gemi 0.171.0 → 0.173.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (227) hide show
  1. package/dist/ai/index.js +2 -2
  2. package/dist/ai/index.js.map +1 -1
  3. package/dist/app/App.d.ts +10 -0
  4. package/dist/app/App.d.ts.map +1 -1
  5. package/dist/app/index.js +1 -1
  6. package/dist/bin/gemi.js +4 -1
  7. package/dist/bin/gemi.js.map +3 -3
  8. package/dist/bun/plugin.js +1 -1
  9. package/dist/bun/preload.js +1 -1
  10. package/dist/{chunk-thbs63gy.js → chunk-05k9gmr9.js} +1 -1
  11. package/dist/{chunk-fb77hwk0.js → chunk-0v46hne6.js} +3 -3
  12. package/dist/{chunk-fb77hwk0.js.map → chunk-0v46hne6.js.map} +1 -1
  13. package/dist/{chunk-mm45shzv.js → chunk-1hhwqx50.js} +2 -2
  14. package/dist/{chunk-mm45shzv.js.map → chunk-1hhwqx50.js.map} +1 -1
  15. package/dist/chunk-1pvfgfhj.js +117 -0
  16. package/dist/{chunk-3qtn3zjt.js.map → chunk-1pvfgfhj.js.map} +8 -8
  17. package/dist/chunk-2mvz2pjr.js +5 -0
  18. package/dist/{chunk-f4nanvkm.js.map → chunk-2mvz2pjr.js.map} +1 -1
  19. package/dist/{chunk-q3511sb5.js → chunk-2p7zph5z.js} +2 -2
  20. package/dist/{chunk-q3511sb5.js.map → chunk-2p7zph5z.js.map} +1 -1
  21. package/dist/{chunk-c46vhvk4.js → chunk-3esnjxv9.js} +2 -2
  22. package/dist/{chunk-c46vhvk4.js.map → chunk-3esnjxv9.js.map} +1 -1
  23. package/dist/{chunk-5n21z4n8.js → chunk-4dnr1vg7.js} +2 -2
  24. package/dist/{chunk-5n21z4n8.js.map → chunk-4dnr1vg7.js.map} +1 -1
  25. package/dist/chunk-4hhvaa7a.js +5 -0
  26. package/dist/{chunk-1h6g1hkg.js.map → chunk-4hhvaa7a.js.map} +3 -3
  27. package/dist/{chunk-df2zeevj.js → chunk-5yvy70d7.js} +2 -2
  28. package/dist/{chunk-df2zeevj.js.map → chunk-5yvy70d7.js.map} +1 -1
  29. package/dist/{chunk-31np60bx.js → chunk-6016sfy5.js} +2 -2
  30. package/dist/{chunk-31np60bx.js.map → chunk-6016sfy5.js.map} +1 -1
  31. package/dist/{chunk-sdn3dmpp.js → chunk-699j2epd.js} +4 -4
  32. package/dist/{chunk-sdn3dmpp.js.map → chunk-699j2epd.js.map} +1 -1
  33. package/dist/{chunk-gwphn604.js → chunk-6rh3brnr.js} +3 -3
  34. package/dist/{chunk-gwphn604.js.map → chunk-6rh3brnr.js.map} +1 -1
  35. package/dist/{chunk-s71e6k9m.js → chunk-6srzhv88.js} +3 -3
  36. package/dist/{chunk-s71e6k9m.js.map → chunk-6srzhv88.js.map} +1 -1
  37. package/dist/{chunk-0wet87jm.js → chunk-6vmc8eak.js} +2 -2
  38. package/dist/{chunk-0wet87jm.js.map → chunk-6vmc8eak.js.map} +1 -1
  39. package/dist/{chunk-rpdekb8t.js → chunk-7gc1jp2z.js} +2 -2
  40. package/dist/{chunk-rpdekb8t.js.map → chunk-7gc1jp2z.js.map} +1 -1
  41. package/dist/{chunk-y3s05q6b.js → chunk-7mp369vg.js} +2 -2
  42. package/dist/{chunk-y3s05q6b.js.map → chunk-7mp369vg.js.map} +1 -1
  43. package/dist/{chunk-44y62yav.js → chunk-8tzmat5s.js} +3 -3
  44. package/dist/{chunk-44y62yav.js.map → chunk-8tzmat5s.js.map} +1 -1
  45. package/dist/{chunk-sv86v56c.js → chunk-97aeny79.js} +3 -3
  46. package/dist/{chunk-sv86v56c.js.map → chunk-97aeny79.js.map} +1 -1
  47. package/dist/{chunk-978pc27j.js → chunk-9bcsfce4.js} +2 -2
  48. package/dist/{chunk-978pc27j.js.map → chunk-9bcsfce4.js.map} +1 -1
  49. package/dist/{chunk-sp77zwpn.js → chunk-9pet8zmd.js} +2 -2
  50. package/dist/{chunk-sp77zwpn.js.map → chunk-9pet8zmd.js.map} +1 -1
  51. package/dist/{chunk-4mtqbcc5.js → chunk-9r4rvyfr.js} +2 -2
  52. package/dist/{chunk-4mtqbcc5.js.map → chunk-9r4rvyfr.js.map} +1 -1
  53. package/dist/{chunk-vfvjfw5k.js → chunk-9zcsshgb.js} +2 -2
  54. package/dist/{chunk-vfvjfw5k.js.map → chunk-9zcsshgb.js.map} +1 -1
  55. package/dist/{chunk-krdq5s4y.js → chunk-b1grj1t0.js} +2 -2
  56. package/dist/{chunk-krdq5s4y.js.map → chunk-b1grj1t0.js.map} +1 -1
  57. package/dist/{chunk-q788x8pm.js → chunk-bs8mrewm.js} +2 -2
  58. package/dist/{chunk-q788x8pm.js.map → chunk-bs8mrewm.js.map} +1 -1
  59. package/dist/{chunk-8b9ks729.js → chunk-bsnp7h5w.js} +3 -3
  60. package/dist/{chunk-8b9ks729.js.map → chunk-bsnp7h5w.js.map} +1 -1
  61. package/dist/{chunk-z4dhd5pk.js → chunk-c9q856yk.js} +2 -2
  62. package/dist/{chunk-z4dhd5pk.js.map → chunk-c9q856yk.js.map} +1 -1
  63. package/dist/{chunk-2v7wq01w.js → chunk-cx05t002.js} +2 -2
  64. package/dist/{chunk-2v7wq01w.js.map → chunk-cx05t002.js.map} +1 -1
  65. package/dist/{chunk-p56zntmt.js → chunk-d084zwp9.js} +3 -3
  66. package/dist/{chunk-p56zntmt.js.map → chunk-d084zwp9.js.map} +1 -1
  67. package/dist/{chunk-6t1t7h05.js → chunk-d7a79eqm.js} +2 -2
  68. package/dist/{chunk-6t1t7h05.js.map → chunk-d7a79eqm.js.map} +1 -1
  69. package/dist/{chunk-aj1jrwwh.js → chunk-df0nx9d6.js} +2 -2
  70. package/dist/{chunk-aj1jrwwh.js.map → chunk-df0nx9d6.js.map} +1 -1
  71. package/dist/{chunk-hwpp9b7f.js → chunk-dqj22m1r.js} +2 -2
  72. package/dist/{chunk-9wcv7e1a.js.map → chunk-dqj22m1r.js.map} +1 -1
  73. package/dist/chunk-dxtry1gh.js +10 -0
  74. package/dist/{chunk-212m5z3p.js.map → chunk-dxtry1gh.js.map} +3 -3
  75. package/dist/{chunk-kbw6y0ag.js → chunk-erwawm84.js} +2 -2
  76. package/dist/{chunk-kbw6y0ag.js.map → chunk-erwawm84.js.map} +1 -1
  77. package/dist/{chunk-9ft0ayhf.js → chunk-eykb93pv.js} +2 -2
  78. package/dist/{chunk-9ft0ayhf.js.map → chunk-eykb93pv.js.map} +1 -1
  79. package/dist/{chunk-8hfyscnn.js → chunk-f1my4jah.js} +1 -1
  80. package/dist/{chunk-drwjwtmj.js → chunk-f4wkm07x.js} +2 -2
  81. package/dist/{chunk-drwjwtmj.js.map → chunk-f4wkm07x.js.map} +1 -1
  82. package/dist/{chunk-4tt14jnx.js → chunk-fqw81xgw.js} +2 -2
  83. package/dist/{chunk-4tt14jnx.js.map → chunk-fqw81xgw.js.map} +1 -1
  84. package/dist/{chunk-hgpvfhtp.js → chunk-g3m7t5zc.js} +1 -1
  85. package/dist/{chunk-0wk992a5.js → chunk-h041bq3j.js} +2 -2
  86. package/dist/{chunk-0wk992a5.js.map → chunk-h041bq3j.js.map} +1 -1
  87. package/dist/{chunk-sxf94q13.js → chunk-h3jb2g2g.js} +2 -2
  88. package/dist/{chunk-sxf94q13.js.map → chunk-h3jb2g2g.js.map} +1 -1
  89. package/dist/{chunk-vnk4vaer.js → chunk-hr9twa8v.js} +3 -3
  90. package/dist/{chunk-vnk4vaer.js.map → chunk-hr9twa8v.js.map} +1 -1
  91. package/dist/{chunk-21hppqtb.js → chunk-jhn1h70n.js} +2 -2
  92. package/dist/{chunk-21hppqtb.js.map → chunk-jhn1h70n.js.map} +1 -1
  93. package/dist/{chunk-wp9hw3we.js → chunk-jv48eg0a.js} +2 -2
  94. package/dist/{chunk-wp9hw3we.js.map → chunk-jv48eg0a.js.map} +1 -1
  95. package/dist/{chunk-3682hkq0.js → chunk-k9ndr16q.js} +2 -2
  96. package/dist/{chunk-3682hkq0.js.map → chunk-k9ndr16q.js.map} +1 -1
  97. package/dist/{chunk-4qpyz627.js → chunk-kknybxbv.js} +2 -2
  98. package/dist/{chunk-4qpyz627.js.map → chunk-kknybxbv.js.map} +1 -1
  99. package/dist/{chunk-a9frf7ym.js → chunk-ksgeqtcv.js} +2 -2
  100. package/dist/{chunk-a9frf7ym.js.map → chunk-ksgeqtcv.js.map} +1 -1
  101. package/dist/{chunk-ta2wsjz6.js → chunk-kxgxeead.js} +2 -2
  102. package/dist/{chunk-ta2wsjz6.js.map → chunk-kxgxeead.js.map} +1 -1
  103. package/dist/{chunk-xkas0yp8.js → chunk-m0nvysa5.js} +3 -3
  104. package/dist/{chunk-xkas0yp8.js.map → chunk-m0nvysa5.js.map} +1 -1
  105. package/dist/{chunk-fcbgshf5.js → chunk-m250ejpg.js} +2 -2
  106. package/dist/{chunk-fcbgshf5.js.map → chunk-m250ejpg.js.map} +1 -1
  107. package/dist/{chunk-embwksec.js → chunk-mbshptjq.js} +2 -2
  108. package/dist/{chunk-embwksec.js.map → chunk-mbshptjq.js.map} +1 -1
  109. package/dist/{chunk-m6sj1q1q.js → chunk-nfj6k1a6.js} +2 -2
  110. package/dist/{chunk-m6sj1q1q.js.map → chunk-nfj6k1a6.js.map} +1 -1
  111. package/dist/{chunk-2xtkh8bh.js → chunk-pbc3w7mq.js} +2 -2
  112. package/dist/{chunk-2xtkh8bh.js.map → chunk-pbc3w7mq.js.map} +1 -1
  113. package/dist/{chunk-ztfkmpk5.js → chunk-psmwxtf5.js} +2 -2
  114. package/dist/{chunk-ztfkmpk5.js.map → chunk-psmwxtf5.js.map} +1 -1
  115. package/dist/{chunk-777v6242.js → chunk-qfqn7rz8.js} +1 -1
  116. package/dist/chunk-r1n2fkfz.js +4 -0
  117. package/dist/chunk-r1n2fkfz.js.map +10 -0
  118. package/dist/{chunk-ys8nk9ga.js → chunk-r22svpab.js} +3 -3
  119. package/dist/{chunk-ys8nk9ga.js.map → chunk-r22svpab.js.map} +1 -1
  120. package/dist/{chunk-jxx9mctk.js → chunk-rjsd8f8q.js} +2 -2
  121. package/dist/{chunk-jxx9mctk.js.map → chunk-rjsd8f8q.js.map} +1 -1
  122. package/dist/{chunk-k87tqe29.js → chunk-sgarq1q9.js} +2 -2
  123. package/dist/{chunk-k87tqe29.js.map → chunk-sgarq1q9.js.map} +1 -1
  124. package/dist/{chunk-jd079awh.js → chunk-sjg5g92s.js} +2 -2
  125. package/dist/{chunk-jd079awh.js.map → chunk-sjg5g92s.js.map} +1 -1
  126. package/dist/{chunk-3rp908gn.js → chunk-srvsz7vm.js} +1 -1
  127. package/dist/{chunk-gjwf07hy.js → chunk-tbf76adx.js} +2 -2
  128. package/dist/{chunk-gjwf07hy.js.map → chunk-tbf76adx.js.map} +1 -1
  129. package/dist/{chunk-17272ccy.js → chunk-tzne38pa.js} +3 -3
  130. package/dist/{chunk-17272ccy.js.map → chunk-tzne38pa.js.map} +1 -1
  131. package/dist/{chunk-m950vw4c.js → chunk-vpmbynke.js} +2 -2
  132. package/dist/{chunk-m950vw4c.js.map → chunk-vpmbynke.js.map} +1 -1
  133. package/dist/{chunk-s4fb4njt.js → chunk-vzz91xsm.js} +2 -2
  134. package/dist/{chunk-s4fb4njt.js.map → chunk-vzz91xsm.js.map} +1 -1
  135. package/dist/{chunk-5nz46dyw.js → chunk-w65gftzm.js} +2 -2
  136. package/dist/{chunk-5nz46dyw.js.map → chunk-w65gftzm.js.map} +1 -1
  137. package/dist/{chunk-g1jfc50d.js → chunk-w8hre8gz.js} +2 -2
  138. package/dist/{chunk-g1jfc50d.js.map → chunk-w8hre8gz.js.map} +1 -1
  139. package/dist/{chunk-wt1yzzbw.js → chunk-x2e20w8g.js} +1 -1
  140. package/dist/{chunk-9wcv7e1a.js → chunk-xe126csw.js} +2 -2
  141. package/dist/{chunk-hwpp9b7f.js.map → chunk-xe126csw.js.map} +1 -1
  142. package/dist/{chunk-0q65jzhv.js → chunk-xtj7cgsx.js} +2 -2
  143. package/dist/{chunk-0q65jzhv.js.map → chunk-xtj7cgsx.js.map} +1 -1
  144. package/dist/chunk-yeaftz5a.js +24 -0
  145. package/dist/{chunk-376s9rbe.js.map → chunk-yeaftz5a.js.map} +3 -3
  146. package/dist/{chunk-9akefv1y.js → chunk-ykd2ayw8.js} +2 -2
  147. package/dist/{chunk-9akefv1y.js.map → chunk-ykd2ayw8.js.map} +1 -1
  148. package/dist/{chunk-z5g56ds0.js → chunk-ywcfezjq.js} +2 -2
  149. package/dist/{chunk-z5g56ds0.js.map → chunk-ywcfezjq.js.map} +1 -1
  150. package/dist/chunk-z58zh5gm.js +58 -0
  151. package/dist/{chunk-eq3xexqp.js.map → chunk-z58zh5gm.js.map} +3 -3
  152. package/dist/{chunk-ecdjbd2w.js → chunk-zdpxwpc3.js} +3 -3
  153. package/dist/{chunk-ecdjbd2w.js.map → chunk-zdpxwpc3.js.map} +1 -1
  154. package/dist/client/Head.d.ts.map +1 -1
  155. package/dist/client/index.js +20 -2
  156. package/dist/client/index.js.map +1 -1
  157. package/dist/config/index.js +1 -1
  158. package/dist/console/run.js +2 -2
  159. package/dist/console/run.js.map +1 -1
  160. package/dist/container/index.js +2 -2
  161. package/dist/container/index.js.map +1 -1
  162. package/dist/database/index.js +2 -2
  163. package/dist/database/index.js.map +1 -1
  164. package/dist/email/index.js +2 -2
  165. package/dist/email/index.js.map +1 -1
  166. package/dist/facades/Meta.d.ts +10 -0
  167. package/dist/facades/Meta.d.ts.map +1 -1
  168. package/dist/facades/index.js +2 -2
  169. package/dist/facades/index.js.map +1 -1
  170. package/dist/foundation/index.js +2 -2
  171. package/dist/foundation/index.js.map +1 -1
  172. package/dist/http/HttpRequest.d.ts +1 -0
  173. package/dist/http/HttpRequest.d.ts.map +1 -1
  174. package/dist/http/Metadata.d.ts +15 -0
  175. package/dist/http/Metadata.d.ts.map +1 -1
  176. package/dist/http/contentDisposition.d.ts +1 -1
  177. package/dist/http/contentDisposition.d.ts.map +1 -1
  178. package/dist/http/index.js +2 -2
  179. package/dist/http/index.js.map +1 -1
  180. package/dist/http/requestContext.d.ts +1 -0
  181. package/dist/http/requestContext.d.ts.map +1 -1
  182. package/dist/i18n/dictionaryRuntime.js +2 -2
  183. package/dist/i18n/dictionaryRuntime.js.map +1 -1
  184. package/dist/i18n/index.js +2 -2
  185. package/dist/i18n/index.js.map +1 -1
  186. package/dist/kernel/index.js +2 -2
  187. package/dist/kernel/index.js.map +1 -1
  188. package/dist/orm/index.js +2 -2
  189. package/dist/orm/index.js.map +1 -1
  190. package/dist/probe/index.js +2 -2
  191. package/dist/probe/index.js.map +1 -1
  192. package/dist/server/devFetch.d.ts.map +1 -1
  193. package/dist/server/httpProd.d.ts.map +1 -1
  194. package/dist/server/index.js +2 -2
  195. package/dist/server/index.js.map +1 -1
  196. package/dist/services/index.js +2 -2
  197. package/dist/services/index.js.map +1 -1
  198. package/dist/services/queue/work.js +2 -2
  199. package/dist/services/queue/work.js.map +1 -1
  200. package/dist/services/router/DomainRouter.d.ts +21 -0
  201. package/dist/services/router/DomainRouter.d.ts.map +1 -1
  202. package/dist/services/router/ViewRouteDispatcher.d.ts +8 -0
  203. package/dist/services/router/ViewRouteDispatcher.d.ts.map +1 -1
  204. package/dist/services/router/config.d.ts +52 -3
  205. package/dist/services/router/config.d.ts.map +1 -1
  206. package/dist/services/router/globalMiddleware.d.ts.map +1 -1
  207. package/dist/services/router/staticCache.d.ts +8 -0
  208. package/dist/services/router/staticCache.d.ts.map +1 -1
  209. package/dist/stats/route-table.js +1 -1
  210. package/dist/support/index.js +2 -2
  211. package/dist/support/index.js.map +1 -1
  212. package/dist/vitest/index.js +1 -1
  213. package/package.json +1 -1
  214. package/dist/chunk-1h6g1hkg.js +0 -5
  215. package/dist/chunk-212m5z3p.js +0 -10
  216. package/dist/chunk-376s9rbe.js +0 -24
  217. package/dist/chunk-3qtn3zjt.js +0 -117
  218. package/dist/chunk-743ympvp.js +0 -4
  219. package/dist/chunk-743ympvp.js.map +0 -10
  220. package/dist/chunk-eq3xexqp.js +0 -58
  221. package/dist/chunk-f4nanvkm.js +0 -5
  222. /package/dist/{chunk-thbs63gy.js.map → chunk-05k9gmr9.js.map} +0 -0
  223. /package/dist/{chunk-8hfyscnn.js.map → chunk-f1my4jah.js.map} +0 -0
  224. /package/dist/{chunk-hgpvfhtp.js.map → chunk-g3m7t5zc.js.map} +0 -0
  225. /package/dist/{chunk-777v6242.js.map → chunk-qfqn7rz8.js.map} +0 -0
  226. /package/dist/{chunk-3rp908gn.js.map → chunk-srvsz7vm.js.map} +0 -0
  227. /package/dist/{chunk-wt1yzzbw.js.map → chunk-x2e20w8g.js.map} +0 -0
