gemi 0.194.0 → 0.195.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 (63) hide show
  1. package/dist/ai/index.js +2 -2
  2. package/dist/ai/index.js.map +1 -1
  3. package/dist/{chunk-svtjfmkc.js → chunk-0y7jqe6m.js} +2 -2
  4. package/dist/{chunk-svtjfmkc.js.map → chunk-0y7jqe6m.js.map} +1 -1
  5. package/dist/{chunk-mc8fdh65.js → chunk-39w89wss.js} +2 -2
  6. package/dist/{chunk-mc8fdh65.js.map → chunk-39w89wss.js.map} +1 -1
  7. package/dist/{chunk-1yhvqthv.js → chunk-3qmvtfw2.js} +2 -2
  8. package/dist/{chunk-1yhvqthv.js.map → chunk-3qmvtfw2.js.map} +1 -1
  9. package/dist/{chunk-1m7kqf2t.js → chunk-5qcqwcp7.js} +3 -3
  10. package/dist/{chunk-1m7kqf2t.js.map → chunk-5qcqwcp7.js.map} +1 -1
  11. package/dist/{chunk-3svm89z4.js → chunk-652a9mr0.js} +2 -2
  12. package/dist/{chunk-3svm89z4.js.map → chunk-652a9mr0.js.map} +1 -1
  13. package/dist/{chunk-63dh2zt4.js → chunk-6efjnt6r.js} +2 -2
  14. package/dist/{chunk-63dh2zt4.js.map → chunk-6efjnt6r.js.map} +1 -1
  15. package/dist/{chunk-h9taahxv.js → chunk-7zf8rnsb.js} +3 -3
  16. package/dist/{chunk-h9taahxv.js.map → chunk-7zf8rnsb.js.map} +1 -1
  17. package/dist/chunk-afs0geyy.js +10 -0
  18. package/dist/{chunk-c6khfprk.js.map → chunk-afs0geyy.js.map} +3 -4
  19. package/dist/{chunk-jq1vwj5g.js → chunk-ahx3g8tq.js} +1 -1
  20. package/dist/chunk-ggbf1web.js +5 -0
  21. package/dist/{chunk-gn90agsv.js.map → chunk-ggbf1web.js.map} +1 -1
  22. package/dist/{chunk-scmjmsps.js → chunk-j56zk5a0.js} +3 -3
  23. package/dist/{chunk-scmjmsps.js.map → chunk-j56zk5a0.js.map} +1 -1
  24. package/dist/{chunk-495k9h6p.js → chunk-mndcq5z1.js} +2 -2
  25. package/dist/{chunk-495k9h6p.js.map → chunk-mndcq5z1.js.map} +1 -1
  26. package/dist/{chunk-v20fe53s.js → chunk-nphb176s.js} +9 -9
  27. package/dist/{chunk-v20fe53s.js.map → chunk-nphb176s.js.map} +5 -4
  28. package/dist/{chunk-geqdq8hp.js → chunk-p4eger3g.js} +2 -2
  29. package/dist/{chunk-geqdq8hp.js.map → chunk-p4eger3g.js.map} +1 -1
  30. package/dist/{chunk-xpkpz4g6.js → chunk-vqq0z746.js} +2 -2
  31. package/dist/{chunk-xpkpz4g6.js.map → chunk-vqq0z746.js.map} +1 -1
  32. package/dist/{chunk-5nkg3rmw.js → chunk-xjb8frdx.js} +3 -3
  33. package/dist/{chunk-5nkg3rmw.js.map → chunk-xjb8frdx.js.map} +1 -1
  34. package/dist/console/run.js +2 -2
  35. package/dist/console/run.js.map +1 -1
  36. package/dist/database/index.js +1 -1
  37. package/dist/facades/index.js +2 -2
  38. package/dist/facades/index.js.map +1 -1
  39. package/dist/http/index.js +2 -2
  40. package/dist/http/index.js.map +1 -1
  41. package/dist/i18n/index.js +2 -2
  42. package/dist/i18n/index.js.map +1 -1
  43. package/dist/kernel/index.js +2 -2
  44. package/dist/kernel/index.js.map +1 -1
  45. package/dist/orm/index.js +2 -2
  46. package/dist/orm/index.js.map +1 -1
  47. package/dist/server/index.js +1 -1
  48. package/dist/services/index.d.ts +1 -1
  49. package/dist/services/index.d.ts.map +1 -1
  50. package/dist/services/index.js +3 -3
  51. package/dist/services/index.js.map +1 -1
  52. package/dist/services/logging/LogManager.d.ts +10 -1
  53. package/dist/services/logging/LogManager.d.ts.map +1 -1
  54. package/dist/services/logging/config.d.ts +29 -0
  55. package/dist/services/logging/config.d.ts.map +1 -1
  56. package/dist/services/queue/work.js +2 -2
  57. package/dist/services/queue/work.js.map +1 -1
  58. package/dist/support/index.js +2 -2
  59. package/dist/support/index.js.map +1 -1
  60. package/package.json +1 -1
  61. package/dist/chunk-c6khfprk.js +0 -10
  62. package/dist/chunk-gn90agsv.js +0 -5
  63. /package/dist/{chunk-jq1vwj5g.js.map → chunk-ahx3g8tq.js.map} +0 -0
