function w(t){return t&&typeof t=="object"&&"data"in t&&t.data&&typeof t.data=="object"?t.data:t}function g(t){return t&&typeof t=="object"&&t.data&&typeof t.data=="object"&&"id"in t.data?t.data:t}async function h({api:t,sessionId:u,projectDir:f,item:b,content:a}){const y=await t.request("/teams",{method:"POST",body:{name:a.name||b.name,description:a.description}}),o=g(y),n=(o==null?void 0:o.id)||null,d=Array.isArray(a.members)?a.members:[];let l=0,s=0;for(const e of d){let r;try{r=await t.orchestratorRequest(u,"create_agent",{name:e.name,model:e.model||"claude-sonnet-4-5",systemPrompt:e.systemPrompt||"",capabilities:e.capabilities||[],mode:"chat"},f)}catch(m){console.warn(`[marketplaceInstall] create_agent failed for "${e.name}":`,m);continue}const c=w(r),i=c==null?void 0:c.id;if(!i){console.warn(`[marketplaceInstall] agent "${e.name}" created but response carried no id`,r);continue}if(l+=1,!!n)try{await t.addAgentToTeam(n,i),s+=1}catch(m){console.warn(`[marketplaceInstall] failed to link agent ${i} to team ${n}:`,m)}}return{teamId:n,createdCount:l,linkedCount:s,totalRequested:d.length}}export{h as installTeam,w as unwrapOrchestratorResponse,g as unwrapTeamResponse};
