eve
Version:
Filesystem-first framework for durable backend AI agents that run anywhere.
1 lines • 837 B
JavaScript
import{createEventDeduper}from"#protocol/event-dedupe.js";import{isCurrentTurnBoundaryEvent}from"#protocol/message.js";var SteeringStream=class{session;streams;closed=!1;controller=new AbortController;constructor(e,t){this.session=t,this.streams=[Promise.resolve(e)]}async send(e){if(this.closed)throw Error(`The active stream ended before steering was sent.`);let t=this.session.send(e,{turnPolicy:`steer`,signal:this.controller.signal});this.streams.push(t.then(e=>e,()=>void 0)),await t}abort(){this.closed=!0,this.controller.abort()}async*[Symbol.asyncIterator](){let e=createEventDeduper(),t;try{for(;this.streams.length>0;){let n=await this.streams.shift();if(n!==void 0){for await(let r of n)if(e.admit(r)){if(isCurrentTurnBoundaryEvent(r)){t=r;break}yield r}}}t!==void 0&&(yield t)}finally{this.abort()}}};export{SteeringStream};