function x(e){return e.status==="running"}function M(e){return e.pending.length>0}function O(e,t){return e/1e6*t}var b=new Set(["http:","https:"]);function D(e){try{let t=new URL(e);if(!b.has(t.protocol))throw new Error(`[Directive] Invalid baseURL protocol "${t.protocol}" \u2013 only http: and https: are allowed`)}catch(t){throw t instanceof Error&&t.message.startsWith("[Directive]")?t:new Error(`[Directive] Invalid baseURL "${e}" \u2013 must be a valid URL (e.g. "https://api.openai.com/v1")`)}}function L(e){let{fetch:t=globalThis.fetch,buildRequest:T,parseResponse:f,parseOutput:m,hooks:u}=e,k=m??(s=>{try{return JSON.parse(s)}catch{return s}});return async(s,o,p)=>{let c=Date.now();u?.onBeforeCall?.({agent:s,input:o,timestamp:c});let l=[{role:"user",content:o}];try{let{url:r,init:i}=T(s,o,l),d=p?.signal?{...i,signal:p.signal}:i,a=await t(r,d);if(!a.ok){let R=await a.text().catch(()=>"");throw new Error(`[Directive] AgentRunner request failed: ${a.status} ${a.statusText}${R?` \u2013 ${R.slice(0,300)}`:""}`)}let n=await f(a,l),g={inputTokens:n.inputTokens??0,outputTokens:n.outputTokens??0},h={role:"assistant",content:n.text},w=[...l,h];p?.onMessage?.(h);let A=Date.now()-c;return u?.onAfterCall?.({agent:s,input:o,output:n.text,totalTokens:n.totalTokens,tokenUsage:g,durationMs:A,timestamp:Date.now()}),{output:k(n.text),messages:w,toolCalls:[],totalTokens:n.totalTokens,tokenUsage:g}}catch(r){let i=Date.now()-c;throw r instanceof Error&&u?.onError?.({agent:s,input:o,error:r,durationMs:i,timestamp:Date.now()}),r}}}
export{x as a,M as b,O as c,D as d,L as e};//# sourceMappingURL=chunk-W6WZBQER.js.map
//# sourceMappingURL=chunk-W6WZBQER.js.map