gemi 0.187.0 → 0.188.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 (203) hide show
  1. package/dist/ai/index.js +2 -2
  2. package/dist/ai/index.js.map +1 -1
  3. package/dist/app/index.js +1 -1
  4. package/dist/bun/plugin.js +1 -1
  5. package/dist/bun/preload.js +1 -1
  6. package/dist/{chunk-wd3eyjbj.js → chunk-07mvnzgx.js} +3 -3
  7. package/dist/{chunk-wd3eyjbj.js.map → chunk-07mvnzgx.js.map} +1 -1
  8. package/dist/{chunk-jg1n0b5e.js → chunk-0sjz2g5b.js} +2 -2
  9. package/dist/{chunk-jg1n0b5e.js.map → chunk-0sjz2g5b.js.map} +1 -1
  10. package/dist/{chunk-pcc8v9jc.js → chunk-0t5mex63.js} +2 -2
  11. package/dist/{chunk-pcc8v9jc.js.map → chunk-0t5mex63.js.map} +1 -1
  12. package/dist/{chunk-n2vx8eqm.js → chunk-1mg3x0j0.js} +2 -2
  13. package/dist/{chunk-n2vx8eqm.js.map → chunk-1mg3x0j0.js.map} +1 -1
  14. package/dist/{chunk-8nxrgzxp.js → chunk-1p7p76er.js} +2 -2
  15. package/dist/{chunk-8nxrgzxp.js.map → chunk-1p7p76er.js.map} +1 -1
  16. package/dist/{chunk-5yj3k754.js → chunk-24vv42t6.js} +3 -3
  17. package/dist/{chunk-5yj3k754.js.map → chunk-24vv42t6.js.map} +1 -1
  18. package/dist/{chunk-nd2vajx0.js → chunk-2tfafjmk.js} +2 -2
  19. package/dist/{chunk-nd2vajx0.js.map → chunk-2tfafjmk.js.map} +1 -1
  20. package/dist/{chunk-x0vrrfp7.js → chunk-3kd3w33a.js} +2 -2
  21. package/dist/{chunk-x0vrrfp7.js.map → chunk-3kd3w33a.js.map} +1 -1
  22. package/dist/{chunk-nchyjgpr.js → chunk-4x22y92r.js} +2 -2
  23. package/dist/{chunk-nchyjgpr.js.map → chunk-4x22y92r.js.map} +1 -1
  24. package/dist/chunk-4xpcx3ws.js +15 -0
  25. package/dist/{chunk-9caq1znh.js.map → chunk-4xpcx3ws.js.map} +7 -6
  26. package/dist/{chunk-s5p7pd7v.js → chunk-4xtefwwa.js} +2 -2
  27. package/dist/{chunk-s5p7pd7v.js.map → chunk-4xtefwwa.js.map} +1 -1
  28. package/dist/{chunk-ttcmvam5.js → chunk-4zwnmk3c.js} +2 -2
  29. package/dist/{chunk-ttcmvam5.js.map → chunk-4zwnmk3c.js.map} +1 -1
  30. package/dist/{chunk-1x1je71f.js → chunk-5zgkh1xp.js} +2 -2
  31. package/dist/{chunk-1x1je71f.js.map → chunk-5zgkh1xp.js.map} +1 -1
  32. package/dist/{chunk-6cq83t7e.js → chunk-6dtq4h9p.js} +2 -2
  33. package/dist/{chunk-6cq83t7e.js.map → chunk-6dtq4h9p.js.map} +1 -1
  34. package/dist/{chunk-1ecvjvbg.js → chunk-6s6cek6k.js} +2 -2
  35. package/dist/{chunk-1ecvjvbg.js.map → chunk-6s6cek6k.js.map} +1 -1
  36. package/dist/{chunk-9sv8skzh.js → chunk-74n9paen.js} +2 -2
  37. package/dist/{chunk-9sv8skzh.js.map → chunk-74n9paen.js.map} +1 -1
  38. package/dist/{chunk-epmtvd6j.js → chunk-7s6gdgwx.js} +2 -2
  39. package/dist/{chunk-epmtvd6j.js.map → chunk-7s6gdgwx.js.map} +1 -1
  40. package/dist/{chunk-cgxk8pn8.js → chunk-80cwastb.js} +3 -3
  41. package/dist/{chunk-cgxk8pn8.js.map → chunk-80cwastb.js.map} +1 -1
  42. package/dist/{chunk-0jbwxas3.js → chunk-88508q02.js} +2 -2
  43. package/dist/{chunk-0jbwxas3.js.map → chunk-88508q02.js.map} +1 -1
  44. package/dist/{chunk-2pj5e233.js → chunk-8a72czrb.js} +3 -3
  45. package/dist/{chunk-2pj5e233.js.map → chunk-8a72czrb.js.map} +1 -1
  46. package/dist/{chunk-n7nx6hby.js → chunk-8bp5s118.js} +4 -4
  47. package/dist/{chunk-n7nx6hby.js.map → chunk-8bp5s118.js.map} +1 -1
  48. package/dist/{chunk-xa2k8dm0.js → chunk-9ep490s9.js} +2 -2
  49. package/dist/{chunk-xa2k8dm0.js.map → chunk-9ep490s9.js.map} +1 -1
  50. package/dist/{chunk-gap8ta5q.js → chunk-attv9byj.js} +2 -2
  51. package/dist/{chunk-gap8ta5q.js.map → chunk-attv9byj.js.map} +1 -1
  52. package/dist/{chunk-2757n2e2.js → chunk-babcg0fq.js} +2 -2
  53. package/dist/{chunk-2757n2e2.js.map → chunk-babcg0fq.js.map} +1 -1
  54. package/dist/{chunk-gpsqtjx5.js → chunk-bmckdsec.js} +1 -1
  55. package/dist/{chunk-3cmm9atm.js → chunk-bwh1n2cj.js} +2 -2
  56. package/dist/{chunk-3cmm9atm.js.map → chunk-bwh1n2cj.js.map} +1 -1
  57. package/dist/{chunk-y4yv9e31.js → chunk-cbjjg80m.js} +1 -1
  58. package/dist/{chunk-s52ecbdd.js → chunk-cbp8xrsn.js} +2 -2
  59. package/dist/{chunk-s52ecbdd.js.map → chunk-cbp8xrsn.js.map} +1 -1
  60. package/dist/{chunk-nwafkabk.js → chunk-cr37wx3s.js} +2 -2
  61. package/dist/{chunk-nwafkabk.js.map → chunk-cr37wx3s.js.map} +1 -1
  62. package/dist/{chunk-d19x7t1z.js → chunk-cr9rd0v4.js} +2 -2
  63. package/dist/{chunk-d19x7t1z.js.map → chunk-cr9rd0v4.js.map} +1 -1
  64. package/dist/{chunk-sg8fcsvn.js → chunk-czw7kqtp.js} +2 -2
  65. package/dist/{chunk-sg8fcsvn.js.map → chunk-czw7kqtp.js.map} +1 -1
  66. package/dist/{chunk-kgsmh0v0.js → chunk-dm61gz7e.js} +2 -2
  67. package/dist/{chunk-kgsmh0v0.js.map → chunk-dm61gz7e.js.map} +1 -1
  68. package/dist/{chunk-5q2v29ma.js → chunk-e6k0024c.js} +1 -1
  69. package/dist/{chunk-znnt70rn.js → chunk-edj701p0.js} +3 -3
  70. package/dist/{chunk-znnt70rn.js.map → chunk-edj701p0.js.map} +1 -1
  71. package/dist/{chunk-aezj1erg.js → chunk-fg1mpyp9.js} +2 -2
  72. package/dist/{chunk-aezj1erg.js.map → chunk-fg1mpyp9.js.map} +1 -1
  73. package/dist/{chunk-hc58rnwq.js → chunk-gcjjwgnt.js} +2 -2
  74. package/dist/{chunk-hc58rnwq.js.map → chunk-gcjjwgnt.js.map} +1 -1
  75. package/dist/{chunk-yn2v5axb.js → chunk-gtbjdx8d.js} +2 -2
  76. package/dist/{chunk-yn2v5axb.js.map → chunk-gtbjdx8d.js.map} +1 -1
  77. package/dist/chunk-h3jxnd65.js +5 -0
  78. package/dist/{chunk-ghf4kgs6.js.map → chunk-h3jxnd65.js.map} +1 -1
  79. package/dist/{chunk-q7nz3b4q.js → chunk-jmgjhfya.js} +2 -2
  80. package/dist/{chunk-q7nz3b4q.js.map → chunk-jmgjhfya.js.map} +1 -1
  81. package/dist/{chunk-m62jshaz.js → chunk-jsbq8qq0.js} +3 -3
  82. package/dist/{chunk-m62jshaz.js.map → chunk-jsbq8qq0.js.map} +1 -1
  83. package/dist/{chunk-ascbx2kb.js → chunk-k4c0q1za.js} +1 -1
  84. package/dist/{chunk-gw9sy16b.js → chunk-kcgbb7cd.js} +2 -2
  85. package/dist/{chunk-gw9sy16b.js.map → chunk-kcgbb7cd.js.map} +1 -1
  86. package/dist/{chunk-9by5yphc.js → chunk-kjtq7vk3.js} +1 -1
  87. package/dist/{chunk-5sc7j1g0.js → chunk-kkymwxt2.js} +2 -2
  88. package/dist/{chunk-5sc7j1g0.js.map → chunk-kkymwxt2.js.map} +1 -1
  89. package/dist/{chunk-v7e5gv6w.js → chunk-ktgmrjj3.js} +2 -2
  90. package/dist/{chunk-v7e5gv6w.js.map → chunk-ktgmrjj3.js.map} +1 -1
  91. package/dist/{chunk-3yzmzcxn.js → chunk-kzny5cj2.js} +2 -2
  92. package/dist/{chunk-3yzmzcxn.js.map → chunk-kzny5cj2.js.map} +1 -1
  93. package/dist/{chunk-kqwenh9b.js → chunk-m8y3y6sw.js} +2 -2
  94. package/dist/{chunk-kqwenh9b.js.map → chunk-m8y3y6sw.js.map} +1 -1
  95. package/dist/{chunk-4e99zzkt.js → chunk-ma2sders.js} +2 -2
  96. package/dist/{chunk-4e99zzkt.js.map → chunk-ma2sders.js.map} +1 -1
  97. package/dist/{chunk-tns989kw.js → chunk-mx4z8c6r.js} +2 -2
  98. package/dist/{chunk-tns989kw.js.map → chunk-mx4z8c6r.js.map} +1 -1
  99. package/dist/{chunk-xf515fp7.js → chunk-n0mjy9ep.js} +2 -2
  100. package/dist/{chunk-xf515fp7.js.map → chunk-n0mjy9ep.js.map} +1 -1
  101. package/dist/{chunk-jqdqpdss.js → chunk-n1b6r6s9.js} +2 -2
  102. package/dist/{chunk-jqdqpdss.js.map → chunk-n1b6r6s9.js.map} +1 -1
  103. package/dist/{chunk-rztf3yam.js → chunk-n28c9xjp.js} +2 -2
  104. package/dist/{chunk-rztf3yam.js.map → chunk-n28c9xjp.js.map} +1 -1
  105. package/dist/{chunk-y8c704wp.js → chunk-nbfzyvav.js} +2 -2
  106. package/dist/{chunk-y8c704wp.js.map → chunk-nbfzyvav.js.map} +1 -1
  107. package/dist/{chunk-2ys56r3z.js → chunk-p9rf0e8r.js} +2 -2
  108. package/dist/{chunk-2ys56r3z.js.map → chunk-p9rf0e8r.js.map} +1 -1
  109. package/dist/{chunk-28xqs354.js → chunk-pchb1awj.js} +2 -2
  110. package/dist/{chunk-28xqs354.js.map → chunk-pchb1awj.js.map} +1 -1
  111. package/dist/{chunk-bf88yh7q.js → chunk-ph793v5g.js} +2 -2
  112. package/dist/{chunk-bf88yh7q.js.map → chunk-ph793v5g.js.map} +1 -1
  113. package/dist/{chunk-2a4q9t8c.js → chunk-q8zhfe2s.js} +2 -2
  114. package/dist/{chunk-2a4q9t8c.js.map → chunk-q8zhfe2s.js.map} +1 -1
  115. package/dist/{chunk-jx8n3w5j.js → chunk-q9b0ndf0.js} +3 -3
  116. package/dist/{chunk-jx8n3w5j.js.map → chunk-q9b0ndf0.js.map} +1 -1
  117. package/dist/{chunk-qj138p8j.js → chunk-r5cddkyc.js} +2 -2
  118. package/dist/{chunk-qj138p8j.js.map → chunk-r5cddkyc.js.map} +1 -1
  119. package/dist/{chunk-x0983cez.js → chunk-sbhpdhwc.js} +2 -2
  120. package/dist/{chunk-x0983cez.js.map → chunk-sbhpdhwc.js.map} +1 -1
  121. package/dist/{chunk-3t37a4e5.js → chunk-scscdtd6.js} +2 -2
  122. package/dist/{chunk-3t37a4e5.js.map → chunk-scscdtd6.js.map} +1 -1
  123. package/dist/{chunk-bw2ptzxr.js → chunk-t201nja2.js} +2 -2
  124. package/dist/{chunk-bw2ptzxr.js.map → chunk-t201nja2.js.map} +1 -1
  125. package/dist/{chunk-b3e27j6t.js → chunk-tfvdrvbn.js} +2 -2
  126. package/dist/{chunk-b3e27j6t.js.map → chunk-tfvdrvbn.js.map} +1 -1
  127. package/dist/{chunk-7pes8axs.js → chunk-v6ewt7tc.js} +2 -2
  128. package/dist/{chunk-7pes8axs.js.map → chunk-v6ewt7tc.js.map} +1 -1
  129. package/dist/{chunk-tnqvxzbw.js → chunk-vmax8gjr.js} +2 -2
  130. package/dist/{chunk-tnqvxzbw.js.map → chunk-vmax8gjr.js.map} +1 -1
  131. package/dist/{chunk-0bzcxgks.js → chunk-vpms0v5m.js} +3 -3
  132. package/dist/{chunk-0bzcxgks.js.map → chunk-vpms0v5m.js.map} +1 -1
  133. package/dist/{chunk-twn4yxsd.js → chunk-vqrqzfyw.js} +2 -2
  134. package/dist/{chunk-twn4yxsd.js.map → chunk-vqrqzfyw.js.map} +1 -1
  135. package/dist/{chunk-c3rn99hm.js → chunk-vyqk7de0.js} +1 -1
  136. package/dist/{chunk-zdwgcyjh.js → chunk-wk84z25h.js} +2 -2
  137. package/dist/{chunk-zdwgcyjh.js.map → chunk-wk84z25h.js.map} +1 -1
  138. package/dist/{chunk-dwt3p2aw.js → chunk-yp4rbknt.js} +2 -2
  139. package/dist/{chunk-dwt3p2aw.js.map → chunk-yp4rbknt.js.map} +1 -1
  140. package/dist/{chunk-rsnm21vr.js → chunk-yqf1k3kb.js} +3 -3
  141. package/dist/{chunk-rsnm21vr.js.map → chunk-yqf1k3kb.js.map} +1 -1
  142. package/dist/{chunk-kj6wqkjc.js → chunk-zck41hz4.js} +4 -4
  143. package/dist/{chunk-kj6wqkjc.js.map → chunk-zck41hz4.js.map} +1 -1
  144. package/dist/{chunk-6m5rt6xg.js → chunk-zjr8kgbg.js} +2 -2
  145. package/dist/{chunk-6m5rt6xg.js.map → chunk-zjr8kgbg.js.map} +1 -1
  146. package/dist/{chunk-10sbvn36.js → chunk-zqcaqwey.js} +2 -2
  147. package/dist/{chunk-10sbvn36.js.map → chunk-zqcaqwey.js.map} +1 -1
  148. package/dist/{chunk-eeqfp05r.js → chunk-zrndnz4n.js} +2 -2
  149. package/dist/{chunk-eeqfp05r.js.map → chunk-zrndnz4n.js.map} +1 -1
  150. package/dist/config/index.js +1 -1
  151. package/dist/console/run.js +2 -2
  152. package/dist/console/run.js.map +1 -1
  153. package/dist/container/index.js +2 -2
  154. package/dist/container/index.js.map +1 -1
  155. package/dist/database/index.js +2 -2
  156. package/dist/database/index.js.map +1 -1
  157. package/dist/email/index.js +2 -2
  158. package/dist/email/index.js.map +1 -1
  159. package/dist/facades/Storage.d.ts +6 -0
  160. package/dist/facades/Storage.d.ts.map +1 -1
  161. package/dist/facades/index.js +2 -2
  162. package/dist/facades/index.js.map +1 -1
  163. package/dist/foundation/index.js +2 -2
  164. package/dist/foundation/index.js.map +1 -1
  165. package/dist/http/index.js +2 -2
  166. package/dist/http/index.js.map +1 -1
  167. package/dist/i18n/dictionaryRuntime.js +2 -2
  168. package/dist/i18n/dictionaryRuntime.js.map +1 -1
  169. package/dist/i18n/index.js +2 -2
  170. package/dist/i18n/index.js.map +1 -1
  171. package/dist/kernel/index.js +2 -2
  172. package/dist/kernel/index.js.map +1 -1
  173. package/dist/orm/index.js +2 -2
  174. package/dist/orm/index.js.map +1 -1
  175. package/dist/probe/index.js +2 -2
  176. package/dist/probe/index.js.map +1 -1
  177. package/dist/server/index.js +2 -2
  178. package/dist/server/index.js.map +1 -1
  179. package/dist/services/file-storage/FilesystemManager.d.ts +4 -0
  180. package/dist/services/file-storage/FilesystemManager.d.ts.map +1 -1
  181. package/dist/services/file-storage/config.d.ts +16 -0
  182. package/dist/services/file-storage/config.d.ts.map +1 -1
  183. package/dist/services/file-storage/fetchTimeouts.d.ts +41 -0
  184. package/dist/services/file-storage/fetchTimeouts.d.ts.map +1 -0
  185. package/dist/services/index.d.ts +1 -0
  186. package/dist/services/index.d.ts.map +1 -1
  187. package/dist/services/index.js +3 -3
  188. package/dist/services/index.js.map +2 -2
  189. package/dist/services/queue/work.js +2 -2
  190. package/dist/services/queue/work.js.map +1 -1
  191. package/dist/stats/route-table.js +1 -1
  192. package/dist/support/index.js +2 -2
  193. package/dist/support/index.js.map +1 -1
  194. package/dist/vitest/index.js +1 -1
  195. package/package.json +1 -1
  196. package/dist/chunk-9caq1znh.js +0 -15
  197. package/dist/chunk-ghf4kgs6.js +0 -5
  198. /package/dist/{chunk-gpsqtjx5.js.map → chunk-bmckdsec.js.map} +0 -0
  199. /package/dist/{chunk-y4yv9e31.js.map → chunk-cbjjg80m.js.map} +0 -0
  200. /package/dist/{chunk-5q2v29ma.js.map → chunk-e6k0024c.js.map} +0 -0
  201. /package/dist/{chunk-ascbx2kb.js.map → chunk-k4c0q1za.js.map} +0 -0
  202. /package/dist/{chunk-9by5yphc.js.map → chunk-kjtq7vk3.js.map} +0 -0
  203. /package/dist/{chunk-c3rn99hm.js.map → chunk-vyqk7de0.js.map} +0 -0
