@herbertgao/pi-extensions 2026.9.17 → 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 (266) 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/@juicesharp/rpiv-ask-user-question/package.json +99 -99
  11. package/node_modules/@pi-plugins/fast-mode/package.json +1 -1
  12. package/node_modules/@tifan/pi-handoff/package.json +1 -1
  13. package/node_modules/@tifan/pi-handoff/src/index.ts +56 -26
  14. package/node_modules/@tifan/pi-mermaid-open/package.json +1 -1
  15. package/node_modules/@tifan/pi-preferred-thinking/package.json +1 -1
  16. package/node_modules/@tifan/pi-recap/package.json +1 -1
  17. package/node_modules/@tifan/pi-rename/package.json +1 -1
  18. package/node_modules/pi-antigravity/package.json +2 -2
  19. package/node_modules/pi-lens/package.json +158 -158
  20. package/node_modules/pi-multi-account/package.json +2 -2
  21. package/node_modules/pi-typesafe/README.md +1 -1
  22. package/node_modules/pi-typesafe/dist/auth.d.ts +9 -5
  23. package/node_modules/pi-typesafe/dist/auth.js +7 -3
  24. package/node_modules/pi-typesafe/dist/backends.d.ts +33 -3
  25. package/node_modules/pi-typesafe/dist/backends.js +95 -1
  26. package/node_modules/pi-typesafe/dist/client.d.ts +5 -5
  27. package/node_modules/pi-typesafe/dist/client.js +12 -9
  28. package/node_modules/pi-typesafe/dist/credentials.d.ts +14 -8
  29. package/node_modules/pi-typesafe/dist/credentials.js +10 -7
  30. package/node_modules/pi-typesafe/dist/errors.d.ts +2 -2
  31. package/node_modules/pi-typesafe/dist/index.d.ts +2 -2
  32. package/node_modules/pi-typesafe/dist/index.js +1 -1
  33. package/node_modules/pi-typesafe/dist/login.d.ts +2 -2
  34. package/node_modules/pi-typesafe/dist/login.js +2 -2
  35. package/node_modules/pi-typesafe/package.json +5 -5
  36. package/node_modules/pi-web-access/package.json +2 -2
  37. package/node_modules/remote-pi/package.json +5 -1
  38. package/package.json +16 -28
  39. package/node_modules/pi-mcp-adapter/CHANGELOG.md +0 -1013
  40. package/node_modules/pi-mcp-adapter/LICENSE +0 -21
  41. package/node_modules/pi-mcp-adapter/OAUTH.md +0 -369
  42. package/node_modules/pi-mcp-adapter/README.md +0 -1021
  43. package/node_modules/pi-mcp-adapter/abort.ts +0 -34
  44. package/node_modules/pi-mcp-adapter/agent-dir.ts +0 -68
  45. package/node_modules/pi-mcp-adapter/agent-plugin-loader.ts +0 -416
  46. package/node_modules/pi-mcp-adapter/agent-plugin-provenance.ts +0 -36
  47. package/node_modules/pi-mcp-adapter/app-bridge.bundle.js +0 -67
  48. package/node_modules/pi-mcp-adapter/banner.png +0 -0
  49. package/node_modules/pi-mcp-adapter/bearer-command-resolver.ts +0 -193
  50. package/node_modules/pi-mcp-adapter/claude-plugin-loader.ts +0 -365
  51. package/node_modules/pi-mcp-adapter/cli.js +0 -454
  52. package/node_modules/pi-mcp-adapter/commands.ts +0 -861
  53. package/node_modules/pi-mcp-adapter/config.ts +0 -1565
  54. package/node_modules/pi-mcp-adapter/consent-manager.ts +0 -95
  55. package/node_modules/pi-mcp-adapter/direct-tool-surface.ts +0 -244
  56. package/node_modules/pi-mcp-adapter/direct-tools.ts +0 -428
  57. package/node_modules/pi-mcp-adapter/dist/abort.d.ts +0 -2
  58. package/node_modules/pi-mcp-adapter/dist/abort.js +0 -36
  59. package/node_modules/pi-mcp-adapter/dist/abort.js.map +0 -1
  60. package/node_modules/pi-mcp-adapter/dist/agent-dir.d.ts +0 -10
  61. package/node_modules/pi-mcp-adapter/dist/agent-dir.js +0 -63
  62. package/node_modules/pi-mcp-adapter/dist/agent-dir.js.map +0 -1
  63. package/node_modules/pi-mcp-adapter/dist/agent-plugin-loader.d.ts +0 -8
  64. package/node_modules/pi-mcp-adapter/dist/agent-plugin-loader.js +0 -398
  65. package/node_modules/pi-mcp-adapter/dist/agent-plugin-loader.js.map +0 -1
  66. package/node_modules/pi-mcp-adapter/dist/agent-plugin-provenance.d.ts +0 -1
  67. package/node_modules/pi-mcp-adapter/dist/agent-plugin-provenance.js +0 -31
  68. package/node_modules/pi-mcp-adapter/dist/agent-plugin-provenance.js.map +0 -1
  69. package/node_modules/pi-mcp-adapter/dist/bearer-command-resolver.d.ts +0 -6
  70. package/node_modules/pi-mcp-adapter/dist/bearer-command-resolver.js +0 -194
  71. package/node_modules/pi-mcp-adapter/dist/bearer-command-resolver.js.map +0 -1
  72. package/node_modules/pi-mcp-adapter/dist/claude-plugin-loader.d.ts +0 -9
  73. package/node_modules/pi-mcp-adapter/dist/claude-plugin-loader.js +0 -362
  74. package/node_modules/pi-mcp-adapter/dist/claude-plugin-loader.js.map +0 -1
  75. package/node_modules/pi-mcp-adapter/dist/config.d.ts +0 -134
  76. package/node_modules/pi-mcp-adapter/dist/config.js +0 -1361
  77. package/node_modules/pi-mcp-adapter/dist/config.js.map +0 -1
  78. package/node_modules/pi-mcp-adapter/dist/consent-manager.d.ts +0 -18
  79. package/node_modules/pi-mcp-adapter/dist/consent-manager.js +0 -88
  80. package/node_modules/pi-mcp-adapter/dist/consent-manager.js.map +0 -1
  81. package/node_modules/pi-mcp-adapter/dist/elicitation-handler.d.ts +0 -17
  82. package/node_modules/pi-mcp-adapter/dist/elicitation-handler.js +0 -316
  83. package/node_modules/pi-mcp-adapter/dist/elicitation-handler.js.map +0 -1
  84. package/node_modules/pi-mcp-adapter/dist/errors.d.ts +0 -131
  85. package/node_modules/pi-mcp-adapter/dist/errors.js +0 -278
  86. package/node_modules/pi-mcp-adapter/dist/errors.js.map +0 -1
  87. package/node_modules/pi-mcp-adapter/dist/http-ca.d.ts +0 -8
  88. package/node_modules/pi-mcp-adapter/dist/http-ca.js +0 -88
  89. package/node_modules/pi-mcp-adapter/dist/http-ca.js.map +0 -1
  90. package/node_modules/pi-mcp-adapter/dist/jev-client.d.ts +0 -14
  91. package/node_modules/pi-mcp-adapter/dist/jev-client.js +0 -367
  92. package/node_modules/pi-mcp-adapter/dist/jev-client.js.map +0 -1
  93. package/node_modules/pi-mcp-adapter/dist/jev-contracts.d.ts +0 -77
  94. package/node_modules/pi-mcp-adapter/dist/jev-contracts.js +0 -2
  95. package/node_modules/pi-mcp-adapter/dist/jev-contracts.js.map +0 -1
  96. package/node_modules/pi-mcp-adapter/dist/jev-key-store.d.ts +0 -51
  97. package/node_modules/pi-mcp-adapter/dist/jev-key-store.js +0 -205
  98. package/node_modules/pi-mcp-adapter/dist/jev-key-store.js.map +0 -1
  99. package/node_modules/pi-mcp-adapter/dist/json-schema-validator.d.ts +0 -2
  100. package/node_modules/pi-mcp-adapter/dist/json-schema-validator.js +0 -68
  101. package/node_modules/pi-mcp-adapter/dist/json-schema-validator.js.map +0 -1
  102. package/node_modules/pi-mcp-adapter/dist/lifecycle.d.ts +0 -56
  103. package/node_modules/pi-mcp-adapter/dist/lifecycle.js +0 -410
  104. package/node_modules/pi-mcp-adapter/dist/lifecycle.js.map +0 -1
  105. package/node_modules/pi-mcp-adapter/dist/logger.d.ts +0 -51
  106. package/node_modules/pi-mcp-adapter/dist/logger.js +0 -131
  107. package/node_modules/pi-mcp-adapter/dist/logger.js.map +0 -1
  108. package/node_modules/pi-mcp-adapter/dist/mcp-auth-fetch.d.ts +0 -26
  109. package/node_modules/pi-mcp-adapter/dist/mcp-auth-fetch.js +0 -103
  110. package/node_modules/pi-mcp-adapter/dist/mcp-auth-fetch.js.map +0 -1
  111. package/node_modules/pi-mcp-adapter/dist/mcp-auth-flow.d.ts +0 -118
  112. package/node_modules/pi-mcp-adapter/dist/mcp-auth-flow.js +0 -1097
  113. package/node_modules/pi-mcp-adapter/dist/mcp-auth-flow.js.map +0 -1
  114. package/node_modules/pi-mcp-adapter/dist/mcp-auth.d.ts +0 -170
  115. package/node_modules/pi-mcp-adapter/dist/mcp-auth.js +0 -1142
  116. package/node_modules/pi-mcp-adapter/dist/mcp-auth.js.map +0 -1
  117. package/node_modules/pi-mcp-adapter/dist/mcp-bearer-store.d.ts +0 -24
  118. package/node_modules/pi-mcp-adapter/dist/mcp-bearer-store.js +0 -203
  119. package/node_modules/pi-mcp-adapter/dist/mcp-bearer-store.js.map +0 -1
  120. package/node_modules/pi-mcp-adapter/dist/mcp-callback-server.d.ts +0 -53
  121. package/node_modules/pi-mcp-adapter/dist/mcp-callback-server.js +0 -441
  122. package/node_modules/pi-mcp-adapter/dist/mcp-callback-server.js.map +0 -1
  123. package/node_modules/pi-mcp-adapter/dist/mcp-oauth-provider.d.ts +0 -148
  124. package/node_modules/pi-mcp-adapter/dist/mcp-oauth-provider.js +0 -689
  125. package/node_modules/pi-mcp-adapter/dist/mcp-oauth-provider.js.map +0 -1
  126. package/node_modules/pi-mcp-adapter/dist/mcp-probe.d.ts +0 -6
  127. package/node_modules/pi-mcp-adapter/dist/mcp-probe.js +0 -166
  128. package/node_modules/pi-mcp-adapter/dist/mcp-probe.js.map +0 -1
  129. package/node_modules/pi-mcp-adapter/dist/mcp-tasks.d.ts +0 -102
  130. package/node_modules/pi-mcp-adapter/dist/mcp-tasks.js +0 -369
  131. package/node_modules/pi-mcp-adapter/dist/mcp-tasks.js.map +0 -1
  132. package/node_modules/pi-mcp-adapter/dist/mcp-trace.d.ts +0 -95
  133. package/node_modules/pi-mcp-adapter/dist/mcp-trace.js +0 -242
  134. package/node_modules/pi-mcp-adapter/dist/mcp-trace.js.map +0 -1
  135. package/node_modules/pi-mcp-adapter/dist/metadata-cache.d.ts +0 -19
  136. package/node_modules/pi-mcp-adapter/dist/metadata-cache.js +0 -301
  137. package/node_modules/pi-mcp-adapter/dist/metadata-cache.js.map +0 -1
  138. package/node_modules/pi-mcp-adapter/dist/npx-resolver.d.ts +0 -6
  139. package/node_modules/pi-mcp-adapter/dist/npx-resolver.js +0 -505
  140. package/node_modules/pi-mcp-adapter/dist/npx-resolver.js.map +0 -1
  141. package/node_modules/pi-mcp-adapter/dist/package-mcp-loader.d.ts +0 -2
  142. package/node_modules/pi-mcp-adapter/dist/package-mcp-loader.js +0 -144
  143. package/node_modules/pi-mcp-adapter/dist/package-mcp-loader.js.map +0 -1
  144. package/node_modules/pi-mcp-adapter/dist/request-headers-command.d.ts +0 -10
  145. package/node_modules/pi-mcp-adapter/dist/request-headers-command.js +0 -312
  146. package/node_modules/pi-mcp-adapter/dist/request-headers-command.js.map +0 -1
  147. package/node_modules/pi-mcp-adapter/dist/resource-tools.d.ts +0 -1
  148. package/node_modules/pi-mcp-adapter/dist/resource-tools.js +0 -15
  149. package/node_modules/pi-mcp-adapter/dist/resource-tools.js.map +0 -1
  150. package/node_modules/pi-mcp-adapter/dist/runtime-owner.d.ts +0 -13
  151. package/node_modules/pi-mcp-adapter/dist/runtime-owner.js +0 -97
  152. package/node_modules/pi-mcp-adapter/dist/runtime-owner.js.map +0 -1
  153. package/node_modules/pi-mcp-adapter/dist/sampling-handler.d.ts +0 -17
  154. package/node_modules/pi-mcp-adapter/dist/sampling-handler.js +0 -203
  155. package/node_modules/pi-mcp-adapter/dist/sampling-handler.js.map +0 -1
  156. package/node_modules/pi-mcp-adapter/dist/secure-keyring.d.ts +0 -11
  157. package/node_modules/pi-mcp-adapter/dist/secure-keyring.js +0 -172
  158. package/node_modules/pi-mcp-adapter/dist/secure-keyring.js.map +0 -1
  159. package/node_modules/pi-mcp-adapter/dist/server-manager.d.ts +0 -157
  160. package/node_modules/pi-mcp-adapter/dist/server-manager.js +0 -1745
  161. package/node_modules/pi-mcp-adapter/dist/server-manager.js.map +0 -1
  162. package/node_modules/pi-mcp-adapter/dist/session-approvals.d.ts +0 -34
  163. package/node_modules/pi-mcp-adapter/dist/session-approvals.js +0 -140
  164. package/node_modules/pi-mcp-adapter/dist/session-approvals.js.map +0 -1
  165. package/node_modules/pi-mcp-adapter/dist/session-recovery.d.ts +0 -26
  166. package/node_modules/pi-mcp-adapter/dist/session-recovery.js +0 -142
  167. package/node_modules/pi-mcp-adapter/dist/session-recovery.js.map +0 -1
  168. package/node_modules/pi-mcp-adapter/dist/state.d.ts +0 -73
  169. package/node_modules/pi-mcp-adapter/dist/state.js +0 -2
  170. package/node_modules/pi-mcp-adapter/dist/state.js.map +0 -1
  171. package/node_modules/pi-mcp-adapter/dist/types.d.ts +0 -642
  172. package/node_modules/pi-mcp-adapter/dist/types.js +0 -331
  173. package/node_modules/pi-mcp-adapter/dist/types.js.map +0 -1
  174. package/node_modules/pi-mcp-adapter/dist/ui-app-bridge-helpers.d.ts +0 -6
  175. package/node_modules/pi-mcp-adapter/dist/ui-app-bridge-helpers.js +0 -37
  176. package/node_modules/pi-mcp-adapter/dist/ui-app-bridge-helpers.js.map +0 -1
  177. package/node_modules/pi-mcp-adapter/dist/ui-resource-handler.d.ts +0 -17
  178. package/node_modules/pi-mcp-adapter/dist/ui-resource-handler.js +0 -219
  179. package/node_modules/pi-mcp-adapter/dist/ui-resource-handler.js.map +0 -1
  180. package/node_modules/pi-mcp-adapter/dist/ui-stream-types.d.ts +0 -104
  181. package/node_modules/pi-mcp-adapter/dist/ui-stream-types.js +0 -59
  182. package/node_modules/pi-mcp-adapter/dist/ui-stream-types.js.map +0 -1
  183. package/node_modules/pi-mcp-adapter/dist/ui-tool-visibility.d.ts +0 -4
  184. package/node_modules/pi-mcp-adapter/dist/ui-tool-visibility.js +0 -27
  185. package/node_modules/pi-mcp-adapter/dist/ui-tool-visibility.js.map +0 -1
  186. package/node_modules/pi-mcp-adapter/dist/unix-socket-transport.d.ts +0 -15
  187. package/node_modules/pi-mcp-adapter/dist/unix-socket-transport.js +0 -85
  188. package/node_modules/pi-mcp-adapter/dist/unix-socket-transport.js.map +0 -1
  189. package/node_modules/pi-mcp-adapter/dist/utils.d.ts +0 -41
  190. package/node_modules/pi-mcp-adapter/dist/utils.js +0 -417
  191. package/node_modules/pi-mcp-adapter/dist/utils.js.map +0 -1
  192. package/node_modules/pi-mcp-adapter/elicitation-handler.ts +0 -358
  193. package/node_modules/pi-mcp-adapter/error-signal.ts +0 -32
  194. package/node_modules/pi-mcp-adapter/errors.ts +0 -364
  195. package/node_modules/pi-mcp-adapter/examples/jev-accessibility-loop.mjs +0 -85
  196. package/node_modules/pi-mcp-adapter/examples/jev-semantic-filter.mjs +0 -34
  197. package/node_modules/pi-mcp-adapter/failure-backoff.ts +0 -23
  198. package/node_modules/pi-mcp-adapter/glimpse-ui.ts +0 -80
  199. package/node_modules/pi-mcp-adapter/host-html-template.ts +0 -515
  200. package/node_modules/pi-mcp-adapter/http-ca.ts +0 -84
  201. package/node_modules/pi-mcp-adapter/index.ts +0 -2106
  202. package/node_modules/pi-mcp-adapter/init.ts +0 -721
  203. package/node_modules/pi-mcp-adapter/jev-client.ts +0 -300
  204. package/node_modules/pi-mcp-adapter/jev-contracts.ts +0 -53
  205. package/node_modules/pi-mcp-adapter/jev-key-store.ts +0 -192
  206. package/node_modules/pi-mcp-adapter/json-schema-validator.ts +0 -83
  207. package/node_modules/pi-mcp-adapter/lazy-loader.ts +0 -7
  208. package/node_modules/pi-mcp-adapter/lifecycle.ts +0 -457
  209. package/node_modules/pi-mcp-adapter/logger.ts +0 -169
  210. package/node_modules/pi-mcp-adapter/mcp-auth-fetch.ts +0 -113
  211. package/node_modules/pi-mcp-adapter/mcp-auth-flow.ts +0 -1296
  212. package/node_modules/pi-mcp-adapter/mcp-auth.ts +0 -1287
  213. package/node_modules/pi-mcp-adapter/mcp-bearer-store.ts +0 -250
  214. package/node_modules/pi-mcp-adapter/mcp-callback-server.ts +0 -534
  215. package/node_modules/pi-mcp-adapter/mcp-code.ts +0 -495
  216. package/node_modules/pi-mcp-adapter/mcp-install.ts +0 -60
  217. package/node_modules/pi-mcp-adapter/mcp-keyring-helper.cjs +0 -89
  218. package/node_modules/pi-mcp-adapter/mcp-oauth-provider.ts +0 -819
  219. package/node_modules/pi-mcp-adapter/mcp-output-guard.ts +0 -511
  220. package/node_modules/pi-mcp-adapter/mcp-panel-theme.ts +0 -104
  221. package/node_modules/pi-mcp-adapter/mcp-panel.ts +0 -1099
  222. package/node_modules/pi-mcp-adapter/mcp-probe.ts +0 -201
  223. package/node_modules/pi-mcp-adapter/mcp-references.ts +0 -373
  224. package/node_modules/pi-mcp-adapter/mcp-script-worker.mjs +0 -137
  225. package/node_modules/pi-mcp-adapter/mcp-setup-panel.ts +0 -747
  226. package/node_modules/pi-mcp-adapter/mcp-status.ts +0 -105
  227. package/node_modules/pi-mcp-adapter/mcp-tasks.ts +0 -467
  228. package/node_modules/pi-mcp-adapter/mcp-trace.ts +0 -306
  229. package/node_modules/pi-mcp-adapter/metadata-cache.ts +0 -362
  230. package/node_modules/pi-mcp-adapter/namespace-tools.ts +0 -334
  231. package/node_modules/pi-mcp-adapter/npx-resolver.ts +0 -543
  232. package/node_modules/pi-mcp-adapter/oauth-handler.ts +0 -30
  233. package/node_modules/pi-mcp-adapter/oauth.ts +0 -52
  234. package/node_modules/pi-mcp-adapter/onboarding-state.ts +0 -76
  235. package/node_modules/pi-mcp-adapter/package-mcp-loader.ts +0 -156
  236. package/node_modules/pi-mcp-adapter/package.json +0 -219
  237. package/node_modules/pi-mcp-adapter/panel-keys.ts +0 -53
  238. package/node_modules/pi-mcp-adapter/prompts.ts +0 -385
  239. package/node_modules/pi-mcp-adapter/proxy-modes.ts +0 -1735
  240. package/node_modules/pi-mcp-adapter/request-headers-command.ts +0 -333
  241. package/node_modules/pi-mcp-adapter/resource-tools.ts +0 -17
  242. package/node_modules/pi-mcp-adapter/runtime-owner.ts +0 -106
  243. package/node_modules/pi-mcp-adapter/sampling-handler.ts +0 -261
  244. package/node_modules/pi-mcp-adapter/sandbox-proxy-template.ts +0 -144
  245. package/node_modules/pi-mcp-adapter/search-ranking.ts +0 -309
  246. package/node_modules/pi-mcp-adapter/secure-keyring.ts +0 -170
  247. package/node_modules/pi-mcp-adapter/semantic-search.ts +0 -186
  248. package/node_modules/pi-mcp-adapter/server-manager.ts +0 -2088
  249. package/node_modules/pi-mcp-adapter/session-approvals.ts +0 -201
  250. package/node_modules/pi-mcp-adapter/session-recovery.ts +0 -158
  251. package/node_modules/pi-mcp-adapter/skills/mcp-scripting/SKILL.md +0 -49
  252. package/node_modules/pi-mcp-adapter/state.ts +0 -71
  253. package/node_modules/pi-mcp-adapter/tool-approval.ts +0 -205
  254. package/node_modules/pi-mcp-adapter/tool-metadata.ts +0 -302
  255. package/node_modules/pi-mcp-adapter/tool-registrar.ts +0 -255
  256. package/node_modules/pi-mcp-adapter/tool-result-renderer.ts +0 -573
  257. package/node_modules/pi-mcp-adapter/ts-shape.ts +0 -149
  258. package/node_modules/pi-mcp-adapter/types.ts +0 -1120
  259. package/node_modules/pi-mcp-adapter/ui-app-bridge-helpers.ts +0 -40
  260. package/node_modules/pi-mcp-adapter/ui-resource-handler.ts +0 -266
  261. package/node_modules/pi-mcp-adapter/ui-server.ts +0 -993
  262. package/node_modules/pi-mcp-adapter/ui-session.ts +0 -624
  263. package/node_modules/pi-mcp-adapter/ui-stream-types.ts +0 -89
  264. package/node_modules/pi-mcp-adapter/ui-tool-visibility.ts +0 -25
  265. package/node_modules/pi-mcp-adapter/unix-socket-transport.ts +0 -85
  266. package/node_modules/pi-mcp-adapter/utils.ts +0 -464
