@vybestack/llxprt-code-core 0.1.12 → 0.1.13-hotfix1
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/src/adapters/IStreamAdapter.d.ts +18 -0
- package/dist/src/adapters/IStreamAdapter.js +7 -0
- package/dist/src/adapters/IStreamAdapter.js.map +1 -0
- package/dist/src/code_assist/oauth2.d.ts +1 -1
- package/dist/src/code_assist/oauth2.js +51 -29
- package/dist/src/code_assist/oauth2.js.map +1 -1
- package/dist/src/code_assist/oauth2.test.js +36 -7
- package/dist/src/code_assist/oauth2.test.js.map +1 -1
- package/dist/src/code_assist/server.test.js +10 -2
- package/dist/src/code_assist/server.test.js.map +1 -1
- package/dist/src/config/config.d.ts +28 -5
- package/dist/src/config/config.js +29 -4
- package/dist/src/config/config.js.map +1 -1
- package/dist/src/config/config.test.js +2 -3
- package/dist/src/config/config.test.js.map +1 -1
- package/dist/src/core/client.d.ts +4 -2
- package/dist/src/core/client.js +68 -7
- package/dist/src/core/client.js.map +1 -1
- package/dist/src/core/client.test.js +8 -0
- package/dist/src/core/client.test.js.map +1 -1
- package/dist/src/core/contentGenerator.d.ts +3 -2
- package/dist/src/core/contentGenerator.js +6 -8
- package/dist/src/core/contentGenerator.js.map +1 -1
- package/dist/src/core/contentGenerator.test.js +12 -5
- package/dist/src/core/contentGenerator.test.js.map +1 -1
- package/dist/src/core/coreToolScheduler.test.js +4 -2
- package/dist/src/core/coreToolScheduler.test.js.map +1 -1
- package/dist/src/core/geminiChat.js +50 -3
- package/dist/src/core/geminiChat.js.map +1 -1
- package/dist/src/core/modelCheck.d.ts +1 -1
- package/dist/src/core/modelCheck.js +10 -3
- package/dist/src/core/modelCheck.js.map +1 -1
- package/dist/src/core/nonInteractiveToolExecutor.test.js +3 -0
- package/dist/src/core/nonInteractiveToolExecutor.test.js.map +1 -1
- package/dist/src/core/prompts.d.ts +1 -1
- package/dist/src/core/prompts.js +14 -2
- package/dist/src/core/prompts.js.map +1 -1
- package/dist/src/core/turn.js +6 -0
- package/dist/src/core/turn.js.map +1 -1
- package/dist/src/index.d.ts +29 -1
- package/dist/src/index.js +33 -0
- package/dist/src/index.js.map +1 -1
- package/dist/src/mcp/oauth-provider.d.ts +142 -0
- package/dist/src/mcp/oauth-provider.js +446 -0
- package/dist/src/mcp/oauth-provider.js.map +1 -0
- package/dist/src/mcp/oauth-provider.test.js +520 -0
- package/dist/src/mcp/oauth-provider.test.js.map +1 -0
- package/dist/src/mcp/oauth-token-storage.d.ts +81 -0
- package/dist/src/mcp/oauth-token-storage.js +149 -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 +205 -0
- package/dist/src/mcp/oauth-token-storage.test.js.map +1 -0
- package/dist/src/mcp/oauth-utils.d.ts +109 -0
- package/dist/src/mcp/oauth-utils.js +183 -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 +144 -0
- package/dist/src/mcp/oauth-utils.test.js.map +1 -0
- package/dist/src/parsers/TextToolCallParser.d.ts +35 -0
- package/dist/src/parsers/TextToolCallParser.js +248 -0
- package/dist/src/parsers/TextToolCallParser.js.map +1 -0
- package/dist/src/parsers/TextToolCallParser.test.d.ts +1 -0
- package/dist/src/parsers/TextToolCallParser.test.js +225 -0
- package/dist/src/parsers/TextToolCallParser.test.js.map +1 -0
- package/dist/src/providers/ContentGeneratorRole.d.ts +14 -0
- package/dist/src/providers/ContentGeneratorRole.js +16 -0
- package/dist/src/providers/ContentGeneratorRole.js.map +1 -0
- package/dist/src/providers/IMessage.d.ts +38 -0
- package/dist/src/providers/IMessage.js +17 -0
- package/dist/src/providers/IMessage.js.map +1 -0
- package/dist/src/providers/IModel.d.ts +23 -0
- package/dist/src/providers/IModel.js +17 -0
- package/dist/src/providers/IModel.js.map +1 -0
- package/dist/src/providers/IProvider.d.ts +36 -0
- package/dist/src/providers/IProvider.js +17 -0
- package/dist/src/providers/IProvider.js.map +1 -0
- package/dist/src/providers/IProviderConfig.d.ts +31 -0
- package/dist/src/providers/IProviderConfig.js +7 -0
- package/dist/src/providers/IProviderConfig.js.map +1 -0
- package/dist/src/providers/IProviderManager.d.ts +53 -0
- package/dist/src/providers/IProviderManager.js +7 -0
- package/dist/src/providers/IProviderManager.js.map +1 -0
- package/dist/src/providers/ITool.d.ts +23 -0
- package/dist/src/providers/ITool.js +17 -0
- package/dist/src/providers/ITool.js.map +1 -0
- package/dist/src/providers/ProviderContentGenerator.d.ts +1 -1
- package/dist/src/providers/ProviderManager.d.ts +24 -0
- package/dist/src/providers/ProviderManager.gemini-switch.test.d.ts +6 -0
- package/dist/src/providers/ProviderManager.gemini-switch.test.js +57 -0
- package/dist/src/providers/ProviderManager.gemini-switch.test.js.map +1 -0
- package/dist/src/providers/ProviderManager.js +116 -0
- package/dist/src/providers/ProviderManager.js.map +1 -0
- package/dist/src/providers/ProviderManager.test.d.ts +6 -0
- package/dist/src/providers/ProviderManager.test.js +284 -0
- package/dist/src/providers/ProviderManager.test.js.map +1 -0
- package/dist/src/providers/adapters/GeminiCompatibleWrapper.d.ts +2 -1
- package/dist/src/providers/adapters/GeminiCompatibleWrapper.js +15 -2
- package/dist/src/providers/adapters/GeminiCompatibleWrapper.js.map +1 -1
- package/dist/src/providers/adapters/GeminiCompatibleWrapper.test.js +20 -0
- package/dist/src/providers/adapters/GeminiCompatibleWrapper.test.js.map +1 -1
- package/dist/src/providers/anthropic/AnthropicProvider.d.ts +57 -0
- package/dist/src/providers/anthropic/AnthropicProvider.js +490 -0
- package/dist/src/providers/anthropic/AnthropicProvider.js.map +1 -0
- package/dist/src/providers/anthropic/AnthropicProvider.test.d.ts +1 -0
- package/dist/src/providers/anthropic/AnthropicProvider.test.js +486 -0
- package/dist/src/providers/anthropic/AnthropicProvider.test.js.map +1 -0
- package/dist/src/providers/errors.d.ts +13 -0
- package/dist/src/providers/errors.js +19 -0
- package/dist/src/providers/errors.js.map +1 -0
- package/dist/src/providers/gemini/GeminiProvider.d.ts +97 -0
- package/dist/src/providers/gemini/GeminiProvider.integration.test.d.ts +6 -0
- package/dist/src/providers/gemini/GeminiProvider.integration.test.js +90 -0
- package/dist/src/providers/gemini/GeminiProvider.integration.test.js.map +1 -0
- package/dist/src/providers/gemini/GeminiProvider.js +937 -0
- package/dist/src/providers/gemini/GeminiProvider.js.map +1 -0
- package/dist/src/providers/gemini/GeminiProvider.test.d.ts +6 -0
- package/dist/src/providers/gemini/GeminiProvider.test.js +136 -0
- package/dist/src/providers/gemini/GeminiProvider.test.js.map +1 -0
- package/dist/src/providers/integration/TEST_INSTRUCTIONS.md +197 -0
- package/dist/src/providers/integration/multi-provider.integration.test.d.ts +6 -0
- package/dist/src/providers/integration/multi-provider.integration.test.js +292 -0
- package/dist/src/providers/integration/multi-provider.integration.test.js.map +1 -0
- package/dist/src/providers/openai/ConversationCache.accumTokens.test.d.ts +1 -0
- package/dist/src/providers/openai/ConversationCache.accumTokens.test.js +97 -0
- package/dist/src/providers/openai/ConversationCache.accumTokens.test.js.map +1 -0
- package/dist/src/providers/openai/ConversationCache.d.ts +20 -0
- package/dist/src/providers/openai/ConversationCache.js +109 -0
- package/dist/src/providers/openai/ConversationCache.js.map +1 -0
- package/dist/src/providers/openai/ConversationCache.test.d.ts +1 -0
- package/dist/src/providers/openai/ConversationCache.test.js +113 -0
- package/dist/src/providers/openai/ConversationCache.test.js.map +1 -0
- package/dist/src/providers/openai/IChatGenerateParams.d.ts +11 -0
- package/dist/src/providers/openai/IChatGenerateParams.js +2 -0
- package/dist/src/providers/openai/IChatGenerateParams.js.map +1 -0
- package/dist/src/providers/openai/OpenAIProvider.callResponses.stateless.test.d.ts +1 -0
- package/dist/src/providers/openai/OpenAIProvider.callResponses.stateless.test.js +189 -0
- package/dist/src/providers/openai/OpenAIProvider.callResponses.stateless.test.js.map +1 -0
- package/dist/src/providers/openai/OpenAIProvider.d.ts +80 -0
- package/dist/src/providers/openai/OpenAIProvider.integration.test.d.ts +6 -0
- package/dist/src/providers/openai/OpenAIProvider.integration.test.js +125 -0
- package/dist/src/providers/openai/OpenAIProvider.integration.test.js.map +1 -0
- package/dist/src/providers/openai/OpenAIProvider.js +523 -0
- package/dist/src/providers/openai/OpenAIProvider.js.map +1 -0
- package/dist/src/providers/openai/OpenAIProvider.responses.test.d.ts +1 -0
- package/dist/src/providers/openai/OpenAIProvider.responses.test.js +326 -0
- package/dist/src/providers/openai/OpenAIProvider.responses.test.js.map +1 -0
- package/dist/src/providers/openai/OpenAIProvider.responsesIntegration.test.d.ts +1 -0
- package/dist/src/providers/openai/OpenAIProvider.responsesIntegration.test.js +213 -0
- package/dist/src/providers/openai/OpenAIProvider.responsesIntegration.test.js.map +1 -0
- package/dist/src/providers/openai/OpenAIProvider.shouldUseResponses.test.d.ts +1 -0
- package/dist/src/providers/openai/OpenAIProvider.shouldUseResponses.test.js +58 -0
- package/dist/src/providers/openai/OpenAIProvider.shouldUseResponses.test.js.map +1 -0
- package/dist/src/providers/openai/OpenAIProvider.stateful.integration.test.d.ts +6 -0
- package/dist/src/providers/openai/OpenAIProvider.stateful.integration.test.js +105 -0
- package/dist/src/providers/openai/OpenAIProvider.stateful.integration.test.js.map +1 -0
- package/dist/src/providers/openai/OpenAIProvider.switch.test.d.ts +1 -0
- package/dist/src/providers/openai/OpenAIProvider.switch.test.js +256 -0
- package/dist/src/providers/openai/OpenAIProvider.switch.test.js.map +1 -0
- package/dist/src/providers/openai/OpenAIProvider.test.d.ts +16 -0
- package/dist/src/providers/openai/OpenAIProvider.test.js +214 -0
- package/dist/src/providers/openai/OpenAIProvider.test.js.map +1 -0
- package/dist/src/providers/openai/RESPONSES_API_MODELS.d.ts +2 -0
- package/dist/src/providers/openai/RESPONSES_API_MODELS.js +14 -0
- package/dist/src/providers/openai/RESPONSES_API_MODELS.js.map +1 -0
- package/dist/src/providers/openai/ResponsesContextTrim.integration.test.d.ts +1 -0
- package/dist/src/providers/openai/ResponsesContextTrim.integration.test.js +210 -0
- package/dist/src/providers/openai/ResponsesContextTrim.integration.test.js.map +1 -0
- package/dist/src/providers/openai/__tests__/formatArrayResponse.test.d.ts +1 -0
- package/dist/src/providers/openai/__tests__/formatArrayResponse.test.js +65 -0
- package/dist/src/providers/openai/__tests__/formatArrayResponse.test.js.map +1 -0
- package/dist/src/providers/openai/buildResponsesRequest.d.ts +73 -0
- package/dist/src/providers/openai/buildResponsesRequest.js +165 -0
- package/dist/src/providers/openai/buildResponsesRequest.js.map +1 -0
- package/dist/src/providers/openai/buildResponsesRequest.stripToolCalls.test.d.ts +1 -0
- package/dist/src/providers/openai/buildResponsesRequest.stripToolCalls.test.js +129 -0
- package/dist/src/providers/openai/buildResponsesRequest.stripToolCalls.test.js.map +1 -0
- package/dist/src/providers/openai/buildResponsesRequest.test.d.ts +1 -0
- package/dist/src/providers/openai/buildResponsesRequest.test.js +406 -0
- package/dist/src/providers/openai/buildResponsesRequest.test.js.map +1 -0
- package/dist/src/providers/openai/buildResponsesRequest.undefined.test.d.ts +1 -0
- package/dist/src/providers/openai/buildResponsesRequest.undefined.test.js +50 -0
- package/dist/src/providers/openai/buildResponsesRequest.undefined.test.js.map +1 -0
- package/dist/src/providers/openai/docs/accessing-provider-info.md +172 -0
- package/dist/src/providers/openai/docs/params-mapping.md +91 -0
- package/dist/src/providers/openai/docs/responses-api-tool-calls.md +96 -0
- package/dist/src/providers/openai/estimateRemoteTokens.d.ts +26 -0
- package/dist/src/providers/openai/estimateRemoteTokens.js +75 -0
- package/dist/src/providers/openai/estimateRemoteTokens.js.map +1 -0
- package/dist/src/providers/openai/estimateRemoteTokens.test.d.ts +1 -0
- package/dist/src/providers/openai/estimateRemoteTokens.test.js +125 -0
- package/dist/src/providers/openai/estimateRemoteTokens.test.js.map +1 -0
- package/dist/src/providers/openai/getOpenAIProviderInfo.d.ts +46 -0
- package/dist/src/providers/openai/getOpenAIProviderInfo.js +75 -0
- package/dist/src/providers/openai/getOpenAIProviderInfo.js.map +1 -0
- package/dist/src/providers/openai/parseResponsesStream.d.ts +3 -0
- package/dist/src/providers/openai/parseResponsesStream.js +462 -0
- package/dist/src/providers/openai/parseResponsesStream.js.map +1 -0
- package/dist/src/providers/openai/parseResponsesStream.responsesToolCalls.test.d.ts +1 -0
- package/dist/src/providers/openai/parseResponsesStream.responsesToolCalls.test.js +192 -0
- package/dist/src/providers/openai/parseResponsesStream.responsesToolCalls.test.js.map +1 -0
- package/dist/src/providers/openai/parseResponsesStream.test.d.ts +1 -0
- package/dist/src/providers/openai/parseResponsesStream.test.js +151 -0
- package/dist/src/providers/openai/parseResponsesStream.test.js.map +1 -0
- package/dist/src/providers/tokenizers/AnthropicTokenizer.d.ts +19 -0
- package/dist/src/providers/tokenizers/AnthropicTokenizer.js +37 -0
- package/dist/src/providers/tokenizers/AnthropicTokenizer.js.map +1 -0
- package/dist/src/providers/tokenizers/ITokenizer.d.ts +18 -0
- package/dist/src/providers/tokenizers/ITokenizer.js +17 -0
- package/dist/src/providers/tokenizers/ITokenizer.js.map +1 -0
- package/dist/src/providers/tokenizers/OpenAITokenizer.d.ts +24 -0
- package/dist/src/providers/tokenizers/OpenAITokenizer.js +56 -0
- package/dist/src/providers/tokenizers/OpenAITokenizer.js.map +1 -0
- package/dist/src/providers/types/IProviderConfig.d.ts +102 -0
- package/dist/src/providers/types/IProviderConfig.js +17 -0
- package/dist/src/providers/types/IProviderConfig.js.map +1 -0
- package/dist/src/providers/types.d.ts +4 -69
- package/dist/src/services/ideContext.d.ts +2 -0
- package/dist/src/services/ideContext.js +8 -0
- package/dist/src/services/ideContext.js.map +1 -1
- package/dist/src/services/ideContext.test.js +10 -0
- package/dist/src/services/ideContext.test.js.map +1 -1
- package/dist/src/services/loopDetectionService.d.ts +17 -1
- package/dist/src/services/loopDetectionService.js +117 -2
- package/dist/src/services/loopDetectionService.js.map +1 -1
- package/dist/src/services/loopDetectionService.test.js +109 -2
- package/dist/src/services/loopDetectionService.test.js.map +1 -1
- package/dist/src/telemetry/clearcut-logger/clearcut-logger.d.ts +2 -0
- package/dist/src/telemetry/clearcut-logger/clearcut-logger.js +40 -2
- package/dist/src/telemetry/clearcut-logger/clearcut-logger.js.map +1 -1
- package/dist/src/telemetry/clearcut-logger/event-metadata-key.d.ts +2 -0
- package/dist/src/telemetry/clearcut-logger/event-metadata-key.js +4 -0
- package/dist/src/telemetry/clearcut-logger/event-metadata-key.js.map +1 -1
- package/dist/src/telemetry/sdk.js +0 -2
- package/dist/src/telemetry/sdk.js.map +1 -1
- package/dist/src/telemetry/types.d.ts +2 -1
- package/dist/src/telemetry/types.js +1 -0
- package/dist/src/telemetry/types.js.map +1 -1
- package/dist/src/telemetry/uiTelemetry.d.ts +1 -0
- package/dist/src/telemetry/uiTelemetry.js +7 -0
- package/dist/src/telemetry/uiTelemetry.js.map +1 -1
- package/dist/src/telemetry/uiTelemetry.test.js +92 -0
- package/dist/src/telemetry/uiTelemetry.test.js.map +1 -1
- package/dist/src/tools/IToolFormatter.d.ts +40 -0
- package/dist/src/tools/IToolFormatter.js +17 -0
- package/dist/src/tools/IToolFormatter.js.map +1 -0
- package/dist/src/tools/ToolFormatter.d.ts +45 -0
- package/dist/src/tools/ToolFormatter.js +216 -0
- package/dist/src/tools/ToolFormatter.js.map +1 -0
- package/dist/src/tools/ToolFormatter.test.d.ts +16 -0
- package/dist/src/tools/ToolFormatter.test.js +349 -0
- package/dist/src/tools/ToolFormatter.test.js.map +1 -0
- package/dist/src/tools/ToolFormatter.toResponsesTool.test.d.ts +1 -0
- package/dist/src/tools/ToolFormatter.toResponsesTool.test.js +241 -0
- package/dist/src/tools/ToolFormatter.toResponsesTool.test.js.map +1 -0
- package/dist/src/tools/edit.d.ts +7 -1
- package/dist/src/tools/edit.js +19 -7
- package/dist/src/tools/edit.js.map +1 -1
- package/dist/src/tools/glob.js +2 -2
- package/dist/src/tools/glob.js.map +1 -1
- package/dist/src/tools/grep.js +2 -2
- package/dist/src/tools/grep.js.map +1 -1
- package/dist/src/tools/ls.js +2 -2
- package/dist/src/tools/ls.js.map +1 -1
- package/dist/src/tools/mcp-client.d.ts +0 -2
- package/dist/src/tools/mcp-client.js +8 -20
- package/dist/src/tools/mcp-client.js.map +1 -1
- package/dist/src/tools/mcp-client.test.js +1 -72
- package/dist/src/tools/mcp-client.test.js.map +1 -1
- package/dist/src/tools/mcp-tool.d.ts +11 -5
- package/dist/src/tools/mcp-tool.js +33 -9
- package/dist/src/tools/mcp-tool.js.map +1 -1
- package/dist/src/tools/mcp-tool.test.js +40 -24
- package/dist/src/tools/mcp-tool.test.js.map +1 -1
- package/dist/src/tools/memoryTool.js +2 -2
- package/dist/src/tools/memoryTool.js.map +1 -1
- package/dist/src/tools/read-file.d.ts +2 -1
- package/dist/src/tools/read-file.js +5 -2
- package/dist/src/tools/read-file.js.map +1 -1
- package/dist/src/tools/read-many-files.js +2 -2
- package/dist/src/tools/read-many-files.js.map +1 -1
- package/dist/src/tools/shell.js +2 -2
- package/dist/src/tools/shell.js.map +1 -1
- package/dist/src/tools/todo-read.js +2 -2
- package/dist/src/tools/todo-read.js.map +1 -1
- package/dist/src/tools/todo-write.js +2 -2
- package/dist/src/tools/todo-write.js.map +1 -1
- package/dist/src/tools/tool-registry.d.ts +0 -1
- package/dist/src/tools/tool-registry.js +11 -8
- package/dist/src/tools/tool-registry.js.map +1 -1
- package/dist/src/tools/tool-registry.test.js +36 -10
- package/dist/src/tools/tool-registry.test.js.map +1 -1
- package/dist/src/tools/tools.d.ts +37 -2
- package/dist/src/tools/tools.js +25 -2
- package/dist/src/tools/tools.js.map +1 -1
- package/dist/src/tools/web-fetch.integration.test.d.ts +6 -0
- package/dist/src/tools/web-fetch.integration.test.js +532 -0
- package/dist/src/tools/web-fetch.integration.test.js.map +1 -0
- package/dist/src/tools/web-fetch.js +57 -50
- package/dist/src/tools/web-fetch.js.map +1 -1
- package/dist/src/tools/web-search.js +34 -6
- package/dist/src/tools/web-search.js.map +1 -1
- package/dist/src/tools/web-search.test.d.ts +6 -0
- package/dist/src/tools/web-search.test.js +229 -0
- package/dist/src/tools/web-search.test.js.map +1 -0
- package/dist/src/tools/write-file.js +12 -5
- package/dist/src/tools/write-file.js.map +1 -1
- package/dist/src/utils/browser.d.ts +13 -0
- package/dist/src/utils/browser.js +49 -0
- package/dist/src/utils/browser.js.map +1 -0
- package/dist/src/utils/errors.js +4 -4
- package/dist/src/utils/errors.js.map +1 -1
- package/dist/src/utils/memoryDiscovery.js +5 -1
- package/dist/src/utils/memoryDiscovery.js.map +1 -1
- package/dist/src/utils/quotaErrorDetection.js +0 -2
- package/dist/src/utils/quotaErrorDetection.js.map +1 -1
- package/dist/src/utils/retry.d.ts +6 -0
- package/dist/src/utils/retry.js +1 -1
- package/dist/src/utils/retry.js.map +1 -1
- package/dist/src/utils/user_account.js +6 -1
- package/dist/src/utils/user_account.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +6 -3
- package/dist/src/tools/web-fetch.test.js +0 -70
- package/dist/src/tools/web-fetch.test.js.map +0 -1
- package/dist/vybestack-llxprt-code-core-0.1.12.tgz +0 -0
- /package/dist/src/{tools/web-fetch.test.d.ts → mcp/oauth-provider.test.d.ts} +0 -0
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2025 Vybestack LLC
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* Provider configuration interface that provides a subset of settings
|
|
18
|
+
* required by provider implementations.
|
|
19
|
+
*/
|
|
20
|
+
export interface IProviderConfig {
|
|
21
|
+
/**
|
|
22
|
+
* API key for authenticating with the provider.
|
|
23
|
+
*/
|
|
24
|
+
apiKey?: string;
|
|
25
|
+
/**
|
|
26
|
+
* Base URL for the provider's API endpoint.
|
|
27
|
+
* If not provided, the provider's default endpoint will be used.
|
|
28
|
+
*/
|
|
29
|
+
baseUrl?: string;
|
|
30
|
+
/**
|
|
31
|
+
* Default model to use for this provider.
|
|
32
|
+
*/
|
|
33
|
+
defaultModel?: string;
|
|
34
|
+
/**
|
|
35
|
+
* Maximum number of tokens to generate in a single request.
|
|
36
|
+
*/
|
|
37
|
+
maxTokens?: number;
|
|
38
|
+
/**
|
|
39
|
+
* Temperature setting for response generation (0.0 - 2.0).
|
|
40
|
+
*/
|
|
41
|
+
temperature?: number;
|
|
42
|
+
/**
|
|
43
|
+
* Whether to enable streaming responses.
|
|
44
|
+
*/
|
|
45
|
+
streaming?: boolean;
|
|
46
|
+
/**
|
|
47
|
+
* Request timeout in milliseconds.
|
|
48
|
+
*/
|
|
49
|
+
timeout?: number;
|
|
50
|
+
/**
|
|
51
|
+
* Custom headers to include in API requests.
|
|
52
|
+
*/
|
|
53
|
+
customHeaders?: Record<string, string>;
|
|
54
|
+
/**
|
|
55
|
+
* Whether to enable text-based tool call parsing for models that
|
|
56
|
+
* don't natively support function calling.
|
|
57
|
+
*/
|
|
58
|
+
enableTextToolCallParsing?: boolean;
|
|
59
|
+
/**
|
|
60
|
+
* List of model IDs that require text-based tool call parsing.
|
|
61
|
+
*/
|
|
62
|
+
textToolCallModels?: string[];
|
|
63
|
+
/**
|
|
64
|
+
* Override tool format for specific providers.
|
|
65
|
+
* Maps provider name to tool format.
|
|
66
|
+
*/
|
|
67
|
+
providerToolFormatOverrides?: Record<string, string>;
|
|
68
|
+
/**
|
|
69
|
+
* Whether to enable OpenAI Responses API for compatible models.
|
|
70
|
+
*/
|
|
71
|
+
openaiResponsesEnabled?: boolean;
|
|
72
|
+
/**
|
|
73
|
+
* Organization ID for providers that support organization-level access.
|
|
74
|
+
*/
|
|
75
|
+
organizationId?: string;
|
|
76
|
+
/**
|
|
77
|
+
* Project ID for providers that support project-level access.
|
|
78
|
+
*/
|
|
79
|
+
projectId?: string;
|
|
80
|
+
/**
|
|
81
|
+
* Retry configuration for failed requests.
|
|
82
|
+
*/
|
|
83
|
+
retryConfig?: {
|
|
84
|
+
/**
|
|
85
|
+
* Maximum number of retry attempts.
|
|
86
|
+
*/
|
|
87
|
+
maxRetries?: number;
|
|
88
|
+
/**
|
|
89
|
+
* Base delay in milliseconds between retries.
|
|
90
|
+
*/
|
|
91
|
+
retryDelay?: number;
|
|
92
|
+
/**
|
|
93
|
+
* Whether to use exponential backoff.
|
|
94
|
+
*/
|
|
95
|
+
exponentialBackoff?: boolean;
|
|
96
|
+
};
|
|
97
|
+
/**
|
|
98
|
+
* Provider-specific configuration options.
|
|
99
|
+
* This allows for flexibility when different providers need unique settings.
|
|
100
|
+
*/
|
|
101
|
+
providerSpecific?: Record<string, unknown>;
|
|
102
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2025 Vybestack LLC
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
export {};
|
|
17
|
+
//# sourceMappingURL=IProviderConfig.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IProviderConfig.js","sourceRoot":"","sources":["../../../../src/providers/types/IProviderConfig.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG"}
|
|
@@ -3,26 +3,10 @@
|
|
|
3
3
|
* Copyright 2025 Google LLC
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
export interface ProviderMessage {
|
|
11
|
-
role: 'system' | 'user' | 'assistant' | 'tool';
|
|
12
|
-
content: string;
|
|
13
|
-
tool_calls?: ProviderToolCall[];
|
|
14
|
-
tool_call_id?: string;
|
|
15
|
-
name?: string;
|
|
16
|
-
usage?: {
|
|
17
|
-
prompt_tokens: number;
|
|
18
|
-
completion_tokens: number;
|
|
19
|
-
total_tokens: number;
|
|
20
|
-
};
|
|
21
|
-
parts?: Part[];
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* Represents a tool call from a provider
|
|
25
|
-
*/
|
|
6
|
+
export type { IMessage as ProviderMessage } from './IMessage.js';
|
|
7
|
+
export type { ITool as ProviderTool } from './ITool.js';
|
|
8
|
+
export type { IProvider as Provider } from './IProvider.js';
|
|
9
|
+
export type { IProviderManager as ProviderManager } from './IProviderManager.js';
|
|
26
10
|
export interface ProviderToolCall {
|
|
27
11
|
id: string;
|
|
28
12
|
type: 'function';
|
|
@@ -31,52 +15,3 @@ export interface ProviderToolCall {
|
|
|
31
15
|
arguments: string;
|
|
32
16
|
};
|
|
33
17
|
}
|
|
34
|
-
/**
|
|
35
|
-
* Represents a tool definition for providers
|
|
36
|
-
*/
|
|
37
|
-
export interface ProviderTool {
|
|
38
|
-
type: 'function';
|
|
39
|
-
function: {
|
|
40
|
-
name: string;
|
|
41
|
-
description?: string;
|
|
42
|
-
parameters?: Record<string, unknown>;
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* Provider interface for external AI providers
|
|
47
|
-
*/
|
|
48
|
-
export interface Provider {
|
|
49
|
-
name: string;
|
|
50
|
-
/**
|
|
51
|
-
* Generate a chat completion
|
|
52
|
-
* @param messages The conversation history
|
|
53
|
-
* @param tools Available tools for the model to use
|
|
54
|
-
* @returns An async iterator of response messages
|
|
55
|
-
*/
|
|
56
|
-
generateChatCompletion(messages: ProviderMessage[], tools?: ProviderTool[]): AsyncIterableIterator<ProviderMessage>;
|
|
57
|
-
/**
|
|
58
|
-
* Get the current model being used
|
|
59
|
-
*/
|
|
60
|
-
getCurrentModel(): string;
|
|
61
|
-
/**
|
|
62
|
-
* Set the model to use
|
|
63
|
-
*/
|
|
64
|
-
setModel(modelId: string): void;
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
67
|
-
* Manager for handling multiple providers
|
|
68
|
-
*/
|
|
69
|
-
export interface ProviderManager {
|
|
70
|
-
/**
|
|
71
|
-
* Check if a provider is currently active
|
|
72
|
-
*/
|
|
73
|
-
hasActiveProvider(): boolean;
|
|
74
|
-
/**
|
|
75
|
-
* Get the currently active provider
|
|
76
|
-
*/
|
|
77
|
-
getActiveProvider(): Provider | null;
|
|
78
|
-
/**
|
|
79
|
-
* Get the name of the active provider
|
|
80
|
-
*/
|
|
81
|
-
getActiveProviderName(): string;
|
|
82
|
-
}
|
|
@@ -112,6 +112,7 @@ export declare function createIdeContextStore(): {
|
|
|
112
112
|
setActiveFileContext: (newActiveFile: ActiveFile) => void;
|
|
113
113
|
getActiveFileContext: () => ActiveFile | undefined;
|
|
114
114
|
subscribeToActiveFile: (subscriber: ActiveFileSubscriber) => () => void;
|
|
115
|
+
clearActiveFileContext: () => void;
|
|
115
116
|
};
|
|
116
117
|
/**
|
|
117
118
|
* The default, shared instance of the IDE context store for the application.
|
|
@@ -120,5 +121,6 @@ export declare const ideContext: {
|
|
|
120
121
|
setActiveFileContext: (newActiveFile: ActiveFile) => void;
|
|
121
122
|
getActiveFileContext: () => ActiveFile | undefined;
|
|
122
123
|
subscribeToActiveFile: (subscriber: ActiveFileSubscriber) => () => void;
|
|
124
|
+
clearActiveFileContext: () => void;
|
|
123
125
|
};
|
|
124
126
|
export {};
|
|
@@ -55,6 +55,13 @@ export function createIdeContextStore() {
|
|
|
55
55
|
activeFileContext = newActiveFile;
|
|
56
56
|
notifySubscribers();
|
|
57
57
|
}
|
|
58
|
+
/**
|
|
59
|
+
* Clears the active file context and notifies all registered subscribers of the change.
|
|
60
|
+
*/
|
|
61
|
+
function clearActiveFileContext() {
|
|
62
|
+
activeFileContext = undefined;
|
|
63
|
+
notifySubscribers();
|
|
64
|
+
}
|
|
58
65
|
/**
|
|
59
66
|
* Retrieves the current active file context.
|
|
60
67
|
* @returns The `ActiveFile` object if a file is active, otherwise `undefined`.
|
|
@@ -81,6 +88,7 @@ export function createIdeContextStore() {
|
|
|
81
88
|
setActiveFileContext,
|
|
82
89
|
getActiveFileContext,
|
|
83
90
|
subscribeToActiveFile,
|
|
91
|
+
clearActiveFileContext,
|
|
84
92
|
};
|
|
85
93
|
}
|
|
86
94
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ideContext.js","sourceRoot":"","sources":["../../../src/services/ideContext.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;GAEG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,aAAa,CAAC;AAE7C;;GAEG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,CAAC,MAAM,CAAC;IACnC,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE;IAChB,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE;CACtB,CAAC,CAAC;AAGH;;GAEG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,CAAC,MAAM,CAAC;IACvC,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AAU,CAAC,CAAC;QACjC,CAAC,CAAC;IACJ,CAAC;IAED,OAAO;QACL,oBAAoB;QACpB,oBAAoB;QACpB,qBAAqB;QACrB,sBAAsB;KACvB,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,qBAAqB,EAAE,CAAC"}
|
|
@@ -97,5 +97,15 @@ describe('ideContext - Active File', () => {
|
|
|
97
97
|
const activeFile = ideContext.getActiveFileContext();
|
|
98
98
|
expect(activeFile).toEqual(testFile);
|
|
99
99
|
});
|
|
100
|
+
it('should clear the active file context', () => {
|
|
101
|
+
const testFile = {
|
|
102
|
+
filePath: '/path/to/test/file.ts',
|
|
103
|
+
cursor: { line: 5, character: 10 },
|
|
104
|
+
};
|
|
105
|
+
ideContext.setActiveFileContext(testFile);
|
|
106
|
+
expect(ideContext.getActiveFileContext()).toEqual(testFile);
|
|
107
|
+
ideContext.clearActiveFileContext();
|
|
108
|
+
expect(ideContext.getActiveFileContext()).toBeUndefined();
|
|
109
|
+
});
|
|
100
110
|
});
|
|
101
111
|
//# sourceMappingURL=ideContext.test.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ideContext.test.js","sourceRoot":"","sources":["../../../src/services/ideContext.test.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,UAAU,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAC9D,OAAO,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AAExD,QAAQ,CAAC,0BAA0B,EAAE,GAAG,EAAE;IACxC,IAAI,UAAoD,CAAC;IAEzD,UAAU,CAAC,GAAG,EAAE;QACd,kDAAkD;QAClD,UAAU,GAAG,qBAAqB,EAAE,CAAC;IACvC,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,2DAA2D,EAAE,GAAG,EAAE;QACnE,MAAM,CAAC,UAAU,CAAC,oBAAoB,EA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AAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -10,12 +10,15 @@ import { Config } from '../config/config.js';
|
|
|
10
10
|
* Monitors tool call repetitions and content sentence repetitions.
|
|
11
11
|
*/
|
|
12
12
|
export declare class LoopDetectionService {
|
|
13
|
+
private readonly config;
|
|
13
14
|
private lastToolCallKey;
|
|
14
15
|
private toolCallRepetitionCount;
|
|
15
16
|
private lastRepeatedSentence;
|
|
16
17
|
private sentenceRepetitionCount;
|
|
17
18
|
private partialContent;
|
|
18
|
-
private
|
|
19
|
+
private turnsInCurrentPrompt;
|
|
20
|
+
private llmCheckInterval;
|
|
21
|
+
private lastCheckTurn;
|
|
19
22
|
constructor(config: Config);
|
|
20
23
|
private getToolCallKey;
|
|
21
24
|
/**
|
|
@@ -24,12 +27,25 @@ export declare class LoopDetectionService {
|
|
|
24
27
|
* @returns true if a loop is detected, false otherwise
|
|
25
28
|
*/
|
|
26
29
|
addAndCheck(event: ServerGeminiStreamEvent): boolean;
|
|
30
|
+
/**
|
|
31
|
+
* Signals the start of a new turn in the conversation.
|
|
32
|
+
*
|
|
33
|
+
* This method increments the turn counter and, if specific conditions are met,
|
|
34
|
+
* triggers an LLM-based check to detect potential conversation loops. The check
|
|
35
|
+
* is performed periodically based on the `llmCheckInterval`.
|
|
36
|
+
*
|
|
37
|
+
* @param signal - An AbortSignal to allow for cancellation of the asynchronous LLM check.
|
|
38
|
+
* @returns A promise that resolves to `true` if a loop is detected, and `false` otherwise.
|
|
39
|
+
*/
|
|
40
|
+
turnStarted(signal: AbortSignal): Promise<boolean>;
|
|
27
41
|
private checkToolCallLoop;
|
|
28
42
|
private checkContentLoop;
|
|
43
|
+
private checkForLoopWithLLM;
|
|
29
44
|
/**
|
|
30
45
|
* Resets all loop detection state.
|
|
31
46
|
*/
|
|
32
47
|
reset(): void;
|
|
33
48
|
private resetToolCallCount;
|
|
34
49
|
private resetSentenceCount;
|
|
50
|
+
private resetLlmCheckTracking;
|
|
35
51
|
}
|
|
@@ -7,14 +7,40 @@ import { createHash } from 'crypto';
|
|
|
7
7
|
import { GeminiEventType } from '../core/turn.js';
|
|
8
8
|
import { logLoopDetected } from '../telemetry/loggers.js';
|
|
9
9
|
import { LoopDetectedEvent, LoopType } from '../telemetry/types.js';
|
|
10
|
+
import { DEFAULT_GEMINI_FLASH_MODEL } from '../config/config.js';
|
|
11
|
+
import { Type } from '@google/genai';
|
|
10
12
|
const TOOL_CALL_LOOP_THRESHOLD = 5;
|
|
11
13
|
const CONTENT_LOOP_THRESHOLD = 10;
|
|
14
|
+
/**
|
|
15
|
+
* The number of recent conversation turns to include in the history when asking the LLM to check for a loop.
|
|
16
|
+
*/
|
|
17
|
+
const LLM_LOOP_CHECK_HISTORY_COUNT = 20;
|
|
18
|
+
/**
|
|
19
|
+
* The number of turns that must pass in a single prompt before the LLM-based loop check is activated.
|
|
20
|
+
*/
|
|
21
|
+
const LLM_CHECK_AFTER_TURNS = 30;
|
|
22
|
+
/**
|
|
23
|
+
* The default interval, in number of turns, at which the LLM-based loop check is performed.
|
|
24
|
+
* This value is adjusted dynamically based on the LLM's confidence.
|
|
25
|
+
*/
|
|
26
|
+
const DEFAULT_LLM_CHECK_INTERVAL = 3;
|
|
27
|
+
/**
|
|
28
|
+
* The minimum interval for LLM-based loop checks.
|
|
29
|
+
* This is used when the confidence of a loop is high, to check more frequently.
|
|
30
|
+
*/
|
|
31
|
+
const MIN_LLM_CHECK_INTERVAL = 5;
|
|
32
|
+
/**
|
|
33
|
+
* The maximum interval for LLM-based loop checks.
|
|
34
|
+
* This is used when the confidence of a loop is low, to check less frequently.
|
|
35
|
+
*/
|
|
36
|
+
const MAX_LLM_CHECK_INTERVAL = 15;
|
|
12
37
|
const SENTENCE_ENDING_PUNCTUATION_REGEX = /[.!?]+(?=\s|$)/;
|
|
13
38
|
/**
|
|
14
39
|
* Service for detecting and preventing infinite loops in AI responses.
|
|
15
40
|
* Monitors tool call repetitions and content sentence repetitions.
|
|
16
41
|
*/
|
|
17
42
|
export class LoopDetectionService {
|
|
43
|
+
config;
|
|
18
44
|
// Tool call tracking
|
|
19
45
|
lastToolCallKey = null;
|
|
20
46
|
toolCallRepetitionCount = 0;
|
|
@@ -22,7 +48,10 @@ export class LoopDetectionService {
|
|
|
22
48
|
lastRepeatedSentence = '';
|
|
23
49
|
sentenceRepetitionCount = 0;
|
|
24
50
|
partialContent = '';
|
|
25
|
-
|
|
51
|
+
// LLM loop track tracking
|
|
52
|
+
turnsInCurrentPrompt = 0;
|
|
53
|
+
llmCheckInterval = DEFAULT_LLM_CHECK_INTERVAL;
|
|
54
|
+
lastCheckTurn = 0;
|
|
26
55
|
constructor(config) {
|
|
27
56
|
this.config = config;
|
|
28
57
|
}
|
|
@@ -46,10 +75,28 @@ export class LoopDetectionService {
|
|
|
46
75
|
case GeminiEventType.Content:
|
|
47
76
|
return this.checkContentLoop(event.value);
|
|
48
77
|
default:
|
|
49
|
-
this.reset();
|
|
50
78
|
return false;
|
|
51
79
|
}
|
|
52
80
|
}
|
|
81
|
+
/**
|
|
82
|
+
* Signals the start of a new turn in the conversation.
|
|
83
|
+
*
|
|
84
|
+
* This method increments the turn counter and, if specific conditions are met,
|
|
85
|
+
* triggers an LLM-based check to detect potential conversation loops. The check
|
|
86
|
+
* is performed periodically based on the `llmCheckInterval`.
|
|
87
|
+
*
|
|
88
|
+
* @param signal - An AbortSignal to allow for cancellation of the asynchronous LLM check.
|
|
89
|
+
* @returns A promise that resolves to `true` if a loop is detected, and `false` otherwise.
|
|
90
|
+
*/
|
|
91
|
+
async turnStarted(signal) {
|
|
92
|
+
this.turnsInCurrentPrompt++;
|
|
93
|
+
if (this.turnsInCurrentPrompt >= LLM_CHECK_AFTER_TURNS &&
|
|
94
|
+
this.turnsInCurrentPrompt - this.lastCheckTurn >= this.llmCheckInterval) {
|
|
95
|
+
this.lastCheckTurn = this.turnsInCurrentPrompt;
|
|
96
|
+
return await this.checkForLoopWithLLM(signal);
|
|
97
|
+
}
|
|
98
|
+
return false;
|
|
99
|
+
}
|
|
53
100
|
checkToolCallLoop(toolCall) {
|
|
54
101
|
const key = this.getToolCallKey(toolCall);
|
|
55
102
|
if (this.lastToolCallKey === key) {
|
|
@@ -97,12 +144,75 @@ export class LoopDetectionService {
|
|
|
97
144
|
}
|
|
98
145
|
return false;
|
|
99
146
|
}
|
|
147
|
+
async checkForLoopWithLLM(signal) {
|
|
148
|
+
const recentHistory = this.config
|
|
149
|
+
.getGeminiClient()
|
|
150
|
+
.getHistory()
|
|
151
|
+
.slice(-LLM_LOOP_CHECK_HISTORY_COUNT);
|
|
152
|
+
const prompt = `You are a sophisticated AI diagnostic agent specializing in identifying when a conversational AI is stuck in an unproductive state. Your task is to analyze the provided conversation history and determine if the assistant has ceased to make meaningful progress.
|
|
153
|
+
|
|
154
|
+
An unproductive state is characterized by one or more of the following patterns over the last 5 or more assistant turns:
|
|
155
|
+
|
|
156
|
+
Repetitive Actions: The assistant repeats the same tool calls or conversational responses a decent number of times. This includes simple loops (e.g., tool_A, tool_A, tool_A) and alternating patterns (e.g., tool_A, tool_B, tool_A, tool_B, ...).
|
|
157
|
+
|
|
158
|
+
Cognitive Loop: The assistant seems unable to determine the next logical step. It might express confusion, repeatedly ask the same questions, or generate responses that don't logically follow from the previous turns, indicating it's stuck and not advancing the task.
|
|
159
|
+
|
|
160
|
+
Crucially, differentiate between a true unproductive state and legitimate, incremental progress.
|
|
161
|
+
For example, a series of 'tool_A' or 'tool_B' tool calls that make small, distinct changes to the same file (like adding docstrings to functions one by one) is considered forward progress and is NOT a loop. A loop would be repeatedly replacing the same text with the same content, or cycling between a small set of files with no net change.
|
|
162
|
+
|
|
163
|
+
Please analyze the conversation history to determine the possibility that the conversation is stuck in a repetitive, non-productive state.`;
|
|
164
|
+
const contents = [
|
|
165
|
+
...recentHistory,
|
|
166
|
+
{ role: 'user', parts: [{ text: prompt }] },
|
|
167
|
+
];
|
|
168
|
+
const schema = {
|
|
169
|
+
type: Type.OBJECT,
|
|
170
|
+
properties: {
|
|
171
|
+
reasoning: {
|
|
172
|
+
type: Type.STRING,
|
|
173
|
+
description: 'Your reasoning on if the conversation is looping without forward progress.',
|
|
174
|
+
},
|
|
175
|
+
confidence: {
|
|
176
|
+
type: Type.NUMBER,
|
|
177
|
+
description: 'A number between 0.0 and 1.0 representing your confidence that the conversation is in an unproductive state.',
|
|
178
|
+
},
|
|
179
|
+
},
|
|
180
|
+
required: ['reasoning', 'confidence'],
|
|
181
|
+
};
|
|
182
|
+
let result;
|
|
183
|
+
try {
|
|
184
|
+
result = await this.config
|
|
185
|
+
.getGeminiClient()
|
|
186
|
+
.generateJson(contents, schema, signal, DEFAULT_GEMINI_FLASH_MODEL);
|
|
187
|
+
}
|
|
188
|
+
catch (e) {
|
|
189
|
+
// Do nothing, treat it as a non-loop.
|
|
190
|
+
this.config.getDebugMode() ? console.error(e) : console.debug(e);
|
|
191
|
+
return false;
|
|
192
|
+
}
|
|
193
|
+
if (typeof result.confidence === 'number') {
|
|
194
|
+
if (result.confidence > 0.9) {
|
|
195
|
+
if (typeof result.reasoning === 'string' && result.reasoning) {
|
|
196
|
+
console.warn(result.reasoning);
|
|
197
|
+
}
|
|
198
|
+
logLoopDetected(this.config, new LoopDetectedEvent(LoopType.LLM_DETECTED_LOOP));
|
|
199
|
+
return true;
|
|
200
|
+
}
|
|
201
|
+
else {
|
|
202
|
+
this.llmCheckInterval = Math.round(MIN_LLM_CHECK_INTERVAL +
|
|
203
|
+
(MAX_LLM_CHECK_INTERVAL - MIN_LLM_CHECK_INTERVAL) *
|
|
204
|
+
(1 - result.confidence));
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
return false;
|
|
208
|
+
}
|
|
100
209
|
/**
|
|
101
210
|
* Resets all loop detection state.
|
|
102
211
|
*/
|
|
103
212
|
reset() {
|
|
104
213
|
this.resetToolCallCount();
|
|
105
214
|
this.resetSentenceCount();
|
|
215
|
+
this.resetLlmCheckTracking();
|
|
106
216
|
}
|
|
107
217
|
resetToolCallCount() {
|
|
108
218
|
this.lastToolCallKey = null;
|
|
@@ -113,5 +223,10 @@ export class LoopDetectionService {
|
|
|
113
223
|
this.sentenceRepetitionCount = 0;
|
|
114
224
|
this.partialContent = '';
|
|
115
225
|
}
|
|
226
|
+
resetLlmCheckTracking() {
|
|
227
|
+
this.turnsInCurrentPrompt = 0;
|
|
228
|
+
this.llmCheckInterval = DEFAULT_LLM_CHECK_INTERVAL;
|
|
229
|
+
this.lastCheckTurn = 0;
|
|
230
|
+
}
|
|
116
231
|
}
|
|
117
232
|
//# sourceMappingURL=loopDetectionService.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loopDetectionService.js","sourceRoot":"","sources":["../../../src/services/loopDetectionService.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AACpC,OAAO,EAAE,eAAe,EAA2B,MAAM,iBAAiB,CAAC;AAC3E,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,EAAE,iBAAiB,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"loopDetectionService.js","sourceRoot":"","sources":["../../../src/services/loopDetectionService.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AACpC,OAAO,EAAE,eAAe,EAA2B,MAAM,iBAAiB,CAAC;AAC3E,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,EAAE,iBAAiB,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AACpE,OAAO,EAAU,0BAA0B,EAAE,MAAM,qBAAqB,CAAC;AACzE,OAAO,EAAe,IAAI,EAAE,MAAM,eAAe,CAAC;AAElD,MAAM,wBAAwB,GAAG,CAAC,CAAC;AACnC,MAAM,sBAAsB,GAAG,EAAE,CAAC;AAElC;;GAEG;AACH,MAAM,4BAA4B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7
|
-
import { LoopDetectionService } from './loopDetectionService.js';
|
|
6
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
8
7
|
import { GeminiEventType, } from '../core/turn.js';
|
|
9
8
|
import * as loggers from '../telemetry/loggers.js';
|
|
9
|
+
import { LoopType } from '../telemetry/types.js';
|
|
10
|
+
import { LoopDetectionService } from './loopDetectionService.js';
|
|
10
11
|
vi.mock('../telemetry/loggers.js', () => ({
|
|
11
12
|
logLoopDetected: vi.fn(),
|
|
12
13
|
}));
|
|
@@ -76,6 +77,23 @@ describe('LoopDetectionService', () => {
|
|
|
76
77
|
expect(service.addAndCheck(event3)).toBe(false);
|
|
77
78
|
}
|
|
78
79
|
});
|
|
80
|
+
it('should not reset tool call counter for other event types', () => {
|
|
81
|
+
const toolCallEvent = createToolCallRequestEvent('testTool', {
|
|
82
|
+
param: 'value',
|
|
83
|
+
});
|
|
84
|
+
const otherEvent = {
|
|
85
|
+
type: 'thought',
|
|
86
|
+
};
|
|
87
|
+
// Send events just below the threshold
|
|
88
|
+
for (let i = 0; i < TOOL_CALL_LOOP_THRESHOLD - 1; i++) {
|
|
89
|
+
expect(service.addAndCheck(toolCallEvent)).toBe(false);
|
|
90
|
+
}
|
|
91
|
+
// Send a different event type
|
|
92
|
+
expect(service.addAndCheck(otherEvent)).toBe(false);
|
|
93
|
+
// Send the tool call event again, which should now trigger the loop
|
|
94
|
+
expect(service.addAndCheck(toolCallEvent)).toBe(true);
|
|
95
|
+
expect(loggers.logLoopDetected).toHaveBeenCalledTimes(1);
|
|
96
|
+
});
|
|
79
97
|
});
|
|
80
98
|
describe('Content Loop Detection', () => {
|
|
81
99
|
it(`should not detect a loop for fewer than CONTENT_LOOP_THRESHOLD identical content strings`, () => {
|
|
@@ -229,4 +247,93 @@ describe('LoopDetectionService', () => {
|
|
|
229
247
|
});
|
|
230
248
|
});
|
|
231
249
|
});
|
|
250
|
+
describe('LoopDetectionService LLM Checks', () => {
|
|
251
|
+
let service;
|
|
252
|
+
let mockConfig;
|
|
253
|
+
let mockGeminiClient;
|
|
254
|
+
let abortController;
|
|
255
|
+
beforeEach(() => {
|
|
256
|
+
mockGeminiClient = {
|
|
257
|
+
getHistory: vi.fn().mockReturnValue([]),
|
|
258
|
+
generateJson: vi.fn(),
|
|
259
|
+
};
|
|
260
|
+
mockConfig = {
|
|
261
|
+
getGeminiClient: () => mockGeminiClient,
|
|
262
|
+
getDebugMode: () => false,
|
|
263
|
+
getTelemetryEnabled: () => true,
|
|
264
|
+
};
|
|
265
|
+
service = new LoopDetectionService(mockConfig);
|
|
266
|
+
abortController = new AbortController();
|
|
267
|
+
vi.clearAllMocks();
|
|
268
|
+
});
|
|
269
|
+
afterEach(() => {
|
|
270
|
+
vi.restoreAllMocks();
|
|
271
|
+
});
|
|
272
|
+
const advanceTurns = async (count) => {
|
|
273
|
+
for (let i = 0; i < count; i++) {
|
|
274
|
+
await service.turnStarted(abortController.signal);
|
|
275
|
+
}
|
|
276
|
+
};
|
|
277
|
+
it('should not trigger LLM check before LLM_CHECK_AFTER_TURNS', async () => {
|
|
278
|
+
await advanceTurns(29);
|
|
279
|
+
expect(mockGeminiClient.generateJson).not.toHaveBeenCalled();
|
|
280
|
+
});
|
|
281
|
+
it('should trigger LLM check on the 30th turn', async () => {
|
|
282
|
+
mockGeminiClient.generateJson = vi
|
|
283
|
+
.fn()
|
|
284
|
+
.mockResolvedValue({ confidence: 0.1 });
|
|
285
|
+
await advanceTurns(30);
|
|
286
|
+
expect(mockGeminiClient.generateJson).toHaveBeenCalledTimes(1);
|
|
287
|
+
});
|
|
288
|
+
it('should detect a cognitive loop when confidence is high', async () => {
|
|
289
|
+
// First check at turn 30
|
|
290
|
+
mockGeminiClient.generateJson = vi
|
|
291
|
+
.fn()
|
|
292
|
+
.mockResolvedValue({ confidence: 0.85, reasoning: 'Repetitive actions' });
|
|
293
|
+
await advanceTurns(30);
|
|
294
|
+
expect(mockGeminiClient.generateJson).toHaveBeenCalledTimes(1);
|
|
295
|
+
// The confidence of 0.85 will result in a low interval.
|
|
296
|
+
// The interval will be: 5 + (15 - 5) * (1 - 0.85) = 5 + 10 * 0.15 = 6.5 -> rounded to 7
|
|
297
|
+
await advanceTurns(6); // advance to turn 36
|
|
298
|
+
mockGeminiClient.generateJson = vi
|
|
299
|
+
.fn()
|
|
300
|
+
.mockResolvedValue({ confidence: 0.95, reasoning: 'Repetitive actions' });
|
|
301
|
+
const finalResult = await service.turnStarted(abortController.signal); // This is turn 37
|
|
302
|
+
expect(finalResult).toBe(true);
|
|
303
|
+
expect(loggers.logLoopDetected).toHaveBeenCalledWith(mockConfig, expect.objectContaining({
|
|
304
|
+
'event.name': 'loop_detected',
|
|
305
|
+
loop_type: LoopType.LLM_DETECTED_LOOP,
|
|
306
|
+
}));
|
|
307
|
+
});
|
|
308
|
+
it('should not detect a loop when confidence is low', async () => {
|
|
309
|
+
mockGeminiClient.generateJson = vi
|
|
310
|
+
.fn()
|
|
311
|
+
.mockResolvedValue({ confidence: 0.5, reasoning: 'Looks okay' });
|
|
312
|
+
await advanceTurns(30);
|
|
313
|
+
const result = await service.turnStarted(abortController.signal);
|
|
314
|
+
expect(result).toBe(false);
|
|
315
|
+
expect(loggers.logLoopDetected).not.toHaveBeenCalled();
|
|
316
|
+
});
|
|
317
|
+
it('should adjust the check interval based on confidence', async () => {
|
|
318
|
+
// Confidence is 0.0, so interval should be MAX_LLM_CHECK_INTERVAL (15)
|
|
319
|
+
mockGeminiClient.generateJson = vi
|
|
320
|
+
.fn()
|
|
321
|
+
.mockResolvedValue({ confidence: 0.0 });
|
|
322
|
+
await advanceTurns(30); // First check at turn 30
|
|
323
|
+
expect(mockGeminiClient.generateJson).toHaveBeenCalledTimes(1);
|
|
324
|
+
await advanceTurns(14); // Advance to turn 44
|
|
325
|
+
expect(mockGeminiClient.generateJson).toHaveBeenCalledTimes(1);
|
|
326
|
+
await service.turnStarted(abortController.signal); // Turn 45
|
|
327
|
+
expect(mockGeminiClient.generateJson).toHaveBeenCalledTimes(2);
|
|
328
|
+
});
|
|
329
|
+
it('should handle errors from generateJson gracefully', async () => {
|
|
330
|
+
mockGeminiClient.generateJson = vi
|
|
331
|
+
.fn()
|
|
332
|
+
.mockRejectedValue(new Error('API error'));
|
|
333
|
+
await advanceTurns(30);
|
|
334
|
+
const result = await service.turnStarted(abortController.signal);
|
|
335
|
+
expect(result).toBe(false);
|
|
336
|
+
expect(loggers.logLoopDetected).not.toHaveBeenCalled();
|
|
337
|
+
});
|
|
338
|
+
});
|
|
232
339
|
//# sourceMappingURL=loopDetectionService.test.js.map
|