gemi 0.112.1 → 0.114.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 (240) hide show
  1. package/dist/ai/index.js +32 -32
  2. package/dist/ai/index.js.map +3 -5
  3. package/dist/app/App.d.ts.map +1 -1
  4. package/dist/app/index.js +1 -1
  5. package/dist/auth/AuthController.d.ts +19 -2
  6. package/dist/auth/AuthController.d.ts.map +1 -1
  7. package/dist/auth/config.d.ts +9 -0
  8. package/dist/auth/config.d.ts.map +1 -1
  9. package/dist/auth/oauth/GoogleOAuthProvider.d.ts +16 -17
  10. package/dist/auth/oauth/GoogleOAuthProvider.d.ts.map +1 -1
  11. package/dist/auth/oauth/OAuthProvider.d.ts +56 -7
  12. package/dist/auth/oauth/OAuthProvider.d.ts.map +1 -1
  13. package/dist/auth/oauth/XOAuthProvider.d.ts +10 -9
  14. package/dist/auth/oauth/XOAuthProvider.d.ts.map +1 -1
  15. package/dist/auth/oauth/oauthState.d.ts +70 -0
  16. package/dist/auth/oauth/oauthState.d.ts.map +1 -0
  17. package/dist/auth/routes.d.ts +3 -2
  18. package/dist/auth/routes.d.ts.map +1 -1
  19. package/dist/bin/gemi.js +8 -1
  20. package/dist/bin/gemi.js.map +3 -3
  21. package/dist/bun/plugin.js +1 -1
  22. package/dist/bun/preload.js +1 -1
  23. package/dist/chunk-0n9vs1ad.js +14 -0
  24. package/dist/{chunk-j0sncgxc.js.map → chunk-0n9vs1ad.js.map} +4 -4
  25. package/dist/{chunk-18c3y8m3.js → chunk-1f9sqht5.js} +2 -2
  26. package/dist/{chunk-18c3y8m3.js.map → chunk-1f9sqht5.js.map} +1 -1
  27. package/dist/{chunk-bhw7k8vp.js → chunk-1p0dazvk.js} +2 -2
  28. package/dist/{chunk-bhw7k8vp.js.map → chunk-1p0dazvk.js.map} +1 -1
  29. package/dist/{chunk-b7cqwcbm.js → chunk-2rphhsr7.js} +2 -2
  30. package/dist/{chunk-b7cqwcbm.js.map → chunk-2rphhsr7.js.map} +1 -1
  31. package/dist/{chunk-qx87cdfg.js → chunk-2z1981d0.js} +2 -2
  32. package/dist/{chunk-qx87cdfg.js.map → chunk-2z1981d0.js.map} +1 -1
  33. package/dist/{chunk-tb126j80.js → chunk-329ggbcw.js} +2 -2
  34. package/dist/{chunk-tb126j80.js.map → chunk-329ggbcw.js.map} +1 -1
  35. package/dist/{chunk-dm59ze55.js → chunk-37qk5dh8.js} +2 -2
  36. package/dist/{chunk-dm59ze55.js.map → chunk-37qk5dh8.js.map} +1 -1
  37. package/dist/{chunk-b7qjp7r1.js → chunk-3ma9m432.js} +2 -2
  38. package/dist/{chunk-b7qjp7r1.js.map → chunk-3ma9m432.js.map} +1 -1
  39. package/dist/{chunk-5waxjsvv.js → chunk-4szjp84e.js} +2 -2
  40. package/dist/{chunk-5waxjsvv.js.map → chunk-4szjp84e.js.map} +1 -1
  41. package/dist/{chunk-8reepafh.js → chunk-56fgk5rq.js} +2 -2
  42. package/dist/{chunk-8reepafh.js.map → chunk-56fgk5rq.js.map} +1 -1
  43. package/dist/{chunk-hfyxvdjj.js → chunk-583vxa2v.js} +2 -2
  44. package/dist/{chunk-hfyxvdjj.js.map → chunk-583vxa2v.js.map} +1 -1
  45. package/dist/{chunk-6w79zajj.js → chunk-5j76r5q8.js} +3 -3
  46. package/dist/{chunk-6w79zajj.js.map → chunk-5j76r5q8.js.map} +1 -1
  47. package/dist/chunk-60nyk1w8.js +10 -0
  48. package/dist/chunk-60nyk1w8.js.map +38 -0
  49. package/dist/{chunk-jn59bsww.js → chunk-6h9j3f1x.js} +2 -2
  50. package/dist/{chunk-jn59bsww.js.map → chunk-6h9j3f1x.js.map} +1 -1
  51. package/dist/{chunk-teny6xkw.js → chunk-75wk4jxd.js} +2 -2
  52. package/dist/{chunk-teny6xkw.js.map → chunk-75wk4jxd.js.map} +1 -1
  53. package/dist/{chunk-k7rbkhhw.js → chunk-7fwp7vwh.js} +2 -2
  54. package/dist/{chunk-k7rbkhhw.js.map → chunk-7fwp7vwh.js.map} +1 -1
  55. package/dist/{chunk-beks65me.js → chunk-7rmjr8p7.js} +3 -3
  56. package/dist/{chunk-beks65me.js.map → chunk-7rmjr8p7.js.map} +1 -1
  57. package/dist/{chunk-jn8hh25v.js → chunk-7v8sgqen.js} +2 -2
  58. package/dist/{chunk-jn8hh25v.js.map → chunk-7v8sgqen.js.map} +1 -1
  59. package/dist/{chunk-57edag57.js → chunk-8c2fs0n0.js} +3 -3
  60. package/dist/{chunk-57edag57.js.map → chunk-8c2fs0n0.js.map} +1 -1
  61. package/dist/{chunk-0z2h35d7.js → chunk-8h7dh2h2.js} +2 -2
  62. package/dist/{chunk-0z2h35d7.js.map → chunk-8h7dh2h2.js.map} +1 -1
  63. package/dist/{chunk-b1mk12xg.js → chunk-8k8534kg.js} +2 -2
  64. package/dist/{chunk-b1mk12xg.js.map → chunk-8k8534kg.js.map} +1 -1
  65. package/dist/{chunk-ga7c7tq0.js → chunk-8rt4wx8z.js} +3 -3
  66. package/dist/{chunk-ga7c7tq0.js.map → chunk-8rt4wx8z.js.map} +1 -1
  67. package/dist/{chunk-es487acc.js → chunk-a5sbgffr.js} +1 -1
  68. package/dist/{chunk-vgdcz7tk.js → chunk-ap5gek56.js} +2 -2
  69. package/dist/{chunk-vgdcz7tk.js.map → chunk-ap5gek56.js.map} +1 -1
  70. package/dist/{chunk-851k0b26.js → chunk-awp3n119.js} +2 -2
  71. package/dist/{chunk-851k0b26.js.map → chunk-awp3n119.js.map} +1 -1
  72. package/dist/{chunk-d0trs736.js → chunk-cna105t6.js} +2 -2
  73. package/dist/{chunk-d0trs736.js.map → chunk-cna105t6.js.map} +1 -1
  74. package/dist/{chunk-amvy4r59.js → chunk-d4m4amy4.js} +2 -2
  75. package/dist/{chunk-amvy4r59.js.map → chunk-d4m4amy4.js.map} +1 -1
  76. package/dist/{chunk-ddad3902.js → chunk-e6fp6dxx.js} +2 -2
  77. package/dist/{chunk-ddad3902.js.map → chunk-e6fp6dxx.js.map} +1 -1
  78. package/dist/{chunk-qyp652jz.js → chunk-e7axa0d5.js} +3 -3
  79. package/dist/{chunk-qyp652jz.js.map → chunk-e7axa0d5.js.map} +1 -1
  80. package/dist/{chunk-dx7wpz5b.js → chunk-erxv1jz7.js} +2 -2
  81. package/dist/{chunk-dx7wpz5b.js.map → chunk-erxv1jz7.js.map} +1 -1
  82. package/dist/chunk-fakvf9wb.js +5 -0
  83. package/dist/{chunk-d9an2nra.js.map → chunk-fakvf9wb.js.map} +1 -1
  84. package/dist/{chunk-s9rfgxj5.js → chunk-fv9mr1t4.js} +2 -2
  85. package/dist/{chunk-s9rfgxj5.js.map → chunk-fv9mr1t4.js.map} +1 -1
  86. package/dist/{chunk-5az0mq4p.js → chunk-gdmsn3f5.js} +2 -2
  87. package/dist/{chunk-5az0mq4p.js.map → chunk-gdmsn3f5.js.map} +1 -1
  88. package/dist/{chunk-rend2sbk.js → chunk-gv91vjeb.js} +1 -1
  89. package/dist/{chunk-dan79jab.js → chunk-h2r2rdhj.js} +2 -2
  90. package/dist/{chunk-dan79jab.js.map → chunk-h2r2rdhj.js.map} +1 -1
  91. package/dist/{chunk-15a1mrdv.js → chunk-h4pazcgg.js} +2 -2
  92. package/dist/{chunk-15a1mrdv.js.map → chunk-h4pazcgg.js.map} +1 -1
  93. package/dist/{chunk-scbvv2e4.js → chunk-hrvzchxd.js} +2 -2
  94. package/dist/{chunk-scbvv2e4.js.map → chunk-hrvzchxd.js.map} +1 -1
  95. package/dist/{chunk-1pvkw2pq.js → chunk-hytt9qyj.js} +2 -2
  96. package/dist/{chunk-1pvkw2pq.js.map → chunk-hytt9qyj.js.map} +1 -1
  97. package/dist/{chunk-mx9y9mtx.js → chunk-hz6yzzbz.js} +1 -1
  98. package/dist/{chunk-eazqda9z.js → chunk-j3nr4cg0.js} +3 -3
  99. package/dist/{chunk-eazqda9z.js.map → chunk-j3nr4cg0.js.map} +1 -1
  100. package/dist/{chunk-2taa0brj.js → chunk-jk97wv0q.js} +2 -2
  101. package/dist/{chunk-2taa0brj.js.map → chunk-jk97wv0q.js.map} +1 -1
  102. package/dist/{chunk-mrdarm2q.js → chunk-jv4g8grc.js} +2 -2
  103. package/dist/{chunk-mrdarm2q.js.map → chunk-jv4g8grc.js.map} +1 -1
  104. package/dist/{chunk-gcs9ydjv.js → chunk-jyrsd1dn.js} +2 -2
  105. package/dist/{chunk-gcs9ydjv.js.map → chunk-jyrsd1dn.js.map} +1 -1
  106. package/dist/{chunk-yv1psptb.js → chunk-jzp0fs6h.js} +2 -2
  107. package/dist/{chunk-yv1psptb.js.map → chunk-jzp0fs6h.js.map} +1 -1
  108. package/dist/{chunk-tmrmwthr.js → chunk-kcx468qv.js} +2 -2
  109. package/dist/{chunk-tmrmwthr.js.map → chunk-kcx468qv.js.map} +1 -1
  110. package/dist/{chunk-zfter1x0.js → chunk-kg1nbxvm.js} +4 -4
  111. package/dist/{chunk-zfter1x0.js.map → chunk-kg1nbxvm.js.map} +1 -1
  112. package/dist/{chunk-9hr0bcfy.js → chunk-kqb4s1r0.js} +3 -3
  113. package/dist/{chunk-9hr0bcfy.js.map → chunk-kqb4s1r0.js.map} +1 -1
  114. package/dist/{chunk-53bek7sp.js → chunk-m17ktssc.js} +1 -1
  115. package/dist/{chunk-75ptmewf.js → chunk-m2yfvwrn.js} +2 -2
  116. package/dist/{chunk-75ptmewf.js.map → chunk-m2yfvwrn.js.map} +1 -1
  117. package/dist/{chunk-ck0v2kzw.js → chunk-mqcy5vja.js} +2 -2
  118. package/dist/{chunk-ck0v2kzw.js.map → chunk-mqcy5vja.js.map} +1 -1
  119. package/dist/{chunk-f1y8eggf.js → chunk-n672d4g8.js} +2 -2
  120. package/dist/{chunk-f1y8eggf.js.map → chunk-n672d4g8.js.map} +1 -1
  121. package/dist/{chunk-p2fhtf5r.js → chunk-nek1gzz2.js} +3 -3
  122. package/dist/{chunk-p2fhtf5r.js.map → chunk-nek1gzz2.js.map} +1 -1
  123. package/dist/{chunk-jdtn0zk2.js → chunk-pmywkp1w.js} +3 -3
  124. package/dist/{chunk-jdtn0zk2.js.map → chunk-pmywkp1w.js.map} +1 -1
  125. package/dist/chunk-q95k1ymq.js +4 -0
  126. package/dist/{chunk-ryzcfxq7.js.map → chunk-q95k1ymq.js.map} +3 -3
  127. package/dist/{chunk-30yg31sz.js → chunk-r4namj39.js} +2 -2
  128. package/dist/{chunk-30yg31sz.js.map → chunk-r4namj39.js.map} +1 -1
  129. package/dist/{chunk-a9q2cr4w.js → chunk-rrqr1dwq.js} +2 -2
  130. package/dist/{chunk-a9q2cr4w.js.map → chunk-rrqr1dwq.js.map} +1 -1
  131. package/dist/{chunk-xv74rhay.js → chunk-tp3mzj4v.js} +2 -2
  132. package/dist/{chunk-xv74rhay.js.map → chunk-tp3mzj4v.js.map} +1 -1
  133. package/dist/{chunk-csbc1fxa.js → chunk-ty4aj41k.js} +3 -3
  134. package/dist/{chunk-csbc1fxa.js.map → chunk-ty4aj41k.js.map} +1 -1
  135. package/dist/chunk-v9na3dny.js +46 -0
  136. package/dist/{chunk-4sb1484x.js.map → chunk-v9na3dny.js.map} +11 -9
  137. package/dist/{chunk-kk502yk2.js → chunk-w2fpr99k.js} +2 -2
  138. package/dist/{chunk-kk502yk2.js.map → chunk-w2fpr99k.js.map} +1 -1
  139. package/dist/{chunk-et3vhkbf.js → chunk-wwmdqhzy.js} +2 -2
  140. package/dist/{chunk-et3vhkbf.js.map → chunk-wwmdqhzy.js.map} +1 -1
  141. package/dist/chunk-wysm6qte.js +5 -0
  142. package/dist/chunk-wysm6qte.js.map +12 -0
  143. package/dist/{chunk-j9jqxv1d.js → chunk-x157wrgy.js} +2 -2
  144. package/dist/{chunk-j9jqxv1d.js.map → chunk-x157wrgy.js.map} +1 -1
  145. package/dist/{chunk-mvtgx1mr.js → chunk-xrh6k13s.js} +2 -2
  146. package/dist/{chunk-mvtgx1mr.js.map → chunk-xrh6k13s.js.map} +1 -1
  147. package/dist/{chunk-xs4c2nvz.js → chunk-y0wx6w80.js} +2 -2
  148. package/dist/{chunk-xs4c2nvz.js.map → chunk-y0wx6w80.js.map} +1 -1
  149. package/dist/{chunk-wexs11yy.js → chunk-yp5979we.js} +2 -2
  150. package/dist/{chunk-wexs11yy.js.map → chunk-yp5979we.js.map} +1 -1
  151. package/dist/{chunk-qtbf3w6w.js → chunk-z32xfe8c.js} +2 -2
  152. package/dist/{chunk-qtbf3w6w.js.map → chunk-z32xfe8c.js.map} +1 -1
  153. package/dist/{chunk-d8ekyng4.js → chunk-zgn0p8qr.js} +3 -3
  154. package/dist/{chunk-d8ekyng4.js.map → chunk-zgn0p8qr.js.map} +1 -1
  155. package/dist/{chunk-rx2shb3t.js → chunk-zns7xcz9.js} +1 -1
  156. package/dist/config/index.js +1 -1
  157. package/dist/console/run.js +2 -2
  158. package/dist/console/run.js.map +1 -1
  159. package/dist/container/index.js +2 -2
  160. package/dist/container/index.js.map +1 -1
  161. package/dist/database/index.js +2 -2
  162. package/dist/database/index.js.map +1 -1
  163. package/dist/email/index.js +2 -2
  164. package/dist/email/index.js.map +1 -1
  165. package/dist/facades/index.js +2 -2
  166. package/dist/facades/index.js.map +1 -1
  167. package/dist/foundation/index.js +2 -2
  168. package/dist/foundation/index.js.map +1 -1
  169. package/dist/http/HttpRequest.d.ts +31 -0
  170. package/dist/http/HttpRequest.d.ts.map +1 -1
  171. package/dist/http/McpRouter.d.ts +54 -1
  172. package/dist/http/McpRouter.d.ts.map +1 -1
  173. package/dist/http/RateLimitMiddleware.d.ts +4 -1
  174. package/dist/http/RateLimitMiddleware.d.ts.map +1 -1
  175. package/dist/http/index.d.ts +1 -0
  176. package/dist/http/index.d.ts.map +1 -1
  177. package/dist/http/index.js +2 -2
  178. package/dist/http/index.js.map +1 -1
  179. package/dist/http/modelOriginated.d.ts +36 -2
  180. package/dist/http/modelOriginated.d.ts.map +1 -1
  181. package/dist/i18n/dictionaryRuntime.js +2 -2
  182. package/dist/i18n/dictionaryRuntime.js.map +1 -1
  183. package/dist/i18n/index.js +2 -2
  184. package/dist/i18n/index.js.map +1 -1
  185. package/dist/kernel/Kernel.d.ts +3 -0
  186. package/dist/kernel/Kernel.d.ts.map +1 -1
  187. package/dist/kernel/index.js +3 -3
  188. package/dist/kernel/index.js.map +3 -3
  189. package/dist/orm/index.js +2 -2
  190. package/dist/orm/index.js.map +1 -1
  191. package/dist/server/index.js +2 -2
  192. package/dist/server/index.js.map +1 -1
  193. package/dist/services/index.d.ts +8 -2
  194. package/dist/services/index.d.ts.map +1 -1
  195. package/dist/services/index.js +44 -9
  196. package/dist/services/index.js.map +8 -6
  197. package/dist/services/mcp/McpRegistry.d.ts +190 -29
  198. package/dist/services/mcp/McpRegistry.d.ts.map +1 -1
  199. package/dist/services/mcp/http/McpHttpServer.d.ts +153 -0
  200. package/dist/services/mcp/http/McpHttpServer.d.ts.map +1 -0
  201. package/dist/services/mcp/http/callers.d.ts +131 -0
  202. package/dist/services/mcp/http/callers.d.ts.map +1 -0
  203. package/dist/services/mcp/http/limits.d.ts +11 -0
  204. package/dist/services/mcp/http/limits.d.ts.map +1 -0
  205. package/dist/services/mcp/http/oauth/McpOAuthServer.d.ts +150 -0
  206. package/dist/services/mcp/http/oauth/McpOAuthServer.d.ts.map +1 -0
  207. package/dist/services/mcp/http/oauth/consentPage.d.ts +14 -0
  208. package/dist/services/mcp/http/oauth/consentPage.d.ts.map +1 -0
  209. package/dist/services/mcp/http/oauth/store.d.ts +98 -0
  210. package/dist/services/mcp/http/oauth/store.d.ts.map +1 -0
  211. package/dist/services/mcp/http/protocol.d.ts +95 -0
  212. package/dist/services/mcp/http/protocol.d.ts.map +1 -0
  213. package/dist/services/mcp/http/signedState.d.ts +25 -0
  214. package/dist/services/mcp/http/signedState.d.ts.map +1 -0
  215. package/dist/services/queue/work.js +2 -2
  216. package/dist/services/queue/work.js.map +1 -1
  217. package/dist/services/router/ApiRouteDispatcher.d.ts +29 -0
  218. package/dist/services/router/ApiRouteDispatcher.d.ts.map +1 -1
  219. package/dist/services/router/RouteServiceProvider.d.ts +6 -0
  220. package/dist/services/router/RouteServiceProvider.d.ts.map +1 -1
  221. package/dist/services/router/config.d.ts +16 -0
  222. package/dist/services/router/config.d.ts.map +1 -1
  223. package/dist/stats/route-table.js +1 -1
  224. package/dist/support/index.js +2 -2
  225. package/dist/support/index.js.map +1 -1
  226. package/dist/vitest/index.js +1 -1
  227. package/package.json +1 -1
  228. package/dist/chunk-3z9vhjd7.js +0 -5
  229. package/dist/chunk-3z9vhjd7.js.map +0 -10
  230. package/dist/chunk-4sb1484x.js +0 -46
  231. package/dist/chunk-bf1ets45.js +0 -5
  232. package/dist/chunk-bf1ets45.js.map +0 -33
  233. package/dist/chunk-d9an2nra.js +0 -5
  234. package/dist/chunk-j0sncgxc.js +0 -14
  235. package/dist/chunk-ryzcfxq7.js +0 -4
  236. /package/dist/{chunk-es487acc.js.map → chunk-a5sbgffr.js.map} +0 -0
  237. /package/dist/{chunk-rend2sbk.js.map → chunk-gv91vjeb.js.map} +0 -0
  238. /package/dist/{chunk-mx9y9mtx.js.map → chunk-hz6yzzbz.js.map} +0 -0
  239. /package/dist/{chunk-53bek7sp.js.map → chunk-m17ktssc.js.map} +0 -0
  240. /package/dist/{chunk-rx2shb3t.js.map → chunk-zns7xcz9.js.map} +0 -0
