mppx 0.0.1 → 0.1.0

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 (446) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +195 -0
  3. package/dist/BodyDigest.d.ts +42 -0
  4. package/dist/BodyDigest.d.ts.map +1 -0
  5. package/dist/BodyDigest.js +40 -0
  6. package/dist/BodyDigest.js.map +1 -0
  7. package/dist/Challenge.d.ts +271 -0
  8. package/dist/Challenge.d.ts.map +1 -0
  9. package/dist/Challenge.js +291 -0
  10. package/dist/Challenge.js.map +1 -0
  11. package/dist/Credential.d.ts +91 -0
  12. package/dist/Credential.d.ts.map +1 -0
  13. package/dist/Credential.js +122 -0
  14. package/dist/Credential.js.map +1 -0
  15. package/dist/Errors.d.ts +243 -0
  16. package/dist/Errors.d.ts.map +1 -0
  17. package/dist/Errors.js +201 -0
  18. package/dist/Errors.js.map +1 -0
  19. package/dist/Expires.d.ts +15 -0
  20. package/dist/Expires.d.ts.map +1 -0
  21. package/dist/Expires.js +29 -0
  22. package/dist/Expires.js.map +1 -0
  23. package/dist/Intent.d.ts +101 -0
  24. package/dist/Intent.d.ts.map +1 -0
  25. package/dist/Intent.js +83 -0
  26. package/dist/Intent.js.map +1 -0
  27. package/dist/Mcp.d.ts +74 -0
  28. package/dist/Mcp.d.ts.map +1 -0
  29. package/dist/Mcp.js +9 -0
  30. package/dist/Mcp.js.map +1 -0
  31. package/dist/MethodIntent.d.ts +225 -0
  32. package/dist/MethodIntent.d.ts.map +1 -0
  33. package/dist/MethodIntent.js +156 -0
  34. package/dist/MethodIntent.js.map +1 -0
  35. package/dist/PaymentRequest.d.ts +88 -0
  36. package/dist/PaymentRequest.d.ts.map +1 -0
  37. package/dist/PaymentRequest.js +81 -0
  38. package/dist/PaymentRequest.js.map +1 -0
  39. package/dist/Receipt.d.ts +110 -0
  40. package/dist/Receipt.d.ts.map +1 -0
  41. package/dist/Receipt.js +105 -0
  42. package/dist/Receipt.js.map +1 -0
  43. package/dist/Store.d.ts +28 -0
  44. package/dist/Store.d.ts.map +1 -0
  45. package/dist/Store.js +61 -0
  46. package/dist/Store.js.map +1 -0
  47. package/dist/cli.d.ts +3 -0
  48. package/dist/cli.d.ts.map +1 -0
  49. package/dist/cli.js +1219 -0
  50. package/dist/cli.js.map +1 -0
  51. package/dist/client/Methods.d.ts +4 -0
  52. package/dist/client/Methods.d.ts.map +1 -0
  53. package/dist/client/Methods.js +4 -0
  54. package/dist/client/Methods.js.map +1 -0
  55. package/dist/client/Mppx.d.ts +84 -0
  56. package/dist/client/Mppx.d.ts.map +1 -0
  57. package/dist/client/Mppx.js +64 -0
  58. package/dist/client/Mppx.js.map +1 -0
  59. package/dist/client/Transport.d.ts +56 -0
  60. package/dist/client/Transport.d.ts.map +1 -0
  61. package/dist/client/Transport.js +81 -0
  62. package/dist/client/Transport.js.map +1 -0
  63. package/dist/client/index.d.ts +5 -0
  64. package/dist/client/index.d.ts.map +1 -0
  65. package/dist/client/index.js +5 -0
  66. package/dist/client/index.js.map +1 -0
  67. package/dist/client/internal/Fetch.d.ts +85 -0
  68. package/dist/client/internal/Fetch.d.ts.map +1 -0
  69. package/dist/client/internal/Fetch.js +95 -0
  70. package/dist/client/internal/Fetch.js.map +1 -0
  71. package/dist/index.d.ts +13 -0
  72. package/dist/index.d.ts.map +1 -0
  73. package/dist/index.js +13 -0
  74. package/dist/index.js.map +1 -0
  75. package/dist/internal/types.d.ts +302 -0
  76. package/dist/internal/types.d.ts.map +1 -0
  77. package/dist/internal/types.js +2 -0
  78. package/dist/internal/types.js.map +1 -0
  79. package/dist/mcp-sdk/client/McpClient.d.ts +78 -0
  80. package/dist/mcp-sdk/client/McpClient.d.ts.map +1 -0
  81. package/dist/mcp-sdk/client/McpClient.js +98 -0
  82. package/dist/mcp-sdk/client/McpClient.js.map +1 -0
  83. package/dist/mcp-sdk/client/index.d.ts +3 -0
  84. package/dist/mcp-sdk/client/index.d.ts.map +1 -0
  85. package/dist/mcp-sdk/client/index.js +3 -0
  86. package/dist/mcp-sdk/client/index.js.map +1 -0
  87. package/dist/mcp-sdk/server/Transport.d.ts +43 -0
  88. package/dist/mcp-sdk/server/Transport.d.ts.map +1 -0
  89. package/dist/mcp-sdk/server/Transport.js +71 -0
  90. package/dist/mcp-sdk/server/Transport.js.map +1 -0
  91. package/dist/mcp-sdk/server/index.d.ts +2 -0
  92. package/dist/mcp-sdk/server/index.d.ts.map +1 -0
  93. package/dist/mcp-sdk/server/index.js +2 -0
  94. package/dist/mcp-sdk/server/index.js.map +1 -0
  95. package/dist/middlewares/elysia.d.ts +51 -0
  96. package/dist/middlewares/elysia.d.ts.map +1 -0
  97. package/dist/middlewares/elysia.js +59 -0
  98. package/dist/middlewares/elysia.js.map +1 -0
  99. package/dist/middlewares/express.d.ts +46 -0
  100. package/dist/middlewares/express.d.ts.map +1 -0
  101. package/dist/middlewares/express.js +69 -0
  102. package/dist/middlewares/express.js.map +1 -0
  103. package/dist/middlewares/hono.d.ts +46 -0
  104. package/dist/middlewares/hono.d.ts.map +1 -0
  105. package/dist/middlewares/hono.js +57 -0
  106. package/dist/middlewares/hono.js.map +1 -0
  107. package/dist/middlewares/internal/mppx.d.ts +16 -0
  108. package/dist/middlewares/internal/mppx.d.ts.map +1 -0
  109. package/dist/middlewares/internal/mppx.js +16 -0
  110. package/dist/middlewares/internal/mppx.js.map +1 -0
  111. package/dist/middlewares/nextjs.d.ts +45 -0
  112. package/dist/middlewares/nextjs.d.ts.map +1 -0
  113. package/dist/middlewares/nextjs.js +57 -0
  114. package/dist/middlewares/nextjs.js.map +1 -0
  115. package/dist/proxy/Proxy.d.ts +47 -0
  116. package/dist/proxy/Proxy.d.ts.map +1 -0
  117. package/dist/proxy/Proxy.js +126 -0
  118. package/dist/proxy/Proxy.js.map +1 -0
  119. package/dist/proxy/Service.d.ts +100 -0
  120. package/dist/proxy/Service.d.ts.map +1 -0
  121. package/dist/proxy/Service.js +147 -0
  122. package/dist/proxy/Service.js.map +1 -0
  123. package/dist/proxy/index.d.ts +7 -0
  124. package/dist/proxy/index.d.ts.map +1 -0
  125. package/dist/proxy/index.js +7 -0
  126. package/dist/proxy/index.js.map +1 -0
  127. package/dist/proxy/internal/Headers.d.ts +3 -0
  128. package/dist/proxy/internal/Headers.d.ts.map +1 -0
  129. package/dist/proxy/internal/Headers.js +41 -0
  130. package/dist/proxy/internal/Headers.js.map +1 -0
  131. package/dist/proxy/internal/Route.d.ts +14 -0
  132. package/dist/proxy/internal/Route.d.ts.map +1 -0
  133. package/dist/proxy/internal/Route.js +47 -0
  134. package/dist/proxy/internal/Route.js.map +1 -0
  135. package/dist/proxy/services/anthropic.d.ts +29 -0
  136. package/dist/proxy/services/anthropic.d.ts.map +1 -0
  137. package/dist/proxy/services/anthropic.js +30 -0
  138. package/dist/proxy/services/anthropic.js.map +1 -0
  139. package/dist/proxy/services/openai.d.ts +29 -0
  140. package/dist/proxy/services/openai.d.ts.map +1 -0
  141. package/dist/proxy/services/openai.js +30 -0
  142. package/dist/proxy/services/openai.js.map +1 -0
  143. package/dist/proxy/services/stripe.d.ts +29 -0
  144. package/dist/proxy/services/stripe.d.ts.map +1 -0
  145. package/dist/proxy/services/stripe.js +30 -0
  146. package/dist/proxy/services/stripe.js.map +1 -0
  147. package/dist/server/Methods.d.ts +3 -0
  148. package/dist/server/Methods.d.ts.map +1 -0
  149. package/dist/server/Methods.js +3 -0
  150. package/dist/server/Methods.js.map +1 -0
  151. package/dist/server/Mppx.d.ts +116 -0
  152. package/dist/server/Mppx.d.ts.map +1 -0
  153. package/dist/server/Mppx.js +207 -0
  154. package/dist/server/Mppx.js.map +1 -0
  155. package/dist/server/NodeListener.d.ts +3 -0
  156. package/dist/server/NodeListener.d.ts.map +1 -0
  157. package/dist/server/NodeListener.js +3 -0
  158. package/dist/server/NodeListener.js.map +1 -0
  159. package/dist/server/Request.d.ts +24 -0
  160. package/dist/server/Request.d.ts.map +1 -0
  161. package/dist/server/Request.js +26 -0
  162. package/dist/server/Request.js.map +1 -0
  163. package/dist/server/Response.d.ts +10 -0
  164. package/dist/server/Response.d.ts.map +1 -0
  165. package/dist/server/Response.js +15 -0
  166. package/dist/server/Response.js.map +1 -0
  167. package/dist/server/Transport.d.ts +93 -0
  168. package/dist/server/Transport.d.ts.map +1 -0
  169. package/dist/server/Transport.js +132 -0
  170. package/dist/server/Transport.js.map +1 -0
  171. package/dist/server/index.d.ts +9 -0
  172. package/dist/server/index.d.ts.map +1 -0
  173. package/dist/server/index.js +9 -0
  174. package/dist/server/index.js.map +1 -0
  175. package/dist/stripe/Intents.d.ts +54 -0
  176. package/dist/stripe/Intents.d.ts.map +1 -0
  177. package/dist/stripe/Intents.js +27 -0
  178. package/dist/stripe/Intents.js.map +1 -0
  179. package/dist/stripe/client/Charge.d.ts +114 -0
  180. package/dist/stripe/client/Charge.d.ts.map +1 -0
  181. package/dist/stripe/client/Charge.js +77 -0
  182. package/dist/stripe/client/Charge.js.map +1 -0
  183. package/dist/stripe/client/MethodIntents.d.ts +80 -0
  184. package/dist/stripe/client/MethodIntents.d.ts.map +1 -0
  185. package/dist/stripe/client/MethodIntents.js +34 -0
  186. package/dist/stripe/client/MethodIntents.js.map +1 -0
  187. package/dist/stripe/client/index.d.ts +3 -0
  188. package/dist/stripe/client/index.d.ts.map +1 -0
  189. package/dist/stripe/client/index.js +3 -0
  190. package/dist/stripe/client/index.js.map +1 -0
  191. package/dist/stripe/index.d.ts +2 -0
  192. package/dist/stripe/index.d.ts.map +1 -0
  193. package/dist/stripe/index.js +2 -0
  194. package/dist/stripe/index.js.map +1 -0
  195. package/dist/stripe/server/Charge.d.ts +74 -0
  196. package/dist/stripe/server/Charge.d.ts.map +1 -0
  197. package/dist/stripe/server/Charge.js +79 -0
  198. package/dist/stripe/server/Charge.js.map +1 -0
  199. package/dist/stripe/server/MethodIntents.d.ts +65 -0
  200. package/dist/stripe/server/MethodIntents.d.ts.map +1 -0
  201. package/dist/stripe/server/MethodIntents.js +21 -0
  202. package/dist/stripe/server/MethodIntents.js.map +1 -0
  203. package/dist/stripe/server/index.d.ts +3 -0
  204. package/dist/stripe/server/index.d.ts.map +1 -0
  205. package/dist/stripe/server/index.js +3 -0
  206. package/dist/stripe/server/index.js.map +1 -0
  207. package/dist/tempo/Attribution.d.ts +101 -0
  208. package/dist/tempo/Attribution.d.ts.map +1 -0
  209. package/dist/tempo/Attribution.js +124 -0
  210. package/dist/tempo/Attribution.js.map +1 -0
  211. package/dist/tempo/Intents.d.ts +132 -0
  212. package/dist/tempo/Intents.d.ts.map +1 -0
  213. package/dist/tempo/Intents.js +81 -0
  214. package/dist/tempo/Intents.js.map +1 -0
  215. package/dist/tempo/client/ChannelOps.d.ts +54 -0
  216. package/dist/tempo/client/ChannelOps.d.ts.map +1 -0
  217. package/dist/tempo/client/ChannelOps.js +138 -0
  218. package/dist/tempo/client/ChannelOps.js.map +1 -0
  219. package/dist/tempo/client/Charge.d.ts +76 -0
  220. package/dist/tempo/client/Charge.d.ts.map +1 -0
  221. package/dist/tempo/client/Charge.js +69 -0
  222. package/dist/tempo/client/Charge.js.map +1 -0
  223. package/dist/tempo/client/MethodIntents.d.ts +157 -0
  224. package/dist/tempo/client/MethodIntents.d.ts.map +1 -0
  225. package/dist/tempo/client/MethodIntents.js +25 -0
  226. package/dist/tempo/client/MethodIntents.js.map +1 -0
  227. package/dist/tempo/client/Session.d.ts +159 -0
  228. package/dist/tempo/client/Session.d.ts.map +1 -0
  229. package/dist/tempo/client/Session.js +263 -0
  230. package/dist/tempo/client/Session.js.map +1 -0
  231. package/dist/tempo/client/SessionManager.d.ts +62 -0
  232. package/dist/tempo/client/SessionManager.d.ts.map +1 -0
  233. package/dist/tempo/client/SessionManager.js +196 -0
  234. package/dist/tempo/client/SessionManager.js.map +1 -0
  235. package/dist/tempo/client/index.d.ts +6 -0
  236. package/dist/tempo/client/index.d.ts.map +1 -0
  237. package/dist/tempo/client/index.js +5 -0
  238. package/dist/tempo/client/index.js.map +1 -0
  239. package/dist/tempo/index.d.ts +3 -0
  240. package/dist/tempo/index.d.ts.map +1 -0
  241. package/dist/tempo/index.js +3 -0
  242. package/dist/tempo/index.js.map +1 -0
  243. package/dist/tempo/internal/account.d.ts +32 -0
  244. package/dist/tempo/internal/account.d.ts.map +1 -0
  245. package/dist/tempo/internal/account.js +33 -0
  246. package/dist/tempo/internal/account.js.map +1 -0
  247. package/dist/tempo/internal/defaults.d.ts +18 -0
  248. package/dist/tempo/internal/defaults.d.ts.map +1 -0
  249. package/dist/tempo/internal/defaults.js +18 -0
  250. package/dist/tempo/internal/defaults.js.map +1 -0
  251. package/dist/tempo/internal/types.d.ts +11 -0
  252. package/dist/tempo/internal/types.d.ts.map +1 -0
  253. package/dist/tempo/internal/types.js +2 -0
  254. package/dist/tempo/internal/types.js.map +1 -0
  255. package/dist/tempo/server/Charge.d.ts +77 -0
  256. package/dist/tempo/server/Charge.d.ts.map +1 -0
  257. package/dist/tempo/server/Charge.js +228 -0
  258. package/dist/tempo/server/Charge.js.map +1 -0
  259. package/dist/tempo/server/MethodIntents.d.ts +140 -0
  260. package/dist/tempo/server/MethodIntents.d.ts.map +1 -0
  261. package/dist/tempo/server/MethodIntents.js +26 -0
  262. package/dist/tempo/server/MethodIntents.js.map +1 -0
  263. package/dist/tempo/server/Session.d.ts +148 -0
  264. package/dist/tempo/server/Session.d.ts.map +1 -0
  265. package/dist/tempo/server/Session.js +529 -0
  266. package/dist/tempo/server/Session.js.map +1 -0
  267. package/dist/tempo/server/internal/transport.d.ts +47 -0
  268. package/dist/tempo/server/internal/transport.d.ts.map +1 -0
  269. package/dist/tempo/server/internal/transport.js +118 -0
  270. package/dist/tempo/server/internal/transport.js.map +1 -0
  271. package/dist/tempo/stream/Chain.d.ts +52 -0
  272. package/dist/tempo/stream/Chain.d.ts.map +1 -0
  273. package/dist/tempo/stream/Chain.js +215 -0
  274. package/dist/tempo/stream/Chain.js.map +1 -0
  275. package/dist/tempo/stream/Channel.d.ts +26 -0
  276. package/dist/tempo/stream/Channel.d.ts.map +1 -0
  277. package/dist/tempo/stream/Channel.js +27 -0
  278. package/dist/tempo/stream/Channel.js.map +1 -0
  279. package/dist/tempo/stream/ChannelStore.d.ts +103 -0
  280. package/dist/tempo/stream/ChannelStore.d.ts.map +1 -0
  281. package/dist/tempo/stream/ChannelStore.js +100 -0
  282. package/dist/tempo/stream/ChannelStore.js.map +1 -0
  283. package/dist/tempo/stream/Receipt.d.ts +22 -0
  284. package/dist/tempo/stream/Receipt.d.ts.map +1 -0
  285. package/dist/tempo/stream/Receipt.js +34 -0
  286. package/dist/tempo/stream/Receipt.js.map +1 -0
  287. package/dist/tempo/stream/Sse.d.ts +134 -0
  288. package/dist/tempo/stream/Sse.d.ts.map +1 -0
  289. package/dist/tempo/stream/Sse.js +288 -0
  290. package/dist/tempo/stream/Sse.js.map +1 -0
  291. package/dist/tempo/stream/Types.d.ts +78 -0
  292. package/dist/tempo/stream/Types.d.ts.map +1 -0
  293. package/dist/tempo/stream/Types.js +2 -0
  294. package/dist/tempo/stream/Types.js.map +1 -0
  295. package/dist/tempo/stream/Voucher.d.ts +20 -0
  296. package/dist/tempo/stream/Voucher.d.ts.map +1 -0
  297. package/dist/tempo/stream/Voucher.js +98 -0
  298. package/dist/tempo/stream/Voucher.js.map +1 -0
  299. package/dist/tempo/stream/escrow.abi.d.ts +598 -0
  300. package/dist/tempo/stream/escrow.abi.d.ts.map +1 -0
  301. package/dist/tempo/stream/escrow.abi.js +760 -0
  302. package/dist/tempo/stream/escrow.abi.js.map +1 -0
  303. package/dist/tempo/stream/index.d.ts +8 -0
  304. package/dist/tempo/stream/index.d.ts.map +1 -0
  305. package/dist/tempo/stream/index.js +8 -0
  306. package/dist/tempo/stream/index.js.map +1 -0
  307. package/dist/viem/Account.d.ts +12 -0
  308. package/dist/viem/Account.d.ts.map +1 -0
  309. package/dist/viem/Account.js +14 -0
  310. package/dist/viem/Account.js.map +1 -0
  311. package/dist/viem/Client.d.ts +21 -0
  312. package/dist/viem/Client.d.ts.map +1 -0
  313. package/dist/viem/Client.js +19 -0
  314. package/dist/viem/Client.js.map +1 -0
  315. package/dist/zod.d.ts +17 -0
  316. package/dist/zod.d.ts.map +1 -0
  317. package/dist/zod.js +35 -0
  318. package/dist/zod.js.map +1 -0
  319. package/package.json +117 -4
  320. package/src/BodyDigest.test.ts +43 -0
  321. package/src/BodyDigest.ts +53 -0
  322. package/src/Challenge.test-d.ts +81 -0
  323. package/src/Challenge.test.ts +414 -0
  324. package/src/Challenge.ts +429 -0
  325. package/src/Credential.test.ts +227 -0
  326. package/src/Credential.ts +154 -0
  327. package/src/Errors.test.ts +402 -0
  328. package/src/Errors.ts +348 -0
  329. package/src/Expires.ts +34 -0
  330. package/src/Intent.test.ts +180 -0
  331. package/src/Intent.ts +109 -0
  332. package/src/Mcp.ts +81 -0
  333. package/src/MethodIntent.test.ts +303 -0
  334. package/src/MethodIntent.ts +388 -0
  335. package/src/PaymentRequest.test.ts +152 -0
  336. package/src/PaymentRequest.ts +107 -0
  337. package/src/Receipt.test.ts +98 -0
  338. package/src/Receipt.ts +129 -0
  339. package/src/Store.ts +84 -0
  340. package/src/cli.test.ts +542 -0
  341. package/src/cli.ts +1319 -0
  342. package/src/client/Methods.ts +3 -0
  343. package/src/client/Mppx.test-d.ts +90 -0
  344. package/src/client/Mppx.test.ts +468 -0
  345. package/src/client/Mppx.ts +149 -0
  346. package/src/client/Transport.test.ts +283 -0
  347. package/src/client/Transport.ts +115 -0
  348. package/src/client/index.ts +4 -0
  349. package/src/client/internal/Fetch.test-d.ts +57 -0
  350. package/src/client/internal/Fetch.test.ts +281 -0
  351. package/src/client/internal/Fetch.ts +157 -0
  352. package/src/env.d.ts +11 -0
  353. package/src/index.ts +12 -0
  354. package/src/internal/types.ts +403 -0
  355. package/src/mcp-sdk/client/McpClient.test-d.ts +109 -0
  356. package/src/mcp-sdk/client/McpClient.test.ts +219 -0
  357. package/src/mcp-sdk/client/McpClient.ts +187 -0
  358. package/src/mcp-sdk/client/index.ts +2 -0
  359. package/src/mcp-sdk/server/Transport.ts +94 -0
  360. package/src/mcp-sdk/server/index.ts +1 -0
  361. package/src/middlewares/elysia.ts +66 -0
  362. package/src/middlewares/express.test.ts +155 -0
  363. package/src/middlewares/express.ts +82 -0
  364. package/src/middlewares/hono.test.ts +148 -0
  365. package/src/middlewares/hono.ts +62 -0
  366. package/src/middlewares/internal/mppx.ts +30 -0
  367. package/src/middlewares/nextjs.test.ts +164 -0
  368. package/src/middlewares/nextjs.ts +66 -0
  369. package/src/proxy/Proxy.test.ts +472 -0
  370. package/src/proxy/Proxy.ts +175 -0
  371. package/src/proxy/Service.test.ts +125 -0
  372. package/src/proxy/Service.ts +227 -0
  373. package/src/proxy/index.ts +6 -0
  374. package/src/proxy/internal/Headers.test.ts +100 -0
  375. package/src/proxy/internal/Headers.ts +40 -0
  376. package/src/proxy/internal/Route.test.ts +143 -0
  377. package/src/proxy/internal/Route.ts +54 -0
  378. package/src/proxy/services/anthropic.ts +45 -0
  379. package/src/proxy/services/openai.test.ts +97 -0
  380. package/src/proxy/services/openai.ts +48 -0
  381. package/src/proxy/services/stripe.ts +49 -0
  382. package/src/server/Methods.ts +2 -0
  383. package/src/server/Mppx.test-d.ts +343 -0
  384. package/src/server/Mppx.test.ts +342 -0
  385. package/src/server/Mppx.ts +378 -0
  386. package/src/server/NodeListener.test.ts +188 -0
  387. package/src/server/NodeListener.ts +3 -0
  388. package/src/server/Request.test.ts +102 -0
  389. package/src/server/Request.ts +33 -0
  390. package/src/server/Response.test.ts +31 -0
  391. package/src/server/Response.ts +27 -0
  392. package/src/server/Transport.test.ts +294 -0
  393. package/src/server/Transport.ts +222 -0
  394. package/src/server/index.ts +8 -0
  395. package/src/stripe/Charge.integration.test.ts +326 -0
  396. package/src/stripe/Intents.test.ts +52 -0
  397. package/src/stripe/Intents.ts +27 -0
  398. package/src/stripe/client/Charge.ts +119 -0
  399. package/src/stripe/client/MethodIntents.ts +37 -0
  400. package/src/stripe/client/index.ts +2 -0
  401. package/src/stripe/index.ts +1 -0
  402. package/src/stripe/server/Charge.ts +121 -0
  403. package/src/stripe/server/MethodIntents.ts +24 -0
  404. package/src/stripe/server/index.ts +2 -0
  405. package/src/tempo/Attribution.test.ts +187 -0
  406. package/src/tempo/Attribution.ts +156 -0
  407. package/src/tempo/Intents.test.ts +84 -0
  408. package/src/tempo/Intents.ts +93 -0
  409. package/src/tempo/client/ChannelOps.ts +233 -0
  410. package/src/tempo/client/Charge.ts +84 -0
  411. package/src/tempo/client/MethodIntents.ts +28 -0
  412. package/src/tempo/client/Session.ts +369 -0
  413. package/src/tempo/client/SessionManager.test.ts +223 -0
  414. package/src/tempo/client/SessionManager.ts +270 -0
  415. package/src/tempo/client/index.ts +5 -0
  416. package/src/tempo/index.ts +2 -0
  417. package/src/tempo/internal/account.ts +47 -0
  418. package/src/tempo/internal/defaults.ts +20 -0
  419. package/src/tempo/internal/types.ts +8 -0
  420. package/src/tempo/server/Charge.test.ts +847 -0
  421. package/src/tempo/server/Charge.ts +309 -0
  422. package/src/tempo/server/MethodIntents.ts +29 -0
  423. package/src/tempo/server/Session.test.ts +1349 -0
  424. package/src/tempo/server/Session.ts +773 -0
  425. package/src/tempo/server/Sse.test.ts +289 -0
  426. package/src/tempo/server/index.ts +5 -0
  427. package/src/tempo/server/internal/transport.ts +153 -0
  428. package/src/tempo/stream/Chain.ts +333 -0
  429. package/src/tempo/stream/Channel.ts +50 -0
  430. package/src/tempo/stream/ChannelStore.test.ts +473 -0
  431. package/src/tempo/stream/ChannelStore.ts +202 -0
  432. package/src/tempo/stream/Receipt.test.ts +84 -0
  433. package/src/tempo/stream/Receipt.ts +45 -0
  434. package/src/tempo/stream/Sse.test.ts +401 -0
  435. package/src/tempo/stream/Sse.ts +375 -0
  436. package/src/tempo/stream/Types.ts +86 -0
  437. package/src/tempo/stream/Voucher.test.ts +134 -0
  438. package/src/tempo/stream/Voucher.ts +123 -0
  439. package/src/tempo/stream/escrow.abi.ts +759 -0
  440. package/src/tempo/stream/index.ts +7 -0
  441. package/src/tsconfig.json +10 -0
  442. package/src/viem/Account.test.ts +71 -0
  443. package/src/viem/Account.ts +30 -0
  444. package/src/viem/Client.test.ts +58 -0
  445. package/src/viem/Client.ts +33 -0
  446. package/src/zod.ts +47 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"nextjs.js","sourceRoot":"","sources":["../../src/middlewares/nextjs.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,SAAS,MAAM,mBAAmB,CAAA;AAC9C,OAAO,KAAK,aAAa,MAAM,oBAAoB,CAAA;AAEnD,cAAc,sBAAsB,CAAA;AAMpC,MAAM,KAAW,IAAI,CAwBpB;AAxBD,WAAiB,IAAI;IACnB;;;;;;;;;;;;;;;OAeG;IACH,SAAgB,MAAM,CACpB,MAAwC;QAExC,OAAO,aAAa,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,OAAO,EAAE,EAAE;YACtE,OAAO,CAAC,OAAqB,EAAE,EAAE,CAAC,OAAO,CAAC,MAAM,EAAE,OAAO,EAAE,OAAO,CAAC,CAAA;QACrE,CAAC,CAAC,CAAA;IACJ,CAAC;IANe,WAAM,SAMrB,CAAA;AACH,CAAC,EAxBgB,IAAI,KAAJ,IAAI,QAwBpB;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,UAAU,OAAO,CACrB,MAAc,EACd,OAAyE,EACzE,OAAqB;IAErB,OAAO,KAAK,EAAE,OAAO,EAAE,EAAE;QACvB,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,CAAA;QAC7C,IAAI,MAAM,CAAC,MAAM,KAAK,GAAG;YAAE,OAAO,MAAM,CAAC,SAAS,CAAA;QAClD,MAAM,QAAQ,GAAG,MAAM,OAAO,CAAC,OAAO,CAAC,CAAA;QACvC,OAAO,MAAM,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAA;IACrC,CAAC,CAAA;AACH,CAAC"}
