gemi 0.111.0 → 0.112.1

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 (265) hide show
  1. package/dist/ai/Agent.d.ts +54 -1
  2. package/dist/ai/Agent.d.ts.map +1 -1
  3. package/dist/ai/AgentController.d.ts +41 -0
  4. package/dist/ai/AgentController.d.ts.map +1 -1
  5. package/dist/ai/client/index.d.ts +1 -1
  6. package/dist/ai/client/index.d.ts.map +1 -1
  7. package/dist/ai/contextCompaction.d.ts +247 -0
  8. package/dist/ai/contextCompaction.d.ts.map +1 -0
  9. package/dist/ai/contextWindow.d.ts +18 -0
  10. package/dist/ai/contextWindow.d.ts.map +1 -1
  11. package/dist/ai/index.d.ts +5 -1
  12. package/dist/ai/index.d.ts.map +1 -1
  13. package/dist/ai/index.js +93 -14
  14. package/dist/ai/index.js.map +16 -10
  15. package/dist/ai/jobs/AgentJob.d.ts +259 -0
  16. package/dist/ai/jobs/AgentJob.d.ts.map +1 -0
  17. package/dist/ai/jobs/AgentJobDeadlineSweep.d.ts +18 -0
  18. package/dist/ai/jobs/AgentJobDeadlineSweep.d.ts.map +1 -0
  19. package/dist/ai/jobs/AgentJobStore.d.ts +141 -0
  20. package/dist/ai/jobs/AgentJobStore.d.ts.map +1 -0
  21. package/dist/ai/jobs/DatabaseAgentJobStore.d.ts +82 -0
  22. package/dist/ai/jobs/DatabaseAgentJobStore.d.ts.map +1 -0
  23. package/dist/ai/jobs/contextBlock.d.ts +31 -0
  24. package/dist/ai/jobs/contextBlock.d.ts.map +1 -0
  25. package/dist/ai/jobs/index.d.ts +6 -0
  26. package/dist/ai/jobs/index.d.ts.map +1 -0
  27. package/dist/ai/jobs/overlay.d.ts +49 -0
  28. package/dist/ai/jobs/overlay.d.ts.map +1 -0
  29. package/dist/ai/providers/request.d.ts.map +1 -1
  30. package/dist/ai/store/Attachments.d.ts +6 -0
  31. package/dist/ai/store/Attachments.d.ts.map +1 -1
  32. package/dist/ai/store/MemoryAgentStore.d.ts +3 -0
  33. package/dist/ai/store/MemoryAgentStore.d.ts.map +1 -1
  34. package/dist/ai/types.d.ts +28 -0
  35. package/dist/ai/types.d.ts.map +1 -1
  36. package/dist/app/index.js +1 -1
  37. package/dist/bin/gemi.js +13 -2
  38. package/dist/bin/gemi.js.map +4 -4
  39. package/dist/bun/plugin.js +1 -1
  40. package/dist/bun/preload.js +1 -1
  41. package/dist/{chunk-30xjcyzh.js → chunk-0z2h35d7.js} +2 -2
  42. package/dist/{chunk-30xjcyzh.js.map → chunk-0z2h35d7.js.map} +1 -1
  43. package/dist/{chunk-358sdcx9.js → chunk-15a1mrdv.js} +2 -2
  44. package/dist/{chunk-358sdcx9.js.map → chunk-15a1mrdv.js.map} +1 -1
  45. package/dist/{chunk-hf7a51s3.js → chunk-18c3y8m3.js} +2 -2
  46. package/dist/{chunk-hf7a51s3.js.map → chunk-18c3y8m3.js.map} +1 -1
  47. package/dist/{chunk-tq85n8zh.js → chunk-1pvkw2pq.js} +2 -2
  48. package/dist/{chunk-tq85n8zh.js.map → chunk-1pvkw2pq.js.map} +1 -1
  49. package/dist/{chunk-8afxrmdc.js → chunk-2taa0brj.js} +2 -2
  50. package/dist/{chunk-8afxrmdc.js.map → chunk-2taa0brj.js.map} +1 -1
  51. package/dist/{chunk-5cygrbxv.js → chunk-30yg31sz.js} +2 -2
  52. package/dist/{chunk-5cygrbxv.js.map → chunk-30yg31sz.js.map} +1 -1
  53. package/dist/{chunk-3y8q8x11.js → chunk-3z9vhjd7.js} +2 -2
  54. package/dist/{chunk-3y8q8x11.js.map → chunk-3z9vhjd7.js.map} +1 -1
  55. package/dist/chunk-4sb1484x.js +46 -0
  56. package/dist/{chunk-h3864a8z.js.map → chunk-4sb1484x.js.map} +13 -4
  57. package/dist/{chunk-0sjh5v1n.js → chunk-53bek7sp.js} +1 -1
  58. package/dist/{chunk-xkc7ftnq.js → chunk-57edag57.js} +3 -3
  59. package/dist/{chunk-xkc7ftnq.js.map → chunk-57edag57.js.map} +1 -1
  60. package/dist/{chunk-ddr4qvvt.js → chunk-5az0mq4p.js} +3 -3
  61. package/dist/{chunk-ddr4qvvt.js.map → chunk-5az0mq4p.js.map} +1 -1
  62. package/dist/{chunk-nsvktvp4.js → chunk-5waxjsvv.js} +2 -2
  63. package/dist/{chunk-nsvktvp4.js.map → chunk-5waxjsvv.js.map} +1 -1
  64. package/dist/{chunk-rfcygmf5.js → chunk-6w79zajj.js} +3 -3
  65. package/dist/{chunk-rfcygmf5.js.map → chunk-6w79zajj.js.map} +1 -1
  66. package/dist/{chunk-gb37722w.js → chunk-75ptmewf.js} +3 -3
  67. package/dist/{chunk-gb37722w.js.map → chunk-75ptmewf.js.map} +1 -1
  68. package/dist/{chunk-pyj7cd9t.js → chunk-851k0b26.js} +2 -2
  69. package/dist/{chunk-pyj7cd9t.js.map → chunk-851k0b26.js.map} +1 -1
  70. package/dist/{chunk-m6ystvtk.js → chunk-8reepafh.js} +2 -2
  71. package/dist/{chunk-m6ystvtk.js.map → chunk-8reepafh.js.map} +1 -1
  72. package/dist/{chunk-nvv9wej6.js → chunk-9hr0bcfy.js} +3 -3
  73. package/dist/{chunk-nvv9wej6.js.map → chunk-9hr0bcfy.js.map} +1 -1
  74. package/dist/{chunk-yqavgpwd.js → chunk-a9q2cr4w.js} +2 -2
  75. package/dist/{chunk-yqavgpwd.js.map → chunk-a9q2cr4w.js.map} +1 -1
  76. package/dist/{chunk-cy5qp6mz.js → chunk-amvy4r59.js} +2 -2
  77. package/dist/{chunk-cy5qp6mz.js.map → chunk-amvy4r59.js.map} +1 -1
  78. package/dist/{chunk-twnn7r66.js → chunk-b1mk12xg.js} +2 -2
  79. package/dist/{chunk-twnn7r66.js.map → chunk-b1mk12xg.js.map} +1 -1
  80. package/dist/{chunk-a6453d9s.js → chunk-b7cqwcbm.js} +2 -2
  81. package/dist/{chunk-a6453d9s.js.map → chunk-b7cqwcbm.js.map} +1 -1
  82. package/dist/{chunk-nncz308h.js → chunk-b7qjp7r1.js} +2 -2
  83. package/dist/{chunk-nncz308h.js.map → chunk-b7qjp7r1.js.map} +1 -1
  84. package/dist/chunk-beks65me.js +19 -0
  85. package/dist/{chunk-mb7q7s0a.js.map → chunk-beks65me.js.map} +3 -4
  86. package/dist/chunk-bf1ets45.js +5 -0
  87. package/dist/{chunk-11fsn5mr.js.map → chunk-bf1ets45.js.map} +4 -3
  88. package/dist/{chunk-9rchedr4.js → chunk-bhw7k8vp.js} +2 -2
  89. package/dist/{chunk-9rchedr4.js.map → chunk-bhw7k8vp.js.map} +1 -1
  90. package/dist/{chunk-k1vw22t2.js → chunk-ck0v2kzw.js} +2 -2
  91. package/dist/{chunk-k1vw22t2.js.map → chunk-ck0v2kzw.js.map} +1 -1
  92. package/dist/{chunk-6vr7f5fq.js → chunk-csbc1fxa.js} +3 -3
  93. package/dist/{chunk-6vr7f5fq.js.map → chunk-csbc1fxa.js.map} +1 -1
  94. package/dist/{chunk-kf71mjxa.js → chunk-d0trs736.js} +3 -3
  95. package/dist/{chunk-kf71mjxa.js.map → chunk-d0trs736.js.map} +1 -1
  96. package/dist/{chunk-zhs1r1z0.js → chunk-d8ekyng4.js} +3 -3
  97. package/dist/{chunk-zhs1r1z0.js.map → chunk-d8ekyng4.js.map} +1 -1
  98. package/dist/chunk-d9an2nra.js +5 -0
  99. package/dist/{chunk-hn67spz6.js.map → chunk-d9an2nra.js.map} +1 -1
  100. package/dist/{chunk-0d9qsmx2.js → chunk-dan79jab.js} +2 -2
  101. package/dist/{chunk-0d9qsmx2.js.map → chunk-dan79jab.js.map} +1 -1
  102. package/dist/{chunk-1yx2e0bh.js → chunk-ddad3902.js} +2 -2
  103. package/dist/{chunk-1yx2e0bh.js.map → chunk-ddad3902.js.map} +1 -1
  104. package/dist/{chunk-3cg7y62b.js → chunk-dm59ze55.js} +2 -2
  105. package/dist/{chunk-3cg7y62b.js.map → chunk-dm59ze55.js.map} +1 -1
  106. package/dist/{chunk-wvsv1jgg.js → chunk-dx7wpz5b.js} +2 -2
  107. package/dist/{chunk-wvsv1jgg.js.map → chunk-dx7wpz5b.js.map} +1 -1
  108. package/dist/{chunk-q9s7kwgt.js → chunk-eazqda9z.js} +3 -3
  109. package/dist/{chunk-q9s7kwgt.js.map → chunk-eazqda9z.js.map} +1 -1
  110. package/dist/{chunk-td8tha3j.js → chunk-es487acc.js} +1 -1
  111. package/dist/{chunk-9s851qz8.js → chunk-et3vhkbf.js} +2 -2
  112. package/dist/{chunk-9s851qz8.js.map → chunk-et3vhkbf.js.map} +1 -1
  113. package/dist/{chunk-qd2v93y4.js → chunk-f1y8eggf.js} +2 -2
  114. package/dist/{chunk-qd2v93y4.js.map → chunk-f1y8eggf.js.map} +1 -1
  115. package/dist/{chunk-1pem26zc.js → chunk-ga7c7tq0.js} +3 -3
  116. package/dist/{chunk-1pem26zc.js.map → chunk-ga7c7tq0.js.map} +1 -1
  117. package/dist/{chunk-c098fzvk.js → chunk-gcs9ydjv.js} +2 -2
  118. package/dist/{chunk-c098fzvk.js.map → chunk-gcs9ydjv.js.map} +1 -1
  119. package/dist/{chunk-bn5yn731.js → chunk-hfyxvdjj.js} +2 -2
  120. package/dist/{chunk-bn5yn731.js.map → chunk-hfyxvdjj.js.map} +1 -1
  121. package/dist/chunk-j0sncgxc.js +14 -0
  122. package/dist/{chunk-mn5xw79b.js.map → chunk-j0sncgxc.js.map} +6 -5
  123. package/dist/{chunk-p7r2w4qw.js → chunk-j9jqxv1d.js} +3 -3
  124. package/dist/{chunk-p7r2w4qw.js.map → chunk-j9jqxv1d.js.map} +1 -1
  125. package/dist/{chunk-jbrwt3cs.js → chunk-jdtn0zk2.js} +4 -4
  126. package/dist/{chunk-jbrwt3cs.js.map → chunk-jdtn0zk2.js.map} +1 -1
  127. package/dist/{chunk-s6jjy4y9.js → chunk-jn59bsww.js} +2 -2
  128. package/dist/{chunk-s6jjy4y9.js.map → chunk-jn59bsww.js.map} +1 -1
  129. package/dist/chunk-jn8hh25v.js +24 -0
  130. package/dist/{chunk-wqvvjd5r.js.map → chunk-jn8hh25v.js.map} +2 -2
  131. package/dist/chunk-k7rbkhhw.js +6 -0
  132. package/dist/{chunk-tdsfke9q.js.map → chunk-k7rbkhhw.js.map} +2 -2
  133. package/dist/{chunk-he7z7y9j.js → chunk-kk502yk2.js} +2 -2
  134. package/dist/{chunk-he7z7y9j.js.map → chunk-kk502yk2.js.map} +1 -1
  135. package/dist/{chunk-wsttx9rg.js → chunk-mrdarm2q.js} +2 -2
  136. package/dist/{chunk-wsttx9rg.js.map → chunk-mrdarm2q.js.map} +1 -1
  137. package/dist/chunk-mvtgx1mr.js +4 -0
  138. package/dist/{chunk-x78jrs4y.js.map → chunk-mvtgx1mr.js.map} +2 -2
  139. package/dist/{chunk-et4pv1b1.js → chunk-mx9y9mtx.js} +1 -1
  140. package/dist/{chunk-cttmy1jp.js → chunk-p2fhtf5r.js} +3 -3
  141. package/dist/{chunk-cttmy1jp.js.map → chunk-p2fhtf5r.js.map} +1 -1
  142. package/dist/{chunk-w7jsh3xd.js → chunk-qtbf3w6w.js} +2 -2
  143. package/dist/{chunk-w7jsh3xd.js.map → chunk-qtbf3w6w.js.map} +1 -1
  144. package/dist/chunk-qx87cdfg.js +5 -0
  145. package/dist/chunk-qx87cdfg.js.map +10 -0
  146. package/dist/{chunk-1kr25rcg.js → chunk-qyp652jz.js} +3 -3
  147. package/dist/{chunk-1kr25rcg.js.map → chunk-qyp652jz.js.map} +1 -1
  148. package/dist/{chunk-8b2tw2yp.js → chunk-rend2sbk.js} +1 -1
  149. package/dist/chunk-rx2shb3t.js +25 -0
  150. package/dist/chunk-rx2shb3t.js.map +19 -0
  151. package/dist/{chunk-mwqg079k.js → chunk-ryzcfxq7.js} +2 -2
  152. package/dist/{chunk-mwqg079k.js.map → chunk-ryzcfxq7.js.map} +1 -1
  153. package/dist/{chunk-7tx5y712.js → chunk-s9rfgxj5.js} +2 -2
  154. package/dist/{chunk-7tx5y712.js.map → chunk-s9rfgxj5.js.map} +1 -1
  155. package/dist/{chunk-1c1d0e60.js → chunk-scbvv2e4.js} +3 -3
  156. package/dist/{chunk-1c1d0e60.js.map → chunk-scbvv2e4.js.map} +1 -1
  157. package/dist/{chunk-1bkr5wnt.js → chunk-tb126j80.js} +2 -2
  158. package/dist/{chunk-1bkr5wnt.js.map → chunk-tb126j80.js.map} +1 -1
  159. package/dist/{chunk-pwmgqq7z.js → chunk-teny6xkw.js} +2 -2
  160. package/dist/{chunk-pwmgqq7z.js.map → chunk-teny6xkw.js.map} +1 -1
  161. package/dist/{chunk-09ypnhjv.js → chunk-tmrmwthr.js} +2 -2
  162. package/dist/{chunk-09ypnhjv.js.map → chunk-tmrmwthr.js.map} +1 -1
  163. package/dist/{chunk-h4sw6nt3.js → chunk-vgdcz7tk.js} +3 -3
  164. package/dist/{chunk-h4sw6nt3.js.map → chunk-vgdcz7tk.js.map} +1 -1
  165. package/dist/{chunk-xk930yaw.js → chunk-wexs11yy.js} +2 -2
  166. package/dist/{chunk-xk930yaw.js.map → chunk-wexs11yy.js.map} +1 -1
  167. package/dist/{chunk-k1xt2tw7.js → chunk-xs4c2nvz.js} +2 -2
  168. package/dist/{chunk-k1xt2tw7.js.map → chunk-xs4c2nvz.js.map} +1 -1
  169. package/dist/{chunk-1va15sfq.js → chunk-xv74rhay.js} +2 -2
  170. package/dist/{chunk-1va15sfq.js.map → chunk-xv74rhay.js.map} +1 -1
  171. package/dist/{chunk-sq2wkynk.js → chunk-yv1psptb.js} +2 -2
  172. package/dist/{chunk-sq2wkynk.js.map → chunk-yv1psptb.js.map} +1 -1
  173. package/dist/{chunk-tk5q8hkv.js → chunk-zfter1x0.js} +4 -4
  174. package/dist/{chunk-tk5q8hkv.js.map → chunk-zfter1x0.js.map} +1 -1
  175. package/dist/client/ClientRouter.d.ts.map +1 -1
  176. package/dist/client/index.d.ts +2 -0
  177. package/dist/client/index.d.ts.map +1 -1
  178. package/dist/client/index.js +215 -2
  179. package/dist/client/index.js.map +1 -1
  180. package/dist/client/useSubscription.d.ts +70 -0
  181. package/dist/client/useSubscription.d.ts.map +1 -0
  182. package/dist/config/index.js +1 -1
  183. package/dist/console/run.js +2 -2
  184. package/dist/console/run.js.map +2 -2
  185. package/dist/container/index.js +2 -2
  186. package/dist/container/index.js.map +1 -1
  187. package/dist/database/index.js +2 -2
  188. package/dist/database/index.js.map +1 -1
  189. package/dist/email/index.js +2 -2
  190. package/dist/email/index.js.map +1 -1
  191. package/dist/facades/ChangeFeed.d.ts +42 -0
  192. package/dist/facades/ChangeFeed.d.ts.map +1 -0
  193. package/dist/facades/index.d.ts +1 -0
  194. package/dist/facades/index.d.ts.map +1 -1
  195. package/dist/facades/index.js +2 -2
  196. package/dist/facades/index.js.map +1 -1
  197. package/dist/foundation/index.js +2 -2
  198. package/dist/foundation/index.js.map +1 -1
  199. package/dist/http/ResourcePolicy.d.ts +141 -0
  200. package/dist/http/ResourcePolicy.d.ts.map +1 -0
  201. package/dist/http/errors.d.ts +13 -0
  202. package/dist/http/errors.d.ts.map +1 -1
  203. package/dist/http/index.d.ts +2 -1
  204. package/dist/http/index.d.ts.map +1 -1
  205. package/dist/http/index.js +2 -2
  206. package/dist/http/index.js.map +1 -1
  207. package/dist/i18n/dictionaryRuntime.js +2 -2
  208. package/dist/i18n/dictionaryRuntime.js.map +1 -1
  209. package/dist/i18n/index.js +2 -2
  210. package/dist/i18n/index.js.map +2 -2
  211. package/dist/kernel/index.js +3 -3
  212. package/dist/kernel/index.js.map +3 -3
  213. package/dist/kernel/providers.d.ts.map +1 -1
  214. package/dist/orm/index.js +2 -2
  215. package/dist/orm/index.js.map +1 -1
  216. package/dist/server/index.js +2 -2
  217. package/dist/server/index.js.map +1 -1
  218. package/dist/services/change-feed/ChangeFeedDriver.d.ts +94 -0
  219. package/dist/services/change-feed/ChangeFeedDriver.d.ts.map +1 -0
  220. package/dist/services/change-feed/ChangeFeedManager.d.ts +166 -0
  221. package/dist/services/change-feed/ChangeFeedManager.d.ts.map +1 -0
  222. package/dist/services/change-feed/ChangeFeedServiceProvider.d.ts +11 -0
  223. package/dist/services/change-feed/ChangeFeedServiceProvider.d.ts.map +1 -0
  224. package/dist/services/change-feed/DatabaseChangeFeedDriver.d.ts +84 -0
  225. package/dist/services/change-feed/DatabaseChangeFeedDriver.d.ts.map +1 -0
  226. package/dist/services/change-feed/MemoryChangeFeedDriver.d.ts +26 -0
  227. package/dist/services/change-feed/MemoryChangeFeedDriver.d.ts.map +1 -0
  228. package/dist/services/change-feed/changeFeedDriverContract.d.ts +8 -0
  229. package/dist/services/change-feed/changeFeedDriverContract.d.ts.map +1 -0
  230. package/dist/services/change-feed/config.d.ts +42 -0
  231. package/dist/services/change-feed/config.d.ts.map +1 -0
  232. package/dist/services/change-feed/cursor.d.ts +17 -0
  233. package/dist/services/change-feed/cursor.d.ts.map +1 -0
  234. package/dist/services/change-feed/postgresListen.d.ts +30 -0
  235. package/dist/services/change-feed/postgresListen.d.ts.map +1 -0
  236. package/dist/services/change-feed/stream.d.ts +16 -0
  237. package/dist/services/change-feed/stream.d.ts.map +1 -0
  238. package/dist/services/change-feed/wire.d.ts +20 -0
  239. package/dist/services/change-feed/wire.d.ts.map +1 -0
  240. package/dist/services/index.d.ts +9 -0
  241. package/dist/services/index.d.ts.map +1 -1
  242. package/dist/services/index.js +3 -3
  243. package/dist/services/index.js.map +2 -2
  244. package/dist/services/queue/work.js +2 -2
  245. package/dist/services/queue/work.js.map +1 -1
  246. package/dist/services/router/ViewRouteDispatcher.d.ts +16 -0
  247. package/dist/services/router/ViewRouteDispatcher.d.ts.map +1 -1
  248. package/dist/stats/route-table.js +1 -1
  249. package/dist/support/index.js +2 -2
  250. package/dist/support/index.js.map +1 -1
  251. package/dist/vitest/index.js +1 -1
  252. package/package.json +6 -2
  253. package/skills/gemi-react-best-practices/rules/controller-authorize-every-tenant-read.md +16 -1
  254. package/dist/chunk-11fsn5mr.js +0 -5
  255. package/dist/chunk-h3864a8z.js +0 -17
  256. package/dist/chunk-hn67spz6.js +0 -5
  257. package/dist/chunk-mb7q7s0a.js +0 -19
  258. package/dist/chunk-mn5xw79b.js +0 -9
  259. package/dist/chunk-tdsfke9q.js +0 -6
  260. package/dist/chunk-wqvvjd5r.js +0 -24
  261. package/dist/chunk-x78jrs4y.js +0 -4
  262. /package/dist/{chunk-0sjh5v1n.js.map → chunk-53bek7sp.js.map} +0 -0
  263. /package/dist/{chunk-td8tha3j.js.map → chunk-es487acc.js.map} +0 -0
  264. /package/dist/{chunk-et4pv1b1.js.map → chunk-mx9y9mtx.js.map} +0 -0
  265. /package/dist/{chunk-8b2tw2yp.js.map → chunk-rend2sbk.js.map} +0 -0
