@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,1802 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2025 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
7
|
+
import { ApprovalMode, BaseDeclarativeTool, BaseToolInvocation, Kind, ToolConfirmationOutcome, DEFAULT_TRUNCATE_TOOL_OUTPUT_LINES, DEFAULT_TRUNCATE_TOOL_OUTPUT_THRESHOLD, } from '../index.js';
|
|
8
|
+
import { CoreToolScheduler, convertToFunctionResponse, truncateAndSaveToFile, } from './coreToolScheduler.js';
|
|
9
|
+
import { MockModifiableTool, MockTool, MOCK_TOOL_SHOULD_CONFIRM_EXECUTE, } from '../test-utils/mock-tool.js';
|
|
10
|
+
import * as fs from 'node:fs/promises';
|
|
11
|
+
import * as path from 'node:path';
|
|
12
|
+
vi.mock('fs/promises', () => ({
|
|
13
|
+
writeFile: vi.fn(),
|
|
14
|
+
}));
|
|
15
|
+
class TestApprovalTool extends BaseDeclarativeTool {
|
|
16
|
+
config;
|
|
17
|
+
static Name = 'testApprovalTool';
|
|
18
|
+
constructor(config) {
|
|
19
|
+
super(TestApprovalTool.Name, 'TestApprovalTool', 'A tool for testing approval logic', Kind.Edit, {
|
|
20
|
+
properties: { id: { type: 'string' } },
|
|
21
|
+
required: ['id'],
|
|
22
|
+
type: 'object',
|
|
23
|
+
});
|
|
24
|
+
this.config = config;
|
|
25
|
+
}
|
|
26
|
+
createInvocation(params) {
|
|
27
|
+
return new TestApprovalInvocation(this.config, params);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
class TestApprovalInvocation extends BaseToolInvocation {
|
|
31
|
+
config;
|
|
32
|
+
constructor(config, params) {
|
|
33
|
+
super(params);
|
|
34
|
+
this.config = config;
|
|
35
|
+
}
|
|
36
|
+
getDescription() {
|
|
37
|
+
return `Test tool ${this.params.id}`;
|
|
38
|
+
}
|
|
39
|
+
async shouldConfirmExecute() {
|
|
40
|
+
// Need confirmation unless approval mode is AUTO_EDIT
|
|
41
|
+
if (this.config.getApprovalMode() === ApprovalMode.AUTO_EDIT) {
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
return {
|
|
45
|
+
type: 'edit',
|
|
46
|
+
title: `Confirm Test Tool ${this.params.id}`,
|
|
47
|
+
fileName: `test-${this.params.id}.txt`,
|
|
48
|
+
filePath: `/test-${this.params.id}.txt`,
|
|
49
|
+
fileDiff: 'Test diff content',
|
|
50
|
+
originalContent: '',
|
|
51
|
+
newContent: 'Test content',
|
|
52
|
+
onConfirm: async (outcome) => {
|
|
53
|
+
if (outcome === ToolConfirmationOutcome.ProceedAlways) {
|
|
54
|
+
this.config.setApprovalMode(ApprovalMode.AUTO_EDIT);
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
async execute() {
|
|
60
|
+
return {
|
|
61
|
+
llmContent: `Executed test tool ${this.params.id}`,
|
|
62
|
+
returnDisplay: `Executed test tool ${this.params.id}`,
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
class AbortDuringConfirmationInvocation extends BaseToolInvocation {
|
|
67
|
+
abortController;
|
|
68
|
+
abortError;
|
|
69
|
+
constructor(abortController, abortError, params) {
|
|
70
|
+
super(params);
|
|
71
|
+
this.abortController = abortController;
|
|
72
|
+
this.abortError = abortError;
|
|
73
|
+
}
|
|
74
|
+
async shouldConfirmExecute(_signal) {
|
|
75
|
+
this.abortController.abort();
|
|
76
|
+
throw this.abortError;
|
|
77
|
+
}
|
|
78
|
+
async execute(_abortSignal) {
|
|
79
|
+
throw new Error('execute should not be called when confirmation fails');
|
|
80
|
+
}
|
|
81
|
+
getDescription() {
|
|
82
|
+
return 'Abort during confirmation invocation';
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
class AbortDuringConfirmationTool extends BaseDeclarativeTool {
|
|
86
|
+
abortController;
|
|
87
|
+
abortError;
|
|
88
|
+
constructor(abortController, abortError) {
|
|
89
|
+
super('abortDuringConfirmationTool', 'Abort During Confirmation Tool', 'A tool that aborts while confirming execution.', Kind.Other, {
|
|
90
|
+
type: 'object',
|
|
91
|
+
properties: {},
|
|
92
|
+
});
|
|
93
|
+
this.abortController = abortController;
|
|
94
|
+
this.abortError = abortError;
|
|
95
|
+
}
|
|
96
|
+
createInvocation(params) {
|
|
97
|
+
return new AbortDuringConfirmationInvocation(this.abortController, this.abortError, params);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
async function waitForStatus(onToolCallsUpdate, status, timeout = 5000) {
|
|
101
|
+
return new Promise((resolve, reject) => {
|
|
102
|
+
const startTime = Date.now();
|
|
103
|
+
const check = () => {
|
|
104
|
+
if (Date.now() - startTime > timeout) {
|
|
105
|
+
const seenStatuses = onToolCallsUpdate.mock.calls
|
|
106
|
+
.flatMap((call) => call[0])
|
|
107
|
+
.map((toolCall) => toolCall.status);
|
|
108
|
+
reject(new Error(`Timed out waiting for status "${status}". Seen statuses: ${seenStatuses.join(', ')}`));
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
const foundCall = onToolCallsUpdate.mock.calls
|
|
112
|
+
.flatMap((call) => call[0])
|
|
113
|
+
.find((toolCall) => toolCall.status === status);
|
|
114
|
+
if (foundCall) {
|
|
115
|
+
resolve(foundCall);
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
118
|
+
setTimeout(check, 10); // Check again in 10ms
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
check();
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
describe('CoreToolScheduler', () => {
|
|
125
|
+
it('should cancel a tool call if the signal is aborted before confirmation', async () => {
|
|
126
|
+
const mockTool = new MockTool({
|
|
127
|
+
name: 'mockTool',
|
|
128
|
+
shouldConfirmExecute: MOCK_TOOL_SHOULD_CONFIRM_EXECUTE,
|
|
129
|
+
});
|
|
130
|
+
const declarativeTool = mockTool;
|
|
131
|
+
const mockToolRegistry = {
|
|
132
|
+
getTool: () => declarativeTool,
|
|
133
|
+
getFunctionDeclarations: () => [],
|
|
134
|
+
tools: new Map(),
|
|
135
|
+
discovery: {},
|
|
136
|
+
registerTool: () => { },
|
|
137
|
+
getToolByName: () => declarativeTool,
|
|
138
|
+
getToolByDisplayName: () => declarativeTool,
|
|
139
|
+
getTools: () => [],
|
|
140
|
+
discoverTools: async () => { },
|
|
141
|
+
getAllTools: () => [],
|
|
142
|
+
getToolsByServer: () => [],
|
|
143
|
+
};
|
|
144
|
+
const onAllToolCallsComplete = vi.fn();
|
|
145
|
+
const onToolCallsUpdate = vi.fn();
|
|
146
|
+
const mockConfig = {
|
|
147
|
+
getSessionId: () => 'test-session-id',
|
|
148
|
+
getUsageStatisticsEnabled: () => true,
|
|
149
|
+
getDebugMode: () => false,
|
|
150
|
+
getApprovalMode: () => ApprovalMode.DEFAULT,
|
|
151
|
+
getAllowedTools: () => [],
|
|
152
|
+
getContentGeneratorConfig: () => ({
|
|
153
|
+
model: 'test-model',
|
|
154
|
+
authType: 'oauth-personal',
|
|
155
|
+
}),
|
|
156
|
+
getShellExecutionConfig: () => ({
|
|
157
|
+
terminalWidth: 90,
|
|
158
|
+
terminalHeight: 30,
|
|
159
|
+
}),
|
|
160
|
+
storage: {
|
|
161
|
+
getProjectTempDir: () => '/tmp',
|
|
162
|
+
},
|
|
163
|
+
getTruncateToolOutputThreshold: () => DEFAULT_TRUNCATE_TOOL_OUTPUT_THRESHOLD,
|
|
164
|
+
getTruncateToolOutputLines: () => DEFAULT_TRUNCATE_TOOL_OUTPUT_LINES,
|
|
165
|
+
getToolRegistry: () => mockToolRegistry,
|
|
166
|
+
getUseSmartEdit: () => false,
|
|
167
|
+
getUseModelRouter: () => false,
|
|
168
|
+
getGeminiClient: () => null, // No client needed for these tests
|
|
169
|
+
};
|
|
170
|
+
const scheduler = new CoreToolScheduler({
|
|
171
|
+
config: mockConfig,
|
|
172
|
+
onAllToolCallsComplete,
|
|
173
|
+
onToolCallsUpdate,
|
|
174
|
+
getPreferredEditor: () => 'vscode',
|
|
175
|
+
onEditorClose: vi.fn(),
|
|
176
|
+
});
|
|
177
|
+
const abortController = new AbortController();
|
|
178
|
+
const request = {
|
|
179
|
+
callId: '1',
|
|
180
|
+
name: 'mockTool',
|
|
181
|
+
args: {},
|
|
182
|
+
isClientInitiated: false,
|
|
183
|
+
prompt_id: 'prompt-id-1',
|
|
184
|
+
};
|
|
185
|
+
abortController.abort();
|
|
186
|
+
await scheduler.schedule([request], abortController.signal);
|
|
187
|
+
expect(onAllToolCallsComplete).toHaveBeenCalled();
|
|
188
|
+
const completedCalls = onAllToolCallsComplete.mock
|
|
189
|
+
.calls[0][0];
|
|
190
|
+
expect(completedCalls[0].status).toBe('cancelled');
|
|
191
|
+
});
|
|
192
|
+
it('should mark tool call as cancelled when abort happens during confirmation error', async () => {
|
|
193
|
+
const abortController = new AbortController();
|
|
194
|
+
const abortError = new Error('Abort requested during confirmation');
|
|
195
|
+
const declarativeTool = new AbortDuringConfirmationTool(abortController, abortError);
|
|
196
|
+
const mockToolRegistry = {
|
|
197
|
+
getTool: () => declarativeTool,
|
|
198
|
+
getFunctionDeclarations: () => [],
|
|
199
|
+
tools: new Map(),
|
|
200
|
+
discovery: {},
|
|
201
|
+
registerTool: () => { },
|
|
202
|
+
getToolByName: () => declarativeTool,
|
|
203
|
+
getToolByDisplayName: () => declarativeTool,
|
|
204
|
+
getTools: () => [],
|
|
205
|
+
discoverTools: async () => { },
|
|
206
|
+
getAllTools: () => [],
|
|
207
|
+
getToolsByServer: () => [],
|
|
208
|
+
};
|
|
209
|
+
const onAllToolCallsComplete = vi.fn();
|
|
210
|
+
const onToolCallsUpdate = vi.fn();
|
|
211
|
+
const mockConfig = {
|
|
212
|
+
getSessionId: () => 'test-session-id',
|
|
213
|
+
getUsageStatisticsEnabled: () => true,
|
|
214
|
+
getDebugMode: () => false,
|
|
215
|
+
getApprovalMode: () => ApprovalMode.DEFAULT,
|
|
216
|
+
getAllowedTools: () => [],
|
|
217
|
+
getContentGeneratorConfig: () => ({
|
|
218
|
+
model: 'test-model',
|
|
219
|
+
authType: 'oauth-personal',
|
|
220
|
+
}),
|
|
221
|
+
getShellExecutionConfig: () => ({
|
|
222
|
+
terminalWidth: 90,
|
|
223
|
+
terminalHeight: 30,
|
|
224
|
+
}),
|
|
225
|
+
storage: {
|
|
226
|
+
getProjectTempDir: () => '/tmp',
|
|
227
|
+
},
|
|
228
|
+
getTruncateToolOutputThreshold: () => DEFAULT_TRUNCATE_TOOL_OUTPUT_THRESHOLD,
|
|
229
|
+
getTruncateToolOutputLines: () => DEFAULT_TRUNCATE_TOOL_OUTPUT_LINES,
|
|
230
|
+
getToolRegistry: () => mockToolRegistry,
|
|
231
|
+
getUseSmartEdit: () => false,
|
|
232
|
+
getUseModelRouter: () => false,
|
|
233
|
+
getGeminiClient: () => null,
|
|
234
|
+
};
|
|
235
|
+
const scheduler = new CoreToolScheduler({
|
|
236
|
+
config: mockConfig,
|
|
237
|
+
onAllToolCallsComplete,
|
|
238
|
+
onToolCallsUpdate,
|
|
239
|
+
getPreferredEditor: () => 'vscode',
|
|
240
|
+
onEditorClose: vi.fn(),
|
|
241
|
+
});
|
|
242
|
+
const request = {
|
|
243
|
+
callId: 'abort-1',
|
|
244
|
+
name: 'abortDuringConfirmationTool',
|
|
245
|
+
args: {},
|
|
246
|
+
isClientInitiated: false,
|
|
247
|
+
prompt_id: 'prompt-id-abort',
|
|
248
|
+
};
|
|
249
|
+
await scheduler.schedule([request], abortController.signal);
|
|
250
|
+
expect(onAllToolCallsComplete).toHaveBeenCalled();
|
|
251
|
+
const completedCalls = onAllToolCallsComplete.mock
|
|
252
|
+
.calls[0][0];
|
|
253
|
+
expect(completedCalls[0].status).toBe('cancelled');
|
|
254
|
+
const statuses = onToolCallsUpdate.mock.calls.flatMap((call) => call[0].map((toolCall) => toolCall.status));
|
|
255
|
+
expect(statuses).not.toContain('error');
|
|
256
|
+
});
|
|
257
|
+
describe('getToolSuggestion', () => {
|
|
258
|
+
it('should suggest the top N closest tool names for a typo', () => {
|
|
259
|
+
// Create mocked tool registry
|
|
260
|
+
const mockConfig = {
|
|
261
|
+
getToolRegistry: () => mockToolRegistry,
|
|
262
|
+
getUseSmartEdit: () => false,
|
|
263
|
+
getUseModelRouter: () => false,
|
|
264
|
+
getGeminiClient: () => null, // No client needed for these tests
|
|
265
|
+
getExcludeTools: () => undefined,
|
|
266
|
+
isInteractive: () => true,
|
|
267
|
+
};
|
|
268
|
+
const mockToolRegistry = {
|
|
269
|
+
getAllToolNames: () => ['list_files', 'read_file', 'write_file'],
|
|
270
|
+
};
|
|
271
|
+
// Create scheduler
|
|
272
|
+
const scheduler = new CoreToolScheduler({
|
|
273
|
+
config: mockConfig,
|
|
274
|
+
getPreferredEditor: () => 'vscode',
|
|
275
|
+
onEditorClose: vi.fn(),
|
|
276
|
+
});
|
|
277
|
+
// Test that the right tool is selected, with only 1 result, for typos
|
|
278
|
+
// @ts-expect-error accessing private method
|
|
279
|
+
const misspelledTool = scheduler.getToolSuggestion('list_fils', 1);
|
|
280
|
+
expect(misspelledTool).toBe(' Did you mean "list_files"?');
|
|
281
|
+
// Test that the right tool is selected, with only 1 result, for prefixes
|
|
282
|
+
// @ts-expect-error accessing private method
|
|
283
|
+
const prefixedTool = scheduler.getToolSuggestion('github.list_files', 1);
|
|
284
|
+
expect(prefixedTool).toBe(' Did you mean "list_files"?');
|
|
285
|
+
// Test that the right tool is first
|
|
286
|
+
// @ts-expect-error accessing private method
|
|
287
|
+
const suggestionMultiple = scheduler.getToolSuggestion('list_fils');
|
|
288
|
+
expect(suggestionMultiple).toBe(' Did you mean one of: "list_files", "read_file", "write_file"?');
|
|
289
|
+
});
|
|
290
|
+
it('should use Levenshtein suggestions for excluded tools (getToolSuggestion only handles non-excluded)', () => {
|
|
291
|
+
// Create mocked tool registry
|
|
292
|
+
const mockToolRegistry = {
|
|
293
|
+
getAllToolNames: () => ['list_files', 'read_file'],
|
|
294
|
+
};
|
|
295
|
+
// Create mocked config with excluded tools
|
|
296
|
+
const mockConfig = {
|
|
297
|
+
getToolRegistry: () => mockToolRegistry,
|
|
298
|
+
getUseSmartEdit: () => false,
|
|
299
|
+
getUseModelRouter: () => false,
|
|
300
|
+
getGeminiClient: () => null,
|
|
301
|
+
getExcludeTools: () => ['write_file', 'edit', 'run_shell_command'],
|
|
302
|
+
isInteractive: () => false, // Value doesn't matter, but included for completeness
|
|
303
|
+
};
|
|
304
|
+
// Create scheduler
|
|
305
|
+
const scheduler = new CoreToolScheduler({
|
|
306
|
+
config: mockConfig,
|
|
307
|
+
getPreferredEditor: () => 'vscode',
|
|
308
|
+
onEditorClose: vi.fn(),
|
|
309
|
+
});
|
|
310
|
+
// getToolSuggestion no longer handles excluded tools - it only handles truly missing tools
|
|
311
|
+
// So excluded tools will use Levenshtein distance to find similar registered tools
|
|
312
|
+
// @ts-expect-error accessing private method
|
|
313
|
+
const excludedTool = scheduler.getToolSuggestion('write_file');
|
|
314
|
+
expect(excludedTool).toContain('Did you mean');
|
|
315
|
+
});
|
|
316
|
+
it('should use Levenshtein suggestions for non-excluded tools', () => {
|
|
317
|
+
// Create mocked tool registry
|
|
318
|
+
const mockToolRegistry = {
|
|
319
|
+
getAllToolNames: () => ['list_files', 'read_file'],
|
|
320
|
+
};
|
|
321
|
+
// Create mocked config with excluded tools
|
|
322
|
+
const mockConfig = {
|
|
323
|
+
getToolRegistry: () => mockToolRegistry,
|
|
324
|
+
getUseSmartEdit: () => false,
|
|
325
|
+
getUseModelRouter: () => false,
|
|
326
|
+
getGeminiClient: () => null,
|
|
327
|
+
getExcludeTools: () => ['write_file', 'edit'],
|
|
328
|
+
isInteractive: () => false, // Value doesn't matter
|
|
329
|
+
};
|
|
330
|
+
// Create scheduler
|
|
331
|
+
const scheduler = new CoreToolScheduler({
|
|
332
|
+
config: mockConfig,
|
|
333
|
+
getPreferredEditor: () => 'vscode',
|
|
334
|
+
onEditorClose: vi.fn(),
|
|
335
|
+
});
|
|
336
|
+
// Test that non-excluded tool (hallucinated) still uses Levenshtein suggestions
|
|
337
|
+
// @ts-expect-error accessing private method
|
|
338
|
+
const hallucinatedTool = scheduler.getToolSuggestion('list_fils');
|
|
339
|
+
expect(hallucinatedTool).toContain('Did you mean');
|
|
340
|
+
expect(hallucinatedTool).not.toContain('not available in the current environment');
|
|
341
|
+
});
|
|
342
|
+
});
|
|
343
|
+
describe('excluded tools handling', () => {
|
|
344
|
+
it('should return permission error for excluded tools instead of "not found" message', async () => {
|
|
345
|
+
const onAllToolCallsComplete = vi.fn();
|
|
346
|
+
const onToolCallsUpdate = vi.fn();
|
|
347
|
+
const mockToolRegistry = {
|
|
348
|
+
getTool: () => undefined, // Tool not in registry
|
|
349
|
+
getAllToolNames: () => ['list_files', 'read_file'],
|
|
350
|
+
getFunctionDeclarations: () => [],
|
|
351
|
+
tools: new Map(),
|
|
352
|
+
discovery: {},
|
|
353
|
+
registerTool: () => { },
|
|
354
|
+
getToolByName: () => undefined,
|
|
355
|
+
getToolByDisplayName: () => undefined,
|
|
356
|
+
getTools: () => [],
|
|
357
|
+
discoverTools: async () => { },
|
|
358
|
+
getAllTools: () => [],
|
|
359
|
+
getToolsByServer: () => [],
|
|
360
|
+
};
|
|
361
|
+
const mockConfig = {
|
|
362
|
+
getSessionId: () => 'test-session-id',
|
|
363
|
+
getUsageStatisticsEnabled: () => true,
|
|
364
|
+
getDebugMode: () => false,
|
|
365
|
+
getApprovalMode: () => ApprovalMode.DEFAULT,
|
|
366
|
+
getAllowedTools: () => [],
|
|
367
|
+
getExcludeTools: () => ['write_file', 'edit', 'run_shell_command'],
|
|
368
|
+
getContentGeneratorConfig: () => ({
|
|
369
|
+
model: 'test-model',
|
|
370
|
+
authType: 'oauth-personal',
|
|
371
|
+
}),
|
|
372
|
+
getShellExecutionConfig: () => ({
|
|
373
|
+
terminalWidth: 90,
|
|
374
|
+
terminalHeight: 30,
|
|
375
|
+
}),
|
|
376
|
+
storage: {
|
|
377
|
+
getProjectTempDir: () => '/tmp',
|
|
378
|
+
},
|
|
379
|
+
getTruncateToolOutputThreshold: () => DEFAULT_TRUNCATE_TOOL_OUTPUT_THRESHOLD,
|
|
380
|
+
getTruncateToolOutputLines: () => DEFAULT_TRUNCATE_TOOL_OUTPUT_LINES,
|
|
381
|
+
getToolRegistry: () => mockToolRegistry,
|
|
382
|
+
getUseSmartEdit: () => false,
|
|
383
|
+
getUseModelRouter: () => false,
|
|
384
|
+
getGeminiClient: () => null,
|
|
385
|
+
};
|
|
386
|
+
const scheduler = new CoreToolScheduler({
|
|
387
|
+
config: mockConfig,
|
|
388
|
+
onAllToolCallsComplete,
|
|
389
|
+
onToolCallsUpdate,
|
|
390
|
+
getPreferredEditor: () => 'vscode',
|
|
391
|
+
onEditorClose: vi.fn(),
|
|
392
|
+
});
|
|
393
|
+
const abortController = new AbortController();
|
|
394
|
+
const request = {
|
|
395
|
+
callId: '1',
|
|
396
|
+
name: 'write_file', // Excluded tool
|
|
397
|
+
args: {},
|
|
398
|
+
isClientInitiated: false,
|
|
399
|
+
prompt_id: 'prompt-id-excluded',
|
|
400
|
+
};
|
|
401
|
+
await scheduler.schedule([request], abortController.signal);
|
|
402
|
+
// Wait for completion
|
|
403
|
+
await vi.waitFor(() => {
|
|
404
|
+
expect(onAllToolCallsComplete).toHaveBeenCalled();
|
|
405
|
+
});
|
|
406
|
+
const completedCalls = onAllToolCallsComplete.mock
|
|
407
|
+
.calls[0][0];
|
|
408
|
+
expect(completedCalls).toHaveLength(1);
|
|
409
|
+
const completedCall = completedCalls[0];
|
|
410
|
+
expect(completedCall.status).toBe('error');
|
|
411
|
+
if (completedCall.status === 'error') {
|
|
412
|
+
const errorMessage = completedCall.response.error?.message;
|
|
413
|
+
expect(errorMessage).toBe('Qwen Code requires permission to use write_file, but that permission was declined.');
|
|
414
|
+
// Should NOT contain "not found in registry"
|
|
415
|
+
expect(errorMessage).not.toContain('not found in registry');
|
|
416
|
+
}
|
|
417
|
+
});
|
|
418
|
+
it('should return "not found" message for truly missing tools (not excluded)', async () => {
|
|
419
|
+
const onAllToolCallsComplete = vi.fn();
|
|
420
|
+
const onToolCallsUpdate = vi.fn();
|
|
421
|
+
const mockToolRegistry = {
|
|
422
|
+
getTool: () => undefined, // Tool not in registry
|
|
423
|
+
getAllToolNames: () => ['list_files', 'read_file'],
|
|
424
|
+
getFunctionDeclarations: () => [],
|
|
425
|
+
tools: new Map(),
|
|
426
|
+
discovery: {},
|
|
427
|
+
registerTool: () => { },
|
|
428
|
+
getToolByName: () => undefined,
|
|
429
|
+
getToolByDisplayName: () => undefined,
|
|
430
|
+
getTools: () => [],
|
|
431
|
+
discoverTools: async () => { },
|
|
432
|
+
getAllTools: () => [],
|
|
433
|
+
getToolsByServer: () => [],
|
|
434
|
+
};
|
|
435
|
+
const mockConfig = {
|
|
436
|
+
getSessionId: () => 'test-session-id',
|
|
437
|
+
getUsageStatisticsEnabled: () => true,
|
|
438
|
+
getDebugMode: () => false,
|
|
439
|
+
getApprovalMode: () => ApprovalMode.DEFAULT,
|
|
440
|
+
getAllowedTools: () => [],
|
|
441
|
+
getExcludeTools: () => ['write_file', 'edit'], // Different excluded tools
|
|
442
|
+
getContentGeneratorConfig: () => ({
|
|
443
|
+
model: 'test-model',
|
|
444
|
+
authType: 'oauth-personal',
|
|
445
|
+
}),
|
|
446
|
+
getShellExecutionConfig: () => ({
|
|
447
|
+
terminalWidth: 90,
|
|
448
|
+
terminalHeight: 30,
|
|
449
|
+
}),
|
|
450
|
+
storage: {
|
|
451
|
+
getProjectTempDir: () => '/tmp',
|
|
452
|
+
},
|
|
453
|
+
getTruncateToolOutputThreshold: () => DEFAULT_TRUNCATE_TOOL_OUTPUT_THRESHOLD,
|
|
454
|
+
getTruncateToolOutputLines: () => DEFAULT_TRUNCATE_TOOL_OUTPUT_LINES,
|
|
455
|
+
getToolRegistry: () => mockToolRegistry,
|
|
456
|
+
getUseSmartEdit: () => false,
|
|
457
|
+
getUseModelRouter: () => false,
|
|
458
|
+
getGeminiClient: () => null,
|
|
459
|
+
};
|
|
460
|
+
const scheduler = new CoreToolScheduler({
|
|
461
|
+
config: mockConfig,
|
|
462
|
+
onAllToolCallsComplete,
|
|
463
|
+
onToolCallsUpdate,
|
|
464
|
+
getPreferredEditor: () => 'vscode',
|
|
465
|
+
onEditorClose: vi.fn(),
|
|
466
|
+
});
|
|
467
|
+
const abortController = new AbortController();
|
|
468
|
+
const request = {
|
|
469
|
+
callId: '1',
|
|
470
|
+
name: 'nonexistent_tool', // Not excluded, just doesn't exist
|
|
471
|
+
args: {},
|
|
472
|
+
isClientInitiated: false,
|
|
473
|
+
prompt_id: 'prompt-id-missing',
|
|
474
|
+
};
|
|
475
|
+
await scheduler.schedule([request], abortController.signal);
|
|
476
|
+
// Wait for completion
|
|
477
|
+
await vi.waitFor(() => {
|
|
478
|
+
expect(onAllToolCallsComplete).toHaveBeenCalled();
|
|
479
|
+
});
|
|
480
|
+
const completedCalls = onAllToolCallsComplete.mock
|
|
481
|
+
.calls[0][0];
|
|
482
|
+
expect(completedCalls).toHaveLength(1);
|
|
483
|
+
const completedCall = completedCalls[0];
|
|
484
|
+
expect(completedCall.status).toBe('error');
|
|
485
|
+
if (completedCall.status === 'error') {
|
|
486
|
+
const errorMessage = completedCall.response.error?.message;
|
|
487
|
+
// Should contain "not found in registry"
|
|
488
|
+
expect(errorMessage).toContain('not found in registry');
|
|
489
|
+
// Should NOT contain permission message
|
|
490
|
+
expect(errorMessage).not.toContain('requires permission');
|
|
491
|
+
}
|
|
492
|
+
});
|
|
493
|
+
});
|
|
494
|
+
});
|
|
495
|
+
describe('CoreToolScheduler with payload', () => {
|
|
496
|
+
it('should update args and diff and execute tool when payload is provided', async () => {
|
|
497
|
+
const mockTool = new MockModifiableTool();
|
|
498
|
+
mockTool.executeFn = vi.fn();
|
|
499
|
+
const declarativeTool = mockTool;
|
|
500
|
+
const mockToolRegistry = {
|
|
501
|
+
getTool: () => declarativeTool,
|
|
502
|
+
getFunctionDeclarations: () => [],
|
|
503
|
+
tools: new Map(),
|
|
504
|
+
discovery: {},
|
|
505
|
+
registerTool: () => { },
|
|
506
|
+
getToolByName: () => declarativeTool,
|
|
507
|
+
getToolByDisplayName: () => declarativeTool,
|
|
508
|
+
getTools: () => [],
|
|
509
|
+
discoverTools: async () => { },
|
|
510
|
+
getAllTools: () => [],
|
|
511
|
+
getToolsByServer: () => [],
|
|
512
|
+
};
|
|
513
|
+
const onAllToolCallsComplete = vi.fn();
|
|
514
|
+
const onToolCallsUpdate = vi.fn();
|
|
515
|
+
const mockConfig = {
|
|
516
|
+
getSessionId: () => 'test-session-id',
|
|
517
|
+
getUsageStatisticsEnabled: () => true,
|
|
518
|
+
getDebugMode: () => false,
|
|
519
|
+
getApprovalMode: () => ApprovalMode.DEFAULT,
|
|
520
|
+
getAllowedTools: () => [],
|
|
521
|
+
getContentGeneratorConfig: () => ({
|
|
522
|
+
model: 'test-model',
|
|
523
|
+
authType: 'oauth-personal',
|
|
524
|
+
}),
|
|
525
|
+
getShellExecutionConfig: () => ({
|
|
526
|
+
terminalWidth: 90,
|
|
527
|
+
terminalHeight: 30,
|
|
528
|
+
}),
|
|
529
|
+
storage: {
|
|
530
|
+
getProjectTempDir: () => '/tmp',
|
|
531
|
+
},
|
|
532
|
+
getTruncateToolOutputThreshold: () => DEFAULT_TRUNCATE_TOOL_OUTPUT_THRESHOLD,
|
|
533
|
+
getTruncateToolOutputLines: () => DEFAULT_TRUNCATE_TOOL_OUTPUT_LINES,
|
|
534
|
+
getToolRegistry: () => mockToolRegistry,
|
|
535
|
+
getUseSmartEdit: () => false,
|
|
536
|
+
getUseModelRouter: () => false,
|
|
537
|
+
getGeminiClient: () => null, // No client needed for these tests
|
|
538
|
+
isInteractive: () => true, // Required to prevent auto-denial of tool calls
|
|
539
|
+
getIdeMode: () => false,
|
|
540
|
+
getExperimentalZedIntegration: () => false,
|
|
541
|
+
};
|
|
542
|
+
const scheduler = new CoreToolScheduler({
|
|
543
|
+
config: mockConfig,
|
|
544
|
+
onAllToolCallsComplete,
|
|
545
|
+
onToolCallsUpdate,
|
|
546
|
+
getPreferredEditor: () => 'vscode',
|
|
547
|
+
onEditorClose: vi.fn(),
|
|
548
|
+
});
|
|
549
|
+
const abortController = new AbortController();
|
|
550
|
+
const request = {
|
|
551
|
+
callId: '1',
|
|
552
|
+
name: 'mockModifiableTool',
|
|
553
|
+
args: {},
|
|
554
|
+
isClientInitiated: false,
|
|
555
|
+
prompt_id: 'prompt-id-2',
|
|
556
|
+
};
|
|
557
|
+
await scheduler.schedule([request], abortController.signal);
|
|
558
|
+
const awaitingCall = (await waitForStatus(onToolCallsUpdate, 'awaiting_approval'));
|
|
559
|
+
const confirmationDetails = awaitingCall.confirmationDetails;
|
|
560
|
+
if (confirmationDetails) {
|
|
561
|
+
const payload = { newContent: 'final version' };
|
|
562
|
+
await confirmationDetails.onConfirm(ToolConfirmationOutcome.ProceedOnce, payload);
|
|
563
|
+
}
|
|
564
|
+
// Wait for the tool execution to complete
|
|
565
|
+
await vi.waitFor(() => {
|
|
566
|
+
expect(onAllToolCallsComplete).toHaveBeenCalled();
|
|
567
|
+
});
|
|
568
|
+
const completedCalls = onAllToolCallsComplete.mock
|
|
569
|
+
.calls[0][0];
|
|
570
|
+
expect(completedCalls[0].status).toBe('success');
|
|
571
|
+
expect(mockTool.executeFn).toHaveBeenCalledWith({
|
|
572
|
+
newContent: 'final version',
|
|
573
|
+
});
|
|
574
|
+
});
|
|
575
|
+
});
|
|
576
|
+
describe('convertToFunctionResponse', () => {
|
|
577
|
+
const toolName = 'testTool';
|
|
578
|
+
const callId = 'call1';
|
|
579
|
+
it('should handle simple string llmContent', () => {
|
|
580
|
+
const llmContent = 'Simple text output';
|
|
581
|
+
const result = convertToFunctionResponse(toolName, callId, llmContent);
|
|
582
|
+
expect(result).toEqual([
|
|
583
|
+
{
|
|
584
|
+
functionResponse: {
|
|
585
|
+
name: toolName,
|
|
586
|
+
id: callId,
|
|
587
|
+
response: { output: 'Simple text output' },
|
|
588
|
+
},
|
|
589
|
+
},
|
|
590
|
+
]);
|
|
591
|
+
});
|
|
592
|
+
it('should handle llmContent as a single Part with text', () => {
|
|
593
|
+
const llmContent = { text: 'Text from Part object' };
|
|
594
|
+
const result = convertToFunctionResponse(toolName, callId, llmContent);
|
|
595
|
+
expect(result).toEqual([
|
|
596
|
+
{
|
|
597
|
+
functionResponse: {
|
|
598
|
+
name: toolName,
|
|
599
|
+
id: callId,
|
|
600
|
+
response: { output: 'Text from Part object' },
|
|
601
|
+
},
|
|
602
|
+
},
|
|
603
|
+
]);
|
|
604
|
+
});
|
|
605
|
+
it('should handle llmContent as a PartListUnion array with a single text Part', () => {
|
|
606
|
+
const llmContent = [{ text: 'Text from array' }];
|
|
607
|
+
const result = convertToFunctionResponse(toolName, callId, llmContent);
|
|
608
|
+
expect(result).toEqual([
|
|
609
|
+
{
|
|
610
|
+
functionResponse: {
|
|
611
|
+
name: toolName,
|
|
612
|
+
id: callId,
|
|
613
|
+
response: { output: 'Text from array' },
|
|
614
|
+
},
|
|
615
|
+
},
|
|
616
|
+
]);
|
|
617
|
+
});
|
|
618
|
+
it('should handle llmContent with inlineData', () => {
|
|
619
|
+
const llmContent = {
|
|
620
|
+
inlineData: { mimeType: 'image/png', data: 'base64...' },
|
|
621
|
+
};
|
|
622
|
+
const result = convertToFunctionResponse(toolName, callId, llmContent);
|
|
623
|
+
expect(result).toEqual([
|
|
624
|
+
{
|
|
625
|
+
functionResponse: {
|
|
626
|
+
name: toolName,
|
|
627
|
+
id: callId,
|
|
628
|
+
response: {
|
|
629
|
+
output: 'Binary content of type image/png was processed.',
|
|
630
|
+
},
|
|
631
|
+
},
|
|
632
|
+
},
|
|
633
|
+
llmContent,
|
|
634
|
+
]);
|
|
635
|
+
});
|
|
636
|
+
it('should handle llmContent with fileData', () => {
|
|
637
|
+
const llmContent = {
|
|
638
|
+
fileData: { mimeType: 'application/pdf', fileUri: 'gs://...' },
|
|
639
|
+
};
|
|
640
|
+
const result = convertToFunctionResponse(toolName, callId, llmContent);
|
|
641
|
+
expect(result).toEqual([
|
|
642
|
+
{
|
|
643
|
+
functionResponse: {
|
|
644
|
+
name: toolName,
|
|
645
|
+
id: callId,
|
|
646
|
+
response: {
|
|
647
|
+
output: 'Binary content of type application/pdf was processed.',
|
|
648
|
+
},
|
|
649
|
+
},
|
|
650
|
+
},
|
|
651
|
+
llmContent,
|
|
652
|
+
]);
|
|
653
|
+
});
|
|
654
|
+
it('should handle llmContent as an array of multiple Parts (text and inlineData)', () => {
|
|
655
|
+
const llmContent = [
|
|
656
|
+
{ text: 'Some textual description' },
|
|
657
|
+
{ inlineData: { mimeType: 'image/jpeg', data: 'base64data...' } },
|
|
658
|
+
{ text: 'Another text part' },
|
|
659
|
+
];
|
|
660
|
+
const result = convertToFunctionResponse(toolName, callId, llmContent);
|
|
661
|
+
expect(result).toEqual([
|
|
662
|
+
{
|
|
663
|
+
functionResponse: {
|
|
664
|
+
name: toolName,
|
|
665
|
+
id: callId,
|
|
666
|
+
response: { output: 'Tool execution succeeded.' },
|
|
667
|
+
},
|
|
668
|
+
},
|
|
669
|
+
...llmContent,
|
|
670
|
+
]);
|
|
671
|
+
});
|
|
672
|
+
it('should handle llmContent as an array with a single inlineData Part', () => {
|
|
673
|
+
const llmContent = [
|
|
674
|
+
{ inlineData: { mimeType: 'image/gif', data: 'gifdata...' } },
|
|
675
|
+
];
|
|
676
|
+
const result = convertToFunctionResponse(toolName, callId, llmContent);
|
|
677
|
+
expect(result).toEqual([
|
|
678
|
+
{
|
|
679
|
+
functionResponse: {
|
|
680
|
+
name: toolName,
|
|
681
|
+
id: callId,
|
|
682
|
+
response: {
|
|
683
|
+
output: 'Binary content of type image/gif was processed.',
|
|
684
|
+
},
|
|
685
|
+
},
|
|
686
|
+
},
|
|
687
|
+
...llmContent,
|
|
688
|
+
]);
|
|
689
|
+
});
|
|
690
|
+
it('should handle llmContent as a generic Part (not text, inlineData, or fileData)', () => {
|
|
691
|
+
const llmContent = { functionCall: { name: 'test', args: {} } };
|
|
692
|
+
const result = convertToFunctionResponse(toolName, callId, llmContent);
|
|
693
|
+
expect(result).toEqual([
|
|
694
|
+
{
|
|
695
|
+
functionResponse: {
|
|
696
|
+
name: toolName,
|
|
697
|
+
id: callId,
|
|
698
|
+
response: { output: 'Tool execution succeeded.' },
|
|
699
|
+
},
|
|
700
|
+
},
|
|
701
|
+
]);
|
|
702
|
+
});
|
|
703
|
+
it('should handle empty string llmContent', () => {
|
|
704
|
+
const llmContent = '';
|
|
705
|
+
const result = convertToFunctionResponse(toolName, callId, llmContent);
|
|
706
|
+
expect(result).toEqual([
|
|
707
|
+
{
|
|
708
|
+
functionResponse: {
|
|
709
|
+
name: toolName,
|
|
710
|
+
id: callId,
|
|
711
|
+
response: { output: '' },
|
|
712
|
+
},
|
|
713
|
+
},
|
|
714
|
+
]);
|
|
715
|
+
});
|
|
716
|
+
it('should handle llmContent as an empty array', () => {
|
|
717
|
+
const llmContent = [];
|
|
718
|
+
const result = convertToFunctionResponse(toolName, callId, llmContent);
|
|
719
|
+
expect(result).toEqual([
|
|
720
|
+
{
|
|
721
|
+
functionResponse: {
|
|
722
|
+
name: toolName,
|
|
723
|
+
id: callId,
|
|
724
|
+
response: { output: 'Tool execution succeeded.' },
|
|
725
|
+
},
|
|
726
|
+
},
|
|
727
|
+
]);
|
|
728
|
+
});
|
|
729
|
+
it('should handle llmContent as a Part with undefined inlineData/fileData/text', () => {
|
|
730
|
+
const llmContent = {}; // An empty part object
|
|
731
|
+
const result = convertToFunctionResponse(toolName, callId, llmContent);
|
|
732
|
+
expect(result).toEqual([
|
|
733
|
+
{
|
|
734
|
+
functionResponse: {
|
|
735
|
+
name: toolName,
|
|
736
|
+
id: callId,
|
|
737
|
+
response: { output: 'Tool execution succeeded.' },
|
|
738
|
+
},
|
|
739
|
+
},
|
|
740
|
+
]);
|
|
741
|
+
});
|
|
742
|
+
});
|
|
743
|
+
class MockEditToolInvocation extends BaseToolInvocation {
|
|
744
|
+
constructor(params) {
|
|
745
|
+
super(params);
|
|
746
|
+
}
|
|
747
|
+
getDescription() {
|
|
748
|
+
return 'A mock edit tool invocation';
|
|
749
|
+
}
|
|
750
|
+
async shouldConfirmExecute(_abortSignal) {
|
|
751
|
+
return {
|
|
752
|
+
type: 'edit',
|
|
753
|
+
title: 'Confirm Edit',
|
|
754
|
+
fileName: 'test.txt',
|
|
755
|
+
filePath: 'test.txt',
|
|
756
|
+
fileDiff: '--- test.txt\n+++ test.txt\n@@ -1,1 +1,1 @@\n-old content\n+new content',
|
|
757
|
+
originalContent: 'old content',
|
|
758
|
+
newContent: 'new content',
|
|
759
|
+
onConfirm: async () => { },
|
|
760
|
+
};
|
|
761
|
+
}
|
|
762
|
+
async execute(_abortSignal) {
|
|
763
|
+
return {
|
|
764
|
+
llmContent: 'Edited successfully',
|
|
765
|
+
returnDisplay: 'Edited successfully',
|
|
766
|
+
};
|
|
767
|
+
}
|
|
768
|
+
}
|
|
769
|
+
class MockEditTool extends BaseDeclarativeTool {
|
|
770
|
+
constructor() {
|
|
771
|
+
super('mockEditTool', 'mockEditTool', 'A mock edit tool', Kind.Edit, {});
|
|
772
|
+
}
|
|
773
|
+
createInvocation(params) {
|
|
774
|
+
return new MockEditToolInvocation(params);
|
|
775
|
+
}
|
|
776
|
+
}
|
|
777
|
+
describe('CoreToolScheduler edit cancellation', () => {
|
|
778
|
+
it('should preserve diff when an edit is cancelled', async () => {
|
|
779
|
+
const mockEditTool = new MockEditTool();
|
|
780
|
+
const mockToolRegistry = {
|
|
781
|
+
getTool: () => mockEditTool,
|
|
782
|
+
getFunctionDeclarations: () => [],
|
|
783
|
+
tools: new Map(),
|
|
784
|
+
discovery: {},
|
|
785
|
+
registerTool: () => { },
|
|
786
|
+
getToolByName: () => mockEditTool,
|
|
787
|
+
getToolByDisplayName: () => mockEditTool,
|
|
788
|
+
getTools: () => [],
|
|
789
|
+
discoverTools: async () => { },
|
|
790
|
+
getAllTools: () => [],
|
|
791
|
+
getToolsByServer: () => [],
|
|
792
|
+
};
|
|
793
|
+
const onAllToolCallsComplete = vi.fn();
|
|
794
|
+
const onToolCallsUpdate = vi.fn();
|
|
795
|
+
const mockConfig = {
|
|
796
|
+
getSessionId: () => 'test-session-id',
|
|
797
|
+
getUsageStatisticsEnabled: () => true,
|
|
798
|
+
getDebugMode: () => false,
|
|
799
|
+
getApprovalMode: () => ApprovalMode.DEFAULT,
|
|
800
|
+
getAllowedTools: () => [],
|
|
801
|
+
getContentGeneratorConfig: () => ({
|
|
802
|
+
model: 'test-model',
|
|
803
|
+
authType: 'oauth-personal',
|
|
804
|
+
}),
|
|
805
|
+
getShellExecutionConfig: () => ({
|
|
806
|
+
terminalWidth: 90,
|
|
807
|
+
terminalHeight: 30,
|
|
808
|
+
}),
|
|
809
|
+
storage: {
|
|
810
|
+
getProjectTempDir: () => '/tmp',
|
|
811
|
+
},
|
|
812
|
+
getToolRegistry: () => mockToolRegistry,
|
|
813
|
+
getUseSmartEdit: () => false,
|
|
814
|
+
getUseModelRouter: () => false,
|
|
815
|
+
getGeminiClient: () => null, // No client needed for these tests
|
|
816
|
+
isInteractive: () => true, // Required to prevent auto-denial of tool calls
|
|
817
|
+
getIdeMode: () => false,
|
|
818
|
+
getExperimentalZedIntegration: () => false,
|
|
819
|
+
};
|
|
820
|
+
const scheduler = new CoreToolScheduler({
|
|
821
|
+
config: mockConfig,
|
|
822
|
+
onAllToolCallsComplete,
|
|
823
|
+
onToolCallsUpdate,
|
|
824
|
+
getPreferredEditor: () => 'vscode',
|
|
825
|
+
onEditorClose: vi.fn(),
|
|
826
|
+
});
|
|
827
|
+
const abortController = new AbortController();
|
|
828
|
+
const request = {
|
|
829
|
+
callId: '1',
|
|
830
|
+
name: 'mockEditTool',
|
|
831
|
+
args: {},
|
|
832
|
+
isClientInitiated: false,
|
|
833
|
+
prompt_id: 'prompt-id-1',
|
|
834
|
+
};
|
|
835
|
+
await scheduler.schedule([request], abortController.signal);
|
|
836
|
+
const awaitingCall = (await waitForStatus(onToolCallsUpdate, 'awaiting_approval'));
|
|
837
|
+
// Cancel the edit
|
|
838
|
+
const confirmationDetails = awaitingCall.confirmationDetails;
|
|
839
|
+
if (confirmationDetails) {
|
|
840
|
+
await confirmationDetails.onConfirm(ToolConfirmationOutcome.Cancel);
|
|
841
|
+
}
|
|
842
|
+
expect(onAllToolCallsComplete).toHaveBeenCalled();
|
|
843
|
+
const completedCalls = onAllToolCallsComplete.mock
|
|
844
|
+
.calls[0][0];
|
|
845
|
+
expect(completedCalls[0].status).toBe('cancelled');
|
|
846
|
+
// Check that the diff is preserved
|
|
847
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
848
|
+
const cancelledCall = completedCalls[0];
|
|
849
|
+
expect(cancelledCall.response.resultDisplay).toBeDefined();
|
|
850
|
+
expect(cancelledCall.response.resultDisplay.fileDiff).toBe('--- test.txt\n+++ test.txt\n@@ -1,1 +1,1 @@\n-old content\n+new content');
|
|
851
|
+
expect(cancelledCall.response.resultDisplay.fileName).toBe('test.txt');
|
|
852
|
+
});
|
|
853
|
+
});
|
|
854
|
+
describe('CoreToolScheduler YOLO mode', () => {
|
|
855
|
+
it('should execute tool requiring confirmation directly without waiting', async () => {
|
|
856
|
+
// Arrange
|
|
857
|
+
const executeFn = vi.fn().mockResolvedValue({
|
|
858
|
+
llmContent: 'Tool executed',
|
|
859
|
+
returnDisplay: 'Tool executed',
|
|
860
|
+
});
|
|
861
|
+
const mockTool = new MockTool({
|
|
862
|
+
name: 'mockTool',
|
|
863
|
+
execute: executeFn,
|
|
864
|
+
shouldConfirmExecute: MOCK_TOOL_SHOULD_CONFIRM_EXECUTE,
|
|
865
|
+
});
|
|
866
|
+
const declarativeTool = mockTool;
|
|
867
|
+
const mockToolRegistry = {
|
|
868
|
+
getTool: () => declarativeTool,
|
|
869
|
+
getToolByName: () => declarativeTool,
|
|
870
|
+
// Other properties are not needed for this test but are included for type consistency.
|
|
871
|
+
getFunctionDeclarations: () => [],
|
|
872
|
+
tools: new Map(),
|
|
873
|
+
discovery: {},
|
|
874
|
+
registerTool: () => { },
|
|
875
|
+
getToolByDisplayName: () => declarativeTool,
|
|
876
|
+
getTools: () => [],
|
|
877
|
+
discoverTools: async () => { },
|
|
878
|
+
getAllTools: () => [],
|
|
879
|
+
getToolsByServer: () => [],
|
|
880
|
+
};
|
|
881
|
+
const onAllToolCallsComplete = vi.fn();
|
|
882
|
+
const onToolCallsUpdate = vi.fn();
|
|
883
|
+
// Configure the scheduler for YOLO mode.
|
|
884
|
+
const mockConfig = {
|
|
885
|
+
getSessionId: () => 'test-session-id',
|
|
886
|
+
getUsageStatisticsEnabled: () => true,
|
|
887
|
+
getDebugMode: () => false,
|
|
888
|
+
getApprovalMode: () => ApprovalMode.YOLO,
|
|
889
|
+
getAllowedTools: () => [],
|
|
890
|
+
getContentGeneratorConfig: () => ({
|
|
891
|
+
model: 'test-model',
|
|
892
|
+
authType: 'oauth-personal',
|
|
893
|
+
}),
|
|
894
|
+
getShellExecutionConfig: () => ({
|
|
895
|
+
terminalWidth: 90,
|
|
896
|
+
terminalHeight: 30,
|
|
897
|
+
}),
|
|
898
|
+
storage: {
|
|
899
|
+
getProjectTempDir: () => '/tmp',
|
|
900
|
+
},
|
|
901
|
+
getToolRegistry: () => mockToolRegistry,
|
|
902
|
+
getTruncateToolOutputThreshold: () => DEFAULT_TRUNCATE_TOOL_OUTPUT_THRESHOLD,
|
|
903
|
+
getTruncateToolOutputLines: () => DEFAULT_TRUNCATE_TOOL_OUTPUT_LINES,
|
|
904
|
+
getUseSmartEdit: () => false,
|
|
905
|
+
getUseModelRouter: () => false,
|
|
906
|
+
getGeminiClient: () => null, // No client needed for these tests
|
|
907
|
+
};
|
|
908
|
+
const scheduler = new CoreToolScheduler({
|
|
909
|
+
config: mockConfig,
|
|
910
|
+
onAllToolCallsComplete,
|
|
911
|
+
onToolCallsUpdate,
|
|
912
|
+
getPreferredEditor: () => 'vscode',
|
|
913
|
+
onEditorClose: vi.fn(),
|
|
914
|
+
});
|
|
915
|
+
const abortController = new AbortController();
|
|
916
|
+
const request = {
|
|
917
|
+
callId: '1',
|
|
918
|
+
name: 'mockTool',
|
|
919
|
+
args: { param: 'value' },
|
|
920
|
+
isClientInitiated: false,
|
|
921
|
+
prompt_id: 'prompt-id-yolo',
|
|
922
|
+
};
|
|
923
|
+
// Act
|
|
924
|
+
await scheduler.schedule([request], abortController.signal);
|
|
925
|
+
// Wait for the tool execution to complete
|
|
926
|
+
await vi.waitFor(() => {
|
|
927
|
+
expect(onAllToolCallsComplete).toHaveBeenCalled();
|
|
928
|
+
});
|
|
929
|
+
// Assert
|
|
930
|
+
// 1. The tool's execute method was called directly.
|
|
931
|
+
expect(executeFn).toHaveBeenCalledWith({ param: 'value' });
|
|
932
|
+
// 2. The tool call status never entered 'awaiting_approval'.
|
|
933
|
+
const statusUpdates = onToolCallsUpdate.mock.calls
|
|
934
|
+
.map((call) => call[0][0]?.status)
|
|
935
|
+
.filter(Boolean);
|
|
936
|
+
expect(statusUpdates).not.toContain('awaiting_approval');
|
|
937
|
+
expect(statusUpdates).toEqual([
|
|
938
|
+
'validating',
|
|
939
|
+
'scheduled',
|
|
940
|
+
'executing',
|
|
941
|
+
'success',
|
|
942
|
+
]);
|
|
943
|
+
// 3. The final callback indicates the tool call was successful.
|
|
944
|
+
const completedCalls = onAllToolCallsComplete.mock
|
|
945
|
+
.calls[0][0];
|
|
946
|
+
expect(completedCalls).toHaveLength(1);
|
|
947
|
+
const completedCall = completedCalls[0];
|
|
948
|
+
expect(completedCall.status).toBe('success');
|
|
949
|
+
if (completedCall.status === 'success') {
|
|
950
|
+
expect(completedCall.response.resultDisplay).toBe('Tool executed');
|
|
951
|
+
}
|
|
952
|
+
});
|
|
953
|
+
});
|
|
954
|
+
describe('CoreToolScheduler cancellation during executing with live output', () => {
|
|
955
|
+
it('sets status to cancelled and preserves last output', async () => {
|
|
956
|
+
class StreamingInvocation extends BaseToolInvocation {
|
|
957
|
+
getDescription() {
|
|
958
|
+
return `Streaming tool ${this.params.id}`;
|
|
959
|
+
}
|
|
960
|
+
async execute(signal, updateOutput) {
|
|
961
|
+
updateOutput?.('hello');
|
|
962
|
+
// Wait until aborted to emulate a long-running task
|
|
963
|
+
await new Promise((resolve) => {
|
|
964
|
+
if (signal.aborted)
|
|
965
|
+
return resolve();
|
|
966
|
+
const onAbort = () => {
|
|
967
|
+
signal.removeEventListener('abort', onAbort);
|
|
968
|
+
resolve();
|
|
969
|
+
};
|
|
970
|
+
signal.addEventListener('abort', onAbort, { once: true });
|
|
971
|
+
});
|
|
972
|
+
// Return a normal (non-error) result; scheduler should still mark cancelled
|
|
973
|
+
return { llmContent: 'done', returnDisplay: 'done' };
|
|
974
|
+
}
|
|
975
|
+
}
|
|
976
|
+
class StreamingTool extends BaseDeclarativeTool {
|
|
977
|
+
constructor() {
|
|
978
|
+
super('stream-tool', 'Stream Tool', 'Emits live output and waits for abort', Kind.Other, {
|
|
979
|
+
type: 'object',
|
|
980
|
+
properties: { id: { type: 'string' } },
|
|
981
|
+
required: ['id'],
|
|
982
|
+
}, true, true);
|
|
983
|
+
}
|
|
984
|
+
createInvocation(params) {
|
|
985
|
+
return new StreamingInvocation(params);
|
|
986
|
+
}
|
|
987
|
+
}
|
|
988
|
+
const tool = new StreamingTool();
|
|
989
|
+
const mockToolRegistry = {
|
|
990
|
+
getTool: () => tool,
|
|
991
|
+
getFunctionDeclarations: () => [],
|
|
992
|
+
tools: new Map(),
|
|
993
|
+
discovery: {},
|
|
994
|
+
registerTool: () => { },
|
|
995
|
+
getToolByName: () => tool,
|
|
996
|
+
getToolByDisplayName: () => tool,
|
|
997
|
+
getTools: () => [],
|
|
998
|
+
discoverTools: async () => { },
|
|
999
|
+
getAllTools: () => [],
|
|
1000
|
+
getToolsByServer: () => [],
|
|
1001
|
+
};
|
|
1002
|
+
const onAllToolCallsComplete = vi.fn();
|
|
1003
|
+
const onToolCallsUpdate = vi.fn();
|
|
1004
|
+
const mockConfig = {
|
|
1005
|
+
getSessionId: () => 'test-session-id',
|
|
1006
|
+
getUsageStatisticsEnabled: () => true,
|
|
1007
|
+
getDebugMode: () => false,
|
|
1008
|
+
getApprovalMode: () => ApprovalMode.DEFAULT,
|
|
1009
|
+
getContentGeneratorConfig: () => ({
|
|
1010
|
+
model: 'test-model',
|
|
1011
|
+
authType: 'oauth-personal',
|
|
1012
|
+
}),
|
|
1013
|
+
getToolRegistry: () => mockToolRegistry,
|
|
1014
|
+
getShellExecutionConfig: () => ({
|
|
1015
|
+
terminalWidth: 90,
|
|
1016
|
+
terminalHeight: 30,
|
|
1017
|
+
}),
|
|
1018
|
+
};
|
|
1019
|
+
const scheduler = new CoreToolScheduler({
|
|
1020
|
+
config: mockConfig,
|
|
1021
|
+
onAllToolCallsComplete,
|
|
1022
|
+
onToolCallsUpdate,
|
|
1023
|
+
getPreferredEditor: () => 'vscode',
|
|
1024
|
+
onEditorClose: vi.fn(),
|
|
1025
|
+
});
|
|
1026
|
+
const abortController = new AbortController();
|
|
1027
|
+
const request = {
|
|
1028
|
+
callId: '1',
|
|
1029
|
+
name: 'stream-tool',
|
|
1030
|
+
args: { id: 'x' },
|
|
1031
|
+
isClientInitiated: true,
|
|
1032
|
+
prompt_id: 'prompt-stream',
|
|
1033
|
+
};
|
|
1034
|
+
const schedulePromise = scheduler.schedule([request], abortController.signal);
|
|
1035
|
+
// Wait until executing
|
|
1036
|
+
await vi.waitFor(() => {
|
|
1037
|
+
const calls = onToolCallsUpdate.mock.calls;
|
|
1038
|
+
const last = calls[calls.length - 1]?.[0][0];
|
|
1039
|
+
expect(last?.status).toBe('executing');
|
|
1040
|
+
});
|
|
1041
|
+
// Now abort
|
|
1042
|
+
abortController.abort();
|
|
1043
|
+
await schedulePromise;
|
|
1044
|
+
await vi.waitFor(() => {
|
|
1045
|
+
expect(onAllToolCallsComplete).toHaveBeenCalled();
|
|
1046
|
+
});
|
|
1047
|
+
const completedCalls = onAllToolCallsComplete.mock
|
|
1048
|
+
.calls[0][0];
|
|
1049
|
+
expect(completedCalls[0].status).toBe('cancelled');
|
|
1050
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1051
|
+
const cancelled = completedCalls[0];
|
|
1052
|
+
expect(cancelled.response.resultDisplay).toBe('hello');
|
|
1053
|
+
});
|
|
1054
|
+
});
|
|
1055
|
+
describe('CoreToolScheduler request queueing', () => {
|
|
1056
|
+
it('should queue a request if another is running', async () => {
|
|
1057
|
+
let resolveFirstCall;
|
|
1058
|
+
const firstCallPromise = new Promise((resolve) => {
|
|
1059
|
+
resolveFirstCall = resolve;
|
|
1060
|
+
});
|
|
1061
|
+
const executeFn = vi.fn().mockImplementation(() => firstCallPromise);
|
|
1062
|
+
const mockTool = new MockTool({ name: 'mockTool', execute: executeFn });
|
|
1063
|
+
const declarativeTool = mockTool;
|
|
1064
|
+
const mockToolRegistry = {
|
|
1065
|
+
getTool: () => declarativeTool,
|
|
1066
|
+
getToolByName: () => declarativeTool,
|
|
1067
|
+
getFunctionDeclarations: () => [],
|
|
1068
|
+
tools: new Map(),
|
|
1069
|
+
discovery: {},
|
|
1070
|
+
registerTool: () => { },
|
|
1071
|
+
getToolByDisplayName: () => declarativeTool,
|
|
1072
|
+
getTools: () => [],
|
|
1073
|
+
discoverTools: async () => { },
|
|
1074
|
+
getAllTools: () => [],
|
|
1075
|
+
getToolsByServer: () => [],
|
|
1076
|
+
};
|
|
1077
|
+
const onAllToolCallsComplete = vi.fn();
|
|
1078
|
+
const onToolCallsUpdate = vi.fn();
|
|
1079
|
+
const mockConfig = {
|
|
1080
|
+
getSessionId: () => 'test-session-id',
|
|
1081
|
+
getUsageStatisticsEnabled: () => true,
|
|
1082
|
+
getDebugMode: () => false,
|
|
1083
|
+
getApprovalMode: () => ApprovalMode.YOLO, // Use YOLO to avoid confirmation prompts
|
|
1084
|
+
getAllowedTools: () => [],
|
|
1085
|
+
getContentGeneratorConfig: () => ({
|
|
1086
|
+
model: 'test-model',
|
|
1087
|
+
authType: 'oauth-personal',
|
|
1088
|
+
}),
|
|
1089
|
+
getShellExecutionConfig: () => ({
|
|
1090
|
+
terminalWidth: 90,
|
|
1091
|
+
terminalHeight: 30,
|
|
1092
|
+
}),
|
|
1093
|
+
storage: {
|
|
1094
|
+
getProjectTempDir: () => '/tmp',
|
|
1095
|
+
},
|
|
1096
|
+
getTruncateToolOutputThreshold: () => DEFAULT_TRUNCATE_TOOL_OUTPUT_THRESHOLD,
|
|
1097
|
+
getTruncateToolOutputLines: () => DEFAULT_TRUNCATE_TOOL_OUTPUT_LINES,
|
|
1098
|
+
getToolRegistry: () => mockToolRegistry,
|
|
1099
|
+
getUseSmartEdit: () => false,
|
|
1100
|
+
getUseModelRouter: () => false,
|
|
1101
|
+
getGeminiClient: () => null, // No client needed for these tests
|
|
1102
|
+
};
|
|
1103
|
+
const scheduler = new CoreToolScheduler({
|
|
1104
|
+
config: mockConfig,
|
|
1105
|
+
onAllToolCallsComplete,
|
|
1106
|
+
onToolCallsUpdate,
|
|
1107
|
+
getPreferredEditor: () => 'vscode',
|
|
1108
|
+
onEditorClose: vi.fn(),
|
|
1109
|
+
});
|
|
1110
|
+
const abortController = new AbortController();
|
|
1111
|
+
const request1 = {
|
|
1112
|
+
callId: '1',
|
|
1113
|
+
name: 'mockTool',
|
|
1114
|
+
args: { a: 1 },
|
|
1115
|
+
isClientInitiated: false,
|
|
1116
|
+
prompt_id: 'prompt-1',
|
|
1117
|
+
};
|
|
1118
|
+
const request2 = {
|
|
1119
|
+
callId: '2',
|
|
1120
|
+
name: 'mockTool',
|
|
1121
|
+
args: { b: 2 },
|
|
1122
|
+
isClientInitiated: false,
|
|
1123
|
+
prompt_id: 'prompt-2',
|
|
1124
|
+
};
|
|
1125
|
+
// Schedule the first call, which will pause execution.
|
|
1126
|
+
scheduler.schedule([request1], abortController.signal);
|
|
1127
|
+
// Wait for the first call to be in the 'executing' state.
|
|
1128
|
+
await waitForStatus(onToolCallsUpdate, 'executing');
|
|
1129
|
+
// Schedule the second call while the first is "running".
|
|
1130
|
+
const schedulePromise2 = scheduler.schedule([request2], abortController.signal);
|
|
1131
|
+
// Ensure the second tool call hasn't been executed yet.
|
|
1132
|
+
expect(executeFn).toHaveBeenCalledWith({ a: 1 });
|
|
1133
|
+
// Complete the first tool call.
|
|
1134
|
+
resolveFirstCall({
|
|
1135
|
+
llmContent: 'First call complete',
|
|
1136
|
+
returnDisplay: 'First call complete',
|
|
1137
|
+
});
|
|
1138
|
+
// Wait for the second schedule promise to resolve.
|
|
1139
|
+
await schedulePromise2;
|
|
1140
|
+
// Let the second call finish.
|
|
1141
|
+
const secondCallResult = {
|
|
1142
|
+
llmContent: 'Second call complete',
|
|
1143
|
+
returnDisplay: 'Second call complete',
|
|
1144
|
+
};
|
|
1145
|
+
// Since the mock is shared, we need to resolve the current promise.
|
|
1146
|
+
// In a real scenario, a new promise would be created for the second call.
|
|
1147
|
+
resolveFirstCall(secondCallResult);
|
|
1148
|
+
await vi.waitFor(() => {
|
|
1149
|
+
// Now the second tool call should have been executed.
|
|
1150
|
+
expect(executeFn).toHaveBeenCalledTimes(2);
|
|
1151
|
+
});
|
|
1152
|
+
expect(executeFn).toHaveBeenCalledWith({ b: 2 });
|
|
1153
|
+
// Wait for the second completion.
|
|
1154
|
+
await vi.waitFor(() => {
|
|
1155
|
+
expect(onAllToolCallsComplete).toHaveBeenCalledTimes(2);
|
|
1156
|
+
});
|
|
1157
|
+
// Verify the completion callbacks were called correctly.
|
|
1158
|
+
expect(onAllToolCallsComplete.mock.calls[0][0][0].status).toBe('success');
|
|
1159
|
+
expect(onAllToolCallsComplete.mock.calls[1][0][0].status).toBe('success');
|
|
1160
|
+
});
|
|
1161
|
+
it('should auto-approve a tool call if it is on the allowedTools list', async () => {
|
|
1162
|
+
// Arrange
|
|
1163
|
+
const executeFn = vi.fn().mockResolvedValue({
|
|
1164
|
+
llmContent: 'Tool executed',
|
|
1165
|
+
returnDisplay: 'Tool executed',
|
|
1166
|
+
});
|
|
1167
|
+
const mockTool = new MockTool({
|
|
1168
|
+
name: 'mockTool',
|
|
1169
|
+
execute: executeFn,
|
|
1170
|
+
shouldConfirmExecute: MOCK_TOOL_SHOULD_CONFIRM_EXECUTE,
|
|
1171
|
+
});
|
|
1172
|
+
const declarativeTool = mockTool;
|
|
1173
|
+
const toolRegistry = {
|
|
1174
|
+
getTool: () => declarativeTool,
|
|
1175
|
+
getToolByName: () => declarativeTool,
|
|
1176
|
+
getFunctionDeclarations: () => [],
|
|
1177
|
+
tools: new Map(),
|
|
1178
|
+
discovery: {},
|
|
1179
|
+
registerTool: () => { },
|
|
1180
|
+
getToolByDisplayName: () => declarativeTool,
|
|
1181
|
+
getTools: () => [],
|
|
1182
|
+
discoverTools: async () => { },
|
|
1183
|
+
getAllTools: () => [],
|
|
1184
|
+
getToolsByServer: () => [],
|
|
1185
|
+
};
|
|
1186
|
+
const onAllToolCallsComplete = vi.fn();
|
|
1187
|
+
const onToolCallsUpdate = vi.fn();
|
|
1188
|
+
// Configure the scheduler to auto-approve the specific tool call.
|
|
1189
|
+
const mockConfig = {
|
|
1190
|
+
getSessionId: () => 'test-session-id',
|
|
1191
|
+
getUsageStatisticsEnabled: () => true,
|
|
1192
|
+
getDebugMode: () => false,
|
|
1193
|
+
getApprovalMode: () => ApprovalMode.DEFAULT, // Not YOLO mode
|
|
1194
|
+
getAllowedTools: () => ['mockTool'], // Auto-approve this tool
|
|
1195
|
+
getToolRegistry: () => toolRegistry,
|
|
1196
|
+
getContentGeneratorConfig: () => ({
|
|
1197
|
+
model: 'test-model',
|
|
1198
|
+
authType: 'oauth-personal',
|
|
1199
|
+
}),
|
|
1200
|
+
getShellExecutionConfig: () => ({
|
|
1201
|
+
terminalWidth: 80,
|
|
1202
|
+
terminalHeight: 24,
|
|
1203
|
+
}),
|
|
1204
|
+
getTerminalWidth: vi.fn(() => 80),
|
|
1205
|
+
getTerminalHeight: vi.fn(() => 24),
|
|
1206
|
+
storage: {
|
|
1207
|
+
getProjectTempDir: () => '/tmp',
|
|
1208
|
+
},
|
|
1209
|
+
getTruncateToolOutputThreshold: () => DEFAULT_TRUNCATE_TOOL_OUTPUT_THRESHOLD,
|
|
1210
|
+
getTruncateToolOutputLines: () => DEFAULT_TRUNCATE_TOOL_OUTPUT_LINES,
|
|
1211
|
+
getUseSmartEdit: () => false,
|
|
1212
|
+
getUseModelRouter: () => false,
|
|
1213
|
+
getGeminiClient: () => null, // No client needed for these tests
|
|
1214
|
+
};
|
|
1215
|
+
const scheduler = new CoreToolScheduler({
|
|
1216
|
+
config: mockConfig,
|
|
1217
|
+
onAllToolCallsComplete,
|
|
1218
|
+
onToolCallsUpdate,
|
|
1219
|
+
getPreferredEditor: () => 'vscode',
|
|
1220
|
+
onEditorClose: vi.fn(),
|
|
1221
|
+
});
|
|
1222
|
+
const abortController = new AbortController();
|
|
1223
|
+
const request = {
|
|
1224
|
+
callId: '1',
|
|
1225
|
+
name: 'mockTool',
|
|
1226
|
+
args: { param: 'value' },
|
|
1227
|
+
isClientInitiated: false,
|
|
1228
|
+
prompt_id: 'prompt-auto-approved',
|
|
1229
|
+
};
|
|
1230
|
+
// Act
|
|
1231
|
+
await scheduler.schedule([request], abortController.signal);
|
|
1232
|
+
// Wait for the tool execution to complete
|
|
1233
|
+
await vi.waitFor(() => {
|
|
1234
|
+
expect(onAllToolCallsComplete).toHaveBeenCalled();
|
|
1235
|
+
});
|
|
1236
|
+
// Assert
|
|
1237
|
+
// 1. The tool's execute method was called directly.
|
|
1238
|
+
expect(executeFn).toHaveBeenCalledWith({ param: 'value' });
|
|
1239
|
+
// 2. The tool call status never entered 'awaiting_approval'.
|
|
1240
|
+
const statusUpdates = onToolCallsUpdate.mock.calls
|
|
1241
|
+
.map((call) => call[0][0]?.status)
|
|
1242
|
+
.filter(Boolean);
|
|
1243
|
+
expect(statusUpdates).not.toContain('awaiting_approval');
|
|
1244
|
+
expect(statusUpdates).toEqual([
|
|
1245
|
+
'validating',
|
|
1246
|
+
'scheduled',
|
|
1247
|
+
'executing',
|
|
1248
|
+
'success',
|
|
1249
|
+
]);
|
|
1250
|
+
// 3. The final callback indicates the tool call was successful.
|
|
1251
|
+
expect(onAllToolCallsComplete).toHaveBeenCalled();
|
|
1252
|
+
const completedCalls = onAllToolCallsComplete.mock
|
|
1253
|
+
.calls[0][0];
|
|
1254
|
+
expect(completedCalls).toHaveLength(1);
|
|
1255
|
+
const completedCall = completedCalls[0];
|
|
1256
|
+
expect(completedCall.status).toBe('success');
|
|
1257
|
+
if (completedCall.status === 'success') {
|
|
1258
|
+
expect(completedCall.response.resultDisplay).toBe('Tool executed');
|
|
1259
|
+
}
|
|
1260
|
+
});
|
|
1261
|
+
it('should handle two synchronous calls to schedule', async () => {
|
|
1262
|
+
const executeFn = vi.fn().mockResolvedValue({
|
|
1263
|
+
llmContent: 'Tool executed',
|
|
1264
|
+
returnDisplay: 'Tool executed',
|
|
1265
|
+
});
|
|
1266
|
+
const mockTool = new MockTool({ name: 'mockTool', execute: executeFn });
|
|
1267
|
+
const declarativeTool = mockTool;
|
|
1268
|
+
const mockToolRegistry = {
|
|
1269
|
+
getTool: () => declarativeTool,
|
|
1270
|
+
getToolByName: () => declarativeTool,
|
|
1271
|
+
getFunctionDeclarations: () => [],
|
|
1272
|
+
tools: new Map(),
|
|
1273
|
+
discovery: {},
|
|
1274
|
+
registerTool: () => { },
|
|
1275
|
+
getToolByDisplayName: () => declarativeTool,
|
|
1276
|
+
getTools: () => [],
|
|
1277
|
+
discoverTools: async () => { },
|
|
1278
|
+
getAllTools: () => [],
|
|
1279
|
+
getToolsByServer: () => [],
|
|
1280
|
+
};
|
|
1281
|
+
const onAllToolCallsComplete = vi.fn();
|
|
1282
|
+
const onToolCallsUpdate = vi.fn();
|
|
1283
|
+
const mockConfig = {
|
|
1284
|
+
getSessionId: () => 'test-session-id',
|
|
1285
|
+
getUsageStatisticsEnabled: () => true,
|
|
1286
|
+
getDebugMode: () => false,
|
|
1287
|
+
getApprovalMode: () => ApprovalMode.YOLO,
|
|
1288
|
+
getAllowedTools: () => [],
|
|
1289
|
+
getContentGeneratorConfig: () => ({
|
|
1290
|
+
model: 'test-model',
|
|
1291
|
+
authType: 'oauth-personal',
|
|
1292
|
+
}),
|
|
1293
|
+
getShellExecutionConfig: () => ({
|
|
1294
|
+
terminalWidth: 90,
|
|
1295
|
+
terminalHeight: 30,
|
|
1296
|
+
}),
|
|
1297
|
+
storage: {
|
|
1298
|
+
getProjectTempDir: () => '/tmp',
|
|
1299
|
+
},
|
|
1300
|
+
getTruncateToolOutputThreshold: () => DEFAULT_TRUNCATE_TOOL_OUTPUT_THRESHOLD,
|
|
1301
|
+
getTruncateToolOutputLines: () => DEFAULT_TRUNCATE_TOOL_OUTPUT_LINES,
|
|
1302
|
+
getToolRegistry: () => mockToolRegistry,
|
|
1303
|
+
getUseSmartEdit: () => false,
|
|
1304
|
+
getUseModelRouter: () => false,
|
|
1305
|
+
getGeminiClient: () => null, // No client needed for these tests
|
|
1306
|
+
};
|
|
1307
|
+
const scheduler = new CoreToolScheduler({
|
|
1308
|
+
config: mockConfig,
|
|
1309
|
+
onAllToolCallsComplete,
|
|
1310
|
+
onToolCallsUpdate,
|
|
1311
|
+
getPreferredEditor: () => 'vscode',
|
|
1312
|
+
onEditorClose: vi.fn(),
|
|
1313
|
+
});
|
|
1314
|
+
const abortController = new AbortController();
|
|
1315
|
+
const request1 = {
|
|
1316
|
+
callId: '1',
|
|
1317
|
+
name: 'mockTool',
|
|
1318
|
+
args: { a: 1 },
|
|
1319
|
+
isClientInitiated: false,
|
|
1320
|
+
prompt_id: 'prompt-1',
|
|
1321
|
+
};
|
|
1322
|
+
const request2 = {
|
|
1323
|
+
callId: '2',
|
|
1324
|
+
name: 'mockTool',
|
|
1325
|
+
args: { b: 2 },
|
|
1326
|
+
isClientInitiated: false,
|
|
1327
|
+
prompt_id: 'prompt-2',
|
|
1328
|
+
};
|
|
1329
|
+
// Schedule two calls synchronously.
|
|
1330
|
+
const schedulePromise1 = scheduler.schedule([request1], abortController.signal);
|
|
1331
|
+
const schedulePromise2 = scheduler.schedule([request2], abortController.signal);
|
|
1332
|
+
// Wait for both promises to resolve.
|
|
1333
|
+
await Promise.all([schedulePromise1, schedulePromise2]);
|
|
1334
|
+
// Ensure the tool was called twice with the correct arguments.
|
|
1335
|
+
expect(executeFn).toHaveBeenCalledTimes(2);
|
|
1336
|
+
expect(executeFn).toHaveBeenCalledWith({ a: 1 });
|
|
1337
|
+
expect(executeFn).toHaveBeenCalledWith({ b: 2 });
|
|
1338
|
+
// Ensure completion callbacks were called twice.
|
|
1339
|
+
expect(onAllToolCallsComplete).toHaveBeenCalledTimes(2);
|
|
1340
|
+
});
|
|
1341
|
+
it('should auto-approve remaining tool calls when first tool call is approved with ProceedAlways', async () => {
|
|
1342
|
+
let approvalMode = ApprovalMode.DEFAULT;
|
|
1343
|
+
const mockConfig = {
|
|
1344
|
+
getSessionId: () => 'test-session-id',
|
|
1345
|
+
getUsageStatisticsEnabled: () => true,
|
|
1346
|
+
getDebugMode: () => false,
|
|
1347
|
+
getApprovalMode: () => approvalMode,
|
|
1348
|
+
getAllowedTools: () => [],
|
|
1349
|
+
setApprovalMode: (mode) => {
|
|
1350
|
+
approvalMode = mode;
|
|
1351
|
+
},
|
|
1352
|
+
getShellExecutionConfig: () => ({
|
|
1353
|
+
terminalWidth: 90,
|
|
1354
|
+
terminalHeight: 30,
|
|
1355
|
+
}),
|
|
1356
|
+
storage: {
|
|
1357
|
+
getProjectTempDir: () => '/tmp',
|
|
1358
|
+
},
|
|
1359
|
+
getTruncateToolOutputThreshold: () => DEFAULT_TRUNCATE_TOOL_OUTPUT_THRESHOLD,
|
|
1360
|
+
getTruncateToolOutputLines: () => DEFAULT_TRUNCATE_TOOL_OUTPUT_LINES,
|
|
1361
|
+
getUseSmartEdit: () => false,
|
|
1362
|
+
getUseModelRouter: () => false,
|
|
1363
|
+
getGeminiClient: () => null, // No client needed for these tests
|
|
1364
|
+
isInteractive: () => true, // Required to prevent auto-denial of tool calls
|
|
1365
|
+
getIdeMode: () => false,
|
|
1366
|
+
getExperimentalZedIntegration: () => false,
|
|
1367
|
+
};
|
|
1368
|
+
const testTool = new TestApprovalTool(mockConfig);
|
|
1369
|
+
const toolRegistry = {
|
|
1370
|
+
getTool: () => testTool,
|
|
1371
|
+
getFunctionDeclarations: () => [],
|
|
1372
|
+
getFunctionDeclarationsFiltered: () => [],
|
|
1373
|
+
registerTool: () => { },
|
|
1374
|
+
discoverAllTools: async () => { },
|
|
1375
|
+
discoverMcpTools: async () => { },
|
|
1376
|
+
discoverToolsForServer: async () => { },
|
|
1377
|
+
removeMcpToolsByServer: () => { },
|
|
1378
|
+
getAllTools: () => [],
|
|
1379
|
+
getToolsByServer: () => [],
|
|
1380
|
+
tools: new Map(),
|
|
1381
|
+
config: mockConfig,
|
|
1382
|
+
mcpClientManager: undefined,
|
|
1383
|
+
getToolByName: () => testTool,
|
|
1384
|
+
getToolByDisplayName: () => testTool,
|
|
1385
|
+
getTools: () => [],
|
|
1386
|
+
discoverTools: async () => { },
|
|
1387
|
+
discovery: {},
|
|
1388
|
+
};
|
|
1389
|
+
mockConfig.getToolRegistry = () => toolRegistry;
|
|
1390
|
+
const onAllToolCallsComplete = vi.fn();
|
|
1391
|
+
const onToolCallsUpdate = vi.fn();
|
|
1392
|
+
const pendingConfirmations = [];
|
|
1393
|
+
const scheduler = new CoreToolScheduler({
|
|
1394
|
+
config: mockConfig,
|
|
1395
|
+
onAllToolCallsComplete,
|
|
1396
|
+
onToolCallsUpdate: (toolCalls) => {
|
|
1397
|
+
onToolCallsUpdate(toolCalls);
|
|
1398
|
+
// Capture confirmation handlers for awaiting_approval tools
|
|
1399
|
+
toolCalls.forEach((call) => {
|
|
1400
|
+
if (call.status === 'awaiting_approval') {
|
|
1401
|
+
const waitingCall = call;
|
|
1402
|
+
if (waitingCall.confirmationDetails?.onConfirm) {
|
|
1403
|
+
const originalHandler = pendingConfirmations.find((h) => h === waitingCall.confirmationDetails.onConfirm);
|
|
1404
|
+
if (!originalHandler) {
|
|
1405
|
+
pendingConfirmations.push(waitingCall.confirmationDetails.onConfirm);
|
|
1406
|
+
}
|
|
1407
|
+
}
|
|
1408
|
+
}
|
|
1409
|
+
});
|
|
1410
|
+
},
|
|
1411
|
+
getPreferredEditor: () => 'vscode',
|
|
1412
|
+
onEditorClose: vi.fn(),
|
|
1413
|
+
});
|
|
1414
|
+
const abortController = new AbortController();
|
|
1415
|
+
// Schedule multiple tools that need confirmation
|
|
1416
|
+
const requests = [
|
|
1417
|
+
{
|
|
1418
|
+
callId: '1',
|
|
1419
|
+
name: 'testApprovalTool',
|
|
1420
|
+
args: { id: 'first' },
|
|
1421
|
+
isClientInitiated: false,
|
|
1422
|
+
prompt_id: 'prompt-1',
|
|
1423
|
+
},
|
|
1424
|
+
{
|
|
1425
|
+
callId: '2',
|
|
1426
|
+
name: 'testApprovalTool',
|
|
1427
|
+
args: { id: 'second' },
|
|
1428
|
+
isClientInitiated: false,
|
|
1429
|
+
prompt_id: 'prompt-2',
|
|
1430
|
+
},
|
|
1431
|
+
{
|
|
1432
|
+
callId: '3',
|
|
1433
|
+
name: 'testApprovalTool',
|
|
1434
|
+
args: { id: 'third' },
|
|
1435
|
+
isClientInitiated: false,
|
|
1436
|
+
prompt_id: 'prompt-3',
|
|
1437
|
+
},
|
|
1438
|
+
];
|
|
1439
|
+
await scheduler.schedule(requests, abortController.signal);
|
|
1440
|
+
// Wait for all tools to be awaiting approval
|
|
1441
|
+
await vi.waitFor(() => {
|
|
1442
|
+
const calls = onToolCallsUpdate.mock.calls.at(-1)?.[0];
|
|
1443
|
+
expect(calls?.length).toBe(3);
|
|
1444
|
+
expect(calls?.every((call) => call.status === 'awaiting_approval')).toBe(true);
|
|
1445
|
+
});
|
|
1446
|
+
expect(pendingConfirmations.length).toBe(3);
|
|
1447
|
+
// Approve the first tool with ProceedAlways
|
|
1448
|
+
const firstConfirmation = pendingConfirmations[0];
|
|
1449
|
+
await firstConfirmation(ToolConfirmationOutcome.ProceedAlways);
|
|
1450
|
+
// Wait for all tools to be completed
|
|
1451
|
+
await vi.waitFor(() => {
|
|
1452
|
+
expect(onAllToolCallsComplete).toHaveBeenCalled();
|
|
1453
|
+
const completedCalls = onAllToolCallsComplete.mock.calls.at(-1)?.[0];
|
|
1454
|
+
expect(completedCalls?.length).toBe(3);
|
|
1455
|
+
expect(completedCalls?.every((call) => call.status === 'success')).toBe(true);
|
|
1456
|
+
});
|
|
1457
|
+
// Verify approval mode was changed
|
|
1458
|
+
expect(approvalMode).toBe(ApprovalMode.AUTO_EDIT);
|
|
1459
|
+
});
|
|
1460
|
+
});
|
|
1461
|
+
describe('CoreToolScheduler Sequential Execution', () => {
|
|
1462
|
+
it('should execute tool calls in a batch sequentially', async () => {
|
|
1463
|
+
// Arrange
|
|
1464
|
+
let firstCallFinished = false;
|
|
1465
|
+
const executeFn = vi
|
|
1466
|
+
.fn()
|
|
1467
|
+
.mockImplementation(async (args) => {
|
|
1468
|
+
if (args.call === 1) {
|
|
1469
|
+
// First call, wait for a bit to simulate work
|
|
1470
|
+
await new Promise((resolve) => setTimeout(resolve, 50));
|
|
1471
|
+
firstCallFinished = true;
|
|
1472
|
+
return { llmContent: 'First call done' };
|
|
1473
|
+
}
|
|
1474
|
+
if (args.call === 2) {
|
|
1475
|
+
// Second call, should only happen after the first is finished
|
|
1476
|
+
if (!firstCallFinished) {
|
|
1477
|
+
throw new Error('Second tool call started before the first one finished!');
|
|
1478
|
+
}
|
|
1479
|
+
return { llmContent: 'Second call done' };
|
|
1480
|
+
}
|
|
1481
|
+
return { llmContent: 'default' };
|
|
1482
|
+
});
|
|
1483
|
+
const mockTool = new MockTool({ name: 'mockTool', execute: executeFn });
|
|
1484
|
+
const declarativeTool = mockTool;
|
|
1485
|
+
const mockToolRegistry = {
|
|
1486
|
+
getTool: () => declarativeTool,
|
|
1487
|
+
getToolByName: () => declarativeTool,
|
|
1488
|
+
getFunctionDeclarations: () => [],
|
|
1489
|
+
tools: new Map(),
|
|
1490
|
+
discovery: {},
|
|
1491
|
+
registerTool: () => { },
|
|
1492
|
+
getToolByDisplayName: () => declarativeTool,
|
|
1493
|
+
getTools: () => [],
|
|
1494
|
+
discoverTools: async () => { },
|
|
1495
|
+
getAllTools: () => [],
|
|
1496
|
+
getToolsByServer: () => [],
|
|
1497
|
+
};
|
|
1498
|
+
const onAllToolCallsComplete = vi.fn();
|
|
1499
|
+
const onToolCallsUpdate = vi.fn();
|
|
1500
|
+
const mockConfig = {
|
|
1501
|
+
getSessionId: () => 'test-session-id',
|
|
1502
|
+
getUsageStatisticsEnabled: () => true,
|
|
1503
|
+
getDebugMode: () => false,
|
|
1504
|
+
getApprovalMode: () => ApprovalMode.YOLO, // Use YOLO to avoid confirmation prompts
|
|
1505
|
+
getAllowedTools: () => [],
|
|
1506
|
+
getContentGeneratorConfig: () => ({
|
|
1507
|
+
model: 'test-model',
|
|
1508
|
+
authType: 'oauth-personal',
|
|
1509
|
+
}),
|
|
1510
|
+
getShellExecutionConfig: () => ({
|
|
1511
|
+
terminalWidth: 90,
|
|
1512
|
+
terminalHeight: 30,
|
|
1513
|
+
}),
|
|
1514
|
+
storage: {
|
|
1515
|
+
getProjectTempDir: () => '/tmp',
|
|
1516
|
+
},
|
|
1517
|
+
getToolRegistry: () => mockToolRegistry,
|
|
1518
|
+
getTruncateToolOutputThreshold: () => DEFAULT_TRUNCATE_TOOL_OUTPUT_THRESHOLD,
|
|
1519
|
+
getTruncateToolOutputLines: () => DEFAULT_TRUNCATE_TOOL_OUTPUT_LINES,
|
|
1520
|
+
getUseSmartEdit: () => false,
|
|
1521
|
+
getUseModelRouter: () => false,
|
|
1522
|
+
getGeminiClient: () => null,
|
|
1523
|
+
};
|
|
1524
|
+
const scheduler = new CoreToolScheduler({
|
|
1525
|
+
config: mockConfig,
|
|
1526
|
+
onAllToolCallsComplete,
|
|
1527
|
+
onToolCallsUpdate,
|
|
1528
|
+
getPreferredEditor: () => 'vscode',
|
|
1529
|
+
onEditorClose: vi.fn(),
|
|
1530
|
+
});
|
|
1531
|
+
const abortController = new AbortController();
|
|
1532
|
+
const requests = [
|
|
1533
|
+
{
|
|
1534
|
+
callId: '1',
|
|
1535
|
+
name: 'mockTool',
|
|
1536
|
+
args: { call: 1 },
|
|
1537
|
+
isClientInitiated: false,
|
|
1538
|
+
prompt_id: 'prompt-1',
|
|
1539
|
+
},
|
|
1540
|
+
{
|
|
1541
|
+
callId: '2',
|
|
1542
|
+
name: 'mockTool',
|
|
1543
|
+
args: { call: 2 },
|
|
1544
|
+
isClientInitiated: false,
|
|
1545
|
+
prompt_id: 'prompt-1',
|
|
1546
|
+
},
|
|
1547
|
+
];
|
|
1548
|
+
// Act
|
|
1549
|
+
await scheduler.schedule(requests, abortController.signal);
|
|
1550
|
+
// Assert
|
|
1551
|
+
await vi.waitFor(() => {
|
|
1552
|
+
expect(onAllToolCallsComplete).toHaveBeenCalled();
|
|
1553
|
+
});
|
|
1554
|
+
// Check that execute was called twice
|
|
1555
|
+
expect(executeFn).toHaveBeenCalledTimes(2);
|
|
1556
|
+
// Check the order of calls
|
|
1557
|
+
const calls = executeFn.mock.calls;
|
|
1558
|
+
expect(calls[0][0]).toEqual({ call: 1 });
|
|
1559
|
+
expect(calls[1][0]).toEqual({ call: 2 });
|
|
1560
|
+
// The onAllToolCallsComplete should be called once with both results
|
|
1561
|
+
const completedCalls = onAllToolCallsComplete.mock
|
|
1562
|
+
.calls[0][0];
|
|
1563
|
+
expect(completedCalls).toHaveLength(2);
|
|
1564
|
+
expect(completedCalls[0].status).toBe('success');
|
|
1565
|
+
expect(completedCalls[1].status).toBe('success');
|
|
1566
|
+
});
|
|
1567
|
+
it('should cancel subsequent tools when the signal is aborted.', async () => {
|
|
1568
|
+
// Arrange
|
|
1569
|
+
const abortController = new AbortController();
|
|
1570
|
+
let secondCallStarted = false;
|
|
1571
|
+
const executeFn = vi
|
|
1572
|
+
.fn()
|
|
1573
|
+
.mockImplementation(async (args) => {
|
|
1574
|
+
if (args.call === 1) {
|
|
1575
|
+
return { llmContent: 'First call done' };
|
|
1576
|
+
}
|
|
1577
|
+
if (args.call === 2) {
|
|
1578
|
+
secondCallStarted = true;
|
|
1579
|
+
// This call will be cancelled while it's "running".
|
|
1580
|
+
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
1581
|
+
// It should not return a value because it will be cancelled.
|
|
1582
|
+
return { llmContent: 'Second call should not complete' };
|
|
1583
|
+
}
|
|
1584
|
+
if (args.call === 3) {
|
|
1585
|
+
return { llmContent: 'Third call done' };
|
|
1586
|
+
}
|
|
1587
|
+
return { llmContent: 'default' };
|
|
1588
|
+
});
|
|
1589
|
+
const mockTool = new MockTool({ name: 'mockTool', execute: executeFn });
|
|
1590
|
+
const declarativeTool = mockTool;
|
|
1591
|
+
const mockToolRegistry = {
|
|
1592
|
+
getTool: () => declarativeTool,
|
|
1593
|
+
getToolByName: () => declarativeTool,
|
|
1594
|
+
getFunctionDeclarations: () => [],
|
|
1595
|
+
tools: new Map(),
|
|
1596
|
+
discovery: {},
|
|
1597
|
+
registerTool: () => { },
|
|
1598
|
+
getToolByDisplayName: () => declarativeTool,
|
|
1599
|
+
getTools: () => [],
|
|
1600
|
+
discoverTools: async () => { },
|
|
1601
|
+
getAllTools: () => [],
|
|
1602
|
+
getToolsByServer: () => [],
|
|
1603
|
+
};
|
|
1604
|
+
const onAllToolCallsComplete = vi.fn();
|
|
1605
|
+
const onToolCallsUpdate = vi.fn();
|
|
1606
|
+
const mockConfig = {
|
|
1607
|
+
getSessionId: () => 'test-session-id',
|
|
1608
|
+
getUsageStatisticsEnabled: () => true,
|
|
1609
|
+
getDebugMode: () => false,
|
|
1610
|
+
getApprovalMode: () => ApprovalMode.YOLO,
|
|
1611
|
+
getAllowedTools: () => [],
|
|
1612
|
+
getContentGeneratorConfig: () => ({
|
|
1613
|
+
model: 'test-model',
|
|
1614
|
+
authType: 'oauth-personal',
|
|
1615
|
+
}),
|
|
1616
|
+
getShellExecutionConfig: () => ({
|
|
1617
|
+
terminalWidth: 90,
|
|
1618
|
+
terminalHeight: 30,
|
|
1619
|
+
}),
|
|
1620
|
+
storage: {
|
|
1621
|
+
getProjectTempDir: () => '/tmp',
|
|
1622
|
+
},
|
|
1623
|
+
getToolRegistry: () => mockToolRegistry,
|
|
1624
|
+
getTruncateToolOutputThreshold: () => DEFAULT_TRUNCATE_TOOL_OUTPUT_THRESHOLD,
|
|
1625
|
+
getTruncateToolOutputLines: () => DEFAULT_TRUNCATE_TOOL_OUTPUT_LINES,
|
|
1626
|
+
getUseSmartEdit: () => false,
|
|
1627
|
+
getUseModelRouter: () => false,
|
|
1628
|
+
getGeminiClient: () => null,
|
|
1629
|
+
};
|
|
1630
|
+
const scheduler = new CoreToolScheduler({
|
|
1631
|
+
config: mockConfig,
|
|
1632
|
+
onAllToolCallsComplete,
|
|
1633
|
+
onToolCallsUpdate,
|
|
1634
|
+
getPreferredEditor: () => 'vscode',
|
|
1635
|
+
onEditorClose: vi.fn(),
|
|
1636
|
+
});
|
|
1637
|
+
const requests = [
|
|
1638
|
+
{
|
|
1639
|
+
callId: '1',
|
|
1640
|
+
name: 'mockTool',
|
|
1641
|
+
args: { call: 1 },
|
|
1642
|
+
isClientInitiated: false,
|
|
1643
|
+
prompt_id: 'prompt-1',
|
|
1644
|
+
},
|
|
1645
|
+
{
|
|
1646
|
+
callId: '2',
|
|
1647
|
+
name: 'mockTool',
|
|
1648
|
+
args: { call: 2 },
|
|
1649
|
+
isClientInitiated: false,
|
|
1650
|
+
prompt_id: 'prompt-1',
|
|
1651
|
+
},
|
|
1652
|
+
{
|
|
1653
|
+
callId: '3',
|
|
1654
|
+
name: 'mockTool',
|
|
1655
|
+
args: { call: 3 },
|
|
1656
|
+
isClientInitiated: false,
|
|
1657
|
+
prompt_id: 'prompt-1',
|
|
1658
|
+
},
|
|
1659
|
+
];
|
|
1660
|
+
// Act
|
|
1661
|
+
const schedulePromise = scheduler.schedule(requests, abortController.signal);
|
|
1662
|
+
// Wait for the second call to start, then abort.
|
|
1663
|
+
await vi.waitFor(() => {
|
|
1664
|
+
expect(secondCallStarted).toBe(true);
|
|
1665
|
+
});
|
|
1666
|
+
abortController.abort();
|
|
1667
|
+
await schedulePromise;
|
|
1668
|
+
// Assert
|
|
1669
|
+
await vi.waitFor(() => {
|
|
1670
|
+
expect(onAllToolCallsComplete).toHaveBeenCalled();
|
|
1671
|
+
});
|
|
1672
|
+
// Check that execute was called for all three tools initially
|
|
1673
|
+
expect(executeFn).toHaveBeenCalledTimes(3);
|
|
1674
|
+
expect(executeFn).toHaveBeenCalledWith({ call: 1 });
|
|
1675
|
+
expect(executeFn).toHaveBeenCalledWith({ call: 2 });
|
|
1676
|
+
expect(executeFn).toHaveBeenCalledWith({ call: 3 });
|
|
1677
|
+
const completedCalls = onAllToolCallsComplete.mock
|
|
1678
|
+
.calls[0][0];
|
|
1679
|
+
expect(completedCalls).toHaveLength(3);
|
|
1680
|
+
const call1 = completedCalls.find((c) => c.request.callId === '1');
|
|
1681
|
+
const call2 = completedCalls.find((c) => c.request.callId === '2');
|
|
1682
|
+
const call3 = completedCalls.find((c) => c.request.callId === '3');
|
|
1683
|
+
expect(call1?.status).toBe('success');
|
|
1684
|
+
expect(call2?.status).toBe('cancelled');
|
|
1685
|
+
expect(call3?.status).toBe('cancelled');
|
|
1686
|
+
});
|
|
1687
|
+
});
|
|
1688
|
+
describe('truncateAndSaveToFile', () => {
|
|
1689
|
+
const mockWriteFile = vi.mocked(fs.writeFile);
|
|
1690
|
+
const THRESHOLD = 40_000;
|
|
1691
|
+
const TRUNCATE_LINES = 1000;
|
|
1692
|
+
beforeEach(() => {
|
|
1693
|
+
vi.clearAllMocks();
|
|
1694
|
+
});
|
|
1695
|
+
it('should return content unchanged if below threshold', async () => {
|
|
1696
|
+
const content = 'Short content';
|
|
1697
|
+
const callId = 'test-call-id';
|
|
1698
|
+
const projectTempDir = '/tmp';
|
|
1699
|
+
const result = await truncateAndSaveToFile(content, callId, projectTempDir, THRESHOLD, TRUNCATE_LINES);
|
|
1700
|
+
expect(result).toEqual({ content });
|
|
1701
|
+
expect(mockWriteFile).not.toHaveBeenCalled();
|
|
1702
|
+
});
|
|
1703
|
+
it('should truncate content by lines when content has many lines', async () => {
|
|
1704
|
+
// Create content that exceeds 100,000 character threshold with many lines
|
|
1705
|
+
const lines = Array(2000).fill('x'.repeat(100)); // 100 chars per line * 2000 lines = 200,000 chars
|
|
1706
|
+
const content = lines.join('\n');
|
|
1707
|
+
const callId = 'test-call-id';
|
|
1708
|
+
const projectTempDir = '/tmp';
|
|
1709
|
+
mockWriteFile.mockResolvedValue(undefined);
|
|
1710
|
+
const result = await truncateAndSaveToFile(content, callId, projectTempDir, THRESHOLD, TRUNCATE_LINES);
|
|
1711
|
+
expect(result.outputFile).toBe(path.join(projectTempDir, `${callId}.output`));
|
|
1712
|
+
expect(mockWriteFile).toHaveBeenCalledWith(path.join(projectTempDir, `${callId}.output`), content);
|
|
1713
|
+
// Should contain the first and last lines with 1/5 head and 4/5 tail
|
|
1714
|
+
const head = Math.floor(TRUNCATE_LINES / 5);
|
|
1715
|
+
const beginning = lines.slice(0, head);
|
|
1716
|
+
const end = lines.slice(-(TRUNCATE_LINES - head));
|
|
1717
|
+
const expectedTruncated = beginning.join('\n') + '\n... [CONTENT TRUNCATED] ...\n' + end.join('\n');
|
|
1718
|
+
expect(result.content).toContain('Tool output was too large and has been truncated');
|
|
1719
|
+
expect(result.content).toContain('Truncated part of the output:');
|
|
1720
|
+
expect(result.content).toContain(expectedTruncated);
|
|
1721
|
+
});
|
|
1722
|
+
it('should wrap and truncate content when content has few but long lines', async () => {
|
|
1723
|
+
const content = 'a'.repeat(200_000); // A single very long line
|
|
1724
|
+
const callId = 'test-call-id';
|
|
1725
|
+
const projectTempDir = '/tmp';
|
|
1726
|
+
const wrapWidth = 120;
|
|
1727
|
+
mockWriteFile.mockResolvedValue(undefined);
|
|
1728
|
+
// Manually wrap the content to generate the expected file content
|
|
1729
|
+
const wrappedLines = [];
|
|
1730
|
+
for (let i = 0; i < content.length; i += wrapWidth) {
|
|
1731
|
+
wrappedLines.push(content.substring(i, i + wrapWidth));
|
|
1732
|
+
}
|
|
1733
|
+
const expectedFileContent = wrappedLines.join('\n');
|
|
1734
|
+
const result = await truncateAndSaveToFile(content, callId, projectTempDir, THRESHOLD, TRUNCATE_LINES);
|
|
1735
|
+
expect(result.outputFile).toBe(path.join(projectTempDir, `${callId}.output`));
|
|
1736
|
+
// Check that the file was written with the wrapped content
|
|
1737
|
+
expect(mockWriteFile).toHaveBeenCalledWith(path.join(projectTempDir, `${callId}.output`), expectedFileContent);
|
|
1738
|
+
// Should contain the first and last lines with 1/5 head and 4/5 tail of the wrapped content
|
|
1739
|
+
const head = Math.floor(TRUNCATE_LINES / 5);
|
|
1740
|
+
const beginning = wrappedLines.slice(0, head);
|
|
1741
|
+
const end = wrappedLines.slice(-(TRUNCATE_LINES - head));
|
|
1742
|
+
const expectedTruncated = beginning.join('\n') + '\n... [CONTENT TRUNCATED] ...\n' + end.join('\n');
|
|
1743
|
+
expect(result.content).toContain('Tool output was too large and has been truncated');
|
|
1744
|
+
expect(result.content).toContain('Truncated part of the output:');
|
|
1745
|
+
expect(result.content).toContain(expectedTruncated);
|
|
1746
|
+
});
|
|
1747
|
+
it('should handle file write errors gracefully', async () => {
|
|
1748
|
+
const content = 'a'.repeat(2_000_000);
|
|
1749
|
+
const callId = 'test-call-id';
|
|
1750
|
+
const projectTempDir = '/tmp';
|
|
1751
|
+
mockWriteFile.mockRejectedValue(new Error('File write failed'));
|
|
1752
|
+
const result = await truncateAndSaveToFile(content, callId, projectTempDir, THRESHOLD, TRUNCATE_LINES);
|
|
1753
|
+
expect(result.outputFile).toBeUndefined();
|
|
1754
|
+
expect(result.content).toContain('[Note: Could not save full output to file]');
|
|
1755
|
+
expect(mockWriteFile).toHaveBeenCalled();
|
|
1756
|
+
});
|
|
1757
|
+
it('should save to correct file path with call ID', async () => {
|
|
1758
|
+
const content = 'a'.repeat(200_000);
|
|
1759
|
+
const callId = 'unique-call-123';
|
|
1760
|
+
const projectTempDir = '/custom/temp/dir';
|
|
1761
|
+
const wrapWidth = 120;
|
|
1762
|
+
mockWriteFile.mockResolvedValue(undefined);
|
|
1763
|
+
// Manually wrap the content to generate the expected file content
|
|
1764
|
+
const wrappedLines = [];
|
|
1765
|
+
for (let i = 0; i < content.length; i += wrapWidth) {
|
|
1766
|
+
wrappedLines.push(content.substring(i, i + wrapWidth));
|
|
1767
|
+
}
|
|
1768
|
+
const expectedFileContent = wrappedLines.join('\n');
|
|
1769
|
+
const result = await truncateAndSaveToFile(content, callId, projectTempDir, THRESHOLD, TRUNCATE_LINES);
|
|
1770
|
+
const expectedPath = path.join(projectTempDir, `${callId}.output`);
|
|
1771
|
+
expect(result.outputFile).toBe(expectedPath);
|
|
1772
|
+
expect(mockWriteFile).toHaveBeenCalledWith(expectedPath, expectedFileContent);
|
|
1773
|
+
});
|
|
1774
|
+
it('should include helpful instructions in truncated message', async () => {
|
|
1775
|
+
const content = 'a'.repeat(2_000_000);
|
|
1776
|
+
const callId = 'test-call-id';
|
|
1777
|
+
const projectTempDir = '/tmp';
|
|
1778
|
+
mockWriteFile.mockResolvedValue(undefined);
|
|
1779
|
+
const result = await truncateAndSaveToFile(content, callId, projectTempDir, THRESHOLD, TRUNCATE_LINES);
|
|
1780
|
+
expect(result.content).toContain('Tool output was too large and has been truncated');
|
|
1781
|
+
expect(result.content).toContain('The full output has been saved to:');
|
|
1782
|
+
expect(result.content).toContain('To read the complete output, use the read_file tool with the absolute file path above');
|
|
1783
|
+
expect(result.content).toContain('The truncated output below shows the beginning and end of the content');
|
|
1784
|
+
});
|
|
1785
|
+
it('should sanitize callId to prevent path traversal', async () => {
|
|
1786
|
+
const content = 'a'.repeat(200_000);
|
|
1787
|
+
const callId = '../../../../../etc/passwd';
|
|
1788
|
+
const projectTempDir = '/tmp/safe_dir';
|
|
1789
|
+
const wrapWidth = 120;
|
|
1790
|
+
mockWriteFile.mockResolvedValue(undefined);
|
|
1791
|
+
// Manually wrap the content to generate the expected file content
|
|
1792
|
+
const wrappedLines = [];
|
|
1793
|
+
for (let i = 0; i < content.length; i += wrapWidth) {
|
|
1794
|
+
wrappedLines.push(content.substring(i, i + wrapWidth));
|
|
1795
|
+
}
|
|
1796
|
+
const expectedFileContent = wrappedLines.join('\n');
|
|
1797
|
+
await truncateAndSaveToFile(content, callId, projectTempDir, THRESHOLD, TRUNCATE_LINES);
|
|
1798
|
+
const expectedPath = path.join(projectTempDir, 'passwd.output');
|
|
1799
|
+
expect(mockWriteFile).toHaveBeenCalledWith(expectedPath, expectedFileContent);
|
|
1800
|
+
});
|
|
1801
|
+
});
|
|
1802
|
+
//# sourceMappingURL=coreToolScheduler.test.js.map
|