@@ -0,0 +1,47 @@
1
+ import type * as http from 'node:http';
2
+ import * as Service from './Service.js';
3
+ /** A paid API proxy that gates upstream services behind the mppx 402 protocol. */
4
+ export type Proxy = {
5
+ /** Fetch API handler. Works with Bun, Deno, Next.js, Hono, Elysia, SvelteKit, etc. */
6
+ fetch: (request: Request) => Promise<Response>;
7
+ /** Node.js request listener. Works with Express, Fastify, `http.createServer`, etc. */
8
+ listener: (req: http.IncomingMessage, res: http.ServerResponse) => void;
9
+ };
10
+ /**
11
+ * Creates a paid API proxy.
12
+ *
13
+ * Routes incoming requests to upstream services, injects credentials,
14
+ * and requires payment via the mppx 402 protocol for non-free endpoints.
15
+ *
16
+ * @example
17
+ * ```ts
18
+ * import { Proxy, openai } from 'mppx/proxy'
19
+ * import { Mppx, tempo } from 'mppx/server'
20
+ *
21
+ * const mppx = Mppx.create({ methods: [tempo()] })
22
+ *
23
+ * const proxy = Proxy.create({
24
+ * services: [
25
+ * openai({
26
+ * apiKey: 'sk-...',
27
+ * routes: {
28
+ * 'POST /v1/chat/completions': mppx.charge({ amount: '0.05' }),
29
+ * 'GET /v1/models': true,
30
+ * },
31
+ * }),
32
+ * ],
33
+ * })
34
+ * ```
35
+ */
36
+ export declare function create(config: create.Config): Proxy;
37
+ export declare namespace create {
38
+ type Config = {
39
+ /** Base path prefix to strip before routing (e.g. `'/api/proxy'`). */
40
+ basePath?: string | undefined;
41
+ /** Custom `fetch` implementation. Defaults to `globalThis.fetch`. */
42
+ fetch?: typeof globalThis.fetch | undefined;
43
+ /** Services to proxy. Each service is mounted at `/{serviceId}/`. */
44
+ services: Service.Service[];
45
+ };
46
+ }
47
+ //# sourceMappingURL=Proxy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Proxy.d.ts","sourceRoot":"","sources":["../../src/proxy/Proxy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,IAAI,MAAM,WAAW,CAAA;AAKtC,OAAO,KAAK,OAAO,MAAM,cAAc,CAAA;AAEvC,kFAAkF;AAClF,MAAM,MAAM,KAAK,GAAG;IAClB,sFAAsF;IACtF,KAAK,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAA;IAC9C,uFAAuF;IACvF,QAAQ,EAAE,CAAC,GAAG,EAAE,IAAI,CAAC,eAAe,EAAE,GAAG,EAAE,IAAI,CAAC,cAAc,KAAK,IAAI,CAAA;CACxE,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,GAAG,KAAK,CAgFnD;AAED,MAAM,CAAC,OAAO,WAAW,MAAM,CAAC;IAC9B,KAAY,MAAM,GAAG;QACnB,sEAAsE;QACtE,QAAQ,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;QAC7B,qEAAqE;QACrE,KAAK,CAAC,EAAE,OAAO,UAAU,CAAC,KAAK,GAAG,SAAS,CAAA;QAC3C,qEAAqE;QACrE,QAAQ,EAAE,OAAO,CAAC,OAAO,EAAE,CAAA;KAC5B,CAAA;CACF"}
@@ -0,0 +1,126 @@
1
+ import { createFetchProxy } from '@remix-run/fetch-proxy';
2
+ import * as Request from '../server/Request.js';
3
+ import * as Headers from './internal/Headers.js';
4
+ import * as Route from './internal/Route.js';
5
+ import * as Service from './Service.js';
6
+ /**
7
+ * Creates a paid API proxy.
8
+ *
9
+ * Routes incoming requests to upstream services, injects credentials,
10
+ * and requires payment via the mppx 402 protocol for non-free endpoints.
11
+ *
12
+ * @example
13
+ * ```ts
14
+ * import { Proxy, openai } from 'mppx/proxy'
15
+ * import { Mppx, tempo } from 'mppx/server'
16
+ *
17
+ * const mppx = Mppx.create({ methods: [tempo()] })
18
+ *
19
+ * const proxy = Proxy.create({
20
+ * services: [
21
+ * openai({
22
+ * apiKey: 'sk-...',
23
+ * routes: {
24
+ * 'POST /v1/chat/completions': mppx.charge({ amount: '0.05' }),
25
+ * 'GET /v1/models': true,
26
+ * },
27
+ * }),
28
+ * ],
29
+ * })
30
+ * ```
31
+ */
32
+ export function create(config) {
33
+ const fetchImpl = config.fetch ?? globalThis.fetch;
34
+ const services = new Map(config.services.map((s) => {
35
+ const proxy = createFetchProxy(s.baseUrl, {
36
+ fetch: fetchImpl,
37
+ rewriteCookieDomain: false,
38
+ rewriteCookiePath: false,
39
+ });
40
+ return [s.id, { service: s, proxy }];
41
+ }));
42
+ async function handle(request) {
43
+ const url = new URL(request.url);
44
+ const pathname = Route.pathname(url, config.basePath);
45
+ if (!pathname)
46
+ return new Response('Not Found', { status: 404 });
47
+ if (request.method === 'GET' && pathname === '/llms.txt')
48
+ return new Response(Service.toLlmsTxt(config.services), {
49
+ headers: { 'Content-Type': 'text/plain; charset=utf-8' },
50
+ });
51
+ if (request.method === 'GET' && (pathname === '/services' || pathname === '/services/'))
52
+ return Response.json(config.services.map(Service.serialize));
53
+ {
54
+ const match = pathname.match(/^\/services\/([^/]+)\/?$/);
55
+ if (request.method === 'GET' && match) {
56
+ const service = config.services.find((s) => s.id === match[1]);
57
+ if (!service)
58
+ return new Response('Not Found', { status: 404 });
59
+ return Response.json(Service.serialize(service));
60
+ }
61
+ }
62
+ const parsed = Route.parse(pathname);
63
+ if (!parsed)
64
+ return new Response('Not Found', { status: 404 });
65
+ const { serviceId, upstreamPath } = parsed;
66
+ const entry = services.get(serviceId);
67
+ if (!entry)
68
+ return new Response('Not Found', { status: 404 });
69
+ const { service, proxy } = entry;
70
+ const matched = Route.match(service.routes, request.method, upstreamPath) ??
71
+ // Management POSTs (e.g. session close) may target a path whose route
72
+ // is registered for a different HTTP method (e.g. GET). Fall back to
73
+ // path-only matching so the payment handler can process the action.
74
+ (request.method === 'POST' && request.headers.has('authorization')
75
+ ? Route.matchPath(service.routes, upstreamPath)
76
+ : null);
77
+ if (!matched)
78
+ return new Response('Not Found', { status: 404 });
79
+ const endpoint = matched.value;
80
+ const ctx = { request, service, upstreamPath };
81
+ if (endpoint === true)
82
+ return proxyUpstream({ request, service, ctx, proxy });
83
+ const handler = typeof endpoint === 'function' ? endpoint : endpoint.pay;
84
+ const result = await handler(request);
85
+ if (result.status === 402)
86
+ return result.challenge;
87
+ const options = Service.getOptions(endpoint);
88
+ const upstreamRes = await proxyUpstream({
89
+ request,
90
+ service,
91
+ ctx: { ...ctx, ...options },
92
+ proxy,
93
+ });
94
+ return result.withReceipt(upstreamRes);
95
+ }
96
+ return {
97
+ fetch: handle,
98
+ listener: Request.toNodeListener(handle),
99
+ };
100
+ }
101
+ /** @internal */
102
+ async function proxyUpstream(options) {
103
+ const { request, service, ctx, proxy } = options;
104
+ const url = ctx.upstreamPath + new URL(request.url).search;
105
+ const headers = Headers.scrub(request.headers);
106
+ const method = request.method.toUpperCase();
107
+ const hasBody = method !== 'GET' && method !== 'HEAD';
108
+ const init = {
109
+ method: request.method,
110
+ headers,
111
+ signal: request.signal,
112
+ };
113
+ if (hasBody && request.body) {
114
+ init.body = request.body;
115
+ init.duplex = 'half';
116
+ }
117
+ let upstreamReq = new globalThis.Request(new URL(url, new URL(service.baseUrl).origin), init);
118
+ if (service.rewriteRequest)
119
+ upstreamReq = await service.rewriteRequest(upstreamReq, ctx);
120
+ let upstreamRes = await proxy(upstreamReq);
121
+ upstreamRes = Headers.scrubResponse(upstreamRes);
122
+ if (service.rewriteResponse)
123
+ upstreamRes = await service.rewriteResponse(upstreamRes, ctx);
124
+ return upstreamRes;
125
+ }
126
+ //# sourceMappingURL=Proxy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Proxy.js","sourceRoot":"","sources":["../../src/proxy/Proxy.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAA;AACzD,OAAO,KAAK,OAAO,MAAM,sBAAsB,CAAA;AAC/C,OAAO,KAAK,OAAO,MAAM,uBAAuB,CAAA;AAChD,OAAO,KAAK,KAAK,MAAM,qBAAqB,CAAA;AAC5C,OAAO,KA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AC,WAAW,EAAE,GAAG,CAAC,CAAA;IAE1F,OAAO,WAAW,CAAA;AACpB,CAAC"}
@@ -0,0 +1,100 @@
1
+ /** A proxied upstream service with route definitions and optional request/response hooks. */
2
+ export type Service = {
3
+ /** Unique identifier used as the URL prefix (e.g. `'openai'` → `/{id}/...`). */
4
+ id: string;
5
+ /** Base URL of the upstream service (e.g. `'https://api.openai.com'`). */
6
+ baseUrl: string;
7
+ /** Map of route patterns to endpoint handlers. */
8
+ routes: EndpointMap;
9
+ /** Hook to modify the upstream request before sending (e.g. inject auth headers). */
10
+ rewriteRequest?: ((req: Request, ctx: Context) => Request | Promise<Request>) | undefined;
11
+ /** Hook to modify the upstream response before returning to the client. */
12
+ rewriteResponse?: ((res: Response, ctx: Context) => Response | Promise<Response>) | undefined;
13
+ };
14
+ /**
15
+ * An endpoint definition.
16
+ *
17
+ * - `IntentHandler` — payment required, calls the handler to issue a 402 challenge or verify payment.
18
+ * - `{ pay, options }` — payment required with per-endpoint config overrides.
19
+ * - `true` — free passthrough, no payment required, rewriteRequest is applied.
20
+ */
21
+ export type Endpoint = IntentHandler | {
22
+ pay: IntentHandler;
23
+ options: EndpointOptions;
24
+ } | true;
25
+ /** Map of `"METHOD /pattern"` keys to endpoint definitions. */
26
+ export type EndpointMap<routes extends string = string> = Partial<Record<routes, Endpoint>> & Record<string & {}, Endpoint>;
27
+ /** Per-endpoint configuration overrides (e.g. `{ apiKey: 'sk-...' }`). */
28
+ export type EndpointOptions = {
29
+ [key: string]: unknown;
30
+ };
31
+ /** A function that handles the mppx payment flow for a request. */
32
+ export type IntentHandler = (input: Request) => Promise<IntentResult>;
33
+ /** Result of an intent handler — either a 402 challenge or a 200 with receipt attachment. */
34
+ export type IntentResult = {
35
+ challenge: Response;
36
+ status: 402;
37
+ } | {
38
+ status: 200;
39
+ withReceipt: <response>(response: response) => response;
40
+ };
41
+ /** Context passed to `rewriteRequest`/`rewriteResponse` hooks, including any per-endpoint options. */
42
+ export type Context = {
43
+ request: Request;
44
+ service: Service;
45
+ upstreamPath: string;
46
+ } & EndpointOptions;
47
+ export type From<options extends {
48
+ routes: string;
49
+ }> = {
50
+ routes: EndpointMap<options['routes']>;
51
+ } & Omit<options, 'routes'>;
52
+ /**
53
+ * Creates a service definition.
54
+ *
55
+ * @example
56
+ * ```ts
57
+ * Service.from('my-api', {
58
+ * baseUrl: 'https://api.example.com',
59
+ * bearer: 'sk-...',
60
+ * routes: {
61
+ * 'POST /v1/generate': mppx.charge({ amount: '0.01' }),
62
+ * 'GET /v1/status': true,
63
+ * },
64
+ * })
65
+ * ```
66
+ */
67
+ export declare function from<options = unknown>(id: string, config: from.Config<options>): Service;
68
+ export declare namespace from {
69
+ type Config<options = unknown> = {
70
+ /** Base URL of the upstream service. */
71
+ baseUrl: string;
72
+ /** Shorthand: inject `Authorization: Bearer {token}` header. */
73
+ bearer?: string | undefined;
74
+ /** Shorthand: inject custom headers. */
75
+ headers?: Record<string, string> | undefined;
76
+ /** Shorthand: full request mutation function. Takes priority over `bearer`/`headers`. */
77
+ mutate?: ((req: Request) => Request | Promise<Request>) | undefined;
78
+ /** Hook to modify the upstream request. Receives typed per-endpoint options via `ctx`. */
79
+ rewriteRequest?: ((req: Request, ctx: Context & Partial<options & {}>) => Request | Promise<Request>) | undefined;
80
+ /** Map of route patterns to endpoint definitions. */
81
+ routes: EndpointMap;
82
+ };
83
+ }
84
+ export { from as custom };
85
+ /** Serializes a service for discovery responses. */
86
+ export declare function serialize(s: Service): {
87
+ id: string;
88
+ baseUrl: string;
89
+ routes: {
90
+ method: string | undefined;
91
+ path: string;
92
+ pattern: string;
93
+ payment: Record<string, unknown> | null;
94
+ }[];
95
+ };
96
+ /** Renders an llms.txt markdown string for a list of services. */
97
+ export declare function toLlmsTxt(services: Service[]): string;
98
+ /** Extracts per-endpoint options from an endpoint definition. */
99
+ export declare function getOptions(endpoint: Endpoint): EndpointOptions | undefined;
100
+ //# sourceMappingURL=Service.d.ts.map
@@ -0,0 +1 @@
1
+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AC,KAAK,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC,GACpF,SAAS,CAAA;QACb,qDAAqD;QACrD,MAAM,EAAE,WAAW,CAAA;KACpB,CAAA;CACF;AAED,OAAO,EAAE,IAAI,IAAI,MAAM,EAAE,CAAA;AAiCzB,oDAAoD;AACpD,wBAAgB,SAAS,CAAC,CAAC,EAAE,OAAO;;;;;;;;;EAenC;AAED,kEAAkE;AAClE,wBAAgB,SAAS,CAAC,QAAQ,EAAE,OAAO,EAAE,GAAG,MAAM,CA8CrD;AAED,iEAAiE;AACjE,wBAAgB,UAAU,CAAC,QAAQ,EAAE,QAAQ,GAAG,eAAe,GAAG,SAAS,CAI1E"}
@@ -0,0 +1,147 @@
1
+ import { Value } from 'ox';
2
+ /**
3
+ * Creates a service definition.
4
+ *
5
+ * @example
6
+ * ```ts
7
+ * Service.from('my-api', {
8
+ * baseUrl: 'https://api.example.com',
9
+ * bearer: 'sk-...',
10
+ * routes: {
11
+ * 'POST /v1/generate': mppx.charge({ amount: '0.01' }),
12
+ * 'GET /v1/status': true,
13
+ * },
14
+ * })
15
+ * ```
16
+ */
17
+ export function from(id, config) {
18
+ const rewriteFromConfig = resolveRewriteRequest(config);
19
+ return {
20
+ id,
21
+ baseUrl: config.baseUrl,
22
+ routes: config.routes,
23
+ rewriteRequest: config.rewriteRequest
24
+ ? rewriteFromConfig
25
+ ? async (req, ctx) => {
26
+ req = await rewriteFromConfig(req, ctx);
27
+ return config.rewriteRequest(req, ctx);
28
+ }
29
+ : config.rewriteRequest
30
+ : rewriteFromConfig,
31
+ };
32
+ }
33
+ export { from as custom };
34
+ function resolveRewriteRequest(config) {
35
+ if (config.mutate) {
36
+ const mutate = config.mutate;
37
+ return (req, ctx) => {
38
+ const options = ctx;
39
+ const m = options.mutate ?? mutate;
40
+ return m(req);
41
+ };
42
+ }
43
+ if (config.bearer) {
44
+ const bearer = config.bearer;
45
+ return (req, ctx) => {
46
+ const options = ctx;
47
+ req.headers.set('Authorization', `Bearer ${options.bearer ?? bearer}`);
48
+ return req;
49
+ };
50
+ }
51
+ if (config.headers) {
52
+ const headers = config.headers;
53
+ return (req, ctx) => {
54
+ const options = ctx;
55
+ const h = options.headers ?? headers;
56
+ for (const [name, value] of Object.entries(h))
57
+ req.headers.set(name, value);
58
+ return req;
59
+ };
60
+ }
61
+ return undefined;
62
+ }
63
+ /** Serializes a service for discovery responses. */
64
+ export function serialize(s) {
65
+ return {
66
+ id: s.id,
67
+ baseUrl: s.baseUrl,
68
+ routes: Object.entries(s.routes).map(([pattern, endpoint]) => {
69
+ const tokens = pattern.trim().split(/\s+/);
70
+ const hasMethod = tokens.length >= 2;
71
+ return {
72
+ method: hasMethod ? tokens[0] : undefined,
73
+ path: hasMethod ? tokens.slice(1).join(' ') : tokens[0],
74
+ pattern,
75
+ payment: endpoint ? resolvePayment(endpoint) : null,
76
+ };
77
+ }),
78
+ };
79
+ }
80
+ /** Renders an llms.txt markdown string for a list of services. */
81
+ export function toLlmsTxt(services) {
82
+ const lines = [
83
+ '# API Proxy',
84
+ '',
85
+ '> Paid API proxy powered by [Machine Payments Protocol](https://mpp.tempo.xyz).',
86
+ '',
87
+ 'For machine-readable service data, use `GET /services` (JSON).',
88
+ '',
89
+ ];
90
+ if (services.length === 0)
91
+ return lines.join('\n');
92
+ lines.push('## Services', '');
93
+ for (const s of services) {
94
+ const serialized = serialize(s);
95
+ const free = serialized.routes.filter((r) => r.payment === null).length;
96
+ const paid = serialized.routes.length - free;
97
+ const parts = [paid && `${paid} paid`, free && `${free} free`].filter(Boolean).join(', ');
98
+ lines.push(`- [${s.id}](${s.baseUrl}): ${parts}`);
99
+ }
100
+ for (const s of services) {
101
+ const serialized = serialize(s);
102
+ lines.push('', `## ${s.id}`, '');
103
+ for (const route of serialized.routes) {
104
+ if (!route.payment) {
105
+ lines.push(`- \`${route.pattern}\`: Free`);
106
+ continue;
107
+ }
108
+ const p = route.payment;
109
+ const parts = [`${p.intent}`];
110
+ if (p.amount) {
111
+ const unit = `${p.amount} units`;
112
+ parts.push(p.unitType ? `${unit} per ${p.unitType}` : unit);
113
+ }
114
+ if (p.description)
115
+ parts.push(`"${p.description}"`);
116
+ const meta = [
117
+ p.currency && `currency: ${p.currency}`,
118
+ p.decimals !== undefined && `decimals: ${p.decimals}`,
119
+ ].filter(Boolean);
120
+ if (meta.length)
121
+ parts.push(`(${meta.join(', ')})`);
122
+ lines.push(`- \`${route.pattern}\`: ${parts.join(' — ')}`);
123
+ }
124
+ }
125
+ return lines.join('\n');
126
+ }
127
+ /** Extracts per-endpoint options from an endpoint definition. */
128
+ export function getOptions(endpoint) {
129
+ if (typeof endpoint === 'object' && endpoint !== null && 'options' in endpoint)
130
+ return endpoint.options;
131
+ return undefined;
132
+ }
133
+ function resolvePayment(endpoint) {
134
+ if (endpoint === true)
135
+ return null;
136
+ const handler = typeof endpoint === 'function' ? endpoint : endpoint.pay;
137
+ if (!('_internal' in handler))
138
+ return {};
139
+ const { name, method, defaults, schema, ...rest } = handler._internal;
140
+ const amount = (() => {
141
+ if (typeof rest.amount === 'string' && typeof rest.decimals === 'number')
142
+ return String(Value.from(rest.amount, rest.decimals));
143
+ return rest.amount;
144
+ })();
145
+ return { intent: name, method, ...rest, ...(amount !== undefined && { amount }) };
146
+ }
147
+ //# sourceMappingURL=Service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Service.js","sourceRoot":"","sources":["../../src/proxy/Service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,IAAI,CAAA;AAyD1B;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,IAAI,CAAoB,EAAU,EAAE,MAA4B;IAC9E,MAAM,iBAAiB,GAAG,qBAAqB,CAAC,MAAM,CAAC,CAAA;IACvD,OAAO;QACL,EAAE;QACF,OAAO,EAAE,MAAM,CAAC,OAAO;QACvB,MAAM,EAAE,MAAM,CAAC,MAAM;QACrB,cAAc,EAAE,MAAM,CAAC,cAAc;YACnC,CAAC,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C;AAED,SAAS,cAAc,CAAC,QAAkB;IACxC,IAAI,QAAQ,KAAK,IAAI;QAAE,OAAO,IAAI,CAAA;IAClC,MAAM,OAAO,GAAG,OAAO,QAAQ,KAAK,UAAU,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAA;IACxE,IAAI,CAAC,CAAC,WAAW,IAAI,OAAO,CAAC;QAAE,OAAO,EAAE,CAAA;IACxC,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,GAAG,OAAO,CAAC,SAAoC,CAAA;IAChG,MAAM,MAAM,GAAG,CAAC,GAAG,EAAE;QACnB,IAAI,OAAO,IAAI,CAAC,MAAM,KAAK,QAAQ,IAAI,OAAO,IAAI,CAAC,QAAQ,KAAK,QAAQ;YACtE,OAAO,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAA;QACvD,OAAO,IAAI,CAAC,MAAM,CAAA;IACpB,CAAC,CAAC,EAAE,CAAA;IACJ,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,GAAG,CAAC,MAAM,KAAK,SAAS,IAAI,EAAE,MAAM,EAAE,CAAC,EAAE,CAAA;AACnF,CAAC"}
@@ -0,0 +1,7 @@
1
+ export * as Proxy from './Proxy.js';
2
+ export * as Service from './Service.js';
3
+ export { from as custom } from './Service.js';
4
+ export { anthropic } from './services/anthropic.js';
5
+ export { openai } from './services/openai.js';
6
+ export { stripe } from './services/stripe.js';
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/proxy/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,YAAY,CAAA;AACnC,OAAO,KAAK,OAAO,MAAM,cAAc,CAAA;AACvC,OAAO,EAAE,IAAI,IAAI,MAAM,EAAE,MAAM,cAAc,CAAA;AAC7C,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AACnD,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAA;AAC7C,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAA"}
@@ -0,0 +1,7 @@
1
+ export * as Proxy from './Proxy.js';
2
+ export * as Service from './Service.js';
3
+ export { from as custom } from './Service.js';
4
+ export { anthropic } from './services/anthropic.js';
5
+ export { openai } from './services/openai.js';
6
+ export { stripe } from './services/stripe.js';
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/proxy/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,YAAY,CAAA;AACnC,OAAO,KAAK,OAAO,MAAM,cAAc,CAAA;AACvC,OAAO,EAAE,IAAI,IAAI,MAAM,EAAE,MAAM,cAAc,CAAA;AAC7C,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AACnD,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAA;AAC7C,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAA"}
@@ -0,0 +1,3 @@
1
+ export declare function scrub(headers: Headers): Headers;
2
+ export declare function scrubResponse(response: Response): Response;
3
+ //# sourceMappingURL=Headers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Headers.d.ts","sourceRoot":"","sources":["../../../src/proxy/internal/Headers.ts"],"names":[],"mappings":"AAWA,wBAAgB,KAAK,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAiB/C;AAED,wBAAgB,aAAa,CAAC,QAAQ,EAAE,QAAQ,GAAG,QAAQ,CAS1D"}
@@ -0,0 +1,41 @@
1
+ const hopByHopHeaders = new Set([
2
+ 'connection',
3
+ 'keep-alive',
4
+ 'transfer-encoding',
5
+ 'upgrade',
6
+ 'proxy-authenticate',
7
+ 'proxy-authorization',
8
+ 'te',
9
+ 'trailer',
10
+ ]);
11
+ export function scrub(headers) {
12
+ const scrubbed = new Headers();
13
+ for (const [name, value] of headers) {
14
+ const lower = name.toLowerCase();
15
+ if (lower === 'authorization')
16
+ continue;
17
+ if (lower === 'accept-encoding')
18
+ continue;
19
+ if (lower === 'content-length')
20
+ continue;
21
+ if (lower === 'cookie')
22
+ continue;
23
+ if (hopByHopHeaders.has(lower))
24
+ continue;
25
+ if (lower.startsWith('x-forwarded-'))
26
+ continue;
27
+ scrubbed.append(name, value);
28
+ }
29
+ return scrubbed;
30
+ }
31
+ export function scrubResponse(response) {
32
+ const headers = new Headers(response.headers);
33
+ headers.delete('content-encoding');
34
+ headers.delete('content-length');
35
+ return new Response(response.body, {
36
+ status: response.status,
37
+ statusText: response.statusText,
38
+ headers,
39
+ });
40
+ }
41
+ //# sourceMappingURL=Headers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Headers.js","sourceRoot":"","sources":["../../../src/proxy/internal/Headers.ts"],"names":[],"mappings":"AAAA,MAAM,eAAe,GAAG,IAAI,GAAG,CAAC;IAC9B,YAAY;IACZ,YAAY;IACZ,mBAAmB;IACnB,SAAS;IACT,oBAAoB;IACpB,qBAAqB;IACrB,IAAI;IACJ,SAAS;CACV,CAAC,CAAA;AAEF,MAAM,UAAU,KAAK,CAAC,OAAgB;IACpC,MAAM,QAAQ,GAAG,IAAI,OAAO,EAAE,CAAA;IAE9B,KAAK,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,OAAO,EAAE,CAAC;QACpC,MAAM,KAAK,GAAG,IAAI,CAAC,WAAW,EAAE,CAAA;QAEhC,IAAI,KAAK,KAAK,eAAe;YAAE,SAAQ;QACvC,IAAI,KAAK,KAAK,iBAAiB;YAAE,SAAQ;QACzC,IAAI,KAAK,KAAK,gBAAgB;YAAE,SAAQ;QACxC,IAAI,KAAK,KAAK,QAAQ;YAAE,SAAQ;QAChC,IAAI,eAAe,CAAC,GAAG,CAAC,KAAK,CAAC;YAAE,SAAQ;QACxC,IAAI,KAAK,CAAC,UAAU,CAAC,cAAc,CAAC;YAAE,SAAQ;QAE9C,QAAQ,CAAC,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,CAAA;IAC9B,CAAC;IAED,OAAO,QAAQ,CAAA;AACjB,CAAC;AAED,MAAM,UAAU,aAAa,CAAC,QAAkB;IAC9C,MAAM,OAAO,GAAG,IAAI,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAA;IAC7C,OAAO,CAAC,MAAM,CAAC,kBAAkB,CAAC,CAAA;IAClC,OAAO,CAAC,MAAM,CAAC,gBAAgB,CAAC,CAAA;IAChC,OAAO,IAAI,QAAQ,CAAC,QAAQ,CAAC,IAAI,EAAE;QACjC,MAAM,EAAE,QAAQ,CAAC,MAAM;QACvB,UAAU,EAAE,QAAQ,CAAC,UAAU;QAC/B,OAAO;KACR,CAAC,CAAA;AACJ,CAAC"}
@@ -0,0 +1,14 @@
1
+ export declare function pathname(url: URL, basePath?: string): string | null;
2
+ export declare function parse(pathname: string): {
3
+ serviceId: string;
4
+ upstreamPath: string;
5
+ } | null;
6
+ export declare function match(routes: Record<string, unknown>, method: string, path: string): {
7
+ key: string;
8
+ value: unknown;
9
+ } | null;
10
+ export declare function matchPath(routes: Record<string, unknown>, path: string): {
11
+ key: string;
12
+ value: unknown;
13
+ } | null;
14
+ //# sourceMappingURL=Route.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Route.d.ts","sourceRoot":"","sources":["../../../src/proxy/internal/Route.ts"],"names":[],"mappings":"AAEA,wBAAgB,QAAQ,CAAC,GAAG,EAAE,GAAG,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAQnE;AAED,wBAAgB,KAAK,CAAC,QAAQ,EAAE,MAAM,GAAG;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,YAAY,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAO1F;AAED,wBAAgB,KAAK,CACnB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC/B,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,GACX;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,OAAO,CAAA;CAAE,GAAG,IAAI,CAQxC;AAED,wBAAgB,SAAS,CACvB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC/B,IAAI,EAAE,MAAM,GACX;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,OAAO,CAAA;CAAE,GAAG,IAAI,CAOxC"}
@@ -0,0 +1,47 @@
1
+ const httpMethods = new Set(['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'HEAD', 'OPTIONS']);
2
+ export function pathname(url, basePath) {
3
+ let pathname = url.pathname;
4
+ if (basePath) {
5
+ const base = basePath.replace(/\/+$/, '');
6
+ if (!pathname.startsWith(base))
7
+ return null;
8
+ pathname = pathname.slice(base.length);
9
+ }
10
+ return pathname;
11
+ }
12
+ export function parse(pathname) {
13
+ const segments = pathname.split('/').filter(Boolean);
14
+ const serviceId = segments[0];
15
+ if (!serviceId)
16
+ return null;
17
+ const upstreamPath = `/${segments.slice(1).join('/')}`;
18
+ return { serviceId, upstreamPath };
19
+ }
20
+ export function match(routes, method, path) {
21
+ for (const [key, value] of Object.entries(routes)) {
22
+ const { method: routeMethod, pattern } = parseRouteKey(key);
23
+ if (routeMethod && routeMethod !== method.toUpperCase())
24
+ continue;
25
+ const urlPattern = new URLPattern({ pathname: pattern });
26
+ if (urlPattern.test({ pathname: path }))
27
+ return { key, value };
28
+ }
29
+ return null;
30
+ }
31
+ export function matchPath(routes, path) {
32
+ for (const [key, value] of Object.entries(routes)) {
33
+ const { pattern } = parseRouteKey(key);
34
+ const urlPattern = new URLPattern({ pathname: pattern });
35
+ if (urlPattern.test({ pathname: path }))
36
+ return { key, value };
37
+ }
38
+ return null;
39
+ }
40
+ function parseRouteKey(key) {
41
+ const tokens = key.trim().split(/\s+/);
42
+ if (tokens.length >= 2 && httpMethods.has(tokens[0].toUpperCase())) {
43
+ return { method: tokens[0].toUpperCase(), pattern: tokens.slice(1).join(' ') };
44
+ }
45
+ return { method: undefined, pattern: key };
46
+ }
47
+ //# sourceMappingURL=Route.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Route.js","sourceRoot":"","sources":["../../../src/proxy/internal/Route.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,GAAG,IAAI,GAAG,CAAC,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,EAAE,SAAS,CAAC,CAAC,CAAA;AAEzF,MAAM,UAAU,QAAQ,CAAC,GAAQ,EAAE,QAAiB;IAClD,IAAI,QAAQ,GAAG,GAAG,CAAC,QAAQ,CAAA;IAC3B,IAAI,QAAQ,EAAE,CAAC;QACb,MAAM,IAAI,GAAG,QAAQ,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAA;QACzC,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,IAAI,CAAC;YAAE,OAAO,IAAI,CAAA;QAC3C,QAAQ,GAAG,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;IACxC,CAAC;IACD,OAAO,QAAQ,CAAA;AACjB,CAAC;AAED,MAAM,UAAU,KAAK,CAAC,QAAgB;IACpC,MAAM,QAAQ,GAAG,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAA;IACpD,MAAM,SAAS,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAA;IAC7B,IAAI,CAAC,SAAS;QAAE,OAAO,IAAI,CAAA;IAE3B,MAAM,YAAY,GAAG,IAAI,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE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;IACtC,IAAI,MAAM,CAAC,MAAM,IAAI,CAAC,IAAI,WAAW,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAE,CAAC,WAAW,EAAE,CAAC,EAAE,CAAC;QACpE,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,CAAE,CAAC,WAAW,EAAE,EAAE,OAAO,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAA;IACjF,CAAC;IACD,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,GAAG,EAAE,CAAA;AAC5C,CAAC"}
@@ -0,0 +1,29 @@
1
+ import * as Service from '../Service.js';
2
+ /**
3
+ * Creates an Anthropic service definition.
4
+ *
5
+ * Injects `x-api-key` header for upstream authentication.
6
+ * Per-endpoint `apiKey` overrides are supported via `options`.
7
+ *
8
+ * @example
9
+ * ```ts
10
+ * anthropic({
11
+ * apiKey: 'sk-ant-...',
12
+ * routes: {
13
+ * 'POST /v1/messages': mppx.charge({ amount: '0.03' }),
14
+ * 'POST /v1/complete': mppx.charge({ amount: '0.02' }),
15
+ * },
16
+ * })
17
+ * ```
18
+ */
19
+ export declare function anthropic(config: anthropic.Config): Service.Service;
20
+ export declare namespace anthropic {
21
+ type Config = Service.From<{
22
+ /** Anthropic API key. Used as `x-api-key` header. */
23
+ apiKey: string;
24
+ /** Base URL override. Defaults to `'https://api.anthropic.com'`. */
25
+ baseUrl?: string | undefined;
26
+ routes: 'POST /v1/messages' | 'POST /v1/messages/batches' | 'GET /v1/messages/batches' | 'GET /v1/messages/batches/:batchId' | 'POST /v1/complete';
27
+ }>;
28
+ }
29
+ //# sourceMappingURL=anthropic.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"anthropic.d.ts","sourceRoot":"","sources":["../../../src/proxy/services/anthropic.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,eAAe,CAAA;AAExC;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,SAAS,CAAC,MAAM,EAAE,SAAS,CAAC,MAAM,mBAUjD;AAED,MAAM,CAAC,OAAO,WAAW,SAAS,CAAC;IACjC,KAAY,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;QAChC,qDAAqD;QACrD,MAAM,EAAE,MAAM,CAAA;QACd,oEAAoE;QACpE,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;QAC5B,MAAM,EACF,mBAAmB,GACnB,2BAA2B,GAC3B,0BAA0B,GAC1B,mCAAmC,GACnC,mBAAmB,CAAA;KACxB,CAAC,CAAA;CACH"}