gemi 0.233.1 → 0.234.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/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-0hy5dsbt.js +5 -0
- package/dist/{chunk-rqzpxeb5.js.map → chunk-0hy5dsbt.js.map} +1 -1
- package/dist/{chunk-e30saw5t.js → chunk-17bva6b1.js} +2 -2
- package/dist/{chunk-e30saw5t.js.map → chunk-17bva6b1.js.map} +1 -1
- package/dist/{chunk-6fpjc2eg.js → chunk-17ewxwga.js} +3 -3
- package/dist/{chunk-6fpjc2eg.js.map → chunk-17ewxwga.js.map} +1 -1
- package/dist/{chunk-5p0gbwq1.js → chunk-1mb7kaxs.js} +3 -3
- package/dist/{chunk-5p0gbwq1.js.map → chunk-1mb7kaxs.js.map} +1 -1
- package/dist/{chunk-mcgcgm6g.js → chunk-1w6ra6jc.js} +1 -1
- package/dist/{chunk-qqe19gtm.js → chunk-1xz206e1.js} +3 -3
- package/dist/{chunk-qqe19gtm.js.map → chunk-1xz206e1.js.map} +1 -1
- package/dist/{chunk-wgxkr2jx.js → chunk-28yb0q82.js} +2 -2
- package/dist/{chunk-wgxkr2jx.js.map → chunk-28yb0q82.js.map} +1 -1
- package/dist/{chunk-j5fh6pjs.js → chunk-2j45vbs2.js} +2 -2
- package/dist/{chunk-j5fh6pjs.js.map → chunk-2j45vbs2.js.map} +1 -1
- package/dist/{chunk-mgvrfhy8.js → chunk-2kzysesp.js} +3 -3
- package/dist/{chunk-mgvrfhy8.js.map → chunk-2kzysesp.js.map} +1 -1
- package/dist/{chunk-tegjs0gg.js → chunk-2ver7cdt.js} +1 -1
- package/dist/{chunk-kfcz4qa8.js → chunk-3y1h3ncf.js} +2 -2
- package/dist/{chunk-kfcz4qa8.js.map → chunk-3y1h3ncf.js.map} +1 -1
- package/dist/{chunk-xprhym1t.js → chunk-406ef17s.js} +2 -2
- package/dist/{chunk-xprhym1t.js.map → chunk-406ef17s.js.map} +1 -1
- package/dist/{chunk-j7swq19b.js → chunk-4mha212g.js} +1 -1
- package/dist/{chunk-vnpfdr52.js → chunk-4n3jva4e.js} +2 -2
- package/dist/{chunk-vnpfdr52.js.map → chunk-4n3jva4e.js.map} +1 -1
- package/dist/{chunk-jrvqya5h.js → chunk-4vn8gyzy.js} +2 -2
- package/dist/{chunk-jrvqya5h.js.map → chunk-4vn8gyzy.js.map} +1 -1
- package/dist/{chunk-c5kd7eac.js → chunk-5exrgw07.js} +3 -3
- package/dist/{chunk-c5kd7eac.js.map → chunk-5exrgw07.js.map} +1 -1
- package/dist/chunk-69xg5wgz.js +10 -0
- package/dist/{chunk-1eha67ey.js.map → chunk-69xg5wgz.js.map} +5 -4
- package/dist/{chunk-mg9j9r9f.js → chunk-6v1fbe70.js} +2 -2
- package/dist/{chunk-mg9j9r9f.js.map → chunk-6v1fbe70.js.map} +1 -1
- package/dist/{chunk-q78n7dvm.js → chunk-74dzzd64.js} +2 -2
- package/dist/{chunk-q78n7dvm.js.map → chunk-74dzzd64.js.map} +1 -1
- package/dist/{chunk-3v8b2kdr.js → chunk-7fbnw7e2.js} +1 -1
- package/dist/{chunk-znh1mbqs.js → chunk-8476xvk9.js} +2 -2
- package/dist/{chunk-znh1mbqs.js.map → chunk-8476xvk9.js.map} +1 -1
- package/dist/{chunk-65wnm25z.js → chunk-8gz07168.js} +4 -4
- package/dist/{chunk-65wnm25z.js.map → chunk-8gz07168.js.map} +1 -1
- package/dist/{chunk-8q1n4087.js → chunk-8jc8x9tc.js} +2 -2
- package/dist/{chunk-8q1n4087.js.map → chunk-8jc8x9tc.js.map} +1 -1
- package/dist/{chunk-kpmp5hmc.js → chunk-8mpptpn5.js} +3 -3
- package/dist/{chunk-kpmp5hmc.js.map → chunk-8mpptpn5.js.map} +1 -1
- package/dist/{chunk-5sgwnrr8.js → chunk-8n40a2sn.js} +2 -2
- package/dist/{chunk-5sgwnrr8.js.map → chunk-8n40a2sn.js.map} +1 -1
- package/dist/{chunk-wedj46ec.js → chunk-8yb9jrj5.js} +2 -2
- package/dist/{chunk-wedj46ec.js.map → chunk-8yb9jrj5.js.map} +1 -1
- package/dist/{chunk-7ka1abkd.js → chunk-9jt5qj1b.js} +2 -2
- package/dist/{chunk-7ka1abkd.js.map → chunk-9jt5qj1b.js.map} +1 -1
- package/dist/{chunk-7g3r55sj.js → chunk-9kt24ctk.js} +2 -2
- package/dist/{chunk-7g3r55sj.js.map → chunk-9kt24ctk.js.map} +1 -1
- package/dist/{chunk-gd4qydsx.js → chunk-9sbhqscs.js} +3 -3
- package/dist/{chunk-gd4qydsx.js.map → chunk-9sbhqscs.js.map} +1 -1
- package/dist/{chunk-efnerp0c.js → chunk-a119av2z.js} +2 -2
- package/dist/{chunk-efnerp0c.js.map → chunk-a119av2z.js.map} +1 -1
- package/dist/{chunk-g0t49jec.js → chunk-aj9atkwk.js} +1 -1
- package/dist/{chunk-8hr7z8cc.js → chunk-at82qczv.js} +3 -3
- package/dist/{chunk-8hr7z8cc.js.map → chunk-at82qczv.js.map} +1 -1
- package/dist/{chunk-xmrd9460.js → chunk-byv7b79h.js} +2 -2
- package/dist/{chunk-xmrd9460.js.map → chunk-byv7b79h.js.map} +1 -1
- package/dist/{chunk-3q0sbk92.js → chunk-ca5kp6cn.js} +2 -2
- package/dist/{chunk-3q0sbk92.js.map → chunk-ca5kp6cn.js.map} +1 -1
- package/dist/{chunk-hd9yny4q.js → chunk-cb7mgx75.js} +4 -4
- package/dist/{chunk-hd9yny4q.js.map → chunk-cb7mgx75.js.map} +1 -1
- package/dist/{chunk-7y2g8wbb.js → chunk-ehtj7zs2.js} +2 -2
- package/dist/{chunk-7y2g8wbb.js.map → chunk-ehtj7zs2.js.map} +1 -1
- package/dist/{chunk-69q9tk74.js → chunk-ezea9fpd.js} +2 -2
- package/dist/{chunk-69q9tk74.js.map → chunk-ezea9fpd.js.map} +1 -1
- package/dist/{chunk-kspqqyv1.js → chunk-fbk79z21.js} +2 -2
- package/dist/{chunk-kspqqyv1.js.map → chunk-fbk79z21.js.map} +1 -1
- package/dist/{chunk-vjqpcet2.js → chunk-fqndtpwm.js} +3 -3
- package/dist/{chunk-vjqpcet2.js.map → chunk-fqndtpwm.js.map} +1 -1
- package/dist/{chunk-qgka1mvf.js → chunk-fs94x6ef.js} +3 -3
- package/dist/{chunk-qgka1mvf.js.map → chunk-fs94x6ef.js.map} +1 -1
- package/dist/{chunk-a2y481gh.js → chunk-g7hz0dmk.js} +2 -2
- package/dist/{chunk-a2y481gh.js.map → chunk-g7hz0dmk.js.map} +1 -1
- package/dist/{chunk-1v1ek1ey.js → chunk-gt9ftnhn.js} +2 -2
- package/dist/{chunk-1v1ek1ey.js.map → chunk-gt9ftnhn.js.map} +1 -1
- package/dist/{chunk-x6fa13e1.js → chunk-gvr7cwxn.js} +3 -3
- package/dist/{chunk-x6fa13e1.js.map → chunk-gvr7cwxn.js.map} +1 -1
- package/dist/{chunk-vrtt8nvm.js → chunk-h0dch3vh.js} +2 -2
- package/dist/{chunk-vrtt8nvm.js.map → chunk-h0dch3vh.js.map} +1 -1
- package/dist/{chunk-jqqyj6cr.js → chunk-h1wmpa03.js} +2 -2
- package/dist/{chunk-jqqyj6cr.js.map → chunk-h1wmpa03.js.map} +1 -1
- package/dist/{chunk-agc0e46c.js → chunk-h5wjk91m.js} +2 -2
- package/dist/{chunk-agc0e46c.js.map → chunk-h5wjk91m.js.map} +1 -1
- package/dist/{chunk-x1p31k7q.js → chunk-hgwkxn0g.js} +2 -2
- package/dist/{chunk-x1p31k7q.js.map → chunk-hgwkxn0g.js.map} +1 -1
- package/dist/{chunk-bs8bq053.js → chunk-hprgj13q.js} +2 -2
- package/dist/{chunk-bs8bq053.js.map → chunk-hprgj13q.js.map} +1 -1
- package/dist/{chunk-9bjggtdt.js → chunk-jssjfvsz.js} +2 -2
- package/dist/{chunk-9bjggtdt.js.map → chunk-jssjfvsz.js.map} +1 -1
- package/dist/{chunk-ct8eh241.js → chunk-k2mpxwh2.js} +2 -2
- package/dist/{chunk-30jcs49q.js.map → chunk-k2mpxwh2.js.map} +1 -1
- package/dist/{chunk-x8by5j7p.js → chunk-ka8dzc6q.js} +2 -2
- package/dist/{chunk-x8by5j7p.js.map → chunk-ka8dzc6q.js.map} +1 -1
- package/dist/{chunk-0zf4dy4y.js → chunk-kak3vc71.js} +2 -2
- package/dist/{chunk-0zf4dy4y.js.map → chunk-kak3vc71.js.map} +1 -1
- package/dist/{chunk-g0mxdh2x.js → chunk-kvtvx64t.js} +2 -2
- package/dist/{chunk-g0mxdh2x.js.map → chunk-kvtvx64t.js.map} +1 -1
- package/dist/{chunk-6j439skq.js → chunk-m2f4n0mq.js} +2 -2
- package/dist/{chunk-6j439skq.js.map → chunk-m2f4n0mq.js.map} +1 -1
- package/dist/{chunk-0zakpsep.js → chunk-m3fbewhz.js} +3 -3
- package/dist/{chunk-0zakpsep.js.map → chunk-m3fbewhz.js.map} +1 -1
- package/dist/{chunk-ejvamy3q.js → chunk-n4kz9vft.js} +1 -1
- package/dist/{chunk-vsr08sbe.js → chunk-n84v63hn.js} +2 -2
- package/dist/{chunk-vsr08sbe.js.map → chunk-n84v63hn.js.map} +1 -1
- package/dist/{chunk-m4wagwhr.js → chunk-naj8bmj5.js} +2 -2
- package/dist/{chunk-m4wagwhr.js.map → chunk-naj8bmj5.js.map} +1 -1
- package/dist/{chunk-6xt7w9bb.js → chunk-np6vee9d.js} +3 -3
- package/dist/{chunk-6xt7w9bb.js.map → chunk-np6vee9d.js.map} +1 -1
- package/dist/{chunk-bm4hjbbk.js → chunk-pfkbhqp7.js} +2 -2
- package/dist/{chunk-bm4hjbbk.js.map → chunk-pfkbhqp7.js.map} +1 -1
- package/dist/{chunk-ngbrbeg2.js → chunk-px9h2qgv.js} +3 -3
- package/dist/{chunk-ngbrbeg2.js.map → chunk-px9h2qgv.js.map} +1 -1
- package/dist/{chunk-0dp6jvrg.js → chunk-qvn0w2rt.js} +2 -2
- package/dist/{chunk-0dp6jvrg.js.map → chunk-qvn0w2rt.js.map} +1 -1
- package/dist/{chunk-c3jg93sn.js → chunk-sh2bd09k.js} +2 -2
- package/dist/{chunk-c3jg93sn.js.map → chunk-sh2bd09k.js.map} +1 -1
- package/dist/{chunk-dqb257xv.js → chunk-sv2mv2q2.js} +2 -2
- package/dist/{chunk-dqb257xv.js.map → chunk-sv2mv2q2.js.map} +1 -1
- package/dist/{chunk-ph7cjs7e.js → chunk-t2p5n8fe.js} +2 -2
- package/dist/{chunk-ph7cjs7e.js.map → chunk-t2p5n8fe.js.map} +1 -1
- package/dist/{chunk-11yrxwkt.js → chunk-t60krz4g.js} +2 -2
- package/dist/{chunk-11yrxwkt.js.map → chunk-t60krz4g.js.map} +1 -1
- package/dist/{chunk-30zs008n.js → chunk-t6x1r5n6.js} +3 -3
- package/dist/{chunk-30zs008n.js.map → chunk-t6x1r5n6.js.map} +1 -1
- package/dist/{chunk-rgcdf5pb.js → chunk-t929a66m.js} +2 -2
- package/dist/{chunk-rgcdf5pb.js.map → chunk-t929a66m.js.map} +1 -1
- package/dist/{chunk-30jcs49q.js → chunk-ts75gcfd.js} +2 -2
- package/dist/{chunk-ct8eh241.js.map → chunk-ts75gcfd.js.map} +1 -1
- package/dist/{chunk-t17vf1ep.js → chunk-w225pkpp.js} +2 -2
- package/dist/{chunk-t17vf1ep.js.map → chunk-w225pkpp.js.map} +1 -1
- package/dist/{chunk-c71dr883.js → chunk-x185900b.js} +3 -3
- package/dist/{chunk-c71dr883.js.map → chunk-x185900b.js.map} +1 -1
- package/dist/{chunk-djhr379j.js → chunk-x2dmgge8.js} +2 -2
- package/dist/{chunk-djhr379j.js.map → chunk-x2dmgge8.js.map} +1 -1
- package/dist/{chunk-76sp9knq.js → chunk-x6a5qxpa.js} +2 -2
- package/dist/{chunk-76sp9knq.js.map → chunk-x6a5qxpa.js.map} +1 -1
- package/dist/{chunk-607nk925.js → chunk-xtpx3f5t.js} +3 -3
- package/dist/{chunk-607nk925.js.map → chunk-xtpx3f5t.js.map} +1 -1
- package/dist/{chunk-b9gwjs4r.js → chunk-y2vayxcd.js} +2 -2
- package/dist/{chunk-b9gwjs4r.js.map → chunk-y2vayxcd.js.map} +1 -1
- package/dist/{chunk-xd4kvswv.js → chunk-y56xd7sv.js} +2 -2
- package/dist/{chunk-xd4kvswv.js.map → chunk-y56xd7sv.js.map} +1 -1
- package/dist/{chunk-xkrfxcm7.js → chunk-yahabnz4.js} +3 -3
- package/dist/{chunk-xkrfxcm7.js.map → chunk-yahabnz4.js.map} +1 -1
- package/dist/{chunk-keqjdy8q.js → chunk-z3tk66vh.js} +2 -2
- package/dist/{chunk-keqjdy8q.js.map → chunk-z3tk66vh.js.map} +1 -1
- package/dist/{chunk-jkhtybga.js → chunk-zm6b938z.js} +3 -3
- package/dist/{chunk-jkhtybga.js.map → chunk-zm6b938z.js.map} +1 -1
- package/dist/{chunk-7vkqcrfn.js → chunk-zt4hybgg.js} +2 -2
- package/dist/{chunk-7vkqcrfn.js.map → chunk-zt4hybgg.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/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/index.js +9 -9
- package/dist/services/index.js.map +3 -4
- package/dist/services/queue/work.js +2 -2
- package/dist/services/queue/work.js.map +1 -1
- package/dist/services/rate-limiter/RateLimiterServiceProvider.d.ts +6 -0
- package/dist/services/rate-limiter/RateLimiterServiceProvider.d.ts.map +1 -1
- package/dist/services/rate-limiter/drivers/DatabaseRateLimiterDriver.d.ts +18 -0
- package/dist/services/rate-limiter/drivers/DatabaseRateLimiterDriver.d.ts.map +1 -1
- package/dist/stats/route-table.js +1 -1
- package/dist/support/index.js +2 -2
- package/dist/support/index.js.map +1 -1
- package/dist/vitest/index.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-1eha67ey.js +0 -10
- package/dist/chunk-rqzpxeb5.js +0 -5
- /package/dist/{chunk-mcgcgm6g.js.map → chunk-1w6ra6jc.js.map} +0 -0
- /package/dist/{chunk-tegjs0gg.js.map → chunk-2ver7cdt.js.map} +0 -0
- /package/dist/{chunk-j7swq19b.js.map → chunk-4mha212g.js.map} +0 -0
- /package/dist/{chunk-3v8b2kdr.js.map → chunk-7fbnw7e2.js.map} +0 -0
- /package/dist/{chunk-g0t49jec.js.map → chunk-aj9atkwk.js.map} +0 -0
- /package/dist/{chunk-ejvamy3q.js.map → chunk-n4kz9vft.js.map} +0 -0
package/dist/ai/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{ca as rQ,da as QZ,ea as ZZ,fa as r6,ga as e6,ha as J0,ia as r$,ja as $0,ka as Q0,la as O$,ma as Z0,na as W0,oa as X0,pa as K0}from"../chunk-
|
|
2
|
+
import{ca as rQ,da as QZ,ea as ZZ,fa as r6,ga as e6,ha as J0,ia as r$,ja as $0,ka as Q0,la as O$,ma as Z0,na as W0,oa as X0,pa as K0}from"../chunk-w225pkpp.js";import{$c as u6,Ac as IZ,Bc as wZ,Cc as LQ,Ec as BQ,Fc as kQ,Gc as AQ,Hc as RQ,Ic as EQ,Jc as TQ,Kc as jQ,Lc as xQ,Mc as IQ,Nc as wQ,Oc as fQ,Pc as qQ,Rc as q6,Sc as b6,Tc as v6,Uc as y6,Vc as h6,Wc as NJ,Xc as g6,Yc as L8,Zc as c6,_c as B8,ad as m6,bd as p6,cd as fJ,dd as D$,ed as l6,fd as i6,gd as M8,hd as d6,id as n6,jc as o$,jd as o6,kc as D8,kd as s6,lc as H8,ld as a6,mc as s$,md as S8,nd as t6,od as z$,qc as tQ,rc as iQ,sc as YJ,tc as k6,uc as h,vc as CQ,wc as _Q,yc as OQ,zc as m}from"../chunk-xtpx3f5t.js";import{$d as j6,Bd as i,Cd as a$,Fd as P8,Gd as N8,Hd as F8,Id as mJ,Jd as U8,Kd as oJ,Ld as pJ,Md as u$,Nd as C8,Od as _8,Pd as sJ,Qd as O8,Wd as QJ,Yd as $J,Zd as t$,_d as T6,ae as x6,be as I6,ce as w6,de as f6,sd as XZ,td as E,ud as x}from"../chunk-gvr7cwxn.js";import{ue as DQ}from"../chunk-g7hz0dmk.js";import"../chunk-x185900b.js";import{Si as f,qi as W8,ti as K8,yj as G8,zj as T$}from"../chunk-fqndtpwm.js";import{Aj as X8,Cj as dJ,Dj as nJ}from"../chunk-h1wmpa03.js";import{Gj as A6,Hj as R6,Ij as E6}from"../chunk-t6x1r5n6.js";import{Vj as l}from"../chunk-naj8bmj5.js";import"../chunk-jssjfvsz.js";import{al as V8,bl as z8,cl as Y8,dl as c$}from"../chunk-m3fbewhz.js";import"../chunk-x2dmgge8.js";import{jl as e,kl as JJ,zl as xJ}from"../chunk-fs94x6ef.js";import"../chunk-8476xvk9.js";import"../chunk-9jt5qj1b.js";import{qm as OZ}from"../chunk-17ewxwga.js";import"../chunk-sv2mv2q2.js";import"../chunk-qvn0w2rt.js";import{Nm as eJ}from"../chunk-ka8dzc6q.js";import"../chunk-ts75gcfd.js";import{existsSync as f8,readdirSync as V0,readFileSync as VQ}from"fs";import{isAbsolute as q8,join as AJ,relative as b8,sep as v8}from"path";var zQ="prompts.json",y8=/\{\{>\s*([\w./-]+)\s*\}\}/g,XQ=/\{\{(\w+)\}\}/g,h8=/^[\w-]+(\/[\w-]+)*$/,KQ={dir:"app/agents",shared:"prompts"},EJ={},tJ=new Map,RJ;function g8(){if(RJ===void 0){let J=AJ(eJ(),"dist","server",zQ);RJ=f8(J)?JSON.parse(VQ(J,"utf8")):null}return RJ??null}function c8(J){return J.replace(/\r?\n$/,"")}function GQ(){return EJ.cache??Bun.env.NODE_ENV==="production"}function u8(J,$){if(!h8.test(J))throw Error(`"${J}" is not a prompt name. Use letters, digits, "-" and "_", with "/" between folders.`);let Q=$.dir??EJ.dir??KQ.dir,Z=q8(Q)?Q:AJ(process.cwd(),Q),W=J.includes("/")?`${J}.md`:AJ($.shared??EJ.shared??KQ.shared,`${J}.md`);return AJ(Z,W)}function m8(J,$){let Q=u8(J,$),Z=GQ()?tJ.get(Q):void 0;if(Z!==void 0)return Z;let W=Bun.env.NODE_ENV==="production";if(W){let K=g8()?.[b8(eJ(),Q).split(v8).join("/")];if(K!==void 0)return K}let X;try{X=c8(VQ(Q,"utf8"))}catch(K){if(K.code==="ENOENT"){let G=W?` or in dist/server/${zQ}`:"";throw Error(`The prompt "${J}" does not exist (looked for ${Q}${G}).`)}throw K}if(GQ())tJ.set(Q,X);return X}function rJ(J,$,Q){if($.includes(J))throw Error(`The prompt "${J}" includes itself: ${[...$,J].join(" > ")}.`);return m8(J,Q).replace(y8,(Z,W)=>rJ(W,[...$,J],Q))}class YQ{static configure(J){EJ={...J},tJ.clear(),RJ=void 0}static render(J,$={},Q={}){return rJ(J,[],Q).replace(XQ,(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(XQ)].map((Z)=>Z[1]);return[...new Set(Q)]}}class J$ extends DQ{name="AgentJobDeadlineSweep";cron="* * * * *";async callback(){while(await m.sweep({limit:100})===100);}}var TJ=20,p8=300,l8=200;function PQ(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}: ${HQ(X.error.message,l8)}`:"failed";K.push(`failed at ${kJ(X.settledAt??X.updatedAt)} (${G})`)}if(X.summary!==void 0)K.push(`summary: ${HQ(JSON.stringify(X.summary),p8)}`);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 HQ(J,$){return J.length<=$?J:`${J.slice(0,$-1)}\u2026`}var NQ=["after_jobs","batch_key","queued","inbox","job_checkpoint"],FQ=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 i8(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,R=await this.context(J,{body:V}),T=await this.reasoning(J,{body:V})||void 0,I=await this.skills(J,{body:V})||void 0,w=await this.runTools(J,{body:V,context:R})||void 0,s=await this.usageLimits(J,{body:V,context:R})||void 0,B=await this.trailingContext(J,{body:V,context:R})||void 0,k=await this.attachmentsFor(J,Z,{body:V}),L=await this.attachmentRetention(J,{route:"stream",threadId:Z,body:V});pJ(L,this.turnAttachmentMaxAgeMs);let e$=[],T8=k&&L?k.withLifetime({next:()=>pJ(L,this.turnAttachmentMaxAgeMs),onPut:(S)=>e$.push(S)}):k,JQ=this.agent.memory?await this.memoryScopes(J,{body:V}):void 0;if(D?.cancelled)return rZ();let y=Z?new q$(this.store,Z,F,(S)=>this.reportHookFailure(S)):null,$Q=`run_${crypto.randomUUID()}`,QQ=[],ZQ,a={req:J,runId:$Q,threadId:Z,get denials(){return QQ},get turn(){return ZQ?.turn}},MJ={id:null,notified:Promise.resolve()},j=this.agent.stream({runId:$Q,messages:F,turn:X,threadId:Z,...N.parallel||z==="parallel"?{keepOtherTurnsOpen:!0}:{},...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:O,..._J.has(J)?{event:_J.get(J)}:{},...v.has(J)?{echoTurn:!0}:{},...T?{reasoning:T}:{},...I&&I.length>0?{skills:I}:{},...w?.tools&&w.tools.length>0?{tools:w.tools}:{},...w?.activeTools?{activeTools:w.activeTools}:{},...B?{trailingContext:B}:{},...s?{usageLimits:s}:{},context:R,attachments:T8,body:V,redactError:(S,t)=>this.redactError(S,t,a),onProviderRetry:(S)=>this.onProviderRetry(S,a),nonces:this.nonces,receipts:this.receipts,subject:Y,...JQ?{memory:{scopes:JQ,...this.memoryMaxTokens!==void 0?{maxTokens:this.memoryMaxTokens}:{}}}:{},...Z?{jobs:{owner:Y}}:{},...this.contextWindow!==void 0?{contextWindow:this.contextWindow}:{},...Z&&L8(this.store)?{summaryStore:this.store}:{},...this.prepareStep!==iJ.prototype.prepareStep||this.hooks?.prepareStep?{prepareStep:(S)=>this.prepareStep(S,a)}:{}});QQ=j.denials,ZQ=j;let j8=this.liveRuns.register(j,{threadId:Z,owner:Y,clientRunId:G,onEvent:(S)=>this.dispatchEvent(S,a),onInternalError:(S)=>this.reportHookFailure(S),maxRunDurationMs:this.agent.maxRunDurationMs});P=j;let SJ=_J.get(J);if(b$.set(j,{startedAt:new Date,owner:Y,turn:SJ?{...SJ.text?{text:SJ.text}:{},event:{name:SJ.name}}:vZ(X),joined:[],body:V}),y)v$.set(j,y),this.follow(j,y);if(Z)$6(this.liveRuns,Z,j.runId);let WQ=X?.files??[],x8=this.definesRetention()&&(WQ.length>0||L==="turn")?()=>this.expireTurn({scoped:k,files:WQ,made:e$,owner:Y}):null,{stored:I8,hooks:aJ}=this.persistRun(j,a,j8,y,MJ,x8);if(o.set(j,I8),cZ.set(J,{run:j,hooks:aJ}),v.has(J))v.set(J,{run:j,hooks:aJ});if(N.release)j.result().then(N.release,N.release);return J.ctx?.()?.waitUntil(aJ),j.toResponse()};try{await this.authorizeRequest(J,{route:"stream",threadId:Z,body:V});let N=await this.foreignFile([...X?.files??[],...Z?[]:U6(Q.messages)],Y);if(N)return N;if(D?.cancelled)return rZ();let F=await this.runLimitKey(J,{owner:Y,threadId:Z}),C=F===null?A:dZ(this.liveRuns).take(F,Z?`thread:${Z}`:`run:${crypto.randomUUID()}`,this.maxConcurrentRuns);if(!C)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 O;try{return O=Z?await this.withThread(Z,Y,_,{req:J,requested:K?"supersede":z,decide:!K,source:v.has(J)?"server":"client",turn:X,body:V,limitKey:F}):await _(),O}finally{let R=P,T=O?gZ.get(O):void 0;if(R)R.result().then(C,C);else if(T)T.then(C,C);else C()}}finally{if(D&&uJ.get(G)===D)uJ.delete(G)}}async withThread(J,$,Q,Z){if(Z.requested==="skip"&&CJ.has(J))return eZ(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:eZ(J)};if(V==="queue")return{waitFor:Promise.all(z.map(({run:D})=>Y(D)))};if(V==="join"){let D=z.filter(({info:U})=>this.liveRuns.mayAccess(U.runId,$));if(D.length===0)return{response:n()};let P=D[D.length-1],H=l9(Z.turn,_J.get(Z.req)),_=H?P.run.join?.(H)??null:null;if(!_)return{waitFor:Y(P.run)};return b$.get(P.run)?.joined.push(vZ(H)),{response:this.joinResponse(J,$,P.run,_,H,Q,Z)}}if(V==="parallel"){let D=Z.intake??={policy:V,waited:new WeakSet},P=z.filter(({run:N})=>!pZ(N,v$.get(N)).done&&!D.waited.has(N));if(P.length>0){for(let{run:O}of P)D.waited.add(O);let N=Promise.all(P.map(({run:O})=>pZ(O,v$.get(O)).promise)),F,C=new Promise((O)=>{F=setTimeout(O,o9)});return{waitFor:Promise.race([N,C]).finally(()=>clearTimeout(F))}}let{max:H,overflow:_}=r9(await this.maxThreadRuns(Z.req,{threadId:J,owner:$,body:Z.body}));if(z.length>=H){if(_==="queue")return{waitFor:Promise.race(z.map(({run:N})=>Y(N)))};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 U=Z.limitKey===null?A:dZ(this.liveRuns).take(Z.limitKey,`run:${crypto.randomUUID()}`,this.maxConcurrentRuns);if(!U)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:U})}}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??{},messageId:K.turn?.id,body:G?.body,joined:[...G?.joined??[]]}})});if(!bZ.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 _=mZ.get(H);if(_)return _;let U=cZ.get(K.req);if(U&&n9(H))return{kind:"answered",...U};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 _=await z.catch(()=>null),U=await V;if(U.kind==="refused"){if(_?.body?.cancel().catch(A),U.stored&&W.localId)yield{seq:++H,event:{type:"message-id",localId:W.localId,messageId:U.stored.id,message:U.stored}};let N=U.error.status===429;yield{seq:++H,event:{type:"error",error:{code:N?"rate_limited":"unknown",message:`Your message was not answered: ${U.error.message}`,retryable:N}}};return}if(!_?.body)return;try{for await(let N of BZ(_.body))yield N}finally{_.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 gZ.set(P,D),mZ.set(P,V),P}async storeUnanswered(J,$,Q){await o.get($);let Z=S8(Q.event?Q.event.text:Q.text,Q.files,Q.event);Z.turn=Z.id;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,OJ);if($.error)return u($);let Q=$.body,Z=typeof Q.threadId==="string"?Q.threadId:tZ(J,"threadId");if(!Z)return M(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 Z8(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 Z8(Z,W);let G=typeof Q.runId==="string"?Q.runId:void 0,z=G&&G!==K.runId?void 0:H6(J,Q);try{return c$(this.liveRuns.replay(K.runId,z))}catch(V){if(V instanceof WJ)return M(410,{code:V.code,message:V.message,oldestSeq:V.oldest});if(V instanceof FJ)return M(404,{code:V.code,message:V.message});throw V}}async watch(J=new f){let $=await XJ(J,OJ);if($.error)return u($);let Q=$.body,Z=typeof Q.threadId==="string"?Q.threadId:tZ(J,"threadId");if(!Z)return M(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 M(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=J6(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=z8(P);let H=(U)=>{if(!X.mayAccess(U,W))return;try{P.enqueue(new TextEncoder().encode(V8({seq:++V,event:{type:"run-start",runId:U,threadId:Z}}))),z?.touch()}catch{Y()}};G=H;let _=K.get(Z);if(!_)_=new Set,K.set(Z,_);_.add(H);for(let{runId:U}of X.running({threadId:Z}))H(U)},cancel(){Y()}});return J.rawRequest?.signal?.addEventListener("abort",Y,{once:!0}),new Response(D,{status:200,headers:Y8()})}async stop(J=new f){let $=await XJ(J,OJ);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,OJ);if(Q.error)return u(Q);let{sdp:Z,threadId:W,pushToTalk:X}=Q.body;if(typeof Z!=="string"||!Z.trimStart().startsWith("v="))return M(400,{code:"invalid_request",message:"`sdp` must be the browser's SDP offer."});let K=lJ(Q.body,C6),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(C)=>{if(C!==void 0)console.error("[gemi/ai] a voice session could not start.",C);if(D)await $.realtime.hangup(D).catch((O)=>{console.error("[gemi/ai] a voice call that failed to start could not be hung up.",O)});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:E(),transcription:{usage:E(),seconds:0},transcript:[],requests:[],toolCalls:[],errors:[]})}catch(O){console.error("[gemi/ai] a voice session's onEnd threw.",O)}},H=V.threadId??G;if(!H)return await P(void 0),M(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(C){throw await P(void 0),C}let _=crypto.randomUUID(),U=V.tools??[];try{if(V.mcp)U=[...U,...await L$(V.mcp,{user:z,sessionId:_})]}catch(C){return await P(C),M(500,{code:"voice_unavailable",message:"Voice isn't available right now."})}let N={...V.session,tools:[...HJ($.delegate),...V.session?.tools??[],...U.map((C)=>C.tool)],...X===!0?{turnDetection:null}:{}},F;try{F=await $.realtime.createCall({sdp:Z,session:N,safetyIdentifier:V.safetyIdentifier})}catch(C){await P(C);let O=C instanceof r$&&C.code==="rate_limited";return M(O?429:502,{code:"voice_unavailable",message:"Voice isn't available right now."})}D=F.callId;try{await this.voiceStore.create({id:_,callId:F.callId,threadId:H,owner:await this.runOwner(J),body:K,startedAt:Y});let{threadId:C,session:O,safetyIdentifier:R,mcp:T,tools:I,...w}=V;return{sessionId:d.start({...w,tools:U,controller:this.constructor,threadId:H,user:z,body:K,call:{realtime:$.realtime,callId:F.callId},sessionId:_,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(C){return await P(C),M(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,OJ);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 M(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 M(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=W6($.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=K6(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=(I)=>this.fileOwners.record(I,{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 _=await this.attachmentDestination(Q,J,P),U=_6(_,$.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=U!=="provider"&&!N;if(F){if(U==="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()`.');O6()}if(U==="provider"||!N){let I=await nZ(this.agent.provider,Q);await D(I);let w={fileId:I,name:Z,mimeType:W,size:Q.size,destination:"provider"};if(F)w.downgraded="no_scope";return w}let C=U8(),O=await this.attachmentStorage.put({name:C8(C,Z),body:Q,contentType:W}),R=U==="both"?await nZ(this.agent.provider,Q):void 0;if(R)await D(R);let T={id:C,scopeKey:N.key,fileId:R,objectName:O,name:Z,mimeType:W,size:Q.size,createdAt:new Date().toISOString(),destination:U,...Y};return await this.attachments.put(N,T),{fileId:R,attachmentId:C,name:Z,mimeType:W,size:Q.size,destination:U}}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 F6()}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:M8(Q)});return}case"awaiting-input":await this.onAwaitingInput(J.pending,$);return;case"error":await this.onError(P8(J.error),$);return;default:return}}async readThread(J,$={}){let Z=await($.scope===null||$.scope===void 0?this.store:Q8(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 jZ($,Z),X=W.messages,K=[],G=new Map(W.settled.map((z)=>[z.id,z]));if(S6(X)||Q)try{let z=await fZ(X,{threadId:J,store:m.store,isRunLive:Z,outputSchemaFor:(V)=>this.toolNamed(V)?.outputSchema,modelOutputFor:(V,Y)=>B8(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 qZ(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 PQ(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(()=>B6(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"],Z6=["text","files","toolResults"];function lJ(J,$=k8(J)?i$:[...i$,...Z6]){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 W6(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 nZ(J,$){try{return await J.upload($)}catch(Q){if(Q instanceof O8&&X6.has(Q.status))throw new E8($J(Q).message);throw Q}}var X6=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 K6(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 ${oZ($.size)}; the limit is ${oZ(W)}.`};if(X&&X.length>0&&!X.some((K)=>G6(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 G6(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 oZ(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 E8 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(!V6(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 sZ($);let W;try{let K=await z6(Q,$);if(K===null)return sZ($);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 V6(J){return K8(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 sZ(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 M(J,{...nJ(X8(J),Q,J),code:$})}function u(J){if(J.status===413)return LJ(413,J.code??"body_too_large",J.error??"");return M(J.status??400,{code:J.code??"invalid_request",message:J.error})}function k8(J){return Boolean(J.turn)&&typeof J.turn==="object"}function Y6(J){let $=k8(J)?J.turn:J,Q={};if(typeof $.text==="string")Q.text=$.text;if(Array.isArray($.files)){let Z=D6($.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>aZ)return{error:`turn.localId is longer than ${aZ} characters.`};Q.localId=Z}return{turn:Q}}var aZ=200;function D6(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 H6(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 tZ(J,$){let Q=J?.search?.get($);return typeof Q==="string"?Q:void 0}function P6(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 rZ(){return M(409,{code:"stopped",message:"The turn was stopped before it started."})}function N6(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"||!u9.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 eZ(J){return M(409,{code:A8,message:`Thread ${J} has a run going, and this turn was not to interrupt it.`})}function n(){return M(403,nJ("permission","This run belongs to someone else.",403))}function F6(){return M(403,nJ("permission","A file in this turn was uploaded by someone else.",403))}function U6(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 C6=["sdp","threadId","pushToTalk"];function g$(){return M(404,{code:"voice_not_enabled",message:"This agent has no voice: set `voice` on its controller."})}function M(J,$){return new Response(JSON.stringify({error:$}),{status:J,headers:{"Content-Type":"application/json"}})}function _6(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 J8=!1;function O6(){if(J8)return;J8=!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 L6=2147483647;function B6(J,$){let Q=J.then(()=>{},()=>{});if(!($<=L6))return Q;let Z,W=new Promise((X)=>{Z=setTimeout(X,$)});return Promise.race([Q,W]).finally(()=>clearTimeout(Z))}var $8=!1;function M6(J){if($8||Bun.env.NODE_ENV!=="production")return;if(!(J instanceof o$))return;$8=!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 S6(J){return J.some(($)=>$.content.some((Q)=>Q.type==="tool-result"&&Q.status==="running"))}function Q8(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 Z8(J,$=!1){if($)return new Response(null,{status:204});return M(404,{code:"no_live_run",message:`No run in progress for thread ${J} in this process.`})}export{f6 as windowMessages,HJ as voiceTools,T6 as turnStarts,J0 as toRealtimeUsage,$9 as toAgentTools,E6 as supportsStrict,j6 as splitTurns,c6 as settleSummaries,R6 as s,a$ as redactError,t6 as parsePartialJson,x6 as messageSize,YJ as measureUsage,L$ as mcpVoiceTools,R$ as liveRuns,NJ as keepSummary,Q0 as isCallNotFound,t$ as injectedMessageIds,z$ as generate,H9 as evalChain,Q6 as defineAgentHooks,M$ as defaultVoiceStore,m6 as defaultUsageLimitStore,g6 as defaultSummaryStore,a6 as defaultPromptCacheKey,s$ as defaultNonceStore,E$ as defaultFileOwners,sJ as defaultAttachmentStore,w$ as defaultAgentStore,hJ as VoiceHangup,d as VoiceBridge,k6 as Usage,D$ as ToolNamespace,i as ToolError,o6 as ToolArgumentsTooLongError,l6 as Skill,oJ as ScopedAttachments,i6 as SKILLS_NAMESPACE,x$ as RedisReceiptStore,D8 as RedisNonceStore,r6 as RealtimeSideband,r$ as RealtimeRequestError,$0 as RealtimeClient,YQ as Prompt,H8 as PrismaNonceStore,p6 as PendingEscalation,Z0 as OpenAIProvider,F$ as OpenAIImageProvider,B$ as MemoryVoiceSessionStore,u6 as MemoryUsageLimitStore,h6 as MemorySummaryStore,j$ as MemoryReceiptStore,o$ as MemoryNonceStore,gJ as MemoryLiveRuns,cJ as MemoryFileOwners,vJ as MemoryCircuitStore,_8 as MemoryAttachmentStore,UJ as MemoryAgentStore,CQ as MemoryAgentJobStore,qQ as MEMORY_NAMESPACE,FJ as LiveRunNotFoundError,OQ as JobsRequireThreadError,_Q as JobHandle,A6 as JSONSchemaError,F8 as InvalidAttachmentScopeError,TQ as InMemoryAgentMemoryStore,qJ as ImageRequestError,bJ as ImageProvider,H$ as ImageModel,WJ as FrameCursorEvictedError,DJ as FallbackProvider,wQ as FakeAgentMemoryStore,wJ as Eval,S$ as DatabaseAgentStore,Z$ as DatabaseAgentMemoryStore,$$ as DatabaseAgentJobStore,e6 as DEFAULT_TRANSCRIPTION_MODEL,kQ as DEFAULT_MEMORY_MAX_TOKENS,fQ as DEFAULT_MEMORY_LIMITS,q6 as DEFAULT_MAX_SUMMARY_TOKENS,d6 as DEFAULT_MAX_RUN_DURATION_MS,LQ as DEFAULT_JOB_DEADLINE_MS,TJ as DEFAULT_JOBS_CONTEXT_MAX,PJ as DEFAULT_DELEGATE_NAME,I6 as DEFAULT_CONTEXT_WINDOW_STEP,w6 as DEFAULT_CONTEXT_WINDOW_NOTE,b6 as DEFAULT_COMPACT_TRIGGER_TOKENS,v6 as DEFAULT_COMPACT_INSTRUCTIONS,y6 as COMPACT_SUMMARY_HEADER,K0 as AzureOpenAIProvider,U$ as AzureOpenAIImageProvider,X0 as AzureAnthropicProvider,N8 as AttachmentNotFoundError,W0 as AnthropicProvider,KJ as AgentTurnError,fJ as AgentTool,n6 as AgentRunError,O$ as AgentProvider,jQ as AgentMemoryRefusedError,xQ as AgentMemoryConflictError,IQ as AgentMemories,m as AgentJobs,J$ as AgentJobDeadlineSweep,BQ as AgentJob,iJ as AgentController,s6 as Agent};
|
|
337
337
|
|
|
338
|
-
//# debugId=
|
|
338
|
+
//# debugId=FA938D4405128AF164756E2164756E21
|