@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,1149 @@
|
|
|
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 { ApiError } from '@google/genai';
|
|
8
|
+
import { GeminiChat, InvalidStreamError, StreamEventType, } from './geminiChat.js';
|
|
9
|
+
import { setSimulate429 } from '../utils/testUtils.js';
|
|
10
|
+
import { DEFAULT_GEMINI_FLASH_MODEL } from '../config/models.js';
|
|
11
|
+
import { AuthType } from './contentGenerator.js';
|
|
12
|
+
import {} from '../utils/retry.js';
|
|
13
|
+
import { uiTelemetryService } from '../telemetry/uiTelemetry.js';
|
|
14
|
+
// Mock fs module to prevent actual file system operations during tests
|
|
15
|
+
const mockFileSystem = new Map();
|
|
16
|
+
vi.mock('node:fs', () => {
|
|
17
|
+
const fsModule = {
|
|
18
|
+
mkdirSync: vi.fn(),
|
|
19
|
+
writeFileSync: vi.fn((path, data) => {
|
|
20
|
+
mockFileSystem.set(path, data);
|
|
21
|
+
}),
|
|
22
|
+
readFileSync: vi.fn((path) => {
|
|
23
|
+
if (mockFileSystem.has(path)) {
|
|
24
|
+
return mockFileSystem.get(path);
|
|
25
|
+
}
|
|
26
|
+
throw Object.assign(new Error('ENOENT: no such file or directory'), {
|
|
27
|
+
code: 'ENOENT',
|
|
28
|
+
});
|
|
29
|
+
}),
|
|
30
|
+
existsSync: vi.fn((path) => mockFileSystem.has(path)),
|
|
31
|
+
};
|
|
32
|
+
return {
|
|
33
|
+
default: fsModule,
|
|
34
|
+
...fsModule,
|
|
35
|
+
};
|
|
36
|
+
});
|
|
37
|
+
const { mockHandleFallback } = vi.hoisted(() => ({
|
|
38
|
+
mockHandleFallback: vi.fn(),
|
|
39
|
+
}));
|
|
40
|
+
// Add mock for the retry utility
|
|
41
|
+
const { mockRetryWithBackoff } = vi.hoisted(() => ({
|
|
42
|
+
mockRetryWithBackoff: vi.fn(),
|
|
43
|
+
}));
|
|
44
|
+
vi.mock('../utils/retry.js', () => ({
|
|
45
|
+
retryWithBackoff: mockRetryWithBackoff,
|
|
46
|
+
}));
|
|
47
|
+
vi.mock('../fallback/handler.js', () => ({
|
|
48
|
+
handleFallback: mockHandleFallback,
|
|
49
|
+
}));
|
|
50
|
+
const { mockLogContentRetry, mockLogContentRetryFailure } = vi.hoisted(() => ({
|
|
51
|
+
mockLogContentRetry: vi.fn(),
|
|
52
|
+
mockLogContentRetryFailure: vi.fn(),
|
|
53
|
+
}));
|
|
54
|
+
vi.mock('../telemetry/loggers.js', () => ({
|
|
55
|
+
logContentRetry: mockLogContentRetry,
|
|
56
|
+
logContentRetryFailure: mockLogContentRetryFailure,
|
|
57
|
+
}));
|
|
58
|
+
vi.mock('../telemetry/uiTelemetry.js', () => ({
|
|
59
|
+
uiTelemetryService: {
|
|
60
|
+
setLastPromptTokenCount: vi.fn(),
|
|
61
|
+
},
|
|
62
|
+
}));
|
|
63
|
+
describe('GeminiChat', () => {
|
|
64
|
+
let mockContentGenerator;
|
|
65
|
+
let chat;
|
|
66
|
+
let mockConfig;
|
|
67
|
+
const config = {};
|
|
68
|
+
beforeEach(() => {
|
|
69
|
+
vi.clearAllMocks();
|
|
70
|
+
vi.mocked(uiTelemetryService.setLastPromptTokenCount).mockClear();
|
|
71
|
+
mockContentGenerator = {
|
|
72
|
+
generateContent: vi.fn(),
|
|
73
|
+
generateContentStream: vi.fn(),
|
|
74
|
+
countTokens: vi.fn(),
|
|
75
|
+
embedContent: vi.fn(),
|
|
76
|
+
batchEmbedContents: vi.fn(),
|
|
77
|
+
};
|
|
78
|
+
mockHandleFallback.mockClear();
|
|
79
|
+
// Default mock implementation for tests that don't care about retry logic
|
|
80
|
+
mockRetryWithBackoff.mockImplementation(async (apiCall) => apiCall());
|
|
81
|
+
mockConfig = {
|
|
82
|
+
getSessionId: () => 'test-session-id',
|
|
83
|
+
getTelemetryLogPromptsEnabled: () => true,
|
|
84
|
+
getUsageStatisticsEnabled: () => true,
|
|
85
|
+
getDebugMode: () => false,
|
|
86
|
+
getContentGeneratorConfig: vi.fn().mockReturnValue({
|
|
87
|
+
authType: 'oauth-personal', // Ensure this is set for fallback tests
|
|
88
|
+
model: 'test-model',
|
|
89
|
+
}),
|
|
90
|
+
getModel: vi.fn().mockReturnValue('gemini-pro'),
|
|
91
|
+
setModel: vi.fn(),
|
|
92
|
+
isInFallbackMode: vi.fn().mockReturnValue(false),
|
|
93
|
+
getQuotaErrorOccurred: vi.fn().mockReturnValue(false),
|
|
94
|
+
setQuotaErrorOccurred: vi.fn(),
|
|
95
|
+
flashFallbackHandler: undefined,
|
|
96
|
+
getProjectRoot: vi.fn().mockReturnValue('/test/project/root'),
|
|
97
|
+
storage: {
|
|
98
|
+
getProjectTempDir: vi.fn().mockReturnValue('/test/temp'),
|
|
99
|
+
},
|
|
100
|
+
getToolRegistry: vi.fn().mockReturnValue({
|
|
101
|
+
getTool: vi.fn(),
|
|
102
|
+
}),
|
|
103
|
+
getContentGenerator: vi.fn().mockReturnValue(mockContentGenerator),
|
|
104
|
+
};
|
|
105
|
+
// Disable 429 simulation for tests
|
|
106
|
+
setSimulate429(false);
|
|
107
|
+
// Reset history for each test by creating a new instance
|
|
108
|
+
chat = new GeminiChat(mockConfig, config, []);
|
|
109
|
+
});
|
|
110
|
+
afterEach(() => {
|
|
111
|
+
vi.restoreAllMocks();
|
|
112
|
+
vi.resetAllMocks();
|
|
113
|
+
});
|
|
114
|
+
describe('sendMessageStream', () => {
|
|
115
|
+
it('should succeed if a tool call is followed by an empty part', async () => {
|
|
116
|
+
// 1. Mock a stream that contains a tool call, then an invalid (empty) part.
|
|
117
|
+
const streamWithToolCall = (async function* () {
|
|
118
|
+
yield {
|
|
119
|
+
candidates: [
|
|
120
|
+
{
|
|
121
|
+
content: {
|
|
122
|
+
role: 'model',
|
|
123
|
+
parts: [{ functionCall: { name: 'test_tool', args: {} } }],
|
|
124
|
+
},
|
|
125
|
+
},
|
|
126
|
+
],
|
|
127
|
+
};
|
|
128
|
+
// This second chunk is invalid according to isValidResponse
|
|
129
|
+
yield {
|
|
130
|
+
candidates: [
|
|
131
|
+
{
|
|
132
|
+
content: {
|
|
133
|
+
role: 'model',
|
|
134
|
+
parts: [{ text: '' }],
|
|
135
|
+
},
|
|
136
|
+
},
|
|
137
|
+
],
|
|
138
|
+
};
|
|
139
|
+
})();
|
|
140
|
+
vi.mocked(mockContentGenerator.generateContentStream).mockResolvedValue(streamWithToolCall);
|
|
141
|
+
// 2. Action & Assert: The stream processing should complete without throwing an error
|
|
142
|
+
// because the presence of a tool call makes the empty final chunk acceptable.
|
|
143
|
+
const stream = await chat.sendMessageStream('test-model', { message: 'test message' }, 'prompt-id-tool-call-empty-end');
|
|
144
|
+
await expect((async () => {
|
|
145
|
+
for await (const _ of stream) {
|
|
146
|
+
/* consume stream */
|
|
147
|
+
}
|
|
148
|
+
})()).resolves.not.toThrow();
|
|
149
|
+
// 3. Verify history was recorded correctly
|
|
150
|
+
const history = chat.getHistory();
|
|
151
|
+
expect(history.length).toBe(2); // user turn + model turn
|
|
152
|
+
const modelTurn = history[1];
|
|
153
|
+
expect(modelTurn?.parts?.length).toBe(1); // The empty part is discarded
|
|
154
|
+
expect(modelTurn?.parts[0].functionCall).toBeDefined();
|
|
155
|
+
});
|
|
156
|
+
it('should fail if the stream ends with an empty part and has no finishReason', async () => {
|
|
157
|
+
// 1. Mock a stream that ends with an invalid part and has no finish reason.
|
|
158
|
+
const streamWithNoFinish = (async function* () {
|
|
159
|
+
yield {
|
|
160
|
+
candidates: [
|
|
161
|
+
{
|
|
162
|
+
content: {
|
|
163
|
+
role: 'model',
|
|
164
|
+
parts: [{ text: 'Initial content...' }],
|
|
165
|
+
},
|
|
166
|
+
},
|
|
167
|
+
],
|
|
168
|
+
};
|
|
169
|
+
// This second chunk is invalid and has no finishReason, so it should fail.
|
|
170
|
+
yield {
|
|
171
|
+
candidates: [
|
|
172
|
+
{
|
|
173
|
+
content: {
|
|
174
|
+
role: 'model',
|
|
175
|
+
parts: [{ text: '' }],
|
|
176
|
+
},
|
|
177
|
+
},
|
|
178
|
+
],
|
|
179
|
+
};
|
|
180
|
+
})();
|
|
181
|
+
vi.mocked(mockContentGenerator.generateContentStream).mockResolvedValue(streamWithNoFinish);
|
|
182
|
+
// 2. Action & Assert: The stream should fail because there's no finish reason.
|
|
183
|
+
const stream = await chat.sendMessageStream('test-model', { message: 'test message' }, 'prompt-id-no-finish-empty-end');
|
|
184
|
+
await expect((async () => {
|
|
185
|
+
for await (const _ of stream) {
|
|
186
|
+
/* consume stream */
|
|
187
|
+
}
|
|
188
|
+
})()).rejects.toThrow(InvalidStreamError);
|
|
189
|
+
});
|
|
190
|
+
it('should succeed if the stream ends with an invalid part but has a finishReason and contained a valid part', async () => {
|
|
191
|
+
// 1. Mock a stream that sends a valid chunk, then an invalid one, but has a finish reason.
|
|
192
|
+
const streamWithInvalidEnd = (async function* () {
|
|
193
|
+
yield {
|
|
194
|
+
candidates: [
|
|
195
|
+
{
|
|
196
|
+
content: {
|
|
197
|
+
role: 'model',
|
|
198
|
+
parts: [{ text: 'Initial valid content...' }],
|
|
199
|
+
},
|
|
200
|
+
},
|
|
201
|
+
],
|
|
202
|
+
};
|
|
203
|
+
// This second chunk is invalid, but the response has a finishReason.
|
|
204
|
+
yield {
|
|
205
|
+
candidates: [
|
|
206
|
+
{
|
|
207
|
+
content: {
|
|
208
|
+
role: 'model',
|
|
209
|
+
parts: [{ text: '' }], // Invalid part
|
|
210
|
+
},
|
|
211
|
+
finishReason: 'STOP',
|
|
212
|
+
},
|
|
213
|
+
],
|
|
214
|
+
};
|
|
215
|
+
})();
|
|
216
|
+
vi.mocked(mockContentGenerator.generateContentStream).mockResolvedValue(streamWithInvalidEnd);
|
|
217
|
+
// 2. Action & Assert: The stream should complete without throwing an error.
|
|
218
|
+
const stream = await chat.sendMessageStream('test-model', { message: 'test message' }, 'prompt-id-valid-then-invalid-end');
|
|
219
|
+
await expect((async () => {
|
|
220
|
+
for await (const _ of stream) {
|
|
221
|
+
/* consume stream */
|
|
222
|
+
}
|
|
223
|
+
})()).resolves.not.toThrow();
|
|
224
|
+
// 3. Verify history was recorded correctly with only the valid part.
|
|
225
|
+
const history = chat.getHistory();
|
|
226
|
+
expect(history.length).toBe(2); // user turn + model turn
|
|
227
|
+
const modelTurn = history[1];
|
|
228
|
+
expect(modelTurn?.parts?.length).toBe(1);
|
|
229
|
+
expect(modelTurn?.parts[0].text).toBe('Initial valid content...');
|
|
230
|
+
});
|
|
231
|
+
it('should consolidate subsequent text chunks after receiving an empty text chunk', async () => {
|
|
232
|
+
// 1. Mock the API to return a stream where one chunk is just an empty text part.
|
|
233
|
+
const multiChunkStream = (async function* () {
|
|
234
|
+
yield {
|
|
235
|
+
candidates: [
|
|
236
|
+
{ content: { role: 'model', parts: [{ text: 'Hello' }] } },
|
|
237
|
+
],
|
|
238
|
+
};
|
|
239
|
+
// FIX: The original test used { text: '' }, which is invalid.
|
|
240
|
+
// A chunk can be empty but still valid. This chunk is now removed
|
|
241
|
+
// as the important part is consolidating what comes after.
|
|
242
|
+
yield {
|
|
243
|
+
candidates: [
|
|
244
|
+
{
|
|
245
|
+
content: { role: 'model', parts: [{ text: ' World!' }] },
|
|
246
|
+
finishReason: 'STOP',
|
|
247
|
+
},
|
|
248
|
+
],
|
|
249
|
+
};
|
|
250
|
+
})();
|
|
251
|
+
vi.mocked(mockContentGenerator.generateContentStream).mockResolvedValue(multiChunkStream);
|
|
252
|
+
// 2. Action: Send a message and consume the stream.
|
|
253
|
+
const stream = await chat.sendMessageStream('test-model', { message: 'test message' }, 'prompt-id-empty-chunk-consolidation');
|
|
254
|
+
for await (const _ of stream) {
|
|
255
|
+
// Consume the stream
|
|
256
|
+
}
|
|
257
|
+
// 3. Assert: Check that the final history was correctly consolidated.
|
|
258
|
+
const history = chat.getHistory();
|
|
259
|
+
expect(history.length).toBe(2);
|
|
260
|
+
const modelTurn = history[1];
|
|
261
|
+
expect(modelTurn?.parts?.length).toBe(1);
|
|
262
|
+
expect(modelTurn?.parts[0].text).toBe('Hello World!');
|
|
263
|
+
});
|
|
264
|
+
it('should consolidate adjacent text parts that arrive in separate stream chunks', async () => {
|
|
265
|
+
// 1. Mock the API to return a stream of multiple, adjacent text chunks.
|
|
266
|
+
const multiChunkStream = (async function* () {
|
|
267
|
+
yield {
|
|
268
|
+
candidates: [
|
|
269
|
+
{ content: { role: 'model', parts: [{ text: 'This is the ' }] } },
|
|
270
|
+
],
|
|
271
|
+
};
|
|
272
|
+
yield {
|
|
273
|
+
candidates: [
|
|
274
|
+
{ content: { role: 'model', parts: [{ text: 'first part.' }] } },
|
|
275
|
+
],
|
|
276
|
+
};
|
|
277
|
+
// This function call should break the consolidation.
|
|
278
|
+
yield {
|
|
279
|
+
candidates: [
|
|
280
|
+
{
|
|
281
|
+
content: {
|
|
282
|
+
role: 'model',
|
|
283
|
+
parts: [{ functionCall: { name: 'do_stuff', args: {} } }],
|
|
284
|
+
},
|
|
285
|
+
},
|
|
286
|
+
],
|
|
287
|
+
};
|
|
288
|
+
yield {
|
|
289
|
+
candidates: [
|
|
290
|
+
{
|
|
291
|
+
content: {
|
|
292
|
+
role: 'model',
|
|
293
|
+
parts: [{ text: 'This is the second part.' }],
|
|
294
|
+
},
|
|
295
|
+
},
|
|
296
|
+
],
|
|
297
|
+
};
|
|
298
|
+
})();
|
|
299
|
+
vi.mocked(mockContentGenerator.generateContentStream).mockResolvedValue(multiChunkStream);
|
|
300
|
+
// 2. Action: Send a message and consume the stream.
|
|
301
|
+
const stream = await chat.sendMessageStream('test-model', { message: 'test message' }, 'prompt-id-multi-chunk');
|
|
302
|
+
for await (const _ of stream) {
|
|
303
|
+
// Consume the stream to trigger history recording.
|
|
304
|
+
}
|
|
305
|
+
// 3. Assert: Check that the final history was correctly consolidated.
|
|
306
|
+
const history = chat.getHistory();
|
|
307
|
+
// The history should contain the user's turn and ONE consolidated model turn.
|
|
308
|
+
expect(history.length).toBe(2);
|
|
309
|
+
const modelTurn = history[1];
|
|
310
|
+
expect(modelTurn.role).toBe('model');
|
|
311
|
+
// The model turn should have 3 distinct parts: the merged text, the function call, and the final text.
|
|
312
|
+
expect(modelTurn?.parts?.length).toBe(3);
|
|
313
|
+
expect(modelTurn?.parts[0].text).toBe('This is the first part.');
|
|
314
|
+
expect(modelTurn.parts[1].functionCall).toBeDefined();
|
|
315
|
+
expect(modelTurn.parts[2].text).toBe('This is the second part.');
|
|
316
|
+
});
|
|
317
|
+
it('should preserve text parts that stream in the same chunk as a thought', async () => {
|
|
318
|
+
// 1. Mock the API to return a single chunk containing both a thought and visible text.
|
|
319
|
+
const mixedContentStream = (async function* () {
|
|
320
|
+
yield {
|
|
321
|
+
candidates: [
|
|
322
|
+
{
|
|
323
|
+
content: {
|
|
324
|
+
role: 'model',
|
|
325
|
+
parts: [
|
|
326
|
+
{ thought: 'This is a thought.' },
|
|
327
|
+
{ text: 'This is the visible text that should not be lost.' },
|
|
328
|
+
],
|
|
329
|
+
},
|
|
330
|
+
finishReason: 'STOP',
|
|
331
|
+
},
|
|
332
|
+
],
|
|
333
|
+
};
|
|
334
|
+
})();
|
|
335
|
+
vi.mocked(mockContentGenerator.generateContentStream).mockResolvedValue(mixedContentStream);
|
|
336
|
+
// 2. Action: Send a message and fully consume the stream to trigger history recording.
|
|
337
|
+
const stream = await chat.sendMessageStream('test-model', { message: 'test message' }, 'prompt-id-mixed-chunk');
|
|
338
|
+
for await (const _ of stream) {
|
|
339
|
+
// This loop consumes the stream.
|
|
340
|
+
}
|
|
341
|
+
// 3. Assert: Check the final state of the history.
|
|
342
|
+
const history = chat.getHistory();
|
|
343
|
+
// The history should contain two turns: the user's message and the model's response.
|
|
344
|
+
expect(history.length).toBe(2);
|
|
345
|
+
const modelTurn = history[1];
|
|
346
|
+
expect(modelTurn.role).toBe('model');
|
|
347
|
+
// CRUCIAL ASSERTION:
|
|
348
|
+
// The buggy code would fail here, resulting in parts.length being 0.
|
|
349
|
+
// The corrected code will pass, preserving the single visible text part.
|
|
350
|
+
expect(modelTurn?.parts?.length).toBe(1);
|
|
351
|
+
expect(modelTurn?.parts[0].text).toBe('This is the visible text that should not be lost.');
|
|
352
|
+
});
|
|
353
|
+
it('should throw an error when a tool call is followed by an empty stream response', async () => {
|
|
354
|
+
// 1. Setup: A history where the model has just made a function call.
|
|
355
|
+
const initialHistory = [
|
|
356
|
+
{
|
|
357
|
+
role: 'user',
|
|
358
|
+
parts: [{ text: 'Find a good Italian restaurant for me.' }],
|
|
359
|
+
},
|
|
360
|
+
{
|
|
361
|
+
role: 'model',
|
|
362
|
+
parts: [
|
|
363
|
+
{
|
|
364
|
+
functionCall: {
|
|
365
|
+
name: 'find_restaurant',
|
|
366
|
+
args: { cuisine: 'Italian' },
|
|
367
|
+
},
|
|
368
|
+
},
|
|
369
|
+
],
|
|
370
|
+
},
|
|
371
|
+
];
|
|
372
|
+
chat.setHistory(initialHistory);
|
|
373
|
+
// 2. Mock the API to return an empty/thought-only stream.
|
|
374
|
+
const emptyStreamResponse = (async function* () {
|
|
375
|
+
yield {
|
|
376
|
+
candidates: [
|
|
377
|
+
{
|
|
378
|
+
content: { role: 'model', parts: [{ thought: true }] },
|
|
379
|
+
finishReason: 'STOP',
|
|
380
|
+
},
|
|
381
|
+
],
|
|
382
|
+
};
|
|
383
|
+
})();
|
|
384
|
+
vi.mocked(mockContentGenerator.generateContentStream).mockResolvedValue(emptyStreamResponse);
|
|
385
|
+
// 3. Action: Send the function response back to the model and consume the stream.
|
|
386
|
+
const stream = await chat.sendMessageStream('test-model', {
|
|
387
|
+
message: {
|
|
388
|
+
functionResponse: {
|
|
389
|
+
name: 'find_restaurant',
|
|
390
|
+
response: { name: 'Vesuvio' },
|
|
391
|
+
},
|
|
392
|
+
},
|
|
393
|
+
}, 'prompt-id-stream-1');
|
|
394
|
+
// 4. Assert: The stream processing should throw an InvalidStreamError.
|
|
395
|
+
await expect((async () => {
|
|
396
|
+
for await (const _ of stream) {
|
|
397
|
+
// This loop consumes the stream to trigger the internal logic.
|
|
398
|
+
}
|
|
399
|
+
})()).rejects.toThrow(InvalidStreamError);
|
|
400
|
+
});
|
|
401
|
+
it('should succeed when there is a tool call without finish reason', async () => {
|
|
402
|
+
// Setup: Stream with tool call but no finish reason
|
|
403
|
+
const streamWithToolCall = (async function* () {
|
|
404
|
+
yield {
|
|
405
|
+
candidates: [
|
|
406
|
+
{
|
|
407
|
+
content: {
|
|
408
|
+
role: 'model',
|
|
409
|
+
parts: [
|
|
410
|
+
{
|
|
411
|
+
functionCall: {
|
|
412
|
+
name: 'test_function',
|
|
413
|
+
args: { param: 'value' },
|
|
414
|
+
},
|
|
415
|
+
},
|
|
416
|
+
],
|
|
417
|
+
},
|
|
418
|
+
// No finishReason
|
|
419
|
+
},
|
|
420
|
+
],
|
|
421
|
+
};
|
|
422
|
+
})();
|
|
423
|
+
vi.mocked(mockContentGenerator.generateContentStream).mockResolvedValue(streamWithToolCall);
|
|
424
|
+
const stream = await chat.sendMessageStream('test-model', { message: 'test' }, 'prompt-id-1');
|
|
425
|
+
// Should not throw an error
|
|
426
|
+
await expect((async () => {
|
|
427
|
+
for await (const _ of stream) {
|
|
428
|
+
// consume stream
|
|
429
|
+
}
|
|
430
|
+
})()).resolves.not.toThrow();
|
|
431
|
+
});
|
|
432
|
+
it('should throw InvalidStreamError when no tool call and no finish reason', async () => {
|
|
433
|
+
// Setup: Stream with text but no finish reason and no tool call
|
|
434
|
+
const streamWithoutFinishReason = (async function* () {
|
|
435
|
+
yield {
|
|
436
|
+
candidates: [
|
|
437
|
+
{
|
|
438
|
+
content: {
|
|
439
|
+
role: 'model',
|
|
440
|
+
parts: [{ text: 'some response' }],
|
|
441
|
+
},
|
|
442
|
+
// No finishReason
|
|
443
|
+
},
|
|
444
|
+
],
|
|
445
|
+
};
|
|
446
|
+
})();
|
|
447
|
+
vi.mocked(mockContentGenerator.generateContentStream).mockResolvedValue(streamWithoutFinishReason);
|
|
448
|
+
const stream = await chat.sendMessageStream('test-model', { message: 'test' }, 'prompt-id-1');
|
|
449
|
+
await expect((async () => {
|
|
450
|
+
for await (const _ of stream) {
|
|
451
|
+
// consume stream
|
|
452
|
+
}
|
|
453
|
+
})()).rejects.toThrow(InvalidStreamError);
|
|
454
|
+
});
|
|
455
|
+
it('should throw InvalidStreamError when no tool call and empty response text', async () => {
|
|
456
|
+
// Setup: Stream with finish reason but empty response (only thoughts)
|
|
457
|
+
const streamWithEmptyResponse = (async function* () {
|
|
458
|
+
yield {
|
|
459
|
+
candidates: [
|
|
460
|
+
{
|
|
461
|
+
content: {
|
|
462
|
+
role: 'model',
|
|
463
|
+
parts: [{ thought: 'thinking...' }],
|
|
464
|
+
},
|
|
465
|
+
finishReason: 'STOP',
|
|
466
|
+
},
|
|
467
|
+
],
|
|
468
|
+
};
|
|
469
|
+
})();
|
|
470
|
+
vi.mocked(mockContentGenerator.generateContentStream).mockResolvedValue(streamWithEmptyResponse);
|
|
471
|
+
const stream = await chat.sendMessageStream('test-model', { message: 'test' }, 'prompt-id-1');
|
|
472
|
+
await expect((async () => {
|
|
473
|
+
for await (const _ of stream) {
|
|
474
|
+
// consume stream
|
|
475
|
+
}
|
|
476
|
+
})()).rejects.toThrow(InvalidStreamError);
|
|
477
|
+
});
|
|
478
|
+
it('should succeed when there is finish reason and response text', async () => {
|
|
479
|
+
// Setup: Stream with both finish reason and text content
|
|
480
|
+
const validStream = (async function* () {
|
|
481
|
+
yield {
|
|
482
|
+
candidates: [
|
|
483
|
+
{
|
|
484
|
+
content: {
|
|
485
|
+
role: 'model',
|
|
486
|
+
parts: [{ text: 'valid response' }],
|
|
487
|
+
},
|
|
488
|
+
finishReason: 'STOP',
|
|
489
|
+
},
|
|
490
|
+
],
|
|
491
|
+
};
|
|
492
|
+
})();
|
|
493
|
+
vi.mocked(mockContentGenerator.generateContentStream).mockResolvedValue(validStream);
|
|
494
|
+
const stream = await chat.sendMessageStream('test-model', { message: 'test' }, 'prompt-id-1');
|
|
495
|
+
// Should not throw an error
|
|
496
|
+
await expect((async () => {
|
|
497
|
+
for await (const _ of stream) {
|
|
498
|
+
// consume stream
|
|
499
|
+
}
|
|
500
|
+
})()).resolves.not.toThrow();
|
|
501
|
+
});
|
|
502
|
+
it('should call generateContentStream with the correct parameters', async () => {
|
|
503
|
+
const response = (async function* () {
|
|
504
|
+
yield {
|
|
505
|
+
candidates: [
|
|
506
|
+
{
|
|
507
|
+
content: {
|
|
508
|
+
parts: [{ text: 'response' }],
|
|
509
|
+
role: 'model',
|
|
510
|
+
},
|
|
511
|
+
finishReason: 'STOP',
|
|
512
|
+
index: 0,
|
|
513
|
+
safetyRatings: [],
|
|
514
|
+
},
|
|
515
|
+
],
|
|
516
|
+
text: () => 'response',
|
|
517
|
+
usageMetadata: {
|
|
518
|
+
promptTokenCount: 42,
|
|
519
|
+
candidatesTokenCount: 15,
|
|
520
|
+
totalTokenCount: 57,
|
|
521
|
+
},
|
|
522
|
+
};
|
|
523
|
+
})();
|
|
524
|
+
vi.mocked(mockContentGenerator.generateContentStream).mockResolvedValue(response);
|
|
525
|
+
const stream = await chat.sendMessageStream('test-model', { message: 'hello' }, 'prompt-id-1');
|
|
526
|
+
for await (const _ of stream) {
|
|
527
|
+
// consume stream
|
|
528
|
+
}
|
|
529
|
+
expect(mockContentGenerator.generateContentStream).toHaveBeenCalledWith({
|
|
530
|
+
model: 'test-model',
|
|
531
|
+
contents: [
|
|
532
|
+
{
|
|
533
|
+
role: 'user',
|
|
534
|
+
parts: [{ text: 'hello' }],
|
|
535
|
+
},
|
|
536
|
+
],
|
|
537
|
+
config: {},
|
|
538
|
+
}, 'prompt-id-1');
|
|
539
|
+
// Verify that token counting is called when usageMetadata is present
|
|
540
|
+
expect(uiTelemetryService.setLastPromptTokenCount).toHaveBeenCalledWith(42);
|
|
541
|
+
expect(uiTelemetryService.setLastPromptTokenCount).toHaveBeenCalledTimes(1);
|
|
542
|
+
});
|
|
543
|
+
});
|
|
544
|
+
describe('addHistory', () => {
|
|
545
|
+
it('should add a new content item to the history', () => {
|
|
546
|
+
const newContent = {
|
|
547
|
+
role: 'user',
|
|
548
|
+
parts: [{ text: 'A new message' }],
|
|
549
|
+
};
|
|
550
|
+
chat.addHistory(newContent);
|
|
551
|
+
const history = chat.getHistory();
|
|
552
|
+
expect(history.length).toBe(1);
|
|
553
|
+
expect(history[0]).toEqual(newContent);
|
|
554
|
+
});
|
|
555
|
+
it('should add multiple items correctly', () => {
|
|
556
|
+
const content1 = {
|
|
557
|
+
role: 'user',
|
|
558
|
+
parts: [{ text: 'Message 1' }],
|
|
559
|
+
};
|
|
560
|
+
const content2 = {
|
|
561
|
+
role: 'model',
|
|
562
|
+
parts: [{ text: 'Message 2' }],
|
|
563
|
+
};
|
|
564
|
+
chat.addHistory(content1);
|
|
565
|
+
chat.addHistory(content2);
|
|
566
|
+
const history = chat.getHistory();
|
|
567
|
+
expect(history.length).toBe(2);
|
|
568
|
+
expect(history[0]).toEqual(content1);
|
|
569
|
+
expect(history[1]).toEqual(content2);
|
|
570
|
+
});
|
|
571
|
+
});
|
|
572
|
+
describe('sendMessageStream with retries', () => {
|
|
573
|
+
it('should yield a RETRY event when an invalid stream is encountered', async () => {
|
|
574
|
+
// ARRANGE: Mock the stream to fail once, then succeed.
|
|
575
|
+
vi.mocked(mockContentGenerator.generateContentStream)
|
|
576
|
+
.mockImplementationOnce(async () =>
|
|
577
|
+
// First attempt: An invalid stream with an empty text part.
|
|
578
|
+
(async function* () {
|
|
579
|
+
yield {
|
|
580
|
+
candidates: [{ content: { parts: [{ text: '' }] } }],
|
|
581
|
+
};
|
|
582
|
+
})())
|
|
583
|
+
.mockImplementationOnce(async () =>
|
|
584
|
+
// Second attempt (the retry): A minimal valid stream.
|
|
585
|
+
(async function* () {
|
|
586
|
+
yield {
|
|
587
|
+
candidates: [
|
|
588
|
+
{
|
|
589
|
+
content: { parts: [{ text: 'Success' }] },
|
|
590
|
+
finishReason: 'STOP',
|
|
591
|
+
},
|
|
592
|
+
],
|
|
593
|
+
};
|
|
594
|
+
})());
|
|
595
|
+
// ACT: Send a message and collect all events from the stream.
|
|
596
|
+
const stream = await chat.sendMessageStream('test-model', { message: 'test' }, 'prompt-id-yield-retry');
|
|
597
|
+
const events = [];
|
|
598
|
+
for await (const event of stream) {
|
|
599
|
+
events.push(event);
|
|
600
|
+
}
|
|
601
|
+
// ASSERT: Check that a RETRY event was present in the stream's output.
|
|
602
|
+
const retryEvent = events.find((e) => e.type === StreamEventType.RETRY);
|
|
603
|
+
expect(retryEvent).toBeDefined();
|
|
604
|
+
expect(retryEvent?.type).toBe(StreamEventType.RETRY);
|
|
605
|
+
});
|
|
606
|
+
it('should retry on invalid content, succeed, and report metrics', async () => {
|
|
607
|
+
// Use mockImplementationOnce to provide a fresh, promise-wrapped generator for each attempt.
|
|
608
|
+
vi.mocked(mockContentGenerator.generateContentStream)
|
|
609
|
+
.mockImplementationOnce(async () =>
|
|
610
|
+
// First call returns an invalid stream
|
|
611
|
+
(async function* () {
|
|
612
|
+
yield {
|
|
613
|
+
candidates: [{ content: { parts: [{ text: '' }] } }], // Invalid empty text part
|
|
614
|
+
};
|
|
615
|
+
})())
|
|
616
|
+
.mockImplementationOnce(async () =>
|
|
617
|
+
// Second call returns a valid stream
|
|
618
|
+
(async function* () {
|
|
619
|
+
yield {
|
|
620
|
+
candidates: [
|
|
621
|
+
{
|
|
622
|
+
content: { parts: [{ text: 'Successful response' }] },
|
|
623
|
+
finishReason: 'STOP',
|
|
624
|
+
},
|
|
625
|
+
],
|
|
626
|
+
};
|
|
627
|
+
})());
|
|
628
|
+
const stream = await chat.sendMessageStream('test-model', { message: 'test' }, 'prompt-id-retry-success');
|
|
629
|
+
const chunks = [];
|
|
630
|
+
for await (const chunk of stream) {
|
|
631
|
+
chunks.push(chunk);
|
|
632
|
+
}
|
|
633
|
+
// Assertions
|
|
634
|
+
expect(mockLogContentRetry).toHaveBeenCalledTimes(1);
|
|
635
|
+
expect(mockLogContentRetryFailure).not.toHaveBeenCalled();
|
|
636
|
+
expect(mockContentGenerator.generateContentStream).toHaveBeenCalledTimes(2);
|
|
637
|
+
// Check for a retry event
|
|
638
|
+
expect(chunks.some((c) => c.type === StreamEventType.RETRY)).toBe(true);
|
|
639
|
+
// Check for the successful content chunk
|
|
640
|
+
expect(chunks.some((c) => c.type === StreamEventType.CHUNK &&
|
|
641
|
+
c.value.candidates?.[0]?.content?.parts?.[0]?.text ===
|
|
642
|
+
'Successful response')).toBe(true);
|
|
643
|
+
// Check that history was recorded correctly once, with no duplicates.
|
|
644
|
+
const history = chat.getHistory();
|
|
645
|
+
expect(history.length).toBe(2);
|
|
646
|
+
expect(history[0]).toEqual({
|
|
647
|
+
role: 'user',
|
|
648
|
+
parts: [{ text: 'test' }],
|
|
649
|
+
});
|
|
650
|
+
expect(history[1]).toEqual({
|
|
651
|
+
role: 'model',
|
|
652
|
+
parts: [{ text: 'Successful response' }],
|
|
653
|
+
});
|
|
654
|
+
// Verify that token counting is not called when usageMetadata is missing
|
|
655
|
+
expect(uiTelemetryService.setLastPromptTokenCount).not.toHaveBeenCalled();
|
|
656
|
+
});
|
|
657
|
+
it('should fail after all retries on persistent invalid content and report metrics', async () => {
|
|
658
|
+
vi.mocked(mockContentGenerator.generateContentStream).mockImplementation(async () => (async function* () {
|
|
659
|
+
yield {
|
|
660
|
+
candidates: [
|
|
661
|
+
{
|
|
662
|
+
content: {
|
|
663
|
+
parts: [{ text: '' }],
|
|
664
|
+
role: 'model',
|
|
665
|
+
},
|
|
666
|
+
},
|
|
667
|
+
],
|
|
668
|
+
};
|
|
669
|
+
})());
|
|
670
|
+
const stream = await chat.sendMessageStream('test-model', { message: 'test' }, 'prompt-id-retry-fail');
|
|
671
|
+
await expect(async () => {
|
|
672
|
+
for await (const _ of stream) {
|
|
673
|
+
// Must loop to trigger the internal logic that throws.
|
|
674
|
+
}
|
|
675
|
+
}).rejects.toThrow(InvalidStreamError);
|
|
676
|
+
// Should be called 2 times (initial + 1 retry)
|
|
677
|
+
expect(mockContentGenerator.generateContentStream).toHaveBeenCalledTimes(2);
|
|
678
|
+
expect(mockLogContentRetry).toHaveBeenCalledTimes(1);
|
|
679
|
+
expect(mockLogContentRetryFailure).toHaveBeenCalledTimes(1);
|
|
680
|
+
// History should still contain the user message.
|
|
681
|
+
const history = chat.getHistory();
|
|
682
|
+
expect(history.length).toBe(1);
|
|
683
|
+
expect(history[0]).toEqual({
|
|
684
|
+
role: 'user',
|
|
685
|
+
parts: [{ text: 'test' }],
|
|
686
|
+
});
|
|
687
|
+
});
|
|
688
|
+
describe('API error retry behavior', () => {
|
|
689
|
+
beforeEach(() => {
|
|
690
|
+
// Use a more direct mock for retry testing
|
|
691
|
+
mockRetryWithBackoff.mockImplementation(async (apiCall, options) => {
|
|
692
|
+
try {
|
|
693
|
+
return await apiCall();
|
|
694
|
+
}
|
|
695
|
+
catch (error) {
|
|
696
|
+
if (options?.shouldRetryOnError &&
|
|
697
|
+
options.shouldRetryOnError(error)) {
|
|
698
|
+
// Try again
|
|
699
|
+
return await apiCall();
|
|
700
|
+
}
|
|
701
|
+
throw error;
|
|
702
|
+
}
|
|
703
|
+
});
|
|
704
|
+
});
|
|
705
|
+
it('should not retry on 400 Bad Request errors', async () => {
|
|
706
|
+
const error400 = new ApiError({ message: 'Bad Request', status: 400 });
|
|
707
|
+
vi.mocked(mockContentGenerator.generateContentStream).mockRejectedValue(error400);
|
|
708
|
+
const stream = await chat.sendMessageStream('test-model', { message: 'test' }, 'prompt-id-400');
|
|
709
|
+
await expect((async () => {
|
|
710
|
+
for await (const _ of stream) {
|
|
711
|
+
/* consume stream */
|
|
712
|
+
}
|
|
713
|
+
})()).rejects.toThrow(error400);
|
|
714
|
+
// Should only be called once (no retry)
|
|
715
|
+
expect(mockContentGenerator.generateContentStream).toHaveBeenCalledTimes(1);
|
|
716
|
+
});
|
|
717
|
+
it('should retry on 429 Rate Limit errors', async () => {
|
|
718
|
+
const error429 = new ApiError({ message: 'Rate Limited', status: 429 });
|
|
719
|
+
vi.mocked(mockContentGenerator.generateContentStream)
|
|
720
|
+
.mockRejectedValueOnce(error429)
|
|
721
|
+
.mockResolvedValueOnce((async function* () {
|
|
722
|
+
yield {
|
|
723
|
+
candidates: [
|
|
724
|
+
{
|
|
725
|
+
content: { parts: [{ text: 'Success after retry' }] },
|
|
726
|
+
finishReason: 'STOP',
|
|
727
|
+
},
|
|
728
|
+
],
|
|
729
|
+
};
|
|
730
|
+
})());
|
|
731
|
+
const stream = await chat.sendMessageStream('test-model', { message: 'test' }, 'prompt-id-429-retry');
|
|
732
|
+
const events = [];
|
|
733
|
+
for await (const event of stream) {
|
|
734
|
+
events.push(event);
|
|
735
|
+
}
|
|
736
|
+
// Should be called twice (initial + retry)
|
|
737
|
+
expect(mockContentGenerator.generateContentStream).toHaveBeenCalledTimes(2);
|
|
738
|
+
// Should have successful content
|
|
739
|
+
expect(events.some((e) => e.type === StreamEventType.CHUNK &&
|
|
740
|
+
e.value.candidates?.[0]?.content?.parts?.[0]?.text ===
|
|
741
|
+
'Success after retry')).toBe(true);
|
|
742
|
+
});
|
|
743
|
+
it('should not retry on schema depth errors', async () => {
|
|
744
|
+
const schemaError = new ApiError({
|
|
745
|
+
message: 'Request failed: maximum schema depth exceeded',
|
|
746
|
+
status: 500,
|
|
747
|
+
});
|
|
748
|
+
vi.mocked(mockContentGenerator.generateContentStream).mockRejectedValue(schemaError);
|
|
749
|
+
const stream = await chat.sendMessageStream('test-model', { message: 'test' }, 'prompt-id-schema');
|
|
750
|
+
await expect((async () => {
|
|
751
|
+
for await (const _ of stream) {
|
|
752
|
+
/* consume stream */
|
|
753
|
+
}
|
|
754
|
+
})()).rejects.toThrow(schemaError);
|
|
755
|
+
// Should only be called once (no retry)
|
|
756
|
+
expect(mockContentGenerator.generateContentStream).toHaveBeenCalledTimes(1);
|
|
757
|
+
});
|
|
758
|
+
it('should retry on 5xx server errors', async () => {
|
|
759
|
+
const error500 = new ApiError({
|
|
760
|
+
message: 'Internal Server Error 500',
|
|
761
|
+
status: 500,
|
|
762
|
+
});
|
|
763
|
+
vi.mocked(mockContentGenerator.generateContentStream)
|
|
764
|
+
.mockRejectedValueOnce(error500)
|
|
765
|
+
.mockResolvedValueOnce((async function* () {
|
|
766
|
+
yield {
|
|
767
|
+
candidates: [
|
|
768
|
+
{
|
|
769
|
+
content: { parts: [{ text: 'Recovered from 500' }] },
|
|
770
|
+
finishReason: 'STOP',
|
|
771
|
+
},
|
|
772
|
+
],
|
|
773
|
+
};
|
|
774
|
+
})());
|
|
775
|
+
const stream = await chat.sendMessageStream('test-model', { message: 'test' }, 'prompt-id-500-retry');
|
|
776
|
+
const events = [];
|
|
777
|
+
for await (const event of stream) {
|
|
778
|
+
events.push(event);
|
|
779
|
+
}
|
|
780
|
+
// Should be called twice (initial + retry)
|
|
781
|
+
expect(mockContentGenerator.generateContentStream).toHaveBeenCalledTimes(2);
|
|
782
|
+
});
|
|
783
|
+
afterEach(() => {
|
|
784
|
+
// Reset to default behavior
|
|
785
|
+
mockRetryWithBackoff.mockImplementation(async (apiCall) => apiCall());
|
|
786
|
+
});
|
|
787
|
+
});
|
|
788
|
+
});
|
|
789
|
+
it('should correctly retry and append to an existing history mid-conversation', async () => {
|
|
790
|
+
// 1. Setup
|
|
791
|
+
const initialHistory = [
|
|
792
|
+
{ role: 'user', parts: [{ text: 'First question' }] },
|
|
793
|
+
{ role: 'model', parts: [{ text: 'First answer' }] },
|
|
794
|
+
];
|
|
795
|
+
chat.setHistory(initialHistory);
|
|
796
|
+
// 2. Mock the API to fail once with an empty stream, then succeed.
|
|
797
|
+
vi.mocked(mockContentGenerator.generateContentStream)
|
|
798
|
+
.mockImplementationOnce(async () => (async function* () {
|
|
799
|
+
yield {
|
|
800
|
+
candidates: [{ content: { parts: [{ text: '' }] } }],
|
|
801
|
+
};
|
|
802
|
+
})())
|
|
803
|
+
.mockImplementationOnce(async () =>
|
|
804
|
+
// Second attempt succeeds
|
|
805
|
+
(async function* () {
|
|
806
|
+
yield {
|
|
807
|
+
candidates: [
|
|
808
|
+
{
|
|
809
|
+
content: { parts: [{ text: 'Second answer' }] },
|
|
810
|
+
finishReason: 'STOP',
|
|
811
|
+
},
|
|
812
|
+
],
|
|
813
|
+
};
|
|
814
|
+
})());
|
|
815
|
+
// 3. Send a new message
|
|
816
|
+
const stream = await chat.sendMessageStream('test-model', { message: 'Second question' }, 'prompt-id-retry-existing');
|
|
817
|
+
for await (const _ of stream) {
|
|
818
|
+
// consume stream
|
|
819
|
+
}
|
|
820
|
+
// 4. Assert the final history and metrics
|
|
821
|
+
const history = chat.getHistory();
|
|
822
|
+
expect(history.length).toBe(4);
|
|
823
|
+
// Assert that the correct metrics were reported for one empty-stream retry
|
|
824
|
+
expect(mockLogContentRetry).toHaveBeenCalledTimes(1);
|
|
825
|
+
// Explicitly verify the structure of each part to satisfy TypeScript
|
|
826
|
+
const turn1 = history[0];
|
|
827
|
+
if (!turn1?.parts?.[0] || !('text' in turn1.parts[0])) {
|
|
828
|
+
throw new Error('Test setup error: First turn is not a valid text part.');
|
|
829
|
+
}
|
|
830
|
+
expect(turn1.parts[0].text).toBe('First question');
|
|
831
|
+
const turn2 = history[1];
|
|
832
|
+
if (!turn2?.parts?.[0] || !('text' in turn2.parts[0])) {
|
|
833
|
+
throw new Error('Test setup error: Second turn is not a valid text part.');
|
|
834
|
+
}
|
|
835
|
+
expect(turn2.parts[0].text).toBe('First answer');
|
|
836
|
+
const turn3 = history[2];
|
|
837
|
+
if (!turn3?.parts?.[0] || !('text' in turn3.parts[0])) {
|
|
838
|
+
throw new Error('Test setup error: Third turn is not a valid text part.');
|
|
839
|
+
}
|
|
840
|
+
expect(turn3.parts[0].text).toBe('Second question');
|
|
841
|
+
const turn4 = history[3];
|
|
842
|
+
if (!turn4?.parts?.[0] || !('text' in turn4.parts[0])) {
|
|
843
|
+
throw new Error('Test setup error: Fourth turn is not a valid text part.');
|
|
844
|
+
}
|
|
845
|
+
expect(turn4.parts[0].text).toBe('Second answer');
|
|
846
|
+
});
|
|
847
|
+
it('should retry if the model returns a completely empty stream (no chunks)', async () => {
|
|
848
|
+
// 1. Mock the API to return an empty stream first, then a valid one.
|
|
849
|
+
vi.mocked(mockContentGenerator.generateContentStream)
|
|
850
|
+
.mockImplementationOnce(
|
|
851
|
+
// First call resolves to an async generator that yields nothing.
|
|
852
|
+
async () => (async function* () { })())
|
|
853
|
+
.mockImplementationOnce(
|
|
854
|
+
// Second call returns a valid stream.
|
|
855
|
+
async () => (async function* () {
|
|
856
|
+
yield {
|
|
857
|
+
candidates: [
|
|
858
|
+
{
|
|
859
|
+
content: {
|
|
860
|
+
parts: [{ text: 'Successful response after empty' }],
|
|
861
|
+
},
|
|
862
|
+
finishReason: 'STOP',
|
|
863
|
+
},
|
|
864
|
+
],
|
|
865
|
+
};
|
|
866
|
+
})());
|
|
867
|
+
// 2. Call the method and consume the stream.
|
|
868
|
+
const stream = await chat.sendMessageStream('test-model', { message: 'test empty stream' }, 'prompt-id-empty-stream');
|
|
869
|
+
const chunks = [];
|
|
870
|
+
for await (const chunk of stream) {
|
|
871
|
+
chunks.push(chunk);
|
|
872
|
+
}
|
|
873
|
+
// 3. Assert the results.
|
|
874
|
+
expect(mockContentGenerator.generateContentStream).toHaveBeenCalledTimes(2);
|
|
875
|
+
expect(chunks.some((c) => c.type === StreamEventType.CHUNK &&
|
|
876
|
+
c.value.candidates?.[0]?.content?.parts?.[0]?.text ===
|
|
877
|
+
'Successful response after empty')).toBe(true);
|
|
878
|
+
const history = chat.getHistory();
|
|
879
|
+
expect(history.length).toBe(2);
|
|
880
|
+
// Explicitly verify the structure of each part to satisfy TypeScript
|
|
881
|
+
const turn1 = history[0];
|
|
882
|
+
if (!turn1?.parts?.[0] || !('text' in turn1.parts[0])) {
|
|
883
|
+
throw new Error('Test setup error: First turn is not a valid text part.');
|
|
884
|
+
}
|
|
885
|
+
expect(turn1.parts[0].text).toBe('test empty stream');
|
|
886
|
+
const turn2 = history[1];
|
|
887
|
+
if (!turn2?.parts?.[0] || !('text' in turn2.parts[0])) {
|
|
888
|
+
throw new Error('Test setup error: Second turn is not a valid text part.');
|
|
889
|
+
}
|
|
890
|
+
expect(turn2.parts[0].text).toBe('Successful response after empty');
|
|
891
|
+
});
|
|
892
|
+
it('should queue a subsequent sendMessageStream call until the first stream is fully consumed', async () => {
|
|
893
|
+
// 1. Create a promise to manually control the stream's lifecycle
|
|
894
|
+
let continueFirstStream;
|
|
895
|
+
const firstStreamContinuePromise = new Promise((resolve) => {
|
|
896
|
+
continueFirstStream = resolve;
|
|
897
|
+
});
|
|
898
|
+
// 2. Mock the API to return controllable async generators
|
|
899
|
+
const firstStreamGenerator = (async function* () {
|
|
900
|
+
yield {
|
|
901
|
+
candidates: [
|
|
902
|
+
{ content: { parts: [{ text: 'first response part 1' }] } },
|
|
903
|
+
],
|
|
904
|
+
};
|
|
905
|
+
await firstStreamContinuePromise; // Pause the stream
|
|
906
|
+
yield {
|
|
907
|
+
candidates: [
|
|
908
|
+
{
|
|
909
|
+
content: { parts: [{ text: ' part 2' }] },
|
|
910
|
+
finishReason: 'STOP',
|
|
911
|
+
},
|
|
912
|
+
],
|
|
913
|
+
};
|
|
914
|
+
})();
|
|
915
|
+
const secondStreamGenerator = (async function* () {
|
|
916
|
+
yield {
|
|
917
|
+
candidates: [
|
|
918
|
+
{
|
|
919
|
+
content: { parts: [{ text: 'second response' }] },
|
|
920
|
+
finishReason: 'STOP',
|
|
921
|
+
},
|
|
922
|
+
],
|
|
923
|
+
};
|
|
924
|
+
})();
|
|
925
|
+
vi.mocked(mockContentGenerator.generateContentStream)
|
|
926
|
+
.mockResolvedValueOnce(firstStreamGenerator)
|
|
927
|
+
.mockResolvedValueOnce(secondStreamGenerator);
|
|
928
|
+
// 3. Start the first stream and consume only the first chunk to pause it
|
|
929
|
+
const firstStream = await chat.sendMessageStream('test-model', { message: 'first' }, 'prompt-1');
|
|
930
|
+
const firstStreamIterator = firstStream[Symbol.asyncIterator]();
|
|
931
|
+
await firstStreamIterator.next();
|
|
932
|
+
// 4. While the first stream is paused, start the second call. It will block.
|
|
933
|
+
const secondStreamPromise = chat.sendMessageStream('test-model', { message: 'second' }, 'prompt-2');
|
|
934
|
+
// 5. Assert that only one API call has been made so far.
|
|
935
|
+
expect(mockContentGenerator.generateContentStream).toHaveBeenCalledTimes(1);
|
|
936
|
+
// 6. Unblock and fully consume the first stream to completion.
|
|
937
|
+
continueFirstStream();
|
|
938
|
+
await firstStreamIterator.next(); // Consume the rest of the stream
|
|
939
|
+
await firstStreamIterator.next(); // Finish the iterator
|
|
940
|
+
// 7. Now that the first stream is done, await the second promise to get its generator.
|
|
941
|
+
const secondStream = await secondStreamPromise;
|
|
942
|
+
// 8. Start consuming the second stream, which triggers its internal API call.
|
|
943
|
+
const secondStreamIterator = secondStream[Symbol.asyncIterator]();
|
|
944
|
+
await secondStreamIterator.next();
|
|
945
|
+
// 9. The second API call should now have been made.
|
|
946
|
+
expect(mockContentGenerator.generateContentStream).toHaveBeenCalledTimes(2);
|
|
947
|
+
// 10. FIX: Fully consume the second stream to ensure recordHistory is called.
|
|
948
|
+
await secondStreamIterator.next(); // This finishes the iterator.
|
|
949
|
+
// 11. Final check on history.
|
|
950
|
+
const history = chat.getHistory();
|
|
951
|
+
expect(history.length).toBe(4);
|
|
952
|
+
const turn4 = history[3];
|
|
953
|
+
if (!turn4?.parts?.[0] || !('text' in turn4.parts[0])) {
|
|
954
|
+
throw new Error('Test setup error: Fourth turn is not a valid text part.');
|
|
955
|
+
}
|
|
956
|
+
expect(turn4.parts[0].text).toBe('second response');
|
|
957
|
+
});
|
|
958
|
+
describe('Model Resolution', () => {
|
|
959
|
+
const mockResponse = {
|
|
960
|
+
candidates: [
|
|
961
|
+
{
|
|
962
|
+
content: { parts: [{ text: 'response' }], role: 'model' },
|
|
963
|
+
finishReason: 'STOP',
|
|
964
|
+
},
|
|
965
|
+
],
|
|
966
|
+
};
|
|
967
|
+
it('should use the FLASH model when in fallback mode (sendMessageStream)', async () => {
|
|
968
|
+
vi.mocked(mockConfig.getModel).mockReturnValue('gemini-pro');
|
|
969
|
+
vi.mocked(mockConfig.isInFallbackMode).mockReturnValue(true);
|
|
970
|
+
vi.mocked(mockContentGenerator.generateContentStream).mockImplementation(async () => (async function* () {
|
|
971
|
+
yield mockResponse;
|
|
972
|
+
})());
|
|
973
|
+
const stream = await chat.sendMessageStream('test-model', { message: 'test' }, 'prompt-id-res3');
|
|
974
|
+
for await (const _ of stream) {
|
|
975
|
+
// consume stream
|
|
976
|
+
}
|
|
977
|
+
expect(mockContentGenerator.generateContentStream).toHaveBeenCalledWith(expect.objectContaining({
|
|
978
|
+
model: DEFAULT_GEMINI_FLASH_MODEL,
|
|
979
|
+
}), 'prompt-id-res3');
|
|
980
|
+
});
|
|
981
|
+
});
|
|
982
|
+
describe('Fallback Integration (Retries)', () => {
|
|
983
|
+
const error429 = new ApiError({
|
|
984
|
+
message: 'API Error 429: Quota exceeded',
|
|
985
|
+
status: 429,
|
|
986
|
+
});
|
|
987
|
+
// Define the simulated behavior for retryWithBackoff for these tests.
|
|
988
|
+
// This simulation tries the apiCall, if it fails, it calls the callback,
|
|
989
|
+
// and then tries the apiCall again if the callback returns true.
|
|
990
|
+
const simulateRetryBehavior = async (apiCall, options) => {
|
|
991
|
+
try {
|
|
992
|
+
return await apiCall();
|
|
993
|
+
}
|
|
994
|
+
catch (error) {
|
|
995
|
+
if (options.onPersistent429) {
|
|
996
|
+
// We simulate the "persistent" trigger here for simplicity.
|
|
997
|
+
const shouldRetry = await options.onPersistent429(options.authType, error);
|
|
998
|
+
if (shouldRetry) {
|
|
999
|
+
return await apiCall();
|
|
1000
|
+
}
|
|
1001
|
+
}
|
|
1002
|
+
throw error; // Stop if callback returns false/null or doesn't exist
|
|
1003
|
+
}
|
|
1004
|
+
};
|
|
1005
|
+
beforeEach(() => {
|
|
1006
|
+
mockRetryWithBackoff.mockImplementation(simulateRetryBehavior);
|
|
1007
|
+
});
|
|
1008
|
+
afterEach(() => {
|
|
1009
|
+
mockRetryWithBackoff.mockImplementation(async (apiCall) => apiCall());
|
|
1010
|
+
});
|
|
1011
|
+
it('should call handleFallback with the specific failed model and retry if handler returns true', async () => {
|
|
1012
|
+
const authType = AuthType.LOGIN_WITH_GOOGLE;
|
|
1013
|
+
vi.mocked(mockConfig.getContentGeneratorConfig).mockReturnValue({
|
|
1014
|
+
model: 'test-model',
|
|
1015
|
+
authType,
|
|
1016
|
+
});
|
|
1017
|
+
const isInFallbackModeSpy = vi.spyOn(mockConfig, 'isInFallbackMode');
|
|
1018
|
+
isInFallbackModeSpy.mockReturnValue(false);
|
|
1019
|
+
vi.mocked(mockContentGenerator.generateContentStream)
|
|
1020
|
+
.mockRejectedValueOnce(error429) // Attempt 1 fails
|
|
1021
|
+
.mockResolvedValueOnce(
|
|
1022
|
+
// Attempt 2 succeeds
|
|
1023
|
+
(async function* () {
|
|
1024
|
+
yield {
|
|
1025
|
+
candidates: [
|
|
1026
|
+
{
|
|
1027
|
+
content: { parts: [{ text: 'Success on retry' }] },
|
|
1028
|
+
finishReason: 'STOP',
|
|
1029
|
+
},
|
|
1030
|
+
],
|
|
1031
|
+
};
|
|
1032
|
+
})());
|
|
1033
|
+
mockHandleFallback.mockImplementation(async () => {
|
|
1034
|
+
isInFallbackModeSpy.mockReturnValue(true);
|
|
1035
|
+
return true; // Signal retry
|
|
1036
|
+
});
|
|
1037
|
+
const stream = await chat.sendMessageStream('test-model', { message: 'trigger 429' }, 'prompt-id-fb1');
|
|
1038
|
+
// Consume stream to trigger logic
|
|
1039
|
+
for await (const _ of stream) {
|
|
1040
|
+
// no-op
|
|
1041
|
+
}
|
|
1042
|
+
expect(mockContentGenerator.generateContentStream).toHaveBeenCalledTimes(2);
|
|
1043
|
+
expect(mockHandleFallback).toHaveBeenCalledTimes(1);
|
|
1044
|
+
expect(mockHandleFallback).toHaveBeenCalledWith(mockConfig, 'test-model', authType, error429);
|
|
1045
|
+
const history = chat.getHistory();
|
|
1046
|
+
const modelTurn = history[1];
|
|
1047
|
+
expect(modelTurn.parts[0].text).toBe('Success on retry');
|
|
1048
|
+
});
|
|
1049
|
+
it('should stop retrying if handleFallback returns false (e.g., auth intent)', async () => {
|
|
1050
|
+
vi.mocked(mockConfig.getModel).mockReturnValue('gemini-pro');
|
|
1051
|
+
vi.mocked(mockContentGenerator.generateContentStream).mockRejectedValue(error429);
|
|
1052
|
+
mockHandleFallback.mockResolvedValue(false);
|
|
1053
|
+
const stream = await chat.sendMessageStream('test-model', { message: 'test stop' }, 'prompt-id-fb2');
|
|
1054
|
+
await expect((async () => {
|
|
1055
|
+
for await (const _ of stream) {
|
|
1056
|
+
/* consume stream */
|
|
1057
|
+
}
|
|
1058
|
+
})()).rejects.toThrow(error429);
|
|
1059
|
+
expect(mockContentGenerator.generateContentStream).toHaveBeenCalledTimes(1);
|
|
1060
|
+
expect(mockHandleFallback).toHaveBeenCalledTimes(1);
|
|
1061
|
+
});
|
|
1062
|
+
});
|
|
1063
|
+
it('should discard valid partial content from a failed attempt upon retry', async () => {
|
|
1064
|
+
// Mock the stream to fail on the first attempt after yielding some valid content.
|
|
1065
|
+
vi.mocked(mockContentGenerator.generateContentStream)
|
|
1066
|
+
.mockImplementationOnce(async () =>
|
|
1067
|
+
// First attempt: yields one valid chunk, then one invalid chunk
|
|
1068
|
+
(async function* () {
|
|
1069
|
+
yield {
|
|
1070
|
+
candidates: [
|
|
1071
|
+
{
|
|
1072
|
+
content: {
|
|
1073
|
+
parts: [{ text: 'This valid part should be discarded' }],
|
|
1074
|
+
},
|
|
1075
|
+
},
|
|
1076
|
+
],
|
|
1077
|
+
};
|
|
1078
|
+
yield {
|
|
1079
|
+
candidates: [{ content: { parts: [{ text: '' }] } }], // Invalid chunk triggers retry
|
|
1080
|
+
};
|
|
1081
|
+
})())
|
|
1082
|
+
.mockImplementationOnce(async () =>
|
|
1083
|
+
// Second attempt (the retry): succeeds
|
|
1084
|
+
(async function* () {
|
|
1085
|
+
yield {
|
|
1086
|
+
candidates: [
|
|
1087
|
+
{
|
|
1088
|
+
content: {
|
|
1089
|
+
parts: [{ text: 'Successful final response' }],
|
|
1090
|
+
},
|
|
1091
|
+
finishReason: 'STOP',
|
|
1092
|
+
},
|
|
1093
|
+
],
|
|
1094
|
+
};
|
|
1095
|
+
})());
|
|
1096
|
+
// Send a message and consume the stream
|
|
1097
|
+
const stream = await chat.sendMessageStream('test-model', { message: 'test' }, 'prompt-id-discard-test');
|
|
1098
|
+
const events = [];
|
|
1099
|
+
for await (const event of stream) {
|
|
1100
|
+
events.push(event);
|
|
1101
|
+
}
|
|
1102
|
+
// Check that a retry happened
|
|
1103
|
+
expect(mockContentGenerator.generateContentStream).toHaveBeenCalledTimes(2);
|
|
1104
|
+
expect(events.some((e) => e.type === StreamEventType.RETRY)).toBe(true);
|
|
1105
|
+
// Check the final recorded history
|
|
1106
|
+
const history = chat.getHistory();
|
|
1107
|
+
expect(history.length).toBe(2); // user turn + final model turn
|
|
1108
|
+
const modelTurn = history[1];
|
|
1109
|
+
// The model turn should only contain the text from the successful attempt
|
|
1110
|
+
expect(modelTurn.parts[0].text).toBe('Successful final response');
|
|
1111
|
+
// It should NOT contain any text from the failed attempt
|
|
1112
|
+
expect(modelTurn.parts[0].text).not.toContain('This valid part should be discarded');
|
|
1113
|
+
});
|
|
1114
|
+
describe('stripThoughtsFromHistory', () => {
|
|
1115
|
+
it('should strip thought signatures', () => {
|
|
1116
|
+
chat.setHistory([
|
|
1117
|
+
{
|
|
1118
|
+
role: 'user',
|
|
1119
|
+
parts: [{ text: 'hello' }],
|
|
1120
|
+
},
|
|
1121
|
+
{
|
|
1122
|
+
role: 'model',
|
|
1123
|
+
parts: [
|
|
1124
|
+
{ text: 'thinking...', thoughtSignature: 'thought-123' },
|
|
1125
|
+
{
|
|
1126
|
+
functionCall: { name: 'test', args: {} },
|
|
1127
|
+
thoughtSignature: 'thought-456',
|
|
1128
|
+
},
|
|
1129
|
+
],
|
|
1130
|
+
},
|
|
1131
|
+
]);
|
|
1132
|
+
chat.stripThoughtsFromHistory();
|
|
1133
|
+
expect(chat.getHistory()).toEqual([
|
|
1134
|
+
{
|
|
1135
|
+
role: 'user',
|
|
1136
|
+
parts: [{ text: 'hello' }],
|
|
1137
|
+
},
|
|
1138
|
+
{
|
|
1139
|
+
role: 'model',
|
|
1140
|
+
parts: [
|
|
1141
|
+
{ text: 'thinking...' },
|
|
1142
|
+
{ functionCall: { name: 'test', args: {} } },
|
|
1143
|
+
],
|
|
1144
|
+
},
|
|
1145
|
+
]);
|
|
1146
|
+
});
|
|
1147
|
+
});
|
|
1148
|
+
});
|
|
1149
|
+
//# sourceMappingURL=geminiChat.test.js.map
|