PageSourceSearch

https://rationalgo.ai/_next/static/chunks/18411-a752c373bbb374d0.js

js rationalgo.ai collected 2026-10-05 12:28:33 UTC 112,460 bytes, 1 lines download raw bytes

1"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[18411],{18411:(e,t,s)=>{s.d(t,{V:()=>eG});var r=s(78542),n=s(18558),a=s(39164),l=s(27471),i=s(28109),o=s(58168),c=s(44e3),d=s(43307),u=s(59652),m=s(45778),x=s(72842),h=s(26835),g=s(39303),p=s(41936),f=s(33591),v=s(59978),j=s(93606),b=s(81066),y=s(64951),N=s(19042),w=s(51591),k=s(92888),_=s(36217),C=s(7424),S=s(70885),A=s(35726),I=s(64772),E=s(29798),F=s(8700),z=s(73482),M=s(87107),R=s(25251),D=s(76524);let L=async e=>{try{let t=new FormData;t.append("audio_file",e);let s=await D.H.upload("/transcription",t,{showErrors:!0});if(s.error)throw Error("Error transcribing audio: ".concat(s.error.message," (").concat(s.error.status,")"));return s.data}catch(e){throw console.error("Failed to transcribe audio:",e),(0,R.hS)(e,{operation:"transcribe audio",resource:"speech-to-text"}),e}},T=(0,n.memo)(function(e){let{onTranscription:t,disabled:s=!1}=e,[a,l]=(0,n.useState)("idle"),i=(0,n.useRef)(null),o=(0,n.useRef)([]),c=(0,n.useRef)(null),d=(0,n.useRef)(null),u=(0,n.useRef)(null),m=(0,M.n)({mutationFn:L,onError:e=>{(0,R.hS)(e,{operation:"transcribe audio",resource:"speech-to-text"})}});(0,n.useEffect)(()=>("recording"===a?(d.current=Date.now(),u.current=setTimeout(()=>{p()},9e5)):(d.current=null,u.current&&(clearTimeout(u.current),u.current=null)),()=>{u.current&&clearTimeout(u.current)}),[a]);let g=async()=>{try{let e=await navigator.mediaDevices.getUserMedia({audio:!0});c.current=e;let s=new MediaRecorder(e,{mimeType:"audio/webm"});i.current=s,o.current=[],s.ondataavailable=e=>{e.data.size>0&&o.current.push(e.data)},s.onstop=async()=>{if(0===o.current.length){f(),l("idle");return}l("processing");let e=new Blob(o.current,{type:"audio/webm"}),s=new File([e],"recording.webm",{type:"audio/webm"});m.mutate(s,{onSuccess:e=>{t(e.text),l("idle")},onError:e=>{console.error("Transcription failed:",e),l("idle")}}),f()},s.start(),l("recording")}catch(e){console.error("Error starting recording:",e),l("idle")}},p=()=>{i.current&&"recording"===a&&i.current.stop()},f=()=>{c.current&&(c.current.getTracks().forEach(e=>e.stop()),c.current=null)};return(0,r.jsxs)(h.m_,{children:[(0,r.jsx)(h.k$,{asChild:!0,children:(0,r.jsx)(x.$,{type:"button",variant:"ghost",size:"sm",onClick:()=>{"idle"===a?g():"recording"===a&&p()},onContextMenu:e=>{e.preventDefault(),"recording"===a&&i.current&&"recording"===a&&(o.current=[],i.current.stop(),f(),l("idle"))},disabled:s||"processing"===a,className:"h-9 w-9 p-0 bg-background/60 border-[1.5px] border-border/50 rounded-lg text-muted-foreground hover:text-foreground hover:border-border hover:bg-muted/80 flex items-center justify-center transition-all duration-200 ".concat("recording"===a?"text-red-500 hover:bg-red-50 hover:text-red-600":""),children:(()=>{switch(a){case"recording":return(0,r.jsx)(F.default,{className:"h-3.5 w-3.5"});case"processing":return(0,r.jsx)(E.RgoLoader,{size:"small"});default:return(0,r.jsx)(z.default,{className:"h-3.5 w-3.5"})}})()})}),(0,r.jsx)(h.ZI,{side:"top",className:"text-xs",children:(0,r.jsx)("p",{children:"recording"===a?"Click to stop recording":"processing"===a?"Processing...":"Record voice message"})})]})});var P=s(58061),$=s(70665),U=s(72409),O=s(31294),Z=s(95228),q=s(14333),B=s(46204),W=s(65986),V=s(1855);let H=["Ultra","Starter","Pro"],K=e=>{let{subscriptionData:t,onClose:s,onOpenUpgrade:a,hasMultiple:l=!1,showIndicators:i=!1,currentIndex:o=0,totalCount:c=1,onIndicatorClick:d}=e,[u,m]=(0,n.useState)(0);return(0,n.useEffect)(()=>{let e=setInterval(()=>{m(e=>(e+1)%3)},1200);return()=>clearInterval(e)},[]),(0,r.jsxs)("div",{className:"flex items-center gap-3",children:[(0,r.jsx)("div",{className:"flex-shrink-0 w-10 h-10 flex items-center justify-center relative ml-2",children:(0,r.jsx)(W.N,{mode:"wait",children:(0,r.jsx)(B.P.div,{initial:{opacity:0,y:8},animate:{opacity:1,y:0},exit:{opacity:0,y:-8},transition:{duration:.2},className:"absolute",children:(0,r.jsx)(V.y,{planName:H[u],size:"xxs"})},H[u])})}),(0,r.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,r.jsx)(B.P.div,{className:"flex items-center gap-2 mb-0.5",children:(0,r.jsx)("h4",{className:"text-sm font-medium text-foreground truncate",children:"Unlock the full RationalGo experience"})}),(0,r.jsx)("span",{className:"text-xs text-muted-foreground truncate block",children:"Advanced AI, more sites, leads, research & AI images every day"})]}),i&&c>1&&(0,r.jsx)("button",{"data-indicator-click":!0,onClick:e=>{e.stopPropagation(),null==d||d(2===c?+(0===o):(o+1)%c)},className:"flex items-center gap-1.5 mr-3 px-2 py-1.5 rounded-lg hover:bg-muted/30 transition-colors",children:Array.from({length:c}).map((e,t)=>(0,r.jsx)("div",{className:(0,U.cn)("transition-all duration-300 ease-out rounded-full",t===o?"w-6 h-2 bg-foreground":"w-3 h-2 bg-muted-foreground
1/40")},t))}),(0,r.jsx)(x.$,{variant:"ghost",size:"icon",className:"h-8 w-8 flex-shrink-0 hover:bg-muted/50",onClick:e=>{e.stopPropagation(),null==s||s()},children:(0,r.jsx)(_.default,{className:"h-4 w-4 text-muted-foreground hover:text-foreground transition-colors"})})]})},G=e=>{var t,s,a;let{subscriptionData:l,onOpenUpgrade:i,isVisible:o=!1}=e,[c,d]=n.useState(0),[u,m]=n.useState(!1),x=l&&("free"===l.tier_key||(null==(t=l.tier)?void 0:t.name)==="free"||"free"===l.plan_name),h=(null!=(a=null==l||null==(s=l.credits)?void 0:s.balance)?a:0)<=0,g=[];x&&h&&l&&!u&&i&&g.push("upgrade");let p=g.length,f=p>1;n.useEffect(()=>{c>=p&&p>0&&d(0)},[p,c]);let v=o||x&&h&&l&&!u&&i&&p>0;if(n.useEffect(()=>{if(!f||!v)return;let e=setInterval(()=>{d(e=>(e+1)%p)},2e4);return()=>clearInterval(e)},[f,v,p,c]),!v||0===p)return null;let j=g[c];return(0,r.jsx)("div",{children:v&&("upgrade"===j&&x&&h&&l&&i?(0,r.jsx)(B.P.div,{layoutId:"chat-snack-float",layout:!0,transition:{layout:{type:"spring",stiffness:300,damping:30}},className:"-mb-4 w-full",style:{pointerEvents:"auto"},children:(0,r.jsx)(B.P.div,{layoutId:"chat-snack-content",className:(0,U.cn)("bg-card border border-border rounded-2xl p-2 w-full transition-all duration-200","cursor-pointer hover:shadow-md"),whileHover:{scale:1.02},whileTap:{scale:.98},onClick:e=>{let t=e.target,s=t.closest("[data-indicator-click]"),r=t.closest("[data-close-click]");s||r||!i||i()},children:(0,r.jsx)(K,{subscriptionData:l,onClose:()=>{m(!0)},hasMultiple:f,showIndicators:f,currentIndex:c,totalCount:p,onIndicatorClick:e=>d(e),onOpenUpgrade:i})})}):null)})};var J=s(30230),Q=s(84499),X=s(78145),Y=s(17215),ee=s(51660),et=s(37693),es=s(14815),er=s(15294),en=s(23258),ea=s(41894),el=s(25796),ei=s(61491),eo=s(26138),ec=s(903),ed=s(80193);let eu=e=>{let{showAgentSelector:t=!0,selectedAgentId:s,onAgentChange:n,onToolsSelected:a,onClose:l,initialSelectedApp:i,isBlocked:o,onBlockedClick:c}=e;return(0,r.jsx)(ed.h,{showAgentSelector:t,selectedAgentId:s,onAgentChange:n,onToolsSelected:a,onClose:l,initialSelectedApp:i,isBlocked:o,onBlockedClick:c})};var em=s(47358),ex=s(72248),eh=s(57570),eg=s(15770),ep=s(32606),ef=s(33835),ev=s(51145),ej=s(38509),eb=s(72315),ey=s(84917),eN=s(75646),ew=s(236),ek=s(42061),e_=s(70686),eC=s(26643),eS=s(67191),eA=s(63960);let eI=(0,n.memo)(function(e){let{isLoggedIn:t=!0,selectedAgentId:s,onAgentSelect:l,onOpenSkillsDialog:i,onOpenIntegrationsDialog:o}=e;(0,eC.c)("thread");
1let c=(0,eA.b2)(),[d,u]=(0,n.useState)(!1),[m,g]=(0,n.useState)(""),[p,v]=(0,n.useState)(""),[j,b]=(0,n.useState)(1),[y,N]=(0,n.useState)([]),[w,k]=(0,n.useState)({open:!1,tab:"knowledge"}),[_,C]=(0,n.useState)(!1),[A,F]=(0,n.useState)("main");(0,n.useEffect)(()=>{let e=()=>{C(window.innerWidth<640)};return e(),window.addEventListener("resize",e),()=>window.removeEventListener("resize",e)},[]),(0,n.useEffect)(()=>{let e=setTimeout(()=>{v(m),b(1)},300);return()=>clearTimeout(e)},[m]);let z=(0,n.useMemo)(()=>({page:j>1?j:void 0,limit:50,search:p||void 0}),[j,p]),{data:M,isLoading:R,isFetching:D}=(0,a._F)(z,{enabled:t});(0,n.useEffect)(()=>{Array.isArray(null==M?void 0:M.agents)&&(1===j||p?N(M.agents):N(e=>[...e,...M.agents]))},[M,j,p]);let L=(0,n.useMemo)(()=>y.find(e=>{var t;return(null==(t=e.metadata)?void 0:t.is_rgo_default)===!0}),[y]),T=(0,n.useMemo)(()=>({agent_id:void 0,name:"RationalGo",metadata:{is_rgo_default:!0}}),[]);(0,n.useEffect)(()=>{d||(g(""),v(""),b(1),F("main"))},[d]);let P=(0,n.useMemo)(()=>{let e=[..."app_builder"===c?y:y.filter(e=>{var t;return(null==(t=e.metadata)?void 0:t.is_app_builder_default)!==!0})],t=s?e.find(e=>e.agent_id===s):void 0,r=t?e.filter(e=>e.agent_id!==s):e;return t?[t,...r]:r},[y,s,c]),$=(0,n.useMemo)(()=>!!(null==M?void 0:M.pagination)&&M.pagination.current_page<M.pagination.total_pages,[null==M?void 0:M.pagination]),O=(0,n.useCallback)(()=>{$&&!D&&b(e=>e+1)},[$,D]),Z=(0,n.useCallback)(e=>{null==l||l(e),u(!1)},[l]),q=(0,n.useMemo)(()=>{if(s){var e;let t=y.find(e=>e.agent_id===s);if(t&&("app_builder"===c||(null==(e=t.metadata)?void 0:e.is_app_builder_default)!==!0))return t}return L||y[0]},[y,s,L,c]),B=(0,n.useCallback)(e=>{(s||(null==q?void 0:q.agent_id))&&(k({open:!0,tab:e}),u(!1))},[s,null==q?void 0:q.agent_id]),W=(0,n.useCallback)(function(e){var t;let s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:20;return!e&&(R||L)||(null==e||null==(t=e.metadata)?void 0:t.is_rgo_default)?(0,r.jsx)(e_.Y,{size:s}):(0,r.jsx)(eS.lx,{agent:e,agentId:null==e?void 0:e.agent_id,size:s,className:"flex-shrink-0 !border-0"})},[R,L]),V=(0,n.useCallback)(e=>{u(!1),"skills"===e?null==i||i():"integrations"===e?null==o||o():B(e)},[i,o,B]),H=(0,n.useMemo)(()=>[{action:"skills",icon:I.default,label:"Skills"},{action:"knowledge",icon:S.default,label:"Knowledge"},{action:"integrations",icon:ey.default,label:"Integrations"},{action:"triggers",icon:eN.default,label:"Triggers"}],[]),K=(0,n.useCallback)(()=>(0,r.jsx)(r.Fragment,{children:R&&0===P.length?(0,r.jsx)("div",{className:"px-1 space-y-0.5",children:Array.from({length:3}).map((e,t)=>(0,r.jsxs)("div",{className:"flex items-center gap-2 px-2 py-1.5 rounded-lg",children:[(0,r.jsx)("div",{className:"w-1.5"}),(0,r.jsx)("div",{className:"h-5 w-5 bg-muted/60 rounded-md animate-pulse"}),(0,r.jsx)("div",{className:"h-3.5 bg-muted rounded flex-1 animate-pulse"})]},t))}):0===P.length?(0,r.jsx)(ej.xL,{children:p?"No agents found":"No agents yet"}):(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(ej.L$,{children:P.map(e=>{let t=s===e.agent_id;return(0,r.jsxs)(ej.h_,{value:e.agent_id||e.name,onSelect:()=>Z(e.agent_id),className:(0,U.cn)("flex items-center gap-2 px-2 py-1.5 cursor-pointer",t&&"bg-accent"),children:[(0,r.jsx)("div",{className:(0,U.cn)("w-1.5 h-1.5 rounded-full flex-shrink-0",t?"bg-primary":"opacity-0")}),W(e,20),(0,r.jsx)("span",{className:"flex-1 truncate text-sm",children:e.name})]},e.agent_id)})}),$&&(0,r.jsx)("div",{className:"px-2 py-1",children:(0,r.jsx)("button",{className:"w-full text-xs text-muted-foreground hover:text-foreground py-1 rounded-lg hover:bg-accent transition-colors",onClick:O,disabled:D,children:D?"Loading...":"Load more"})})]})}),[P,R,p,s,Z,W,$,O,D]),G=(0,n.useCallback)(()=>l&&(s||(null==q?void 0:q.agent_id))?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(ej.fx,{className:"my-1"}),(0,r.jsx)(ej.L$,{children:H.map(e=>{let{action:t,icon:s,label:n}=e;return(0,r.jsxs)(ej.h_,{value:"setting-".concat(t),onSelect:()=>V(t),className:"flex items-center gap-2 px-2 py-1.5 cursor-pointer text-muted-foreground",children:[(0,r.jsx)(s,{className:"h-3.5 w-3.5"}),(0,r.jsx)("span",{className:"text-xs",children:n})]},t)})})]}):null,[l,s,null==q?void 0:q.agent_id,H,V]),J=(0,n.useCallback)(()=>(0,r.jsx)(r.Fragment,{children:R&&0===P.length?(0,r.jsx)("div",{className:"space-y-2 px-3",children:Array.from({length:3}).map((e,t)=>(0,r.jsxs)("div",{className:"flex items-center gap-3 p-2 rounded-xl",children:[(0,r.jsx)("div",{className:"h-7 w-7 bg-muted/60 rounded-lg animate-pulse"}),(0,r.jsx)("div",{className:"h-4 bg-muted rounded flex-1 animate-pulse"})]},t))}):0===P.length?(0,r.jsx)("div",{className:"p-6 text-center text-sm text-muted-foreground",children:p?"No agents found":"No agents yet"}):(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("div",{className:(0,U.cn)("overflow-y-auto max-h-[50vh] px-3 space-y-0.5","[&::-webkit-scrollbar]:hidden [-ms-overflow-style:'none'] [scrollbar-width:'none']"),children:P.map(e=>{let t=s===e.agent_id;return(0,r.jsxs)("div",{className:(0,U.cn)("flex items-center gap-3 text-sm cursor-pointer rounded-xl transition-colors px-3 py-2.5",t?"bg-accent":"hover:bg-muted/50 active:bg-muted/70"),onClick:()=>Z(e.agent_id),children:[(0,r.jsx)("div",{className:(0,U.cn)("w-2 h-2 rounded-full flex-shrink-0",t?"bg-primary":"opacity-0")}),W(e,28),(0,r.jsx)("span",{className:"flex-1 truncate text-base font-medium",children:e.name})]},e.agent_id)})}),$&&(0,r.jsx)("div",{className:"pt-2 px-3",children:(0,r.jsx)(x.$,{size:"sm",variant:"ghost",className:"w-full text-sm text-muted-foreground hover:text-foreground rounded-xl hover:bg-muted/60 h-10",onClick:O,disabled:D,children:D?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(E.RgoLoader,{size:"small",className:"mr-2"}),"Loading..."]}):"Load more"})})]})}),[P,R,p,s,Z,W,$,O,D]),Q=(0,n.useCallback)(()=>l&&(s||(null==q?void 0:q.agent_id))?(0,r.jsx)("div",{className:"px-4",children:(0,r.jsx)("div",{className:"space-y-0.5",children:H.map(e=>{let{action:t,icon:s,label:n}=e;return(0,r.jsxs)("div",{className:"flex items-center gap-3 px-3 py-2.5 rounded-xl text-muted-foreground hover:text-foreground hover:bg-muted/50 active:bg-muted/70 cursor-pointer transition-colors",onClick:()=>V(t),children:[(0,r.jsx)(s,{className:"h-4 w-4"}),(0,r.jsx)("span",{className:"text-sm",children:n})]},t)})})}):null,[l,s,null==q?void 0:q.agent_id,H,V]),X=!(null==q?void 0:q.name)||(null==q?void 0:q.name)==="RationalGo",Y=(0,n.useCallback)(()=>"agents"===A?(0,r.jsxs)("div",{className:"flex flex-col h-full",children:[(0,r.jsxs)("div",{className:"flex items-center gap-3 px-4 py-3 border-b border-border",children:[(0,r.jsx)("button",{onClick:()=>F("main"),className:"p-2 -ml-2 hover:bg-muted/50 rounded-xl transition-colors",children:(0,r.jsx)(ew.default,{className:"h-5 w-5 text-muted-foreground"})}),(0,r.jsx)("span",{className:"text-base font-medium",children:"Select Agent"})]}),(0,r.jsx)("div",{className:"px-4 py-3",children:(0,r.jsxs)("div",{className:"relative",children:[(0,r.jsx)(f.default,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-5 w-5 text-muted-foreground pointer-events-none"}),(0,r.jsx)("input",{type:"text",placeholder:"Search agents...",value:m,onChange:e=>g(e.target.value),className:"w-full h-12 pl-11 pr-4 rounded-xl text-base font-medium bg-muted/50 border border-border focus:outline-none focus:ring-[1.5px] focus:ring-primary/50",autoFocus:!0})]})}),(0,r.jsx)("div",{className:"flex-1 overflow-hidden",children:(0,r.jsx)(J,{})})]}):(0,r.jsxs)("div",{className:"flex flex-col",children:[(0,r.jsx)("div",{className:"flex justify-center pt-3 pb-2",children:(0,r.jsx)("div",{className:"w-10 h-1 rounded-full bg-muted-foreground
1/30"})}),l&&(0,r.jsx)("div",{className:"px-4 pb-2",children:(0,r.jsxs)("button",{onClick:()=>F("agents"),className:"w-full flex items-center gap-3 p-3 rounded-xl border border-border bg-card hover:bg-muted/50 active:bg-muted/70 transition-colors",children:[W(X?null:R&&!q?T:q,28),(0,r.jsx)("span",{className:"flex-1 truncate text-base font-medium text-left min-w-0",children:X?"RationalGo":null==q?void 0:q.name}),(0,r.jsx)(ek.default,{className:"h-5 w-5 text-muted-foreground rotate-[-90deg] flex-shrink-0"})]})}),l&&(s||(null==q?void 0:q.agent_id))&&(0,r.jsx)("div",{className:"py-2",children:(0,r.jsx)(Q,{})})]}),[A,m,l,q,R,T,W,s,J,Q,X]),ee=(0,r.jsx)(x.$,{variant:"ghost",size:"sm",className:"h-9 px-1.5 bg-transparent rounded-lg text-muted-foreground hover:text-foreground hover:bg-accent/50 flex items-center gap-1","aria-label":"Config menu",onClick:()=>u(!0),children:l?(0,r.jsxs)("div",{className:"flex items-center gap-0.5 min-w-0 max-w-[180px]",children:[X?(0,r.jsx)(e_.Y,{size:18}):(0,r.jsxs)("div",{className:"flex items-center gap-0",children:[W(R&&!q?T:q,18),(0,r.jsx)("span",{className:"truncate text-xs font-medium",children:null==q?void 0:q.name})]}),(0,r.jsx)(ek.default,{size:11,className:"opacity-60 flex-shrink-0"})]}):(0,r.jsxs)("div",{className:"flex items-center gap-1",children:[(0,r.jsx)(e_.Y,{size:18}),(0,r.jsx)(ek.default,{size:11,className:"opacity-60"})]})});return(0,r.jsxs)(r.Fragment,{children:[_?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)(h.m_,{children:[(0,r.jsx)(h.k$,{asChild:!0,children:ee}),(0,r.jsx)(h.ZI,{side:"top",children:(0,r.jsx)("p",{children:"Agent settings"})})]}),(0,r.jsx)(eb.cj,{open:d,onOpenChange:u,children:(0,r.jsxs)(eb.h,{side:"bottom",className:(0,U.cn)("rounded-t-2xl px-0 pb-8","main"===A?"max-h-[70vh]":"h-[85vh]"),children:[(0,r.jsx)(ex.s6,{children:(0,r.jsx)(eb.Fm,{children:(0,r.jsx)(eb.qp,{children:"Configuration"})})}),(0,r.jsx)(Y,{})]})})]}):(0,r.jsxs)(ev.AM,{open:d,onOpenChange:u,children:[(0,r.jsxs)(h.m_,{children:[(0,r.jsx)(h.k$,{asChild:!0,children:(0,r.jsx)(ev.Wv,{asChild:!0,children:ee})}),(0,r.jsx)(h.ZI,{side:"top",children:(0,r.jsx)("p",{children:"Agent settings"})})]}),(0,r.jsx)(ev.hl,{align:"end",sideOffset:6,className:"w-[280px] p-1.5 shadow-lg",children:(0,r.jsxs)(ej.uB,{shouldFilter:!1,children:[(0,r.jsx)(ej.G7,{placeholder:"Search agents...",value:m,onValueChange:g}),(0,r.jsxs)(ej.oI,{className:"max-h-[340px]",children:[(0,r.jsx)(K,{}),(0,r.jsx)(G,{})]})]})})]}),(s||(null==q?void 0:q.agent_id))&&w.open&&(0,r.jsx)(ef.AgentConfigurationDialog,{open:w.open,onOpenChange:e=>k({...w,open:e}),agentId:s||(null==q?void 0:q.agent_id),initialTab:w.tab,onAgentChange:l})]})}),eE=(0,n.memo)(function(){return(0,r.jsxs)(h.m_,{children:[(0,r.jsx)(h.k$,{asChild:!0,children:(0,r.jsx)("span",{className:"inline-block",children:(0,r.jsx)(x.$,{variant:"ghost",size:"sm",className:"h-9 px-1.5 sm:px-2 bg-transparent rounded-lg text-muted-foreground hover:text-foreground hover:bg-accent/50 flex items-center gap-1 cursor-pointer transition-all duration-200 flex-shrink-0 animate-in fade-in-0 zoom-in-95",disabled:!0,children:(0,r.jsxs)("div",{className:"flex items-center gap-1 min-w-0 max-w-[180px]",children:[(0,r.jsx)("div",{className:"flex-shrink-0",children:(0,r.jsx)(e_.Y,{size:18})}),(0,r.jsx)("span",{className:"truncate text-xs font-medium",children:"RationalGo"}),(0,r.jsx)(ek.default,{size:11,className:"opacity-60 flex-shrink-0"})]})})})}),(0,r.jsx)(h.ZI,{side:"top",className:"text-xs",children:(0,r.jsx)("p",{children:"Log in to change agent"})})]})}),eF=(0,n.memo)(function(e){return e.isLoggedIn?(0,r.jsx)(eI,{...e}):(0,r.jsx)(eE,{...e})});var ez=s(55823),eM=s(94251),eR=s(8175);function eD(e){let{items:t,query:s,onSelect:a,onDismiss:l,visible:i}=e,[o,c]=(0,n.useState)(0),d=(0,n.useRef)(null),u=s.startsWith("/")?s.slice(1).toLowerCase():"",m=t.filter(e=>e.slug.toLowerCase().includes(u)||e.name.toLowerCase().includes(u)||e.description&&e.description.toLowerCase().includes(u));(0,n.useEffect)(()=>{c(0)},[u]);let x=(0,n.useCallback)(e=>{i&&0!==m.length&&("ArrowDown"===e.key?(e.preventDefault(),e.stopPropagation(),c(e=>(e+1)%m.length)):"ArrowUp"===e.key?(e.preventDefault(),e.stopPropagation(),c(e=>(e-1+m.length)%m.length)):"Enter"===e.key||"Tab"===e.key?(e.preventDefault(),e.stopPropagation(),a(m[o])):"Escape"===e.key&&(e.preventDefault(),e.stopPropagation(),l()))},[i,m,o,a,l]);return((0,n.useEffect)(()=>
1{if(i)return document.addEventListener("keydown",x,!0),()=>document.removeEventListener("keydown",x,!0)},[i,x]),(0,n.useEffect)(()=>{let e=d.current;if(!e)return;let t=e.children[o];null==t||t.scrollIntoView({block:"nearest"})},[o]),i&&0!==m.length)?(0,r.jsx)("div",{ref:d,className:"absolute bottom-full left-2 right-2 mb-1.5 bg-popover border border-border/60 rounded-lg shadow-sm overflow-hidden max-h-[168px] overflow-y-auto z-50",children:m.map((e,t)=>{let s="skill"===e.type;return(0,r.jsx)("button",{className:(0,U.cn)("w-full flex items-center gap-2 px-2.5 py-1.5 text-left transition-colors",t===o?"bg-accent":"hover:bg-accent/40"),onMouseEnter:()=>c(t),onClick:()=>a(e),children:(0,r.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,r.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,r.jsxs)("span",{className:"text-xs font-medium font-mono text-foreground",children:["/",e.slug]}),(0,r.jsx)("span",{className:"text-xs text-muted-foreground truncate",children:e.name}),(0,r.jsx)("span",{className:(0,U.cn)("text-[10px] font-semibold px-1 py-px rounded uppercase leading-none flex-shrink-0",s?"bg-blue-500/10 text-blue-500":"bg-muted text-muted-foreground"),children:s?"SKILL":"CMD"})]}),e.description&&(0,r.jsx)("p",{className:"text-[10px] text-muted-foreground/60 truncate mt-px",children:e.description})]})},"".concat(e.type,"-").concat(e.id))})}):null}var eL=s(65336),eT=s(21572),eP=s(17807),e$=s(25837);let eU=n.useLayoutEffect,eO=(0,n.memo)((0,n.forwardRef)(function(e,t){let{initialValue:s="",placeholder:a,animatePlaceholder:l=!1,disabled:i,isDraggingOver:o,onSubmit:c,onPaste:d,hasFiles:m,loading:x,isAgentRunning:h,isUploading:g,valueRef:p,onHasContentChange:f,onValueChangeRef:v,forceSubmitEnabled:j,onBackspaceEmptyRef:b,onEngagedChangeRef:y}=e,[N,w]=(0,n.useState)(s),k=(0,n.useRef)(null),_=(0,n.useRef)(!1),[C,S]=(0,n.useState)(!1),[A,I]=(0,n.useState)(!1),E=A||""!==N;(0,n.useImperativeHandle)(t,()=>k.current,[]),eU(()=>{let e=k.current;if(!e)return;document.activeElement===e&&I(!0);let t=e.value;if(t&&t!==s){var r;console.info("[ChatInput] Kept text typed before the page finished loading",{length:t.length}),w(t),null==v||null==(r=v.current)||r.call(v,t)}},[]),(0,n.useEffect)(()=>{S(!0)},[]);let F=(0,n.useRef)(!1);(0,n.useEffect)(()=>{var e;E!==F.current&&(F.current=E,null==y||null==(e=y.current)||e.call(y,E))},[E,y]),(0,n.useEffect)(()=>()=>{if(F.current){var e;F.current=!1,null==y||null==(e=y.current)||e.call(y,!1)}},[y]);let[z,M]=(0,n.useState)(a),R=(0,n.useRef)(a);(0,n.useEffect)(()=>{if(!l||E||a===R.current){R.current=a,M(a);return}R.current=a;let e=0;M("");let t=setInterval(()=>{e+=1,M(a.slice(0,e)),e>=a.length&&clearInterval(t)},50);return()=>clearInterval(t)},[a,l,E]);let D=l&&!E?z:a,L=(0,n.useCallback)(()=>I(!0),[]),T=(0,n.useCallback)(()=>I(!1),[]);(0,n.useEffect)(()=>{p.current=N},[N,p]),(0,n.useEffect)(()=>{let e=N.trim().length>0;e!==_.current&&(_.current=e,f(e))},[N,f]);let P=(0,n.useCallback)(()=>{let e=k.current;if(!e)return;e.style.height="auto",e.style.maxHeight="200px",e.style.overflowY=e.scrollHeight>200?"auto":"hidden";let t=Math.min(e.scrollHeight,200);e.style.height="".concat(t,"px")},[]);(0,n.useEffect)(()=>{P()},[N,P]),(0,n.useEffect)(()=>{if(C)return window.addEventListener("resize",P),()=>window.removeEventListener("resize",P)},[P,C]);let $=(0,n.useCallback)(e=>{var t;let s=e.target.value;w(s),null==v||null==(t=v.current)||t.call(v,s)},[v]),O=(0,n.useMemo)(()=>!!C&&(/iPhone|iPad|iPod|Android/i.test(navigator.userAgent)||window.innerWidth<=768&&"ontouchstart"in window),[C]),Z=(0,n.useCallback)(e=>{if("Backspace"===e.key&&""===N){var t;null==b||null==(t=b.current)||t.call(b);return}(!O||"Enter"!==e.key||e.shiftKey)&&("Enter"!==e.key||e.shiftKey||e.nativeEvent.isComposing||(e.preventDefault(),(N.trim().length>0||m||j)&&!x&&(!i||h)&&!g&&c()))},[N,m,x,i,h,g,c,O,j,b]);return(0,n.useEffect)(()=>{let e=k.current;e&&(e.clearValue=()=>w(""),e.appendValue=e=>{w(t=>t?"".concat(t," ").concat(e):e)})},[]),(0,r.jsx)("div",{className:"flex flex-col gap-1 px-2",children:(0,r.jsx)(u.T,{ref:k,value:N,onChange:$,onKeyDown:Z,onPaste:d,onFocus:L,onBlur:T,placeholder:D,className:(0,U.cn)("w-full bg-transparent dark:bg-transparent border-none shadow-none focus-visible:ring-0 focus:border-transparent focus:shadow-none px-0.5 pb-6 pt-4 min-h-[100px] sm:min-h-[72px] max-h-[200px] overflow-y-auto resize-none rounded-[24px]","!text-[16
1px] sm:!text-[15px]",o?"opacity-40":""),disabled:i&&!h,rows:1})})})),eZ=(0,n.memo)(function(e){let{enabled:t}=e,s=(0,n.useMemo)(()=>["googledrive","gmail","googlecalendar","slack","notion","github","linear","airtable","asana","trello","salesforce","hubspot"],[]),[a,l]=(0,n.useState)(0),[i,o]=(0,n.useState)(!1),c=(0,n.useRef)(null),d=(0,n.useRef)(null),u=(0,n.useRef)(!1),m=(0,n.useRef)(s);(0,n.useEffect)(()=>{m.current=s},[s]);let x=s[a],h=(a+1)%s.length,p=s[h],{data:f}=(0,eo.Sk)(x,{enabled:t}),{data:v}=(0,eo.Sk)(p,{enabled:t}),j=(0,n.useCallback)(()=>{u.current||(u.current=!0,o(!0),c.current=setTimeout(()=>{l(e=>(e+1)%m.current.length),u.current=!1,o(!1)},500))},[]),b=(0,n.useRef)(!0);if((0,n.useEffect)(()=>{if(!t)return;let e=()=>{d.current||(d.current=setInterval(()=>{j()},1e3))},s=()=>{d.current&&(clearInterval(d.current),d.current=null)},r=()=>{b.current=!document.hidden,document.hidden?s():e()};return document.hidden||e(),document.addEventListener("visibilitychange",r),()=>{s(),c.current&&(clearTimeout(c.current),c.current=null),document.removeEventListener("visibilitychange",r)}},[t,j]),!t)return(0,r.jsx)(g.default,{className:"h-3 w-3"});if(!(null==f?void 0:f.icon_url))return(0,r.jsx)(g.default,{className:"h-3 w-3 animate-pulse"});let y=f.icon_url,N=null==v?void 0:v.icon_url;return(0,r.jsxs)("div",{className:"relative h-3 w-3 overflow-hidden",children:[(0,r.jsx)("img",{src:y,alt:x,className:"absolute inset-0 h-3 w-3 object-contain transition-opacity duration-300 ease-in-out ".concat(i?"opacity-0":"opacity-100"),style:{willChange:"opacity",backfaceVisibility:"hidden",transform:"translateZ(0)"}},"current-".concat(x)),N&&(0,r.jsx)("img",{src:N,alt:p,className:"absolute inset-0 h-3 w-3 object-contain transition-opacity duration-300 ease-in-out ".concat(i?"opacity-100":"opacity-0"),style:{willChange:"opacity",backfaceVisibility:"hidden",transform:"translateZ(0)"}},"next-".concat(p))]})}),eq=(0,n.memo)(function(e){let{isLoggedIn:t,loading:s,disabled:n,isAgentRunning:a,isIntegrationsLocked:l,quickIntegrations:i,integrationIcons:o,onOpenRegistry:c,onOpenPlanModal:d}=e;return t?(0,r.jsxs)(h.m_,{children:[(0,r.jsx)(h.k$,{asChild:!0,children:(0,r.jsxs)("div",{className:"relative",children:[(0,r.jsx)(x.$,{variant:"outline",size:"sm",className:"h-9 w-9 p-0 bg-background/60 border-[1.5px] border-border/50 rounded-lg text-muted-foreground hover:text-foreground hover:border-border hover:bg-muted/80 flex items-center justify-center cursor-pointer transition-all duration-200",disabled:s||n&&!a,onClick:()=>{c(null)},children:(0,r.jsx)(eZ,{enabled:t&&!s&&!(n&&!a)})}),l&&(0,r.jsx)("div",{className:"absolute -top-1 -right-1 w-4 h-4 bg-primary rounded-full flex items-center justify-center z-10 pointer-events-none",children:(0,r.jsx)(p.default,{className:"h-2.5 w-2.5 text-primary-foreground",strokeWidth:2.5})})]})}),(0,r.jsx)(h.ZI,{side:"top",children:(0,r.jsx)("p",{children:"Integrations"})})]}):null}),eB=(0,n.memo)(function(e){let{selectedMode:t,isModeDismissing:s,onDeselect:n}=e;return t||s?(0,r.jsxs)(x.$,{variant:"outline",size:"sm",onClick:e=>{e.preventDefault(),e.stopPropagation(),s||n()},className:(0,U.cn)("h-9 px-2.5 sm:px-3.5 bg-background/60 border-[1.5px] border-border/50 rounded-lg text-muted-foreground hover:text-foreground hover:border-border hover:bg-muted/80 flex items-center gap-1.5 cursor-pointer transition-all duration-200 flex-shrink-0",!s&&"animate-in fade-in-0 zoom-in-95",s&&"animate-out fade-out-0 zoom-out-95"),children:[t&&(e=>{let t="w-3.5 h-3.5";switch(e){case"research":return(0,r.jsx)(f.default,{className:t,strokeWidth:2});case"canvas":return(0,r.jsx)(v.default,{className:t,strokeWidth:2});case"video":return(0,r.jsx)(j.default,{className:t,strokeWidth:2});case"code":return(0,r.jsx)(b.default,{className:t,strokeWidth:2});case"docs":return(0,r.jsx)(y.default,{className:t,strokeWidth:2});case"data":return(0,r.jsx)(N.default,{className:t,strokeWidth:2});case"slides":return(0,r.jsx)(w.default,{className:t,strokeWidth:2});case"image":return(0,r.jsx)(k.default,{className:t,strokeWidth:2});default:return null}})(t),t&&(0,r.jsxs)("span",{className:"hidden sm:inline text-xs font-medium",children:[t.charAt(0).toUpperCase(),t.slice(1)]}),(0,r.jsx)(_.default,{className:"w-3.5 h-3.5",strokeWidth:2})]}):null}),eW=(0,n.memo)(function(e){let{enabled:t,isRgoAgent:s,rgoAgentModes:n,onModeChange:a}=e;return t&&((0,eg.pS)()||(0,eg.Jn)())&&s?(0,r.jsxs)("div",{className:"flex items-center gap-1 p-0.5 bg-muted/50 rounded-lg",children:[(0,r.jsxs)(h.m_,{children:[(0,r.jsx)(h.k$,{asChild:!0,children:(0,r.jsx)("button",{onClick:()=>a("adaptive"),className:(0,U.cn)("p-1.5 rounded-md transition-all duration-200 cursor-pointer","adaptive"===n?"bg-background text-foreground shadow-sm":"text-muted-foreground hover:text-foreground hover:bg-background/50"),children:(0,r.jsx)(C.default,{className:"w-4 h-4"})})}),(0,r.jsx)(h.ZI,{side:"bottom",children:(0,r.jsxs)("div",{className:"space-y-1",children:[(0,r.jsx)("p",{className:"font-medium text-primary-foreground",children:"Adaptive"}
1),(0,r.jsx)("p",{className:"text-xs text-primary-foreground/80",children:"Quick responses with smart context switching"})]})})]}),(0,r.jsxs)(h.m_,{children:[(0,r.jsx)(h.k$,{asChild:!0,children:(0,r.jsx)("button",{onClick:()=>a("autonomous"),className:(0,U.cn)("p-1.5 rounded-md transition-all duration-200 cursor-pointer","autonomous"===n?"bg-background text-foreground shadow-sm":"text-muted-foreground hover:text-foreground hover:bg-background/50"),children:(0,r.jsx)(S.default,{className:"w-4 h-4"})})}),(0,r.jsx)(h.ZI,{side:"bottom",children:(0,r.jsxs)("div",{className:"space-y-1",children:[(0,r.jsx)("p",{className:"font-medium text-primary-foreground",children:"Autonomous"}),(0,r.jsx)("p",{className:"text-xs text-primary-foreground/80",children:"Deep work mode for multi-step problem solving"})]})})]}),(0,r.jsxs)(h.m_,{children:[(0,r.jsx)(h.k$,{asChild:!0,children:(0,r.jsx)("button",{onClick:()=>a("chat"),className:(0,U.cn)("p-1.5 rounded-md transition-all duration-200 cursor-pointer","chat"===n?"bg-background text-foreground shadow-sm":"text-muted-foreground hover:text-foreground hover:bg-background/50"),children:(0,r.jsx)(A.default,{className:"w-4 h-4"})})}),(0,r.jsx)(h.ZI,{side:"bottom",children:(0,r.jsxs)("div",{className:"space-y-1",children:[(0,r.jsx)("p",{className:"font-medium text-primary-foreground",children:"Chat"}),(0,r.jsx)("p",{className:"text-xs text-primary-foreground/80",children:"Simple back-and-forth conversation"})]})})]})]}):null}),eV=(0,n.memo)(function(e){let{hasContent:t,hasFiles:s,isAgentRunning:n,loading:a,disabled:l,isUploading:i,onStopAgent:o,onSubmit:c,buttonLoaderVariant:d,pendingFilesCount:u}=e,m=!t&&!s&&!n||a||l&&!n||i;return n&&o?(0,r.jsx)("div",{className:"relative",children:(0,r.jsxs)(h.m_,{children:[(0,r.jsx)(h.k$,{asChild:!0,children:(0,r.jsx)(x.$,{type:"button",onClick:o,size:"sm","aria-label":"Stop",className:(0,U.cn)("flex-shrink-0 self-end border-[1.5px] border-border rounded-lg relative z-10 transition-all duration-200 w-9 h-9",(a||i)&&"opacity-100 [&[disabled]]:opacity-100"),disabled:m,children:(0,r.jsx)(F.default,{className:"h-3.5 w-3.5 fill-current","aria-hidden":"true"})})}),(0,r.jsx)(h.ZI,{side:"top",children:i?(0,r.jsxs)("p",{children:["Uploading ",u," file",1!==u?"s":"","..."]}):(0,r.jsx)("p",{children:"Stop"})})]})},"stop"):(0,r.jsx)("div",{className:"relative",children:(0,r.jsxs)(h.m_,{children:[(0,r.jsx)(h.k$,{asChild:!0,children:(0,r.jsx)(x.$,{type:"submit",onClick:c,size:"sm",className:(0,U.cn)("flex-shrink-0 self-end border-[1.5px] border-border rounded-lg relative z-10 transition-all duration-200","w-9 h-9",(a||i)&&"opacity-100 [&[disabled]]:opacity-100"),disabled:m,children:(a||i)&&!n?(0,r.jsx)(E.RgoLoader,{customSize:30,variant:d}):n?(0,r.jsx)("div",{className:"min-h-[12px] min-w-[12px] w-[12px] h-[12px] rounded-sm bg-current"}):(0,r.jsx)(J.default,{className:"h-5 w-5",strokeWidth:2.5})})}),i?(0,r.jsx)(h.ZI,{side:"top",children:(0,r.jsxs)("p",{children:["Uploading ",u," file",1!==u?"s":"","..."]})}):n?(0,r.jsx)(h.ZI,{side:"top",children:(0,r.jsx)("p",{children:"Stop agent"})}):null]})},"send")}),eH=(0,n.memo)(function(e){let{mounted:t}=e,s=(0,i.EK)(),n=(0,i.py)();return t?(0,r.jsxs)(h.m_,{children:[(0,r.jsx)(h.k$,{asChild:!0,children:(0,r.jsxs)("div",{className:"flex items-center gap-1.5 flex-shrink-0 cursor-pointer",onClick:e=>{e.stopPropagation(),n()},children:[(0,r.jsx)("span",{className:(0,U.cn)("text-xs font-medium transition-colors duration-200 select-none",s?"text-amber-500 dark:text-amber-400":"text-muted-foreground/60"),children:"God Mode"}),(0,r.jsx)(m.d,{checked:s,className:(0,U.cn)("pointer-events-none h-4 w-7","data-[state=checked]:bg-amber-500 data-[state=checked]:border-amber-500/50","[&_[data-slot=switch-thumb]]:size-3 [&_[data-slot=switch-thumb][data-state=checked]]:translate-x-[calc(100%+2px)]"),tabIndex:-1})]})}),(0,r.jsx)(h.ZI,{side:"top",children:(0,r.jsx)("p",{children:s?"God Mode ON — Agent decides autonomously":"God Mode OFF — Agent may ask questions"})})]}):null}),eK=(0,n.memo)(function(e){let{mounted:t}=e,s=(0,o.v9)(),n=(0,o.gf)();return t?(0,r.jsxs)(h.m_,{children:[(0,r.jsx)(h.k$,{asChild:!0,children:(0,r.jsxs)("div",{className:"flex items-center gap-1.5 flex-shrink-0 cursor-pointer",onClick:e=>{e.stopPropagation(),n()},children:[(0,r.jsx)("span",{className:(0,U.cn)("text-xs font-medium transition-colors duration-200 select-none",s?"text-gold-strong":"text-muted-foreground
1/60"),children:"Memory"}),(0,r.jsx)(m.d,{checked:s,className:(0,U.cn)("pointer-events-none h-4 w-7","data-[state=checked]:bg-gold data-[state=checked]:border-gold/50","[&_[data-slot=switch-thumb]]:size-3 [&_[data-slot=switch-thumb][data-state=checked]]:translate-x-[calc(100%+2px)]"),tabIndex:-1})]})}),(0,r.jsx)(h.ZI,{side:"top",children:(0,r.jsx)("p",{children:s?"Memory ON — Agent learns from conversations":"Memory OFF — No memory extraction for this run"})})]}):null}),eG=(0,n.memo)((0,n.forwardRef)((e,t)=>{var s,i,o,u,m;let{onSubmit:x,placeholder:g="Describe what you need help with...",loading:p=!1,disabled:f=!1,isAgentRunning:v=!1,onStopAgent:j,autoFocus:b=!0,value:y,onChange:N,onFileBrowse:w,sandboxId:k,hideAttachments:C=!1,selectedAgentId:A,onAgentSelect:E,messages:F=[],bgColor:z="bg-card",isLoggedIn:M=!0,enableAdvancedConfig:R=!1,onConfigureAgent:D,hideAgentSelection:L=!1,hideIntegrations:B=!1,hideSkills:W=!1,hideMemoryToggle:V=!1,hideGodMode:H=!1,hideRgoModes:K=!1,showGitHubButton:J=!1,githubProjectId:Q,githubProjectName:X,tightBottomPadding:ed=!1,defaultShowSnackbar:eg=!1,showToLowCreditUsers:ev=!0,showScrollToBottomIndicator:ej=!1,onScrollToBottom:eb,selectedMode:ey,onModeDeselect:eN,animatePlaceholder:ew=!1,onInputEngagedChange:ek,threadId:e_=null,projectId:eC}=e,eS=(0,ei.H)(eC),eA=f||eS,eI=v&&!eS,eE=(0,n.useRef)(""),eZ=(0,n.useRef)(null),[eG,eJ]=(0,n.use
1State)(!1),[eQ,eX]=(0,n.useState)([]),eY=(0,n.useRef)(eQ);eY.current=eQ;let[e0,e1]=(0,n.useState)([]),[e2,e5]=(0,n.useState)(!1),[e3,e4]=(0,n.useState)(!1),[e8,e6]=(0,n.useState)(!1),e7=eQ.length>0,e9=e0.length,te=void 0!==y&&void 0!==N,tt=(0,n.useRef)(null),ts=(0,n.useCallback)(e=>{te&&N&&(tt.current=e,N(e))},[te,N]),[tr,tn]=(0,n.useState)(!1),[ta,tl]=(0,n.useState)(null),[ti,to]=(0,n.useState)(eg),[tc,td]=(0,n.useState)(!1),[tu,tm]=(0,n.useState)(!1),[tx,th]=(0,n.useState)({open:!1,tab:"knowledge"}),[tg,tp]=(0,n.useState)(!1),[tf,tv]=(0,n.useState)(!1),[tj,tb]=(0,n.useState)(""),[ty,tN]=(0,n.useState)(null),tw=(0,n.useRef)(null);tw.current=ty;let{data:tk=[]}=(0,eL.rW)(A||"",{enabled:!!A}),{data:t_=[]}=(0,eT.zi)(A||"",{enabled:!!A}),tC=(0,n.useMemo)(()=>{let e=tk.map(e=>({id:e.id,slug:e.slug,name:e.name,description:e.description,type:"command",icon:e.icon,prompt_template:e.prompt_template,argument_hint:e.argument_hint})),t=new Set(tk.map(e=>e.slug));for(let s of t_)s.is_active&&(t.has(s.slug)||e.push({id:s.agent_skill_id||s.skill_id,slug:s.slug,name:s.name,description:s.description,type:"skill",icon:s.icon,auth_provider:s.auth_provider}));return e},[tk,t_]),[tS,tA]=(0,n.useState)(!1),[tI,tE]=(0,n.useState)(!1),[tF,tz]=(0,n.useState)("adaptive"),{selectedModel:tM,setSelectedModel:tR,subscriptionStatus:tD,allModels:tL,canAccessModel:tT,getActualModelId:tP,refreshCustomModels:t$}=(0,O.xE)(),{data:tU,isLoading:tO}=(0,eh.u4)({enabled:M}),tZ=(0,Z.np)(),tq=(0,q.jE)(),tB=(null==tU?void 0:tU.subscription)?(()=>{var e,t,s,r,n,a,l,i,o,c,d,u,m;if(("free"===tU.subscription.tier_key||"none"===tU.subscription.tier_key||(null!=(i=null==(e=tU.tier)?void 0:e.monthly_credits)?i:0)===0)&&(null==(s=tU.credits)||null==(t=s.daily_refresh)?void 0:t.enabled)){let e=tU.credits.daily_refresh.daily_amount||0,t=Math.max(0,e-((null==(o=tU.credits)?void 0:o.daily)||0));return{tier_key:tU.subscription.tier_key,tier:{name:tU.subscription.tier_key,display_name:tU.subscription.tier_display_name},plan_name:tU.subscription.tier_display_name,status:tU.subscription.status,current_usage:t,cost_limit:e,credits:{balance:null!=(d=null==(c=tU.credits)?void 0:c.total)?d:0,tier_credits:e}}}let x=(null==(r=tU.tier)?void 0:r.monthly_credits)||0,h=Math.max(0,x-((null==(n=tU.credits)?void 0:n.monthly)||0));return{tier_key:tU.subscription.tier_key,tier:{name:tU.subscription.tier_key,display_name:tU.subscription.tier_display_name},plan_name:tU.subscription.tier_display_name,status:tU.subscription.status,current_usage:h,cost_limit:x,credits:{balance:null!=(u=null==(a=tU.credits)?void 0:a.total)?u:0,tier_credits:null!=(m=null==(l=tU.tier)?void 0:l.monthly_credits)?m:0}}})():null,tW=(null==tU?void 0:tU.subscription)&&("free"===tU.subscription.tier_key||"none"===tU.subscription.tier_key||!tU.subscription.tier_key),tV=null!=(u=null==tU||null==(s=tU.free_tier_overrides)?void 0:s.integrations_enabled)&&u,tH=tW&&!tV,{resolvedTheme:tK}=(0,P.D)(),tG="dark"===tK?"black":"white",tJ=(0,n.useMemo)(()=>[{id:"googledrive",name:"Google Drive",slug:"googledrive"}
1,{id:"slack",name:"Slack",slug:"slack"},{id:"notion",name:"Notion",slug:"notion"}],[]),{data:tQ}=(0,eo.Sk)("googledrive",{enabled:M}),{data:tX}=(0,eo.Sk)("slack",{enabled:M}),{data:tY}=(0,eo.Sk)("notion",{enabled:M}),t0=(0,n.useMemo)(()=>({googledrive:null==tQ?void 0:tQ.icon_url,slack:null==tX?void 0:tX.icon_url,notion:null==tY?void 0:tY.icon_url}),[tQ,tX,tY]),t1=(0,n.useMemo)(()=>{if(!tU||!tB||!ev)return!1;let e=tB.cost_limit||0,t=tB.current_usage||0;return 0!==e&&t>=.7*e},[tU,tB,ev]);(0,n.useEffect)(()=>{t1&&!1!==eg&&!tc&&(!1===ti||ti===eg)?to("upgrade"):t1||!1===ti||to(!1)},[tB,ti,eg,t1,tD,ev,tc]);let t2=(0,n.useRef)(null),{data:t5,isLoading:t3}=(0,a._F)({},{enabled:M}),t4=Array.isArray(null==t5?void 0:t5.agents)?t5.agents:[],t8=t4.find(e=>e.agent_id===A),t6=t4.find(e=>{var t;return(null==(t=e.metadata)?void 0:t.is_rgo_default)===!0}),t7=!!t3||(null==t8||null==(i=t8.metadata)?void 0:i.is_rgo_default)||!A&&void 0!==t6||!1,{initializeFromAgents:t9}=(0,l.xi)();(0,n.useImperativeHandle)(t,()=>({getPendingFiles:()=>e0,getUploadedFileIds:()=>eQ.filter(e=>e.fileId&&"ready"===e.status).map(e=>e.fileId),hasUploadsInProgress:()=>eQ.some(e=>"uploading"===e.status||"pending"===e.status),clearPendingFiles:()=>e1([]),clearUploadedFiles:()=>eX([]),setValue:e=>{let t=eZ.current;(null==t?void 0:t.clearValue)&&(t.clearValue(),e&&t.appendValue(e)),eE.current=e,eJ(e.trim().length>0)},getValue:()=>eE.current,hydrateUploadedFiles:e=>{eX(e.map(e=>({...e,status:"ready"})))},focusAndSelect:e=>{let t=0,s=()=>{let r=eZ.current;if(!r)return;let n=e?r.value.indexOf(e):-1;if(-1===n&&t<8){t+=1,requestAnimationFrame(s);return}r.focus(),n>-1&&r.setSelectionRange(n,n+e.length)};requestAnimationFrame(s)}}),[e0,eQ]),(0,n.useEffect)(()=>{t4.length>0&&!E&&t9(t4)},[t4,E,t9]),(0,n.useEffect)(()=>{tA(!0)},[]),(0,n.useEffect)(()=>{if(void 0!==y&&y!==eE.current){if(y===tt.current)return void console.debug("[ChatInput] Ignored a stale echo of typed text from the parent",{echoLength:y.length,currentLength:eE.current.length});tt.current=null;let e=eZ.current;(null==e?void 0:e.clearValue)&&(e.clearValue(),y&&e.appendValue(y)),eE.current=y,eJ(y.trim().length>0)}},[y]);let se=(0,n.useRef)(void 0);se.current=e=>{if(tw.current){e.startsWith("/")&&(tN(null),tC.length>0&&(tb(e),tv(!0)));return}tC.length>0&&e.startsWith("/")?(tb(e),tv(!0)):tv(!1)};let st=(0,n.useRef)(void 0);st.current=()=>{tw.current&&tN(null)};let ss=(0,n.useRef)(void 0);ss.current=ek,(0,n.useEffect)(()=>{tE(!1)},[ey]);let sr=(0,n.useCallback)(()=>{tE(!0),setTimeout(()=>{null==eN||eN(),tE(!1)},200)},[eN]);(0,n.useEffect)(()=>{b&&eZ.current&&eZ.current.focus()},[b]);let sn=(0,n.useRef)(v);(0,n.useEffect)(()=>{sn.current=v},[v]);let sa=(0,n.useRef)(0),sl=(0,n.useRef)(0);eU(()=>{eI&&(sl.current=Date.now())},[eI]);let si=(0,n.useCallback)(async e=>{e.preventDefault();let t=eE.current,s=eY.current,r=!!tw.current;if(!t.trim()&&!r&&0===s.length){v&&console.debug("[ChatInput] Empty submit while a run is active: ignored (Stop is the only way to stop)",{threadId:e_});return}if(p||f&&!v||eS||e2)return;v||(sa.current=Date.now()),e6(!0),tv(!1);let n=t;if(tw.current&&(n="/".concat(tw.current.slug," ").concat(n).trim(),tN(null)),n.startsWith("/")&&tC.length>0){let e=n.match(/^\/(\S+)\s*([\s\S]*)/);if(e){let t=e[1],s=e[2]||"",r=tC.find(e=>e.slug===t);(null==r?void 0:r.type)==="command"&&r.prompt_template?n="[Command: ".concat(r.name,"]\n").concat(r.prompt_template,"\n\n").concat(s).trim():(null==r?void 0:r.type)==="skill"&&(n="[Invoke Skill: /".concat(t,"]\n\nUser request: ").concat(s).trim())}}let a=tM?tP(tM):void 0,l=s.filter(e=>e.fileId&&"ready"===e.status).map(e=>e.fileId);(0,eP.Kw)({message_length:n.length}),x(n,{agent_id:A,model_name:a&&a.trim()?a.trim():void 0,file_ids:l.length>0?l:void 0})},[p,f,v,e2,eS,e_,tP,tM,x,A,tC]),so=(0,n.useCallback)(()=>{if(!j)return;let e=Date.now(),t=e-sa.current,s=e-sl.current;if(t<1500||s<1500)return void console.info("[ChatInput] Ignored a Stop press too soon after the send or after Stop appeared (treated as a double-click on Send)",{threadId:e_,msSinceSend:t,msSinceStopShown:s});console.info("[ChatInput] Stop pressed",{threadId:e_}),j()},[j,e_]),sc=(0,n.useCallback)(e=>{if(!e.clipboardData)return;let t=Array.from(e.clipboardData.items),s=[],r=t.some(e=>"string"===e.kind&&"text/plain"===e.type);for(let e of t)if("file"===e.kind&&e.type.startsWith("image/")){let t=e.getAsFile();t&&s.push(t)}s.length>0&&(r||e.preventDefault(),(0,d.aT)(s,k,eC,e1,eX,e5,F,tq))},[k,eC,F,tq]),sd=(0,n.useCallback)(e=>{let t=eZ.current;(null==t?void 0:t.appendValue)&&t.appendValue(e),te&&ts(eE.current?"".concat(eE.current," ").concat(e):e)},[te,ts]),su=(0,n.useCallback)(async e=>{let t=eQ[e];t.localUrl&&URL.revokeObjectURL(t.localUrl),eX(t=>t.filter((t,s)=>s!==e)),!k&&e0.length>e&&e1(t=>t.filter((t,s)=>s!==e));let s=F.some(e=>("string"==typeof e.content?e.content:"").includes("[Uploaded File: ".concat(t.path,"]")));k&&t.path&&!s&&tZ.mutate({sandboxId:k,filePath:t.path},{onError:e=>{console.error("Failed to delete file from server:",e)}})},[eQ,k,e0,F,tZ]),sm=(0,n.useCallback)(()=>{si({preventDefault:()=>{}})},[si]),sx=(0,n.useCallback)(e=>{eJ(e),ts(eE.current)},[ts]),sh=eS?"Publishing your app — chat will resume when done":ty?"Add instructions for /".concat(ty.slug,"..."):g,sg=ew&&!eS&&!ty,sp=!!ty,sf=(0,n.useMemo)(()=>(0,r.jsx)(eO,{ref:eZ,placeholder:sh,animatePlaceholder:sg,disabled:eA,isDraggingOver:e3,onSubmit:sm,onPaste:sc,hasFiles:e7,loading:p,isAgentRunning:eI,isUploading:e2,valueRef:eE,onHasContentChange:sx,onValueChangeRef:se,forceSubmitEnabled:sp,onBackspaceEmptyRef:st,onEngagedChangeRef:ss}),[sh,sg,eA,e3,sm,sc,e7,p,eI,e2,sx,sp]),sv=(0,n.useCallback)(e=>{tl(e),tn(!0)},[]),sj=(0,n.useCallback)(()=>{tm(!0)},[]),sb=(0,n.useMemo)(()=>(0,r.jsxs)("div",{className:"order-2 @xl/controls:order-1 flex items-center gap-1.5 min-w-0 flex-shrink overflow-visible",children:[!C&&(0,r.jsx)(d.eT,{ref:t2,loading:p,disabled:eA,isAgentRunning:eI,isUploading:e2,s
1andboxId:k,projectId:eC,setPendingFiles:e1,setUploadedFiles:eX,setIsUploading:e5,messages:F,isLoggedIn:M}),J&&(0,r.jsx)(eM.e,{projectId:Q||eC||void 0,defaultRepoName:(0,eR.P)(X),variant:"icon"}),!B&&(0,r.jsx)(eq,{isLoggedIn:M,loading:p,disabled:eA,isAgentRunning:eI,isIntegrationsLocked:null!=tH&&tH,quickIntegrations:tJ,integrationIcons:t0,onOpenRegistry:sv,onOpenPlanModal:sj}),!W&&M&&A&&(0,r.jsxs)(h.m_,{children:[(0,r.jsx)(h.k$,{asChild:!0,children:(0,r.jsx)("button",{onClick:()=>tp(!0),disabled:eA&&!eI,className:"h-9 w-9 p-0 bg-background/60 border-[1.5px] border-border/50 rounded-lg text-muted-foreground hover:text-foreground hover:border-border hover:bg-muted/80 flex items-center justify-center cursor-pointer transition-all duration-200 disabled:cursor-not-allowed disabled:opacity-60","aria-label":"Skills & Plugins",children:(0,r.jsx)(I.default,{className:"h-3.5 w-3.5",strokeWidth:2})})}),(0,r.jsx)(h.ZI,{side:"top",className:"text-xs",children:"Skills & Plugins"})]}),!L&&(0,r.jsx)("div",{className:"@xl/controls:hidden",children:(0,r.jsx)(eF,{isLoggedIn:M,selectedAgentId:A,onAgentSelect:E,onOpenSkillsDialog:()=>tp(!0),onOpenIntegrationsDialog:()=>sv(null)})}),!K&&(0,r.jsx)("div",{className:"hidden @xl/controls:block",children:(0,r.jsx)(eW,{enabled:!1,isRgoAgent:t7,rgoAgentModes:tF,onModeChange:tz})}),eN&&(0,r.jsx)("div",{className:"hidden @xl/controls:block",children:(0,r.jsx)(eB,{selectedMode:ey,isModeDismissing:tI,onDeselect:sr})})]}),[C,p,eA,eI,e2,k,eC,F,M,tH,tJ,t0,sv,sj,e_,t7,tF,eN,ey,tI,sr,A,L,E,B,W,K,J,Q,X]),sy=(0,n.useMemo)(()=>(0,r.jsxs)("div",{className:"order-1 @xl/controls:order-2 w-full @xl/controls:w-auto @xl/controls:ml-auto flex items-center justify-start @xl/controls:justify-end gap-2 flex-shrink-0",children:[!V&&M&&(0,r.jsx)(eK,{mounted:tS}),!V&&!H&&M&&(0,r.jsx)("div",{className:"w-[1.5px] h-3.5 rounded-full bg-foreground
1/15"}),!H&&M&&(0,r.jsx)(eH,{mounted:tS}),!L&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("div",{className:"hidden @xl/controls:block w-[1.5px] h-3.5 rounded-full bg-foreground/15"}),(0,r.jsx)("div",{className:"hidden @xl/controls:block",children:(0,r.jsx)(eF,{isLoggedIn:M,selectedAgentId:A,onAgentSelect:E,onOpenSkillsDialog:()=>tp(!0),onOpenIntegrationsDialog:()=>sv(null)})})]})]}),[M,tS,L,A,E,sv,V,H]),sN=(0,n.useMemo)(()=>(0,r.jsxs)("div",{className:"order-3 ml-auto @xl/controls:ml-0 flex items-center gap-2 flex-shrink-0",children:[M&&(0,r.jsx)(T,{onTranscription:sd,disabled:p||eA&&!eI}),(0,r.jsx)(eV,{hasContent:eG||!!ty,hasFiles:e7,isAgentRunning:eI,loading:p,disabled:eA,isUploading:e2,onStopAgent:j?so:void 0,onSubmit:si,buttonLoaderVariant:tG,pendingFilesCount:e9})]}),[M,p,eA,sd,eI,eG,e7,e2,j,so,si,tG,e9,ty]),sw=(0,n.useMemo)(()=>(0,r.jsx)("div",{className:"@container/controls",children:(0,r.jsxs)("div",{className:"flex flex-wrap @xl/controls:flex-nowrap items-center mt-0 px-2 gap-x-1.5 gap-y-1",children:[sb,sy,sN]})}),[sb,sy,sN]),sk=(null!=(m=null==tB||null==(o=tB.credits)?void 0:o.balance)?m:0)<=0,s_=!!ti||!!(tW&&sk&&tB),sC=(0,el.N)(e=>e.queuedMessages),sS=(0,el.N)(e=>e.removeMessage),sA=(0,el.N)(e=>e.moveUp),sI=n.useMemo(()=>e_?sC.filter(e=>e.threadId===e_):[],[sC,e_]),sE=n.useCallback(e=>{j&&j(),sS(e.id),setTimeout(()=>{x(e.message,e.options)},100)},[j,sS,x]);return(0,r.jsx)(h.Bc,{children:(0,r.jsxs)("div",{className:"mx-auto w-full max-w-4xl relative",children:[!1,(0,r.jsxs)("div",{className:"relative",children:[(0,r.jsx)(G,{subscriptionData:tB,onOpenUpgrade:()=>{(0,e$.CT)(),tm(!0)},isVisible:s_}),ej&&eb&&(0,r.jsx)("button",{onClick:eb,className:"absolute cursor-pointer right-3 z-50 w-8 h-8 rounded-full bg-card border border-border transition-all duration-200 hover:scale-105 flex items-center justify-center -top-12\n                }",title:"Scroll to bottom",children:(0,r.jsx)(Y.default,{className:"w-4 h-4 text-muted-foreground"})}),(0,r.jsx)(c.Zp,{className:"shadow-none w-full max-w-4xl mx-auto bg-transparent border-none overflow-visible py-0 ".concat(ed?"pb-2":"pb-5"," ").concat(s_?"mt-6":""," ").concat(R&&A?"":"rounded-2xl"," relative z-10"),onDragOver:e=>{e.preventDefault(),e.stopPropagation(),e4(!0)},onDragLeave:e=>{e.preventDefault(),e.stopPropagation(),e4(!1)},onDrop:e=>{if(e.preventDefault(),e.stopPropagation(),e4(!1),t2.current&&e.dataTransfer.files.length>0){let t=Array.from(e.dataTransfer.files);(0,d.aT)(t,k,eC,e1,eX,e5,F,tq)}},children:(0,r.jsx)("div",{className:"w-full text-sm flex flex-col justify-between items-start rounded-lg",children:(0,r.jsxs)(c.Wu,{className:"w-full p-1.5 pb-1.5 ".concat(z," border rounded-[24px]"),children:[(eQ.length>0||e2)&&(0,r.jsx)("div",{className:"relative",children:(0,r.jsx)($.XO,{files:eQ||[],sandboxId:k,onRemove:p?void 0:su,layout:"inline",maxHeight:"216px",showPreviews:!0})}),(0,r.jsxs)("div",{className:"relative flex flex-col w-full h-full gap-2 justify-between",children:[(0,r.jsx)(eD,{items:tC,query:tj,visible:tf,onSelect:e=>{let t=eZ.current;(null==t?void 0:t.clearValue)&&t.clearValue(),eE.current="",tN(e),tv(!1),requestAnimationFrame(()=>{null==t||t.focus()})},onDismiss:()=>tv(!1)}),eS&&(0,r.jsxs)("div",{className:"flex items-center gap-2 mx-3 mt-2 px-3 py-2 rounded-lg border border-primary/20 bg-primary/5 text-xs text-muted-foreground",children:[(0,r.jsx)(ee.default,{className:"h-3.5 w-3.5 text-primary animate-pulse flex-shrink-0"}),(0,r.jsx)("span",{className:"flex-1",children:"Publishing your app — chat will resume when the build finishes."})]}),ty&&(0,r.jsx)("div",{className:"flex items-center px-3 pt-2 pb-0",children:(0,r.jsxs)("div",{className:"inline-flex items-center gap-1 pl-2 pr-1 py-0.5 bg-accent/80 border border-border/50 rounded-lg",children:["skill"===ty.type?(0,r.jsx)(et.default,{className:"h-3 w-3 text-blue-500 flex-shrink-0"}):(0,r.jsx)(es.default,{className:"h-3 w-3 text-muted-foreground flex-shrink-0"}),(0,r.jsxs)("span",{className:"text-xs font-medium font-mono text-foreground",children:["/",ty.slug]}),(0,r.jsx)("span",{className:(0,U.cn)("text-[10px] font-semibold px-1 py-px rounded uppercase leading-none flex-shrink-0","skill"===ty.type?"bg-blue-500/15 text-blue-500":"bg-muted text-muted-foreground"),children:"skill"===ty.type?"SKILL":"CMD"}),(0,r.jsx)("button",{onClick:()=>{var e;tN(null),null==(e=eZ.current)||e.focus()}
1,className:"p-1 rounded hover:bg-muted-foreground/15 text-muted-foreground/60 hover:text-muted-foreground transition-colors",children:(0,r.jsx)(_.default,{className:"h-3 w-3"})})]})}),sf,sw]})]})})}),R&&A&&(0,r.jsx)("div",{className:"w-full max-w-4xl mx-auto -mt-12 relative z-20",children:(0,r.jsx)("div",{className:"bg-gradient-to-b from-transparent via-transparent to-muted/30 pt-8 pb-2 px-4 rounded-b-3xl border border-t-0 border-border/50 transition-all duration-300 ease-out",children:(0,r.jsxs)("div",{className:"flex items-center justify-between gap-1 overflow-x-auto scrollbar-none relative",children:[(0,r.jsxs)("button",{onClick:()=>th({open:!0,tab:"knowledge"}),className:"flex items-center gap-1.5 text-muted-foreground hover:text-foreground transition-all duration-200 px-2.5 py-1.5 rounded-2xl hover:bg-muted/50 border border-transparent hover:border-border/30 flex-shrink-0 cursor-pointer relative pointer-events-auto",children:[(0,r.jsx)("div",{className:"flex items-center -space-x-0.5",children:tJ.every(e=>t0[e.id])?(0,r.jsx)(r.Fragment,{children:tJ.map(e=>(0,r.jsx)("div",{className:"w-4 h-4 bg-white dark:bg-muted border border-border rounded-full flex items-center justify-center shadow-sm",children:(0,r.jsx)("img",{src:t0[e.id],className:"w-2.5 h-2.5",alt:e.name})},e.id))}):(0,r.jsx)(r.Fragment,{children:tJ.map(e=>(0,r.jsx)("div",{className:"w-4 h-4 bg-white dark:bg-muted border border-border rounded-full flex items-center justify-center shadow-sm",children:(0,r.jsx)(ec.Skeleton,{className:"w-2.5 h-2.5 rounded"})},e.id))})}),(0,r.jsx)("span",{className:"text-xs font-medium",children:"Integrations"})]}),(0,r.jsxs)("button",{onClick:()=>th({open:!0,tab:"knowledge"}),className:"flex items-center gap-1.5 text-muted-foreground hover:text-foreground transition-all duration-200 px-2.5 py-1.5 rounded-2xl hover:bg-muted/50 border border-transparent hover:border-border/30 flex-shrink-0 cursor-pointer relative pointer-events-auto",children:[(0,r.jsx)(er.default,{className:"h-3.5 w-3.5 flex-shrink-0"}),(0,r.jsx)("span",{className:"text-xs font-medium",children:"Tools"})]}),(0,r.jsxs)("button",{onClick:()=>th({open:!0,tab:"knowledge"}),className:"flex items-center gap-1.5 text-muted-foreground hover:text-foreground transition-all duration-200 px-2.5 py-1.5 rounded-2xl hover:bg-muted/50 border border-transparent hover:border-border/30 flex-shrink-0 cursor-pointer relative pointer-events-auto",children:[(0,r.jsx)(S.default,{className:"h-3.5 w-3.5 flex-shrink-0"}),(0,r.jsx)("span",{className:"text-xs font-medium",children:"Instructions"})]}),(0,r.jsxs)("button",{onClick:()=>th({open:!0,tab:"knowledge"}),className:"flex items-center gap-1.5 text-muted-foreground hover:text-foreground transition-all duration-200 px-2.5 py-1.5 rounded-2xl hover:bg-muted/50 border border-transparent hover:border-border/30 flex-shrink-0 cursor-pointer relative pointer-events-auto",children:[(0,r.jsx)(en.default,{className:"h-3.5 w-3.5 flex-shrink-0"}),(0,r.jsx)("span",{className:"text-xs font-medium",children:"Knowledge"})]}),(0,r.jsxs)("button",{onClick:()=>th({open:!0,tab:"triggers"}),className:"flex items-center gap-1.5 text-muted-foreground hover:text-foreground transition-all duration-200 px-2.5 py-1.5 rounded-2xl hover:bg-muted/50 border border-transparent hover:border-border/30 flex-shrink-0 cursor-pointer relative pointer-events-auto",children:[(0,r.jsx)(ea.default,{className:"h-3.5 w-3.5 flex-shrink-0"}),(0,r.jsx)("span",{className:"text-xs font-medium",children:"Triggers"})]}),(0,r.jsxs)("button",{onClick:()=>tp(!0),className:"flex items-center gap-1.5 text-muted-foreground hover:text-foreground transition-all duration-200 px-2.5 py-1.5 rounded-2xl hover:bg-muted/50 border border-transparent hover:border-border/30 flex-shrink-0 cursor-pointer relative pointer-events-auto",children:[(0,r.jsx)(I.default,{className:"h-3.5 w-3.5 flex-shrink-0"}),(0,r.jsx)("span",{className:"text-xs font-medium",children:"Skills"})]})]})})}),(0,r.jsx)(em.lG,{open:tr,onOpenChange:e=>{tn(e),e||tl(null)},children:(0,r.jsxs)(em.Cf,{className:"p-0 max-w-6xl h-[90vh] overflow-hidden",children:[(0,r.jsx)(ex.s6,{children:(0,r.jsx)(em.L3,{children:"Integrations"})}),(0,r.jsx)(eu,{showAgentSelector:!0,selectedAgentId:A,onAgentChange:E,onToolsSelected:(e,t,s,r)=>{},initialSelectedApp:ta,isBlocked:tH,onBlockedClick:()=>tm(!0)})]})}),(0,r.jsx)(ep.PlanSelectionModal,{open:tu,onOpenChange:tm}),A&&tx.open&&(0,r.jsx)(ef.AgentConfigurationDialog,{open:tx.open,onOpenChange:e=>th({...tx,open:e}),agentId:A,initialTab:tx.tab,onAgentChange:E}),A&&(0,r.jsx)(ez.x,{open:tg,onOpenChange:tp,agentId:A,onNavigateToIntegrations:()=>th({open:!0,tab:"knowledge"})})]})]})})}));eG.displayName="ChatInput"},25796:(e,t,s)=>{s.d(t,{N:()=>r});let r=(0,s(67211).v)((e,t)=>({queuedMessages:[],queueMessage:(t,s,r)=>{let n="queued-".concat(Date.now(),"-").concat(Math.random().toString(36).substr(2,9)),a={id:n,threadId:t,message:s,options:r,timestamp:Date.now()};return console.log("[MessageQueueStore] Queueing message:",a),e(e=>({queuedMessages:[...e.queuedMessages,a]})),n},removeMessage:t=>{console.log("[MessageQueueStore] Removing message:",t),e(e=>({queuedMessages:e.queuedMessages.filter(e=>e.id!==t)}))},clearQueue:t=>{console.log("[MessageQueueStore] Clearing queue for thread:",t),t?e(e=>({queuedMessages:e.queuedMessages.filter(e=>e.threadId!==t)})):e({queuedMessages:[]})},getMessagesForThread:e=>t().queuedMessages.filter(t=>t.threadId===e),moveUp:(t,s)=>{e(e=>{let r=e.queuedMessages.filter(e=>e.threadId===s),n=e.queuedMessages.filter(e=>e.threadId!==s),a=r.findIndex(e=>e.id===t);if(a<=0)return e;let l=[...r];return[l[a-1],l[a]]=[l[a],l[a-1]],{queuedMessages:[...n,...l]}})},moveDown:(t,s)=>{e(e=>{let r=e.queuedMessages.filter(e=>e.threadId===s),n=e.queuedMessages.filter(e=>e.threadId!==s),a=r.findIndex(e=>e.id===t);if(a<0||a>=r.length-1)return e;let l=[...r];return[l[a],l[a+1]]=[l[a+1],l[a]],{queuedMessages:[...n,...l]}})}}))},27471:(e,t,s)=>{s.d(t,{HS:()=>l,K1:()=>i,e1:()=>c,qe:()=>
1o,r$:()=>d,xi:()=>u});var r=s(67211),n=s(16699);let a=(0,r.v)()((0,n.Zr)((e,t)=>({selectedAgentId:void 0,hasInitialized:!1,setSelectedAgent:t=>{e({selectedAgentId:t})},initializeFromAgents:(s,r,n)=>{let a;if(!t().hasInitialized){if(r)a=r;else if(1){let e=new URLSearchParams(window.location.search).get("agent_id");e&&(a=e)}if(!a){let e=t().selectedAgentId;if(e&&s.some(t=>t.agent_id===e))a=e;else if(s.length>0){let e=s.find(e=>{var t;return null==(t=e.metadata)?void 0:t.is_rgo_default});a=e?e.agent_id:s[0].agent_id}}a&&e({selectedAgentId:a}),a&&n&&n(a),e({hasInitialized:!0})}},autoSelectAgent:(t,s,r)=>{if(0===t.length||r)return;let n=t.find(e=>{var t;return null==(t=e.metadata)?void 0:t.is_rgo_default})||t[0];n&&(s?s(n.agent_id):e({selectedAgentId:n.agent_id}))},clearSelection:()=>{e({selectedAgentId:void 0,hasInitialized:!1})},getCurrentAgent:e=>{let{selectedAgentId:s}=t();return s&&e.find(e=>e.agent_id===s)||null},isRgoAgent:e=>{var s;let{selectedAgentId:r}=t(),n=r?e.find(e=>e.agent_id===r):null;return(null==n||null==(s=n.metadata)?void 0:s.is_rgo_default)||void 0===r}}),{name:"agent-selection-storage",partialize:e=>({selectedAgentId:e.selectedAgentId})})),l=()=>a(e=>e.selectedAgentId),i=()=>a(e=>e.setSelectedAgent),o=()=>a(e=>e.initializeFromAgents),c=()=>a(e=>e.getCurrentAgent),d=()=>a(e=>e.isRgoAgent),u=()=>{let e=a();return{selectedAgentId:e.selectedAgentId,hasInitialized:e.hasInitialized,setSelectedAgent:e.setSelectedAgent,initializeFromAgents:e.initializeFromAgents,autoSelectAgent:e.autoSelectAgent,clearSelection:e.clearSelection,getCurrentAgent:e.getCurrentAgent,isRgoAgent:e.isRgoAgent}}},28109:(e,t,s)=>{s.d(t,{EK:()=>l,py:()=>i});var r=s(67211),n=s(16699);let a=(0,r.v)()((0,n.Zr)(e=>({godModeEnabled:!0,setGodModeEnabled:t=>{e({godModeEnabled:t})},toggleGodMode:()=>{e(e=>({godModeEnabled:!e.godModeEnabled}))}}),{name:"god-mode-storage",partialize:e=>({godModeEnabled:e.godModeEnabled})})),l=()=>a(e=>e.godModeEnabled),i=()=>a(e=>e.toggleGodMode)},33835:(e,t,s)=>{s.r(t),s.d(t,{AgentConfigurationDialog:()=>eA});var r=s(78542),n=s(18558),a=s(15253),l=s(14333),i=s(47358),o=s(73511),c=s(34298),d=s(72842),u=s(7424),m=s(63505),x=s(36217),h=s(42061),g=s(33591),p=s(32035),f=s(27496),v=s(70885),j=s(41894),b=s(29798),y=s(36987),N=s(72409),w=s(57570),k=s(47155),_=s(31294),C=s(39164),S=s(84163),A=s(87107),I=s(40570),E=s(19240);let F=e=>{let{agentId:t,agentName:s}=e;return(0,r.jsx)(E.J,{agentId:t,agentName:s,showHeader:!0,showRecentFiles:!1,enableAssignments:!0,maxHeight:"400px",compact:!0,emptyStateMessage:"Create folders and upload files to provide ".concat(s," with searchable knowledge")})};var z=s(75646),M=s(45778),R=s(73646),D=s(34556),L=s(26835),T=s(13033),P=s(78145);let $=e=>{let{className:t}=e;return(0,r.jsxs)("svg",{className:t,viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[(0,r.jsx)("path",{d:"M5.042 15.165a2.528 2.528 0 0 1-2.52 2.523A2.528 2.528 0 0 1 0 15.165a2.527 2.527 0 0 1 2.522-2.52h2.52v2.52zM6.313 15.165a2.527 2.527 0 0 1 2.521-2.52 2.527 2.527 0 0 1 2.521 2.52v6.313A2.528 2.528 0 0 1 8.834 24a2.528 2.528 0 0 1-2.521-2.522v-6.313z",fill:"#E01E5A"}),(0,r.jsx)("path",{d:"M8.834 5.042a2.528 2.528 0 0 1-2.521-2.52A2.528 2.528 0 0 1 8.834 0a2.527 2.527 0 0 1 2.521 2.522v2.52H8.834zM8.834 6.313a2.527 2.527 0 0 1 2.521 2.521 2.527 2.527 0 0 1-2.521 2.521H2.522A2.528 2.528 0 0 1 0 8.834a2.528 2.528 0 0 1 2.522-2.521h6.312z",fill:"#36C5F0"}),(0,r.jsx)("path",{d:"M18.956 8.834a2.528 2.528 0 0 1 2.521-2.521A2.528 2.528 0 0 1 24 8.834a2.527 2.527 0 0 1-2.523 2.521h-2.521V8.834zM17.688 8.834a2.527 2.527 0 0 1-2.523 2.521 2.527 2.527 0 0 1-2.52-2.521V2.522A2.528 2.528 0 0 1 15.165 0a2.528 2.528 0 0 1 2.523 2.522v6.312z",fill:"#2EB67D"}),(0,r.jsx)("path",{d:"M15.165 18.956a2.528 2.528 0 0 1 2.523 2.521A2.528 2.528 0 0 1 15.165 24a2.527 2.527 0 0 1-2.52-2.523v-2.521h2.52zM15.165 17.688a2.527 2.527 0 0 1-2.52-2.523 2.527 2.527 0 0 1 2.52-2.52h6.313A2.528 2.528 0 0 1 24 15.165a2.528 2.528 0 0 1-2.522 2.523h-6.313z",fill:"#ECB22E"})]})};var U=s(34212),O=s(84499);let Z=e=>{let{triggers:t,onEdit:s,onRemove:a,onToggle:l,isLoading:i=!1}=e,[o,c]=n.useState(!1),[u,m]=n.useState(null);return(0,r.jsxs)(L.Bc,{children:[(0,r.jsx)("div",{className:"space-y-2",children:t.map(e=>(0,r.jsxs)("div",{className:"flex items-stretch justify-between p-3 rounded-lg border transition-all duration-200 overflow-hidden ".concat(e.is_active?"bg-card hover:bg-muted/50 border-border":"bg-muted/20 hover:bg-muted/30 border-muted-foreground
1/30"),children:[(0,r.jsxs)("div",{className:"flex items-stretch space-x-3 flex-1 min-w-0",children:[(0,r.jsx)("div",{className:"h-7 min-h-7 max-h-7 w-7 rounded-md border transition-colors flex-shrink-0 flex items-center justify-center ".concat(e.is_active?"bg-muted border-border":"bg-muted/50 border-muted-foreground/20"," ").concat(e.is_active?"":"opacity-70"),children:(e=>{switch(e){case"telegram":return(0,r.jsx)(P.default,{className:"h-5 w-5",color:"#0088cc"});case"slack":return(0,r.jsx)($,{className:"h-5 w-5"});case"webhook":return(0,r.jsx)(U.default,{className:"h-5 w-5"});case"schedule":return(0,r.jsx)(O.default,{className:"h-5 w-5",color:"#6F7D4F"});default:return(0,r.jsx)(z.default,{className:"h-5 w-5"})}})(e.trigger_type)}),(0,r.jsxs)("div",{className:"flex-1 min-w-0 overflow-hidden",children:[(0,r.jsxs)("div",{className:"flex items-center space-x-1.5 mb-0.5",children:[(0,r.jsx)("h4",{className:"text-xs font-medium truncate transition-colors ".concat(e.is_active?"text-foreground":"text-muted-foreground"),children:e.name}),(0,r.jsxs)(L.m_,{children:[(0,r.jsx)(L.k$,{asChild:!0,children:(0,r.jsx)("div",{className:(0,N.cn)("h-2 w-2 rounded-full",e.is_active?"bg-green-500":"bg-red-500")})}),(0,r.jsx)(L.ZI,{children:(0,r.jsx)("p",{children:e.is_active?"Active":"Inactive"})})]})]}),e.description&&(0,r.jsx)("p",{className:"text-xs truncate text-muted-foreground",children:(0,N.W5)(e.description,50)}),"schedule"===e.trigger_type&&e.config&&e.config.agent_prompt&&(0,r.jsx)("div",{className:"text-xs mt-0.5 text-muted-foreground",children:(0,r.jsxs)("p",{children:["Prompt: ",(0,N.W5)(e.config.agent_prompt,40)]})})]})]}),(0,r.jsxs)("div",{className:"flex items-center space-x-2 flex-shrink-0",children:[(0,r.jsxs)(L.m_,{children:[(0,r.jsx)(L.k$,{asChild:!0,children:(0,r.jsx)("div",{className:"flex items-center",children:(0,r.jsx)(M.d,{checked:e.is_active,onCheckedChange:()=>l(e),disabled:i})})}),(0,r.jsx)(L.ZI,{children:(0,r.jsxs)("p",{children:[e.is_active?"Disable":"Enable"," trigger"]})})]}),(0,r.jsxs)(L.m_,{children:[(0,r.jsx)(L.k$,{asChild:!0,children:(0,r.jsx)(d.$,{size:"sm",variant:"ghost",onClick:()=>s(e),className:"h-7 w-7 p-0 transition-opacity ".concat(e.is_active?"":"opacity-70"),disabled:i,children:(0,r.jsx)(R.default,{className:"h-3.5 w-3.5"})})}),(0,r.jsx)(L.ZI,{children:(0,r.jsx)("p",{children:"Edit trigger"})})]}),(0,r.jsxs)(L.m_,{children:[(0,r.jsx)(L.k$,{asChild:!0,children:(0,r.jsx)(d.$,{size:"sm",variant:"ghost",onClick:()=>{m(e),c(!0)},className:"h-7 w-7 p-0 text-destructive hover:text-destructive transition-opacity ".concat(e.is_active?"":"opacity-70"),disabled:i,children:(0,r.jsx)(D.default,{className:"h-3.5 w-3.5"})})}),(0,r.jsx)(L.ZI,{children:(0,r.jsx)("p",{children:"Delete trigger"})})]})]})]},e.trigger_id))}),(0,r.jsx)(T.Lt,{open:o,onOpenChange:c,children:(0,r.jsxs)(T.EO,{children:[(0,r.jsxs)(T.wd,{children:[(0,r.jsx)(T.r7,{children:"Delete Trigger"}),(0,r.jsxs)(T.$v,{children:['Are you sure you want to delete "',null==u?void 0:u.name,'"? This action cannot be undone and will stop all automated runs from this trigger.']})]}),(0,r.jsxs)(T.ck,{children:[(0,r.jsx)(T.Zr,{children:"Cancel"}),(0,r.jsx)(T.Rx,{onClick:()=>{u&&(a(u),m(null),c(!1))},className:"bg-destructive hover:bg-destructive/90 text-white",children:"Delete Trigger"})]})]})})]})};var q=s(33712),B=s(76195),W=s(41936),V=s(42458),H=s(82202),K=s(32640);let G={schedule:{name:"Create Schedule Trigger",icon:(0,r.jsx)(O.default,{className:"h-3.5 w-3.5",color:"#6F7D4F"}),isOAuth:!1}},J=e=>{var t,s,a,l,i;let{agentId:o}
1=e,[c,u]=(0,n.useState)(!1),[m,x]=(0,n.useState)(!1),{data:h}=(0,w.u4)(),{openPricingModal:g}=(0,k.s)(),p=h&&((null==(t=h.subscription)?void 0:t.tier_key)==="free"||(null==(s=h.tier)?void 0:s.name)==="free"),f=null==h||null==(a=h.limits)?void 0:a.trigger_count,v=p&&(null==f||null==(l=f.app)?void 0:l.limit)===0&&(null==f||null==(i=f.scheduled)?void 0:i.limit)===0,[j,N]=(0,n.useState)({cron_expression:"",timezone:Intl.DateTimeFormat().resolvedOptions().timeZone}),[_,C]=(0,n.useState)(""),[S,A]=(0,n.useState)(""),[I,E]=(0,n.useState)(!0),{data:F=[]}=(0,B.aC)(o),M=(0,H.ol)(),R=(0,H.Lp)(),D=(0,B.A$)(),T=(0,B.Dz)(),{handleCallback:P}=(0,H.CA)();(0,n.useEffect)(()=>{P()},[]);let $=async e=>{if("schedule"===e){N({cron_expression:"",timezone:Intl.DateTimeFormat().resolvedOptions().timeZone}),C(""),A(""),E(!0),u(!0);return}try{await M.mutateAsync({agent_id:o,provider:e})}catch(t){console.error("Error installing ".concat(e,":"),t)}},U=async(e,t)=>{if("schedule"===e&&t){try{await T.mutateAsync({triggerId:t,agentId:o}),y.o.success("Schedule trigger removed successfully")}catch(e){y.o.error("Failed to remove schedule trigger"),console.error("Error removing schedule trigger:",e)}return}try{await R.mutateAsync(t)}catch(e){console.error("Error uninstalling integration:",e)}},O=async e=>{try{await D.mutateAsync({agentId:o,provider_id:"schedule",name:e.name||"Scheduled Trigger",description:e.description||"Automatically scheduled trigger",config:{...e.config,is_active:e.is_active}}),y.o.success("Schedule trigger created successfully"),u(!1)}catch(e){y.o.error(e.message||"Failed to create schedule trigger"),console.error("Error creating schedule trigger:",e)}},Z=e=>{if("schedule"===e)return F.find(e=>"schedule"===e.trigger_type)};return(0,r.jsx)(L.Bc,{children:(0,r.jsxs)("div",{className:"space-y-3",children:[(0,r.jsxs)("div",{className:"flex flex-wrap gap-2",children:[Object.entries(G).map(e=>{let[t,s]=e,n=!!Z(t),a=M.isPending||R.isPending||"schedule"===t&&(D.isPending||T.isPending),l=(e=>{let t=Z(e);return null==t?void 0:t.trigger_id})(t),i="schedule"===t?s.name:n?"Disconnect ".concat(s.name):"Connect ".concat(s.name);return v&&"schedule"===t?(0,r.jsxs)(L.m_,{children:[(0,r.jsx)(L.k$,{asChild:!0,children:(0,r.jsx)("div",{className:"relative",children:(0,r.jsxs)(d.$,{variant:"outline",size:"sm",disabled:!0,className:"h-7 text-xs flex items-center opacity-50 cursor-not-allowed",children:[(0,r.jsx)(W.default,{className:"h-3.5 w-3.5 mr-1.5"}),i]})})}),(0,r.jsx)(L.ZI,{children:(0,r.jsx)("p",{className:"text-xs",children:"UPGRADE for time-based automation"})})]},t):(0,r.jsxs)(d.$,{variant:"outline",size:"sm",onClick:()=>{"schedule"===t?$(t):n?U(t,l):$(t)},disabled:a,className:"h-7 text-xs flex items-center",children:[a?(0,r.jsx)(b.RgoLoader,{customSize:14,className:"mr-1.5"}):s.icon,i]},t)}),v?(0,r.jsxs)(L.m_,{children:[(0,r.jsx)(L.k$,{asChild:!0,children:(0,r.jsx)("div",{className:"relative",children:(0,r.jsxs)(d.$,{variant:"default",size:"sm",disabled:!0,className:"h-7 text-xs flex items-center gap-1.5 opacity-50 cursor-not-allowed",children:[(0,r.jsx)(W.default,{className:"h-3.5 w-3.5"}),"App-based Trigger"]})})}),(0,r.jsx)(L.ZI,{children:(0,r.jsx)("p",{className:"text-xs",children:"UPGRADE for event-based automation (email, CRM, etc.)"})})]}):(0,r.jsxs)(d.$,{variant:"default",size:"sm",onClick:()=>x(!0),className:"h-7 text-xs flex items-center gap-1.5",children:[(0,r.jsx)(z.default,{className:"h-3.5 w-3.5"})," App-based Trigger"]})]}),v&&(0,r.jsx)("div",{className:"relative overflow-hidden rounded-lg border border-primary/30 bg-gradient-to-br from-primary/10 via-primary/5 to-transparent p-3 cursor-pointer hover:border-primary/50 hover:from-primary/15 transition-all group",onClick:()=>g(),children:(0,r.jsxs)("div",{className:"flex items-start gap-2.5",children:[(0,r.jsx)("div",{className:"flex items-center justify-center w-8 h-8 rounded-lg bg-primary/15 border border-primary/20 flex-shrink-0 group-hover:bg-primary/20 transition-colors",children:(0,r.jsx)(z.default,{className:"h-4 w-4 text-primary"})}),(0,r.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,r.jsx)("p",{className:"text-xs font-medium text-foreground mb-0.5",children:"Unlock Automation"}),(0,r.jsx)("p",{className:"text-xs text-muted-foreground leading-relaxed",children:"Run your AI Agents on autopilot with scheduled tasks and app-based triggers"})]}),(0,r.jsx)(d.$,{size:"sm",className:"text-xs h-7 flex-shrink-0",children:"Upgrade"})]})}),(0,r.jsx)(K.i,{open:m,onOpenChange:x,agentId:o}),(0,r.jsx)(V.u,{provider:{provider_id:"schedule",name:"Schedule",trigger_type:"schedule",webhook_enabled:!0,config_schema:{}},config:j,onChange:e=>{N(e)},errors:{},agentId:o,name:_,description:S,onNameChange:C,onDescriptionChange:A,isActive:I,onActiveChange:E,open:c,onOpenChange:u,onSave:O})]})})},Q=e=>{let{agentId:t}
1=e,[s,a]=(0,n.useState)(null),[l,i]=(0,n.useState)(null),{data:o=[],isLoading:c,error:d}=(0,B.aC)(t),{data:u=[]}=(0,B.Gj)(),m=(0,B.A$)(),x=(0,B.vg)(),h=(0,B.Dz)(),g=(0,B.ct)(),p=async e=>{try{await h.mutateAsync({triggerId:e.trigger_id,agentId:e.agent_id}),y.o.success("Task deleted successfully")}catch(e){y.o.error("Failed to delete trigger"),console.error("Error deleting trigger:",e)}},f=async e=>{try{l?(await x.mutateAsync({triggerId:l.trigger_id,name:e.name,description:e.description,config:e.config,is_active:e.is_active}),y.o.success("Trigger updated successfully")):(await m.mutateAsync({agentId:t,provider_id:s.provider_id,name:e.name,description:e.description,config:e.config}),y.o.success("Trigger created successfully"))}catch(e){y.o.error(e.message||"Failed to save trigger"),console.error("Error saving trigger:",e)}a(null),i(null)},v=async e=>{try{await g.mutateAsync({triggerId:e.trigger_id,isActive:!e.is_active}),y.o.success("Trigger ".concat(e.is_active?"disabled":"enabled"))}catch(e){y.o.error("Failed to toggle trigger"),console.error("Error toggling trigger:",e)}};return d?(0,r.jsx)("div",{className:"rounded-xl p-4 border border-destructive/20 bg-destructive/5",children:(0,r.jsxs)("div",{className:"flex items-center space-x-3",children:[(0,r.jsx)("div",{className:"p-1.5 bg-destructive/10 rounded-lg",children:(0,r.jsx)(z.default,{className:"h-4 w-4 text-destructive"})}),(0,r.jsxs)("div",{children:[(0,r.jsx)("h3",{className:"text-sm font-medium text-destructive",children:"Error Loading Triggers"}),(0,r.jsx)("p",{className:"text-xs text-muted-foreground",children:d instanceof Error?d.message:"Failed to load triggers"})]})]})}):(0,r.jsxs)("div",{className:"space-y-3",children:[(0,r.jsx)(J,{agentId:t}),o.length>0&&(0,r.jsx)(Z,{triggers:o,onEdit:e=>{i(e);let t=u.find(t=>t.provider_id===e.provider_id);t?a(t):a({provider_id:e.provider_id,name:e.trigger_type,description:"",trigger_type:e.trigger_type,webhook_enabled:!!e.webhook_url,config_schema:{}})},onRemove:p,onToggle:v,isLoading:h.isPending||g.isPending}),!c&&0===o.length&&(0,r.jsxs)("div",{className:"flex flex-col items-center justify-center py-8 border border-dashed border-border rounded-xl",children:[(0,r.jsx)("div",{className:"flex items-center justify-center w-8 h-8 rounded-lg bg-muted mb-2.5",children:(0,r.jsx)(z.default,{className:"h-4 w-4 text-muted-foreground"})}),(0,r.jsx)("h4",{className:"text-sm font-medium text-muted-foreground",children:"No triggers configured"}),(0,r.jsx)("p",{className:"text-xs text-muted-foreground/60 mt-0.5",children:"Click on a trigger provider above to get started"})]}),s&&(0,r.jsx)(q.Y,{open:!!s,onOpenChange:()=>a(null),type:"schedule"===s.provider_id?"schedule":"event",isEditMode:!!l,existingTrigger:l,onTriggerCreated:f,onTriggerUpdated:f})]})};var X=s(67191),Y=s(7808),ee=s(29302),et=s(66717),es=s(84609);function er(e){let{selectedIcon:t,onIconSelect:s,iconColor:a="#000000",backgroundColor:l="#F4F3F1",className:i}=e,[o,d]=(0,n.useState)(""),u=(0,n.useMemo)(()=>Object.keys(et).map(e=>e.replace(/([a-z0-9])([A-Z])/g,"$1-$2").replace(/([A-Z])([A-Z][a-z])/g,"$1-$2").toLowerCase()).sort(),[]),m=(0,n.useMemo)(()=>{if(!o)return u;let e=o.toLowerCase();return u.filter(t=>t.includes(e)||t.replace(/-/g," ").includes(e))},[u,o]);return(0,r.jsxs)("div",{className:(0,N.cn)("flex flex-col",i),children:[(0,r.jsx)("div",{className:"pb-3 shrink-0",children:(0,r.jsx)(c.p,{type:"text",placeholder:"Search icons...",value:o,onChange:e=>d(e.target.value),className:"w-full"})}),(0,r.jsx)(es.F,{className:"flex-1 rounded-lg border min-h-0",children:(0,r.jsxs)("div",{className:"p-4 space-y-6",children:[!o&&(0,r.jsxs)("div",{className:"space-y-3",children:[(0,r.jsx)("p",{className:"text-xs font-medium text-muted-foreground uppercase tracking-wider",children:"Popular Icons"}),(0,r.jsx)("div",{className:"grid grid-cols-5 sm:grid-cols-8 gap-2",children:["bot","brain","sparkles","zap","rocket","briefcase","code","database","globe","heart","lightbulb","message-circle","shield","star","user","cpu","terminal","settings","wand-2","layers"].map(e=>(0,r.jsx)("button",{onClick:()=>s(e),className:(0,N.cn)("p-3 border transition-all hover:scale-105 flex items-center justify-center aspect-square",t===e?"border-primary ring-2 ring-primary/30":"border-border hover:border-primary/60 hover:bg-accent"),style:{backgroundColor:t===e?l:void 0,borderRadius:"12px"},title:e,children:(0,r.jsx)(ee.A,{name:e,size:24,color:t===e?a:void 0})},e))})]}),(0,r.jsxs)("div",{className:"space-y-3",children:[(0,r.jsx)("p",{className:"text-xs font-medium text-muted-foreground uppercase tracking-wider",children:o?"Search Results (".concat(m.length,")"):"All Icons (".concat(u.length,")")}),0===m.length?(0,r.jsxs)("div",{className:"text-center py-12 text-sm text-muted-foreground",children:[(0,r.jsxs)("p",{children:['No icons foun
1d matching "',o,'"']}),(0,r.jsx)("p",{className:"text-xs mt-2",children:"Try a different search term"})]}):(0,r.jsx)("div",{className:"grid grid-cols-4 sm:grid-cols-8 gap-2",children:m.map(e=>(0,r.jsx)("button",{onClick:()=>s(e),className:(0,N.cn)("p-3 border transition-all hover:scale-105 flex items-center justify-center aspect-square",t===e?"border-primary ring-2 ring-primary/30":"border-border hover:border-primary/60 hover:bg-accent"),style:{backgroundColor:t===e?l:void 0,borderRadius:"12px"},title:e,children:(0,r.jsx)(ee.A,{name:e,size:24,color:t===e?a:void 0})},e))})]})]})})]})}var en=s(92919),ea=s(18906),el=s(51145),ei=s(2576);function eo(e){let{isOpen:t,onClose:s,agentName:a,agentDescription:l,currentIconName:o,currentIconColor:m="#000000",currentBackgroundColor:x="#F3F4F6",onIconUpdate:h}=e,[g,p]=(0,n.useState)(o||"bot"),[f,v]=(0,n.useState)(m||"#000000"),[j,b]=(0,n.useState)(x||"#e5e5e5");(0,n.useEffect)(()=>{t&&console.log("\uD83D\uDD27 AgentIconEditorDialog opened with props:",{agentName:a,currentIconName:o,currentIconColor:m,currentBackgroundColor:x,onIconUpdate:!!h})},[t,a,o,m,x,h]),(0,n.useEffect)(()=>{t&&(p(o||"bot"),v(m||"#000000"),b(x||"#e5e5e5"))},[t,o,m,x]);let y=(0,n.useCallback)(()=>{h&&(h(g,f,j),s())},[g,f,j,h,s]),w=["#000000","#FFFFFF","#C5A381","#8A6A47","#75593C","#A8754F","#D8C4A8","#6F7D4F","#87965E","#2D2926","#F0E7DA","#7E756F","#BA1A1A","#211E1B","#CFC4BD"],k=e=>{let{label:t,color:s,onChange:a}
1=e,[l,i]=(0,n.useState)(!1),[o,u]=(0,n.useState)(!1);return(0,r.jsxs)("div",{className:"space-y-2",children:[(0,r.jsx)(Y.J,{className:"text-sm font-medium",children:t}),(0,r.jsxs)("div",{className:"flex items-center gap-3",children:[(0,r.jsxs)(el.AM,{open:l,onOpenChange:e=>{e&&o||i(e)},children:[(0,r.jsx)(el.Wv,{asChild:!0,children:(0,r.jsx)("button",{type:"button",className:"h-10 w-12 rounded-2xl border cursor-pointer hover:border-primary/50 transition-colors",style:{backgroundColor:s},"aria-label":"".concat(t," color")})}),(0,r.jsx)(el.hl,{className:"w-auto p-3",align:"start",side:"bottom",sideOffset:5,onInteractOutside:e=>{if(o)return void e.preventDefault();let t=e.target;(t.closest('[class*="react-colorful"]')||t.className.includes("react-colorful")||t.closest(".react-colorful-container"))&&e.preventDefault()},children:(0,r.jsxs)("div",{className:"space-y-3",children:[(0,r.jsx)("div",{className:"react-colorful-container",onMouseDown:()=>u(!0),onMouseUp:()=>u(!1),onTouchStart:()=>u(!0),onTouchEnd:()=>u(!1),children:(0,r.jsx)(ei.jI,{color:s,onChange:e=>{a(e)},style:{width:"200px",height:"150px"}})}),(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsx)(c.p,{type:"text",value:s,onChange:e=>{let t=e.target.value;(/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/.test(t)||t.startsWith("#"))&&a(t.toUpperCase())},placeholder:"#000000",className:"font-mono text-sm flex-1",maxLength:7}),(0,r.jsx)(d.$,{size:"sm",variant:"outline",onClick:()=>{u(!1),i(!1)},children:"Done"})]})]})})]}),(0,r.jsx)(c.p,{type:"text",value:s,onChange:e=>{let t=e.target.value;(/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/.test(t)||t.startsWith("#"))&&a(t.toUpperCase())},placeholder:"#000000",className:"font-mono text-sm",maxLength:7})]}),(0,r.jsxs)("div",{className:"space-y-2",children:[(0,r.jsx)(Y.J,{className:"text-xs text-muted-foreground",children:"Presets"}),(0,r.jsx)("div",{className:"grid grid-cols-8 gap-1",children:w.map(e=>(0,r.jsx)("button",{onClick:()=>a(e),className:(0,N.cn)("w-7 h-7 rounded border-2 transition-all hover:scale-110",s===e?"border-primary ring-2 ring-primary/20":"border-transparent"),style:{backgroundColor:e},title:e},e))})]})]})},_=[{bg:"#2D2926",icon:"#FAF9F6",name:"Obsidian"},{bg:"#C5A381",icon:"#2D2926",name:"Gold"},{bg:"#75593C",icon:"#FAF9F6",name:"Brown"},{bg:"#6F7D4F",icon:"#FAF9F6",name:"Olive"},{bg:"#A8754F",icon:"#FAF9F6",name:"Clay"}],C=()=>(0,r.jsxs)("div",{className:"space-y-4",children:[(0,r.jsxs)("div",{className:"flex flex-col items-center space-y-2 py-3",children:[(0,r.jsx)(X.lx,{iconName:g,iconColor:f,backgroundColor:j,agentName:a,size:100,className:"border shadow-lg"}),(0,r.jsx)("div",{className:"text-center",children:(0,r.jsx)("p",{className:"font-medium",children:a||"Agent"})})]}),(0,r.jsxs)("div",{className:"space-y-3",children:[(0,r.jsx)(k,{label:"Icon Color",color:f,onChange:v}),(0,r.jsx)(k,{label:"Background Color",color:j,onChange:b})]}),(0,r.jsxs)("div",{className:"space-y-2",children:[(0,r.jsx)(Y.J,{className:"text-sm font-medium",children:"Quick Themes"}),(0,r.jsx)("div",{className:"grid grid-cols-5 gap-1.5",children:_.map(e=>(0,r.jsxs)("button",{onClick:()=>{v(e.icon),b(e.bg)},className:(0,N.cn)("group relative h-12 w-full rounded-xl border-2 transition-all hover:scale-105",j===e.bg&&f===e.icon?"border-primary shadow-md":"border-border hover:border-primary/60"),style:{backgroundColor:e.bg},title:e.name,children:[(0,r.jsx)("span",{className:"absolute inset-0 flex items-center justify-center",children:(0,r.jsx)(u.default,{className:"w-4 h-4",style:{color:e.icon}})}),(0,r.jsx)("span",{className:"sr-only",children:e.name})]},e.name))})]})]});return(0,r.jsx)(i.lG,{open:t,onOpenChange:s,children:(0,r.jsxs)(i.Cf,{className:"max-w-4xl max-h-[80vh] flex flex-col p-0 gap-0",children:[(0,r.jsx)(i.c7,{className:"px-4 pt-4 pb-3 border-b border-border shrink-0",children:(0,r.jsxs)("div",{className:"flex items-center gap-2.5",children:[(0,r.jsx)("div",{className:"h-8 w-8 rounded-lg bg-muted border border-border flex items-center justify-center",children:(0,r.jsx)(u.default,{className:"h-4 w-4 text-muted-foreground"})}),(0,r.jsxs)("div",{children:[(0,r.jsx)(i.L3,{className:"text-base font-medium",children:"Customize Agent Icon"}),(0,r.jsx)(i.rr,{className:"text-xs mt-0.5",children:"Choose an icon and customize colors"})]})]})}),(0,r.jsx)("div",{className:"hidden md:flex flex-1 min-h-0 px-4",children:(0,r.jsxs)("div",{className:"flex gap-4 w-full",children:[(0,r.jsx)("div",{className:"flex-1 min-w-0",children:(0,r.jsx)(er,{selectedIcon:g,onIconSelect:p,iconColor:f,backgroundColor:j,className:"h-full"})}),(0,r.jsx)(en.w,{orientation:"vertical",className:"h-full"}),(0,r.jsx)("div",{className:"w-72 shrink-0 flex flex-col h-full",children:(0,r.jsx)("div",{className:"flex-1 overflow-y-auto pr-3",children:(0,r.jsx)(C,{})})})]})}),(0,r.jsx)("div",{className:"md:hidden flex-1 min-h-0 px-4",children:(0,r.jsxs)(ea.tU,{defaultValue:"customize",className:"h-full flex flex-col",children:[(0,r.jsxs)(ea.j7,{className:"grid w-full grid-cols-2 shrink-0",children:[(0,r.jsx)(ea.Xi,{value:"customize",children:"Customize"}),(0,r.jsx)(ea.Xi,{value:"icons",children:"Icons"})]}),(0,r.jsx)(ea.av,{value:"customize",className:"flex-1 min-h-0 mt-4",children:(0,r.jsx)(es.F,{className:"h-[400px]",children:(0,r.jsx)(C,{})})}),(0,r.jsx)(ea.av,{value:"icons",className:"flex-1 min-h-0 mt-4",children:(0,r.jsx)(er,{selectedIcon:g,onIconSelect:p,iconColor:f,backgroundColor:j,className:"h-[400px]"})})]})}),(0,r.jsx)("div",{className:"flex items-center justify-end px-4 py-3 shrink-0 border-t border-border bg-muted/30",children:(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsx)(d.$,{variant:"outline",size:"sm",onClick:s,children:"Cancel"}),(0,r.jsx)(d.$,{size:"sm",onClick:y,children:"Save Icon"})]})})]})})}var ec=s(87656),ed=s(32904),eu=s(77475),em=s(65920),ex=s(54163),eh=s(75277),eg=s(59652),ep=s(19058);function ef(e){let{agentId:t,versionId:s,versionName:a,changeDescription:l,isActive:i=!1,onUpdate:o}
1=e,[u,h]=(0,n.useState)(!1),[g,p]=(0,n.useState)(a),[f,v]=(0,n.useState)(l||""),[j,y]=(0,n.useState)(!1),w=(0,ex.J$)();(0,n.useEffect)(()=>{let e=f!==(l||"");y(g!==a||e)},[g,f,a,l]);let k=()=>{h(!1),p(a),v(l||""),y(!1)},_=async()=>{if(!j)return void h(!1);try{let e={};g!==a&&(e.version_name=g),f!==(l||"")&&(e.change_description=f),await w.mutateAsync({agentId:t,versionId:s,data:e}),h(!1),null==o||o({versionName:g,changeDescription:f})}catch(e){console.error("Failed to update version:",e)}},C=e=>{"Escape"===e.key?k():"Enter"===e.key&&e.metaKey&&_()};return u?(0,r.jsxs)("div",{className:"space-y-2",onClick:e=>e.stopPropagation(),children:[(0,r.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,r.jsx)(c.p,{value:g,onChange:e=>p(e.target.value),onKeyDown:C,placeholder:"Version name",className:"flex-1 h-7 text-xs",autoFocus:!0}),(0,r.jsxs)("div",{className:"flex items-center gap-0.5",children:[(0,r.jsx)(d.$,{size:"sm",variant:"ghost",onClick:e=>{e.stopPropagation(),_()},disabled:!j||w.isPending,className:"h-6 w-6 p-0",children:w.isPending?(0,r.jsx)(b.RgoLoader,{customSize:12}):(0,r.jsx)(m.default,{className:"h-3 w-3"})}),(0,r.jsx)(d.$,{size:"sm",variant:"ghost",onClick:e=>{e.stopPropagation(),k()},disabled:w.isPending,className:"h-6 w-6 p-0",children:(0,r.jsx)(x.default,{className:"h-3 w-3"})})]})]}),(0,r.jsx)(eg.T,{value:f,onChange:e=>v(e.target.value),onKeyDown:C,placeholder:"Change description (optional)",className:"min-h-[48px] resize-none text-xs"}),(0,r.jsx)("div",{className:"text-[10px] text-muted-foreground",children:"Escape to cancel, Cmd+Enter to save"})]}):(0,r.jsxs)("div",{className:"group space-y-0.5",children:[(0,r.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,r.jsx)("span",{className:(0,N.cn)("text-xs font-medium",i&&"text-primary"),children:a}),(0,r.jsx)(d.$,{size:"sm",variant:"ghost",onClick:e=>{e.stopPropagation(),h(!0),p(a),v(l||"")},className:"h-5 w-5 p-0 opacity-0 group-hover:opacity-100 transition-opacity",children:(0,r.jsx)(ep.default,{className:"h-2.5 w-2.5"})})]}),l&&(0,r.jsx)("p",{className:"text-[10px] text-muted-foreground line-clamp-1",children:l})]})}function ev(e){let{agentId:t,currentVersionId:s,currentFormData:l}=e,i=(0,a.useRouter)(),c=(0,a.useSearchParams)(),u=c.get("version"),{data:x,isLoading:h}=(0,ex.aA)(t);(0,ex.Ic)(),(0,ex.bW)();let[g,p]=(0,n.useState)(!1),[f,v]=(0,n.useState)(null),[j,N]=(0,n.useState)(!1),w=u||s,k=(null==x?void 0:x.find(e=>e.version_id===w))||(null==x?void 0:x[0]);k&&k.version_number;let _=async e=>{if(e.version_id===w)return;let t=new URLSearchParams(c.toString());e.version_id===s?t.delete("version"):t.set("version",e.version_id);let r=t.toString()?"?".concat(t.toString()):window.location.pathname;i.push(r),e.version_id!==s&&y.o.success("Viewing ".concat(e.version_name," (read-only)"))};return h?(0,r.jsx)("div",{className:"flex items-center gap-1.5 px-2 py-1.5",children:(0,r.jsx)(b.RgoLoader,{customSize:14})}):x&&0!==x.length?(0,r.jsx)(r.Fragment,{children:(0,r.jsx)(L.Bc,{children:(0,r.jsxs)(o.rI,{children:[(0,r.jsxs)(L.m_,{children:[(0,r.jsx)(L.k$,{asChild:!0,children:(0,r.jsx)(o.ty,{asChild:!0,children:(0,r.jsxs)(d.$,{variant:"ghost",size:"icon",className:"h-7 w-7 relative",children:[(0,r.jsx)(ec.default,{className:"h-3.5 w-3.5"}),w===s&&(0,r.jsx)("div",{className:"absolute -top-1 -right-1 h-2 w-2 rounded-full bg-green-500"})]})})}),(0,r.jsx)(L.ZI,{children:(0,r.jsx)("p",{children:k?"".concat(k.version_name).concat(w===s?" (Current)":""):"Version History"})})]}),(0,r.jsxs)(o.SQ,{align:"start",className:"w-64",children:[(0,r.jsx)(o.lp,{className:"text-xs text-muted-foreground py-1.5",children:"Version History"}),(0,r.jsx)(o.mB,{}),(0,r.jsx)("div",{className:"max-h-72 overflow-y-auto",children:x.map(e=>{let n=e.version_id===w,a=e.version_id===s;return(0,r.jsx)("div",{className:"relative mb-0.5",children:(0,r.jsx)("div",{className:"px-2 py-1.5 hover:bg-accent rounded-sm ".concat(n?"bg-accent":""),children:(0,r.jsxs)("div",{className:"flex items-start justify-between w-full",children:[(0,r.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,r.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,r.jsx)("div",{className:"flex-1 cursor-pointer min-w-0",onClick:()=>_(e),children:(0,r.jsx)(ef,{agentId:t,versionId:e.version_id,versionName:e.version_name,changeDescription:e.change_description,isActive:a})}),a&&(0,r.jsx)(eu.E,{variant:"default",className:"text-[10px] px-1.5 py-0",children:"Current"}
1),n&&!a&&(0,r.jsx)(eu.E,{variant:"outline",className:"text-[10px] px-1.5 py-0",children:"Viewing"})]}),(0,r.jsxs)("div",{className:"flex items-center gap-1.5 mt-0.5 cursor-pointer",onClick:()=>_(e),children:[(0,r.jsx)(O.default,{className:"h-2.5 w-2.5 text-muted-foreground"}),(0,r.jsx)("span",{className:"text-[10px] text-muted-foreground",children:(0,eh.m)(new Date(e.created_at),{addSuffix:!0})})]})]}),n&&(0,r.jsx)(m.default,{className:"h-3.5 w-3.5 text-primary ml-1.5"})]})})},e.version_id)})}),1===x.length&&(0,r.jsxs)(em.Fc,{children:[(0,r.jsx)(ed.default,{className:"h-3.5 w-3.5"}),(0,r.jsx)(em.TN,{className:"text-xs",children:"This is the first version. Make changes to create a new version."})]})]})]})})}):null}var ej=s(80195),eb=s(34215),ey=s(35726),eN=s(25414),ew=s(44e3),ek=s(68432),e_=s(3091);let eC=[{value:"on_run_start",label:"Run Start"},{value:"on_run_end",label:"Run End"},{value:"pre_tool_call",label:"Pre Tool Call"},{value:"post_tool_call",label:"Post Tool Call"},{value:"on_turn_start",label:"Turn Start"},{value:"on_turn_end",label:"Turn End"},{value:"on_message_received",label:"Message Received"}];function eS(e){let{agentId:t}
1=e,s=(0,l.jE)(),[a,i]=(0,n.useState)(!1),[o,u]=(0,n.useState)({event_type:"on_run_start",handler_type:"prompt",prompt:"",webhook_url:"",can_block:!1}),{data:m,isLoading:x}=(0,ek.I)({queryKey:["agent-hooks",t],queryFn:async()=>{var e,s;return null!=(s=null==(e=(await (0,e_.g7)(t)).data)?void 0:e.data)?s:[]},enabled:!!t}),h=(0,A.n)({mutationFn:async()=>{var e;let s="prompt"===o.handler_type?{prompt:o.prompt}:{url:o.webhook_url,timeout_ms:5e3},r=await (0,e_.f5)(t,{event_type:o.event_type,handler_type:o.handler_type,handler_config:s,can_block:o.can_block&&"pre_tool_call"===o.event_type});if(!r.success)throw null!=(e=r.error)?e:Error("Failed to create hook");return r.data},onSuccess:()=>{s.invalidateQueries({queryKey:["agent-hooks",t]}),i(!1),u({event_type:"on_run_start",handler_type:"prompt",prompt:"",webhook_url:"",can_block:!1}),y.o.success("Hook registered")},onError:()=>y.o.error("Failed to create hook")}),g=(0,A.n)({mutationFn:async e=>{var s;let r=await (0,e_.Mt)(t,e);if(!r.success)throw null!=(s=r.error)?s:Error("Failed to delete hook")},onSuccess:()=>{s.invalidateQueries({queryKey:["agent-hooks",t]}),y.o.success("Hook removed")}}),p=(0,A.n)({mutationFn:async e=>{var s;let{hookId:r,isActive:n}=e,a=await (0,e_.Cp)(t,r,{is_active:n});if(!a.success)throw null!=(s=a.error)?s:Error("Failed to toggle hook")},onSuccess:()=>{s.invalidateQueries({queryKey:["agent-hooks",t]})}}),f=(null!=m?m:[]).reduce((e,t)=>(e[t.event_type]||(e[t.event_type]=[]),e[t.event_type].push(t),e),{});return(0,r.jsxs)("div",{className:"p-4 space-y-3",children:[(0,r.jsxs)("div",{className:"flex items-center justify-between",children:[(0,r.jsxs)("div",{children:[(0,r.jsx)("h3",{className:"text-xs font-medium",children:"Lifecycle Hooks"}),(0,r.jsx)("p",{className:"text-xs text-muted-foreground mt-0.5",children:"Hooks run at specific points during agent execution"})]}),(0,r.jsxs)(d.$,{variant:"outline",size:"sm",className:"h-7 text-xs",onClick:()=>i(!0),children:[(0,r.jsx)(ej.default,{className:"h-3 w-3 mr-1"}),"Add Hook"]})]}),a&&(0,r.jsx)(ew.Zp,{children:(0,r.jsxs)(ew.Wu,{className:"p-2.5 space-y-2.5",children:[(0,r.jsxs)("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-2.5",children:[(0,r.jsxs)("div",{children:[(0,r.jsx)(Y.J,{className:"text-xs",children:"Event Type"}),(0,r.jsxs)(eN.l6,{value:o.event_type,onValueChange:e=>u(t=>({...t,event_type:e})),children:[(0,r.jsx)(eN.bq,{className:"h-7 text-xs mt-1 w-full border-border",children:(0,r.jsx)(eN.yv,{})}),(0,r.jsx)(eN.gC,{children:eC.map(e=>(0,r.jsx)(eN.eb,{value:e.value,className:"text-xs",children:e.label},e.value))})]})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(Y.J,{className:"text-xs",children:"Handler Type"}),(0,r.jsxs)(eN.l6,{value:o.handler_type,onValueChange:e=>u(t=>({...t,handler_type:e})),children:[(0,r.jsx)(eN.bq,{className:"h-7 text-xs mt-1 w-full border-border",children:(0,r.jsx)(eN.yv,{})}),(0,r.jsxs)(eN.gC,{children:[(0,r.jsx)(eN.eb,{value:"prompt",className:"text-xs",children:"Prompt Injection"}),(0,r.jsx)(eN.eb,{value:"webhook",className:"text-xs",children:"Webhook"})]})]})]})]}),"prompt"===o.handler_type?(0,r.jsxs)("div",{children:[(0,r.jsx)(Y.J,{className:"text-xs",children:"Prompt"}),(0,r.jsx)(eg.T,{value:o.prompt,onChange:e=>u(t=>({...t,prompt:e.target.value})),placeholder:"Before executing, verify that all parameters are safe...",className:"text-xs md:text-xs mt-1 min-h-[56px] border-border",rows:2})]}):(0,r.jsxs)("div",{children:[(0,r.jsx)(Y.J,{className:"text-xs",children:"Webhook URL"}),(0,r.jsx)(c.p,{value:o.webhook_url,onChange:e=>u(t=>({...t,webhook_url:e.target.value})),placeholder:"https://example.com/hook",className:"h-7 text-xs mt-1"})]}),"pre_tool_call"===o.event_type&&(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsx)(M.d,{checked:o.can_block,onCheckedChange:e=>u(t=>({...t,can_block:e}))}),(0,r.jsx)(Y.J,{className:"text-xs",children:"Can block tool execution"})]}),(0,r.jsxs)("div",{className:"flex justify-end gap-2",children:[(0,r.jsx)(d.$,{variant:"ghost",size:"sm",className:"h-7 text-xs",onClick:()=>i(!1),children:"Cancel"}),(0,r.jsxs)(d.$,{size:"sm",className:"h-7 text-xs",onClick:()=>h.mutate(),disabled:h.isPending,children:[h.isPending&&(0,r.jsx)(eb.default,{className:"h-3 w-3 mr-1 animate-spin"}),"Register Hook"]})]})]})}),x?(0,r.jsx)("div",{className:"text-xs text-muted-foreground py-6 text-center",children:"Loading hooks..."}):Object.keys(f).length>0?(0,r.jsx)("div",{className:"space-y-3",children:Object.entries(f).map(e=>{var t;let[s,n]=e;return(0,r.jsxs)("div",{className:"space-y-1.5",children:[(0,r.jsx)("h4",{className:"text-[10px] font-medium text-muted-foreground uppercase tracking-wider",children:(null==(t=eC.find(e=>e.value===s))?void 0:t.label)||s}),n.map(e=>{var t,s,n;
1return(0,r.jsx)(ew.Zp,{children:(0,r.jsxs)(ew.Wu,{className:"p-2.5 flex items-center justify-between gap-2.5",children:[(0,r.jsxs)("div",{className:"flex items-center gap-2 min-w-0",children:["webhook"===e.handler_type?(0,r.jsx)(U.default,{className:"h-3.5 w-3.5 text-muted-foreground flex-shrink-0"}):(0,r.jsx)(ey.default,{className:"h-3.5 w-3.5 text-muted-foreground flex-shrink-0"}),(0,r.jsxs)("div",{className:"min-w-0",children:[(0,r.jsx)("span",{className:"text-xs font-medium",children:"webhook"===e.handler_type?"Webhook":"Prompt"}),(0,r.jsx)("p",{className:"text-[10px] text-muted-foreground truncate",children:"webhook"===e.handler_type?null==(t=e.handler_config)?void 0:t.url:null==(n=e.handler_config)||null==(s=n.prompt)?void 0:s.slice(0,80)})]})]}),(0,r.jsxs)("div",{className:"flex items-center gap-2 flex-shrink-0",children:[e.can_block&&(0,r.jsx)(eu.E,{variant:"secondary",className:"text-[10px] px-1.5 py-0",children:"Blocking"}),e.plugin_id&&(0,r.jsx)(eu.E,{variant:"beta",className:"text-[10px] px-1.5 py-0",children:"Plugin"}),(0,r.jsx)(M.d,{checked:e.is_active,onCheckedChange:t=>p.mutate({hookId:e.id,isActive:t})}),!e.plugin_id&&(0,r.jsx)(d.$,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0 text-muted-foreground hover:text-destructive",onClick:()=>g.mutate(e.id),disabled:g.isPending,children:(0,r.jsx)(D.default,{className:"h-3 w-3"})})]})]})},e.id)})]},s)})}):(0,r.jsxs)("div",{className:"flex flex-col items-center justify-center py-8 border border-dashed border-border rounded-xl",children:[(0,r.jsx)("div",{className:"flex items-center justify-center w-8 h-8 rounded-lg bg-muted mb-2.5",children:(0,r.jsx)(U.default,{className:"h-4 w-4 text-muted-foreground"})}),(0,r.jsx)("p",{className:"text-xs font-medium text-muted-foreground",children:"No hooks registered"}),(0,r.jsx)("p",{className:"text-xs text-muted-foreground/60 mt-0.5",children:"Add hooks to run at lifecycle events during agent execution"})]})]})}function eA(e){var t,s,E,z,M,R,D,L,T;let{open:P,onOpenChange:$,agentId:U,initialTab:O="knowledge",onAgentChange:Z}=e,q=(0,a.useRouter)(),B=(0,a.useSearchParams)(),W=(0,l.jE)(),{agent:V,versionData:H,isViewingOldVersion:K,isLoading:G,error:J}=(0,_.fy)({agentId:U}),{data:Y,refetch:ee}=(0,C._F)({},{enabled:!!Z,refetchOnWindowFocus:!0,refetchOnMount:"always"}),et=Array.isArray(null==Y?void 0:Y.agents)?Y.agents:[],es=(0,C.Ae)(),er=(0,S.J)(),en=(0,A.n)({mutationFn:async e=>{let t=await (0,I.getAccessTokenAsync)();if(!t)throw Error("You must be logged in to export agents");let s=await fetch("".concat("https://api.rationalgo.ai/v1","/agents/").concat(e,"/export"),{method:"GET",headers:{"Content-Type":"application/json",Authorization:"Bearer ".concat(t)}});if(!s.ok)throw Error((await s.json().catch(()=>({message:"Unknown error"}))).message||"HTTP ".concat(s.status,": ").concat(s.statusText));return await s.json()},onSuccess:(e,t)=>{let s=new Blob([JSON.stringify(e,null,2)],{type:"application/json"}),r=URL.createObjectURL(s),n=document.createElement("a");n.href=r,n.download="".concat(e.name.replace(/[^a-zA-Z0-9]/g,"_"),"_agent_export.json"),document.body.appendChild(n),n.click(),document.body.removeChild(n),URL.revokeObjectURL(r),y.o.success('Agent "'.concat(e.name,'" exported successfully'))},onError:e=>{console.error("Export error:",e),y.o.error((null==e?void 0:e.message)||"Failed to export Agent")}}),{data:ea}=(0,w.u4)(),{openPricingModal:el}=(0,k.s)(),ei=ea&&((null==(t=ea.subscription)?void 0:t.tier_key)==="free"||(null==(s=ea.tier)?void 0:s.name)==="free");null==ea||null==(E=ea.free_tier_overrides)||E.integrations_enabled;let ec=null==ea||null==(z=ea.limits)?void 0:z.trigger_count,ed=ei&&
1(null==ec||null==(M=ec.app)?void 0:M.limit)===0&&(null==ec||null==(R=ec.scheduled)?void 0:R.limit)===0,eu=["knowledge","triggers"],[em,ex]=(0,n.useState)(eu.includes(O)?O:"knowledge"),[eh,eg]=(0,n.useState)(!1),[ep,ef]=(0,n.useState)(""),[ej,eb]=(0,n.useState)(!1),ey=(0,n.useRef)(null);(0,n.useEffect)(()=>{P&&O&&ex(eu.includes(O)?O:"knowledge")},[P,O]);let[eN,ew]=(0,n.useState)({name:"",system_prompt:"",model:void 0,rgo_base_tools:{},configured_mcps:[],custom_mcps:[],is_default:!1,icon_name:null,icon_color:"#000000",icon_background:"#E4E0D9"}),[ek,e_]=(0,n.useState)(eN),[eC,eA]=(0,n.useState)(!1);(0,n.useEffect)(()=>{if(!V)return;let e=V;H&&(e={...V,...H,icon_name:H.icon_name||V.icon_name,icon_color:H.icon_color||V.icon_color,icon_background:H.icon_background||V.icon_background});let t={name:e.name||"",system_prompt:e.system_prompt||"",model:e.model||void 0,rgo_base_tools:e.rgo_base_tools||{},configured_mcps:e.configured_mcps||[],custom_mcps:e.custom_mcps||[],is_default:e.is_default||!1,icon_name:e.icon_name||null,icon_color:e.icon_color||"#000000",icon_background:e.icon_background||"#E4E0D9"};ew(t),e_(t),ef(e.name||"")},[V,H]);let eI=(null==V||null==(D=V.metadata)?void 0:D.is_rgo_default)||!1,eE=(null==V||null==(L=V.metadata)?void 0:L.is_app_builder_default)||!1;(0,n.useEffect)(()=>{eE&&"knowledge"===em&&ex("triggers")},[eE,em]);let eF=(null==V||null==(T=V.metadata)?void 0:T.restrictions)||{},ez=!K&&!1!==eF.name_editable&&!eI;K||eF.system_prompt_editable,K||eF.tools_editable;let eM=(0,n.useMemo)(()=>JSON.stringify(eN)!==JSON.stringify(ek),[eN,ek]),eR=async()=>{if(eM){eA(!0);try{let e={agentId:U,name:eN.name,system_prompt:eN.system_prompt,rgo_base_tools:eN.rgo_base_tools};void 0!==eN.model&&null!==eN.model&&(e.model=eN.model),void 0!==eN.icon_name&&(e.icon_name=eN.icon_name),void 0!==eN.icon_color&&(e.icon_color=eN.icon_color),void 0!==eN.icon_background&&(e.icon_background=eN.icon_background),void 0!==eN.is_default&&(e.is_default=eN.is_default);let t=await es.mutateAsync(e);if((JSON.stringify(eN.configured_mcps)!==JSON.stringify(ek.configured_mcps)||JSON.stringify(eN.custom_mcps)!==JSON.stringify(ek.custom_mcps))&&await er.mutateAsync({agentId:U,configured_mcps:eN.configured_mcps,custom_mcps:eN.custom_mcps,replace_mcps:!0}),W.invalidateQueries({queryKey:["versions","list",U]}),W.invalidateQueries({queryKey:["agents","detail",U]}),t.current_version_id){let e=new URLSearchParams(B.toString());e.delete("version");let t=e.toString()?"?".concat(e.toString()):window.location.pathname;q.push(t)}e_(eN),y.o.success("Agent configuration saved successfully")}catch(e){console.error("Failed to save changes:",e),y.o.error("Failed to save changes")}finally{eA(!1)}}},eD=()=>{if(!ep.trim()){ef(eN.name),eg(!1);return}if(!ez){eI&&y.o.error("Name cannot be edited",{description:"RationalGo's name is managed centrally and cannot be changed."}),ef(eN.name),eg(!1);return}ew(e=>({...e,name:ep})),eg(!1)},eL=async(e,t,s)=>{ew(r=>({...r,icon_name:e,icon_color:t,icon_background:s}));try{await es.mutateAsync({agentId:U,icon_name:e,icon_color:t,icon_background:s}),e_(r=>({...r,icon_name:e,icon_color:t,icon_background:s})),W.invalidateQueries({queryKey:["agents","detail",U]}),W.invalidateQueries({queryKey:["versions","list",U]}),y.o.success("Agent icon updated successfully!")}catch(e){console.error("Failed to update agent icon:",e),y.o.error("Failed to update agent icon. Please try again."),ew(e=>({...e,icon_name:ek.icon_name,icon_color:ek.icon_color,icon_background:ek.icon_background}))}},eT=e=>{!e&&eM&&(ew(ek),ef(ek.name)),$(e)};if(J)return null;let eP=[...eE?[]:[{id:"knowledge",label:"Knowledge"}],{id:"triggers",label:"Triggers"}],e$=(e,t,s)=>(0,r.jsxs)("div",{className:"absolute inset-0 z-10",children:[(0,r.jsx)("div",{className:"absolute inset-0 bg-background/80 backdrop-blur-sm"}),(0,r.jsx)("div",{className:"relative h-full flex flex-col items-center justify-center px-6",children:(0,r.jsx)("div",{className:"max-w-sm w-full rounded-xl border border-primary/30 bg-gradient-to-br from-primary/10 via-background to-background p-4 cursor-pointer hover:border-primary/50 transition-all group shadow-sm",onClick:()=>el(),children:(0,r.jsxs)("div",{className:"flex flex-col items-center text-center gap-2.5",children:[(0,r.jsx)("div",{className:"flex items-center justify-center w-10 h-10 rounded-xl bg-primary/15 border border-primary/20 group-hover:bg-primary/20 transition-colors",children:(0,r.jsx)(e,{className:"h-5 w-5 text-primary"})}),(0,r.jsxs)("div",{children:[(0,r.jsx)("h3",{className:"text-sm font-medium text-foreground mb-1",children:t}),(0,r.jsx)("p",{className:"text-xs text-muted-foreground leading-relaxed",children:s})]}),(0,r.jsxs)(d.$,{variant:"default",size:"sm",className:"mt-1 gap-1.5",onClick:e=>{e.stopPropagation(),el()},children:[(0,r.jsx)(u.default,{className:"h-3 w-3"}),"Upgrade to Unlock"]})]})})})]});return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(i.lG,{open:P,onOpenChange:eT,children:(0,r.jsxs)(i.Cf,{className:"max-w-2xl h-[65vh] flex flex-col p-0 gap-0",children:[(0,r.jsx)(i.c7,{className:"px-4 pt-3 pb-2 flex-shrink-0 pr-10",children:(0,r.jsxs)("div",{className:"flex items-center justify-between",children:[(0,r.jsxs)("div",{className:"flex items-center gap-2.5",children:[(0,r.jsx)("div",{className:"flex-shrink-0",children:eI?(0,r.jsx)(X.lx,{isRgoDefault:!0,agentName:eN.name,size:24}):(0,r.jsx)("button",{onClick:e=>{e.preventDefault(),e.stopPropagation(),eb(!0)},className:"cursor-pointer transition-all hover:opacity-80 focus:outline-none rounded-md",type:"button",title:"Click to customize agent icon",children:(0,r.jsx)(X.lx,{iconName:eN.icon_name,iconColor:eN.icon_color,backgroundColor:eN.icon_background,agentName:eN.name,size:24})})}),(0,r.jsx)("div",{className:"flex flex-col",children:eh?(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsx)(c.p,{ref:ey,value:ep,onChange:e=>ef(e.target.value),onKeyDown:e=>{"Enter"===e.key?eD():"Escape"===e.key&&(ef(eN.name),eg(!1))},className:"h-7 w-48 text-xs",maxLength:50}),(0,r.jsx)(d.$,{size:"icon",variant:"ghost",className:"h-7 w-7",onClick:eD,children:(0,r.jsx)(m.default,{className:"h-3.5 w-3.5"})}),(0,r.jsx)(d.$,{size:"icon",variant:"ghost",className:"h-7 w-7",onClick:()=>{ef(eN.name),eg(!1)},children:(0,r.jsx)(x.default,{className:"h-3.5 w-3.5"})})]}):Z?(0,r.jsxs)("div",{className:"flex items-center gap-2 min-w-0 flex-1",children:[(0,r.jsxs)(o.rI,{children:[(0,r.jsx)(o.ty,{asChild:!0,children:(0,r.jsxs)("button",{className:"flex items-center gap-1.5 hover:bg-muted/50 rounded-md px-1.5 py-0.5 transition-colors group",children:[(0,r.jsx)(i.L3,{className:"sr-only",children:G?"Loading...":eN.name||"Agent"}),(0,r.jsx)("span",{className:"text-xs font-medium truncate",children:G?"Loading...":eN.name||"Agent"}),(0,r.jsx)(h.default,{className:"h-3 w-3 opacity-60 group-hover:opacity-100 transition-opacity flex-shrink-0"})]})}),(0,r.jsxs)(o.SQ,{className:"w-64 p-0",align:"start",sideOffset:4,children:[(0,r.jsx)("div",{className:"p-2.5 border-b",children:(0,r.jsxs)("div",{className:"flex items-center gap-2 text-xs font-medium text-muted-foreground",children:[(0,r.jsx)(g.default,{className:"h-3.5 w-3.5"}),"Switch Agent"]})}),(0,r.jsx)("div",{className:"max-h-52 overflow-y-auto",children:et.map(e=>{var t;return(0,r.jsxs)(o._2,{onClick:()=>Z(e.agent_id),className:"p-2 flex items-center gap-2.5 cursor-pointer",children:[(0,r.jsx)(X.lx,{iconName:e.icon_name,iconColor:e.icon_color,backgroundColor:e.icon_background,agentName:e.name,isRgoDefault:null==(t=e.metadata)?void 0:t.is_rgo_default,size:20,className:"flex-shrink-0"}),(0,r.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,r.jsx)("div",{className:"text-xs font-medium truncate",children:e.name}),e.description&&(0,r.jsx)("div",{className:"text-xs text-muted-foreground truncate",children:e.description})]}),e.agent_id===U&&(0,r.jsx)(m.default,{className:"h-3.5 w-3.5 text-primary flex-shrink-0"})]},e.agent_id)})})]})]}),ez&&(0,r.jsx)(d.$,{size:"icon",variant:"ghost",className:"h-6 w-6 flex-shrink-0",onClick:()=>{eg(!0),setTimeout(()=>{var e,t;null==(e=ey.current)||e.focus(),null==(t=ey.current)||t.select()},0)},children:(0,r.jsx)(p.default,{className:"h-3 w-3"})})]}):(0,r.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,r.jsx)(i.L3,{className:"sr-only",children:G?"Loading...":eN.name||"Agent"}),(0,r.jsx)("span",{className:"text-xs font-medium",children:G?"Loading...":eN.name||"Agent"}),ez&&(0,r.jsx)(d.$,{size:"icon",variant:"ghost",className:"h-6 w-6",onClick:()=>{eg(!0),setTimeout(()=>{var e,t;null==(e=ey.current)||e.focus(),null==(t=ey.current)||t.select()},0)},children:(0,r.jsx)(p.default,{className:"h-3 w-3"})})]})})]}),(0,r.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,r.jsx)(ev,{agentId:U,currentVersionId:(null==V?void 0:V.current_version_id)||null,currentFormData:{system_prompt:eN.system_prompt,configured_m
1cps:eN.configured_mcps,custom_mcps:eN.custom_mcps,rgo_base_tools:eN.rgo_base_tools}}),(0,r.jsx)(d.$,{variant:"ghost",size:"icon",onClick:()=>{en.mutate(U)},disabled:en.isPending,className:"h-6 w-6",children:en.isPending?(0,r.jsx)(b.RgoLoader,{customSize:12}):(0,r.jsx)(f.default,{className:"h-3 w-3"})})]})]})}),(0,r.jsx)("div",{className:"flex-1 overflow-hidden flex flex-col min-h-0",children:G?(0,r.jsx)("div",{className:"flex-1 flex items-center justify-center",children:(0,r.jsx)(b.RgoLoader,{customSize:28})}):(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("div",{className:"px-4 pt-1 flex-shrink-0",children:(0,r.jsx)("div",{className:"flex items-end gap-4 border-b border-border",children:eP.map(e=>{let{id:t,label:s}=e;return(0,r.jsxs)("button",{className:(0,N.cn)("pb-1.5 cursor-pointer transition-colors relative text-sm font-medium",em===t?"text-foreground":"text-muted-foreground hover:text-foreground"),onClick:()=>ex(t),children:[s,(0,r.jsx)("div",{className:(0,N.cn)("absolute -bottom-px left-0 right-0 h-px transition-all",em===t?"bg-foreground":"bg-transparent")})]},t)})})}),(0,r.jsxs)("div",{className:"flex-1 overflow-auto",children:["knowledge"===em&&!eE&&(0,r.jsxs)("div",{className:"px-4 py-3 flex flex-col h-full relative",children:[(0,r.jsx)(F,{agentId:U,agentName:eN.name||"Agent"}),ei&&e$(v.default,"Unlock Knowledge Base","Upload documents, PDFs, and files to give your AI Agents custom knowledge and context")]}),"triggers"===em&&(0,r.jsxs)("div",{className:"px-4 py-3 flex flex-col h-full relative",children:[(0,r.jsx)(Q,{agentId:U}),ed&&e$(j.default,"Unlock Automation Triggers","Set up scheduled tasks and event-based triggers to automate your AI Agents 24/7")]}),"hooks"===em&&(0,r.jsx)(eS,{agentId:U})]})]})}),(0,r.jsxs)("div",{className:"flex justify-end gap-1.5 px-4 py-2 border-t border-border flex-shrink-0",children:[(0,r.jsx)(d.$,{variant:"ghost",size:"sm",onClick:()=>eT(!1),disabled:eC,className:"h-6 text-xs",children:"Cancel"}),(0,r.jsx)(d.$,{size:"sm",onClick:eR,disabled:!eM||eC,className:"h-6 text-xs gap-1",children:eC?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(b.RgoLoader,{customSize:12}),"Saving..."]}):"Save Changes"})]})]})}),(0,r.jsx)(eo,{isOpen:ej,onClose:()=>eb(!1),currentIconName:eN.icon_name,currentIconColor:eN.icon_color,currentBackgroundColor:eN.icon_background,agentName:eN.name,agentDescription:null==V?void 0:V.description,onIconUpdate:eL})]})}},43307:(e,t,s)=>{s.d(t,{eT:()=>N,aT:()=>y,mw:()=>w});var r=s(78542),n=s(18558),a=s(72842),l=s(62809),i=s(29798),o=s(36987),c=s(40570),d=s(14333);s(75152);var u=s(26835),m=s(9601),x=s(76524),h=s(5168),g=s.n(h),p=s(2863);let f="https://api.rationalgo.ai/v1",v=m.C1.join(","),j=async(e,t,s)=>{let r=(0,m.L$)(e.name);try{let n=new FormData;n.append("file",e,r),n.append("file_id",t);let a=await x.H.upload("/files/stage",n,{showErrors:!1});if(a.error)throw Error(a.error.message||"Upload failed");s(e=>e.map(e=>e.fileId===t?{...e,status:"ready"}:e))}catch(e){console.error("Failed to stage file ".concat(r,":"),e),s(e=>e.map(e=>e.fileId===t?{...e,status:"error"}:e)),o.o.error("Failed to upload: ".concat(r))}},b=async e=>{try{let s=await g().loadAsync(e),r=[],n=0,a=0,l=Object.entries(s.files).filter(e=>{let[t,s]=e;return!s.dir});if(l.length>m.N6.MAX_ZIP_FILES)return o.o.error("Zip contains too many files (".concat(l.length,"). Max: ").concat(m.N6.MAX_ZIP_FILES)),[];for(let[e,s]of l){var t;let l=e.split("/").pop()||e,i=await s.async("blob");if((n+=i.size)>m.N6.MAX_ZIP_TOTAL_SIZE_BYTES)return o.o.error("Zip total size exceeds ".concat((0,m.v7)(m.N6.MAX_ZIP_TOTAL_SIZE_BYTES)," limit")),[];if(i.size>m.N6.MAX_FILE_SIZE_BYTES){o.o.warning("Skipping ".concat(l,": exceeds ").concat(m.N6.MAX_FILE_SIZE_MB,"MB limit"));continue}let c="."+(null==(t=l.split(".").pop())?void 0:t.toLowerCase());if(!m.C1.includes(c)){o.o.warning("Skipping ".concat(l,": unsupported file type"));continue}let d=new File([i],l,{type:i.type||"application/octet-stream"});r.push(d),a++}return a>0&&o.o.success("Extracted ".concat(a," files from ").concat(e.name)),r}catch(t){return console.error("Failed to extract zip:",t),o.o.error("Failed to extract ".concat(e.name)),[]}},y=async function(e,t,s,r,n,a){arguments.length>6&&void 0!==arguments[6]&&arguments[6],arguments.length>7&&arguments[7];let l=[];for(let t of e)if((0,m.WS)(t)){let e=await b(t);l.push(...e)}else{let e=(0,m.nN)(t);if(!e.allowed){o.o.error("".concat(t.name,": ").concat(e.reason));continue}l.push(t)}if(0!==l.length){for(let e of(a(!0),l)){let t=(0,m.L$)(e.name),s=crypto.randomUUID();n(r=>[...r,{name:t,path:"/workspace/uploads/".concat(t),size:e.size,type:e.type||"application/octet-stream",localUrl:URL.createObjectURL(e),fileId:s,status:"uploading"}]);try{await j(e,s,n)}catch(e){console.error("Failed to stage file ".concat(t,":"),e)}}a(!1)}},N=(0,n.memo)((0,n.forwardRef)((e,t)=>{let{loading:s,disabled:o,isAgentRunning:c,isUploading:m,sandboxId:x,projectId:h,setPendingFiles:g,setUploadedFiles:p,setIsUploading:f,messages:j=[],isLoggedIn:b=!0}=e,N=(0,d.jE)();(0,n.useEffect)(()=>()=>{p(e=>
1(e.forEach(e=>{e.localUrl&&URL.revokeObjectURL(e.localUrl)}),e))},[]);let w=async e=>{e.target.files&&0!==e.target.files.length&&(y(Array.from(e.target.files),x,h,g,p,f,j,N),e.target.value="")};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)(u.m_,{children:[(0,r.jsx)(u.k$,{asChild:!0,children:(0,r.jsx)("span",{className:"inline-block",children:(0,r.jsx)(a.$,{type:"button",onClick:()=>{t&&"current"in t&&t.current&&t.current.click()},variant:"outline",size:"sm",className:"h-9 w-9 p-0 bg-background/60 border-[1.5px] border-border/50 rounded-lg text-muted-foreground hover:text-foreground hover:border-border hover:bg-muted/80 flex items-center justify-center cursor-pointer transition-all duration-200",disabled:!b||s||o&&!c||m,children:m?(0,r.jsx)(i.RgoLoader,{size:"small"}):(0,r.jsx)(l.default,{className:"h-3.5 w-3.5",strokeWidth:2})})})}),(0,r.jsx)(u.ZI,{side:"top",children:(0,r.jsx)("p",{children:b?"Attach files":"Please login to attach files"})})]}),(0,r.jsx)("input",{type:"file",ref:t,className:"hidden",onChange:w,multiple:!0,accept:v})]})}));N.displayName="FileUploadHandler";let w=async(e,t,s)=>{let r=[],n=!0,a=await (0,c.getAccessTokenAsync)();if(!a)throw Error("No access token available");let l=async(e,s)=>{if(e.size>m.N6.MAX_FILE_SIZE_BYTES)throw Error("File size exceeds ".concat(m.N6.MAX_FILE_SIZE_MB,"MB limit"));let r=(0,m.L$)(e.name),n="/workspace/uploads/".concat(r),l=new FormData;l.append("file",e,r),l.append("path",n);let i=await fetch("".concat(f,"/project/").concat(t,"/files"),{method:"POST",headers:{Authorization:"Bearer ".concat(a)},body:l});if(!i.ok){if(431===i.status)throw Error("Request is too large");throw Error("Upload failed: ".concat(i.statusText))}return(await i.json()).path||n};try{await fetch("".concat(f,"/project/").concat(t,"/files/upload-started"),{method:"POST",headers:{Authorization:"Bearer ".concat(a),"Content-Type":"application/json"},body:JSON.stringify({file_count:e.length})})}catch(e){console.warn("Failed to signal upload start:",e)}try{for(let a=0;a<e.length;a++){let i=e[a];null==s||s(a,"uploading");try{let e=await l(i,a);e&&r.push(e),null==s||s(a,"ready")}catch(e){if((0,p.pU)(e)&&(console.log("[FileUploadHandler] Sandbox stopped during pending upload, attempting activation..."),o.o.info("Starting your computer…"),await (0,p.Vd)(t,{onError:e=>o.o.error("Couldn't start your computer — please try again.")}))){await new Promise(e=>setTimeout(e,p.pp));try{let e=await l(i,a);e&&r.push(e),null==s||s(a,"ready");continue}catch(e){console.error("[FileUploadHandler] Retry upload failed for ".concat(i.name,":"),e)}}console.error("Failed to upload file ".concat(i.name,":"),e),null==s||s(a,"error",e instanceof Error?e.message:"Upload failed"),n=!1}}}finally{try{await fetch("".concat(f,"/project/").concat(t,"/files/upload-completed"),{method:"POST",headers:{Authorization:"Bearer ".concat(a)}})}catch(e){console.warn("Failed to signal upload complete:",e)}}return{success:n,uploadedPaths:r}}},58168:(e,t,s)=>{s.d(t,{gf:()=>i,v9:()=>l});var r=s(67211),n=s(16699);let a=(0,r.v)()((0,n.Zr)(e=>({memoryModeEnabled:!1,setMemoryModeEnabled:t=>{e({memoryModeEnabled:t})},toggleMemoryMode:()=>{e(e=>({memoryModeEnabled:!e.memoryModeEnabled}))}}),{name:"memory-mode-storage",partialize:e=>({memoryModeEnabled:e.memoryModeEnabled})})),l=()=>a(e=>e.memoryModeEnabled),i=()=>a(e=>e.toggleMemoryMode)}}]);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.