@@ -1,4 +1,4 @@
1
1
  // @bun
2
- import{da as a}from"../chunk-es487acc.js";import"../chunk-csbc1fxa.js";import"../chunk-amvy4r59.js";import"../chunk-a9q2cr4w.js";import"../chunk-ddad3902.js";export{a as gemiPlugin};
2
+ import{da as a}from"../chunk-a5sbgffr.js";import"../chunk-ty4aj41k.js";import"../chunk-d4m4amy4.js";import"../chunk-rrqr1dwq.js";import"../chunk-e6fp6dxx.js";export{a as gemiPlugin};
3
3
 
4
4
  //# debugId=255F25075168278464756E2164756E21
@@ -1,4 +1,4 @@
1
1
  // @bun
2
- import{da as k}from"../chunk-es487acc.js";import"../chunk-csbc1fxa.js";import"../chunk-amvy4r59.js";import"../chunk-a9q2cr4w.js";import{xa as j}from"../chunk-303mprnv.js";import"../chunk-ddad3902.js";var{plugin:q}=globalThis.Bun;q(k());var y=await j(process.cwd());for(let x of y.bun?.plugins??[])q(x);
2
+ import{da as k}from"../chunk-a5sbgffr.js";import"../chunk-ty4aj41k.js";import"../chunk-d4m4amy4.js";import"../chunk-rrqr1dwq.js";import{xa as j}from"../chunk-303mprnv.js";import"../chunk-e6fp6dxx.js";var{plugin:q}=globalThis.Bun;q(k());var y=await j(process.cwd());for(let x of y.bun?.plugins??[])q(x);
3
3
 
