@hibanacloud/core 0.3.15
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/.last_build +0 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.js +20 -0
- package/dist/index.js.map +1 -0
- package/dist/src/__mocks__/fs/promises.d.ts +11 -0
- package/dist/src/__mocks__/fs/promises.js +17 -0
- package/dist/src/__mocks__/fs/promises.js.map +1 -0
- package/dist/src/code_assist/codeAssist.d.ts +12 -0
- package/dist/src/code_assist/codeAssist.js +31 -0
- package/dist/src/code_assist/codeAssist.js.map +1 -0
- package/dist/src/code_assist/converter.d.ts +74 -0
- package/dist/src/code_assist/converter.js +160 -0
- package/dist/src/code_assist/converter.js.map +1 -0
- package/dist/src/code_assist/converter.test.d.ts +6 -0
- package/dist/src/code_assist/converter.test.js +372 -0
- package/dist/src/code_assist/converter.test.js.map +1 -0
- package/dist/src/code_assist/oauth-credential-storage.d.ts +25 -0
- package/dist/src/code_assist/oauth-credential-storage.js +109 -0
- package/dist/src/code_assist/oauth-credential-storage.js.map +1 -0
- package/dist/src/code_assist/oauth-credential-storage.test.d.ts +6 -0
- package/dist/src/code_assist/oauth-credential-storage.test.js +136 -0
- package/dist/src/code_assist/oauth-credential-storage.test.js.map +1 -0
- package/dist/src/code_assist/oauth2.d.ts +22 -0
- package/dist/src/code_assist/oauth2.js +431 -0
- package/dist/src/code_assist/oauth2.js.map +1 -0
- package/dist/src/code_assist/oauth2.test.d.ts +6 -0
- package/dist/src/code_assist/oauth2.test.js +818 -0
- package/dist/src/code_assist/oauth2.test.js.map +1 -0
- package/dist/src/code_assist/server.d.ts +37 -0
- package/dist/src/code_assist/server.js +148 -0
- package/dist/src/code_assist/server.js.map +1 -0
- package/dist/src/code_assist/server.test.d.ts +6 -0
- package/dist/src/code_assist/server.test.js +159 -0
- package/dist/src/code_assist/server.test.js.map +1 -0
- package/dist/src/code_assist/setup.d.ts +20 -0
- package/dist/src/code_assist/setup.js +101 -0
- package/dist/src/code_assist/setup.js.map +1 -0
- package/dist/src/code_assist/setup.test.d.ts +6 -0
- package/dist/src/code_assist/setup.test.js +171 -0
- package/dist/src/code_assist/setup.test.js.map +1 -0
- package/dist/src/code_assist/types.d.ts +163 -0
- package/dist/src/code_assist/types.js +46 -0
- package/dist/src/code_assist/types.js.map +1 -0
- package/dist/src/config/config.d.ts +431 -0
- package/dist/src/config/config.js +869 -0
- package/dist/src/config/config.js.map +1 -0
- package/dist/src/config/config.test.d.ts +6 -0
- package/dist/src/config/config.test.js +896 -0
- package/dist/src/config/config.test.js.map +1 -0
- package/dist/src/config/constants.d.ts +11 -0
- package/dist/src/config/constants.js +16 -0
- package/dist/src/config/constants.js.map +1 -0
- package/dist/src/config/flashFallback.test.d.ts +6 -0
- package/dist/src/config/flashFallback.test.js +87 -0
- package/dist/src/config/flashFallback.test.js.map +1 -0
- package/dist/src/config/models.d.ts +28 -0
- package/dist/src/config/models.js +42 -0
- package/dist/src/config/models.js.map +1 -0
- package/dist/src/config/models.test.d.ts +6 -0
- package/dist/src/config/models.test.js +55 -0
- package/dist/src/config/models.test.js.map +1 -0
- package/dist/src/config/storage.d.ts +34 -0
- package/dist/src/config/storage.js +95 -0
- package/dist/src/config/storage.js.map +1 -0
- package/dist/src/config/storage.test.d.ts +6 -0
- package/dist/src/config/storage.test.js +43 -0
- package/dist/src/config/storage.test.js.map +1 -0
- package/dist/src/core/__tests__/openaiTimeoutHandling.test.d.ts +6 -0
- package/dist/src/core/__tests__/openaiTimeoutHandling.test.js +295 -0
- package/dist/src/core/__tests__/openaiTimeoutHandling.test.js.map +1 -0
- package/dist/src/core/__tests__/orphanedToolCallsTest.d.ts +64 -0
- package/dist/src/core/__tests__/orphanedToolCallsTest.js +122 -0
- package/dist/src/core/__tests__/orphanedToolCallsTest.js.map +1 -0
- package/dist/src/core/baseLlmClient.d.ts +49 -0
- package/dist/src/core/baseLlmClient.js +104 -0
- package/dist/src/core/baseLlmClient.js.map +1 -0
- package/dist/src/core/baseLlmClient.test.d.ts +6 -0
- package/dist/src/core/baseLlmClient.test.js +323 -0
- package/dist/src/core/baseLlmClient.test.js.map +1 -0
- package/dist/src/core/client.d.ts +56 -0
- package/dist/src/core/client.js +522 -0
- package/dist/src/core/client.js.map +1 -0
- package/dist/src/core/client.test.d.ts +6 -0
- package/dist/src/core/client.test.js +1829 -0
- package/dist/src/core/client.test.js.map +1 -0
- package/dist/src/core/contentGenerator.d.ts +52 -0
- package/dist/src/core/contentGenerator.js +106 -0
- package/dist/src/core/contentGenerator.js.map +1 -0
- package/dist/src/core/contentGenerator.test.d.ts +6 -0
- package/dist/src/core/contentGenerator.test.js +77 -0
- package/dist/src/core/contentGenerator.test.js.map +1 -0
- package/dist/src/core/coreToolScheduler.d.ts +134 -0
- package/dist/src/core/coreToolScheduler.js +774 -0
- package/dist/src/core/coreToolScheduler.js.map +1 -0
- package/dist/src/core/coreToolScheduler.test.d.ts +6 -0
- package/dist/src/core/coreToolScheduler.test.js +1802 -0
- package/dist/src/core/coreToolScheduler.test.js.map +1 -0
- package/dist/src/core/geminiChat.d.ts +124 -0
- package/dist/src/core/geminiChat.js +518 -0
- package/dist/src/core/geminiChat.js.map +1 -0
- package/dist/src/core/geminiChat.test.d.ts +6 -0
- package/dist/src/core/geminiChat.test.js +1149 -0
- package/dist/src/core/geminiChat.test.js.map +1 -0
- package/dist/src/core/geminiRequest.d.ts +13 -0
- package/dist/src/core/geminiRequest.js +11 -0
- package/dist/src/core/geminiRequest.js.map +1 -0
- package/dist/src/core/geminiRequest.test.d.ts +6 -0
- package/dist/src/core/geminiRequest.test.js +73 -0
- package/dist/src/core/geminiRequest.test.js.map +1 -0
- package/dist/src/core/logger.d.ts +67 -0
- package/dist/src/core/logger.js +361 -0
- package/dist/src/core/logger.js.map +1 -0
- package/dist/src/core/logger.test.d.ts +6 -0
- package/dist/src/core/logger.test.js +534 -0
- package/dist/src/core/logger.test.js.map +1 -0
- package/dist/src/core/loggingContentGenerator.d.ts +25 -0
- package/dist/src/core/loggingContentGenerator.js +94 -0
- package/dist/src/core/loggingContentGenerator.js.map +1 -0
- package/dist/src/core/nonInteractiveToolExecutor.d.ts +16 -0
- package/dist/src/core/nonInteractiveToolExecutor.js +29 -0
- package/dist/src/core/nonInteractiveToolExecutor.js.map +1 -0
- package/dist/src/core/nonInteractiveToolExecutor.test.d.ts +6 -0
- package/dist/src/core/nonInteractiveToolExecutor.test.js +294 -0
- package/dist/src/core/nonInteractiveToolExecutor.test.js.map +1 -0
- package/dist/src/core/openaiContentGenerator/constants.d.ts +7 -0
- package/dist/src/core/openaiContentGenerator/constants.js +8 -0
- package/dist/src/core/openaiContentGenerator/constants.js.map +1 -0
- package/dist/src/core/openaiContentGenerator/converter.d.ts +108 -0
- package/dist/src/core/openaiContentGenerator/converter.js +851 -0
- package/dist/src/core/openaiContentGenerator/converter.js.map +1 -0
- package/dist/src/core/openaiContentGenerator/converter.test.d.ts +6 -0
- package/dist/src/core/openaiContentGenerator/converter.test.js +108 -0
- package/dist/src/core/openaiContentGenerator/converter.test.js.map +1 -0
- package/dist/src/core/openaiContentGenerator/errorHandler.d.ts +20 -0
- package/dist/src/core/openaiContentGenerator/errorHandler.js +82 -0
- package/dist/src/core/openaiContentGenerator/errorHandler.js.map +1 -0
- package/dist/src/core/openaiContentGenerator/errorHandler.test.d.ts +6 -0
- package/dist/src/core/openaiContentGenerator/errorHandler.test.js +287 -0
- package/dist/src/core/openaiContentGenerator/errorHandler.test.js.map +1 -0
- package/dist/src/core/openaiContentGenerator/index.d.ts +22 -0
- package/dist/src/core/openaiContentGenerator/index.js +49 -0
- package/dist/src/core/openaiContentGenerator/index.js.map +1 -0
- package/dist/src/core/openaiContentGenerator/openaiContentGenerator.d.ts +21 -0
- package/dist/src/core/openaiContentGenerator/openaiContentGenerator.js +105 -0
- package/dist/src/core/openaiContentGenerator/openaiContentGenerator.js.map +1 -0
- package/dist/src/core/openaiContentGenerator/openaiContentGenerator.test.d.ts +6 -0
- package/dist/src/core/openaiContentGenerator/openaiContentGenerator.test.js +230 -0
- package/dist/src/core/openaiContentGenerator/openaiContentGenerator.test.js.map +1 -0
- package/dist/src/core/openaiContentGenerator/pipeline.d.ts +66 -0
- package/dist/src/core/openaiContentGenerator/pipeline.js +265 -0
- package/dist/src/core/openaiContentGenerator/pipeline.js.map +1 -0
- package/dist/src/core/openaiContentGenerator/pipeline.test.d.ts +6 -0
- package/dist/src/core/openaiContentGenerator/pipeline.test.js +1028 -0
- package/dist/src/core/openaiContentGenerator/pipeline.test.js.map +1 -0
- package/dist/src/core/openaiContentGenerator/provider/README.md +61 -0
- package/dist/src/core/openaiContentGenerator/provider/anthropic.d.ts +14 -0
- package/dist/src/core/openaiContentGenerator/provider/anthropic.js +28 -0
- package/dist/src/core/openaiContentGenerator/provider/anthropic.js.map +1 -0
- package/dist/src/core/openaiContentGenerator/provider/anthropic.test.d.ts +1 -0
- package/dist/src/core/openaiContentGenerator/provider/anthropic.test.js +138 -0
- package/dist/src/core/openaiContentGenerator/provider/anthropic.test.js.map +1 -0
- package/dist/src/core/openaiContentGenerator/provider/dashscope.d.ts +63 -0
- package/dist/src/core/openaiContentGenerator/provider/dashscope.js +241 -0
- package/dist/src/core/openaiContentGenerator/provider/dashscope.js.map +1 -0
- package/dist/src/core/openaiContentGenerator/provider/dashscope.test.d.ts +6 -0
- package/dist/src/core/openaiContentGenerator/provider/dashscope.test.js +707 -0
- package/dist/src/core/openaiContentGenerator/provider/dashscope.test.js.map +1 -0
- package/dist/src/core/openaiContentGenerator/provider/deepseek.d.ts +14 -0
- package/dist/src/core/openaiContentGenerator/provider/deepseek.js +70 -0
- package/dist/src/core/openaiContentGenerator/provider/deepseek.js.map +1 -0
- package/dist/src/core/openaiContentGenerator/provider/deepseek.test.d.ts +6 -0
- package/dist/src/core/openaiContentGenerator/provider/deepseek.test.js +151 -0
- package/dist/src/core/openaiContentGenerator/provider/deepseek.test.js.map +1 -0
- package/dist/src/core/openaiContentGenerator/provider/default.d.ts +15 -0
- package/dist/src/core/openaiContentGenerator/provider/default.js +48 -0
- package/dist/src/core/openaiContentGenerator/provider/default.js.map +1 -0
- package/dist/src/core/openaiContentGenerator/provider/default.test.d.ts +6 -0
- package/dist/src/core/openaiContentGenerator/provider/default.test.js +176 -0
- package/dist/src/core/openaiContentGenerator/provider/default.test.js.map +1 -0
- package/dist/src/core/openaiContentGenerator/provider/index.d.ts +7 -0
- package/dist/src/core/openaiContentGenerator/provider/index.js +7 -0
- package/dist/src/core/openaiContentGenerator/provider/index.js.map +1 -0
- package/dist/src/core/openaiContentGenerator/provider/modelscope.d.ts +17 -0
- package/dist/src/core/openaiContentGenerator/provider/modelscope.js +25 -0
- package/dist/src/core/openaiContentGenerator/provider/modelscope.js.map +1 -0
- package/dist/src/core/openaiContentGenerator/provider/modelscope.test.d.ts +6 -0
- package/dist/src/core/openaiContentGenerator/provider/modelscope.test.js +66 -0
- package/dist/src/core/openaiContentGenerator/provider/modelscope.test.js.map +1 -0
- package/dist/src/core/openaiContentGenerator/provider/openrouter.d.ts +10 -0
- package/dist/src/core/openaiContentGenerator/provider/openrouter.js +33 -0
- package/dist/src/core/openaiContentGenerator/provider/openrouter.js.map +1 -0
- package/dist/src/core/openaiContentGenerator/provider/openrouter.test.d.ts +6 -0
- package/dist/src/core/openaiContentGenerator/provider/openrouter.test.js +175 -0
- package/dist/src/core/openaiContentGenerator/provider/openrouter.test.js.map +1 -0
- package/dist/src/core/openaiContentGenerator/provider/types.d.ts +23 -0
- package/dist/src/core/openaiContentGenerator/provider/types.js +2 -0
- package/dist/src/core/openaiContentGenerator/provider/types.js.map +1 -0
- package/dist/src/core/openaiContentGenerator/streamingToolCallParser.d.ts +145 -0
- package/dist/src/core/openaiContentGenerator/streamingToolCallParser.js +381 -0
- package/dist/src/core/openaiContentGenerator/streamingToolCallParser.js.map +1 -0
- package/dist/src/core/openaiContentGenerator/streamingToolCallParser.test.d.ts +6 -0
- package/dist/src/core/openaiContentGenerator/streamingToolCallParser.test.js +537 -0
- package/dist/src/core/openaiContentGenerator/streamingToolCallParser.test.js.map +1 -0
- package/dist/src/core/openaiContentGenerator/telemetryService.d.ts +36 -0
- package/dist/src/core/openaiContentGenerator/telemetryService.js +150 -0
- package/dist/src/core/openaiContentGenerator/telemetryService.js.map +1 -0
- package/dist/src/core/openaiContentGenerator/telemetryService.test.d.ts +6 -0
- package/dist/src/core/openaiContentGenerator/telemetryService.test.js +978 -0
- package/dist/src/core/openaiContentGenerator/telemetryService.test.js.map +1 -0
- package/dist/src/core/prompts.d.ts +73 -0
- package/dist/src/core/prompts.js +813 -0
- package/dist/src/core/prompts.js.map +1 -0
- package/dist/src/core/prompts.test.d.ts +6 -0
- package/dist/src/core/prompts.test.js +488 -0
- package/dist/src/core/prompts.test.js.map +1 -0
- package/dist/src/core/tokenLimits.d.ts +25 -0
- package/dist/src/core/tokenLimits.js +194 -0
- package/dist/src/core/tokenLimits.js.map +1 -0
- package/dist/src/core/tokenLimits.test.d.ts +1 -0
- package/dist/src/core/tokenLimits.test.js +304 -0
- package/dist/src/core/tokenLimits.test.js.map +1 -0
- package/dist/src/core/turn.d.ts +152 -0
- package/dist/src/core/turn.js +187 -0
- package/dist/src/core/turn.js.map +1 -0
- package/dist/src/core/turn.test.d.ts +6 -0
- package/dist/src/core/turn.test.js +628 -0
- package/dist/src/core/turn.test.js.map +1 -0
- package/dist/src/fallback/handler.d.ts +7 -0
- package/dist/src/fallback/handler.js +97 -0
- package/dist/src/fallback/handler.js.map +1 -0
- package/dist/src/fallback/handler.test.d.ts +6 -0
- package/dist/src/fallback/handler.test.js +130 -0
- package/dist/src/fallback/handler.test.js.map +1 -0
- package/dist/src/fallback/types.d.ts +14 -0
- package/dist/src/fallback/types.js +7 -0
- package/dist/src/fallback/types.js.map +1 -0
- package/dist/src/generated/git-commit.d.ts +7 -0
- package/dist/src/generated/git-commit.js +10 -0
- package/dist/src/generated/git-commit.js.map +1 -0
- package/dist/src/ide/constants.d.ts +9 -0
- package/dist/src/ide/constants.js +10 -0
- package/dist/src/ide/constants.js.map +1 -0
- package/dist/src/ide/detect-ide.d.ts +56 -0
- package/dist/src/ide/detect-ide.js +68 -0
- package/dist/src/ide/detect-ide.js.map +1 -0
- package/dist/src/ide/detect-ide.test.d.ts +6 -0
- package/dist/src/ide/detect-ide.test.js +113 -0
- package/dist/src/ide/detect-ide.test.js.map +1 -0
- package/dist/src/ide/ide-client.d.ts +110 -0
- package/dist/src/ide/ide-client.js +651 -0
- package/dist/src/ide/ide-client.js.map +1 -0
- package/dist/src/ide/ide-client.test.d.ts +6 -0
- package/dist/src/ide/ide-client.test.js +390 -0
- package/dist/src/ide/ide-client.test.js.map +1 -0
- package/dist/src/ide/ide-installer.d.ts +14 -0
- package/dist/src/ide/ide-installer.js +112 -0
- package/dist/src/ide/ide-installer.js.map +1 -0
- package/dist/src/ide/ide-installer.test.d.ts +6 -0
- package/dist/src/ide/ide-installer.test.js +134 -0
- package/dist/src/ide/ide-installer.test.js.map +1 -0
- package/dist/src/ide/ideContext.d.ts +44 -0
- package/dist/src/ide/ideContext.js +101 -0
- package/dist/src/ide/ideContext.js.map +1 -0
- package/dist/src/ide/ideContext.test.d.ts +6 -0
- package/dist/src/ide/ideContext.test.js +393 -0
- package/dist/src/ide/ideContext.test.js.map +1 -0
- package/dist/src/ide/process-utils.d.ts +21 -0
- package/dist/src/ide/process-utils.js +171 -0
- package/dist/src/ide/process-utils.js.map +1 -0
- package/dist/src/ide/process-utils.test.d.ts +6 -0
- package/dist/src/ide/process-utils.test.js +158 -0
- package/dist/src/ide/process-utils.test.js.map +1 -0
- package/dist/src/ide/types.d.ts +486 -0
- package/dist/src/ide/types.js +138 -0
- package/dist/src/ide/types.js.map +1 -0
- package/dist/src/index.d.ts +99 -0
- package/dist/src/index.js +112 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/index.test.d.ts +6 -0
- package/dist/src/index.test.js +12 -0
- package/dist/src/index.test.js.map +1 -0
- package/dist/src/mcp/google-auth-provider.d.ts +23 -0
- package/dist/src/mcp/google-auth-provider.js +72 -0
- package/dist/src/mcp/google-auth-provider.js.map +1 -0
- package/dist/src/mcp/google-auth-provider.test.d.ts +6 -0
- package/dist/src/mcp/google-auth-provider.test.js +89 -0
- package/dist/src/mcp/google-auth-provider.test.js.map +1 -0
- package/dist/src/mcp/oauth-provider.d.ts +150 -0
- package/dist/src/mcp/oauth-provider.js +613 -0
- package/dist/src/mcp/oauth-provider.js.map +1 -0
- package/dist/src/mcp/oauth-provider.test.d.ts +6 -0
- package/dist/src/mcp/oauth-provider.test.js +847 -0
- package/dist/src/mcp/oauth-provider.test.js.map +1 -0
- package/dist/src/mcp/oauth-token-storage.d.ts +65 -0
- package/dist/src/mcp/oauth-token-storage.js +180 -0
- package/dist/src/mcp/oauth-token-storage.js.map +1 -0
- package/dist/src/mcp/oauth-token-storage.test.d.ts +6 -0
- package/dist/src/mcp/oauth-token-storage.test.js +299 -0
- package/dist/src/mcp/oauth-token-storage.test.js.map +1 -0
- package/dist/src/mcp/oauth-utils.d.ts +119 -0
- package/dist/src/mcp/oauth-utils.js +236 -0
- package/dist/src/mcp/oauth-utils.js.map +1 -0
- package/dist/src/mcp/oauth-utils.test.d.ts +6 -0
- package/dist/src/mcp/oauth-utils.test.js +199 -0
- package/dist/src/mcp/oauth-utils.test.js.map +1 -0
- package/dist/src/mcp/sa-impersonation-provider.d.ts +33 -0
- package/dist/src/mcp/sa-impersonation-provider.js +130 -0
- package/dist/src/mcp/sa-impersonation-provider.js.map +1 -0
- package/dist/src/mcp/sa-impersonation-provider.test.d.ts +6 -0
- package/dist/src/mcp/sa-impersonation-provider.test.js +117 -0
- package/dist/src/mcp/sa-impersonation-provider.test.js.map +1 -0
- package/dist/src/mcp/token-storage/base-token-storage.d.ts +19 -0
- package/dist/src/mcp/token-storage/base-token-storage.js +36 -0
- package/dist/src/mcp/token-storage/base-token-storage.js.map +1 -0
- package/dist/src/mcp/token-storage/base-token-storage.test.d.ts +6 -0
- package/dist/src/mcp/token-storage/base-token-storage.test.js +160 -0
- package/dist/src/mcp/token-storage/base-token-storage.test.js.map +1 -0
- package/dist/src/mcp/token-storage/file-token-storage.d.ts +24 -0
- package/dist/src/mcp/token-storage/file-token-storage.js +144 -0
- package/dist/src/mcp/token-storage/file-token-storage.js.map +1 -0
- package/dist/src/mcp/token-storage/file-token-storage.test.d.ts +6 -0
- package/dist/src/mcp/token-storage/file-token-storage.test.js +235 -0
- package/dist/src/mcp/token-storage/file-token-storage.test.js.map +1 -0
- package/dist/src/mcp/token-storage/hybrid-token-storage.d.ts +23 -0
- package/dist/src/mcp/token-storage/hybrid-token-storage.js +78 -0
- package/dist/src/mcp/token-storage/hybrid-token-storage.js.map +1 -0
- package/dist/src/mcp/token-storage/hybrid-token-storage.test.d.ts +6 -0
- package/dist/src/mcp/token-storage/hybrid-token-storage.test.js +193 -0
- package/dist/src/mcp/token-storage/hybrid-token-storage.test.js.map +1 -0
- package/dist/src/mcp/token-storage/index.d.ts +11 -0
- package/dist/src/mcp/token-storage/index.js +12 -0
- package/dist/src/mcp/token-storage/index.js.map +1 -0
- package/dist/src/mcp/token-storage/keychain-token-storage.d.ts +31 -0
- package/dist/src/mcp/token-storage/keychain-token-storage.js +190 -0
- package/dist/src/mcp/token-storage/keychain-token-storage.js.map +1 -0
- package/dist/src/mcp/token-storage/keychain-token-storage.test.d.ts +6 -0
- package/dist/src/mcp/token-storage/keychain-token-storage.test.js +254 -0
- package/dist/src/mcp/token-storage/keychain-token-storage.test.js.map +1 -0
- package/dist/src/mcp/token-storage/types.d.ts +38 -0
- package/dist/src/mcp/token-storage/types.js +11 -0
- package/dist/src/mcp/token-storage/types.js.map +1 -0
- package/dist/src/mocks/msw.d.ts +6 -0
- package/dist/src/mocks/msw.js +8 -0
- package/dist/src/mocks/msw.js.map +1 -0
- package/dist/src/oauth/callbackServer.d.ts +15 -0
- package/dist/src/oauth/callbackServer.js +89 -0
- package/dist/src/oauth/callbackServer.js.map +1 -0
- package/dist/src/oauth/oauthClient.d.ts +57 -0
- package/dist/src/oauth/oauthClient.js +233 -0
- package/dist/src/oauth/oauthClient.js.map +1 -0
- package/dist/src/oauth/pkce.d.ts +25 -0
- package/dist/src/oauth/pkce.js +45 -0
- package/dist/src/oauth/pkce.js.map +1 -0
- package/dist/src/oauth/tokenManager.d.ts +37 -0
- package/dist/src/oauth/tokenManager.js +110 -0
- package/dist/src/oauth/tokenManager.js.map +1 -0
- package/dist/src/output/json-formatter.d.ts +11 -0
- package/dist/src/output/json-formatter.js +30 -0
- package/dist/src/output/json-formatter.js.map +1 -0
- package/dist/src/output/json-formatter.test.d.ts +6 -0
- package/dist/src/output/json-formatter.test.js +266 -0
- package/dist/src/output/json-formatter.test.js.map +1 -0
- package/dist/src/output/types.d.ts +25 -0
- package/dist/src/output/types.js +17 -0
- package/dist/src/output/types.js.map +1 -0
- package/dist/src/prompts/mcp-prompts.d.ts +8 -0
- package/dist/src/prompts/mcp-prompts.js +13 -0
- package/dist/src/prompts/mcp-prompts.js.map +1 -0
- package/dist/src/prompts/prompt-registry.d.ts +34 -0
- package/dist/src/prompts/prompt-registry.js +63 -0
- package/dist/src/prompts/prompt-registry.js.map +1 -0
- package/dist/src/qwen/qwenContentGenerator.d.ts +70 -0
- package/dist/src/qwen/qwenContentGenerator.js +180 -0
- package/dist/src/qwen/qwenContentGenerator.js.map +1 -0
- package/dist/src/qwen/qwenContentGenerator.test.d.ts +6 -0
- package/dist/src/qwen/qwenContentGenerator.test.js +1178 -0
- package/dist/src/qwen/qwenContentGenerator.test.js.map +1 -0
- package/dist/src/qwen/qwenOAuth2.d.ts +194 -0
- package/dist/src/qwen/qwenOAuth2.js +594 -0
- package/dist/src/qwen/qwenOAuth2.js.map +1 -0
- package/dist/src/qwen/qwenOAuth2.test.d.ts +6 -0
- package/dist/src/qwen/qwenOAuth2.test.js +1724 -0
- package/dist/src/qwen/qwenOAuth2.test.js.map +1 -0
- package/dist/src/qwen/sharedTokenManager.d.ts +196 -0
- package/dist/src/qwen/sharedTokenManager.js +647 -0
- package/dist/src/qwen/sharedTokenManager.js.map +1 -0
- package/dist/src/qwen/sharedTokenManager.test.d.ts +7 -0
- package/dist/src/qwen/sharedTokenManager.test.js +662 -0
- package/dist/src/qwen/sharedTokenManager.test.js.map +1 -0
- package/dist/src/services/chatCompressionService.d.ts +32 -0
- package/dist/src/services/chatCompressionService.js +180 -0
- package/dist/src/services/chatCompressionService.js.map +1 -0
- package/dist/src/services/chatCompressionService.test.d.ts +6 -0
- package/dist/src/services/chatCompressionService.test.js +292 -0
- package/dist/src/services/chatCompressionService.test.js.map +1 -0
- package/dist/src/services/chatRecordingService.d.ts +144 -0
- package/dist/src/services/chatRecordingService.js +330 -0
- package/dist/src/services/chatRecordingService.js.map +1 -0
- package/dist/src/services/chatRecordingService.test.d.ts +6 -0
- package/dist/src/services/chatRecordingService.test.js +332 -0
- package/dist/src/services/chatRecordingService.test.js.map +1 -0
- package/dist/src/services/fileDiscoveryService.d.ts +45 -0
- package/dist/src/services/fileDiscoveryService.js +104 -0
- package/dist/src/services/fileDiscoveryService.js.map +1 -0
- package/dist/src/services/fileDiscoveryService.test.d.ts +6 -0
- package/dist/src/services/fileDiscoveryService.test.js +143 -0
- package/dist/src/services/fileDiscoveryService.test.js.map +1 -0
- package/dist/src/services/fileSystemService.d.ts +40 -0
- package/dist/src/services/fileSystemService.js +29 -0
- package/dist/src/services/fileSystemService.js.map +1 -0
- package/dist/src/services/fileSystemService.test.d.ts +6 -0
- package/dist/src/services/fileSystemService.test.js +41 -0
- package/dist/src/services/fileSystemService.test.js.map +1 -0
- package/dist/src/services/gitService.d.ts +22 -0
- package/dist/src/services/gitService.js +98 -0
- package/dist/src/services/gitService.js.map +1 -0
- package/dist/src/services/gitService.test.d.ts +6 -0
- package/dist/src/services/gitService.test.js +187 -0
- package/dist/src/services/gitService.test.js.map +1 -0
- package/dist/src/services/loopDetectionService.d.ts +103 -0
- package/dist/src/services/loopDetectionService.js +379 -0
- package/dist/src/services/loopDetectionService.js.map +1 -0
- package/dist/src/services/loopDetectionService.test.d.ts +6 -0
- package/dist/src/services/loopDetectionService.test.js +588 -0
- package/dist/src/services/loopDetectionService.test.js.map +1 -0
- package/dist/src/services/shellExecutionService.d.ts +102 -0
- package/dist/src/services/shellExecutionService.js +522 -0
- package/dist/src/services/shellExecutionService.js.map +1 -0
- package/dist/src/services/shellExecutionService.test.d.ts +6 -0
- package/dist/src/services/shellExecutionService.test.js +655 -0
- package/dist/src/services/shellExecutionService.test.js.map +1 -0
- package/dist/src/subagents/builtin-agents.d.ts +35 -0
- package/dist/src/subagents/builtin-agents.js +85 -0
- package/dist/src/subagents/builtin-agents.js.map +1 -0
- package/dist/src/subagents/builtin-agents.test.d.ts +6 -0
- package/dist/src/subagents/builtin-agents.test.js +78 -0
- package/dist/src/subagents/builtin-agents.test.js.map +1 -0
- package/dist/src/subagents/index.d.ts +29 -0
- package/dist/src/subagents/index.js +15 -0
- package/dist/src/subagents/index.js.map +1 -0
- package/dist/src/subagents/subagent-events.d.ts +95 -0
- package/dist/src/subagents/subagent-events.js +31 -0
- package/dist/src/subagents/subagent-events.js.map +1 -0
- package/dist/src/subagents/subagent-hooks.d.ts +29 -0
- package/dist/src/subagents/subagent-hooks.js +7 -0
- package/dist/src/subagents/subagent-hooks.js.map +1 -0
- package/dist/src/subagents/subagent-manager.d.ts +170 -0
- package/dist/src/subagents/subagent-manager.js +596 -0
- package/dist/src/subagents/subagent-manager.js.map +1 -0
- package/dist/src/subagents/subagent-manager.test.d.ts +6 -0
- package/dist/src/subagents/subagent-manager.test.js +822 -0
- package/dist/src/subagents/subagent-manager.test.js.map +1 -0
- package/dist/src/subagents/subagent-statistics.d.ts +46 -0
- package/dist/src/subagents/subagent-statistics.js +193 -0
- package/dist/src/subagents/subagent-statistics.js.map +1 -0
- package/dist/src/subagents/subagent-statistics.test.d.ts +6 -0
- package/dist/src/subagents/subagent-statistics.test.js +231 -0
- package/dist/src/subagents/subagent-statistics.test.js.map +1 -0
- package/dist/src/subagents/subagent.d.ts +162 -0
- package/dist/src/subagents/subagent.js +677 -0
- package/dist/src/subagents/subagent.js.map +1 -0
- package/dist/src/subagents/subagent.test.d.ts +6 -0
- package/dist/src/subagents/subagent.test.js +477 -0
- package/dist/src/subagents/subagent.test.js.map +1 -0
- package/dist/src/subagents/types.d.ts +218 -0
- package/dist/src/subagents/types.js +58 -0
- package/dist/src/subagents/types.js.map +1 -0
- package/dist/src/subagents/types.test.d.ts +6 -0
- package/dist/src/subagents/types.test.js +31 -0
- package/dist/src/subagents/types.test.js.map +1 -0
- package/dist/src/subagents/validation.d.ts +63 -0
- package/dist/src/subagents/validation.js +293 -0
- package/dist/src/subagents/validation.js.map +1 -0
- package/dist/src/subagents/validation.test.d.ts +6 -0
- package/dist/src/subagents/validation.test.js +330 -0
- package/dist/src/subagents/validation.test.js.map +1 -0
- package/dist/src/telemetry/clearcut-logger/clearcut-logger.d.ts +137 -0
- package/dist/src/telemetry/clearcut-logger/clearcut-logger.js +915 -0
- package/dist/src/telemetry/clearcut-logger/clearcut-logger.js.map +1 -0
- package/dist/src/telemetry/clearcut-logger/clearcut-logger.test.d.ts +18 -0
- package/dist/src/telemetry/clearcut-logger/clearcut-logger.test.js +594 -0
- package/dist/src/telemetry/clearcut-logger/clearcut-logger.test.js.map +1 -0
- package/dist/src/telemetry/clearcut-logger/event-metadata-key.d.ts +115 -0
- package/dist/src/telemetry/clearcut-logger/event-metadata-key.js +291 -0
- package/dist/src/telemetry/clearcut-logger/event-metadata-key.js.map +1 -0
- package/dist/src/telemetry/config.d.ts +31 -0
- package/dist/src/telemetry/config.js +76 -0
- package/dist/src/telemetry/config.js.map +1 -0
- package/dist/src/telemetry/config.test.d.ts +6 -0
- package/dist/src/telemetry/config.test.js +124 -0
- package/dist/src/telemetry/config.test.js.map +1 -0
- package/dist/src/telemetry/constants.d.ts +36 -0
- package/dist/src/telemetry/constants.js +38 -0
- package/dist/src/telemetry/constants.js.map +1 -0
- package/dist/src/telemetry/file-exporters.d.ts +29 -0
- package/dist/src/telemetry/file-exporters.js +62 -0
- package/dist/src/telemetry/file-exporters.js.map +1 -0
- package/dist/src/telemetry/index.d.ts +25 -0
- package/dist/src/telemetry/index.js +31 -0
- package/dist/src/telemetry/index.js.map +1 -0
- package/dist/src/telemetry/integration.test.circular.d.ts +6 -0
- package/dist/src/telemetry/integration.test.circular.js +95 -0
- package/dist/src/telemetry/integration.test.circular.js.map +1 -0
- package/dist/src/telemetry/loggers.d.ts +37 -0
- package/dist/src/telemetry/loggers.js +651 -0
- package/dist/src/telemetry/loggers.js.map +1 -0
- package/dist/src/telemetry/loggers.test.circular.d.ts +6 -0
- package/dist/src/telemetry/loggers.test.circular.js +107 -0
- package/dist/src/telemetry/loggers.test.circular.js.map +1 -0
- package/dist/src/telemetry/loggers.test.d.ts +6 -0
- package/dist/src/telemetry/loggers.test.js +978 -0
- package/dist/src/telemetry/loggers.test.js.map +1 -0
- package/dist/src/telemetry/metrics.d.ts +320 -0
- package/dist/src/telemetry/metrics.js +532 -0
- package/dist/src/telemetry/metrics.js.map +1 -0
- package/dist/src/telemetry/metrics.test.d.ts +6 -0
- package/dist/src/telemetry/metrics.test.js +744 -0
- package/dist/src/telemetry/metrics.test.js.map +1 -0
- package/dist/src/telemetry/qwen-logger/event-types.d.ts +88 -0
- package/dist/src/telemetry/qwen-logger/event-types.js +2 -0
- package/dist/src/telemetry/qwen-logger/event-types.js.map +1 -0
- package/dist/src/telemetry/qwen-logger/qwen-logger.d.ts +91 -0
- package/dist/src/telemetry/qwen-logger/qwen-logger.js +685 -0
- package/dist/src/telemetry/qwen-logger/qwen-logger.js.map +1 -0
- package/dist/src/telemetry/qwen-logger/qwen-logger.test.d.ts +6 -0
- package/dist/src/telemetry/qwen-logger/qwen-logger.test.js +317 -0
- package/dist/src/telemetry/qwen-logger/qwen-logger.test.js.map +1 -0
- package/dist/src/telemetry/sdk.d.ts +9 -0
- package/dist/src/telemetry/sdk.js +164 -0
- package/dist/src/telemetry/sdk.js.map +1 -0
- package/dist/src/telemetry/sdk.test.d.ts +6 -0
- package/dist/src/telemetry/sdk.test.js +116 -0
- package/dist/src/telemetry/sdk.test.js.map +1 -0
- package/dist/src/telemetry/telemetry-utils.d.ts +6 -0
- package/dist/src/telemetry/telemetry-utils.js +14 -0
- package/dist/src/telemetry/telemetry-utils.js.map +1 -0
- package/dist/src/telemetry/telemetry-utils.test.d.ts +6 -0
- package/dist/src/telemetry/telemetry-utils.test.js +40 -0
- package/dist/src/telemetry/telemetry-utils.test.js.map +1 -0
- package/dist/src/telemetry/telemetry.test.d.ts +6 -0
- package/dist/src/telemetry/telemetry.test.js +50 -0
- package/dist/src/telemetry/telemetry.test.js.map +1 -0
- package/dist/src/telemetry/tool-call-decision.d.ts +13 -0
- package/dist/src/telemetry/tool-call-decision.js +29 -0
- package/dist/src/telemetry/tool-call-decision.js.map +1 -0
- package/dist/src/telemetry/types.d.ts +327 -0
- package/dist/src/telemetry/types.js +558 -0
- package/dist/src/telemetry/types.js.map +1 -0
- package/dist/src/telemetry/uiTelemetry.d.ts +75 -0
- package/dist/src/telemetry/uiTelemetry.js +152 -0
- package/dist/src/telemetry/uiTelemetry.js.map +1 -0
- package/dist/src/telemetry/uiTelemetry.test.d.ts +6 -0
- package/dist/src/telemetry/uiTelemetry.test.js +625 -0
- package/dist/src/telemetry/uiTelemetry.test.js.map +1 -0
- package/dist/src/test-utils/config.d.ts +17 -0
- package/dist/src/test-utils/config.js +32 -0
- package/dist/src/test-utils/config.js.map +1 -0
- package/dist/src/test-utils/index.d.ts +6 -0
- package/dist/src/test-utils/index.js +7 -0
- package/dist/src/test-utils/index.js.map +1 -0
- package/dist/src/test-utils/mock-tool.d.ts +66 -0
- package/dist/src/test-utils/mock-tool.js +121 -0
- package/dist/src/test-utils/mock-tool.js.map +1 -0
- package/dist/src/test-utils/mockWorkspaceContext.d.ts +13 -0
- package/dist/src/test-utils/mockWorkspaceContext.js +24 -0
- package/dist/src/test-utils/mockWorkspaceContext.js.map +1 -0
- package/dist/src/tools/diffOptions.d.ts +9 -0
- package/dist/src/tools/diffOptions.js +46 -0
- package/dist/src/tools/diffOptions.js.map +1 -0
- package/dist/src/tools/diffOptions.test.d.ts +6 -0
- package/dist/src/tools/diffOptions.test.js +155 -0
- package/dist/src/tools/diffOptions.test.js.map +1 -0
- package/dist/src/tools/edit.d.ts +55 -0
- package/dist/src/tools/edit.js +421 -0
- package/dist/src/tools/edit.js.map +1 -0
- package/dist/src/tools/edit.test.d.ts +6 -0
- package/dist/src/tools/edit.test.js +684 -0
- package/dist/src/tools/edit.test.js.map +1 -0
- package/dist/src/tools/exitPlanMode.d.ts +28 -0
- package/dist/src/tools/exitPlanMode.js +132 -0
- package/dist/src/tools/exitPlanMode.js.map +1 -0
- package/dist/src/tools/exitPlanMode.test.d.ts +6 -0
- package/dist/src/tools/exitPlanMode.test.js +178 -0
- package/dist/src/tools/exitPlanMode.test.js.map +1 -0
- package/dist/src/tools/glob.d.ts +44 -0
- package/dist/src/tools/glob.js +190 -0
- package/dist/src/tools/glob.js.map +1 -0
- package/dist/src/tools/glob.test.d.ts +6 -0
- package/dist/src/tools/glob.test.js +442 -0
- package/dist/src/tools/glob.test.js.map +1 -0
- package/dist/src/tools/grep.d.ts +44 -0
- package/dist/src/tools/grep.js +425 -0
- package/dist/src/tools/grep.js.map +1 -0
- package/dist/src/tools/grep.test.d.ts +6 -0
- package/dist/src/tools/grep.test.js +360 -0
- package/dist/src/tools/grep.test.js.map +1 -0
- package/dist/src/tools/ls.d.ts +68 -0
- package/dist/src/tools/ls.js +215 -0
- package/dist/src/tools/ls.js.map +1 -0
- package/dist/src/tools/ls.test.d.ts +6 -0
- package/dist/src/tools/ls.test.js +249 -0
- package/dist/src/tools/ls.test.js.map +1 -0
- package/dist/src/tools/mcp-client-manager.d.ts +40 -0
- package/dist/src/tools/mcp-client-manager.js +83 -0
- package/dist/src/tools/mcp-client-manager.js.map +1 -0
- package/dist/src/tools/mcp-client-manager.test.d.ts +6 -0
- package/dist/src/tools/mcp-client-manager.test.js +58 -0
- package/dist/src/tools/mcp-client-manager.test.js.map +1 -0
- package/dist/src/tools/mcp-client.d.ts +189 -0
- package/dist/src/tools/mcp-client.js +957 -0
- package/dist/src/tools/mcp-client.js.map +1 -0
- package/dist/src/tools/mcp-client.test.d.ts +6 -0
- package/dist/src/tools/mcp-client.test.js +309 -0
- package/dist/src/tools/mcp-client.test.js.map +1 -0
- package/dist/src/tools/mcp-tool.d.ts +24 -0
- package/dist/src/tools/mcp-tool.js +268 -0
- package/dist/src/tools/mcp-tool.js.map +1 -0
- package/dist/src/tools/mcp-tool.test.d.ts +6 -0
- package/dist/src/tools/mcp-tool.test.js +714 -0
- package/dist/src/tools/mcp-tool.test.js.map +1 -0
- package/dist/src/tools/memoryTool.d.ts +41 -0
- package/dist/src/tools/memoryTool.js +396 -0
- package/dist/src/tools/memoryTool.js.map +1 -0
- package/dist/src/tools/memoryTool.test.d.ts +6 -0
- package/dist/src/tools/memoryTool.test.js +419 -0
- package/dist/src/tools/memoryTool.test.js.map +1 -0
- package/dist/src/tools/modifiable-tool.d.ts +32 -0
- package/dist/src/tools/modifiable-tool.js +88 -0
- package/dist/src/tools/modifiable-tool.js.map +1 -0
- package/dist/src/tools/modifiable-tool.test.d.ts +6 -0
- package/dist/src/tools/modifiable-tool.test.js +193 -0
- package/dist/src/tools/modifiable-tool.test.js.map +1 -0
- package/dist/src/tools/read-file.d.ts +35 -0
- package/dist/src/tools/read-file.js +124 -0
- package/dist/src/tools/read-file.js.map +1 -0
- package/dist/src/tools/read-file.test.d.ts +6 -0
- package/dist/src/tools/read-file.test.js +339 -0
- package/dist/src/tools/read-file.test.js.map +1 -0
- package/dist/src/tools/read-many-files.d.ts +60 -0
- package/dist/src/tools/read-many-files.js +391 -0
- package/dist/src/tools/read-many-files.js.map +1 -0
- package/dist/src/tools/read-many-files.test.d.ts +6 -0
- package/dist/src/tools/read-many-files.test.js +566 -0
- package/dist/src/tools/read-many-files.test.js.map +1 -0
- package/dist/src/tools/ripGrep.d.ts +44 -0
- package/dist/src/tools/ripGrep.js +233 -0
- package/dist/src/tools/ripGrep.js.map +1 -0
- package/dist/src/tools/ripGrep.test.d.ts +6 -0
- package/dist/src/tools/ripGrep.test.js +529 -0
- package/dist/src/tools/ripGrep.test.js.map +1 -0
- package/dist/src/tools/shell.d.ts +33 -0
- package/dist/src/tools/shell.js +388 -0
- package/dist/src/tools/shell.js.map +1 -0
- package/dist/src/tools/shell.test.d.ts +6 -0
- package/dist/src/tools/shell.test.js +566 -0
- package/dist/src/tools/shell.test.js.map +1 -0
- package/dist/src/tools/smart-edit.d.ts +91 -0
- package/dist/src/tools/smart-edit.js +703 -0
- package/dist/src/tools/smart-edit.js.map +1 -0
- package/dist/src/tools/smart-edit.test.d.ts +6 -0
- package/dist/src/tools/smart-edit.test.js +542 -0
- package/dist/src/tools/smart-edit.test.js.map +1 -0
- package/dist/src/tools/task.d.ts +59 -0
- package/dist/src/tools/task.js +412 -0
- package/dist/src/tools/task.js.map +1 -0
- package/dist/src/tools/task.test.d.ts +6 -0
- package/dist/src/tools/task.test.js +369 -0
- package/dist/src/tools/task.test.js.map +1 -0
- package/dist/src/tools/todoWrite.d.ts +42 -0
- package/dist/src/tools/todoWrite.js +407 -0
- package/dist/src/tools/todoWrite.js.map +1 -0
- package/dist/src/tools/todoWrite.test.d.ts +6 -0
- package/dist/src/tools/todoWrite.test.js +234 -0
- package/dist/src/tools/todoWrite.test.js.map +1 -0
- package/dist/src/tools/tool-error.d.ts +45 -0
- package/dist/src/tools/tool-error.js +61 -0
- package/dist/src/tools/tool-error.js.map +1 -0
- package/dist/src/tools/tool-names.d.ts +56 -0
- package/dist/src/tools/tool-names.js +62 -0
- package/dist/src/tools/tool-names.js.map +1 -0
- package/dist/src/tools/tool-registry.d.ts +87 -0
- package/dist/src/tools/tool-registry.js +370 -0
- package/dist/src/tools/tool-registry.js.map +1 -0
- package/dist/src/tools/tool-registry.test.d.ts +6 -0
- package/dist/src/tools/tool-registry.test.js +332 -0
- package/dist/src/tools/tool-registry.test.js.map +1 -0
- package/dist/src/tools/tools.d.ts +327 -0
- package/dist/src/tools/tools.js +258 -0
- package/dist/src/tools/tools.js.map +1 -0
- package/dist/src/tools/tools.test.d.ts +6 -0
- package/dist/src/tools/tools.test.js +205 -0
- package/dist/src/tools/tools.test.js.map +1 -0
- package/dist/src/tools/web-fetch.d.ts +31 -0
- package/dist/src/tools/web-fetch.js +163 -0
- package/dist/src/tools/web-fetch.js.map +1 -0
- package/dist/src/tools/web-fetch.test.d.ts +6 -0
- package/dist/src/tools/web-fetch.test.js +133 -0
- package/dist/src/tools/web-fetch.test.js.map +1 -0
- package/dist/src/tools/web-search/base-provider.d.ts +31 -0
- package/dist/src/tools/web-search/base-provider.js +34 -0
- package/dist/src/tools/web-search/base-provider.js.map +1 -0
- package/dist/src/tools/web-search/index.d.ts +24 -0
- package/dist/src/tools/web-search/index.js +245 -0
- package/dist/src/tools/web-search/index.js.map +1 -0
- package/dist/src/tools/web-search/index.test.d.ts +6 -0
- package/dist/src/tools/web-search/index.test.js +237 -0
- package/dist/src/tools/web-search/index.test.js.map +1 -0
- package/dist/src/tools/web-search/providers/dashscope-provider.d.ts +23 -0
- package/dist/src/tools/web-search/providers/dashscope-provider.js +120 -0
- package/dist/src/tools/web-search/providers/dashscope-provider.js.map +1 -0
- package/dist/src/tools/web-search/providers/google-provider.d.ts +17 -0
- package/dist/src/tools/web-search/providers/google-provider.js +55 -0
- package/dist/src/tools/web-search/providers/google-provider.js.map +1 -0
- package/dist/src/tools/web-search/providers/tavily-provider.d.ts +17 -0
- package/dist/src/tools/web-search/providers/tavily-provider.js +54 -0
- package/dist/src/tools/web-search/providers/tavily-provider.js.map +1 -0
- package/dist/src/tools/web-search/types.d.ts +138 -0
- package/dist/src/tools/web-search/types.js +7 -0
- package/dist/src/tools/web-search/types.js.map +1 -0
- package/dist/src/tools/web-search/utils.d.ts +28 -0
- package/dist/src/tools/web-search/utils.js +35 -0
- package/dist/src/tools/web-search/utils.js.map +1 -0
- package/dist/src/tools/write-file.d.ts +52 -0
- package/dist/src/tools/write-file.js +293 -0
- package/dist/src/tools/write-file.js.map +1 -0
- package/dist/src/tools/write-file.test.d.ts +6 -0
- package/dist/src/tools/write-file.test.js +516 -0
- package/dist/src/tools/write-file.test.js.map +1 -0
- package/dist/src/utils/LruCache.d.ts +13 -0
- package/dist/src/utils/LruCache.js +38 -0
- package/dist/src/utils/LruCache.js.map +1 -0
- package/dist/src/utils/bfsFileSearch.d.ts +24 -0
- package/dist/src/utils/bfsFileSearch.js +95 -0
- package/dist/src/utils/bfsFileSearch.js.map +1 -0
- package/dist/src/utils/bfsFileSearch.test.d.ts +6 -0
- package/dist/src/utils/bfsFileSearch.test.js +163 -0
- package/dist/src/utils/bfsFileSearch.test.js.map +1 -0
- package/dist/src/utils/browser.d.ts +13 -0
- package/dist/src/utils/browser.js +50 -0
- package/dist/src/utils/browser.js.map +1 -0
- package/dist/src/utils/editHelper.d.ts +53 -0
- package/dist/src/utils/editHelper.js +359 -0
- package/dist/src/utils/editHelper.js.map +1 -0
- package/dist/src/utils/editHelper.test.d.ts +6 -0
- package/dist/src/utils/editHelper.test.js +93 -0
- package/dist/src/utils/editHelper.test.js.map +1 -0
- package/dist/src/utils/editor.d.ts +28 -0
- package/dist/src/utils/editor.js +177 -0
- package/dist/src/utils/editor.js.map +1 -0
- package/dist/src/utils/editor.test.d.ts +6 -0
- package/dist/src/utils/editor.test.js +437 -0
- package/dist/src/utils/editor.test.js.map +1 -0
- package/dist/src/utils/environmentContext.d.ts +22 -0
- package/dist/src/utils/environmentContext.js +108 -0
- package/dist/src/utils/environmentContext.js.map +1 -0
- package/dist/src/utils/environmentContext.test.d.ts +6 -0
- package/dist/src/utils/environmentContext.test.js +219 -0
- package/dist/src/utils/environmentContext.test.js.map +1 -0
- package/dist/src/utils/errorParsing.d.ts +8 -0
- package/dist/src/utils/errorParsing.js +93 -0
- package/dist/src/utils/errorParsing.js.map +1 -0
- package/dist/src/utils/errorParsing.test.d.ts +6 -0
- package/dist/src/utils/errorParsing.test.js +172 -0
- package/dist/src/utils/errorParsing.test.js.map +1 -0
- package/dist/src/utils/errorReporting.d.ts +14 -0
- package/dist/src/utils/errorReporting.js +88 -0
- package/dist/src/utils/errorReporting.js.map +1 -0
- package/dist/src/utils/errorReporting.test.d.ts +6 -0
- package/dist/src/utils/errorReporting.test.js +130 -0
- package/dist/src/utils/errorReporting.test.js.map +1 -0
- package/dist/src/utils/errors.d.ts +39 -0
- package/dist/src/utils/errors.js +96 -0
- package/dist/src/utils/errors.js.map +1 -0
- package/dist/src/utils/fetch.d.ts +11 -0
- package/dist/src/utils/fetch.js +51 -0
- package/dist/src/utils/fetch.js.map +1 -0
- package/dist/src/utils/fileUtils.d.ts +69 -0
- package/dist/src/utils/fileUtils.js +426 -0
- package/dist/src/utils/fileUtils.js.map +1 -0
- package/dist/src/utils/fileUtils.test.d.ts +6 -0
- package/dist/src/utils/fileUtils.test.js +685 -0
- package/dist/src/utils/fileUtils.test.js.map +1 -0
- package/dist/src/utils/filesearch/crawlCache.d.ts +25 -0
- package/dist/src/utils/filesearch/crawlCache.js +57 -0
- package/dist/src/utils/filesearch/crawlCache.js.map +1 -0
- package/dist/src/utils/filesearch/crawlCache.test.d.ts +6 -0
- package/dist/src/utils/filesearch/crawlCache.test.js +103 -0
- package/dist/src/utils/filesearch/crawlCache.test.js.map +1 -0
- package/dist/src/utils/filesearch/crawler.d.ts +15 -0
- package/dist/src/utils/filesearch/crawler.js +50 -0
- package/dist/src/utils/filesearch/crawler.js.map +1 -0
- package/dist/src/utils/filesearch/crawler.test.d.ts +6 -0
- package/dist/src/utils/filesearch/crawler.test.js +468 -0
- package/dist/src/utils/filesearch/crawler.test.js.map +1 -0
- package/dist/src/utils/filesearch/fileSearch.d.ts +38 -0
- package/dist/src/utils/filesearch/fileSearch.js +191 -0
- package/dist/src/utils/filesearch/fileSearch.js.map +1 -0
- package/dist/src/utils/filesearch/fileSearch.test.d.ts +6 -0
- package/dist/src/utils/filesearch/fileSearch.test.js +642 -0
- package/dist/src/utils/filesearch/fileSearch.test.js.map +1 -0
- package/dist/src/utils/filesearch/ignore.d.ts +42 -0
- package/dist/src/utils/filesearch/ignore.js +106 -0
- package/dist/src/utils/filesearch/ignore.js.map +1 -0
- package/dist/src/utils/filesearch/ignore.test.d.ts +6 -0
- package/dist/src/utils/filesearch/ignore.test.js +144 -0
- package/dist/src/utils/filesearch/ignore.test.js.map +1 -0
- package/dist/src/utils/filesearch/result-cache.d.ts +33 -0
- package/dist/src/utils/filesearch/result-cache.js +59 -0
- package/dist/src/utils/filesearch/result-cache.js.map +1 -0
- package/dist/src/utils/filesearch/result-cache.test.d.ts +6 -0
- package/dist/src/utils/filesearch/result-cache.test.js +46 -0
- package/dist/src/utils/filesearch/result-cache.test.js.map +1 -0
- package/dist/src/utils/flashFallback.test.d.ts +6 -0
- package/dist/src/utils/flashFallback.test.js +122 -0
- package/dist/src/utils/flashFallback.test.js.map +1 -0
- package/dist/src/utils/formatters.d.ts +6 -0
- package/dist/src/utils/formatters.js +16 -0
- package/dist/src/utils/formatters.js.map +1 -0
- package/dist/src/utils/generateContentResponseUtilities.d.ts +13 -0
- package/dist/src/utils/generateContentResponseUtilities.js +80 -0
- package/dist/src/utils/generateContentResponseUtilities.js.map +1 -0
- package/dist/src/utils/generateContentResponseUtilities.test.d.ts +6 -0
- package/dist/src/utils/generateContentResponseUtilities.test.js +235 -0
- package/dist/src/utils/generateContentResponseUtilities.test.js.map +1 -0
- package/dist/src/utils/getFolderStructure.d.ts +31 -0
- package/dist/src/utils/getFolderStructure.js +246 -0
- package/dist/src/utils/getFolderStructure.js.map +1 -0
- package/dist/src/utils/getFolderStructure.test.d.ts +6 -0
- package/dist/src/utils/getFolderStructure.test.js +282 -0
- package/dist/src/utils/getFolderStructure.test.js.map +1 -0
- package/dist/src/utils/getPty.d.ts +19 -0
- package/dist/src/utils/getPty.js +23 -0
- package/dist/src/utils/getPty.js.map +1 -0
- package/dist/src/utils/gitIgnoreParser.d.ts +16 -0
- package/dist/src/utils/gitIgnoreParser.js +152 -0
- package/dist/src/utils/gitIgnoreParser.js.map +1 -0
- package/dist/src/utils/gitIgnoreParser.test.d.ts +6 -0
- package/dist/src/utils/gitIgnoreParser.test.js +185 -0
- package/dist/src/utils/gitIgnoreParser.test.js.map +1 -0
- package/dist/src/utils/gitUtils.d.ts +17 -0
- package/dist/src/utils/gitUtils.js +61 -0
- package/dist/src/utils/gitUtils.js.map +1 -0
- package/dist/src/utils/ignorePatterns.d.ts +103 -0
- package/dist/src/utils/ignorePatterns.js +220 -0
- package/dist/src/utils/ignorePatterns.js.map +1 -0
- package/dist/src/utils/ignorePatterns.test.d.ts +6 -0
- package/dist/src/utils/ignorePatterns.test.js +250 -0
- package/dist/src/utils/ignorePatterns.test.js.map +1 -0
- package/dist/src/utils/installationManager.d.ts +16 -0
- package/dist/src/utils/installationManager.js +50 -0
- package/dist/src/utils/installationManager.js.map +1 -0
- package/dist/src/utils/installationManager.test.d.ts +6 -0
- package/dist/src/utils/installationManager.test.js +83 -0
- package/dist/src/utils/installationManager.test.js.map +1 -0
- package/dist/src/utils/language-detection.d.ts +6 -0
- package/dist/src/utils/language-detection.js +101 -0
- package/dist/src/utils/language-detection.js.map +1 -0
- package/dist/src/utils/llm-edit-fixer.d.ts +26 -0
- package/dist/src/utils/llm-edit-fixer.js +131 -0
- package/dist/src/utils/llm-edit-fixer.js.map +1 -0
- package/dist/src/utils/llm-edit-fixer.test.d.ts +6 -0
- package/dist/src/utils/llm-edit-fixer.test.js +186 -0
- package/dist/src/utils/llm-edit-fixer.test.js.map +1 -0
- package/dist/src/utils/memoryDiscovery.d.ts +16 -0
- package/dist/src/utils/memoryDiscovery.js +272 -0
- package/dist/src/utils/memoryDiscovery.js.map +1 -0
- package/dist/src/utils/memoryDiscovery.test.d.ts +6 -0
- package/dist/src/utils/memoryDiscovery.test.js +244 -0
- package/dist/src/utils/memoryDiscovery.test.js.map +1 -0
- package/dist/src/utils/memoryImportProcessor.d.ts +42 -0
- package/dist/src/utils/memoryImportProcessor.js +284 -0
- package/dist/src/utils/memoryImportProcessor.js.map +1 -0
- package/dist/src/utils/memoryImportProcessor.test.d.ts +6 -0
- package/dist/src/utils/memoryImportProcessor.test.js +587 -0
- package/dist/src/utils/memoryImportProcessor.test.js.map +1 -0
- package/dist/src/utils/messageInspectors.d.ts +8 -0
- package/dist/src/utils/messageInspectors.js +16 -0
- package/dist/src/utils/messageInspectors.js.map +1 -0
- package/dist/src/utils/nextSpeakerChecker.d.ts +12 -0
- package/dist/src/utils/nextSpeakerChecker.js +97 -0
- package/dist/src/utils/nextSpeakerChecker.js.map +1 -0
- package/dist/src/utils/nextSpeakerChecker.test.d.ts +6 -0
- package/dist/src/utils/nextSpeakerChecker.test.js +181 -0
- package/dist/src/utils/nextSpeakerChecker.test.js.map +1 -0
- package/dist/src/utils/openaiLogger.d.ts +42 -0
- package/dist/src/utils/openaiLogger.js +138 -0
- package/dist/src/utils/openaiLogger.js.map +1 -0
- package/dist/src/utils/openaiLogger.test.d.ts +6 -0
- package/dist/src/utils/openaiLogger.test.js +304 -0
- package/dist/src/utils/openaiLogger.test.js.map +1 -0
- package/dist/src/utils/partUtils.d.ts +35 -0
- package/dist/src/utils/partUtils.js +133 -0
- package/dist/src/utils/partUtils.js.map +1 -0
- package/dist/src/utils/partUtils.test.d.ts +6 -0
- package/dist/src/utils/partUtils.test.js +241 -0
- package/dist/src/utils/partUtils.test.js.map +1 -0
- package/dist/src/utils/pathReader.d.ts +17 -0
- package/dist/src/utils/pathReader.js +92 -0
- package/dist/src/utils/pathReader.js.map +1 -0
- package/dist/src/utils/pathReader.test.d.ts +6 -0
- package/dist/src/utils/pathReader.test.js +365 -0
- package/dist/src/utils/pathReader.test.js.map +1 -0
- package/dist/src/utils/paths.d.ts +93 -0
- package/dist/src/utils/paths.js +229 -0
- package/dist/src/utils/paths.js.map +1 -0
- package/dist/src/utils/paths.test.d.ts +6 -0
- package/dist/src/utils/paths.test.js +438 -0
- package/dist/src/utils/paths.test.js.map +1 -0
- package/dist/src/utils/projectSummary.d.ts +22 -0
- package/dist/src/utils/projectSummary.js +86 -0
- package/dist/src/utils/projectSummary.js.map +1 -0
- package/dist/src/utils/promptIdContext.d.ts +7 -0
- package/dist/src/utils/promptIdContext.js +8 -0
- package/dist/src/utils/promptIdContext.js.map +1 -0
- package/dist/src/utils/quotaErrorDetection.d.ts +20 -0
- package/dist/src/utils/quotaErrorDetection.js +114 -0
- package/dist/src/utils/quotaErrorDetection.js.map +1 -0
- package/dist/src/utils/quotaErrorDetection.test.d.ts +6 -0
- package/dist/src/utils/quotaErrorDetection.test.js +153 -0
- package/dist/src/utils/quotaErrorDetection.test.js.map +1 -0
- package/dist/src/utils/qwenIgnoreParser.d.ts +18 -0
- package/dist/src/utils/qwenIgnoreParser.js +69 -0
- package/dist/src/utils/qwenIgnoreParser.js.map +1 -0
- package/dist/src/utils/qwenIgnoreParser.test.d.ts +6 -0
- package/dist/src/utils/qwenIgnoreParser.test.js +50 -0
- package/dist/src/utils/qwenIgnoreParser.test.js.map +1 -0
- package/dist/src/utils/request-tokenizer/imageTokenizer.d.ts +112 -0
- package/dist/src/utils/request-tokenizer/imageTokenizer.js +401 -0
- package/dist/src/utils/request-tokenizer/imageTokenizer.js.map +1 -0
- package/dist/src/utils/request-tokenizer/imageTokenizer.test.d.ts +6 -0
- package/dist/src/utils/request-tokenizer/imageTokenizer.test.js +114 -0
- package/dist/src/utils/request-tokenizer/imageTokenizer.test.js.map +1 -0
- package/dist/src/utils/request-tokenizer/index.d.ts +18 -0
- package/dist/src/utils/request-tokenizer/index.js +30 -0
- package/dist/src/utils/request-tokenizer/index.js.map +1 -0
- package/dist/src/utils/request-tokenizer/requestTokenizer.d.ts +56 -0
- package/dist/src/utils/request-tokenizer/requestTokenizer.js +263 -0
- package/dist/src/utils/request-tokenizer/requestTokenizer.js.map +1 -0
- package/dist/src/utils/request-tokenizer/requestTokenizer.test.d.ts +6 -0
- package/dist/src/utils/request-tokenizer/requestTokenizer.test.js +245 -0
- package/dist/src/utils/request-tokenizer/requestTokenizer.test.js.map +1 -0
- package/dist/src/utils/request-tokenizer/supportedImageFormats.d.ts +30 -0
- package/dist/src/utils/request-tokenizer/supportedImageFormats.js +41 -0
- package/dist/src/utils/request-tokenizer/supportedImageFormats.js.map +1 -0
- package/dist/src/utils/request-tokenizer/textTokenizer.d.ts +29 -0
- package/dist/src/utils/request-tokenizer/textTokenizer.js +88 -0
- package/dist/src/utils/request-tokenizer/textTokenizer.js.map +1 -0
- package/dist/src/utils/request-tokenizer/textTokenizer.test.d.ts +6 -0
- package/dist/src/utils/request-tokenizer/textTokenizer.test.js +253 -0
- package/dist/src/utils/request-tokenizer/textTokenizer.test.js.map +1 -0
- package/dist/src/utils/request-tokenizer/types.d.ts +55 -0
- package/dist/src/utils/request-tokenizer/types.js +7 -0
- package/dist/src/utils/request-tokenizer/types.js.map +1 -0
- package/dist/src/utils/retry.d.ts +32 -0
- package/dist/src/utils/retry.js +303 -0
- package/dist/src/utils/retry.js.map +1 -0
- package/dist/src/utils/retry.test.d.ts +6 -0
- package/dist/src/utils/retry.test.js +474 -0
- package/dist/src/utils/retry.test.js.map +1 -0
- package/dist/src/utils/ripgrepUtils.d.ts +61 -0
- package/dist/src/utils/ripgrepUtils.js +230 -0
- package/dist/src/utils/ripgrepUtils.js.map +1 -0
- package/dist/src/utils/ripgrepUtils.test.d.ts +6 -0
- package/dist/src/utils/ripgrepUtils.test.js +101 -0
- package/dist/src/utils/ripgrepUtils.test.js.map +1 -0
- package/dist/src/utils/safeJsonParse.d.ts +15 -0
- package/dist/src/utils/safeJsonParse.js +41 -0
- package/dist/src/utils/safeJsonParse.js.map +1 -0
- package/dist/src/utils/safeJsonParse.test.d.ts +6 -0
- package/dist/src/utils/safeJsonParse.test.js +112 -0
- package/dist/src/utils/safeJsonParse.test.js.map +1 -0
- package/dist/src/utils/safeJsonStringify.d.ts +13 -0
- package/dist/src/utils/safeJsonStringify.js +25 -0
- package/dist/src/utils/safeJsonStringify.js.map +1 -0
- package/dist/src/utils/safeJsonStringify.test.d.ts +6 -0
- package/dist/src/utils/safeJsonStringify.test.js +61 -0
- package/dist/src/utils/safeJsonStringify.test.js.map +1 -0
- package/dist/src/utils/schemaValidator.d.ts +15 -0
- package/dist/src/utils/schemaValidator.js +67 -0
- package/dist/src/utils/schemaValidator.js.map +1 -0
- package/dist/src/utils/schemaValidator.test.d.ts +6 -0
- package/dist/src/utils/schemaValidator.test.js +113 -0
- package/dist/src/utils/schemaValidator.test.js.map +1 -0
- package/dist/src/utils/secure-browser-launcher.d.ts +23 -0
- package/dist/src/utils/secure-browser-launcher.js +165 -0
- package/dist/src/utils/secure-browser-launcher.js.map +1 -0
- package/dist/src/utils/secure-browser-launcher.test.d.ts +6 -0
- package/dist/src/utils/secure-browser-launcher.test.js +149 -0
- package/dist/src/utils/secure-browser-launcher.test.js.map +1 -0
- package/dist/src/utils/session.d.ts +6 -0
- package/dist/src/utils/session.js +8 -0
- package/dist/src/utils/session.js.map +1 -0
- package/dist/src/utils/shell-utils.d.ts +152 -0
- package/dist/src/utils/shell-utils.js +467 -0
- package/dist/src/utils/shell-utils.js.map +1 -0
- package/dist/src/utils/shell-utils.test.d.ts +6 -0
- package/dist/src/utils/shell-utils.test.js +351 -0
- package/dist/src/utils/shell-utils.test.js.map +1 -0
- package/dist/src/utils/shellReadOnlyChecker.d.ts +6 -0
- package/dist/src/utils/shellReadOnlyChecker.js +247 -0
- package/dist/src/utils/shellReadOnlyChecker.js.map +1 -0
- package/dist/src/utils/shellReadOnlyChecker.test.d.ts +6 -0
- package/dist/src/utils/shellReadOnlyChecker.test.js +47 -0
- package/dist/src/utils/shellReadOnlyChecker.test.js.map +1 -0
- package/dist/src/utils/subagentGenerator.d.ts +20 -0
- package/dist/src/utils/subagentGenerator.js +120 -0
- package/dist/src/utils/subagentGenerator.js.map +1 -0
- package/dist/src/utils/subagentGenerator.test.d.ts +6 -0
- package/dist/src/utils/subagentGenerator.test.js +135 -0
- package/dist/src/utils/subagentGenerator.test.js.map +1 -0
- package/dist/src/utils/summarizer.d.ts +25 -0
- package/dist/src/utils/summarizer.js +51 -0
- package/dist/src/utils/summarizer.js.map +1 -0
- package/dist/src/utils/summarizer.test.d.ts +6 -0
- package/dist/src/utils/summarizer.test.js +131 -0
- package/dist/src/utils/summarizer.test.js.map +1 -0
- package/dist/src/utils/systemEncoding.d.ts +40 -0
- package/dist/src/utils/systemEncoding.js +149 -0
- package/dist/src/utils/systemEncoding.js.map +1 -0
- package/dist/src/utils/systemEncoding.test.d.ts +6 -0
- package/dist/src/utils/systemEncoding.test.js +368 -0
- package/dist/src/utils/systemEncoding.test.js.map +1 -0
- package/dist/src/utils/terminalSerializer.d.ts +25 -0
- package/dist/src/utils/terminalSerializer.js +432 -0
- package/dist/src/utils/terminalSerializer.js.map +1 -0
- package/dist/src/utils/terminalSerializer.test.d.ts +6 -0
- package/dist/src/utils/terminalSerializer.test.js +176 -0
- package/dist/src/utils/terminalSerializer.test.js.map +1 -0
- package/dist/src/utils/testUtils.d.ts +29 -0
- package/dist/src/utils/testUtils.js +70 -0
- package/dist/src/utils/testUtils.js.map +1 -0
- package/dist/src/utils/textUtils.d.ts +18 -0
- package/dist/src/utils/textUtils.js +42 -0
- package/dist/src/utils/textUtils.js.map +1 -0
- package/dist/src/utils/textUtils.test.d.ts +6 -0
- package/dist/src/utils/textUtils.test.js +59 -0
- package/dist/src/utils/textUtils.test.js.map +1 -0
- package/dist/src/utils/thoughtUtils.d.ts +21 -0
- package/dist/src/utils/thoughtUtils.js +39 -0
- package/dist/src/utils/thoughtUtils.js.map +1 -0
- package/dist/src/utils/thoughtUtils.test.d.ts +6 -0
- package/dist/src/utils/thoughtUtils.test.js +78 -0
- package/dist/src/utils/thoughtUtils.test.js.map +1 -0
- package/dist/src/utils/tool-utils.d.ts +22 -0
- package/dist/src/utils/tool-utils.js +121 -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 +100 -0
- package/dist/src/utils/tool-utils.test.js.map +1 -0
- package/dist/src/utils/userAccountManager.d.ts +20 -0
- package/dist/src/utils/userAccountManager.js +114 -0
- package/dist/src/utils/userAccountManager.js.map +1 -0
- package/dist/src/utils/userAccountManager.test.d.ts +6 -0
- package/dist/src/utils/userAccountManager.test.js +223 -0
- package/dist/src/utils/userAccountManager.test.js.map +1 -0
- package/dist/src/utils/workspaceContext.d.ts +66 -0
- package/dist/src/utils/workspaceContext.js +171 -0
- package/dist/src/utils/workspaceContext.js.map +1 -0
- package/dist/src/utils/workspaceContext.test.d.ts +6 -0
- package/dist/src/utils/workspaceContext.test.js +318 -0
- package/dist/src/utils/workspaceContext.test.js.map +1 -0
- package/dist/src/utils/yaml-parser.d.ts +29 -0
- package/dist/src/utils/yaml-parser.js +172 -0
- package/dist/src/utils/yaml-parser.js.map +1 -0
- package/dist/src/utils/yaml-parser.test.d.ts +6 -0
- package/dist/src/utils/yaml-parser.test.js +170 -0
- package/dist/src/utils/yaml-parser.test.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +106 -0
- package/scripts/postinstall.js +100 -0
- package/vendor/ripgrep/COPYING +3 -0
- package/vendor/ripgrep/arm64-darwin/rg +0 -0
- package/vendor/ripgrep/arm64-linux/rg +0 -0
- package/vendor/ripgrep/x64-darwin/rg +0 -0
- package/vendor/ripgrep/x64-linux/rg +0 -0
- package/vendor/ripgrep/x64-win32/rg.exe +0 -0
|
@@ -0,0 +1,1829 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2025 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import { describe, it, expect, vi, beforeEach, afterEach, } from 'vitest';
|
|
7
|
+
import { isThinkingDefault, isThinkingSupported, GeminiClient, } from './client.js';
|
|
8
|
+
import { findCompressSplitPoint } from '../services/chatCompressionService.js';
|
|
9
|
+
import { AuthType, } from './contentGenerator.js';
|
|
10
|
+
import {} from './geminiChat.js';
|
|
11
|
+
import { ApprovalMode } from '../config/config.js';
|
|
12
|
+
import { CompressionStatus, GeminiEventType, Turn, } from './turn.js';
|
|
13
|
+
import { getCoreSystemPrompt } from './prompts.js';
|
|
14
|
+
import { DEFAULT_GEMINI_FLASH_MODEL } from '../config/models.js';
|
|
15
|
+
import { FileDiscoveryService } from '../services/fileDiscoveryService.js';
|
|
16
|
+
import { setSimulate429 } from '../utils/testUtils.js';
|
|
17
|
+
import { tokenLimit } from './tokenLimits.js';
|
|
18
|
+
import { ideContextStore } from '../ide/ideContext.js';
|
|
19
|
+
import { uiTelemetryService } from '../telemetry/uiTelemetry.js';
|
|
20
|
+
// Mock fs module to prevent actual file system operations during tests
|
|
21
|
+
const mockFileSystem = new Map();
|
|
22
|
+
vi.mock('node:fs', () => {
|
|
23
|
+
const fsModule = {
|
|
24
|
+
mkdirSync: vi.fn(),
|
|
25
|
+
writeFileSync: vi.fn((path, data) => {
|
|
26
|
+
mockFileSystem.set(path, data);
|
|
27
|
+
}),
|
|
28
|
+
readFileSync: vi.fn((path) => {
|
|
29
|
+
if (mockFileSystem.has(path)) {
|
|
30
|
+
return mockFileSystem.get(path);
|
|
31
|
+
}
|
|
32
|
+
throw Object.assign(new Error('ENOENT: no such file or directory'), {
|
|
33
|
+
code: 'ENOENT',
|
|
34
|
+
});
|
|
35
|
+
}),
|
|
36
|
+
existsSync: vi.fn((path) => mockFileSystem.has(path)),
|
|
37
|
+
};
|
|
38
|
+
return {
|
|
39
|
+
default: fsModule,
|
|
40
|
+
...fsModule,
|
|
41
|
+
};
|
|
42
|
+
});
|
|
43
|
+
// --- Mocks ---
|
|
44
|
+
const mockTurnRunFn = vi.fn();
|
|
45
|
+
vi.mock('./turn', async (importOriginal) => {
|
|
46
|
+
const actual = await importOriginal();
|
|
47
|
+
// Define a mock class that has the same shape as the real Turn
|
|
48
|
+
class MockTurn {
|
|
49
|
+
pendingToolCalls = [];
|
|
50
|
+
// The run method is a property that holds our mock function
|
|
51
|
+
run = mockTurnRunFn;
|
|
52
|
+
constructor() {
|
|
53
|
+
// The constructor can be empty or do some mock setup
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
// Export the mock class as 'Turn'
|
|
57
|
+
return {
|
|
58
|
+
...actual,
|
|
59
|
+
Turn: MockTurn,
|
|
60
|
+
};
|
|
61
|
+
});
|
|
62
|
+
vi.mock('../config/config.js');
|
|
63
|
+
vi.mock('./prompts');
|
|
64
|
+
vi.mock('../utils/getFolderStructure', () => ({
|
|
65
|
+
getFolderStructure: vi.fn().mockResolvedValue('Mock Folder Structure'),
|
|
66
|
+
}));
|
|
67
|
+
vi.mock('../utils/errorReporting', () => ({ reportError: vi.fn() }));
|
|
68
|
+
vi.mock('../utils/nextSpeakerChecker', () => ({
|
|
69
|
+
checkNextSpeaker: vi.fn().mockResolvedValue(null),
|
|
70
|
+
}));
|
|
71
|
+
vi.mock('../utils/environmentContext', () => ({
|
|
72
|
+
getEnvironmentContext: vi
|
|
73
|
+
.fn()
|
|
74
|
+
.mockResolvedValue([{ text: 'Mocked env context' }]),
|
|
75
|
+
getInitialChatHistory: vi.fn(async (_config, extraHistory) => [
|
|
76
|
+
{
|
|
77
|
+
role: 'user',
|
|
78
|
+
parts: [{ text: 'Mocked env context' }],
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
role: 'model',
|
|
82
|
+
parts: [{ text: 'Got it. Thanks for the context!' }],
|
|
83
|
+
},
|
|
84
|
+
...(extraHistory ?? []),
|
|
85
|
+
]),
|
|
86
|
+
}));
|
|
87
|
+
vi.mock('../utils/generateContentResponseUtilities', () => ({
|
|
88
|
+
getResponseText: (result) => result.candidates?.[0]?.content?.parts?.map((part) => part.text).join('') ||
|
|
89
|
+
undefined,
|
|
90
|
+
getFunctionCalls: (result) => {
|
|
91
|
+
// Extract function calls from the response
|
|
92
|
+
const parts = result.candidates?.[0]?.content?.parts;
|
|
93
|
+
if (!parts) {
|
|
94
|
+
return undefined;
|
|
95
|
+
}
|
|
96
|
+
const functionCallParts = parts
|
|
97
|
+
.filter((part) => !!part.functionCall)
|
|
98
|
+
.map((part) => part.functionCall);
|
|
99
|
+
return functionCallParts.length > 0 ? functionCallParts : undefined;
|
|
100
|
+
},
|
|
101
|
+
}));
|
|
102
|
+
// Create shared mock for uiTelemetryService that's used by both telemetry mocks
|
|
103
|
+
const mockUiTelemetryService = vi.hoisted(() => ({
|
|
104
|
+
setLastPromptTokenCount: vi.fn(),
|
|
105
|
+
getLastPromptTokenCount: vi.fn(),
|
|
106
|
+
}));
|
|
107
|
+
vi.mock('../telemetry/index.js', async (importOriginal) => {
|
|
108
|
+
const actual = await importOriginal();
|
|
109
|
+
return {
|
|
110
|
+
...actual,
|
|
111
|
+
uiTelemetryService: mockUiTelemetryService,
|
|
112
|
+
// We keep the real implementations of logChatCompression, etc.
|
|
113
|
+
// but we can spy on QwenLogger if needed
|
|
114
|
+
};
|
|
115
|
+
});
|
|
116
|
+
vi.mock('../ide/ideContext.js');
|
|
117
|
+
vi.mock('../telemetry/uiTelemetry.js', () => ({
|
|
118
|
+
uiTelemetryService: mockUiTelemetryService,
|
|
119
|
+
}));
|
|
120
|
+
vi.mock('../telemetry/loggers.js', () => ({
|
|
121
|
+
logChatCompression: vi.fn(),
|
|
122
|
+
logNextSpeakerCheck: vi.fn(),
|
|
123
|
+
}));
|
|
124
|
+
/**
|
|
125
|
+
* Array.fromAsync ponyfill, which will be available in es 2024.
|
|
126
|
+
*
|
|
127
|
+
* Buffers an async generator into an array and returns the result.
|
|
128
|
+
*/
|
|
129
|
+
async function fromAsync(promise) {
|
|
130
|
+
const results = [];
|
|
131
|
+
for await (const result of promise) {
|
|
132
|
+
results.push(result);
|
|
133
|
+
}
|
|
134
|
+
return results;
|
|
135
|
+
}
|
|
136
|
+
describe('findCompressSplitPoint', () => {
|
|
137
|
+
it('should throw an error for non-positive numbers', () => {
|
|
138
|
+
expect(() => findCompressSplitPoint([], 0)).toThrow('Fraction must be between 0 and 1');
|
|
139
|
+
});
|
|
140
|
+
it('should throw an error for a fraction greater than or equal to 1', () => {
|
|
141
|
+
expect(() => findCompressSplitPoint([], 1)).toThrow('Fraction must be between 0 and 1');
|
|
142
|
+
});
|
|
143
|
+
it('should handle an empty history', () => {
|
|
144
|
+
expect(findCompressSplitPoint([], 0.5)).toBe(0);
|
|
145
|
+
});
|
|
146
|
+
it('should handle a fraction in the middle', () => {
|
|
147
|
+
const history = [
|
|
148
|
+
{ role: 'user', parts: [{ text: 'This is the first message.' }] }, // JSON length: 66 (19%)
|
|
149
|
+
{ role: 'model', parts: [{ text: 'This is the second message.' }] }, // JSON length: 68 (40%)
|
|
150
|
+
{ role: 'user', parts: [{ text: 'This is the third message.' }] }, // JSON length: 66 (60%)
|
|
151
|
+
{ role: 'model', parts: [{ text: 'This is the fourth message.' }] }, // JSON length: 68 (80%)
|
|
152
|
+
{ role: 'user', parts: [{ text: 'This is the fifth message.' }] }, // JSON length: 65 (100%)
|
|
153
|
+
];
|
|
154
|
+
expect(findCompressSplitPoint(history, 0.5)).toBe(4);
|
|
155
|
+
});
|
|
156
|
+
it('should handle a fraction of last index', () => {
|
|
157
|
+
const history = [
|
|
158
|
+
{ role: 'user', parts: [{ text: 'This is the first message.' }] }, // JSON length: 66 (19%)
|
|
159
|
+
{ role: 'model', parts: [{ text: 'This is the second message.' }] }, // JSON length: 68 (40%)
|
|
160
|
+
{ role: 'user', parts: [{ text: 'This is the third message.' }] }, // JSON length: 66 (60%)
|
|
161
|
+
{ role: 'model', parts: [{ text: 'This is the fourth message.' }] }, // JSON length: 68 (80%)
|
|
162
|
+
{ role: 'user', parts: [{ text: 'This is the fifth message.' }] }, // JSON length: 65 (100%)
|
|
163
|
+
];
|
|
164
|
+
expect(findCompressSplitPoint(history, 0.9)).toBe(4);
|
|
165
|
+
});
|
|
166
|
+
it('should handle a fraction of after last index', () => {
|
|
167
|
+
const history = [
|
|
168
|
+
{ role: 'user', parts: [{ text: 'This is the first message.' }] }, // JSON length: 66 (24%%)
|
|
169
|
+
{ role: 'model', parts: [{ text: 'This is the second message.' }] }, // JSON length: 68 (50%)
|
|
170
|
+
{ role: 'user', parts: [{ text: 'This is the third message.' }] }, // JSON length: 66 (74%)
|
|
171
|
+
{ role: 'model', parts: [{ text: 'This is the fourth message.' }] }, // JSON length: 68 (100%)
|
|
172
|
+
];
|
|
173
|
+
expect(findCompressSplitPoint(history, 0.8)).toBe(4);
|
|
174
|
+
});
|
|
175
|
+
it('should return earlier splitpoint if no valid ones are after threshhold', () => {
|
|
176
|
+
const history = [
|
|
177
|
+
{ role: 'user', parts: [{ text: 'This is the first message.' }] },
|
|
178
|
+
{ role: 'model', parts: [{ text: 'This is the second message.' }] },
|
|
179
|
+
{ role: 'user', parts: [{ text: 'This is the third message.' }] },
|
|
180
|
+
{ role: 'model', parts: [{ functionCall: {} }] },
|
|
181
|
+
];
|
|
182
|
+
// Can't return 4 because the previous item has a function call.
|
|
183
|
+
expect(findCompressSplitPoint(history, 0.99)).toBe(2);
|
|
184
|
+
});
|
|
185
|
+
it('should handle a history with only one item', () => {
|
|
186
|
+
const historyWithEmptyParts = [
|
|
187
|
+
{ role: 'user', parts: [{ text: 'Message 1' }] },
|
|
188
|
+
];
|
|
189
|
+
expect(findCompressSplitPoint(historyWithEmptyParts, 0.5)).toBe(0);
|
|
190
|
+
});
|
|
191
|
+
it('should handle history with weird parts', () => {
|
|
192
|
+
const historyWithEmptyParts = [
|
|
193
|
+
{ role: 'user', parts: [{ text: 'Message 1' }] },
|
|
194
|
+
{ role: 'model', parts: [{ fileData: { fileUri: 'derp' } }] },
|
|
195
|
+
{ role: 'user', parts: [{ text: 'Message 2' }] },
|
|
196
|
+
];
|
|
197
|
+
expect(findCompressSplitPoint(historyWithEmptyParts, 0.5)).toBe(2);
|
|
198
|
+
});
|
|
199
|
+
});
|
|
200
|
+
describe('isThinkingSupported', () => {
|
|
201
|
+
it('should return true for gemini-2.5', () => {
|
|
202
|
+
expect(isThinkingSupported('gemini-2.5')).toBe(true);
|
|
203
|
+
});
|
|
204
|
+
it('should return true for gemini-2.5-pro', () => {
|
|
205
|
+
expect(isThinkingSupported('gemini-2.5-pro')).toBe(true);
|
|
206
|
+
});
|
|
207
|
+
it('should return false for other models', () => {
|
|
208
|
+
expect(isThinkingSupported('gemini-1.5-flash')).toBe(false);
|
|
209
|
+
expect(isThinkingSupported('some-other-model')).toBe(false);
|
|
210
|
+
});
|
|
211
|
+
});
|
|
212
|
+
describe('isThinkingDefault', () => {
|
|
213
|
+
it('should return false for gemini-2.5-flash-lite', () => {
|
|
214
|
+
expect(isThinkingDefault('gemini-2.5-flash-lite')).toBe(false);
|
|
215
|
+
});
|
|
216
|
+
it('should return true for gemini-2.5', () => {
|
|
217
|
+
expect(isThinkingDefault('gemini-2.5')).toBe(true);
|
|
218
|
+
});
|
|
219
|
+
it('should return true for gemini-2.5-pro', () => {
|
|
220
|
+
expect(isThinkingDefault('gemini-2.5-pro')).toBe(true);
|
|
221
|
+
});
|
|
222
|
+
it('should return false for other models', () => {
|
|
223
|
+
expect(isThinkingDefault('gemini-1.5-flash')).toBe(false);
|
|
224
|
+
expect(isThinkingDefault('some-other-model')).toBe(false);
|
|
225
|
+
});
|
|
226
|
+
});
|
|
227
|
+
describe('Gemini Client (client.ts)', () => {
|
|
228
|
+
let mockContentGenerator;
|
|
229
|
+
let mockConfig;
|
|
230
|
+
let client;
|
|
231
|
+
let mockGenerateContentFn;
|
|
232
|
+
beforeEach(async () => {
|
|
233
|
+
vi.resetAllMocks();
|
|
234
|
+
vi.mocked(uiTelemetryService.setLastPromptTokenCount).mockClear();
|
|
235
|
+
mockGenerateContentFn = vi.fn().mockResolvedValue({
|
|
236
|
+
candidates: [{ content: { parts: [{ text: '{"key": "value"}' }] } }],
|
|
237
|
+
});
|
|
238
|
+
// Disable 429 simulation for tests
|
|
239
|
+
setSimulate429(false);
|
|
240
|
+
mockContentGenerator = {
|
|
241
|
+
generateContent: mockGenerateContentFn,
|
|
242
|
+
generateContentStream: vi.fn(),
|
|
243
|
+
batchEmbedContents: vi.fn(),
|
|
244
|
+
countTokens: vi.fn().mockResolvedValue({ totalTokens: 100 }),
|
|
245
|
+
};
|
|
246
|
+
// Because the GeminiClient constructor kicks off an async process (startChat)
|
|
247
|
+
// that depends on a fully-formed Config object, we need to mock the
|
|
248
|
+
// entire implementation of Config for these tests.
|
|
249
|
+
const mockToolRegistry = {
|
|
250
|
+
getFunctionDeclarations: vi.fn().mockReturnValue([]),
|
|
251
|
+
getTool: vi.fn().mockReturnValue(null),
|
|
252
|
+
};
|
|
253
|
+
const fileService = new FileDiscoveryService('/test/dir');
|
|
254
|
+
const contentGeneratorConfig = {
|
|
255
|
+
model: 'test-model',
|
|
256
|
+
apiKey: 'test-key',
|
|
257
|
+
vertexai: false,
|
|
258
|
+
authType: AuthType.USE_GEMINI,
|
|
259
|
+
};
|
|
260
|
+
const mockSubagentManager = {
|
|
261
|
+
listSubagents: vi.fn().mockResolvedValue([]),
|
|
262
|
+
addChangeListener: vi.fn().mockReturnValue(() => { }),
|
|
263
|
+
};
|
|
264
|
+
mockConfig = {
|
|
265
|
+
getContentGeneratorConfig: vi
|
|
266
|
+
.fn()
|
|
267
|
+
.mockReturnValue(contentGeneratorConfig),
|
|
268
|
+
getToolRegistry: vi.fn().mockReturnValue(mockToolRegistry),
|
|
269
|
+
getModel: vi.fn().mockReturnValue('test-model'),
|
|
270
|
+
getEmbeddingModel: vi.fn().mockReturnValue('test-embedding-model'),
|
|
271
|
+
getApiKey: vi.fn().mockReturnValue('test-key'),
|
|
272
|
+
getVertexAI: vi.fn().mockReturnValue(false),
|
|
273
|
+
getUserAgent: vi.fn().mockReturnValue('test-agent'),
|
|
274
|
+
getUserMemory: vi.fn().mockReturnValue(''),
|
|
275
|
+
getFullContext: vi.fn().mockReturnValue(false),
|
|
276
|
+
getSessionId: vi.fn().mockReturnValue('test-session-id'),
|
|
277
|
+
getProxy: vi.fn().mockReturnValue(undefined),
|
|
278
|
+
getWorkingDir: vi.fn().mockReturnValue('/test/dir'),
|
|
279
|
+
getFileService: vi.fn().mockReturnValue(fileService),
|
|
280
|
+
getMaxSessionTurns: vi.fn().mockReturnValue(0),
|
|
281
|
+
getSessionTokenLimit: vi.fn().mockReturnValue(32000),
|
|
282
|
+
getQuotaErrorOccurred: vi.fn().mockReturnValue(false),
|
|
283
|
+
setQuotaErrorOccurred: vi.fn(),
|
|
284
|
+
getNoBrowser: vi.fn().mockReturnValue(false),
|
|
285
|
+
getUsageStatisticsEnabled: vi.fn().mockReturnValue(true),
|
|
286
|
+
getApprovalMode: vi.fn().mockReturnValue(ApprovalMode.DEFAULT),
|
|
287
|
+
getIdeModeFeature: vi.fn().mockReturnValue(false),
|
|
288
|
+
getIdeMode: vi.fn().mockReturnValue(true),
|
|
289
|
+
getDebugMode: vi.fn().mockReturnValue(false),
|
|
290
|
+
getWorkspaceContext: vi.fn().mockReturnValue({
|
|
291
|
+
getDirectories: vi.fn().mockReturnValue(['/test/dir']),
|
|
292
|
+
}),
|
|
293
|
+
getGeminiClient: vi.fn(),
|
|
294
|
+
getModelRouterService: vi.fn().mockReturnValue({
|
|
295
|
+
route: vi.fn().mockResolvedValue({ model: 'default-routed-model' }),
|
|
296
|
+
}),
|
|
297
|
+
isInFallbackMode: vi.fn().mockReturnValue(false),
|
|
298
|
+
setFallbackMode: vi.fn(),
|
|
299
|
+
getCliVersion: vi.fn().mockReturnValue('1.0.0'),
|
|
300
|
+
getChatCompression: vi.fn().mockReturnValue(undefined),
|
|
301
|
+
getSkipNextSpeakerCheck: vi.fn().mockReturnValue(false),
|
|
302
|
+
getUseSmartEdit: vi.fn().mockReturnValue(false),
|
|
303
|
+
getUseModelRouter: vi.fn().mockReturnValue(false),
|
|
304
|
+
getProjectRoot: vi.fn().mockReturnValue('/test/project/root'),
|
|
305
|
+
storage: {
|
|
306
|
+
getProjectTempDir: vi.fn().mockReturnValue('/test/temp'),
|
|
307
|
+
},
|
|
308
|
+
getContentGenerator: vi.fn().mockReturnValue(mockContentGenerator),
|
|
309
|
+
getBaseLlmClient: vi.fn().mockReturnValue({
|
|
310
|
+
generateJson: vi.fn().mockResolvedValue({
|
|
311
|
+
next_speaker: 'user',
|
|
312
|
+
reasoning: 'test',
|
|
313
|
+
}),
|
|
314
|
+
}),
|
|
315
|
+
getSubagentManager: vi.fn().mockReturnValue(mockSubagentManager),
|
|
316
|
+
getSkipLoopDetection: vi.fn().mockReturnValue(false),
|
|
317
|
+
};
|
|
318
|
+
client = new GeminiClient(mockConfig);
|
|
319
|
+
await client.initialize();
|
|
320
|
+
vi.mocked(mockConfig.getGeminiClient).mockReturnValue(client);
|
|
321
|
+
});
|
|
322
|
+
afterEach(() => {
|
|
323
|
+
vi.restoreAllMocks();
|
|
324
|
+
});
|
|
325
|
+
describe('addHistory', () => {
|
|
326
|
+
it('should call chat.addHistory with the provided content', async () => {
|
|
327
|
+
const mockChat = {
|
|
328
|
+
addHistory: vi.fn(),
|
|
329
|
+
};
|
|
330
|
+
client['chat'] = mockChat;
|
|
331
|
+
const newContent = {
|
|
332
|
+
role: 'user',
|
|
333
|
+
parts: [{ text: 'New history item' }],
|
|
334
|
+
};
|
|
335
|
+
await client.addHistory(newContent);
|
|
336
|
+
expect(mockChat.addHistory).toHaveBeenCalledWith(newContent);
|
|
337
|
+
});
|
|
338
|
+
});
|
|
339
|
+
describe('resetChat', () => {
|
|
340
|
+
it('should create a new chat session, clearing the old history', async () => {
|
|
341
|
+
// 1. Get the initial chat instance and add some history.
|
|
342
|
+
const initialChat = client.getChat();
|
|
343
|
+
const initialHistory = await client.getHistory();
|
|
344
|
+
await client.addHistory({
|
|
345
|
+
role: 'user',
|
|
346
|
+
parts: [{ text: 'some old message' }],
|
|
347
|
+
});
|
|
348
|
+
const historyWithOldMessage = await client.getHistory();
|
|
349
|
+
expect(historyWithOldMessage.length).toBeGreaterThan(initialHistory.length);
|
|
350
|
+
// 2. Call resetChat.
|
|
351
|
+
await client.resetChat();
|
|
352
|
+
// 3. Get the new chat instance and its history.
|
|
353
|
+
const newChat = client.getChat();
|
|
354
|
+
const newHistory = await client.getHistory();
|
|
355
|
+
// 4. Assert that the chat instance is new and the history is reset.
|
|
356
|
+
expect(newChat).not.toBe(initialChat);
|
|
357
|
+
expect(newHistory.length).toBe(initialHistory.length);
|
|
358
|
+
expect(JSON.stringify(newHistory)).not.toContain('some old message');
|
|
359
|
+
});
|
|
360
|
+
});
|
|
361
|
+
describe('tryCompressChat', () => {
|
|
362
|
+
const mockGetHistory = vi.fn();
|
|
363
|
+
beforeEach(() => {
|
|
364
|
+
vi.mock('./tokenLimits', () => ({
|
|
365
|
+
tokenLimit: vi.fn(),
|
|
366
|
+
}));
|
|
367
|
+
client['chat'] = {
|
|
368
|
+
getHistory: mockGetHistory,
|
|
369
|
+
addHistory: vi.fn(),
|
|
370
|
+
setHistory: vi.fn(),
|
|
371
|
+
};
|
|
372
|
+
});
|
|
373
|
+
function setup({ chatHistory = [
|
|
374
|
+
{ role: 'user', parts: [{ text: 'Long conversation' }] },
|
|
375
|
+
{ role: 'model', parts: [{ text: 'Long response' }] },
|
|
376
|
+
], originalTokenCount = 1000, summaryText = 'This is a summary.', } = {}) {
|
|
377
|
+
const mockOriginalChat = {
|
|
378
|
+
getHistory: vi.fn((_curated) => chatHistory),
|
|
379
|
+
setHistory: vi.fn(),
|
|
380
|
+
};
|
|
381
|
+
client['chat'] = mockOriginalChat;
|
|
382
|
+
vi.mocked(uiTelemetryService.getLastPromptTokenCount).mockReturnValue(originalTokenCount);
|
|
383
|
+
mockGenerateContentFn.mockResolvedValue({
|
|
384
|
+
candidates: [
|
|
385
|
+
{
|
|
386
|
+
content: {
|
|
387
|
+
role: 'model',
|
|
388
|
+
parts: [{ text: summaryText }],
|
|
389
|
+
},
|
|
390
|
+
},
|
|
391
|
+
],
|
|
392
|
+
});
|
|
393
|
+
// Calculate what the new history will be
|
|
394
|
+
const splitPoint = findCompressSplitPoint(chatHistory, 0.7); // 1 - 0.3
|
|
395
|
+
const historyToKeep = chatHistory.slice(splitPoint);
|
|
396
|
+
// This is the history that the new chat will have.
|
|
397
|
+
// It includes the default startChat history + the extra history from tryCompressChat
|
|
398
|
+
const newCompressedHistory = [
|
|
399
|
+
// Mocked envParts + canned response from startChat
|
|
400
|
+
{
|
|
401
|
+
role: 'user',
|
|
402
|
+
parts: [{ text: 'Mocked env context' }],
|
|
403
|
+
},
|
|
404
|
+
{
|
|
405
|
+
role: 'model',
|
|
406
|
+
parts: [{ text: 'Got it. Thanks for the context!' }],
|
|
407
|
+
},
|
|
408
|
+
// extraHistory from tryCompressChat
|
|
409
|
+
{
|
|
410
|
+
role: 'user',
|
|
411
|
+
parts: [{ text: summaryText }],
|
|
412
|
+
},
|
|
413
|
+
{
|
|
414
|
+
role: 'model',
|
|
415
|
+
parts: [{ text: 'Got it. Thanks for the additional context!' }],
|
|
416
|
+
},
|
|
417
|
+
...historyToKeep,
|
|
418
|
+
];
|
|
419
|
+
const mockNewChat = {
|
|
420
|
+
getHistory: vi.fn().mockReturnValue(newCompressedHistory),
|
|
421
|
+
setHistory: vi.fn(),
|
|
422
|
+
};
|
|
423
|
+
client['startChat'] = vi
|
|
424
|
+
.fn()
|
|
425
|
+
.mockResolvedValue(mockNewChat);
|
|
426
|
+
const totalChars = newCompressedHistory.reduce((total, content) => total + JSON.stringify(content).length, 0);
|
|
427
|
+
const estimatedNewTokenCount = Math.floor(totalChars / 4);
|
|
428
|
+
return {
|
|
429
|
+
client,
|
|
430
|
+
mockOriginalChat,
|
|
431
|
+
mockNewChat,
|
|
432
|
+
estimatedNewTokenCount,
|
|
433
|
+
};
|
|
434
|
+
}
|
|
435
|
+
describe('when compression inflates the token count', () => {
|
|
436
|
+
it('allows compression to be forced/manual after a failure', async () => {
|
|
437
|
+
// Call 1 (Fails): Setup with a long summary to inflate tokens
|
|
438
|
+
const longSummary = 'long summary '.repeat(100);
|
|
439
|
+
const { client, estimatedNewTokenCount: inflatedTokenCount } = setup({
|
|
440
|
+
originalTokenCount: 100,
|
|
441
|
+
summaryText: longSummary,
|
|
442
|
+
});
|
|
443
|
+
expect(inflatedTokenCount).toBeGreaterThan(100); // Ensure setup is correct
|
|
444
|
+
await client.tryCompressChat('prompt-id-4', false); // Fails
|
|
445
|
+
// Call 2 (Forced): Re-setup with a short summary
|
|
446
|
+
const shortSummary = 'short';
|
|
447
|
+
const { estimatedNewTokenCount: compressedTokenCount } = setup({
|
|
448
|
+
originalTokenCount: 100,
|
|
449
|
+
summaryText: shortSummary,
|
|
450
|
+
});
|
|
451
|
+
expect(compressedTokenCount).toBeLessThanOrEqual(100); // Ensure setup is correct
|
|
452
|
+
const result = await client.tryCompressChat('prompt-id-4', true); // Forced
|
|
453
|
+
expect(result).toEqual({
|
|
454
|
+
compressionStatus: CompressionStatus.COMPRESSED,
|
|
455
|
+
newTokenCount: compressedTokenCount,
|
|
456
|
+
originalTokenCount: 100,
|
|
457
|
+
});
|
|
458
|
+
});
|
|
459
|
+
it('yields the result even if the compression inflated the tokens', async () => {
|
|
460
|
+
const longSummary = 'long summary '.repeat(100);
|
|
461
|
+
const { client, estimatedNewTokenCount } = setup({
|
|
462
|
+
originalTokenCount: 100,
|
|
463
|
+
summaryText: longSummary,
|
|
464
|
+
});
|
|
465
|
+
expect(estimatedNewTokenCount).toBeGreaterThan(100); // Ensure setup is correct
|
|
466
|
+
const result = await client.tryCompressChat('prompt-id-4', false);
|
|
467
|
+
expect(result).toEqual({
|
|
468
|
+
compressionStatus: CompressionStatus.COMPRESSION_FAILED_INFLATED_TOKEN_COUNT,
|
|
469
|
+
newTokenCount: estimatedNewTokenCount,
|
|
470
|
+
originalTokenCount: 100,
|
|
471
|
+
});
|
|
472
|
+
// IMPORTANT: The change in client.ts means setLastPromptTokenCount is NOT called on failure
|
|
473
|
+
expect(uiTelemetryService.setLastPromptTokenCount).not.toHaveBeenCalled();
|
|
474
|
+
});
|
|
475
|
+
it('does not manipulate the source chat', async () => {
|
|
476
|
+
const longSummary = 'long summary '.repeat(100);
|
|
477
|
+
const { client, mockOriginalChat, estimatedNewTokenCount } = setup({
|
|
478
|
+
originalTokenCount: 100,
|
|
479
|
+
summaryText: longSummary,
|
|
480
|
+
});
|
|
481
|
+
expect(estimatedNewTokenCount).toBeGreaterThan(100); // Ensure setup is correct
|
|
482
|
+
await client.tryCompressChat('prompt-id-4', false);
|
|
483
|
+
// On failure, the chat should NOT be replaced
|
|
484
|
+
expect(client['chat']).toBe(mockOriginalChat);
|
|
485
|
+
});
|
|
486
|
+
it('will not attempt to compress context after a failure', async () => {
|
|
487
|
+
const longSummary = 'long summary '.repeat(100);
|
|
488
|
+
const { client, estimatedNewTokenCount } = setup({
|
|
489
|
+
originalTokenCount: 100,
|
|
490
|
+
summaryText: longSummary,
|
|
491
|
+
});
|
|
492
|
+
expect(estimatedNewTokenCount).toBeGreaterThan(100); // Ensure setup is correct
|
|
493
|
+
await client.tryCompressChat('prompt-id-4', false); // This fails and sets hasFailedCompressionAttempt = true
|
|
494
|
+
// This call should now be a NOOP
|
|
495
|
+
const result = await client.tryCompressChat('prompt-id-5', false);
|
|
496
|
+
// generateContent (for summary) should only have been called once
|
|
497
|
+
expect(mockGenerateContentFn).toHaveBeenCalledTimes(1);
|
|
498
|
+
expect(result).toEqual({
|
|
499
|
+
compressionStatus: CompressionStatus.NOOP,
|
|
500
|
+
newTokenCount: 0,
|
|
501
|
+
originalTokenCount: 0,
|
|
502
|
+
});
|
|
503
|
+
});
|
|
504
|
+
});
|
|
505
|
+
it('should not trigger summarization if token count is below threshold', async () => {
|
|
506
|
+
const MOCKED_TOKEN_LIMIT = 1000;
|
|
507
|
+
vi.mocked(tokenLimit).mockReturnValue(MOCKED_TOKEN_LIMIT);
|
|
508
|
+
mockGetHistory.mockReturnValue([
|
|
509
|
+
{ role: 'user', parts: [{ text: '...history...' }] },
|
|
510
|
+
]);
|
|
511
|
+
const originalTokenCount = MOCKED_TOKEN_LIMIT * 0.699;
|
|
512
|
+
vi.mocked(uiTelemetryService.getLastPromptTokenCount).mockReturnValue(originalTokenCount);
|
|
513
|
+
const initialChat = client.getChat();
|
|
514
|
+
const result = await client.tryCompressChat('prompt-id-2', false);
|
|
515
|
+
const newChat = client.getChat();
|
|
516
|
+
expect(tokenLimit).toHaveBeenCalled();
|
|
517
|
+
expect(result).toEqual({
|
|
518
|
+
compressionStatus: CompressionStatus.NOOP,
|
|
519
|
+
newTokenCount: originalTokenCount,
|
|
520
|
+
originalTokenCount,
|
|
521
|
+
});
|
|
522
|
+
expect(newChat).toBe(initialChat);
|
|
523
|
+
});
|
|
524
|
+
it('logs a telemetry event when compressing', async () => {
|
|
525
|
+
const { logChatCompression } = await import('../telemetry/loggers.js');
|
|
526
|
+
vi.mocked(logChatCompression).mockClear();
|
|
527
|
+
const MOCKED_TOKEN_LIMIT = 1000;
|
|
528
|
+
const MOCKED_CONTEXT_PERCENTAGE_THRESHOLD = 0.5;
|
|
529
|
+
vi.mocked(tokenLimit).mockReturnValue(MOCKED_TOKEN_LIMIT);
|
|
530
|
+
vi.spyOn(client['config'], 'getChatCompression').mockReturnValue({
|
|
531
|
+
contextPercentageThreshold: MOCKED_CONTEXT_PERCENTAGE_THRESHOLD,
|
|
532
|
+
});
|
|
533
|
+
// Need multiple history items so there's something to compress
|
|
534
|
+
const history = [
|
|
535
|
+
{ role: 'user', parts: [{ text: '...history 1...' }] },
|
|
536
|
+
{ role: 'model', parts: [{ text: '...history 2...' }] },
|
|
537
|
+
{ role: 'user', parts: [{ text: '...history 3...' }] },
|
|
538
|
+
{ role: 'model', parts: [{ text: '...history 4...' }] },
|
|
539
|
+
];
|
|
540
|
+
mockGetHistory.mockReturnValue(history);
|
|
541
|
+
// Token count needs to be ABOVE the threshold to trigger compression
|
|
542
|
+
const originalTokenCount = MOCKED_TOKEN_LIMIT * MOCKED_CONTEXT_PERCENTAGE_THRESHOLD + 1;
|
|
543
|
+
vi.mocked(uiTelemetryService.getLastPromptTokenCount).mockReturnValue(originalTokenCount);
|
|
544
|
+
// Mock the summary response from the chat
|
|
545
|
+
const summaryText = 'This is a summary.';
|
|
546
|
+
mockGenerateContentFn.mockResolvedValue({
|
|
547
|
+
candidates: [
|
|
548
|
+
{
|
|
549
|
+
content: {
|
|
550
|
+
role: 'model',
|
|
551
|
+
parts: [{ text: summaryText }],
|
|
552
|
+
},
|
|
553
|
+
},
|
|
554
|
+
],
|
|
555
|
+
});
|
|
556
|
+
// Mock startChat to complete the compression flow
|
|
557
|
+
const splitPoint = findCompressSplitPoint(history, 0.7);
|
|
558
|
+
const historyToKeep = history.slice(splitPoint);
|
|
559
|
+
const newCompressedHistory = [
|
|
560
|
+
{ role: 'user', parts: [{ text: 'Mocked env context' }] },
|
|
561
|
+
{ role: 'model', parts: [{ text: 'Got it. Thanks for the context!' }] },
|
|
562
|
+
{ role: 'user', parts: [{ text: summaryText }] },
|
|
563
|
+
{
|
|
564
|
+
role: 'model',
|
|
565
|
+
parts: [{ text: 'Got it. Thanks for the additional context!' }],
|
|
566
|
+
},
|
|
567
|
+
...historyToKeep,
|
|
568
|
+
];
|
|
569
|
+
const mockNewChat = {
|
|
570
|
+
getHistory: vi.fn().mockReturnValue(newCompressedHistory),
|
|
571
|
+
};
|
|
572
|
+
client['startChat'] = vi
|
|
573
|
+
.fn()
|
|
574
|
+
.mockResolvedValue(mockNewChat);
|
|
575
|
+
await client.tryCompressChat('prompt-id-3', false);
|
|
576
|
+
expect(logChatCompression).toHaveBeenCalledWith(expect.anything(), expect.objectContaining({
|
|
577
|
+
tokens_before: originalTokenCount,
|
|
578
|
+
}));
|
|
579
|
+
expect(uiTelemetryService.setLastPromptTokenCount).toHaveBeenCalled();
|
|
580
|
+
});
|
|
581
|
+
it('should trigger summarization if token count is above threshold with contextPercentageThreshold setting', async () => {
|
|
582
|
+
const MOCKED_TOKEN_LIMIT = 1000;
|
|
583
|
+
const MOCKED_CONTEXT_PERCENTAGE_THRESHOLD = 0.5;
|
|
584
|
+
vi.mocked(tokenLimit).mockReturnValue(MOCKED_TOKEN_LIMIT);
|
|
585
|
+
vi.spyOn(client['config'], 'getChatCompression').mockReturnValue({
|
|
586
|
+
contextPercentageThreshold: MOCKED_CONTEXT_PERCENTAGE_THRESHOLD,
|
|
587
|
+
});
|
|
588
|
+
// Need multiple history items so there's something to compress
|
|
589
|
+
const history = [
|
|
590
|
+
{ role: 'user', parts: [{ text: '...history 1...' }] },
|
|
591
|
+
{ role: 'model', parts: [{ text: '...history 2...' }] },
|
|
592
|
+
{ role: 'user', parts: [{ text: '...history 3...' }] },
|
|
593
|
+
{ role: 'model', parts: [{ text: '...history 4...' }] },
|
|
594
|
+
];
|
|
595
|
+
mockGetHistory.mockReturnValue(history);
|
|
596
|
+
// Token count needs to be ABOVE the threshold to trigger compression
|
|
597
|
+
const originalTokenCount = MOCKED_TOKEN_LIMIT * MOCKED_CONTEXT_PERCENTAGE_THRESHOLD + 1;
|
|
598
|
+
vi.mocked(uiTelemetryService.getLastPromptTokenCount).mockReturnValue(originalTokenCount);
|
|
599
|
+
// Mock summary and new chat
|
|
600
|
+
const summaryText = 'This is a summary.';
|
|
601
|
+
const splitPoint = findCompressSplitPoint(history, 0.7);
|
|
602
|
+
const historyToKeep = history.slice(splitPoint);
|
|
603
|
+
const newCompressedHistory = [
|
|
604
|
+
{ role: 'user', parts: [{ text: 'Mocked env context' }] },
|
|
605
|
+
{ role: 'model', parts: [{ text: 'Got it. Thanks for the context!' }] },
|
|
606
|
+
{ role: 'user', parts: [{ text: summaryText }] },
|
|
607
|
+
{
|
|
608
|
+
role: 'model',
|
|
609
|
+
parts: [{ text: 'Got it. Thanks for the additional context!' }],
|
|
610
|
+
},
|
|
611
|
+
...historyToKeep,
|
|
612
|
+
];
|
|
613
|
+
const mockNewChat = {
|
|
614
|
+
getHistory: vi.fn().mockReturnValue(newCompressedHistory),
|
|
615
|
+
};
|
|
616
|
+
client['startChat'] = vi
|
|
617
|
+
.fn()
|
|
618
|
+
.mockResolvedValue(mockNewChat);
|
|
619
|
+
const totalChars = newCompressedHistory.reduce((total, content) => total + JSON.stringify(content).length, 0);
|
|
620
|
+
const newTokenCount = Math.floor(totalChars / 4);
|
|
621
|
+
// Mock the summary response from the chat
|
|
622
|
+
mockGenerateContentFn.mockResolvedValue({
|
|
623
|
+
candidates: [
|
|
624
|
+
{
|
|
625
|
+
content: {
|
|
626
|
+
role: 'model',
|
|
627
|
+
parts: [{ text: summaryText }],
|
|
628
|
+
},
|
|
629
|
+
},
|
|
630
|
+
],
|
|
631
|
+
});
|
|
632
|
+
const initialChat = client.getChat();
|
|
633
|
+
const result = await client.tryCompressChat('prompt-id-3', false);
|
|
634
|
+
const newChat = client.getChat();
|
|
635
|
+
expect(tokenLimit).toHaveBeenCalled();
|
|
636
|
+
expect(mockGenerateContentFn).toHaveBeenCalled();
|
|
637
|
+
// Assert that summarization happened and returned the correct stats
|
|
638
|
+
expect(result).toEqual({
|
|
639
|
+
compressionStatus: CompressionStatus.COMPRESSED,
|
|
640
|
+
originalTokenCount,
|
|
641
|
+
newTokenCount,
|
|
642
|
+
});
|
|
643
|
+
// Assert that the chat was reset
|
|
644
|
+
expect(newChat).not.toBe(initialChat);
|
|
645
|
+
});
|
|
646
|
+
it('should not compress across a function call response', async () => {
|
|
647
|
+
const MOCKED_TOKEN_LIMIT = 1000;
|
|
648
|
+
vi.mocked(tokenLimit).mockReturnValue(MOCKED_TOKEN_LIMIT);
|
|
649
|
+
const history = [
|
|
650
|
+
{ role: 'user', parts: [{ text: '...history 1...' }] },
|
|
651
|
+
{ role: 'model', parts: [{ text: '...history 2...' }] },
|
|
652
|
+
{ role: 'user', parts: [{ text: '...history 3...' }] },
|
|
653
|
+
{ role: 'model', parts: [{ text: '...history 4...' }] },
|
|
654
|
+
{ role: 'user', parts: [{ text: '...history 5...' }] },
|
|
655
|
+
{ role: 'model', parts: [{ text: '...history 6...' }] },
|
|
656
|
+
{ role: 'user', parts: [{ text: '...history 7...' }] },
|
|
657
|
+
{ role: 'model', parts: [{ text: '...history 8...' }] },
|
|
658
|
+
// Normally we would break here, but we have a function response.
|
|
659
|
+
{
|
|
660
|
+
role: 'user',
|
|
661
|
+
parts: [{ functionResponse: { name: '...history 8...' } }],
|
|
662
|
+
},
|
|
663
|
+
{ role: 'model', parts: [{ text: '...history 10...' }] },
|
|
664
|
+
// Instead we will break here.
|
|
665
|
+
{ role: 'user', parts: [{ text: '...history 10...' }] },
|
|
666
|
+
];
|
|
667
|
+
mockGetHistory.mockReturnValue(history);
|
|
668
|
+
const originalTokenCount = 1000 * 0.7;
|
|
669
|
+
vi.mocked(uiTelemetryService.getLastPromptTokenCount).mockReturnValue(originalTokenCount);
|
|
670
|
+
// Mock summary and new chat
|
|
671
|
+
const summaryText = 'This is a summary.';
|
|
672
|
+
const splitPoint = findCompressSplitPoint(history, 0.7); // This should be 10
|
|
673
|
+
expect(splitPoint).toBe(10); // Verify split point logic
|
|
674
|
+
const historyToKeep = history.slice(splitPoint); // Should keep last user message
|
|
675
|
+
expect(historyToKeep).toEqual([
|
|
676
|
+
{ role: 'user', parts: [{ text: '...history 10...' }] },
|
|
677
|
+
]);
|
|
678
|
+
const newCompressedHistory = [
|
|
679
|
+
{ role: 'user', parts: [{ text: 'Mocked env context' }] },
|
|
680
|
+
{ role: 'model', parts: [{ text: 'Got it. Thanks for the context!' }] },
|
|
681
|
+
{ role: 'user', parts: [{ text: summaryText }] },
|
|
682
|
+
{
|
|
683
|
+
role: 'model',
|
|
684
|
+
parts: [{ text: 'Got it. Thanks for the additional context!' }],
|
|
685
|
+
},
|
|
686
|
+
...historyToKeep,
|
|
687
|
+
];
|
|
688
|
+
const mockNewChat = {
|
|
689
|
+
getHistory: vi.fn().mockReturnValue(newCompressedHistory),
|
|
690
|
+
};
|
|
691
|
+
client['startChat'] = vi
|
|
692
|
+
.fn()
|
|
693
|
+
.mockResolvedValue(mockNewChat);
|
|
694
|
+
const totalChars = newCompressedHistory.reduce((total, content) => total + JSON.stringify(content).length, 0);
|
|
695
|
+
const newTokenCount = Math.floor(totalChars / 4);
|
|
696
|
+
// Mock the summary response from the chat
|
|
697
|
+
mockGenerateContentFn.mockResolvedValue({
|
|
698
|
+
candidates: [
|
|
699
|
+
{
|
|
700
|
+
content: {
|
|
701
|
+
role: 'model',
|
|
702
|
+
parts: [{ text: summaryText }],
|
|
703
|
+
},
|
|
704
|
+
},
|
|
705
|
+
],
|
|
706
|
+
});
|
|
707
|
+
const initialChat = client.getChat();
|
|
708
|
+
const result = await client.tryCompressChat('prompt-id-3', false);
|
|
709
|
+
const newChat = client.getChat();
|
|
710
|
+
expect(tokenLimit).toHaveBeenCalled();
|
|
711
|
+
expect(mockGenerateContentFn).toHaveBeenCalled();
|
|
712
|
+
// Assert that summarization happened and returned the correct stats
|
|
713
|
+
expect(result).toEqual({
|
|
714
|
+
compressionStatus: CompressionStatus.COMPRESSED,
|
|
715
|
+
originalTokenCount,
|
|
716
|
+
newTokenCount,
|
|
717
|
+
});
|
|
718
|
+
// Assert that the chat was reset
|
|
719
|
+
expect(newChat).not.toBe(initialChat);
|
|
720
|
+
// 1. standard start context message (env)
|
|
721
|
+
// 2. standard canned model response
|
|
722
|
+
// 3. compressed summary message (user)
|
|
723
|
+
// 4. standard canned model response
|
|
724
|
+
// 5. The last user message (historyToKeep)
|
|
725
|
+
expect(newChat.getHistory().length).toEqual(5);
|
|
726
|
+
});
|
|
727
|
+
it('should always trigger summarization when force is true, regardless of token count', async () => {
|
|
728
|
+
// Need multiple history items so there's something to compress
|
|
729
|
+
const history = [
|
|
730
|
+
{ role: 'user', parts: [{ text: '...history 1...' }] },
|
|
731
|
+
{ role: 'model', parts: [{ text: '...history 2...' }] },
|
|
732
|
+
{ role: 'user', parts: [{ text: '...history 3...' }] },
|
|
733
|
+
{ role: 'model', parts: [{ text: '...history 4...' }] },
|
|
734
|
+
];
|
|
735
|
+
mockGetHistory.mockReturnValue(history);
|
|
736
|
+
const originalTokenCount = 100; // Well below threshold, but > estimated new count
|
|
737
|
+
vi.mocked(uiTelemetryService.getLastPromptTokenCount).mockReturnValue(originalTokenCount);
|
|
738
|
+
// Mock summary and new chat
|
|
739
|
+
const summaryText = 'This is a summary.';
|
|
740
|
+
const splitPoint = findCompressSplitPoint(history, 0.7);
|
|
741
|
+
const historyToKeep = history.slice(splitPoint);
|
|
742
|
+
const newCompressedHistory = [
|
|
743
|
+
{ role: 'user', parts: [{ text: 'Mocked env context' }] },
|
|
744
|
+
{ role: 'model', parts: [{ text: 'Got it. Thanks for the context!' }] },
|
|
745
|
+
{ role: 'user', parts: [{ text: summaryText }] },
|
|
746
|
+
{
|
|
747
|
+
role: 'model',
|
|
748
|
+
parts: [{ text: 'Got it. Thanks for the additional context!' }],
|
|
749
|
+
},
|
|
750
|
+
...historyToKeep,
|
|
751
|
+
];
|
|
752
|
+
const mockNewChat = {
|
|
753
|
+
getHistory: vi.fn().mockReturnValue(newCompressedHistory),
|
|
754
|
+
};
|
|
755
|
+
client['startChat'] = vi
|
|
756
|
+
.fn()
|
|
757
|
+
.mockResolvedValue(mockNewChat);
|
|
758
|
+
const totalChars = newCompressedHistory.reduce((total, content) => total + JSON.stringify(content).length, 0);
|
|
759
|
+
const newTokenCount = Math.floor(totalChars / 4);
|
|
760
|
+
// Mock the summary response from the chat
|
|
761
|
+
mockGenerateContentFn.mockResolvedValue({
|
|
762
|
+
candidates: [
|
|
763
|
+
{
|
|
764
|
+
content: {
|
|
765
|
+
role: 'model',
|
|
766
|
+
parts: [{ text: summaryText }],
|
|
767
|
+
},
|
|
768
|
+
},
|
|
769
|
+
],
|
|
770
|
+
});
|
|
771
|
+
const initialChat = client.getChat();
|
|
772
|
+
const result = await client.tryCompressChat('prompt-id-1', true); // force = true
|
|
773
|
+
const newChat = client.getChat();
|
|
774
|
+
expect(mockGenerateContentFn).toHaveBeenCalled();
|
|
775
|
+
expect(result).toEqual({
|
|
776
|
+
compressionStatus: CompressionStatus.COMPRESSED,
|
|
777
|
+
originalTokenCount,
|
|
778
|
+
newTokenCount,
|
|
779
|
+
});
|
|
780
|
+
// Assert that the chat was reset
|
|
781
|
+
expect(newChat).not.toBe(initialChat);
|
|
782
|
+
});
|
|
783
|
+
});
|
|
784
|
+
describe('sendMessageStream', () => {
|
|
785
|
+
it('emits a compression event when the context was automatically compressed', async () => {
|
|
786
|
+
// Arrange
|
|
787
|
+
mockTurnRunFn.mockReturnValue((async function* () {
|
|
788
|
+
yield { type: 'content', value: 'Hello' };
|
|
789
|
+
})());
|
|
790
|
+
const compressionInfo = {
|
|
791
|
+
compressionStatus: CompressionStatus.COMPRESSED,
|
|
792
|
+
originalTokenCount: 1000,
|
|
793
|
+
newTokenCount: 500,
|
|
794
|
+
};
|
|
795
|
+
vi.spyOn(client, 'tryCompressChat').mockResolvedValueOnce(compressionInfo);
|
|
796
|
+
// Act
|
|
797
|
+
const stream = client.sendMessageStream([{ text: 'Hi' }], new AbortController().signal, 'prompt-id-1');
|
|
798
|
+
const events = await fromAsync(stream);
|
|
799
|
+
// Assert
|
|
800
|
+
expect(events).toContainEqual({
|
|
801
|
+
type: GeminiEventType.ChatCompressed,
|
|
802
|
+
value: compressionInfo,
|
|
803
|
+
});
|
|
804
|
+
});
|
|
805
|
+
it.each([
|
|
806
|
+
{
|
|
807
|
+
compressionStatus: CompressionStatus.COMPRESSION_FAILED_INFLATED_TOKEN_COUNT,
|
|
808
|
+
},
|
|
809
|
+
{ compressionStatus: CompressionStatus.NOOP },
|
|
810
|
+
])('does not emit a compression event when the status is $compressionStatus', async ({ compressionStatus }) => {
|
|
811
|
+
// Arrange
|
|
812
|
+
const mockStream = (async function* () {
|
|
813
|
+
yield { type: 'content', value: 'Hello' };
|
|
814
|
+
})();
|
|
815
|
+
mockTurnRunFn.mockReturnValue(mockStream);
|
|
816
|
+
const compressionInfo = {
|
|
817
|
+
compressionStatus,
|
|
818
|
+
originalTokenCount: 1000,
|
|
819
|
+
newTokenCount: 500,
|
|
820
|
+
};
|
|
821
|
+
vi.spyOn(client, 'tryCompressChat').mockResolvedValueOnce(compressionInfo);
|
|
822
|
+
// Act
|
|
823
|
+
const stream = client.sendMessageStream([{ text: 'Hi' }], new AbortController().signal, 'prompt-id-1');
|
|
824
|
+
const events = await fromAsync(stream);
|
|
825
|
+
// Assert
|
|
826
|
+
expect(events).not.toContainEqual({
|
|
827
|
+
type: GeminiEventType.ChatCompressed,
|
|
828
|
+
value: expect.anything(),
|
|
829
|
+
});
|
|
830
|
+
});
|
|
831
|
+
it('should include editor context when ideMode is enabled', async () => {
|
|
832
|
+
// Arrange
|
|
833
|
+
vi.mocked(ideContextStore.get).mockReturnValue({
|
|
834
|
+
workspaceState: {
|
|
835
|
+
openFiles: [
|
|
836
|
+
{
|
|
837
|
+
path: '/path/to/active/file.ts',
|
|
838
|
+
timestamp: Date.now(),
|
|
839
|
+
isActive: true,
|
|
840
|
+
selectedText: 'hello',
|
|
841
|
+
cursor: { line: 5, character: 10 },
|
|
842
|
+
},
|
|
843
|
+
{
|
|
844
|
+
path: '/path/to/recent/file1.ts',
|
|
845
|
+
timestamp: Date.now(),
|
|
846
|
+
},
|
|
847
|
+
{
|
|
848
|
+
path: '/path/to/recent/file2.ts',
|
|
849
|
+
timestamp: Date.now(),
|
|
850
|
+
},
|
|
851
|
+
],
|
|
852
|
+
},
|
|
853
|
+
});
|
|
854
|
+
vi.mocked(mockConfig.getIdeMode).mockReturnValue(true);
|
|
855
|
+
vi.spyOn(client, 'tryCompressChat').mockResolvedValue({
|
|
856
|
+
originalTokenCount: 0,
|
|
857
|
+
newTokenCount: 0,
|
|
858
|
+
compressionStatus: CompressionStatus.COMPRESSED,
|
|
859
|
+
});
|
|
860
|
+
mockTurnRunFn.mockReturnValue((async function* () {
|
|
861
|
+
yield { type: 'content', value: 'Hello' };
|
|
862
|
+
})());
|
|
863
|
+
const mockChat = {
|
|
864
|
+
addHistory: vi.fn(),
|
|
865
|
+
getHistory: vi.fn().mockReturnValue([]),
|
|
866
|
+
};
|
|
867
|
+
client['chat'] = mockChat;
|
|
868
|
+
const initialRequest = [{ text: 'Hi' }];
|
|
869
|
+
// Act
|
|
870
|
+
const stream = client.sendMessageStream(initialRequest, new AbortController().signal, 'prompt-id-ide');
|
|
871
|
+
for await (const _ of stream) {
|
|
872
|
+
// consume stream
|
|
873
|
+
}
|
|
874
|
+
// Assert
|
|
875
|
+
expect(ideContextStore.get).toHaveBeenCalled();
|
|
876
|
+
const expectedContext = `
|
|
877
|
+
Here is the user's editor context as a JSON object. This is for your information only.
|
|
878
|
+
\`\`\`json
|
|
879
|
+
${JSON.stringify({
|
|
880
|
+
activeFile: {
|
|
881
|
+
path: '/path/to/active/file.ts',
|
|
882
|
+
cursor: {
|
|
883
|
+
line: 5,
|
|
884
|
+
character: 10,
|
|
885
|
+
},
|
|
886
|
+
selectedText: 'hello',
|
|
887
|
+
},
|
|
888
|
+
otherOpenFiles: ['/path/to/recent/file1.ts', '/path/to/recent/file2.ts'],
|
|
889
|
+
}, null, 2)}
|
|
890
|
+
\`\`\`
|
|
891
|
+
`.trim();
|
|
892
|
+
const expectedRequest = [{ text: expectedContext }];
|
|
893
|
+
expect(mockChat.addHistory).toHaveBeenCalledWith({
|
|
894
|
+
role: 'user',
|
|
895
|
+
parts: expectedRequest,
|
|
896
|
+
});
|
|
897
|
+
});
|
|
898
|
+
it('should not add context if ideMode is enabled but no open files', async () => {
|
|
899
|
+
// Arrange
|
|
900
|
+
vi.mocked(ideContextStore.get).mockReturnValue({
|
|
901
|
+
workspaceState: {
|
|
902
|
+
openFiles: [],
|
|
903
|
+
},
|
|
904
|
+
});
|
|
905
|
+
vi.spyOn(client['config'], 'getIdeMode').mockReturnValue(true);
|
|
906
|
+
const mockStream = (async function* () {
|
|
907
|
+
yield { type: 'content', value: 'Hello' };
|
|
908
|
+
})();
|
|
909
|
+
mockTurnRunFn.mockReturnValue(mockStream);
|
|
910
|
+
const mockChat = {
|
|
911
|
+
addHistory: vi.fn(),
|
|
912
|
+
getHistory: vi.fn().mockReturnValue([]),
|
|
913
|
+
};
|
|
914
|
+
client['chat'] = mockChat;
|
|
915
|
+
const initialRequest = [{ text: 'Hi' }];
|
|
916
|
+
// Act
|
|
917
|
+
const stream = client.sendMessageStream(initialRequest, new AbortController().signal, 'prompt-id-ide');
|
|
918
|
+
for await (const _ of stream) {
|
|
919
|
+
// consume stream
|
|
920
|
+
}
|
|
921
|
+
// Assert
|
|
922
|
+
expect(ideContextStore.get).toHaveBeenCalled();
|
|
923
|
+
// The `turn.run` method is now called with the model name as the first
|
|
924
|
+
// argument and the request parts are passed in a simplified format.
|
|
925
|
+
// We verify that turn.run was called (indicating no IDE context was added).
|
|
926
|
+
expect(mockTurnRunFn).toHaveBeenCalled();
|
|
927
|
+
});
|
|
928
|
+
it('should add context if ideMode is enabled and there is one active file', async () => {
|
|
929
|
+
// Arrange
|
|
930
|
+
vi.mocked(ideContextStore.get).mockReturnValue({
|
|
931
|
+
workspaceState: {
|
|
932
|
+
openFiles: [
|
|
933
|
+
{
|
|
934
|
+
path: '/path/to/active/file.ts',
|
|
935
|
+
timestamp: Date.now(),
|
|
936
|
+
isActive: true,
|
|
937
|
+
selectedText: 'hello',
|
|
938
|
+
cursor: { line: 5, character: 10 },
|
|
939
|
+
},
|
|
940
|
+
],
|
|
941
|
+
},
|
|
942
|
+
});
|
|
943
|
+
vi.spyOn(client['config'], 'getIdeMode').mockReturnValue(true);
|
|
944
|
+
vi.spyOn(client, 'tryCompressChat').mockResolvedValue({
|
|
945
|
+
originalTokenCount: 0,
|
|
946
|
+
newTokenCount: 0,
|
|
947
|
+
compressionStatus: CompressionStatus.COMPRESSED,
|
|
948
|
+
});
|
|
949
|
+
const mockStream = (async function* () {
|
|
950
|
+
yield { type: 'content', value: 'Hello' };
|
|
951
|
+
})();
|
|
952
|
+
mockTurnRunFn.mockReturnValue(mockStream);
|
|
953
|
+
const mockChat = {
|
|
954
|
+
addHistory: vi.fn(),
|
|
955
|
+
getHistory: vi.fn().mockReturnValue([]),
|
|
956
|
+
};
|
|
957
|
+
client['chat'] = mockChat;
|
|
958
|
+
const initialRequest = [{ text: 'Hi' }];
|
|
959
|
+
// Act
|
|
960
|
+
const stream = client.sendMessageStream(initialRequest, new AbortController().signal, 'prompt-id-ide');
|
|
961
|
+
for await (const _ of stream) {
|
|
962
|
+
// consume stream
|
|
963
|
+
}
|
|
964
|
+
// Assert
|
|
965
|
+
expect(ideContextStore.get).toHaveBeenCalled();
|
|
966
|
+
const expectedContext = `
|
|
967
|
+
Here is the user's editor context as a JSON object. This is for your information only.
|
|
968
|
+
\`\`\`json
|
|
969
|
+
${JSON.stringify({
|
|
970
|
+
activeFile: {
|
|
971
|
+
path: '/path/to/active/file.ts',
|
|
972
|
+
cursor: {
|
|
973
|
+
line: 5,
|
|
974
|
+
character: 10,
|
|
975
|
+
},
|
|
976
|
+
selectedText: 'hello',
|
|
977
|
+
},
|
|
978
|
+
}, null, 2)}
|
|
979
|
+
\`\`\`
|
|
980
|
+
`.trim();
|
|
981
|
+
const expectedRequest = [{ text: expectedContext }];
|
|
982
|
+
expect(mockChat.addHistory).toHaveBeenCalledWith({
|
|
983
|
+
role: 'user',
|
|
984
|
+
parts: expectedRequest,
|
|
985
|
+
});
|
|
986
|
+
});
|
|
987
|
+
it('should add context if ideMode is enabled and there are open files but no active file', async () => {
|
|
988
|
+
// Arrange
|
|
989
|
+
vi.mocked(ideContextStore.get).mockReturnValue({
|
|
990
|
+
workspaceState: {
|
|
991
|
+
openFiles: [
|
|
992
|
+
{
|
|
993
|
+
path: '/path/to/recent/file1.ts',
|
|
994
|
+
timestamp: Date.now(),
|
|
995
|
+
},
|
|
996
|
+
{
|
|
997
|
+
path: '/path/to/recent/file2.ts',
|
|
998
|
+
timestamp: Date.now(),
|
|
999
|
+
},
|
|
1000
|
+
],
|
|
1001
|
+
},
|
|
1002
|
+
});
|
|
1003
|
+
vi.spyOn(client['config'], 'getIdeMode').mockReturnValue(true);
|
|
1004
|
+
vi.spyOn(client, 'tryCompressChat').mockResolvedValue({
|
|
1005
|
+
originalTokenCount: 0,
|
|
1006
|
+
newTokenCount: 0,
|
|
1007
|
+
compressionStatus: CompressionStatus.COMPRESSED,
|
|
1008
|
+
});
|
|
1009
|
+
const mockStream = (async function* () {
|
|
1010
|
+
yield { type: 'content', value: 'Hello' };
|
|
1011
|
+
})();
|
|
1012
|
+
mockTurnRunFn.mockReturnValue(mockStream);
|
|
1013
|
+
const mockChat = {
|
|
1014
|
+
addHistory: vi.fn(),
|
|
1015
|
+
getHistory: vi.fn().mockReturnValue([]),
|
|
1016
|
+
};
|
|
1017
|
+
client['chat'] = mockChat;
|
|
1018
|
+
const initialRequest = [{ text: 'Hi' }];
|
|
1019
|
+
// Act
|
|
1020
|
+
const stream = client.sendMessageStream(initialRequest, new AbortController().signal, 'prompt-id-ide');
|
|
1021
|
+
for await (const _ of stream) {
|
|
1022
|
+
// consume stream
|
|
1023
|
+
}
|
|
1024
|
+
// Assert
|
|
1025
|
+
expect(ideContextStore.get).toHaveBeenCalled();
|
|
1026
|
+
const expectedContext = `
|
|
1027
|
+
Here is the user's editor context as a JSON object. This is for your information only.
|
|
1028
|
+
\`\`\`json
|
|
1029
|
+
${JSON.stringify({
|
|
1030
|
+
otherOpenFiles: ['/path/to/recent/file1.ts', '/path/to/recent/file2.ts'],
|
|
1031
|
+
}, null, 2)}
|
|
1032
|
+
\`\`\`
|
|
1033
|
+
`.trim();
|
|
1034
|
+
const expectedRequest = [{ text: expectedContext }];
|
|
1035
|
+
expect(mockChat.addHistory).toHaveBeenCalledWith({
|
|
1036
|
+
role: 'user',
|
|
1037
|
+
parts: expectedRequest,
|
|
1038
|
+
});
|
|
1039
|
+
});
|
|
1040
|
+
it('should return the turn instance after the stream is complete', async () => {
|
|
1041
|
+
// Arrange
|
|
1042
|
+
const mockStream = (async function* () {
|
|
1043
|
+
yield { type: 'content', value: 'Hello' };
|
|
1044
|
+
})();
|
|
1045
|
+
mockTurnRunFn.mockReturnValue(mockStream);
|
|
1046
|
+
const mockChat = {
|
|
1047
|
+
addHistory: vi.fn(),
|
|
1048
|
+
getHistory: vi.fn().mockReturnValue([]),
|
|
1049
|
+
};
|
|
1050
|
+
client['chat'] = mockChat;
|
|
1051
|
+
// Act
|
|
1052
|
+
const stream = client.sendMessageStream([{ text: 'Hi' }], new AbortController().signal, 'prompt-id-1');
|
|
1053
|
+
// Consume the stream manually to get the final return value.
|
|
1054
|
+
let finalResult;
|
|
1055
|
+
while (true) {
|
|
1056
|
+
const result = await stream.next();
|
|
1057
|
+
if (result.done) {
|
|
1058
|
+
finalResult = result.value;
|
|
1059
|
+
break;
|
|
1060
|
+
}
|
|
1061
|
+
}
|
|
1062
|
+
// Assert
|
|
1063
|
+
expect(finalResult).toBeInstanceOf(Turn);
|
|
1064
|
+
});
|
|
1065
|
+
it('should stop infinite loop after MAX_TURNS when nextSpeaker always returns model', async () => {
|
|
1066
|
+
// Get the mocked checkNextSpeaker function and configure it to trigger infinite loop
|
|
1067
|
+
const { checkNextSpeaker } = await import('../utils/nextSpeakerChecker.js');
|
|
1068
|
+
const mockCheckNextSpeaker = vi.mocked(checkNextSpeaker);
|
|
1069
|
+
mockCheckNextSpeaker.mockResolvedValue({
|
|
1070
|
+
next_speaker: 'model',
|
|
1071
|
+
reasoning: 'Test case - always continue',
|
|
1072
|
+
});
|
|
1073
|
+
// Mock Turn to have no pending tool calls (which would allow nextSpeaker check)
|
|
1074
|
+
const mockStream = (async function* () {
|
|
1075
|
+
yield { type: 'content', value: 'Continue...' };
|
|
1076
|
+
})();
|
|
1077
|
+
mockTurnRunFn.mockReturnValue(mockStream);
|
|
1078
|
+
const mockChat = {
|
|
1079
|
+
addHistory: vi.fn(),
|
|
1080
|
+
getHistory: vi.fn().mockReturnValue([]),
|
|
1081
|
+
};
|
|
1082
|
+
client['chat'] = mockChat;
|
|
1083
|
+
// Use a signal that never gets aborted
|
|
1084
|
+
const abortController = new AbortController();
|
|
1085
|
+
const signal = abortController.signal;
|
|
1086
|
+
// Act - Start the stream that should loop
|
|
1087
|
+
const stream = client.sendMessageStream([{ text: 'Start conversation' }], signal, 'prompt-id-2');
|
|
1088
|
+
// Count how many stream events we get
|
|
1089
|
+
let eventCount = 0;
|
|
1090
|
+
let finalResult;
|
|
1091
|
+
// Consume the stream and count iterations
|
|
1092
|
+
while (true) {
|
|
1093
|
+
const result = await stream.next();
|
|
1094
|
+
if (result.done) {
|
|
1095
|
+
finalResult = result.value;
|
|
1096
|
+
break;
|
|
1097
|
+
}
|
|
1098
|
+
eventCount++;
|
|
1099
|
+
// Safety check to prevent actual infinite loop in test
|
|
1100
|
+
if (eventCount > 200) {
|
|
1101
|
+
abortController.abort();
|
|
1102
|
+
throw new Error('Test exceeded expected event limit - possible actual infinite loop');
|
|
1103
|
+
}
|
|
1104
|
+
}
|
|
1105
|
+
// Assert
|
|
1106
|
+
expect(finalResult).toBeInstanceOf(Turn);
|
|
1107
|
+
// Debug: Check how many times checkNextSpeaker was called
|
|
1108
|
+
const callCount = mockCheckNextSpeaker.mock.calls.length;
|
|
1109
|
+
// If infinite loop protection is working, checkNextSpeaker should be called many times
|
|
1110
|
+
// but stop at MAX_TURNS (100). Since each recursive call should trigger checkNextSpeaker,
|
|
1111
|
+
// we expect it to be called multiple times before hitting the limit
|
|
1112
|
+
expect(mockCheckNextSpeaker).toHaveBeenCalled();
|
|
1113
|
+
// The test should demonstrate that the infinite loop protection works:
|
|
1114
|
+
// - If checkNextSpeaker is called many times (close to MAX_TURNS), it shows the loop was happening
|
|
1115
|
+
// - If it's only called once, the recursive behavior might not be triggered
|
|
1116
|
+
if (callCount === 0) {
|
|
1117
|
+
throw new Error('checkNextSpeaker was never called - the recursive condition was not met');
|
|
1118
|
+
}
|
|
1119
|
+
else if (callCount === 1) {
|
|
1120
|
+
// This might be expected behavior if the turn has pending tool calls or other conditions prevent recursion
|
|
1121
|
+
console.log('checkNextSpeaker called only once - no infinite loop occurred');
|
|
1122
|
+
}
|
|
1123
|
+
else {
|
|
1124
|
+
console.log(`checkNextSpeaker called ${callCount} times - infinite loop protection worked`);
|
|
1125
|
+
// If called multiple times, we expect it to be stopped before MAX_TURNS
|
|
1126
|
+
expect(callCount).toBeLessThanOrEqual(100); // Should not exceed MAX_TURNS
|
|
1127
|
+
}
|
|
1128
|
+
// The stream should produce events and eventually terminate
|
|
1129
|
+
expect(eventCount).toBeGreaterThanOrEqual(1);
|
|
1130
|
+
expect(eventCount).toBeLessThan(200); // Should not exceed our safety limit
|
|
1131
|
+
});
|
|
1132
|
+
it('should yield MaxSessionTurns and stop when session turn limit is reached', async () => {
|
|
1133
|
+
// Arrange
|
|
1134
|
+
const MAX_SESSION_TURNS = 5;
|
|
1135
|
+
vi.spyOn(client['config'], 'getMaxSessionTurns').mockReturnValue(MAX_SESSION_TURNS);
|
|
1136
|
+
const mockStream = (async function* () {
|
|
1137
|
+
yield { type: 'content', value: 'Hello' };
|
|
1138
|
+
})();
|
|
1139
|
+
mockTurnRunFn.mockReturnValue(mockStream);
|
|
1140
|
+
const mockChat = {
|
|
1141
|
+
addHistory: vi.fn(),
|
|
1142
|
+
getHistory: vi.fn().mockReturnValue([]),
|
|
1143
|
+
};
|
|
1144
|
+
client['chat'] = mockChat;
|
|
1145
|
+
// Act & Assert
|
|
1146
|
+
// Run up to the limit
|
|
1147
|
+
for (let i = 0; i < MAX_SESSION_TURNS; i++) {
|
|
1148
|
+
const stream = client.sendMessageStream([{ text: 'Hi' }], new AbortController().signal, 'prompt-id-4');
|
|
1149
|
+
// consume stream
|
|
1150
|
+
for await (const _event of stream) {
|
|
1151
|
+
// do nothing
|
|
1152
|
+
}
|
|
1153
|
+
}
|
|
1154
|
+
// This call should exceed the limit
|
|
1155
|
+
const stream = client.sendMessageStream([{ text: 'Hi' }], new AbortController().signal, 'prompt-id-5');
|
|
1156
|
+
const events = [];
|
|
1157
|
+
for await (const event of stream) {
|
|
1158
|
+
events.push(event);
|
|
1159
|
+
}
|
|
1160
|
+
expect(events).toEqual([{ type: GeminiEventType.MaxSessionTurns }]);
|
|
1161
|
+
expect(mockTurnRunFn).toHaveBeenCalledTimes(MAX_SESSION_TURNS);
|
|
1162
|
+
});
|
|
1163
|
+
it('should respect MAX_TURNS limit even when turns parameter is set to a large value', async () => {
|
|
1164
|
+
// This test verifies that the infinite loop protection works even when
|
|
1165
|
+
// someone tries to bypass it by calling with a very large turns value
|
|
1166
|
+
// Get the mocked checkNextSpeaker function and configure it to trigger infinite loop
|
|
1167
|
+
const { checkNextSpeaker } = await import('../utils/nextSpeakerChecker.js');
|
|
1168
|
+
const mockCheckNextSpeaker = vi.mocked(checkNextSpeaker);
|
|
1169
|
+
mockCheckNextSpeaker.mockResolvedValue({
|
|
1170
|
+
next_speaker: 'model',
|
|
1171
|
+
reasoning: 'Test case - always continue',
|
|
1172
|
+
});
|
|
1173
|
+
// Mock Turn to have no pending tool calls (which would allow nextSpeaker check)
|
|
1174
|
+
const mockStream = (async function* () {
|
|
1175
|
+
yield { type: 'content', value: 'Continue...' };
|
|
1176
|
+
})();
|
|
1177
|
+
mockTurnRunFn.mockReturnValue(mockStream);
|
|
1178
|
+
const mockChat = {
|
|
1179
|
+
addHistory: vi.fn(),
|
|
1180
|
+
getHistory: vi.fn().mockReturnValue([]),
|
|
1181
|
+
};
|
|
1182
|
+
client['chat'] = mockChat;
|
|
1183
|
+
// Use a signal that never gets aborted
|
|
1184
|
+
const abortController = new AbortController();
|
|
1185
|
+
const signal = abortController.signal;
|
|
1186
|
+
// Act - Start the stream with an extremely high turns value
|
|
1187
|
+
// This simulates a case where the turns protection is bypassed
|
|
1188
|
+
const stream = client.sendMessageStream([{ text: 'Start conversation' }], signal, 'prompt-id-3', Number.MAX_SAFE_INTEGER);
|
|
1189
|
+
// Count how many stream events we get
|
|
1190
|
+
let eventCount = 0;
|
|
1191
|
+
const maxTestIterations = 1000; // Higher limit to show the loop continues
|
|
1192
|
+
// Consume the stream and count iterations
|
|
1193
|
+
try {
|
|
1194
|
+
while (true) {
|
|
1195
|
+
const result = await stream.next();
|
|
1196
|
+
if (result.done) {
|
|
1197
|
+
break;
|
|
1198
|
+
}
|
|
1199
|
+
eventCount++;
|
|
1200
|
+
// This test should hit this limit, demonstrating the infinite loop
|
|
1201
|
+
if (eventCount > maxTestIterations) {
|
|
1202
|
+
abortController.abort();
|
|
1203
|
+
// This is the expected behavior - we hit the infinite loop
|
|
1204
|
+
break;
|
|
1205
|
+
}
|
|
1206
|
+
}
|
|
1207
|
+
}
|
|
1208
|
+
catch (error) {
|
|
1209
|
+
// If the test framework times out, that also demonstrates the infinite loop
|
|
1210
|
+
console.error('Test timed out or errored:', error);
|
|
1211
|
+
}
|
|
1212
|
+
// Assert that the fix works - the loop should stop at MAX_TURNS
|
|
1213
|
+
const callCount = mockCheckNextSpeaker.mock.calls.length;
|
|
1214
|
+
// With the fix: even when turns is set to a very high value,
|
|
1215
|
+
// the loop should stop at MAX_TURNS (100)
|
|
1216
|
+
expect(callCount).toBeLessThanOrEqual(100); // Should not exceed MAX_TURNS
|
|
1217
|
+
expect(eventCount).toBeLessThanOrEqual(200); // Should have reasonable number of events
|
|
1218
|
+
console.log(`Infinite loop protection working: checkNextSpeaker called ${callCount} times, ` +
|
|
1219
|
+
`${eventCount} events generated (properly bounded by MAX_TURNS)`);
|
|
1220
|
+
});
|
|
1221
|
+
describe('Editor context delta', () => {
|
|
1222
|
+
const mockStream = (async function* () {
|
|
1223
|
+
yield { type: 'content', value: 'Hello' };
|
|
1224
|
+
})();
|
|
1225
|
+
beforeEach(() => {
|
|
1226
|
+
client['forceFullIdeContext'] = false; // Reset before each delta test
|
|
1227
|
+
vi.spyOn(client, 'tryCompressChat').mockResolvedValue({
|
|
1228
|
+
originalTokenCount: 0,
|
|
1229
|
+
newTokenCount: 0,
|
|
1230
|
+
compressionStatus: CompressionStatus.COMPRESSED,
|
|
1231
|
+
});
|
|
1232
|
+
vi.spyOn(client['config'], 'getIdeMode').mockReturnValue(true);
|
|
1233
|
+
mockTurnRunFn.mockReturnValue(mockStream);
|
|
1234
|
+
const mockChat = {
|
|
1235
|
+
addHistory: vi.fn(),
|
|
1236
|
+
setHistory: vi.fn(),
|
|
1237
|
+
// Assume history is not empty for delta checks
|
|
1238
|
+
getHistory: vi
|
|
1239
|
+
.fn()
|
|
1240
|
+
.mockReturnValue([
|
|
1241
|
+
{ role: 'user', parts: [{ text: 'previous message' }] },
|
|
1242
|
+
]),
|
|
1243
|
+
};
|
|
1244
|
+
client['chat'] = mockChat;
|
|
1245
|
+
});
|
|
1246
|
+
const testCases = [
|
|
1247
|
+
{
|
|
1248
|
+
description: 'sends delta when active file changes',
|
|
1249
|
+
previousActiveFile: {
|
|
1250
|
+
path: '/path/to/old/file.ts',
|
|
1251
|
+
cursor: { line: 5, character: 10 },
|
|
1252
|
+
selectedText: 'hello',
|
|
1253
|
+
},
|
|
1254
|
+
currentActiveFile: {
|
|
1255
|
+
path: '/path/to/active/file.ts',
|
|
1256
|
+
cursor: { line: 5, character: 10 },
|
|
1257
|
+
selectedText: 'hello',
|
|
1258
|
+
},
|
|
1259
|
+
shouldSendContext: true,
|
|
1260
|
+
},
|
|
1261
|
+
{
|
|
1262
|
+
description: 'sends delta when cursor line changes',
|
|
1263
|
+
previousActiveFile: {
|
|
1264
|
+
path: '/path/to/active/file.ts',
|
|
1265
|
+
cursor: { line: 1, character: 10 },
|
|
1266
|
+
selectedText: 'hello',
|
|
1267
|
+
},
|
|
1268
|
+
currentActiveFile: {
|
|
1269
|
+
path: '/path/to/active/file.ts',
|
|
1270
|
+
cursor: { line: 5, character: 10 },
|
|
1271
|
+
selectedText: 'hello',
|
|
1272
|
+
},
|
|
1273
|
+
shouldSendContext: true,
|
|
1274
|
+
},
|
|
1275
|
+
{
|
|
1276
|
+
description: 'sends delta when cursor character changes',
|
|
1277
|
+
previousActiveFile: {
|
|
1278
|
+
path: '/path/to/active/file.ts',
|
|
1279
|
+
cursor: { line: 5, character: 1 },
|
|
1280
|
+
selectedText: 'hello',
|
|
1281
|
+
},
|
|
1282
|
+
currentActiveFile: {
|
|
1283
|
+
path: '/path/to/active/file.ts',
|
|
1284
|
+
cursor: { line: 5, character: 10 },
|
|
1285
|
+
selectedText: 'hello',
|
|
1286
|
+
},
|
|
1287
|
+
shouldSendContext: true,
|
|
1288
|
+
},
|
|
1289
|
+
{
|
|
1290
|
+
description: 'sends delta when selected text changes',
|
|
1291
|
+
previousActiveFile: {
|
|
1292
|
+
path: '/path/to/active/file.ts',
|
|
1293
|
+
cursor: { line: 5, character: 10 },
|
|
1294
|
+
selectedText: 'world',
|
|
1295
|
+
},
|
|
1296
|
+
currentActiveFile: {
|
|
1297
|
+
path: '/path/to/active/file.ts',
|
|
1298
|
+
cursor: { line: 5, character: 10 },
|
|
1299
|
+
selectedText: 'hello',
|
|
1300
|
+
},
|
|
1301
|
+
shouldSendContext: true,
|
|
1302
|
+
},
|
|
1303
|
+
{
|
|
1304
|
+
description: 'sends delta when selected text is added',
|
|
1305
|
+
previousActiveFile: {
|
|
1306
|
+
path: '/path/to/active/file.ts',
|
|
1307
|
+
cursor: { line: 5, character: 10 },
|
|
1308
|
+
},
|
|
1309
|
+
currentActiveFile: {
|
|
1310
|
+
path: '/path/to/active/file.ts',
|
|
1311
|
+
cursor: { line: 5, character: 10 },
|
|
1312
|
+
selectedText: 'hello',
|
|
1313
|
+
},
|
|
1314
|
+
shouldSendContext: true,
|
|
1315
|
+
},
|
|
1316
|
+
{
|
|
1317
|
+
description: 'sends delta when selected text is removed',
|
|
1318
|
+
previousActiveFile: {
|
|
1319
|
+
path: '/path/to/active/file.ts',
|
|
1320
|
+
cursor: { line: 5, character: 10 },
|
|
1321
|
+
selectedText: 'hello',
|
|
1322
|
+
},
|
|
1323
|
+
currentActiveFile: {
|
|
1324
|
+
path: '/path/to/active/file.ts',
|
|
1325
|
+
cursor: { line: 5, character: 10 },
|
|
1326
|
+
},
|
|
1327
|
+
shouldSendContext: true,
|
|
1328
|
+
},
|
|
1329
|
+
{
|
|
1330
|
+
description: 'does not send context when nothing changes',
|
|
1331
|
+
previousActiveFile: {
|
|
1332
|
+
path: '/path/to/active/file.ts',
|
|
1333
|
+
cursor: { line: 5, character: 10 },
|
|
1334
|
+
selectedText: 'hello',
|
|
1335
|
+
},
|
|
1336
|
+
currentActiveFile: {
|
|
1337
|
+
path: '/path/to/active/file.ts',
|
|
1338
|
+
cursor: { line: 5, character: 10 },
|
|
1339
|
+
selectedText: 'hello',
|
|
1340
|
+
},
|
|
1341
|
+
shouldSendContext: false,
|
|
1342
|
+
},
|
|
1343
|
+
];
|
|
1344
|
+
it.each(testCases)('$description', async ({ previousActiveFile, currentActiveFile, shouldSendContext, }) => {
|
|
1345
|
+
// Setup previous context
|
|
1346
|
+
client['lastSentIdeContext'] = {
|
|
1347
|
+
workspaceState: {
|
|
1348
|
+
openFiles: [
|
|
1349
|
+
{
|
|
1350
|
+
path: previousActiveFile.path,
|
|
1351
|
+
cursor: previousActiveFile.cursor,
|
|
1352
|
+
selectedText: previousActiveFile.selectedText,
|
|
1353
|
+
isActive: true,
|
|
1354
|
+
timestamp: Date.now() - 1000,
|
|
1355
|
+
},
|
|
1356
|
+
],
|
|
1357
|
+
},
|
|
1358
|
+
};
|
|
1359
|
+
// Setup current context
|
|
1360
|
+
vi.mocked(ideContextStore.get).mockReturnValue({
|
|
1361
|
+
workspaceState: {
|
|
1362
|
+
openFiles: [
|
|
1363
|
+
{ ...currentActiveFile, isActive: true, timestamp: Date.now() },
|
|
1364
|
+
],
|
|
1365
|
+
},
|
|
1366
|
+
});
|
|
1367
|
+
const stream = client.sendMessageStream([{ text: 'Hi' }], new AbortController().signal, 'prompt-id-delta');
|
|
1368
|
+
for await (const _ of stream) {
|
|
1369
|
+
// consume stream
|
|
1370
|
+
}
|
|
1371
|
+
const mockChat = client['chat'];
|
|
1372
|
+
if (shouldSendContext) {
|
|
1373
|
+
expect(mockChat.addHistory).toHaveBeenCalledWith(expect.objectContaining({
|
|
1374
|
+
parts: expect.arrayContaining([
|
|
1375
|
+
expect.objectContaining({
|
|
1376
|
+
text: expect.stringContaining("Here is a summary of changes in the user's editor context"),
|
|
1377
|
+
}),
|
|
1378
|
+
]),
|
|
1379
|
+
}));
|
|
1380
|
+
}
|
|
1381
|
+
else {
|
|
1382
|
+
expect(mockChat.addHistory).not.toHaveBeenCalled();
|
|
1383
|
+
}
|
|
1384
|
+
});
|
|
1385
|
+
it('sends full context when history is cleared, even if editor state is unchanged', async () => {
|
|
1386
|
+
const activeFile = {
|
|
1387
|
+
path: '/path/to/active/file.ts',
|
|
1388
|
+
cursor: { line: 5, character: 10 },
|
|
1389
|
+
selectedText: 'hello',
|
|
1390
|
+
};
|
|
1391
|
+
// Setup previous context
|
|
1392
|
+
client['lastSentIdeContext'] = {
|
|
1393
|
+
workspaceState: {
|
|
1394
|
+
openFiles: [
|
|
1395
|
+
{
|
|
1396
|
+
path: activeFile.path,
|
|
1397
|
+
cursor: activeFile.cursor,
|
|
1398
|
+
selectedText: activeFile.selectedText,
|
|
1399
|
+
isActive: true,
|
|
1400
|
+
timestamp: Date.now() - 1000,
|
|
1401
|
+
},
|
|
1402
|
+
],
|
|
1403
|
+
},
|
|
1404
|
+
};
|
|
1405
|
+
// Setup current context (same as previous)
|
|
1406
|
+
vi.mocked(ideContextStore.get).mockReturnValue({
|
|
1407
|
+
workspaceState: {
|
|
1408
|
+
openFiles: [
|
|
1409
|
+
{ ...activeFile, isActive: true, timestamp: Date.now() },
|
|
1410
|
+
],
|
|
1411
|
+
},
|
|
1412
|
+
});
|
|
1413
|
+
// Make history empty
|
|
1414
|
+
const mockChat = client['chat'];
|
|
1415
|
+
mockChat.getHistory.mockReturnValue([]);
|
|
1416
|
+
const stream = client.sendMessageStream([{ text: 'Hi' }], new AbortController().signal, 'prompt-id-history-cleared');
|
|
1417
|
+
for await (const _ of stream) {
|
|
1418
|
+
// consume stream
|
|
1419
|
+
}
|
|
1420
|
+
expect(mockChat.addHistory).toHaveBeenCalledWith(expect.objectContaining({
|
|
1421
|
+
parts: expect.arrayContaining([
|
|
1422
|
+
expect.objectContaining({
|
|
1423
|
+
text: expect.stringContaining("Here is the user's editor context"),
|
|
1424
|
+
}),
|
|
1425
|
+
]),
|
|
1426
|
+
}));
|
|
1427
|
+
// Also verify it's the full context, not a delta.
|
|
1428
|
+
const call = mockChat.addHistory.mock.calls[0][0];
|
|
1429
|
+
const contextText = call.parts[0].text;
|
|
1430
|
+
const contextJson = JSON.parse(contextText.match(/```json\n(.*)\n```/s)[1]);
|
|
1431
|
+
expect(contextJson).toHaveProperty('activeFile');
|
|
1432
|
+
expect(contextJson.activeFile.path).toBe('/path/to/active/file.ts');
|
|
1433
|
+
});
|
|
1434
|
+
});
|
|
1435
|
+
describe('IDE context with pending tool calls', () => {
|
|
1436
|
+
let mockChat;
|
|
1437
|
+
beforeEach(() => {
|
|
1438
|
+
vi.spyOn(client, 'tryCompressChat').mockResolvedValue({
|
|
1439
|
+
originalTokenCount: 0,
|
|
1440
|
+
newTokenCount: 0,
|
|
1441
|
+
compressionStatus: CompressionStatus.COMPRESSED,
|
|
1442
|
+
});
|
|
1443
|
+
const mockStream = (async function* () {
|
|
1444
|
+
yield { type: 'content', value: 'response' };
|
|
1445
|
+
})();
|
|
1446
|
+
mockTurnRunFn.mockReturnValue(mockStream);
|
|
1447
|
+
mockChat = {
|
|
1448
|
+
addHistory: vi.fn(),
|
|
1449
|
+
getHistory: vi.fn().mockReturnValue([]), // Default empty history
|
|
1450
|
+
setHistory: vi.fn(),
|
|
1451
|
+
};
|
|
1452
|
+
client['chat'] = mockChat;
|
|
1453
|
+
vi.spyOn(client['config'], 'getIdeMode').mockReturnValue(true);
|
|
1454
|
+
vi.mocked(ideContextStore.get).mockReturnValue({
|
|
1455
|
+
workspaceState: {
|
|
1456
|
+
openFiles: [{ path: '/path/to/file.ts', timestamp: Date.now() }],
|
|
1457
|
+
},
|
|
1458
|
+
});
|
|
1459
|
+
});
|
|
1460
|
+
it('should NOT add IDE context when a tool call is pending', async () => {
|
|
1461
|
+
// Arrange: History ends with a functionCall from the model
|
|
1462
|
+
const historyWithPendingCall = [
|
|
1463
|
+
{ role: 'user', parts: [{ text: 'Please use a tool.' }] },
|
|
1464
|
+
{
|
|
1465
|
+
role: 'model',
|
|
1466
|
+
parts: [{ functionCall: { name: 'some_tool', args: {} } }],
|
|
1467
|
+
},
|
|
1468
|
+
];
|
|
1469
|
+
vi.mocked(mockChat.getHistory).mockReturnValue(historyWithPendingCall);
|
|
1470
|
+
// Act: Simulate sending the tool's response back
|
|
1471
|
+
const stream = client.sendMessageStream([
|
|
1472
|
+
{
|
|
1473
|
+
functionResponse: {
|
|
1474
|
+
name: 'some_tool',
|
|
1475
|
+
response: { success: true },
|
|
1476
|
+
},
|
|
1477
|
+
},
|
|
1478
|
+
], new AbortController().signal, 'prompt-id-tool-response');
|
|
1479
|
+
for await (const _ of stream) {
|
|
1480
|
+
// consume stream to complete the call
|
|
1481
|
+
}
|
|
1482
|
+
// Assert: The IDE context message should NOT have been added to the history.
|
|
1483
|
+
expect(mockChat.addHistory).not.toHaveBeenCalledWith(expect.objectContaining({
|
|
1484
|
+
parts: expect.arrayContaining([
|
|
1485
|
+
expect.objectContaining({
|
|
1486
|
+
text: expect.stringContaining("user's editor context"),
|
|
1487
|
+
}),
|
|
1488
|
+
]),
|
|
1489
|
+
}));
|
|
1490
|
+
});
|
|
1491
|
+
it('should add IDE context when no tool call is pending', async () => {
|
|
1492
|
+
// Arrange: History is normal, no pending calls
|
|
1493
|
+
const normalHistory = [
|
|
1494
|
+
{ role: 'user', parts: [{ text: 'A normal message.' }] },
|
|
1495
|
+
{ role: 'model', parts: [{ text: 'A normal response.' }] },
|
|
1496
|
+
];
|
|
1497
|
+
vi.mocked(mockChat.getHistory).mockReturnValue(normalHistory);
|
|
1498
|
+
// Act
|
|
1499
|
+
const stream = client.sendMessageStream([{ text: 'Another normal message' }], new AbortController().signal, 'prompt-id-normal');
|
|
1500
|
+
for await (const _ of stream) {
|
|
1501
|
+
// consume stream
|
|
1502
|
+
}
|
|
1503
|
+
// Assert: The IDE context message SHOULD have been added.
|
|
1504
|
+
expect(mockChat.addHistory).toHaveBeenCalledWith(expect.objectContaining({
|
|
1505
|
+
role: 'user',
|
|
1506
|
+
parts: expect.arrayContaining([
|
|
1507
|
+
expect.objectContaining({
|
|
1508
|
+
text: expect.stringContaining("user's editor context"),
|
|
1509
|
+
}),
|
|
1510
|
+
]),
|
|
1511
|
+
}));
|
|
1512
|
+
});
|
|
1513
|
+
it('should send the latest IDE context on the next message after a skipped context', async () => {
|
|
1514
|
+
// --- Step 1: A tool call is pending, context should be skipped ---
|
|
1515
|
+
// Arrange: History ends with a functionCall
|
|
1516
|
+
const historyWithPendingCall = [
|
|
1517
|
+
{ role: 'user', parts: [{ text: 'Please use a tool.' }] },
|
|
1518
|
+
{
|
|
1519
|
+
role: 'model',
|
|
1520
|
+
parts: [{ functionCall: { name: 'some_tool', args: {} } }],
|
|
1521
|
+
},
|
|
1522
|
+
];
|
|
1523
|
+
vi.mocked(mockChat.getHistory).mockReturnValue(historyWithPendingCall);
|
|
1524
|
+
// Arrange: Set the initial IDE context
|
|
1525
|
+
const initialIdeContext = {
|
|
1526
|
+
workspaceState: {
|
|
1527
|
+
openFiles: [{ path: '/path/to/fileA.ts', timestamp: Date.now() }],
|
|
1528
|
+
},
|
|
1529
|
+
};
|
|
1530
|
+
vi.mocked(ideContextStore.get).mockReturnValue(initialIdeContext);
|
|
1531
|
+
// Act: Send the tool response
|
|
1532
|
+
let stream = client.sendMessageStream([
|
|
1533
|
+
{
|
|
1534
|
+
functionResponse: {
|
|
1535
|
+
name: 'some_tool',
|
|
1536
|
+
response: { success: true },
|
|
1537
|
+
},
|
|
1538
|
+
},
|
|
1539
|
+
], new AbortController().signal, 'prompt-id-tool-response');
|
|
1540
|
+
for await (const _ of stream) {
|
|
1541
|
+
/* consume */
|
|
1542
|
+
}
|
|
1543
|
+
// Assert: The initial context was NOT sent
|
|
1544
|
+
expect(mockChat.addHistory).not.toHaveBeenCalledWith(expect.objectContaining({
|
|
1545
|
+
parts: expect.arrayContaining([
|
|
1546
|
+
expect.objectContaining({
|
|
1547
|
+
text: expect.stringContaining("user's editor context"),
|
|
1548
|
+
}),
|
|
1549
|
+
]),
|
|
1550
|
+
}));
|
|
1551
|
+
// --- Step 2: A new message is sent, latest context should be included ---
|
|
1552
|
+
// Arrange: The model has responded to the tool, and the user is sending a new message.
|
|
1553
|
+
const historyAfterToolResponse = [
|
|
1554
|
+
...historyWithPendingCall,
|
|
1555
|
+
{
|
|
1556
|
+
role: 'user',
|
|
1557
|
+
parts: [
|
|
1558
|
+
{
|
|
1559
|
+
functionResponse: {
|
|
1560
|
+
name: 'some_tool',
|
|
1561
|
+
response: { success: true },
|
|
1562
|
+
},
|
|
1563
|
+
},
|
|
1564
|
+
],
|
|
1565
|
+
},
|
|
1566
|
+
{ role: 'model', parts: [{ text: 'The tool ran successfully.' }] },
|
|
1567
|
+
];
|
|
1568
|
+
vi.mocked(mockChat.getHistory).mockReturnValue(historyAfterToolResponse);
|
|
1569
|
+
vi.mocked(mockChat.addHistory).mockClear(); // Clear previous calls for the next assertion
|
|
1570
|
+
// Arrange: The IDE context has now changed
|
|
1571
|
+
const newIdeContext = {
|
|
1572
|
+
workspaceState: {
|
|
1573
|
+
openFiles: [{ path: '/path/to/fileB.ts', timestamp: Date.now() }],
|
|
1574
|
+
},
|
|
1575
|
+
};
|
|
1576
|
+
vi.mocked(ideContextStore.get).mockReturnValue(newIdeContext);
|
|
1577
|
+
// Act: Send a new, regular user message
|
|
1578
|
+
stream = client.sendMessageStream([{ text: 'Thanks!' }], new AbortController().signal, 'prompt-id-final');
|
|
1579
|
+
for await (const _ of stream) {
|
|
1580
|
+
/* consume */
|
|
1581
|
+
}
|
|
1582
|
+
// Assert: The NEW context was sent as a FULL context because there was no previously sent context.
|
|
1583
|
+
const addHistoryCalls = vi.mocked(mockChat.addHistory).mock.calls;
|
|
1584
|
+
const contextCall = addHistoryCalls.find((call) => JSON.stringify(call[0]).includes("user's editor context"));
|
|
1585
|
+
expect(contextCall).toBeDefined();
|
|
1586
|
+
expect(JSON.stringify(contextCall[0])).toContain("Here is the user's editor context as a JSON object");
|
|
1587
|
+
// Check that the sent context is the new one (fileB.ts)
|
|
1588
|
+
expect(JSON.stringify(contextCall[0])).toContain('fileB.ts');
|
|
1589
|
+
// Check that the sent context is NOT the old one (fileA.ts)
|
|
1590
|
+
expect(JSON.stringify(contextCall[0])).not.toContain('fileA.ts');
|
|
1591
|
+
});
|
|
1592
|
+
it('should send a context DELTA on the next message after a skipped context', async () => {
|
|
1593
|
+
// --- Step 0: Establish an initial context ---
|
|
1594
|
+
vi.mocked(mockChat.getHistory).mockReturnValue([]); // Start with empty history
|
|
1595
|
+
const contextA = {
|
|
1596
|
+
workspaceState: {
|
|
1597
|
+
openFiles: [
|
|
1598
|
+
{
|
|
1599
|
+
path: '/path/to/fileA.ts',
|
|
1600
|
+
isActive: true,
|
|
1601
|
+
timestamp: Date.now(),
|
|
1602
|
+
},
|
|
1603
|
+
],
|
|
1604
|
+
},
|
|
1605
|
+
};
|
|
1606
|
+
vi.mocked(ideContextStore.get).mockReturnValue(contextA);
|
|
1607
|
+
// Act: Send a regular message to establish the initial context
|
|
1608
|
+
let stream = client.sendMessageStream([{ text: 'Initial message' }], new AbortController().signal, 'prompt-id-initial');
|
|
1609
|
+
for await (const _ of stream) {
|
|
1610
|
+
/* consume */
|
|
1611
|
+
}
|
|
1612
|
+
// Assert: Full context for fileA.ts was sent and stored.
|
|
1613
|
+
const initialCall = vi.mocked(mockChat.addHistory).mock.calls[0][0];
|
|
1614
|
+
expect(JSON.stringify(initialCall)).toContain("user's editor context as a JSON object");
|
|
1615
|
+
expect(JSON.stringify(initialCall)).toContain('fileA.ts');
|
|
1616
|
+
// This implicitly tests that `lastSentIdeContext` is now set internally by the client.
|
|
1617
|
+
vi.mocked(mockChat.addHistory).mockClear();
|
|
1618
|
+
// --- Step 1: A tool call is pending, context should be skipped ---
|
|
1619
|
+
const historyWithPendingCall = [
|
|
1620
|
+
{ role: 'user', parts: [{ text: 'Please use a tool.' }] },
|
|
1621
|
+
{
|
|
1622
|
+
role: 'model',
|
|
1623
|
+
parts: [{ functionCall: { name: 'some_tool', args: {} } }],
|
|
1624
|
+
},
|
|
1625
|
+
];
|
|
1626
|
+
vi.mocked(mockChat.getHistory).mockReturnValue(historyWithPendingCall);
|
|
1627
|
+
// Arrange: IDE context changes, but this should be skipped
|
|
1628
|
+
const contextB = {
|
|
1629
|
+
workspaceState: {
|
|
1630
|
+
openFiles: [
|
|
1631
|
+
{
|
|
1632
|
+
path: '/path/to/fileB.ts',
|
|
1633
|
+
isActive: true,
|
|
1634
|
+
timestamp: Date.now(),
|
|
1635
|
+
},
|
|
1636
|
+
],
|
|
1637
|
+
},
|
|
1638
|
+
};
|
|
1639
|
+
vi.mocked(ideContextStore.get).mockReturnValue(contextB);
|
|
1640
|
+
// Act: Send the tool response
|
|
1641
|
+
stream = client.sendMessageStream([
|
|
1642
|
+
{
|
|
1643
|
+
functionResponse: {
|
|
1644
|
+
name: 'some_tool',
|
|
1645
|
+
response: { success: true },
|
|
1646
|
+
},
|
|
1647
|
+
},
|
|
1648
|
+
], new AbortController().signal, 'prompt-id-tool-response');
|
|
1649
|
+
for await (const _ of stream) {
|
|
1650
|
+
/* consume */
|
|
1651
|
+
}
|
|
1652
|
+
// Assert: No context was sent
|
|
1653
|
+
expect(mockChat.addHistory).not.toHaveBeenCalled();
|
|
1654
|
+
// --- Step 2: A new message is sent, latest context DELTA should be included ---
|
|
1655
|
+
const historyAfterToolResponse = [
|
|
1656
|
+
...historyWithPendingCall,
|
|
1657
|
+
{
|
|
1658
|
+
role: 'user',
|
|
1659
|
+
parts: [
|
|
1660
|
+
{
|
|
1661
|
+
functionResponse: {
|
|
1662
|
+
name: 'some_tool',
|
|
1663
|
+
response: { success: true },
|
|
1664
|
+
},
|
|
1665
|
+
},
|
|
1666
|
+
],
|
|
1667
|
+
},
|
|
1668
|
+
{ role: 'model', parts: [{ text: 'The tool ran successfully.' }] },
|
|
1669
|
+
];
|
|
1670
|
+
vi.mocked(mockChat.getHistory).mockReturnValue(historyAfterToolResponse);
|
|
1671
|
+
// Arrange: The IDE context has changed again
|
|
1672
|
+
const contextC = {
|
|
1673
|
+
workspaceState: {
|
|
1674
|
+
openFiles: [
|
|
1675
|
+
// fileA is now closed, fileC is open
|
|
1676
|
+
{
|
|
1677
|
+
path: '/path/to/fileC.ts',
|
|
1678
|
+
isActive: true,
|
|
1679
|
+
timestamp: Date.now(),
|
|
1680
|
+
},
|
|
1681
|
+
],
|
|
1682
|
+
},
|
|
1683
|
+
};
|
|
1684
|
+
vi.mocked(ideContextStore.get).mockReturnValue(contextC);
|
|
1685
|
+
// Act: Send a new, regular user message
|
|
1686
|
+
stream = client.sendMessageStream([{ text: 'Thanks!' }], new AbortController().signal, 'prompt-id-final');
|
|
1687
|
+
for await (const _ of stream) {
|
|
1688
|
+
/* consume */
|
|
1689
|
+
}
|
|
1690
|
+
// Assert: The DELTA context was sent
|
|
1691
|
+
const finalCall = vi.mocked(mockChat.addHistory).mock.calls[0][0];
|
|
1692
|
+
expect(JSON.stringify(finalCall)).toContain('summary of changes');
|
|
1693
|
+
// The delta should reflect fileA being closed and fileC being opened.
|
|
1694
|
+
expect(JSON.stringify(finalCall)).toContain('filesClosed');
|
|
1695
|
+
expect(JSON.stringify(finalCall)).toContain('fileA.ts');
|
|
1696
|
+
expect(JSON.stringify(finalCall)).toContain('activeFileChanged');
|
|
1697
|
+
expect(JSON.stringify(finalCall)).toContain('fileC.ts');
|
|
1698
|
+
});
|
|
1699
|
+
});
|
|
1700
|
+
it('should not call checkNextSpeaker when turn.run() yields an error', async () => {
|
|
1701
|
+
// Arrange
|
|
1702
|
+
const { checkNextSpeaker } = await import('../utils/nextSpeakerChecker.js');
|
|
1703
|
+
const mockCheckNextSpeaker = vi.mocked(checkNextSpeaker);
|
|
1704
|
+
const mockStream = (async function* () {
|
|
1705
|
+
yield {
|
|
1706
|
+
type: GeminiEventType.Error,
|
|
1707
|
+
value: { error: { message: 'test error' } },
|
|
1708
|
+
};
|
|
1709
|
+
})();
|
|
1710
|
+
mockTurnRunFn.mockReturnValue(mockStream);
|
|
1711
|
+
const mockChat = {
|
|
1712
|
+
addHistory: vi.fn(),
|
|
1713
|
+
getHistory: vi.fn().mockReturnValue([]),
|
|
1714
|
+
};
|
|
1715
|
+
client['chat'] = mockChat;
|
|
1716
|
+
// Act
|
|
1717
|
+
const stream = client.sendMessageStream([{ text: 'Hi' }], new AbortController().signal, 'prompt-id-error');
|
|
1718
|
+
for await (const _ of stream) {
|
|
1719
|
+
// consume stream
|
|
1720
|
+
}
|
|
1721
|
+
// Assert
|
|
1722
|
+
expect(mockCheckNextSpeaker).not.toHaveBeenCalled();
|
|
1723
|
+
});
|
|
1724
|
+
it('should not call checkNextSpeaker when turn.run() yields a value then an error', async () => {
|
|
1725
|
+
// Arrange
|
|
1726
|
+
const { checkNextSpeaker } = await import('../utils/nextSpeakerChecker.js');
|
|
1727
|
+
const mockCheckNextSpeaker = vi.mocked(checkNextSpeaker);
|
|
1728
|
+
const mockStream = (async function* () {
|
|
1729
|
+
yield { type: GeminiEventType.Content, value: 'some content' };
|
|
1730
|
+
yield {
|
|
1731
|
+
type: GeminiEventType.Error,
|
|
1732
|
+
value: { error: { message: 'test error' } },
|
|
1733
|
+
};
|
|
1734
|
+
})();
|
|
1735
|
+
mockTurnRunFn.mockReturnValue(mockStream);
|
|
1736
|
+
const mockChat = {
|
|
1737
|
+
addHistory: vi.fn(),
|
|
1738
|
+
getHistory: vi.fn().mockReturnValue([]),
|
|
1739
|
+
};
|
|
1740
|
+
client['chat'] = mockChat;
|
|
1741
|
+
// Act
|
|
1742
|
+
const stream = client.sendMessageStream([{ text: 'Hi' }], new AbortController().signal, 'prompt-id-error');
|
|
1743
|
+
for await (const _ of stream) {
|
|
1744
|
+
// consume stream
|
|
1745
|
+
}
|
|
1746
|
+
// Assert
|
|
1747
|
+
expect(mockCheckNextSpeaker).not.toHaveBeenCalled();
|
|
1748
|
+
});
|
|
1749
|
+
it('does not run loop checks when skipLoopDetection is true', async () => {
|
|
1750
|
+
// Arrange
|
|
1751
|
+
// Ensure config returns true for skipLoopDetection
|
|
1752
|
+
vi.spyOn(client['config'], 'getSkipLoopDetection').mockReturnValue(true);
|
|
1753
|
+
// Replace loop detector with spies
|
|
1754
|
+
const ldMock = {
|
|
1755
|
+
turnStarted: vi.fn().mockResolvedValue(false),
|
|
1756
|
+
addAndCheck: vi.fn().mockReturnValue(false),
|
|
1757
|
+
reset: vi.fn(),
|
|
1758
|
+
};
|
|
1759
|
+
// @ts-expect-error override private for testing
|
|
1760
|
+
client['loopDetector'] = ldMock;
|
|
1761
|
+
const mockStream = (async function* () {
|
|
1762
|
+
yield { type: 'content', value: 'Hello' };
|
|
1763
|
+
yield { type: 'content', value: 'World' };
|
|
1764
|
+
})();
|
|
1765
|
+
mockTurnRunFn.mockReturnValue(mockStream);
|
|
1766
|
+
const mockChat = {
|
|
1767
|
+
addHistory: vi.fn(),
|
|
1768
|
+
getHistory: vi.fn().mockReturnValue([]),
|
|
1769
|
+
};
|
|
1770
|
+
client['chat'] = mockChat;
|
|
1771
|
+
// Act
|
|
1772
|
+
const stream = client.sendMessageStream([{ text: 'Hi' }], new AbortController().signal, 'prompt-id-skip-loop');
|
|
1773
|
+
for await (const _ of stream) {
|
|
1774
|
+
// consume stream
|
|
1775
|
+
}
|
|
1776
|
+
// Assert - loop detection methods should not be called when skipLoopDetection is true
|
|
1777
|
+
expect(ldMock.turnStarted).not.toHaveBeenCalled();
|
|
1778
|
+
expect(ldMock.addAndCheck).not.toHaveBeenCalled();
|
|
1779
|
+
});
|
|
1780
|
+
});
|
|
1781
|
+
describe('generateContent', () => {
|
|
1782
|
+
it('should call generateContent with the correct parameters', async () => {
|
|
1783
|
+
const contents = [{ role: 'user', parts: [{ text: 'hello' }] }];
|
|
1784
|
+
const generationConfig = { temperature: 0.5 };
|
|
1785
|
+
const abortSignal = new AbortController().signal;
|
|
1786
|
+
await client.generateContent(contents, generationConfig, abortSignal, DEFAULT_GEMINI_FLASH_MODEL);
|
|
1787
|
+
expect(mockContentGenerator.generateContent).toHaveBeenCalledWith({
|
|
1788
|
+
model: DEFAULT_GEMINI_FLASH_MODEL,
|
|
1789
|
+
config: {
|
|
1790
|
+
abortSignal,
|
|
1791
|
+
systemInstruction: getCoreSystemPrompt(''),
|
|
1792
|
+
temperature: 0.5,
|
|
1793
|
+
topP: 1,
|
|
1794
|
+
},
|
|
1795
|
+
contents,
|
|
1796
|
+
}, 'test-session-id');
|
|
1797
|
+
});
|
|
1798
|
+
it('should use current model from config for content generation', async () => {
|
|
1799
|
+
const initialModel = client['config'].getModel();
|
|
1800
|
+
const contents = [{ role: 'user', parts: [{ text: 'test' }] }];
|
|
1801
|
+
const currentModel = initialModel + '-changed';
|
|
1802
|
+
vi.spyOn(client['config'], 'getModel').mockReturnValueOnce(currentModel);
|
|
1803
|
+
await client.generateContent(contents, {}, new AbortController().signal, DEFAULT_GEMINI_FLASH_MODEL);
|
|
1804
|
+
expect(mockContentGenerator.generateContent).not.toHaveBeenCalledWith({
|
|
1805
|
+
model: initialModel,
|
|
1806
|
+
config: expect.any(Object),
|
|
1807
|
+
contents,
|
|
1808
|
+
});
|
|
1809
|
+
expect(mockContentGenerator.generateContent).toHaveBeenCalledWith({
|
|
1810
|
+
model: DEFAULT_GEMINI_FLASH_MODEL,
|
|
1811
|
+
config: expect.any(Object),
|
|
1812
|
+
contents,
|
|
1813
|
+
}, 'test-session-id');
|
|
1814
|
+
});
|
|
1815
|
+
it('should use the Flash model when fallback mode is active', async () => {
|
|
1816
|
+
const contents = [{ role: 'user', parts: [{ text: 'hello' }] }];
|
|
1817
|
+
const generationConfig = { temperature: 0.5 };
|
|
1818
|
+
const abortSignal = new AbortController().signal;
|
|
1819
|
+
const requestedModel = 'gemini-2.5-pro'; // A non-flash model
|
|
1820
|
+
// Mock config to be in fallback mode
|
|
1821
|
+
vi.spyOn(client['config'], 'isInFallbackMode').mockReturnValue(true);
|
|
1822
|
+
await client.generateContent(contents, generationConfig, abortSignal, requestedModel);
|
|
1823
|
+
expect(mockGenerateContentFn).toHaveBeenCalledWith(expect.objectContaining({
|
|
1824
|
+
model: DEFAULT_GEMINI_FLASH_MODEL,
|
|
1825
|
+
}), 'test-session-id');
|
|
1826
|
+
});
|
|
1827
|
+
});
|
|
1828
|
+
});
|
|
1829
|
+
//# sourceMappingURL=client.test.js.map
|