package/dist/ai/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  // @bun
2
- import{$b as G8,$c as C6,Ac as XQ,Bc as GQ,Cc as E8,Ec as j8,Fc as q8,Gc as x8,Hc as w8,Ic as I8,Jc as b8,Kc as f8,Lc as y8,Mc as v8,Nc as h8,Oc as g8,Pc as u8,Rc as b,Sc as G9,Tc as A9,Uc as R9,Vc as E9,Wc as t,Xc as x,Yb as X8,Yc as V8,Zb as qQ,Zc as B6,_b as bQ,_c as L6,ad as O6,bd as _6,cc as yJ,cd as M6,dc as E,dd as S6,ec as k,ed as A6,fd as R6,gc as Z9,gd as E6,hc as t8,hd as j6,ic as VJ,id as NJ,jc as N6,jd as k6,kc as m,kd as cQ,lc as Y8,ld as T6,mc as fQ,md as mQ,nc as yQ,nd as x6,oc as vQ,od as w6,pc as d,pd as I6,qc as hQ,qd as IJ,rc as aJ,rd as U$,sc as gQ,sd as q6,tc as uQ,td as b6,uc as tJ,ud as pQ,vc as S8,vd as f6,wc as A8,wd as y6,xd as v6,yc as R8,yd as h6,zc as g,zd as F$}from"../chunk-5nkg3rmw.js";import{Rd as L8}from"../chunk-495k9h6p.js";import"../chunk-mc8fdh65.js";import{$i as xQ,Rh as RQ,Uh as jQ,Vi as kQ,Yi as i$,Zi as TQ,aj as wQ,bj as IQ,ii as w9,ji as F6,ki as P6,li as U6,mi as q}from"../chunk-v20fe53s.js";import{cj as EQ,ej as oJ,fj as sJ}from"../chunk-228w21t6.js";import{oj as c}from"../chunk-dfmxvp8p.js";import"../chunk-1705yamg.js";import"../chunk-gmcttf0f.js";import"../chunk-beckfwe9.js";import{Gk as TJ,rk as s,sk as a}from"../chunk-wvq3c25z.js";import"../chunk-ftvc1a0k.js";import"../chunk-8e17k7ht.js";import{tl as a9}from"../chunk-ermvtpy9.js";import"../chunk-1x23scpn.js";import"../chunk-5bfrr8x5.js";import{Ml as $$}from"../chunk-aycfrzh1.js";import"../chunk-vgxkt9vd.js";import{existsSync as tQ,readdirSync as u6,readFileSync as U8}from"fs";import{isAbsolute as rQ,join as SJ,relative as eQ,sep as JZ}from"path";var N8="prompts.json",$Z=/\{\{>\s*([\w./-]+)\s*\}\}/g,D8=/\{\{(\w+)\}\}/g,QZ=/^[\w-]+(\/[\w-]+)*$/,F8={dir:"app/agents",shared:"prompts"},RJ={},eJ=new Map,AJ;function ZZ(){if(AJ===void 0){let J=SJ($$(),"dist","server",N8);AJ=tQ(J)?JSON.parse(U8(J,"utf8")):null}return AJ??null}function WZ(J){return J.replace(/\r?\n$/,"")}function P8(){return RJ.cache??Bun.env.NODE_ENV==="production"}function KZ(J){if(!QZ.test(J))throw Error(`"${J}" is not a prompt name. Use letters, digits, "-" and "_", with "/" between folders.`);let $=RJ.dir??F8.dir,Q=rQ($)?$:SJ(process.cwd(),$),Z=J.includes("/")?`${J}.md`:SJ(RJ.shared??F8.shared,`${J}.md`);return SJ(Q,Z)}function XZ(J){let $=KZ(J),Q=P8()?eJ.get($):void 0;if(Q!==void 0)return Q;let Z=Bun.env.NODE_ENV==="production";if(Z){let K=ZZ()?.[eQ($$(),$).split(JZ).join("/")];if(K!==void 0)return K}let W;try{W=WZ(U8($,"utf8"))}catch(K){if(K.code==="ENOENT"){let X=Z?` or in dist/server/${N8}`:"";throw Error(`The prompt "${J}" does not exist (looked for ${$}${X}).`)}throw K}if(P8())eJ.set($,W);return W}function J$(J,$){if($.includes(J))throw Error(`The prompt "${J}" includes itself: ${[...$,J].join(" > ")}.`);return XZ(J).replace($Z,(Q,Z)=>J$(Z,[...$,J]))}class B8{static configure(J){RJ={...J},eJ.clear(),AJ=void 0}static render(J,$={}){return J$(J,[]).replace(D8,(Q,Z)=>{if(!Object.hasOwn($,Z))throw Error(`The prompt "${J}" has no value for {{${Z}}}.`);return String($[Z])})}static placeholders(J){let $=[...J$(J,[]).matchAll(D8)].map((Q)=>Q[1]);return[...new Set($)]}}class Q$ extends L8{name="AgentJobDeadlineSweep";cron="* * * * *";async callback(){while(await g.sweep({limit:100})===100);}}var EJ=20;function O8(J,$){if($<=0||J.length===0)return null;let Q=(K,X)=>X.createdAt-K.createdAt||(K.id<X.id?1:-1);return["<jobs>","Background jobs that tools started in this conversation, running ones first. A running job's result replaces its tool result when it finishes. Do not start the same work again while a job for it is running.",...[...J.filter((K)=>K.state==="running").sort(Q),...J.filter((K)=>K.state!=="running").sort(Q)].slice(0,$).map((K)=>{let X=[`- ${K.id} (${K.toolName})`];if(K.state==="running")X.push(`running since ${Z$(K.createdAt)}`);else if(K.state==="ok")X.push(`finished at ${Z$(K.settledAt??K.updatedAt)}`);else{let Y=K.error?`${K.error.code}: ${C8(K.error.message,200)}`:"failed";X.push(`failed at ${Z$(K.settledAt??K.updatedAt)} (${Y})`)}if(K.summary!==void 0)X.push(`summary: ${C8(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{$c as _6,Ac as E8,Cc as j8,Dc as q8,Ec as x8,Fc as w8,Gc as I8,Hc as b8,Ic as f8,Jc as y8,Kc as v8,Lc as h8,Mc as g8,Nc as u8,Pc as b,Qc as G9,Rc as A9,Sc as R9,Tc as E9,Uc as t,Vc as x,Wb as X8,Wc as V8,Xb as qQ,Xc as B6,Yb as bQ,Yc as L6,Zb as G8,Zc as C6,_c as O6,ac as yJ,ad as M6,bc as E,bd as S6,cc as k,cd as A6,dd as R6,ec as Z9,ed as E6,fc as t8,fd as j6,gc as VJ,gd as NJ,hc as N6,hd as k6,ic as m,id as cQ,jc as Y8,jd as T6,kc as fQ,kd as mQ,lc as yQ,ld as x6,mc as vQ,md as w6,nc as d,nd as I6,oc as hQ,od as IJ,pc as aJ,pd as U$,qc as gQ,qd as q6,rc as uQ,rd as b6,sc as tJ,sd as pQ,tc as S8,td as f6,uc as A8,ud as y6,vd as v6,wc as R8,wd as h6,xc as g,xd as F$,yc as XQ,zc as GQ}from"../chunk-xjb8frdx.js";import{Pd as L8}from"../chunk-mndcq5z1.js";import"../chunk-39w89wss.js";import{$i as xQ,Ph as RQ,Sh as jQ,Ti as kQ,Yi as i$,Zi as TQ,aj as wQ,bj as IQ,gi as w9,hi as F6,ii as P6,ji as U6,ki as q}from"../chunk-nphb176s.js";import{cj as EQ,ej as oJ,fj as sJ}from"../chunk-228w21t6.js";import{oj as c}from"../chunk-dfmxvp8p.js";import"../chunk-1705yamg.js";import"../chunk-gmcttf0f.js";import"../chunk-beckfwe9.js";import{Gk as TJ,rk as s,sk as a}from"../chunk-wvq3c25z.js";import"../chunk-ftvc1a0k.js";import"../chunk-8e17k7ht.js";import{tl as a9}from"../chunk-ermvtpy9.js";import"../chunk-1x23scpn.js";import"../chunk-5bfrr8x5.js";import{Ml as $$}from"../chunk-aycfrzh1.js";import"../chunk-vgxkt9vd.js";import{existsSync as tQ,readdirSync as u6,readFileSync as U8}from"fs";import{isAbsolute as rQ,join as SJ,relative as eQ,sep as JZ}from"path";var N8="prompts.json",$Z=/\{\{>\s*([\w./-]+)\s*\}\}/g,D8=/\{\{(\w+)\}\}/g,QZ=/^[\w-]+(\/[\w-]+)*$/,F8={dir:"app/agents",shared:"prompts"},RJ={},eJ=new Map,AJ;function ZZ(){if(AJ===void 0){let J=SJ($$(),"dist","server",N8);AJ=tQ(J)?JSON.parse(U8(J,"utf8")):null}return AJ??null}function WZ(J){return J.replace(/\r?\n$/,"")}function P8(){return RJ.cache??Bun.env.NODE_ENV==="production"}function KZ(J){if(!QZ.test(J))throw Error(`"${J}" is not a prompt name. Use letters, digits, "-" and "_", with "/" between folders.`);let $=RJ.dir??F8.dir,Q=rQ($)?$:SJ(process.cwd(),$),Z=J.includes("/")?`${J}.md`:SJ(RJ.shared??F8.shared,`${J}.md`);return SJ(Q,Z)}function XZ(J){let $=KZ(J),Q=P8()?eJ.get($):void 0;if(Q!==void 0)return Q;let Z=Bun.env.NODE_ENV==="production";if(Z){let K=ZZ()?.[eQ($$(),$).split(JZ).join("/")];if(K!==void 0)return K}let W;try{W=WZ(U8($,"utf8"))}catch(K){if(K.code==="ENOENT"){let X=Z?` or in dist/server/${N8}`:"";throw Error(`The prompt "${J}" does not exist (looked for ${$}${X}).`)}throw K}if(P8())eJ.set($,W);return W}function J$(J,$){if($.includes(J))throw Error(`The prompt "${J}" includes itself: ${[...$,J].join(" > ")}.`);return XZ(J).replace($Z,(Q,Z)=>J$(Z,[...$,J]))}class B8{static configure(J){RJ={...J},eJ.clear(),AJ=void 0}static render(J,$={}){return J$(J,[]).replace(D8,(Q,Z)=>{if(!Object.hasOwn($,Z))throw Error(`The prompt "${J}" has no value for {{${Z}}}.`);return String($[Z])})}static placeholders(J){let $=[...J$(J,[]).matchAll(D8)].map((Q)=>Q[1]);return[...new Set($)]}}class Q$ extends L8{name="AgentJobDeadlineSweep";cron="* * * * *";async callback(){while(await g.sweep({limit:100})===100);}}var EJ=20;function O8(J,$){if($<=0||J.length===0)return null;let Q=(K,X)=>X.createdAt-K.createdAt||(K.id<X.id?1:-1);return["<jobs>","Background jobs that tools started in this conversation, running ones first. A running job's result replaces its tool result when it finishes. Do not start the same work again while a job for it is running.",...[...J.filter((K)=>K.state==="running").sort(Q),...J.filter((K)=>K.state!=="running").sort(Q)].slice(0,$).map((K)=>{let X=[`- ${K.id} (${K.toolName})`];if(K.state==="running")X.push(`running since ${Z$(K.createdAt)}`);else if(K.state==="ok")X.push(`finished at ${Z$(K.settledAt??K.updatedAt)}`);else{let Y=K.error?`${K.error.code}: ${C8(K.error.message,200)}`:"failed";X.push(`failed at ${Z$(K.settledAt??K.updatedAt)} (${Y})`)}if(K.summary!==void 0)X.push(`summary: ${C8(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 Z$(J){return new Date(J).toISOString().replace(/\.\d{3}Z$/,"Z")}function C8(J,$){return J.length<=$?J:`${J.slice(0,$-1)}\u2026`}class K${table;sql;dialect;connection;constructor(J,$={}){let Q=$.table??"gemi_agent_jobs";if(!/^[A-Za-z_][A-Za-z0-9_]*$/.test(Q))throw Error(`The agent jobs table name "${Q}" is not a plain identifier. Use letters, digits and underscores.`);this.table=Q,this.sql=J.sql,this.dialect=J.dialect,this.connection=J.name}async createTable(){for(let J of GZ(this.dialect,this.table))await this.sql.unsafe(J)}async transaction(J){if(this.connection===void 0||this.joinable())return J();return TJ(this.sql,()=>J(),{connection:this.connection})}async create(J){let $=this.q(),Q=this.clock($);await $`
4
4
  INSERT INTO ${this.name($)}
5
5
  (id, thread_id, run_id, tool_call_id, tool_name, owner, job, summary, state,
@@ -264,4 +264,4 @@ return 0`;class o${injectedClient;prefix;constructor(J={}){this.injectedClient=J
264
264
 
265
265
  `)||void 0,L=await this.context(J,{body:V}),C=await this.reasoning(J,{body:V})||void 0,w=await this.skills(J,{body:V})||void 0,R=await this.runTools(J,{body:V,context:L})||void 0,M=await this.usageLimits(J,{body:V,context:L})||void 0,O=await this.attachmentsFor(J,Z,{body:V}),I=this.agent.memory?await this.memoryScopes(J,{body:V}):void 0;if(H?.cancelled)return CQ();let _=Z?new t$(this.store,Z,P,(T)=>this.reportHookFailure(T)):null,j=`run_${crypto.randomUUID()}`,S={req:J,runId:j,threadId:Z},MJ={id:null,notified:Promise.resolve()},y=this.agent.stream({runId:j,messages:P,turn:K,threadId:Z,..._?{onMessage:(T)=>_.finish(T)}:{},onTurn:(T)=>{if(MJ.id!==null)return;MJ.id=T.id;let o=_?_.settled():Promise.resolve();MJ.notified=o.then(()=>this.safely(()=>this.onMessage(T,S)))},instructions:U,...e$.has(J)?{event:e$.get(J)}:{},...QJ.has(J)?{echoTurn:!0}:{},...C?{reasoning:C}:{},...w&&w.length>0?{skills:w}:{},...R?.tools&&R.tools.length>0?{tools:R.tools}:{},...R?.activeTools?{activeTools:R.activeTools}:{},...M?{usageLimits:M}:{},context:L,attachments:O,body:V,redactError:(T,o)=>this.redactError(T,o,S),nonces:this.nonces,receipts:this.receipts,subject:G,...I?{memory:{scopes:I,...this.memoryMaxTokens!==void 0?{maxTokens:this.memoryMaxTokens}:{}}}:{},...Z?{jobs:{owner:G}}:{},...this.contextWindow!==void 0?{contextWindow:this.contextWindow}:{},...Z&&cQ(this.store)?{summaryStore:this.store}:{},...this.prepareStep!==H8.prototype.prepareStep||this.hooks?.prepareStep?{prepareStep:(T)=>this.prepareStep(T,S)}:{}}),oQ=this.liveRuns.register(y,{threadId:Z,owner:G,clientRunId:Y,onEvent:(T)=>this.dispatchEvent(T,S),onInternalError:(T)=>this.reportHookFailure(T),maxRunDurationMs:this.agent.maxRunDurationMs});if(D=y,_)this.follow(y,_);if(Z)p0(this.liveRuns,Z,y.runId);let{stored:sQ,hooks:z8}=this.persistRun(y,S,oQ,_,MJ);if(r$.set(y,sQ),QJ.has(J))QJ.set(J,{run:y,hooks:z8});return J.ctx?.()?.waitUntil(z8),y.toResponse()};try{await this.authorizeRequest(J,{route:"stream",threadId:Z,body:V});let P=await this.foreignFile([...K?.files??[],...Z?[]:K6(Q.messages)],G);if(P)return P;if(H?.cancelled)return CQ();let N=await this.runLimitKey(J,{owner:G,threadId:Z}),U=N===null?WJ:l0(this.liveRuns).take(N,Z?`thread:${Z}`:`run:${crypto.randomUUID()}`,this.maxConcurrentRuns);if(!U)return K8(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,G,F,zQ.get(J)??"supersede"):await F()}finally{let L=D;if(L)L.result().then(U,U);else U()}}finally{if(H&&iJ.get(Y)===H)iJ.delete(Y)}}async withThread(J,$,Q,Z="supersede"){if(Z==="skip"&&CJ.has(J))return OQ(J);for(;;){let W=await this.underThreadLock(J,$,Q,Z);if(!("waitFor"in W))return W.response;await W.waitFor}}async underThreadLock(J,$,Q,Z){let W=CJ.get(J)??Promise.resolve(),K,X=new Promise((V)=>{K=V}),Y=W.then(()=>X);CJ.set(J,Y),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:OQ(J)};let H=this.liveRuns.get(V.runId),D=H?r$.get(H)??H.result():null;if(D)return{waitFor:D.then(WJ,WJ)}}if(V&&this.liveRuns.isRunning(V.runId)&&!this.liveRuns.mayAccess(V.runId,$))return{response:_J()};let G=V?this.liveRuns.get(V.runId):null;if(G)G.stop({reason:"superseded by a later turn on this thread"}),await r$.get(G);return{response:await Q()}}finally{if(K(),CJ.get(J)===Y)CJ.delete(J)}}async attach(J=new q){let $=await ZJ(J,OJ);if($.error)return n($);let Q=$.body,Z=typeof Q.threadId==="string"?Q.threadId:LQ(J,"threadId");if(!Z)return A(400,{code:"invalid_request",message:"attach needs a threadId: it is the handle that survives a refresh."});if(await this.authorizeRequest(J,{route:"attach",threadId:Z}),!await this.threadInScope(J,Z))return AQ(Z);let W=await this.liveRuns.find({threadId:Z});if(W&&!this.liveRuns.mayAccess(W.runId,await this.runOwner(J)))return _J();if(!W)return AQ(Z);let K=typeof Q.runId==="string"?Q.runId:void 0,X=K&&K!==W.runId?void 0:$6(J,Q);try{return IQ(this.liveRuns.replay(W.runId,X))}catch(Y){if(Y instanceof $J)return A(410,{code:Y.code,message:Y.message,oldestSeq:Y.oldest});if(Y instanceof BJ)return A(404,{code:Y.code,message:Y.message});throw Y}}async watch(J=new q){let $=await ZJ(J,OJ);if($.error)return n($);let Q=$.body,Z=typeof Q.threadId==="string"?Q.threadId:LQ(J,"threadId");if(!Z)return A(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 A(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=m0(K),Y=await K.find({threadId:Z}),V=null,G=null,H=0,D=()=>{if(G?.stop(),!V)return;let F=X.get(Z);if(F?.delete(V),F&&F.size===0)X.delete(Z);V=null},z=new ReadableStream({start(F){G=xQ(F);let B=(N)=>{if(!K.mayAccess(N,W))return;try{F.enqueue(new TextEncoder().encode(TQ({seq:++H,event:{type:"run-start",runId:N,threadId:Z}}))),G?.touch()}catch{D()}};V=B;let P=X.get(Z);if(!P)P=new Set,X.set(Z,P);if(P.add(B),Y&&K.isRunning(Y.runId))B(Y.runId)},cancel(){D()}});return J.rawRequest?.signal?.addEventListener("abort",D,{once:!0}),new Response(z,{status:200,headers:wQ()})}async stop(J=new q){let $=await ZJ(J,OJ);if($.error)return n($);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=iJ.get(Q.clientRunId);if(X){if(X.owner!==null&&X.owner!==Z)return _J();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 _J();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 aJ(this.attachments,this.attachmentStorage,Z)}async voiceStart(J=new q){let $=this.voice;if(!$)return J8();let Q=await ZJ(J,OJ);if(Q.error)return n(Q);let{sdp:Z,threadId:W,pushToTalk:K}=Q.body;if(typeof Z!=="string"||!Z.trimStart().startsWith("v="))return A(400,{code:"invalid_request",message:"`sdp` must be the browser's SDP offer."});let X=nJ(Q.body,X6),Y=typeof W==="string"&&W!==""?W:void 0;await this.authorizeRequest(J,{route:"stream",threadId:Y,body:X});let V=J.ctx?.()?.user??null,G=await $.start({req:J,body:X,threadId:Y,user:V,pushToTalk:K===!0}),H=Date.now(),D,z=async(L)=>{if(L!==void 0)console.error("[gemi/ai] a voice session could not start.",L);if(D)await $.realtime.hangup(D).catch((C)=>{console.error("[gemi/ai] a voice call that failed to start could not be hung up.",C)});try{await G.onEnd?.({sessionId:"",...D?{callId:D}:{},threadId:G.threadId??Y??"",reason:"start_failed",startedAt:H,endedAt:Date.now(),durationMs:0,seconds:0,usage:E(),transcription:{usage:E(),seconds:0},transcript:[],requests:[],toolCalls:[],errors:[]})}catch(C){console.error("[gemi/ai] a voice session's onEnd threw.",C)}},F=G.threadId??Y;if(!F)return await z(void 0),A(400,{code:"invalid_request",message:"A voice session needs a thread: send `threadId`, or answer one from `voice.start`."});try{if(F!==Y)await this.authorizeRequest(J,{route:"stream",threadId:F,body:X})}catch(L){throw await z(void 0),L}let B=crypto.randomUUID(),P=G.tools??[];try{if(G.mcp)P=[...P,...await h$(G.mcp,{user:V,sessionId:B})]}catch(L){return await z(L),A(500,{code:"voice_unavailable",message:"Voice isn't available right now."})}let N={...G.session,tools:[...PJ($.delegate),...G.session?.tools??[],...P.map((L)=>L.tool)],...K===!0?{turnDetection:null}:{}},U;try{U=await $.realtime.createCall({sdp:Z,session:N,safetyIdentifier:G.safetyIdentifier})}catch(L){await z(L);let C=L instanceof v&&L.code==="rate_limited";return A(C?429:502,{code:"voice_unavailable",message:"Voice isn't available right now."})}D=U.callId;try{await this.voiceStore.create({id:B,callId:U.callId,threadId:F,owner:await this.runOwner(J),body:X,startedAt:H});let{threadId:L,session:C,safetyIdentifier:w,mcp:R,tools:M,...O}=G;return{sessionId:i.start({...O,tools:P,controller:this.constructor,threadId:F,user:V,body:X,call:{realtime:$.realtime,callId:U.callId},sessionId:B,store:this.voiceStore,liveRuns:this.liveRuns,delegate:$.delegate,session:N}).sessionId,sdp:U.sdpAnswer,threadId:F,delegate:$.delegate?.name??UJ,endsAt:H+(G.limits?.maxDurationMs??900000)}}catch(L){return await z(L),A(500,{code:"voice_unavailable",message:"Voice isn't available right now."})}}async voiceUpdate(J=new q){if(!this.voice)return J8();let $=await this.voiceSession(J);if($ instanceof Response)return $;let Q=await ZJ(J,OJ);if(Q.error)return n(Q);let Z=nJ(Q.body,[]);if(await this.authorizeRequest(J,{route:"stream",threadId:$.threadId,body:Z}),$.endedAt!==void 0)return A(409,{code:"voice_ended",message:"This voice session has ended."});return await this.voiceStore.update($.id,{body:Z}),i.get($.id)?.setBody(Z),{updated:!0}}async voiceEnd(J=new q){let $=this.voice;if(!$)return J8();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=i.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 A(404,{code:"voice_not_found",message:"No such voice session."});if(Q.owner!==null&&Q.owner!==await this.runOwner(J))return _J();return Q}async upload(J=new q){let $=await J.rawRequest.formData(),Q=$.get("file");if(!(Q instanceof Blob))throw Error("upload expects a multipart body with a `file` field.");let Z=Q instanceof File&&Q.name?Q.name:"upload",W=Q.type||"application/octet-stream",K=n0($.get("body")),X=$.get("threadId");await this.authorizeRequest(J,{route:"upload",threadId:typeof X==="string"&&X.length>0?X:void 0,body:K});let Y=s0(await this.attachmentLimits(J),Q,Z,W);if(Y)throw new W8(Y.code,Y.message);await this.scopeStore(J,K);let V=typeof X==="string"&&X.length>0&&await this.store.loadThread(X)!==null?X:void 0,G=await this.runOwner(J),H=(R)=>this.fileOwners.record(R,{owner:G,name:Z,mimeType:W,size:Q.size,createdAt:new Date().toISOString()}),D={body:K,threadId:V},z=await this.checkUpload({name:Z,size:Q.size,mimeType:W},J,D);if(z)throw new W8(z.code||"upload_refused",z.message);let F=await this.attachmentDestination(Q,J,D),B=G6(F,$.get("destination")),P=await this.attachmentScope(J,V,{body:K}),N=B!=="provider"&&!P;if(N){if(B==="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()`.');Y6()}if(B==="provider"||!P){let R=await PQ(this.agent.provider,Q);await H(R);let M={fileId:R,name:Z,mimeType:W,size:Q.size,destination:"provider"};if(N)M.downgraded="no_scope";return M}let U=hQ(),L=await this.attachmentStorage.put({name:gQ(U,Z),body:Q,contentType:W}),C=B==="both"?await PQ(this.agent.provider,Q):void 0;if(C)await H(C);let w={id:U,scopeKey:P.key,fileId:C,objectName:L,name:Z,mimeType:W,size:Q.size,createdAt:new Date().toISOString(),destination:B};return await this.attachments.put(P,w),{fileId:C,attachmentId:U,name:Z,mimeType:W,size:Q.size,destination:B}}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 W6()}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 Y8(J,$)}onError(J,$){return this.hooks?.onError?.(J,$)}onStreamComplete(J,$){return this.hooks?.onStreamComplete?.(J,$)}reportHookFailure(J){let $=this.hooks?.reportHookFailure;if($)try{return $(J)}catch(Q){console.error("[gemi/ai] reportHookFailure hook failed",Q)}console.error("[gemi/ai] agent controller hook failed",J)}async dispatchEvent(J,$){switch(J.type){case"tool-call":if(!J.part.partial&&!J.resent)await this.onToolCall({toolCallId:J.part.toolCallId,name:String(J.part.name),input:J.part.input},$);return;case"tool-result":{let Q=J.part;await this.onToolResult(Q,$,{toolCallId:Q.toolCallId,name:String(Q.name),input:pQ(Q)});return}case"awaiting-input":await this.onAwaitingInput(J.pending,$);return;case"error":await this.onError(fQ(J.error),$);return;default:return}}async readThread(J,$={}){let Z=await($.scope===null||$.scope===void 0?this.store:SQ(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 WQ($,Z),K=W.messages,X=[],Y=new Map(W.settled.map((V)=>[V.id,V]));if(D6(K)||Q)try{let V=await YQ(K,{threadId:J,store:g.store,isRunLive:Z,outputSchemaFor:(G)=>this.toolNamed(G)?.outputSchema,modelOutputFor:(G,H)=>mQ(this.toolNamed(G),H,(D)=>this.reportHookFailure(D)),scan:this.jobsBlockMax()});K=V.messages,X=V.jobs;for(let G of V.settled)Y.set(G.id,G);if(Q&&V.orphans.length>0){await VQ(g.store,V.orphans,(H)=>this.reportHookFailure(H));let G=new Set(V.orphans.map((H)=>H.id));X=X.map((H)=>G.has(H.id)?{...H,orphaned:!0}:H)}}catch(V){this.reportHookFailure(V)}if(Q&&Y.size>0)try{await this.store.appendMessages(J,[...Y.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??EJ}jobsBlock(J){return O8(J,this.jobsBlockMax())}toolNamed(J){let $=(Q)=>{for(let Z of Q){let W=Z;if(Array.isArray(W.tools)){let K=$(W.tools);if(K)return K}else if(W.name===J)return W}return};return $(this.agent.tools??[])}follow(J,$){(async()=>{try{for await(let Q of J.frames())$.frame(Q)}catch(Q){this.reportHookFailure(Q)}})()}persistRun(J,$,Q,Z=null,W={id:null,notified:Promise.resolve()}){let K=Promise.resolve(),X=(async()=>{let V;try{V=await J.result()}catch(H){Z?.close(),await Z?.settled(),K=W.notified.then(()=>this.safely(()=>this.onError({code:"unknown",message:H instanceof Error?H.message:String(H),retryable:!1},$)));return}let G=V.messages;if(Z?.close(G),await Z?.settled(),$.threadId&&G.length>0)try{await this.store.appendMessages($.threadId,G)}catch(H){this.reportHookFailure(H)}K=this.notifyRun(V,G,$,W)})(),Y=X.then(()=>H6(Promise.all([K,Q]).then(()=>{}),this.hookHoldMs));return{stored:X,hooks:Y}}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 Q8=["turn","clientRunId","threadId","messages","regenerate"],i0=["text","files","toolResults"];function nJ(J,$=nQ(J)?Q8:[...Q8,...i0]){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 n0(J){if(J===null)return{};let $;if(typeof J==="string")try{$=JSON.parse(J)}catch{throw new Z8("The upload's `body` field is not valid JSON.")}if($===null||typeof $!=="object"||Array.isArray($))throw new Z8("The upload's `body` field must be a JSON object.");return nJ($,Q8)}class Z8 extends oJ{constructor(J){super(J);this.name="InvalidUploadError",this.payload={api:{status:400,data:{error:{code:"invalid_request",message:J}}},view:{}}}}async function PQ(J,$){try{return await J.upload($)}catch(Q){if(Q instanceof b&&o0.has(Q.status))throw new iQ(x(Q).message);throw Q}}var o0=new Set([400,413,415,422]);class W8 extends oJ{constructor(J,$){super($);this.name="LimitedUploadError",this.payload={api:{status:422,data:{error:{code:J,message:$}}},view:{}}}}function s0(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 ${UQ($.size)}; the limit is ${UQ(W)}.`};if(K&&K.length>0&&!K.some((X)=>a0(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 a0(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 UQ(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 iQ extends oJ{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 ZJ(J,$){let Q=J?.rawRequest;if(!Q||Q.method==="GET"||Q.method==="HEAD"||!Q.body)return{body:{}};if(!t0(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 NQ($);let W;try{let X=await r0(Q,$);if(X===null)return NQ($);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 t0(J){return jQ(J)==="application/json"}async function r0(J,$){if(!Number.isFinite($)||!J.body)return await J.text();let Q=J.body.getReader(),Z=[],W=0;for(;;){let{done:Y,value:V}=await Q.read();if(Y)break;if(W+=V.byteLength,W>$)return await Q.cancel().catch(WJ),null;Z.push(V)}let K=new Uint8Array(W),X=0;for(let Y of Z)K.set(Y,X),X+=Y.byteLength;return new TextDecoder().decode(K)}function NQ(J){return{body:{},status:413,code:"body_too_large",error:`The request body is larger than this agent accepts (${J} bytes).`}}function K8(J,$,Q){return A(J,{...sJ(EQ(J),Q,J),code:$})}function n(J){if(J.status===413)return K8(413,J.code??"body_too_large",J.error??"");return A(J.status??400,{code:J.code??"invalid_request",message:J.error})}function nQ(J){return Boolean(J.turn)&&typeof J.turn==="object"}function e0(J){let $=nQ(J)?J.turn:J,Q={};if(typeof $.text==="string")Q.text=$.text;if(Array.isArray($.files)){let Z=J6($.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>BQ)return{error:`turn.localId is longer than ${BQ} characters.`};Q.localId=Z}return{turn:Q}}var BQ=200;function J6(J){let $=[];for(let[Q,Z]of J.entries()){let W=`turn.files[${Q}]`;if(!Z||typeof Z!=="object"||Array.isArray(Z))return`${W} must be an object.`;let K={};for(let H of["fileId","attachmentId","name","mimeType"]){let D=Z[H];if(D===void 0||D===null||D==="")continue;if(typeof D!=="string")return`${W}.${H} must be a string.`;K[H]=D}let{fileId:X,attachmentId:Y,name:V,mimeType:G}=K;if(X?.startsWith(d))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(Y!==void 0&&!Y.startsWith(d))return`${W}.attachmentId is not a gemi attachment id: it must start with "${d}".`;if(!X&&!Y)return`${W} has neither a \`fileId\` nor an \`attachmentId\`. Send the ids the upload response answered.`;$.push({...X?{fileId:X}:{},...Y?{attachmentId:Y}:{},...V!==void 0?{name:V}:{},...G!==void 0?{mimeType:G}:{}})}return $}function $6(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 LQ(J,$){let Q=J?.search?.get($);return typeof Q==="string"?Q:void 0}function Q6(J){let $=V8(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 CQ(){return A(409,{code:"stopped",message:"The turn was stopped before it started."})}function Z6(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"||!y0.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 OQ(J){return A(409,{code:lQ,message:`Thread ${J} has a run going, and this turn was not to interrupt it.`})}function _J(){return A(403,sJ("permission","This run belongs to someone else.",403))}function W6(){return A(403,sJ("permission","A file in this turn was uploaded by someone else.",403))}function K6(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 X6=["sdp","threadId","pushToTalk"];function J8(){return A(404,{code:"voice_not_enabled",message:"This agent has no voice: set `voice` on its controller."})}function A(J,$){return new Response(JSON.stringify({error:$}),{status:J,headers:{"Content-Type":"application/json"}})}function G6(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 _Q=!1;function Y6(){if(_Q)return;_Q=!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 V6=2147483647;function H6(J,$){let Q=J.then(()=>{},()=>{});if(!($<=V6))return Q;let Z,W=new Promise((K)=>{Z=setTimeout(K,$)});return Promise.race([Q,W]).finally(()=>clearTimeout(Z))}var MQ=!1;function z6(J){if(MQ||Bun.env.NODE_ENV!=="production")return;if(!(J instanceof X8))return;MQ=!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 D6(J){return J.some(($)=>$.content.some((Q)=>Q.type==="tool-result"&&Q.status==="running"))}function SQ(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 AQ(J){return A(404,{code:"no_live_run",message:`No run in progress for thread ${J} in this process.`})}export{M6 as windowMessages,PJ as voiceTools,B6 as turnStarts,vJ as toRealtimeUsage,BZ as toAgentTools,U6 as supportsStrict,L6 as splitTurns,T6 as settleSummaries,P6 as s,Y8 as redactError,h6 as parsePartialJson,C6 as messageSize,VJ as measureUsage,h$ as mcpVoiceTools,p$ as liveRuns,NJ as keepSummary,b9 as isCallNotFound,V8 as injectedMessageIds,F$ as generate,z0 as evalChain,d0 as defineAgentHooks,u$ as defaultVoiceStore,w6 as defaultUsageLimitStore,k6 as defaultSummaryStore,G8 as defaultNonceStore,l$ as defaultFileOwners,tJ as defaultAttachmentStore,s$ as defaultAgentStore,pJ as VoiceHangup,i as VoiceBridge,N6 as Usage,U$ as ToolNamespace,m as ToolError,q6 as Skill,aJ as ScopedAttachments,b6 as SKILLS_NAMESPACE,o$ as RedisReceiptStore,qQ as RedisNonceStore,hJ as RealtimeSideband,v as RealtimeRequestError,DJ as RealtimeClient,B8 as Prompt,bQ as PrismaNonceStore,I6 as PendingEscalation,b$ as OpenAIProvider,O$ as OpenAIImageProvider,g$ as MemoryVoiceSessionStore,x6 as MemoryUsageLimitStore,j6 as MemorySummaryStore,n$ as MemoryReceiptStore,X8 as MemoryNonceStore,lJ as MemoryLiveRuns,dJ as MemoryFileOwners,cJ as MemoryCircuitStore,uQ as MemoryAttachmentStore,LJ as MemoryAgentStore,S8 as MemoryAgentJobStore,u8 as MEMORY_NAMESPACE,BJ as LiveRunNotFoundError,R8 as JobsRequireThreadError,A8 as JobHandle,F6 as JSONSchemaError,vQ as InvalidAttachmentScopeError,b8 as InMemoryAgentMemoryStore,bJ as ImageRequestError,fJ as ImageProvider,N$ as ImageModel,$J as FrameCursorEvictedError,FJ as FallbackProvider,h8 as FakeAgentMemoryStore,wJ as Eval,c$ as DatabaseAgentStore,G$ as DatabaseAgentMemoryStore,K$ as DatabaseAgentJobStore,I9 as DEFAULT_TRANSCRIPTION_MODEL,q8 as DEFAULT_MEMORY_MAX_TOKENS,g8 as DEFAULT_MEMORY_LIMITS,S6 as DEFAULT_MAX_SUMMARY_TOKENS,f6 as DEFAULT_MAX_RUN_DURATION_MS,E8 as DEFAULT_JOB_DEADLINE_MS,EJ as DEFAULT_JOBS_CONTEXT_MAX,UJ as DEFAULT_DELEGATE_NAME,O6 as DEFAULT_CONTEXT_WINDOW_STEP,_6 as DEFAULT_CONTEXT_WINDOW_NOTE,A6 as DEFAULT_COMPACT_TRIGGER_TOKENS,R6 as DEFAULT_COMPACT_INSTRUCTIONS,E6 as COMPACT_SUMMARY_HEADER,f$ as AzureOpenAIProvider,_$ as AzureOpenAIImageProvider,yQ as AttachmentNotFoundError,rJ as AgentTurnError,IJ as AgentTool,y6 as AgentRunError,JJ as AgentProvider,f8 as AgentMemoryRefusedError,y8 as AgentMemoryConflictError,v8 as AgentMemories,g as AgentJobs,Q$ as AgentJobDeadlineSweep,j8 as AgentJob,H8 as AgentController,v6 as Agent};
266
266
 
267
- //# debugId=E2DAD0271D1BAC7064756E2164756E21
267
+ //# debugId=75509A8233BCAFFF64756E2164756E21