@jshookmcp/jshook 0.3.0 → 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 (321) hide show
  1. package/README.md +25 -50
  2. package/README.zh.md +25 -48
  3. package/dist/AntiCheatDetector-CGVGNfy5.mjs +1 -0
  4. package/dist/CacheAdapters-CdAxBmVW.mjs +1 -0
  5. package/dist/CodeInjector-BlgyqTOk.mjs +1 -0
  6. package/dist/ConsoleMonitor-Dkqc0HNi.mjs +490 -0
  7. package/dist/DOMInspector-BYY_EJ0C.mjs +95 -0
  8. package/dist/DarwinAPI-DC4HGGLl.mjs +1 -0
  9. package/dist/DetailedDataManager-BniBJlVv.mjs +1 -0
  10. package/dist/EventBus-DgciURGg.mjs +1 -0
  11. package/dist/EvidenceGraphBridge-BIfgB7HP.mjs +1 -0
  12. package/dist/ExtensionManager-erMpqcLk.mjs +1 -0
  13. package/dist/FingerprintManager-N7BZqjxP.mjs +1 -0
  14. package/dist/HardwareBreakpoint-OcJqNFVc.mjs +1 -0
  15. package/dist/HeapAnalyzer-CqAxZzeS.mjs +1 -0
  16. package/dist/{HookGeneratorBuilders.core.generators.storage-CTbB4Lcx.mjs → HookGeneratorBuilders.core.generators.storage-Bf1fbrNK.mjs} +66 -101
  17. package/dist/InstrumentationSession-DxXs0sCp.mjs +1 -0
  18. package/dist/MCPServer.search.handlers.domain-DVbWL1bT.mjs +1 -0
  19. package/dist/MemoryController-BaqstM5w.mjs +2 -0
  20. package/dist/MemoryScanSession-CaxAjZJf.mjs +1 -0
  21. package/dist/MemoryScanner-BLYnMJy6.mjs +1 -0
  22. package/dist/NativeMemoryManager.impl-CI554XbY.mjs +1 -0
  23. package/dist/NativeMemoryManager.utils-DM4NC3FE.mjs +1 -0
  24. package/dist/PEAnalyzer-DJyaJTQJ.mjs +1 -0
  25. package/dist/PageController-D9jVkH0i.mjs +1 -0
  26. package/dist/PointerChainEngine-5nF9eNlu.mjs +1 -0
  27. package/dist/PrerequisiteError-Bl3dK8XA.mjs +1 -0
  28. package/dist/ProcessRegistry-Hf12LlR9.mjs +1 -0
  29. package/dist/ResponseBuilder-B2lu4KEl.mjs +1 -0
  30. package/dist/ReverseEvidenceGraph-B931HeoW.mjs +2 -0
  31. package/dist/ScriptManager-fgqiALgj.mjs +7 -0
  32. package/dist/Speedhack-l6s8L2Qw.mjs +1 -0
  33. package/dist/StealthVerifier-Dhbj4B4P.mjs +1 -0
  34. package/dist/StructureAnalyzer-A-WamfYE.mjs +2 -0
  35. package/dist/ToolCatalog-D_IKl1Hu.mjs +1 -0
  36. package/dist/ToolError-DWU_z7gp.mjs +1 -0
  37. package/dist/ToolProbe-xsfALmN3.mjs +1 -0
  38. package/dist/ToolRegistry-B0Zs-phN.mjs +1 -0
  39. package/dist/ToolRouter.policy-CFHoN_Lw.mjs +4 -0
  40. package/dist/TraceRecorder-Dd8jLXpi.mjs +272 -0
  41. package/dist/VersionDetector-DMoUWyNm.mjs +9 -0
  42. package/dist/Win32API-Bhi5xFBe.mjs +1 -0
  43. package/dist/Win32Debug-CQteFL4F.mjs +1 -0
  44. package/dist/WorkflowEngine-CxEp2WXH.mjs +1 -0
  45. package/dist/analysis-BuR-NgX8.mjs +5 -0
  46. package/dist/{antidebug-BRKeyt27.mjs → antidebug-BOTZH6-0.mjs} +8 -259
  47. package/dist/artifactRetention-NBdncOEW.mjs +1 -0
  48. package/dist/artifacts-B5xQuEa_.mjs +1 -0
  49. package/dist/authorization-schema-B40obG1A.mjs +1 -0
  50. package/dist/betterSqlite3-CGaxz4AX.mjs +1 -0
  51. package/dist/binary-instrument-Cf9qqLlM.mjs +7 -0
  52. package/dist/bind-helpers-BlAOQrFQ.mjs +1 -0
  53. package/dist/boringssl-inspector-BST5vtKx.mjs +2 -0
  54. package/dist/browser-C4Le3xqA.mjs +11 -0
  55. package/dist/capabilities-DbYCv-HF.mjs +1 -0
  56. package/dist/chunk-C_pMuVsO.mjs +1 -0
  57. package/dist/collector-CKO8RPK8.mjs +1 -0
  58. package/dist/concurrency-CcK46d0h.mjs +1 -0
  59. package/dist/constants-Cp6hBrrx.mjs +1 -0
  60. package/dist/coordination-BbijHEHH.mjs +1 -0
  61. package/dist/debugger-CRJq_krh.mjs +1 -0
  62. package/dist/definitions-BGobEDQa.mjs +1 -0
  63. package/dist/definitions-BGwNSkVm.mjs +1 -0
  64. package/dist/definitions-BbxOUiP-.mjs +1 -0
  65. package/dist/definitions-CCP9gphV.mjs +1 -0
  66. package/dist/definitions-CIO9O-Sw.mjs +1 -0
  67. package/dist/definitions-CYFbewnd.mjs +1 -0
  68. package/dist/definitions-CdWEuIkI.mjs +1 -0
  69. package/dist/definitions-CoQFbggH.mjs +1 -0
  70. package/dist/definitions-CuJRsJ6N.mjs +1 -0
  71. package/dist/definitions-DI9YXsJk.mjs +1 -0
  72. package/dist/definitions-DJklW2sS.mjs +1 -0
  73. package/dist/definitions-DZ8uKusP.mjs +1 -0
  74. package/dist/definitions-Dds_zrWx.mjs +1 -0
  75. package/dist/definitions-Dgrg7f3D.mjs +1 -0
  76. package/dist/definitions-DtE0XLrT.mjs +1 -0
  77. package/dist/definitions-LaYTuwQd.mjs +26 -0
  78. package/dist/definitions-NoVp_9Pm.mjs +1 -0
  79. package/dist/definitions-OvGsfxdt.mjs +1 -0
  80. package/dist/definitions-jXPaVy4P.mjs +1 -0
  81. package/dist/encoding-DGcr6Aj_.mjs +2 -0
  82. package/dist/ensure-browser-core-Buls24LQ.mjs +1 -0
  83. package/dist/evidence-graph-bridge-B0yhGPcs.mjs +1 -0
  84. package/dist/factory-Cx_1LorX.mjs +1 -0
  85. package/dist/flat-target-session-CO5g78k3.mjs +1 -0
  86. package/dist/formatAddress-C7j2fDlM.mjs +1 -0
  87. package/dist/graphql-HLf3MS8H.mjs +62 -0
  88. package/dist/handlers-BLMa4X7l.mjs +54 -0
  89. package/dist/handlers-BP12ZsWc.mjs +4 -0
  90. package/dist/handlers-BZoPla6E.mjs +1 -0
  91. package/dist/handlers-BggKiVx9.mjs +2 -0
  92. package/dist/handlers-D3iev8g1.mjs +1 -0
  93. package/dist/handlers-D49r1-1P.mjs +1 -0
  94. package/dist/handlers-DCE45Ww8.mjs +2 -0
  95. package/dist/handlers-DW5AbYs5.mjs +5 -0
  96. package/dist/handlers-De5u62Ga2.mjs +1 -0
  97. package/dist/handlers-DmQzIc44.mjs +31 -0
  98. package/dist/handlers-DnJRGp7t.mjs +302 -0
  99. package/dist/handlers-Dv_runVv.mjs +2 -0
  100. package/dist/handlers-S9Ws0IGy.mjs +2 -0
  101. package/dist/{handlers-Dz9PYsCa.mjs → handlers-pVNpaw4A.mjs} +118 -904
  102. package/dist/handlers.impl-CD2_kOcC.mjs +1 -0
  103. package/dist/hooks-DDKppogd.mjs +600 -0
  104. package/dist/index.mjs +12 -5235
  105. package/dist/logger-sBC6IdRT.mjs +1 -0
  106. package/dist/maintenance-CutEO84j.mjs +1 -0
  107. package/dist/manifest-BFGxlDRh.mjs +123 -0
  108. package/dist/manifest-BPuE6oH2.mjs +1 -0
  109. package/dist/manifest-BXry5N09.mjs +1 -0
  110. package/dist/manifest-BeP_zJGb2.mjs +1 -0
  111. package/dist/manifest-C0g67k6U.mjs +1 -0
  112. package/dist/manifest-C1nZkTkO.mjs +1 -0
  113. package/dist/manifest-C7qV1z7F.mjs +1 -0
  114. package/dist/manifest-CDeUZGUZ.mjs +1 -0
  115. package/dist/manifest-CDiCtaQT.mjs +1 -0
  116. package/dist/manifest-CFn0359q2.mjs +1 -0
  117. package/dist/manifest-CGq4NpqH2.mjs +1 -0
  118. package/dist/manifest-CJMGt7Qy.mjs +1 -0
  119. package/dist/manifest-CRIJq4Hs.mjs +1 -0
  120. package/dist/manifest-C_hEIjSx.mjs +1 -0
  121. package/dist/manifest-CeQmtQOY.mjs +1 -0
  122. package/dist/manifest-Cq0j7GZt.mjs +1 -0
  123. package/dist/manifest-CtPmHAdn.mjs +1 -0
  124. package/dist/manifest-Cx2IVMUY.mjs +1 -0
  125. package/dist/manifest-D16xPXro.mjs +1 -0
  126. package/dist/manifest-D44TaRJU.mjs +1 -0
  127. package/dist/manifest-D610kxZr.mjs +2 -0
  128. package/dist/manifest-DC-SMF6b.mjs +1 -0
  129. package/dist/manifest-DD3rtxvV.mjs +1 -0
  130. package/dist/manifest-DKUorv5M.mjs +1 -0
  131. package/dist/manifest-DMJlcsTR.mjs +1 -0
  132. package/dist/manifest-DWUUWBz0.mjs +1 -0
  133. package/dist/manifest-De-6Wf2R.mjs +1 -0
  134. package/dist/manifest-Dgh0uDW-.mjs +1 -0
  135. package/dist/manifest-Dm0o3i2U.mjs +1 -0
  136. package/dist/manifest-DsVh7Y4U.mjs +1 -0
  137. package/dist/manifest-DtEFSRaq.mjs +1 -0
  138. package/dist/manifest-H-EpAyZQ.mjs +1 -0
  139. package/dist/manifest-ais9Afrw.mjs +1 -0
  140. package/dist/manifest-tmb54wmA.mjs +1 -0
  141. package/dist/manifest-yu2xiQqe.mjs +1 -0
  142. package/dist/manifest-zrbrpKCC.mjs +1 -0
  143. package/dist/matchesWildcardPattern-BGqLSmEs.mjs +1 -0
  144. package/dist/modules-p-PUNv9r.mjs +332 -0
  145. package/dist/mojo-ipc-VGlv3Qyp.mjs +9 -0
  146. package/dist/network-BjZ1Y-GB.mjs +7 -0
  147. package/dist/outputPaths-BonGThuc.mjs +2 -0
  148. package/dist/parse-args-Cuk7-xUt.mjs +1 -0
  149. package/dist/platform-C446Lf97.mjs +93 -0
  150. package/dist/playwright-cdp-fallback-BwVR-_T3.mjs +1 -0
  151. package/dist/process-C9f2A5zk.mjs +962 -0
  152. package/dist/proxy-CvRepxgV.mjs +1 -0
  153. package/dist/registry-DUHIPE-v.mjs +1 -0
  154. package/dist/response-C7rKQst4.mjs +1 -0
  155. package/dist/search-defaults-D2bY-rzH.mjs +1 -0
  156. package/dist/server/plugin-api.mjs +1 -293
  157. package/dist/shared-state-board-Cyg-xh_k.mjs +1 -0
  158. package/dist/sourcemap-D6Q1UuAp.mjs +1 -0
  159. package/dist/ssrf-policy-T96MR3r6.mjs +1 -0
  160. package/dist/streaming-CTX58tbb.mjs +1 -0
  161. package/dist/tool-builder-CI9914Tf.mjs +1 -0
  162. package/dist/transform-Cv9P2vVD.mjs +103 -0
  163. package/dist/types-CuyefmGT.mjs +1 -0
  164. package/dist/types-DtThH00r.mjs +1 -0
  165. package/dist/wasm-DaJa8J0V.mjs +174 -0
  166. package/dist/webcrack-CsLLJIs9.mjs +46 -0
  167. package/dist/workflow-CYIXtrWD.mjs +101 -0
  168. package/package.json +50 -78
  169. package/dist/AntiCheatDetector-CqGDXmfc.mjs +0 -350
  170. package/dist/CacheAdapters-jJFy20G-.mjs +0 -80
  171. package/dist/CodeInjector-BdjRfNx7.mjs +0 -150
  172. package/dist/ConsoleMonitor-DykL3IAw.mjs +0 -2269
  173. package/dist/DarwinAPI-ETyy0xyo.mjs +0 -363
  174. package/dist/DetailedDataManager-HT49OrvF.mjs +0 -217
  175. package/dist/EventBus-DFKvADm3.mjs +0 -141
  176. package/dist/EvidenceGraphBridge-318Oi0Lf.mjs +0 -153
  177. package/dist/ExtensionManager-BDMsY2Dz.mjs +0 -721
  178. package/dist/FingerprintManager-BN4UQWnX.mjs +0 -96
  179. package/dist/HardwareBreakpoint-Cc2AFq1Y.mjs +0 -239
  180. package/dist/HeapAnalyzer-DruMgsgj.mjs +0 -284
  181. package/dist/InstrumentationSession-DLH0vd-z.mjs +0 -244
  182. package/dist/MemoryController-CMtviNW_.mjs +0 -167
  183. package/dist/MemoryScanSession-ITgb_NMi.mjs +0 -278
  184. package/dist/MemoryScanner-CiL7Z3ey.mjs +0 -428
  185. package/dist/NativeMemoryManager.impl-D9Lkovvn.mjs +0 -485
  186. package/dist/NativeMemoryManager.utils-BBlAixF5.mjs +0 -165
  187. package/dist/PEAnalyzer-DMQ44gen.mjs +0 -385
  188. package/dist/PageController-BPJNqqBN.mjs +0 -431
  189. package/dist/PointerChainEngine-K7wN8Z-w.mjs +0 -325
  190. package/dist/PrerequisiteError-TuyZIs6n.mjs +0 -20
  191. package/dist/ProcessRegistry-zGg12QbE.mjs +0 -74
  192. package/dist/ResponseBuilder-CJXWmWNw.mjs +0 -143
  193. package/dist/ReverseEvidenceGraph-C02-gXOh.mjs +0 -269
  194. package/dist/ScriptManager-ZuWD-0Jg.mjs +0 -3003
  195. package/dist/Speedhack-D-z0umeT.mjs +0 -156
  196. package/dist/StealthVerifier-BWmPgQsv.mjs +0 -135
  197. package/dist/StructureAnalyzer-Cav5AVSL.mjs +0 -429
  198. package/dist/ToolCatalog-5OJdMiF0.mjs +0 -582
  199. package/dist/ToolError-jh9whhMd.mjs +0 -15
  200. package/dist/ToolProbe-DbCFGyrg.mjs +0 -45
  201. package/dist/ToolRegistry-B9krbTtI.mjs +0 -180
  202. package/dist/ToolRouter.policy-BGDAGyeH.mjs +0 -344
  203. package/dist/TraceRecorder-B41Z5XBj.mjs +0 -1286
  204. package/dist/VersionDetector-K3V4vGsw.mjs +0 -104
  205. package/dist/Win32API-C2kjj0ze.mjs +0 -346
  206. package/dist/Win32Debug-CKrGOTpo.mjs +0 -274
  207. package/dist/WorkflowEngine-DJ6M4opp.mjs +0 -569
  208. package/dist/analysis-BHeJW2Nb.mjs +0 -1234
  209. package/dist/artifactRetention-CPXkUJXp.mjs +0 -598
  210. package/dist/artifacts-DkfosXH3.mjs +0 -59
  211. package/dist/authorization-schema-DRqyJMSk.mjs +0 -31
  212. package/dist/betterSqlite3-DLSBZodi.mjs +0 -74
  213. package/dist/binary-instrument--V3MAhJ4.mjs +0 -971
  214. package/dist/bind-helpers-ClV34xdn.mjs +0 -42
  215. package/dist/boringssl-inspector-Bo_LOLaS.mjs +0 -180
  216. package/dist/browser-Dx3_S2cG.mjs +0 -4369
  217. package/dist/capabilities-CcHlvWgK.mjs +0 -33
  218. package/dist/chunk-CjcI7cDX.mjs +0 -15
  219. package/dist/concurrency-Drev_Vz9.mjs +0 -41
  220. package/dist/constants-CDZLOoVv.mjs +0 -534
  221. package/dist/coordination-DgItD9DL.mjs +0 -259
  222. package/dist/debugger-RS3RSAqs.mjs +0 -1288
  223. package/dist/definitions-BEoYofW5.mjs +0 -47
  224. package/dist/definitions-BRaefg3u.mjs +0 -365
  225. package/dist/definitions-BbkvZkiv.mjs +0 -96
  226. package/dist/definitions-BtWSHJ3o.mjs +0 -17
  227. package/dist/definitions-C1gCHO0i.mjs +0 -43
  228. package/dist/definitions-CDOg_b-l.mjs +0 -138
  229. package/dist/definitions-CVPD9hzZ.mjs +0 -54
  230. package/dist/definitions-Cea8Lgl7.mjs +0 -94
  231. package/dist/definitions-DAgIyjxM.mjs +0 -10
  232. package/dist/definitions-DJA27nsL.mjs +0 -66
  233. package/dist/definitions-DKPFU3LW.mjs +0 -25
  234. package/dist/definitions-DPRpZQ96.mjs +0 -47
  235. package/dist/definitions-DUE5gmdn.mjs +0 -18
  236. package/dist/definitions-DYVjOtxa.mjs +0 -26
  237. package/dist/definitions-DcYLVLCo.mjs +0 -37
  238. package/dist/definitions-Pp5LI2H4.mjs +0 -27
  239. package/dist/definitions-j9KdHVNR.mjs +0 -14
  240. package/dist/definitions-uzkjBwa7.mjs +0 -258
  241. package/dist/definitions-va-AnLuQ.mjs +0 -28
  242. package/dist/encoding-DJeqHmpd.mjs +0 -1079
  243. package/dist/evidence-graph-bridge-DcYizFk2.mjs +0 -136
  244. package/dist/factory-C90tBff6.mjs +0 -575
  245. package/dist/flat-target-session-Dgax2Cy3.mjs +0 -29
  246. package/dist/formatAddress-nnMvEohD.mjs +0 -17
  247. package/dist/graphql-CoHrhweh.mjs +0 -1197
  248. package/dist/handlers-4jmR0nMs.mjs +0 -898
  249. package/dist/handlers-BAHPxcch.mjs +0 -789
  250. package/dist/handlers-BOs9b907.mjs +0 -2600
  251. package/dist/handlers-BWXEy6ef.mjs +0 -917
  252. package/dist/handlers-Bndn6QvE.mjs +0 -111
  253. package/dist/handlers-BqC4bD4s.mjs +0 -681
  254. package/dist/handlers-BtYq60bM2.mjs +0 -276
  255. package/dist/handlers-BzgcB4iv.mjs +0 -799
  256. package/dist/handlers-CRyRWj2b.mjs +0 -859
  257. package/dist/handlers-CVv2H1uq.mjs +0 -592
  258. package/dist/handlers-Dl5a7JS4.mjs +0 -572
  259. package/dist/handlers-Dx2d7jt7.mjs +0 -2537
  260. package/dist/handlers-HujRKC3b.mjs +0 -661
  261. package/dist/handlers.impl-XWXkQfyi.mjs +0 -807
  262. package/dist/hooks-B1B8NRHL.mjs +0 -898
  263. package/dist/logger-Dh_xb7_2.mjs +0 -93
  264. package/dist/maintenance-PRMkLVRW.mjs +0 -835
  265. package/dist/manifest-67Bok-Si.mjs +0 -58
  266. package/dist/manifest-6lNTMZAB2.mjs +0 -87
  267. package/dist/manifest-B2duEHiH.mjs +0 -90
  268. package/dist/manifest-B6EY9Vm8.mjs +0 -57
  269. package/dist/manifest-B6nKSbyY.mjs +0 -95
  270. package/dist/manifest-BL8AQNPF.mjs +0 -106
  271. package/dist/manifest-BSZvJJmV.mjs +0 -47
  272. package/dist/manifest-BU7qzUyX.mjs +0 -418
  273. package/dist/manifest-Bl62e8WK.mjs +0 -49
  274. package/dist/manifest-Bo5cXjdt.mjs +0 -82
  275. package/dist/manifest-BpS4gtUK.mjs +0 -1347
  276. package/dist/manifest-Bv65_e2W.mjs +0 -101
  277. package/dist/manifest-BytNIF4Z.mjs +0 -117
  278. package/dist/manifest-C-xtsjS3.mjs +0 -81
  279. package/dist/manifest-CDYl7OhA.mjs +0 -66
  280. package/dist/manifest-CRZ3xmkD.mjs +0 -61
  281. package/dist/manifest-CoW6u4Tp.mjs +0 -132
  282. package/dist/manifest-Cq5zN_8A.mjs +0 -50
  283. package/dist/manifest-D7YZM_2e.mjs +0 -194
  284. package/dist/manifest-DE_VrAeQ.mjs +0 -314
  285. package/dist/manifest-DGsXSCpT.mjs +0 -39
  286. package/dist/manifest-DJ2vfEuW.mjs +0 -156
  287. package/dist/manifest-DPXDYhEu.mjs +0 -80
  288. package/dist/manifest-Dd4fQb0a.mjs +0 -322
  289. package/dist/manifest-Deq6opGg.mjs +0 -223
  290. package/dist/manifest-DfJTafJK.mjs +0 -37
  291. package/dist/manifest-DgOdgN_j.mjs +0 -50
  292. package/dist/manifest-DlbMW4v4.mjs +0 -47
  293. package/dist/manifest-DmVfbH0w.mjs +0 -374
  294. package/dist/manifest-Dog6Ddjr.mjs +0 -109
  295. package/dist/manifest-DvgU5FWb.mjs +0 -58
  296. package/dist/manifest-HsfDBs7j.mjs +0 -50
  297. package/dist/manifest-I8oQHvCG.mjs +0 -186
  298. package/dist/manifest-NvH_a-av.mjs +0 -786
  299. package/dist/manifest-cEJU1v0Z.mjs +0 -129
  300. package/dist/manifest-wOl5XLB12.mjs +0 -112
  301. package/dist/modules-tZozf0LQ.mjs +0 -10635
  302. package/dist/mojo-ipc-DXNEXEqb.mjs +0 -640
  303. package/dist/network-CPVvwvFg.mjs +0 -3852
  304. package/dist/outputPaths-um7lCRY3.mjs +0 -1141
  305. package/dist/parse-args-B4cY5Vx5.mjs +0 -39
  306. package/dist/platform-CYeFoTWp.mjs +0 -2161
  307. package/dist/process-BTbgcVc6.mjs +0 -1306
  308. package/dist/proxy-r8YN6nP1.mjs +0 -192
  309. package/dist/registry-Bl8ZQW61.mjs +0 -34
  310. package/dist/response-CWhh2aLo.mjs +0 -34
  311. package/dist/shared-state-board-BoZnSoj-.mjs +0 -586
  312. package/dist/sourcemap-BIDHUVXy.mjs +0 -934
  313. package/dist/ssrf-policy-Dsqd-DTX.mjs +0 -166
  314. package/dist/streaming-Dal6utPp.mjs +0 -725
  315. package/dist/tool-builder-BHJp32mV.mjs +0 -186
  316. package/dist/transform-DRVgGG90.mjs +0 -1011
  317. package/dist/types-Bx92KJfT.mjs +0 -4
  318. package/dist/types-DDBWs9UP.mjs +0 -37
  319. package/dist/wasm-BYx5UOeG.mjs +0 -1044
  320. package/dist/webcrack-Be0_FccV.mjs +0 -747
  321. package/dist/workflow-BpuKEtvn.mjs +0 -725
