@herbertgao/pi-extensions 2026.9.16 → 2026.9.18

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 (267) hide show
  1. package/README.md +14 -15
  2. package/node_modules/@herbertgao/pi-bark/package.json +2 -2
  3. package/node_modules/@herbertgao/pi-cc-extensions/README.en.md +4 -1
  4. package/node_modules/@herbertgao/pi-cc-extensions/README.md +4 -1
  5. package/node_modules/@herbertgao/pi-cc-extensions/package.json +75 -75
  6. package/node_modules/@herbertgao/pi-subagents/CHANGELOG.md +6 -0
  7. package/node_modules/@herbertgao/pi-subagents/package.json +7 -7
  8. package/node_modules/@herbertgao/resume-from/package.json +4 -2
  9. package/node_modules/@herbertgao/sol-pi/package.json +6 -6
  10. package/node_modules/@herbertgao/sol-pi/src/sol-pi/extensions/online-context-compact/extension.ts +11 -53
  11. package/node_modules/@juicesharp/rpiv-ask-user-question/package.json +99 -99
  12. package/node_modules/@pi-plugins/fast-mode/package.json +1 -1
  13. package/node_modules/@tifan/pi-handoff/package.json +1 -1
  14. package/node_modules/@tifan/pi-handoff/src/index.ts +56 -26
  15. package/node_modules/@tifan/pi-mermaid-open/package.json +1 -1
  16. package/node_modules/@tifan/pi-preferred-thinking/package.json +1 -1
  17. package/node_modules/@tifan/pi-recap/package.json +1 -1
  18. package/node_modules/@tifan/pi-rename/package.json +1 -1
  19. package/node_modules/pi-antigravity/package.json +2 -2
  20. package/node_modules/pi-lens/package.json +158 -158
  21. package/node_modules/pi-multi-account/package.json +2 -2
  22. package/node_modules/pi-typesafe/README.md +1 -1
  23. package/node_modules/pi-typesafe/dist/auth.d.ts +9 -5
  24. package/node_modules/pi-typesafe/dist/auth.js +7 -3
  25. package/node_modules/pi-typesafe/dist/backends.d.ts +33 -3
  26. package/node_modules/pi-typesafe/dist/backends.js +95 -1
  27. package/node_modules/pi-typesafe/dist/client.d.ts +5 -5
  28. package/node_modules/pi-typesafe/dist/client.js +12 -9
  29. package/node_modules/pi-typesafe/dist/credentials.d.ts +14 -8
  30. package/node_modules/pi-typesafe/dist/credentials.js +10 -7
  31. package/node_modules/pi-typesafe/dist/errors.d.ts +2 -2
  32. package/node_modules/pi-typesafe/dist/index.d.ts +2 -2
  33. package/node_modules/pi-typesafe/dist/index.js +1 -1
  34. package/node_modules/pi-typesafe/dist/login.d.ts +2 -2
  35. package/node_modules/pi-typesafe/dist/login.js +2 -2
  36. package/node_modules/pi-typesafe/package.json +5 -5
  37. package/node_modules/pi-web-access/package.json +2 -2
  38. package/node_modules/remote-pi/package.json +5 -1
  39. package/package.json +16 -28
  40. package/node_modules/pi-mcp-adapter/CHANGELOG.md +0 -1013
  41. package/node_modules/pi-mcp-adapter/LICENSE +0 -21
  42. package/node_modules/pi-mcp-adapter/OAUTH.md +0 -369
  43. package/node_modules/pi-mcp-adapter/README.md +0 -1021
  44. package/node_modules/pi-mcp-adapter/abort.ts +0 -34
  45. package/node_modules/pi-mcp-adapter/agent-dir.ts +0 -68
  46. package/node_modules/pi-mcp-adapter/agent-plugin-loader.ts +0 -416
  47. package/node_modules/pi-mcp-adapter/agent-plugin-provenance.ts +0 -36
  48. package/node_modules/pi-mcp-adapter/app-bridge.bundle.js +0 -67
  49. package/node_modules/pi-mcp-adapter/banner.png +0 -0
  50. package/node_modules/pi-mcp-adapter/bearer-command-resolver.ts +0 -193
  51. package/node_modules/pi-mcp-adapter/claude-plugin-loader.ts +0 -365
  52. package/node_modules/pi-mcp-adapter/cli.js +0 -454
  53. package/node_modules/pi-mcp-adapter/commands.ts +0 -861
  54. package/node_modules/pi-mcp-adapter/config.ts +0 -1565
  55. package/node_modules/pi-mcp-adapter/consent-manager.ts +0 -95
  56. package/node_modules/pi-mcp-adapter/direct-tool-surface.ts +0 -244
  57. package/node_modules/pi-mcp-adapter/direct-tools.ts +0 -428
  58. package/node_modules/pi-mcp-adapter/dist/abort.d.ts +0 -2
  59. package/node_modules/pi-mcp-adapter/dist/abort.js +0 -36
  60. package/node_modules/pi-mcp-adapter/dist/abort.js.map +0 -1
  61. package/node_modules/pi-mcp-adapter/dist/agent-dir.d.ts +0 -10
  62. package/node_modules/pi-mcp-adapter/dist/agent-dir.js +0 -63
  63. package/node_modules/pi-mcp-adapter/dist/agent-dir.js.map +0 -1
  64. package/node_modules/pi-mcp-adapter/dist/agent-plugin-loader.d.ts +0 -8
  65. package/node_modules/pi-mcp-adapter/dist/agent-plugin-loader.js +0 -398
  66. package/node_modules/pi-mcp-adapter/dist/agent-plugin-loader.js.map +0 -1
  67. package/node_modules/pi-mcp-adapter/dist/agent-plugin-provenance.d.ts +0 -1
  68. package/node_modules/pi-mcp-adapter/dist/agent-plugin-provenance.js +0 -31
  69. package/node_modules/pi-mcp-adapter/dist/agent-plugin-provenance.js.map +0 -1
  70. package/node_modules/pi-mcp-adapter/dist/bearer-command-resolver.d.ts +0 -6
  71. package/node_modules/pi-mcp-adapter/dist/bearer-command-resolver.js +0 -194
  72. package/node_modules/pi-mcp-adapter/dist/bearer-command-resolver.js.map +0 -1
  73. package/node_modules/pi-mcp-adapter/dist/claude-plugin-loader.d.ts +0 -9
  74. package/node_modules/pi-mcp-adapter/dist/claude-plugin-loader.js +0 -362
  75. package/node_modules/pi-mcp-adapter/dist/claude-plugin-loader.js.map +0 -1
  76. package/node_modules/pi-mcp-adapter/dist/config.d.ts +0 -134
  77. package/node_modules/pi-mcp-adapter/dist/config.js +0 -1361
  78. package/node_modules/pi-mcp-adapter/dist/config.js.map +0 -1
  79. package/node_modules/pi-mcp-adapter/dist/consent-manager.d.ts +0 -18
  80. package/node_modules/pi-mcp-adapter/dist/consent-manager.js +0 -88
  81. package/node_modules/pi-mcp-adapter/dist/consent-manager.js.map +0 -1
  82. package/node_modules/pi-mcp-adapter/dist/elicitation-handler.d.ts +0 -17
  83. package/node_modules/pi-mcp-adapter/dist/elicitation-handler.js +0 -316
  84. package/node_modules/pi-mcp-adapter/dist/elicitation-handler.js.map +0 -1
  85. package/node_modules/pi-mcp-adapter/dist/errors.d.ts +0 -131
  86. package/node_modules/pi-mcp-adapter/dist/errors.js +0 -278
  87. package/node_modules/pi-mcp-adapter/dist/errors.js.map +0 -1
  88. package/node_modules/pi-mcp-adapter/dist/http-ca.d.ts +0 -8
  89. package/node_modules/pi-mcp-adapter/dist/http-ca.js +0 -88
  90. package/node_modules/pi-mcp-adapter/dist/http-ca.js.map +0 -1
  91. package/node_modules/pi-mcp-adapter/dist/jev-client.d.ts +0 -14
  92. package/node_modules/pi-mcp-adapter/dist/jev-client.js +0 -367
  93. package/node_modules/pi-mcp-adapter/dist/jev-client.js.map +0 -1
  94. package/node_modules/pi-mcp-adapter/dist/jev-contracts.d.ts +0 -77
  95. package/node_modules/pi-mcp-adapter/dist/jev-contracts.js +0 -2
  96. package/node_modules/pi-mcp-adapter/dist/jev-contracts.js.map +0 -1
  97. package/node_modules/pi-mcp-adapter/dist/jev-key-store.d.ts +0 -51
  98. package/node_modules/pi-mcp-adapter/dist/jev-key-store.js +0 -205
  99. package/node_modules/pi-mcp-adapter/dist/jev-key-store.js.map +0 -1
  100. package/node_modules/pi-mcp-adapter/dist/json-schema-validator.d.ts +0 -2
  101. package/node_modules/pi-mcp-adapter/dist/json-schema-validator.js +0 -68
  102. package/node_modules/pi-mcp-adapter/dist/json-schema-validator.js.map +0 -1
  103. package/node_modules/pi-mcp-adapter/dist/lifecycle.d.ts +0 -56
  104. package/node_modules/pi-mcp-adapter/dist/lifecycle.js +0 -410
  105. package/node_modules/pi-mcp-adapter/dist/lifecycle.js.map +0 -1
  106. package/node_modules/pi-mcp-adapter/dist/logger.d.ts +0 -51
  107. package/node_modules/pi-mcp-adapter/dist/logger.js +0 -131
  108. package/node_modules/pi-mcp-adapter/dist/logger.js.map +0 -1
  109. package/node_modules/pi-mcp-adapter/dist/mcp-auth-fetch.d.ts +0 -26
  110. package/node_modules/pi-mcp-adapter/dist/mcp-auth-fetch.js +0 -103
  111. package/node_modules/pi-mcp-adapter/dist/mcp-auth-fetch.js.map +0 -1
  112. package/node_modules/pi-mcp-adapter/dist/mcp-auth-flow.d.ts +0 -118
  113. package/node_modules/pi-mcp-adapter/dist/mcp-auth-flow.js +0 -1097
  114. package/node_modules/pi-mcp-adapter/dist/mcp-auth-flow.js.map +0 -1
  115. package/node_modules/pi-mcp-adapter/dist/mcp-auth.d.ts +0 -170
  116. package/node_modules/pi-mcp-adapter/dist/mcp-auth.js +0 -1142
  117. package/node_modules/pi-mcp-adapter/dist/mcp-auth.js.map +0 -1
  118. package/node_modules/pi-mcp-adapter/dist/mcp-bearer-store.d.ts +0 -24
  119. package/node_modules/pi-mcp-adapter/dist/mcp-bearer-store.js +0 -203
  120. package/node_modules/pi-mcp-adapter/dist/mcp-bearer-store.js.map +0 -1
  121. package/node_modules/pi-mcp-adapter/dist/mcp-callback-server.d.ts +0 -53
  122. package/node_modules/pi-mcp-adapter/dist/mcp-callback-server.js +0 -441
  123. package/node_modules/pi-mcp-adapter/dist/mcp-callback-server.js.map +0 -1
  124. package/node_modules/pi-mcp-adapter/dist/mcp-oauth-provider.d.ts +0 -148
  125. package/node_modules/pi-mcp-adapter/dist/mcp-oauth-provider.js +0 -689
  126. package/node_modules/pi-mcp-adapter/dist/mcp-oauth-provider.js.map +0 -1
  127. package/node_modules/pi-mcp-adapter/dist/mcp-probe.d.ts +0 -6
  128. package/node_modules/pi-mcp-adapter/dist/mcp-probe.js +0 -166
  129. package/node_modules/pi-mcp-adapter/dist/mcp-probe.js.map +0 -1
  130. package/node_modules/pi-mcp-adapter/dist/mcp-tasks.d.ts +0 -102
  131. package/node_modules/pi-mcp-adapter/dist/mcp-tasks.js +0 -369
  132. package/node_modules/pi-mcp-adapter/dist/mcp-tasks.js.map +0 -1
  133. package/node_modules/pi-mcp-adapter/dist/mcp-trace.d.ts +0 -95
  134. package/node_modules/pi-mcp-adapter/dist/mcp-trace.js +0 -242
  135. package/node_modules/pi-mcp-adapter/dist/mcp-trace.js.map +0 -1
  136. package/node_modules/pi-mcp-adapter/dist/metadata-cache.d.ts +0 -19
  137. package/node_modules/pi-mcp-adapter/dist/metadata-cache.js +0 -301
  138. package/node_modules/pi-mcp-adapter/dist/metadata-cache.js.map +0 -1
  139. package/node_modules/pi-mcp-adapter/dist/npx-resolver.d.ts +0 -6
  140. package/node_modules/pi-mcp-adapter/dist/npx-resolver.js +0 -505
  141. package/node_modules/pi-mcp-adapter/dist/npx-resolver.js.map +0 -1
  142. package/node_modules/pi-mcp-adapter/dist/package-mcp-loader.d.ts +0 -2
  143. package/node_modules/pi-mcp-adapter/dist/package-mcp-loader.js +0 -144
  144. package/node_modules/pi-mcp-adapter/dist/package-mcp-loader.js.map +0 -1
  145. package/node_modules/pi-mcp-adapter/dist/request-headers-command.d.ts +0 -10
  146. package/node_modules/pi-mcp-adapter/dist/request-headers-command.js +0 -312
  147. package/node_modules/pi-mcp-adapter/dist/request-headers-command.js.map +0 -1
  148. package/node_modules/pi-mcp-adapter/dist/resource-tools.d.ts +0 -1
  149. package/node_modules/pi-mcp-adapter/dist/resource-tools.js +0 -15
  150. package/node_modules/pi-mcp-adapter/dist/resource-tools.js.map +0 -1
  151. package/node_modules/pi-mcp-adapter/dist/runtime-owner.d.ts +0 -13
  152. package/node_modules/pi-mcp-adapter/dist/runtime-owner.js +0 -97
  153. package/node_modules/pi-mcp-adapter/dist/runtime-owner.js.map +0 -1
  154. package/node_modules/pi-mcp-adapter/dist/sampling-handler.d.ts +0 -17
  155. package/node_modules/pi-mcp-adapter/dist/sampling-handler.js +0 -203
  156. package/node_modules/pi-mcp-adapter/dist/sampling-handler.js.map +0 -1
  157. package/node_modules/pi-mcp-adapter/dist/secure-keyring.d.ts +0 -11
  158. package/node_modules/pi-mcp-adapter/dist/secure-keyring.js +0 -172
  159. package/node_modules/pi-mcp-adapter/dist/secure-keyring.js.map +0 -1
  160. package/node_modules/pi-mcp-adapter/dist/server-manager.d.ts +0 -157
  161. package/node_modules/pi-mcp-adapter/dist/server-manager.js +0 -1745
  162. package/node_modules/pi-mcp-adapter/dist/server-manager.js.map +0 -1
  163. package/node_modules/pi-mcp-adapter/dist/session-approvals.d.ts +0 -34
  164. package/node_modules/pi-mcp-adapter/dist/session-approvals.js +0 -140
  165. package/node_modules/pi-mcp-adapter/dist/session-approvals.js.map +0 -1
  166. package/node_modules/pi-mcp-adapter/dist/session-recovery.d.ts +0 -26
  167. package/node_modules/pi-mcp-adapter/dist/session-recovery.js +0 -142
  168. package/node_modules/pi-mcp-adapter/dist/session-recovery.js.map +0 -1
  169. package/node_modules/pi-mcp-adapter/dist/state.d.ts +0 -73
  170. package/node_modules/pi-mcp-adapter/dist/state.js +0 -2
  171. package/node_modules/pi-mcp-adapter/dist/state.js.map +0 -1
  172. package/node_modules/pi-mcp-adapter/dist/types.d.ts +0 -642
  173. package/node_modules/pi-mcp-adapter/dist/types.js +0 -331
  174. package/node_modules/pi-mcp-adapter/dist/types.js.map +0 -1
  175. package/node_modules/pi-mcp-adapter/dist/ui-app-bridge-helpers.d.ts +0 -6
  176. package/node_modules/pi-mcp-adapter/dist/ui-app-bridge-helpers.js +0 -37
  177. package/node_modules/pi-mcp-adapter/dist/ui-app-bridge-helpers.js.map +0 -1
  178. package/node_modules/pi-mcp-adapter/dist/ui-resource-handler.d.ts +0 -17
  179. package/node_modules/pi-mcp-adapter/dist/ui-resource-handler.js +0 -219
  180. package/node_modules/pi-mcp-adapter/dist/ui-resource-handler.js.map +0 -1
  181. package/node_modules/pi-mcp-adapter/dist/ui-stream-types.d.ts +0 -104
  182. package/node_modules/pi-mcp-adapter/dist/ui-stream-types.js +0 -59
  183. package/node_modules/pi-mcp-adapter/dist/ui-stream-types.js.map +0 -1
  184. package/node_modules/pi-mcp-adapter/dist/ui-tool-visibility.d.ts +0 -4
  185. package/node_modules/pi-mcp-adapter/dist/ui-tool-visibility.js +0 -27
  186. package/node_modules/pi-mcp-adapter/dist/ui-tool-visibility.js.map +0 -1
  187. package/node_modules/pi-mcp-adapter/dist/unix-socket-transport.d.ts +0 -15
  188. package/node_modules/pi-mcp-adapter/dist/unix-socket-transport.js +0 -85
  189. package/node_modules/pi-mcp-adapter/dist/unix-socket-transport.js.map +0 -1
  190. package/node_modules/pi-mcp-adapter/dist/utils.d.ts +0 -41
  191. package/node_modules/pi-mcp-adapter/dist/utils.js +0 -417
  192. package/node_modules/pi-mcp-adapter/dist/utils.js.map +0 -1
  193. package/node_modules/pi-mcp-adapter/elicitation-handler.ts +0 -358
  194. package/node_modules/pi-mcp-adapter/error-signal.ts +0 -32
  195. package/node_modules/pi-mcp-adapter/errors.ts +0 -364
  196. package/node_modules/pi-mcp-adapter/examples/jev-accessibility-loop.mjs +0 -85
  197. package/node_modules/pi-mcp-adapter/examples/jev-semantic-filter.mjs +0 -34
  198. package/node_modules/pi-mcp-adapter/failure-backoff.ts +0 -23
  199. package/node_modules/pi-mcp-adapter/glimpse-ui.ts +0 -80
  200. package/node_modules/pi-mcp-adapter/host-html-template.ts +0 -515
  201. package/node_modules/pi-mcp-adapter/http-ca.ts +0 -84
  202. package/node_modules/pi-mcp-adapter/index.ts +0 -2106
  203. package/node_modules/pi-mcp-adapter/init.ts +0 -721
  204. package/node_modules/pi-mcp-adapter/jev-client.ts +0 -300
  205. package/node_modules/pi-mcp-adapter/jev-contracts.ts +0 -53
  206. package/node_modules/pi-mcp-adapter/jev-key-store.ts +0 -192
  207. package/node_modules/pi-mcp-adapter/json-schema-validator.ts +0 -83
  208. package/node_modules/pi-mcp-adapter/lazy-loader.ts +0 -7
  209. package/node_modules/pi-mcp-adapter/lifecycle.ts +0 -457
  210. package/node_modules/pi-mcp-adapter/logger.ts +0 -169
  211. package/node_modules/pi-mcp-adapter/mcp-auth-fetch.ts +0 -113
  212. package/node_modules/pi-mcp-adapter/mcp-auth-flow.ts +0 -1296
  213. package/node_modules/pi-mcp-adapter/mcp-auth.ts +0 -1287
  214. package/node_modules/pi-mcp-adapter/mcp-bearer-store.ts +0 -250
  215. package/node_modules/pi-mcp-adapter/mcp-callback-server.ts +0 -534
  216. package/node_modules/pi-mcp-adapter/mcp-code.ts +0 -495
  217. package/node_modules/pi-mcp-adapter/mcp-install.ts +0 -60
  218. package/node_modules/pi-mcp-adapter/mcp-keyring-helper.cjs +0 -89
  219. package/node_modules/pi-mcp-adapter/mcp-oauth-provider.ts +0 -819
  220. package/node_modules/pi-mcp-adapter/mcp-output-guard.ts +0 -511
  221. package/node_modules/pi-mcp-adapter/mcp-panel-theme.ts +0 -104
  222. package/node_modules/pi-mcp-adapter/mcp-panel.ts +0 -1099
  223. package/node_modules/pi-mcp-adapter/mcp-probe.ts +0 -201
  224. package/node_modules/pi-mcp-adapter/mcp-references.ts +0 -373
  225. package/node_modules/pi-mcp-adapter/mcp-script-worker.mjs +0 -137
  226. package/node_modules/pi-mcp-adapter/mcp-setup-panel.ts +0 -747
  227. package/node_modules/pi-mcp-adapter/mcp-status.ts +0 -105
  228. package/node_modules/pi-mcp-adapter/mcp-tasks.ts +0 -467
  229. package/node_modules/pi-mcp-adapter/mcp-trace.ts +0 -306
  230. package/node_modules/pi-mcp-adapter/metadata-cache.ts +0 -362
  231. package/node_modules/pi-mcp-adapter/namespace-tools.ts +0 -334
  232. package/node_modules/pi-mcp-adapter/npx-resolver.ts +0 -543
  233. package/node_modules/pi-mcp-adapter/oauth-handler.ts +0 -30
  234. package/node_modules/pi-mcp-adapter/oauth.ts +0 -52
  235. package/node_modules/pi-mcp-adapter/onboarding-state.ts +0 -76
  236. package/node_modules/pi-mcp-adapter/package-mcp-loader.ts +0 -156
  237. package/node_modules/pi-mcp-adapter/package.json +0 -219
  238. package/node_modules/pi-mcp-adapter/panel-keys.ts +0 -53
  239. package/node_modules/pi-mcp-adapter/prompts.ts +0 -385
  240. package/node_modules/pi-mcp-adapter/proxy-modes.ts +0 -1735
  241. package/node_modules/pi-mcp-adapter/request-headers-command.ts +0 -333
  242. package/node_modules/pi-mcp-adapter/resource-tools.ts +0 -17
  243. package/node_modules/pi-mcp-adapter/runtime-owner.ts +0 -106
  244. package/node_modules/pi-mcp-adapter/sampling-handler.ts +0 -261
  245. package/node_modules/pi-mcp-adapter/sandbox-proxy-template.ts +0 -144
  246. package/node_modules/pi-mcp-adapter/search-ranking.ts +0 -309
  247. package/node_modules/pi-mcp-adapter/secure-keyring.ts +0 -170
  248. package/node_modules/pi-mcp-adapter/semantic-search.ts +0 -186
  249. package/node_modules/pi-mcp-adapter/server-manager.ts +0 -2088
  250. package/node_modules/pi-mcp-adapter/session-approvals.ts +0 -201
  251. package/node_modules/pi-mcp-adapter/session-recovery.ts +0 -158
  252. package/node_modules/pi-mcp-adapter/skills/mcp-scripting/SKILL.md +0 -49
  253. package/node_modules/pi-mcp-adapter/state.ts +0 -71
  254. package/node_modules/pi-mcp-adapter/tool-approval.ts +0 -205
  255. package/node_modules/pi-mcp-adapter/tool-metadata.ts +0 -302
  256. package/node_modules/pi-mcp-adapter/tool-registrar.ts +0 -255
  257. package/node_modules/pi-mcp-adapter/tool-result-renderer.ts +0 -573
  258. package/node_modules/pi-mcp-adapter/ts-shape.ts +0 -149
  259. package/node_modules/pi-mcp-adapter/types.ts +0 -1120
  260. package/node_modules/pi-mcp-adapter/ui-app-bridge-helpers.ts +0 -40
  261. package/node_modules/pi-mcp-adapter/ui-resource-handler.ts +0 -266
  262. package/node_modules/pi-mcp-adapter/ui-server.ts +0 -993
  263. package/node_modules/pi-mcp-adapter/ui-session.ts +0 -624
  264. package/node_modules/pi-mcp-adapter/ui-stream-types.ts +0 -89
  265. package/node_modules/pi-mcp-adapter/ui-tool-visibility.ts +0 -25
  266. package/node_modules/pi-mcp-adapter/unix-socket-transport.ts +0 -85
  267. package/node_modules/pi-mcp-adapter/utils.ts +0 -464
