@cc-monitoring/proxy-core 0.2.3 → 0.3.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 (335) hide show
  1. package/dist/docs/404.html +1 -1
  2. package/dist/docs/assets/{app.6_CicOIJ.js → app.B9A39uFv.js} +1 -1
  3. package/dist/docs/assets/chunks/@localSearchIndexroot.B6Qfxe6W.js +1 -0
  4. package/dist/docs/assets/chunks/{VPLocalSearchBox.ZMWZsg8z.js → VPLocalSearchBox.DdhC696L.js} +1 -1
  5. package/dist/docs/assets/chunks/{theme.BkvhsjzH.js → theme.CfB2tOFi.js} +2 -2
  6. package/dist/docs/index.html +2 -2
  7. package/dist/docs/overview.html +2 -2
  8. package/dist/docs/packages-utils.html +2 -2
  9. package/dist/docs/proxy-admin/env-and-build.html +2 -2
  10. package/dist/docs/proxy-admin/index.html +2 -2
  11. package/dist/docs/proxy-admin/layout-and-menu.html +2 -2
  12. package/dist/docs/proxy-admin/pages.html +2 -2
  13. package/dist/docs/proxy-admin/routing-and-auth.html +2 -2
  14. package/dist/docs/proxy-admin/services-and-mock.html +2 -2
  15. package/dist/docs/proxy-cli/api-layer.html +2 -2
  16. package/dist/docs/proxy-cli/app-shell.html +2 -2
  17. package/dist/docs/proxy-cli/components-common.html +2 -2
  18. package/dist/docs/proxy-cli/components-config.html +2 -2
  19. package/dist/docs/proxy-cli/components-requests.html +2 -2
  20. package/dist/docs/proxy-cli/components-stats.html +2 -2
  21. package/dist/docs/proxy-cli/components-status.html +2 -2
  22. package/dist/docs/proxy-cli/data-hooks.html +2 -2
  23. package/dist/docs/proxy-cli/index.html +2 -2
  24. package/dist/docs/proxy-cli/utils-and-i18n.html +2 -2
  25. package/dist/docs/proxy-core/chat-api.html +2 -2
  26. package/dist/docs/proxy-core/cli.html +2 -2
  27. package/dist/docs/proxy-core/config.html +2 -2
  28. package/dist/docs/proxy-core/data-layer.html +2 -2
  29. package/dist/docs/proxy-core/entry.html +2 -2
  30. package/dist/docs/proxy-core/index.html +2 -2
  31. package/dist/docs/proxy-core/pm2.html +2 -2
  32. package/dist/docs/proxy-core/providers.html +2 -2
  33. package/dist/docs/proxy-core/proxy.html +2 -2
  34. package/dist/docs/proxy-core/stats.html +2 -2
  35. package/dist/docs/proxy-core/tool.html +2 -2
  36. package/dist/docs/proxy-core/ui-routes.html +2 -2
  37. package/dist/docs/proxy-core/utilities.html +2 -2
  38. package/dist/docs/quickstart.html +2 -2
  39. package/dist/docs/request-flow.html +2 -2
  40. package/dist/mcp-server/index.js +5 -3
  41. package/dist/mcp-server/tools.js +24 -2
  42. package/dist/server/__tests__/server.test.js +9 -1
  43. package/dist/server/__tests__/ui-route.test.js +8 -0
  44. package/dist/server/chat-route.js +6 -0
  45. package/dist/server/proxy.js +5 -0
  46. package/dist/server/ui-route.js +113 -7
  47. package/dist/ui/assets/{1c-HTPXddJd.js → 1c-DAu68mP4.js} +1 -1
  48. package/dist/ui/assets/{abnf-bINSkl_m.js → abnf-Cu8RHCHK.js} +1 -1
  49. package/dist/ui/assets/{abnfDiagram-VRR7QNED-ClDzCbvw.js → abnfDiagram-VRR7QNED-BUBToPXF.js} +1 -1
  50. package/dist/ui/assets/{accesslog-BAnIWzpe.js → accesslog-BG-34XOy.js} +1 -1
  51. package/dist/ui/assets/{actionscript-DVcm6F_C.js → actionscript-iw0HHMGM.js} +1 -1
  52. package/dist/ui/assets/{ada-Cxn-QX4j.js → ada-qRqj6VGQ.js} +1 -1
  53. package/dist/ui/assets/{angelscript-BAwAPvBQ.js → angelscript-BeaXyx_P.js} +1 -1
  54. package/dist/ui/assets/{apache-CjjovgUx.js → apache-CU8d-z9X.js} +1 -1
  55. package/dist/ui/assets/{applescript-VUcyXoVh.js → applescript-d1Wxkqz1.js} +1 -1
  56. package/dist/ui/assets/{arc-3Nou_aku.js → arc-BMsPIm3j.js} +1 -1
  57. package/dist/ui/assets/{arcade-Dz2VAk7O.js → arcade-CtbgrWTM.js} +1 -1
  58. package/dist/ui/assets/{architectureDiagram-ZJ3FMSHR-DhwSsCdN.js → architectureDiagram-ZJ3FMSHR-CVjC5TrS.js} +1 -1
  59. package/dist/ui/assets/{arduino-B-Ptb1K1.js → arduino-Bc9L39Hr.js} +1 -1
  60. package/dist/ui/assets/{armasm-DU_6qZlW.js → armasm-DuWmpjWR.js} +1 -1
  61. package/dist/ui/assets/{asciidoc-DYbYiWKT.js → asciidoc-CDIhFTnx.js} +1 -1
  62. package/dist/ui/assets/{aspectj-CmdNkqAs.js → aspectj-SYj-57Es.js} +1 -1
  63. package/dist/ui/assets/{autohotkey-if9QUvYo.js → autohotkey-hBi5dq37.js} +1 -1
  64. package/dist/ui/assets/{autoit-DGU3G1s6.js → autoit-BSawXzhg.js} +1 -1
  65. package/dist/ui/assets/{avrasm-1zsEtPJ6.js → avrasm-CwYom8Np.js} +1 -1
  66. package/dist/ui/assets/{awk-CvmeshSq.js → awk-BvBRfGo2.js} +1 -1
  67. package/dist/ui/assets/{axapta-CbJGb5cN.js → axapta-CqUavA8k.js} +1 -1
  68. package/dist/ui/assets/{bash-CFXg_i2e.js → bash-BS_ZnmEu.js} +1 -1
  69. package/dist/ui/assets/{basic-6atic5cT.js → basic-xbP4IXrN.js} +1 -1
  70. package/dist/ui/assets/{blockDiagram-677ZJIJ3-BKXinDkB.js → blockDiagram-677ZJIJ3-CmpI3f5p.js} +1 -1
  71. package/dist/ui/assets/{bnf-DydAtPHV.js → bnf-BECwu6uW.js} +1 -1
  72. package/dist/ui/assets/{brainfuck-CnHx1vO0.js → brainfuck-QQgu4j4N.js} +1 -1
  73. package/dist/ui/assets/{coq-BShzwzh7.js → c-BRJEPYra.js} +1 -1
  74. package/dist/ui/assets/{c-like-XpQV9S6j.js → c-like-DYrFOtXy.js} +1 -1
  75. package/dist/ui/assets/{c4Diagram-LMCZKHZV-D5EmWl5d.js → c4Diagram-LMCZKHZV-B6Hgngz9.js} +1 -1
  76. package/dist/ui/assets/{cal-D-orUuBW.js → cal-CNMrJ6v5.js} +1 -1
  77. package/dist/ui/assets/{capnproto-TdI6NT8O.js → capnproto-DYCKl6oY.js} +1 -1
  78. package/dist/ui/assets/{ceylon-Dji8eqtG.js → ceylon-mb8tRPl0.js} +1 -1
  79. package/dist/ui/assets/channel-Bc4Td8eZ.js +1 -0
  80. package/dist/ui/assets/{chunk-2Q5K7J3B-CaIvwVWl.js → chunk-2Q5K7J3B-LxvQ-G67.js} +1 -1
  81. package/dist/ui/assets/{chunk-32BRIVSS-C7oMpoeu.js → chunk-32BRIVSS-DxzKK6Aw.js} +1 -1
  82. package/dist/ui/assets/{chunk-5VM5RSS4-BQ0aVGl-.js → chunk-5VM5RSS4-CZEoYJ2W.js} +1 -1
  83. package/dist/ui/assets/{chunk-EX3LRPZG-D-_EqojZ.js → chunk-EX3LRPZG-DS2PytrN.js} +1 -1
  84. package/dist/ui/assets/{chunk-JWPE2WC7-B0OLx2rk.js → chunk-JWPE2WC7-UX0Sr1Ie.js} +1 -1
  85. package/dist/ui/assets/{chunk-MOJQB5TN-Be8IXTUE.js → chunk-MOJQB5TN-YbJgT9t4.js} +1 -1
  86. package/dist/ui/assets/{chunk-RYQCIY6F-DceCW2mS.js → chunk-RYQCIY6F-DS2VH_U9.js} +1 -1
  87. package/dist/ui/assets/{chunk-V7JOEXUC-Cbhq5qgO.js → chunk-V7JOEXUC-CZr0pkI1.js} +1 -1
  88. package/dist/ui/assets/{chunk-VR4S4FIN-D6WJuaS1.js → chunk-VR4S4FIN-50opPAD3.js} +1 -1
  89. package/dist/ui/assets/{chunk-XXDRQBXY-CKrih4pC.js → chunk-XXDRQBXY-DAAX9l7U.js} +1 -1
  90. package/dist/ui/assets/classDiagram-OUVF2IWQ-BicxhZFq.js +1 -0
  91. package/dist/ui/assets/classDiagram-v2-EOCWNBFH-BicxhZFq.js +1 -0
  92. package/dist/ui/assets/{clean-0frlVN_A.js → clean-C4X7dSkh.js} +1 -1
  93. package/dist/ui/assets/{clojure-D0q_yQDf.js → clojure-DSg9gUa7.js} +1 -1
  94. package/dist/ui/assets/{clojure-repl-DgYhEzOe.js → clojure-repl-CagRYx7h.js} +1 -1
  95. package/dist/ui/assets/{cmake-WF5tF5xU.js → cmake-CFdBn53c.js} +1 -1
  96. package/dist/ui/assets/{coffeescript-CyWYgeyv.js → coffeescript-CJZtMOPx.js} +1 -1
  97. package/dist/ui/assets/{c-DarYnPBd.js → coq-IDMIFfem.js} +1 -1
  98. package/dist/ui/assets/{cos-C5i3_TIB.js → cos-Bx2VJuzG.js} +1 -1
  99. package/dist/ui/assets/{cose-bilkent-JH36ORCC-BCwilS6I.js → cose-bilkent-JH36ORCC-zWRLsZpZ.js} +1 -1
  100. package/dist/ui/assets/{cpp-F1mRQFyw.js → cpp-CsG6DlC4.js} +1 -1
  101. package/dist/ui/assets/{crmsh-BAkHUu-B.js → crmsh-DTy9MnmJ.js} +1 -1
  102. package/dist/ui/assets/{crystal-CwUaomfj.js → crystal-BwgrLrZ1.js} +1 -1
  103. package/dist/ui/assets/{csharp-B1gHIdjK.js → csharp-B2VeTPAF.js} +1 -1
  104. package/dist/ui/assets/{csp-CblCTMvV.js → csp-CTpydNhH.js} +1 -1
  105. package/dist/ui/assets/{css-CXg7kJV3.js → css-B0mMUbpY.js} +1 -1
  106. package/dist/ui/assets/{cynefin-VYW2F7L2-BdgMlR5e.js → cynefin-VYW2F7L2-BmjQEj6q.js} +1 -1
  107. package/dist/ui/assets/{cynefinDiagram-TSTJHNR4-Bozdux8p.js → cynefinDiagram-TSTJHNR4-Dr0Zrke0.js} +1 -1
  108. package/dist/ui/assets/{d-Cs5yNCaM.js → d-DjuDZnbI.js} +1 -1
  109. package/dist/ui/assets/{dagre-VKFMJZFB-tI_mjNMn.js → dagre-VKFMJZFB-xoTPT2Uu.js} +1 -1
  110. package/dist/ui/assets/{dart-BqgylVkh.js → dart-xR3GU9TJ.js} +1 -1
  111. package/dist/ui/assets/{delphi-CbnfHpIi.js → delphi-bJas5QnG.js} +1 -1
  112. package/dist/ui/assets/{diagram-FQU43EPY-DmyL3OJT.js → diagram-FQU43EPY-rL_IU7gU.js} +1 -1
  113. package/dist/ui/assets/{diagram-G47NLZAW-BEi9GZlZ.js → diagram-G47NLZAW-EcDiCVGj.js} +1 -1
  114. package/dist/ui/assets/{diagram-NH7WQ7WH-Bct44Oh1.js → diagram-NH7WQ7WH-CGGXOjev.js} +1 -1
  115. package/dist/ui/assets/{diagram-OA4YK3LP-VWAgZxPK.js → diagram-OA4YK3LP-DnE7hDjD.js} +1 -1
  116. package/dist/ui/assets/{diagram-WEI45ONY-CxcHsE6q.js → diagram-WEI45ONY-CTJH5eD8.js} +1 -1
  117. package/dist/ui/assets/{diff-CMJ2hGQW.js → diff-doJFF3fv.js} +1 -1
  118. package/dist/ui/assets/{django-Cq_XIhVZ.js → django-D3b-owa_.js} +1 -1
  119. package/dist/ui/assets/{dns-CJs3z6-E.js → dns-C42KYV-Z.js} +1 -1
  120. package/dist/ui/assets/{dockerfile-ehs0ogry.js → dockerfile-9KUINc2j.js} +1 -1
  121. package/dist/ui/assets/{dos-DXOYESf1.js → dos-CxnlJ6qp.js} +1 -1
  122. package/dist/ui/assets/{dsconfig-Cs2hs3Bl.js → dsconfig-6CMMCwmY.js} +1 -1
  123. package/dist/ui/assets/{dts-Dk8yoweb.js → dts-D78rdUIB.js} +1 -1
  124. package/dist/ui/assets/{dust-BMK9e-Ss.js → dust-Dv1uTfJU.js} +1 -1
  125. package/dist/ui/assets/{ebnf-DlyBI5m6.js → ebnf-BGbG1cFK.js} +1 -1
  126. package/dist/ui/assets/{ebnfDiagram-CCIWWBDH-DBp9JHEq.js → ebnfDiagram-CCIWWBDH-z2VgRSUV.js} +1 -1
  127. package/dist/ui/assets/{elixir-BThlsblT.js → elixir-ZgAQVY1J.js} +1 -1
  128. package/dist/ui/assets/{elm-DrmZwmcc.js → elm-CudiFuNu.js} +1 -1
  129. package/dist/ui/assets/{erDiagram-Q63AITRT-BhK4NKvx.js → erDiagram-Q63AITRT-X1TODuRv.js} +1 -1
  130. package/dist/ui/assets/{erb-BQM7j3K9.js → erb-Bz_NZh6W.js} +1 -1
  131. package/dist/ui/assets/{erlang-CuUaWEXv.js → erlang-DNuj1nb2.js} +1 -1
  132. package/dist/ui/assets/{erlang-repl-DB0uphao.js → erlang-repl-SP1Gan9W.js} +1 -1
  133. package/dist/ui/assets/{excel-DmsuWUss.js → excel-0K77uECF.js} +1 -1
  134. package/dist/ui/assets/{fix-D-Uzxpz_.js → fix-CalJq7JD.js} +1 -1
  135. package/dist/ui/assets/{flix-B_7EHWiA.js → flix-BlIs11_w.js} +1 -1
  136. package/dist/ui/assets/{flowDiagram-23GEKE2U-DtMG1G-h.js → flowDiagram-23GEKE2U-DA2dnmc0.js} +1 -1
  137. package/dist/ui/assets/{fortran-Djp5tH9W.js → fortran-ZCobXY2R.js} +1 -1
  138. package/dist/ui/assets/{fsharp-Pj_2ZEa4.js → fsharp-Be8rwUtc.js} +1 -1
  139. package/dist/ui/assets/{gams-B2i3v2ec.js → gams-DUat8frQ.js} +1 -1
  140. package/dist/ui/assets/{ganttDiagram-NO4QXBWP-C7M-JA0W.js → ganttDiagram-NO4QXBWP-DdFwaIGZ.js} +1 -1
  141. package/dist/ui/assets/{gauss-DaV8sHLU.js → gauss-BB4U88dy.js} +1 -1
  142. package/dist/ui/assets/{gcode-0Jvrh6HY.js → gcode-DzeUZuZg.js} +1 -1
  143. package/dist/ui/assets/{gherkin-DoOl28D6.js → gherkin-B_8vW_BO.js} +1 -1
  144. package/dist/ui/assets/{gitGraphDiagram-IHSO6WYX-D3HB5mow.js → gitGraphDiagram-IHSO6WYX-B-Dn8x6I.js} +1 -1
  145. package/dist/ui/assets/{glsl-DEbk7rH5.js → glsl-DGHGjPC1.js} +1 -1
  146. package/dist/ui/assets/{gml-CBcqXBNV.js → gml-BYEku8Yh.js} +1 -1
  147. package/dist/ui/assets/{go-DqesmqF8.js → go-D8aSgQMc.js} +1 -1
  148. package/dist/ui/assets/{golo-9U1oO0b5.js → golo-CDjCU_jh.js} +1 -1
  149. package/dist/ui/assets/{gradle-DZliBXTY.js → gradle-BeUw7tl_.js} +1 -1
  150. package/dist/ui/assets/{groovy-Dys3GQwv.js → groovy-5iCQOtR3.js} +1 -1
  151. package/dist/ui/assets/{haml-CrtAODl1.js → haml-BEdL8FJi.js} +1 -1
  152. package/dist/ui/assets/{handlebars-CueXuqSj.js → handlebars-BuYQNzoK.js} +1 -1
  153. package/dist/ui/assets/{haskell-CRungOQt.js → haskell-I4FCBcW0.js} +1 -1
  154. package/dist/ui/assets/{haxe-aMz7L4gD.js → haxe-yigyKfFr.js} +1 -1
  155. package/dist/ui/assets/{hsp-Cw75yqGb.js → hsp-ZUk4j7d1.js} +1 -1
  156. package/dist/ui/assets/{htmlbars-e_mpUZNH.js → htmlbars-QYP3lT3u.js} +1 -1
  157. package/dist/ui/assets/{http-Di7E_m1o.js → http-BJpD1O71.js} +1 -1
  158. package/dist/ui/assets/{hy-CwlvsNj6.js → hy-CIJ1bP6S.js} +1 -1
  159. package/dist/ui/assets/{index-BdSumlU0.js → index-BDXWttnT.js} +3 -3
  160. package/dist/ui/assets/index-C0fxlU9d.css +10 -0
  161. package/dist/ui/assets/{index-BVM6YOjH.js → index-COAgrx1J.js} +256 -256
  162. package/dist/ui/assets/{infoDiagram-FWYZ7A6U-_r-6eAzx.js → infoDiagram-FWYZ7A6U-fTg9eLNt.js} +1 -1
  163. package/dist/ui/assets/{inform7-dwg1imm1.js → inform7-DAsu-lC2.js} +1 -1
  164. package/dist/ui/assets/{ini-DEXL1rCA.js → ini-Bhz-zHCg.js} +1 -1
  165. package/dist/ui/assets/{irpf90-Ccs_8Sp-.js → irpf90-BunhbwBl.js} +1 -1
  166. package/dist/ui/assets/{isbl-B9d1nYmL.js → isbl-q9L6hOhP.js} +1 -1
  167. package/dist/ui/assets/{ishikawaDiagram-FXEZZL3T-lNCezpU4.js → ishikawaDiagram-FXEZZL3T-B8G0sdgd.js} +1 -1
  168. package/dist/ui/assets/{java-5fv2smM6.js → java-Iks5Pkau.js} +1 -1
  169. package/dist/ui/assets/{javascript-TAWm0NK8.js → javascript-C4vltXPw.js} +1 -1
  170. package/dist/ui/assets/{jboss-cli-dM1kcsbR.js → jboss-cli-BQBvd2X2.js} +1 -1
  171. package/dist/ui/assets/{journeyDiagram-5HDEW3XC-CBYHux8i.js → journeyDiagram-5HDEW3XC-Crbzgrum.js} +1 -1
  172. package/dist/ui/assets/{json-CtCzm6jF.js → json-DXK0_jUK.js} +1 -1
  173. package/dist/ui/assets/{julia-Co7H3kzk.js → julia-CCYoBiYK.js} +1 -1
  174. package/dist/ui/assets/{julia-repl-BT1ar5VS.js → julia-repl-y8v2Oorl.js} +1 -1
  175. package/dist/ui/assets/{kanban-definition-HUTT4EX6-B8x8eQyo.js → kanban-definition-HUTT4EX6-C8sCOsBX.js} +1 -1
  176. package/dist/ui/assets/{kotlin-W6mVKIj9.js → kotlin-Bnjk7_fw.js} +1 -1
  177. package/dist/ui/assets/{lasso-DJG4luGz.js → lasso-B-al6x63.js} +1 -1
  178. package/dist/ui/assets/{latex-DbBOxO7u.js → latex-BUmqlb9r.js} +1 -1
  179. package/dist/ui/assets/{ldif-CVS189JA.js → ldif-D42RWj6Q.js} +1 -1
  180. package/dist/ui/assets/{leaf-eYNiXTKP.js → leaf-CrH4BZ0m.js} +1 -1
  181. package/dist/ui/assets/{less-DxhvWM95.js → less-upmRlQQW.js} +1 -1
  182. package/dist/ui/assets/{lisp-SC7AwnXC.js → lisp-DHYS22SA.js} +1 -1
  183. package/dist/ui/assets/{livecodeserver-CR2eHihF.js → livecodeserver-CeQNmFP3.js} +1 -1
  184. package/dist/ui/assets/{livescript-DBZ-GaVK.js → livescript-PJWpY1JI.js} +1 -1
  185. package/dist/ui/assets/{llvm-BzURO4tt.js → llvm-BKtKWwCt.js} +1 -1
  186. package/dist/ui/assets/{lsl-DGoJxEUu.js → lsl-RWRLRjk7.js} +1 -1
  187. package/dist/ui/assets/{lua-qgG9gdiw.js → lua-BFUDiPGm.js} +1 -1
  188. package/dist/ui/assets/{makefile-D0kZ6SOe.js → makefile-CUDyOz5D.js} +1 -1
  189. package/dist/ui/assets/{markdown-DRQWgMxk.js → markdown-zZCLypc6.js} +1 -1
  190. package/dist/ui/assets/{mathematica-DIBvZyEZ.js → mathematica-BHbxKxnq.js} +1 -1
  191. package/dist/ui/assets/{matlab-BNg0BR0b.js → matlab-DlGtg--p.js} +1 -1
  192. package/dist/ui/assets/{maxima-Bpga3G1G.js → maxima-BBBeS3Ra.js} +1 -1
  193. package/dist/ui/assets/{mel-CMOJa9Mg.js → mel-nh8j7W_6.js} +1 -1
  194. package/dist/ui/assets/{mercury-uvrRzupw.js → mercury-DyyD-pqr.js} +1 -1
  195. package/dist/ui/assets/{mindmap-definition-LN4V7U3C-DK8j_8Ap.js → mindmap-definition-LN4V7U3C-CJlhDHqM.js} +1 -1
  196. package/dist/ui/assets/{mipsasm-p1gWpDuw.js → mipsasm-hiEhRRiq.js} +1 -1
  197. package/dist/ui/assets/{mizar-DV1ENOOU.js → mizar-BZa3iAAL.js} +1 -1
  198. package/dist/ui/assets/{mojolicious-tg5XQSro.js → mojolicious-BCIm2V_y.js} +1 -1
  199. package/dist/ui/assets/{monkey-D8mYa31Q.js → monkey-zmK-7N8b.js} +1 -1
  200. package/dist/ui/assets/{moonscript-1d_rtlyv.js → moonscript-BsS_Mn3D.js} +1 -1
  201. package/dist/ui/assets/{n1ql-C5srRxme.js → n1ql-D7xVgDP0.js} +1 -1
  202. package/dist/ui/assets/{nginx-xS1muaWm.js → nginx-ct2q4dtd.js} +1 -1
  203. package/dist/ui/assets/{nim-CGGiMQfp.js → nim-RO0UOmW3.js} +1 -1
  204. package/dist/ui/assets/{nix-C77HsR7m.js → nix-BcRJxPKH.js} +1 -1
  205. package/dist/ui/assets/{node-repl-CSeYusSM.js → node-repl-DgIefwxW.js} +1 -1
  206. package/dist/ui/assets/{nsis-BffC7mSW.js → nsis-DqHs9QhB.js} +1 -1
  207. package/dist/ui/assets/{objectivec-WpjnmlJB.js → objectivec-BBcWqc7Y.js} +1 -1
  208. package/dist/ui/assets/{ocaml-CHUkJkjB.js → ocaml-BExfw7D6.js} +1 -1
  209. package/dist/ui/assets/{openscad-BvImqFT0.js → openscad-CHPRELQb.js} +1 -1
  210. package/dist/ui/assets/{oxygene-BMBykbf5.js → oxygene-DpS9uMJW.js} +1 -1
  211. package/dist/ui/assets/{parser3-lRbuZW0M.js → parser3-CjJ_QdBp.js} +1 -1
  212. package/dist/ui/assets/{pegDiagram-2B236MQR-C4DWmrja.js → pegDiagram-2B236MQR-GM70woGy.js} +1 -1
  213. package/dist/ui/assets/{perl-B0DjfKoO.js → perl-BSNM2Kt8.js} +1 -1
  214. package/dist/ui/assets/{pf-Aor6NyYJ.js → pf-Z-hKf_88.js} +1 -1
  215. package/dist/ui/assets/{pgsql-CVKcjjNR.js → pgsql-DDgznxBg.js} +1 -1
  216. package/dist/ui/assets/{php-CZ7geHZt.js → php-BzAhxF-l.js} +1 -1
  217. package/dist/ui/assets/{php-template-DiFuW2dF.js → php-template-DkgcKHRc.js} +1 -1
  218. package/dist/ui/assets/{pieDiagram-ENE6RG2P-BO7AmF5j.js → pieDiagram-ENE6RG2P-Bst7mPyz.js} +1 -1
  219. package/dist/ui/assets/{plaintext-DcvmOuNc.js → plaintext-BYEppD0R.js} +1 -1
  220. package/dist/ui/assets/{pony-DGPeAcOc.js → pony-BT_kQd1K.js} +1 -1
  221. package/dist/ui/assets/{powershell-DsrPyJdK.js → powershell-BfRsuSsf.js} +1 -1
  222. package/dist/ui/assets/{processing-Co2VRXN1.js → processing-DpzWe5Iu.js} +1 -1
  223. package/dist/ui/assets/{profile-D4PjpLUf.js → profile-BCOhS5cM.js} +1 -1
  224. package/dist/ui/assets/{prolog-DEbkeg9r.js → prolog-OxaCCaW8.js} +1 -1
  225. package/dist/ui/assets/{properties-Cxqcuj1s.js → properties-DMFlA2Ca.js} +1 -1
  226. package/dist/ui/assets/{protobuf-C-zdlrww.js → protobuf-CRDFkXvZ.js} +1 -1
  227. package/dist/ui/assets/{puppet-BPX3SrOx.js → puppet-DnrVyLzx.js} +1 -1
  228. package/dist/ui/assets/{purebasic-BdQnNJS3.js → purebasic-Dht4Hniv.js} +1 -1
  229. package/dist/ui/assets/{python-D067_Gj8.js → python-B0aMirWu.js} +1 -1
  230. package/dist/ui/assets/{python-repl-DCqNVlc0.js → python-repl-BlYDBGa7.js} +1 -1
  231. package/dist/ui/assets/{q-kABXYW-8.js → q-DzrtW9kT.js} +1 -1
  232. package/dist/ui/assets/{qml-Iao-Whg7.js → qml-DnfQsR3i.js} +1 -1
  233. package/dist/ui/assets/{quadrantDiagram-ABIIQ3AL-DetQn-0l.js → quadrantDiagram-ABIIQ3AL-DNRYurBT.js} +1 -1
  234. package/dist/ui/assets/{r-BnwpapnO.js → r-DGI_ZuTD.js} +1 -1
  235. package/dist/ui/assets/{railroadDiagram-RFXS5EU6-DFaFKHAH.js → railroadDiagram-RFXS5EU6-CmbC3Vz4.js} +1 -1
  236. package/dist/ui/assets/{reasonml-Cn_Y03uT.js → reasonml-3SohMgh2.js} +1 -1
  237. package/dist/ui/assets/{requirementDiagram-TGXJPOKE-Dg1LrT-T.js → requirementDiagram-TGXJPOKE-8CxrXHco.js} +1 -1
  238. package/dist/ui/assets/{rib-ByAqQn0v.js → rib-DfRSd4Qa.js} +1 -1
  239. package/dist/ui/assets/{roboconf-BJPu6NC5.js → roboconf-CQczGdGW.js} +1 -1
  240. package/dist/ui/assets/{routeros-CL3Jm0Zq.js → routeros-DCka-T2i.js} +1 -1
  241. package/dist/ui/assets/{rsl-DaXy7KaD.js → rsl-Dr8MOwMo.js} +1 -1
  242. package/dist/ui/assets/{ruby-DI6awte_.js → ruby-C2zFSkh_.js} +1 -1
  243. package/dist/ui/assets/{ruleslanguage-DoTVEZE9.js → ruleslanguage-C97YsgQq.js} +1 -1
  244. package/dist/ui/assets/{rust-ULEd75wO.js → rust-H3h8kd9A.js} +1 -1
  245. package/dist/ui/assets/{sankeyDiagram-HTMAVEWB-DQtFl110.js → sankeyDiagram-HTMAVEWB-DBXLWjEq.js} +1 -1
  246. package/dist/ui/assets/{sas-f7ATFuJk.js → sas-04z0Xu8P.js} +1 -1
  247. package/dist/ui/assets/{scala-Dha1zro2.js → scala-DyB9Aoiv.js} +1 -1
  248. package/dist/ui/assets/{scheme-BcaFHKeF.js → scheme-DBj6nxUi.js} +1 -1
  249. package/dist/ui/assets/{scilab-CIiiyD4z.js → scilab-Btj7AD9s.js} +1 -1
  250. package/dist/ui/assets/{scss-CkBomL0n.js → scss-BXZJyXt7.js} +1 -1
  251. package/dist/ui/assets/{sequenceDiagram-DBY2YBRQ-DIbNQtCn.js → sequenceDiagram-DBY2YBRQ-DXIkBFKC.js} +1 -1
  252. package/dist/ui/assets/{shell-Cxu8Py1z.js → shell-BsreQR1Z.js} +1 -1
  253. package/dist/ui/assets/{sizeCapture-X5ZJPWSS-Cj7PglQv.js → sizeCapture-X5ZJPWSS-ocS9jxAQ.js} +1 -1
  254. package/dist/ui/assets/{smali-C4EYyWYz.js → smali-D9wQw9zm.js} +1 -1
  255. package/dist/ui/assets/{smalltalk-BlPTprP4.js → smalltalk-Dku6G_H3.js} +1 -1
  256. package/dist/ui/assets/{sml-DEPzhlr4.js → sml-BknyU6ya.js} +1 -1
  257. package/dist/ui/assets/{sqf-CRu3asu9.js → sqf-DRYMaOg8.js} +1 -1
  258. package/dist/ui/assets/{sql-DK-YfQqg.js → sql-Cw3Ax4KA.js} +1 -1
  259. package/dist/ui/assets/{sql_more-BuMEOcjj.js → sql_more-vWdslLE0.js} +1 -1
  260. package/dist/ui/assets/{stan-DMr13kyD.js → stan-8XH5bDS6.js} +1 -1
  261. package/dist/ui/assets/{stata-Bt6E2zQi.js → stata-4e77wgfe.js} +1 -1
  262. package/dist/ui/assets/{stateDiagram-2N3HPSRC-Bk-gF72D.js → stateDiagram-2N3HPSRC-RMmL9jMG.js} +1 -1
  263. package/dist/ui/assets/stateDiagram-v2-6OUMAXLB-QvaEO5U6.js +1 -0
  264. package/dist/ui/assets/{step21-Bi954ur4.js → step21-ByIeDMY3.js} +1 -1
  265. package/dist/ui/assets/{stylus-CQwwMaLm.js → stylus-ZAhJyWsw.js} +1 -1
  266. package/dist/ui/assets/{subunit-BkixDEMH.js → subunit-pPW2UGkj.js} +1 -1
  267. package/dist/ui/assets/{swift-DS1DWNAE.js → swift-CX3BB5az.js} +1 -1
  268. package/dist/ui/assets/{swimlanes-5IMT3BWC-C-AZKO5z.js → swimlanes-5IMT3BWC-C2zAuJ56.js} +2 -2
  269. package/dist/ui/assets/swimlanesDiagram-G3AALYLV-DPgCOY0D.js +8 -0
  270. package/dist/ui/assets/{taggerscript-DZHi1hoc.js → taggerscript-BHcjbWIC.js} +1 -1
  271. package/dist/ui/assets/{tap-CXxSD8bM.js → tap-BOl1lBlS.js} +1 -1
  272. package/dist/ui/assets/{tcl-CdoAAMbn.js → tcl-DZjeOBDh.js} +1 -1
  273. package/dist/ui/assets/{thrift-DM086HVt.js → thrift-BxboWg4x.js} +1 -1
  274. package/dist/ui/assets/{timeline-definition-FHXFAJF6-DcrcjFwq.js → timeline-definition-FHXFAJF6-BOxsxyq_.js} +1 -1
  275. package/dist/ui/assets/{tp-Y-w3S3ES.js → tp-BNM6ql3J.js} +1 -1
  276. package/dist/ui/assets/{twig-C5c_nAus.js → twig-Dj9ZiXD4.js} +1 -1
  277. package/dist/ui/assets/{typescript-fc7SMhJu.js → typescript-7MEJlu_6.js} +1 -1
  278. package/dist/ui/assets/{vala-BV-GlwLI.js → vala-DNqOAgHJ.js} +1 -1
  279. package/dist/ui/assets/{vbnet-BIqQmnKr.js → vbnet-T0mNKVc_.js} +1 -1
  280. package/dist/ui/assets/{vbscript-h186Lnrz.js → vbscript-CeuwVMAI.js} +1 -1
  281. package/dist/ui/assets/{vbscript-html-DcuP7lTb.js → vbscript-html-BbJSt2w6.js} +1 -1
  282. package/dist/ui/assets/{vennDiagram-L72KCM5P-Dnh11y2e.js → vennDiagram-L72KCM5P-BX9mWeiT.js} +1 -1
  283. package/dist/ui/assets/{verilog-Cbgb_XnR.js → verilog-DYuhYfkX.js} +1 -1
  284. package/dist/ui/assets/{vhdl-COP7w5IC.js → vhdl-Cf9aT-t7.js} +1 -1
  285. package/dist/ui/assets/{vim-COGwKzgS.js → vim-DciP44K1.js} +1 -1
  286. package/dist/ui/assets/{wardleyDiagram-EHGQE667-BeiD8fPz.js → wardleyDiagram-EHGQE667-CDj2rOzu.js} +1 -1
  287. package/dist/ui/assets/{x86asm-BdBqPPf4.js → x86asm-E-AN_LXO.js} +1 -1
  288. package/dist/ui/assets/{xl-BmCQT7Vj.js → xl-CxYLJelN.js} +1 -1
  289. package/dist/ui/assets/{xml-DM0NxGiJ.js → xml-yz1SRLuU.js} +1 -1
  290. package/dist/ui/assets/{xquery-BUaYHDJM.js → xquery-BLzBF3tV.js} +1 -1
  291. package/dist/ui/assets/{xychartDiagram-FW5EYKEG-CnwvTrkm.js → xychartDiagram-FW5EYKEG-Czapk9-Z.js} +1 -1
  292. package/dist/ui/assets/{yaml-DMs8lGDt.js → yaml-Cv4Y7iN_.js} +1 -1
  293. package/dist/ui/assets/{zephir-BvjoPdmg.js → zephir-KRcdQfEX.js} +1 -1
  294. package/dist/ui/index.html +2 -2
  295. package/dist/utils/__tests__/knowledge-store.test.js +86 -5
  296. package/dist/utils/__tests__/pi-browser-tools.test.d.ts +1 -0
  297. package/dist/utils/__tests__/pi-browser-tools.test.js +30 -0
  298. package/dist/utils/__tests__/pi-crawl-tools.test.d.ts +1 -0
  299. package/dist/utils/__tests__/pi-crawl-tools.test.js +315 -0
  300. package/dist/utils/__tests__/pi-dedup-reconcile.test.d.ts +1 -0
  301. package/dist/utils/__tests__/pi-dedup-reconcile.test.js +89 -0
  302. package/dist/utils/__tests__/pi-dedup.test.d.ts +1 -0
  303. package/dist/utils/__tests__/pi-dedup.test.js +106 -0
  304. package/dist/utils/__tests__/pi-learn-orchestrator.test.d.ts +1 -0
  305. package/dist/utils/__tests__/pi-learn-orchestrator.test.js +885 -0
  306. package/dist/utils/__tests__/pi-runtime-json.test.d.ts +1 -0
  307. package/dist/utils/__tests__/pi-runtime-json.test.js +11 -0
  308. package/dist/utils/__tests__/web-crawler.test.d.ts +1 -0
  309. package/dist/utils/__tests__/web-crawler.test.js +69 -0
  310. package/dist/utils/db.d.ts +1 -0
  311. package/dist/utils/db.js +18 -0
  312. package/dist/utils/knowledge-store.d.ts +9 -0
  313. package/dist/utils/knowledge-store.js +85 -11
  314. package/dist/utils/pi-browser-tools.d.ts +2 -0
  315. package/dist/utils/pi-browser-tools.js +9 -2
  316. package/dist/utils/pi-crawl-tools.d.ts +62 -0
  317. package/dist/utils/pi-crawl-tools.js +298 -0
  318. package/dist/utils/pi-dedup.d.ts +62 -0
  319. package/dist/utils/pi-dedup.js +218 -0
  320. package/dist/utils/pi-learn-orchestrator.d.ts +44 -0
  321. package/dist/utils/pi-learn-orchestrator.js +431 -0
  322. package/dist/utils/pi-runtime.d.ts +23 -1
  323. package/dist/utils/pi-runtime.js +255 -68
  324. package/dist/utils/request-writer.d.ts +1 -0
  325. package/dist/utils/request-writer.js +5 -4
  326. package/dist/utils/web-crawler.d.ts +13 -0
  327. package/dist/utils/web-crawler.js +64 -0
  328. package/package.json +1 -1
  329. package/dist/docs/assets/chunks/@localSearchIndexroot.CHyuB7c8.js +0 -1
  330. package/dist/ui/assets/channel-BdcV3Ykv.js +0 -1
  331. package/dist/ui/assets/classDiagram-OUVF2IWQ-CAZR5rAv.js +0 -1
  332. package/dist/ui/assets/classDiagram-v2-EOCWNBFH-CAZR5rAv.js +0 -1
  333. package/dist/ui/assets/index-WPLwx8h5.css +0 -10
  334. package/dist/ui/assets/stateDiagram-v2-6OUMAXLB-BFJCYsLY.js +0 -1
  335. package/dist/ui/assets/swimlanesDiagram-G3AALYLV-BZd1Gt4_.js +0 -8
