agentdb 1.0.12 → 1.1.1

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 (503) hide show
  1. package/README.md +196 -838
  2. package/dist/benchmarks/comprehensive-benchmark.js +664 -0
  3. package/dist/benchmarks/frontier-benchmark.js +419 -0
  4. package/dist/benchmarks/reflexion-benchmark.js +370 -0
  5. package/dist/cli/agentdb-cli.d.ts +117 -0
  6. package/dist/cli/agentdb-cli.d.ts.map +1 -0
  7. package/dist/cli/agentdb-cli.js +724 -0
  8. package/dist/cli/agentdb-cli.js.map +1 -0
  9. package/dist/controllers/CausalMemoryGraph.d.ts +125 -0
  10. package/dist/controllers/CausalMemoryGraph.d.ts.map +1 -0
  11. package/dist/controllers/CausalMemoryGraph.js +323 -0
  12. package/dist/controllers/CausalMemoryGraph.js.map +1 -0
  13. package/dist/controllers/CausalRecall.d.ts +111 -0
  14. package/dist/controllers/CausalRecall.d.ts.map +1 -0
  15. package/dist/controllers/CausalRecall.js +282 -0
  16. package/dist/controllers/CausalRecall.js.map +1 -0
  17. package/dist/controllers/EmbeddingService.d.ts +37 -0
  18. package/dist/controllers/EmbeddingService.d.ts.map +1 -0
  19. package/dist/controllers/EmbeddingService.js +119 -0
  20. package/dist/controllers/EmbeddingService.js.map +1 -0
  21. package/dist/controllers/ExplainableRecall.d.ts +138 -0
  22. package/dist/controllers/ExplainableRecall.d.ts.map +1 -0
  23. package/dist/controllers/ExplainableRecall.js +388 -0
  24. package/dist/controllers/ExplainableRecall.js.map +1 -0
  25. package/dist/controllers/NightlyLearner.d.ts +113 -0
  26. package/dist/controllers/NightlyLearner.d.ts.map +1 -0
  27. package/dist/controllers/NightlyLearner.js +383 -0
  28. package/dist/controllers/NightlyLearner.js.map +1 -0
  29. package/dist/controllers/ReflexionMemory.d.ts +84 -0
  30. package/dist/controllers/ReflexionMemory.d.ts.map +1 -0
  31. package/dist/controllers/ReflexionMemory.js +240 -0
  32. package/dist/controllers/ReflexionMemory.js.map +1 -0
  33. package/dist/controllers/SkillLibrary.d.ts +96 -0
  34. package/dist/controllers/SkillLibrary.d.ts.map +1 -0
  35. package/dist/controllers/SkillLibrary.js +277 -0
  36. package/dist/controllers/SkillLibrary.js.map +1 -0
  37. package/dist/controllers/frontier-index.d.ts +14 -0
  38. package/dist/controllers/frontier-index.d.ts.map +1 -0
  39. package/dist/controllers/frontier-index.js +10 -0
  40. package/dist/controllers/frontier-index.js.map +1 -0
  41. package/dist/controllers/index.d.ts +12 -0
  42. package/dist/controllers/index.d.ts.map +1 -0
  43. package/dist/controllers/index.js +9 -0
  44. package/dist/controllers/index.js.map +1 -0
  45. package/dist/optimizations/BatchOperations.d.ts +61 -0
  46. package/dist/optimizations/BatchOperations.d.ts.map +1 -0
  47. package/dist/optimizations/BatchOperations.js +199 -0
  48. package/dist/optimizations/BatchOperations.js.map +1 -0
  49. package/dist/optimizations/QueryOptimizer.d.ts +82 -0
  50. package/dist/optimizations/QueryOptimizer.d.ts.map +1 -0
  51. package/dist/optimizations/QueryOptimizer.js +226 -0
  52. package/dist/optimizations/QueryOptimizer.js.map +1 -0
  53. package/dist/optimizations/index.d.ts +10 -0
  54. package/dist/optimizations/index.d.ts.map +1 -0
  55. package/dist/optimizations/index.js +8 -0
  56. package/dist/optimizations/index.js.map +1 -0
  57. package/dist/schemas/frontier-schema.sql +341 -0
  58. package/dist/schemas/schema.sql +382 -0
  59. package/dist/tests/frontier-features.test.js +665 -0
  60. package/package.json +54 -117
  61. package/src/cli/agentdb-cli.ts +861 -0
  62. package/src/cli/examples.sh +83 -0
  63. package/src/controllers/CausalMemoryGraph.ts +504 -0
  64. package/src/controllers/CausalRecall.ts +395 -0
  65. package/src/controllers/EmbeddingService.ts +141 -0
  66. package/src/controllers/ExplainableRecall.ts +577 -0
  67. package/src/controllers/NightlyLearner.ts +475 -0
  68. package/src/controllers/ReflexionMemory.ts +349 -0
  69. package/src/controllers/SkillLibrary.ts +391 -0
  70. package/src/controllers/frontier-index.ts +35 -0
  71. package/src/controllers/index.ts +13 -0
  72. package/src/optimizations/BatchOperations.ts +292 -0
  73. package/src/optimizations/QueryOptimizer.ts +294 -0
  74. package/src/optimizations/index.ts +11 -0
  75. package/src/schemas/frontier-schema.sql +341 -0
  76. package/src/schemas/schema.sql +382 -0
  77. package/CHANGELOG.md +0 -166
  78. package/LICENSE +0 -38
  79. package/LICENSE-APACHE +0 -190
  80. package/LICENSE-MIT +0 -21
  81. package/bin/agentdb.js +0 -733
  82. package/bin/benchmark.js +0 -165
  83. package/bin/plugin-cli-wrapper.mjs +0 -21
  84. package/dist/agentdb.js +0 -5352
  85. package/dist/agentdb.js.map +0 -7
  86. package/dist/agentdb.min.js +0 -143
  87. package/dist/agentdb.min.js.map +0 -7
  88. package/dist/cache/query-cache.d.ts +0 -105
  89. package/dist/cache/query-cache.d.ts.map +0 -1
  90. package/dist/cache/query-cache.js +0 -224
  91. package/dist/cache/query-cache.js.map +0 -1
  92. package/dist/cache/query-cache.mjs +0 -219
  93. package/dist/cli/cache/query-cache.d.ts +0 -104
  94. package/dist/cli/cache/query-cache.js +0 -244
  95. package/dist/cli/cli/db-commands.d.ts +0 -48
  96. package/dist/cli/cli/db-commands.js +0 -613
  97. package/dist/cli/commands.d.ts +0 -7
  98. package/dist/cli/commands.d.ts.map +0 -1
  99. package/dist/cli/commands.js +0 -113
  100. package/dist/cli/commands.js.map +0 -1
  101. package/dist/cli/commands.mjs +0 -104
  102. package/dist/cli/core/backend-interface.d.ts +0 -70
  103. package/dist/cli/core/backend-interface.js +0 -15
  104. package/dist/cli/core/native-backend.d.ts +0 -140
  105. package/dist/cli/core/native-backend.js +0 -432
  106. package/dist/cli/core/vector-db.d.ts +0 -126
  107. package/dist/cli/core/vector-db.js +0 -338
  108. package/dist/cli/core/wasm-backend.d.ts +0 -95
  109. package/dist/cli/core/wasm-backend.js +0 -418
  110. package/dist/cli/db-commands.d.ts +0 -49
  111. package/dist/cli/db-commands.d.ts.map +0 -1
  112. package/dist/cli/db-commands.js +0 -533
  113. package/dist/cli/db-commands.js.map +0 -1
  114. package/dist/cli/db-commands.mjs +0 -522
  115. package/dist/cli/generator.d.ts +0 -11
  116. package/dist/cli/generator.d.ts.map +0 -1
  117. package/dist/cli/generator.js +0 -567
  118. package/dist/cli/generator.js.map +0 -1
  119. package/dist/cli/generator.mjs +0 -527
  120. package/dist/cli/help.d.ts +0 -18
  121. package/dist/cli/help.d.ts.map +0 -1
  122. package/dist/cli/help.js +0 -676
  123. package/dist/cli/help.js.map +0 -1
  124. package/dist/cli/help.mjs +0 -667
  125. package/dist/cli/index/hnsw.d.ts +0 -164
  126. package/dist/cli/index/hnsw.js +0 -558
  127. package/dist/cli/plugin-cli.d.ts +0 -7
  128. package/dist/cli/plugin-cli.d.ts.map +0 -1
  129. package/dist/cli/plugin-cli.js +0 -295
  130. package/dist/cli/plugin-cli.js.map +0 -1
  131. package/dist/cli/plugin-cli.mjs +0 -289
  132. package/dist/cli/quantization/product-quantization.d.ts +0 -108
  133. package/dist/cli/quantization/product-quantization.js +0 -350
  134. package/dist/cli/query/query-builder.d.ts +0 -322
  135. package/dist/cli/query/query-builder.js +0 -600
  136. package/dist/cli/templates.d.ts +0 -14
  137. package/dist/cli/templates.d.ts.map +0 -1
  138. package/dist/cli/templates.js +0 -182
  139. package/dist/cli/templates.js.map +0 -1
  140. package/dist/cli/templates.mjs +0 -176
  141. package/dist/cli/types/index.d.ts +0 -116
  142. package/dist/cli/types/index.js +0 -5
  143. package/dist/cli/types.d.ts +0 -91
  144. package/dist/cli/types.d.ts.map +0 -1
  145. package/dist/cli/types.js +0 -6
  146. package/dist/cli/types.js.map +0 -1
  147. package/dist/cli/types.mjs +0 -4
  148. package/dist/cli/wizard/index.d.ts +0 -6
  149. package/dist/cli/wizard/index.d.ts.map +0 -1
  150. package/dist/cli/wizard/index.js +0 -138
  151. package/dist/cli/wizard/index.js.map +0 -1
  152. package/dist/cli/wizard/index.mjs +0 -131
  153. package/dist/cli/wizard/prompts.d.ts +0 -11
  154. package/dist/cli/wizard/prompts.d.ts.map +0 -1
  155. package/dist/cli/wizard/prompts.js +0 -482
  156. package/dist/cli/wizard/prompts.js.map +0 -1
  157. package/dist/cli/wizard/prompts.mjs +0 -470
  158. package/dist/cli/wizard/validator.d.ts +0 -13
  159. package/dist/cli/wizard/validator.d.ts.map +0 -1
  160. package/dist/cli/wizard/validator.js +0 -234
  161. package/dist/cli/wizard/validator.js.map +0 -1
  162. package/dist/cli/wizard/validator.mjs +0 -224
  163. package/dist/core/backend-interface.d.ts +0 -71
  164. package/dist/core/backend-interface.d.ts.map +0 -1
  165. package/dist/core/backend-interface.js +0 -16
  166. package/dist/core/backend-interface.js.map +0 -1
  167. package/dist/core/backend-interface.mjs +0 -12
  168. package/dist/core/native-backend.d.ts +0 -141
  169. package/dist/core/native-backend.d.ts.map +0 -1
  170. package/dist/core/native-backend.js +0 -457
  171. package/dist/core/native-backend.js.map +0 -1
  172. package/dist/core/native-backend.mjs +0 -449
  173. package/dist/core/vector-db.d.ts +0 -127
  174. package/dist/core/vector-db.d.ts.map +0 -1
  175. package/dist/core/vector-db.js +0 -270
  176. package/dist/core/vector-db.js.map +0 -1
  177. package/dist/core/vector-db.mjs +0 -265
  178. package/dist/core/wasm-backend.d.ts +0 -96
  179. package/dist/core/wasm-backend.d.ts.map +0 -1
  180. package/dist/core/wasm-backend.js +0 -393
  181. package/dist/core/wasm-backend.js.map +0 -1
  182. package/dist/core/wasm-backend.mjs +0 -385
  183. package/dist/index/hnsw-optimized.d.ts +0 -75
  184. package/dist/index/hnsw-optimized.d.ts.map +0 -1
  185. package/dist/index/hnsw-optimized.js +0 -412
  186. package/dist/index/hnsw-optimized.js.map +0 -1
  187. package/dist/index/hnsw-optimized.mjs +0 -407
  188. package/dist/index/hnsw.d.ts +0 -165
  189. package/dist/index/hnsw.d.ts.map +0 -1
  190. package/dist/index/hnsw.js +0 -521
  191. package/dist/index/hnsw.js.map +0 -1
  192. package/dist/index/hnsw.mjs +0 -516
  193. package/dist/index.browser.d.ts +0 -47
  194. package/dist/index.browser.d.ts.map +0 -1
  195. package/dist/index.browser.js +0 -72
  196. package/dist/index.browser.js.map +0 -1
  197. package/dist/index.browser.mjs +0 -54
  198. package/dist/index.d.ts +0 -59
  199. package/dist/index.d.ts.map +0 -1
  200. package/dist/index.js +0 -84
  201. package/dist/index.js.map +0 -1
  202. package/dist/index.mjs +0 -65
  203. package/dist/mcp/learning/core/experience-buffer.d.ts +0 -61
  204. package/dist/mcp/learning/core/experience-buffer.d.ts.map +0 -1
  205. package/dist/mcp/learning/core/experience-buffer.js +0 -175
  206. package/dist/mcp/learning/core/experience-buffer.js.map +0 -1
  207. package/dist/mcp/learning/core/experience-buffer.mjs +0 -170
  208. package/dist/mcp/learning/core/experience-recorder.d.ts +0 -40
  209. package/dist/mcp/learning/core/experience-recorder.d.ts.map +0 -1
  210. package/dist/mcp/learning/core/experience-recorder.js +0 -200
  211. package/dist/mcp/learning/core/experience-recorder.js.map +0 -1
  212. package/dist/mcp/learning/core/experience-recorder.mjs +0 -195
  213. package/dist/mcp/learning/core/learning-manager.d.ts +0 -66
  214. package/dist/mcp/learning/core/learning-manager.d.ts.map +0 -1
  215. package/dist/mcp/learning/core/learning-manager.js +0 -252
  216. package/dist/mcp/learning/core/learning-manager.js.map +0 -1
  217. package/dist/mcp/learning/core/learning-manager.mjs +0 -247
  218. package/dist/mcp/learning/core/policy-optimizer.d.ts +0 -53
  219. package/dist/mcp/learning/core/policy-optimizer.d.ts.map +0 -1
  220. package/dist/mcp/learning/core/policy-optimizer.js +0 -251
  221. package/dist/mcp/learning/core/policy-optimizer.js.map +0 -1
  222. package/dist/mcp/learning/core/policy-optimizer.mjs +0 -246
  223. package/dist/mcp/learning/core/reward-estimator.d.ts +0 -44
  224. package/dist/mcp/learning/core/reward-estimator.d.ts.map +0 -1
  225. package/dist/mcp/learning/core/reward-estimator.js +0 -158
  226. package/dist/mcp/learning/core/reward-estimator.js.map +0 -1
  227. package/dist/mcp/learning/core/reward-estimator.mjs +0 -153
  228. package/dist/mcp/learning/core/session-manager.d.ts +0 -63
  229. package/dist/mcp/learning/core/session-manager.d.ts.map +0 -1
  230. package/dist/mcp/learning/core/session-manager.js +0 -202
  231. package/dist/mcp/learning/core/session-manager.js.map +0 -1
  232. package/dist/mcp/learning/core/session-manager.mjs +0 -197
  233. package/dist/mcp/learning/index.d.ts +0 -19
  234. package/dist/mcp/learning/index.d.ts.map +0 -1
  235. package/dist/mcp/learning/index.js +0 -30
  236. package/dist/mcp/learning/index.js.map +0 -1
  237. package/dist/mcp/learning/index.mjs +0 -19
  238. package/dist/mcp/learning/tools/mcp-learning-tools.d.ts +0 -369
  239. package/dist/mcp/learning/tools/mcp-learning-tools.d.ts.map +0 -1
  240. package/dist/mcp/learning/tools/mcp-learning-tools.js +0 -361
  241. package/dist/mcp/learning/tools/mcp-learning-tools.js.map +0 -1
  242. package/dist/mcp/learning/tools/mcp-learning-tools.mjs +0 -356
  243. package/dist/mcp/learning/types/index.d.ts +0 -138
  244. package/dist/mcp/learning/types/index.d.ts.map +0 -1
  245. package/dist/mcp/learning/types/index.js +0 -6
  246. package/dist/mcp/learning/types/index.js.map +0 -1
  247. package/dist/mcp/learning/types/index.mjs +0 -4
  248. package/dist/mcp-server.d.ts +0 -29
  249. package/dist/mcp-server.d.ts.map +0 -1
  250. package/dist/mcp-server.js +0 -862
  251. package/dist/mcp-server.js.map +0 -1
  252. package/dist/mcp-server.mjs +0 -857
  253. package/dist/plugins/base-plugin.d.ts +0 -114
  254. package/dist/plugins/base-plugin.d.ts.map +0 -1
  255. package/dist/plugins/base-plugin.js +0 -313
  256. package/dist/plugins/base-plugin.js.map +0 -1
  257. package/dist/plugins/base-plugin.mjs +0 -275
  258. package/dist/plugins/implementations/active-learning.d.ts +0 -135
  259. package/dist/plugins/implementations/active-learning.d.ts.map +0 -1
  260. package/dist/plugins/implementations/active-learning.js +0 -372
  261. package/dist/plugins/implementations/active-learning.js.map +0 -1
  262. package/dist/plugins/implementations/active-learning.mjs +0 -367
  263. package/dist/plugins/implementations/actor-critic.d.ts +0 -64
  264. package/dist/plugins/implementations/actor-critic.d.ts.map +0 -1
  265. package/dist/plugins/implementations/actor-critic.js +0 -363
  266. package/dist/plugins/implementations/actor-critic.js.map +0 -1
  267. package/dist/plugins/implementations/actor-critic.mjs +0 -358
  268. package/dist/plugins/implementations/adversarial-training.d.ts +0 -133
  269. package/dist/plugins/implementations/adversarial-training.d.ts.map +0 -1
  270. package/dist/plugins/implementations/adversarial-training.js +0 -409
  271. package/dist/plugins/implementations/adversarial-training.js.map +0 -1
  272. package/dist/plugins/implementations/adversarial-training.mjs +0 -404
  273. package/dist/plugins/implementations/curriculum-learning.d.ts +0 -132
  274. package/dist/plugins/implementations/curriculum-learning.d.ts.map +0 -1
  275. package/dist/plugins/implementations/curriculum-learning.js +0 -354
  276. package/dist/plugins/implementations/curriculum-learning.js.map +0 -1
  277. package/dist/plugins/implementations/curriculum-learning.mjs +0 -349
  278. package/dist/plugins/implementations/decision-transformer.d.ts +0 -77
  279. package/dist/plugins/implementations/decision-transformer.d.ts.map +0 -1
  280. package/dist/plugins/implementations/decision-transformer.js +0 -422
  281. package/dist/plugins/implementations/decision-transformer.js.map +0 -1
  282. package/dist/plugins/implementations/decision-transformer.mjs +0 -417
  283. package/dist/plugins/implementations/federated-learning.d.ts +0 -126
  284. package/dist/plugins/implementations/federated-learning.d.ts.map +0 -1
  285. package/dist/plugins/implementations/federated-learning.js +0 -436
  286. package/dist/plugins/implementations/federated-learning.js.map +0 -1
  287. package/dist/plugins/implementations/federated-learning.mjs +0 -431
  288. package/dist/plugins/implementations/index.d.ts +0 -30
  289. package/dist/plugins/implementations/index.d.ts.map +0 -1
  290. package/dist/plugins/implementations/index.js +0 -45
  291. package/dist/plugins/implementations/index.js.map +0 -1
  292. package/dist/plugins/implementations/index.mjs +0 -31
  293. package/dist/plugins/implementations/multi-task-learning.d.ts +0 -115
  294. package/dist/plugins/implementations/multi-task-learning.d.ts.map +0 -1
  295. package/dist/plugins/implementations/multi-task-learning.js +0 -369
  296. package/dist/plugins/implementations/multi-task-learning.js.map +0 -1
  297. package/dist/plugins/implementations/multi-task-learning.mjs +0 -364
  298. package/dist/plugins/implementations/neural-architecture-search.d.ts +0 -148
  299. package/dist/plugins/implementations/neural-architecture-search.d.ts.map +0 -1
  300. package/dist/plugins/implementations/neural-architecture-search.js +0 -379
  301. package/dist/plugins/implementations/neural-architecture-search.js.map +0 -1
  302. package/dist/plugins/implementations/neural-architecture-search.mjs +0 -374
  303. package/dist/plugins/implementations/q-learning.d.ts +0 -98
  304. package/dist/plugins/implementations/q-learning.d.ts.map +0 -1
  305. package/dist/plugins/implementations/q-learning.js +0 -435
  306. package/dist/plugins/implementations/q-learning.js.map +0 -1
  307. package/dist/plugins/implementations/q-learning.mjs +0 -430
  308. package/dist/plugins/implementations/sarsa.d.ts +0 -103
  309. package/dist/plugins/implementations/sarsa.d.ts.map +0 -1
  310. package/dist/plugins/implementations/sarsa.js +0 -347
  311. package/dist/plugins/implementations/sarsa.js.map +0 -1
  312. package/dist/plugins/implementations/sarsa.mjs +0 -342
  313. package/dist/plugins/index.d.ts +0 -107
  314. package/dist/plugins/index.d.ts.map +0 -1
  315. package/dist/plugins/index.js +0 -179
  316. package/dist/plugins/index.js.map +0 -1
  317. package/dist/plugins/index.mjs +0 -168
  318. package/dist/plugins/interface.d.ts +0 -439
  319. package/dist/plugins/interface.d.ts.map +0 -1
  320. package/dist/plugins/interface.js +0 -12
  321. package/dist/plugins/interface.js.map +0 -1
  322. package/dist/plugins/interface.mjs +0 -10
  323. package/dist/plugins/learning-plugin.interface.d.ts +0 -257
  324. package/dist/plugins/learning-plugin.interface.d.ts.map +0 -1
  325. package/dist/plugins/learning-plugin.interface.js +0 -7
  326. package/dist/plugins/learning-plugin.interface.js.map +0 -1
  327. package/dist/plugins/learning-plugin.interface.mjs +0 -5
  328. package/dist/plugins/plugin-exports.d.ts +0 -71
  329. package/dist/plugins/plugin-exports.d.ts.map +0 -1
  330. package/dist/plugins/plugin-exports.js +0 -78
  331. package/dist/plugins/plugin-exports.js.map +0 -1
  332. package/dist/plugins/plugin-exports.mjs +0 -69
  333. package/dist/plugins/registry.d.ts +0 -206
  334. package/dist/plugins/registry.d.ts.map +0 -1
  335. package/dist/plugins/registry.js +0 -365
  336. package/dist/plugins/registry.js.map +0 -1
  337. package/dist/plugins/registry.mjs +0 -356
  338. package/dist/plugins/validator.d.ts +0 -63
  339. package/dist/plugins/validator.d.ts.map +0 -1
  340. package/dist/plugins/validator.js +0 -464
  341. package/dist/plugins/validator.js.map +0 -1
  342. package/dist/plugins/validator.mjs +0 -458
  343. package/dist/presets.d.ts +0 -65
  344. package/dist/presets.d.ts.map +0 -1
  345. package/dist/presets.js +0 -145
  346. package/dist/presets.js.map +0 -1
  347. package/dist/presets.mjs +0 -140
  348. package/dist/quantization/binary-quantization.d.ts +0 -104
  349. package/dist/quantization/binary-quantization.d.ts.map +0 -1
  350. package/dist/quantization/binary-quantization.js +0 -246
  351. package/dist/quantization/binary-quantization.js.map +0 -1
  352. package/dist/quantization/binary-quantization.mjs +0 -240
  353. package/dist/quantization/optimized-pq.d.ts +0 -138
  354. package/dist/quantization/optimized-pq.d.ts.map +0 -1
  355. package/dist/quantization/optimized-pq.js +0 -320
  356. package/dist/quantization/optimized-pq.js.map +0 -1
  357. package/dist/quantization/optimized-pq.mjs +0 -313
  358. package/dist/quantization/product-quantization.d.ts +0 -109
  359. package/dist/quantization/product-quantization.d.ts.map +0 -1
  360. package/dist/quantization/product-quantization.js +0 -287
  361. package/dist/quantization/product-quantization.js.map +0 -1
  362. package/dist/quantization/product-quantization.mjs +0 -282
  363. package/dist/quantization/scalar-quantization.d.ts +0 -100
  364. package/dist/quantization/scalar-quantization.d.ts.map +0 -1
  365. package/dist/quantization/scalar-quantization.js +0 -324
  366. package/dist/quantization/scalar-quantization.js.map +0 -1
  367. package/dist/quantization/scalar-quantization.mjs +0 -319
  368. package/dist/query/index.d.ts +0 -6
  369. package/dist/query/index.d.ts.map +0 -1
  370. package/dist/query/index.js +0 -9
  371. package/dist/query/index.js.map +0 -1
  372. package/dist/query/index.mjs +0 -4
  373. package/dist/query/query-builder.d.ts +0 -323
  374. package/dist/query/query-builder.d.ts.map +0 -1
  375. package/dist/query/query-builder.js +0 -524
  376. package/dist/query/query-builder.js.map +0 -1
  377. package/dist/query/query-builder.mjs +0 -519
  378. package/dist/reasoning/context-synthesizer.d.ts +0 -57
  379. package/dist/reasoning/context-synthesizer.d.ts.map +0 -1
  380. package/dist/reasoning/context-synthesizer.js +0 -224
  381. package/dist/reasoning/context-synthesizer.js.map +0 -1
  382. package/dist/reasoning/context-synthesizer.mjs +0 -219
  383. package/dist/reasoning/experience-curator.d.ts +0 -66
  384. package/dist/reasoning/experience-curator.d.ts.map +0 -1
  385. package/dist/reasoning/experience-curator.js +0 -288
  386. package/dist/reasoning/experience-curator.js.map +0 -1
  387. package/dist/reasoning/experience-curator.mjs +0 -283
  388. package/dist/reasoning/memory-optimizer.d.ts +0 -69
  389. package/dist/reasoning/memory-optimizer.d.ts.map +0 -1
  390. package/dist/reasoning/memory-optimizer.js +0 -331
  391. package/dist/reasoning/memory-optimizer.js.map +0 -1
  392. package/dist/reasoning/memory-optimizer.mjs +0 -326
  393. package/dist/reasoning/pattern-matcher.d.ts +0 -59
  394. package/dist/reasoning/pattern-matcher.d.ts.map +0 -1
  395. package/dist/reasoning/pattern-matcher.js +0 -229
  396. package/dist/reasoning/pattern-matcher.js.map +0 -1
  397. package/dist/reasoning/pattern-matcher.mjs +0 -224
  398. package/dist/reasoningbank/adapter/agentdb-adapter.d.ts +0 -118
  399. package/dist/reasoningbank/adapter/agentdb-adapter.d.ts.map +0 -1
  400. package/dist/reasoningbank/adapter/agentdb-adapter.js +0 -477
  401. package/dist/reasoningbank/adapter/agentdb-adapter.js.map +0 -1
  402. package/dist/reasoningbank/adapter/types.d.ts +0 -113
  403. package/dist/reasoningbank/adapter/types.d.ts.map +0 -1
  404. package/dist/reasoningbank/adapter/types.js +0 -9
  405. package/dist/reasoningbank/adapter/types.js.map +0 -1
  406. package/dist/reasoningbank/cli/commands.d.ts +0 -16
  407. package/dist/reasoningbank/cli/commands.d.ts.map +0 -1
  408. package/dist/reasoningbank/cli/commands.js +0 -272
  409. package/dist/reasoningbank/cli/commands.js.map +0 -1
  410. package/dist/reasoningbank/mcp/agentdb-tools.d.ts +0 -319
  411. package/dist/reasoningbank/mcp/agentdb-tools.d.ts.map +0 -1
  412. package/dist/reasoningbank/mcp/agentdb-tools.js +0 -301
  413. package/dist/reasoningbank/mcp/agentdb-tools.js.map +0 -1
  414. package/dist/reasoningbank/migration/migrate.d.ts +0 -25
  415. package/dist/reasoningbank/migration/migrate.d.ts.map +0 -1
  416. package/dist/reasoningbank/migration/migrate.js +0 -178
  417. package/dist/reasoningbank/migration/migrate.js.map +0 -1
  418. package/dist/reasoningbank/reasoning/context-synthesizer.d.ts +0 -37
  419. package/dist/reasoningbank/reasoning/context-synthesizer.d.ts.map +0 -1
  420. package/dist/reasoningbank/reasoning/context-synthesizer.js +0 -114
  421. package/dist/reasoningbank/reasoning/context-synthesizer.js.map +0 -1
  422. package/dist/reasoningbank/reasoning/experience-curator.d.ts +0 -39
  423. package/dist/reasoningbank/reasoning/experience-curator.d.ts.map +0 -1
  424. package/dist/reasoningbank/reasoning/experience-curator.js +0 -98
  425. package/dist/reasoningbank/reasoning/experience-curator.js.map +0 -1
  426. package/dist/reasoningbank/reasoning/memory-optimizer.d.ts +0 -44
  427. package/dist/reasoningbank/reasoning/memory-optimizer.d.ts.map +0 -1
  428. package/dist/reasoningbank/reasoning/memory-optimizer.js +0 -184
  429. package/dist/reasoningbank/reasoning/memory-optimizer.js.map +0 -1
  430. package/dist/reasoningbank/reasoning/pattern-matcher.d.ts +0 -40
  431. package/dist/reasoningbank/reasoning/pattern-matcher.d.ts.map +0 -1
  432. package/dist/reasoningbank/reasoning/pattern-matcher.js +0 -87
  433. package/dist/reasoningbank/reasoning/pattern-matcher.js.map +0 -1
  434. package/dist/reasoningbank/sync/quic-sync.d.ts +0 -77
  435. package/dist/reasoningbank/sync/quic-sync.d.ts.map +0 -1
  436. package/dist/reasoningbank/sync/quic-sync.js +0 -165
  437. package/dist/reasoningbank/sync/quic-sync.js.map +0 -1
  438. package/dist/sync/conflict.d.ts +0 -78
  439. package/dist/sync/conflict.d.ts.map +0 -1
  440. package/dist/sync/conflict.js +0 -202
  441. package/dist/sync/conflict.js.map +0 -1
  442. package/dist/sync/conflict.mjs +0 -196
  443. package/dist/sync/coordinator.d.ts +0 -111
  444. package/dist/sync/coordinator.d.ts.map +0 -1
  445. package/dist/sync/coordinator.js +0 -256
  446. package/dist/sync/coordinator.js.map +0 -1
  447. package/dist/sync/coordinator.mjs +0 -250
  448. package/dist/sync/delta.d.ts +0 -81
  449. package/dist/sync/delta.d.ts.map +0 -1
  450. package/dist/sync/delta.js +0 -245
  451. package/dist/sync/delta.js.map +0 -1
  452. package/dist/sync/delta.mjs +0 -238
  453. package/dist/sync/index.d.ts +0 -11
  454. package/dist/sync/index.d.ts.map +0 -1
  455. package/dist/sync/index.js +0 -22
  456. package/dist/sync/index.js.map +0 -1
  457. package/dist/sync/index.mjs +0 -9
  458. package/dist/sync/quic-sync.d.ts +0 -81
  459. package/dist/sync/quic-sync.d.ts.map +0 -1
  460. package/dist/sync/quic-sync.js +0 -329
  461. package/dist/sync/quic-sync.js.map +0 -1
  462. package/dist/sync/quic-sync.mjs +0 -323
  463. package/dist/sync/types.d.ts +0 -168
  464. package/dist/sync/types.d.ts.map +0 -1
  465. package/dist/sync/types.js +0 -8
  466. package/dist/sync/types.js.map +0 -1
  467. package/dist/sync/types.mjs +0 -6
  468. package/dist/types/index.d.ts +0 -117
  469. package/dist/types/index.d.ts.map +0 -1
  470. package/dist/types/index.js +0 -6
  471. package/dist/types/index.js.map +0 -1
  472. package/dist/types/index.mjs +0 -4
  473. package/dist/wasm/sql-wasm-debug.js +0 -6989
  474. package/dist/wasm/sql-wasm-debug.wasm +0 -0
  475. package/dist/wasm/sql-wasm.js +0 -188
  476. package/dist/wasm/sql-wasm.wasm +0 -0
  477. package/dist/wasm-loader.d.ts +0 -32
  478. package/dist/wasm-loader.d.ts.map +0 -1
  479. package/dist/wasm-loader.js +0 -78
  480. package/dist/wasm-loader.js.map +0 -1
  481. package/dist/wasm-loader.mjs +0 -67
  482. package/examples/adaptive-learning.ts +0 -284
  483. package/examples/browser/README.md +0 -732
  484. package/examples/browser/adaptive-recommendations/index.html +0 -427
  485. package/examples/browser/collaborative-filtering/index.html +0 -310
  486. package/examples/browser/continual-learning/index.html +0 -736
  487. package/examples/browser/experience-replay/index.html +0 -616
  488. package/examples/browser/index.html +0 -369
  489. package/examples/browser/meta-learning/index.html +0 -789
  490. package/examples/browser/neuro-symbolic/index.html +0 -692
  491. package/examples/browser/pattern-learning/index.html +0 -620
  492. package/examples/browser/quantum-inspired/index.html +0 -728
  493. package/examples/browser/rag/index.html +0 -624
  494. package/examples/browser/swarm-intelligence/index.html +0 -811
  495. package/examples/browser-basic.html +0 -170
  496. package/examples/browser-wasm-real.html +0 -231
  497. package/examples/hnsw-example.ts +0 -148
  498. package/examples/mcp-learning-example.ts +0 -220
  499. package/examples/node-basic.js +0 -70
  500. package/examples/quic-sync-example.ts +0 -310
  501. package/examples/quick-start.js +0 -68
  502. package/examples/test-v1.0.7-cdn.html +0 -190
  503. package/examples/wasm-example.ts +0 -222
