// @bun
var W=Object.defineProperty;var X=(f)=>f;function Y(f,j){this[f]=X.bind(null,j)}var O=(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 R=import.meta.require;import{readUIMessageStream as _,tool as $}from"ai";import{z as J}from"zod";function v(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 M(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=v(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 $(Q)}var C=()=>{};C();export{M as createSubagentTool};
