@cc-monitoring/proxy-core 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (389) hide show
  1. package/dist/cli/__tests__/commands.test.js +1 -1
  2. package/dist/cli/commands/exec.js +31 -42
  3. package/dist/docs/404.html +2 -2
  4. package/dist/docs/assets/{app.Dc46Hlqp.js → app.DtYNT5zS.js} +1 -1
  5. package/dist/docs/assets/chunks/@localSearchIndexroot.C4sjikMO.js +1 -0
  6. package/dist/docs/assets/chunks/{VPLocalSearchBox.Snq5jR6J.js → VPLocalSearchBox.DpXF9ZAI.js} +1 -1
  7. package/dist/docs/assets/chunks/{theme.XLtxGM-l.js → theme.TS_gUyc7.js} +2 -2
  8. package/dist/docs/assets/{proxy-cli_data-hooks.md.w9Oe1OD3.js → proxy-cli_data-hooks.md.Bz8CVbxO.js} +1 -1
  9. package/dist/docs/assets/{proxy-core_ui-routes.md.Dyqkeoiv.js → proxy-core_ui-routes.md.B21t1p7R.js} +1 -1
  10. package/dist/docs/hashmap.json +1 -1
  11. package/dist/docs/index.html +3 -3
  12. package/dist/docs/overview.html +3 -3
  13. package/dist/docs/packages-utils.html +3 -3
  14. package/dist/docs/proxy-admin/env-and-build.html +3 -3
  15. package/dist/docs/proxy-admin/index.html +3 -3
  16. package/dist/docs/proxy-admin/layout-and-menu.html +3 -3
  17. package/dist/docs/proxy-admin/pages.html +3 -3
  18. package/dist/docs/proxy-admin/routing-and-auth.html +3 -3
  19. package/dist/docs/proxy-admin/services-and-mock.html +3 -3
  20. package/dist/docs/proxy-cli/api-layer.html +3 -3
  21. package/dist/docs/proxy-cli/app-shell.html +3 -3
  22. package/dist/docs/proxy-cli/components-common.html +3 -3
  23. package/dist/docs/proxy-cli/components-config.html +3 -3
  24. package/dist/docs/proxy-cli/components-requests.html +3 -3
  25. package/dist/docs/proxy-cli/components-stats.html +3 -3
  26. package/dist/docs/proxy-cli/components-status.html +3 -3
  27. package/dist/docs/proxy-cli/data-hooks.html +5 -5
  28. package/dist/docs/proxy-cli/index.html +3 -3
  29. package/dist/docs/proxy-cli/utils-and-i18n.html +3 -3
  30. package/dist/docs/proxy-core/chat-api.html +3 -3
  31. package/dist/docs/proxy-core/cli.html +3 -3
  32. package/dist/docs/proxy-core/config.html +3 -3
  33. package/dist/docs/proxy-core/data-layer.html +3 -3
  34. package/dist/docs/proxy-core/entry.html +3 -3
  35. package/dist/docs/proxy-core/index.html +3 -3
  36. package/dist/docs/proxy-core/pm2.html +3 -3
  37. package/dist/docs/proxy-core/providers.html +3 -3
  38. package/dist/docs/proxy-core/proxy.html +3 -3
  39. package/dist/docs/proxy-core/stats.html +3 -3
  40. package/dist/docs/proxy-core/tool.html +3 -3
  41. package/dist/docs/proxy-core/ui-routes.html +5 -5
  42. package/dist/docs/proxy-core/utilities.html +3 -3
  43. package/dist/docs/quickstart.html +3 -3
  44. package/dist/docs/request-flow.html +3 -3
  45. package/dist/logger/index.d.ts +0 -3
  46. package/dist/logger/index.js +0 -1
  47. package/dist/mcp-server/index.js +5 -3
  48. package/dist/mcp-server/tools.js +31 -10
  49. package/dist/server/__tests__/providers-route.test.js +1 -0
  50. package/dist/server/auth.d.ts +0 -1
  51. package/dist/server/auth.js +1 -1
  52. package/dist/server/chat-route.js +48 -156
  53. package/dist/server/data-push.d.ts +0 -1
  54. package/dist/server/data-push.js +0 -7
  55. package/dist/server/proxy.js +128 -219
  56. package/dist/server/ui-route.js +76 -59
  57. package/dist/tools/index.d.ts +1 -1
  58. package/dist/tools/index.js +1 -1
  59. package/dist/tools/registry.d.ts +0 -4
  60. package/dist/tools/registry.js +0 -8
  61. package/dist/types/config.d.ts +0 -13
  62. package/dist/types/pm2.d.ts +1 -2
  63. package/dist/ui/assets/{1c-Bx3CHH-I.js → 1c-CCx-FOtz.js} +1 -1
  64. package/dist/ui/assets/{abnf-NN4-iXDM.js → abnf-Bwbi42Z8.js} +1 -1
  65. package/dist/ui/assets/{abnfDiagram-VRR7QNED-CXFZgDk7.js → abnfDiagram-VRR7QNED-Dm1-8q0E.js} +1 -1
  66. package/dist/ui/assets/{accesslog-Bq9x4vSZ.js → accesslog-DCytz_-m.js} +1 -1
  67. package/dist/ui/assets/{actionscript-CeaB6gjT.js → actionscript-3udf15oh.js} +1 -1
  68. package/dist/ui/assets/{ada-DObFDSC6.js → ada-M5Xa74xG.js} +1 -1
  69. package/dist/ui/assets/{angelscript-4pIbuWPH.js → angelscript-qlrFxfW-.js} +1 -1
  70. package/dist/ui/assets/{apache-w0LzP4me.js → apache-B-sF-DQH.js} +1 -1
  71. package/dist/ui/assets/{applescript-DXpD6Cc9.js → applescript-4FdcBnbI.js} +1 -1
  72. package/dist/ui/assets/{arc-Dtt1H4m8.js → arc-BB3K1enp.js} +1 -1
  73. package/dist/ui/assets/{arcade-D_zU9Djr.js → arcade-B_yqWaaG.js} +1 -1
  74. package/dist/ui/assets/{architectureDiagram-ZJ3FMSHR-C0E_eQDM.js → architectureDiagram-ZJ3FMSHR-B39vkY8V.js} +1 -1
  75. package/dist/ui/assets/{arduino-BnmN_xp_.js → arduino-yAcBoTWU.js} +1 -1
  76. package/dist/ui/assets/{armasm-CH_xJaHf.js → armasm-wIcY84bI.js} +1 -1
  77. package/dist/ui/assets/{asciidoc-BlvZZ-hO.js → asciidoc-Bxnu28-Z.js} +1 -1
  78. package/dist/ui/assets/{aspectj-DP5DdFKQ.js → aspectj-B2cKJA_O.js} +1 -1
  79. package/dist/ui/assets/{autohotkey-Cy7dy_B1.js → autohotkey-B_rMWTtE.js} +1 -1
  80. package/dist/ui/assets/{autoit-BmQwjQdM.js → autoit-DwcuvMwv.js} +1 -1
  81. package/dist/ui/assets/{avrasm-fcPy4w1X.js → avrasm-heGX1PXK.js} +1 -1
  82. package/dist/ui/assets/{awk-AlcwGSdk.js → awk-BiqCQAEf.js} +1 -1
  83. package/dist/ui/assets/{axapta-NyMN6Mvz.js → axapta-Cv8M-Ih6.js} +1 -1
  84. package/dist/ui/assets/{bash-Bn3yyTUs.js → bash-Divgn3JV.js} +1 -1
  85. package/dist/ui/assets/{basic-gp9eOjjv.js → basic-B9dnAP55.js} +1 -1
  86. package/dist/ui/assets/{blockDiagram-677ZJIJ3-BHAadGGo.js → blockDiagram-677ZJIJ3-DQ1mf7A_.js} +1 -1
  87. package/dist/ui/assets/{bnf-DRAiK-_J.js → bnf-kIL5mSsP.js} +1 -1
  88. package/dist/ui/assets/{brainfuck-IYgPavhh.js → brainfuck-DqB7xDjH.js} +1 -1
  89. package/dist/ui/assets/{coq-BYVsAo31.js → c-HmsCM6sx.js} +1 -1
  90. package/dist/ui/assets/{c-like-B7T39dtK.js → c-like-De5MhE7G.js} +1 -1
  91. package/dist/ui/assets/{c4Diagram-LMCZKHZV-4cXT8R9f.js → c4Diagram-LMCZKHZV-DQxtYsAx.js} +1 -1
  92. package/dist/ui/assets/{cal-DmXm_WLX.js → cal-mYdfz9en.js} +1 -1
  93. package/dist/ui/assets/{capnproto-Cb-rKd-Z.js → capnproto-D04CRlOt.js} +1 -1
  94. package/dist/ui/assets/{ceylon-Bn2aNwEq.js → ceylon-pi9lFCja.js} +1 -1
  95. package/dist/ui/assets/channel-ChTtxQDg.js +1 -0
  96. package/dist/ui/assets/{chunk-2Q5K7J3B-B3N_AddF.js → chunk-2Q5K7J3B-BDD1nPt8.js} +1 -1
  97. package/dist/ui/assets/{chunk-32BRIVSS-CW7iU3gE.js → chunk-32BRIVSS-DgeQFBb5.js} +1 -1
  98. package/dist/ui/assets/{chunk-5VM5RSS4-M8Ep3dJD.js → chunk-5VM5RSS4-C7Xf2SnI.js} +1 -1
  99. package/dist/ui/assets/{chunk-EX3LRPZG-t2hCXH-v.js → chunk-EX3LRPZG-B_3p1HEv.js} +1 -1
  100. package/dist/ui/assets/{chunk-JWPE2WC7-rQK8maXo.js → chunk-JWPE2WC7-Dvs7u8eY.js} +1 -1
  101. package/dist/ui/assets/{chunk-MOJQB5TN-BpU7vp3L.js → chunk-MOJQB5TN-By21wDCN.js} +1 -1
  102. package/dist/ui/assets/{chunk-RYQCIY6F-CJVNOulR.js → chunk-RYQCIY6F-6NC700r1.js} +1 -1
  103. package/dist/ui/assets/{chunk-V7JOEXUC-B--maww3.js → chunk-V7JOEXUC-vEUqZ3rh.js} +1 -1
  104. package/dist/ui/assets/{chunk-VR4S4FIN-QJ5u9nSh.js → chunk-VR4S4FIN-6tX2dNN9.js} +1 -1
  105. package/dist/ui/assets/{chunk-XXDRQBXY-BcM9JOXa.js → chunk-XXDRQBXY-qDb2jxAR.js} +1 -1
  106. package/dist/ui/assets/classDiagram-OUVF2IWQ-Ccbvamlu.js +1 -0
  107. package/dist/ui/assets/classDiagram-v2-EOCWNBFH-Ccbvamlu.js +1 -0
  108. package/dist/ui/assets/{clean-BCfhFoON.js → clean-CLCsDUl1.js} +1 -1
  109. package/dist/ui/assets/{clojure-DtnBj8eB.js → clojure-dVi5Xifj.js} +1 -1
  110. package/dist/ui/assets/{clojure-repl-D8X-urCW.js → clojure-repl-BO_FpFmF.js} +1 -1
  111. package/dist/ui/assets/{cmake-BH2RXBgt.js → cmake-CP5aJbyK.js} +1 -1
  112. package/dist/ui/assets/{coffeescript-CuoLiQ_d.js → coffeescript-ZEfu_9pF.js} +1 -1
  113. package/dist/ui/assets/{c-Dht0EgwX.js → coq-6aKUn3zn.js} +1 -1
  114. package/dist/ui/assets/{cos-t-cDfrf6.js → cos-BohCnRN2.js} +1 -1
  115. package/dist/ui/assets/{cose-bilkent-JH36ORCC-CYip_9u7.js → cose-bilkent-JH36ORCC-DyXCbbro.js} +1 -1
  116. package/dist/ui/assets/{cpp-Cgv0dQ7g.js → cpp-FOgPWPEt.js} +1 -1
  117. package/dist/ui/assets/{crmsh-7pr1Pq_e.js → crmsh-B0OYb-Oe.js} +1 -1
  118. package/dist/ui/assets/{crystal-BHZFifeV.js → crystal-CuWb_dXm.js} +1 -1
  119. package/dist/ui/assets/{csharp-CVMfBRGF.js → csharp-BbcqM09j.js} +1 -1
  120. package/dist/ui/assets/{csp-NEBRDuZY.js → csp-rgHnTaDq.js} +1 -1
  121. package/dist/ui/assets/{css-B0fbMkoQ.js → css-C-ibh7ZG.js} +1 -1
  122. package/dist/ui/assets/{cynefin-VYW2F7L2-CycR2u2l.js → cynefin-VYW2F7L2-CkuBhgC4.js} +1 -1
  123. package/dist/ui/assets/{cynefinDiagram-TSTJHNR4-CvXYb5em.js → cynefinDiagram-TSTJHNR4-eycFyDao.js} +1 -1
  124. package/dist/ui/assets/{d-AzA6F7Ab.js → d-C0gXxJ0O.js} +1 -1
  125. package/dist/ui/assets/{dagre-VKFMJZFB-6NuSYMRG.js → dagre-VKFMJZFB-DzqX9e49.js} +1 -1
  126. package/dist/ui/assets/{dart-D0VXSwKi.js → dart-C-fTpuUV.js} +1 -1
  127. package/dist/ui/assets/{delphi-B-bkLmCx.js → delphi-Chm0B9xv.js} +1 -1
  128. package/dist/ui/assets/{diagram-FQU43EPY-CNNW_5O7.js → diagram-FQU43EPY-BEgCqfg1.js} +1 -1
  129. package/dist/ui/assets/{diagram-G47NLZAW-C60bRph-.js → diagram-G47NLZAW-Cw11Vs2v.js} +1 -1
  130. package/dist/ui/assets/{diagram-NH7WQ7WH-CwERNWac.js → diagram-NH7WQ7WH-DSG_UWpP.js} +1 -1
  131. package/dist/ui/assets/{diagram-OA4YK3LP-9XSTmf1Z.js → diagram-OA4YK3LP-CJz-WOaJ.js} +1 -1
  132. package/dist/ui/assets/{diagram-WEI45ONY-h8K41_YA.js → diagram-WEI45ONY-CBXjBCvc.js} +1 -1
  133. package/dist/ui/assets/{diff-Ch9RlEn8.js → diff-C-vyuMSL.js} +1 -1
  134. package/dist/ui/assets/{django-C00rhzcB.js → django-CJK7lReT.js} +1 -1
  135. package/dist/ui/assets/{dns-C5MKVde0.js → dns-D02SHjSy.js} +1 -1
  136. package/dist/ui/assets/{dockerfile-BpRaVDMB.js → dockerfile-trKL1Bqu.js} +1 -1
  137. package/dist/ui/assets/{dos-CjQOJ_vn.js → dos-C52dy-sK.js} +1 -1
  138. package/dist/ui/assets/{dsconfig-3zd3UkyN.js → dsconfig-MzHgzVrt.js} +1 -1
  139. package/dist/ui/assets/{dts-Bb6PtK5T.js → dts-B137dHyX.js} +1 -1
  140. package/dist/ui/assets/{dust-BEJKezIa.js → dust-BcbM0r5C.js} +1 -1
  141. package/dist/ui/assets/{ebnf-5-TvfsoC.js → ebnf-DkbpI7bK.js} +1 -1
  142. package/dist/ui/assets/{ebnfDiagram-CCIWWBDH-CRmIjeas.js → ebnfDiagram-CCIWWBDH-aI5uQ7w1.js} +1 -1
  143. package/dist/ui/assets/{elixir-B6gSEyen.js → elixir-BOtDuqQy.js} +1 -1
  144. package/dist/ui/assets/{elm-rR0aqyyf.js → elm-DS8Tyyu-.js} +1 -1
  145. package/dist/ui/assets/{erDiagram-Q63AITRT-DS3jYOq8.js → erDiagram-Q63AITRT-2vCbd4Mm.js} +1 -1
  146. package/dist/ui/assets/{erb-DUu22Jxg.js → erb-CSXECRbn.js} +1 -1
  147. package/dist/ui/assets/{erlang-C0m-R-6W.js → erlang-BMxlgKPJ.js} +1 -1
  148. package/dist/ui/assets/{erlang-repl-B7O2MhlI.js → erlang-repl-DPzlolPg.js} +1 -1
  149. package/dist/ui/assets/{excel-CIqnqFs1.js → excel-CW2Uxed3.js} +1 -1
  150. package/dist/ui/assets/{fix-Ds9tcTzQ.js → fix-UW84SlCs.js} +1 -1
  151. package/dist/ui/assets/{flix-ByzuevTB.js → flix-4UGiPULd.js} +1 -1
  152. package/dist/ui/assets/{flowDiagram-23GEKE2U-B9F3S_Hl.js → flowDiagram-23GEKE2U-R5PbCbZI.js} +1 -1
  153. package/dist/ui/assets/{fortran-DieSVGx5.js → fortran-nhHsngdu.js} +1 -1
  154. package/dist/ui/assets/{fsharp-DGP8m6H3.js → fsharp-CDyZ1ST5.js} +1 -1
  155. package/dist/ui/assets/{gams-BiLGBohb.js → gams-DHzkkUie.js} +1 -1
  156. package/dist/ui/assets/{ganttDiagram-NO4QXBWP-CHiCWnJt.js → ganttDiagram-NO4QXBWP-CGcq4Ie_.js} +1 -1
  157. package/dist/ui/assets/{gauss-Btl1fjJ0.js → gauss-DdhFGyBv.js} +1 -1
  158. package/dist/ui/assets/{gcode-DWl2YoL_.js → gcode-ImHh8OLA.js} +1 -1
  159. package/dist/ui/assets/{gherkin-D42ESIJ2.js → gherkin-CTWAW-XR.js} +1 -1
  160. package/dist/ui/assets/{gitGraphDiagram-IHSO6WYX-0pEKZnJg.js → gitGraphDiagram-IHSO6WYX-8nM2Z9lD.js} +1 -1
  161. package/dist/ui/assets/{glsl-Dx1QhGIM.js → glsl-0_W_27G2.js} +1 -1
  162. package/dist/ui/assets/{gml-f0noEVTB.js → gml-BoDggu2z.js} +1 -1
  163. package/dist/ui/assets/{go-DXT6c-0g.js → go-DYfFygwl.js} +1 -1
  164. package/dist/ui/assets/{golo-D3NuJxTg.js → golo-Mlq-TCg9.js} +1 -1
  165. package/dist/ui/assets/{gradle-CUsTLc_e.js → gradle-BALAinEB.js} +1 -1
  166. package/dist/ui/assets/{groovy-BIkOcIpQ.js → groovy-Dht--dWU.js} +1 -1
  167. package/dist/ui/assets/{haml-C5jI7YVN.js → haml-DpMrxg0d.js} +1 -1
  168. package/dist/ui/assets/{handlebars-UOvbWwDx.js → handlebars-DqHzujNj.js} +1 -1
  169. package/dist/ui/assets/{haskell-DuO_Av2n.js → haskell-DZSchhkY.js} +1 -1
  170. package/dist/ui/assets/{haxe-C0Cg5Hjh.js → haxe-C0zBRjdy.js} +1 -1
  171. package/dist/ui/assets/{hsp-CTDajZig.js → hsp-D_PwbSv2.js} +1 -1
  172. package/dist/ui/assets/{htmlbars-_ITuCkOs.js → htmlbars-DxAFMG8u.js} +1 -1
  173. package/dist/ui/assets/{http-Dr26PHfb.js → http-DvTRF0Do.js} +1 -1
  174. package/dist/ui/assets/{hy-B-ThgV4T.js → hy-lVO-kNyp.js} +1 -1
  175. package/dist/ui/assets/{index-CpQr158p.js → index-BbMRVVGt.js} +3 -3
  176. package/dist/ui/assets/{index-CwcnuNUs.js → index-Ci23SMK2.js} +242 -242
  177. package/dist/ui/assets/index-DlsVXaHT.css +10 -0
  178. package/dist/ui/assets/{infoDiagram-FWYZ7A6U-ClKPOdlx.js → infoDiagram-FWYZ7A6U-C7WYDlvc.js} +1 -1
  179. package/dist/ui/assets/{inform7-D7JYYkX9.js → inform7-B8Tf2n8v.js} +1 -1
  180. package/dist/ui/assets/{ini-BZwCkFAf.js → ini-DSoYMaLF.js} +1 -1
  181. package/dist/ui/assets/{irpf90-omMve0rd.js → irpf90-RCPdkB14.js} +1 -1
  182. package/dist/ui/assets/{isbl-C4xosfum.js → isbl-C2p75PPj.js} +1 -1
  183. package/dist/ui/assets/{ishikawaDiagram-FXEZZL3T-PtbNBMgh.js → ishikawaDiagram-FXEZZL3T-Cm6jsPlc.js} +1 -1
  184. package/dist/ui/assets/{java-CWjWDe7Q.js → java-DeY4Yuia.js} +1 -1
  185. package/dist/ui/assets/{javascript-C3dxrGuA.js → javascript-3uX1CO-H.js} +1 -1
  186. package/dist/ui/assets/{jboss-cli-CJE7m0Y-.js → jboss-cli-DgnD8mEc.js} +1 -1
  187. package/dist/ui/assets/{journeyDiagram-5HDEW3XC-DgK9V4yg.js → journeyDiagram-5HDEW3XC-DEGV1uA5.js} +1 -1
  188. package/dist/ui/assets/{json-DFUiNV7v.js → json-BV2PmJJp.js} +1 -1
  189. package/dist/ui/assets/{julia-CUTHpx8X.js → julia-B-m8kQm7.js} +1 -1
  190. package/dist/ui/assets/{julia-repl-_ZaQqdrz.js → julia-repl-C51atU2X.js} +1 -1
  191. package/dist/ui/assets/{kanban-definition-HUTT4EX6-BFrDfKdv.js → kanban-definition-HUTT4EX6-BJ4k5iTX.js} +1 -1
  192. package/dist/ui/assets/{kotlin-CrYjQYp8.js → kotlin-CYBziIgl.js} +1 -1
  193. package/dist/ui/assets/{lasso-CAiVg9m2.js → lasso-Dw2SBMDW.js} +1 -1
  194. package/dist/ui/assets/{latex-BkxnXIrT.js → latex-Dpd35yke.js} +1 -1
  195. package/dist/ui/assets/{ldif-CBOqxiN7.js → ldif-Ce9EZU__.js} +1 -1
  196. package/dist/ui/assets/{leaf-CbBZyOGH.js → leaf-CpkZzQtC.js} +1 -1
  197. package/dist/ui/assets/{less-Ca6uLPP0.js → less-Uzo7M0FD.js} +1 -1
  198. package/dist/ui/assets/{lisp-0Cm7_Bzv.js → lisp-DWXDlJYm.js} +1 -1
  199. package/dist/ui/assets/{livecodeserver-B7ka0vFT.js → livecodeserver-uEyPEgVJ.js} +1 -1
  200. package/dist/ui/assets/{livescript-CGmWmcLd.js → livescript-BQ5f07oK.js} +1 -1
  201. package/dist/ui/assets/{llvm-DCVMvkrH.js → llvm-BAvP-skE.js} +1 -1
  202. package/dist/ui/assets/{lsl-PVrTScpn.js → lsl-DhbiIKu6.js} +1 -1
  203. package/dist/ui/assets/{lua-BTo3z2Ux.js → lua-COxeUeLx.js} +1 -1
  204. package/dist/ui/assets/{makefile-DJGh9r9C.js → makefile-DhDx-IgL.js} +1 -1
  205. package/dist/ui/assets/{markdown-BOloL-q7.js → markdown-DX5_kSxq.js} +1 -1
  206. package/dist/ui/assets/{mathematica-CtMMQM2V.js → mathematica-D351ZddB.js} +1 -1
  207. package/dist/ui/assets/{matlab-Bfg_AWdR.js → matlab-CELqIiwF.js} +1 -1
  208. package/dist/ui/assets/{maxima-B2cdS7BY.js → maxima-B_YljrMm.js} +1 -1
  209. package/dist/ui/assets/{mel-BvfPvpYI.js → mel-DltsbNS8.js} +1 -1
  210. package/dist/ui/assets/{mercury-B6KgNIai.js → mercury-axX-5Vjj.js} +1 -1
  211. package/dist/ui/assets/{mindmap-definition-LN4V7U3C-BkeXo5If.js → mindmap-definition-LN4V7U3C-Bl1EJo6p.js} +1 -1
  212. package/dist/ui/assets/{mipsasm-Csras-cD.js → mipsasm-BxmerVwX.js} +1 -1
  213. package/dist/ui/assets/{mizar-C3WDI1-X.js → mizar-XNHfbpL2.js} +1 -1
  214. package/dist/ui/assets/{mojolicious-MnD2Whic.js → mojolicious-BR0U_7zk.js} +1 -1
  215. package/dist/ui/assets/{monkey-DLvUPYTI.js → monkey-lLuu9_f-.js} +1 -1
  216. package/dist/ui/assets/{moonscript-B0XEb3R3.js → moonscript-DoaZ3DRQ.js} +1 -1
  217. package/dist/ui/assets/{n1ql-BMRF54sY.js → n1ql-C6TId6Iu.js} +1 -1
  218. package/dist/ui/assets/{nginx-DqUyeHb8.js → nginx-BezSG-JT.js} +1 -1
  219. package/dist/ui/assets/{nim-3xwg8mOL.js → nim-Bb0rfXie.js} +1 -1
  220. package/dist/ui/assets/{nix-ByTkLdcH.js → nix-o3sJ5-54.js} +1 -1
  221. package/dist/ui/assets/{node-repl-sGSuIUFG.js → node-repl-Sv5hhcTf.js} +1 -1
  222. package/dist/ui/assets/{nsis-Dng5mFSM.js → nsis-B45BJFhF.js} +1 -1
  223. package/dist/ui/assets/{objectivec-DSQ8vb7n.js → objectivec-CzS6zVgh.js} +1 -1
  224. package/dist/ui/assets/{ocaml-BHOhEgRu.js → ocaml-Bqux7PyP.js} +1 -1
  225. package/dist/ui/assets/{openscad-DcUxQ-FQ.js → openscad-4Wf6mF84.js} +1 -1
  226. package/dist/ui/assets/{oxygene-DNlmqhsR.js → oxygene-Fvwqgkkt.js} +1 -1
  227. package/dist/ui/assets/{parser3-DIR98Q6n.js → parser3-zEfzT5wv.js} +1 -1
  228. package/dist/ui/assets/{pegDiagram-2B236MQR-BrXp_1_9.js → pegDiagram-2B236MQR-Dd4rIztM.js} +1 -1
  229. package/dist/ui/assets/{perl-16cY7fyu.js → perl-CsS1Gs6o.js} +1 -1
  230. package/dist/ui/assets/{pf-KrAq2BW7.js → pf-BNH1jO0R.js} +1 -1
  231. package/dist/ui/assets/{pgsql-BV1Z2bjp.js → pgsql-DqPigHrq.js} +1 -1
  232. package/dist/ui/assets/{php-FGjYSZqs.js → php-CdOl9bRs.js} +1 -1
  233. package/dist/ui/assets/{php-template-B1OW86WT.js → php-template-DPfirJg2.js} +1 -1
  234. package/dist/ui/assets/{pieDiagram-ENE6RG2P-Bh0bhWSa.js → pieDiagram-ENE6RG2P-DGaJNf4S.js} +1 -1
  235. package/dist/ui/assets/{plaintext-Cvn_UgSv.js → plaintext-EHbgBKzw.js} +1 -1
  236. package/dist/ui/assets/{pony-CRWnA3MR.js → pony-DmJajtp2.js} +1 -1
  237. package/dist/ui/assets/{powershell-Cwn155MZ.js → powershell-DfGzdWR6.js} +1 -1
  238. package/dist/ui/assets/{processing-BS6-1lrQ.js → processing-BT0ETgPG.js} +1 -1
  239. package/dist/ui/assets/{profile-C45OLQrv.js → profile-B3I-x5Lt.js} +1 -1
  240. package/dist/ui/assets/{prolog-C5YafSzY.js → prolog-B_4QJIvI.js} +1 -1
  241. package/dist/ui/assets/{properties-BULd-Zhg.js → properties-BFVI8weS.js} +1 -1
  242. package/dist/ui/assets/{protobuf-Qf1IuG5l.js → protobuf-PaF39oZZ.js} +1 -1
  243. package/dist/ui/assets/{puppet-93XdQvnn.js → puppet-BDC6Q8VF.js} +1 -1
  244. package/dist/ui/assets/{purebasic-DlYNScQP.js → purebasic-B2ejrOZK.js} +1 -1
  245. package/dist/ui/assets/{python-D-Do6-F0.js → python-BOxtIk9H.js} +1 -1
  246. package/dist/ui/assets/{python-repl-DGutP04w.js → python-repl-BslBh_Mx.js} +1 -1
  247. package/dist/ui/assets/{q-lmgfrySy.js → q-BPe8WLGW.js} +1 -1
  248. package/dist/ui/assets/{qml-BbjX_mSU.js → qml-BazRR6fz.js} +1 -1
  249. package/dist/ui/assets/{quadrantDiagram-ABIIQ3AL-B891FOO8.js → quadrantDiagram-ABIIQ3AL-BQ7aPkHk.js} +1 -1
  250. package/dist/ui/assets/{r--x8NzO9N.js → r-C09pGNJC.js} +1 -1
  251. package/dist/ui/assets/{railroadDiagram-RFXS5EU6-R3O-GKNe.js → railroadDiagram-RFXS5EU6-sCO9VGvE.js} +1 -1
  252. package/dist/ui/assets/{reasonml-DwHsAflh.js → reasonml-S7dzwVL9.js} +1 -1
  253. package/dist/ui/assets/{requirementDiagram-TGXJPOKE-D4l_xEXt.js → requirementDiagram-TGXJPOKE-CfT5aVZg.js} +1 -1
  254. package/dist/ui/assets/{rib-DMJNtDwV.js → rib-fM2EwQd4.js} +1 -1
  255. package/dist/ui/assets/{roboconf-BNNGTvHr.js → roboconf-D7AaeyrW.js} +1 -1
  256. package/dist/ui/assets/{routeros-BF7SVruD.js → routeros-c6Q7mKuq.js} +1 -1
  257. package/dist/ui/assets/{rsl-1EHeIZqp.js → rsl-sCpEQBxh.js} +1 -1
  258. package/dist/ui/assets/{ruby-B-v_BYYp.js → ruby-lcKhz2w9.js} +1 -1
  259. package/dist/ui/assets/{ruleslanguage-GFeEMSdK.js → ruleslanguage-BW4ATOuX.js} +1 -1
  260. package/dist/ui/assets/{rust-ApqGtMhh.js → rust-BbpU-0VY.js} +1 -1
  261. package/dist/ui/assets/{sankeyDiagram-HTMAVEWB-Dc-2lhBq.js → sankeyDiagram-HTMAVEWB-CaweCpvN.js} +1 -1
  262. package/dist/ui/assets/{sas-YkxX6N9_.js → sas-BPt5R0dx.js} +1 -1
  263. package/dist/ui/assets/{scala-BpHi86GZ.js → scala-DxW_vqXs.js} +1 -1
  264. package/dist/ui/assets/{scheme-D889qY8Y.js → scheme-T2Q_jWzT.js} +1 -1
  265. package/dist/ui/assets/{scilab-C3l-bcRx.js → scilab-DMORg9lV.js} +1 -1
  266. package/dist/ui/assets/{scss-D0iGASxm.js → scss-t0VsosqT.js} +1 -1
  267. package/dist/ui/assets/{sequenceDiagram-DBY2YBRQ-DvppgciC.js → sequenceDiagram-DBY2YBRQ-o-H_R4zb.js} +1 -1
  268. package/dist/ui/assets/{shell-PUnaEPCO.js → shell-CnCDa1s9.js} +1 -1
  269. package/dist/ui/assets/{sizeCapture-X5ZJPWSS-DhvIbxXs.js → sizeCapture-X5ZJPWSS-BNLkHGDS.js} +1 -1
  270. package/dist/ui/assets/{smali-Du_dF9hl.js → smali-_n-BxJyG.js} +1 -1
  271. package/dist/ui/assets/{smalltalk-CSr2Gc1v.js → smalltalk-B90PXJwK.js} +1 -1
  272. package/dist/ui/assets/{sml-D3zkvzP2.js → sml-fuY7bj-n.js} +1 -1
  273. package/dist/ui/assets/{sqf-BZQ34qEZ.js → sqf-COpwkyuo.js} +1 -1
  274. package/dist/ui/assets/{sql-BFKScMsf.js → sql-CXIT0j-x.js} +1 -1
  275. package/dist/ui/assets/{sql_more-C2Lc_Qqq.js → sql_more-C1Oxq4rx.js} +1 -1
  276. package/dist/ui/assets/{stan-CzY8VdxU.js → stan-BZEpaHeC.js} +1 -1
  277. package/dist/ui/assets/{stata-9GxyhPpV.js → stata-CkBwaiZM.js} +1 -1
  278. package/dist/ui/assets/{stateDiagram-2N3HPSRC-CM63y6f0.js → stateDiagram-2N3HPSRC-BkdnNF7I.js} +1 -1
  279. package/dist/ui/assets/stateDiagram-v2-6OUMAXLB-0JnZ1VSQ.js +1 -0
  280. package/dist/ui/assets/{step21-BpK_Zw3v.js → step21-fs9N_U3O.js} +1 -1
  281. package/dist/ui/assets/{stylus-DQ4k28M4.js → stylus-Bs_9cvKZ.js} +1 -1
  282. package/dist/ui/assets/{subunit-C6ciOPNF.js → subunit-DvgcOCqJ.js} +1 -1
  283. package/dist/ui/assets/{swift-CJfqqSbT.js → swift-BE4ONsur.js} +1 -1
  284. package/dist/ui/assets/{swimlanes-5IMT3BWC-DS6_HNF7.js → swimlanes-5IMT3BWC-uqTAc7o7.js} +2 -2
  285. package/dist/ui/assets/swimlanesDiagram-G3AALYLV-DQRIIEmi.js +8 -0
  286. package/dist/ui/assets/{taggerscript-VouMmJ_v.js → taggerscript-BhmPJ64C.js} +1 -1
  287. package/dist/ui/assets/{tap-wXCy18ot.js → tap-DkueIVKV.js} +1 -1
  288. package/dist/ui/assets/{tcl-ewDOmCFX.js → tcl-DyXOOkFi.js} +1 -1
  289. package/dist/ui/assets/{thrift-BfFA03rE.js → thrift-Dhgbk56T.js} +1 -1
  290. package/dist/ui/assets/{timeline-definition-FHXFAJF6-Dz2m6S6x.js → timeline-definition-FHXFAJF6-DBAk9Ouc.js} +1 -1
  291. package/dist/ui/assets/{tp-HGBcpNf9.js → tp-BsXyrRGH.js} +1 -1
  292. package/dist/ui/assets/{twig-nrQZ0pw8.js → twig-J0HqIuHw.js} +1 -1
  293. package/dist/ui/assets/{typescript-B7tNYFEQ.js → typescript-Dkwvul39.js} +1 -1
  294. package/dist/ui/assets/{vala-BIjQtoo6.js → vala-CRGnf8aY.js} +1 -1
  295. package/dist/ui/assets/{vbnet-Bbspccm6.js → vbnet-BtJAUe3z.js} +1 -1
  296. package/dist/ui/assets/{vbscript-C45_QgOy.js → vbscript-RgFFNuM3.js} +1 -1
  297. package/dist/ui/assets/{vbscript-html-DlF2QBc7.js → vbscript-html-DO32Io9Y.js} +1 -1
  298. package/dist/ui/assets/{vennDiagram-L72KCM5P-BPEphYtX.js → vennDiagram-L72KCM5P-BJi6y0hh.js} +1 -1
  299. package/dist/ui/assets/{verilog-BSitd8W0.js → verilog-C4h6MLcI.js} +1 -1
  300. package/dist/ui/assets/{vhdl-C1bbeiC4.js → vhdl-DOafePyU.js} +1 -1
  301. package/dist/ui/assets/{vim-DchwbT8X.js → vim-BAdTA9TY.js} +1 -1
  302. package/dist/ui/assets/{wardleyDiagram-EHGQE667-BttTCoBT.js → wardleyDiagram-EHGQE667-C7c_4IJ6.js} +1 -1
  303. package/dist/ui/assets/{x86asm-vARxMUvn.js → x86asm-BCL6__QH.js} +1 -1
  304. package/dist/ui/assets/{xl-dx63vvXo.js → xl-qIzE4HOe.js} +1 -1
  305. package/dist/ui/assets/{xml-BUnj27wL.js → xml-DE2sJXYU.js} +1 -1
  306. package/dist/ui/assets/{xquery-T7gpnf0e.js → xquery-CQ35t92y.js} +1 -1
  307. package/dist/ui/assets/{xychartDiagram-FW5EYKEG-BfrNhdrG.js → xychartDiagram-FW5EYKEG-D2ILn0jL.js} +1 -1
  308. package/dist/ui/assets/{yaml-xRgQKzeL.js → yaml-5KaAvG5C.js} +1 -1
  309. package/dist/ui/assets/{zephir-Yu6l5qJj.js → zephir-CbR3Ryfq.js} +1 -1
  310. package/dist/ui/index.html +2 -2
  311. package/dist/utils/__tests__/abort-signals.test.js +67 -0
  312. package/dist/utils/__tests__/inject-loop.test.js +1 -53
  313. package/dist/utils/__tests__/learn-tasks-db.test.js +82 -0
  314. package/dist/utils/__tests__/openai-converter.test.js +25 -0
  315. package/dist/utils/__tests__/pi-crawl-tools.test.js +15 -4
  316. package/dist/utils/__tests__/pi-dedup-reconcile.test.js +11 -9
  317. package/dist/utils/__tests__/pi-events.test.js +172 -0
  318. package/dist/utils/__tests__/pi-learn-orchestrator.test.js +216 -6
  319. package/dist/utils/__tests__/pi-runtime-json.test.js +38 -3
  320. package/dist/utils/__tests__/providers-db.test.js +40 -2
  321. package/dist/utils/__tests__/request-writer.test.js +271 -39
  322. package/dist/utils/__tests__/sse-protocol.test.d.ts +1 -0
  323. package/dist/utils/__tests__/sse-protocol.test.js +115 -0
  324. package/dist/utils/__tests__/vault.test.d.ts +1 -0
  325. package/dist/utils/__tests__/{knowledge-store.test.js → vault.test.js} +16 -16
  326. package/dist/utils/abort-signals.d.ts +13 -0
  327. package/dist/utils/abort-signals.js +33 -0
  328. package/dist/utils/db.d.ts +2 -0
  329. package/dist/utils/db.js +42 -0
  330. package/dist/utils/esm-dirname.d.ts +0 -15
  331. package/dist/utils/esm-dirname.js +0 -4
  332. package/dist/utils/inject-loop.d.ts +0 -27
  333. package/dist/utils/inject-loop.js +2 -56
  334. package/dist/utils/learn-tasks-db.d.ts +15 -0
  335. package/dist/utils/learn-tasks-db.js +35 -0
  336. package/dist/utils/openai-converter.js +88 -78
  337. package/dist/utils/pi-browser-tools.d.ts +0 -2
  338. package/dist/utils/pi-browser-tools.js +0 -174
  339. package/dist/utils/pi-crawl-tools.d.ts +2 -1
  340. package/dist/utils/pi-crawl-tools.js +16 -11
  341. package/dist/utils/pi-dedup.d.ts +8 -30
  342. package/dist/utils/pi-dedup.js +32 -67
  343. package/dist/utils/pi-events.d.ts +65 -0
  344. package/dist/utils/pi-events.js +98 -0
  345. package/dist/utils/pi-learn-orchestrator.d.ts +6 -5
  346. package/dist/utils/pi-learn-orchestrator.js +71 -106
  347. package/dist/utils/pi-runtime.d.ts +5 -6
  348. package/dist/utils/pi-runtime.js +38 -42
  349. package/dist/utils/pi-sandbox-ops.d.ts +0 -36
  350. package/dist/utils/pi-sandbox-ops.js +5 -190
  351. package/dist/utils/providers-db.d.ts +3 -0
  352. package/dist/utils/providers-db.js +21 -7
  353. package/dist/utils/request-writer.d.ts +60 -30
  354. package/dist/utils/request-writer.js +182 -61
  355. package/dist/utils/sse-protocol.d.ts +34 -0
  356. package/dist/utils/sse-protocol.js +121 -0
  357. package/dist/utils/sse-stream-processor.d.ts +4 -9
  358. package/dist/utils/sse-stream-processor.js +13 -104
  359. package/dist/utils/sse-writer.d.ts +1 -1
  360. package/dist/utils/sse-writer.js +3 -2
  361. package/dist/utils/stats-aggregator.js +3 -0
  362. package/dist/utils/tool-injector.js +7 -0
  363. package/dist/utils/vault.d.ts +111 -0
  364. package/dist/utils/vault.js +434 -0
  365. package/package.json +1 -1
  366. package/dist/docs/assets/chunks/@localSearchIndexroot.BN6hB8Jr.js +0 -1
  367. package/dist/types/api.d.ts +0 -20
  368. package/dist/types/index.d.ts +0 -4
  369. package/dist/types/index.js +0 -4
  370. package/dist/types/log.d.ts +0 -13
  371. package/dist/ui/assets/channel-BgAIihW-.js +0 -1
  372. package/dist/ui/assets/classDiagram-OUVF2IWQ-0fsnUoNI.js +0 -1
  373. package/dist/ui/assets/classDiagram-v2-EOCWNBFH-0fsnUoNI.js +0 -1
  374. package/dist/ui/assets/index-C0fxlU9d.css +0 -10
  375. package/dist/ui/assets/stateDiagram-v2-6OUMAXLB-OA9dcuA9.js +0 -1
  376. package/dist/ui/assets/swimlanesDiagram-G3AALYLV-BLEnJU_R.js +0 -8
  377. package/dist/utils/__tests__/sse-accumulator.test.js +0 -83
  378. package/dist/utils/knowledge-store.d.ts +0 -44
  379. package/dist/utils/knowledge-store.js +0 -193
  380. package/dist/utils/migrate-files-to-db.d.ts +0 -1
  381. package/dist/utils/migrate-files-to-db.js +0 -138
  382. package/dist/utils/sse-accumulator.d.ts +0 -9
  383. package/dist/utils/sse-accumulator.js +0 -59
  384. /package/dist/docs/assets/{proxy-cli_data-hooks.md.w9Oe1OD3.lean.js → proxy-cli_data-hooks.md.Bz8CVbxO.lean.js} +0 -0
  385. /package/dist/docs/assets/{proxy-core_ui-routes.md.Dyqkeoiv.lean.js → proxy-core_ui-routes.md.B21t1p7R.lean.js} +0 -0
  386. /package/dist/{types/api.js → utils/__tests__/abort-signals.test.d.ts} +0 -0
  387. /package/dist/{types/log.js → utils/__tests__/learn-tasks-db.test.d.ts} +0 -0
  388. /package/dist/utils/__tests__/{knowledge-store.test.d.ts → openai-converter.test.d.ts} +0 -0
  389. /package/dist/utils/__tests__/{sse-accumulator.test.d.ts → pi-events.test.d.ts} +0 -0
