@vybestack/llxprt-code-core 0.1.12

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 (448) hide show
  1. package/dist/.last_build +0 -0
  2. package/dist/index.d.ts +7 -0
  3. package/dist/index.js +8 -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 +9 -0
  9. package/dist/src/code_assist/codeAssist.js +19 -0
  10. package/dist/src/code_assist/codeAssist.js.map +1 -0
  11. package/dist/src/code_assist/converter.d.ts +68 -0
  12. package/dist/src/code_assist/converter.js +125 -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 +229 -0
  16. package/dist/src/code_assist/converter.test.js.map +1 -0
  17. package/dist/src/code_assist/oauth2.d.ts +20 -0
  18. package/dist/src/code_assist/oauth2.js +339 -0
  19. package/dist/src/code_assist/oauth2.js.map +1 -0
  20. package/dist/src/code_assist/oauth2.test.d.ts +6 -0
  21. package/dist/src/code_assist/oauth2.test.js +249 -0
  22. package/dist/src/code_assist/oauth2.test.js.map +1 -0
  23. package/dist/src/code_assist/server.d.ts +39 -0
  24. package/dist/src/code_assist/server.js +191 -0
  25. package/dist/src/code_assist/server.js.map +1 -0
  26. package/dist/src/code_assist/server.test.d.ts +6 -0
  27. package/dist/src/code_assist/server.test.js +123 -0
  28. package/dist/src/code_assist/server.test.js.map +1 -0
  29. package/dist/src/code_assist/setup.d.ts +15 -0
  30. package/dist/src/code_assist/setup.js +67 -0
  31. package/dist/src/code_assist/setup.js.map +1 -0
  32. package/dist/src/code_assist/setup.test.d.ts +6 -0
  33. package/dist/src/code_assist/setup.test.js +62 -0
  34. package/dist/src/code_assist/setup.test.js.map +1 -0
  35. package/dist/src/code_assist/types.d.ts +148 -0
  36. package/dist/src/code_assist/types.js +46 -0
  37. package/dist/src/code_assist/types.js.map +1 -0
  38. package/dist/src/config/config.d.ts +212 -0
  39. package/dist/src/config/config.js +454 -0
  40. package/dist/src/config/config.js.map +1 -0
  41. package/dist/src/config/config.test.d.ts +6 -0
  42. package/dist/src/config/config.test.js +291 -0
  43. package/dist/src/config/config.test.js.map +1 -0
  44. package/dist/src/config/flashFallback.test.d.ts +6 -0
  45. package/dist/src/config/flashFallback.test.js +115 -0
  46. package/dist/src/config/flashFallback.test.js.map +1 -0
  47. package/dist/src/config/models.d.ts +8 -0
  48. package/dist/src/config/models.js +9 -0
  49. package/dist/src/config/models.js.map +1 -0
  50. package/dist/src/core/client.d.ts +59 -0
  51. package/dist/src/core/client.js +503 -0
  52. package/dist/src/core/client.js.map +1 -0
  53. package/dist/src/core/client.test.d.ts +6 -0
  54. package/dist/src/core/client.test.js +1006 -0
  55. package/dist/src/core/client.test.js.map +1 -0
  56. package/dist/src/core/contentGenerator.d.ts +36 -0
  57. package/dist/src/core/contentGenerator.js +79 -0
  58. package/dist/src/core/contentGenerator.js.map +1 -0
  59. package/dist/src/core/contentGenerator.test.d.ts +6 -0
  60. package/dist/src/core/contentGenerator.test.js +92 -0
  61. package/dist/src/core/contentGenerator.test.js.map +1 -0
  62. package/dist/src/core/coreToolScheduler.d.ts +104 -0
  63. package/dist/src/core/coreToolScheduler.js +413 -0
  64. package/dist/src/core/coreToolScheduler.js.map +1 -0
  65. package/dist/src/core/coreToolScheduler.test.d.ts +6 -0
  66. package/dist/src/core/coreToolScheduler.test.js +347 -0
  67. package/dist/src/core/coreToolScheduler.test.js.map +1 -0
  68. package/dist/src/core/geminiChat.d.ts +116 -0
  69. package/dist/src/core/geminiChat.js +513 -0
  70. package/dist/src/core/geminiChat.js.map +1 -0
  71. package/dist/src/core/geminiChat.test.d.ts +6 -0
  72. package/dist/src/core/geminiChat.test.js +424 -0
  73. package/dist/src/core/geminiChat.test.js.map +1 -0
  74. package/dist/src/core/geminiRequest.d.ts +13 -0
  75. package/dist/src/core/geminiRequest.js +45 -0
  76. package/dist/src/core/geminiRequest.js.map +1 -0
  77. package/dist/src/core/geminiRequest.test.d.ts +6 -0
  78. package/dist/src/core/geminiRequest.test.js +72 -0
  79. package/dist/src/core/geminiRequest.test.js.map +1 -0
  80. package/dist/src/core/logger.d.ts +38 -0
  81. package/dist/src/core/logger.js +237 -0
  82. package/dist/src/core/logger.js.map +1 -0
  83. package/dist/src/core/logger.test.d.ts +6 -0
  84. package/dist/src/core/logger.test.js +387 -0
  85. package/dist/src/core/logger.test.js.map +1 -0
  86. package/dist/src/core/modelCheck.d.ts +14 -0
  87. package/dist/src/core/modelCheck.js +55 -0
  88. package/dist/src/core/modelCheck.js.map +1 -0
  89. package/dist/src/core/nonInteractiveToolExecutor.d.ts +12 -0
  90. package/dist/src/core/nonInteractiveToolExecutor.js +93 -0
  91. package/dist/src/core/nonInteractiveToolExecutor.js.map +1 -0
  92. package/dist/src/core/nonInteractiveToolExecutor.test.d.ts +6 -0
  93. package/dist/src/core/nonInteractiveToolExecutor.test.js +180 -0
  94. package/dist/src/core/nonInteractiveToolExecutor.test.js.map +1 -0
  95. package/dist/src/core/prompts.d.ts +12 -0
  96. package/dist/src/core/prompts.js +418 -0
  97. package/dist/src/core/prompts.js.map +1 -0
  98. package/dist/src/core/prompts.test.d.ts +6 -0
  99. package/dist/src/core/prompts.test.js +97 -0
  100. package/dist/src/core/prompts.test.js.map +1 -0
  101. package/dist/src/core/tokenLimits.d.ts +10 -0
  102. package/dist/src/core/tokenLimits.js +75 -0
  103. package/dist/src/core/tokenLimits.js.map +1 -0
  104. package/dist/src/core/tokenLimits.test.d.ts +6 -0
  105. package/dist/src/core/tokenLimits.test.js +66 -0
  106. package/dist/src/core/tokenLimits.test.js.map +1 -0
  107. package/dist/src/core/turn.d.ts +116 -0
  108. package/dist/src/core/turn.js +131 -0
  109. package/dist/src/core/turn.js.map +1 -0
  110. package/dist/src/core/turn.test.d.ts +6 -0
  111. package/dist/src/core/turn.test.js +237 -0
  112. package/dist/src/core/turn.test.js.map +1 -0
  113. package/dist/src/index.d.ts +57 -0
  114. package/dist/src/index.js +64 -0
  115. package/dist/src/index.js.map +1 -0
  116. package/dist/src/index.test.d.ts +6 -0
  117. package/dist/src/index.test.js +12 -0
  118. package/dist/src/index.test.js.map +1 -0
  119. package/dist/src/providers/ProviderContentGenerator.d.ts +21 -0
  120. package/dist/src/providers/ProviderContentGenerator.js +52 -0
  121. package/dist/src/providers/ProviderContentGenerator.js.map +1 -0
  122. package/dist/src/providers/adapters/GeminiCompatibleWrapper.d.ts +68 -0
  123. package/dist/src/providers/adapters/GeminiCompatibleWrapper.js +549 -0
  124. package/dist/src/providers/adapters/GeminiCompatibleWrapper.js.map +1 -0
  125. package/dist/src/providers/adapters/GeminiCompatibleWrapper.test.d.ts +6 -0
  126. package/dist/src/providers/adapters/GeminiCompatibleWrapper.test.js +253 -0
  127. package/dist/src/providers/adapters/GeminiCompatibleWrapper.test.js.map +1 -0
  128. package/dist/src/providers/types.d.ts +82 -0
  129. package/dist/src/providers/types.js +7 -0
  130. package/dist/src/providers/types.js.map +1 -0
  131. package/dist/src/services/fileDiscoveryService.d.ts +35 -0
  132. package/dist/src/services/fileDiscoveryService.js +91 -0
  133. package/dist/src/services/fileDiscoveryService.js.map +1 -0
  134. package/dist/src/services/fileDiscoveryService.test.d.ts +6 -0
  135. package/dist/src/services/fileDiscoveryService.test.js +102 -0
  136. package/dist/src/services/fileDiscoveryService.test.js.map +1 -0
  137. package/dist/src/services/gitService.d.ts +21 -0
  138. package/dist/src/services/gitService.js +102 -0
  139. package/dist/src/services/gitService.js.map +1 -0
  140. package/dist/src/services/gitService.test.d.ts +6 -0
  141. package/dist/src/services/gitService.test.js +246 -0
  142. package/dist/src/services/gitService.test.js.map +1 -0
  143. package/dist/src/services/ideContext.d.ts +124 -0
  144. package/dist/src/services/ideContext.js +90 -0
  145. package/dist/src/services/ideContext.js.map +1 -0
  146. package/dist/src/services/ideContext.test.d.ts +6 -0
  147. package/dist/src/services/ideContext.test.js +101 -0
  148. package/dist/src/services/ideContext.test.js.map +1 -0
  149. package/dist/src/services/loopDetectionService.d.ts +35 -0
  150. package/dist/src/services/loopDetectionService.js +117 -0
  151. package/dist/src/services/loopDetectionService.js.map +1 -0
  152. package/dist/src/services/loopDetectionService.test.d.ts +6 -0
  153. package/dist/src/services/loopDetectionService.test.js +232 -0
  154. package/dist/src/services/loopDetectionService.test.js.map +1 -0
  155. package/dist/src/telemetry/clearcut-logger/clearcut-logger.d.ts +35 -0
  156. package/dist/src/telemetry/clearcut-logger/clearcut-logger.js +424 -0
  157. package/dist/src/telemetry/clearcut-logger/clearcut-logger.js.map +1 -0
  158. package/dist/src/telemetry/clearcut-logger/event-metadata-key.d.ts +47 -0
  159. package/dist/src/telemetry/clearcut-logger/event-metadata-key.js +123 -0
  160. package/dist/src/telemetry/clearcut-logger/event-metadata-key.js.map +1 -0
  161. package/dist/src/telemetry/constants.d.ts +20 -0
  162. package/dist/src/telemetry/constants.js +21 -0
  163. package/dist/src/telemetry/constants.js.map +1 -0
  164. package/dist/src/telemetry/index.d.ts +18 -0
  165. package/dist/src/telemetry/index.js +20 -0
  166. package/dist/src/telemetry/index.js.map +1 -0
  167. package/dist/src/telemetry/integration.test.circular.d.ts +6 -0
  168. package/dist/src/telemetry/integration.test.circular.js +53 -0
  169. package/dist/src/telemetry/integration.test.circular.js.map +1 -0
  170. package/dist/src/telemetry/loggers.d.ts +15 -0
  171. package/dist/src/telemetry/loggers.js +229 -0
  172. package/dist/src/telemetry/loggers.js.map +1 -0
  173. package/dist/src/telemetry/loggers.test.circular.d.ts +6 -0
  174. package/dist/src/telemetry/loggers.test.circular.js +100 -0
  175. package/dist/src/telemetry/loggers.test.circular.js.map +1 -0
  176. package/dist/src/telemetry/loggers.test.d.ts +6 -0
  177. package/dist/src/telemetry/loggers.test.js +558 -0
  178. package/dist/src/telemetry/loggers.test.js.map +1 -0
  179. package/dist/src/telemetry/metrics.d.ts +19 -0
  180. package/dist/src/telemetry/metrics.js +144 -0
  181. package/dist/src/telemetry/metrics.js.map +1 -0
  182. package/dist/src/telemetry/metrics.test.d.ts +6 -0
  183. package/dist/src/telemetry/metrics.test.js +162 -0
  184. package/dist/src/telemetry/metrics.test.js.map +1 -0
  185. package/dist/src/telemetry/sdk.d.ts +9 -0
  186. package/dist/src/telemetry/sdk.js +120 -0
  187. package/dist/src/telemetry/sdk.js.map +1 -0
  188. package/dist/src/telemetry/telemetry.test.d.ts +6 -0
  189. package/dist/src/telemetry/telemetry.test.js +52 -0
  190. package/dist/src/telemetry/telemetry.test.js.map +1 -0
  191. package/dist/src/telemetry/types.d.ts +115 -0
  192. package/dist/src/telemetry/types.js +217 -0
  193. package/dist/src/telemetry/types.js.map +1 -0
  194. package/dist/src/telemetry/uiTelemetry.d.ts +67 -0
  195. package/dist/src/telemetry/uiTelemetry.js +131 -0
  196. package/dist/src/telemetry/uiTelemetry.js.map +1 -0
  197. package/dist/src/telemetry/uiTelemetry.test.d.ts +6 -0
  198. package/dist/src/telemetry/uiTelemetry.test.js +412 -0
  199. package/dist/src/telemetry/uiTelemetry.test.js.map +1 -0
  200. package/dist/src/tools/diffOptions.d.ts +7 -0
  201. package/dist/src/tools/diffOptions.js +10 -0
  202. package/dist/src/tools/diffOptions.js.map +1 -0
  203. package/dist/src/tools/edit.d.ts +73 -0
  204. package/dist/src/tools/edit.js +343 -0
  205. package/dist/src/tools/edit.js.map +1 -0
  206. package/dist/src/tools/edit.test.d.ts +6 -0
  207. package/dist/src/tools/edit.test.js +500 -0
  208. package/dist/src/tools/edit.test.js.map +1 -0
  209. package/dist/src/tools/glob.d.ts +58 -0
  210. package/dist/src/tools/glob.js +193 -0
  211. package/dist/src/tools/glob.js.map +1 -0
  212. package/dist/src/tools/glob.test.d.ts +6 -0
  213. package/dist/src/tools/glob.test.js +294 -0
  214. package/dist/src/tools/glob.test.js.map +1 -0
  215. package/dist/src/tools/grep.d.ts +78 -0
  216. package/dist/src/tools/grep.js +422 -0
  217. package/dist/src/tools/grep.js.map +1 -0
  218. package/dist/src/tools/grep.test.d.ts +6 -0
  219. package/dist/src/tools/grep.test.js +188 -0
  220. package/dist/src/tools/grep.test.js.map +1 -0
  221. package/dist/src/tools/ls.d.ts +83 -0
  222. package/dist/src/tools/ls.js +194 -0
  223. package/dist/src/tools/ls.js.map +1 -0
  224. package/dist/src/tools/mcp-client.d.ts +112 -0
  225. package/dist/src/tools/mcp-client.js +332 -0
  226. package/dist/src/tools/mcp-client.js.map +1 -0
  227. package/dist/src/tools/mcp-client.test.d.ts +6 -0
  228. package/dist/src/tools/mcp-client.test.js +227 -0
  229. package/dist/src/tools/mcp-client.test.js.map +1 -0
  230. package/dist/src/tools/mcp-tool.d.ts +23 -0
  231. package/dist/src/tools/mcp-tool.js +119 -0
  232. package/dist/src/tools/mcp-tool.js.map +1 -0
  233. package/dist/src/tools/mcp-tool.test.d.ts +6 -0
  234. package/dist/src/tools/mcp-tool.test.js +173 -0
  235. package/dist/src/tools/mcp-tool.test.js.map +1 -0
  236. package/dist/src/tools/memoryTool.d.ts +28 -0
  237. package/dist/src/tools/memoryTool.js +172 -0
  238. package/dist/src/tools/memoryTool.js.map +1 -0
  239. package/dist/src/tools/memoryTool.test.d.ts +6 -0
  240. package/dist/src/tools/memoryTool.test.js +181 -0
  241. package/dist/src/tools/memoryTool.test.js.map +1 -0
  242. package/dist/src/tools/modifiable-tool.d.ts +29 -0
  243. package/dist/src/tools/modifiable-tool.js +85 -0
  244. package/dist/src/tools/modifiable-tool.js.map +1 -0
  245. package/dist/src/tools/modifiable-tool.test.d.ts +6 -0
  246. package/dist/src/tools/modifiable-tool.test.js +204 -0
  247. package/dist/src/tools/modifiable-tool.test.js.map +1 -0
  248. package/dist/src/tools/read-file.d.ts +35 -0
  249. package/dist/src/tools/read-file.js +106 -0
  250. package/dist/src/tools/read-file.js.map +1 -0
  251. package/dist/src/tools/read-file.test.d.ts +6 -0
  252. package/dist/src/tools/read-file.test.js +181 -0
  253. package/dist/src/tools/read-file.test.js.map +1 -0
  254. package/dist/src/tools/read-many-files.d.ts +59 -0
  255. package/dist/src/tools/read-many-files.js +321 -0
  256. package/dist/src/tools/read-many-files.js.map +1 -0
  257. package/dist/src/tools/read-many-files.test.d.ts +6 -0
  258. package/dist/src/tools/read-many-files.test.js +312 -0
  259. package/dist/src/tools/read-many-files.test.js.map +1 -0
  260. package/dist/src/tools/shell.d.ts +43 -0
  261. package/dist/src/tools/shell.js +435 -0
  262. package/dist/src/tools/shell.js.map +1 -0
  263. package/dist/src/tools/shell.test.d.ts +6 -0
  264. package/dist/src/tools/shell.test.js +407 -0
  265. package/dist/src/tools/shell.test.js.map +1 -0
  266. package/dist/src/tools/todo-read.d.ts +15 -0
  267. package/dist/src/tools/todo-read.js +66 -0
  268. package/dist/src/tools/todo-read.js.map +1 -0
  269. package/dist/src/tools/todo-read.test.d.ts +6 -0
  270. package/dist/src/tools/todo-read.test.js +158 -0
  271. package/dist/src/tools/todo-read.test.js.map +1 -0
  272. package/dist/src/tools/todo-schemas.d.ts +43 -0
  273. package/dist/src/tools/todo-schemas.js +16 -0
  274. package/dist/src/tools/todo-schemas.js.map +1 -0
  275. package/dist/src/tools/todo-schemas.test.d.ts +6 -0
  276. package/dist/src/tools/todo-schemas.test.js +152 -0
  277. package/dist/src/tools/todo-schemas.test.js.map +1 -0
  278. package/dist/src/tools/todo-store.d.ts +15 -0
  279. package/dist/src/tools/todo-store.js +59 -0
  280. package/dist/src/tools/todo-store.js.map +1 -0
  281. package/dist/src/tools/todo-store.test.d.ts +6 -0
  282. package/dist/src/tools/todo-store.test.js +175 -0
  283. package/dist/src/tools/todo-store.test.js.map +1 -0
  284. package/dist/src/tools/todo-write.d.ts +17 -0
  285. package/dist/src/tools/todo-write.js +98 -0
  286. package/dist/src/tools/todo-write.js.map +1 -0
  287. package/dist/src/tools/todo-write.test.d.ts +6 -0
  288. package/dist/src/tools/todo-write.test.js +208 -0
  289. package/dist/src/tools/todo-write.test.js.map +1 -0
  290. package/dist/src/tools/tool-registry.d.ts +67 -0
  291. package/dist/src/tools/tool-registry.js +326 -0
  292. package/dist/src/tools/tool-registry.js.map +1 -0
  293. package/dist/src/tools/tool-registry.test.d.ts +6 -0
  294. package/dist/src/tools/tool-registry.test.js +398 -0
  295. package/dist/src/tools/tool-registry.test.js.map +1 -0
  296. package/dist/src/tools/tools.d.ts +184 -0
  297. package/dist/src/tools/tools.js +88 -0
  298. package/dist/src/tools/tools.js.map +1 -0
  299. package/dist/src/tools/web-fetch.d.ts +29 -0
  300. package/dist/src/tools/web-fetch.js +243 -0
  301. package/dist/src/tools/web-fetch.js.map +1 -0
  302. package/dist/src/tools/web-fetch.test.d.ts +6 -0
  303. package/dist/src/tools/web-fetch.test.js +70 -0
  304. package/dist/src/tools/web-fetch.test.js.map +1 -0
  305. package/dist/src/tools/web-search.d.ts +49 -0
  306. package/dist/src/tools/web-search.js +120 -0
  307. package/dist/src/tools/web-search.js.map +1 -0
  308. package/dist/src/tools/write-file.d.ts +42 -0
  309. package/dist/src/tools/write-file.js +248 -0
  310. package/dist/src/tools/write-file.js.map +1 -0
  311. package/dist/src/tools/write-file.test.d.ts +6 -0
  312. package/dist/src/tools/write-file.test.js +413 -0
  313. package/dist/src/tools/write-file.test.js.map +1 -0
  314. package/dist/src/utils/LruCache.d.ts +13 -0
  315. package/dist/src/utils/LruCache.js +38 -0
  316. package/dist/src/utils/LruCache.js.map +1 -0
  317. package/dist/src/utils/bfsFileSearch.d.ts +22 -0
  318. package/dist/src/utils/bfsFileSearch.js +62 -0
  319. package/dist/src/utils/bfsFileSearch.js.map +1 -0
  320. package/dist/src/utils/bfsFileSearch.test.d.ts +6 -0
  321. package/dist/src/utils/bfsFileSearch.test.js +129 -0
  322. package/dist/src/utils/bfsFileSearch.test.js.map +1 -0
  323. package/dist/src/utils/editCorrector.d.ts +53 -0
  324. package/dist/src/utils/editCorrector.js +546 -0
  325. package/dist/src/utils/editCorrector.js.map +1 -0
  326. package/dist/src/utils/editCorrector.test.d.ts +6 -0
  327. package/dist/src/utils/editCorrector.test.js +564 -0
  328. package/dist/src/utils/editCorrector.test.js.map +1 -0
  329. package/dist/src/utils/editor.d.ts +28 -0
  330. package/dist/src/utils/editor.js +163 -0
  331. package/dist/src/utils/editor.js.map +1 -0
  332. package/dist/src/utils/editor.test.d.ts +6 -0
  333. package/dist/src/utils/editor.test.js +293 -0
  334. package/dist/src/utils/editor.test.js.map +1 -0
  335. package/dist/src/utils/errorReporting.d.ts +14 -0
  336. package/dist/src/utils/errorReporting.js +88 -0
  337. package/dist/src/utils/errorReporting.js.map +1 -0
  338. package/dist/src/utils/errorReporting.test.d.ts +6 -0
  339. package/dist/src/utils/errorReporting.test.js +124 -0
  340. package/dist/src/utils/errorReporting.test.js.map +1 -0
  341. package/dist/src/utils/errors.d.ts +14 -0
  342. package/dist/src/utils/errors.js +54 -0
  343. package/dist/src/utils/errors.js.map +1 -0
  344. package/dist/src/utils/fetch.d.ts +11 -0
  345. package/dist/src/utils/fetch.js +51 -0
  346. package/dist/src/utils/fetch.js.map +1 -0
  347. package/dist/src/utils/fileUtils.d.ts +49 -0
  348. package/dist/src/utils/fileUtils.js +286 -0
  349. package/dist/src/utils/fileUtils.js.map +1 -0
  350. package/dist/src/utils/fileUtils.test.d.ts +6 -0
  351. package/dist/src/utils/fileUtils.test.js +321 -0
  352. package/dist/src/utils/fileUtils.test.js.map +1 -0
  353. package/dist/src/utils/flashFallback.integration.test.d.ts +6 -0
  354. package/dist/src/utils/flashFallback.integration.test.js +112 -0
  355. package/dist/src/utils/flashFallback.integration.test.js.map +1 -0
  356. package/dist/src/utils/generateContentResponseUtilities.d.ts +14 -0
  357. package/dist/src/utils/generateContentResponseUtilities.js +92 -0
  358. package/dist/src/utils/generateContentResponseUtilities.js.map +1 -0
  359. package/dist/src/utils/generateContentResponseUtilities.test.d.ts +6 -0
  360. package/dist/src/utils/generateContentResponseUtilities.test.js +273 -0
  361. package/dist/src/utils/generateContentResponseUtilities.test.js.map +1 -0
  362. package/dist/src/utils/getFolderStructure.d.ts +30 -0
  363. package/dist/src/utils/getFolderStructure.js +247 -0
  364. package/dist/src/utils/getFolderStructure.js.map +1 -0
  365. package/dist/src/utils/getFolderStructure.test.d.ts +6 -0
  366. package/dist/src/utils/getFolderStructure.test.js +298 -0
  367. package/dist/src/utils/getFolderStructure.test.js.map +1 -0
  368. package/dist/src/utils/gitIgnoreParser.d.ts +20 -0
  369. package/dist/src/utils/gitIgnoreParser.js +64 -0
  370. package/dist/src/utils/gitIgnoreParser.js.map +1 -0
  371. package/dist/src/utils/gitIgnoreParser.test.d.ts +6 -0
  372. package/dist/src/utils/gitIgnoreParser.test.js +145 -0
  373. package/dist/src/utils/gitIgnoreParser.test.js.map +1 -0
  374. package/dist/src/utils/gitUtils.d.ts +17 -0
  375. package/dist/src/utils/gitUtils.js +61 -0
  376. package/dist/src/utils/gitUtils.js.map +1 -0
  377. package/dist/src/utils/memoryDiscovery.d.ts +14 -0
  378. package/dist/src/utils/memoryDiscovery.js +219 -0
  379. package/dist/src/utils/memoryDiscovery.js.map +1 -0
  380. package/dist/src/utils/memoryDiscovery.test.d.ts +6 -0
  381. package/dist/src/utils/memoryDiscovery.test.js +432 -0
  382. package/dist/src/utils/memoryDiscovery.test.js.map +1 -0
  383. package/dist/src/utils/memoryImportProcessor.d.ts +35 -0
  384. package/dist/src/utils/memoryImportProcessor.js +141 -0
  385. package/dist/src/utils/memoryImportProcessor.js.map +1 -0
  386. package/dist/src/utils/memoryImportProcessor.test.d.ts +6 -0
  387. package/dist/src/utils/memoryImportProcessor.test.js +170 -0
  388. package/dist/src/utils/memoryImportProcessor.test.js.map +1 -0
  389. package/dist/src/utils/messageInspectors.d.ts +8 -0
  390. package/dist/src/utils/messageInspectors.js +16 -0
  391. package/dist/src/utils/messageInspectors.js.map +1 -0
  392. package/dist/src/utils/nextSpeakerChecker.d.ts +12 -0
  393. package/dist/src/utils/nextSpeakerChecker.js +113 -0
  394. package/dist/src/utils/nextSpeakerChecker.js.map +1 -0
  395. package/dist/src/utils/nextSpeakerChecker.test.d.ts +6 -0
  396. package/dist/src/utils/nextSpeakerChecker.test.js +168 -0
  397. package/dist/src/utils/nextSpeakerChecker.test.js.map +1 -0
  398. package/dist/src/utils/paths.d.ts +49 -0
  399. package/dist/src/utils/paths.js +145 -0
  400. package/dist/src/utils/paths.js.map +1 -0
  401. package/dist/src/utils/quotaErrorDetection.d.ts +22 -0
  402. package/dist/src/utils/quotaErrorDetection.js +67 -0
  403. package/dist/src/utils/quotaErrorDetection.js.map +1 -0
  404. package/dist/src/utils/retry.d.ts +21 -0
  405. package/dist/src/utils/retry.js +276 -0
  406. package/dist/src/utils/retry.js.map +1 -0
  407. package/dist/src/utils/retry.test.d.ts +6 -0
  408. package/dist/src/utils/retry.test.js +322 -0
  409. package/dist/src/utils/retry.test.js.map +1 -0
  410. package/dist/src/utils/safeJsonStringify.d.ts +13 -0
  411. package/dist/src/utils/safeJsonStringify.js +25 -0
  412. package/dist/src/utils/safeJsonStringify.js.map +1 -0
  413. package/dist/src/utils/safeJsonStringify.test.d.ts +6 -0
  414. package/dist/src/utils/safeJsonStringify.test.js +61 -0
  415. package/dist/src/utils/safeJsonStringify.test.js.map +1 -0
  416. package/dist/src/utils/schemaValidator.d.ts +23 -0
  417. package/dist/src/utils/schemaValidator.js +142 -0
  418. package/dist/src/utils/schemaValidator.js.map +1 -0
  419. package/dist/src/utils/schemaValidator.test.d.ts +6 -0
  420. package/dist/src/utils/schemaValidator.test.js +146 -0
  421. package/dist/src/utils/schemaValidator.test.js.map +1 -0
  422. package/dist/src/utils/session.d.ts +6 -0
  423. package/dist/src/utils/session.js +8 -0
  424. package/dist/src/utils/session.js.map +1 -0
  425. package/dist/src/utils/summarizer.d.ts +25 -0
  426. package/dist/src/utils/summarizer.js +80 -0
  427. package/dist/src/utils/summarizer.js.map +1 -0
  428. package/dist/src/utils/summarizer.test.d.ts +6 -0
  429. package/dist/src/utils/summarizer.test.js +131 -0
  430. package/dist/src/utils/summarizer.test.js.map +1 -0
  431. package/dist/src/utils/testUtils.d.ts +29 -0
  432. package/dist/src/utils/testUtils.js +70 -0
  433. package/dist/src/utils/testUtils.js.map +1 -0
  434. package/dist/src/utils/user_account.d.ts +9 -0
  435. package/dist/src/utils/user_account.js +99 -0
  436. package/dist/src/utils/user_account.js.map +1 -0
  437. package/dist/src/utils/user_account.test.d.ts +6 -0
  438. package/dist/src/utils/user_account.test.js +153 -0
  439. package/dist/src/utils/user_account.test.js.map +1 -0
  440. package/dist/src/utils/user_id.d.ts +11 -0
  441. package/dist/src/utils/user_id.js +49 -0
  442. package/dist/src/utils/user_id.js.map +1 -0
  443. package/dist/src/utils/user_id.test.d.ts +6 -0
  444. package/dist/src/utils/user_id.test.js +21 -0
  445. package/dist/src/utils/user_id.test.js.map +1 -0
  446. package/dist/tsconfig.tsbuildinfo +1 -0
  447. package/dist/vybestack-llxprt-code-core-0.1.12.tgz +0 -0
  448. package/package.json +62 -0
