@machina.ai/cell-cli-core 1.0.21-rc4 → 1.4.0-rc1

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 (505) hide show
  1. package/dist/index.d.ts +6 -2
  2. package/dist/index.js +6 -2
  3. package/dist/index.js.map +1 -1
  4. package/dist/package.json +25 -11
  5. package/dist/src/code_assist/codeAssist.d.ts +6 -3
  6. package/dist/src/code_assist/codeAssist.js +12 -0
  7. package/dist/src/code_assist/codeAssist.js.map +1 -1
  8. package/dist/src/code_assist/converter.d.ts +3 -1
  9. package/dist/src/code_assist/converter.js +37 -5
  10. package/dist/src/code_assist/converter.js.map +1 -1
  11. package/dist/src/code_assist/converter.test.js +83 -0
  12. package/dist/src/code_assist/converter.test.js.map +1 -1
  13. package/dist/src/code_assist/oauth2.d.ts +2 -1
  14. package/dist/src/code_assist/oauth2.js +85 -49
  15. package/dist/src/code_assist/oauth2.js.map +1 -1
  16. package/dist/src/code_assist/oauth2.test.js +317 -15
  17. package/dist/src/code_assist/oauth2.test.js.map +1 -1
  18. package/dist/src/code_assist/server.d.ts +5 -5
  19. package/dist/src/code_assist/server.js +1 -1
  20. package/dist/src/code_assist/server.js.map +1 -1
  21. package/dist/src/code_assist/setup.d.ts +1 -1
  22. package/dist/src/code_assist/setup.js +1 -1
  23. package/dist/src/code_assist/setup.js.map +1 -1
  24. package/dist/src/code_assist/setup.test.js.map +1 -1
  25. package/dist/src/config/config.d.ts +53 -15
  26. package/dist/src/config/config.js +127 -47
  27. package/dist/src/config/config.js.map +1 -1
  28. package/dist/src/config/config.test.js +151 -6
  29. package/dist/src/config/config.test.js.map +1 -1
  30. package/dist/src/config/models.d.ts +1 -0
  31. package/dist/src/config/models.js +2 -0
  32. package/dist/src/config/models.js.map +1 -1
  33. package/dist/src/config/storage.d.ts +32 -0
  34. package/dist/src/config/storage.js +90 -0
  35. package/dist/src/config/storage.js.map +1 -0
  36. package/dist/src/config/storage.test.js +43 -0
  37. package/dist/src/config/storage.test.js.map +1 -0
  38. package/dist/src/core/client.d.ts +21 -11
  39. package/dist/src/core/client.js +83 -26
  40. package/dist/src/core/client.js.map +1 -1
  41. package/dist/src/core/client.test.js +398 -88
  42. package/dist/src/core/client.test.js.map +1 -1
  43. package/dist/src/core/contentGenerator.d.ts +6 -6
  44. package/dist/src/core/contentGenerator.js +4 -3
  45. package/dist/src/core/contentGenerator.js.map +1 -1
  46. package/dist/src/core/contentGenerator.test.js.map +1 -1
  47. package/dist/src/core/coreToolScheduler.d.ts +14 -5
  48. package/dist/src/core/coreToolScheduler.js +120 -49
  49. package/dist/src/core/coreToolScheduler.js.map +1 -1
  50. package/dist/src/core/coreToolScheduler.test.js +383 -72
  51. package/dist/src/core/coreToolScheduler.test.js.map +1 -1
  52. package/dist/src/core/geminiChat.d.ts +48 -15
  53. package/dist/src/core/geminiChat.js +327 -154
  54. package/dist/src/core/geminiChat.js.map +1 -1
  55. package/dist/src/core/geminiChat.test.js +1041 -257
  56. package/dist/src/core/geminiChat.test.js.map +1 -1
  57. package/dist/src/core/geminiRequest.js +1 -0
  58. package/dist/src/core/geminiRequest.js.map +1 -1
  59. package/dist/src/core/logger.d.ts +4 -2
  60. package/dist/src/core/logger.js +4 -3
  61. package/dist/src/core/logger.js.map +1 -1
  62. package/dist/src/core/logger.test.js +19 -18
  63. package/dist/src/core/logger.test.js.map +1 -1
  64. package/dist/src/core/loggingContentGenerator.d.ts +3 -3
  65. package/dist/src/core/loggingContentGenerator.js +11 -9
  66. package/dist/src/core/loggingContentGenerator.js.map +1 -1
  67. package/dist/src/core/nonInteractiveToolExecutor.d.ts +3 -5
  68. package/dist/src/core/nonInteractiveToolExecutor.js +15 -123
  69. package/dist/src/core/nonInteractiveToolExecutor.js.map +1 -1
  70. package/dist/src/core/nonInteractiveToolExecutor.test.js +116 -90
  71. package/dist/src/core/nonInteractiveToolExecutor.test.js.map +1 -1
  72. package/dist/src/core/prompts.js +8 -7
  73. package/dist/src/core/prompts.js.map +1 -1
  74. package/dist/src/core/prompts.test.js +21 -21
  75. package/dist/src/core/prompts.test.js.map +1 -1
  76. package/dist/src/core/subagent.d.ts +24 -18
  77. package/dist/src/core/subagent.js +126 -89
  78. package/dist/src/core/subagent.js.map +1 -1
  79. package/dist/src/core/subagent.test.js +51 -35
  80. package/dist/src/core/subagent.test.js.map +1 -1
  81. package/dist/src/core/turn.d.ts +33 -8
  82. package/dist/src/core/turn.js +59 -14
  83. package/dist/src/core/turn.js.map +1 -1
  84. package/dist/src/core/turn.test.js +349 -90
  85. package/dist/src/core/turn.test.js.map +1 -1
  86. package/dist/src/generated/git-commit.d.ts +2 -2
  87. package/dist/src/generated/git-commit.js +2 -2
  88. package/dist/src/generated/git-commit.js.map +1 -1
  89. package/dist/src/ide/constants.d.ts +1 -1
  90. package/dist/src/ide/constants.js +1 -1
  91. package/dist/src/ide/constants.js.map +1 -1
  92. package/dist/src/ide/detect-ide.d.ts +8 -3
  93. package/dist/src/ide/detect-ide.js +29 -11
  94. package/dist/src/ide/detect-ide.js.map +1 -1
  95. package/dist/src/ide/detect-ide.test.js +96 -52
  96. package/dist/src/ide/detect-ide.test.js.map +1 -1
  97. package/dist/src/ide/ide-client.d.ts +18 -9
  98. package/dist/src/ide/ide-client.js +151 -33
  99. package/dist/src/ide/ide-client.js.map +1 -1
  100. package/dist/src/ide/ide-client.test.js +147 -25
  101. package/dist/src/ide/ide-client.test.js.map +1 -1
  102. package/dist/src/ide/ide-installer.d.ts +1 -1
  103. package/dist/src/ide/ide-installer.js +31 -22
  104. package/dist/src/ide/ide-installer.js.map +1 -1
  105. package/dist/src/ide/ide-installer.test.js +82 -22
  106. package/dist/src/ide/ide-installer.test.js.map +1 -1
  107. package/dist/src/ide/ideContext.d.ts +12 -0
  108. package/dist/src/ide/ideContext.js +1 -0
  109. package/dist/src/ide/ideContext.js.map +1 -1
  110. package/dist/src/ide/process-utils.d.ts +13 -6
  111. package/dist/src/ide/process-utils.js +142 -35
  112. package/dist/src/ide/process-utils.js.map +1 -1
  113. package/dist/src/ide/process-utils.test.js +158 -0
  114. package/dist/src/ide/process-utils.test.js.map +1 -0
  115. package/dist/src/index.d.ts +12 -2
  116. package/dist/src/index.js +11 -1
  117. package/dist/src/index.js.map +1 -1
  118. package/dist/src/mcp/google-auth-provider.d.ts +3 -3
  119. package/dist/src/mcp/google-auth-provider.test.js.map +1 -1
  120. package/dist/src/mcp/oauth-provider.d.ts +13 -13
  121. package/dist/src/mcp/oauth-provider.js +32 -31
  122. package/dist/src/mcp/oauth-provider.js.map +1 -1
  123. package/dist/src/mcp/oauth-provider.test.js +75 -36
  124. package/dist/src/mcp/oauth-provider.test.js.map +1 -1
  125. package/dist/src/mcp/oauth-token-storage.d.ts +9 -31
  126. package/dist/src/mcp/oauth-token-storage.js +10 -13
  127. package/dist/src/mcp/oauth-token-storage.js.map +1 -1
  128. package/dist/src/mcp/oauth-token-storage.test.js +30 -27
  129. package/dist/src/mcp/oauth-token-storage.test.js.map +1 -1
  130. package/dist/src/mcp/oauth-utils.d.ts +9 -1
  131. package/dist/src/mcp/oauth-utils.js +41 -27
  132. package/dist/src/mcp/oauth-utils.js.map +1 -1
  133. package/dist/src/mcp/oauth-utils.test.js +41 -1
  134. package/dist/src/mcp/oauth-utils.test.js.map +1 -1
  135. package/dist/src/mcp/token-storage/base-token-storage.d.ts +19 -0
  136. package/dist/src/mcp/token-storage/base-token-storage.js +36 -0
  137. package/dist/src/mcp/token-storage/base-token-storage.js.map +1 -0
  138. package/dist/src/mcp/token-storage/base-token-storage.test.d.ts +6 -0
  139. package/dist/src/mcp/token-storage/base-token-storage.test.js +160 -0
  140. package/dist/src/mcp/token-storage/base-token-storage.test.js.map +1 -0
  141. package/dist/src/mcp/token-storage/file-token-storage.d.ts +24 -0
  142. package/dist/src/mcp/token-storage/file-token-storage.js +144 -0
  143. package/dist/src/mcp/token-storage/file-token-storage.js.map +1 -0
  144. package/dist/src/mcp/token-storage/file-token-storage.test.d.ts +6 -0
  145. package/dist/src/mcp/token-storage/file-token-storage.test.js +235 -0
  146. package/dist/src/mcp/token-storage/file-token-storage.test.js.map +1 -0
  147. package/dist/src/mcp/token-storage/hybrid-token-storage.d.ts +23 -0
  148. package/dist/src/mcp/token-storage/hybrid-token-storage.js +78 -0
  149. package/dist/src/mcp/token-storage/hybrid-token-storage.js.map +1 -0
  150. package/dist/src/mcp/token-storage/hybrid-token-storage.test.d.ts +6 -0
  151. package/dist/src/mcp/token-storage/hybrid-token-storage.test.js +193 -0
  152. package/dist/src/mcp/token-storage/hybrid-token-storage.test.js.map +1 -0
  153. package/dist/src/mcp/token-storage/keychain-token-storage.d.ts +31 -0
  154. package/dist/src/mcp/token-storage/keychain-token-storage.js +190 -0
  155. package/dist/src/mcp/token-storage/keychain-token-storage.js.map +1 -0
  156. package/dist/src/mcp/token-storage/keychain-token-storage.test.d.ts +6 -0
  157. package/dist/src/mcp/token-storage/keychain-token-storage.test.js +254 -0
  158. package/dist/src/mcp/token-storage/keychain-token-storage.test.js.map +1 -0
  159. package/dist/src/mcp/token-storage/types.d.ts +38 -0
  160. package/dist/src/mcp/token-storage/types.js +11 -0
  161. package/dist/src/mcp/token-storage/types.js.map +1 -0
  162. package/dist/src/prompts/mcp-prompts.d.ts +2 -2
  163. package/dist/src/prompts/prompt-registry.d.ts +1 -1
  164. package/dist/src/services/chatRecordingService.d.ts +6 -13
  165. package/dist/src/services/chatRecordingService.js +31 -19
  166. package/dist/src/services/chatRecordingService.js.map +1 -1
  167. package/dist/src/services/chatRecordingService.test.js +64 -25
  168. package/dist/src/services/chatRecordingService.test.js.map +1 -1
  169. package/dist/src/services/fileDiscoveryService.js +1 -1
  170. package/dist/src/services/fileDiscoveryService.js.map +1 -1
  171. package/dist/src/services/fileDiscoveryService.test.js +3 -3
  172. package/dist/src/services/fileDiscoveryService.test.js.map +1 -1
  173. package/dist/src/services/fileSystemService.js +1 -1
  174. package/dist/src/services/fileSystemService.js.map +1 -1
  175. package/dist/src/services/fileSystemService.test.js +1 -1
  176. package/dist/src/services/fileSystemService.test.js.map +1 -1
  177. package/dist/src/services/gitService.d.ts +3 -1
  178. package/dist/src/services/gitService.js +21 -12
  179. package/dist/src/services/gitService.js.map +1 -1
  180. package/dist/src/services/gitService.test.js +22 -19
  181. package/dist/src/services/gitService.test.js.map +1 -1
  182. package/dist/src/services/loopDetectionService.d.ts +3 -2
  183. package/dist/src/services/loopDetectionService.js +28 -4
  184. package/dist/src/services/loopDetectionService.js.map +1 -1
  185. package/dist/src/services/loopDetectionService.test.js +23 -1
  186. package/dist/src/services/loopDetectionService.test.js.map +1 -1
  187. package/dist/src/services/shellExecutionService.d.ts +8 -10
  188. package/dist/src/services/shellExecutionService.js +292 -135
  189. package/dist/src/services/shellExecutionService.js.map +1 -1
  190. package/dist/src/services/shellExecutionService.test.js +277 -42
  191. package/dist/src/services/shellExecutionService.test.js.map +1 -1
  192. package/dist/src/telemetry/clearcut-logger/clearcut-logger.d.ts +18 -4
  193. package/dist/src/telemetry/clearcut-logger/clearcut-logger.js +171 -11
  194. package/dist/src/telemetry/clearcut-logger/clearcut-logger.js.map +1 -1
  195. package/dist/src/telemetry/clearcut-logger/clearcut-logger.test.js +103 -11
  196. package/dist/src/telemetry/clearcut-logger/clearcut-logger.test.js.map +1 -1
  197. package/dist/src/telemetry/clearcut-logger/event-metadata-key.d.ts +31 -1
  198. package/dist/src/telemetry/clearcut-logger/event-metadata-key.js +75 -0
  199. package/dist/src/telemetry/clearcut-logger/event-metadata-key.js.map +1 -1
  200. package/dist/src/telemetry/constants.d.ts +9 -0
  201. package/dist/src/telemetry/constants.js +9 -0
  202. package/dist/src/telemetry/constants.js.map +1 -1
  203. package/dist/src/telemetry/file-exporters.d.ts +5 -4
  204. package/dist/src/telemetry/file-exporters.js +1 -1
  205. package/dist/src/telemetry/file-exporters.js.map +1 -1
  206. package/dist/src/telemetry/index.d.ts +5 -2
  207. package/dist/src/telemetry/index.js +3 -2
  208. package/dist/src/telemetry/index.js.map +1 -1
  209. package/dist/src/telemetry/loggers.d.ts +8 -2
  210. package/dist/src/telemetry/loggers.js +130 -2
  211. package/dist/src/telemetry/loggers.js.map +1 -1
  212. package/dist/src/telemetry/loggers.test.circular.js.map +1 -1
  213. package/dist/src/telemetry/loggers.test.js +105 -9
  214. package/dist/src/telemetry/loggers.test.js.map +1 -1
  215. package/dist/src/telemetry/metrics.d.ts +15 -4
  216. package/dist/src/telemetry/metrics.js +46 -8
  217. package/dist/src/telemetry/metrics.js.map +1 -1
  218. package/dist/src/telemetry/metrics.test.js +5 -25
  219. package/dist/src/telemetry/metrics.test.js.map +1 -1
  220. package/dist/src/telemetry/sdk.d.ts +1 -1
  221. package/dist/src/telemetry/sdk.js +3 -3
  222. package/dist/src/telemetry/sdk.js.map +1 -1
  223. package/dist/src/telemetry/telemetry-utils.d.ts +6 -0
  224. package/dist/src/telemetry/telemetry-utils.js +14 -0
  225. package/dist/src/telemetry/telemetry-utils.js.map +1 -0
  226. package/dist/src/telemetry/telemetry-utils.test.d.ts +6 -0
  227. package/dist/src/telemetry/telemetry-utils.test.js +40 -0
  228. package/dist/src/telemetry/telemetry-utils.test.js.map +1 -0
  229. package/dist/src/telemetry/types.d.ts +61 -6
  230. package/dist/src/telemetry/types.js +105 -4
  231. package/dist/src/telemetry/types.js.map +1 -1
  232. package/dist/src/telemetry/uiTelemetry.d.ts +2 -2
  233. package/dist/src/telemetry/uiTelemetry.js +5 -5
  234. package/dist/src/telemetry/uiTelemetry.js.map +1 -1
  235. package/dist/src/telemetry/uiTelemetry.test.js +20 -16
  236. package/dist/src/telemetry/uiTelemetry.test.js.map +1 -1
  237. package/dist/src/test-utils/config.d.ts +2 -1
  238. package/dist/src/test-utils/config.js.map +1 -1
  239. package/dist/src/test-utils/index.d.ts +6 -0
  240. package/dist/src/test-utils/index.js +7 -0
  241. package/dist/src/test-utils/index.js.map +1 -0
  242. package/dist/src/test-utils/mock-tool.d.ts +41 -0
  243. package/dist/src/test-utils/mock-tool.js +51 -0
  244. package/dist/src/test-utils/mock-tool.js.map +1 -0
  245. package/dist/src/test-utils/mockWorkspaceContext.d.ts +1 -1
  246. package/dist/src/test-utils/tools.d.ts +3 -2
  247. package/dist/src/test-utils/tools.js.map +1 -1
  248. package/dist/src/tools/diffOptions.d.ts +1 -1
  249. package/dist/src/tools/diffOptions.js +21 -13
  250. package/dist/src/tools/diffOptions.js.map +1 -1
  251. package/dist/src/tools/diffOptions.test.js +58 -22
  252. package/dist/src/tools/diffOptions.test.js.map +1 -1
  253. package/dist/src/tools/edit.d.ts +6 -5
  254. package/dist/src/tools/edit.js +47 -36
  255. package/dist/src/tools/edit.js.map +1 -1
  256. package/dist/src/tools/edit.test.js +77 -12
  257. package/dist/src/tools/edit.test.js.map +1 -1
  258. package/dist/src/tools/glob.d.ts +3 -2
  259. package/dist/src/tools/glob.js +17 -6
  260. package/dist/src/tools/glob.js.map +1 -1
  261. package/dist/src/tools/glob.test.js +29 -4
  262. package/dist/src/tools/glob.test.js.map +1 -1
  263. package/dist/src/tools/grep.d.ts +3 -2
  264. package/dist/src/tools/grep.js +35 -15
  265. package/dist/src/tools/grep.js.map +1 -1
  266. package/dist/src/tools/grep.test.js +26 -3
  267. package/dist/src/tools/grep.test.js.map +1 -1
  268. package/dist/src/tools/ls.d.ts +3 -2
  269. package/dist/src/tools/ls.js +12 -7
  270. package/dist/src/tools/ls.js.map +1 -1
  271. package/dist/src/tools/ls.test.js +7 -2
  272. package/dist/src/tools/ls.test.js.map +1 -1
  273. package/dist/src/tools/mcp-client-manager.d.ts +8 -6
  274. package/dist/src/tools/mcp-client-manager.js +30 -5
  275. package/dist/src/tools/mcp-client-manager.js.map +1 -1
  276. package/dist/src/tools/mcp-client-manager.test.js +20 -1
  277. package/dist/src/tools/mcp-client-manager.test.js.map +1 -1
  278. package/dist/src/tools/mcp-client.d.ts +18 -11
  279. package/dist/src/tools/mcp-client.js +67 -57
  280. package/dist/src/tools/mcp-client.js.map +1 -1
  281. package/dist/src/tools/mcp-client.test.js +29 -4
  282. package/dist/src/tools/mcp-client.test.js.map +1 -1
  283. package/dist/src/tools/mcp-tool.d.ts +6 -4
  284. package/dist/src/tools/mcp-tool.js +21 -11
  285. package/dist/src/tools/mcp-tool.js.map +1 -1
  286. package/dist/src/tools/mcp-tool.test.js +49 -12
  287. package/dist/src/tools/mcp-tool.test.js.map +1 -1
  288. package/dist/src/tools/memoryTool.d.ts +4 -3
  289. package/dist/src/tools/memoryTool.js +15 -38
  290. package/dist/src/tools/memoryTool.js.map +1 -1
  291. package/dist/src/tools/memoryTool.test.js +24 -12
  292. package/dist/src/tools/memoryTool.test.js.map +1 -1
  293. package/dist/src/tools/modifiable-tool.d.ts +2 -2
  294. package/dist/src/tools/modifiable-tool.js +3 -3
  295. package/dist/src/tools/modifiable-tool.js.map +1 -1
  296. package/dist/src/tools/modifiable-tool.test.js +4 -4
  297. package/dist/src/tools/modifiable-tool.test.js.map +1 -1
  298. package/dist/src/tools/read-file.d.ts +3 -2
  299. package/dist/src/tools/read-file.js +12 -34
  300. package/dist/src/tools/read-file.js.map +1 -1
  301. package/dist/src/tools/read-file.test.js +9 -6
  302. package/dist/src/tools/read-file.test.js.map +1 -1
  303. package/dist/src/tools/read-many-files.d.ts +3 -2
  304. package/dist/src/tools/read-many-files.js +35 -58
  305. package/dist/src/tools/read-many-files.js.map +1 -1
  306. package/dist/src/tools/read-many-files.test.js +64 -11
  307. package/dist/src/tools/read-many-files.test.js.map +1 -1
  308. package/dist/src/tools/ripGrep.d.ts +47 -0
  309. package/dist/src/tools/ripGrep.js +368 -0
  310. package/dist/src/tools/ripGrep.js.map +1 -0
  311. package/dist/src/tools/ripGrep.test.d.ts +6 -0
  312. package/dist/src/tools/ripGrep.test.js +874 -0
  313. package/dist/src/tools/ripGrep.test.js.map +1 -0
  314. package/dist/src/tools/shell.d.ts +3 -2
  315. package/dist/src/tools/shell.js +30 -25
  316. package/dist/src/tools/shell.js.map +1 -1
  317. package/dist/src/tools/shell.test.js +34 -25
  318. package/dist/src/tools/shell.test.js.map +1 -1
  319. package/dist/src/tools/smart-edit.d.ts +73 -0
  320. package/dist/src/tools/smart-edit.js +607 -0
  321. package/dist/src/tools/smart-edit.js.map +1 -0
  322. package/dist/src/tools/smart-edit.test.d.ts +6 -0
  323. package/dist/src/tools/smart-edit.test.js +405 -0
  324. package/dist/src/tools/smart-edit.test.js.map +1 -0
  325. package/dist/src/tools/tool-error.d.ts +17 -1
  326. package/dist/src/tools/tool-error.js +26 -0
  327. package/dist/src/tools/tool-error.js.map +1 -1
  328. package/dist/src/tools/tool-registry.d.ts +10 -4
  329. package/dist/src/tools/tool-registry.js +19 -7
  330. package/dist/src/tools/tool-registry.js.map +1 -1
  331. package/dist/src/tools/tool-registry.test.js +86 -3
  332. package/dist/src/tools/tool-registry.test.js.map +1 -1
  333. package/dist/src/tools/tools.d.ts +15 -9
  334. package/dist/src/tools/tools.js +12 -0
  335. package/dist/src/tools/tools.js.map +1 -1
  336. package/dist/src/tools/tools.test.js +1 -2
  337. package/dist/src/tools/tools.test.js.map +1 -1
  338. package/dist/src/tools/web-fetch.d.ts +3 -2
  339. package/dist/src/tools/web-fetch.js +14 -10
  340. package/dist/src/tools/web-fetch.js.map +1 -1
  341. package/dist/src/tools/web-fetch.test.js +55 -16
  342. package/dist/src/tools/web-fetch.test.js.map +1 -1
  343. package/dist/src/tools/web-search.d.ts +4 -3
  344. package/dist/src/tools/web-search.js +31 -8
  345. package/dist/src/tools/web-search.js.map +1 -1
  346. package/dist/src/tools/web-search.test.js +69 -1
  347. package/dist/src/tools/web-search.test.js.map +1 -1
  348. package/dist/src/tools/write-file.d.ts +4 -3
  349. package/dist/src/tools/write-file.js +14 -14
  350. package/dist/src/tools/write-file.js.map +1 -1
  351. package/dist/src/tools/write-file.test.js +14 -14
  352. package/dist/src/tools/write-file.test.js.map +1 -1
  353. package/dist/src/utils/bfsFileSearch.d.ts +2 -2
  354. package/dist/src/utils/bfsFileSearch.js +2 -2
  355. package/dist/src/utils/bfsFileSearch.js.map +1 -1
  356. package/dist/src/utils/bfsFileSearch.test.js +3 -3
  357. package/dist/src/utils/bfsFileSearch.test.js.map +1 -1
  358. package/dist/src/utils/editCorrector.d.ts +2 -2
  359. package/dist/src/utils/editCorrector.js +1 -1
  360. package/dist/src/utils/editCorrector.js.map +1 -1
  361. package/dist/src/utils/editCorrector.test.js +3 -3
  362. package/dist/src/utils/editCorrector.test.js.map +1 -1
  363. package/dist/src/utils/editor.js +2 -2
  364. package/dist/src/utils/editor.js.map +1 -1
  365. package/dist/src/utils/editor.test.js +2 -2
  366. package/dist/src/utils/editor.test.js.map +1 -1
  367. package/dist/src/utils/environmentContext.d.ts +2 -2
  368. package/dist/src/utils/environmentContext.js +1 -1
  369. package/dist/src/utils/environmentContext.js.map +1 -1
  370. package/dist/src/utils/environmentContext.test.js +1 -1
  371. package/dist/src/utils/environmentContext.test.js.map +1 -1
  372. package/dist/src/utils/errorReporting.d.ts +1 -1
  373. package/dist/src/utils/errors.d.ts +19 -0
  374. package/dist/src/utils/errors.js +32 -0
  375. package/dist/src/utils/errors.js.map +1 -1
  376. package/dist/src/utils/fetch.js +1 -1
  377. package/dist/src/utils/fetch.js.map +1 -1
  378. package/dist/src/utils/fileUtils.d.ts +23 -12
  379. package/dist/src/utils/fileUtils.js +160 -79
  380. package/dist/src/utils/fileUtils.js.map +1 -1
  381. package/dist/src/utils/fileUtils.test.js +314 -21
  382. package/dist/src/utils/fileUtils.test.js.map +1 -1
  383. package/dist/src/utils/filesearch/crawler.d.ts +1 -1
  384. package/dist/src/utils/filesearch/crawler.test.js +2 -2
  385. package/dist/src/utils/filesearch/crawler.test.js.map +1 -1
  386. package/dist/src/utils/filesearch/fileSearch.d.ts +1 -0
  387. package/dist/src/utils/filesearch/fileSearch.js +14 -9
  388. package/dist/src/utils/filesearch/fileSearch.js.map +1 -1
  389. package/dist/src/utils/filesearch/fileSearch.test.js +90 -0
  390. package/dist/src/utils/filesearch/fileSearch.test.js.map +1 -1
  391. package/dist/src/utils/generateContentResponseUtilities.d.ts +1 -2
  392. package/dist/src/utils/generateContentResponseUtilities.js +1 -13
  393. package/dist/src/utils/generateContentResponseUtilities.js.map +1 -1
  394. package/dist/src/utils/generateContentResponseUtilities.test.js +2 -40
  395. package/dist/src/utils/generateContentResponseUtilities.test.js.map +1 -1
  396. package/dist/src/utils/getFolderStructure.d.ts +2 -2
  397. package/dist/src/utils/getFolderStructure.js +2 -2
  398. package/dist/src/utils/getFolderStructure.js.map +1 -1
  399. package/dist/src/utils/getFolderStructure.test.js +13 -13
  400. package/dist/src/utils/getFolderStructure.test.js.map +1 -1
  401. package/dist/src/utils/getPty.d.ts +19 -0
  402. package/dist/src/utils/getPty.js +23 -0
  403. package/dist/src/utils/getPty.js.map +1 -0
  404. package/dist/src/utils/gitIgnoreParser.d.ts +1 -0
  405. package/dist/src/utils/gitIgnoreParser.js +104 -13
  406. package/dist/src/utils/gitIgnoreParser.js.map +1 -1
  407. package/dist/src/utils/gitIgnoreParser.test.js +69 -3
  408. package/dist/src/utils/gitIgnoreParser.test.js.map +1 -1
  409. package/dist/src/utils/gitUtils.js +2 -2
  410. package/dist/src/utils/gitUtils.js.map +1 -1
  411. package/dist/src/utils/ide-trust.d.ts +10 -0
  412. package/dist/src/utils/ide-trust.js +14 -0
  413. package/dist/src/utils/ide-trust.js.map +1 -0
  414. package/dist/src/utils/ignorePatterns.d.ts +103 -0
  415. package/dist/src/utils/ignorePatterns.js +220 -0
  416. package/dist/src/utils/ignorePatterns.js.map +1 -0
  417. package/dist/src/utils/ignorePatterns.test.d.ts +6 -0
  418. package/dist/src/utils/ignorePatterns.test.js +250 -0
  419. package/dist/src/utils/ignorePatterns.test.js.map +1 -0
  420. package/dist/src/utils/installationManager.d.ts +16 -0
  421. package/dist/src/utils/installationManager.js +50 -0
  422. package/dist/src/utils/installationManager.js.map +1 -0
  423. package/dist/src/utils/installationManager.test.d.ts +6 -0
  424. package/dist/src/utils/installationManager.test.js +83 -0
  425. package/dist/src/utils/installationManager.test.js.map +1 -0
  426. package/dist/src/utils/language-detection.d.ts +6 -0
  427. package/dist/src/utils/language-detection.js +101 -0
  428. package/dist/src/utils/language-detection.js.map +1 -0
  429. package/dist/src/utils/llm-edit-fixer.d.ts +25 -0
  430. package/dist/src/utils/llm-edit-fixer.js +112 -0
  431. package/dist/src/utils/llm-edit-fixer.js.map +1 -0
  432. package/dist/src/utils/memoryDiscovery.d.ts +7 -6
  433. package/dist/src/utils/memoryDiscovery.js +68 -33
  434. package/dist/src/utils/memoryDiscovery.js.map +1 -1
  435. package/dist/src/utils/memoryDiscovery.test.js +76 -20
  436. package/dist/src/utils/memoryDiscovery.test.js.map +1 -1
  437. package/dist/src/utils/memoryImportProcessor.js +2 -2
  438. package/dist/src/utils/memoryImportProcessor.js.map +1 -1
  439. package/dist/src/utils/memoryImportProcessor.test.js +2 -141
  440. package/dist/src/utils/memoryImportProcessor.test.js.map +1 -1
  441. package/dist/src/utils/messageInspectors.d.ts +1 -1
  442. package/dist/src/utils/nextSpeakerChecker.d.ts +2 -2
  443. package/dist/src/utils/nextSpeakerChecker.test.js +33 -0
  444. package/dist/src/utils/nextSpeakerChecker.test.js.map +1 -1
  445. package/dist/src/utils/partUtils.d.ts +22 -1
  446. package/dist/src/utils/partUtils.js +68 -0
  447. package/dist/src/utils/partUtils.js.map +1 -1
  448. package/dist/src/utils/partUtils.test.js +112 -1
  449. package/dist/src/utils/partUtils.test.js.map +1 -1
  450. package/dist/src/utils/pathReader.d.ts +17 -0
  451. package/dist/src/utils/pathReader.js +92 -0
  452. package/dist/src/utils/pathReader.js.map +1 -0
  453. package/dist/src/utils/pathReader.test.d.ts +6 -0
  454. package/dist/src/utils/pathReader.test.js +363 -0
  455. package/dist/src/utils/pathReader.test.js.map +1 -0
  456. package/dist/src/utils/paths.d.ts +1 -18
  457. package/dist/src/utils/paths.js +3 -29
  458. package/dist/src/utils/paths.js.map +1 -1
  459. package/dist/src/utils/quotaErrorDetection.d.ts +1 -1
  460. package/dist/src/utils/retry.test.js +4 -1
  461. package/dist/src/utils/retry.test.js.map +1 -1
  462. package/dist/src/utils/schemaValidator.js +4 -0
  463. package/dist/src/utils/schemaValidator.js.map +1 -1
  464. package/dist/src/utils/session.js +1 -1
  465. package/dist/src/utils/session.js.map +1 -1
  466. package/dist/src/utils/shell-utils.d.ts +1 -1
  467. package/dist/src/utils/shell-utils.js +23 -29
  468. package/dist/src/utils/shell-utils.js.map +1 -1
  469. package/dist/src/utils/shell-utils.test.js +7 -0
  470. package/dist/src/utils/shell-utils.test.js.map +1 -1
  471. package/dist/src/utils/summarizer.d.ts +2 -2
  472. package/dist/src/utils/summarizer.test.js.map +1 -1
  473. package/dist/src/utils/systemEncoding.js +2 -2
  474. package/dist/src/utils/systemEncoding.js.map +1 -1
  475. package/dist/src/utils/systemEncoding.test.js +2 -2
  476. package/dist/src/utils/systemEncoding.test.js.map +1 -1
  477. package/dist/src/utils/tool-utils.d.ts +19 -0
  478. package/dist/src/utils/tool-utils.js +58 -0
  479. package/dist/src/utils/tool-utils.js.map +1 -0
  480. package/dist/src/utils/tool-utils.test.d.ts +6 -0
  481. package/dist/src/utils/tool-utils.test.js +61 -0
  482. package/dist/src/utils/tool-utils.test.js.map +1 -0
  483. package/dist/src/utils/userAccountManager.d.ts +20 -0
  484. package/dist/src/utils/userAccountManager.js +114 -0
  485. package/dist/src/utils/userAccountManager.js.map +1 -0
  486. package/dist/src/utils/userAccountManager.test.d.ts +6 -0
  487. package/dist/src/utils/{user_account.test.js → userAccountManager.test.js} +33 -30
  488. package/dist/src/utils/userAccountManager.test.js.map +1 -0
  489. package/dist/src/utils/workspaceContext.js +13 -7
  490. package/dist/src/utils/workspaceContext.js.map +1 -1
  491. package/dist/src/utils/workspaceContext.test.js +41 -16
  492. package/dist/src/utils/workspaceContext.test.js.map +1 -1
  493. package/dist/tsconfig.tsbuildinfo +1 -1
  494. package/package.json +27 -13
  495. package/dist/src/utils/user_account.d.ts +0 -9
  496. package/dist/src/utils/user_account.js +0 -109
  497. package/dist/src/utils/user_account.js.map +0 -1
  498. package/dist/src/utils/user_account.test.js.map +0 -1
  499. package/dist/src/utils/user_id.d.ts +0 -11
  500. package/dist/src/utils/user_id.js +0 -49
  501. package/dist/src/utils/user_id.js.map +0 -1
  502. package/dist/src/utils/user_id.test.js +0 -21
  503. package/dist/src/utils/user_id.test.js.map +0 -1
  504. /package/dist/src/{utils/user_account.test.d.ts → config/storage.test.d.ts} +0 -0
  505. /package/dist/src/{utils/user_id.test.d.ts → ide/process-utils.test.d.ts} +0 -0