@@ -1,4 +1,4 @@
1
1
  // @bun
2
- import{pc as Y}from"../chunk-qd2v93y4.js";import{ig as M}from"../chunk-bn5yn731.js";import{jh as P,lh as R}from"../chunk-q9s7kwgt.js";import"../chunk-3cg7y62b.js";import{uh as Q,vh as U,wh as V,xh as W}from"../chunk-m6ystvtk.js";import"../chunk-1yx2e0bh.js";class S{static token;async boot(){}static inject(){if(!this.token)throw Error(`Service [${this.name}] does not declare a \`static token\`, so the container has no key to resolve it by.`);try{return R(this)}catch(x){throw Error(`Could not inject [${this.name}]. Services are constructed when the kernel boots, so `+"inject() only works from code that runs after that \u2014 a constructor default or a method "+`body, never module top level. Check that [${this.name}] is listed in \`services\` on your Kernel.`,{cause:x})}}static with(x){let f=new this;for(let[C,g]of Object.entries(x))if(g!==void 0)f[C]=g;return f}}import{readdir as z}from"fs/promises";import{join as B,parse as j}from"path";var H=[".ts",".tsx",".js",".mjs",".jsx"];function J(x={}){let f={};for(let[C,g]of Object.entries(x))f[C]=q(g);return new P(f)}async function L(x,f=new P){let C=[];try{C=await z(x)}catch(D){return f}let g=C.filter((D)=>{let{ext:v,name:F}=j(D);return H.includes(v)&&!F.startsWith(".")}).sort();for(let D of g){let{name:v}=j(D),F=await import(B(x,D));f.set(v,q(F))}return f}function q(x){if(x&&typeof x==="object"&&"default"in x)return x.default;return x}export{M as withDefaults,Q as sourceFiles,W as projectRoot,L as loadConfigFrom,V as discoverClasses,J as createConfigRepository,Y as ServiceProvider,S as Service,P as Repository,U as DiscoveryError};
2
+ import{qc as Y}from"../chunk-f1y8eggf.js";import{Ag as M}from"../chunk-hfyxvdjj.js";import{Bh as P,Dh as R}from"../chunk-eazqda9z.js";import"../chunk-dm59ze55.js";import{Mh as Q,Nh as U,Oh as V,Ph as W}from"../chunk-8reepafh.js";import"../chunk-ddad3902.js";class S{static token;async boot(){}static inject(){if(!this.token)throw Error(`Service [${this.name}] does not declare a \`static token\`, so the container has no key to resolve it by.`);try{return R(this)}catch(x){throw Error(`Could not inject [${this.name}]. Services are constructed when the kernel boots, so `+"inject() only works from code that runs after that \u2014 a constructor default or a method "+`body, never module top level. Check that [${this.name}] is listed in \`services\` on your Kernel.`,{cause:x})}}static with(x){let f=new this;for(let[C,g]of Object.entries(x))if(g!==void 0)f[C]=g;return f}}import{readdir as z}from"fs/promises";import{join as B,parse as j}from"path";var H=[".ts",".tsx",".js",".mjs",".jsx"];function J(x={}){let f={};for(let[C,g]of Object.entries(x))f[C]=q(g);return new P(f)}async function L(x,f=new P){let C=[];try{C=await z(x)}catch(D){return f}let g=C.filter((D)=>{let{ext:v,name:F}=j(D);return H.includes(v)&&!F.startsWith(".")}).sort();for(let D of g){let{name:v}=j(D),F=await import(B(x,D));f.set(v,q(F))}return f}function q(x){if(x&&typeof x==="object"&&"default"in x)return x.default;return x}export{M as withDefaults,Q as sourceFiles,W as projectRoot,L as loadConfigFrom,V as discoverClasses,J as createConfigRepository,Y as ServiceProvider,S as Service,P as Repository,U as DiscoveryError};
3
3
 
