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,143 @@
1
+ import { describe, expect, test } from 'vitest'
2
+
3
+ import * as Route from './Route.js'
4
+
5
+ describe('pathname', () => {
6
+ test('behavior: returns pathname without basePath', () => {
7
+ expect(
8
+ Route.pathname(new URL('http://localhost/api/proxy/openai/v1/models'), '/api/proxy'),
9
+ ).toBe('/openai/v1/models')
10
+ })
11
+
12
+ test('behavior: handles basePath with trailing slash', () => {
13
+ expect(
14
+ Route.pathname(new URL('http://localhost/api/proxy/stripe/v1/charges'), '/api/proxy/'),
15
+ ).toBe('/stripe/v1/charges')
16
+ })
17
+
18
+ test('behavior: returns pathname as-is when no basePath', () => {
19
+ expect(Route.pathname(new URL('http://localhost/openai/v1/models'))).toBe('/openai/v1/models')
20
+ })
21
+
22
+ test('error: returns null when basePath does not match', () => {
23
+ expect(
24
+ Route.pathname(new URL('http://localhost/other/openai/v1/models'), '/api/proxy'),
25
+ ).toBeNull()
26
+ })
27
+ })
28
+
29
+ describe('parse', () => {
30
+ test('behavior: extracts serviceId and upstreamPath', () => {
31
+ expect(Route.parse('/openai/v1/chat/completions')).toMatchInlineSnapshot(`
32
+ {
33
+ "serviceId": "openai",
34
+ "upstreamPath": "/v1/chat/completions",
35
+ }
36
+ `)
37
+ })
38
+
39
+ test('behavior: parses anthropic service path', () => {
40
+ expect(Route.parse('/anthropic/v1/messages')).toMatchInlineSnapshot(`
41
+ {
42
+ "serviceId": "anthropic",
43
+ "upstreamPath": "/v1/messages",
44
+ }
45
+ `)
46
+ })
47
+
48
+ test('behavior: returns root upstreamPath when no sub-path', () => {
49
+ expect(Route.parse('/stripe')).toMatchInlineSnapshot(`
50
+ {
51
+ "serviceId": "stripe",
52
+ "upstreamPath": "/",
53
+ }
54
+ `)
55
+ })
56
+
57
+ test('error: returns null for root path', () => {
58
+ expect(Route.parse('/')).toBeNull()
59
+ })
60
+
61
+ test('error: returns null for empty pathname', () => {
62
+ expect(Route.parse('')).toBeNull()
63
+ })
64
+ })
65
+
66
+ describe('match', () => {
67
+ test('behavior: matches exact method and path', () => {
68
+ const routes = { 'POST /v1/chat/completions': 'chat' }
69
+ const result = Route.match(routes, 'POST', '/v1/chat/completions')
70
+ expect(result).toMatchInlineSnapshot(`
71
+ {
72
+ "key": "POST /v1/chat/completions",
73
+ "value": "chat",
74
+ }
75
+ `)
76
+ })
77
+
78
+ test('behavior: matches wildcard pattern', () => {
79
+ const routes = { 'POST /v1/images/*': 'images' }
80
+ const result = Route.match(routes, 'POST', '/v1/images/generations')
81
+ expect(result).toMatchInlineSnapshot(`
82
+ {
83
+ "key": "POST /v1/images/*",
84
+ "value": "images",
85
+ }
86
+ `)
87
+ })
88
+
89
+ test('behavior: method-less pattern matches any method', () => {
90
+ const routes = { '/v1/*': 'catchall' }
91
+ expect(Route.match(routes, 'GET', '/v1/models')).toMatchInlineSnapshot(`
92
+ {
93
+ "key": "/v1/*",
94
+ "value": "catchall",
95
+ }
96
+ `)
97
+ expect(Route.match(routes, 'POST', '/v1/completions')).toMatchInlineSnapshot(`
98
+ {
99
+ "key": "/v1/*",
100
+ "value": "catchall",
101
+ }
102
+ `)
103
+ })
104
+
105
+ test('behavior: matches named params', () => {
106
+ const routes = { 'GET /v1/users/:id': 'user' }
107
+ const result = Route.match(routes, 'GET', '/v1/users/123')
108
+ expect(result).toMatchInlineSnapshot(`
109
+ {
110
+ "key": "GET /v1/users/:id",
111
+ "value": "user",
112
+ }
113
+ `)
114
+ })
115
+
116
+ test('behavior: first match wins', () => {
117
+ const routes = {
118
+ 'POST /v1/chat/completions': 'specific',
119
+ 'POST /v1/*': 'general',
120
+ }
121
+ expect(Route.match(routes, 'POST', '/v1/chat/completions')?.value).toBe('specific')
122
+ })
123
+
124
+ test('behavior: case insensitive method matching', () => {
125
+ const routes = { 'POST /v1/chat': 'chat' }
126
+ expect(Route.match(routes, 'post', '/v1/chat')).toMatchInlineSnapshot(`
127
+ {
128
+ "key": "POST /v1/chat",
129
+ "value": "chat",
130
+ }
131
+ `)
132
+ })
133
+
134
+ test('error: returns null when no match', () => {
135
+ const routes = { 'POST /v1/chat/completions': 'chat' }
136
+ expect(Route.match(routes, 'POST', '/v2/unknown')).toBeNull()
137
+ })
138
+
139
+ test('error: returns null for wrong method', () => {
140
+ const routes = { 'POST /v1/chat/completions': 'chat' }
141
+ expect(Route.match(routes, 'GET', '/v1/chat/completions')).toBeNull()
142
+ })
143
+ })
@@ -0,0 +1,54 @@
1
+ const httpMethods = new Set(['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'HEAD', 'OPTIONS'])
2
+
3
+ export function pathname(url: URL, basePath?: string): string | null {
4
+ let pathname = url.pathname
5
+ if (basePath) {
6
+ const base = basePath.replace(/\/+$/, '')
7
+ if (!pathname.startsWith(base)) return null
8
+ pathname = pathname.slice(base.length)
9
+ }
10
+ return pathname
11
+ }
12
+
13
+ export function parse(pathname: string): { serviceId: string; upstreamPath: string } | null {
14
+ const segments = pathname.split('/').filter(Boolean)
15
+ const serviceId = segments[0]
16
+ if (!serviceId) return null
17
+
18
+ const upstreamPath = `/${segments.slice(1).join('/')}`
19
+ return { serviceId, upstreamPath }
20
+ }
21
+
22
+ export function match(
23
+ routes: Record<string, unknown>,
24
+ method: string,
25
+ path: string,
26
+ ): { key: string; value: unknown } | null {
27
+ for (const [key, value] of Object.entries(routes)) {
28
+ const { method: routeMethod, pattern } = parseRouteKey(key)
29
+ if (routeMethod && routeMethod !== method.toUpperCase()) continue
30
+ const urlPattern = new URLPattern({ pathname: pattern })
31
+ if (urlPattern.test({ pathname: path })) return { key, value }
32
+ }
33
+ return null
34
+ }
35
+
36
+ export function matchPath(
37
+ routes: Record<string, unknown>,
38
+ path: string,
39
+ ): { key: string; value: unknown } | null {
40
+ for (const [key, value] of Object.entries(routes)) {
41
+ const { pattern } = parseRouteKey(key)
42
+ const urlPattern = new URLPattern({ pathname: pattern })
43
+ if (urlPattern.test({ pathname: path })) return { key, value }
44
+ }
45
+ return null
46
+ }
47
+
48
+ function parseRouteKey(key: string): { method: string | undefined; pattern: string } {
49
+ const tokens = key.trim().split(/\s+/)
50
+ if (tokens.length >= 2 && httpMethods.has(tokens[0]!.toUpperCase())) {
51
+ return { method: tokens[0]!.toUpperCase(), pattern: tokens.slice(1).join(' ') }
52
+ }
53
+ return { method: undefined, pattern: key }
54
+ }
@@ -0,0 +1,45 @@
1
+ import * as Service from '../Service.js'
2
+
3
+ /**
4
+ * Creates an Anthropic service definition.
5
+ *
6
+ * Injects `x-api-key` header for upstream authentication.
7
+ * Per-endpoint `apiKey` overrides are supported via `options`.
8
+ *
9
+ * @example
10
+ * ```ts
11
+ * anthropic({
12
+ * apiKey: 'sk-ant-...',
13
+ * routes: {
14
+ * 'POST /v1/messages': mppx.charge({ amount: '0.03' }),
15
+ * 'POST /v1/complete': mppx.charge({ amount: '0.02' }),
16
+ * },
17
+ * })
18
+ * ```
19
+ */
20
+ export function anthropic(config: anthropic.Config) {
21
+ return Service.from<anthropic.Config>('anthropic', {
22
+ baseUrl: config.baseUrl ?? 'https://api.anthropic.com',
23
+ rewriteRequest(request, ctx) {
24
+ const apiKey = ctx.apiKey ?? config.apiKey
25
+ request.headers.set('x-api-key', apiKey)
26
+ return request
27
+ },
28
+ routes: config.routes,
29
+ })
30
+ }
31
+
32
+ export declare namespace anthropic {
33
+ export type Config = Service.From<{
34
+ /** Anthropic API key. Used as `x-api-key` header. */
35
+ apiKey: string
36
+ /** Base URL override. Defaults to `'https://api.anthropic.com'`. */
37
+ baseUrl?: string | undefined
38
+ routes:
39
+ | 'POST /v1/messages'
40
+ | 'POST /v1/messages/batches'
41
+ | 'GET /v1/messages/batches'
42
+ | 'GET /v1/messages/batches/:batchId'
43
+ | 'POST /v1/complete'
44
+ }>
45
+ }
@@ -0,0 +1,97 @@
1
+ import { Receipt } from 'mppx'
2
+ import { Mppx as Mppx_client, tempo as tempo_client } from 'mppx/client'
3
+ import { Mppx as Mppx_server, tempo as tempo_server } from 'mppx/server'
4
+ import { afterEach, describe, expect, test } from 'vitest'
5
+ import * as Http from '~test/Http.js'
6
+ import { accounts, asset, client } from '~test/tempo/viem.js'
7
+ import * as ApiProxy from '../Proxy.js'
8
+ import { openai } from './openai.js'
9
+
10
+ const apiKey = process.env.VITE_OPENAI_API_KEY
11
+ if (!apiKey) console.warn('OPENAI_API_KEY not set — openai proxy tests will be skipped')
12
+
13
+ const mppx_server = Mppx_server.create({
14
+ methods: [
15
+ tempo_server({
16
+ account: accounts[0],
17
+ currency: asset,
18
+ getClient: () => client,
19
+ }),
20
+ ],
21
+ })
22
+
23
+ const mppx_client = Mppx_client.create({
24
+ polyfill: false,
25
+ methods: [
26
+ tempo_client({
27
+ account: accounts[1],
28
+ getClient: () => client,
29
+ }),
30
+ ],
31
+ })
32
+
33
+ let proxyServer: Awaited<ReturnType<typeof Http.createServer>> | undefined
34
+
35
+ afterEach(() => proxyServer?.close())
36
+
37
+ describe.skipIf(!apiKey)('openai', () => {
38
+ test('behavior: proxies GET /v1/models with charge', async () => {
39
+ const proxy = ApiProxy.create({
40
+ services: [
41
+ openai({
42
+ apiKey: apiKey!,
43
+ routes: {
44
+ 'GET /v1/models': mppx_server.charge({ amount: '1', decimals: 6 }),
45
+ },
46
+ }),
47
+ ],
48
+ })
49
+ proxyServer = await Http.createServer(proxy.listener)
50
+
51
+ const res = await mppx_client.fetch(`${proxyServer.url}/openai/v1/models`)
52
+ expect(res.status).toBe(200)
53
+
54
+ const body = (await res.json()) as { data: unknown[] }
55
+ expect(body.data).toBeDefined()
56
+ expect(Array.isArray(body.data)).toBe(true)
57
+
58
+ const receipt = Receipt.fromResponse(res)
59
+ expect(receipt.status).toBe('success')
60
+ expect(receipt.method).toBe('tempo')
61
+ })
62
+
63
+ test('behavior: returns 402 without credential', async () => {
64
+ const proxy = ApiProxy.create({
65
+ services: [
66
+ openai({
67
+ apiKey: apiKey!,
68
+ routes: {
69
+ 'GET /v1/models': mppx_server.charge({ amount: '1', decimals: 6 }),
70
+ },
71
+ }),
72
+ ],
73
+ })
74
+ proxyServer = await Http.createServer(proxy.listener)
75
+
76
+ const res = await fetch(`${proxyServer.url}/openai/v1/models`)
77
+ expect(res.status).toBe(402)
78
+ expect(res.headers.get('WWW-Authenticate')).toContain('Payment')
79
+ })
80
+
81
+ test('behavior: returns 404 for unmatched route', async () => {
82
+ const proxy = ApiProxy.create({
83
+ services: [
84
+ openai({
85
+ apiKey: apiKey!,
86
+ routes: {
87
+ 'GET /v1/models': mppx_server.charge({ amount: '1', decimals: 6 }),
88
+ },
89
+ }),
90
+ ],
91
+ })
92
+ proxyServer = await Http.createServer(proxy.listener)
93
+
94
+ const res = await fetch(`${proxyServer.url}/openai/v1/unknown`)
95
+ expect(res.status).toBe(404)
96
+ })
97
+ })
@@ -0,0 +1,48 @@
1
+ import * as Service from '../Service.js'
2
+
3
+ /**
4
+ * Creates an OpenAI service definition.
5
+ *
6
+ * Injects `Authorization: Bearer` header for upstream authentication.
7
+ * Per-endpoint `apiKey` overrides are supported via `options`.
8
+ *
9
+ * @example
10
+ * ```ts
11
+ * openai({
12
+ * apiKey: 'sk-...',
13
+ * routes: {
14
+ * 'POST /v1/chat/completions': mppx.charge({ amount: '0.05' }),
15
+ * 'GET /v1/models': true,
16
+ * },
17
+ * })
18
+ * ```
19
+ */
20
+ export function openai(config: openai.Config) {
21
+ return Service.from<openai.Config>('openai', {
22
+ baseUrl: config.baseUrl ?? 'https://api.openai.com',
23
+ rewriteRequest(request, ctx) {
24
+ const apiKey = ctx.apiKey ?? config.apiKey
25
+ request.headers.set('Authorization', `Bearer ${apiKey}`)
26
+ return request
27
+ },
28
+ routes: config.routes,
29
+ })
30
+ }
31
+
32
+ export declare namespace openai {
33
+ export type Config = Service.From<{
34
+ /** OpenAI API key. Used as `Authorization: Bearer` header. */
35
+ apiKey: string
36
+ /** Base URL override. Defaults to `'https://api.openai.com'`. */
37
+ baseUrl?: string | undefined
38
+ routes:
39
+ | 'POST /v1/chat/completions'
40
+ | 'POST /v1/completions'
41
+ | 'POST /v1/embeddings'
42
+ | 'POST /v1/images/generations'
43
+ | 'POST /v1/images/edits'
44
+ | 'POST /v1/images/variations'
45
+ | 'POST /v1/audio/transcriptions'
46
+ | 'POST /v1/audio/translations'
47
+ }>
48
+ }
@@ -0,0 +1,49 @@
1
+ import * as Service from '../Service.js'
2
+
3
+ /**
4
+ * Creates a Stripe service definition.
5
+ *
6
+ * Injects `Authorization: Basic` header (API key as username) for upstream authentication.
7
+ * Per-endpoint `apiKey` overrides are supported via `options`.
8
+ *
9
+ * @example
10
+ * ```ts
11
+ * stripe({
12
+ * apiKey: 'sk-...',
13
+ * routes: {
14
+ * 'POST /v1/charges': mppx.charge({ amount: '1' }),
15
+ * 'GET /v1/customers/:id': true,
16
+ * },
17
+ * })
18
+ * ```
19
+ */
20
+ export function stripe(config: stripe.Config) {
21
+ return Service.from<stripe.Config>('stripe', {
22
+ baseUrl: config.baseUrl ?? 'https://api.stripe.com',
23
+ rewriteRequest(request, ctx) {
24
+ const apiKey = ctx.apiKey ?? config.apiKey
25
+ request.headers.set('Authorization', `Basic ${btoa(`${apiKey}:`)}`)
26
+ return request
27
+ },
28
+ routes: config.routes,
29
+ })
30
+ }
31
+
32
+ export declare namespace stripe {
33
+ export type Config = Service.From<{
34
+ /** Stripe API key. Used as Basic auth username. */
35
+ apiKey: string
36
+ /** Base URL override. Defaults to `'https://api.stripe.com'`. */
37
+ baseUrl?: string | undefined
38
+ routes:
39
+ | 'POST /v1/charges'
40
+ | 'POST /v1/customers'
41
+ | 'GET /v1/customers/:id'
42
+ | 'POST /v1/payment_intents'
43
+ | 'GET /v1/payment_intents/:id'
44
+ | 'POST /v1/subscriptions'
45
+ | 'GET /v1/subscriptions/:id'
46
+ | 'POST /v1/invoices'
47
+ | 'GET /v1/invoices/:id'
48
+ }>
49
+ }
@@ -0,0 +1,2 @@
1
+ export { stripe } from '../stripe/server/MethodIntents.js'
2
+ export { tempo } from '../tempo/server/MethodIntents.js'