@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,261 +0,0 @@
1
- import type { Api, AssistantMessage, Message, Model, TextContent } from "@earendil-works/pi-ai";
2
- import { truncateAtWord } from "./utils.ts";
3
- import { throwIfAborted } from "./abort.ts";
4
- import type { ExtensionUIContext, ModelRegistry } from "@earendil-works/pi-coding-agent";
5
- import type { Client } from "@modelcontextprotocol/client";
6
- import {
7
- type CreateMessageRequest,
8
- type CreateMessageResult,
9
- type ModelPreferences,
10
- type SamplingMessage,
11
- type SamplingMessageContentBlock,
12
- } from "@modelcontextprotocol/client";
13
-
14
- export type SamplingUIContext = Pick<ExtensionUIContext, "confirm">;
15
- export type SamplingModelRegistry = Pick<ModelRegistry, "getAvailable" | "complete">;
16
-
17
- export interface SamplingHandlerOptions {
18
- serverName: string;
19
- autoApprove: boolean;
20
- ui?: SamplingUIContext;
21
- modelRegistry: SamplingModelRegistry;
22
- getCurrentModel: () => Model<Api> | undefined;
23
- getSignal: () => AbortSignal | undefined;
24
- }
25
-
26
- export type ServerSamplingConfig = Omit<SamplingHandlerOptions, "serverName">;
27
-
28
- export function registerSamplingHandler(client: Client, options: SamplingHandlerOptions): void {
29
- client.setRequestHandler("sampling/createMessage", request => {
30
- return handleSamplingRequest(options, request);
31
- });
32
- }
33
-
34
- export async function handleSamplingRequest(
35
- options: SamplingHandlerOptions,
36
- request: CreateMessageRequest,
37
- ): Promise<CreateMessageResult> {
38
- const params = request.params;
39
- const signal = options.getSignal();
40
- throwIfAborted(signal);
41
-
42
- if ("task" in params && params.task) {
43
- throw new Error("MCP sampling tasks are not supported");
44
- }
45
- if (params.includeContext && params.includeContext !== "none") {
46
- throw new Error("MCP sampling context inclusion is not supported");
47
- }
48
- if (params.tools?.length) {
49
- throw new Error("MCP sampling tool use is not supported");
50
- }
51
- if (params.toolChoice) {
52
- throw new Error("MCP sampling tool choice is not supported");
53
- }
54
- if (params.stopSequences?.length) {
55
- throw new Error("MCP sampling stop sequences are not supported");
56
- }
57
-
58
- const messages = params.messages.map(convertSamplingMessage);
59
- const model = resolveSamplingModel(options, params.modelPreferences);
60
- throwIfAborted(signal);
61
- await confirmSampling(
62
- options,
63
- "Approve MCP sampling request",
64
- formatRequestApproval(options.serverName, `${model.provider}/${model.id}`, params.systemPrompt, messages),
65
- );
66
- throwIfAborted(signal);
67
-
68
- const result = await options.modelRegistry.complete(
69
- model,
70
- {
71
- ...(params.systemPrompt !== undefined ? { systemPrompt: params.systemPrompt } : {}),
72
- messages,
73
- },
74
- {
75
- maxTokens: params.maxTokens,
76
- ...(params.temperature !== undefined ? { temperature: params.temperature } : {}),
77
- ...(params.metadata !== undefined ? { metadata: params.metadata as Record<string, unknown> } : {}),
78
- ...(signal ? { signal } : {}),
79
- },
80
- );
81
-
82
- const converted = convertAssistantResult(result);
83
- throwIfAborted(signal);
84
- await confirmSampling(
85
- options,
86
- "Return MCP sampling response",
87
- formatResponseApproval(options.serverName, converted),
88
- );
89
- return converted;
90
- }
91
-
92
- function formatRequestApproval(
93
- serverName: string,
94
- modelName: string,
95
- systemPrompt: string | undefined,
96
- messages: Message[],
97
- ): string {
98
- const lines = [`${serverName} wants to sample ${messages.length} message${messages.length === 1 ? "" : "s"} with ${modelName}.`];
99
- if (systemPrompt) {
100
- lines.push(`System: ${truncateAtWord(systemPrompt, 400)}`);
101
- }
102
- for (const [index, message] of messages.entries()) {
103
- lines.push(`${index + 1}. ${message.role}: ${truncateAtWord(messageText(message), 400)}`);
104
- }
105
- return lines.join("\n\n");
106
- }
107
-
108
- function formatResponseApproval(serverName: string, response: CreateMessageResult): string {
109
- const text = response.content.type === "text" ? response.content.text : `[${response.content.type} content]`;
110
- return `${serverName} will receive this response from ${response.model}:\n\n${truncateAtWord(text, 1000)}`;
111
- }
112
-
113
- function messageText(message: Message): string {
114
- if (typeof message.content === "string") return message.content;
115
- return message.content.map((block) => {
116
- if (block.type === "text") return block.text;
117
- if (block.type === "image") return `[image: ${block.mimeType}]`;
118
- if (block.type === "thinking") return "[thinking]";
119
- if (block.type === "toolCall") return `[tool call: ${block.name}]`;
120
- return "[content]";
121
- }).join("\n");
122
- }
123
-
124
- function resolveSamplingModel(
125
- options: SamplingHandlerOptions,
126
- modelPreferences: ModelPreferences | undefined,
127
- ): Model<Api> {
128
- const candidates: Model<Api>[] = [];
129
- const availableModels = options.modelRegistry.getAvailable();
130
-
131
- for (const hint of modelPreferences?.hints ?? []) {
132
- const normalizedHint = hint.name?.trim().toLowerCase();
133
- if (!normalizedHint) continue;
134
- for (const model of availableModels) {
135
- const searchableNames = [`${model.provider}/${model.id}`, model.id, model.name];
136
- if (searchableNames.some((name) => name.toLowerCase().includes(normalizedHint))) {
137
- addSamplingCandidate(candidates, model);
138
- }
139
- }
140
- }
141
-
142
- const currentModel = options.getCurrentModel();
143
- if (currentModel) addSamplingCandidate(candidates, currentModel);
144
-
145
- for (const model of availableModels) {
146
- addSamplingCandidate(candidates, model);
147
- }
148
-
149
- const signal = options.getSignal();
150
- throwIfAborted(signal);
151
- const model = candidates[0];
152
- if (model) return model;
153
- throw new Error("No Pi model is available for MCP sampling");
154
- }
155
-
156
- function addSamplingCandidate(candidates: Model<Api>[], model: Model<Api>): void {
157
- if (!candidates.some((candidate) => candidate.provider === model.provider && candidate.id === model.id)) {
158
- candidates.push(model);
159
- }
160
- }
161
-
162
- async function confirmSampling(options: SamplingHandlerOptions, title: string, message: string): Promise<void> {
163
- if (options.autoApprove) return;
164
- if (!options.ui) {
165
- throw new Error("MCP sampling requires interactive approval. Set settings.samplingAutoApprove to true to allow it without UI.");
166
- }
167
- const approved = await options.ui.confirm(title, message);
168
- if (!approved) {
169
- throw new Error("MCP sampling request was declined");
170
- }
171
- }
172
-
173
- function convertSamplingMessage(message: SamplingMessage): Message {
174
- const blocks = Array.isArray(message.content) ? message.content : [message.content];
175
- if (message.role === "user") {
176
- return {
177
- role: "user",
178
- content: blocks.map(convertUserContent),
179
- timestamp: Date.now(),
180
- };
181
- }
182
-
183
- return {
184
- role: "assistant",
185
- content: blocks.map(convertAssistantContent),
186
- api: "mcp-sampling",
187
- provider: "mcp",
188
- model: "sampling-request",
189
- usage: zeroUsage(),
190
- stopReason: "stop",
191
- timestamp: Date.now(),
192
- };
193
- }
194
-
195
- function convertUserContent(block: SamplingMessageContentBlock): TextContent {
196
- if (block.type === "text") {
197
- return { type: "text", text: block.text };
198
- }
199
- throw new Error(`MCP sampling ${block.type} content is not supported`);
200
- }
201
-
202
- function convertAssistantContent(block: SamplingMessageContentBlock): TextContent {
203
- if (block.type === "text") {
204
- return { type: "text", text: block.text };
205
- }
206
- throw new Error(`MCP sampling assistant ${block.type} content is not supported`);
207
- }
208
-
209
- function convertAssistantResult(message: AssistantMessage): CreateMessageResult {
210
- if (message.stopReason === "error") {
211
- throw new Error(message.errorMessage ?? "MCP sampling model call failed");
212
- }
213
- if (message.stopReason === "aborted") {
214
- throw new Error(message.errorMessage ?? "MCP sampling model call was aborted");
215
- }
216
-
217
- const text = message.content
218
- .map((block) => {
219
- if (block.type === "text") return block.text;
220
- if (block.type === "thinking") return undefined;
221
- throw new Error(`MCP sampling result ${block.type} content is not supported`);
222
- })
223
- .filter((value): value is string => value !== undefined)
224
- .join("\n\n")
225
- .trim();
226
-
227
- if (!text) {
228
- throw new Error("MCP sampling result did not contain text content");
229
- }
230
-
231
- return {
232
- role: "assistant",
233
- content: { type: "text", text },
234
- model: `${message.provider}/${message.model}`,
235
- stopReason: mapStopReason(message.stopReason),
236
- };
237
- }
238
-
239
- function mapStopReason(reason: AssistantMessage["stopReason"]): CreateMessageResult["stopReason"] {
240
- if (reason === "stop") return "endTurn";
241
- if (reason === "length") return "maxTokens";
242
- if (reason === "toolUse") return "toolUse";
243
- return reason;
244
- }
245
-
246
- function zeroUsage(): AssistantMessage["usage"] {
247
- return {
248
- input: 0,
249
- output: 0,
250
- cacheRead: 0,
251
- cacheWrite: 0,
252
- totalTokens: 0,
253
- cost: {
254
- input: 0,
255
- output: 0,
256
- cacheRead: 0,
257
- cacheWrite: 0,
258
- total: 0,
259
- },
260
- };
261
- }
@@ -1,144 +0,0 @@
1
- /**
2
- * The proxy is served from a different loopback origin than the trusted host.
3
- * `allow-same-origin` is safe here because this document never contains the
4
- * host's session capability; provider HTML is loaded into the nested frame.
5
- */
6
- export const SANDBOX_PROXY_SANDBOX =
7
- "allow-scripts allow-forms allow-modals allow-popups allow-downloads allow-same-origin";
8
- export const SANDBOX_INNER_SANDBOX = SANDBOX_PROXY_SANDBOX;
9
- export const SANDBOX_PROXY_PATH = "/sandbox";
10
- export const SANDBOX_RESOURCE_PATH_PREFIX = "/resource/";
11
-
12
- export interface SandboxProxyTemplateInput {
13
- parentOrigin: string;
14
- resourcePath: string;
15
- allowAttribute: string;
16
- }
17
-
18
- /**
19
- * Build the static document used by the trusted, second-origin sandbox proxy.
20
- * The per-session values are the exact parent host origin and opaque resource path.
21
- */
22
- export function buildSandboxProxyHtml(input: SandboxProxyTemplateInput): string {
23
- const parentOrigin = safeInlineJSON(input.parentOrigin);
24
- const resourcePath = safeInlineJSON(input.resourcePath);
25
- const allowAttribute = escapeHtmlAttribute(input.allowAttribute);
26
-
27
- return `<!doctype html>
28
- <html lang="en">
29
- <head>
30
- <meta charset="utf-8" />
31
- <meta name="viewport" content="width=device-width, initial-scale=1" />
32
- <title>MCP App Sandbox</title>
33
- <style>
34
- html, body { margin: 0; padding: 0; width: 100%; height: 100%; overflow: hidden; background: transparent; }
35
- iframe { display: block; width: 100%; height: 100%; border: 0; }
36
- </style>
37
- </head>
38
- <body>
39
- <iframe id="mcp-app" title="MCP App" sandbox="${SANDBOX_INNER_SANDBOX}" allow="${allowAttribute}" referrerpolicy="no-referrer"></iframe>
40
- <script>
41
- const EXPECTED_PARENT_ORIGIN = ${parentOrigin};
42
- const RESOURCE_PATH = ${resourcePath};
43
- const SANDBOX_PROXY_READY_METHOD = "ui/notifications/sandbox-proxy-ready";
44
- const SANDBOX_RESOURCE_READY_METHOD = "ui/notifications/sandbox-resource-ready";
45
- const MAX_PENDING_MESSAGES = 64;
46
- const innerFrame = document.getElementById("mcp-app");
47
- const pendingToInner = [];
48
- let innerReady = false;
49
-
50
- innerFrame.addEventListener("load", () => {
51
- if (innerFrame.getAttribute("src") === RESOURCE_PATH) flushPendingMessages();
52
- });
53
-
54
- const isObject = (value) => value !== null && typeof value === "object";
55
- const isMessageFromParent = (event) =>
56
- event.source === window.parent && event.origin === EXPECTED_PARENT_ORIGIN;
57
- const isMessageFromInner = (event) =>
58
- event.source === innerFrame.contentWindow && event.origin === window.location.origin;
59
-
60
- const postToParent = (data) => {
61
- window.parent.postMessage(data, EXPECTED_PARENT_ORIGIN);
62
- };
63
-
64
- const postToInner = (data) => {
65
- if (!innerReady || !innerFrame.contentWindow) {
66
- if (pendingToInner.length < MAX_PENDING_MESSAGES) pendingToInner.push(data);
67
- return;
68
- }
69
- innerFrame.contentWindow.postMessage(data, window.location.origin);
70
- };
71
-
72
- const flushPendingMessages = () => {
73
- if (!innerFrame.contentWindow) return;
74
- innerReady = true;
75
- for (const data of pendingToInner.splice(0)) {
76
- innerFrame.contentWindow.postMessage(data, window.location.origin);
77
- }
78
- };
79
-
80
- window.addEventListener("message", (event) => {
81
- if (isMessageFromParent(event)) {
82
- const data = event.data;
83
- if (!isObject(data)) return;
84
- if (data.method === SANDBOX_RESOURCE_READY_METHOD) {
85
- innerReady = false;
86
- innerFrame.setAttribute("src", RESOURCE_PATH);
87
- return;
88
- }
89
- if (data.method === SANDBOX_PROXY_READY_METHOD) return;
90
- if (typeof data.method === "string" && data.method.startsWith("ui/notifications/sandbox-")) return;
91
- postToInner(data);
92
- return;
93
- }
94
-
95
- if (!isMessageFromInner(event)) return;
96
- const data = event.data;
97
- if (!isObject(data)) return;
98
- if (typeof data.method === "string" && data.method.startsWith("ui/notifications/sandbox-")) return;
99
- postToParent(data);
100
- });
101
-
102
- postToParent({
103
- jsonrpc: "2.0",
104
- method: SANDBOX_PROXY_READY_METHOD,
105
- params: {},
106
- });
107
- </script>
108
- </body>
109
- </html>`;
110
- }
111
-
112
- function escapeHtmlAttribute(value: string): string {
113
- return value.replace(/&/g, "&amp;").replace(/"/g, "&quot;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
114
- }
115
-
116
- /**
117
- * CSP for the proxy document itself. It contains only the inline relay script
118
- * and a same-origin nested frame. Provider policy is applied on the resource
119
- * navigation response, not inherited from this relay document.
120
- */
121
- export function buildSandboxProxyCsp(): string {
122
- return [
123
- "default-src 'none'",
124
- "script-src 'unsafe-inline'",
125
- "style-src 'unsafe-inline'",
126
- "frame-src 'self'",
127
- "connect-src 'none'",
128
- "worker-src 'none'",
129
- "object-src 'none'",
130
- "base-uri 'none'",
131
- `sandbox ${SANDBOX_PROXY_SANDBOX}`,
132
- ].join("; ");
133
- }
134
-
135
- function safeInlineJSON(value: unknown): string {
136
- const json = JSON.stringify(value);
137
- if (json === undefined) return "undefined";
138
- return json
139
- .replace(/</g, "\\u003c")
140
- .replace(/>/g, "\\u003e")
141
- .replace(/&/g, "\\u0026")
142
- .replace(/\u2028/g, "\\u2028")
143
- .replace(/\u2029/g, "\\u2029");
144
- }