@google/gemini-cli-core 0.3.0-nightly.20250823.1a89d185 → 0.3.0-preview.1
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/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
|
@@ -14,15 +14,15 @@ const mockModelsModule = {
|
|
|
14
14
|
embedContent: vi.fn(),
|
|
15
15
|
batchEmbedContents: vi.fn(),
|
|
16
16
|
};
|
|
17
|
-
const {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
17
|
+
const { mockLogInvalidChunk, mockLogContentRetry, mockLogContentRetryFailure } = vi.hoisted(() => ({
|
|
18
|
+
mockLogInvalidChunk: vi.fn(),
|
|
19
|
+
mockLogContentRetry: vi.fn(),
|
|
20
|
+
mockLogContentRetryFailure: vi.fn(),
|
|
21
21
|
}));
|
|
22
|
-
vi.mock('../telemetry/
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
22
|
+
vi.mock('../telemetry/loggers.js', () => ({
|
|
23
|
+
logInvalidChunk: mockLogInvalidChunk,
|
|
24
|
+
logContentRetry: mockLogContentRetry,
|
|
25
|
+
logContentRetryFailure: mockLogContentRetryFailure,
|
|
26
26
|
}));
|
|
27
27
|
describe('GeminiChat', () => {
|
|
28
28
|
let chat;
|
|
@@ -55,6 +55,110 @@ describe('GeminiChat', () => {
|
|
|
55
55
|
vi.resetAllMocks();
|
|
56
56
|
});
|
|
57
57
|
describe('sendMessage', () => {
|
|
58
|
+
it('should throw an error when attempting to add a user turn after another user turn', async () => {
|
|
59
|
+
// 1. Setup: Create a history that already ends with a user turn (a functionResponse).
|
|
60
|
+
const initialHistory = [
|
|
61
|
+
{ role: 'user', parts: [{ text: 'Initial prompt' }] },
|
|
62
|
+
{
|
|
63
|
+
role: 'model',
|
|
64
|
+
parts: [{ functionCall: { name: 'test_tool', args: {} } }],
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
role: 'user',
|
|
68
|
+
parts: [{ functionResponse: { name: 'test_tool', response: {} } }],
|
|
69
|
+
},
|
|
70
|
+
];
|
|
71
|
+
chat.setHistory(initialHistory);
|
|
72
|
+
// 2. Mock a valid model response so the call doesn't fail for other reasons.
|
|
73
|
+
const mockResponse = {
|
|
74
|
+
candidates: [
|
|
75
|
+
{ content: { role: 'model', parts: [{ text: 'some response' }] } },
|
|
76
|
+
],
|
|
77
|
+
};
|
|
78
|
+
vi.mocked(mockModelsModule.generateContent).mockResolvedValue(mockResponse);
|
|
79
|
+
// 3. Action & Assert: Expect that sending another user message immediately
|
|
80
|
+
// after a user-role turn throws the specific error.
|
|
81
|
+
await expect(chat.sendMessage({ message: 'This is an invalid consecutive user message' }, 'prompt-id-1')).rejects.toThrow('Cannot add a user turn after another user turn.');
|
|
82
|
+
});
|
|
83
|
+
it('should preserve text parts that are in the same response as a thought', async () => {
|
|
84
|
+
// 1. Mock the API to return a single response containing both a thought and visible text.
|
|
85
|
+
const mixedContentResponse = {
|
|
86
|
+
candidates: [
|
|
87
|
+
{
|
|
88
|
+
content: {
|
|
89
|
+
role: 'model',
|
|
90
|
+
parts: [
|
|
91
|
+
{ thought: 'This is a thought.' },
|
|
92
|
+
{ text: 'This is the visible text that should not be lost.' },
|
|
93
|
+
],
|
|
94
|
+
},
|
|
95
|
+
},
|
|
96
|
+
],
|
|
97
|
+
};
|
|
98
|
+
vi.mocked(mockModelsModule.generateContent).mockResolvedValue(mixedContentResponse);
|
|
99
|
+
// 2. Action: Send a standard, non-streaming message.
|
|
100
|
+
await chat.sendMessage({ message: 'test message' }, 'prompt-id-mixed-response');
|
|
101
|
+
// 3. Assert: Check the final state of the history.
|
|
102
|
+
const history = chat.getHistory();
|
|
103
|
+
// The history should contain two turns: the user's message and the model's response.
|
|
104
|
+
expect(history.length).toBe(2);
|
|
105
|
+
const modelTurn = history[1];
|
|
106
|
+
expect(modelTurn.role).toBe('model');
|
|
107
|
+
// CRUCIAL ASSERTION:
|
|
108
|
+
// Buggy code would discard the entire response because a "thought" was present,
|
|
109
|
+
// resulting in an empty placeholder turn with 0 parts.
|
|
110
|
+
// The corrected code will pass, preserving the single visible text part.
|
|
111
|
+
expect(modelTurn?.parts?.length).toBe(1);
|
|
112
|
+
expect(modelTurn?.parts[0].text).toBe('This is the visible text that should not be lost.');
|
|
113
|
+
});
|
|
114
|
+
it('should add a placeholder model turn when a tool call is followed by an empty model response', async () => {
|
|
115
|
+
// 1. Setup: A history where the model has just made a function call.
|
|
116
|
+
const initialHistory = [
|
|
117
|
+
{
|
|
118
|
+
role: 'user',
|
|
119
|
+
parts: [{ text: 'Find a good Italian restaurant for me.' }],
|
|
120
|
+
},
|
|
121
|
+
{
|
|
122
|
+
role: 'model',
|
|
123
|
+
parts: [
|
|
124
|
+
{
|
|
125
|
+
functionCall: {
|
|
126
|
+
name: 'find_restaurant',
|
|
127
|
+
args: { cuisine: 'Italian' },
|
|
128
|
+
},
|
|
129
|
+
},
|
|
130
|
+
],
|
|
131
|
+
},
|
|
132
|
+
];
|
|
133
|
+
chat.setHistory(initialHistory);
|
|
134
|
+
// 2. Mock the API to return an empty/thought-only response.
|
|
135
|
+
const emptyModelResponse = {
|
|
136
|
+
candidates: [
|
|
137
|
+
{ content: { role: 'model', parts: [{ thought: true }] } },
|
|
138
|
+
],
|
|
139
|
+
};
|
|
140
|
+
vi.mocked(mockModelsModule.generateContent).mockResolvedValue(emptyModelResponse);
|
|
141
|
+
// 3. Action: Send the function response back to the model.
|
|
142
|
+
await chat.sendMessage({
|
|
143
|
+
message: {
|
|
144
|
+
functionResponse: {
|
|
145
|
+
name: 'find_restaurant',
|
|
146
|
+
response: { name: 'Vesuvio' },
|
|
147
|
+
},
|
|
148
|
+
},
|
|
149
|
+
}, 'prompt-id-1');
|
|
150
|
+
// 4. Assert: The history should now have four valid, alternating turns.
|
|
151
|
+
const history = chat.getHistory();
|
|
152
|
+
expect(history.length).toBe(4);
|
|
153
|
+
// The final turn must be the empty model placeholder.
|
|
154
|
+
const lastTurn = history[3];
|
|
155
|
+
expect(lastTurn.role).toBe('model');
|
|
156
|
+
expect(lastTurn?.parts?.length).toBe(0);
|
|
157
|
+
// The second-to-last turn must be the function response we sent.
|
|
158
|
+
const secondToLastTurn = history[2];
|
|
159
|
+
expect(secondToLastTurn.role).toBe('user');
|
|
160
|
+
expect(secondToLastTurn?.parts[0].functionResponse).toBeDefined();
|
|
161
|
+
});
|
|
58
162
|
it('should call generateContent with the correct parameters', async () => {
|
|
59
163
|
const response = {
|
|
60
164
|
candidates: [
|
|
@@ -80,6 +184,226 @@ describe('GeminiChat', () => {
|
|
|
80
184
|
});
|
|
81
185
|
});
|
|
82
186
|
describe('sendMessageStream', () => {
|
|
187
|
+
it('should not consolidate text into a part that also contains a functionCall', async () => {
|
|
188
|
+
// 1. Mock the API to stream a malformed part followed by a valid text part.
|
|
189
|
+
const multiChunkStream = (async function* () {
|
|
190
|
+
// This malformed part has both text and a functionCall.
|
|
191
|
+
yield {
|
|
192
|
+
candidates: [
|
|
193
|
+
{
|
|
194
|
+
content: {
|
|
195
|
+
role: 'model',
|
|
196
|
+
parts: [
|
|
197
|
+
{
|
|
198
|
+
text: 'Some text',
|
|
199
|
+
functionCall: { name: 'do_stuff', args: {} },
|
|
200
|
+
},
|
|
201
|
+
],
|
|
202
|
+
},
|
|
203
|
+
},
|
|
204
|
+
],
|
|
205
|
+
};
|
|
206
|
+
// This valid text part should NOT be merged into the malformed one.
|
|
207
|
+
yield {
|
|
208
|
+
candidates: [
|
|
209
|
+
{
|
|
210
|
+
content: {
|
|
211
|
+
role: 'model',
|
|
212
|
+
parts: [{ text: ' that should not be merged.' }],
|
|
213
|
+
},
|
|
214
|
+
},
|
|
215
|
+
],
|
|
216
|
+
};
|
|
217
|
+
})();
|
|
218
|
+
vi.mocked(mockModelsModule.generateContentStream).mockResolvedValue(multiChunkStream);
|
|
219
|
+
// 2. Action: Send a message and consume the stream.
|
|
220
|
+
const stream = await chat.sendMessageStream({ message: 'test message' }, 'prompt-id-malformed-chunk');
|
|
221
|
+
for await (const _ of stream) {
|
|
222
|
+
// Consume the stream to trigger history recording.
|
|
223
|
+
}
|
|
224
|
+
// 3. Assert: Check that the final history was not incorrectly consolidated.
|
|
225
|
+
const history = chat.getHistory();
|
|
226
|
+
expect(history.length).toBe(2);
|
|
227
|
+
const modelTurn = history[1];
|
|
228
|
+
// CRUCIAL ASSERTION: There should be two separate parts.
|
|
229
|
+
// The old, non-strict logic would incorrectly merge them, resulting in one part.
|
|
230
|
+
expect(modelTurn?.parts?.length).toBe(2);
|
|
231
|
+
// Verify the contents of each part.
|
|
232
|
+
expect(modelTurn?.parts[0].text).toBe('Some text');
|
|
233
|
+
expect(modelTurn?.parts[0].functionCall).toBeDefined();
|
|
234
|
+
expect(modelTurn?.parts[1].text).toBe(' that should not be merged.');
|
|
235
|
+
});
|
|
236
|
+
it('should consolidate subsequent text chunks after receiving an empty text chunk', async () => {
|
|
237
|
+
// 1. Mock the API to return a stream where one chunk is just an empty text part.
|
|
238
|
+
const multiChunkStream = (async function* () {
|
|
239
|
+
yield {
|
|
240
|
+
candidates: [
|
|
241
|
+
{ content: { role: 'model', parts: [{ text: 'Hello' }] } },
|
|
242
|
+
],
|
|
243
|
+
};
|
|
244
|
+
// FIX: The original test used { text: '' }, which is invalid.
|
|
245
|
+
// A chunk can be empty but still valid. This chunk is now removed
|
|
246
|
+
// as the important part is consolidating what comes after.
|
|
247
|
+
yield {
|
|
248
|
+
candidates: [
|
|
249
|
+
{ content: { role: 'model', parts: [{ text: ' World!' }] } },
|
|
250
|
+
],
|
|
251
|
+
};
|
|
252
|
+
})();
|
|
253
|
+
vi.mocked(mockModelsModule.generateContentStream).mockResolvedValue(multiChunkStream);
|
|
254
|
+
// 2. Action: Send a message and consume the stream.
|
|
255
|
+
const stream = await chat.sendMessageStream({ message: 'test message' }, 'prompt-id-empty-chunk-consolidation');
|
|
256
|
+
for await (const _ of stream) {
|
|
257
|
+
// Consume the stream
|
|
258
|
+
}
|
|
259
|
+
// 3. Assert: Check that the final history was correctly consolidated.
|
|
260
|
+
const history = chat.getHistory();
|
|
261
|
+
expect(history.length).toBe(2);
|
|
262
|
+
const modelTurn = history[1];
|
|
263
|
+
expect(modelTurn?.parts?.length).toBe(1);
|
|
264
|
+
expect(modelTurn?.parts[0].text).toBe('Hello World!');
|
|
265
|
+
});
|
|
266
|
+
it('should consolidate adjacent text parts that arrive in separate stream chunks', async () => {
|
|
267
|
+
// 1. Mock the API to return a stream of multiple, adjacent text chunks.
|
|
268
|
+
const multiChunkStream = (async function* () {
|
|
269
|
+
yield {
|
|
270
|
+
candidates: [
|
|
271
|
+
{ content: { role: 'model', parts: [{ text: 'This is the ' }] } },
|
|
272
|
+
],
|
|
273
|
+
};
|
|
274
|
+
yield {
|
|
275
|
+
candidates: [
|
|
276
|
+
{ content: { role: 'model', parts: [{ text: 'first part.' }] } },
|
|
277
|
+
],
|
|
278
|
+
};
|
|
279
|
+
// This function call should break the consolidation.
|
|
280
|
+
yield {
|
|
281
|
+
candidates: [
|
|
282
|
+
{
|
|
283
|
+
content: {
|
|
284
|
+
role: 'model',
|
|
285
|
+
parts: [{ functionCall: { name: 'do_stuff', args: {} } }],
|
|
286
|
+
},
|
|
287
|
+
},
|
|
288
|
+
],
|
|
289
|
+
};
|
|
290
|
+
yield {
|
|
291
|
+
candidates: [
|
|
292
|
+
{
|
|
293
|
+
content: {
|
|
294
|
+
role: 'model',
|
|
295
|
+
parts: [{ text: 'This is the second part.' }],
|
|
296
|
+
},
|
|
297
|
+
},
|
|
298
|
+
],
|
|
299
|
+
};
|
|
300
|
+
})();
|
|
301
|
+
vi.mocked(mockModelsModule.generateContentStream).mockResolvedValue(multiChunkStream);
|
|
302
|
+
// 2. Action: Send a message and consume the stream.
|
|
303
|
+
const stream = await chat.sendMessageStream({ message: 'test message' }, 'prompt-id-multi-chunk');
|
|
304
|
+
for await (const _ of stream) {
|
|
305
|
+
// Consume the stream to trigger history recording.
|
|
306
|
+
}
|
|
307
|
+
// 3. Assert: Check that the final history was correctly consolidated.
|
|
308
|
+
const history = chat.getHistory();
|
|
309
|
+
// The history should contain the user's turn and ONE consolidated model turn.
|
|
310
|
+
expect(history.length).toBe(2);
|
|
311
|
+
const modelTurn = history[1];
|
|
312
|
+
expect(modelTurn.role).toBe('model');
|
|
313
|
+
// The model turn should have 3 distinct parts: the merged text, the function call, and the final text.
|
|
314
|
+
expect(modelTurn?.parts?.length).toBe(3);
|
|
315
|
+
expect(modelTurn?.parts[0].text).toBe('This is the first part.');
|
|
316
|
+
expect(modelTurn.parts[1].functionCall).toBeDefined();
|
|
317
|
+
expect(modelTurn.parts[2].text).toBe('This is the second part.');
|
|
318
|
+
});
|
|
319
|
+
it('should preserve text parts that stream in the same chunk as a thought', async () => {
|
|
320
|
+
// 1. Mock the API to return a single chunk containing both a thought and visible text.
|
|
321
|
+
const mixedContentStream = (async function* () {
|
|
322
|
+
yield {
|
|
323
|
+
candidates: [
|
|
324
|
+
{
|
|
325
|
+
content: {
|
|
326
|
+
role: 'model',
|
|
327
|
+
parts: [
|
|
328
|
+
{ thought: 'This is a thought.' },
|
|
329
|
+
{ text: 'This is the visible text that should not be lost.' },
|
|
330
|
+
],
|
|
331
|
+
},
|
|
332
|
+
},
|
|
333
|
+
],
|
|
334
|
+
};
|
|
335
|
+
})();
|
|
336
|
+
vi.mocked(mockModelsModule.generateContentStream).mockResolvedValue(mixedContentStream);
|
|
337
|
+
// 2. Action: Send a message and fully consume the stream to trigger history recording.
|
|
338
|
+
const stream = await chat.sendMessageStream({ message: 'test message' }, 'prompt-id-mixed-chunk');
|
|
339
|
+
for await (const _ of stream) {
|
|
340
|
+
// This loop consumes the stream.
|
|
341
|
+
}
|
|
342
|
+
// 3. Assert: Check the final state of the history.
|
|
343
|
+
const history = chat.getHistory();
|
|
344
|
+
// The history should contain two turns: the user's message and the model's response.
|
|
345
|
+
expect(history.length).toBe(2);
|
|
346
|
+
const modelTurn = history[1];
|
|
347
|
+
expect(modelTurn.role).toBe('model');
|
|
348
|
+
// CRUCIAL ASSERTION:
|
|
349
|
+
// The buggy code would fail here, resulting in parts.length being 0.
|
|
350
|
+
// The corrected code will pass, preserving the single visible text part.
|
|
351
|
+
expect(modelTurn?.parts?.length).toBe(1);
|
|
352
|
+
expect(modelTurn?.parts[0].text).toBe('This is the visible text that should not be lost.');
|
|
353
|
+
});
|
|
354
|
+
it('should add a placeholder model turn when a tool call is followed by an empty stream response', async () => {
|
|
355
|
+
// 1. Setup: A history where the model has just made a function call.
|
|
356
|
+
const initialHistory = [
|
|
357
|
+
{
|
|
358
|
+
role: 'user',
|
|
359
|
+
parts: [{ text: 'Find a good Italian restaurant for me.' }],
|
|
360
|
+
},
|
|
361
|
+
{
|
|
362
|
+
role: 'model',
|
|
363
|
+
parts: [
|
|
364
|
+
{
|
|
365
|
+
functionCall: {
|
|
366
|
+
name: 'find_restaurant',
|
|
367
|
+
args: { cuisine: 'Italian' },
|
|
368
|
+
},
|
|
369
|
+
},
|
|
370
|
+
],
|
|
371
|
+
},
|
|
372
|
+
];
|
|
373
|
+
chat.setHistory(initialHistory);
|
|
374
|
+
// 2. Mock the API to return an empty/thought-only stream.
|
|
375
|
+
const emptyStreamResponse = (async function* () {
|
|
376
|
+
yield {
|
|
377
|
+
candidates: [
|
|
378
|
+
{ content: { role: 'model', parts: [{ thought: true }] } },
|
|
379
|
+
],
|
|
380
|
+
};
|
|
381
|
+
})();
|
|
382
|
+
vi.mocked(mockModelsModule.generateContentStream).mockResolvedValue(emptyStreamResponse);
|
|
383
|
+
// 3. Action: Send the function response back to the model and consume the stream.
|
|
384
|
+
const stream = await chat.sendMessageStream({
|
|
385
|
+
message: {
|
|
386
|
+
functionResponse: {
|
|
387
|
+
name: 'find_restaurant',
|
|
388
|
+
response: { name: 'Vesuvio' },
|
|
389
|
+
},
|
|
390
|
+
},
|
|
391
|
+
}, 'prompt-id-stream-1');
|
|
392
|
+
for await (const _ of stream) {
|
|
393
|
+
// This loop consumes the stream to trigger the internal logic.
|
|
394
|
+
}
|
|
395
|
+
// 4. Assert: The history should now have four valid, alternating turns.
|
|
396
|
+
const history = chat.getHistory();
|
|
397
|
+
expect(history.length).toBe(4);
|
|
398
|
+
// The final turn must be the empty model placeholder.
|
|
399
|
+
const lastTurn = history[3];
|
|
400
|
+
expect(lastTurn.role).toBe('model');
|
|
401
|
+
expect(lastTurn?.parts?.length).toBe(0);
|
|
402
|
+
// The second-to-last turn must be the function response we sent.
|
|
403
|
+
const secondToLastTurn = history[2];
|
|
404
|
+
expect(secondToLastTurn.role).toBe('user');
|
|
405
|
+
expect(secondToLastTurn?.parts[0].functionResponse).toBeDefined();
|
|
406
|
+
});
|
|
83
407
|
it('should call generateContentStream with the correct parameters', async () => {
|
|
84
408
|
const response = (async function* () {
|
|
85
409
|
yield {
|
|
@@ -114,295 +438,128 @@ describe('GeminiChat', () => {
|
|
|
114
438
|
role: 'user',
|
|
115
439
|
parts: [{ text: 'User input' }],
|
|
116
440
|
};
|
|
117
|
-
it('should
|
|
441
|
+
it('should consolidate all consecutive model turns into a single turn', () => {
|
|
442
|
+
const userInput = {
|
|
443
|
+
role: 'user',
|
|
444
|
+
parts: [{ text: 'User input' }],
|
|
445
|
+
};
|
|
446
|
+
// This simulates a multi-part model response with different part types.
|
|
118
447
|
const modelOutput = [
|
|
119
|
-
{ role: 'model', parts: [{ text: '
|
|
448
|
+
{ role: 'model', parts: [{ text: 'Thinking...' }] },
|
|
449
|
+
{
|
|
450
|
+
role: 'model',
|
|
451
|
+
parts: [{ functionCall: { name: 'do_stuff', args: {} } }],
|
|
452
|
+
},
|
|
120
453
|
];
|
|
121
|
-
// @ts-expect-error Accessing private method for testing
|
|
454
|
+
// @ts-expect-error Accessing private method for testing
|
|
122
455
|
chat.recordHistory(userInput, modelOutput);
|
|
123
456
|
const history = chat.getHistory();
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
const modelOutputParts = [
|
|
128
|
-
{ role: 'model', parts: [{ text: 'Model part 1' }] },
|
|
129
|
-
{ role: 'model', parts: [{ text: 'Model part 2' }] },
|
|
130
|
-
];
|
|
131
|
-
// @ts-expect-error Accessing private method for testing purposes
|
|
132
|
-
chat.recordHistory(userInput, modelOutputParts);
|
|
133
|
-
const history = chat.getHistory();
|
|
134
|
-
expect(history.length).toBe(2);
|
|
135
|
-
expect(history[0]).toEqual(userInput);
|
|
136
|
-
expect(history[1].role).toBe('model');
|
|
137
|
-
expect(history[1].parts).toEqual([{ text: 'Model part 1Model part 2' }]);
|
|
138
|
-
});
|
|
139
|
-
it('should handle a mix of user and model roles in outputContents (though unusual)', () => {
|
|
140
|
-
const mixedOutput = [
|
|
141
|
-
{ role: 'model', parts: [{ text: 'Model 1' }] },
|
|
142
|
-
{ role: 'user', parts: [{ text: 'Unexpected User' }] }, // This should be pushed as is
|
|
143
|
-
{ role: 'model', parts: [{ text: 'Model 2' }] },
|
|
144
|
-
];
|
|
145
|
-
// @ts-expect-error Accessing private method for testing purposes
|
|
146
|
-
chat.recordHistory(userInput, mixedOutput);
|
|
147
|
-
const history = chat.getHistory();
|
|
148
|
-
expect(history.length).toBe(4); // user, model1, user_unexpected, model2
|
|
149
|
-
expect(history[0]).toEqual(userInput);
|
|
150
|
-
expect(history[1]).toEqual(mixedOutput[0]);
|
|
151
|
-
expect(history[2]).toEqual(mixedOutput[1]);
|
|
152
|
-
expect(history[3]).toEqual(mixedOutput[2]);
|
|
153
|
-
});
|
|
154
|
-
it('should consolidate multiple adjacent model outputs correctly', () => {
|
|
155
|
-
const modelOutputParts = [
|
|
156
|
-
{ role: 'model', parts: [{ text: 'M1' }] },
|
|
157
|
-
{ role: 'model', parts: [{ text: 'M2' }] },
|
|
158
|
-
{ role: 'model', parts: [{ text: 'M3' }] },
|
|
159
|
-
];
|
|
160
|
-
// @ts-expect-error Accessing private method for testing purposes
|
|
161
|
-
chat.recordHistory(userInput, modelOutputParts);
|
|
162
|
-
const history = chat.getHistory();
|
|
457
|
+
// The history should contain the user's turn and ONE consolidated model turn.
|
|
458
|
+
// The old code would fail here, resulting in a length of 3.
|
|
459
|
+
//expect(history).toBe([]);
|
|
163
460
|
expect(history.length).toBe(2);
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
{ role: 'model', parts: [{ text: 'M2' }] },
|
|
171
|
-
];
|
|
172
|
-
// @ts-expect-error Accessing private method for testing purposes
|
|
173
|
-
chat.recordHistory(userInput, modelOutputParts);
|
|
174
|
-
const history = chat.getHistory();
|
|
175
|
-
expect(history.length).toBe(4); // user, M1, Interjecting User, M2
|
|
176
|
-
expect(history[1].parts).toEqual([{ text: 'M1' }]);
|
|
177
|
-
expect(history[3].parts).toEqual([{ text: 'M2' }]);
|
|
461
|
+
const modelTurn = history[1];
|
|
462
|
+
expect(modelTurn.role).toBe('model');
|
|
463
|
+
// The consolidated turn should contain both the text part and the functionCall part.
|
|
464
|
+
expect(modelTurn?.parts?.length).toBe(2);
|
|
465
|
+
expect(modelTurn?.parts[0].text).toBe('Thinking...');
|
|
466
|
+
expect(modelTurn?.parts[1].functionCall).toBeDefined();
|
|
178
467
|
});
|
|
179
|
-
it('should
|
|
180
|
-
//
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
{
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
{ role: 'model', parts: [{ text: 'New Model Part 2' }] },
|
|
188
|
-
];
|
|
189
|
-
// @ts-expect-error Accessing private method for testing purposes
|
|
190
|
-
chat.recordHistory(userInput, newModelOutput); // userInput here is for the *next* turn, but history is already primed
|
|
191
|
-
// Reset and set up a more realistic scenario for merging with existing history
|
|
192
|
-
chat = new GeminiChat(mockConfig, mockModelsModule, config, []);
|
|
193
|
-
const firstUserInput = {
|
|
194
|
-
role: 'user',
|
|
195
|
-
parts: [{ text: 'First user input' }],
|
|
196
|
-
};
|
|
197
|
-
const firstModelOutput = [
|
|
198
|
-
{ role: 'model', parts: [{ text: 'First model response' }] },
|
|
199
|
-
];
|
|
200
|
-
// @ts-expect-error Accessing private method for testing purposes
|
|
201
|
-
chat.recordHistory(firstUserInput, firstModelOutput);
|
|
202
|
-
const secondUserInput = {
|
|
203
|
-
role: 'user',
|
|
204
|
-
parts: [{ text: 'Second user input' }],
|
|
205
|
-
};
|
|
206
|
-
const secondModelOutput = [
|
|
207
|
-
{ role: 'model', parts: [{ text: 'Second model response part 1' }] },
|
|
208
|
-
{ role: 'model', parts: [{ text: 'Second model response part 2' }] },
|
|
468
|
+
it('should add a placeholder model turn when a tool call is followed by an empty response', () => {
|
|
469
|
+
// 1. Setup: A history where the model has just made a function call.
|
|
470
|
+
const initialHistory = [
|
|
471
|
+
{ role: 'user', parts: [{ text: 'Initial prompt' }] },
|
|
472
|
+
{
|
|
473
|
+
role: 'model',
|
|
474
|
+
parts: [{ functionCall: { name: 'test_tool', args: {} } }],
|
|
475
|
+
},
|
|
209
476
|
];
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
expect(finalHistory[0]).toEqual(firstUserInput);
|
|
215
|
-
expect(finalHistory[1]).toEqual(firstModelOutput[0]);
|
|
216
|
-
expect(finalHistory[2]).toEqual(secondUserInput);
|
|
217
|
-
expect(finalHistory[3].role).toBe('model');
|
|
218
|
-
expect(finalHistory[3].parts).toEqual([
|
|
219
|
-
{ text: 'Second model response part 1Second model response part 2' },
|
|
220
|
-
]);
|
|
221
|
-
});
|
|
222
|
-
it('should correctly merge consolidated new output with existing model history', () => {
|
|
223
|
-
// Setup: history ends with a model turn
|
|
224
|
-
const initialUser = {
|
|
477
|
+
chat.setHistory(initialHistory);
|
|
478
|
+
// 2. Action: The user provides the tool's response, and the model's
|
|
479
|
+
// final output is empty (e.g., just a thought, which gets filtered out).
|
|
480
|
+
const functionResponse = {
|
|
225
481
|
role: 'user',
|
|
226
|
-
parts: [{
|
|
482
|
+
parts: [{ functionResponse: { name: 'test_tool', response: {} } }],
|
|
227
483
|
};
|
|
228
|
-
const
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
chat = new GeminiChat(mockConfig, mockModelsModule, config, [
|
|
233
|
-
initialUser,
|
|
234
|
-
initialModel,
|
|
484
|
+
const emptyModelOutput = [];
|
|
485
|
+
// @ts-expect-error Accessing private method for testing
|
|
486
|
+
chat.recordHistory(functionResponse, emptyModelOutput, [
|
|
487
|
+
functionResponse,
|
|
235
488
|
]);
|
|
236
|
-
//
|
|
237
|
-
const currentUserInput = {
|
|
238
|
-
role: 'user',
|
|
239
|
-
parts: [{ text: 'Follow-up question' }],
|
|
240
|
-
};
|
|
241
|
-
const newModelParts = [
|
|
242
|
-
{ role: 'model', parts: [{ text: 'Part A of new answer.' }] },
|
|
243
|
-
{ role: 'model', parts: [{ text: 'Part B of new answer.' }] },
|
|
244
|
-
];
|
|
245
|
-
// @ts-expect-error Accessing private method for testing purposes
|
|
246
|
-
chat.recordHistory(currentUserInput, newModelParts);
|
|
489
|
+
// 3. Assert: The history should now have four valid, alternating turns.
|
|
247
490
|
const history = chat.getHistory();
|
|
248
|
-
// Expected: initialUser, initialModel, currentUserInput, consolidatedNewModelParts
|
|
249
491
|
expect(history.length).toBe(4);
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
expect(
|
|
253
|
-
expect(
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
it('should handle empty modelOutput array', () => {
|
|
259
|
-
// @ts-expect-error Accessing private method for testing purposes
|
|
260
|
-
chat.recordHistory(userInput, []);
|
|
261
|
-
const history = chat.getHistory();
|
|
262
|
-
// If modelOutput is empty, it might push a default empty model part depending on isFunctionResponse
|
|
263
|
-
// Assuming isFunctionResponse(userInput) is false for this simple text input
|
|
264
|
-
expect(history.length).toBe(2);
|
|
265
|
-
expect(history[0]).toEqual(userInput);
|
|
266
|
-
expect(history[1].role).toBe('model');
|
|
267
|
-
expect(history[1].parts).toEqual([]);
|
|
268
|
-
});
|
|
269
|
-
it('should handle aggregating modelOutput', () => {
|
|
270
|
-
const modelOutputUndefinedParts = [
|
|
271
|
-
{ role: 'model', parts: [{ text: 'First model part' }] },
|
|
272
|
-
{ role: 'model', parts: [{ text: 'Second model part' }] },
|
|
273
|
-
{ role: 'model', parts: undefined }, // Test undefined parts
|
|
274
|
-
{ role: 'model', parts: [{ text: 'Third model part' }] },
|
|
275
|
-
{ role: 'model', parts: [] }, // Test empty parts array
|
|
276
|
-
];
|
|
277
|
-
// @ts-expect-error Accessing private method for testing purposes
|
|
278
|
-
chat.recordHistory(userInput, modelOutputUndefinedParts);
|
|
279
|
-
const history = chat.getHistory();
|
|
280
|
-
expect(history.length).toBe(5);
|
|
281
|
-
expect(history[0]).toEqual(userInput);
|
|
282
|
-
expect(history[1].role).toBe('model');
|
|
283
|
-
expect(history[1].parts).toEqual([
|
|
284
|
-
{ text: 'First model partSecond model part' },
|
|
285
|
-
]);
|
|
286
|
-
expect(history[2].role).toBe('model');
|
|
287
|
-
expect(history[2].parts).toBeUndefined();
|
|
288
|
-
expect(history[3].role).toBe('model');
|
|
289
|
-
expect(history[3].parts).toEqual([{ text: 'Third model part' }]);
|
|
290
|
-
expect(history[4].role).toBe('model');
|
|
291
|
-
expect(history[4].parts).toEqual([]);
|
|
292
|
-
});
|
|
293
|
-
it('should handle modelOutput with parts being undefined or empty (if they pass initial every check)', () => {
|
|
294
|
-
const modelOutputUndefinedParts = [
|
|
295
|
-
{ role: 'model', parts: [{ text: 'Text part' }] },
|
|
296
|
-
{ role: 'model', parts: undefined }, // Test undefined parts
|
|
297
|
-
{ role: 'model', parts: [] }, // Test empty parts array
|
|
298
|
-
];
|
|
299
|
-
// @ts-expect-error Accessing private method for testing purposes
|
|
300
|
-
chat.recordHistory(userInput, modelOutputUndefinedParts);
|
|
301
|
-
const history = chat.getHistory();
|
|
302
|
-
expect(history.length).toBe(4); // userInput, model1 (text), model2 (undefined parts), model3 (empty parts)
|
|
303
|
-
expect(history[0]).toEqual(userInput);
|
|
304
|
-
expect(history[1].role).toBe('model');
|
|
305
|
-
expect(history[1].parts).toEqual([{ text: 'Text part' }]);
|
|
306
|
-
expect(history[2].role).toBe('model');
|
|
307
|
-
expect(history[2].parts).toBeUndefined();
|
|
308
|
-
expect(history[3].role).toBe('model');
|
|
309
|
-
expect(history[3].parts).toEqual([]);
|
|
492
|
+
// The final turn must be the empty model placeholder.
|
|
493
|
+
const lastTurn = history[3];
|
|
494
|
+
expect(lastTurn.role).toBe('model');
|
|
495
|
+
expect(lastTurn?.parts?.length).toBe(0);
|
|
496
|
+
// The second-to-last turn must be the function response we provided.
|
|
497
|
+
const secondToLastTurn = history[2];
|
|
498
|
+
expect(secondToLastTurn.role).toBe('user');
|
|
499
|
+
expect(secondToLastTurn?.parts[0].functionResponse).toBeDefined();
|
|
310
500
|
});
|
|
311
|
-
it('should
|
|
312
|
-
const afcHistory = [
|
|
313
|
-
{ role: 'user', parts: [{ text: 'AFC User' }] },
|
|
314
|
-
{ role: 'model', parts: [{ text: 'AFC Model' }] },
|
|
315
|
-
];
|
|
316
|
-
const modelOutput = [
|
|
317
|
-
{ role: 'model', parts: [{ text: 'Regular Model Output' }] },
|
|
318
|
-
];
|
|
319
|
-
// @ts-expect-error Accessing private method for testing purposes
|
|
320
|
-
chat.recordHistory(userInput, modelOutput, afcHistory);
|
|
321
|
-
const history = chat.getHistory();
|
|
322
|
-
expect(history.length).toBe(3);
|
|
323
|
-
expect(history[0]).toEqual(afcHistory[0]);
|
|
324
|
-
expect(history[1]).toEqual(afcHistory[1]);
|
|
325
|
-
expect(history[2]).toEqual(modelOutput[0]);
|
|
326
|
-
});
|
|
327
|
-
it('should add userInput if AFC history is present but empty', () => {
|
|
501
|
+
it('should add user input and a single model output to history', () => {
|
|
328
502
|
const modelOutput = [
|
|
329
|
-
{ role: 'model', parts: [{ text: 'Model
|
|
503
|
+
{ role: 'model', parts: [{ text: 'Model output' }] },
|
|
330
504
|
];
|
|
331
|
-
// @ts-expect-error Accessing private method for testing
|
|
332
|
-
chat.recordHistory(userInput, modelOutput
|
|
505
|
+
// @ts-expect-error Accessing private method for testing
|
|
506
|
+
chat.recordHistory(userInput, modelOutput);
|
|
333
507
|
const history = chat.getHistory();
|
|
334
508
|
expect(history.length).toBe(2);
|
|
335
509
|
expect(history[0]).toEqual(userInput);
|
|
336
510
|
expect(history[1]).toEqual(modelOutput[0]);
|
|
337
511
|
});
|
|
338
|
-
it('should
|
|
339
|
-
const
|
|
340
|
-
{ role: 'model', parts: [{
|
|
341
|
-
{ role: 'model', parts: [{ text: '
|
|
512
|
+
it('should consolidate adjacent text parts from multiple content objects', () => {
|
|
513
|
+
const modelOutput = [
|
|
514
|
+
{ role: 'model', parts: [{ text: 'Part 1.' }] },
|
|
515
|
+
{ role: 'model', parts: [{ text: ' Part 2.' }] },
|
|
516
|
+
{ role: 'model', parts: [{ text: ' Part 3.' }] },
|
|
342
517
|
];
|
|
343
|
-
// @ts-expect-error Accessing private method for testing
|
|
344
|
-
chat.recordHistory(userInput,
|
|
518
|
+
// @ts-expect-error Accessing private method for testing
|
|
519
|
+
chat.recordHistory(userInput, modelOutput);
|
|
345
520
|
const history = chat.getHistory();
|
|
346
|
-
expect(history.length).toBe(2);
|
|
347
|
-
expect(history[0]).toEqual(userInput);
|
|
521
|
+
expect(history.length).toBe(2);
|
|
348
522
|
expect(history[1].role).toBe('model');
|
|
349
|
-
|
|
350
|
-
expect(history[1].parts).toEqual([{ text: 'Another visible text' }]);
|
|
351
|
-
});
|
|
352
|
-
it('should skip "thought" content even if it is the only content', () => {
|
|
353
|
-
const modelOutputOnlyThought = [
|
|
354
|
-
{ role: 'model', parts: [{ thought: true }] },
|
|
355
|
-
];
|
|
356
|
-
// @ts-expect-error Accessing private method for testing purposes
|
|
357
|
-
chat.recordHistory(userInput, modelOutputOnlyThought);
|
|
358
|
-
const history = chat.getHistory();
|
|
359
|
-
expect(history.length).toBe(1); // User input + default empty model part
|
|
360
|
-
expect(history[0]).toEqual(userInput);
|
|
523
|
+
expect(history[1].parts).toEqual([{ text: 'Part 1. Part 2. Part 3.' }]);
|
|
361
524
|
});
|
|
362
|
-
it('should
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
parts: [{ thought: true }, { text: 'Should be skipped' }],
|
|
368
|
-
},
|
|
369
|
-
{ role: 'model', parts: [{ text: 'Part 2.' }] },
|
|
370
|
-
];
|
|
371
|
-
// @ts-expect-error Accessing private method for testing purposes
|
|
372
|
-
chat.recordHistory(userInput, modelOutputMixed);
|
|
525
|
+
it('should add an empty placeholder turn if modelOutput is empty', () => {
|
|
526
|
+
// This simulates receiving a pre-filtered, thought-only response.
|
|
527
|
+
const emptyModelOutput = [];
|
|
528
|
+
// @ts-expect-error Accessing private method for testing
|
|
529
|
+
chat.recordHistory(userInput, emptyModelOutput);
|
|
373
530
|
const history = chat.getHistory();
|
|
374
531
|
expect(history.length).toBe(2);
|
|
375
532
|
expect(history[0]).toEqual(userInput);
|
|
376
533
|
expect(history[1].role).toBe('model');
|
|
377
|
-
expect(history[1].parts).toEqual([
|
|
534
|
+
expect(history[1].parts).toEqual([]);
|
|
378
535
|
});
|
|
379
|
-
it('should
|
|
380
|
-
const
|
|
381
|
-
{ role: 'model', parts: [{
|
|
382
|
-
{ role: 'model', parts:
|
|
383
|
-
{ role: 'model', parts: [
|
|
384
|
-
{ role: 'model', parts: [{ text: 'Visible 2' }] },
|
|
536
|
+
it('should preserve model outputs with undefined or empty parts arrays', () => {
|
|
537
|
+
const malformedOutput = [
|
|
538
|
+
{ role: 'model', parts: [{ text: 'Text part' }] },
|
|
539
|
+
{ role: 'model', parts: undefined },
|
|
540
|
+
{ role: 'model', parts: [] },
|
|
385
541
|
];
|
|
386
|
-
// @ts-expect-error Accessing private method for testing
|
|
387
|
-
chat.recordHistory(userInput,
|
|
542
|
+
// @ts-expect-error Accessing private method for testing
|
|
543
|
+
chat.recordHistory(userInput, malformedOutput);
|
|
388
544
|
const history = chat.getHistory();
|
|
389
|
-
expect(history.length).toBe(
|
|
390
|
-
expect(history[
|
|
391
|
-
expect(history[
|
|
392
|
-
expect(history[
|
|
545
|
+
expect(history.length).toBe(4); // userInput + 3 model turns
|
|
546
|
+
expect(history[1].parts).toEqual([{ text: 'Text part' }]);
|
|
547
|
+
expect(history[2].parts).toBeUndefined();
|
|
548
|
+
expect(history[3].parts).toEqual([]);
|
|
393
549
|
});
|
|
394
|
-
it('should
|
|
395
|
-
const
|
|
396
|
-
{ role: 'model', parts: [{ text: '
|
|
397
|
-
{ role: '
|
|
550
|
+
it('should not consolidate content with different roles', () => {
|
|
551
|
+
const mixedOutput = [
|
|
552
|
+
{ role: 'model', parts: [{ text: 'Model 1' }] },
|
|
553
|
+
{ role: 'user', parts: [{ text: 'Unexpected User' }] },
|
|
554
|
+
{ role: 'model', parts: [{ text: 'Model 2' }] },
|
|
398
555
|
];
|
|
399
|
-
// @ts-expect-error Accessing private method for testing
|
|
400
|
-
chat.recordHistory(userInput,
|
|
556
|
+
// @ts-expect-error Accessing private method for testing
|
|
557
|
+
chat.recordHistory(userInput, mixedOutput);
|
|
401
558
|
const history = chat.getHistory();
|
|
402
|
-
expect(history.length).toBe(
|
|
403
|
-
expect(history[
|
|
404
|
-
expect(history[
|
|
405
|
-
expect(history[
|
|
559
|
+
expect(history.length).toBe(4); // userInput, model1, unexpected_user, model2
|
|
560
|
+
expect(history[1]).toEqual(mixedOutput[0]);
|
|
561
|
+
expect(history[2]).toEqual(mixedOutput[1]);
|
|
562
|
+
expect(history[3]).toEqual(mixedOutput[2]);
|
|
406
563
|
});
|
|
407
564
|
});
|
|
408
565
|
describe('addHistory', () => {
|
|
@@ -459,9 +616,9 @@ describe('GeminiChat', () => {
|
|
|
459
616
|
chunks.push(chunk);
|
|
460
617
|
}
|
|
461
618
|
// Assertions
|
|
462
|
-
expect(
|
|
463
|
-
expect(
|
|
464
|
-
expect(
|
|
619
|
+
expect(mockLogInvalidChunk).toHaveBeenCalledTimes(1);
|
|
620
|
+
expect(mockLogContentRetry).toHaveBeenCalledTimes(1);
|
|
621
|
+
expect(mockLogContentRetryFailure).not.toHaveBeenCalled();
|
|
465
622
|
expect(mockModelsModule.generateContentStream).toHaveBeenCalledTimes(2);
|
|
466
623
|
expect(chunks.some((c) => c.candidates?.[0]?.content?.parts?.[0]?.text ===
|
|
467
624
|
'Successful response')).toBe(true);
|
|
@@ -500,9 +657,9 @@ describe('GeminiChat', () => {
|
|
|
500
657
|
await expect(consumeStreamAndExpectError()).rejects.toThrow(EmptyStreamError);
|
|
501
658
|
// Should be called 3 times (initial + 2 retries)
|
|
502
659
|
expect(mockModelsModule.generateContentStream).toHaveBeenCalledTimes(3);
|
|
503
|
-
expect(
|
|
504
|
-
expect(
|
|
505
|
-
expect(
|
|
660
|
+
expect(mockLogInvalidChunk).toHaveBeenCalledTimes(3);
|
|
661
|
+
expect(mockLogContentRetry).toHaveBeenCalledTimes(2);
|
|
662
|
+
expect(mockLogContentRetryFailure).toHaveBeenCalledTimes(1);
|
|
506
663
|
// History should be clean, as if the failed turn never happened.
|
|
507
664
|
const history = chat.getHistory();
|
|
508
665
|
expect(history.length).toBe(0);
|
|
@@ -538,7 +695,7 @@ describe('GeminiChat', () => {
|
|
|
538
695
|
const history = chat.getHistory();
|
|
539
696
|
expect(history.length).toBe(4);
|
|
540
697
|
// Assert that the correct metrics were reported for one empty-stream retry
|
|
541
|
-
expect(
|
|
698
|
+
expect(mockLogContentRetry).toHaveBeenCalledTimes(1);
|
|
542
699
|
// Explicitly verify the structure of each part to satisfy TypeScript
|
|
543
700
|
const turn1 = history[0];
|
|
544
701
|
if (!turn1?.parts?.[0] || !('text' in turn1.parts[0])) {
|