@hibanacloud/core 0.3.15

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