import{createRequire as _}from"node:module";var W=Object.defineProperty;var X=(f)=>f;function Y(f,j){this[f]=X.bind(null,j)}var R=(f,j)=>{for(var q in j)W(f,q,{get:j[q],enumerable:!0,configurable:!0,set:Y.bind(j,q)})};var Z=(f,j)=>()=>(f&&(j=f(f=0)),j);var h=_(import.meta.url);import{readUIMessageStream as $,tool as v}from"ai";import{z as J}from"zod";function C(f){if(f instanceof ReadableStream)return f;return new ReadableStream({async start(j){try{for await(let q of f)j.enqueue(q)}finally{j.close()}}})}function z(f){let{subagent:j,description:q="Research a topic or question in depth.",taskParam:F="task",toModelSummary:K=!0,passConversationHistory:L=!1}=f,N=J.object({[F]:J.string().describe("The research task to complete")}),Q={description:q,inputSchema:N,execute:async function*(w,A){let D=String(w[F]??w.task??""),{abortSignal:B,messages:E}=A??{};if(L&&E&&E.length>0&&typeof j.generate==="function"){yield{parts:[{type:"text",text:(await j.generate({messages:[...E,{role:"user",content:D}],abortSignal:B})).text}]};return}let T=(await j.stream({prompt:D,abortSignal:B})).toUIMessageStream(),V=C(T);for await(let G of $({stream:V}))yield G},...K&&{toModelOutput:({output:w})=>{let A=w?.parts;if(!Array.isArray(A))return{type:"text",value:"Task completed."};return{type:"text",value:[...A].reverse().find((B)=>B?.type==="text")?.text??"Task completed."}}}};return v(Q)}var H=()=>{};H();export{z as createSubagentTool};