@@ -19,6 +19,7 @@ export function aggregateStats() {
19
19
  COUNT(*) as request_count
20
20
  FROM requests
21
21
  WHERE timestamp >= ?
22
+ AND closed_at IS NULL
22
23
  GROUP BY hour
23
24
  `).all(hourlyCutoff);
24
25
  // Upsert hourly stats
@@ -90,12 +91,14 @@ export function getTodayStats(since) {
90
91
  COUNT(*) as request_count
91
92
  FROM requests
92
93
  WHERE timestamp >= ?
94
+ AND closed_at IS NULL
93
95
  `).get(since);
94
96
  // Per-model usage count since local midnight
95
97
  const modelRows = db.prepare(`
96
98
  SELECT model, COUNT(*) as count
97
99
  FROM requests
98
100
  WHERE timestamp >= ?
101
+ AND closed_at IS NULL
99
102
  AND model IS NOT NULL AND model != ''
100
103
  GROUP BY model
101
104
  ORDER BY count DESC
@@ -10,6 +10,13 @@ import { mcpManager } from './mcp-manager.js';
10
10
  * 无 tools 数组时自动创建,让裸请求也能使用 MCP tool。
11
11
  */
12
12
  export function injectMcpTools(body) {
13
+ // 守卫:malformed body 直接返回,避免给原始值赋值抛 TypeError。
14
+ // 判定依据:有效 chat body 至少要有 messages 数组;null/非对象,或既无 tools 也无 messages(如 {}、{tools:'nope'})均不注入。
15
+ if (body === null ||
16
+ typeof body !== 'object' ||
17
+ (!Array.isArray(body?.tools) && !Array.isArray(body?.messages))) {
18
+ return [];
19
+ }
13
20
  if (!Array.isArray(body?.tools)) {
14
21
  body.tools = [];
15
22
  }
@@ -0,0 +1,111 @@
1
+ export declare function isValidSlug(slug: string): boolean;
2
+ export interface TopicSummary {
3
+ slug: string;
4
+ title: string;
5
+ summary: string;
6
+ tags: string[];
7
+ }
8
+ export interface ChunkRef {
9
+ id: string;
10
+ title: string;
11
+ summary: string;
12
+ tags: string[];
13
+ }
14
+ export interface TopicIndex {
15
+ slug: string;
16
+ title: string;
17
+ summary: string;
18
+ tags: string[];
19
+ chunks: ChunkRef[];
20
+ }
21
+ interface TopicDetail {
22
+ title: string;
23
+ tags: string[];
24
+ sources: unknown[];
25
+ chunks: ChunkRef[];
26
+ }
27
+ interface ChunkHit {
28
+ topic: string;
29
+ chunkId: string;
30
+ title: string;
31
+ }
32
+ interface QueryHit {
33
+ topic: string;
34
+ chunkId: string;
35
+ title: string;
36
+ body: string;
37
+ }
38
+ export interface OutlineItem {
39
+ id: string;
40
+ title: string;
41
+ oneLine: string;
42
+ }
43
+ interface RootIndex {
44
+ topics: TopicSummary[];
45
+ }
46
+ export interface Vault {
47
+ /** vault 根目录(docsDir)绝对路径 */
48
+ readonly root: string;
49
+ listTopics(): Promise<TopicSummary[]>;
50
+ getTopic(topic: string): Promise<TopicDetail>;
51
+ searchChunks(query: string): Promise<ChunkHit[]>;
52
+ queryKnowledge(query: string, limit?: number): Promise<QueryHit[]>;
53
+ readChunk(topic: string, chunkId: string): Promise<string>;
54
+ upsertTopic(input: {
55
+ slug: string;
56
+ title: string;
57
+ summary: string;
58
+ tags: string[];
59
+ }): Promise<void>;
60
+ upsertChunkRef(input: {
61
+ topic: string;
62
+ chunkId: string;
63
+ title: string;
64
+ summary: string;
65
+ tags: string[];
66
+ }): Promise<void>;
67
+ readTopicIndex(slug: string): Promise<TopicIndex | null>;
68
+ readSidecarIndex(slug: string): Promise<TopicIndex | null>;
69
+ assertSlug(slug: string, field?: string): void;
70
+ /** 重建 topic 目录:rm -rf 后建 sources/ + chunks/ */
71
+ prepareTopic(slug: string): void;
72
+ /** 写 <slug>/sources/source-NNN.md(content 带 Source 头) */
73
+ writeSourceFile(slug: string, index: number, url: string, text: string): void;
74
+ /** 数 <slug>/sources 下 .md 文件;目录不存在按 0 */
75
+ countSourceFiles(slug: string): number;
76
+ /** 读 <slug>/sources 下全部 .md 正文(按文件名排序);目录缺失抛底层错误 */
77
+ readSourceBodies(slug: string): string[];
78
+ /** 写 <slug>/outline.json(校验目录已 prepare、sources 存在) */
79
+ writeOutline(slug: string, items: OutlineItem[]): void;
80
+ /** 读 <slug>/outline.json 的 items;文件不存在抛「outline 未生成」 */
81
+ readOutlineItems(slug: string): OutlineItem[];
82
+ /** 旁挂:<slug> → <slug>.old */
83
+ parkTopic(slug: string): void;
84
+ /** 还原:<slug>.old → <slug> */
85
+ restoreTopic(slug: string): void;
86
+ /** 重命名 topic 目录:<slug> → <newSlug> */
87
+ renameTopic(slug: string, newSlug: string): void;
88
+ /** 读 <entry>/index.json(entry 可为 slug 或 <slug>.old);缺失/坏抛底层错误 */
89
+ readEntryIndexSync(entry: string): TopicIndex;
90
+ /** 写 <entry>/index.json */
91
+ writeEntryIndexSync(entry: string, idx: TopicIndex): void;
92
+ readRootIndexSync(): RootIndex;
93
+ writeRootIndexSync(root: RootIndex): void;
94
+ /** 列 <entry>/<subdir> 下 .md 文件名(排序);目录缺失视为空 */
95
+ listEntryMd(entry: string, subdir: 'sources' | 'chunks'): string[];
96
+ mkdirEntrySubdir(entry: string, subdir: 'sources' | 'chunks'): void;
97
+ readEntryFile(entry: string, subdir: 'sources' | 'chunks', file: string): Buffer;
98
+ writeEntryFile(entry: string, subdir: 'sources' | 'chunks', file: string, body: Buffer): void;
99
+ unlinkEntryFile(entry: string, subdir: 'sources' | 'chunks', file: string): void;
100
+ /** 删除整个 <entry> 目录 */
101
+ removeEntry(entry: string): void;
102
+ /** docsDir 下存在任何 .old 旁挂目录时抛错 */
103
+ assertNoOldSidecars(): void;
104
+ /** 归一化路径并断言其在 docsDir 内,越界抛错 */
105
+ assertInside(absPath: string): string;
106
+ /** 目标为受管 index.json 时抛错 */
107
+ assertNotManagedIndexJson(absPath: string): void;
108
+ }
109
+ export declare function createVault(docsDir: string): Vault;
110
+ export declare const vault: Vault;
111
+ export {};
@@ -0,0 +1,434 @@
1
+ // vault:learn 文件型知识库(~/.cc-monitoring/docs)的深 module。
2
+ // 物理布局:
3
+ // - index.json 根索引 {"topics":[TopicSummary]}
4
+ // - <slug>/index.json 主题索引 TopicIndex(元数据 + chunks 引用)
5
+ // - <slug>/outline.json、<slug>/sources/source-NNN.md、<slug>/chunks/chunk-NNN.md
6
+ // - <slug>.old/ 旁挂备份
7
+ // 所有路径解析、slug/chunk-id 校验、物理读写均以本 module 为唯一权威。
8
+ import { promises as fs } from 'node:fs';
9
+ import fsSync from 'node:fs';
10
+ import path from 'node:path';
11
+ import { dataDir } from './paths.js';
12
+ // 合法 slug:小写字母数字开头,仅含小写字母数字与连字符
13
+ const SLUG_RE = /^[a-z0-9][a-z0-9-]*$/;
14
+ const CHUNK_RE = /^chunk-\d{3}$/;
15
+ export function isValidSlug(slug) {
16
+ return SLUG_RE.test(slug);
17
+ }
18
+ export function createVault(docsDir) {
19
+ // ---- 路径解析(单一权威)----
20
+ const rootIndexPath = () => path.join(docsDir, 'index.json');
21
+ const entryDir = (entry) => path.join(docsDir, entry);
22
+ const entryIndexPath = (entry) => path.join(docsDir, entry, 'index.json');
23
+ const entrySubdir = (entry, subdir) => path.join(docsDir, entry, subdir);
24
+ function assertTopic(topic) {
25
+ if (!SLUG_RE.test(topic)) {
26
+ throw new Error(`invalid topic slug: ${topic}`);
27
+ }
28
+ }
29
+ function assertChunkId(chunkId) {
30
+ if (!CHUNK_RE.test(chunkId)) {
31
+ throw new Error(`invalid chunk id: ${chunkId} (expect chunk-NNN)`);
32
+ }
33
+ }
34
+ /** 从 chunk 正文首行 `# xxx` 提取 title(用于 searchChunks) */
35
+ function parseChunkTitle(text) {
36
+ const m = text.match(/^#\s+(.+?)\s*$/m);
37
+ return m ? m[1].trim() : '';
38
+ }
39
+ /** 读 JSON 文件,不存在或解析失败时返回 fallback */
40
+ async function readJsonOr(file, fallback) {
41
+ try {
42
+ const text = await fs.readFile(file, 'utf8');
43
+ return JSON.parse(text);
44
+ }
45
+ catch {
46
+ return fallback;
47
+ }
48
+ }
49
+ // ============================================================
50
+ // 读 / 查(原 knowledge-store,逐字保持)
51
+ // ============================================================
52
+ async function listTopics() {
53
+ const parsed = await readJsonOr(rootIndexPath(), { topics: [] });
54
+ return Array.isArray(parsed.topics) ? parsed.topics : [];
55
+ }
56
+ async function getTopic(topic) {
57
+ assertTopic(topic);
58
+ const indexPath = entryIndexPath(topic);
59
+ let meta;
60
+ try {
61
+ const text = await fs.readFile(indexPath, 'utf8');
62
+ meta = JSON.parse(text);
63
+ }
64
+ catch (e) {
65
+ if (e && e.code === 'ENOENT') {
66
+ throw new Error(`topic not found: ${topic}`);
67
+ }
68
+ throw new Error(`topic index corrupt: ${topic}, fix or delete ${topic}/index.json`);
69
+ }
70
+ return {
71
+ title: meta.title || topic,
72
+ tags: Array.isArray(meta.tags) ? meta.tags : [],
73
+ sources: [],
74
+ chunks: Array.isArray(meta.chunks)
75
+ ? meta.chunks.map(c => ({
76
+ id: c.id,
77
+ title: c.title,
78
+ summary: c.summary,
79
+ tags: Array.isArray(c.tags) ? c.tags : [],
80
+ }))
81
+ : [],
82
+ };
83
+ }
84
+ async function upsertTopic(input) {
85
+ assertTopic(input.slug);
86
+ const { slug, title, summary, tags } = input;
87
+ // 1. 更新根 index.json
88
+ const rootPath = rootIndexPath();
89
+ const rootIdx = await readJsonOr(rootPath, { topics: [] });
90
+ if (!Array.isArray(rootIdx.topics))
91
+ rootIdx.topics = [];
92
+ const existingRoot = rootIdx.topics.find(t => t.slug === slug);
93
+ if (existingRoot) {
94
+ existingRoot.title = title;
95
+ existingRoot.summary = summary;
96
+ existingRoot.tags = tags;
97
+ }
98
+ else {
99
+ rootIdx.topics.push({ slug, title, summary, tags });
100
+ }
101
+ await fs.writeFile(rootPath, JSON.stringify(rootIdx, null, 2), 'utf8');
102
+ // 2. 更新主题 index.json(不动 chunks 数组)
103
+ const topicDir = entryDir(slug);
104
+ const topicPath = entryIndexPath(slug);
105
+ const topicIdx = await readJsonOr(topicPath, { slug, title, summary, tags, chunks: [] });
106
+ topicIdx.slug = slug;
107
+ topicIdx.title = title;
108
+ topicIdx.summary = summary;
109
+ topicIdx.tags = tags;
110
+ if (!Array.isArray(topicIdx.chunks))
111
+ topicIdx.chunks = [];
112
+ await fs.mkdir(topicDir, { recursive: true });
113
+ await fs.writeFile(topicPath, JSON.stringify(topicIdx, null, 2), 'utf8');
114
+ }
115
+ async function upsertChunkRef(input) {
116
+ assertTopic(input.topic);
117
+ assertChunkId(input.chunkId);
118
+ const { topic, chunkId, title, summary, tags } = input;
119
+ const topicPath = entryIndexPath(topic);
120
+ let topicIdx;
121
+ try {
122
+ const text = await fs.readFile(topicPath, 'utf8');
123
+ topicIdx = JSON.parse(text);
124
+ }
125
+ catch (e) {
126
+ if (e && e.code === 'ENOENT') {
127
+ throw new Error(`topic not found: ${topic}, call add_topic first`);
128
+ }
129
+ throw e;
130
+ }
131
+ if (!Array.isArray(topicIdx.chunks))
132
+ topicIdx.chunks = [];
133
+ const existing = topicIdx.chunks.find(c => c.id === chunkId);
134
+ if (existing) {
135
+ existing.title = title;
136
+ existing.summary = summary;
137
+ existing.tags = tags;
138
+ }
139
+ else {
140
+ topicIdx.chunks.push({ id: chunkId, title, summary, tags });
141
+ }
142
+ await fs.writeFile(topicPath, JSON.stringify(topicIdx, null, 2), 'utf8');
143
+ }
144
+ /** 匹配词集合:整体 query + whitespace 分割的长度 >1 的 token,去重 */
145
+ function buildTerms(query) {
146
+ const q = query.toLowerCase();
147
+ const terms = new Set([q]);
148
+ for (const tok of q.split(/\s+/)) {
149
+ if (tok.length > 1)
150
+ terms.add(tok);
151
+ }
152
+ return [...terms];
153
+ }
154
+ /** 扫描所有 topic/chunk,返回打分候选(searchChunks / queryKnowledge 共用) */
155
+ async function scanChunks(query) {
156
+ const q = query.toLowerCase();
157
+ if (!q.trim())
158
+ return [];
159
+ const terms = buildTerms(query);
160
+ const candidates = [];
161
+ // topic index 本函数作用域缓存,避免每个 chunk 重复读
162
+ const topicIndexCache = new Map();
163
+ let entries;
164
+ try {
165
+ entries = await fs.readdir(docsDir);
166
+ }
167
+ catch {
168
+ return [];
169
+ }
170
+ for (const topic of entries) {
171
+ if (!SLUG_RE.test(topic))
172
+ continue;
173
+ if (!topicIndexCache.has(topic)) {
174
+ const idx = await readJsonOr(entryIndexPath(topic), null);
175
+ topicIndexCache.set(topic, idx);
176
+ }
177
+ const topicIdx = topicIndexCache.get(topic) ?? null;
178
+ const topicTags = topicIdx && Array.isArray(topicIdx.tags) ? topicIdx.tags : [];
179
+ const chunkRefs = topicIdx && Array.isArray(topicIdx.chunks) ? topicIdx.chunks : [];
180
+ const topicTagHit = (term) => topicTags.some(t => t.toLowerCase().includes(term));
181
+ const chunksDir = entrySubdir(topic, 'chunks');
182
+ let files;
183
+ try {
184
+ files = await fs.readdir(chunksDir);
185
+ }
186
+ catch {
187
+ continue;
188
+ }
189
+ for (const file of files) {
190
+ const chunkId = file.replace(/\.md$/, '');
191
+ if (!CHUNK_RE.test(chunkId))
192
+ continue;
193
+ const text = await fs.readFile(path.join(chunksDir, file), 'utf8');
194
+ const textLc = text.toLowerCase();
195
+ const ref = chunkRefs.find(c => c.id === chunkId);
196
+ const refTitle = (ref?.title ?? '').toLowerCase();
197
+ const refSummary = (ref?.summary ?? '').toLowerCase();
198
+ const refTags = ref && Array.isArray(ref.tags) ? ref.tags : [];
199
+ let score = 0;
200
+ for (const term of terms) {
201
+ // 每个字段每词只计一次分,body 不按出现次数刷分
202
+ if (refTitle.includes(term))
203
+ score += 3;
204
+ if (refTags.some(t => t.toLowerCase().includes(term)))
205
+ score += 2;
206
+ if (topicTagHit(term))
207
+ score += 2;
208
+ if (refSummary.includes(term))
209
+ score += 1;
210
+ if (textLc.includes(term))
211
+ score += 1;
212
+ }
213
+ if (score === 0)
214
+ continue;
215
+ const wholeQueryHit = textLc.includes(q) ||
216
+ refTitle.includes(q) ||
217
+ refSummary.includes(q) ||
218
+ topicTagHit(q) ||
219
+ refTags.some(t => t.toLowerCase().includes(q));
220
+ candidates.push({ topic, chunkId, title: parseChunkTitle(text), score, wholeQueryHit });
221
+ }
222
+ }
223
+ return candidates;
224
+ }
225
+ async function searchChunks(query) {
226
+ if (!query.trim())
227
+ return [];
228
+ return (await scanChunks(query))
229
+ .filter(c => c.wholeQueryHit)
230
+ .map(({ topic, chunkId, title }) => ({ topic, chunkId, title }));
231
+ }
232
+ async function queryKnowledge(query, limit = 3) {
233
+ const capped = Math.min(Math.max(limit, 1), 5);
234
+ const candidates = (await scanChunks(query))
235
+ .sort((a, b) => b.score - a.score)
236
+ .slice(0, capped);
237
+ const hits = [];
238
+ for (const c of candidates) {
239
+ const body = await readChunk(c.topic, c.chunkId);
240
+ hits.push({ topic: c.topic, chunkId: c.chunkId, title: c.title, body });
241
+ }
242
+ return hits;
243
+ }
244
+ async function readChunk(topic, chunkId) {
245
+ assertTopic(topic);
246
+ assertChunkId(chunkId);
247
+ const filePath = path.join(entrySubdir(topic, 'chunks'), `${chunkId}.md`);
248
+ // 二次校验:解析后路径必须在 root/<topic>/chunks/ 内
249
+ const resolved = path.resolve(filePath);
250
+ const expectedDir = path.resolve(docsDir, topic, 'chunks');
251
+ if (!resolved.startsWith(expectedDir + path.sep)) {
252
+ throw new Error('access denied: chunk path escapes chunks dir');
253
+ }
254
+ return fs.readFile(resolved, 'utf8');
255
+ }
256
+ // ============================================================
257
+ // 主题索引(async;缺失/坏 → null)
258
+ // ============================================================
259
+ async function readTopicIndex(slug) {
260
+ try {
261
+ const raw = await fs.readFile(entryIndexPath(slug), 'utf8');
262
+ return JSON.parse(raw);
263
+ }
264
+ catch {
265
+ return null;
266
+ }
267
+ }
268
+ async function readSidecarIndex(slug) {
269
+ try {
270
+ const raw = await fs.readFile(entryIndexPath(`${slug}.old`), 'utf8');
271
+ return JSON.parse(raw);
272
+ }
273
+ catch {
274
+ return null;
275
+ }
276
+ }
277
+ // ============================================================
278
+ // 物理操作(sync)
279
+ // ============================================================
280
+ function assertSlug(slug, field = 'slug') {
281
+ if (!SLUG_RE.test(slug)) {
282
+ throw new Error(`invalid ${field}: ${slug}`);
283
+ }
284
+ }
285
+ /** 重建 topic 目录:sources/(抓取/上传原料)+ chunks/(后续产物) */
286
+ function prepareTopic(slug) {
287
+ const dir = entryDir(slug);
288
+ fsSync.rmSync(dir, { recursive: true, force: true });
289
+ fsSync.mkdirSync(path.join(dir, 'sources'), { recursive: true });
290
+ fsSync.mkdirSync(path.join(dir, 'chunks'), { recursive: true });
291
+ }
292
+ /** 写一份原料到 <slug>/sources/source-NNN.md */
293
+ function writeSourceFile(slug, index, url, text) {
294
+ const dir = entrySubdir(slug, 'sources');
295
+ fsSync.mkdirSync(dir, { recursive: true });
296
+ const name = `source-${String(index + 1).padStart(3, '0')}.md`;
297
+ fsSync.writeFileSync(path.join(dir, name), `Source: ${url}\n\n${text}`, 'utf8');
298
+ }
299
+ /** 数 <slug>/sources 下 .md 文件数量;目录不存在按 0 */
300
+ function countSourceFiles(slug) {
301
+ try {
302
+ return fsSync.readdirSync(entrySubdir(slug, 'sources')).filter((f) => f.endsWith('.md')).length;
303
+ }
304
+ catch {
305
+ return 0;
306
+ }
307
+ }
308
+ function readSourceBodies(slug) {
309
+ const dir = entrySubdir(slug, 'sources');
310
+ const files = fsSync.readdirSync(dir).filter((f) => f.endsWith('.md')).sort();
311
+ return files.map((f) => fsSync.readFileSync(path.join(dir, f), 'utf8'));
312
+ }
313
+ function writeOutline(slug, items) {
314
+ assertSlug(slug, 'slug');
315
+ const topicDir = entryDir(slug);
316
+ if (!fsSync.existsSync(topicDir))
317
+ throw new Error(`topic dir not prepared: ${slug}`);
318
+ if (!fsSync.existsSync(path.join(topicDir, 'sources')))
319
+ throw new Error(`sources missing for topic: ${slug}`);
320
+ fsSync.writeFileSync(path.join(topicDir, 'outline.json'), JSON.stringify({ slug, source: 'sources/', items }, null, 2));
321
+ }
322
+ function readOutlineItems(slug) {
323
+ const outlinePath = path.join(entryDir(slug), 'outline.json');
324
+ if (!fsSync.existsSync(outlinePath))
325
+ throw new Error('outline 未生成');
326
+ const outline = JSON.parse(fsSync.readFileSync(outlinePath, 'utf8'));
327
+ return outline.items;
328
+ }
329
+ function parkTopic(slug) {
330
+ fsSync.renameSync(entryDir(slug), entryDir(`${slug}.old`));
331
+ }
332
+ function restoreTopic(slug) {
333
+ fsSync.renameSync(entryDir(`${slug}.old`), entryDir(slug));
334
+ }
335
+ function renameTopic(slug, newSlug) {
336
+ fsSync.renameSync(entryDir(slug), entryDir(newSlug));
337
+ }
338
+ function readEntryIndexSync(entry) {
339
+ return JSON.parse(fsSync.readFileSync(entryIndexPath(entry), 'utf8'));
340
+ }
341
+ function writeEntryIndexSync(entry, idx) {
342
+ fsSync.writeFileSync(entryIndexPath(entry), JSON.stringify(idx, null, 2));
343
+ }
344
+ function readRootIndexSync() {
345
+ return JSON.parse(fsSync.readFileSync(rootIndexPath(), 'utf8'));
346
+ }
347
+ function writeRootIndexSync(root) {
348
+ fsSync.writeFileSync(rootIndexPath(), JSON.stringify(root, null, 2));
349
+ }
350
+ /** 列出 dir 下的 .md 文件名(排序);目录缺失视为空 */
351
+ function listEntryMd(entry, subdir) {
352
+ try {
353
+ return fsSync.readdirSync(entrySubdir(entry, subdir)).filter(f => f.endsWith('.md')).sort();
354
+ }
355
+ catch {
356
+ return [];
357
+ }
358
+ }
359
+ function mkdirEntrySubdir(entry, subdir) {
360
+ fsSync.mkdirSync(entrySubdir(entry, subdir), { recursive: true });
361
+ }
362
+ function readEntryFile(entry, subdir, file) {
363
+ return fsSync.readFileSync(path.join(entrySubdir(entry, subdir), file));
364
+ }
365
+ function writeEntryFile(entry, subdir, file, body) {
366
+ fsSync.writeFileSync(path.join(entrySubdir(entry, subdir), file), body);
367
+ }
368
+ function unlinkEntryFile(entry, subdir, file) {
369
+ fsSync.unlinkSync(path.join(entrySubdir(entry, subdir), file));
370
+ }
371
+ function removeEntry(entry) {
372
+ fsSync.rmSync(entryDir(entry), { recursive: true, force: true });
373
+ }
374
+ // 阻断:docsDir 下存在任何 .old 旁挂目录时抛错,要求人工先处理。
375
+ // docsDir 本身缺失时直接让 readdirSync 抛错(调用方本就应在已初始化的库上学习)。
376
+ function assertNoOldSidecars() {
377
+ const oldDir = fsSync.readdirSync(docsDir).find(name => name.endsWith('.old'));
378
+ if (oldDir) {
379
+ throw new Error(`检测到未清理的旁挂目录 ${oldDir},请手工处理后再学习`);
380
+ }
381
+ }
382
+ // ============================================================
383
+ // 沙箱判定
384
+ // ============================================================
385
+ function assertInside(absPath) {
386
+ const resolved = path.resolve(absPath);
387
+ if (resolved !== docsDir && !resolved.startsWith(docsDir + path.sep)) {
388
+ throw new Error(`Access denied: ${absPath} is outside the knowledge directory ${docsDir}`);
389
+ }
390
+ return resolved;
391
+ }
392
+ function assertNotManagedIndexJson(absPath) {
393
+ if (path.basename(absPath) === 'index.json') {
394
+ throw new Error('index.json is managed by add_topic/add_chunk tools, do not write directly');
395
+ }
396
+ }
397
+ return {
398
+ root: docsDir,
399
+ listTopics,
400
+ getTopic,
401
+ searchChunks,
402
+ queryKnowledge,
403
+ readChunk,
404
+ upsertTopic,
405
+ upsertChunkRef,
406
+ readTopicIndex,
407
+ readSidecarIndex,
408
+ assertSlug,
409
+ prepareTopic,
410
+ writeSourceFile,
411
+ countSourceFiles,
412
+ readSourceBodies,
413
+ writeOutline,
414
+ readOutlineItems,
415
+ parkTopic,
416
+ restoreTopic,
417
+ renameTopic,
418
+ readEntryIndexSync,
419
+ writeEntryIndexSync,
420
+ readRootIndexSync,
421
+ writeRootIndexSync,
422
+ listEntryMd,
423
+ mkdirEntrySubdir,
424
+ readEntryFile,
425
+ writeEntryFile,
426
+ unlinkEntryFile,
427
+ removeEntry,
428
+ assertNoOldSidecars,
429
+ assertInside,
430
+ assertNotManagedIndexJson,
431
+ };
432
+ }
433
+ // 默认单例:绑生产 docsDir
434
+ export const vault = createVault(path.join(dataDir, 'docs'));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cc-monitoring/proxy-core",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
4
4
  "description": "Claude Code 代理工具 + Token 消耗监控面板",
5
5
  "keywords": [
6
6
  "claude-code-proxy",