@google/gemini-cli-core 0.3.0-nightly.20250823.1a89d185 → 0.3.0-preview.2
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/dist/google-gemini-cli-core-0.3.0-preview.1.tgz +0 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/src/code_assist/codeAssist.d.ts +4 -3
- package/dist/src/code_assist/codeAssist.js +1 -2
- package/dist/src/code_assist/codeAssist.js.map +1 -1
- package/dist/src/code_assist/converter.d.ts +2 -1
- package/dist/src/code_assist/converter.js +1 -1
- package/dist/src/code_assist/converter.js.map +1 -1
- package/dist/src/code_assist/converter.test.js.map +1 -1
- package/dist/src/code_assist/oauth2.d.ts +1 -1
- package/dist/src/code_assist/oauth2.js +8 -8
- package/dist/src/code_assist/oauth2.js.map +1 -1
- package/dist/src/code_assist/oauth2.test.js +5 -5
- package/dist/src/code_assist/oauth2.test.js.map +1 -1
- package/dist/src/code_assist/server.d.ts +5 -5
- package/dist/src/code_assist/server.js +1 -1
- package/dist/src/code_assist/server.js.map +1 -1
- package/dist/src/code_assist/setup.d.ts +4 -12
- package/dist/src/code_assist/setup.js +14 -97
- package/dist/src/code_assist/setup.js.map +1 -1
- package/dist/src/code_assist/setup.test.js +13 -11
- package/dist/src/code_assist/setup.test.js.map +1 -1
- package/dist/src/config/config.d.ts +22 -5
- package/dist/src/config/config.js +42 -11
- package/dist/src/config/config.js.map +1 -1
- package/dist/src/config/config.test.js +83 -2
- package/dist/src/config/config.test.js.map +1 -1
- package/dist/src/config/storage.js +3 -3
- package/dist/src/config/storage.js.map +1 -1
- package/dist/src/config/storage.test.js +1 -1
- package/dist/src/config/storage.test.js.map +1 -1
- package/dist/src/core/client.d.ts +15 -9
- package/dist/src/core/client.js +57 -14
- package/dist/src/core/client.js.map +1 -1
- package/dist/src/core/client.test.js +336 -82
- package/dist/src/core/client.test.js.map +1 -1
- package/dist/src/core/contentGenerator.d.ts +3 -4
- package/dist/src/core/contentGenerator.js +1 -4
- package/dist/src/core/contentGenerator.js.map +1 -1
- package/dist/src/core/contentGenerator.test.js.map +1 -1
- package/dist/src/core/coreToolScheduler.d.ts +11 -2
- package/dist/src/core/coreToolScheduler.js +60 -27
- package/dist/src/core/coreToolScheduler.js.map +1 -1
- package/dist/src/core/coreToolScheduler.test.js +148 -20
- package/dist/src/core/coreToolScheduler.test.js.map +1 -1
- package/dist/src/core/geminiChat.d.ts +10 -12
- package/dist/src/core/geminiChat.js +93 -74
- package/dist/src/core/geminiChat.js.map +1 -1
- package/dist/src/core/geminiChat.test.js +427 -270
- package/dist/src/core/geminiChat.test.js.map +1 -1
- package/dist/src/core/geminiRequest.js +1 -0
- package/dist/src/core/geminiRequest.js.map +1 -1
- package/dist/src/core/logger.d.ts +2 -2
- package/dist/src/core/logger.test.js.map +1 -1
- package/dist/src/core/loggingContentGenerator.d.ts +3 -3
- package/dist/src/core/nonInteractiveToolExecutor.d.ts +1 -1
- package/dist/src/core/nonInteractiveToolExecutor.js.map +1 -1
- package/dist/src/core/nonInteractiveToolExecutor.test.js +11 -4
- package/dist/src/core/nonInteractiveToolExecutor.test.js.map +1 -1
- package/dist/src/core/subagent.d.ts +24 -18
- package/dist/src/core/subagent.js +120 -72
- package/dist/src/core/subagent.js.map +1 -1
- package/dist/src/core/subagent.test.js +26 -21
- package/dist/src/core/subagent.test.js.map +1 -1
- package/dist/src/core/turn.d.ts +15 -4
- package/dist/src/core/turn.js +12 -1
- package/dist/src/core/turn.js.map +1 -1
- package/dist/src/core/turn.test.js +1 -1
- package/dist/src/core/turn.test.js.map +1 -1
- package/dist/src/generated/git-commit.d.ts +2 -2
- package/dist/src/generated/git-commit.js +2 -2
- package/dist/src/generated/git-commit.js.map +1 -1
- package/dist/src/ide/detect-ide.d.ts +8 -3
- package/dist/src/ide/detect-ide.js +29 -11
- package/dist/src/ide/detect-ide.js.map +1 -1
- package/dist/src/ide/detect-ide.test.js +96 -52
- package/dist/src/ide/detect-ide.test.js.map +1 -1
- package/dist/src/ide/ide-client.d.ts +6 -5
- package/dist/src/ide/ide-client.js +19 -17
- package/dist/src/ide/ide-client.js.map +1 -1
- package/dist/src/ide/ide-client.test.js +14 -10
- package/dist/src/ide/ide-client.test.js.map +1 -1
- package/dist/src/ide/ide-installer.d.ts +1 -1
- package/dist/src/ide/ide-installer.js +29 -20
- package/dist/src/ide/ide-installer.js.map +1 -1
- package/dist/src/ide/ide-installer.test.js +82 -22
- package/dist/src/ide/ide-installer.test.js.map +1 -1
- package/dist/src/ide/ideContext.d.ts +11 -11
- package/dist/src/ide/process-utils.d.ts +7 -4
- package/dist/src/ide/process-utils.js +47 -34
- package/dist/src/ide/process-utils.js.map +1 -1
- 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 +7 -2
- package/dist/src/index.js +5 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/mcp/google-auth-provider.d.ts +3 -3
- package/dist/src/mcp/google-auth-provider.test.js.map +1 -1
- package/dist/src/mcp/oauth-provider.d.ts +2 -2
- package/dist/src/mcp/oauth-provider.js.map +1 -1
- package/dist/src/mcp/oauth-provider.test.js +1 -1
- package/dist/src/mcp/oauth-provider.test.js.map +1 -1
- package/dist/src/mcp/oauth-token-storage.d.ts +5 -25
- package/dist/src/mcp/oauth-token-storage.js.map +1 -1
- package/dist/src/mcp/oauth-token-storage.test.js +1 -1
- package/dist/src/mcp/oauth-token-storage.test.js.map +1 -1
- package/dist/src/mcp/oauth-utils.d.ts +9 -1
- package/dist/src/mcp/oauth-utils.js +41 -27
- package/dist/src/mcp/oauth-utils.js.map +1 -1
- package/dist/src/mcp/oauth-utils.test.js +41 -1
- package/dist/src/mcp/oauth-utils.test.js.map +1 -1
- 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/prompts/mcp-prompts.d.ts +2 -2
- package/dist/src/prompts/prompt-registry.d.ts +1 -1
- package/dist/src/services/chatRecordingService.d.ts +1 -1
- package/dist/src/services/chatRecordingService.js +3 -0
- package/dist/src/services/chatRecordingService.js.map +1 -1
- package/dist/src/services/chatRecordingService.test.js +2 -2
- package/dist/src/services/chatRecordingService.test.js.map +1 -1
- package/dist/src/services/fileDiscoveryService.js +1 -1
- package/dist/src/services/fileDiscoveryService.js.map +1 -1
- package/dist/src/services/fileDiscoveryService.test.js +3 -3
- package/dist/src/services/fileDiscoveryService.test.js.map +1 -1
- package/dist/src/services/fileSystemService.js +1 -1
- package/dist/src/services/fileSystemService.js.map +1 -1
- package/dist/src/services/fileSystemService.test.js +1 -1
- package/dist/src/services/fileSystemService.test.js.map +1 -1
- package/dist/src/services/gitService.d.ts +1 -1
- package/dist/src/services/gitService.js +2 -2
- package/dist/src/services/gitService.js.map +1 -1
- package/dist/src/services/gitService.test.js +3 -3
- package/dist/src/services/gitService.test.js.map +1 -1
- package/dist/src/services/loopDetectionService.d.ts +2 -2
- package/dist/src/services/loopDetectionService.js +9 -3
- package/dist/src/services/loopDetectionService.js.map +1 -1
- package/dist/src/services/loopDetectionService.test.js +23 -1
- package/dist/src/services/loopDetectionService.test.js.map +1 -1
- package/dist/src/services/shellExecutionService.js +5 -4
- package/dist/src/services/shellExecutionService.js.map +1 -1
- package/dist/src/services/shellExecutionService.test.js +4 -3
- package/dist/src/services/shellExecutionService.test.js.map +1 -1
- package/dist/src/telemetry/clearcut-logger/clearcut-logger.d.ts +11 -3
- package/dist/src/telemetry/clearcut-logger/clearcut-logger.js +77 -2
- package/dist/src/telemetry/clearcut-logger/clearcut-logger.js.map +1 -1
- package/dist/src/telemetry/clearcut-logger/clearcut-logger.test.js +11 -3
- package/dist/src/telemetry/clearcut-logger/clearcut-logger.test.js.map +1 -1
- package/dist/src/telemetry/clearcut-logger/event-metadata-key.d.ts +21 -5
- package/dist/src/telemetry/clearcut-logger/event-metadata-key.js +48 -7
- package/dist/src/telemetry/clearcut-logger/event-metadata-key.js.map +1 -1
- package/dist/src/telemetry/constants.d.ts +5 -0
- package/dist/src/telemetry/constants.js +5 -0
- package/dist/src/telemetry/constants.js.map +1 -1
- package/dist/src/telemetry/file-exporters.d.ts +5 -4
- package/dist/src/telemetry/file-exporters.js +1 -1
- package/dist/src/telemetry/file-exporters.js.map +1 -1
- package/dist/src/telemetry/index.d.ts +5 -2
- package/dist/src/telemetry/index.js +3 -2
- package/dist/src/telemetry/index.js.map +1 -1
- package/dist/src/telemetry/loggers.d.ts +7 -2
- package/dist/src/telemetry/loggers.js +96 -2
- package/dist/src/telemetry/loggers.js.map +1 -1
- package/dist/src/telemetry/loggers.test.circular.js.map +1 -1
- package/dist/src/telemetry/loggers.test.js +60 -4
- package/dist/src/telemetry/loggers.test.js.map +1 -1
- package/dist/src/telemetry/metrics.d.ts +3 -3
- package/dist/src/telemetry/metrics.js +1 -1
- package/dist/src/telemetry/metrics.js.map +1 -1
- package/dist/src/telemetry/sdk.d.ts +1 -1
- package/dist/src/telemetry/types.d.ts +37 -7
- package/dist/src/telemetry/types.js +51 -0
- package/dist/src/telemetry/types.js.map +1 -1
- package/dist/src/telemetry/uiTelemetry.d.ts +2 -2
- package/dist/src/telemetry/uiTelemetry.js +1 -1
- package/dist/src/telemetry/uiTelemetry.js.map +1 -1
- package/dist/src/telemetry/uiTelemetry.test.js.map +1 -1
- package/dist/src/test-utils/config.d.ts +2 -1
- package/dist/src/test-utils/config.js.map +1 -1
- package/dist/src/test-utils/mockWorkspaceContext.d.ts +1 -1
- package/dist/src/test-utils/tools.d.ts +3 -2
- package/dist/src/test-utils/tools.js.map +1 -1
- package/dist/src/tools/diffOptions.d.ts +1 -1
- package/dist/src/tools/edit.d.ts +4 -3
- package/dist/src/tools/edit.js +3 -3
- package/dist/src/tools/edit.js.map +1 -1
- package/dist/src/tools/edit.test.js +3 -3
- package/dist/src/tools/edit.test.js.map +1 -1
- package/dist/src/tools/glob.d.ts +3 -2
- package/dist/src/tools/glob.js +4 -4
- package/dist/src/tools/glob.js.map +1 -1
- package/dist/src/tools/glob.test.js +6 -3
- package/dist/src/tools/glob.test.js.map +1 -1
- package/dist/src/tools/grep.d.ts +3 -2
- package/dist/src/tools/grep.js +30 -15
- package/dist/src/tools/grep.js.map +1 -1
- package/dist/src/tools/grep.test.js +15 -3
- package/dist/src/tools/grep.test.js.map +1 -1
- package/dist/src/tools/ls.d.ts +3 -2
- package/dist/src/tools/ls.js +3 -3
- package/dist/src/tools/ls.js.map +1 -1
- package/dist/src/tools/ls.test.js +2 -2
- package/dist/src/tools/ls.test.js.map +1 -1
- package/dist/src/tools/mcp-client-manager.d.ts +4 -4
- package/dist/src/tools/mcp-client.d.ts +7 -7
- package/dist/src/tools/mcp-client.js +2 -2
- package/dist/src/tools/mcp-client.js.map +1 -1
- package/dist/src/tools/mcp-tool.d.ts +3 -2
- package/dist/src/tools/mcp-tool.js.map +1 -1
- package/dist/src/tools/mcp-tool.test.js +1 -2
- package/dist/src/tools/mcp-tool.test.js.map +1 -1
- package/dist/src/tools/memoryTool.d.ts +3 -2
- package/dist/src/tools/memoryTool.js +2 -2
- package/dist/src/tools/memoryTool.js.map +1 -1
- package/dist/src/tools/memoryTool.test.js +4 -4
- package/dist/src/tools/memoryTool.test.js.map +1 -1
- package/dist/src/tools/modifiable-tool.d.ts +2 -2
- package/dist/src/tools/modifiable-tool.js +3 -3
- package/dist/src/tools/modifiable-tool.js.map +1 -1
- package/dist/src/tools/modifiable-tool.test.js +4 -4
- package/dist/src/tools/modifiable-tool.test.js.map +1 -1
- package/dist/src/tools/read-file.d.ts +3 -2
- package/dist/src/tools/read-file.js +2 -2
- package/dist/src/tools/read-file.js.map +1 -1
- package/dist/src/tools/read-file.test.js +4 -4
- package/dist/src/tools/read-file.test.js.map +1 -1
- package/dist/src/tools/read-many-files.d.ts +3 -2
- package/dist/src/tools/read-many-files.js +14 -47
- package/dist/src/tools/read-many-files.js.map +1 -1
- package/dist/src/tools/read-many-files.test.js +18 -3
- package/dist/src/tools/read-many-files.test.js.map +1 -1
- package/dist/src/tools/ripGrep.d.ts +3 -2
- package/dist/src/tools/ripGrep.js +5 -5
- package/dist/src/tools/ripGrep.js.map +1 -1
- package/dist/src/tools/ripGrep.test.js +4 -4
- package/dist/src/tools/ripGrep.test.js.map +1 -1
- package/dist/src/tools/shell.d.ts +3 -2
- package/dist/src/tools/shell.js +16 -5
- package/dist/src/tools/shell.js.map +1 -1
- package/dist/src/tools/shell.test.js +21 -5
- package/dist/src/tools/shell.test.js.map +1 -1
- package/dist/src/tools/tool-error.d.ts +1 -0
- package/dist/src/tools/tool-error.js +2 -0
- package/dist/src/tools/tool-error.js.map +1 -1
- package/dist/src/tools/tool-registry.d.ts +8 -3
- package/dist/src/tools/tool-registry.js +7 -1
- package/dist/src/tools/tool-registry.js.map +1 -1
- package/dist/src/tools/tool-registry.test.js +15 -2
- package/dist/src/tools/tool-registry.test.js.map +1 -1
- package/dist/src/tools/tools.d.ts +8 -2
- package/dist/src/tools/tools.js +12 -0
- package/dist/src/tools/tools.js.map +1 -1
- package/dist/src/tools/tools.test.js +1 -1
- package/dist/src/tools/tools.test.js.map +1 -1
- package/dist/src/tools/web-fetch.d.ts +3 -2
- package/dist/src/tools/web-fetch.js +1 -1
- package/dist/src/tools/web-fetch.js.map +1 -1
- package/dist/src/tools/web-fetch.test.js.map +1 -1
- package/dist/src/tools/web-search.d.ts +4 -3
- package/dist/src/tools/web-search.js +2 -2
- package/dist/src/tools/web-search.js.map +1 -1
- package/dist/src/tools/web-search.test.js.map +1 -1
- package/dist/src/tools/write-file.d.ts +4 -3
- package/dist/src/tools/write-file.js +2 -2
- package/dist/src/tools/write-file.js.map +1 -1
- package/dist/src/tools/write-file.test.js +6 -5
- package/dist/src/tools/write-file.test.js.map +1 -1
- package/dist/src/utils/bfsFileSearch.d.ts +2 -2
- package/dist/src/utils/bfsFileSearch.js +2 -2
- package/dist/src/utils/bfsFileSearch.js.map +1 -1
- package/dist/src/utils/bfsFileSearch.test.js +3 -3
- package/dist/src/utils/bfsFileSearch.test.js.map +1 -1
- package/dist/src/utils/editCorrector.d.ts +2 -2
- package/dist/src/utils/editCorrector.js +1 -1
- package/dist/src/utils/editCorrector.js.map +1 -1
- package/dist/src/utils/editCorrector.test.js +2 -3
- package/dist/src/utils/editCorrector.test.js.map +1 -1
- package/dist/src/utils/editor.js +1 -1
- package/dist/src/utils/editor.js.map +1 -1
- package/dist/src/utils/editor.test.js +1 -1
- package/dist/src/utils/editor.test.js.map +1 -1
- package/dist/src/utils/environmentContext.d.ts +2 -2
- package/dist/src/utils/errorReporting.d.ts +1 -1
- package/dist/src/utils/errors.d.ts +19 -0
- package/dist/src/utils/errors.js +32 -0
- package/dist/src/utils/errors.js.map +1 -1
- package/dist/src/utils/fetch.js +1 -1
- package/dist/src/utils/fetch.js.map +1 -1
- package/dist/src/utils/fileUtils.d.ts +2 -2
- package/dist/src/utils/fileUtils.js +2 -30
- package/dist/src/utils/fileUtils.js.map +1 -1
- package/dist/src/utils/filesearch/crawler.d.ts +1 -1
- package/dist/src/utils/filesearch/crawler.test.js +2 -2
- package/dist/src/utils/filesearch/crawler.test.js.map +1 -1
- package/dist/src/utils/filesearch/fileSearch.js +12 -8
- package/dist/src/utils/filesearch/fileSearch.js.map +1 -1
- package/dist/src/utils/generateContentResponseUtilities.d.ts +1 -2
- package/dist/src/utils/generateContentResponseUtilities.js +1 -13
- package/dist/src/utils/generateContentResponseUtilities.js.map +1 -1
- package/dist/src/utils/generateContentResponseUtilities.test.js +2 -40
- package/dist/src/utils/generateContentResponseUtilities.test.js.map +1 -1
- package/dist/src/utils/getFolderStructure.d.ts +2 -2
- package/dist/src/utils/getFolderStructure.js +2 -2
- package/dist/src/utils/getFolderStructure.js.map +1 -1
- package/dist/src/utils/getFolderStructure.test.js +4 -4
- package/dist/src/utils/getFolderStructure.test.js.map +1 -1
- package/dist/src/utils/gitIgnoreParser.js +3 -3
- package/dist/src/utils/gitIgnoreParser.js.map +1 -1
- package/dist/src/utils/gitIgnoreParser.test.js +3 -3
- package/dist/src/utils/gitIgnoreParser.test.js.map +1 -1
- package/dist/src/utils/gitUtils.js +2 -2
- package/dist/src/utils/gitUtils.js.map +1 -1
- 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.js +2 -2
- package/dist/src/utils/installationManager.js.map +1 -1
- package/dist/src/utils/installationManager.test.js +1 -1
- package/dist/src/utils/installationManager.test.js.map +1 -1
- package/dist/src/utils/language-detection.js +1 -1
- package/dist/src/utils/language-detection.js.map +1 -1
- package/dist/src/utils/memoryDiscovery.d.ts +2 -2
- package/dist/src/utils/memoryDiscovery.js +5 -5
- package/dist/src/utils/memoryDiscovery.js.map +1 -1
- package/dist/src/utils/memoryDiscovery.test.js +3 -3
- package/dist/src/utils/memoryDiscovery.test.js.map +1 -1
- package/dist/src/utils/memoryImportProcessor.js +2 -2
- package/dist/src/utils/memoryImportProcessor.js.map +1 -1
- package/dist/src/utils/memoryImportProcessor.test.js +2 -141
- package/dist/src/utils/memoryImportProcessor.test.js.map +1 -1
- package/dist/src/utils/messageInspectors.d.ts +1 -1
- package/dist/src/utils/nextSpeakerChecker.d.ts +2 -2
- package/dist/src/utils/nextSpeakerChecker.test.js.map +1 -1
- package/dist/src/utils/partUtils.d.ts +22 -1
- package/dist/src/utils/partUtils.js +68 -0
- package/dist/src/utils/partUtils.js.map +1 -1
- package/dist/src/utils/partUtils.test.js +112 -1
- package/dist/src/utils/partUtils.test.js.map +1 -1
- 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.js +2 -2
- package/dist/src/utils/paths.js.map +1 -1
- package/dist/src/utils/quotaErrorDetection.d.ts +1 -1
- package/dist/src/utils/retry.test.js +4 -1
- package/dist/src/utils/retry.test.js.map +1 -1
- package/dist/src/utils/schemaValidator.js +4 -0
- package/dist/src/utils/schemaValidator.js.map +1 -1
- package/dist/src/utils/session.js +1 -1
- package/dist/src/utils/session.js.map +1 -1
- package/dist/src/utils/shell-utils.d.ts +1 -1
- package/dist/src/utils/shell-utils.js +23 -29
- package/dist/src/utils/shell-utils.js.map +1 -1
- package/dist/src/utils/shell-utils.test.js +4 -0
- package/dist/src/utils/shell-utils.test.js.map +1 -1
- package/dist/src/utils/summarizer.d.ts +2 -2
- package/dist/src/utils/summarizer.test.js.map +1 -1
- package/dist/src/utils/systemEncoding.js +2 -2
- package/dist/src/utils/systemEncoding.js.map +1 -1
- package/dist/src/utils/systemEncoding.test.js +2 -2
- package/dist/src/utils/systemEncoding.test.js.map +1 -1
- 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.test.js.map +1 -1
- package/dist/src/utils/workspaceContext.js +3 -3
- package/dist/src/utils/workspaceContext.js.map +1 -1
- package/dist/src/utils/workspaceContext.test.js +3 -3
- package/dist/src/utils/workspaceContext.test.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +10 -7
|
@@ -3,12 +3,13 @@
|
|
|
3
3
|
* Copyright 2025 Google LLC
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
|
-
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
|
|
7
|
-
import { GoogleGenAI
|
|
6
|
+
import { describe, it, expect, vi, beforeEach, afterEach, } from 'vitest';
|
|
7
|
+
import { GoogleGenAI } from '@google/genai';
|
|
8
8
|
import { findIndexAfterFraction, GeminiClient } from './client.js';
|
|
9
|
-
import { AuthType } from './contentGenerator.js';
|
|
9
|
+
import { AuthType, } from './contentGenerator.js';
|
|
10
|
+
import {} from './geminiChat.js';
|
|
10
11
|
import { Config } from '../config/config.js';
|
|
11
|
-
import { GeminiEventType, Turn } from './turn.js';
|
|
12
|
+
import { CompressionStatus, GeminiEventType, Turn, } from './turn.js';
|
|
12
13
|
import { getCoreSystemPrompt } from './prompts.js';
|
|
13
14
|
import { DEFAULT_GEMINI_FLASH_MODEL } from '../config/models.js';
|
|
14
15
|
import { FileDiscoveryService } from '../services/fileDiscoveryService.js';
|
|
@@ -22,7 +23,8 @@ const mockGenerateContentFn = vi.fn();
|
|
|
22
23
|
const mockEmbedContentFn = vi.fn();
|
|
23
24
|
const mockTurnRunFn = vi.fn();
|
|
24
25
|
vi.mock('@google/genai');
|
|
25
|
-
vi.mock('./turn', () => {
|
|
26
|
+
vi.mock('./turn', async (importOriginal) => {
|
|
27
|
+
const actual = await importOriginal();
|
|
26
28
|
// Define a mock class that has the same shape as the real Turn
|
|
27
29
|
class MockTurn {
|
|
28
30
|
pendingToolCalls = [];
|
|
@@ -34,11 +36,8 @@ vi.mock('./turn', () => {
|
|
|
34
36
|
}
|
|
35
37
|
// Export the mock class as 'Turn'
|
|
36
38
|
return {
|
|
39
|
+
...actual,
|
|
37
40
|
Turn: MockTurn,
|
|
38
|
-
GeminiEventType: {
|
|
39
|
-
MaxSessionTurns: 'MaxSessionTurns',
|
|
40
|
-
ChatCompressed: 'ChatCompressed',
|
|
41
|
-
},
|
|
42
41
|
};
|
|
43
42
|
});
|
|
44
43
|
vi.mock('../config/config.js');
|
|
@@ -60,6 +59,18 @@ vi.mock('../telemetry/index.js', () => ({
|
|
|
60
59
|
logApiError: vi.fn(),
|
|
61
60
|
}));
|
|
62
61
|
vi.mock('../ide/ideContext.js');
|
|
62
|
+
/**
|
|
63
|
+
* Array.fromAsync ponyfill, which will be available in es 2024.
|
|
64
|
+
*
|
|
65
|
+
* Buffers an async generator into an array and returns the result.
|
|
66
|
+
*/
|
|
67
|
+
async function fromAsync(promise) {
|
|
68
|
+
const results = [];
|
|
69
|
+
for await (const result of promise) {
|
|
70
|
+
results.push(result);
|
|
71
|
+
}
|
|
72
|
+
return results;
|
|
73
|
+
}
|
|
63
74
|
describe('findIndexAfterFraction', () => {
|
|
64
75
|
const history = [
|
|
65
76
|
{ role: 'user', parts: [{ text: 'This is the first message.' }] }, // JSON length: 66
|
|
@@ -275,30 +286,6 @@ describe('Gemini Client (client.ts)', () => {
|
|
|
275
286
|
await expect(client.generateEmbedding(texts)).rejects.toThrow('API Failure');
|
|
276
287
|
});
|
|
277
288
|
});
|
|
278
|
-
describe('generateContent', () => {
|
|
279
|
-
it('should call generateContent with the correct parameters', async () => {
|
|
280
|
-
const contents = [{ role: 'user', parts: [{ text: 'hello' }] }];
|
|
281
|
-
const generationConfig = { temperature: 0.5 };
|
|
282
|
-
const abortSignal = new AbortController().signal;
|
|
283
|
-
// Mock countTokens
|
|
284
|
-
const mockGenerator = {
|
|
285
|
-
countTokens: vi.fn().mockResolvedValue({ totalTokens: 1 }),
|
|
286
|
-
generateContent: mockGenerateContentFn,
|
|
287
|
-
};
|
|
288
|
-
client['contentGenerator'] = mockGenerator;
|
|
289
|
-
await client.generateContent(contents, generationConfig, abortSignal);
|
|
290
|
-
expect(mockGenerateContentFn).toHaveBeenCalledWith({
|
|
291
|
-
model: 'test-model',
|
|
292
|
-
config: {
|
|
293
|
-
abortSignal,
|
|
294
|
-
systemInstruction: getCoreSystemPrompt(''),
|
|
295
|
-
temperature: 0.5,
|
|
296
|
-
topP: 1,
|
|
297
|
-
},
|
|
298
|
-
contents,
|
|
299
|
-
}, 'test-session-id');
|
|
300
|
-
});
|
|
301
|
-
});
|
|
302
289
|
describe('generateJson', () => {
|
|
303
290
|
it('should call generateContent with the correct parameters', async () => {
|
|
304
291
|
const contents = [{ role: 'user', parts: [{ text: 'hello' }] }];
|
|
@@ -325,7 +312,9 @@ describe('Gemini Client (client.ts)', () => {
|
|
|
325
312
|
}, 'test-session-id');
|
|
326
313
|
});
|
|
327
314
|
it('should allow overriding model and config', async () => {
|
|
328
|
-
const contents = [
|
|
315
|
+
const contents = [
|
|
316
|
+
{ role: 'user', parts: [{ text: 'hello' }] },
|
|
317
|
+
];
|
|
329
318
|
const schema = { type: 'string' };
|
|
330
319
|
const abortSignal = new AbortController().signal;
|
|
331
320
|
const customModel = 'custom-json-model';
|
|
@@ -405,6 +394,106 @@ describe('Gemini Client (client.ts)', () => {
|
|
|
405
394
|
sendMessage: mockSendMessage,
|
|
406
395
|
};
|
|
407
396
|
});
|
|
397
|
+
function setup({ chatHistory = [
|
|
398
|
+
{ role: 'user', parts: [{ text: 'Long conversation' }] },
|
|
399
|
+
{ role: 'model', parts: [{ text: 'Long response' }] },
|
|
400
|
+
], } = {}) {
|
|
401
|
+
const mockChat = {
|
|
402
|
+
getHistory: vi.fn().mockReturnValue(chatHistory),
|
|
403
|
+
setHistory: vi.fn(),
|
|
404
|
+
sendMessage: vi.fn().mockResolvedValue({ text: 'Summary' }),
|
|
405
|
+
};
|
|
406
|
+
const mockCountTokens = vi
|
|
407
|
+
.fn()
|
|
408
|
+
.mockResolvedValueOnce({ totalTokens: 1000 })
|
|
409
|
+
.mockResolvedValueOnce({ totalTokens: 5000 });
|
|
410
|
+
const mockGenerator = {
|
|
411
|
+
countTokens: mockCountTokens,
|
|
412
|
+
};
|
|
413
|
+
client['chat'] = mockChat;
|
|
414
|
+
client['contentGenerator'] = mockGenerator;
|
|
415
|
+
client['startChat'] = vi.fn().mockResolvedValue({ ...mockChat });
|
|
416
|
+
return { client, mockChat, mockGenerator };
|
|
417
|
+
}
|
|
418
|
+
describe('when compression inflates the token count', () => {
|
|
419
|
+
it('uses the truncated history for compression');
|
|
420
|
+
it('allows compression to be forced/manual after a failure', async () => {
|
|
421
|
+
const { client, mockGenerator } = setup();
|
|
422
|
+
mockGenerator.countTokens?.mockResolvedValue({
|
|
423
|
+
totalTokens: 1000,
|
|
424
|
+
});
|
|
425
|
+
await client.tryCompressChat('prompt-id-4'); // Fails
|
|
426
|
+
const result = await client.tryCompressChat('prompt-id-4', true);
|
|
427
|
+
expect(result).toEqual({
|
|
428
|
+
compressionStatus: CompressionStatus.COMPRESSED,
|
|
429
|
+
newTokenCount: 1000,
|
|
430
|
+
originalTokenCount: 1000,
|
|
431
|
+
});
|
|
432
|
+
});
|
|
433
|
+
it('yields the result even if the compression inflated the tokens', async () => {
|
|
434
|
+
const { client } = setup();
|
|
435
|
+
const result = await client.tryCompressChat('prompt-id-4', true);
|
|
436
|
+
expect(result).toEqual({
|
|
437
|
+
compressionStatus: CompressionStatus.COMPRESSION_FAILED_INFLATED_TOKEN_COUNT,
|
|
438
|
+
newTokenCount: 5000,
|
|
439
|
+
originalTokenCount: 1000,
|
|
440
|
+
});
|
|
441
|
+
});
|
|
442
|
+
it('does not manipulate the source chat', async () => {
|
|
443
|
+
const { client, mockChat } = setup();
|
|
444
|
+
await client.tryCompressChat('prompt-id-4', true);
|
|
445
|
+
expect(client['chat']).toBe(mockChat); // a new chat session was not created
|
|
446
|
+
});
|
|
447
|
+
it('restores the history back to the original', async () => {
|
|
448
|
+
vi.mocked(tokenLimit).mockReturnValue(1000);
|
|
449
|
+
mockCountTokens.mockResolvedValue({
|
|
450
|
+
totalTokens: 999,
|
|
451
|
+
});
|
|
452
|
+
const originalHistory = [
|
|
453
|
+
{ role: 'user', parts: [{ text: 'what is your wisdom?' }] },
|
|
454
|
+
{ role: 'model', parts: [{ text: 'some wisdom' }] },
|
|
455
|
+
{ role: 'user', parts: [{ text: 'ahh that is a good a wisdom' }] },
|
|
456
|
+
];
|
|
457
|
+
const { client } = setup({
|
|
458
|
+
chatHistory: originalHistory,
|
|
459
|
+
});
|
|
460
|
+
const { compressionStatus } = await client.tryCompressChat('prompt-id-4');
|
|
461
|
+
expect(compressionStatus).toBe(CompressionStatus.COMPRESSION_FAILED_INFLATED_TOKEN_COUNT);
|
|
462
|
+
expect(client['chat']?.setHistory).toHaveBeenCalledWith(originalHistory);
|
|
463
|
+
});
|
|
464
|
+
it('will not attempt to compress context after a failure', async () => {
|
|
465
|
+
const { client, mockGenerator } = setup();
|
|
466
|
+
await client.tryCompressChat('prompt-id-4');
|
|
467
|
+
const result = await client.tryCompressChat('prompt-id-5');
|
|
468
|
+
// it counts tokens for {original, compressed} and then never again
|
|
469
|
+
expect(mockGenerator.countTokens).toHaveBeenCalledTimes(2);
|
|
470
|
+
expect(result).toEqual({
|
|
471
|
+
compressionStatus: CompressionStatus.NOOP,
|
|
472
|
+
newTokenCount: 0,
|
|
473
|
+
originalTokenCount: 0,
|
|
474
|
+
});
|
|
475
|
+
});
|
|
476
|
+
});
|
|
477
|
+
it('attempts to compress with a maxOutputTokens set to the original token count', async () => {
|
|
478
|
+
vi.mocked(tokenLimit).mockReturnValue(1000);
|
|
479
|
+
mockCountTokens.mockResolvedValue({
|
|
480
|
+
totalTokens: 999,
|
|
481
|
+
});
|
|
482
|
+
mockGetHistory.mockReturnValue([
|
|
483
|
+
{ role: 'user', parts: [{ text: '...history...' }] },
|
|
484
|
+
]);
|
|
485
|
+
// Mock the summary response from the chat
|
|
486
|
+
mockSendMessage.mockResolvedValue({
|
|
487
|
+
role: 'model',
|
|
488
|
+
parts: [{ text: 'This is a summary.' }],
|
|
489
|
+
});
|
|
490
|
+
await client.tryCompressChat('prompt-id-2', true);
|
|
491
|
+
expect(mockSendMessage).toHaveBeenCalledWith(expect.objectContaining({
|
|
492
|
+
config: expect.objectContaining({
|
|
493
|
+
maxOutputTokens: 999,
|
|
494
|
+
}),
|
|
495
|
+
}), 'prompt-id-2');
|
|
496
|
+
});
|
|
408
497
|
it('should not trigger summarization if token count is below threshold', async () => {
|
|
409
498
|
const MOCKED_TOKEN_LIMIT = 1000;
|
|
410
499
|
vi.mocked(tokenLimit).mockReturnValue(MOCKED_TOKEN_LIMIT);
|
|
@@ -418,7 +507,11 @@ describe('Gemini Client (client.ts)', () => {
|
|
|
418
507
|
const result = await client.tryCompressChat('prompt-id-2');
|
|
419
508
|
const newChat = client.getChat();
|
|
420
509
|
expect(tokenLimit).toHaveBeenCalled();
|
|
421
|
-
expect(result).
|
|
510
|
+
expect(result).toEqual({
|
|
511
|
+
compressionStatus: CompressionStatus.NOOP,
|
|
512
|
+
newTokenCount: 699,
|
|
513
|
+
originalTokenCount: 699,
|
|
514
|
+
});
|
|
422
515
|
expect(newChat).toBe(initialChat);
|
|
423
516
|
});
|
|
424
517
|
it('logs a telemetry event when compressing', async () => {
|
|
@@ -475,6 +568,7 @@ describe('Gemini Client (client.ts)', () => {
|
|
|
475
568
|
expect(mockSendMessage).toHaveBeenCalled();
|
|
476
569
|
// Assert that summarization happened and returned the correct stats
|
|
477
570
|
expect(result).toEqual({
|
|
571
|
+
compressionStatus: CompressionStatus.COMPRESSED,
|
|
478
572
|
originalTokenCount,
|
|
479
573
|
newTokenCount,
|
|
480
574
|
});
|
|
@@ -519,6 +613,7 @@ describe('Gemini Client (client.ts)', () => {
|
|
|
519
613
|
expect(mockSendMessage).toHaveBeenCalled();
|
|
520
614
|
// Assert that summarization happened and returned the correct stats
|
|
521
615
|
expect(result).toEqual({
|
|
616
|
+
compressionStatus: CompressionStatus.COMPRESSED,
|
|
522
617
|
originalTokenCount,
|
|
523
618
|
newTokenCount,
|
|
524
619
|
});
|
|
@@ -550,14 +645,129 @@ describe('Gemini Client (client.ts)', () => {
|
|
|
550
645
|
const newChat = client.getChat();
|
|
551
646
|
expect(mockSendMessage).toHaveBeenCalled();
|
|
552
647
|
expect(result).toEqual({
|
|
648
|
+
compressionStatus: CompressionStatus.COMPRESSED,
|
|
553
649
|
originalTokenCount,
|
|
554
650
|
newTokenCount,
|
|
555
651
|
});
|
|
556
652
|
// Assert that the chat was reset
|
|
557
653
|
expect(newChat).not.toBe(initialChat);
|
|
558
654
|
});
|
|
655
|
+
it('should use current model from config for token counting after sendMessage', async () => {
|
|
656
|
+
const initialModel = client['config'].getModel();
|
|
657
|
+
const mockCountTokens = vi
|
|
658
|
+
.fn()
|
|
659
|
+
.mockResolvedValueOnce({ totalTokens: 100000 })
|
|
660
|
+
.mockResolvedValueOnce({ totalTokens: 5000 });
|
|
661
|
+
const mockSendMessage = vi.fn().mockResolvedValue({ text: 'Summary' });
|
|
662
|
+
const mockChatHistory = [
|
|
663
|
+
{ role: 'user', parts: [{ text: 'Long conversation' }] },
|
|
664
|
+
{ role: 'model', parts: [{ text: 'Long response' }] },
|
|
665
|
+
];
|
|
666
|
+
const mockChat = {
|
|
667
|
+
getHistory: vi.fn().mockReturnValue(mockChatHistory),
|
|
668
|
+
setHistory: vi.fn(),
|
|
669
|
+
sendMessage: mockSendMessage,
|
|
670
|
+
};
|
|
671
|
+
const mockGenerator = {
|
|
672
|
+
countTokens: mockCountTokens,
|
|
673
|
+
};
|
|
674
|
+
// mock the model has been changed between calls of `countTokens`
|
|
675
|
+
const firstCurrentModel = initialModel + '-changed-1';
|
|
676
|
+
const secondCurrentModel = initialModel + '-changed-2';
|
|
677
|
+
vi.spyOn(client['config'], 'getModel')
|
|
678
|
+
.mockReturnValueOnce(firstCurrentModel)
|
|
679
|
+
.mockReturnValueOnce(secondCurrentModel);
|
|
680
|
+
client['chat'] = mockChat;
|
|
681
|
+
client['contentGenerator'] = mockGenerator;
|
|
682
|
+
client['startChat'] = vi.fn().mockResolvedValue(mockChat);
|
|
683
|
+
const result = await client.tryCompressChat('prompt-id-4', true);
|
|
684
|
+
expect(mockCountTokens).toHaveBeenCalledTimes(2);
|
|
685
|
+
expect(mockCountTokens).toHaveBeenNthCalledWith(1, {
|
|
686
|
+
model: firstCurrentModel,
|
|
687
|
+
contents: mockChatHistory,
|
|
688
|
+
});
|
|
689
|
+
expect(mockCountTokens).toHaveBeenNthCalledWith(2, {
|
|
690
|
+
model: secondCurrentModel,
|
|
691
|
+
contents: expect.any(Array),
|
|
692
|
+
});
|
|
693
|
+
expect(result).toEqual({
|
|
694
|
+
compressionStatus: CompressionStatus.COMPRESSED,
|
|
695
|
+
originalTokenCount: 100000,
|
|
696
|
+
newTokenCount: 5000,
|
|
697
|
+
});
|
|
698
|
+
});
|
|
559
699
|
});
|
|
560
700
|
describe('sendMessageStream', () => {
|
|
701
|
+
it('emits a compression event when the context was automatically compressed', async () => {
|
|
702
|
+
// Arrange
|
|
703
|
+
const mockStream = (async function* () {
|
|
704
|
+
yield { type: 'content', value: 'Hello' };
|
|
705
|
+
})();
|
|
706
|
+
mockTurnRunFn.mockReturnValue(mockStream);
|
|
707
|
+
const mockChat = {
|
|
708
|
+
addHistory: vi.fn(),
|
|
709
|
+
getHistory: vi.fn().mockReturnValue([]),
|
|
710
|
+
};
|
|
711
|
+
client['chat'] = mockChat;
|
|
712
|
+
const mockGenerator = {
|
|
713
|
+
countTokens: vi.fn().mockResolvedValue({ totalTokens: 0 }),
|
|
714
|
+
generateContent: mockGenerateContentFn,
|
|
715
|
+
};
|
|
716
|
+
client['contentGenerator'] = mockGenerator;
|
|
717
|
+
const compressionInfo = {
|
|
718
|
+
compressionStatus: CompressionStatus.COMPRESSED,
|
|
719
|
+
originalTokenCount: 1000,
|
|
720
|
+
newTokenCount: 500,
|
|
721
|
+
};
|
|
722
|
+
vi.spyOn(client, 'tryCompressChat').mockResolvedValueOnce(compressionInfo);
|
|
723
|
+
// Act
|
|
724
|
+
const stream = client.sendMessageStream([{ text: 'Hi' }], new AbortController().signal, 'prompt-id-1');
|
|
725
|
+
const events = await fromAsync(stream);
|
|
726
|
+
// Assert
|
|
727
|
+
expect(events).toContainEqual({
|
|
728
|
+
type: GeminiEventType.ChatCompressed,
|
|
729
|
+
value: compressionInfo,
|
|
730
|
+
});
|
|
731
|
+
});
|
|
732
|
+
it.each([
|
|
733
|
+
{
|
|
734
|
+
compressionStatus: CompressionStatus.COMPRESSION_FAILED_INFLATED_TOKEN_COUNT,
|
|
735
|
+
},
|
|
736
|
+
{ compressionStatus: CompressionStatus.NOOP },
|
|
737
|
+
{
|
|
738
|
+
compressionStatus: CompressionStatus.COMPRESSION_FAILED_TOKEN_COUNT_ERROR,
|
|
739
|
+
},
|
|
740
|
+
])('does not emit a compression event when the status is $compressionStatus', async ({ compressionStatus }) => {
|
|
741
|
+
// Arrange
|
|
742
|
+
const mockStream = (async function* () {
|
|
743
|
+
yield { type: 'content', value: 'Hello' };
|
|
744
|
+
})();
|
|
745
|
+
mockTurnRunFn.mockReturnValue(mockStream);
|
|
746
|
+
const mockChat = {
|
|
747
|
+
addHistory: vi.fn(),
|
|
748
|
+
getHistory: vi.fn().mockReturnValue([]),
|
|
749
|
+
};
|
|
750
|
+
client['chat'] = mockChat;
|
|
751
|
+
const mockGenerator = {
|
|
752
|
+
countTokens: vi.fn().mockResolvedValue({ totalTokens: 0 }),
|
|
753
|
+
generateContent: mockGenerateContentFn,
|
|
754
|
+
};
|
|
755
|
+
client['contentGenerator'] = mockGenerator;
|
|
756
|
+
const compressionInfo = {
|
|
757
|
+
compressionStatus,
|
|
758
|
+
originalTokenCount: 1000,
|
|
759
|
+
newTokenCount: 500,
|
|
760
|
+
};
|
|
761
|
+
vi.spyOn(client, 'tryCompressChat').mockResolvedValueOnce(compressionInfo);
|
|
762
|
+
// Act
|
|
763
|
+
const stream = client.sendMessageStream([{ text: 'Hi' }], new AbortController().signal, 'prompt-id-1');
|
|
764
|
+
const events = await fromAsync(stream);
|
|
765
|
+
// Assert
|
|
766
|
+
expect(events).not.toContainEqual({
|
|
767
|
+
type: GeminiEventType.ChatCompressed,
|
|
768
|
+
value: expect.anything(),
|
|
769
|
+
});
|
|
770
|
+
});
|
|
561
771
|
it('should include editor context when ideMode is enabled', async () => {
|
|
562
772
|
// Arrange
|
|
563
773
|
vi.mocked(ideContext.getIdeContext).mockReturnValue({
|
|
@@ -977,7 +1187,11 @@ ${JSON.stringify({
|
|
|
977
1187
|
})();
|
|
978
1188
|
beforeEach(() => {
|
|
979
1189
|
client['forceFullIdeContext'] = false; // Reset before each delta test
|
|
980
|
-
vi.spyOn(client, 'tryCompressChat').mockResolvedValue(
|
|
1190
|
+
vi.spyOn(client, 'tryCompressChat').mockResolvedValue({
|
|
1191
|
+
originalTokenCount: 0,
|
|
1192
|
+
newTokenCount: 0,
|
|
1193
|
+
compressionStatus: CompressionStatus.COMPRESSED,
|
|
1194
|
+
});
|
|
981
1195
|
vi.spyOn(client['config'], 'getIdeMode').mockReturnValue(true);
|
|
982
1196
|
mockTurnRunFn.mockReturnValue(mockStream);
|
|
983
1197
|
const mockChat = {
|
|
@@ -1190,7 +1404,11 @@ ${JSON.stringify({
|
|
|
1190
1404
|
describe('IDE context with pending tool calls', () => {
|
|
1191
1405
|
let mockChat;
|
|
1192
1406
|
beforeEach(() => {
|
|
1193
|
-
vi.spyOn(client, 'tryCompressChat').mockResolvedValue(
|
|
1407
|
+
vi.spyOn(client, 'tryCompressChat').mockResolvedValue({
|
|
1408
|
+
originalTokenCount: 0,
|
|
1409
|
+
newTokenCount: 0,
|
|
1410
|
+
compressionStatus: CompressionStatus.COMPRESSED,
|
|
1411
|
+
});
|
|
1194
1412
|
const mockStream = (async function* () {
|
|
1195
1413
|
yield { type: 'content', value: 'response' };
|
|
1196
1414
|
})();
|
|
@@ -1453,8 +1671,89 @@ ${JSON.stringify({
|
|
|
1453
1671
|
expect(JSON.stringify(finalCall)).toContain('fileC.ts');
|
|
1454
1672
|
});
|
|
1455
1673
|
});
|
|
1674
|
+
it('should not call checkNextSpeaker when turn.run() yields an error', async () => {
|
|
1675
|
+
// Arrange
|
|
1676
|
+
const { checkNextSpeaker } = await import('../utils/nextSpeakerChecker.js');
|
|
1677
|
+
const mockCheckNextSpeaker = vi.mocked(checkNextSpeaker);
|
|
1678
|
+
const mockStream = (async function* () {
|
|
1679
|
+
yield {
|
|
1680
|
+
type: GeminiEventType.Error,
|
|
1681
|
+
value: { error: { message: 'test error' } },
|
|
1682
|
+
};
|
|
1683
|
+
})();
|
|
1684
|
+
mockTurnRunFn.mockReturnValue(mockStream);
|
|
1685
|
+
const mockChat = {
|
|
1686
|
+
addHistory: vi.fn(),
|
|
1687
|
+
getHistory: vi.fn().mockReturnValue([]),
|
|
1688
|
+
};
|
|
1689
|
+
client['chat'] = mockChat;
|
|
1690
|
+
const mockGenerator = {
|
|
1691
|
+
countTokens: vi.fn().mockResolvedValue({ totalTokens: 0 }),
|
|
1692
|
+
generateContent: mockGenerateContentFn,
|
|
1693
|
+
};
|
|
1694
|
+
client['contentGenerator'] = mockGenerator;
|
|
1695
|
+
// Act
|
|
1696
|
+
const stream = client.sendMessageStream([{ text: 'Hi' }], new AbortController().signal, 'prompt-id-error');
|
|
1697
|
+
for await (const _ of stream) {
|
|
1698
|
+
// consume stream
|
|
1699
|
+
}
|
|
1700
|
+
// Assert
|
|
1701
|
+
expect(mockCheckNextSpeaker).not.toHaveBeenCalled();
|
|
1702
|
+
});
|
|
1703
|
+
it('should not call checkNextSpeaker when turn.run() yields a value then an error', async () => {
|
|
1704
|
+
// Arrange
|
|
1705
|
+
const { checkNextSpeaker } = await import('../utils/nextSpeakerChecker.js');
|
|
1706
|
+
const mockCheckNextSpeaker = vi.mocked(checkNextSpeaker);
|
|
1707
|
+
const mockStream = (async function* () {
|
|
1708
|
+
yield { type: GeminiEventType.Content, value: 'some content' };
|
|
1709
|
+
yield {
|
|
1710
|
+
type: GeminiEventType.Error,
|
|
1711
|
+
value: { error: { message: 'test error' } },
|
|
1712
|
+
};
|
|
1713
|
+
})();
|
|
1714
|
+
mockTurnRunFn.mockReturnValue(mockStream);
|
|
1715
|
+
const mockChat = {
|
|
1716
|
+
addHistory: vi.fn(),
|
|
1717
|
+
getHistory: vi.fn().mockReturnValue([]),
|
|
1718
|
+
};
|
|
1719
|
+
client['chat'] = mockChat;
|
|
1720
|
+
const mockGenerator = {
|
|
1721
|
+
countTokens: vi.fn().mockResolvedValue({ totalTokens: 0 }),
|
|
1722
|
+
generateContent: mockGenerateContentFn,
|
|
1723
|
+
};
|
|
1724
|
+
client['contentGenerator'] = mockGenerator;
|
|
1725
|
+
// Act
|
|
1726
|
+
const stream = client.sendMessageStream([{ text: 'Hi' }], new AbortController().signal, 'prompt-id-error');
|
|
1727
|
+
for await (const _ of stream) {
|
|
1728
|
+
// consume stream
|
|
1729
|
+
}
|
|
1730
|
+
// Assert
|
|
1731
|
+
expect(mockCheckNextSpeaker).not.toHaveBeenCalled();
|
|
1732
|
+
});
|
|
1456
1733
|
});
|
|
1457
1734
|
describe('generateContent', () => {
|
|
1735
|
+
it('should call generateContent with the correct parameters', async () => {
|
|
1736
|
+
const contents = [{ role: 'user', parts: [{ text: 'hello' }] }];
|
|
1737
|
+
const generationConfig = { temperature: 0.5 };
|
|
1738
|
+
const abortSignal = new AbortController().signal;
|
|
1739
|
+
// Mock countTokens
|
|
1740
|
+
const mockGenerator = {
|
|
1741
|
+
countTokens: vi.fn().mockResolvedValue({ totalTokens: 1 }),
|
|
1742
|
+
generateContent: mockGenerateContentFn,
|
|
1743
|
+
};
|
|
1744
|
+
client['contentGenerator'] = mockGenerator;
|
|
1745
|
+
await client.generateContent(contents, generationConfig, abortSignal);
|
|
1746
|
+
expect(mockGenerateContentFn).toHaveBeenCalledWith({
|
|
1747
|
+
model: 'test-model',
|
|
1748
|
+
config: {
|
|
1749
|
+
abortSignal,
|
|
1750
|
+
systemInstruction: getCoreSystemPrompt(''),
|
|
1751
|
+
temperature: 0.5,
|
|
1752
|
+
topP: 1,
|
|
1753
|
+
},
|
|
1754
|
+
contents,
|
|
1755
|
+
}, 'test-session-id');
|
|
1756
|
+
});
|
|
1458
1757
|
it('should use current model from config for content generation', async () => {
|
|
1459
1758
|
const initialModel = client['config'].getModel();
|
|
1460
1759
|
const contents = [{ role: 'user', parts: [{ text: 'test' }] }];
|
|
@@ -1478,51 +1777,6 @@ ${JSON.stringify({
|
|
|
1478
1777
|
}, 'test-session-id');
|
|
1479
1778
|
});
|
|
1480
1779
|
});
|
|
1481
|
-
describe('tryCompressChat', () => {
|
|
1482
|
-
it('should use current model from config for token counting after sendMessage', async () => {
|
|
1483
|
-
const initialModel = client['config'].getModel();
|
|
1484
|
-
const mockCountTokens = vi
|
|
1485
|
-
.fn()
|
|
1486
|
-
.mockResolvedValueOnce({ totalTokens: 100000 })
|
|
1487
|
-
.mockResolvedValueOnce({ totalTokens: 5000 });
|
|
1488
|
-
const mockSendMessage = vi.fn().mockResolvedValue({ text: 'Summary' });
|
|
1489
|
-
const mockChatHistory = [
|
|
1490
|
-
{ role: 'user', parts: [{ text: 'Long conversation' }] },
|
|
1491
|
-
{ role: 'model', parts: [{ text: 'Long response' }] },
|
|
1492
|
-
];
|
|
1493
|
-
const mockChat = {
|
|
1494
|
-
getHistory: vi.fn().mockReturnValue(mockChatHistory),
|
|
1495
|
-
setHistory: vi.fn(),
|
|
1496
|
-
sendMessage: mockSendMessage,
|
|
1497
|
-
};
|
|
1498
|
-
const mockGenerator = {
|
|
1499
|
-
countTokens: mockCountTokens,
|
|
1500
|
-
};
|
|
1501
|
-
// mock the model has been changed between calls of `countTokens`
|
|
1502
|
-
const firstCurrentModel = initialModel + '-changed-1';
|
|
1503
|
-
const secondCurrentModel = initialModel + '-changed-2';
|
|
1504
|
-
vi.spyOn(client['config'], 'getModel')
|
|
1505
|
-
.mockReturnValueOnce(firstCurrentModel)
|
|
1506
|
-
.mockReturnValueOnce(secondCurrentModel);
|
|
1507
|
-
client['chat'] = mockChat;
|
|
1508
|
-
client['contentGenerator'] = mockGenerator;
|
|
1509
|
-
client['startChat'] = vi.fn().mockResolvedValue(mockChat);
|
|
1510
|
-
const result = await client.tryCompressChat('prompt-id-4', true);
|
|
1511
|
-
expect(mockCountTokens).toHaveBeenCalledTimes(2);
|
|
1512
|
-
expect(mockCountTokens).toHaveBeenNthCalledWith(1, {
|
|
1513
|
-
model: firstCurrentModel,
|
|
1514
|
-
contents: mockChatHistory,
|
|
1515
|
-
});
|
|
1516
|
-
expect(mockCountTokens).toHaveBeenNthCalledWith(2, {
|
|
1517
|
-
model: secondCurrentModel,
|
|
1518
|
-
contents: expect.any(Array),
|
|
1519
|
-
});
|
|
1520
|
-
expect(result).toEqual({
|
|
1521
|
-
originalTokenCount: 100000,
|
|
1522
|
-
newTokenCount: 5000,
|
|
1523
|
-
});
|
|
1524
|
-
});
|
|
1525
|
-
});
|
|
1526
1780
|
describe('handleFlashFallback', () => {
|
|
1527
1781
|
it('should use current model from config when checking for fallback', async () => {
|
|
1528
1782
|
const initialModel = client['config'].getModel();
|