gemi 0.244.0 → 0.245.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 (229) hide show
  1. package/dist/ai/index.js +2 -2
  2. package/dist/ai/index.js.map +1 -1
  3. package/dist/ai/testing/index.js +2 -2
  4. package/dist/ai/testing/index.js.map +1 -1
  5. package/dist/app/index.js +1 -1
  6. package/dist/bun/plugin.js +1 -1
  7. package/dist/bun/preload.js +1 -1
  8. package/dist/{chunk-t77xnb8k.js → chunk-11fc5nve.js} +3 -3
  9. package/dist/{chunk-t77xnb8k.js.map → chunk-11fc5nve.js.map} +1 -1
  10. package/dist/{chunk-7mxwstm2.js → chunk-1gptecxr.js} +2 -2
  11. package/dist/{chunk-7mxwstm2.js.map → chunk-1gptecxr.js.map} +1 -1
  12. package/dist/{chunk-n537kc55.js → chunk-1v7qcmr7.js} +2 -2
  13. package/dist/{chunk-n537kc55.js.map → chunk-1v7qcmr7.js.map} +1 -1
  14. package/dist/{chunk-632nqkza.js → chunk-2kt5kgaq.js} +2 -2
  15. package/dist/{chunk-632nqkza.js.map → chunk-2kt5kgaq.js.map} +1 -1
  16. package/dist/{chunk-s0azv6dd.js → chunk-31fgprsv.js} +2 -2
  17. package/dist/{chunk-s0azv6dd.js.map → chunk-31fgprsv.js.map} +1 -1
  18. package/dist/{chunk-wac3gv1t.js → chunk-3n7rmrd1.js} +2 -2
  19. package/dist/{chunk-wac3gv1t.js.map → chunk-3n7rmrd1.js.map} +1 -1
  20. package/dist/{chunk-vqtzwnwr.js → chunk-4md5qxe1.js} +2 -2
  21. package/dist/{chunk-vqtzwnwr.js.map → chunk-4md5qxe1.js.map} +1 -1
  22. package/dist/{chunk-tws22txn.js → chunk-5961jw1h.js} +2 -2
  23. package/dist/{chunk-7ztbpqed.js.map → chunk-5961jw1h.js.map} +1 -1
  24. package/dist/{chunk-65m459jb.js → chunk-5npzvdh9.js} +2 -2
  25. package/dist/{chunk-65m459jb.js.map → chunk-5npzvdh9.js.map} +1 -1
  26. package/dist/{chunk-4y0j6c56.js → chunk-71ap56wq.js} +4 -4
  27. package/dist/{chunk-4y0j6c56.js.map → chunk-71ap56wq.js.map} +1 -1
  28. package/dist/{chunk-7ztbpqed.js → chunk-748evey0.js} +2 -2
  29. package/dist/{chunk-tws22txn.js.map → chunk-748evey0.js.map} +1 -1
  30. package/dist/{chunk-bbhrs7s3.js → chunk-7gf0hjth.js} +2 -2
  31. package/dist/{chunk-bbhrs7s3.js.map → chunk-7gf0hjth.js.map} +1 -1
  32. package/dist/{chunk-xvnjahea.js → chunk-7jpfvs5v.js} +2 -2
  33. package/dist/{chunk-xvnjahea.js.map → chunk-7jpfvs5v.js.map} +1 -1
  34. package/dist/chunk-8fb7gey2.js +5 -0
  35. package/dist/{chunk-8dga75cv.js.map → chunk-8fb7gey2.js.map} +1 -1
  36. package/dist/{chunk-e0e43wvq.js → chunk-8vzxnjp4.js} +2 -2
  37. package/dist/{chunk-e0e43wvq.js.map → chunk-8vzxnjp4.js.map} +1 -1
  38. package/dist/{chunk-p03jdwc1.js → chunk-akvv3mvx.js} +2 -2
  39. package/dist/{chunk-p03jdwc1.js.map → chunk-akvv3mvx.js.map} +1 -1
  40. package/dist/{chunk-dfat5nmk.js → chunk-b0hjrnn6.js} +3 -3
  41. package/dist/{chunk-dfat5nmk.js.map → chunk-b0hjrnn6.js.map} +1 -1
  42. package/dist/{chunk-sew755q5.js → chunk-b1dxjd33.js} +1 -1
  43. package/dist/{chunk-e4a6smfv.js → chunk-b1gt8s41.js} +1 -1
  44. package/dist/{chunk-3tpj5t10.js → chunk-b5g6ch5p.js} +2 -2
  45. package/dist/{chunk-3tpj5t10.js.map → chunk-b5g6ch5p.js.map} +1 -1
  46. package/dist/{chunk-ed64ynex.js → chunk-ba2yfwv1.js} +2 -2
  47. package/dist/{chunk-ed64ynex.js.map → chunk-ba2yfwv1.js.map} +1 -1
  48. package/dist/{chunk-ac135mmf.js → chunk-bcpxyv8m.js} +2 -2
  49. package/dist/{chunk-ac135mmf.js.map → chunk-bcpxyv8m.js.map} +1 -1
  50. package/dist/{chunk-h6dzn5j6.js → chunk-be0r4rgs.js} +2 -2
  51. package/dist/{chunk-h6dzn5j6.js.map → chunk-be0r4rgs.js.map} +1 -1
  52. package/dist/{chunk-57n0m9fv.js → chunk-bv76ypa6.js} +2 -2
  53. package/dist/{chunk-57n0m9fv.js.map → chunk-bv76ypa6.js.map} +1 -1
  54. package/dist/{chunk-9xm5z33t.js → chunk-c2cdf01r.js} +2 -2
  55. package/dist/{chunk-9xm5z33t.js.map → chunk-c2cdf01r.js.map} +1 -1
  56. package/dist/{chunk-26pfh03x.js → chunk-cyxsmd4q.js} +3 -3
  57. package/dist/{chunk-26pfh03x.js.map → chunk-cyxsmd4q.js.map} +1 -1
  58. package/dist/{chunk-5pfbqc1c.js → chunk-d8ekdvsw.js} +2 -2
  59. package/dist/{chunk-5pfbqc1c.js.map → chunk-d8ekdvsw.js.map} +1 -1
  60. package/dist/{chunk-093j5rh8.js → chunk-dapd4vkd.js} +3 -3
  61. package/dist/{chunk-093j5rh8.js.map → chunk-dapd4vkd.js.map} +1 -1
  62. package/dist/{chunk-gqw25apr.js → chunk-dx4h7rap.js} +2 -2
  63. package/dist/{chunk-gqw25apr.js.map → chunk-dx4h7rap.js.map} +1 -1
  64. package/dist/{chunk-fwmzms6e.js → chunk-e71g3wf3.js} +2 -2
  65. package/dist/{chunk-fwmzms6e.js.map → chunk-e71g3wf3.js.map} +1 -1
  66. package/dist/{chunk-7c48nxqb.js → chunk-exw8wa9c.js} +3 -3
  67. package/dist/{chunk-7c48nxqb.js.map → chunk-exw8wa9c.js.map} +1 -1
  68. package/dist/{chunk-fs2cdxry.js → chunk-fe7f6jbc.js} +2 -2
  69. package/dist/{chunk-fs2cdxry.js.map → chunk-fe7f6jbc.js.map} +1 -1
  70. package/dist/{chunk-fb3qkmwh.js → chunk-fesg4q4p.js} +2 -2
  71. package/dist/{chunk-fb3qkmwh.js.map → chunk-fesg4q4p.js.map} +1 -1
  72. package/dist/{chunk-0jmh2271.js → chunk-ffb2mytk.js} +2 -2
  73. package/dist/{chunk-0jmh2271.js.map → chunk-ffb2mytk.js.map} +1 -1
  74. package/dist/{chunk-t67dbfqs.js → chunk-fgmd1hn7.js} +3 -3
  75. package/dist/{chunk-t67dbfqs.js.map → chunk-fgmd1hn7.js.map} +1 -1
  76. package/dist/{chunk-kjz6jh54.js → chunk-gm14dthh.js} +3 -3
  77. package/dist/{chunk-kjz6jh54.js.map → chunk-gm14dthh.js.map} +1 -1
  78. package/dist/{chunk-d39h1mrz.js → chunk-gmkzq212.js} +3 -3
  79. package/dist/{chunk-d39h1mrz.js.map → chunk-gmkzq212.js.map} +1 -1
  80. package/dist/{chunk-54v3y7mg.js → chunk-gx5yhz2m.js} +3 -3
  81. package/dist/{chunk-54v3y7mg.js.map → chunk-gx5yhz2m.js.map} +1 -1
  82. package/dist/{chunk-ge5m9qdt.js → chunk-h02cqzar.js} +2 -2
  83. package/dist/{chunk-ge5m9qdt.js.map → chunk-h02cqzar.js.map} +1 -1
  84. package/dist/{chunk-hvw25pe3.js → chunk-h2ar54x8.js} +1 -1
  85. package/dist/{chunk-kejexfsg.js → chunk-h6yse9wf.js} +2 -2
  86. package/dist/{chunk-kejexfsg.js.map → chunk-h6yse9wf.js.map} +1 -1
  87. package/dist/{chunk-n8cm2sw6.js → chunk-hh3m9be7.js} +2 -2
  88. package/dist/{chunk-n8cm2sw6.js.map → chunk-hh3m9be7.js.map} +1 -1
  89. package/dist/{chunk-11hmhyk5.js → chunk-hhka8j31.js} +3 -3
  90. package/dist/{chunk-11hmhyk5.js.map → chunk-hhka8j31.js.map} +1 -1
  91. package/dist/{chunk-xy5evkaz.js → chunk-hmdpf21x.js} +1 -1
  92. package/dist/{chunk-ss0gk90s.js → chunk-jv7n3p61.js} +2 -2
  93. package/dist/{chunk-ss0gk90s.js.map → chunk-jv7n3p61.js.map} +1 -1
  94. package/dist/{chunk-2yvzc5tq.js → chunk-jzg9zdtj.js} +2 -2
  95. package/dist/{chunk-2yvzc5tq.js.map → chunk-jzg9zdtj.js.map} +1 -1
  96. package/dist/{chunk-zpnxr23b.js → chunk-k5vt2kz6.js} +2 -2
  97. package/dist/{chunk-zpnxr23b.js.map → chunk-k5vt2kz6.js.map} +1 -1
  98. package/dist/{chunk-yqsnrp2b.js → chunk-kck2q09f.js} +2 -2
  99. package/dist/{chunk-yqsnrp2b.js.map → chunk-kck2q09f.js.map} +1 -1
  100. package/dist/{chunk-9cxs1q57.js → chunk-ket76475.js} +2 -2
  101. package/dist/{chunk-9cxs1q57.js.map → chunk-ket76475.js.map} +1 -1
  102. package/dist/{chunk-2mtm1yt6.js → chunk-kjtx99jj.js} +2 -2
  103. package/dist/{chunk-2mtm1yt6.js.map → chunk-kjtx99jj.js.map} +1 -1
  104. package/dist/{chunk-ye1kbxkx.js → chunk-kjzvrx2p.js} +3 -3
  105. package/dist/{chunk-ye1kbxkx.js.map → chunk-kjzvrx2p.js.map} +1 -1
  106. package/dist/{chunk-v3ddktnq.js → chunk-kss2kkmm.js} +3 -3
  107. package/dist/{chunk-v3ddktnq.js.map → chunk-kss2kkmm.js.map} +1 -1
  108. package/dist/{chunk-jr53em8y.js → chunk-mbfjxyq0.js} +2 -2
  109. package/dist/{chunk-jr53em8y.js.map → chunk-mbfjxyq0.js.map} +1 -1
  110. package/dist/{chunk-w9v8bbp8.js → chunk-mc7p37d0.js} +2 -2
  111. package/dist/{chunk-w9v8bbp8.js.map → chunk-mc7p37d0.js.map} +1 -1
  112. package/dist/{chunk-rffa9x3d.js → chunk-n26d4z3t.js} +2 -2
  113. package/dist/{chunk-rffa9x3d.js.map → chunk-n26d4z3t.js.map} +1 -1
  114. package/dist/{chunk-646bqwp8.js → chunk-n8kke112.js} +2 -2
  115. package/dist/{chunk-646bqwp8.js.map → chunk-n8kke112.js.map} +1 -1
  116. package/dist/{chunk-vh6vc4h1.js → chunk-nbdjbde4.js} +3 -3
  117. package/dist/{chunk-vh6vc4h1.js.map → chunk-nbdjbde4.js.map} +1 -1
  118. package/dist/{chunk-fy4142fv.js → chunk-ptm1d4vp.js} +2 -2
  119. package/dist/{chunk-fy4142fv.js.map → chunk-ptm1d4vp.js.map} +1 -1
  120. package/dist/chunk-q0k1j5a4.js +10 -0
  121. package/dist/{chunk-q94v5skw.js.map → chunk-q0k1j5a4.js.map} +4 -6
  122. package/dist/{chunk-t4eeg7j1.js → chunk-qbm49b1t.js} +3 -3
  123. package/dist/{chunk-t4eeg7j1.js.map → chunk-qbm49b1t.js.map} +1 -1
  124. package/dist/{chunk-eb4mx34p.js → chunk-r9266nax.js} +3 -3
  125. package/dist/{chunk-eb4mx34p.js.map → chunk-r9266nax.js.map} +1 -1
  126. package/dist/{chunk-e3m0anq1.js → chunk-rqknf5k0.js} +3 -3
  127. package/dist/{chunk-e3m0anq1.js.map → chunk-rqknf5k0.js.map} +1 -1
  128. package/dist/{chunk-4f8qpzsw.js → chunk-rtmz9yvj.js} +1 -1
  129. package/dist/{chunk-bsmy8vqs.js → chunk-rxtec0qr.js} +2 -2
  130. package/dist/{chunk-bsmy8vqs.js.map → chunk-rxtec0qr.js.map} +1 -1
  131. package/dist/{chunk-7qt9pxm6.js → chunk-s4xekxsk.js} +1 -1
  132. package/dist/{chunk-sp79baph.js → chunk-se0tnb9x.js} +2 -2
  133. package/dist/{chunk-sp79baph.js.map → chunk-se0tnb9x.js.map} +1 -1
  134. package/dist/chunk-t56z2zec.js +88 -0
  135. package/dist/{chunk-v040m0k2.js.map → chunk-t56z2zec.js.map} +15 -12
  136. package/dist/{chunk-fjh3xaq7.js → chunk-thdhm39v.js} +2 -2
  137. package/dist/{chunk-fjh3xaq7.js.map → chunk-thdhm39v.js.map} +1 -1
  138. package/dist/{chunk-zrqqnfrs.js → chunk-vg0yj29r.js} +2 -2
  139. package/dist/{chunk-zrqqnfrs.js.map → chunk-vg0yj29r.js.map} +1 -1
  140. package/dist/{chunk-110ecy3e.js → chunk-vq0gcvcy.js} +2 -2
  141. package/dist/{chunk-110ecy3e.js.map → chunk-vq0gcvcy.js.map} +1 -1
  142. package/dist/{chunk-3ywtqcxt.js → chunk-w31afsrx.js} +2 -2
  143. package/dist/{chunk-3ywtqcxt.js.map → chunk-w31afsrx.js.map} +1 -1
  144. package/dist/{chunk-27f9z8yk.js → chunk-wr7xq82n.js} +3 -3
  145. package/dist/{chunk-27f9z8yk.js.map → chunk-wr7xq82n.js.map} +1 -1
  146. package/dist/{chunk-2g6cmkrn.js → chunk-xac2vwtq.js} +3 -3
  147. package/dist/{chunk-2g6cmkrn.js.map → chunk-xac2vwtq.js.map} +1 -1
  148. package/dist/{chunk-mjfnv2r9.js → chunk-y1qmedgq.js} +2 -2
  149. package/dist/{chunk-mjfnv2r9.js.map → chunk-y1qmedgq.js.map} +1 -1
  150. package/dist/{chunk-mbstaydx.js → chunk-z0nx5nkb.js} +2 -2
  151. package/dist/{chunk-mbstaydx.js.map → chunk-z0nx5nkb.js.map} +1 -1
  152. package/dist/{chunk-c0hxmw3a.js → chunk-z5ha9z3m.js} +2 -2
  153. package/dist/{chunk-c0hxmw3a.js.map → chunk-z5ha9z3m.js.map} +1 -1
  154. package/dist/{chunk-yrna0ajq.js → chunk-z5wwhgsg.js} +3 -3
  155. package/dist/{chunk-yrna0ajq.js.map → chunk-z5wwhgsg.js.map} +1 -1
  156. package/dist/{chunk-0tsnmrf9.js → chunk-zc42brkr.js} +2 -2
  157. package/dist/{chunk-0tsnmrf9.js.map → chunk-zc42brkr.js.map} +1 -1
  158. package/dist/{chunk-hhaxacwh.js → chunk-zez3fjnf.js} +2 -2
  159. package/dist/{chunk-hhaxacwh.js.map → chunk-zez3fjnf.js.map} +1 -1
  160. package/dist/{chunk-rwyn40p1.js → chunk-ztg4pgqe.js} +2 -2
  161. package/dist/{chunk-rwyn40p1.js.map → chunk-ztg4pgqe.js.map} +1 -1
  162. package/dist/config/index.js +1 -1
  163. package/dist/console/run.js +2 -2
  164. package/dist/console/run.js.map +1 -1
  165. package/dist/container/index.js +2 -2
  166. package/dist/container/index.js.map +1 -1
  167. package/dist/database/index.js +2 -2
  168. package/dist/database/index.js.map +1 -1
  169. package/dist/email/index.js +2 -2
  170. package/dist/email/index.js.map +1 -1
  171. package/dist/facades/index.js +2 -2
  172. package/dist/facades/index.js.map +1 -1
  173. package/dist/foundation/index.js +2 -2
  174. package/dist/foundation/index.js.map +1 -1
  175. package/dist/http/ApiRouter.d.ts +11 -0
  176. package/dist/http/ApiRouter.d.ts.map +1 -1
  177. package/dist/http/McpEndpoint.d.ts +228 -0
  178. package/dist/http/McpEndpoint.d.ts.map +1 -0
  179. package/dist/http/RateLimitMiddleware.d.ts +7 -0
  180. package/dist/http/RateLimitMiddleware.d.ts.map +1 -1
  181. package/dist/http/index.d.ts +1 -0
  182. package/dist/http/index.d.ts.map +1 -1
  183. package/dist/http/index.js +2 -2
  184. package/dist/http/index.js.map +1 -1
  185. package/dist/i18n/dictionaryRuntime.js +2 -2
  186. package/dist/i18n/dictionaryRuntime.js.map +1 -1
  187. package/dist/i18n/index.js +2 -2
  188. package/dist/i18n/index.js.map +1 -1
  189. package/dist/kernel/index.js +2 -2
  190. package/dist/kernel/index.js.map +1 -1
  191. package/dist/orm/index.js +2 -2
  192. package/dist/orm/index.js.map +1 -1
  193. package/dist/probe/index.js +2 -2
  194. package/dist/probe/index.js.map +1 -1
  195. package/dist/server/index.js +2 -2
  196. package/dist/server/index.js.map +1 -1
  197. package/dist/services/index.js +2 -2
  198. package/dist/services/index.js.map +1 -1
  199. package/dist/services/mcp/http/McpHttpServer.d.ts +0 -1
  200. package/dist/services/mcp/http/McpHttpServer.d.ts.map +1 -1
  201. package/dist/services/mcp/http/protocol.d.ts +6 -0
  202. package/dist/services/mcp/http/protocol.d.ts.map +1 -1
  203. package/dist/services/middleware/MiddlewareRegistry.d.ts +12 -0
  204. package/dist/services/middleware/MiddlewareRegistry.d.ts.map +1 -1
  205. package/dist/services/queue/work.js +2 -2
  206. package/dist/services/queue/work.js.map +1 -1
  207. package/dist/services/router/DomainResolver.d.ts +22 -5
  208. package/dist/services/router/DomainResolver.d.ts.map +1 -1
  209. package/dist/services/router/DomainRouter.d.ts +1 -1
  210. package/dist/services/router/DomainRouter.d.ts.map +1 -1
  211. package/dist/services/router/config.d.ts +42 -4
  212. package/dist/services/router/config.d.ts.map +1 -1
  213. package/dist/stats/route-table.js +1 -1
  214. package/dist/stats/route-table.js.map +1 -1
  215. package/dist/stats/routeTable.d.ts +1 -1
  216. package/dist/stats/routeTable.d.ts.map +1 -1
  217. package/dist/support/index.js +2 -2
  218. package/dist/support/index.js.map +1 -1
  219. package/dist/vitest/index.js +1 -1
  220. package/package.json +1 -1
  221. package/dist/chunk-8dga75cv.js +0 -5
  222. package/dist/chunk-q94v5skw.js +0 -10
  223. package/dist/chunk-v040m0k2.js +0 -88
  224. /package/dist/{chunk-sew755q5.js.map → chunk-b1dxjd33.js.map} +0 -0
  225. /package/dist/{chunk-e4a6smfv.js.map → chunk-b1gt8s41.js.map} +0 -0
  226. /package/dist/{chunk-hvw25pe3.js.map → chunk-h2ar54x8.js.map} +0 -0
  227. /package/dist/{chunk-xy5evkaz.js.map → chunk-hmdpf21x.js.map} +0 -0
  228. /package/dist/{chunk-4f8qpzsw.js.map → chunk-rtmz9yvj.js.map} +0 -0
  229. /package/dist/{chunk-7qt9pxm6.js.map → chunk-s4xekxsk.js.map} +0 -0
