@weavelogic/knowledge-graph-agent 0.2.0 → 0.3.0

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 (585) hide show
  1. package/README.md +686 -304
  2. package/dist/_virtual/_commonjsHelpers.js +7 -0
  3. package/dist/_virtual/_commonjsHelpers.js.map +1 -0
  4. package/dist/_virtual/additionalItems.js +5 -0
  5. package/dist/_virtual/additionalItems.js.map +1 -0
  6. package/dist/_virtual/additionalProperties.js +5 -0
  7. package/dist/_virtual/additionalProperties.js.map +1 -0
  8. package/dist/_virtual/ajv.js +6 -0
  9. package/dist/_virtual/ajv.js.map +1 -0
  10. package/dist/_virtual/ajv2.js +5 -0
  11. package/dist/_virtual/ajv2.js.map +1 -0
  12. package/dist/_virtual/allOf.js +5 -0
  13. package/dist/_virtual/allOf.js.map +1 -0
  14. package/dist/_virtual/anyOf.js +5 -0
  15. package/dist/_virtual/anyOf.js.map +1 -0
  16. package/dist/_virtual/applicability.js +5 -0
  17. package/dist/_virtual/applicability.js.map +1 -0
  18. package/dist/_virtual/boolSchema.js +5 -0
  19. package/dist/_virtual/boolSchema.js.map +1 -0
  20. package/dist/_virtual/code.js +5 -0
  21. package/dist/_virtual/code.js.map +1 -0
  22. package/dist/_virtual/code2.js +5 -0
  23. package/dist/_virtual/code2.js.map +1 -0
  24. package/dist/_virtual/const.js +5 -0
  25. package/dist/_virtual/const.js.map +1 -0
  26. package/dist/_virtual/contains.js +5 -0
  27. package/dist/_virtual/contains.js.map +1 -0
  28. package/dist/_virtual/core.js +5 -0
  29. package/dist/_virtual/core.js.map +1 -0
  30. package/dist/_virtual/dataType.js +5 -0
  31. package/dist/_virtual/dataType.js.map +1 -0
  32. package/dist/_virtual/defaults.js +5 -0
  33. package/dist/_virtual/defaults.js.map +1 -0
  34. package/dist/_virtual/dependencies.js +5 -0
  35. package/dist/_virtual/dependencies.js.map +1 -0
  36. package/dist/_virtual/draft7.js +5 -0
  37. package/dist/_virtual/draft7.js.map +1 -0
  38. package/dist/_virtual/enum.js +5 -0
  39. package/dist/_virtual/enum.js.map +1 -0
  40. package/dist/_virtual/equal.js +5 -0
  41. package/dist/_virtual/equal.js.map +1 -0
  42. package/dist/_virtual/errors.js +5 -0
  43. package/dist/_virtual/errors.js.map +1 -0
  44. package/dist/_virtual/format.js +5 -0
  45. package/dist/_virtual/format.js.map +1 -0
  46. package/dist/_virtual/formats.js +5 -0
  47. package/dist/_virtual/formats.js.map +1 -0
  48. package/dist/_virtual/id.js +5 -0
  49. package/dist/_virtual/id.js.map +1 -0
  50. package/dist/_virtual/if.js +5 -0
  51. package/dist/_virtual/if.js.map +1 -0
  52. package/dist/_virtual/index.js +8 -0
  53. package/dist/_virtual/index.js.map +1 -0
  54. package/dist/_virtual/index10.js +5 -0
  55. package/dist/_virtual/index10.js.map +1 -0
  56. package/dist/_virtual/index11.js +5 -0
  57. package/dist/_virtual/index11.js.map +1 -0
  58. package/dist/_virtual/index12.js +5 -0
  59. package/dist/_virtual/index12.js.map +1 -0
  60. package/dist/_virtual/index2.js +5 -0
  61. package/dist/_virtual/index2.js.map +1 -0
  62. package/dist/_virtual/index3.js +5 -0
  63. package/dist/_virtual/index3.js.map +1 -0
  64. package/dist/_virtual/index4.js +5 -0
  65. package/dist/_virtual/index4.js.map +1 -0
  66. package/dist/_virtual/index5.js +5 -0
  67. package/dist/_virtual/index5.js.map +1 -0
  68. package/dist/_virtual/index6.js +5 -0
  69. package/dist/_virtual/index6.js.map +1 -0
  70. package/dist/_virtual/index7.js +5 -0
  71. package/dist/_virtual/index7.js.map +1 -0
  72. package/dist/_virtual/index8.js +5 -0
  73. package/dist/_virtual/index8.js.map +1 -0
  74. package/dist/_virtual/index9.js +5 -0
  75. package/dist/_virtual/index9.js.map +1 -0
  76. package/dist/_virtual/items.js +5 -0
  77. package/dist/_virtual/items.js.map +1 -0
  78. package/dist/_virtual/items2020.js +5 -0
  79. package/dist/_virtual/items2020.js.map +1 -0
  80. package/dist/_virtual/keyword.js +5 -0
  81. package/dist/_virtual/keyword.js.map +1 -0
  82. package/dist/_virtual/limit.js +5 -0
  83. package/dist/_virtual/limit.js.map +1 -0
  84. package/dist/_virtual/limitItems.js +5 -0
  85. package/dist/_virtual/limitItems.js.map +1 -0
  86. package/dist/_virtual/limitLength.js +5 -0
  87. package/dist/_virtual/limitLength.js.map +1 -0
  88. package/dist/_virtual/limitNumber.js +5 -0
  89. package/dist/_virtual/limitNumber.js.map +1 -0
  90. package/dist/_virtual/limitProperties.js +5 -0
  91. package/dist/_virtual/limitProperties.js.map +1 -0
  92. package/dist/_virtual/metadata.js +5 -0
  93. package/dist/_virtual/metadata.js.map +1 -0
  94. package/dist/_virtual/multipleOf.js +5 -0
  95. package/dist/_virtual/multipleOf.js.map +1 -0
  96. package/dist/_virtual/names.js +5 -0
  97. package/dist/_virtual/names.js.map +1 -0
  98. package/dist/_virtual/not.js +5 -0
  99. package/dist/_virtual/not.js.map +1 -0
  100. package/dist/_virtual/oneOf.js +5 -0
  101. package/dist/_virtual/oneOf.js.map +1 -0
  102. package/dist/_virtual/pattern.js +5 -0
  103. package/dist/_virtual/pattern.js.map +1 -0
  104. package/dist/_virtual/patternProperties.js +5 -0
  105. package/dist/_virtual/patternProperties.js.map +1 -0
  106. package/dist/_virtual/prefixItems.js +5 -0
  107. package/dist/_virtual/prefixItems.js.map +1 -0
  108. package/dist/_virtual/properties.js +5 -0
  109. package/dist/_virtual/properties.js.map +1 -0
  110. package/dist/_virtual/propertyNames.js +5 -0
  111. package/dist/_virtual/propertyNames.js.map +1 -0
  112. package/dist/_virtual/ref.js +5 -0
  113. package/dist/_virtual/ref.js.map +1 -0
  114. package/dist/_virtual/ref_error.js +5 -0
  115. package/dist/_virtual/ref_error.js.map +1 -0
  116. package/dist/_virtual/required.js +5 -0
  117. package/dist/_virtual/required.js.map +1 -0
  118. package/dist/_virtual/resolve.js +5 -0
  119. package/dist/_virtual/resolve.js.map +1 -0
  120. package/dist/_virtual/rules.js +5 -0
  121. package/dist/_virtual/rules.js.map +1 -0
  122. package/dist/_virtual/scope.js +5 -0
  123. package/dist/_virtual/scope.js.map +1 -0
  124. package/dist/_virtual/subschema.js +5 -0
  125. package/dist/_virtual/subschema.js.map +1 -0
  126. package/dist/_virtual/thenElse.js +5 -0
  127. package/dist/_virtual/thenElse.js.map +1 -0
  128. package/dist/_virtual/types.js +5 -0
  129. package/dist/_virtual/types.js.map +1 -0
  130. package/dist/_virtual/ucs2length.js +5 -0
  131. package/dist/_virtual/ucs2length.js.map +1 -0
  132. package/dist/_virtual/uniqueItems.js +5 -0
  133. package/dist/_virtual/uniqueItems.js.map +1 -0
  134. package/dist/_virtual/uri.js +5 -0
  135. package/dist/_virtual/uri.js.map +1 -0
  136. package/dist/_virtual/util.js +5 -0
  137. package/dist/_virtual/util.js.map +1 -0
  138. package/dist/_virtual/validation_error.js +5 -0
  139. package/dist/_virtual/validation_error.js.map +1 -0
  140. package/dist/agents/analyst-agent.d.ts +230 -0
  141. package/dist/agents/analyst-agent.d.ts.map +1 -0
  142. package/dist/agents/analyst-agent.js +793 -0
  143. package/dist/agents/analyst-agent.js.map +1 -0
  144. package/dist/agents/architect-agent.d.ts +248 -0
  145. package/dist/agents/architect-agent.d.ts.map +1 -0
  146. package/dist/agents/architect-agent.js +685 -0
  147. package/dist/agents/architect-agent.js.map +1 -0
  148. package/dist/agents/base-agent.d.ts +169 -0
  149. package/dist/agents/base-agent.d.ts.map +1 -0
  150. package/dist/agents/base-agent.js +441 -0
  151. package/dist/agents/base-agent.js.map +1 -0
  152. package/dist/agents/coder-agent.d.ts +191 -0
  153. package/dist/agents/coder-agent.d.ts.map +1 -0
  154. package/dist/agents/coder-agent.js +1008 -0
  155. package/dist/agents/coder-agent.js.map +1 -0
  156. package/dist/agents/index.d.ts +18 -0
  157. package/dist/agents/index.d.ts.map +1 -0
  158. package/dist/agents/index.js +40 -0
  159. package/dist/agents/index.js.map +1 -0
  160. package/dist/agents/registry.d.ts +213 -0
  161. package/dist/agents/registry.d.ts.map +1 -0
  162. package/dist/agents/registry.js +419 -0
  163. package/dist/agents/registry.js.map +1 -0
  164. package/dist/agents/researcher-agent.d.ts +226 -0
  165. package/dist/agents/researcher-agent.d.ts.map +1 -0
  166. package/dist/agents/researcher-agent.js +572 -0
  167. package/dist/agents/researcher-agent.js.map +1 -0
  168. package/dist/agents/rules-engine.d.ts +320 -0
  169. package/dist/agents/rules-engine.d.ts.map +1 -0
  170. package/dist/agents/rules-engine.js +552 -0
  171. package/dist/agents/rules-engine.js.map +1 -0
  172. package/dist/agents/tester-agent.d.ts +219 -0
  173. package/dist/agents/tester-agent.d.ts.map +1 -0
  174. package/dist/agents/tester-agent.js +683 -0
  175. package/dist/agents/tester-agent.js.map +1 -0
  176. package/dist/agents/types.d.ts +425 -0
  177. package/dist/agents/types.d.ts.map +1 -0
  178. package/dist/agents/types.js +57 -0
  179. package/dist/agents/types.js.map +1 -0
  180. package/dist/caching/index.d.ts +55 -0
  181. package/dist/caching/index.d.ts.map +1 -0
  182. package/dist/caching/index.js +206 -0
  183. package/dist/caching/index.js.map +1 -0
  184. package/dist/caching/lru-cache.d.ts +254 -0
  185. package/dist/caching/lru-cache.d.ts.map +1 -0
  186. package/dist/caching/types.d.ts +95 -0
  187. package/dist/caching/types.d.ts.map +1 -0
  188. package/dist/chunking/chunker.d.ts +94 -0
  189. package/dist/chunking/chunker.d.ts.map +1 -0
  190. package/dist/chunking/index.d.ts +125 -0
  191. package/dist/chunking/index.d.ts.map +1 -0
  192. package/dist/chunking/index.js +283 -0
  193. package/dist/chunking/index.js.map +1 -0
  194. package/dist/chunking/types.d.ts +92 -0
  195. package/dist/chunking/types.d.ts.map +1 -0
  196. package/dist/cli/commands/commit.d.ts +11 -0
  197. package/dist/cli/commands/commit.d.ts.map +1 -0
  198. package/dist/cli/commands/commit.js +379 -0
  199. package/dist/cli/commands/commit.js.map +1 -0
  200. package/dist/cli/commands/config.d.ts +8 -0
  201. package/dist/cli/commands/config.d.ts.map +1 -0
  202. package/dist/cli/commands/config.js +107 -0
  203. package/dist/cli/commands/config.js.map +1 -0
  204. package/dist/cli/commands/cultivate.d.ts +16 -0
  205. package/dist/cli/commands/cultivate.d.ts.map +1 -0
  206. package/dist/cli/commands/cultivate.js +254 -0
  207. package/dist/cli/commands/cultivate.js.map +1 -0
  208. package/dist/cli/commands/diagnostics.d.ts +8 -0
  209. package/dist/cli/commands/diagnostics.d.ts.map +1 -0
  210. package/dist/cli/commands/diagnostics.js +140 -0
  211. package/dist/cli/commands/diagnostics.js.map +1 -0
  212. package/dist/cli/commands/generate.d.ts +13 -0
  213. package/dist/cli/commands/generate.d.ts.map +1 -0
  214. package/dist/cli/commands/init-primitives.d.ts +19 -0
  215. package/dist/cli/commands/init-primitives.d.ts.map +1 -0
  216. package/dist/cli/commands/init-primitives.js +208 -0
  217. package/dist/cli/commands/init-primitives.js.map +1 -0
  218. package/dist/cli/commands/sop.d.ts +14 -0
  219. package/dist/cli/commands/sop.d.ts.map +1 -0
  220. package/dist/cli/commands/sop.js +598 -0
  221. package/dist/cli/commands/sop.js.map +1 -0
  222. package/dist/cli/index.d.ts.map +1 -1
  223. package/dist/cli/index.js +40 -1
  224. package/dist/cli/index.js.map +1 -1
  225. package/dist/config/index.d.ts +153 -0
  226. package/dist/config/index.d.ts.map +1 -0
  227. package/dist/config/index.js +141 -0
  228. package/dist/config/index.js.map +1 -0
  229. package/dist/config/manager.d.ts +136 -0
  230. package/dist/config/manager.d.ts.map +1 -0
  231. package/dist/config/types.d.ts +127 -0
  232. package/dist/config/types.d.ts.map +1 -0
  233. package/dist/core/cache.d.ts +185 -0
  234. package/dist/core/cache.d.ts.map +1 -0
  235. package/dist/core/cache.js +435 -0
  236. package/dist/core/cache.js.map +1 -0
  237. package/dist/cultivation/deep-analyzer.d.ts +129 -0
  238. package/dist/cultivation/deep-analyzer.d.ts.map +1 -0
  239. package/dist/cultivation/deep-analyzer.js +322 -0
  240. package/dist/cultivation/deep-analyzer.js.map +1 -0
  241. package/dist/cultivation/index.d.ts +13 -0
  242. package/dist/cultivation/index.d.ts.map +1 -0
  243. package/dist/cultivation/seed-generator.d.ts +92 -0
  244. package/dist/cultivation/seed-generator.d.ts.map +1 -0
  245. package/dist/cultivation/seed-generator.js +1033 -0
  246. package/dist/cultivation/seed-generator.js.map +1 -0
  247. package/dist/cultivation/types.d.ts +230 -0
  248. package/dist/cultivation/types.d.ts.map +1 -0
  249. package/dist/generators/claude-md.d.ts +7 -0
  250. package/dist/generators/claude-md.d.ts.map +1 -1
  251. package/dist/generators/claude-md.js.map +1 -1
  252. package/dist/generators/docs-init.d.ts +6 -0
  253. package/dist/generators/docs-init.d.ts.map +1 -1
  254. package/dist/generators/docs-init.js.map +1 -1
  255. package/dist/health/checks.d.ts +135 -0
  256. package/dist/health/checks.d.ts.map +1 -0
  257. package/dist/health/index.d.ts +119 -0
  258. package/dist/health/index.d.ts.map +1 -0
  259. package/dist/health/index.js +191 -0
  260. package/dist/health/index.js.map +1 -0
  261. package/dist/health/monitor.d.ts +146 -0
  262. package/dist/health/monitor.d.ts.map +1 -0
  263. package/dist/health/types.d.ts +135 -0
  264. package/dist/health/types.d.ts.map +1 -0
  265. package/dist/index.d.ts +30 -0
  266. package/dist/index.d.ts.map +1 -1
  267. package/dist/index.js +173 -1
  268. package/dist/index.js.map +1 -1
  269. package/dist/integrations/auto-commit.d.ts +175 -0
  270. package/dist/integrations/auto-commit.d.ts.map +1 -0
  271. package/dist/integrations/auto-commit.js +399 -0
  272. package/dist/integrations/auto-commit.js.map +1 -0
  273. package/dist/integrations/git.d.ts +299 -0
  274. package/dist/integrations/git.d.ts.map +1 -0
  275. package/dist/integrations/git.js +465 -0
  276. package/dist/integrations/git.js.map +1 -0
  277. package/dist/mcp-server/bin.d.ts +11 -0
  278. package/dist/mcp-server/bin.d.ts.map +1 -0
  279. package/dist/mcp-server/handlers/index.d.ts +57 -0
  280. package/dist/mcp-server/handlers/index.d.ts.map +1 -0
  281. package/dist/mcp-server/handlers/index.js +235 -0
  282. package/dist/mcp-server/handlers/index.js.map +1 -0
  283. package/dist/mcp-server/index.d.ts +28 -0
  284. package/dist/mcp-server/index.d.ts.map +1 -0
  285. package/dist/mcp-server/server.d.ts +133 -0
  286. package/dist/mcp-server/server.d.ts.map +1 -0
  287. package/dist/mcp-server/server.js +280 -0
  288. package/dist/mcp-server/server.js.map +1 -0
  289. package/dist/mcp-server/tools/agents/index.d.ts +10 -0
  290. package/dist/mcp-server/tools/agents/index.d.ts.map +1 -0
  291. package/dist/mcp-server/tools/agents/list.d.ts +19 -0
  292. package/dist/mcp-server/tools/agents/list.d.ts.map +1 -0
  293. package/dist/mcp-server/tools/agents/spawn.d.ts +19 -0
  294. package/dist/mcp-server/tools/agents/spawn.d.ts.map +1 -0
  295. package/dist/mcp-server/tools/graph/generate.d.ts +21 -0
  296. package/dist/mcp-server/tools/graph/generate.d.ts.map +1 -0
  297. package/dist/mcp-server/tools/graph/index.d.ts +11 -0
  298. package/dist/mcp-server/tools/graph/index.d.ts.map +1 -0
  299. package/dist/mcp-server/tools/graph/query.d.ts +22 -0
  300. package/dist/mcp-server/tools/graph/query.d.ts.map +1 -0
  301. package/dist/mcp-server/tools/graph/stats.d.ts +22 -0
  302. package/dist/mcp-server/tools/graph/stats.d.ts.map +1 -0
  303. package/dist/mcp-server/tools/health.d.ts +21 -0
  304. package/dist/mcp-server/tools/health.d.ts.map +1 -0
  305. package/dist/mcp-server/tools/index.d.ts +13 -0
  306. package/dist/mcp-server/tools/index.d.ts.map +1 -0
  307. package/dist/mcp-server/tools/registry.d.ts +90 -0
  308. package/dist/mcp-server/tools/registry.d.ts.map +1 -0
  309. package/dist/mcp-server/tools/registry.js +663 -0
  310. package/dist/mcp-server/tools/registry.js.map +1 -0
  311. package/dist/mcp-server/tools/search/index.d.ts +10 -0
  312. package/dist/mcp-server/tools/search/index.d.ts.map +1 -0
  313. package/dist/mcp-server/tools/search/nodes.d.ts +22 -0
  314. package/dist/mcp-server/tools/search/nodes.d.ts.map +1 -0
  315. package/dist/mcp-server/tools/search/tags.d.ts +22 -0
  316. package/dist/mcp-server/tools/search/tags.d.ts.map +1 -0
  317. package/dist/mcp-server/types/index.d.ts +286 -0
  318. package/dist/mcp-server/types/index.d.ts.map +1 -0
  319. package/dist/memory/index.d.ts +10 -0
  320. package/dist/memory/index.d.ts.map +1 -0
  321. package/dist/memory/vault-sync.d.ts +212 -0
  322. package/dist/memory/vault-sync.d.ts.map +1 -0
  323. package/dist/memory/vault-sync.js +463 -0
  324. package/dist/memory/vault-sync.js.map +1 -0
  325. package/dist/node_modules/@modelcontextprotocol/sdk/dist/esm/server/index.js +296 -0
  326. package/dist/node_modules/@modelcontextprotocol/sdk/dist/esm/server/index.js.map +1 -0
  327. package/dist/node_modules/@modelcontextprotocol/sdk/dist/esm/server/zod-compat.js +71 -0
  328. package/dist/node_modules/@modelcontextprotocol/sdk/dist/esm/server/zod-compat.js.map +1 -0
  329. package/dist/node_modules/@modelcontextprotocol/sdk/dist/esm/server/zod-json-schema-compat.js +26 -0
  330. package/dist/node_modules/@modelcontextprotocol/sdk/dist/esm/server/zod-json-schema-compat.js.map +1 -0
  331. package/dist/node_modules/@modelcontextprotocol/sdk/dist/esm/shared/protocol.js +407 -0
  332. package/dist/node_modules/@modelcontextprotocol/sdk/dist/esm/shared/protocol.js.map +1 -0
  333. package/dist/node_modules/@modelcontextprotocol/sdk/dist/esm/types.js +1332 -0
  334. package/dist/node_modules/@modelcontextprotocol/sdk/dist/esm/types.js.map +1 -0
  335. package/dist/node_modules/@modelcontextprotocol/sdk/dist/esm/validation/ajv-provider.js +71 -0
  336. package/dist/node_modules/@modelcontextprotocol/sdk/dist/esm/validation/ajv-provider.js.map +1 -0
  337. package/dist/node_modules/ajv/dist/ajv.js +84 -0
  338. package/dist/node_modules/ajv/dist/ajv.js.map +1 -0
  339. package/dist/node_modules/ajv/dist/compile/codegen/code.js +160 -0
  340. package/dist/node_modules/ajv/dist/compile/codegen/code.js.map +1 -0
  341. package/dist/node_modules/ajv/dist/compile/codegen/index.js +728 -0
  342. package/dist/node_modules/ajv/dist/compile/codegen/index.js.map +1 -0
  343. package/dist/node_modules/ajv/dist/compile/codegen/scope.js +152 -0
  344. package/dist/node_modules/ajv/dist/compile/codegen/scope.js.map +1 -0
  345. package/dist/node_modules/ajv/dist/compile/errors.js +131 -0
  346. package/dist/node_modules/ajv/dist/compile/errors.js.map +1 -0
  347. package/dist/node_modules/ajv/dist/compile/index.js +234 -0
  348. package/dist/node_modules/ajv/dist/compile/index.js.map +1 -0
  349. package/dist/node_modules/ajv/dist/compile/names.js +44 -0
  350. package/dist/node_modules/ajv/dist/compile/names.js.map +1 -0
  351. package/dist/node_modules/ajv/dist/compile/ref_error.js +22 -0
  352. package/dist/node_modules/ajv/dist/compile/ref_error.js.map +1 -0
  353. package/dist/node_modules/ajv/dist/compile/resolve.js +163 -0
  354. package/dist/node_modules/ajv/dist/compile/resolve.js.map +1 -0
  355. package/dist/node_modules/ajv/dist/compile/rules.js +35 -0
  356. package/dist/node_modules/ajv/dist/compile/rules.js.map +1 -0
  357. package/dist/node_modules/ajv/dist/compile/util.js +173 -0
  358. package/dist/node_modules/ajv/dist/compile/util.js.map +1 -0
  359. package/dist/node_modules/ajv/dist/compile/validate/applicability.js +27 -0
  360. package/dist/node_modules/ajv/dist/compile/validate/applicability.js.map +1 -0
  361. package/dist/node_modules/ajv/dist/compile/validate/boolSchema.js +58 -0
  362. package/dist/node_modules/ajv/dist/compile/validate/boolSchema.js.map +1 -0
  363. package/dist/node_modules/ajv/dist/compile/validate/dataType.js +193 -0
  364. package/dist/node_modules/ajv/dist/compile/validate/dataType.js.map +1 -0
  365. package/dist/node_modules/ajv/dist/compile/validate/defaults.js +43 -0
  366. package/dist/node_modules/ajv/dist/compile/validate/defaults.js.map +1 -0
  367. package/dist/node_modules/ajv/dist/compile/validate/index.js +522 -0
  368. package/dist/node_modules/ajv/dist/compile/validate/index.js.map +1 -0
  369. package/dist/node_modules/ajv/dist/compile/validate/keyword.js +126 -0
  370. package/dist/node_modules/ajv/dist/compile/validate/keyword.js.map +1 -0
  371. package/dist/node_modules/ajv/dist/compile/validate/subschema.js +89 -0
  372. package/dist/node_modules/ajv/dist/compile/validate/subschema.js.map +1 -0
  373. package/dist/node_modules/ajv/dist/core.js +628 -0
  374. package/dist/node_modules/ajv/dist/core.js.map +1 -0
  375. package/dist/node_modules/ajv/dist/refs/data.json.js +24 -0
  376. package/dist/node_modules/ajv/dist/refs/data.json.js.map +1 -0
  377. package/dist/node_modules/ajv/dist/refs/json-schema-draft-07.json.js +25 -0
  378. package/dist/node_modules/ajv/dist/refs/json-schema-draft-07.json.js.map +1 -0
  379. package/dist/node_modules/ajv/dist/runtime/equal.js +16 -0
  380. package/dist/node_modules/ajv/dist/runtime/equal.js.map +1 -0
  381. package/dist/node_modules/ajv/dist/runtime/ucs2length.js +30 -0
  382. package/dist/node_modules/ajv/dist/runtime/ucs2length.js.map +1 -0
  383. package/dist/node_modules/ajv/dist/runtime/uri.js +16 -0
  384. package/dist/node_modules/ajv/dist/runtime/uri.js.map +1 -0
  385. package/dist/node_modules/ajv/dist/runtime/validation_error.js +20 -0
  386. package/dist/node_modules/ajv/dist/runtime/validation_error.js.map +1 -0
  387. package/dist/node_modules/ajv/dist/vocabularies/applicator/additionalItems.js +59 -0
  388. package/dist/node_modules/ajv/dist/vocabularies/applicator/additionalItems.js.map +1 -0
  389. package/dist/node_modules/ajv/dist/vocabularies/applicator/additionalProperties.js +114 -0
  390. package/dist/node_modules/ajv/dist/vocabularies/applicator/additionalProperties.js.map +1 -0
  391. package/dist/node_modules/ajv/dist/vocabularies/applicator/allOf.js +32 -0
  392. package/dist/node_modules/ajv/dist/vocabularies/applicator/allOf.js.map +1 -0
  393. package/dist/node_modules/ajv/dist/vocabularies/applicator/anyOf.js +22 -0
  394. package/dist/node_modules/ajv/dist/vocabularies/applicator/anyOf.js.map +1 -0
  395. package/dist/node_modules/ajv/dist/vocabularies/applicator/contains.js +100 -0
  396. package/dist/node_modules/ajv/dist/vocabularies/applicator/contains.js.map +1 -0
  397. package/dist/node_modules/ajv/dist/vocabularies/applicator/dependencies.js +103 -0
  398. package/dist/node_modules/ajv/dist/vocabularies/applicator/dependencies.js.map +1 -0
  399. package/dist/node_modules/ajv/dist/vocabularies/applicator/if.js +75 -0
  400. package/dist/node_modules/ajv/dist/vocabularies/applicator/if.js.map +1 -0
  401. package/dist/node_modules/ajv/dist/vocabularies/applicator/index.js +68 -0
  402. package/dist/node_modules/ajv/dist/vocabularies/applicator/index.js.map +1 -0
  403. package/dist/node_modules/ajv/dist/vocabularies/applicator/items.js +64 -0
  404. package/dist/node_modules/ajv/dist/vocabularies/applicator/items.js.map +1 -0
  405. package/dist/node_modules/ajv/dist/vocabularies/applicator/items2020.js +43 -0
  406. package/dist/node_modules/ajv/dist/vocabularies/applicator/items2020.js.map +1 -0
  407. package/dist/node_modules/ajv/dist/vocabularies/applicator/not.js +36 -0
  408. package/dist/node_modules/ajv/dist/vocabularies/applicator/not.js.map +1 -0
  409. package/dist/node_modules/ajv/dist/vocabularies/applicator/oneOf.js +64 -0
  410. package/dist/node_modules/ajv/dist/vocabularies/applicator/oneOf.js.map +1 -0
  411. package/dist/node_modules/ajv/dist/vocabularies/applicator/patternProperties.js +81 -0
  412. package/dist/node_modules/ajv/dist/vocabularies/applicator/patternProperties.js.map +1 -0
  413. package/dist/node_modules/ajv/dist/vocabularies/applicator/prefixItems.js +22 -0
  414. package/dist/node_modules/ajv/dist/vocabularies/applicator/prefixItems.js.map +1 -0
  415. package/dist/node_modules/ajv/dist/vocabularies/applicator/properties.js +66 -0
  416. package/dist/node_modules/ajv/dist/vocabularies/applicator/properties.js.map +1 -0
  417. package/dist/node_modules/ajv/dist/vocabularies/applicator/propertyNames.js +49 -0
  418. package/dist/node_modules/ajv/dist/vocabularies/applicator/propertyNames.js.map +1 -0
  419. package/dist/node_modules/ajv/dist/vocabularies/applicator/thenElse.js +23 -0
  420. package/dist/node_modules/ajv/dist/vocabularies/applicator/thenElse.js.map +1 -0
  421. package/dist/node_modules/ajv/dist/vocabularies/code.js +140 -0
  422. package/dist/node_modules/ajv/dist/vocabularies/code.js.map +1 -0
  423. package/dist/node_modules/ajv/dist/vocabularies/core/id.js +19 -0
  424. package/dist/node_modules/ajv/dist/vocabularies/core/id.js.map +1 -0
  425. package/dist/node_modules/ajv/dist/vocabularies/core/index.js +27 -0
  426. package/dist/node_modules/ajv/dist/vocabularies/core/index.js.map +1 -0
  427. package/dist/node_modules/ajv/dist/vocabularies/core/ref.js +132 -0
  428. package/dist/node_modules/ajv/dist/vocabularies/core/ref.js.map +1 -0
  429. package/dist/node_modules/ajv/dist/vocabularies/discriminator/index.js +114 -0
  430. package/dist/node_modules/ajv/dist/vocabularies/discriminator/index.js.map +1 -0
  431. package/dist/node_modules/ajv/dist/vocabularies/discriminator/types.js +18 -0
  432. package/dist/node_modules/ajv/dist/vocabularies/discriminator/types.js.map +1 -0
  433. package/dist/node_modules/ajv/dist/vocabularies/draft7.js +31 -0
  434. package/dist/node_modules/ajv/dist/vocabularies/draft7.js.map +1 -0
  435. package/dist/node_modules/ajv/dist/vocabularies/format/format.js +95 -0
  436. package/dist/node_modules/ajv/dist/vocabularies/format/format.js.map +1 -0
  437. package/dist/node_modules/ajv/dist/vocabularies/format/index.js +16 -0
  438. package/dist/node_modules/ajv/dist/vocabularies/format/index.js.map +1 -0
  439. package/dist/node_modules/ajv/dist/vocabularies/metadata.js +27 -0
  440. package/dist/node_modules/ajv/dist/vocabularies/metadata.js.map +1 -0
  441. package/dist/node_modules/ajv/dist/vocabularies/validation/const.js +36 -0
  442. package/dist/node_modules/ajv/dist/vocabularies/validation/const.js.map +1 -0
  443. package/dist/node_modules/ajv/dist/vocabularies/validation/enum.js +56 -0
  444. package/dist/node_modules/ajv/dist/vocabularies/validation/enum.js.map +1 -0
  445. package/dist/node_modules/ajv/dist/vocabularies/validation/index.js +52 -0
  446. package/dist/node_modules/ajv/dist/vocabularies/validation/index.js.map +1 -0
  447. package/dist/node_modules/ajv/dist/vocabularies/validation/limitItems.js +34 -0
  448. package/dist/node_modules/ajv/dist/vocabularies/validation/limitItems.js.map +1 -0
  449. package/dist/node_modules/ajv/dist/vocabularies/validation/limitLength.js +39 -0
  450. package/dist/node_modules/ajv/dist/vocabularies/validation/limitLength.js.map +1 -0
  451. package/dist/node_modules/ajv/dist/vocabularies/validation/limitNumber.js +37 -0
  452. package/dist/node_modules/ajv/dist/vocabularies/validation/limitNumber.js.map +1 -0
  453. package/dist/node_modules/ajv/dist/vocabularies/validation/limitProperties.js +34 -0
  454. package/dist/node_modules/ajv/dist/vocabularies/validation/limitProperties.js.map +1 -0
  455. package/dist/node_modules/ajv/dist/vocabularies/validation/multipleOf.js +33 -0
  456. package/dist/node_modules/ajv/dist/vocabularies/validation/multipleOf.js.map +1 -0
  457. package/dist/node_modules/ajv/dist/vocabularies/validation/pattern.js +34 -0
  458. package/dist/node_modules/ajv/dist/vocabularies/validation/pattern.js.map +1 -0
  459. package/dist/node_modules/ajv/dist/vocabularies/validation/required.js +89 -0
  460. package/dist/node_modules/ajv/dist/vocabularies/validation/required.js.map +1 -0
  461. package/dist/node_modules/ajv/dist/vocabularies/validation/uniqueItems.js +75 -0
  462. package/dist/node_modules/ajv/dist/vocabularies/validation/uniqueItems.js.map +1 -0
  463. package/dist/node_modules/ajv-formats/dist/formats.js +209 -0
  464. package/dist/node_modules/ajv-formats/dist/formats.js.map +1 -0
  465. package/dist/node_modules/ajv-formats/dist/index.js +51 -0
  466. package/dist/node_modules/ajv-formats/dist/index.js.map +1 -0
  467. package/dist/node_modules/ajv-formats/dist/limit.js +80 -0
  468. package/dist/node_modules/ajv-formats/dist/limit.js.map +1 -0
  469. package/dist/node_modules/fast-deep-equal/index.js +39 -0
  470. package/dist/node_modules/fast-deep-equal/index.js.map +1 -0
  471. package/dist/node_modules/fast-uri/index.js +261 -0
  472. package/dist/node_modules/fast-uri/index.js.map +1 -0
  473. package/dist/node_modules/fast-uri/lib/schemes.js +215 -0
  474. package/dist/node_modules/fast-uri/lib/schemes.js.map +1 -0
  475. package/dist/node_modules/fast-uri/lib/utils.js +261 -0
  476. package/dist/node_modules/fast-uri/lib/utils.js.map +1 -0
  477. package/dist/node_modules/json-schema-traverse/index.js +92 -0
  478. package/dist/node_modules/json-schema-traverse/index.js.map +1 -0
  479. package/dist/node_modules/zod/v4/classic/errors.js +37 -0
  480. package/dist/node_modules/zod/v4/classic/errors.js.map +1 -0
  481. package/dist/node_modules/zod/v4/classic/iso.js +43 -0
  482. package/dist/node_modules/zod/v4/classic/iso.js.map +1 -0
  483. package/dist/node_modules/zod/v4/classic/parse.js +13 -0
  484. package/dist/node_modules/zod/v4/classic/parse.js.map +1 -0
  485. package/dist/node_modules/zod/v4/classic/schemas.js +688 -0
  486. package/dist/node_modules/zod/v4/classic/schemas.js.map +1 -0
  487. package/dist/node_modules/zod/v4/core/api.js +492 -0
  488. package/dist/node_modules/zod/v4/core/api.js.map +1 -0
  489. package/dist/node_modules/zod/v4/core/checks.js +405 -0
  490. package/dist/node_modules/zod/v4/core/checks.js.map +1 -0
  491. package/dist/node_modules/zod/v4/core/core.js +58 -0
  492. package/dist/node_modules/zod/v4/core/core.js.map +1 -0
  493. package/dist/node_modules/zod/v4/core/doc.js +38 -0
  494. package/dist/node_modules/zod/v4/core/doc.js.map +1 -0
  495. package/dist/node_modules/zod/v4/core/errors.js +82 -0
  496. package/dist/node_modules/zod/v4/core/errors.js.map +1 -0
  497. package/dist/node_modules/zod/v4/core/parse.js +60 -0
  498. package/dist/node_modules/zod/v4/core/parse.js.map +1 -0
  499. package/dist/node_modules/zod/v4/core/regexes.js +87 -0
  500. package/dist/node_modules/zod/v4/core/regexes.js.map +1 -0
  501. package/dist/node_modules/zod/v4/core/registries.js +52 -0
  502. package/dist/node_modules/zod/v4/core/registries.js.map +1 -0
  503. package/dist/node_modules/zod/v4/core/schemas.js +1283 -0
  504. package/dist/node_modules/zod/v4/core/schemas.js.map +1 -0
  505. package/dist/node_modules/zod/v4/core/util.js +341 -0
  506. package/dist/node_modules/zod/v4/core/util.js.map +1 -0
  507. package/dist/node_modules/zod/v4/core/versions.js +9 -0
  508. package/dist/node_modules/zod/v4/core/versions.js.map +1 -0
  509. package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/string.js +2 -0
  510. package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/string.js.map +1 -0
  511. package/dist/reasoning/index.d.ts +74 -0
  512. package/dist/reasoning/index.d.ts.map +1 -0
  513. package/dist/reasoning/index.js +124 -0
  514. package/dist/reasoning/index.js.map +1 -0
  515. package/dist/reasoning/tracker.d.ts +210 -0
  516. package/dist/reasoning/tracker.d.ts.map +1 -0
  517. package/dist/reasoning/types.d.ts +146 -0
  518. package/dist/reasoning/types.d.ts.map +1 -0
  519. package/dist/recovery/backup.d.ts +110 -0
  520. package/dist/recovery/backup.d.ts.map +1 -0
  521. package/dist/recovery/index.d.ts +70 -0
  522. package/dist/recovery/index.d.ts.map +1 -0
  523. package/dist/recovery/index.js +186 -0
  524. package/dist/recovery/index.js.map +1 -0
  525. package/dist/recovery/integrity.d.ts +74 -0
  526. package/dist/recovery/integrity.d.ts.map +1 -0
  527. package/dist/recovery/types.d.ts +94 -0
  528. package/dist/recovery/types.d.ts.map +1 -0
  529. package/dist/services/index.d.ts +130 -0
  530. package/dist/services/index.d.ts.map +1 -0
  531. package/dist/services/index.js +134 -0
  532. package/dist/services/index.js.map +1 -0
  533. package/dist/services/manager.d.ts +140 -0
  534. package/dist/services/manager.d.ts.map +1 -0
  535. package/dist/services/types.d.ts +106 -0
  536. package/dist/services/types.d.ts.map +1 -0
  537. package/dist/services/watchers.d.ts +95 -0
  538. package/dist/services/watchers.d.ts.map +1 -0
  539. package/dist/sops/compliance-checker.d.ts +83 -0
  540. package/dist/sops/compliance-checker.d.ts.map +1 -0
  541. package/dist/sops/compliance-checker.js +399 -0
  542. package/dist/sops/compliance-checker.js.map +1 -0
  543. package/dist/sops/gap-analyzer.d.ts +124 -0
  544. package/dist/sops/gap-analyzer.d.ts.map +1 -0
  545. package/dist/sops/gap-analyzer.js +313 -0
  546. package/dist/sops/gap-analyzer.js.map +1 -0
  547. package/dist/sops/index.d.ts +14 -0
  548. package/dist/sops/index.d.ts.map +1 -0
  549. package/dist/sops/overlay-manager.d.ts +115 -0
  550. package/dist/sops/overlay-manager.d.ts.map +1 -0
  551. package/dist/sops/overlay-manager.js +394 -0
  552. package/dist/sops/overlay-manager.js.map +1 -0
  553. package/dist/sops/registry.d.ts +73 -0
  554. package/dist/sops/registry.d.ts.map +1 -0
  555. package/dist/sops/registry.js +919 -0
  556. package/dist/sops/registry.js.map +1 -0
  557. package/dist/sops/types.d.ts +377 -0
  558. package/dist/sops/types.d.ts.map +1 -0
  559. package/dist/sops/types.js +46 -0
  560. package/dist/sops/types.js.map +1 -0
  561. package/dist/utils/error-recovery.d.ts +230 -0
  562. package/dist/utils/error-recovery.d.ts.map +1 -0
  563. package/dist/utils/error-recovery.js +228 -0
  564. package/dist/utils/error-recovery.js.map +1 -0
  565. package/dist/utils/error-taxonomy.d.ts +149 -0
  566. package/dist/utils/error-taxonomy.d.ts.map +1 -0
  567. package/dist/utils/error-taxonomy.js +260 -0
  568. package/dist/utils/error-taxonomy.js.map +1 -0
  569. package/dist/utils/index.d.ts +11 -0
  570. package/dist/utils/index.d.ts.map +1 -0
  571. package/dist/utils/logger.d.ts +139 -0
  572. package/dist/utils/logger.d.ts.map +1 -0
  573. package/dist/utils/logger.js +311 -0
  574. package/dist/utils/logger.js.map +1 -0
  575. package/dist/workflows/index.d.ts +11 -0
  576. package/dist/workflows/index.d.ts.map +1 -0
  577. package/dist/workflows/registry.d.ts +118 -0
  578. package/dist/workflows/registry.d.ts.map +1 -0
  579. package/dist/workflows/registry.js +575 -0
  580. package/dist/workflows/registry.js.map +1 -0
  581. package/dist/workflows/types.d.ts +322 -0
  582. package/dist/workflows/types.d.ts.map +1 -0
  583. package/dist/workflows/types.js +16 -0
  584. package/dist/workflows/types.js.map +1 -0
  585. package/package.json +1 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vault-sync.js","sources":["../../src/memory/vault-sync.ts"],"sourcesContent":["/**\n * Vault Memory Sync\n *\n * Provides bidirectional synchronization between the knowledge graph\n * and claude-flow memory system for persistent agent coordination.\n *\n * @module memory/vault-sync\n */\n\nimport { createHash } from 'crypto';\nimport { createLogger, withRetry, type RetryOptions } from '../utils/index.js';\nimport { ShadowCache, type FileMetadata, type FileChange } from '../core/cache.js';\nimport type { KnowledgeNode, GraphStats, SyncResult } from '../core/types.js';\nimport { KnowledgeGraphDatabase } from '../core/database.js';\n\nconst logger = createLogger('vault-sync');\n\n/**\n * Sync direction\n */\nexport type SyncDirection = 'to-memory' | 'from-memory' | 'bidirectional';\n\n/**\n * Conflict resolution strategy\n */\nexport type ConflictStrategy =\n | 'memory-wins' // Memory version takes precedence\n | 'vault-wins' // Vault version takes precedence\n | 'newest-wins' // Most recently modified wins\n | 'merge' // Attempt to merge changes\n | 'manual'; // Require manual resolution\n\n/**\n * Sync status\n */\nexport interface SyncStatus {\n /** Last successful sync timestamp */\n lastSync: Date | null;\n /** Whether sync is currently running */\n isSyncing: boolean;\n /** Number of pending changes in vault */\n pendingVaultChanges: number;\n /** Number of pending changes in memory */\n pendingMemoryChanges: number;\n /** Any sync errors */\n errors: string[];\n /** Sync health status */\n health: 'healthy' | 'warning' | 'error';\n}\n\n/**\n * Memory entry format for claude-flow\n */\nexport interface MemoryNode {\n id: string;\n title: string;\n type: string;\n status: string;\n path: string;\n tags: string[];\n outgoingLinks: string[];\n incomingLinks: string[];\n summary: string;\n contentHash: string;\n lastModified: string;\n syncedAt: string;\n}\n\n/**\n * Conflict record\n */\nexport interface SyncConflict {\n nodeId: string;\n path: string;\n vaultVersion: {\n hash: string;\n modifiedAt: Date;\n content?: string;\n };\n memoryVersion: {\n hash: string;\n modifiedAt: Date;\n content?: string;\n };\n resolvedAs?: 'vault' | 'memory' | 'merged';\n resolvedAt?: Date;\n}\n\n/**\n * Sync options\n */\nexport interface VaultSyncOptions {\n /** Project root directory */\n projectRoot: string;\n /** Claude-flow memory namespace */\n namespace?: string;\n /** Conflict resolution strategy */\n conflictStrategy?: ConflictStrategy;\n /** Whether to auto-sync on changes */\n autoSync?: boolean;\n /** Auto-sync interval in milliseconds */\n autoSyncInterval?: number;\n /** Retry options for network operations */\n retryOptions?: RetryOptions;\n /** Maximum batch size for sync operations */\n batchSize?: number;\n /** Whether to include content in memory entries */\n includeContent?: boolean;\n /** Maximum content length to store */\n maxContentLength?: number;\n}\n\n/**\n * Sync result for a single operation\n */\nexport interface SyncOperationResult {\n success: boolean;\n synced: number;\n skipped: number;\n failed: number;\n conflicts: SyncConflict[];\n errors: Array<{ nodeId: string; error: string }>;\n duration: number;\n}\n\n/**\n * Full sync result\n */\nexport interface FullSyncResult {\n success: boolean;\n toMemory: SyncOperationResult;\n fromMemory: SyncOperationResult;\n totalDuration: number;\n timestamp: Date;\n}\n\n/**\n * Vault Memory Sync\n *\n * Manages bidirectional synchronization between the knowledge graph vault\n * and claude-flow memory for cross-session persistence and agent coordination.\n *\n * @example\n * ```typescript\n * const sync = new VaultMemorySync({\n * projectRoot: '/my/project',\n * namespace: 'knowledge-graph',\n * conflictStrategy: 'newest-wins',\n * });\n *\n * // Initialize with database\n * await sync.initialize(db);\n *\n * // Sync to memory\n * const result = await sync.syncToMemory();\n *\n * // Check status\n * const status = sync.getStatus();\n * ```\n */\nexport class VaultMemorySync {\n private options: Required<VaultSyncOptions>;\n private shadowCache: ShadowCache;\n private db: KnowledgeGraphDatabase | null = null;\n private memoryCache: Map<string, MemoryNode> = new Map();\n private conflicts: SyncConflict[] = [];\n private lastSyncTime: Date | null = null;\n private isSyncing = false;\n private syncErrors: string[] = [];\n private autoSyncTimer: NodeJS.Timeout | null = null;\n\n constructor(options: VaultSyncOptions) {\n this.options = {\n projectRoot: options.projectRoot,\n namespace: options.namespace ?? 'knowledge-graph',\n conflictStrategy: options.conflictStrategy ?? 'newest-wins',\n autoSync: options.autoSync ?? false,\n autoSyncInterval: options.autoSyncInterval ?? 300000, // 5 minutes\n retryOptions: options.retryOptions ?? { maxRetries: 3, initialDelay: 1000 },\n batchSize: options.batchSize ?? 50,\n includeContent: options.includeContent ?? false,\n maxContentLength: options.maxContentLength ?? 5000,\n };\n\n this.shadowCache = new ShadowCache({\n projectRoot: options.projectRoot,\n cacheDir: '.kg/sync-cache',\n });\n }\n\n /**\n * Initialize the sync system with database\n */\n async initialize(db: KnowledgeGraphDatabase): Promise<void> {\n this.db = db;\n await this.shadowCache.load();\n\n // Load memory cache from previous sync\n await this.loadMemoryCache();\n\n if (this.options.autoSync) {\n this.startAutoSync();\n }\n\n logger.info('Vault sync initialized', {\n namespace: this.options.namespace,\n autoSync: this.options.autoSync,\n });\n }\n\n /**\n * Sync knowledge graph to claude-flow memory\n */\n async syncToMemory(): Promise<SyncOperationResult> {\n if (!this.db) {\n throw new Error('Database not initialized. Call initialize() first.');\n }\n\n const startTime = Date.now();\n const result: SyncOperationResult = {\n success: true,\n synced: 0,\n skipped: 0,\n failed: 0,\n conflicts: [],\n errors: [],\n duration: 0,\n };\n\n this.isSyncing = true;\n this.syncErrors = [];\n\n try {\n const nodes = this.db.getAllNodes();\n const batches = this.createBatches(nodes, this.options.batchSize);\n\n for (const batch of batches) {\n for (const node of batch) {\n try {\n const memoryNode = this.nodeToMemoryEntry(node);\n const cached = this.memoryCache.get(node.id);\n\n // Check for conflicts\n if (cached && cached.contentHash !== memoryNode.contentHash) {\n const conflict = await this.detectConflict(node, cached);\n if (conflict) {\n result.conflicts.push(conflict);\n const resolved = await this.resolveConflict(conflict);\n if (!resolved) {\n result.skipped++;\n continue;\n }\n }\n }\n\n // Generate MCP command for sync\n await this.storeToMemory(memoryNode);\n this.memoryCache.set(node.id, memoryNode);\n result.synced++;\n } catch (error) {\n result.failed++;\n result.errors.push({\n nodeId: node.id,\n error: String(error),\n });\n this.syncErrors.push(`Failed to sync ${node.id}: ${error}`);\n }\n }\n }\n\n // Sync indexes and metadata\n await this.syncIndexesToMemory(nodes);\n\n result.duration = Date.now() - startTime;\n result.success = result.failed === 0;\n this.lastSyncTime = new Date();\n\n logger.info('Sync to memory completed', {\n synced: result.synced,\n failed: result.failed,\n duration: result.duration,\n });\n } finally {\n this.isSyncing = false;\n await this.saveMemoryCache();\n }\n\n return result;\n }\n\n /**\n * Sync from claude-flow memory to knowledge graph\n */\n async syncFromMemory(): Promise<SyncOperationResult> {\n if (!this.db) {\n throw new Error('Database not initialized. Call initialize() first.');\n }\n\n const startTime = Date.now();\n const result: SyncOperationResult = {\n success: true,\n synced: 0,\n skipped: 0,\n failed: 0,\n conflicts: [],\n errors: [],\n duration: 0,\n };\n\n this.isSyncing = true;\n this.syncErrors = [];\n\n try {\n // Retrieve node index from memory\n const memoryNodes = await this.retrieveFromMemory();\n\n for (const memoryNode of memoryNodes) {\n try {\n const existingNode = this.db.getNode(memoryNode.id);\n\n if (existingNode) {\n // Check for conflicts\n const currentHash = this.computeContentHash(existingNode.content);\n if (currentHash !== memoryNode.contentHash) {\n const conflict = this.createConflictRecord(existingNode, memoryNode);\n result.conflicts.push(conflict);\n\n const resolved = await this.resolveConflict(conflict);\n if (!resolved || conflict.resolvedAs === 'vault') {\n result.skipped++;\n continue;\n }\n }\n }\n\n // Memory sync would update vault files if needed\n // For now, we track what would be synced\n result.synced++;\n this.memoryCache.set(memoryNode.id, memoryNode);\n } catch (error) {\n result.failed++;\n result.errors.push({\n nodeId: memoryNode.id,\n error: String(error),\n });\n }\n }\n\n result.duration = Date.now() - startTime;\n result.success = result.failed === 0;\n this.lastSyncTime = new Date();\n\n logger.info('Sync from memory completed', {\n synced: result.synced,\n failed: result.failed,\n duration: result.duration,\n });\n } finally {\n this.isSyncing = false;\n await this.saveMemoryCache();\n }\n\n return result;\n }\n\n /**\n * Perform full bidirectional sync\n */\n async fullSync(): Promise<FullSyncResult> {\n const startTime = Date.now();\n\n const toMemory = await this.syncToMemory();\n const fromMemory = await this.syncFromMemory();\n\n return {\n success: toMemory.success && fromMemory.success,\n toMemory,\n fromMemory,\n totalDuration: Date.now() - startTime,\n timestamp: new Date(),\n };\n }\n\n /**\n * Get current sync status\n */\n getStatus(): SyncStatus {\n const pendingVaultChanges = this.db\n ? this.countPendingVaultChanges()\n : 0;\n\n const pendingMemoryChanges = this.countPendingMemoryChanges();\n\n let health: SyncStatus['health'] = 'healthy';\n if (this.syncErrors.length > 0) {\n health = 'error';\n } else if (this.conflicts.length > 0 || pendingVaultChanges > 10) {\n health = 'warning';\n }\n\n return {\n lastSync: this.lastSyncTime,\n isSyncing: this.isSyncing,\n pendingVaultChanges,\n pendingMemoryChanges,\n errors: [...this.syncErrors],\n health,\n };\n }\n\n /**\n * Get unresolved conflicts\n */\n getConflicts(): SyncConflict[] {\n return this.conflicts.filter(c => !c.resolvedAt);\n }\n\n /**\n * Manually resolve a conflict\n */\n async resolveConflictManually(\n nodeId: string,\n resolution: 'vault' | 'memory'\n ): Promise<boolean> {\n const conflict = this.conflicts.find(\n c => c.nodeId === nodeId && !c.resolvedAt\n );\n\n if (!conflict) {\n return false;\n }\n\n conflict.resolvedAs = resolution;\n conflict.resolvedAt = new Date();\n\n if (resolution === 'vault' && this.db) {\n // Re-sync vault version to memory\n const node = this.db.getNode(nodeId);\n if (node) {\n const memoryNode = this.nodeToMemoryEntry(node);\n await this.storeToMemory(memoryNode);\n this.memoryCache.set(nodeId, memoryNode);\n }\n }\n\n return true;\n }\n\n /**\n * Detect changes in vault since last sync\n */\n async detectChanges(): Promise<FileChange[]> {\n if (!this.db) {\n return [];\n }\n\n const nodes = this.db.getAllNodes();\n const filePaths = nodes.map(n => n.path);\n\n return this.shadowCache.detectChanges(filePaths);\n }\n\n /**\n * Stop the sync system\n */\n stop(): void {\n if (this.autoSyncTimer) {\n clearInterval(this.autoSyncTimer);\n this.autoSyncTimer = null;\n }\n this.saveMemoryCache().catch(err =>\n logger.error('Failed to save memory cache on stop', err)\n );\n }\n\n // Private methods\n\n private startAutoSync(): void {\n if (this.autoSyncTimer) {\n clearInterval(this.autoSyncTimer);\n }\n\n this.autoSyncTimer = setInterval(async () => {\n if (!this.isSyncing) {\n try {\n await this.syncToMemory();\n } catch (error) {\n logger.error('Auto-sync failed', error as Error);\n }\n }\n }, this.options.autoSyncInterval);\n }\n\n private nodeToMemoryEntry(node: KnowledgeNode): MemoryNode {\n const summary = this.extractSummary(node.content);\n const contentHash = this.computeContentHash(node.content);\n\n return {\n id: node.id,\n title: node.title,\n type: node.type,\n status: node.status,\n path: node.path,\n tags: node.tags,\n outgoingLinks: node.outgoingLinks.map(l => l.target),\n incomingLinks: node.incomingLinks.map(l => l.target),\n summary,\n contentHash,\n lastModified: node.lastModified.toISOString(),\n syncedAt: new Date().toISOString(),\n };\n }\n\n private extractSummary(content: string, maxLength = 200): string {\n const lines = content.split('\\n');\n let summary = '';\n\n for (const line of lines) {\n const trimmed = line.trim();\n if (!trimmed || trimmed.startsWith('#') || trimmed.startsWith('```') || trimmed === '---') {\n continue;\n }\n summary = trimmed;\n break;\n }\n\n if (summary.length > maxLength) {\n summary = summary.slice(0, maxLength - 3) + '...';\n }\n\n return summary;\n }\n\n private computeContentHash(content: string): string {\n return createHash('md5').update(content).digest('hex').substring(0, 16);\n }\n\n private async storeToMemory(node: MemoryNode): Promise<void> {\n // This would integrate with actual claude-flow MCP calls\n // For now, we log the command that would be executed\n logger.debug('Store to memory', {\n key: `node/${node.id}`,\n namespace: this.options.namespace,\n });\n\n // In production, this would call:\n // await mcpClient.memoryUsage({\n // action: 'store',\n // key: `node/${node.id}`,\n // namespace: this.options.namespace,\n // value: JSON.stringify(node),\n // });\n }\n\n private async retrieveFromMemory(): Promise<MemoryNode[]> {\n // This would integrate with actual claude-flow MCP calls\n // For now, return cached nodes\n logger.debug('Retrieve from memory', {\n namespace: this.options.namespace,\n });\n\n return Array.from(this.memoryCache.values());\n }\n\n private async syncIndexesToMemory(nodes: KnowledgeNode[]): Promise<void> {\n // Sync node index\n const nodeIndex = nodes.map(n => ({\n id: n.id,\n title: n.title,\n type: n.type,\n path: n.path,\n }));\n\n logger.debug('Sync node index', {\n count: nodeIndex.length,\n namespace: this.options.namespace,\n });\n\n // Sync tag index\n const tagIndex: Record<string, string[]> = {};\n for (const node of nodes) {\n for (const tag of node.tags) {\n if (!tagIndex[tag]) {\n tagIndex[tag] = [];\n }\n tagIndex[tag].push(node.id);\n }\n }\n\n logger.debug('Sync tag index', {\n tags: Object.keys(tagIndex).length,\n namespace: this.options.namespace,\n });\n\n // Sync metadata\n const metadata = {\n lastSync: new Date().toISOString(),\n nodeCount: nodes.length,\n namespace: this.options.namespace,\n };\n\n logger.debug('Sync metadata', metadata);\n }\n\n private async detectConflict(\n node: KnowledgeNode,\n cached: MemoryNode\n ): Promise<SyncConflict | null> {\n const vaultHash = this.computeContentHash(node.content);\n\n if (vaultHash === cached.contentHash) {\n return null; // No conflict\n }\n\n return {\n nodeId: node.id,\n path: node.path,\n vaultVersion: {\n hash: vaultHash,\n modifiedAt: node.lastModified,\n content: this.options.includeContent ? node.content : undefined,\n },\n memoryVersion: {\n hash: cached.contentHash,\n modifiedAt: new Date(cached.lastModified),\n },\n };\n }\n\n private createConflictRecord(\n node: KnowledgeNode,\n memoryNode: MemoryNode\n ): SyncConflict {\n return {\n nodeId: node.id,\n path: node.path,\n vaultVersion: {\n hash: this.computeContentHash(node.content),\n modifiedAt: node.lastModified,\n },\n memoryVersion: {\n hash: memoryNode.contentHash,\n modifiedAt: new Date(memoryNode.lastModified),\n },\n };\n }\n\n private async resolveConflict(conflict: SyncConflict): Promise<boolean> {\n switch (this.options.conflictStrategy) {\n case 'vault-wins':\n conflict.resolvedAs = 'vault';\n conflict.resolvedAt = new Date();\n return true;\n\n case 'memory-wins':\n conflict.resolvedAs = 'memory';\n conflict.resolvedAt = new Date();\n return true;\n\n case 'newest-wins':\n if (conflict.vaultVersion.modifiedAt > conflict.memoryVersion.modifiedAt) {\n conflict.resolvedAs = 'vault';\n } else {\n conflict.resolvedAs = 'memory';\n }\n conflict.resolvedAt = new Date();\n return true;\n\n case 'merge':\n // Merge strategy would require content comparison\n // For now, fall back to newest-wins\n if (conflict.vaultVersion.modifiedAt > conflict.memoryVersion.modifiedAt) {\n conflict.resolvedAs = 'vault';\n } else {\n conflict.resolvedAs = 'memory';\n }\n conflict.resolvedAt = new Date();\n return true;\n\n case 'manual':\n // Don't auto-resolve, add to conflicts list\n this.conflicts.push(conflict);\n return false;\n\n default:\n return false;\n }\n }\n\n private countPendingVaultChanges(): number {\n const cachedHashes = new Map<string, string>();\n for (const [id, node] of this.memoryCache) {\n cachedHashes.set(id, node.contentHash);\n }\n\n let pending = 0;\n const nodes = this.db?.getAllNodes() ?? [];\n\n for (const node of nodes) {\n const cachedHash = cachedHashes.get(node.id);\n const currentHash = this.computeContentHash(node.content);\n\n if (!cachedHash || cachedHash !== currentHash) {\n pending++;\n }\n }\n\n return pending;\n }\n\n private countPendingMemoryChanges(): number {\n // In a real implementation, this would check memory for changes\n // that haven't been synced to vault\n return 0;\n }\n\n private createBatches<T>(items: T[], batchSize: number): T[][] {\n const batches: T[][] = [];\n for (let i = 0; i < items.length; i += batchSize) {\n batches.push(items.slice(i, i + batchSize));\n }\n return batches;\n }\n\n private async loadMemoryCache(): Promise<void> {\n // In production, this would load from persistent storage\n // or retrieve the current state from claude-flow memory\n logger.debug('Loading memory cache');\n }\n\n private async saveMemoryCache(): Promise<void> {\n // Persist cache to disk for recovery\n await this.shadowCache.save();\n logger.debug('Memory cache saved');\n }\n}\n\n/**\n * Create a vault memory sync instance\n */\nexport function createVaultMemorySync(options: VaultSyncOptions): VaultMemorySync {\n return new VaultMemorySync(options);\n}\n"],"names":[],"mappings":";;;AAeA,MAAM,SAAS,aAAa,YAAY;AAiJjC,MAAM,gBAAgB;AAAA,EACnB;AAAA,EACA;AAAA,EACA,KAAoC;AAAA,EACpC,kCAA2C,IAAA;AAAA,EAC3C,YAA4B,CAAA;AAAA,EAC5B,e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,EAEQ,4BAAoC;AAG1C,WAAO;AAAA,EACT;AAAA,EAEQ,cAAiB,OAAY,WAA0B;AAC7D,UAAM,UAAiB,CAAA;AACvB,aAAS,IAAI,GAAG,IAAI,MAAM,QAAQ,KAAK,WAAW;AAChD,cAAQ,KAAK,MAAM,MAAM,GAAG,IAAI,SAAS,CAAC;AAAA,IAC5C;AACA,WAAO;AAAA,EACT;AAAA,EAEA,MAAc,kBAAiC;AAG7C,WAAO,MAAM,sBAAsB;AAAA,EACrC;AAAA,EAEA,MAAc,kBAAiC;AAE7C,UAAM,KAAK,YAAY,KAAA;AACvB,WAAO,MAAM,oBAAoB;AAAA,EACnC;AACF;AAKO,SAAS,sBAAsB,SAA4C;AAChF,SAAO,IAAI,gBAAgB,OAAO;AACpC;"}
