gemi 0.226.0 → 0.228.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/AgentController.d.ts +1 -1
- package/dist/ai/index.js +2 -2
- package/dist/ai/index.js.map +2 -2
- package/dist/ai/providers/http.d.ts.map +1 -1
- package/dist/ai/providers/live.d.ts +23 -0
- package/dist/ai/providers/live.d.ts.map +1 -0
- package/dist/ai/providers/sideband.d.ts.map +1 -1
- package/dist/ai/testing/index.js +2 -2
- package/dist/ai/testing/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-k4v5e6ww.js → chunk-0dp6jvrg.js} +2 -2
- package/dist/{chunk-k4v5e6ww.js.map → chunk-0dp6jvrg.js.map} +1 -1
- package/dist/{chunk-se6ktpm5.js → chunk-0zakpsep.js} +3 -3
- package/dist/{chunk-se6ktpm5.js.map → chunk-0zakpsep.js.map} +1 -1
- package/dist/{chunk-5yxyd1vb.js → chunk-0zf4dy4y.js} +2 -2
- package/dist/{chunk-5yxyd1vb.js.map → chunk-0zf4dy4y.js.map} +1 -1
- package/dist/{chunk-q67c5zyw.js → chunk-11yrxwkt.js} +2 -2
- package/dist/{chunk-q67c5zyw.js.map → chunk-11yrxwkt.js.map} +1 -1
- package/dist/{chunk-p7s80mhn.js → chunk-1v1ek1ey.js} +2 -2
- package/dist/{chunk-p7s80mhn.js.map → chunk-1v1ek1ey.js.map} +1 -1
- package/dist/{chunk-f1pyzfw0.js → chunk-30jcs49q.js} +2 -2
- package/dist/{chunk-f1pyzfw0.js.map → chunk-30jcs49q.js.map} +1 -1
- package/dist/{chunk-w7511nk3.js → chunk-30zs008n.js} +3 -3
- package/dist/{chunk-w7511nk3.js.map → chunk-30zs008n.js.map} +1 -1
- package/dist/{chunk-bv9kqnj1.js → chunk-3q0sbk92.js} +2 -2
- package/dist/{chunk-bv9kqnj1.js.map → chunk-3q0sbk92.js.map} +1 -1
- package/dist/{chunk-ppx8p2g0.js → chunk-3v8b2kdr.js} +1 -1
- package/dist/{chunk-axjw9g4s.js → chunk-5p0gbwq1.js} +3 -3
- package/dist/{chunk-axjw9g4s.js.map → chunk-5p0gbwq1.js.map} +1 -1
- package/dist/{chunk-t956xcy4.js → chunk-5sgwnrr8.js} +2 -2
- package/dist/{chunk-t956xcy4.js.map → chunk-5sgwnrr8.js.map} +1 -1
- package/dist/{chunk-53hg89g5.js → chunk-65wnm25z.js} +4 -4
- package/dist/{chunk-53hg89g5.js.map → chunk-65wnm25z.js.map} +1 -1
- package/dist/{chunk-vre98hts.js → chunk-69q9tk74.js} +2 -2
- package/dist/{chunk-vre98hts.js.map → chunk-69q9tk74.js.map} +1 -1
- package/dist/{chunk-yg7sra7w.js → chunk-6fpjc2eg.js} +3 -3
- package/dist/{chunk-yg7sra7w.js.map → chunk-6fpjc2eg.js.map} +1 -1
- package/dist/{chunk-mdby3yea.js → chunk-6xt7w9bb.js} +3 -3
- package/dist/{chunk-mdby3yea.js.map → chunk-6xt7w9bb.js.map} +1 -1
- package/dist/{chunk-qmezsfxd.js → chunk-76sp9knq.js} +2 -2
- package/dist/{chunk-qmezsfxd.js.map → chunk-76sp9knq.js.map} +1 -1
- package/dist/{chunk-07rrezpq.js → chunk-7ka1abkd.js} +2 -2
- package/dist/{chunk-07rrezpq.js.map → chunk-7ka1abkd.js.map} +1 -1
- package/dist/{chunk-zq4jbwvn.js → chunk-7vkqcrfn.js} +2 -2
- package/dist/{chunk-zq4jbwvn.js.map → chunk-7vkqcrfn.js.map} +1 -1
- package/dist/{chunk-0anqpm98.js → chunk-7y2g8wbb.js} +2 -2
- package/dist/{chunk-0anqpm98.js.map → chunk-7y2g8wbb.js.map} +1 -1
- package/dist/{chunk-f3jf9bk8.js → chunk-8hr7z8cc.js} +3 -3
- package/dist/{chunk-f3jf9bk8.js.map → chunk-8hr7z8cc.js.map} +1 -1
- package/dist/{chunk-dvsafvww.js → chunk-8q1n4087.js} +2 -2
- package/dist/{chunk-dvsafvww.js.map → chunk-8q1n4087.js.map} +1 -1
- package/dist/{chunk-fhe8c8zy.js → chunk-9bjggtdt.js} +2 -2
- package/dist/{chunk-fhe8c8zy.js.map → chunk-9bjggtdt.js.map} +1 -1
- package/dist/{chunk-ydgtkgf9.js → chunk-9jz5ts7h.js} +2 -2
- package/dist/{chunk-ydgtkgf9.js.map → chunk-9jz5ts7h.js.map} +1 -1
- package/dist/{chunk-2jx1r4m7.js → chunk-agc0e46c.js} +2 -2
- package/dist/{chunk-2jx1r4m7.js.map → chunk-agc0e46c.js.map} +1 -1
- package/dist/{chunk-77pms0y3.js → chunk-b9gwjs4r.js} +2 -2
- package/dist/{chunk-77pms0y3.js.map → chunk-b9gwjs4r.js.map} +1 -1
- package/dist/{chunk-w6j7q0dc.js → chunk-bm4hjbbk.js} +2 -2
- package/dist/{chunk-w6j7q0dc.js.map → chunk-bm4hjbbk.js.map} +1 -1
- package/dist/{chunk-ztpenack.js → chunk-bs8bq053.js} +2 -2
- package/dist/{chunk-ztpenack.js.map → chunk-bs8bq053.js.map} +1 -1
- package/dist/{chunk-hqxbxk1f.js → chunk-c3jg93sn.js} +2 -2
- package/dist/{chunk-hqxbxk1f.js.map → chunk-c3jg93sn.js.map} +1 -1
- package/dist/{chunk-acsyr6wq.js → chunk-c5kd7eac.js} +3 -3
- package/dist/{chunk-acsyr6wq.js.map → chunk-c5kd7eac.js.map} +1 -1
- package/dist/{chunk-n1dcwz8z.js → chunk-ct8eh241.js} +2 -2
- package/dist/{chunk-n1dcwz8z.js.map → chunk-ct8eh241.js.map} +1 -1
- package/dist/{chunk-5zbqh32n.js → chunk-djhr379j.js} +2 -2
- package/dist/{chunk-5zbqh32n.js.map → chunk-djhr379j.js.map} +1 -1
- package/dist/{chunk-8s8bjrjp.js → chunk-dpn78sq7.js} +2 -2
- package/dist/{chunk-8s8bjrjp.js.map → chunk-dpn78sq7.js.map} +1 -1
- package/dist/{chunk-pdxmd8bd.js → chunk-dqb257xv.js} +2 -2
- package/dist/{chunk-pdxmd8bd.js.map → chunk-dqb257xv.js.map} +1 -1
- package/dist/{chunk-xg2ctnwf.js → chunk-e30saw5t.js} +2 -2
- package/dist/{chunk-xg2ctnwf.js.map → chunk-e30saw5t.js.map} +1 -1
- package/dist/{chunk-q26d0qa3.js → chunk-efnerp0c.js} +2 -2
- package/dist/{chunk-q26d0qa3.js.map → chunk-efnerp0c.js.map} +1 -1
- package/dist/{chunk-6n3wadx7.js → chunk-ejvamy3q.js} +1 -1
- package/dist/{chunk-1p82h0y2.js → chunk-g0mxdh2x.js} +2 -2
- package/dist/{chunk-1p82h0y2.js.map → chunk-g0mxdh2x.js.map} +1 -1
- package/dist/{chunk-rk3xgyd0.js → chunk-g0t49jec.js} +1 -1
- package/dist/{chunk-58gyj15y.js → chunk-gd4qydsx.js} +3 -3
- package/dist/{chunk-58gyj15y.js.map → chunk-gd4qydsx.js.map} +1 -1
- package/dist/chunk-hddxvnh7.js +10 -0
- package/dist/{chunk-9kcjxtqg.js.map → chunk-hddxvnh7.js.map} +5 -5
- package/dist/{chunk-jm4908xm.js → chunk-hhpme9te.js} +2 -2
- package/dist/{chunk-jm4908xm.js.map → chunk-hhpme9te.js.map} +1 -1
- package/dist/{chunk-atn9z9hx.js → chunk-j5fh6pjs.js} +2 -2
- package/dist/{chunk-atn9z9hx.js.map → chunk-j5fh6pjs.js.map} +1 -1
- package/dist/{chunk-kn2hk1n3.js → chunk-j7swq19b.js} +1 -1
- package/dist/{chunk-26ngc9ed.js → chunk-jkhtybga.js} +3 -3
- package/dist/{chunk-26ngc9ed.js.map → chunk-jkhtybga.js.map} +1 -1
- package/dist/{chunk-mzmv1zmn.js → chunk-jqqyj6cr.js} +2 -2
- package/dist/{chunk-mzmv1zmn.js.map → chunk-jqqyj6cr.js.map} +1 -1
- package/dist/{chunk-grxz4ecb.js → chunk-jrvqya5h.js} +2 -2
- package/dist/{chunk-grxz4ecb.js.map → chunk-jrvqya5h.js.map} +1 -1
- package/dist/{chunk-r8zp4khs.js → chunk-keqjdy8q.js} +2 -2
- package/dist/{chunk-r8zp4khs.js.map → chunk-keqjdy8q.js.map} +1 -1
- package/dist/{chunk-mmns1ske.js → chunk-kfcz4qa8.js} +2 -2
- package/dist/{chunk-mmns1ske.js.map → chunk-kfcz4qa8.js.map} +1 -1
- package/dist/{chunk-eb03m143.js → chunk-kspqqyv1.js} +2 -2
- package/dist/{chunk-eb03m143.js.map → chunk-kspqqyv1.js.map} +1 -1
- package/dist/{chunk-vd8a3g3n.js → chunk-kx5gycdv.js} +2 -2
- package/dist/{chunk-vd8a3g3n.js.map → chunk-kx5gycdv.js.map} +1 -1
- package/dist/{chunk-jy26hy7z.js → chunk-m4wagwhr.js} +2 -2
- package/dist/{chunk-jy26hy7z.js.map → chunk-m4wagwhr.js.map} +1 -1
- package/dist/{chunk-v1d1xc2r.js → chunk-mcgcgm6g.js} +1 -1
- package/dist/{chunk-72k87qz8.js → chunk-mg9j9r9f.js} +2 -2
- package/dist/{chunk-72k87qz8.js.map → chunk-mg9j9r9f.js.map} +1 -1
- package/dist/{chunk-h4179pzx.js → chunk-mgvrfhy8.js} +3 -3
- package/dist/{chunk-h4179pzx.js.map → chunk-mgvrfhy8.js.map} +1 -1
- package/dist/{chunk-6e12tbqc.js → chunk-ngbrbeg2.js} +3 -3
- package/dist/{chunk-6e12tbqc.js.map → chunk-ngbrbeg2.js.map} +1 -1
- package/dist/{chunk-jkftpj8g.js → chunk-ph7cjs7e.js} +2 -2
- package/dist/{chunk-jkftpj8g.js.map → chunk-ph7cjs7e.js.map} +1 -1
- package/dist/{chunk-q902m8c6.js → chunk-q78n7dvm.js} +2 -2
- package/dist/{chunk-q902m8c6.js.map → chunk-q78n7dvm.js.map} +1 -1
- package/dist/{chunk-n6rf9tnb.js → chunk-qgka1mvf.js} +3 -3
- package/dist/{chunk-n6rf9tnb.js.map → chunk-qgka1mvf.js.map} +1 -1
- package/dist/{chunk-mcntwhp7.js → chunk-qqe19gtm.js} +3 -3
- package/dist/{chunk-mcntwhp7.js.map → chunk-qqe19gtm.js.map} +1 -1
- package/dist/chunk-rqzpxeb5.js +5 -0
- package/dist/{chunk-9rkjhnx2.js.map → chunk-rqzpxeb5.js.map} +1 -1
- package/dist/{chunk-bpfc31b9.js → chunk-tegjs0gg.js} +1 -1
- package/dist/{chunk-ay5raj98.js → chunk-vjqpcet2.js} +3 -3
- package/dist/{chunk-ay5raj98.js.map → chunk-vjqpcet2.js.map} +1 -1
- package/dist/{chunk-szx9z0zm.js → chunk-vnpfdr52.js} +2 -2
- package/dist/{chunk-szx9z0zm.js.map → chunk-vnpfdr52.js.map} +1 -1
- package/dist/{chunk-5tf6nm65.js → chunk-vrtt8nvm.js} +2 -2
- package/dist/{chunk-5tf6nm65.js.map → chunk-vrtt8nvm.js.map} +1 -1
- package/dist/{chunk-2xzf4nqq.js → chunk-vsh9jck0.js} +26 -26
- package/dist/{chunk-2xzf4nqq.js.map → chunk-vsh9jck0.js.map} +5 -5
- package/dist/{chunk-a95pp5kn.js → chunk-wedj46ec.js} +2 -2
- package/dist/{chunk-a95pp5kn.js.map → chunk-wedj46ec.js.map} +1 -1
- package/dist/{chunk-nfmsyjf4.js → chunk-wgxkr2jx.js} +2 -2
- package/dist/{chunk-nfmsyjf4.js.map → chunk-wgxkr2jx.js.map} +1 -1
- package/dist/{chunk-gae8a3jk.js → chunk-wyb6k943.js} +4 -4
- package/dist/{chunk-gae8a3jk.js.map → chunk-wyb6k943.js.map} +2 -2
- package/dist/{chunk-ngk1tka6.js → chunk-x1p31k7q.js} +2 -2
- package/dist/{chunk-ngk1tka6.js.map → chunk-x1p31k7q.js.map} +1 -1
- package/dist/{chunk-dp2xrc54.js → chunk-x8by5j7p.js} +2 -2
- package/dist/{chunk-dp2xrc54.js.map → chunk-x8by5j7p.js.map} +1 -1
- package/dist/{chunk-42mm1g89.js → chunk-xd4kvswv.js} +2 -2
- package/dist/{chunk-42mm1g89.js.map → chunk-xd4kvswv.js.map} +1 -1
- package/dist/{chunk-4m7srgh5.js → chunk-xkrfxcm7.js} +2 -2
- package/dist/{chunk-4m7srgh5.js.map → chunk-xkrfxcm7.js.map} +1 -1
- package/dist/{chunk-vf4tn1yd.js → chunk-xmrd9460.js} +2 -2
- package/dist/{chunk-vf4tn1yd.js.map → chunk-xmrd9460.js.map} +1 -1
- package/dist/{chunk-e1qssbfa.js → chunk-xprhym1t.js} +2 -2
- package/dist/{chunk-e1qssbfa.js.map → chunk-xprhym1t.js.map} +1 -1
- package/dist/{chunk-8xta8133.js → chunk-xv46emqt.js} +2 -2
- package/dist/{chunk-8xta8133.js.map → chunk-xv46emqt.js.map} +1 -1
- package/dist/chunk-z0s09je5.js +12 -0
- package/dist/{chunk-jg94sqmx.js.map → chunk-z0s09je5.js.map} +6 -5
- package/dist/{chunk-603twf6k.js → chunk-z6zvemqa.js} +2 -2
- package/dist/{chunk-603twf6k.js.map → chunk-z6zvemqa.js.map} +1 -1
- package/dist/{chunk-jc5nbacx.js → chunk-znh1mbqs.js} +2 -2
- package/dist/{chunk-jc5nbacx.js.map → chunk-znh1mbqs.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/RateLimitMiddleware.d.ts +23 -6
- package/dist/http/RateLimitMiddleware.d.ts.map +1 -1
- package/dist/http/clientAddress.d.ts +13 -0
- package/dist/http/clientAddress.d.ts.map +1 -1
- package/dist/http/index.d.ts +1 -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/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/cron/ScheduleServiceProvider.d.ts.map +1 -1
- package/dist/services/index.js +2 -2
- package/dist/services/index.js.map +3 -3
- package/dist/services/queue/work.js +2 -2
- package/dist/services/queue/work.js.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-9kcjxtqg.js +0 -10
- package/dist/chunk-9rkjhnx2.js +0 -5
- package/dist/chunk-jg94sqmx.js +0 -12
- /package/dist/{chunk-ppx8p2g0.js.map → chunk-3v8b2kdr.js.map} +0 -0
- /package/dist/{chunk-6n3wadx7.js.map → chunk-ejvamy3q.js.map} +0 -0
- /package/dist/{chunk-rk3xgyd0.js.map → chunk-g0t49jec.js.map} +0 -0
- /package/dist/{chunk-kn2hk1n3.js.map → chunk-j7swq19b.js.map} +0 -0
- /package/dist/{chunk-v1d1xc2r.js.map → chunk-mcgcgm6g.js.map} +0 -0
- /package/dist/{chunk-bpfc31b9.js.map → chunk-tegjs0gg.js.map} +0 -0
|
@@ -1232,7 +1232,7 @@ Body extends object = Record<string, unknown>> extends ControllerBase {
|
|
|
1232
1232
|
* nothing sound to count it under: a client address is the proxy's unless
|
|
1233
1233
|
* `GEMI_TRUST_PROXY` is set, which would put every visitor in one bucket, and
|
|
1234
1234
|
* the session cookie is the visitor's to drop. An app that serves anonymous
|
|
1235
|
-
* chats returns its own key here (`ip:${
|
|
1235
|
+
* chats returns its own key here (`ip:${clientAddress(req)}` behind a trusted
|
|
1236
1236
|
* proxy, say), sets `requireThread`, or puts `RateLimitMiddleware` on the
|
|
1237
1237
|
* route.
|
|
1238
1238
|
*/
|
package/dist/ai/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{ca as aQ,da as JZ,ea as $Z,fa as d6,ga as n6,ha as o6,ia as r$,ja as s6,ka as a6,la as _$,ma as t6,na as r6,oa as e6,pa as J0}from"../chunk-
|
|
2
|
+
import{ca as aQ,da as JZ,ea as $Z,fa as d6,ga as n6,ha as o6,ia as r$,ja as s6,ka as a6,la as _$,ma as t6,na as r6,oa as e6,pa as J0}from"../chunk-z0s09je5.js";import{$c as I6,Ac as xZ,Bc as OQ,Dc as _Q,Ec as RQ,Fc as MQ,Gc as SQ,Hc as AQ,Ic as EQ,Jc as kQ,Kc as TQ,Lc as jQ,Mc as xQ,Nc as wQ,Oc as IQ,Qc as t$,Rc as M6,Sc as S6,Tc as A6,Uc as R6,Vc as E6,Wc as k6,Xc as T6,Yc as j6,Zc as x6,_c as w6,ad as NJ,bd as f6,cd as O8,dd as q6,ed as _8,fd as b6,gd as v6,hd as y6,ic as o$,id as fJ,jc as z8,jd as D$,kc as Y8,kd as h6,lc as s$,ld as g6,md as L8,nd as c6,od as u6,pc as sQ,pd as m6,qc as pQ,qd as p6,rc as YJ,rd as l6,sc as B6,sd as B8,tc as h,td as i6,uc as FQ,ud as z$,vc as UQ,xc as CQ,yc as m,zc as jZ}from"../chunk-9jz5ts7h.js";import{Ad as j,Hd as i,Id as a$,Ld as D8,Md as H8,Nd as P8,Od as mJ,Pd as N8,Qd as oJ,Rd as pJ,Sd as u$,Td as F8,Ud as U8,Vd as sJ,Wd as C8,ae as QJ,ce as $J,yd as ZZ,zd as R}from"../chunk-kx5gycdv.js";import{te as zQ}from"../chunk-a2y481gh.js";import"../chunk-xv46emqt.js";import{Ri as f,pi as Q8,si as W8,xj as X8,yj as T$}from"../chunk-vjqpcet2.js";import{Bj as dJ,Cj as nJ,zj as Z8}from"../chunk-jqqyj6cr.js";import{Fj as O6,Gj as _6,Hj as L6}from"../chunk-30zs008n.js";import{Uj as l}from"../chunk-m4wagwhr.js";import"../chunk-9bjggtdt.js";import{$k as K8,al as G8,bl as V8,cl as c$}from"../chunk-0zakpsep.js";import"../chunk-djhr379j.js";import{il as e,jl as JJ,yl as xJ}from"../chunk-qgka1mvf.js";import"../chunk-znh1mbqs.js";import"../chunk-7ka1abkd.js";import{pm as CZ}from"../chunk-6fpjc2eg.js";import"../chunk-dqb257xv.js";import"../chunk-0dp6jvrg.js";import{Mm as eJ}from"../chunk-x8by5j7p.js";import"../chunk-30jcs49q.js";import{existsSync as w8,readdirSync as Q0,readFileSync as KQ}from"fs";import{isAbsolute as I8,join as AJ,relative as f8,sep as q8}from"path";var GQ="prompts.json",b8=/\{\{>\s*([\w./-]+)\s*\}\}/g,ZQ=/\{\{(\w+)\}\}/g,v8=/^[\w-]+(\/[\w-]+)*$/,WQ={dir:"app/agents",shared:"prompts"},EJ={},tJ=new Map,RJ;function y8(){if(RJ===void 0){let J=AJ(eJ(),"dist","server",GQ);RJ=w8(J)?JSON.parse(KQ(J,"utf8")):null}return RJ??null}function h8(J){return J.replace(/\r?\n$/,"")}function XQ(){return EJ.cache??Bun.env.NODE_ENV==="production"}function g8(J,$){if(!v8.test(J))throw Error(`"${J}" is not a prompt name. Use letters, digits, "-" and "_", with "/" between folders.`);let Q=$.dir??EJ.dir??WQ.dir,Z=I8(Q)?Q:AJ(process.cwd(),Q),W=J.includes("/")?`${J}.md`:AJ($.shared??EJ.shared??WQ.shared,`${J}.md`);return AJ(Z,W)}function c8(J,$){let Q=g8(J,$),Z=XQ()?tJ.get(Q):void 0;if(Z!==void 0)return Z;let W=Bun.env.NODE_ENV==="production";if(W){let K=y8()?.[f8(eJ(),Q).split(q8).join("/")];if(K!==void 0)return K}let X;try{X=h8(KQ(Q,"utf8"))}catch(K){if(K.code==="ENOENT"){let G=W?` or in dist/server/${GQ}`:"";throw Error(`The prompt "${J}" does not exist (looked for ${Q}${G}).`)}throw K}if(XQ())tJ.set(Q,X);return X}function rJ(J,$,Q){if($.includes(J))throw Error(`The prompt "${J}" includes itself: ${[...$,J].join(" > ")}.`);return c8(J,Q).replace(b8,(Z,W)=>rJ(W,[...$,J],Q))}class VQ{static configure(J){EJ={...J},tJ.clear(),RJ=void 0}static render(J,$={},Q={}){return rJ(J,[],Q).replace(ZQ,(Z,W)=>{if(!Object.hasOwn($,W))throw Error(`The prompt "${J}" has no value for {{${W}}}.`);return String($[W])})}static placeholders(J,$={}){let Q=[...rJ(J,[],$).matchAll(ZQ)].map((Z)=>Z[1]);return[...new Set(Q)]}}class J$ extends zQ{name="AgentJobDeadlineSweep";cron="* * * * *";async callback(){while(await m.sweep({limit:100})===100);}}var TJ=20,u8=300,m8=200;function DQ(J,$){if($<=0||J.length===0)return null;let Q=(X,K)=>K.createdAt-X.createdAt||(X.id<K.id?1:-1);return["<jobs>","Background jobs that tools started in this conversation, running ones first. A running job's result replaces its tool result when it finishes. Do not start the same work again while a job for it is running.",...[...J.filter((X)=>!h(X.state)).sort(Q),...J.filter((X)=>h(X.state)).sort(Q)].slice(0,$).map((X)=>{let K=[`- ${X.id} (${X.toolName})`];if(X.state==="waiting")K.push(`waiting for ${(X.after??[]).join(", ")} since ${kJ(X.createdAt)}`);else if(X.state==="running")K.push(`running since ${kJ(X.createdAt)}`);else if(X.state==="ok")K.push(`finished at ${kJ(X.settledAt??X.updatedAt)}`);else{let G=X.error?`${X.error.code}: ${YQ(X.error.message,m8)}`:"failed";K.push(`failed at ${kJ(X.settledAt??X.updatedAt)} (${G})`)}if(X.summary!==void 0)K.push(`summary: ${YQ(JSON.stringify(X.summary),u8)}`);if(X.orphaned)K.push("its tool call was lost when the turn that started it was cut short");return K.join("; ")}),"</jobs>"].join(`
|
|
3
3
|
`)}function kJ(J){return new Date(J).toISOString().replace(/\.\d{3}Z$/,"Z")}function YQ(J,$){return J.length<=$?J:`${J.slice(0,$-1)}\u2026`}var HQ=["after_jobs","batch_key","queued","inbox","job_checkpoint"],PQ=20;class $${table;sql;dialect;connection;later;constructor(J,$={}){let Q=$.table??"gemi_agent_jobs";if(!/^[A-Za-z_][A-Za-z0-9_]*$/.test(Q))throw Error(`The agent jobs table name "${Q}" is not a plain identifier. Use letters, digits and underscores.`);this.table=Q,this.sql=J.sql,this.dialect=J.dialect,this.connection=J.name}async createTable(){for(let J of p8(this.dialect,this.table))await this.sql.unsafe(J)}async transaction(J){if(this.connection===void 0||this.joinable())return J();return xJ(this.sql,()=>J(),{connection:this.connection})}async create(J){let $=J.after!==void 0||J.batch!==void 0||J.queued!==void 0;if($)await this.requireLaterColumns("A job with `after` or `batch`");let Q=this.q(),Z=this.clock(Q),W=J.state??"running";if($)await Q`
|
|
4
4
|
INSERT INTO ${this.name(Q)}
|
|
5
5
|
(id, thread_id, run_id, tool_call_id, tool_name, owner, job, summary, state,
|
|
@@ -335,4 +335,4 @@ return 0`;class x${injectedClient;prefix;constructor(J={}){this.injectedClient=J
|
|
|
335
335
|
|
|
336
336
|
`)||void 0,E=await this.context(J,{body:V}),T=await this.reasoning(J,{body:V})||void 0,x=await this.skills(J,{body:V})||void 0,w=await this.runTools(J,{body:V,context:E})||void 0,s=await this.usageLimits(J,{body:V,context:E})||void 0,L=await this.attachmentsFor(J,Z,{body:V}),k=await this.attachmentRetention(J,{route:"stream",threadId:Z,body:V});pJ(k,this.turnAttachmentMaxAgeMs);let M=[],E8=L&&k?L.withLifetime({next:()=>pJ(k,this.turnAttachmentMaxAgeMs),onPut:(S)=>M.push(S)}):L,e$=this.agent.memory?await this.memoryScopes(J,{body:V}):void 0;if(D?.cancelled)return aZ();let y=Z?new q$(this.store,Z,F,(S)=>this.reportHookFailure(S)):null,JQ=`run_${crypto.randomUUID()}`,$Q=[],a={req:J,runId:JQ,threadId:Z,get denials(){return $Q}},MJ={id:null,notified:Promise.resolve()},I=this.agent.stream({runId:JQ,messages:F,turn:X,threadId:Z,...y?{onMessage:(S)=>y.finish(S)}:{},onTurn:(S)=>{if(MJ.id!==null)return;MJ.id=S.id;let t=y?y.settled():Promise.resolve();MJ.notified=t.then(()=>this.safely(()=>this.onMessage(S,a)))},instructions:_,...OJ.has(J)?{event:OJ.get(J)}:{},...v.has(J)?{echoTurn:!0}:{},...T?{reasoning:T}:{},...x&&x.length>0?{skills:x}:{},...w?.tools&&w.tools.length>0?{tools:w.tools}:{},...w?.activeTools?{activeTools:w.activeTools}:{},...s?{usageLimits:s}:{},context:E,attachments:E8,body:V,redactError:(S,t)=>this.redactError(S,t,a),onProviderRetry:(S)=>this.onProviderRetry(S,a),nonces:this.nonces,receipts:this.receipts,subject:Y,...e$?{memory:{scopes:e$,...this.memoryMaxTokens!==void 0?{maxTokens:this.memoryMaxTokens}:{}}}:{},...Z?{jobs:{owner:Y}}:{},...this.contextWindow!==void 0?{contextWindow:this.contextWindow}:{},...Z&&O8(this.store)?{summaryStore:this.store}:{},...this.prepareStep!==iJ.prototype.prepareStep||this.hooks?.prepareStep?{prepareStep:(S)=>this.prepareStep(S,a)}:{}});$Q=I.denials;let k8=this.liveRuns.register(I,{threadId:Z,owner:Y,clientRunId:G,onEvent:(S)=>this.dispatchEvent(S,a),onInternalError:(S)=>this.reportHookFailure(S),maxRunDurationMs:this.agent.maxRunDurationMs});P=I;let SJ=OJ.get(J);if(b$.set(I,{startedAt:new Date,owner:Y,turn:SJ?{...SJ.text?{text:SJ.text}:{},event:{name:SJ.name}}:qZ(X),joined:[]}),y)v$.set(I,y),this.follow(I,y);if(Z)s9(this.liveRuns,Z,I.runId);let QQ=X?.files??[],T8=this.definesRetention()&&(QQ.length>0||k==="turn")?()=>this.expireTurn({scoped:L,files:QQ,made:M,owner:Y}):null,{stored:j8,hooks:aJ}=this.persistRun(I,a,k8,y,MJ,T8);if(o.set(I,j8),hZ.set(J,{run:I,hooks:aJ}),v.has(J))v.set(J,{run:I,hooks:aJ});if(N.release)I.result().then(N.release,N.release);return J.ctx?.()?.waitUntil(aJ),I.toResponse()};try{await this.authorizeRequest(J,{route:"stream",threadId:Z,body:V});let N=await this.foreignFile([...X?.files??[],...Z?[]:Y6(Q.messages)],Y);if(N)return N;if(D?.cancelled)return aZ();let F=await this.runLimitKey(J,{owner:Y,threadId:Z}),U=F===null?A:lZ(this.liveRuns).take(F,Z?`thread:${Z}`:`run:${crypto.randomUUID()}`,this.maxConcurrentRuns);if(!U)return LJ(429,"too_many_runs",`You already have ${this.maxConcurrentRuns} conversations answering. Wait for one to finish, or stop it, and send again.`);let _;try{return _=Z?await this.withThread(Z,Y,O,{req:J,requested:K?"supersede":z,decide:!K,source:v.has(J)?"server":"client",turn:X,body:V,limitKey:F}):await O(),_}finally{let E=P,T=_?yZ.get(_):void 0;if(E)E.result().then(U,U);else if(T)T.then(U,U);else U()}}finally{if(D&&uJ.get(G)===D)uJ.delete(G)}}async withThread(J,$,Q,Z){if(Z.requested==="skip"&&CJ.has(J))return tZ(J);for(;;){let W=await this.underThreadLock(J,$,Q,Z);if(!("waitFor"in W))return W.response;await W.waitFor}}async underThreadLock(J,$,Q,Z){let W=CJ.get(J)??Promise.resolve(),X,K=new Promise((z)=>{X=z}),G=W.then(()=>K);CJ.set(J,G),await W;try{let z=this.liveRuns.running({threadId:J}).map((D)=>({info:D,run:this.liveRuns.get(D.runId)})).filter((D)=>D.run!==null);if(z.length===0){let D=await this.liveRuns.find({threadId:J}),P=D?this.liveRuns.get(D.runId):null;if(P)await o.get(P);return{response:await Q(y$)}}let V=Z.intake?.policy??(Z.decide?await this.decideBusy(J,$,z,Z):Z.requested??"supersede"),Y=(D)=>(o.get(D)??D.result()).then(A,A);if(V==="skip")return{response:tZ(J)};if(V==="queue")return{waitFor:Promise.all(z.map(({run:D})=>Y(D)))};if(V==="join"){let D=z.filter(({info:C})=>this.liveRuns.mayAccess(C.runId,$));if(D.length===0)return{response:n()};let P=D[D.length-1],H=g9(Z.turn,OJ.get(Z.req)),O=H?P.run.join?.(H)??null:null;if(!O)return{waitFor:Y(P.run)};return b$.get(P.run)?.joined.push(qZ(H)),{response:this.joinResponse(J,$,P.run,O,H,Q,Z)}}if(V==="parallel"){let D=Z.intake??={policy:V,waited:new WeakSet},P=z.filter(({run:C})=>!uZ(C,v$.get(C)).done&&!D.waited.has(C));if(P.length>0){for(let{run:U}of P)D.waited.add(U);let C=Promise.all(P.map(({run:U})=>uZ(U,v$.get(U)).promise)),N,F=new Promise((U)=>{N=setTimeout(U,p9)});return{waitFor:Promise.race([C,F]).finally(()=>clearTimeout(N))}}let H=await this.maxThreadRuns(Z.req,{threadId:J,owner:$,body:Z.body});if(z.length>=H)return{response:LJ(429,"too_many_runs",`This conversation already has ${z.length} answers going. Wait for one to finish, or stop it, and send again.`)};let O=Z.limitKey===null?A:lZ(this.liveRuns).take(Z.limitKey,`run:${crypto.randomUUID()}`,this.maxConcurrentRuns);if(!O)return{response:LJ(429,"too_many_runs",`You already have ${this.maxConcurrentRuns} conversations answering. Wait for one to finish, or stop it, and send again.`)};return{response:await Q({parallel:!0,release:O})}}if(z.some(({info:D})=>!this.liveRuns.mayAccess(D.runId,$)))return{response:n()};for(let{run:D}of z)D.stop({reason:"superseded by a later turn on this thread"});return await Promise.all(z.map(({run:D})=>o.get(D))),{response:await Q(y$)}}finally{if(X(),CJ.get(J)===G)CJ.delete(J)}}async decideBusy(J,$,Q,Z){let W=await this.busyPolicy(Z.req,{threadId:J,owner:$,requested:Z.requested,source:Z.source,turn:Z.turn,body:Z.body,running:Q.map(({info:X,run:K})=>{let G=b$.get(K);return{runId:X.runId,startedAt:G?.startedAt??new Date(X.startedAt),owner:this.liveRuns.ownerOf(X.runId),turn:G?.turn??{},joined:[...G?.joined??[]]}})});if(!fZ.includes(W))throw TypeError(`AgentController.busyPolicy answers "supersede", "queue", "join", "parallel" or "skip"; got ${JSON.stringify(W)}.`);return W}joinResponse(J,$,Q,Z,W,X,K){let G=(H)=>({kind:"answered",run:H,hooks:o.get(H)??H.result().then(A,A)}),z=Z.taken.then(async(H)=>{if(H||p$.has(Q))return null;return this.withThread(J,$,X,K)}),V=z.then(async(H)=>{if(!H)return p$.has(Q)?{kind:"dropped"}:G(Q);let O=cZ.get(H);if(O)return O;let C=hZ.get(K.req);if(C&&m9(H))return{kind:"answered",...C};return{kind:"refused",error:await KJ.from(H),stored:await this.storeUnanswered(J,Q,W)}},async(H)=>{return this.reportHookFailure(H),{kind:"refused",error:new KJ("The turn started for a joined message failed.",{status:500}),stored:await this.storeUnanswered(J,Q,W)}});if(v.has(K.req))h$.set(K.req,{run:Q,answer:V});async function*Y(){let H=-1;for await(let N of Q.frames())H=N.seq,yield N;let O=await z.catch(()=>null),C=await V;if(C.kind==="refused"){if(O?.body?.cancel().catch(A),C.stored&&W.localId)yield{seq:++H,event:{type:"message-id",localId:W.localId,messageId:C.stored.id,message:C.stored}};let N=C.error.status===429;yield{seq:++H,event:{type:"error",error:{code:N?"rate_limited":"unknown",message:`Your message was not answered: ${C.error.message}`,retryable:N}}};return}if(!O?.body)return;try{for await(let N of _Z(O.body))yield N}finally{O.body.cancel().catch(A)}}let D=(async()=>{await Q.result().catch(A);let H=await V;if(H.kind==="answered")await H.run.result().catch(A)})(),P=c$(Y());return yZ.set(P,D),cZ.set(P,V),P}async storeUnanswered(J,$,Q){await o.get($);let Z=B8(Q.event?Q.event.text:Q.text,Q.files,Q.event);try{return await this.store.appendMessages(J,[Z]),Z}catch(W){return this.reportHookFailure(W),null}}async attach(J=new f){let $=await XJ(J,_J);if($.error)return u($);let Q=$.body,Z=typeof Q.threadId==="string"?Q.threadId:sZ(J,"threadId");if(!Z)return B(400,{code:"invalid_request",message:"attach needs a threadId: it is the handle that survives a refresh."});await this.authorizeRequest(J,{route:"attach",threadId:Z});let W=Q.emptyMiss===!0;if(!await this.threadInScope(J,Z))return $8(Z,W);let X=typeof Q.runId==="string"?Q.runId:void 0,K=X&&this.liveRuns.isRunning(X)&&this.liveRuns.threadOf(X)===Z?{runId:X}:await this.liveRuns.find({threadId:Z});if(K&&!this.liveRuns.mayAccess(K.runId,await this.runOwner(J)))return n();if(!K)return $8(Z,W);let G=typeof Q.runId==="string"?Q.runId:void 0,z=G&&G!==K.runId?void 0:K6(J,Q);try{return c$(this.liveRuns.replay(K.runId,z))}catch(V){if(V instanceof WJ)return B(410,{code:V.code,message:V.message,oldestSeq:V.oldest});if(V instanceof FJ)return B(404,{code:V.code,message:V.message});throw V}}async watch(J=new f){let $=await XJ(J,_J);if($.error)return u($);let Q=$.body,Z=typeof Q.threadId==="string"?Q.threadId:sZ(J,"threadId");if(!Z)return B(400,{code:"invalid_request",message:"watch needs a threadId: it is the thread whose runs are announced."});if(await this.authorizeRequest(J,{route:"attach",threadId:Z}),!await this.threadInScope(J,Z))return B(404,{code:"thread_not_found",message:`Thread ${Z} does not exist here, or has expired.`});let W=await this.runOwner(J),X=this.liveRuns,K=o9(X),G=null,z=null,V=0,Y=()=>{if(z?.stop(),!G)return;let P=K.get(Z);if(P?.delete(G),P&&P.size===0)K.delete(Z);G=null},D=new ReadableStream({start(P){z=G8(P);let H=(C)=>{if(!X.mayAccess(C,W))return;try{P.enqueue(new TextEncoder().encode(K8({seq:++V,event:{type:"run-start",runId:C,threadId:Z}}))),z?.touch()}catch{Y()}};G=H;let O=K.get(Z);if(!O)O=new Set,K.set(Z,O);O.add(H);for(let{runId:C}of X.running({threadId:Z}))H(C)},cancel(){Y()}});return J.rawRequest?.signal?.addEventListener("abort",Y,{once:!0}),new Response(D,{status:200,headers:V8()})}async stop(J=new f){let $=await XJ(J,_J);if($.error)return u($);let Q=$.body;await this.authorizeRequest(J,{route:"stop",threadId:typeof Q.threadId==="string"?Q.threadId:void 0});let Z=await this.runOwner(J),W=typeof Q.runId==="string"?Q.runId:void 0;if(!W&&typeof Q.clientRunId==="string"){if(W=this.liveRuns.findByClientRunId(Q.clientRunId)??void 0,!W){let K=uJ.get(Q.clientRunId);if(K){if(K.owner!==null&&K.owner!==Z)return n();return K.cancelled=!0,{stopped:!0}}}}if(!W&&typeof Q.threadId==="string"){let K=this.liveRuns.running({threadId:Q.threadId});if(K.length>1){let G=K.filter((V)=>this.liveRuns.mayAccess(V.runId,Z));if(G.length===0)return n();let z=typeof Q.reason==="string"?Q.reason:void 0;for(let V of G){let Y=this.liveRuns.get(V.runId);if(Y)BJ(Y,{reason:z})}return{stopped:!0}}W=(await this.liveRuns.find({threadId:Q.threadId}))?.runId}let X=W?this.liveRuns.get(W):null;if(!X)return{stopped:!1};if(!this.liveRuns.mayAccess(X.runId,Z))return n();return BJ(X,{reason:typeof Q.reason==="string"?Q.reason:void 0}),{stopped:!0}}attachmentScope(J,$,Q){let Z=this.hooks?.attachmentScope;if(Z)return Z(J,$,Q);let W=J.ctx()?.user,X=W?.id??W?.publicId;if(X!==void 0&&X!==null&&String(X)!=="")return{key:`user:${String(X)}`};if($)return{key:`thread:${$}`};return null}attachmentRetention(J,$){return this.hooks?.attachmentRetention?.(J,$)??null}definesRetention(){return this.attachmentRetention!==iJ.prototype.attachmentRetention||Boolean(this.hooks?.attachmentRetention)}async sweepAttachments(J={}){let $=J.now??new Date,Q=J.limit??500;if(!this.attachments.expired||!this.attachments.delete)throw Error("sweepAttachments() needs an attachment store with expired() and delete(). Implement both on the controller's `attachments` store.");let Z={deleted:0,failed:0},W=this.deletionTargets();for(let X of await this.attachments.expired($,Q))try{await u$(X,W),Z.deleted++}catch(K){Z.failed++,this.reportHookFailure(K)}for(let X of await this.fileOwners.expired?.($,Q)??[])try{await this.deleteProviderFile(X),Z.deleted++}catch(K){Z.failed++,this.reportHookFailure(K)}return Z}deletionTargets(){return{store:this.attachments,storage:this.attachmentStorage,provider:this.agent.provider,fileOwners:this.fileOwners}}async deleteProviderFile(J){let $=this.agent.provider;if(!$.deleteFile)throw Error(`Cannot delete provider file ${J}: the agent's provider has no deleteFile().`);await $.deleteFile(J),await this.fileOwners.delete?.(J)}async expireTurn(J){let $=this.deletionTargets(),Q=new Set,Z=new Set,W=async(X)=>{if(Q.has(X.id))return;if(Q.add(X.id),X.fileId)Z.add(X.fileId);try{await u$(X,$)}catch(K){this.reportHookFailure(K)}};for(let X of J.made)if(X.deleteAfterTurn)await W(X);for(let X of J.files){if(X.attachmentId&&J.scoped){let K=await J.scoped.get(X.attachmentId).catch(()=>null);if(K?.deleteAfterTurn)await W(K)}if(X.fileId&&!Z.has(X.fileId)){Z.add(X.fileId);let K=await this.fileOwners.get(X.fileId);if(K?.deleteAfterTurn&&K.owner===J.owner)try{await this.deleteProviderFile(X.fileId)}catch(G){this.reportHookFailure(G)}}}}attachmentLimits(J){let $=this.hooks?.attachmentLimits;if($)return $(J);return null}checkUpload(J,$,Q){return this.hooks?.checkUpload?.(J,$,Q)}attachmentDestination(J,$,Q){let Z=this.hooks?.attachmentDestination;if(Z)return Z(J,$,Q);return"both"}async attachmentsFor(J,$,Q={body:{}}){let Z=await this.attachmentScope(J,$,Q);if(!Z)return null;return new oJ(this.attachments,this.attachmentStorage,Z)}async voiceStart(J=new f){let $=this.voice;if(!$)return g$();let Q=await XJ(J,_J);if(Q.error)return u(Q);let{sdp:Z,threadId:W,pushToTalk:X}=Q.body;if(typeof Z!=="string"||!Z.trimStart().startsWith("v="))return B(400,{code:"invalid_request",message:"`sdp` must be the browser's SDP offer."});let K=lJ(Q.body,D6),G=typeof W==="string"&&W!==""?W:void 0;await this.authorizeRequest(J,{route:"stream",threadId:G,body:K});let z=J.ctx?.()?.user??null,V=await $.start({req:J,body:K,threadId:G,user:z,pushToTalk:X===!0}),Y=Date.now(),D,P=async(U)=>{if(U!==void 0)console.error("[gemi/ai] a voice session could not start.",U);if(D)await $.realtime.hangup(D).catch((_)=>{console.error("[gemi/ai] a voice call that failed to start could not be hung up.",_)});try{await V.onEnd?.({sessionId:"",...D?{callId:D}:{},threadId:V.threadId??G??"",reason:"start_failed",startedAt:Y,endedAt:Date.now(),durationMs:0,seconds:0,usage:R(),transcription:{usage:R(),seconds:0},transcript:[],requests:[],toolCalls:[],errors:[]})}catch(_){console.error("[gemi/ai] a voice session's onEnd threw.",_)}},H=V.threadId??G;if(!H)return await P(void 0),B(400,{code:"invalid_request",message:"A voice session needs a thread: send `threadId`, or answer one from `voice.start`."});try{if(H!==G)await this.authorizeRequest(J,{route:"stream",threadId:H,body:K})}catch(U){throw await P(void 0),U}let O=crypto.randomUUID(),C=V.tools??[];try{if(V.mcp)C=[...C,...await L$(V.mcp,{user:z,sessionId:O})]}catch(U){return await P(U),B(500,{code:"voice_unavailable",message:"Voice isn't available right now."})}let N={...V.session,tools:[...HJ($.delegate),...V.session?.tools??[],...C.map((U)=>U.tool)],...X===!0?{turnDetection:null}:{}},F;try{F=await $.realtime.createCall({sdp:Z,session:N,safetyIdentifier:V.safetyIdentifier})}catch(U){await P(U);let _=U instanceof r$&&U.code==="rate_limited";return B(_?429:502,{code:"voice_unavailable",message:"Voice isn't available right now."})}D=F.callId;try{await this.voiceStore.create({id:O,callId:F.callId,threadId:H,owner:await this.runOwner(J),body:K,startedAt:Y});let{threadId:U,session:_,safetyIdentifier:E,mcp:T,tools:x,...w}=V;return{sessionId:d.start({...w,tools:C,controller:this.constructor,threadId:H,user:z,body:K,call:{realtime:$.realtime,callId:F.callId},sessionId:O,store:this.voiceStore,liveRuns:this.liveRuns,delegate:$.delegate,session:N}).sessionId,sdp:F.sdpAnswer,threadId:H,delegate:$.delegate?.name??PJ,endsAt:Y+(V.limits?.maxDurationMs??900000)}}catch(U){return await P(U),B(500,{code:"voice_unavailable",message:"Voice isn't available right now."})}}async voiceUpdate(J=new f){if(!this.voice)return g$();let $=await this.voiceSession(J);if($ instanceof Response)return $;let Q=await XJ(J,_J);if(Q.error)return u(Q);let Z=lJ(Q.body,[]);if(await this.authorizeRequest(J,{route:"stream",threadId:$.threadId,body:Z}),$.endedAt!==void 0)return B(409,{code:"voice_ended",message:"This voice session has ended."});return await this.voiceStore.update($.id,{body:Z}),d.get($.id)?.setBody(Z),{updated:!0}}async voiceEnd(J=new f){let $=this.voice;if(!$)return g$();let Q=await this.voiceSession(J);if(Q instanceof Response)return Q;if(await this.authorizeRequest(J,{route:"stream",threadId:Q.threadId,body:Q.body}),Q.endedAt!==void 0)return{ended:!1};let Z=d.get(Q.id);if(Z)await Z.end("hangup");else await $.realtime.hangup(Q.callId),await this.voiceStore.update(Q.id,{endedAt:Date.now(),endReason:"hangup"});return{ended:!0}}async voiceSession(J){let $=J.params?.sessionId,Q=typeof $==="string"&&$?await this.voiceStore.get($):null;if(!Q)return B(404,{code:"voice_not_found",message:"No such voice session."});if(Q.owner!==null&&Q.owner!==await this.runOwner(J))return n();return Q}async upload(J=new f){let $=await J.rawRequest.formData(),Q=$.get("file");if(!(Q instanceof Blob))throw Error("upload expects a multipart body with a `file` field.");let Z=Q instanceof File&&Q.name?Q.name:"upload",W=Q.type||"application/octet-stream",X=r9($.get("body")),K=$.get("threadId");await this.authorizeRequest(J,{route:"upload",threadId:typeof K==="string"&&K.length>0?K:void 0,body:X});let G=J6(await this.attachmentLimits(J),Q,Z,W);if(G)throw new n$(G.code,G.message);await this.scopeStore(J,X);let z=typeof K==="string"&&K.length>0&&await this.store.loadThread(K)!==null?K:void 0,V=await this.runOwner(J),Y=null,D=(x)=>this.fileOwners.record(x,{owner:V,name:Z,mimeType:W,size:Q.size,createdAt:new Date().toISOString(),...Y}),P={body:X,threadId:z},H=await this.checkUpload({name:Z,size:Q.size,mimeType:W},J,P);if(H)throw new n$(H.code||"upload_refused",H.message);let O=await this.attachmentDestination(Q,J,P),C=H6(O,$.get("destination")),N=await this.attachmentScope(J,z,{body:X});Y=pJ(await this.attachmentRetention(J,{route:"upload",threadId:z,body:X}),this.turnAttachmentMaxAgeMs);let F=C!=="provider"&&!N;if(F){if(C==="storage")throw Error('This upload was routed to storage, but `attachmentScope()` returned null for the request, so there is no subject to file the attachment under. Guard the route (`this.agent(Chat).middleware({ upload: "auth" })`), send a `threadId` with the upload, or override `attachmentScope()`.');P6()}if(C==="provider"||!N){let x=await iZ(this.agent.provider,Q);await D(x);let w={fileId:x,name:Z,mimeType:W,size:Q.size,destination:"provider"};if(F)w.downgraded="no_scope";return w}let U=N8(),_=await this.attachmentStorage.put({name:F8(U,Z),body:Q,contentType:W}),E=C==="both"?await iZ(this.agent.provider,Q):void 0;if(E)await D(E);let T={id:U,scopeKey:N.key,fileId:E,objectName:_,name:Z,mimeType:W,size:Q.size,createdAt:new Date().toISOString(),destination:C,...Y};return await this.attachments.put(N,T),{fileId:E,attachmentId:U,name:Z,mimeType:W,size:Q.size,destination:C}}async foreignFile(J,$){let Q=new Set(J.map((Z)=>Z.fileId).filter((Z)=>typeof Z==="string"));for(let Z of Q){let W=await this.fileOwners.get(Z);if(W?W.owner!==null&&W.owner!==$:this.requireKnownFiles)return z6()}return null}onMessage(J,$){return this.hooks?.onMessage?.(J,$)}onToolCall(J,$){return this.hooks?.onToolCall?.(J,$)}onToolResult(J,$,Q){return this.hooks?.onToolResult?.(J,$,Q)}onAwaitingInput(J,$){return this.hooks?.onAwaitingInput?.(J,$)}redactError(J,$,Q){let Z=this.hooks?.redactError;if(Z)return Z(J,$,Q);return a$(J,$)}onError(J,$){return this.hooks?.onError?.(J,$)}onProviderRetry(J,$){return this.hooks?.onProviderRetry?.(J,$)}onStreamComplete(J,$){return this.hooks?.onStreamComplete?.(J,$)}reportHookFailure(J){let $=this.hooks?.reportHookFailure;if($)try{return $(J)}catch(Q){console.error("[gemi/ai] reportHookFailure hook failed",Q)}console.error("[gemi/ai] agent controller hook failed",J)}async dispatchEvent(J,$){switch(J.type){case"tool-call":if(!J.part.partial&&!J.resent)await this.onToolCall({toolCallId:J.part.toolCallId,name:String(J.part.name),input:J.part.input},$);return;case"tool-result":{let Q=J.part;await this.onToolResult(Q,$,{toolCallId:Q.toolCallId,name:String(Q.name),input:L8(Q)});return}case"awaiting-input":await this.onAwaitingInput(J.pending,$);return;case"error":await this.onError(D8(J.error),$);return;default:return}}async readThread(J,$={}){let Z=await($.scope===null||$.scope===void 0?this.store:J8(this.store,$.scope)).loadThread(J);if(!Z)return null;let{messages:W}=await this.settleThread(J,Z,{write:!1});return W}isRunLive(J,$){return this.liveRuns.get(J)!==null}async settleThread(J,$,{write:Q}){let Z=(z)=>this.isRunLive(z,J),W=await kZ($,Z),X=W.messages,K=[],G=new Map(W.settled.map((z)=>[z.id,z]));if(C6(X)||Q)try{let z=await wZ(X,{threadId:J,store:m.store,isRunLive:Z,outputSchemaFor:(V)=>this.toolNamed(V)?.outputSchema,modelOutputFor:(V,Y)=>_8(this.toolNamed(V),Y,(D)=>this.reportHookFailure(D)),scan:this.jobsBlockMax()});X=z.messages,K=z.jobs;for(let V of z.settled)G.set(V.id,V);if(Q&&z.orphans.length>0){await IZ(m.store,z.orphans,(Y)=>this.reportHookFailure(Y));let V=new Set(z.orphans.map((Y)=>Y.id));K=K.map((Y)=>V.has(Y.id)?{...Y,orphaned:!0}:Y)}}catch(z){this.reportHookFailure(z)}if(Q&&G.size>0)try{await this.store.appendMessages(J,[...G.values()])}catch(z){this.reportHookFailure(z)}return{messages:X,jobs:K}}jobsBlockMax(){let J=this.agent.jobs?.contextBlock;if(J===!1)return 0;return J?.max??TJ}jobsBlock(J){return DQ(J,this.jobsBlockMax())}toolNamed(J){let $=(Q)=>{for(let Z of Q){let W=Z;if(Array.isArray(W.tools)){let X=$(W.tools);if(X)return X}else if(W.name===J)return W}return};return $(this.agent.tools??[])}follow(J,$){(async()=>{try{for await(let Q of J.frames())$.frame(Q)}catch(Q){this.reportHookFailure(Q)}})()}persistRun(J,$,Q,Z=null,W={id:null,notified:Promise.resolve()},X=null){let K=(Y)=>X?Y.then(()=>this.safely(X)):Y,G=Promise.resolve(),z=(async()=>{let Y;try{Y=await J.result()}catch(P){Z?.close(),await Z?.settled(),G=K(W.notified.then(()=>this.safely(()=>this.onError({code:"unknown",message:P instanceof Error?P.message:String(P),retryable:!1},$))));return}let D=Y.messages;if(Z?.close(D),await Z?.settled(),$.threadId&&D.length>0)try{await this.store.appendMessages($.threadId,D)}catch(P){this.reportHookFailure(P)}G=K(this.notifyRun(Y,D,$,W))})(),V=z.then(()=>F6(Promise.all([G,Q]).then(()=>{}),this.hookHoldMs));return{stored:z,hooks:V}}async notifyRun(J,$,Q,Z){await Z.notified;for(let W of $){if(W.id===Z.id)continue;await this.safely(()=>this.onMessage(W,Q))}await this.safely(()=>this.onStreamComplete(J,Q))}async safely(J){try{await J()}catch($){this.reportHookFailure($)}}}var i$=["turn","clientRunId","threadId","messages","regenerate","ifBusy"],t9=["text","files","toolResults"];function lJ(J,$=R8(J)?i$:[...i$,...t9]){let Q={};for(let[Z,W]of Object.entries(J)){if($.includes(Z))continue;Object.defineProperty(Q,Z,{value:W,writable:!0,enumerable:!0,configurable:!0})}return Q}function r9(J){if(J===null)return{};let $;if(typeof J==="string")try{$=JSON.parse(J)}catch{throw new d$("The upload's `body` field is not valid JSON.")}if($===null||typeof $!=="object"||Array.isArray($))throw new d$("The upload's `body` field must be a JSON object.");return lJ($,i$)}class d$ extends dJ{constructor(J){super(J);this.name="InvalidUploadError",this.payload={api:{status:400,data:{error:{code:"invalid_request",message:J}}},view:{}}}}async function iZ(J,$){try{return await J.upload($)}catch(Q){if(Q instanceof C8&&e9.has(Q.status))throw new A8($J(Q).message);throw Q}}var e9=new Set([400,413,415,422]);class n$ extends dJ{constructor(J,$){super($);this.name="LimitedUploadError",this.payload={api:{status:422,data:{error:{code:J,message:$}}},view:{}}}}function J6(J,$,Q,Z){if(!J)return null;let{maxBytes:W,accept:X}=J;if(typeof W==="number"&&$.size>W)return{code:"file_too_large",message:`${JSON.stringify(Q)} is ${dZ($.size)}; the limit is ${dZ(W)}.`};if(X&&X.length>0&&!X.some((K)=>$6(K,Q,Z)))return{code:"unsupported_file_type",message:`${JSON.stringify(Q)} is not a type this chat accepts. Accepted: ${X.join(", ")}.`};return null}function $6(J,$,Q){let Z=J.trim().toLowerCase();if(!Z)return!1;if(Z.startsWith("."))return $.toLowerCase().endsWith(Z);let W=Q.toLowerCase().split(";")[0].trim();if(Z.endsWith("/*"))return W.startsWith(Z.slice(0,-1));return W===Z}function dZ(J){if(J<1024)return`${J} B`;let $=["KB","MB","GB"],Q=J/1024,Z=0;while(Q>=1024&&Z<$.length-1)Q/=1024,Z++;return`${Math.round(Q*10)/10} ${$[Z]}`}class A8 extends dJ{constructor(J){super(J);this.name="RejectedUploadError";let $=/(unsupported|invalid) (extension|file type|format|mime)|supported (extensions|formats?)/i.test(J)?"unsupported_file_type":"file_rejected";this.payload={api:{status:422,data:{error:{code:$,message:J}}},view:{}}}}async function XJ(J,$){let Q=J?.rawRequest;if(!Q||Q.method==="GET"||Q.method==="HEAD"||!Q.body)return{body:{}};if(!Q6(Q.headers.get("Content-Type")))return{body:{},status:415,code:"unsupported_media_type",error:"The request body must be sent as application/json."};let Z=Number(Q.headers.get("Content-Length"));if(Number.isFinite(Z)&&Z>$)return nZ($);let W;try{let K=await Z6(Q,$);if(K===null)return nZ($);W=K}catch{return{body:{},error:"The request body could not be read."}}if(!W.trim())return{body:{}};let X;try{X=JSON.parse(W)}catch{return{body:{},error:"The request body is not valid JSON."}}if(X===null||typeof X!=="object"||Array.isArray(X))return{body:{},error:"The request body must be a JSON object."};return{body:X}}function Q6(J){return W8(J)==="application/json"}async function Z6(J,$){if(!Number.isFinite($)||!J.body)return await J.text();let Q=J.body.getReader(),Z=[],W=0;for(;;){let{done:G,value:z}=await Q.read();if(G)break;if(W+=z.byteLength,W>$)return await Q.cancel().catch(A),null;Z.push(z)}let X=new Uint8Array(W),K=0;for(let G of Z)X.set(G,K),K+=G.byteLength;return new TextDecoder().decode(X)}function nZ(J){return{body:{},status:413,code:"body_too_large",error:`The request body is larger than this agent accepts (${J} bytes).`}}function LJ(J,$,Q){return B(J,{...nJ(Z8(J),Q,J),code:$})}function u(J){if(J.status===413)return LJ(413,J.code??"body_too_large",J.error??"");return B(J.status??400,{code:J.code??"invalid_request",message:J.error})}function R8(J){return Boolean(J.turn)&&typeof J.turn==="object"}function W6(J){let $=R8(J)?J.turn:J,Q={};if(typeof $.text==="string")Q.text=$.text;if(Array.isArray($.files)){let Z=X6($.files);if(typeof Z==="string")return{error:Z};Q.files=Z}if(Array.isArray($.toolResults))Q.toolResults=$.toolResults;if(Object.keys(Q).length===0)return{};if($===J.turn&&$.localId!==void 0&&$.localId!==null&&$.localId!==""){let{localId:Z}=$;if(typeof Z!=="string")return{error:"turn.localId must be a string."};if(Z.length>oZ)return{error:`turn.localId is longer than ${oZ} characters.`};Q.localId=Z}return{turn:Q}}var oZ=200;function X6(J){let $=[];for(let[Q,Z]of J.entries()){let W=`turn.files[${Q}]`;if(!Z||typeof Z!=="object"||Array.isArray(Z))return`${W} must be an object.`;let X={};for(let Y of["fileId","attachmentId","name","mimeType"]){let D=Z[Y];if(D===void 0||D===null||D==="")continue;if(typeof D!=="string")return`${W}.${Y} must be a string.`;X[Y]=D}let{fileId:K,attachmentId:G,name:z,mimeType:V}=X;if(K?.startsWith(mJ))return`${W}.fileId holds a gemi attachment id (${K}). \`fileId\` is the provider's id from the upload response; put this one in \`attachmentId\`.`;if(G!==void 0&&!G.startsWith(mJ))return`${W}.attachmentId is not a gemi attachment id: it must start with "${mJ}".`;if(!K&&!G)return`${W} has neither a \`fileId\` nor an \`attachmentId\`. Send the ids the upload response answered.`;$.push({...K?{fileId:K}:{},...G?{attachmentId:G}:{},...z!==void 0?{name:z}:{},...V!==void 0?{mimeType:V}:{}})}return $}function K6(J,$){if(typeof $.from==="number"&&Number.isFinite($.from))return Math.max(0,Math.floor($.from));if(typeof $.cursor==="number"&&Number.isFinite($.cursor)){let Z=Math.floor($.cursor);if(Z>=0)return Z+1;return}let Q=J?.rawRequest?.headers?.get("Last-Event-ID");if(Q){let Z=Number.parseInt(Q,10);if(Number.isFinite(Z))return Math.max(0,Z+1)}return}function sZ(J,$){let Q=J?.search?.get($);return typeof Q==="string"?Q:void 0}function G6(J){let $=t$(J);for(let Q=J.length-1;Q>=0;Q--){let Z=J[Q];if(Z.role!=="user"||$.has(Z.id))continue;let W="",X=[];for(let K of Z.content){if(K.type==="text")W+=K.text;if(K.type==="file")X.push({...K.fileId?{fileId:K.fileId}:{},...K.attachmentId?{attachmentId:K.attachmentId}:{},...K.name?{name:K.name}:{},...K.mimeType?{mimeType:K.mimeType}:{}})}if(!W&&X.length===0)continue;return{index:Q,turn:{...W?{text:W}:{},...X.length>0?{files:X}:{}}}}return null}function aZ(){return B(409,{code:"stopped",message:"The turn was stopped before it started."})}function V6(J){let $=J.event;if(J.text!==void 0||J.turn!==void 0)throw TypeError("AgentController.startTurn takes an `event` or a `text`/`turn`, not both: an event is not a person's message.");if(typeof $!=="object"||$===null||typeof $.name!=="string"||!v9.test($.name))throw TypeError('AgentController.startTurn\'s `event.name` must be letters, digits and `.`, `_`, `:`, `-` (at most 64), like "job-settled".');if($.text!==void 0&&typeof $.text!=="string")throw TypeError("AgentController.startTurn's `event.text` must be a string.");let Q;if($.data!==void 0)try{Q=JSON.parse(JSON.stringify($.data))}catch(Z){throw TypeError(`AgentController.startTurn's \`event.data\` is not JSON: ${String(Z)}`)}return{name:$.name,...$.text?{text:$.text}:{},...Q!==void 0?{data:Q}:{}}}function tZ(J){return B(409,{code:M8,message:`Thread ${J} has a run going, and this turn was not to interrupt it.`})}function n(){return B(403,nJ("permission","This run belongs to someone else.",403))}function z6(){return B(403,nJ("permission","A file in this turn was uploaded by someone else.",403))}function Y6(J){if(!Array.isArray(J))return[];let $=[];for(let Q of J){let Z=Q?.content;if(!Array.isArray(Z))continue;for(let W of Z)if(W&&typeof W==="object"&&typeof W.fileId==="string")$.push({fileId:W.fileId})}return $}var D6=["sdp","threadId","pushToTalk"];function g$(){return B(404,{code:"voice_not_enabled",message:"This agent has no voice: set `voice` on its controller."})}function B(J,$){return new Response(JSON.stringify({error:$}),{status:J,headers:{"Content-Type":"application/json"}})}function H6(J,$){if(typeof $!=="string"||$.length===0)return J;if($!=="both"&&$!=="provider"&&$!=="storage")throw Error(`Unknown attachment destination "${$}". Expected "both", "provider" or "storage".`);if($===J||J==="both"&&$==="storage")return $;if(J==="both"&&$==="provider")throw Error('This upload asked for the "provider" destination under a "both" policy. A client may ask for "storage", which keeps a file away from the model provider, but it may not ask the server to stop keeping its own copy while the vendor still gets the file \u2014 that is the app\'s retention decision. Change `attachmentDestination()` if this file should not be kept.');throw Error(`This upload asked for the "${$}" destination, but the server's policy for it is "${J}", and a client hint may only ask for "storage" under a "both" policy. Change \`attachmentDestination()\` if the file really should go there.`)}var rZ=!1;function P6(){if(rZ)return;rZ=!0,console.warn("[gemi/ai] An upload had no attachment scope, so its bytes were sent to the model provider only and no attachment id was minted \u2014 a tool cannot forward this file. Guard the route with auth, send a `threadId` with the upload, or override `attachmentScope()`.")}var N6=2147483647;function F6(J,$){let Q=J.then(()=>{},()=>{});if(!($<=N6))return Q;let Z,W=new Promise((X)=>{Z=setTimeout(X,$)});return Promise.race([Q,W]).finally(()=>clearTimeout(Z))}var eZ=!1;function U6(J){if(eZ||Bun.env.NODE_ENV!=="production")return;if(!(J instanceof o$))return;eZ=!0,console.warn("[gemi/ai] A stateless agent chat is spending approval nonces in process memory. With more than one instance a replayed approval is accepted once per instance. Set `nonces = new RedisNonceStore()` (or your own NonceStore) on the AgentController.")}function C6(J){return J.some(($)=>$.content.some((Q)=>Q.type==="tool-result"&&Q.status==="running"))}function J8(J,$){if(typeof $!=="string"||$==="")throw TypeError("A store scope is a non-empty string.");if(!J.forScope)throw Error("This controller's store cannot be scoped: storeScope() or a turn's `scope` needs a store that implements `forScope` (DatabaseAgentStore or MemoryAgentStore).");return J.forScope($)}function $8(J,$=!1){if($)return new Response(null,{status:204});return B(404,{code:"no_live_run",message:`No run in progress for thread ${J} in this process.`})}export{k6 as windowMessages,HJ as voiceTools,M6 as turnStarts,o6 as toRealtimeUsage,e8 as toAgentTools,L6 as supportsStrict,S6 as splitTurns,q6 as settleSummaries,_6 as s,a$ as redactError,i6 as parsePartialJson,A6 as messageSize,YJ as measureUsage,L$ as mcpVoiceTools,R$ as liveRuns,NJ as keepSummary,a6 as isCallNotFound,t$ as injectedMessageIds,z$ as generate,Y9 as evalChain,a9 as defineAgentHooks,M$ as defaultVoiceStore,v6 as defaultUsageLimitStore,f6 as defaultSummaryStore,l6 as defaultPromptCacheKey,s$ as defaultNonceStore,E$ as defaultFileOwners,sJ as defaultAttachmentStore,I$ as defaultAgentStore,hJ as VoiceHangup,d as VoiceBridge,B6 as Usage,D$ as ToolNamespace,i as ToolError,m6 as ToolArgumentsTooLongError,h6 as Skill,oJ as ScopedAttachments,g6 as SKILLS_NAMESPACE,x$ as RedisReceiptStore,z8 as RedisNonceStore,d6 as RealtimeSideband,r$ as RealtimeRequestError,s6 as RealtimeClient,VQ as Prompt,Y8 as PrismaNonceStore,y6 as PendingEscalation,t6 as OpenAIProvider,F$ as OpenAIImageProvider,B$ as MemoryVoiceSessionStore,b6 as MemoryUsageLimitStore,I6 as MemorySummaryStore,j$ as MemoryReceiptStore,o$ as MemoryNonceStore,gJ as MemoryLiveRuns,cJ as MemoryFileOwners,vJ as MemoryCircuitStore,U8 as MemoryAttachmentStore,UJ as MemoryAgentStore,FQ as MemoryAgentJobStore,IQ as MEMORY_NAMESPACE,FJ as LiveRunNotFoundError,CQ as JobsRequireThreadError,UQ as JobHandle,O6 as JSONSchemaError,P8 as InvalidAttachmentScopeError,EQ as InMemoryAgentMemoryStore,qJ as ImageRequestError,bJ as ImageProvider,H$ as ImageModel,WJ as FrameCursorEvictedError,DJ as FallbackProvider,xQ as FakeAgentMemoryStore,IJ as Eval,S$ as DatabaseAgentStore,Z$ as DatabaseAgentMemoryStore,$$ as DatabaseAgentJobStore,n6 as DEFAULT_TRANSCRIPTION_MODEL,RQ as DEFAULT_MEMORY_MAX_TOKENS,wQ as DEFAULT_MEMORY_LIMITS,T6 as DEFAULT_MAX_SUMMARY_TOKENS,c6 as DEFAULT_MAX_RUN_DURATION_MS,OQ as DEFAULT_JOB_DEADLINE_MS,TJ as DEFAULT_JOBS_CONTEXT_MAX,PJ as DEFAULT_DELEGATE_NAME,R6 as DEFAULT_CONTEXT_WINDOW_STEP,E6 as DEFAULT_CONTEXT_WINDOW_NOTE,j6 as DEFAULT_COMPACT_TRIGGER_TOKENS,x6 as DEFAULT_COMPACT_INSTRUCTIONS,w6 as COMPACT_SUMMARY_HEADER,J0 as AzureOpenAIProvider,U$ as AzureOpenAIImageProvider,e6 as AzureAnthropicProvider,H8 as AttachmentNotFoundError,r6 as AnthropicProvider,KJ as AgentTurnError,fJ as AgentTool,u6 as AgentRunError,_$ as AgentProvider,kQ as AgentMemoryRefusedError,TQ as AgentMemoryConflictError,jQ as AgentMemories,m as AgentJobs,J$ as AgentJobDeadlineSweep,_Q as AgentJob,iJ as AgentController,p6 as Agent};
|
|
337
337
|
|
|
338
|
-
//# debugId=
|
|
338
|
+
//# debugId=1179FC034332829864756E2164756E21
|