1import{r as n,j as t}from"./utm-Cy4lOW-Q.js";import{B as R}from"./createLucideIcon-dPnAjM8L.js";import{a4 as N,a6 as $,a5 as F,a7 as G,a3 as W,a2 as K,w as B,P as v,cJ as Y,cG as V,g as q,al as J,_ as Q}from"./authContext-DDS04vem.js";import{H as M,l as U,i as X}from"./homepageChatDraft-CFZkOD1a.js";import"./analytics-Zu3G7Flx.js";import"./onboardingFunnelEvents-DqAy5zM4.js";(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{};e.SENTRY_RELEASE={id:"v20261009-gen9227-idb-noise-61c858d6"};var a=new e.Error().stack;a&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[a]="25a0faea-32f2-45b6-8405-add071b635b3",e._sentryDebugIdIdentifier="sentry-dbid-25a0faea-32f2-45b6-8405-add071b635b3")}catch{}})();const Z="This link is no longer valid. Start a new chat to continue.",k="We could not find your draft. Start a new chat to continue.",ee="Your draft expired before it could run. Please type your prompt again.",te="We could not read your draft. Please try again.",E="We could not load your workspace. Please try again.",ae="We could not find a workspace or agent for your account. Please try again.",re=e=>{if(!e||typeof e!="object")return;const a=e.last_active_selection;if(!(!a||typeof a!="object"))return Q(a)},ne=e=>{switch(e.status){case"expired":return ee;case"invalid":case"missing":return k;default:return te}},ue=()=>{const{isAuthenticated:e,isLoading:a}=N(),o=$(),[z]=F(),{organizations:x,isLoading:_,isError:u,refetch:b}=G(),{data:f,isError:g,refetch:I}=W(),w=K(r=>r.setOrganizationId),P=B(r=>r.setAgentId),[C,s]=n.useState(null),[D,H]=n.useState(0),i=n.useRef(null),y=n.useRef(!1),S=z.get(M),c=X(S)?S:null,h=c?null:S?Z:k,O=n.useMemo(()=>re(f),[f]),L=n.useCallback(()=>{g&&I(),u&&b(),i.current=null,y.current=!1,H(r=>r+1)},[g,u,I,b]),j=n.useCallback(()=>{o(v.HOME)},[o]);return n.useEffect(()=>{if(!c||h||a||!e)return;if(g){s(E);return}if(_||f===void 0)return;if(u){s(E);return}const r=`${c}:${D}`;if(i.current===r)return;i.current=r;let m=!1;s(null);const T=d=>{y.current||(y.current=!0,o(d,{replace:!0}))};return(async()=>{const d=await U(c);if(m)return;if(d.status!=="ok"){s(ne(d));return}const p=d.draft;if(p.status==="consumed"&&p.conversationId){T(`${v.CHAT}/${p.conversationId}`);return}let l;try{l=await Y({organizations:x,lastActiveSelection:O,getAgentsForOrganization:A=>V.getAgents(A==null?null:String(A))})}catch(A){if(m)return;s(q(A,E)||E);return}if(!m){if(!l){s(ae);return}w(l.organizationId),P(l.agentId),T(`${v.CHAT}/${l.agentId}?${M}
1=${p.id}`)}})(),()=>{m=!0,i.current===r&&(i.current=null)}},[c,h,e,a,_,u,g,x,O,f,o,D,P,w]),h?t.jsxs("main",{className:"flex min-h-[60vh] flex-col items-center justify-center gap-4 px-6 text-center",children:[t.jsx("p",{role:"alert","data-testid":"msg-homepage-chat-draft-error",className:"text-sm text-red-400",children:h}),t.jsx(R,{variant:"secondary",size:"sm","data-testid":"btn-homepage-chat-new",onClick:j,children:"Start a new chat"})]}):C?t.jsxs("main",{className:"flex min-h-[60vh] flex-col items-center justify-center gap-4 px-6 text-center",children:[t.jsx("p",{role:"alert","data-testid":"msg-homepage-chat-draft-error",className:"text-sm text-red-400",children:C}),t.jsxs("div",{className:"flex items-center gap-3",children:[t.jsx(R,{variant:"primary",size:"sm","data-testid":"btn-homepage-chat-retry",onClick:L,children:"Try again"}),t.jsx(R,{variant:"secondary",size:"sm","data-testid":"btn-homepage-chat-new",onClick:j,children:"Start a new chat"})]})]}):t.jsx("div",{"data-testid":"page-homepage-chat-start",children:t.jsx(J,{})})};export{ue as default};
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.