@@ -0,0 +1,119 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2025 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import { BaseTool, ToolConfirmationOutcome, } from './tools.js';
7
+ export class DiscoveredMCPTool extends BaseTool {
8
+ mcpTool;
9
+ serverName;
10
+ name;
11
+ description;
12
+ parameterSchema;
13
+ serverToolName;
14
+ timeout;
15
+ trust;
16
+ static allowlist = new Set();
17
+ constructor(mcpTool, serverName, name, description, parameterSchema, serverToolName, timeout, trust) {
18
+ super(name, `${serverToolName} (${serverName} MCP Server)`, description, parameterSchema, true, // isOutputMarkdown
19
+ false);
20
+ this.mcpTool = mcpTool;
21
+ this.serverName = serverName;
22
+ this.name = name;
23
+ this.description = description;
24
+ this.parameterSchema = parameterSchema;
25
+ this.serverToolName = serverToolName;
26
+ this.timeout = timeout;
27
+ this.trust = trust;
28
+ }
29
+ async shouldConfirmExecute(_params, _abortSignal) {
30
+ const serverAllowListKey = this.serverName;
31
+ const toolAllowListKey = `${this.serverName}.${this.serverToolName}`;
32
+ if (this.trust) {
33
+ return false; // server is trusted, no confirmation needed
34
+ }
35
+ if (DiscoveredMCPTool.allowlist.has(serverAllowListKey) ||
36
+ DiscoveredMCPTool.allowlist.has(toolAllowListKey)) {
37
+ return false; // server and/or tool already allow listed
38
+ }
39
+ const confirmationDetails = {
40
+ type: 'mcp',
41
+ title: 'Confirm MCP Tool Execution',
42
+ serverName: this.serverName,
43
+ toolName: this.serverToolName, // Display original tool name in confirmation
44
+ toolDisplayName: this.name, // Display global registry name exposed to model and user
45
+ onConfirm: async (outcome) => {
46
+ if (outcome === ToolConfirmationOutcome.ProceedAlwaysServer) {
47
+ DiscoveredMCPTool.allowlist.add(serverAllowListKey);
48
+ }
49
+ else if (outcome === ToolConfirmationOutcome.ProceedAlwaysTool) {
50
+ DiscoveredMCPTool.allowlist.add(toolAllowListKey);
51
+ }
52
+ },
53
+ };
54
+ return confirmationDetails;
55
+ }
56
+ async execute(params) {
57
+ const functionCalls = [
58
+ {
59
+ name: this.serverToolName,
60
+ args: params,
61
+ },
62
+ ];
63
+ const responseParts = await this.mcpTool.callTool(functionCalls);
64
+ return {
65
+ llmContent: responseParts,
66
+ returnDisplay: getStringifiedResultForDisplay(responseParts),
67
+ };
68
+ }
69
+ }
70
+ /**
71
+ * Processes an array of `Part` objects, primarily from a tool's execution result,
72
+ * to generate a user-friendly string representation, typically for display in a CLI.
73
+ *
74
+ * The `result` array can contain various types of `Part` objects:
75
+ * 1. `FunctionResponse` parts:
76
+ * - If the `response.content` of a `FunctionResponse` is an array consisting solely
77
+ * of `TextPart` objects, their text content is concatenated into a single string.
78
+ * This is to present simple textual outputs directly.
79
+ * - If `response.content` is an array but contains other types of `Part` objects (or a mix),
80
+ * the `content` array itself is preserved. This handles structured data like JSON objects or arrays
81
+ * returned by a tool.
82
+ * - If `response.content` is not an array or is missing, the entire `functionResponse`
83
+ * object is preserved.
84
+ * 2. Other `Part` types (e.g., `TextPart` directly in the `result` array):
85
+ * - These are preserved as is.
86
+ *
87
+ * All processed parts are then collected into an array, which is JSON.stringify-ed
88
+ * with indentation and wrapped in a markdown JSON code block.
89
+ */
90
+ function getStringifiedResultForDisplay(result) {
91
+ if (!result || result.length === 0) {
92
+ return '```json\n[]\n```';
93
+ }
94
+ const processFunctionResponse = (part) => {
95
+ if (part.functionResponse) {
96
+ const responseContent = part.functionResponse.response?.content;
97
+ if (responseContent && Array.isArray(responseContent)) {
98
+ // Check if all parts in responseContent are simple TextParts
99
+ const allTextParts = responseContent.every((p) => p.text !== undefined);
100
+ if (allTextParts) {
101
+ return responseContent.map((p) => p.text).join('');
102
+ }
103
+ // If not all simple text parts, return the array of these content parts for JSON stringification
104
+ return responseContent;
105
+ }
106
+ // If no content, or not an array, or not a functionResponse, stringify the whole functionResponse part for inspection
107
+ return part.functionResponse;
108
+ }
109
+ return part; // Fallback for unexpected structure or non-FunctionResponsePart
110
+ };
111
+ const processedResults = result.length === 1
112
+ ? processFunctionResponse(result[0])
113
+ : result.map(processFunctionResponse);
114
+ if (typeof processedResults === 'string') {
115
+ return processedResults;
116
+ }
117
+ return '```json\n' + JSON.stringify(processedResults, null, 2) + '\n```';
118
+ }
119
+ //# sourceMappingURL=mcp-tool.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mcp-tool.js","sourceRoot":"","sources":["../../../src/tools/mcp-tool.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EACL,QAAQ,EAGR,uBAAuB,GAExB,MAAM,YAAY,CAAC;AAKpB,MAAM,OAAO,iBAAkB,SAAQ,QAAgC;IAIlD;IACR;IACA;IACA;IACA;IACA;IACA;IACA;IAVH,MAAM,CAAU,SAAS,GAAgB,IAAI,GAAG,EAAE,CAAC;IAE3D,YACmB,OAAqB,EAC7B,UAAkB,EAClB,IAAY,EACZ,WAAmB,EACnB,eAAuB,EACvB,cAAsB,EACt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C,CAAO,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;gBAC3D,CAAC;gBACD,iGAAiG;gBACjG,OAAO,eAAe,CAAC;YACzB,CAAC;YAED,sHAAsH;YACtH,OAAO,IAAI,CAAC,gBAAgB,CAAC;QAC/B,CAAC;QACD,OAAO,IAAI,CAAC,CAAC,gEAAgE;IAC/E,CAAC,CAAC;IAEF,MAAM,gBAAgB,GACpB,MAAM,CAAC,MAAM,KAAK,CAAC;QACjB,CAAC,CAAC,uBAAuB,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;QACpC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,uBAAuB,CAAC,CAAC;IAC1C,IAAI,OAAO,gBAAgB,KAAK,QAAQ,EAAE,CAAC;QACzC,OAAO,gBAAgB,CAAC;IAC1B,CAAC;IAED,OAAO,WAAW,GAAG,IAAI,CAAC,SAAS,CAAC,gBAAgB,EAAE,IAAI,EAAE,CAAC,CAAC,GAAG,OAAO,CAAC;AAC3E,CAAC"}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2025 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ export {};
@@ -0,0 +1,173 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2025 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ /* eslint-disable @typescript-eslint/no-explicit-any */
7
+ import { describe, it, expect, vi, beforeEach, afterEach, } from 'vitest';
8
+ import { DiscoveredMCPTool } from './mcp-tool.js'; // Added getStringifiedResultForDisplay
9
+ import { ToolConfirmationOutcome } from './tools.js'; // Added ToolConfirmationOutcome
10
+ // Mock @google/genai mcpToTool and CallableTool
11
+ // We only need to mock the parts of CallableTool that DiscoveredMCPTool uses.
12
+ const mockCallTool = vi.fn();
13
+ const mockToolMethod = vi.fn();
14
+ const mockCallableToolInstance = {
15
+ tool: mockToolMethod, // Not directly used by DiscoveredMCPTool instance methods
16
+ callTool: mockCallTool,
17
+ // Add other methods if DiscoveredMCPTool starts using them
18
+ };
19
+ describe('DiscoveredMCPTool', () => {
20
+ const serverName = 'mock-mcp-server';
21
+ const toolNameForModel = 'test-mcp-tool-for-model';
22
+ const serverToolName = 'actual-server-tool-name';
23
+ const baseDescription = 'A test MCP tool.';
24
+ const inputSchema = {
25
+ type: 'object',
26
+ properties: { param: { type: 'string' } },
27
+ required: ['param'],
28
+ };
29
+ beforeEach(() => {
30
+ mockCallTool.mockClear();
31
+ mockToolMethod.mockClear();
32
+ // Clear allowlist before each relevant test, especially for shouldConfirmExecute
33
+ DiscoveredMCPTool.allowlist.clear();
34
+ });
35
+ afterEach(() => {
36
+ vi.restoreAllMocks();
37
+ });
38
+ describe('constructor', () => {
39
+ it('should set properties correctly (non-generic server)', () => {
40
+ const tool = new DiscoveredMCPTool(mockCallableToolInstance, serverName, // serverName is 'mock-mcp-server', not 'mcp'
41
+ toolNameForModel, baseDescription, inputSchema, serverToolName);
42
+ expect(tool.name).toBe(toolNameForModel);
43
+ expect(tool.schema.name).toBe(toolNameForModel);
44
+ expect(tool.schema.description).toBe(baseDescription);
45
+ expect(tool.schema.parameters).toEqual(inputSchema);
46
+ expect(tool.serverToolName).toBe(serverToolName);
47
+ expect(tool.timeout).toBeUndefined();
48
+ });
49
+ it('should set properties correctly (generic "mcp" server)', () => {
50
+ const genericServerName = 'mcp';
51
+ const tool = new DiscoveredMCPTool(mockCallableToolInstance, genericServerName, // serverName is 'mcp'
52
+ toolNameForModel, baseDescription, inputSchema, serverToolName);
53
+ expect(tool.schema.description).toBe(baseDescription);
54
+ });
55
+ it('should accept and store a custom timeout', () => {
56
+ const customTimeout = 5000;
57
+ const tool = new DiscoveredMCPTool(mockCallableToolInstance, serverName, toolNameForModel, baseDescription, inputSchema, serverToolName, customTimeout);
58
+ expect(tool.timeout).toBe(customTimeout);
59
+ });
60
+ });
61
+ describe('execute', () => {
62
+ it('should call mcpTool.callTool with correct parameters and format display output', async () => {
63
+ const tool = new DiscoveredMCPTool(mockCallableToolInstance, serverName, toolNameForModel, baseDescription, inputSchema, serverToolName);
64
+ const params = { param: 'testValue' };
65
+ const mockToolSuccessResultObject = {
66
+ success: true,
67
+ details: 'executed',
68
+ };
69
+ const mockFunctionResponseContent = [
70
+ { text: JSON.stringify(mockToolSuccessResultObject) },
71
+ ];
72
+ const mockMcpToolResponseParts = [
73
+ {
74
+ functionResponse: {
75
+ name: serverToolName,
76
+ response: { content: mockFunctionResponseContent },
77
+ },
78
+ },
79
+ ];
80
+ mockCallTool.mockResolvedValue(mockMcpToolResponseParts);
81
+ const toolResult = await tool.execute(params);
82
+ expect(mockCallTool).toHaveBeenCalledWith([
83
+ { name: serverToolName, args: params },
84
+ ]);
85
+ expect(toolResult.llmContent).toEqual(mockMcpToolResponseParts);
86
+ const stringifiedResponseContent = JSON.stringify(mockToolSuccessResultObject);
87
+ expect(toolResult.returnDisplay).toBe(stringifiedResponseContent);
88
+ });
89
+ it('should handle empty result from getStringifiedResultForDisplay', async () => {
90
+ const tool = new DiscoveredMCPTool(mockCallableToolInstance, serverName, toolNameForModel, baseDescription, inputSchema, serverToolName);
91
+ const params = { param: 'testValue' };
92
+ const mockMcpToolResponsePartsEmpty = [];
93
+ mockCallTool.mockResolvedValue(mockMcpToolResponsePartsEmpty);
94
+ const toolResult = await tool.execute(params);
95
+ expect(toolResult.returnDisplay).toBe('```json\n[]\n```');
96
+ });
97
+ it('should propagate rejection if mcpTool.callTool rejects', async () => {
98
+ const tool = new DiscoveredMCPTool(mockCallableToolInstance, serverName, toolNameForModel, baseDescription, inputSchema, serverToolName);
99
+ const params = { param: 'failCase' };
100
+ const expectedError = new Error('MCP call failed');
101
+ mockCallTool.mockRejectedValue(expectedError);
102
+ await expect(tool.execute(params)).rejects.toThrow(expectedError);
103
+ });
104
+ });
105
+ describe('shouldConfirmExecute', () => {
106
+ // beforeEach is already clearing allowlist
107
+ it('should return false if trust is true', async () => {
108
+ const tool = new DiscoveredMCPTool(mockCallableToolInstance, serverName, toolNameForModel, baseDescription, inputSchema, serverToolName, undefined, true);
109
+ expect(await tool.shouldConfirmExecute({}, new AbortController().signal)).toBe(false);
110
+ });
111
+ it('should return false if server is allowlisted', async () => {
112
+ DiscoveredMCPTool.allowlist.add(serverName);
113
+ const tool = new DiscoveredMCPTool(mockCallableToolInstance, serverName, toolNameForModel, baseDescription, inputSchema, serverToolName);
114
+ expect(await tool.shouldConfirmExecute({}, new AbortController().signal)).toBe(false);
115
+ });
116
+ it('should return false if tool is allowlisted', async () => {
117
+ const toolAllowlistKey = `${serverName}.${serverToolName}`;
118
+ DiscoveredMCPTool.allowlist.add(toolAllowlistKey);
119
+ const tool = new DiscoveredMCPTool(mockCallableToolInstance, serverName, toolNameForModel, baseDescription, inputSchema, serverToolName);
120
+ expect(await tool.shouldConfirmExecute({}, new AbortController().signal)).toBe(false);
121
+ });
122
+ it('should return confirmation details if not trusted and not allowlisted', async () => {
123
+ const tool = new DiscoveredMCPTool(mockCallableToolInstance, serverName, toolNameForModel, baseDescription, inputSchema, serverToolName);
124
+ const confirmation = await tool.shouldConfirmExecute({}, new AbortController().signal);
125
+ expect(confirmation).not.toBe(false);
126
+ if (confirmation && confirmation.type === 'mcp') {
127
+ // Type guard for ToolMcpConfirmationDetails
128
+ expect(confirmation.type).toBe('mcp');
129
+ expect(confirmation.serverName).toBe(serverName);
130
+ expect(confirmation.toolName).toBe(serverToolName);
131
+ }
132
+ else if (confirmation) {
133
+ // Handle other possible confirmation types if necessary, or strengthen test if only MCP is expected
134
+ throw new Error('Confirmation was not of expected type MCP or was false');
135
+ }
136
+ else {
137
+ throw new Error('Confirmation details not in expected format or was false');
138
+ }
139
+ });
140
+ it('should add server to allowlist on ProceedAlwaysServer', async () => {
141
+ const tool = new DiscoveredMCPTool(mockCallableToolInstance, serverName, toolNameForModel, baseDescription, inputSchema, serverToolName);
142
+ const confirmation = await tool.shouldConfirmExecute({}, new AbortController().signal);
143
+ expect(confirmation).not.toBe(false);
144
+ if (confirmation &&
145
+ typeof confirmation === 'object' &&
146
+ 'onConfirm' in confirmation &&
147
+ typeof confirmation.onConfirm === 'function') {
148
+ await confirmation.onConfirm(ToolConfirmationOutcome.ProceedAlwaysServer);
149
+ expect(DiscoveredMCPTool.allowlist.has(serverName)).toBe(true);
150
+ }
151
+ else {
152
+ throw new Error('Confirmation details or onConfirm not in expected format');
153
+ }
154
+ });
155
+ it('should add tool to allowlist on ProceedAlwaysTool', async () => {
156
+ const tool = new DiscoveredMCPTool(mockCallableToolInstance, serverName, toolNameForModel, baseDescription, inputSchema, serverToolName);
157
+ const toolAllowlistKey = `${serverName}.${serverToolName}`;
158
+ const confirmation = await tool.shouldConfirmExecute({}, new AbortController().signal);
159
+ expect(confirmation).not.toBe(false);
160
+ if (confirmation &&
161
+ typeof confirmation === 'object' &&
162
+ 'onConfirm' in confirmation &&
163
+ typeof confirmation.onConfirm === 'function') {
164
+ await confirmation.onConfirm(ToolConfirmationOutcome.ProceedAlwaysTool);
165
+ expect(DiscoveredMCPTool.allowlist.has(toolAllowlistKey)).toBe(true);
166
+ }
167
+ else {
168
+ throw new Error('Confirmation details or onConfirm not in expected format');
169
+ }
170
+ });
171
+ });
172
+ });
173
+ //# sourceMappingURL=mcp-tool.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mcp-tool.test.js","sourceRoot":"","sources":["../../../src/tools/mcp-tool.test.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,uDAAuD;AACvD,OAAO,EACL,QAAQ,EACR,EAAE,EACF,MAAM,EACN,EAAE,EACF,UAAU,EACV,SAAS,GAEV,MAAM,QAAQ,CAAC;AAChB,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC,CAAC,uCAAuC;AAC1F,OAAO,EAAc,uBAAuB,EAAE,MAAM,YAAY,CAAC,CAAC,gCAAgC;AAGlG,gDAAgD;AAChD,8EAA8E;AAC9E,MAAM,YAAY,GAAG,EAAE,C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,CAAC;QACH,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,mDAAmD,EAAE,KAAK,IAAI,EAAE;YACjE,MAAM,IAAI,GAAG,IAAI,iBAAiB,CAChC,wBAAwB,EACxB,UAAU,EACV,gBAAgB,EAChB,eAAe,EACf,WAAW,EACX,cAAc,CACf,CAAC;YACF,MAAM,gBAAgB,GAAG,GAAG,UAAU,IAAI,cAAc,EAAE,CAAC;YAC3D,MAAM,YAAY,GAAG,MAAM,IAAI,CAAC,oBAAoB,CAClD,EAAE,EACF,IAAI,eAAe,EAAE,CAAC,MAAM,CAC7B,CAAC;YACF,MAAM,CAAC,YAAY,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YACrC,IACE,YAAY;gBACZ,OAAO,YAAY,KAAK,QAAQ;gBAChC,WAAW,IAAI,YAAY;gBAC3B,OAAO,YAAY,CAAC,SAAS,KAAK,UAAU,EAC5C,CAAC;gBACD,MAAM,YAAY,CAAC,SAAS,CAAC,uBAAuB,CAAC,iBAAiB,CAAC,CAAC;gBACxE,MAAM,CAAE,iBAAyB,CAAC,SAAS,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAC,CAAC,IAAI,CACrE,IAAI,CACL,CAAC;YACJ,CAAC;iBAAM,CAAC;gBACN,MAAM,IAAI,KAAK,CACb,0DAA0D,CAC3D,CAAC;YACJ,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -0,0 +1,28 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2025 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import { BaseTool, ToolResult } from './tools.js';
7
+ export declare const LLXPRT_CONFIG_DIR = ".llxprt";
8
+ export declare const DEFAULT_CONTEXT_FILENAME = "LLXPRT.md";
9
+ export declare const MEMORY_SECTION_HEADER = "## Gemini Added Memories";
10
+ export declare function setLlxprtMdFilename(newFilename: string | string[]): void;
11
+ export declare function getCurrentLlxprtMdFilename(): string;
12
+ export declare function getAllLlxprtMdFilenames(): string[];
13
+ interface SaveMemoryParams {
14
+ fact: string;
15
+ }
16
+ export declare class MemoryTool extends BaseTool<SaveMemoryParams, ToolResult> {
17
+ static readonly Name: string;
18
+ constructor();
19
+ static performAddMemoryEntry(text: string, memoryFilePath: string, fsAdapter: {
20
+ readFile: (path: string, encoding: 'utf-8') => Promise<string>;
21
+ writeFile: (path: string, data: string, encoding: 'utf-8') => Promise<void>;
22
+ mkdir: (path: string, options: {
23
+ recursive: boolean;
24
+ }) => Promise<string | undefined>;
25
+ }): Promise<void>;
26
+ execute(params: SaveMemoryParams, _signal: AbortSignal): Promise<ToolResult>;
27
+ }
28
+ export {};
@@ -0,0 +1,172 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2025 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import { BaseTool } from './tools.js';
7
+ import { Type } from '@google/genai';
8
+ import * as fs from 'fs/promises';
9
+ import * as path from 'path';
10
+ import { homedir } from 'os';
11
+ const memoryToolSchemaData = {
12
+ name: 'save_memory',
13
+ description: 'Saves a specific piece of information or fact to your long-term memory. Use this when the user explicitly asks you to remember something, or when they state a clear, concise fact that seems important to retain for future interactions.',
14
+ parameters: {
15
+ type: Type.OBJECT,
16
+ properties: {
17
+ fact: {
18
+ type: Type.STRING,
19
+ description: 'The specific fact or piece of information to remember. Should be a clear, self-contained statement.',
20
+ },
21
+ },
22
+ required: ['fact'],
23
+ },
24
+ };
25
+ const memoryToolDescription = `
26
+ Saves a specific piece of information or fact to your long-term memory.
27
+
28
+ Use this tool:
29
+
30
+ - When the user explicitly asks you to remember something (e.g., "Remember that I like pineapple on pizza", "Please save this: my cat's name is Whiskers").
31
+ - When the user states a clear, concise fact about themselves, their preferences, or their environment that seems important for you to retain for future interactions to provide a more personalized and effective assistance.
32
+
33
+ Do NOT use this tool:
34
+
35
+ - To remember conversational context that is only relevant for the current session.
36
+ - To save long, complex, or rambling pieces of text. The fact should be relatively short and to the point.
37
+ - If you are unsure whether the information is a fact worth remembering long-term. If in doubt, you can ask the user, "Should I remember that for you?"
38
+
39
+ ## Parameters
40
+
41
+ - \`fact\` (string, required): The specific fact or piece of information to remember. This should be a clear, self-contained statement. For example, if the user says "My favorite color is blue", the fact would be "My favorite color is blue".
42
+ `;
43
+ export const LLXPRT_CONFIG_DIR = '.llxprt';
44
+ export const DEFAULT_CONTEXT_FILENAME = 'LLXPRT.md';
45
+ export const MEMORY_SECTION_HEADER = '## Gemini Added Memories';
46
+ // This variable will hold the currently configured filename for LLXPRT.md context files.
47
+ // It defaults to DEFAULT_CONTEXT_FILENAME but can be overridden by setLlxprtMdFilename.
48
+ let currentLlxprtMdFilename = DEFAULT_CONTEXT_FILENAME;
49
+ export function setLlxprtMdFilename(newFilename) {
50
+ if (Array.isArray(newFilename)) {
51
+ if (newFilename.length > 0) {
52
+ currentLlxprtMdFilename = newFilename.map((name) => name.trim());
53
+ }
54
+ }
55
+ else if (newFilename && newFilename.trim() !== '') {
56
+ currentLlxprtMdFilename = newFilename.trim();
57
+ }
58
+ }
59
+ export function getCurrentLlxprtMdFilename() {
60
+ if (Array.isArray(currentLlxprtMdFilename)) {
61
+ return currentLlxprtMdFilename[0];
62
+ }
63
+ return currentLlxprtMdFilename;
64
+ }
65
+ export function getAllLlxprtMdFilenames() {
66
+ if (Array.isArray(currentLlxprtMdFilename)) {
67
+ return currentLlxprtMdFilename;
68
+ }
69
+ return [currentLlxprtMdFilename];
70
+ }
71
+ function getGlobalMemoryFilePath() {
72
+ return path.join(homedir(), LLXPRT_CONFIG_DIR, getCurrentLlxprtMdFilename());
73
+ }
74
+ /**
75
+ * Ensures proper newline separation before appending content.
76
+ */
77
+ function ensureNewlineSeparation(currentContent) {
78
+ if (currentContent.length === 0)
79
+ return '';
80
+ if (currentContent.endsWith('\n\n') || currentContent.endsWith('\r\n\r\n'))
81
+ return '';
82
+ if (currentContent.endsWith('\n') || currentContent.endsWith('\r\n'))
83
+ return '\n';
84
+ return '\n\n';
85
+ }
86
+ export class MemoryTool extends BaseTool {
87
+ static Name = memoryToolSchemaData.name;
88
+ constructor() {
89
+ super(MemoryTool.Name, 'Save Memory', memoryToolDescription, memoryToolSchemaData.parameters);
90
+ }
91
+ static async performAddMemoryEntry(text, memoryFilePath, fsAdapter) {
92
+ let processedText = text.trim();
93
+ // Remove leading hyphens and spaces that might be misinterpreted as markdown list items
94
+ processedText = processedText.replace(/^(-+\s*)+/, '').trim();
95
+ const newMemoryItem = `- ${processedText}`;
96
+ try {
97
+ await fsAdapter.mkdir(path.dirname(memoryFilePath), { recursive: true });
98
+ let content = '';
99
+ try {
100
+ content = await fsAdapter.readFile(memoryFilePath, 'utf-8');
101
+ }
102
+ catch (_e) {
103
+ // File doesn't exist, will be created with header and item.
104
+ }
105
+ const headerIndex = content.indexOf(MEMORY_SECTION_HEADER);
106
+ if (headerIndex === -1) {
107
+ // Header not found, append header and then the entry
108
+ const separator = ensureNewlineSeparation(content);
109
+ content += `${separator}${MEMORY_SECTION_HEADER}\n${newMemoryItem}\n`;
110
+ }
111
+ else {
112
+ // Header found, find where to insert the new memory entry
113
+ const startOfSectionContent = headerIndex + MEMORY_SECTION_HEADER.length;
114
+ let endOfSectionIndex = content.indexOf('\n## ', startOfSectionContent);
115
+ if (endOfSectionIndex === -1) {
116
+ endOfSectionIndex = content.length; // End of file
117
+ }
118
+ const beforeSectionMarker = content
119
+ .substring(0, startOfSectionContent)
120
+ .trimEnd();
121
+ let sectionContent = content
122
+ .substring(startOfSectionContent, endOfSectionIndex)
123
+ .trimEnd();
124
+ const afterSectionMarker = content.substring(endOfSectionIndex);
125
+ sectionContent += `\n${newMemoryItem}`;
126
+ content =
127
+ `${beforeSectionMarker}\n${sectionContent.trimStart()}\n${afterSectionMarker}`.trimEnd() +
128
+ '\n';
129
+ }
130
+ await fsAdapter.writeFile(memoryFilePath, content, 'utf-8');
131
+ }
132
+ catch (error) {
133
+ console.error(`[MemoryTool] Error adding memory entry to ${memoryFilePath}:`, error);
134
+ throw new Error(`[MemoryTool] Failed to add memory entry: ${error instanceof Error ? error.message : String(error)}`);
135
+ }
136
+ }
137
+ async execute(params, _signal) {
138
+ const { fact } = params;
139
+ if (!fact || typeof fact !== 'string' || fact.trim() === '') {
140
+ const errorMessage = 'Parameter "fact" must be a non-empty string.';
141
+ return {
142
+ llmContent: JSON.stringify({ success: false, error: errorMessage }),
143
+ returnDisplay: `Error: ${errorMessage}`,
144
+ };
145
+ }
146
+ try {
147
+ // Use the static method with actual fs promises
148
+ await MemoryTool.performAddMemoryEntry(fact, getGlobalMemoryFilePath(), {
149
+ readFile: fs.readFile,
150
+ writeFile: fs.writeFile,
151
+ mkdir: fs.mkdir,
152
+ });
153
+ const successMessage = `Okay, I've remembered that: "${fact}"`;
154
+ return {
155
+ llmContent: JSON.stringify({ success: true, message: successMessage }),
156
+ returnDisplay: successMessage,
157
+ };
158
+ }
159
+ catch (error) {
160
+ const errorMessage = error instanceof Error ? error.message : String(error);
161
+ console.error(`[MemoryTool] Error executing save_memory for fact "${fact}": ${errorMessage}`);
162
+ return {
163
+ llmContent: JSON.stringify({
164
+ success: false,
165
+ error: `Failed to save memory. Detail: ${errorMessage}`,
166
+ }),
167
+ returnDisplay: `Error saving memory: ${errorMessage}`,
168
+ };
169
+ }
170
+ }
171
+ }
172
+ //# sourceMappingURL=memoryTool.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"memoryTool.js","sourceRoot":"","sources":["../../../src/tools/memoryTool.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,QAAQ,EAAc,MAAM,YAAY,CAAC;AAClD,OAAO,EAAuB,IAAI,EAAE,MAAM,eAAe,CAAC;AAC1D,OAAO,KAAK,EAAE,MAAM,aAAa,CAAC;AAClC,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,EAAE,OAAO,EAAE,MAAM,IAAI,CAAC;AAE7B,MAAM,oBA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