docorbit 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (402) hide show
  1. package/bin/docorbit.js +2 -2
  2. package/dist/apps/cli/src/commands/add.d.ts +7 -0
  3. package/dist/apps/cli/src/commands/add.js +35 -0
  4. package/dist/apps/cli/src/commands/api.d.ts +2 -0
  5. package/dist/apps/cli/src/commands/api.js +35 -0
  6. package/dist/apps/cli/src/commands/context.d.ts +10 -0
  7. package/dist/apps/cli/src/commands/context.js +36 -0
  8. package/dist/apps/cli/src/commands/dashboard.d.ts +8 -0
  9. package/dist/apps/cli/src/commands/dashboard.js +43 -0
  10. package/dist/apps/cli/src/commands/diff.d.ts +2 -0
  11. package/dist/apps/cli/src/commands/diff.js +29 -0
  12. package/dist/apps/cli/src/commands/evaluate.d.ts +11 -0
  13. package/dist/apps/cli/src/commands/evaluate.js +101 -0
  14. package/dist/apps/cli/src/commands/examples.d.ts +2 -0
  15. package/dist/apps/cli/src/commands/examples.js +36 -0
  16. package/dist/apps/cli/src/commands/export.d.ts +11 -0
  17. package/dist/apps/cli/src/commands/export.js +72 -0
  18. package/dist/apps/cli/src/commands/impact.d.ts +2 -0
  19. package/dist/apps/cli/src/commands/impact.js +30 -0
  20. package/dist/apps/cli/src/commands/init.d.ts +5 -0
  21. package/dist/apps/cli/src/commands/init.js +52 -0
  22. package/dist/apps/cli/src/commands/inspect.d.ts +5 -0
  23. package/dist/apps/cli/src/commands/inspect.js +24 -0
  24. package/dist/apps/cli/src/commands/mcp.d.ts +8 -0
  25. package/dist/apps/cli/src/commands/mcp.js +49 -0
  26. package/dist/apps/cli/src/commands/pitfalls.d.ts +2 -0
  27. package/dist/apps/cli/src/commands/pitfalls.js +35 -0
  28. package/dist/apps/cli/src/commands/recipes.d.ts +2 -0
  29. package/dist/apps/cli/src/commands/recipes.js +33 -0
  30. package/dist/apps/cli/src/commands/search.d.ts +11 -0
  31. package/dist/apps/cli/src/commands/search.js +36 -0
  32. package/dist/apps/cli/src/commands/update.d.ts +6 -0
  33. package/dist/apps/cli/src/commands/update.js +53 -0
  34. package/dist/apps/cli/src/commands/verify.d.ts +2 -0
  35. package/dist/apps/cli/src/commands/verify.js +44 -0
  36. package/dist/apps/cli/src/formatters/colors.d.ts +21 -0
  37. package/dist/apps/cli/src/formatters/colors.js +22 -0
  38. package/dist/apps/cli/src/formatters/inspection.d.ts +3 -0
  39. package/dist/apps/cli/src/formatters/inspection.js +88 -0
  40. package/dist/apps/cli/src/formatters/knowledge.d.ts +5 -0
  41. package/dist/apps/cli/src/formatters/knowledge.js +229 -0
  42. package/dist/apps/cli/src/formatters/retrieval.d.ts +3 -0
  43. package/dist/apps/cli/src/formatters/retrieval.js +61 -0
  44. package/{apps/cli/src/formatters/terminal.ts → dist/apps/cli/src/formatters/terminal.d.ts} +0 -1
  45. package/dist/apps/cli/src/formatters/terminal.js +5 -0
  46. package/dist/apps/cli/src/formatters/verification.d.ts +4 -0
  47. package/dist/apps/cli/src/formatters/verification.js +102 -0
  48. package/dist/apps/cli/src/index.d.ts +1 -0
  49. package/dist/apps/cli/src/index.js +376 -0
  50. package/dist/packages/core/src/dashboard/server.d.ts +33 -0
  51. package/dist/packages/core/src/dashboard/server.js +267 -0
  52. package/dist/packages/core/src/dashboard/ui.d.ts +5 -0
  53. package/{packages/core/src/dashboard/ui.ts → dist/packages/core/src/dashboard/ui.js} +2 -2
  54. package/dist/packages/core/src/implementation-service.d.ts +73 -0
  55. package/dist/packages/core/src/implementation-service.js +325 -0
  56. package/{packages/core/src/index.ts → dist/packages/core/src/index.d.ts} +0 -1
  57. package/dist/packages/core/src/index.js +6 -0
  58. package/dist/packages/core/src/inspector.d.ts +22 -0
  59. package/dist/packages/core/src/inspector.js +38 -0
  60. package/dist/packages/core/src/pipeline.d.ts +45 -0
  61. package/dist/packages/core/src/pipeline.js +246 -0
  62. package/dist/packages/crawler/src/config.d.ts +2 -0
  63. package/dist/packages/crawler/src/config.js +10 -0
  64. package/dist/packages/crawler/src/fetcher.d.ts +31 -0
  65. package/dist/packages/crawler/src/fetcher.js +139 -0
  66. package/dist/packages/crawler/src/index.js +2 -0
  67. package/dist/packages/discovery/src/index.d.ts +11 -0
  68. package/dist/packages/discovery/src/index.js +29 -0
  69. package/dist/packages/discovery/src/provider.d.ts +12 -0
  70. package/dist/packages/discovery/src/provider.js +30 -0
  71. package/dist/packages/discovery/src/providers/generic.d.ts +7 -0
  72. package/dist/packages/discovery/src/providers/generic.js +94 -0
  73. package/dist/packages/discovery/src/providers/github.d.ts +7 -0
  74. package/dist/packages/discovery/src/providers/github.js +52 -0
  75. package/dist/packages/discovery/src/providers/llms-txt.d.ts +7 -0
  76. package/dist/packages/discovery/src/providers/llms-txt.js +60 -0
  77. package/dist/packages/discovery/src/providers/markdown.d.ts +7 -0
  78. package/dist/packages/discovery/src/providers/markdown.js +38 -0
  79. package/dist/packages/discovery/src/providers/openapi.d.ts +7 -0
  80. package/dist/packages/discovery/src/providers/openapi.js +77 -0
  81. package/dist/packages/discovery/src/providers/sitemap.d.ts +7 -0
  82. package/dist/packages/discovery/src/providers/sitemap.js +53 -0
  83. package/dist/packages/discovery/src/providers/skill.d.ts +7 -0
  84. package/dist/packages/discovery/src/providers/skill.js +46 -0
  85. package/dist/packages/discovery/src/ranker.d.ts +6 -0
  86. package/dist/packages/discovery/src/ranker.js +107 -0
  87. package/dist/packages/evaluation/src/dataset.d.ts +2 -0
  88. package/dist/packages/evaluation/src/dataset.js +944 -0
  89. package/dist/packages/evaluation/src/index.js +8 -0
  90. package/dist/packages/evaluation/src/runner.d.ts +7 -0
  91. package/dist/packages/evaluation/src/runner.js +196 -0
  92. package/dist/packages/evaluation/src/strategies/context7-runner.d.ts +24 -0
  93. package/dist/packages/evaluation/src/strategies/context7-runner.js +229 -0
  94. package/dist/packages/evaluation/src/strategies/docorbit-runner.d.ts +5 -0
  95. package/dist/packages/evaluation/src/strategies/docorbit-runner.js +210 -0
  96. package/dist/packages/evaluation/src/strategies/firecrawl-runner.d.ts +24 -0
  97. package/dist/packages/evaluation/src/strategies/firecrawl-runner.js +151 -0
  98. package/dist/packages/evaluation/src/strategies/web-search-runner.d.ts +32 -0
  99. package/dist/packages/evaluation/src/strategies/web-search-runner.js +161 -0
  100. package/dist/packages/evaluation/src/types.d.ts +15 -0
  101. package/dist/packages/evaluation/src/types.js +1 -0
  102. package/dist/packages/evaluation/src/version-matcher.d.ts +11 -0
  103. package/dist/packages/evaluation/src/version-matcher.js +61 -0
  104. package/dist/packages/export/src/agents-md.d.ts +19 -0
  105. package/dist/packages/export/src/agents-md.js +170 -0
  106. package/dist/packages/export/src/claude-md.d.ts +17 -0
  107. package/dist/packages/export/src/claude-md.js +118 -0
  108. package/dist/packages/export/src/docs-map.d.ts +14 -0
  109. package/dist/packages/export/src/docs-map.js +118 -0
  110. package/dist/packages/export/src/index.js +6 -0
  111. package/dist/packages/export/src/llms-txt.d.ts +15 -0
  112. package/dist/packages/export/src/llms-txt.js +73 -0
  113. package/dist/packages/export/src/service.d.ts +23 -0
  114. package/dist/packages/export/src/service.js +210 -0
  115. package/dist/packages/export/src/skill-md.d.ts +14 -0
  116. package/dist/packages/export/src/skill-md.js +107 -0
  117. package/{packages/mcp/src/index.ts → dist/packages/mcp/src/index.d.ts} +2 -35
  118. package/dist/packages/mcp/src/index.js +6 -0
  119. package/dist/packages/mcp/src/resources/index.d.ts +12 -0
  120. package/dist/packages/mcp/src/resources/index.js +165 -0
  121. package/dist/packages/mcp/src/server.d.ts +30 -0
  122. package/dist/packages/mcp/src/server.js +243 -0
  123. package/dist/packages/mcp/src/tools/analyze-impact.d.ts +6 -0
  124. package/dist/packages/mcp/src/tools/analyze-impact.js +64 -0
  125. package/dist/packages/mcp/src/tools/check-api.d.ts +6 -0
  126. package/dist/packages/mcp/src/tools/check-api.js +74 -0
  127. package/dist/packages/mcp/src/tools/diff-docs.d.ts +6 -0
  128. package/dist/packages/mcp/src/tools/diff-docs.js +58 -0
  129. package/dist/packages/mcp/src/tools/export-context.d.ts +6 -0
  130. package/dist/packages/mcp/src/tools/export-context.js +61 -0
  131. package/dist/packages/mcp/src/tools/find-api.d.ts +6 -0
  132. package/dist/packages/mcp/src/tools/find-api.js +91 -0
  133. package/dist/packages/mcp/src/tools/find-example.d.ts +6 -0
  134. package/dist/packages/mcp/src/tools/find-example.js +92 -0
  135. package/dist/packages/mcp/src/tools/find-pitfall.d.ts +6 -0
  136. package/dist/packages/mcp/src/tools/find-pitfall.js +85 -0
  137. package/dist/packages/mcp/src/tools/find-recipe.d.ts +6 -0
  138. package/dist/packages/mcp/src/tools/find-recipe.js +89 -0
  139. package/dist/packages/mcp/src/tools/get-doc.d.ts +6 -0
  140. package/dist/packages/mcp/src/tools/get-doc.js +118 -0
  141. package/dist/packages/mcp/src/tools/get-docs-map.d.ts +6 -0
  142. package/dist/packages/mcp/src/tools/get-docs-map.js +54 -0
  143. package/dist/packages/mcp/src/tools/get-version.d.ts +6 -0
  144. package/dist/packages/mcp/src/tools/get-version.js +104 -0
  145. package/dist/packages/mcp/src/tools/implementation-context.d.ts +6 -0
  146. package/dist/packages/mcp/src/tools/implementation-context.js +82 -0
  147. package/dist/packages/mcp/src/tools/index.d.ts +18 -0
  148. package/dist/packages/mcp/src/tools/index.js +39 -0
  149. package/dist/packages/mcp/src/tools/list-sources.d.ts +6 -0
  150. package/dist/packages/mcp/src/tools/list-sources.js +76 -0
  151. package/dist/packages/mcp/src/tools/search-docs.d.ts +6 -0
  152. package/dist/packages/mcp/src/tools/search-docs.js +113 -0
  153. package/dist/packages/mcp/src/tools/types.d.ts +22 -0
  154. package/dist/packages/mcp/src/tools/types.js +1 -0
  155. package/dist/packages/mcp/src/transports/http.d.ts +31 -0
  156. package/dist/packages/mcp/src/transports/http.js +215 -0
  157. package/dist/packages/mcp/src/transports/stdio.d.ts +22 -0
  158. package/dist/packages/mcp/src/transports/stdio.js +86 -0
  159. package/{packages/mcp/src/transports/types.ts → dist/packages/mcp/src/transports/types.d.ts} +2 -3
  160. package/dist/packages/mcp/src/transports/types.js +1 -0
  161. package/dist/packages/mcp/src/types.d.ts +89 -0
  162. package/dist/packages/mcp/src/types.js +7 -0
  163. package/dist/packages/normalizer/src/example-indexer.d.ts +5 -0
  164. package/dist/packages/normalizer/src/example-indexer.js +200 -0
  165. package/dist/packages/normalizer/src/html.d.ts +13 -0
  166. package/dist/packages/normalizer/src/html.js +221 -0
  167. package/{packages/normalizer/src/index.ts → dist/packages/normalizer/src/index.d.ts} +0 -1
  168. package/dist/packages/normalizer/src/index.js +7 -0
  169. package/dist/packages/normalizer/src/llms.d.ts +3 -0
  170. package/dist/packages/normalizer/src/llms.js +71 -0
  171. package/dist/packages/normalizer/src/openapi/endpoint-parser.d.ts +11 -0
  172. package/dist/packages/normalizer/src/openapi/endpoint-parser.js +357 -0
  173. package/dist/packages/normalizer/src/openapi/schema-resolver.d.ts +10 -0
  174. package/dist/packages/normalizer/src/openapi/schema-resolver.js +82 -0
  175. package/dist/packages/normalizer/src/openapi.js +2 -0
  176. package/dist/packages/normalizer/src/page.d.ts +13 -0
  177. package/dist/packages/normalizer/src/page.js +150 -0
  178. package/dist/packages/normalizer/src/pitfall-extractor.d.ts +6 -0
  179. package/dist/packages/normalizer/src/pitfall-extractor.js +153 -0
  180. package/dist/packages/normalizer/src/slicer.d.ts +30 -0
  181. package/dist/packages/normalizer/src/slicer.js +360 -0
  182. package/dist/packages/retrieval/src/engine.d.ts +17 -0
  183. package/dist/packages/retrieval/src/engine.js +93 -0
  184. package/{packages/retrieval/src/index.ts → dist/packages/retrieval/src/index.d.ts} +0 -1
  185. package/dist/packages/retrieval/src/index.js +6 -0
  186. package/dist/packages/retrieval/src/intent.d.ts +6 -0
  187. package/dist/packages/retrieval/src/intent.js +39 -0
  188. package/dist/packages/retrieval/src/packer.d.ts +2 -0
  189. package/dist/packages/retrieval/src/packer.js +108 -0
  190. package/dist/packages/retrieval/src/recipe-engine.d.ts +18 -0
  191. package/dist/packages/retrieval/src/recipe-engine.js +265 -0
  192. package/dist/packages/retrieval/src/scorer.d.ts +13 -0
  193. package/dist/packages/retrieval/src/scorer.js +110 -0
  194. package/dist/packages/retrieval/src/weights.d.ts +3 -0
  195. package/dist/packages/retrieval/src/weights.js +28 -0
  196. package/dist/packages/security/src/annotations.d.ts +10 -0
  197. package/dist/packages/security/src/annotations.js +100 -0
  198. package/dist/packages/security/src/index.js +2 -0
  199. package/dist/packages/security/src/ssrf.d.ts +17 -0
  200. package/dist/packages/security/src/ssrf.js +132 -0
  201. package/dist/packages/shared/src/errors.d.ts +22 -0
  202. package/dist/packages/shared/src/errors.js +44 -0
  203. package/dist/packages/shared/src/hashing.d.ts +3 -0
  204. package/dist/packages/shared/src/hashing.js +21 -0
  205. package/dist/packages/shared/src/index.js +3 -0
  206. package/dist/packages/shared/src/types.d.ts +715 -0
  207. package/dist/packages/shared/src/types.js +1 -0
  208. package/dist/packages/storage/src/db.d.ts +10 -0
  209. package/dist/packages/storage/src/db.js +61 -0
  210. package/dist/packages/storage/src/index.js +10 -0
  211. package/dist/packages/storage/src/interfaces.d.ts +83 -0
  212. package/dist/packages/storage/src/interfaces.js +1 -0
  213. package/dist/packages/storage/src/repositories/api-repository.d.ts +16 -0
  214. package/dist/packages/storage/src/repositories/api-repository.js +169 -0
  215. package/dist/packages/storage/src/repositories/chunk-repository.d.ts +32 -0
  216. package/dist/packages/storage/src/repositories/chunk-repository.js +250 -0
  217. package/dist/packages/storage/src/repositories/example-repository.d.ts +16 -0
  218. package/dist/packages/storage/src/repositories/example-repository.js +158 -0
  219. package/dist/packages/storage/src/repositories/page-repository.d.ts +16 -0
  220. package/dist/packages/storage/src/repositories/page-repository.js +161 -0
  221. package/dist/packages/storage/src/repositories/pitfall-repository.d.ts +15 -0
  222. package/dist/packages/storage/src/repositories/pitfall-repository.js +144 -0
  223. package/dist/packages/storage/src/repositories/source-repository.d.ts +33 -0
  224. package/dist/packages/storage/src/repositories/source-repository.js +153 -0
  225. package/dist/packages/storage/src/repository.d.ts +92 -0
  226. package/dist/packages/storage/src/repository.js +157 -0
  227. package/dist/packages/storage/src/schema.d.ts +2 -0
  228. package/{packages/storage/src/schema.ts → dist/packages/storage/src/schema.js} +0 -3
  229. package/dist/packages/storage/src/search-tokens.d.ts +6 -0
  230. package/dist/packages/storage/src/search-tokens.js +26 -0
  231. package/dist/packages/verification/src/diff-engine.d.ts +18 -0
  232. package/dist/packages/verification/src/diff-engine.js +218 -0
  233. package/dist/packages/verification/src/extractor.d.ts +29 -0
  234. package/dist/packages/verification/src/extractor.js +302 -0
  235. package/dist/packages/verification/src/impact-scanner.d.ts +9 -0
  236. package/dist/packages/verification/src/impact-scanner.js +181 -0
  237. package/dist/packages/verification/src/index.js +5 -0
  238. package/dist/packages/verification/src/services.d.ts +55 -0
  239. package/dist/packages/verification/src/services.js +189 -0
  240. package/dist/packages/verification/src/verifier.d.ts +15 -0
  241. package/dist/packages/verification/src/verifier.js +315 -0
  242. package/dist/packages/workspace/src/detector.d.ts +7 -0
  243. package/dist/packages/workspace/src/detector.js +117 -0
  244. package/dist/packages/workspace/src/ecosystems/cargo.d.ts +10 -0
  245. package/dist/packages/workspace/src/ecosystems/cargo.js +69 -0
  246. package/dist/packages/workspace/src/ecosystems/composer.d.ts +7 -0
  247. package/dist/packages/workspace/src/ecosystems/composer.js +40 -0
  248. package/dist/packages/workspace/src/ecosystems/go.d.ts +7 -0
  249. package/dist/packages/workspace/src/ecosystems/go.js +49 -0
  250. package/{packages/workspace/src/ecosystems/index.ts → dist/packages/workspace/src/ecosystems/index.d.ts} +2 -24
  251. package/dist/packages/workspace/src/ecosystems/index.js +21 -0
  252. package/dist/packages/workspace/src/ecosystems/maven.d.ts +7 -0
  253. package/dist/packages/workspace/src/ecosystems/maven.js +28 -0
  254. package/dist/packages/workspace/src/ecosystems/npm.d.ts +10 -0
  255. package/dist/packages/workspace/src/ecosystems/npm.js +73 -0
  256. package/dist/packages/workspace/src/ecosystems/pub.d.ts +7 -0
  257. package/dist/packages/workspace/src/ecosystems/pub.js +34 -0
  258. package/dist/packages/workspace/src/ecosystems/pypi.d.ts +9 -0
  259. package/dist/packages/workspace/src/ecosystems/pypi.js +94 -0
  260. package/dist/packages/workspace/src/ecosystems/rubygems.d.ts +7 -0
  261. package/dist/packages/workspace/src/ecosystems/rubygems.js +25 -0
  262. package/dist/packages/workspace/src/ecosystems/types.d.ts +9 -0
  263. package/dist/packages/workspace/src/ecosystems/types.js +1 -0
  264. package/dist/packages/workspace/src/index.js +5 -0
  265. package/dist/packages/workspace/src/lockfile.d.ts +21 -0
  266. package/dist/packages/workspace/src/lockfile.js +153 -0
  267. package/dist/packages/workspace/src/resolver.d.ts +39 -0
  268. package/dist/packages/workspace/src/resolver.js +164 -0
  269. package/dist/packages/workspace/src/semver.d.ts +33 -0
  270. package/dist/packages/workspace/src/semver.js +235 -0
  271. package/package.json +8 -7
  272. package/apps/cli/bin/docorbit.js +0 -8
  273. package/apps/cli/src/commands/add.ts +0 -44
  274. package/apps/cli/src/commands/api.ts +0 -38
  275. package/apps/cli/src/commands/context.ts +0 -47
  276. package/apps/cli/src/commands/dashboard.ts +0 -55
  277. package/apps/cli/src/commands/diff.ts +0 -30
  278. package/apps/cli/src/commands/evaluate.ts +0 -133
  279. package/apps/cli/src/commands/examples.ts +0 -39
  280. package/apps/cli/src/commands/export.ts +0 -89
  281. package/apps/cli/src/commands/impact.ts +0 -31
  282. package/apps/cli/src/commands/init.ts +0 -69
  283. package/apps/cli/src/commands/inspect.ts +0 -30
  284. package/apps/cli/src/commands/mcp.ts +0 -72
  285. package/apps/cli/src/commands/pitfalls.ts +0 -38
  286. package/apps/cli/src/commands/recipes.ts +0 -35
  287. package/apps/cli/src/commands/search.ts +0 -48
  288. package/apps/cli/src/commands/update.ts +0 -73
  289. package/apps/cli/src/commands/verify.ts +0 -48
  290. package/apps/cli/src/formatters/colors.ts +0 -23
  291. package/apps/cli/src/formatters/inspection.ts +0 -102
  292. package/apps/cli/src/formatters/knowledge.ts +0 -272
  293. package/apps/cli/src/formatters/retrieval.ts +0 -74
  294. package/apps/cli/src/formatters/verification.ts +0 -126
  295. package/apps/cli/src/index.ts +0 -409
  296. package/packages/core/src/dashboard/server.ts +0 -314
  297. package/packages/core/src/implementation-service.ts +0 -451
  298. package/packages/core/src/inspector.ts +0 -71
  299. package/packages/core/src/pipeline.ts +0 -331
  300. package/packages/crawler/src/config.ts +0 -12
  301. package/packages/crawler/src/fetcher.ts +0 -185
  302. package/packages/discovery/src/index.ts +0 -31
  303. package/packages/discovery/src/provider.ts +0 -47
  304. package/packages/discovery/src/providers/generic.ts +0 -98
  305. package/packages/discovery/src/providers/github.ts +0 -61
  306. package/packages/discovery/src/providers/llms-txt.ts +0 -73
  307. package/packages/discovery/src/providers/markdown.ts +0 -48
  308. package/packages/discovery/src/providers/openapi.ts +0 -91
  309. package/packages/discovery/src/providers/sitemap.ts +0 -62
  310. package/packages/discovery/src/providers/skill.ts +0 -54
  311. package/packages/discovery/src/ranker.ts +0 -123
  312. package/packages/evaluation/src/dataset.ts +0 -963
  313. package/packages/evaluation/src/runner.ts +0 -241
  314. package/packages/evaluation/src/strategies/context7-runner.ts +0 -269
  315. package/packages/evaluation/src/strategies/docorbit-runner.ts +0 -228
  316. package/packages/evaluation/src/strategies/firecrawl-runner.ts +0 -172
  317. package/packages/evaluation/src/strategies/web-search-runner.ts +0 -194
  318. package/packages/evaluation/src/types.ts +0 -34
  319. package/packages/evaluation/src/version-matcher.ts +0 -73
  320. package/packages/export/src/agents-md.ts +0 -200
  321. package/packages/export/src/claude-md.ts +0 -141
  322. package/packages/export/src/docs-map.ts +0 -150
  323. package/packages/export/src/llms-txt.ts +0 -96
  324. package/packages/export/src/service.ts +0 -250
  325. package/packages/export/src/skill-md.ts +0 -128
  326. package/packages/mcp/src/resources/index.ts +0 -189
  327. package/packages/mcp/src/server.ts +0 -278
  328. package/packages/mcp/src/tools/analyze-impact.ts +0 -74
  329. package/packages/mcp/src/tools/check-api.ts +0 -86
  330. package/packages/mcp/src/tools/diff-docs.ts +0 -68
  331. package/packages/mcp/src/tools/export-context.ts +0 -73
  332. package/packages/mcp/src/tools/find-api.ts +0 -99
  333. package/packages/mcp/src/tools/find-example.ts +0 -100
  334. package/packages/mcp/src/tools/find-pitfall.ts +0 -94
  335. package/packages/mcp/src/tools/find-recipe.ts +0 -98
  336. package/packages/mcp/src/tools/get-doc.ts +0 -130
  337. package/packages/mcp/src/tools/get-docs-map.ts +0 -64
  338. package/packages/mcp/src/tools/get-version.ts +0 -118
  339. package/packages/mcp/src/tools/implementation-context.ts +0 -88
  340. package/packages/mcp/src/tools/index.ts +0 -59
  341. package/packages/mcp/src/tools/list-sources.ts +0 -85
  342. package/packages/mcp/src/tools/search-docs.ts +0 -123
  343. package/packages/mcp/src/tools/types.ts +0 -28
  344. package/packages/mcp/src/transports/http.ts +0 -256
  345. package/packages/mcp/src/transports/stdio.ts +0 -105
  346. package/packages/mcp/src/types.ts +0 -102
  347. package/packages/normalizer/src/example-indexer.ts +0 -240
  348. package/packages/normalizer/src/html.ts +0 -253
  349. package/packages/normalizer/src/llms.ts +0 -83
  350. package/packages/normalizer/src/openapi/endpoint-parser.ts +0 -406
  351. package/packages/normalizer/src/openapi/schema-resolver.ts +0 -111
  352. package/packages/normalizer/src/page.ts +0 -184
  353. package/packages/normalizer/src/pitfall-extractor.ts +0 -190
  354. package/packages/normalizer/src/slicer.ts +0 -455
  355. package/packages/retrieval/src/engine.ts +0 -120
  356. package/packages/retrieval/src/intent.ts +0 -43
  357. package/packages/retrieval/src/packer.ts +0 -145
  358. package/packages/retrieval/src/recipe-engine.ts +0 -313
  359. package/packages/retrieval/src/scorer.ts +0 -139
  360. package/packages/retrieval/src/weights.ts +0 -31
  361. package/packages/security/src/annotations.ts +0 -112
  362. package/packages/security/src/ssrf.ts +0 -153
  363. package/packages/shared/src/errors.ts +0 -53
  364. package/packages/shared/src/hashing.ts +0 -23
  365. package/packages/shared/src/types.ts +0 -881
  366. package/packages/storage/src/db.ts +0 -72
  367. package/packages/storage/src/interfaces.ts +0 -115
  368. package/packages/storage/src/repositories/api-repository.ts +0 -219
  369. package/packages/storage/src/repositories/chunk-repository.ts +0 -316
  370. package/packages/storage/src/repositories/example-repository.ts +0 -206
  371. package/packages/storage/src/repositories/page-repository.ts +0 -205
  372. package/packages/storage/src/repositories/pitfall-repository.ts +0 -188
  373. package/packages/storage/src/repositories/source-repository.ts +0 -205
  374. package/packages/storage/src/repository.ts +0 -256
  375. package/packages/storage/src/search-tokens.ts +0 -28
  376. package/packages/verification/src/diff-engine.ts +0 -258
  377. package/packages/verification/src/extractor.ts +0 -339
  378. package/packages/verification/src/impact-scanner.ts +0 -203
  379. package/packages/verification/src/services.ts +0 -238
  380. package/packages/verification/src/verifier.ts +0 -375
  381. package/packages/workspace/src/detector.ts +0 -143
  382. package/packages/workspace/src/ecosystems/cargo.ts +0 -84
  383. package/packages/workspace/src/ecosystems/composer.ts +0 -42
  384. package/packages/workspace/src/ecosystems/go.ts +0 -54
  385. package/packages/workspace/src/ecosystems/maven.ts +0 -34
  386. package/packages/workspace/src/ecosystems/npm.ts +0 -83
  387. package/packages/workspace/src/ecosystems/pub.ts +0 -40
  388. package/packages/workspace/src/ecosystems/pypi.ts +0 -100
  389. package/packages/workspace/src/ecosystems/rubygems.ts +0 -30
  390. package/packages/workspace/src/ecosystems/types.ts +0 -18
  391. package/packages/workspace/src/lockfile.ts +0 -194
  392. package/packages/workspace/src/resolver.ts +0 -234
  393. package/packages/workspace/src/semver.ts +0 -259
  394. /package/{packages/crawler/src/index.ts → dist/packages/crawler/src/index.d.ts} +0 -0
  395. /package/{packages/evaluation/src/index.ts → dist/packages/evaluation/src/index.d.ts} +0 -0
  396. /package/{packages/export/src/index.ts → dist/packages/export/src/index.d.ts} +0 -0
  397. /package/{packages/normalizer/src/openapi.ts → dist/packages/normalizer/src/openapi.d.ts} +0 -0
  398. /package/{packages/security/src/index.ts → dist/packages/security/src/index.d.ts} +0 -0
  399. /package/{packages/shared/src/index.ts → dist/packages/shared/src/index.d.ts} +0 -0
  400. /package/{packages/storage/src/index.ts → dist/packages/storage/src/index.d.ts} +0 -0
  401. /package/{packages/verification/src/index.ts → dist/packages/verification/src/index.d.ts} +0 -0
  402. /package/{packages/workspace/src/index.ts → dist/packages/workspace/src/index.d.ts} +0 -0