@@ -1,34 +0,0 @@
1
- export function throwIfAborted(signal?: AbortSignal): void {
2
- if (!signal?.aborted) return;
3
- throw signal.reason instanceof Error ? signal.reason : new Error(String(signal.reason ?? "MCP request aborted"));
4
- }
5
-
6
- export async function abortable<T>(promise: Promise<T>, signal?: AbortSignal): Promise<T> {
7
- if (!signal) return promise;
8
- throwIfAborted(signal);
9
- return await new Promise<T>((resolve, reject) => {
10
- let settled = false;
11
- const cleanup = () => signal.removeEventListener("abort", onAbort);
12
- const onAbort = () => {
13
- if (settled) return;
14
- settled = true;
15
- cleanup();
16
- reject(signal.reason instanceof Error ? signal.reason : new Error(String(signal.reason ?? "MCP request aborted")));
17
- };
18
- signal.addEventListener("abort", onAbort, { once: true });
19
- promise.then(
20
- value => {
21
- if (settled) return;
22
- settled = true;
23
- cleanup();
24
- resolve(value);
25
- },
26
- error => {
27
- if (settled) return;
28
- settled = true;
29
- cleanup();
30
- reject(error);
31
- },
32
- );
33
- });
34
- }
@@ -1,68 +0,0 @@
1
- import { readFileSync } from "node:fs";
2
- import { homedir } from "node:os";
3
- import { join, resolve } from "node:path";
4
-
5
- export function getConfigDirName(): string {
6
- const configDir = readPiConfig()?.configDir;
7
- return typeof configDir === "string" && configDir.trim() ? configDir.trim() : ".pi";
8
- }
9
-
10
- export function getAgentDir(): string {
11
- const piConfig = readPiConfig();
12
- const name = piConfig?.name;
13
- const appName = typeof name === "string" && name.trim() ? name.trim() : "pi";
14
- const configured = process.env[`${appName.toUpperCase()}_CODING_AGENT_DIR`]?.trim();
15
- if (!configured) {
16
- return join(homedir(), getConfigDirName(), "agent");
17
- }
18
- if (configured === "~") {
19
- return homedir();
20
- }
21
- if (configured.startsWith("~/")) {
22
- return resolve(homedir(), configured.slice(2));
23
- }
24
- return resolve(configured);
25
- }
26
-
27
- export function getAgentPath(...segments: string[]): string {
28
- return join(getAgentDir(), ...segments);
29
- }
30
-
31
- /**
32
- * What the host calls itself.
33
- *
34
- * pi supports rebranding through `piConfig.name` in the package.json that its
35
- * `getPackageDir()` resolves, and distributions built on pi (arc, tau, …) point
36
- * `PI_PACKAGE_DIR` at their own manifest. Read that manifest directly rather
37
- * than importing pi: this package deliberately depends on pi-ai and pi-tui
38
- * only, and `getAgentDir()` above reads its env var the same self-contained way.
39
- *
40
- * Falls back to "pi", which is what pi's own APP_NAME resolves to.
41
- */
42
- function readPiConfig(): { name?: unknown; configDir?: unknown; clientUri?: unknown } | undefined {
43
- const dir = process.env.PI_PACKAGE_DIR?.trim()
44
- if (!dir) return undefined
45
- try {
46
- const manifest = JSON.parse(readFileSync(join(resolve(dir), "package.json"), "utf8")) as {
47
- piConfig?: { name?: unknown; configDir?: unknown; clientUri?: unknown }
48
- }
49
- return manifest.piConfig
50
- } catch {
51
- return undefined
52
- }
53
- }
54
-
55
- export function getAppName(): string {
56
- const name = readPiConfig()?.name
57
- return typeof name === "string" && name.trim() ? name.trim() : "pi"
58
- }
59
-
60
- /**
61
- * Home page the host declares for itself, via `piConfig.clientUri` in the same
62
- * manifest that carries `piConfig.name`. Only the distribution knows its own
63
- * URL, so this is the one place it can come from without guessing.
64
- */
65
- export function getAppClientUri(): string | undefined {
66
- const uri = readPiConfig()?.clientUri
67
- return typeof uri === "string" && uri.trim() ? uri.trim() : undefined
68
- }
@@ -1,416 +0,0 @@
1
- import { existsSync, readFileSync, realpathSync, statSync } from "node:fs";
2
- import { dirname, isAbsolute, resolve } from "node:path";
3
- import { getAgentPath } from "./agent-dir.ts";
4
- import { markBuiltInAgentPlugin } from "./agent-plugin-provenance.ts";
5
- import type { McpConfig, ServerEntry } from "./types.ts";
6
- import { resolveRealContainedPath } from "./utils.ts";
7
-
8
- const PLUGIN_SCHEMA = "https://agent-plugins.org/schemas/1.0.0/plugin.schema.json";
9
- const MCP_SCHEMA = "https://agent-plugins.org/schemas/1.0.0/mcp.schema.json";
10
- const PLUGIN_NAME_PATTERN = /^(?!.*(?:--|\.\.))[a-z0-9](?:[a-z0-9.-]*[a-z0-9])?$/;
11
- const PLUGIN_MANIFEST_FIELDS = new Set([
12
- "$schema",
13
- "name",
14
- "version",
15
- "description",
16
- "author",
17
- "homepage",
18
- "repository",
19
- "license",
20
- "keywords",
21
- "extensions",
22
- ]);
23
- const MCP_CONFIG_FIELDS = new Set(["$schema", "mcpServers"]);
24
- const STDIO_FIELDS = new Set(["type", "command", "args", "env", "cwd"]);
25
- const HTTP_FIELDS = new Set(["type", "url", "headers"]);
26
- const STRING_MANIFEST_FIELDS = ["version", "description", "homepage", "repository", "license"] as const;
27
- const AUTHOR_FIELDS = new Set(["name", "email", "url"]);
28
-
29
- interface AgentPluginManifest {
30
- name: string;
31
- }
32
-
33
- export interface AgentPluginSummary {
34
- path: string;
35
- name?: string;
36
- serverCount: number;
37
- }
38
-
39
- export function loadAgentPluginConfigs(paths: unknown, cwd = process.cwd()): McpConfig {
40
- const mcpServers: Record<string, ServerEntry> = {};
41
- for (const pluginPath of getPluginPaths(paths)) {
42
- const loaded = loadAgentPluginMcpConfig(pluginPath, cwd);
43
- if (!loaded) continue;
44
- for (const [serverName, server] of Object.entries(loaded.mcpServers)) {
45
- if (mcpServers[serverName]) {
46
- console.warn(`Agent Plugin at ${resolvePluginPath(pluginPath, cwd)} skips duplicate normalized MCP server ${serverName}`);
47
- continue;
48
- }
49
- mcpServers[serverName] = server;
50
- }
51
- }
52
- return { mcpServers };
53
- }
54
-
55
- export function getAgentPluginSummaries(paths: unknown, cwd = process.cwd()): AgentPluginSummary[] {
56
- return getPluginPaths(paths).map(path => {
57
- const pluginRoot = resolvePluginRoot(path, cwd);
58
- const loaded = loadAgentPluginMcpConfig(path, cwd);
59
- const manifest = loaded ? readPluginManifest(pluginRoot, false) : null;
60
- return {
61
- path: pluginRoot,
62
- ...(manifest?.name ? { name: manifest.name } : {}),
63
- serverCount: loaded ? Object.keys(loaded.mcpServers).length : 0,
64
- };
65
- });
66
- }
67
-
68
- function getPluginPaths(paths: unknown): string[] {
69
- return Array.isArray(paths) ? paths.filter((path): path is string => typeof path === "string") : [];
70
- }
71
-
72
- function loadAgentPluginMcpConfig(path: string, cwd: string): McpConfig | null {
73
- const pluginRoot = resolvePluginRoot(path, cwd);
74
- const manifest = readPluginManifest(pluginRoot, true);
75
- if (!manifest) return null;
76
-
77
- const mcpPath = resolve(pluginRoot, "mcp.json");
78
- if (!existsSync(mcpPath)) return { mcpServers: {} };
79
- if (!statSync(mcpPath).isFile()) {
80
- console.warn(`Agent Plugin ${manifest.name} has invalid MCP config: mcp.json is not a regular file`);
81
- return { mcpServers: {} };
82
- }
83
- const resolvedMcpPath = resolveRealContainedPath(pluginRoot, mcpPath);
84
- if (!resolvedMcpPath) {
85
- console.warn(`Agent Plugin ${manifest.name} has invalid MCP config: mcp.json must stay inside the plugin directory`);
86
- return { mcpServers: {} };
87
- }
88
-
89
- let raw: unknown;
90
- try {
91
- raw = JSON.parse(readFileSync(resolvedMcpPath, "utf8"));
92
- } catch (error) {
93
- console.warn(`Agent Plugin ${manifest.name} has invalid MCP config: failed to parse mcp.json`, error);
94
- return { mcpServers: {} };
95
- }
96
-
97
- return translateAgentPluginMcpConfig(raw, manifest, pluginRoot);
98
- }
99
-
100
- function readPluginManifest(pluginRoot: string, report: boolean): AgentPluginManifest | null {
101
- const manifestPath = resolve(pluginRoot, "plugin.json");
102
- if (!existsSync(manifestPath)) {
103
- if (report) console.warn(`Agent Plugin at ${pluginRoot} is invalid: missing plugin.json`);
104
- return null;
105
- }
106
- if (!statSync(manifestPath).isFile()) {
107
- if (report) console.warn(`Agent Plugin at ${pluginRoot} is invalid: plugin.json is not a regular file`);
108
- return null;
109
- }
110
- const resolvedManifestPath = resolveRealContainedPath(pluginRoot, manifestPath);
111
- if (!resolvedManifestPath) {
112
- if (report) console.warn(`Agent Plugin at ${pluginRoot} is invalid: plugin.json must stay inside the plugin directory`);
113
- return null;
114
- }
115
-
116
- let raw: unknown;
117
- try {
118
- raw = JSON.parse(readFileSync(resolvedManifestPath, "utf8"));
119
- } catch (error) {
120
- if (report) console.warn(`Agent Plugin at ${pluginRoot} is invalid: failed to parse plugin.json`, error);
121
- return null;
122
- }
123
- if (!raw || typeof raw !== "object" || Array.isArray(raw)) {
124
- if (report) console.warn(`Agent Plugin at ${pluginRoot} is invalid: plugin.json must be an object`);
125
- return null;
126
- }
127
-
128
- const manifest = raw as Record<string, unknown>;
129
- for (const key of Object.keys(manifest)) {
130
- if (!PLUGIN_MANIFEST_FIELDS.has(key) && report) {
131
- console.warn(`Agent Plugin at ${pluginRoot} ignores unknown plugin.json field: ${key}`);
132
- }
133
- }
134
- if (manifest.$schema !== PLUGIN_SCHEMA) {
135
- if (report) console.warn(`Agent Plugin at ${pluginRoot} is invalid: unsupported plugin.json $schema`);
136
- return null;
137
- }
138
- if (typeof manifest.name !== "string" || manifest.name.length < 1 || manifest.name.length > 64 || !PLUGIN_NAME_PATTERN.test(manifest.name)) {
139
- if (report) console.warn(`Agent Plugin at ${pluginRoot} is invalid: plugin.json name is invalid`);
140
- return null;
141
- }
142
- for (const field of STRING_MANIFEST_FIELDS) {
143
- if (manifest[field] !== undefined && typeof manifest[field] !== "string") {
144
- if (report) console.warn(`Agent Plugin ${manifest.name} is invalid: plugin.json ${field} must be a string`);
145
- return null;
146
- }
147
- }
148
- if (manifest.keywords !== undefined && (!Array.isArray(manifest.keywords) || manifest.keywords.some(value => typeof value !== "string"))) {
149
- if (report) console.warn(`Agent Plugin ${manifest.name} is invalid: plugin.json keywords must be an array of strings`);
150
- return null;
151
- }
152
- if (manifest.author !== undefined && !isValidManifestAuthor(manifest.author)) {
153
- if (report) console.warn(`Agent Plugin ${manifest.name} is invalid: plugin.json author is invalid`);
154
- return null;
155
- }
156
- if (manifest.extensions !== undefined && (!manifest.extensions || typeof manifest.extensions !== "object" || Array.isArray(manifest.extensions))) {
157
- if (report) console.warn(`Agent Plugin ${manifest.name} ignores non-object plugin.json extensions`);
158
- }
159
-
160
- return { name: manifest.name };
161
- }
162
-
163
- function translateAgentPluginMcpConfig(raw: unknown, manifest: AgentPluginManifest, pluginRoot: string): McpConfig {
164
- if (!raw || typeof raw !== "object" || Array.isArray(raw)) {
165
- console.warn(`Agent Plugin ${manifest.name} has invalid MCP config: mcp.json must be an object`);
166
- return { mcpServers: {} };
167
- }
168
-
169
- const mcpConfig = raw as Record<string, unknown>;
170
- for (const key of Object.keys(mcpConfig)) {
171
- if (!MCP_CONFIG_FIELDS.has(key)) {
172
- console.warn(`Agent Plugin ${manifest.name} has invalid MCP config: unknown top-level field ${key}`);
173
- return { mcpServers: {} };
174
- }
175
- }
176
- if (mcpConfig.$schema !== MCP_SCHEMA) {
177
- console.warn(`Agent Plugin ${manifest.name} has invalid MCP config: unsupported mcp.json $schema`);
178
- return { mcpServers: {} };
179
- }
180
- if (!mcpConfig.mcpServers || typeof mcpConfig.mcpServers !== "object" || Array.isArray(mcpConfig.mcpServers)) {
181
- console.warn(`Agent Plugin ${manifest.name} has invalid MCP config: mcpServers must be an object`);
182
- return { mcpServers: {} };
183
- }
184
-
185
- const mcpServers: Record<string, ServerEntry> = {};
186
- for (const [serverName, entry] of Object.entries(mcpConfig.mcpServers)) {
187
- const translated = translateAgentPluginServer(manifest, pluginRoot, serverName, entry);
188
- if (!translated) continue;
189
-
190
- const normalizedName = formatAgentPluginServerName(manifest.name, serverName);
191
- if (mcpServers[normalizedName]) {
192
- console.warn(`Agent Plugin ${manifest.name} skips invalid MCP server ${serverName}: normalized server name ${normalizedName} already exists`);
193
- continue;
194
- }
195
- mcpServers[normalizedName] = translated;
196
- }
197
- return { mcpServers };
198
- }
199
-
200
- function translateAgentPluginServer(
201
- manifest: AgentPluginManifest,
202
- pluginRoot: string,
203
- serverName: string,
204
- entry: unknown,
205
- ): ServerEntry | null {
206
- if (!entry || typeof entry !== "object" || Array.isArray(entry)) {
207
- console.warn(`Agent Plugin ${manifest.name} skips invalid MCP server ${serverName}: entry must be an object`);
208
- return null;
209
- }
210
-
211
- const raw = entry as Record<string, unknown>;
212
- if (raw.type === "stdio") return translateStdioServer(manifest, pluginRoot, serverName, raw);
213
- if (raw.type === "streamable-http" || raw.type === "sse") return translateHttpServer(manifest, serverName, raw, raw.type);
214
-
215
- console.warn(`Agent Plugin ${manifest.name} skips invalid MCP server ${serverName}: unsupported type`);
216
- return null;
217
- }
218
-
219
- function translateStdioServer(
220
- manifest: AgentPluginManifest,
221
- pluginRoot: string,
222
- serverName: string,
223
- raw: Record<string, unknown>,
224
- ): ServerEntry | null {
225
- for (const key of Object.keys(raw)) {
226
- if (!STDIO_FIELDS.has(key)) return skipServer(manifest, serverName, `unknown field ${key}`);
227
- }
228
- if (typeof raw.command !== "string" || raw.command.length === 0) return skipServer(manifest, serverName, "command must be a non-empty string");
229
- if (!isBareCommand(raw.command) && !raw.command.startsWith("./")) return skipServer(manifest, serverName, "command must be bare or plugin-relative");
230
-
231
- const args = translateStringArray(raw.args, manifest, serverName, "args");
232
- if (args === null) return null;
233
- const env = translateEnv(raw.env, manifest, serverName);
234
- if (env === null) return null;
235
-
236
- const command = raw.command.startsWith("./") ? resolveRealContainedPath(pluginRoot, resolve(pluginRoot, raw.command)) : raw.command;
237
- if (command === null) return skipServer(manifest, serverName, "command must resolve to an accessible path inside the plugin directory");
238
-
239
- const pluginDataDir = getAgentPath("agent-plugin-data", manifest.name);
240
- const cwd = resolvePluginCwd(raw.cwd, pluginRoot, pluginDataDir);
241
- if (cwd === null) return skipServer(manifest, serverName, "cwd must resolve from an allowed root and stay contained");
242
-
243
- return markBuiltInAgentPlugin({
244
- command,
245
- args: args.map(value => expandPluginPlaceholders(value, pluginRoot, pluginDataDir)),
246
- env: {
247
- ...Object.fromEntries(Object.entries(env).map(([key, value]) => [key, expandPluginPlaceholders(value, pluginRoot, pluginDataDir)])),
248
- PLUGIN_ROOT: pluginRoot,
249
- PLUGIN_DATA: pluginDataDir,
250
- },
251
- cwd,
252
- pluginDataDir,
253
- literalEnv: true,
254
- }, ["args", "env", "cwd"]);
255
- }
256
-
257
- function translateHttpServer(
258
- manifest: AgentPluginManifest,
259
- serverName: string,
260
- raw: Record<string, unknown>,
261
- type: "streamable-http" | "sse",
262
- ): ServerEntry | null {
263
- for (const key of Object.keys(raw)) {
264
- if (!HTTP_FIELDS.has(key)) return skipServer(manifest, serverName, `unknown field ${key}`);
265
- }
266
- if (typeof raw.url !== "string" || raw.url.length === 0) return skipServer(manifest, serverName, "url must be a non-empty string");
267
- if (!isValidAgentPluginUrl(raw.url)) return skipServer(manifest, serverName, "url must be an allowed absolute HTTP(S) URL");
268
- const headers = translateHeaders(raw.headers, manifest, serverName);
269
- if (headers === null) return null;
270
-
271
- return markBuiltInAgentPlugin({
272
- url: raw.url,
273
- httpTransport: type,
274
- ...(headers ? { headers } : {}),
275
- }, headers ? ["headers"] : []);
276
- }
277
-
278
- function formatAgentPluginServerName(pluginName: string, serverName: string): string {
279
- const pluginPart = pluginName.replace(/[^A-Za-z0-9_-]+/g, "_").replace(/^[_-]+|[_-]+$/g, "") || "plugin";
280
- const serverPart = serverName.replace(/[^A-Za-z0-9_-]+/g, "_").replace(/^[_-]+|[_-]+$/g, "") || "server";
281
- return `${pluginPart}__${serverPart}`;
282
- }
283
-
284
- function skipServer(manifest: AgentPluginManifest, serverName: string, reason: string): null {
285
- console.warn(`Agent Plugin ${manifest.name} skips invalid MCP server ${serverName}: ${reason}`);
286
- return null;
287
- }
288
-
289
- function translateStringArray(value: unknown, manifest: AgentPluginManifest, serverName: string, field: string): string[] | null {
290
- if (value === undefined) return [];
291
- if (!Array.isArray(value) || value.some(item => typeof item !== "string")) {
292
- console.warn(`Agent Plugin ${manifest.name} skips invalid MCP server ${serverName}: ${field} must be an array of strings`);
293
- return null;
294
- }
295
- return value;
296
- }
297
-
298
- function translateEnv(value: unknown, manifest: AgentPluginManifest, serverName: string): Record<string, string> | null {
299
- if (value === undefined) return {};
300
- if (!value || typeof value !== "object" || Array.isArray(value)) {
301
- console.warn(`Agent Plugin ${manifest.name} skips invalid MCP server ${serverName}: env must be an object of strings`);
302
- return null;
303
- }
304
- const entries: Array<[string, string]> = [];
305
- for (const [key, entry] of Object.entries(value)) {
306
- if (key === "PLUGIN_ROOT" || key === "PLUGIN_DATA") {
307
- console.warn(`Agent Plugin ${manifest.name} skips invalid MCP server ${serverName}: env must not define ${key}`);
308
- return null;
309
- }
310
- if (typeof entry !== "string") {
311
- console.warn(`Agent Plugin ${manifest.name} skips invalid MCP server ${serverName}: env values must be strings`);
312
- return null;
313
- }
314
- entries.push([key, entry]);
315
- }
316
- return Object.fromEntries(entries);
317
- }
318
-
319
- function translateHeaders(value: unknown, manifest: AgentPluginManifest, serverName: string): Record<string, string> | undefined | null {
320
- if (value === undefined) return undefined;
321
- if (!value || typeof value !== "object" || Array.isArray(value)) {
322
- console.warn(`Agent Plugin ${manifest.name} skips invalid MCP server ${serverName}: headers must be an object of strings`);
323
- return null;
324
- }
325
- const entries: Array<[string, string]> = [];
326
- const seen = new Set<string>();
327
- for (const [key, entry] of Object.entries(value)) {
328
- if (typeof entry !== "string") {
329
- console.warn(`Agent Plugin ${manifest.name} skips invalid MCP server ${serverName}: header values must be strings`);
330
- return null;
331
- }
332
- const normalized = key.toLowerCase();
333
- if (seen.has(normalized)) {
334
- console.warn(`Agent Plugin ${manifest.name} skips invalid MCP server ${serverName}: duplicate header ${key}`);
335
- return null;
336
- }
337
- seen.add(normalized);
338
- entries.push([key, entry]);
339
- }
340
- const headers = Object.fromEntries(entries);
341
- try {
342
- new Headers(headers);
343
- } catch {
344
- console.warn(`Agent Plugin ${manifest.name} skips invalid MCP server ${serverName}: headers are not valid HTTP fields`);
345
- return null;
346
- }
347
- return Object.keys(headers).length > 0 ? headers : undefined;
348
- }
349
-
350
- function resolvePluginPath(path: string, cwd: string): string {
351
- if (path === "~") return resolve(process.env.HOME ?? "", ".");
352
- if (path.startsWith("~/")) return resolve(process.env.HOME ?? "", path.slice(2));
353
- return isAbsolute(path) ? resolve(path) : resolve(cwd, path);
354
- }
355
-
356
- function resolvePluginRoot(path: string, cwd: string): string {
357
- const resolved = resolvePluginPath(path, cwd);
358
- try {
359
- return realpathSync(resolved);
360
- } catch {
361
- return resolved;
362
- }
363
- }
364
-
365
- function isValidManifestAuthor(value: unknown): boolean {
366
- if (!value || typeof value !== "object" || Array.isArray(value)) return false;
367
- return Object.entries(value).every(([key, entry]) => AUTHOR_FIELDS.has(key) && typeof entry === "string");
368
- }
369
-
370
- function isBareCommand(command: string): boolean {
371
- return !command.includes("/") && !command.includes("\\") && !command.includes("${PLUGIN_ROOT}") && !command.includes("${PLUGIN_DATA}");
372
- }
373
-
374
- function resolvePluginCwd(value: unknown, pluginRoot: string, pluginDataDir: string): string | null {
375
- if (value === undefined) return pluginRoot;
376
- if (typeof value !== "string") return null;
377
- const expanded = expandPluginPlaceholders(value, pluginRoot, pluginDataDir);
378
- if (value.startsWith("./") || value === "${PLUGIN_ROOT}" || value.startsWith("${PLUGIN_ROOT}/")) {
379
- return resolveRealContainedPath(pluginRoot, resolve(pluginRoot, expanded));
380
- }
381
- if (value === "${PLUGIN_DATA}" || value.startsWith("${PLUGIN_DATA}/")) {
382
- return resolvePluginDataCwd(pluginDataDir, expanded);
383
- }
384
- return null;
385
- }
386
-
387
- function resolvePluginDataCwd(pluginDataDir: string, expanded: string): string | null {
388
- if (existsSync(pluginDataDir) && !resolveRealContainedPath(dirname(pluginDataDir), pluginDataDir)) return null;
389
- return resolveRealContainedPath(pluginDataDir, resolve(pluginDataDir, expanded), true);
390
- }
391
-
392
- function expandPluginPlaceholders(value: string, pluginRoot: string, pluginDataDir: string): string {
393
- return value.replace(/\$\{PLUGIN_(ROOT|DATA)\}/g, (_, name: string) => name === "ROOT" ? pluginRoot : pluginDataDir);
394
- }
395
-
396
- function isValidAgentPluginUrl(value: string): boolean {
397
- if (value.includes("${") || value.includes("$env:") || value.includes("{env:")) return false;
398
-
399
- let url: URL;
400
- try {
401
- url = new URL(value);
402
- } catch {
403
- return false;
404
- }
405
- if (url.protocol !== "http:" && url.protocol !== "https:") return false;
406
- if (url.username || url.password || url.hash) return false;
407
- if (url.protocol === "https:") return true;
408
- return isLoopbackHost(url.hostname);
409
- }
410
-
411
- function isLoopbackHost(hostname: string): boolean {
412
- const host = hostname.toLowerCase();
413
- if (host === "localhost" || host === "127.0.0.1" || host === "::1" || host === "[::1]") return true;
414
- if (/^127(?:\.\d{1,3}){3}$/.test(host)) return true;
415
- return false;
416
- }
@@ -1,36 +0,0 @@
1
- import type { ServerEntry } from "./types.ts";
2
-
3
- const LITERAL_PLUGIN_FIELDS = ["args", "env", "cwd", "headers"] as const;
4
- type LiteralPluginField = typeof LITERAL_PLUGIN_FIELDS[number];
5
- const BUILT_IN_AGENT_PLUGIN = Symbol("built-in-agent-plugin");
6
- type BuiltInAgentPluginEntry = ServerEntry & { [BUILT_IN_AGENT_PLUGIN]?: ReadonlySet<LiteralPluginField> };
7
-
8
- /** @internal */
9
- export function markBuiltInAgentPlugin(definition: ServerEntry, fields: LiteralPluginField[]): ServerEntry {
10
- (definition as BuiltInAgentPluginEntry)[BUILT_IN_AGENT_PLUGIN] = new Set(fields);
11
- return definition;
12
- }
13
-
14
- /** @internal */
15
- export function isBuiltInAgentPlugin(definition: ServerEntry, field: LiteralPluginField): boolean {
16
- return (definition as BuiltInAgentPluginEntry)[BUILT_IN_AGENT_PLUGIN]?.has(field) === true;
17
- }
18
-
19
- /** @internal */
20
- export function cloneBuiltInAgentPluginEntry(source: ServerEntry): ServerEntry | undefined {
21
- const fields = LITERAL_PLUGIN_FIELDS.filter(field => Object.hasOwn(source, field) && isBuiltInAgentPlugin(source, field));
22
- if (fields.length === 0) return undefined;
23
- return markBuiltInAgentPlugin(structuredClone(source), fields);
24
- }
25
-
26
- /** @internal */
27
- export function mergeBuiltInAgentPluginEntries(base: ServerEntry, next: ServerEntry): ServerEntry {
28
- const merged = { ...base, ...next };
29
- delete (merged as BuiltInAgentPluginEntry)[BUILT_IN_AGENT_PLUGIN];
30
- const fields = LITERAL_PLUGIN_FIELDS.filter(field => {
31
- const owner = Object.hasOwn(next, field) ? next : base;
32
- return Object.hasOwn(owner, field) && isBuiltInAgentPlugin(owner, field);
33
- });
34
- if (fields.length > 0) markBuiltInAgentPlugin(merged, fields);
35
- return merged;
36
- }