toolcraft 0.0.749 → 0.0.751

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 (374) hide show
  1. package/composition.json +23 -3
  2. package/dist/composition.json +23 -3
  3. package/dist/human-in-loop/approvals-commands.d.ts +1 -1
  4. package/dist/index.d.ts +1 -262
  5. package/dist/index.js +1 -573
  6. package/dist/runtime-platform.d.ts +2 -0
  7. package/dist/runtime-platform.js +2 -0
  8. package/dist/runtime-platform.workerd.d.ts +3 -0
  9. package/dist/runtime-platform.workerd.js +10 -0
  10. package/dist/runtime.d.ts +262 -0
  11. package/dist/runtime.js +576 -0
  12. package/node_modules/@noble/hashes/LICENSE +21 -0
  13. package/node_modules/@noble/hashes/README.md +478 -0
  14. package/node_modules/@noble/hashes/_blake.d.ts +20 -0
  15. package/node_modules/@noble/hashes/_blake.js +59 -0
  16. package/node_modules/@noble/hashes/_md.d.ts +95 -0
  17. package/node_modules/@noble/hashes/_md.js +209 -0
  18. package/node_modules/@noble/hashes/_u64.d.ts +36 -0
  19. package/node_modules/@noble/hashes/_u64.js +77 -0
  20. package/node_modules/@noble/hashes/argon2.d.ts +148 -0
  21. package/node_modules/@noble/hashes/argon2.js +577 -0
  22. package/node_modules/@noble/hashes/blake1.d.ts +162 -0
  23. package/node_modules/@noble/hashes/blake1.js +630 -0
  24. package/node_modules/@noble/hashes/blake2.d.ts +203 -0
  25. package/node_modules/@noble/hashes/blake2.js +573 -0
  26. package/node_modules/@noble/hashes/blake3.d.ts +68 -0
  27. package/node_modules/@noble/hashes/blake3.js +310 -0
  28. package/node_modules/@noble/hashes/eskdf.d.ts +91 -0
  29. package/node_modules/@noble/hashes/eskdf.js +225 -0
  30. package/node_modules/@noble/hashes/hkdf.d.ts +70 -0
  31. package/node_modules/@noble/hashes/hkdf.js +152 -0
  32. package/node_modules/@noble/hashes/hmac.d.ts +50 -0
  33. package/node_modules/@noble/hashes/hmac.js +93 -0
  34. package/node_modules/@noble/hashes/index.d.ts +1 -0
  35. package/node_modules/@noble/hashes/index.js +34 -0
  36. package/node_modules/@noble/hashes/legacy.d.ts +107 -0
  37. package/node_modules/@noble/hashes/legacy.js +348 -0
  38. package/node_modules/@noble/hashes/package.json +91 -0
  39. package/node_modules/@noble/hashes/pbkdf2.d.ts +66 -0
  40. package/node_modules/@noble/hashes/pbkdf2.js +176 -0
  41. package/node_modules/@noble/hashes/scrypt.d.ts +98 -0
  42. package/node_modules/@noble/hashes/scrypt.js +304 -0
  43. package/node_modules/@noble/hashes/sha2.d.ts +176 -0
  44. package/node_modules/@noble/hashes/sha2.js +446 -0
  45. package/node_modules/@noble/hashes/sha3-addons.d.ts +533 -0
  46. package/node_modules/@noble/hashes/sha3-addons.js +973 -0
  47. package/node_modules/@noble/hashes/sha3.d.ts +208 -0
  48. package/node_modules/@noble/hashes/sha3.js +475 -0
  49. package/node_modules/@noble/hashes/src/_blake.ts +67 -0
  50. package/node_modules/@noble/hashes/src/_md.ts +227 -0
  51. package/node_modules/@noble/hashes/src/_u64.ts +111 -0
  52. package/node_modules/@noble/hashes/src/argon2.ts +693 -0
  53. package/node_modules/@noble/hashes/src/blake1.ts +677 -0
  54. package/node_modules/@noble/hashes/src/blake2.ts +648 -0
  55. package/node_modules/@noble/hashes/src/blake3.ts +344 -0
  56. package/node_modules/@noble/hashes/src/eskdf.ts +265 -0
  57. package/node_modules/@noble/hashes/src/hkdf.ts +161 -0
  58. package/node_modules/@noble/hashes/src/hmac.ts +130 -0
  59. package/node_modules/@noble/hashes/src/index.ts +33 -0
  60. package/node_modules/@noble/hashes/src/legacy.ts +361 -0
  61. package/node_modules/@noble/hashes/src/pbkdf2.ts +219 -0
  62. package/node_modules/@noble/hashes/src/scrypt.ts +375 -0
  63. package/node_modules/@noble/hashes/src/sha2.ts +486 -0
  64. package/node_modules/@noble/hashes/src/sha3-addons.ts +1157 -0
  65. package/node_modules/@noble/hashes/src/sha3.ts +525 -0
  66. package/node_modules/@noble/hashes/src/utils.ts +978 -0
  67. package/node_modules/@noble/hashes/src/webcrypto.ts +283 -0
  68. package/node_modules/@noble/hashes/utils.d.ts +560 -0
  69. package/node_modules/@noble/hashes/utils.js +687 -0
  70. package/node_modules/@noble/hashes/webcrypto.d.ts +121 -0
  71. package/node_modules/@noble/hashes/webcrypto.js +228 -0
  72. package/node_modules/@poe-code/agent-mcp-config/dist/apply.js +23 -9
  73. package/node_modules/@poe-code/config-mutations/README.md +2 -0
  74. package/node_modules/@poe-code/config-mutations/dist/execution/apply-mutation.js +4 -5
  75. package/node_modules/@poe-code/config-mutations/dist/execution/path-utils.d.ts +3 -4
  76. package/node_modules/@poe-code/config-mutations/dist/execution/path-utils.js +3 -3
  77. package/node_modules/@poe-code/config-mutations/dist/template/render.js +1 -1
  78. package/node_modules/@poe-code/config-mutations/dist/testing/mock-fs.d.ts +2 -2
  79. package/node_modules/@poe-code/config-mutations/dist/testing/mock-fs.js +3 -6
  80. package/node_modules/@poe-code/config-mutations/dist/types.d.ts +4 -2
  81. package/node_modules/@poe-code/process-runner/README.md +2 -1
  82. package/node_modules/@poe-code/process-runner/dist/transfer-filesystem.d.ts +1 -0
  83. package/node_modules/@poe-code/process-runner/dist/transfer-filesystem.js +1 -0
  84. package/node_modules/@poe-code/process-runner/dist/transfer-filesystem.workerd.d.ts +2 -0
  85. package/node_modules/@poe-code/process-runner/dist/transfer-filesystem.workerd.js +1 -0
  86. package/node_modules/@poe-code/process-runner/dist/types.d.ts +1 -1
  87. package/node_modules/@poe-code/process-runner/dist/workspace-transfer.d.ts +6 -5
  88. package/node_modules/@poe-code/process-runner/dist/workspace-transfer.js +67 -29
  89. package/node_modules/@poe-code/process-runner/package.json +13 -0
  90. package/node_modules/@poe-code/safe-fs/LICENSE +21 -0
  91. package/node_modules/@poe-code/safe-fs/PROVENANCE.json +428 -0
  92. package/node_modules/@poe-code/safe-fs/README.md +411 -0
  93. package/node_modules/@poe-code/safe-fs/dist/bridge/confinement.d.ts +3 -0
  94. package/node_modules/@poe-code/safe-fs/dist/bridge/confinement.js +171 -0
  95. package/node_modules/@poe-code/safe-fs/dist/bridge/filesystem.d.ts +93 -0
  96. package/node_modules/@poe-code/safe-fs/dist/bridge/filesystem.js +453 -0
  97. package/node_modules/@poe-code/safe-fs/dist/bridge/index.d.ts +7 -0
  98. package/node_modules/@poe-code/safe-fs/dist/bridge/index.js +19 -0
  99. package/node_modules/@poe-code/safe-fs/dist/bridge/stats.d.ts +4 -0
  100. package/node_modules/@poe-code/safe-fs/dist/bridge/stats.js +37 -0
  101. package/node_modules/@poe-code/safe-fs/dist/bridge/types.d.ts +81 -0
  102. package/node_modules/@poe-code/safe-fs/dist/bridge/types.js +1 -0
  103. package/node_modules/@poe-code/safe-fs/dist/bridge/values.d.ts +6 -0
  104. package/node_modules/@poe-code/safe-fs/dist/bridge/values.js +65 -0
  105. package/node_modules/@poe-code/safe-fs/dist/config/memory.d.ts +3 -0
  106. package/node_modules/@poe-code/safe-fs/dist/config/memory.js +7 -0
  107. package/node_modules/@poe-code/safe-fs/dist/config/real.d.ts +5 -0
  108. package/node_modules/@poe-code/safe-fs/dist/config/real.js +16 -0
  109. package/node_modules/@poe-code/safe-fs/dist/config/registry.d.ts +2 -0
  110. package/node_modules/@poe-code/safe-fs/dist/config/registry.js +15 -0
  111. package/node_modules/@poe-code/safe-fs/dist/config.d.ts +15 -0
  112. package/node_modules/@poe-code/safe-fs/dist/config.js +46 -0
  113. package/node_modules/@poe-code/safe-fs/dist/config.node.d.ts +2 -0
  114. package/node_modules/@poe-code/safe-fs/dist/config.node.js +11 -0
  115. package/node_modules/@poe-code/safe-fs/dist/config.portable.d.ts +3 -0
  116. package/node_modules/@poe-code/safe-fs/dist/config.portable.js +9 -0
  117. package/node_modules/@poe-code/safe-fs/dist/contracts/abort.d.ts +5 -0
  118. package/node_modules/@poe-code/safe-fs/dist/contracts/abort.js +34 -0
  119. package/node_modules/@poe-code/safe-fs/dist/contracts/cleanup.d.ts +1 -0
  120. package/node_modules/@poe-code/safe-fs/dist/contracts/cleanup.js +9 -0
  121. package/node_modules/@poe-code/safe-fs/dist/contracts/descriptor.d.ts +38 -0
  122. package/node_modules/@poe-code/safe-fs/dist/contracts/descriptor.js +1 -0
  123. package/node_modules/@poe-code/safe-fs/dist/contracts/errors.d.ts +53 -0
  124. package/node_modules/@poe-code/safe-fs/dist/contracts/errors.js +99 -0
  125. package/node_modules/@poe-code/safe-fs/dist/contracts/filesystem.d.ts +379 -0
  126. package/node_modules/@poe-code/safe-fs/dist/contracts/filesystem.js +1 -0
  127. package/node_modules/@poe-code/safe-fs/dist/contracts/index.d.ts +6 -0
  128. package/node_modules/@poe-code/safe-fs/dist/contracts/index.js +6 -0
  129. package/node_modules/@poe-code/safe-fs/dist/contracts/io.d.ts +12 -0
  130. package/node_modules/@poe-code/safe-fs/dist/contracts/io.js +321 -0
  131. package/node_modules/@poe-code/safe-fs/dist/contracts/object.d.ts +134 -0
  132. package/node_modules/@poe-code/safe-fs/dist/contracts/object.js +97 -0
  133. package/node_modules/@poe-code/safe-fs/dist/contracts/path.d.ts +3 -0
  134. package/node_modules/@poe-code/safe-fs/dist/contracts/path.js +2 -0
  135. package/node_modules/@poe-code/safe-fs/dist/contracts/portable-path.d.ts +21 -0
  136. package/node_modules/@poe-code/safe-fs/dist/contracts/portable-path.js +78 -0
  137. package/node_modules/@poe-code/safe-fs/dist/contracts/virtual-path.d.ts +15 -0
  138. package/node_modules/@poe-code/safe-fs/dist/contracts/virtual-path.js +162 -0
  139. package/node_modules/@poe-code/safe-fs/dist/core.d.ts +19 -0
  140. package/node_modules/@poe-code/safe-fs/dist/core.js +17 -0
  141. package/node_modules/@poe-code/safe-fs/dist/fs/capabilities.d.ts +10 -0
  142. package/node_modules/@poe-code/safe-fs/dist/fs/capabilities.js +216 -0
  143. package/node_modules/@poe-code/safe-fs/dist/fs/conditional-chmod.d.ts +7 -0
  144. package/node_modules/@poe-code/safe-fs/dist/fs/conditional-chmod.js +19 -0
  145. package/node_modules/@poe-code/safe-fs/dist/fs/descriptor.d.ts +21 -0
  146. package/node_modules/@poe-code/safe-fs/dist/fs/descriptor.js +279 -0
  147. package/node_modules/@poe-code/safe-fs/dist/fs/devices/index.d.ts +59 -0
  148. package/node_modules/@poe-code/safe-fs/dist/fs/devices/index.js +875 -0
  149. package/node_modules/@poe-code/safe-fs/dist/fs/devices/path.d.ts +7 -0
  150. package/node_modules/@poe-code/safe-fs/dist/fs/devices/path.js +250 -0
  151. package/node_modules/@poe-code/safe-fs/dist/fs/devices/stream.d.ts +6 -0
  152. package/node_modules/@poe-code/safe-fs/dist/fs/devices/stream.js +136 -0
  153. package/node_modules/@poe-code/safe-fs/dist/fs/directory-admission.d.ts +3 -0
  154. package/node_modules/@poe-code/safe-fs/dist/fs/directory-admission.js +14 -0
  155. package/node_modules/@poe-code/safe-fs/dist/fs/memory/atomic-view.d.ts +11 -0
  156. package/node_modules/@poe-code/safe-fs/dist/fs/memory/atomic-view.js +13 -0
  157. package/node_modules/@poe-code/safe-fs/dist/fs/memory/index.d.ts +186 -0
  158. package/node_modules/@poe-code/safe-fs/dist/fs/memory/index.js +3771 -0
  159. package/node_modules/@poe-code/safe-fs/dist/fs/memory/ledger.d.ts +26 -0
  160. package/node_modules/@poe-code/safe-fs/dist/fs/memory/ledger.js +96 -0
  161. package/node_modules/@poe-code/safe-fs/dist/fs/memory/limits.d.ts +13 -0
  162. package/node_modules/@poe-code/safe-fs/dist/fs/memory/limits.js +26 -0
  163. package/node_modules/@poe-code/safe-fs/dist/fs/memory/missing-target.d.ts +15 -0
  164. package/node_modules/@poe-code/safe-fs/dist/fs/memory/missing-target.js +144 -0
  165. package/node_modules/@poe-code/safe-fs/dist/fs/mount/comparison.d.ts +19 -0
  166. package/node_modules/@poe-code/safe-fs/dist/fs/mount/comparison.js +118 -0
  167. package/node_modules/@poe-code/safe-fs/dist/fs/mount/identity.d.ts +6 -0
  168. package/node_modules/@poe-code/safe-fs/dist/fs/mount/identity.js +29 -0
  169. package/node_modules/@poe-code/safe-fs/dist/fs/mount/index.d.ts +74 -0
  170. package/node_modules/@poe-code/safe-fs/dist/fs/mount/index.js +1291 -0
  171. package/node_modules/@poe-code/safe-fs/dist/fs/object-authority.d.ts +27 -0
  172. package/node_modules/@poe-code/safe-fs/dist/fs/object-authority.js +287 -0
  173. package/node_modules/@poe-code/safe-fs/dist/fs/object-publication/index.d.ts +45 -0
  174. package/node_modules/@poe-code/safe-fs/dist/fs/object-publication/index.js +531 -0
  175. package/node_modules/@poe-code/safe-fs/dist/fs/overlay/index.d.ts +87 -0
  176. package/node_modules/@poe-code/safe-fs/dist/fs/overlay/index.js +1185 -0
  177. package/node_modules/@poe-code/safe-fs/dist/fs/overlay/memory-publication.d.ts +42 -0
  178. package/node_modules/@poe-code/safe-fs/dist/fs/overlay/memory-publication.js +558 -0
  179. package/node_modules/@poe-code/safe-fs/dist/fs/path-namespace.d.ts +4 -0
  180. package/node_modules/@poe-code/safe-fs/dist/fs/path-namespace.js +63 -0
  181. package/node_modules/@poe-code/safe-fs/dist/fs/quota/index.d.ts +12 -0
  182. package/node_modules/@poe-code/safe-fs/dist/fs/quota/index.js +520 -0
  183. package/node_modules/@poe-code/safe-fs/dist/fs/readonly/index.d.ts +37 -0
  184. package/node_modules/@poe-code/safe-fs/dist/fs/readonly/index.js +208 -0
  185. package/node_modules/@poe-code/safe-fs/dist/fs/real/allocation.d.ts +1 -0
  186. package/node_modules/@poe-code/safe-fs/dist/fs/real/allocation.js +8 -0
  187. package/node_modules/@poe-code/safe-fs/dist/fs/real/index.d.ts +105 -0
  188. package/node_modules/@poe-code/safe-fs/dist/fs/real/index.js +1259 -0
  189. package/node_modules/@poe-code/safe-fs/dist/fs/s3/authority.d.ts +7 -0
  190. package/node_modules/@poe-code/safe-fs/dist/fs/s3/authority.js +38 -0
  191. package/node_modules/@poe-code/safe-fs/dist/fs/s3/filesystem.d.ts +130 -0
  192. package/node_modules/@poe-code/safe-fs/dist/fs/s3/filesystem.js +1137 -0
  193. package/node_modules/@poe-code/safe-fs/dist/fs/s3/http/bytes.d.ts +1 -0
  194. package/node_modules/@poe-code/safe-fs/dist/fs/s3/http/bytes.js +9 -0
  195. package/node_modules/@poe-code/safe-fs/dist/fs/s3/http/index.d.ts +2 -0
  196. package/node_modules/@poe-code/safe-fs/dist/fs/s3/http/index.js +1 -0
  197. package/node_modules/@poe-code/safe-fs/dist/fs/s3/http/request-fetch.d.ts +15 -0
  198. package/node_modules/@poe-code/safe-fs/dist/fs/s3/http/request-fetch.js +74 -0
  199. package/node_modules/@poe-code/safe-fs/dist/fs/s3/http/request-node.d.ts +4 -0
  200. package/node_modules/@poe-code/safe-fs/dist/fs/s3/http/request-node.js +111 -0
  201. package/node_modules/@poe-code/safe-fs/dist/fs/s3/http/request.d.ts +17 -0
  202. package/node_modules/@poe-code/safe-fs/dist/fs/s3/http/request.js +89 -0
  203. package/node_modules/@poe-code/safe-fs/dist/fs/s3/http/signature.d.ts +20 -0
  204. package/node_modules/@poe-code/safe-fs/dist/fs/s3/http/signature.js +76 -0
  205. package/node_modules/@poe-code/safe-fs/dist/fs/s3/http/transport.d.ts +3 -0
  206. package/node_modules/@poe-code/safe-fs/dist/fs/s3/http/transport.js +478 -0
  207. package/node_modules/@poe-code/safe-fs/dist/fs/s3/http/types.d.ts +30 -0
  208. package/node_modules/@poe-code/safe-fs/dist/fs/s3/http/types.js +1 -0
  209. package/node_modules/@poe-code/safe-fs/dist/fs/s3/http/xml.d.ts +14 -0
  210. package/node_modules/@poe-code/safe-fs/dist/fs/s3/http/xml.js +192 -0
  211. package/node_modules/@poe-code/safe-fs/dist/fs/s3/index.d.ts +8 -0
  212. package/node_modules/@poe-code/safe-fs/dist/fs/s3/index.js +4 -0
  213. package/node_modules/@poe-code/safe-fs/dist/fs/s3/key-order.d.ts +2 -0
  214. package/node_modules/@poe-code/safe-fs/dist/fs/s3/key-order.js +11 -0
  215. package/node_modules/@poe-code/safe-fs/dist/fs/s3/manifest-admission.d.ts +8 -0
  216. package/node_modules/@poe-code/safe-fs/dist/fs/s3/manifest-admission.js +167 -0
  217. package/node_modules/@poe-code/safe-fs/dist/fs/s3/mock.d.ts +48 -0
  218. package/node_modules/@poe-code/safe-fs/dist/fs/s3/mock.js +249 -0
  219. package/node_modules/@poe-code/safe-fs/dist/fs/s3/namespace.d.ts +13 -0
  220. package/node_modules/@poe-code/safe-fs/dist/fs/s3/namespace.js +400 -0
  221. package/node_modules/@poe-code/safe-fs/dist/fs/s3/registry.d.ts +10 -0
  222. package/node_modules/@poe-code/safe-fs/dist/fs/s3/registry.js +73 -0
  223. package/node_modules/@poe-code/safe-fs/dist/fs/s3/transport.d.ts +103 -0
  224. package/node_modules/@poe-code/safe-fs/dist/fs/s3/transport.js +28 -0
  225. package/node_modules/@poe-code/safe-fs/dist/fs/scoped.d.ts +19 -0
  226. package/node_modules/@poe-code/safe-fs/dist/fs/scoped.js +663 -0
  227. package/node_modules/@poe-code/safe-fs/dist/fs/staging-ancestry.d.ts +8 -0
  228. package/node_modules/@poe-code/safe-fs/dist/fs/staging-ancestry.js +115 -0
  229. package/node_modules/@poe-code/safe-fs/dist/fs/staging-cleanup.d.ts +5 -0
  230. package/node_modules/@poe-code/safe-fs/dist/fs/staging-cleanup.js +63 -0
  231. package/node_modules/@poe-code/safe-fs/dist/fs/webdav/index.d.ts +2 -0
  232. package/node_modules/@poe-code/safe-fs/dist/fs/webdav/index.js +1 -0
  233. package/node_modules/@poe-code/safe-fs/dist/fs/webdav/resource-id.d.ts +18 -0
  234. package/node_modules/@poe-code/safe-fs/dist/fs/webdav/resource-id.js +109 -0
  235. package/node_modules/@poe-code/safe-fs/dist/fs/webdav/webdav.d.ts +141 -0
  236. package/node_modules/@poe-code/safe-fs/dist/fs/webdav/webdav.js +1377 -0
  237. package/node_modules/@poe-code/safe-fs/dist/fs/webdav/xml.d.ts +15 -0
  238. package/node_modules/@poe-code/safe-fs/dist/fs/webdav/xml.js +59 -0
  239. package/node_modules/@poe-code/safe-fs/dist/index.d.ts +25 -0
  240. package/node_modules/@poe-code/safe-fs/dist/index.js +21 -0
  241. package/node_modules/@poe-code/safe-fs/dist/native/fs-seek/linux-x64-glibc.node +0 -0
  242. package/node_modules/@poe-code/safe-fs/dist/native/fs-seek/loader.d.ts +5 -0
  243. package/node_modules/@poe-code/safe-fs/dist/native/fs-seek/loader.mjs +120 -0
  244. package/node_modules/@poe-code/safe-fs/dist/native/fs-seek/manifest.json +46 -0
  245. package/node_modules/@poe-code/safe-fs/dist/node/filesystem.d.ts +19 -0
  246. package/node_modules/@poe-code/safe-fs/dist/node/filesystem.js +30 -0
  247. package/node_modules/@poe-code/safe-fs/dist/node/host.d.ts +3 -0
  248. package/node_modules/@poe-code/safe-fs/dist/node/host.js +78 -0
  249. package/node_modules/@poe-code/safe-fs/dist/node/index.d.ts +3 -0
  250. package/node_modules/@poe-code/safe-fs/dist/node/index.js +2 -0
  251. package/node_modules/@poe-code/safe-fs/dist/node/native-seek-unavailable.d.ts +1 -0
  252. package/node_modules/@poe-code/safe-fs/dist/node/native-seek-unavailable.js +5 -0
  253. package/node_modules/@poe-code/safe-fs/dist/node/native-seek.d.ts +3 -0
  254. package/node_modules/@poe-code/safe-fs/dist/node/native-seek.js +54 -0
  255. package/node_modules/@poe-code/safe-fs/dist/node/stats.d.ts +1 -0
  256. package/node_modules/@poe-code/safe-fs/dist/node/stats.js +1 -0
  257. package/node_modules/@poe-code/safe-fs/dist/node/values.d.ts +1 -0
  258. package/node_modules/@poe-code/safe-fs/dist/node/values.js +1 -0
  259. package/node_modules/@poe-code/safe-fs/dist/node-host.d.ts +1 -0
  260. package/node_modules/@poe-code/safe-fs/dist/node-host.js +1 -0
  261. package/node_modules/@poe-code/safe-fs/dist/node-unavailable.d.ts +1 -0
  262. package/node_modules/@poe-code/safe-fs/dist/node-unavailable.js +1 -0
  263. package/node_modules/@poe-code/safe-fs/dist/package.json +29 -0
  264. package/node_modules/@poe-code/safe-fs/dist/platform/browser-path.d.ts +1 -0
  265. package/node_modules/@poe-code/safe-fs/dist/platform/browser-path.js +1 -0
  266. package/node_modules/@poe-code/safe-fs/dist/platform/browser.d.ts +26 -0
  267. package/node_modules/@poe-code/safe-fs/dist/platform/browser.js +58 -0
  268. package/node_modules/@poe-code/safe-fs/dist/platform/node-path.d.ts +1 -0
  269. package/node_modules/@poe-code/safe-fs/dist/platform/node-path.js +1 -0
  270. package/node_modules/@poe-code/safe-fs/dist/platform/node.d.ts +26 -0
  271. package/node_modules/@poe-code/safe-fs/dist/platform/node.js +64 -0
  272. package/node_modules/@poe-code/safe-fs/dist/platform/transport-budget.d.ts +9 -0
  273. package/node_modules/@poe-code/safe-fs/dist/platform/transport-budget.js +17 -0
  274. package/node_modules/@poe-code/safe-fs/dist/python/emscripten.d.ts +15 -0
  275. package/node_modules/@poe-code/safe-fs/dist/python/emscripten.js +357 -0
  276. package/node_modules/@poe-code/safe-fs/dist/python/filesystem.d.ts +51 -0
  277. package/node_modules/@poe-code/safe-fs/dist/python/filesystem.js +243 -0
  278. package/node_modules/@poe-code/safe-fs/dist/python/flags.d.ts +3 -0
  279. package/node_modules/@poe-code/safe-fs/dist/python/flags.js +14 -0
  280. package/node_modules/@poe-code/safe-fs/dist/python/index.d.ts +9 -0
  281. package/node_modules/@poe-code/safe-fs/dist/python/index.js +5 -0
  282. package/node_modules/@poe-code/safe-fs/dist/python/native.d.ts +18 -0
  283. package/node_modules/@poe-code/safe-fs/dist/python/native.js +446 -0
  284. package/node_modules/@poe-code/safe-fs/dist/python/request.d.ts +2 -0
  285. package/node_modules/@poe-code/safe-fs/dist/python/request.js +61 -0
  286. package/node_modules/@poe-code/safe-fs/dist/python/stat.d.ts +8 -0
  287. package/node_modules/@poe-code/safe-fs/dist/python/stat.js +34 -0
  288. package/node_modules/@poe-code/safe-fs/dist/runtime-core.d.ts +27 -0
  289. package/node_modules/@poe-code/safe-fs/dist/runtime-core.js +57 -0
  290. package/node_modules/@poe-code/safe-fs/dist/testing/atomic-filesystem.d.ts +16 -0
  291. package/node_modules/@poe-code/safe-fs/dist/testing/atomic-filesystem.js +496 -0
  292. package/node_modules/@poe-code/safe-fs/dist/testing/object-io-control.d.ts +23 -0
  293. package/node_modules/@poe-code/safe-fs/dist/testing/object-io-control.js +39 -0
  294. package/node_modules/@poe-code/safe-fs/dist/testing/object-io-metrics.d.ts +31 -0
  295. package/node_modules/@poe-code/safe-fs/dist/testing/object-io-metrics.js +143 -0
  296. package/node_modules/@poe-code/safe-fs/dist/testing/object-publication.d.ts +19 -0
  297. package/node_modules/@poe-code/safe-fs/dist/testing/object-publication.js +209 -0
  298. package/node_modules/@poe-code/safe-fs/dist/xml.d.ts +1 -0
  299. package/node_modules/@poe-code/safe-fs/dist/xml.js +1 -0
  300. package/node_modules/@poe-code/safe-fs/package.json +189 -0
  301. package/node_modules/@poe-code/task-list/README.md +2 -0
  302. package/node_modules/@poe-code/task-list/dist/backends/gh-issues-client.d.ts +1 -1
  303. package/node_modules/@poe-code/task-list/dist/backends/gh-issues-client.js +11 -4
  304. package/node_modules/@poe-code/task-list/dist/backends/markdown-dir.js +2 -2
  305. package/node_modules/@poe-code/task-list/dist/backends/utils.js +5 -7
  306. package/node_modules/@poe-code/task-list/dist/backends/yaml-file.js +1 -1
  307. package/node_modules/@poe-code/task-list/dist/default-host.d.ts +2 -0
  308. package/node_modules/@poe-code/task-list/dist/default-host.js +2 -0
  309. package/node_modules/@poe-code/task-list/dist/default-host.workerd.d.ts +4 -0
  310. package/node_modules/@poe-code/task-list/dist/default-host.workerd.js +6 -0
  311. package/node_modules/@poe-code/task-list/dist/filesystem.d.ts +3 -0
  312. package/node_modules/@poe-code/task-list/dist/filesystem.js +32 -0
  313. package/node_modules/@poe-code/task-list/dist/move.js +3 -3
  314. package/node_modules/@poe-code/task-list/dist/open.js +2 -5
  315. package/node_modules/@poe-code/task-list/dist/paths.d.ts +12 -0
  316. package/node_modules/@poe-code/task-list/dist/paths.js +7 -0
  317. package/node_modules/@poe-code/task-list/dist/types.d.ts +6 -5
  318. package/node_modules/@poe-code/task-list/package.json +9 -0
  319. package/node_modules/@poe-code/terminal-text/LICENSE +21 -0
  320. package/node_modules/@poe-code/terminal-text/README.md +12 -0
  321. package/node_modules/@poe-code/terminal-text/dist/index.d.ts +2 -0
  322. package/node_modules/@poe-code/terminal-text/dist/index.js +20 -0
  323. package/node_modules/@poe-code/terminal-text/package.json +22 -0
  324. package/node_modules/@poe-code/xml-ast/LICENSE +21 -0
  325. package/node_modules/@poe-code/xml-ast/README.md +28 -0
  326. package/node_modules/@poe-code/xml-ast/dist/index.d.ts +47 -0
  327. package/node_modules/@poe-code/xml-ast/dist/index.js +635 -0
  328. package/node_modules/@poe-code/xml-ast/package.json +25 -0
  329. package/node_modules/auth-store/README.md +35 -0
  330. package/node_modules/auth-store/dist/index.browser.d.ts +4 -0
  331. package/node_modules/auth-store/dist/index.browser.js +2 -0
  332. package/node_modules/auth-store/dist/provider-store.d.ts +1 -1
  333. package/node_modules/auth-store/dist/safe-fs-secret-store.d.ts +21 -0
  334. package/node_modules/auth-store/dist/safe-fs-secret-store.js +119 -0
  335. package/node_modules/auth-store/dist/secret-store.d.ts +12 -0
  336. package/node_modules/auth-store/dist/secret-store.js +1 -0
  337. package/node_modules/auth-store/dist/transaction-lock.d.ts +2 -4
  338. package/node_modules/auth-store/dist/types.d.ts +2 -9
  339. package/node_modules/auth-store/package.json +16 -2
  340. package/node_modules/tiny-http-mcp-server/dist/composition.json +16 -1
  341. package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/README.md +25 -0
  342. package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/client/authorization-state.js +4 -4
  343. package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/client/default-oauth-client-provider.js +6 -40
  344. package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/client/oauth-form.d.ts +10 -0
  345. package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/client/oauth-form.js +20 -0
  346. package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/client/pkce.js +4 -3
  347. package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/client/register-client.d.ts +14 -0
  348. package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/client/register-client.js +53 -0
  349. package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/client/resumable.d.ts +16 -2
  350. package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/client/resumable.js +29 -9
  351. package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/client/revoke-token.d.ts +12 -0
  352. package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/client/revoke-token.js +23 -0
  353. package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/client/token-endpoint.js +6 -19
  354. package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/http-fetch.js +1 -1
  355. package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/index.browser.d.ts +6 -2
  356. package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/index.browser.js +5 -1
  357. package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/index.d.ts +5 -2
  358. package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/index.js +4 -1
  359. package/node_modules/tiny-http-mcp-server/package.json +4 -4
  360. package/node_modules/tiny-mcp-client/README.md +2 -0
  361. package/node_modules/tiny-mcp-client/dist/index.browser.d.ts +25 -23
  362. package/node_modules/tiny-mcp-client/dist/index.browser.js +116 -1
  363. package/node_modules/tiny-mcp-client/dist/index.d.ts +25 -23
  364. package/node_modules/tiny-mcp-client/dist/index.js +1034 -561
  365. package/node_modules/tiny-mcp-client/package.json +15 -0
  366. package/node_modules/tiny-stdio-mcp-server/dist/composition.json +1 -1
  367. package/node_modules/toolcraft-design/dist/components/table.js +6 -0
  368. package/node_modules/toolcraft-design/dist/escape-terminal-text.d.ts +1 -2
  369. package/node_modules/toolcraft-design/dist/escape-terminal-text.js +1 -20
  370. package/node_modules/toolcraft-design/dist/terminal-markdown/parser/frontmatter.js +2 -1
  371. package/node_modules/toolcraft-design/dist/terminal-markdown/parser.js +2 -1
  372. package/node_modules/toolcraft-schema/dist/json-schema/utils.js +3 -0
  373. package/node_modules/toolcraft-schema/package.json +1 -1
  374. package/package.json +32 -7