@@ -0,0 +1,296 @@
1
+ import { Protocol, mergeCapabilities } from "../shared/protocol.js";
2
+ import { LoggingLevelSchema, InitializeRequestSchema, InitializedNotificationSchema, SetLevelRequestSchema, LATEST_PROTOCOL_VERSION, EmptyResultSchema, CreateMessageResultSchema, ElicitResultSchema, McpError, ErrorCode, ListRootsResultSchema, SUPPORTED_PROTOCOL_VERSIONS } from "../types.js";
3
+ import { AjvJsonSchemaValidator } from "../validation/ajv-provider.js";
4
+ class Server extends Protocol {
5
+ /**
6
+ * Initializes this server with the given name and version information.
7
+ */
8
+ constructor(_serverInfo, options) {
9
+ var _a, _b;
10
+ super(options);
11
+ this._serverInfo = _serverInfo;
12
+ this._loggingLevels = /* @__PURE__ */ new Map();
13
+ this.LOG_LEVEL_SEVERITY = new Map(LoggingLevelSchema.options.map((level, index) => [level, index]));
14
+ this.isMessageIgnored = (level, sessionId) => {
15
+ const currentLevel = this._loggingLevels.get(sessionId);
16
+ return currentLevel ? this.LOG_LEVEL_SEVERITY.get(level) < this.LOG_LEVEL_SEVERITY.get(currentLevel) : false;
17
+ };
18
+ this._capabilities = (_a = options === null || options === void 0 ? void 0 : options.capabilities) !== null && _a !== void 0 ? _a : {};
19
+ this._instructions = options === null || options === void 0 ? void 0 : options.instructions;
20
+ this._jsonSchemaValidator = (_b = options === null || options === void 0 ? void 0 : options.jsonSchemaValidator) !== null && _b !== void 0 ? _b : new AjvJsonSchemaValidator();
21
+ this.setRequestHandler(InitializeRequestSchema, (request) => this._oninitialize(request));
22
+ this.setNotificationHandler(InitializedNotificationSchema, () => {
23
+ var _a2;
24
+ return (_a2 = this.oninitialized) === null || _a2 === void 0 ? void 0 : _a2.call(this);
25
+ });
26
+ if (this._capabilities.logging) {
27
+ this.setRequestHandler(SetLevelRequestSchema, async (request, extra) => {
28
+ var _a2;
29
+ const transportSessionId = extra.sessionId || ((_a2 = extra.requestInfo) === null || _a2 === void 0 ? void 0 : _a2.headers["mcp-session-id"]) || void 0;
30
+ const { level } = request.params;
31
+ const parseResult = LoggingLevelSchema.safeParse(level);
32
+ if (parseResult.success) {
33
+ this._loggingLevels.set(transportSessionId, parseResult.data);
34
+ }
35
+ return {};
36
+ });
37
+ }
38
+ }
39
+ /**
40
+ * Registers new capabilities. This can only be called before connecting to a transport.
41
+ *
42
+ * The new capabilities will be merged with any existing capabilities previously given (e.g., at initialization).
43
+ */
44
+ registerCapabilities(capabilities) {
45
+ if (this.transport) {
46
+ throw new Error("Cannot register capabilities after connecting to transport");
47
+ }
48
+ this._capabilities = mergeCapabilities(this._capabilities, capabilities);
49
+ }
50
+ assertCapabilityForMethod(method) {
51
+ var _a, _b, _c;
52
+ switch (method) {
53
+ case "sampling/createMessage":
54
+ if (!((_a = this._clientCapabilities) === null || _a === void 0 ? void 0 : _a.sampling)) {
55
+ throw new Error(`Client does not support sampling (required for ${method})`);
56
+ }
57
+ break;
58
+ case "elicitation/create":
59
+ if (!((_b = this._clientCapabilities) === null || _b === void 0 ? void 0 : _b.elicitation)) {
60
+ throw new Error(`Client does not support elicitation (required for ${method})`);
61
+ }
62
+ break;
63
+ case "roots/list":
64
+ if (!((_c = this._clientCapabilities) === null || _c === void 0 ? void 0 : _c.roots)) {
65
+ throw new Error(`Client does not support listing roots (required for ${method})`);
66
+ }
67
+ break;
68
+ }
69
+ }
70
+ assertNotificationCapability(method) {
71
+ var _a, _b;
72
+ switch (method) {
73
+ case "notifications/message":
74
+ if (!this._capabilities.logging) {
75
+ throw new Error(`Server does not support logging (required for ${method})`);
76
+ }
77
+ break;
78
+ case "notifications/resources/updated":
79
+ case "notifications/resources/list_changed":
80
+ if (!this._capabilities.resources) {
81
+ throw new Error(`Server does not support notifying about resources (required for ${method})`);
82
+ }
83
+ break;
84
+ case "notifications/tools/list_changed":
85
+ if (!this._capabilities.tools) {
86
+ throw new Error(`Server does not support notifying of tool list changes (required for ${method})`);
87
+ }
88
+ break;
89
+ case "notifications/prompts/list_changed":
90
+ if (!this._capabilities.prompts) {
91
+ throw new Error(`Server does not support notifying of prompt list changes (required for ${method})`);
92
+ }
93
+ break;
94
+ case "notifications/elicitation/complete":
95
+ if (!((_b = (_a = this._clientCapabilities) === null || _a === void 0 ? void 0 : _a.elicitation) === null || _b === void 0 ? void 0 : _b.url)) {
96
+ throw new Error(`Client does not support URL elicitation (required for ${method})`);
97
+ }
98
+ break;
99
+ }
100
+ }
101
+ assertRequestHandlerCapability(method) {
102
+ switch (method) {
103
+ case "completion/complete":
104
+ if (!this._capabilities.completions) {
105
+ throw new Error(`Server does not support completions (required for ${method})`);
106
+ }
107
+ break;
108
+ case "logging/setLevel":
109
+ if (!this._capabilities.logging) {
110
+ throw new Error(`Server does not support logging (required for ${method})`);
111
+ }
112
+ break;
113
+ case "prompts/get":
114
+ case "prompts/list":
115
+ if (!this._capabilities.prompts) {
116
+ throw new Error(`Server does not support prompts (required for ${method})`);
117
+ }
118
+ break;
119
+ case "resources/list":
120
+ case "resources/templates/list":
121
+ case "resources/read":
122
+ if (!this._capabilities.resources) {
123
+ throw new Error(`Server does not support resources (required for ${method})`);
124
+ }
125
+ break;
126
+ case "tools/call":
127
+ case "tools/list":
128
+ if (!this._capabilities.tools) {
129
+ throw new Error(`Server does not support tools (required for ${method})`);
130
+ }
131
+ break;
132
+ }
133
+ }
134
+ async _oninitialize(request) {
135
+ const requestedVersion = request.params.protocolVersion;
136
+ this._clientCapabilities = request.params.capabilities;
137
+ this._clientVersion = request.params.clientInfo;
138
+ const protocolVersion = SUPPORTED_PROTOCOL_VERSIONS.includes(requestedVersion) ? requestedVersion : LATEST_PROTOCOL_VERSION;
139
+ return {
140
+ protocolVersion,
141
+ capabilities: this.getCapabilities(),
142
+ serverInfo: this._serverInfo,
143
+ ...this._instructions && { instructions: this._instructions }
144
+ };
145
+ }
146
+ /**
147
+ * After initialization has completed, this will be populated with the client's reported capabilities.
148
+ */
149
+ getClientCapabilities() {
150
+ return this._clientCapabilities;
151
+ }
152
+ /**
153
+ * After initialization has completed, this will be populated with information about the client's name and version.
154
+ */
155
+ getClientVersion() {
156
+ return this._clientVersion;
157
+ }
158
+ getCapabilities() {
159
+ return this._capabilities;
160
+ }
161
+ async ping() {
162
+ return this.request({ method: "ping" }, EmptyResultSchema);
163
+ }
164
+ async createMessage(params, options) {
165
+ var _a, _b;
166
+ if (params.tools || params.toolChoice) {
167
+ if (!((_b = (_a = this._clientCapabilities) === null || _a === void 0 ? void 0 : _a.sampling) === null || _b === void 0 ? void 0 : _b.tools)) {
168
+ throw new Error("Client does not support sampling tools capability.");
169
+ }
170
+ }
171
+ if (params.messages.length > 0) {
172
+ const lastMessage = params.messages[params.messages.length - 1];
173
+ const lastContent = Array.isArray(lastMessage.content) ? lastMessage.content : [lastMessage.content];
174
+ const hasToolResults = lastContent.some((c) => c.type === "tool_result");
175
+ const previousMessage = params.messages.length > 1 ? params.messages[params.messages.length - 2] : void 0;
176
+ const previousContent = previousMessage ? Array.isArray(previousMessage.content) ? previousMessage.content : [previousMessage.content] : [];
177
+ const hasPreviousToolUse = previousContent.some((c) => c.type === "tool_use");
178
+ if (hasToolResults) {
179
+ if (lastContent.some((c) => c.type !== "tool_result")) {
180
+ throw new Error("The last message must contain only tool_result content if any is present");
181
+ }
182
+ if (!hasPreviousToolUse) {
183
+ throw new Error("tool_result blocks are not matching any tool_use from the previous message");
184
+ }
185
+ }
186
+ if (hasPreviousToolUse) {
187
+ const toolUseIds = new Set(previousContent.filter((c) => c.type === "tool_use").map((c) => c.id));
188
+ const toolResultIds = new Set(lastContent.filter((c) => c.type === "tool_result").map((c) => c.toolUseId));
189
+ if (toolUseIds.size !== toolResultIds.size || ![...toolUseIds].every((id) => toolResultIds.has(id))) {
190
+ throw new Error("ids of tool_result blocks and tool_use blocks from previous message do not match");
191
+ }
192
+ }
193
+ }
194
+ return this.request({ method: "sampling/createMessage", params }, CreateMessageResultSchema, options);
195
+ }
196
+ /**
197
+ * Creates an elicitation request for the given parameters.
198
+ * For backwards compatibility, `mode` may be omitted for form requests and will default to `'form'`.
199
+ * @param params The parameters for the elicitation request.
200
+ * @param options Optional request options.
201
+ * @returns The result of the elicitation request.
202
+ */
203
+ async elicitInput(params, options) {
204
+ var _a, _b, _c, _d, _e;
205
+ const mode = (_a = params.mode) !== null && _a !== void 0 ? _a : "form";
206
+ switch (mode) {
207
+ case "url": {
208
+ if (!((_c = (_b = this._clientCapabilities) === null || _b === void 0 ? void 0 : _b.elicitation) === null || _c === void 0 ? void 0 : _c.url)) {
209
+ throw new Error("Client does not support url elicitation.");
210
+ }
211
+ const urlParams = params;
212
+ return this.request({ method: "elicitation/create", params: urlParams }, ElicitResultSchema, options);
213
+ }
214
+ case "form": {
215
+ if (!((_e = (_d = this._clientCapabilities) === null || _d === void 0 ? void 0 : _d.elicitation) === null || _e === void 0 ? void 0 : _e.form)) {
216
+ throw new Error("Client does not support form elicitation.");
217
+ }
218
+ const formParams = params.mode === "form" ? params : { ...params, mode: "form" };
219
+ const result = await this.request({ method: "elicitation/create", params: formParams }, ElicitResultSchema, options);
220
+ if (result.action === "accept" && result.content && formParams.requestedSchema) {
221
+ try {
222
+ const validator = this._jsonSchemaValidator.getValidator(formParams.requestedSchema);
223
+ const validationResult = validator(result.content);
224
+ if (!validationResult.valid) {
225
+ throw new McpError(ErrorCode.InvalidParams, `Elicitation response content does not match requested schema: ${validationResult.errorMessage}`);
226
+ }
227
+ } catch (error) {
228
+ if (error instanceof McpError) {
229
+ throw error;
230
+ }
231
+ throw new McpError(ErrorCode.InternalError, `Error validating elicitation response: ${error instanceof Error ? error.message : String(error)}`);
232
+ }
233
+ }
234
+ return result;
235
+ }
236
+ }
237
+ }
238
+ /**
239
+ * Creates a reusable callback that, when invoked, will send a `notifications/elicitation/complete`
240
+ * notification for the specified elicitation ID.
241
+ *
242
+ * @param elicitationId The ID of the elicitation to mark as complete.
243
+ * @param options Optional notification options. Useful when the completion notification should be related to a prior request.
244
+ * @returns A function that emits the completion notification when awaited.
245
+ */
246
+ createElicitationCompletionNotifier(elicitationId, options) {
247
+ var _a, _b;
248
+ if (!((_b = (_a = this._clientCapabilities) === null || _a === void 0 ? void 0 : _a.elicitation) === null || _b === void 0 ? void 0 : _b.url)) {
249
+ throw new Error("Client does not support URL elicitation (required for notifications/elicitation/complete)");
250
+ }
251
+ return () => this.notification({
252
+ method: "notifications/elicitation/complete",
253
+ params: {
254
+ elicitationId
255
+ }
256
+ }, options);
257
+ }
258
+ async listRoots(params, options) {
259
+ return this.request({ method: "roots/list", params }, ListRootsResultSchema, options);
260
+ }
261
+ /**
262
+ * Sends a logging message to the client, if connected.
263
+ * Note: You only need to send the parameters object, not the entire JSON RPC message
264
+ * @see LoggingMessageNotification
265
+ * @param params
266
+ * @param sessionId optional for stateless and backward compatibility
267
+ */
268
+ async sendLoggingMessage(params, sessionId) {
269
+ if (this._capabilities.logging) {
270
+ if (!this.isMessageIgnored(params.level, sessionId)) {
271
+ return this.notification({ method: "notifications/message", params });
272
+ }
273
+ }
274
+ }
275
+ async sendResourceUpdated(params) {
276
+ return this.notification({
277
+ method: "notifications/resources/updated",
278
+ params
279
+ });
280
+ }
281
+ async sendResourceListChanged() {
282
+ return this.notification({
283
+ method: "notifications/resources/list_changed"
284
+ });
285
+ }
286
+ async sendToolListChanged() {
287
+ return this.notification({ method: "notifications/tools/list_changed" });
288
+ }
289
+ async sendPromptListChanged() {
290
+ return this.notification({ method: "notifications/prompts/list_changed" });
291
+ }
292
+ }
293
+ export {
294
+ Server
295
+ };
296
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["../../../../../../../../../../node_modules/@modelcontextprotocol/sdk/dist/esm/server/index.js"],"sourcesContent":["import { mergeCapabilities, Protocol } from '../shared/protocol.js';\nimport { CreateMessageResultSchema, ElicitResultSchema, EmptyResultSchema, ErrorCode, InitializedNotificationSchema, InitializeRequestSchema, LATEST_PROTOCOL_VERSION, ListRootsResultSchema, LoggingLevelSchema, McpError, SetLevelRequestSchema, SUPPORTED_PROTOCOL_VERSIONS } from '../types.js';\nimport { AjvJsonSchemaValidator } from '../validation/ajv-provider.js';\n/**\n * An MCP server on top of a pluggable transport.\n *\n * This server will automatically respond to the initialization flow as initiated from the client.\n *\n * To use with custom types, extend the base Request/Notification/Result types and pass them as type parameters:\n *\n * ```typescript\n * // Custom schemas\n * const CustomRequestSchema = RequestSchema.extend({...})\n * const CustomNotificationSchema = NotificationSchema.extend({...})\n * const CustomResultSchema = ResultSchema.extend({...})\n *\n * // Type aliases\n * type CustomRequest = z.infer<typeof CustomRequestSchema>\n * type CustomNotification = z.infer<typeof CustomNotificationSchema>\n * type CustomResult = z.infer<typeof CustomResultSchema>\n *\n * // Create typed server\n * const server = new Server<CustomRequest, CustomNotification, CustomResult>({\n * name: \"CustomServer\",\n * version: \"1.0.0\"\n * })\n * ```\n * @deprecated Use `McpServer` instead for the high-level API. Only use `Server` for advanced use cases.\n */\nexport class Server extends Protocol {\n /**\n * Initializes this server with the given name and version information.\n */\n constructor(_serverInfo, options) {\n var _a, _b;\n super(options);\n this._serverInfo = _serverInfo;\n // Map log levels by session id\n this._loggingLevels = new Map();\n // Map LogLevelSchema to severity index\n this.LOG_LEVEL_SEVERITY = new Map(LoggingLevelSchema.options.map((level, index) => [level, index]));\n // Is a message with the given level ignored in the log level set for the given session id?\n this.isMessageIgnored = (level, sessionId) => {\n const currentLevel = this._loggingLevels.get(sessionId);\n return currentLevel ? this.LOG_LEVEL_SEVERITY.get(level) < this.LOG_LEVEL_SEVERITY.get(currentLevel) : false;\n };\n this._capabilities = (_a = options === null || options === void 0 ? void 0 : options.capabilities) !== null && _a !== void 0 ? _a : {};\n this._instructions = options === null || options === void 0 ? void 0 : options.instructions;\n this._jsonSchemaValidator = (_b = options === null || options === void 0 ? void 0 : options.jsonSchemaValidator) !== null && _b !== void 0 ? _b : new AjvJsonSchemaValidator();\n this.setRequestHandler(InitializeRequestSchema, request => this._oninitialize(request));\n this.setNotificationHandler(InitializedNotificationSchema, () => { var _a; return (_a = this.oninitialized) === null || _a === void 0 ? void 0 : _a.call(this); });\n if (this._capabilities.logging) {\n this.setRequestHandler(SetLevelRequestSchema, async (request, extra) => {\n var _a;\n const transportSessionId = extra.sessionId || ((_a = extra.requestInfo) === null || _a === void 0 ? void 0 : _a.headers['mcp-session-id']) || undefined;\n const { level } = request.params;\n const parseResult = LoggingLevelSchema.safeParse(level);\n if (parseResult.success) {\n this._loggingLevels.set(transportSessionId, parseResult.data);\n }\n return {};\n });\n }\n }\n /**\n * Registers new capabilities. This can only be called before connecting to a transport.\n *\n * The new capabilities will be merged with any existing capabilities previously given (e.g., at initialization).\n */\n registerCapabilities(capabilities) {\n if (this.transport) {\n throw new Error('Cannot register capabilities after connecting to transport');\n }\n this._capabilities = mergeCapabilities(this._capabilities, capabilities);\n }\n assertCapabilityForMethod(method) {\n var _a, _b, _c;\n switch (method) {\n case 'sampling/createMessage':\n if (!((_a = this._clientCapabilities) === null || _a === void 0 ? void 0 : _a.sampling)) {\n throw new Error(`Client does not support sampling (required for ${method})`);\n }\n break;\n case 'elicitation/create':\n if (!((_b = this._clientCapabilities) === null || _b === void 0 ? void 0 : _b.elicitation)) {\n throw new Error(`Client does not support elicitation (required for ${method})`);\n }\n break;\n case 'roots/list':\n if (!((_c = this._clientCapabilities) === null || _c === void 0 ? void 0 : _c.roots)) {\n throw new Error(`Client does not support listing roots (required for ${method})`);\n }\n break;\n case 'ping':\n // No specific capability required for ping\n break;\n }\n }\n assertNotificationCapability(method) {\n var _a, _b;\n switch (method) {\n case 'notifications/message':\n if (!this._capabilities.logging) {\n throw new Error(`Server does not support logging (required for ${method})`);\n }\n break;\n case 'notifications/resources/updated':\n case 'notifications/resources/list_changed':\n if (!this._capabilities.resources) {\n throw new Error(`Server does not support notifying about resources (required for ${method})`);\n }\n break;\n case 'notifications/tools/list_changed':\n if (!this._capabilities.tools) {\n throw new Error(`Server does not support notifying of tool list changes (required for ${method})`);\n }\n break;\n case 'notifications/prompts/list_changed':\n if (!this._capabilities.prompts) {\n throw new Error(`Server does not support notifying of prompt list changes (required for ${method})`);\n }\n break;\n case 'notifications/elicitation/complete':\n if (!((_b = (_a = this._clientCapabilities) === null || _a === void 0 ? void 0 : _a.elicitation) === null || _b === void 0 ? void 0 : _b.url)) {\n throw new Error(`Client does not support URL elicitation (required for ${method})`);\n }\n break;\n case 'notifications/cancelled':\n // Cancellation notifications are always allowed\n break;\n case 'notifications/progress':\n // Progress notifications are always allowed\n break;\n }\n }\n assertRequestHandlerCapability(method) {\n switch (method) {\n case 'completion/complete':\n if (!this._capabilities.completions) {\n throw new Error(`Server does not support completions (required for ${method})`);\n }\n break;\n case 'logging/setLevel':\n if (!this._capabilities.logging) {\n throw new Error(`Server does not support logging (required for ${method})`);\n }\n break;\n case 'prompts/get':\n case 'prompts/list':\n if (!this._capabilities.prompts) {\n throw new Error(`Server does not support prompts (required for ${method})`);\n }\n break;\n case 'resources/list':\n case 'resources/templates/list':\n case 'resources/read':\n if (!this._capabilities.resources) {\n throw new Error(`Server does not support resources (required for ${method})`);\n }\n break;\n case 'tools/call':\n case 'tools/list':\n if (!this._capabilities.tools) {\n throw new Error(`Server does not support tools (required for ${method})`);\n }\n break;\n case 'ping':\n case 'initialize':\n // No specific capability required for these methods\n break;\n }\n }\n async _oninitialize(request) {\n const requestedVersion = request.params.protocolVersion;\n this._clientCapabilities = request.params.capabilities;\n this._clientVersion = request.params.clientInfo;\n const protocolVersion = SUPPORTED_PROTOCOL_VERSIONS.includes(requestedVersion) ? requestedVersion : LATEST_PROTOCOL_VERSION;\n return {\n protocolVersion,\n capabilities: this.getCapabilities(),\n serverInfo: this._serverInfo,\n ...(this._instructions && { instructions: this._instructions })\n };\n }\n /**\n * After initialization has completed, this will be populated with the client's reported capabilities.\n */\n getClientCapabilities() {\n return this._clientCapabilities;\n }\n /**\n * After initialization has completed, this will be populated with information about the client's name and version.\n */\n getClientVersion() {\n return this._clientVersion;\n }\n getCapabilities() {\n return this._capabilities;\n }\n async ping() {\n return this.request({ method: 'ping' }, EmptyResultSchema);\n }\n async createMessage(params, options) {\n var _a, _b;\n // Capability check - only required when tools/toolChoice are provided\n if (params.tools || params.toolChoice) {\n if (!((_b = (_a = this._clientCapabilities) === null || _a === void 0 ? void 0 : _a.sampling) === null || _b === void 0 ? void 0 : _b.tools)) {\n throw new Error('Client does not support sampling tools capability.');\n }\n }\n // Message structure validation - always validate tool_use/tool_result pairs.\n // These may appear even without tools/toolChoice in the current request when\n // a previous sampling request returned tool_use and this is a follow-up with results.\n if (params.messages.length > 0) {\n const lastMessage = params.messages[params.messages.length - 1];\n const lastContent = Array.isArray(lastMessage.content) ? lastMessage.content : [lastMessage.content];\n const hasToolResults = lastContent.some(c => c.type === 'tool_result');\n const previousMessage = params.messages.length > 1 ? params.messages[params.messages.length - 2] : undefined;\n const previousContent = previousMessage\n ? Array.isArray(previousMessage.content)\n ? previousMessage.content\n : [previousMessage.content]\n : [];\n const hasPreviousToolUse = previousContent.some(c => c.type === 'tool_use');\n if (hasToolResults) {\n if (lastContent.some(c => c.type !== 'tool_result')) {\n throw new Error('The last message must contain only tool_result content if any is present');\n }\n if (!hasPreviousToolUse) {\n throw new Error('tool_result blocks are not matching any tool_use from the previous message');\n }\n }\n if (hasPreviousToolUse) {\n const toolUseIds = new Set(previousContent.filter(c => c.type === 'tool_use').map(c => c.id));\n const toolResultIds = new Set(lastContent.filter(c => c.type === 'tool_result').map(c => c.toolUseId));\n if (toolUseIds.size !== toolResultIds.size || ![...toolUseIds].every(id => toolResultIds.has(id))) {\n throw new Error('ids of tool_result blocks and tool_use blocks from previous message do not match');\n }\n }\n }\n return this.request({ method: 'sampling/createMessage', params }, CreateMessageResultSchema, options);\n }\n /**\n * Creates an elicitation request for the given parameters.\n * For backwards compatibility, `mode` may be omitted for form requests and will default to `'form'`.\n * @param params The parameters for the elicitation request.\n * @param options Optional request options.\n * @returns The result of the elicitation request.\n */\n async elicitInput(params, options) {\n var _a, _b, _c, _d, _e;\n const mode = ((_a = params.mode) !== null && _a !== void 0 ? _a : 'form');\n switch (mode) {\n case 'url': {\n if (!((_c = (_b = this._clientCapabilities) === null || _b === void 0 ? void 0 : _b.elicitation) === null || _c === void 0 ? void 0 : _c.url)) {\n throw new Error('Client does not support url elicitation.');\n }\n const urlParams = params;\n return this.request({ method: 'elicitation/create', params: urlParams }, ElicitResultSchema, options);\n }\n case 'form': {\n if (!((_e = (_d = this._clientCapabilities) === null || _d === void 0 ? void 0 : _d.elicitation) === null || _e === void 0 ? void 0 : _e.form)) {\n throw new Error('Client does not support form elicitation.');\n }\n const formParams = params.mode === 'form' ? params : { ...params, mode: 'form' };\n const result = await this.request({ method: 'elicitation/create', params: formParams }, ElicitResultSchema, options);\n if (result.action === 'accept' && result.content && formParams.requestedSchema) {\n try {\n const validator = this._jsonSchemaValidator.getValidator(formParams.requestedSchema);\n const validationResult = validator(result.content);\n if (!validationResult.valid) {\n throw new McpError(ErrorCode.InvalidParams, `Elicitation response content does not match requested schema: ${validationResult.errorMessage}`);\n }\n }\n catch (error) {\n if (error instanceof McpError) {\n throw error;\n }\n throw new McpError(ErrorCode.InternalError, `Error validating elicitation response: ${error instanceof Error ? error.message : String(error)}`);\n }\n }\n return result;\n }\n }\n }\n /**\n * Creates a reusable callback that, when invoked, will send a `notifications/elicitation/complete`\n * notification for the specified elicitation ID.\n *\n * @param elicitationId The ID of the elicitation to mark as complete.\n * @param options Optional notification options. Useful when the completion notification should be related to a prior request.\n * @returns A function that emits the completion notification when awaited.\n */\n createElicitationCompletionNotifier(elicitationId, options) {\n var _a, _b;\n if (!((_b = (_a = this._clientCapabilities) === null || _a === void 0 ? void 0 : _a.elicitation) === null || _b === void 0 ? void 0 : _b.url)) {\n throw new Error('Client does not support URL elicitation (required for notifications/elicitation/complete)');\n }\n return () => this.notification({\n method: 'notifications/elicitation/complete',\n params: {\n elicitationId\n }\n }, options);\n }\n async listRoots(params, options) {\n return this.request({ method: 'roots/list', params }, ListRootsResultSchema, options);\n }\n /**\n * Sends a logging message to the client, if connected.\n * Note: You only need to send the parameters object, not the entire JSON RPC message\n * @see LoggingMessageNotification\n * @param params\n * @param sessionId optional for stateless and backward compatibility\n */\n async sendLoggingMessage(params, sessionId) {\n if (this._capabilities.logging) {\n if (!this.isMessageIgnored(params.level, sessionId)) {\n return this.notification({ method: 'notifications/message', params });\n }\n }\n }\n async sendResourceUpdated(params) {\n return this.notification({\n method: 'notifications/resources/updated',\n params\n });\n }\n async sendResourceListChanged() {\n return this.notification({\n method: 'notifications/resources/list_changed'\n });\n }\n async sendToolListChanged() {\n return this.notification({ method: 'notifications/tools/list_changed' });\n }\n async sendPromptListChanged() {\n return this.notification({ method: 'notifications/prompts/list_changed' });\n }\n}\n//# sourceMappingURL=index.js.map"],"names":["_a"],"mappings":";;;AA6BO,MAAM,eAAe,SAAS;AAAA;AAAA;AAAA;AAAA,EAIjC,YAAY,aAAa,SAAS;AAC9B,QAAI,IAAI;AACR,UAAM,OAAO;AACb,SAAK,cAAc;AAEnB,SAAK,iBAAiB,oBAAI,IAAG;AAE7B,SAAK,qBAAqB,IAAI,IAAI,mBAAmB,QAAQ,IAAI,CAAC,OAAO,UAAU,CAAC,OAAO,KAAK,CAAC,CAAC;AAElG,SAAK,mBAAmB,CAAC,OAAO,cAAc;AAC1C,YA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K,aAAa,EAAE,QAAQ,yBAAyB,OAAM,CAAE;AAAA,MACxE;AAAA,IACJ;AAAA,EACJ;AAAA,EACA,MAAM,oBAAoB,QAAQ;AAC9B,WAAO,KAAK,aAAa;AAAA,MACrB,QAAQ;AAAA,MACR;AAAA,IACZ,CAAS;AAAA,EACL;AAAA,EACA,MAAM,0BAA0B;AAC5B,WAAO,KAAK,aAAa;AAAA,MACrB,QAAQ;AAAA,IACpB,CAAS;AAAA,EACL;AAAA,EACA,MAAM,sBAAsB;AACxB,WAAO,KAAK,aAAa,EAAE,QAAQ,mCAAkC,CAAE;AAAA,EAC3E;AAAA,EACA,MAAM,wBAAwB;AAC1B,WAAO,KAAK,aAAa,EAAE,QAAQ,qCAAoC,CAAE;AAAA,EAC7E;AACJ;","x_google_ignoreList":[0]}
@@ -0,0 +1,71 @@
1
+ import { safeParse as safeParse$1 } from "../../../../../zod/v4/core/parse.js";
2
+ function isZ4Schema(s) {
3
+ const schema = s;
4
+ return !!schema._zod;
5
+ }
6
+ function safeParse(schema, data) {
7
+ if (isZ4Schema(schema)) {
8
+ const result2 = safeParse$1(schema, data);
9
+ return result2;
10
+ }
11
+ const v3Schema = schema;
12
+ const result = v3Schema.safeParse(data);
13
+ return result;
14
+ }
15
+ function getObjectShape(schema) {
16
+ var _a, _b;
17
+ if (!schema)
18
+ return void 0;
19
+ let rawShape;
20
+ if (isZ4Schema(schema)) {
21
+ const v4Schema = schema;
22
+ rawShape = (_b = (_a = v4Schema._zod) === null || _a === void 0 ? void 0 : _a.def) === null || _b === void 0 ? void 0 : _b.shape;
23
+ } else {
24
+ const v3Schema = schema;
25
+ rawShape = v3Schema.shape;
26
+ }
27
+ if (!rawShape)
28
+ return void 0;
29
+ if (typeof rawShape === "function") {
30
+ try {
31
+ return rawShape();
32
+ } catch (_c) {
33
+ return void 0;
34
+ }
35
+ }
36
+ return rawShape;
37
+ }
38
+ function getLiteralValue(schema) {
39
+ var _a;
40
+ if (isZ4Schema(schema)) {
41
+ const v4Schema = schema;
42
+ const def2 = (_a = v4Schema._zod) === null || _a === void 0 ? void 0 : _a.def;
43
+ if (def2) {
44
+ if (def2.value !== void 0)
45
+ return def2.value;
46
+ if (Array.isArray(def2.values) && def2.values.length > 0) {
47
+ return def2.values[0];
48
+ }
49
+ }
50
+ }
51
+ const v3Schema = schema;
52
+ const def = v3Schema._def;
53
+ if (def) {
54
+ if (def.value !== void 0)
55
+ return def.value;
56
+ if (Array.isArray(def.values) && def.values.length > 0) {
57
+ return def.values[0];
58
+ }
59
+ }
60
+ const directValue = schema.value;
61
+ if (directValue !== void 0)
62
+ return directValue;
63
+ return void 0;
64
+ }
65
+ export {
66
+ getLiteralValue,
67
+ getObjectShape,
68
+ isZ4Schema,
69
+ safeParse
70
+ };
71
+ //# sourceMappingURL=zod-compat.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"zod-compat.js","sources":["../../../../../../../../../../node_modules/@modelcontextprotocol/sdk/dist/esm/server/zod-compat.js"],"sourcesContent":["// zod-compat.ts\n// ----------------------------------------------------\n// Unified types + helpers to accept Zod v3 and v4 (Mini)\n// ----------------------------------------------------\nimport * as z3rt from 'zod/v3';\nimport * as z4mini from 'zod/v4-mini';\n// --- Runtime detection ---\nexport function isZ4Schema(s) {\n // Present on Zod 4 (Classic & Mini) schemas; absent on Zod 3\n const schema = s;\n return !!schema._zod;\n}\n// --- Schema construction ---\nexport function objectFromShape(shape) {\n const values = Object.values(shape);\n if (values.length === 0)\n return z4mini.object({}); // default to v4 Mini\n const allV4 = values.every(isZ4Schema);\n const allV3 = values.every(s => !isZ4Schema(s));\n if (allV4)\n return z4mini.object(shape);\n if (allV3)\n return z3rt.object(shape);\n throw new Error('Mixed Zod versions detected in object shape.');\n}\n// --- Unified parsing ---\nexport function safeParse(schema, data) {\n if (isZ4Schema(schema)) {\n // Mini exposes top-level safeParse\n const result = z4mini.safeParse(schema, data);\n return result;\n }\n const v3Schema = schema;\n const result = v3Schema.safeParse(data);\n return result;\n}\nexport async function safeParseAsync(schema, data) {\n if (isZ4Schema(schema)) {\n // Mini exposes top-level safeParseAsync\n const result = await z4mini.safeParseAsync(schema, data);\n return result;\n }\n const v3Schema = schema;\n const result = await v3Schema.safeParseAsync(data);\n return result;\n}\n// --- Shape extraction ---\nexport function getObjectShape(schema) {\n var _a, _b;\n if (!schema)\n return undefined;\n // Zod v3 exposes `.shape`; Zod v4 keeps the shape on `_zod.def.shape`\n let rawShape;\n if (isZ4Schema(schema)) {\n const v4Schema = schema;\n rawShape = (_b = (_a = v4Schema._zod) === null || _a === void 0 ? void 0 : _a.def) === null || _b === void 0 ? void 0 : _b.shape;\n }\n else {\n const v3Schema = schema;\n rawShape = v3Schema.shape;\n }\n if (!rawShape)\n return undefined;\n if (typeof rawShape === 'function') {\n try {\n return rawShape();\n }\n catch (_c) {\n return undefined;\n }\n }\n return rawShape;\n}\n// --- Schema normalization ---\n/**\n * Normalizes a schema to an object schema. Handles both:\n * - Already-constructed object schemas (v3 or v4)\n * - Raw shapes that need to be wrapped into object schemas\n */\nexport function normalizeObjectSchema(schema) {\n var _a;\n if (!schema)\n return undefined;\n // First check if it's a raw shape (Record<string, AnySchema>)\n // Raw shapes don't have _def or _zod properties and aren't schemas themselves\n if (typeof schema === 'object') {\n // Check if it's actually a ZodRawShapeCompat (not a schema instance)\n // by checking if it lacks schema-like internal properties\n const asV3 = schema;\n const asV4 = schema;\n // If it's not a schema instance (no _def or _zod), it might be a raw shape\n if (!asV3._def && !asV4._zod) {\n // Check if all values are schemas (heuristic to confirm it's a raw shape)\n const values = Object.values(schema);\n if (values.length > 0 &&\n values.every(v => typeof v === 'object' &&\n v !== null &&\n (v._def !== undefined ||\n v._zod !== undefined ||\n typeof v.parse === 'function'))) {\n return objectFromShape(schema);\n }\n }\n }\n // If we get here, it should be an AnySchema (not a raw shape)\n // Check if it's already an object schema\n if (isZ4Schema(schema)) {\n // Check if it's a v4 object\n const v4Schema = schema;\n const def = (_a = v4Schema._zod) === null || _a === void 0 ? void 0 : _a.def;\n if (def && (def.typeName === 'object' || def.shape !== undefined)) {\n return schema;\n }\n }\n else {\n // Check if it's a v3 object\n const v3Schema = schema;\n if (v3Schema.shape !== undefined) {\n return schema;\n }\n }\n return undefined;\n}\n// --- Error message extraction ---\n/**\n * Safely extracts an error message from a parse result error.\n * Zod errors can have different structures, so we handle various cases.\n */\nexport function getParseErrorMessage(error) {\n if (error && typeof error === 'object') {\n // Try common error structures\n if ('message' in error && typeof error.message === 'string') {\n return error.message;\n }\n if ('issues' in error && Array.isArray(error.issues) && error.issues.length > 0) {\n const firstIssue = error.issues[0];\n if (firstIssue && typeof firstIssue === 'object' && 'message' in firstIssue) {\n return String(firstIssue.message);\n }\n }\n // Fallback: try to stringify the error\n try {\n return JSON.stringify(error);\n }\n catch (_a) {\n return String(error);\n }\n }\n return String(error);\n}\n// --- Schema metadata access ---\n/**\n * Gets the description from a schema, if available.\n * Works with both Zod v3 and v4.\n */\nexport function getSchemaDescription(schema) {\n var _a, _b, _c, _d;\n if (isZ4Schema(schema)) {\n const v4Schema = schema;\n return (_b = (_a = v4Schema._zod) === null || _a === void 0 ? void 0 : _a.def) === null || _b === void 0 ? void 0 : _b.description;\n }\n const v3Schema = schema;\n // v3 may have description on the schema itself or in _def\n return (_c = schema.description) !== null && _c !== void 0 ? _c : (_d = v3Schema._def) === null || _d === void 0 ? void 0 : _d.description;\n}\n/**\n * Checks if a schema is optional.\n * Works with both Zod v3 and v4.\n */\nexport function isSchemaOptional(schema) {\n var _a, _b, _c;\n if (isZ4Schema(schema)) {\n const v4Schema = schema;\n return ((_b = (_a = v4Schema._zod) === null || _a === void 0 ? void 0 : _a.def) === null || _b === void 0 ? void 0 : _b.typeName) === 'ZodOptional';\n }\n const v3Schema = schema;\n // v3 has isOptional() method\n if (typeof schema.isOptional === 'function') {\n return schema.isOptional();\n }\n return ((_c = v3Schema._def) === null || _c === void 0 ? void 0 : _c.typeName) === 'ZodOptional';\n}\n/**\n * Gets the literal value from a schema, if it's a literal schema.\n * Works with both Zod v3 and v4.\n * Returns undefined if the schema is not a literal or the value cannot be determined.\n */\nexport function getLiteralValue(schema) {\n var _a;\n if (isZ4Schema(schema)) {\n const v4Schema = schema;\n const def = (_a = v4Schema._zod) === null || _a === void 0 ? void 0 : _a.def;\n if (def) {\n // Try various ways to get the literal value\n if (def.value !== undefined)\n return def.value;\n if (Array.isArray(def.values) && def.values.length > 0) {\n return def.values[0];\n }\n }\n }\n const v3Schema = schema;\n const def = v3Schema._def;\n if (def) {\n if (def.value !== undefined)\n return def.value;\n if (Array.isArray(def.values) && def.values.length > 0) {\n return def.values[0];\n }\n }\n // Fallback: check for direct value property (some Zod versions)\n const directValue = schema.value;\n if (directValue !== undefined)\n return directValue;\n return undefined;\n}\n//# sourceMappingURL=zod-compat.js.map"],"names":["result","z4mini.safeParse","def"],"mappings":";AAOO,SAAS,WAAW,GAAG;AAE1B,QAAM,SAAS;AACf,SAAO,CAAC,CAAC,OAAO;AACpB;AAeO,SAAS,UAAU,QAAQ,MAAM;AACpC,MAAI,WAAW,MAAM,GAAG;AAEpB,UAAMA,UAASC,YAAiB,QAAQ,IAAI;AAC5C,WAAOD;AAAA,EACX;AACA,QAAM,WAAW;AACjB,QAAM,SAAS,SAAS,UAAU,IAAI;AACtC,SAAO;AACX;AAYO,SAAS,eAAe,QAAQ;AACnC,MAAI,IAAI;AACR,MAAI,CAAC;AACD,WAAO;AAEX,MAAI;AACJ,MAAI,WAAW,MAAM,GAAG;AACpB,UAAM,WAAW;AACjB,gBAAY,MAAM,KAAK,SAAS,UAAU,QAAQ,OAAO,SAAS,SAAS,GAAG,SAAS,QAAQ,OAAO,SAAS,SAAS,GAAG;AAAA,EAC/H,OACK;AACD,UAAM,WAAW;AACjB,eAAW,SAAS;AAAA,EACxB;AACA,MAAI,CAAC;AACD,WAAO;AACX,MAAI,OAAO,aAAa,YAAY;AAChC,QAAI;AACA,aAAO,SAAQ;AAAA,IACnB,SACO,IAAI;AACP,aAAO;AAAA,IACX;AAAA,EACJ;AACA,SAAO;AACX;AAmHO,SAAS,gBAAgB,QAAQ;AACpC,MAAI;AACJ,MAAI,WAAW,MAAM,GAAG;AACpB,UAAM,WAAW;AACjB,UAAME,QAAO,KAAK,SAAS,UAAU,QAAQ,OAAO,SAAS,SAAS,GAAG;AACzE,QAAIA,MAAK;AAEL,UAAIA,KAAI,UAAU;AACd,eAAOA,KAAI;AACf,UAAI,MAAM,QAAQA,KAAI,MAAM,KAAKA,KAAI,OAAO,SAAS,GAAG;AACpD,eAAOA,KAAI,OAAO,CAAC;AAAA,MACvB;AAAA,IACJ;AAAA,EACJ;AACA,QAAM,WAAW;AACjB,QAAM,MAAM,SAAS;AACrB,MAAI,KAAK;AACL,QAAI,IAAI,UAAU;AACd,aAAO,IAAI;AACf,QAAI,MAAM,QAAQ,IAAI,MAAM,KAAK,IAAI,OAAO,SAAS,GAAG;AACpD,aAAO,IAAI,OAAO,CAAC;AAAA,IACvB;AAAA,EACJ;AAEA,QAAM,cAAc,OAAO;AAC3B,MAAI,gBAAgB;AAChB,WAAO;AACX,SAAO;AACX;","x_google_ignoreList":[0]}
@@ -0,0 +1,26 @@
1
+ import { getObjectShape, getLiteralValue, safeParse } from "./zod-compat.js";
2
+ import "../../../../../zod-to-json-schema/dist/esm/parsers/string.js";
3
+ function getMethodLiteral(schema) {
4
+ const shape = getObjectShape(schema);
5
+ const methodSchema = shape === null || shape === void 0 ? void 0 : shape.method;
6
+ if (!methodSchema) {
7
+ throw new Error("Schema is missing a method literal");
8
+ }
9
+ const value = getLiteralValue(methodSchema);
10
+ if (typeof value !== "string") {
11
+ throw new Error("Schema method literal must be a string");
12
+ }
13
+ return value;
14
+ }
15
+ function parseWithCompat(schema, data) {
16
+ const result = safeParse(schema, data);
17
+ if (!result.success) {
18
+ throw result.error;
19
+ }
20
+ return result.data;
21
+ }
22
+ export {
23
+ getMethodLiteral,
24
+ parseWithCompat
25
+ };
26
+ //# sourceMappingURL=zod-json-schema-compat.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"zod-json-schema-compat.js","sources":["../../../../../../../../../../node_modules/@modelcontextprotocol/sdk/dist/esm/server/zod-json-schema-compat.js"],"sourcesContent":["// zod-json-schema-compat.ts\n// ----------------------------------------------------\n// JSON Schema conversion for both Zod v3 and Zod v4 (Mini)\n// v3 uses your vendored converter; v4 uses Mini's toJSONSchema\n// ----------------------------------------------------\nimport * as z4mini from 'zod/v4-mini';\nimport { getObjectShape, safeParse, isZ4Schema, getLiteralValue } from './zod-compat.js';\nimport { zodToJsonSchema } from 'zod-to-json-schema';\nfunction mapMiniTarget(t) {\n if (!t)\n return 'draft-7';\n if (t === 'jsonSchema7' || t === 'draft-7')\n return 'draft-7';\n if (t === 'jsonSchema2019-09' || t === 'draft-2020-12')\n return 'draft-2020-12';\n return 'draft-7'; // fallback\n}\nexport function toJsonSchemaCompat(schema, opts) {\n var _a, _b, _c;\n if (isZ4Schema(schema)) {\n // v4 branch — use Mini's built-in toJSONSchema\n return z4mini.toJSONSchema(schema, {\n target: mapMiniTarget(opts === null || opts === void 0 ? void 0 : opts.target),\n io: (_a = opts === null || opts === void 0 ? void 0 : opts.pipeStrategy) !== null && _a !== void 0 ? _a : 'input'\n });\n }\n // v3 branch — use vendored converter\n return zodToJsonSchema(schema, {\n strictUnions: (_b = opts === null || opts === void 0 ? void 0 : opts.strictUnions) !== null && _b !== void 0 ? _b : true,\n pipeStrategy: (_c = opts === null || opts === void 0 ? void 0 : opts.pipeStrategy) !== null && _c !== void 0 ? _c : 'input'\n });\n}\nexport function getMethodLiteral(schema) {\n const shape = getObjectShape(schema);\n const methodSchema = shape === null || shape === void 0 ? void 0 : shape.method;\n if (!methodSchema) {\n throw new Error('Schema is missing a method literal');\n }\n const value = getLiteralValue(methodSchema);\n if (typeof value !== 'string') {\n throw new Error('Schema method literal must be a string');\n }\n return value;\n}\nexport function parseWithCompat(schema, data) {\n const result = safeParse(schema, data);\n if (!result.success) {\n throw result.error;\n }\n return result.data;\n}\n//# sourceMappingURL=zod-json-schema-compat.js.map"],"names":[],"mappings":";;AAgCO,SAAS,iBAAiB,QAAQ;AACrC,QAAM,QAAQ,eAAe,MAAM;AACnC,QAAM,eAAe,UAAU,QAAQ,UAAU,SAAS,SAAS,MAAM;AACzE,MAAI,CAAC,cAAc;AACf,UAAM,IAAI,MAAM,oCAAoC;AAAA,EACxD;AACA,QAAM,QAAQ,gBAAgB,YAAY;AAC1C,MAAI,OAAO,UAAU,UAAU;AAC3B,UAAM,IAAI,MAAM,wCAAwC;AAAA,EAC5D;AACA,SAAO;AACX;AACO,SAAS,gBAAgB,QAAQ,MAAM;AAC1C,QAAM,SAAS,UAAU,QAAQ,IAAI;AACrC,MAAI,CAAC,OAAO,SAAS;AACjB,UAAM,OAAO;AAAA,EACjB;AACA,SAAO,OAAO;AAClB;","x_google_ignoreList":[0]}