@herbertgao/pi-extensions 2026.9.17 → 2026.9.19

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 (307) hide show
  1. package/README.md +31 -33
  2. package/THIRD_PARTY_NOTICES.md +1 -1
  3. package/node_modules/@herbertgao/pi-bark/package.json +2 -2
  4. package/node_modules/@herbertgao/pi-cc-extensions/README.en.md +4 -1
  5. package/node_modules/@herbertgao/pi-cc-extensions/README.md +4 -1
  6. package/node_modules/@herbertgao/pi-cc-extensions/extensions/feature/shell/working-message.ts +21 -6
  7. package/node_modules/@herbertgao/pi-cc-extensions/extensions/renderer/index.ts +15 -4
  8. package/node_modules/@herbertgao/pi-cc-extensions/extensions/renderer/tool/diff/index.ts +43 -7
  9. package/node_modules/@herbertgao/pi-cc-extensions/extensions/renderer/tool/grouping.ts +7 -2
  10. package/node_modules/@herbertgao/pi-cc-extensions/extensions/renderer/tool/result.ts +1 -1
  11. package/node_modules/@herbertgao/pi-cc-extensions/package.json +75 -75
  12. package/node_modules/@herbertgao/pi-subagents/CHANGELOG.md +6 -0
  13. package/node_modules/@herbertgao/pi-subagents/package.json +7 -7
  14. package/node_modules/@herbertgao/resume-from/package.json +4 -2
  15. package/node_modules/@herbertgao/sol-pi/package.json +6 -6
  16. package/node_modules/@juicesharp/rpiv-ask-user-question/package.json +99 -99
  17. package/node_modules/@pi-plugins/fast-mode/package.json +1 -1
  18. package/node_modules/@tifan/pi-handoff/package.json +1 -1
  19. package/node_modules/@tifan/pi-handoff/src/index.ts +56 -26
  20. package/node_modules/@tifan/pi-mermaid-open/package.json +1 -1
  21. package/node_modules/@tifan/pi-preferred-thinking/package.json +1 -1
  22. package/node_modules/@tifan/pi-recap/package.json +1 -1
  23. package/node_modules/@tifan/pi-rename/package.json +1 -1
  24. package/node_modules/pi-antigravity/README.md +29 -6
  25. package/node_modules/pi-antigravity/package.json +14 -9
  26. package/node_modules/pi-antigravity/src/auth/accounts.ts +327 -0
  27. package/node_modules/pi-antigravity/src/auth/index.ts +9 -0
  28. package/node_modules/pi-antigravity/src/client/client.ts +1 -1
  29. package/node_modules/pi-antigravity/src/image/image.ts +4 -4
  30. package/node_modules/pi-antigravity/src/index.ts +203 -13
  31. package/node_modules/pi-antigravity/src/search/index.ts +1 -0
  32. package/node_modules/pi-antigravity/src/search/search.ts +325 -0
  33. package/node_modules/pi-antigravity/src/stream/stream.ts +191 -14
  34. package/node_modules/pi-antigravity/src/types/enums.ts +45 -36
  35. package/node_modules/pi-antigravity/src/types/types.ts +5 -12
  36. package/node_modules/pi-antigravity/src/utils/http.ts +7 -2
  37. package/node_modules/pi-antigravity/src/utils/util.ts +31 -3
  38. package/node_modules/pi-lens/package.json +158 -158
  39. package/node_modules/pi-multi-account/package.json +2 -2
  40. package/node_modules/pi-typesafe/README.md +3 -1
  41. package/node_modules/pi-typesafe/dist/auth.d.ts +9 -5
  42. package/node_modules/pi-typesafe/dist/auth.js +7 -3
  43. package/node_modules/pi-typesafe/dist/backends.d.ts +33 -3
  44. package/node_modules/pi-typesafe/dist/backends.js +95 -1
  45. package/node_modules/pi-typesafe/dist/client.d.ts +5 -5
  46. package/node_modules/pi-typesafe/dist/client.js +12 -9
  47. package/node_modules/pi-typesafe/dist/credentials.d.ts +14 -8
  48. package/node_modules/pi-typesafe/dist/credentials.js +10 -7
  49. package/node_modules/pi-typesafe/dist/errors.d.ts +2 -2
  50. package/node_modules/pi-typesafe/dist/index.d.ts +2 -2
  51. package/node_modules/pi-typesafe/dist/index.js +1 -1
  52. package/node_modules/pi-typesafe/dist/login.d.ts +2 -2
  53. package/node_modules/pi-typesafe/dist/login.js +2 -2
  54. package/node_modules/pi-typesafe/package.json +6 -5
  55. package/node_modules/pi-web-access/CHANGELOG.md +72 -0
  56. package/node_modules/pi-web-access/README.md +34 -13
  57. package/node_modules/pi-web-access/chrome-cookies.ts +79 -25
  58. package/node_modules/pi-web-access/curator-page.ts +5 -1
  59. package/node_modules/pi-web-access/curator-server.ts +2 -0
  60. package/node_modules/pi-web-access/dist/index.js +1337 -1009
  61. package/node_modules/pi-web-access/exa.ts +20 -52
  62. package/node_modules/pi-web-access/extract.ts +41 -4
  63. package/node_modules/pi-web-access/gemini-search.ts +12 -4
  64. package/node_modules/pi-web-access/index.ts +29 -37
  65. package/node_modules/pi-web-access/openai-search.ts +35 -7
  66. package/node_modules/pi-web-access/package.json +8 -7
  67. package/node_modules/pi-web-access/page-query.ts +2 -2
  68. package/node_modules/pi-web-access/query-rewrite.ts +2 -3
  69. package/node_modules/pi-web-access/ssrf-protection.ts +27 -10
  70. package/node_modules/pi-web-access/storage.ts +48 -77
  71. package/node_modules/pi-web-access/summary-model-scope.ts +6 -77
  72. package/node_modules/pi-web-access/summary-review.ts +3 -4
  73. package/node_modules/pi-web-access/tavily.ts +67 -20
  74. package/node_modules/pi-web-access/tool-activation.ts +53 -33
  75. package/node_modules/pi-web-access/utils.ts +1 -1
  76. package/node_modules/pi-web-access/you.ts +164 -0
  77. package/node_modules/pi-web-access/zai.ts +161 -0
  78. package/node_modules/remote-pi/package.json +5 -1
  79. package/package.json +19 -31
  80. package/node_modules/pi-mcp-adapter/CHANGELOG.md +0 -1013
  81. package/node_modules/pi-mcp-adapter/LICENSE +0 -21
  82. package/node_modules/pi-mcp-adapter/OAUTH.md +0 -369
  83. package/node_modules/pi-mcp-adapter/README.md +0 -1021
  84. package/node_modules/pi-mcp-adapter/abort.ts +0 -34
  85. package/node_modules/pi-mcp-adapter/agent-dir.ts +0 -68
  86. package/node_modules/pi-mcp-adapter/agent-plugin-loader.ts +0 -416
  87. package/node_modules/pi-mcp-adapter/agent-plugin-provenance.ts +0 -36
  88. package/node_modules/pi-mcp-adapter/app-bridge.bundle.js +0 -67
  89. package/node_modules/pi-mcp-adapter/banner.png +0 -0
  90. package/node_modules/pi-mcp-adapter/bearer-command-resolver.ts +0 -193
  91. package/node_modules/pi-mcp-adapter/claude-plugin-loader.ts +0 -365
  92. package/node_modules/pi-mcp-adapter/cli.js +0 -454
  93. package/node_modules/pi-mcp-adapter/commands.ts +0 -861
  94. package/node_modules/pi-mcp-adapter/config.ts +0 -1565
  95. package/node_modules/pi-mcp-adapter/consent-manager.ts +0 -95
  96. package/node_modules/pi-mcp-adapter/direct-tool-surface.ts +0 -244
  97. package/node_modules/pi-mcp-adapter/direct-tools.ts +0 -428
  98. package/node_modules/pi-mcp-adapter/dist/abort.d.ts +0 -2
  99. package/node_modules/pi-mcp-adapter/dist/abort.js +0 -36
  100. package/node_modules/pi-mcp-adapter/dist/abort.js.map +0 -1
  101. package/node_modules/pi-mcp-adapter/dist/agent-dir.d.ts +0 -10
  102. package/node_modules/pi-mcp-adapter/dist/agent-dir.js +0 -63
  103. package/node_modules/pi-mcp-adapter/dist/agent-dir.js.map +0 -1
  104. package/node_modules/pi-mcp-adapter/dist/agent-plugin-loader.d.ts +0 -8
  105. package/node_modules/pi-mcp-adapter/dist/agent-plugin-loader.js +0 -398
  106. package/node_modules/pi-mcp-adapter/dist/agent-plugin-loader.js.map +0 -1
  107. package/node_modules/pi-mcp-adapter/dist/agent-plugin-provenance.d.ts +0 -1
  108. package/node_modules/pi-mcp-adapter/dist/agent-plugin-provenance.js +0 -31
  109. package/node_modules/pi-mcp-adapter/dist/agent-plugin-provenance.js.map +0 -1
  110. package/node_modules/pi-mcp-adapter/dist/bearer-command-resolver.d.ts +0 -6
  111. package/node_modules/pi-mcp-adapter/dist/bearer-command-resolver.js +0 -194
  112. package/node_modules/pi-mcp-adapter/dist/bearer-command-resolver.js.map +0 -1
  113. package/node_modules/pi-mcp-adapter/dist/claude-plugin-loader.d.ts +0 -9
  114. package/node_modules/pi-mcp-adapter/dist/claude-plugin-loader.js +0 -362
  115. package/node_modules/pi-mcp-adapter/dist/claude-plugin-loader.js.map +0 -1
  116. package/node_modules/pi-mcp-adapter/dist/config.d.ts +0 -134
  117. package/node_modules/pi-mcp-adapter/dist/config.js +0 -1361
  118. package/node_modules/pi-mcp-adapter/dist/config.js.map +0 -1
  119. package/node_modules/pi-mcp-adapter/dist/consent-manager.d.ts +0 -18
  120. package/node_modules/pi-mcp-adapter/dist/consent-manager.js +0 -88
  121. package/node_modules/pi-mcp-adapter/dist/consent-manager.js.map +0 -1
  122. package/node_modules/pi-mcp-adapter/dist/elicitation-handler.d.ts +0 -17
  123. package/node_modules/pi-mcp-adapter/dist/elicitation-handler.js +0 -316
  124. package/node_modules/pi-mcp-adapter/dist/elicitation-handler.js.map +0 -1
  125. package/node_modules/pi-mcp-adapter/dist/errors.d.ts +0 -131
  126. package/node_modules/pi-mcp-adapter/dist/errors.js +0 -278
  127. package/node_modules/pi-mcp-adapter/dist/errors.js.map +0 -1
  128. package/node_modules/pi-mcp-adapter/dist/http-ca.d.ts +0 -8
  129. package/node_modules/pi-mcp-adapter/dist/http-ca.js +0 -88
  130. package/node_modules/pi-mcp-adapter/dist/http-ca.js.map +0 -1
  131. package/node_modules/pi-mcp-adapter/dist/jev-client.d.ts +0 -14
  132. package/node_modules/pi-mcp-adapter/dist/jev-client.js +0 -367
  133. package/node_modules/pi-mcp-adapter/dist/jev-client.js.map +0 -1
  134. package/node_modules/pi-mcp-adapter/dist/jev-contracts.d.ts +0 -77
  135. package/node_modules/pi-mcp-adapter/dist/jev-contracts.js +0 -2
  136. package/node_modules/pi-mcp-adapter/dist/jev-contracts.js.map +0 -1
  137. package/node_modules/pi-mcp-adapter/dist/jev-key-store.d.ts +0 -51
  138. package/node_modules/pi-mcp-adapter/dist/jev-key-store.js +0 -205
  139. package/node_modules/pi-mcp-adapter/dist/jev-key-store.js.map +0 -1
  140. package/node_modules/pi-mcp-adapter/dist/json-schema-validator.d.ts +0 -2
  141. package/node_modules/pi-mcp-adapter/dist/json-schema-validator.js +0 -68
  142. package/node_modules/pi-mcp-adapter/dist/json-schema-validator.js.map +0 -1
  143. package/node_modules/pi-mcp-adapter/dist/lifecycle.d.ts +0 -56
  144. package/node_modules/pi-mcp-adapter/dist/lifecycle.js +0 -410
  145. package/node_modules/pi-mcp-adapter/dist/lifecycle.js.map +0 -1
  146. package/node_modules/pi-mcp-adapter/dist/logger.d.ts +0 -51
  147. package/node_modules/pi-mcp-adapter/dist/logger.js +0 -131
  148. package/node_modules/pi-mcp-adapter/dist/logger.js.map +0 -1
  149. package/node_modules/pi-mcp-adapter/dist/mcp-auth-fetch.d.ts +0 -26
  150. package/node_modules/pi-mcp-adapter/dist/mcp-auth-fetch.js +0 -103
  151. package/node_modules/pi-mcp-adapter/dist/mcp-auth-fetch.js.map +0 -1
  152. package/node_modules/pi-mcp-adapter/dist/mcp-auth-flow.d.ts +0 -118
  153. package/node_modules/pi-mcp-adapter/dist/mcp-auth-flow.js +0 -1097
  154. package/node_modules/pi-mcp-adapter/dist/mcp-auth-flow.js.map +0 -1
  155. package/node_modules/pi-mcp-adapter/dist/mcp-auth.d.ts +0 -170
  156. package/node_modules/pi-mcp-adapter/dist/mcp-auth.js +0 -1142
  157. package/node_modules/pi-mcp-adapter/dist/mcp-auth.js.map +0 -1
  158. package/node_modules/pi-mcp-adapter/dist/mcp-bearer-store.d.ts +0 -24
  159. package/node_modules/pi-mcp-adapter/dist/mcp-bearer-store.js +0 -203
  160. package/node_modules/pi-mcp-adapter/dist/mcp-bearer-store.js.map +0 -1
  161. package/node_modules/pi-mcp-adapter/dist/mcp-callback-server.d.ts +0 -53
  162. package/node_modules/pi-mcp-adapter/dist/mcp-callback-server.js +0 -441
  163. package/node_modules/pi-mcp-adapter/dist/mcp-callback-server.js.map +0 -1
  164. package/node_modules/pi-mcp-adapter/dist/mcp-oauth-provider.d.ts +0 -148
  165. package/node_modules/pi-mcp-adapter/dist/mcp-oauth-provider.js +0 -689
  166. package/node_modules/pi-mcp-adapter/dist/mcp-oauth-provider.js.map +0 -1
  167. package/node_modules/pi-mcp-adapter/dist/mcp-probe.d.ts +0 -6
  168. package/node_modules/pi-mcp-adapter/dist/mcp-probe.js +0 -166
  169. package/node_modules/pi-mcp-adapter/dist/mcp-probe.js.map +0 -1
  170. package/node_modules/pi-mcp-adapter/dist/mcp-tasks.d.ts +0 -102
  171. package/node_modules/pi-mcp-adapter/dist/mcp-tasks.js +0 -369
  172. package/node_modules/pi-mcp-adapter/dist/mcp-tasks.js.map +0 -1
  173. package/node_modules/pi-mcp-adapter/dist/mcp-trace.d.ts +0 -95
  174. package/node_modules/pi-mcp-adapter/dist/mcp-trace.js +0 -242
  175. package/node_modules/pi-mcp-adapter/dist/mcp-trace.js.map +0 -1
  176. package/node_modules/pi-mcp-adapter/dist/metadata-cache.d.ts +0 -19
  177. package/node_modules/pi-mcp-adapter/dist/metadata-cache.js +0 -301
  178. package/node_modules/pi-mcp-adapter/dist/metadata-cache.js.map +0 -1
  179. package/node_modules/pi-mcp-adapter/dist/npx-resolver.d.ts +0 -6
  180. package/node_modules/pi-mcp-adapter/dist/npx-resolver.js +0 -505
  181. package/node_modules/pi-mcp-adapter/dist/npx-resolver.js.map +0 -1
  182. package/node_modules/pi-mcp-adapter/dist/package-mcp-loader.d.ts +0 -2
  183. package/node_modules/pi-mcp-adapter/dist/package-mcp-loader.js +0 -144
  184. package/node_modules/pi-mcp-adapter/dist/package-mcp-loader.js.map +0 -1
  185. package/node_modules/pi-mcp-adapter/dist/request-headers-command.d.ts +0 -10
  186. package/node_modules/pi-mcp-adapter/dist/request-headers-command.js +0 -312
  187. package/node_modules/pi-mcp-adapter/dist/request-headers-command.js.map +0 -1
  188. package/node_modules/pi-mcp-adapter/dist/resource-tools.d.ts +0 -1
  189. package/node_modules/pi-mcp-adapter/dist/resource-tools.js +0 -15
  190. package/node_modules/pi-mcp-adapter/dist/resource-tools.js.map +0 -1
  191. package/node_modules/pi-mcp-adapter/dist/runtime-owner.d.ts +0 -13
  192. package/node_modules/pi-mcp-adapter/dist/runtime-owner.js +0 -97
  193. package/node_modules/pi-mcp-adapter/dist/runtime-owner.js.map +0 -1
  194. package/node_modules/pi-mcp-adapter/dist/sampling-handler.d.ts +0 -17
  195. package/node_modules/pi-mcp-adapter/dist/sampling-handler.js +0 -203
  196. package/node_modules/pi-mcp-adapter/dist/sampling-handler.js.map +0 -1
  197. package/node_modules/pi-mcp-adapter/dist/secure-keyring.d.ts +0 -11
  198. package/node_modules/pi-mcp-adapter/dist/secure-keyring.js +0 -172
  199. package/node_modules/pi-mcp-adapter/dist/secure-keyring.js.map +0 -1
  200. package/node_modules/pi-mcp-adapter/dist/server-manager.d.ts +0 -157
  201. package/node_modules/pi-mcp-adapter/dist/server-manager.js +0 -1745
  202. package/node_modules/pi-mcp-adapter/dist/server-manager.js.map +0 -1
  203. package/node_modules/pi-mcp-adapter/dist/session-approvals.d.ts +0 -34
  204. package/node_modules/pi-mcp-adapter/dist/session-approvals.js +0 -140
  205. package/node_modules/pi-mcp-adapter/dist/session-approvals.js.map +0 -1
  206. package/node_modules/pi-mcp-adapter/dist/session-recovery.d.ts +0 -26
  207. package/node_modules/pi-mcp-adapter/dist/session-recovery.js +0 -142
  208. package/node_modules/pi-mcp-adapter/dist/session-recovery.js.map +0 -1
  209. package/node_modules/pi-mcp-adapter/dist/state.d.ts +0 -73
  210. package/node_modules/pi-mcp-adapter/dist/state.js +0 -2
  211. package/node_modules/pi-mcp-adapter/dist/state.js.map +0 -1
  212. package/node_modules/pi-mcp-adapter/dist/types.d.ts +0 -642
  213. package/node_modules/pi-mcp-adapter/dist/types.js +0 -331
  214. package/node_modules/pi-mcp-adapter/dist/types.js.map +0 -1
  215. package/node_modules/pi-mcp-adapter/dist/ui-app-bridge-helpers.d.ts +0 -6
  216. package/node_modules/pi-mcp-adapter/dist/ui-app-bridge-helpers.js +0 -37
  217. package/node_modules/pi-mcp-adapter/dist/ui-app-bridge-helpers.js.map +0 -1
  218. package/node_modules/pi-mcp-adapter/dist/ui-resource-handler.d.ts +0 -17
  219. package/node_modules/pi-mcp-adapter/dist/ui-resource-handler.js +0 -219
  220. package/node_modules/pi-mcp-adapter/dist/ui-resource-handler.js.map +0 -1
  221. package/node_modules/pi-mcp-adapter/dist/ui-stream-types.d.ts +0 -104
  222. package/node_modules/pi-mcp-adapter/dist/ui-stream-types.js +0 -59
  223. package/node_modules/pi-mcp-adapter/dist/ui-stream-types.js.map +0 -1
  224. package/node_modules/pi-mcp-adapter/dist/ui-tool-visibility.d.ts +0 -4
  225. package/node_modules/pi-mcp-adapter/dist/ui-tool-visibility.js +0 -27
  226. package/node_modules/pi-mcp-adapter/dist/ui-tool-visibility.js.map +0 -1
  227. package/node_modules/pi-mcp-adapter/dist/unix-socket-transport.d.ts +0 -15
  228. package/node_modules/pi-mcp-adapter/dist/unix-socket-transport.js +0 -85
  229. package/node_modules/pi-mcp-adapter/dist/unix-socket-transport.js.map +0 -1
  230. package/node_modules/pi-mcp-adapter/dist/utils.d.ts +0 -41
  231. package/node_modules/pi-mcp-adapter/dist/utils.js +0 -417
  232. package/node_modules/pi-mcp-adapter/dist/utils.js.map +0 -1
  233. package/node_modules/pi-mcp-adapter/elicitation-handler.ts +0 -358
  234. package/node_modules/pi-mcp-adapter/error-signal.ts +0 -32
  235. package/node_modules/pi-mcp-adapter/errors.ts +0 -364
  236. package/node_modules/pi-mcp-adapter/examples/jev-accessibility-loop.mjs +0 -85
  237. package/node_modules/pi-mcp-adapter/examples/jev-semantic-filter.mjs +0 -34
  238. package/node_modules/pi-mcp-adapter/failure-backoff.ts +0 -23
  239. package/node_modules/pi-mcp-adapter/glimpse-ui.ts +0 -80
  240. package/node_modules/pi-mcp-adapter/host-html-template.ts +0 -515
  241. package/node_modules/pi-mcp-adapter/http-ca.ts +0 -84
  242. package/node_modules/pi-mcp-adapter/index.ts +0 -2106
  243. package/node_modules/pi-mcp-adapter/init.ts +0 -721
  244. package/node_modules/pi-mcp-adapter/jev-client.ts +0 -300
  245. package/node_modules/pi-mcp-adapter/jev-contracts.ts +0 -53
  246. package/node_modules/pi-mcp-adapter/jev-key-store.ts +0 -192
  247. package/node_modules/pi-mcp-adapter/json-schema-validator.ts +0 -83
  248. package/node_modules/pi-mcp-adapter/lazy-loader.ts +0 -7
  249. package/node_modules/pi-mcp-adapter/lifecycle.ts +0 -457
  250. package/node_modules/pi-mcp-adapter/logger.ts +0 -169
  251. package/node_modules/pi-mcp-adapter/mcp-auth-fetch.ts +0 -113
  252. package/node_modules/pi-mcp-adapter/mcp-auth-flow.ts +0 -1296
  253. package/node_modules/pi-mcp-adapter/mcp-auth.ts +0 -1287
  254. package/node_modules/pi-mcp-adapter/mcp-bearer-store.ts +0 -250
  255. package/node_modules/pi-mcp-adapter/mcp-callback-server.ts +0 -534
  256. package/node_modules/pi-mcp-adapter/mcp-code.ts +0 -495
  257. package/node_modules/pi-mcp-adapter/mcp-install.ts +0 -60
  258. package/node_modules/pi-mcp-adapter/mcp-keyring-helper.cjs +0 -89
  259. package/node_modules/pi-mcp-adapter/mcp-oauth-provider.ts +0 -819
  260. package/node_modules/pi-mcp-adapter/mcp-output-guard.ts +0 -511
  261. package/node_modules/pi-mcp-adapter/mcp-panel-theme.ts +0 -104
  262. package/node_modules/pi-mcp-adapter/mcp-panel.ts +0 -1099
  263. package/node_modules/pi-mcp-adapter/mcp-probe.ts +0 -201
  264. package/node_modules/pi-mcp-adapter/mcp-references.ts +0 -373
  265. package/node_modules/pi-mcp-adapter/mcp-script-worker.mjs +0 -137
  266. package/node_modules/pi-mcp-adapter/mcp-setup-panel.ts +0 -747
  267. package/node_modules/pi-mcp-adapter/mcp-status.ts +0 -105
  268. package/node_modules/pi-mcp-adapter/mcp-tasks.ts +0 -467
  269. package/node_modules/pi-mcp-adapter/mcp-trace.ts +0 -306
  270. package/node_modules/pi-mcp-adapter/metadata-cache.ts +0 -362
  271. package/node_modules/pi-mcp-adapter/namespace-tools.ts +0 -334
  272. package/node_modules/pi-mcp-adapter/npx-resolver.ts +0 -543
  273. package/node_modules/pi-mcp-adapter/oauth-handler.ts +0 -30
  274. package/node_modules/pi-mcp-adapter/oauth.ts +0 -52
  275. package/node_modules/pi-mcp-adapter/onboarding-state.ts +0 -76
  276. package/node_modules/pi-mcp-adapter/package-mcp-loader.ts +0 -156
  277. package/node_modules/pi-mcp-adapter/package.json +0 -219
  278. package/node_modules/pi-mcp-adapter/panel-keys.ts +0 -53
  279. package/node_modules/pi-mcp-adapter/prompts.ts +0 -385
  280. package/node_modules/pi-mcp-adapter/proxy-modes.ts +0 -1735
  281. package/node_modules/pi-mcp-adapter/request-headers-command.ts +0 -333
  282. package/node_modules/pi-mcp-adapter/resource-tools.ts +0 -17
  283. package/node_modules/pi-mcp-adapter/runtime-owner.ts +0 -106
  284. package/node_modules/pi-mcp-adapter/sampling-handler.ts +0 -261
  285. package/node_modules/pi-mcp-adapter/sandbox-proxy-template.ts +0 -144
  286. package/node_modules/pi-mcp-adapter/search-ranking.ts +0 -309
  287. package/node_modules/pi-mcp-adapter/secure-keyring.ts +0 -170
  288. package/node_modules/pi-mcp-adapter/semantic-search.ts +0 -186
  289. package/node_modules/pi-mcp-adapter/server-manager.ts +0 -2088
  290. package/node_modules/pi-mcp-adapter/session-approvals.ts +0 -201
  291. package/node_modules/pi-mcp-adapter/session-recovery.ts +0 -158
  292. package/node_modules/pi-mcp-adapter/skills/mcp-scripting/SKILL.md +0 -49
  293. package/node_modules/pi-mcp-adapter/state.ts +0 -71
  294. package/node_modules/pi-mcp-adapter/tool-approval.ts +0 -205
  295. package/node_modules/pi-mcp-adapter/tool-metadata.ts +0 -302
  296. package/node_modules/pi-mcp-adapter/tool-registrar.ts +0 -255
  297. package/node_modules/pi-mcp-adapter/tool-result-renderer.ts +0 -573
  298. package/node_modules/pi-mcp-adapter/ts-shape.ts +0 -149
  299. package/node_modules/pi-mcp-adapter/types.ts +0 -1120
  300. package/node_modules/pi-mcp-adapter/ui-app-bridge-helpers.ts +0 -40
  301. package/node_modules/pi-mcp-adapter/ui-resource-handler.ts +0 -266
  302. package/node_modules/pi-mcp-adapter/ui-server.ts +0 -993
  303. package/node_modules/pi-mcp-adapter/ui-session.ts +0 -624
  304. package/node_modules/pi-mcp-adapter/ui-stream-types.ts +0 -89
  305. package/node_modules/pi-mcp-adapter/ui-tool-visibility.ts +0 -25
  306. package/node_modules/pi-mcp-adapter/unix-socket-transport.ts +0 -85
  307. package/node_modules/pi-mcp-adapter/utils.ts +0 -464