4
- //# debugId=447CF5C12AD6A7A564756E2164756E21
4
+ //# debugId=3E6AB9C2D6AF98A764756E2164756E21
@@ -6,6 +6,6 @@
6
6
  "import { readdir } from \"node:fs/promises\";\nimport { join, parse } from \"node:path\";\n\nimport { Repository } from \"./Repository\";\n\nconst CONFIG_EXTENSIONS = [\".ts\", \".tsx\", \".js\", \".mjs\", \".jsx\"];\n\n// Builds a Repository from an already-imported map of config modules. The map\n// key becomes the top-level config key, so `{ mail: mailModule }` is readable\n// as `config.get(\"mail.driver\")`. Each entry may be either the module namespace\n// (its `default` export is unwrapped) or the config object itself.\nexport function createConfigRepository(\n modules: Record<string, any> = {},\n): Repository {\n const items: Record<string, any> = {};\n\n for (const [key, mod] of Object.entries(modules)) {\n items[key] = unwrap(mod);\n }\n\n return new Repository(items);\n}\n\n// Reads every config module in an app's `app/config` directory into a\n// Repository. The file's basename is the top-level key: `app/config/mail.ts`\n// populates `mail.*`. A missing directory yields an empty Repository so apps\n// that declare no config still boot.\nexport async function loadConfigFrom(\n directory: string,\n repository = new Repository(),\n): Promise<Repository> {\n let entries: string[] = [];\n\n try {\n entries = await readdir(directory);\n } catch (err) {\n return repository;\n }\n\n const files = entries\n .filter((entry) => {\n const { ext, name } = parse(entry);\n return CONFIG_EXTENSIONS.includes(ext) && !name.startsWith(\".\");\n })\n .sort();\n\n for (const file of files) {\n const { name } = parse(file);\n const mod = await import(join(directory, file));\n repository.set(name, unwrap(mod));\n }\n\n return repository;\n}\n\nfunction unwrap(mod: any) {\n if (mod && typeof mod === \"object\" && \"default\" in mod) {\n return mod.default;\n }\n return mod;\n}\n"