@@ -1,406 +0,0 @@
1
- import { createHash } from 'node:crypto';
2
- import type {
3
- OpenApiSummary,
4
- ApiEndpoint,
5
- ApiParameter,
6
- ApiSchema,
7
- ApiResponse,
8
- ApiAuthScheme,
9
- ApiErrorResponse,
10
- ApiPaginationMetadata,
11
- Provenance,
12
- } from '../../../shared/src/index.ts';
13
- import { resolveJsonPointer, normalizeSchema } from './schema-resolver.ts';
14
-
15
- /**
16
- * Detects if a document content is an OpenAPI or Swagger specification.
17
- */
18
- export function detectOpenApiSpec(content: string, sourceUrl: string): OpenApiSummary | null {
19
- if (!content || typeof content !== 'string') return null;
20
-
21
- let parsed: Record<string, unknown>;
22
- try {
23
- parsed = JSON.parse(content);
24
- } catch {
25
- return null;
26
- }
27
-
28
- if (typeof parsed !== 'object' || parsed === null) return null;
29
-
30
- const openapiVer = typeof parsed.openapi === 'string' ? parsed.openapi : undefined;
31
- const swaggerVer = typeof parsed.swagger === 'string' ? parsed.swagger : undefined;
32
-
33
- const specVersion = openapiVer || swaggerVer;
34
- if (!specVersion) return null;
35
-
36
- const info = (typeof parsed.info === 'object' && parsed.info !== null)
37
- ? (parsed.info as Record<string, unknown>)
38
- : {};
39
-
40
- const title = typeof info.title === 'string' ? info.title : 'Untitled API';
41
- const description = typeof info.description === 'string' ? info.description : undefined;
42
-
43
- const servers: string[] = [];
44
- if (Array.isArray(parsed.servers)) {
45
- for (const server of parsed.servers) {
46
- if (server && typeof server === 'object' && typeof (server as Record<string, unknown>).url === 'string') {
47
- servers.push((server as Record<string, unknown>).url as string);
48
- }
49
- }
50
- } else if (typeof parsed.host === 'string') {
51
- const basePath = typeof parsed.basePath === 'string' ? parsed.basePath : '';
52
- const schemes = Array.isArray(parsed.schemes) ? parsed.schemes : ['https'];
53
- servers.push(`${schemes[0]}://${parsed.host}${basePath}`);
54
- }
55
-
56
- let pathCount = 0;
57
- if (typeof parsed.paths === 'object' && parsed.paths !== null) {
58
- pathCount = Object.keys(parsed.paths).length;
59
- }
60
-
61
- return {
62
- specVersion,
63
- title,
64
- description,
65
- servers,
66
- pathCount,
67
- sourceUrl,
68
- rawJson: parsed,
69
- };
70
- }
71
-
72
- /**
73
- * Parses all API endpoints from an OpenAPI 3.x or Swagger 2.0 specification.
74
- * Fully deterministic with internal $ref resolution, schema normalization,
75
- * pagination heuristics, and error detection.
76
- */
77
- export function parseOpenApiEndpoints(
78
- rawSpec: string | Record<string, unknown>,
79
- pageId: string,
80
- snapshotId: string,
81
- sourceUrl?: string,
82
- docVersion?: string
83
- ): ApiEndpoint[] {
84
- let root: Record<string, unknown>;
85
- if (typeof rawSpec === 'string') {
86
- try {
87
- root = JSON.parse(rawSpec);
88
- } catch {
89
- return [];
90
- }
91
- } else {
92
- root = rawSpec;
93
- }
94
-
95
- if (!root || typeof root !== 'object') return [];
96
-
97
- const isOpenApi3 = typeof root.openapi === 'string';
98
- const isSwagger2 = typeof root.swagger === 'string';
99
- if (!isOpenApi3 && !isSwagger2) return [];
100
-
101
- const paths = (typeof root.paths === 'object' && root.paths !== null)
102
- ? (root.paths as Record<string, unknown>)
103
- : {};
104
-
105
- const endpoints: ApiEndpoint[] = [];
106
- const supportedMethods = new Set(['get', 'post', 'put', 'delete', 'patch', 'head', 'options']);
107
-
108
- // Extract root-level security schemes
109
- const securitySchemesMap = new Map<string, ApiAuthScheme>();
110
- if (isOpenApi3 && root.components && typeof root.components === 'object') {
111
- const comps = root.components as Record<string, unknown>;
112
- if (typeof comps.securitySchemes === 'object' && comps.securitySchemes !== null) {
113
- for (const [name, schemeRaw] of Object.entries(comps.securitySchemes as Record<string, unknown>)) {
114
- if (typeof schemeRaw === 'object' && schemeRaw !== null) {
115
- const s = schemeRaw as Record<string, unknown>;
116
- securitySchemesMap.set(name, {
117
- type: (s.type as ApiAuthScheme['type']) || 'http',
118
- name: typeof s.name === 'string' ? s.name : name,
119
- in: s.in as ApiAuthScheme['in'],
120
- scheme: typeof s.scheme === 'string' ? s.scheme : undefined,
121
- bearerFormat: typeof s.bearerFormat === 'string' ? s.bearerFormat : undefined,
122
- description: typeof s.description === 'string' ? s.description : undefined,
123
- });
124
- }
125
- }
126
- }
127
- } else if (isSwagger2 && typeof root.securityDefinitions === 'object' && root.securityDefinitions !== null) {
128
- for (const [name, schemeRaw] of Object.entries(root.securityDefinitions as Record<string, unknown>)) {
129
- if (typeof schemeRaw === 'object' && schemeRaw !== null) {
130
- const s = schemeRaw as Record<string, unknown>;
131
- const rawType = typeof s.type === 'string' ? s.type : 'apiKey';
132
- let mappedType: ApiAuthScheme['type'] = 'apiKey';
133
- let mappedScheme: string | undefined = undefined;
134
-
135
- if (rawType === 'basic') {
136
- mappedType = 'http';
137
- mappedScheme = 'basic';
138
- } else if (rawType === 'oauth2') {
139
- mappedType = 'oauth2';
140
- }
141
-
142
- securitySchemesMap.set(name, {
143
- type: mappedType,
144
- name: typeof s.name === 'string' ? s.name : name,
145
- in: s.in as ApiAuthScheme['in'],
146
- scheme: mappedScheme,
147
- description: typeof s.description === 'string' ? s.description : undefined,
148
- });
149
- }
150
- }
151
- }
152
-
153
- // Root security fallback
154
- const rootSecurityReqs: Array<Record<string, unknown>> = Array.isArray(root.security)
155
- ? (root.security as Array<Record<string, unknown>>)
156
- : [];
157
-
158
- const nowIso = new Date().toISOString();
159
-
160
- for (const [pathStr, pathItemRaw] of Object.entries(paths)) {
161
- if (!pathItemRaw || typeof pathItemRaw !== 'object') continue;
162
- const pathItem = pathItemRaw as Record<string, unknown>;
163
-
164
- // Common path-level parameters
165
- const pathCommonParams: unknown[] = Array.isArray(pathItem.parameters) ? pathItem.parameters : [];
166
-
167
- for (const [methodKey, operationRaw] of Object.entries(pathItem)) {
168
- const method = methodKey.toLowerCase();
169
- if (!supportedMethods.has(method)) continue;
170
- if (!operationRaw || typeof operationRaw !== 'object') continue;
171
-
172
- const op = operationRaw as Record<string, unknown>;
173
-
174
- // Summary & Description
175
- const summary = typeof op.summary === 'string' ? op.summary : undefined;
176
- const description = typeof op.description === 'string' ? op.description : undefined;
177
- const operationId = typeof op.operationId === 'string' ? op.operationId : undefined;
178
- const deprecated = Boolean(op.deprecated || pathItem.deprecated);
179
-
180
- // Parameters
181
- const rawParams: unknown[] = [...pathCommonParams, ...(Array.isArray(op.parameters) ? op.parameters : [])];
182
- const parameters: ApiParameter[] = [];
183
- let swaggerBodySchema: unknown = undefined;
184
-
185
- for (const pRaw of rawParams) {
186
- let p = pRaw as Record<string, unknown>;
187
- if (typeof p.$ref === 'string') {
188
- const resolved = resolveJsonPointer(root, p.$ref);
189
- if (typeof resolved === 'object' && resolved !== null) {
190
- p = resolved as Record<string, unknown>;
191
- }
192
- }
193
-
194
- if (isSwagger2 && p.in === 'body') {
195
- swaggerBodySchema = p.schema;
196
- continue;
197
- }
198
-
199
- const name = typeof p.name === 'string' ? p.name : '';
200
- const paramIn = (typeof p.in === 'string' ? p.in : 'query') as ApiParameter['in'];
201
- const required = paramIn === 'path' ? true : Boolean(p.required);
202
- const pDesc = typeof p.description === 'string' ? p.description : undefined;
203
- const pDefault = p.default !== undefined ? p.default : (p.schema && typeof p.schema === 'object' ? (p.schema as Record<string, unknown>).default : undefined);
204
- const pExample = p.example !== undefined ? p.example : (p.schema && typeof p.schema === 'object' ? (p.schema as Record<string, unknown>).example : undefined);
205
-
206
- let pType: string | undefined = typeof p.type === 'string' ? p.type : undefined;
207
- let pSchema: Record<string, unknown> | undefined = undefined;
208
-
209
- if (p.schema && typeof p.schema === 'object') {
210
- pSchema = p.schema as Record<string, unknown>;
211
- if (!pType && typeof pSchema.type === 'string') {
212
- pType = pSchema.type;
213
- }
214
- }
215
-
216
- parameters.push({
217
- name,
218
- in: paramIn,
219
- required,
220
- type: pType,
221
- description: pDesc,
222
- default: pDefault,
223
- schema: pSchema,
224
- example: pExample,
225
- });
226
- }
227
-
228
- // Request Body
229
- let requestSchema: ApiSchema | undefined = undefined;
230
- if (isOpenApi3 && op.requestBody && typeof op.requestBody === 'object') {
231
- let rb = op.requestBody as Record<string, unknown>;
232
- if (typeof rb.$ref === 'string') {
233
- const resolved = resolveJsonPointer(root, rb.$ref);
234
- if (typeof resolved === 'object' && resolved !== null) {
235
- rb = resolved as Record<string, unknown>;
236
- }
237
- }
238
- if (typeof rb.content === 'object' && rb.content !== null) {
239
- const content = rb.content as Record<string, unknown>;
240
- // Prefer application/json, fallback to first media type
241
- const mediaTypeObj = (content['application/json'] || Object.values(content)[0]) as Record<string, unknown> | undefined;
242
- if (mediaTypeObj && mediaTypeObj.schema) {
243
- requestSchema = normalizeSchema(mediaTypeObj.schema, root);
244
- }
245
- }
246
- } else if (isSwagger2 && swaggerBodySchema) {
247
- requestSchema = normalizeSchema(swaggerBodySchema, root);
248
- }
249
-
250
- // Responses & Errors
251
- const responseSchema: Record<string, ApiResponse> = {};
252
- const errors: ApiErrorResponse[] = [];
253
-
254
- if (typeof op.responses === 'object' && op.responses !== null) {
255
- for (const [statusCode, resRaw] of Object.entries(op.responses as Record<string, unknown>)) {
256
- let res = resRaw as Record<string, unknown>;
257
- if (typeof res.$ref === 'string') {
258
- const resolved = resolveJsonPointer(root, res.$ref);
259
- if (typeof resolved === 'object' && resolved !== null) {
260
- res = resolved as Record<string, unknown>;
261
- }
262
- }
263
-
264
- const resDesc = typeof res.description === 'string' ? res.description : '';
265
- let contentType: string | undefined = undefined;
266
- let resSchemaObj: unknown = undefined;
267
- let resExample: unknown = undefined;
268
-
269
- if (isOpenApi3 && typeof res.content === 'object' && res.content !== null) {
270
- const content = res.content as Record<string, unknown>;
271
- const ctKey = content['application/json'] ? 'application/json' : Object.keys(content)[0];
272
- contentType = ctKey;
273
- const mediaObj = content[ctKey] as Record<string, unknown> | undefined;
274
- if (mediaObj) {
275
- resSchemaObj = mediaObj.schema;
276
- resExample = mediaObj.example || (mediaObj.examples ? Object.values(mediaObj.examples as Record<string, unknown>)[0] : undefined);
277
- }
278
- } else if (isSwagger2) {
279
- resSchemaObj = res.schema;
280
- contentType = 'application/json';
281
- resExample = res.examples ? Object.values(res.examples as Record<string, unknown>)[0] : undefined;
282
- }
283
-
284
- const normalizedResSchema = normalizeSchema(resSchemaObj, root);
285
-
286
- const apiResponse: ApiResponse = {
287
- statusCode,
288
- description: resDesc,
289
- contentType,
290
- schema: normalizedResSchema,
291
- example: resExample,
292
- };
293
-
294
- responseSchema[statusCode] = apiResponse;
295
-
296
- // Detect errors
297
- const isErrorCode = statusCode.startsWith('4') || statusCode.startsWith('5') || statusCode === 'default';
298
- if (isErrorCode) {
299
- errors.push({
300
- statusCode,
301
- description: resDesc,
302
- schema: normalizedResSchema,
303
- example: resExample,
304
- });
305
- }
306
- }
307
- }
308
-
309
- // Authentication Schemes
310
- const auth: ApiAuthScheme[] = [];
311
- const opSecurityReqs: Array<Record<string, unknown>> = Array.isArray(op.security)
312
- ? (op.security as Array<Record<string, unknown>>)
313
- : rootSecurityReqs;
314
-
315
- for (const req of opSecurityReqs) {
316
- if (typeof req !== 'object' || req === null) continue;
317
- for (const schemeName of Object.keys(req)) {
318
- const found = securitySchemesMap.get(schemeName);
319
- if (found) {
320
- // Avoid duplicate schemes
321
- if (!auth.some(a => a.name === found.name && a.type === found.type)) {
322
- auth.push(found);
323
- }
324
- } else {
325
- auth.push({
326
- type: 'apiKey',
327
- name: schemeName,
328
- });
329
- }
330
- }
331
- }
332
-
333
- // Pagination Heuristics
334
- let pagination: ApiPaginationMetadata | undefined = undefined;
335
- const paramNames = parameters.map(p => p.name.toLowerCase());
336
- const cursorParams = paramNames.filter(n => ['starting_after', 'ending_before', 'cursor', 'next_cursor', 'after', 'before'].includes(n));
337
- const offsetParams = paramNames.filter(n => ['offset', 'skip', 'start'].includes(n));
338
- const pageParams = paramNames.filter(n => ['page', 'page_number', 'pagenumber'].includes(n));
339
- const limitParams = paramNames.filter(n => ['limit', 'per_page', 'page_size', 'pagesize', 'count', 'max'].includes(n));
340
-
341
- // Inspect response properties for pagination clues
342
- const okResponse = responseSchema['200'] || responseSchema['201'];
343
- const responseProps = okResponse?.schema?.properties ? Object.keys(okResponse.schema.properties) : [];
344
- const detectedResponseFields = responseProps.filter(prop =>
345
- ['has_more', 'next_cursor', 'cursor', 'next_page', 'page_info', 'total_count', 'data', 'items', 'results'].includes(prop.toLowerCase())
346
- );
347
-
348
- if (cursorParams.length > 0) {
349
- pagination = {
350
- type: 'cursor',
351
- parameters: [...cursorParams, ...limitParams],
352
- responseFields: detectedResponseFields,
353
- };
354
- } else if (offsetParams.length > 0) {
355
- pagination = {
356
- type: 'offset',
357
- parameters: [...offsetParams, ...limitParams],
358
- responseFields: detectedResponseFields,
359
- };
360
- } else if (pageParams.length > 0) {
361
- pagination = {
362
- type: 'page',
363
- parameters: [...pageParams, ...limitParams],
364
- responseFields: detectedResponseFields,
365
- };
366
- }
367
-
368
- // Deterministic Endpoint ID
369
- const endpointId = createHash('sha256')
370
- .update(`${pageId}:${method}:${pathStr}`)
371
- .digest('hex')
372
- .substring(0, 16);
373
-
374
- const provenance: Provenance | undefined = sourceUrl
375
- ? {
376
- sourceUrl,
377
- retrievedAt: nowIso,
378
- sourceAuthority: 'official',
379
- }
380
- : undefined;
381
-
382
- endpoints.push({
383
- id: endpointId,
384
- pageId,
385
- snapshotId,
386
- method: method as ApiEndpoint['method'],
387
- path: pathStr,
388
- summary,
389
- description,
390
- operationId,
391
- parameters,
392
- requestSchema,
393
- responseSchema,
394
- auth,
395
- errors,
396
- pagination,
397
- deprecated,
398
- docVersion,
399
- provenance,
400
- createdAt: nowIso,
401
- });
402
- }
403
- }
404
-
405
- return endpoints;
406
- }
@@ -1,111 +0,0 @@
1
- import type { ApiSchema } from '../../../shared/src/index.ts';
2
-
3
- /**
4
- * Resolves a JSON Pointer (e.g. `#/components/schemas/Pet` or `#/definitions/Pet`)
5
- * within the root document. Handles circular references safely.
6
- */
7
- export function resolveJsonPointer(
8
- root: Record<string, unknown>,
9
- pointer: string,
10
- visited: Set<string> = new Set()
11
- ): unknown {
12
- if (visited.has(pointer)) {
13
- return { $ref: pointer, description: '[Circular Reference]' };
14
- }
15
- visited.add(pointer);
16
-
17
- if (!pointer.startsWith('#/')) {
18
- return { $ref: pointer, description: '[External Reference]' };
19
- }
20
-
21
- const parts = pointer.slice(2).split('/').map((part) =>
22
- part.replace(/~1/g, '/').replace(/~0/g, '~')
23
- );
24
-
25
- let current: unknown = root;
26
- for (const part of parts) {
27
- if (typeof current !== 'object' || current === null) {
28
- return undefined;
29
- }
30
- current = (current as Record<string, unknown>)[part];
31
- }
32
-
33
- // If the resolved object itself is a reference, resolve further
34
- if (
35
- typeof current === 'object' &&
36
- current !== null &&
37
- typeof (current as Record<string, unknown>).$ref === 'string'
38
- ) {
39
- return resolveJsonPointer(
40
- root,
41
- (current as Record<string, unknown>).$ref as string,
42
- visited
43
- );
44
- }
45
-
46
- return current;
47
- }
48
-
49
- /**
50
- * Normalizes an OpenAPI / JSON schema object into an ApiSchema model.
51
- */
52
- export function normalizeSchema(
53
- rawSchema: unknown,
54
- root: Record<string, unknown>,
55
- visited: Set<string> = new Set()
56
- ): ApiSchema | undefined {
57
- if (!rawSchema || typeof rawSchema !== 'object') return undefined;
58
-
59
- let schemaObj = rawSchema as Record<string, unknown>;
60
-
61
- if (typeof schemaObj.$ref === 'string') {
62
- const resolved = resolveJsonPointer(root, schemaObj.$ref, visited);
63
- if (typeof resolved === 'object' && resolved !== null) {
64
- schemaObj = resolved as Record<string, unknown>;
65
- }
66
- }
67
-
68
- const type = typeof schemaObj.type === 'string'
69
- ? schemaObj.type
70
- : (Array.isArray(schemaObj.type) ? schemaObj.type.join(' | ') : undefined);
71
-
72
- const description = typeof schemaObj.description === 'string'
73
- ? schemaObj.description
74
- : undefined;
75
-
76
- const required = Array.isArray(schemaObj.required)
77
- ? schemaObj.required.filter((r): r is string => typeof r === 'string')
78
- : undefined;
79
-
80
- let properties: Record<string, unknown> | undefined;
81
- if (typeof schemaObj.properties === 'object' && schemaObj.properties !== null) {
82
- properties = {};
83
- for (const [k, v] of Object.entries(schemaObj.properties as Record<string, unknown>)) {
84
- if (typeof v === 'object' && v !== null && typeof (v as Record<string, unknown>).$ref === 'string') {
85
- const refResolved = resolveJsonPointer(root, (v as Record<string, unknown>).$ref as string, new Set(visited));
86
- properties[k] = refResolved || v;
87
- } else {
88
- properties[k] = v;
89
- }
90
- }
91
- }
92
-
93
- let items: Record<string, unknown> | undefined;
94
- if (typeof schemaObj.items === 'object' && schemaObj.items !== null) {
95
- if (typeof (schemaObj.items as Record<string, unknown>).$ref === 'string') {
96
- const refResolved = resolveJsonPointer(root, (schemaObj.items as Record<string, unknown>).$ref as string, new Set(visited));
97
- items = (refResolved as Record<string, unknown>) || (schemaObj.items as Record<string, unknown>);
98
- } else {
99
- items = schemaObj.items as Record<string, unknown>;
100
- }
101
- }
102
-
103
- return {
104
- type,
105
- properties,
106
- required,
107
- description,
108
- items,
109
- raw: schemaObj,
110
- };
111
- }
@@ -1,184 +0,0 @@
1
- import {
2
- computeContentHash,
3
- estimateTokenCount,
4
- } from '../../shared/src/index.ts';
5
- import type {
6
- NormalizedPage,
7
- Heading,
8
- Link,
9
- CodeExample,
10
- Provenance,
11
- } from '../../shared/src/index.ts';
12
- import { detectSecurityAnnotations } from '../../security/src/index.ts';
13
- import { normalizeHtmlToMarkdown } from './html.ts';
14
- import { parseLlmsTxt, isValidLlmsTxt } from './llms.ts';
15
- import { detectOpenApiSpec } from './openapi.ts';
16
-
17
- function extractMarkdownHeadings(content: string): Heading[] {
18
- const headings: Heading[] = [];
19
- const lines = content.split('\n');
20
- for (const line of lines) {
21
- const match = line.match(/^(#{1,6})\s+(.+)$/);
22
- if (match) {
23
- const level = match[1].length;
24
- const text = match[2].trim();
25
- const anchor = text.toLowerCase().replace(/[^\w\s-]/g, '').replace(/\s+/g, '-');
26
- headings.push({ level, text, anchor });
27
- }
28
- }
29
- return headings;
30
- }
31
-
32
- function extractMarkdownCodeBlocks(content: string): CodeExample[] {
33
- const examples: CodeExample[] = [];
34
- const regex = /```([a-zA-Z0-9_-]*)\n([\s\S]*?)```/g;
35
- let match: RegExpExecArray | null;
36
- let idx = 1;
37
- while ((match = regex.exec(content)) !== null) {
38
- const lang = match[1].trim() || 'text';
39
- const code = match[2].trim();
40
- if (code) {
41
- examples.push({
42
- id: `code_${idx++}`,
43
- language: lang,
44
- code,
45
- });
46
- }
47
- }
48
- return examples;
49
- }
50
-
51
- function extractMarkdownLinks(content: string, baseUrl: string): Link[] {
52
- const links: Link[] = [];
53
- const regex = /\[([^\]]+)\]\(([^)]+)\)/g;
54
- let match: RegExpExecArray | null;
55
- while ((match = regex.exec(content)) !== null) {
56
- const text = match[1].trim();
57
- const href = match[2].trim();
58
- if (href.startsWith('#') || href.startsWith('javascript:')) continue;
59
-
60
- let absoluteUrl = href;
61
- let isExternal = false;
62
- try {
63
- const resolved = new URL(href, baseUrl);
64
- absoluteUrl = resolved.href;
65
- const baseHost = new URL(baseUrl).hostname;
66
- isExternal = resolved.hostname !== baseHost;
67
- } catch {
68
- // Keep raw href
69
- }
70
-
71
- links.push({ text, url: absoluteUrl, isExternal });
72
- }
73
- return links;
74
- }
75
-
76
- export interface BuildNormalizedPageInput {
77
- sourceId: string;
78
- url: string;
79
- rawContent: string;
80
- contentType?: string;
81
- sourceUrl?: string;
82
- targetUrl?: string;
83
- discoveredBy?: string;
84
- fetchedAt?: string;
85
- snapshotId?: string;
86
- }
87
-
88
- export function buildNormalizedPage(input: BuildNormalizedPageInput): NormalizedPage {
89
- const { sourceId, url, rawContent, contentType = '' } = input;
90
- const rawBytes = Buffer.byteLength(rawContent, 'utf-8');
91
-
92
- let title = 'Documentation';
93
- let cleanMarkdown = '';
94
- let headings: Heading[] = [];
95
- let links: Link[] = [];
96
- let codeExamples: CodeExample[] = [];
97
-
98
- const isHtml = contentType.includes('text/html') || /^\s*<(!DOCTYPE|html)/i.test(rawContent);
99
- const isOpenApi = contentType.includes('application/json') || url.endsWith('.json') || url.endsWith('.yaml');
100
-
101
- if (isOpenApi) {
102
- const apiSummary = detectOpenApiSpec(rawContent, url);
103
- if (apiSummary) {
104
- title = `${apiSummary.title} (OpenAPI ${apiSummary.specVersion})`;
105
- cleanMarkdown = `# ${title}\n\n${apiSummary.description || ''}\n\n` +
106
- `**Servers**: ${apiSummary.servers.join(', ') || 'None specified'}\n\n` +
107
- `**Endpoints Count**: ${apiSummary.pathCount}\n\n` +
108
- `\`\`\`json\n${JSON.stringify(apiSummary.rawJson, null, 2)}\n\`\`\``;
109
- headings = [
110
- { level: 1, text: title, anchor: 'title' },
111
- { level: 2, text: 'API Overview', anchor: 'api-overview' },
112
- ];
113
- codeExamples = [
114
- {
115
- id: 'spec_1',
116
- language: 'json',
117
- code: JSON.stringify(apiSummary.rawJson, null, 2),
118
- caption: 'OpenAPI Specification',
119
- },
120
- ];
121
- }
122
- }
123
-
124
- if (!cleanMarkdown && isHtml) {
125
- const extracted = normalizeHtmlToMarkdown(rawContent, url);
126
- title = extracted.title;
127
- cleanMarkdown = extracted.markdown;
128
- headings = extracted.headings;
129
- links = extracted.links;
130
- codeExamples = extracted.codeExamples;
131
- }
132
-
133
- if (!cleanMarkdown) {
134
- if (isValidLlmsTxt(rawContent)) {
135
- const llmsDoc = parseLlmsTxt(rawContent, url);
136
- title = llmsDoc.title || 'llms.txt Index';
137
- cleanMarkdown = rawContent;
138
- headings = extractMarkdownHeadings(rawContent);
139
- links = extractMarkdownLinks(rawContent, url);
140
- codeExamples = extractMarkdownCodeBlocks(rawContent);
141
- } else {
142
- cleanMarkdown = rawContent.trim();
143
- headings = extractMarkdownHeadings(cleanMarkdown);
144
- links = extractMarkdownLinks(cleanMarkdown, url);
145
- codeExamples = extractMarkdownCodeBlocks(cleanMarkdown);
146
- if (headings.length > 0 && headings[0].level === 1) {
147
- title = headings[0].text;
148
- }
149
- }
150
- }
151
-
152
- const contentHash = computeContentHash(cleanMarkdown);
153
- const estimatedTokens = estimateTokenCount(cleanMarkdown);
154
- const securityAnnotations = detectSecurityAnnotations(cleanMarkdown);
155
-
156
- const id = `page_${computeContentHash(`${sourceId}:${url}`).slice(0, 16)}`;
157
- const fetchedAt = input.fetchedAt || new Date().toISOString();
158
-
159
- const provenance: Provenance = {
160
- sourceUrl: input.sourceUrl || url,
161
- targetUrl: input.targetUrl || url,
162
- fetchedAt,
163
- discoveredBy: input.discoveredBy || 'direct',
164
- contentHash,
165
- snapshotId: input.snapshotId,
166
- };
167
-
168
- return {
169
- id,
170
- sourceId,
171
- title,
172
- url,
173
- content: cleanMarkdown,
174
- headings,
175
- links,
176
- codeExamples,
177
- contentHash,
178
- fetchedAt,
179
- rawBytes,
180
- estimatedTokens,
181
- securityAnnotations,
182
- provenance,
183
- };
184
- }