gemi 0.210.0 → 0.210.1

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 (205) 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-zzs96hc8.js → chunk-0exm7bsw.js} +2 -2
  9. package/dist/{chunk-zzs96hc8.js.map → chunk-0exm7bsw.js.map} +1 -1
  10. package/dist/{chunk-kax9ghny.js → chunk-0nzz7ftq.js} +2 -2
  11. package/dist/{chunk-kax9ghny.js.map → chunk-0nzz7ftq.js.map} +1 -1
  12. package/dist/{chunk-arzp5dne.js → chunk-18v3qyzp.js} +2 -2
  13. package/dist/{chunk-arzp5dne.js.map → chunk-18v3qyzp.js.map} +1 -1
  14. package/dist/{chunk-p608rrfc.js → chunk-24mk3gn3.js} +3 -3
  15. package/dist/{chunk-p608rrfc.js.map → chunk-24mk3gn3.js.map} +1 -1
  16. package/dist/{chunk-t9gc6mhq.js → chunk-2swfxn2c.js} +2 -2
  17. package/dist/{chunk-t9gc6mhq.js.map → chunk-2swfxn2c.js.map} +1 -1
  18. package/dist/chunk-2x8e3j7j.js +10 -0
  19. package/dist/{chunk-9zatr0vt.js.map → chunk-2x8e3j7j.js.map} +3 -3
  20. package/dist/{chunk-yn3pf1fp.js → chunk-3c45f8f3.js} +2 -2
  21. package/dist/{chunk-yn3pf1fp.js.map → chunk-3c45f8f3.js.map} +1 -1
  22. package/dist/{chunk-2jbdbvd8.js → chunk-3r8zkpes.js} +2 -2
  23. package/dist/{chunk-2jbdbvd8.js.map → chunk-3r8zkpes.js.map} +1 -1
  24. package/dist/{chunk-yzbj11dd.js → chunk-4g7n30zy.js} +2 -2
  25. package/dist/{chunk-yzbj11dd.js.map → chunk-4g7n30zy.js.map} +1 -1
  26. package/dist/{chunk-h1f4f9wx.js → chunk-56z4jd8t.js} +2 -2
  27. package/dist/{chunk-h1f4f9wx.js.map → chunk-56z4jd8t.js.map} +1 -1
  28. package/dist/{chunk-dje6exhs.js → chunk-5ncc9tn6.js} +2 -2
  29. package/dist/{chunk-dje6exhs.js.map → chunk-5ncc9tn6.js.map} +1 -1
  30. package/dist/{chunk-vrpsgq3x.js → chunk-5ra8x6ax.js} +2 -2
  31. package/dist/{chunk-vrpsgq3x.js.map → chunk-5ra8x6ax.js.map} +1 -1
  32. package/dist/{chunk-wy87gc0b.js → chunk-6d807fgx.js} +3 -3
  33. package/dist/{chunk-wy87gc0b.js.map → chunk-6d807fgx.js.map} +1 -1
  34. package/dist/{chunk-kbkyde5f.js → chunk-6f11bb3s.js} +2 -2
  35. package/dist/{chunk-kbkyde5f.js.map → chunk-6f11bb3s.js.map} +1 -1
  36. package/dist/{chunk-m60st4nt.js → chunk-6hkwvezk.js} +2 -2
  37. package/dist/{chunk-m60st4nt.js.map → chunk-6hkwvezk.js.map} +1 -1
  38. package/dist/{chunk-716832vw.js → chunk-6wrk51tb.js} +2 -2
  39. package/dist/{chunk-716832vw.js.map → chunk-6wrk51tb.js.map} +1 -1
  40. package/dist/{chunk-r5ggnywk.js → chunk-768yza4f.js} +2 -2
  41. package/dist/{chunk-r5ggnywk.js.map → chunk-768yza4f.js.map} +1 -1
  42. package/dist/{chunk-fv6ncgbc.js → chunk-7m20yym1.js} +2 -2
  43. package/dist/{chunk-fv6ncgbc.js.map → chunk-7m20yym1.js.map} +1 -1
  44. package/dist/{chunk-9qyedsvw.js → chunk-8wxt3v9r.js} +3 -3
  45. package/dist/{chunk-9qyedsvw.js.map → chunk-8wxt3v9r.js.map} +1 -1
  46. package/dist/{chunk-y16vp7yf.js → chunk-9a3wbbr6.js} +2 -2
  47. package/dist/{chunk-y16vp7yf.js.map → chunk-9a3wbbr6.js.map} +1 -1
  48. package/dist/{chunk-8b2421h0.js → chunk-9cjmtx61.js} +2 -2
  49. package/dist/{chunk-8b2421h0.js.map → chunk-9cjmtx61.js.map} +1 -1
  50. package/dist/{chunk-ntcj2sgv.js → chunk-a7svhrg6.js} +3 -3
  51. package/dist/{chunk-ntcj2sgv.js.map → chunk-a7svhrg6.js.map} +1 -1
  52. package/dist/{chunk-bhc9vk13.js → chunk-akh97aw9.js} +1 -1
  53. package/dist/{chunk-9d8tz60r.js → chunk-as9cs2bk.js} +1 -1
  54. package/dist/{chunk-hmccxtd3.js → chunk-axgpe682.js} +2 -2
  55. package/dist/{chunk-hmccxtd3.js.map → chunk-axgpe682.js.map} +1 -1
  56. package/dist/{chunk-fsae9dgb.js → chunk-b5v00jn8.js} +2 -2
  57. package/dist/{chunk-fsae9dgb.js.map → chunk-b5v00jn8.js.map} +1 -1
  58. package/dist/{chunk-wcpqn1pg.js → chunk-b9q72ssw.js} +2 -2
  59. package/dist/{chunk-wcpqn1pg.js.map → chunk-b9q72ssw.js.map} +1 -1
  60. package/dist/{chunk-rhyhxgxg.js → chunk-bf4wqp2f.js} +2 -2
  61. package/dist/{chunk-rhyhxgxg.js.map → chunk-bf4wqp2f.js.map} +1 -1
  62. package/dist/{chunk-v10kckwp.js → chunk-bxtv9am0.js} +4 -4
  63. package/dist/{chunk-v10kckwp.js.map → chunk-bxtv9am0.js.map} +1 -1
  64. package/dist/{chunk-bdzj9znx.js → chunk-c94zdk4r.js} +3 -3
  65. package/dist/{chunk-bdzj9znx.js.map → chunk-c94zdk4r.js.map} +1 -1
  66. package/dist/{chunk-641fns6j.js → chunk-cdt888qf.js} +2 -2
  67. package/dist/{chunk-641fns6j.js.map → chunk-cdt888qf.js.map} +1 -1
  68. package/dist/{chunk-094hbhc8.js → chunk-cgjdxxwy.js} +2 -2
  69. package/dist/{chunk-094hbhc8.js.map → chunk-cgjdxxwy.js.map} +1 -1
  70. package/dist/{chunk-cfbhhfkv.js → chunk-d675g712.js} +3 -3
  71. package/dist/{chunk-cfbhhfkv.js.map → chunk-d675g712.js.map} +1 -1
  72. package/dist/{chunk-tjfvkzq8.js → chunk-d79zfm40.js} +1 -1
  73. package/dist/{chunk-xt90xbes.js → chunk-d8nxkc90.js} +2 -2
  74. package/dist/{chunk-xt90xbes.js.map → chunk-d8nxkc90.js.map} +1 -1
  75. package/dist/{chunk-ewhgsw1n.js → chunk-dp8nmks0.js} +2 -2
  76. package/dist/{chunk-ewhgsw1n.js.map → chunk-dp8nmks0.js.map} +1 -1
  77. package/dist/{chunk-q634cwbc.js → chunk-ds5adkcf.js} +3 -3
  78. package/dist/{chunk-q634cwbc.js.map → chunk-ds5adkcf.js.map} +1 -1
  79. package/dist/{chunk-jggtz103.js → chunk-f1jq1mp9.js} +2 -2
  80. package/dist/{chunk-jggtz103.js.map → chunk-f1jq1mp9.js.map} +1 -1
  81. package/dist/{chunk-ad0dx73f.js → chunk-f7bayqs7.js} +2 -2
  82. package/dist/{chunk-ad0dx73f.js.map → chunk-f7bayqs7.js.map} +1 -1
  83. package/dist/{chunk-zcx8n3mk.js → chunk-frjavybg.js} +2 -2
  84. package/dist/{chunk-zcx8n3mk.js.map → chunk-frjavybg.js.map} +1 -1
  85. package/dist/{chunk-zv6a6w1v.js → chunk-fypj6z8t.js} +2 -2
  86. package/dist/{chunk-zv6a6w1v.js.map → chunk-fypj6z8t.js.map} +1 -1
  87. package/dist/{chunk-mxedsqbe.js → chunk-g6z6shvz.js} +3 -3
  88. package/dist/{chunk-mxedsqbe.js.map → chunk-g6z6shvz.js.map} +1 -1
  89. package/dist/{chunk-b51a77kv.js → chunk-gg4q59q1.js} +2 -2
  90. package/dist/{chunk-b51a77kv.js.map → chunk-gg4q59q1.js.map} +1 -1
  91. package/dist/{chunk-101rvvje.js → chunk-gk2k76tn.js} +3 -3
  92. package/dist/{chunk-101rvvje.js.map → chunk-gk2k76tn.js.map} +1 -1
  93. package/dist/{chunk-t0xfzpfa.js → chunk-h4rmpnkv.js} +2 -2
  94. package/dist/{chunk-t0xfzpfa.js.map → chunk-h4rmpnkv.js.map} +1 -1
  95. package/dist/{chunk-12gthjxx.js → chunk-hchyarr4.js} +1 -1
  96. package/dist/{chunk-2k438dp6.js → chunk-j72wr9ck.js} +2 -2
  97. package/dist/{chunk-2k438dp6.js.map → chunk-j72wr9ck.js.map} +1 -1
  98. package/dist/{chunk-p27ft91c.js → chunk-jcsm6g58.js} +1 -1
  99. package/dist/{chunk-q7x7ddw0.js → chunk-jp0d4qhn.js} +2 -2
  100. package/dist/{chunk-q7x7ddw0.js.map → chunk-jp0d4qhn.js.map} +1 -1
  101. package/dist/{chunk-n0sbg84n.js → chunk-jzspg75a.js} +2 -2
  102. package/dist/{chunk-n0sbg84n.js.map → chunk-jzspg75a.js.map} +1 -1
  103. package/dist/chunk-kpww16c7.js +5 -0
  104. package/dist/{chunk-pag82mxh.js.map → chunk-kpww16c7.js.map} +1 -1
  105. package/dist/{chunk-1vnbw1d8.js → chunk-kwvx36xw.js} +2 -2
  106. package/dist/{chunk-1vnbw1d8.js.map → chunk-kwvx36xw.js.map} +1 -1
  107. package/dist/{chunk-w92n83g2.js → chunk-m4wagwhr.js} +2 -2
  108. package/dist/{chunk-w92n83g2.js.map → chunk-m4wagwhr.js.map} +1 -1
  109. package/dist/{chunk-n65hk6bq.js → chunk-mcqzgyvf.js} +2 -2
  110. package/dist/{chunk-n65hk6bq.js.map → chunk-mcqzgyvf.js.map} +1 -1
  111. package/dist/{chunk-dm6tkkwv.js → chunk-n5zq7ckd.js} +2 -2
  112. package/dist/{chunk-dm6tkkwv.js.map → chunk-n5zq7ckd.js.map} +1 -1
  113. package/dist/{chunk-tj8wbxyz.js → chunk-njfbfx3k.js} +2 -2
  114. package/dist/{chunk-tj8wbxyz.js.map → chunk-njfbfx3k.js.map} +1 -1
  115. package/dist/{chunk-hbdqv48k.js → chunk-pce2vqtc.js} +2 -2
  116. package/dist/{chunk-hbdqv48k.js.map → chunk-pce2vqtc.js.map} +1 -1
  117. package/dist/{chunk-b1y54j6v.js → chunk-pmyw9t15.js} +2 -2
  118. package/dist/{chunk-b1y54j6v.js.map → chunk-pmyw9t15.js.map} +1 -1
  119. package/dist/{chunk-mtf5kzza.js → chunk-q34hyv6y.js} +2 -2
  120. package/dist/{chunk-mtf5kzza.js.map → chunk-q34hyv6y.js.map} +1 -1
  121. package/dist/{chunk-3rgf7rsy.js → chunk-qsf3t0rc.js} +3 -3
  122. package/dist/{chunk-3rgf7rsy.js.map → chunk-qsf3t0rc.js.map} +1 -1
  123. package/dist/{chunk-a76a7869.js → chunk-qymdnzpy.js} +2 -2
  124. package/dist/{chunk-a76a7869.js.map → chunk-qymdnzpy.js.map} +1 -1
  125. package/dist/{chunk-w8cbs1kg.js → chunk-r6e5jwjm.js} +16 -16
  126. package/dist/{chunk-w8cbs1kg.js.map → chunk-r6e5jwjm.js.map} +4 -4
  127. package/dist/{chunk-wkh9xcdq.js → chunk-rarqef1m.js} +2 -2
  128. package/dist/{chunk-wkh9xcdq.js.map → chunk-rarqef1m.js.map} +1 -1
  129. package/dist/{chunk-3raywsbj.js → chunk-rs3krbw9.js} +2 -2
  130. package/dist/{chunk-3raywsbj.js.map → chunk-rs3krbw9.js.map} +1 -1
  131. package/dist/{chunk-agrr8f8y.js → chunk-rzmngbn5.js} +2 -2
  132. package/dist/{chunk-agrr8f8y.js.map → chunk-rzmngbn5.js.map} +1 -1
  133. package/dist/{chunk-8ty6yp6r.js → chunk-s158qvjg.js} +3 -3
  134. package/dist/{chunk-8ty6yp6r.js.map → chunk-s158qvjg.js.map} +1 -1
  135. package/dist/{chunk-h4byt0x3.js → chunk-sgqfg5gg.js} +2 -2
  136. package/dist/{chunk-h4byt0x3.js.map → chunk-sgqfg5gg.js.map} +1 -1
  137. package/dist/{chunk-enq03rgh.js → chunk-sry4r3kf.js} +2 -2
  138. package/dist/{chunk-enq03rgh.js.map → chunk-sry4r3kf.js.map} +1 -1
  139. package/dist/{chunk-zrqzxc50.js → chunk-t3vgqv9a.js} +2 -2
  140. package/dist/{chunk-zrqzxc50.js.map → chunk-t3vgqv9a.js.map} +1 -1
  141. package/dist/{chunk-3wsmgdcr.js → chunk-t8ghxzva.js} +3 -3
  142. package/dist/{chunk-3wsmgdcr.js.map → chunk-t8ghxzva.js.map} +1 -1
  143. package/dist/{chunk-jr9y6k90.js → chunk-vj9f634z.js} +1 -1
  144. package/dist/{chunk-achvynaf.js → chunk-wfpvsgfy.js} +2 -2
  145. package/dist/{chunk-achvynaf.js.map → chunk-wfpvsgfy.js.map} +1 -1
  146. package/dist/{chunk-1agwddws.js → chunk-xdrnzs3t.js} +2 -2
  147. package/dist/{chunk-1agwddws.js.map → chunk-xdrnzs3t.js.map} +1 -1
  148. package/dist/{chunk-8gyq2etb.js → chunk-y10tys3s.js} +2 -2
  149. package/dist/{chunk-8gyq2etb.js.map → chunk-y10tys3s.js.map} +1 -1
  150. package/dist/{chunk-p507sdj8.js → chunk-ybdmkzb9.js} +2 -2
  151. package/dist/{chunk-p507sdj8.js.map → chunk-ybdmkzb9.js.map} +1 -1
  152. package/dist/{chunk-raejxs3y.js → chunk-z0c08ete.js} +2 -2
  153. package/dist/{chunk-raejxs3y.js.map → chunk-z0c08ete.js.map} +1 -1
  154. package/dist/{chunk-6zcqa5fz.js → chunk-z7r6td69.js} +2 -2
  155. package/dist/{chunk-6zcqa5fz.js.map → chunk-z7r6td69.js.map} +1 -1
  156. package/dist/{chunk-qc7x8q1q.js → chunk-zbm7njvf.js} +2 -2
  157. package/dist/{chunk-qc7x8q1q.js.map → chunk-zbm7njvf.js.map} +1 -1
  158. package/dist/config/index.js +1 -1
  159. package/dist/console/run.js +2 -2
  160. package/dist/console/run.js.map +1 -1
  161. package/dist/container/index.js +2 -2
  162. package/dist/container/index.js.map +1 -1
  163. package/dist/database/index.js +2 -2
  164. package/dist/database/index.js.map +1 -1
  165. package/dist/email/index.js +2 -2
  166. package/dist/email/index.js.map +1 -1
  167. package/dist/facades/index.js +2 -2
  168. package/dist/facades/index.js.map +1 -1
  169. package/dist/foundation/index.js +2 -2
  170. package/dist/foundation/index.js.map +1 -1
  171. package/dist/http/index.js +2 -2
  172. package/dist/http/index.js.map +1 -1
  173. package/dist/i18n/dictionaryRuntime.js +2 -2
  174. package/dist/i18n/dictionaryRuntime.js.map +1 -1
  175. package/dist/i18n/index.js +2 -2
  176. package/dist/i18n/index.js.map +1 -1
  177. package/dist/kernel/index.js +2 -2
  178. package/dist/kernel/index.js.map +1 -1
  179. package/dist/orm/index.js +2 -2
  180. package/dist/orm/index.js.map +1 -1
  181. package/dist/probe/index.js +2 -2
  182. package/dist/probe/index.js.map +1 -1
  183. package/dist/server/index.js +2 -2
  184. package/dist/server/index.js.map +1 -1
  185. package/dist/services/index.js +2 -2
  186. package/dist/services/index.js.map +1 -1
  187. package/dist/services/queue/work.js +2 -2
  188. package/dist/services/queue/work.js.map +1 -1
  189. package/dist/services/router/ViewRouteDispatcher.d.ts.map +1 -1
  190. package/dist/services/router/globalMiddleware.d.ts.map +1 -1
  191. package/dist/services/router/matchViewRoute.d.ts +8 -0
  192. package/dist/services/router/matchViewRoute.d.ts.map +1 -1
  193. package/dist/stats/route-table.js +1 -1
  194. package/dist/support/index.js +2 -2
  195. package/dist/support/index.js.map +1 -1
  196. package/dist/vitest/index.js +1 -1
  197. package/package.json +1 -1
  198. package/dist/chunk-9zatr0vt.js +0 -10
  199. package/dist/chunk-pag82mxh.js +0 -5
  200. /package/dist/{chunk-bhc9vk13.js.map → chunk-akh97aw9.js.map} +0 -0
  201. /package/dist/{chunk-9d8tz60r.js.map → chunk-as9cs2bk.js.map} +0 -0
  202. /package/dist/{chunk-tjfvkzq8.js.map → chunk-d79zfm40.js.map} +0 -0
  203. /package/dist/{chunk-12gthjxx.js.map → chunk-hchyarr4.js.map} +0 -0
  204. /package/dist/{chunk-p27ft91c.js.map → chunk-jcsm6g58.js.map} +0 -0
  205. /package/dist/{chunk-jr9y6k90.js.map → chunk-vj9f634z.js.map} +0 -0