7
7
  ],
8
8
  "mappings": ";2RAgCO,CAAe,JAAQ,EAOrB,OAMD,AAAI,EAAkB,QAmBrB,OAAS,EAKX,CACH,GAAI,CAAC,KAAK,MACR,MAAU,MACR,YAAY,KAAK,0FACnB,EAGF,GAAI,CACF,OAAO,EAAI,IAAuB,EAClC,MAAO,EAAO,CACd,MAAU,MACR,qBAAqB,KAAK,6DACxB,+FACA,6CAA6C,KAAK,kDAEpD,CAAE,OAAM,CACV,SAoBG,KAAuB,CAAoB,EAA0B,CAC1E,IAAM,EAAW,IAAI,KACrB,QAAY,EAAK,KAAU,OAAO,QAAQ,CAAS,EACjD,GAAI,IAAU,OAAW,EAAS,GAAO,EAE3C,OAAO,EAEX,CChHA,kBAAS,oBACT,eAAS,WAAM,aAIf,IAAM,EAAoB,CAAC,MAAO,OAAQ,MAAO,OAAQ,MAAM,EAMxD,SAAS,CAAsB,CACpC,EAA+B,CAAC,EACpB,CACZ,IAAM,EAA6B,CAAC,EAEpC,QAAY,EAAK,KAAQ,OAAO,QAAQ,CAAO,EAC7C,EAAM,GAAO,EAAO,CAAG,EAGzB,OAAO,IAAI,EAAW,CAAK,EAO7B,eAAsB,CAAc,CAClC,EACA,EAAa,IAAI,EACI,CACrB,IAAI,EAAoB,CAAC,EAEzB,GAAI,CACF,EAAU,MAAM,EAAQ,CAAS,EACjC,MAAO,EAAK,CACZ,OAAO,EAGT,IAAM,EAAQ,EACX,OAAO,CAAC,IAAU,CACjB,IAAQ,MAAK,QAAS,EAAM,CAAK,EACjC,OAAO,EAAkB,SAAS,CAAG,GAAK,CAAC,EAAK,WAAW,GAAG,EAC/D,EACA,KAAK,EAER,QAAW,KAAQ,EAAO,CACxB,IAAQ,QAAS,EAAM,CAAI,EACrB,EAAM,MAAa,SAAK,EAAW,CAAI,GAC7C,EAAW,IAAI,EAAM,EAAO,CAAG,CAAC,EAGlC,OAAO,EAGT,SAAS,CAAM,CAAC,EAAU,CACxB,GAAI,GAAO,OAAO,IAAQ,UAAY,YAAa,EACjD,OAAO,EAAI,QAEb,OAAO",
9
- "debugId": "447CF5C12AD6A7A564756E2164756E21",
9
+ "debugId": "3E6AB9C2D6AF98A764756E2164756E21",
10
10
  "names": []
11
11
  }
@@ -1,4 +1,4 @@
1
1
  // @bun
2
- import{ea as B,fa as D}from"../chunk-6vr7f5fq.js";import"../chunk-cy5qp6mz.js";import"../chunk-yqavgpwd.js";import{za as J}from"../chunk-p1aqq0ga.js";import"../chunk-4mfrgd5m.js";import"../chunk-1yx2e0bh.js";function N(){return{name:"gemi-custom-request",enforce:"pre",async transform(G,H){let j=H.split("?",1)[0];if(j.includes("/node_modules/")||!B.test(j))return null;return{code:await D(G),map:null}}}}export{N as gemiRequestPlugin,J as gemiIslandPlugin};
2
+ import{ea as B,fa as D}from"../chunk-csbc1fxa.js";import"../chunk-amvy4r59.js";import"../chunk-a9q2cr4w.js";import{za as J}from"../chunk-p1aqq0ga.js";import"../chunk-4mfrgd5m.js";import"../chunk-ddad3902.js";function N(){return{name:"gemi-custom-request",enforce:"pre",async transform(G,H){let j=H.split("?",1)[0];if(j.includes("/node_modules/")||!B.test(j))return null;return{code:await D(G),map:null}}}}export{N as gemiRequestPlugin,J as gemiIslandPlugin};
3
3
 
4
4
  //# debugId=69032BE0B0AA208664756E2164756E21
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gemi",
3
- "version": "0.111.0",
3
+ "version": "0.112.1",
4
4
  "private": false,
5
5
  "license": "MIT",
6
6
  "author": "Enes Tufekci <enes@gemijs.dev>",
