@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.
Files changed (327) hide show
  1. package/dist/src/adapters/IStreamAdapter.d.ts +18 -0
  2. package/dist/src/adapters/IStreamAdapter.js +7 -0
  3. package/dist/src/adapters/IStreamAdapter.js.map +1 -0
  4. package/dist/src/code_assist/oauth2.d.ts +1 -1
  5. package/dist/src/code_assist/oauth2.js +51 -29
  6. package/dist/src/code_assist/oauth2.js.map +1 -1
  7. package/dist/src/code_assist/oauth2.test.js +36 -7
  8. package/dist/src/code_assist/oauth2.test.js.map +1 -1
  9. package/dist/src/code_assist/server.test.js +10 -2
  10. package/dist/src/code_assist/server.test.js.map +1 -1
  11. package/dist/src/config/config.d.ts +28 -5
  12. package/dist/src/config/config.js +29 -4
  13. package/dist/src/config/config.js.map +1 -1
  14. package/dist/src/config/config.test.js +2 -3
  15. package/dist/src/config/config.test.js.map +1 -1
  16. package/dist/src/core/client.d.ts +4 -2
  17. package/dist/src/core/client.js +68 -7
  18. package/dist/src/core/client.js.map +1 -1
  19. package/dist/src/core/client.test.js +8 -0
  20. package/dist/src/core/client.test.js.map +1 -1
  21. package/dist/src/core/contentGenerator.d.ts +3 -2
  22. package/dist/src/core/contentGenerator.js +6 -8
  23. package/dist/src/core/contentGenerator.js.map +1 -1
  24. package/dist/src/core/contentGenerator.test.js +12 -5
  25. package/dist/src/core/contentGenerator.test.js.map +1 -1
  26. package/dist/src/core/coreToolScheduler.test.js +4 -2
  27. package/dist/src/core/coreToolScheduler.test.js.map +1 -1
  28. package/dist/src/core/geminiChat.js +50 -3
  29. package/dist/src/core/geminiChat.js.map +1 -1
  30. package/dist/src/core/modelCheck.d.ts +1 -1
  31. package/dist/src/core/modelCheck.js +10 -3
  32. package/dist/src/core/modelCheck.js.map +1 -1
  33. package/dist/src/core/nonInteractiveToolExecutor.test.js +3 -0
  34. package/dist/src/core/nonInteractiveToolExecutor.test.js.map +1 -1
  35. package/dist/src/core/prompts.d.ts +1 -1
  36. package/dist/src/core/prompts.js +14 -2
  37. package/dist/src/core/prompts.js.map +1 -1
  38. package/dist/src/core/turn.js +6 -0
  39. package/dist/src/core/turn.js.map +1 -1
  40. package/dist/src/index.d.ts +29 -1
  41. package/dist/src/index.js +33 -0
  42. package/dist/src/index.js.map +1 -1
  43. package/dist/src/mcp/oauth-provider.d.ts +142 -0
  44. package/dist/src/mcp/oauth-provider.js +446 -0
  45. package/dist/src/mcp/oauth-provider.js.map +1 -0
  46. package/dist/src/mcp/oauth-provider.test.js +520 -0
  47. package/dist/src/mcp/oauth-provider.test.js.map +1 -0
  48. package/dist/src/mcp/oauth-token-storage.d.ts +81 -0
  49. package/dist/src/mcp/oauth-token-storage.js +149 -0
  50. package/dist/src/mcp/oauth-token-storage.js.map +1 -0
  51. package/dist/src/mcp/oauth-token-storage.test.d.ts +6 -0
  52. package/dist/src/mcp/oauth-token-storage.test.js +205 -0
  53. package/dist/src/mcp/oauth-token-storage.test.js.map +1 -0
  54. package/dist/src/mcp/oauth-utils.d.ts +109 -0
  55. package/dist/src/mcp/oauth-utils.js +183 -0
  56. package/dist/src/mcp/oauth-utils.js.map +1 -0
  57. package/dist/src/mcp/oauth-utils.test.d.ts +6 -0
  58. package/dist/src/mcp/oauth-utils.test.js +144 -0
  59. package/dist/src/mcp/oauth-utils.test.js.map +1 -0
  60. package/dist/src/parsers/TextToolCallParser.d.ts +35 -0
  61. package/dist/src/parsers/TextToolCallParser.js +248 -0
  62. package/dist/src/parsers/TextToolCallParser.js.map +1 -0
  63. package/dist/src/parsers/TextToolCallParser.test.d.ts +1 -0
  64. package/dist/src/parsers/TextToolCallParser.test.js +225 -0
  65. package/dist/src/parsers/TextToolCallParser.test.js.map +1 -0
  66. package/dist/src/providers/ContentGeneratorRole.d.ts +14 -0
  67. package/dist/src/providers/ContentGeneratorRole.js +16 -0
  68. package/dist/src/providers/ContentGeneratorRole.js.map +1 -0
  69. package/dist/src/providers/IMessage.d.ts +38 -0
  70. package/dist/src/providers/IMessage.js +17 -0
  71. package/dist/src/providers/IMessage.js.map +1 -0
  72. package/dist/src/providers/IModel.d.ts +23 -0
  73. package/dist/src/providers/IModel.js +17 -0
  74. package/dist/src/providers/IModel.js.map +1 -0
  75. package/dist/src/providers/IProvider.d.ts +36 -0
  76. package/dist/src/providers/IProvider.js +17 -0
  77. package/dist/src/providers/IProvider.js.map +1 -0
  78. package/dist/src/providers/IProviderConfig.d.ts +31 -0
  79. package/dist/src/providers/IProviderConfig.js +7 -0
  80. package/dist/src/providers/IProviderConfig.js.map +1 -0
  81. package/dist/src/providers/IProviderManager.d.ts +53 -0
  82. package/dist/src/providers/IProviderManager.js +7 -0
  83. package/dist/src/providers/IProviderManager.js.map +1 -0
  84. package/dist/src/providers/ITool.d.ts +23 -0
  85. package/dist/src/providers/ITool.js +17 -0
  86. package/dist/src/providers/ITool.js.map +1 -0
  87. package/dist/src/providers/ProviderContentGenerator.d.ts +1 -1
  88. package/dist/src/providers/ProviderManager.d.ts +24 -0
  89. package/dist/src/providers/ProviderManager.gemini-switch.test.d.ts +6 -0
  90. package/dist/src/providers/ProviderManager.gemini-switch.test.js +57 -0
  91. package/dist/src/providers/ProviderManager.gemini-switch.test.js.map +1 -0
  92. package/dist/src/providers/ProviderManager.js +116 -0
  93. package/dist/src/providers/ProviderManager.js.map +1 -0
  94. package/dist/src/providers/ProviderManager.test.d.ts +6 -0
  95. package/dist/src/providers/ProviderManager.test.js +284 -0
  96. package/dist/src/providers/ProviderManager.test.js.map +1 -0
  97. package/dist/src/providers/adapters/GeminiCompatibleWrapper.d.ts +2 -1
  98. package/dist/src/providers/adapters/GeminiCompatibleWrapper.js +15 -2
  99. package/dist/src/providers/adapters/GeminiCompatibleWrapper.js.map +1 -1
  100. package/dist/src/providers/adapters/GeminiCompatibleWrapper.test.js +20 -0
  101. package/dist/src/providers/adapters/GeminiCompatibleWrapper.test.js.map +1 -1
  102. package/dist/src/providers/anthropic/AnthropicProvider.d.ts +57 -0
  103. package/dist/src/providers/anthropic/AnthropicProvider.js +490 -0
  104. package/dist/src/providers/anthropic/AnthropicProvider.js.map +1 -0
  105. package/dist/src/providers/anthropic/AnthropicProvider.test.d.ts +1 -0
  106. package/dist/src/providers/anthropic/AnthropicProvider.test.js +486 -0
  107. package/dist/src/providers/anthropic/AnthropicProvider.test.js.map +1 -0
  108. package/dist/src/providers/errors.d.ts +13 -0
  109. package/dist/src/providers/errors.js +19 -0
  110. package/dist/src/providers/errors.js.map +1 -0
  111. package/dist/src/providers/gemini/GeminiProvider.d.ts +97 -0
  112. package/dist/src/providers/gemini/GeminiProvider.integration.test.d.ts +6 -0
  113. package/dist/src/providers/gemini/GeminiProvider.integration.test.js +90 -0
  114. package/dist/src/providers/gemini/GeminiProvider.integration.test.js.map +1 -0
  115. package/dist/src/providers/gemini/GeminiProvider.js +937 -0
  116. package/dist/src/providers/gemini/GeminiProvider.js.map +1 -0
  117. package/dist/src/providers/gemini/GeminiProvider.test.d.ts +6 -0
  118. package/dist/src/providers/gemini/GeminiProvider.test.js +136 -0
  119. package/dist/src/providers/gemini/GeminiProvider.test.js.map +1 -0
  120. package/dist/src/providers/integration/TEST_INSTRUCTIONS.md +197 -0
  121. package/dist/src/providers/integration/multi-provider.integration.test.d.ts +6 -0
  122. package/dist/src/providers/integration/multi-provider.integration.test.js +292 -0
  123. package/dist/src/providers/integration/multi-provider.integration.test.js.map +1 -0
  124. package/dist/src/providers/openai/ConversationCache.accumTokens.test.d.ts +1 -0
  125. package/dist/src/providers/openai/ConversationCache.accumTokens.test.js +97 -0
  126. package/dist/src/providers/openai/ConversationCache.accumTokens.test.js.map +1 -0
  127. package/dist/src/providers/openai/ConversationCache.d.ts +20 -0
  128. package/dist/src/providers/openai/ConversationCache.js +109 -0
  129. package/dist/src/providers/openai/ConversationCache.js.map +1 -0
  130. package/dist/src/providers/openai/ConversationCache.test.d.ts +1 -0
  131. package/dist/src/providers/openai/ConversationCache.test.js +113 -0
  132. package/dist/src/providers/openai/ConversationCache.test.js.map +1 -0
  133. package/dist/src/providers/openai/IChatGenerateParams.d.ts +11 -0
  134. package/dist/src/providers/openai/IChatGenerateParams.js +2 -0
  135. package/dist/src/providers/openai/IChatGenerateParams.js.map +1 -0
  136. package/dist/src/providers/openai/OpenAIProvider.callResponses.stateless.test.d.ts +1 -0
  137. package/dist/src/providers/openai/OpenAIProvider.callResponses.stateless.test.js +189 -0
  138. package/dist/src/providers/openai/OpenAIProvider.callResponses.stateless.test.js.map +1 -0
  139. package/dist/src/providers/openai/OpenAIProvider.d.ts +80 -0
  140. package/dist/src/providers/openai/OpenAIProvider.integration.test.d.ts +6 -0
  141. package/dist/src/providers/openai/OpenAIProvider.integration.test.js +125 -0
  142. package/dist/src/providers/openai/OpenAIProvider.integration.test.js.map +1 -0
  143. package/dist/src/providers/openai/OpenAIProvider.js +523 -0
  144. package/dist/src/providers/openai/OpenAIProvider.js.map +1 -0
  145. package/dist/src/providers/openai/OpenAIProvider.responses.test.d.ts +1 -0
  146. package/dist/src/providers/openai/OpenAIProvider.responses.test.js +326 -0
  147. package/dist/src/providers/openai/OpenAIProvider.responses.test.js.map +1 -0
  148. package/dist/src/providers/openai/OpenAIProvider.responsesIntegration.test.d.ts +1 -0
  149. package/dist/src/providers/openai/OpenAIProvider.responsesIntegration.test.js +213 -0
  150. package/dist/src/providers/openai/OpenAIProvider.responsesIntegration.test.js.map +1 -0
  151. package/dist/src/providers/openai/OpenAIProvider.shouldUseResponses.test.d.ts +1 -0
  152. package/dist/src/providers/openai/OpenAIProvider.shouldUseResponses.test.js +58 -0
  153. package/dist/src/providers/openai/OpenAIProvider.shouldUseResponses.test.js.map +1 -0
  154. package/dist/src/providers/openai/OpenAIProvider.stateful.integration.test.d.ts +6 -0
  155. package/dist/src/providers/openai/OpenAIProvider.stateful.integration.test.js +105 -0
  156. package/dist/src/providers/openai/OpenAIProvider.stateful.integration.test.js.map +1 -0
  157. package/dist/src/providers/openai/OpenAIProvider.switch.test.d.ts +1 -0
  158. package/dist/src/providers/openai/OpenAIProvider.switch.test.js +256 -0
  159. package/dist/src/providers/openai/OpenAIProvider.switch.test.js.map +1 -0
  160. package/dist/src/providers/openai/OpenAIProvider.test.d.ts +16 -0
  161. package/dist/src/providers/openai/OpenAIProvider.test.js +214 -0
  162. package/dist/src/providers/openai/OpenAIProvider.test.js.map +1 -0
  163. package/dist/src/providers/openai/RESPONSES_API_MODELS.d.ts +2 -0
  164. package/dist/src/providers/openai/RESPONSES_API_MODELS.js +14 -0
  165. package/dist/src/providers/openai/RESPONSES_API_MODELS.js.map +1 -0
  166. package/dist/src/providers/openai/ResponsesContextTrim.integration.test.d.ts +1 -0
  167. package/dist/src/providers/openai/ResponsesContextTrim.integration.test.js +210 -0
  168. package/dist/src/providers/openai/ResponsesContextTrim.integration.test.js.map +1 -0
  169. package/dist/src/providers/openai/__tests__/formatArrayResponse.test.d.ts +1 -0
  170. package/dist/src/providers/openai/__tests__/formatArrayResponse.test.js +65 -0
  171. package/dist/src/providers/openai/__tests__/formatArrayResponse.test.js.map +1 -0
  172. package/dist/src/providers/openai/buildResponsesRequest.d.ts +73 -0
  173. package/dist/src/providers/openai/buildResponsesRequest.js +165 -0
  174. package/dist/src/providers/openai/buildResponsesRequest.js.map +1 -0
  175. package/dist/src/providers/openai/buildResponsesRequest.stripToolCalls.test.d.ts +1 -0
  176. package/dist/src/providers/openai/buildResponsesRequest.stripToolCalls.test.js +129 -0
  177. package/dist/src/providers/openai/buildResponsesRequest.stripToolCalls.test.js.map +1 -0
  178. package/dist/src/providers/openai/buildResponsesRequest.test.d.ts +1 -0
  179. package/dist/src/providers/openai/buildResponsesRequest.test.js +406 -0
  180. package/dist/src/providers/openai/buildResponsesRequest.test.js.map +1 -0
  181. package/dist/src/providers/openai/buildResponsesRequest.undefined.test.d.ts +1 -0
  182. package/dist/src/providers/openai/buildResponsesRequest.undefined.test.js +50 -0
  183. package/dist/src/providers/openai/buildResponsesRequest.undefined.test.js.map +1 -0
  184. package/dist/src/providers/openai/docs/accessing-provider-info.md +172 -0
  185. package/dist/src/providers/openai/docs/params-mapping.md +91 -0
  186. package/dist/src/providers/openai/docs/responses-api-tool-calls.md +96 -0
  187. package/dist/src/providers/openai/estimateRemoteTokens.d.ts +26 -0
  188. package/dist/src/providers/openai/estimateRemoteTokens.js +75 -0
  189. package/dist/src/providers/openai/estimateRemoteTokens.js.map +1 -0
  190. package/dist/src/providers/openai/estimateRemoteTokens.test.d.ts +1 -0
  191. package/dist/src/providers/openai/estimateRemoteTokens.test.js +125 -0
  192. package/dist/src/providers/openai/estimateRemoteTokens.test.js.map +1 -0
  193. package/dist/src/providers/openai/getOpenAIProviderInfo.d.ts +46 -0
  194. package/dist/src/providers/openai/getOpenAIProviderInfo.js +75 -0
  195. package/dist/src/providers/openai/getOpenAIProviderInfo.js.map +1 -0
  196. package/dist/src/providers/openai/parseResponsesStream.d.ts +3 -0
  197. package/dist/src/providers/openai/parseResponsesStream.js +462 -0
  198. package/dist/src/providers/openai/parseResponsesStream.js.map +1 -0
  199. package/dist/src/providers/openai/parseResponsesStream.responsesToolCalls.test.d.ts +1 -0
  200. package/dist/src/providers/openai/parseResponsesStream.responsesToolCalls.test.js +192 -0
  201. package/dist/src/providers/openai/parseResponsesStream.responsesToolCalls.test.js.map +1 -0
  202. package/dist/src/providers/openai/parseResponsesStream.test.d.ts +1 -0
  203. package/dist/src/providers/openai/parseResponsesStream.test.js +151 -0
  204. package/dist/src/providers/openai/parseResponsesStream.test.js.map +1 -0
  205. package/dist/src/providers/tokenizers/AnthropicTokenizer.d.ts +19 -0
  206. package/dist/src/providers/tokenizers/AnthropicTokenizer.js +37 -0
  207. package/dist/src/providers/tokenizers/AnthropicTokenizer.js.map +1 -0
  208. package/dist/src/providers/tokenizers/ITokenizer.d.ts +18 -0
  209. package/dist/src/providers/tokenizers/ITokenizer.js +17 -0
  210. package/dist/src/providers/tokenizers/ITokenizer.js.map +1 -0
  211. package/dist/src/providers/tokenizers/OpenAITokenizer.d.ts +24 -0
  212. package/dist/src/providers/tokenizers/OpenAITokenizer.js +56 -0
  213. package/dist/src/providers/tokenizers/OpenAITokenizer.js.map +1 -0
  214. package/dist/src/providers/types/IProviderConfig.d.ts +102 -0
  215. package/dist/src/providers/types/IProviderConfig.js +17 -0
  216. package/dist/src/providers/types/IProviderConfig.js.map +1 -0
  217. package/dist/src/providers/types.d.ts +4 -69
  218. package/dist/src/services/ideContext.d.ts +2 -0
  219. package/dist/src/services/ideContext.js +8 -0
  220. package/dist/src/services/ideContext.js.map +1 -1
  221. package/dist/src/services/ideContext.test.js +10 -0
  222. package/dist/src/services/ideContext.test.js.map +1 -1
  223. package/dist/src/services/loopDetectionService.d.ts +17 -1
  224. package/dist/src/services/loopDetectionService.js +117 -2
  225. package/dist/src/services/loopDetectionService.js.map +1 -1
  226. package/dist/src/services/loopDetectionService.test.js +109 -2
  227. package/dist/src/services/loopDetectionService.test.js.map +1 -1
  228. package/dist/src/telemetry/clearcut-logger/clearcut-logger.d.ts +2 -0
  229. package/dist/src/telemetry/clearcut-logger/clearcut-logger.js +40 -2
  230. package/dist/src/telemetry/clearcut-logger/clearcut-logger.js.map +1 -1
  231. package/dist/src/telemetry/clearcut-logger/event-metadata-key.d.ts +2 -0
  232. package/dist/src/telemetry/clearcut-logger/event-metadata-key.js +4 -0
  233. package/dist/src/telemetry/clearcut-logger/event-metadata-key.js.map +1 -1
  234. package/dist/src/telemetry/sdk.js +0 -2
  235. package/dist/src/telemetry/sdk.js.map +1 -1
  236. package/dist/src/telemetry/types.d.ts +2 -1
  237. package/dist/src/telemetry/types.js +1 -0
  238. package/dist/src/telemetry/types.js.map +1 -1
  239. package/dist/src/telemetry/uiTelemetry.d.ts +1 -0
  240. package/dist/src/telemetry/uiTelemetry.js +7 -0
  241. package/dist/src/telemetry/uiTelemetry.js.map +1 -1
  242. package/dist/src/telemetry/uiTelemetry.test.js +92 -0
  243. package/dist/src/telemetry/uiTelemetry.test.js.map +1 -1
  244. package/dist/src/tools/IToolFormatter.d.ts +40 -0
  245. package/dist/src/tools/IToolFormatter.js +17 -0
  246. package/dist/src/tools/IToolFormatter.js.map +1 -0
  247. package/dist/src/tools/ToolFormatter.d.ts +45 -0
  248. package/dist/src/tools/ToolFormatter.js +216 -0
  249. package/dist/src/tools/ToolFormatter.js.map +1 -0
  250. package/dist/src/tools/ToolFormatter.test.d.ts +16 -0
  251. package/dist/src/tools/ToolFormatter.test.js +349 -0
  252. package/dist/src/tools/ToolFormatter.test.js.map +1 -0
  253. package/dist/src/tools/ToolFormatter.toResponsesTool.test.d.ts +1 -0
  254. package/dist/src/tools/ToolFormatter.toResponsesTool.test.js +241 -0
  255. package/dist/src/tools/ToolFormatter.toResponsesTool.test.js.map +1 -0
  256. package/dist/src/tools/edit.d.ts +7 -1
  257. package/dist/src/tools/edit.js +19 -7
  258. package/dist/src/tools/edit.js.map +1 -1
  259. package/dist/src/tools/glob.js +2 -2
  260. package/dist/src/tools/glob.js.map +1 -1
  261. package/dist/src/tools/grep.js +2 -2
  262. package/dist/src/tools/grep.js.map +1 -1
  263. package/dist/src/tools/ls.js +2 -2
  264. package/dist/src/tools/ls.js.map +1 -1
  265. package/dist/src/tools/mcp-client.d.ts +0 -2
  266. package/dist/src/tools/mcp-client.js +8 -20
  267. package/dist/src/tools/mcp-client.js.map +1 -1
  268. package/dist/src/tools/mcp-client.test.js +1 -72
  269. package/dist/src/tools/mcp-client.test.js.map +1 -1
  270. package/dist/src/tools/mcp-tool.d.ts +11 -5
  271. package/dist/src/tools/mcp-tool.js +33 -9
  272. package/dist/src/tools/mcp-tool.js.map +1 -1
  273. package/dist/src/tools/mcp-tool.test.js +40 -24
  274. package/dist/src/tools/mcp-tool.test.js.map +1 -1
  275. package/dist/src/tools/memoryTool.js +2 -2
  276. package/dist/src/tools/memoryTool.js.map +1 -1
  277. package/dist/src/tools/read-file.d.ts +2 -1
  278. package/dist/src/tools/read-file.js +5 -2
  279. package/dist/src/tools/read-file.js.map +1 -1
  280. package/dist/src/tools/read-many-files.js +2 -2
  281. package/dist/src/tools/read-many-files.js.map +1 -1
  282. package/dist/src/tools/shell.js +2 -2
  283. package/dist/src/tools/shell.js.map +1 -1
  284. package/dist/src/tools/todo-read.js +2 -2
  285. package/dist/src/tools/todo-read.js.map +1 -1
  286. package/dist/src/tools/todo-write.js +2 -2
  287. package/dist/src/tools/todo-write.js.map +1 -1
  288. package/dist/src/tools/tool-registry.d.ts +0 -1
  289. package/dist/src/tools/tool-registry.js +11 -8
  290. package/dist/src/tools/tool-registry.js.map +1 -1
  291. package/dist/src/tools/tool-registry.test.js +36 -10
  292. package/dist/src/tools/tool-registry.test.js.map +1 -1
  293. package/dist/src/tools/tools.d.ts +37 -2
  294. package/dist/src/tools/tools.js +25 -2
  295. package/dist/src/tools/tools.js.map +1 -1
  296. package/dist/src/tools/web-fetch.integration.test.d.ts +6 -0
  297. package/dist/src/tools/web-fetch.integration.test.js +532 -0
  298. package/dist/src/tools/web-fetch.integration.test.js.map +1 -0
  299. package/dist/src/tools/web-fetch.js +57 -50
  300. package/dist/src/tools/web-fetch.js.map +1 -1
  301. package/dist/src/tools/web-search.js +34 -6
  302. package/dist/src/tools/web-search.js.map +1 -1
  303. package/dist/src/tools/web-search.test.d.ts +6 -0
  304. package/dist/src/tools/web-search.test.js +229 -0
  305. package/dist/src/tools/web-search.test.js.map +1 -0
  306. package/dist/src/tools/write-file.js +12 -5
  307. package/dist/src/tools/write-file.js.map +1 -1
  308. package/dist/src/utils/browser.d.ts +13 -0
  309. package/dist/src/utils/browser.js +49 -0
  310. package/dist/src/utils/browser.js.map +1 -0
  311. package/dist/src/utils/errors.js +4 -4
  312. package/dist/src/utils/errors.js.map +1 -1
  313. package/dist/src/utils/memoryDiscovery.js +5 -1
  314. package/dist/src/utils/memoryDiscovery.js.map +1 -1
  315. package/dist/src/utils/quotaErrorDetection.js +0 -2
  316. package/dist/src/utils/quotaErrorDetection.js.map +1 -1
  317. package/dist/src/utils/retry.d.ts +6 -0
  318. package/dist/src/utils/retry.js +1 -1
  319. package/dist/src/utils/retry.js.map +1 -1
  320. package/dist/src/utils/user_account.js +6 -1
  321. package/dist/src/utils/user_account.js.map +1 -1
  322. package/dist/tsconfig.tsbuildinfo +1 -1
  323. package/package.json +6 -3
  324. package/dist/src/tools/web-fetch.test.js +0 -70
  325. package/dist/src/tools/web-fetch.test.js.map +0 -1
  326. package/dist/vybestack-llxprt-code-core-0.1.12.tgz +0 -0
  327. /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