4
4
  //# debugId=E7ABFC04ABC989B264756E2164756E21
@@ -0,0 +1,14 @@
1
+ // @bun
2
+ import{Qg as z,Rg as i,Sg as t}from"./chunk-75wk4jxd.js";import{Vg as C}from"./chunk-jzp0fs6h.js";import{ai as S0}from"./chunk-j3nr4cg0.js";import{mi as v}from"./chunk-56fgk5rq.js";import{ti as zH}from"./chunk-e6fp6dxx.js";class U0{static kind="controller";constructor(){}}class p0 extends U0{}function s(H){let Q=new Map;if(!H)return Q;for(let X of H.split(";")){let $=X.indexOf("=");if($===-1)continue;let Z=X.slice(0,$).trim();if(!Z)continue;Q.set(Z,X.slice($+1).trim())}return Q}function xH(H){return s(H.headers.get("cookie"))}function I(H){if(!/^\d+$/.test(H))return null;let Q=Number(H);return Number.isSafeInteger(Q)?Q:null}function K0(H){if(!H)return null;let Q=H.trim();if(!/^bytes=/i.test(Q))return null;let $=Q.slice(6).split(",").map((K)=>K.trim()).filter((K)=>K!=="");if($.length!==1)return null;let Z=$[0],G=Z.indexOf("-");if(G===-1)return null;let W=Z.slice(0,G),Y=Z.slice(G+1);if(W===""){let K=I(Y);if(K===null)return null;return{kind:"suffix",suffixLength:K}}let D=I(W);if(D===null)return null;if(Y==="")return{kind:"offset",start:D,end:null};let T=I(Y);if(T===null||T<D)return null;return{kind:"offset",start:D,end:T}}function B0(H,Q){if(!Number.isFinite(Q)||Q<=0)return null;let X,$;if(H.kind==="suffix"){if(H.suffixLength<=0)return null;X=Math.max(0,Q-H.suffixLength),$=Q-1}else{if(H.start>=Q)return null;if(X=H.start,$=H.end===null?Q-1:Math.min(H.end,Q-1),$<X)return null}return{start:X,end:$,length:$-X+1}}function SH(H){if(H.kind==="suffix")return`bytes=-${H.suffixLength}`;return H.end===null?`bytes=${H.start}-`:`bytes=${H.start}-${H.end}`}function gH(H){if(!H)return null;let Q=/^bytes\s+(\d+)-(\d+)\/(\d+)$/i.exec(H.trim());if(!Q)return null;let X=I(Q[1]),$=I(Q[2]),Z=I(Q[3]);if(X===null||$===null||Z===null||$<X)return null;return{start:X,end:$,total:Z}}function yH(H,Q,X){return`bytes ${H}-${Q}/${X}`}function P0(H){return`bytes */${H}`}class x extends z{errors={};constructor(H){super("Validation error");this.name="ValidationError",this.errors=H,this.payload={api:{status:400,data:{error:{kind:"validation_error",messages:H,status:400}},headers:{"Content-Type":"application/json"}},view:{status:400}}}}function h0(H){let[Q,X]=H.match(/\d+|\D+/g)??[];if(!Q||!X)return 0;let $=Number.parseInt(Q);switch(X){case"B":return $;case"KB":return $*1024;case"MB":return $*1024*1024;case"GB":return $*1024*1024*1024;case"TB":return $*1024*1024*1024*1024;default:return 0}}function c0(H){switch(H){case"image":return"image";case"png":return"image/png";case"jpg":return"image/jpeg";case"jpeg":return"image/jpeg";case"ttf":return"font/ttf";case"excel":return"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";case"csv":return"text/csv";case"word":return"application/vnd.openxmlformats-officedocument.wordprocessingml.document";case"pdf":return"application/pdf";case"json":return"application/json";default:return H}}function z0(H){if(typeof H==="string"||Array.isArray(H))return H.length;return}function a(H){return typeof H==="number"&&!Number.isNaN(H)}var m0=["required","string","boolean","number","email","password","min","max","gte","lte","file","fileType","fileSize","array","object","in"];class L extends Error{name="InvalidValidationRuleError"}function h(H,Q){let X=Q===void 0||Q.trim()===""?Number.NaN:Number(Q);if(Number.isNaN(X))throw new L(`Validation rule "${H}:${Q??""}" needs a number, e.g. "${H}:3"`);return X}function F0(H){let Q=H.indexOf(":"),X=Q===-1?H:H.slice(0,Q),$=Q===-1?void 0:H.slice(Q+1);switch(X){case"required":return(Z)=>{if(Z instanceof Blob)return Z.size>0;if(Z===null||Z===void 0)return!1;if(typeof Z==="string"||Array.isArray(Z))return Z.length>0;return!0};case"string":return(Z)=>typeof Z==="string";case"boolean":return(Z)=>typeof Z==="boolean";case"number":return(Z)=>a(Z);case"password":return(Z)=>{return typeof Z==="string"&&/^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[^a-zA-Z0-9]).{8,}$/.test(Z)};case"min":{let Z=h(X,$);return(G)=>{let W=z0(G);return W!==void 0&&W>=Z}}case"max":{let Z=h(X,$);return(G)=>{let W=z0(G);return W!==void 0&&W<=Z}}case"gte":{let Z=h(X,$);return(G)=>a(G)&&G>=Z}case"lte":{let Z=h(X,$);return(G)=>a(G)&&G<=Z}case"email":return(Z)=>{return typeof Z==="string"&&/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(Z)};case"file":return(Z)=>{return Z instanceof Blob};case"fileType":{if(!$)throw new L('Validation rule "fileType" needs a type, e.g. "fileType:png" or "fileType:image"');let Z=c0($);return(G)=>G instanceof Blob&&G.type.startsWith(Z)}case"fileSize":{let Z=h0($??"");if(Z===0&&!/^0+(B|KB|MB|GB|TB)$/.test($??""))throw new L(`Validation rule "fileSize:${$??""}" needs a whole size in B, KB, MB, GB or TB, e.g. "fileSize:5MB"`);return(G)=>G instanceof Blob&&G.size<=Z}case"array":return(Z)=>Array.isArray(Z);case"object":return(Z)=>typeof Z==="object"&&Z!==null&&!Array.isArray(Z)&&!(Z instanceof Blob);case"in":{let Z=($??"").split(",").filter((G)=>G!=="");if(Z.length===0)throw new L('Validation rule "in" needs a comma-separated list, e.g. "in:draft,published"');return(G)=>typeof G==="string"&&Z.includes(G)}default:throw new L(`Unknown validation rule "${H}". Known rules: ${m0.join(", ")}`)}}function q(H){if(!H.definition)throw Error(`gemi/ai: the recursive schema "${H.name}" was used before its definition returned; \`self\` can be nested into the schema, but not parsed or emitted inside the callback`);return H.definition}var n=new WeakMap;function J0(H){return typeof H==="object"&&H!==null&&n.has(H)}function m(H){let Q=n.get(H);if(!Q)throw Error("gemi/ai: expected a schema built with `s`, got a foreign object");return Q}function d0(H){let Q={defs:{},cells:new Map},X=H;if(H.node.kind==="ref"){let Z=q(H.node.cell);X={...Z,...H.description?{description:H.description}:{},optional:H.optional,nullable:H.nullable||Z.nullable}}let $=S(X,Q);return Object.keys(Q.defs).length>0?{...$,$defs:Q.defs}:$}function S(H,Q){let X=(H.optional||H.nullable)&&H.node.kind!=="json",$=n0(o0(H.node,Q),X),Z=[H.description,u0(H.node)].filter(Boolean).join(" ");if(Z&&$.$ref!==void 0)$={anyOf:[$]};return Z?{description:Z,...$}:$}function u0(H){let Q=[];if(H.kind==="string"||H.kind==="enum"){let X=H.checks;if(X?.format)Q.push(`Format: ${X.format.name}.`);if(X?.minLength!==void 0)Q.push(`At least ${X.minLength} characters.`);if(X?.maxLength!==void 0)Q.push(`At most ${X.maxLength} characters.`)}else if(H.kind==="number"){let X=H.checks;if(X?.minimum!==void 0)Q.push(`Minimum ${X.minimum}.`);if(X?.exclusiveMinimum!==void 0)Q.push(`Greater than ${X.exclusiveMinimum}.`);if(X?.maximum!==void 0)Q.push(`Maximum ${X.maximum}.`);if(X?.exclusiveMaximum!==void 0)Q.push(`Less than ${X.exclusiveMaximum}.`)}else if(H.kind==="array"){let X=H.checks;if(X?.minItems!==void 0)Q.push(`At least ${X.minItems} items.`);if(X?.maxItems!==void 0)Q.push(`At most ${X.maxItems} items.`)}return Q.join(" ")}function o0(H,Q){switch(H.kind){case"string":return{type:"string"};case"number":return{type:H.checks?.integer?"integer":"number"};case"boolean":return{type:"boolean"};case"literal":return{type:typeof H.value,const:H.value};case"enum":return{type:"string",enum:H.values};case"array":return{type:"array",items:S(H.item,Q)};case"object":return{type:"object",properties:Object.fromEntries(Object.entries(H.shape).map(([X,$])=>[X,S($,Q)])),required:Object.keys(H.shape),additionalProperties:!1};case"union":return{anyOf:H.members.map((X)=>S(X,Q))};case"json":return{};case"ref":{let{cell:X}=H,$=Q.cells.get(X.name);if($&&$!==X)throw Error(`gemi/ai: two different recursive schemas are named "${X.name}" in one schema; give each s.recursive(...) its own name`);if(!$)Q.cells.set(X.name,X),Q.defs[X.name]={},Q.defs[X.name]=S(q(X),Q);return{$ref:`#/$defs/${X.name}`}}}}function n0(H,Q){if(!Q)return H;if(H.anyOf)return{...H,anyOf:[...H.anyOf,{type:"null"}]};if(H.enum||H.const!==void 0)return{anyOf:[H,{type:"null"}]};if(typeof H.type==="string")return{...H,type:[H.type,"null"]};return{anyOf:[H,{type:"null"}]}}function i0(H){if(H===null)return"null";if(Array.isArray(H))return"array";return typeof H}function t0(H,Q){if(typeof Q==="number"&&!Number.isFinite(Q))return String(Q);if(H.kind==="literal"||H.kind==="enum"){if(typeof Q==="string"||typeof Q==="number"||typeof Q==="boolean")return JSON.stringify(Q)}return i0(Q)}function L0(H){let Q=H.node,X=(()=>{switch(Q.kind){case"number":return Q.checks?.integer?"integer":"number";case"string":case"boolean":return Q.kind;case"literal":return JSON.stringify(Q.value);case"enum":return`one of ${Q.values.map(($)=>JSON.stringify($)).join(" | ")}`;case"array":return"array";case"object":return"object";case"union":return"one of the variants";case"json":return"a JSON value";case"ref":return L0({...q(Q.cell),optional:!1,nullable:!1})}})();return H.optional||H.nullable?`${X} or null`:X}function l0(H){let Q="";for(let X of H)Q+=typeof X==="number"?`[${X}]`:Q?`.${X}`:X;return Q}function r0(H){let Q=l0(H);return Q?`${Q}: `:""}function e(H){return`${r0(H.path)}${H.message}`}function d(H,Q){if(Q===null||Q===void 0)return H.optional||H.nullable?1:0;let X=H.node;switch(X.kind){case"string":return typeof Q==="string"?1:0;case"number":return typeof Q==="number"?1:0;case"boolean":return typeof Q==="boolean"?1:0;case"literal":return Q===X.value?10:0;case"enum":return typeof Q==="string"&&X.values.includes(Q)?10:0;case"array":return Array.isArray(Q)?1:0;case"object":{if(typeof Q!=="object"||Array.isArray(Q))return 0;let $=Q,Z=1;for(let[G,W]of Object.entries(X.shape))Z+=d(W,$[G]);return Z}case"union":return X.members.reduce(($,Z)=>Math.max($,d(Z,Q)),0);case"json":return 1;case"ref":return C0(X.cell,Q,()=>1,()=>d(q(X.cell),Q))}}function C0(H,Q,X,$){if(typeof Q!=="object"||Q===null)return $();if(H.active.has(Q))return X();H.active.add(Q);try{return $()}finally{H.active.delete(Q)}}function _(H,Q,X,$){if(H.optional&&(Q===null||Q===void 0))return{drop:!0,value:void 0};if(H.nullable&&Q===null)return{drop:!1,value:null};return{drop:!1,value:s0(H,Q,X,$)}}function s0(H,Q,X,$){let Z=H.node,G=()=>{let W=Q===void 0?"required":Z.kind==="literal"?"const":Z.kind==="enum"&&typeof Q==="string"?"enum":"type",Y=W==="const"?{allowedValue:Z.value}:W==="enum"?{allowedValues:Z.values}:{};$.push({path:X,code:W,message:`expected ${L0(H)}, got ${t0(Z,Q)}`,params:Y});return};switch(Z.kind){case"string":if(typeof Q!=="string")return G();return R0(Z.checks,Q,X,$),Q;case"number":if(typeof Q!=="number"||!Number.isFinite(Q))return G();if(Z.checks?.integer&&!Number.isInteger(Q))return G();return e0(Z.checks,Q,X,$),Q;case"boolean":return typeof Q==="boolean"?Q:G();case"literal":return Q===Z.value?Q:G();case"enum":if(typeof Q!=="string"||!Z.values.includes(Q))return G();return R0(Z.checks,Q,X,$),Q;case"array":{if(!Array.isArray(Q))return G();let W=Q.map((T,K)=>{let w=_(Z.item,T,[...X,K],$);return w.drop?void 0:w.value}),{minItems:Y,maxItems:D}=Z.checks??{};if(Y!==void 0&&Q.length<Y)$.push({path:X,code:"minItems",message:`expected at least ${Y} items, got ${Q.length}`,params:{limit:Y}});if(D!==void 0&&Q.length>D)$.push({path:X,code:"maxItems",message:`expected at most ${D} items, got ${Q.length}`,params:{limit:D}});return W}case"object":{if(typeof Q!=="object"||Q===null||Array.isArray(Q))return G();let W=Q,Y={};for(let[D,T]of Object.entries(Z.shape)){let K=_(T,W[D],[...X,D],$);if(!K.drop)Y[D]=K.value}if(Z.unknownKeys)for(let D of Object.keys(W)){if(Object.hasOwn(Z.shape,D)||W[D]===void 0)continue;if(Z.unknownKeys==="error"){$.push({path:[...X,D],code:"additionalProperties",message:"unknown key",params:{additionalProperty:D}});continue}k(W[D],[...X,D],$,new Set),Object.defineProperty(Y,D,{value:W[D],enumerable:!0,writable:!0,configurable:!0})}return Y}case"union":{let W;for(let Y of Z.members){let D=[],T=_(Y,Q,X,D);if(D.length===0)return T.drop?void 0:T.value;let K=d(Y,Q);if(!W||K>W.score)W={issues:D,score:K}}$.push({path:X,code:"anyOf",message:`no matching variant; closest: ${W.issues.map(e).join("; ")}`,params:{closest:W.issues}});return}case"json":if(Q===void 0)return G();return k(Q,X,$,new Set),Q;case"ref":return C0(Z.cell,Q,()=>{$.push({path:X,code:"type",message:"expected a finite tree, got a circular reference",params:{}});return},()=>_(q(Z.cell),Q,X,$).value)}}function a0(H){let Q=0;for(let X of H)Q++;return Q}function R0(H,Q,X,$){if(!H)return;let{minLength:Z,maxLength:G,format:W}=H;if(Z!==void 0||G!==void 0){let Y=a0(Q);if(Z!==void 0&&Y<Z)$.push({path:X,code:"minLength",message:`expected at least ${Z} characters, got ${Y}`,params:{limit:Z}});if(G!==void 0&&Y>G)$.push({path:X,code:"maxLength",message:`expected at most ${G} characters, got ${Y}`,params:{limit:G}})}if(W){let Y=!1;try{Y=W.test(Q)===!0}catch{}if(!Y)$.push({path:X,code:"format",message:`expected a string in format "${W.name}"`,params:{format:W.name}})}}function e0(H,Q,X,$){if(!H)return;let Z=(G,W,Y,D)=>{if(W===void 0||Y(W))return;$.push({path:X,code:G,message:`expected ${D} ${W}, got ${Q}`,params:{limit:W}})};Z("minimum",H.minimum,(G)=>Q>=G,"at least"),Z("exclusiveMinimum",H.exclusiveMinimum,(G)=>Q>G,"more than"),Z("maximum",H.maximum,(G)=>Q<=G,"at most"),Z("exclusiveMaximum",H.exclusiveMaximum,(G)=>Q<G,"less than")}function k(H,Q,X,$,Z=!0){let G=(Y)=>{X.push({path:Q,code:"type",message:`expected a JSON value, got ${Y}`,params:{}})};switch(typeof H){case"undefined":case"string":case"boolean":return;case"number":if(!Number.isFinite(H))G(String(H));return;case"bigint":return G("a bigint");case"function":return G("a function");case"symbol":return G("a symbol")}if(H===null)return;let W=H;if($.has(W))return G("a circular reference");$.add(W);try{let Y=Z?W.toJSON:void 0;if(typeof Y==="function"){let D;try{D=Y.call(W)}catch{return G("a toJSON that threw")}if(D===void 0)return G("a toJSON that returns undefined");return k(D,Q,X,$,!1)}if(Array.isArray(H))H.forEach((D,T)=>k(D,[...Q,T],X,$));else for(let[D,T]of Object.entries(W))k(T,[...Q,D],X,$)}finally{$.delete(W)}}function F(H){return u(H)}function u(H){let Q={toJSONSchema:()=>d0(H),parse(X){let $=[],Z=_(H,X,[],$);if($.length>0)throw Error($.map(e).join("; "));return Z.drop?void 0:Z.value},safeParse(X){let $=[],Z=_(H,X,[],$);if($.length>0)return{ok:!1,errors:$.map(e)};return{ok:!0,value:Z.drop?void 0:Z.value}},validate(X){let $=[],Z=_(H,X,[],$);if($.length>0)return{ok:!1,issues:$};return{ok:!0,value:Z.drop?void 0:Z.value}},describe:(X)=>u({...H,description:X}),optional:()=>u({...H,optional:!0}),nullable:()=>u({...H,nullable:!0,optional:!1})};return n.set(Q,H),Q}function A(H){return{node:H,optional:!1,nullable:!1}}var A0=["strip","error","passthrough"];class V0 extends Error{problems;constructor(H){super(`gemi/ai: s.fromJSONSchema cannot model this schema:
3
+ ${H.map((Q)=>`- ${Q}`).join(`
4
+ `)}`);this.name="JSONSchemaError",this.problems=H}}var HH=new Set(["title","$schema","$id","$comment","examples","default","deprecated","readOnly","writeOnly"]),E={string:["minLength","maxLength","format"],number:["minimum","maximum","exclusiveMinimum","exclusiveMaximum"],integer:["minimum","maximum","exclusiveMinimum","exclusiveMaximum"],boolean:[],object:["properties","required","additionalProperties"],array:["items","minItems","maxItems"]};function c(H){return typeof H==="object"&&H!==null&&!Array.isArray(H)}function o(H,Q,X,$){let Z=(M,U=X)=>{$.push(U?`${U}: ${M}`:M);return},G=(M)=>X?`${X}.${M}`:M;if(!c(H))return Z("expected a schema object");let W=new Set(Q.ignoreKeywords??[]),Y=(M)=>HH.has(M)||M.startsWith("x-")||W.has(M),D=!1,T=H.type;if(Array.isArray(T)){let M=T.filter((U)=>U!=="null");if(M.length!==1)return Z(`type ${JSON.stringify(T)} is not supported; only one type, optionally with "null". Use anyOf for alternatives`,G("type"));D=M.length<T.length,T=M[0]}if(T!==void 0&&(typeof T!=="string"||!(T in E)))return Z(`type ${JSON.stringify(T)} is not supported; expected one of ${Object.keys(E).join(", ")}`,G("type"));let K=new Set(["type","description","enum","const","anyOf",...T?E[T]:[]]),w=!1;for(let M of Object.keys(H)){if(K.has(M)||Y(M))continue;w=!0;let U=Object.entries(E).find(([,P])=>P.includes(M));Z(U&&U[0]!==T?`"${M}" applies to type ${U[0]}, and this schema is ${T?`type ${T}`:"untyped"}`:`"${M}" is not supported by s.fromJSONSchema`,G(M))}if(w)return;if(H.description!==void 0&&typeof H.description!=="string")return Z("expected a string",G("description"));let p=H.description,J=(M)=>({node:M,optional:!1,nullable:D,...p?{description:p}:{}});if(H.anyOf!==void 0){if(T!==void 0||H.enum!==void 0||H.const!==void 0)return Z("anyOf cannot be combined with type, enum or const here",G("anyOf"));if(!Array.isArray(H.anyOf)||H.anyOf.length===0)return Z("expected a non-empty array",G("anyOf"));let M=[],U=!1;if(H.anyOf.forEach((P,B)=>{if(c(P)&&P.type==="null"&&Object.keys(P).length===1){D=!0;return}let R=o(P,Q,G(`anyOf[${B}]`),$);if(R)M.push(R);else U=!0}),U)return;if(M.length===0)return Z("anyOf has only null in it",G("anyOf"));if(M.length===1){let P=M[0];return{...P,nullable:P.nullable||D,...p?{description:p}:{}}}return J({kind:"union",members:M})}if(H.const!==void 0){let M=H.const;if(typeof M!=="string"&&typeof M!=="number"&&typeof M!=="boolean")return Z("only a string, number or boolean const is supported",G("const"));if(T!==void 0&&typeof M!==(T==="integer"?"number":T))return Z(`const ${JSON.stringify(M)} is not of type ${T}`,G("const"));return J({kind:"literal",value:M})}let O;if(T==="string"){if(O=QH(H,Q,G,$),O===null)return}if(H.enum!==void 0){if(!Array.isArray(H.enum)||H.enum.length===0)return Z("expected a non-empty array",G("enum"));let M=H.enum.filter((B)=>B!==null);if(M.length<H.enum.length)D=!0;let U=M.find((B)=>!(typeof B==="string"||typeof B==="number"||typeof B==="boolean")||T!==void 0&&typeof B!==(T==="integer"?"number":T));if(U!==void 0||M.length===0)return Z(T?`every value must be of type ${T}${M.length===0?", and there must be one":`; ${JSON.stringify(U)} is not`}`:"only strings, numbers and booleans are supported",G("enum"));if(M.every((B)=>typeof B==="string"))return J({kind:"enum",values:[...new Set(M)],...O?{checks:O}:{}});let P=[...new Set(M)];if(P.length===1)return J({kind:"literal",value:P[0]});return J({kind:"union",members:P.map((B)=>A({kind:"literal",value:B}))})}switch(T){case void 0:return Z("a schema needs a type, an enum, a const or an anyOf");case"string":return J({kind:"string",...O?{checks:O}:{}});case"number":case"integer":{let M=T==="integer"?{integer:!0}:{},U=!1;for(let P of E.number){let B=H[P];if(B===void 0)continue;if(typeof B!=="number"||!Number.isFinite(B)){Z("expected a number",G(P)),U=!0;continue}M[P]=B}if(U)return;return J({kind:"number",...Object.keys(M).length>0?{checks:M}:{}})}case"boolean":return J({kind:"boolean"});case"array":{if(!c(H.items))return Z('an array needs "items" to be one schema (tuples are not supported)',G("items"));let M={},U=!1;for(let B of["minItems","maxItems"]){let R=H[B];if(R===void 0)continue;if(typeof R!=="number"||!Number.isInteger(R)||R<0){Z("expected a non-negative integer",G(B)),U=!0;continue}M[B]=R}let P=o(H.items,Q,G("items"),$);if(!P||U)return;return J({kind:"array",item:P,...Object.keys(M).length>0?{checks:M}:{}})}case"object":{let M=H.properties??{};if(!c(M))return Z("expected an object",G("properties"));if(H.additionalProperties!==void 0&&H.additionalProperties!==!1)return Z("only false is supported; a record with arbitrary keys has no strict-mode form (use s.json())",G("additionalProperties"));let U=H.required??[];if(!Array.isArray(U)||!U.every((V)=>typeof V==="string"))return Z("expected an array of property names",G("required"));let P=U.filter((V)=>!Object.hasOwn(M,V));if(P.length>0)return Z(`lists properties the schema doesn't have: ${P.join(", ")}`,G("required"));let B={},R=!1;for(let[V,v0]of Object.entries(M)){let r=o(v0,Q,G(`properties.${V}`),$);if(!r){R=!0;continue}B[V]=U.includes(V)?r:{...r,optional:!0}}if(R)return;let l=Q.unknownKeys;return J({kind:"object",shape:B,...l==="error"||l==="passthrough"?{unknownKeys:l}:{}})}}return}function QH(H,Q,X,$){let Z={},G=!1;for(let W of["minLength","maxLength"]){let Y=H[W];if(Y===void 0)continue;if(typeof Y!=="number"||!Number.isInteger(Y)||Y<0){$.push(`${X(W)}: expected a non-negative integer`),G=!0;continue}Z[W]=Y}if(H.format!==void 0){let W=H.format,Y=typeof W==="string"?Q.formats?.[W]:void 0;if(typeof W!=="string")$.push(`${X("format")}: expected a string`),G=!0;else if(!Y||!Object.hasOwn(Q.formats,W))$.push(`${X("format")}: unknown format ${JSON.stringify(W)}; pass a check for it in the formats option`),G=!0;else Z.format={name:W,test:XH(Y)}}if(G)return null;return Object.keys(Z).length>0?Z:void 0}function XH(H){if(H===!0)return()=>!0;if(H instanceof RegExp)return(Q)=>{return H.lastIndex=0,H.test(Q)};return H}var pH={string:()=>F(A({kind:"string"})),number:()=>F(A({kind:"number"})),boolean:()=>F(A({kind:"boolean"})),literal:(H)=>F(A({kind:"literal",value:H})),enum:(H)=>F(A({kind:"enum",values:H})),object:(H)=>F(A({kind:"object",shape:Object.fromEntries(Object.entries(H).map(([Q,X])=>[Q,m(X)]))})),array:(H)=>F(A({kind:"array",item:m(H)})),union:(H)=>F(A({kind:"union",members:H.map(m)})),json:()=>F(A({kind:"json"})),recursive:$H,fromJSONSchema:(H,Q={})=>{let X=[];if(Q.unknownKeys!==void 0&&!A0.includes(Q.unknownKeys))throw Error(`gemi/ai: s.fromJSONSchema's unknownKeys option must be one of ${A0.map((Z)=>JSON.stringify(Z)).join(", ")}, got ${JSON.stringify(Q.unknownKeys)}`);let $=o(H,Q,"",X);if(!$||X.length>0)throw new V0(X.length>0?X:["unreadable schema"]);return F($)}};function hH(H){let Q=n.get(H);if(Q)return y(Q.node);return g(H.toJSONSchema())}function g(H){if(!(H.$ref!==void 0||H.type!==void 0||H.enum!==void 0||H.const!==void 0||H.anyOf!==void 0||H.properties!==void 0||H.items!==void 0))return!1;for(let X of Object.values(H.properties??{}))if(!g(X))return!1;if(H.items&&!g(H.items))return!1;for(let X of H.anyOf??[])if(!g(X))return!1;for(let X of Object.values(H.$defs??{}))if(!g(X))return!1;return!0}function y(H,Q=new Set){switch(H.kind){case"string":case"number":case"boolean":case"literal":case"enum":return!0;case"object":return Object.values(H.shape).every((X)=>y(X.node,Q));case"array":return y(H.item.node,Q);case"union":return H.members.every((X)=>y(X.node,Q));case"json":return!1;case"ref":if(Q.has(H.cell))return!0;return Q.add(H.cell),y(q(H.cell).node,Q)}}function H0(H,Q,X=new Set){let $=H.node;if($.kind==="union")return $.members.some((Z)=>H0(Z,Q,X));if($.kind!=="ref")return!1;if($.cell===Q)return!0;if(X.has($.cell)||!$.cell.definition)return!1;return X.add($.cell),H0($.cell.definition,Q,X)}var ZH=/^[A-Za-z_][A-Za-z0-9_-]{0,63}$/;function $H(H,Q){if(typeof H!=="string"||!ZH.test(H))throw Error(`gemi/ai: s.recursive needs a name of letters, digits, "_" and "-" (starting with a letter or "_", at most 64), got ${JSON.stringify(H)}`);let X={name:H,active:new Set},$=()=>A({kind:"ref",cell:X}),Z=m(Q(F($())));if(Z.optional)throw Error(`gemi/ai: the recursive schema "${H}" is optional() as a whole; mark the places that use it optional instead`);if(H0(Z,X))throw Error(`gemi/ai: the recursive schema "${H}" refers to itself outside any object or array, so it describes no finite value; nest \`self\` in an s.object(...) field or an s.array(...)`);return X.definition=Z,F($())}function _0(H){if(typeof H!=="string")return null;let[Q]=H.split(";",1),X=Q.trim().toLowerCase();return X===""?null:X}function j0(H){if(H===null)return!1;if(H==="application/json")return!0;let Q=H.indexOf("/");return Q>0&&H.endsWith("+json")&&H.length>Q+1+5}var b=new WeakMap;function dH(H,Q,X,$){b.set(H,{clientAddress:Q,...X?{grant:Object.freeze({...X,scopes:Object.freeze([...X.scopes])})}:{},...$?{progress:$}:{}})}function O0(H){return b.get(H)?.progress}function I0(H){return b.get(H)?.grant}function q0(H){return b.has(H)}function uH(H){return b.get(H)?.clientAddress}var N0=new WeakMap;function nH(H,Q){N0.set(H,Q)}function w0(H){return N0.get(H)??null}var Q0=new WeakMap;function iH(H,Q){let X=Q0.get(H)??[];if(!X.includes(Q))Q0.set(H,[...X,Q])}function tH(H){return Q0.get(H)??[]}class N{data;constructor(H){this.data=H}get(H){return this.data[H]}has(H){return this.data[H]!==void 0}toJSON(){return this.data}}function x0(H){return typeof H==="object"&&H!==null&&!(H instanceof Blob)}function GH(H,Q){if(!Q.includes(".")||Object.hasOwn(H,Q))return[{path:[Q],value:H[Q]}];let X=[{path:[],value:H}];for(let $ of Q.split(".")){let Z=[];for(let{path:G,value:W}of X){if($==="*"){if(Array.isArray(W))W.forEach((Y,D)=>Z.push({path:[...G,D],value:Y}));else if(x0(W))for(let[Y,D]of Object.entries(W))Z.push({path:[...G,Y],value:D});continue}if(Array.isArray(W)&&/^\d+$/.test($)){Z.push({path:[...G,Number($)],value:W[Number($)]});continue}Z.push({path:[...G,$],value:x0(W)&&Object.hasOwn(W,$)?W[$]:void 0})}X=Z}return X}function E0(H){return H.join(".")}class WH{kind;rawRequest;headers;cookies;search;schema={};routePath;params;domain;constructor(H,Q,X,$){if(!H){let D=C.getStore().req;this.params=D.params,this.rawRequest=D.rawRequest,this.kind=D.kind,this.routePath=D.routePath,this.domain=D.domain??null}else this.params=Q,this.rawRequest=H,this.routePath=$,this.kind=X??"api",this.domain=w0(H);this.headers=this.rawRequest.headers;let Z=s(this.rawRequest.headers.get("Cookie")),G=new URL(this.rawRequest.url),W=new Map;for(let[D,T]of G.searchParams)if(W.has(D)){let K=W.get(D);if(Array.isArray(K))K.push(T),W.set(D,K);else W.set(D,[K,T])}else W.set(D,T);let Y=Object.fromEntries(W.entries());this.search=new N(Y),this.cookies=Z}locale(){return C.getStore().locale}ctx(){return C.getStore()}isModelOriginated(){return q0(this.rawRequest)}mcpGrant(){return I0(this.rawRequest)??null}reportProgress(H){let Q=O0(this.rawRequest);if(!Q)return!1;return Q(H),!0}get signal(){return this.rawRequest.signal}range(){return K0(this.rawRequest.headers.get("Range"))}refine(H){return{}}async parseBody(){let H=_0(this.rawRequest.headers.get("Content-Type"));if(j0(H))return new N(await this.parseJsonBody());if(H==="application/x-www-form-urlencoded"||H==="multipart/form-data"){let Q;try{Q=await this.rawRequest.formData()}catch($){if($ instanceof z)throw $;throw new z("The request body could not be read as a form.")}let X=new Map;for(let[$,Z]of Q.entries())if(X.has($)){let G=X.get($);if(Array.isArray(G))G.push(Z);else X.set($,[G,Z])}else X.set($,Z);return new N(Object.fromEntries(X.entries()))}return new N({})}async parseJsonBody(){if(!this.rawRequest.body)return{};let H;try{H=await this.rawRequest.text()}catch(X){if(X instanceof z)throw X;throw new z("The request body could not be read.")}if(H.trim()==="")return{};let Q;try{Q=JSON.parse(H)}catch{throw new z("The request body is not valid JSON.")}if(Q===null||typeof Q!=="object")throw new z("The request body must be a JSON object.");return Q}validateInput(H){if(J0(this.schema))return this.validateWithSchema(H);let Q=H.toJSON()??{},X={},$=Object.entries(this.schema).map(([Z,G])=>({key:Z,rules:Object.entries(G).map(([W,Y])=>({rule:W,message:Y,check:typeof Y==="function"?null:this.ruleFor(Z,W)}))}));for(let{key:Z,rules:G}of $)for(let{path:W,value:Y}of GH(Q,Z)){let D=this.checkField(Y,G);if(D.length>0){let T=X[E0(W)]??=[];for(let K of D)if(!T.includes(K))T.push(K)}}if(this.addRefinements(X,Q),Object.keys(X).length>0)throw new x(X);return H}checkField(H,Q){let X=Q.some(({rule:G})=>G==="required"),$=H===void 0||H===null||H==="",Z=[];for(let{rule:G,message:W,check:Y}of Q){let D=W,T=!1;if(typeof W==="function")D=W(H),T=typeof D>"u";else T=Y(H);if(T)continue;if($&&!X)continue;if(G==="required")return[String(D)];if(!Z.includes(String(D)))Z.push(String(D))}return Z}validateWithSchema(H){let Q=this.schema.validate(H.toJSON()),X={};if("issues"in Q)for(let Z of Q.issues){let G=E0(Z.path),W=X[G]??=[];if(!W.includes(Z.message))W.push(Z.message)}let $="value"in Q?new N(Q.value):H;if(this.addRefinements(X,$.toJSON()),Object.keys(X).length>0)throw new x(X);return $}addRefinements(H,Q){for(let[X,$]of Object.entries(this.refine(Q)??{})){let Z=H[X]??[];H[X]=Z.includes($)?Z:[...Z,$]}}ruleFor(H,Q){try{return F0(Q)}catch(X){if(X instanceof L)throw new L(`${this.constructor.name}.schema.${H}: ${X.message}`);throw X}}async input(){return this.validateInput(await this.parseBody())}async safeInput(){let H=await this.parseBody();try{return{isValid:!0,errors:{},input:this.validateInput(H)}}catch(Q){if(!(Q instanceof x))throw Q;return{isValid:!1,errors:Q.errors,input:H}}}}class YH extends z{error;constructor(H="Not authorized"){super(H);this.name="AuthorizationError",this.error=H,this.payload={api:{status:401,data:{error:t("authorization",this.error,401)}},view:{}}}}class X0 extends z{static apiStatus=403;error;constructor(H="Insufficient permissions"){super(H);this.name="InsufficientPermissionsError",this.error=H,this.payload={api:{status:X0.apiStatus,data:{error:t("permission",this.error,X0.apiStatus)}},view:{status:403}}}}class Z0 extends z{total;constructor(H){super("Range not satisfiable");this.total=H;this.name="RangeNotSatisfiableError",this.payload={api:{status:416,data:{error:i("range_not_satisfiable","Range not satisfiable",416)},headers:{"Content-Range":P0(H),"Accept-Ranges":"bytes","Cache-Control":"no-store"}},view:{}}}}class DH extends z{constructor(H="Not found"){super(H);this.name="NotFoundError",this.payload={api:{status:404,data:{error:i("not_found",H,404)},headers:{"Cache-Control":"no-store"}},view:{status:404}}}}class j extends z{fileName;constructor(H){super("File not found");this.fileName=H;this.name="FileNotFoundError",this.payload={api:{status:404,data:{error:i("not_found","Not found",404)},headers:{"Cache-Control":"no-store"}},view:{status:404}}}}class TH extends z{constructor(H={}){super("Authentication error");this.name="AuthenticationError";let Q=H.redirectTo??"/auth/sign-in";this.payload={api:{status:401,data:{error:t("authentication","Authentication error",401)}},viewData:{status:200,data:{},headers:{"Cache-Control":"private, no-cache, no-store, max-age=0, must-revalidate"},directive:{kind:"Redirect",path:Q}},view:{status:302,headers:{"Cache-Control":"private, no-cache, no-store, max-age=0, must-revalidate",Location:Q}}}}}class f{static getFacadeAccessor(){throw Error(`Facade [${this.name}] does not implement getFacadeAccessor().`)}static getFacadeRoot(){return S0(this.getFacadeAccessor())}}class $0{async delete(H){throw Error(`${this.constructor.name} does not implement delete(). Override it to remove objects from this backend.`)}async read(H){let Q=typeof H==="string"?{name:H}:H,X=await this.fetch({name:Q.name,bucket:Q.bucket});if(!X.ok)throw new j(Q.name);let $=X.headers.get("Content-Type")??"application/octet-stream",Z=X.headers.get("ETag")??void 0,G=X.headers.get("Last-Modified"),W=G?new Date(G):void 0;if(Q.range){let T=await X.blob();return{body:T,start:0,end:T.size-1,total:T.size,partial:!1,type:$,etag:Z,lastModified:W,name:Q.name}}let Y=Number(X.headers.get("Content-Length")),D=Number.isFinite(Y)?Y:0;return{body:X.body,start:0,end:D-1,total:D,partial:!1,type:$,etag:Z,lastModified:W,name:Q.name}}async size(H){let Q=typeof H==="string"?H:H.name,X=typeof H==="string"?void 0:H.bucket,$=await this.fetch({name:Q,bucket:X});if(!$.ok)throw new j(Q);let Z=Number($.headers.get("Content-Length"));if(Number.isFinite(Z))return await $.body?.cancel(),Z;return(await $.blob()).size}}function g0(H,Q){if(!Q)return H;let X=H.getReader(),$=!1,Z,G=()=>{if($=!0,Z)Q.removeEventListener("abort",Z)};return new ReadableStream({start(W){if(Z=()=>{if($)return;G(),W.error(Q.reason),X.cancel(Q.reason).catch(()=>{})},Q.aborted)Z();else Q.addEventListener("abort",Z,{once:!0})},async pull(W){let Y;try{Y=await X.read()}catch(D){if($)return;G(),W.error(D);return}if($)return;if(Y.done){G(),W.close();return}W.enqueue(Y.value)},cancel(W){return G(),X.cancel(W)}},{highWaterMark:0})}import{readdir as MH,unlink as UH}from"fs/promises";import{isAbsolute as KH,relative as BH,resolve as y0,sep as PH}from"path";class G0 extends $0{configured;constructor(H){super();this.configured=H}get folderPath(){return this.configured??`${v()}/storage`}async put(H,{signal:Q}={}){Q?.throwIfAborted();let X,$;if(H instanceof Blob)X=H,$=`${Bun.randomUUIDv7()}.${H.type.split("/")[1].split(";")[0]}`;else X=H.body,$=H.name;let Z=X instanceof Buffer?X:X instanceof Blob||X instanceof File?Buffer.from(await X.arrayBuffer()):"",G=`${this.folderPath}/${$}`;return Q?.throwIfAborted(),await Bun.write(G,Z),$}async fetch(H,{signal:Q}={}){Q?.throwIfAborted();let X=process.env.BUCKET_NAME,$;if(typeof H==="string")$=H;else X=H.bucket??X,$=H.name;if(!$)throw Error("Object name has to be specified");let Z=`${this.folderPath}/${$}`,G=Bun.file(Z),W=g0(Bun.file(Z).stream(),Q),Y=new Date(G.lastModified).toUTCString();return new Response(W,{headers:{"Content-Type":G.type,"Content-Length":String(G.size),"Cache-Control":"private, max-age=12000, must-revalidate","Last-Modified":Y}})}async read(H){let Q=typeof H==="string"?{name:H}:H,{name:X,range:$=null}=Q;if(!X)throw Error("Object name has to be specified");let Z=Bun.file(`${this.folderPath}/${X}`);if(!await Z.exists())throw new j(X);let G=Z.size,W=$?B0($,G):null;if($&&!W)throw new Z0(G);let Y=W?.start??0,D=W?W.end:G-1;return{body:W?Z.slice(Y,D+1):Z,start:Y,end:D,total:G,partial:Boolean(W),type:Z.type||"application/octet-stream",lastModified:new Date(Z.lastModified),name:X}}async size(H){let Q=typeof H==="string"?H:H.name,X=Bun.file(`${this.folderPath}/${Q}`);if(!await X.exists())throw new j(Q);return X.size}async delete(H){let Q=typeof H==="string"?H:H.name;if(!Q)throw Error("Object name has to be specified");let X=y0(this.folderPath),$=y0(X,Q),Z=BH(X,$);if(!Z||Z===".."||Z.startsWith(`..${PH}`)||KH(Z))throw Error(`Refusing to delete "${Q}": it is outside the storage folder`);try{await UH($)}catch(G){if(G?.code==="ENOENT")return;throw G}}async list(){return await MH(this.folderPath)}}function jQ(H){return H}function k0(){return{driver:new G0}}class W0{static token="filesystem";driver;constructor(H={}){this.driver=H.driver??k0().driver}}import{Buffer as FH}from"buffer";async function b0(H){try{return(await import("sharp")).default}catch(Q){throw Error(`${H} requires the 'sharp' package. Install it with \`bun add sharp\`.`,{cause:Q})}}class RH extends f{static getFacadeAccessor(){return W0}static async put(H,Q={}){return this.getFacadeRoot().driver.put(H,Q)}static async metadata(H){let Q=FH.from(await H.arrayBuffer()),X=await b0("Storage.metadata()");try{return await X(Q).metadata()}catch{return{}}}static async fetch(H,Q={}){return Q.signal?.throwIfAborted(),this.getFacadeRoot().driver.fetch(H,Q)}static async read(H,Q={}){let X=typeof H==="string"?{name:H}:{...H},$="range"in Q?Q.range??null:X.range!==void 0?X.range:C.getStore()?.rangeRequest??null;return this.getFacadeRoot().driver.read({...X,range:$})}static list(H){return this.getFacadeRoot().driver.list(H)}static async delete(H){return this.getFacadeRoot().driver.delete(H)}}import{mkdir as Y0,readdir as AH,access as JH}from"fs/promises";async function D0(H){try{return await JH(H),!0}catch{return!1}}class T0{config;static token="log";writer;isReady=!1;flushTimeout;fileSize=0;writerSize=0;isCreatingFile=!1;bootPromise=null;currentLogFilePath;get logsDirPath(){return`${v()}/storage/logs`}constructor(H){this.config=H}boot(){if(!this.bootPromise)this.bootPromise=this.createStorage().catch((H)=>{console.error("Log storage unavailable, file logging disabled",H)}).then(()=>{this.isReady=!0});return this.bootPromise}async createStorage(){let H=`${v()}/storage`;if(!await D0(H))await Y0(H);if(!await D0(this.logsDirPath))await Y0(this.logsDirPath);await this.newLogFile()}async newLogFile(){if(!await D0(this.logsDirPath))await Y0(this.logsDirPath);if(this.isCreatingFile=!0,this.currentLogFilePath){this.writer.flush(),this.writer.end(),this.writer=null;let X=new File([await Bun.file(this.currentLogFilePath).arrayBuffer()],this.currentLogFilePath.split("/").pop(),{type:"text/plain"});this.config.onLogFileClosed(X),this.fileSize=0,this.writerSize=0}let Q=(await AH(this.logsDirPath)).sort().reverse()[0];if(Q){let X=Bun.file(`${this.logsDirPath}/${Q}`);if(X.size<this.config.maxFileSize)this.currentLogFilePath=`${this.logsDirPath}/${Q}`,this.writer=X.writer(),this.writer.write(await X.text()),this.writer.write(`
5
+ `),this.writer.flush(),this.fileSize=X.size}if(!this.writer){let X=`${new Date(Date.now()).toISOString()}.log`.replaceAll(":","-");this.currentLogFilePath=`${this.logsDirPath}/${X}`;let $=Bun.file(`${this.logsDirPath}/${X}`);this.writer=$.writer(),this.fileSize=0,this.writerSize=0}this.isCreatingFile=!1}async log(H,Q,X={}){if(!this.isReady)await this.boot();let $=C.getStore(),Z={};if($)Z={url:$.req.rawRequest.url,method:$.req.rawRequest.method,headers:$.req.rawRequest.headers,body:$.req.rawRequest.body};let G={timestamp:new Date(Date.now()).toISOString(),env:Bun.env.NODE_ENV,level:H,message:Q,metadata:{...Z,...X}},W="";try{W=JSON.stringify(G)}catch(Y){console.log("Error parsing log object",Y)}try{let Y=this.config.onLogCreated(G);if(Y instanceof Promise)Y.catch((D)=>console.error("Error in onLogCreated",D))}catch(Y){console.error("Error in onLogCreated",Y)}if(!this.writer)return;this.writerSize+=W.length,this.fileSize+=W.length;try{this.writer.write(W),this.writer.write(`
6
+ `),this.tryFlush()}catch(Y){console.error("Error writing log",Y)}}async tryFlush(){if(this.fileSize>this.config.maxFileSize){if(!this.isCreatingFile)await this.newLogFile()}if(this.writerSize>this.config.maxFileSize/2)await this.writer.flush(),this.writerSize=0,await this.newLogFile();else clearTimeout(this.flushTimeout),this.flushTimeout=setTimeout(async()=>{await this.writer.flush(),this.writerSize=0},100)}}class LH extends f{static getFacadeAccessor(){return T0}static debug(H,Q){this.getFacadeRoot().log("debug",H,Q)}static info(H,Q){this.getFacadeRoot().log("info",H,Q)}static notice(H,Q){this.getFacadeRoot().log("notice",H,Q)}static warning(H,Q){this.getFacadeRoot().log("warning",H,Q)}static error(H,Q){this.getFacadeRoot().log("error",H,Q)}static critical(H,Q){this.getFacadeRoot().log("critical",H,Q)}static alert(H,Q){this.getFacadeRoot().log("alert",H,Q)}static emergency(H,Q){this.getFacadeRoot().log("emergency",H,Q)}}class CH{config;static token="redis";instance=null;constructor(H={}){this.config=H}get client(){return this.instance??=new(VH())(this.config.url,this.config.options)}set client(H){this.instance=H}close(){let H=this.instance;this.instance=null,H?.close()}}function VH(){let H=globalThis.Bun?.RedisClient;if(typeof H!=="function")throw Error("Redis requires Bun's built-in Redis client, which this runtime does not provide. Run the app under Bun, or bind your own client for the 'redis' token.");return H}var M0=new TextEncoder;function f0(H){return`id: ${H.seq}
7
+ data: ${JSON.stringify(H.event)}
8
+
9
+ `}var _H=5000,jH=`: keepalive
10
+
11
+ `;function OH(H,Q=_H){let X=null,$=!1,Z=()=>{if($)return;if(X!==null)clearTimeout(X);X=setTimeout(()=>{if(X=null,$)return;try{H.enqueue(M0.encode(jH))}catch{G();return}Z()},Q)},G=()=>{if($=!0,X!==null)clearTimeout(X);X=null};return Z(),{touch:Z,stop:G}}function IH(){return{"Content-Type":"text/event-stream","Cache-Control":"no-store, no-transform",Connection:"keep-alive","X-Accel-Buffering":"no"}}function dQ(H,Q=200){let X=H[Symbol.asyncIterator](),$=-1,Z,G=new ReadableStream({start(W){Z=OH(W)},async pull(W){try{let Y=await X.next();if(Y.done){Z.stop(),W.close();return}$=Y.value.seq,W.enqueue(M0.encode(f0(Y.value))),Z.touch()}catch(Y){let D={type:"error",error:NH(Y)};Z.stop(),W.enqueue(M0.encode(f0({seq:$+1,event:D}))),W.close()}},cancel(W){Z.stop(),X.return?.(W)}});return new Response(G,{status:Q,headers:IH()})}var qH=new Set(["frame_cursor_evicted","live_run_not_found"]);function NH(H){let Q=H&&typeof H==="object"?H.code:void 0;if(H instanceof Error&&typeof Q==="string"&&qH.has(Q))return{code:"unknown",message:H.message,retryable:!1};return console.error("[gemi/ai] agent stream failed",H),{code:"unknown",message:"The run's stream failed.",retryable:!1}}
12
+ export{U0 as Xf,p0 as Yf,xH as Zf,_0 as _f,dH as $f,I0 as ag,uH as bg,K0 as cg,B0 as dg,SH as eg,gH as fg,yH as gg,P0 as hg,nH as ig,w0 as jg,iH as kg,tH as lg,x as mg,L as ng,V0 as og,pH as pg,hH as qg,WH as rg,YH as sg,X0 as tg,Z0 as ug,DH as vg,j as wg,TH as xg,f as yg,b0 as zg,$0 as Ag,g0 as Bg,G0 as Cg,jQ as Dg,k0 as Eg,W0 as Fg,RH as Gg,T0 as Hg,LH as Ig,CH as Jg,jH as Kg,OH as Lg,IH as Mg,dQ as Ng};
13
+
14
+ //# debugId=935B2A48C72ADE0E64756E2164756E21