@@ -1,89 +0,0 @@
1
- import { z } from "zod";
2
-
3
- export const UI_STREAM_HOST_CONTEXT_KEY = "pi-mcp-adapter/stream";
4
- export const UI_STREAM_REQUEST_META_KEY = "pi-mcp-adapter/stream-token";
5
- export const UI_STREAM_RESULT_PATCH_METHOD = "notifications/pi-mcp-adapter/ui-result-patch";
6
- export const SERVER_STREAM_RESULT_PATCH_METHOD = "notifications/pi-mcp-adapter/result-patch";
7
- export const UI_STREAM_STRUCTURED_CONTENT_KEY = "pi-mcp-adapter/stream";
8
-
9
- export const uiStreamModeSchema = z.enum(["eager", "stream-first"]);
10
- export type UiStreamMode = z.infer<typeof uiStreamModeSchema>;
11
-
12
- export const visualizationStreamPhaseSchema = z.enum(["shell", "narrative", "structure", "detail", "settled"]);
13
- export type VisualizationStreamPhase = z.infer<typeof visualizationStreamPhaseSchema>;
14
-
15
- export const visualizationStreamFrameTypeSchema = z.enum(["patch", "checkpoint", "final"]);
16
- export type VisualizationStreamFrameType = z.infer<typeof visualizationStreamFrameTypeSchema>;
17
-
18
- export const visualizationStreamStatusSchema = z.enum(["ok", "error"]);
19
- export type VisualizationStreamStatus = z.infer<typeof visualizationStreamStatusSchema>;
20
-
21
- const looseRecordSchema = z.record(z.string(), z.unknown());
22
- const looseArraySchema = z.array(z.unknown());
23
-
24
- export const uiStreamHostContextSchema = z.object({
25
- mode: uiStreamModeSchema,
26
- streamId: z.string().min(1),
27
- intermediateResultPatches: z.boolean(),
28
- partialInput: z.boolean(),
29
- });
30
- export type UiStreamHostContext = z.infer<typeof uiStreamHostContextSchema>;
31
-
32
- export const visualizationStreamEnvelopeSchema = z.object({
33
- streamId: z.string().min(1),
34
- sequence: z.number().int().nonnegative(),
35
- frameType: visualizationStreamFrameTypeSchema,
36
- phase: visualizationStreamPhaseSchema,
37
- status: visualizationStreamStatusSchema,
38
- message: z.string().optional(),
39
- spec: looseRecordSchema.optional(),
40
- checkpoint: looseRecordSchema.optional(),
41
- });
42
- export type VisualizationStreamEnvelope = z.infer<typeof visualizationStreamEnvelopeSchema>;
43
-
44
- export const uiStreamCallToolResultSchema = z.object({
45
- content: looseArraySchema.optional(),
46
- structuredContent: looseRecordSchema.optional(),
47
- isError: z.boolean().optional(),
48
- _meta: looseRecordSchema.optional(),
49
- }).passthrough();
50
- export type UiStreamCallToolResult = z.infer<typeof uiStreamCallToolResultSchema>;
51
-
52
- export const uiStreamResultPatchNotificationSchema = z.object({
53
- method: z.literal(UI_STREAM_RESULT_PATCH_METHOD),
54
- params: uiStreamCallToolResultSchema,
55
- });
56
- export type UiStreamResultPatchNotification = z.infer<typeof uiStreamResultPatchNotificationSchema>;
57
-
58
- export const serverStreamResultPatchNotificationSchema = z.object({
59
- method: z.literal(SERVER_STREAM_RESULT_PATCH_METHOD),
60
- params: z.object({
61
- streamToken: z.string().min(1),
62
- result: uiStreamCallToolResultSchema,
63
- }),
64
- });
65
- export type ServerStreamResultPatchNotification = z.infer<typeof serverStreamResultPatchNotificationSchema>;
66
-
67
- export interface UiStreamSummary {
68
- streamId: string;
69
- mode: UiStreamMode;
70
- frames: number;
71
- phases: VisualizationStreamPhase[];
72
- finalStatus?: VisualizationStreamStatus;
73
- lastMessage?: string;
74
- }
75
-
76
- export function getUiStreamHostContext(hostContext: Record<string, unknown> | undefined): UiStreamHostContext | undefined {
77
- const candidate = hostContext?.[UI_STREAM_HOST_CONTEXT_KEY];
78
- const parsed = uiStreamHostContextSchema.safeParse(candidate);
79
- return parsed.success ? parsed.data : undefined;
80
- }
81
-
82
- export function getVisualizationStreamEnvelope(structuredContent: unknown): VisualizationStreamEnvelope | undefined {
83
- if (!structuredContent || typeof structuredContent !== "object" || Array.isArray(structuredContent)) {
84
- return undefined;
85
- }
86
- const candidate = (structuredContent as Record<string, unknown>)[UI_STREAM_STRUCTURED_CONTENT_KEY];
87
- const parsed = visualizationStreamEnvelopeSchema.safeParse(candidate);
88
- return parsed.success ? parsed.data : undefined;
89
- }
@@ -1,25 +0,0 @@
1
- export type UiToolVisibility = "model" | "app";
2
-
3
- export function extractUiToolVisibility(meta: Record<string, unknown> | undefined): UiToolVisibility[] | undefined {
4
- if (!meta || typeof meta !== "object") return undefined;
5
- const ui = meta.ui;
6
- if (!ui || typeof ui !== "object" || Array.isArray(ui)) return undefined;
7
- const visibility = (ui as Record<string, unknown>).visibility;
8
- if (visibility === undefined) return undefined;
9
- if (!Array.isArray(visibility)) return [];
10
-
11
- const values: UiToolVisibility[] = [];
12
- for (const entry of visibility) {
13
- if (entry !== "model" && entry !== "app") return [];
14
- if (!values.includes(entry)) values.push(entry);
15
- }
16
- return values;
17
- }
18
-
19
- export function isUiToolVisibleToModel(visibility: readonly UiToolVisibility[] | undefined): boolean {
20
- return visibility === undefined || visibility.includes("model");
21
- }
22
-
23
- export function isUiToolCallableByApp(visibility: readonly UiToolVisibility[] | undefined): boolean {
24
- return visibility === undefined || visibility.includes("app");
25
- }
@@ -1,85 +0,0 @@
1
- import { createConnection, type Socket } from "node:net";
2
- import { ReadBuffer, serializeMessage } from "@modelcontextprotocol/client";
3
- import type { Transport } from "@modelcontextprotocol/client";
4
- import type { JSONRPCMessage } from "@modelcontextprotocol/client";
5
-
6
- /** MCP JSONL transport for an explicitly configured Unix-domain socket. */
7
- export class UnixSocketClientTransport implements Transport {
8
- private socket: Socket | undefined;
9
- private readonly readBuffer = new ReadBuffer();
10
-
11
- onclose?: () => void;
12
- onerror?: (error: Error) => void;
13
- onmessage?: (message: JSONRPCMessage) => void;
14
-
15
- constructor(private readonly socketPath: string) {}
16
-
17
- async start(): Promise<void> {
18
- if (this.socket) {
19
- throw new Error("UnixSocketClientTransport already started");
20
- }
21
-
22
- await new Promise<void>((resolve, reject) => {
23
- const socket = createConnection(this.socketPath);
24
- this.socket = socket;
25
- let connected = false;
26
-
27
- socket.once("connect", () => {
28
- connected = true;
29
- resolve();
30
- });
31
- socket.on("data", chunk => {
32
- try {
33
- this.readBuffer.append(chunk);
34
- while (true) {
35
- const message = this.readBuffer.readMessage();
36
- if (message === null) break;
37
- this.onmessage?.(message);
38
- }
39
- } catch (error) {
40
- const cause = error instanceof Error ? error : new Error(String(error));
41
- this.onerror?.(cause);
42
- void this.close();
43
- }
44
- });
45
- socket.on("error", error => {
46
- if (!connected) reject(error);
47
- this.onerror?.(error);
48
- });
49
- socket.on("close", () => {
50
- if (this.socket === socket) this.socket = undefined;
51
- this.readBuffer.clear();
52
- this.onclose?.();
53
- });
54
- });
55
- }
56
-
57
- async close(): Promise<void> {
58
- const socket = this.socket;
59
- this.socket = undefined;
60
- this.readBuffer.clear();
61
- if (!socket || socket.destroyed) return;
62
-
63
- await new Promise<void>(resolve => {
64
- const timeout = setTimeout(() => socket.destroy(), 2_000);
65
- timeout.unref();
66
- socket.once("close", () => {
67
- clearTimeout(timeout);
68
- resolve();
69
- });
70
- socket.end();
71
- });
72
- }
73
-
74
- async send(message: JSONRPCMessage): Promise<void> {
75
- const socket = this.socket;
76
- if (!socket || socket.destroyed) throw new Error("Unix socket is not connected");
77
-
78
- await new Promise<void>((resolve, reject) => {
79
- socket.write(serializeMessage(message), error => {
80
- if (error) reject(error);
81
- else resolve();
82
- });
83
- });
84
- }
85
- }
@@ -1,464 +0,0 @@
1
- import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
2
- import { spawnSync } from "node:child_process";
3
- import { existsSync, realpathSync } from "node:fs";
4
- import { homedir, platform } from "node:os";
5
- import { dirname, extname, isAbsolute, join, relative, resolve, sep } from "node:path";
6
- import stripJsonComments from "strip-json-comments";
7
- import type { McpConfig, ServerEntry } from "./types.ts";
8
-
9
- export function parseJsonWithComments(raw: string): unknown {
10
- return JSON.parse(stripJsonComments(raw, { trailingCommas: true }));
11
- }
12
-
13
- /** Resolve a candidate only when its real path stays within the real root. */
14
- export function resolveRealContainedPath(root: string, candidate: string, allowMissing = false): string | null {
15
- const contained = resolveContainedPath(root, candidate);
16
- if (!contained) return null;
17
- const canonical = (path: string): string => {
18
- let existing = path;
19
- while (allowMissing && !existsSync(existing)) {
20
- const parent = dirname(existing);
21
- if (parent === existing) throw new Error("No existing path ancestor");
22
- existing = parent;
23
- }
24
- return resolve(realpathSync(existing), relative(existing, path));
25
- };
26
- try {
27
- return resolveContainedPath(canonical(root), canonical(contained));
28
- } catch {
29
- return null;
30
- }
31
- }
32
-
33
- export function resolveContainedPath(root: string, candidate: string): string | null {
34
- const resolved = resolve(root, candidate);
35
- const rel = relative(root, resolved);
36
- return rel === "" || (!rel.startsWith("..") && !rel.startsWith(sep) && !isAbsolute(rel)) ? resolved : null;
37
- }
38
-
39
- export function stableStringify(value: unknown): string {
40
- if (value === null || typeof value !== "object") return JSON.stringify(value) ?? "undefined";
41
- if (Array.isArray(value)) {
42
- return `[${value.map(item => stableStringify(item)).join(",")}]`;
43
- }
44
- const object = value as Record<string, unknown>;
45
- return `{${Object.keys(object).sort().map(key => `${JSON.stringify(key)}:${stableStringify(object[key])}`).join(",")}}`;
46
- }
47
-
48
- async function execOpen(pi: ExtensionAPI, target: string, browser?: string, signal?: AbortSignal) {
49
- const os = platform();
50
-
51
- if (os === "darwin") {
52
- if (browser) {
53
- // An absolute executable path (e.g. from $BROWSER) names a launcher
54
- // binary. App bundles still go through `open -a`, which handles them.
55
- return isAbsolute(browser) && extname(browser).toLowerCase() !== ".app"
56
- ? pi.exec(browser, [target], signal ? { signal } : {})
57
- : pi.exec("open", ["-a", browser, target], signal ? { signal } : {});
58
- }
59
- return pi.exec("open", [target], signal ? { signal } : {});
60
- }
61
- if (os === "win32") {
62
- return browser
63
- ? pi.exec("cmd", ["/c", "start", "", browser, target], signal ? { signal } : {})
64
- : pi.exec("cmd", ["/c", "start", "", target], signal ? { signal } : {});
65
- }
66
- return browser
67
- ? pi.exec(browser, [target], signal ? { signal } : {})
68
- : pi.exec("xdg-open", [target], signal ? { signal } : {});
69
- }
70
-
71
- export async function openUrl(pi: ExtensionAPI, url: string, browser?: string, signal?: AbortSignal): Promise<void> {
72
- const result = await execOpen(pi, url, browser, signal);
73
- if (result.code !== 0) {
74
- throw new Error(result.stderr || `Failed to open browser (exit code ${result.code})`);
75
- }
76
- }
77
-
78
- export async function openPath(pi: ExtensionAPI, targetPath: string): Promise<void> {
79
- const result = await execOpen(pi, targetPath);
80
- if (result.code !== 0) {
81
- throw new Error(result.stderr || `Failed to open path (exit code ${result.code})`);
82
- }
83
- }
84
-
85
- export async function parallelLimit<T, R>(
86
- items: T[],
87
- limit: number,
88
- fn: (item: T) => Promise<R>
89
- ): Promise<R[]> {
90
- const results: R[] = [];
91
- const iterator = items.entries();
92
-
93
- async function worker() {
94
- while (true) {
95
- const next = iterator.next();
96
- if (next.done) return;
97
- const [index, item] = next.value;
98
- results[index] = await fn(item);
99
- }
100
- }
101
-
102
- const workers = Array(Math.min(limit, items.length)).fill(null).map(() => worker());
103
- await Promise.all(workers);
104
- return results;
105
- }
106
-
107
- export function getConfigPathFromArgv(): string | undefined {
108
- let configPath: string | undefined;
109
- for (let index = 2; index < process.argv.length; index++) {
110
- const arg = process.argv[index];
111
- if (arg === undefined) continue;
112
- if (arg === "--") break;
113
-
114
- if (arg === "--mcp-config") {
115
- const value = process.argv[index + 1];
116
- if (value !== undefined && !value.startsWith("-") && !value.startsWith("@")) {
117
- configPath = value;
118
- index++;
119
- } else {
120
- configPath = undefined;
121
- }
122
- continue;
123
- }
124
-
125
- if (arg.startsWith("--mcp-config=")) {
126
- configPath = arg.slice("--mcp-config=".length);
127
- }
128
- }
129
- return configPath;
130
- }
131
-
132
- export function interpolateEnvVars(value: string): string;
133
- export function interpolateEnvVars(value: string, environment: NodeJS.ProcessEnv): string;
134
- export function interpolateEnvVars(value: string, environment: NodeJS.ProcessEnv = process.env): string {
135
- return value
136
- .replace(/\$\{(\w+)\}/g, (_, name) => environment[name] ?? "")
137
- .replace(/\$env:(\w+)/g, (_, name) => environment[name] ?? "")
138
- .replace(/\{env:(\w+)\}/g, (_, name) => environment[name] ?? "");
139
- }
140
-
141
- export function getMissingEnvVars(value: string, environment: NodeJS.ProcessEnv = process.env): string[] {
142
- const missing = new Set<string>();
143
- for (const match of value.matchAll(/\$\{(\w+)\}|\$env:(\w+)|\{env:(\w+)\}/g)) {
144
- const name = match[1] ?? match[2] ?? match[3];
145
- if (name && environment[name] === undefined) {
146
- missing.add(name);
147
- }
148
- }
149
- return [...missing];
150
- }
151
-
152
- export function toStringRecord(value: unknown): Record<string, string> | undefined {
153
- if (!value || typeof value !== "object" || Array.isArray(value)) return undefined;
154
-
155
- const result: Record<string, string> = {};
156
- for (const [key, entry] of Object.entries(value)) {
157
- if (typeof entry === "string") result[key] = entry;
158
- }
159
- return Object.keys(result).length > 0 ? result : undefined;
160
- }
161
-
162
- function interpolateSecretExpression(value: string, environment: NodeJS.ProcessEnv): string {
163
- if (value.startsWith("!!")) return interpolateEnvVars(value.slice(1), environment);
164
- return value.startsWith("!") ? value : interpolateEnvVars(value, environment);
165
- }
166
-
167
- export function interpolateEnvRecord(values: Record<string, string> | undefined, environment: NodeJS.ProcessEnv = process.env): Record<string, string> | undefined {
168
- if (!values) return undefined;
169
-
170
- return Object.fromEntries(Object.entries(values).map(([key, value]) => [
171
- key,
172
- interpolateSecretExpression(value, environment),
173
- ]));
174
- }
175
-
176
- const COMMAND_SECRET_TIMEOUT_MS = 10_000;
177
- const COMMAND_SECRET_MAX_OUTPUT_BYTES = 1024 * 1024;
178
-
179
- /** Resolve a secret value, executing only a single leading `!` command marker. */
180
- export function resolveCommandSecret(value: string, context: string): string;
181
- export function resolveCommandSecret(value: undefined, context: string): undefined;
182
- export function resolveCommandSecret(value: string | undefined, context: string): string | undefined;
183
- export function resolveCommandSecret(value: string | undefined, context: string): string | undefined {
184
- if (value === undefined) return undefined;
185
- if (value.startsWith("!!")) return interpolateEnvVars(value.slice(1));
186
- if (!value.startsWith("!")) return interpolateEnvVars(value);
187
-
188
- const result = spawnSync(value.slice(1), {
189
- shell: true,
190
- encoding: "utf8",
191
- timeout: COMMAND_SECRET_TIMEOUT_MS,
192
- maxBuffer: COMMAND_SECRET_MAX_OUTPUT_BYTES,
193
- stdio: ["ignore", "pipe", "ignore"],
194
- windowsHide: true,
195
- });
196
- if (result.error) {
197
- const code = (result.error as NodeJS.ErrnoException).code;
198
- const reason = code === "ETIMEDOUT"
199
- ? "command timed out after 10 seconds"
200
- : code === "ENOBUFS"
201
- ? "command output exceeded 1 MiB"
202
- : "command failed to start";
203
- throw new Error(`Failed to resolve ${context}: ${reason}`);
204
- }
205
- if (result.status !== 0) {
206
- throw new Error(`Failed to resolve ${context}: command exited with code ${result.status ?? "unknown"}`);
207
- }
208
-
209
- const resolved = result.stdout.trim();
210
- if (!resolved) throw new Error(`Failed to resolve ${context}: command returned empty output`);
211
- return resolved;
212
- }
213
-
214
- /** Resolve command markers in a configured record without mutating the input. */
215
- export function resolveCommandSecretsRecord(
216
- values: Record<string, string> | undefined,
217
- context: (key: string) => string,
218
- ): Record<string, string> | undefined {
219
- if (!values) return undefined;
220
-
221
- return Object.fromEntries(Object.entries(values).map(([key, value]) => [
222
- key,
223
- resolveCommandSecret(value, context(key)),
224
- ]));
225
- }
226
-
227
- export function resolveServerUrl(definition: Pick<ServerEntry, "url">, environment: NodeJS.ProcessEnv = process.env): string | undefined {
228
- if (definition.url == null) return undefined;
229
- if (typeof definition.url !== "string") {
230
- throw new Error("MCP server URL must be a string");
231
- }
232
-
233
- const missing = getMissingEnvVars(definition.url, environment);
234
- if (missing.length > 0) {
235
- throw new Error(`Missing environment variable${missing.length === 1 ? "" : "s"} in MCP server URL: ${missing.join(", ")}`);
236
- }
237
-
238
- const resolved = interpolateEnvVars(definition.url, environment);
239
- try {
240
- new URL(resolved);
241
- } catch (error) {
242
- throw new Error(`Invalid MCP server URL after environment interpolation: ${resolved}`, { cause: error });
243
- }
244
- return resolved;
245
- }
246
-
247
- export function resolveConfigPath(value: string | undefined, environment: NodeJS.ProcessEnv = process.env): string | undefined {
248
- if (value === undefined) return undefined;
249
-
250
- return expandHomePath(interpolateEnvVars(value, environment));
251
- }
252
-
253
- /** Expand a leading home-directory marker without interpolating environment variables. */
254
- export function expandHomePath(value: string | undefined): string | undefined {
255
- if (value === undefined) return undefined;
256
-
257
- const resolved = value;
258
- if (resolved === "~") return homedir();
259
- if (resolved.startsWith("~/") || (platform() === "win32" && resolved.startsWith("~\\"))) {
260
- const suffix = platform() === "win32" ? resolved.slice(2).replace(/[\\/]/g, sep) : resolved.slice(2);
261
- return join(homedir(), suffix);
262
- }
263
- return resolved;
264
- }
265
-
266
- export function resolveBearerToken(definition: Pick<ServerEntry, "bearerToken" | "bearerTokenEnv">, environment: NodeJS.ProcessEnv = process.env): string | undefined {
267
- if (definition.bearerToken !== undefined) {
268
- return interpolateSecretExpression(definition.bearerToken, environment);
269
- }
270
- return definition.bearerTokenEnv ? environment[definition.bearerTokenEnv] : undefined;
271
- }
272
-
273
- /** Remove OSC control strings, including payloads that have no terminator. */
274
- export function stripOscSequences(text: string): string {
275
- let result = "";
276
- let index = 0;
277
- while (index < text.length) {
278
- const isEscOsc = text.charCodeAt(index) === 0x1b && text[index + 1] === "]";
279
- const isC1Osc = text.charCodeAt(index) === 0x9d;
280
- if (!isEscOsc && !isC1Osc) {
281
- result += text[index++];
282
- continue;
283
- }
284
-
285
- index += isEscOsc ? 2 : 1;
286
- while (index < text.length) {
287
- const code = text.charCodeAt(index++);
288
- if (code === 0x07 || code === 0x9c) break;
289
- if (code === 0x1b && text[index] === "\\") {
290
- index++;
291
- break;
292
- }
293
- }
294
- }
295
- return result;
296
- }
297
-
298
- export function sanitizeTerminalText(text: string): string {
299
- return stripOscSequences(text)
300
- .replace(/(?:\x1b\[[0-?]*[ -/]*[@-~]|\x1b[@-Z\\-_])/g, "")
301
- .replace(/[\u0000-\u001f\u007f-\u009f]+/g, " ")
302
- .replace(/\s+/g, " ")
303
- .trim();
304
- }
305
-
306
- export function formatTerminalError(error: unknown): string {
307
- const messages: string[] = [];
308
- const seen = new Set<unknown>();
309
- const collect = (value: unknown) => {
310
- if (seen.has(value)) return;
311
- if ((typeof value === "object" && value !== null) || typeof value === "function") seen.add(value);
312
-
313
- if (value instanceof AggregateError) {
314
- const countBefore = messages.length;
315
- for (const nested of value.errors) collect(nested);
316
- if (value.cause !== undefined) collect(value.cause);
317
- if (messages.length === countBefore && value.message) messages.push(value.message);
318
- return;
319
- }
320
- if (value instanceof Error) {
321
- if (value.message) messages.push(value.message);
322
- if (value.cause !== undefined) collect(value.cause);
323
- return;
324
- }
325
- messages.push(String(value));
326
- };
327
-
328
- collect(error);
329
- return sanitizeTerminalText([...new Set(messages)].join(": "));
330
- }
331
-
332
- export function truncateAtWord(text: string, target: number): string {
333
- if (!text || text.length <= target) return text;
334
-
335
- const truncated = text.slice(0, target);
336
- const lastSpace = truncated.lastIndexOf(" ");
337
-
338
- if (lastSpace > target * 0.6) {
339
- return truncated.slice(0, lastSpace) + "...";
340
- }
341
-
342
- return truncated + "...";
343
- }
344
-
345
- export function normalizeDirectToolInputSchema(schema: unknown): Record<string, unknown> {
346
- const inputSchema = schema && typeof schema === "object" && !Array.isArray(schema)
347
- ? schema as Record<string, unknown>
348
- : { type: "object", properties: {} };
349
- const { $schema, additionalProperties, ...normalized } = inputSchema;
350
- return normalized;
351
- }
352
-
353
- export function normalizeToolArguments(
354
- value: unknown,
355
- context = "tool arguments",
356
- ): Record<string, unknown> {
357
- if (value === undefined || value === null || value === "") return {};
358
-
359
- if (typeof value === "string") {
360
- const trimmed = value.trim();
361
- if (trimmed === "") return {};
362
- let parsed: unknown;
363
- try {
364
- parsed = JSON.parse(trimmed);
365
- } catch (error) {
366
- throw new Error(
367
- `${context}: invalid args JSON (${error instanceof SyntaxError ? error.message : String(error)}); ` +
368
- `pass args as a JSON object, or as a valid JSON string encoding one`,
369
- { cause: error },
370
- );
371
- }
372
- if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) {
373
- throw new Error(
374
- `${context}: expected a JSON object, got ${Array.isArray(parsed) ? "array" : typeof parsed}`,
375
- );
376
- }
377
- return parsed as Record<string, unknown>;
378
- }
379
-
380
- if (typeof value !== "object" || Array.isArray(value)) {
381
- throw new Error(
382
- `${context}: expected a JSON object, got ${Array.isArray(value) ? "array" : typeof value}`,
383
- );
384
- }
385
-
386
- assertJsonSerializable(value, context);
387
- try {
388
- return JSON.parse(JSON.stringify(value)) as Record<string, unknown>;
389
- } catch (error) {
390
- throw new Error(
391
- `${context}: value is not JSON-serializable: ${error instanceof Error ? error.message : String(error)}`,
392
- { cause: error },
393
- );
394
- }
395
- }
396
-
397
- function assertJsonSerializable(value: unknown, context: string, path = ""): void {
398
- if (value === null) return;
399
- if (typeof value === "string" || typeof value === "boolean") return;
400
- if (typeof value === "number") {
401
- if (!Number.isFinite(value)) throw new Error(`${context}: value at ${path || "root"} is not a finite number`);
402
- return;
403
- }
404
- if (Array.isArray(value)) {
405
- for (const [index, item] of value.entries()) assertJsonSerializable(item, context, `${path}[${index}]`);
406
- return;
407
- }
408
- if (typeof value === "object") {
409
- if (Object.getPrototypeOf(value) !== Object.prototype && Object.getPrototypeOf(value) !== null) {
410
- throw new Error(`${context}: value at ${path || "root"} is not a plain JSON object`);
411
- }
412
- if (Object.getOwnPropertySymbols(value).length > 0) {
413
- throw new Error(`${context}: value at ${path || "root"} has symbol keys`);
414
- }
415
- for (const [key, item] of Object.entries(value)) {
416
- assertJsonSerializable(item, context, path ? `${path}.${key}` : key);
417
- }
418
- return;
419
- }
420
- throw new Error(`${context}: value at ${path || "root"} is not JSON-serializable`);
421
- }
422
-
423
- export function formatAuthRequiredMessage(
424
- config: Pick<McpConfig, "settings">,
425
- serverName: string,
426
- defaultMessage: string,
427
- ): string {
428
- const template = config.settings?.authRequiredMessage;
429
- return template ? template.replaceAll("${server}", serverName) : defaultMessage;
430
- }
431
-
432
- export function formatMcpStatus(config: Pick<McpConfig, "settings">, message: string): string | undefined {
433
- if (config.settings?.mcpFooterStatus === "off") return undefined;
434
- return `${config.settings?.showStatusIcon === false ? "MCP: " : "🔌 MCP: "}${message}`;
435
- }
436
-
437
- export function formatMcpFooterStatus(
438
- config: Pick<McpConfig, "settings">,
439
- enabledCount: number,
440
- disabledCount: number,
441
- connectedCount: number,
442
- ): string | undefined {
443
- if (enabledCount + disabledCount === 0 || config.settings?.mcpFooterStatus === "off") return undefined;
444
- const footerStatus = config.settings?.mcpFooterStatus ?? "full";
445
- if (footerStatus === "compact") return `MCP ${connectedCount}/${enabledCount}`;
446
-
447
- let status = `${enabledCount} ${enabledCount === 1 ? "server" : "servers"} enabled`;
448
- if (connectedCount > 0) status += ` (${connectedCount} connected)`;
449
- if (disabledCount > 0) status += ` (${disabledCount} disabled)`;
450
- return formatMcpStatus(config, status);
451
- }
452
-
453
- /**
454
- * Extract the adapter-owned UI stream mode from tool metadata.
455
- */
456
- export function extractToolUiStreamMode(toolMeta: Record<string, unknown> | undefined): "eager" | "stream-first" | undefined {
457
- const uiMeta = toolMeta?.ui;
458
- if (!uiMeta || typeof uiMeta !== "object") return undefined;
459
- const streamMode = (uiMeta as Record<string, unknown>)["pi-mcp-adapter.streamMode"];
460
- if (streamMode === "eager" || streamMode === "stream-first") {
461
- return streamMode;
462
- }
463
- return undefined;
464
- }