gemi 0.196.2 → 0.197.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.
- package/dist/ai/index.js +2 -2
- package/dist/ai/index.js.map +1 -1
- package/dist/app/index.js +1 -1
- package/dist/bun/plugin.js +1 -1
- package/dist/bun/preload.js +1 -1
- package/dist/{chunk-mgdrf89p.js → chunk-02jze3te.js} +2 -2
- package/dist/{chunk-mgdrf89p.js.map → chunk-02jze3te.js.map} +1 -1
- package/dist/{chunk-nk7nmtng.js → chunk-20y02g4n.js} +2 -2
- package/dist/{chunk-nk7nmtng.js.map → chunk-20y02g4n.js.map} +1 -1
- package/dist/{chunk-9dxp7t3n.js → chunk-2g2cntdm.js} +2 -2
- package/dist/{chunk-9dxp7t3n.js.map → chunk-2g2cntdm.js.map} +1 -1
- package/dist/{chunk-228w21t6.js → chunk-2qbfvb6m.js} +2 -2
- package/dist/{chunk-228w21t6.js.map → chunk-2qbfvb6m.js.map} +1 -1
- package/dist/{chunk-m0dfgmbj.js → chunk-2v83pskm.js} +1 -1
- package/dist/{chunk-652a9mr0.js → chunk-2z160r1b.js} +2 -2
- package/dist/{chunk-652a9mr0.js.map → chunk-2z160r1b.js.map} +1 -1
- package/dist/{chunk-28macaes.js → chunk-3am1e8ya.js} +2 -2
- package/dist/{chunk-28macaes.js.map → chunk-3am1e8ya.js.map} +1 -1
- package/dist/{chunk-rp6ss7v3.js → chunk-3bsw9sra.js} +2 -2
- package/dist/{chunk-rp6ss7v3.js.map → chunk-3bsw9sra.js.map} +1 -1
- package/dist/{chunk-j56zk5a0.js → chunk-4f2xy9ws.js} +3 -3
- package/dist/{chunk-j56zk5a0.js.map → chunk-4f2xy9ws.js.map} +1 -1
- package/dist/{chunk-08m9egzx.js → chunk-4ftk3z34.js} +2 -2
- package/dist/{chunk-08m9egzx.js.map → chunk-4ftk3z34.js.map} +1 -1
- package/dist/{chunk-7t60d5qy.js → chunk-4k62r4hv.js} +1 -1
- package/dist/{chunk-9hjxpdjt.js → chunk-51n7yky9.js} +1 -1
- package/dist/{chunk-wvq3c25z.js → chunk-5qaxde5h.js} +3 -3
- package/dist/{chunk-wvq3c25z.js.map → chunk-5qaxde5h.js.map} +1 -1
- package/dist/{chunk-pmt2jt9b.js → chunk-6nj9xjsm.js} +2 -2
- package/dist/{chunk-pmt2jt9b.js.map → chunk-6nj9xjsm.js.map} +1 -1
- package/dist/{chunk-g7h28xcr.js → chunk-7q42fej6.js} +2 -2
- package/dist/{chunk-g7h28xcr.js.map → chunk-7q42fej6.js.map} +1 -1
- package/dist/{chunk-p4eger3g.js → chunk-7sadg8d7.js} +3 -3
- package/dist/{chunk-p4eger3g.js.map → chunk-7sadg8d7.js.map} +1 -1
- package/dist/chunk-7xy7ebkx.js +117 -0
- package/dist/{chunk-5w3kcn4a.js.map → chunk-7xy7ebkx.js.map} +9 -10
- package/dist/{chunk-2485bwzs.js → chunk-8mmskn4g.js} +3 -3
- package/dist/{chunk-2485bwzs.js.map → chunk-8mmskn4g.js.map} +1 -1
- package/dist/{chunk-hswnqn33.js → chunk-8xckmvea.js} +2 -2
- package/dist/{chunk-hswnqn33.js.map → chunk-8xckmvea.js.map} +1 -1
- package/dist/{chunk-pqr01waj.js → chunk-9dnbf9q8.js} +2 -2
- package/dist/{chunk-pqr01waj.js.map → chunk-9dnbf9q8.js.map} +1 -1
- package/dist/{chunk-ermvtpy9.js → chunk-9ky5d5js.js} +3 -3
- package/dist/{chunk-ermvtpy9.js.map → chunk-9ky5d5js.js.map} +1 -1
- package/dist/{chunk-3fcd8a47.js → chunk-a4kk68xy.js} +2 -2
- package/dist/{chunk-3fcd8a47.js.map → chunk-a4kk68xy.js.map} +1 -1
- package/dist/{chunk-1x23scpn.js → chunk-a77w04sw.js} +2 -2
- package/dist/{chunk-1x23scpn.js.map → chunk-a77w04sw.js.map} +1 -1
- package/dist/{chunk-43599z6g.js → chunk-arb0qkrm.js} +2 -2
- package/dist/{chunk-43599z6g.js.map → chunk-arb0qkrm.js.map} +1 -1
- package/dist/{chunk-paawtkza.js → chunk-bcydd231.js} +2 -2
- package/dist/{chunk-paawtkza.js.map → chunk-bcydd231.js.map} +1 -1
- package/dist/{chunk-hmn6pa78.js → chunk-c601phyd.js} +2 -2
- package/dist/{chunk-hmn6pa78.js.map → chunk-c601phyd.js.map} +1 -1
- package/dist/{chunk-zcqz5xn9.js → chunk-cpgc5q74.js} +2 -2
- package/dist/{chunk-zcqz5xn9.js.map → chunk-cpgc5q74.js.map} +1 -1
- package/dist/{chunk-39w89wss.js → chunk-dbe8zgyb.js} +2 -2
- package/dist/{chunk-39w89wss.js.map → chunk-dbe8zgyb.js.map} +1 -1
- package/dist/{chunk-qrn6ch3t.js → chunk-degz94dk.js} +2 -2
- package/dist/{chunk-qrn6ch3t.js.map → chunk-degz94dk.js.map} +1 -1
- package/dist/{chunk-qg9pyxg7.js → chunk-e0d6az7p.js} +2 -2
- package/dist/{chunk-qg9pyxg7.js.map → chunk-e0d6az7p.js.map} +1 -1
- package/dist/{chunk-g02gqhq0.js → chunk-ecyq52t3.js} +3 -3
- package/dist/{chunk-g02gqhq0.js.map → chunk-ecyq52t3.js.map} +1 -1
- package/dist/chunk-es05kqtp.js +15 -0
- package/dist/{chunk-nphb176s.js.map → chunk-es05kqtp.js.map} +6 -5
- package/dist/{chunk-qjwv9xfq.js → chunk-evdca0b9.js} +2 -2
- package/dist/{chunk-qjwv9xfq.js.map → chunk-evdca0b9.js.map} +1 -1
- package/dist/{chunk-0xssrbar.js → chunk-ff16m7gm.js} +2 -2
- package/dist/{chunk-0xssrbar.js.map → chunk-ff16m7gm.js.map} +1 -1
- package/dist/{chunk-dn20caf2.js → chunk-fyk66c5e.js} +2 -2
- package/dist/{chunk-dn20caf2.js.map → chunk-fyk66c5e.js.map} +1 -1
- package/dist/{chunk-vgxkt9vd.js → chunk-fzy1z97a.js} +2 -2
- package/dist/{chunk-q1aaqhnw.js.map → chunk-fzy1z97a.js.map} +1 -1
- package/dist/{chunk-1ghbn9jg.js → chunk-g1th116z.js} +2 -2
- package/dist/{chunk-1ghbn9jg.js.map → chunk-g1th116z.js.map} +1 -1
- package/dist/{chunk-2yzv5v3m.js → chunk-gk0d26zw.js} +2 -2
- package/dist/{chunk-2yzv5v3m.js.map → chunk-gk0d26zw.js.map} +1 -1
- package/dist/{chunk-sqqby94y.js → chunk-gk12v51y.js} +1 -1
- package/dist/{chunk-ftvc1a0k.js → chunk-htnbmbx1.js} +2 -2
- package/dist/{chunk-ftvc1a0k.js.map → chunk-htnbmbx1.js.map} +1 -1
- package/dist/{chunk-pg5hm00s.js → chunk-j84r2j7a.js} +2 -2
- package/dist/{chunk-pg5hm00s.js.map → chunk-j84r2j7a.js.map} +1 -1
- package/dist/{chunk-1705yamg.js → chunk-kjgy7sk0.js} +2 -2
- package/dist/{chunk-1705yamg.js.map → chunk-kjgy7sk0.js.map} +1 -1
- package/dist/{chunk-6m9qrs6d.js → chunk-kjygnj7y.js} +2 -2
- package/dist/{chunk-6m9qrs6d.js.map → chunk-kjygnj7y.js.map} +1 -1
- package/dist/{chunk-n914rs58.js → chunk-kzy4pyqb.js} +3 -3
- package/dist/{chunk-n914rs58.js.map → chunk-kzy4pyqb.js.map} +1 -1
- package/dist/{chunk-07zfrfbg.js → chunk-mk4x0vtp.js} +2 -2
- package/dist/{chunk-07zfrfbg.js.map → chunk-mk4x0vtp.js.map} +1 -1
- package/dist/{chunk-gmcttf0f.js → chunk-mnmz8n5k.js} +2 -2
- package/dist/{chunk-gmcttf0f.js.map → chunk-mnmz8n5k.js.map} +1 -1
- package/dist/{chunk-wgqppqcn.js → chunk-n01mhwkj.js} +3 -3
- package/dist/{chunk-wgqppqcn.js.map → chunk-n01mhwkj.js.map} +1 -1
- package/dist/{chunk-xhkga697.js → chunk-nbry43s8.js} +2 -2
- package/dist/{chunk-xhkga697.js.map → chunk-nbry43s8.js.map} +1 -1
- package/dist/{chunk-beckfwe9.js → chunk-ng5qfkgp.js} +2 -2
- package/dist/{chunk-beckfwe9.js.map → chunk-ng5qfkgp.js.map} +1 -1
- package/dist/{chunk-aycfrzh1.js → chunk-nnn2f1ew.js} +2 -2
- package/dist/{chunk-aycfrzh1.js.map → chunk-nnn2f1ew.js.map} +1 -1
- package/dist/{chunk-reaty2mv.js → chunk-pvx66dq2.js} +3 -3
- package/dist/{chunk-reaty2mv.js.map → chunk-pvx66dq2.js.map} +1 -1
- package/dist/{chunk-j49vh5bs.js → chunk-qw6aa9fy.js} +2 -2
- package/dist/{chunk-j49vh5bs.js.map → chunk-qw6aa9fy.js.map} +1 -1
- package/dist/{chunk-28fz99pn.js → chunk-qx1vc11v.js} +2 -2
- package/dist/{chunk-28fz99pn.js.map → chunk-qx1vc11v.js.map} +1 -1
- package/dist/{chunk-9gpjn44n.js → chunk-rk34z2wa.js} +2 -2
- package/dist/{chunk-9gpjn44n.js.map → chunk-rk34z2wa.js.map} +1 -1
- package/dist/{chunk-m08p5mre.js → chunk-rnjjn09d.js} +2 -2
- package/dist/{chunk-m08p5mre.js.map → chunk-rnjjn09d.js.map} +1 -1
- package/dist/{chunk-q1aaqhnw.js → chunk-rqs2s5nh.js} +2 -2
- package/dist/{chunk-vgxkt9vd.js.map → chunk-rqs2s5nh.js.map} +1 -1
- package/dist/{chunk-zzdvdr5a.js → chunk-s57n552b.js} +4 -4
- package/dist/{chunk-zzdvdr5a.js.map → chunk-s57n552b.js.map} +1 -1
- package/dist/{chunk-ejktrxp2.js → chunk-spsheyx9.js} +1 -1
- package/dist/{chunk-7zf8rnsb.js → chunk-sxww1ka5.js} +2 -2
- package/dist/{chunk-7zf8rnsb.js.map → chunk-sxww1ka5.js.map} +1 -1
- package/dist/chunk-tgbky7fc.js +5 -0
- package/dist/{chunk-ggbf1web.js.map → chunk-tgbky7fc.js.map} +1 -1
- package/dist/{chunk-03q4j7wa.js → chunk-tv33103m.js} +1 -1
- package/dist/{chunk-p2vasd1z.js → chunk-tvdmx66x.js} +2 -2
- package/dist/{chunk-p2vasd1z.js.map → chunk-tvdmx66x.js.map} +1 -1
- package/dist/{chunk-f6css3z6.js → chunk-v4ka65g8.js} +2 -2
- package/dist/{chunk-f6css3z6.js.map → chunk-v4ka65g8.js.map} +1 -1
- package/dist/{chunk-a02bmp0q.js → chunk-wprzrnqh.js} +2 -2
- package/dist/{chunk-a02bmp0q.js.map → chunk-wprzrnqh.js.map} +1 -1
- package/dist/{chunk-tj7z65ba.js → chunk-x05mj7ye.js} +2 -2
- package/dist/{chunk-tj7z65ba.js.map → chunk-x05mj7ye.js.map} +1 -1
- package/dist/{chunk-2g2fsr71.js → chunk-xb9zjaes.js} +2 -2
- package/dist/{chunk-2g2fsr71.js.map → chunk-xb9zjaes.js.map} +1 -1
- package/dist/{chunk-b6zqjyn1.js → chunk-y50h3cd6.js} +2 -2
- package/dist/{chunk-b6zqjyn1.js.map → chunk-y50h3cd6.js.map} +1 -1
- package/dist/{chunk-5bfrr8x5.js → chunk-y9pzr1wc.js} +2 -2
- package/dist/{chunk-5bfrr8x5.js.map → chunk-y9pzr1wc.js.map} +1 -1
- package/dist/{chunk-8e17k7ht.js → chunk-yzazktke.js} +3 -3
- package/dist/{chunk-8e17k7ht.js.map → chunk-yzazktke.js.map} +3 -3
- package/dist/{chunk-6efjnt6r.js → chunk-zcmfkb9f.js} +2 -2
- package/dist/{chunk-6efjnt6r.js.map → chunk-zcmfkb9f.js.map} +1 -1
- package/dist/{chunk-trqt1kkd.js → chunk-zehvtpgm.js} +2 -2
- package/dist/{chunk-trqt1kkd.js.map → chunk-zehvtpgm.js.map} +1 -1
- package/dist/{chunk-bc7hr358.js → chunk-zrykhpn9.js} +3 -3
- package/dist/{chunk-bc7hr358.js.map → chunk-zrykhpn9.js.map} +1 -1
- package/dist/{chunk-8fdk8bfd.js → chunk-zryrem89.js} +3 -3
- package/dist/{chunk-8fdk8bfd.js.map → chunk-zryrem89.js.map} +1 -1
- package/dist/{chunk-fhfkcmkc.js → chunk-zv55h4x9.js} +2 -2
- package/dist/{chunk-fhfkcmkc.js.map → chunk-zv55h4x9.js.map} +1 -1
- package/dist/{chunk-dfmxvp8p.js → chunk-zzmgz14a.js} +2 -2
- package/dist/{chunk-dfmxvp8p.js.map → chunk-zzmgz14a.js.map} +1 -1
- package/dist/config/index.js +1 -1
- package/dist/console/run.js +2 -2
- package/dist/console/run.js.map +1 -1
- package/dist/container/index.js +2 -2
- package/dist/container/index.js.map +1 -1
- package/dist/database/index.js +2 -2
- package/dist/database/index.js.map +1 -1
- package/dist/email/index.js +2 -2
- package/dist/email/index.js.map +1 -1
- package/dist/facades/index.js +2 -2
- package/dist/facades/index.js.map +1 -1
- package/dist/foundation/index.js +2 -2
- package/dist/foundation/index.js.map +1 -1
- package/dist/http/ApiRouter.d.ts +7 -0
- package/dist/http/ApiRouter.d.ts.map +1 -1
- package/dist/http/BodyLimitMiddleware.d.ts +3 -0
- package/dist/http/BodyLimitMiddleware.d.ts.map +1 -1
- package/dist/http/HttpRequest.d.ts.map +1 -1
- package/dist/http/bodyLimit.d.ts +21 -1
- package/dist/http/bodyLimit.d.ts.map +1 -1
- package/dist/http/index.js +2 -2
- package/dist/http/index.js.map +1 -1
- package/dist/http/middleware-config.d.ts +12 -3
- package/dist/http/middleware-config.d.ts.map +1 -1
- package/dist/http/validate.d.ts +8 -0
- package/dist/http/validate.d.ts.map +1 -1
- package/dist/i18n/Translator.d.ts +5 -0
- package/dist/i18n/Translator.d.ts.map +1 -1
- package/dist/i18n/dictionaryRuntime.js +2 -2
- package/dist/i18n/dictionaryRuntime.js.map +1 -1
- package/dist/i18n/index.js +2 -2
- package/dist/i18n/index.js.map +1 -1
- package/dist/kernel/index.js +2 -2
- package/dist/kernel/index.js.map +1 -1
- package/dist/orm/index.js +2 -2
- package/dist/orm/index.js.map +1 -1
- package/dist/probe/index.js +2 -2
- package/dist/probe/index.js.map +1 -1
- package/dist/server/index.js +2 -2
- package/dist/server/index.js.map +1 -1
- package/dist/services/index.js +2 -2
- package/dist/services/index.js.map +1 -1
- package/dist/services/middleware/MiddlewareRegistry.d.ts +16 -5
- package/dist/services/middleware/MiddlewareRegistry.d.ts.map +1 -1
- package/dist/services/queue/work.js +2 -2
- package/dist/services/queue/work.js.map +1 -1
- package/dist/services/router/ApiRouteDispatcher.d.ts.map +1 -1
- package/dist/services/router/createFlatApiRoutes.d.ts +3 -0
- package/dist/services/router/createFlatApiRoutes.d.ts.map +1 -1
- package/dist/stats/route-table.js +1 -1
- package/dist/support/index.js +2 -2
- package/dist/support/index.js.map +1 -1
- package/dist/vitest/index.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-5w3kcn4a.js +0 -117
- package/dist/chunk-ggbf1web.js +0 -5
- package/dist/chunk-nphb176s.js +0 -15
- /package/dist/{chunk-m0dfgmbj.js.map → chunk-2v83pskm.js.map} +0 -0
- /package/dist/{chunk-7t60d5qy.js.map → chunk-4k62r4hv.js.map} +0 -0
- /package/dist/{chunk-9hjxpdjt.js.map → chunk-51n7yky9.js.map} +0 -0
- /package/dist/{chunk-sqqby94y.js.map → chunk-gk12v51y.js.map} +0 -0
- /package/dist/{chunk-ejktrxp2.js.map → chunk-spsheyx9.js.map} +0 -0
- /package/dist/{chunk-03q4j7wa.js.map → chunk-tv33103m.js.map} +0 -0
package/dist/chunk-ggbf1web.js
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
// @bun
|
|
2
|
-
import{ke as o}from"./chunk-652a9mr0.js";import{le as i}from"./chunk-vqq0z746.js";import{pk as t}from"./chunk-beckfwe9.js";import{pl as r}from"./chunk-8e17k7ht.js";class n extends i{register(){this.app.singleton(r,()=>new r(t(o(),this.app.config.get("translation",{}))))}}
|
|
3
|
-
export{n as bb};
|
|
4
|
-
|
|
5
|
-
//# debugId=BDE7A4D4B6CA957C64756E2164756E21
|
package/dist/chunk-nphb176s.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
// @bun
|
|
2
|
-
import{ej as q,fj as O1,gj as _1}from"./chunk-228w21t6.js";import{lj as g1,oj as b}from"./chunk-dfmxvp8p.js";import{pl as R0}from"./chunk-8e17k7ht.js";import{tl as C1}from"./chunk-ermvtpy9.js";import{Ml as H1}from"./chunk-aycfrzh1.js";import{Ul as rQ}from"./chunk-vgxkt9vd.js";class s1{static kind="controller";constructor(){}}class p0 extends s1{}function w1(Q){let Z=new Map;if(!Q)return Z;for(let $ of Q.split(";")){let X=$.indexOf("=");if(X===-1)continue;let G=$.slice(0,X).trim();if(!G)continue;Z.set(G,$.slice(X+1).trim())}return Z}function RZ(Q){return w1(Q.headers.get("cookie"))}function u(Q){if(!/^\d+$/.test(Q))return null;let Z=Number(Q);return Number.isSafeInteger(Z)?Z:null}function a1(Q){if(!Q)return null;let Z=Q.trim();if(!/^bytes=/i.test(Z))return null;let X=Z.slice(6).split(",").map((z)=>z.trim()).filter((z)=>z!=="");if(X.length!==1)return null;let G=X[0],Y=G.indexOf("-");if(Y===-1)return null;let K=G.slice(0,Y),J=G.slice(Y+1);if(K===""){let z=u(J);if(z===null)return null;return{kind:"suffix",suffixLength:z}}let H=u(K);if(H===null)return null;if(J==="")return{kind:"offset",start:H,end:null};let W=u(J);if(W===null||W<H)return null;return{kind:"offset",start:H,end:W}}function r1(Q,Z){if(!Number.isFinite(Z)||Z<=0)return null;let $,X;if(Q.kind==="suffix"){if(Q.suffixLength<=0)return null;$=Math.max(0,Z-Q.suffixLength),X=Z-1}else{if(Q.start>=Z)return null;if($=Q.start,X=Q.end===null?Z-1:Math.min(Q.end,Z-1),X<$)return null}return{start:$,end:X,length:X-$+1}}function LZ(Q){if(Q.kind==="suffix")return`bytes=-${Q.suffixLength}`;return Q.end===null?`bytes=${Q.start}-`:`bytes=${Q.start}-${Q.end}`}function CZ(Q){if(!Q)return null;let Z=/^bytes\s+(\d+)-(\d+)\/(\d+)$/i.exec(Q.trim());if(!Z)return null;let $=u(Z[1]),X=u(Z[2]),G=u(Z[3]);if($===null||X===null||G===null||X<$)return null;return{start:$,end:X,total:G}}function OZ(Q,Z,$){return`bytes ${Q}-${Z}/${$}`}function e1(Q){return`bytes */${Q}`}class a extends q{errors={};constructor(Q){super("Validation error");this.name="ValidationError",this.errors=Q,this.payload={api:{status:400,data:{error:{kind:"validation_error",messages:Q,status:400}},headers:{"Content-Type":"application/json"}},view:{status:400}}}}function u0(Q){let[Z,$]=Q.match(/\d+|\D+/g)??[];if(!Z||!$)return 0;let X=Number.parseInt(Z);switch($){case"B":return X;case"KB":return X*1024;case"MB":return X*1024*1024;case"GB":return X*1024*1024*1024;case"TB":return X*1024*1024*1024*1024;default:return 0}}function d0(Q){switch(Q){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 Q}}function Q0(Q){if(typeof Q==="string"||Array.isArray(Q))return Q.length;return}function S1(Q){return typeof Q==="number"&&!Number.isNaN(Q)}var l0=["required","string","boolean","number","email","password","min","max","gte","lte","file","fileType","fileSize","array","object","in"];class k extends Error{name="InvalidValidationRuleError"}function P1(Q,Z){let $=Z===void 0||Z.trim()===""?Number.NaN:Number(Z);if(Number.isNaN($))throw new k(`Validation rule "${Q}:${Z??""}" needs a number, e.g. "${Q}:3"`);return $}function Z0(Q){let Z=Q.indexOf(":"),$=Z===-1?Q:Q.slice(0,Z),X=Z===-1?void 0:Q.slice(Z+1);switch($){case"required":return(G)=>{if(G instanceof Blob)return G.size>0;if(G===null||G===void 0)return!1;if(typeof G==="string"||Array.isArray(G))return G.length>0;return!0};case"string":return(G)=>typeof G==="string";case"boolean":return(G)=>typeof G==="boolean";case"number":return(G)=>S1(G);case"password":return(G)=>{return typeof G==="string"&&/^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[^a-zA-Z0-9]).{8,}$/.test(G)};case"min":{let G=P1($,X);return(Y)=>{let K=Q0(Y);return K!==void 0&&K>=G}}case"max":{let G=P1($,X);return(Y)=>{let K=Q0(Y);return K!==void 0&&K<=G}}case"gte":{let G=P1($,X);return(Y)=>S1(Y)&&Y>=G}case"lte":{let G=P1($,X);return(Y)=>S1(Y)&&Y<=G}case"email":return(G)=>{return typeof G==="string"&&/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(G)};case"file":return(G)=>{return G instanceof Blob};case"fileType":{if(!X)throw new k('Validation rule "fileType" needs a type, e.g. "fileType:png" or "fileType:image"');let G=d0(X);return(Y)=>Y instanceof Blob&&Y.type.startsWith(G)}case"fileSize":{let G=u0(X??"");if(G===0&&!/^0+(B|KB|MB|GB|TB)$/.test(X??""))throw new k(`Validation rule "fileSize:${X??""}" needs a whole size in B, KB, MB, GB or TB, e.g. "fileSize:5MB"`);return(Y)=>Y instanceof Blob&&Y.size<=G}case"array":return(G)=>Array.isArray(G);case"object":return(G)=>typeof G==="object"&&G!==null&&!Array.isArray(G)&&!(G instanceof Blob);case"in":{let G=(X??"").split(",").filter((Y)=>Y!=="");if(G.length===0)throw new k('Validation rule "in" needs a comma-separated list, e.g. "in:draft,published"');return(Y)=>typeof Y==="string"&&G.includes(Y)}default:throw new k(`Unknown validation rule "${Q}". Known rules: ${l0.join(", ")}`)}}function d(Q){if(!Q.definition)throw Error(`gemi/ai: the recursive schema "${Q.name}" was used before its definition returned; \`self\` can be nested into the schema, but not parsed or emitted inside the callback`);return Q.definition}var L1=new WeakMap;function G0(Q){return typeof Q==="object"&&Q!==null&&L1.has(Q)}function U1(Q){let Z=L1.get(Q);if(!Z)throw Error("gemi/ai: expected a schema built with `s`, got a foreign object");return Z}function n0(Q){let Z={defs:{},cells:new Map},$=Q;if(Q.node.kind==="ref"){let G=d(Q.node.cell);$={...G,...Q.description?{description:Q.description}:{},optional:Q.optional,nullable:Q.nullable||G.nullable}}let X=e($,Z);return Object.keys(Z.defs).length>0?{...X,$defs:Z.defs}:X}function e(Q,Z){let $=(Q.optional||Q.nullable)&&Q.node.kind!=="json",X=t0(o0(Q.node,Z),$),G=[Q.description,i0(Q.node)].filter(Boolean).join(" ");if(G&&X.$ref!==void 0)X={anyOf:[X]};return G?{description:G,...X}:X}function i0(Q){let Z=[];if(Q.kind==="string"||Q.kind==="enum"){let $=Q.checks;if($?.format)Z.push(`Format: ${$.format.name}.`);if($?.minLength!==void 0)Z.push(`At least ${$.minLength} characters.`);if($?.maxLength!==void 0)Z.push(`At most ${$.maxLength} characters.`)}else if(Q.kind==="number"){let $=Q.checks;if($?.minimum!==void 0)Z.push(`Minimum ${$.minimum}.`);if($?.exclusiveMinimum!==void 0)Z.push(`Greater than ${$.exclusiveMinimum}.`);if($?.maximum!==void 0)Z.push(`Maximum ${$.maximum}.`);if($?.exclusiveMaximum!==void 0)Z.push(`Less than ${$.exclusiveMaximum}.`)}else if(Q.kind==="array"){let $=Q.checks;if($?.minItems!==void 0)Z.push(`At least ${$.minItems} items.`);if($?.maxItems!==void 0)Z.push(`At most ${$.maxItems} items.`)}return Z.join(" ")}function o0(Q,Z){switch(Q.kind){case"string":return{type:"string"};case"number":return{type:Q.checks?.integer?"integer":"number"};case"boolean":return{type:"boolean"};case"literal":return{type:typeof Q.value,const:Q.value};case"enum":return{type:"string",enum:Q.values};case"array":return{type:"array",items:e(Q.item,Z)};case"object":return{type:"object",properties:Object.fromEntries(Object.entries(Q.shape).map(([$,X])=>[$,e(X,Z)])),required:Object.keys(Q.shape),additionalProperties:!1};case"union":return{anyOf:Q.members.map(($)=>e($,Z))};case"json":return{};case"ref":{let{cell:$}=Q,X=Z.cells.get($.name);if(X&&X!==$)throw Error(`gemi/ai: two different recursive schemas are named "${$.name}" in one schema; give each s.recursive(...) its own name`);if(!X)Z.cells.set($.name,$),Z.defs[$.name]={},Z.defs[$.name]=e(d($),Z);return{$ref:`#/$defs/${$.name}`}}}}function t0(Q,Z){if(!Z)return Q;if(Q.anyOf)return{...Q,anyOf:[...Q.anyOf,{type:"null"}]};if(Q.enum||Q.const!==void 0)return{anyOf:[Q,{type:"null"}]};if(typeof Q.type==="string")return{...Q,type:[Q.type,"null"]};return{anyOf:[Q,{type:"null"}]}}function s0(Q){if(Q===null)return"null";if(Array.isArray(Q))return"array";return typeof Q}function a0(Q,Z){if(typeof Z==="number"&&!Number.isFinite(Z))return String(Z);if(Q.kind==="literal"||Q.kind==="enum"){if(typeof Z==="string"||typeof Z==="number"||typeof Z==="boolean")return JSON.stringify(Z)}return s0(Z)}function Y0(Q){let Z=Q.node,$=(()=>{switch(Z.kind){case"number":return Z.checks?.integer?"integer":"number";case"string":case"boolean":return Z.kind;case"literal":return JSON.stringify(Z.value);case"enum":return`one of ${Z.values.map((X)=>JSON.stringify(X)).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 Y0({...d(Z.cell),optional:!1,nullable:!1})}})();return Q.optional||Q.nullable?`${$} or null`:$}function r0(Q){let Z="";for(let $ of Q)Z+=typeof $==="number"?`[${$}]`:Z?`.${$}`:$;return Z}function e0(Q){let Z=r0(Q);return Z?`${Z}: `:""}function E1(Q){return`${e0(Q.path)}${Q.message}`}function M1(Q,Z){if(Z===null||Z===void 0)return Q.optional||Q.nullable?1:0;let $=Q.node;switch($.kind){case"string":return typeof Z==="string"?1:0;case"number":return typeof Z==="number"?1:0;case"boolean":return typeof Z==="boolean"?1:0;case"literal":return Z===$.value?10:0;case"enum":return typeof Z==="string"&&$.values.includes(Z)?10:0;case"array":return Array.isArray(Z)?1:0;case"object":{if(typeof Z!=="object"||Array.isArray(Z))return 0;let X=Z,G=1;for(let[Y,K]of Object.entries($.shape))G+=M1(K,X[Y]);return G}case"union":return $.members.reduce((X,G)=>Math.max(X,M1(G,Z)),0);case"json":return 1;case"ref":return K0($.cell,Z,()=>1,()=>M1(d($.cell),Z))}}function K0(Q,Z,$,X){if(typeof Z!=="object"||Z===null)return X();if(Q.active.has(Z))return $();Q.active.add(Z);try{return X()}finally{Q.active.delete(Z)}}function h(Q,Z,$,X){if(Q.optional&&(Z===null||Z===void 0))return{drop:!0,value:void 0};if(Q.nullable&&Z===null)return{drop:!1,value:null};return{drop:!1,value:QQ(Q,Z,$,X)}}function QQ(Q,Z,$,X){let G=Q.node,Y=()=>{let K=Z===void 0?"required":G.kind==="literal"?"const":G.kind==="enum"&&typeof Z==="string"?"enum":"type",J=K==="const"?{allowedValue:G.value}:K==="enum"?{allowedValues:G.values}:{};X.push({path:$,code:K,message:`expected ${Y0(Q)}, got ${a0(G,Z)}`,params:J});return};switch(G.kind){case"string":if(typeof Z!=="string")return Y();return $0(G.checks,Z,$,X),Z;case"number":if(typeof Z!=="number"||!Number.isFinite(Z))return Y();if(G.checks?.integer&&!Number.isInteger(Z))return Y();return $Q(G.checks,Z,$,X),Z;case"boolean":return typeof Z==="boolean"?Z:Y();case"literal":return Z===G.value?Z:Y();case"enum":if(typeof Z!=="string"||!G.values.includes(Z))return Y();return $0(G.checks,Z,$,X),Z;case"array":{if(!Array.isArray(Z))return Y();let K=Z.map((W,z)=>{let B=h(G.item,W,[...$,z],X);return B.drop?void 0:B.value}),{minItems:J,maxItems:H}=G.checks??{};if(J!==void 0&&Z.length<J)X.push({path:$,code:"minItems",message:`expected at least ${J} items, got ${Z.length}`,params:{limit:J}});if(H!==void 0&&Z.length>H)X.push({path:$,code:"maxItems",message:`expected at most ${H} items, got ${Z.length}`,params:{limit:H}});return K}case"object":{if(typeof Z!=="object"||Z===null||Array.isArray(Z))return Y();let K=Z,J={};for(let[H,W]of Object.entries(G.shape)){let z=h(W,K[H],[...$,H],X);if(!z.drop)J[H]=z.value}if(G.unknownKeys)for(let H of Object.keys(K)){if(Object.hasOwn(G.shape,H)||K[H]===void 0)continue;if(G.unknownKeys==="error"){X.push({path:[...$,H],code:"additionalProperties",message:"unknown key",params:{additionalProperty:H}});continue}$1(K[H],[...$,H],X,new Set),Object.defineProperty(J,H,{value:K[H],enumerable:!0,writable:!0,configurable:!0})}return J}case"union":{let K;for(let J of G.members){let H=[],W=h(J,Z,$,H);if(H.length===0)return W.drop?void 0:W.value;let z=M1(J,Z);if(!K||z>K.score)K={issues:H,score:z}}X.push({path:$,code:"anyOf",message:`no matching variant; closest: ${K.issues.map(E1).join("; ")}`,params:{closest:K.issues}});return}case"json":if(Z===void 0)return Y();return $1(Z,$,X,new Set),Z;case"ref":return K0(G.cell,Z,()=>{X.push({path:$,code:"type",message:"expected a finite tree, got a circular reference",params:{}});return},()=>h(d(G.cell),Z,$,X).value)}}function ZQ(Q){let Z=0;for(let $ of Q)Z++;return Z}function $0(Q,Z,$,X){if(!Q)return;let{minLength:G,maxLength:Y,format:K}=Q;if(G!==void 0||Y!==void 0){let J=ZQ(Z);if(G!==void 0&&J<G)X.push({path:$,code:"minLength",message:`expected at least ${G} characters, got ${J}`,params:{limit:G}});if(Y!==void 0&&J>Y)X.push({path:$,code:"maxLength",message:`expected at most ${Y} characters, got ${J}`,params:{limit:Y}})}if(K){let J=!1;try{J=K.test(Z)===!0}catch{}if(!J)X.push({path:$,code:"format",message:`expected a string in format "${K.name}"`,params:{format:K.name}})}}function $Q(Q,Z,$,X){if(!Q)return;let G=(Y,K,J,H)=>{if(K===void 0||J(K))return;X.push({path:$,code:Y,message:`expected ${H} ${K}, got ${Z}`,params:{limit:K}})};G("minimum",Q.minimum,(Y)=>Z>=Y,"at least"),G("exclusiveMinimum",Q.exclusiveMinimum,(Y)=>Z>Y,"more than"),G("maximum",Q.maximum,(Y)=>Z<=Y,"at most"),G("exclusiveMaximum",Q.exclusiveMaximum,(Y)=>Z<Y,"less than")}function $1(Q,Z,$,X,G=!0){let Y=(J)=>{$.push({path:Z,code:"type",message:`expected a JSON value, got ${J}`,params:{}})};switch(typeof Q){case"undefined":case"string":case"boolean":return;case"number":if(!Number.isFinite(Q))Y(String(Q));return;case"bigint":return Y("a bigint");case"function":return Y("a function");case"symbol":return Y("a symbol")}if(Q===null)return;let K=Q;if(X.has(K))return Y("a circular reference");X.add(K);try{let J=G?K.toJSON:void 0;if(typeof J==="function"){let H;try{H=J.call(K)}catch{return Y("a toJSON that threw")}if(H===void 0)return Y("a toJSON that returns undefined");return $1(H,Z,$,X,!1)}if(Array.isArray(Q))Q.forEach((H,W)=>$1(H,[...Z,W],$,X));else for(let[H,W]of Object.entries(K))$1(W,[...Z,H],$,X)}finally{X.delete(K)}}function S(Q){return R1(Q)}function R1(Q){let Z={toJSONSchema:()=>n0(Q),parse($){let X=[],G=h(Q,$,[],X);if(X.length>0)throw Error(X.map(E1).join("; "));return G.drop?void 0:G.value},safeParse($){let X=[],G=h(Q,$,[],X);if(X.length>0)return{ok:!1,errors:X.map(E1)};return{ok:!0,value:G.drop?void 0:G.value}},validate($){let X=[],G=h(Q,$,[],X);if(X.length>0)return{ok:!1,issues:X};return{ok:!0,value:G.drop?void 0:G.value}},describe:($)=>R1({...Q,description:$}),optional:()=>R1({...Q,optional:!0}),nullable:()=>R1({...Q,nullable:!0,optional:!1})};return L1.set(Z,Q),Z}function x(Q){return{node:Q,optional:!1,nullable:!1}}var X0=["strip","error","passthrough"];class H0 extends Error{problems;constructor(Q){super(`gemi/ai: s.fromJSONSchema cannot model this schema:
|
|
3
|
-
${Q.map((Z)=>`- ${Z}`).join(`
|
|
4
|
-
`)}`);this.name="JSONSchemaError",this.problems=Q}}var XQ=new Set(["title","$schema","$id","$comment","examples","default","deprecated","readOnly","writeOnly"]),r={string:["minLength","maxLength","format"],number:["minimum","maximum","exclusiveMinimum","exclusiveMaximum"],integer:["minimum","maximum","exclusiveMinimum","exclusiveMaximum"],boolean:[],object:["properties","required","additionalProperties"],array:["items","minItems","maxItems"]};function D1(Q){return typeof Q==="object"&&Q!==null&&!Array.isArray(Q)}function j1(Q,Z,$,X){let G=(V,U=$)=>{X.push(U?`${U}: ${V}`:V);return},Y=(V)=>$?`${$}.${V}`:V;if(!D1(Q))return G("expected a schema object");let K=new Set(Z.ignoreKeywords??[]),J=(V)=>XQ.has(V)||V.startsWith("x-")||K.has(V),H=!1,W=Q.type;if(Array.isArray(W)){let V=W.filter((U)=>U!=="null");if(V.length!==1)return G(`type ${JSON.stringify(W)} is not supported; only one type, optionally with "null". Use anyOf for alternatives`,Y("type"));H=V.length<W.length,W=V[0]}if(W!==void 0&&(typeof W!=="string"||!(W in r)))return G(`type ${JSON.stringify(W)} is not supported; expected one of ${Object.keys(r).join(", ")}`,Y("type"));let z=new Set(["type","description","enum","const","anyOf",...W?r[W]:[]]),B=!1;for(let V of Object.keys(Q)){if(z.has(V)||J(V))continue;B=!0;let U=Object.entries(r).find(([,P])=>P.includes(V));G(U&&U[0]!==W?`"${V}" applies to type ${U[0]}, and this schema is ${W?`type ${W}`:"untyped"}`:`"${V}" is not supported by s.fromJSONSchema`,Y(V))}if(B)return;if(Q.description!==void 0&&typeof Q.description!=="string")return G("expected a string",Y("description"));let L=Q.description,D=(V)=>({node:V,optional:!1,nullable:H,...L?{description:L}:{}});if(Q.anyOf!==void 0){if(W!==void 0||Q.enum!==void 0||Q.const!==void 0)return G("anyOf cannot be combined with type, enum or const here",Y("anyOf"));if(!Array.isArray(Q.anyOf)||Q.anyOf.length===0)return G("expected a non-empty array",Y("anyOf"));let V=[],U=!1;if(Q.anyOf.forEach((P,R)=>{if(D1(P)&&P.type==="null"&&Object.keys(P).length===1){H=!0;return}let A=j1(P,Z,Y(`anyOf[${R}]`),X);if(A)V.push(A);else U=!0}),U)return;if(V.length===0)return G("anyOf has only null in it",Y("anyOf"));if(V.length===1){let P=V[0];return{...P,nullable:P.nullable||H,...L?{description:L}:{}}}return D({kind:"union",members:V})}if(Q.const!==void 0){let V=Q.const;if(typeof V!=="string"&&typeof V!=="number"&&typeof V!=="boolean")return G("only a string, number or boolean const is supported",Y("const"));if(W!==void 0&&typeof V!==(W==="integer"?"number":W))return G(`const ${JSON.stringify(V)} is not of type ${W}`,Y("const"));return D({kind:"literal",value:V})}let M;if(W==="string"){if(M=GQ(Q,Z,Y,X),M===null)return}if(Q.enum!==void 0){if(!Array.isArray(Q.enum)||Q.enum.length===0)return G("expected a non-empty array",Y("enum"));let V=Q.enum.filter((R)=>R!==null);if(V.length<Q.enum.length)H=!0;let U=V.find((R)=>!(typeof R==="string"||typeof R==="number"||typeof R==="boolean")||W!==void 0&&typeof R!==(W==="integer"?"number":W));if(U!==void 0||V.length===0)return G(W?`every value must be of type ${W}${V.length===0?", and there must be one":`; ${JSON.stringify(U)} is not`}`:"only strings, numbers and booleans are supported",Y("enum"));if(V.every((R)=>typeof R==="string"))return D({kind:"enum",values:[...new Set(V)],...M?{checks:M}:{}});let P=[...new Set(V)];if(P.length===1)return D({kind:"literal",value:P[0]});return D({kind:"union",members:P.map((R)=>x({kind:"literal",value:R}))})}switch(W){case void 0:return G("a schema needs a type, an enum, a const or an anyOf");case"string":return D({kind:"string",...M?{checks:M}:{}});case"number":case"integer":{let V=W==="integer"?{integer:!0}:{},U=!1;for(let P of r.number){let R=Q[P];if(R===void 0)continue;if(typeof R!=="number"||!Number.isFinite(R)){G("expected a number",Y(P)),U=!0;continue}V[P]=R}if(U)return;return D({kind:"number",...Object.keys(V).length>0?{checks:V}:{}})}case"boolean":return D({kind:"boolean"});case"array":{if(!D1(Q.items))return G('an array needs "items" to be one schema (tuples are not supported)',Y("items"));let V={},U=!1;for(let R of["minItems","maxItems"]){let A=Q[R];if(A===void 0)continue;if(typeof A!=="number"||!Number.isInteger(A)||A<0){G("expected a non-negative integer",Y(R)),U=!0;continue}V[R]=A}let P=j1(Q.items,Z,Y("items"),X);if(!P||U)return;return D({kind:"array",item:P,...Object.keys(V).length>0?{checks:V}:{}})}case"object":{let V=Q.properties??{};if(!D1(V))return G("expected an object",Y("properties"));if(Q.additionalProperties!==void 0&&Q.additionalProperties!==!1)return G("only false is supported; a record with arbitrary keys has no strict-mode form (use s.json())",Y("additionalProperties"));let U=Q.required??[];if(!Array.isArray(U)||!U.every((N)=>typeof N==="string"))return G("expected an array of property names",Y("required"));let P=U.filter((N)=>!Object.hasOwn(V,N));if(P.length>0)return G(`lists properties the schema doesn't have: ${P.join(", ")}`,Y("required"));let R={},A=!1;for(let[N,_]of Object.entries(V)){let C=j1(_,Z,Y(`properties.${N}`),X);if(!C){A=!0;continue}R[N]=U.includes(N)?C:{...C,optional:!0}}if(A)return;let I=Z.unknownKeys;return D({kind:"object",shape:R,...I==="error"||I==="passthrough"?{unknownKeys:I}:{}})}}return}function GQ(Q,Z,$,X){let G={},Y=!1;for(let K of["minLength","maxLength"]){let J=Q[K];if(J===void 0)continue;if(typeof J!=="number"||!Number.isInteger(J)||J<0){X.push(`${$(K)}: expected a non-negative integer`),Y=!0;continue}G[K]=J}if(Q.format!==void 0){let K=Q.format,J=typeof K==="string"?Z.formats?.[K]:void 0;if(typeof K!=="string")X.push(`${$("format")}: expected a string`),Y=!0;else if(!J||!Object.hasOwn(Z.formats,K))X.push(`${$("format")}: unknown format ${JSON.stringify(K)}; pass a check for it in the formats option`),Y=!0;else G.format={name:K,test:YQ(J)}}if(Y)return null;return Object.keys(G).length>0?G:void 0}function YQ(Q){if(Q===!0)return()=>!0;if(Q instanceof RegExp)return(Z)=>{return Q.lastIndex=0,Q.test(Z)};return Q}var FZ={string:()=>S(x({kind:"string"})),number:()=>S(x({kind:"number"})),boolean:()=>S(x({kind:"boolean"})),literal:(Q)=>S(x({kind:"literal",value:Q})),enum:(Q)=>S(x({kind:"enum",values:Q})),object:(Q)=>S(x({kind:"object",shape:Object.fromEntries(Object.entries(Q).map(([Z,$])=>[Z,U1($)]))})),array:(Q)=>S(x({kind:"array",item:U1(Q)})),union:(Q)=>S(x({kind:"union",members:Q.map(U1)})),json:()=>S(x({kind:"json"})),recursive:HQ,fromJSONSchema:(Q,Z={})=>{let $=[];if(Z.unknownKeys!==void 0&&!X0.includes(Z.unknownKeys))throw Error(`gemi/ai: s.fromJSONSchema's unknownKeys option must be one of ${X0.map((G)=>JSON.stringify(G)).join(", ")}, got ${JSON.stringify(Z.unknownKeys)}`);let X=j1(Q,Z,"",$);if(!X||$.length>0)throw new H0($.length>0?$:["unreadable schema"]);return S(X)}};function qZ(Q){let Z=L1.get(Q);if(Z)return Z1(Z.node);return Q1(Q.toJSONSchema())}function Q1(Q){if(!(Q.$ref!==void 0||Q.type!==void 0||Q.enum!==void 0||Q.const!==void 0||Q.anyOf!==void 0||Q.properties!==void 0||Q.items!==void 0))return!1;for(let $ of Object.values(Q.properties??{}))if(!Q1($))return!1;if(Q.items&&!Q1(Q.items))return!1;for(let $ of Q.anyOf??[])if(!Q1($))return!1;for(let $ of Object.values(Q.$defs??{}))if(!Q1($))return!1;return!0}function Z1(Q,Z=new Set){switch(Q.kind){case"string":case"number":case"boolean":case"literal":case"enum":return!0;case"object":return Object.values(Q.shape).every(($)=>Z1($.node,Z));case"array":return Z1(Q.item.node,Z);case"union":return Q.members.every(($)=>Z1($.node,Z));case"json":return!1;case"ref":if(Z.has(Q.cell))return!0;return Z.add(Q.cell),Z1(d(Q.cell).node,Z)}}function x1(Q,Z,$=new Set){let X=Q.node;if(X.kind==="union")return X.members.some((G)=>x1(G,Z,$));if(X.kind!=="ref")return!1;if(X.cell===Z)return!0;if($.has(X.cell)||!X.cell.definition)return!1;return $.add(X.cell),x1(X.cell.definition,Z,$)}var KQ=/^[A-Za-z_][A-Za-z0-9_-]{0,63}$/;function HQ(Q,Z){if(typeof Q!=="string"||!KQ.test(Q))throw Error(`gemi/ai: s.recursive needs a name of letters, digits, "_" and "-" (starting with a letter or "_", at most 64), got ${JSON.stringify(Q)}`);let $={name:Q,active:new Set},X=()=>x({kind:"ref",cell:$}),G=U1(Z(S(X())));if(G.optional)throw Error(`gemi/ai: the recursive schema "${Q}" is optional() as a whole; mark the places that use it optional instead`);if(x1(G,$))throw Error(`gemi/ai: the recursive schema "${Q}" 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 $.definition=G,S(X())}function J0(Q){if(typeof Q!=="string")return null;let[Z]=Q.split(";",1),$=Z.trim().toLowerCase();return $===""?null:$}function W0(Q){if(Q===null)return!1;if(Q==="application/json")return!0;let Z=Q.indexOf("/");return Z>0&&Q.endsWith("+json")&&Q.length>Z+1+5}var X1=new WeakMap;function SZ(Q,Z,$,X){X1.set(Q,{clientAddress:Z,...$?{grant:Object.freeze({...$,scopes:Object.freeze([...$.scopes])})}:{},...X?{progress:X}:{}})}function V0(Q){return X1.get(Q)?.progress}function z0(Q){return X1.get(Q)?.grant}function B0(Q){return X1.has(Q)}function EZ(Q){return X1.get(Q)?.clientAddress}var P0=new WeakMap;function kZ(Q,Z){P0.set(Q,Z)}function D0(Q){return P0.get(Q)??null}var k1=new WeakMap;function gZ(Q,Z){let $=k1.get(Q)??[];if(!$.includes(Z))k1.set(Q,[...$,Z])}function yZ(Q){return k1.get(Q)??[]}class l{data;constructor(Q){this.data=Q}get(Q){return this.data[Q]}has(Q){return this.data[Q]!==void 0}toJSON(){return this.data}}function U0(Q){return typeof Q==="object"&&Q!==null&&!(Q instanceof Blob)}function JQ(Q,Z){if(!Z.includes(".")||Object.hasOwn(Q,Z))return[{path:[Z],value:Q[Z]}];let $=[{path:[],value:Q}];for(let X of Z.split(".")){let G=[];for(let{path:Y,value:K}of $){if(X==="*"){if(Array.isArray(K))K.forEach((J,H)=>G.push({path:[...Y,H],value:J}));else if(U0(K))for(let[J,H]of Object.entries(K))G.push({path:[...Y,J],value:H});continue}if(Array.isArray(K)&&/^\d+$/.test(X)){G.push({path:[...Y,Number(X)],value:K[Number(X)]});continue}G.push({path:[...Y,X],value:U0(K)&&Object.hasOwn(K,X)?K[X]:void 0})}$=G}return $}function M0(Q){return Q.join(".")}class WQ{kind;rawRequest;headers;cookies;search;schema={};routePath;params;domain;state;constructor(Q,Z,$,X){if(!Q){let H=b.getStore().req;this.params=H.params,this.rawRequest=H.rawRequest,this.kind=H.kind,this.routePath=H.routePath,this.domain=H.domain??null,this.state=H.state??new g1}else this.params=Z,this.rawRequest=Q,this.routePath=X,this.kind=$??"api",this.domain=D0(Q),this.state=new g1;this.headers=this.rawRequest.headers;let G=w1(this.rawRequest.headers.get("Cookie")),Y=new URL(this.rawRequest.url),K=new Map;for(let[H,W]of Y.searchParams)if(K.has(H)){let z=K.get(H);if(Array.isArray(z))z.push(W),K.set(H,z);else K.set(H,[z,W])}else K.set(H,W);let J=Object.fromEntries(K.entries());this.search=new l(J),this.cookies=G}locale(){let Q=b.getStore();if(Q.locale)return Q.locale;let Z=C1(R0);return Z.isLocaleAware?Z.detectLocale(Q.req):Q.locale}ctx(){return b.getStore()}isModelOriginated(){return B0(this.rawRequest)}mcpGrant(){return z0(this.rawRequest)??null}reportProgress(Q){let Z=V0(this.rawRequest);if(!Z)return!1;return Z(Q),!0}get signal(){return this.rawRequest.signal}range(){return a1(this.rawRequest.headers.get("Range"))}refine(Q){return{}}async parseBody(){let Q=J0(this.rawRequest.headers.get("Content-Type"));if(W0(Q))return new l(await this.parseJsonBody());if(Q==="application/x-www-form-urlencoded"||Q==="multipart/form-data"){let Z;try{Z=await this.rawRequest.formData()}catch(X){if(X instanceof q)throw X;throw new q("The request body could not be read as a form.")}let $=new Map;for(let[X,G]of Z.entries())if($.has(X)){let Y=$.get(X);if(Array.isArray(Y))Y.push(G);else $.set(X,[Y,G])}else $.set(X,G);return new l(Object.fromEntries($.entries()))}return new l({})}async parseJsonBody(){if(!this.rawRequest.body)return{};let Q;try{Q=await this.rawRequest.text()}catch($){if($ instanceof q)throw $;throw new q("The request body could not be read.")}if(Q.trim()==="")return{};let Z;try{Z=JSON.parse(Q)}catch{throw new q("The request body is not valid JSON.")}if(Z===null||typeof Z!=="object")throw new q("The request body must be a JSON object.");return Z}validateInput(Q){if(G0(this.schema))return this.validateWithSchema(Q);let Z=Q.toJSON()??{},$={},X=Object.entries(this.schema).map(([G,Y])=>({key:G,rules:Object.entries(Y).map(([K,J])=>({rule:K,message:J,check:typeof J==="function"?null:this.ruleFor(G,K)}))}));for(let{key:G,rules:Y}of X)for(let{path:K,value:J}of JQ(Z,G)){let H=this.checkField(J,Y);if(H.length>0){let W=$[M0(K)]??=[];for(let z of H)if(!W.includes(z))W.push(z)}}if(this.addRefinements($,Z),Object.keys($).length>0)throw new a($);return Q}checkField(Q,Z){let $=Z.some(({rule:Y})=>Y==="required"),X=Q===void 0||Q===null||Q==="",G=[];for(let{rule:Y,message:K,check:J}of Z){let H=K,W=!1;if(typeof K==="function")H=K(Q),W=typeof H>"u";else W=J(Q);if(W)continue;if(X&&!$)continue;if(Y==="required")return[String(H)];if(!G.includes(String(H)))G.push(String(H))}return G}validateWithSchema(Q){let Z=this.schema.validate(Q.toJSON()),$={};if("issues"in Z)for(let G of Z.issues){let Y=M0(G.path),K=$[Y]??=[];if(!K.includes(G.message))K.push(G.message)}let X="value"in Z?new l(Z.value):Q;if(this.addRefinements($,X.toJSON()),Object.keys($).length>0)throw new a($);return X}addRefinements(Q,Z){for(let[$,X]of Object.entries(this.refine(Z)??{})){let G=Q[$]??[];Q[$]=G.includes(X)?G:[...G,X]}}ruleFor(Q,Z){try{return Z0(Z)}catch($){if($ instanceof k)throw new k(`${this.constructor.name}.schema.${Q}: ${$.message}`);throw $}}async input(){return this.validateInput(await this.parseBody())}async safeInput(){let Q=await this.parseBody();try{return{isValid:!0,errors:{},input:this.validateInput(Q)}}catch(Z){if(!(Z instanceof a))throw Z;return{isValid:!1,errors:Z.errors,input:Q}}}}var j0="x-gemi-sign-in";class VQ extends q{error;constructor(Q="Not authorized"){super(Q);this.name="AuthorizationError",this.error=Q,this.payload={api:{status:401,data:{error:_1("authorization",this.error,401)}},view:{}}}}class y1 extends q{static apiStatus=403;error;constructor(Q="Insufficient permissions"){super(Q);this.name="InsufficientPermissionsError",this.error=Q,this.payload={api:{status:y1.apiStatus,data:{error:_1("permission",this.error,y1.apiStatus)}},view:{status:403}}}}class b1 extends q{total;constructor(Q){super("Range not satisfiable");this.total=Q;this.name="RangeNotSatisfiableError",this.payload={api:{status:416,data:{error:O1("range_not_satisfiable","Range not satisfiable",416)},headers:{"Content-Range":e1(Q),"Accept-Ranges":"bytes","Cache-Control":"no-store"}},view:{}}}}class zQ extends q{constructor(Q="Not found"){super(Q);this.name="NotFoundError",this.payload={api:{status:404,data:{error:O1("not_found",Q,404)},headers:{"Cache-Control":"no-store"}},view:{status:404}}}}class m extends q{fileName;constructor(Q){super("File not found");this.fileName=Q;this.name="FileNotFoundError",this.payload={api:{status:404,data:{error:O1("not_found","Not found",404)},headers:{"Cache-Control":"no-store"}},view:{status:404}}}}class BQ extends q{constructor(Q={}){super("Authentication error");this.name="AuthenticationError";let Z=Q.redirectTo??"/auth/sign-in";this.payload={api:{status:401,data:{error:_1("authentication","Authentication error",401)},headers:{[j0]:Z}},viewData:{status:200,data:{},headers:{"Cache-Control":"private, no-cache, no-store, max-age=0, must-revalidate"},directive:{kind:"Redirect",path:Z}},view:{status:302,headers:{"Cache-Control":"private, no-cache, no-store, max-age=0, must-revalidate",Location:Z}}}}}class G1{static getFacadeAccessor(){throw Error(`Facade [${this.name}] does not implement getFacadeAccessor().`)}static getFacadeRoot(){return C1(this.getFacadeAccessor())}}import{Buffer as PQ}from"buffer";function A1(Q){if(typeof Q!=="string"||/^[\s/.]*$/.test(Q))throw Error(`Refusing to delete by prefix ${JSON.stringify(Q)}: it would match the whole store`)}class Y1{async putStream({body:Q,...Z},$={}){$.signal?.throwIfAborted();let X=[],G=Q.getReader();try{for(;;){$.signal?.throwIfAborted();let{done:Y,value:K}=await G.read();if(Y)break;X.push(K)}}catch(Y){throw await G.cancel(Y).catch(()=>{}),Y}return this.put({...Z,body:PQ.concat(X)},$)}async*objects(Q,Z={}){throw Error(`${this.constructor.name} does not implement objects(). Override it to list objects in this backend.`)}async deletePrefix(Q,Z={}){A1(Q);let $=[];for await(let X of this.objects(Q,Z))$.push(X.name);for(let X of $)Z.signal?.throwIfAborted(),await this.delete({name:X,bucket:Z.bucket});return $.length}async delete(Q){throw Error(`${this.constructor.name} does not implement delete(). Override it to remove objects from this backend.`)}async read(Q){let Z=typeof Q==="string"?{name:Q}:Q,$=await this.fetch({name:Z.name,bucket:Z.bucket});if(!$.ok)throw new m(Z.name);let X=$.headers.get("Content-Type")??"application/octet-stream",G=$.headers.get("ETag")??void 0,Y=$.headers.get("Last-Modified"),K=Y?new Date(Y):void 0;if(Z.range){let W=await $.blob();return{body:W,start:0,end:W.size-1,total:W.size,partial:!1,type:X,etag:G,lastModified:K,name:Z.name}}let J=Number($.headers.get("Content-Length")),H=Number.isFinite(J)?J:0;return{body:$.body,start:0,end:H-1,total:H,partial:!1,type:X,etag:G,lastModified:K,name:Z.name}}async size(Q){let Z=typeof Q==="string"?Q:Q.name,$=typeof Q==="string"?void 0:Q.bucket,X=await this.fetch({name:Z,bucket:$});if(!X.ok)throw new m(Z);let G=Number(X.headers.get("Content-Length"));if(Number.isFinite(G))return await X.body?.cancel(),G;return(await X.blob()).size}}function L0(Q,Z){if(!Z)return Q;let $=Q.getReader(),X=!1,G,Y=()=>{if(X=!0,G)Z.removeEventListener("abort",G)};return new ReadableStream({start(K){if(G=()=>{if(X)return;Y(),K.error(Z.reason),$.cancel(Z.reason).catch(()=>{})},Z.aborted)G();else Z.addEventListener("abort",G,{once:!0})},async pull(K){let J;try{J=await $.read()}catch(H){if(X)return;Y(),K.error(H);return}if(X)return;if(J.done){Y(),K.close();return}K.enqueue(J.value)},cancel(K){return Y(),$.cancel(K)}},{highWaterMark:0})}import{mkdir as DQ,open as UQ,readdir as f1,rename as MQ,rmdir as RQ,stat as jQ,unlink as C0}from"fs/promises";import{dirname as LQ,isAbsolute as v1,relative as K1,resolve as n,sep as f}from"path";class h1 extends Y1{configured;constructor(Q){super();this.configured=Q}get folderPath(){return this.configured??`${H1()}/storage`}async put(Q,{signal:Z}={}){Z?.throwIfAborted();let $,X;if(Q instanceof Blob)$=Q,X=`${Bun.randomUUIDv7()}.${Q.type.split("/")[1].split(";")[0]}`;else $=Q.body,X=Q.name;let G=$ instanceof Buffer?$:$ instanceof Blob||$ instanceof File?Buffer.from(await $.arrayBuffer()):"",Y=`${this.folderPath}/${X}`;return Z?.throwIfAborted(),await Bun.write(Y,G),X}async putStream({name:Q,body:Z},{signal:$}={}){let X=Z.getReader(),G=null;try{if($?.throwIfAborted(),!Q)throw Error("Object name has to be specified");let Y=n(this.folderPath),K=n(Y,Q),J=K1(Y,K);if(!J||J===".."||J.startsWith(`..${f}`)||v1(J))throw Error(`Refusing to write "${Q}": it is outside the storage folder`);await DQ(LQ(K),{recursive:!0}),G=`${K}.${Bun.randomUUIDv7()}.partial`;let H=await UQ(G,"wx");try{for(;;){$?.throwIfAborted();let{done:W,value:z}=await X.read();if(W)break;for(let B=0;B<z.byteLength;){let{bytesWritten:L}=await H.write(z,B);B+=L}}}finally{await H.close()}return $?.throwIfAborted(),await MQ(G,K),Q}catch(Y){if(await X.cancel(Y).catch(()=>{}),G)await C0(G).catch(()=>{});throw Y}}async fetch(Q,{signal:Z}={}){Z?.throwIfAborted();let $=process.env.BUCKET_NAME,X;if(typeof Q==="string")X=Q;else $=Q.bucket??$,X=Q.name;if(!X)throw Error("Object name has to be specified");let G=`${this.folderPath}/${X}`,Y=Bun.file(G),K=L0(Bun.file(G).stream(),Z),J=new Date(Y.lastModified).toUTCString();return new Response(K,{headers:{"Content-Type":Y.type,"Content-Length":String(Y.size),"Cache-Control":"private, max-age=12000, must-revalidate","Last-Modified":J}})}async read(Q){let Z=typeof Q==="string"?{name:Q}:Q,{name:$,range:X=null}=Z;if(!$)throw Error("Object name has to be specified");let G=Bun.file(`${this.folderPath}/${$}`);if(!await G.exists())throw new m($);let Y=G.size,K=X?r1(X,Y):null;if(X&&!K)throw new b1(Y);let J=K?.start??0,H=K?K.end:Y-1;return{body:K?G.slice(J,H+1):G,start:J,end:H,total:Y,partial:Boolean(K),type:G.type||"application/octet-stream",lastModified:new Date(G.lastModified),name:$}}async size(Q){let Z=typeof Q==="string"?Q:Q.name,$=Bun.file(`${this.folderPath}/${Z}`);if(!await $.exists())throw new m(Z);return $.size}async delete(Q){let Z=typeof Q==="string"?Q:Q.name;if(!Z)throw Error("Object name has to be specified");let $=n(this.folderPath),X=n($,Z),G=K1($,X);if(!G||G===".."||G.startsWith(`..${f}`)||v1(G))throw Error(`Refusing to delete "${Z}": it is outside the storage folder`);try{await C0(X)}catch(Y){if(Y?.code==="ENOENT")return;throw Y}}resolvePrefix(Q){let Z=n(this.folderPath),$=Q.lastIndexOf("/"),X=$===-1?"":Q.slice(0,$),G=$===-1?Q:Q.slice($+1),Y=n(Z,X),K=K1(Z,Y);if(K===".."||K.startsWith(`..${f}`)||v1(K))throw Error(`Refusing to list "${Q}": it is outside the storage folder`);let J=K.split(f).join("/");return{root:Z,dir:Y,match:J?`${J}/${G}`:G}}async*objects(Q,{signal:Z}={}){Z?.throwIfAborted();let{root:$,dir:X,match:G}=this.resolvePrefix(Q),Y=[],K=async(J)=>{let H;try{H=await f1(J,{withFileTypes:!0})}catch(W){if(W?.code==="ENOENT"||W?.code==="ENOTDIR")return;throw W}for(let W of H){let z=`${J}${f}${W.name}`,B=K1($,z).split(f).join("/");if(W.isDirectory()){if(`${B}/`.startsWith(G)||G.startsWith(`${B}/`))await K(z)}else if(W.isFile()&&B.startsWith(G))Y.push(B)}};await K(X),Y.sort();for(let J of Y){Z?.throwIfAborted();let H;try{H=await jQ(`${$}/${J}`)}catch(W){if(W?.code==="ENOENT")continue;throw W}yield{name:J,size:H.size,lastModified:H.mtime}}}async deletePrefix(Q,Z={}){A1(Q);let{root:$,match:X}=this.resolvePrefix(Q);A1(X);let G=await super.deletePrefix(Q,Z);if(G>0)await this.pruneEmptyDirs($,X);return G}async pruneEmptyDirs(Q,Z){let $=[],X=async(G)=>{let Y;try{Y=await f1(G,{withFileTypes:!0})}catch{return}for(let K of Y){if(!K.isDirectory())continue;let J=`${G}${f}${K.name}`,H=K1(Q,J).split(f).join("/");if(`${H}/`.startsWith(Z)||Z.startsWith(`${H}/`)){if(await X(J),`${H}/`.startsWith(Z))$.push(J)}}};await X(Q);for(let G of $)try{await RQ(G)}catch{}}async list(){return await f1(this.folderPath)}}var v=30000;function R8(Q){return Q}function O0(){return{driver:new h1,fetchTimeoutMs:v,fetchIdleTimeoutMs:v}}class m1{static token="filesystem";driver;fetchTimeoutMs;fetchIdleTimeoutMs;constructor(Q={}){this.driver=Q.driver??O0().driver,this.fetchTimeoutMs=Q.fetchTimeoutMs??v,this.fetchIdleTimeoutMs=Q.fetchIdleTimeoutMs??v}}class _0 extends Error{driver;limit;timeoutMs;object;code="storage-fetch-timeout";constructor(Q,Z,$,X){super(Z==="fetchTimeoutMs"?`${Q}: no response for "${X}" within ${$}ms (fetchTimeoutMs)`:`${Q}: the body of "${X}" sent nothing for ${$}ms (fetchIdleTimeoutMs)`);this.driver=Q;this.limit=Z;this.timeoutMs=$;this.object=X;this.name="StorageFetchTimeoutError"}}async function A0(Q,Z,$,X){let{fetchTimeoutMs:G,fetchIdleTimeoutMs:Y}=X;if($.signal||!G&&!Y)return Q.fetch(Z,$);let K=new AbortController,J=Q.constructor?.name||"FileStorageDriver",H=typeof Z==="string"?Z:Z.name,W=(L,D)=>{let M=new _0(J,L,D,H);return K.abort(M),M},z=Promise.resolve(Q.fetch(Z,{...$,signal:K.signal})),B;if(G){let L,D=new Promise((M,V)=>{L=setTimeout(()=>V(W("fetchTimeoutMs",G)),G)});try{B=await Promise.race([z,D])}catch(M){if(K.signal.aborted)throw z.then((V)=>V.body?.cancel(K.signal.reason).catch(()=>{}),()=>{}),K.signal.reason;throw M}finally{clearTimeout(L)}}else B=await z;if(!Y||!B.body)return B;return new Response(CQ(B.body,Y,()=>W("fetchIdleTimeoutMs",Y)),{status:B.status,statusText:B.statusText,headers:B.headers})}function CQ(Q,Z,$){let X=Q.getReader();return new ReadableStream({async pull(G){let Y,K,J=new Promise((H,W)=>{Y=setTimeout(()=>{K=$(),W(K)},Z)});try{let H=await Promise.race([X.read(),J]);if(H.done)G.close();else G.enqueue(H.value)}catch(H){let W=K??H;G.error(W),X.cancel(W).catch(()=>{})}finally{clearTimeout(Y)}},cancel(G){return X.cancel(G)}},{highWaterMark:0})}class T extends Error{code="safe-fetch";url;constructor(Q,Z,$){super(Q,$);this.name=new.target.name,this.url=Z}}class c extends T{reason;code="invalid-url";constructor(Q,Z,$){super($,Q);this.reason=Z}}class I1 extends T{host;reason;code="blocked-host";constructor(Q,Z,$){super($==="denied"?`Requests to ${Z} are not allowed.`:`${Z} is not on the list of hosts this request may reach.`,Q);this.host=Z;this.reason=$}}class i extends T{host;address;range;code="blocked-address";constructor(Q,Z,$,X){super(Z===$?`${$} is not a public address (${X}).`:`${Z} resolves to ${$}, which is not a public address (${X}).`,Q);this.host=Z;this.address=$;this.range=X}}class N1 extends T{host;code="dns";constructor(Q,Z,$){super(`Couldn't resolve ${Z}.`,Q,{cause:$});this.host=Z}}class F1 extends T{phase;ms;code="timeout";constructor(Q,Z,$){super(Z==="connect"?`Couldn't connect within ${$} ms.`:`The request didn't finish within ${$} ms.`,Q);this.phase=Z;this.ms=$}}class q1 extends T{limit;code="too-large";constructor(Q,Z){super(`The response is larger than ${Z} bytes.`,Q);this.limit=Z}}class J1 extends T{contentType;allowed;code="content-type";constructor(Q,Z,$){super(`The response is ${Z??"of no content type"}, not ${$.join(" or ")}.`,Q);this.contentType=Z;this.allowed=$}}class c1 extends T{limit;code="too-many-redirects";constructor(Q,Z){super(`More than ${Z} redirects.`,Q);this.limit=Z}}class o extends T{code="network";constructor(Q,Z){super(`The request failed: ${Z instanceof Error?Z.message:String(Z)}`,Q,{cause:Z})}}class p1 extends T{status;code="http-status";constructor(Q,Z){super(`The server answered ${Z}.`,Q);this.status=Z}}function OQ(Q){if(Q==="")return null;let Z=Q.split(".");if(Z.length>1&&Z[Z.length-1]==="")Z.pop();if(Z.length===0||Z.length>4)return null;let $=[];for(let Y of Z){let K=_Q(Y);if(K===null)return null;$.push(K)}let X=$.pop();for(let Y of $)if(Y>255)return null;if(X>=256**(4-$.length))return null;let G=X;return $.forEach((Y,K)=>{G+=Y*256**(3-K)}),new Uint8Array([Math.floor(G/16777216)&255,Math.floor(G/65536)&255,Math.floor(G/256)&255,G&255])}function _Q(Q){if(Q==="")return null;let Z=Q,$=10;if(/^0x/i.test(Z)){if(Z=Z.slice(2),$=16,Z==="")return 0}else if(Z.length>1&&Z.startsWith("0"))Z=Z.slice(1),$=8;if(!($===16?/^[0-9a-f]+$/i:$===8?/^[0-7]+$/:/^[0-9]+$/).test(Z))return null;let G=parseInt(Z,$);return Number.isSafeInteger(G)?G:null}function I0(Q){let Z=Q;if(Z.startsWith("[")&&Z.endsWith("]"))Z=Z.slice(1,-1);let $=Z.indexOf("%");if($!==-1)Z=Z.slice(0,$);if(!Z.includes(":"))return null;let X=Z.split("::");if(X.length>2)return null;let G=(W,z)=>{if(W==="")return[];let B=[],L=W.split(":");for(let D=0;D<L.length;D++){let M=L[D];if(z&&D===L.length-1&&M.includes(".")){if(!/^\d{1,3}(\.\d{1,3}){3}$/.test(M))return null;let V=M.split(".").map(Number);if(V.some((U)=>U>255))return null;B.push(V[0]<<8|V[1],V[2]<<8|V[3]);continue}if(!/^[0-9a-f]{1,4}$/i.test(M))return null;B.push(parseInt(M,16))}return B},Y=G(X[0],X.length===1),K=X.length===2?G(X[1],!0):[];if(!Y||!K)return null;let J;if(X.length===2){let W=8-Y.length-K.length;if(W<1)return null;J=[...Y,...Array.from({length:W},()=>0),...K]}else J=Y;if(J.length!==8)return null;let H=new Uint8Array(16);return J.forEach((W,z)=>{H[z*2]=W>>8,H[z*2+1]=W&255}),H}function W1(Q){let Z=I0(Q);if(Z)return{family:6,bytes:Z};let $=OQ(Q);if($)return{family:4,bytes:$};return null}function p(Q){if(Q.family===6&&AQ(Q.bytes))return{family:4,bytes:Q.bytes.slice(12)};return Q}function AQ(Q){for(let Z=0;Z<10;Z++)if(Q[Z]!==0)return!1;return Q[10]===255&&Q[11]===255}function V1(Q){if(Q.family===4)return Array.from(Q.bytes).join(".");let Z=[];for(let $=0;$<16;$+=2)Z.push((Q.bytes[$]<<8|Q.bytes[$+1]).toString(16));return Z.join(":")}function t(Q){let Z=Q.lastIndexOf("/"),$=Z===-1?Q:Q.slice(0,Z),X=/^[0-9.]+$/.test($)?IQ($):I0($);if(!X)return null;let G=p(X.length===4?{family:4,bytes:X}:{family:6,bytes:X}),Y=G.family===4?32:128,K=Y;if(Z!==-1){let J=Q.slice(Z+1);if(!/^\d{1,3}$/.test(J))return null;if(K=Number(J),X.length===16&&G.family===4)K-=96;if(K<0||K>Y)return null}return{family:G.family,bytes:G.bytes,prefix:K}}function IQ(Q){return/^\d{1,3}(\.\d{1,3}){3}$/.test(Q)&&Q.split(".").every((Z)=>Number(Z)<=255)?new Uint8Array(Q.split(".").map(Number)):null}function g(Q,Z){let $=p(Q);if($.family!==Z.family)return!1;let X=Z.prefix;for(let G=0;X>0;G++){let Y=Math.min(8,X),K=255<<8-Y&255;if(($.bytes[G]&K)!==(Z.bytes[G]&K))return!1;X-=Y}return!0}var O=(Q,Z)=>({cidr:t(Q),kind:Z,text:Q}),NQ=[O("0.0.0.0/8","unspecified"),O("10.0.0.0/8","private"),O("100.64.0.0/10","shared"),O("127.0.0.0/8","loopback"),O("169.254.169.254/32","metadata"),O("169.254.0.0/16","link-local"),O("168.63.129.16/32","metadata"),O("172.16.0.0/12","private"),O("192.0.0.0/24","reserved"),O("192.0.2.0/24","documentation"),O("192.88.99.0/24","reserved"),O("192.168.0.0/16","private"),O("198.18.0.0/15","benchmarking"),O("198.51.100.0/24","documentation"),O("203.0.113.0/24","documentation"),O("224.0.0.0/4","multicast"),O("255.255.255.255/32","broadcast"),O("240.0.0.0/4","reserved")],FQ=[O("::/128","unspecified"),O("::1/128","loopback"),O("64:ff9b:1::/48","private"),O("::/8","reserved"),O("100::/64","reserved"),O("2001:db8::/32","documentation"),O("2001::/23","reserved"),O("3fff::/20","documentation"),O("fd00:ec2::254/128","metadata"),O("fc00::/7","unique-local"),O("fe80::/10","link-local"),O("fec0::/10","private"),O("ff00::/8","multicast")],qQ=t("64:ff9b::/96"),TQ=t("2002::/16"),wQ=t("2000::/3");function T1(Q){let Z=typeof Q==="string"?W1(Q):Q;if(!Z)return{kind:"reserved",range:"not an IP address"};let $=p(Z);if($.family===4){let G=NQ.find((Y)=>g($,Y.cidr));return G?{kind:G.kind,range:G.text}:null}if(g($,qQ))return T1({family:4,bytes:$.bytes.slice(12)});if(g($,TQ))return T1({family:4,bytes:$.bytes.slice(2,6)});let X=FQ.find((G)=>g($,G.cidr));if(X)return{kind:X.kind,range:X.text};return g($,wQ)?null:{kind:"reserved",range:"outside 2000::/3"}}function N0(Q,Z){let $=p(Q),X=p(Z);return $.family===X.family&&$.bytes.every((G,Y)=>G===X.bytes[Y])}import{lookup as SQ}from"dns/promises";import*as EQ from"http";import*as xQ from"https";import*as s from"zlib";class u1 extends Response{#Q;#Z;address;constructor(Q,Z,$){super(Q,Z);this.#Q=$.url,this.#Z=$.redirected,this.address=$.address}get url(){return this.#Q}get redirected(){return this.#Z}}var z1={timeout:30000,connectTimeout:1e4,maxSize:10485760,maxRedirects:5,ports:[80,443]},kQ=new Set([301,302,303,307,308]),gQ=new Set([101,103,204,205,304]),yQ=["host","connection","content-length","transfer-encoding","keep-alive","upgrade"],bQ=["authorization","cookie","proxy-authorization"];async function T0(Q,Z={}){let $=fQ(Z),X=Z.signal;X?.throwIfAborted();let G=new AbortController,Y=G.signal,K=String(Q),J=(B)=>{if(!Y.aborted)G.abort(B)},H=setTimeout(()=>J(new F1(K,"total",$.timeout)),$.timeout),W=()=>J(X.reason);X?.addEventListener("abort",W,{once:!0});let z=()=>{clearTimeout(H),X?.removeEventListener("abort",W)};try{let B=q0(K,$),L=(Z.method??"GET").toUpperCase(),D=new Headers(Z.headers);for(let V of yQ)D.delete(V);if(!D.has("accept"))D.set("accept","*/*");if(!D.has("user-agent"))D.set("user-agent","gemi");if(!D.has("accept-encoding"))D.set("accept-encoding","gzip, deflate, br");let M=await cQ(L,Z.body,D);for(let V=0;;V++){K=B.href;let{request:U,response:P,address:R}=await pQ(B,L,D,M,$,Y),A=P.statusCode??0,I=P.headers.location;if(kQ.has(A)&&I&&Z.redirect!=="manual"){if(U.destroy(),V>=$.maxRedirects)throw new c1(B.href,$.maxRedirects);let N;try{N=new URL(I,B)}catch{throw new c(I,"malformed",`The redirect to "${I}" is not a URL.`)}if(A===303?L!=="HEAD":(A===301||A===302)&&L==="POST"){L="GET",M=null;let _=[];D.forEach((C,j)=>{if(j.startsWith("content-"))_.push(j)});for(let C of _)D.delete(C)}if(N.origin!==B.origin)for(let _ of bQ)D.delete(_);B=q0(N.href,$);continue}return uQ({url:B,hop:V,method:L,request:U,response:P,address:R,policy:$,signal:Y,release:z})}}catch(B){throw z(),Y.aborted?Y.reason:B}}function fQ(Q){let Z=(X,G)=>{let Y={hosts:[],ranges:[]};for(let K of X){let J=K.includes("/")||K.includes(":")||/^[\d.]+$/.test(K),H=J?t(K):null;if(H)Y.ranges.push(H);else if(!J&&/^(\*\.)?[a-z0-9-]+(\.[a-z0-9-]+)*\.?$/i.test(K))Y.hosts.push(w0(K));else throw TypeError(`safeFetch: "${K}" in ${G} is not a host name or an IP range.`)}return Y},$=Q.allowPrivate;return{timeout:Q.timeout??z1.timeout,connectTimeout:Q.connectTimeout??z1.connectTimeout,maxSize:Q.maxSize??z1.maxSize,maxRedirects:Q.maxRedirects??z1.maxRedirects,ports:Q.ports??z1.ports,allow:Q.allow&&Q.allow.length>0?Z(Q.allow,"allow"):null,deny:Z(Q.deny??[],"deny"),allowPrivate:$===!0?!0:Z($||[],"allowPrivate").ranges,contentTypes:Q.contentTypes?.length?Q.contentTypes:null,resolve:Q.resolve??vQ}}async function vQ(Q){return(await SQ(Q,{all:!0,verbatim:!0})).map(($)=>$.address)}function w0(Q){return Q.toLowerCase().replace(/\.$/,"")}function F0(Q,Z){return Z.some(($)=>$.startsWith("*.")?Q.endsWith($.slice(1)):Q===$)}function q0(Q,Z){let $;try{$=new URL(Q)}catch{throw new c(Q,"malformed",`"${Q}" is not a URL.`)}if($.protocol!=="http:"&&$.protocol!=="https:")throw new c($.href,"scheme",`Only http and https URLs can be fetched, not ${$.protocol.slice(0,-1)}.`);if($.username||$.password)throw new c($.href,"credentials","The URL has a username or password in it.");let X=S0($);if(Z.ports!=="any"&&!Z.ports.includes(X))throw new c($.href,"port",`Port ${X} is not allowed.`);return $}function S0(Q){return Q.port?Number(Q.port):Q.protocol==="https:"?443:80}async function hQ(Q,Z,$){let X=w0(Q.hostname.replace(/^\[(.*)\]$/,"$1")),G=W1(X),Y=G!==null&&(X.includes(":")||/^\d+\.\d+\.\d+\.\d+$/.test(X));if(!Y&&F0(X,Z.deny.hosts))throw new I1(Q.href,X,"denied");let K=!Y&&Z.allow!==null&&F0(X,Z.allow.hosts);if(Z.allow&&!K&&Z.allow.ranges.length===0)throw new I1(Q.href,X,"not-allowed");let J;if(Y)J=[G];else{let H;try{H=await mQ(Z.resolve(X),$)}catch(W){if($.aborted)throw $.reason;throw new N1(Q.href,X,W)}if(J=H.map((W)=>W1(W)).filter((W)=>W!==null),J.length===0)throw new N1(Q.href,X)}for(let H of J){let W=V1(H);if(Z.deny.ranges.some((B)=>g(H,B)))throw new i(Q.href,X,W,"denied");if(Z.allow&&!K&&!Z.allow.ranges.some((B)=>g(H,B)))throw new i(Q.href,X,W,"not-allowed");let z=T1(H);if(z&&Z.allowPrivate!==!0&&!Z.allowPrivate.some((B)=>g(H,B)))throw new i(Q.href,X,W,z.kind)}return{host:X,addresses:J,isLiteral:Y}}function mQ(Q,Z){if(Z.aborted)return Promise.reject(Z.reason);return new Promise(($,X)=>{let G=()=>X(Z.reason);Z.addEventListener("abort",G,{once:!0}),Q.then((Y)=>{Z.removeEventListener("abort",G),$(Y)},(Y)=>{Z.removeEventListener("abort",G),X(Y)})})}async function cQ(Q,Z,$){if(Z===void 0||Z===null)return null;if(Q==="GET"||Q==="HEAD")throw TypeError(`safeFetch: a ${Q} request can't have a body.`);let X=new Request("http://body.invalid/",{method:"POST",body:Z}),G=X.headers.get("content-type");if(G&&!$.has("content-type"))$.set("content-type",G);return new Uint8Array(await X.arrayBuffer())}async function pQ(Q,Z,$,X,G,Y){let K=new AbortController,J=setTimeout(()=>K.abort(new F1(Q.href,"connect",G.connectTimeout)),G.connectTimeout),H=AbortSignal.any([Y,K.signal]);try{let{host:W,addresses:z,isLiteral:B}=await hQ(Q,G,H),L=Q.protocol==="https:",D={};if($.forEach((M,V)=>{D[V]=M}),X)D["content-length"]=String(X.byteLength);return await new Promise((M,V)=>{let U={method:Z,host:W,port:S0(Q),path:`${Q.pathname}${Q.search}`,headers:D,agent:!1,lookup:(_,C,j)=>{let w=C?.family,F=z.filter((B1)=>!w||B1.family===w);if(F.length===0)j(Object.assign(Error(`No IPv${w} address for ${W}`),{code:"ENOTFOUND"}));else if(C?.all)j(null,F.map((B1)=>({address:V1(B1),family:B1.family})));else j(null,V1(F[0]),F[0].family)}};if(L&&!B)U.servername=W;let P=(L?xQ:EQ).request(U),R=null,A=(_)=>{H.removeEventListener("abort",I),P.destroy(),V(_)},I=()=>A(H.aborted?H.reason:Y.reason);H.addEventListener("abort",I,{once:!0});let N=(_)=>{let C=_?.remoteAddress;if(!C||R!==null)return!0;let j=W1(C);if(!j||!z.some((w)=>N0(w,j)))return A(new i(Q.href,W,C,"not-allowed")),!1;return R=V1(p(j)),!0};P.once("socket",(_)=>{let C=()=>{if(N(_)&&!L)clearTimeout(J)};if(_.connecting)_.once("connect",C);else C();if(L)_.once("secureConnect",()=>clearTimeout(J))}),P.once("response",(_)=>{if(clearTimeout(J),_.on("error",()=>{}),!N(_.socket))return;H.removeEventListener("abort",I),M({request:P,response:_,address:R})}),P.on("error",(_)=>{if(H.aborted)return A(H.reason);A(_ instanceof T?_:new o(Q.href,_))}),P.end(X??void 0)})}finally{clearTimeout(J)}}function uQ({url:Q,hop:Z,method:$,request:X,response:G,address:Y,policy:K,signal:J,release:H}){let W=G.statusCode??0;if(W<200||W>599)throw X.destroy(),new o(Q.href,Error(`Unexpected status ${W}`));let z=new Headers,B=G.rawHeaders;for(let C=0;C<B.length;C+=2)z.append(B[C],B[C+1]);if(K.contentTypes){let C=z.get("content-type")?.split(";")[0].trim().toLowerCase()??null;if(!C||!K.contentTypes.some((j)=>dQ(C,j)))throw X.destroy(),new J1(Q.href,C,K.contentTypes)}let L={url:Q.href,redirected:Z>0,address:Y},D={status:W,statusText:G.statusMessage??"",headers:z};if($==="HEAD"||gQ.has(W))return X.destroy(),H(),new u1(null,D,L);let M=z.get("content-encoding")?.trim().toLowerCase(),V=M==="gzip"||M==="x-gzip"?s.createGunzip():M==="deflate"?s.createInflate():M==="br"?s.createBrotliDecompress():null,U=Number(z.get("content-length"));if(!V&&Number.isFinite(U)&&U>K.maxSize)throw X.destroy(),new q1(Q.href,K.maxSize);if(V)z.delete("content-encoding"),z.delete("content-length");let P=V?G.pipe(V):G,R=0,A=!1,I=()=>{},N=()=>{A=!0,J.removeEventListener("abort",I),H()},_=new ReadableStream({start(C){let j=(F)=>{if(A)return;if(N(),F===void 0)C.close();else X.destroy(),V?.destroy(),C.error(F)};if(I=()=>j(J.reason),J.addEventListener("abort",I,{once:!0}),J.aborted)return I();P.on("data",(F)=>{if(A)return;if(R+=F.byteLength,R>K.maxSize)return j(new q1(Q.href,K.maxSize));if(C.enqueue(new Uint8Array(F)),(C.desiredSize??1)<=0)P.pause()}),P.once("end",()=>j());let w=(F)=>j(F instanceof T?F:new o(Q.href,F));if(P.on("error",w),V)G.on("error",w);G.once("aborted",()=>j(new o(Q.href,Error("The response was cut off."))))},pull(){P.resume()},cancel(){if(A)return;N(),X.destroy(),V?.destroy()}});return new u1(_,D,L)}function dQ(Q,Z){let $=Z.toLowerCase();return $.endsWith("/*")?Q.startsWith($.slice(0,-1)):Q===$}function x0(Q){return iQ(Q)??tQ(Q)??sQ(Q)}var d1=4096,lQ={"image/png":"png","image/jpeg":"jpg","image/gif":"gif","image/webp":"webp","image/avif":"avif","image/heic":"heic","image/heif":"heif","image/bmp":"bmp","image/tiff":"tiff","image/x-icon":"ico","image/svg+xml":"svg","audio/mpeg":"mp3","audio/aac":"aac","audio/mp4":"m4a","audio/ogg":"ogg","audio/flac":"flac","audio/wav":"wav","video/mp4":"mp4","video/quicktime":"mov","video/webm":"webm","video/x-matroska":"mkv","video/x-msvideo":"avi","font/woff":"woff","font/woff2":"woff2","font/ttf":"ttf","font/otf":"otf","application/pdf":"pdf","application/zip":"zip","application/gzip":"gz","application/xml":"xml","text/html":"html","text/plain":"txt","application/octet-stream":"bin"};function k0(Q){return lQ[Q]??"bin"}function E(Q,Z,$=0){if(Q.length<$+Z.length)return!1;return Z.every((X,G)=>Q[$+G]===X)}function y(Q,Z,$){return String.fromCharCode(...Q.subarray(Z,$))}var nQ={avif:"image/avif",avis:"image/avif",heic:"image/heic",heix:"image/heic",hevc:"image/heic",hevx:"image/heic",heim:"image/heic",heis:"image/heic",mif1:"image/heif",msf1:"image/heif","qt ":"video/quicktime","M4A ":"audio/mp4","M4B ":"audio/mp4"};function iQ(Q){if(E(Q,[137,80,78,71,13,10,26,10]))return"image/png";if(E(Q,[255,216,255]))return"image/jpeg";if(Q.length>=6&&(y(Q,0,6)==="GIF87a"||y(Q,0,6)==="GIF89a"))return"image/gif";if(Q.length>=12&&y(Q,0,4)==="RIFF"){let Z=y(Q,8,12);if(Z==="WEBP")return"image/webp";if(Z==="WAVE")return"audio/wav";if(Z==="AVI ")return"video/x-msvideo"}if(Q.length>=12&&y(Q,4,8)==="ftyp"){let Z=y(Q,8,12);return nQ[Z]??"video/mp4"}if(E(Q,[73,73,42,0])||E(Q,[77,77,0,42]))return"image/tiff";if(E(Q,[66,77])&&E(Q,[0,0,0,0],6))return"image/bmp";if(E(Q,[0,0,1,0])&&Q.length>=6&&Q[4]>0)return"image/x-icon";if(E(Q,[37,80,68,70,45]))return"application/pdf";if(E(Q,[80,75,3,4]))return"application/zip";if(E(Q,[31,139]))return"application/gzip";if(E(Q,[26,69,223,163]))return y(Q,0,Math.min(Q.length,64)).includes("webm")?"video/webm":"video/x-matroska";if(Q.length>=4){let Z=y(Q,0,4);if(Z==="OggS")return"audio/ogg";if(Z==="fLaC")return"audio/flac";if(Z==="wOFF")return"font/woff";if(Z==="wOF2")return"font/woff2";if(Z==="OTTO")return"font/otf"}if(E(Q,[0,1,0,0,0]))return"font/ttf";if(Q.length>=3&&y(Q,0,3)==="ID3")return"audio/mpeg";if(Q.length>=2&&Q[0]===255){if((Q[1]&246)===240)return"audio/aac";if((Q[1]&224)===224&&(Q[1]&6)!==0)return"audio/mpeg"}return null}var oQ=["!doctype html","html","head","script","iframe","h1","div","font","table","a","style","title","b","body","br","p","!--"];function tQ(Q){let Z=new TextDecoder("utf-8",{fatal:!1}).decode(Q);if(Z.charCodeAt(0)===65279)Z=Z.slice(1);if(Z=Z.trimStart(),!Z.startsWith("<"))return null;let $=Z.toLowerCase(),X=$;for(;;){X=X.trimStart();let G=/^(<\?[\s\S]*?\?>|<!--[\s\S]*?-->|<!doctype[^>]*>)/.exec(X);if(!G)break;X=X.slice(G[0].length)}if(/^<svg[\s>/]/.test(X))return"image/svg+xml";for(let G of oQ){if(!$.startsWith(`<${G}`))continue;if(/^[\s>]/.test($.charAt(G.length+1)))return"text/html"}if(/^<(html|head|body)[\s>]/.test(X))return"text/html";if($.startsWith("<?xml"))return"application/xml";return null}function sQ(Q){if(Q.length===0)return"application/octet-stream";for(let Z of Q)if(Z<32&&Z!==9&&Z!==10&&Z!==12&&Z!==13&&Z!==27)return"application/octet-stream";try{return new TextDecoder("utf-8",{fatal:!0}).decode(Q,{stream:!0}),"text/plain"}catch{return"application/octet-stream"}}var aQ=new Set(["text/html","application/xhtml+xml","image/svg+xml","text/xml","application/xml","text/xsl","application/xslt+xml"]);function E0(Q){let Z=Q.split(";")[0].trim().toLowerCase();return aQ.has(Z)||Z.endsWith("+xml")}function g0(Q,Z){let $=Q.split(";")[0].trim().toLowerCase();return Z.some((X)=>{let G=X.split(";")[0].trim().toLowerCase();if(G==="*/*"||G==="*")return!E0($);if(G.endsWith("/*"))return $.startsWith(G.slice(0,-1))&&!E0($);return $===G})}import{Buffer as QZ}from"buffer";async function y0(Q){try{return(await import("sharp")).default}catch(Z){throw Error(`${Q} requires the 'sharp' package. Install it with \`bun add sharp\`.`,{cause:Z})}}async function b0(Q,Z,$={}){let{name:X,directory:G,bucket:Y,maxSize:K,timeout:J,contentTypes:H,signal:W}=$;if(X!==void 0&&G!==void 0)throw TypeError("Storage.putFromUrl(): pass `name` or `directory`, not both.");if(X!==void 0&&!X)throw TypeError("Storage.putFromUrl(): `name` is empty.");let z=await T0(Z,{...$.fetch,method:"GET",redirect:"follow",contentTypes:void 0,signal:W,timeout:J,maxSize:K});if(!z.ok)throw await z.body?.cancel().catch(()=>{}),new p1(z.url,z.status);let B=(z.body??new Response(new Uint8Array).body).getReader(),L=async(j)=>{throw await B.cancel(j).catch(()=>{}),j},D=[],M=0,V=!1;while(M<d1){let{done:j,value:w}=await B.read();if(j){V=!0;break}D.push(w),M+=w.byteLength}let U=eQ(D,M),P=x0(U.subarray(0,Math.min(M,d1))),R=H?.length?H:["*/*"];if(!g0(P,R))await L(new J1(z.url,P,R));let A=X??[(G??"").replace(/\/+$/,""),`${Bun.randomUUIDv7()}.${k0(P)}`].filter(Boolean).join("/"),I=M,N=new ReadableStream({start(j){if(M>0)j.enqueue(U);if(V)j.close()},async pull(j){let{done:w,value:F}=await B.read();if(w){j.close();return}I+=F.byteLength,j.enqueue(F)},cancel(j){return B.cancel(j)}}),_={name:A,bucket:Y,body:N,contentType:P},C;try{C=Q.putStream?await Q.putStream(_,{signal:W}):await Y1.prototype.putStream.call(Q,_,{signal:W})}catch(j){throw await L(j),j}return{name:C,contentType:P,size:I,url:z.url}}function eQ(Q,Z){if(Q.length===1)return Q[0];let $=new Uint8Array(Z),X=0;for(let G of Q)$.set(G,X),X+=G.byteLength;return $}class ZZ extends G1{static getFacadeAccessor(){return m1}static async put(Q,Z={}){return this.getFacadeRoot().driver.put(Q,Z)}static async putFromUrl(Q,Z={}){return b0(this.getFacadeRoot().driver,Q,Z)}static async metadata(Q){let Z=QZ.from(await Q.arrayBuffer()),$=await y0("Storage.metadata()");try{return await $(Z).metadata()}catch{return{}}}static async fetch(Q,Z={}){Z.signal?.throwIfAborted();let $=this.getFacadeRoot();return A0($.driver,Q,Z,{fetchTimeoutMs:$.fetchTimeoutMs??v,fetchIdleTimeoutMs:$.fetchIdleTimeoutMs??v})}static async read(Q,Z={}){let $=typeof Q==="string"?{name:Q}:{...Q},X="range"in Z?Z.range??null:$.range!==void 0?$.range:b.getStore()?.rangeRequest??null;return this.getFacadeRoot().driver.read({...$,range:X})}static list(Q){return this.getFacadeRoot().driver.list(Q)}static objects(Q,Z={}){return this.getFacadeRoot().driver.objects(Q,Z)}static async deletePrefix(Q,Z={}){return this.getFacadeRoot().driver.deletePrefix(Q,Z)}static async delete(Q){return this.getFacadeRoot().driver.delete(Q)}}var f0=["cookie","set-cookie","authorization","proxy-authorization","x-api-key"];function d8(Q){return Q}function l8(){let Q=Bun.env.NODE_ENV==="development";return{maxFileSize:10485760,console:Q,consoleFormat:Q?"text":"json",requestFields:[],redactHeaders:[],onLogFileClosed:()=>{},onLogCreated:()=>{}}}import{mkdir as n1,readdir as YZ,access as KZ}from"fs/promises";var l1=["debug","info","notice","warning","error","critical","alert","emergency"],$Z=l1.indexOf("warning");function h0(Q){if(!Q)return-1;if(Q===!0)return 0;let Z=l1.indexOf(Q);return Z===-1?0:Z}function XZ(){let Q=new WeakSet;return function(Z,$){if(typeof $==="bigint")return $.toString();if($ instanceof Error){let X={name:$.name,message:$.message,stack:$.stack};for(let G of Object.keys($))X[G]=$[G];if($.cause!==void 0)X.cause=$.cause;return X}if($!==null&&typeof $==="object"){if(Q.has($))return"[Circular]";Q.add($)}return $}}function v0(Q){try{return JSON.stringify(Q,XZ())}catch{return'"[Unserializable]"'}}function GZ(Q,Z){if(Z==="json")return v0({...Q.metadata,timestamp:Q.timestamp,level:Q.level,message:Q.message});let $=Object.keys(Q.metadata).length>0;return`${Q.timestamp} ${Q.level.toUpperCase()} ${Q.message}${$?` ${v0(Q.metadata)}`:""}`}function m0(Q,Z){let $=l1.indexOf(Q.level);if(Z.threshold===-1||$<Z.threshold)return;try{let X=GZ(Q,Z.format)+`
|
|
5
|
-
`;if($>=$Z)process.stderr.write(X);else process.stdout.write(X)}catch{}}async function i1(Q){try{return await KZ(Q),!0}catch{return!1}}class o1{config;static token="log";writer;isReady=!1;flushTimeout;fileSize=0;writerSize=0;isCreatingFile=!1;bootPromise=null;currentLogFilePath;get logsDirPath(){return`${H1()}/storage/logs`}consoleThreshold;redactedHeaders;constructor(Q){this.config=Q;this.consoleThreshold=h0(Q.console),this.redactedHeaders=new Set([...f0,...Q.redactHeaders??[]].map((Z)=>Z.toLowerCase()))}requestMetadata(Q){let Z=new URL(Q.url),$={method:Q.method,path:Z.pathname,userAgent:Q.headers.get("user-agent")??void 0},X=Q.headers.get("x-request-id");if(X)$.requestId=X;let G=this.config.requestFields??[];if(G.includes("url"))$.url=Q.url;if(G.includes("headers")){let Y={};Q.headers.forEach((K,J)=>{Y[J]=this.redactedHeaders.has(J)?"[redacted]":K}),$.headers=Y}return $}boot(){if(!this.bootPromise)this.bootPromise=this.createStorage().catch((Q)=>{console.error("Log storage unavailable, file logging disabled",Q)}).then(()=>{this.isReady=!0});return this.bootPromise}async createStorage(){let Q=`${H1()}/storage`;if(!await i1(Q))await n1(Q);if(!await i1(this.logsDirPath))await n1(this.logsDirPath);await this.newLogFile()}async newLogFile(){if(!await i1(this.logsDirPath))await n1(this.logsDirPath);if(this.isCreatingFile=!0,this.currentLogFilePath){this.writer.flush(),this.writer.end(),this.writer=null;let $=new File([await Bun.file(this.currentLogFilePath).arrayBuffer()],this.currentLogFilePath.split("/").pop(),{type:"text/plain"});this.config.onLogFileClosed($),this.fileSize=0,this.writerSize=0}let Z=(await YZ(this.logsDirPath)).sort().reverse()[0];if(Z){let $=Bun.file(`${this.logsDirPath}/${Z}`);if($.size<this.config.maxFileSize)this.currentLogFilePath=`${this.logsDirPath}/${Z}`,this.writer=$.writer(),this.writer.write(await $.text()),this.writer.write(`
|
|
6
|
-
`),this.writer.flush(),this.fileSize=$.size}if(!this.writer){let $=`${new Date(Date.now()).toISOString()}.log`.replaceAll(":","-");this.currentLogFilePath=`${this.logsDirPath}/${$}`;let X=Bun.file(`${this.logsDirPath}/${$}`);this.writer=X.writer(),this.fileSize=0,this.writerSize=0}this.isCreatingFile=!1}async log(Q,Z,$={}){if(!this.isReady)await this.boot();let X=b.getStore(),G={},Y={};if(X)Y={method:X.req.rawRequest.method,path:new URL(X.req.rawRequest.url).pathname},G=this.requestMetadata(X.req.rawRequest);let K={timestamp:new Date(Date.now()).toISOString(),env:Bun.env.NODE_ENV,level:Q,message:Z,metadata:{...G,...$}};if(this.consoleThreshold!==-1)m0({timestamp:K.timestamp,level:Q,message:Z,metadata:{...Y,...$}},{threshold:this.consoleThreshold,format:this.config.consoleFormat});let J="";try{J=JSON.stringify(K)}catch(H){console.log("Error parsing log object",H)}try{let H=this.config.onLogCreated(K);if(H instanceof Promise)H.catch((W)=>console.error("Error in onLogCreated",W))}catch(H){console.error("Error in onLogCreated",H)}if(!this.writer)return;this.writerSize+=J.length,this.fileSize+=J.length;try{this.writer.write(J),this.writer.write(`
|
|
7
|
-
`),this.tryFlush()}catch(H){console.error("Error writing log",H)}}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 HZ extends G1{static getFacadeAccessor(){return o1}static debug(Q,Z){this.getFacadeRoot().log("debug",Q,Z)}static info(Q,Z){this.getFacadeRoot().log("info",Q,Z)}static notice(Q,Z){this.getFacadeRoot().log("notice",Q,Z)}static warning(Q,Z){this.getFacadeRoot().log("warning",Q,Z)}static error(Q,Z){this.getFacadeRoot().log("error",Q,Z)}static critical(Q,Z){this.getFacadeRoot().log("critical",Q,Z)}static alert(Q,Z){this.getFacadeRoot().log("alert",Q,Z)}static emergency(Q,Z){this.getFacadeRoot().log("emergency",Q,Z)}}class JZ{config;static token="redis";instance=null;connectingSince=null;downSince=null;replaceDelay=500;constructor(Q={}){this.config=Q}get client(){if(this.instance===null)return this.build();let Q=this.instance;if(this.isDown(Q,Date.now())){this.instance=null;try{Q.close()}catch{}return this.build()}return Q}set client(Q){this.instance=Q,this.connectingSince=null,this.downSince=null,this.replaceDelay=500}close(){let Q=this.instance;this.instance=null,this.connectingSince=null,this.downSince=null,this.replaceDelay=500,Q?.close()}build(){let Q=new(WZ())(this.config.url,this.config.options);if(this.instance=Q,this.downSince=null,this.connectingSince=null,typeof Q.connect==="function"){this.connectingSince=Date.now();let Z;try{Z=Promise.resolve(Q.connect())}catch($){Z=Promise.reject($)}Z.then(()=>{if(this.instance!==Q)return;this.connectingSince=null,this.replaceDelay=500},()=>{if(this.instance!==Q)return;this.connectingSince=null})}return Q}isDown(Q,Z){if(Q.connected!==!1||typeof Q.connect!=="function")return this.downSince=null,!1;if(this.connectingSince!==null){let $=(this.config.options?.connectionTimeout??1e4)+5000;if(Z-this.connectingSince<$)return!1;this.connectingSince=null}if(this.downSince??=Z,Z-this.downSince<this.replaceDelay)return!1;return this.replaceDelay=Math.min(this.replaceDelay*2,1e4),!0}}function WZ(){let Q=globalThis.Bun?.RedisClient;if(typeof Q!=="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 Q}var t1=new TextEncoder;function c0(Q){return`id: ${Q.seq}
|
|
8
|
-
data: ${JSON.stringify(Q.event)}
|
|
9
|
-
|
|
10
|
-
`}var VZ=5000,zZ=`: keepalive
|
|
11
|
-
|
|
12
|
-
`;function BZ(Q,Z=VZ){let $=null,X=!1,G=()=>{if(X)return;if($!==null)clearTimeout($);$=setTimeout(()=>{if($=null,X)return;try{Q.enqueue(t1.encode(zZ))}catch{Y();return}G()},Z)},Y=()=>{if(X=!0,$!==null)clearTimeout($);$=null};return G(),{touch:G,stop:Y}}function PZ(){return{"Content-Type":"text/event-stream","Cache-Control":"no-store, no-transform",Connection:"keep-alive","X-Accel-Buffering":"no"}}function G$(Q,Z=200){let $=Q[Symbol.asyncIterator](),X=-1,G,Y=new ReadableStream({start(K){G=BZ(K)},async pull(K){try{let J=await $.next();if(J.done){G.stop(),K.close();return}X=J.value.seq,K.enqueue(t1.encode(c0(J.value))),G.touch()}catch(J){let H={type:"error",error:UZ(J)};G.stop(),K.enqueue(t1.encode(c0({seq:X+1,event:H}))),K.close()}},cancel(K){G.stop(),$.return?.(K)}});return new Response(Y,{status:Z,headers:PZ()})}var DZ=new Set(["frame_cursor_evicted","live_run_not_found"]);function UZ(Q){let Z=Q&&typeof Q==="object"?Q.code:void 0;if(Q instanceof Error&&typeof Z==="string"&&DZ.has(Z))return{code:"unknown",message:Q.message,retryable:!1};return console.error("[gemi/ai] agent stream failed",Q),{code:"unknown",message:"The run's stream failed.",retryable:!1}}
|
|
13
|
-
export{s1 as Ph,p0 as Qh,RZ as Rh,J0 as Sh,SZ as Th,z0 as Uh,EZ as Vh,a1 as Wh,r1 as Xh,LZ as Yh,CZ as Zh,OZ as _h,e1 as $h,kZ as ai,D0 as bi,gZ as ci,yZ as di,a as ei,k as fi,G0 as gi,H0 as hi,FZ as ii,qZ as ji,WQ as ki,j0 as li,VQ as mi,y1 as ni,b1 as oi,zQ as pi,m as qi,BQ as ri,G1 as si,y0 as ti,A1 as ui,Y1 as vi,L0 as wi,h1 as xi,R8 as yi,O0 as zi,m1 as Ai,_0 as Bi,T as Ci,c as Di,I1 as Ei,i as Fi,N1 as Gi,F1 as Hi,q1 as Ii,J1 as Ji,c1 as Ki,o as Li,p1 as Mi,W1 as Ni,T1 as Oi,u1 as Pi,T0 as Qi,x0 as Ri,E0 as Si,ZZ as Ti,d8 as Ui,l8 as Vi,o1 as Wi,HZ as Xi,JZ as Yi,c0 as Zi,zZ as _i,BZ as $i,PZ as aj,G$ as bj};
|
|
14
|
-
|
|
15
|
-
//# debugId=C42D8D547A2FAD9864756E2164756E21
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|