package/dist/ai/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  // @bun
2
- import{ca as QZ,da as WZ,ea as XZ,fa as e6,ga as Q0,ha as J0,ia as W$,ja as $0,ka as Z0,la as RJ,ma as W0,na as X0,oa as K0,pa as G0}from"../chunk-ac135mmf.js";import{$c as M8,Ac as i,Bc as fZ,Cc as qZ,Dc as B$,Fc as S$,Gc as T$,Hc as R$,Ic as E$,Jc as k$,Kc as j$,Lc as x$,Mc as I$,Nc as w$,Oc as f$,Pc as q$,Qc as b$,Sc as b6,Tc as v6,Uc as y6,Vc as h6,Wc as g6,Xc as OQ,Yc as c6,Zc as S8,_c as u6,ad as m6,bd as p6,cd as l6,dd as gQ,ed as UJ,fd as i6,gd as d6,hd as A8,id as n6,jc as Q$,jd as o6,kc as P8,kd as s6,lc as N8,ld as a6,mc as J$,md as t6,nd as R8,od as r6,pd as FJ,qc as r$,rc as e$,sc as d$,tc as FQ,uc as T6,vc as g,wc as _$,xc as O$,zc as L$}from"../chunk-t77xnb8k.js";import{$d as XQ,Ed as o,Fd as $$,Id as F8,Jd as C8,Kd as U8,Ld as oQ,Md as _8,Nd as QJ,Od as sQ,Pd as nJ,Qd as O8,Rd as L8,Sd as JJ,Td as B8,Zd as KQ,ae as Z$,be as j6,ce as x6,de as I6,ee as w6,fe as f6,ge as q6,td as GZ,ud as S,vd as k}from"../chunk-11hmhyk5.js";import{xe as H$}from"../chunk-w9v8bbp8.js";import"../chunk-vh6vc4h1.js";import{Dj as z8,Ej as qJ,Xi as w,vi as K8,yi as V8}from"../chunk-093j5rh8.js";import{Fj as G8,Hj as rQ,Ij as eQ}from"../chunk-632nqkza.js";import{Lj as R6,Mj as E6,Nj as k6}from"../chunk-54v3y7mg.js";import{_j as n}from"../chunk-110ecy3e.js";import"../chunk-zpnxr23b.js";import{fl as Y8,gl as D8,hl as H8,il as dJ}from"../chunk-yrna0ajq.js";import"../chunk-jr53em8y.js";import{El as vQ,ol as ZQ,pl as WQ}from"../chunk-v3ddktnq.js";import{Rl as _Z}from"../chunk-rffa9x3d.js";import"../chunk-hhaxacwh.js";import{ym as BZ}from"../chunk-2g6cmkrn.js";import"../chunk-sp79baph.js";import"../chunk-3ywtqcxt.js";import{Vm as XJ}from"../chunk-9cxs1q57.js";import"../chunk-7ztbpqed.js";import{existsSync as q8,readdirSync as z0,readFileSync as z$}from"fs";import{isAbsolute as b8,join as xQ,relative as v8,sep as y8}from"path";var Y$="prompts.json",h8=/\{\{>\s*([\w./-]+)\s*\}\}/g,K$=/\{\{(\w+)\}\}/g,g8=/^[\w-]+(\/[\w-]+)*$/,G$={dir:"app/agents",shared:"prompts"},wQ={},ZJ=new Map,IQ;function c8(){if(IQ===void 0){let Q=xQ(XJ(),"dist","server",Y$);IQ=q8(Q)?JSON.parse(z$(Q,"utf8")):null}return IQ??null}function u8(Q){return Q.replace(/\r?\n$/,"")}function V$(){return wQ.cache??Bun.env.NODE_ENV==="production"}function m8(Q,J){if(!g8.test(Q))throw Error(`"${Q}" is not a prompt name. Use letters, digits, "-" and "_", with "/" between folders.`);let $=J.dir??wQ.dir??G$.dir,Z=b8($)?$:xQ(process.cwd(),$),W=Q.includes("/")?`${Q}.md`:xQ(J.shared??wQ.shared??G$.shared,`${Q}.md`);return xQ(Z,W)}function p8(Q,J){let $=m8(Q,J),Z=V$()?ZJ.get($):void 0;if(Z!==void 0)return Z;let W=Bun.env.NODE_ENV==="production";if(W){let K=c8()?.[v8(XJ(),$).split(y8).join("/")];if(K!==void 0)return K}let X;try{X=u8(z$($,"utf8"))}catch(K){if(K.code==="ENOENT"){let G=W?` or in dist/server/${Y$}`:"";throw Error(`The prompt "${Q}" does not exist (looked for ${$}${G}).`)}throw K}if(V$())ZJ.set($,X);return X}function WJ(Q,J,$){if(J.includes(Q))throw Error(`The prompt "${Q}" includes itself: ${[...J,Q].join(" > ")}.`);return p8(Q,$).replace(h8,(Z,W)=>WJ(W,[...J,Q],$))}class D${static configure(Q){wQ={...Q},ZJ.clear(),IQ=void 0}static render(Q,J={},$={}){return WJ(Q,[],$).replace(K$,(Z,W)=>{if(!Object.hasOwn(J,W))throw Error(`The prompt "${Q}" has no value for {{${W}}}.`);return String(J[W])})}static placeholders(Q,J={}){let $=[...WJ(Q,[],J).matchAll(K$)].map((Z)=>Z[1]);return[...new Set($)]}}class KJ extends H${name="AgentJobDeadlineSweep";cron="* * * * *";async callback(){while(await i.sweep({limit:100})===100);}}var qQ=20,l8=300,i8=200;function N$(Q,J){if(J<=0||Q.length===0)return null;let $=(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.",...[...Q.filter((X)=>!g(X.state)).sort($),...Q.filter((X)=>g(X.state)).sort($)].slice(0,J).map((X)=>{let K=[`- ${X.id} (${X.toolName})`];if(X.state==="waiting")K.push(`waiting for ${(X.after??[]).join(", ")} since ${fQ(X.createdAt)}`);else if(X.state==="running")K.push(`running since ${fQ(X.createdAt)}`);else if(X.state==="ok")K.push(`finished at ${fQ(X.settledAt??X.updatedAt)}`);else{let G=X.error?`${X.error.code}: ${P$(X.error.message,i8)}`:"failed";K.push(`failed at ${fQ(X.settledAt??X.updatedAt)} (${G})`)}if(X.summary!==void 0)K.push(`summary: ${P$(JSON.stringify(X.summary),l8)}`);if(X.orphaned)K.push("its tool call was lost when the turn that started it was cut short");return K.join("; ")}),"</jobs>"].join(`
2
+ import{ca as QZ,da as WZ,ea as XZ,fa as e6,ga as Q0,ha as J0,ia as W$,ja as $0,ka as Z0,la as RJ,ma as W0,na as X0,oa as K0,pa as G0}from"../chunk-bcpxyv8m.js";import{$c as m6,Ac as fZ,Bc as qZ,Cc as B$,Ec as S$,Fc as T$,Gc as R$,Hc as E$,Ic as k$,Jc as j$,Kc as x$,Lc as I$,Mc as w$,Nc as f$,Oc as q$,Pc as b$,Rc as b6,Sc as v6,Tc as y6,Uc as h6,Vc as g6,Wc as OQ,Xc as c6,Yc as S8,Zc as u6,_c as M8,ad as p6,bd as l6,cd as gQ,dd as UJ,ed as i6,fd as d6,gd as A8,hd as n6,ic as Q$,id as o6,jc as P8,jd as s6,kc as N8,kd as a6,lc as J$,ld as t6,md as R8,nd as r6,od as FJ,pc as r$,qc as e$,rc as d$,sc as FQ,tc as T6,uc as g,vc as _$,wc as O$,yc as L$,zc as i}from"../chunk-11fc5nve.js";import{$d as Z$,Dd as o,Ed as $$,Hd as F8,Id as C8,Jd as U8,Kd as oQ,Ld as _8,Md as QJ,Nd as sQ,Od as nJ,Pd as O8,Qd as L8,Rd as JJ,Sd as B8,Yd as KQ,_d as XQ,ae as j6,be as x6,ce as I6,de as w6,ee as f6,fe as q6,sd as GZ,td as S,ud as k}from"../chunk-hhka8j31.js";import{we as H$}from"../chunk-mc7p37d0.js";import"../chunk-nbdjbde4.js";import{Ki as K8,Ni as V8,Sj as z8,Tj as qJ,kj as w}from"../chunk-dapd4vkd.js";import{Uj as G8,Wj as rQ,Xj as eQ}from"../chunk-2kt5kgaq.js";import{$j as E6,_j as R6,ak as k6}from"../chunk-gx5yhz2m.js";import{nk as n}from"../chunk-vq0gcvcy.js";import"../chunk-k5vt2kz6.js";import{ul as Y8,vl as D8,wl as H8,xl as dJ}from"../chunk-z5wwhgsg.js";import"../chunk-mbfjxyq0.js";import{Dl as ZQ,El as WQ,Tl as vQ}from"../chunk-kss2kkmm.js";import{em as _Z}from"../chunk-n26d4z3t.js";import"../chunk-zez3fjnf.js";import{Nm as BZ}from"../chunk-xac2vwtq.js";import"../chunk-se0tnb9x.js";import"../chunk-w31afsrx.js";import{in as XJ}from"../chunk-ket76475.js";import"../chunk-748evey0.js";import{existsSync as q8,readdirSync as z0,readFileSync as z$}from"fs";import{isAbsolute as b8,join as xQ,relative as v8,sep as y8}from"path";var Y$="prompts.json",h8=/\{\{>\s*([\w./-]+)\s*\}\}/g,K$=/\{\{(\w+)\}\}/g,g8=/^[\w-]+(\/[\w-]+)*$/,G$={dir:"app/agents",shared:"prompts"},wQ={},ZJ=new Map,IQ;function c8(){if(IQ===void 0){let Q=xQ(XJ(),"dist","server",Y$);IQ=q8(Q)?JSON.parse(z$(Q,"utf8")):null}return IQ??null}function u8(Q){return Q.replace(/\r?\n$/,"")}function V$(){return wQ.cache??Bun.env.NODE_ENV==="production"}function m8(Q,J){if(!g8.test(Q))throw Error(`"${Q}" is not a prompt name. Use letters, digits, "-" and "_", with "/" between folders.`);let $=J.dir??wQ.dir??G$.dir,Z=b8($)?$:xQ(process.cwd(),$),W=Q.includes("/")?`${Q}.md`:xQ(J.shared??wQ.shared??G$.shared,`${Q}.md`);return xQ(Z,W)}function p8(Q,J){let $=m8(Q,J),Z=V$()?ZJ.get($):void 0;if(Z!==void 0)return Z;let W=Bun.env.NODE_ENV==="production";if(W){let K=c8()?.[v8(XJ(),$).split(y8).join("/")];if(K!==void 0)return K}let X;try{X=u8(z$($,"utf8"))}catch(K){if(K.code==="ENOENT"){let G=W?` or in dist/server/${Y$}`:"";throw Error(`The prompt "${Q}" does not exist (looked for ${$}${G}).`)}throw K}if(V$())ZJ.set($,X);return X}function WJ(Q,J,$){if(J.includes(Q))throw Error(`The prompt "${Q}" includes itself: ${[...J,Q].join(" > ")}.`);return p8(Q,$).replace(h8,(Z,W)=>WJ(W,[...J,Q],$))}class D${static configure(Q){wQ={...Q},ZJ.clear(),IQ=void 0}static render(Q,J={},$={}){return WJ(Q,[],$).replace(K$,(Z,W)=>{if(!Object.hasOwn(J,W))throw Error(`The prompt "${Q}" has no value for {{${W}}}.`);return String(J[W])})}static placeholders(Q,J={}){let $=[...WJ(Q,[],J).matchAll(K$)].map((Z)=>Z[1]);return[...new Set($)]}}class KJ extends H${name="AgentJobDeadlineSweep";cron="* * * * *";async callback(){while(await i.sweep({limit:100})===100);}}var qQ=20,l8=300,i8=200;function N$(Q,J){if(J<=0||Q.length===0)return null;let $=(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.",...[...Q.filter((X)=>!g(X.state)).sort($),...Q.filter((X)=>g(X.state)).sort($)].slice(0,J).map((X)=>{let K=[`- ${X.id} (${X.toolName})`];if(X.state==="waiting")K.push(`waiting for ${(X.after??[]).join(", ")} since ${fQ(X.createdAt)}`);else if(X.state==="running")K.push(`running since ${fQ(X.createdAt)}`);else if(X.state==="ok")K.push(`finished at ${fQ(X.settledAt??X.updatedAt)}`);else{let G=X.error?`${X.error.code}: ${P$(X.error.message,i8)}`:"failed";K.push(`failed at ${fQ(X.settledAt??X.updatedAt)} (${G})`)}if(X.summary!==void 0)K.push(`summary: ${P$(JSON.stringify(X.summary),l8)}`);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 fQ(Q){return new Date(Q).toISOString().replace(/\.\d{3}Z$/,"Z")}function P$(Q,J){return Q.length<=J?Q:`${Q.slice(0,J-1)}\u2026`}var F$=["after_jobs","batch_key","queued","inbox","job_checkpoint"],C$=20;class GJ{table;sql;dialect;connection;later;constructor(Q,J={}){let $=J.table??"gemi_agent_jobs";if(!/^[A-Za-z_][A-Za-z0-9_]*$/.test($))throw Error(`The agent jobs table name "${$}" is not a plain identifier. Use letters, digits and underscores.`);this.table=$,this.sql=Q.sql,this.dialect=Q.dialect,this.connection=Q.name}async createTable(){for(let Q of d8(this.dialect,this.table))await this.sql.unsafe(Q)}async transaction(Q){if(this.connection===void 0||this.joinable())return Q();return vQ(this.sql,()=>Q(),{connection:this.connection,dialect:this.dialect})}async create(Q){let J=Q.after!==void 0||Q.batch!==void 0||Q.queued!==void 0;if(J)await this.requireLaterColumns("A job with `after` or `batch`");let $=this.q(),Z=this.clock($),W=Q.state??"running";if(J)await $`
4
4
  INSERT INTO ${this.name($)}
5
5
  (id, thread_id, run_id, tool_call_id, tool_name, owner, job, summary, state,
@@ -335,4 +335,4 @@ return 0`;class vJ{injectedClient;prefix;constructor(Q={}){this.injectedClient=Q
335
335
 
336
336
  `)||void 0,R=await this.context(Q,{body:V}),f=await this.reasoning(Q,{body:V})||void 0,x=await this.skills(Q,{body:V})||void 0,I=await this.runTools(Q,{body:V,context:R})||void 0,h=await this.usageLimits(Q,{body:V,context:R})||void 0,r=await this.trailingContext(Q,{body:V,context:R})||void 0,p=await this.attachmentsFor(Q,Z,{body:V}),l=await this.attachmentRetention(Q,{route:"stream",threadId:Z,body:V});sQ(l,this.turnAttachmentMaxAgeMs);let L=[],A=p&&l?p.withLifetime({next:()=>sQ(l,this.turnAttachmentMaxAgeMs),onPut:(E)=>L.push(E)}):p,B=this.agent.memory?await this.memoryScopes(Q,{body:V}):void 0;if(D?.cancelled)return Q8();let q=Z?new cJ(this.store,Z,C,(E)=>this.reportHookFailure(E)):null,DQ=`run_${crypto.randomUUID()}`,e=[],kQ,QQ={req:Q,runId:DQ,threadId:Z,get denials(){return e},get turn(){return kQ?.turn}},TQ={id:null,notified:Promise.resolve()},j=this.agent.stream({runId:DQ,messages:C,turn:X,threadId:Z,...P.parallel||z==="parallel"||y.has(Q)?{keepOtherTurnsOpen:!0}:{},...q?{onMessage:(E)=>q.finish(E)}:{},onTurn:(E)=>{if(TQ.id!==null)return;TQ.id=E.id;let JQ=q?q.settled():Promise.resolve();TQ.notified=JQ.then(()=>this.safely(()=>this.onMessage(E,QQ)))},instructions:O,...MQ.has(Q)?{event:MQ.get(Q)}:{},...y.has(Q)?{echoTurn:!0}:{},...f?{reasoning:f}:{},...x&&x.length>0?{skills:x}:{},...I?.tools&&I.tools.length>0?{tools:I.tools}:{},...I?.activeTools?{activeTools:I.activeTools}:{},...r?{trailingContext:r}:{},...h?{usageLimits:h}:{},context:R,attachments:A,body:V,redactError:(E,JQ)=>this.redactError(E,JQ,QQ),onProviderRetry:(E)=>this.onProviderRetry(E,QQ),nonces:this.nonces,receipts:this.receipts,subject:Y,...B?{memory:{scopes:B,...this.memoryMaxTokens!==void 0?{maxTokens:this.memoryMaxTokens}:{}}}:{},...Z?{jobs:{owner:Y}}:{},...this.contextWindow!==void 0?{contextWindow:this.contextWindow}:{},...Z&&S8(this.store)?{summaryStore:this.store}:{},...this.prepareStep!==tQ.prototype.prepareStep||this.hooks?.prepareStep?{prepareStep:(E)=>this.prepareStep(E,QQ)}:{}});e=j.denials,kQ=j;let x8=this.liveRuns.register(j,{threadId:Z,owner:Y,clientRunId:G,onEvent:(E)=>this.dispatchEvent(E,QQ),onInternalError:(E)=>this.reportHookFailure(E),maxRunDurationMs:this.agent.maxRunDurationMs});N=j;let jQ=MQ.get(Q);if(uJ.set(j,{startedAt:new Date,owner:Y,turn:jQ?{...jQ.text?{text:jQ.text}:{},event:{name:jQ.name}}:hZ(X),joined:[],body:V}),q)mJ.set(j,q),this.follow(j,q);if(Z)$6(this.liveRuns,Z,j.runId);let X$=X?.files??[],I8=this.definesRetention()&&(X$.length>0||l==="turn")?()=>this.expireTurn({scoped:p,files:X$,made:L,owner:Y}):null,{stored:w8,hooks:$J}=this.persistRun(j,QQ,x8,q,TQ,I8);if(t.set(j,w8),mZ.set(Q,{run:j,hooks:$J}),y.has(Q))y.set(Q,{run:j,hooks:$J});if(P.release)j.result().then(P.release,P.release);return Q.ctx?.()?.waitUntil($J),j.toResponse()};try{await this.authorizeRequest(Q,{route:"stream",threadId:Z,body:V});let P=await this.foreignFile([...X?.files??[],...Z?[]:U6($.messages)],Y);if(P)return P;if(D?.cancelled)return Q8();let C=await this.runLimitKey(Q,{owner:Y,threadId:Z}),F=C===null?T:oZ(this.liveRuns).take(C,Z?`thread:${Z}`:`run:${crypto.randomUUID()}`,this.maxConcurrentRuns);if(!F)return RQ(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,U,{req:Q,requested:K?"supersede":z,decide:!K,source:y.has(Q)?"server":"client",turn:X,body:V,limitKey:C}):await U(),O}finally{let R=N,f=O?uZ.get(O):void 0;if(R)R.result().then(F,F);else if(f)f.then(F,F);else F()}}finally{if(D&&nQ.get(G)===D)nQ.delete(G)}}async withThread(Q,J,$,Z){if(Z.requested==="skip"&&SQ.has(Q))return J8(Q);for(;;){let W=await this.underThreadLock(Q,J,$,Z);if(!("waitFor"in W))return W.response;await W.waitFor}}async underThreadLock(Q,J,$,Z){let W=SQ.get(Q)??Promise.resolve(),X,K=new Promise((z)=>{X=z}),G=W.then(()=>K);SQ.set(Q,G),await W;try{let z=this.liveRuns.running({threadId:Q}).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:Q}),N=D?this.liveRuns.get(D.runId):null;if(N)await t.get(N);return{response:await $(pJ)}}let V=Z.intake?.policy??(Z.decide?await this.decideBusy(Q,J,z,Z):Z.requested??"supersede"),Y=(D)=>(t.get(D)??D.result()).then(T,T);if(V==="skip")return{response:J8(Q)};if(V==="queue")return{waitFor:Promise.all(z.map(({run:D})=>Y(D)))};if(V==="join"){let D=z.filter(({info:_})=>this.liveRuns.mayAccess(_.runId,J));if(D.length===0)return{response:a()};let N=D[D.length-1],H=i9(Z.turn,MQ.get(Z.req)),U=H?N.run.join?.(H)??null:null;if(!U)return{waitFor:Y(N.run)};return uJ.get(N.run)?.joined.push(hZ(H)),{response:this.joinResponse(Q,J,N.run,U,H,$,Z)}}if(V==="parallel"){let D=Z.intake??={policy:V,waited:new WeakSet},N=z.filter(({run:P})=>!iZ(P,mJ.get(P)).done&&!D.waited.has(P));if(N.length>0){for(let{run:O}of N)D.waited.add(O);let P=Promise.all(N.map(({run:O})=>iZ(O,mJ.get(O)).promise)),C,F=new Promise((O)=>{C=setTimeout(O,s9)});return{waitFor:Promise.race([P,F]).finally(()=>clearTimeout(C))}}let{max:H,overflow:U}=e9(await this.maxThreadRuns(Z.req,{threadId:Q,owner:J,body:Z.body}));if(z.length>=H){if(U==="queue")return{waitFor:Promise.race(z.map(({run:P})=>Y(P)))};return{response:RQ(429,"too_many_runs",`This conversation already has ${z.length} answers going. Wait for one to finish, or stop it, and send again.`)}}let _=Z.limitKey===null?T:oZ(this.liveRuns).take(Z.limitKey,`run:${crypto.randomUUID()}`,this.maxConcurrentRuns);if(!_)return{response:RQ(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 $({parallel:!0,release:_})}}if(z.some(({info:D})=>!this.liveRuns.mayAccess(D.runId,J)))return{response:a()};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})=>t.get(D))),{response:await $(pJ)}}finally{if(X(),SQ.get(Q)===G)SQ.delete(Q)}}async decideBusy(Q,J,$,Z){let W=await this.busyPolicy(Z.req,{threadId:Q,owner:J,requested:Z.requested,source:Z.source,turn:Z.turn,body:Z.body,running:$.map(({info:X,run:K})=>{let G=uJ.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(!yZ.includes(W))throw TypeError(`AgentController.busyPolicy answers "supersede", "queue", "join", "parallel" or "skip"; got ${JSON.stringify(W)}.`);return W}joinResponse(Q,J,$,Z,W,X,K){let G=(H)=>({kind:"answered",run:H,hooks:t.get(H)??H.result().then(T,T)}),z=Z.taken.then(async(H)=>{if(H||sJ.has($))return null;return this.withThread(Q,J,X,K)}),V=z.then(async(H)=>{if(!H)return sJ.has($)?{kind:"dropped"}:G($);let U=lZ.get(H);if(U)return U;let _=mZ.get(K.req);if(_&&o9(H))return{kind:"answered",..._};return{kind:"refused",error:await YQ.from(H),stored:await this.storeUnanswered(Q,$,W)}},async(H)=>{return this.reportHookFailure(H),{kind:"refused",error:new YQ("The turn started for a joined message failed.",{status:500}),stored:await this.storeUnanswered(Q,$,W)}});if(y.has(K.req))lJ.set(K.req,{run:$,answer:V});async function*Y(){let H=-1;for await(let P of $.frames())H=P.seq,yield P;let U=await z.catch(()=>null),_=await V;if(_.kind==="refused"){if(U?.body?.cancel().catch(T),_.stored&&W.localId)yield{seq:++H,event:{type:"message-id",localId:W.localId,messageId:_.stored.id,message:_.stored}};let P=_.error.status===429;yield{seq:++H,event:{type:"error",error:{code:P?"rate_limited":"unknown",message:`Your message was not answered: ${_.error.message}`,retryable:P}}};return}if(!U?.body)return;try{for await(let P of MZ(U.body))yield P}finally{U.body.cancel().catch(T)}}let D=(async()=>{await $.result().catch(T);let H=await V;if(H.kind==="answered")await H.run.result().catch(T)})(),N=dJ(Y());return uZ.set(N,D),lZ.set(N,V),N}async storeUnanswered(Q,J,$){await t.get(J);let Z=R8($.event?$.event.text:$.text,$.files,$.event);Z.turn=Z.id;try{return await this.store.appendMessages(Q,[Z]),Z}catch(W){return this.reportHookFailure(W),null}}async attach(Q=new w){let J=await zQ(Q,AQ);if(J.error)return m(J);let $=J.body,Z=typeof $.threadId==="string"?$.threadId:eZ(Q,"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(Q,{route:"attach",threadId:Z});let W=$.emptyMiss===!0;if(!await this.threadInScope(Q,Z))return X8(Z,W);let X=typeof $.runId==="string"?$.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(Q)))return a();if(!K)return X8(Z,W);let G=typeof $.runId==="string"?$.runId:void 0,z=G&&G!==K.runId?void 0:P6(Q,$);try{return dJ(this.liveRuns.replay(K.runId,z))}catch(V){if(V instanceof VQ)return M(410,{code:V.code,message:V.message,oldestSeq:V.oldest});if(V instanceof LQ)return M(404,{code:V.code,message:V.message});throw V}}async watch(Q=new w){let J=await zQ(Q,AQ);if(J.error)return m(J);let $=J.body,Z=typeof $.threadId==="string"?$.threadId:eZ(Q,"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(Q,{route:"attach",threadId:Z}),!await this.threadInScope(Q,Z))return M(404,{code:"thread_not_found",message:`Thread ${Z} does not exist here, or has expired.`});let W=await this.runOwner(Q),X=this.liveRuns,K=J6(X),G=null,z=null,V=0,Y=()=>{if(z?.stop(),!G)return;let N=K.get(Z);if(N?.delete(G),N&&N.size===0)K.delete(Z);G=null},D=new ReadableStream({start(N){z=D8(N);let H=(_)=>{if(!X.mayAccess(_,W))return;try{N.enqueue(new TextEncoder().encode(Y8({seq:++V,event:{type:"run-start",runId:_,threadId:Z}}))),z?.touch()}catch{Y()}};G=H;let U=K.get(Z);if(!U)U=new Set,K.set(Z,U);U.add(H);for(let{runId:_}of X.running({threadId:Z}))H(_)},cancel(){Y()}});return Q.rawRequest?.signal?.addEventListener("abort",Y,{once:!0}),new Response(D,{status:200,headers:H8()})}async stop(Q=new w){let J=await zQ(Q,AQ);if(J.error)return m(J);let $=J.body;await this.authorizeRequest(Q,{route:"stop",threadId:typeof $.threadId==="string"?$.threadId:void 0});let Z=await this.runOwner(Q),W=typeof $.runId==="string"?$.runId:void 0;if(!W&&typeof $.clientRunId==="string"){if(W=this.liveRuns.findByClientRunId($.clientRunId)??void 0,!W){let K=nQ.get($.clientRunId);if(K){if(K.owner!==null&&K.owner!==Z)return a();return K.cancelled=!0,{stopped:!0}}}}if(!W&&typeof $.threadId==="string"){let K=this.liveRuns.running({threadId:$.threadId});if(K.length>1){let G=K.filter((V)=>this.liveRuns.mayAccess(V.runId,Z));if(G.length===0)return a();let z=typeof $.reason==="string"?$.reason:void 0;for(let V of G){let Y=this.liveRuns.get(V.runId);if(Y)EQ(Y,{reason:z})}return{stopped:!0}}W=(await this.liveRuns.find({threadId:$.threadId}))?.runId}let X=W?this.liveRuns.get(W):null;if(!X)return{stopped:!1};if(!this.liveRuns.mayAccess(X.runId,Z))return a();return EQ(X,{reason:typeof $.reason==="string"?$.reason:void 0}),{stopped:!0}}attachmentScope(Q,J,$){let Z=this.hooks?.attachmentScope;if(Z)return Z(Q,J,$);let W=Q.ctx()?.user,X=W?.id??W?.publicId;if(X!==void 0&&X!==null&&String(X)!=="")return{key:`user:${String(X)}`};if(J)return{key:`thread:${J}`};return null}attachmentRetention(Q,J){return this.hooks?.attachmentRetention?.(Q,J)??null}definesRetention(){return this.attachmentRetention!==tQ.prototype.attachmentRetention||Boolean(this.hooks?.attachmentRetention)}async sweepAttachments(Q={}){let J=Q.now??new Date,$=Q.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(J,$))try{await nJ(X,W),Z.deleted++}catch(K){Z.failed++,this.reportHookFailure(K)}for(let X of await this.fileOwners.expired?.(J,$)??[])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(Q){let J=this.agent.provider;if(!J.deleteFile)throw Error(`Cannot delete provider file ${Q}: the agent's provider has no deleteFile().`);await J.deleteFile(Q),await this.fileOwners.delete?.(Q)}async expireTurn(Q){let J=this.deletionTargets(),$=new Set,Z=new Set,W=async(X)=>{if($.has(X.id))return;if($.add(X.id),X.fileId)Z.add(X.fileId);try{await nJ(X,J)}catch(K){this.reportHookFailure(K)}};for(let X of Q.made)if(X.deleteAfterTurn)await W(X);for(let X of Q.files){if(X.attachmentId&&Q.scoped){let K=await Q.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===Q.owner)try{await this.deleteProviderFile(X.fileId)}catch(G){this.reportHookFailure(G)}}}}attachmentLimits(Q){let J=this.hooks?.attachmentLimits;if(J)return J(Q);return null}checkUpload(Q,J,$){return this.hooks?.checkUpload?.(Q,J,$)}attachmentDestination(Q,J,$){let Z=this.hooks?.attachmentDestination;if(Z)return Z(Q,J,$);return"both"}async attachmentsFor(Q,J,$={body:{}}){let Z=await this.attachmentScope(Q,J,$);if(!Z)return null;return new QJ(this.attachments,this.attachmentStorage,Z)}async voiceStart(Q=new w){let J=this.voice;if(!J)return iJ();let $=await zQ(Q,AQ);if($.error)return m($);let{sdp:Z,threadId:W,pushToTalk:X}=$.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=aQ($.body,_6),G=typeof W==="string"&&W!==""?W:void 0;await this.authorizeRequest(Q,{route:"stream",threadId:G,body:K});let z=Q.ctx?.()?.user??null,V=await J.start({req:Q,body:K,threadId:G,user:z,pushToTalk:X===!0}),Y=Date.now(),D,N=async(F)=>{if(F!==void 0)console.error("[gemi/ai] a voice session could not start.",F);if(D)await J.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:S(),transcription:{usage:S(),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 N(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(Q,{route:"stream",threadId:H,body:K})}catch(F){throw await N(void 0),F}let U=crypto.randomUUID(),_=V.tools??[];try{if(V.mcp)_=[..._,...await EJ(V.mcp,{user:z,sessionId:U})]}catch(F){return await N(F),M(500,{code:"voice_unavailable",message:"Voice isn't available right now."})}let P={...V.session,tools:[...UQ(J.delegate),...V.session?.tools??[],..._.map((F)=>F.tool)],...X===!0?{turnDetection:null}:{}},C;try{C=await J.realtime.createCall({sdp:Z,session:P,safetyIdentifier:V.safetyIdentifier})}catch(F){await N(F);let O=F instanceof W$&&F.code==="rate_limited";return M(O?429:502,{code:"voice_unavailable",message:"Voice isn't available right now."})}D=C.callId;try{await this.voiceStore.create({id:U,callId:C.callId,threadId:H,owner:await this.runOwner(Q),body:K,startedAt:Y});let{threadId:F,session:O,safetyIdentifier:R,mcp:f,tools:x,...I}=V;return{sessionId:s.start({...I,tools:_,controller:this.constructor,threadId:H,user:z,body:K,call:{realtime:J.realtime,callId:C.callId},sessionId:U,store:this.voiceStore,liveRuns:this.liveRuns,delegate:J.delegate,session:P}).sessionId,sdp:C.sdpAnswer,threadId:H,delegate:J.delegate?.name??_Q,endsAt:Y+(V.limits?.maxDurationMs??900000)}}catch(F){return await N(F),M(500,{code:"voice_unavailable",message:"Voice isn't available right now."})}}async voiceUpdate(Q=new w){if(!this.voice)return iJ();let J=await this.voiceSession(Q);if(J instanceof Response)return J;let $=await zQ(Q,AQ);if($.error)return m($);let Z=aQ($.body,[]);if(await this.authorizeRequest(Q,{route:"stream",threadId:J.threadId,body:Z}),J.endedAt!==void 0)return M(409,{code:"voice_ended",message:"This voice session has ended."});return await this.voiceStore.update(J.id,{body:Z}),s.get(J.id)?.setBody(Z),{updated:!0}}async voiceEnd(Q=new w){let J=this.voice;if(!J)return iJ();let $=await this.voiceSession(Q);if($ instanceof Response)return $;if(await this.authorizeRequest(Q,{route:"stream",threadId:$.threadId,body:$.body}),$.endedAt!==void 0)return{ended:!1};let Z=s.get($.id);if(Z)await Z.end("hangup");else await J.realtime.hangup($.callId),await this.voiceStore.update($.id,{endedAt:Date.now(),endReason:"hangup"});return{ended:!0}}async voiceSession(Q){let J=Q.params?.sessionId,$=typeof J==="string"&&J?await this.voiceStore.get(J):null;if(!$)return M(404,{code:"voice_not_found",message:"No such voice session."});if($.owner!==null&&$.owner!==await this.runOwner(Q))return a();return $}async upload(Q=new w){let J=await Q.rawRequest.formData(),$=J.get("file");if(!($ instanceof Blob))throw Error("upload expects a multipart body with a `file` field.");let Z=$ instanceof File&&$.name?$.name:"upload",W=$.type||"application/octet-stream",X=X6(J.get("body")),K=J.get("threadId");await this.authorizeRequest(Q,{route:"upload",threadId:typeof K==="string"&&K.length>0?K:void 0,body:X});let G=G6(await this.attachmentLimits(Q),$,Z,W);if(G)throw new eJ(G.code,G.message);await this.scopeStore(Q,X);let z=typeof K==="string"&&K.length>0&&await this.store.loadThread(K)!==null?K:void 0,V=await this.runOwner(Q),Y=null,D=(x)=>this.fileOwners.record(x,{owner:V,name:Z,mimeType:W,size:$.size,createdAt:new Date().toISOString(),...Y}),N={body:X,threadId:z},H=await this.checkUpload({name:Z,size:$.size,mimeType:W},Q,N);if(H)throw new eJ(H.code||"upload_refused",H.message);let U=await this.attachmentDestination($,Q,N),_=O6(U,J.get("destination")),P=await this.attachmentScope(Q,z,{body:X});Y=sQ(await this.attachmentRetention(Q,{route:"upload",threadId:z,body:X}),this.turnAttachmentMaxAgeMs);let C=_!=="provider"&&!P;if(C){if(_==="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()`.');L6()}if(_==="provider"||!P){let x=await sZ(this.agent.provider,$);await D(x);let I={fileId:x,name:Z,mimeType:W,size:$.size,destination:"provider"};if(C)I.downgraded="no_scope";return I}let F=_8(),O=await this.attachmentStorage.put({name:O8(F,Z),body:$,contentType:W}),R=_==="both"?await sZ(this.agent.provider,$):void 0;if(R)await D(R);let f={id:F,scopeKey:P.key,fileId:R,objectName:O,name:Z,mimeType:W,size:$.size,createdAt:new Date().toISOString(),destination:_,...Y};return await this.attachments.put(P,f),{fileId:R,attachmentId:F,name:Z,mimeType:W,size:$.size,destination:_}}async foreignFile(Q,J){let $=new Set(Q.map((Z)=>Z.fileId).filter((Z)=>typeof Z==="string"));for(let Z of $){let W=await this.fileOwners.get(Z);if(W?W.owner!==null&&W.owner!==J:this.requireKnownFiles)return C6()}return null}onMessage(Q,J){return this.hooks?.onMessage?.(Q,J)}onToolCall(Q,J){return this.hooks?.onToolCall?.(Q,J)}onToolResult(Q,J,$){return this.hooks?.onToolResult?.(Q,J,$)}onAwaitingInput(Q,J){return this.hooks?.onAwaitingInput?.(Q,J)}redactError(Q,J,$){let Z=this.hooks?.redactError;if(Z)return Z(Q,J,$);return $$(Q,J)}onError(Q,J){return this.hooks?.onError?.(Q,J)}onProviderRetry(Q,J){return this.hooks?.onProviderRetry?.(Q,J)}onStreamComplete(Q,J){return this.hooks?.onStreamComplete?.(Q,J)}reportHookFailure(Q){let J=this.hooks?.reportHookFailure;if(J)try{return J(Q)}catch($){console.error("[gemi/ai] reportHookFailure hook failed",$)}console.error("[gemi/ai] agent controller hook failed",Q)}async dispatchEvent(Q,J){switch(Q.type){case"tool-call":if(!Q.part.partial&&!Q.resent)await this.onToolCall({toolCallId:Q.part.toolCallId,name:String(Q.part.name),input:Q.part.input},J);return;case"tool-result":{let $=Q.part;await this.onToolResult($,J,{toolCallId:$.toolCallId,name:String($.name),input:A8($)});return}case"awaiting-input":await this.onAwaitingInput(Q.pending,J);return;case"error":await this.onError(F8(Q.error),J);return;default:return}}async readThread(Q,J={}){let Z=await(J.scope===null||J.scope===void 0?this.store:W8(this.store,J.scope)).loadThread(Q);if(!Z)return null;let{messages:W}=await this.settleThread(Q,Z,{write:!1});return W}isRunLive(Q,J){return this.liveRuns.get(Q)!==null}async settleThread(Q,J,{write:$}){let Z=(z)=>this.isRunLive(z,Q),W=await IZ(J,Z),X=W.messages,K=[],G=new Map(W.settled.map((z)=>[z.id,z]));if(A6(X)||$)try{let z=await bZ(X,{threadId:Q,store:i.store,isRunLive:Z,outputSchemaFor:(V)=>this.toolNamed(V)?.outputSchema,modelOutputFor:(V,Y)=>M8(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($&&z.orphans.length>0){await vZ(i.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($&&G.size>0)try{await this.store.appendMessages(Q,[...G.values()])}catch(z){this.reportHookFailure(z)}return{messages:X,jobs:K}}jobsBlockMax(){let Q=this.agent.jobs?.contextBlock;if(Q===!1)return 0;return Q?.max??qQ}jobsBlock(Q){return N$(Q,this.jobsBlockMax())}toolNamed(Q){let J=($)=>{for(let Z of $){let W=Z;if(Array.isArray(W.tools)){let X=J(W.tools);if(X)return X}else if(W.name===Q)return W}return};return J(this.agent.tools??[])}follow(Q,J){(async()=>{try{for await(let $ of Q.frames())J.frame($)}catch($){this.reportHookFailure($)}})()}persistRun(Q,J,$,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 Q.result()}catch(N){Z?.close(),await Z?.settled(),G=K(W.notified.then(()=>this.safely(()=>this.onError({code:"unknown",message:N instanceof Error?N.message:String(N),retryable:!1},J))));return}let D=Y.messages;if(Z?.close(D),await Z?.settled(),J.threadId&&D.length>0)try{await this.store.appendMessages(J.threadId,D)}catch(N){this.reportHookFailure(N)}G=K(this.notifyRun(Y,D,J,W))})(),V=z.then(()=>S6(Promise.all([G,$]).then(()=>{}),this.hookHoldMs));return{stored:z,hooks:V}}async notifyRun(Q,J,$,Z){await Z.notified;for(let W of J){if(W.id===Z.id)continue;await this.safely(()=>this.onMessage(W,$))}await this.safely(()=>this.onStreamComplete(Q,$))}async safely(Q){try{await Q()}catch(J){this.reportHookFailure(J)}}}var tJ=["turn","clientRunId","threadId","messages","regenerate","ifBusy"],W6=["text","files","toolResults"];function aQ(Q,J=j8(Q)?tJ:[...tJ,...W6]){let $={};for(let[Z,W]of Object.entries(Q)){if(J.includes(Z))continue;Object.defineProperty($,Z,{value:W,writable:!0,enumerable:!0,configurable:!0})}return $}function X6(Q){if(Q===null)return{};let J;if(typeof Q==="string")try{J=JSON.parse(Q)}catch{throw new rJ("The upload's `body` field is not valid JSON.")}if(J===null||typeof J!=="object"||Array.isArray(J))throw new rJ("The upload's `body` field must be a JSON object.");return aQ(J,tJ)}class rJ extends rQ{constructor(Q){super(Q);this.name="InvalidUploadError",this.payload={api:{status:400,data:{error:{code:"invalid_request",message:Q}}},view:{}}}}async function sZ(Q,J){try{return await Q.upload(J)}catch($){if($ instanceof B8&&K6.has($.status))throw new T8(XQ($).message);throw $}}var K6=new Set([400,413,415,422]);class eJ extends rQ{constructor(Q,J){super(J);this.name="LimitedUploadError",this.payload={api:{status:422,data:{error:{code:Q,message:J}}},view:{}}}}function G6(Q,J,$,Z){if(!Q)return null;let{maxBytes:W,accept:X}=Q;if(typeof W==="number"&&J.size>W)return{code:"file_too_large",message:`${JSON.stringify($)} is ${aZ(J.size)}; the limit is ${aZ(W)}.`};if(X&&X.length>0&&!X.some((K)=>V6(K,$,Z)))return{code:"unsupported_file_type",message:`${JSON.stringify($)} is not a type this chat accepts. Accepted: ${X.join(", ")}.`};return null}function V6(Q,J,$){let Z=Q.trim().toLowerCase();if(!Z)return!1;if(Z.startsWith("."))return J.toLowerCase().endsWith(Z);let W=$.toLowerCase().split(";")[0].trim();if(Z.endsWith("/*"))return W.startsWith(Z.slice(0,-1));return W===Z}function aZ(Q){if(Q<1024)return`${Q} B`;let J=["KB","MB","GB"],$=Q/1024,Z=0;while($>=1024&&Z<J.length-1)$/=1024,Z++;return`${Math.round($*10)/10} ${J[Z]}`}class T8 extends rQ{constructor(Q){super(Q);this.name="RejectedUploadError";let J=/(unsupported|invalid) (extension|file type|format|mime)|supported (extensions|formats?)/i.test(Q)?"unsupported_file_type":"file_rejected";this.payload={api:{status:422,data:{error:{code:J,message:Q}}},view:{}}}}async function zQ(Q,J){let $=Q?.rawRequest;if(!$||$.method==="GET"||$.method==="HEAD"||!$.body)return{body:{}};if(!z6($.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($.headers.get("Content-Length"));if(Number.isFinite(Z)&&Z>J)return tZ(J);let W;try{let K=await Y6($,J);if(K===null)return tZ(J);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 z6(Q){return V8(Q)==="application/json"}async function Y6(Q,J){if(!Number.isFinite(J)||!Q.body)return await Q.text();let $=Q.body.getReader(),Z=[],W=0;for(;;){let{done:G,value:z}=await $.read();if(G)break;if(W+=z.byteLength,W>J)return await $.cancel().catch(T),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 tZ(Q){return{body:{},status:413,code:"body_too_large",error:`The request body is larger than this agent accepts (${Q} bytes).`}}function RQ(Q,J,$){return M(Q,{...eQ(G8(Q),$,Q),code:J})}function m(Q){if(Q.status===413)return RQ(413,Q.code??"body_too_large",Q.error??"");return M(Q.status??400,{code:Q.code??"invalid_request",message:Q.error})}function j8(Q){return Boolean(Q.turn)&&typeof Q.turn==="object"}function D6(Q){let J=j8(Q)?Q.turn:Q,$={};if(typeof J.text==="string")$.text=J.text;if(Array.isArray(J.files)){let Z=H6(J.files);if(typeof Z==="string")return{error:Z};$.files=Z}if(Array.isArray(J.toolResults))$.toolResults=J.toolResults;if(Object.keys($).length===0)return{};if(J===Q.turn&&J.localId!==void 0&&J.localId!==null&&J.localId!==""){let{localId:Z}=J;if(typeof Z!=="string")return{error:"turn.localId must be a string."};if(Z.length>rZ)return{error:`turn.localId is longer than ${rZ} characters.`};$.localId=Z}return{turn:$}}var rZ=200;function H6(Q){let J=[];for(let[$,Z]of Q.entries()){let W=`turn.files[${$}]`;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(oQ))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(oQ))return`${W}.attachmentId is not a gemi attachment id: it must start with "${oQ}".`;if(!K&&!G)return`${W} has neither a \`fileId\` nor an \`attachmentId\`. Send the ids the upload response answered.`;J.push({...K?{fileId:K}:{},...G?{attachmentId:G}:{},...z!==void 0?{name:z}:{},...V!==void 0?{mimeType:V}:{}})}return J}function P6(Q,J){if(typeof J.from==="number"&&Number.isFinite(J.from))return Math.max(0,Math.floor(J.from));if(typeof J.cursor==="number"&&Number.isFinite(J.cursor)){let Z=Math.floor(J.cursor);if(Z>=0)return Z+1;return}let $=Q?.rawRequest?.headers?.get("Last-Event-ID");if($){let Z=Number.parseInt($,10);if(Number.isFinite(Z))return Math.max(0,Z+1)}return}function eZ(Q,J){let $=Q?.search?.get(J);return typeof $==="string"?$:void 0}function N6(Q){let J=Z$(Q);for(let $=Q.length-1;$>=0;$--){let Z=Q[$];if(Z.role!=="user"||J.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:$,turn:{...W?{text:W}:{},...X.length>0?{files:X}:{}}}}return null}function Q8(){return M(409,{code:"stopped",message:"The turn was stopped before it started."})}function F6(Q){let J=Q.event;if(Q.text!==void 0||Q.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 J!=="object"||J===null||typeof J.name!=="string"||!m9.test(J.name))throw TypeError('AgentController.startTurn\'s `event.name` must be letters, digits and `.`, `_`, `:`, `-` (at most 64), like "job-settled".');if(J.text!==void 0&&typeof J.text!=="string")throw TypeError("AgentController.startTurn's `event.text` must be a string.");let $;if(J.data!==void 0)try{$=JSON.parse(JSON.stringify(J.data))}catch(Z){throw TypeError(`AgentController.startTurn's \`event.data\` is not JSON: ${String(Z)}`)}return{name:J.name,...J.text?{text:J.text}:{},...$!==void 0?{data:$}:{}}}function J8(Q){return M(409,{code:E8,message:`Thread ${Q} has a run going, and this turn was not to interrupt it.`})}function a(){return M(403,eQ("permission","This run belongs to someone else.",403))}function C6(){return M(403,eQ("permission","A file in this turn was uploaded by someone else.",403))}function U6(Q){if(!Array.isArray(Q))return[];let J=[];for(let $ of Q){let Z=$?.content;if(!Array.isArray(Z))continue;for(let W of Z)if(W&&typeof W==="object"&&typeof W.fileId==="string")J.push({fileId:W.fileId})}return J}var _6=["sdp","threadId","pushToTalk"];function iJ(){return M(404,{code:"voice_not_enabled",message:"This agent has no voice: set `voice` on its controller."})}function M(Q,J){return new Response(JSON.stringify({error:J}),{status:Q,headers:{"Content-Type":"application/json"}})}function O6(Q,J){if(typeof J!=="string"||J.length===0)return Q;if(J!=="both"&&J!=="provider"&&J!=="storage")throw Error(`Unknown attachment destination "${J}". Expected "both", "provider" or "storage".`);if(J===Q||Q==="both"&&J==="storage")return J;if(Q==="both"&&J==="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 "${J}" destination, but the server's policy for it is "${Q}", and a client hint may only ask for "storage" under a "both" policy. Change \`attachmentDestination()\` if the file really should go there.`)}var $8=!1;function L6(){if($8)return;$8=!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 B6=2147483647;function S6(Q,J){let $=Q.then(()=>{},()=>{});if(!(J<=B6))return $;let Z,W=new Promise((X)=>{Z=setTimeout(X,J)});return Promise.race([$,W]).finally(()=>clearTimeout(Z))}var Z8=!1;function M6(Q){if(Z8||Bun.env.NODE_ENV!=="production")return;if(!(Q instanceof Q$))return;Z8=!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 A6(Q){return Q.some((J)=>J.content.some(($)=>$.type==="tool-result"&&$.status==="running"))}function W8(Q,J){if(typeof J!=="string"||J==="")throw TypeError("A store scope is a non-empty string.");if(!Q.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 Q.forScope(J)}function X8(Q,J=!1){if(J)return new Response(null,{status:204});return M(404,{code:"no_live_run",message:`No run in progress for thread ${Q} in this process.`})}export{q6 as windowMessages,UQ as voiceTools,j6 as turnStarts,J0 as toRealtimeUsage,$9 as toAgentTools,k6 as supportsStrict,x6 as splitTurns,u6 as settleSummaries,E6 as s,$$ as redactError,r6 as parsePartialJson,I6 as messageSize,FQ as measureUsage,EJ as mcpVoiceTools,IJ as liveRuns,OQ as keepSummary,Z0 as isCallNotFound,Z$ as injectedMessageIds,FJ as generate,P9 as evalChain,Z6 as defineAgentHooks,TJ as defaultVoiceStore,p6 as defaultUsageLimitStore,c6 as defaultSummaryStore,t6 as defaultPromptCacheKey,J$ as defaultNonceStore,wJ as defaultFileOwners,JJ as defaultAttachmentStore,hJ as defaultAgentStore,lQ as VoiceHangup,s as VoiceBridge,T6 as Usage,UJ as ToolNamespace,o as ToolError,s6 as ToolArgumentsTooLongError,i6 as Skill,QJ as ScopedAttachments,d6 as SKILLS_NAMESPACE,vJ as RedisReceiptStore,P8 as RedisNonceStore,e6 as RealtimeSideband,W$ as RealtimeRequestError,$0 as RealtimeClient,D$ as Prompt,N8 as PrismaNonceStore,l6 as PendingEscalation,W0 as OpenAIProvider,BJ as OpenAIImageProvider,kJ as MemoryVoiceSessionStore,m6 as MemoryUsageLimitStore,g6 as MemorySummaryStore,bJ as MemoryReceiptStore,Q$ as MemoryNonceStore,iQ as MemoryLiveRuns,dQ as MemoryFileOwners,mQ as MemoryCircuitStore,L8 as MemoryAttachmentStore,BQ as MemoryAgentStore,_$ as MemoryAgentJobStore,b$ as MEMORY_NAMESPACE,LQ as LiveRunNotFoundError,L$ as JobsRequireThreadError,O$ as JobHandle,R6 as JSONSchemaError,U8 as InvalidAttachmentScopeError,j$ as InMemoryAgentMemoryStore,cQ as ImageRequestError,uQ as ImageProvider,_J as ImageModel,VQ as FrameCursorEvictedError,CQ as FallbackProvider,f$ as FakeAgentMemoryStore,hQ as Eval,jJ as DatabaseAgentStore,zJ as DatabaseAgentMemoryStore,GJ as DatabaseAgentJobStore,Q0 as DEFAULT_TRANSCRIPTION_MODEL,T$ as DEFAULT_MEMORY_MAX_TOKENS,q$ as DEFAULT_MEMORY_LIMITS,b6 as DEFAULT_MAX_SUMMARY_TOKENS,n6 as DEFAULT_MAX_RUN_DURATION_MS,B$ as DEFAULT_JOB_DEADLINE_MS,qQ as DEFAULT_JOBS_CONTEXT_MAX,_Q as DEFAULT_DELEGATE_NAME,w6 as DEFAULT_CONTEXT_WINDOW_STEP,f6 as DEFAULT_CONTEXT_WINDOW_NOTE,v6 as DEFAULT_COMPACT_TRIGGER_TOKENS,y6 as DEFAULT_COMPACT_INSTRUCTIONS,h6 as COMPACT_SUMMARY_HEADER,G0 as AzureOpenAIProvider,SJ as AzureOpenAIImageProvider,K0 as AzureAnthropicProvider,C8 as AttachmentNotFoundError,X0 as AnthropicProvider,YQ as AgentTurnError,gQ as AgentTool,o6 as AgentRunError,RJ as AgentProvider,x$ as AgentMemoryRefusedError,I$ as AgentMemoryConflictError,w$ as AgentMemories,i as AgentJobs,KJ as AgentJobDeadlineSweep,S$ as AgentJob,tQ as AgentController,a6 as Agent};
337
337
 
338
- //# debugId=D7E332ABAB13DB0464756E2164756E21
338
+ //# debugId=6F93632D8EE8913B64756E2164756E21