import{c as T,bQ as I,r as g,bR as j,j as n,Z as L,g as S,aq as $,bS as C,a4 as k,ae as D,bT as M}from"./index-CfKY7XrC.js";import{L as N,A as w}from"./agent-thread-DqdDtu0Y.js";function y({owner:a,agent:h,threadId:c,surface:r="agent",footer:m,className:f,initialDraft:x}){const i=T(),t=h.agentId,{data:s=[]}=I(t,{orgSlug:a}),[p]=g.useState(()=>j()),[o,A]=g.useState(null),d=g.useMemo(()=>!o||s.some(l=>l.id===o.id)?s:[o,...s],[s,o]),e=c??p,b=!c||!d.some(l=>l.id===c),u=g.useCallback(()=>{if(!d.some(l=>l.id===e)){if(A({id:e,title:`Conversation ${d.length+1}`,createdAt:Date.now(),updatedAt:Date.now()}),r==="home"){i({to:"/$owner/c/$threadId",params:{owner:a,threadId:e},replace:!0});return}i({to:"/$owner/agents/$agentId/chat/c/$threadId",params:{owner:a,agentId:t,threadId:e},replace:!0})}},[d,e,i,a,t,r]),v=g.useCallback(()=>{b&&u()},[b,u]);return n.jsx("div",{className:L("flex min-h-0 flex-1 flex-col",f),children:n.jsx("div",{className:"flex min-h-0 flex-1 flex-col",children:n.jsx(N,{agentId:t,workspaceSlug:a,thread:e,onFirstUserMessage:v,initialDraft:x,children:n.jsx(w,{footer:m})},`${t}:${e}`)})})}function R({owner:a,agentId:h,threadId:c,surface:r="agent",initialDraft:m}){const{isAuthenticated:f}=S(),{isMember:x,isLoading:i}=$(),t=f&&x,{agents:s,builderAgent:p,systemAgentId:o,isLoading:A}=C(t),d=r==="home"?o:h??null,e=r==="home"?p:s.find(u=>u.agentId===d)??null;return t&&A||i?n.jsx(k,{label:"chat",variant:"panel"}):e?n.jsx(y,{owner:a,agent:e,threadId:c,surface:r,initialDraft:m,className:"min-h-0 flex-1 overflow-hidden"}):n.jsx(D,{icon:M,title:"Agent not found",description:"This agent may have been removed."})}export{R as A};