@@ -1,358 +0,0 @@
1
- import type { ExtensionUIContext } from "@earendil-works/pi-coding-agent";
2
- import type { Client } from "@modelcontextprotocol/client";
3
- import {
4
- ProtocolError,
5
- ProtocolErrorCode,
6
- type ElicitRequest,
7
- type ElicitRequestFormParams,
8
- type ElicitRequestURLParams,
9
- type ElicitResult,
10
- } from "@modelcontextprotocol/client";
11
- import { AjvJsonSchemaValidator } from "@modelcontextprotocol/client/validators/ajv";
12
- import type { JsonSchemaType } from "@modelcontextprotocol/client";
13
- import open from "open";
14
- import { abortable, throwIfAborted } from "./abort.ts";
15
-
16
- export type ElicitationValue = string | number | boolean | string[] | undefined;
17
- type FormProperty = ElicitRequestFormParams["requestedSchema"]["properties"][string];
18
- type FieldCollectionResult = { status: "cancelled" } | { status: "collected"; value: ElicitationValue };
19
-
20
- export type ElicitationUIContext = Pick<ExtensionUIContext, "select" | "input" | "notify">;
21
-
22
- export interface ElicitationHandlerOptions {
23
- serverName: string;
24
- ui: ElicitationUIContext;
25
- allowUrl: boolean;
26
- onUrlAccepted?: (elicitationId: string) => void;
27
- }
28
-
29
- export type ServerElicitationConfig = Omit<ElicitationHandlerOptions, "serverName" | "onUrlAccepted">;
30
-
31
- export function registerElicitationHandler(client: Client, options: ElicitationHandlerOptions): void {
32
- client.setRequestHandler("elicitation/create", request =>
33
- handleElicitationRequest(options, request));
34
- }
35
-
36
- export async function handleElicitationRequest(
37
- options: ElicitationHandlerOptions,
38
- request: ElicitRequest,
39
- signal?: AbortSignal,
40
- ): Promise<ElicitResult> {
41
- throwIfAborted(signal);
42
- return request.params.mode === "url"
43
- ? handleUrlElicitation(options, request.params, signal)
44
- : handleFormElicitation(options, request.params, signal);
45
- }
46
-
47
- export async function handleFormElicitation(
48
- options: ElicitationHandlerOptions,
49
- params: ElicitRequestFormParams,
50
- signal?: AbortSignal,
51
- ): Promise<ElicitResult> {
52
- const properties = Object.entries(params.requestedSchema.properties);
53
- const decision = await abortable(options.ui.select(
54
- `MCP Input Request\nServer: ${options.serverName}\n\n${params.message}`,
55
- ["Continue", "Decline"],
56
- ), signal);
57
- if (decision === undefined) return { action: "cancel" };
58
- if (decision === "Decline") return { action: "decline" };
59
- if (properties.length === 0) return { action: "accept", content: {} };
60
-
61
- const values: Record<string, ElicitationValue> = {};
62
- for (const [name, schema] of properties) {
63
- const value = await collectValidField(options.ui, params, name, schema, undefined, signal);
64
- if (value.status === "cancelled") return { action: "cancel" };
65
- values[name] = value.value;
66
- }
67
-
68
- while (true) {
69
- const content = coerceAndValidateFormValues(params, values);
70
- const action = await abortable(options.ui.select(
71
- formatReview(options.serverName, properties, content),
72
- ["Submit", "Edit", "Decline"],
73
- ), signal);
74
- if (action === undefined) return { action: "cancel" };
75
- if (action === "Decline") return { action: "decline" };
76
- if (action === "Submit") return { action: "accept", content };
77
-
78
- const labels = properties.map(([name, schema]) => `${schema.title ?? humanizeName(name)} (${name})`);
79
- const selected = await abortable(options.ui.select("Choose a field to edit", labels), signal);
80
- if (selected === undefined) return { action: "cancel" };
81
- const property = properties[labels.indexOf(selected)];
82
- if (!property) continue;
83
- const [name, schema] = property;
84
- const value = await collectValidField(options.ui, params, name, schema, values[name], signal);
85
- if (value.status === "cancelled") return { action: "cancel" };
86
- values[name] = value.value;
87
- }
88
- }
89
-
90
- async function collectValidField(
91
- ui: ElicitationUIContext,
92
- params: ElicitRequestFormParams,
93
- name: string,
94
- schema: FormProperty,
95
- current?: ElicitationValue,
96
- signal?: AbortSignal,
97
- ): Promise<FieldCollectionResult> {
98
- const required = params.requestedSchema.required?.includes(name) === true;
99
- while (true) {
100
- const result = await collectField(ui, params, name, schema, current, signal);
101
- if (result.status === "cancelled") return result;
102
- try {
103
- coerceAndValidateFormValues({
104
- ...params,
105
- requestedSchema: {
106
- type: "object",
107
- properties: { [name]: schema },
108
- ...(required ? { required: [name] } : {}),
109
- },
110
- }, { [name]: result.value });
111
- return result;
112
- } catch (error) {
113
- ui.notify(error instanceof Error ? error.message : String(error), "error");
114
- current = result.value;
115
- }
116
- }
117
- }
118
-
119
- async function collectField(
120
- ui: ElicitationUIContext,
121
- params: ElicitRequestFormParams,
122
- name: string,
123
- schema: FormProperty,
124
- current?: ElicitationValue,
125
- signal?: AbortSignal,
126
- ): Promise<FieldCollectionResult> {
127
- const required = params.requestedSchema.required?.includes(name) === true;
128
- const title = [schema.title ?? humanizeName(name), required ? "(required)" : "", schema.description]
129
- .filter(Boolean)
130
- .join(" ");
131
-
132
- if (schema.type === "string" && ("enum" in schema || "oneOf" in schema)) {
133
- const choices = "oneOf" in schema
134
- ? schema.oneOf.map(option => ({ value: option.const, display: formatChoice(option.const, option.title) }))
135
- : schema.enum.map((value, index) => ({
136
- value,
137
- display: formatChoice(value, "enumNames" in schema ? schema.enumNames?.[index] : undefined),
138
- }));
139
- const displays = uniqueLabels(choices.map(choice => choice.display));
140
- const actions = [...displays];
141
- const useDefault = schema.default === undefined ? undefined : uniqueAction("Use default", actions);
142
- if (useDefault) actions.push(useDefault);
143
- const omit = required ? undefined : uniqueAction("Omit", actions);
144
- if (omit) actions.push(omit);
145
- const action = await abortable(ui.select(title, actions), signal);
146
- if (action === undefined) return { status: "cancelled" };
147
- if (action === useDefault) return { status: "collected", value: schema.default };
148
- if (action === omit) return { status: "collected", value: undefined };
149
- return { status: "collected", value: choices[displays.indexOf(action)]?.value };
150
- }
151
-
152
- if (schema.type === "boolean") {
153
- const actions = ["Yes", "No"];
154
- if (schema.default !== undefined) actions.push("Use default");
155
- if (!required) actions.push("Omit");
156
- const action = await abortable(ui.select(title, actions), signal);
157
- if (action === undefined) return { status: "cancelled" };
158
- if (action === "Use default") return { status: "collected", value: schema.default };
159
- if (action === "Omit") return { status: "collected", value: undefined };
160
- return { status: "collected", value: action === "Yes" };
161
- }
162
-
163
- if (schema.type === "array") {
164
- const actions = ["Choose values"];
165
- if (schema.default !== undefined) actions.push("Use default");
166
- if (!required) actions.push("Omit");
167
- const action = await abortable(ui.select(title, actions), signal);
168
- if (action === undefined) return { status: "cancelled" };
169
- if (action === "Use default") return { status: "collected", value: schema.default };
170
- if (action === "Omit") return { status: "collected", value: undefined };
171
-
172
- const choices = extractMultiSelectOptions(schema);
173
- const selected = new Set(Array.isArray(current) ? current : []);
174
- while (true) {
175
- const displays = uniqueLabels(choices.map(choice => selected.has(choice.value) ? `✓ ${choice.display}` : choice.display));
176
- const done = uniqueAction("Done", displays);
177
- const picked = await abortable(ui.select(title, [...displays, done]), signal);
178
- if (picked === undefined) return { status: "cancelled" };
179
- if (picked === done) return { status: "collected", value: [...selected] };
180
- const choice = choices[displays.indexOf(picked)];
181
- if (!choice) continue;
182
- if (selected.has(choice.value)) selected.delete(choice.value);
183
- else selected.add(choice.value);
184
- }
185
- }
186
-
187
- const actions = ["Enter value"];
188
- if (schema.default !== undefined) actions.push("Use default");
189
- if (!required) actions.push("Omit");
190
- const action = await abortable(ui.select(title, actions), signal);
191
- if (action === undefined) return { status: "cancelled" };
192
- if (action === "Use default") return { status: "collected", value: schema.default };
193
- if (action === "Omit") return { status: "collected", value: undefined };
194
- const entered = await abortable(ui.input(title, current === undefined ? undefined : String(current)), signal);
195
- return entered === undefined ? { status: "cancelled" } : { status: "collected", value: entered };
196
- }
197
-
198
- export function coerceAndValidateFormValues(
199
- params: ElicitRequestFormParams,
200
- values: Record<string, ElicitationValue>,
201
- ): Record<string, string | number | boolean | string[]> {
202
- const output: Record<string, string | number | boolean | string[]> = {};
203
- const required = new Set(params.requestedSchema.required ?? []);
204
- for (const [name, schema] of Object.entries(params.requestedSchema.properties)) {
205
- const value = values[name];
206
- if (value === undefined) {
207
- if (required.has(name)) throw new Error(`Missing required elicitation field: ${name}`);
208
- continue;
209
- }
210
- if (schema.type === "string") {
211
- const stringValue = String(value);
212
- const limits = schema as typeof schema & { minLength?: number; maxLength?: number };
213
- if (limits.minLength !== undefined && stringValue.length < limits.minLength) {
214
- throw new Error(`Elicitation field ${name} is shorter than minimum length ${limits.minLength}`);
215
- }
216
- if (limits.maxLength !== undefined && stringValue.length > limits.maxLength) {
217
- throw new Error(`Elicitation field ${name} is longer than maximum length ${limits.maxLength}`);
218
- }
219
- if ("enum" in schema && !schema.enum.includes(stringValue)) {
220
- throw new Error(`Elicitation field ${name} is not an allowed value`);
221
- }
222
- if ("oneOf" in schema && !schema.oneOf.some(option => option.const === stringValue)) {
223
- throw new Error(`Elicitation field ${name} is not an allowed value`);
224
- }
225
- output[name] = stringValue;
226
- continue;
227
- }
228
- if (schema.type === "number" || schema.type === "integer") {
229
- if (typeof value === "string" && value.trim() === "") {
230
- throw new Error(`Elicitation field ${name} must be a number`);
231
- }
232
- const numberValue = typeof value === "number" ? value : Number(value);
233
- if (!Number.isFinite(numberValue)) throw new Error(`Elicitation field ${name} must be a number`);
234
- if (schema.type === "integer" && !Number.isInteger(numberValue)) {
235
- throw new Error(`Elicitation field ${name} must be an integer`);
236
- }
237
- if (schema.minimum !== undefined && numberValue < schema.minimum) {
238
- throw new Error(`Elicitation field ${name} is below minimum ${schema.minimum}`);
239
- }
240
- if (schema.maximum !== undefined && numberValue > schema.maximum) {
241
- throw new Error(`Elicitation field ${name} is above maximum ${schema.maximum}`);
242
- }
243
- output[name] = numberValue;
244
- continue;
245
- }
246
- if (schema.type === "boolean") {
247
- output[name] = typeof value === "boolean" ? value : value === "true";
248
- continue;
249
- }
250
- if (schema.type === "array") {
251
- if (!Array.isArray(value)) throw new Error(`Elicitation field ${name} must be a list`);
252
- const allowed = new Set(extractMultiSelectOptions(schema).map(option => option.value));
253
- const arrayValue = value.map(String);
254
- if (schema.minItems !== undefined && arrayValue.length < schema.minItems) {
255
- throw new Error(`Elicitation field ${name} has fewer than ${schema.minItems} selections`);
256
- }
257
- if (schema.maxItems !== undefined && arrayValue.length > schema.maxItems) {
258
- throw new Error(`Elicitation field ${name} has more than ${schema.maxItems} selections`);
259
- }
260
- if (arrayValue.some(item => !allowed.has(item))) {
261
- throw new Error(`Elicitation field ${name} contains an invalid selection`);
262
- }
263
- output[name] = arrayValue;
264
- }
265
- }
266
- const validation = new AjvJsonSchemaValidator()
267
- .getValidator(params.requestedSchema as JsonSchemaType)(output);
268
- if (!validation.valid) {
269
- throw new Error(`Invalid elicitation response: ${validation.errorMessage}`);
270
- }
271
- return output;
272
- }
273
-
274
- function formatChoice(value: string, title?: string): string {
275
- return title && title !== value ? `${title} (${value})` : value;
276
- }
277
-
278
- function uniqueLabels(labels: string[]): string[] {
279
- const used = new Set<string>();
280
- return labels.map(label => {
281
- let unique = label;
282
- while (used.has(unique)) unique += "…";
283
- used.add(unique);
284
- return unique;
285
- });
286
- }
287
-
288
- function uniqueAction(label: string, choices: string[]): string {
289
- let unique = label;
290
- while (choices.includes(unique)) unique += "…";
291
- return unique;
292
- }
293
-
294
- function extractMultiSelectOptions(schema: Extract<FormProperty, { type: "array" }>): Array<{ value: string; display: string }> {
295
- const items = schema.items as { enum?: string[]; anyOf?: Array<{ const: string; title: string }> };
296
- return items.anyOf
297
- ? items.anyOf.map(option => ({ value: option.const, display: formatChoice(option.const, option.title) }))
298
- : (items.enum ?? []).map(value => ({ value, display: value }));
299
- }
300
-
301
- function formatReview(
302
- serverName: string,
303
- properties: Array<[string, FormProperty]>,
304
- content: Record<string, string | number | boolean | string[]>,
305
- ): string {
306
- const rows = properties.map(([name, schema]) =>
307
- `${schema.title ?? humanizeName(name)}: ${content[name] === undefined ? "(omitted)" : String(content[name])}`);
308
- return [`Review input for ${serverName}`, "", ...rows].join("\n");
309
- }
310
-
311
- export async function handleUrlElicitation(
312
- options: ElicitationHandlerOptions,
313
- params: ElicitRequestURLParams,
314
- signal?: AbortSignal,
315
- ): Promise<ElicitResult> {
316
- throwIfAborted(signal);
317
- if (!options.allowUrl) throw new ProtocolError(ProtocolErrorCode.InvalidParams, "URL elicitation is not supported");
318
-
319
- let parsed: URL;
320
- try {
321
- parsed = new URL(params.url);
322
- } catch {
323
- throw new ProtocolError(ProtocolErrorCode.InvalidParams, "URL elicitation supplied an invalid URL");
324
- }
325
- if (parsed.protocol !== "http:" && parsed.protocol !== "https:") {
326
- throw new ProtocolError(ProtocolErrorCode.InvalidParams, "URL elicitation only supports HTTP and HTTPS URLs");
327
- }
328
-
329
- const decision = await abortable(options.ui.select([
330
- "MCP Browser Request",
331
- `Server: ${options.serverName}`,
332
- "",
333
- params.message,
334
- "",
335
- `Host: ${parsed.host}`,
336
- `Full URL: ${params.url}`,
337
- "",
338
- "Open this URL in your browser?",
339
- ].join("\n"), ["Open", "Decline"]), signal);
340
- if (decision === undefined) return { action: "cancel" };
341
- if (decision === "Decline") return { action: "decline" };
342
-
343
- try {
344
- await abortable(open(params.url), signal);
345
- } catch (error) {
346
- throwIfAborted(signal);
347
- options.ui.notify(`Could not open MCP elicitation URL: ${error instanceof Error ? error.message : String(error)}`, "error");
348
- return { action: "cancel" };
349
- }
350
- throwIfAborted(signal);
351
- options.onUrlAccepted?.(params.elicitationId);
352
- options.ui.notify("Opened browser for MCP elicitation.", "info");
353
- return { action: "accept" };
354
- }
355
-
356
- function humanizeName(name: string): string {
357
- return name.replace(/[_-]+/g, " ").replace(/([a-z0-9])([A-Z])/g, "$1 $2").replace(/^./, char => char.toUpperCase());
358
- }
@@ -1,32 +0,0 @@
1
- import { INPUT_REQUIRED_NEEDS_UI } from "./errors.ts";
2
-
3
- /**
4
- * Decide the `isError` override for a finished tool result in the `tool_result` hook.
5
- *
6
- * A failed MCP tool call is *returned* (not thrown), tagged `details.error: "tool_error"` (the server
7
- * returned an error result), `"call_failed"` (the call itself threw and was caught), or a typed
8
- * input-required failure that could not run without UI. pi never reads a result-level `isError`,
9
- * so without this such a call is recorded as a success. Returning
10
- * `{ isError: true }` (and nothing else) flips the flag; pi's field-by-field merge keeps the original
11
- * `content` and `details` intact.
12
- *
13
- * Limited to execution-failure codes: the adapter's other `details.error` values (`auth_required`, connection
14
- * states, search/validation feedback, ...) are not failed tool calls, so they get no override.
15
- */
16
- export function toolErrorOverride(details: unknown): { isError: true } | undefined {
17
- if (details && typeof details === "object" && "error" in details) {
18
- const code = (details as { error?: unknown }).error;
19
- if (code === "tool_error" || code === "call_failed" || code === INPUT_REQUIRED_NEEDS_UI) {
20
- return { isError: true };
21
- }
22
- }
23
- if (details && typeof details === "object" && (details as { mode?: unknown }).mode === "script") {
24
- const calls = (details as { calls?: unknown }).calls;
25
- if (Array.isArray(calls) && calls.some((call) => (
26
- !!call && typeof call === "object" && (call as { error?: unknown }).error === INPUT_REQUIRED_NEEDS_UI
27
- ))) {
28
- return { isError: true };
29
- }
30
- }
31
- return undefined;
32
- }