@capyclaw/browser-suite 0.1.2 → 0.2.37

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 (217) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +9 -5
  3. package/composition.lock.json +37 -25
  4. package/contract/browser-contract.json +484 -25
  5. package/cordis.patch.yml +3 -9
  6. package/dsh-suite.json +110 -82
  7. package/lib/index.mjs +1 -1
  8. package/node_modules/@capyclaw/asset-service/README.md +48 -0
  9. package/node_modules/@capyclaw/asset-service/cordis.patch.yml +4 -0
  10. package/node_modules/@capyclaw/asset-service/dsh-suite.json +29 -0
  11. package/node_modules/@capyclaw/asset-service/lib/host.mjs +14 -0
  12. package/node_modules/@capyclaw/asset-service/package.json +59 -0
  13. package/node_modules/@capyclaw/asset-service/src/index.mjs +304 -0
  14. package/node_modules/@capyclaw/browser-skill-api/README.md +3 -0
  15. package/node_modules/@capyclaw/browser-skill-api/contract/browser-contract.json +1349 -0
  16. package/node_modules/@capyclaw/browser-skill-api/cordis.patch.yml +4 -0
  17. package/node_modules/@capyclaw/browser-skill-api/package.json +49 -0
  18. package/node_modules/@capyclaw/browser-skill-api/plugin.mjs +15 -0
  19. package/node_modules/@capyclaw/browser-skill-api/skills/browser-api/SKILL.md +85 -0
  20. package/node_modules/@capyclaw/browser-skill-api/skills/browser-api/references/tool-contract.md +692 -0
  21. package/node_modules/@capyclaw/browser-skill-browser/README.md +3 -0
  22. package/node_modules/@capyclaw/browser-skill-browser/contract/browser-contract.json +1349 -0
  23. package/node_modules/@capyclaw/browser-skill-browser/cordis.patch.yml +4 -0
  24. package/node_modules/@capyclaw/browser-skill-browser/package.json +49 -0
  25. package/node_modules/@capyclaw/browser-skill-browser/plugin.mjs +15 -0
  26. package/node_modules/@capyclaw/browser-skill-browser/skills/browser/SKILL.md +27 -0
  27. package/node_modules/@capyclaw/browser-skill-ops/README.md +3 -0
  28. package/node_modules/@capyclaw/browser-skill-ops/contract/browser-contract.json +1349 -0
  29. package/node_modules/@capyclaw/browser-skill-ops/cordis.patch.yml +4 -0
  30. package/node_modules/@capyclaw/browser-skill-ops/package.json +49 -0
  31. package/node_modules/@capyclaw/browser-skill-ops/plugin.mjs +15 -0
  32. package/node_modules/@capyclaw/browser-skill-ops/skills/browser-ops/SKILL.md +63 -0
  33. package/node_modules/@capyclaw/browser-workbench/README.md +89 -0
  34. package/node_modules/@capyclaw/browser-workbench/contract/browser-contract.json +1349 -0
  35. package/node_modules/@capyclaw/browser-workbench/demo/form.html +112 -0
  36. package/node_modules/@capyclaw/browser-workbench/lib/host.mjs +1 -0
  37. package/node_modules/@capyclaw/browser-workbench/package.json +71 -0
  38. package/node_modules/@capyclaw/browser-workbench/plugin.mjs +1 -0
  39. package/node_modules/@capyclaw/browser-workbench/server/constants.mjs +16 -0
  40. package/node_modules/@capyclaw/browser-workbench/server/contract-snapshots.mjs +81 -0
  41. package/node_modules/@capyclaw/browser-workbench/server/contract.mjs +24 -0
  42. package/node_modules/@capyclaw/browser-workbench/server/embedded-host.mjs +247 -0
  43. package/node_modules/@capyclaw/browser-workbench/server/engine.mjs +2466 -0
  44. package/node_modules/@capyclaw/browser-workbench/server/governor.mjs +189 -0
  45. package/node_modules/@capyclaw/browser-workbench/server/http-utils.mjs +2 -0
  46. package/node_modules/@capyclaw/browser-workbench/server/human.mjs +628 -0
  47. package/node_modules/@capyclaw/browser-workbench/server/infra/http.mjs +2 -0
  48. package/node_modules/@capyclaw/browser-workbench/server/infra/tuning.mjs +2 -0
  49. package/node_modules/@capyclaw/browser-workbench/server/input.mjs +154 -0
  50. package/node_modules/@capyclaw/browser-workbench/server/login-vault.mjs +109 -0
  51. package/node_modules/@capyclaw/browser-workbench/server/mcp/handler.mjs +2 -0
  52. package/node_modules/@capyclaw/browser-workbench/server/mcp/instructions.mjs +31 -0
  53. package/node_modules/@capyclaw/browser-workbench/server/orphans.mjs +163 -0
  54. package/node_modules/@capyclaw/browser-workbench/server/relay.mjs +198 -0
  55. package/node_modules/@capyclaw/browser-workbench/server/routes/api.mjs +233 -0
  56. package/node_modules/@capyclaw/browser-workbench/server/routes/assets.mjs +2 -0
  57. package/node_modules/@capyclaw/browser-workbench/server/routes/mcp.mjs +17 -0
  58. package/node_modules/@capyclaw/browser-workbench/server/routes/workbench.mjs +33 -0
  59. package/node_modules/@capyclaw/browser-workbench/server/session-engines.mjs +223 -0
  60. package/node_modules/@capyclaw/browser-workbench/server/shared/SHARED_MANIFEST.json +70 -0
  61. package/node_modules/@capyclaw/browser-workbench/server/shared/asset-service.mjs +2 -0
  62. package/node_modules/@capyclaw/browser-workbench/server/shared/editor-host.mjs +2 -0
  63. package/node_modules/@capyclaw/browser-workbench/server/shared/kit/editor/lease.mjs +2 -0
  64. package/node_modules/@capyclaw/browser-workbench/server/shared/kit/service/api.mjs +2 -0
  65. package/node_modules/@capyclaw/browser-workbench/server/shared/kit/service/http.mjs +2 -0
  66. package/node_modules/@capyclaw/browser-workbench/server/shared/kit/service/mcp-http.mjs +2 -0
  67. package/node_modules/@capyclaw/browser-workbench/server/shared/kit/tools/validate.mjs +2 -0
  68. package/node_modules/@capyclaw/browser-workbench/server/shared/kit/tuning.mjs +2 -0
  69. package/node_modules/@capyclaw/browser-workbench/server/shared/kit/util/fs-lock.mjs +2 -0
  70. package/node_modules/@capyclaw/browser-workbench/server/shared/service-host.mjs +2 -0
  71. package/node_modules/@capyclaw/browser-workbench/server/shared/tool-host.mjs +2 -0
  72. package/node_modules/@capyclaw/browser-workbench/server/shared/tuning.mjs +2 -0
  73. package/node_modules/@capyclaw/browser-workbench/server/tools/capabilities/contract.mjs +55 -0
  74. package/node_modules/@capyclaw/browser-workbench/server/tools/capabilities/evaluate.mjs +36 -0
  75. package/node_modules/@capyclaw/browser-workbench/server/tools/capabilities/index.mjs +26 -0
  76. package/node_modules/@capyclaw/browser-workbench/server/tools/capabilities/interaction.mjs +215 -0
  77. package/node_modules/@capyclaw/browser-workbench/server/tools/capabilities/navigation.mjs +35 -0
  78. package/node_modules/@capyclaw/browser-workbench/server/tools/capabilities/screenshot.mjs +50 -0
  79. package/node_modules/@capyclaw/browser-workbench/server/tools/capabilities/session.mjs +81 -0
  80. package/node_modules/@capyclaw/browser-workbench/server/tools/capabilities/snapshot.mjs +30 -0
  81. package/node_modules/@capyclaw/browser-workbench/server/tools/capabilities/tabs.mjs +35 -0
  82. package/node_modules/@capyclaw/browser-workbench/server/tools/index.mjs +12 -0
  83. package/node_modules/@capyclaw/browser-workbench/server/tools/kernel/define.mjs +5 -0
  84. package/node_modules/@capyclaw/browser-workbench/server/tools/kernel/output.mjs +30 -0
  85. package/node_modules/@capyclaw/browser-workbench/server/tools/kernel/ports.mjs +59 -0
  86. package/node_modules/@capyclaw/browser-workbench/server/tools/kernel/registry.mjs +17 -0
  87. package/node_modules/@capyclaw/browser-workbench/server/tools.mjs +3 -0
  88. package/node_modules/@capyclaw/browser-workbench/server/workbench-framework.mjs +305 -0
  89. package/node_modules/@capyclaw/browser-workbench/ui/app.js +447 -0
  90. package/node_modules/@capyclaw/browser-workbench/ui/index.html +46 -0
  91. package/node_modules/@capyclaw/browser-workbench/ui/style.css +144 -0
  92. package/node_modules/@capyclaw/document-workbench/README.md +125 -0
  93. package/node_modules/@capyclaw/document-workbench/package.json +44 -0
  94. package/node_modules/@capyclaw/document-workbench/src/bridge/index.mjs +321 -0
  95. package/node_modules/@capyclaw/document-workbench/src/client/index.mjs +625 -0
  96. package/node_modules/@capyclaw/document-workbench/src/client/screenshot.mjs +98 -0
  97. package/node_modules/@capyclaw/document-workbench/src/index.mjs +9 -0
  98. package/node_modules/@capyclaw/document-workbench/src/model/audit.mjs +101 -0
  99. package/node_modules/@capyclaw/document-workbench/src/model/conformance.mjs +92 -0
  100. package/node_modules/@capyclaw/document-workbench/src/model/ids.mjs +56 -0
  101. package/node_modules/@capyclaw/document-workbench/src/model/index.mjs +18 -0
  102. package/node_modules/@capyclaw/document-workbench/src/model/locate.mjs +118 -0
  103. package/node_modules/@capyclaw/document-workbench/src/model/manifest.mjs +148 -0
  104. package/node_modules/@capyclaw/document-workbench/src/model/ops.mjs +160 -0
  105. package/node_modules/@capyclaw/document-workbench/src/model/validate.mjs +72 -0
  106. package/node_modules/@capyclaw/document-workbench/src/ops/index.mjs +93 -0
  107. package/node_modules/@capyclaw/document-workbench/src/session/context.mjs +103 -0
  108. package/node_modules/@capyclaw/document-workbench/src/session/index.mjs +394 -0
  109. package/node_modules/@capyclaw/document-workbench/src/session/lease.mjs +105 -0
  110. package/node_modules/@capyclaw/document-workbench/src/session/mode.mjs +80 -0
  111. package/node_modules/@capyclaw/document-workbench/src/session/sanitize.mjs +107 -0
  112. package/node_modules/@capyclaw/document-workbench/src/session/state.mjs +159 -0
  113. package/node_modules/@capyclaw/document-workbench/src/session/watch.mjs +63 -0
  114. package/node_modules/@capyclaw/document-workbench/src/store/file-backend.mjs +158 -0
  115. package/node_modules/@capyclaw/document-workbench/src/testing/index.mjs +75 -0
  116. package/node_modules/@capyclaw/foundation/README.md +51 -0
  117. package/node_modules/@capyclaw/foundation/abi/bridge.mjs +86 -0
  118. package/node_modules/@capyclaw/foundation/abi/errors.mjs +63 -0
  119. package/node_modules/@capyclaw/foundation/abi/index.mjs +35 -0
  120. package/node_modules/@capyclaw/foundation/abi/kinds.mjs +271 -0
  121. package/node_modules/@capyclaw/foundation/abi/loader.mjs +345 -0
  122. package/node_modules/@capyclaw/foundation/abi/schema.mjs +98 -0
  123. package/node_modules/@capyclaw/foundation/abi/spec.mjs +255 -0
  124. package/node_modules/@capyclaw/foundation/abi/validate.mjs +24 -0
  125. package/node_modules/@capyclaw/foundation/abi/version.mjs +82 -0
  126. package/node_modules/@capyclaw/foundation/cordis.patch.yml +5 -0
  127. package/node_modules/@capyclaw/foundation/kit/index.mjs +6 -0
  128. package/node_modules/@capyclaw/foundation/lib/adapters/client-panel.mjs +98 -0
  129. package/node_modules/@capyclaw/foundation/lib/adapters/host-event.mjs +35 -0
  130. package/node_modules/@capyclaw/foundation/lib/adapters/http-router.mjs +69 -0
  131. package/node_modules/@capyclaw/foundation/lib/adapters/lifecycle-hook.mjs +55 -0
  132. package/node_modules/@capyclaw/foundation/lib/adapters/own-server.mjs +113 -0
  133. package/node_modules/@capyclaw/foundation/lib/adapters/raw.mjs +69 -0
  134. package/node_modules/@capyclaw/foundation/lib/adapters/runtime-driver.mjs +120 -0
  135. package/node_modules/@capyclaw/foundation/lib/adapters/service-provider.mjs +77 -0
  136. package/node_modules/@capyclaw/foundation/lib/adapters/skill-provider.mjs +56 -0
  137. package/node_modules/@capyclaw/foundation/lib/adapters/tool-provider.mjs +50 -0
  138. package/node_modules/@capyclaw/foundation/lib/adapters/ui-panel.mjs +64 -0
  139. package/node_modules/@capyclaw/foundation/lib/ctx-service.mjs +42 -0
  140. package/node_modules/@capyclaw/foundation/lib/host/caps.mjs +34 -0
  141. package/node_modules/@capyclaw/foundation/lib/host/contract.mjs +85 -0
  142. package/node_modules/@capyclaw/foundation/lib/host/dsh.mjs +50 -0
  143. package/node_modules/@capyclaw/foundation/lib/host/memory.mjs +160 -0
  144. package/node_modules/@capyclaw/foundation/lib/host.mjs +23 -0
  145. package/node_modules/@capyclaw/foundation/lib/kernel.mjs +185 -0
  146. package/node_modules/@capyclaw/foundation/lib/skill/scan.mjs +115 -0
  147. package/node_modules/@capyclaw/foundation/lib/subsystems/events.mjs +60 -0
  148. package/node_modules/@capyclaw/foundation/lib/subsystems/log.mjs +51 -0
  149. package/node_modules/@capyclaw/foundation/lib/subsystems/net.mjs +188 -0
  150. package/node_modules/@capyclaw/foundation/package.json +53 -0
  151. package/node_modules/@capyclaw/foundation/runtime/index.mjs +20 -0
  152. package/node_modules/@capyclaw/plugin-kit/INTEGRATION.md +100 -0
  153. package/node_modules/@capyclaw/plugin-kit/README.md +70 -0
  154. package/node_modules/@capyclaw/plugin-kit/bin/sync.mjs +103 -0
  155. package/node_modules/@capyclaw/plugin-kit/package.json +69 -0
  156. package/node_modules/@capyclaw/plugin-kit/src/cli.mjs +56 -0
  157. package/node_modules/@capyclaw/plugin-kit/src/config.mjs +142 -0
  158. package/node_modules/@capyclaw/plugin-kit/src/editor/heartbeat-worker.js +129 -0
  159. package/node_modules/@capyclaw/plugin-kit/src/editor/lease.mjs +139 -0
  160. package/node_modules/@capyclaw/plugin-kit/src/editor/shadow.mjs +219 -0
  161. package/node_modules/@capyclaw/plugin-kit/src/editor/transport.js +13 -0
  162. package/node_modules/@capyclaw/plugin-kit/src/index.mjs +13 -0
  163. package/node_modules/@capyclaw/plugin-kit/src/pack.mjs +230 -0
  164. package/node_modules/@capyclaw/plugin-kit/src/runtime/context.mjs +128 -0
  165. package/node_modules/@capyclaw/plugin-kit/src/self-contained.mjs +307 -0
  166. package/node_modules/@capyclaw/plugin-kit/src/service/api.mjs +45 -0
  167. package/node_modules/@capyclaw/plugin-kit/src/service/http.mjs +113 -0
  168. package/node_modules/@capyclaw/plugin-kit/src/service/mcp-http.mjs +150 -0
  169. package/node_modules/@capyclaw/plugin-kit/src/service/server.mjs +131 -0
  170. package/node_modules/@capyclaw/plugin-kit/src/skills/provider.mjs +82 -0
  171. package/node_modules/@capyclaw/plugin-kit/src/store/blob-store.mjs +109 -0
  172. package/node_modules/@capyclaw/plugin-kit/src/store/content-store.mjs +17 -0
  173. package/node_modules/@capyclaw/plugin-kit/src/store/journal-store.mjs +89 -0
  174. package/node_modules/@capyclaw/plugin-kit/src/tools/result.mjs +57 -0
  175. package/node_modules/@capyclaw/plugin-kit/src/tools/validate.mjs +150 -0
  176. package/node_modules/@capyclaw/plugin-kit/src/tuning.mjs +82 -0
  177. package/node_modules/@capyclaw/plugin-kit/src/util/fs-lock.mjs +132 -0
  178. package/node_modules/@capyclaw/plugin-kit/src/util/http.mjs +130 -0
  179. package/node_modules/@capyclaw/plugin-kit/src/workspace/manager.mjs +656 -0
  180. package/node_modules/@capyclaw/plugin-kit/src/zip.mjs +181 -0
  181. package/node_modules/@capyclaw/portal/README.md +70 -0
  182. package/node_modules/@capyclaw/portal/lib/index.mjs +387 -0
  183. package/node_modules/@capyclaw/portal/lib/ledger.mjs +194 -0
  184. package/node_modules/@capyclaw/portal/lib/portal-agent.ps1 +811 -0
  185. package/node_modules/@capyclaw/portal/lib/portal-darwin.mjs +183 -0
  186. package/node_modules/@capyclaw/portal/package.json +40 -0
  187. package/node_modules/@capyclaw/service-broker/README.md +104 -0
  188. package/node_modules/@capyclaw/service-broker/cordis.patch.yml +8 -0
  189. package/node_modules/@capyclaw/service-broker/dsh-suite.json +21 -0
  190. package/node_modules/@capyclaw/service-broker/lib/control.mjs +193 -0
  191. package/node_modules/@capyclaw/service-broker/lib/discovery.mjs +109 -0
  192. package/node_modules/@capyclaw/service-broker/lib/engine.mjs +1236 -0
  193. package/node_modules/@capyclaw/service-broker/lib/host.mjs +182 -0
  194. package/node_modules/@capyclaw/service-broker/lib/manifest.mjs +249 -0
  195. package/node_modules/@capyclaw/service-broker/lib/recovery.mjs +325 -0
  196. package/node_modules/@capyclaw/service-broker/lib/skills-client.mjs +28 -0
  197. package/node_modules/@capyclaw/service-broker/lib/spec.mjs +78 -0
  198. package/node_modules/@capyclaw/service-broker/package.json +65 -0
  199. package/node_modules/@capyclaw/service-broker/server.mjs +81 -0
  200. package/node_modules/@capyclaw/service-broker/service.schema.json +62 -0
  201. package/node_modules/@capyclaw/service-broker/services.json +3 -0
  202. package/node_modules/@capyclaw/service-host/README.md +86 -0
  203. package/node_modules/@capyclaw/service-host/cordis.patch.yml +4 -0
  204. package/node_modules/@capyclaw/service-host/dsh-suite.json +29 -0
  205. package/node_modules/@capyclaw/service-host/lib/host.mjs +22 -0
  206. package/node_modules/@capyclaw/service-host/package.json +60 -0
  207. package/node_modules/@capyclaw/service-host/src/index.mjs +571 -0
  208. package/node_modules/@capyclaw/service-host/src/tuning.mjs +63 -0
  209. package/node_modules/@capyclaw/tool-host/README.md +56 -0
  210. package/node_modules/@capyclaw/tool-host/cordis.patch.yml +4 -0
  211. package/node_modules/@capyclaw/tool-host/dsh-suite.json +30 -0
  212. package/node_modules/@capyclaw/tool-host/lib/host.mjs +16 -0
  213. package/node_modules/@capyclaw/tool-host/package.json +59 -0
  214. package/node_modules/@capyclaw/tool-host/src/descriptors.mjs +166 -0
  215. package/node_modules/@capyclaw/tool-host/src/index.mjs +416 -0
  216. package/package.json +31 -14
  217. package/services.json +1 -21