package/dist/ai/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  // @bun
2
- import{ca as wQ,da as yQ,ea as vQ,fa as z6,ga as D6,ha as H6,ia as y$,ja as P6,ka as F6,la as V$,ma as N6,na as O6,oa as C6,pa as U6}from"../chunk-t9gc6mhq.js";import{$c as a9,Ac as zZ,Bc as JQ,Dc as $Q,Ec as GQ,Fc as WQ,Gc as KQ,Hc as XQ,Ic as YQ,Jc as VQ,Kc as zQ,Lc as DQ,Mc as HQ,Nc as PQ,Oc as FQ,Qc as b$,Rc as u9,Sc as c9,Tc as m9,Uc as p9,Vc as l9,Wc as i9,Xc as d9,Yc as n9,Zc as o9,_c as s9,ad as YJ,bd as t9,cd as iZ,dd as r9,ed as dZ,fd as e9,gd as J6,hd as $6,ic as w$,id as AJ,jc as yZ,jd as J$,kc as vZ,kd as Q6,lc as f$,ld as Z6,md as nZ,nd as W6,od as K6,pc as IQ,pd as X6,qc as RQ,qd as G6,rc as WJ,rd as Y6,sc as g9,sd as V6,tc as f,td as rJ,uc as t$,vc as r$,xc as e$,yc as y,zc as VZ}from"../chunk-zrqzxc50.js";import{Gd as g,Hd as q$,Kd as hZ,Ld as gZ,Md as uZ,Nd as fJ,Od as cZ,Pd as vJ,Qd as mZ,Rd as pZ,Sd as hJ,Td as lZ,Yd as Y$,Zd as s,xd as gQ,yd as A,zd as k}from"../chunk-8gyq2etb.js";import{oe as i$}from"../chunk-hcysexst.js";import"../chunk-zcx8n3mk.js";import{Bj as U$,Cj as wZ,Ej as fZ,Fj as qZ,Gj as bZ,Pi as j,ni as TZ,qi as xZ,wj as IZ}from"../chunk-wy87gc0b.js";import{Hj as jZ,Jj as bJ,Kj as yJ}from"../chunk-xt90xbes.js";import{Tj as h}from"../chunk-w92n83g2.js";import{Vj as y9,Wj as v9,Xj as h9}from"../chunk-1agwddws.js";import"../chunk-r5ggnywk.js";import"../chunk-n65hk6bq.js";import"../chunk-094hbhc8.js";import{$k as o,_k as n,nl as BJ}from"../chunk-9qyedsvw.js";import"../chunk-h1f4f9wx.js";import"../chunk-qc7x8q1q.js";import{em as eQ}from"../chunk-p608rrfc.js";import"../chunk-achvynaf.js";import"../chunk-ad0dx73f.js";import{Bm as mJ}from"../chunk-mtf5kzza.js";import"../chunk-a76a7869.js";import{existsSync as $8,readdirSync as _6,readFileSync as m$}from"fs";import{isAbsolute as Q8,join as NJ,relative as Z8,sep as W8}from"path";var p$="prompts.json",K8=/\{\{>\s*([\w./-]+)\s*\}\}/g,g$=/\{\{(\w+)\}\}/g,X8=/^[\w-]+(\/[\w-]+)*$/,u$={dir:"app/agents",shared:"prompts"},CJ={},uJ=new Map,OJ;function G8(){if(OJ===void 0){let J=NJ(mJ(),"dist","server",p$);OJ=$8(J)?JSON.parse(m$(J,"utf8")):null}return OJ??null}function Y8(J){return J.replace(/\r?\n$/,"")}function c$(){return CJ.cache??Bun.env.NODE_ENV==="production"}function V8(J,$){if(!X8.test(J))throw Error(`"${J}" is not a prompt name. Use letters, digits, "-" and "_", with "/" between folders.`);let Q=$.dir??CJ.dir??u$.dir,Z=Q8(Q)?Q:NJ(process.cwd(),Q),W=J.includes("/")?`${J}.md`:NJ($.shared??CJ.shared??u$.shared,`${J}.md`);return NJ(Z,W)}function z8(J,$){let Q=V8(J,$),Z=c$()?uJ.get(Q):void 0;if(Z!==void 0)return Z;let W=Bun.env.NODE_ENV==="production";if(W){let X=G8()?.[Z8(mJ(),Q).split(W8).join("/")];if(X!==void 0)return X}let K;try{K=Y8(m$(Q,"utf8"))}catch(X){if(X.code==="ENOENT"){let G=W?` or in dist/server/${p$}`:"";throw Error(`The prompt "${J}" does not exist (looked for ${Q}${G}).`)}throw X}if(c$())uJ.set(Q,K);return K}function cJ(J,$,Q){if($.includes(J))throw Error(`The prompt "${J}" includes itself: ${[...$,J].join(" > ")}.`);return z8(J,Q).replace(K8,(Z,W)=>cJ(W,[...$,J],Q))}class l${static configure(J){CJ={...J},uJ.clear(),OJ=void 0}static render(J,$={},Q={}){return cJ(J,[],Q).replace(g$,(Z,W)=>{if(!Object.hasOwn($,W))throw Error(`The prompt "${J}" has no value for {{${W}}}.`);return String($[W])})}static placeholders(J,$={}){let Q=[...cJ(J,[],$).matchAll(g$)].map((Z)=>Z[1]);return[...new Set(Q)]}}class pJ extends i${name="AgentJobDeadlineSweep";cron="* * * * *";async callback(){while(await y.sweep({limit:100})===100);}}var LJ=20,D8=300,H8=200;function n$(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)=>!f(K.state)).sort(Q),...J.filter((K)=>f(K.state)).sort(Q)].slice(0,$).map((K)=>{let X=[`- ${K.id} (${K.toolName})`];if(K.state==="waiting")X.push(`waiting for ${(K.after??[]).join(", ")} since ${UJ(K.createdAt)}`);else if(K.state==="running")X.push(`running since ${UJ(K.createdAt)}`);else if(K.state==="ok")X.push(`finished at ${UJ(K.settledAt??K.updatedAt)}`);else{let G=K.error?`${K.error.code}: ${d$(K.error.message,H8)}`:"failed";X.push(`failed at ${UJ(K.settledAt??K.updatedAt)} (${G})`)}if(K.summary!==void 0)X.push(`summary: ${d$(JSON.stringify(K.summary),D8)}`);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{ca as wQ,da as yQ,ea as vQ,fa as z6,ga as D6,ha as H6,ia as y$,ja as P6,ka as F6,la as V$,ma as N6,na as O6,oa as C6,pa as U6}from"../chunk-2swfxn2c.js";import{$c as a9,Ac as zZ,Bc as JQ,Dc as $Q,Ec as GQ,Fc as WQ,Gc as KQ,Hc as XQ,Ic as YQ,Jc as VQ,Kc as zQ,Lc as DQ,Mc as HQ,Nc as PQ,Oc as FQ,Qc as b$,Rc as u9,Sc as c9,Tc as m9,Uc as p9,Vc as l9,Wc as i9,Xc as d9,Yc as n9,Zc as o9,_c as s9,ad as YJ,bd as t9,cd as iZ,dd as r9,ed as dZ,fd as e9,gd as J6,hd as $6,ic as w$,id as AJ,jc as yZ,jd as J$,kc as vZ,kd as Q6,lc as f$,ld as Z6,md as nZ,nd as W6,od as K6,pc as IQ,pd as X6,qc as RQ,qd as G6,rc as WJ,rd as Y6,sc as g9,sd as V6,tc as f,td as rJ,uc as t$,vc as r$,xc as e$,yc as y,zc as VZ}from"../chunk-t3vgqv9a.js";import{Gd as g,Hd as q$,Kd as hZ,Ld as gZ,Md as uZ,Nd as fJ,Od as cZ,Pd as vJ,Qd as mZ,Rd as pZ,Sd as hJ,Td as lZ,Yd as Y$,Zd as s,xd as gQ,yd as A,zd as k}from"../chunk-y10tys3s.js";import{oe as i$}from"../chunk-hcysexst.js";import"../chunk-frjavybg.js";import{Cj as U$,Dj as wZ,Fj as fZ,Gj as qZ,Hj as bZ,Qi as j,oi as TZ,ri as xZ,xj as IZ}from"../chunk-6d807fgx.js";import{Ij as jZ,Kj as bJ,Lj as yJ}from"../chunk-d8nxkc90.js";import{Uj as h}from"../chunk-m4wagwhr.js";import{Wj as y9,Xj as v9,Yj as h9}from"../chunk-xdrnzs3t.js";import"../chunk-768yza4f.js";import"../chunk-mcqzgyvf.js";import"../chunk-cgjdxxwy.js";import{$k as n,al as o,ol as BJ}from"../chunk-8wxt3v9r.js";import"../chunk-56z4jd8t.js";import"../chunk-zbm7njvf.js";import{fm as eQ}from"../chunk-24mk3gn3.js";import"../chunk-wfpvsgfy.js";import"../chunk-f7bayqs7.js";import{Cm as mJ}from"../chunk-q34hyv6y.js";import"../chunk-qymdnzpy.js";import{existsSync as $8,readdirSync as _6,readFileSync as m$}from"fs";import{isAbsolute as Q8,join as NJ,relative as Z8,sep as W8}from"path";var p$="prompts.json",K8=/\{\{>\s*([\w./-]+)\s*\}\}/g,g$=/\{\{(\w+)\}\}/g,X8=/^[\w-]+(\/[\w-]+)*$/,u$={dir:"app/agents",shared:"prompts"},CJ={},uJ=new Map,OJ;function G8(){if(OJ===void 0){let J=NJ(mJ(),"dist","server",p$);OJ=$8(J)?JSON.parse(m$(J,"utf8")):null}return OJ??null}function Y8(J){return J.replace(/\r?\n$/,"")}function c$(){return CJ.cache??Bun.env.NODE_ENV==="production"}function V8(J,$){if(!X8.test(J))throw Error(`"${J}" is not a prompt name. Use letters, digits, "-" and "_", with "/" between folders.`);let Q=$.dir??CJ.dir??u$.dir,Z=Q8(Q)?Q:NJ(process.cwd(),Q),W=J.includes("/")?`${J}.md`:NJ($.shared??CJ.shared??u$.shared,`${J}.md`);return NJ(Z,W)}function z8(J,$){let Q=V8(J,$),Z=c$()?uJ.get(Q):void 0;if(Z!==void 0)return Z;let W=Bun.env.NODE_ENV==="production";if(W){let X=G8()?.[Z8(mJ(),Q).split(W8).join("/")];if(X!==void 0)return X}let K;try{K=Y8(m$(Q,"utf8"))}catch(X){if(X.code==="ENOENT"){let G=W?` or in dist/server/${p$}`:"";throw Error(`The prompt "${J}" does not exist (looked for ${Q}${G}).`)}throw X}if(c$())uJ.set(Q,K);return K}function cJ(J,$,Q){if($.includes(J))throw Error(`The prompt "${J}" includes itself: ${[...$,J].join(" > ")}.`);return z8(J,Q).replace(K8,(Z,W)=>cJ(W,[...$,J],Q))}class l${static configure(J){CJ={...J},uJ.clear(),OJ=void 0}static render(J,$={},Q={}){return cJ(J,[],Q).replace(g$,(Z,W)=>{if(!Object.hasOwn($,W))throw Error(`The prompt "${J}" has no value for {{${W}}}.`);return String($[W])})}static placeholders(J,$={}){let Q=[...cJ(J,[],$).matchAll(g$)].map((Z)=>Z[1]);return[...new Set(Q)]}}class pJ extends i${name="AgentJobDeadlineSweep";cron="* * * * *";async callback(){while(await y.sweep({limit:100})===100);}}var LJ=20,D8=300,H8=200;function n$(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)=>!f(K.state)).sort(Q),...J.filter((K)=>f(K.state)).sort(Q)].slice(0,$).map((K)=>{let X=[`- ${K.id} (${K.toolName})`];if(K.state==="waiting")X.push(`waiting for ${(K.after??[]).join(", ")} since ${UJ(K.createdAt)}`);else if(K.state==="running")X.push(`running since ${UJ(K.createdAt)}`);else if(K.state==="ok")X.push(`finished at ${UJ(K.settledAt??K.updatedAt)}`);else{let G=K.error?`${K.error.code}: ${d$(K.error.message,H8)}`:"failed";X.push(`failed at ${UJ(K.settledAt??K.updatedAt)} (${G})`)}if(K.summary!==void 0)X.push(`summary: ${d$(JSON.stringify(K.summary),D8)}`);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 UJ(J){return new Date(J).toISOString().replace(/\.\d{3}Z$/,"Z")}function d$(J,$){return J.length<=$?J:`${J.slice(0,$-1)}\u2026`}var o$=["after_jobs","batch_key","queued","inbox","job_checkpoint"],s$=20;class lJ{table;sql;dialect;connection;later;constructor(J,$={}){let Q=$.table??"gemi_agent_jobs";if(!/^[A-Za-z_][A-Za-z0-9_]*$/.test(Q))throw Error(`The agent jobs table name "${Q}" is not a plain identifier. Use letters, digits and underscores.`);this.table=Q,this.sql=J.sql,this.dialect=J.dialect,this.connection=J.name}async createTable(){for(let J of P8(this.dialect,this.table))await this.sql.unsafe(J)}async transaction(J){if(this.connection===void 0||this.joinable())return J();return BJ(this.sql,()=>J(),{connection:this.connection})}async create(J){let $=J.after!==void 0||J.batch!==void 0||J.queued!==void 0;if($)await this.requireLaterColumns("A job with `after` or `batch`");let Q=this.q(),Z=this.clock(Q),W=J.state??"running";if($)await Q`
4
4
  INSERT INTO ${this.name(Q)}
5
5
  (id, thread_id, run_id, tool_call_id, tool_name, owner, job, summary, state,
@@ -299,4 +299,4 @@ return 0`;class _${injectedClient;prefix;constructor(J={}){this.injectedClient=J
299
299
 
300
300
  `)||void 0,C=await this.context(J,{body:V}),L=await this.reasoning(J,{body:V})||void 0,T=await this.skills(J,{body:V})||void 0,R=await this.runTools(J,{body:V,context:C})||void 0,x=await this.usageLimits(J,{body:V,context:C})||void 0,m=await this.attachmentsFor(J,Z,{body:V}),p=this.agent.memory?await this.memoryScopes(J,{body:V}):void 0;if(z?.cancelled)return MZ();let _=Z?new S$(this.store,Z,O,(S)=>this.reportHookFailure(S)):null,E=`run_${crypto.randomUUID()}`,B=[],l={req:J,runId:E,threadId:Z,get denials(){return B}},FJ={id:null,notified:Promise.resolve()},w=this.agent.stream({runId:E,messages:O,turn:K,threadId:Z,..._?{onMessage:(S)=>_.finish(S)}:{},onTurn:(S)=>{if(FJ.id!==null)return;FJ.id=S.id;let i=_?_.settled():Promise.resolve();FJ.notified=i.then(()=>this.safely(()=>this.onMessage(S,l)))},instructions:H,...R$.has(J)?{event:R$.get(J)}:{},...t.has(J)?{echoTurn:!0}:{},...L?{reasoning:L}:{},...T&&T.length>0?{skills:T}:{},...R?.tools&&R.tools.length>0?{tools:R.tools}:{},...R?.activeTools?{activeTools:R.activeTools}:{},...x?{usageLimits:x}:{},context:C,attachments:m,body:V,redactError:(S,i)=>this.redactError(S,i,l),onProviderRetry:(S)=>this.onProviderRetry(S,l),nonces:this.nonces,receipts:this.receipts,subject:Y,...p?{memory:{scopes:p,...this.memoryMaxTokens!==void 0?{maxTokens:this.memoryMaxTokens}:{}}}:{},...Z?{jobs:{owner:Y}}:{},...this.contextWindow!==void 0?{contextWindow:this.contextWindow}:{},...Z&&iZ(this.store)?{summaryStore:this.store}:{},...this.prepareStep!==v$.prototype.prepareStep||this.hooks?.prepareStep?{prepareStep:(S)=>this.prepareStep(S,l)}:{}});B=w.denials;let rZ=this.liveRuns.register(w,{threadId:Z,owner:Y,clientRunId:G,onEvent:(S)=>this.dispatchEvent(S,l),onInternalError:(S)=>this.reportHookFailure(S),maxRunDurationMs:this.agent.maxRunDurationMs});if(D=w,_)this.follow(w,_);if(Z)H9(this.liveRuns,Z,w.runId);let{stored:eZ,hooks:h$}=this.persistRun(w,l,rZ,_,FJ);if(A$.set(w,eZ),t.has(J))t.set(J,{run:w,hooks:h$});return J.ctx?.()?.waitUntil(h$),w.toResponse()};try{await this.authorizeRequest(J,{route:"stream",threadId:Z,body:V});let O=await this.foreignFile([...K?.files??[],...Z?[]:T9(Q.messages)],Y);if(O)return O;if(z?.cancelled)return MZ();let F=await this.runLimitKey(J,{owner:Y,threadId:Z}),H=F===null?e:P9(this.liveRuns).take(F,Z?`thread:${Z}`:`run:${crypto.randomUUID()}`,this.maxConcurrentRuns);if(!H)return I$(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,P,FZ.get(J)??"supersede"):await P()}finally{let C=D;if(C)C.result().then(H,H);else H()}}finally{if(z&&wJ.get(G)===z)wJ.delete(G)}}async withThread(J,$,Q,Z="supersede"){if(Z==="skip"&&DJ.has(J))return SZ(J);for(;;){let W=await this.underThreadLock(J,$,Q,Z);if(!("waitFor"in W))return W.response;await W.waitFor}}async underThreadLock(J,$,Q,Z){let W=DJ.get(J)??Promise.resolve(),K,X=new Promise((V)=>{K=V}),G=W.then(()=>X);DJ.set(J,G),await W;try{let V=await this.liveRuns.find({threadId:J});if(V&&Z!=="supersede"&&this.liveRuns.isRunning(V.runId)){if(Z==="skip")return{response:SZ(J)};let z=this.liveRuns.get(V.runId),D=z?A$.get(z)??z.result():null;if(D)return{waitFor:D.then(e,e)}}if(V&&this.liveRuns.isRunning(V.runId)&&!this.liveRuns.mayAccess(V.runId,$))return{response:PJ()};let Y=V?this.liveRuns.get(V.runId):null;if(Y)Y.stop({reason:"superseded by a later turn on this thread"}),await A$.get(Y);return{response:await Q()}}finally{if(K(),DJ.get(J)===G)DJ.delete(J)}}async attach(J=new j){let $=await r(J,HJ);if($.error)return c($);let Q=$.body,Z=typeof Q.threadId==="string"?Q.threadId:BZ(J,"threadId");if(!Z)return M(400,{code:"invalid_request",message:"attach needs a threadId: it is the handle that survives a refresh."});await this.authorizeRequest(J,{route:"attach",threadId:Z});let W=Q.emptyMiss===!0;if(!await this.threadInScope(J,Z))return kZ(Z,W);let K=await this.liveRuns.find({threadId:Z});if(K&&!this.liveRuns.mayAccess(K.runId,await this.runOwner(J)))return PJ();if(!K)return kZ(Z,W);let X=typeof Q.runId==="string"?Q.runId:void 0,G=X&&X!==K.runId?void 0:A9(J,Q);try{return bZ(this.liveRuns.replay(K.runId,G))}catch(V){if(V instanceof a)return M(410,{code:V.code,message:V.message,oldestSeq:V.oldest});if(V instanceof VJ)return M(404,{code:V.code,message:V.message});throw V}}async watch(J=new j){let $=await r(J,HJ);if($.error)return c($);let Q=$.body,Z=typeof Q.threadId==="string"?Q.threadId:BZ(J,"threadId");if(!Z)return M(400,{code:"invalid_request",message:"watch needs a threadId: it is the thread whose runs are announced."});if(await this.authorizeRequest(J,{route:"attach",threadId:Z}),!await this.threadInScope(J,Z))return M(404,{code:"thread_not_found",message:`Thread ${Z} does not exist here, or has expired.`});let W=await this.runOwner(J),K=this.liveRuns,X=D9(K),G=await K.find({threadId:Z}),V=null,Y=null,z=0,D=()=>{if(Y?.stop(),!V)return;let P=X.get(Z);if(P?.delete(V),P&&P.size===0)X.delete(Z);V=null},N=new ReadableStream({start(P){Y=fZ(P);let U=(F)=>{if(!K.mayAccess(F,W))return;try{P.enqueue(new TextEncoder().encode(wZ({seq:++z,event:{type:"run-start",runId:F,threadId:Z}}))),Y?.touch()}catch{D()}};V=U;let O=X.get(Z);if(!O)O=new Set,X.set(Z,O);if(O.add(U),G&&K.isRunning(G.runId))U(G.runId)},cancel(){D()}});return J.rawRequest?.signal?.addEventListener("abort",D,{once:!0}),new Response(N,{status:200,headers:qZ()})}async stop(J=new j){let $=await r(J,HJ);if($.error)return c($);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=wJ.get(Q.clientRunId);if(X){if(X.owner!==null&&X.owner!==Z)return PJ();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 PJ();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 vJ(this.attachments,this.attachmentStorage,Z)}async voiceStart(J=new j){let $=this.voice;if(!$)return E$();let Q=await r(J,HJ);if(Q.error)return c(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=qJ(Q.body,j9),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}),z=Date.now(),D,N=async(C)=>{if(C!==void 0)console.error("[gemi/ai] a voice session could not start.",C);if(D)await $.realtime.hangup(D).catch((L)=>{console.error("[gemi/ai] a voice call that failed to start could not be hung up.",L)});try{await Y.onEnd?.({sessionId:"",...D?{callId:D}:{},threadId:Y.threadId??G??"",reason:"start_failed",startedAt:z,endedAt:Date.now(),durationMs:0,seconds:0,usage:A(),transcription:{usage:A(),seconds:0},transcript:[],requests:[],toolCalls:[],errors:[]})}catch(L){console.error("[gemi/ai] a voice session's onEnd threw.",L)}},P=Y.threadId??G;if(!P)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(P!==G)await this.authorizeRequest(J,{route:"stream",threadId:P,body:X})}catch(C){throw await N(void 0),C}let U=crypto.randomUUID(),O=Y.tools??[];try{if(Y.mcp)O=[...O,...await z$(Y.mcp,{user:V,sessionId:U})]}catch(C){return await N(C),M(500,{code:"voice_unavailable",message:"Voice isn't available right now."})}let F={...Y.session,tools:[...XJ($.delegate),...Y.session?.tools??[],...O.map((C)=>C.tool)],...K===!0?{turnDetection:null}:{}},H;try{H=await $.realtime.createCall({sdp:Z,session:F,safetyIdentifier:Y.safetyIdentifier})}catch(C){await N(C);let L=C instanceof y$&&C.code==="rate_limited";return M(L?429:502,{code:"voice_unavailable",message:"Voice isn't available right now."})}D=H.callId;try{await this.voiceStore.create({id:U,callId:H.callId,threadId:P,owner:await this.runOwner(J),body:X,startedAt:z});let{threadId:C,session:L,safetyIdentifier:T,mcp:R,tools:x,...m}=Y;return{sessionId:u.start({...m,tools:O,controller:this.constructor,threadId:P,user:V,body:X,call:{realtime:$.realtime,callId:H.callId},sessionId:U,store:this.voiceStore,liveRuns:this.liveRuns,delegate:$.delegate,session:F}).sessionId,sdp:H.sdpAnswer,threadId:P,delegate:$.delegate?.name??GJ,endsAt:z+(Y.limits?.maxDurationMs??900000)}}catch(C){return await N(C),M(500,{code:"voice_unavailable",message:"Voice isn't available right now."})}}async voiceUpdate(J=new j){if(!this.voice)return E$();let $=await this.voiceSession(J);if($ instanceof Response)return $;let Q=await r(J,HJ);if(Q.error)return c(Q);let Z=qJ(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}),u.get($.id)?.setBody(Z),{updated:!0}}async voiceEnd(J=new j){let $=this.voice;if(!$)return E$();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=u.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 PJ();return Q}async upload(J=new j){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=O9($.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=U9(await this.attachmentLimits(J),Q,Z,W);if(G)throw new x$(G.code,G.message);await this.scopeStore(J,K);let V=typeof X==="string"&&X.length>0&&await this.store.loadThread(X)!==null?X:void 0,Y=await this.runOwner(J),z=(R)=>this.fileOwners.record(R,{owner:Y,name:Z,mimeType:W,size:Q.size,createdAt:new Date().toISOString()}),D={body:K,threadId:V},N=await this.checkUpload({name:Z,size:Q.size,mimeType:W},J,D);if(N)throw new x$(N.code||"upload_refused",N.message);let P=await this.attachmentDestination(Q,J,D),U=x9(P,$.get("destination")),O=await this.attachmentScope(J,V,{body:K}),F=U!=="provider"&&!O;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()`.');I9()}if(U==="provider"||!O){let R=await CZ(this.agent.provider,Q);await z(R);let x={fileId:R,name:Z,mimeType:W,size:Q.size,destination:"provider"};if(F)x.downgraded="no_scope";return x}let H=cZ(),C=await this.attachmentStorage.put({name:mZ(H,Z),body:Q,contentType:W}),L=U==="both"?await CZ(this.agent.provider,Q):void 0;if(L)await z(L);let T={id:H,scopeKey:O.key,fileId:L,objectName:C,name:Z,mimeType:W,size:Q.size,createdAt:new Date().toISOString(),destination:U};return await this.attachments.put(O,T),{fileId:L,attachmentId:H,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 k9()}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 q$(J,$)}onError(J,$){return this.hooks?.onError?.(J,$)}onProviderRetry(J,$){return this.hooks?.onProviderRetry?.(J,$)}onStreamComplete(J,$){return this.hooks?.onStreamComplete?.(J,$)}reportHookFailure(J){let $=this.hooks?.reportHookFailure;if($)try{return $(J)}catch(Q){console.error("[gemi/ai] reportHookFailure hook failed",Q)}console.error("[gemi/ai] agent controller hook failed",J)}async dispatchEvent(J,$){switch(J.type){case"tool-call":if(!J.part.partial&&!J.resent)await this.onToolCall({toolCallId:J.part.toolCallId,name:String(J.part.name),input:J.part.input},$);return;case"tool-result":{let Q=J.part;await this.onToolResult(Q,$,{toolCallId:Q.toolCallId,name:String(Q.name),input:nZ(Q)});return}case"awaiting-input":await this.onAwaitingInput(J.pending,$);return;case"error":await this.onError(hZ(J.error),$);return;default:return}}async readThread(J,$={}){let Z=await($.scope===null||$.scope===void 0?this.store:EZ(this.store,$.scope)).loadThread(J);if(!Z)return null;let{messages:W}=await this.settleThread(J,Z,{write:!1});return W}isRunLive(J,$){return this.liveRuns.get(J)!==null}async settleThread(J,$,{write:Q}){let Z=(V)=>this.isRunLive(V,J),W=await GZ($,Z),K=W.messages,X=[],G=new Map(W.settled.map((V)=>[V.id,V]));if(b9(K)||Q)try{let V=await DZ(K,{threadId:J,store:y.store,isRunLive:Z,outputSchemaFor:(Y)=>this.toolNamed(Y)?.outputSchema,modelOutputFor:(Y,z)=>dZ(this.toolNamed(Y),z,(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 HZ(y.store,V.orphans,(z)=>this.reportHookFailure(z));let Y=new Set(V.orphans.map((z)=>z.id));X=X.map((z)=>Y.has(z.id)?{...z,orphaned:!0}:z)}}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??LJ}jobsBlock(J){return n$(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(z){Z?.close(),await Z?.settled(),K=W.notified.then(()=>this.safely(()=>this.onError({code:"unknown",message:z instanceof Error?z.message:String(z),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(z){this.reportHookFailure(z)}K=this.notifyRun(V,Y,$,W)})(),G=X.then(()=>f9(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 T$=["turn","clientRunId","threadId","messages","regenerate"],N9=["text","files","toolResults"];function qJ(J,$=tZ(J)?T$:[...T$,...N9]){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 O9(J){if(J===null)return{};let $;if(typeof J==="string")try{$=JSON.parse(J)}catch{throw new j$("The upload's `body` field is not valid JSON.")}if($===null||typeof $!=="object"||Array.isArray($))throw new j$("The upload's `body` field must be a JSON object.");return qJ($,T$)}class j$ extends bJ{constructor(J){super(J);this.name="InvalidUploadError",this.payload={api:{status:400,data:{error:{code:"invalid_request",message:J}}},view:{}}}}async function CZ(J,$){try{return await J.upload($)}catch(Q){if(Q instanceof lZ&&C9.has(Q.status))throw new aZ(s(Q).message);throw Q}}var C9=new Set([400,413,415,422]);class x$ extends bJ{constructor(J,$){super($);this.name="LimitedUploadError",this.payload={api:{status:422,data:{error:{code:J,message:$}}},view:{}}}}function U9(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 ${UZ($.size)}; the limit is ${UZ(W)}.`};if(K&&K.length>0&&!K.some((X)=>L9(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 L9(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 UZ(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 aZ extends bJ{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 r(J,$){let Q=J?.rawRequest;if(!Q||Q.method==="GET"||Q.method==="HEAD"||!Q.body)return{body:{}};if(!_9(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 LZ($);let W;try{let X=await B9(Q,$);if(X===null)return LZ($);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 _9(J){return xZ(J)==="application/json"}async function B9(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(e),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 LZ(J){return{body:{},status:413,code:"body_too_large",error:`The request body is larger than this agent accepts (${J} bytes).`}}function I$(J,$,Q){return M(J,{...yJ(jZ(J),Q,J),code:$})}function c(J){if(J.status===413)return I$(413,J.code??"body_too_large",J.error??"");return M(J.status??400,{code:J.code??"invalid_request",message:J.error})}function tZ(J){return Boolean(J.turn)&&typeof J.turn==="object"}function M9(J){let $=tZ(J)?J.turn:J,Q={};if(typeof $.text==="string")Q.text=$.text;if(Array.isArray($.files)){let Z=S9($.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>_Z)return{error:`turn.localId is longer than ${_Z} characters.`};Q.localId=Z}return{turn:Q}}var _Z=200;function S9(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 z of["fileId","attachmentId","name","mimeType"]){let D=Z[z];if(D===void 0||D===null||D==="")continue;if(typeof D!=="string")return`${W}.${z} must be a string.`;K[z]=D}let{fileId:X,attachmentId:G,name:V,mimeType:Y}=K;if(X?.startsWith(fJ))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(fJ))return`${W}.attachmentId is not a gemi attachment id: it must start with "${fJ}".`;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 A9(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 BZ(J,$){let Q=J?.search?.get($);return typeof Q==="string"?Q:void 0}function R9(J){let $=b$(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 MZ(){return M(409,{code:"stopped",message:"The turn was stopped before it started."})}function E9(J){let $=J.event;if(J.text!==void 0||J.turn!==void 0)throw TypeError("AgentController.startTurn takes an `event` or a `text`/`turn`, not both: an event is not a person's message.");if(typeof $!=="object"||$===null||typeof $.name!=="string"||!K9.test($.name))throw TypeError('AgentController.startTurn\'s `event.name` must be letters, digits and `.`, `_`, `:`, `-` (at most 64), like "job-settled".');if($.text!==void 0&&typeof $.text!=="string")throw TypeError("AgentController.startTurn's `event.text` must be a string.");let Q;if($.data!==void 0)try{Q=JSON.parse(JSON.stringify($.data))}catch(Z){throw TypeError(`AgentController.startTurn's \`event.data\` is not JSON: ${String(Z)}`)}return{name:$.name,...$.text?{text:$.text}:{},...Q!==void 0?{data:Q}:{}}}function SZ(J){return M(409,{code:oZ,message:`Thread ${J} has a run going, and this turn was not to interrupt it.`})}function PJ(){return M(403,yJ("permission","This run belongs to someone else.",403))}function k9(){return M(403,yJ("permission","A file in this turn was uploaded by someone else.",403))}function T9(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 j9=["sdp","threadId","pushToTalk"];function E$(){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 x9(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 AZ=!1;function I9(){if(AZ)return;AZ=!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 w9=2147483647;function f9(J,$){let Q=J.then(()=>{},()=>{});if(!($<=w9))return Q;let Z,W=new Promise((K)=>{Z=setTimeout(K,$)});return Promise.race([Q,W]).finally(()=>clearTimeout(Z))}var RZ=!1;function q9(J){if(RZ||Bun.env.NODE_ENV!=="production")return;if(!(J instanceof w$))return;RZ=!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 b9(J){return J.some(($)=>$.content.some((Q)=>Q.type==="tool-result"&&Q.status==="running"))}function EZ(J,$){if(typeof $!=="string"||$==="")throw TypeError("A store scope is a non-empty string.");if(!J.forScope)throw Error("This controller's store cannot be scoped: storeScope() or a turn's `scope` needs a store that implements `forScope` (DatabaseAgentStore or MemoryAgentStore).");return J.forScope($)}function kZ(J,$=!1){if($)return new Response(null,{status:204});return M(404,{code:"no_live_run",message:`No run in progress for thread ${J} in this process.`})}export{i9 as windowMessages,XJ as voiceTools,u9 as turnStarts,H6 as toRealtimeUsage,S8 as toAgentTools,h9 as supportsStrict,c9 as splitTurns,r9 as settleSummaries,v9 as s,q$ as redactError,V6 as parsePartialJson,m9 as messageSize,WJ as measureUsage,z$ as mcpVoiceTools,N$ as liveRuns,YJ as keepSummary,F6 as isCallNotFound,b$ as injectedMessageIds,rJ as generate,q8 as evalChain,F9 as defineAgentHooks,H$ as defaultVoiceStore,J6 as defaultUsageLimitStore,t9 as defaultSummaryStore,Y6 as defaultPromptCacheKey,f$ as defaultNonceStore,O$ as defaultFileOwners,hJ as defaultAttachmentStore,B$ as defaultAgentStore,jJ as VoiceHangup,u as VoiceBridge,g9 as Usage,J$ as ToolNamespace,g as ToolError,X6 as ToolArgumentsTooLongError,Q6 as Skill,vJ as ScopedAttachments,Z6 as SKILLS_NAMESPACE,_$ as RedisReceiptStore,yZ as RedisNonceStore,z6 as RealtimeSideband,y$ as RealtimeRequestError,P6 as RealtimeClient,l$ as Prompt,vZ as PrismaNonceStore,$6 as PendingEscalation,N6 as OpenAIProvider,W$ as OpenAIImageProvider,D$ as MemoryVoiceSessionStore,e9 as MemoryUsageLimitStore,a9 as MemorySummaryStore,L$ as MemoryReceiptStore,w$ as MemoryNonceStore,xJ as MemoryLiveRuns,IJ as MemoryFileOwners,kJ as MemoryCircuitStore,pZ as MemoryAttachmentStore,zJ as MemoryAgentStore,t$ as MemoryAgentJobStore,FQ as MEMORY_NAMESPACE,VJ as LiveRunNotFoundError,e$ as JobsRequireThreadError,r$ as JobHandle,y9 as JSONSchemaError,uZ as InvalidAttachmentScopeError,YQ as InMemoryAgentMemoryStore,RJ as ImageRequestError,EJ as ImageProvider,$$ as ImageModel,a as FrameCursorEvictedError,KJ as FallbackProvider,HQ as FakeAgentMemoryStore,SJ as Eval,P$ as DatabaseAgentStore,dJ as DatabaseAgentMemoryStore,lJ as DatabaseAgentJobStore,D6 as DEFAULT_TRANSCRIPTION_MODEL,GQ as DEFAULT_MEMORY_MAX_TOKENS,PQ as DEFAULT_MEMORY_LIMITS,d9 as DEFAULT_MAX_SUMMARY_TOKENS,W6 as DEFAULT_MAX_RUN_DURATION_MS,JQ as DEFAULT_JOB_DEADLINE_MS,LJ as DEFAULT_JOBS_CONTEXT_MAX,GJ as DEFAULT_DELEGATE_NAME,p9 as DEFAULT_CONTEXT_WINDOW_STEP,l9 as DEFAULT_CONTEXT_WINDOW_NOTE,n9 as DEFAULT_COMPACT_TRIGGER_TOKENS,o9 as DEFAULT_COMPACT_INSTRUCTIONS,s9 as COMPACT_SUMMARY_HEADER,U6 as AzureOpenAIProvider,K$ as AzureOpenAIImageProvider,C6 as AzureAnthropicProvider,gZ as AttachmentNotFoundError,O6 as AnthropicProvider,gJ as AgentTurnError,AJ as AgentTool,K6 as AgentRunError,V$ as AgentProvider,VQ as AgentMemoryRefusedError,zQ as AgentMemoryConflictError,DQ as AgentMemories,y as AgentJobs,pJ as AgentJobDeadlineSweep,$Q as AgentJob,v$ as AgentController,G6 as Agent};
301
301
 
302
- //# debugId=CA73D1920DB03D7264756E2164756E21
302
+ //# debugId=3D36E52EA0A7B76464756E2164756E21