package/dist/ai/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  // @bun
2
- import{$b as Z8,$c as Q6,Ac as e9,Bc as $Q,Cc as M8,Ec as S8,Fc as k8,Gc as E8,Hc as T8,Ic as j8,Jc as x8,Kc as q8,Lc as I8,Mc as w8,Nc as b8,Oc as f8,Pc as v8,Rc as I,Sc as Z9,Tc as a,Uc as T,Vc as K8,Wc as t0,Xc as r0,Yb as Q8,Yc as e0,Zb as LQ,Zc as $6,_b as OQ,_c as J6,ad as Z6,bd as W6,cc as I$,cd as K6,dc as S,dd as X6,ec as A,ed as Y6,fd as F$,gc as e8,gd as G6,hc as n8,hd as EQ,ic as X$,id as V6,jc as a0,jd as TQ,kc as g,kd as H6,lc as W8,ld as z6,mc as CQ,md as D6,nc as _Q,nd as j$,oc as MQ,od as PJ,pc as m,pd as F6,qc as SQ,qd as B6,rc as a$,rd as jQ,sc as AQ,sd as P6,tc as RQ,td as N6,uc as t$,ud as U6,vc as O8,vd as L6,wc as C8,wd as FJ,yc as _8,zc as v}from"../chunk-2757n2e2.js";import{Od as B8}from"../chunk-bm3pyh9m.js";import"../chunk-gap8ta5q.js";import{Lh as FQ,Oh as PQ,Oi as NQ,Ri as dJ,Vi as UQ,ci as S9,di as n0,ei as o0,fi as s0,gi as x}from"../chunk-9caq1znh.js";import{Wi as BQ,Yi as o$,Zi as s$}from"../chunk-1ecvjvbg.js";import{gj as h}from"../chunk-nd2vajx0.js";import"../chunk-0jbwxas3.js";import"../chunk-v7e5gv6w.js";import"../chunk-jqdqpdss.js";import{jk as o,kk as s,yk as R$}from"../chunk-5yj3k754.js";import"../chunk-3yzmzcxn.js";import"../chunk-ttcmvam5.js";import{ll as p9}from"../chunk-znnt70rn.js";import"../chunk-x0983cez.js";import"../chunk-dwt3p2aw.js";import{El as JJ}from"../chunk-tns989kw.js";import"../chunk-q7nz3b4q.js";import{existsSync as fQ,readdirSync as C6,readFileSync as z8}from"fs";import{isAbsolute as vQ,join as O$,relative as yQ,sep as hQ}from"path";var D8="prompts.json",gQ=/\{\{>\s*([\w./-]+)\s*\}\}/g,G8=/\{\{(\w+)\}\}/g,uQ=/^[\w-]+(\/[\w-]+)*$/,V8={dir:"app/agents",shared:"prompts"},_$={},e$=new Map,C$;function cQ(){if(C$===void 0){let $=O$(JJ(),"dist","server",D8);C$=fQ($)?JSON.parse(z8($,"utf8")):null}return C$??null}function mQ($){return $.replace(/\r?\n$/,"")}function H8(){return _$.cache??Bun.env.NODE_ENV==="production"}function pQ($){if(!uQ.test($))throw Error(`"${$}" is not a prompt name. Use letters, digits, "-" and "_", with "/" between folders.`);let J=_$.dir??V8.dir,Q=vQ(J)?J:O$(process.cwd(),J),Z=$.includes("/")?`${$}.md`:O$(_$.shared??V8.shared,`${$}.md`);return O$(Q,Z)}function lQ($){let J=pQ($),Q=H8()?e$.get(J):void 0;if(Q!==void 0)return Q;let Z=Bun.env.NODE_ENV==="production";if(Z){let K=cQ()?.[yQ(JJ(),J).split(hQ).join("/")];if(K!==void 0)return K}let W;try{W=mQ(z8(J,"utf8"))}catch(K){if(K.code==="ENOENT"){let X=Z?` or in dist/server/${D8}`:"";throw Error(`The prompt "${$}" does not exist (looked for ${J}${X}).`)}throw K}if(H8())e$.set(J,W);return W}function $J($,J){if(J.includes($))throw Error(`The prompt "${$}" includes itself: ${[...J,$].join(" > ")}.`);return lQ($).replace(gQ,(Q,Z)=>$J(Z,[...J,$]))}class F8{static configure($){_$={...$},e$.clear(),C$=void 0}static render($,J={}){return $J($,[]).replace(G8,(Q,Z)=>{if(!Object.hasOwn(J,Z))throw Error(`The prompt "${$}" has no value for {{${Z}}}.`);return String(J[Z])})}static placeholders($){let J=[...$J($,[]).matchAll(G8)].map((Q)=>Q[1]);return[...new Set(J)]}}class QJ extends B8{name="AgentJobDeadlineSweep";cron="* * * * *";async callback(){while(await v.sweep({limit:100})===100);}}var M$=20;function N8($,J){if(J<=0||$.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.",...[...$.filter((K)=>K.state==="running").sort(Q),...$.filter((K)=>K.state!=="running").sort(Q)].slice(0,J).map((K)=>{let X=[`- ${K.id} (${K.toolName})`];if(K.state==="running")X.push(`running since ${ZJ(K.createdAt)}`);else if(K.state==="ok")X.push(`finished at ${ZJ(K.settledAt??K.updatedAt)}`);else{let G=K.error?`${K.error.code}: ${P8(K.error.message,200)}`:"failed";X.push(`failed at ${ZJ(K.settledAt??K.updatedAt)} (${G})`)}if(K.summary!==void 0)X.push(`summary: ${P8(JSON.stringify(K.summary),300)}`);if(K.orphaned)X.push("its tool call was lost when the turn that started it was cut short");return X.join("; ")}),"</jobs>"].join(`
2
+ import{$b as Z8,$c as Q6,Ac as e9,Bc as $Q,Cc as M8,Ec as S8,Fc as k8,Gc as E8,Hc as T8,Ic as j8,Jc as x8,Kc as q8,Lc as I8,Mc as w8,Nc as b8,Oc as f8,Pc as v8,Rc as I,Sc as Z9,Tc as a,Uc as T,Vc as K8,Wc as t0,Xc as r0,Yb as Q8,Yc as e0,Zb as LQ,Zc as $6,_b as OQ,_c as J6,ad as Z6,bd as W6,cc as I$,cd as K6,dc as S,dd as X6,ec as A,ed as Y6,fd as F$,gc as e8,gd as G6,hc as n8,hd as EQ,ic as X$,id as V6,jc as a0,jd as TQ,kc as g,kd as H6,lc as W8,ld as z6,mc as CQ,md as D6,nc as _Q,nd as j$,oc as MQ,od as PJ,pc as m,pd as F6,qc as SQ,qd as B6,rc as a$,rd as jQ,sc as AQ,sd as P6,tc as RQ,td as N6,uc as t$,ud as U6,vc as O8,vd as L6,wc as C8,wd as FJ,yc as _8,zc as v}from"../chunk-babcg0fq.js";import{Od as B8}from"../chunk-bm3pyh9m.js";import"../chunk-attv9byj.js";import{Lh as FQ,Oh as PQ,Pi as NQ,Si as dJ,Wi as UQ,ci as S9,di as n0,ei as o0,fi as s0,gi as x}from"../chunk-4xpcx3ws.js";import{Xi as BQ,Zi as o$,_i as s$}from"../chunk-6s6cek6k.js";import{hj as h}from"../chunk-2tfafjmk.js";import"../chunk-88508q02.js";import"../chunk-ktgmrjj3.js";import"../chunk-n1b6r6s9.js";import{kk as o,lk as s,zk as R$}from"../chunk-24vv42t6.js";import"../chunk-kzny5cj2.js";import"../chunk-4zwnmk3c.js";import{ml as p9}from"../chunk-edj701p0.js";import"../chunk-sbhpdhwc.js";import"../chunk-yp4rbknt.js";import{Fl as JJ}from"../chunk-mx4z8c6r.js";import"../chunk-jmgjhfya.js";import{existsSync as fQ,readdirSync as C6,readFileSync as z8}from"fs";import{isAbsolute as vQ,join as O$,relative as yQ,sep as hQ}from"path";var D8="prompts.json",gQ=/\{\{>\s*([\w./-]+)\s*\}\}/g,G8=/\{\{(\w+)\}\}/g,uQ=/^[\w-]+(\/[\w-]+)*$/,V8={dir:"app/agents",shared:"prompts"},_$={},e$=new Map,C$;function cQ(){if(C$===void 0){let $=O$(JJ(),"dist","server",D8);C$=fQ($)?JSON.parse(z8($,"utf8")):null}return C$??null}function mQ($){return $.replace(/\r?\n$/,"")}function H8(){return _$.cache??Bun.env.NODE_ENV==="production"}function pQ($){if(!uQ.test($))throw Error(`"${$}" is not a prompt name. Use letters, digits, "-" and "_", with "/" between folders.`);let J=_$.dir??V8.dir,Q=vQ(J)?J:O$(process.cwd(),J),Z=$.includes("/")?`${$}.md`:O$(_$.shared??V8.shared,`${$}.md`);return O$(Q,Z)}function lQ($){let J=pQ($),Q=H8()?e$.get(J):void 0;if(Q!==void 0)return Q;let Z=Bun.env.NODE_ENV==="production";if(Z){let K=cQ()?.[yQ(JJ(),J).split(hQ).join("/")];if(K!==void 0)return K}let W;try{W=mQ(z8(J,"utf8"))}catch(K){if(K.code==="ENOENT"){let X=Z?` or in dist/server/${D8}`:"";throw Error(`The prompt "${$}" does not exist (looked for ${J}${X}).`)}throw K}if(H8())e$.set(J,W);return W}function $J($,J){if(J.includes($))throw Error(`The prompt "${$}" includes itself: ${[...J,$].join(" > ")}.`);return lQ($).replace(gQ,(Q,Z)=>$J(Z,[...J,$]))}class F8{static configure($){_$={...$},e$.clear(),C$=void 0}static render($,J={}){return $J($,[]).replace(G8,(Q,Z)=>{if(!Object.hasOwn(J,Z))throw Error(`The prompt "${$}" has no value for {{${Z}}}.`);return String(J[Z])})}static placeholders($){let J=[...$J($,[]).matchAll(G8)].map((Q)=>Q[1]);return[...new Set(J)]}}class QJ extends B8{name="AgentJobDeadlineSweep";cron="* * * * *";async callback(){while(await v.sweep({limit:100})===100);}}var M$=20;function N8($,J){if(J<=0||$.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.",...[...$.filter((K)=>K.state==="running").sort(Q),...$.filter((K)=>K.state!=="running").sort(Q)].slice(0,J).map((K)=>{let X=[`- ${K.id} (${K.toolName})`];if(K.state==="running")X.push(`running since ${ZJ(K.createdAt)}`);else if(K.state==="ok")X.push(`finished at ${ZJ(K.settledAt??K.updatedAt)}`);else{let G=K.error?`${K.error.code}: ${P8(K.error.message,200)}`:"failed";X.push(`failed at ${ZJ(K.settledAt??K.updatedAt)} (${G})`)}if(K.summary!==void 0)X.push(`summary: ${P8(JSON.stringify(K.summary),300)}`);if(K.orphaned)X.push("its tool call was lost when the turn that started it was cut short");return X.join("; ")}),"</jobs>"].join(`
3
3
  `)}function ZJ($){return new Date($).toISOString().replace(/\.\d{3}Z$/,"Z")}function P8($,J){return $.length<=J?$:`${$.slice(0,J-1)}\u2026`}class KJ{table;sql;dialect;connection;constructor($,J={}){let Q=J.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=$.sql,this.dialect=$.dialect,this.connection=$.name}async createTable(){for(let $ of dQ(this.dialect,this.table))await this.sql.unsafe($)}async transaction($){if(this.connection===void 0||this.joinable())return $();return R$(this.sql,()=>$(),{connection:this.connection})}async create($){let J=this.q(),Q=this.clock(J);await J`
4
4
  INSERT INTO ${this.name(J)}
5
5
  (id, thread_id, run_id, tool_call_id, tool_name, owner, job, summary, state,
@@ -241,4 +241,4 @@ return 0`;class nJ{injectedClient;prefix;constructor($={}){this.injectedClient=$
241
241
 
242
242
  `)||void 0,L=await this.context($,{body:V}),O=await this.reasoning($,{body:V})||void 0,j=await this.skills($,{body:V})||void 0,R=await this.runTools($,{body:V,context:L})||void 0,q=await this.usageLimits($,{body:V,context:L})||void 0,d=await this.attachmentsFor($,Z,{body:V}),i=this.agent.memory?await this.memoryScopes($,{body:V}):void 0;if(H?.cancelled)return HQ();let C=Z?new aJ(this.store,Z,N,(E)=>this.reportHookFailure(E)):null,k=`run_${crypto.randomUUID()}`,_={req:$,runId:k,threadId:Z},L$={id:null,notified:Promise.resolve()},f=this.agent.stream({runId:k,messages:N,turn:K,threadId:Z,...C?{onMessage:(E)=>C.finish(E)}:{},onTurn:(E)=>{if(L$.id!==null)return;L$.id=E.id;let n=C?C.settled():Promise.resolve();L$.notified=n.then(()=>this.safely(()=>this.onMessage(E,_)))},instructions:P,...O?{reasoning:O}:{},...j&&j.length>0?{skills:j}:{},...R?.tools&&R.tools.length>0?{tools:R.tools}:{},...R?.activeTools?{activeTools:R.activeTools}:{},...q?{usageLimits:q}:{},context:L,attachments:d,body:V,redactError:(E,n)=>this.redactError(E,n,_),nonces:this.nonces,receipts:this.receipts,subject:Y,...i?{memory:{scopes:i,...this.memoryMaxTokens!==void 0?{maxTokens:this.memoryMaxTokens}:{}}}:{},...Z?{jobs:{owner:Y}}:{},...this.contextWindow!==void 0?{contextWindow:this.contextWindow}:{},...Z&&EQ(this.store)?{summaryStore:this.store}:{},...this.prepareStep!==X8.prototype.prepareStep||this.hooks?.prepareStep?{prepareStep:(E)=>this.prepareStep(E,_)}:{}}),IQ=this.liveRuns.register(f,{threadId:Z,owner:Y,clientRunId:G,onEvent:(E)=>this.dispatchEvent(E,_),onInternalError:(E)=>this.reportHookFailure(E),maxRunDurationMs:this.agent.maxRunDurationMs});if(D=f,C)this.follow(f,C);let{stored:wQ,hooks:Y8}=this.persistRun(f,_,IQ,C,L$);if(ZQ.set(f,wQ),P$.has($))P$.set($,{run:f,hooks:Y8});return $.ctx?.()?.waitUntil(Y8),f.toResponse()};try{await this.authorizeRequest($,{route:"stream",threadId:Z,body:V});let N=await this.foreignFile([...K?.files??[],...Z?[]:g0(Q.messages)],Y);if(N)return N;if(H?.cancelled)return HQ();let B=await this.runLimitKey($,{owner:Y,threadId:Z}),P=B===null?i$:A0(this.liveRuns).take(B,Z?`thread:${Z}`:`run:${crypto.randomUUID()}`,this.maxConcurrentRuns);if(!P)return J8(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,F):await F()}finally{let L=D;if(L)L.result().then(P,P);else P()}}finally{if(H&&l$.get(G)===H)l$.delete(G)}}async withThread($,J,Q){let Z=p$.get($)??Promise.resolve(),W,K=new Promise((G)=>{W=G}),X=Z.then(()=>K);p$.set($,X),await Z;try{let G=await this.liveRuns.find({threadId:$});if(G&&this.liveRuns.isRunning(G.runId)&&!this.liveRuns.mayAccess(G.runId,J))return U$();let V=G?this.liveRuns.get(G.runId):null;if(V)V.stop({reason:"superseded by a later turn on this thread"}),await ZQ.get(V);return await Q()}finally{if(W(),p$.get($)===X)p$.delete($)}}async attach($=new x){let J=await N$($,d$);if(J.error)return J$(J);let Q=J.body,Z=typeof Q.threadId==="string"?Q.threadId:v0($,"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($,{route:"attach",threadId:Z});let W=await this.liveRuns.find({threadId:Z});if(W&&!this.liveRuns.mayAccess(W.runId,await this.runOwner($)))return U$();if(!W)return M(404,{code:"no_live_run",message:`No run in progress for thread ${Z} in this process.`});let K=typeof Q.runId==="string"?Q.runId:void 0,X=K&&K!==W.runId?void 0:f0($,Q);try{return UQ(this.liveRuns.replay(W.runId,X))}catch(G){if(G instanceof $$)return M(410,{code:G.code,message:G.message,oldestSeq:G.oldest});if(G instanceof B$)return M(404,{code:G.code,message:G.message});throw G}}async stop($=new x){let J=await N$($,d$);if(J.error)return J$(J);let Q=J.body;await this.authorizeRequest($,{route:"stop",threadId:typeof Q.threadId==="string"?Q.threadId:void 0});let Z=await this.runOwner($),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=l$.get(Q.clientRunId);if(X){if(X.owner!==null&&X.owner!==Z)return U$();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 U$();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=$.ctx()?.user,K=W?.id??W?.publicId;if(K!==void 0&&K!==null&&String(K)!=="")return{key:`user:${String(K)}`};if(J)return{key:`thread:${J}`};return null}attachmentLimits($){let J=this.hooks?.attachmentLimits;if(J)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 a$(this.attachments,this.attachmentStorage,Z)}async voiceStart($=new x){let J=this.voice;if(!J)return tJ();let Q=await N$($,d$);if(Q.error)return J$(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=n$(Q.body,u0),G=typeof W==="string"&&W!==""?W:void 0;await this.authorizeRequest($,{route:"stream",threadId:G,body:X});let V=$.ctx?.()?.user??null,Y=await J.start({req:$,body:X,threadId:G,user:V,pushToTalk:K===!0}),H=Date.now(),D,z=async(L)=>{if(L!==void 0)console.error("[gemi/ai] a voice session could not start.",L);if(D)await 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 Y.onEnd?.({sessionId:"",...D?{callId:D}:{},threadId:Y.threadId??G??"",reason:"start_failed",startedAt:H,endedAt:Date.now(),durationMs:0,seconds:0,usage:S(),transcription:{usage:S(),seconds:0},transcript:[],requests:[],toolCalls:[],errors:[]})}catch(O){console.error("[gemi/ai] a voice session's onEnd threw.",O)}},F=Y.threadId??G;if(!F)return await z(void 0),M(400,{code:"invalid_request",message:"A voice session needs a thread: send `threadId`, or answer one from `voice.start`."});try{if(F!==G)await this.authorizeRequest($,{route:"stream",threadId:F,body:X})}catch(L){throw await z(void 0),L}let U=crypto.randomUUID(),N=Y.tools??[];try{if(Y.mcp)N=[...N,...await hJ(Y.mcp,{user:V,sessionId:U})]}catch(L){return await z(L),M(500,{code:"voice_unavailable",message:"Voice isn't available right now."})}let B={...Y.session,tools:[...z$(J.delegate),...Y.session?.tools??[],...N.map((L)=>L.tool)],...K===!0?{turnDetection:null}:{}},P;try{P=await J.realtime.createCall({sdp:Z,session:B,safetyIdentifier:Y.safetyIdentifier})}catch(L){await z(L);let O=L instanceof b&&L.code==="rate_limited";return M(O?429:502,{code:"voice_unavailable",message:"Voice isn't available right now."})}D=P.callId;try{await this.voiceStore.create({id:U,callId:P.callId,threadId:F,owner:await this.runOwner($),body:X,startedAt:H});let{threadId:L,session:O,safetyIdentifier:j,mcp:R,tools:q,...d}=Y;return{sessionId:p.start({...d,tools:N,controller:this.constructor,threadId:F,user:V,body:X,call:{realtime:J.realtime,callId:P.callId},sessionId:U,store:this.voiceStore,liveRuns:this.liveRuns,delegate:J.delegate,session:B}).sessionId,sdp:P.sdpAnswer,threadId:F,delegate:J.delegate?.name??D$,endsAt:H+(Y.limits?.maxDurationMs??900000)}}catch(L){return await z(L),M(500,{code:"voice_unavailable",message:"Voice isn't available right now."})}}async voiceUpdate($=new x){if(!this.voice)return tJ();let J=await this.voiceSession($);if(J instanceof Response)return J;let Q=await N$($,d$);if(Q.error)return J$(Q);let Z=n$(Q.body,[]);if(await this.authorizeRequest($,{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}),p.get(J.id)?.setBody(Z),{updated:!0}}async voiceEnd($=new x){let J=this.voice;if(!J)return tJ();let Q=await this.voiceSession($);if(Q instanceof Response)return Q;if(await this.authorizeRequest($,{route:"stream",threadId:Q.threadId,body:Q.body}),Q.endedAt!==void 0)return{ended:!1};let Z=p.get(Q.id);if(Z)await Z.end("hangup");else await J.realtime.hangup(Q.callId),await this.voiceStore.update(Q.id,{endedAt:Date.now(),endReason:"hangup"});return{ended:!0}}async voiceSession($){let J=$.params?.sessionId,Q=typeof J==="string"&&J?await this.voiceStore.get(J):null;if(!Q)return M(404,{code:"voice_not_found",message:"No such voice session."});if(Q.owner!==null&&Q.owner!==await this.runOwner($))return U$();return Q}async upload($=new x){let J=await $.rawRequest.formData(),Q=J.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=T0(J.get("body")),X=J.get("threadId");await this.authorizeRequest($,{route:"upload",threadId:typeof X==="string"&&X.length>0?X:void 0,body:K});let G=k0(await this.attachmentLimits($),Q,Z,W);if(G)throw new $8(G.code,G.message);let V=typeof X==="string"&&X.length>0&&await this.store.loadThread(X)!==null?X:void 0,Y=await this.runOwner($),H=(R)=>this.fileOwners.record(R,{owner:Y,name:Z,mimeType:W,size:Q.size,createdAt:new Date().toISOString()}),D={body:K,threadId:V},z=await this.checkUpload({name:Z,size:Q.size,mimeType:W},$,D);if(z)throw new $8(z.code||"upload_refused",z.message);let F=await this.attachmentDestination(Q,$,D),U=c0(F,J.get("destination")),N=await this.attachmentScope($,V,{body:K}),B=U!=="provider"&&!N;if(B){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()`.');m0()}if(U==="provider"||!N){let R=await XQ(this.agent.provider,Q);await H(R);let q={fileId:R,name:Z,mimeType:W,size:Q.size,destination:"provider"};if(B)q.downgraded="no_scope";return q}let P=SQ(),L=await this.attachmentStorage.put({name:AQ(P,Z),body:Q,contentType:W}),O=U==="both"?await XQ(this.agent.provider,Q):void 0;if(O)await H(O);let j={id:P,scopeKey:N.key,fileId:O,objectName:L,name:Z,mimeType:W,size:Q.size,createdAt:new Date().toISOString(),destination:U};return await this.attachments.put(N,j),{fileId:O,attachmentId:P,name:Z,mimeType:W,size:Q.size,destination:U}}async foreignFile($,J){let Q=new Set($.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!==J:this.requireKnownFiles)return h0()}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 W8($,J)}onError($,J){return this.hooks?.onError?.($,J)}onStreamComplete($,J){return this.hooks?.onStreamComplete?.($,J)}reportHookFailure($){let J=this.hooks?.reportHookFailure;if(J)try{return J($)}catch(Q){console.error("[gemi/ai] reportHookFailure hook failed",Q)}console.error("[gemi/ai] agent controller hook failed",$)}async dispatchEvent($,J){switch($.type){case"tool-call":if(!$.part.partial&&!$.resent)await this.onToolCall({toolCallId:$.part.toolCallId,name:String($.part.name),input:$.part.input},J);return;case"tool-result":{let Q=$.part;await this.onToolResult(Q,J,{toolCallId:Q.toolCallId,name:String(Q.name),input:jQ(Q)});return}case"awaiting-input":await this.onAwaitingInput($.pending,J);return;case"error":await this.onError(CQ($.error),J);return;default:return}}async readThread($){let J=await this.store.loadThread($);if(!J)return null;let{messages:Q}=await this.settleThread($,J,{write:!1});return Q}isRunLive($,J){return this.liveRuns.get($)!==null}async settleThread($,J,{write:Q}){let Z=(V)=>this.isRunLive(V,$),W=await t9(J,Z),K=W.messages,X=[],G=new Map(W.settled.map((V)=>[V.id,V]));if(i0(K)||Q)try{let V=await JQ(K,{threadId:$,store:v.store,isRunLive:Z,outputSchemaFor:(Y)=>this.toolNamed(Y)?.outputSchema,modelOutputFor:(Y,H)=>TQ(this.toolNamed(Y),H,(D)=>this.reportHookFailure(D)),scan:this.jobsBlockMax()});K=V.messages,X=V.jobs;for(let Y of V.settled)G.set(Y.id,Y);if(Q&&V.orphans.length>0){await QQ(v.store,V.orphans,(H)=>this.reportHookFailure(H));let Y=new Set(V.orphans.map((H)=>H.id));X=X.map((H)=>Y.has(H.id)?{...H,orphaned:!0}:H)}}catch(V){this.reportHookFailure(V)}if(Q&&G.size>0)try{await this.store.appendMessages($,[...G.values()])}catch(V){this.reportHookFailure(V)}return{messages:K,jobs:X}}jobsBlockMax(){let $=this.agent.jobs?.contextBlock;if($===!1)return 0;return $?.max??M$}jobsBlock($){return N8($,this.jobsBlockMax())}toolNamed($){let J=(Q)=>{for(let Z of Q){let W=Z;if(Array.isArray(W.tools)){let K=J(W.tools);if(K)return K}else if(W.name===$)return W}return};return J(this.agent.tools??[])}follow($,J){(async()=>{try{for await(let Q of $.frames())J.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 $.result()}catch(H){Z?.close(),await Z?.settled(),K=W.notified.then(()=>this.safely(()=>this.onError({code:"unknown",message:H instanceof Error?H.message:String(H),retryable:!1},J)));return}let Y=V.messages;if(Z?.close(Y),await Z?.settled(),J.threadId&&Y.length>0)try{await this.store.appendMessages(J.threadId,Y)}catch(H){this.reportHookFailure(H)}K=this.notifyRun(V,Y,J,W)})(),G=X.then(()=>l0(Promise.all([K,Q]).then(()=>{}),this.hookHoldMs));return{stored:X,hooks:G}}async notifyRun($,J,Q,Z){await Z.notified;for(let W of J){if(W.id===Z.id)continue;await this.safely(()=>this.onMessage(W,Q))}await this.safely(()=>this.onStreamComplete($,Q))}async safely($){try{await $()}catch(J){this.reportHookFailure(J)}}}var rJ=["turn","clientRunId","threadId","messages","regenerate"],E0=["text","files","toolResults"];function n$($,J=qQ($)?rJ:[...rJ,...E0]){let Q={};for(let[Z,W]of Object.entries($)){if(J.includes(Z))continue;Object.defineProperty(Q,Z,{value:W,writable:!0,enumerable:!0,configurable:!0})}return Q}function T0($){if($===null)return{};let J;if(typeof $==="string")try{J=JSON.parse($)}catch{throw new eJ("The upload's `body` field is not valid JSON.")}if(J===null||typeof J!=="object"||Array.isArray(J))throw new eJ("The upload's `body` field must be a JSON object.");return n$(J,rJ)}class eJ extends o${constructor($){super($);this.name="InvalidUploadError",this.payload={api:{status:400,data:{error:{code:"invalid_request",message:$}}},view:{}}}}async function XQ($,J){try{return await $.upload(J)}catch(Q){if(Q instanceof I&&j0.has(Q.status))throw new xQ(T(Q).message);throw Q}}var j0=new Set([400,413,415,422]);class $8 extends o${constructor($,J){super(J);this.name="LimitedUploadError",this.payload={api:{status:422,data:{error:{code:$,message:J}}},view:{}}}}function k0($,J,Q,Z){if(!$)return null;let{maxBytes:W,accept:K}=$;if(typeof W==="number"&&J.size>W)return{code:"file_too_large",message:`${JSON.stringify(Q)} is ${YQ(J.size)}; the limit is ${YQ(W)}.`};if(K&&K.length>0&&!K.some((X)=>x0(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 x0($,J,Q){let Z=$.trim().toLowerCase();if(!Z)return!1;if(Z.startsWith("."))return J.toLowerCase().endsWith(Z);let W=Q.toLowerCase().split(";")[0].trim();if(Z.endsWith("/*"))return W.startsWith(Z.slice(0,-1));return W===Z}function YQ($){if($<1024)return`${$} B`;let J=["KB","MB","GB"],Q=$/1024,Z=0;while(Q>=1024&&Z<J.length-1)Q/=1024,Z++;return`${Math.round(Q*10)/10} ${J[Z]}`}class xQ extends o${constructor($){super($);this.name="RejectedUploadError";let J=/(unsupported|invalid) (extension|file type|format|mime)|supported (extensions|formats?)/i.test($)?"unsupported_file_type":"file_rejected";this.payload={api:{status:422,data:{error:{code:J,message:$}}},view:{}}}}async function N$($,J){let Q=$?.rawRequest;if(!Q||Q.method==="GET"||Q.method==="HEAD"||!Q.body)return{body:{}};if(!q0(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>J)return GQ(J);let W;try{let X=await I0(Q,J);if(X===null)return GQ(J);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 q0($){return PQ($)==="application/json"}async function I0($,J){if(!Number.isFinite(J)||!$.body)return await $.text();let Q=$.body.getReader(),Z=[],W=0;for(;;){let{done:G,value:V}=await Q.read();if(G)break;if(W+=V.byteLength,W>J)return await Q.cancel().catch(i$),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 GQ($){return{body:{},status:413,code:"body_too_large",error:`The request body is larger than this agent accepts (${$} bytes).`}}function J8($,J,Q){return M($,{...s$(BQ($),Q,$),code:J})}function J$($){if($.status===413)return J8(413,$.code??"body_too_large",$.error??"");return M($.status??400,{code:$.code??"invalid_request",message:$.error})}function qQ($){return Boolean($.turn)&&typeof $.turn==="object"}function w0($){let J=qQ($)?$.turn:$,Q={};if(typeof J.text==="string")Q.text=J.text;if(Array.isArray(J.files)){let Z=b0(J.files);if(typeof Z==="string")return{error:Z};Q.files=Z}if(Array.isArray(J.toolResults))Q.toolResults=J.toolResults;if(Object.keys(Q).length===0)return{};if(J===$.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>VQ)return{error:`turn.localId is longer than ${VQ} characters.`};Q.localId=Z}return{turn:Q}}var VQ=200;function b0($){let J=[];for(let[Q,Z]of $.entries()){let W=`turn.files[${Q}]`;if(!Z||typeof Z!=="object"||Array.isArray(Z))return`${W} must be an object.`;let K={};for(let H of["fileId","attachmentId","name","mimeType"]){let D=Z[H];if(D===void 0||D===null||D==="")continue;if(typeof D!=="string")return`${W}.${H} must be a string.`;K[H]=D}let{fileId:X,attachmentId:G,name:V,mimeType:Y}=K;if(X?.startsWith(m))return`${W}.fileId holds a gemi attachment id (${X}). \`fileId\` is the provider's id from the upload response; put this one in \`attachmentId\`.`;if(G!==void 0&&!G.startsWith(m))return`${W}.attachmentId is not a gemi attachment id: it must start with "${m}".`;if(!X&&!G)return`${W} has neither a \`fileId\` nor an \`attachmentId\`. Send the ids the upload response answered.`;J.push({...X?{fileId:X}:{},...G?{attachmentId:G}:{},...V!==void 0?{name:V}:{},...Y!==void 0?{mimeType:Y}:{}})}return J}function f0($,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(Q){let Z=Number.parseInt(Q,10);if(Number.isFinite(Z))return Math.max(0,Z+1)}return}function v0($,J){let Q=$?.search?.get(J);return typeof Q==="string"?Q:void 0}function y0($){let J=K8($);for(let Q=$.length-1;Q>=0;Q--){let Z=$[Q];if(Z.role!=="user"||J.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 HQ(){return M(409,{code:"stopped",message:"The turn was stopped before it started."})}function U$(){return M(403,s$("permission","This run belongs to someone else.",403))}function h0(){return M(403,s$("permission","A file in this turn was uploaded by someone else.",403))}function g0($){if(!Array.isArray($))return[];let J=[];for(let Q of $){let Z=Q?.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 u0=["sdp","threadId","pushToTalk"];function tJ(){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:J}),{status:$,headers:{"Content-Type":"application/json"}})}function c0($,J){if(typeof J!=="string"||J.length===0)return $;if(J!=="both"&&J!=="provider"&&J!=="storage")throw Error(`Unknown attachment destination "${J}". Expected "both", "provider" or "storage".`);if(J===$||$==="both"&&J==="storage")return J;if($==="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 "${$}", and a client hint may only ask for "storage" under a "both" policy. Change \`attachmentDestination()\` if the file really should go there.`)}var zQ=!1;function m0(){if(zQ)return;zQ=!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 p0=2147483647;function l0($,J){let Q=$.then(()=>{},()=>{});if(!(J<=p0))return Q;let Z,W=new Promise((K)=>{Z=setTimeout(K,J)});return Promise.race([Q,W]).finally(()=>clearTimeout(Z))}var DQ=!1;function d0($){if(DQ||Bun.env.NODE_ENV!=="production")return;if(!($ instanceof Q8))return;DQ=!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 i0($){return $.some((J)=>J.content.some((Q)=>Q.type==="tool-result"&&Q.status==="running"))}export{Q6 as windowMessages,z$ as voiceTools,t0 as turnStarts,w$ as toRealtimeUsage,JZ as toAgentTools,s0 as supportsStrict,r0 as splitTurns,V6 as settleSummaries,o0 as s,W8 as redactError,L6 as parsePartialJson,e0 as messageSize,X$ as measureUsage,hJ as mcpVoiceTools,mJ as liveRuns,F$ as keepSummary,E9 as isCallNotFound,K8 as injectedMessageIds,FJ as generate,sZ as evalChain,R0 as defineAgentHooks,uJ as defaultVoiceStore,z6 as defaultUsageLimitStore,G6 as defaultSummaryStore,Z8 as defaultNonceStore,pJ as defaultFileOwners,t$ as defaultAttachmentStore,oJ as defaultAgentStore,g$ as VoiceHangup,p as VoiceBridge,a0 as Usage,PJ as ToolNamespace,g as ToolError,F6 as Skill,a$ as ScopedAttachments,B6 as SKILLS_NAMESPACE,nJ as RedisReceiptStore,LQ as RedisNonceStore,b$ as RealtimeSideband,b as RealtimeRequestError,V$ as RealtimeClient,F8 as Prompt,OQ as PrismaNonceStore,D6 as PendingEscalation,bJ as OpenAIProvider,CJ as OpenAIImageProvider,gJ as MemoryVoiceSessionStore,H6 as MemoryUsageLimitStore,Y6 as MemorySummaryStore,iJ as MemoryReceiptStore,Q8 as MemoryNonceStore,u$ as MemoryLiveRuns,c$ as MemoryFileOwners,y$ as MemoryCircuitStore,RQ as MemoryAttachmentStore,m$ as MemoryAgentStore,O8 as MemoryAgentJobStore,v8 as MEMORY_NAMESPACE,B$ as LiveRunNotFoundError,_8 as JobsRequireThreadError,C8 as JobHandle,n0 as JSONSchemaError,MQ as InvalidAttachmentScopeError,x8 as InMemoryAgentMemoryStore,x$ as ImageRequestError,q$ as ImageProvider,NJ as ImageModel,$$ as FrameCursorEvictedError,H$ as FallbackProvider,b8 as FakeAgentMemoryStore,T$ as Eval,u9 as DatabaseAgentStore,YJ as DatabaseAgentMemoryStore,KJ as DatabaseAgentJobStore,A9 as DEFAULT_TRANSCRIPTION_MODEL,k8 as DEFAULT_MEMORY_MAX_TOKENS,f8 as DEFAULT_MEMORY_LIMITS,Z6 as DEFAULT_MAX_SUMMARY_TOKENS,P6 as DEFAULT_MAX_RUN_DURATION_MS,M8 as DEFAULT_JOB_DEADLINE_MS,M$ as DEFAULT_JOBS_CONTEXT_MAX,D$ as DEFAULT_DELEGATE_NAME,$6 as DEFAULT_CONTEXT_WINDOW_STEP,J6 as DEFAULT_CONTEXT_WINDOW_NOTE,W6 as DEFAULT_COMPACT_TRIGGER_TOKENS,K6 as DEFAULT_COMPACT_INSTRUCTIONS,X6 as COMPACT_SUMMARY_HEADER,fJ as AzureOpenAIProvider,_J as AzureOpenAIImageProvider,_Q as AttachmentNotFoundError,r$ as AgentTurnError,j$ as AgentTool,N6 as AgentRunError,e as AgentProvider,q8 as AgentMemoryRefusedError,I8 as AgentMemoryConflictError,w8 as AgentMemories,v as AgentJobs,QJ as AgentJobDeadlineSweep,S8 as AgentJob,X8 as AgentController,U6 as Agent};
243
243
 
244
- //# debugId=14E2EA9ED452C95264756E2164756E21
244
+ //# debugId=E03BE52234C9D4B464756E2164756E21