var O=Object.defineProperty;var d=(r,e)=>O(r,"name",{value:e,configurable:!0});import{u as k,r as S,l as M,n as B,o as V,q as L,j as l,S as P,b as H,C as T,d as F,c as q,a as N,A as W,s as Y,H as $,L as z,E as G,m as J}from"../assets/mermaid-GHXKKRXX-D4c_pudv.js";import{u as K,a as Q}from"../assets/useBackgroundEventWiring-n4SNqHSI.js";import"../styles.js";function U(r){return r.length===0?{}:{repositories:r.map(e=>e.name)}}d(U,"buildRepoBinding");function X(r){const e=r.find(n=>n.category==="model"),j=r.find(n=>n.category==="mode"),a=e?.type==="select"?e.currentValue:void 0,C=j?.type==="select"?j.currentValue:void 0;return{modelId:a,agentMode:C}}d(X,"readComposedConfig");function Z(r){const e=k(),[j,a]=S.useState(()=>r.map(({id:t})=>t)),[C,n]=S.useState(()=>r.find(t=>t.focused)?.id??null),[f,x]=S.useState(null),u=S.useRef(null);u.current=f;const v=S.useRef(new Map),c=S.useRef(!1),[R,w]=S.useState(!1),b=d(t=>{const s=u.current;if(s===t){n(t);return}a(o=>{const i=s?o.filter(m=>m!==s):o;return i.includes(t)?i:[...i,t]}),x(t),n(t)},"enterCompose");M("onSwitchSession",t=>{if(B(t)){b(t);return}const s=u.current;a(o=>{const i=s?o.filter(m=>m!==s):o;return i.includes(t)?i:[...i,t]}),s&&x(null),n(t)}),M("onCloseSession",t=>{t&&(a(s=>s.includes(t)?s.filter(o=>o!==t):s),n(s=>s===t?null:s))}),M("onComposeRemoteSession",()=>{b(u.current??V())});const E=S.useCallback(async t=>{const s=u.current;if(!s||c.current)return;const o=t.getState();if(!o.chatInputDraft)return;const{modelId:m,agentMode:g}=X(o.configOptions),D=U(o.selectedRepos);c.current=!0,w(!0);let h;try{const{sessionId:p}=await e("newSession",{executionTarget:{kind:"cloud-sandbox"},...D,modelId:m,modeId:g});if(h=p,u.current!==s){e("deleteSession",p);return}if(await e("loadSession",p),u.current!==s){e("deleteSession",p);return}t.getState().adoptComposeDraft(p),v.current.set(p,s),a(y=>y.map(A=>A===s?p:A)),x(null),n(p)}catch{h&&e("deleteSession",h),e("showMessage",{type:"error",message:"Couldn't start the cloud session. Your draft was kept — try submitting again."})}finally{c.current=!1,w(!1)}},[e]);return{sessionRefs:j.map(t=>{const s=v.current.get(t);return s!==void 0?{id:t,adoptedFrom:s}:{id:t}}),activeSessionId:C,composeDraftId:f,isSubmitting:R,submitCompose:E}}d(Z,"useStandaloneSessions");function _(r){const e=L.c(29),{initialSessions:j}=r,a=k(),{sessionRefs:C,activeSessionId:n,composeDraftId:f,isSubmitting:x,submitCompose:u}=Z(j);let v;e[0]!==a?(v={onOrphaned:d(g=>{B(g)||a("closeSession",g)},"onOrphaned")},e[0]=a,e[1]=v):v=e[1];const c=K(C,v);Q(c,n);let R,w;e[2]!==n||e[3]!==a?(R=d(()=>{n&&!B(n)&&a("focusSession",n)},"t2"),w=[n,a],e[2]=n,e[3]=a,e[4]=R,e[5]=w):(R=e[4],w=e[5]),S.useEffect(R,w);let b;e[6]!==f||e[7]!==c?(b=f?c.get(f):void 0,e[6]=f,e[7]=c,e[8]=b):b=e[8];const E=b;let I;e[9]!==E||e[10]!==u?(I=d(()=>E?u(E):Promise.resolve(),"t5"),e[9]=E,e[10]=u,e[11]=I):I=e[11];let t;e[12]!==f||e[13]!==x||e[14]!==I?(t={draftId:f,isSubmitting:x,submit:I},e[12]=f,e[13]=x,e[14]=I,e[15]=t):t=e[15];const s=t;let o;if(e[16]!==n||e[17]!==C||e[18]!==c){let g;e[20]!==n||e[21]!==c?(g=d(D=>{const{id:h,adoptedFrom:p}=D,y=c.get(h);if(!y)return null;const A=h===n?l.jsx(F,{}):null;return l.jsx(P,{sessionId:h,store:y,children:A},p??h)},"t82"),e[20]=n,e[21]=c,e[22]=g):g=e[22],o=C.map(g),e[16]=n,e[17]=C,e[18]=c,e[19]=o}else o=e[19];let i;e[23]!==n||e[24]!==o?(i=l.jsx(H,{value:n,children:o}),e[23]=n,e[24]=o,e[25]=i):i=e[25];let m;return e[26]!==s||e[27]!==i?(m=l.jsx("div",{className:"kiro-standalone-root",children:l.jsx(T,{value:s,children:i})}),e[26]=s,e[27]=i,e[28]=m):m=e[28],m}d(_,"StandaloneApp");const ee=d(r=>window.vscode.postMessage(r),"postMessage"),te=q(ee),se=window.initialSessions??[],ne=window.hostCapabilities??z;N.createRoot(document.getElementById("root")).render(l.jsx(S.StrictMode,{children:l.jsx(W,{value:te,children:l.jsx(Y,{value:!0,children:l.jsx($,{initialCapabilities:ne,children:l.jsxs(G,{children:[l.jsx(_,{initialSessions:se}),l.jsx(J,{})]})})})})}));