@@ -124,8 +124,7 @@ function assertHttpJsonBudget(text) {
124
124
  if (stack.length !== 0) throw new SyntaxError("Unterminated MCP HTTP JSON container");
125
125
  }
126
126
 
127
- // src/internal.ts
128
- import { spawn as spawn2 } from "node:child_process";
127
+ // src/stream.node.ts
129
128
  import { PassThrough } from "node:stream";
130
129
 
131
130
  // src/http-message-validation.ts
@@ -304,6 +303,9 @@ function dialectFor(schema, inherited) {
304
303
  return inherited;
305
304
  }
306
305
  function resolveUri(reference, baseUri) {
306
+ if (typeof URL === "undefined" && (reference === "" || reference.startsWith("#"))) {
307
+ return `${withoutFragment(baseUri)}${reference}`;
308
+ }
307
309
  try {
308
310
  return new URL(reference, baseUri).href;
309
311
  } catch {
@@ -4798,7 +4800,7 @@ async function fetchMcpResponse(fetchImplementation, input, init = {}) {
4798
4800
  abort();
4799
4801
  return;
4800
4802
  }
4801
- if (response.redirected || response.type === "opaqueredirect") {
4803
+ if (response.redirected || response.type === "opaqueredirect" || response.status >= 300 && response.status < 400) {
4802
4804
  void response.body?.cancel().catch(() => void 0);
4803
4805
  finish(new Error("MCP HTTP redirects are not allowed"));
4804
4806
  } else
@@ -4807,180 +4809,546 @@ async function fetchMcpResponse(fetchImplementation, input, init = {}) {
4807
4809
  });
4808
4810
  }
4809
4811
 
4810
- // ../mcp-oauth/dist/client/default-oauth-client-provider.js
4811
- import { URL as URL2 } from "node:url";
4812
-
4813
- // ../mcp-oauth/dist/client/loopback-authorization.js
4814
- import http from "node:http";
4815
-
4816
- // ../mcp-oauth/dist/client/authorization-state.js
4817
- import crypto3 from "node:crypto";
4818
- function createAuthorizationState(input) {
4819
- const payload = {
4820
- v: 1,
4821
- n: crypto3.randomBytes(16).toString("base64url"),
4822
- i: input.issuer,
4823
- r: input.requireIssuer
4824
- };
4825
- return Buffer.from(JSON.stringify(payload), "utf8").toString("base64url");
4812
+ // ../mcp-oauth/dist/client/oauth-form.js
4813
+ function createOAuthFormRequest(input) {
4814
+ const method = normalizeOAuthTokenEndpointAuthMethod(input.tokenEndpointAuthMethod) ?? (input.clientSecret === void 0 ? "none" : "client_secret_post");
4815
+ if (method !== "none" && (input.clientSecret === void 0 || input.clientSecret.trim() === ""))
4816
+ throw new Error("OAuth token endpoint authentication requires a client secret");
4817
+ const body = new URLSearchParams(input.params);
4818
+ const headers = new Headers({ Accept: "application/json", "Content-Type": "application/x-www-form-urlencoded" });
4819
+ if (method === "client_secret_basic") {
4820
+ const encoded = new URLSearchParams({ credential: input.clientId }).toString().slice("credential=".length);
4821
+ const encodedSecret = new URLSearchParams({ credential: input.clientSecret }).toString().slice("credential=".length);
4822
+ headers.set("Authorization", `Basic ${btoa(`${encoded}:${encodedSecret}`)}`);
4823
+ } else {
4824
+ body.set("client_id", input.clientId);
4825
+ if (method === "client_secret_post")
4826
+ body.set("client_secret", input.clientSecret);
4827
+ }
4828
+ return { body, headers };
4826
4829
  }
4827
- function parseAuthorizationState(value) {
4828
- if (value === null || value.length === 0) {
4829
- return null;
4830
+
4831
+ // ../mcp-oauth/dist/http-response.js
4832
+ async function readBoundedResponseText(response, maxBytes, readers, signal) {
4833
+ if (maxBytes !== Infinity && (!Number.isSafeInteger(maxBytes) || maxBytes < 1))
4834
+ throw new Error("HTTP response byte limit must be a positive safe integer");
4835
+ if (signal?.aborted) {
4836
+ void response.body?.cancel().catch(() => void 0);
4837
+ throw signal.reason;
4838
+ }
4839
+ const length = response.headers.get("Content-Length");
4840
+ if (length !== null && length.length > 0 && [...length].every((character) => character >= "0" && character <= "9") && Number(length) > maxBytes) {
4841
+ void response.body?.cancel().catch(() => void 0);
4842
+ throw new Error(`HTTP response exceeds ${maxBytes} bytes`);
4830
4843
  }
4844
+ if (response.body === null)
4845
+ return "";
4846
+ const reader = response.body.getReader();
4847
+ readers?.add(reader);
4848
+ const abort = () => {
4849
+ void reader.cancel().catch(() => void 0);
4850
+ };
4851
+ signal?.addEventListener("abort", abort, { once: true });
4852
+ if (signal?.aborted)
4853
+ abort();
4854
+ const decoder2 = new TextDecoder("utf-8", { fatal: true });
4855
+ let bytes = 0;
4856
+ let text = "";
4831
4857
  try {
4832
- const decoded = Buffer.from(value, "base64url").toString("utf8");
4833
- const parsed = JSON.parse(decoded);
4834
- if (!isObjectRecord2(parsed)) {
4835
- return null;
4836
- }
4837
- const version = getOwnEntry4(parsed, "v");
4838
- const nonce = getOwnEntry4(parsed, "n");
4839
- const issuer = getOwnEntry4(parsed, "i");
4840
- const requireIssuer = getOwnEntry4(parsed, "r");
4841
- if (version !== 1 || typeof nonce !== "string" || nonce.length === 0 || typeof issuer !== "string" || issuer.length === 0 || typeof requireIssuer !== "boolean") {
4842
- return null;
4858
+ while (true) {
4859
+ const chunk = await reader.read();
4860
+ signal?.throwIfAborted();
4861
+ if (chunk.done)
4862
+ return text + decoder2.decode();
4863
+ bytes += chunk.value.byteLength;
4864
+ if (bytes > maxBytes)
4865
+ throw new Error(`HTTP response exceeds ${maxBytes} bytes`);
4866
+ text += decoder2.decode(chunk.value, { stream: true });
4843
4867
  }
4844
- return {
4845
- issuer,
4846
- requireIssuer
4847
- };
4848
- } catch {
4849
- return null;
4868
+ } catch (error) {
4869
+ void reader.cancel().catch(() => void 0);
4870
+ throw error;
4871
+ } finally {
4872
+ signal?.removeEventListener("abort", abort);
4873
+ readers?.delete(reader);
4874
+ reader.releaseLock();
4850
4875
  }
4851
4876
  }
4852
- function isObjectRecord2(value) {
4853
- return typeof value === "object" && value !== null && !Array.isArray(value);
4854
- }
4855
- function getOwnEntry4(record2, key2) {
4856
- return Object.prototype.hasOwnProperty.call(record2, key2) ? record2[key2] : void 0;
4857
- }
4858
4877
 
4859
- // ../mcp-oauth/dist/client/authorization-error.js
4860
- var authorizationErrorBrand = /* @__PURE__ */ Symbol.for("poe-platform.mcp-oauth.OAuthAuthorizationError");
4861
- var OAuthAuthorizationError = class extends Error {
4862
- error;
4863
- errorDescription;
4878
+ // ../mcp-oauth/dist/client/token-endpoint.js
4879
+ var MAX_JS_DATE_MS2 = 864e13;
4880
+ var oauthErrorBrand = /* @__PURE__ */ Symbol.for("poe-platform.mcp-oauth.OAuthError");
4881
+ var OAuthError = class extends Error {
4864
4882
  /** Recognize errors from separately bundled copies of this package. */
4865
4883
  static is(value) {
4866
- return value instanceof Error && Object.getOwnPropertyDescriptor(value, authorizationErrorBrand)?.value === true;
4884
+ return value instanceof Error && Object.getOwnPropertyDescriptor(value, oauthErrorBrand)?.value === true;
4867
4885
  }
4868
- constructor(error, errorDescription) {
4869
- super(`OAuth authorization failed: ${error} \u2014 ${errorDescription}`);
4870
- this.error = error;
4871
- this.errorDescription = errorDescription;
4872
- this.name = "OAuthAuthorizationError";
4873
- Object.defineProperty(this, authorizationErrorBrand, { value: true });
4886
+ error;
4887
+ errorDescription;
4888
+ errorUri;
4889
+ error_description;
4890
+ error_uri;
4891
+ status;
4892
+ retryable;
4893
+ terminal;
4894
+ /** True only when a complete OAuth error response establishes rejection. */
4895
+ outcomeKnown;
4896
+ constructor(shape, status, outcomeKnown = true) {
4897
+ const description = Object.hasOwn(shape, "error_description") ? shape.error_description : void 0;
4898
+ const uri = Object.hasOwn(shape, "error_uri") ? shape.error_uri : void 0;
4899
+ super(description ?? (outcomeKnown ? shape.error : `OAuth HTTP response did not contain a valid error (HTTP ${status})`));
4900
+ this.name = "OAuthError";
4901
+ Object.defineProperty(this, oauthErrorBrand, { value: true });
4902
+ this.error = shape.error;
4903
+ this.errorDescription = description;
4904
+ this.errorUri = uri;
4905
+ this.error_description = description;
4906
+ this.error_uri = uri;
4907
+ this.status = status;
4908
+ this.retryable = isRetryableOAuthError(this);
4909
+ this.terminal = !this.retryable;
4910
+ this.outcomeKnown = outcomeKnown;
4874
4911
  }
4875
4912
  };
4876
-
4877
- // ../mcp-oauth/dist/client/loopback-authorization.js
4878
- function snapshotLoopbackAuthorizationOptions(options) {
4879
- return {
4880
- ...options,
4881
- openBrowser: options.openBrowser?.bind(options),
4882
- readLine: options.readLine?.bind(options),
4883
- waitForCallback: options.waitForCallback?.bind(options),
4884
- createServer: options.createServer?.bind(options),
4885
- callbackPath: options.callbackPath,
4886
- redirectUri: options.redirectUri,
4887
- signal: options.signal,
4888
- timeoutMs: options.timeoutMs,
4889
- landingPage: options.landingPage === void 0 ? void 0 : { ...options.landingPage, title: options.landingPage.title, body: options.landingPage.body }
4890
- };
4913
+ function isRetryableOAuthError(error) {
4914
+ return error instanceof OAuthError && (error.status >= 500 || error.error === "server_error" || error.error === "temporarily_unavailable");
4891
4915
  }
4892
- async function createLoopbackAuthorizationSession(options = {}) {
4893
- options = snapshotLoopbackAuthorizationOptions(options);
4894
- options.signal?.throwIfAborted();
4895
- const timeoutMs = options.timeoutMs ?? Infinity;
4896
- if (timeoutMs !== Infinity && (!Number.isSafeInteger(timeoutMs) || timeoutMs < 1 || timeoutMs > 2147483647))
4897
- throw new Error("OAuth authorization timeoutMs must be a positive supported timer interval");
4898
- if (options.waitForCallback !== void 0)
4899
- return createHostedAuthorizationSession(options, timeoutMs);
4900
- const target = loopbackTarget(options);
4901
- const server = options.createServer ? options.createServer() : http.createServer();
4902
- const controller = new AbortController();
4903
- let closed = false;
4904
- let used = false;
4905
- const callerAbort = () => controller.abort(options.signal?.reason);
4906
- const teardown = () => {
4907
- if (closed)
4908
- return;
4909
- closed = true;
4910
- clearTimeout(timer);
4911
- options.signal?.removeEventListener("abort", callerAbort);
4912
- server.closeAllConnections?.();
4913
- server.close();
4914
- };
4915
- const timer = timeoutMs === Infinity ? void 0 : setTimeout(() => controller.abort(new Error("OAuth authorization timed out")), timeoutMs);
4916
- timer?.unref?.();
4917
- controller.signal.addEventListener("abort", teardown, { once: true });
4918
- options.signal?.addEventListener("abort", callerAbort, { once: true });
4919
- if (options.signal?.aborted)
4920
- callerAbort();
4921
- let port;
4922
- try {
4923
- port = await startServer(server, target.port, target.host, controller.signal);
4924
- } catch (error) {
4925
- controller.abort(error);
4926
- throw error;
4927
- }
4928
- const redirectUri = options.redirectUri ?? `http://127.0.0.1:${port}${target.callbackPath}`;
4929
- return {
4930
- redirectUri,
4931
- async waitForCode(authorizationUrl) {
4932
- controller.signal.throwIfAborted();
4933
- if (used)
4934
- throw new Error("OAuth authorization session has already been used");
4935
- used = true;
4936
- try {
4937
- return await waitForAuthorizationCode(server, authorizationUrl, options, target.callbackPath, controller.signal);
4938
- } finally {
4939
- clearTimeout(timer);
4940
- }
4916
+ async function exchangeAuthorizationCode(input) {
4917
+ const resource = canonicalizeResourceIndicator(input.resource);
4918
+ return requestTokens({
4919
+ tokenEndpoint: input.tokenEndpoint,
4920
+ clientId: input.clientId,
4921
+ clientSecret: input.clientSecret,
4922
+ tokenEndpointAuthMethod: input.tokenEndpointAuthMethod,
4923
+ params: {
4924
+ grant_type: "authorization_code",
4925
+ code: input.code,
4926
+ code_verifier: input.codeVerifier,
4927
+ redirect_uri: input.redirectUri,
4928
+ resource
4941
4929
  },
4942
- close() {
4943
- controller.abort(new Error("OAuth authorization session closed"));
4944
- }
4945
- };
4930
+ fetch: input.fetch,
4931
+ signal: input.signal,
4932
+ now: input.now
4933
+ });
4946
4934
  }
4947
- function createHostedAuthorizationSession(options, timeoutMs) {
4948
- validateAuthorizationRedirect(options);
4949
- const redirectUri = options.redirectUri, controller = new AbortController();
4950
- let used = false;
4951
- const aborted = () => controller.abort(options.signal?.reason);
4952
- const timer = timeoutMs === Infinity ? void 0 : setTimeout(() => controller.abort(new Error("OAuth authorization timed out")), timeoutMs);
4953
- timer?.unref?.();
4954
- const cleanup = () => {
4955
- clearTimeout(timer);
4956
- options.signal?.removeEventListener("abort", aborted);
4957
- };
4958
- controller.signal.addEventListener("abort", cleanup, { once: true });
4959
- options.signal?.addEventListener("abort", aborted, { once: true });
4960
- if (options.signal?.aborted)
4961
- aborted();
4962
- return {
4963
- redirectUri,
4964
- async waitForCode(authorizationUrl) {
4965
- controller.signal.throwIfAborted();
4966
- if (used)
4967
- throw new Error("OAuth authorization session has already been used");
4968
- used = true;
4969
- try {
4970
- const authorization = new URL(authorizationUrl);
4971
- if (authorization.searchParams.getAll("redirect_uri").length !== 1 || authorization.searchParams.get("redirect_uri") !== redirectUri)
4972
- throw new Error("OAuth authorization redirect mismatch");
4973
- const callback = await new Promise((resolve, reject) => {
4974
- const onAbort = () => reject(controller.signal.reason);
4975
- controller.signal.addEventListener("abort", onAbort, { once: true });
4976
- void Promise.resolve().then(() => {
4977
- controller.signal.throwIfAborted();
4978
- return options.waitForCallback({ authorizationUrl, redirectUri, signal: controller.signal });
4979
- }).then(resolve, reject).finally(() => controller.signal.removeEventListener("abort", onAbort));
4980
- });
4981
- controller.signal.throwIfAborted();
4982
- const url = new URL(callback), base = new URL(redirectUri);
4983
- if (url.origin !== base.origin || url.pathname !== base.pathname || url.username || url.password || url.href.includes("#") || [...callback].some((char) => char.codePointAt(0) <= 32))
4935
+ async function refreshAccessToken(input) {
4936
+ const resource = canonicalizeResourceIndicator(input.resource);
4937
+ const refreshToken = input.refreshToken;
4938
+ const tokens = await requestTokens({
4939
+ tokenEndpoint: input.tokenEndpoint,
4940
+ clientId: input.clientId,
4941
+ clientSecret: input.clientSecret,
4942
+ tokenEndpointAuthMethod: input.tokenEndpointAuthMethod,
4943
+ params: {
4944
+ grant_type: "refresh_token",
4945
+ refresh_token: refreshToken,
4946
+ resource
4947
+ },
4948
+ fetch: input.fetch,
4949
+ signal: input.signal,
4950
+ now: input.now
4951
+ });
4952
+ return { ...tokens, refreshToken: tokens.refreshToken ?? refreshToken };
4953
+ }
4954
+ async function requestTokens(input) {
4955
+ const { body, headers } = createOAuthFormRequest(input);
4956
+ input.signal?.throwIfAborted();
4957
+ const deadline = AbortSignal.timeout(3e4);
4958
+ const signal = input.signal === void 0 ? deadline : AbortSignal.any([input.signal, deadline]);
4959
+ const response = await fetchMcpResponse(input.fetch, input.tokenEndpoint, {
4960
+ method: "POST",
4961
+ headers,
4962
+ body: body.toString(),
4963
+ signal
4964
+ });
4965
+ const payload = await readOAuthJsonObjectResponse(response, signal);
4966
+ const accessToken = getOwnEntry4(payload, "access_token");
4967
+ if (typeof accessToken !== "string" || accessToken.trim().length === 0) {
4968
+ throw new Error("OAuth token response missing access_token");
4969
+ }
4970
+ const normalizedAccessToken = accessToken.trim();
4971
+ try {
4972
+ new Headers({ Authorization: `Bearer ${normalizedAccessToken}` });
4973
+ } catch {
4974
+ throw new Error("OAuth token response access_token is not a valid HTTP header value");
4975
+ }
4976
+ const tokenType = normalizeBearerTokenType(getOwnEntry4(payload, "token_type"));
4977
+ if (tokenType === null) {
4978
+ throw new Error("OAuth token response missing token_type=Bearer");
4979
+ }
4980
+ const expiresIn = getOwnEntry4(payload, "expires_in");
4981
+ let expiresAt = null;
4982
+ if (expiresIn !== void 0) {
4983
+ if (typeof expiresIn !== "number" || !Number.isFinite(expiresIn) || !Number.isInteger(expiresIn) || expiresIn < 0) {
4984
+ throw new Error("OAuth token response has invalid expires_in");
4985
+ }
4986
+ const issuedAt = input.now();
4987
+ if (!Number.isSafeInteger(issuedAt) || Math.abs(issuedAt) > MAX_JS_DATE_MS2)
4988
+ throw new Error("OAuth token response has invalid expires_in");
4989
+ expiresAt = issuedAt + expiresIn * 1e3;
4990
+ if (!Number.isSafeInteger(expiresAt) || expiresAt > MAX_JS_DATE_MS2 || !Number.isFinite(new Date(expiresAt).getTime())) {
4991
+ throw new Error("OAuth token response has invalid expires_in");
4992
+ }
4993
+ }
4994
+ const refreshToken = getOwnEntry4(payload, "refresh_token");
4995
+ if (refreshToken !== void 0 && (typeof refreshToken !== "string" || refreshToken.trim().length === 0))
4996
+ throw new Error("OAuth token response has invalid refresh_token");
4997
+ const scope = getOwnEntry4(payload, "scope");
4998
+ const normalizedRefreshToken = typeof refreshToken === "string" && refreshToken.trim().length > 0 ? refreshToken.trim() : void 0;
4999
+ const normalizedScope = scope === "" ? "" : normalizeOAuthScope(scope);
5000
+ if (scope !== void 0 && normalizedScope === void 0)
5001
+ throw new Error("Invalid OAuth scope syntax in token response");
5002
+ return {
5003
+ accessToken: normalizedAccessToken,
5004
+ refreshToken: normalizedRefreshToken === void 0 ? void 0 : normalizedRefreshToken,
5005
+ tokenType,
5006
+ expiresAt,
5007
+ scope: normalizedScope === void 0 ? void 0 : normalizedScope
5008
+ };
5009
+ }
5010
+ async function readOAuthJsonObjectResponse(response, signal) {
5011
+ const fallbackError = createFallbackOAuthError(response.status);
5012
+ let payload;
5013
+ try {
5014
+ payload = JSON.parse(await readBoundedResponseText(response, 1024 * 1024, void 0, signal));
5015
+ } catch (error) {
5016
+ if (signal?.aborted)
5017
+ throw signal.reason;
5018
+ if (error instanceof Error && error.message.startsWith("HTTP response exceeds "))
5019
+ throw error;
5020
+ if (!response.ok) {
5021
+ throw fallbackError;
5022
+ }
5023
+ throw new Error("OAuth response must be a JSON object");
5024
+ }
5025
+ if (typeof payload !== "object" || payload === null || Array.isArray(payload)) {
5026
+ if (!response.ok) {
5027
+ throw fallbackError;
5028
+ }
5029
+ throw new Error("OAuth response must be a JSON object");
5030
+ }
5031
+ const record2 = payload;
5032
+ if (!response.ok) {
5033
+ const error = getOwnEntry4(record2, "error");
5034
+ if (typeof error !== "string" || error.trim() === "")
5035
+ throw fallbackError;
5036
+ throw new OAuthError(readOAuthError(record2), response.status);
5037
+ }
5038
+ return record2;
5039
+ }
5040
+ function readOAuthError(payload, fallbackError = "server_error") {
5041
+ const error = getOwnEntry4(payload, "error");
5042
+ const errorDescription = getOwnEntry4(payload, "error_description");
5043
+ const errorUri = getOwnEntry4(payload, "error_uri");
5044
+ return {
5045
+ error: typeof error === "string" ? error : fallbackError,
5046
+ error_description: typeof errorDescription === "string" ? errorDescription : void 0,
5047
+ error_uri: typeof errorUri === "string" ? errorUri : void 0
5048
+ };
5049
+ }
5050
+ function getOwnEntry4(record2, key2) {
5051
+ return Object.prototype.hasOwnProperty.call(record2, key2) ? record2[key2] : void 0;
5052
+ }
5053
+ function createFallbackOAuthError(status) {
5054
+ const error = status === 503 ? "temporarily_unavailable" : status >= 500 ? "server_error" : "invalid_response";
5055
+ return new OAuthError({ error }, status, false);
5056
+ }
5057
+ function normalizeBearerTokenType(value) {
5058
+ if (typeof value !== "string") {
5059
+ return null;
5060
+ }
5061
+ return value.toLowerCase() === "bearer" ? "Bearer" : null;
5062
+ }
5063
+
5064
+ // ../mcp-oauth/dist/client/register-client.js
5065
+ async function registerOAuthClient(input) {
5066
+ if (new URL(input.redirectUri).protocol === "https:")
5067
+ validateHostedOAuthRedirect(input.redirectUri);
5068
+ else
5069
+ loopbackTarget({ redirectUri: input.redirectUri });
5070
+ const body = JSON.stringify(buildClientRegistrationBody(input.metadata, input.redirectUri, normalizeOAuthTokenEndpointAuthMethod(input.tokenEndpointAuthMethod) ?? "none"));
5071
+ if (new TextEncoder().encode(body).byteLength > 65536)
5072
+ throw new Error("OAuth registration request is too large");
5073
+ input.signal?.throwIfAborted();
5074
+ const deadline = AbortSignal.timeout(3e4);
5075
+ const signal = input.signal === void 0 ? deadline : AbortSignal.any([input.signal, deadline]);
5076
+ const response = await fetchMcpResponse(input.fetch, input.registrationEndpoint, {
5077
+ method: "POST",
5078
+ headers: { Accept: "application/json", "Content-Type": "application/json" },
5079
+ body,
5080
+ signal
5081
+ });
5082
+ return parseOAuthClientRegistration(await readOAuthJsonObjectResponse(response, signal));
5083
+ }
5084
+ function getOwnString2(input, key2) {
5085
+ const descriptor = Object.getOwnPropertyDescriptor(input, key2);
5086
+ return descriptor !== void 0 && "value" in descriptor && typeof descriptor.value === "string" ? descriptor.value : void 0;
5087
+ }
5088
+ function buildClientRegistrationBody(metadata, redirectUri, tokenEndpointAuthMethod) {
5089
+ const body = {
5090
+ redirect_uris: [redirectUri],
5091
+ grant_types: ["authorization_code", "refresh_token"],
5092
+ response_types: ["code"],
5093
+ token_endpoint_auth_method: tokenEndpointAuthMethod
5094
+ };
5095
+ const clientName = metadata === void 0 ? void 0 : getOwnString2(metadata, "clientName");
5096
+ const scope = metadata === void 0 ? void 0 : getOwnString2(metadata, "scope");
5097
+ const softwareId = metadata === void 0 ? void 0 : getOwnString2(metadata, "softwareId");
5098
+ const softwareVersion = metadata === void 0 ? void 0 : getOwnString2(metadata, "softwareVersion");
5099
+ if (clientName !== void 0 && clientName.length > 0) {
5100
+ body.client_name = clientName;
5101
+ }
5102
+ if (scope !== void 0 && scope.length > 0) {
5103
+ body.scope = scope;
5104
+ }
5105
+ if (softwareId !== void 0 && softwareId.length > 0) {
5106
+ body.software_id = softwareId;
5107
+ }
5108
+ if (softwareVersion !== void 0 && softwareVersion.length > 0) {
5109
+ body.software_version = softwareVersion;
5110
+ }
5111
+ return body;
5112
+ }
5113
+
5114
+ // ../mcp-oauth/dist/client/default-oauth-client-provider.js
5115
+ import { URL as URL2 } from "node:url";
5116
+
5117
+ // ../mcp-oauth/dist/client/loopback-authorization.js
5118
+ import http from "node:http";
5119
+
5120
+ // ../../node_modules/jose/dist/webapi/util/base64url.js
5121
+ var base64url_exports = {};
5122
+ __export(base64url_exports, {
5123
+ decode: () => decode,
5124
+ encode: () => encode
5125
+ });
5126
+
5127
+ // ../../node_modules/jose/dist/webapi/lib/buffer_utils.js
5128
+ var encoder = new TextEncoder();
5129
+ var decoder = new TextDecoder();
5130
+ var MAX_INT32 = 2 ** 32;
5131
+
5132
+ // ../../node_modules/jose/dist/webapi/lib/base64.js
5133
+ function encodeBase64(input) {
5134
+ if (Uint8Array.prototype.toBase64) {
5135
+ return input.toBase64();
5136
+ }
5137
+ const CHUNK_SIZE = 32768;
5138
+ const arr = [];
5139
+ for (let i = 0; i < input.length; i += CHUNK_SIZE) {
5140
+ arr.push(String.fromCharCode.apply(null, input.subarray(i, i + CHUNK_SIZE)));
5141
+ }
5142
+ return btoa(arr.join(""));
5143
+ }
5144
+ function decodeBase64(encoded) {
5145
+ if (Uint8Array.fromBase64) {
5146
+ return Uint8Array.fromBase64(encoded);
5147
+ }
5148
+ const binary = atob(encoded);
5149
+ const bytes = new Uint8Array(binary.length);
5150
+ for (let i = 0; i < binary.length; i++) {
5151
+ bytes[i] = binary.charCodeAt(i);
5152
+ }
5153
+ return bytes;
5154
+ }
5155
+
5156
+ // ../../node_modules/jose/dist/webapi/util/base64url.js
5157
+ function decode(input) {
5158
+ if (Uint8Array.fromBase64) {
5159
+ return Uint8Array.fromBase64(typeof input === "string" ? input : decoder.decode(input), {
5160
+ alphabet: "base64url"
5161
+ });
5162
+ }
5163
+ let encoded = input;
5164
+ if (encoded instanceof Uint8Array) {
5165
+ encoded = decoder.decode(encoded);
5166
+ }
5167
+ encoded = encoded.replace(/-/g, "+").replace(/_/g, "/");
5168
+ try {
5169
+ return decodeBase64(encoded);
5170
+ } catch {
5171
+ throw new TypeError("The input to be decoded is not correctly encoded.");
5172
+ }
5173
+ }
5174
+ function encode(input) {
5175
+ let unencoded = input;
5176
+ if (typeof unencoded === "string") {
5177
+ unencoded = encoder.encode(unencoded);
5178
+ }
5179
+ if (Uint8Array.prototype.toBase64) {
5180
+ return unencoded.toBase64({ alphabet: "base64url", omitPadding: true });
5181
+ }
5182
+ return encodeBase64(unencoded).replace(/=/g, "").replace(/\+/g, "-").replace(/\//g, "_");
5183
+ }
5184
+
5185
+ // ../mcp-oauth/dist/client/authorization-state.js
5186
+ function createAuthorizationState(input) {
5187
+ const payload = {
5188
+ v: 1,
5189
+ n: base64url_exports.encode(crypto.getRandomValues(new Uint8Array(16))),
5190
+ i: input.issuer,
5191
+ r: input.requireIssuer
5192
+ };
5193
+ return base64url_exports.encode(JSON.stringify(payload));
5194
+ }
5195
+ function parseAuthorizationState(value) {
5196
+ if (value === null || value.length === 0) {
5197
+ return null;
5198
+ }
5199
+ try {
5200
+ const decoded = new TextDecoder().decode(base64url_exports.decode(value));
5201
+ const parsed = JSON.parse(decoded);
5202
+ if (!isObjectRecord2(parsed)) {
5203
+ return null;
5204
+ }
5205
+ const version = getOwnEntry5(parsed, "v");
5206
+ const nonce = getOwnEntry5(parsed, "n");
5207
+ const issuer = getOwnEntry5(parsed, "i");
5208
+ const requireIssuer = getOwnEntry5(parsed, "r");
5209
+ if (version !== 1 || typeof nonce !== "string" || nonce.length === 0 || typeof issuer !== "string" || issuer.length === 0 || typeof requireIssuer !== "boolean") {
5210
+ return null;
5211
+ }
5212
+ return {
5213
+ issuer,
5214
+ requireIssuer
5215
+ };
5216
+ } catch {
5217
+ return null;
5218
+ }
5219
+ }
5220
+ function isObjectRecord2(value) {
5221
+ return typeof value === "object" && value !== null && !Array.isArray(value);
5222
+ }
5223
+ function getOwnEntry5(record2, key2) {
5224
+ return Object.prototype.hasOwnProperty.call(record2, key2) ? record2[key2] : void 0;
5225
+ }
5226
+
5227
+ // ../mcp-oauth/dist/client/authorization-error.js
5228
+ var authorizationErrorBrand = /* @__PURE__ */ Symbol.for("poe-platform.mcp-oauth.OAuthAuthorizationError");
5229
+ var OAuthAuthorizationError = class extends Error {
5230
+ error;
5231
+ errorDescription;
5232
+ /** Recognize errors from separately bundled copies of this package. */
5233
+ static is(value) {
5234
+ return value instanceof Error && Object.getOwnPropertyDescriptor(value, authorizationErrorBrand)?.value === true;
5235
+ }
5236
+ constructor(error, errorDescription) {
5237
+ super(`OAuth authorization failed: ${error} \u2014 ${errorDescription}`);
5238
+ this.error = error;
5239
+ this.errorDescription = errorDescription;
5240
+ this.name = "OAuthAuthorizationError";
5241
+ Object.defineProperty(this, authorizationErrorBrand, { value: true });
5242
+ }
5243
+ };
5244
+
5245
+ // ../mcp-oauth/dist/client/loopback-authorization.js
5246
+ function snapshotLoopbackAuthorizationOptions(options) {
5247
+ return {
5248
+ ...options,
5249
+ openBrowser: options.openBrowser?.bind(options),
5250
+ readLine: options.readLine?.bind(options),
5251
+ waitForCallback: options.waitForCallback?.bind(options),
5252
+ createServer: options.createServer?.bind(options),
5253
+ callbackPath: options.callbackPath,
5254
+ redirectUri: options.redirectUri,
5255
+ signal: options.signal,
5256
+ timeoutMs: options.timeoutMs,
5257
+ landingPage: options.landingPage === void 0 ? void 0 : { ...options.landingPage, title: options.landingPage.title, body: options.landingPage.body }
5258
+ };
5259
+ }
5260
+ async function createLoopbackAuthorizationSession(options = {}) {
5261
+ options = snapshotLoopbackAuthorizationOptions(options);
5262
+ options.signal?.throwIfAborted();
5263
+ const timeoutMs = options.timeoutMs ?? Infinity;
5264
+ if (timeoutMs !== Infinity && (!Number.isSafeInteger(timeoutMs) || timeoutMs < 1 || timeoutMs > 2147483647))
5265
+ throw new Error("OAuth authorization timeoutMs must be a positive supported timer interval");
5266
+ if (options.waitForCallback !== void 0)
5267
+ return createHostedAuthorizationSession(options, timeoutMs);
5268
+ const target = loopbackTarget(options);
5269
+ const server = options.createServer ? options.createServer() : http.createServer();
5270
+ const controller = new AbortController();
5271
+ let closed = false;
5272
+ let used = false;
5273
+ const callerAbort = () => controller.abort(options.signal?.reason);
5274
+ const teardown = () => {
5275
+ if (closed)
5276
+ return;
5277
+ closed = true;
5278
+ clearTimeout(timer);
5279
+ options.signal?.removeEventListener("abort", callerAbort);
5280
+ server.closeAllConnections?.();
5281
+ server.close();
5282
+ };
5283
+ const timer = timeoutMs === Infinity ? void 0 : setTimeout(() => controller.abort(new Error("OAuth authorization timed out")), timeoutMs);
5284
+ timer?.unref?.();
5285
+ controller.signal.addEventListener("abort", teardown, { once: true });
5286
+ options.signal?.addEventListener("abort", callerAbort, { once: true });
5287
+ if (options.signal?.aborted)
5288
+ callerAbort();
5289
+ let port;
5290
+ try {
5291
+ port = await startServer(server, target.port, target.host, controller.signal);
5292
+ } catch (error) {
5293
+ controller.abort(error);
5294
+ throw error;
5295
+ }
5296
+ const redirectUri = options.redirectUri ?? `http://127.0.0.1:${port}${target.callbackPath}`;
5297
+ return {
5298
+ redirectUri,
5299
+ async waitForCode(authorizationUrl) {
5300
+ controller.signal.throwIfAborted();
5301
+ if (used)
5302
+ throw new Error("OAuth authorization session has already been used");
5303
+ used = true;
5304
+ try {
5305
+ return await waitForAuthorizationCode(server, authorizationUrl, options, target.callbackPath, controller.signal);
5306
+ } finally {
5307
+ clearTimeout(timer);
5308
+ }
5309
+ },
5310
+ close() {
5311
+ controller.abort(new Error("OAuth authorization session closed"));
5312
+ }
5313
+ };
5314
+ }
5315
+ function createHostedAuthorizationSession(options, timeoutMs) {
5316
+ validateAuthorizationRedirect(options);
5317
+ const redirectUri = options.redirectUri, controller = new AbortController();
5318
+ let used = false;
5319
+ const aborted = () => controller.abort(options.signal?.reason);
5320
+ const timer = timeoutMs === Infinity ? void 0 : setTimeout(() => controller.abort(new Error("OAuth authorization timed out")), timeoutMs);
5321
+ timer?.unref?.();
5322
+ const cleanup = () => {
5323
+ clearTimeout(timer);
5324
+ options.signal?.removeEventListener("abort", aborted);
5325
+ };
5326
+ controller.signal.addEventListener("abort", cleanup, { once: true });
5327
+ options.signal?.addEventListener("abort", aborted, { once: true });
5328
+ if (options.signal?.aborted)
5329
+ aborted();
5330
+ return {
5331
+ redirectUri,
5332
+ async waitForCode(authorizationUrl) {
5333
+ controller.signal.throwIfAborted();
5334
+ if (used)
5335
+ throw new Error("OAuth authorization session has already been used");
5336
+ used = true;
5337
+ try {
5338
+ const authorization = new URL(authorizationUrl);
5339
+ if (authorization.searchParams.getAll("redirect_uri").length !== 1 || authorization.searchParams.get("redirect_uri") !== redirectUri)
5340
+ throw new Error("OAuth authorization redirect mismatch");
5341
+ const callback = await new Promise((resolve, reject) => {
5342
+ const onAbort = () => reject(controller.signal.reason);
5343
+ controller.signal.addEventListener("abort", onAbort, { once: true });
5344
+ void Promise.resolve().then(() => {
5345
+ controller.signal.throwIfAborted();
5346
+ return options.waitForCallback({ authorizationUrl, redirectUri, signal: controller.signal });
5347
+ }).then(resolve, reject).finally(() => controller.signal.removeEventListener("abort", onAbort));
5348
+ });
5349
+ controller.signal.throwIfAborted();
5350
+ const url = new URL(callback), base = new URL(redirectUri);
5351
+ if (url.origin !== base.origin || url.pathname !== base.pathname || url.username || url.password || url.href.includes("#") || [...callback].some((char) => char.codePointAt(0) <= 32))
4984
5352
  throw new Error("OAuth callback redirect mismatch");
4985
5353
  const params = readAuthorizationCallbackParameters(url);
4986
5354
  for (const name of oauthCallbackParameters)
@@ -5189,257 +5557,387 @@ function buildSuccessPage(landingPage) {
5189
5557
  ].join("");
5190
5558
  }
5191
5559
 
5192
- // ../mcp-oauth/dist/client/pkce.js
5193
- import crypto4 from "node:crypto";
5194
- function generateCodeVerifier() {
5195
- return crypto4.randomBytes(32).toString("base64url");
5196
- }
5197
- function generateCodeChallenge(verifier) {
5198
- return crypto4.createHash("sha256").update(verifier).digest("base64url");
5199
- }
5200
-
5201
- // ../mcp-oauth/dist/http-response.js
5202
- async function readBoundedResponseText(response, maxBytes, readers, signal) {
5203
- if (maxBytes !== Infinity && (!Number.isSafeInteger(maxBytes) || maxBytes < 1))
5204
- throw new Error("HTTP response byte limit must be a positive safe integer");
5205
- if (signal?.aborted) {
5206
- void response.body?.cancel().catch(() => void 0);
5207
- throw signal.reason;
5208
- }
5209
- const length = response.headers.get("Content-Length");
5210
- if (length !== null && length.length > 0 && [...length].every((character) => character >= "0" && character <= "9") && Number(length) > maxBytes) {
5211
- void response.body?.cancel().catch(() => void 0);
5212
- throw new Error(`HTTP response exceeds ${maxBytes} bytes`);
5213
- }
5214
- if (response.body === null)
5215
- return "";
5216
- const reader = response.body.getReader();
5217
- readers?.add(reader);
5218
- const abort = () => {
5219
- void reader.cancel().catch(() => void 0);
5220
- };
5221
- signal?.addEventListener("abort", abort, { once: true });
5222
- if (signal?.aborted)
5223
- abort();
5224
- const decoder = new TextDecoder("utf-8", { fatal: true });
5225
- let bytes = 0;
5226
- let text = "";
5227
- try {
5228
- while (true) {
5229
- const chunk = await reader.read();
5230
- signal?.throwIfAborted();
5231
- if (chunk.done)
5232
- return text + decoder.decode();
5233
- bytes += chunk.value.byteLength;
5234
- if (bytes > maxBytes)
5235
- throw new Error(`HTTP response exceeds ${maxBytes} bytes`);
5236
- text += decoder.decode(chunk.value, { stream: true });
5237
- }
5238
- } catch (error) {
5239
- void reader.cancel().catch(() => void 0);
5240
- throw error;
5241
- } finally {
5242
- signal?.removeEventListener("abort", abort);
5243
- readers?.delete(reader);
5244
- reader.releaseLock();
5245
- }
5560
+ // ../../node_modules/@noble/hashes/_u64.js
5561
+ var fromNumH = (n) => n / 2 ** 32 | 0;
5562
+ var fromNumL = (n) => n >>> 0;
5563
+ function setU64FromNum(view, byteOffset, n, isLE) {
5564
+ const h = fromNumH(n);
5565
+ const l = fromNumL(n);
5566
+ view.setUint32(byteOffset, isLE ? l : h, isLE);
5567
+ view.setUint32(byteOffset + 4, isLE ? h : l, isLE);
5246
5568
  }
5247
5569
 
5248
- // ../mcp-oauth/dist/client/token-endpoint.js
5249
- var MAX_JS_DATE_MS2 = 864e13;
5250
- var oauthErrorBrand = /* @__PURE__ */ Symbol.for("poe-platform.mcp-oauth.OAuthError");
5251
- var OAuthError = class extends Error {
5252
- /** Recognize errors from separately bundled copies of this package. */
5253
- static is(value) {
5254
- return value instanceof Error && Object.getOwnPropertyDescriptor(value, oauthErrorBrand)?.value === true;
5255
- }
5256
- error;
5257
- errorDescription;
5258
- errorUri;
5259
- error_description;
5260
- error_uri;
5261
- status;
5262
- retryable;
5263
- terminal;
5264
- /** True only when a complete OAuth error response establishes rejection. */
5265
- outcomeKnown;
5266
- constructor(shape, status, outcomeKnown = true) {
5267
- const description = Object.hasOwn(shape, "error_description") ? shape.error_description : void 0;
5268
- const uri = Object.hasOwn(shape, "error_uri") ? shape.error_uri : void 0;
5269
- super(description ?? (outcomeKnown ? shape.error : `OAuth HTTP response did not contain a valid error (HTTP ${status})`));
5270
- this.name = "OAuthError";
5271
- Object.defineProperty(this, oauthErrorBrand, { value: true });
5272
- this.error = shape.error;
5273
- this.errorDescription = description;
5274
- this.errorUri = uri;
5275
- this.error_description = description;
5276
- this.error_uri = uri;
5277
- this.status = status;
5278
- this.retryable = isRetryableOAuthError(this);
5279
- this.terminal = !this.retryable;
5280
- this.outcomeKnown = outcomeKnown;
5281
- }
5570
+ // ../../node_modules/@noble/hashes/utils.js
5571
+ function isBytes(a) {
5572
+ return a instanceof Uint8Array || ArrayBuffer.isView(a) && a.constructor.name === "Uint8Array" && "BYTES_PER_ELEMENT" in a && a.BYTES_PER_ELEMENT === 1;
5573
+ }
5574
+ var atitle = (title) => title ? `"${title}" ` : "";
5575
+ function anumber(n, title = "") {
5576
+ if (typeof n !== "number")
5577
+ throw new TypeError(atitle(title) + "expected number, got " + typeof n);
5578
+ if (!Number.isSafeInteger(n) || n < 0)
5579
+ throw new RangeError(atitle(title) + "expected integer >= 0, got " + n);
5580
+ return n;
5581
+ }
5582
+ function abytes(value, length, title = "") {
5583
+ if (isBytes(value) && (length === void 0 || value.length === length))
5584
+ return value;
5585
+ if (length !== void 0)
5586
+ anumber(length, "length");
5587
+ const bytes = isBytes(value);
5588
+ const ofLen = length !== void 0 ? ` of length ${length}` : "";
5589
+ const got = bytes ? `length=${value.length}` : `type=${typeof value}`;
5590
+ const message = atitle(title) + "expected Uint8Array" + ofLen + ", got " + got;
5591
+ if (!bytes)
5592
+ throw new TypeError(message);
5593
+ throw new RangeError(message);
5594
+ }
5595
+ var aobject = (value, label) => {
5596
+ if (value === null || typeof value !== "object" || Array.isArray(value))
5597
+ throw new TypeError((label === "object" ? "" : `"${label}" `) + "expected object, got type=" + typeof value);
5282
5598
  };
5283
- function isRetryableOAuthError(error) {
5284
- return error instanceof OAuthError && (error.status >= 500 || error.error === "server_error" || error.error === "temporarily_unavailable");
5285
- }
5286
- async function exchangeAuthorizationCode(input) {
5287
- const resource = canonicalizeResourceIndicator(input.resource);
5288
- return requestTokens({
5289
- tokenEndpoint: input.tokenEndpoint,
5290
- clientId: input.clientId,
5291
- clientSecret: input.clientSecret,
5292
- tokenEndpointAuthMethod: input.tokenEndpointAuthMethod,
5293
- params: {
5294
- grant_type: "authorization_code",
5295
- code: input.code,
5296
- code_verifier: input.codeVerifier,
5297
- redirect_uri: input.redirectUri,
5298
- resource
5299
- },
5300
- fetch: input.fetch,
5301
- signal: input.signal,
5302
- now: input.now
5303
- });
5304
- }
5305
- async function refreshAccessToken(input) {
5306
- const resource = canonicalizeResourceIndicator(input.resource);
5307
- return requestTokens({
5308
- tokenEndpoint: input.tokenEndpoint,
5309
- clientId: input.clientId,
5310
- clientSecret: input.clientSecret,
5311
- tokenEndpointAuthMethod: input.tokenEndpointAuthMethod,
5312
- params: {
5313
- grant_type: "refresh_token",
5314
- refresh_token: input.refreshToken,
5315
- resource
5316
- },
5317
- fetch: input.fetch,
5318
- signal: input.signal,
5319
- now: input.now
5320
- });
5599
+ var aopts = (value, label) => {
5600
+ aobject(value, label);
5601
+ const proto = Object.getPrototypeOf(value);
5602
+ if (proto !== Object.prototype && proto !== null)
5603
+ throw new TypeError(`"${label}" expected plain object`);
5604
+ if (Object.hasOwn(value, "__proto__"))
5605
+ throw new TypeError(`"${label}.__proto__" is not allowed`);
5606
+ };
5607
+ function aexists(instance, checkFinished = true) {
5608
+ if (instance.destroyed)
5609
+ throw new Error("hash was destroyed");
5610
+ if (checkFinished && instance.finished)
5611
+ throw new Error("digest() was already called");
5321
5612
  }
5322
- async function requestTokens(input) {
5323
- const method = normalizeOAuthTokenEndpointAuthMethod(input.tokenEndpointAuthMethod) ?? (input.clientSecret === void 0 ? "none" : "client_secret_post");
5324
- if (method !== "none" && (input.clientSecret === void 0 || input.clientSecret.trim() === ""))
5325
- throw new Error("OAuth token endpoint authentication requires a client secret");
5326
- const body = new URLSearchParams(input.params);
5327
- const headers = new Headers({ Accept: "application/json", "Content-Type": "application/x-www-form-urlencoded" });
5328
- if (method === "client_secret_basic") {
5329
- const encoded = new URLSearchParams({ credential: input.clientId }).toString().slice("credential=".length);
5330
- const encodedSecret = new URLSearchParams({ credential: input.clientSecret }).toString().slice("credential=".length);
5331
- headers.set("Authorization", `Basic ${btoa(`${encoded}:${encodedSecret}`)}`);
5332
- } else {
5333
- body.set("client_id", input.clientId);
5334
- if (method === "client_secret_post")
5335
- body.set("client_secret", input.clientSecret);
5336
- }
5337
- input.signal?.throwIfAborted();
5338
- const deadline = AbortSignal.timeout(3e4);
5339
- const signal = input.signal === void 0 ? deadline : AbortSignal.any([input.signal, deadline]);
5340
- const response = await fetchMcpResponse(input.fetch, input.tokenEndpoint, {
5341
- method: "POST",
5342
- headers,
5343
- body: body.toString(),
5344
- signal
5345
- });
5346
- const payload = await readOAuthJsonObjectResponse(response, signal);
5347
- const accessToken = getOwnEntry5(payload, "access_token");
5348
- if (typeof accessToken !== "string" || accessToken.trim().length === 0) {
5349
- throw new Error("OAuth token response missing access_token");
5350
- }
5351
- const normalizedAccessToken = accessToken.trim();
5352
- try {
5353
- new Headers({ Authorization: `Bearer ${normalizedAccessToken}` });
5354
- } catch {
5355
- throw new Error("OAuth token response access_token is not a valid HTTP header value");
5356
- }
5357
- const tokenType = normalizeBearerTokenType(getOwnEntry5(payload, "token_type"));
5358
- if (tokenType === null) {
5359
- throw new Error("OAuth token response missing token_type=Bearer");
5360
- }
5361
- const expiresIn = getOwnEntry5(payload, "expires_in");
5362
- let expiresAt = null;
5363
- if (expiresIn !== void 0) {
5364
- if (typeof expiresIn !== "number" || !Number.isFinite(expiresIn) || !Number.isInteger(expiresIn) || expiresIn < 0) {
5365
- throw new Error("OAuth token response has invalid expires_in");
5366
- }
5367
- const issuedAt = input.now();
5368
- if (!Number.isSafeInteger(issuedAt) || Math.abs(issuedAt) > MAX_JS_DATE_MS2)
5369
- throw new Error("OAuth token response has invalid expires_in");
5370
- expiresAt = issuedAt + expiresIn * 1e3;
5371
- if (!Number.isSafeInteger(expiresAt) || expiresAt > MAX_JS_DATE_MS2 || !Number.isFinite(new Date(expiresAt).getTime())) {
5372
- throw new Error("OAuth token response has invalid expires_in");
5373
- }
5613
+ function aoutput(out, instance) {
5614
+ abytes(out, void 0, "output");
5615
+ const min = instance.outputLen;
5616
+ if (!(out.length >= min)) {
5617
+ throw new RangeError('"output" expected length >= ' + min);
5374
5618
  }
5375
- const refreshToken = getOwnEntry5(payload, "refresh_token");
5376
- if (refreshToken !== void 0 && (typeof refreshToken !== "string" || refreshToken.trim().length === 0))
5377
- throw new Error("OAuth token response has invalid refresh_token");
5378
- const scope = getOwnEntry5(payload, "scope");
5379
- const normalizedRefreshToken = typeof refreshToken === "string" && refreshToken.trim().length > 0 ? refreshToken.trim() : void 0;
5380
- const normalizedScope = scope === "" ? "" : normalizeOAuthScope(scope);
5381
- if (scope !== void 0 && normalizedScope === void 0)
5382
- throw new Error("Invalid OAuth scope syntax in token response");
5383
- return {
5384
- accessToken: normalizedAccessToken,
5385
- refreshToken: normalizedRefreshToken === void 0 ? void 0 : normalizedRefreshToken,
5386
- tokenType,
5387
- expiresAt,
5388
- scope: normalizedScope === void 0 ? void 0 : normalizedScope
5389
- };
5390
5619
  }
5391
- async function readOAuthJsonObjectResponse(response, signal) {
5392
- const fallbackError = createFallbackOAuthError(response.status);
5393
- let payload;
5394
- try {
5395
- payload = JSON.parse(await readBoundedResponseText(response, 1024 * 1024, void 0, signal));
5396
- } catch (error) {
5397
- if (signal?.aborted)
5398
- throw signal.reason;
5399
- if (error instanceof Error && error.message.startsWith("HTTP response exceeds "))
5400
- throw error;
5401
- if (!response.ok) {
5402
- throw fallbackError;
5403
- }
5404
- throw new Error("OAuth response must be a JSON object");
5405
- }
5406
- if (typeof payload !== "object" || payload === null || Array.isArray(payload)) {
5407
- if (!response.ok) {
5408
- throw fallbackError;
5409
- }
5410
- throw new Error("OAuth response must be a JSON object");
5411
- }
5412
- const record2 = payload;
5413
- if (!response.ok) {
5414
- const error = getOwnEntry5(record2, "error");
5415
- if (typeof error !== "string" || error.trim() === "")
5416
- throw fallbackError;
5417
- throw new OAuthError(readOAuthError(record2), response.status);
5620
+ function clean(...arrays) {
5621
+ for (let i = 0; i < arrays.length; i++) {
5622
+ arrays[i].fill(0);
5418
5623
  }
5419
- return record2;
5420
5624
  }
5421
- function readOAuthError(payload, fallbackError = "server_error") {
5422
- const error = getOwnEntry5(payload, "error");
5423
- const errorDescription = getOwnEntry5(payload, "error_description");
5424
- const errorUri = getOwnEntry5(payload, "error_uri");
5425
- return {
5426
- error: typeof error === "string" ? error : fallbackError,
5427
- error_description: typeof errorDescription === "string" ? errorDescription : void 0,
5428
- error_uri: typeof errorUri === "string" ? errorUri : void 0
5429
- };
5625
+ function createView(arr) {
5626
+ return new DataView(arr.buffer, arr.byteOffset, arr.byteLength);
5430
5627
  }
5431
- function getOwnEntry5(record2, key2) {
5432
- return Object.prototype.hasOwnProperty.call(record2, key2) ? record2[key2] : void 0;
5628
+ function rotr(word, shift) {
5629
+ return word << 32 - shift | word >>> shift;
5433
5630
  }
5434
- function createFallbackOAuthError(status) {
5435
- const error = status === 503 ? "temporarily_unavailable" : status >= 500 ? "server_error" : "invalid_response";
5436
- return new OAuthError({ error }, status, false);
5631
+ function checkOpts(defaults, opts, title = "opts") {
5632
+ aopts(defaults, "defaults");
5633
+ if (opts !== void 0)
5634
+ aopts(opts, title);
5635
+ const merged = Object.assign(/* @__PURE__ */ Object.create(null), defaults, opts);
5636
+ return merged;
5437
5637
  }
5438
- function normalizeBearerTokenType(value) {
5439
- if (typeof value !== "string") {
5440
- return null;
5638
+ function createHasher(hashCons, info = {}) {
5639
+ if (typeof hashCons !== "function")
5640
+ throw new TypeError('"hashCons" expected function, got type=' + typeof hashCons);
5641
+ info = checkOpts({}, info, "info");
5642
+ const hashC = (msg, opts) => hashCons(opts).update(msg).digest();
5643
+ const tmp = hashCons(void 0);
5644
+ hashC.outputLen = tmp.outputLen;
5645
+ hashC.blockLen = tmp.blockLen;
5646
+ hashC.canXOF = tmp.canXOF;
5647
+ hashC.create = (opts) => hashCons(opts);
5648
+ Object.assign(hashC, info);
5649
+ return Object.freeze(hashC);
5650
+ }
5651
+ var oidNist = (suffix) => ({
5652
+ // Current NIST hashAlgs suffixes used here fit in one DER subidentifier octet.
5653
+ // Larger suffix values would need base-128 OID encoding and a different length byte.
5654
+ oid: Uint8Array.from([6, 9, 96, 134, 72, 1, 101, 3, 4, 2, suffix])
5655
+ });
5656
+
5657
+ // ../../node_modules/@noble/hashes/_md.js
5658
+ function Chi(a, b, c) {
5659
+ return a & b ^ ~a & c;
5660
+ }
5661
+ function Maj(a, b, c) {
5662
+ return a & b ^ a & c ^ b & c;
5663
+ }
5664
+ var HashMD = class {
5665
+ blockLen;
5666
+ outputLen;
5667
+ canXOF = false;
5668
+ padOffset;
5669
+ isLE;
5670
+ // For partial updates less than block size
5671
+ buffer;
5672
+ view;
5673
+ finished = false;
5674
+ length = 0;
5675
+ pos = 0;
5676
+ destroyed = false;
5677
+ constructor(blockLen, outputLen, padOffset, isLE) {
5678
+ this.blockLen = blockLen;
5679
+ this.outputLen = outputLen;
5680
+ this.padOffset = padOffset;
5681
+ this.isLE = isLE;
5682
+ this.buffer = new Uint8Array(blockLen);
5683
+ this.view = createView(this.buffer);
5684
+ }
5685
+ update(data) {
5686
+ aexists(this);
5687
+ abytes(data);
5688
+ const { view, buffer, blockLen } = this;
5689
+ const len = data.length;
5690
+ let processed = false;
5691
+ for (let pos = 0; pos < len; ) {
5692
+ const take = Math.min(blockLen - this.pos, len - pos);
5693
+ if (take === blockLen) {
5694
+ const dataView = createView(data);
5695
+ for (; blockLen <= len - pos; pos += blockLen)
5696
+ this.process(dataView, pos);
5697
+ processed = true;
5698
+ continue;
5699
+ }
5700
+ buffer.set(pos === 0 && take === len ? data : data.subarray(pos, pos + take), this.pos);
5701
+ this.pos += take;
5702
+ pos += take;
5703
+ if (this.pos === blockLen) {
5704
+ this.process(view, 0);
5705
+ this.pos = 0;
5706
+ processed = true;
5707
+ }
5708
+ }
5709
+ this.length += data.length;
5710
+ if (processed)
5711
+ this.roundClean();
5712
+ return this;
5713
+ }
5714
+ digestInto(out) {
5715
+ aexists(this);
5716
+ aoutput(out, this);
5717
+ this.finished = true;
5718
+ const { buffer, view, blockLen, isLE } = this;
5719
+ let { pos } = this;
5720
+ buffer[pos++] = 128;
5721
+ buffer.fill(0, pos);
5722
+ if (this.padOffset > blockLen - pos) {
5723
+ this.process(view, 0);
5724
+ buffer.fill(0);
5725
+ }
5726
+ setU64FromNum(view, blockLen - 8, this.length * 8, isLE);
5727
+ this.process(view, 0);
5728
+ this.roundClean();
5729
+ const oview = out === buffer ? view : createView(out);
5730
+ const len = this.outputLen;
5731
+ const outLen = len / 4;
5732
+ const state = this.get();
5733
+ if (len % 4 || outLen > state.length)
5734
+ throw new Error("invalid outputLen");
5735
+ for (let i = 0; i < outLen; i++)
5736
+ oview.setUint32(4 * i, state[i], isLE);
5737
+ }
5738
+ digest() {
5739
+ const { buffer, outputLen } = this;
5740
+ this.digestInto(buffer);
5741
+ const res = buffer.slice(0, outputLen);
5742
+ this.destroy();
5743
+ return res;
5744
+ }
5745
+ _cloneIntoMeta(to) {
5746
+ const { buffer, length, finished, destroyed, pos } = this;
5747
+ to.destroyed = destroyed;
5748
+ to.finished = finished;
5749
+ to.length = length;
5750
+ to.pos = pos;
5751
+ if (pos)
5752
+ to.buffer.set(buffer);
5753
+ return to;
5754
+ }
5755
+ clone() {
5756
+ return this._cloneInto();
5441
5757
  }
5442
- return value.toLowerCase() === "bearer" ? "Bearer" : null;
5758
+ };
5759
+ var SHA256_IV = /* @__PURE__ */ Uint32Array.from([
5760
+ 1779033703,
5761
+ 3144134277,
5762
+ 1013904242,
5763
+ 2773480762,
5764
+ 1359893119,
5765
+ 2600822924,
5766
+ 528734635,
5767
+ 1541459225
5768
+ ]);
5769
+
5770
+ // ../../node_modules/@noble/hashes/sha2.js
5771
+ var SHA256_K = /* @__PURE__ */ Uint32Array.from([
5772
+ 1116352408,
5773
+ 1899447441,
5774
+ 3049323471,
5775
+ 3921009573,
5776
+ 961987163,
5777
+ 1508970993,
5778
+ 2453635748,
5779
+ 2870763221,
5780
+ 3624381080,
5781
+ 310598401,
5782
+ 607225278,
5783
+ 1426881987,
5784
+ 1925078388,
5785
+ 2162078206,
5786
+ 2614888103,
5787
+ 3248222580,
5788
+ 3835390401,
5789
+ 4022224774,
5790
+ 264347078,
5791
+ 604807628,
5792
+ 770255983,
5793
+ 1249150122,
5794
+ 1555081692,
5795
+ 1996064986,
5796
+ 2554220882,
5797
+ 2821834349,
5798
+ 2952996808,
5799
+ 3210313671,
5800
+ 3336571891,
5801
+ 3584528711,
5802
+ 113926993,
5803
+ 338241895,
5804
+ 666307205,
5805
+ 773529912,
5806
+ 1294757372,
5807
+ 1396182291,
5808
+ 1695183700,
5809
+ 1986661051,
5810
+ 2177026350,
5811
+ 2456956037,
5812
+ 2730485921,
5813
+ 2820302411,
5814
+ 3259730800,
5815
+ 3345764771,
5816
+ 3516065817,
5817
+ 3600352804,
5818
+ 4094571909,
5819
+ 275423344,
5820
+ 430227734,
5821
+ 506948616,
5822
+ 659060556,
5823
+ 883997877,
5824
+ 958139571,
5825
+ 1322822218,
5826
+ 1537002063,
5827
+ 1747873779,
5828
+ 1955562222,
5829
+ 2024104815,
5830
+ 2227730452,
5831
+ 2361852424,
5832
+ 2428436474,
5833
+ 2756734187,
5834
+ 3204031479,
5835
+ 3329325298
5836
+ ]);
5837
+ var SHA256_W = /* @__PURE__ */ new Uint32Array(64);
5838
+ var SHA2_32B = class extends HashMD {
5839
+ // We cannot use array here since array allows indexing by variable
5840
+ // which means optimizer/compiler cannot use registers.
5841
+ // Numeric initializers matter: starting the fields as `undefined` changes
5842
+ // V8's field representation and makes sha256 3x slower (measured).
5843
+ A = 0;
5844
+ B = 0;
5845
+ C = 0;
5846
+ D = 0;
5847
+ E = 0;
5848
+ F = 0;
5849
+ G = 0;
5850
+ H = 0;
5851
+ constructor(outputLen, IV) {
5852
+ super(64, outputLen, 8, false);
5853
+ this.A = IV[0] | 0;
5854
+ this.B = IV[1] | 0;
5855
+ this.C = IV[2] | 0;
5856
+ this.D = IV[3] | 0;
5857
+ this.E = IV[4] | 0;
5858
+ this.F = IV[5] | 0;
5859
+ this.G = IV[6] | 0;
5860
+ this.H = IV[7] | 0;
5861
+ }
5862
+ get() {
5863
+ const { A, B, C, D, E, F, G, H } = this;
5864
+ return [A, B, C, D, E, F, G, H];
5865
+ }
5866
+ // prettier-ignore
5867
+ set(A, B, C, D, E, F, G, H) {
5868
+ this.A = A | 0;
5869
+ this.B = B | 0;
5870
+ this.C = C | 0;
5871
+ this.D = D | 0;
5872
+ this.E = E | 0;
5873
+ this.F = F | 0;
5874
+ this.G = G | 0;
5875
+ this.H = H | 0;
5876
+ }
5877
+ _cloneInto(to) {
5878
+ (to ||= new this.constructor()).set(...this.get());
5879
+ return this._cloneIntoMeta(to);
5880
+ }
5881
+ process(view, offset) {
5882
+ for (let i = 0; i < 16; i++, offset += 4)
5883
+ SHA256_W[i] = view.getUint32(offset, false);
5884
+ for (let i = 16; i < 64; i++) {
5885
+ const W15 = SHA256_W[i - 15];
5886
+ const W2 = SHA256_W[i - 2];
5887
+ const s0 = rotr(W15, 7) ^ rotr(W15, 18) ^ W15 >>> 3;
5888
+ const s1 = rotr(W2, 17) ^ rotr(W2, 19) ^ W2 >>> 10;
5889
+ SHA256_W[i] = s1 + SHA256_W[i - 7] + s0 + SHA256_W[i - 16] | 0;
5890
+ }
5891
+ let { A, B, C, D, E, F, G, H } = this;
5892
+ for (let i = 0; i < 64; i++) {
5893
+ const sigma1 = rotr(E, 6) ^ rotr(E, 11) ^ rotr(E, 25);
5894
+ const T1 = H + sigma1 + Chi(E, F, G) + SHA256_K[i] + SHA256_W[i] | 0;
5895
+ const sigma0 = rotr(A, 2) ^ rotr(A, 13) ^ rotr(A, 22);
5896
+ const T2 = sigma0 + Maj(A, B, C) | 0;
5897
+ H = G;
5898
+ G = F;
5899
+ F = E;
5900
+ E = D + T1 | 0;
5901
+ D = C;
5902
+ C = B;
5903
+ B = A;
5904
+ A = T1 + T2 | 0;
5905
+ }
5906
+ A = A + this.A | 0;
5907
+ B = B + this.B | 0;
5908
+ C = C + this.C | 0;
5909
+ D = D + this.D | 0;
5910
+ E = E + this.E | 0;
5911
+ F = F + this.F | 0;
5912
+ G = G + this.G | 0;
5913
+ H = H + this.H | 0;
5914
+ this.set(A, B, C, D, E, F, G, H);
5915
+ }
5916
+ roundClean() {
5917
+ clean(SHA256_W);
5918
+ }
5919
+ destroy() {
5920
+ this.destroyed = true;
5921
+ this.set(0, 0, 0, 0, 0, 0, 0, 0);
5922
+ clean(this.buffer);
5923
+ }
5924
+ };
5925
+ var _SHA256 = class extends SHA2_32B {
5926
+ constructor() {
5927
+ super(32, SHA256_IV);
5928
+ }
5929
+ };
5930
+ var sha256 = /* @__PURE__ */ createHasher(
5931
+ () => new _SHA256(),
5932
+ /* @__PURE__ */ oidNist(1)
5933
+ );
5934
+
5935
+ // ../mcp-oauth/dist/client/pkce.js
5936
+ function generateCodeVerifier() {
5937
+ return base64url_exports.encode(crypto.getRandomValues(new Uint8Array(32)));
5938
+ }
5939
+ function generateCodeChallenge(verifier) {
5940
+ return base64url_exports.encode(sha256(new TextEncoder().encode(verifier)));
5443
5941
  }
5444
5942
 
5445
5943
  // ../mcp-oauth/dist/client/session-transaction.js
@@ -5657,7 +6155,7 @@ function createDefaultOAuthClientProvider(options) {
5657
6155
  async function ensureAuthorizedSession(resource, discovery, fetch2, allowInteractive, forceRefresh = false, signal, rejectedTokens) {
5658
6156
  signal?.throwIfAborted();
5659
6157
  if (discovery !== void 0) {
5660
- if (getOwnString2(discovery.authorizationServerMetadata, "issuer") !== discovery.authorizationServer)
6158
+ if (getOwnString3(discovery.authorizationServerMetadata, "issuer") !== discovery.authorizationServer)
5661
6159
  throw new Error("OAuth discovery authorization-server issuer mismatch");
5662
6160
  assertSecureOAuthFlowEndpoints(discovery.authorizationServerMetadata);
5663
6161
  }
@@ -5676,7 +6174,7 @@ function createDefaultOAuthClientProvider(options) {
5676
6174
  if (session !== null && initialGrant?.resource === canonicalResource)
5677
6175
  initialGrantConsumed = true;
5678
6176
  signal?.throwIfAborted();
5679
- if (session !== null && (canonicalizeResourceIndicator(session.resource) !== canonicalResource || getOwnString2(session.discovery.authorizationServerMetadata, "issuer") !== session.authorizationServer || discovery !== void 0 && discovery.authorizationServer !== session.authorizationServer)) {
6177
+ if (session !== null && (canonicalizeResourceIndicator(session.resource) !== canonicalResource || getOwnString3(session.discovery.authorizationServerMetadata, "issuer") !== session.authorizationServer || discovery !== void 0 && discovery.authorizationServer !== session.authorizationServer)) {
5680
6178
  await clearSession(canonicalResource);
5681
6179
  session = null;
5682
6180
  }
@@ -5890,7 +6388,7 @@ function createDefaultOAuthClientProvider(options) {
5890
6388
  client: configuredClient
5891
6389
  };
5892
6390
  }
5893
- const registrationEndpoint = getOwnString2(discovery.authorizationServerMetadata, "registration_endpoint");
6391
+ const registrationEndpoint = getOwnString3(discovery.authorizationServerMetadata, "registration_endpoint");
5894
6392
  let storedClient = await loadRegisteredClient(discovery.authorizationServer);
5895
6393
  const importedClient = existingSession?.client.registrationOwnership === "caller" ? existingSession.client : storedClient?.registrationOwnership === "caller" ? storedClient : void 0;
5896
6394
  if (importedClient !== void 0) {
@@ -5937,21 +6435,15 @@ function createDefaultOAuthClientProvider(options) {
5937
6435
  const registrationMethod = requestedTokenMethod ?? (supported === void 0 ? "none" : ["none", "client_secret_basic", "client_secret_post"].find((method) => supported.includes(method)));
5938
6436
  if (registrationMethod === void 0 || supported !== void 0 && !supported.includes(registrationMethod))
5939
6437
  throw new Error("Authorization server does not support the requested OAuth token endpoint authentication");
5940
- const registrationBody = buildClientRegistrationBody(clientMetadata, redirectUri, registrationMethod);
5941
- const deadline = AbortSignal.timeout(3e4);
5942
- const signal = parentSignal === void 0 ? deadline : AbortSignal.any([parentSignal, deadline]);
5943
- const response = await fetchMcpResponse(fetch2, registrationEndpoint, {
5944
- method: "POST",
5945
- headers: {
5946
- Accept: "application/json",
5947
- "Content-Type": "application/json"
5948
- },
5949
- body: JSON.stringify(registrationBody),
5950
- signal
6438
+ const registration = await registerOAuthClient({
6439
+ registrationEndpoint,
6440
+ redirectUri,
6441
+ metadata: clientMetadata,
6442
+ tokenEndpointAuthMethod: normalizeOAuthTokenEndpointAuthMethod(registrationMethod),
6443
+ fetch: fetch2,
6444
+ signal: parentSignal
5951
6445
  });
5952
- const payload = await readOAuthJsonObjectResponse(response, signal);
5953
- const registration = parseOAuthClientRegistration(payload);
5954
- const registeredSecret = getOwnString2(registration, "client_secret");
6446
+ const registeredSecret = getOwnString3(registration, "client_secret");
5955
6447
  const responseMethod = normalizeOAuthTokenEndpointAuthMethod(getOwnEntry6(registration, "token_endpoint_auth_method")) ?? requestedTokenMethod ?? (supported === void 0 ? void 0 : normalizeOAuthTokenEndpointAuthMethod(registrationMethod));
5956
6448
  const registeredClient = {
5957
6449
  clientId: registration.client_id.trim(),
@@ -6027,9 +6519,9 @@ function resolveDiscovery(discovery, session) {
6027
6519
  return void 0;
6028
6520
  }
6029
6521
  const metadata = session.discovery.authorizationServerMetadata;
6030
- const issuer = getOwnString2(metadata, "issuer");
6031
- const authorizationEndpoint = getOwnString2(metadata, "authorization_endpoint");
6032
- const tokenEndpoint = getOwnString2(metadata, "token_endpoint");
6522
+ const issuer = getOwnString3(metadata, "issuer");
6523
+ const authorizationEndpoint = getOwnString3(metadata, "authorization_endpoint");
6524
+ const tokenEndpoint = getOwnString3(metadata, "token_endpoint");
6033
6525
  const codeChallengeMethodsSupported = getOwnStringArray(metadata, "code_challenge_methods_supported");
6034
6526
  if (issuer === void 0 || authorizationEndpoint === void 0 || tokenEndpoint === void 0 || codeChallengeMethodsSupported === void 0 || !codeChallengeMethodsSupported.includes("S256")) {
6035
6527
  return void 0;
@@ -6101,8 +6593,8 @@ function normalizeStoredTokens(value) {
6101
6593
  if (value === void 0 || !isObjectRecord3(value)) {
6102
6594
  return void 0;
6103
6595
  }
6104
- const accessToken = getOwnString2(value, "accessToken");
6105
- const tokenType = getOwnString2(value, "tokenType");
6596
+ const accessToken = getOwnString3(value, "accessToken");
6597
+ const tokenType = getOwnString3(value, "tokenType");
6106
6598
  const expiresAt = getOwnEntry6(value, "expiresAt");
6107
6599
  const refreshToken = getOwnEntry6(value, "refreshToken");
6108
6600
  const scope = getOwnEntry6(value, "scope");
@@ -6136,7 +6628,7 @@ function normalizeConfiguredClient(client) {
6136
6628
  const clientId = normalizeOptionalOAuthString(client.clientId) ?? registration?.client_id.trim();
6137
6629
  if (clientId === void 0)
6138
6630
  return null;
6139
- const clientSecret = normalizeOptionalOAuthString(client.clientSecret) ?? (registration === void 0 ? void 0 : getOwnString2(registration, "client_secret")?.trim());
6631
+ const clientSecret = normalizeOptionalOAuthString(client.clientSecret) ?? (registration === void 0 ? void 0 : getOwnString3(registration, "client_secret")?.trim());
6140
6632
  return normalizeStoredOAuthClient({
6141
6633
  clientId,
6142
6634
  clientSecret,
@@ -6158,12 +6650,12 @@ function getOwnEntry6(record2, key2) {
6158
6650
  function isObjectRecord3(value) {
6159
6651
  return typeof value === "object" && value !== null && !Array.isArray(value);
6160
6652
  }
6161
- function getOwnString2(record2, key2) {
6653
+ function getOwnString3(record2, key2) {
6162
6654
  const value = getOwnEntry6(record2, key2);
6163
6655
  return typeof value === "string" ? value : void 0;
6164
6656
  }
6165
6657
  function requireOwnString(record2, key2, label) {
6166
- const value = getOwnString2(record2, key2);
6658
+ const value = getOwnString3(record2, key2);
6167
6659
  if (value === void 0) {
6168
6660
  throw new Error(`${label} is missing ${key2}`);
6169
6661
  }
@@ -6225,7 +6717,7 @@ function assertSecureOAuthFlowEndpoints(metadata) {
6225
6717
  throw new Error("Authorization server issuer must not include query or fragment");
6226
6718
  const authorizationEndpoint = requireOwnString(metadata, "authorization_endpoint", "Authorization server metadata");
6227
6719
  const tokenEndpoint = requireOwnString(metadata, "token_endpoint", "Authorization server metadata");
6228
- const registrationEndpoint = getOwnString2(metadata, "registration_endpoint");
6720
+ const registrationEndpoint = getOwnString3(metadata, "registration_endpoint");
6229
6721
  assertNoAccessTokenInUrl(authorizationEndpoint, "Authorization endpoint");
6230
6722
  assertNoAccessTokenInUrl(tokenEndpoint, "Token endpoint");
6231
6723
  assertSecureUrl(authorizationEndpoint, "Authorization endpoint");
@@ -6247,7 +6739,7 @@ function assertRequestMatchesResource(requestUrl, resource) {
6247
6739
  }
6248
6740
  }
6249
6741
  function assertRegistrationIssuer(client, issuer) {
6250
- const registrationIssuer = client.registration === void 0 ? void 0 : getOwnString2(client.registration, "issuer");
6742
+ const registrationIssuer = client.registration === void 0 ? void 0 : getOwnString3(client.registration, "issuer");
6251
6743
  if (registrationIssuer !== void 0 && registrationIssuer !== issuer)
6252
6744
  throw new Error("OAuth client registration issuer does not match the authorization server");
6253
6745
  }
@@ -6273,31 +6765,6 @@ function assertTokenEndpointAuthentication(client, metadata) {
6273
6765
  if (supported !== void 0 && !supported.includes(method))
6274
6766
  throw new Error("Authorization server does not support the requested OAuth token endpoint authentication");
6275
6767
  }
6276
- function buildClientRegistrationBody(metadata, redirectUri, tokenEndpointAuthMethod) {
6277
- const body = {
6278
- redirect_uris: [redirectUri],
6279
- grant_types: ["authorization_code", "refresh_token"],
6280
- response_types: ["code"],
6281
- token_endpoint_auth_method: tokenEndpointAuthMethod
6282
- };
6283
- const clientName = metadata === void 0 ? void 0 : getOwnString2(metadata, "clientName");
6284
- const scope = metadata === void 0 ? void 0 : getOwnString2(metadata, "scope");
6285
- const softwareId = metadata === void 0 ? void 0 : getOwnString2(metadata, "softwareId");
6286
- const softwareVersion = metadata === void 0 ? void 0 : getOwnString2(metadata, "softwareVersion");
6287
- if (clientName !== void 0 && clientName.length > 0) {
6288
- body.client_name = clientName;
6289
- }
6290
- if (scope !== void 0 && scope.length > 0) {
6291
- body.scope = scope;
6292
- }
6293
- if (softwareId !== void 0 && softwareId.length > 0) {
6294
- body.software_id = softwareId;
6295
- }
6296
- if (softwareVersion !== void 0 && softwareVersion.length > 0) {
6297
- body.software_version = softwareVersion;
6298
- }
6299
- return body;
6300
- }
6301
6768
  function toStoredDiscovery(discovery) {
6302
6769
  return {
6303
6770
  resourceMetadataUrl: discovery.resourceMetadataUrl,
@@ -7782,111 +8249,9 @@ var HttpTransportError = class extends Error {
7782
8249
  method;
7783
8250
  rpcMethod;
7784
8251
  };
7785
- function defaultStdioSpawn(command, args, options) {
7786
- return spawn2(command, args, options);
7787
- }
7788
8252
  function defaultHttpTransportFetch(input, init) {
7789
8253
  return fetch(input, init);
7790
8254
  }
7791
- var StdioTransport = class _StdioTransport {
7792
- readable;
7793
- writable;
7794
- closed;
7795
- child;
7796
- disposed = false;
7797
- stderrOutput = "";
7798
- static STDERR_MAX_LENGTH = 65536;
7799
- constructor({
7800
- command,
7801
- args = [],
7802
- cwd,
7803
- env,
7804
- spawn: spawnProcess = defaultStdioSpawn
7805
- }) {
7806
- this.child = spawnProcess(command, args, {
7807
- cwd,
7808
- env,
7809
- stdio: ["pipe", "pipe", "pipe"]
7810
- });
7811
- const child = this.child;
7812
- this.readable = child.stdout;
7813
- this.writable = child.stdin;
7814
- const stderrDecoder = new TextDecoder();
7815
- child.stderr.on("data", (chunk) => {
7816
- const decoded = chunk instanceof Uint8Array ? stderrDecoder.decode(chunk, { stream: true }) : `${stderrDecoder.decode()}${String(chunk)}`;
7817
- this.appendStderrOutput(decoded);
7818
- });
7819
- child.stderr.once("end", () => {
7820
- this.appendStderrOutput(stderrDecoder.decode());
7821
- });
7822
- this.closed = new Promise((resolve) => {
7823
- let settled = false;
7824
- let streamError;
7825
- const resolveClosed = (event) => {
7826
- if (settled) {
7827
- return;
7828
- }
7829
- settled = true;
7830
- resolve(event);
7831
- };
7832
- for (const stream of [child.stdin, child.stdout, child.stderr]) {
7833
- stream.once("error", (reason) => {
7834
- streamError ??= reason;
7835
- this.dispose(reason);
7836
- });
7837
- }
7838
- child.once("exit", (code, signal) => {
7839
- const closedEvent = {
7840
- reason: streamError ?? new Error("Stdio transport process exited")
7841
- };
7842
- if (code !== null) {
7843
- closedEvent.code = code;
7844
- }
7845
- if (signal !== null) {
7846
- closedEvent.signal = signal;
7847
- }
7848
- resolveClosed(closedEvent);
7849
- });
7850
- child.once("error", (error) => {
7851
- const closedEvent = {
7852
- reason: error instanceof Error ? error : new Error(String(error))
7853
- };
7854
- if (child.exitCode !== null) {
7855
- closedEvent.code = child.exitCode;
7856
- }
7857
- if (child.signalCode !== null) {
7858
- closedEvent.signal = child.signalCode;
7859
- }
7860
- resolveClosed(closedEvent);
7861
- });
7862
- });
7863
- }
7864
- getStderrOutput() {
7865
- return this.stderrOutput;
7866
- }
7867
- appendStderrOutput(chunk) {
7868
- if (chunk.length === 0) {
7869
- return;
7870
- }
7871
- this.stderrOutput += chunk;
7872
- if (this.stderrOutput.length > _StdioTransport.STDERR_MAX_LENGTH) {
7873
- this.stderrOutput = this.stderrOutput.slice(-_StdioTransport.STDERR_MAX_LENGTH);
7874
- }
7875
- }
7876
- dispose(reason = new Error("Stdio transport disposed")) {
7877
- void reason;
7878
- if (this.disposed) {
7879
- return;
7880
- }
7881
- this.disposed = true;
7882
- if (!this.child.stdin.destroyed && !this.child.stdin.writableEnded) {
7883
- this.child.stdin.end();
7884
- }
7885
- if (this.child.exitCode === null && this.child.signalCode === null && !this.child.killed) {
7886
- this.child.kill("SIGTERM");
7887
- }
7888
- }
7889
- };
7890
8255
  function snapshotHttpTransportHeaders(headers) {
7891
8256
  try {
7892
8257
  return new Headers(headers);
@@ -8465,7 +8830,7 @@ var HttpTransport = class {
8465
8830
  return;
8466
8831
  }
8467
8832
  const parser = new SseParser(this.maxResponseBytes, options.acceptEndpoint);
8468
- const decoder = new TextDecoder("utf-8", { fatal: true });
8833
+ const decoder2 = new TextDecoder("utf-8", { fatal: true });
8469
8834
  const reader = response.body.getReader();
8470
8835
  this.openResponseReaders.add(reader);
8471
8836
  const abort = () => {
@@ -8483,7 +8848,7 @@ var HttpTransport = class {
8483
8848
  if (value === void 0) {
8484
8849
  continue;
8485
8850
  }
8486
- const messages = parser.push(decoder.decode(value, { stream: true }));
8851
+ const messages = parser.push(decoder2.decode(value, { stream: true }));
8487
8852
  this.writeSseMessages(messages, context);
8488
8853
  if (context?.completed || options.stopAfterInitialization && this.initializationRequestId === void 0) {
8489
8854
  void reader.cancel().catch(() => void 0);
@@ -8491,7 +8856,7 @@ var HttpTransport = class {
8491
8856
  }
8492
8857
  this.lastEventId = parser.lastEventId ?? this.lastEventId;
8493
8858
  }
8494
- const trailingChunk = decoder.decode();
8859
+ const trailingChunk = decoder2.decode();
8495
8860
  if (trailingChunk.length > 0) {
8496
8861
  this.writeSseMessages(parser.push(trailingChunk), context);
8497
8862
  this.lastEventId = parser.lastEventId ?? this.lastEventId;
@@ -8655,14 +9020,14 @@ async function* readLines(stream, maxLineBytes = 16 * 1024 * 1024) {
8655
9020
  }
8656
9021
  let parts = [];
8657
9022
  let bytes = 0;
8658
- const decoder = new TextDecoder("utf-8", { fatal: true });
9023
+ const decoder2 = new TextDecoder("utf-8", { fatal: true });
8659
9024
  const append = (part) => {
8660
9025
  bytes += new TextEncoder().encode(part).byteLength;
8661
9026
  if (bytes > maxLineBytes) throw new Error(`Stdio input line byte limit exceeded (${maxLineBytes} bytes)`);
8662
9027
  if (part.length > 0) parts.push(part);
8663
9028
  };
8664
9029
  for await (const chunk of stream) {
8665
- const text = chunk instanceof Uint8Array ? decoder.decode(chunk, { stream: true }) : decoder.decode() + String(chunk);
9030
+ const text = chunk instanceof Uint8Array ? decoder2.decode(chunk, { stream: true }) : decoder2.decode() + String(chunk);
8666
9031
  let start = 0;
8667
9032
  let newline = text.indexOf("\n", start);
8668
9033
  while (newline !== -1) {
@@ -8675,7 +9040,7 @@ async function* readLines(stream, maxLineBytes = 16 * 1024 * 1024) {
8675
9040
  }
8676
9041
  append(text.slice(start));
8677
9042
  }
8678
- append(decoder.decode());
9043
+ append(decoder2.decode());
8679
9044
  if (parts.length > 0) yield normalizeLine(parts.join(""));
8680
9045
  }
8681
9046
  var SseParser = class {
@@ -9499,6 +9864,113 @@ function parseJsonRpcPayload(parsed) {
9499
9864
  }
9500
9865
  };
9501
9866
  }
9867
+
9868
+ // src/spawn.node.ts
9869
+ import { spawn as spawn2 } from "node:child_process";
9870
+
9871
+ // src/stdio-transport.ts
9872
+ function defaultStdioSpawn(command, args, options) {
9873
+ return spawn2(command, args, options);
9874
+ }
9875
+ var StdioTransport = class _StdioTransport {
9876
+ readable;
9877
+ writable;
9878
+ closed;
9879
+ child;
9880
+ disposed = false;
9881
+ stderrOutput = "";
9882
+ static STDERR_MAX_LENGTH = 65536;
9883
+ constructor({
9884
+ command,
9885
+ args = [],
9886
+ cwd,
9887
+ env,
9888
+ spawn: spawnProcess = defaultStdioSpawn
9889
+ }) {
9890
+ this.child = spawnProcess(command, args, {
9891
+ cwd,
9892
+ env,
9893
+ stdio: ["pipe", "pipe", "pipe"]
9894
+ });
9895
+ const child = this.child;
9896
+ this.readable = child.stdout;
9897
+ this.writable = child.stdin;
9898
+ const stderrDecoder = new TextDecoder();
9899
+ child.stderr.on("data", (chunk) => {
9900
+ const decoded = chunk instanceof Uint8Array ? stderrDecoder.decode(chunk, { stream: true }) : `${stderrDecoder.decode()}${String(chunk)}`;
9901
+ this.appendStderrOutput(decoded);
9902
+ });
9903
+ child.stderr.once("end", () => {
9904
+ this.appendStderrOutput(stderrDecoder.decode());
9905
+ });
9906
+ this.closed = new Promise((resolve) => {
9907
+ let settled = false;
9908
+ let streamError;
9909
+ const resolveClosed = (event) => {
9910
+ if (settled) {
9911
+ return;
9912
+ }
9913
+ settled = true;
9914
+ resolve(event);
9915
+ };
9916
+ for (const stream of [child.stdin, child.stdout, child.stderr]) {
9917
+ stream.once("error", (reason) => {
9918
+ streamError ??= reason;
9919
+ this.dispose(reason);
9920
+ });
9921
+ }
9922
+ child.once("exit", (code, signal) => {
9923
+ const closedEvent = {
9924
+ reason: streamError ?? new Error("Stdio transport process exited")
9925
+ };
9926
+ if (code !== null) {
9927
+ closedEvent.code = code;
9928
+ }
9929
+ if (signal !== null) {
9930
+ closedEvent.signal = signal;
9931
+ }
9932
+ resolveClosed(closedEvent);
9933
+ });
9934
+ child.once("error", (error) => {
9935
+ const closedEvent = {
9936
+ reason: error instanceof Error ? error : new Error(String(error))
9937
+ };
9938
+ if (child.exitCode !== null) {
9939
+ closedEvent.code = child.exitCode;
9940
+ }
9941
+ if (child.signalCode !== null) {
9942
+ closedEvent.signal = child.signalCode;
9943
+ }
9944
+ resolveClosed(closedEvent);
9945
+ });
9946
+ });
9947
+ }
9948
+ getStderrOutput() {
9949
+ return this.stderrOutput;
9950
+ }
9951
+ appendStderrOutput(chunk) {
9952
+ if (chunk.length === 0) {
9953
+ return;
9954
+ }
9955
+ this.stderrOutput += chunk;
9956
+ if (this.stderrOutput.length > _StdioTransport.STDERR_MAX_LENGTH) {
9957
+ this.stderrOutput = this.stderrOutput.slice(-_StdioTransport.STDERR_MAX_LENGTH);
9958
+ }
9959
+ }
9960
+ dispose(reason = new Error("Stdio transport disposed")) {
9961
+ void reason;
9962
+ if (this.disposed) {
9963
+ return;
9964
+ }
9965
+ this.disposed = true;
9966
+ if (!this.child.stdin.destroyed && !this.child.stdin.writableEnded) {
9967
+ this.child.stdin.end();
9968
+ }
9969
+ if (this.child.exitCode === null && this.child.signalCode === null && !this.child.killed) {
9970
+ this.child.kill("SIGTERM");
9971
+ }
9972
+ }
9973
+ };
9502
9974
  export {
9503
9975
  ERROR_INTERNAL,
9504
9976
  ERROR_INVALID_PARAMS,
@@ -9517,6 +9989,7 @@ export {
9517
9989
  createInMemoryTransportPair,
9518
9990
  createSdkTestPair,
9519
9991
  createTestPair,
9992
+ defaultStdioSpawn,
9520
9993
  discoverOAuthMetadata,
9521
9994
  fetchMcpResponse,
9522
9995
  snapshotHttpTransportHeaders