- import type { Part } from '@google/genai';
7
- /**
8
- * Represents a message in a provider's format
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,G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,iBAAiB,GAAG,SAAS,CAAC;QAC9B,iBAAiB,EAAE,CAAC;IACtB,CAAC;IAED;;;OAGG;IACH,SAAS,oBAAoB;QAC3B,OAAO,iBAAiB,CAAC;IAC3B,CAAC;IAED;;;;;;;;OAQG;IACH,SAAS,qBAAqB,CAAC,UAAgC;QAC7D,WAAW,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;QAC5B,OAAO,GAAG,EAAE;YACV,WAAW,CAAC,MAAM,CAAC,UAAU,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,G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AO,CAAC,QAAQ,CAAC,CAAC;QAE5D,UAAU,CAAC,sBAAsB,EAAE,CAAC;QAEpC,MAAM,CAAC,UAAU,CAAC,oBAAoB,EAAE,CAAC,CAAC,aAAa,EAAE,CAAC;IAC5D,CAAC,CAAC,CAAC;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 config;
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
- config;
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;AAGpE,MAAM,wBAAwB,GAAG,CAAC,CAAC;AACnC,MAAM,sBAAsB,GAAG,EAAE,CAAC;AAClC,MAAM,iCAAiC,GAAG,gBAAgB,CAAC;AAE3D;;;GAGG;AACH,MAAM,OAAO,oBAAoB;IAC/B,qBAAqB;IACb,eAAe,GAAkB,IAAI,CAAC;IACtC,uBAAuB,GAAW,CAAC,CAAC;IAE5C,6BAA6B;IACrB,oBAAoB,GAAW,EAAE,CAAC;IAClC,uBAAuB,GAAW,CAAC,CAAC;IACpC,cAAc,GAAW,EAAE,CAAC;IAC5B,MAAM,CAAS;IAEvB,YAAY,MAAc;QACxB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;IAEO,cAAc,CAAC,QAAwC;QAC7D,MAAM,UAAU,GAAG,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;QACjD,MAAM,SAAS,GAAG,GAAG,QAAQ,CAAC,IAAI,IAAI,UAAU,EAAE,CAA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ACpB,CAAC,sBAAsB,GAAG,sBAAsB,CAAC;wBAC/C,CAAC,CAAC,GAAG,MAAM,CAAC,UAAU,CAAC,CAC5B,CAAC;YACJ,CAAC;QACH,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IAED;;OAEG;IACH,KAAK;QACH,IAAI,CAAC,kBAAkB,EAAE,CAAC;QAC1B,IAAI,CAAC,kBAAkB,EAAE,CAAC;QAC1B,IAAI,CAAC,qBAAqB,EAAE,CAAC;IAC/B,CAAC;IAEO,kBAAkB;QACxB,IAAI,CAAC,eAAe,GAAG,IAAI,CAAC;QAC5B,IAAI,CAAC,uBAAuB,GAAG,CAAC,CAAC;IACnC,CAAC;IAEO,kBAAkB;QACxB,IAAI,CAAC,oBAAoB,GAAG,EAAE,CAAC;QAC/B,IAAI,CAAC,uBAAuB,GAAG,CAAC,CAAC;QACjC,IAAI,CAAC,cAAc,GAAG,EAAE,CAAC;IAC3B,CAAC;IAEO,qBAAqB;QAC3B,IAAI,CAAC,oBAAoB,GAAG,CAAC,CAAC;QAC9B,IAAI,CAAC,gBAAgB,GAAG,0BAA0B,CAAC;QACnD,IAAI,CAAC,aAAa,GAAG,CAAC,CAAC;IACzB,CAAC;CACF"}
@@ -3,10 +3,11 @@
3
3
  * Copyright 2025 Google LLC
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
- import { describe, it, expect, beforeEach, vi } from 'vitest';
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