@@ -0,0 +1,315 @@
1
+ import { promises as fsp } from 'node:fs';
2
+ import path from 'node:path';
3
+ import os from 'node:os';
4
+ // Mock ego-browser:默认 navigate / close 均经 runEgoBrowser 子进程
5
+ jest.mock('../pi-browser-tools.js', () => ({
6
+ runEgoBrowser: jest.fn(),
7
+ }));
8
+ import { runEgoBrowser } from '../pi-browser-tools.js';
9
+ import { CrawlGuard, createCrawlTools } from '../pi-crawl-tools.js';
10
+ const mockRunEgoBrowser = runEgoBrowser;
11
+ /** 构造一张 url -> 页面 的图;未登记的 URL navigate 抛错(模拟抓取失败) */
12
+ function makeGraphNav(graph) {
13
+ return async (url) => {
14
+ const page = graph[url];
15
+ if (!page)
16
+ throw new Error(`fixture missing: ${url}`);
17
+ return { ...page };
18
+ };
19
+ }
20
+ let tmpDir;
21
+ const docsDir = () => path.join(tmpDir, 'docs');
22
+ beforeEach(async () => {
23
+ tmpDir = await fsp.mkdtemp(path.join(os.tmpdir(), 'crawl-tools-'));
24
+ mockRunEgoBrowser.mockReset();
25
+ });
26
+ afterEach(async () => {
27
+ await fsp.rm(tmpDir, { recursive: true, force: true });
28
+ });
29
+ describe('CrawlGuard.open', () => {
30
+ it('入口页登记为 depth 0 并返回页面信息', async () => {
31
+ const guard = new CrawlGuard({
32
+ entryUrl: 'https://pi.dev/',
33
+ docsDir: docsDir(),
34
+ slug: 'pi',
35
+ navigate: makeGraphNav({
36
+ 'https://pi.dev/': { title: 'Pi', text: 'A text', links: ['https://pi.dev/b'] },
37
+ }),
38
+ });
39
+ const page = await guard.open();
40
+ expect(page).toEqual({
41
+ url: 'https://pi.dev/',
42
+ title: 'Pi',
43
+ text: 'A text',
44
+ links: ['https://pi.dev/b'],
45
+ });
46
+ expect(guard.savedCount).toBe(0);
47
+ });
48
+ it('入口 URL 非法时抛错', async () => {
49
+ const guard = new CrawlGuard({
50
+ entryUrl: 'not a url',
51
+ docsDir: docsDir(),
52
+ slug: 'pi',
53
+ navigate: makeGraphNav({}),
54
+ });
55
+ await expect(guard.open()).rejects.toThrow();
56
+ });
57
+ it('未注入 navigate 时默认走 runEgoBrowser 并解析 JSON', async () => {
58
+ mockRunEgoBrowser.mockResolvedValue(JSON.stringify({ title: 'T', text: 'X', links: ['https://pi.dev/b'] }));
59
+ const guard = new CrawlGuard({ entryUrl: 'https://pi.dev/', docsDir: docsDir(), slug: 'pi' });
60
+ const page = await guard.open();
61
+ expect(page.title).toBe('T');
62
+ expect(page.text).toBe('X');
63
+ expect(page.links).toEqual(['https://pi.dev/b']);
64
+ // 抓取脚本 timeoutMs 60000,URL 以 JSON 字面量注入
65
+ expect(mockRunEgoBrowser).toHaveBeenCalledWith(expect.any(String), { timeoutMs: 60000 });
66
+ expect(mockRunEgoBrowser.mock.calls[0][0]).toContain(JSON.stringify('https://pi.dev/'));
67
+ expect(mockRunEgoBrowser.mock.calls[0][0]).toContain('await task.newPage()');
68
+ });
69
+ it('浏览器输出 JSON parse 失败时抛错', async () => {
70
+ mockRunEgoBrowser.mockResolvedValue('not-json');
71
+ const guard = new CrawlGuard({ entryUrl: 'https://pi.dev/', docsDir: docsDir(), slug: 'pi' });
72
+ await expect(guard.open()).rejects.toThrow(/parse/);
73
+ });
74
+ });
75
+ describe('CrawlGuard.visit', () => {
76
+ let graph;
77
+ beforeEach(() => {
78
+ graph = {
79
+ 'https://pi.dev/': { title: 'A', text: 'A text', links: ['https://pi.dev/b'] },
80
+ 'https://pi.dev/b': { title: 'B', text: 'B text', links: ['https://pi.dev/c'] },
81
+ 'https://pi.dev/c': { title: 'C', text: 'C text', links: [] },
82
+ };
83
+ });
84
+ it('同站子页推进深度(0 → 1),登记状态并返回页面信息', async () => {
85
+ const guard = new CrawlGuard({ entryUrl: 'https://pi.dev/', docsDir: docsDir(), slug: 'pi', navigate: makeGraphNav(graph) });
86
+ await guard.open();
87
+ const page = await guard.visit('https://pi.dev/b');
88
+ expect(page).toEqual({ url: 'https://pi.dev/b', title: 'B', text: 'B text', links: ['https://pi.dev/c'] });
89
+ // 再访问 c:当前深度 1 + 1 = 2 > maxDepth(1) → 拒绝
90
+ await expect(guard.visit('https://pi.dev/c')).rejects.toThrow(/max-depth/);
91
+ });
92
+ it('跨站链接 throw cross-site', async () => {
93
+ graph['https://pi.dev/'].links.push('https://other.com/x');
94
+ const guard = new CrawlGuard({ entryUrl: 'https://pi.dev/', docsDir: docsDir(), slug: 'pi', navigate: makeGraphNav(graph) });
95
+ await guard.open();
96
+ await expect(guard.visit('https://other.com/x')).rejects.toThrow(/cross-site/);
97
+ });
98
+ it('二进制资源链接 throw', async () => {
99
+ graph['https://pi.dev/'].links.push('https://pi.dev/file.pdf');
100
+ const guard = new CrawlGuard({ entryUrl: 'https://pi.dev/', docsDir: docsDir(), slug: 'pi', navigate: makeGraphNav(graph) });
101
+ await guard.open();
102
+ await expect(guard.visit('https://pi.dev/file.pdf')).rejects.toThrow();
103
+ });
104
+ it('已访问(seen,含纯锚点归一)throw seen', async () => {
105
+ const guard = new CrawlGuard({ entryUrl: 'https://pi.dev/', docsDir: docsDir(), slug: 'pi', navigate: makeGraphNav(graph) });
106
+ await guard.open();
107
+ await expect(guard.visit('https://pi.dev/#section')).rejects.toThrow(/seen/);
108
+ });
109
+ it('maxDepth=0 时任何子页 throw max-depth', async () => {
110
+ const guard = new CrawlGuard({ entryUrl: 'https://pi.dev/', docsDir: docsDir(), slug: 'pi', maxDepth: 0, navigate: makeGraphNav(graph) });
111
+ await guard.open();
112
+ await expect(guard.visit('https://pi.dev/b')).rejects.toThrow(/max-depth/);
113
+ });
114
+ it('maxPages=1 时将达页数上限 throw max-pages', async () => {
115
+ const guard = new CrawlGuard({ entryUrl: 'https://pi.dev/', docsDir: docsDir(), slug: 'pi', maxPages: 1, navigate: makeGraphNav(graph) });
116
+ await guard.open();
117
+ await expect(guard.visit('https://pi.dev/b')).rejects.toThrow(/max-pages/);
118
+ });
119
+ it('BFS 深度:A links=[B,E],visit B(d1) 后再 visit E 仍为 d1(线性深度旧实现会误拒)', async () => {
120
+ const bfsGraph = {
121
+ 'https://pi.dev/': { title: 'A', text: 'A text', links: ['https://pi.dev/b', 'https://pi.dev/e'] },
122
+ 'https://pi.dev/b': { title: 'B', text: 'B text', links: [] },
123
+ 'https://pi.dev/e': { title: 'E', text: 'E text', links: [] },
124
+ };
125
+ const guard = new CrawlGuard({ entryUrl: 'https://pi.dev/', docsDir: docsDir(), slug: 'pi', navigate: makeGraphNav(bfsGraph) });
126
+ await guard.open();
127
+ await guard.visit('https://pi.dev/b');
128
+ // E 由入口 A 链接,真实 BFS 深度=1,必须可访问
129
+ const page = await guard.visit('https://pi.dev/e');
130
+ expect(page.url).toBe('https://pi.dev/e');
131
+ const depthByUrl = guard.depthByUrl;
132
+ expect(depthByUrl.get('https://pi.dev/e')).toBe(1);
133
+ });
134
+ it('A links=[B]、B links=[C]:visit B(d1) 后 C 为 d2 > maxDepth,仍 throw max-depth', async () => {
135
+ const chainGraph = {
136
+ 'https://pi.dev/': { title: 'A', text: 'A text', links: ['https://pi.dev/b'] },
137
+ 'https://pi.dev/b': { title: 'B', text: 'B text', links: ['https://pi.dev/c'] },
138
+ 'https://pi.dev/c': { title: 'C', text: 'C text', links: [] },
139
+ };
140
+ const guard = new CrawlGuard({ entryUrl: 'https://pi.dev/', docsDir: docsDir(), slug: 'pi', navigate: makeGraphNav(chainGraph) });
141
+ await guard.open();
142
+ await guard.visit('https://pi.dev/b');
143
+ await expect(guard.visit('https://pi.dev/c')).rejects.toThrow(/max-depth/);
144
+ });
145
+ it('同一页被 d0 和 d1 两个来源链接时,深度取 min=1', async () => {
146
+ const sharedGraph = {
147
+ 'https://pi.dev/': { title: 'A', text: 'A text', links: ['https://pi.dev/b', 'https://pi.dev/e'] },
148
+ 'https://pi.dev/b': { title: 'B', text: 'B text', links: ['https://pi.dev/e'] },
149
+ 'https://pi.dev/e': { title: 'E', text: 'E text', links: [] },
150
+ };
151
+ const guard = new CrawlGuard({ entryUrl: 'https://pi.dev/', docsDir: docsDir(), slug: 'pi', navigate: makeGraphNav(sharedGraph) });
152
+ await guard.open();
153
+ await guard.visit('https://pi.dev/b');
154
+ // E 同时被 A(d0) 和 B(d1) 链接,取最短来源 → d1
155
+ await guard.visit('https://pi.dev/e');
156
+ const depthByUrl = guard.depthByUrl;
157
+ expect(depthByUrl.get('https://pi.dev/e')).toBe(1);
158
+ });
159
+ it('未被任何已抓页链接的同站 URL → throw not linked(不放行幻觉 URL)', async () => {
160
+ const guard = new CrawlGuard({
161
+ entryUrl: 'https://pi.dev/',
162
+ docsDir: docsDir(),
163
+ slug: 'pi',
164
+ navigate: makeGraphNav({ 'https://pi.dev/': { title: 'A', text: 'A text', links: [] } }),
165
+ });
166
+ await guard.open();
167
+ await expect(guard.visit('https://pi.dev/ghost')).rejects.toThrow(/not linked from any crawled page/);
168
+ });
169
+ it('navigate reject 时 seen 不增加:再次 visit 同 URL 不报 seen(失败页不占名额)', async () => {
170
+ const nav = jest.fn(async (url) => {
171
+ if (url === 'https://pi.dev/b')
172
+ throw new Error('nav boom');
173
+ return { title: 'A', text: 'A text', links: ['https://pi.dev/b'] };
174
+ });
175
+ const guard = new CrawlGuard({ entryUrl: 'https://pi.dev/', docsDir: docsDir(), slug: 'pi', navigate: nav });
176
+ await guard.open();
177
+ await expect(guard.visit('https://pi.dev/b')).rejects.toThrow(/nav boom/);
178
+ // 第二次仍因抓取失败报错,而不是 seen;seen 集合保持只有入口
179
+ await expect(guard.visit('https://pi.dev/b')).rejects.toThrow(/nav boom/);
180
+ const seen = guard.seen;
181
+ expect(seen.size).toBe(1);
182
+ });
183
+ });
184
+ describe('CrawlGuard.saveSource', () => {
185
+ it('按 source-NNN.md 落盘,内容含 Source 头,savedCount 递增', async () => {
186
+ const dir = docsDir();
187
+ const guard = new CrawlGuard({
188
+ entryUrl: 'https://pi.dev/',
189
+ docsDir: dir,
190
+ slug: 'pi',
191
+ navigate: makeGraphNav({
192
+ 'https://pi.dev/': { title: 'A', text: 'A text', links: ['https://pi.dev/b'] },
193
+ 'https://pi.dev/b': { title: 'B', text: 'B text', links: [] },
194
+ }),
195
+ });
196
+ await guard.open();
197
+ expect(guard.saveSource('https://pi.dev/')).toEqual({ savedCount: 1, reused: false });
198
+ await guard.visit('https://pi.dev/b');
199
+ expect(guard.saveSource('https://pi.dev/b')).toEqual({ savedCount: 2, reused: false });
200
+ const sourcesDir = path.join(dir, 'pi', 'sources');
201
+ const f1 = await fsp.readFile(path.join(sourcesDir, 'source-001.md'), 'utf8');
202
+ expect(f1).toBe('Source: https://pi.dev/\n\nA text');
203
+ const f2 = await fsp.readFile(path.join(sourcesDir, 'source-002.md'), 'utf8');
204
+ expect(f2).toBe('Source: https://pi.dev/b\n\nB text');
205
+ });
206
+ it('未抓取过的 URL saveSource throw', async () => {
207
+ const guard = new CrawlGuard({
208
+ entryUrl: 'https://pi.dev/',
209
+ docsDir: docsDir(),
210
+ slug: 'pi',
211
+ navigate: makeGraphNav({ 'https://pi.dev/': { title: 'A', text: 'A', links: [] } }),
212
+ });
213
+ await guard.open();
214
+ expect(() => guard.saveSource('https://pi.dev/ghost')).toThrow(/not crawled/);
215
+ });
216
+ it('同页重复 save_source:不写重复文件、reused=true、savedCount 不重复增', async () => {
217
+ const dir = docsDir();
218
+ const guard = new CrawlGuard({
219
+ entryUrl: 'https://pi.dev/',
220
+ docsDir: dir,
221
+ slug: 'pi',
222
+ navigate: makeGraphNav({ 'https://pi.dev/': { title: 'A', text: 'A text', links: [] } }),
223
+ });
224
+ await guard.open();
225
+ const r1 = guard.saveSource('https://pi.dev/');
226
+ const r2 = guard.saveSource('https://pi.dev/');
227
+ expect(r1).toEqual({ savedCount: 1, reused: false });
228
+ expect(r2).toEqual({ savedCount: 1, reused: true });
229
+ expect(guard.savedCount).toBe(1);
230
+ const files = await fsp.readdir(path.join(dir, 'pi', 'sources'));
231
+ expect(files).toEqual(['source-001.md']);
232
+ });
233
+ it('空正文页 saveSource throw empty page', async () => {
234
+ const guard = new CrawlGuard({
235
+ entryUrl: 'https://pi.dev/',
236
+ docsDir: docsDir(),
237
+ slug: 'pi',
238
+ navigate: makeGraphNav({
239
+ 'https://pi.dev/': { title: 'A', text: 'A text', links: ['https://pi.dev/b'] },
240
+ 'https://pi.dev/b': { title: 'B', text: ' \n ', links: [] },
241
+ }),
242
+ });
243
+ await guard.open();
244
+ await guard.visit('https://pi.dev/b');
245
+ expect(() => guard.saveSource('https://pi.dev/b')).toThrow(/empty page/);
246
+ });
247
+ });
248
+ describe('CrawlGuard.close', () => {
249
+ it('no-op:不起 ego-browser 进程,也不抛错', async () => {
250
+ const guard = new CrawlGuard({
251
+ entryUrl: 'https://pi.dev/',
252
+ docsDir: docsDir(),
253
+ slug: 'pi',
254
+ navigate: makeGraphNav({ 'https://pi.dev/': { title: 'A', text: 'A text', links: [] } }),
255
+ });
256
+ await expect(guard.close()).resolves.toBeUndefined();
257
+ expect(mockRunEgoBrowser).not.toHaveBeenCalled();
258
+ });
259
+ });
260
+ describe('CrawlGuard signal 透传', () => {
261
+ it('open/visit 把 abort signal 转发给 runEgoBrowser', async () => {
262
+ mockRunEgoBrowser.mockResolvedValue(JSON.stringify({ title: 'A', text: 'A text', links: ['https://pi.dev/b'] }));
263
+ const guard = new CrawlGuard({ entryUrl: 'https://pi.dev/', docsDir: docsDir(), slug: 'pi' });
264
+ const signal = new AbortController().signal;
265
+ await guard.open(signal);
266
+ expect(mockRunEgoBrowser).toHaveBeenNthCalledWith(1, expect.any(String), { timeoutMs: 60000, signal });
267
+ await guard.visit('https://pi.dev/b', signal);
268
+ expect(mockRunEgoBrowser).toHaveBeenNthCalledWith(2, expect.any(String), { timeoutMs: 60000, signal });
269
+ });
270
+ it('crawl_open/crawl_visit 的 execute 把 signal 透传给 guard.navigate', async () => {
271
+ const nav = jest.fn(async () => ({ title: 'A', text: 'A text', links: ['https://pi.dev/b'] }));
272
+ const guard = new CrawlGuard({ entryUrl: 'https://pi.dev/', docsDir: docsDir(), slug: 'pi', navigate: nav });
273
+ const tools = createCrawlTools(guard);
274
+ const byName = Object.fromEntries(tools.map((t) => [t.name, t]));
275
+ const signal = new AbortController().signal;
276
+ await byName.crawl_open.execute('id-1', {}, signal, undefined, {});
277
+ expect(nav).toHaveBeenNthCalledWith(1, 'https://pi.dev/', signal);
278
+ await byName.crawl_visit.execute('id-2', { url: 'https://pi.dev/b' }, signal, undefined, {});
279
+ expect(nav).toHaveBeenNthCalledWith(2, 'https://pi.dev/b', signal);
280
+ });
281
+ });
282
+ describe('createCrawlTools', () => {
283
+ function makeGuard() {
284
+ return new CrawlGuard({
285
+ entryUrl: 'https://pi.dev/',
286
+ docsDir: docsDir(),
287
+ slug: 'pi',
288
+ navigate: makeGraphNav({
289
+ 'https://pi.dev/': { title: 'A', text: 'A text', links: ['https://pi.dev/b', 'https://other.com/x'] },
290
+ 'https://pi.dev/b': { title: 'B', text: 'B text', links: [] },
291
+ }),
292
+ });
293
+ }
294
+ it('提供 crawl_open/crawl_visit/save_source/crawl_finish 四个工具', () => {
295
+ const tools = createCrawlTools(makeGuard());
296
+ expect(tools.map((t) => t.name)).toEqual(['crawl_open', 'crawl_visit', 'save_source', 'crawl_finish']);
297
+ });
298
+ it('工具错误以可读文本返回(不抛异常)', async () => {
299
+ mockRunEgoBrowser.mockResolvedValue('closed');
300
+ const guard = makeGuard();
301
+ const tools = createCrawlTools(guard);
302
+ const byName = Object.fromEntries(tools.map((t) => [t.name, t]));
303
+ const textOf = (res) => res.content.map((c) => c.text ?? '').join('\n');
304
+ // execute 签名 5 参(id/params/signal/onUpdate/ctx),测试只需前 2 个
305
+ const call = (tool, params) => tool.execute('id', params, undefined, undefined, undefined);
306
+ const openRes = await call(byName.crawl_open, {});
307
+ expect(textOf(openRes)).toContain('https://pi.dev/');
308
+ const badRes = await call(byName.crawl_visit, { url: 'https://other.com/x' });
309
+ expect(textOf(badRes)).toMatch(/error:.*cross-site/);
310
+ const saveRes = await call(byName.save_source, { url: 'https://pi.dev/' });
311
+ expect(textOf(saveRes)).toContain('"savedCount":1');
312
+ const finishRes = await call(byName.crawl_finish, {});
313
+ expect(textOf(finishRes)).toContain('"finished":true');
314
+ });
315
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,89 @@
1
+ jest.mock('../pi-runtime.js', () => ({ runJsonPrompt: jest.fn() }));
2
+ import { mkdtemp, mkdir, writeFile } from 'fs/promises';
3
+ import os from 'os';
4
+ import path from 'path';
5
+ import { runJsonPrompt } from '../pi-runtime.js';
6
+ import { reconcileTopics, readAllTopics, readTopicDetail, mintSlug } from '../pi-dedup.js';
7
+ const mockJson = runJsonPrompt;
8
+ let tmp;
9
+ beforeEach(async () => {
10
+ tmp = await mkdtemp(path.join(os.tmpdir(), 'pi-dedup-'));
11
+ mockJson.mockReset();
12
+ });
13
+ test('预筛命中 → 调 LLM,match=true 透传 targetSlug/mergedTitle/itemsToAdd', async () => {
14
+ mockJson.mockResolvedValue({ match: true, targetSlug: 'a', mergedTitle: 'M', mergedSummary: 's',
15
+ confidence: 0.62, itemsToAdd: [{ id: 'x', title: 'X', oneLine: 'x' }] });
16
+ const r = await reconcileTopics({ port: 1, docsDir: tmp, wantItems: true,
17
+ candidate: { slug: 'new', title: 'React Hooks', tags: [] },
18
+ targets: [{ slug: 'a', title: 'React Hooks', summary: '', tags: [], chunks: [] }] });
19
+ expect(r.match).toBe(true);
20
+ expect(r.targetSlug).toBe('a');
21
+ expect(r.itemsToAdd).toHaveLength(1);
22
+ });
23
+ test('LLM 抛错(坏 JSON)→ 安全返回 match=false', async () => {
24
+ mockJson.mockRejectedValue(new Error('no json object in response'));
25
+ await expect(reconcileTopics({ port: 1, docsDir: tmp, wantItems: false,
26
+ candidate: { slug: 'new', title: 'T', tags: [] },
27
+ targets: [{ slug: 'a', title: 'T', summary: '', tags: [], chunks: [] }] }))
28
+ .resolves.toMatchObject({ match: false });
29
+ });
30
+ test('正载荷回显候选自身 slug(未提供的目标)→ match=false', async () => {
31
+ mockJson.mockResolvedValue({ match: true, targetSlug: 'new', mergedTitle: 'M',
32
+ mergedSummary: 's', itemsToAdd: [] });
33
+ const r = await reconcileTopics({ port: 1, docsDir: tmp, wantItems: true,
34
+ candidate: { slug: 'new', title: 'React Hooks', tags: [] },
35
+ targets: [{ slug: 'a', title: 'React Hooks', summary: '', tags: [], chunks: [] }] });
36
+ expect(r).toEqual({ match: false });
37
+ });
38
+ test('正载荷缺 mergedTitle → match=false', async () => {
39
+ mockJson.mockResolvedValue({ match: true, targetSlug: 'a', mergedSummary: 's', itemsToAdd: [] });
40
+ const r = await reconcileTopics({ port: 1, docsDir: tmp, wantItems: true,
41
+ candidate: { slug: 'new', title: 'React Hooks', tags: [] },
42
+ targets: [{ slug: 'a', title: 'React Hooks', summary: '', tags: [], chunks: [] }] });
43
+ expect(r).toEqual({ match: false });
44
+ });
45
+ test('空目标 → 不调 LLM,match=false', async () => {
46
+ const r = await reconcileTopics({ port: 1, docsDir: tmp, wantItems: false,
47
+ candidate: { slug: 'new', title: 'zzz', tags: [] }, targets: [] });
48
+ expect(r).toEqual({ match: false });
49
+ expect(mockJson).not.toHaveBeenCalled();
50
+ });
51
+ test('预筛空且目标>20 → 不调 LLM,match=false', async () => {
52
+ const targets = Array.from({ length: 21 }, (_, i) => ({ slug: `s${i}`, title: `Distinct ${i}`, summary: '', tags: [], chunks: [] }));
53
+ const r = await reconcileTopics({ port: 1, docsDir: tmp, wantItems: false,
54
+ candidate: { slug: 'new', title: 'zzzz-noise', tags: [] }, targets });
55
+ expect(r.match).toBe(false);
56
+ expect(mockJson).not.toHaveBeenCalled();
57
+ });
58
+ test('readAllTopics: 返回 index.json 的 topics', async () => {
59
+ await writeFile(path.join(tmp, 'index.json'), JSON.stringify({
60
+ topics: [{ slug: 'a', title: 'A', summary: '', tags: [] }],
61
+ }));
62
+ await expect(readAllTopics(tmp)).resolves.toMatchObject([{ slug: 'a', title: 'A' }]);
63
+ });
64
+ test('readAllTopics: 空/缺失目录返回 []', async () => {
65
+ await expect(readAllTopics(tmp)).resolves.toEqual([]);
66
+ });
67
+ describe('mintSlug', () => {
68
+ test('LLM 返回合法且空闲的 slug → 直接使用', async () => {
69
+ mockJson.mockResolvedValue({ slug: 'react-hooks' });
70
+ await expect(mintSlug({ port: 1, title: 'React Hooks', existing: [] })).resolves.toBe('react-hooks');
71
+ });
72
+ test('LLM 返回非法 slug → 降级 slugFromLabel(title)', async () => {
73
+ mockJson.mockResolvedValue({ slug: 'Bad Slug!' });
74
+ await expect(mintSlug({ port: 1, title: 'Hello World', existing: [] })).resolves.toBe('hello-world');
75
+ });
76
+ test('LLM slug 与 slugFromLabel(title) 均被占 → 追加 -2', async () => {
77
+ mockJson.mockResolvedValue({ slug: 'my-topic' });
78
+ await expect(mintSlug({ port: 1, title: 'My Topic', existing: ['my-topic'] }))
79
+ .resolves.toBe('my-topic-2');
80
+ });
81
+ });
82
+ test('readTopicDetail: 返回 <slug>/index.json 解析结果;缺失返回 null', async () => {
83
+ await mkdir(path.join(tmp, 'a'));
84
+ await writeFile(path.join(tmp, 'a', 'index.json'), JSON.stringify({
85
+ slug: 'a', title: 'A', summary: 's', tags: ['t'], chunks: [],
86
+ }));
87
+ await expect(readTopicDetail(tmp, 'a')).resolves.toMatchObject({ slug: 'a', chunks: [] });
88
+ await expect(readTopicDetail(tmp, 'missing')).resolves.toBeNull();
89
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,106 @@
1
+ jest.mock('../pi-runtime.js', () => ({ runJsonPrompt: jest.fn() }));
2
+ import { findCandidates, mergeTopics, assertNoOldDirs } from '../pi-dedup.js';
3
+ import fs from 'node:fs';
4
+ import os from 'node:os';
5
+ import path from 'node:path';
6
+ // ---- mergeTopics / assertNoOldDirs:真实 tmpDir 手工铺盘 ----
7
+ const pad3 = (n) => String(n).padStart(3, '0');
8
+ // 铺一个 topic:sources 为正文数组(按序 source-NNN);chunks 为 { id?, body }
9
+ function layoutTopic(docsDir, slug, opts = {}) {
10
+ const topicDir = path.join(docsDir, slug);
11
+ fs.mkdirSync(path.join(topicDir, 'sources'), { recursive: true });
12
+ fs.mkdirSync(path.join(topicDir, 'chunks'), { recursive: true });
13
+ for (let i = 0; i < (opts.sources ?? []).length; i++) {
14
+ fs.writeFileSync(path.join(topicDir, 'sources', `source-${pad3(i + 1)}.md`), opts.sources[i]);
15
+ }
16
+ const chunks = (opts.chunks ?? []).map((c, i) => {
17
+ const id = c.id ?? `chunk-${pad3(i + 1)}`;
18
+ fs.writeFileSync(path.join(topicDir, 'chunks', `${id}.md`), c.body);
19
+ return { id, title: id, summary: '', tags: [] };
20
+ });
21
+ fs.writeFileSync(path.join(topicDir, 'index.json'), JSON.stringify({ slug, title: slug, summary: '', tags: [], chunks }));
22
+ }
23
+ function writeRoot(docsDir, slugs) {
24
+ fs.writeFileSync(path.join(docsDir, 'index.json'), JSON.stringify({ topics: slugs.map(slug => ({ slug, title: slug, summary: '', tags: [] })) }));
25
+ }
26
+ function freshTmp() {
27
+ return fs.mkdtempSync(path.join(os.tmpdir(), 'pi-dedup-'));
28
+ }
29
+ test('findCandidates: title 归一相等命中并排前', () => {
30
+ const topics = [
31
+ { slug: 'a', title: 'React Hooks', summary: '', tags: [] },
32
+ { slug: 'b', title: 'Other', summary: '', tags: [] },
33
+ ];
34
+ expect(findCandidates({ title: 'react hooks!', tags: [] }, topics).map(t => t.slug)).toEqual(['a']);
35
+ });
36
+ test('findCandidates: tag 相交命中', () => {
37
+ const topics = [{ slug: 'c', title: 'X', summary: '', tags: ['state-management'] }];
38
+ expect(findCandidates({ title: 'zzz', tags: ['State Management'] }, topics)).toHaveLength(1);
39
+ });
40
+ test('findCandidates: 无命中返回 []', () => {
41
+ expect(findCandidates({ title: 'qqq', tags: [] }, [{ slug: 'd', title: 'rrr', summary: '', tags: [] }])).toEqual([]);
42
+ });
43
+ test('mergeTopics: 两边都有 → sources 续号、chunks 重编号、refs 合并、根 index 移除 src', () => {
44
+ const tmp = freshTmp();
45
+ layoutTopic(tmp, 'dsta', { sources: ['dst source'], chunks: [{ body: 'dst chunk' }] });
46
+ layoutTopic(tmp, 'newb', { sources: ['src source'], chunks: [{ body: 'src c1' }, { body: 'src c2' }] });
47
+ writeRoot(tmp, ['dsta', 'newb', 'other']);
48
+ expect(mergeTopics(tmp, 'newb', 'dsta')).toBe(3);
49
+ expect(fs.readdirSync(path.join(tmp, 'dsta', 'sources')).sort())
50
+ .toEqual(['source-001.md', 'source-002.md']);
51
+ expect(fs.readdirSync(path.join(tmp, 'dsta', 'chunks')).sort())
52
+ .toEqual(['chunk-001.md', 'chunk-002.md', 'chunk-003.md']);
53
+ // src 目录已删;根 index 无 newb,其余保留
54
+ expect(fs.existsSync(path.join(tmp, 'newb'))).toBe(false);
55
+ const root = JSON.parse(fs.readFileSync(path.join(tmp, 'index.json'), 'utf8'));
56
+ expect(root.topics.map((t) => t.slug)).toEqual(['dsta', 'other']);
57
+ // refs 已合并进 dst index
58
+ const dstIndex = JSON.parse(fs.readFileSync(path.join(tmp, 'dsta', 'index.json'), 'utf8'));
59
+ expect(dstIndex.chunks.map((c) => c.id))
60
+ .toEqual(['chunk-001', 'chunk-002', 'chunk-003']);
61
+ });
62
+ test('mergeTopics: src 无 chunks(门1)→ 只移 sources,返回 dst 原 chunk 数', () => {
63
+ const tmp = freshTmp();
64
+ layoutTopic(tmp, 'dsta', { sources: ['dst source'], chunks: [{ body: 'dst chunk' }] });
65
+ layoutTopic(tmp, 'newb', { sources: ['src source 1', 'src source 2'] });
66
+ writeRoot(tmp, ['dsta', 'newb']);
67
+ expect(mergeTopics(tmp, 'newb', 'dsta')).toBe(1);
68
+ expect(fs.readdirSync(path.join(tmp, 'dsta', 'chunks')).sort()).toEqual(['chunk-001.md']);
69
+ expect(fs.readdirSync(path.join(tmp, 'dsta', 'sources')).sort())
70
+ .toEqual(['source-001.md', 'source-002.md', 'source-003.md']);
71
+ });
72
+ test('mergeTopics: dst 无 chunks(门0)→ src chunks 从 chunk-001 起重编号并入', () => {
73
+ const tmp = freshTmp();
74
+ layoutTopic(tmp, 'dsta', {});
75
+ layoutTopic(tmp, 'newb', { chunks: [{ body: 'src c1' }, { body: 'src c2' }] });
76
+ writeRoot(tmp, ['dsta', 'newb']);
77
+ expect(mergeTopics(tmp, 'newb', 'dsta')).toBe(2);
78
+ expect(fs.readdirSync(path.join(tmp, 'dsta', 'chunks')).sort())
79
+ .toEqual(['chunk-001.md', 'chunk-002.md']);
80
+ expect(fs.readFileSync(path.join(tmp, 'dsta', 'chunks', 'chunk-001.md'), 'utf8')).toBe('src c1');
81
+ expect(fs.readFileSync(path.join(tmp, 'dsta', 'chunks', 'chunk-002.md'), 'utf8')).toBe('src c2');
82
+ });
83
+ test('mergeTopics: chunk 正文逐字不变(含花括号与换行)', () => {
84
+ const tmp = freshTmp();
85
+ layoutTopic(tmp, 'dsta', { chunks: [{ body: 'dst chunk' }] });
86
+ const body = '{\n "key": "值 {braces}\n换行"\n}\n最后一行\n';
87
+ layoutTopic(tmp, 'newb', { chunks: [{ body }] });
88
+ writeRoot(tmp, ['dsta', 'newb']);
89
+ mergeTopics(tmp, 'newb', 'dsta');
90
+ // src chunk-001 偏移为 dst chunk-002,正文逐字一致
91
+ expect(fs.readFileSync(path.join(tmp, 'dsta', 'chunks', 'chunk-002.md'), 'utf8')).toBe(body);
92
+ });
93
+ test('mergeTopics: src 与 dst 相同 → 抛错防自合并', () => {
94
+ const tmp = freshTmp();
95
+ layoutTopic(tmp, 't', {});
96
+ writeRoot(tmp, ['t']);
97
+ expect(() => mergeTopics(tmp, 't', 't')).toThrow('mergeTopics: src 与 dst 相同');
98
+ });
99
+ test('assertNoOldDirs: 存在 x.old → 抛精确错误;无 → 不抛', () => {
100
+ const withOld = freshTmp();
101
+ fs.mkdirSync(path.join(withOld, 'x.old'));
102
+ expect(() => assertNoOldDirs(withOld)).toThrow('检测到未清理的旁挂目录 x.old,请手工处理后再学习');
103
+ const clean = freshTmp();
104
+ fs.mkdirSync(path.join(clean, 'normal-slug'));
105
+ expect(() => assertNoOldDirs(clean)).not.toThrow();
106
+ });