gemi 0.116.0 → 0.117.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 +2 -2
- package/dist/app/index.js.map +1 -1
- package/dist/auth/AuthServiceProvider.d.ts.map +1 -1
- package/dist/auth/config.d.ts +27 -0
- package/dist/auth/config.d.ts.map +1 -1
- package/dist/auth/connections/ConnectionManager.d.ts +133 -0
- package/dist/auth/connections/ConnectionManager.d.ts.map +1 -0
- package/dist/auth/connections/ConnectionStore.d.ts +146 -0
- package/dist/auth/connections/ConnectionStore.d.ts.map +1 -0
- package/dist/auth/connections/ConnectionsController.d.ts +23 -0
- package/dist/auth/connections/ConnectionsController.d.ts.map +1 -0
- package/dist/auth/connections/OAuthConnectionProvider.d.ts +105 -0
- package/dist/auth/connections/OAuthConnectionProvider.d.ts.map +1 -0
- package/dist/auth/connections/errors.d.ts +32 -0
- package/dist/auth/connections/errors.d.ts.map +1 -0
- package/dist/auth/oauth/oauthState.d.ts +15 -2
- package/dist/auth/oauth/oauthState.d.ts.map +1 -1
- package/dist/auth/routes.d.ts +13 -0
- package/dist/auth/routes.d.ts.map +1 -1
- package/dist/bin/orm/emit.d.ts.map +1 -1
- package/dist/bin/orm-generator.js +51 -4
- package/dist/bin/orm-generator.js.map +4 -4
- package/dist/bun/plugin.js +2 -2
- package/dist/bun/plugin.js.map +1 -1
- package/dist/bun/preload.js +2 -2
- package/dist/bun/preload.js.map +1 -1
- package/dist/chunk-00n3gwr8.js +71 -0
- package/dist/chunk-00n3gwr8.js.map +13 -0
- package/dist/{chunk-t4yh4nf9.js → chunk-076jezzg.js} +3 -3
- package/dist/{chunk-t4yh4nf9.js.map → chunk-076jezzg.js.map} +1 -1
- package/dist/{chunk-qjhw8nje.js → chunk-077rea02.js} +1 -1
- package/dist/{chunk-6cx8ncd4.js → chunk-1ckha5dt.js} +3 -3
- package/dist/{chunk-6cx8ncd4.js.map → chunk-1ckha5dt.js.map} +1 -1
- package/dist/{chunk-mschc94q.js → chunk-1zzd39qg.js} +2 -2
- package/dist/{chunk-mschc94q.js.map → chunk-1zzd39qg.js.map} +1 -1
- package/dist/{chunk-5stgtwqw.js → chunk-2bja99cq.js} +2 -2
- package/dist/{chunk-5stgtwqw.js.map → chunk-2bja99cq.js.map} +1 -1
- package/dist/chunk-2czfefn2.js +10 -0
- package/dist/{chunk-yf1njzd5.js.map → chunk-2czfefn2.js.map} +5 -4
- package/dist/{chunk-aazmrxj9.js → chunk-37pk2cjg.js} +2 -2
- package/dist/{chunk-aazmrxj9.js.map → chunk-37pk2cjg.js.map} +1 -1
- package/dist/{chunk-qsrcdzan.js → chunk-3w4hk6q2.js} +3 -3
- package/dist/{chunk-qsrcdzan.js.map → chunk-3w4hk6q2.js.map} +1 -1
- package/dist/chunk-51w202vr.js +5 -0
- package/dist/{chunk-whtzggn6.js.map → chunk-51w202vr.js.map} +3 -4
- package/dist/{chunk-4088szy9.js → chunk-5m8vvtvn.js} +3 -3
- package/dist/{chunk-4088szy9.js.map → chunk-5m8vvtvn.js.map} +1 -1
- package/dist/{chunk-6d8rvr1v.js → chunk-5p4z1fgc.js} +2 -2
- package/dist/{chunk-6d8rvr1v.js.map → chunk-5p4z1fgc.js.map} +1 -1
- package/dist/{chunk-kejwjerj.js → chunk-5w6kyxsj.js} +2 -2
- package/dist/{chunk-kejwjerj.js.map → chunk-5w6kyxsj.js.map} +1 -1
- package/dist/{chunk-pyk3gzvc.js → chunk-62jw0vsf.js} +2 -2
- package/dist/{chunk-pyk3gzvc.js.map → chunk-62jw0vsf.js.map} +1 -1
- package/dist/chunk-63ewmmhc.js +5 -0
- package/dist/{chunk-1q9kd20m.js.map → chunk-63ewmmhc.js.map} +1 -1
- package/dist/{chunk-p1aqq0ga.js → chunk-6ggmk2eg.js} +3 -3
- package/dist/{chunk-p1aqq0ga.js.map → chunk-6ggmk2eg.js.map} +1 -1
- package/dist/{chunk-2tzm58j3.js → chunk-6y4nk9f1.js} +2 -2
- package/dist/{chunk-2tzm58j3.js.map → chunk-6y4nk9f1.js.map} +1 -1
- package/dist/{chunk-1hr4xht1.js → chunk-8gtc3s1y.js} +2 -2
- package/dist/{chunk-1hr4xht1.js.map → chunk-8gtc3s1y.js.map} +1 -1
- package/dist/{chunk-frerzsxq.js → chunk-a22h5cby.js} +2 -2
- package/dist/{chunk-frerzsxq.js.map → chunk-a22h5cby.js.map} +1 -1
- package/dist/{chunk-zyt2w03d.js → chunk-a32wfzdq.js} +2 -2
- package/dist/{chunk-zyt2w03d.js.map → chunk-a32wfzdq.js.map} +1 -1
- package/dist/{chunk-t04f3akb.js → chunk-a77586gv.js} +2 -2
- package/dist/{chunk-t04f3akb.js.map → chunk-a77586gv.js.map} +1 -1
- package/dist/chunk-a7r39713.js +5 -0
- package/dist/chunk-a7r39713.js.map +10 -0
- package/dist/{chunk-vxm6yevm.js → chunk-arwmvgrz.js} +2 -2
- package/dist/{chunk-vxm6yevm.js.map → chunk-arwmvgrz.js.map} +1 -1
- package/dist/{chunk-41da9628.js → chunk-bvqae0px.js} +1 -1
- package/dist/{chunk-d9mar37g.js → chunk-c2n6zdyd.js} +2 -2
- package/dist/{chunk-d9mar37g.js.map → chunk-c2n6zdyd.js.map} +1 -1
- package/dist/{chunk-56jky6vf.js → chunk-cytss9mb.js} +2 -2
- package/dist/{chunk-56jky6vf.js.map → chunk-cytss9mb.js.map} +1 -1
- package/dist/{chunk-vw8849ys.js → chunk-dcgvq79a.js} +2 -2
- package/dist/{chunk-m54s6jpr.js.map → chunk-dcgvq79a.js.map} +1 -1
- package/dist/{chunk-6chz1ktz.js → chunk-de4t48j9.js} +3 -3
- package/dist/{chunk-6chz1ktz.js.map → chunk-de4t48j9.js.map} +1 -1
- package/dist/{chunk-cbqazg9k.js → chunk-dz99g58c.js} +2 -2
- package/dist/{chunk-cbqazg9k.js.map → chunk-dz99g58c.js.map} +1 -1
- package/dist/{chunk-e573yxpq.js → chunk-e7ezmag9.js} +3 -3
- package/dist/{chunk-e573yxpq.js.map → chunk-e7ezmag9.js.map} +1 -1
- package/dist/{chunk-yer1r3t3.js → chunk-epvpmakp.js} +2 -2
- package/dist/{chunk-yer1r3t3.js.map → chunk-epvpmakp.js.map} +1 -1
- package/dist/{chunk-yhrye9cm.js → chunk-f8vcwzgd.js} +2 -2
- package/dist/{chunk-yhrye9cm.js.map → chunk-f8vcwzgd.js.map} +1 -1
- package/dist/chunk-fa37qzm3.js +5 -0
- package/dist/chunk-fa37qzm3.js.map +12 -0
- package/dist/{chunk-fxgxf16k.js → chunk-ffgmqwzy.js} +2 -2
- package/dist/{chunk-fxgxf16k.js.map → chunk-ffgmqwzy.js.map} +1 -1
- package/dist/{chunk-er3wf6ng.js → chunk-fk6nxhxn.js} +2 -2
- package/dist/{chunk-er3wf6ng.js.map → chunk-fk6nxhxn.js.map} +1 -1
- package/dist/{chunk-3hrj5rwm.js → chunk-fnwbbmnk.js} +2 -2
- package/dist/{chunk-3hrj5rwm.js.map → chunk-fnwbbmnk.js.map} +1 -1
- package/dist/chunk-g2wncay4.js +9 -0
- package/dist/{chunk-hytt9qyj.js.map → chunk-g2wncay4.js.map} +3 -4
- package/dist/{chunk-gts5p6mw.js → chunk-ge9xjwgq.js} +4 -4
- package/dist/{chunk-gts5p6mw.js.map → chunk-ge9xjwgq.js.map} +1 -1
- package/dist/{chunk-tw5kwbx4.js → chunk-gjy2qjcr.js} +2 -2
- package/dist/{chunk-tw5kwbx4.js.map → chunk-gjy2qjcr.js.map} +1 -1
- package/dist/{chunk-15c2vgaf.js → chunk-gn7kne7r.js} +2 -2
- package/dist/{chunk-15c2vgaf.js.map → chunk-gn7kne7r.js.map} +1 -1
- package/dist/{chunk-9n1hx3mq.js → chunk-hr61ekcr.js} +3 -3
- package/dist/{chunk-9n1hx3mq.js.map → chunk-hr61ekcr.js.map} +1 -1
- package/dist/{chunk-m54s6jpr.js → chunk-hvgmqt6z.js} +2 -2
- package/dist/{chunk-vw8849ys.js.map → chunk-hvgmqt6z.js.map} +1 -1
- package/dist/{chunk-aeh67ynz.js → chunk-hvpn18bb.js} +3 -3
- package/dist/{chunk-aeh67ynz.js.map → chunk-hvpn18bb.js.map} +1 -1
- package/dist/{chunk-jdhdrr2k.js → chunk-j1453bn1.js} +2 -2
- package/dist/{chunk-jdhdrr2k.js.map → chunk-j1453bn1.js.map} +1 -1
- package/dist/{chunk-tn2bryy2.js → chunk-jpetnpzn.js} +2 -2
- package/dist/{chunk-tn2bryy2.js.map → chunk-jpetnpzn.js.map} +1 -1
- package/dist/{chunk-v1tfdgy1.js → chunk-jqrs16g2.js} +3 -3
- package/dist/{chunk-v1tfdgy1.js.map → chunk-jqrs16g2.js.map} +1 -1
- package/dist/{chunk-4mfrgd5m.js → chunk-kk77x2v4.js} +2 -2
- package/dist/{chunk-4mfrgd5m.js.map → chunk-kk77x2v4.js.map} +1 -1
- package/dist/chunk-kpn7f58a.js +14 -0
- package/dist/{chunk-pn8v6fj2.js.map → chunk-kpn7f58a.js.map} +11 -6
- package/dist/chunk-mhteg4yz.js +57 -0
- package/dist/{chunk-ms9k0rx6.js.map → chunk-mhteg4yz.js.map} +15 -11
- package/dist/{chunk-n672d4g8.js → chunk-n9jyjp4a.js} +2 -2
- package/dist/{chunk-n672d4g8.js.map → chunk-n9jyjp4a.js.map} +1 -1
- package/dist/{chunk-vbdty91k.js → chunk-nb2gggba.js} +3 -3
- package/dist/{chunk-vbdty91k.js.map → chunk-nb2gggba.js.map} +1 -1
- package/dist/chunk-ntxsdchf.js +50 -0
- package/dist/chunk-ntxsdchf.js.map +10 -0
- package/dist/{chunk-2z1981d0.js → chunk-pepzecrm.js} +2 -2
- package/dist/{chunk-2z1981d0.js.map → chunk-pepzecrm.js.map} +1 -1
- package/dist/{chunk-785b41h1.js → chunk-pgy3mfxw.js} +3 -3
- package/dist/{chunk-785b41h1.js.map → chunk-pgy3mfxw.js.map} +1 -1
- package/dist/{chunk-98m15b9x.js → chunk-qhw0hej0.js} +2 -2
- package/dist/{chunk-98m15b9x.js.map → chunk-qhw0hej0.js.map} +1 -1
- package/dist/{chunk-303mprnv.js → chunk-r3v2cnrj.js} +2 -2
- package/dist/{chunk-303mprnv.js.map → chunk-r3v2cnrj.js.map} +1 -1
- package/dist/{chunk-ktr3k768.js → chunk-rhmpphhc.js} +3 -3
- package/dist/{chunk-ktr3k768.js.map → chunk-rhmpphhc.js.map} +1 -1
- package/dist/{chunk-fre6f4nk.js → chunk-s4f56035.js} +2 -2
- package/dist/{chunk-fre6f4nk.js.map → chunk-s4f56035.js.map} +1 -1
- package/dist/{chunk-sr942vb1.js → chunk-sj4f7x4p.js} +2 -2
- package/dist/{chunk-sr942vb1.js.map → chunk-sj4f7x4p.js.map} +1 -1
- package/dist/{chunk-wyw6p3fg.js → chunk-sksmnjkn.js} +3 -3
- package/dist/{chunk-wyw6p3fg.js.map → chunk-sksmnjkn.js.map} +1 -1
- package/dist/{chunk-kqxdsv22.js → chunk-stnd9qht.js} +2 -2
- package/dist/{chunk-kqxdsv22.js.map → chunk-stnd9qht.js.map} +1 -1
- package/dist/{chunk-1myhm0g3.js → chunk-t65074mw.js} +3 -3
- package/dist/{chunk-1myhm0g3.js.map → chunk-t65074mw.js.map} +1 -1
- package/dist/chunk-t87w4h84.js +24 -0
- package/dist/{chunk-79xg42e7.js.map → chunk-t87w4h84.js.map} +2 -2
- package/dist/{chunk-z10cas5r.js → chunk-thz75w6e.js} +2 -2
- package/dist/{chunk-z10cas5r.js.map → chunk-thz75w6e.js.map} +1 -1
- package/dist/{chunk-xt9tv99x.js → chunk-v8vnxkvp.js} +2 -2
- package/dist/{chunk-xt9tv99x.js.map → chunk-v8vnxkvp.js.map} +1 -1
- package/dist/{chunk-x7cpth2f.js → chunk-veq07rp8.js} +1 -1
- package/dist/{chunk-agyfv3f8.js → chunk-vj5necm0.js} +1 -1
- package/dist/{chunk-p91b8zcn.js → chunk-vtc23xpk.js} +2 -2
- package/dist/{chunk-p91b8zcn.js.map → chunk-vtc23xpk.js.map} +1 -1
- package/dist/{chunk-jmpw6bqz.js → chunk-w4e480he.js} +2 -2
- package/dist/{chunk-jmpw6bqz.js.map → chunk-w4e480he.js.map} +1 -1
- package/dist/{chunk-8rv62v14.js → chunk-wgb79ysr.js} +2 -2
- package/dist/{chunk-8rv62v14.js.map → chunk-wgb79ysr.js.map} +1 -1
- package/dist/{chunk-1vzks22y.js → chunk-wk1tp1f1.js} +2 -2
- package/dist/{chunk-1vzks22y.js.map → chunk-wk1tp1f1.js.map} +1 -1
- package/dist/{chunk-bra1a1fq.js → chunk-wwdbgshx.js} +2 -2
- package/dist/{chunk-bra1a1fq.js.map → chunk-wwdbgshx.js.map} +1 -1
- package/dist/{chunk-eqse2m6n.js → chunk-wzzrz612.js} +2 -2
- package/dist/{chunk-eqse2m6n.js.map → chunk-wzzrz612.js.map} +1 -1
- package/dist/{chunk-hdps9n52.js → chunk-x7qwx07b.js} +3 -3
- package/dist/{chunk-hdps9n52.js.map → chunk-x7qwx07b.js.map} +1 -1
- package/dist/chunk-x84as3vy.js +5 -0
- package/dist/chunk-x84as3vy.js.map +12 -0
- package/dist/chunk-y0en07zh.js +302 -0
- package/dist/chunk-y0en07zh.js.map +17 -0
- package/dist/{chunk-d2gfcf85.js → chunk-yfwrbfnw.js} +2 -2
- package/dist/{chunk-d2gfcf85.js.map → chunk-yfwrbfnw.js.map} +1 -1
- package/dist/{chunk-mazznq15.js → chunk-yhp6bvhj.js} +3 -3
- package/dist/{chunk-mazznq15.js.map → chunk-yhp6bvhj.js.map} +1 -1
- package/dist/{chunk-tzm3c7n6.js → chunk-yvtmygrk.js} +4 -4
- package/dist/{chunk-tzm3c7n6.js.map → chunk-yvtmygrk.js.map} +1 -1
- package/dist/{chunk-mqfzdfnz.js → chunk-zkjs3m5m.js} +2 -2
- package/dist/{chunk-mqfzdfnz.js.map → chunk-zkjs3m5m.js.map} +1 -1
- package/dist/chunk-zw6843j3.js +5 -0
- package/dist/chunk-zw6843j3.js.map +12 -0
- package/dist/client/Head.d.ts.map +1 -1
- package/dist/client/fonts.d.ts +69 -0
- package/dist/client/fonts.d.ts.map +1 -0
- package/dist/client/index.d.ts +1 -0
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +75 -1
- package/dist/client/index.js.map +1 -1
- package/dist/config/index.js +1 -1
- package/dist/console/builtins.d.ts +13 -0
- package/dist/console/builtins.d.ts.map +1 -0
- package/dist/console/run.js +13 -11
- package/dist/console/run.js.map +6 -5
- package/dist/console/runner.d.ts.map +1 -1
- package/dist/console/usage.d.ts +2 -0
- package/dist/console/usage.d.ts.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/Connections.d.ts +36 -0
- package/dist/facades/Connections.d.ts.map +1 -0
- package/dist/facades/Crypt.d.ts +26 -0
- package/dist/facades/Crypt.d.ts.map +1 -0
- package/dist/facades/Meta.d.ts +7 -1
- package/dist/facades/Meta.d.ts.map +1 -1
- package/dist/facades/Storage.d.ts +29 -0
- package/dist/facades/Storage.d.ts.map +1 -1
- package/dist/facades/index.d.ts +2 -0
- package/dist/facades/index.d.ts.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/HttpRequest.d.ts +1 -0
- package/dist/http/HttpRequest.d.ts.map +1 -1
- package/dist/http/Metadata.d.ts +5 -0
- package/dist/http/Metadata.d.ts.map +1 -1
- package/dist/http/index.d.ts +3 -1
- package/dist/http/index.d.ts.map +1 -1
- package/dist/http/index.js +2 -2
- package/dist/http/index.js.map +1 -1
- package/dist/http/requestContext.d.ts +1 -0
- package/dist/http/requestContext.d.ts.map +1 -1
- package/dist/http/safeFetch/errors.d.ts +10 -0
- package/dist/http/safeFetch/errors.d.ts.map +1 -1
- package/dist/http/safeFetch/index.d.ts +1 -1
- package/dist/http/safeFetch/index.d.ts.map +1 -1
- package/dist/http/sitemap/Robots.d.ts +95 -0
- package/dist/http/sitemap/Robots.d.ts.map +1 -0
- package/dist/http/sitemap/Sitemap.d.ts +145 -0
- package/dist/http/sitemap/Sitemap.d.ts.map +1 -0
- package/dist/http/sitemap/fetchText.d.ts +16 -0
- package/dist/http/sitemap/fetchText.d.ts.map +1 -0
- package/dist/http/sitemap/index.d.ts +3 -0
- package/dist/http/sitemap/index.d.ts.map +1 -0
- package/dist/http/sitemap/xml.d.ts +21 -0
- package/dist/http/sitemap/xml.d.ts.map +1 -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.d.ts +1 -1
- package/dist/i18n/index.d.ts.map +1 -1
- package/dist/i18n/index.js +2 -2
- package/dist/i18n/index.js.map +2 -2
- package/dist/i18n/resolveLocale.d.ts +18 -0
- package/dist/i18n/resolveLocale.d.ts.map +1 -1
- package/dist/kernel/index.js +3 -3
- package/dist/kernel/index.js.map +3 -3
- package/dist/kernel/providers.d.ts +2 -2
- package/dist/kernel/providers.d.ts.map +1 -1
- package/dist/orm/Model.d.ts.map +1 -1
- package/dist/orm/encryption-rotate.d.ts +44 -0
- package/dist/orm/encryption-rotate.d.ts.map +1 -0
- package/dist/orm/encryption.d.ts +54 -0
- package/dist/orm/encryption.d.ts.map +1 -0
- package/dist/orm/index.d.ts +2 -0
- package/dist/orm/index.d.ts.map +1 -1
- package/dist/orm/index.js +3 -3
- package/dist/orm/index.js.map +4 -4
- package/dist/orm/schema.d.ts +25 -1
- package/dist/orm/schema.d.ts.map +1 -1
- package/dist/server/index.js +2 -2
- package/dist/server/index.js.map +1 -1
- package/dist/services/encryption/Encrypter.d.ts +86 -0
- package/dist/services/encryption/Encrypter.d.ts.map +1 -0
- package/dist/services/encryption/EncryptionServiceProvider.d.ts +13 -0
- package/dist/services/encryption/EncryptionServiceProvider.d.ts.map +1 -0
- package/dist/services/encryption/config.d.ts +36 -0
- package/dist/services/encryption/config.d.ts.map +1 -0
- package/dist/services/file-storage/drivers/FileStorageDriver.d.ts +12 -1
- package/dist/services/file-storage/drivers/FileStorageDriver.d.ts.map +1 -1
- package/dist/services/file-storage/drivers/FileSystemDriver.d.ts +8 -1
- package/dist/services/file-storage/drivers/FileSystemDriver.d.ts.map +1 -1
- package/dist/services/file-storage/drivers/types.d.ts +17 -0
- package/dist/services/file-storage/drivers/types.d.ts.map +1 -1
- package/dist/services/file-storage/putFromUrl.d.ts +56 -0
- package/dist/services/file-storage/putFromUrl.d.ts.map +1 -0
- package/dist/services/file-storage/sniffContentType.d.ts +33 -0
- package/dist/services/file-storage/sniffContentType.d.ts.map +1 -0
- package/dist/services/index.d.ts +18 -4
- package/dist/services/index.d.ts.map +1 -1
- package/dist/services/index.js +10 -10
- package/dist/services/index.js.map +4 -3
- package/dist/services/queue/DatabaseQueueDriver.d.ts +96 -7
- package/dist/services/queue/DatabaseQueueDriver.d.ts.map +1 -1
- package/dist/services/queue/Job.d.ts +72 -0
- package/dist/services/queue/Job.d.ts.map +1 -1
- package/dist/services/queue/MemoryQueueDriver.d.ts +22 -2
- package/dist/services/queue/MemoryQueueDriver.d.ts.map +1 -1
- package/dist/services/queue/QueueDriver.d.ts +74 -1
- package/dist/services/queue/QueueDriver.d.ts.map +1 -1
- package/dist/services/queue/QueueManager.d.ts +47 -0
- package/dist/services/queue/QueueManager.d.ts.map +1 -1
- package/dist/services/queue/batch.d.ts +112 -0
- package/dist/services/queue/batch.d.ts.map +1 -0
- package/dist/services/queue/queueDriverContract.d.ts +5 -0
- package/dist/services/queue/queueDriverContract.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/ViewRouteDispatcher.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 +2 -2
- package/dist/vitest/index.js.map +1 -1
- package/package.json +1 -1
- package/dist/chunk-1q9kd20m.js +0 -5
- package/dist/chunk-49nyyjfe.js +0 -5
- package/dist/chunk-49nyyjfe.js.map +0 -11
- package/dist/chunk-79xg42e7.js +0 -24
- package/dist/chunk-7vb4eey2.js +0 -217
- package/dist/chunk-7vb4eey2.js.map +0 -16
- package/dist/chunk-hytt9qyj.js +0 -54
- package/dist/chunk-jmg2zsaf.js +0 -5
- package/dist/chunk-jmg2zsaf.js.map +0 -12
- package/dist/chunk-ms9k0rx6.js +0 -46
- package/dist/chunk-pn8v6fj2.js +0 -14
- package/dist/chunk-whtzggn6.js +0 -5
- package/dist/chunk-yf1njzd5.js +0 -10
- /package/dist/{chunk-qjhw8nje.js.map → chunk-077rea02.js.map} +0 -0
- /package/dist/{chunk-41da9628.js.map → chunk-bvqae0px.js.map} +0 -0
- /package/dist/{chunk-x7cpth2f.js.map → chunk-veq07rp8.js.map} +0 -0
- /package/dist/{chunk-agyfv3f8.js.map → chunk-vj5necm0.js.map} +0 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{
|
|
2
|
+
import{Wi as a}from"./chunk-dcgvq79a.js";var i=a((f)=>{function u(t){let r={};if(t=t.replace(/^\?/,""),t)for(let n of t.split("&")){let[e,s=null]=n.split("=");if(e=decodeURIComponent(e),s)s=decodeURIComponent(s);if(!(e in r))r[e]=s;else if(Array.isArray(r[e]))r[e].push(s);else r[e]=[r[e],s]}return r}f.parseQueryString=u});var U=a((d)=>{var y=i(),c=(t)=>{if(typeof t==="string")return c(new URL(t));let{hostname:r,pathname:n,port:e,protocol:s,search:o}=t,p;if(o)p=y.parseQueryString(o);return{hostname:r,port:e?parseInt(e):void 0,protocol:s,path:n,query:p}};d.parseUrl=c});
|
|
3
3
|
export{U as Z};
|
|
4
4
|
|
|
5
|
-
//# debugId=
|
|
5
|
+
//# debugId=74124BFE44BDFB8E64756E2164756E21
|
|
@@ -6,6 +6,6 @@
|
|
|
6
6
|
"'use strict';\n\nvar querystringParser = require('@smithy/querystring-parser');\n\nconst parseUrl = (url) => {\n if (typeof url === \"string\") {\n return parseUrl(new URL(url));\n }\n const { hostname, pathname, port, protocol, search } = url;\n let query;\n if (search) {\n query = querystringParser.parseQueryString(search);\n }\n return {\n hostname,\n port: port ? parseInt(port) : undefined,\n protocol,\n path: pathname,\n query,\n };\n};\n\nexports.parseUrl = parseUrl;\n"
|
|
7
7
|
],
|
|
8
8
|
"mappings": ";uDAEA,SAAS,CAAgB,CAAC,EAAa,CACnC,IAAM,EAAQ,CAAC,EAEf,GADA,EAAc,EAAY,QAAQ,MAAO,EAAE,EACvC,EACA,QAAW,KAAQ,EAAY,MAAM,GAAG,EAAG,CACvC,IAAK,EAAK,EAAQ,MAAQ,EAAK,MAAM,GAAG,EAExC,GADA,EAAM,mBAAmB,CAAG,EACxB,EACA,EAAQ,mBAAmB,CAAK,EAEpC,GAAI,EAAE,KAAO,GACT,EAAM,GAAO,EAEZ,QAAI,MAAM,QAAQ,EAAM,EAAI,EAC7B,EAAM,GAAK,KAAK,CAAK,EAGrB,OAAM,GAAO,CAAC,EAAM,GAAM,CAAK,EAI3C,OAAO,EAGH,mBAAmB,kBCxB3B,IAAI,MAEE,EAAW,CAAC,IAAQ,CACtB,GAAI,OAAO,IAAQ,SACf,OAAO,EAAS,IAAI,IAAI,CAAG,CAAC,EAEhC,IAAQ,WAAU,WAAU,OAAM,WAAU,UAAW,EACnD,EACJ,GAAI,EACA,EAAQ,EAAkB,iBAAiB,CAAM,EAErD,MAAO,CACH,WACA,KAAM,EAAO,SAAS,CAAI,EAAI,OAC9B,WACA,KAAM,EACN,OACJ,GAGI,WAAW",
|
|
9
|
-
"debugId": "
|
|
9
|
+
"debugId": "74124BFE44BDFB8E64756E2164756E21",
|
|
10
10
|
"names": []
|
|
11
11
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// @bun
|
|
2
2
|
import{watch as K,existsSync as L,readFileSync as M}from"fs";import{join as O}from"path";function P(G){let A={};for(let C of G.split(`
|
|
3
3
|
`)){let z=C.trim();if(!z||z.startsWith("#"))continue;let B=z.startsWith("export ")?z.slice(7).trim():z,I=B.indexOf("=");if(I===-1)continue;let J=B.slice(0,I).trim();if(!J)continue;let H=B.slice(I+1).trim();if(H.length>=2&&(H.startsWith('"')&&H.endsWith('"')||H.startsWith("'")&&H.endsWith("'")))H=H.slice(1,-1);A[J]=H}return A}function Q(G){let A=Bun.env.NODE_ENV,C=[".env"];if(A)C.push(`.env.${A}`);if(A!=="test"){if(C.push(".env.local"),A)C.push(`.env.${A}.local`)}return C.map((z)=>O(G,z))}function R(G){let A={};for(let z of Q(G))if(L(z))Object.assign(A,P(M(z,"utf8")));let C=[];for(let[z,B]of Object.entries(A))if(process.env[z]!==B)process.env[z]=B,C.push(z);return C}function V(G=process.cwd()){if(globalThis.__gemiEnvWatcher)return;let A;globalThis.__gemiEnvWatcher=K(G,(C,z)=>{if(!z||!String(z).startsWith(".env"))return;clearTimeout(A),A=setTimeout(()=>{try{let B=R(G);if(B.length)console.log(`[gemi] .env reloaded: ${B.join(", ")}`)}catch(B){console.error("[gemi] failed to reload .env:",B)}},50)})}
|
|
4
|
-
export{Q as
|
|
4
|
+
export{Q as Ga,V as Ha};
|
|
5
5
|
|
|
6
|
-
//# debugId=
|
|
6
|
+
//# debugId=B160D754446BE26F64756E2164756E21
|
|
@@ -5,6 +5,6 @@
|
|
|
5
5
|
"import { watch, existsSync, readFileSync, type FSWatcher } from \"node:fs\";\nimport { join } from \"node:path\";\n\ndeclare global {\n // A single directory watcher, kept on globalThis so `bun --hot` reloads (which\n // re-run `Server.start`) don't stack duplicate watchers.\n var __gemiEnvWatcher: FSWatcher | undefined;\n}\n\n// Minimal `.env` parser: `KEY=VALUE` lines, `#` comments, an optional leading\n// `export`, and surrounding single/double quotes stripped. Multi-line values and\n// `${VAR}` interpolation are intentionally not handled (uncommon subset).\nfunction parseEnv(content: string): Record<string, string> {\n const out: Record<string, string> = {};\n for (const raw of content.split(\"\\n\")) {\n const line = raw.trim();\n if (!line || line.startsWith(\"#\")) continue;\n const body = line.startsWith(\"export \") ? line.slice(7).trim() : line;\n const eq = body.indexOf(\"=\");\n if (eq === -1) continue;\n const key = body.slice(0, eq).trim();\n if (!key) continue;\n let value = body.slice(eq + 1).trim();\n if (\n value.length >= 2 &&\n ((value.startsWith('\"') && value.endsWith('\"')) ||\n (value.startsWith(\"'\") && value.endsWith(\"'\")))\n ) {\n value = value.slice(1, -1);\n }\n out[key] = value;\n }\n return out;\n}\n\n// The `.env` files Bun loads, in increasing precedence (later overrides earlier).\n// `.env.local` is skipped for `NODE_ENV=test`, matching Bun/dotenv conventions.\nexport function envFiles(rootDir: string): string[] {\n const nodeEnv = process.env.NODE_ENV;\n const names = [\".env\"];\n if (nodeEnv) names.push(`.env.${nodeEnv}`);\n if (nodeEnv !== \"test\") {\n names.push(\".env.local\");\n if (nodeEnv) names.push(`.env.${nodeEnv}.local`);\n }\n return names.map((name) => join(rootDir, name));\n}\n\n// Re-read the env files and apply them to `process.env`. Only adds/updates keys\n// (a value edit is the common case); a key removed from the file keeps its last\n// value until the next full restart, so we never clobber the real OS environment.\nfunction applyEnv(rootDir: string): string[] {\n const merged: Record<string, string> = {};\n for (const file of envFiles(rootDir)) {\n if (existsSync(file)) {\n Object.assign(merged, parseEnv(readFileSync(file, \"utf8\")));\n }\n }\n const changed: string[] = [];\n for (const [key, value] of Object.entries(merged)) {\n if (process.env[key] !== value) {\n process.env[key] = value;\n changed.push(key);\n }\n }\n return changed;\n}\n\n// Watch the project's `.env` files and re-apply them to `process.env` on change,\n// so edits take effect without restarting the dev server. Bun loads `.env` only\n// at startup and does not reload it (even under `--hot`), so this fills that gap.\n// Dev only — called from `Server.start()`'s dev branch, not in production.\n// Idempotent: keeps a single watcher across `bun --hot` reloads.\n//\n// Note: this updates `process.env`, so config read at request time picks up the\n// new value immediately; values a service reads once at boot (e.g. a client\n// constructed from an env var) are cached and won't change until that code\n// re-runs (a hot reload in dev, a restart in prod).\nexport function watchEnv(rootDir: string = process.cwd()) {\n if (globalThis.__gemiEnvWatcher) return;\n\n let timer: ReturnType<typeof setTimeout> | undefined;\n globalThis.__gemiEnvWatcher = watch(rootDir, (_event, filename) => {\n // Non-recursive: only direct children of `rootDir`. Filter to `.env*`.\n if (!filename || !String(filename).startsWith(\".env\")) return;\n clearTimeout(timer);\n timer = setTimeout(() => {\n try {\n const changed = applyEnv(rootDir);\n if (changed.length) {\n console.log(`[gemi] .env reloaded: ${changed.join(\", \")}`);\n }\n } catch (error) {\n console.error(\"[gemi] failed to reload .env:\", error);\n }\n }, 50);\n });\n}\n"
|
|
6
6
|
],
|
|
7
7
|
"mappings": ";AAAA,gBAAS,gBAAO,kBAAY,WAC5B,eAAS,aAWT,SAAS,CAAQ,CAAC,EAAyC,CACzD,IAAM,EAA8B,CAAC,EACrC,QAAW,KAAO,EAAQ,MAAM;AAAA,CAAI,EAAG,CACrC,IAAM,EAAO,EAAI,KAAK,EACtB,GAAI,CAAC,GAAQ,EAAK,WAAW,GAAG,EAAG,SACnC,IAAM,EAAO,EAAK,WAAW,SAAS,EAAI,EAAK,MAAM,CAAC,EAAE,KAAK,EAAI,EAC3D,EAAK,EAAK,QAAQ,GAAG,EAC3B,GAAI,IAAO,GAAI,SACf,IAAM,EAAM,EAAK,MAAM,EAAG,CAAE,EAAE,KAAK,EACnC,GAAI,CAAC,EAAK,SACV,IAAI,EAAQ,EAAK,MAAM,EAAK,CAAC,EAAE,KAAK,EACpC,GACE,EAAM,QAAU,IACd,EAAM,WAAW,GAAG,GAAK,EAAM,SAAS,GAAG,GAC1C,EAAM,WAAW,GAAG,GAAK,EAAM,SAAS,GAAG,GAE9C,EAAQ,EAAM,MAAM,EAAG,EAAE,EAE3B,EAAI,GAAO,EAEb,OAAO,EAKF,SAAS,CAAQ,CAAC,EAA2B,CAClD,IAAM,EAAU,iBACV,EAAQ,CAAC,MAAM,EACrB,GAAI,EAAS,EAAM,KAAK,QAAQ,GAAS,EACzC,GAAI,IAAY,QAEd,GADA,EAAM,KAAK,YAAY,EACnB,EAAS,EAAM,KAAK,QAAQ,SAAe,EAEjD,OAAO,EAAM,IAAI,CAAC,IAAS,EAAK,EAAS,CAAI,CAAC,EAMhD,SAAS,CAAQ,CAAC,EAA2B,CAC3C,IAAM,EAAiC,CAAC,EACxC,QAAW,KAAQ,EAAS,CAAO,EACjC,GAAI,EAAW,CAAI,EACjB,OAAO,OAAO,EAAQ,EAAS,EAAa,EAAM,MAAM,CAAC,CAAC,EAG9D,IAAM,EAAoB,CAAC,EAC3B,QAAY,EAAK,KAAU,OAAO,QAAQ,CAAM,EAC9C,GAAI,QAAQ,IAAI,KAAS,EACvB,QAAQ,IAAI,GAAO,EACnB,EAAQ,KAAK,CAAG,EAGpB,OAAO,EAaF,SAAS,CAAQ,CAAC,EAAkB,QAAQ,IAAI,EAAG,CACxD,GAAI,WAAW,iBAAkB,OAEjC,IAAI,EACJ,WAAW,iBAAmB,EAAM,EAAS,CAAC,EAAQ,IAAa,CAEjE,GAAI,CAAC,GAAY,CAAC,OAAO,CAAQ,EAAE,WAAW,MAAM,EAAG,OACvD,aAAa,CAAK,EAClB,EAAQ,WAAW,IAAM,CACvB,GAAI,CACF,IAAM,EAAU,EAAS,CAAO,EAChC,GAAI,EAAQ,OACV,QAAQ,IAAI,yBAAyB,EAAQ,KAAK,IAAI,GAAG,EAE3D,MAAO,EAAO,CACd,QAAQ,MAAM,gCAAiC,CAAK,IAErD,EAAE,EACN",
|
|
8
|
-
"debugId": "
|
|
8
|
+
"debugId": "B160D754446BE26F64756E2164756E21",
|
|
9
9
|
"names": []
|
|
10
10
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import{Ub as eZ,Xb as t,Yb as Z3,fc as YZ}from"./chunk-5m8vvtvn.js";import{qc as LZ,sc as ZZ,uc as B3,vc as F3,xc as L3}from"./chunk-rhmpphhc.js";import{Cc as _3,Ec as K3,Fc as H3,Gc as D,Hc as U3,Ic as Q3,Kc as V3,zc as Y3}from"./chunk-y0en07zh.js";import{Nc as J}from"./chunk-n9jyjp4a.js";import{Ce as m,De as zZ,Ee as AZ,Nd as p,Xd as x3,Yd as qZ,ae as r,cd as q3,gd as v,jd as rZ,ke as MZ,me as GZ,nd as T3,qe as kZ,ye as l}from"./chunk-mhteg4yz.js";import{If as b,Kf as CZ,Zf as jZ,lg as gZ,pg as $Z,qg as a,rg as i}from"./chunk-kpn7f58a.js";import{Dg as aZ}from"./chunk-x84as3vy.js";import{Jg as DZ}from"./chunk-00n3gwr8.js";import{Mg as N3,Ng as OZ,Qg as e,Rg as SZ,Ug as C3}from"./chunk-fa37qzm3.js";import{Bh as k,zh as X3}from"./chunk-jpetnpzn.js";import{Ch as _}from"./chunk-dz99g58c.js";import{Ih as A3}from"./chunk-t65074mw.js";import{wi as TZ}from"./chunk-3w4hk6q2.js";import{Di as J3,Gi as g}from"./chunk-076jezzg.js";var k3="mcp",R3=/^[\x21\x23-\x5B\x5D-\x7E]+$/;class L extends YZ{status;constructor(Z,$){super(Z);this.status=$;this.name="McpToolError"}}class d extends Error{reason;constructor(Z,$){super(Z);this.reason=$;this.name="McpCallRefusedError"}}var w3=/^[A-Za-z0-9_-]{1,64}$/,E3=/:([A-Za-z_][A-Za-z0-9_]*)([?*+]?)/g,RZ=4000,f=1e5,b3=/^(text\/|application\/([\w.+-]*\+)?(json|xml))/i;class y{router;dispatcher;static token="router.mcp";plans=new Map;scopeTools=new Map;files;constructor(Z,$,G={}){this.router=Z;this.dispatcher=$;this.files=y3(G.files);for(let[W,z]of Object.entries(Z.routes??{}))this.plans.set(W,this.plan(W,z));this.resolveScopes()}list(Z,$){if(wZ(Z),Z.kind==="local")return this.descriptors($);let G=[];for(let[W,z]of this.plans){if(!z.remote||!this.grants(Z.principal,W))continue;if(EZ(z.remote,$))G.push(z.remote)}return G}descriptors(Z){let $=[];for(let{descriptor:G}of this.plans.values())if(EZ(G,Z))$.push(G);return $}get maxFileBytes(){return this.files.maxBytes}scopes(){return[...this.scopeTools].map(([Z,{description:$}])=>({name:Z,description:$}))}scopesFor(Z){return[...this.scopeTools].filter(([,{tools:$}])=>$.has(Z)).map(([$])=>$)}async execute(Z,$,G,W,z={}){wZ(Z);let X=this.plans.get($);if(Z.kind==="remote"){if(!X?.remote||!this.grants(Z.principal,$))throw new d(`There is no tool named "${$}".`,"unknown-tool");if(X.descriptor.requiresApproval&&z.approved!==!0)throw new d(`"${$}" needs the user's approval, and this call does not have it.`,"approval-required");W=void 0}if(!X)throw Error(`McpRegistry: there is no tool named "${$}".`);let Y=X,K=Z.kind==="remote"?Y.remote:Y.descriptor,U=K.inputSchema.safeParse(G);if(U.ok===!1)throw new L(`Invalid arguments for "${$}": ${U.errors.join(", ")}`);let H=U.value,Q={caller:Z,req:Z.req,tool:K,input:H,ctx:W},V=await this.fillPath(Y,Q),{path:I}=this.dispatcher.getRouteHandlerAndParams(new Request(`http://gemi.internal/api${V}`));if(I!==K.url)throw new L(`"${$}" has nothing at ${V}.`,404);let C={};for(let q of Y.jsonKeys)if(H[q]!==void 0)C[q]=H[q];let P,x="";if(Y.fileFields.length>0)P=await this.formData(Y,C,Q);else if(K.method==="GET")x=n3(C);else if(Y.jsonKeys.length>0)P=C;let j=this.router.credentials?await this.bind(Y,"the credentials",()=>this.router.credentials(Q)):void 0,E={...j?{credentials:j}:{},...z.signal?{signal:z.signal}:{},...z.progress?{progress:z.progress}:{},...Z.kind==="remote"?{identity:{user:Z.principal.user,grant:{via:Z.principal.via,id:Z.principal.id,scopes:Z.principal.scopes,...Z.principal.clientId?{clientId:Z.principal.clientId}:{}}}}:{}},u;try{let q=x?`${V}?${x}`:V;u=Object.keys(E).length>0?await this.dispatcher.dispatchAs(Z.req,K.method,q,P,E):await this.dispatcher.dispatchAs(Z.req,K.method,q,P)}catch(q){throw console.error(`[gemi/mcp] Dispatching "${$}" failed:`,q),new L(`"${$}" failed on the server.`,500)}if(!Y.result&&!K.outputSchema)return await vZ($,u);return await this.project(Y,Q,u)}plan(Z,$){if(!w3.test(Z))throw Error(`McpRouter: "${Z}" is not a valid tool name. A routes key is the tool's name as a model and an MCP client see it, used verbatim \u2014 letters, digits, "_" and "-", at most 64.`);let G=`McpRouter: "${Z}" (${$?.method} ${$?.url})`;if(!($ instanceof Object)||$.__internal_brand!=="McpRoute")throw Error(`McpRouter: "${Z}" is not a route. Declare it with this.fromApiRoute(...).`);let{method:W,url:z,meta:X}=$;if(z.startsWith("/__gemi__"))throw Error(`${G} is a framework route, not an app route.`);let Y=this.dispatcher.flatRoutes[z]?.[W];if(!Y)throw Error(`${G} names no route of this app. Expose a route by the path and verb it is mounted at.`);let K=[...z.matchAll(E3)].map(([,B,A])=>({name:B,modifier:A})),U=X.params??{};for(let B of K)if(!(B.name in U))throw Error(`${G}: the path param "${B.name}" must be bound or declared "input".`);for(let[B,A]of Object.entries(U)){if(!K.some((M)=>M.name===B))throw Error(`${G}: "${B}" in params is not a param of the url.`);if(fZ(A))u3(G,`params.${B}`,A);else bZ(G,`params.${B}`,A)}let H=[],Q;if(X.input){if(Q=X.input.toJSONSchema(),Q.type!=="object"||!Q.properties)throw Error(`${G}: input must be an s.object(...), the fields of the request body.`);H=Object.keys(Q.properties)}let V=Object.entries(X.files??{}).map(([B,A])=>({name:B,binder:A}));for(let B of V)bZ(G,`files.${B.name}`,B.binder);if(X.result!==void 0&&typeof X.result!=="function")throw Error(`${G}: result must be a function.`);if(X.output!==void 0&&typeof X.output?.safeParse!=="function")throw Error(`${G}: output must be a schema, built with s.`);if(X.title!==void 0&&(typeof X.title!=="string"||X.title===""))throw Error(`${G}: title must be a non-empty string.`);let I=p3(G,W,X.annotations);if(V.length>0&&W==="GET")throw Error(`${G}: a GET has no body to carry a file.`);let C={},P=(B,A)=>{if(B in C)throw Error(`${G}: "${B}" is the input key of two params or files, and the model can only send one.`);C[B]=A},x=new Map,j=new Map;for(let B of K){let A=U[B.name];if(A==="input"){let M=b.string().describe(`The ":${B.name}" segment of the url.`);P(B.name,B.modifier==="?"||B.modifier==="*"?M.optional():M)}else if(fZ(A)){let M=A.as??B.name;P(M,A.input),j.set(B.name,{key:M,param:A})}else x.set(B.name,A)}let E={};for(let B of V)if(B.binder==="input")P(B.name,b.string().describe("The id of an attachment the user uploaded or a tool produced (gemi_att_\u2026), whose file is sent as this field.")),E[B.name]=this.remoteFileSchema();let u=[...Object.keys(C),...V.map((B)=>B.name)];for(let B of new Set(u))if(H.includes(B))throw Error(`${G}: "${B}" is both an input field and a param or file, and the model can only send one.`);let q=Object.freeze({name:Z,description:X.description,method:W,url:z,inputSchema:yZ(X.input,Q,b.object(C)),...X.output?{outputSchema:X.output}:{},...X.title?{title:X.title}:{},annotations:I,tags:Object.freeze([...X.tags??[]]),requiresApproval:X.requiresApproval===!0,...Y.source?{source:Y.source}:{}}),M3=!V.every((B)=>B.binder==="input")?null:V.length===0?q:Object.freeze({...q,inputSchema:yZ(X.input,Q,b.object(i3(C,Object.keys(E))),E)});return{descriptor:q,remote:M3,params:K,paramBinders:x,modelParams:j,fileFields:V,jsonKeys:H,...X.result?{result:X.result}:{}}}remoteFileSchema(){let{maxBytes:Z,fetch:$}=this.files,G={name:{type:"string",description:"The file's name, like report.pdf."},mimeType:{type:"string",description:"The file's media type, like application/pdf."},data:{type:"string",contentEncoding:"base64",description:`The file's bytes, base64-encoded (RFC 4648, standard alphabet). At most ${Z} bytes decoded.`}};if($)G.url={type:"string",format:"uri",description:"An https URL the server downloads the file from, instead of data."};let W={type:"object",description:$?"A file, sent as base64 in data or fetched from url: exactly one of the two.":"A file, sent as base64 in data.",properties:G,required:["name","mimeType"],additionalProperties:!1},z=Object.keys(G),X=(Y)=>{if(typeof Y!=="object"||Y===null||Array.isArray(Y))return{ok:!1,errors:["a file must be an object"]};let K=[],U={};for(let H of Object.keys(Y))if(!z.includes(H))K.push(`a file has no field "${H}"`);for(let H of z){let Q=Y[H];if(Q===void 0||Q===null){if(H==="name"||H==="mimeType")K.push(`a file needs "${H}"`);continue}if(typeof Q!=="string")K.push(`a file's "${H}" must be a string`);else U[H]=Q}return K.length>0?{ok:!1,errors:K}:{ok:!0,value:U}};return{toJSONSchema:()=>W,safeParse:X,parse(Y){let K=X(Y);if(K.ok===!1)throw Error(K.errors.join(", "));return K.value}}}async fillPath(Z,$){let{input:G,req:W}=$,z=Z.descriptor.url;for(let X of Z.params){let Y=Z.paramBinders.get(X.name),K=Z.modelParams.get(X.name),U;if(Y||K){if(U=K?await this.bind(Z,`the param "${X.name}"`,()=>K.param.bind(G[K.key],W,$),{refusals:!0}):await this.bind(Z,`the param "${X.name}"`,()=>Y(W,$)),U===void 0||U===null||U==="")throw console.error(`[gemi/mcp] The ${K?"resolver":"binder"} for "${X.name}" of "${Z.descriptor.name}" returned ${JSON.stringify(U)}.`),new L(`"${Z.descriptor.name}" failed on the server.`,500)}else U=G[X.name];let H=`:${X.name}${X.modifier}`;if(U===void 0||U===null||U===""){if(X.modifier!=="?"&&X.modifier!=="*")throw new L(`"${X.name}" of "${Z.descriptor.name}" must not be empty.`);z=z.replace(`/${H}`,"");continue}z=z.replace(H,l3(Z.descriptor.name,X,String(U)))}return z}async formData(Z,$,G){let{input:W,ctx:z}=G,X=Z.descriptor.name;if(G.caller.kind==="remote"){let K=new FormData;for(let[U,H]of Object.entries($))XZ(K,U,H);for(let U of Z.fileFields)K.append(U.name,await this.remoteFile(X,U.name,W[U.name]));return K}if(!z)throw Error(`McpRegistry: "${X}" sends a file, which is resolved through the tool context's attachments, and none was passed to execute().`);let Y=new FormData;for(let[K,U]of Object.entries($))XZ(Y,K,U);for(let K of Z.fileFields){let U=K.binder==="input"?W[K.name]:await this.bind(Z,`the file "${K.name}"`,()=>K.binder(z,G));if(typeof U!=="string"||U==="")throw new L(`"${X}" needs a file for "${K.name}", and this turn has none. Ask the user to attach one.`);Y.append(K.name,await z.attachments.file(U))}return Y}async remoteFile(Z,$,G){let W=(Q)=>new L(`"${$}" of "${Z}" ${Q}`,400),z=G,{maxBytes:X,fetch:Y}=this.files;if(!v3(z.name))throw W("needs a name of 1 to 255 characters, without control characters or slashes.");if(!g3.test(z.mimeType))throw W(`has a mimeType that is not a media type: "${z.mimeType.slice(0,100)}".`);let K=typeof z.data==="string",U=typeof z.url==="string";if(K===U)throw W(Y?"needs exactly one of data or url.":"needs its bytes, base64, in data.");if(K){let Q=z.data.replace(/\s+/g,"");if(Math.floor(Q.length*3/4)-m3(Q)>X)throw W(`is larger than the ${X} bytes a file may be.`);if(Q.length%4!==0||!h3.test(Q))throw W("has data that is not base64 (RFC 4648, standard alphabet, padded).");return new File([Buffer.from(Q,"base64")],z.name,{type:z.mimeType})}if(!Y)throw W("cannot be fetched from a URL here. Send its bytes, base64, in data.");let H;try{H=new URL(z.url)}catch{throw W("has a url that is not a URL.")}if(H.protocol!=="https:")throw W("can only be fetched from an https URL.");try{let Q=await gZ(H.href,{...Y,maxSize:Math.min(Y.maxSize??X,X),redirect:"follow"});if(!Q.ok)throw W(`could not be fetched: ${H.host} answered ${Q.status}.`);let V=await Q.arrayBuffer();return new File([V],z.name,{type:z.mimeType})}catch(Q){if(Q instanceof L)throw Q;throw W(`could not be fetched from ${H.host}: ${Q instanceof Error?Q.message:"failed"}.`)}}grants(Z,$){for(let G of Z.scopes??[])if(this.scopeTools.get(G)?.tools.has($))return!0;return!1}resolveScopes(){let Z=this.router.scopes;if(Z===void 0){this.scopeTools.set(k3,{description:"Use this app's tools as you",tools:new Set(this.plans.keys())});return}if(typeof Z!=="object"||Z===null)throw Error("McpRouter: scopes must be an object of scope names.");let $=new Set([...this.plans.values()].flatMap(({descriptor:G})=>G.tags));for(let[G,W]of Object.entries(Z)){let z=`McpRouter: scope "${G}"`;if(!R3.test(G))throw Error(`${z} is not a valid OAuth scope: printable ASCII, no spaces or quotes.`);if(typeof W?.description!=="string"||W.description==="")throw Error(`${z} needs a description: it is what a consent screen shows.`);let X=new Set;for(let Y of W.tags??[]){if(!$.has(Y))throw Error(`${z} names the tag "${Y}", which no tool has.`);for(let[K,{descriptor:U}]of this.plans)if(U.tags.includes(Y))X.add(K)}for(let Y of W.names??[]){if(!this.plans.has(Y))throw Error(`${z} names "${Y}", which is no tool.`);X.add(Y)}if(X.size===0)throw Error(`${z} reaches no tool. Give it tags or names.`);this.scopeTools.set(G,{description:W.description,tools:X})}}async project(Z,$,G){let{name:W,outputSchema:z}=Z.descriptor;if(G.status<200||G.status>=300)return await vZ(W,G);let X=(V,I)=>{if(I===void 0)console.error(`[gemi/mcp] "${W}" ${V}`);else console.error(`[gemi/mcp] "${W}" ${V}`,I);return new L(`"${W}" failed on the server.`,500)},Y=G.headers.get("Content-Type"),K=await G.text(),U=null;if(K!=="")try{U=JSON.parse(K)}catch{throw X(`answered ${Y??"a body with no content-type"} that is not JSON, and its result or output needs JSON.`)}let H=U;if(Z.result)try{H=await Z.result(U,$)}catch(V){throw X("failed in its result projection:",V)}if(z){let V=z.safeParse(H);if(V.ok===!1)throw X(`answered what its output schema refuses: ${V.errors.join(", ")}`);H=V.value}if(H===void 0)return null;let Q=JSON.stringify(H);if(Q!==void 0&&Q.length>f)return`${Q.slice(0,f)}\u2026 [cut at ${f} of ${Q.length} characters]`;return H}async bind(Z,$,G,W={}){try{return await G()}catch(z){if(W.refusals&&z instanceof YZ)throw z;throw console.error(`[gemi/mcp] Binding ${$} of "${Z.descriptor.name}" failed:`,z),new L(`"${Z.descriptor.name}" failed on the server.`,500)}}}function wZ(Z){if(Z?.kind==="local"&&Z.req)return;if(Z?.kind==="remote"&&Z.req&&Z.principal?.user&&typeof Z.principal.id==="string"&&Array.isArray(Z.principal.scopes))return;throw Error('McpRegistry: a caller is { kind: "local", req } or { kind: "remote", req, principal }, with the principal a caller resolver verified.')}function EZ(Z,$){if($?.names&&!$.names.includes(Z.name))return!1;if($?.tags&&!Z.tags.some((G)=>$.tags.includes(G)))return!1;return!0}var f3=10485760;function y3(Z){let $=Z?.maxBytes??f3;if(!Number.isSafeInteger($)||$<=0)throw Error("McpRegistry: files.maxBytes must be a positive whole number of bytes.");let G=Z?.fetchUrls===!0?{}:typeof Z?.fetchUrls==="object"&&Z.fetchUrls!==null?Z.fetchUrls:null;return{maxBytes:$,fetch:G}}function v3(Z){if(Z.length===0||Z.length>255)return!1;for(let $ of Z){let G=$.codePointAt(0);if(G<32||G===127||$==="/"||$==="\\")return!1}return!0}var g3=/^[A-Za-z0-9][A-Za-z0-9!#$&^_.+-]{0,126}\/[A-Za-z0-9][A-Za-z0-9!#$&^_.+-]{0,126}(\s*;.{0,200})?$/,h3=/^[A-Za-z0-9+/]*={0,2}$/;function m3(Z){return Z.endsWith("==")?2:Z.endsWith("=")?1:0}function bZ(Z,$,G){if(G!=="input"&&typeof G!=="function")throw Error(`${Z}: ${$} must be a function or "input".`)}function fZ(Z){return Z instanceof Object&&Z.__internal_brand==="McpModelParam"}function u3(Z,$,G){if(G.as!==void 0&&(typeof G.as!=="string"||G.as===""))throw Error(`${Z}: ${$}.as must be a non-empty string.`);let W=G.input;if(typeof W?.safeParse!=="function"||typeof W.toJSONSchema!=="function")throw Error(`${Z}: ${$}.input must be a schema, built with s.`);if(typeof G.bind!=="function")throw Error(`${Z}: ${$}.bind must be a function.`)}var d3=new Set(["readOnlyHint","destructiveHint","idempotentHint","openWorldHint"]);function c3(Z){switch(Z){case"GET":return{readOnlyHint:!0};case"DELETE":return{destructiveHint:!0};case"PUT":return{idempotentHint:!0};default:return{}}}function p3(Z,$,G){if(G!==void 0&&(typeof G!=="object"||G===null))throw Error(`${Z}: annotations must be an object of hints.`);let W=c3($);for(let[z,X]of Object.entries(G??{})){if(!d3.has(z))throw Error(`${Z}: "${z}" is not a tool annotation. Use readOnlyHint, destructiveHint, idempotentHint or openWorldHint.`);if(X===void 0)continue;if(typeof X!=="boolean")throw Error(`${Z}: annotations.${z} must be true or false.`);W[z]=X}if(W.readOnlyHint===!0&&(W.destructiveHint||W.idempotentHint))throw Error(`${Z} is read-only${G?.readOnlyHint?"":` (a ${$})`} and also ${W.destructiveHint?"destructive":"idempotent"}, which only a tool that is not read-only can be. Set readOnlyHint: false if it changes something.`);return Object.freeze(W)}function yZ(Z,$,G,W={}){let z=G.toJSONSchema(),X=Object.fromEntries(Object.entries(W).map(([U,H])=>[U,H.toJSONSchema()])),Y={...$??{},type:"object",properties:{...$?.properties??{},...z.properties,...X},required:[...$?.required??[],...z.required??[],...Object.keys(W)],additionalProperties:!1},K=(U)=>{if(typeof U!=="object"||U===null||Array.isArray(U))return{ok:!1,errors:["expected an object"]};let H=[],Q={};if(Z){let I=Z.safeParse(U);if(I.ok===!1)H.push(...I.errors);else Q={...I.value}}let V=G.safeParse(U);if(V.ok===!1)H.push(...V.errors);else Q={...Q,...V.value};for(let[I,C]of Object.entries(W)){let P=U[I];if(P===void 0){H.push(`"${I}" is required`);continue}let x=C.safeParse(P);if(x.ok===!1)H.push(...x.errors.map((j)=>`${I}: ${j}`));else Q[I]=x.value}return H.length>0?{ok:!1,errors:H}:{ok:!0,value:Q}};return{toJSONSchema:()=>Y,safeParse:K,parse(U){let H=K(U);if(H.ok===!1)throw Error(H.errors.join(", "));return H.value}}}function i3(Z,$){return Object.fromEntries(Object.entries(Z).filter(([G])=>!$.includes(G)))}function l3(Z,$,G){let W=$.modifier==="*"||$.modifier==="+"?G.split("/"):[G];if(W.some((z)=>z==="."||z===".."))throw new L(`"${G}" is not a valid value for "${$.name}" of "${Z}".`);return W.map(encodeURIComponent).join("/")}function XZ(Z,$,G){if(G===void 0||G===null)return;if(Array.isArray(G)){for(let W of G)XZ(Z,$,W);return}Z.append($,typeof G==="object"?JSON.stringify(G):String(G))}function n3(Z){let $=new URLSearchParams,G=(W,z)=>{if(z===void 0||z===null)return;if(Array.isArray(z)){for(let X of z)G(W,X);return}$.append(W,typeof z==="object"?JSON.stringify(z):String(z))};for(let[W,z]of Object.entries(Z))G(W,z);return $.toString()}async function vZ(Z,$){if($.status>=200&&$.status<300){let W=$.headers.get("Content-Type");if(W&&!b3.test(W)){let X=(await $.arrayBuffer()).byteLength;return`"${Z}" answered with ${X} bytes of ${W}, which is not shown.`}let z=await $.text();if(z==="")return null;if(z.length>f)return`${z.slice(0,f)}\u2026 [cut at ${f} of ${z.length} characters]`;try{return JSON.parse(z)}catch{return z}}let G=await $.text();if($.status>=400&&$.status<500){let W=G.length>RZ?`${G.slice(0,RZ)}\u2026`:G;throw new L(`"${Z}" was refused with ${$.status}${W?`: ${W}`:"."}`,$.status)}if($.status<500)console.error(`[gemi/mcp] "${Z}" answered ${$.status}${$.headers.get("Location")?` to ${$.headers.get("Location")}`:""}, which a tool call cannot follow.`);throw new L(`"${Z}" failed on the server.`,$.status)}import{createHash as t3,randomBytes as s3,timingSafeEqual as o3}from"crypto";function KZ(Z){let $=Z.headers.get("authorization");if(!$)return null;let G=/^Bearer[ ]+([\x21-\x7e]+)$/i.exec($.trim());return G?G[1]:null}class a3{options;name="api-key";constructor(Z){this.options=Z;if(typeof Z?.prefix!=="string"||!/^[A-Za-z0-9_-]{3,32}$/.test(Z.prefix))throw Error('McpApiKeyResolver: prefix is required: 3 to 32 letters, digits, _ or -, like "myapp_mcp_".');if(typeof Z.verify!=="function")throw Error("McpApiKeyResolver: verify must be a function that looks a key up.")}static generate(Z){return`${Z}${s3(32).toString("base64url")}`}static hash(Z){return t3("sha256").update(Z).digest("hex")}static hashesMatch(Z,$){let G=Buffer.from(Z),W=Buffer.from($);return G.length===W.length&&o3(G,W)}async resolve(Z){let $=KZ(Z);if(!$?.startsWith(this.options.prefix))return null;let G=await this.options.verify($,Z);if(!G)return{ok:!1,error:"invalid_token",description:"The API key is not valid."};if(!G.user||typeof G.id!=="string"||G.id===""||!Array.isArray(G.scopes))throw Error("McpApiKeyResolver: verify must answer { user, id, scopes } for a key it knows, or null.");return{ok:!0,principal:{user:G.user,via:this.name,id:G.id,scopes:[...G.scopes]}}}}import{createHash as $3,randomBytes as dZ}from"crypto";async function HZ(Z,$){let G=r3();if(!G)return null;let W=await G.consume(Z,$);return W.allowed?null:Math.max(1,Math.ceil(W.retryAfter/1000))}function r3(){try{let Z=g();return Z.bound(v)?Z.make(v):null}catch{return null}}var UZ=["2026-07-28"],n=["2025-11-25","2025-06-18","2025-03-26"],QZ=[...UZ,...n],VZ="io.modelcontextprotocol/protocolVersion",BZ="io.modelcontextprotocol/clientCapabilities";var IZ="io.modelcontextprotocol/serverInfo",N={ParseError:-32700,InvalidRequest:-32600,MethodNotFound:-32601,InvalidParams:-32602,InternalError:-32603,HeaderMismatch:-32020,MissingRequiredClientCapability:-32021,UnsupportedProtocolVersion:-32022};class F extends Error{code;data;status;constructor(Z,$,G,W=200){super($);this.code=Z;this.data=G;this.status=W;this.name="JsonRpcError"}}function T(Z,$){return{jsonrpc:"2.0",id:Z,error:{code:$.code,message:$.message,...$.data!==void 0?{data:$.data}:{}}}}function hZ(Z){if(Array.isArray(Z))throw new F(N.InvalidRequest,"Batched requests are not supported.",void 0,400);if(typeof Z!=="object"||Z===null||Z.jsonrpc!=="2.0")throw new F(N.InvalidRequest,"Not a JSON-RPC 2.0 message.",void 0,400);let $=Z,G=$.id,W=typeof G==="string"||typeof G==="number"&&Number.isFinite(G);if(typeof $.method==="string"){if($.params!==void 0&&(typeof $.params!=="object"||$.params===null||Array.isArray($.params)))throw new F(N.InvalidRequest,"params must be an object.",void 0,400);if(G===void 0)return{kind:"notification",message:$};if(!W)throw new F(N.InvalidRequest,"id must be a string or a number.",void 0,400);return{kind:"request",message:$}}if(W&&(("result"in $)||("error"in $)))return{kind:"response",message:$};throw new F(N.InvalidRequest,"Not a JSON-RPC request, notification or response.",void 0,400)}function JZ(Z,$){let G=Z.outputSchema?.toJSONSchema(),W={...Z.annotations,...Z.title&&!$?{title:Z.title}:{}};return{name:Z.name,...Z.title?{title:Z.title}:{},description:Z.description,inputSchema:Z.inputSchema.toJSONSchema(),...G&&($||G.type==="object")?{outputSchema:G}:{},...Object.keys(W).length>0?{annotations:W}:{}}}function O(Z){return typeof Z==="object"&&Z!==null&&!Array.isArray(Z)}function mZ(Z){let $=/^=\?base64\?([A-Za-z0-9+/]*={0,2})\?=$/.exec(Z);if(!$)return Z;try{let G=Buffer.from($[1],"base64");return new TextDecoder("utf-8",{fatal:!0}).decode(G)}catch{return null}}import{createHmac as e3,timingSafeEqual as Z9}from"crypto";function FZ(Z,$,G){let W=Buffer.from(JSON.stringify(G)).toString("base64url");return`${$}.${W}.${uZ(Z,$,W).toString("base64url")}`}function NZ(Z,$,G,W=Date.now()){if(typeof G!=="string"||G.length>8192)return null;let z=G.split(".");if(z.length!==3||z[0]!==$)return null;let[,X,Y]=z,K=Buffer.from(Y,"base64url"),U=uZ(Z,$,X);if(K.length!==U.length||!Z9(K,U))return null;let H;try{H=JSON.parse(Buffer.from(X,"base64url").toString("utf8"))}catch{return null}if(typeof H!=="object"||H===null)return null;if(typeof H.exp!=="number"||H.exp<=W)return null;return H}function uZ(Z,$,G){return e3("sha256",t(Z)).update(`${$}.${G}`).digest()}var xZ="gemi.mcp.request-state.v1",cZ="gemi.mcp.session.v1",$9=86400000,pZ=600000,iZ="gemi_approval",PZ=2000,G9={limit:600,window:60},W9={limit:30,window:60};class c{registry;static token="router.mcp.http";endpoint;resolvers;context;allowedOrigins;rateLimit;maxBodyBytes;serverInfo;instructions;nonces;approvalTimeoutMs;pending=new Map;inflight=new Map;constructor(Z,$){this.registry=Z;if(typeof $.url!=="string")throw Error(`route.mcp.remote.url is required: the endpoint's canonical URL, like "https://example.com/mcp".`);this.endpoint=Y9($.url);let G=$.resolvers??[];if(!Array.isArray(G)||G.length===0)throw Error("route.mcp.remote is enabled without a caller resolver. Configure route.mcp.remote.resolvers \u2014 an McpOAuthServer, an McpApiKeyResolver, or your own \u2014 or leave the endpoint off. Without one every request would be refused, or answered as nobody.");for(let W of G)if(typeof W?.resolve!=="function"||typeof W.name!=="string"||W.name==="")throw Error("route.mcp.remote.resolvers: each resolver needs a name and a resolve().");this.resolvers=G,t(xZ),this.context={resource:this.resource,registry:Z},this.allowedOrigins=new Set(($.allowedOrigins??[]).map((W)=>{if(new URL(W).origin!==W)throw Error(`route.mcp.remote.allowedOrigins: "${W}" is not an origin (scheme://host[:port]).`);return W})),this.allowedOrigins.add(this.endpoint.origin),this.rateLimit=$.rateLimit===!1?!1:$.rateLimit??G9,this.maxBodyBytes=$.maxBodyBytes??Math.ceil(Z.maxFileBytes*1.4)+1048576,this.serverInfo={name:$.server?.name??"gemi",version:$.server?.version??"1.0.0"},this.instructions=$.server?.instructions,this.nonces=$.nonces??new eZ,this.approvalTimeoutMs=$.approvalTimeoutMs??pZ;for(let W of G)W.boot?.(this.context)}get resource(){return this.endpoint.href.replace(/\/$/,"")}async handle(Z){let $=new URL(Z.url);if($.host!==this.endpoint.host)return null;for(let z of this.resolvers){let X=await z.handle?.(Z,this.context);if(X)return X}if($.pathname!==this.endpoint.pathname)return null;let G=Z.headers.get("origin");if(G!==null&&!this.allowedOrigins.has(G))return S(T(null,new F(N.InvalidRequest,"Origin not allowed.")),403);let W=G?X9(G):{};if(Z.method==="OPTIONS")return new Response(null,{status:204,headers:{...W,"Access-Control-Allow-Methods":"POST","Access-Control-Allow-Headers":"Authorization, Content-Type, Accept, MCP-Protocol-Version, Mcp-Session-Id, Mcp-Method, Mcp-Name, Last-Event-ID","Access-Control-Max-Age":"600"}});if(Z.method!=="POST")return lZ(new Response(null,{status:405,headers:{Allow:"POST, OPTIONS"}}),W);return lZ(await this.post(Z),W)}async post(Z){let $=null;for(let Y of this.resolvers){let K=await Y.resolve(Z,this.context);if(K===null)continue;if(K.ok===!1)return await this.failedAttempt(Z)??this.unauthorized(K.description);$={...K.principal,via:Y.name};break}if(!$)return(KZ(Z)!==null?await this.failedAttempt(Z):null)??this.unauthorized();let G=await this.spend($);if(G)return G;let W=Z.headers.get("content-type")??"";if(!/^application\/json\s*(;|$)/i.test(W))return new Response("Content-Type must be application/json.",{status:415});let z;try{z=JSON.parse(await z9(Z,this.maxBodyBytes))}catch(Y){if(Y instanceof o)return S(T(null,new F(N.InvalidRequest,`The request is larger than ${this.maxBodyBytes} bytes.`)),413);return S(T(null,new F(N.ParseError,"Parse error.")),400)}let X=new CZ(Z,{},"api",this.endpoint.pathname);return await aZ.run(X,async()=>{try{return await this.dispatch(Z,X,$,z)}catch(Y){if(Y instanceof F){let K=O(z)&&(typeof z.id==="string"||typeof z.id==="number")?z.id:null;return S(T(K,Y),Y.status)}return console.error("[gemi/mcp] The MCP endpoint failed:",Y),S(T(null,new F(N.InternalError,"Internal error.")),500)}},{user:$.user})}async dispatch(Z,$,G,W){let z=hZ(W),X={kind:"remote",req:$,principal:G};if(z.kind==="response"){let P=this.session(Z,G),x=this.pending.get(String(z.message.id));if(x&&x.session===P.id)this.pending.delete(String(z.message.id)),x.resolve(z.message);return new Response(null,{status:202})}let{message:Y}=z,K=Y.params??{},U=O(K._meta)?K._meta:{};if(typeof U[VZ]==="string"){if(this.checkModernHeaders(Z,Y,U[VZ]),z.kind==="notification")return new Response(null,{status:202});return await this.respond(Y,async(P,x)=>this.modern({principal:G,caller:X,message:Y,params:K,era:{modern:!0},stream:P,signal:x}),tZ(K),Z.signal)}if(Y.method==="initialize"){if(z.kind!=="request")throw new F(N.InvalidRequest,"initialize is a request.",void 0,400);return this.initialize(z.message,K,G)}let H=this.session(Z,G),Q=Z.headers.get("mcp-protocol-version");if(Q!==null&&Q!==H.state.v)throw new F(N.InvalidRequest,`MCP-Protocol-Version ${Q} is not the session's ${H.state.v}.`,void 0,400);if(z.kind==="notification"){if(Y.method==="notifications/cancelled"){let P=K.requestId;this.inflight.get(`${H.id}:${String(P)}`)?.abort()}return new Response(null,{status:202})}let V=`${H.id}:${String(Y.id)}`,I=new AbortController;this.inflight.set(V,I);let C=AbortSignal.any([I.signal,Z.signal]);try{return await this.respond(Y,async(P,x)=>this.legacy({principal:G,caller:X,message:Y,params:K,era:{modern:!1,session:H.state,sessionId:H.id},stream:P,signal:x}),tZ(K)||H9(this.registry,Y,H.state),C,()=>this.inflight.delete(V))}catch(P){throw this.inflight.delete(V),P}}async modern(Z){switch(Z.message.method){case"server/discover":return this.complete({supportedVersions:QZ,capabilities:{tools:{}},...this.instructions?{instructions:this.instructions}:{},ttlMs:60000,cacheScope:"private"});case"tools/list":return this.complete({tools:this.registry.list(Z.caller).map(($)=>JZ($,!0)),ttlMs:60000,cacheScope:"private"});case"tools/call":return await this.callTool(Z);default:throw new F(N.MethodNotFound,`Method not found: ${Z.message.method}`,void 0,404)}}async legacy(Z){switch(Z.message.method){case"ping":return{};case"tools/list":return{tools:this.registry.list(Z.caller).map(($)=>JZ($,!1))};case"tools/call":return await this.callTool(Z);default:throw new F(N.MethodNotFound,`Method not found: ${Z.message.method}`)}}complete(Z){return{resultType:"complete",...Z,_meta:{[IZ]:this.serverInfo}}}initialize(Z,$,G){let W=$.protocolVersion,z=n.includes(W)?W:n[0],X=O($.capabilities)?$.capabilities:{},Y={v:z,e:nZ(X.elicitation),p:s(G),exp:Date.now()+$9},K=FZ(cZ,"gms1",Y);return S({jsonrpc:"2.0",id:Z.id,result:{protocolVersion:z,capabilities:{tools:{listChanged:!1}},serverInfo:this.serverInfo,...this.instructions?{instructions:this.instructions}:{}}},200,{"Mcp-Session-Id":K})}session(Z,$){let G=Z.headers.get("mcp-session-id");if(!G)throw new F(N.InvalidRequest,"Missing Mcp-Session-Id. Send initialize first, or a request carrying io.modelcontextprotocol/protocolVersion in _meta.",void 0,400);let W=NZ(cZ,"gms1",G);if(!W||W.p!==s($))throw new F(N.InvalidRequest,"Session not found.",void 0,404);return{id:G,state:W}}checkModernHeaders(Z,$,G){if(!UZ.includes(G))throw new F(N.UnsupportedProtocolVersion,"Unsupported protocol version",{supported:QZ,requested:G},400);let W=(Y)=>new F(N.HeaderMismatch,`Header mismatch: ${Y}`,void 0,400);if(Z.headers.get("mcp-protocol-version")!==G)throw W("MCP-Protocol-Version does not match the protocol version in _meta.");if(Z.headers.get("mcp-method")!==$.method)throw W("Mcp-Method does not match the method.");let z=$.params??{},X=$.method==="tools/call"||$.method==="prompts/get"?z.name:$.method==="resources/read"?z.uri:void 0;if(X!==void 0){let Y=Z.headers.get("mcp-name");if(Y===null||mZ(Y)!==X)throw W("Mcp-Name does not match the request's name.")}}async callTool(Z){let{params:$,caller:G,principal:W}=Z,z=$.name;if(typeof z!=="string")throw new F(N.InvalidParams,"tools/call needs a tool name.");let X=$.arguments??{},Y=this.registry.list(G,{names:[z]})[0];if(!Y)throw new F(N.InvalidParams,`Unknown tool: ${z}`);let K=!1;if(Y.requiresApproval){let I=Y.inputSchema.safeParse(X);if(I.ok===!1)return this.toolResult(Z,{content:[{type:"text",text:`Invalid arguments for "${z}": ${I.errors.join(", ")}`}],isError:!0});let C=await this.approval(Z,Y,X);if(C.kind==="answer")return C.result;K=!0}let U=U9(Z),H;try{H=await this.registry.execute(G,z,X,void 0,{approved:K,signal:Z.signal,...U?{progress:U}:{}})}catch(I){if(I instanceof L)return this.toolResult(Z,{content:[{type:"text",text:I.message}],isError:!0});if(I instanceof d)throw new F(N.InvalidParams,I.reason==="unknown-tool"?`Unknown tool: ${z}`:I.message);return console.error(`[gemi/mcp] "${z}" failed for ${W.via}:${W.id}:`,I),this.toolResult(Z,{content:[{type:"text",text:`"${z}" failed on the server.`}],isError:!0})}let Q=typeof H==="string"?H:JSON.stringify(H??null),V=Y.outputSchema&&(Z.era.modern||O(H))?{structuredContent:H}:{};return this.toolResult(Z,{content:[{type:"text",text:Q}],...V,isError:!1})}toolResult(Z,$){return Z.era.modern?this.complete($):$}async approval(Z,$,G){let W=Q9($,G),z=(H)=>({kind:"answer",result:this.toolResult(Z,{content:[{type:"text",text:H}],isError:!0})});if(Z.era.modern){let H=O(Z.params._meta)?Z.params._meta:{},Q=O(H[BZ])?H[BZ]:{},V=O(Z.params.inputResponses)?Z.params.inputResponses:null,I=Z.params.requestState,C=K9(G);if(V&&I!==void 0){let x=NZ(xZ,"grs1",I);if(!x||x.p!==s(Z.principal)||x.t!==$.name||x.a!==C)throw new F(N.InvalidParams,"requestState is not valid for this call.");if(!await this.spendNonce(x.n,x.exp))throw new F(N.InvalidParams,"requestState has already been used.");return sZ(V[iZ])?{kind:"approved"}:z(`The user did not approve "${$.name}", and it did not run.`)}if(!nZ(Q.elicitation))throw new F(N.MissingRequiredClientCapability,`"${$.name}" needs the user's approval, and this client cannot ask for it (elicitation).`,{requiredCapabilities:{elicitation:{form:{}}}},400);let P={p:s(Z.principal),t:$.name,a:C,n:dZ(16).toString("base64url"),exp:Date.now()+pZ};return{kind:"answer",result:{resultType:"input_required",inputRequests:{[iZ]:{method:"elicitation/create",params:{mode:"form",...W}}},requestState:FZ(xZ,"grs1",P),_meta:{[IZ]:this.serverInfo}}}}let X=Z.era;if(!X.session.e||!Z.stream)return z(`"${$.name}" needs the user's approval, and this client cannot ask for it (elicitation). It did not run.`);let Y=`gemi-approval-${dZ(12).toString("base64url")}`,K=X.sessionId,U=await new Promise((H)=>{let Q=setTimeout(()=>{this.pending.delete(Y),H(null)},this.approvalTimeoutMs),V=(I)=>{clearTimeout(Q),H(I)};this.pending.set(Y,{session:K,resolve:V}),Z.signal.addEventListener("abort",()=>{this.pending.delete(Y),V(null)}),Z.stream.send({jsonrpc:"2.0",id:Y,method:"elicitation/create",params:X.session.v==="2025-11-25"?{mode:"form",...W}:W})});return U&&!U.error&&sZ(U.result)?{kind:"approved"}:z(`The user did not approve "${$.name}", and it did not run.`)}async spendNonce(Z,$){try{return await this.nonces.consume(Z,$)}catch(G){return console.error("[gemi/mcp] Spending an approval failed:",G),!1}}async respond(Z,$,G,W,z){if(!G)try{let U=await $(null,W);return S({jsonrpc:"2.0",id:Z.id,result:U},200)}finally{z?.()}let X=new AbortController,Y=AbortSignal.any([X.signal,W]),K=new G3(()=>X.abort());return(async()=>{try{let U=await $(K,Y);K.send({jsonrpc:"2.0",id:Z.id,result:U})}catch(U){if(U instanceof F)K.send(T(Z.id,U));else console.error("[gemi/mcp] The MCP endpoint failed:",U),K.send(T(Z.id,new F(N.InternalError,"Internal error.")))}finally{z?.(),K.close()}})(),new Response(K.readable,{status:200,headers:{"Content-Type":"text/event-stream","Cache-Control":"no-store","X-Accel-Buffering":"no"}})}unauthorized(Z){let $=this.resolvers.map((W)=>W.challenge?.(this.context)).find(Boolean)??'Bearer realm="mcp"',G=Z?`${$}, error="invalid_token", error_description="${Z.replace(/["\\]/g,"")}"`:$;return S(T(null,new F(N.InvalidRequest,"Unauthorized.")),401,{"WWW-Authenticate":G})}async failedAttempt(Z){let $=rZ(new CZ(Z,{},"api",this.endpoint.pathname)),G=await HZ(`mcp-auth-failed:${$}`,W9);return G===null?null:oZ(G)}async spend(Z){if(!this.rateLimit)return null;let $=await HZ(`mcp-endpoint:${Z.via}:${Z.id}`,this.rateLimit);return $===null?null:oZ($)}}class G3{readable;controller;closed=!1;encoder=new TextEncoder;constructor(Z){this.readable=new ReadableStream({start:($)=>{this.controller=$},cancel:()=>{this.closed=!0,Z()}})}send(Z){if(this.closed)return;this.controller.enqueue(this.encoder.encode(`event: message
|
|
3
|
+
data: ${JSON.stringify(Z)}
|
|
4
|
+
|
|
5
|
+
`))}close(){if(this.closed)return;this.closed=!0,this.controller.close()}}class o extends Error{}async function z9(Z,$){let G=Number(Z.headers.get("content-length"));if(Number.isFinite(G)&&G>$)throw new o;if(!Z.body)return"";let W=Z.body.getReader(),z=[],X=0;for(;;){let{done:Y,value:K}=await W.read();if(Y)break;if(X+=K.byteLength,X>$)throw await W.cancel(),new o;z.push(K)}return Buffer.concat(z).toString("utf8")}function S(Z,$,G={}){return new Response(JSON.stringify(Z),{status:$,headers:{"Content-Type":"application/json","Cache-Control":"no-store",...G}})}function lZ(Z,$){for(let[G,W]of Object.entries($))Z.headers.set(G,W);return Z}function X9(Z){return{"Access-Control-Allow-Origin":Z,"Access-Control-Expose-Headers":"Mcp-Session-Id, WWW-Authenticate",Vary:"Origin"}}function Y9(Z){let $;try{$=new URL(Z)}catch{throw Error(`route.mcp.remote.url: "${Z}" is not a URL.`)}let G=$.hostname==="localhost"||$.hostname==="127.0.0.1"||$.hostname==="[::1]";if($.protocol!=="https:"&&!($.protocol==="http:"&&G))throw Error("route.mcp.remote.url must be https (http only on localhost): tokens travel to it.");if($.search||$.hash||$.username||$.password)throw Error("route.mcp.remote.url must have no query, fragment or credentials.");if($.pathname==="/"||$.pathname.endsWith("/"))throw Error('route.mcp.remote.url needs a path of its own, like "/mcp", without a trailing slash.');return $}function s(Z){return $3("sha256").update(`${Z.via}\x00${Z.id}\x00${Z.user?.id}`).digest("base64url").slice(0,32)}function K9(Z){return $3("sha256").update(Z3(Z??{})).digest("base64url")}function nZ(Z){if(!O(Z))return!1;if(Object.keys(Z).length===0)return!0;return"form"in Z}function tZ(Z){let $=O(Z._meta)?Z._meta:{};return typeof $.progressToken==="string"||typeof $.progressToken==="number"}function H9(Z,$,G){if($.method!=="tools/call"||!G.e)return!1;let W=$.params?.name;return typeof W==="string"&&Z.descriptors({names:[W]})[0]?.requiresApproval===!0}function U9(Z){let G=(O(Z.params._meta)?Z.params._meta:{}).progressToken;if(!Z.stream||typeof G!=="string"&&typeof G!=="number")return;let W=-1/0;return(z)=>{if(typeof z?.progress!=="number"||!Number.isFinite(z.progress)||z.progress<=W)return;W=z.progress,Z.stream.send({jsonrpc:"2.0",method:"notifications/progress",params:{progressToken:G,progress:z.progress,...typeof z.total==="number"?{total:z.total}:{},...typeof z.message==="string"?{message:z.message.slice(0,1000)}:{}}})}}function Q9(Z,$){let G=JSON.stringify($??{},null,1),W=G.length>PZ?`${G.slice(0,PZ)}\u2026 (${G.length-PZ} more characters not shown)`:G;return{message:`Allow "${Z.title??Z.name}" to run? ${Z.description}
|
|
6
|
+
|
|
7
|
+
Arguments: ${W}`,requestedSchema:{type:"object",properties:{approve:{type:"boolean",title:"Approve",description:`Run "${Z.title??Z.name}" with these arguments.`}},required:["approve"]}}}function sZ(Z){return O(Z)&&Z.action==="accept"&&O(Z.content)&&Z.content.approve===!0}function oZ(Z){return S(T(null,new F(N.InvalidRequest,"Rate limit exceeded.")),429,{"Retry-After":String(Z)})}async function V9(Z,$={}){try{if(!await Z.shouldRun.call(Z))return}catch(z){console.error(`Error evaluating shouldRun for cron job ${Z.name}:`,z);return}let G=B9(Z.withoutOverlapping);if(!Z.onOneServer&&G===void 0){await _Z(Z);return}let W;try{if(W=$.locks?.()??I9(),Z.onOneServer){let z=Math.floor(($.now??Date.now())/60000);if(!await W.store.advance(`gemi:cron-tick:${Z.name}`,z))return}}catch(z){console.error(`Could not claim the tick of cron job ${Z.name}; skipped it:`,z);return}if(G===void 0){await _Z(Z);return}try{await W.run(`gemi:cron:${Z.name}`,{ttl:G},(z)=>_Z(Z,z))}catch(z){if(z instanceof X3)console.error(`Cron job ${Z.name} lost its withoutOverlapping lock while running: another tick may have started alongside it.`,z);else console.error(`Could not take the withoutOverlapping lock of cron job ${Z.name}:`,z)}}var W3=300000;function B9(Z){if(!Z)return;if(Z===!0)return W3;return Z.expiresAfter??W3}var z3;function I9(){return z3??=new k(new Y3),z3}async function _Z(Z,$){try{await Z.onTick.call(Z)}catch(G){console.error(`Error executing cron job ${Z.name}:`,G)}try{await Z.callback.call(Z,$)}catch(G){console.error(`Error in cron job ${Z.name}:`,G)}try{await Z.onComplete.call(Z)}catch(G){console.error(`Error completing cron job ${Z.name}:`,G)}}class R{static token="scheduler";handles=[];resolved;inFlight=new Map;stopped=!1;locks;constructor(Z){this.resolved=Z.jobs}get jobs(){return[...this.resolved]}useJobs(Z){this.resolved=Z}useLocks(Z){this.locks=Z}start(Z=($)=>$()){if(this.stopped=!1,this.resolved.length===0)return;let $=globalThis.__gemiCronJobs??=new Map,G=new Map;for(let W of this.resolved){let z=new W;if(!z.name){console.error(`Cron job must have a name \u2014 ${W.name||"an anonymous class"} has none, so it is not scheduled. If this is a base class that other jobs extend, move it out of the discovered directory: \`abstract\` does not survive to runtime, so a class under app/cron is indistinguishable from a job.`);continue}if(!z.cron){console.error(`Cron job must have an expression. Job: ${z.name}`);continue}let X=G.get(z.name);if(X!==void 0){console.error(`Two cron jobs claim the name "${z.name}" \u2014 ${X} is scheduled and ${W.name||"an anonymous class"} is not. A name is the scheduler's key, so only one job can hold it. Rename one.`);continue}G.set(z.name,W.name||"an anonymous class"),$.get(z.name)?.stop();let Y=Bun.cron(z.cron,()=>{if(this.stopped)return;let K=this.locks;return this.track(z.name,()=>Z(()=>V9(z,{locks:K})))});$.set(z.name,Y),this.handles.push(Y)}}stop(){this.stopped=!0;for(let Z of this.handles)Z.stop();this.handles=[]}async drain(Z=1/0){this.stop();let $,G=new Promise((W)=>{if(Z!==1/0)$=setTimeout(W,Z)});return await Promise.race([Promise.allSettled([...this.inFlight.values()].map((W)=>W.done)),G]),clearTimeout($),{unfinished:[...this.inFlight.values()].map((W)=>({...W.tick}))}}get running(){return this.inFlight.size}track(Z,$){let G={},W=Promise.resolve().then($).finally(()=>this.inFlight.delete(G));return this.inFlight.set(G,{tick:{name:Z,startedAt:new Date},done:W}),W}}import{isMainThread as J9}from"worker_threads";var F9=100,N9=(Z)=>Math.min(F9,Math.floor(Z/10));class x9 extends J{register(){this.app.singleton(D,()=>new D(this.app.config.get("queue",{}),{application:this.app})),this.app.singleton(k,()=>this.app.make(D).locks)}async boot(){let Z=this.app.config.get("queue",{});if(Z.jobs!==void 0)return;let{jobsDir:$}=_(K3(),Z);this.app.make(D).useJobs(await B3($))}async shutdown(Z){if(!this.app.resolved(D))return;let $=this.app.make(D);if($.running>0)console.log(`[gemi] Shutting down: waiting for ${$.running} running queued job(s).`);let G=Z?.timeoutMs,{unfinished:W}=await $.drain(G===void 0?1/0:Math.max(0,G-N9(G)));if(W.length>0)return console.error("[gemi] Queued jobs still running at shutdown: "+W.map((z)=>`${z.name} (${z.id})`).join(", ")),{abandoned:!0}}}function q$(Z){if(C9(Z),Bun.env.NODE_ENV!=="production")return _9(Z);if(I3(Z))return;if(!U3())return;if(!Z.bound(D))return;Z.make(D).start()}function I3(Z){let $=Z.config.get("queue",{}).driver??"memory";return $==="memory"||$ instanceof H3}function P9(Z){if(I3(Z))return!0;if(typeof Z.config.get("queue",{}).driver!=="function"||!Z.bound(D))return!1;try{return!Z.make(D).durable}catch{return!1}}function C9(Z){let $=process.env.GEMI_QUEUE_CLAIM;if($===void 0||V3())return;if(process.env.ROOT_DIR===void 0||!J9)return;if(Q3()){if(!P9(Z))return;console.warn('[gemi] GEMI_QUEUE_CLAIM=off is ignored: the memory queue driver keeps jobs in the process that dispatched them, so no worker could run them. This server runs its own jobs. Use a driver other processes can read, such as "database", to hand jobs to `gemi queue:work`.')}else if($.trim().toLowerCase()!=="on")console.warn(`[gemi] GEMI_QUEUE_CLAIM="${$}" is not "off" or "on", so this server claims jobs. Set it to "off" to leave them to \`gemi queue:work\`.`)}function _9(Z){let $=globalThis.__gemiDevQueue;if(!$)return;if(globalThis.__gemiDevQueue=void 0,$.stop(),Z.bound(D))Z.make(D).start()}class D9 extends J{register(){this.app.singleton(p,()=>new p(this.app.config.get("changeFeed",{}),{application:this.app}))}async shutdown(){if(!this.app.resolved(p))return;await this.app.make(p).close()}}class A9 extends J{register(){this.app.singleton(AZ,()=>new AZ(this.app.config.get("auth",{}))),this.app.singleton(DZ,()=>{let Z=this.app.config.get("auth",{});return new DZ({providers:Z.connections??{},store:Z.connectionStore??void 0})})}}var L9=100,O9=(Z)=>Math.min(L9,Math.floor(Z/10));class q9 extends J{register(){this.app.singleton(R,()=>new R(_(LZ(),this.app.config.get("schedule",{}))))}async boot(){let Z=this.app.make(R),$=this.app.config.get("schedule",{});if($.jobs===void 0){let{jobsDir:W}=_(LZ(),$);Z.useJobs(await F3(W))}if(process.env.GEMI_NO_SCHEDULE==="1")return;let G=this.app;if(G.bound(k))Z.useLocks(()=>G.make(k));Z.start((W)=>J3.run(G,W))}async shutdown(Z){if(!this.app.resolved(R))return;let $=this.app.make(R);if($.running>0)console.log(`[gemi] Shutting down: waiting for ${$.running} running cron tick(s).`);let G=Z?.timeoutMs,{unfinished:W}=await $.drain(G===void 0?1/0:Math.max(0,G-O9(G)));if(W.length>0)return console.error("[gemi] Cron jobs still running at shutdown: "+W.map((z)=>`${z.name} (started ${z.startedAt.toISOString()})`).join(", ")),{abandoned:!0}}}class h extends x3{modelName;constructor(Z="FeatureFlag"){super();this.modelName=Z}get available(){return N3(this.modelName)}async load(){if(!this.available)throw new qZ(this.modelName);let Z=OZ(this.modelName);return await Z.asSystem(()=>Z.findMany())}async write(Z,$,G){if(!this.available)throw new qZ(this.modelName);let W=OZ(this.modelName),z=this.hasActorColumn(W),X={active:$};if(z)X.updatedBy=G.actor;return await W.asSystem(()=>W.upsert({where:{key:Z},create:{key:Z,...X},update:X})),{actorRecorded:z}}hasActorColumn(Z){let $=Z?.$schema?.fields?.updatedBy;return $!==void 0&&$.type==="String"}}function l$(Z){return Z}function P3(){return{features:void 0,enabled:!0,source:new h,model:"FeatureFlag",ttl:30,context:void 0,onEvaluate:void 0,maxClientFlags:200}}class T9 extends J{register(){this.app.singleton(r,()=>{let Z=this.app.config.get("features",{}),$=_(P3(),Z);if(Z?.model!==void 0&&Z?.source===void 0)$.source=new h(Z.model);else if(Z?.model!==void 0&&Z.source instanceof h&&Z.source.modelName!==Z.model)a.warning(`app/config/features.ts sets \`model: "${Z.model}"\` and a source reading "${Z.source.modelName}". The source wins; drop \`model\` to silence this.`);return new r($,(G)=>a.warning(G))})}async boot(){let Z=this.app.make(r);if(!Z.config.enabled)return;try{await Z.refresh()}catch($){a.error(`Could not warm the feature flag cache at boot. ${$ instanceof Error?$.message:String($)}`)}}}class S9 extends J{register(){this.app.singleton(TZ,()=>new TZ(this.app.config.get("mail",{})))}}class j9 extends J{register(){this.app.singleton(e,()=>new e(this.app.config.get("encryption",{})))}boot(){if(this.app.make(e).configured)return;let $=this.app.config.get("auth",{}),G=Object.keys($?.connections??{});if(G.length>0&&!$?.connectionStore)throw new SZ(`auth.connections (${G.join(", ")}) keeps OAuth tokens encrypted, but no encryption key is configured. Add app/config/encryption.ts (defineEncryptionConfig({ keys: { k1: process.env.APP_ENCRYPTION_KEY } })) and list it as \`encryption\` in your Kernel's config. Generate a key with \`openssl rand -base64 32\`.`);let W=C3();if(W.length===0)return;throw new SZ(`${W.join(", ")} ${W.length===1?"is an encrypted column":"are encrypted columns"}, but no encryption key is configured. Add app/config/encryption.ts (defineEncryptionConfig({ keys: { k1: process.env.APP_ENCRYPTION_KEY } })) and list it as \`encryption\` in your Kernel's config. Generate a key with \`openssl rand -base64 32\`.`)}}function M9(Z){return`listener:${Z}`}function D3(Z,$){k9(Z);let{maxAttempts:G,backoff:W,worker:z}=$,X=Z.event.name,Y=class extends _3{maxAttempts=G;backoff=W;worker=z;async run(...K){let[U,H]=R9(K),Q=g(w).rehydrate(U,H);await new Z().handle(Q)}onFail(K){console.error(`The listener ${Z.name} threw while handling ${X} off the queue. The queue will retry it up to ${G} times in total; nothing the dispatcher did is waiting on it.`,K)}onDeadletter(K){console.error(`The listener ${Z.name} failed every one of its ${G} attempts at ${X} and has been dead-lettered, so this side effect did not happen and will not be retried.`,K)}};return Object.defineProperty(Y,"name",{value:M9(Z.name),writable:!0}),Y}function k9(Z){if(Object.getOwnPropertyDescriptor(Z,"name")?.writable)return;throw Error(`The listener ${Z.name} sets \`queued = true\` but does not declare \`static name\`, so it would be registered with the queue `+"under its class name \u2014 which a production build renames while the "+`payload that names it does not. Add: static name = "${Z.name}";`)}function R9(Z){return typeof Z[0]==="string"?Z:Z[0]}class w{static token="events";listeners={};events={};warnedFor=new Set;warnedAboutWaiting=new Set;config;constructor(Z={}){this.config=_(ZZ(),Z),this.useListeners(this.config.listeners)}useListeners(Z){this.config.listeners=Z,this.listeners={},this.events={};let $=new Set;for(let G of Z){if(!G.event){console.error(`Listener ${G.name} does not declare \`static event\`, so there is no event name to register it under and its handle will never run. Add: static event = SomeEvent;`);continue}if($.has(G.name)){console.error(`Two event listeners are named "${G.name}" \u2014 the first is `+"registered and this one is not. A listener's name identifies it across the framework, so only one class can hold it. Rename one.");continue}$.add(G.name);let W=G.event.name,z=new G;this.events[W]??=G.event,(this.listeners[W]??=[]).push({listener:G,job:z.queued?D3(G,z):null})}}get queuedListenerJobs(){return Object.values(this.listeners).flat().flatMap(({job:Z})=>Z?[Z]:[])}get registeredListeners(){return[...this.config.listeners]}dispatch(Z,$){if(this.deferToCommit(Z,$,!1))return;this.runListeners(Z,$)}async dispatchAndWait(Z,$){if(this.deferToCommit(Z,$,!0))return;return this.runListeners(Z,$)}deferToCommit(Z,$,G){let{name:W,afterCommit:z}=Z.constructor;if(!z)return!1;let X=A3(()=>this.runListeners(Z,$));if(X&&G)this.warnNothingIsWaitedFor(W);return X}async runListeners(Z,$){let G=Z.constructor.name,W=this.listeners[G];if(!W?.length){this.warnNothingIsListening(G);return}for(let{listener:z,job:X}of W){if(X){this.enqueue(X,z,G,$);continue}try{await new z().handle(Z)}catch(Y){console.error(`The listener ${z.name} threw while handling ${G}. The `+"listeners after it still ran \u2014 a listener's failure is its own.",Y)}}}rehydrate(Z,$=[]){let G=this.events[Z];if(!G)throw Error(`Cannot rebuild the event "${Z}" that came off the queue: no registered listener binds to an event of that name, so there is no class to construct. A queued listener runs in an application that `+"discovered its own listeners \u2014 check that this process sees the "+`same app/listeners as the one that dispatched, and that the event declares \`static name = "${Z}"\`.`);return new G(...$)}enqueue(Z,$,G,W){if(W===void 0){console.error(`The listener ${$.name} is queued, but ${G} reached the dispatcher without its constructor arguments, so there is nothing for the queue to rebuild it from and the listener was skipped. Dispatch through ${G}.dispatch(...) or ${G}.dispatchAndWait(...), which carry them.`);return}let z=(X)=>console.error(`The listener ${$.name} could not be queued for ${G}, so it did not run and will not be retried. The listeners after it still ran.`,X);try{g(D).push(Z,JSON.stringify([G,W]),{reportFailure:!1}).catch(z)}catch(X){z(X)}}warnNothingIsWaitedFor(Z){if(Bun.env.NODE_ENV==="production")return;if(this.warnedAboutWaiting.has(Z))return;this.warnedAboutWaiting.add(Z),console.warn(`[gemi] ${Z}.dispatchAndWait() was called inside a transaction and ${Z} declares \`static afterCommit = true\`, so it resolved `+"immediately with no listener having run \u2014 they run when the "+"transaction commits. Await the transaction instead, or drop afterCommit if the caller needs the side effects first. Development only.")}warnNothingIsListening(Z){if(Bun.env.NODE_ENV==="production")return;if(this.warnedFor.has(Z))return;this.warnedFor.add(Z),console.warn(`[gemi] ${Z} was dispatched and nothing is listening for it. A listener registers under the name its event declares, so check that app/listeners holds a Listener with \`static event = ${Z}\` and that ${Z} declares \`static name = "${Z}"\`. Development only.`)}}class w9 extends J{register(){this.app.singleton(w,()=>new w(this.app.config.get("events",{})))}async boot(){let Z=this.app.make(w),$=this.app.config.get("events",{});if($.listeners===void 0){let{listenersDir:z}=_(ZZ(),$);Z.useListeners(await L3(z))}let G=Z.queuedListenerJobs;if(G.length===0)return;let W=this.app.make(D);for(let z of G)W.registerJob(z)}}class E9 extends J{register(){this.app.singleton(jZ,()=>new jZ(this.app.config.get("filesystem",{})))}}class b9 extends J{register(){this.app.singleton(MZ,()=>new MZ(this.app.config.get("image",{})))}}class f9 extends J{register(){this.app.instance(kZ,new kZ)}}function y2(Z){return Z}function O3(){return{maxFileSize:10485760,onLogFileClosed:()=>{},onLogCreated:()=>{}}}class y9 extends J{register(){this.app.singleton($Z,()=>new $Z(_(O3(),this.app.config.get("log",{}))))}async boot(){if(!process.env.ROOT_DIR)return;await this.app.make($Z).boot()}}class v9 extends J{register(){this.app.singleton(GZ,()=>new GZ(_(q3(),this.app.config.get("middleware",{}))))}boot(){this.app.make(GZ).assertGlobalMiddleware()}}function s2(Z){return Z}function S3(){return{driver:new T3,limit:1000,window:60}}class g9 extends J{register(){this.app.singleton(v,()=>new v(_(S3(),this.app.config.get("ratelimiter",{}))))}}function G6(Z){return Z}function j3(){return{url:process.env.REDIS_URL,options:void 0}}class h9 extends J{register(){this.app.singleton(i,()=>new i(_(j3(),this.app.config.get("redis",{}))))}shutdown(){if(!this.app.resolved(i))return;this.app.make(i).close()}}function WZ(Z,$){let G=Z.get($);if(!G)throw Error(`Missing "${$}" configuration. Route dispatching needs a root router \u2014 declare it in "app/config/route.ts".`);return G}class m9 extends J{register(){this.app.singleton(m,()=>new m(WZ(this.app.config,"route.api"))),this.app.singleton(l,()=>new l(WZ(this.app.config,"route.view"))),this.app.singleton(zZ,()=>new zZ({api:this.app.make(m),view:this.app.make(l)},{api:WZ(this.app.config,"route.api"),view:WZ(this.app.config,"route.view"),domains:this.app.config.get("route.domains")})),this.app.singleton(y,()=>{let Z=this.app.config.get("route.mcp");if(!Z?.router)throw Error('No MCP router is configured. Declare one as `mcp: { router }` in "app/config/route.ts".');return new y(new Z.router,this.app.make(m),{files:Z.remote?.files})}),this.registerMcpHttp()}registerMcpHttp(){this.app.singleton(c,()=>{let Z=this.app.config.get("route.mcp");if(!Z?.remote?.enabled)throw Error("The MCP endpoint is not enabled: set route.mcp.remote.enabled.");return new c(this.app.make(y),Z.remote)})}boot(){if(this.app.make(m),this.app.make(l),this.app.make(zZ),this.app.config.get("route.mcp"))this.app.make(y);let Z=this.app.config.get("route.mcp.remote");if(Z?.enabled===!0)this.app.make(c);else if(Z?.enabled!==void 0&&Z.enabled!==!1)throw Error("route.mcp.remote.enabled must be true or false.")}}
|
|
8
|
+
export{k3 as ib,L as jb,d as kb,y as lb,KZ as mb,a3 as nb,HZ as ob,FZ as pb,NZ as qb,c as rb,R as sb,x9 as tb,q$ as ub,D9 as vb,A9 as wb,q9 as xb,h as yb,l$ as zb,P3 as Ab,T9 as Bb,S9 as Cb,j9 as Db,w as Eb,w9 as Fb,E9 as Gb,b9 as Hb,f9 as Ib,y2 as Jb,O3 as Kb,y9 as Lb,v9 as Mb,s2 as Nb,S3 as Ob,g9 as Pb,G6 as Qb,j3 as Rb,h9 as Sb,m9 as Tb};
|
|
9
|
+
|
|
10
|
+
//# debugId=AB2BC57546C7A4A264756E2164756E21
|