@@ -1,799 +0,0 @@
1
- import { kr as WEBHOOK_PROCESS_TIMEOUT_MS } from "./constants-CDZLOoVv.mjs";
2
- import { n as asJsonResponse } from "./response-CWhh2aLo.mjs";
3
- import { i as getProjectRoot, r as getExtensionRegistryDir } from "./outputPaths-um7lCRY3.mjs";
4
- import { a as argString, i as argObject, s as argStringRequired } from "./parse-args-B4cY5Vx5.mjs";
5
- import http from "node:http";
6
- import { existsSync, mkdirSync, readFileSync, readdirSync } from "node:fs";
7
- import path from "node:path";
8
- import { fileURLToPath, pathToFileURL } from "node:url";
9
- import { mkdir, writeFile } from "node:fs/promises";
10
- import { EventEmitter } from "node:events";
11
- //#region src/modules/extension-registry/PluginRegistry.ts
12
- function isRecord$2(value) {
13
- return value !== null && typeof value === "object" && !Array.isArray(value);
14
- }
15
- function sanitizeId(value) {
16
- const normalized = value.trim().toLowerCase().replace(/\//g, "-").replace(/(?!^@)[^a-z0-9@_-]+/g, "-");
17
- return normalized.length > 0 ? normalized : `plugin-${Date.now()}`;
18
- }
19
- function toStoredPluginManifest(value) {
20
- if (!isRecord$2(value)) return null;
21
- const { id, name, version, entry, permissions, status } = value;
22
- if (typeof id !== "string" || typeof name !== "string" || typeof version !== "string" || typeof entry !== "string" || status !== "loaded" && status !== "unloaded") return null;
23
- return {
24
- id,
25
- name,
26
- version,
27
- entry,
28
- permissions: Array.isArray(permissions) ? permissions.filter((permission) => typeof permission === "string") : [],
29
- status
30
- };
31
- }
32
- var PluginRegistry = class {
33
- rootDir;
34
- legacyPluginRoots;
35
- useLegacyScanApi;
36
- registryFile;
37
- moduleCacheDir;
38
- installedPlugins = /* @__PURE__ */ new Map();
39
- loadedPlugins = /* @__PURE__ */ new Map();
40
- constructor(rootDirOrContext = getExtensionRegistryDir(), pluginRoots = []) {
41
- const resolvedRootDir = typeof rootDirOrContext === "string" ? rootDirOrContext : getExtensionRegistryDir();
42
- this.useLegacyScanApi = typeof rootDirOrContext !== "string";
43
- this.rootDir = resolvedRootDir;
44
- this.registryFile = path.join(resolvedRootDir, "plugins.json");
45
- this.moduleCacheDir = path.join(resolvedRootDir, "modules");
46
- this.legacyPluginRoots = pluginRoots.length > 0 ? pluginRoots : process.env["JSHOOKMCP_PLUGIN_ROOT"] ? [process.env["JSHOOKMCP_PLUGIN_ROOT"]] : [];
47
- if (this.useLegacyScanApi) return;
48
- this.initializeFromDisk();
49
- }
50
- async register(plugin) {
51
- const pluginId = sanitizeId(plugin.id || plugin.name);
52
- const manifest = {
53
- id: pluginId,
54
- name: plugin.name,
55
- version: plugin.version,
56
- entry: plugin.entry,
57
- permissions: plugin.permissions ? [...plugin.permissions] : [],
58
- status: this.loadedPlugins.has(pluginId) ? "loaded" : "unloaded"
59
- };
60
- this.installedPlugins.set(pluginId, manifest);
61
- await this.persist();
62
- return pluginId;
63
- }
64
- async unregister(pluginId) {
65
- await this.unloadPlugin(pluginId);
66
- this.installedPlugins.delete(pluginId);
67
- await this.persist();
68
- }
69
- listInstalled() {
70
- return [...this.installedPlugins.values()].map((plugin) => ({
71
- id: plugin.id,
72
- name: plugin.name,
73
- version: plugin.version,
74
- status: plugin.status,
75
- permissions: [...plugin.permissions]
76
- })).toSorted((left, right) => left.name.localeCompare(right.name));
77
- }
78
- async loadPlugin(pluginId) {
79
- const manifest = this.installedPlugins.get(pluginId);
80
- if (!manifest) throw new Error(`Plugin not found: ${pluginId}`);
81
- const existing = this.loadedPlugins.get(pluginId);
82
- if (existing) return {
83
- manifest: this.toPublicManifest(existing.manifest),
84
- exports: existing.exports
85
- };
86
- const importUrl = pathToFileURL(await this.resolveEntryPath(manifest));
87
- importUrl.searchParams.set("ts", String(Date.now()));
88
- const moduleExports = await import(importUrl.href);
89
- const exportsRecord = isRecord$2(moduleExports) ? moduleExports : {};
90
- manifest.status = "loaded";
91
- this.loadedPlugins.set(pluginId, {
92
- manifest,
93
- exports: exportsRecord
94
- });
95
- await this.persist();
96
- return {
97
- manifest: this.toPublicManifest(manifest),
98
- exports: exportsRecord
99
- };
100
- }
101
- async unloadPlugin(pluginId) {
102
- const manifest = this.installedPlugins.get(pluginId);
103
- if (!manifest) return;
104
- this.loadedPlugins.delete(pluginId);
105
- manifest.status = "unloaded";
106
- await this.persist();
107
- }
108
- initializeFromDisk() {
109
- if (!existsSync(this.rootDir)) mkdirSync(this.rootDir, { recursive: true });
110
- if (!existsSync(this.moduleCacheDir)) mkdirSync(this.moduleCacheDir, { recursive: true });
111
- if (!existsSync(this.registryFile)) return;
112
- const content = readFileSync(this.registryFile, "utf8");
113
- if (!content.trim()) return;
114
- const parsed = JSON.parse(content);
115
- if (!Array.isArray(parsed)) return;
116
- for (const item of parsed) {
117
- const manifest = toStoredPluginManifest(item);
118
- if (manifest) this.installedPlugins.set(manifest.id, manifest);
119
- }
120
- }
121
- async persist() {
122
- await mkdir(this.rootDir, { recursive: true });
123
- await mkdir(this.moduleCacheDir, { recursive: true });
124
- await writeFile(this.registryFile, JSON.stringify([...this.installedPlugins.values()], null, 2), "utf8");
125
- }
126
- async resolveEntryPath(manifest) {
127
- if (manifest.entry.startsWith("http://") || manifest.entry.startsWith("https://")) return this.downloadRemoteModule(manifest.id, manifest.entry);
128
- if (manifest.entry.startsWith("file://")) return fileURLToPath(new URL(manifest.entry));
129
- return path.isAbsolute(manifest.entry) ? manifest.entry : path.resolve(getProjectRoot(), manifest.entry);
130
- }
131
- async downloadRemoteModule(pluginId, url) {
132
- const response = await fetch(url);
133
- if (!response.ok) throw new Error(`Failed to download plugin module: ${response.status} ${response.statusText}`);
134
- const source = await response.text();
135
- const outputPath = path.join(this.moduleCacheDir, `${sanitizeId(pluginId)}.mjs`);
136
- await mkdir(this.moduleCacheDir, { recursive: true });
137
- await writeFile(outputPath, source, "utf8");
138
- return outputPath;
139
- }
140
- toPublicManifest(manifest) {
141
- return {
142
- id: manifest.id,
143
- name: manifest.name,
144
- version: manifest.version,
145
- entry: manifest.entry,
146
- permissions: [...manifest.permissions]
147
- };
148
- }
149
- listPlugins() {
150
- const plugins = [];
151
- for (const root of this.legacyPluginRoots) {
152
- if (!existsSync(root)) continue;
153
- const entries = readdirSync(root, { withFileTypes: true });
154
- for (const entry of entries) {
155
- if (!entry.isDirectory() || entry.name.startsWith(".")) continue;
156
- const packageJsonPath = path.join(root, entry.name, "package.json");
157
- if (!existsSync(packageJsonPath)) continue;
158
- try {
159
- const manifest = JSON.parse(readFileSync(packageJsonPath, "utf8"));
160
- const plugin = this.toLegacyPluginInfo(manifest);
161
- if (plugin) plugins.push(plugin);
162
- } catch {
163
- continue;
164
- }
165
- }
166
- }
167
- return plugins;
168
- }
169
- searchPlugins(query) {
170
- const normalized = query.trim().toLowerCase();
171
- if (!normalized) return this.listPlugins();
172
- return this.listPlugins().filter((plugin) => {
173
- return plugin.name.toLowerCase().includes(normalized) || (plugin.description ?? "").toLowerCase().includes(normalized) || (plugin.capabilities ?? []).some((capability) => capability.toLowerCase().includes(normalized)) || (plugin.dependencies ?? []).some((dependency) => dependency.toLowerCase().includes(normalized));
174
- });
175
- }
176
- async installPlugin(source) {
177
- if (/^https:\/\/github\.com\/.+\.git$/u.test(source) || /^git@github\.com:.+\.git$/u.test(source)) return {
178
- id: "git-plugin",
179
- name: source.split("/").pop()?.replace(/\.git$/u, "") ?? "plugin",
180
- version: "0.0.0"
181
- };
182
- if (source.includes("://") || source.startsWith("git@") || source === "invalid-url") throw new Error("Invalid git URL");
183
- if (source.startsWith("/") || source.includes("\\")) {
184
- const packageJsonPath = path.join(source, "package.json");
185
- if (!existsSync(packageJsonPath)) throw new Error("No package.json");
186
- const manifest = JSON.parse(readFileSync(packageJsonPath, "utf8"));
187
- const plugin = this.toLegacyPluginInfo(manifest);
188
- if (!plugin) throw new Error("No package.json");
189
- return plugin;
190
- }
191
- for (const root of this.legacyPluginRoots) {
192
- const packageJsonPath = path.join(root, source, "package.json");
193
- if (!existsSync(packageJsonPath)) continue;
194
- const manifest = JSON.parse(readFileSync(packageJsonPath, "utf8"));
195
- const plugin = this.toLegacyPluginInfo(manifest);
196
- if (plugin) return plugin;
197
- }
198
- throw new Error("Plugin not found");
199
- }
200
- getPluginInfo(pluginId) {
201
- return this.listPlugins().find((plugin) => plugin.id === pluginId || plugin.name === pluginId);
202
- }
203
- getPluginDependencies(pluginId) {
204
- return this.getPluginInfo(pluginId)?.dependencies ?? [];
205
- }
206
- async uninstallPlugin(_pluginId) {}
207
- toLegacyPluginInfo(manifest) {
208
- if (typeof manifest["name"] !== "string") return null;
209
- const dependencies = isRecord$2(manifest["dependencies"]) ? Object.keys(manifest["dependencies"]) : [];
210
- return {
211
- id: sanitizeId(manifest["name"]),
212
- name: manifest["name"],
213
- version: typeof manifest["version"] === "string" ? manifest["version"] : "0.0.0",
214
- description: typeof manifest["description"] === "string" ? manifest["description"] : void 0,
215
- capabilities: Array.isArray(manifest["capabilities"]) ? manifest["capabilities"].filter((value) => typeof value === "string") : void 0,
216
- dependencies
217
- };
218
- }
219
- };
220
- //#endregion
221
- //#region src/modules/extension-registry/WebhookBridge.ts
222
- function isRecord$1(value) {
223
- return value !== null && typeof value === "object" && !Array.isArray(value);
224
- }
225
- function toWebhookRecord(value) {
226
- if (!isRecord$1(value)) return null;
227
- const { id, url, events, active } = value;
228
- if (typeof id !== "string" || typeof url !== "string" || !Array.isArray(events) || typeof active !== "boolean") return null;
229
- return {
230
- id,
231
- url,
232
- events: events.filter((event) => typeof event === "string"),
233
- active
234
- };
235
- }
236
- var WebhookBridge = class {
237
- rootDir;
238
- storageFile;
239
- webhooks = /* @__PURE__ */ new Map();
240
- constructor(rootDir = getExtensionRegistryDir()) {
241
- this.rootDir = rootDir;
242
- this.storageFile = path.join(rootDir, "webhooks.json");
243
- this.initializeFromDisk();
244
- }
245
- async registerWebhook(url, events) {
246
- new URL(url);
247
- const record = {
248
- id: `webhook-${Date.now()}-${this.webhooks.size + 1}`,
249
- url,
250
- events: [...new Set(events.filter((event) => event.trim().length > 0))],
251
- active: true
252
- };
253
- this.webhooks.set(record.id, record);
254
- await this.persist();
255
- return record.id;
256
- }
257
- async sendEvent(event, payload) {
258
- const deliveries = [...this.webhooks.values()].filter((record) => record.active && (record.events.includes(event) || record.events.includes("*")));
259
- for (const record of deliveries) {
260
- const response = await fetch(record.url, {
261
- method: "POST",
262
- headers: { "content-type": "application/json" },
263
- body: JSON.stringify({
264
- event,
265
- payload,
266
- timestamp: (/* @__PURE__ */ new Date()).toISOString()
267
- })
268
- });
269
- if (!response.ok) throw new Error(`Webhook delivery failed for ${record.url}: ${response.status} ${response.statusText}`);
270
- }
271
- }
272
- listWebhooks() {
273
- return [...this.webhooks.values()].map((record) => ({
274
- id: record.id,
275
- url: record.url,
276
- events: [...record.events],
277
- active: record.active
278
- }));
279
- }
280
- /**
281
- * Register an external callback URL for a webhook endpoint.
282
- * Used when webhook({ action: "create" }) registers an endpoint — the URL is stored
283
- * here so emitEvent() can forward events to external callbacks.
284
- */
285
- registerExternalCallback(endpointId, url) {
286
- const existing = this.webhooks.get(endpointId);
287
- if (existing) {
288
- existing.url = url;
289
- return;
290
- }
291
- this.webhooks.set(endpointId, {
292
- id: endpointId,
293
- url,
294
- events: ["*"],
295
- active: true
296
- });
297
- }
298
- initializeFromDisk() {
299
- if (!existsSync(this.rootDir)) mkdirSync(this.rootDir, { recursive: true });
300
- if (!existsSync(this.storageFile)) return;
301
- const content = readFileSync(this.storageFile, "utf8");
302
- if (!content.trim()) return;
303
- const parsed = JSON.parse(content);
304
- if (!Array.isArray(parsed)) return;
305
- for (const item of parsed) {
306
- const record = toWebhookRecord(item);
307
- if (record) this.webhooks.set(record.id, record);
308
- }
309
- }
310
- async persist() {
311
- await mkdir(this.rootDir, { recursive: true });
312
- await writeFile(this.storageFile, JSON.stringify([...this.webhooks.values()], null, 2), "utf8");
313
- }
314
- };
315
- //#endregion
316
- //#region src/server/webhook/CommandQueue.impl.ts
317
- function cloneCommand(command) {
318
- return { ...command };
319
- }
320
- function normalizeTimestamp() {
321
- return (/* @__PURE__ */ new Date()).toISOString();
322
- }
323
- var CommandQueueImpl = class extends EventEmitter {
324
- maxQueueSize;
325
- commands = /* @__PURE__ */ new Map();
326
- order = [];
327
- maxRetries;
328
- retryDelay;
329
- processTimeout;
330
- nextId = 1;
331
- constructor(options = {}) {
332
- super();
333
- this.maxQueueSize = typeof options.maxQueueSize === "number" ? options.maxQueueSize : 1e3;
334
- this.maxRetries = typeof options.maxRetries === "number" ? options.maxRetries : 3;
335
- this.retryDelay = typeof options.retryDelay === "number" ? options.retryDelay : 0;
336
- this.processTimeout = typeof options.processTimeout === "number" ? options.processTimeout : WEBHOOK_PROCESS_TIMEOUT_MS;
337
- }
338
- enqueue(command) {
339
- if (this.order.length >= this.maxQueueSize) throw new Error(`Command queue is full (${this.maxQueueSize})`);
340
- const id = `cmd-${this.nextId}`;
341
- this.nextId += 1;
342
- const createdAt = normalizeTimestamp();
343
- const entry = {
344
- id,
345
- endpointId: command.endpointId,
346
- event: command.event,
347
- payload: command.payload,
348
- status: "pending",
349
- retries: 0,
350
- createdAt,
351
- updatedAt: createdAt
352
- };
353
- this.commands.set(id, entry);
354
- this.order.push(id);
355
- this.emit("enqueued", cloneCommand(entry));
356
- return id;
357
- }
358
- dequeue(filter) {
359
- if (!filter) {
360
- const firstPending = this.getCommandsByFilter({ status: "pending" })[0];
361
- return firstPending ? cloneCommand(firstPending) : void 0;
362
- }
363
- return this.getCommandsByFilter(filter).map(cloneCommand);
364
- }
365
- getStatus(id) {
366
- const command = this.commands.get(id);
367
- if (!command) return "failed";
368
- if (command.status === "processed") return "completed";
369
- return command.status;
370
- }
371
- retry(id) {
372
- const command = this.commands.get(id);
373
- if (!command) throw new Error(`Command ${id} not found`);
374
- if (command.status !== "failed") throw new Error(`Command ${id} is not in failed state`);
375
- command.status = "pending";
376
- command.retries = 0;
377
- command.lastError = void 0;
378
- command.updatedAt = normalizeTimestamp();
379
- }
380
- getCommand(id) {
381
- return this.commands.get(id);
382
- }
383
- getCommandsByFilter(filter) {
384
- const normalizedStatus = filter.status === "completed" ? "processed" : filter.status;
385
- const results = [];
386
- for (const id of this.order) {
387
- const command = this.commands.get(id);
388
- if (!command) continue;
389
- if (normalizedStatus && command.status !== normalizedStatus) continue;
390
- if (filter.endpointId && command.endpointId !== filter.endpointId) continue;
391
- results.push(command);
392
- }
393
- return results;
394
- }
395
- updateStatus(id, status, lastError) {
396
- const command = this.commands.get(id);
397
- if (!command) throw new Error(`Command ${id} not found`);
398
- command.status = status;
399
- command.updatedAt = normalizeTimestamp();
400
- command.lastError = lastError;
401
- return command;
402
- }
403
- };
404
- var CommandQueue = class extends CommandQueueImpl {
405
- async process(id, handler) {
406
- const command = this.getCommand(id);
407
- if (!command) throw new Error(`Command ${id} not found`);
408
- if (command.status === "processed") throw new Error(`Command ${id} already processed`);
409
- if (command.status === "failed") throw new Error(`Command ${id} already processed with failure`);
410
- if (command.status === "processing") throw new Error(`Command ${id} is already processing`);
411
- this.updateStatus(id, "processing");
412
- let finalStatus = "processed";
413
- let lastError;
414
- try {
415
- await Promise.race([Promise.resolve(handler(cloneCommand(command))), new Promise((_, reject) => {
416
- setTimeout(() => {
417
- reject(/* @__PURE__ */ new Error("Process timeout"));
418
- }, this.processTimeout);
419
- })]);
420
- } catch (error) {
421
- lastError = error instanceof Error ? error.message : String(error);
422
- if (command.retries + 1 >= this.maxRetries) finalStatus = "failed";
423
- else finalStatus = "pending";
424
- }
425
- if (lastError !== void 0 && this.retryDelay > 0) setTimeout(() => {}, this.retryDelay);
426
- if (finalStatus === "processed") {
427
- const processed = this.updateStatus(id, "processed");
428
- this.emit("processed", cloneCommand(processed));
429
- } else if (finalStatus === "pending") {
430
- command.retries += 1;
431
- const retried = this.updateStatus(id, "pending", lastError);
432
- this.emit("retried", cloneCommand(retried));
433
- throw lastError !== void 0 ? new Error(lastError) : /* @__PURE__ */ new Error("retry");
434
- } else {
435
- const failed = this.updateStatus(id, "failed", lastError);
436
- this.emit("failed", cloneCommand(failed));
437
- throw lastError !== void 0 ? new Error(lastError) : /* @__PURE__ */ new Error("failed");
438
- }
439
- }
440
- async retry(id) {
441
- super.retry(id);
442
- }
443
- exportState() {
444
- const results = [];
445
- for (const id of this.order) {
446
- const command = this.commands.get(id);
447
- if (command) results.push(cloneCommand(command));
448
- }
449
- return results;
450
- }
451
- importState(commands) {
452
- this.commands.clear();
453
- this.order.length = 0;
454
- let maxId = 0;
455
- for (const command of commands) {
456
- const entry = cloneCommand(command);
457
- this.commands.set(entry.id, entry);
458
- this.order.push(entry.id);
459
- const match = /^cmd-(\d+)$/.exec(entry.id);
460
- if (match && match[1]) {
461
- const num = parseInt(match[1], 10);
462
- if (num > maxId) maxId = num;
463
- }
464
- }
465
- if (maxId > 0) this.nextId = maxId + 1;
466
- }
467
- };
468
- //#endregion
469
- //#region src/server/webhook/WebhookServer.impl.ts
470
- function isWebhookEvent(value) {
471
- return value === "tool_called" || value === "domain_activated" || value === "evidence_added" || value === "workflow_completed";
472
- }
473
- function parseJsonBody(rawBody) {
474
- if (rawBody.length === 0) return {};
475
- try {
476
- return JSON.parse(rawBody);
477
- } catch {
478
- return { rawBody };
479
- }
480
- }
481
- var WebhookServerImpl = class extends EventEmitter {
482
- endpoints = /* @__PURE__ */ new Map();
483
- eventHandlers = /* @__PURE__ */ new Map();
484
- port;
485
- commandQueue;
486
- stats = {
487
- eventsRegistered: 0,
488
- webhooksSent: 0
489
- };
490
- server;
491
- nextEndpointId = 1;
492
- constructor(options = {}) {
493
- super();
494
- this.port = typeof options.port === "number" ? options.port : 18789;
495
- this.commandQueue = options.commandQueue;
496
- }
497
- registerEndpoint(config) {
498
- const id = `ep-${this.nextEndpointId}`;
499
- this.nextEndpointId += 1;
500
- this.endpoints.set(id, {
501
- id,
502
- path: config.path,
503
- method: config.method ?? "POST",
504
- secret: config.secret
505
- });
506
- this.emit("endpointRegistered", id);
507
- return id;
508
- }
509
- removeEndpoint(id) {
510
- if (!this.endpoints.delete(id)) throw new Error(`Endpoint ${id} not found`);
511
- this.emit("endpointRemoved", id);
512
- }
513
- listEndpoints() {
514
- return [...this.endpoints.values()].map((endpoint) => ({ ...endpoint }));
515
- }
516
- getPort() {
517
- return this.port;
518
- }
519
- isRunning() {
520
- return this.server !== void 0;
521
- }
522
- registerEvent(event, handler) {
523
- const handlers = this.eventHandlers.get(event) ?? [];
524
- handlers.push(handler);
525
- this.eventHandlers.set(event, handlers);
526
- this.stats.eventsRegistered += 1;
527
- }
528
- start() {
529
- if (this.server) throw new Error("Webhook server already started");
530
- this.server = http.createServer((request, response) => {
531
- this.handleRequest(request, response);
532
- });
533
- this.server.listen(this.port);
534
- this.emit("started", this.port);
535
- }
536
- async stop() {
537
- if (!this.server) return;
538
- const server = this.server;
539
- this.server = void 0;
540
- await new Promise((resolve, reject) => {
541
- server.close((error) => {
542
- if (error) {
543
- reject(error);
544
- return;
545
- }
546
- resolve();
547
- });
548
- });
549
- this.emit("stopped");
550
- }
551
- async sendWebhook(url, event, payload) {
552
- await fetch(url, {
553
- method: "POST",
554
- headers: { "content-type": "application/json" },
555
- body: JSON.stringify({
556
- event,
557
- payload
558
- })
559
- });
560
- this.stats.webhooksSent += 1;
561
- this.stats.lastSentAt = (/* @__PURE__ */ new Date()).toISOString();
562
- }
563
- getStats() {
564
- return { ...this.stats };
565
- }
566
- async handleRequest(request, response) {
567
- const method = request.method ?? "GET";
568
- const url = request.url ?? "/";
569
- const endpoint = [...this.endpoints.values()].find((item) => item.path === url && item.method === method);
570
- if (!endpoint) {
571
- response.statusCode = 404;
572
- response.end("not found");
573
- return;
574
- }
575
- if (endpoint.secret) {
576
- if (request.headers["x-webhook-secret"] !== endpoint.secret) {
577
- response.statusCode = 401;
578
- response.end("unauthorized");
579
- return;
580
- }
581
- }
582
- const chunks = [];
583
- await new Promise((resolve, reject) => {
584
- request.setEncoding("utf8");
585
- request.on("data", (chunk) => {
586
- chunks.push(chunk);
587
- });
588
- request.on("end", () => {
589
- resolve();
590
- });
591
- request.on("error", (error) => {
592
- reject(error);
593
- });
594
- });
595
- const payload = parseJsonBody(chunks.join(""));
596
- if (this.commandQueue) this.commandQueue.enqueue({
597
- endpointId: endpoint.id,
598
- payload
599
- });
600
- if (payload && typeof payload === "object" && "event" in payload && typeof payload.event === "string") await this.invokeEventHandlers(payload.event, payload);
601
- response.setHeader("content-type", "application/json");
602
- response.end(JSON.stringify({
603
- ok: true,
604
- endpointId: endpoint.id
605
- }));
606
- }
607
- async invokeEventHandlers(eventName, payload) {
608
- if (!isWebhookEvent(eventName)) return;
609
- const handlers = this.eventHandlers.get(eventName) ?? [];
610
- for (const handler of handlers) await Promise.resolve(handler(payload));
611
- }
612
- };
613
- var WebhookServer = class extends WebhookServerImpl {};
614
- //#endregion
615
- //#region src/server/domains/extension-registry/handlers.impl.ts
616
- function isRecord(value) {
617
- return value !== null && typeof value === "object" && !Array.isArray(value);
618
- }
619
- function isCallable(value) {
620
- return typeof value === "function";
621
- }
622
- var ExtensionRegistryHandlers = class {
623
- webhookServer;
624
- commandQueue;
625
- constructor(registry, webhook) {
626
- this.registry = registry;
627
- this.webhook = webhook;
628
- }
629
- async handleListInstalled() {
630
- return asJsonResponse({
631
- success: true,
632
- plugins: this.getRegistry().listInstalled()
633
- });
634
- }
635
- async handleExecuteInContext(args) {
636
- const pluginId = argStringRequired(args, "pluginId");
637
- const contextName = argStringRequired(args, "contextName");
638
- const contextArgs = argObject(args, "args") ?? {};
639
- const { manifest, exports } = await this.getRegistry().loadPlugin(pluginId);
640
- const context = this.resolveContext(exports, contextName);
641
- if (!context) throw new Error(`Context "${contextName}" was not found in plugin "${pluginId}"`);
642
- const result = await Promise.resolve(context(contextArgs));
643
- this.emitEvent("extension.executed", {
644
- pluginId,
645
- contextName
646
- });
647
- return asJsonResponse({
648
- success: true,
649
- manifest,
650
- contextName,
651
- result
652
- });
653
- }
654
- async handleReload(args) {
655
- const pluginId = argStringRequired(args, "pluginId");
656
- await this.getRegistry().unloadPlugin(pluginId);
657
- const loaded = await this.getRegistry().loadPlugin(pluginId);
658
- this.emitEvent("extension.reloaded", { pluginId });
659
- return asJsonResponse({
660
- success: true,
661
- pluginId,
662
- manifest: loaded.manifest,
663
- exportedKeys: Object.keys(loaded.exports).toSorted()
664
- });
665
- }
666
- async handleUninstall(args) {
667
- const pluginId = argStringRequired(args, "pluginId");
668
- await this.getRegistry().unregister(pluginId);
669
- this.emitEvent("extension.uninstalled", { pluginId });
670
- return asJsonResponse({
671
- success: true,
672
- pluginId
673
- });
674
- }
675
- async handleWebhookCreate(args) {
676
- const name = argStringRequired(args, "name");
677
- const webhookPath = argStringRequired(args, "path");
678
- const secret = argString(args, "secret");
679
- const events = Array.isArray(args.events) ? args.events.filter((e) => typeof e === "string") : [];
680
- const server = this.getWebhookServer();
681
- if (!server.isRunning()) server.start();
682
- const endpointId = server.registerEndpoint({
683
- path: webhookPath,
684
- method: "POST",
685
- secret: secret ?? void 0
686
- });
687
- const bridge = this.getWebhook();
688
- const baseUrl = `http://localhost:${server.getPort()}${webhookPath}`;
689
- bridge.registerExternalCallback(endpointId, baseUrl);
690
- return asJsonResponse({
691
- success: true,
692
- endpointId,
693
- url: baseUrl,
694
- name,
695
- events
696
- });
697
- }
698
- async handleWebhookList() {
699
- const server = this.getWebhookServer();
700
- return asJsonResponse({
701
- success: true,
702
- endpoints: server.listEndpoints(),
703
- port: server.getPort(),
704
- running: server.isRunning()
705
- });
706
- }
707
- async handleWebhookDelete(args) {
708
- const endpointId = argStringRequired(args, "endpointId");
709
- const server = this.getWebhookServer();
710
- try {
711
- server.removeEndpoint(endpointId);
712
- } catch (err) {
713
- throw new Error(`GRACEFUL: ${err instanceof Error ? err.message : String(err)}`, { cause: err });
714
- }
715
- return asJsonResponse({
716
- success: true,
717
- endpointId
718
- });
719
- }
720
- async handleWebhookCommands(args) {
721
- const endpointId = argStringRequired(args, "endpointId");
722
- const status = argString(args, "status");
723
- const command = argObject(args, "command");
724
- if (command) return asJsonResponse({
725
- success: true,
726
- commandId: this.getCommandQueue().enqueue({
727
- endpointId,
728
- payload: command
729
- }),
730
- status: "pending"
731
- });
732
- const queue = this.getCommandQueue();
733
- const filter = { endpointId };
734
- if (status) filter.status = status;
735
- const commands = queue.dequeue(filter);
736
- return asJsonResponse({
737
- success: true,
738
- endpointId,
739
- commands,
740
- count: Array.isArray(commands) ? commands.length : commands ? 1 : 0
741
- });
742
- }
743
- getWebhookServer() {
744
- if (!this.webhookServer) {
745
- this.commandQueue = new CommandQueue();
746
- this.webhookServer = new WebhookServer({ commandQueue: this.commandQueue });
747
- }
748
- return this.webhookServer;
749
- }
750
- async startWebhookServer() {
751
- const server = this.getWebhookServer();
752
- if (!server.isRunning()) server.start();
753
- }
754
- async stopWebhookServer() {
755
- if (this.webhookServer) {
756
- await this.webhookServer.stop();
757
- this.webhookServer = void 0;
758
- this.commandQueue = void 0;
759
- }
760
- }
761
- getRegistry() {
762
- if (!this.registry) this.registry = new PluginRegistry();
763
- return this.registry;
764
- }
765
- getWebhook() {
766
- if (!this.webhook) this.webhook = new WebhookBridge();
767
- return this.webhook;
768
- }
769
- getCommandQueue() {
770
- if (!this.commandQueue) this.commandQueue = new CommandQueue();
771
- return this.commandQueue;
772
- }
773
- emitEvent(event, payload) {
774
- this.getWebhook().sendEvent(event, payload).catch(() => void 0);
775
- }
776
- resolveContext(exportsRecord, contextName) {
777
- const directContext = exportsRecord[contextName];
778
- if (isCallable(directContext)) return directContext;
779
- const defaultExport = exportsRecord.default;
780
- if (contextName === "default" && isCallable(defaultExport)) return defaultExport;
781
- if (isRecord(defaultExport)) {
782
- const nestedContext = defaultExport[contextName];
783
- if (isCallable(nestedContext)) return nestedContext;
784
- }
785
- return null;
786
- }
787
- async handleWebhookDispatch(args) {
788
- const action = argString(args, "action");
789
- switch (action) {
790
- case "create": return this.handleWebhookCreate(args);
791
- case "list": return this.handleWebhookList();
792
- case "delete": return this.handleWebhookDelete(args);
793
- case "commands": return this.handleWebhookCommands(args);
794
- default: return asJsonResponse({ error: `Invalid action: "${action}". Expected one of: create, list, delete, commands` });
795
- }
796
- }
797
- };
798
- //#endregion
799
- export { ExtensionRegistryHandlers };