@@ -4,8 +4,31 @@
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
6
  import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
7
- import { GeminiChat } from './geminiChat.js';
7
+ import { GeminiChat, EmptyStreamError, StreamEventType, } from './geminiChat.js';
8
8
  import { setSimulate429 } from '../utils/testUtils.js';
9
+ // Mock fs module to prevent actual file system operations during tests
10
+ const mockFileSystem = new Map();
11
+ vi.mock('node:fs', () => {
12
+ const fsModule = {
13
+ mkdirSync: vi.fn(),
14
+ writeFileSync: vi.fn((path, data) => {
15
+ mockFileSystem.set(path, data);
16
+ }),
17
+ readFileSync: vi.fn((path) => {
18
+ if (mockFileSystem.has(path)) {
19
+ return mockFileSystem.get(path);
20
+ }
21
+ throw Object.assign(new Error('ENOENT: no such file or directory'), {
22
+ code: 'ENOENT',
23
+ });
24
+ }),
25
+ existsSync: vi.fn((path) => mockFileSystem.has(path)),
26
+ };
27
+ return {
28
+ default: fsModule,
29
+ ...fsModule,
30
+ };
31
+ });
9
32
  // Mocks
10
33
  const mockModelsModule = {
11
34
  generateContent: vi.fn(),
@@ -14,6 +37,16 @@ const mockModelsModule = {
14
37
  embedContent: vi.fn(),
15
38
  batchEmbedContents: vi.fn(),
16
39
  };
40
+ const { mockLogInvalidChunk, mockLogContentRetry, mockLogContentRetryFailure } = vi.hoisted(() => ({
41
+ mockLogInvalidChunk: vi.fn(),
42
+ mockLogContentRetry: vi.fn(),
43
+ mockLogContentRetryFailure: vi.fn(),
44
+ }));
45
+ vi.mock('../telemetry/loggers.js', () => ({
46
+ logInvalidChunk: mockLogInvalidChunk,
47
+ logContentRetry: mockLogContentRetry,
48
+ logContentRetryFailure: mockLogContentRetryFailure,
49
+ }));
17
50
  describe('GeminiChat', () => {
18
51
  let chat;
19
52
  let mockConfig;
@@ -34,6 +67,13 @@ describe('GeminiChat', () => {
34
67
  getQuotaErrorOccurred: vi.fn().mockReturnValue(false),
35
68
  setQuotaErrorOccurred: vi.fn(),
36
69
  flashFallbackHandler: undefined,
70
+ getProjectRoot: vi.fn().mockReturnValue('/test/project/root'),
71
+ storage: {
72
+ getProjectTempDir: vi.fn().mockReturnValue('/test/temp'),
73
+ },
74
+ getToolRegistry: vi.fn().mockReturnValue({
75
+ getTool: vi.fn(),
76
+ }),
37
77
  };
38
78
  // Disable 429 simulation for tests
39
79
  setSimulate429(false);
@@ -45,6 +85,181 @@ describe('GeminiChat', () => {
45
85
  vi.resetAllMocks();
46
86
  });
47
87
  describe('sendMessage', () => {
88
+ it('should retain the initial user message when an automatic function call occurs', async () => {
89
+ // 1. Define the user's initial text message. This is the turn that gets dropped by the buggy logic.
90
+ const userInitialMessage = {
91
+ role: 'user',
92
+ parts: [{ text: 'How is the weather in Boston?' }],
93
+ };
94
+ // 2. Mock the full API response, including the automaticFunctionCallingHistory.
95
+ // This history represents the full turn: user asks, model calls tool, tool responds, model answers.
96
+ const mockAfcResponse = {
97
+ candidates: [
98
+ {
99
+ content: {
100
+ role: 'model',
101
+ parts: [
102
+ { text: 'The weather in Boston is 72 degrees and sunny.' },
103
+ ],
104
+ },
105
+ },
106
+ ],
107
+ automaticFunctionCallingHistory: [
108
+ userInitialMessage, // The user's turn
109
+ {
110
+ // The model's first response: a tool call
111
+ role: 'model',
112
+ parts: [
113
+ {
114
+ functionCall: {
115
+ name: 'get_weather',
116
+ args: { location: 'Boston' },
117
+ },
118
+ },
119
+ ],
120
+ },
121
+ {
122
+ // The tool's response, which has a 'user' role
123
+ role: 'user',
124
+ parts: [
125
+ {
126
+ functionResponse: {
127
+ name: 'get_weather',
128
+ response: { temperature: 72, condition: 'sunny' },
129
+ },
130
+ },
131
+ ],
132
+ },
133
+ ],
134
+ };
135
+ vi.mocked(mockModelsModule.generateContent).mockResolvedValue(mockAfcResponse);
136
+ // 3. Action: Send the initial message.
137
+ await chat.sendMessage({ message: 'How is the weather in Boston?' }, 'prompt-id-afc-bug');
138
+ // 4. Assert: Check the final state of the history.
139
+ const history = chat.getHistory();
140
+ // With the bug, history.length will be 3, because the first user message is dropped.
141
+ // The correct behavior is for the history to contain all 4 turns.
142
+ expect(history.length).toBe(4);
143
+ // Crucially, assert that the very first turn in the history matches the user's initial message.
144
+ // This is the assertion that will fail.
145
+ const firstTurn = history[0];
146
+ expect(firstTurn.role).toBe('user');
147
+ expect(firstTurn?.parts[0].text).toBe('How is the weather in Boston?');
148
+ // Verify the rest of the history is also correct.
149
+ const secondTurn = history[1];
150
+ expect(secondTurn.role).toBe('model');
151
+ expect(secondTurn?.parts[0].functionCall).toBeDefined();
152
+ const thirdTurn = history[2];
153
+ expect(thirdTurn.role).toBe('user');
154
+ expect(thirdTurn?.parts[0].functionResponse).toBeDefined();
155
+ const fourthTurn = history[3];
156
+ expect(fourthTurn.role).toBe('model');
157
+ expect(fourthTurn?.parts[0].text).toContain('72 degrees and sunny');
158
+ });
159
+ it('should throw an error when attempting to add a user turn after another user turn', async () => {
160
+ // 1. Setup: Create a history that already ends with a user turn (a functionResponse).
161
+ const initialHistory = [
162
+ { role: 'user', parts: [{ text: 'Initial prompt' }] },
163
+ {
164
+ role: 'model',
165
+ parts: [{ functionCall: { name: 'test_tool', args: {} } }],
166
+ },
167
+ {
168
+ role: 'user',
169
+ parts: [{ functionResponse: { name: 'test_tool', response: {} } }],
170
+ },
171
+ ];
172
+ chat.setHistory(initialHistory);
173
+ // 2. Mock a valid model response so the call doesn't fail for other reasons.
174
+ const mockResponse = {
175
+ candidates: [
176
+ { content: { role: 'model', parts: [{ text: 'some response' }] } },
177
+ ],
178
+ };
179
+ vi.mocked(mockModelsModule.generateContent).mockResolvedValue(mockResponse);
180
+ // 3. Action & Assert: Expect that sending another user message immediately
181
+ // after a user-role turn throws the specific error.
182
+ await expect(chat.sendMessage({ message: 'This is an invalid consecutive user message' }, 'prompt-id-1')).rejects.toThrow('Cannot add a user turn after another user turn.');
183
+ });
184
+ it('should preserve text parts that are in the same response as a thought', async () => {
185
+ // 1. Mock the API to return a single response containing both a thought and visible text.
186
+ const mixedContentResponse = {
187
+ candidates: [
188
+ {
189
+ content: {
190
+ role: 'model',
191
+ parts: [
192
+ { thought: 'This is a thought.' },
193
+ { text: 'This is the visible text that should not be lost.' },
194
+ ],
195
+ },
196
+ },
197
+ ],
198
+ };
199
+ vi.mocked(mockModelsModule.generateContent).mockResolvedValue(mixedContentResponse);
200
+ // 2. Action: Send a standard, non-streaming message.
201
+ await chat.sendMessage({ message: 'test message' }, 'prompt-id-mixed-response');
202
+ // 3. Assert: Check the final state of the history.
203
+ const history = chat.getHistory();
204
+ // The history should contain two turns: the user's message and the model's response.
205
+ expect(history.length).toBe(2);
206
+ const modelTurn = history[1];
207
+ expect(modelTurn.role).toBe('model');
208
+ // CRUCIAL ASSERTION:
209
+ // Buggy code would discard the entire response because a "thought" was present,
210
+ // resulting in an empty placeholder turn with 0 parts.
211
+ // The corrected code will pass, preserving the single visible text part.
212
+ expect(modelTurn?.parts?.length).toBe(1);
213
+ expect(modelTurn?.parts[0].text).toBe('This is the visible text that should not be lost.');
214
+ });
215
+ it('should add a placeholder model turn when a tool call is followed by an empty model response', async () => {
216
+ // 1. Setup: A history where the model has just made a function call.
217
+ const initialHistory = [
218
+ {
219
+ role: 'user',
220
+ parts: [{ text: 'Find a good Italian restaurant for me.' }],
221
+ },
222
+ {
223
+ role: 'model',
224
+ parts: [
225
+ {
226
+ functionCall: {
227
+ name: 'find_restaurant',
228
+ args: { cuisine: 'Italian' },
229
+ },
230
+ },
231
+ ],
232
+ },
233
+ ];
234
+ chat.setHistory(initialHistory);
235
+ // 2. Mock the API to return an empty/thought-only response.
236
+ const emptyModelResponse = {
237
+ candidates: [
238
+ { content: { role: 'model', parts: [{ thought: true }] } },
239
+ ],
240
+ };
241
+ vi.mocked(mockModelsModule.generateContent).mockResolvedValue(emptyModelResponse);
242
+ // 3. Action: Send the function response back to the model.
243
+ await chat.sendMessage({
244
+ message: {
245
+ functionResponse: {
246
+ name: 'find_restaurant',
247
+ response: { name: 'Vesuvio' },
248
+ },
249
+ },
250
+ }, 'prompt-id-1');
251
+ // 4. Assert: The history should now have four valid, alternating turns.
252
+ const history = chat.getHistory();
253
+ expect(history.length).toBe(4);
254
+ // The final turn must be the empty model placeholder.
255
+ const lastTurn = history[3];
256
+ expect(lastTurn.role).toBe('model');
257
+ expect(lastTurn?.parts?.length).toBe(0);
258
+ // The second-to-last turn must be the function response we sent.
259
+ const secondToLastTurn = history[2];
260
+ expect(secondToLastTurn.role).toBe('user');
261
+ expect(secondToLastTurn?.parts[0].functionResponse).toBeDefined();
262
+ });
48
263
  it('should call generateContent with the correct parameters', async () => {
49
264
  const response = {
50
265
  candidates: [
@@ -70,6 +285,349 @@ describe('GeminiChat', () => {
70
285
  });
71
286
  });
72
287
  describe('sendMessageStream', () => {
288
+ it('should succeed if a tool call is followed by an empty part', async () => {
289
+ // 1. Mock a stream that contains a tool call, then an invalid (empty) part.
290
+ const streamWithToolCall = (async function* () {
291
+ yield {
292
+ candidates: [
293
+ {
294
+ content: {
295
+ role: 'model',
296
+ parts: [{ functionCall: { name: 'test_tool', args: {} } }],
297
+ },
298
+ },
299
+ ],
300
+ };
301
+ // This second chunk is invalid according to isValidResponse
302
+ yield {
303
+ candidates: [
304
+ {
305
+ content: {
306
+ role: 'model',
307
+ parts: [{ text: '' }],
308
+ },
309
+ },
310
+ ],
311
+ };
312
+ })();
313
+ vi.mocked(mockModelsModule.generateContentStream).mockResolvedValue(streamWithToolCall);
314
+ // 2. Action & Assert: The stream processing should complete without throwing an error
315
+ // because the presence of a tool call makes the empty final chunk acceptable.
316
+ const stream = await chat.sendMessageStream({ message: 'test message' }, 'prompt-id-tool-call-empty-end');
317
+ await expect((async () => {
318
+ for await (const _ of stream) {
319
+ /* consume stream */
320
+ }
321
+ })()).resolves.not.toThrow();
322
+ // 3. Verify history was recorded correctly
323
+ const history = chat.getHistory();
324
+ expect(history.length).toBe(2); // user turn + model turn
325
+ const modelTurn = history[1];
326
+ expect(modelTurn?.parts?.length).toBe(1); // The empty part is discarded
327
+ expect(modelTurn?.parts[0].functionCall).toBeDefined();
328
+ });
329
+ it('should fail if the stream ends with an empty part and has no finishReason', async () => {
330
+ // 1. Mock a stream that ends with an invalid part and has no finish reason.
331
+ const streamWithNoFinish = (async function* () {
332
+ yield {
333
+ candidates: [
334
+ {
335
+ content: {
336
+ role: 'model',
337
+ parts: [{ text: 'Initial content...' }],
338
+ },
339
+ },
340
+ ],
341
+ };
342
+ // This second chunk is invalid and has no finishReason, so it should fail.
343
+ yield {
344
+ candidates: [
345
+ {
346
+ content: {
347
+ role: 'model',
348
+ parts: [{ text: '' }],
349
+ },
350
+ },
351
+ ],
352
+ };
353
+ })();
354
+ vi.mocked(mockModelsModule.generateContentStream).mockResolvedValue(streamWithNoFinish);
355
+ // 2. Action & Assert: The stream should fail because there's no finish reason.
356
+ const stream = await chat.sendMessageStream({ message: 'test message' }, 'prompt-id-no-finish-empty-end');
357
+ await expect((async () => {
358
+ for await (const _ of stream) {
359
+ /* consume stream */
360
+ }
361
+ })()).rejects.toThrow(EmptyStreamError);
362
+ });
363
+ it('should succeed if the stream ends with an invalid part but has a finishReason and contained a valid part', async () => {
364
+ // 1. Mock a stream that sends a valid chunk, then an invalid one, but has a finish reason.
365
+ const streamWithInvalidEnd = (async function* () {
366
+ yield {
367
+ candidates: [
368
+ {
369
+ content: {
370
+ role: 'model',
371
+ parts: [{ text: 'Initial valid content...' }],
372
+ },
373
+ },
374
+ ],
375
+ };
376
+ // This second chunk is invalid, but the response has a finishReason.
377
+ yield {
378
+ candidates: [
379
+ {
380
+ content: {
381
+ role: 'model',
382
+ parts: [{ text: '' }], // Invalid part
383
+ },
384
+ finishReason: 'STOP',
385
+ },
386
+ ],
387
+ };
388
+ })();
389
+ vi.mocked(mockModelsModule.generateContentStream).mockResolvedValue(streamWithInvalidEnd);
390
+ // 2. Action & Assert: The stream should complete without throwing an error.
391
+ const stream = await chat.sendMessageStream({ message: 'test message' }, 'prompt-id-valid-then-invalid-end');
392
+ await expect((async () => {
393
+ for await (const _ of stream) {
394
+ /* consume stream */
395
+ }
396
+ })()).resolves.not.toThrow();
397
+ // 3. Verify history was recorded correctly with only the valid part.
398
+ const history = chat.getHistory();
399
+ expect(history.length).toBe(2); // user turn + model turn
400
+ const modelTurn = history[1];
401
+ expect(modelTurn?.parts?.length).toBe(1);
402
+ expect(modelTurn?.parts[0].text).toBe('Initial valid content...');
403
+ });
404
+ it('should not consolidate text into a part that also contains a functionCall', async () => {
405
+ // 1. Mock the API to stream a malformed part followed by a valid text part.
406
+ const multiChunkStream = (async function* () {
407
+ // This malformed part has both text and a functionCall.
408
+ yield {
409
+ candidates: [
410
+ {
411
+ content: {
412
+ role: 'model',
413
+ parts: [
414
+ {
415
+ text: 'Some text',
416
+ functionCall: { name: 'do_stuff', args: {} },
417
+ },
418
+ ],
419
+ },
420
+ },
421
+ ],
422
+ };
423
+ // This valid text part should NOT be merged into the malformed one.
424
+ yield {
425
+ candidates: [
426
+ {
427
+ content: {
428
+ role: 'model',
429
+ parts: [{ text: ' that should not be merged.' }],
430
+ },
431
+ },
432
+ ],
433
+ };
434
+ })();
435
+ vi.mocked(mockModelsModule.generateContentStream).mockResolvedValue(multiChunkStream);
436
+ // 2. Action: Send a message and consume the stream.
437
+ const stream = await chat.sendMessageStream({ message: 'test message' }, 'prompt-id-malformed-chunk');
438
+ for await (const _ of stream) {
439
+ // Consume the stream to trigger history recording.
440
+ }
441
+ // 3. Assert: Check that the final history was not incorrectly consolidated.
442
+ const history = chat.getHistory();
443
+ expect(history.length).toBe(2);
444
+ const modelTurn = history[1];
445
+ // CRUCIAL ASSERTION: There should be two separate parts.
446
+ // The old, non-strict logic would incorrectly merge them, resulting in one part.
447
+ expect(modelTurn?.parts?.length).toBe(2);
448
+ // Verify the contents of each part.
449
+ expect(modelTurn?.parts[0].text).toBe('Some text');
450
+ expect(modelTurn?.parts[0].functionCall).toBeDefined();
451
+ expect(modelTurn?.parts[1].text).toBe(' that should not be merged.');
452
+ });
453
+ it('should consolidate subsequent text chunks after receiving an empty text chunk', async () => {
454
+ // 1. Mock the API to return a stream where one chunk is just an empty text part.
455
+ const multiChunkStream = (async function* () {
456
+ yield {
457
+ candidates: [
458
+ { content: { role: 'model', parts: [{ text: 'Hello' }] } },
459
+ ],
460
+ };
461
+ // FIX: The original test used { text: '' }, which is invalid.
462
+ // A chunk can be empty but still valid. This chunk is now removed
463
+ // as the important part is consolidating what comes after.
464
+ yield {
465
+ candidates: [
466
+ {
467
+ content: { role: 'model', parts: [{ text: ' World!' }] },
468
+ finishReason: 'STOP',
469
+ },
470
+ ],
471
+ };
472
+ })();
473
+ vi.mocked(mockModelsModule.generateContentStream).mockResolvedValue(multiChunkStream);
474
+ // 2. Action: Send a message and consume the stream.
475
+ const stream = await chat.sendMessageStream({ message: 'test message' }, 'prompt-id-empty-chunk-consolidation');
476
+ for await (const _ of stream) {
477
+ // Consume the stream
478
+ }
479
+ // 3. Assert: Check that the final history was correctly consolidated.
480
+ const history = chat.getHistory();
481
+ expect(history.length).toBe(2);
482
+ const modelTurn = history[1];
483
+ expect(modelTurn?.parts?.length).toBe(1);
484
+ expect(modelTurn?.parts[0].text).toBe('Hello World!');
485
+ });
486
+ it('should consolidate adjacent text parts that arrive in separate stream chunks', async () => {
487
+ // 1. Mock the API to return a stream of multiple, adjacent text chunks.
488
+ const multiChunkStream = (async function* () {
489
+ yield {
490
+ candidates: [
491
+ { content: { role: 'model', parts: [{ text: 'This is the ' }] } },
492
+ ],
493
+ };
494
+ yield {
495
+ candidates: [
496
+ { content: { role: 'model', parts: [{ text: 'first part.' }] } },
497
+ ],
498
+ };
499
+ // This function call should break the consolidation.
500
+ yield {
501
+ candidates: [
502
+ {
503
+ content: {
504
+ role: 'model',
505
+ parts: [{ functionCall: { name: 'do_stuff', args: {} } }],
506
+ },
507
+ },
508
+ ],
509
+ };
510
+ yield {
511
+ candidates: [
512
+ {
513
+ content: {
514
+ role: 'model',
515
+ parts: [{ text: 'This is the second part.' }],
516
+ },
517
+ },
518
+ ],
519
+ };
520
+ })();
521
+ vi.mocked(mockModelsModule.generateContentStream).mockResolvedValue(multiChunkStream);
522
+ // 2. Action: Send a message and consume the stream.
523
+ const stream = await chat.sendMessageStream({ message: 'test message' }, 'prompt-id-multi-chunk');
524
+ for await (const _ of stream) {
525
+ // Consume the stream to trigger history recording.
526
+ }
527
+ // 3. Assert: Check that the final history was correctly consolidated.
528
+ const history = chat.getHistory();
529
+ // The history should contain the user's turn and ONE consolidated model turn.
530
+ expect(history.length).toBe(2);
531
+ const modelTurn = history[1];
532
+ expect(modelTurn.role).toBe('model');
533
+ // The model turn should have 3 distinct parts: the merged text, the function call, and the final text.
534
+ expect(modelTurn?.parts?.length).toBe(3);
535
+ expect(modelTurn?.parts[0].text).toBe('This is the first part.');
536
+ expect(modelTurn.parts[1].functionCall).toBeDefined();
537
+ expect(modelTurn.parts[2].text).toBe('This is the second part.');
538
+ });
539
+ it('should preserve text parts that stream in the same chunk as a thought', async () => {
540
+ // 1. Mock the API to return a single chunk containing both a thought and visible text.
541
+ const mixedContentStream = (async function* () {
542
+ yield {
543
+ candidates: [
544
+ {
545
+ content: {
546
+ role: 'model',
547
+ parts: [
548
+ { thought: 'This is a thought.' },
549
+ { text: 'This is the visible text that should not be lost.' },
550
+ ],
551
+ },
552
+ finishReason: 'STOP',
553
+ },
554
+ ],
555
+ };
556
+ })();
557
+ vi.mocked(mockModelsModule.generateContentStream).mockResolvedValue(mixedContentStream);
558
+ // 2. Action: Send a message and fully consume the stream to trigger history recording.
559
+ const stream = await chat.sendMessageStream({ message: 'test message' }, 'prompt-id-mixed-chunk');
560
+ for await (const _ of stream) {
561
+ // This loop consumes the stream.
562
+ }
563
+ // 3. Assert: Check the final state of the history.
564
+ const history = chat.getHistory();
565
+ // The history should contain two turns: the user's message and the model's response.
566
+ expect(history.length).toBe(2);
567
+ const modelTurn = history[1];
568
+ expect(modelTurn.role).toBe('model');
569
+ // CRUCIAL ASSERTION:
570
+ // The buggy code would fail here, resulting in parts.length being 0.
571
+ // The corrected code will pass, preserving the single visible text part.
572
+ expect(modelTurn?.parts?.length).toBe(1);
573
+ expect(modelTurn?.parts[0].text).toBe('This is the visible text that should not be lost.');
574
+ });
575
+ it('should add a placeholder model turn when a tool call is followed by an empty stream response', async () => {
576
+ // 1. Setup: A history where the model has just made a function call.
577
+ const initialHistory = [
578
+ {
579
+ role: 'user',
580
+ parts: [{ text: 'Find a good Italian restaurant for me.' }],
581
+ },
582
+ {
583
+ role: 'model',
584
+ parts: [
585
+ {
586
+ functionCall: {
587
+ name: 'find_restaurant',
588
+ args: { cuisine: 'Italian' },
589
+ },
590
+ },
591
+ ],
592
+ },
593
+ ];
594
+ chat.setHistory(initialHistory);
595
+ // 2. Mock the API to return an empty/thought-only stream.
596
+ const emptyStreamResponse = (async function* () {
597
+ yield {
598
+ candidates: [
599
+ {
600
+ content: { role: 'model', parts: [{ thought: true }] },
601
+ finishReason: 'STOP',
602
+ },
603
+ ],
604
+ };
605
+ })();
606
+ vi.mocked(mockModelsModule.generateContentStream).mockResolvedValue(emptyStreamResponse);
607
+ // 3. Action: Send the function response back to the model and consume the stream.
608
+ const stream = await chat.sendMessageStream({
609
+ message: {
610
+ functionResponse: {
611
+ name: 'find_restaurant',
612
+ response: { name: 'Vesuvio' },
613
+ },
614
+ },
615
+ }, 'prompt-id-stream-1');
616
+ for await (const _ of stream) {
617
+ // This loop consumes the stream to trigger the internal logic.
618
+ }
619
+ // 4. Assert: The history should now have four valid, alternating turns.
620
+ const history = chat.getHistory();
621
+ expect(history.length).toBe(4);
622
+ // The final turn must be the empty model placeholder.
623
+ const lastTurn = history[3];
624
+ expect(lastTurn.role).toBe('model');
625
+ expect(lastTurn?.parts?.length).toBe(0);
626
+ // The second-to-last turn must be the function response we sent.
627
+ const secondToLastTurn = history[2];
628
+ expect(secondToLastTurn.role).toBe('user');
629
+ expect(secondToLastTurn?.parts[0].functionResponse).toBeDefined();
630
+ });
73
631
  it('should call generateContentStream with the correct parameters', async () => {
74
632
  const response = (async function* () {
75
633
  yield {
@@ -88,7 +646,10 @@ describe('GeminiChat', () => {
88
646
  };
89
647
  })();
90
648
  vi.mocked(mockModelsModule.generateContentStream).mockResolvedValue(response);
91
- await chat.sendMessageStream({ message: 'hello' }, 'prompt-id-1');
649
+ const stream = await chat.sendMessageStream({ message: 'hello' }, 'prompt-id-1');
650
+ for await (const _ of stream) {
651
+ // consume stream to trigger internal logic
652
+ }
92
653
  expect(mockModelsModule.generateContentStream).toHaveBeenCalledWith({
93
654
  model: 'gemini-pro',
94
655
  contents: [{ role: 'user', parts: [{ text: 'hello' }] }],
@@ -101,295 +662,128 @@ describe('GeminiChat', () => {
101
662
  role: 'user',
102
663
  parts: [{ text: 'User input' }],
103
664
  };
104
- it('should add user input and a single model output to history', () => {
665
+ it('should consolidate all consecutive model turns into a single turn', () => {
666
+ const userInput = {
667
+ role: 'user',
668
+ parts: [{ text: 'User input' }],
669
+ };
670
+ // This simulates a multi-part model response with different part types.
105
671
  const modelOutput = [
106
- { role: 'model', parts: [{ text: 'Model output' }] },
672
+ { role: 'model', parts: [{ text: 'Thinking...' }] },
673
+ {
674
+ role: 'model',
675
+ parts: [{ functionCall: { name: 'do_stuff', args: {} } }],
676
+ },
107
677
  ];
108
- // @ts-expect-error Accessing private method for testing purposes
678
+ // @ts-expect-error Accessing private method for testing
109
679
  chat.recordHistory(userInput, modelOutput);
110
680
  const history = chat.getHistory();
111
- expect(history).toEqual([userInput, modelOutput[0]]);
112
- });
113
- it('should consolidate adjacent model outputs', () => {
114
- const modelOutputParts = [
115
- { role: 'model', parts: [{ text: 'Model part 1' }] },
116
- { role: 'model', parts: [{ text: 'Model part 2' }] },
117
- ];
118
- // @ts-expect-error Accessing private method for testing purposes
119
- chat.recordHistory(userInput, modelOutputParts);
120
- const history = chat.getHistory();
121
- expect(history.length).toBe(2);
122
- expect(history[0]).toEqual(userInput);
123
- expect(history[1].role).toBe('model');
124
- expect(history[1].parts).toEqual([{ text: 'Model part 1Model part 2' }]);
125
- });
126
- it('should handle a mix of user and model roles in outputContents (though unusual)', () => {
127
- const mixedOutput = [
128
- { role: 'model', parts: [{ text: 'Model 1' }] },
129
- { role: 'user', parts: [{ text: 'Unexpected User' }] }, // This should be pushed as is
130
- { role: 'model', parts: [{ text: 'Model 2' }] },
131
- ];
132
- // @ts-expect-error Accessing private method for testing purposes
133
- chat.recordHistory(userInput, mixedOutput);
134
- const history = chat.getHistory();
135
- expect(history.length).toBe(4); // user, model1, user_unexpected, model2
136
- expect(history[0]).toEqual(userInput);
137
- expect(history[1]).toEqual(mixedOutput[0]);
138
- expect(history[2]).toEqual(mixedOutput[1]);
139
- expect(history[3]).toEqual(mixedOutput[2]);
140
- });
141
- it('should consolidate multiple adjacent model outputs correctly', () => {
142
- const modelOutputParts = [
143
- { role: 'model', parts: [{ text: 'M1' }] },
144
- { role: 'model', parts: [{ text: 'M2' }] },
145
- { role: 'model', parts: [{ text: 'M3' }] },
146
- ];
147
- // @ts-expect-error Accessing private method for testing purposes
148
- chat.recordHistory(userInput, modelOutputParts);
149
- const history = chat.getHistory();
681
+ // The history should contain the user's turn and ONE consolidated model turn.
682
+ // The old code would fail here, resulting in a length of 3.
683
+ //expect(history).toBe([]);
150
684
  expect(history.length).toBe(2);
151
- expect(history[1].parts).toEqual([{ text: 'M1M2M3' }]);
685
+ const modelTurn = history[1];
686
+ expect(modelTurn.role).toBe('model');
687
+ // The consolidated turn should contain both the text part and the functionCall part.
688
+ expect(modelTurn?.parts?.length).toBe(2);
689
+ expect(modelTurn?.parts[0].text).toBe('Thinking...');
690
+ expect(modelTurn?.parts[1].functionCall).toBeDefined();
152
691
  });
153
- it('should not consolidate if roles are different between model outputs', () => {
154
- const modelOutputParts = [
155
- { role: 'model', parts: [{ text: 'M1' }] },
156
- { role: 'user', parts: [{ text: 'Interjecting User' }] },
157
- { role: 'model', parts: [{ text: 'M2' }] },
158
- ];
159
- // @ts-expect-error Accessing private method for testing purposes
160
- chat.recordHistory(userInput, modelOutputParts);
161
- const history = chat.getHistory();
162
- expect(history.length).toBe(4); // user, M1, Interjecting User, M2
163
- expect(history[1].parts).toEqual([{ text: 'M1' }]);
164
- expect(history[3].parts).toEqual([{ text: 'M2' }]);
165
- });
166
- it('should merge with last history entry if it is also a model output', () => {
167
- // @ts-expect-error Accessing private property for test setup
168
- chat.history = [
169
- userInput,
170
- { role: 'model', parts: [{ text: 'Initial Model Output' }] },
171
- ]; // Prime the history
172
- const newModelOutput = [
173
- { role: 'model', parts: [{ text: 'New Model Part 1' }] },
174
- { role: 'model', parts: [{ text: 'New Model Part 2' }] },
175
- ];
176
- // @ts-expect-error Accessing private method for testing purposes
177
- chat.recordHistory(userInput, newModelOutput); // userInput here is for the *next* turn, but history is already primed
178
- // Reset and set up a more realistic scenario for merging with existing history
179
- chat = new GeminiChat(mockConfig, mockModelsModule, config, []);
180
- const firstUserInput = {
181
- role: 'user',
182
- parts: [{ text: 'First user input' }],
183
- };
184
- const firstModelOutput = [
185
- { role: 'model', parts: [{ text: 'First model response' }] },
186
- ];
187
- // @ts-expect-error Accessing private method for testing purposes
188
- chat.recordHistory(firstUserInput, firstModelOutput);
189
- const secondUserInput = {
190
- role: 'user',
191
- parts: [{ text: 'Second user input' }],
192
- };
193
- const secondModelOutput = [
194
- { role: 'model', parts: [{ text: 'Second model response part 1' }] },
195
- { role: 'model', parts: [{ text: 'Second model response part 2' }] },
692
+ it('should add a placeholder model turn when a tool call is followed by an empty response', () => {
693
+ // 1. Setup: A history where the model has just made a function call.
694
+ const initialHistory = [
695
+ { role: 'user', parts: [{ text: 'Initial prompt' }] },
696
+ {
697
+ role: 'model',
698
+ parts: [{ functionCall: { name: 'test_tool', args: {} } }],
699
+ },
196
700
  ];
197
- // @ts-expect-error Accessing private method for testing purposes
198
- chat.recordHistory(secondUserInput, secondModelOutput);
199
- const finalHistory = chat.getHistory();
200
- expect(finalHistory.length).toBe(4); // user1, model1, user2, model2(consolidated)
201
- expect(finalHistory[0]).toEqual(firstUserInput);
202
- expect(finalHistory[1]).toEqual(firstModelOutput[0]);
203
- expect(finalHistory[2]).toEqual(secondUserInput);
204
- expect(finalHistory[3].role).toBe('model');
205
- expect(finalHistory[3].parts).toEqual([
206
- { text: 'Second model response part 1Second model response part 2' },
207
- ]);
208
- });
209
- it('should correctly merge consolidated new output with existing model history', () => {
210
- // Setup: history ends with a model turn
211
- const initialUser = {
701
+ chat.setHistory(initialHistory);
702
+ // 2. Action: The user provides the tool's response, and the model's
703
+ // final output is empty (e.g., just a thought, which gets filtered out).
704
+ const functionResponse = {
212
705
  role: 'user',
213
- parts: [{ text: 'Initial user query' }],
706
+ parts: [{ functionResponse: { name: 'test_tool', response: {} } }],
214
707
  };
215
- const initialModel = {
216
- role: 'model',
217
- parts: [{ text: 'Initial model answer.' }],
218
- };
219
- chat = new GeminiChat(mockConfig, mockModelsModule, config, [
220
- initialUser,
221
- initialModel,
708
+ const emptyModelOutput = [];
709
+ // @ts-expect-error Accessing private method for testing
710
+ chat.recordHistory(functionResponse, emptyModelOutput, [
711
+ functionResponse,
222
712
  ]);
223
- // New interaction
224
- const currentUserInput = {
225
- role: 'user',
226
- parts: [{ text: 'Follow-up question' }],
227
- };
228
- const newModelParts = [
229
- { role: 'model', parts: [{ text: 'Part A of new answer.' }] },
230
- { role: 'model', parts: [{ text: 'Part B of new answer.' }] },
231
- ];
232
- // @ts-expect-error Accessing private method for testing purposes
233
- chat.recordHistory(currentUserInput, newModelParts);
713
+ // 3. Assert: The history should now have four valid, alternating turns.
234
714
  const history = chat.getHistory();
235
- // Expected: initialUser, initialModel, currentUserInput, consolidatedNewModelParts
236
715
  expect(history.length).toBe(4);
237
- expect(history[0]).toEqual(initialUser);
238
- expect(history[1]).toEqual(initialModel);
239
- expect(history[2]).toEqual(currentUserInput);
240
- expect(history[3].role).toBe('model');
241
- expect(history[3].parts).toEqual([
242
- { text: 'Part A of new answer.Part B of new answer.' },
243
- ]);
244
- });
245
- it('should handle empty modelOutput array', () => {
246
- // @ts-expect-error Accessing private method for testing purposes
247
- chat.recordHistory(userInput, []);
248
- const history = chat.getHistory();
249
- // If modelOutput is empty, it might push a default empty model part depending on isFunctionResponse
250
- // Assuming isFunctionResponse(userInput) is false for this simple text input
251
- expect(history.length).toBe(2);
252
- expect(history[0]).toEqual(userInput);
253
- expect(history[1].role).toBe('model');
254
- expect(history[1].parts).toEqual([]);
255
- });
256
- it('should handle aggregating modelOutput', () => {
257
- const modelOutputUndefinedParts = [
258
- { role: 'model', parts: [{ text: 'First model part' }] },
259
- { role: 'model', parts: [{ text: 'Second model part' }] },
260
- { role: 'model', parts: undefined }, // Test undefined parts
261
- { role: 'model', parts: [{ text: 'Third model part' }] },
262
- { role: 'model', parts: [] }, // Test empty parts array
263
- ];
264
- // @ts-expect-error Accessing private method for testing purposes
265
- chat.recordHistory(userInput, modelOutputUndefinedParts);
266
- const history = chat.getHistory();
267
- expect(history.length).toBe(5);
268
- expect(history[0]).toEqual(userInput);
269
- expect(history[1].role).toBe('model');
270
- expect(history[1].parts).toEqual([
271
- { text: 'First model partSecond model part' },
272
- ]);
273
- expect(history[2].role).toBe('model');
274
- expect(history[2].parts).toBeUndefined();
275
- expect(history[3].role).toBe('model');
276
- expect(history[3].parts).toEqual([{ text: 'Third model part' }]);
277
- expect(history[4].role).toBe('model');
278
- expect(history[4].parts).toEqual([]);
279
- });
280
- it('should handle modelOutput with parts being undefined or empty (if they pass initial every check)', () => {
281
- const modelOutputUndefinedParts = [
282
- { role: 'model', parts: [{ text: 'Text part' }] },
283
- { role: 'model', parts: undefined }, // Test undefined parts
284
- { role: 'model', parts: [] }, // Test empty parts array
285
- ];
286
- // @ts-expect-error Accessing private method for testing purposes
287
- chat.recordHistory(userInput, modelOutputUndefinedParts);
288
- const history = chat.getHistory();
289
- expect(history.length).toBe(4); // userInput, model1 (text), model2 (undefined parts), model3 (empty parts)
290
- expect(history[0]).toEqual(userInput);
291
- expect(history[1].role).toBe('model');
292
- expect(history[1].parts).toEqual([{ text: 'Text part' }]);
293
- expect(history[2].role).toBe('model');
294
- expect(history[2].parts).toBeUndefined();
295
- expect(history[3].role).toBe('model');
296
- expect(history[3].parts).toEqual([]);
716
+ // The final turn must be the empty model placeholder.
717
+ const lastTurn = history[3];
718
+ expect(lastTurn.role).toBe('model');
719
+ expect(lastTurn?.parts?.length).toBe(0);
720
+ // The second-to-last turn must be the function response we provided.
721
+ const secondToLastTurn = history[2];
722
+ expect(secondToLastTurn.role).toBe('user');
723
+ expect(secondToLastTurn?.parts[0].functionResponse).toBeDefined();
297
724
  });
298
- it('should correctly handle automaticFunctionCallingHistory', () => {
299
- const afcHistory = [
300
- { role: 'user', parts: [{ text: 'AFC User' }] },
301
- { role: 'model', parts: [{ text: 'AFC Model' }] },
302
- ];
303
- const modelOutput = [
304
- { role: 'model', parts: [{ text: 'Regular Model Output' }] },
305
- ];
306
- // @ts-expect-error Accessing private method for testing purposes
307
- chat.recordHistory(userInput, modelOutput, afcHistory);
308
- const history = chat.getHistory();
309
- expect(history.length).toBe(3);
310
- expect(history[0]).toEqual(afcHistory[0]);
311
- expect(history[1]).toEqual(afcHistory[1]);
312
- expect(history[2]).toEqual(modelOutput[0]);
313
- });
314
- it('should add userInput if AFC history is present but empty', () => {
725
+ it('should add user input and a single model output to history', () => {
315
726
  const modelOutput = [
316
- { role: 'model', parts: [{ text: 'Model Output' }] },
727
+ { role: 'model', parts: [{ text: 'Model output' }] },
317
728
  ];
318
- // @ts-expect-error Accessing private method for testing purposes
319
- chat.recordHistory(userInput, modelOutput, []); // Empty AFC history
729
+ // @ts-expect-error Accessing private method for testing
730
+ chat.recordHistory(userInput, modelOutput);
320
731
  const history = chat.getHistory();
321
732
  expect(history.length).toBe(2);
322
733
  expect(history[0]).toEqual(userInput);
323
734
  expect(history[1]).toEqual(modelOutput[0]);
324
735
  });
325
- it('should skip "thought" content from modelOutput', () => {
326
- const modelOutputWithThought = [
327
- { role: 'model', parts: [{ thought: true }, { text: 'Visible text' }] },
328
- { role: 'model', parts: [{ text: 'Another visible text' }] },
736
+ it('should consolidate adjacent text parts from multiple content objects', () => {
737
+ const modelOutput = [
738
+ { role: 'model', parts: [{ text: 'Part 1.' }] },
739
+ { role: 'model', parts: [{ text: ' Part 2.' }] },
740
+ { role: 'model', parts: [{ text: ' Part 3.' }] },
329
741
  ];
330
- // @ts-expect-error Accessing private method for testing purposes
331
- chat.recordHistory(userInput, modelOutputWithThought);
742
+ // @ts-expect-error Accessing private method for testing
743
+ chat.recordHistory(userInput, modelOutput);
332
744
  const history = chat.getHistory();
333
- expect(history.length).toBe(2); // User input + consolidated model output
334
- expect(history[0]).toEqual(userInput);
745
+ expect(history.length).toBe(2);
335
746
  expect(history[1].role).toBe('model');
336
- // The 'thought' part is skipped, 'Another visible text' becomes the first part.
337
- expect(history[1].parts).toEqual([{ text: 'Another visible text' }]);
747
+ expect(history[1].parts).toEqual([{ text: 'Part 1. Part 2. Part 3.' }]);
338
748
  });
339
- it('should skip "thought" content even if it is the only content', () => {
340
- const modelOutputOnlyThought = [
341
- { role: 'model', parts: [{ thought: true }] },
342
- ];
343
- // @ts-expect-error Accessing private method for testing purposes
344
- chat.recordHistory(userInput, modelOutputOnlyThought);
345
- const history = chat.getHistory();
346
- expect(history.length).toBe(1); // User input + default empty model part
347
- expect(history[0]).toEqual(userInput);
348
- });
349
- it('should correctly consolidate text parts when a thought part is in between', () => {
350
- const modelOutputMixed = [
351
- { role: 'model', parts: [{ text: 'Part 1.' }] },
352
- {
353
- role: 'model',
354
- parts: [{ thought: true }, { text: 'Should be skipped' }],
355
- },
356
- { role: 'model', parts: [{ text: 'Part 2.' }] },
357
- ];
358
- // @ts-expect-error Accessing private method for testing purposes
359
- chat.recordHistory(userInput, modelOutputMixed);
749
+ it('should add an empty placeholder turn if modelOutput is empty', () => {
750
+ // This simulates receiving a pre-filtered, thought-only response.
751
+ const emptyModelOutput = [];
752
+ // @ts-expect-error Accessing private method for testing
753
+ chat.recordHistory(userInput, emptyModelOutput);
360
754
  const history = chat.getHistory();
361
755
  expect(history.length).toBe(2);
362
756
  expect(history[0]).toEqual(userInput);
363
757
  expect(history[1].role).toBe('model');
364
- expect(history[1].parts).toEqual([{ text: 'Part 1.Part 2.' }]);
758
+ expect(history[1].parts).toEqual([]);
365
759
  });
366
- it('should handle multiple thought parts correctly', () => {
367
- const modelOutputMultipleThoughts = [
368
- { role: 'model', parts: [{ thought: true }] },
369
- { role: 'model', parts: [{ text: 'Visible 1' }] },
370
- { role: 'model', parts: [{ thought: true }] },
371
- { role: 'model', parts: [{ text: 'Visible 2' }] },
760
+ it('should preserve model outputs with undefined or empty parts arrays', () => {
761
+ const malformedOutput = [
762
+ { role: 'model', parts: [{ text: 'Text part' }] },
763
+ { role: 'model', parts: undefined },
764
+ { role: 'model', parts: [] },
372
765
  ];
373
- // @ts-expect-error Accessing private method for testing purposes
374
- chat.recordHistory(userInput, modelOutputMultipleThoughts);
766
+ // @ts-expect-error Accessing private method for testing
767
+ chat.recordHistory(userInput, malformedOutput);
375
768
  const history = chat.getHistory();
376
- expect(history.length).toBe(2);
377
- expect(history[0]).toEqual(userInput);
378
- expect(history[1].role).toBe('model');
379
- expect(history[1].parts).toEqual([{ text: 'Visible 1Visible 2' }]);
769
+ expect(history.length).toBe(4); // userInput + 3 model turns
770
+ expect(history[1].parts).toEqual([{ text: 'Text part' }]);
771
+ expect(history[2].parts).toBeUndefined();
772
+ expect(history[3].parts).toEqual([]);
380
773
  });
381
- it('should handle thought part at the end of outputContents', () => {
382
- const modelOutputThoughtAtEnd = [
383
- { role: 'model', parts: [{ text: 'Visible text' }] },
384
- { role: 'model', parts: [{ thought: true }] },
774
+ it('should not consolidate content with different roles', () => {
775
+ const mixedOutput = [
776
+ { role: 'model', parts: [{ text: 'Model 1' }] },
777
+ { role: 'user', parts: [{ text: 'Unexpected User' }] },
778
+ { role: 'model', parts: [{ text: 'Model 2' }] },
385
779
  ];
386
- // @ts-expect-error Accessing private method for testing purposes
387
- chat.recordHistory(userInput, modelOutputThoughtAtEnd);
780
+ // @ts-expect-error Accessing private method for testing
781
+ chat.recordHistory(userInput, mixedOutput);
388
782
  const history = chat.getHistory();
389
- expect(history.length).toBe(2);
390
- expect(history[0]).toEqual(userInput);
391
- expect(history[1].role).toBe('model');
392
- expect(history[1].parts).toEqual([{ text: 'Visible text' }]);
783
+ expect(history.length).toBe(4); // userInput, model1, unexpected_user, model2
784
+ expect(history[1]).toEqual(mixedOutput[0]);
785
+ expect(history[2]).toEqual(mixedOutput[1]);
786
+ expect(history[3]).toEqual(mixedOutput[2]);
393
787
  });
394
788
  });
395
789
  describe('addHistory', () => {
@@ -420,5 +814,395 @@ describe('GeminiChat', () => {
420
814
  expect(history[1]).toEqual(content2);
421
815
  });
422
816
  });
817
+ describe('sendMessageStream with retries', () => {
818
+ it('should yield a RETRY event when an invalid stream is encountered', async () => {
819
+ // ARRANGE: Mock the stream to fail once, then succeed.
820
+ vi.mocked(mockModelsModule.generateContentStream)
821
+ .mockImplementationOnce(async () =>
822
+ // First attempt: An invalid stream with an empty text part.
823
+ (async function* () {
824
+ yield {
825
+ candidates: [{ content: { parts: [{ text: '' }] } }],
826
+ };
827
+ })())
828
+ .mockImplementationOnce(async () =>
829
+ // Second attempt (the retry): A minimal valid stream.
830
+ (async function* () {
831
+ yield {
832
+ candidates: [
833
+ {
834
+ content: { parts: [{ text: 'Success' }] },
835
+ finishReason: 'STOP',
836
+ },
837
+ ],
838
+ };
839
+ })());
840
+ // ACT: Send a message and collect all events from the stream.
841
+ const stream = await chat.sendMessageStream({ message: 'test' }, 'prompt-id-yield-retry');
842
+ const events = [];
843
+ for await (const event of stream) {
844
+ events.push(event);
845
+ }
846
+ // ASSERT: Check that a RETRY event was present in the stream's output.
847
+ const retryEvent = events.find((e) => e.type === StreamEventType.RETRY);
848
+ expect(retryEvent).toBeDefined();
849
+ expect(retryEvent?.type).toBe(StreamEventType.RETRY);
850
+ });
851
+ it('should retry on invalid content, succeed, and report metrics', async () => {
852
+ // Use mockImplementationOnce to provide a fresh, promise-wrapped generator for each attempt.
853
+ vi.mocked(mockModelsModule.generateContentStream)
854
+ .mockImplementationOnce(async () =>
855
+ // First call returns an invalid stream
856
+ (async function* () {
857
+ yield {
858
+ candidates: [{ content: { parts: [{ text: '' }] } }], // Invalid empty text part
859
+ };
860
+ })())
861
+ .mockImplementationOnce(async () =>
862
+ // Second call returns a valid stream
863
+ (async function* () {
864
+ yield {
865
+ candidates: [
866
+ {
867
+ content: { parts: [{ text: 'Successful response' }] },
868
+ finishReason: 'STOP',
869
+ },
870
+ ],
871
+ };
872
+ })());
873
+ const stream = await chat.sendMessageStream({ message: 'test' }, 'prompt-id-retry-success');
874
+ const chunks = [];
875
+ for await (const chunk of stream) {
876
+ chunks.push(chunk);
877
+ }
878
+ // Assertions
879
+ expect(mockLogInvalidChunk).toHaveBeenCalledTimes(1);
880
+ expect(mockLogContentRetry).toHaveBeenCalledTimes(1);
881
+ expect(mockLogContentRetryFailure).not.toHaveBeenCalled();
882
+ expect(mockModelsModule.generateContentStream).toHaveBeenCalledTimes(2);
883
+ // Check for a retry event
884
+ expect(chunks.some((c) => c.type === StreamEventType.RETRY)).toBe(true);
885
+ // Check for the successful content chunk
886
+ expect(chunks.some((c) => c.type === StreamEventType.CHUNK &&
887
+ c.value.candidates?.[0]?.content?.parts?.[0]?.text ===
888
+ 'Successful response')).toBe(true);
889
+ // Check that history was recorded correctly once, with no duplicates.
890
+ const history = chat.getHistory();
891
+ expect(history.length).toBe(2);
892
+ expect(history[0]).toEqual({
893
+ role: 'user',
894
+ parts: [{ text: 'test' }],
895
+ });
896
+ expect(history[1]).toEqual({
897
+ role: 'model',
898
+ parts: [{ text: 'Successful response' }],
899
+ });
900
+ });
901
+ it('should fail after all retries on persistent invalid content and report metrics', async () => {
902
+ vi.mocked(mockModelsModule.generateContentStream).mockImplementation(async () => (async function* () {
903
+ yield {
904
+ candidates: [
905
+ {
906
+ content: {
907
+ parts: [{ text: '' }],
908
+ role: 'model',
909
+ },
910
+ },
911
+ ],
912
+ };
913
+ })());
914
+ // This helper function consumes the stream and allows us to test for rejection.
915
+ async function consumeStreamAndExpectError() {
916
+ const stream = await chat.sendMessageStream({ message: 'test' }, 'prompt-id-retry-fail');
917
+ for await (const _ of stream) {
918
+ // Must loop to trigger the internal logic that throws.
919
+ }
920
+ }
921
+ await expect(consumeStreamAndExpectError()).rejects.toThrow(EmptyStreamError);
922
+ // Should be called 3 times (initial + 2 retries)
923
+ expect(mockModelsModule.generateContentStream).toHaveBeenCalledTimes(3);
924
+ expect(mockLogInvalidChunk).toHaveBeenCalledTimes(3);
925
+ expect(mockLogContentRetry).toHaveBeenCalledTimes(2);
926
+ expect(mockLogContentRetryFailure).toHaveBeenCalledTimes(1);
927
+ // History should be clean, as if the failed turn never happened.
928
+ const history = chat.getHistory();
929
+ expect(history.length).toBe(0);
930
+ });
931
+ });
932
+ it('should correctly retry and append to an existing history mid-conversation', async () => {
933
+ // 1. Setup
934
+ const initialHistory = [
935
+ { role: 'user', parts: [{ text: 'First question' }] },
936
+ { role: 'model', parts: [{ text: 'First answer' }] },
937
+ ];
938
+ chat.setHistory(initialHistory);
939
+ // 2. Mock the API to fail once with an empty stream, then succeed.
940
+ vi.mocked(mockModelsModule.generateContentStream)
941
+ .mockImplementationOnce(async () => (async function* () {
942
+ yield {
943
+ candidates: [{ content: { parts: [{ text: '' }] } }],
944
+ };
945
+ })())
946
+ .mockImplementationOnce(async () =>
947
+ // Second attempt succeeds
948
+ (async function* () {
949
+ yield {
950
+ candidates: [
951
+ {
952
+ content: { parts: [{ text: 'Second answer' }] },
953
+ finishReason: 'STOP',
954
+ },
955
+ ],
956
+ };
957
+ })());
958
+ // 3. Send a new message
959
+ const stream = await chat.sendMessageStream({ message: 'Second question' }, 'prompt-id-retry-existing');
960
+ for await (const _ of stream) {
961
+ // consume stream
962
+ }
963
+ // 4. Assert the final history and metrics
964
+ const history = chat.getHistory();
965
+ expect(history.length).toBe(4);
966
+ // Assert that the correct metrics were reported for one empty-stream retry
967
+ expect(mockLogContentRetry).toHaveBeenCalledTimes(1);
968
+ // Explicitly verify the structure of each part to satisfy TypeScript
969
+ const turn1 = history[0];
970
+ if (!turn1?.parts?.[0] || !('text' in turn1.parts[0])) {
971
+ throw new Error('Test setup error: First turn is not a valid text part.');
972
+ }
973
+ expect(turn1.parts[0].text).toBe('First question');
974
+ const turn2 = history[1];
975
+ if (!turn2?.parts?.[0] || !('text' in turn2.parts[0])) {
976
+ throw new Error('Test setup error: Second turn is not a valid text part.');
977
+ }
978
+ expect(turn2.parts[0].text).toBe('First answer');
979
+ const turn3 = history[2];
980
+ if (!turn3?.parts?.[0] || !('text' in turn3.parts[0])) {
981
+ throw new Error('Test setup error: Third turn is not a valid text part.');
982
+ }
983
+ expect(turn3.parts[0].text).toBe('Second question');
984
+ const turn4 = history[3];
985
+ if (!turn4?.parts?.[0] || !('text' in turn4.parts[0])) {
986
+ throw new Error('Test setup error: Fourth turn is not a valid text part.');
987
+ }
988
+ expect(turn4.parts[0].text).toBe('Second answer');
989
+ });
990
+ describe('concurrency control', () => {
991
+ it('should queue a subsequent sendMessage call until the first one completes', async () => {
992
+ // 1. Create promises to manually control when the API calls resolve
993
+ let firstCallResolver;
994
+ const firstCallPromise = new Promise((resolve) => {
995
+ firstCallResolver = resolve;
996
+ });
997
+ let secondCallResolver;
998
+ const secondCallPromise = new Promise((resolve) => {
999
+ secondCallResolver = resolve;
1000
+ });
1001
+ // A standard response body for the mock
1002
+ const mockResponse = {
1003
+ candidates: [
1004
+ {
1005
+ content: { parts: [{ text: 'response' }], role: 'model' },
1006
+ },
1007
+ ],
1008
+ };
1009
+ // 2. Mock the API to return our controllable promises in order
1010
+ vi.mocked(mockModelsModule.generateContent)
1011
+ .mockReturnValueOnce(firstCallPromise)
1012
+ .mockReturnValueOnce(secondCallPromise);
1013
+ // 3. Start the first message call. Do not await it yet.
1014
+ const firstMessagePromise = chat.sendMessage({ message: 'first' }, 'prompt-1');
1015
+ // Give the event loop a chance to run the async call up to the `await`
1016
+ await new Promise(process.nextTick);
1017
+ // 4. While the first call is "in-flight", start the second message call.
1018
+ const secondMessagePromise = chat.sendMessage({ message: 'second' }, 'prompt-2');
1019
+ // 5. CRUCIAL CHECK: At this point, only the first API call should have been made.
1020
+ // The second call should be waiting on `sendPromise`.
1021
+ expect(mockModelsModule.generateContent).toHaveBeenCalledTimes(1);
1022
+ expect(mockModelsModule.generateContent).toHaveBeenCalledWith(expect.objectContaining({
1023
+ contents: expect.arrayContaining([
1024
+ expect.objectContaining({ parts: [{ text: 'first' }] }),
1025
+ ]),
1026
+ }), 'prompt-1');
1027
+ // 6. Unblock the first API call and wait for the first message to fully complete.
1028
+ firstCallResolver(mockResponse);
1029
+ await firstMessagePromise;
1030
+ // Give the event loop a chance to unblock and run the second call.
1031
+ await new Promise(process.nextTick);
1032
+ // 7. CRUCIAL CHECK: Now, the second API call should have been made.
1033
+ expect(mockModelsModule.generateContent).toHaveBeenCalledTimes(2);
1034
+ expect(mockModelsModule.generateContent).toHaveBeenCalledWith(expect.objectContaining({
1035
+ contents: expect.arrayContaining([
1036
+ expect.objectContaining({ parts: [{ text: 'second' }] }),
1037
+ ]),
1038
+ }), 'prompt-2');
1039
+ // 8. Clean up by resolving the second call.
1040
+ secondCallResolver(mockResponse);
1041
+ await secondMessagePromise;
1042
+ });
1043
+ });
1044
+ it('should retry if the model returns a completely empty stream (no chunks)', async () => {
1045
+ // 1. Mock the API to return an empty stream first, then a valid one.
1046
+ vi.mocked(mockModelsModule.generateContentStream)
1047
+ .mockImplementationOnce(
1048
+ // First call resolves to an async generator that yields nothing.
1049
+ async () => (async function* () { })())
1050
+ .mockImplementationOnce(
1051
+ // Second call returns a valid stream.
1052
+ async () => (async function* () {
1053
+ yield {
1054
+ candidates: [
1055
+ {
1056
+ content: {
1057
+ parts: [{ text: 'Successful response after empty' }],
1058
+ },
1059
+ finishReason: 'STOP',
1060
+ },
1061
+ ],
1062
+ };
1063
+ })());
1064
+ // 2. Call the method and consume the stream.
1065
+ const stream = await chat.sendMessageStream({ message: 'test empty stream' }, 'prompt-id-empty-stream');
1066
+ const chunks = [];
1067
+ for await (const chunk of stream) {
1068
+ chunks.push(chunk);
1069
+ }
1070
+ // 3. Assert the results.
1071
+ expect(mockModelsModule.generateContentStream).toHaveBeenCalledTimes(2);
1072
+ expect(chunks.some((c) => c.type === StreamEventType.CHUNK &&
1073
+ c.value.candidates?.[0]?.content?.parts?.[0]?.text ===
1074
+ 'Successful response after empty')).toBe(true);
1075
+ const history = chat.getHistory();
1076
+ expect(history.length).toBe(2);
1077
+ // Explicitly verify the structure of each part to satisfy TypeScript
1078
+ const turn1 = history[0];
1079
+ if (!turn1?.parts?.[0] || !('text' in turn1.parts[0])) {
1080
+ throw new Error('Test setup error: First turn is not a valid text part.');
1081
+ }
1082
+ expect(turn1.parts[0].text).toBe('test empty stream');
1083
+ const turn2 = history[1];
1084
+ if (!turn2?.parts?.[0] || !('text' in turn2.parts[0])) {
1085
+ throw new Error('Test setup error: Second turn is not a valid text part.');
1086
+ }
1087
+ expect(turn2.parts[0].text).toBe('Successful response after empty');
1088
+ });
1089
+ it('should queue a subsequent sendMessageStream call until the first stream is fully consumed', async () => {
1090
+ // 1. Create a promise to manually control the stream's lifecycle
1091
+ let continueFirstStream;
1092
+ const firstStreamContinuePromise = new Promise((resolve) => {
1093
+ continueFirstStream = resolve;
1094
+ });
1095
+ // 2. Mock the API to return controllable async generators
1096
+ const firstStreamGenerator = (async function* () {
1097
+ yield {
1098
+ candidates: [
1099
+ { content: { parts: [{ text: 'first response part 1' }] } },
1100
+ ],
1101
+ };
1102
+ await firstStreamContinuePromise; // Pause the stream
1103
+ yield {
1104
+ candidates: [
1105
+ {
1106
+ content: { parts: [{ text: ' part 2' }] },
1107
+ finishReason: 'STOP',
1108
+ },
1109
+ ],
1110
+ };
1111
+ })();
1112
+ const secondStreamGenerator = (async function* () {
1113
+ yield {
1114
+ candidates: [
1115
+ {
1116
+ content: { parts: [{ text: 'second response' }] },
1117
+ finishReason: 'STOP',
1118
+ },
1119
+ ],
1120
+ };
1121
+ })();
1122
+ vi.mocked(mockModelsModule.generateContentStream)
1123
+ .mockResolvedValueOnce(firstStreamGenerator)
1124
+ .mockResolvedValueOnce(secondStreamGenerator);
1125
+ // 3. Start the first stream and consume only the first chunk to pause it
1126
+ const firstStream = await chat.sendMessageStream({ message: 'first' }, 'prompt-1');
1127
+ const firstStreamIterator = firstStream[Symbol.asyncIterator]();
1128
+ await firstStreamIterator.next();
1129
+ // 4. While the first stream is paused, start the second call. It will block.
1130
+ const secondStreamPromise = chat.sendMessageStream({ message: 'second' }, 'prompt-2');
1131
+ // 5. Assert that only one API call has been made so far.
1132
+ expect(mockModelsModule.generateContentStream).toHaveBeenCalledTimes(1);
1133
+ // 6. Unblock and fully consume the first stream to completion.
1134
+ continueFirstStream();
1135
+ await firstStreamIterator.next(); // Consume the rest of the stream
1136
+ await firstStreamIterator.next(); // Finish the iterator
1137
+ // 7. Now that the first stream is done, await the second promise to get its generator.
1138
+ const secondStream = await secondStreamPromise;
1139
+ // 8. Start consuming the second stream, which triggers its internal API call.
1140
+ const secondStreamIterator = secondStream[Symbol.asyncIterator]();
1141
+ await secondStreamIterator.next();
1142
+ // 9. The second API call should now have been made.
1143
+ expect(mockModelsModule.generateContentStream).toHaveBeenCalledTimes(2);
1144
+ // 10. FIX: Fully consume the second stream to ensure recordHistory is called.
1145
+ await secondStreamIterator.next(); // This finishes the iterator.
1146
+ // 11. Final check on history.
1147
+ const history = chat.getHistory();
1148
+ expect(history.length).toBe(4);
1149
+ const turn4 = history[3];
1150
+ if (!turn4?.parts?.[0] || !('text' in turn4.parts[0])) {
1151
+ throw new Error('Test setup error: Fourth turn is not a valid text part.');
1152
+ }
1153
+ expect(turn4.parts[0].text).toBe('second response');
1154
+ });
1155
+ it('should discard valid partial content from a failed attempt upon retry', async () => {
1156
+ // ARRANGE: Mock the stream to fail on the first attempt after yielding some valid content.
1157
+ vi.mocked(mockModelsModule.generateContentStream)
1158
+ .mockImplementationOnce(async () =>
1159
+ // First attempt: yields one valid chunk, then one invalid chunk
1160
+ (async function* () {
1161
+ yield {
1162
+ candidates: [
1163
+ {
1164
+ content: {
1165
+ parts: [{ text: 'This valid part should be discarded' }],
1166
+ },
1167
+ },
1168
+ ],
1169
+ };
1170
+ yield {
1171
+ candidates: [{ content: { parts: [{ text: '' }] } }], // Invalid chunk triggers retry
1172
+ };
1173
+ })())
1174
+ .mockImplementationOnce(async () =>
1175
+ // Second attempt (the retry): succeeds
1176
+ (async function* () {
1177
+ yield {
1178
+ candidates: [
1179
+ {
1180
+ content: {
1181
+ parts: [{ text: 'Successful final response' }],
1182
+ },
1183
+ finishReason: 'STOP',
1184
+ },
1185
+ ],
1186
+ };
1187
+ })());
1188
+ // ACT: Send a message and consume the stream
1189
+ const stream = await chat.sendMessageStream({ message: 'test' }, 'prompt-id-discard-test');
1190
+ const events = [];
1191
+ for await (const event of stream) {
1192
+ events.push(event);
1193
+ }
1194
+ // ASSERT
1195
+ // Check that a retry happened
1196
+ expect(mockModelsModule.generateContentStream).toHaveBeenCalledTimes(2);
1197
+ expect(events.some((e) => e.type === StreamEventType.RETRY)).toBe(true);
1198
+ // Check the final recorded history
1199
+ const history = chat.getHistory();
1200
+ expect(history.length).toBe(2); // user turn + final model turn
1201
+ const modelTurn = history[1];
1202
+ // The model turn should only contain the text from the successful attempt
1203
+ expect(modelTurn.parts[0].text).toBe('Successful final response');
1204
+ // It should NOT contain any text from the failed attempt
1205
+ expect(modelTurn.parts[0].text).not.toContain('This valid part should be discarded');
1206
+ });
423
1207
  });
424
1208
  //# sourceMappingURL=geminiChat.test.js.map