@@ -1,857 +0,0 @@
1
- #!/usr/bin/env node
2
- /**
3
- * AgentDB MCP Server
4
- * Production-ready MCP server for Claude Code integration
5
- * Exposes AgentDB vector database and ReasoningBank operations via MCP protocol
6
- */
7
- import { Server } from '@modelcontextprotocol/sdk/server/index.js';
8
- import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
9
- import { CallToolRequestSchema, ListResourcesRequestSchema, ListToolsRequestSchema, ReadResourceRequestSchema, } from '@modelcontextprotocol/sdk/types.js';
10
- import { SQLiteVectorDB } from './core/vector-db.mjs';
11
- import { PatternMatcher } from './reasoning/pattern-matcher.mjs';
12
- import { BackendType } from './core/backend-interface.mjs';
13
- import { z } from 'zod';
14
- import { LearningManager } from './mcp/learning/core/learning-manager.mjs';
15
- import { MCPLearningTools } from './mcp/learning/tools/mcp-learning-tools.mjs';
16
- // ============================================================================
17
- // Type Definitions
18
- // ============================================================================
19
- const VectorSchema = z.object({
20
- id: z.string().optional(),
21
- embedding: z.array(z.number()),
22
- metadata: z.record(z.any()).optional(),
23
- timestamp: z.number().optional(),
24
- });
25
- const PatternSchema = z.object({
26
- embedding: z.array(z.number()),
27
- taskType: z.string(),
28
- approach: z.string(),
29
- successRate: z.number().min(0).max(1),
30
- avgDuration: z.number().positive(),
31
- metadata: z.object({
32
- domain: z.string(),
33
- complexity: z.enum(['simple', 'medium', 'complex']),
34
- learningSource: z.enum(['success', 'failure', 'adaptation']),
35
- tags: z.array(z.string()),
36
- }),
37
- });
38
- // ============================================================================
39
- // MCP Tool Definitions
40
- // ============================================================================
41
- const tools = [
42
- {
43
- name: 'agentdb_init',
44
- description: 'Initialize a new AgentDB vector database with specified configuration. Supports both in-memory and persistent storage with optional quantization and caching.',
45
- inputSchema: {
46
- type: 'object',
47
- properties: {
48
- path: {
49
- type: 'string',
50
- description: 'Database file path (optional, uses in-memory if not provided)',
51
- },
52
- memoryMode: {
53
- type: 'boolean',
54
- description: 'Use in-memory database (default: true if no path provided)',
55
- default: true,
56
- },
57
- backend: {
58
- type: 'string',
59
- enum: ['native', 'wasm'],
60
- description: 'Backend type: native (Node.js) or wasm (browser/universal)',
61
- default: 'native',
62
- },
63
- enableQueryCache: {
64
- type: 'boolean',
65
- description: 'Enable query caching for 50-100x speedup',
66
- default: true,
67
- },
68
- enableQuantization: {
69
- type: 'boolean',
70
- description: 'Enable vector quantization for 4-32x compression',
71
- default: false,
72
- },
73
- },
74
- },
75
- },
76
- {
77
- name: 'agentdb_insert',
78
- description: 'Insert a single vector into AgentDB with optional metadata. Returns the generated vector ID.',
79
- inputSchema: {
80
- type: 'object',
81
- properties: {
82
- vector: {
83
- type: 'object',
84
- properties: {
85
- id: {
86
- type: 'string',
87
- description: 'Optional vector ID (auto-generated if not provided)',
88
- },
89
- embedding: {
90
- type: 'array',
91
- items: { type: 'number' },
92
- description: 'Vector embedding values',
93
- },
94
- metadata: {
95
- type: 'object',
96
- description: 'Optional metadata as key-value pairs',
97
- },
98
- },
99
- required: ['embedding'],
100
- },
101
- },
102
- required: ['vector'],
103
- },
104
- },
105
- {
106
- name: 'agentdb_insert_batch',
107
- description: 'Insert multiple vectors in batch for better performance. Optimized for high-throughput operations.',
108
- inputSchema: {
109
- type: 'object',
110
- properties: {
111
- vectors: {
112
- type: 'array',
113
- items: {
114
- type: 'object',
115
- properties: {
116
- id: { type: 'string' },
117
- embedding: {
118
- type: 'array',
119
- items: { type: 'number' },
120
- },
121
- metadata: { type: 'object' },
122
- },
123
- required: ['embedding'],
124
- },
125
- description: 'Array of vectors to insert',
126
- },
127
- },
128
- required: ['vectors'],
129
- },
130
- },
131
- {
132
- name: 'agentdb_search',
133
- description: 'Perform k-nearest neighbor search to find similar vectors. Uses cosine similarity by default with optional query caching.',
134
- inputSchema: {
135
- type: 'object',
136
- properties: {
137
- queryEmbedding: {
138
- type: 'array',
139
- items: { type: 'number' },
140
- description: 'Query vector embedding',
141
- },
142
- k: {
143
- type: 'number',
144
- description: 'Number of nearest neighbors to return',
145
- minimum: 1,
146
- maximum: 1000,
147
- default: 5,
148
- },
149
- metric: {
150
- type: 'string',
151
- enum: ['cosine', 'euclidean', 'dot'],
152
- description: 'Similarity metric',
153
- default: 'cosine',
154
- },
155
- threshold: {
156
- type: 'number',
157
- description: 'Minimum similarity threshold',
158
- minimum: 0,
159
- maximum: 1,
160
- default: 0.0,
161
- },
162
- },
163
- required: ['queryEmbedding'],
164
- },
165
- },
166
- {
167
- name: 'agentdb_delete',
168
- description: 'Delete a vector by ID from the database.',
169
- inputSchema: {
170
- type: 'object',
171
- properties: {
172
- id: {
173
- type: 'string',
174
- description: 'Vector ID to delete',
175
- },
176
- },
177
- required: ['id'],
178
- },
179
- },
180
- {
181
- name: 'agentdb_stats',
182
- description: 'Get comprehensive database statistics including vector count, cache stats, and compression metrics.',
183
- inputSchema: {
184
- type: 'object',
185
- properties: {},
186
- },
187
- },
188
- {
189
- name: 'agentdb_pattern_store',
190
- description: 'Store a reasoning pattern in ReasoningBank for future retrieval and learning.',
191
- inputSchema: {
192
- type: 'object',
193
- properties: {
194
- pattern: {
195
- type: 'object',
196
- properties: {
197
- embedding: {
198
- type: 'array',
199
- items: { type: 'number' },
200
- description: 'Pattern embedding vector',
201
- },
202
- taskType: {
203
- type: 'string',
204
- description: 'Type of task this pattern applies to',
205
- },
206
- approach: {
207
- type: 'string',
208
- description: 'Approach or solution strategy',
209
- },
210
- successRate: {
211
- type: 'number',
212
- description: 'Success rate (0-1)',
213
- minimum: 0,
214
- maximum: 1,
215
- },
216
- avgDuration: {
217
- type: 'number',
218
- description: 'Average execution duration in milliseconds',
219
- minimum: 0,
220
- },
221
- metadata: {
222
- type: 'object',
223
- properties: {
224
- domain: { type: 'string' },
225
- complexity: {
226
- type: 'string',
227
- enum: ['simple', 'medium', 'complex'],
228
- },
229
- learningSource: {
230
- type: 'string',
231
- enum: ['success', 'failure', 'adaptation'],
232
- },
233
- tags: {
234
- type: 'array',
235
- items: { type: 'string' },
236
- },
237
- },
238
- required: ['domain', 'complexity', 'learningSource', 'tags'],
239
- },
240
- },
241
- required: ['embedding', 'taskType', 'approach', 'successRate', 'avgDuration', 'metadata'],
242
- },
243
- },
244
- required: ['pattern'],
245
- },
246
- },
247
- {
248
- name: 'agentdb_pattern_search',
249
- description: 'Search for similar reasoning patterns in ReasoningBank based on task embedding.',
250
- inputSchema: {
251
- type: 'object',
252
- properties: {
253
- taskEmbedding: {
254
- type: 'array',
255
- items: { type: 'number' },
256
- description: 'Task embedding to find similar patterns for',
257
- },
258
- k: {
259
- type: 'number',
260
- description: 'Number of similar patterns to return',
261
- minimum: 1,
262
- maximum: 50,
263
- default: 5,
264
- },
265
- threshold: {
266
- type: 'number',
267
- description: 'Minimum similarity threshold',
268
- minimum: 0,
269
- maximum: 1,
270
- default: 0.7,
271
- },
272
- filters: {
273
- type: 'object',
274
- properties: {
275
- domain: { type: 'string' },
276
- taskType: { type: 'string' },
277
- minSuccessRate: { type: 'number' },
278
- },
279
- },
280
- },
281
- required: ['taskEmbedding'],
282
- },
283
- },
284
- {
285
- name: 'agentdb_pattern_stats',
286
- description: 'Get statistics about stored reasoning patterns in ReasoningBank.',
287
- inputSchema: {
288
- type: 'object',
289
- properties: {},
290
- },
291
- },
292
- {
293
- name: 'agentdb_clear_cache',
294
- description: 'Clear the query cache to free memory or force fresh queries.',
295
- inputSchema: {
296
- type: 'object',
297
- properties: {},
298
- },
299
- },
300
- // Learning tools - will be dynamically added
301
- ];
302
- // Helper function to merge learning tools
303
- function getAllTools() {
304
- return [...tools];
305
- }
306
- // ============================================================================
307
- // Database Registry
308
- // ============================================================================
309
- class AgentDBRegistry {
310
- constructor() {
311
- this.db = null;
312
- this.patternMatcher = null;
313
- this.learningManager = null;
314
- this.config = null;
315
- }
316
- async getOrCreate(config = {}) {
317
- if (!this.db) {
318
- // Set default config
319
- const dbConfig = {
320
- path: config.path,
321
- memoryMode: config.memoryMode ?? (!config.path),
322
- backend: config.backend === 'wasm' ? BackendType.WASM : BackendType.NATIVE,
323
- queryCache: {
324
- enabled: config.enableQueryCache ?? true,
325
- },
326
- quantization: config.enableQuantization ? {
327
- enabled: true,
328
- dimensions: 768, // Default, will be updated
329
- subvectors: 8,
330
- bits: 8,
331
- } : undefined,
332
- };
333
- this.db = new SQLiteVectorDB(dbConfig);
334
- this.config = dbConfig;
335
- // Initialize async if WASM backend
336
- if (dbConfig.backend === BackendType.WASM) {
337
- await this.db.initializeAsync();
338
- }
339
- // Initialize PatternMatcher for ReasoningBank
340
- if (dbConfig.backend === BackendType.NATIVE) {
341
- this.patternMatcher = new PatternMatcher(this.db);
342
- }
343
- }
344
- return this.db;
345
- }
346
- get() {
347
- return this.db;
348
- }
349
- getPatternMatcher() {
350
- return this.patternMatcher;
351
- }
352
- getLearningManager() {
353
- return this.learningManager;
354
- }
355
- getOrCreateLearningManager() {
356
- if (!this.learningManager) {
357
- if (!this.db) {
358
- throw new Error('Database must be initialized before learning manager');
359
- }
360
- this.learningManager = new LearningManager(this.db);
361
- }
362
- return this.learningManager;
363
- }
364
- close() {
365
- if (this.db) {
366
- this.db.close();
367
- this.db = null;
368
- this.patternMatcher = null;
369
- }
370
- }
371
- }
372
- // ============================================================================
373
- // Resource Handler
374
- // ============================================================================
375
- class ResourceHandler {
376
- constructor(registry) {
377
- this.registry = registry;
378
- }
379
- async listResources() {
380
- return {
381
- resources: [
382
- {
383
- uri: 'agentdb://stats',
384
- name: 'Database Statistics',
385
- description: 'Current AgentDB statistics and metrics',
386
- mimeType: 'application/json',
387
- },
388
- {
389
- uri: 'agentdb://cache-stats',
390
- name: 'Query Cache Statistics',
391
- description: 'Query cache hit rates and performance metrics',
392
- mimeType: 'application/json',
393
- },
394
- {
395
- uri: 'agentdb://pattern-stats',
396
- name: 'ReasoningBank Pattern Statistics',
397
- description: 'Statistics about stored reasoning patterns',
398
- mimeType: 'application/json',
399
- },
400
- ],
401
- };
402
- }
403
- async readResource(uri) {
404
- const db = this.registry.get();
405
- if (!db) {
406
- throw new Error('Database not initialized. Call agentdb_init first.');
407
- }
408
- switch (uri) {
409
- case 'agentdb://stats': {
410
- const stats = db.stats();
411
- return {
412
- contents: [
413
- {
414
- uri,
415
- mimeType: 'application/json',
416
- text: JSON.stringify(stats, null, 2),
417
- },
418
- ],
419
- };
420
- }
421
- case 'agentdb://cache-stats': {
422
- const cacheStats = db.getCacheStats();
423
- return {
424
- contents: [
425
- {
426
- uri,
427
- mimeType: 'application/json',
428
- text: JSON.stringify(cacheStats || { message: 'Cache not enabled' }, null, 2),
429
- },
430
- ],
431
- };
432
- }
433
- case 'agentdb://pattern-stats': {
434
- const patternMatcher = this.registry.getPatternMatcher();
435
- if (!patternMatcher) {
436
- throw new Error('PatternMatcher not available (WASM backend or not initialized)');
437
- }
438
- const patternStats = patternMatcher.getStats();
439
- return {
440
- contents: [
441
- {
442
- uri,
443
- mimeType: 'application/json',
444
- text: JSON.stringify({
445
- totalPatterns: patternStats.totalPatterns,
446
- avgSuccessRate: patternStats.avgSuccessRate,
447
- domainDistribution: Object.fromEntries(patternStats.domainDistribution),
448
- topPatterns: patternStats.topPatterns,
449
- }, null, 2),
450
- },
451
- ],
452
- };
453
- }
454
- default:
455
- throw new Error(`Unknown resource: ${uri}`);
456
- }
457
- }
458
- }
459
- // ============================================================================
460
- // Main MCP Server
461
- // ============================================================================
462
- export class AgentDBMCPServer {
463
- constructor() {
464
- this.learningTools = null;
465
- this.registry = new AgentDBRegistry();
466
- this.resourceHandler = new ResourceHandler(this.registry);
467
- // Initialize learning tools immediately so they show in tools list
468
- // Learning tools work independently of the main database
469
- const tempDb = new SQLiteVectorDB({ memoryMode: true });
470
- const learningManager = new LearningManager(tempDb);
471
- this.learningTools = new MCPLearningTools(learningManager);
472
- this.server = new Server({
473
- name: 'agentdb-mcp',
474
- version: '1.0.3',
475
- }, {
476
- capabilities: {
477
- tools: {},
478
- resources: {},
479
- },
480
- });
481
- this.setupHandlers();
482
- this.setupErrorHandlers();
483
- }
484
- setupHandlers() {
485
- // List available tools
486
- this.server.setRequestHandler(ListToolsRequestSchema, async () => {
487
- const allTools = [...tools];
488
- // Add learning tools if learning manager is available
489
- if (this.learningTools) {
490
- const learningToolDefs = this.learningTools.getToolDefinitions();
491
- for (const [name, def] of Object.entries(learningToolDefs)) {
492
- allTools.push({
493
- name,
494
- description: def.description,
495
- inputSchema: def.inputSchema,
496
- });
497
- }
498
- }
499
- return { tools: allTools };
500
- });
501
- // List available resources
502
- this.server.setRequestHandler(ListResourcesRequestSchema, async () => this.resourceHandler.listResources());
503
- // Read resource
504
- this.server.setRequestHandler(ReadResourceRequestSchema, async (request) => this.resourceHandler.readResource(request.params.uri));
505
- // Handle tool calls
506
- this.server.setRequestHandler(CallToolRequestSchema, async (request) => {
507
- const { name, arguments: args } = request.params;
508
- try {
509
- switch (name) {
510
- case 'agentdb_init':
511
- return await this.handleInit(args);
512
- case 'agentdb_insert':
513
- return await this.handleInsert(args);
514
- case 'agentdb_insert_batch':
515
- return await this.handleInsertBatch(args);
516
- case 'agentdb_search':
517
- return await this.handleSearch(args);
518
- case 'agentdb_delete':
519
- return await this.handleDelete(args);
520
- case 'agentdb_stats':
521
- return await this.handleStats(args);
522
- case 'agentdb_pattern_store':
523
- return await this.handlePatternStore(args);
524
- case 'agentdb_pattern_search':
525
- return await this.handlePatternSearch(args);
526
- case 'agentdb_pattern_stats':
527
- return await this.handlePatternStats(args);
528
- case 'agentdb_clear_cache':
529
- return await this.handleClearCache(args);
530
- // Learning tools
531
- case 'learning_start_session':
532
- case 'learning_end_session':
533
- case 'learning_predict':
534
- case 'learning_feedback':
535
- case 'learning_train':
536
- case 'learning_metrics':
537
- case 'learning_transfer':
538
- case 'learning_explain':
539
- case 'experience_record':
540
- case 'reward_signal':
541
- return await this.handleLearningTool(name, args);
542
- default:
543
- throw new Error(`Unknown tool: ${name}`);
544
- }
545
- }
546
- catch (error) {
547
- const errorMessage = error instanceof Error ? error.message : 'Unknown error';
548
- return {
549
- content: [
550
- {
551
- type: 'text',
552
- text: JSON.stringify({
553
- error: errorMessage,
554
- tool: name,
555
- timestamp: Date.now(),
556
- }, null, 2),
557
- },
558
- ],
559
- isError: true,
560
- };
561
- }
562
- });
563
- }
564
- setupErrorHandlers() {
565
- this.server.onerror = (error) => {
566
- console.error('[AgentDB MCP Error]', error);
567
- };
568
- process.on('SIGINT', async () => {
569
- await this.cleanup();
570
- process.exit(0);
571
- });
572
- process.on('SIGTERM', async () => {
573
- await this.cleanup();
574
- process.exit(0);
575
- });
576
- }
577
- // ============================================================================
578
- // Tool Handlers
579
- // ============================================================================
580
- async handleInit(args) {
581
- const db = await this.registry.getOrCreate(args);
582
- // Learning tools already initialized in constructor
583
- // Just use the registry's learning manager for database operations
584
- this.registry.getOrCreateLearningManager();
585
- return {
586
- content: [
587
- {
588
- type: 'text',
589
- text: JSON.stringify({
590
- success: true,
591
- message: 'AgentDB initialized successfully with learning capabilities',
592
- backend: db.getBackendType(),
593
- config: {
594
- path: args.path || 'in-memory',
595
- memoryMode: args.memoryMode ?? true,
596
- queryCache: args.enableQueryCache ?? true,
597
- quantization: args.enableQuantization ?? false,
598
- },
599
- learningEnabled: true,
600
- }, null, 2),
601
- },
602
- ],
603
- };
604
- }
605
- async handleInsert(args) {
606
- const db = this.registry.get();
607
- if (!db) {
608
- throw new Error('Database not initialized. Call agentdb_init first.');
609
- }
610
- const vector = VectorSchema.parse(args.vector);
611
- const id = db.insert(vector);
612
- return {
613
- content: [
614
- {
615
- type: 'text',
616
- text: JSON.stringify({
617
- success: true,
618
- id,
619
- message: 'Vector inserted successfully',
620
- }, null, 2),
621
- },
622
- ],
623
- };
624
- }
625
- async handleInsertBatch(args) {
626
- const db = this.registry.get();
627
- if (!db) {
628
- throw new Error('Database not initialized. Call agentdb_init first.');
629
- }
630
- const vectors = z.array(VectorSchema).parse(args.vectors);
631
- const ids = db.insertBatch(vectors);
632
- return {
633
- content: [
634
- {
635
- type: 'text',
636
- text: JSON.stringify({
637
- success: true,
638
- inserted: ids.length,
639
- ids,
640
- message: `${ids.length} vectors inserted successfully`,
641
- }, null, 2),
642
- },
643
- ],
644
- };
645
- }
646
- async handleSearch(args) {
647
- const db = this.registry.get();
648
- if (!db) {
649
- throw new Error('Database not initialized. Call agentdb_init first.');
650
- }
651
- const { queryEmbedding, k = 5, metric = 'cosine', threshold = 0.0 } = args;
652
- const results = db.search(queryEmbedding, k, metric, threshold);
653
- return {
654
- content: [
655
- {
656
- type: 'text',
657
- text: JSON.stringify({
658
- success: true,
659
- results,
660
- count: results.length,
661
- message: `Found ${results.length} similar vectors`,
662
- }, null, 2),
663
- },
664
- ],
665
- };
666
- }
667
- async handleDelete(args) {
668
- const db = this.registry.get();
669
- if (!db) {
670
- throw new Error('Database not initialized. Call agentdb_init first.');
671
- }
672
- const success = db.delete(args.id);
673
- return {
674
- content: [
675
- {
676
- type: 'text',
677
- text: JSON.stringify({
678
- success,
679
- id: args.id,
680
- message: success ? 'Vector deleted successfully' : 'Vector not found',
681
- }, null, 2),
682
- },
683
- ],
684
- };
685
- }
686
- async handleStats(args) {
687
- const db = this.registry.get();
688
- if (!db) {
689
- throw new Error('Database not initialized. Call agentdb_init first.');
690
- }
691
- const stats = db.stats();
692
- const cacheStats = db.getCacheStats();
693
- const compressionStats = db.getCompressionStats();
694
- return {
695
- content: [
696
- {
697
- type: 'text',
698
- text: JSON.stringify({
699
- success: true,
700
- stats: {
701
- vectors: stats,
702
- cache: cacheStats || { enabled: false },
703
- compression: compressionStats || { enabled: false },
704
- },
705
- message: 'Statistics retrieved successfully',
706
- }, null, 2),
707
- },
708
- ],
709
- };
710
- }
711
- async handlePatternStore(args) {
712
- const patternMatcher = this.registry.getPatternMatcher();
713
- if (!patternMatcher) {
714
- throw new Error('PatternMatcher not available (WASM backend or not initialized)');
715
- }
716
- const pattern = PatternSchema.parse(args.pattern);
717
- // Add default iterations field required by PatternMetadata
718
- const patternWithIterations = {
719
- ...pattern,
720
- metadata: {
721
- ...pattern.metadata,
722
- iterations: 1, // Initial iteration count
723
- },
724
- };
725
- const id = await patternMatcher.storePattern(patternWithIterations);
726
- return {
727
- content: [
728
- {
729
- type: 'text',
730
- text: JSON.stringify({
731
- success: true,
732
- id,
733
- message: 'Reasoning pattern stored successfully',
734
- }, null, 2),
735
- },
736
- ],
737
- };
738
- }
739
- async handlePatternSearch(args) {
740
- const patternMatcher = this.registry.getPatternMatcher();
741
- if (!patternMatcher) {
742
- throw new Error('PatternMatcher not available (WASM backend or not initialized)');
743
- }
744
- const { taskEmbedding, k = 5, threshold = 0.7, filters } = args;
745
- const patterns = await patternMatcher.findSimilar(taskEmbedding, k, threshold, filters);
746
- return {
747
- content: [
748
- {
749
- type: 'text',
750
- text: JSON.stringify({
751
- success: true,
752
- patterns: patterns.map((p) => ({
753
- id: p.id,
754
- taskType: p.taskType,
755
- approach: p.approach,
756
- successRate: p.successRate,
757
- avgDuration: p.avgDuration,
758
- similarity: p.similarity,
759
- metadata: p.metadata,
760
- })),
761
- count: patterns.length,
762
- message: `Found ${patterns.length} similar patterns`,
763
- }, null, 2),
764
- },
765
- ],
766
- };
767
- }
768
- async handlePatternStats(args) {
769
- const patternMatcher = this.registry.getPatternMatcher();
770
- if (!patternMatcher) {
771
- throw new Error('PatternMatcher not available (WASM backend or not initialized)');
772
- }
773
- const stats = patternMatcher.getStats();
774
- return {
775
- content: [
776
- {
777
- type: 'text',
778
- text: JSON.stringify({
779
- success: true,
780
- stats: {
781
- totalPatterns: stats.totalPatterns,
782
- avgSuccessRate: stats.avgSuccessRate,
783
- domainDistribution: Object.fromEntries(stats.domainDistribution),
784
- topPatterns: stats.topPatterns,
785
- },
786
- message: 'Pattern statistics retrieved successfully',
787
- }, null, 2),
788
- },
789
- ],
790
- };
791
- }
792
- async handleClearCache(args) {
793
- const db = this.registry.get();
794
- if (!db) {
795
- throw new Error('Database not initialized. Call agentdb_init first.');
796
- }
797
- db.clearCache();
798
- return {
799
- content: [
800
- {
801
- type: 'text',
802
- text: JSON.stringify({
803
- success: true,
804
- message: 'Query cache cleared successfully',
805
- }, null, 2),
806
- },
807
- ],
808
- };
809
- }
810
- async handleLearningTool(toolName, args) {
811
- if (!this.learningTools) {
812
- throw new Error('Learning tools not initialized. Call agentdb_init first.');
813
- }
814
- const result = await this.learningTools.handleToolCall(toolName, args);
815
- return {
816
- content: [
817
- {
818
- type: 'text',
819
- text: JSON.stringify({
820
- success: true,
821
- tool: toolName,
822
- result,
823
- timestamp: Date.now(),
824
- }, null, 2),
825
- },
826
- ],
827
- };
828
- }
829
- async start() {
830
- const transport = new StdioServerTransport();
831
- await this.server.connect(transport);
832
- console.error('AgentDB MCP Server started');
833
- }
834
- async cleanup() {
835
- console.error('Shutting down AgentDB MCP Server...');
836
- this.registry.close();
837
- await this.server.close();
838
- }
839
- }
840
- // ============================================================================
841
- // Entry Point
842
- // ============================================================================
843
- async function main() {
844
- const server = new AgentDBMCPServer();
845
- try {
846
- await server.start();
847
- }
848
- catch (error) {
849
- console.error('Failed to start AgentDB MCP Server:', error);
850
- process.exit(1);
851
- }
852
- }
853
- // Only run if this is the main module
854
- // Note: This check works in ESM modules. For CommonJS, check require.main === module
855
- if (typeof require !== 'undefined' && require.main === module) {
856
- main();
857
- }