package/dist/ai/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  // @bun
2
- import{$b as $8,$c as J6,Ac as t9,Bc as r9,Cc as C8,Ec as _8,Fc as T8,Gc as A8,Hc as R8,Ic as E8,Jc as j8,Kc as k8,Lc as x8,Mc as q8,Nc as I8,Oc as w8,Pc as b8,Rc as w,Sc as $9,Tc as s,Uc as T,Vc as Z8,Wc as s0,Xc as a0,Yb as J8,Yc as t0,Zb as NQ,Zc as r0,_b as UQ,_c as e0,ad as $6,bd as Q6,cc as xJ,cd as Z6,dc as S,dd as W6,ec as A,ed as K6,fd as DJ,gc as t8,gd as X6,hc as d8,hd as AQ,ic as KJ,id as Y6,jc as o0,jd as RQ,kc as g,kd as G6,lc as Q8,ld as EJ,mc as LQ,md as B$,nc as OQ,nd as V6,oc as CQ,od as H6,pc as m,pd as EQ,qc as _Q,qd as z6,rc as oJ,rd as D6,sc as MQ,sd as B6,tc as SQ,td as z$,uc as sJ,vc as U8,wc as L8,yc as O8,zc as v}from"../chunk-2xtkh8bh.js";import{Ld as D8}from"../chunk-9aj6eavs.js";import"../chunk-gjwf07hy.js";import{$h as i0,Gh as zQ,Hi as FQ,Jh as BQ,Ki as p$,Oi as PQ,Zh as _9,_h as d0,ai as n0,bi as q}from"../chunk-ys8nk9ga.js";import{Pi as DQ,Ri as iJ,Si as nJ}from"../chunk-5n21z4n8.js";import{$i as h}from"../chunk-1h6g1hkg.js";import"../chunk-jxx9mctk.js";import"../chunk-6t1t7h05.js";import"../chunk-a9frf7ym.js";import{ck as n,dk as o,rk as SJ}from"../chunk-gwphn604.js";import"../chunk-m950vw4c.js";import"../chunk-vfvjfw5k.js";import{el as c9}from"../chunk-8b9ks729.js";import"../chunk-0q65jzhv.js";import"../chunk-9akefv1y.js";import{xl as eJ}from"../chunk-rpdekb8t.js";import"../chunk-9wcv7e1a.js";import{existsSync as wQ,readdirSync as P6,readFileSync as V8}from"fs";import{isAbsolute as bQ,join as UJ,relative as fQ,sep as vQ}from"path";var H8="prompts.json",yQ=/\{\{>\s*([\w./-]+)\s*\}\}/g,X8=/\{\{(\w+)\}\}/g,hQ=/^[\w-]+(\/[\w-]+)*$/,Y8={dir:"app/agents",shared:"prompts"},OJ={},tJ=new Map,LJ;function gQ(){if(LJ===void 0){let J=UJ(eJ(),"dist","server",H8);LJ=wQ(J)?JSON.parse(V8(J,"utf8")):null}return LJ??null}function uQ(J){return J.replace(/\r?\n$/,"")}function G8(){return OJ.cache??Bun.env.NODE_ENV==="production"}function cQ(J){if(!hQ.test(J))throw Error(`"${J}" is not a prompt name. Use letters, digits, "-" and "_", with "/" between folders.`);let $=OJ.dir??Y8.dir,Q=bQ($)?$:UJ(process.cwd(),$),Z=J.includes("/")?`${J}.md`:UJ(OJ.shared??Y8.shared,`${J}.md`);return UJ(Q,Z)}function mQ(J){let $=cQ(J),Q=G8()?tJ.get($):void 0;if(Q!==void 0)return Q;let Z=Bun.env.NODE_ENV==="production";if(Z){let K=gQ()?.[fQ(eJ(),$).split(vQ).join("/")];if(K!==void 0)return K}let W;try{W=uQ(V8($,"utf8"))}catch(K){if(K.code==="ENOENT"){let X=Z?` or in dist/server/${H8}`:"";throw Error(`The prompt "${J}" does not exist (looked for ${$}${X}).`)}throw K}if(G8())tJ.set($,W);return W}function rJ(J,$){if($.includes(J))throw Error(`The prompt "${J}" includes itself: ${[...$,J].join(" > ")}.`);return mQ(J).replace(yQ,(Q,Z)=>rJ(Z,[...$,J]))}class z8{static configure(J){OJ={...J},tJ.clear(),LJ=void 0}static render(J,$={}){return rJ(J,[]).replace(X8,(Q,Z)=>{if(!Object.hasOwn($,Z))throw Error(`The prompt "${J}" has no value for {{${Z}}}.`);return String($[Z])})}static placeholders(J){let $=[...rJ(J,[]).matchAll(X8)].map((Q)=>Q[1]);return[...new Set($)]}}class J$ extends D8{name="AgentJobDeadlineSweep";cron="* * * * *";async callback(){while(await v.sweep({limit:100})===100);}}var CJ=20;function F8(J,$){if($<=0||J.length===0)return null;let Q=(K,X)=>X.createdAt-K.createdAt||(K.id<X.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((K)=>K.state==="running").sort(Q),...J.filter((K)=>K.state!=="running").sort(Q)].slice(0,$).map((K)=>{let X=[`- ${K.id} (${K.toolName})`];if(K.state==="running")X.push(`running since ${$$(K.createdAt)}`);else if(K.state==="ok")X.push(`finished at ${$$(K.settledAt??K.updatedAt)}`);else{let G=K.error?`${K.error.code}: ${B8(K.error.message,200)}`:"failed";X.push(`failed at ${$$(K.settledAt??K.updatedAt)} (${G})`)}if(K.summary!==void 0)X.push(`summary: ${B8(JSON.stringify(K.summary),300)}`);if(K.orphaned)X.push("its tool call was lost when the turn that started it was cut short");return X.join("; ")}),"</jobs>"].join(`
2
+ import{$b as $8,$c as J6,Ac as t9,Bc as r9,Cc as C8,Ec as _8,Fc as T8,Gc as A8,Hc as R8,Ic as E8,Jc as j8,Kc as k8,Lc as x8,Mc as q8,Nc as I8,Oc as w8,Pc as b8,Rc as w,Sc as $9,Tc as s,Uc as T,Vc as Z8,Wc as s0,Xc as a0,Yb as J8,Yc as t0,Zb as NQ,Zc as r0,_b as UQ,_c as e0,ad as $6,bd as Q6,cc as xJ,cd as Z6,dc as S,dd as W6,ec as A,ed as K6,fd as DJ,gc as t8,gd as X6,hc as d8,hd as AQ,ic as KJ,id as Y6,jc as o0,jd as RQ,kc as g,kd as G6,lc as Q8,ld as EJ,mc as LQ,md as B$,nc as OQ,nd as V6,oc as CQ,od as H6,pc as m,pd as EQ,qc as _Q,qd as z6,rc as oJ,rd as D6,sc as MQ,sd as B6,tc as SQ,td as z$,uc as sJ,vc as U8,wc as L8,yc as O8,zc as v}from"../chunk-pbc3w7mq.js";import{Ld as D8}from"../chunk-9aj6eavs.js";import"../chunk-tbf76adx.js";import{$h as d0,Hh as zQ,Ii as FQ,Kh as BQ,Li as p$,Pi as PQ,_h as _9,ai as i0,bi as n0,ci as q}from"../chunk-r22svpab.js";import{Qi as DQ,Si as iJ,Ti as nJ}from"../chunk-4dnr1vg7.js";import{aj as h}from"../chunk-4hhvaa7a.js";import"../chunk-rjsd8f8q.js";import"../chunk-d7a79eqm.js";import"../chunk-ksgeqtcv.js";import{dk as n,ek as o,sk as SJ}from"../chunk-6rh3brnr.js";import"../chunk-vpmbynke.js";import"../chunk-9zcsshgb.js";import{fl as c9}from"../chunk-bsnp7h5w.js";import"../chunk-xtj7cgsx.js";import"../chunk-ykd2ayw8.js";import{yl as eJ}from"../chunk-7gc1jp2z.js";import"../chunk-xe126csw.js";import{existsSync as wQ,readdirSync as P6,readFileSync as V8}from"fs";import{isAbsolute as bQ,join as UJ,relative as fQ,sep as vQ}from"path";var H8="prompts.json",yQ=/\{\{>\s*([\w./-]+)\s*\}\}/g,X8=/\{\{(\w+)\}\}/g,hQ=/^[\w-]+(\/[\w-]+)*$/,Y8={dir:"app/agents",shared:"prompts"},OJ={},tJ=new Map,LJ;function gQ(){if(LJ===void 0){let J=UJ(eJ(),"dist","server",H8);LJ=wQ(J)?JSON.parse(V8(J,"utf8")):null}return LJ??null}function uQ(J){return J.replace(/\r?\n$/,"")}function G8(){return OJ.cache??Bun.env.NODE_ENV==="production"}function cQ(J){if(!hQ.test(J))throw Error(`"${J}" is not a prompt name. Use letters, digits, "-" and "_", with "/" between folders.`);let $=OJ.dir??Y8.dir,Q=bQ($)?$:UJ(process.cwd(),$),Z=J.includes("/")?`${J}.md`:UJ(OJ.shared??Y8.shared,`${J}.md`);return UJ(Q,Z)}function mQ(J){let $=cQ(J),Q=G8()?tJ.get($):void 0;if(Q!==void 0)return Q;let Z=Bun.env.NODE_ENV==="production";if(Z){let K=gQ()?.[fQ(eJ(),$).split(vQ).join("/")];if(K!==void 0)return K}let W;try{W=uQ(V8($,"utf8"))}catch(K){if(K.code==="ENOENT"){let X=Z?` or in dist/server/${H8}`:"";throw Error(`The prompt "${J}" does not exist (looked for ${$}${X}).`)}throw K}if(G8())tJ.set($,W);return W}function rJ(J,$){if($.includes(J))throw Error(`The prompt "${J}" includes itself: ${[...$,J].join(" > ")}.`);return mQ(J).replace(yQ,(Q,Z)=>rJ(Z,[...$,J]))}class z8{static configure(J){OJ={...J},tJ.clear(),LJ=void 0}static render(J,$={}){return rJ(J,[]).replace(X8,(Q,Z)=>{if(!Object.hasOwn($,Z))throw Error(`The prompt "${J}" has no value for {{${Z}}}.`);return String($[Z])})}static placeholders(J){let $=[...rJ(J,[]).matchAll(X8)].map((Q)=>Q[1]);return[...new Set($)]}}class J$ extends D8{name="AgentJobDeadlineSweep";cron="* * * * *";async callback(){while(await v.sweep({limit:100})===100);}}var CJ=20;function F8(J,$){if($<=0||J.length===0)return null;let Q=(K,X)=>X.createdAt-K.createdAt||(K.id<X.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((K)=>K.state==="running").sort(Q),...J.filter((K)=>K.state!=="running").sort(Q)].slice(0,$).map((K)=>{let X=[`- ${K.id} (${K.toolName})`];if(K.state==="running")X.push(`running since ${$$(K.createdAt)}`);else if(K.state==="ok")X.push(`finished at ${$$(K.settledAt??K.updatedAt)}`);else{let G=K.error?`${K.error.code}: ${B8(K.error.message,200)}`:"failed";X.push(`failed at ${$$(K.settledAt??K.updatedAt)} (${G})`)}if(K.summary!==void 0)X.push(`summary: ${B8(JSON.stringify(K.summary),300)}`);if(K.orphaned)X.push("its tool call was lost when the turn that started it was cut short");return X.join("; ")}),"</jobs>"].join(`
3
3
  `)}function $$(J){return new Date(J).toISOString().replace(/\.\d{3}Z$/,"Z")}function B8(J,$){return J.length<=$?J:`${J.slice(0,$-1)}\u2026`}class Z${table;sql;dialect;connection;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 pQ(this.dialect,this.table))await this.sql.unsafe(J)}async transaction(J){if(this.connection===void 0||this.joinable())return J();return SJ(this.sql,()=>J(),{connection:this.connection})}async create(J){let $=this.q(),Q=this.clock($);await $`
4
4
  INSERT INTO ${this.name($)}
5
5
  (id, thread_id, run_id, tool_call_id, tool_name, owner, job, summary, state,
@@ -241,4 +241,4 @@ return 0`;class d${injectedClient;prefix;constructor(J={}){this.injectedClient=J
241
241
 
242
242
  `)||void 0,L=await this.context(J,{body:V}),O=await this.reasoning(J,{body:V})||void 0,j=await this.skills(J,{body:V})||void 0,k=await this.attachmentsFor(J,Z,{body:V}),I=this.agent.memory?await this.memoryScopes(J,{body:V}):void 0;if(H?.cancelled)return GQ();let x=Z?new o$(this.store,Z,N,(E)=>this.reportHookFailure(E)):null,d=`run_${crypto.randomUUID()}`,_={req:J,runId:d,threadId:Z},R={id:null,notified:Promise.resolve()},C=this.agent.stream({runId:d,messages:N,turn:K,threadId:Z,...x?{onMessage:(E)=>x.finish(E)}:{},onTurn:(E)=>{if(R.id!==null)return;R.id=E.id;let i=x?x.settled():Promise.resolve();R.notified=i.then(()=>this.safely(()=>this.onMessage(E,_)))},instructions:P,...O?{reasoning:O}:{},...j&&j.length>0?{skills:j}:{},context:L,attachments:k,body:V,redactError:(E,i)=>this.redactError(E,i,_),nonces:this.nonces,receipts:this.receipts,subject:Y,...I?{memory:{scopes:I,...this.memoryMaxTokens!==void 0?{maxTokens:this.memoryMaxTokens}:{}}}:{},...Z?{jobs:{owner:Y}}:{},...this.contextWindow!==void 0?{contextWindow:this.contextWindow}:{},...Z&&AQ(this.store)?{summaryStore:this.store}:{},...this.prepareStep!==W8.prototype.prepareStep||this.hooks?.prepareStep?{prepareStep:(E)=>this.prepareStep(E,_)}:{}}),xQ=this.liveRuns.register(C,{threadId:Z,owner:Y,clientRunId:G,onEvent:(E)=>this.dispatchEvent(E,_),onInternalError:(E)=>this.reportHookFailure(E),maxRunDurationMs:this.agent.maxRunDurationMs});if(D=C,x)this.follow(C,x);let{stored:qQ,hooks:K8}=this.persistRun(C,_,xQ,x,R);if($Q.set(C,qQ),FJ.has(J))FJ.set(J,{run:C,hooks:K8});return J.ctx?.()?.waitUntil(K8),C.toResponse()};try{await this.authorizeRequest(J,{route:"stream",threadId:Z,body:V});let N=await this.foreignFile([...K?.files??[],...Z?[]:y0(Q.messages)],Y);if(N)return N;if(H?.cancelled)return GQ();let F=await this.runLimitKey(J,{owner:Y,threadId:Z}),P=F===null?lJ:M0(this.liveRuns).take(F,Z?`thread:${Z}`:`run:${crypto.randomUUID()}`,this.maxConcurrentRuns);if(!P)return e$(429,"too_many_runs",`You already have ${this.maxConcurrentRuns} conversations answering. Wait for one to finish, or stop it, and send again.`);try{return Z?await this.withThread(Z,Y,B):await B()}finally{let L=D;if(L)L.result().then(P,P);else P()}}finally{if(H&&mJ.get(G)===H)mJ.delete(G)}}async withThread(J,$,Q){let Z=cJ.get(J)??Promise.resolve(),W,K=new Promise((G)=>{W=G}),X=Z.then(()=>K);cJ.set(J,X),await Z;try{let G=await this.liveRuns.find({threadId:J});if(G&&this.liveRuns.isRunning(G.runId)&&!this.liveRuns.mayAccess(G.runId,$))return NJ();let V=G?this.liveRuns.get(G.runId):null;if(V)V.stop({reason:"superseded by a later turn on this thread"}),await $Q.get(V);return await Q()}finally{if(W(),cJ.get(J)===X)cJ.delete(J)}}async attach(J=new q){let $=await PJ(J,pJ);if($.error)return JJ($);let Q=$.body,Z=typeof Q.threadId==="string"?Q.threadId:b0(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=await this.liveRuns.find({threadId:Z});if(W&&!this.liveRuns.mayAccess(W.runId,await this.runOwner(J)))return NJ();if(!W)return M(404,{code:"no_live_run",message:`No run in progress for thread ${Z} in this process.`});let K=typeof Q.runId==="string"?Q.runId:void 0,X=K&&K!==W.runId?void 0:w0(J,Q);try{return PQ(this.liveRuns.replay(W.runId,X))}catch(G){if(G instanceof e)return M(410,{code:G.code,message:G.message,oldestSeq:G.oldest});if(G instanceof BJ)return M(404,{code:G.code,message:G.message});throw G}}async stop(J=new q){let $=await PJ(J,pJ);if($.error)return JJ($);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 X=mJ.get(Q.clientRunId);if(X){if(X.owner!==null&&X.owner!==Z)return NJ();return X.cancelled=!0,{stopped:!0}}}}if(!W&&typeof Q.threadId==="string")W=(await this.liveRuns.find({threadId:Q.threadId}))?.runId;let K=W?this.liveRuns.get(W):null;if(!K)return{stopped:!1};if(!this.liveRuns.mayAccess(K.runId,Z))return NJ();return K.stop({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,K=W?.id??W?.publicId;if(K!==void 0&&K!==null&&String(K)!=="")return{key:`user:${String(K)}`};if($)return{key:`thread:${$}`};return null}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 q){let $=this.voice;if(!$)return s$();let Q=await PJ(J,pJ);if(Q.error)return JJ(Q);let{sdp:Z,threadId:W,pushToTalk:K}=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 X=dJ(Q.body,h0),G=typeof W==="string"&&W!==""?W:void 0;await this.authorizeRequest(J,{route:"stream",threadId:G,body:X});let V=J.ctx?.()?.user??null,Y=await $.start({req:J,body:X,threadId:G,user:V,pushToTalk:K===!0}),H=Date.now(),D,z=async(L)=>{if(L!==void 0)console.error("[gemi/ai] a voice session could not start.",L);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 Y.onEnd?.({sessionId:"",...D?{callId:D}:{},threadId:Y.threadId??G??"",reason:"start_failed",startedAt:H,endedAt:Date.now(),durationMs:0,seconds:0,usage:S(),transcription:{usage:S(),seconds:0},transcript:[],requests:[],toolCalls:[],errors:[]})}catch(O){console.error("[gemi/ai] a voice session's onEnd threw.",O)}},B=Y.threadId??G;if(!B)return await z(void 0),M(400,{code:"invalid_request",message:"A voice session needs a thread: send `threadId`, or answer one from `voice.start`."});try{if(B!==G)await this.authorizeRequest(J,{route:"stream",threadId:B,body:X})}catch(L){throw await z(void 0),L}let U=crypto.randomUUID(),N=Y.tools??[];try{if(Y.mcp)N=[...N,...await v$(Y.mcp,{user:V,sessionId:U})]}catch(L){return await z(L),M(500,{code:"voice_unavailable",message:"Voice isn't available right now."})}let F={...Y.session,tools:[...HJ($.delegate),...Y.session?.tools??[],...N.map((L)=>L.tool)],...K===!0?{turnDetection:null}:{}},P;try{P=await $.realtime.createCall({sdp:Z,session:F,safetyIdentifier:Y.safetyIdentifier})}catch(L){await z(L);let O=L instanceof f&&L.code==="rate_limited";return M(O?429:502,{code:"voice_unavailable",message:"Voice isn't available right now."})}D=P.callId;try{await this.voiceStore.create({id:U,callId:P.callId,threadId:B,owner:await this.runOwner(J),body:X,startedAt:H});let{threadId:L,session:O,safetyIdentifier:j,mcp:k,tools:I,...x}=Y;return{sessionId:p.start({...x,tools:N,controller:this.constructor,threadId:B,user:V,body:X,call:{realtime:$.realtime,callId:P.callId},sessionId:U,store:this.voiceStore,liveRuns:this.liveRuns,delegate:$.delegate,session:F}).sessionId,sdp:P.sdpAnswer,threadId:B,delegate:$.delegate?.name??zJ,endsAt:H+(Y.limits?.maxDurationMs??900000)}}catch(L){return await z(L),M(500,{code:"voice_unavailable",message:"Voice isn't available right now."})}}async voiceUpdate(J=new q){if(!this.voice)return s$();let $=await this.voiceSession(J);if($ instanceof Response)return $;let Q=await PJ(J,pJ);if(Q.error)return JJ(Q);let Z=dJ(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}),p.get($.id)?.setBody(Z),{updated:!0}}async voiceEnd(J=new q){let $=this.voice;if(!$)return s$();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=p.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 NJ();return Q}async upload(J=new q){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",K=R0($.get("body")),X=$.get("threadId");await this.authorizeRequest(J,{route:"upload",threadId:typeof X==="string"&&X.length>0?X:void 0,body:K});let G=T0(await this.attachmentLimits(J),Q,Z,W);if(G)throw new r$(G.code,G.message);let V=typeof X==="string"&&X.length>0&&await this.store.loadThread(X)!==null?X:void 0,Y=await this.runOwner(J),H=(k)=>this.fileOwners.record(k,{owner:Y,name:Z,mimeType:W,size:Q.size,createdAt:new Date().toISOString()}),D={body:K,threadId:V},z=await this.checkUpload({name:Z,size:Q.size,mimeType:W},J,D);if(z)throw new r$(z.code||"upload_refused",z.message);let B=await this.attachmentDestination(Q,J,D),U=g0(B,$.get("destination")),N=await this.attachmentScope(J,V,{body:K}),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()`.');u0()}if(U==="provider"||!N){let k=await WQ(this.agent.provider,Q);await H(k);let I={fileId:k,name:Z,mimeType:W,size:Q.size,destination:"provider"};if(F)I.downgraded="no_scope";return I}let P=_Q(),L=await this.attachmentStorage.put({name:MQ(P,Z),body:Q,contentType:W}),O=U==="both"?await WQ(this.agent.provider,Q):void 0;if(O)await H(O);let j={id:P,scopeKey:N.key,fileId:O,objectName:L,name:Z,mimeType:W,size:Q.size,createdAt:new Date().toISOString(),destination:U};return await this.attachments.put(N,j),{fileId:O,attachmentId:P,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 v0()}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 Q8(J,$)}onError(J,$){return this.hooks?.onError?.(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:EQ(Q)});return}case"awaiting-input":await this.onAwaitingInput(J.pending,$);return;case"error":await this.onError(LQ(J.error),$);return;default:return}}async readThread(J){let $=await this.store.loadThread(J);return $?(await this.settleThread(J,$,{write:!1})).messages:null}isRunLive(J,$){return this.liveRuns.get(J)!==null}async settleThread(J,$,{write:Q}){let Z=(V)=>this.isRunLive(V,J),W=await s9($,Z),K=W.messages,X=[],G=new Map(W.settled.map((V)=>[V.id,V]));if(l0(K)||Q)try{let V=await e9(K,{threadId:J,store:v.store,isRunLive:Z,outputSchemaFor:(Y)=>this.toolNamed(Y)?.outputSchema,modelOutputFor:(Y,H)=>RQ(this.toolNamed(Y),H,(D)=>this.reportHookFailure(D)),scan:this.jobsBlockMax()});K=V.messages,X=V.jobs;for(let Y of V.settled)G.set(Y.id,Y);if(Q&&V.orphans.length>0){await JQ(v.store,V.orphans,(H)=>this.reportHookFailure(H));let Y=new Set(V.orphans.map((H)=>H.id));X=X.map((H)=>Y.has(H.id)?{...H,orphaned:!0}:H)}}catch(V){this.reportHookFailure(V)}if(Q&&G.size>0)try{await this.store.appendMessages(J,[...G.values()])}catch(V){this.reportHookFailure(V)}return{messages:K,jobs:X}}jobsBlockMax(){let J=this.agent.jobs?.contextBlock;if(J===!1)return 0;return J?.max??CJ}jobsBlock(J){return F8(J,this.jobsBlockMax())}toolNamed(J){let $=(Q)=>{for(let Z of Q){let W=Z;if(Array.isArray(W.tools)){let K=$(W.tools);if(K)return K}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()}){let K=Promise.resolve(),X=(async()=>{let V;try{V=await J.result()}catch(H){Z?.close(),await Z?.settled(),K=W.notified.then(()=>this.safely(()=>this.onError({code:"unknown",message:H instanceof Error?H.message:String(H),retryable:!1},$)));return}let Y=V.messages;if(Z?.close(Y),await Z?.settled(),$.threadId&&Y.length>0)try{await this.store.appendMessages($.threadId,Y)}catch(H){this.reportHookFailure(H)}K=this.notifyRun(V,Y,$,W)})(),G=X.then(()=>m0(Promise.all([K,Q]).then(()=>{}),this.hookHoldMs));return{stored:X,hooks:G}}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 a$=["turn","clientRunId","threadId","messages","regenerate"],A0=["text","files","toolResults"];function dJ(J,$=kQ(J)?a$:[...a$,...A0]){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 R0(J){if(J===null)return{};let $;if(typeof J==="string")try{$=JSON.parse(J)}catch{throw new t$("The upload's `body` field is not valid JSON.")}if($===null||typeof $!=="object"||Array.isArray($))throw new t$("The upload's `body` field must be a JSON object.");return dJ($,a$)}class t$ extends iJ{constructor(J){super(J);this.name="InvalidUploadError",this.payload={api:{status:400,data:{error:{code:"invalid_request",message:J}}},view:{}}}}async function WQ(J,$){try{return await J.upload($)}catch(Q){if(Q instanceof w&&E0.has(Q.status))throw new jQ(T(Q).message);throw Q}}var E0=new Set([400,413,415,422]);class r$ extends iJ{constructor(J,$){super($);this.name="LimitedUploadError",this.payload={api:{status:422,data:{error:{code:J,message:$}}},view:{}}}}function T0(J,$,Q,Z){if(!J)return null;let{maxBytes:W,accept:K}=J;if(typeof W==="number"&&$.size>W)return{code:"file_too_large",message:`${JSON.stringify(Q)} is ${KQ($.size)}; the limit is ${KQ(W)}.`};if(K&&K.length>0&&!K.some((X)=>j0(X,Q,Z)))return{code:"unsupported_file_type",message:`${JSON.stringify(Q)} is not a type this chat accepts. Accepted: ${K.join(", ")}.`};return null}function j0(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 KQ(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 jQ extends iJ{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 PJ(J,$){let Q=J?.rawRequest;if(!Q||Q.method==="GET"||Q.method==="HEAD"||!Q.body)return{body:{}};if(!k0(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 XQ($);let W;try{let X=await x0(Q,$);if(X===null)return XQ($);W=X}catch{return{body:{},error:"The request body could not be read."}}if(!W.trim())return{body:{}};let K;try{K=JSON.parse(W)}catch{return{body:{},error:"The request body is not valid JSON."}}if(K===null||typeof K!=="object"||Array.isArray(K))return{body:{},error:"The request body must be a JSON object."};return{body:K}}function k0(J){return BQ(J)==="application/json"}async function x0(J,$){if(!Number.isFinite($)||!J.body)return await J.text();let Q=J.body.getReader(),Z=[],W=0;for(;;){let{done:G,value:V}=await Q.read();if(G)break;if(W+=V.byteLength,W>$)return await Q.cancel().catch(lJ),null;Z.push(V)}let K=new Uint8Array(W),X=0;for(let G of Z)K.set(G,X),X+=G.byteLength;return new TextDecoder().decode(K)}function XQ(J){return{body:{},status:413,code:"body_too_large",error:`The request body is larger than this agent accepts (${J} bytes).`}}function e$(J,$,Q){return M(J,{...nJ(DQ(J),Q,J),code:$})}function JJ(J){if(J.status===413)return e$(413,J.code??"body_too_large",J.error??"");return M(J.status??400,{code:J.code??"invalid_request",message:J.error})}function kQ(J){return Boolean(J.turn)&&typeof J.turn==="object"}function q0(J){let $=kQ(J)?J.turn:J,Q={};if(typeof $.text==="string")Q.text=$.text;if(Array.isArray($.files)){let Z=I0($.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>YQ)return{error:`turn.localId is longer than ${YQ} characters.`};Q.localId=Z}return{turn:Q}}var YQ=200;function I0(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 K={};for(let H of["fileId","attachmentId","name","mimeType"]){let D=Z[H];if(D===void 0||D===null||D==="")continue;if(typeof D!=="string")return`${W}.${H} must be a string.`;K[H]=D}let{fileId:X,attachmentId:G,name:V,mimeType:Y}=K;if(X?.startsWith(m))return`${W}.fileId holds a gemi attachment id (${X}). \`fileId\` is the provider's id from the upload response; put this one in \`attachmentId\`.`;if(G!==void 0&&!G.startsWith(m))return`${W}.attachmentId is not a gemi attachment id: it must start with "${m}".`;if(!X&&!G)return`${W} has neither a \`fileId\` nor an \`attachmentId\`. Send the ids the upload response answered.`;$.push({...X?{fileId:X}:{},...G?{attachmentId:G}:{},...V!==void 0?{name:V}:{},...Y!==void 0?{mimeType:Y}:{}})}return $}function w0(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 b0(J,$){let Q=J?.search?.get($);return typeof Q==="string"?Q:void 0}function f0(J){let $=Z8(J);for(let Q=J.length-1;Q>=0;Q--){let Z=J[Q];if(Z.role!=="user"||$.has(Z.id))continue;let W="",K=[];for(let X of Z.content){if(X.type==="text")W+=X.text;if(X.type==="file")K.push({...X.fileId?{fileId:X.fileId}:{},...X.attachmentId?{attachmentId:X.attachmentId}:{},...X.name?{name:X.name}:{},...X.mimeType?{mimeType:X.mimeType}:{}})}if(!W&&K.length===0)continue;return{index:Q,turn:{...W?{text:W}:{},...K.length>0?{files:K}:{}}}}return null}function GQ(){return M(409,{code:"stopped",message:"The turn was stopped before it started."})}function NJ(){return M(403,nJ("permission","This run belongs to someone else.",403))}function v0(){return M(403,nJ("permission","A file in this turn was uploaded by someone else.",403))}function y0(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 h0=["sdp","threadId","pushToTalk"];function s$(){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 g0(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 VQ=!1;function u0(){if(VQ)return;VQ=!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 c0=2147483647;function m0(J,$){let Q=J.then(()=>{},()=>{});if(!($<=c0))return Q;let Z,W=new Promise((K)=>{Z=setTimeout(K,$)});return Promise.race([Q,W]).finally(()=>clearTimeout(Z))}var HQ=!1;function p0(J){if(HQ||Bun.env.NODE_ENV!=="production")return;if(!(J instanceof J8))return;HQ=!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 l0(J){return J.some(($)=>$.content.some((Q)=>Q.type==="tool-result"&&Q.status==="running"))}export{J6 as windowMessages,HJ as voiceTools,s0 as turnStarts,qJ as toRealtimeUsage,eQ as toAgentTools,n0 as supportsStrict,a0 as splitTurns,Y6 as settleSummaries,i0 as s,Q8 as redactError,t0 as messageSize,KJ as measureUsage,v$ as mcpVoiceTools,u$ as liveRuns,DJ as keepSummary,A9 as isCallNotFound,Z8 as injectedMessageIds,z$ as generate,nZ as evalChain,S0 as defineAgentHooks,h$ as defaultVoiceStore,X6 as defaultSummaryStore,$8 as defaultNonceStore,c$ as defaultFileOwners,sJ as defaultAttachmentStore,i$ as defaultAgentStore,yJ as VoiceHangup,p as VoiceBridge,o0 as Usage,B$ as ToolNamespace,g as ToolError,V6 as Skill,oJ as ScopedAttachments,H6 as SKILLS_NAMESPACE,d$ as RedisReceiptStore,NQ as RedisNonceStore,IJ as RealtimeSideband,f as RealtimeRequestError,GJ as RealtimeClient,z8 as Prompt,UQ as PrismaNonceStore,G6 as PendingEscalation,I$ as OpenAIProvider,L$ as OpenAIImageProvider,y$ as MemoryVoiceSessionStore,K6 as MemorySummaryStore,l$ as MemoryReceiptStore,J8 as MemoryNonceStore,hJ as MemoryLiveRuns,gJ as MemoryFileOwners,fJ as MemoryCircuitStore,SQ as MemoryAttachmentStore,uJ as MemoryAgentStore,U8 as MemoryAgentJobStore,b8 as MEMORY_NAMESPACE,BJ as LiveRunNotFoundError,O8 as JobsRequireThreadError,L8 as JobHandle,d0 as JSONSchemaError,CQ as InvalidAttachmentScopeError,j8 as InMemoryAgentMemoryStore,jJ as ImageRequestError,kJ as ImageProvider,F$ as ImageModel,e as FrameCursorEvictedError,VJ as FallbackProvider,I8 as FakeAgentMemoryStore,RJ as Eval,h9 as DatabaseAgentStore,K$ as DatabaseAgentMemoryStore,Z$ as DatabaseAgentJobStore,M9 as DEFAULT_TRANSCRIPTION_MODEL,T8 as DEFAULT_MEMORY_MAX_TOKENS,w8 as DEFAULT_MEMORY_LIMITS,$6 as DEFAULT_MAX_SUMMARY_TOKENS,z6 as DEFAULT_MAX_RUN_DURATION_MS,C8 as DEFAULT_JOB_DEADLINE_MS,CJ as DEFAULT_JOBS_CONTEXT_MAX,zJ as DEFAULT_DELEGATE_NAME,r0 as DEFAULT_CONTEXT_WINDOW_STEP,e0 as DEFAULT_CONTEXT_WINDOW_NOTE,Q6 as DEFAULT_COMPACT_TRIGGER_TOKENS,Z6 as DEFAULT_COMPACT_INSTRUCTIONS,W6 as COMPACT_SUMMARY_HEADER,w$ as AzureOpenAIProvider,O$ as AzureOpenAIImageProvider,OQ as AttachmentNotFoundError,aJ as AgentTurnError,EJ as AgentTool,D6 as AgentRunError,r as AgentProvider,k8 as AgentMemoryRefusedError,x8 as AgentMemoryConflictError,q8 as AgentMemories,v as AgentJobs,J$ as AgentJobDeadlineSweep,_8 as AgentJob,W8 as AgentController,B6 as Agent};
243
243
 
244
- //# debugId=BC2F53030F49461164756E2164756E21
244
+ //# debugId=81FBD753421EB89C64756E2164756E21