@@ -0,0 +1,307 @@
1
+ /**
2
+ * 自包含打包(vendoring)—— 全流水线唯一实现。
3
+ *
4
+ * 背景:本仓的插件既要走 **zip 分发**(dist/plugins/*.zip),也要走 **npm 分发**
5
+ * (`dsh plugin add @capyclaw/xxx`)。两条通道的「自包含」语义此前不一致:
6
+ *
7
+ * - zip 通道:plugin-kit 的 packPlugin 会保留 node_modules,产物自带成员 → 自包含;
8
+ * - npm 通道:`npm pack` / `npm publish` **默认剥离 node_modules**,只有包内
9
+ * `bundledDependencies` 列出的依赖才会被打进 tarball → 不自包含。
10
+ *
11
+ * 结果:同一个包,zip 装完是自包含的,npm 装完却要回头去 registry 逐个解析依赖。
12
+ * 用户侧表现为「明明包里带了 skill,换个机器 npm 装出来却还要联网拉一堆东西」。
13
+ *
14
+ * 本模块把 npm 语义收敛到与 zip 一致:给定一个 staging 目录,
15
+ * 1. 从根 package.json 的 dependencies 出发求**传递闭包**;
16
+ * 2. 闭包里每个包都解析到实体目录并拷进 `<staging>/node_modules/`;
17
+ * 3. 把闭包写进根 package.json 的 `bundledDependencies`。
18
+ *
19
+ * 三条约束(实测 npm 行为,见 scripts/test 里的用例):
20
+ * - `bundledDependencies` 会**覆盖** `files` 白名单:列出的包一定进 tarball;
21
+ * - 不在 bundledDependencies 里的 node_modules 目录会被**剥离**;
22
+ * - 必须同时满足「在 bundledDependencies 里」且「在依赖图可达」两个条件,
23
+ * 否则 npm 会丢弃(孤立的 pako 实验即此)。故闭包口径 = 可达 ∩ 有实体。
24
+ *
25
+ * `files` 不需要改:npm 对 bundledDependencies 另有通道。
26
+ * `dependencies` 也不要删:bundledDependencies 要求包在依赖图里可达。
27
+ */
28
+ import fs from 'node:fs'
29
+ import path from 'node:path'
30
+
31
+ /** 拷贝依赖时跳过的目录(运行时状态、VCS、测试与非分发内容)。
32
+ * 注意:**不能跳 `dist`**。我们自己的包把源码放 src/,但第三方依赖常常只有 dist/
33
+ * (pptxgenjs 的 main 就是 `dist/pptxgen.cjs.js`)——跳过它等于把依赖拷成一个空壳,
34
+ * 装出来的包里 `ppt_export_pptx` 会报「没有安装 pptxgenjs」,而目录明明存在。 */
35
+ const VENDOR_SKIP_DIRS = new Set([
36
+ 'node_modules', '.git', '.github', 'test', 'tests', '__tests__',
37
+ 'coverage', '.host', '__pycache__', '.cache', '.temp-pack',
38
+ ])
39
+
40
+ function readJson(file) {
41
+ return JSON.parse(fs.readFileSync(file, 'utf8'))
42
+ }
43
+
44
+ function hasPackage(dir) {
45
+ return Boolean(dir) && fs.existsSync(path.join(dir, 'package.json'))
46
+ }
47
+
48
+ /**
49
+ * 目录里的包是否**真的可用**:package.json 声明的入口文件必须存在。
50
+ *
51
+ * 为什么不能只看 package.json:曾经 `dist` 被当成「非分发内容」跳过,
52
+ * 于是 pptxgenjs 拷进来只有 package.json + types,`hasPackage()` 为真、
53
+ * 拼装闸放行,安装后 `import('pptxgenjs')` 才炸。空壳包必须能被识别出来重拷。
54
+ */
55
+ export function isUsablePackage(dir) {
56
+ if (!hasPackage(dir)) return false
57
+ let pkg
58
+ try { pkg = readJson(path.join(dir, 'package.json')) } catch { return false }
59
+ const entries = []
60
+ const exportsField = pkg.exports
61
+ if (typeof exportsField === 'string') entries.push(exportsField)
62
+ else if (exportsField && typeof exportsField === 'object') {
63
+ const root = exportsField['.'] ?? exportsField
64
+ if (typeof root === 'string') entries.push(root)
65
+ else if (root && typeof root === 'object') {
66
+ for (const value of Object.values(root)) {
67
+ if (typeof value === 'string') entries.push(value)
68
+ else if (value && typeof value === 'object') {
69
+ for (const deep of Object.values(value)) if (typeof deep === 'string') entries.push(deep)
70
+ }
71
+ }
72
+ }
73
+ }
74
+ if (typeof pkg.main === 'string') entries.push(pkg.main)
75
+ if (typeof pkg.module === 'string') entries.push(pkg.module)
76
+ /* 没有入口声明(纯资源包):只要目录里有文件就算可用。 */
77
+ if (!entries.length) {
78
+ try {
79
+ return fs.readdirSync(dir).some((name) => name !== 'package.json')
80
+ } catch { return false }
81
+ }
82
+ return entries.some((rel) => fs.existsSync(path.join(dir, rel.replace(/^\.\//, ''))))
83
+ }
84
+
85
+ /**
86
+ * 工作区包解析器:按本仓布局把包名解析到实体目录。
87
+ *
88
+ * 查找顺序(先近后远,staging 内已有的优先,避免重复劳动):
89
+ * 1. `<staging>/node_modules/<name>` —— 已拼装/已 vendor 的成员
90
+ * 2. `<root>/node_modules/<name>` —— 仓库已安装的第三方依赖与 workspace 链接
91
+ * 3. `<root>/packages/<dir名>` —— 公共基建包
92
+ * 4. `<root>/B/official/<dir名>`
93
+ * 5. `<root>/projects/<项目>/artifacts/plugin/<dir名>` —— 各项目的构建产物
94
+ *
95
+ * `@scope/name` → 目录名候选 `@scope/name` 与 `scope-name` 两种形态都试。
96
+ */
97
+ export function createWorkspaceResolver({ root, stagingDir }) {
98
+ const dirNameCandidates = (name) => {
99
+ const out = new Set([name])
100
+ if (name.startsWith('@') && name.includes('/')) {
101
+ const [scope, base] = name.slice(1).split('/')
102
+ out.add(`${scope}-${base}`)
103
+ out.add(base)
104
+ }
105
+ return [...out]
106
+ }
107
+
108
+ /** 项目产物目录:projects/<任意>/artifacts/plugin。 */
109
+ const projectArtifactDirs = () => {
110
+ const out = []
111
+ const projectsDir = path.join(root, 'A/projects')
112
+ let projects = []
113
+ try { projects = fs.readdirSync(projectsDir, { withFileTypes: true }) } catch { return out }
114
+ for (const entry of projects) {
115
+ if (!entry.isDirectory()) continue
116
+ out.push(path.join(projectsDir, entry.name, 'artifacts', 'plugin'))
117
+ }
118
+ return out
119
+ }
120
+
121
+ return function resolve(name) {
122
+ for (const candidate of dirNameCandidates(name)) {
123
+ const direct = [
124
+ path.join(stagingDir, 'node_modules', candidate),
125
+ path.join(root, 'node_modules', candidate),
126
+ path.join(root, 'C/packages', candidate),
127
+ path.join(root, 'B', 'official', candidate),
128
+ ]
129
+ for (const dir of direct) {
130
+ if (hasPackage(dir)) return dir
131
+ }
132
+ for (const base of projectArtifactDirs()) {
133
+ const dir = path.join(base, candidate)
134
+ if (hasPackage(dir)) return dir
135
+ }
136
+ }
137
+ return null
138
+ }
139
+ }
140
+
141
+ /**
142
+ * 从根 package.json 求**可达依赖闭包**,并标注每个包是否已有实体。
143
+ *
144
+ * @returns {{names:string[], present:string[], missing:string[]}}
145
+ */
146
+ export function computeDependencyClosure(pkg, resolve) {
147
+ const present = []
148
+ const missing = []
149
+ const seen = new Set()
150
+ const queue = [
151
+ ...Object.keys(pkg.dependencies || {}),
152
+ ...Object.keys(pkg.optionalDependencies || {}),
153
+ ]
154
+
155
+ while (queue.length) {
156
+ const name = queue.shift()
157
+ if (seen.has(name)) continue
158
+ seen.add(name)
159
+
160
+ const dir = resolve(name)
161
+ if (!dir) { missing.push(name); continue }
162
+
163
+ present.push(name)
164
+ let depPkg = {}
165
+ try { depPkg = readJson(path.join(dir, 'package.json')) } catch { /* 坏清单:仍保留实体,不阻断 */ }
166
+ for (const dep of Object.keys(depPkg.dependencies || {})) {
167
+ if (!seen.has(dep)) queue.push(dep)
168
+ }
169
+ for (const dep of Object.keys(depPkg.optionalDependencies || {})) {
170
+ if (!seen.has(dep)) queue.push(dep)
171
+ }
172
+ /* peerDependencies 不作为传递展开项:npm 语义里 peer 由上层提供,
173
+ * 但若上层确实装了实体,它已在 dependencies 链路里;不额外强拉。 */
174
+ }
175
+
176
+ return { names: [...seen].sort(), present: present.sort(), missing: [...new Set(missing)].sort() }
177
+ }
178
+
179
+ /** 把目录内容递归拷到目标(跳过 VENDOR_SKIP_DIRS)。返回拷贝的文件数。 */
180
+ export function copyDirContents(srcDir, destDir) {
181
+ let count = 0
182
+ const walk = (from, to) => {
183
+ for (const entry of fs.readdirSync(from, { withFileTypes: true })) {
184
+ if (VENDOR_SKIP_DIRS.has(entry.name)) continue
185
+ const s = path.join(from, entry.name)
186
+ const d = path.join(to, entry.name)
187
+ if (entry.isDirectory()) {
188
+ fs.mkdirSync(d, { recursive: true })
189
+ walk(s, d)
190
+ } else if (entry.isFile()) {
191
+ fs.mkdirSync(path.dirname(d), { recursive: true })
192
+ fs.copyFileSync(s, d)
193
+ count++
194
+ }
195
+ }
196
+ }
197
+ walk(srcDir, destDir)
198
+ return count
199
+ }
200
+
201
+ /** 覆写根 package.json 的 bundledDependencies(数组已排序、去重)。 */
202
+ export function writeBundledDependencies(pkgFile, names) {
203
+ const pkg = readJson(pkgFile)
204
+ const unique = [...new Set(names)].sort()
205
+ pkg.bundledDependencies = unique
206
+ fs.writeFileSync(pkgFile, `${JSON.stringify(pkg, null, 2)}\n`)
207
+ return unique
208
+ }
209
+
210
+ /**
211
+ * 让一个 staging 目录变成自包含包。
212
+ *
213
+ * 幂等:已存在于 `<staging>/node_modules/<name>` 的包不会被重复拷贝,
214
+ * 因此对 C 段拼装产物(成员已就位)调用只是补第三方依赖 + 写清单。
215
+ *
216
+ * @param {{stagingDir:string, root:string, verbose?:boolean}} options
217
+ * @returns {{bundled:string[], missing:string[], copied:number}}
218
+ */
219
+ export function makeSelfContained({ stagingDir, root, verbose = false }) {
220
+ const pkgFile = path.join(stagingDir, 'package.json')
221
+ if (!fs.existsSync(pkgFile)) throw new Error(`自包含打包缺少 package.json: ${stagingDir}`)
222
+
223
+ const pkg = readJson(pkgFile)
224
+ const resolve = createWorkspaceResolver({ root, stagingDir })
225
+ const closure = computeDependencyClosure(pkg, resolve)
226
+
227
+ const modulesDir = path.join(stagingDir, 'node_modules')
228
+ /* 重拷空壳时不能再解析到 staging 自己(解析器优先 staging,删掉后就 ENOENT)。 */
229
+ const resolveOutside = createWorkspaceResolver({ root, stagingDir: path.join(stagingDir, '__not_a_staging__') })
230
+ let copied = 0
231
+ let repaired = 0
232
+ for (const name of closure.present) {
233
+ const dest = path.join(modulesDir, name)
234
+ /* 已存在且入口完整 → 跳过;存在但缺入口(历史空壳)→ 删掉重拷。 */
235
+ if (isUsablePackage(dest)) continue
236
+ let src = resolve(name)
237
+ if (hasPackage(dest)) {
238
+ fs.rmSync(dest, { recursive: true, force: true })
239
+ repaired++
240
+ if (verbose) console.log(` ~ 重拷空壳依赖 ${name}`)
241
+ src = resolveOutside(name)
242
+ }
243
+ if (!src) continue
244
+ copied += copyDirContents(src, dest)
245
+ if (verbose) console.log(` + vendor ${name} ← ${path.relative(root, src).replace(/\\/g, '/')}`)
246
+ }
247
+
248
+ const bundled = writeBundledDependencies(pkgFile, closure.present)
249
+ return { bundled, missing: closure.missing, copied, repaired }
250
+ }
251
+
252
+ /**
253
+ * 校验闸:给定 staging 目录,断言它「自包含」——
254
+ * 根依赖闭包里每个包都能在**包内** node_modules 解析到实体,
255
+ * 且 bundledDependencies 与之一致。返回错误数组(空数组 = 通过)。
256
+ */
257
+ export function selfContainedErrors({ stagingDir, root }) {
258
+ const errors = []
259
+ const pkgFile = path.join(stagingDir, 'package.json')
260
+ if (!fs.existsSync(pkgFile)) return [`缺少 package.json: ${stagingDir}`]
261
+ const pkg = readJson(pkgFile)
262
+
263
+ const declared = Array.isArray(pkg.bundledDependencies)
264
+ ? pkg.bundledDependencies
265
+ : Array.isArray(pkg.bundleDependencies) ? pkg.bundleDependencies : []
266
+
267
+ const declaredDeps = Object.keys(pkg.dependencies || {})
268
+ if (!declaredDeps.length) return [] // 无运行时依赖:天然自包含
269
+
270
+ if (!declared.length) {
271
+ errors.push('缺少 bundledDependencies:npm/pnpm 打包会剥离 node_modules,安装后需回 registry 逐个解析')
272
+ return errors
273
+ }
274
+
275
+ /* 包内实体必须齐:这是「解压即用」的硬条件。
276
+ * 注意要查**整个闭包**而非只有直接依赖——传递依赖缺一个,安装后照样要联网。
277
+ * 解析器会回退到仓库根目录,所以这里必须显式只看包内 node_modules。 */
278
+ const resolve = createWorkspaceResolver({ root, stagingDir })
279
+ const closure = computeDependencyClosure(pkg, resolve)
280
+ if (closure.missing.length) {
281
+ errors.push(`依赖闭包无法解析到实体(会迫使安装侧联网): ${closure.missing.join(', ')}`)
282
+ }
283
+
284
+ const missingInPackage = closure.present.filter(
285
+ (name) => !hasPackage(path.join(stagingDir, 'node_modules', name)),
286
+ )
287
+ if (missingInPackage.length) {
288
+ errors.push(`依赖未随包携带(安装后需从 registry 拉取): ${missingInPackage.join(', ')}`)
289
+ }
290
+
291
+ /* 有目录但没入口 = 空壳:比缺目录更隐蔽,必须单独报。 */
292
+ const hollow = closure.present.filter((name) => {
293
+ const dir = path.join(stagingDir, 'node_modules', name)
294
+ return hasPackage(dir) && !isUsablePackage(dir)
295
+ })
296
+ if (hollow.length) {
297
+ errors.push(`依赖是空壳(package.json 在、入口文件缺): ${hollow.join(', ')}`)
298
+ }
299
+
300
+ /* bundledDependencies 必须覆盖闭包。 */
301
+ const notBundled = closure.present.filter((name) => !declared.includes(name))
302
+ if (notBundled.length) {
303
+ errors.push(`传递依赖未列入 bundledDependencies(npm 会丢弃): ${notBundled.join(', ')}`)
304
+ }
305
+
306
+ return errors
307
+ }
@@ -0,0 +1,45 @@
1
+ /** 公共服务 API 契约:插件之间只通过这份描述判断兼容性。 */
2
+
3
+ /**
4
+ * @param {string} name 服务名(ctx.<name>)
5
+ * @param {string} version API 版本(semver;major 变化 = 不兼容)
6
+ * @param {string[]} capabilities 能力标签
7
+ */
8
+ export function createServiceApi(name, version = '1.0.0', capabilities = []) {
9
+ if (!name) throw new Error('createServiceApi 需要 name')
10
+ return Object.freeze({
11
+ name,
12
+ version,
13
+ capabilities: Object.freeze([...capabilities]),
14
+ })
15
+ }
16
+
17
+ /**
18
+ * 断言一个已注入的服务对象满足消费者要求。
19
+ * 缺失服务或 major 不一致时抛出明确错误,避免“看起来能跑”的静默不兼容。
20
+ * @param {object} service
21
+ * @param {{ name: string, major?: number|string, version?: string }} expected
22
+ */
23
+ export function assertServiceApi(service, expected = {}) {
24
+ const name = expected.name
25
+ if (!name) throw new Error('assertServiceApi 需要 expected.name')
26
+ const major = String(expected.major ?? String(expected.version || '1').split('.')[0])
27
+ if (!service) throw new Error(`缺少公共服务: ctx.${name}`)
28
+ const api = service.api
29
+ if (!api || typeof api !== 'object') {
30
+ throw new Error(`服务 ctx.${name} 没有声明 api 契约;请升级提供方插件`)
31
+ }
32
+ if (api.name !== name) {
33
+ throw new Error(`服务 ctx.${name} 的 api.name=${api.name},与消费者期望的 ${name} 不一致`)
34
+ }
35
+ const gotMajor = String(api.version || '').split('.')[0]
36
+ if (gotMajor !== major) {
37
+ throw new Error(`服务 ctx.${name} API major=${gotMajor},消费者要求 major=${major}(提供方版本 ${api.version})`)
38
+ }
39
+ return api
40
+ }
41
+
42
+ export function serviceApiSummary(service) {
43
+ const api = service?.api
44
+ return api ? { name: api.name, version: api.version, capabilities: [...(api.capabilities || [])] } : null
45
+ }
@@ -0,0 +1,113 @@
1
+ /** 本机插件 HTTP 传输:安全响应头、body 上限、查询解析、loopback 监听。 */
2
+ import http from 'node:http'
3
+ import { tuning } from '../tuning.mjs'
4
+
5
+ export const SECURITY_HEADERS = {
6
+ 'x-content-type-options': 'nosniff',
7
+ 'referrer-policy': 'no-referrer',
8
+ 'cache-control': 'no-store, no-cache, must-revalidate',
9
+ }
10
+
11
+ /** 客户端已断开时放弃写入:长请求(截图/长轮询)在 handler 完成前客户端超时
12
+ * 断连是常态,写已销毁的 socket 会触发无人监听的 'error' 事件打崩进程。 */
13
+ function resDead(res) {
14
+ return res.destroyed || res.writableEnded
15
+ }
16
+
17
+ export function send(req, res, code, obj, extraHeaders = {}) {
18
+ if (resDead(res)) return
19
+ const body = obj === undefined ? '' : JSON.stringify(obj)
20
+ try {
21
+ res.writeHead(code, {
22
+ 'content-type': 'application/json',
23
+ 'content-length': Buffer.byteLength(body),
24
+ ...SECURITY_HEADERS,
25
+ ...extraHeaders,
26
+ })
27
+ res.end(req.method === 'HEAD' ? undefined : body)
28
+ } catch { /* socket 已死:响应无人接收,静默放弃 */ }
29
+ }
30
+
31
+ export function sendText(req, res, code, text, contentType = 'text/plain; charset=utf-8', extraHeaders = {}) {
32
+ if (resDead(res)) return
33
+ const body = text === undefined || text === null ? '' : String(text)
34
+ try {
35
+ res.writeHead(code, {
36
+ 'content-type': contentType,
37
+ 'content-length': Buffer.byteLength(body),
38
+ ...SECURITY_HEADERS,
39
+ ...extraHeaders,
40
+ })
41
+ res.end(req.method === 'HEAD' ? undefined : body)
42
+ } catch { /* socket 已死:响应无人接收,静默放弃 */ }
43
+ }
44
+
45
+ function bodyError(code, message) {
46
+ const error = new Error(message)
47
+ error.code = code
48
+ return error
49
+ }
50
+
51
+ export function readBody(req, limit = 10 * 1024 * 1024) {
52
+ return new Promise((resolve, reject) => {
53
+ let size = 0
54
+ const chunks = []
55
+ let settled = false
56
+ const fail = (error) => {
57
+ if (settled) return
58
+ settled = true
59
+ reject(error)
60
+ }
61
+ req.on('data', (chunk) => {
62
+ if (settled) return
63
+ size += chunk.length
64
+ if (size > limit) {
65
+ /* 先让路由回 413;立即 destroy 会让客户端只看到 connection reset。 */
66
+ fail(bodyError('BODY_TOO_LARGE', 'body too large'))
67
+ req.resume()
68
+ return
69
+ }
70
+ chunks.push(chunk)
71
+ })
72
+ req.on('end', () => {
73
+ if (settled) return
74
+ settled = true
75
+ const raw = Buffer.concat(chunks).toString('utf8')
76
+ if (!raw) return resolve({})
77
+ try { resolve(JSON.parse(raw)) } catch { reject(bodyError('BAD_JSON', 'bad json')) }
78
+ })
79
+ req.on('error', (error) => fail(error))
80
+ /* 客户端中途断连且未触发 error/aborted 时(如 curl -m 超时),close 兜底,
81
+ 否则 promise 永远 pending,handler 泄漏。 */
82
+ req.on('close', () => {
83
+ if (!req.readableEnded) fail(bodyError('CLIENT_ABORTED', 'client aborted'))
84
+ })
85
+ })
86
+ }
87
+
88
+ export function intQ(url, name) {
89
+ const value = parseInt(url.searchParams.get(name) || '0', 10)
90
+ return Number.isFinite(value) && value >= 0 ? value : 0
91
+ }
92
+
93
+ export function listen(port, opts = {}) {
94
+ const defaults = tuning()
95
+ const {
96
+ host = '127.0.0.1',
97
+ requestTimeoutMs = defaults.requestTimeoutMs,
98
+ headersTimeoutMs = defaults.headersTimeoutMs,
99
+ keepAliveTimeoutMs = defaults.keepAliveTimeoutMs,
100
+ handler,
101
+ } = opts
102
+ return new Promise((resolve, reject) => {
103
+ const server = handler ? http.createServer(handler) : http.createServer()
104
+ server.requestTimeout = requestTimeoutMs
105
+ server.headersTimeout = headersTimeoutMs
106
+ server.keepAliveTimeout = keepAliveTimeoutMs
107
+ server.on('clientError', (error, socket) => {
108
+ if (socket.writable) socket.end('HTTP/1.1 400 Bad Request\r\n\r\n')
109
+ })
110
+ server.on('error', reject)
111
+ server.listen(port, host, () => resolve(server))
112
+ })
113
+ }
@@ -0,0 +1,150 @@
1
+ /**
2
+ * 通用 MCP Streamable HTTP 处理器。
3
+ *
4
+ * 只实现工具面所需的最小协议:initialize / ping / tools/list / tools/call。
5
+ * 所有工具调用在进入业务实现前先经过 validateToolArguments。
6
+ */
7
+ import { readBody, send } from './http.mjs'
8
+ import { validateToolArguments } from '../tools/validate.mjs'
9
+ import { normalizeToolResult } from '../tools/result.mjs'
10
+
11
+ const DEFAULT_PROTOCOL = '2024-11-05'
12
+
13
+ function rpcError(id, code, message, data) {
14
+ const error = { code, message }
15
+ if (data !== undefined) error.data = data
16
+ return { jsonrpc: '2.0', id: id ?? null, error }
17
+ }
18
+
19
+ function reply(id, result) {
20
+ return { jsonrpc: '2.0', id, result }
21
+ }
22
+
23
+ export function createMcpHandler({
24
+ tools = [], callTool, serverInfo, instructions,
25
+ maxBodyBytes = 10 * 1024 * 1024, maxBatch = 100, listChanged = false,
26
+ } = {}) {
27
+ /* tools 可以是静态数组,或一个返回当前数组的函数(活引用)。活引用让
28
+ * tools/list 每次读到最新工具集——registry 动态增删工具后无需重建 handler。 */
29
+ const liveProvider = typeof tools === 'function' ? tools : null
30
+ if (!liveProvider && !Array.isArray(tools)) throw new Error('createMcpHandler: tools 必须是数组或返回数组的函数')
31
+ if (typeof callTool !== 'function') throw new Error('createMcpHandler: callTool 必须是函数')
32
+
33
+ const currentTools = () => {
34
+ const list = liveProvider ? liveProvider() : tools
35
+ return Array.isArray(list) ? list : []
36
+ }
37
+ const toolMapNow = () => new Map(currentTools().map((tool) => [tool.name, tool]))
38
+
39
+ return async function handle(req, res) {
40
+ /* 长工具调用(如截图)期间客户端可能超时断连;socket 的 'error' 事件
41
+ 无人监听会打崩进程。挂空处理器,配合 send() 的断连防护。 */
42
+ res.on('error', () => {})
43
+ if (req.method !== 'POST') {
44
+ if (res.destroyed) return
45
+ res.writeHead(405, { allow: 'POST', 'content-type': 'text/plain; charset=utf-8' })
46
+ return res.end('MCP endpoint: POST only')
47
+ }
48
+
49
+ let msg
50
+ try {
51
+ msg = await readBody(req, maxBodyBytes)
52
+ } catch (error) {
53
+ if (error?.code === 'BODY_TOO_LARGE') {
54
+ return send(req, res, 413, rpcError(null, -32600, 'Request body too large'))
55
+ }
56
+ return send(req, res, 400, rpcError(null, -32700, 'Parse error'))
57
+ }
58
+
59
+ if (!msg || typeof msg !== 'object') {
60
+ return send(req, res, 400, rpcError(null, -32600, 'Invalid Request'))
61
+ }
62
+
63
+ const batch = Array.isArray(msg)
64
+ if (batch && msg.length === 0) {
65
+ return send(req, res, 400, rpcError(null, -32600, 'Invalid Request'))
66
+ }
67
+ if (batch && msg.length > maxBatch) {
68
+ return send(req, res, 400, rpcError(null, -32600, `Batch too large (max ${maxBatch})`))
69
+ }
70
+ const messages = batch ? msg : [msg]
71
+ const replies = []
72
+ for (const message of messages) {
73
+ const result = await handleOne(message, req)
74
+ if (result !== null) replies.push(result)
75
+ }
76
+ if (!replies.length) {
77
+ if (res.destroyed) return
78
+ res.writeHead(202, { 'content-length': 0 })
79
+ return res.end()
80
+ }
81
+ return send(req, res, 200, batch ? replies : replies[0])
82
+ }
83
+
84
+ async function handleOne(message, req) {
85
+ if (!message || typeof message !== 'object' || Array.isArray(message)) {
86
+ return rpcError(null, -32600, 'Invalid Request')
87
+ }
88
+
89
+ const { id, method, params } = message
90
+ const isNotification = id === undefined || id === null
91
+
92
+ if (typeof method !== 'string' || !method) {
93
+ return isNotification ? null : rpcError(id, -32600, 'Invalid Request')
94
+ }
95
+
96
+ if (method === 'initialize') {
97
+ const result = {
98
+ protocolVersion: String(params?.protocolVersion || DEFAULT_PROTOCOL),
99
+ capabilities: { tools: { listChanged: !!listChanged } },
100
+ serverInfo: serverInfo || { name: 'dsh-plugin', version: '0.0.0' },
101
+ }
102
+ if (typeof instructions === 'string' && instructions) result.instructions = instructions
103
+ return isNotification ? null : reply(id, result)
104
+ }
105
+
106
+ if (method === 'notifications/initialized' || method === 'initialized') return null
107
+ if (method === 'notifications/cancelled' || method === 'notifications/cancel') return null
108
+ if (method === 'ping') return isNotification ? null : reply(id, {})
109
+
110
+ if (method === 'tools/list') {
111
+ return isNotification ? null : reply(id, { tools: currentTools() })
112
+ }
113
+
114
+ if (method === 'tools/call') {
115
+ const name = params?.name
116
+ const args = params?.arguments && typeof params.arguments === 'object' ? params.arguments : {}
117
+ const tool = toolMapNow().get(name)
118
+ if (!tool) {
119
+ if (isNotification) return null
120
+ return reply(id, {
121
+ content: [{ type: 'text', text: `未知工具: ${String(name)}` }],
122
+ isError: true,
123
+ })
124
+ }
125
+
126
+ const check = validateToolArguments(tool, args)
127
+ if (!check.ok) {
128
+ if (isNotification) return null
129
+ return reply(id, {
130
+ content: [{ type: 'text', text: '参数不合法:' + check.errors.join(';') }],
131
+ isError: true,
132
+ })
133
+ }
134
+
135
+ try {
136
+ const out = await callTool(name, args, { req })
137
+ /* 归一化保留纯字符串/空 text/对象,不再用 `|| 'ok'` 丢成无信息占位符(B 轴 P0-5)。 */
138
+ return reply(id, normalizeToolResult(out))
139
+ } catch (error) {
140
+ if (isNotification) return null
141
+ return reply(id, {
142
+ content: [{ type: 'text', text: '工具失败:' + String((error && error.message) || error) }],
143
+ isError: true,
144
+ })
145
+ }
146
+ }
147
+
148
+ return isNotification ? null : rpcError(id, -32601, `Method not found: ${method}`)
149
+ }
150
+ }