@@ -72,7 +72,8 @@
72
72
  "react-dom": ">=19",
73
73
  "sharp": "^0.34.2",
74
74
  "typescript": ">=5",
75
- "vite": "^8.0.0"
75
+ "vite": "^8.0.0",
76
+ "postgres": "^3.4.0"
76
77
  },
77
78
  "peerDependenciesMeta": {
78
79
  "@azure/storage-blob": {
@@ -80,6 +81,9 @@
80
81
  },
81
82
  "typescript": {
82
83
  "optional": true
84
+ },
85
+ "postgres": {
86
+ "optional": true
83
87
  }
84
88
  }
85
89
  }
@@ -57,7 +57,22 @@ export class Account extends AccountModel {
57
57
  }
58
58
  ```
59
59
 
60
- A policy only applies to a model **registered on `Kernel.models`** via the
60
+ **For one record named by the route or the chat** (`/pages/:pageId`, an agent whose
61
+ `body` carries `pageId`), a resource policy states the rule once and applies it to the
62
+ route, the view and the agent's four routes, refusing "missing" and "not yours" with the
63
+ same 404:
64
+
65
+ ```ts
66
+ export const PagePolicy = defineResourcePolicy({
67
+ param: "pageId",
68
+ load: (id) => Page.findUnique({ where: { publicId: id } }),
69
+ allow: (page, req) => page.ownerId === req.ctx().user?.id,
70
+ });
71
+ // aliases: { "owns-page": PagePolicy.middleware }
72
+ // AgentController: resource = PagePolicy.forAgent({ body: (b: PageBody) => b.pageId, thread: … })
73
+ ```
74
+
75
+ An ORM policy only applies to a model **registered on `Kernel.models`** via the
61
76
  `app/models` barrel — that registration is what makes it apply inside nested
62
77
  `include`s. Policies concatenate base-first, so a subclass can narrow an inherited
63
78
  policy but never widen it.
@@ -1,5 +0,0 @@
1
- // @bun
2
- import{Jb as a}from"./chunk-3y8q8x11.js";import{Vb as d,Xb as b,Zb as XZ,_b as JZ,ac as QZ}from"./chunk-mb7q7s0a.js";import{bc as GZ,ec as qZ,gc as WZ,hc as HZ,ic as q,jc as zZ,kc as VZ,mc as KZ}from"./chunk-1pem26zc.js";import{pc as I}from"./chunk-qd2v93y4.js";import{Bd as v,Fd as o,Gc as _Z,Kc as r,Nd as M,Rc as AZ,Rd as R,Sd as c,Td as p,md as UZ,nd as i,rd as w,zd as t}from"./chunk-h3864a8z.js";import{me as CZ,ne as l}from"./chunk-nvv9wej6.js";import{Ff as m,Uf as n,Wf as g,Xf as y,Yf as j}from"./chunk-mn5xw79b.js";import{fg as $Z,hg as x}from"./chunk-twnn7r66.js";import{ig as U}from"./chunk-bn5yn731.js";import{og as OZ}from"./chunk-xkc7ftnq.js";import{ch as s}from"./chunk-rfcygmf5.js";import{ih as IZ,lh as f}from"./chunk-q9s7kwgt.js";async function jZ(Z,$={}){try{if(!await Z.shouldRun.call(Z))return}catch(W){console.error(`Error evaluating shouldRun for cron job ${Z.name}:`,W);return}let G=kZ(Z.withoutOverlapping);if(!Z.onOneServer&&G===void 0){await u(Z);return}let H;try{if(H=$.locks?.()??MZ(),Z.onOneServer){let W=Math.floor(($.now??Date.now())/60000);if(!await H.store.advance(`gemi:cron-tick:${Z.name}`,W))return}}catch(W){console.error(`Could not claim the tick of cron job ${Z.name}; skipped it:`,W);return}if(G===void 0){await u(Z);return}try{await H.run(`gemi:cron:${Z.name}`,{ttl:G},(W)=>u(Z,W))}catch(W){if(W instanceof $Z)console.error(`Cron job ${Z.name} lost its withoutOverlapping lock while running: another tick may have started alongside it.`,W);else console.error(`Could not take the withoutOverlapping lock of cron job ${Z.name}:`,W)}}var e=300000;function kZ(Z){if(!Z)return;if(Z===!0)return e;return Z.expiresAfter??e}var ZZ;function MZ(){return ZZ??=new x(new GZ),ZZ}async function u(Z,$){try{await Z.onTick.call(Z)}catch(G){console.error(`Error executing cron job ${Z.name}:`,G)}try{await Z.callback.call(Z,$)}catch(G){console.error(`Error in cron job ${Z.name}:`,G)}try{await Z.onComplete.call(Z)}catch(G){console.error(`Error completing cron job ${Z.name}:`,G)}}class P{static token="scheduler";handles=[];resolved;inFlight=new Map;stopped=!1;locks;constructor(Z){this.resolved=Z.jobs}get jobs(){return[...this.resolved]}useJobs(Z){this.resolved=Z}useLocks(Z){this.locks=Z}start(Z=($)=>$()){if(this.stopped=!1,this.resolved.length===0)return;let $=globalThis.__gemiCronJobs??=new Map,G=new Map;for(let H of this.resolved){let W=new H;if(!W.name){console.error(`Cron job must have a name \u2014 ${H.name||"an anonymous class"} has none, so it is not scheduled. If this is a base class that other jobs extend, move it out of the discovered directory: \`abstract\` does not survive to runtime, so a class under app/cron is indistinguishable from a job.`);continue}if(!W.cron){console.error(`Cron job must have an expression. Job: ${W.name}`);continue}let z=G.get(W.name);if(z!==void 0){console.error(`Two cron jobs claim the name "${W.name}" \u2014 ${z} is scheduled and ${H.name||"an anonymous class"} is not. A name is the scheduler's key, so only one job can hold it. Rename one.`);continue}G.set(W.name,H.name||"an anonymous class"),$.get(W.name)?.stop();let Y=Bun.cron(W.cron,()=>{if(this.stopped)return;let V=this.locks;return this.track(W.name,()=>Z(()=>jZ(W,{locks:V})))});$.set(W.name,Y),this.handles.push(Y)}}stop(){this.stopped=!0;for(let Z of this.handles)Z.stop();this.handles=[]}async drain(Z=1/0){this.stop();let $,G=new Promise((H)=>{if(Z!==1/0)$=setTimeout(H,Z)});return await Promise.race([Promise.allSettled([...this.inFlight.values()].map((H)=>H.done)),G]),clearTimeout($),{unfinished:[...this.inFlight.values()].map((H)=>({...H.tick}))}}get running(){return this.inFlight.size}track(Z,$){let G={},H=Promise.resolve().then($).finally(()=>this.inFlight.delete(G));return this.inFlight.set(G,{tick:{name:Z,startedAt:new Date},done:H}),H}}import{isMainThread as yZ}from"worker_threads";var wZ=100,fZ=(Z)=>Math.min(wZ,Math.floor(Z/10));class bZ extends I{register(){this.app.singleton(q,()=>new q(this.app.config.get("queue",{}),{application:this.app})),this.app.singleton(x,()=>this.app.make(q).locks)}async boot(){let Z=this.app.config.get("queue",{});if(Z.jobs!==void 0)return;let{jobsDir:$}=U(WZ(),Z);this.app.make(q).useJobs(await XZ($))}async shutdown(Z){if(!this.app.resolved(q))return;let $=this.app.make(q);if($.running>0)console.log(`[gemi] Shutting down: waiting for ${$.running} running queued job(s).`);let G=Z?.timeoutMs,{unfinished:H}=await $.drain(G===void 0?1/0:Math.max(0,G-fZ(G)));if(H.length>0)return console.error("[gemi] Queued jobs still running at shutdown: "+H.map((W)=>`${W.name} (${W.id})`).join(", ")),{abandoned:!0}}}function L3(Z){if(vZ(Z),Bun.env.NODE_ENV!=="production")return mZ(Z);if(YZ(Z))return;if(!zZ())return;if(!Z.bound(q))return;Z.make(q).start()}function YZ(Z){let $=Z.config.get("queue",{}).driver??"memory";return $==="memory"||$ instanceof HZ}function gZ(Z){if(YZ(Z))return!0;if(typeof Z.config.get("queue",{}).driver!=="function"||!Z.bound(q))return!1;try{return!Z.make(q).durable}catch{return!1}}function vZ(Z){let $=process.env.GEMI_QUEUE_CLAIM;if($===void 0||KZ())return;if(process.env.ROOT_DIR===void 0||!yZ)return;if(VZ()){if(!gZ(Z))return;console.warn('[gemi] GEMI_QUEUE_CLAIM=off is ignored: the memory queue driver keeps jobs in the process that dispatched them, so no worker could run them. This server runs its own jobs. Use a driver other processes can read, such as "database", to hand jobs to `gemi queue:work`.')}else if($.trim().toLowerCase()!=="on")console.warn(`[gemi] GEMI_QUEUE_CLAIM="${$}" is not "off" or "on", so this server claims jobs. Set it to "off" to leave them to \`gemi queue:work\`.`)}function mZ(Z){let $=globalThis.__gemiDevQueue;if(!$)return;if(globalThis.__gemiDevQueue=void 0,$.stop(),Z.bound(q))Z.make(q).start()}class hZ extends I{register(){this.app.singleton(p,()=>new p(this.app.config.get("auth",{})))}}var cZ=100,uZ=(Z)=>Math.min(cZ,Math.floor(Z/10));class pZ extends I{register(){this.app.singleton(P,()=>new P(U(d(),this.app.config.get("schedule",{}))))}async boot(){let Z=this.app.make(P),$=this.app.config.get("schedule",{});if($.jobs===void 0){let{jobsDir:H}=U(d(),$);Z.useJobs(await JZ(H))}if(process.env.GEMI_NO_SCHEDULE==="1")return;let G=this.app;if(G.bound(x))Z.useLocks(()=>G.make(x));Z.start((H)=>IZ.run(G,H))}async shutdown(Z){if(!this.app.resolved(P))return;let $=this.app.make(P);if($.running>0)console.log(`[gemi] Shutting down: waiting for ${$.running} running cron tick(s).`);let G=Z?.timeoutMs,{unfinished:H}=await $.drain(G===void 0?1/0:Math.max(0,G-uZ(G)));if(H.length>0)return console.error("[gemi] Cron jobs still running at shutdown: "+H.map((W)=>`${W.name} (started ${W.startedAt.toISOString()})`).join(", ")),{abandoned:!0}}}class T extends UZ{modelName;constructor(Z="FeatureFlag"){super();this.modelName=Z}get available(){return CZ(this.modelName)}async load(){if(!this.available)throw new i(this.modelName);let Z=l(this.modelName);return await Z.asSystem(()=>Z.findMany())}async write(Z,$,G){if(!this.available)throw new i(this.modelName);let H=l(this.modelName),W=this.hasActorColumn(H),z={active:$};if(W)z.updatedBy=G.actor;return await H.asSystem(()=>H.upsert({where:{key:Z},create:{key:Z,...z},update:z})),{actorRecorded:W}}hasActorColumn(Z){let $=Z?.$schema?.fields?.updatedBy;return $!==void 0&&$.type==="String"}}function c3(Z){return Z}function BZ(){return{features:void 0,enabled:!0,source:new T,model:"FeatureFlag",ttl:30,context:void 0,onEvaluate:void 0,maxClientFlags:200}}class dZ extends I{register(){this.app.singleton(w,()=>{let Z=this.app.config.get("features",{}),$=U(BZ(),Z);if(Z?.model!==void 0&&Z?.source===void 0)$.source=new T(Z.model);else if(Z?.model!==void 0&&Z.source instanceof T&&Z.source.modelName!==Z.model)y.warning(`app/config/features.ts sets \`model: "${Z.model}"\` and a source reading "${Z.source.modelName}". The source wins; drop \`model\` to silence this.`);return new w($,(G)=>y.warning(G))})}async boot(){let Z=this.app.make(w);if(!Z.config.enabled)return;try{await Z.refresh()}catch($){y.error(`Could not warm the feature flag cache at boot. ${$ instanceof Error?$.message:String($)}`)}}}class lZ extends I{register(){this.app.singleton(s,()=>new s(this.app.config.get("mail",{})))}}function iZ(Z){return`listener:${Z}`}function NZ(Z,$){sZ(Z);let{maxAttempts:G,backoff:H,worker:W}=$,z=Z.event.name,Y=class extends qZ{maxAttempts=G;backoff=H;worker=W;async run(...V){let[K,J]=nZ(V),B=f(L).rehydrate(K,J);await new Z().handle(B)}onFail(V){console.error(`The listener ${Z.name} threw while handling ${z} off the queue. The queue will retry it up to ${G} times in total; nothing the dispatcher did is waiting on it.`,V)}onDeadletter(V){console.error(`The listener ${Z.name} failed every one of its ${G} attempts at ${z} and has been dead-lettered, so this side effect did not happen and will not be retried.`,V)}};return Object.defineProperty(Y,"name",{value:iZ(Z.name),writable:!0}),Y}function sZ(Z){if(Object.getOwnPropertyDescriptor(Z,"name")?.writable)return;throw Error(`The listener ${Z.name} sets \`queued = true\` but does not declare \`static name\`, so it would be registered with the queue `+"under its class name \u2014 which a production build renames while the "+`payload that names it does not. Add: static name = "${Z.name}";`)}function nZ(Z){return typeof Z[0]==="string"?Z:Z[0]}class L{static token="events";listeners={};events={};warnedFor=new Set;warnedAboutWaiting=new Set;config;constructor(Z={}){this.config=U(b(),Z),this.useListeners(this.config.listeners)}useListeners(Z){this.config.listeners=Z,this.listeners={},this.events={};let $=new Set;for(let G of Z){if(!G.event){console.error(`Listener ${G.name} does not declare \`static event\`, so there is no event name to register it under and its handle will never run. Add: static event = SomeEvent;`);continue}if($.has(G.name)){console.error(`Two event listeners are named "${G.name}" \u2014 the first is `+"registered and this one is not. A listener's name identifies it across the framework, so only one class can hold it. Rename one.");continue}$.add(G.name);let H=G.event.name,W=new G;this.events[H]??=G.event,(this.listeners[H]??=[]).push({listener:G,job:W.queued?NZ(G,W):null})}}get queuedListenerJobs(){return Object.values(this.listeners).flat().flatMap(({job:Z})=>Z?[Z]:[])}get registeredListeners(){return[...this.config.listeners]}dispatch(Z,$){if(this.deferToCommit(Z,$,!1))return;this.runListeners(Z,$)}async dispatchAndWait(Z,$){if(this.deferToCommit(Z,$,!0))return;return this.runListeners(Z,$)}deferToCommit(Z,$,G){let{name:H,afterCommit:W}=Z.constructor;if(!W)return!1;let z=OZ(()=>this.runListeners(Z,$));if(z&&G)this.warnNothingIsWaitedFor(H);return z}async runListeners(Z,$){let G=Z.constructor.name,H=this.listeners[G];if(!H?.length){this.warnNothingIsListening(G);return}for(let{listener:W,job:z}of H){if(z){this.enqueue(z,W,G,$);continue}try{await new W().handle(Z)}catch(Y){console.error(`The listener ${W.name} threw while handling ${G}. The `+"listeners after it still ran \u2014 a listener's failure is its own.",Y)}}}rehydrate(Z,$=[]){let G=this.events[Z];if(!G)throw Error(`Cannot rebuild the event "${Z}" that came off the queue: no registered listener binds to an event of that name, so there is no class to construct. A queued listener runs in an application that `+"discovered its own listeners \u2014 check that this process sees the "+`same app/listeners as the one that dispatched, and that the event declares \`static name = "${Z}"\`.`);return new G(...$)}enqueue(Z,$,G,H){if(H===void 0){console.error(`The listener ${$.name} is queued, but ${G} reached the dispatcher without its constructor arguments, so there is nothing for the queue to rebuild it from and the listener was skipped. Dispatch through ${G}.dispatch(...) or ${G}.dispatchAndWait(...), which carry them.`);return}let W=(z)=>console.error(`The listener ${$.name} could not be queued for ${G}, so it did not run and will not be retried. The listeners after it still ran.`,z);try{f(q).push(Z,JSON.stringify([G,H]),{reportFailure:!1}).catch(W)}catch(z){W(z)}}warnNothingIsWaitedFor(Z){if(Bun.env.NODE_ENV==="production")return;if(this.warnedAboutWaiting.has(Z))return;this.warnedAboutWaiting.add(Z),console.warn(`[gemi] ${Z}.dispatchAndWait() was called inside a transaction and ${Z} declares \`static afterCommit = true\`, so it resolved `+"immediately with no listener having run \u2014 they run when the "+"transaction commits. Await the transaction instead, or drop afterCommit if the caller needs the side effects first. Development only.")}warnNothingIsListening(Z){if(Bun.env.NODE_ENV==="production")return;if(this.warnedFor.has(Z))return;this.warnedFor.add(Z),console.warn(`[gemi] ${Z} was dispatched and nothing is listening for it. A listener registers under the name its event declares, so check that app/listeners holds a Listener with \`static event = ${Z}\` and that ${Z} declares \`static name = "${Z}"\`. Development only.`)}}class tZ extends I{register(){this.app.singleton(L,()=>new L(this.app.config.get("events",{})))}async boot(){let Z=this.app.make(L),$=this.app.config.get("events",{});if($.listeners===void 0){let{listenersDir:W}=U(b(),$);Z.useListeners(await QZ(W))}let G=Z.queuedListenerJobs;if(G.length===0)return;let H=this.app.make(q);for(let W of G)H.registerJob(W)}}class oZ extends I{register(){this.app.singleton(n,()=>new n(this.app.config.get("filesystem",{})))}}class rZ extends I{register(){this.app.singleton(t,()=>new t(this.app.config.get("image",{})))}}class aZ extends I{register(){this.app.instance(o,new o)}}function E4(Z){return Z}function FZ(){return{maxFileSize:10485760,onLogFileClosed:()=>{},onLogCreated:()=>{}}}class eZ extends I{register(){this.app.singleton(g,()=>new g(U(FZ(),this.app.config.get("log",{}))))}async boot(){if(!process.env.ROOT_DIR)return;await this.app.make(g).boot()}}class Z3 extends I{register(){this.app.singleton(v,()=>new v(U(_Z(),this.app.config.get("middleware",{}))))}boot(){this.app.make(v).assertGlobalMiddleware()}}function h4(Z){return Z}function xZ(){return{driver:new AZ,limit:1000,window:60}}class $3 extends I{register(){this.app.singleton(r,()=>new r(U(xZ(),this.app.config.get("ratelimiter",{}))))}}function s4(Z){return Z}function PZ(){return{url:process.env.REDIS_URL,options:void 0}}class G3 extends I{register(){this.app.singleton(j,()=>new j(U(PZ(),this.app.config.get("redis",{}))))}shutdown(){if(!this.app.resolved(j))return;this.app.make(j).close()}}class Q extends a{status;constructor(Z,$){super(Z);this.status=$;this.name="McpToolError"}}var W3=/^[A-Za-z0-9_-]{1,64}$/,H3=/:([A-Za-z_][A-Za-z0-9_]*)([?*+]?)/g,LZ=4000,E=1e5,z3=/^(text\/|application\/([\w.+-]*\+)?(json|xml))/i;class k{router;dispatcher;static token="router.mcp";plans=new Map;constructor(Z,$){this.router=Z;this.dispatcher=$;for(let[G,H]of Object.entries(Z.routes??{}))this.plans.set(G,this.plan(G,H))}list(Z,$){return SZ(Z),this.descriptors($)}descriptors(Z){let $=[];for(let{descriptor:G}of this.plans.values()){if(Z?.names&&!Z.names.includes(G.name))continue;if(Z?.tags&&!G.tags.some((H)=>Z.tags.includes(H)))continue;$.push(G)}return $}async execute(Z,$,G,H){SZ(Z);let W=this.plans.get($);if(!W)throw Error(`McpRegistry: there is no tool named "${$}".`);let{descriptor:z}=W,Y=z.inputSchema.safeParse(G);if(Y.ok===!1)throw new Q(`Invalid arguments for "${$}": ${Y.errors.join(", ")}`);let V=Y.value,K={caller:Z,req:Z.req,tool:z,input:V,ctx:H},J=await this.fillPath(W,K),{path:B}=this.dispatcher.getRouteHandlerAndParams(new Request(`http://gemi.internal/api${J}`));if(B!==z.url)throw new Q(`"${$}" has nothing at ${J}.`,404);let C={};for(let F of W.jsonKeys)if(V[F]!==void 0)C[F]=V[F];let O,_="";if(W.fileFields.length>0)O=await this.formData(W,C,K);else if(z.method==="GET")_=I3(C);else if(W.jsonKeys.length>0)O=C;let D=this.router.credentials?await this.bind(W,"the credentials",()=>this.router.credentials(K)):void 0,S;try{let F=_?`${J}?${_}`:J;S=D?await this.dispatcher.dispatchAs(Z.req,z.method,F,O,{credentials:D}):await this.dispatcher.dispatchAs(Z.req,z.method,F,O)}catch(F){throw console.error(`[gemi/mcp] Dispatching "${$}" failed:`,F),new Q(`"${$}" failed on the server.`,500)}if(!W.result&&!z.outputSchema)return await RZ($,S);return await this.project(W,K,S)}plan(Z,$){if(!W3.test(Z))throw Error(`McpRouter: "${Z}" is not a valid tool name. A routes key is the tool's name as a model and an MCP client see it, used verbatim \u2014 letters, digits, "_" and "-", at most 64.`);let G=`McpRouter: "${Z}" (${$?.method} ${$?.url})`;if(!($ instanceof Object)||$.__internal_brand!=="McpRoute")throw Error(`McpRouter: "${Z}" is not a route. Declare it with this.fromApiRoute(...).`);let{method:H,url:W,meta:z}=$;if(W.startsWith("/__gemi__"))throw Error(`${G} is a framework route, not an app route.`);let Y=this.dispatcher.flatRoutes[W]?.[H];if(!Y)throw Error(`${G} names no route of this app. Expose a route by the path and verb it is mounted at.`);let V=[...W.matchAll(H3)].map(([,X,N])=>({name:X,modifier:N})),K=z.params??{};for(let X of V)if(!(X.name in K))throw Error(`${G}: the path param "${X.name}" must be bound or declared "input".`);for(let[X,N]of Object.entries(K)){if(!V.some((A)=>A.name===X))throw Error(`${G}: "${X}" in params is not a param of the url.`);if(EZ(N))V3(G,`params.${X}`,N);else TZ(G,`params.${X}`,N)}let J=[],B;if(z.input){if(B=z.input.toJSONSchema(),B.type!=="object"||!B.properties)throw Error(`${G}: input must be an s.object(...), the fields of the request body.`);J=Object.keys(B.properties)}let C=Object.entries(z.files??{}).map(([X,N])=>({name:X,binder:N}));for(let X of C)TZ(G,`files.${X.name}`,X.binder);if(z.result!==void 0&&typeof z.result!=="function")throw Error(`${G}: result must be a function.`);if(z.output!==void 0&&typeof z.output?.safeParse!=="function")throw Error(`${G}: output must be a schema, built with s.`);if(C.length>0&&H==="GET")throw Error(`${G}: a GET has no body to carry a file.`);let O={},_=(X,N)=>{if(X in O)throw Error(`${G}: "${X}" is the input key of two params or files, and the model can only send one.`);O[X]=N},D=new Map,S=new Map;for(let X of V){let N=K[X.name];if(N==="input"){let A=m.string().describe(`The ":${X.name}" segment of the url.`);_(X.name,X.modifier==="?"||X.modifier==="*"?A.optional():A)}else if(EZ(N)){let A=N.as??X.name;_(A,N.input),S.set(X.name,{key:A,param:N})}else D.set(X.name,N)}for(let X of C)if(X.binder==="input")_(X.name,m.string().describe("The id of an attachment the user uploaded or a tool produced (gemi_att_\u2026), whose file is sent as this field."));let F=[...Object.keys(O),...C.map((X)=>X.name)];for(let X of new Set(F))if(J.includes(X))throw Error(`${G}: "${X}" is both an input field and a param or file, and the model can only send one.`);return{descriptor:Object.freeze({name:Z,description:z.description,method:H,url:W,inputSchema:X3(z.input,B,m.object(O)),...z.output?{outputSchema:z.output}:{},annotations:K3(H),tags:Object.freeze([...z.tags??[]]),requiresApproval:z.requiresApproval===!0,...Y.source?{source:Y.source}:{}}),params:V,paramBinders:D,modelParams:S,fileFields:C,jsonKeys:J,...z.result?{result:z.result}:{}}}async fillPath(Z,$){let{input:G,req:H}=$,W=Z.descriptor.url;for(let z of Z.params){let Y=Z.paramBinders.get(z.name),V=Z.modelParams.get(z.name),K;if(Y||V){if(K=V?await this.bind(Z,`the param "${z.name}"`,()=>V.param.bind(G[V.key],H,$),{refusals:!0}):await this.bind(Z,`the param "${z.name}"`,()=>Y(H,$)),K===void 0||K===null||K==="")throw console.error(`[gemi/mcp] The ${V?"resolver":"binder"} for "${z.name}" of "${Z.descriptor.name}" returned ${JSON.stringify(K)}.`),new Q(`"${Z.descriptor.name}" failed on the server.`,500)}else K=G[z.name];let J=`:${z.name}${z.modifier}`;if(K===void 0||K===null||K===""){if(z.modifier!=="?"&&z.modifier!=="*")throw new Q(`"${z.name}" of "${Z.descriptor.name}" must not be empty.`);W=W.replace(`/${J}`,"");continue}W=W.replace(J,Y3(Z.descriptor.name,z,String(K)))}return W}async formData(Z,$,G){let{input:H,ctx:W}=G,z=Z.descriptor.name;if(!W)throw Error(`McpRegistry: "${z}" sends a file, which is resolved through the tool context's attachments, and none was passed to execute().`);let Y=new FormData;for(let[V,K]of Object.entries($))DZ(Y,V,K);for(let V of Z.fileFields){let K=V.binder==="input"?H[V.name]:await this.bind(Z,`the file "${V.name}"`,()=>V.binder(W,G));if(typeof K!=="string"||K==="")throw new Q(`"${z}" needs a file for "${V.name}", and this turn has none. Ask the user to attach one.`);Y.append(V.name,await W.attachments.file(K))}return Y}async project(Z,$,G){let{name:H,outputSchema:W}=Z.descriptor;if(G.status<200||G.status>=300)return await RZ(H,G);let z=(C,O)=>{if(O===void 0)console.error(`[gemi/mcp] "${H}" ${C}`);else console.error(`[gemi/mcp] "${H}" ${C}`,O);return new Q(`"${H}" failed on the server.`,500)},Y=G.headers.get("Content-Type"),V=await G.text(),K=null;if(V!=="")try{K=JSON.parse(V)}catch{throw z(`answered ${Y??"a body with no content-type"} that is not JSON, and its result or output needs JSON.`)}let J=K;if(Z.result)try{J=await Z.result(K,$)}catch(C){throw z("failed in its result projection:",C)}if(W){let C=W.safeParse(J);if(C.ok===!1)throw z(`answered what its output schema refuses: ${C.errors.join(", ")}`);J=C.value}if(J===void 0)return null;let B=JSON.stringify(J);if(B!==void 0&&B.length>E)return`${B.slice(0,E)}\u2026 [cut at ${E} of ${B.length} characters]`;return J}async bind(Z,$,G,H={}){try{return await G()}catch(W){if(H.refusals&&W instanceof a)throw W;throw console.error(`[gemi/mcp] Binding ${$} of "${Z.descriptor.name}" failed:`,W),new Q(`"${Z.descriptor.name}" failed on the server.`,500)}}}function SZ(Z){if(Z?.kind!=="local")throw Error("McpRegistry: only local callers are implemented. A remote caller needs a bearer-token resolver, which v1 does not have \u2014 and until it does there is no remote surface to call from.")}function TZ(Z,$,G){if(G!=="input"&&typeof G!=="function")throw Error(`${Z}: ${$} must be a function or "input".`)}function EZ(Z){return Z instanceof Object&&Z.__internal_brand==="McpModelParam"}function V3(Z,$,G){if(G.as!==void 0&&(typeof G.as!=="string"||G.as===""))throw Error(`${Z}: ${$}.as must be a non-empty string.`);let H=G.input;if(typeof H?.safeParse!=="function"||typeof H.toJSONSchema!=="function")throw Error(`${Z}: ${$}.input must be a schema, built with s.`);if(typeof G.bind!=="function")throw Error(`${Z}: ${$}.bind must be a function.`)}function K3(Z){switch(Z){case"GET":return Object.freeze({readOnlyHint:!0});case"DELETE":return Object.freeze({destructiveHint:!0});case"PUT":return Object.freeze({idempotentHint:!0});default:return Object.freeze({})}}function X3(Z,$,G){let H=G.toJSONSchema(),W={...$??{},type:"object",properties:{...$?.properties??{},...H.properties},required:[...$?.required??[],...H.required??[]],additionalProperties:!1},z=(Y)=>{if(typeof Y!=="object"||Y===null||Array.isArray(Y))return{ok:!1,errors:["expected an object"]};let V=[],K={};if(Z){let B=Z.safeParse(Y);if(B.ok===!1)V.push(...B.errors);else K={...B.value}}let J=G.safeParse(Y);if(J.ok===!1)V.push(...J.errors);else K={...K,...J.value};return V.length>0?{ok:!1,errors:V}:{ok:!0,value:K}};return{toJSONSchema:()=>W,safeParse:z,parse(Y){let V=z(Y);if(V.ok===!1)throw Error(V.errors.join(", "));return V.value}}}function Y3(Z,$,G){let H=$.modifier==="*"||$.modifier==="+"?G.split("/"):[G];if(H.some((W)=>W==="."||W===".."))throw new Q(`"${G}" is not a valid value for "${$.name}" of "${Z}".`);return H.map(encodeURIComponent).join("/")}function DZ(Z,$,G){if(G===void 0||G===null)return;if(Array.isArray(G)){for(let H of G)DZ(Z,$,H);return}Z.append($,typeof G==="object"?JSON.stringify(G):String(G))}function I3(Z){let $=new URLSearchParams,G=(H,W)=>{if(W===void 0||W===null)return;if(Array.isArray(W)){for(let z of W)G(H,z);return}$.append(H,typeof W==="object"?JSON.stringify(W):String(W))};for(let[H,W]of Object.entries(Z))G(H,W);return $.toString()}async function RZ(Z,$){if($.status>=200&&$.status<300){let H=$.headers.get("Content-Type");if(H&&!z3.test(H)){let z=(await $.arrayBuffer()).byteLength;return`"${Z}" answered with ${z} bytes of ${H}, which is not shown.`}let W=await $.text();if(W==="")return null;if(W.length>E)return`${W.slice(0,E)}\u2026 [cut at ${E} of ${W.length} characters]`;try{return JSON.parse(W)}catch{return W}}let G=await $.text();if($.status>=400&&$.status<500){let H=G.length>LZ?`${G.slice(0,LZ)}\u2026`:G;throw new Q(`"${Z}" was refused with ${$.status}${H?`: ${H}`:"."}`,$.status)}if($.status<500)console.error(`[gemi/mcp] "${Z}" answered ${$.status}${$.headers.get("Location")?` to ${$.headers.get("Location")}`:""}, which a tool call cannot follow.`);throw new Q(`"${Z}" failed on the server.`,$.status)}function h(Z,$){let G=Z.get($);if(!G)throw Error(`Missing "${$}" configuration. Route dispatching needs a root router \u2014 declare it in "app/config/route.ts".`);return G}class J3 extends I{register(){this.app.singleton(R,()=>new R(h(this.app.config,"route.api"))),this.app.singleton(M,()=>new M(h(this.app.config,"route.view"))),this.app.singleton(c,()=>new c({api:this.app.make(R),view:this.app.make(M)},{api:h(this.app.config,"route.api"),view:h(this.app.config,"route.view"),domains:this.app.config.get("route.domains")})),this.app.singleton(k,()=>{let Z=this.app.config.get("route.mcp");if(!Z?.router)throw Error('No MCP router is configured. Declare one as `mcp: { router }` in "app/config/route.ts".');return new k(new Z.router,this.app.make(R))})}boot(){if(this.app.make(R),this.app.make(M),this.app.make(c),this.app.config.get("route.mcp"))this.app.make(k)}}
3
- export{P as hb,bZ as ib,L3 as jb,hZ as kb,pZ as lb,T as mb,c3 as nb,BZ as ob,dZ as pb,lZ as qb,L as rb,tZ as sb,oZ as tb,rZ as ub,aZ as vb,E4 as wb,FZ as xb,eZ as yb,Z3 as zb,h4 as Ab,xZ as Bb,$3 as Cb,s4 as Db,PZ as Eb,G3 as Fb,Q as Gb,k as Hb,J3 as Ib};
4
-
5
- //# debugId=467BF6E1A0BBD8A564756E2164756E21