tarsk 0.4.10 → 0.4.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +2857 -622
- package/dist/public/assets/account-view-CXpwWuJZ.js +1 -0
- package/dist/public/assets/api-BfUK32d1.js +1 -0
- package/dist/public/assets/{browser-tab-CWkk3b20.js → browser-tab-BdzIB5R4.js} +1 -1
- package/dist/public/assets/context-menu-CC9JLx5B.js +1 -0
- package/dist/public/assets/conversation-history-view-C6iUsZjA.js +1 -0
- package/dist/public/assets/{dialogs-config-CB7G-sX6.js → dialogs-config-Ofxg1Bn0.js} +2 -2
- package/dist/public/assets/diff-view-C-Kz7R_T.js +3 -0
- package/dist/public/assets/explorer-tab-view-DC8arYcw.js +2 -0
- package/dist/public/assets/explorer-tree-BwLCrdfR.js +1 -0
- package/dist/public/assets/explorer-view-CPCrOqXp.js +1 -0
- package/dist/public/assets/history-view-CAVl9GFy.js +1 -0
- package/dist/public/assets/index-BVLzVjoR.css +1 -0
- package/dist/public/assets/index-DIWoaAFy.js +30 -0
- package/dist/public/assets/onboarding-DTzcWokE.js +1 -0
- package/dist/public/assets/onboarding-dialog-BQvu_Nac.js +1 -0
- package/dist/public/assets/project-settings-view-CZPKYKCu.js +1 -0
- package/dist/public/assets/provider-details-view-BBvKe6Am.js +1 -0
- package/dist/public/assets/providers-sidebar-DSrnVDNy.js +1 -0
- package/dist/public/assets/react-vendor-9yNfIRPs.js +17 -0
- package/dist/public/assets/settings-view-D6FAPBQP.js +2 -0
- package/dist/public/assets/store-BuY90jLM.js +2 -0
- package/dist/public/assets/{terminal-panel-Bv2hLEfW.js → terminal-panel-Zyr6xth3.js} +2 -2
- package/dist/public/assets/textarea-CxhrnOOz.js +1 -0
- package/dist/public/assets/todos-view-yiH-gaUK.js +1 -0
- package/dist/public/assets/{utils-DVGxCyLB.js → utils-7CkwsQJ0.js} +1 -1
- package/dist/public/index.html +10 -9
- package/package.json +1 -1
- package/dist/public/assets/account-view-D1x7ZeLs.js +0 -1
- package/dist/public/assets/add-agent-view-Ctbm0EgW.js +0 -1
- package/dist/public/assets/add-rule-view-xKAYGOl5.js +0 -7
- package/dist/public/assets/add-skill-view-D63xCrVn.js +0 -1
- package/dist/public/assets/add-slash-command-view-paJjkCml.js +0 -1
- package/dist/public/assets/conversation-history-view-BdJJ-7zE.js +0 -1
- package/dist/public/assets/diff-view-kPjfhf7_.js +0 -3
- package/dist/public/assets/file-tree-sidebar-D58ROyfi.js +0 -1
- package/dist/public/assets/files-tab-view-DhnLTfaB.js +0 -2
- package/dist/public/assets/files-view-C1vg37wD.js +0 -1
- package/dist/public/assets/history-view-D-hEB6Qt.js +0 -1
- package/dist/public/assets/index-D7yQjYyf.js +0 -16
- package/dist/public/assets/index-DVHw8RF4.css +0 -1
- package/dist/public/assets/mcp-manager-J9VCn8-1.js +0 -1
- package/dist/public/assets/mcp-server-edit-view-yd_q5UVd.js +0 -5
- package/dist/public/assets/mcp-servers-sidebar-Bwg40dY8.js +0 -1
- package/dist/public/assets/mcp-view-BYzQiRVC.js +0 -1
- package/dist/public/assets/onboarding-CxK4aR2J.js +0 -1
- package/dist/public/assets/onboarding-dialog-DX7DCkK0.js +0 -1
- package/dist/public/assets/project-settings-view-CkAqtfjP.js +0 -1
- package/dist/public/assets/provider-details-view-CzsPzv6h.js +0 -1
- package/dist/public/assets/providers-sidebar-BokZx2tk.js +0 -1
- package/dist/public/assets/radio-group-BpmnaKJk.js +0 -1
- package/dist/public/assets/react-vendor-CR4cAsbx.js +0 -17
- package/dist/public/assets/settings-view-CoL0k8nt.js +0 -2
- package/dist/public/assets/side-panel-resizer-CVC2NC75.js +0 -1
- package/dist/public/assets/store-CxlaVYZ6.js +0 -2
- package/dist/public/assets/todos-view-FJ5GkG21.js +0 -1
- /package/dist/public/assets/{monaco-Cp3BWanQ.js → monaco-CgzMkQ7t.js} +0 -0
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/dialogs-config-Ofxg1Bn0.js","assets/rolldown-runtime-Dw2cE7zH.js","assets/account-view-CXpwWuJZ.js","assets/project-settings-view-CZPKYKCu.js","assets/react-vendor-9yNfIRPs.js","assets/history-view-CAVl9GFy.js","assets/monaco-CgzMkQ7t.js","assets/textarea-CxhrnOOz.js","assets/diff-view-C-Kz7R_T.js","assets/onboarding-DTzcWokE.js","assets/context-menu-CC9JLx5B.js","assets/store-BuY90jLM.js","assets/utils-7CkwsQJ0.js","assets/terminal-panel-Zyr6xth3.js","assets/todos-view-yiH-gaUK.js","assets/explorer-tab-view-DC8arYcw.js","assets/browser-tab-BdzIB5R4.js","assets/onboarding-dialog-BQvu_Nac.js","assets/conversation-history-view-C6iUsZjA.js","assets/settings-view-D6FAPBQP.js"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{r as e}from"./rolldown-runtime-Dw2cE7zH.js";import{$ as t,$i as n,$r as r,$t as i,A as a,Ai as o,An as s,Ar as c,At as l,Bi as u,Bn as d,Br as f,Bt as p,Ci as m,Cn as h,Ct as g,D as _,Di as v,Dr as y,Dt as b,E as x,Ei as S,En as C,Er as w,Et as T,F as E,Fn as D,Ft as O,Gn as k,Gt as A,Hi as j,Hr as M,Ht as N,I as P,Ii as F,In as I,Ir as L,It as R,J as z,Ji as B,Jr as V,Jt as ee,Ki as H,Kr as te,Kt as ne,L as re,Li as U,Ln as W,Lr as ie,Lt as ae,M as oe,Mn as se,Mr as ce,Mt as le,N as ue,Nn as de,Nr as fe,Nt as pe,O as me,Oi as he,Or as ge,Ot as _e,P as ve,Pi as G,Pn as ye,Pr as be,Pt as xe,Q as Se,Qr as Ce,Qt as we,R as Te,Ri as Ee,Rn as De,Rr as Oe,Rt as ke,S as Ae,Si as je,Sn as Me,Ti as Ne,Tr as Pe,Tt as Fe,Ui as Ie,Un as Le,Ur as Re,Ut as ze,Vi as Be,Vn as K,Vr as Ve,Vt as He,Wi as Ue,Wn as We,Wr as Ge,Wt as Ke,Xi as qe,Y as Je,Yi as Ye,Yr as Xe,Z as Ze,Zi as Qe,Zt as $e,_ as et,_i as tt,_n as nt,_t as rt,ai as it,an as at,at as ot,bi as st,bn as ct,br as lt,bt as ut,ci as dt,cn as ft,ct as pt,d as mt,di as ht,dt as gt,ei as _t,en as vt,et as yt,f as bt,ft as xt,g as St,gi as Ct,gt as wt,h as Tt,hi as Et,hn as Dt,ht as Ot,ii as kt,in as At,j as jt,ji as Mt,jn as q,jr as Nt,jt as Pt,k as Ft,kn as J,kr as It,kt as Lt,li as Rt,ln as zt,lt as Bt,m as Vt,mi as Ht,mn as Ut,mt as Wt,ni as Gt,nn as Kt,o as qt,oi as Jt,on as Yt,ot as Xt,p as Zt,pi as Qt,pt as $t,q as en,qi as tn,qr as nn,qt as rn,ra as an,rn as on,rt as sn,sn as cn,st as ln,ta as un,ti as dn,tt as fn,ui as pn,un as mn,ut as hn,v as gn,vi as _n,vn,w as yn,wn as bn,wr as xn,wt as Sn,x as Cn,xn as wn,y as Tn,yi as En,yn as Dn,yt as On,z as kn,zi as An,zn as jn,zr as Mn}from"./dialogs-config-Ofxg1Bn0.js";import{$ as Nn,A as Pn,B as Fn,C as In,D as Ln,E as Rn,F as zn,G as Bn,H as Vn,I as Hn,J as Un,K as Wn,L as Gn,M as Kn,N as qn,O as Jn,P as Yn,Q as Xn,R as Zn,S as Qn,T as $n,U as er,V as tr,X as nr,Y as rr,Z as ir,_t as ar,at as or,b as sr,ct as cr,dt as lr,et as ur,ft as dr,ht as fr,it as pr,j as mr,k as hr,lt as gr,mt as _r,nt as vr,ot as yr,pt as br,q as xr,rt as Sr,st as Cr,tt as wr,v as Tr,vt as Er,w as Dr,x as Or,y as kr}from"./react-vendor-9yNfIRPs.js";import{a as Ar,c as jr,d as Mr,f as Nr,i as Pr,l as Fr,n as Ir,o as Lr,p as Rr,r as zr,s as Br,t as Y,u as Vr}from"./store-BuY90jLM.js";import{t as Hr}from"./textarea-CxhrnOOz.js";import{c as Ur,l as Wr,s as Gr,u as Kr}from"./history-view-CAVl9GFy.js";import{n as qr,t as Jr}from"./utils-7CkwsQJ0.js";import{n as Yr,r as Xr}from"./onboarding-DTzcWokE.js";(function(){let e=document.createElement(`link`).relList;if(e&&e.supports&&e.supports(`modulepreload`))return;for(let e of document.querySelectorAll(`link[rel="modulepreload"]`))n(e);new MutationObserver(e=>{for(let t of e)if(t.type===`childList`)for(let e of t.addedNodes)e.tagName===`LINK`&&e.rel===`modulepreload`&&n(e)}).observe(document,{childList:!0,subtree:!0});function t(e){let t={};return e.integrity&&(t.integrity=e.integrity),e.referrerPolicy&&(t.referrerPolicy=e.referrerPolicy),e.crossOrigin===`use-credentials`?t.credentials=`include`:e.crossOrigin===`anonymous`?t.credentials=`omit`:t.credentials=`same-origin`,t}function n(e){if(e.ep)return;e.ep=!0;let n=t(e);fetch(e.href,n)}})();var Zr=Er(),X=e(an(),1),Z=un(),Q=lt();function Qr(e){let t=(0,Z.c)(47),{open:n,onOpenChange:r,feedbackName:i,onFeedbackNameChange:a,feedbackEmail:o,onFeedbackEmailChange:c,feedbackText:l,onFeedbackTextChange:u,loadingFeedbackUser:f,submittingFeedback:p,onSubmit:m}=e,h;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(h=(0,Q.jsxs)(jn,{children:[(0,Q.jsx)(d,{children:`Send Feedback`}),(0,Q.jsx)(W,{children:`Share feedback about Tarsk.`})]}),t[0]=h):h=t[0];let g;t[1]===Symbol.for(`react.memo_cache_sentinel`)?(g=(0,Q.jsx)(J,{htmlFor:`feedback-name`,children:`Name`}),t[1]=g):g=t[1];let _;t[2]===a?_=t[3]:(_=e=>a(e.target.value),t[2]=a,t[3]=_);let v=p||f,y;t[4]!==i||t[5]!==_||t[6]!==v?(y=(0,Q.jsxs)(`div`,{className:`grid gap-2`,children:[g,(0,Q.jsx)(s,{id:`feedback-name`,value:i,onChange:_,placeholder:`Your name`,disabled:v})]}),t[4]=i,t[5]=_,t[6]=v,t[7]=y):y=t[7];let b;t[8]===Symbol.for(`react.memo_cache_sentinel`)?(b=(0,Q.jsx)(J,{htmlFor:`feedback-email`,children:`Email`}),t[8]=b):b=t[8];let x;t[9]===c?x=t[10]:(x=e=>c(e.target.value),t[9]=c,t[10]=x);let S=p||f,C;t[11]!==o||t[12]!==x||t[13]!==S?(C=(0,Q.jsxs)(`div`,{className:`grid gap-2`,children:[b,(0,Q.jsx)(s,{id:`feedback-email`,type:`email`,value:o,onChange:x,placeholder:`you@example.com`,disabled:S})]}),t[11]=o,t[12]=x,t[13]=S,t[14]=C):C=t[14];let w;t[15]===Symbol.for(`react.memo_cache_sentinel`)?(w=(0,Q.jsx)(J,{htmlFor:`feedback-text`,children:`Feedback`}),t[15]=w):w=t[15];let T;t[16]===u?T=t[17]:(T=e=>u(e.target.value),t[16]=u,t[17]=T);let E;t[18]!==l||t[19]!==p||t[20]!==T?(E=(0,Q.jsxs)(`div`,{className:`grid gap-2`,children:[w,(0,Q.jsx)(Hr,{id:`feedback-text`,value:l,onChange:T,placeholder:`Tell us what you think...`,className:`min-h-32`,disabled:p})]}),t[18]=l,t[19]=p,t[20]=T,t[21]=E):E=t[21];let O;t[22]!==E||t[23]!==y||t[24]!==C?(O=(0,Q.jsxs)(`div`,{className:`grid gap-4 py-2`,children:[y,C,E]}),t[22]=E,t[23]=y,t[24]=C,t[25]=O):O=t[25];let k;t[26]===r?k=t[27]:(k=()=>r(!1),t[26]=r,t[27]=k);let A;t[28]!==p||t[29]!==k?(A=(0,Q.jsx)(q,{variant:`outline`,onClick:k,disabled:p,children:`Cancel`}),t[28]=p,t[29]=k,t[30]=A):A=t[30];let j;t[31]===p?j=t[32]:(j=p?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(Rt,{className:`mr-2 h-4 w-4 animate-spin`}),`Sending...`]}):`Send Feedback`,t[31]=p,t[32]=j);let M;t[33]!==m||t[34]!==p||t[35]!==j?(M=(0,Q.jsx)(q,{onClick:m,disabled:p,children:j}),t[33]=m,t[34]=p,t[35]=j,t[36]=M):M=t[36];let N;t[37]!==A||t[38]!==M?(N=(0,Q.jsxs)(De,{children:[A,M]}),t[37]=A,t[38]=M,t[39]=N):N=t[39];let P;t[40]!==O||t[41]!==N?(P=(0,Q.jsxs)(I,{className:`max-w-xl`,children:[h,O,N]}),t[40]=O,t[41]=N,t[42]=P):P=t[42];let F;return t[43]!==r||t[44]!==n||t[45]!==P?(F=(0,Q.jsx)(D,{open:n,onOpenChange:r,children:P}),t[43]=r,t[44]=n,t[45]=P,t[46]=F):F=t[46],F}function $r(e){let t=(0,Z.c)(24),{node:n,level:r,renderNode:i,defaultOpen:a,indent:o,childContainerClassName:s,openState:c,onToggle:l}=e,u=!!(n.children&&n.children.length>0),d=c[n.id]??a,f;t[0]!==n.id||t[1]!==l?(f=()=>l(n.id),t[0]=n.id,t[1]=l,t[2]=f):f=t[2];let p=f,m;t[3]!==u||t[4]!==d||t[5]!==r||t[6]!==n||t[7]!==i||t[8]!==p?(m=i(n,{isOpen:d,level:r,toggle:p,hasChildren:u}),t[3]=u,t[4]=d,t[5]=r,t[6]=n,t[7]=i,t[8]=p,t[9]=m):m=t[9];let h;t[10]!==s||t[11]!==a||t[12]!==u||t[13]!==o||t[14]!==d||t[15]!==r||t[16]!==n.children||t[17]!==l||t[18]!==c||t[19]!==i?(h=u&&d&&(0,Q.jsx)(`div`,{style:{paddingLeft:o},className:s,children:n.children.map(e=>(0,Q.jsx)($r,{node:e,level:r+1,renderNode:i,defaultOpen:a,indent:o,childContainerClassName:s,openState:c,onToggle:l},e.id))}),t[10]=s,t[11]=a,t[12]=u,t[13]=o,t[14]=d,t[15]=r,t[16]=n.children,t[17]=l,t[18]=c,t[19]=i,t[20]=h):h=t[20];let g;return t[21]!==m||t[22]!==h?(g=(0,Q.jsxs)(`div`,{className:`min-w-0`,children:[m,h]}),t[21]=m,t[22]=h,t[23]=g):g=t[23],g}function ei(e){let t=(0,Z.c)(23),{nodes:n,renderNode:r,resetKey:i,defaultOpen:a,indent:o,childContainerClassName:s,className:c}=e,l=a===void 0?!1:a,u=o===void 0?16:o,d;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(d={},t[0]=d):d=t[0];let[f,p]=(0,X.useState)(d),[m,h]=(0,X.useState)(i);i!==m&&(h(i),p({}));let g;t[1]===l?g=t[2]:(g=e=>{p(t=>({...t,[e]:!(t[e]??l)}))},t[1]=l,t[2]=g);let _=g,v;t[3]===c?v=t[4]:(v=K(`min-w-0`,c),t[3]=c,t[4]=v);let y;if(t[5]!==s||t[6]!==l||t[7]!==_||t[8]!==u||t[9]!==n||t[10]!==f||t[11]!==r){let e;t[13]!==s||t[14]!==l||t[15]!==_||t[16]!==u||t[17]!==f||t[18]!==r?(e=e=>(0,Q.jsx)($r,{node:e,level:0,renderNode:r,defaultOpen:l,indent:u,childContainerClassName:s,openState:f,onToggle:_},e.id),t[13]=s,t[14]=l,t[15]=_,t[16]=u,t[17]=f,t[18]=r,t[19]=e):e=t[19],y=n.map(e),t[5]=s,t[6]=l,t[7]=_,t[8]=u,t[9]=n,t[10]=f,t[11]=r,t[12]=y}else y=t[12];let b;return t[20]!==v||t[21]!==y?(b=(0,Q.jsx)(`div`,{className:v,children:y}),t[20]=v,t[21]=y,t[22]=b):b=t[22],b}var ti=1,ni=1e6,ri=0;function ii(){return ri=(ri+1)%(2**53-1),ri.toString()}var ai=new Map,oi=e=>{if(ai.has(e))return;let t=setTimeout(()=>{ai.delete(e),ui({type:`REMOVE_TOAST`,toastId:e})},ni);ai.set(e,t)},si=(e,t)=>{switch(t.type){case`ADD_TOAST`:return{...e,toasts:[t.toast,...e.toasts].slice(0,ti)};case`UPDATE_TOAST`:return{...e,toasts:e.toasts.map(e=>e.id===t.toast.id?{...e,...t.toast}:e)};case`DISMISS_TOAST`:{let{toastId:n}=t;return n?oi(n):e.toasts.forEach(e=>{oi(e.id)}),{...e,toasts:e.toasts.map(e=>e.id===n||n===void 0?{...e,open:!1}:e)}}case`REMOVE_TOAST`:return t.toastId===void 0?{...e,toasts:[]}:{...e,toasts:e.toasts.filter(e=>e.id!==t.toastId)}}},ci=[],li={toasts:[]};function ui(e){li=si(li,e),ci.forEach(e=>{e(li)})}function $({...e}){let t=ii(),n=e=>ui({type:`UPDATE_TOAST`,toast:{...e,id:t}}),r=()=>ui({type:`DISMISS_TOAST`,toastId:t});return ui({type:`ADD_TOAST`,toast:{...e,id:t,open:!0,onOpenChange:e=>{e||r()}}}),{id:t,dismiss:r,update:n}}function di(){let e=(0,Z.c)(5),[t,n]=X.useState(li),r;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(r=()=>(ci.push(n),()=>{let e=ci.indexOf(n);e>-1&&ci.splice(e,1)}),e[0]=r):r=e[0];let i;e[1]===t?i=e[2]:(i=[t],e[1]=t,e[2]=i),X.useEffect(r,i);let a;return e[3]===t?a=e[4]:(a={...t,toast:$,dismiss:fi},e[3]=t,e[4]=a),a}function fi(e){return ui({type:`DISMISS_TOAST`,toastId:e})}function pi(){let[e,t]=(0,X.useState)(!1),[n,r]=(0,X.useState)(``),[i,a]=(0,X.useState)(``),[o,s]=(0,X.useState)(``),[c,l]=(0,X.useState)(!1),[u,d]=(0,X.useState)(!1);return(0,X.useEffect)(()=>{if(!e)return;let t=!0;return l(!0),Xt().then(e=>{t&&(r(t=>t||e.name),a(t=>t||e.email))}).catch(()=>{t&&$({title:`Could not load git details`,description:`You can still submit feedback by entering your name and email manually.`,variant:`destructive`})}).finally(()=>{t&&l(!1)}),()=>{t=!1}},[e]),{showFeedback:e,feedbackName:n,setFeedbackName:r,feedbackEmail:i,setFeedbackEmail:a,feedbackText:o,setFeedbackText:s,loadingFeedbackUser:c,submittingFeedback:u,handleFeedbackDialogChange:e=>{t(e),e||s(``)},handleSubmitFeedback:async()=>{let e=o.trim();if(!e){$({title:`Feedback required`,description:`Please enter your feedback before submitting.`,variant:`destructive`});return}d(!0);try{await bn(`api/feedback`,{name:n.trim(),email:i.trim(),feedback:e}),$({title:`Feedback sent`,description:`Thanks for sharing your feedback.`}),s(``),t(!1)}catch(e){$({title:`Failed to send feedback`,description:e instanceof Error?e.message:`Please try again.`,variant:`destructive`})}finally{d(!1)}}}}var mi=X.forwardRef((e,t)=>{let n=(0,Z.c)(23),r,i,a,o,s,c,l,u,d;n[0]===e?(r=n[1],i=n[2],a=n[3],o=n[4],s=n[5],c=n[6],l=n[7],u=n[8],d=n[9]):({className:i,selected:c,noBackground:o,level:a,basePadding:r,indentSize:u,asChild:d,style:l,...s}=e,n[0]=e,n[1]=r,n[2]=i,n[3]=a,n[4]=o,n[5]=s,n[6]=c,n[7]=l,n[8]=u,n[9]=d);let f=u===void 0?20:u,p=d===void 0?!1:d,m=a===void 0?void 0:(r??12)+a*f,h=p?ye:`div`,g=c&&!o&&`bg-sidebar-accent text-sidebar-accent-foreground font-medium`,_=c&&o&&`font-bold text-foreground`,v;n[10]!==i||n[11]!==g||n[12]!==_?(v=K(`flex items-center gap-2 w-full min-w-0 justify-start px-3 py-2 cursor-pointer rounded-full text-sm transition-colors group overflow-hidden`,`hover:bg-sidebar-accent hover:text-sidebar-accent-foreground`,g,_,i),n[10]=i,n[11]=g,n[12]=_,n[13]=v):v=n[13];let y=m===void 0?void 0:`${m}px`,b;n[14]!==l||n[15]!==y?(b={paddingLeft:y,...l},n[14]=l,n[15]=y,n[16]=b):b=n[16];let x;return n[17]!==h||n[18]!==s||n[19]!==t||n[20]!==v||n[21]!==b?(x=(0,Q.jsx)(h,{ref:t,className:v,style:b,...s}),n[17]=h,n[18]=s,n[19]=t,n[20]=v,n[21]=b,n[22]=x):x=n[22],x});mi.displayName=`StandardListItem`;var hi=cr,gi=Cr,_i=X.forwardRef((e,t)=>{let n=(0,Z.c)(9),r,i;n[0]===e?(r=n[1],i=n[2]):({className:r,...i}=e,n[0]=e,n[1]=r,n[2]=i);let a;n[3]===r?a=n[4]:(a=K(`fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0`,r),n[3]=r,n[4]=a);let o;return n[5]!==i||n[6]!==t||n[7]!==a?(o=(0,Q.jsx)(yr,{className:a,...i,ref:t}),n[5]=i,n[6]=t,n[7]=a,n[8]=o):o=n[8],o});_i.displayName=yr.displayName;var vi=X.forwardRef((e,t)=>{let n=(0,Z.c)(10),r,i;n[0]===e?(r=n[1],i=n[2]):({className:r,...i}=e,n[0]=e,n[1]=r,n[2]=i);let a;n[3]===Symbol.for(`react.memo_cache_sentinel`)?(a=(0,Q.jsx)(_i,{}),n[3]=a):a=n[3];let o;n[4]===r?o=n[5]:(o=K(`fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border bg-background p-6 shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg`,r),n[4]=r,n[5]=o);let s;return n[6]!==i||n[7]!==t||n[8]!==o?(s=(0,Q.jsxs)(gi,{children:[a,(0,Q.jsx)(pr,{ref:t,className:o,...i})]}),n[6]=i,n[7]=t,n[8]=o,n[9]=s):s=n[9],s});vi.displayName=pr.displayName;var yi=e=>{let t=(0,Z.c)(8),n,r;t[0]===e?(n=t[1],r=t[2]):({className:n,...r}=e,t[0]=e,t[1]=n,t[2]=r);let i;t[3]===n?i=t[4]:(i=K(`flex flex-col space-y-2 text-center sm:text-left`,n),t[3]=n,t[4]=i);let a;return t[5]!==r||t[6]!==i?(a=(0,Q.jsx)(`div`,{className:i,...r}),t[5]=r,t[6]=i,t[7]=a):a=t[7],a};yi.displayName=`AlertDialogHeader`;var bi=e=>{let t=(0,Z.c)(8),n,r;t[0]===e?(n=t[1],r=t[2]):({className:n,...r}=e,t[0]=e,t[1]=n,t[2]=r);let i;t[3]===n?i=t[4]:(i=K(`flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2`,n),t[3]=n,t[4]=i);let a;return t[5]!==r||t[6]!==i?(a=(0,Q.jsx)(`div`,{className:i,...r}),t[5]=r,t[6]=i,t[7]=a):a=t[7],a};bi.displayName=`AlertDialogFooter`;var xi=X.forwardRef((e,t)=>{let n=(0,Z.c)(9),r,i;n[0]===e?(r=n[1],i=n[2]):({className:r,...i}=e,n[0]=e,n[1]=r,n[2]=i);let a;n[3]===r?a=n[4]:(a=K(`text-lg font-semibold`,r),n[3]=r,n[4]=a);let o;return n[5]!==i||n[6]!==t||n[7]!==a?(o=(0,Q.jsx)(gr,{ref:t,className:a,...i}),n[5]=i,n[6]=t,n[7]=a,n[8]=o):o=n[8],o});xi.displayName=gr.displayName;var Si=X.forwardRef((e,t)=>{let n=(0,Z.c)(9),r,i;n[0]===e?(r=n[1],i=n[2]):({className:r,...i}=e,n[0]=e,n[1]=r,n[2]=i);let a;n[3]===r?a=n[4]:(a=K(`text-sm text-muted-foreground`,r),n[3]=r,n[4]=a);let o;return n[5]!==i||n[6]!==t||n[7]!==a?(o=(0,Q.jsx)(or,{ref:t,className:a,...i}),n[5]=i,n[6]=t,n[7]=a,n[8]=o):o=n[8],o});Si.displayName=or.displayName;var Ci=X.forwardRef((e,t)=>{let n=(0,Z.c)(9),r,i;n[0]===e?(r=n[1],i=n[2]):({className:r,...i}=e,n[0]=e,n[1]=r,n[2]=i);let a;n[3]===r?a=n[4]:(a=K(se(),r),n[3]=r,n[4]=a);let o;return n[5]!==i||n[6]!==t||n[7]!==a?(o=(0,Q.jsx)(vr,{ref:t,className:a,...i}),n[5]=i,n[6]=t,n[7]=a,n[8]=o):o=n[8],o});Ci.displayName=vr.displayName;var wi=X.forwardRef((e,t)=>{let n=(0,Z.c)(9),r,i;n[0]===e?(r=n[1],i=n[2]):({className:r,...i}=e,n[0]=e,n[1]=r,n[2]=i);let a;n[3]===r?a=n[4]:(a=K(se({variant:`outline`}),`mt-2 sm:mt-0`,r),n[3]=r,n[4]=a);let o;return n[5]!==i||n[6]!==t||n[7]!==a?(o=(0,Q.jsx)(Sr,{ref:t,className:a,...i}),n[5]=i,n[6]=t,n[7]=a,n[8]=o):o=n[8],o});wi.displayName=Sr.displayName;function Ti(e){let t=(0,Z.c)(7),{theme:n,setTheme:r}=qr(),i;t[0]!==r||t[1]!==n?(i=()=>r(n===`dark`?`light`:`dark`),t[0]=r,t[1]=n,t[2]=i):i=t[2];let a,o;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(a=(0,Q.jsx)(be,{className:`h-4 w-4 rotate-0 scale-100 transition-all dark:-rotate-90 dark:scale-0 shrink-0`}),o=(0,Q.jsx)(Gt,{className:`absolute h-4 w-4 rotate-90 scale-0 transition-all dark:rotate-0 dark:scale-100 shrink-0`}),t[3]=a,t[4]=o):(a=t[3],o=t[4]);let s;return t[5]===i?s=t[6]:(s=(0,Q.jsxs)(q,{variant:`ghost`,size:`sm`,className:`justify-start gap-2 text-sidebar-foreground shrink-0`,onClick:i,children:[a,o]}),t[5]=i,t[6]=s),s}function Ei({children:e,collapsed:t,title:n,onTitleClose:r,subtitle:i,headerAction:a,footer:o,onResetOnboarding:s,onLogoClick:c}){let l=(0,X.useRef)(0),u=(0,X.useRef)(null);return(0,X.useEffect)(()=>()=>{u.current&&clearTimeout(u.current)},[]),(0,Q.jsxs)(`div`,{className:`flex flex-col bg-sidebar text-sidebar-foreground m-2.5 mb-6 mr-10 rounded-3xl shadow-2xl overflow-hidden`,style:{containerType:`inline-size`,height:`calc(100% - 24px)`},children:[(0,Q.jsxs)(`div`,{className:`flex items-center justify-between border-b border-sidebar-border px-4 py-3 h-[61px]`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(`div`,{className:`flex h-7 w-7 items-center justify-center overflow-hidden rounded-md border border-sidebar-border shadow-sm`,children:(0,Q.jsx)(`img`,{src:`/tarsk.svg`,alt:`Tarsk`,className:`h-full w-full cursor-pointer`,onClick:s||c?async()=>{if(c?.(),s)if(u.current&&clearTimeout(u.current),l.current+=1,l.current>=3){l.current=0;let{resetOnboarding:e}=await ar(async()=>{let{resetOnboarding:e}=await import(`./dialogs-config-Ofxg1Bn0.js`).then(e=>e.b);return{resetOnboarding:e}},__vite__mapDeps([0,1]));e()}else u.current=setTimeout(()=>{l.current=0},500)}:void 0})}),!t&&(0,Q.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,Q.jsx)(`span`,{className:`text-sm font-semibold tracking-tight`,children:`Tarsk`}),i&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(Ue,{className:`h-3 w-3 text-sidebar-foreground/60`}),(0,Q.jsx)(`span`,{className:`text-sm font-medium text-sidebar-foreground/80`,children:i})]})]})]}),(n??r??a)&&(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 ml-auto`,children:[a&&!t&&a,n&&(0,Q.jsx)(`span`,{className:`text-xs font-medium text-sidebar-foreground/80`,children:n}),r&&(0,Q.jsxs)(q,{variant:`ghost`,size:`icon`,className:`h-7 w-7 text-sidebar-foreground`,onClick:r,children:[(0,Q.jsx)(w,{className:`h-4 w-4`}),(0,Q.jsx)(`span`,{className:`sr-only`,children:`Close`})]})]})]}),(0,Q.jsx)(C,{className:`flex-1`,children:e}),o&&(0,Q.jsx)(`div`,{className:`border-t border-sidebar-border`,children:o})]})}var Di=(0,X.lazy)(()=>ar(()=>import(`./account-view-CXpwWuJZ.js`),__vite__mapDeps([2,1,0]))),Oi=(0,X.lazy)(()=>ar(()=>import(`./project-settings-view-CZPKYKCu.js`),__vite__mapDeps([3,1,4,5,0,6,7])));function ki(e){let t=(0,Z.c)(99),{projects:n,selectedThreadId:r,selectedProjectId:i,processingThreadIds:a,completedThreadIds:o,deletingThreadIds:s,deletingProjectIds:c,onSelectThread:l,onCreateProject:u,onCreateThread:d,onDeleteThread:f,onDeleteProject:p,onNavigateToSettings:m,onDeselect:h,collapsed:g,updateAvailable:_,updatingApp:v,onUpdateApp:y,onRefreshProjects:b}=e,[x,S]=(0,X.useState)(!1),[w,T]=(0,X.useState)(null),{showFeedback:E,feedbackName:O,setFeedbackName:k,feedbackEmail:A,setFeedbackEmail:j,feedbackText:M,setFeedbackText:N,loadingFeedbackUser:P,submittingFeedback:F,handleFeedbackDialogChange:L,handleSubmitFeedback:R}=pi(),z;t[0]===n?z=t[1]:(z=n.map(Ai),t[0]=n,t[1]=z);let V=z,ee;t[2]!==g||t[3]!==u?(ee=!g&&(0,Q.jsxs)(q,{variant:`outline`,size:`sm`,className:`gap-2`,onClick:u,children:[(0,Q.jsx)(te,{className:`h-4 w-4 shrink-0`}),(0,Q.jsx)(`span`,{className:`truncate`,children:`New Project`})]}),t[2]=g,t[3]=u,t[4]=ee):ee=t[4];let H;t[5]!==g||t[6]!==y||t[7]!==_||t[8]!==v?(H=_&&(0,Q.jsxs)(q,{variant:`ghost`,size:`sm`,className:`w-full justify-start gap-2 text-emerald-600 dark:text-emerald-400`,onClick:y,disabled:v,children:[v?(0,Q.jsx)(Rt,{className:`h-4 w-4 animate-spin`}):(0,Q.jsx)(Mt,{className:`h-4 w-4`}),!g&&(0,Q.jsx)(`span`,{className:`truncate`,children:v?`Updating...`:`Update to Latest`})]}),t[5]=g,t[6]=y,t[7]=_,t[8]=v,t[9]=H):H=t[9];let ne;t[10]===L?ne=t[11]:(ne=()=>L(!0),t[10]=L,t[11]=ne);let re;t[12]===Symbol.for(`react.memo_cache_sentinel`)?(re=(0,Q.jsx)(Jt,{className:`h-4 w-4`}),t[12]=re):re=t[12];let U;t[13]===g?U=t[14]:(U=!g&&(0,Q.jsx)(`span`,{className:`truncate`,children:`Feedback`}),t[13]=g,t[14]=U);let W;t[15]!==ne||t[16]!==U?(W=(0,Q.jsxs)(q,{variant:`ghost`,size:`sm`,className:`flex-1 justify-start gap-2 text-sidebar-foreground`,onClick:ne,children:[re,U]}),t[15]=ne,t[16]=U,t[17]=W):W=t[17];let ie;t[18]===Symbol.for(`react.memo_cache_sentinel`)?(ie=(0,Q.jsx)(B,{className:`h-4 w-4`}),t[18]=ie):ie=t[18];let ae;t[19]===g?ae=t[20]:(ae=!g&&(0,Q.jsx)(`span`,{className:`truncate`,children:`Providers`}),t[19]=g,t[20]=ae);let oe;t[21]!==m||t[22]!==ae?(oe=(0,Q.jsxs)(q,{variant:`ghost`,size:`sm`,className:`justify-start gap-2 text-sidebar-foreground shrink-0`,onClick:m,children:[ie,ae]}),t[21]=m,t[22]=ae,t[23]=oe):oe=t[23];let se;t[24]!==oe||t[25]!==W?(se=(0,Q.jsxs)(`div`,{className:`flex items-center gap-1`,children:[W,oe]}),t[24]=oe,t[25]=W,t[26]=se):se=t[26];let ce,le;t[27]===Symbol.for(`react.memo_cache_sentinel`)?(ce=()=>S(!0),le=(0,Q.jsx)(ge,{className:`h-4 w-4`}),t[27]=ce,t[28]=le):(ce=t[27],le=t[28]);let ue;t[29]===g?ue=t[30]:(ue=!g&&(0,Q.jsx)(`span`,{className:`truncate`,children:`Account`}),t[29]=g,t[30]=ue);let de;t[31]===ue?de=t[32]:(de=(0,Q.jsxs)(q,{variant:`ghost`,size:`sm`,className:`flex-1 justify-start gap-2 text-sidebar-foreground`,onClick:ce,children:[le,ue]}),t[31]=ue,t[32]=de);let fe;t[33]===g?fe=t[34]:(fe=(0,Q.jsx)(Ti,{collapsed:g}),t[33]=g,t[34]=fe);let pe;t[35]!==de||t[36]!==fe?(pe=(0,Q.jsxs)(`div`,{className:`flex items-center gap-1`,children:[de,fe]}),t[35]=de,t[36]=fe,t[37]=pe):pe=t[37];let me;t[38]!==se||t[39]!==pe||t[40]!==H?(me=(0,Q.jsxs)(`div`,{className:`px-3 py-2 flex flex-col gap-1`,children:[H,se,pe]}),t[38]=se,t[39]=pe,t[40]=H,t[41]=me):me=t[41];let he;t[42]===n.length?he=t[43]:(he=n.length===0&&(0,Q.jsx)(`p`,{className:`px-3 py-6 text-center text-xs text-muted-foreground`,children:`No projects yet. Clone a repository to get started.`}),t[42]=n.length,t[43]=he);let _e;t[44]!==o||t[45]!==c||t[46]!==s||t[47]!==d||t[48]!==p||t[49]!==f||t[50]!==l||t[51]!==a||t[52]!==n||t[53]!==i||t[54]!==r?(_e=(e,t)=>{let{isOpen:u,toggle:m}=t;return e.kind===`project`?(0,Q.jsx)(ji,{project:e.project,isOpen:u,onToggle:m,isDeletingProject:c.includes(e.project.projectId),isSelected:i?e.project.projectId===i:!1,onCreateThread:d,onDeleteProject:p,onProjectSettings:T,hasSelectedThread:e.project.threads.some(e=>e.threadId===r)}):(0,Q.jsx)(Mi,{thread:e.thread,projectId:e.projectId,selectedThreadId:r,isProcessing:a.includes(e.thread.threadId),isDeleting:s.includes(e.thread.threadId),isCompleted:o.includes(e.thread.threadId),projectTitlePrefix:`${Le(n.find(t=>t.projectId===e.projectId))} - `,onSelectThread:l,onDeleteThread:f})},t[44]=o,t[45]=c,t[46]=s,t[47]=d,t[48]=p,t[49]=f,t[50]=l,t[51]=a,t[52]=n,t[53]=i,t[54]=r,t[55]=_e):_e=t[55];let ve;t[56]!==V||t[57]!==_e?(ve=(0,Q.jsx)(ei,{nodes:V,defaultOpen:!0,childContainerClassName:`ml-4 border-l border-sidebar-border pl-2`,renderNode:_e}),t[56]=V,t[57]=_e,t[58]=ve):ve=t[58];let G;t[59]!==he||t[60]!==ve?(G=(0,Q.jsx)(C,{className:`flex-1 w-full`,children:(0,Q.jsxs)(`div`,{className:`px-2 py-2 w-full max-w-full overflow-hidden`,children:[he,ve]})}),t[59]=he,t[60]=ve,t[61]=G):G=t[61];let ye;t[62]!==g||t[63]!==h||t[64]!==me||t[65]!==ee||t[66]!==G?(ye=(0,Q.jsx)(Ei,{collapsed:g,onLogoClick:h,headerAction:ee,footer:me,children:G}),t[62]=g,t[63]=h,t[64]=me,t[65]=ee,t[66]=G,t[67]=ye):ye=t[67];let be=w!==null,xe;t[68]===Symbol.for(`react.memo_cache_sentinel`)?(xe=e=>!e&&T(null),t[68]=xe):xe=t[68];let Se;t[69]===b?Se=t[70]:(Se=()=>{b?.(),T(null)},t[69]=b,t[70]=Se);let Ce;t[71]!==w||t[72]!==Se?(Ce=(0,Q.jsx)(I,{className:`max-w-2xl p-0 overflow-auto max-h-[90vh]`,children:(0,Q.jsx)(X.Suspense,{fallback:null,children:(0,Q.jsx)(Oi,{projectId:w,onProjectUpdated:Se})})}),t[71]=w,t[72]=Se,t[73]=Ce):Ce=t[73];let we;t[74]!==be||t[75]!==Ce?(we=(0,Q.jsx)(D,{open:be,onOpenChange:xe,children:Ce}),t[74]=be,t[75]=Ce,t[76]=we):we=t[76];let Te;t[77]===R?Te=t[78]:(Te=()=>void R(),t[77]=R,t[78]=Te);let Ee;t[79]!==A||t[80]!==O||t[81]!==M||t[82]!==L||t[83]!==P||t[84]!==j||t[85]!==k||t[86]!==N||t[87]!==E||t[88]!==F||t[89]!==Te?(Ee=(0,Q.jsx)(Qr,{open:E,onOpenChange:L,feedbackName:O,onFeedbackNameChange:k,feedbackEmail:A,onFeedbackEmailChange:j,feedbackText:M,onFeedbackTextChange:N,loadingFeedbackUser:P,submittingFeedback:F,onSubmit:Te}),t[79]=A,t[80]=O,t[81]=M,t[82]=L,t[83]=P,t[84]=j,t[85]=k,t[86]=N,t[87]=E,t[88]=F,t[89]=Te,t[90]=Ee):Ee=t[90];let De;t[91]===Symbol.for(`react.memo_cache_sentinel`)?(De=(0,Q.jsx)(I,{className:`max-w-2xl p-0 overflow-auto max-h-[90vh]`,children:(0,Q.jsx)(X.Suspense,{fallback:null,children:(0,Q.jsx)(Di,{})})}),t[91]=De):De=t[91];let Oe;t[92]===x?Oe=t[93]:(Oe=(0,Q.jsx)(D,{open:x,onOpenChange:S,children:De}),t[92]=x,t[93]=Oe);let ke;return t[94]!==ye||t[95]!==we||t[96]!==Ee||t[97]!==Oe?(ke=(0,Q.jsxs)(Q.Fragment,{children:[ye,we,Ee,Oe]}),t[94]=ye,t[95]=we,t[96]=Ee,t[97]=Oe,t[98]=ke):ke=t[98],ke}function Ai(e,t){return{id:e.projectId||e.gitUrl||`project-${t}`,kind:`project`,project:e,children:e.threads.map((t,n)=>({id:t.threadId||`${e.projectId}-${t.title||n}`,kind:`thread`,thread:t,projectId:e.projectId}))}}function ji(e){let t=(0,Z.c)(26),{project:n,isOpen:r,onToggle:i,isDeletingProject:a,hasSelectedThread:o,isSelected:s,onCreateThread:c,onDeleteProject:l,onProjectSettings:u}=e,d;t[0]===n?d=t[1]:(d=Le(n),t[0]=n,t[1]=d);let f=d,p=o||s,h=r&&`rotate-90`,g;t[2]===h?g=t[3]:(g=K(`h-3.5 w-3.5 shrink-0 text-muted-foreground transition-transform`,h),t[2]=h,t[3]=g);let _;t[4]===g?_=t[5]:(_=(0,Q.jsx)(Ue,{className:g}),t[4]=g,t[5]=_);let v;t[6]===Symbol.for(`react.memo_cache_sentinel`)?(v=(0,Q.jsx)(m,{className:`h-3.5 w-3.5 shrink-0 text-muted-foreground`}),t[6]=v):v=t[6];let y=(o||s)&&`font-bold text-foreground`,b;t[7]===y?b=t[8]:(b=K(`min-w-0 truncate transition-all block`,y),t[7]=y,t[8]=b);let x;t[9]!==f||t[10]!==b?(x=(0,Q.jsx)(`span`,{className:b,children:f}),t[9]=f,t[10]=b,t[11]=x):x=t[11];let S;t[12]!==_||t[13]!==x?(S=(0,Q.jsxs)(`div`,{className:`flex min-w-0 flex-1 items-center gap-1.5 w-0`,children:[_,v,x]}),t[12]=_,t[13]=x,t[14]=S):S=t[14];let C;t[15]!==a||t[16]!==c||t[17]!==l||t[18]!==u||t[19]!==n?(C=(0,Q.jsx)(`div`,{className:`flex shrink-0 items-center ml-auto`,children:a?(0,Q.jsx)(Rt,{className:`h-3.5 w-3.5 shrink-0 animate-spin text-muted-foreground mr-1`}):(0,Q.jsxs)(Wr,{children:[(0,Q.jsxs)(Gr,{children:[(0,Q.jsx)(Kr,{asChild:!0,children:(0,Q.jsxs)(q,{variant:`ghost`,size:`icon`,className:`h-7 w-7 shrink-0 hidden group-hover:flex items-center justify-center`,onClick:e=>{e.stopPropagation(),u(n.projectId)},children:[(0,Q.jsx)(Mn,{className:`h-4 w-4`}),(0,Q.jsx)(`span`,{className:`sr-only`,children:`Project settings`})]})}),(0,Q.jsx)(Ur,{side:`right`,children:`Project settings`})]}),(0,Q.jsxs)(Gr,{children:[(0,Q.jsx)(Kr,{asChild:!0,children:(0,Q.jsxs)(q,{variant:`action`,size:`icon-sm`,className:`shrink-0 hidden group-hover:flex items-center justify-center`,onClick:e=>{e.stopPropagation(),c(n.projectId)},children:[(0,Q.jsx)(te,{}),(0,Q.jsx)(`span`,{className:`sr-only`,children:`Add thread`})]})}),(0,Q.jsx)(Ur,{side:`right`,children:`Add thread`})]}),n.threads.length===0&&(0,Q.jsxs)(Gr,{children:[(0,Q.jsx)(Kr,{asChild:!0,children:(0,Q.jsxs)(q,{variant:`ghost`,size:`icon-sm`,className:`shrink-0 hidden group-hover:flex items-center justify-center text-muted-foreground hover:bg-destructive hover:text-destructive-foreground transition-colors`,onClick:e=>{e.stopPropagation(),l(n.projectId)},children:[(0,Q.jsx)(ce,{}),(0,Q.jsx)(`span`,{className:`sr-only`,children:`Delete project`})]})}),(0,Q.jsx)(Ur,{side:`right`,children:`Delete project`})]})]})}),t[15]=a,t[16]=c,t[17]=l,t[18]=u,t[19]=n,t[20]=C):C=t[20];let w;return t[21]!==i||t[22]!==S||t[23]!==C||t[24]!==p?(w=(0,Q.jsxs)(mi,{selected:p,noBackground:!0,className:`mb-1 h-9`,onClick:i,children:[S,C]}),t[21]=i,t[22]=S,t[23]=C,t[24]=p,t[25]=w):w=t[25],w}function Mi(e){let t=(0,Z.c)(47),{thread:n,projectId:r,selectedThreadId:i,isProcessing:a,isDeleting:o,isCompleted:s,projectTitlePrefix:c,onSelectThread:l,onDeleteThread:u}=e,[d,f]=(0,X.useState)(!1),p;t[0]!==u||t[1]!==r||t[2]!==n.gitStatusDot||t[3]!==n.threadId?(p=e=>{e.stopPropagation(),n.gitStatusDot?f(!0):u(r,n.threadId)},t[0]=u,t[1]=r,t[2]=n.gitStatusDot,t[3]=n.threadId,t[4]=p):p=t[4];let m=p,h;t[5]!==c||t[6]!==n.threadId||t[7]!==n.title?(h=n.title?.startsWith(c)?n.title.slice(c.length):n.title??n.threadId,t[5]=c,t[6]=n.threadId,t[7]=n.title,t[8]=h):h=t[8];let g=h,_;t[9]===Symbol.for(`react.memo_cache_sentinel`)?(_=(0,Q.jsx)(xi,{children:`Delete Thread`}),t[9]=_):_=t[9];let v;t[10]===g?v=t[11]:(v=(0,Q.jsxs)(Si,{children:[`Are you sure you want to delete "`,g,`" and all its files? This action cannot be undone.`]}),t[10]=g,t[11]=v);let y;t[12]===Symbol.for(`react.memo_cache_sentinel`)?(y=(0,Q.jsx)(wi,{children:`Cancel`}),t[12]=y):y=t[12];let b;t[13]!==u||t[14]!==r||t[15]!==n.threadId?(b=(0,Q.jsxs)(`div`,{className:`flex gap-3 justify-end`,children:[y,(0,Q.jsx)(Ci,{onClick:()=>{f(!1),u(r,n.threadId)},className:`bg-destructive text-destructive-foreground hover:bg-destructive/90`,children:`Delete`})]}),t[13]=u,t[14]=r,t[15]=n.threadId,t[16]=b):b=t[16];let x;t[17]!==v||t[18]!==b?(x=(0,Q.jsxs)(vi,{children:[_,v,b]}),t[17]=v,t[18]=b,t[19]=x):x=t[19];let S;t[20]!==d||t[21]!==x?(S=(0,Q.jsx)(hi,{open:d,onOpenChange:f,children:x}),t[20]=d,t[21]=x,t[22]=S):S=t[22];let C=n.threadId===i,w,T;t[23]!==l||t[24]!==r||t[25]!==n.threadId?(w=()=>l(r,n.threadId),T=e=>{(e.key===`Enter`||e.key===` `)&&l(r,n.threadId)},t[23]=l,t[24]=r,t[25]=n.threadId,t[26]=w,t[27]=T):(w=t[26],T=t[27]);let E;t[28]===n.gitStatusDot?E=t[29]:(E=n.gitStatusDot?(0,Q.jsx)(`svg`,{className:`h-3 w-3 shrink-0`,viewBox:`0 0 12 12`,fill:`hsl(var(--brand))`,xmlns:`http://www.w3.org/2000/svg`,children:(0,Q.jsx)(`circle`,{cx:`6`,cy:`6`,r:`5`})}):(0,Q.jsx)(`svg`,{className:`h-3 w-3 shrink-0 text-muted-foreground`,viewBox:`0 0 12 12`,fill:`none`,stroke:`currentColor`,strokeWidth:`2.0`,xmlns:`http://www.w3.org/2000/svg`,children:(0,Q.jsx)(`circle`,{cx:`6`,cy:`6`,r:`4.5`})}),t[28]=n.gitStatusDot,t[29]=E);let D;t[30]===g?D=t[31]:(D=(0,Q.jsx)(`div`,{className:`flex-1 min-w-0 w-0`,children:(0,Q.jsx)(`span`,{className:`text-sm truncate block`,children:g})}),t[30]=g,t[31]=D);let O;t[32]!==m||t[33]!==s||t[34]!==o||t[35]!==a?(O=a||o?(0,Q.jsx)(Rt,{className:`ml-auto h-3 w-3 shrink-0 animate-spin text-muted-foreground`}):s?(0,Q.jsx)(tn,{className:`ml-auto h-3 w-3 shrink-0 text-green-500`}):(0,Q.jsx)(`div`,{className:`ml-auto flex items-center gap-1`,children:(0,Q.jsxs)(Gr,{children:[(0,Q.jsx)(Kr,{asChild:!0,children:(0,Q.jsxs)(q,{variant:`ghost`,size:`icon-sm`,className:`shrink-0 opacity-0 group-hover:opacity-100 flex items-center justify-center text-muted-foreground hover:bg-destructive hover:text-destructive-foreground transition-opacity transition-colors`,onClick:m,children:[(0,Q.jsx)(ce,{}),(0,Q.jsx)(`span`,{className:`sr-only`,children:`Delete thread`})]})}),(0,Q.jsx)(Ur,{side:`right`,children:`Delete thread and files from the repo`})]})}),t[32]=m,t[33]=s,t[34]=o,t[35]=a,t[36]=O):O=t[36];let k;t[37]!==w||t[38]!==T||t[39]!==E||t[40]!==D||t[41]!==O||t[42]!==C?(k=(0,Q.jsxs)(mi,{selected:C,onClick:w,onKeyDown:T,role:`button`,tabIndex:0,children:[E,D,O]}),t[37]=w,t[38]=T,t[39]=E,t[40]=D,t[41]=O,t[42]=C,t[43]=k):k=t[43];let A;return t[44]!==k||t[45]!==S?(A=(0,Q.jsxs)(Q.Fragment,{children:[S,k]}),t[44]=k,t[45]=S,t[46]=A):A=t[46],A}function Ni(e){let t=(0,Z.c)(10),{content:n,className:r}=e,i;bb0:{if(!n||typeof n!=`string`){let e;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(e=[],t[0]=e):e=t[0],i=e;break bb0}let e;t[1]===n?e=t[2]:(e=Fi(n),t[1]=n,t[2]=e),i=e}let a=i;if(a.length===0)return null;let o;t[3]===r?o=t[4]:(o=K(`prose-custom space-y-3 min-w-0 break-words`,r),t[3]=r,t[4]=o);let s;t[5]===a?s=t[6]:(s=a.map(Pi),t[5]=a,t[6]=s);let c;return t[7]!==o||t[8]!==s?(c=(0,Q.jsx)(`div`,{className:o,children:s}),t[7]=o,t[8]=s,t[9]=c):c=t[9],c}function Pi(e,t){return(0,Q.jsx)(Ii,{block:e},t)}function Fi(e){let t=e.split(`
|
|
3
|
+
`),n=[],r=0;for(;r<t.length;){let e=t[r];if(e.trimStart().startsWith("```")){let i=e.trimStart().slice(3).trim(),a=[];for(r++;r<t.length&&!t[r].trimStart().startsWith("```");)a.push(t[r]),r++;n.push({type:`code`,language:i,code:a.join(`
|
|
4
|
+
`)}),r++;continue}let i=e.match(/^(#{1,6})(\s.*)?$/);if(i){n.push({type:`heading`,level:i[1].length,text:i[2]?i[2].trim():``}),r++;continue}if(/^(---|\*\*\*|___)/.test(e.trim())){n.push({type:`hr`}),r++;continue}if(e.includes(`|`)&&r+1<t.length&&t[r+1].match(/^\|?\s*[-:]+/)){let i=e.split(`|`).map(e=>e.trim()).filter(Boolean);r+=2;let a=[];for(;r<t.length&&t[r].includes(`|`);)a.push(t[r].split(`|`).map(e=>e.trim()).filter(Boolean)),r++;n.push({type:`table`,headers:i,rows:a});continue}if(e.startsWith(`> `)){let e=[];for(;r<t.length&&t[r].startsWith(`> `);)e.push(t[r].slice(2)),r++;n.push({type:`blockquote`,text:e.join(`
|
|
5
|
+
`)});continue}if(/^\s*[-*+]\s/.test(e)){let e=[];for(;r<t.length&&/^\s*[-*+]\s/.test(t[r]);)e.push(t[r].replace(/^\s*[-*+]\s/,``)),r++;n.push({type:`list`,ordered:!1,items:e});continue}if(/^\s*\d+\.\s/.test(e)){let e=[];for(;r<t.length&&/^\s*\d+\.\s/.test(t[r]);)e.push(t[r].replace(/^\s*\d+\.\s/,``)),r++;n.push({type:`list`,ordered:!0,items:e});continue}if(e.trim()===``){r++;continue}let a=[];for(;r<t.length&&t[r].trim()!==``&&!t[r].startsWith(`#`)&&!t[r].startsWith("```")&&!t[r].startsWith(`> `)&&!/^\s*[-*+]\s/.test(t[r])&&!/^\s*\d+\.\s/.test(t[r]);)a.push(t[r]),r++;a.length>0&&n.push({type:`paragraph`,text:a.join(`
|
|
6
|
+
`)})}return n}function Ii(e){let t=(0,Z.c)(37),{block:n}=e;switch(n.type){case`heading`:{let e=`h${n.level}`,r,i;t[0]!==e||t[1]!==n.level?(r=e,i=K({1:`text-xl font-bold`,2:`text-lg font-semibold`,3:`text-base font-semibold`,4:`text-sm font-semibold`,5:`text-sm font-medium`,6:`text-xs font-medium`}[n.level],`text-foreground`),t[0]=e,t[1]=n.level,t[2]=r,t[3]=i):(r=t[2],i=t[3]);let a;t[4]===n.text?a=t[5]:(a=(0,Q.jsx)(Vi,{text:n.text}),t[4]=n.text,t[5]=a);let o;return t[6]!==r||t[7]!==i||t[8]!==a?(o=(0,Q.jsx)(r,{className:i,children:a}),t[6]=r,t[7]=i,t[8]=a,t[9]=o):o=t[9],o}case`code`:{let e;return t[10]!==n.code||t[11]!==n.language?(e=(0,Q.jsx)(Wi,{language:n.language,code:n.code}),t[10]=n.code,t[11]=n.language,t[12]=e):e=t[12],e}case`blockquote`:{let e;return t[13]===n.text?e=t[14]:(e=(0,Q.jsx)(`blockquote`,{className:`border-l-2 border-border pl-4 text-muted-foreground italic`,children:(0,Q.jsx)(Vi,{text:n.text})}),t[13]=n.text,t[14]=e),e}case`list`:{let e=n.ordered?`ol`:`ul`,r=n.ordered?`list-decimal`:`list-disc`,i;t[15]===r?i=t[16]:(i=K(`space-y-1 pl-5 text-sm text-foreground list-outside overflow-visible`,r),t[15]=r,t[16]=i);let a;t[17]===n.items?a=t[18]:(a=n.items.map(Bi),t[17]=n.items,t[18]=a);let o;return t[19]!==e||t[20]!==i||t[21]!==a?(o=(0,Q.jsx)(e,{className:i,children:a}),t[19]=e,t[20]=i,t[21]=a,t[22]=o):o=t[22],o}case`paragraph`:{let e;return t[23]===n.text?e=t[24]:(e=(0,Q.jsx)(`p`,{className:`text-sm leading-relaxed text-foreground whitespace-pre-wrap break-words`,children:(0,Q.jsx)(Vi,{text:n.text})}),t[23]=n.text,t[24]=e),e}case`hr`:{let e;return t[25]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,Q.jsx)(`hr`,{className:`border-border`}),t[25]=e):e=t[25],e}case`table`:{let e;t[26]===n.headers?e=t[27]:(e=n.headers.map(zi),t[26]=n.headers,t[27]=e);let r;t[28]===e?r=t[29]:(r=(0,Q.jsx)(`thead`,{children:(0,Q.jsx)(`tr`,{className:`border-b border-border bg-muted/50`,children:e})}),t[28]=e,t[29]=r);let i;t[30]===n.rows?i=t[31]:(i=n.rows.map(Li),t[30]=n.rows,t[31]=i);let a;t[32]===i?a=t[33]:(a=(0,Q.jsx)(`tbody`,{children:i}),t[32]=i,t[33]=a);let o;return t[34]!==r||t[35]!==a?(o=(0,Q.jsx)(`div`,{className:`overflow-x-auto rounded-md border border-border max-w-full`,children:(0,Q.jsxs)(`table`,{className:`w-full text-sm`,children:[r,a]})}),t[34]=r,t[35]=a,t[36]=o):o=t[36],o}default:return null}}function Li(e,t){return(0,Q.jsx)(`tr`,{className:`border-b border-border last:border-0`,children:e.map(Ri)},t)}function Ri(e,t){return(0,Q.jsx)(`td`,{className:`px-3 py-2 text-foreground`,children:e},t)}function zi(e,t){return(0,Q.jsx)(`th`,{className:`px-3 py-2 text-left font-medium text-foreground`,children:e},t)}function Bi(e,t){return(0,Q.jsx)(`li`,{children:(0,Q.jsx)(Vi,{text:e})},t)}function Vi(e){let t=(0,Z.c)(4),{text:n}=e,r;t[0]===n?r=t[1]:(r=Ui(n).map(Hi),t[0]=n,t[1]=r);let i;return t[2]===r?i=t[3]:(i=(0,Q.jsx)(Q.Fragment,{children:r}),t[2]=r,t[3]=i),i}function Hi(e,t){switch(e.type){case`bold`:return(0,Q.jsx)(`strong`,{className:`font-semibold`,children:e.text},t);case`italic`:return(0,Q.jsx)(`em`,{children:e.text},t);case`strikethrough`:return(0,Q.jsx)(`del`,{className:`text-muted-foreground`,children:e.text},t);case`code`:return(0,Q.jsx)(`code`,{className:`rounded bg-muted px-1.5 py-0.5 text-xs font-mono text-foreground`,children:e.text},t);case`link`:return(0,Q.jsx)(`a`,{href:e.href,className:`text-primary underline underline-offset-2 hover:text-primary/80`,target:`_blank`,rel:`noopener noreferrer`,children:e.text},t);default:return(0,Q.jsx)(`span`,{children:e.text},t)}}function Ui(e){let t=[],n=/(`[^`]+`)|(\*\*[^*]+\*\*)|(\*[^*]+\*)|(__[^_]+__)|(_[^_]+_)|(~~[^~]+~~)|(\[[^\]]+\]\([^)]+\))/g,r=0,i;for(;(i=n.exec(e))!==null;){i.index>r&&t.push({type:`text`,text:e.slice(r,i.index)});let n=i[0];if(n.startsWith("`"))t.push({type:`code`,text:n.slice(1,-1)});else if(n.startsWith(`**`))t.push({type:`bold`,text:n.slice(2,-2)});else if(n.startsWith(`__`))t.push({type:`bold`,text:n.slice(2,-2)});else if(n.startsWith(`~~`))t.push({type:`strikethrough`,text:n.slice(2,-2)});else if(n.startsWith(`*`)||n.startsWith(`_`))t.push({type:`italic`,text:n.slice(1,-1)});else if(n.startsWith(`[`)){let e=n.match(/\[([^\]]+)\]\(([^)]+)\)/);e&&t.push({type:`link`,text:e[1],href:e[2]})}r=i.index+n.length}return r<e.length&&t.push({type:`text`,text:e.slice(r)}),t.length>0?t:[{type:`text`,text:e}]}function Wi(e){let t=(0,Z.c)(18),{language:n,code:r}=e,[i,a]=(0,X.useState)(!1),o;t[0]===r?o=t[1]:(o=async()=>{await navigator.clipboard.writeText(r),a(!0),setTimeout(()=>a(!1),2e3)},t[0]=r,t[1]=o);let s=o,c=n||`text`,l;t[2]===c?l=t[3]:(l=(0,Q.jsx)(`span`,{className:`text-xs text-muted-foreground font-mono`,children:c}),t[2]=c,t[3]=l);let u;t[4]===i?u=t[5]:(u=i?(0,Q.jsx)(tn,{}):(0,Q.jsx)(F,{}),t[4]=i,t[5]=u);let d;t[6]===Symbol.for(`react.memo_cache_sentinel`)?(d=(0,Q.jsx)(`span`,{className:`sr-only`,children:`Copy code`}),t[6]=d):d=t[6];let f;t[7]!==s||t[8]!==u?(f=(0,Q.jsxs)(q,{variant:`action`,size:`icon-xs`,onClick:s,children:[u,d]}),t[7]=s,t[8]=u,t[9]=f):f=t[9];let p;t[10]!==l||t[11]!==f?(p=(0,Q.jsxs)(`div`,{className:`flex items-center justify-between border-b border-border bg-muted/80 px-4 py-2`,children:[l,f]}),t[10]=l,t[11]=f,t[12]=p):p=t[12];let m;t[13]===r?m=t[14]:(m=(0,Q.jsx)(`pre`,{className:`overflow-x-auto p-4 max-w-full`,children:(0,Q.jsx)(`code`,{className:`text-xs font-mono text-foreground leading-relaxed`,children:r})}),t[13]=r,t[14]=m);let h;return t[15]!==p||t[16]!==m?(h=(0,Q.jsxs)(`div`,{className:`group relative overflow-hidden rounded-lg border border-border bg-muted`,children:[p,m]}),t[15]=p,t[16]=m,t[17]=h):h=t[17],h}var Gi=ur,Ki=wr,qi=X.forwardRef((e,t)=>{let n=(0,Z.c)(13),r,i,a,o;n[0]===e?(r=n[1],i=n[2],a=n[3],o=n[4]):({className:r,align:a,sideOffset:o,...i}=e,n[0]=e,n[1]=r,n[2]=i,n[3]=a,n[4]=o);let s=a===void 0?`center`:a,c=o===void 0?4:o,l;n[5]===r?l=n[6]:(l=K(`z-50 w-72 rounded-md border bg-popover p-4 text-popover-foreground shadow-md outline-none data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2`,r),n[5]=r,n[6]=l);let u;return n[7]!==s||n[8]!==i||n[9]!==t||n[10]!==c||n[11]!==l?(u=(0,Q.jsx)(Nn,{children:(0,Q.jsx)(Xn,{ref:t,align:s,sideOffset:c,className:l,...i})}),n[7]=s,n[8]=i,n[9]=t,n[10]=c,n[11]=l,n[12]=u):u=n[12],u});qi.displayName=Xn.displayName;function Ji(e){let t=e.toLowerCase();return t.includes(`read`)||t.includes(`file`)?qe:t.includes(`create`)?te:t.includes(`replace`)||t.includes(`edit`)?ie:t.includes(`delete`)?j:t.includes(`terminal`)||t.includes(`bash`)||t.includes(`shell`)?fe:t.includes(`run`)?Pe:t.includes(`git`)||t.includes(`branch`)?st:t.includes(`search`)||t.includes(`grep`)||t.includes(`find`)?Re:t.includes(`code`)||t.includes(`debug`)?U:t.includes(`test`)?Be:t.includes(`agent`)||t.includes(`subagent`)?dn:t.includes(`copy`)?F:t.includes(`dir`)||t.includes(`list`)||t.includes(`ls`)?dt:t.includes(`view`)||t.includes(`show`)?he:t.includes(`config`)||t.includes(`setting`)?Mn:t.includes(`image`)||t.includes(`generate_image`)?Qt:t.includes(`chat`)||t.includes(`message`)||t.includes(`ask`)?Jt:y}function Yi(e){let t=e.toLowerCase();return t.includes(`bash`)||t.includes(`terminal`)||t.includes(`shell`)?`Ran`:t.includes(`read`)||t.includes(`file`)?`Read`:t===`ast_grep`?`Code Search`:t===`agent`?`Subagent`:t===`generate_image`?`Make Image`:e}function Xi(e,t){if(!t||!e||typeof e!=`string`)return e;try{let n=t.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`);return e.replace(new RegExp(n,`g`),`.`)}catch{return e}}function Zi(e){return typeof e==`string`?e:typeof e==`object`&&e?JSON.stringify(e,null,2):String(e)}function Qi(e){let t=e.trim();if(t.startsWith(`{`)&&t.endsWith(`}`)||t.startsWith(`[`)&&t.endsWith(`]`))try{return JSON.parse(t)}catch{return e}return e}function $i(e){if(typeof e!=`object`||!e)return e;if(Array.isArray(e))return e.map($i);let t={};for(let[n,r]of Object.entries(e))if(typeof r==`string`){let e=Qi(r);t[n]=typeof e==`object`?$i(e):r}else t[n]=$i(r);return t}function ea(e){if(e==null||typeof e!=`string`)return``;let t=e;return t=t.replace(/\\\\n/g,`
|
|
7
|
+
`),t=t.replace(/\\\\"/g,`"`),t=t.replace(/\\n/g,`
|
|
8
|
+
`),t=t.replace(/\\"/g,`"`),t}function ta(e){if(e==null)return``;let t=typeof e==`object`&&e?$i(e):e;return ea(typeof t==`string`?t:t==null?``:JSON.stringify(t,null,2))}function na(e){let t=(0,Z.c)(116),{block:n,inline:r,resultContent:i}=e,[a,o]=(0,X.useState)(!1),[s,c]=(0,X.useState)(!1),{state:l}=Ar(),f,p,m,h,g,_,v,y,b,x,S;if(t[0]!==n.id||t[1]!==n.input||t[2]!==n.name||t[3]!==l.projects||t[4]!==l.selectedProjectId||t[5]!==l.selectedThreadId){let e;t[17]===l.selectedProjectId?e=t[18]:(e=e=>e.projectId===l.selectedProjectId,t[17]=l.selectedProjectId,t[18]=e);let r=l.projects.find(e)?.threads.find(e=>e.threadId===l.selectedThreadId)?.path;S=n.name??`Unknown Tool`,b=n.id??`unknown`;let i=n.input,a=i&&typeof i==`object`&&`description`in i,o=a?i.subagent_type:void 0,s;t[19]===o?s=t[20]:(s=o==null?null:JSON.stringify(o),t[19]=o,t[20]=s),v=s,m=i&&typeof i==`object`?i:null,f=S===`agent`&&m&&typeof m.agentName==`string`?m.agentName:null,x=a?null:Xi(Zi(i),r),_=Xi(a?String(i.prompt):null,r),p=Xi(m&&typeof m.command==`string`?m.command:null,r),g=m&&typeof m.pattern==`string`?m.pattern:null,h=m&&typeof m.lang==`string`?m.lang:null,y=Xi(m&&typeof m.path==`string`?m.path:null,r),t[0]=n.id,t[1]=n.input,t[2]=n.name,t[3]=l.projects,t[4]=l.selectedProjectId,t[5]=l.selectedThreadId,t[6]=f,t[7]=p,t[8]=m,t[9]=h,t[10]=g,t[11]=_,t[12]=v,t[13]=y,t[14]=b,t[15]=x,t[16]=S}else f=t[6],p=t[7],m=t[8],h=t[9],g=t[10],_=t[11],v=t[12],y=t[13],b=t[14],x=t[15],S=t[16];let C=y,w=m&&typeof m.offset==`number`?m.offset:null,T=m&&typeof m.limit==`number`?m.limit:null,E=S===`generate_image`&&m&&typeof m.prompt==`string`?m.prompt:null,O,k,A,j,M,N,P;if(t[21]!==f||t[22]!==p||t[23]!==s||t[24]!==a||t[25]!==E||t[26]!==r||t[27]!==m||t[28]!==h||t[29]!==T||t[30]!==w||t[31]!==C||t[32]!==g||t[33]!==_||t[34]!==i||t[35]!==v||t[36]!==b||t[37]!==x||t[38]!==S){P=Symbol.for(`react.early_return_sentinel`);bb0:{let e=Ji(S),n=S===`todo`&&m?m.status:void 0,l=(S===`todo`?n===`done`?Be:n===`working`?u:An:null)??e,y;if(t[46]!==T||t[47]!==w||t[48]!==S?(y=function(){let e=S.charAt(0).toUpperCase()+S.slice(1);return S.toLowerCase()===`bash`&&(e=`Ran`),S.toLowerCase()===`ast_grep`&&(e=`Code Search`),S.toLowerCase()===`generate_image`&&(e=`Make Image`),S.toLowerCase().includes(`read`)&&(w!==null||T!==null)&&(w!==null&&T!==null?e+=` (lines ${w} to ${w+T})`:w===null?e+=` (${T} lines)`:e+=` (from line ${w})`),e},t[46]=T,t[47]=w,t[48]=S,t[49]=y):y=t[49],O=y,r){if(S===`todo`){P=null;break bb0}if(p!==null&&i){let e;t[50]===Symbol.for(`react.memo_cache_sentinel`)?(e=()=>c(!0),t[50]=e):e=t[50];let n=(0,X.createElement)(l,{className:`h-3.5 w-3.5 shrink-0 text-brand`}),r=O(),a;t[51]===r?a=t[52]:(a=(0,Q.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:r}),t[51]=r,t[52]=a);let o;t[53]===p?o=t[54]:(o=(0,Q.jsx)(`code`,{className:`text-xs font-mono text-muted-foreground break-all rounded bg-muted/60 px-1 py-0.5`,children:p}),t[53]=p,t[54]=o);let u;t[55]===p?u=t[56]:(u=(0,Q.jsx)(jn,{children:(0,Q.jsx)(d,{children:(0,Q.jsx)(`code`,{className:`text-sm font-mono`,children:p})})}),t[55]=p,t[56]=u);let f;t[57]===i?f=t[58]:(f=(0,Q.jsx)(`pre`,{className:`text-xs bg-muted p-3 rounded font-mono whitespace-pre-wrap overflow-auto flex-1 text-foreground`,children:i}),t[57]=i,t[58]=f);let m;t[59]!==u||t[60]!==f?(m=(0,Q.jsxs)(I,{className:`max-w-3xl max-h-[80vh] flex flex-col`,children:[u,f]}),t[59]=u,t[60]=f,t[61]=m):m=t[61];let h;t[62]!==s||t[63]!==m?(h=(0,Q.jsx)(D,{open:s,onOpenChange:c,children:m}),t[62]=s,t[63]=m,t[64]=h):h=t[64],P=(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(`button`,{type:`button`,onClick:e,className:`py-0.5 flex items-center gap-2 flex-wrap hover:opacity-70 transition-opacity text-left`,title:`Click to view output`,children:[n,a,o]}),h]});break bb0}let e=_??(x&&!p&&!C&&!g)?(0,Q.jsxs)(Gi,{children:[(0,Q.jsx)(Ki,{asChild:!0,children:(0,Q.jsx)(`span`,{title:S,className:`inline-flex`,children:(0,Q.jsxs)(`button`,{type:`button`,className:`inline-flex shrink-0 items-center gap-1 rounded p-0.5 text-muted-foreground hover:text-foreground focus:outline-none focus-visible:ring-2 focus-visible:ring-ring`,"aria-label":`Show tool details`,children:[(0,X.createElement)(l,{className:`h-3.5 w-3.5 text-brand`}),(0,Q.jsx)(`span`,{className:`text-xs`,children:O()})]})})}),(0,Q.jsx)(qi,{className:`w-80 max-h-80 overflow-auto`,align:`start`,children:(0,Q.jsxs)(`div`,{className:`text-xs text-muted-foreground space-y-2`,children:[(0,Q.jsxs)(`div`,{className:`font-mono`,children:[`ID: `,b]}),_?(0,Q.jsx)(`div`,{className:`whitespace-pre-wrap leading-relaxed`,children:_}):x?(0,Q.jsx)(`pre`,{className:`font-mono whitespace-pre-wrap overflow-auto max-h-48`,children:x}):null]})})]}):(0,Q.jsxs)(`span`,{title:S,className:`inline-flex items-center gap-1`,children:[(0,X.createElement)(l,{className:`h-3.5 w-3.5 shrink-0 text-brand`}),(0,Q.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:O()})]}),n;t[65]===p?n=t[66]:(n=p!==null&&(0,Q.jsx)(`code`,{className:`text-xs font-mono text-muted-foreground break-all rounded bg-muted/60 px-1 py-0.5`,children:p}),t[65]=p,t[66]=n);let r;t[67]===g?r=t[68]:(r=g!==null&&(0,Q.jsx)(`code`,{className:`text-xs font-mono text-muted-foreground break-all rounded bg-muted/60 px-1 py-0.5`,children:g}),t[67]=g,t[68]=r);let a;t[69]===h?a=t[70]:(a=h!==null&&(0,Q.jsx)(`span`,{className:`text-xs px-1.5 py-0.5 rounded bg-muted text-muted-foreground`,children:h}),t[69]=h,t[70]=a);let o;t[71]===C?o=t[72]:(o=C!==null&&(0,Q.jsx)(`span`,{className:`text-xs font-mono text-muted-foreground truncate max-w-[200px] sm:max-w-[320px]`,title:C,children:C}),t[71]=C,t[72]=o);let u;t[73]===f?u=t[74]:(u=f&&(0,Q.jsx)(`span`,{className:`text-xs px-1.5 py-0.5 rounded bg-muted text-muted-foreground font-mono`,children:f}),t[73]=f,t[74]=u);let m;t[75]===v?m=t[76]:(m=v&&(0,Q.jsx)(`span`,{className:`text-xs px-2 py-0.5 rounded bg-muted text-muted-foreground`,children:v}),t[75]=v,t[76]=m);let y;t[77]===E?y=t[78]:(y=E!==null&&(0,Q.jsx)(`span`,{className:`text-xs text-muted-foreground truncate max-w-[200px] sm:max-w-[320px]`,title:E,children:E}),t[77]=E,t[78]=y);let w;t[79]!==n||t[80]!==r||t[81]!==a||t[82]!==o||t[83]!==u||t[84]!==m||t[85]!==y||t[86]!==e?(w=(0,Q.jsxs)(`div`,{className:`py-0.5 flex items-center gap-2 flex-wrap`,children:[e,n,r,a,o,u,m,y]}),t[79]=n,t[80]=r,t[81]=a,t[82]=o,t[83]=u,t[84]=m,t[85]=y,t[86]=e,t[87]=w):w=t[87],P=w;break bb0}N=`mb-3 rounded-lg border border-blue-200 dark:border-blue-800 bg-blue-50 dark:bg-blue-900/20 overflow-hidden`,t[88]===a?k=t[89]:(k=()=>o(!a),t[88]=a,t[89]=k),A=`w-full px-3 py-2 flex items-center gap-2 text-sm font-medium text-blue-900 dark:text-blue-100 hover:bg-blue-100 dark:hover:bg-blue-900/40 transition-colors`,j=S,M=(0,X.createElement)(l,{className:`h-4 w-4 text-brand`})}t[21]=f,t[22]=p,t[23]=s,t[24]=a,t[25]=E,t[26]=r,t[27]=m,t[28]=h,t[29]=T,t[30]=w,t[31]=C,t[32]=g,t[33]=_,t[34]=i,t[35]=v,t[36]=b,t[37]=x,t[38]=S,t[39]=O,t[40]=k,t[41]=A,t[42]=j,t[43]=M,t[44]=N,t[45]=P}else O=t[39],k=t[40],A=t[41],j=t[42],M=t[43],N=t[44],P=t[45];if(P!==Symbol.for(`react.early_return_sentinel`))return P;let F=O(),L;t[90]===F?L=t[91]:(L=(0,Q.jsx)(`span`,{className:`flex-1 text-left min-w-0 truncate`,children:F}),t[90]=F,t[91]=L);let R;t[92]===f?R=t[93]:(R=f&&(0,Q.jsx)(`span`,{className:`text-xs px-2 py-0.5 rounded bg-blue-200 dark:bg-blue-800 text-blue-800 dark:text-blue-200 font-mono`,children:f}),t[92]=f,t[93]=R);let z;t[94]===v?z=t[95]:(z=v&&(0,Q.jsx)(`span`,{className:`text-xs px-2 py-0.5 rounded bg-blue-200 dark:bg-blue-800 text-blue-800 dark:text-blue-200`,children:v}),t[94]=v,t[95]=z);let B;t[96]===a?B=t[97]:(B=a?(0,Q.jsx)(H,{className:`h-4 w-4 shrink-0`}):(0,Q.jsx)(Ue,{className:`h-4 w-4 shrink-0`}),t[96]=a,t[97]=B);let V;t[98]!==R||t[99]!==z||t[100]!==B||t[101]!==k||t[102]!==A||t[103]!==j||t[104]!==M||t[105]!==L?(V=(0,Q.jsxs)(`button`,{onClick:k,className:A,title:j,children:[M,L,R,z,B]}),t[98]=R,t[99]=z,t[100]=B,t[101]=k,t[102]=A,t[103]=j,t[104]=M,t[105]=L,t[106]=V):V=t[106];let ee;t[107]!==a||t[108]!==_||t[109]!==b||t[110]!==x?(ee=a&&(0,Q.jsxs)(`div`,{className:`px-3 py-2 bg-white dark:bg-slate-950 border-t border-blue-200 dark:border-blue-800`,children:[(0,Q.jsxs)(`div`,{className:`text-xs text-muted-foreground mb-2 font-mono text-blue-700 dark:text-blue-300`,children:[`ID: `,b]}),_?(0,Q.jsx)(`div`,{className:`text-xs bg-slate-100 dark:bg-slate-900 p-3 rounded whitespace-pre-wrap overflow-auto max-h-64 leading-relaxed`,children:_}):x?(0,Q.jsx)(`pre`,{className:`text-xs bg-slate-100 dark:bg-slate-900 p-2 rounded font-mono whitespace-pre-wrap overflow-auto max-h-48`,children:x}):null]}),t[107]=a,t[108]=_,t[109]=b,t[110]=x,t[111]=ee):ee=t[111];let te;return t[112]!==V||t[113]!==ee||t[114]!==N?(te=(0,Q.jsxs)(`div`,{className:N,children:[V,ee]}),t[112]=V,t[113]=ee,t[114]=N,t[115]=te):te=t[115],te}var ra=(0,X.createContext)({todos:[],setTodos:()=>{}});function ia(e){let t=(0,Z.c)(7),{children:n}=e,r;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(r=[],t[0]=r):r=t[0];let[i,a]=(0,X.useState)(r),o;t[1]===Symbol.for(`react.memo_cache_sentinel`)?(o=e=>{a(e)},t[1]=o):o=t[1];let s=o,c;t[2]===i?c=t[3]:(c={todos:i,setTodos:s},t[2]=i,t[3]=c);let l;return t[4]!==n||t[5]!==c?(l=(0,Q.jsx)(ra.Provider,{value:c,children:n}),t[4]=n,t[5]=c,t[6]=l):l=t[6],l}function aa(e){let t=[e.result,e.content],n=[];for(let e of t)if(typeof e==`string`)n.push(e);else if(Array.isArray(e))for(let t of e)typeof t==`object`&&t&&`text`in t&&typeof t.text==`string`&&n.push(t.text);for(let e of n){let t=e.trim();if(t.startsWith(`{`))try{let e=JSON.parse(t);if(e&&Array.isArray(e.todos))return e.todos}catch(e){console.error(`Failed to parse todo JSON:`,e)}}return null}function oa(e){let t=(0,Z.c)(17),{todos:n}=e,{todos:r,setTodos:i}=(0,X.useContext)(ra),a,o;t[0]!==n||t[1]!==i?(a=()=>{i(n)},o=[n,i],t[0]=n,t[1]=i,t[2]=a,t[3]=o):(a=t[2],o=t[3]),(0,X.useEffect)(a,o);let s=r.length>0?r:n,c;t[4]===s?c=t[5]:(c=s.filter(ca),t[4]=s,t[5]=c);let l=c.length,u;t[6]===s.length?u=t[7]:(u=s.length===0&&(0,Q.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`No todo items.`}),t[6]=s.length,t[7]=u);let d;t[8]===s?d=t[9]:(d=s.map(sa),t[8]=s,t[9]=d);let f;t[10]!==l||t[11]!==s.length?(f=s.length>0&&(0,Q.jsxs)(`p`,{className:`text-xs text-muted-foreground pt-1`,children:[l,`/`,s.length,` completed`]}),t[10]=l,t[11]=s.length,t[12]=f):f=t[12];let p;return t[13]!==u||t[14]!==d||t[15]!==f?(p=(0,Q.jsxs)(`div`,{className:`space-y-1`,children:[u,d,f]}),t[13]=u,t[14]=d,t[15]=f,t[16]=p):p=t[16],p}function sa(e){return(0,Q.jsxs)(`div`,{className:`flex items-start gap-2 text-sm`,children:[e.status===`done`?(0,Q.jsx)(Be,{className:`h-4 w-4 shrink-0 mt-0.5 text-green-500`}):e.status===`working`?(0,Q.jsx)(Ee,{className:`h-4 w-4 shrink-0 mt-0.5 text-yellow-500`}):(0,Q.jsx)(An,{className:`h-4 w-4 shrink-0 mt-0.5 text-muted-foreground`}),(0,Q.jsx)(`span`,{className:e.status===`done`?`line-through text-muted-foreground`:`text-foreground`,children:e.description})]},e.id)}function ca(e){return e.status===`done`}function la(e){let t=(0,Z.c)(4),{todos:n}=e,{setTodos:r}=(0,X.useContext)(ra),i,a;return t[0]!==r||t[1]!==n?(i=()=>{r(n)},a=[n,r],t[0]=r,t[1]=n,t[2]=i,t[3]=a):(i=t[2],a=t[3]),(0,X.useEffect)(i,a),null}function ua(e){let t=(0,Z.c)(19),{todos:n}=e,[r,i]=(0,X.useState)(!0),a;t[0]===n?a=t[1]:(a=n.filter(da),t[0]=n,t[1]=a);let o=a.length;if(n.length===0||o===n.length)return null;let s=`${n.length-o} Tasks To Do`,c;t[2]===r?c=t[3]:(c=()=>i(!r),t[2]=r,t[3]=c);let l;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(l=(0,Q.jsx)(pn,{className:`h-4 w-4 shrink-0`}),t[4]=l):l=t[4];let u;t[5]===s?u=t[6]:(u=(0,Q.jsx)(`span`,{className:`flex-1 text-left min-w-0 truncate`,children:s}),t[5]=s,t[6]=u);let d;t[7]===r?d=t[8]:(d=r?(0,Q.jsx)(H,{className:`h-4 w-4 shrink-0`}):(0,Q.jsx)(Ue,{className:`h-4 w-4 shrink-0`}),t[7]=r,t[8]=d);let f;t[9]!==c||t[10]!==u||t[11]!==d?(f=(0,Q.jsxs)(`button`,{onClick:c,className:`w-full px-3 py-2 flex items-center gap-2 text-sm font-medium text-foreground hover:bg-muted transition-colors text-left`,title:`Todo list`,children:[l,u,d]}),t[9]=c,t[10]=u,t[11]=d,t[12]=f):f=t[12];let p;t[13]!==r||t[14]!==n?(p=r&&(0,Q.jsx)(`div`,{className:`px-3 py-3 bg-background border-t border-border`,children:(0,Q.jsx)(oa,{todos:n})}),t[13]=r,t[14]=n,t[15]=p):p=t[15];let m;return t[16]!==f||t[17]!==p?(m=(0,Q.jsxs)(`div`,{className:`mb-3 rounded-lg border border-border bg-muted/50 overflow-hidden`,children:[f,p]}),t[16]=f,t[17]=p,t[18]=m):m=t[18],m}function da(e){return e.status===`done`}function fa(e){let t=[];if(typeof e==`string`)t.push(e);else if(Array.isArray(e))for(let n of e)typeof n==`object`&&n&&`text`in n&&typeof n.text==`string`&&t.push(n.text);for(let e of t){let t=e.trim();if(t.startsWith(`{`))try{let e=JSON.parse(t);if(e.imageUrl||e.imageData)return{imageUrl:e.imageUrl,imageData:e.imageData,model:e.model}}catch{}}return null}function pa(e){let t=(0,Z.c)(29),{imageUrl:n,imageData:r}=e,[a,o]=(0,X.useState)(!1),s=r?`data:image/png;base64,${r}`:n??``,c;t[0]===s?c=t[1]:(c=async()=>{let e=`generated-image-${Date.now()}.png`,{path:t}=await i(s.startsWith(`data:`)?{imageData:s.replace(/^data:[^;]+;base64,/,``),filename:e}:{imageUrl:s,filename:e});$({title:`Saved to downloads: ${t.split(`/`).pop()}`})},t[0]=s,t[1]=c);let l=c,u;t[2]===s?u=t[3]:(u=async()=>{await x(s.startsWith(`data:`)?{imageData:s.replace(/^data:[^;]+;base64,/,``)}:{imageUrl:s}),o(!0),setTimeout(()=>o(!1),2e3)},t[2]=s,t[3]=u);let d=u,f;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(f={maxHeight:`512px`},t[4]=f):f=t[4];let p;t[5]===s?p=t[6]:(p=(0,Q.jsx)(`img`,{src:s,alt:`Generated image`,className:`max-w-full rounded-lg block`,style:f}),t[5]=s,t[6]=p);let m;t[7]===Symbol.for(`react.memo_cache_sentinel`)?(m=(0,Q.jsx)(Mt,{className:`h-3.5 w-3.5`}),t[7]=m):m=t[7];let h;t[8]===l?h=t[9]:(h=(0,Q.jsx)(Kr,{asChild:!0,children:(0,Q.jsx)(`button`,{onClick:l,className:`flex items-center justify-center h-7 w-7 rounded-md bg-background/80 backdrop-blur-sm border border-border text-foreground hover:bg-background transition-colors`,children:m})}),t[8]=l,t[9]=h);let g;t[10]===Symbol.for(`react.memo_cache_sentinel`)?(g=(0,Q.jsx)(Ur,{children:`Save image`}),t[10]=g):g=t[10];let _;t[11]===h?_=t[12]:(_=(0,Q.jsxs)(Gr,{children:[h,g]}),t[11]=h,t[12]=_);let v;t[13]===a?v=t[14]:(v=a?(0,Q.jsx)(tn,{className:`h-3.5 w-3.5 text-green-500`}):(0,Q.jsx)(F,{className:`h-3.5 w-3.5`}),t[13]=a,t[14]=v);let y;t[15]!==d||t[16]!==v?(y=(0,Q.jsx)(Kr,{asChild:!0,children:(0,Q.jsx)(`button`,{onClick:d,className:`flex items-center justify-center h-7 w-7 rounded-md bg-background/80 backdrop-blur-sm border border-border text-foreground hover:bg-background transition-colors`,children:v})}),t[15]=d,t[16]=v,t[17]=y):y=t[17];let b=a?`Copied!`:`Copy to clipboard`,S;t[18]===b?S=t[19]:(S=(0,Q.jsx)(Ur,{children:b}),t[18]=b,t[19]=S);let C;t[20]!==y||t[21]!==S?(C=(0,Q.jsxs)(Gr,{children:[y,S]}),t[20]=y,t[21]=S,t[22]=C):C=t[22];let w;t[23]!==C||t[24]!==_?(w=(0,Q.jsx)(`div`,{className:`absolute top-2 right-2 flex gap-1 opacity-0 group-hover/img:opacity-100 transition-opacity`,children:(0,Q.jsxs)(Wr,{children:[_,C]})}),t[23]=C,t[24]=_,t[25]=w):w=t[25];let T;return t[26]!==w||t[27]!==p?(T=(0,Q.jsxs)(`div`,{className:`mb-3 relative group/img inline-block max-w-full`,children:[p,w]}),t[26]=w,t[27]=p,t[28]=T):T=t[28],T}function ma(e){let t=(0,Z.c)(70),{block:n,inline:r}=e,[i,a]=(0,X.useState)(!1),[o,s]=(0,X.useState)(!1),{state:c}=Ar(),l=c.projects,u,f,p,m,h,g,_,v;if(t[0]!==n||t[1]!==r||t[2]!==c.projects||t[3]!==c.selectedProjectId||t[4]!==c.selectedThreadId){g=Symbol.for(`react.early_return_sentinel`);bb0:{let e;t[13]===c.selectedProjectId?e=t[14]:(e=e=>e.projectId===c.selectedProjectId,t[13]=c.selectedProjectId,t[14]=e);let i=l.find(e)?.threads.find(e=>e.threadId===c.selectedThreadId)?.path;v=n.toolName??`Unknown Tool`,_=n.toolCallId??`unknown`;let a=n,o=n.result??a.content,s;t[15]!==a||t[16]!==v?(s=v===`todo`?aa(a):null,t[15]=a,t[16]=v,t[17]=s):s=t[17];let d=s;if(p=Xi(ta(o),i),!(p.length>0)&&d===null){g=null;break bb0}if(u=Yi(v),typeof o==`object`&&o){let e=o,n=e.returnDisplay??e.return_display;if(typeof n==`string`&&n.trim()){let e;t[18]===n?e=t[19]:(e=n.trim(),t[18]=n,t[19]=e),u=e}else if(v===`read`||v===`file_read`){let n=e.filePath??e.file_path??e.path??``;if(n){let e;t[20]===n?e=t[21]:(e=n.split(`/`).pop()??n,t[20]=n,t[21]=e),u=`Completed ${e}`}}}else if(o==null){let e;t[22]===v?e=t[23]:(e=Yi(v),t[22]=v,t[23]=e),u=`${e} (no result)`}if(u=Xi(u,i),d!==null){let e;t[24]===d?e=t[25]:(e=(0,Q.jsx)(la,{todos:d}),t[24]=d,t[25]=e),g=e;break bb0}if(v===`generate_image`){let e;t[26]===o?e=t[27]:(e=fa(o),t[26]=o,t[27]=e);let n=e;if(n&&(n.imageUrl||n.imageData)){let e;t[28]!==n.imageData||t[29]!==n.imageUrl?(e=(0,Q.jsx)(pa,{imageUrl:n.imageUrl,imageData:n.imageData}),t[28]=n.imageData,t[29]=n.imageUrl,t[30]=e):e=t[30],g=e;break bb0}}if(r){g=null;break bb0}let y;t[31]===v?y=t[32]:(y=v.toLowerCase().includes(`bash`),t[31]=v,t[32]=y),f=y,m=p?p.split(`
|
|
9
|
+
`):[],h=f?m.slice(0,3).join(`
|
|
10
|
+
`):p}t[0]=n,t[1]=r,t[2]=c.projects,t[3]=c.selectedProjectId,t[4]=c.selectedThreadId,t[5]=u,t[6]=f,t[7]=p,t[8]=m,t[9]=h,t[10]=g,t[11]=_,t[12]=v}else u=t[5],f=t[6],p=t[7],m=t[8],h=t[9],g=t[10],_=t[11],v=t[12];if(g!==Symbol.for(`react.early_return_sentinel`))return g;let y=h,b=f&&m.length>3;if(f){let e;t[33]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,Q.jsx)(Be,{className:`h-4 w-4 shrink-0`}),t[33]=e):e=t[33];let n;t[34]===u?n=t[35]:(n=(0,Q.jsxs)(`div`,{className:`px-3 py-2 flex items-center gap-2 text-sm font-medium text-foreground`,children:[e,(0,Q.jsx)(`span`,{className:`flex-1 text-left min-w-0 truncate`,children:u})]}),t[34]=u,t[35]=n);let r;t[36]!==b||t[37]!==y||t[38]!==p||t[39]!==m?(r=p&&(0,Q.jsxs)(`div`,{className:`px-3 pb-2 bg-background border-t border-border`,children:[(0,Q.jsxs)(`pre`,{className:`text-xs bg-muted p-2 rounded font-mono whitespace-pre-wrap overflow-auto text-foreground text-left mt-2${b?` cursor-pointer hover:bg-muted/80`:``}`,onClick:b?()=>s(!0):void 0,title:b?`Click to see full output`:void 0,children:[y,b&&(0,Q.jsxs)(`span`,{className:`text-muted-foreground`,children:[`
|
|
11
|
+
`,`...`]})]}),b&&(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>s(!0),className:`mt-1 text-xs text-brand hover:underline`,children:[`Show full output (`,m.length,` lines)`]})]}),t[36]=b,t[37]=y,t[38]=p,t[39]=m,t[40]=r):r=t[40];let i;t[41]!==n||t[42]!==r?(i=(0,Q.jsxs)(`div`,{className:`mb-3 rounded-lg border border-border bg-muted/50 overflow-hidden`,children:[n,r]}),t[41]=n,t[42]=r,t[43]=i):i=t[43];let a;t[44]!==o||t[45]!==b||t[46]!==p?(a=b&&(0,Q.jsx)(D,{open:o,onOpenChange:s,children:(0,Q.jsxs)(I,{className:`max-w-3xl max-h-[80vh] flex flex-col`,children:[(0,Q.jsx)(jn,{children:(0,Q.jsx)(d,{children:`Full Output`})}),(0,Q.jsx)(`pre`,{className:`text-xs bg-muted p-3 rounded font-mono whitespace-pre-wrap overflow-auto flex-1 text-foreground`,children:p})]})}),t[44]=o,t[45]=b,t[46]=p,t[47]=a):a=t[47];let c;return t[48]!==i||t[49]!==a?(c=(0,Q.jsxs)(Q.Fragment,{children:[i,a]}),t[48]=i,t[49]=a,t[50]=c):c=t[50],c}let x;t[51]===i?x=t[52]:(x=()=>a(!i),t[51]=i,t[52]=x);let S=`${v} result`,C;t[53]===Symbol.for(`react.memo_cache_sentinel`)?(C=(0,Q.jsx)(Be,{className:`h-4 w-4 shrink-0`}),t[53]=C):C=t[53];let w;t[54]===u?w=t[55]:(w=(0,Q.jsx)(`span`,{className:`flex-1 text-left min-w-0 truncate`,children:u}),t[54]=u,t[55]=w);let T;t[56]===i?T=t[57]:(T=i?(0,Q.jsx)(H,{className:`h-4 w-4 shrink-0`}):(0,Q.jsx)(Ue,{className:`h-4 w-4 shrink-0`}),t[56]=i,t[57]=T);let E;t[58]!==x||t[59]!==S||t[60]!==w||t[61]!==T?(E=(0,Q.jsxs)(`button`,{onClick:x,className:`w-full px-3 py-2 flex items-center gap-2 text-sm font-medium text-foreground hover:bg-muted transition-colors text-left`,title:S,children:[C,w,T]}),t[58]=x,t[59]=S,t[60]=w,t[61]=T,t[62]=E):E=t[62];let O;t[63]!==i||t[64]!==p||t[65]!==_?(O=i&&(0,Q.jsxs)(`div`,{className:`px-3 py-2 bg-background border-t border-border`,children:[(0,Q.jsxs)(`div`,{className:`text-xs text-muted-foreground mb-2 font-mono`,children:[`Call ID: `,_]}),p&&(0,Q.jsx)(`pre`,{className:`text-xs bg-muted p-2 rounded font-mono whitespace-pre-wrap overflow-auto max-h-48 text-foreground text-left`,children:p})]}),t[63]=i,t[64]=p,t[65]=_,t[66]=O):O=t[66];let k;return t[67]!==O||t[68]!==E?(k=(0,Q.jsxs)(`div`,{className:`mb-3 rounded-lg border border-border bg-muted/50 overflow-hidden`,children:[E,O]}),t[67]=O,t[68]=E,t[69]=k):k=t[69],k}function ha(e){let t=(0,Z.c)(19),{text:n,isStreaming:r,hasContentAfter:i}=e,a=r===void 0?!1:r,o=i===void 0?!1:i,[s,c]=(0,X.useState)(null),l=(0,X.useRef)(a),u=(0,X.useRef)(o),d,f;if(t[0]!==o||t[1]!==a?(d=()=>{(l.current&&!a||!u.current&&o)&&(0,X.startTransition)(()=>{c(!1)}),l.current=a,u.current=o},f=[a,o,c],t[0]=o,t[1]=a,t[2]=d,t[3]=f):(d=t[2],f=t[3]),(0,X.useEffect)(d,f),!n?.trim())return null;let p=s??a,m;t[4]===p?m=t[5]:(m=()=>c(!p),t[4]=p,t[5]=m);let h,g;t[6]===Symbol.for(`react.memo_cache_sentinel`)?(h=(0,Q.jsx)(B,{className:`h-4 w-4 shrink-0 text-brand`}),g=(0,Q.jsx)(`span`,{className:`flex-1 text-left min-w-0 truncate`,children:`Thinking`}),t[6]=h,t[7]=g):(h=t[6],g=t[7]);let _;t[8]===p?_=t[9]:(_=p?(0,Q.jsx)(H,{className:`h-4 w-4 shrink-0`}):(0,Q.jsx)(Ue,{className:`h-4 w-4 shrink-0`}),t[8]=p,t[9]=_);let v;t[10]!==m||t[11]!==_?(v=(0,Q.jsxs)(`button`,{onClick:m,className:`w-full py-2 flex items-center gap-2 text-sm font-medium text-foreground hover:bg-muted/50 transition-colors text-left`,title:`Thinking`,children:[h,g,_]}),t[10]=m,t[11]=_,t[12]=v):v=t[12];let y;t[13]!==p||t[14]!==n?(y=p&&(0,Q.jsx)(`div`,{className:`py-2 border-t border-border`,children:(0,Q.jsx)(`div`,{className:`text-xs text-muted-foreground leading-relaxed whitespace-pre-wrap`,children:n})}),t[13]=p,t[14]=n,t[15]=y):y=t[15];let b;return t[16]!==y||t[17]!==v?(b=(0,Q.jsxs)(`div`,{className:`overflow-hidden`,children:[v,y]}),t[16]=y,t[17]=v,t[18]=b):b=t[18],b}function ga({toolCall:e,className:t}){let{state:n,dispatch:r}=Ar(),[i,a]=(0,X.useState)(!1),o=n.toolCallProgress[e.id];return(0,X.useMemo)(()=>{if(!n.isStreaming)return{isActive:!1,isCompleted:!0};let t=!1,r=!1;for(let i of n.streamingSegments)if(i.type===`thinking`){for(let n of i.chunks)if(n.includes(e.id))try{let i=JSON.parse(n);if(Array.isArray(i))for(let n of i)n.type===`tool_use`&&n.id===e.id&&(t=!0),n.type===`tool-result`&&n.toolCallId===e.id&&(r=!0,t=!1)}catch{}}return t&&!n.isStreaming&&(r=!0,t=!1),{isActive:t,isCompleted:r}},[n.isStreaming,n.streamingSegments,e.id]).isActive?(0,Q.jsxs)(`div`,{className:K(`border border-blue-200 dark:border-blue-800 bg-blue-50 dark:bg-blue-900/20 rounded-lg overflow-hidden mb-2`,t),children:[(0,Q.jsxs)(`div`,{className:`px-3 py-2 flex items-center gap-2`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-1.5 flex-1`,children:[(0,Q.jsx)(Rt,{className:`h-3.5 w-3.5 animate-spin`}),(0,Q.jsx)(`span`,{className:`text-sm font-medium text-blue-900 dark:text-blue-100`,children:e.name}),(0,Q.jsx)(`span`,{className:`text-xs text-blue-700 dark:text-blue-300`,children:`running`})]}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,Q.jsx)(`button`,{onClick:()=>{a(e=>!e)},className:`p-1 hover:bg-blue-200 dark:hover:bg-blue-800 rounded transition-colors`,title:i?`Collapse`:`Expand`,children:i?(0,Q.jsx)(Ie,{className:`h-3.5 w-3.5`}):(0,Q.jsx)(H,{className:`h-3.5 w-3.5`})}),(0,Q.jsx)(`button`,{onClick:()=>{r({type:Y.StopStream});let t={type:`tool-result`,toolCallId:e.id,toolName:e.name,result:`Tool execution was cancelled by the user. The command was taking too long or required user approval.`,isError:!0,content:`Tool execution was cancelled by the user. The command was taking too long or required user approval.`};r({type:Y.AppendStreamChunk,chunkType:`content`,content:JSON.stringify([t]),segments:n.streamingSegments})},className:`p-1 hover:bg-red-200 dark:hover:bg-red-800 rounded transition-colors text-red-600 dark:text-red-400`,title:`Stop tool execution`,children:(0,Q.jsx)(w,{className:`h-3.5 w-3.5`})})]})]}),i&&(0,Q.jsxs)(`div`,{className:`px-3 py-2 bg-white dark:bg-slate-950 border-t border-blue-200 dark:border-blue-800 min-h-[8rem] overflow-auto`,children:[(0,Q.jsxs)(`div`,{className:`text-xs text-muted-foreground mb-2 font-mono text-blue-700 dark:text-blue-300`,children:[`ID: `,e.id]}),(0,Q.jsxs)(`div`,{className:`mb-2`,children:[(0,Q.jsx)(`div`,{className:`text-xs font-medium text-muted-foreground mb-1`,children:`Input:`}),(0,Q.jsx)(`pre`,{className:`text-xs bg-slate-100 dark:bg-slate-900 p-2 rounded font-mono whitespace-pre-wrap overflow-auto max-h-48 border border-slate-200 dark:border-slate-700`,children:(e=>JSON.stringify(e,null,2))(e.input)})]}),o&&(0,Q.jsxs)(`div`,{className:`mb-2`,children:[(0,Q.jsx)(`div`,{className:`text-xs font-medium text-muted-foreground mb-1`,children:`Progress:`}),(0,Q.jsxs)(`div`,{className:`text-xs bg-green-50 dark:bg-green-900/20 p-2 rounded border border-green-200 dark:border-green-800`,children:[(0,Q.jsx)(`div`,{className:`text-green-700 dark:text-green-300 font-mono`,children:o.delta}),o.partial?.content?.[0]?.arguments&&typeof o.partial.content[0].arguments==`object`&&`content`in o.partial.content[0].arguments&&typeof o.partial.content[0].arguments.content==`string`&&(0,Q.jsxs)(`div`,{className:`mt-1 text-green-600 dark:text-green-400 font-mono text-xs`,children:[`Building: `,o.partial.content[0].arguments.content.slice(-50),o.partial.content[0].arguments.content.length>50&&`...`]})]})]}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 text-xs text-blue-600 dark:text-blue-400`,children:[(0,Q.jsx)(Rt,{className:`h-3 w-3 animate-spin`}),`Executing`,o&&` with progress`,`...`]})]})]}):null}function _a(e){let t=(0,Z.c)(51),{toolCallId:n,question:r,options:i,context:a}=e,[o,s]=(0,X.useState)(``),[c,l]=(0,X.useState)(!1),[d,f]=(0,X.useState)(``),[p,m]=(0,X.useState)(!1),[h,g]=(0,X.useState)(null),_;t[0]!==p||t[1]!==n?(_=async e=>{if(!(!e.trim()||p)){m(!0);try{await zt(n,e.trim()),f(e.trim()),l(!0)}catch(e){let t=e;console.error(`Failed to submit answer:`,t),m(!1),g(null)}}},t[0]=p,t[1]=n,t[2]=_):_=t[2];let v=_,y;t[3]!==v||t[4]!==p||t[5]!==c?(y=e=>{c||p||(g(e),v(e))},t[3]=v,t[4]=p,t[5]=c,t[6]=y):y=t[6];let b=y,x;t[7]!==o||t[8]!==v||t[9]!==p||t[10]!==c?(x=()=>{if(c||p)return;let e=o.trim();e&&v(e)},t[7]=o,t[8]=v,t[9]=p,t[10]=c,t[11]=x):x=t[11];let S=x,C;t[12]===S?C=t[13]:(C=e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),S())},t[12]=S,t[13]=C);let w=C;if(c){let e,n;t[14]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,Q.jsx)(tn,{className:`h-4 w-4`}),n=(0,Q.jsx)(`span`,{className:`font-medium`,children:`Answered:`}),t[14]=e,t[15]=n):(e=t[14],n=t[15]);let r;return t[16]===d?r=t[17]:(r=(0,Q.jsx)(`div`,{className:`rounded-lg border border-green-200 dark:border-green-800 bg-green-50 dark:bg-green-900/20 p-3 my-2`,children:(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-green-800 dark:text-green-200`,children:[e,n,(0,Q.jsx)(`span`,{children:d})]})}),t[16]=d,t[17]=r),r}let T;t[18]===Symbol.for(`react.memo_cache_sentinel`)?(T=(0,Q.jsx)(u,{className:`h-5 w-5 text-brand dark:text-brand shrink-0 mt-0.5`}),t[18]=T):T=t[18];let E;t[19]===r?E=t[20]:(E=(0,Q.jsx)(`div`,{className:`text-sm font-medium text-foreground`,children:(0,Q.jsx)(Ni,{content:r})}),t[19]=r,t[20]=E);let D;t[21]===a?D=t[22]:(D=a&&(0,Q.jsx)(`p`,{className:`text-xs text-muted-foreground mt-1`,children:a}),t[21]=a,t[22]=D);let O;t[23]!==E||t[24]!==D?(O=(0,Q.jsxs)(`div`,{className:`flex items-start gap-2 mb-3`,children:[T,(0,Q.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[E,D]})]}),t[23]=E,t[24]=D,t[25]=O):O=t[25];let k;t[26]!==b||t[27]!==p||t[28]!==i||t[29]!==h?(k=i&&i.length>0&&(0,Q.jsx)(`div`,{className:`flex flex-wrap gap-2 mb-3`,children:i.map(e=>{let t=h===e;return(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>b(e),disabled:p,className:K(`rounded-md border px-3 py-1.5 text-sm transition-colors disabled:opacity-50 flex items-center gap-1.5`,t?`border-brand bg-brand/20 dark:bg-brand/30 text-foreground font-medium`:`border-brand/30 dark:border-brand/40 bg-background text-foreground hover:bg-brand/10 dark:hover:bg-brand/20`),children:[t&&(0,Q.jsx)(tn,{className:`h-3.5 w-3.5 text-brand`}),e]},e)})}),t[26]=b,t[27]=p,t[28]=i,t[29]=h,t[30]=k):k=t[30];let A;t[31]===Symbol.for(`react.memo_cache_sentinel`)?(A=e=>s(e.target.value),t[31]=A):A=t[31];let j=i?.length?`Or type a custom answer...`:`Type your answer...`,N;t[32]!==o||t[33]!==w||t[34]!==p||t[35]!==j?(N=(0,Q.jsx)(`input`,{type:`text`,value:o,onChange:A,onKeyDown:w,placeholder:j,disabled:p,className:`flex-1 rounded-md border border-brand/30 dark:border-brand/40 bg-background px-3 py-1.5 text-sm text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-brand dark:focus:ring-brand disabled:opacity-50`}),t[32]=o,t[33]=w,t[34]=p,t[35]=j,t[36]=N):N=t[36];let P;t[37]!==o||t[38]!==p?(P=p||!o.trim(),t[37]=o,t[38]=p,t[39]=P):P=t[39];let F;t[40]===Symbol.for(`react.memo_cache_sentinel`)?(F=(0,Q.jsx)(M,{className:`h-4 w-4`}),t[40]=F):F=t[40];let I;t[41]!==S||t[42]!==P?(I=(0,Q.jsx)(`button`,{type:`button`,onClick:S,disabled:P,className:`rounded-md bg-brand px-3 py-1.5 text-sm text-white hover:bg-brand/90 transition-colors disabled:opacity-50`,children:F}),t[41]=S,t[42]=P,t[43]=I):I=t[43];let L;t[44]!==N||t[45]!==I?(L=(0,Q.jsxs)(`div`,{className:`flex gap-2`,children:[N,I]}),t[44]=N,t[45]=I,t[46]=L):L=t[46];let R;return t[47]!==L||t[48]!==O||t[49]!==k?(R=(0,Q.jsxs)(`div`,{className:`rounded-lg border border-brand/20 dark:border-brand/30 bg-brand/5 dark:bg-brand/10 p-4 my-2`,children:[O,k,L]}),t[47]=L,t[48]=O,t[49]=k,t[50]=R):R=t[50],R}function va(e){let t=[];for(let n of e){if(n.type!==`tool-result`||n.toolName!==`todo`)continue;let e=[n.result,n.content];for(let n of e){let e=[];if(typeof n==`string`)e.push(n);else if(Array.isArray(n))for(let t of n)typeof t==`object`&&t&&`text`in t&&typeof t.text==`string`&&e.push(t.text);for(let n of e)try{let e=JSON.parse(n.trim());e&&Array.isArray(e.todos)&&(t=e.todos)}catch{}}}return t}function ya(e){let t=(0,Z.c)(29),{src:n}=e,[r,a]=(0,X.useState)(!1),o;t[0]===n?o=t[1]:(o=async()=>{let e=`generated-image-${Date.now()}.png`,{path:t}=await i(n.startsWith(`data:`)?{imageData:n.replace(/^data:[^;]+;base64,/,``),filename:e}:{imageUrl:n,filename:e});$({title:`Saved to downloads: ${t.split(`/`).pop()}`})},t[0]=n,t[1]=o);let s=o,c;t[2]===n?c=t[3]:(c=async()=>{await x(n.startsWith(`data:`)?{imageData:n.replace(/^data:[^;]+;base64,/,``)}:{imageUrl:n}),a(!0),setTimeout(()=>a(!1),2e3)},t[2]=n,t[3]=c);let l=c,u;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(u={maxHeight:`512px`},t[4]=u):u=t[4];let d;t[5]===n?d=t[6]:(d=(0,Q.jsx)(`img`,{src:n,alt:`Generated image`,className:`max-w-full rounded-lg border border-border block`,style:u}),t[5]=n,t[6]=d);let f;t[7]===Symbol.for(`react.memo_cache_sentinel`)?(f=(0,Q.jsx)(Mt,{className:`h-3.5 w-3.5`}),t[7]=f):f=t[7];let p;t[8]===s?p=t[9]:(p=(0,Q.jsx)(Kr,{asChild:!0,children:(0,Q.jsx)(`button`,{onClick:s,className:`flex items-center justify-center h-7 w-7 rounded-md bg-background/80 backdrop-blur-sm border border-border text-foreground hover:bg-background transition-colors`,children:f})}),t[8]=s,t[9]=p);let m;t[10]===Symbol.for(`react.memo_cache_sentinel`)?(m=(0,Q.jsx)(Ur,{children:`Save image`}),t[10]=m):m=t[10];let h;t[11]===p?h=t[12]:(h=(0,Q.jsxs)(Gr,{children:[p,m]}),t[11]=p,t[12]=h);let g;t[13]===r?g=t[14]:(g=r?(0,Q.jsx)(tn,{className:`h-3.5 w-3.5 text-green-500`}):(0,Q.jsx)(F,{className:`h-3.5 w-3.5`}),t[13]=r,t[14]=g);let _;t[15]!==l||t[16]!==g?(_=(0,Q.jsx)(Kr,{asChild:!0,children:(0,Q.jsx)(`button`,{onClick:l,className:`flex items-center justify-center h-7 w-7 rounded-md bg-background/80 backdrop-blur-sm border border-border text-foreground hover:bg-background transition-colors`,children:g})}),t[15]=l,t[16]=g,t[17]=_):_=t[17];let v=r?`Copied!`:`Copy to clipboard`,y;t[18]===v?y=t[19]:(y=(0,Q.jsx)(Ur,{children:v}),t[18]=v,t[19]=y);let b;t[20]!==_||t[21]!==y?(b=(0,Q.jsxs)(Gr,{children:[_,y]}),t[20]=_,t[21]=y,t[22]=b):b=t[22];let S;t[23]!==b||t[24]!==h?(S=(0,Q.jsx)(`div`,{className:`absolute top-2 right-2 flex gap-1 opacity-0 group-hover/img:opacity-100 transition-opacity`,children:(0,Q.jsxs)(Wr,{children:[h,b]})}),t[23]=b,t[24]=h,t[25]=S):S=t[25];let C;return t[26]!==S||t[27]!==d?(C=(0,Q.jsxs)(`div`,{className:`mt-2 relative group/img inline-block max-w-full`,children:[d,S]}),t[26]=S,t[27]=d,t[28]=C):C=t[28],C}function ba(e,t){let n=e.find(e=>e.type===`tool-result`&&e.toolCallId===t);if(!n)return;let r=n,i=r.result??r.content;if(i!=null)return typeof i==`string`?i:JSON.stringify(i,null,2)}function xa(e,t,n,r){return e.name===`ask_user`?(0,Q.jsx)(_a,{toolCallId:e.id,question:JSON.stringify(e.input?.question??``),options:e.input?.options,context:e.input?.context},t):n?(0,Q.jsxs)(`span`,{children:[(0,Q.jsx)(ga,{toolCall:e}),(0,Q.jsx)(na,{inline:!0,block:e,resultContent:r})]},t):(0,Q.jsx)(na,{inline:!0,block:e,resultContent:r},t)}function Sa(e){let t=(0,Z.c)(63),{message:n}=e,r=n.sender===`user`,i,a,o,s,c,l;if(t[0]!==r||t[1]!==n.content||t[2]!==n.contentType||t[3]!==n.isThinking||t[4]!==n.metadata||t[5]!==n.model||t[6]!==n.sender||t[7]!==n.timestamp){let e=r?null:Nr(n.content),u;t[14]===n.timestamp?u=t[15]:(u=n.timestamp?new Date(n.timestamp).toLocaleTimeString([],{hour:`2-digit`,minute:`2-digit`}):``,t[14]=n.timestamp,t[15]=u);let d=u,f=r?`flex-row-reverse`:`flex-row`;t[16]===f?c=t[17]:(c=K(`group flex gap-3 px-4 py-4`,f),t[16]=f,t[17]=c);let p=r?`bg-foreground`:`bg-muted`,m;t[18]===p?m=t[19]:(m=K(`flex h-7 w-7 shrink-0 items-center justify-center rounded-full`,p),t[18]=p,t[19]=m);let h;t[20]===r?h=t[21]:(h=r?(0,Q.jsx)(ge,{className:`h-3.5 w-3.5 text-background`}):(0,Q.jsx)(Ye,{className:`h-3.5 w-3.5 text-muted-foreground`}),t[20]=r,t[21]=h),t[22]!==m||t[23]!==h?(l=(0,Q.jsx)(`div`,{className:m,children:h}),t[22]=m,t[23]=h,t[24]=l):l=t[24];let g=r&&`items-end`;t[25]===g?o=t[26]:(o=K(`flex flex-1 flex-col gap-1 min-w-0`,g),t[25]=g,t[26]=o);let _=r&&`flex-row-reverse`,v;t[27]===_?v=t[28]:(v=K(`flex items-center gap-2`,_),t[27]=_,t[28]=v);let y=r?`You`:`Agent`,b;t[29]===y?b=t[30]:(b=(0,Q.jsx)(`span`,{className:`text-xs font-medium text-foreground`,children:y}),t[29]=y,t[30]=b);let x;t[31]===d?x=t[32]:(x=d&&(0,Q.jsxs)(`span`,{className:`flex items-center gap-1 text-[10px] text-muted-foreground opacity-0 group-hover:opacity-100 transition-opacity`,children:[(0,Q.jsx)(Ee,{className:`h-2.5 w-2.5`}),d]}),t[31]=d,t[32]=x);let S;t[33]===n.model?S=t[34]:(S=n.model&&(0,Q.jsxs)(`span`,{className:`flex items-center gap-1 text-[10px] text-muted-foreground opacity-0 group-hover:opacity-100 transition-opacity`,children:[(0,Q.jsx)(G,{className:`h-2.5 w-2.5`}),Xr(n.model)]}),t[33]=n.model,t[34]=S);let C;t[35]===n.metadata?C=t[36]:(C=n.metadata?.tokenCount&&(0,Q.jsxs)(`span`,{className:`text-[10px] text-muted-foreground opacity-0 group-hover:opacity-100 transition-opacity`,children:[n.metadata.tokenCount,` tokens`]}),t[35]=n.metadata,t[36]=C),t[37]!==v||t[38]!==b||t[39]!==x||t[40]!==S||t[41]!==C?(s=(0,Q.jsxs)(`div`,{className:v,children:[b,x,S,C]}),t[37]=v,t[38]=b,t[39]=x,t[40]=S,t[41]=C,t[42]=s):s=t[42];let w=r?`bg-foreground text-background`:`bg-muted text-foreground`;t[43]===w?i=t[44]:(i=K(`rounded-xl px-4 py-3 flex flex-col gap-0.5 min-w-0`,w),t[43]=w,t[44]=i),a=n.isThinking?(()=>{let e=Rr(n.content);return e?.length?e.map((t,n)=>t.type===`tool_use`?xa(t,n,!1,ba(e,t.id)):t.type===`tool-result`?(0,Q.jsx)(ma,{inline:!0,block:t},n):t.type===`reasoning`&&`text`in t?(0,Q.jsx)(ha,{text:Mr(t.text)},n):null):(0,Q.jsx)(`div`,{className:`text-xs text-muted-foreground leading-relaxed whitespace-pre-wrap`,children:(0,Q.jsx)(Ni,{content:Mr(n.content)})})})():e?(()=>{let t=va(e),n=e.filter(Ta);return(0,Q.jsxs)(Q.Fragment,{children:[e.map((t,n)=>t.type===`tool_use`&&t.name===`todo`||t.type===`tool-result`&&t.toolName===`todo`?t.type===`tool-result`?(0,Q.jsx)(ma,{inline:!0,block:t},n):null:t.type===`tool_use`&&t.name===`ask_user`?null:(0,Q.jsx)(`div`,{children:t.type===`reasoning`&&`text`in t?(0,Q.jsx)(ha,{text:Mr(t.text)}):t.type===`text`&&`text`in t?(0,Q.jsx)(Ni,{content:Mr(t.text)}):t.type===`tool_use`?xa(t,void 0,!1,ba(e,t.id)):t.type===`tool-result`?(0,Q.jsx)(ma,{inline:!0,block:t}):null},n)),t.length>0&&(0,Q.jsx)(ua,{todos:t}),n.map(wa)]})})():n.contentType===`markdown`||n.sender===`agent`?(0,Q.jsx)(Ni,{content:Mr(n.content)}):(0,Q.jsx)(`p`,{className:`text-sm whitespace-pre-wrap`,children:n.content}),t[0]=r,t[1]=n.content,t[2]=n.contentType,t[3]=n.isThinking,t[4]=n.metadata,t[5]=n.model,t[6]=n.sender,t[7]=n.timestamp,t[8]=i,t[9]=a,t[10]=o,t[11]=s,t[12]=c,t[13]=l}else i=t[8],a=t[9],o=t[10],s=t[11],c=t[12],l=t[13];let u;t[45]!==i||t[46]!==a?(u=(0,Q.jsx)(`div`,{className:i,children:a}),t[45]=i,t[46]=a,t[47]=u):u=t[47];let d;t[48]!==n.generatedImageData||t[49]!==n.generatedImageUrl?(d=(n.generatedImageUrl||n.generatedImageData)&&(0,Q.jsx)(ya,{src:n.generatedImageData?`data:image/png;base64,${n.generatedImageData}`:n.generatedImageUrl}),t[48]=n.generatedImageData,t[49]=n.generatedImageUrl,t[50]=d):d=t[50];let f;t[51]===n.attachments?f=t[52]:(f=n.attachments&&n.attachments.length>0&&(0,Q.jsx)(`div`,{className:`flex flex-wrap gap-1.5 mt-1`,children:n.attachments.map(Ca)}),t[51]=n.attachments,t[52]=f);let p;t[53]!==o||t[54]!==s||t[55]!==u||t[56]!==d||t[57]!==f?(p=(0,Q.jsxs)(`div`,{className:o,children:[s,u,d,f]}),t[53]=o,t[54]=s,t[55]=u,t[56]=d,t[57]=f,t[58]=p):p=t[58];let m;return t[59]!==p||t[60]!==c||t[61]!==l?(m=(0,Q.jsxs)(`div`,{className:c,children:[l,p]}),t[59]=p,t[60]=c,t[61]=l,t[62]=m):m=t[62],m}function Ca(e,t){return(0,Q.jsxs)(`span`,{className:`flex items-center gap-1 rounded-md bg-muted px-2 py-1 text-[10px] text-muted-foreground`,children:[(0,Q.jsx)(Xe,{className:`h-2.5 w-2.5`}),e.fileName]},t)}function wa(e,t){return(0,Q.jsx)(_a,{toolCallId:e.id,question:JSON.stringify(e.input?.question??``),options:e.input?.options,context:e.input?.context},`ask-${t}`)}function Ta(e){return e.type===`tool_use`&&e.name===`ask_user`}function Ea(e){let t=(0,Z.c)(21),{segments:n,model:r}=e,i,a,o,s,c;if(t[0]!==r||t[1]!==n){let e=jr(n),l=t=>e[t].type===`reasoning`?e.slice(t+1).length>0:!1;s=`group flex gap-3 px-4 py-4`,t[7]===Symbol.for(`react.memo_cache_sentinel`)?(c=(0,Q.jsx)(`div`,{className:`flex h-7 w-7 shrink-0 self-end items-center justify-center rounded-full bg-brand animate-radial-pulse-brand`,children:(0,Q.jsx)(Ye,{className:`h-3.5 w-3.5 text-white`})}),t[7]=c):c=t[7],i=`flex flex-1 flex-col gap-1 min-w-0`;let u;t[8]===Symbol.for(`react.memo_cache_sentinel`)?(u=(0,Q.jsx)(`span`,{className:`text-xs font-medium text-foreground`,children:`Agent`}),t[8]=u):u=t[8];let d;t[9]===r?d=t[10]:(d=r&&(0,Q.jsxs)(`span`,{className:`flex items-center gap-1 text-[10px] text-muted-foreground opacity-0 group-hover:opacity-100 transition-opacity`,children:[(0,Q.jsx)(G,{className:`h-2.5 w-2.5`}),Xr(r)]}),t[9]=r,t[10]=d),t[11]===d?a=t[12]:(a=(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[u,d]}),t[11]=d,t[12]=a),o=e.length>0?(()=>{let t=va(e),n=e.filter(Oa);return(0,Q.jsxs)(`div`,{className:`rounded-xl bg-muted px-4 py-3 text-foreground flex flex-col gap-0.5 min-w-0`,children:[e.map((t,n)=>t.type===`tool_use`&&t.name===`todo`||t.type===`tool-result`&&t.toolName===`todo`?t.type===`tool-result`?(0,Q.jsx)(ma,{inline:!0,block:t},`b-${n}`):null:t.type===`tool_use`&&t.name===`ask_user`?null:(0,Q.jsx)(`div`,{children:t.type===`reasoning`&&`text`in t?(0,Q.jsx)(ha,{text:Mr(t.text),isStreaming:!0,hasContentAfter:l(n)}):t.type===`text`&&`text`in t?(0,Q.jsx)(Ni,{content:Mr(t.text)}):t.type===`tool_use`?xa(t,void 0,!0,ba(e,t.id)):t.type===`tool-result`?(0,Q.jsx)(ma,{inline:!0,block:t}):null},`b-${n}`)),t.length>0&&(0,Q.jsx)(ua,{todos:t}),n.map(Da)]})})():(0,Q.jsx)(`div`,{className:`rounded-xl bg-muted px-4 py-3 min-w-0`,children:(0,Q.jsxs)(`div`,{className:`flex items-center justify-center gap-1.5`,children:[(0,Q.jsx)(`div`,{className:`h-2 w-2 rounded-full bg-muted-foreground/40 animate-bounce [animation-delay:0ms]`}),(0,Q.jsx)(`div`,{className:`h-2 w-2 rounded-full bg-muted-foreground/40 animate-bounce [animation-delay:150ms]`}),(0,Q.jsx)(`div`,{className:`h-2 w-2 rounded-full bg-muted-foreground/40 animate-bounce [animation-delay:300ms]`})]})}),t[0]=r,t[1]=n,t[2]=i,t[3]=a,t[4]=o,t[5]=s,t[6]=c}else i=t[2],a=t[3],o=t[4],s=t[5],c=t[6];let l;t[13]!==i||t[14]!==a||t[15]!==o?(l=(0,Q.jsxs)(`div`,{className:i,children:[a,o]}),t[13]=i,t[14]=a,t[15]=o,t[16]=l):l=t[16];let u;return t[17]!==s||t[18]!==c||t[19]!==l?(u=(0,Q.jsxs)(`div`,{className:s,children:[c,l]}),t[17]=s,t[18]=c,t[19]=l,t[20]=u):u=t[20],u}function Da(e,t){return(0,Q.jsx)(_a,{toolCallId:e.id,question:JSON.stringify(e.input?.question??``),options:e.input?.options,context:e.input?.context},`ask-${t}`)}function Oa(e){return e.type===`tool_use`&&e.name===`ask_user`}var ka=(0,X.memo)(Ea,(e,t)=>{if(e.model!==t.model||e.segments.length!==t.segments.length)return!1;for(let n=0;n<e.segments.length;n++){if(e.segments[n].type!==t.segments[n].type||e.segments[n].chunks.length!==t.segments[n].chunks.length)return!1;for(let r=0;r<e.segments[n].chunks.length;r++)if(e.segments[n].chunks[r]!==t.segments[n].chunks[r])return!1}return!0});function Aa(e){let t=(0,Z.c)(34),{projects:n,onSelectProject:r,onCreateThread:i,onConnectRepo:a,onNewApp:o,onOpenFolder:s}=e,c;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(c=(0,Q.jsx)(`img`,{src:`/tarsk-color.svg`,alt:`Tarsk`,className:`h-16 w-16 rounded-lg`}),t[0]=c):c=t[0];let l;t[1]===Symbol.for(`react.memo_cache_sentinel`)?(l=(0,Q.jsx)(`h1`,{className:`text-2xl font-semibold tracking-tight text-foreground text-balance`,children:`Let's build it!`}),t[1]=l):l=t[1];let u=n.length===0?`Start or connect your first project`:`Select a project to start coding`,d;t[2]===u?d=t[3]:(d=(0,Q.jsxs)(`div`,{className:`flex flex-col items-center gap-3`,children:[c,(0,Q.jsxs)(`div`,{className:`text-center`,children:[l,(0,Q.jsx)(`p`,{className:`mt-1 text-base text-muted-foreground`,children:u})]})]}),t[2]=u,t[3]=d);let f;if(t[4]!==i||t[5]!==r||t[6]!==n){let e;t[8]!==i||t[9]!==r?(e=e=>(0,Q.jsxs)(`button`,{type:`button`,className:`flex w-56 flex-col gap-2 rounded-xl border border-border bg-background p-4 text-left shadow-sm transition-colors hover:bg-muted`,onClick:()=>{e.threads.length===0?i(e.projectId):r(e.projectId,e.threads[0].threadId)},children:[(0,Q.jsx)(m,{className:`h-5 w-5 text-muted-foreground`}),(0,Q.jsx)(`span`,{className:`text-sm text-foreground leading-snug font-medium`,children:e.name}),(0,Q.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[e.threads.length,` thread`,e.threads.length===1?``:`s`]})]},e.projectId),t[8]=i,t[9]=r,t[10]=e):e=t[10],f=n.map(e),t[4]=i,t[5]=r,t[6]=n,t[7]=f}else f=t[7];let p,h,g;t[11]===Symbol.for(`react.memo_cache_sentinel`)?(p=(0,Q.jsx)(st,{className:`h-5 w-5 text-muted-foreground`}),h=(0,Q.jsx)(`span`,{className:`text-sm text-foreground leading-snug font-medium`,children:`Connect a repo`}),g=(0,Q.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`Clone an existing repository`}),t[11]=p,t[12]=h,t[13]=g):(p=t[11],h=t[12],g=t[13]);let _;t[14]===a?_=t[15]:(_=(0,Q.jsxs)(`button`,{type:`button`,className:`flex w-56 flex-col gap-2 rounded-xl border border-border bg-background p-4 text-left shadow-sm transition-colors hover:bg-muted`,onClick:a,children:[p,h,g]}),t[14]=a,t[15]=_);let v,y,b;t[16]===Symbol.for(`react.memo_cache_sentinel`)?(v=(0,Q.jsx)(V,{className:`h-5 w-5 text-muted-foreground`}),y=(0,Q.jsx)(`span`,{className:`text-sm text-foreground leading-snug font-medium`,children:`New App`}),b=(0,Q.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`Create a new project from template`}),t[16]=v,t[17]=y,t[18]=b):(v=t[16],y=t[17],b=t[18]);let x;t[19]===o?x=t[20]:(x=(0,Q.jsxs)(`button`,{type:`button`,className:`flex w-56 flex-col gap-2 rounded-xl border border-border bg-background p-4 text-left shadow-sm transition-colors hover:bg-muted`,onClick:o,children:[v,y,b]}),t[19]=o,t[20]=x);let S,C,w;t[21]===Symbol.for(`react.memo_cache_sentinel`)?(S=(0,Q.jsx)(je,{className:`h-5 w-5 text-muted-foreground`}),C=(0,Q.jsx)(`span`,{className:`text-sm text-foreground leading-snug font-medium`,children:`Open Folder`}),w=(0,Q.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`Use an existing local folder`}),t[21]=S,t[22]=C,t[23]=w):(S=t[21],C=t[22],w=t[23]);let T;t[24]===s?T=t[25]:(T=(0,Q.jsxs)(`button`,{type:`button`,className:`flex w-56 flex-col gap-2 rounded-xl border border-border bg-background p-4 text-left shadow-sm transition-colors hover:bg-muted`,onClick:s,children:[S,C,w]}),t[24]=s,t[25]=T);let E;t[26]!==x||t[27]!==T||t[28]!==f||t[29]!==_?(E=(0,Q.jsxs)(`div`,{className:`flex flex-wrap justify-center gap-3`,children:[f,_,x,T]}),t[26]=x,t[27]=T,t[28]=f,t[29]=_,t[30]=E):E=t[30];let D;return t[31]!==E||t[32]!==d?(D=(0,Q.jsxs)(`div`,{className:`mx-auto flex max-w-3xl flex-1 flex-col items-center justify-center gap-8 px-4`,children:[d,E]}),t[31]=E,t[32]=d,t[33]=D):D=t[33],D}function ja(e){let t=(0,Z.c)(37),{messages:n,isStreaming:r,streamingSegments:i,streamingModel:a,isCreatingProject:o,isProcessingThread:s,selectedThreadId:c,projects:l,projectsLoading:u,onSelectThread:d,onCreateThread:f,onConnectRepo:p,onNewApp:m,onOpenFolder:h,error:g,onClearError:_}=e,v=(0,X.useRef)(null),y;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(y=()=>{v.current&&(v.current.scrollTop=v.current.scrollHeight)},t[0]=y):y=t[0];let b;t[1]!==n||t[2]!==i?(b=[n,i],t[1]=n,t[2]=i,t[3]=b):b=t[3],(0,X.useEffect)(y,b);let x=n.length===0&&!r&&!o&&!c,S=x&&`flex flex-col items-center justify-center`,C;t[4]===S?C=t[5]:(C=K(`flex-1 overflow-y-auto`,S),t[4]=S,t[5]=C);let w;t[6]!==p||t[7]!==f||t[8]!==m||t[9]!==h||t[10]!==d||t[11]!==l||t[12]!==u||t[13]!==x?(w=x&&(0,Q.jsx)(`div`,{className:`transition-opacity duration-500 ease-in-out ${u?`opacity-0`:`opacity-100`}`,children:(0,Q.jsx)(Aa,{projects:l,onSelectProject:d,onCreateThread:f,onConnectRepo:p,onNewApp:m,onOpenFolder:h})}),t[6]=p,t[7]=f,t[8]=m,t[9]=h,t[10]=d,t[11]=l,t[12]=u,t[13]=x,t[14]=w):w=t[14];let T;t[15]===n?T=t[16]:(T=n.map(Ma),t[15]=n,t[16]=T);let E;t[17]!==o||t[18]!==s||t[19]!==r||t[20]!==a||t[21]!==i?(E=(r||o||s)&&(0,Q.jsx)(ka,{segments:i,model:a}),t[17]=o,t[18]=s,t[19]=r,t[20]=a,t[21]=i,t[22]=E):E=t[22];let D;t[23]!==g||t[24]!==_?(D=g&&(0,Q.jsxs)(`div`,{className:`mx-4 my-2 rounded-lg border border-destructive/30 bg-destructive/5 px-4 py-3`,children:[(0,Q.jsx)(`p`,{className:`text-sm text-destructive`,children:g}),(0,Q.jsx)(`button`,{type:`button`,className:`mt-1 text-xs text-destructive underline underline-offset-2 hover:text-destructive/80`,onClick:_,children:`Dismiss`})]}),t[23]=g,t[24]=_,t[25]=D):D=t[25];let O;t[26]!==T||t[27]!==E||t[28]!==D?(O=(0,Q.jsxs)(`div`,{className:`mx-auto max-w-3xl pb-4 w-full min-w-0`,children:[T,E,D]}),t[26]=T,t[27]=E,t[28]=D,t[29]=O):O=t[29];let k;t[30]!==c||t[31]!==O?(k=(0,Q.jsx)(ia,{children:O},c),t[30]=c,t[31]=O,t[32]=k):k=t[32];let A;return t[33]!==k||t[34]!==C||t[35]!==w?(A=(0,Q.jsxs)(`div`,{ref:v,className:C,children:[w,k]}),t[33]=k,t[34]=C,t[35]=w,t[36]=A):A=t[36],A}function Ma(e){return(0,Q.jsx)(Sa,{message:e},e.messageId)}var Na=()=>{if(typeof window>`u`)return null;let e=window.SpeechRecognition||window.webkitSpeechRecognition;return e?new e:null};function Pa(){let e=(0,Z.c)(14),[t,n]=(0,X.useState)(!1),[r,i]=(0,X.useState)(``),[a,o]=(0,X.useState)(null),[s,c]=(0,X.useState)(!1),l=(0,X.useRef)(null),u=(0,X.useRef)(``),d,f;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(d=()=>{try{let e=Na();e?(e.continuous=!0,e.interimResults=!0,e.lang=`en-US`,e.onstart=()=>{n(!0),o(null),u.current=``},e.onresult=e=>{let t=``;for(let n=e.resultIndex;n<e.results.length;n++){let r=e.results[n][0].transcript;e.results[n].isFinal?i(e=>e+r+` `):t+=r}u.current=t},e.onerror=e=>{console.error(`Speech recognition error:`,e.error),o(e.error||`An error occurred during speech recognition`)},e.onend=()=>{n(!1)},l.current=e,c(!0)):(c(!1),o(`Speech Recognition API is not supported in your browser`))}catch(e){let t=e;console.error(`Failed to initialize speech recognition:`,t),c(!1),o(`Failed to initialize speech recognition`)}return()=>{l.current&&l.current.abort()}},f=[],e[0]=d,e[1]=f):(d=e[0],f=e[1]),(0,X.useEffect)(d,f);let p;e[2]===t?p=e[3]:(p=()=>{l.current&&!t&&l.current.start()},e[2]=t,e[3]=p);let m=p,h;e[4]===t?h=e[5]:(h=()=>{l.current&&t&&l.current.stop()},e[4]=t,e[5]=h);let g=h,_;e[6]===Symbol.for(`react.memo_cache_sentinel`)?(_=()=>{i(``),u.current=``},e[6]=_):_=e[6];let v=_,y;return e[7]!==a||e[8]!==t||e[9]!==s||e[10]!==m||e[11]!==g||e[12]!==r?(y={isListening:t,transcript:r,error:a,startListening:m,stopListening:g,resetTranscript:v,isSupported:s},e[7]=a,e[8]=t,e[9]=s,e[10]=m,e[11]=g,e[12]=r,e[13]=y):y=e[13],y}function Fa({initialValue:e}={}){let{state:t,dispatch:n}=Ar(),[r,i]=(0,X.useState)(e??``),[a,o]=(0,X.useState)(-1),[s,c]=(0,X.useState)(``),[l,u]=(0,X.useState)(0),[d,f]=(0,X.useState)([]),[p,m]=(0,X.useState)(()=>(t.selectedThreadId?t.projectModelSelections[t.selectedThreadId]:void 0)??null),h=(0,X.useRef)(p?.id??``),g=(0,X.useRef)(p?.provider??``),_=(0,X.useRef)(null),[v,y]=(0,X.useState)(!1),[b,x]=(0,X.useState)(!1),[S,C]=(0,X.useState)([]),[w,T]=(0,X.useState)(!1),[E,D]=(0,X.useState)(!1),[O,k]=(0,X.useState)([]),[A,j]=(0,X.useState)(null),[M,N]=(0,X.useState)([]),[P,F]=(0,X.useState)(!1),[I,L]=(0,X.useState)(``),[R,z]=(0,X.useState)(0),[B,V]=(0,X.useState)([]),[ee,H]=(0,X.useState)([]),[te,ne]=(0,X.useState)(!1),[re,U]=(0,X.useState)(``),W=(0,X.useRef)(null),ie=(0,X.useRef)(null),ae=(0,X.useRef)(null),oe=(0,X.useRef)(null),se=(0,X.useRef)(null),ce=(0,X.useRef)(null);(0,X.useEffect)(()=>{h.current=p?.id??``,g.current=p?.provider??``},[p?.id,p?.provider]);let le=(0,X.useCallback)((e,r)=>{m(e);let i=t.selectedThreadId;if(!i||(n({type:Y.SetProjectModel,threadId:i,model:e}),r?.persist===!1))return;let a=`${i}:${e.provider??``}:${e.id}`;_.current!==a&&(_.current=a,console.log(`[useChatInputState] Persisting model to thread:`,{threadId:i,model:{id:e.id,provider:e.provider}}),nt(i,{model:e.id,modelProvider:e.provider}).then(()=>{_.current===a&&(_.current=null),console.log(`[useChatInputState] Model persisted successfully`)}).catch(e=>{_.current===a&&(_.current=null),console.error(`Failed to save model to thread:`,e)}))},[t.selectedThreadId,n]);(0,X.useEffect)(()=>{(async()=>{let e=t.selectedProjectId?t.projects.find(e=>e.projectId===t.selectedProjectId)?.threads.find(e=>e.threadId===t.selectedThreadId):void 0,n=t.selectedThreadId?t.projectModelSelections[t.selectedThreadId]:void 0,r=e?.model??n?.id??null,i=e?.modelProvider??n?.provider??null;console.log(`[useChatInputState] Loading models for thread:`,{threadId:t.selectedThreadId,projectId:t.selectedProjectId,currentThread:e?{model:e.model,modelProvider:e.modelProvider}:void 0,storedModel:n?{id:n.id,provider:n.provider}:void 0,savedModelId:r,savedModelProvider:i});try{let e=await Se(),t=Object.values(e).flat();if(t.length===0){f([]),m(null);return}f(t);let n=r&&i?t.find(e=>e.id===r&&e.provider===i)??null:null,a=t[0],o=n??a,s=!n&&!!(r||i),c=h.current===o.id&&g.current===o.provider;console.log(`[useChatInputState] Model selection decision:`,{matchedSavedModel:n?{id:n.id}:null,fallbackModel:{id:a.id},modelToSelect:{id:o.id},shouldPersistFallback:s,hasSameSelection:c,currentSelected:{id:h.current,provider:g.current}}),c||le(o,{persist:s})}catch(e){console.error(`Failed to load enabled models:`,e)}})()},[t.selectedThreadId,t.selectedProjectId,t.projects,le]);let ue=(0,X.useRef)(le);(0,X.useEffect)(()=>{ue.current=le},[le]),(0,X.useEffect)(()=>{t.configUpdatedAt!==0&&(async()=>{try{let e=await Se(),t=Object.values(e).flat();if(t.length>0){f(t);let e=h.current,n=g.current;t.some(t=>t.id===e&&t.provider===n)||ue.current(t[0],{persist:!0})}}catch(e){console.error(`Failed to reload enabled models:`,e)}})()},[t.configUpdatedAt]),(0,X.useEffect)(()=>{!E||O.length>0||(async()=>{try{let e=await Ze(),t=Object.values(e).flat();t.length>0&&(k(t),j(e=>e??t[0]))}catch(e){console.error(`Failed to load image models:`,e)}})()},[E,O.length]);let[de,fe]=(0,X.useState)(t.selectedThreadId);return(0,X.useEffect)(()=>{t.selectedThreadId!==de&&setTimeout(()=>{fe(t.selectedThreadId),N([]),F(!1),V([]),H([]),ne(!1),T(!1),D(!1)},0)},[t.selectedThreadId,de]),(0,X.useEffect)(()=>{t.selectedThreadId&&Sn(t.selectedThreadId).then(({commands:e,skills:t})=>{console.log(`Loaded slash commands:`,e,`skills:`,t),V(e),H(t)}).catch(e=>console.error(`Failed to load slash commands and skills:`,e))},[t.selectedThreadId]),(0,X.useEffect)(()=>{t.focusChatInput&&t.selectedThreadId&&!t.isStreaming&&(ie.current?.focus(),n({type:Y.ClearFocusChatInput}))},[t.focusChatInput,t.selectedThreadId,t.isStreaming,n]),(0,X.useEffect)(()=>{let e=e=>{ae.current&&!ae.current.contains(e.target)&&y(!1),oe.current&&!oe.current.contains(e.target)&&x(!1)};if(v||b)return document.addEventListener(`mousedown`,e),()=>{document.removeEventListener(`mousedown`,e)}},[v,b]),{message:r,setMessage:i,historyIndex:a,setHistoryIndex:o,draftMessage:s,setDraftMessage:c,cursorPosition:l,setCursorPosition:u,availableModels:d,setAvailableModels:f,selectedModel:p,setSelectedModel:le,selectedModelIdRef:h,showModelMenu:v,setShowModelMenu:y,showPlusMenu:b,setShowPlusMenu:x,attachments:S,setAttachments:C,planMode:w,setPlanMode:T,imageMode:E,setImageMode:D,availableImageModels:O,setAvailableImageModels:k,selectedImageModel:A,setSelectedImageModel:j,allFiles:M,setAllFiles:N,showSuggestions:P,setShowSuggestions:F,suggestionQuery:I,setSuggestionQuery:L,selectedIndex:R,setSelectedIndex:z,slashCommands:B,setSlashCommands:V,skills:ee,setSkills:H,showCommandSuggestions:te,setShowCommandSuggestions:ne,commandQuery:re,setCommandQuery:U,fileInputRef:W,textareaRef:ie,modelMenuRef:ae,plusMenuRef:oe,suggestionsRef:se,commandSuggestionsRef:ce,handleNewChat:async()=>{if(t.selectedThreadId)try{let e=await yn(t.selectedThreadId);n({type:Y.ClearMessages}),console.log(`New conversation started:`,e);let r=await yt(t.selectedThreadId);n({type:Y.SetMessages,messages:r.messages})}catch(e){console.error(`Failed to start new chat:`,e)}},state:t,dispatch:n}}var Ia=e=>{mt(e)};function La(e){let t=(0,Z.c)(99),{message:n,setMessage:r,attachments:i,selectedModel:a,onSend:o,isStreaming:s,selectedThreadId:c,isListening:l,stopListening:u,resetTranscript:d,dispatch:f,historyIndex:p,setHistoryIndex:m,draftMessage:h,setDraftMessage:g,cursorPosition:_,setCursorPosition:v,showSuggestions:y,setShowSuggestions:b,suggestionQuery:x,setSuggestionQuery:S,allFiles:C,setAllFiles:w,selectedIndex:T,setSelectedIndex:E,showCommandSuggestions:D,setShowCommandSuggestions:O,commandQuery:k,setCommandQuery:A,slashCommands:j,skills:M,textareaRef:N,setAttachments:P,planMode:F,setPlanMode:I,imageMode:L,selectedImageModel:R}=e,z;t[0]!==i||t[1]!==f||t[2]!==L||t[3]!==l||t[4]!==s||t[5]!==n||t[6]!==o||t[7]!==F||t[8]!==d||t[9]!==R||t[10]!==a||t[11]!==c||t[12]!==P||t[13]!==g||t[14]!==m||t[15]!==r||t[16]!==u||t[17]!==N?(z=()=>{if(!n.trim()&&i.length===0||!c)return;let e=L?R:a;e&&(l&&(u(),d()),s?f({type:Y.EnqueueChatMessage,message:{id:`queued-${Date.now()}`,threadId:c,message:n,model:e.id,attachments:i,provider:e.provider,planMode:F,imageMode:L}}):o(n,e.id,i,e.provider,F,L),Ia(n),r(``),P([]),m(-1),g(``),N.current&&(N.current.style.height=`auto`))},t[0]=i,t[1]=f,t[2]=L,t[3]=l,t[4]=s,t[5]=n,t[6]=o,t[7]=F,t[8]=d,t[9]=R,t[10]=a,t[11]=c,t[12]=P,t[13]=g,t[14]=m,t[15]=r,t[16]=u,t[17]=N,t[18]=z):z=t[18];let B=z,V;t[19]!==_||t[20]!==n||t[21]!==r||t[22]!==b||t[23]!==x||t[24]!==N?(V=e=>{let t=n.substring(0,_-x.length-1);r(`${t}${e} ${n.substring(_)}`),b(!1),setTimeout(()=>{if(N.current){N.current.focus();let n=t.length+e.length+1;N.current.setSelectionRange(n,n)}},0)},t[19]=_,t[20]=n,t[21]=r,t[22]=b,t[23]=x,t[24]=N,t[25]=V):V=t[25];let ee=V,H;t[26]!==k||t[27]!==_||t[28]!==n||t[29]!==r||t[30]!==I||t[31]!==O||t[32]!==N?(H=e=>{let t=n.substring(0,_-k.length-1),i=n.substring(_);r(`${t}${e.content}${i}`),O(!1),setTimeout(()=>{if(N.current){N.current.focus();let n=t.length+e.content.length;N.current.setSelectionRange(n,n)}},0),e.metadata.mode===`plan`&&I(!0)},t[26]=k,t[27]=_,t[28]=n,t[29]=r,t[30]=I,t[31]=O,t[32]=N,t[33]=H):H=t[33];let te=H,ne;t[34]!==k||t[35]!==_||t[36]!==n||t[37]!==r||t[38]!==O||t[39]!==N?(ne=e=>{let t=n.substring(0,_-k.length-1),i=n.substring(_),a=e.name.includes(` `)?`/"${e.name}"`:`/${e.name}`;r(`${t}${a}${i}`),O(!1),setTimeout(()=>{if(N.current){N.current.focus();let e=t.length+a.length;N.current.setSelectionRange(e,e)}},0)},t[34]=k,t[35]=_,t[36]=n,t[37]=r,t[38]=O,t[39]=N,t[40]=ne):ne=t[40];let re=ne,U,W,ie,ae;if(t[41]!==C||t[42]!==k||t[43]!==h||t[44]!==B||t[45]!==p||t[46]!==te||t[47]!==ee||t[48]!==re||t[49]!==n||t[50]!==T||t[51]!==c||t[52]!==w||t[53]!==A||t[54]!==v||t[55]!==g||t[56]!==m||t[57]!==r||t[58]!==E||t[59]!==O||t[60]!==b||t[61]!==S||t[62]!==D||t[63]!==y||t[64]!==M||t[65]!==j||t[66]!==x){ie=e=>{if(D){if(e.key===`ArrowDown`){e.preventDefault(),E((T+1)%U.length);return}if(e.key===`ArrowUp`){e.preventDefault(),E((T-1+U.length)%U.length);return}if(e.key===`Enter`||e.key===`Tab`){e.preventDefault();let t=U[T];t&&(t.type===`command`?te(t.data):re(t.data));return}if(e.key===`Escape`){O(!1);return}}if(y){let t=W.length>0;if(e.key===`ArrowDown`&&t){e.preventDefault(),E((T+1)%W.length);return}if(e.key===`ArrowUp`&&t){e.preventDefault(),E((T-1+W.length)%W.length);return}if(e.key===`Enter`||e.key===`Tab`){e.preventDefault(),W[T]&&ee(W[T]);return}if(e.key===`Escape`){b(!1);return}}if(e.key===`Enter`&&!e.shiftKey){e.preventDefault(),B();return}let t=Vt();t.length!==0&&(e.key===`ArrowUp`?(e.preventDefault(),p===-1?(g(n),m(t.length-1),r(t[t.length-1])):p>0&&(m(p-1),r(t[p-1]))):e.key===`ArrowDown`&&(e.preventDefault(),p>0?(m(p-1),r(t[p-1])):p===0&&(m(-1),r(h))))};let e;t[71]!==C||t[72]!==c||t[73]!==w||t[74]!==A||t[75]!==v||t[76]!==r||t[77]!==E||t[78]!==O||t[79]!==b||t[80]!==S?(e=e=>{let t=e.target.value,n=e.target.selectionStart;r(t),v(n);let i=t.substring(0,n),a=i.lastIndexOf(`/`);if(a!==-1){let e=a>0?i[a-1]:``;if(a===0||/\s/.test(e)){let e=i.substring(a+1);e.includes(` `)?O(!1):(A(e),O(!0),b(!1),E(0))}else O(!1)}else{O(!1);let e=i.lastIndexOf(`#`);if(e!==-1){let t=e>0?i[e-1]:``;if(e===0||/\s/.test(t)){let t=i.substring(e+1);t.includes(` `)?b(!1):(S(t),b(!0),E(0),C.length===0&&c&&_e(c).then(e=>{w(e)}).catch(Ba))}else b(!1)}else b(!1)}let o=e.target;o.style.height=`auto`,o.style.height=`${Math.min(o.scrollHeight,160)}px`},t[71]=C,t[72]=c,t[73]=w,t[74]=A,t[75]=v,t[76]=r,t[77]=E,t[78]=O,t[79]=b,t[80]=S,t[81]=e):e=t[81],ae=e;let i;if(t[82]!==k||t[83]!==M||t[84]!==j){let e;t[86]===k?e=t[87]:(e=e=>e.name.toLowerCase().includes(k.toLowerCase()),t[86]=k,t[87]=e);let n=j.filter(e),r;t[88]===k?r=t[89]:(r=e=>e.name.toLowerCase().includes(k.toLowerCase()),t[88]=k,t[89]=r);let a=M.filter(r);i=[...n.map(za),...a.map(Ra)],t[82]=k,t[83]=M,t[84]=j,t[85]=i}else i=t[85];U=i.slice(0,10),W=y?C.filter(e=>e.toLowerCase().includes(x.toLowerCase())).slice(0,10):[],t[41]=C,t[42]=k,t[43]=h,t[44]=B,t[45]=p,t[46]=te,t[47]=ee,t[48]=re,t[49]=n,t[50]=T,t[51]=c,t[52]=w,t[53]=A,t[54]=v,t[55]=g,t[56]=m,t[57]=r,t[58]=E,t[59]=O,t[60]=b,t[61]=S,t[62]=D,t[63]=y,t[64]=M,t[65]=j,t[66]=x,t[67]=U,t[68]=W,t[69]=ie,t[70]=ae}else U=t[67],W=t[68],ie=t[69],ae=t[70];let oe;return t[90]!==U||t[91]!==W||t[92]!==ie||t[93]!==B||t[94]!==ae||t[95]!==te||t[96]!==ee||t[97]!==re?(oe={handleSend:B,handleKeyDown:ie,handleTextareaInput:ae,insertFileReference:ee,insertCommand:te,insertSkill:re,allSuggestions:U,fileSuggestions:W},t[90]=U,t[91]=W,t[92]=ie,t[93]=B,t[94]=ae,t[95]=te,t[96]=ee,t[97]=re,t[98]=oe):oe=t[98],oe}function Ra(e){return{type:`skill`,data:e}}function za(e){return{type:`command`,data:e}}function Ba(e){return console.error(`Failed to fetch files:`,e)}function Va(e){let t=(0,Z.c)(21),{visible:n,commands:r,skills:i,query:a,selectedIndex:o,onSelectCommand:s,onSelectSkill:c,onMouseEnterSuggestion:l,containerRef:u}=e;if(!n)return null;let d;if(t[0]!==r||t[1]!==a||t[2]!==i){let e;t[4]===a?e=t[5]:(e=e=>e.name.toLowerCase().includes(a.toLowerCase()),t[4]=a,t[5]=e);let n=r.filter(e),o;t[6]===a?o=t[7]:(o=e=>e.name.toLowerCase().includes(a.toLowerCase()),t[6]=a,t[7]=o);let s=i.filter(o);d=[...n.map(Ua),...s.map(Ha)].slice(0,10),t[0]=r,t[1]=a,t[2]=i,t[3]=d}else d=t[3];let f=d,p;t[8]===Symbol.for(`react.memo_cache_sentinel`)?(p=(0,Q.jsx)(fe,{className:`h-3 w-3`}),t[8]=p):p=t[8];let m=a&&` matching "${a}"`,h;t[9]===m?h=t[10]:(h=(0,Q.jsxs)(`div`,{className:`px-2 py-1.5 text-xs font-semibold text-muted-foreground border-b border-border/50 mb-1 flex items-center gap-2`,children:[p,`Commands & Skills`,m]}),t[9]=m,t[10]=h);let g;t[11]!==f||t[12]!==l||t[13]!==s||t[14]!==c||t[15]!==o?(g=f.length>0?f.map((e,t)=>{let n=t===o;if(e.type===`command`){let r=e.data;return(0,Q.jsxs)(`button`,{type:`button`,className:K(`flex w-full flex-col gap-1 rounded-lg px-3 py-2 text-left transition-colors`,n?`bg-accent text-accent-foreground`:`text-popover-foreground hover:bg-accent/50`),onClick:()=>s(r),onMouseEnter:()=>l(t),children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(fe,{className:`h-3 w-3 text-muted-foreground`}),(0,Q.jsxs)(`span`,{className:`font-medium`,children:[`/`,r.name]}),r.metadata.argumentHint&&(0,Q.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:r.metadata.argumentHint}),r.scope===`project`&&(0,Q.jsx)(`span`,{className:`ml-auto text-[10px] rounded-full bg-primary/10 px-1.5 py-0.5 text-primary`,children:`project`})]}),r.metadata.description&&(0,Q.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:r.metadata.description})]},`cmd-${r.name}`)}else{let r=e.data;return(0,Q.jsxs)(`button`,{type:`button`,className:K(`flex w-full flex-col gap-1 rounded-lg px-3 py-2 text-left transition-colors`,n?`bg-accent text-accent-foreground`:`text-popover-foreground hover:bg-accent/50`),onClick:()=>c(r),onMouseEnter:()=>l(t),children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(Pe,{className:`h-3 w-3 text-amber-500`}),(0,Q.jsxs)(`span`,{className:`font-medium`,children:[`/`,r.name]}),(0,Q.jsx)(`span`,{className:`ml-auto text-[10px] rounded-full bg-amber-500/10 px-1.5 py-0.5 text-amber-700 dark:text-amber-400`,children:`skill`}),r.scope===`project`&&(0,Q.jsx)(`span`,{className:`text-[10px] rounded-full bg-primary/10 px-1.5 py-0.5 text-primary`,children:`project`})]}),(0,Q.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:r.description})]},`skill-${r.name}`)}}):(0,Q.jsxs)(`div`,{className:`px-3 py-4 text-center text-xs text-muted-foreground`,children:[`No commands or skills found.`,(0,Q.jsx)(`br`,{}),(0,Q.jsxs)(`span`,{className:`text-[10px]`,children:[`Create commands in `,(0,Q.jsx)(`code`,{className:`bg-muted px-1 rounded`,children:`.agents/commands/`}),` or skills in `,(0,Q.jsx)(`code`,{className:`bg-muted px-1 rounded`,children:`.agents/skills/`})]})]}),t[11]=f,t[12]=l,t[13]=s,t[14]=c,t[15]=o,t[16]=g):g=t[16];let _;return t[17]!==u||t[18]!==h||t[19]!==g?(_=(0,Q.jsxs)(`div`,{ref:u,className:`absolute bottom-full left-0 mb-2 w-full max-h-64 overflow-y-auto rounded-xl border border-border bg-popover p-1 shadow-lg z-50 animate-in fade-in slide-in-from-bottom-2`,children:[h,g]}),t[17]=u,t[18]=h,t[19]=g,t[20]=_):_=t[20],_}function Ha(e){return{type:`skill`,data:e}}function Ua(e){return{type:`command`,data:e}}function Wa(e){return e.startsWith(`image/`)}function Ga(e){let t=(0,Z.c)(7),{attachments:n,onRemove:r}=e;if(n.length===0)return null;let i;if(t[0]!==n||t[1]!==r){let e;t[3]===r?e=t[4]:(e=(e,t)=>(0,Q.jsx)(`div`,{className:`group relative flex items-center gap-1 rounded-md bg-muted text-xs text-muted-foreground`,children:Wa(e.mimeType)?(0,Q.jsxs)(`div`,{className:`relative`,children:[(0,Q.jsx)(`img`,{src:`data:${e.mimeType};base64,${e.content}`,alt:e.fileName,className:`h-16 w-16 rounded-md object-cover`}),(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>r(t),className:`absolute -right-1.5 -top-1.5 flex h-4 w-4 items-center justify-center rounded-full bg-foreground text-background opacity-0 transition-opacity group-hover:opacity-100`,children:[(0,Q.jsx)(w,{className:`h-2.5 w-2.5`}),(0,Q.jsx)(`span`,{className:`sr-only`,children:`Remove attachment`})]})]}):(0,Q.jsxs)(`span`,{className:`flex items-center gap-1 px-2 py-1`,children:[(0,Q.jsx)(Xe,{className:`h-3 w-3`}),e.fileName,(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>r(t),className:`ml-1 hover:text-foreground`,children:[(0,Q.jsx)(w,{className:`h-3 w-3`}),(0,Q.jsx)(`span`,{className:`sr-only`,children:`Remove attachment`})]})]})},t),t[3]=r,t[4]=e),i=n.map(e),t[0]=n,t[1]=r,t[2]=i}else i=t[2];let a;return t[5]===i?a=t[6]:(a=(0,Q.jsx)(`div`,{className:`mb-2 flex flex-wrap gap-1.5`,children:i}),t[5]=i,t[6]=a),a}function Ka(e,t){let n=e.target.files;if(!n||n.length===0)return;let r=Array.from(n),i=r.length,a=Array.from({length:i}),o=0;e.target.value=``,r.forEach((e,n)=>{let r=new FileReader;r.onload=()=>{let s=r.result.split(`,`)[1];a[n]={fileName:e.name,content:s,mimeType:e.type||`application/octet-stream`},o+=1,o===i&&t(a)},r.readAsDataURL(e)})}function qa(e){let t=(0,Z.c)(16),{showSuggestions:n,fileSuggestions:r,suggestionQuery:i,selectedIndex:a,onSelectFile:o,onMouseEnterSuggestion:s,containerRef:c}=e;if(!n||r.length===0)return null;let l;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(l=(0,Q.jsx)(Re,{className:`h-3 w-3`}),t[0]=l):l=t[0];let u;t[1]===i?u=t[2]:(u=(0,Q.jsxs)(`div`,{className:`px-2 py-1.5 text-xs font-semibold text-muted-foreground border-b border-border/50 mb-1 flex items-center gap-2`,children:[l,`Files matching "`,i,`"`]}),t[1]=i,t[2]=u);let d;if(t[3]!==r||t[4]!==s||t[5]!==o||t[6]!==a){let e;t[8]!==s||t[9]!==o||t[10]!==a?(e=(e,t)=>{let n=e.split(`/`).pop()??e;return(0,Q.jsxs)(`button`,{type:`button`,className:K(`flex w-full items-center gap-2 rounded-lg px-3 py-2 text-sm text-left transition-colors`,t===a?`bg-accent text-accent-foreground`:`text-popover-foreground hover:bg-accent/50`),onClick:()=>o(e),onMouseEnter:()=>s(t),children:[e.endsWith(`.ts`)||e.endsWith(`.tsx`)||e.endsWith(`.js`)||e.endsWith(`.jsx`)?(0,Q.jsx)(v,{className:`h-4 w-4 text-blue-500`}):(0,Q.jsx)(Ne,{className:`h-4 w-4 text-muted-foreground`}),(0,Q.jsxs)(`div`,{className:`flex flex-col overflow-hidden`,children:[(0,Q.jsx)(`span`,{className:`truncate font-medium`,children:n}),(0,Q.jsx)(`span`,{className:`truncate text-[10px] text-muted-foreground opacity-70`,children:e})]})]},e)},t[8]=s,t[9]=o,t[10]=a,t[11]=e):e=t[11],d=r.map(e),t[3]=r,t[4]=s,t[5]=o,t[6]=a,t[7]=d}else d=t[7];let f;return t[12]!==c||t[13]!==u||t[14]!==d?(f=(0,Q.jsxs)(`div`,{ref:c,className:`absolute bottom-full left-0 mb-2 w-full max-h-64 overflow-y-auto rounded-xl border border-border bg-popover p-1 shadow-lg z-50 animate-in fade-in slide-in-from-bottom-2`,children:[u,d]}),t[12]=c,t[13]=u,t[14]=d,t[15]=f):f=t[15],f}function Ja(e){let t=(0,Z.c)(3),{provider:n}=e;if(!n)return null;let r=`https://models.tarsk.io/svg/${n}.svg`,i=`${n} logo`,a;return t[0]!==r||t[1]!==i?(a=(0,Q.jsx)(`img`,{src:r,alt:i,className:`h-3.5 w-3.5 flex-shrink-0`,onError:Ya}),t[0]=r,t[1]=i,t[2]=a):a=t[2],a}function Ya(e){e.currentTarget.style.visibility=`hidden`}function Xa(e){let t=(0,Z.c)(24),{availableModels:n,selectedModel:r,onModelSelect:i}=e,[a,o]=X.useState(!1),s=X.useRef(null),c,l;t[0]===a?(c=t[1],l=t[2]):(c=()=>{let e=e=>{s.current&&!s.current.contains(e.target)&&o(!1)};if(a)return document.addEventListener(`mousedown`,e),()=>{document.removeEventListener(`mousedown`,e)}},l=[a],t[0]=a,t[1]=c,t[2]=l),X.useEffect(c,l);let u;t[3]===i?u=t[4]:(u=e=>{i(e),o(!1)},t[3]=i,t[4]=u);let d=u,f;t[5]===a?f=t[6]:(f=()=>o(!a),t[5]=a,t[6]=f);let p=r?.provider,m;t[7]===p?m=t[8]:(m=(0,Q.jsx)(Ja,{provider:p}),t[7]=p,t[8]=m);let h;t[9]===r?h=t[10]:(h=r?Xr(r.id):`No model`,t[9]=r,t[10]=h);let g;t[11]===Symbol.for(`react.memo_cache_sentinel`)?(g=(0,Q.jsx)(H,{className:`h-3 w-3`}),t[11]=g):g=t[11];let _;t[12]!==f||t[13]!==m||t[14]!==h?(_=(0,Q.jsxs)(`button`,{type:`button`,className:`flex items-center gap-1 rounded-md px-2 py-1 text-xs text-muted-foreground hover:bg-muted hover:text-foreground transition-colors`,onClick:f,children:[m,h,g]}),t[12]=f,t[13]=m,t[14]=h,t[15]=_):_=t[15];let v;t[16]!==n||t[17]!==d||t[18]!==r?.id||t[19]!==a?(v=a&&(0,Q.jsx)(`div`,{className:`absolute bottom-full left-0 mb-1 w-80 max-h-80 overflow-y-auto rounded-lg border border-border bg-popover p-1 shadow-md z-50`,children:Object.entries(n.reduce(Za,{})).map(e=>{let[t,n]=e;return(0,Q.jsxs)(`div`,{children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-1.5 px-3 py-1.5 text-xs font-semibold text-muted-foreground uppercase tracking-wide`,children:[(0,Q.jsx)(Ja,{provider:t}),t]}),n.map(e=>(0,Q.jsx)(`button`,{type:`button`,className:`flex w-full items-center whitespace-nowrap rounded-md px-3 py-1.5 pl-8 text-sm text-popover-foreground hover:bg-accent ${e.id===r?.id?`bg-accent font-medium`:``}`,onClick:()=>d(e),children:Xr(e.id)},e.id))]},t)})}),t[16]=n,t[17]=d,t[18]=r?.id,t[19]=a,t[20]=v):v=t[20];let y;return t[21]!==v||t[22]!==_?(y=(0,Q.jsxs)(`div`,{className:`relative`,ref:s,children:[_,v]}),t[21]=v,t[22]=_,t[23]=y):y=t[23],y}function Za(e,t){let n=t.provider??`Other`;return e[n]||(e[n]=[]),e[n].push(t),e}function Qa(e){let t=(0,Z.c)(26),{onFileAttach:n,onPlanModeToggle:r,onImageModeToggle:i,onNewChat:a}=e,[o,s]=X.useState(!1),c=X.useRef(null),l,u;t[0]===o?(l=t[1],u=t[2]):(l=()=>{let e=e=>{c.current&&!c.current.contains(e.target)&&s(!1)};if(o)return document.addEventListener(`mousedown`,e),()=>{document.removeEventListener(`mousedown`,e)}},u=[o],t[0]=o,t[1]=l,t[2]=u),X.useEffect(l,u);let d;t[3]===n?d=t[4]:(d=()=>{n(),s(!1)},t[3]=n,t[4]=d);let f=d,p;t[5]===r?p=t[6]:(p=()=>{r(),s(!1)},t[5]=r,t[6]=p);let m=p,h;t[7]===i?h=t[8]:(h=()=>{i(),s(!1)},t[7]=i,t[8]=h);let g=h,_;t[9]===a?_=t[10]:(_=()=>{s(!1),a()},t[9]=a,t[10]=_);let v=_,y;t[11]===o?y=t[12]:(y=()=>s(!o),t[11]=o,t[12]=y);let b,x;t[13]===Symbol.for(`react.memo_cache_sentinel`)?(b=(0,Q.jsx)(te,{}),x=(0,Q.jsx)(`span`,{className:`sr-only`,children:`More options`}),t[13]=b,t[14]=x):(b=t[13],x=t[14]);let C;t[15]===y?C=t[16]:(C=(0,Q.jsxs)(q,{variant:`action`,size:`icon-sm`,onClick:y,children:[b,x]}),t[15]=y,t[16]=C);let w;t[17]!==f||t[18]!==g||t[19]!==v||t[20]!==m||t[21]!==o?(w=o&&(0,Q.jsxs)(`div`,{className:`absolute bottom-full left-0 mb-1 w-48 rounded-lg border border-border bg-popover p-1 shadow-md z-50`,children:[(0,Q.jsxs)(`button`,{type:`button`,className:`flex w-full items-center gap-2 rounded-md px-3 py-2 text-sm text-popover-foreground hover:bg-accent`,onClick:f,children:[(0,Q.jsx)(Xe,{className:`h-3.5 w-3.5`}),`Attach File`]}),(0,Q.jsxs)(`button`,{type:`button`,className:`flex w-full items-center gap-2 rounded-md px-3 py-2 text-sm text-popover-foreground hover:bg-accent`,onClick:m,children:[(0,Q.jsx)(ht,{className:`h-3.5 w-3.5`}),`Plan Mode`]}),(0,Q.jsxs)(`button`,{type:`button`,className:`flex w-full items-center gap-2 rounded-md px-3 py-2 text-sm text-popover-foreground hover:bg-accent`,onClick:g,children:[(0,Q.jsx)(Ht,{className:`h-3.5 w-3.5`}),`Image Mode`]}),(0,Q.jsxs)(`button`,{type:`button`,className:`flex w-full items-center gap-2 rounded-md px-3 py-2 text-sm text-popover-foreground hover:bg-accent`,onClick:v,children:[(0,Q.jsx)(S,{className:`h-3.5 w-3.5`}),`New Chat`]})]}),t[17]=f,t[18]=g,t[19]=v,t[20]=m,t[21]=o,t[22]=w):w=t[22];let T;return t[23]!==C||t[24]!==w?(T=(0,Q.jsxs)(`div`,{className:`relative`,ref:c,children:[C,w]}),t[23]=C,t[24]=w,t[25]=T):T=t[25],T}function $a(e){let t=(0,Z.c)(14),{onToggleSpeech:n}=e,{isListening:r,isSupported:i}=Pa();if(!i)return null;let a=r?`bg-red-500/20 text-red-500 hover:bg-red-500/30`:`text-muted-foreground hover:text-background`,o;t[0]===r?o=t[1]:(o=r?(0,Q.jsx)(it,{}):(0,Q.jsx)(kt,{}),t[0]=r,t[1]=o);let s=r?`Stop listening`:`Start listening`,c;t[2]===s?c=t[3]:(c=(0,Q.jsx)(`span`,{className:`sr-only`,children:s}),t[2]=s,t[3]=c);let l;t[4]!==n||t[5]!==a||t[6]!==o||t[7]!==c?(l=(0,Q.jsx)(Kr,{asChild:!0,children:(0,Q.jsxs)(q,{variant:`ghost`,size:`icon-sm`,className:a,onClick:n,children:[o,c]})}),t[4]=n,t[5]=a,t[6]=o,t[7]=c,t[8]=l):l=t[8];let u=r?`Stop listening`:`Start listening`,d;t[9]===u?d=t[10]:(d=(0,Q.jsx)(Ur,{side:`top`,className:`bg-popover text-popover-foreground`,children:u}),t[9]=u,t[10]=d);let f;return t[11]!==l||t[12]!==d?(f=(0,Q.jsxs)(Gr,{children:[l,d]}),t[11]=l,t[12]=d,t[13]=f):f=t[13],f}function eo({threadId:e,currentConversationId:t,children:n}){let[r,i]=(0,X.useState)(null),[a,o]=(0,X.useState)(null),[s,c]=(0,X.useState)(null),[l,u]=(0,X.useState)(!1),[d,f]=(0,X.useState)(null),[p,m]=(0,X.useState)(!1),[h,g]=(0,X.useState)(!1);if((0,X.useEffect)(()=>{if(!p||h||!e)return;async function n(){u(!0),f(null);try{let n=(await Fe(e)).currentConversationId??t,[r,a]=await Promise.allSettled([Lt(e).catch(e=>{throw console.error(`Thread usage summary failed:`,e),e}),n?sn(e,n).catch(e=>{throw console.error(`Conversation usage failed:`,e),e}):Promise.resolve(null)]);if(r.status===`fulfilled`)i(r.value);else throw console.error(`Failed to fetch thread usage summary:`,r.reason),r.reason;if(a?.status===`fulfilled`&&a.value){if(o(a.value),a.value.model?.model){let e=a.value.model.model,t=a.value.model.provider,n=t&&e?`${t}/${e}`:e;console.log(`Fetching model info for:`,n,`(provider:`,t,`model:`,e+`)`),Bt(n).then(c).catch(e=>{console.warn(`Failed to fetch model info:`,e)})}}else if(a?.status===`rejected`)throw console.error(`Failed to fetch conversation usage:`,a.reason),a.reason;g(!0)}catch(e){console.error(`[TokenUsageTooltip] Failed to load usage data:`,e),f(`Failed to load usage data`)}finally{u(!1)}}n()},[p,h,e,t]),!e||e===``)return console.log(`[TokenUsageTooltip] No valid threadId, returning children only`),(0,Q.jsx)(Q.Fragment,{children:n});let _=e=>e==null||e===0?`0`:e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}K`:e.toString();return e?(0,Q.jsxs)(Gr,{open:p,onOpenChange:e=>{m(e),!e&&h&&g(!1)},children:[(0,Q.jsx)(Kr,{asChild:!0,children:n}),(0,Q.jsx)(Ur,{side:`top`,align:`center`,className:`max-w-xs`,children:(0,Q.jsxs)(`div`,{className:`text-xs text-muted-foreground space-y-2`,children:[l&&(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(B,{className:`h-3 w-3 animate-pulse`}),(0,Q.jsx)(`span`,{children:`Loading usage...`})]}),d&&(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 text-red-500`,children:[(0,Q.jsx)(B,{className:`h-3 w-3`}),(0,Q.jsx)(`span`,{children:`Failed to load usage`})]}),!l&&!d&&r&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(`div`,{className:`space-y-1`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(B,{className:`h-3 w-3`}),(0,Q.jsxs)(`span`,{className:`font-medium`,children:[_(r.totalTokens),` tokens`]})]}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(Nt,{className:`h-3 w-3`}),(0,Q.jsxs)(`span`,{children:[r.conversationCount,` chats`]})]})]}),a&&(0,Q.jsxs)(`div`,{className:`border-t border-border pt-2 space-y-1`,children:[(0,Q.jsx)(`div`,{className:`text-xs font-semibold text-foreground`,children:`Current Chat:`}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(Pe,{className:`h-3 w-3`}),(0,Q.jsxs)(`span`,{children:[((e,t)=>{let n=_(e);return t?`${n} (${Math.round(e/t*100)}%)`:n})(a.footprint?.totalTokens??a.usage.totalTokens,typeof s?.context_length==`number`?s.context_length:void 0),` `,`tokens`]})]}),a.model.model&&(0,Q.jsxs)(`div`,{className:`text-muted-foreground`,children:[a.model.model,s?.context_length&&(0,Q.jsxs)(`span`,{className:`ml-1`,children:[_(typeof s.context_length==`number`?s.context_length:0),` `,`context)`]})]})]}),(0,Q.jsxs)(`div`,{className:`border-t border-border pt-2 flex items-center gap-3 text-[10px] text-muted-foreground`,children:[(0,Q.jsxs)(`span`,{children:[`In: `,_(r.totalInputTokens)]}),(0,Q.jsxs)(`span`,{children:[`Out: `,_(r.totalOutputTokens)]}),(0,Q.jsxs)(`span`,{children:[`Avg: `,_(r.averageTokensPerConversation),`/chat`]})]})]})]})})]}):(0,Q.jsx)(Q.Fragment,{children:n})}function to(e){let t=(0,Z.c)(7),{threadId:n}=e,[r,i]=(0,X.useState)(),a,o;if(t[0]===n?(a=t[1],o=t[2]):(a=()=>{(async function(){if(n)try{i((await Fe(n)).currentConversationId)}catch(e){let t=e;console.error(`Failed to fetch thread data:`,t)}})()},o=[n],t[0]=n,t[1]=a,t[2]=o),(0,X.useEffect)(a,o),!n||n===``)return null;let s;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(s=(0,Q.jsxs)(q,{variant:`ghost`,size:`icon-sm`,className:`text-muted-foreground hover:text-background`,children:[(0,Q.jsx)(Nt,{className:`h-4 w-4`}),(0,Q.jsx)(`span`,{className:`sr-only`,children:`View token usage`})]}),t[3]=s):s=t[3];let c;return t[4]!==r||t[5]!==n?(c=(0,Q.jsx)(eo,{threadId:n,currentConversationId:r,children:s}),t[4]=r,t[5]=n,t[6]=c):c=t[6],c}function no(e){let t=(0,Z.c)(8),{queuedMessages:n,onRemoveQueuedMessage:r}=e;if(n.length===0)return null;let i;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(i=(0,Q.jsx)(`div`,{className:`text-xs font-medium text-muted-foreground`,children:`Queued messages`}),t[0]=i):i=t[0];let a;if(t[1]!==r||t[2]!==n){let e;t[4]===r?e=t[5]:(e=e=>(0,Q.jsxs)(`div`,{className:`flex items-start justify-between gap-3 rounded-md border border-border/60 bg-background px-3 py-2 text-sm`,children:[(0,Q.jsx)(`p`,{className:`flex-1 whitespace-pre-wrap text-foreground`,children:e.message}),(0,Q.jsx)(`button`,{type:`button`,className:`rounded-full p-1 text-muted-foreground transition-colors hover:bg-foreground hover:text-background`,onClick:()=>r(e.id),"aria-label":`Remove queued message`,children:(0,Q.jsx)(w,{className:`h-3.5 w-3.5`})})]},e.id),t[4]=r,t[5]=e),a=n.map(e),t[1]=r,t[2]=n,t[3]=a}else a=t[3];let o;return t[6]===a?o=t[7]:(o=(0,Q.jsxs)(`div`,{className:`mb-3 rounded-lg border border-border/60 bg-muted/30 px-4 py-3`,children:[i,(0,Q.jsx)(`div`,{className:`mt-2 flex flex-col gap-2`,children:a})]}),t[6]=a,t[7]=o),o}function ro(e){let t=(0,Z.c)(152),{onSend:n,onStop:r,isStreaming:i,disabled:a,initialValue:o,queuedMessages:s,onRemoveQueuedMessage:l,isOverlay:u}=e,d=i===void 0?!1:i,f=u===void 0?!1:u,{isListening:p,transcript:m,startListening:h,stopListening:g,resetTranscript:_}=Pa(),v;t[0]===o?v=t[1]:(v={initialValue:o},t[0]=o,t[1]=v);let{message:y,setMessage:b,historyIndex:x,setHistoryIndex:S,draftMessage:C,setDraftMessage:T,cursorPosition:E,setCursorPosition:D,availableModels:O,selectedModel:k,setSelectedModel:A,attachments:j,setAttachments:M,planMode:N,setPlanMode:P,imageMode:F,setImageMode:I,availableImageModels:R,selectedImageModel:z,setSelectedImageModel:B,allFiles:V,setAllFiles:ee,showSuggestions:H,setShowSuggestions:te,suggestionQuery:ne,setSuggestionQuery:re,selectedIndex:U,setSelectedIndex:W,slashCommands:ie,skills:ae,showCommandSuggestions:oe,setShowCommandSuggestions:se,commandQuery:ce,setCommandQuery:le,fileInputRef:ue,textareaRef:de,suggestionsRef:fe,commandSuggestionsRef:pe,handleNewChat:me,state:he,dispatch:ge}=Fa(v),_e=F?z:k,ve=F?R:O,G=he.selectedThreadId??void 0,ye;t[2]!==V||t[3]!==j||t[4]!==ce||t[5]!==E||t[6]!==ge||t[7]!==C||t[8]!==x||t[9]!==F||t[10]!==p||t[11]!==d||t[12]!==y||t[13]!==n||t[14]!==N||t[15]!==_||t[16]!==z||t[17]!==U||t[18]!==k||t[19]!==ee||t[20]!==M||t[21]!==le||t[22]!==D||t[23]!==T||t[24]!==S||t[25]!==b||t[26]!==P||t[27]!==W||t[28]!==se||t[29]!==te||t[30]!==re||t[31]!==oe||t[32]!==H||t[33]!==ae||t[34]!==ie||t[35]!==g||t[36]!==ne||t[37]!==G||t[38]!==de?(ye={message:y,setMessage:b,attachments:j,selectedModel:k,onSend:n,isStreaming:d,selectedThreadId:G,isListening:p,stopListening:g,resetTranscript:_,dispatch:ge,historyIndex:x,setHistoryIndex:S,draftMessage:C,setDraftMessage:T,cursorPosition:E,setCursorPosition:D,showSuggestions:H,setShowSuggestions:te,suggestionQuery:ne,setSuggestionQuery:re,allFiles:V,setAllFiles:ee,selectedIndex:U,setSelectedIndex:W,showCommandSuggestions:oe,setShowCommandSuggestions:se,commandQuery:ce,setCommandQuery:le,slashCommands:ie,skills:ae,textareaRef:de,setAttachments:M,planMode:N,setPlanMode:P,imageMode:F,selectedImageModel:z},t[2]=V,t[3]=j,t[4]=ce,t[5]=E,t[6]=ge,t[7]=C,t[8]=x,t[9]=F,t[10]=p,t[11]=d,t[12]=y,t[13]=n,t[14]=N,t[15]=_,t[16]=z,t[17]=U,t[18]=k,t[19]=ee,t[20]=M,t[21]=le,t[22]=D,t[23]=T,t[24]=S,t[25]=b,t[26]=P,t[27]=W,t[28]=se,t[29]=te,t[30]=re,t[31]=oe,t[32]=H,t[33]=ae,t[34]=ie,t[35]=g,t[36]=ne,t[37]=G,t[38]=de,t[39]=ye):ye=t[39];let{handleSend:be,handleKeyDown:xe,handleTextareaInput:Se,insertFileReference:Ce,insertCommand:we,insertSkill:Te,fileSuggestions:Ee}=La(ye),De=X.useRef(``),Oe,ke;t[40]!==b||t[41]!==m?(Oe=()=>{if(m&&m!==De.current){let e=m.substring(De.current.length);b(t=>(t.endsWith(` `),t+e)),De.current=m}},ke=[m,b],t[40]=b,t[41]=m,t[42]=Oe,t[43]=ke):(Oe=t[42],ke=t[43]),X.useEffect(Oe,ke);let Ae;t[44]===M?Ae=t[45]:(Ae=e=>{let t=e.clipboardData?.items;if(!t)return;let n=Array.from(t).filter(ao);if(n.length!==0){e.preventDefault();for(let e of n){let t=e.getAsFile();if(!t)continue;let n=new FileReader;n.onload=()=>{let e=n.result.split(`,`)[1];M(n=>[...n,{fileName:t.name||`pasted-image.${t.type.split(`/`)[1]||`png`}`,content:e,mimeType:t.type}])},n.readAsDataURL(t)}}},t[44]=M,t[45]=Ae);let je=Ae,Me;t[46]!==p||t[47]!==_||t[48]!==h||t[49]!==g?(Me=()=>{p?(g(),_()):(_(),h())},t[46]=p,t[47]=_,t[48]=h,t[49]=g,t[50]=Me):Me=t[50];let Ne=Me,Pe=f?`absolute inset-x-0 bottom-0 mx-auto w-full max-w-3xl px-4 pb-4 pointer-events-none`:`relative mx-auto w-full max-w-3xl px-4 pb-4`,Fe;t[51]!==N||t[52]!==P?(Fe=N&&(0,Q.jsxs)(`div`,{className:`mb-2 flex items-center gap-2 rounded-md bg-accent px-3 py-1.5`,children:[(0,Q.jsx)(ht,{className:`h-3.5 w-3.5 text-accent-foreground`}),(0,Q.jsx)(`span`,{className:`text-xs text-accent-foreground font-medium`,children:`Plan Mode`}),(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>P(!1),className:`ml-auto`,children:[(0,Q.jsx)(w,{className:`h-3 w-3 text-accent-foreground`}),(0,Q.jsx)(`span`,{className:`sr-only`,children:`Exit plan mode`})]})]}),t[51]=N,t[52]=P,t[53]=Fe):Fe=t[53];let Ie;t[54]!==F||t[55]!==I?(Ie=F&&(0,Q.jsxs)(`div`,{className:`mb-2 flex items-center gap-2 rounded-md bg-accent px-3 py-1.5`,children:[(0,Q.jsx)(Ht,{className:`h-3.5 w-3.5 text-accent-foreground`}),(0,Q.jsx)(`span`,{className:`text-xs text-accent-foreground font-medium`,children:`Image Mode`}),(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>I(!1),className:`ml-auto`,children:[(0,Q.jsx)(w,{className:`h-3 w-3 text-accent-foreground`}),(0,Q.jsx)(`span`,{className:`sr-only`,children:`Exit image mode`})]})]}),t[54]=F,t[55]=I,t[56]=Ie):Ie=t[56];let Le=`flex flex-col rounded-2xl border focus-within:ring-2 focus-within:ring-brand pointer-events-auto ${f?`border-border/50 bg-background/80 shadow-lg backdrop-blur-sm`:`border-border bg-background shadow-2xl`}`,Re;t[57]!==l||t[58]!==s?(Re=(0,Q.jsx)(no,{queuedMessages:s,onRemoveQueuedMessage:l}),t[57]=l,t[58]=s,t[59]=Re):Re=t[59];let ze;t[60]!==a||t[61]!==xe||t[62]!==je||t[63]!==Se||t[64]!==y||t[65]!==de?(ze=(0,Q.jsx)(`textarea`,{ref:de,value:y,onChange:Se,onKeyDown:xe,onPaste:je,placeholder:`Ask Tarsk anything, # for files, / for commands & skills`,rows:1,className:`w-full resize-none bg-transparent px-6 pt-4 pb-4 text-sm text-foreground placeholder:text-muted-foreground focus:outline-none`,disabled:a}),t[60]=a,t[61]=xe,t[62]=je,t[63]=Se,t[64]=y,t[65]=de,t[66]=ze):ze=t[66];let Be;t[67]!==ce||t[68]!==pe||t[69]!==we||t[70]!==Te||t[71]!==U||t[72]!==W||t[73]!==oe||t[74]!==ae||t[75]!==ie?(Be=(0,Q.jsx)(Va,{visible:oe,commands:ie,skills:ae,query:ce,selectedIndex:U,onSelectCommand:we,onSelectSkill:Te,onMouseEnterSuggestion:W,containerRef:pe}),t[67]=ce,t[68]=pe,t[69]=we,t[70]=Te,t[71]=U,t[72]=W,t[73]=oe,t[74]=ae,t[75]=ie,t[76]=Be):Be=t[76];let K;t[77]!==Ee||t[78]!==Ce||t[79]!==U||t[80]!==W||t[81]!==H||t[82]!==ne||t[83]!==fe?(K=(0,Q.jsx)(qa,{showSuggestions:H,fileSuggestions:Ee,suggestionQuery:ne,selectedIndex:U,onSelectFile:Ce,onMouseEnterSuggestion:W,containerRef:fe}),t[77]=Ee,t[78]=Ce,t[79]=U,t[80]=W,t[81]=H,t[82]=ne,t[83]=fe,t[84]=K):K=t[84];let Ve;t[85]!==j||t[86]!==k?.id||t[87]!==k?.name||t[88]!==k?.supportsImages||t[89]!==M?(Ve=j.length>0&&(0,Q.jsxs)(`div`,{className:`px-4`,children:[(0,Q.jsx)(Ga,{attachments:j,onRemove:e=>M(t=>t.filter((t,n)=>n!==e))}),j.some(io)&&k?.supportsImages===!1&&(0,Q.jsxs)(`div`,{className:`mb-2 flex items-center gap-1.5 text-xs text-amber-500`,children:[(0,Q.jsx)(c,{className:`h-3 w-3 shrink-0`}),(0,Q.jsxs)(`span`,{children:[`Images are not supported by `,k?.name||k?.id]})]})]}),t[85]=j,t[86]=k?.id,t[87]=k?.name,t[88]=k?.supportsImages,t[89]=M,t[90]=Ve):Ve=t[90];let He;t[91]===ue?He=t[92]:(He=()=>ue.current?.click(),t[91]=ue,t[92]=He);let Ue;t[93]===P?Ue=t[94]:(Ue=()=>P(!0),t[93]=P,t[94]=Ue);let We;t[95]===I?We=t[96]:(We=()=>I(!0),t[95]=I,t[96]=We);let Ge;t[97]!==me||t[98]!==He||t[99]!==Ue||t[100]!==We?(Ge=(0,Q.jsx)(Qa,{onFileAttach:He,onPlanModeToggle:Ue,onImageModeToggle:We,onNewChat:me}),t[97]=me,t[98]=He,t[99]=Ue,t[100]=We,t[101]=Ge):Ge=t[101];let Ke;t[102]===Ne?Ke=t[103]:(Ke=(0,Q.jsx)($a,{onToggleSpeech:Ne}),t[102]=Ne,t[103]=Ke);let qe=he.selectedThreadId??void 0,Je;t[104]===qe?Je=t[105]:(Je=(0,Q.jsx)(to,{threadId:qe}),t[104]=qe,t[105]=Je);let Ye=F?B:A,Xe;t[106]!==ve||t[107]!==_e||t[108]!==Ye?(Xe=(0,Q.jsx)(Xa,{availableModels:ve,selectedModel:_e,onModelSelect:Ye}),t[106]=ve,t[107]=_e,t[108]=Ye,t[109]=Xe):Xe=t[109];let Ze;t[110]!==Ge||t[111]!==Ke||t[112]!==Je||t[113]!==Xe?(Ze=(0,Q.jsxs)(`div`,{className:`flex items-center gap-1`,children:[Ge,Ke,Je,Xe]}),t[110]=Ge,t[111]=Ke,t[112]=Je,t[113]=Xe,t[114]=Ze):Ze=t[114];let $e=d?r:be,et;t[115]!==j.length||t[116]!==a||t[117]!==_e||t[118]!==d||t[119]!==y?(et=!d&&((a??!1)||!y.trim()&&j.length===0||!_e),t[115]=j.length,t[116]=a,t[117]=_e,t[118]=d,t[119]=y,t[120]=et):et=t[120];let tt;t[121]===d?tt=t[122]:(tt=d?(0,Q.jsx)(L,{className:`h-3 w-3 fill-current`}):(0,Q.jsx)(Qe,{className:`h-3 w-3`}),t[121]=d,t[122]=tt);let nt=d?`Stop generation`:`Send message`,rt;t[123]===nt?rt=t[124]:(rt=(0,Q.jsx)(`span`,{className:`sr-only`,children:nt}),t[123]=nt,t[124]=rt);let it;t[125]!==$e||t[126]!==et||t[127]!==tt||t[128]!==rt?(it=(0,Q.jsxs)(q,{size:`icon`,className:`h-7 w-7 rounded-full`,onClick:$e,disabled:et,children:[tt,rt]}),t[125]=$e,t[126]=et,t[127]=tt,t[128]=rt,t[129]=it):it=t[129];let at;t[130]!==Ze||t[131]!==it?(at=(0,Q.jsxs)(`div`,{className:`flex items-center justify-between px-3 pb-2`,children:[Ze,it]}),t[130]=Ze,t[131]=it,t[132]=at):at=t[132];let ot;t[133]!==Le||t[134]!==Re||t[135]!==ze||t[136]!==Be||t[137]!==K||t[138]!==Ve||t[139]!==at?(ot=(0,Q.jsxs)(`div`,{className:Le,children:[Re,ze,Be,K,Ve,at]}),t[133]=Le,t[134]=Re,t[135]=ze,t[136]=Be,t[137]=K,t[138]=Ve,t[139]=at,t[140]=ot):ot=t[140];let st;t[141]===M?st=t[142]:(st=e=>Ka(e,e=>M(t=>[...t,...e])),t[141]=M,t[142]=st);let ct;t[143]!==ue||t[144]!==st?(ct=(0,Q.jsx)(`input`,{ref:ue,type:`file`,multiple:!0,className:`hidden`,onChange:st}),t[143]=ue,t[144]=st,t[145]=ct):ct=t[145];let lt;return t[146]!==Pe||t[147]!==Fe||t[148]!==Ie||t[149]!==ot||t[150]!==ct?(lt=(0,Q.jsxs)(`div`,{className:Pe,children:[Fe,Ie,ot,ct]}),t[146]=Pe,t[147]=Fe,t[148]=Ie,t[149]=ot,t[150]=ct,t[151]=lt):lt=t[151],lt}function io(e){return e.mimeType.startsWith(`image/`)}function ao(e){return e.type.startsWith(`image/`)}function oo({threadId:e}){let[t,n]=(0,X.useState)(!1),[r,i]=(0,X.useState)(null);return(0,X.useEffect)(()=>{e&&fn(e).then(i).catch(()=>{})},[e]),(0,Q.jsx)(`div`,{className:`flex items-center justify-end gap-2 px-8 py-2 mt-[-1rem] min-h-[2.25rem]`,children:e&&(0,Q.jsxs)(Gr,{children:[(0,Q.jsx)(Kr,{asChild:!0,children:(0,Q.jsx)(q,{variant:`ghost`,size:`icon`,className:`h-6 w-6 opacity-50 hover:opacity-80`,onClick:async()=>{if(!(!e||t)){n(!0);try{let t=await fn(e);await navigator.clipboard.writeText(t)}finally{n(!1)}}},disabled:t,"aria-label":`Copy repository folder path`,children:(0,Q.jsx)(je,{className:`h-3 w-3`})})}),(0,Q.jsxs)(Ur,{side:`top`,className:`bg-slate-900 text-white`,children:[(0,Q.jsx)(`div`,{children:`Copy repository folder path`}),r&&(0,Q.jsx)(`div`,{className:`opacity-70 text-xs`,children:r})]})]})})}function so(){let{state:e,dispatch:t}=Ar(),[n,r]=(0,X.useState)(null),[i,a]=(0,X.useState)(!1),o=(0,X.useRef)(``),s=(0,X.useRef)(``),c=(0,X.useRef)([]),l=(0,X.useRef)(!1),u=(0,X.useRef)(null),d=(0,X.useRef)(null),f=(0,X.useRef)(()=>{}),[p,m]=(0,X.useState)(null),h=(0,X.useRef)(!1),g=(0,X.useRef)(!1),_=(0,X.useRef)(null),v=(0,X.useRef)(null),y=(0,X.useRef)(null),{selectedThreadId:b,selectedProjectId:x,messages:S,queuedChatMessages:C,isStreaming:w,streamingModel:T,processingThreadIds:E}=e,D=!!(b&&E.includes(b)),O=(0,X.useCallback)(n=>{if(u.current=null,d.current=null,h.current){h.current=!1;return}let r=c.current,i=Br(r)||`...`;if(_.current&&(r.length===0||i===`...`)){let r={messageId:`msg-${Date.now()}-error`,sender:`agent`,content:`Error: ${_.current}`,contentType:`text`,timestamp:new Date().toISOString(),model:e.streamingModel||n,isThinking:!1};t({type:Y.AddMessage,message:r}),t({type:Y.ResetStream}),b&&t({type:Y.RemoveProcessingThread,threadId:b}),_.current=null;return}let a={messageId:`msg-${Date.now()}-agent`,sender:`agent`,content:i,contentType:`markdown`,timestamp:new Date().toISOString(),model:e.streamingModel||n,isThinking:!1};o.current=``,s.current=``,c.current=[],_.current=null,t({type:Y.AddMessage,message:a}),t({type:Y.ResetStream}),b&&(t({type:Y.MarkThreadCompleted,threadId:b}),t({type:Y.RemoveProcessingThread,threadId:b}))},[e.streamingModel,t,b]);(0,X.useEffect)(()=>{f.current=O},[O]);let k=(0,X.useCallback)(()=>{b&&m(b),h.current=!0,b&&Yt(b),u.current&&=(u.current.abort(),null),d.current&&=(d.current(),null),o.current=``,s.current=``,c.current=[],_.current=null;let n={messageId:`msg-${Date.now()}-stopped`,sender:`agent`,content:`I've stopped working on your request.`,contentType:`text`,timestamp:new Date().toISOString(),model:e.streamingModel||`default`,isThinking:!1};t({type:Y.AddMessage,message:n}),t({type:Y.ResetStream}),b&&(t({type:Y.MarkThreadCompleted,threadId:b}),t({type:Y.RemoveProcessingThread,threadId:b}))},[b,t,e.streamingModel]);(0,X.useEffect)(()=>{g.current&&!w&&u.current&&(u.current.abort(),u.current=null,d.current&&=(d.current(),null),f.current(T||`default`)),g.current=w},[w,T]),(0,X.useEffect)(()=>{if(v.current&&=(clearTimeout(v.current),null),w){let e=12e4,t=n=>{v.current&&=(clearTimeout(v.current),null),v.current=setTimeout(()=>{let n=Date.now(),r=y?.current??null;if(r!=null){let i=n-r;if(i<e){t(e-i);return}}console.warn(`[stream-safety] Streaming stuck for 2 minutes with no activity, auto-finalizing`),u.current&&=(u.current.abort(),null),d.current&&=(d.current(),null),f.current(T||`default`)},n)},n=e;if(y?.current!=null){let t=Date.now()-y.current;n=t>=e?0:e-t}t(n)}return()=>{v.current&&=(clearTimeout(v.current),null)}},[w,T]),(0,X.useEffect)(()=>()=>{u.current&&=(u.current.abort(),null),d.current&&=(d.current(),null),t({type:Y.ResetStream})},[b,t]),(0,X.useEffect)(()=>{if(!b)return;let e=!1;async function n(){try{let n=await yt(b);e||t({type:Y.SetMessages,messages:n.messages})}catch(n){console.error(`Failed to load chat history:`,n),e||t({type:Y.SetMessages,messages:[]})}}return n(),()=>{e=!0}},[b,x,t]),(0,X.useEffect)(()=>{if(!b||!D||w)return;let e=new AbortController;return u.current=e,t({type:Y.ResetStream}),t({type:Y.SetStreaming,isStreaming:!0}),o.current=``,s.current=``,c.current=[],l.current=!1,_.current=null,mn(b,e.signal).then(n=>{if(!n||e.signal.aborted){f.current(`default`);return}d.current=ee(n,e=>{if(e.type===`error`){let t=e.content||`Unknown error occurred`;_.current=t,r(t);return}if(e.type!==`message`){if(e.type===`toolcall_delta`){e.partial?.content?.[0]?.id&&e.delta&&t({type:Y.UpdateToolCallProgress,toolCallId:e.partial.content[0].id,progress:{toolCallId:e.partial.content[0].id,toolName:e.partial.content[0].name,delta:e.delta,partial:e.partial}});return}if(e.model&&t({type:Y.SetStreamModel,model:e.model}),e.type===`thinking`||e.isThinking){s.current+=e.content??``;let n=Fr(c.current,`thinking`,e.content??``);c.current=n,t({type:Y.AppendStreamChunk,chunkType:`thinking`,content:e.content??``,segments:n})}else if(e.type===`result`)l.current=!0,o.current=e.content??``,c.current=Vr(c.current,e.content??``),t({type:Y.SetStreamContent,content:e.content??``});else{if(l.current)return;o.current+=e.content??``;let n=Fr(c.current,`content`,e.content??``);c.current=n,t({type:Y.AppendStreamChunk,chunkType:`content`,content:e.content??``,segments:n})}}},()=>{f.current(`default`)},e=>{if(e.includes(`AbortError`)||e.includes(`canceled`)||e.includes(`BodyStreamBuffer was aborted`)){f.current(`default`);return}_.current=e,r(e)},e=>{if(e.role===`assistant`){let n=e.content??``,r=typeof n==`string`?n:JSON.stringify(n);if(e.isThinking??!1){s.current+=r;let e=Fr(c.current,`thinking`,r);c.current=e,t({type:Y.AppendStreamChunk,chunkType:`thinking`,content:r,segments:e});return}let i=!1;if(typeof n==`object`&&Array.isArray(n)&&n.length>0)i=!0;else if(typeof r==`string`&&r.trim().startsWith(`[`))try{let e=JSON.parse(r);i=Array.isArray(e)&&e.length>0}catch{}if(i)l.current=!0,o.current=r,c.current=Vr(c.current,r),t({type:Y.SetStreamContent,content:r});else{o.current+=r;let e=Fr(c.current,`content`,r);c.current=e,t({type:Y.AppendStreamChunk,chunkType:`content`,content:r,segments:e})}}else if(e.role===`tool`){let n=e.content??``,r=typeof n==`string`?n:JSON.stringify(n);if(r){o.current+=r;let e=Fr(c.current,`content`,r);c.current=e,t({type:Y.AppendStreamChunk,chunkType:`content`,content:r,segments:e})}}})}).catch(e=>{if(e instanceof Error&&e.name===`AbortError`){t({type:Y.ResetStream});return}if(e instanceof Error&&e.message.includes(`not currently processing`)){t({type:Y.ResetStream});return}console.error(`Failed to subscribe to chat stream:`,e),t({type:Y.ResetStream})}),()=>{e.abort(),d.current&&=(d.current(),null)}},[b,D]);let A=(0,X.useCallback)(async(e,n,i,p,h,g)=>{if(!b)return;r(null),m(null),u.current&&u.current.abort(),d.current&&d.current();let v={messageId:`msg-${Date.now()}`,sender:`user`,content:e,contentType:`text`,timestamp:new Date().toISOString(),model:n,attachments:i.map(e=>({fileName:e.fileName,content:e.content,mimeType:e.mimeType}))};t({type:Y.AddMessage,message:v});let y=e.trim().replace(/\n/g,` `).slice(0,100);if(x&&b&&(nt(b,{title:y}).catch(e=>{console.error(`Failed to update thread title:`,e)}),t({type:Y.UpdateThreadTitle,projectId:x,threadId:b,title:y})),g){let r=p??void 0;if(!r&&typeof n==`string`){let e=n.split(/[:/]/)[0]?.trim();e&&(r=e)}if(!r){let e={messageId:`msg-${Date.now()}-error`,sender:`agent`,content:`Image generation is not available because no provider is configured for the selected model.`,contentType:`text`,timestamp:new Date().toISOString(),model:n,isThinking:!1};t({type:Y.AddMessage,message:e}),t({type:Y.ResetStream});return}t({type:Y.SetStreaming,isStreaming:!0});try{let i=await z(e,n,r,b),a={messageId:`msg-${Date.now()}-agent`,sender:`agent`,content:e,contentType:`text`,timestamp:new Date().toISOString(),model:n,isThinking:!1,generatedImageUrl:i.imageUrl,generatedImageData:i.imageData};t({type:Y.AddMessage,message:a})}catch(e){let r=e instanceof Error?e.message:`Image generation failed`,i={messageId:`msg-${Date.now()}-error`,sender:`agent`,content:`Error: ${r}`,contentType:`text`,timestamp:new Date().toISOString(),model:n,isThinking:!1};t({type:Y.AddMessage,message:i})}finally{t({type:Y.ResetStream})}return}t({type:Y.ResetStream}),t({type:Y.SetStreaming,isStreaming:!0}),o.current=``,l.current=!1;let S=new AbortController;u.current=S;try{let a=await At(b,e,n,i,S.signal,p,h);if(!a){f.current(n);return}d.current=ee(a,e=>{if(e.type===`error`){let t=e.content||`Unknown error occurred`;_.current=t,r(t);return}if(e.type!==`message`){if(e.type===`toolcall_delta`){if(e.partial?.content?.[0]?.id&&e.delta){let n=e.partial.content[0].id,r=e.partial.content[0].name;t({type:Y.UpdateToolCallProgress,toolCallId:n,progress:{toolCallId:n,toolName:r,delta:e.delta,partial:e.partial}})}return}if(e.model&&t({type:Y.SetStreamModel,model:e.model}),e.type===`thinking`||e.isThinking){s.current+=e.content??``;let n=Fr(c.current,`thinking`,e.content??``);c.current=n,t({type:Y.AppendStreamChunk,chunkType:`thinking`,content:e.content??``,segments:n})}else if(e.type===`result`)l.current=!0,o.current=e.content??``,c.current=Vr(c.current,e.content??``),t({type:Y.SetStreamContent,content:e.content??``});else{if(l.current)return;o.current+=e.content??``;let n=Fr(c.current,`content`,e.content??``);c.current=n,t({type:Y.AppendStreamChunk,chunkType:`content`,content:e.content??``,segments:n})}}},()=>{f.current(n)},e=>{if(e.includes(`AbortError`)||e.includes(`canceled`)||e.includes(`BodyStreamBuffer was aborted`)){f.current(n);return}_.current=e,r(e)},e=>{if(e.role===`assistant`){let n=e.content??``,r=typeof n==`string`?n:JSON.stringify(n);if(e.isThinking??!1){s.current+=r;let e=Fr(c.current,`thinking`,r);c.current=e,t({type:Y.AppendStreamChunk,chunkType:`thinking`,content:r,segments:e});return}let i=!1;if(typeof n==`object`&&Array.isArray(n)&&n.length>0)i=!0;else if(typeof r==`string`&&r.trim().startsWith(`[`))try{let e=JSON.parse(r);i=Array.isArray(e)&&e.length>0}catch{}if(i)l.current=!0,o.current=r,c.current=Vr(c.current,r),t({type:Y.SetStreamContent,content:r});else{o.current+=r;let e=Fr(c.current,`content`,r);c.current=e,t({type:Y.AppendStreamChunk,chunkType:`content`,content:r,segments:e})}}else if(e.role===`tool`){let n=e.content??``,r=typeof n==`string`?n:JSON.stringify(n);if(r){o.current+=r;let e=Fr(c.current,`content`,r);c.current=e,t({type:Y.AppendStreamChunk,chunkType:`content`,content:r,segments:e})}}})}catch(e){if(e instanceof Error&&e.name===`AbortError`||e instanceof Error&&e.message.includes(`BodyStreamBuffer was aborted`))return;if(e instanceof Tn){t({type:Y.ResetStream}),a(!0);return}r(e instanceof Error?e.message:`Failed to send message. Please ensure the CLI server is running on localhost:641`),_.current=e instanceof Error?e.message:`Failed to send message. Please ensure the CLI server is running on localhost:641`,t({type:Y.ResetStream})}},[b,x,t]);(0,X.useEffect)(()=>{let n=e.pendingChatMessage;if(!n||w||n.threadId!==b)return;let r=setTimeout(()=>{t({type:Y.ClearPendingChatMessage}),A(n.message,n.model,[],n.provider)},100);return()=>clearTimeout(r)},[e.pendingChatMessage,w,b,t,A]);let j=(0,X.useMemo)(()=>b?C.filter(e=>e.threadId===b):[],[b,C]),M=(0,X.useRef)(!1);return(0,X.useEffect)(()=>{if(w||!b||j.length===0||M.current)return;let[e]=j;M.current=!0,t({type:Y.RemoveQueuedChatMessage,queuedMessageId:e.id});let n=setTimeout(()=>{A(e.message,e.model,e.attachments,e.provider,e.planMode),M.current=!1},0);return()=>{clearTimeout(n),M.current=!1}},[t,A,w,j,b]),{error:n,setError:r,handleSend:A,handleStop:k,isStreaming:w,selectedThreadId:b,queuedMessagesForThread:j,handleRemoveQueuedMessage:(0,X.useCallback)(e=>{let n=j.find(t=>t.id===e);t({type:Y.RemoveQueuedChatMessage,queuedMessageId:e}),!(!n||w||S.length>0||!b)&&A(n.message,n.model,n.attachments,n.provider,n.planMode)},[t,A,w,S.length,j,b]),showEmptyBalanceDialog:i,setShowEmptyBalanceDialog:a}}function co(e){let t=(0,Z.c)(10),{open:n,onClose:r}=e,i=fr(),a;t[0]===r?a=t[1]:(a=e=>{e||r()},t[0]=r,t[1]=a);let o;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(o=(0,Q.jsxs)(yi,{children:[(0,Q.jsx)(xi,{children:`Balance empty`}),(0,Q.jsx)(Si,{children:`You have no prompts remaining. Purchase additional prompts to continue.`})]}),t[2]=o):o=t[2];let s;t[3]!==i||t[4]!==r?(s=(0,Q.jsxs)(vi,{children:[o,(0,Q.jsx)(bi,{children:(0,Q.jsx)(q,{onClick:()=>{r(),i(`/settings/account`)},children:`Go to Account`})})]}),t[3]=i,t[4]=r,t[5]=s):s=t[5];let c;return t[6]!==n||t[7]!==a||t[8]!==s?(c=(0,Q.jsx)(hi,{open:n,onOpenChange:a,children:s}),t[6]=n,t[7]=a,t[8]=s,t[9]=c):c=t[9],c}function lo(){let e=(0,Z.c)(20),{state:t}=Ar(),{isCreatingProject:n}=t,{handleSend:r,handleStop:i,isStreaming:a,selectedThreadId:o,queuedMessagesForThread:s,handleRemoveQueuedMessage:c,showEmptyBalanceDialog:l,setShowEmptyBalanceDialog:u}=so(),d=t.pendingChatMessage?.threadId===o,f=a||d,p;e[0]===u?p=e[1]:(p=()=>u(!1),e[0]=u,e[1]=p);let m;e[2]!==l||e[3]!==p?(m=(0,Q.jsx)(co,{open:l,onClose:p}),e[2]=l,e[3]=p,e[4]=m):m=e[4];let h=!o&&!n,g;e[5]!==f||e[6]!==c||e[7]!==r||e[8]!==i||e[9]!==s||e[10]!==h?(g=(0,Q.jsx)(ro,{onSend:r,onStop:i,isStreaming:f,disabled:h,initialValue:``,queuedMessages:s,onRemoveQueuedMessage:c,isOverlay:!1}),e[5]=f,e[6]=c,e[7]=r,e[8]=i,e[9]=s,e[10]=h,e[11]=g):g=e[11];let _=o??void 0,v;e[12]===_?v=e[13]:(v=(0,Q.jsx)(oo,{threadId:_}),e[12]=_,e[13]=v);let y;e[14]!==g||e[15]!==v?(y=(0,Q.jsxs)(`div`,{className:`relative mx-auto min-w-[400px] w-[90vw] max-w-3xl`,children:[g,v]}),e[14]=g,e[15]=v,e[16]=y):y=e[16];let b;return e[17]!==m||e[18]!==y?(b=(0,Q.jsxs)(Q.Fragment,{children:[m,y]}),e[17]=m,e[18]=y,e[19]=b):b=e[19],b}async function uo(e){return wn(`api/projects/${ct(e)}/todos`)}async function fo(e,t){return bn(`api/projects/${ct(e)}/todos`,{description:t})}async function po(e,t,n){return h(`api/projects/${ct(e)}/todos/${ct(t)}`,n)}async function mo(e,t){await Dn(`api/projects/${ct(e)}/todos/${ct(t)}`)}var ho={Ready:[{label:`Plan`,target:`Plan`},{label:`Build`,target:`Build`}],Plan:[{label:`Build`,target:`Build`}],Build:[{label:`Test`,target:`Test`},{label:`Review`,target:`Review`}],Test:[{label:`Review`,target:`Review`}],Review:[],Done:[]};function go({todo:e,projectId:t,onUpdate:n,onEdit:r,onAction:i,onThreadSelect:a}){let[s,c]=(0,X.useState)(!1),l=ho[e.status]??[];function u(t){t.stopPropagation(),e.threadId&&a&&a(e.threadId)}async function d(r,a){r.stopPropagation(),c(!0);try{i?await i(e,a):n(await po(t,e.id,{status:a,working:!0}))}finally{c(!1)}}return(0,Q.jsxs)(`div`,{className:K(`rounded-lg border bg-card p-3 shadow-sm space-y-2 cursor-pointer hover:bg-accent/50 transition-colors`,e.working&&`border-primary/50 bg-primary/5`),onClick:t=>{t.stopPropagation(),r(e)},children:[(0,Q.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,Q.jsx)(`p`,{className:`text-sm font-medium leading-tight`,children:e.title}),e.working&&(0,Q.jsx)(Rt,{className:`h-3 w-3 animate-spin text-primary shrink-0`})]}),(l.length>0||e.status!==`Ready`&&e.threadId&&a)&&(0,Q.jsxs)(`div`,{className:`flex gap-1.5 flex-wrap items-center pt-1`,children:[l.map(t=>(0,Q.jsxs)(Gr,{children:[(0,Q.jsx)(Kr,{asChild:!0,children:(0,Q.jsx)(q,{size:`sm`,variant:`outline`,className:`h-6 px-2 text-xs`,onClick:e=>void d(e,t.target),disabled:s||e.working,children:t.label})}),(0,Q.jsx)(Ur,{side:`top`,children:e.status===`Ready`&&t.target===`Build`?`Implement this on a new branch of the project`:t.label})]},t.target)),e.status!==`Ready`&&e.threadId&&a&&(0,Q.jsxs)(Gr,{children:[(0,Q.jsx)(Kr,{asChild:!0,children:(0,Q.jsxs)(q,{size:`icon`,variant:`ghost`,className:`h-7 w-7 shrink-0 group-hover:flex items-center justify-center`,onClick:u,children:[(0,Q.jsx)(o,{className:`h-4 w-4`}),(0,Q.jsx)(`span`,{className:`sr-only`,children:`Open thread`})]})}),(0,Q.jsx)(Ur,{side:`right`,children:`Open thread`})]})]})]})}var _o=[`Ready`,`Plan`,`Build`,`Test`,`Review`,`Done`],vo={Ready:`border-t-slate-400`,Plan:`border-t-blue-400`,Build:`border-t-orange-400`,Test:`border-t-yellow-400`,Review:`border-t-purple-400`,Done:`border-t-green-400`};async function yo(e,t){let n=e.getReader(),r=new TextDecoder,i=``,a=null;try{for(;;){let{done:e,value:o}=await n.read();if(e)break;i+=r.decode(o,{stream:!0});let s=i.split(`
|
|
12
|
+
`);i=s.pop()??``;for(let e of s){let n=e.trim();if(n)try{let e=JSON.parse(n);e.type===`progress`&&typeof e.threadId==`string`&&!a&&(a=e.threadId,t(a))}catch{}}}}catch{}return a}async function bo(e){let t=e.getReader();try{for(;;){let{done:e}=await t.read();if(e)break}}catch{}}function xo({projectId:e,addOpen:t,onAddOpenChange:n,onThreadSelect:r}){let{state:i,dispatch:a}=Ar(),[o,s]=(0,X.useState)([]),[c,l]=(0,X.useState)(!0),[u,f]=(0,X.useState)(null),[p,m]=(0,X.useState)(``),[h,g]=(0,X.useState)(!1),_=(0,X.useCallback)(async()=>{try{let t=await uo(e),n=t.filter(e=>e.threadId&&e.status!==`Done`),r=[...t];await Promise.all(n.map(async t=>{try{await Fe(t.threadId)}catch(n){if(n instanceof Error&&n.message.includes(`not found`)){let n=await po(e,t.id,{status:`Done`}),i=r.findIndex(e=>e.id===t.id);i!==-1&&(r[i]=n);return}}})),s(r)}catch(e){console.error(`Failed to fetch project todos:`,e)}finally{l(!1)}},[e]);(0,X.useEffect)(()=>{_()},[_]),(0,X.useEffect)(()=>{if(!o.some(e=>e.working))return;let t=setInterval(async()=>{try{let n=await uo(e);s(n),n.some(e=>e.working)||clearInterval(t)}catch(e){console.error(`Failed to poll project todos:`,e)}},2e3);return()=>clearInterval(t)},[o,e]),(0,X.useEffect)(()=>{t&&m(``)},[t]);function v(e){m(e.description),f({todo:e})}function y(){f(null),m(``)}async function b(){if(p.trim()){g(!0);try{let t=await fo(e,p);s(e=>[...e,t]),n(!1),m(``)}finally{g(!1)}}}async function x(){if(!(!p.trim()||!u)){g(!0);try{let t=await po(e,u.todo.id,{description:p});s(e=>e.map(e=>e.id===t.id?t:e)),y()}finally{g(!1)}}}async function S(){if(u){g(!0);try{await mo(e,u.todo.id),s(e=>e.filter(e=>e.id!==u.todo.id)),y()}finally{g(!1)}}}function w(e){s(t=>t.map(t=>t.id===e.id?e:t))}async function T(t){let n=i.selectedThreadId?i.projectModelSelections[i.selectedThreadId]:void 0,r=i.projects.find(t=>t.projectId===e)?.threads.find(e=>e.threadId===i.selectedThreadId),o=n?.id??r?.model,s=n?.provider??r?.modelProvider;if(!o||!s)throw console.error(`No model or provider found for project`,e,r),Error(`No model configuration found. Please configure a model and provider for this project first.`);let c=await jt(e);if(!c)return;let l=null,u=await yo(c,n=>{po(e,t.id,{status:`Plan`,working:!0,threadId:n}).then(e=>{l=e,w(e)})});if(!u)return;l||w(await po(e,t.id,{status:`Plan`,working:!0,threadId:u}));let d=n??{id:o,provider:s,name:o,description:``};a({type:Y.SetProjectModel,threadId:u,model:d}),nt(u,{model:o,modelProvider:s});let f=await At(u,`Please analyze this task and create a detailed implementation plan.\nWrite your complete plan to the file \`${t.id}-plan.md\` in the current directory.\n\nTask description:\n${t.description}`,o,[],void 0,s);f&&bo(f)}async function E(t){let n=await jt(e);if(!n)return;let r=null,i=await yo(n,n=>{po(e,t.id,{status:`Build`,working:!0,threadId:n}).then(e=>{r=e,w(e)})});if(!i)return;r||w(await po(e,t.id,{status:`Build`,working:!0,threadId:i}));let o=await Fe(i),s=o.model,c=o.modelProvider;if(!s||!c)try{let t=(await wn(`api/threads?projectId=${encodeURIComponent(e)}`)||[]).map(e=>{let t=e;return{threadId:t.threadId??t.id,model:t.model??void 0,modelProvider:t.modelProvider??void 0}}).find(e=>e.model&&e.modelProvider);t&&(s=t.model,c=t.modelProvider)}catch(e){console.error(`Failed to get project threads:`,e)}if(!s||!c)throw Error(`No model configuration found. Please configure a model and provider for this project first.`);a({type:Y.SetProjectModel,threadId:i,model:{id:s,provider:c,name:s,description:``}}),nt(i,{model:s,modelProvider:c}),console.log(`Sending chat message with provider:`,i,t.description,c);let l=await At(i,t.description,s,[],void 0,c);l&&bo(l)}async function O(t,n){n===`Plan`?await T(t):n===`Build`?await E(t):w(await po(e,t.id,{status:n,working:!0}))}return c?(0,Q.jsx)(`div`,{className:`flex items-center justify-center h-64`,children:(0,Q.jsx)(Rt,{className:`h-6 w-6 animate-spin text-muted-foreground`})}):(0,Q.jsxs)(`div`,{className:`flex h-full min-h-0`,children:[(0,Q.jsx)(`div`,{className:`flex gap-3 overflow-x-auto pb-2 flex-1 min-h-0`,children:_o.map(t=>{let i=o.filter(e=>e.status===t),a=t===`Ready`;return(0,Q.jsxs)(`div`,{className:K(`flex flex-col rounded-lg border border-t-4 bg-muted/30 min-w-[200px] w-[200px] shrink-0`,vo[t]),children:[(0,Q.jsxs)(`div`,{className:`px-3 py-2 flex items-center justify-between`,children:[(0,Q.jsx)(`h3`,{className:`text-xs font-semibold text-muted-foreground uppercase tracking-wide`,children:t}),(0,Q.jsx)(`span`,{className:`text-xs text-muted-foreground bg-muted rounded-full px-1.5 py-0.5`,children:i.length})]}),(0,Q.jsx)(C,{className:`flex-1 px-2 pb-2`,children:(0,Q.jsxs)(`div`,{className:`space-y-2`,children:[a&&(0,Q.jsxs)(q,{variant:`outline`,size:`sm`,className:`w-full h-8 border-dashed text-muted-foreground hover:text-foreground`,onClick:()=>n(!0),children:[(0,Q.jsx)(te,{className:`h-3 w-3 mr-1`}),`Add Task`]}),i.map(t=>(0,Q.jsx)(go,{todo:t,projectId:e,onUpdate:w,onEdit:v,onAction:O,onThreadSelect:r},t.id))]})})]},t)})}),(0,Q.jsx)(D,{open:t,onOpenChange:n,children:(0,Q.jsxs)(I,{className:`sm:max-w-2xl`,children:[(0,Q.jsx)(jn,{children:(0,Q.jsx)(d,{children:`Add Task`})}),(0,Q.jsxs)(`div`,{className:`py-2`,children:[(0,Q.jsx)(Hr,{placeholder:`Describe what needs to be done...`,value:p,onChange:e=>m(e.target.value),rows:12,className:`resize-none text-sm`,autoFocus:!0,onKeyDown:e=>{e.key===`Enter`&&(e.metaKey||e.ctrlKey)&&b()}}),(0,Q.jsx)(`p`,{className:`text-xs text-muted-foreground mt-1.5`,children:`A title will be generated automatically from your description.`})]}),(0,Q.jsx)(De,{children:(0,Q.jsx)(q,{onClick:()=>void b(),disabled:h||!p.trim(),children:h?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(Rt,{className:`h-3 w-3 animate-spin mr-1`}),`Generating title...`]}):`Add`})})]})}),(0,Q.jsx)(D,{open:u!==null,onOpenChange:e=>!e&&y(),children:(0,Q.jsxs)(I,{className:`sm:max-w-2xl`,children:[(0,Q.jsx)(jn,{children:(0,Q.jsx)(d,{children:`Edit Task`})}),(0,Q.jsx)(`div`,{className:`py-2`,children:(0,Q.jsx)(Hr,{placeholder:`Describe what needs to be done...`,value:p,onChange:e=>m(e.target.value),rows:12,className:`resize-none text-sm`,autoFocus:!0,onKeyDown:e=>{e.key===`Enter`&&(e.metaKey||e.ctrlKey)&&x()}})}),(0,Q.jsxs)(De,{className:`gap-2 sm:gap-0`,children:[(0,Q.jsx)(q,{variant:`destructive`,onClick:()=>void S(),disabled:h,className:`mr-auto`,children:`Delete`}),(0,Q.jsx)(q,{onClick:()=>void x(),disabled:h||!p.trim(),children:h?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(Rt,{className:`h-3 w-3 animate-spin mr-1`}),`Saving...`]}):`Save`})]})]})})]})}function So({projectId:e}){let{state:t,dispatch:n}=Ar(),{projects:r}=t,[i,a]=(0,X.useState)(!1),o=fr();async function s(t){if(r.find(t=>t.projectId===e)){o(`/`);try{let{getProjects:r,invalidateProjectsCache:i}=await ar(async()=>{let{getProjects:e,invalidateProjectsCache:t}=await import(`./dialogs-config-Ofxg1Bn0.js`).then(e=>e.b);return{getProjects:e,invalidateProjectsCache:t}},__vite__mapDeps([0,1]));i();let a=await r();n({type:Y.SetProjects,projects:a.projects});let o=a.projects.find(t=>t.projectId===e);if(o&&o.threads.find(e=>e.threadId===t)){n({type:Y.SelectThread,threadId:t,projectId:e});try{let e=await rt();n({type:Y.SetProcessingThreads,threadIds:e})}catch(e){console.error(`Failed to fetch processing threads after thread selection:`,e)}}}catch(r){console.error(`Failed to refresh projects for thread selection:`,r),n({type:Y.SelectThread,threadId:t,projectId:e});try{let e=await rt();n({type:Y.SetProcessingThreads,threadIds:e})}catch(e){console.error(`Failed to fetch processing threads after fallback thread selection:`,e)}}}}return(0,Q.jsx)(`div`,{className:`flex h-full flex-col overflow-hidden`,children:(0,Q.jsx)(`div`,{className:`flex-1 overflow-hidden p-6`,children:(0,Q.jsx)(xo,{projectId:e,addOpen:i,onAddOpenChange:a,onThreadSelect:s})})})}var Co=(0,X.lazy)(()=>ar(()=>import(`./diff-view-C-Kz7R_T.js`),__vite__mapDeps([8,1,4,5,0,6,9,10,7,11,12]))),wo=(0,X.lazy)(()=>ar(()=>import(`./dialogs-config-Ofxg1Bn0.js`).then(e=>e.t),__vite__mapDeps([0,1])));function To(e){let t=(0,Z.c)(48),{onCreateThread:n}=e,{state:r,dispatch:i}=Ar(),a=fr(),o=_r(),[s,c]=(0,X.useState)(!1),[l,u]=(0,X.useState)(null),{selectedThreadId:d,messages:f,isCreatingProject:p,processingThreadIds:m,projects:h,projectsLoading:g,isStreaming:_,streamingSegments:v,streamingModel:y}=r,b;t[0]!==m||t[1]!==d?(b=d&&m.includes(d),t[0]=m,t[1]=d,t[2]=b):b=t[2];let x=!!b,S;t[3]!==i||t[4]!==r.sidebarOpen?(S=()=>{r.sidebarOpen&&i({type:Y.ToggleSidebar})},t[3]=i,t[4]=r.sidebarOpen,t[5]=S):S=t[5];let C=S,w;t[6]===C?w=t[7]:(w=()=>{C(),u(`clone`),c(!0)},t[6]=C,t[7]=w);let T=w,E;t[8]===C?E=t[9]:(E=()=>{C(),u(`webapp`),c(!0)},t[8]=C,t[9]=E);let D=E,O;t[10]===Symbol.for(`react.memo_cache_sentinel`)?(O=async(e,t)=>{try{await me(e,t),c(!1),u(null)}catch(e){let t=e;console.error(`Failed to clone repository:`,t)}},t[10]=O):O=t[10];let k=O,j;t[11]===Symbol.for(`react.memo_cache_sentinel`)?(j=async(e,t,n)=>{try{await Ft(e,t,n),c(!1),u(null)}catch(e){let t=e;console.error(`Failed to create project:`,t)}},t[11]=j):j=t[11];let M=j,N;t[12]===C?N=t[13]:(N=async()=>{C();try{await A(),c(!1),u(null)}catch(e){let t=e;console.error(`Failed to open folder:`,t)}},t[12]=C,t[13]=N);let P=N,F=o.pathname===`/review`,I=o.pathname===`/todos`,L;t[14]===a?L=t[15]:(L=()=>{a(`/`)},t[14]=a,t[15]=L);let R=L,{selectedProjectId:z}=r,B;t[16]!==C||t[17]!==i||t[18]!==T||t[19]!==R||t[20]!==D||t[21]!==P||t[22]!==p||t[23]!==x||t[24]!==_||t[25]!==f||t[26]!==n||t[27]!==h||t[28]!==g||t[29]!==F||t[30]!==z||t[31]!==d||t[32]!==y||t[33]!==v||t[34]!==I?(B=I&&z?(0,Q.jsx)(So,{projectId:z}):F&&d?(0,Q.jsx)(X.Suspense,{fallback:(0,Q.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:`Loading diff view...`}),children:(0,Q.jsx)(Co,{threadId:d,onExit:R})}):(0,Q.jsx)(ja,{messages:f,isStreaming:_,streamingSegments:v,streamingModel:y,isCreatingProject:p,isProcessingThread:x,selectedThreadId:d,projects:h,projectsLoading:g,onSelectThread:(e,t)=>{C(),i({type:Y.SelectThread,projectId:e,threadId:t})},onCreateThread:n,onConnectRepo:T,onNewApp:D,onOpenFolder:P,error:null,onClearError:Eo}),t[16]=C,t[17]=i,t[18]=T,t[19]=R,t[20]=D,t[21]=P,t[22]=p,t[23]=x,t[24]=_,t[25]=f,t[26]=n,t[27]=h,t[28]=g,t[29]=F,t[30]=z,t[31]=d,t[32]=y,t[33]=v,t[34]=I,t[35]=B):B=t[35];let V;t[36]!==F||t[37]!==d||t[38]!==I?(V=!F&&!I&&d&&(0,Q.jsx)(lo,{}),t[36]=F,t[37]=d,t[38]=I,t[39]=V):V=t[39];let ee=l??void 0,H;t[40]!==s||t[41]!==P||t[42]!==ee?(H=(0,Q.jsx)(X.Suspense,{fallback:null,children:(0,Q.jsx)(wo,{open:s,onOpenChange:c,initialMode:ee,onSubmitClone:k,onSubmitWebApp:M,onOpenFolder:P})}),t[40]=s,t[41]=P,t[42]=ee,t[43]=H):H=t[43];let te;return t[44]!==V||t[45]!==H||t[46]!==B?(te=(0,Q.jsxs)(`div`,{className:`flex h-full flex-col`,children:[B,V,H]}),t[44]=V,t[45]=H,t[46]=B,t[47]=te):te=t[47],te}function Eo(){}function Do(e){let t=(0,Z.c)(5),{children:n,className:r}=e,i;t[0]===r?i=t[1]:(i=K(`flex min-h-[71px] shrink-0 items-center gap-2 px-4 py-2`,r),t[0]=r,t[1]=i);let a;return t[2]!==n||t[3]!==i?(a=(0,Q.jsx)(`header`,{className:i,children:n}),t[2]=n,t[3]=i,t[4]=a):a=t[4],a}var Oo=Wn,ko=ir,Ao=Un,jo=X.forwardRef((e,t)=>{let n=(0,Z.c)(14),r,i,a,o;n[0]===e?(r=n[1],i=n[2],a=n[3],o=n[4]):({className:i,inset:a,children:r,...o}=e,n[0]=e,n[1]=r,n[2]=i,n[3]=a,n[4]=o);let s=a&&`pl-8`,c;n[5]!==i||n[6]!==s?(c=K(`flex cursor-default gap-2 select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none focus:bg-accent data-[state=open]:bg-accent [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0`,s,i),n[5]=i,n[6]=s,n[7]=c):c=n[7];let l;n[8]===Symbol.for(`react.memo_cache_sentinel`)?(l=(0,Q.jsx)(Ue,{className:`ml-auto`}),n[8]=l):l=n[8];let u;return n[9]!==r||n[10]!==o||n[11]!==t||n[12]!==c?(u=(0,Q.jsxs)(nr,{ref:t,className:c,...o,children:[r,l]}),n[9]=r,n[10]=o,n[11]=t,n[12]=c,n[13]=u):u=n[13],u});jo.displayName=nr.displayName;var Mo=X.forwardRef((e,t)=>{let n=(0,Z.c)(9),r,i;n[0]===e?(r=n[1],i=n[2]):({className:r,...i}=e,n[0]=e,n[1]=r,n[2]=i);let a;n[3]===r?a=n[4]:(a=K(`z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-lg data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2`,r),n[3]=r,n[4]=a);let o;return n[5]!==i||n[6]!==t||n[7]!==a?(o=(0,Q.jsx)(rr,{ref:t,className:a,...i}),n[5]=i,n[6]=t,n[7]=a,n[8]=o):o=n[8],o});Mo.displayName=rr.displayName;var No=X.forwardRef((e,t)=>{let n=(0,Z.c)(11),r,i,a;n[0]===e?(r=n[1],i=n[2],a=n[3]):({className:r,sideOffset:a,...i}=e,n[0]=e,n[1]=r,n[2]=i,n[3]=a);let o=a===void 0?4:a,s;n[4]===r?s=n[5]:(s=K(`z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2`,r),n[4]=r,n[5]=s);let c;return n[6]!==i||n[7]!==t||n[8]!==o||n[9]!==s?(c=(0,Q.jsx)(er,{children:(0,Q.jsx)(Zn,{ref:t,sideOffset:o,className:s,...i})}),n[6]=i,n[7]=t,n[8]=o,n[9]=s,n[10]=c):c=n[10],c});No.displayName=Zn.displayName;var Po=X.forwardRef((e,t)=>{let n=(0,Z.c)(11),r,i,a;n[0]===e?(r=n[1],i=n[2],a=n[3]):({className:r,inset:i,...a}=e,n[0]=e,n[1]=r,n[2]=i,n[3]=a);let o=i&&`pl-8`,s;n[4]!==r||n[5]!==o?(s=K(`relative flex cursor-default select-none items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0`,o,r),n[4]=r,n[5]=o,n[6]=s):s=n[6];let c;return n[7]!==a||n[8]!==t||n[9]!==s?(c=(0,Q.jsx)(Fn,{ref:t,className:s,...a}),n[7]=a,n[8]=t,n[9]=s,n[10]=c):c=n[10],c});Po.displayName=Fn.displayName;var Fo=X.forwardRef((e,t)=>{let n=(0,Z.c)(14),r,i,a,o;n[0]===e?(r=n[1],i=n[2],a=n[3],o=n[4]):({className:a,children:i,checked:r,...o}=e,n[0]=e,n[1]=r,n[2]=i,n[3]=a,n[4]=o);let s;n[5]===a?s=n[6]:(s=K(`relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50`,a),n[5]=a,n[6]=s);let c;n[7]===Symbol.for(`react.memo_cache_sentinel`)?(c=(0,Q.jsx)(`span`,{className:`absolute left-2 flex h-3.5 w-3.5 items-center justify-center`,children:(0,Q.jsx)(tr,{children:(0,Q.jsx)(tn,{className:`h-4 w-4`})})}),n[7]=c):c=n[7];let l;return n[8]!==r||n[9]!==i||n[10]!==o||n[11]!==t||n[12]!==s?(l=(0,Q.jsxs)(Gn,{ref:t,className:s,checked:r,...o,children:[c,i]}),n[8]=r,n[9]=i,n[10]=o,n[11]=t,n[12]=s,n[13]=l):l=n[13],l});Fo.displayName=Gn.displayName;var Io=X.forwardRef((e,t)=>{let n=(0,Z.c)(12),r,i,a;n[0]===e?(r=n[1],i=n[2],a=n[3]):({className:i,children:r,...a}=e,n[0]=e,n[1]=r,n[2]=i,n[3]=a);let o;n[4]===i?o=n[5]:(o=K(`relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50`,i),n[4]=i,n[5]=o);let s;n[6]===Symbol.for(`react.memo_cache_sentinel`)?(s=(0,Q.jsx)(`span`,{className:`absolute left-2 flex h-3.5 w-3.5 items-center justify-center`,children:(0,Q.jsx)(tr,{children:(0,Q.jsx)(An,{className:`h-2 w-2 fill-current`})})}),n[6]=s):s=n[6];let c;return n[7]!==r||n[8]!==a||n[9]!==t||n[10]!==o?(c=(0,Q.jsxs)(Bn,{ref:t,className:o,...a,children:[s,r]}),n[7]=r,n[8]=a,n[9]=t,n[10]=o,n[11]=c):c=n[11],c});Io.displayName=Bn.displayName;var Lo=X.forwardRef((e,t)=>{let n=(0,Z.c)(11),r,i,a;n[0]===e?(r=n[1],i=n[2],a=n[3]):({className:r,inset:i,...a}=e,n[0]=e,n[1]=r,n[2]=i,n[3]=a);let o=i&&`pl-8`,s;n[4]!==r||n[5]!==o?(s=K(`px-2 py-1.5 text-sm font-semibold`,o,r),n[4]=r,n[5]=o,n[6]=s):s=n[6];let c;return n[7]!==a||n[8]!==t||n[9]!==s?(c=(0,Q.jsx)(Vn,{ref:t,className:s,...a}),n[7]=a,n[8]=t,n[9]=s,n[10]=c):c=n[10],c});Lo.displayName=Vn.displayName;var Ro=X.forwardRef((e,t)=>{let n=(0,Z.c)(9),r,i;n[0]===e?(r=n[1],i=n[2]):({className:r,...i}=e,n[0]=e,n[1]=r,n[2]=i);let a;n[3]===r?a=n[4]:(a=K(`-mx-1 my-1 h-px bg-muted`,r),n[3]=r,n[4]=a);let o;return n[5]!==i||n[6]!==t||n[7]!==a?(o=(0,Q.jsx)(xr,{ref:t,className:a,...i}),n[5]=i,n[6]=t,n[7]=a,n[8]=o):o=n[8],o});Ro.displayName=xr.displayName;var zo=e=>{let t=(0,Z.c)(8),n,r;t[0]===e?(n=t[1],r=t[2]):({className:n,...r}=e,t[0]=e,t[1]=n,t[2]=r);let i;t[3]===n?i=t[4]:(i=K(`ml-auto text-xs tracking-widest opacity-60`,n),t[3]=n,t[4]=i);let a;return t[5]!==r||t[6]!==i?(a=(0,Q.jsx)(`span`,{className:i,...r}),t[5]=r,t[6]=i,t[7]=a):a=t[7],a};zo.displayName=`DropdownMenuShortcut`;var Bo=`VS Code`,Vo={"VS Code":`vscode`,Cursor:`cursor`,Windsurf:`windsurf`,Xcode:`xcode`,"Android Studio":`android-studio`,Kiro:`kiro`,Terminal:`terminal`};function Ho({projectId:e,threadId:n,openWith:r}){let[i,a]=(0,X.useState)(!1),[o,s]=(0,X.useState)([]),[c,l]=(0,X.useState)(r??Bo),[u,d]=(0,X.useState)(!0);(0,X.useEffect)(()=>{(async()=>{try{let e=await t();s(e),!c&&e.length>0&&l(e[0])}catch(e){console.error(`Failed to fetch available programs:`,e),s([Bo])}finally{d(!1)}})()},[]),(0,X.useEffect)(()=>{r&&o.includes(r)&&l(r)},[r,o,l]);let f=async t=>{try{a(!0),l(t),await Ut(e,t),n?await rn(n,t):await ne(e,t),$({title:`Success`,description:`Opened project in ${t}`})}catch(e){console.error(`Failed to open project in ${t}:`,e);let n=`Failed to open project in ${t}`;if(e instanceof Error){let t=e;n=t.details?t.details:e.message}$({title:`Error`,description:n,variant:`destructive`})}finally{a(!1)}};return u?(0,Q.jsx)(q,{variant:`outline`,size:`sm`,className:`h-8`,disabled:!0,children:(0,Q.jsx)(`div`,{className:`h-4 w-4 animate-pulse bg-muted rounded`})}):(0,Q.jsxs)(`div`,{className:`flex items-center gap-0`,children:[(0,Q.jsx)(q,{variant:`outline`,size:`sm`,className:`h-8 rounded-r-none border-r-0 border-transparent`,disabled:i,onClick:async()=>{await f(c)},title:`Open in ${c}`,children:(0,Q.jsx)(`img`,{src:`/ide/${Vo[c]||Vo[Bo]}.svg`,alt:c,className:`h-4 w-4`})}),(0,Q.jsxs)(Oo,{children:[(0,Q.jsx)(ko,{asChild:!0,children:(0,Q.jsx)(q,{variant:`outline`,size:`sm`,className:`h-8 w-8 rounded-l-none px-1 border-transparent`,disabled:i,children:(0,Q.jsx)(H,{className:`h-3.5 w-3.5`})})}),(0,Q.jsx)(No,{align:`end`,children:o.map(e=>(0,Q.jsxs)(Po,{onClick:()=>f(e),disabled:i,className:`flex items-center gap-2`,children:[(0,Q.jsx)(`img`,{src:`/ide/${Vo[e]||Vo[Bo]}.svg`,alt:e,className:`h-4 w-4`}),e]},e))})]})]})}function Uo(e,t){return t?`Creating PR...`:e.status===`Behind`&&!e.hasChanges&&!e.hasUnpushedCommits?`Sync`:e.hasChanges?`Commit`:e.prExists&&e.prState===`OPEN`&&!e.hasChanges&&!e.hasUnpushedCommits?`Open PR`:e.commitsAheadOfDefault&&!e.prExists&&!e.hasChanges?`Create PR`:e.hasUnpushedCommits&&e.prExists?`Update PR`:`Commit`}function Wo(e,t){return t?(0,Q.jsx)(Rt,{className:`h-3.5 w-3.5 animate-spin`}):e.status===`Behind`&&!e.hasChanges&&!e.hasUnpushedCommits?(0,Q.jsx)(n,{className:`h-3.5 w-3.5`}):e.hasChanges?(0,Q.jsx)(En,{className:`h-3.5 w-3.5`}):e.prExists&&e.prState===`OPEN`&&!e.hasChanges&&!e.hasUnpushedCommits?(0,Q.jsx)(o,{className:`h-3.5 w-3.5`}):(0,Q.jsx)(_n,{className:`h-3.5 w-3.5`})}function Go(e){return e.status===`Behind`&&!e.hasChanges&&!e.hasUnpushedCommits?`Your branch "${e.currentBranch}" is behind "${e.defaultBranch??`main`}". This will rebase and sync with the latest changes`:e.hasChanges?e.changedFilesCount>0?`Commit ${e.changedFilesCount} changed file${e.changedFilesCount===1?``:`s`}`:`No changes to commit`:e.prExists&&e.prState===`OPEN`&&!e.hasChanges&&!e.hasUnpushedCommits?`View pull request in GitHub`:e.commitsAheadOfDefault&&!e.prExists&&!e.hasChanges?`Create pull request for committed changes`:e.hasUnpushedCommits&&e.prExists?`Update pull request with unpushed commits`:`No actions available`}function Ko(e,t){return t?!0:e.status===`Behind`&&!e.hasChanges&&!e.hasUnpushedCommits||e.prExists&&e.prState===`OPEN`&&!e.hasChanges&&!e.hasUnpushedCommits||e.commitsAheadOfDefault&&!e.prExists&&!e.hasChanges?!1:!e.hasChanges&&!e.hasUnpushedCommits}function qo(e){return e.hasChanges||e.status===`Behind`&&!e.hasChanges&&!e.hasUnpushedCommits||e.commitsAheadOfDefault&&!e.prExists&&!e.hasChanges}function Jo(e){let t=(0,Z.c)(102),{branchStatus:r,currentBranch:i,remoteUrl:a,hasRemoteBranch:s,hasUnpushedCommits:c,canCreateRepo:l,repoUrl:u,isRefreshing:d,isBrandState:f,gitUser:p,availableBranches:m,isLoadingBranches:h,onBranchSubMenuOpen:g,onCheckoutBranch:_,isDirectCommitMode:v,isLoading:y,isLoadingHistory:b,onFetch:x,onPull:S,onPush:C,onOpenHistory:w,onNewBranch:T,onCreatePR:E,onCreateRepo:D,onViewInGitHub:O}=e,k=`h-8 w-8 rounded-l-none px-1 border-transparent${f?` bg-brand text-brand-foreground hover:bg-brand/90 hover:text-brand-foreground`:``}`,A;t[0]===d?A=t[1]:(A=d?(0,Q.jsx)(Rt,{className:`h-3.5 w-3.5 animate-spin`}):(0,Q.jsx)(H,{className:`h-3.5 w-3.5`}),t[0]=d,t[1]=A);let j;t[2]!==y||t[3]!==k||t[4]!==A?(j=(0,Q.jsx)(ko,{asChild:!0,children:(0,Q.jsx)(q,{variant:`outline`,size:`sm`,className:k,disabled:y,children:A})}),t[2]=y,t[3]=k,t[4]=A,t[5]=j):j=t[5];let M;t[6]===g?M=t[7]:(M=async e=>{e&&await g()},t[6]=g,t[7]=M);let N;t[8]===Symbol.for(`react.memo_cache_sentinel`)?(N=(0,Q.jsx)(st,{className:`h-3 w-3 shrink-0`}),t[8]=N):N=t[8];let P=i||`Unknown`,F;t[9]===P?F=t[10]:(F=(0,Q.jsxs)(jo,{className:`gap-2 text-xs`,children:[N,(0,Q.jsx)(`span`,{className:`font-medium`,children:P})]}),t[9]=P,t[10]=F);let I;t[11]!==m||t[12]!==i||t[13]!==y||t[14]!==h||t[15]!==_?(I=h?(0,Q.jsxs)(`div`,{className:`px-2 py-1.5 text-xs text-muted-foreground flex items-center gap-2`,children:[(0,Q.jsx)(Rt,{className:`h-3 w-3 animate-spin`}),`Loading branches…`]}):m.length===0?(0,Q.jsx)(`div`,{className:`px-2 py-1.5 text-xs text-muted-foreground`,children:`No branches found`}):m.map(e=>(0,Q.jsxs)(Po,{disabled:e===i||y,onClick:()=>void _(e),children:[(0,Q.jsx)(st,{className:`h-3.5 w-3.5 mr-2 shrink-0`}),(0,Q.jsx)(`span`,{className:e===i?`font-semibold text-foreground`:``,children:e}),e===i&&(0,Q.jsx)(`span`,{className:`ml-auto text-xs text-muted-foreground`,children:`current`})]},e)),t[11]=m,t[12]=i,t[13]=y,t[14]=h,t[15]=_,t[16]=I):I=t[16];let L;t[17]===I?L=t[18]:(L=(0,Q.jsx)(Mo,{children:I}),t[17]=I,t[18]=L);let R;t[19]!==M||t[20]!==F||t[21]!==L?(R=(0,Q.jsxs)(Ao,{onOpenChange:M,children:[F,L]}),t[19]=M,t[20]=F,t[21]=L,t[22]=R):R=t[22];let z;t[23]!==r||t[24]!==a?(z=r===`Behind`&&(0,Q.jsxs)(`div`,{className:`px-2 py-1 text-xs text-amber-600`,children:[`Branch is behind `,a?`origin`:`remote`]}),t[23]=r,t[24]=a,t[25]=z):z=t[25];let B;t[26]===p?B=t[27]:(B=p&&(0,Q.jsxs)(`div`,{className:`px-2 py-1 text-xs text-muted-foreground`,children:[(0,Q.jsx)(`span`,{className:`font-medium`,children:`User:`}),` `,p]}),t[26]=p,t[27]=B);let V;t[28]===Symbol.for(`react.memo_cache_sentinel`)?(V=(0,Q.jsx)(Ro,{}),t[28]=V):V=t[28];let ee;t[29]===Symbol.for(`react.memo_cache_sentinel`)?(ee=(0,Q.jsx)(Mt,{className:`h-3.5 w-3.5 mr-2`}),t[29]=ee):ee=t[29];let te;t[30]!==y||t[31]!==x?(te=(0,Q.jsx)(Kr,{asChild:!0,children:(0,Q.jsxs)(Po,{onClick:x,disabled:y,children:[ee,`Fetch`]})}),t[30]=y,t[31]=x,t[32]=te):te=t[32];let ne;t[33]===Symbol.for(`react.memo_cache_sentinel`)?(ne=(0,Q.jsx)(Ur,{side:`right`,children:`Download latest information from remote without merging changes`}),t[33]=ne):ne=t[33];let re;t[34]===te?re=t[35]:(re=(0,Q.jsx)(Wr,{children:(0,Q.jsxs)(Gr,{children:[te,ne]})}),t[34]=te,t[35]=re);let U;t[36]!==s||t[37]!==y||t[38]!==S?(U=()=>{s&&!y&&S()},t[36]=s,t[37]=y,t[38]=S,t[39]=U):U=t[39];let W=!s||y?`opacity-50 cursor-not-allowed`:``,ie;t[40]===Symbol.for(`react.memo_cache_sentinel`)?(ie=(0,Q.jsx)(n,{className:`h-3.5 w-3.5 mr-2`}),t[40]=ie):ie=t[40];let ae;t[41]!==U||t[42]!==W?(ae=(0,Q.jsx)(Kr,{asChild:!0,children:(0,Q.jsxs)(Po,{onClick:U,className:W,children:[ie,`Pull`]})}),t[41]=U,t[42]=W,t[43]=ae):ae=t[43];let oe=s?`Pull latest changes from remote`:`No remote branch to pull from`,se;t[44]===oe?se=t[45]:(se=(0,Q.jsx)(Ur,{side:`right`,children:oe}),t[44]=oe,t[45]=se);let ce;t[46]!==ae||t[47]!==se?(ce=(0,Q.jsx)(Wr,{children:(0,Q.jsxs)(Gr,{children:[ae,se]})}),t[46]=ae,t[47]=se,t[48]=ce):ce=t[48];let le;t[49]!==s||t[50]!==y||t[51]!==C?(le=!s&&(0,Q.jsx)(Wr,{children:(0,Q.jsxs)(Gr,{children:[(0,Q.jsx)(Kr,{asChild:!0,children:(0,Q.jsxs)(Po,{onClick:C,disabled:y,children:[(0,Q.jsx)(It,{className:`h-3.5 w-3.5 mr-2`}),`Push Branch to Remote`]})}),(0,Q.jsx)(Ur,{side:`right`,children:`Create remote branch and push local commits`})]})}),t[49]=s,t[50]=y,t[51]=C,t[52]=le):le=t[52];let ue;t[53]!==c||t[54]!==y||t[55]!==C?(ue=()=>{c&&!y&&C()},t[53]=c,t[54]=y,t[55]=C,t[56]=ue):ue=t[56];let de=!c||y?`opacity-50 cursor-not-allowed`:``,fe;t[57]===Symbol.for(`react.memo_cache_sentinel`)?(fe=(0,Q.jsx)(It,{className:`h-3.5 w-3.5 mr-2`}),t[57]=fe):fe=t[57];let pe;t[58]!==ue||t[59]!==de?(pe=(0,Q.jsx)(Kr,{asChild:!0,children:(0,Q.jsxs)(Po,{onClick:ue,className:de,children:[fe,`Push Commits`]})}),t[58]=ue,t[59]=de,t[60]=pe):pe=t[60];let me=c?y?`Push in progress...`:`Push your uncommitted commits to the remote branch`:`No commits to push - your branch is up to date with remote`,he;t[61]===me?he=t[62]:(he=(0,Q.jsx)(Ur,{side:`right`,children:me}),t[61]=me,t[62]=he);let ge;t[63]!==pe||t[64]!==he?(ge=(0,Q.jsx)(Wr,{children:(0,Q.jsxs)(Gr,{children:[pe,he]})}),t[63]=pe,t[64]=he,t[65]=ge):ge=t[65];let _e=y||b,ve;t[66]===Symbol.for(`react.memo_cache_sentinel`)?(ve=(0,Q.jsx)(Et,{className:`h-3.5 w-3.5 mr-2`}),t[66]=ve):ve=t[66];let G;t[67]!==w||t[68]!==_e?(G=(0,Q.jsxs)(Po,{onClick:w,disabled:_e,children:[ve,`History`]}),t[67]=w,t[68]=_e,t[69]=G):G=t[69];let ye;t[70]===Symbol.for(`react.memo_cache_sentinel`)?(ye=(0,Q.jsx)(st,{className:`h-3.5 w-3.5 mr-2`}),t[70]=ye):ye=t[70];let be;t[71]!==y||t[72]!==T?(be=(0,Q.jsxs)(Po,{onClick:T,disabled:y,children:[ye,`New Branch`]}),t[71]=y,t[72]=T,t[73]=be):be=t[73];let xe;t[74]!==v||t[75]!==y||t[76]!==E?(xe=!v&&(0,Q.jsxs)(Po,{onClick:E,disabled:y,children:[(0,Q.jsx)(_n,{className:`h-3.5 w-3.5 mr-2`}),`Create Pull Request`]}),t[74]=v,t[75]=y,t[76]=E,t[77]=xe):xe=t[77];let Se;t[78]!==l||t[79]!==y||t[80]!==D?(Se=l&&(0,Q.jsxs)(Po,{onClick:D,disabled:y,children:[(0,Q.jsx)(tt,{className:`h-3.5 w-3.5 mr-2`}),`Create Repo`]}),t[78]=l,t[79]=y,t[80]=D,t[81]=Se):Se=t[81];let Ce;t[82]!==y||t[83]!==O||t[84]!==u?(Ce=u&&(0,Q.jsxs)(Po,{onClick:O,disabled:y,children:[(0,Q.jsx)(o,{className:`h-3.5 w-3.5 mr-2`}),`View in GitHub`]}),t[82]=y,t[83]=O,t[84]=u,t[85]=Ce):Ce=t[85];let we;t[86]!==R||t[87]!==z||t[88]!==B||t[89]!==re||t[90]!==ce||t[91]!==le||t[92]!==ge||t[93]!==G||t[94]!==be||t[95]!==xe||t[96]!==Se||t[97]!==Ce?(we=(0,Q.jsxs)(No,{align:`end`,children:[R,z,B,V,re,ce,le,ge,G,be,xe,Se,Ce]}),t[86]=R,t[87]=z,t[88]=B,t[89]=re,t[90]=ce,t[91]=le,t[92]=ge,t[93]=G,t[94]=be,t[95]=xe,t[96]=Se,t[97]=Ce,t[98]=we):we=t[98];let Te;return t[99]!==j||t[100]!==we?(Te=(0,Q.jsxs)(Oo,{children:[j,we]}),t[99]=j,t[100]=we,t[101]=Te):Te=t[101],Te}function Yo(){return{autoGenerateCommitMessage:bt(),autoGeneratePRInfo:Zt(),privateRepositoryDefault:Tt()}}function Xo(e){e.autoGenerateCommitMessage!==void 0&&St(e.autoGenerateCommitMessage),e.autoGeneratePRInfo!==void 0&&et(e.autoGeneratePRInfo),e.privateRepositoryDefault!==void 0&&gn(e.privateRepositoryDefault)}function Zo(e){return e?!0:($({title:`Error`,description:`No thread selected`,variant:`destructive`}),!1)}function Qo(e){let t=(0,Z.c)(57),{open:n,onOpenChange:r,commitMessage:i,onCommitMessageChange:a,autoGenerateCommitMessage:o,onAutoGenerateChange:s,isGeneratingMessage:c,isLoading:l,onGenerateMessage:u,onCommit:f,currentBranch:p}=e,m;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(m=(0,Q.jsx)(d,{children:`Commit Changes`}),t[0]=m):m=t[0];let h;t[1]===p?h=t[2]:(h=(0,Q.jsxs)(jn,{children:[m,(0,Q.jsxs)(W,{children:[`Enter a commit message for your changes on branch `,p]})]}),t[1]=p,t[2]=h);let g;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(g=(0,Q.jsx)(J,{htmlFor:`commit-message`,children:`Commit Message`}),t[3]=g):g=t[3];let _;t[4]===a?_=t[5]:(_=e=>a(e.target.value),t[4]=a,t[5]=_);let v;t[6]!==i||t[7]!==_?(v=(0,Q.jsx)(Hr,{id:`commit-message`,placeholder:`Enter commit message...`,value:i,onChange:_,rows:4,className:`pr-10`}),t[6]=i,t[7]=_,t[8]=v):v=t[8];let y=c||l,b;t[9]===c?b=t[10]:(b=c?(0,Q.jsx)(Rt,{className:`h-3.5 w-3.5 animate-spin`}):(0,Q.jsx)(Oe,{className:`h-3.5 w-3.5`}),t[9]=c,t[10]=b);let x;t[11]!==u||t[12]!==y||t[13]!==b?(x=(0,Q.jsx)(Kr,{asChild:!0,children:(0,Q.jsx)(q,{type:`button`,variant:`ghost`,size:`icon`,className:`absolute top-2 right-2 h-6 w-6`,onClick:u,disabled:y,children:b})}),t[11]=u,t[12]=y,t[13]=b,t[14]=x):x=t[14];let S=c?`Generating commit message...`:`Generate commit message with AI`,C;t[15]===S?C=t[16]:(C=(0,Q.jsx)(Ur,{children:S}),t[15]=S,t[16]=C);let w;t[17]!==C||t[18]!==x?(w=(0,Q.jsx)(Wr,{children:(0,Q.jsxs)(Gr,{children:[x,C]})}),t[17]=C,t[18]=x,t[19]=w):w=t[19];let T;t[20]!==w||t[21]!==v?(T=(0,Q.jsxs)(`div`,{className:`grid gap-2`,children:[g,(0,Q.jsxs)(`div`,{className:`relative`,children:[v,w]})]}),t[20]=w,t[21]=v,t[22]=T):T=t[22];let E;t[23]===s?E=t[24]:(E=e=>s(e===!0),t[23]=s,t[24]=E);let O;t[25]!==o||t[26]!==E?(O=(0,Q.jsx)(Yr,{id:`auto-generate`,checked:o,onCheckedChange:E}),t[25]=o,t[26]=E,t[27]=O):O=t[27];let k;t[28]===Symbol.for(`react.memo_cache_sentinel`)?(k=(0,Q.jsx)(J,{htmlFor:`auto-generate`,className:`text-sm font-normal`,children:`Auto generate commit messages`}),t[28]=k):k=t[28];let A;t[29]===O?A=t[30]:(A=(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[O,k]}),t[29]=O,t[30]=A);let j;t[31]!==T||t[32]!==A?(j=(0,Q.jsxs)(`div`,{className:`grid gap-4 py-4`,children:[T,A]}),t[31]=T,t[32]=A,t[33]=j):j=t[33];let M;t[34]===r?M=t[35]:(M=()=>r(!1),t[34]=r,t[35]=M);let N;t[36]!==l||t[37]!==M?(N=(0,Q.jsx)(q,{variant:`outline`,onClick:M,disabled:l,children:`Cancel`}),t[36]=l,t[37]=M,t[38]=N):N=t[38];let P;t[39]!==i||t[40]!==l?(P=l||!i.trim(),t[39]=i,t[40]=l,t[41]=P):P=t[41];let F=l?`Committing...`:`Commit`,L;t[42]!==f||t[43]!==P||t[44]!==F?(L=(0,Q.jsx)(q,{onClick:f,disabled:P,children:F}),t[42]=f,t[43]=P,t[44]=F,t[45]=L):L=t[45];let R;t[46]!==N||t[47]!==L?(R=(0,Q.jsxs)(De,{children:[N,L]}),t[46]=N,t[47]=L,t[48]=R):R=t[48];let z;t[49]!==j||t[50]!==h||t[51]!==R?(z=(0,Q.jsxs)(I,{children:[h,j,R]}),t[49]=j,t[50]=h,t[51]=R,t[52]=z):z=t[52];let B;return t[53]!==r||t[54]!==n||t[55]!==z?(B=(0,Q.jsx)(D,{open:n,onOpenChange:r,children:z}),t[53]=r,t[54]=n,t[55]=z,t[56]=B):B=t[56],B}function $o(e){let t=(0,Z.c)(62),{open:n,onOpenChange:r,prTitle:i,onPrTitleChange:a,prDescription:o,onPrDescriptionChange:c,isGeneratingPRInfo:l,isLoading:u,onGeneratePRInfo:f,onCreatePR:p,currentBranch:m,autoGeneratePRInfo:h,onAutoGeneratePRInfoChange:g}=e,_;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(_=(0,Q.jsx)(d,{children:`Create Pull Request`}),t[0]=_):_=t[0];let v;t[1]===m?v=t[2]:(v=(0,Q.jsxs)(jn,{children:[_,(0,Q.jsxs)(W,{children:[`Create a pull request for branch `,m]})]}),t[1]=m,t[2]=v);let y;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(y=(0,Q.jsx)(J,{htmlFor:`pr-title`,children:`Title (optional)`}),t[3]=y):y=t[3];let b=m||`Enter PR title...`,x;t[4]===a?x=t[5]:(x=e=>a(e.target.value),t[4]=a,t[5]=x);let S;t[6]!==i||t[7]!==b||t[8]!==x?(S=(0,Q.jsxs)(`div`,{className:`grid gap-2`,children:[y,(0,Q.jsx)(s,{id:`pr-title`,placeholder:b,value:i,onChange:x})]}),t[6]=i,t[7]=b,t[8]=x,t[9]=S):S=t[9];let C;t[10]===Symbol.for(`react.memo_cache_sentinel`)?(C=(0,Q.jsx)(J,{htmlFor:`pr-description`,children:`Description (optional)`}),t[10]=C):C=t[10];let w;t[11]===c?w=t[12]:(w=e=>c(e.target.value),t[11]=c,t[12]=w);let T;t[13]!==o||t[14]!==w?(T=(0,Q.jsx)(Hr,{id:`pr-description`,placeholder:`Enter PR description...`,value:o,onChange:w,rows:4,className:`pr-10`}),t[13]=o,t[14]=w,t[15]=T):T=t[15];let E=l||u,O;t[16]===l?O=t[17]:(O=l?(0,Q.jsx)(Rt,{className:`h-3.5 w-3.5 animate-spin`}):(0,Q.jsx)(Oe,{className:`h-3.5 w-3.5`}),t[16]=l,t[17]=O);let k;t[18]!==f||t[19]!==E||t[20]!==O?(k=(0,Q.jsx)(Kr,{asChild:!0,children:(0,Q.jsx)(q,{type:`button`,variant:`ghost`,size:`icon`,className:`absolute top-2 right-2 h-6 w-6`,onClick:f,disabled:E,children:O})}),t[18]=f,t[19]=E,t[20]=O,t[21]=k):k=t[21];let A=l?`Generating PR description...`:`Generate PR title and description with AI`,j;t[22]===A?j=t[23]:(j=(0,Q.jsx)(Ur,{children:A}),t[22]=A,t[23]=j);let M;t[24]!==k||t[25]!==j?(M=(0,Q.jsx)(Wr,{children:(0,Q.jsxs)(Gr,{children:[k,j]})}),t[24]=k,t[25]=j,t[26]=M):M=t[26];let N;t[27]!==M||t[28]!==T?(N=(0,Q.jsxs)(`div`,{className:`grid gap-2`,children:[C,(0,Q.jsxs)(`div`,{className:`relative`,children:[T,M]})]}),t[27]=M,t[28]=T,t[29]=N):N=t[29];let P;t[30]===g?P=t[31]:(P=e=>g(e===!0),t[30]=g,t[31]=P);let F;t[32]!==h||t[33]!==P?(F=(0,Q.jsx)(Yr,{id:`auto-generate-pr`,checked:h,onCheckedChange:P}),t[32]=h,t[33]=P,t[34]=F):F=t[34];let L;t[35]===Symbol.for(`react.memo_cache_sentinel`)?(L=(0,Q.jsx)(J,{htmlFor:`auto-generate-pr`,className:`text-sm font-normal`,children:`Auto generate PR title and description`}),t[35]=L):L=t[35];let R;t[36]===F?R=t[37]:(R=(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[F,L]}),t[36]=F,t[37]=R);let z;t[38]!==N||t[39]!==R||t[40]!==S?(z=(0,Q.jsxs)(`div`,{className:`grid gap-4 py-4`,children:[S,N,R]}),t[38]=N,t[39]=R,t[40]=S,t[41]=z):z=t[41];let B;t[42]===r?B=t[43]:(B=()=>r(!1),t[42]=r,t[43]=B);let V;t[44]!==u||t[45]!==B?(V=(0,Q.jsx)(q,{variant:`outline`,onClick:B,disabled:u,children:`Cancel`}),t[44]=u,t[45]=B,t[46]=V):V=t[46];let ee=u?`Creating...`:`Create PR`,H;t[47]!==u||t[48]!==p||t[49]!==ee?(H=(0,Q.jsx)(q,{onClick:p,disabled:u,children:ee}),t[47]=u,t[48]=p,t[49]=ee,t[50]=H):H=t[50];let te;t[51]!==V||t[52]!==H?(te=(0,Q.jsxs)(De,{children:[V,H]}),t[51]=V,t[52]=H,t[53]=te):te=t[53];let ne;t[54]!==v||t[55]!==z||t[56]!==te?(ne=(0,Q.jsxs)(I,{children:[v,z,te]}),t[54]=v,t[55]=z,t[56]=te,t[57]=ne):ne=t[57];let re;return t[58]!==r||t[59]!==n||t[60]!==ne?(re=(0,Q.jsx)(D,{open:n,onOpenChange:r,children:ne}),t[58]=r,t[59]=n,t[60]=ne,t[61]=re):re=t[61],re}function es(e){let t=(0,Z.c)(48),{open:n,onOpenChange:r,repoName:i,onRepoNameChange:a,repoDescription:o,onRepoDescriptionChange:c,isPrivateRepo:l,onPrivateRepoChange:u,isLoading:f,onCreateRepo:p}=e,m;t[0]!==r||t[1]!==c||t[2]!==a?(m=e=>{e||(a(``),c(``)),r(e)},t[0]=r,t[1]=c,t[2]=a,t[3]=m):m=t[3];let h;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(h=(0,Q.jsxs)(jn,{children:[(0,Q.jsx)(d,{children:`Create GitHub Repository`}),(0,Q.jsx)(W,{children:`Create a new GitHub repository and push your local repository`})]}),t[4]=h):h=t[4];let g;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(g=(0,Q.jsx)(J,{htmlFor:`repo-name`,children:`Repository Name (optional)`}),t[5]=g):g=t[5];let _;t[6]===a?_=t[7]:(_=e=>a(e.target.value),t[6]=a,t[7]=_);let v;t[8]!==i||t[9]!==_?(v=(0,Q.jsxs)(`div`,{className:`grid gap-2`,children:[g,(0,Q.jsx)(s,{id:`repo-name`,placeholder:`Leave empty to use current folder name`,value:i,onChange:_})]}),t[8]=i,t[9]=_,t[10]=v):v=t[10];let y;t[11]===Symbol.for(`react.memo_cache_sentinel`)?(y=(0,Q.jsx)(J,{htmlFor:`repo-description`,children:`Description (optional)`}),t[11]=y):y=t[11];let b;t[12]===c?b=t[13]:(b=e=>c(e.target.value),t[12]=c,t[13]=b);let x;t[14]!==o||t[15]!==b?(x=(0,Q.jsxs)(`div`,{className:`grid gap-2`,children:[y,(0,Q.jsx)(Hr,{id:`repo-description`,placeholder:`Enter repository description...`,value:o,onChange:b,rows:3})]}),t[14]=o,t[15]=b,t[16]=x):x=t[16];let S;t[17]===u?S=t[18]:(S=e=>u(e===!0),t[17]=u,t[18]=S);let C;t[19]!==l||t[20]!==S?(C=(0,Q.jsx)(Yr,{id:`repo-private`,checked:l,onCheckedChange:S}),t[19]=l,t[20]=S,t[21]=C):C=t[21];let w;t[22]===Symbol.for(`react.memo_cache_sentinel`)?(w=(0,Q.jsx)(J,{htmlFor:`repo-private`,className:`text-sm font-normal`,children:`Private repository`}),t[22]=w):w=t[22];let T;t[23]===C?T=t[24]:(T=(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[C,w]}),t[23]=C,t[24]=T);let E;t[25]!==T||t[26]!==v||t[27]!==x?(E=(0,Q.jsxs)(`div`,{className:`grid gap-4 py-4`,children:[v,x,T]}),t[25]=T,t[26]=v,t[27]=x,t[28]=E):E=t[28];let O;t[29]===r?O=t[30]:(O=()=>r(!1),t[29]=r,t[30]=O);let k;t[31]!==f||t[32]!==O?(k=(0,Q.jsx)(q,{variant:`outline`,onClick:O,disabled:f,children:`Cancel`}),t[31]=f,t[32]=O,t[33]=k):k=t[33];let A=f?`Creating...`:`Create & Push`,j;t[34]!==f||t[35]!==p||t[36]!==A?(j=(0,Q.jsx)(q,{onClick:p,disabled:f,children:A}),t[34]=f,t[35]=p,t[36]=A,t[37]=j):j=t[37];let M;t[38]!==k||t[39]!==j?(M=(0,Q.jsxs)(De,{children:[k,j]}),t[38]=k,t[39]=j,t[40]=M):M=t[40];let N;t[41]!==E||t[42]!==M?(N=(0,Q.jsxs)(I,{children:[h,E,M]}),t[41]=E,t[42]=M,t[43]=N):N=t[43];let P;return t[44]!==n||t[45]!==m||t[46]!==N?(P=(0,Q.jsx)(D,{open:n,onOpenChange:m,children:N}),t[44]=n,t[45]=m,t[46]=N,t[47]=P):P=t[47],P}function ts(e){let t=(0,Z.c)(28),{open:n,onOpenChange:r,commits:i,displayedCommits:a,isLoadingMore:o,onScroll:s,currentBranch:c}=e,l;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(l=(0,Q.jsx)(d,{children:`Commit History`}),t[0]=l):l=t[0];let u;t[1]===c?u=t[2]:(u=(0,Q.jsxs)(jn,{children:[l,(0,Q.jsxs)(W,{children:[`Recent commits on branch `,c]})]}),t[1]=c,t[2]=u);let f;t[3]===a?f=t[4]:(f=a.length>0?a.map(ns):(0,Q.jsx)(`p`,{className:`text-sm text-slate-500 text-center py-8`,children:`No commits found`}),t[3]=a,t[4]=f);let p;t[5]===o?p=t[6]:(p=o&&(0,Q.jsx)(`div`,{className:`p-3 text-center`,children:(0,Q.jsx)(Rt,{className:`h-4 w-4 animate-spin inline`})}),t[5]=o,t[6]=p);let m;t[7]!==i.length||t[8]!==a.length||t[9]!==o?(m=a.length<i.length&&!o&&(0,Q.jsx)(`div`,{className:`p-3 text-center text-xs text-slate-500`,children:`Scroll to load more`}),t[7]=i.length,t[8]=a.length,t[9]=o,t[10]=m):m=t[10];let h;t[11]!==f||t[12]!==p||t[13]!==m?(h=(0,Q.jsxs)(`div`,{className:`divide-y`,children:[f,p,m]}),t[11]=f,t[12]=p,t[13]=m,t[14]=h):h=t[14];let g;t[15]!==s||t[16]!==h?(g=(0,Q.jsx)(`div`,{className:`flex-1 overflow-y-auto border rounded-lg`,onScroll:s,children:h}),t[15]=s,t[16]=h,t[17]=g):g=t[17];let _;t[18]===r?_=t[19]:(_=(0,Q.jsx)(De,{children:(0,Q.jsx)(q,{onClick:()=>r(!1),children:`Close`})}),t[18]=r,t[19]=_);let v;t[20]!==u||t[21]!==g||t[22]!==_?(v=(0,Q.jsxs)(I,{className:`max-w-2xl max-h-[80vh] flex flex-col`,children:[u,g,_]}),t[20]=u,t[21]=g,t[22]=_,t[23]=v):v=t[23];let y;return t[24]!==r||t[25]!==n||t[26]!==v?(y=(0,Q.jsx)(D,{open:n,onOpenChange:r,children:v}),t[24]=r,t[25]=n,t[26]=v,t[27]=y):y=t[27],y}function ns(e){return(0,Q.jsxs)(`div`,{className:`p-3 hover:bg-slate-50 dark:hover:bg-slate-900 transition-colors`,children:[(0,Q.jsx)(`p`,{className:`text-sm font-medium break-words`,children:e.message}),(0,Q.jsxs)(`p`,{className:`text-xs text-slate-600 dark:text-slate-400 mt-1`,children:[(0,Q.jsx)(`span`,{className:`font-mono`,children:e.hash.substring(0,7)}),` •`,` `,e.author,` • `,new Date(e.date).toLocaleDateString()]})]},e.hash)}function rs(e){let t=(0,Z.c)(15),{open:n,onOpenChange:r,isLoading:i,onPushAndCreatePR:a,onCancel:o}=e,s;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(s=(0,Q.jsxs)(jn,{children:[(0,Q.jsx)(d,{children:`Push Branch First`}),(0,Q.jsx)(W,{children:`Your branch needs to be pushed to the remote before creating a pull request. Would you like to push it now?`})]}),t[0]=s):s=t[0];let c;t[1]!==i||t[2]!==o?(c=(0,Q.jsx)(q,{variant:`outline`,onClick:o,disabled:i,children:`Cancel`}),t[1]=i,t[2]=o,t[3]=c):c=t[3];let l=i?`Pushing...`:`Push & Create PR`,u;t[4]!==i||t[5]!==a||t[6]!==l?(u=(0,Q.jsx)(q,{onClick:a,disabled:i,children:l}),t[4]=i,t[5]=a,t[6]=l,t[7]=u):u=t[7];let f;t[8]!==c||t[9]!==u?(f=(0,Q.jsxs)(I,{children:[s,(0,Q.jsxs)(De,{children:[c,u]})]}),t[8]=c,t[9]=u,t[10]=f):f=t[10];let p;return t[11]!==r||t[12]!==n||t[13]!==f?(p=(0,Q.jsx)(D,{open:n,onOpenChange:r,children:f}),t[11]=r,t[12]=n,t[13]=f,t[14]=p):p=t[14],p}function is(e){let t=(0,Z.c)(27),{open:n,onOpenChange:r,onCommitFirst:i,onStashAndPull:a,onCancel:o,isLoading:s}=e,l=s===void 0?!1:s,u;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(u=(0,Q.jsxs)(jn,{children:[(0,Q.jsxs)(d,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(c,{className:`h-5 w-5 text-amber-500`}),`Uncommitted Changes Detected`]}),(0,Q.jsx)(W,{children:`You have uncommitted changes. You need to handle them before pulling from the remote branch.`})]}),t[0]=u):u=t[0];let f;t[1]===Symbol.for(`react.memo_cache_sentinel`)?(f=(0,Q.jsx)(`div`,{className:`text-sm text-muted-foreground`,children:`Choose how you want to proceed:`}),t[1]=f):f=t[1];let p;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(p=(0,Q.jsx)(En,{className:`h-4 w-4 mr-2`}),t[2]=p):p=t[2];let m;t[3]!==l||t[4]!==i?(m=(0,Q.jsxs)(q,{onClick:i,disabled:l,className:`w-full justify-start`,variant:`outline`,children:[p,`Commit changes first, then pull`]}),t[3]=l,t[4]=i,t[5]=m):m=t[5];let h;t[6]===Symbol.for(`react.memo_cache_sentinel`)?(h=(0,Q.jsx)(_t,{className:`h-4 w-4 mr-2`}),t[6]=h):h=t[6];let g;t[7]!==l||t[8]!==a?(g=(0,Q.jsxs)(q,{onClick:a,disabled:l,className:`w-full justify-start`,variant:`outline`,children:[h,`Stash changes → Pull → Restore changes`]}),t[7]=l,t[8]=a,t[9]=g):g=t[9];let _;t[10]!==m||t[11]!==g?(_=(0,Q.jsxs)(`div`,{className:`space-y-2`,children:[m,g]}),t[10]=m,t[11]=g,t[12]=_):_=t[12];let v;t[13]===Symbol.for(`react.memo_cache_sentinel`)?(v=(0,Q.jsx)(`strong`,{children:`Commit first:`}),t[13]=v):v=t[13];let y;t[14]===Symbol.for(`react.memo_cache_sentinel`)?(y=(0,Q.jsxs)(`div`,{className:`text-xs text-muted-foreground mt-4`,children:[v,` Safe option, preserves changes in your commit history`,(0,Q.jsx)(`br`,{}),(0,Q.jsx)(`strong`,{children:`Stash and pull:`}),` Temporary option, changes will be restored after pulling`]}),t[14]=y):y=t[14];let b;t[15]===_?b=t[16]:(b=(0,Q.jsx)(`div`,{className:`py-4`,children:(0,Q.jsxs)(`div`,{className:`space-y-3`,children:[f,_,y]})}),t[15]=_,t[16]=b);let x;t[17]!==l||t[18]!==o?(x=(0,Q.jsx)(De,{children:(0,Q.jsx)(q,{variant:`ghost`,onClick:o,disabled:l,children:`Cancel`})}),t[17]=l,t[18]=o,t[19]=x):x=t[19];let S;t[20]!==b||t[21]!==x?(S=(0,Q.jsxs)(I,{className:`sm:max-w-[425px]`,children:[u,b,x]}),t[20]=b,t[21]=x,t[22]=S):S=t[22];let C;return t[23]!==r||t[24]!==n||t[25]!==S?(C=(0,Q.jsx)(D,{open:n,onOpenChange:r,children:S}),t[23]=r,t[24]=n,t[25]=S,t[26]=C):C=t[26],C}function as(e){let t=(0,Z.c)(19),{open:n,onOpenChange:r,onNewBranch:i,onJustOpen:a,isLoading:o,defaultBranch:s}=e,c=o===void 0?!1:o,l;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(l=(0,Q.jsx)(d,{children:`Pull Request Merged`}),t[0]=l):l=t[0];let u=s?` from ${s}`:``,f;t[1]===u?f=t[2]:(f=(0,Q.jsxs)(jn,{children:[l,(0,Q.jsxs)(W,{children:[`As the pull request has been merged a new branch will be created`,u,`.`]})]}),t[1]=u,t[2]=f);let p;t[3]!==c||t[4]!==a?(p=(0,Q.jsx)(q,{variant:`ghost`,onClick:a,disabled:c,children:`Just Open`}),t[3]=c,t[4]=a,t[5]=p):p=t[5];let m;t[6]!==c||t[7]!==i?(m=(0,Q.jsx)(q,{onClick:i,disabled:c,children:`New Branch`}),t[6]=c,t[7]=i,t[8]=m):m=t[8];let h;t[9]!==p||t[10]!==m?(h=(0,Q.jsxs)(De,{children:[p,m]}),t[9]=p,t[10]=m,t[11]=h):h=t[11];let g;t[12]!==f||t[13]!==h?(g=(0,Q.jsxs)(I,{children:[f,h]}),t[12]=f,t[13]=h,t[14]=g):g=t[14];let _;return t[15]!==r||t[16]!==n||t[17]!==g?(_=(0,Q.jsx)(D,{open:n,onOpenChange:r,children:g}),t[15]=r,t[16]=n,t[17]=g,t[18]=_):_=t[18],_}function os(e){let t=(0,Z.c)(35),{open:n,onOpenChange:r,branchName:i,onBranchNameChange:a,isLoading:o,onCreateBranch:c}=e,l;t[0]!==i||t[1]!==o||t[2]!==c?(l=e=>{e.key===`Enter`&&i.trim()&&!o&&c()},t[0]=i,t[1]=o,t[2]=c,t[3]=l):l=t[3];let u=l,f;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(f=(0,Q.jsxs)(jn,{children:[(0,Q.jsx)(d,{children:`New Branch`}),(0,Q.jsx)(W,{children:`Enter a name for the new branch.`})]}),t[4]=f):f=t[4];let p;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(p=(0,Q.jsx)(J,{htmlFor:`branch-name`,children:`Branch Name`}),t[5]=p):p=t[5];let m;t[6]===a?m=t[7]:(m=e=>a(e.target.value),t[6]=a,t[7]=m);let h;t[8]!==i||t[9]!==u||t[10]!==o||t[11]!==m?(h=(0,Q.jsx)(`div`,{className:`grid gap-4 py-4`,children:(0,Q.jsxs)(`div`,{className:`grid gap-2`,children:[p,(0,Q.jsx)(s,{id:`branch-name`,placeholder:`e.g. feature/my-feature`,value:i,onChange:m,onKeyDown:u,disabled:o,autoFocus:!0})]})}),t[8]=i,t[9]=u,t[10]=o,t[11]=m,t[12]=h):h=t[12];let g;t[13]===r?g=t[14]:(g=()=>r(!1),t[13]=r,t[14]=g);let _;t[15]!==o||t[16]!==g?(_=(0,Q.jsx)(q,{variant:`outline`,onClick:g,disabled:o,children:`Cancel`}),t[15]=o,t[16]=g,t[17]=_):_=t[17];let v;t[18]!==i||t[19]!==o?(v=o||!i.trim(),t[18]=i,t[19]=o,t[20]=v):v=t[20];let y=o?`Creating...`:`Create Branch`,b;t[21]!==c||t[22]!==v||t[23]!==y?(b=(0,Q.jsx)(q,{onClick:c,disabled:v,children:y}),t[21]=c,t[22]=v,t[23]=y,t[24]=b):b=t[24];let x;t[25]!==b||t[26]!==_?(x=(0,Q.jsxs)(De,{children:[_,b]}),t[25]=b,t[26]=_,t[27]=x):x=t[27];let S;t[28]!==x||t[29]!==h?(S=(0,Q.jsxs)(I,{children:[f,h,x]}),t[28]=x,t[29]=h,t[30]=S):S=t[30];let C;return t[31]!==r||t[32]!==n||t[33]!==S?(C=(0,Q.jsx)(D,{open:n,onOpenChange:r,children:S}),t[31]=r,t[32]=n,t[33]=S,t[34]=C):C=t[34],C}var ss=3e4;function cs(e){let[t,n]=(0,X.useState)(!1),[r,i]=(0,X.useState)(0),[a,o]=(0,X.useState)(!1),[s,c]=(0,X.useState)(``),[u,d]=(0,X.useState)(!1),[f,p]=(0,X.useState)(``),[m,h]=(0,X.useState)(!1),[g,_]=(0,X.useState)(void 0),[v,y]=(0,X.useState)(!1),[b,x]=(0,X.useState)(`Up to date`),[S,C]=(0,X.useState)(null),[w,T]=(0,X.useState)(!1),[E,D]=(0,X.useState)(void 0),[O,k]=(0,X.useState)(void 0),[A,j]=(0,X.useState)(!1),[M,N]=(0,X.useState)(!1),P=(0,X.useRef)(!0),F=(0,X.useCallback)(e=>{n(e.hasChanges),i(e.changedFilesCount),o(e.hasUnpushedCommits),c(e.currentBranch),y(e.hasRemoteBranch),d(e.isOnGitHub),p(e.remoteUrl),h(e.canCreateRepo),_(e.repoUrl),x(e.status),C(e.defaultBranch??null),T(e.prExists),D(e.prUrl),k(e.prState),j(e.commitsAheadOfDefault??!1)},[]),I=(0,X.useCallback)(async(t=!1)=>{if(!e)return;let n=setTimeout(()=>N(!0),100);try{let n=`unified-git-status-${e}`;t&&vn.invalidate(n),F(await vn.get(n,()=>l(e,t),ss))}catch(e){console.error(`Failed to fetch unified git status:`,e)}finally{clearTimeout(n),N(!1)}},[e,F]);return(0,X.useEffect)(()=>{e&&(async()=>{if(P.current){let t=`unified-git-status-${e}`,n=vn.getSync(t);n&&F(n),P.current=!1}await I()})()},[e,I,F]),{hasChanges:t,changedFilesCount:r,hasUnpushedCommits:a,hasRemoteBranch:v,currentBranch:s,isOnGitHub:u,remoteUrl:f,canCreateRepo:m,repoUrl:g,status:b,defaultBranch:S,prExists:w,prUrl:E,prState:O,commitsAheadOfDefault:A,isRefreshing:M,fetchUnifiedStatus:I}}function ls(e){let t=e.split(`/`);return t.length>=2?{provider:t[0],model:t.slice(1).join(`/`)}:{provider:void 0,model:e}}function us(e,t,n){let[r,i]=(0,X.useState)(!1),[a,o]=(0,X.useState)(!1),s=()=>{let t=e?n[e]:void 0;return t?.id?t.provider?{provider:t.provider,model:t.id}:ls(t.id):{provider:void 0,model:void 0}};return{isGeneratingMessage:r,isGeneratingPRInfo:a,generateCommitMessageWithAI:async()=>{if(!e)return null;try{i(!0);let{provider:t,model:n}=s();return await en(e,n,t)}catch(e){return console.error(`Failed to generate commit message:`,e),$({title:`Error`,description:e instanceof Error?e.message:`Failed to generate commit message`,variant:`destructive`}),null}finally{i(!1)}},generatePRInfoWithAI:async()=>{if(!e)return null;try{o(!0);let{provider:t,model:n}=s(),r=await Je(e,n,t);return $({title:`Success`,description:`PR title and description generated`}),r}catch(e){return console.error(`Failed to generate PR info:`,e),$({title:`Error`,description:e instanceof Error?e.message:`Failed to generate PR info`,variant:`destructive`}),null}finally{o(!1)}}}}function ds({projectId:e,threadId:t}){let{state:n,dispatch:r}=Ar(),[i,a]=(0,X.useState)(!1),[o,s]=(0,X.useState)(!1),[c,l]=(0,X.useState)(!1),[u,d]=(0,X.useState)(!1),[f,m]=(0,X.useState)(``),[h,g]=(0,X.useState)(``),[v,y]=(0,X.useState)(``),[b,x]=(0,X.useState)(!1),[S,C]=(0,X.useState)(null),w=(0,X.useRef)(!1),T=(0,X.useRef)(!1),[E,D]=(0,X.useState)(!1),[k,A]=(0,X.useState)([]),[j,M]=(0,X.useState)(!1),[P,F]=(0,X.useState)([]),[I,L]=(0,X.useState)(!1),[z,B]=(0,X.useState)(!1),[V,ee]=(0,X.useState)(``),[H,te]=(0,X.useState)(``),[ne,re]=(0,X.useState)(``),[U,W]=(0,X.useState)(!1),[ie,oe]=(0,X.useState)(!1),[se,ce]=(0,X.useState)(!1),[ue,de]=(0,X.useState)(!1),[fe,me]=(0,X.useState)(``),[he,ge]=(0,X.useState)([]),[_e,ve]=(0,X.useState)(!1),G=cs(t),ye=us(t,e,n.projectModelSelections);async function be(){N();let e=await ut();r({type:Y.SetProjects,projects:e.projects})}let[Se,Ce]=(0,X.useState)(()=>Yo()),we=n.projects.find(t=>t.projectId===e),Te=we?.commitMethod===qt.Direct;(0,X.useEffect)(()=>{function e(){document.visibilityState===`visible`&&G.fetchUnifiedStatus(!0)}return document.addEventListener(`visibilitychange`,e),()=>document.removeEventListener(`visibilitychange`,e)},[G.fetchUnifiedStatus]),(0,X.useEffect)(()=>{z&&we?.name&&!V&&ee(we.name)},[z,we?.name,V]),(0,X.useEffect)(()=>{Xo(Se)},[Se]),(0,X.useEffect)(()=>{let e=!0;return ln().then(t=>{e&&re(t)}).catch(()=>{}),()=>{e=!1}},[]),(0,X.useEffect)(()=>{if(!c){T.current=!1;return}if(c&&Se.autoGenerateCommitMessage&&!f.trim()&&t&&!T.current){T.current=!0;async function e(){let e=await ye.generateCommitMessageWithAI();e&&m(e)}e()}},[c,Se.autoGenerateCommitMessage,t,ye,f]),(0,X.useEffect)(()=>{if(!u){w.current=!1;return}if(console.log(`[pr-auto-gen] useEffect triggered`,{isPRDialogOpen:u,autoGeneratePRInfo:Se.autoGeneratePRInfo,prTitleEmpty:!h.trim(),prDescriptionEmpty:!v.trim(),threadId:t,hasThreadId:!!t,generationAlreadyStarted:w.current}),u&&Se.autoGeneratePRInfo&&!h.trim()&&!v.trim()&&t&&!w.current){console.log(`[pr-auto-gen] Starting auto-generation...`),w.current=!0;async function e(){let e=await ye.generatePRInfoWithAI();e&&(console.log(`[pr-auto-gen] Setting PR info:`,e.title.substring(0,50)),g(e.title),y(e.description))}e()}else console.log(`[pr-auto-gen] Skipping auto-generation - conditions not met`)},[u,Se.autoGeneratePRInfo,t,ye,h,v]),(0,X.useEffect)(()=>{console.log(`Unified status changed:`,{prExists:G.prExists,prState:G.prState,threadId:t}),G.prExists&&G.prState===`MERGED`&&(console.log(`Merged PR detected, opening dialog`),ce(!0))},[G.prExists,G.prState,t]),(0,X.useEffect)(()=>{!n.isStreaming&&n.completedThreadIds.includes(n.selectedThreadId??``)&&(G.fetchUnifiedStatus(!0),r({type:Y.ClearThreadCompleted,threadId:n.selectedThreadId??``}))},[n.isStreaming,n.completedThreadIds,n.selectedThreadId,G,r]);async function Ee(){if(f.trim()&&Zo(t))try{a(!0),await le(t,f),m(``),l(!1),await G.fetchUnifiedStatus(!0),be(),$({title:`Changes committed successfully`,description:`Your changes have been committed to '${G.currentBranch}'.`}),ie&&(oe(!1),await Ne())}catch(e){console.error(`Failed to commit:`,e),$({title:`Commit failed`,description:e instanceof Error?e.message:`Failed to commit changes`,variant:`destructive`})}finally{a(!1)}}async function De(){if(G.status===`Behind`&&!G.hasChanges&&!G.hasUnpushedCommits){await Re();return}if(G.hasChanges){l(!0);return}if(G.prExists&&G.prState===`OPEN`&&!G.hasChanges&&!G.hasUnpushedCommits){G.prUrl&&await Ke(G.prUrl);return}if(G.commitsAheadOfDefault&&!G.prExists&&!G.hasChanges){d(!0);return}if(G.hasUnpushedCommits&&G.prExists){await je();return}}async function Oe(){let e=await ye.generateCommitMessageWithAI();e&&m(e)}async function Ae(){if(Zo(t))try{a(!0),await O(t),await G.fetchUnifiedStatus()}catch(e){console.error(`Failed to fetch:`,e)}finally{a(!1)}}async function je(){if(Zo(t))try{a(!0),await ke(t),await G.fetchUnifiedStatus(!0),be(),G.hasRemoteBranch?$({title:`Branch pushed successfully`,description:`Your branch '${G.currentBranch}' has been pushed to the remote.`}):$({title:`Push completed`,description:`Changes have been pushed successfully.`})}catch(e){console.error(`Failed to push:`,e),$({title:`Push failed`,description:e instanceof Error?e.message:`Failed to push to remote`,variant:`destructive`})}finally{a(!1)}}async function Me(){if(Zo(t)){if(G.hasChanges){W(!0);return}await Ne()}}async function Ne(){try{a(!0),await ae(t),await G.fetchUnifiedStatus(!0),be(),$({title:`Pull successful`,description:`Latest changes have been pulled from remote.`})}catch(e){console.error(`Failed to pull:`,e),$({title:`Pull failed`,description:e instanceof Error?e.message:`Failed to pull from remote`,variant:`destructive`})}finally{a(!1)}}function Pe(){W(!1),oe(!0),l(!0)}async function Fe(){W(!1),await Ne()}async function Ie(){if(t)try{a(!0);let e=await pe(t,G.defaultBranch??void 0);N();let n=await ut();r({type:Y.SetProjects,projects:n.projects}),$({title:`New branch created`,description:`Created new branch "${e.branchName}" on current thread`}),ce(!1),await G.fetchUnifiedStatus(!0),setTimeout(()=>void G.fetchUnifiedStatus(!0),1500)}catch(e){console.error(`Failed to create new branch:`,e),$({title:`Failed to create new branch`,description:e instanceof Error?e.message:`Unknown error occurred`,variant:`destructive`})}finally{a(!1)}}async function Le(){if(!(!t||!fe.trim()))try{a(!0);let e=await pe(t,G.defaultBranch??void 0,fe.trim());N();let n=await ut();r({type:Y.SetProjects,projects:n.projects}),$({title:`New branch created`,description:`Switched to branch "${e.branchName}"`}),me(``),de(!1),await G.fetchUnifiedStatus(!0),setTimeout(()=>void G.fetchUnifiedStatus(!0),1500)}catch(e){$({title:`Failed to create branch`,description:e instanceof Error?e.message:`Unknown error occurred`,variant:`destructive`})}finally{a(!1)}}async function Re(){if(!Zo(t)){console.log(`[sync] Thread operation validation failed`);return}try{console.log(`[sync] Starting branch sync for thread: ${t}`),console.log(`[sync] Current branch: ${G.currentBranch}, Default branch: ${G.defaultBranch}`),a(!0),console.log(`[sync] Calling gitSyncBranch API...`);let e=await p(t);console.log(`[sync] ✓ gitSyncBranch API call successful`),console.log(`[sync] Result:`,e),console.log(`[sync] Refreshing git status...`),await G.fetchUnifiedStatus(!0),be(),console.log(`[sync] ✓ Git status refreshed`),$({title:`Branch synced successfully`,description:`Your branch '${G.currentBranch}' has been synced with the latest changes`}),console.log(`[sync] ✓ Sync operation completed successfully`)}catch(e){console.error(`[sync] ✗ Failed to sync branch:`,e),$({title:`Sync failed`,description:e instanceof Error?e.message:`Failed to sync with default branch`,variant:`destructive`})}finally{a(!1)}}async function ze(){if(Zo(t))try{a(!0),s(!0);let e=await xe(t,h,v);e.prUrl&&await Ke(e.prUrl),g(``),y(``),d(!1),await G.fetchUnifiedStatus(),be()}catch(e){console.error(`Failed to create PR:`,e);let t=e instanceof Error?e.message:`Failed to create PR`;t.includes(`push the current branch`)||t.includes(`--head flag`)?(d(!1),Ve({title:h,description:v})):$({title:`Create PR Failed`,description:t,variant:`destructive`})}finally{a(!1),s(!1)}}async function Be(){if(Zo(t))try{a(!0);let e=await _(t,V,H,Se.privateRepositoryDefault);e.repoUrl&&setTimeout(()=>{Ke(e.repoUrl)},3e3),ee(``),te(``),B(!1),await G.fetchUnifiedStatus(),be()}catch(e){console.error(`Failed to create repo:`,e)}finally{a(!1)}}async function K(){let e=await ye.generatePRInfoWithAI();e&&(g(e.title),y(e.description))}async function Ve(e){let n=e??S;if(!(!t||!n))try{a(!0),s(!0);try{await ke(t)}catch(e){let n=e?.message??``;if(n.includes(`non-fast-forward`)||n.includes(`Updates were rejected because the tip of your current branch is behind`)){console.log(`[push-and-pr] Non-fast-forward error detected, pulling first...`),$({title:`Syncing branch before push`,description:`Your branch is behind remote. Pulling latest changes first...`});try{await p(t),console.log(`[push-and-pr] ✓ Pull completed, retrying push...`),await ke(t),console.log(`[push-and-pr] ✓ Push succeeded after pull`)}catch(t){throw console.error(`[push-and-pr] Pull failed:`,t),e}}else throw e}let e=await xe(t,n.title,n.description);e.prUrl&&await Ke(e.prUrl),g(``),y(``),C(null),x(!1),await G.fetchUnifiedStatus(),be()}catch(e){console.error(`Failed to push and create PR:`,e),$({title:`Push & Create PR Failed`,description:e instanceof Error?e.message:`Failed to push and create PR`,variant:`destructive`})}finally{a(!1),s(!1)}}async function He(){if(Zo(t))try{M(!0);let e=await ot(t,100);A(e),F(e.slice(0,10)),D(!0)}catch(e){console.error(`Failed to fetch git history:`,e)}finally{M(!1)}}function Ue(){I||(L(!0),setTimeout(()=>{let e=P.length+10;F(k.slice(0,e)),L(!1)},300))}function We(e){let t=e.currentTarget;t.scrollHeight-t.scrollTop-t.clientHeight<100&&P.length<k.length&&!I&&Ue()}let Ge=qo(G);async function qe(){if(!_e){ve(!0);try{ge((await R(t)).branches)}catch{ge([])}finally{ve(!1)}}}async function Je(e){if(e!==G.currentBranch){a(!0);try{await Pt(t,e),await G.fetchUnifiedStatus(!0),$({title:`Switched to branch "${e}"`})}catch(e){$({title:`Failed to switch branch`,description:e instanceof Error?e.message:String(e),variant:`destructive`})}finally{a(!1)}}}function Ye(){me(``),de(!0)}function Xe(){G.repoUrl&&Ke(G.repoUrl)}function Ze(){x(!1),C(null)}function Qe(){ce(!1),G.fetchUnifiedStatus(!0)}return(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-0`,children:[(0,Q.jsx)(Wr,{children:(0,Q.jsxs)(Gr,{children:[(0,Q.jsx)(Kr,{asChild:!0,children:(0,Q.jsxs)(q,{variant:`outline`,size:`sm`,className:`h-8 rounded-r-none border-r-0 gap-1.5 border-transparent${Ge?` bg-brand text-brand-foreground hover:bg-brand/90 hover:text-brand-foreground`:``}`,disabled:Ko(G,i),onClick:De,children:[Wo(G,o),Uo(G,o)]})}),(0,Q.jsx)(Ur,{children:Go(G)})]})}),(0,Q.jsx)(Jo,{branchStatus:G.status,currentBranch:G.currentBranch,remoteUrl:G.remoteUrl,hasRemoteBranch:G.hasRemoteBranch,hasUnpushedCommits:G.hasUnpushedCommits,canCreateRepo:G.canCreateRepo,repoUrl:G.repoUrl,isRefreshing:G.isRefreshing,isBrandState:Ge,gitUser:ne,availableBranches:he,isLoadingBranches:_e,onBranchSubMenuOpen:qe,onCheckoutBranch:Je,isDirectCommitMode:Te,isLoading:i,isLoadingHistory:j,onFetch:()=>void Ae(),onPull:()=>void Me(),onPush:()=>void je(),onOpenHistory:()=>void He(),onNewBranch:Ye,onCreatePR:()=>d(!0),onCreateRepo:()=>B(!0),onViewInGitHub:Xe})]}),(0,Q.jsx)(Qo,{open:c,onOpenChange:l,commitMessage:f,onCommitMessageChange:m,autoGenerateCommitMessage:Se.autoGenerateCommitMessage,onAutoGenerateChange:e=>Ce(t=>({...t,autoGenerateCommitMessage:e})),isGeneratingMessage:ye.isGeneratingMessage,isLoading:i,onGenerateMessage:Oe,onCommit:Ee,currentBranch:G.currentBranch}),(0,Q.jsx)($o,{open:u,onOpenChange:d,prTitle:h,onPrTitleChange:g,prDescription:v,onPrDescriptionChange:y,isGeneratingPRInfo:ye.isGeneratingPRInfo,isLoading:i,onGeneratePRInfo:K,onCreatePR:ze,currentBranch:G.currentBranch,autoGeneratePRInfo:Se.autoGeneratePRInfo,onAutoGeneratePRInfoChange:e=>Ce(t=>({...t,autoGeneratePRInfo:e}))}),(0,Q.jsx)(rs,{open:b,onOpenChange:x,isLoading:i,onPushAndCreatePR:Ve,onCancel:Ze}),(0,Q.jsx)(es,{open:z,onOpenChange:B,repoName:V,onRepoNameChange:ee,repoDescription:H,onRepoDescriptionChange:te,isPrivateRepo:Se.privateRepositoryDefault,onPrivateRepoChange:e=>Ce(t=>({...t,privateRepositoryDefault:e})),isLoading:i,onCreateRepo:Be}),(0,Q.jsx)(ts,{open:E,onOpenChange:D,commits:k,displayedCommits:P,isLoadingMore:I,onScroll:We,currentBranch:G.currentBranch}),(0,Q.jsx)(is,{open:U,onOpenChange:W,onCommitFirst:Pe,onStashAndPull:Fe,onCancel:()=>W(!1),isLoading:i}),(0,Q.jsx)(as,{open:se,onOpenChange:ce,onNewBranch:Ie,onJustOpen:Qe,isLoading:i,defaultBranch:G.defaultBranch??void 0}),(0,Q.jsx)(os,{open:ue,onOpenChange:de,branchName:fe,onBranchNameChange:me,isLoading:i,onCreateBranch:Le})]})}var fs=`Play.Square.RotateCcw.Terminal.Bug.TestTube.FlaskConical.Wrench.Hammer.Zap.Search.FileCode.Code2.History.Settings.Activity.Cpu.Server.Database.Package.Box.GitBranch.Layers.ExternalLink.Eye.Shield.Flag.Star.Monitor.Smartphone`.split(`.`);function ps({open:e,onOpenChange:t,projectId:n,commands:r,onRefresh:i}){let[a,o]=(0,X.useState)(null),[c,l]=(0,X.useState)(!1),[f,p]=(0,X.useState)(!1),[m,h]=(0,X.useState)([]),[g,_]=(0,X.useState)(0),[v,y]=(0,X.useState)(!1),b=(0,X.useRef)(null),x=(0,X.useRef)(null),S=()=>{o({id:crypto.randomUUID(),name:``,icon:`Play`,commandLine:``}),p(!1),h([])},C=e=>{o({...e}),p(!1),h([])},T=async()=>{try{y(!0);let e=await gt(n);h(e.scripts),_(0),p(e.scripts.length>0)}catch(e){console.error(`Failed to load package scripts:`,e),$({title:`Error`,description:`Failed to load package scripts`,variant:`destructive`})}finally{y(!1)}},E=e=>{o(t=>t?{...t,name:e.name,commandLine:e.commandLine,relativeFolder:e.relativePath||``}:null),p(!1),h([]),b.current?.focus()},O=e=>{f&&(e.key===`ArrowDown`?(e.preventDefault(),_(e=>e<m.length-1?e+1:e)):e.key===`ArrowUp`?(e.preventDefault(),_(e=>e>0?e-1:0)):e.key===`Enter`?(e.preventDefault(),g<m.length&&E(m[g])):e.key===`Escape`&&(e.preventDefault(),p(!1),h([])))};(0,X.useEffect)(()=>{let e=e=>{x.current&&!x.current.contains(e.target)&&(p(!1),h([]))};return f&&document.addEventListener(`mousedown`,e),()=>{document.removeEventListener(`mousedown`,e)}},[f]);let k=async e=>{try{await ve(n,e),$({title:`Success`,description:`Command deleted`}),i()}catch{$({title:`Error`,description:`Failed to delete command`,variant:`destructive`})}};return(0,Q.jsx)(D,{open:e,onOpenChange:t,children:(0,Q.jsxs)(I,{className:`sm:max-w-[500px]`,children:[(0,Q.jsxs)(jn,{children:[(0,Q.jsx)(d,{children:`Project Commands`}),(0,Q.jsx)(W,{children:`Manage custom commands for this project.`})]}),(0,Q.jsx)(`div`,{className:`py-4 flex flex-col gap-4`,children:a?(0,Q.jsxs)(`div`,{className:`p-4 border rounded-lg bg-muted/30 flex flex-col gap-4 animate-in slide-in-from-top-2`,children:[(0,Q.jsxs)(`div`,{className:`grid gap-2`,children:[(0,Q.jsx)(J,{htmlFor:`name`,children:`Command Name`}),(0,Q.jsx)(s,{id:`name`,value:a.name,onChange:e=>o({...a,name:e.target.value}),placeholder:`e.g. Run Tests`,autoComplete:`off`})]}),(0,Q.jsxs)(`div`,{className:`grid gap-2 relative`,children:[(0,Q.jsx)(J,{htmlFor:`commandLine`,children:`Command Line`}),(0,Q.jsxs)(`div`,{className:`relative`,children:[(0,Q.jsx)(Hr,{ref:b,id:`commandLine`,value:a.commandLine,onChange:e=>o({...a,commandLine:e.target.value}),onKeyDown:O,placeholder:`e.g. npm test`,className:`font-mono text-xs min-h-[100px] resize-none pr-10`}),(0,Q.jsx)(Wr,{children:(0,Q.jsxs)(Gr,{children:[(0,Q.jsx)(Kr,{asChild:!0,children:(0,Q.jsx)(q,{type:`button`,variant:`ghost`,size:`icon`,className:`absolute right-2 top-2 h-6 w-6 text-muted-foreground transition-colors`,onClick:()=>void T(),disabled:v,children:(0,Q.jsx)(H,{className:`h-4 w-4`})})}),(0,Q.jsx)(Ur,{children:(0,Q.jsx)(`p`,{children:`Discover package scripts`})})]})})]}),f&&(0,Q.jsx)(`div`,{ref:x,className:`absolute bottom-full left-0 right-0 mb-2 max-h-60 overflow-y-auto rounded-lg border border-border bg-popover shadow-lg z-50`,children:(0,Q.jsxs)(`div`,{className:`p-2`,children:[(0,Q.jsxs)(`div`,{className:`px-2 py-1.5 text-xs font-semibold text-muted-foreground border-b border-border/50 mb-1 flex items-center gap-2`,children:[(0,Q.jsx)(H,{className:`h-3 w-3`}),`Available Scripts `,v&&`(loading...)`]}),m.length>0?(()=>{let e={};m.forEach(t=>{e[t.relativePath]||(e[t.relativePath]=[]),e[t.relativePath].push(t)});let t=Object.keys(e).sort(),n=0;return t.map(t=>{let r=e[t].sort((e,t)=>e.name.localeCompare(t.name));return(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`div`,{className:`px-3 py-1.5 text-xs font-semibold text-muted-foreground/70 bg-muted/30`,children:t}),r.map(e=>{let t=n===g;return n++,(0,Q.jsxs)(`button`,{type:`button`,className:K(`flex w-full flex-col gap-1 rounded-lg mx-1 px-3 py-2 text-left transition-colors`,t?`bg-accent text-accent-foreground`:`text-popover-foreground hover:bg-accent/50`),onClick:()=>E(e),onMouseEnter:()=>_(n-1),children:[(0,Q.jsx)(`span`,{className:`font-medium`,children:e.name}),(0,Q.jsx)(`span`,{className:`text-xs text-muted-foreground font-mono`,children:e.commandLine})]},e.commandLine)})]},t)})})():(0,Q.jsx)(`div`,{className:`px-3 py-4 text-center text-xs text-muted-foreground`,children:v?`Loading scripts...`:`No package scripts found`})]})})]}),(0,Q.jsxs)(`div`,{className:`grid gap-2`,children:[(0,Q.jsx)(J,{htmlFor:`relativeFolder`,children:`Relative Folder`}),(0,Q.jsx)(s,{id:`relativeFolder`,value:a.relativeFolder??``,onChange:e=>o({...a,relativeFolder:e.target.value}),placeholder:`e.g. frontend, packages/api (optional)`,autoComplete:`off`}),(0,Q.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Folder path relative to project root where the command will be executed. Leave empty to run from project root.`})]}),(0,Q.jsxs)(`div`,{className:`grid gap-2`,children:[(0,Q.jsx)(J,{children:`Icon`}),(0,Q.jsx)(`div`,{className:`grid grid-cols-10 gap-1 p-2 bg-background rounded-md border border-border`,children:fs.map(e=>{let t=xn[e]||u;return(0,Q.jsx)(q,{variant:a.icon===e?`default`:`ghost`,size:`icon`,className:`h-8 w-8`,onClick:()=>o({...a,icon:e}),title:e,children:(0,Q.jsx)(t,{className:`h-4 w-4`})},e)})})]}),(0,Q.jsxs)(`div`,{className:`flex justify-end gap-2 mt-2`,children:[(0,Q.jsxs)(q,{variant:`ghost`,size:`sm`,onClick:()=>o(null),children:[(0,Q.jsx)(w,{className:`h-4 w-4 mr-2`}),` Cancel`]}),(0,Q.jsxs)(q,{size:`sm`,onClick:async()=>{if(!a?.name||!a?.commandLine){$({title:`Error`,description:`Name and Command Line are required`,variant:`destructive`});return}try{l(!0),await we(n,a),$({title:`Success`,description:`Command saved`}),o(null),i()}catch{$({title:`Error`,description:`Failed to save command`,variant:`destructive`})}finally{l(!1)}},disabled:c,children:[(0,Q.jsx)(tn,{className:`h-4 w-4 mr-2`}),` `,c?`Saving...`:`Save Command`]})]})]}):(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(`div`,{className:`flex flex-col gap-2 max-h-[400px] overflow-y-auto pr-2`,children:[r.length===0&&(0,Q.jsx)(`div`,{className:`text-center py-8 text-muted-foreground border-2 border-dashed rounded-lg`,children:`No commands defined yet.`}),r.map(e=>(0,Q.jsxs)(`div`,{className:`flex items-center justify-between p-3 rounded-md border border-border bg-card hover:bg-muted/50 cursor-pointer group transition-colors`,onClick:()=>C(e),children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,Q.jsx)(`div`,{className:`p-2 bg-muted rounded`,children:(0,Q.jsx)(xn[e.icon]||nn,{className:`h-4 w-4`})}),(0,Q.jsxs)(`div`,{className:`flex flex-col`,children:[(0,Q.jsx)(`span`,{className:`text-sm font-medium`,children:e.name}),(0,Q.jsx)(`span`,{className:`text-xs text-muted-foreground line-clamp-1 font-mono`,children:e.commandLine})]})]}),(0,Q.jsx)(`div`,{className:`flex items-center gap-1 opacity-0 group-hover:opacity-100 transition-opacity`,children:(0,Q.jsx)(q,{variant:`ghost`,size:`icon`,className:`h-8 w-8 text-muted-foreground hover:bg-destructive hover:text-destructive-foreground transition-colors`,onClick:t=>{t.stopPropagation(),k(e.id)},children:(0,Q.jsx)(ce,{className:`h-4 w-4`})})})]},e.id))]}),(0,Q.jsxs)(q,{variant:`outline`,className:`w-full border-dashed`,onClick:S,children:[(0,Q.jsx)(te,{className:`h-4 w-4 mr-2`}),` Add New Command`]})]})})]})})}function ms(){let e=(0,Z.c)(27),{state:t}=Ar(),{selectedProjectId:n,selectedThreadId:r,projects:i}=t,{dispatch:a}=Lr(r),[o,s]=(0,X.useState)(!1),c,l,u,d,p;if(e[0]!==a||e[1]!==i||e[2]!==n||e[3]!==r||e[4]!==t.isRunningCommand){p=Symbol.for(`react.early_return_sentinel`);bb0:{let o;e[10]===n?o=e[11]:(o=e=>e.projectId===n,e[10]=n,e[11]=o),c=i.find(o)?.commands??[];let m;e[12]!==a||e[13]!==n||e[14]!==r?(m=e=>{!n||!r||a({type:Y.QueueTerminalCommand,threadId:r,command:e.commandLine,relativeFolder:e.relativeFolder})},e[12]=a,e[13]=n,e[14]=r,e[15]=m):m=e[15];let h=m,g;if(e[16]===a?g=e[17]:(g=async()=>{a({type:Y.ConfigUpdated})},e[16]=a,e[17]=g),l=g,!n){p=null;break bb0}u=`flex items-center gap-1`,d=c.length===0?(0,Q.jsx)(Wr,{children:(0,Q.jsxs)(Gr,{children:[(0,Q.jsx)(Kr,{asChild:!0,children:(0,Q.jsx)(q,{variant:`action`,size:`icon-md`,onClick:()=>s(!0),children:(0,Q.jsx)(f,{})})}),(0,Q.jsx)(Ur,{children:`Manage commands`})]})}):(0,Q.jsx)(Q.Fragment,{children:(0,Q.jsxs)(Wr,{children:[c.map(e=>{let n=xn[e.icon]||nn;return(0,Q.jsxs)(Gr,{children:[(0,Q.jsx)(Kr,{asChild:!0,children:(0,Q.jsx)(q,{variant:`action`,size:`icon-md`,onClick:()=>h({commandLine:e.commandLine,relativeFolder:e.relativeFolder}),disabled:t.isRunningCommand,children:(0,Q.jsx)(n,{})})}),(0,Q.jsx)(Ur,{children:(0,Q.jsxs)(`div`,{className:`flex flex-col gap-0.5`,children:[(0,Q.jsx)(`span`,{className:`font-medium`,children:e.name}),(0,Q.jsx)(`span`,{className:`text-[10px] opacity-70 font-mono whitespace-pre-wrap max-w-[300px] max-h-[100px] overflow-y-auto`,children:e.commandLine})]})})]},e.id)}),(0,Q.jsxs)(Gr,{children:[(0,Q.jsx)(Kr,{asChild:!0,children:(0,Q.jsx)(q,{variant:`action`,size:`icon-md`,className:`ml-1`,onClick:()=>s(!0),children:(0,Q.jsx)(f,{})})}),(0,Q.jsx)(Ur,{children:`Manage commands`})]})]})})}e[0]=a,e[1]=i,e[2]=n,e[3]=r,e[4]=t.isRunningCommand,e[5]=c,e[6]=l,e[7]=u,e[8]=d,e[9]=p}else c=e[5],l=e[6],u=e[7],d=e[8],p=e[9];if(p!==Symbol.for(`react.early_return_sentinel`))return p;let m;e[18]!==c||e[19]!==l||e[20]!==n||e[21]!==o?(m=(0,Q.jsx)(ps,{open:o,onOpenChange:s,projectId:n,commands:c,onRefresh:l}),e[18]=c,e[19]=l,e[20]=n,e[21]=o,e[22]=m):m=e[22];let h;return e[23]!==u||e[24]!==d||e[25]!==m?(h=(0,Q.jsxs)(`div`,{className:u,children:[d,m]}),e[23]=u,e[24]=d,e[25]=m,e[26]=h):h=e[26],h}var hs=(0,X.createContext)({activeMainTab:`chat`,setActiveMainTab:()=>{},devServerUrl:null,setDevServerUrl:()=>{},terminalNotification:!1,setTerminalNotification:()=>{},pendingExplorerPath:null,setPendingExplorerPath:()=>{},explorerRefreshTick:0,triggerExplorerRefresh:()=>{},explorerClearPath:null,setExplorerClearPath:()=>{}});function gs(){return(0,X.useContext)(hs)}function _s({projectId:e,runCommand:t}){let{state:n}=Ar(),{selectedThreadId:r}=n,{dispatch:i}=Lr(r),{setActiveMainTab:a,setDevServerUrl:o}=gs(),[s,c]=(0,X.useState)(!1),[l,u]=(0,X.useState)(!1);(0,X.useEffect)(()=>{(async()=>{try{c((await ze(e)).isRunning)}catch{c(!1)}})()},[e]);let d=async()=>{if(!t)return;u(!0),i({type:Y.ClearTerminalOutput}),i({type:Y.SetTerminalOpen,open:!1}),i({type:Y.AppendTerminalLine,line:{type:`system`,content:`Starting dev server: ${t}`}});let n=!1,s=setTimeout(()=>{n=!0,i({type:Y.SetTerminalOpen,open:!0})},3e3);try{console.log(`Starting dev server for project:`,e,`thread:`,r);let t=await at(e,r??void 0);if(!t){clearTimeout(s),$({title:`Error`,description:`Failed to start dev server`,variant:`destructive`}),i({type:Y.AppendTerminalLine,line:{type:`error`,content:`Failed to start dev server`}}),u(!1);return}let l=t.getReader(),d=new TextDecoder;c(!0);let f=!1,p=!1,m=null;for(m=setTimeout(()=>{p||u(!1)},3e3);;){let{done:e,value:t}=await l.read();if(e)break;let r=d.decode(t,{stream:!0});try{let e=r.split(`
|
|
13
|
+
`).filter(e=>e.trim());for(let t of e)try{let e=JSON.parse(t);p||(p=!0,u(!1),m&&clearTimeout(m)),(e.type===`stdout`||e.type===`stderr`)&&i({type:Y.AppendTerminalLine,line:{type:`output`,content:e.content}}),e.type===`url`&&e.url&&(clearTimeout(s),i({type:Y.AppendTerminalLine,line:{type:`system`,content:`✓ Server running at: ${e.url}`}}),o(e.url),a(`browser`),n&&setTimeout(()=>{i({type:Y.SetTerminalOpen,open:!1})},100),$({title:`Dev server started`,description:`Server running at ${e.url}`}),f=!0),e.type===`error`&&e.content&&i({type:Y.AppendTerminalLine,line:{type:`error`,content:e.content}})}catch{r.trim()&&i({type:Y.AppendTerminalLine,line:{type:`output`,content:r}})}}catch{r.trim()&&i({type:Y.AppendTerminalLine,line:{type:`output`,content:r}})}}clearTimeout(s),m&&clearTimeout(m),u(!1),f||(i({type:Y.AppendTerminalLine,line:{type:`system`,content:`Server is running but URL could not be detected`}}),$({title:`Dev server started`,description:`Server is running but URL could not be detected`}))}catch(e){clearTimeout(s),c(!1),u(!1);let t=e instanceof Error?e.message:`Failed to start dev server`;i({type:Y.AppendTerminalLine,line:{type:`error`,content:t}}),$({title:`Error`,description:t,variant:`destructive`})}},f=async()=>{u(!0);try{await cn(e),c(!1),i({type:Y.AppendTerminalLine,line:{type:`system`,content:`Server stopped`}})}catch(e){let t=e instanceof Error?e.message:`Failed to stop dev server`;i({type:Y.AppendTerminalLine,line:{type:`error`,content:t}}),$({title:`Error`,description:t,variant:`destructive`})}finally{u(!1)}},p=!!t;return(0,Q.jsx)(Q.Fragment,{children:(0,Q.jsx)(Wr,{children:(0,Q.jsxs)(Gr,{children:[(0,Q.jsx)(Kr,{asChild:!0,children:(0,Q.jsxs)(q,{variant:`ghost`,size:`icon`,className:`h-8 w-8 ${s?`text-orange-500 bg-orange-500/10`:`text-muted-foreground`}`,onClick:s?f:d,disabled:l||!s&&!p,children:[l?(0,Q.jsx)(Rt,{className:`h-4 w-4 animate-spin`}):s?(0,Q.jsx)(L,{className:`h-4 w-4 fill-current`}):(0,Q.jsx)(nn,{className:`h-4 w-4`}),(0,Q.jsx)(`span`,{className:`sr-only`,children:s?`Stop dev server`:`Start dev server`})]})}),(0,Q.jsx)(Ur,{children:s?`Stop dev server`:p?`Start dev server: ${t}`:`Set run command in project settings`})]})})})}function vs(e){let t=(0,Z.c)(3),{children:n,className:r}=e,i=`flex items-center gap-2 rounded-full shadow-md ${r===void 0?``:r}`,a;return t[0]!==n||t[1]!==i?(a=(0,Q.jsx)(`div`,{className:i,children:n}),t[0]=n,t[1]=i,t[2]=a):a=t[2],a}function ys({threadId:e}){let{dispatch:t}=Ar(),{setTerminalNotification:n}=gs(),[r,i]=(0,X.useState)(null),[a,o]=(0,X.useState)(new Set),s=(0,X.useRef)(new Map);(0,X.useEffect)(()=>((async()=>{try{let t=await On(e);if(t.length===0){i(null);return}i(t),o(new Set(t.filter(e=>e.isRunning).map(e=>e.name)))}catch{i(null)}})(),()=>{for(let e of s.current.values())e.abort();s.current.clear()}),[e]);let c=async r=>{if(a.has(r.name)){let n=s.current.get(r.name);n&&(n.abort(),s.current.delete(r.name));try{await ft(e,r.name)}catch{}t({type:Y.AppendTerminalLine,threadId:e,line:{type:`system`,content:`■ ${r.friendlyName} stopped`}}),o(e=>{let t=new Set(e);return t.delete(r.name),t})}else{let i=new AbortController;s.current.set(r.name,i),o(e=>new Set([...e,r.name])),n(!0),t({type:Y.AppendTerminalLine,threadId:e,line:{type:`system`,content:`▶ ${r.friendlyName}`}});try{let n=await $e(e,r.name,r.command,{signal:i.signal});if(n){let r=n.getReader(),i=new TextDecoder,a=``;try{for(;;){let{done:n,value:o}=await r.read();if(n)break;a+=i.decode(o,{stream:!0});let s=a.split(`
|
|
14
|
+
`);a=s.pop()??``;for(let n of s)if(n.trim())try{let r=JSON.parse(n);typeof r==`string`?t({type:Y.AppendTerminalLine,threadId:e,line:{type:`output`,content:r}}):r.type===`error`&&t({type:Y.AppendTerminalLine,threadId:e,line:{type:`error`,content:r.message}})}catch{t({type:Y.AppendTerminalLine,threadId:e,line:{type:`output`,content:n}})}}if(a.trim())try{let n=JSON.parse(a);typeof n==`string`?t({type:Y.AppendTerminalLine,threadId:e,line:{type:`output`,content:n}}):n.type===`error`&&t({type:Y.AppendTerminalLine,threadId:e,line:{type:`error`,content:n.message}})}catch{t({type:Y.AppendTerminalLine,threadId:e,line:{type:`output`,content:a}})}}finally{r.releaseLock()}}t({type:Y.AppendTerminalLine,threadId:e,line:{type:`system`,content:`✓ ${r.friendlyName} done`}})}catch{}finally{s.current.delete(r.name),o(e=>{let t=new Set(e);return t.delete(r.name),t})}}};if(!r)return null;let l=r.reduce((e,t)=>(e[t.workspace]||(e[t.workspace]=[]),e[t.workspace].push(t),e),{}),u=Object.entries(l).sort(([e],[t])=>e.localeCompare(t)).map(([e,t])=>[e,[...t].sort((e,t)=>e.friendlyName.localeCompare(t.friendlyName))]),d=u.length>1;return(0,Q.jsxs)(Oo,{children:[(0,Q.jsx)(Wr,{children:(0,Q.jsxs)(Gr,{children:[(0,Q.jsx)(Kr,{asChild:!0,children:(0,Q.jsx)(ko,{asChild:!0,children:(0,Q.jsx)(q,{variant:`action`,size:`icon-md`,children:(0,Q.jsx)(Ge,{})})})}),(0,Q.jsx)(Ur,{children:`Project Scripts`})]})}),(0,Q.jsx)(No,{align:`end`,className:`min-w-[180px]`,children:d?u.map(([e,t])=>(0,Q.jsxs)(Ao,{children:[(0,Q.jsx)(jo,{children:e}),(0,Q.jsx)(Mo,{className:`max-h-[min(400px,80vh)] overflow-y-auto`,children:t.map(e=>(0,Q.jsxs)(Po,{onClick:()=>{c(e)},className:`gap-2`,children:[a.has(e.name)?(0,Q.jsx)(Rt,{className:`h-3 w-3 animate-spin shrink-0`}):(0,Q.jsx)(`div`,{className:`h-3 w-3 shrink-0`}),e.friendlyName]},e.name))})]},e)):u[0]?.[1].map(e=>(0,Q.jsxs)(Po,{onClick:()=>{c(e)},className:`gap-2`,children:[a.has(e.name)?(0,Q.jsx)(Rt,{className:`h-3 w-3 animate-spin shrink-0`}):(0,Q.jsx)(`div`,{className:`h-3 w-3 shrink-0`}),e.friendlyName]},e.name))})]})}var bs=X.forwardRef((e,t)=>{let n=(0,Z.c)(9),r,i;n[0]===e?(r=n[1],i=n[2]):({className:r,...i}=e,n[0]=e,n[1]=r,n[2]=i);let a;n[3]===r?a=n[4]:(a=K(`grid gap-2`,r),n[3]=r,n[4]=a);let o;return n[5]!==i||n[6]!==t||n[7]!==a?(o=(0,Q.jsx)(Hn,{className:a,...i,ref:t}),n[5]=i,n[6]=t,n[7]=a,n[8]=o):o=n[8],o});bs.displayName=Hn.displayName;var xs=X.forwardRef((e,t)=>{let n=(0,Z.c)(10),r,i;n[0]===e?(r=n[1],i=n[2]):({className:r,...i}=e,n[0]=e,n[1]=r,n[2]=i);let a;n[3]===r?a=n[4]:(a=K(`aspect-square h-4 w-4 rounded-full border border-brand text-brand ring-offset-background focus:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50`,r),n[3]=r,n[4]=a);let o;n[5]===Symbol.for(`react.memo_cache_sentinel`)?(o=(0,Q.jsx)(Yn,{className:`flex items-center justify-center`,children:(0,Q.jsx)(An,{className:`h-2.5 w-2.5 fill-current text-current`})}),n[5]=o):o=n[5];let s;return n[6]!==i||n[7]!==t||n[8]!==a?(s=(0,Q.jsx)(zn,{ref:t,className:a,...i,children:o}),n[6]=i,n[7]=t,n[8]=a,n[9]=s):s=n[9],s});xs.displayName=zn.displayName;function Ss({threadId:e,onSkillCreated:t}){let[n,r]=(0,X.useState)(``),[i,a]=(0,X.useState)(``),[o,c]=(0,X.useState)(`local`),[l,u]=(0,X.useState)(!1),d=n.toLowerCase().replace(/\s+/g,`-`).replace(/[^a-z0-9-]/g,``).replace(/-+/g,`-`).replace(/^-|-$/g,``),f=d.length>0&&d.length<=64;return e?(0,Q.jsxs)(`div`,{className:`max-w-2xl mx-auto p-6`,children:[(0,Q.jsxs)(`div`,{className:`mb-6`,children:[(0,Q.jsx)(`h1`,{className:`text-2xl font-bold`,children:`Add Skill`}),(0,Q.jsx)(`p`,{className:`text-muted-foreground`,children:`Create a new agent skill. The skill will be saved as a SKILL.md file in the .agents/skills folder.`})]}),(0,Q.jsxs)(`div`,{className:`space-y-6`,children:[(0,Q.jsxs)(`div`,{className:`space-y-2`,children:[(0,Q.jsx)(J,{htmlFor:`skillName`,children:`Skill Name`}),(0,Q.jsx)(s,{id:`skillName`,value:n,onChange:e=>r(e.target.value),placeholder:`e.g. Code Review`,disabled:l}),n&&(0,Q.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`Folder name: `,(0,Q.jsx)(`span`,{className:`font-mono`,children:d||`...`})]})]}),(0,Q.jsxs)(`div`,{className:`space-y-2`,children:[(0,Q.jsx)(J,{htmlFor:`skillDescription`,children:`Description`}),(0,Q.jsx)(Hr,{id:`skillDescription`,value:i,onChange:e=>a(e.target.value),placeholder:`Describe when Tarsk should apply this skill`,className:`resize-none min-h-[120px]`,disabled:l})]}),(0,Q.jsxs)(`div`,{className:`space-y-2`,children:[(0,Q.jsx)(J,{children:`Scope`}),(0,Q.jsxs)(bs,{value:o,onValueChange:e=>c(e),className:`flex gap-4`,disabled:l,children:[(0,Q.jsxs)(`div`,{className:`flex items-center space-x-2`,children:[(0,Q.jsx)(xs,{value:`local`,id:`scope-local`}),(0,Q.jsx)(J,{htmlFor:`scope-local`,className:`font-normal cursor-pointer`,children:`Local (this project)`})]}),(0,Q.jsxs)(`div`,{className:`flex items-center space-x-2`,children:[(0,Q.jsx)(xs,{value:`global`,id:`scope-global`,disabled:!0}),(0,Q.jsx)(J,{htmlFor:`scope-global`,className:`font-normal cursor-pointer text-muted-foreground`,children:`Global (coming soon)`})]})]}),(0,Q.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:o===`local`?`This skill will only be available for this project.`:`This skill will be available across all projects (coming soon).`})]}),(0,Q.jsx)(`div`,{className:`border-t pt-4 flex justify-end`,children:(0,Q.jsx)(q,{onClick:async()=>{if(!(!f||!i.trim()||!e)){u(!0);try{let n=await ue(e,d,i.trim());$({title:`Skill created`,description:`Skill '${d}' was created successfully.`}),r(``),a(``),c(`local`),t?.(n.path,`SKILL.md`)}catch(e){$({title:`Error`,description:e instanceof Error?e.message:`Failed to create skill`,variant:`destructive`})}finally{u(!1)}}},disabled:!f||!i.trim()||l,children:l?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(Rt,{className:`mr-2 h-4 w-4 animate-spin`}),`Creating...`]}):(0,Q.jsxs)(Q.Fragment,{children:[`Continue`,(0,Q.jsx)(Ue,{className:`ml-2 h-4 w-4`})]})})})]})]}):(0,Q.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,Q.jsxs)(`div`,{className:`text-center`,children:[(0,Q.jsx)(`h2`,{className:`text-lg font-semibold text-muted-foreground mb-2`,children:`No Thread Selected`}),(0,Q.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Please select a thread to add a skill.`})]})})}var Cs=X.forwardRef((e,t)=>{let n=(0,Z.c)(10),r,i;n[0]===e?(r=n[1],i=n[2]):({className:r,...i}=e,n[0]=e,n[1]=r,n[2]=i);let a;n[3]===r?a=n[4]:(a=K(`peer inline-flex h-6 w-11 shrink-0 cursor-pointer items-center rounded-full border-2 border-transparent transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=unchecked]:bg-input`,r),n[3]=r,n[4]=a);let o;n[5]===Symbol.for(`react.memo_cache_sentinel`)?(o=(0,Q.jsx)(qn,{className:K(`pointer-events-none block h-5 w-5 rounded-full bg-background shadow-lg ring-0 transition-transform data-[state=checked]:translate-x-5 data-[state=unchecked]:translate-x-0`)}),n[5]=o):o=n[5];let s;return n[6]!==i||n[7]!==t||n[8]!==a?(s=(0,Q.jsx)(Kn,{className:a,...i,ref:t,children:o}),n[6]=i,n[7]=t,n[8]=a,n[9]=s):s=n[9],s});Cs.displayName=Kn.displayName;function ws({threadId:e,onRuleCreated:t}){let[n,r]=(0,X.useState)(``),[i,a]=(0,X.useState)(``),[o,c]=(0,X.useState)(!1),[l,u]=(0,X.useState)(`local`),[d,f]=(0,X.useState)(!1),p=n.toLowerCase().replace(/\s+/g,`-`).replace(/[^a-z0-9-]/g,``).replace(/-+/g,`-`).replace(/^-|-$/g,``),m=p.length>0&&p.length<=64;return e?(0,Q.jsxs)(`div`,{className:`max-w-2xl mx-auto p-6`,children:[(0,Q.jsxs)(`div`,{className:`mb-6`,children:[(0,Q.jsx)(`h1`,{className:`text-2xl font-bold`,children:`Add Rule`}),(0,Q.jsx)(`p`,{className:`text-muted-foreground`,children:`Create a new agent rule. The rule will be saved as a .md file in the .agents/rules folder.`})]}),(0,Q.jsxs)(`div`,{className:`space-y-6`,children:[(0,Q.jsxs)(`div`,{className:`space-y-2`,children:[(0,Q.jsx)(J,{htmlFor:`ruleName`,children:`Rule Name`}),(0,Q.jsx)(s,{id:`ruleName`,value:n,onChange:e=>r(e.target.value),placeholder:`e.g. Code Style Guide`,disabled:d}),n&&(0,Q.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`File name: `,(0,Q.jsxs)(`span`,{className:`font-mono`,children:[p||`...`,`.md`]})]})]}),(0,Q.jsxs)(`div`,{className:`space-y-2`,children:[(0,Q.jsx)(J,{htmlFor:`ruleDescription`,children:`Description`}),(0,Q.jsx)(Hr,{id:`ruleDescription`,value:i,onChange:e=>a(e.target.value),placeholder:`Describe when Tarsk should apply this rule...`,className:`resize-none min-h-[120px]`,disabled:d})]}),(0,Q.jsxs)(`div`,{className:`space-y-2`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Q.jsx)(J,{htmlFor:`alwaysApply`,children:`Always Apply`}),(0,Q.jsx)(Cs,{id:`alwaysApply`,checked:o,onCheckedChange:c,disabled:d})]}),(0,Q.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:o?`This rule will be automatically added to context for all conversations.`:`Only the rule description will be added to context, allowing the agent to read the rule file when needed.`})]}),(0,Q.jsxs)(`div`,{className:`space-y-2`,children:[(0,Q.jsx)(J,{children:`Scope`}),(0,Q.jsxs)(bs,{value:l,onValueChange:e=>u(e),className:`flex gap-4`,disabled:d,children:[(0,Q.jsxs)(`div`,{className:`flex items-center space-x-2`,children:[(0,Q.jsx)(xs,{value:`local`,id:`scope-local`}),(0,Q.jsx)(J,{htmlFor:`scope-local`,className:`font-normal cursor-pointer`,children:`Local (this project)`})]}),(0,Q.jsxs)(`div`,{className:`flex items-center space-x-2`,children:[(0,Q.jsx)(xs,{value:`global`,id:`scope-global`,disabled:!0}),(0,Q.jsx)(J,{htmlFor:`scope-global`,className:`font-normal cursor-pointer text-muted-foreground`,children:`Global (coming soon)`})]})]}),(0,Q.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:l===`local`?`This rule will only be available for this project.`:`This rule will be available across all projects (coming soon).`})]}),(0,Q.jsx)(`div`,{className:`border-t pt-4 flex justify-end`,children:(0,Q.jsx)(q,{onClick:async()=>{if(!(!m||!e)){f(!0);try{let n=`---
|
|
15
|
+
description: ${i.trim()}
|
|
16
|
+
alwaysApply: ${o}
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
Place your rule instructions here as markdown.
|
|
20
|
+
`;await Kt(e,`.agents/rules/${p}.md`,n),$({title:`Rule created`,description:`Rule '${p}' was created successfully.`}),r(``),a(``),c(!1),u(`local`),t?.(p)}catch(e){$({title:`Error`,description:e instanceof Error?e.message:`Failed to create rule`,variant:`destructive`})}finally{f(!1)}}},disabled:!m||!i.trim()||d,children:d?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(Rt,{className:`mr-2 h-4 w-4 animate-spin`}),`Creating...`]}):(0,Q.jsxs)(Q.Fragment,{children:[`Continue`,(0,Q.jsx)(Ue,{className:`ml-2 h-4 w-4`})]})})})]})]}):(0,Q.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,Q.jsxs)(`div`,{className:`text-center`,children:[(0,Q.jsx)(`h2`,{className:`text-lg font-semibold text-muted-foreground mb-2`,children:`No Thread Selected`}),(0,Q.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Please select a thread to add a rule.`})]})})}function Ts({threadId:e,onAgentCreated:t}){let[n,r]=(0,X.useState)(``),[i,a]=(0,X.useState)(``),[o,c]=(0,X.useState)(``),[l,u]=(0,X.useState)(`local`),[d,f]=(0,X.useState)(!1),p=n.toLowerCase().replace(/\s+/g,`-`).replace(/[^a-z0-9-]/g,``).replace(/-+/g,`-`).replace(/^-|-$/g,``),m=p.length>0&&p.length<=64;return e?(0,Q.jsxs)(`div`,{className:`max-w-2xl mx-auto p-6`,children:[(0,Q.jsxs)(`div`,{className:`mb-6`,children:[(0,Q.jsx)(`h1`,{className:`text-2xl font-bold`,children:`Add Agent`}),(0,Q.jsx)(`p`,{className:`text-muted-foreground`,children:`Create a new subagent. The agent will be saved as an AGENT.md file in the .agents/agents folder.`})]}),(0,Q.jsxs)(`div`,{className:`space-y-6`,children:[(0,Q.jsxs)(`div`,{className:`space-y-2`,children:[(0,Q.jsx)(J,{htmlFor:`agentName`,children:`Agent Name`}),(0,Q.jsx)(s,{id:`agentName`,value:n,onChange:e=>r(e.target.value),placeholder:`e.g. Security Reviewer`,disabled:d}),n&&(0,Q.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`Folder name: `,(0,Q.jsx)(`span`,{className:`font-mono`,children:p||`...`})]})]}),(0,Q.jsxs)(`div`,{className:`space-y-2`,children:[(0,Q.jsx)(J,{htmlFor:`agentDescription`,children:`Description`}),(0,Q.jsx)(Hr,{id:`agentDescription`,value:i,onChange:e=>a(e.target.value),placeholder:`Describe what this agent does and when it should be invoked`,className:`resize-none min-h-[120px]`,disabled:d})]}),(0,Q.jsxs)(`div`,{className:`space-y-2`,children:[(0,Q.jsx)(J,{htmlFor:`agentTools`,children:`Allowed Tools (optional)`}),(0,Q.jsx)(s,{id:`agentTools`,value:o,onChange:e=>c(e.target.value),placeholder:`e.g. read grep glob`,disabled:d}),(0,Q.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Space-separated list of tools this agent can use. Leave empty to allow all coding tools.`})]}),(0,Q.jsxs)(`div`,{className:`space-y-2`,children:[(0,Q.jsx)(J,{children:`Scope`}),(0,Q.jsxs)(bs,{value:l,onValueChange:e=>u(e),className:`flex gap-4`,disabled:d,children:[(0,Q.jsxs)(`div`,{className:`flex items-center space-x-2`,children:[(0,Q.jsx)(xs,{value:`local`,id:`scope-local`}),(0,Q.jsx)(J,{htmlFor:`scope-local`,className:`font-normal cursor-pointer`,children:`Local (this project)`})]}),(0,Q.jsxs)(`div`,{className:`flex items-center space-x-2`,children:[(0,Q.jsx)(xs,{value:`global`,id:`scope-global`,disabled:!0}),(0,Q.jsx)(J,{htmlFor:`scope-global`,className:`font-normal cursor-pointer text-muted-foreground`,children:`Global (coming soon)`})]})]}),(0,Q.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:l===`local`?`This agent will only be available for this project.`:`This agent will be available across all projects (coming soon).`})]}),(0,Q.jsx)(`div`,{className:`border-t pt-4 flex justify-end`,children:(0,Q.jsx)(q,{onClick:async()=>{if(!(!m||!i.trim()||!e)){f(!0);try{let n=await oe(e,p,i.trim(),o.trim()||void 0);$({title:`Agent created`,description:`Agent '${p}' was created successfully.`}),r(``),a(``),c(``),u(`local`),t?.(n.path,`AGENT.md`)}catch(e){$({title:`Error`,description:e instanceof Error?e.message:`Failed to create agent`,variant:`destructive`})}finally{f(!1)}}},disabled:!m||!i.trim()||d,children:d?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(Rt,{className:`mr-2 h-4 w-4 animate-spin`}),`Creating...`]}):(0,Q.jsxs)(Q.Fragment,{children:[`Continue`,(0,Q.jsx)(Ue,{className:`ml-2 h-4 w-4`})]})})})]})]}):(0,Q.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,Q.jsxs)(`div`,{className:`text-center`,children:[(0,Q.jsx)(`h2`,{className:`text-lg font-semibold text-muted-foreground mb-2`,children:`No Thread Selected`}),(0,Q.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Please select a thread to add an agent.`})]})})}function Es({projectId:e,threadId:t,onCommandCreated:n}){let[r,i]=(0,X.useState)(``),[o,c]=(0,X.useState)(``),[l,u]=(0,X.useState)(``),[d,f]=(0,X.useState)(`default`),[p,m]=(0,X.useState)(`local`),[h,g]=(0,X.useState)(!1),_=r.toLowerCase().replace(/\s+/g,`-`).replace(/[^a-z0-9-]/g,``).replace(/-+/g,`-`).replace(/^-|-$/g,``),v=_.length>0&&_.length<=64;return e?(0,Q.jsxs)(`div`,{className:`max-w-2xl mx-auto p-6`,children:[(0,Q.jsxs)(`div`,{className:`mb-6`,children:[(0,Q.jsx)(`h1`,{className:`text-2xl font-bold`,children:`Add Slash Command`}),(0,Q.jsx)(`p`,{className:`text-muted-foreground`,children:`Create a new slash command. The command will be saved as a .md file in the ~/.agents/commands folder.`})]}),(0,Q.jsxs)(`div`,{className:`space-y-6`,children:[(0,Q.jsxs)(`div`,{className:`space-y-2`,children:[(0,Q.jsx)(J,{htmlFor:`commandName`,children:`Command Name`}),(0,Q.jsx)(s,{id:`commandName`,value:r,onChange:e=>i(e.target.value),placeholder:`e.g. review`,disabled:h}),r&&(0,Q.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`Command: `,(0,Q.jsxs)(`span`,{className:`font-mono`,children:[`/`,_||`...`]})]})]}),(0,Q.jsxs)(`div`,{className:`space-y-2`,children:[(0,Q.jsx)(J,{htmlFor:`commandDescription`,children:`Description`}),(0,Q.jsx)(s,{id:`commandDescription`,value:o,onChange:e=>c(e.target.value),placeholder:`Brief description shown in autocomplete`,disabled:h})]}),(0,Q.jsxs)(`div`,{className:`space-y-2`,children:[(0,Q.jsx)(J,{htmlFor:`argumentHint`,children:`Argument Hint (optional)`}),(0,Q.jsx)(s,{id:`argumentHint`,value:l,onChange:e=>u(e.target.value),placeholder:`e.g. <focus-area> or <branch-name>`,disabled:h}),(0,Q.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Shows after the command name to guide users what to type`})]}),(0,Q.jsxs)(`div`,{className:`space-y-2`,children:[(0,Q.jsx)(J,{children:`Mode`}),(0,Q.jsxs)(bs,{value:d,onValueChange:e=>f(e),className:`flex gap-4`,disabled:h,children:[(0,Q.jsxs)(`div`,{className:`flex items-center space-x-2`,children:[(0,Q.jsx)(xs,{value:`default`,id:`mode-default`}),(0,Q.jsx)(J,{htmlFor:`mode-default`,className:`font-normal cursor-pointer`,children:`Default`})]}),(0,Q.jsxs)(`div`,{className:`flex items-center space-x-2`,children:[(0,Q.jsx)(xs,{value:`plan`,id:`mode-plan`}),(0,Q.jsx)(J,{htmlFor:`mode-plan`,className:`font-normal cursor-pointer`,children:`Plan`})]})]}),(0,Q.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:d===`default`?`Standard chat mode`:`Activates plan mode when this command is used`})]}),(0,Q.jsxs)(`div`,{className:`space-y-2`,children:[(0,Q.jsx)(J,{children:`Scope`}),(0,Q.jsxs)(bs,{value:p,onValueChange:e=>m(e),className:`flex gap-4`,disabled:h,children:[(0,Q.jsxs)(`div`,{className:`flex items-center space-x-2`,children:[(0,Q.jsx)(xs,{value:`local`,id:`scope-local`}),(0,Q.jsx)(J,{htmlFor:`scope-local`,className:`font-normal cursor-pointer`,children:`Local (this project)`})]}),(0,Q.jsxs)(`div`,{className:`flex items-center space-x-2`,children:[(0,Q.jsx)(xs,{value:`global`,id:`scope-global`,disabled:!0}),(0,Q.jsx)(J,{htmlFor:`scope-global`,className:`font-normal cursor-pointer text-muted-foreground`,children:`Global (coming soon)`})]})]}),(0,Q.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:p===`local`?`This command will only be available for this project.`:`This command will be available across all projects (coming soon).`})]}),(0,Q.jsx)(`div`,{className:`border-t pt-4 flex justify-end`,children:(0,Q.jsx)(q,{onClick:async()=>{if(!(!v||!e)){g(!0);try{await a(_,``,{description:o.trim()||void 0,argumentHint:l.trim()||void 0,mode:d===`plan`?`plan`:void 0},p===`global`?`global`:`project`,t??void 0),$({title:`Command created`,description:`Command '/${_}' was created successfully.`}),i(``),c(``),u(``),f(`default`),m(`local`),n?.(_)}catch(e){$({title:`Error`,description:e instanceof Error?e.message:`Failed to create command`,variant:`destructive`})}finally{g(!1)}}},disabled:!v||h,children:h?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(Rt,{className:`mr-2 h-4 w-4 animate-spin`}),`Creating...`]}):(0,Q.jsxs)(Q.Fragment,{children:[`Continue`,(0,Q.jsx)(Ue,{className:`ml-2 h-4 w-4`})]})})})]})]}):(0,Q.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,Q.jsxs)(`div`,{className:`text-center`,children:[(0,Q.jsx)(`h2`,{className:`text-lg font-semibold text-muted-foreground mb-2`,children:`No Project Selected`}),(0,Q.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Please select a project to add a slash command.`})]})})}function Ds(e){let[t,n]=(0,X.useState)([]),[r,i]=(0,X.useState)(!1),a=(0,X.useCallback)(async()=>{if(e){i(!0);try{let t=await pt(e);n(Object.entries(t.servers??{}).map(([e,t])=>({name:e,config:t})))}catch{n([])}finally{i(!1)}}},[e]);return(0,X.useEffect)(()=>{a()},[a]),{installedServers:t,loadingConfig:r,loadInstalledServers:a}}function Os(){let e=(0,Z.c)(5),t;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(t=[],e[0]=t):t=e[0];let[n,r]=(0,X.useState)(t),i,a;e[1]===Symbol.for(`react.memo_cache_sentinel`)?(i=()=>{$t().then(r).catch(()=>r([]))},a=[],e[1]=i,e[2]=a):(i=e[1],a=e[2]),(0,X.useEffect)(i,a);let o;return e[3]===n?o=e[4]:(o={popularServers:n},e[3]=n,e[4]=o),o}async function ks(e,t,n){await vt(e,t,n)}async function As(e,t){await E(e,t)}function js({projectPath:e,serverName:t,onBack:n}){let{installedServers:r}=Ds(e),i=!!t,[a,o]=(0,X.useState)(``),[c,l]=(0,X.useState)(``),[u,d]=(0,X.useState)(``),[f,p]=(0,X.useState)([]),[m,h]=(0,X.useState)(!1),[g,_]=(0,X.useState)(!1),[v,y]=(0,X.useState)(null),[b,x]=(0,X.useState)(i),[S,C]=(0,X.useState)(``),[T,E]=(0,X.useState)(``),[D,O]=(0,X.useState)(``),[k,A]=(0,X.useState)([]);(0,X.useEffect)(()=>{if(i&&t){let e=r.find(e=>e.name===t);if(e){o(e.name),l(e.config.command);let t=e.config.args.join(`
|
|
21
|
+
`);d(t);let n=Object.entries(e.config.env??{}).map(([e,t])=>({key:e,value:t}));p(n),C(e.name),E(e.config.command),O(t),A(n),x(!1)}}else x(!1)},[r,t,i]);let j=(0,X.useCallback)(()=>{p(e=>[...e,{key:``,value:``}])},[]),M=(0,X.useCallback)(e=>{p(t=>t.filter((t,n)=>n!==e))},[]),N=(0,X.useCallback)((e,t)=>{p(n=>n.map((n,r)=>r===e?{...n,key:t}:n))},[]),P=(0,X.useCallback)((e,t)=>{p(n=>n.map((n,r)=>r===e?{...n,value:t}:n))},[]),F=()=>{let e=u.split(`
|
|
22
|
+
`).map(e=>e.trim()).filter(Boolean),t={};for(let{key:e,value:n}of f)e.trim()&&(t[e.trim()]=n);return{command:c.trim(),args:e,...Object.keys(t).length>0?{env:t}:{}}},I=async()=>{y(null);let t=a.trim(),r=c.trim();if(!t){y(`Server name is required`);return}if(!r){y(`Command is required`);return}h(!0);try{if(!e)throw Error(`No project path`);await ks(e,S||t,F()),$({title:`Success`,description:i?`MCP server configuration saved`:`MCP server added`}),n()}catch(e){y(e instanceof Error?e.message:`Failed to save server`)}finally{h(!1)}},L=async()=>{if(e){_(!0);try{await As(e,S),$({title:`Success`,description:`MCP server removed`}),n()}catch(e){y(e instanceof Error?e.message:`Failed to delete server`)}finally{_(!1)}}},R=i?c!==T||u!==D||JSON.stringify(f)!==JSON.stringify(k):a.trim()!==``||c.trim()!==``||u.trim()!==``||f.length>0;return b?(0,Q.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,Q.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Loading server configuration...`})}):(0,Q.jsxs)(`div`,{className:`max-w-2xl mx-auto p-6`,children:[(0,Q.jsxs)(`div`,{className:`mb-6`,children:[(0,Q.jsx)(`h1`,{className:`text-2xl font-bold`,children:i?a:`Add MCP Server`}),(0,Q.jsx)(`p`,{className:`text-muted-foreground`,children:i?`Edit MCP Server configuration.`:`Configure a new MCP Server.`})]}),(0,Q.jsxs)(`div`,{className:`space-y-6`,children:[(0,Q.jsxs)(`div`,{className:`space-y-2`,children:[(0,Q.jsx)(J,{htmlFor:`server-name`,children:`Server name`}),(0,Q.jsx)(s,{id:`server-name`,placeholder:`e.g. filesystem`,value:a,onChange:e=>o(e.target.value),disabled:i}),i&&(0,Q.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Server name cannot be changed`})]}),(0,Q.jsxs)(`div`,{className:`space-y-2`,children:[(0,Q.jsx)(J,{htmlFor:`server-command`,children:`Command`}),(0,Q.jsx)(s,{id:`server-command`,placeholder:`e.g. npx`,value:c,onChange:e=>l(e.target.value),className:`text-sm`})]}),(0,Q.jsxs)(`div`,{className:`space-y-2`,children:[(0,Q.jsxs)(J,{htmlFor:`server-args`,children:[`Arguments `,(0,Q.jsx)(`span`,{className:`text-muted-foreground font-normal`,children:`(one per line)`})]}),(0,Q.jsx)(Hr,{id:`server-args`,placeholder:`-y
|
|
23
|
+
@modelcontextprotocol/server-filesystem
|
|
24
|
+
/path/to/dir`,value:u,onChange:e=>d(e.target.value),className:`font-mono text-xs min-h-[80px] resize-none`})]}),(0,Q.jsxs)(`div`,{className:`space-y-2`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Q.jsx)(J,{children:`Environment variables`}),(0,Q.jsxs)(q,{variant:`ghost`,size:`sm`,onClick:j,className:`h-6 px-2 text-xs`,children:[(0,Q.jsx)(te,{className:`h-3 w-3 mr-1`}),`Add variable`]})]}),f.length===0?(0,Q.jsx)(`p`,{className:`text-xs text-muted-foreground py-1`,children:`No environment variables configured`}):(0,Q.jsx)(`div`,{className:`flex flex-col gap-2`,children:f.map((e,t)=>(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(s,{placeholder:`KEY`,value:e.key,onChange:e=>N(t,e.target.value),className:`font-mono text-xs w-[35%]`}),(0,Q.jsx)(s,{placeholder:`value`,value:e.value,onChange:e=>P(t,e.target.value),className:`font-mono text-xs flex-1`}),(0,Q.jsx)(q,{variant:`ghost`,size:`icon`,onClick:()=>M(t),className:`h-9 w-9 flex-shrink-0`,children:(0,Q.jsx)(w,{className:`h-3.5 w-3.5`})})]},t))})]}),v&&(0,Q.jsx)(`p`,{className:`text-sm text-destructive`,children:v}),(0,Q.jsxs)(`div`,{className:`border-t pt-4 flex items-center justify-between`,children:[i&&(0,Q.jsx)(q,{variant:`destructive`,onClick:L,disabled:g||m,children:g?`Removing...`:`Remove`}),!i&&(0,Q.jsx)(`div`,{}),(0,Q.jsx)(q,{onClick:I,disabled:m||g||!R,children:m?i?`Saving...`:`Adding...`:i?`Save`:`Add`})]})]})]})}function Ms(e){let t=(0,Z.c)(23),{name:n,description:r,installed:i,onClick:a,onOpen:s,onUninstall:c}=e,l=`flex flex-col gap-2 p-2.5 rounded-lg border border-border bg-card text-left transition-colors w-full ${i?``:`hover:bg-accent/50 cursor-pointer`}`,u=i?void 0:a,d=i?void 0:`button`,f;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(f=(0,Q.jsx)(`div`,{className:`flex-shrink-0 h-6 w-6 rounded-md bg-muted flex items-center justify-center`,children:(0,Q.jsx)(Ve,{className:`h-3 w-3 text-muted-foreground`})}),t[0]=f):f=t[0];let p;t[1]===n?p=t[2]:(p=(0,Q.jsx)(`span`,{className:`font-medium text-sm truncate`,children:n}),t[1]=n,t[2]=p);let m;t[3]===i?m=t[4]:(m=i&&(0,Q.jsx)(Wr,{delayDuration:300,children:(0,Q.jsxs)(Gr,{children:[(0,Q.jsx)(Kr,{asChild:!0,children:(0,Q.jsx)(`span`,{className:`flex-shrink-0 h-4 w-4 rounded-full bg-green-500/15 flex items-center justify-center`,children:(0,Q.jsx)(tn,{className:`h-2.5 w-2.5 text-green-600 dark:text-green-400`})})}),(0,Q.jsx)(Ur,{children:`Installed`})]})}),t[3]=i,t[4]=m);let h;t[5]!==p||t[6]!==m?(h=(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[f,p,m]}),t[5]=p,t[6]=m,t[7]=h):h=t[7];let g;t[8]!==i||t[9]!==s||t[10]!==c?(g=i&&(0,Q.jsxs)(`div`,{className:`flex items-center gap-1 flex-shrink-0`,children:[s&&(0,Q.jsx)(Wr,{delayDuration:300,children:(0,Q.jsxs)(Gr,{children:[(0,Q.jsx)(Kr,{asChild:!0,children:(0,Q.jsx)(q,{variant:`ghost`,size:`icon-sm`,onClick:e=>{e.stopPropagation(),s()},children:(0,Q.jsx)(o,{className:`h-3.5 w-3.5`})})}),(0,Q.jsx)(Ur,{children:`Open in Explorer`})]})}),c&&(0,Q.jsx)(Wr,{delayDuration:300,children:(0,Q.jsxs)(Gr,{children:[(0,Q.jsx)(Kr,{asChild:!0,children:(0,Q.jsx)(q,{variant:`ghost`,size:`icon-sm`,onClick:e=>{e.stopPropagation(),c()},className:`text-destructive hover:text-destructive`,children:(0,Q.jsx)(ce,{className:`h-3.5 w-3.5`})})}),(0,Q.jsx)(Ur,{children:`Remove`})]})})]}),t[8]=i,t[9]=s,t[10]=c,t[11]=g):g=t[11];let _;t[12]!==h||t[13]!==g?(_=(0,Q.jsxs)(`div`,{className:`flex items-start justify-between gap-2`,children:[h,g]}),t[12]=h,t[13]=g,t[14]=_):_=t[14];let v;t[15]===r?v=t[16]:(v=(0,Q.jsx)(`p`,{className:`text-xs text-muted-foreground line-clamp-3`,children:r}),t[15]=r,t[16]=v);let y;return t[17]!==l||t[18]!==v||t[19]!==u||t[20]!==d||t[21]!==_?(y=(0,Q.jsxs)(`div`,{className:l,onClick:u,role:d,children:[_,v]}),t[17]=l,t[18]=v,t[19]=u,t[20]=d,t[21]=_,t[22]=y):y=t[22],y}var Ns=Pn,Ps=X.forwardRef((e,t)=>{let n=(0,Z.c)(9),r,i;n[0]===e?(r=n[1],i=n[2]):({className:r,...i}=e,n[0]=e,n[1]=r,n[2]=i);let a;n[3]===r?a=n[4]:(a=K(`inline-flex h-10 items-center justify-center rounded-md bg-muted p-1 text-muted-foreground`,r),n[3]=r,n[4]=a);let o;return n[5]!==i||n[6]!==t||n[7]!==a?(o=(0,Q.jsx)(hr,{ref:t,className:a,...i}),n[5]=i,n[6]=t,n[7]=a,n[8]=o):o=n[8],o});Ps.displayName=hr.displayName;var Fs=X.forwardRef((e,t)=>{let n=(0,Z.c)(9),r,i;n[0]===e?(r=n[1],i=n[2]):({className:r,...i}=e,n[0]=e,n[1]=r,n[2]=i);let a;n[3]===r?a=n[4]:(a=K(`inline-flex items-center justify-center whitespace-nowrap rounded-sm px-3 py-1.5 text-sm font-medium ring-offset-background transition-all focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 data-[state=active]:bg-background data-[state=active]:text-foreground data-[state=active]:shadow-sm`,r),n[3]=r,n[4]=a);let o;return n[5]!==i||n[6]!==t||n[7]!==a?(o=(0,Q.jsx)(mr,{ref:t,className:a,...i}),n[5]=i,n[6]=t,n[7]=a,n[8]=o):o=n[8],o});Fs.displayName=mr.displayName;var Is=X.forwardRef((e,t)=>{let n=(0,Z.c)(9),r,i;n[0]===e?(r=n[1],i=n[2]):({className:r,...i}=e,n[0]=e,n[1]=r,n[2]=i);let a;n[3]===r?a=n[4]:(a=K(`mt-2 ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2`,r),n[3]=r,n[4]=a);let o;return n[5]!==i||n[6]!==t||n[7]!==a?(o=(0,Q.jsx)(Jn,{ref:t,className:a,...i}),n[5]=i,n[6]=t,n[7]=a,n[8]=o):o=n[8],o});Is.displayName=Jn.displayName;function Ls(e){let t=[];for(let n of e)n.type===`file`&&t.push(n.path),n.children&&t.push(...Ls(n.children));return t}function Rs({projectPath:e,threadId:t,onClose:n}){let{installedServers:r,loadInstalledServers:i}=Ds(e),{popularServers:o}=Os(),{setActiveMainTab:c,setPendingExplorerPath:l,triggerExplorerRefresh:u,setExplorerClearPath:f}=gs(),[p,m]=(0,X.useState)(`mcp`),[h,_]=(0,X.useState)(``),[v,y]=(0,X.useState)(null),[x,S]=(0,X.useState)(null),[C,w]=(0,X.useState)(new Set),[T,E]=(0,X.useState)(new Map),[O,k]=(0,X.useState)([]),[A,j]=(0,X.useState)([]),[M,N]=(0,X.useState)([]),[P,F]=(0,X.useState)([]);(0,X.useEffect)(()=>{Ot().then(k).catch(()=>k([])),xt().then(j).catch(()=>j([])),Wt().then(N).catch(()=>N([])),wt().then(F).catch(()=>F([]))},[]),(0,X.useEffect)(()=>{t&&(b(t).then(e=>w(new Set(Ls(e)))).catch(()=>{}),g(t).then(e=>E(new Map(e.map(e=>[e.name,e.filePath])))).catch(()=>{}))},[t]);let L=(0,X.useCallback)(e=>{m(e),_(``)},[]),R=(0,X.useCallback)(e=>{let t=h.trim().toLowerCase();return t?e.filter(e=>e.name.toLowerCase().includes(t)||e.description.toLowerCase().includes(t)):e},[h]),z=(0,X.useMemo)(()=>R(o),[o,R]),B=(0,X.useMemo)(()=>R(O),[O,R]),V=(0,X.useMemo)(()=>R(A),[A,R]),ee=(0,X.useMemo)(()=>R(M),[M,R]),H=(0,X.useMemo)(()=>R(P),[P,R]),te=(0,X.useCallback)(async t=>{if(!e)return;let n=t.name.toLowerCase().replace(/\s+/g,`-`);if(!r.some(e=>e.name===n||e.name===t.id)){y(t.id);try{await ks(e,n,{command:t.command,args:t.args,...Object.keys(t.env??{}).length>0?{env:t.env}:{}}),await i(),u(),$({title:`MCP server installed`,description:t.name})}catch(e){$({title:`Error`,description:e instanceof Error?e.message:`Failed to install server`,variant:`destructive`})}finally{y(null)}}},[e,r,i,u]),ne=(0,X.useCallback)(async t=>{if(!e)return;let n=t.name.toLowerCase().replace(/\s+/g,`-`);try{await As(e,n),await i(),u(),$({title:`MCP server removed`,description:t.name})}catch(e){$({title:`Error`,description:e instanceof Error?e.message:`Failed to remove server`,variant:`destructive`})}},[e,i,u]),U=(0,X.useCallback)(()=>{l(`.agents/mcp.json`),c(`explorer`),n()},[l,c,n]),ie=(0,X.useCallback)(e=>{l(`.agents/skills/${e.id}/SKILL.md`),c(`explorer`),n()},[l,c,n]),ae=(0,X.useCallback)(e=>{l(`.agents/agents/${e.id}/AGENT.md`),c(`explorer`),n()},[l,c,n]),oe=(0,X.useCallback)(e=>{l(`.agents/rules/${e.name}.md`),c(`explorer`),n()},[l,c,n]),se=(0,X.useCallback)(e=>{let t=T.get(e.name);t&&(l(t),c(`explorer`),n())},[T,l,c,n]),ce=(0,X.useCallback)(async e=>{if(!t)return;let n=`.agents/skills/${e.id}/SKILL.md`;try{await kn(t,`.agents/skills/${e.id}`),w(e=>{let t=new Set(e);return t.delete(n),t}),f(`.agents/skills/${e.id}`),u(),$({title:`Skill removed`,description:e.name})}catch(e){$({title:`Error`,description:e instanceof Error?e.message:`Failed to remove skill`,variant:`destructive`})}},[t,u,f]),le=(0,X.useCallback)(async e=>{if(!t)return;let n=`.agents/agents/${e.id}/AGENT.md`;try{await kn(t,`.agents/agents/${e.id}`),w(e=>{let t=new Set(e);return t.delete(n),t}),f(`.agents/agents/${e.id}`),u(),$({title:`Agent removed`,description:e.name})}catch(e){$({title:`Error`,description:e instanceof Error?e.message:`Failed to remove agent`,variant:`destructive`})}},[t,u,f]),ue=(0,X.useCallback)(async e=>{if(!t)return;let n=`.agents/rules/${e.name}.md`;try{await kn(t,n),w(e=>{let t=new Set(e);return t.delete(n),t}),f(n),u(),$({title:`Rule removed`,description:e.name})}catch(e){$({title:`Error`,description:e instanceof Error?e.message:`Failed to remove rule`,variant:`destructive`})}},[t,u,f]),de=(0,X.useCallback)(async e=>{let t=T.get(e.name);if(t)try{await re(t),E(t=>{let n=new Map(t);return n.delete(e.name),n}),f(t),u(),$({title:`Command removed`,description:`/${e.name}`})}catch(e){$({title:`Error`,description:e instanceof Error?e.message:`Failed to remove command`,variant:`destructive`})}},[T,u,f]),fe=(0,X.useCallback)((e,t,n,r)=>{S({name:e,gitHubRepo:t,gitHubFolder:n,onConfirm:r})},[]),pe=(0,X.useCallback)(async e=>{let n=`.agents/skills/${e.id}/SKILL.md`;if(!t||C.has(n))return;let r=async()=>{y(e.id);try{if(e.gitHubRepo&&e.gitHubFolder)await He(t,e.gitHubRepo,e.gitHubFolder,`.agents/skills/${e.id}`);else{let r=[`---`,`name: ${e.id}`,`description: ${e.description}`];e.allowedTools&&r.push(`allowed-tools: ${e.allowedTools}`),e.license&&r.push(`license: ${e.license}`),r.push(`---`,``,e.instructions),await Kt(t,n,r.join(`
|
|
25
|
+
`))}w(e=>new Set(e).add(n)),u(),$({title:`Skill installed`,description:e.name})}catch(e){$({title:`Error`,description:e instanceof Error?e.message:`Failed to install skill`,variant:`destructive`})}finally{y(null)}};e.gitHubRepo&&e.gitHubFolder?fe(e.name,e.gitHubRepo,e.gitHubFolder,r):await r()},[t,C,u,fe]),me=(0,X.useCallback)(async e=>{let n=`.agents/agents/${e.id}/AGENT.md`;if(!t||C.has(n))return;let r=async()=>{y(e.id);try{if(e.gitHubRepo&&e.gitHubFolder)await He(t,e.gitHubRepo,e.gitHubFolder,`.agents/agents/${e.id}`);else{let r=[`---`,`name: ${e.id}`,`description: ${e.description}`];e.tools&&r.push(`tools: ${e.tools}`),r.push(`---`,``,e.systemPrompt),await Kt(t,n,r.join(`
|
|
26
|
+
`))}w(e=>new Set(e).add(n)),u(),$({title:`Agent installed`,description:e.name})}catch(e){$({title:`Error`,description:e instanceof Error?e.message:`Failed to install agent`,variant:`destructive`})}finally{y(null)}};e.gitHubRepo&&e.gitHubFolder?fe(e.name,e.gitHubRepo,e.gitHubFolder,r):await r()},[t,C,u,fe]),he=(0,X.useCallback)(async e=>{let n=`.agents/rules/${e.name}.md`;if(!t||C.has(n))return;let r=async()=>{y(e.id);try{e.gitHubRepo&&e.gitHubFolder?await He(t,e.gitHubRepo,e.gitHubFolder,`.agents/rules`):await Kt(t,n,[`---`,`description: ${e.description}`,`alwaysApply: ${e.alwaysApply??!1}`,`---`,``,e.content].join(`
|
|
27
|
+
`)),w(e=>new Set(e).add(n)),u(),$({title:`Rule installed`,description:e.name})}catch(e){$({title:`Error`,description:e instanceof Error?e.message:`Failed to install rule`,variant:`destructive`})}finally{y(null)}};e.gitHubRepo&&e.gitHubFolder?fe(e.name,e.gitHubRepo,e.gitHubFolder,r):await r()},[t,C,u,fe]),ge=(0,X.useCallback)(async e=>{if(!t||T.has(e.name))return;let n=async()=>{y(e.id);try{if(e.gitHubRepo&&e.gitHubFolder){let n=`.agents/commands`;await He(t,e.gitHubRepo,e.gitHubFolder,n);let r=`${n}/${e.name}.md`;E(t=>new Map(t).set(e.name,r))}else{let n=await a(e.name,e.content,{description:e.description,argumentHint:e.argumentHint},`project`,t);E(t=>new Map(t).set(e.name,n.filePath))}u(),$({title:`Command installed`,description:`/${e.name}`})}catch(e){$({title:`Error`,description:e instanceof Error?e.message:`Failed to install command`,variant:`destructive`})}finally{y(null)}};e.gitHubRepo&&e.gitHubFolder?fe(e.name,e.gitHubRepo,e.gitHubFolder,n):await n()},[t,T,u,fe]);function _e({items:e,onInstall:n,isInstalled:r,noThreadWarning:i,onOpen:a,onUninstall:o}){return e.length===0&&h.trim()?(0,Q.jsxs)(`p`,{className:`text-sm text-muted-foreground text-center py-8`,children:[`No results for "`,h,`"`]}):e.length===0?(0,Q.jsx)(`div`,{className:`flex items-center justify-center py-16`,children:(0,Q.jsx)(Rt,{className:`h-5 w-5 animate-spin text-muted-foreground`})}):(0,Q.jsxs)(Q.Fragment,{children:[i&&!t&&(0,Q.jsx)(`p`,{className:`text-xs text-muted-foreground bg-muted rounded-md px-3 py-2`,children:`Open a thread to install items into your project.`}),(0,Q.jsx)(`div`,{className:`grid gap-2`,style:{gridTemplateColumns:`repeat(auto-fill, minmax(min(220px, 100%), 1fr))`},children:e.map(e=>{let t=r(e);return(0,Q.jsxs)(`div`,{className:`relative`,children:[v===e.id&&(0,Q.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center bg-background/60 rounded-lg z-10`,children:(0,Q.jsx)(Rt,{className:`h-4 w-4 animate-spin`})}),(0,Q.jsx)(Ms,{name:e.name,description:e.description,installed:t,onClick:()=>n(e),onOpen:t&&a?()=>a(e):void 0,onUninstall:t&&o?()=>o(e):void 0})]},e.id)})})]})}return(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(D,{open:x!==null,onOpenChange:e=>{e||S(null)},children:(0,Q.jsxs)(I,{children:[(0,Q.jsxs)(jn,{children:[(0,Q.jsxs)(d,{children:[`Install `,x?.name]}),(0,Q.jsxs)(W,{children:[`Install `,(0,Q.jsx)(`strong`,{children:x?.name}),` from`,` `,(0,Q.jsx)(`strong`,{children:x?.gitHubRepo}),` (`,x?.gitHubFolder,`)?`]})]}),(0,Q.jsxs)(De,{className:`flex-row gap-2 sm:justify-between`,children:[(0,Q.jsx)(q,{variant:`outline`,onClick:()=>{x&&Ke(`${x.gitHubRepo.replace(/\.git$/,``)}/tree/HEAD/${x.gitHubFolder}`)},children:`More Information`}),(0,Q.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Q.jsx)(q,{variant:`outline`,onClick:()=>S(null),children:`No`}),(0,Q.jsx)(q,{onClick:()=>{let e=x;S(null),e&&e.onConfirm()},children:`Yes`})]})]})]})}),(0,Q.jsxs)(`div`,{className:`flex flex-col h-full`,children:[(0,Q.jsxs)(`div`,{className:`p-6 pb-0 space-y-4 flex-shrink-0`,children:[(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`h2`,{className:`text-lg font-semibold`,children:`Marketplace`}),(0,Q.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:{mcp:`Browse and install popular MCP servers`,skills:`Reusable instruction sets that guide agent behavior`,agents:`Specialized sub-agents for focused tasks`,rules:`Coding standards and project-wide guidelines`,commands:`Slash commands for quick prompts`}[p]})]}),(0,Q.jsx)(Ns,{value:p,onValueChange:L,children:(0,Q.jsxs)(Ps,{className:`w-full`,children:[(0,Q.jsx)(Fs,{value:`mcp`,className:`flex-1`,children:`MCP`}),(0,Q.jsx)(Fs,{value:`skills`,className:`flex-1`,children:`Skills`}),(0,Q.jsx)(Fs,{value:`agents`,className:`flex-1`,children:`Agents`}),(0,Q.jsx)(Fs,{value:`rules`,className:`flex-1`,children:`Rules`}),(0,Q.jsx)(Fs,{value:`commands`,className:`flex-1`,children:`Commands`})]})}),(0,Q.jsxs)(`div`,{className:`relative`,children:[(0,Q.jsx)(Re,{className:`absolute left-2.5 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground pointer-events-none`}),(0,Q.jsx)(s,{placeholder:`Search ${p===`mcp`?`servers`:p}...`,value:h,onChange:e=>_(e.target.value),className:`pl-8`})]})]}),(0,Q.jsxs)(`div`,{className:`flex-1 overflow-y-auto p-6 pt-4 space-y-3`,children:[p===`mcp`&&(0,Q.jsx)(Q.Fragment,{children:o.length===0?(0,Q.jsx)(`div`,{className:`flex items-center justify-center py-16`,children:(0,Q.jsx)(Rt,{className:`h-5 w-5 animate-spin text-muted-foreground`})}):z.length===0?(0,Q.jsxs)(`p`,{className:`text-sm text-muted-foreground text-center py-8`,children:[`No results for "`,h,`"`]}):(0,Q.jsx)(`div`,{className:`grid gap-2`,style:{gridTemplateColumns:`repeat(auto-fill, minmax(min(220px, 100%), 1fr))`},children:z.map(e=>{let t=e.name.toLowerCase().replace(/\s+/g,`-`),n=r.some(n=>n.name===t||n.name===e.id);return(0,Q.jsxs)(`div`,{className:`relative`,children:[v===e.id&&(0,Q.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center bg-background/60 rounded-lg z-10`,children:(0,Q.jsx)(Rt,{className:`h-4 w-4 animate-spin`})}),(0,Q.jsx)(Ms,{name:e.name,description:e.description,installed:n,onClick:()=>void te(e),onOpen:n?U:void 0,onUninstall:n?()=>void ne(e):void 0})]},e.id)})})}),p===`skills`&&(0,Q.jsx)(_e,{items:B,onInstall:e=>void pe(e),isInstalled:e=>C.has(`.agents/skills/${e.id}/SKILL.md`),noThreadWarning:!0,onOpen:ie,onUninstall:e=>void ce(e)}),p===`agents`&&(0,Q.jsx)(_e,{items:V,onInstall:e=>void me(e),isInstalled:e=>C.has(`.agents/agents/${e.id}/AGENT.md`),noThreadWarning:!0,onOpen:ae,onUninstall:e=>void le(e)}),p===`rules`&&(0,Q.jsx)(_e,{items:ee,onInstall:e=>void he(e),isInstalled:e=>C.has(`.agents/rules/${e.name}.md`),noThreadWarning:!0,onOpen:oe,onUninstall:e=>void ue(e)}),p===`commands`&&(0,Q.jsx)(_e,{items:H,onInstall:e=>void ge(e),isInstalled:e=>T.has(e.name),noThreadWarning:!0,onOpen:se,onUninstall:e=>void de(e)})]})]})]})}function zs(){let e=fr(),{state:t}=Ar(),{selectedProjectId:n,selectedThreadId:r,projects:i}=t,a=i.find(e=>e.projectId===n),[o,s]=(0,X.useState)(null),[c,l]=(0,X.useState)(``),[u,f]=(0,X.useState)(!1),[p,m]=(0,X.useState)(!1);(0,X.useEffect)(()=>{o!==`instructions`||!r||(f(!0),T(r,`AGENTS.md`).then(e=>l(e.content)).catch(()=>l(``)).finally(()=>f(!1)))},[o,r]);let h=async()=>{if(r){m(!0);try{await Kt(r,`AGENTS.md`,c),$({title:`Instructions saved`}),s(null)}catch(e){$({title:`Error`,description:e instanceof Error?e.message:`Failed to save instructions`,variant:`destructive`})}finally{m(!1)}}};return n?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(Wr,{children:(0,Q.jsxs)(Oo,{children:[(0,Q.jsxs)(Gr,{children:[(0,Q.jsx)(Kr,{asChild:!0,children:(0,Q.jsx)(ko,{asChild:!0,children:(0,Q.jsx)(q,{variant:`action`,size:`icon-md`,children:(0,Q.jsx)(B,{})})})}),(0,Q.jsx)(Ur,{children:`AI`})]}),(0,Q.jsxs)(No,{align:`end`,children:[(0,Q.jsx)(Po,{onSelect:()=>s(`mcp`),children:`Add MCP Server`}),(0,Q.jsx)(Po,{onSelect:()=>s(`skill`),children:`Add Skill`}),(0,Q.jsx)(Po,{onSelect:()=>s(`rule`),children:`Add Rule`}),(0,Q.jsx)(Po,{onSelect:()=>s(`slash-command`),children:`Add Slash Command`}),(0,Q.jsx)(Po,{onSelect:()=>s(`subagent`),children:`Add Subagent`}),(0,Q.jsx)(Ro,{}),(0,Q.jsx)(Po,{onSelect:()=>s(`instructions`),disabled:!r,children:`Instructions`}),(0,Q.jsx)(Po,{onSelect:()=>void e(`/settings?tab=providers`),children:`Model Providers`}),(0,Q.jsx)(Ro,{}),(0,Q.jsx)(Po,{onSelect:()=>s(`marketplace`),children:`Marketplace`})]})]})}),(0,Q.jsx)(D,{open:o===`mcp`,onOpenChange:e=>!e&&s(null),children:(0,Q.jsx)(I,{className:`max-w-2xl max-h-[90vh] overflow-y-auto p-0`,children:(0,Q.jsx)(`div`,{className:`w-full`,children:(0,Q.jsx)(js,{projectPath:a?.projectPath,onBack:()=>s(null)})})})}),(0,Q.jsx)(D,{open:o===`marketplace`,onOpenChange:e=>!e&&s(null),children:(0,Q.jsx)(I,{className:`max-w-3xl h-[80vh] overflow-y-auto p-0`,children:(0,Q.jsx)(Rs,{projectPath:a?.projectPath,threadId:r,onClose:()=>s(null)})})}),(0,Q.jsx)(D,{open:o===`skill`,onOpenChange:e=>!e&&s(null),children:(0,Q.jsx)(I,{className:`max-w-2xl max-h-[90vh] overflow-y-auto p-0`,children:(0,Q.jsx)(Ss,{threadId:r,onSkillCreated:()=>s(null)})})}),(0,Q.jsx)(D,{open:o===`rule`,onOpenChange:e=>!e&&s(null),children:(0,Q.jsx)(I,{className:`max-w-2xl max-h-[90vh] overflow-y-auto p-0`,children:(0,Q.jsx)(ws,{threadId:r,onRuleCreated:()=>s(null)})})}),(0,Q.jsx)(D,{open:o===`slash-command`,onOpenChange:e=>!e&&s(null),children:(0,Q.jsx)(I,{className:`max-w-2xl max-h-[90vh] overflow-y-auto p-0`,children:(0,Q.jsx)(Es,{projectId:n,threadId:r,onCommandCreated:()=>s(null)})})}),(0,Q.jsx)(D,{open:o===`subagent`,onOpenChange:e=>!e&&s(null),children:(0,Q.jsx)(I,{className:`max-w-2xl max-h-[90vh] overflow-y-auto p-0`,children:(0,Q.jsx)(Ts,{threadId:r,onAgentCreated:()=>s(null)})})}),(0,Q.jsx)(D,{open:o===`instructions`,onOpenChange:e=>!e&&s(null),children:(0,Q.jsxs)(I,{className:`max-w-2xl`,children:[(0,Q.jsxs)(jn,{children:[(0,Q.jsx)(d,{children:`Instructions`}),(0,Q.jsx)(W,{children:`Add context like coding guidelines and expectations that are relevant for all conversations (this is stored in the agents.md file)`})]}),u?(0,Q.jsx)(`div`,{className:`flex items-center justify-center py-12`,children:(0,Q.jsx)(Rt,{className:`h-5 w-5 animate-spin text-muted-foreground`})}):(0,Q.jsx)(Hr,{value:c,onChange:e=>l(e.target.value),className:`min-h-[300px] font-mono text-sm resize-none`,placeholder:`Add instructions for your agent in AGENTS.md...`,disabled:p}),(0,Q.jsxs)(De,{children:[(0,Q.jsx)(q,{variant:`outline`,onClick:()=>s(null),children:`Cancel`}),(0,Q.jsx)(q,{onClick:()=>void h(),disabled:u||p,children:p?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(Rt,{className:`mr-2 h-4 w-4 animate-spin`}),`Saving...`]}):`Save`})]})]})})]}):null}function Bs(){let e=(0,Z.c)(44),{state:t,dispatch:n}=Ar(),{selectedThreadId:i,selectedProjectId:a,projects:o,sidebarOpen:s}=t,c;if(e[0]!==o||e[1]!==a){let t;e[3]===a?t=e[4]:(t=e=>e.projectId===a,e[3]=a,e[4]=t),c=o.find(t),e[0]=o,e[1]=a,e[2]=c}else c=e[2];let l=c,u=!s,d=u&&`h-auto py-3 flex-col items-start gap-3 md:flex-row md:items-center md:h-[71px] md:py-0 md:gap-2`,f;e[5]===d?f=e[6]:(f=K(d),e[5]=d,e[6]=f);let p;e[7]===n?p=e[8]:(p=()=>n({type:Y.ToggleSidebar}),e[7]=n,e[8]=p);let m;e[9]===s?m=e[10]:(m=s?(0,Q.jsx)(r,{className:`h-4 w-4`}):(0,Q.jsx)(Ce,{className:`h-4 w-4`}),e[9]=s,e[10]=m);let h;e[11]===Symbol.for(`react.memo_cache_sentinel`)?(h=(0,Q.jsx)(`span`,{className:`sr-only`,children:`Toggle sidebar`}),e[11]=h):h=e[11];let g;e[12]!==p||e[13]!==m?(g=(0,Q.jsxs)(q,{variant:`ghost`,size:`icon`,className:`h-8 w-8 text-muted-foreground shrink-0`,onClick:p,children:[m,h]}),e[12]=p,e[13]=m,e[14]=g):g=e[14];let _;e[15]!==o||e[16]!==a||e[17]!==i?(_=i&&(0,Q.jsxs)(`div`,{className:`flex flex-col`,children:[(0,Q.jsx)(`span`,{className:`text-sm font-medium text-foreground`,children:We(o,a)}),(0,Q.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:k(o,i)})]}),e[15]=o,e[16]=a,e[17]=i,e[18]=_):_=e[18];let v;e[19]!==g||e[20]!==_?(v=(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[g,_]}),e[19]=g,e[20]=_,e[21]=v):v=e[21];let y=u?`ml-0`:`ml-auto`,b;e[22]===y?b=e[23]:(b=K(`flex flex-wrap items-center justify-end gap-2`,y,`md:ml-auto`),e[22]=y,e[23]=b);let x;e[24]!==l?.runCommand||e[25]!==a||e[26]!==i?(x=a&&(0,Q.jsxs)(vs,{children:[(0,Q.jsx)(_s,{projectId:a,runCommand:l?.runCommand}),i&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(ys,{threadId:i}),(0,Q.jsx)(ms,{}),(0,Q.jsx)(zs,{})]})]}),e[24]=l?.runCommand,e[25]=a,e[26]=i,e[27]=x):x=e[27];let S;e[28]!==a||e[29]!==i?(S=i&&a&&(0,Q.jsx)(vs,{children:(0,Q.jsx)(ds,{projectId:a,threadId:i})}),e[28]=a,e[29]=i,e[30]=S):S=e[30];let C;e[31]!==l?.openWith||e[32]!==a||e[33]!==i?(C=i&&a&&(0,Q.jsx)(vs,{children:(0,Q.jsx)(Ho,{projectId:a,threadId:i,openWith:l?.openWith})}),e[31]=l?.openWith,e[32]=a,e[33]=i,e[34]=C):C=e[34];let w;e[35]!==b||e[36]!==x||e[37]!==S||e[38]!==C?(w=(0,Q.jsxs)(`div`,{className:b,children:[x,S,C]}),e[35]=b,e[36]=x,e[37]=S,e[38]=C,e[39]=w):w=e[39];let T;return e[40]!==w||e[41]!==f||e[42]!==v?(T=(0,Q.jsxs)(Do,{className:f,children:[v,w]}),e[40]=w,e[41]=f,e[42]=v,e[43]=T):T=e[43],T}function Vs(e){let t=(0,Z.c)(13),{open:n,projectName:r,onOpenChange:i,onConfirm:a}=e,o;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(o=(0,Q.jsx)(xi,{children:`Delete Project`}),t[0]=o):o=t[0];let s;t[1]===r?s=t[2]:(s=(0,Q.jsxs)(yi,{children:[o,(0,Q.jsxs)(Si,{children:[`Are you sure you want to delete`,` `,(0,Q.jsxs)(`span`,{className:`font-semibold text-foreground`,children:[`"`,r,`"`]}),`? This will remove the project and all its data. This action cannot be undone.`]})]}),t[1]=r,t[2]=s);let c;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(c=(0,Q.jsx)(wi,{children:`Cancel`}),t[3]=c):c=t[3];let l;t[4]===a?l=t[5]:(l=(0,Q.jsxs)(bi,{children:[c,(0,Q.jsx)(Ci,{onClick:a,className:`bg-destructive text-destructive-foreground hover:bg-destructive/90`,children:`Delete`})]}),t[4]=a,t[5]=l);let u;t[6]!==s||t[7]!==l?(u=(0,Q.jsxs)(vi,{children:[s,l]}),t[6]=s,t[7]=l,t[8]=u):u=t[8];let d;return t[9]!==i||t[10]!==n||t[11]!==u?(d=(0,Q.jsx)(hi,{open:n,onOpenChange:i,children:u}),t[9]=i,t[10]=n,t[11]=u,t[12]=d):d=t[12],d}function Hs(e){let t=(0,Z.c)(28),{open:n,setupScripts:r,onConfirm:i}=e;if(r.length===0)return null;let a;t[0]===i?a=t[1]:(a=e=>{e||i(!1)},t[0]=i,t[1]=a);let o;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(o=(0,Q.jsx)(xi,{children:`Install dependencies?`}),t[2]=o):o=t[2];let s=r.length===1?``:`s`,c;t[3]!==r.length||t[4]!==s?(c=(0,Q.jsxs)(yi,{children:[o,(0,Q.jsxs)(Si,{children:[`Found `,r.length,` package`,s,` with dependencies to install:`]})]}),t[3]=r.length,t[4]=s,t[5]=c):c=t[5];let l;t[6]===r?l=t[7]:(l=r.map(Us),t[6]=r,t[7]=l);let u;t[8]===l?u=t[9]:(u=(0,Q.jsx)(`div`,{className:`my-4 max-h-60 overflow-y-auto`,children:(0,Q.jsx)(`div`,{className:`space-y-2`,children:l})}),t[8]=l,t[9]=u);let d;t[10]===i?d=t[11]:(d=(0,Q.jsx)(wi,{onClick:()=>i(!1),children:`No`}),t[10]=i,t[11]=d);let f;t[12]===i?f=t[13]:(f=()=>i(!0),t[12]=i,t[13]=f);let p;t[14]!==r.length||t[15]!==f?(p=(0,Q.jsxs)(Ci,{onClick:f,children:[`Install All (`,r.length,`)`]}),t[14]=r.length,t[15]=f,t[16]=p):p=t[16];let m;t[17]!==d||t[18]!==p?(m=(0,Q.jsxs)(bi,{children:[d,p]}),t[17]=d,t[18]=p,t[19]=m):m=t[19];let h;t[20]!==m||t[21]!==c||t[22]!==u?(h=(0,Q.jsxs)(vi,{className:`max-w-2xl`,children:[c,u,m]}),t[20]=m,t[21]=c,t[22]=u,t[23]=h):h=t[23];let g;return t[24]!==n||t[25]!==a||t[26]!==h?(g=(0,Q.jsx)(hi,{open:n,onOpenChange:a,children:h}),t[24]=n,t[25]=a,t[26]=h,t[27]=g):g=t[27],g}function Us(e,t){let n=e.match(/^cd "([^"]+)" && (.+)$/),r=n?n[1]:`root`,i=n?n[2]:e;return(0,Q.jsx)(`div`,{className:`flex items-center justify-between p-3 rounded-lg border bg-muted/50`,children:(0,Q.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,Q.jsx)(`div`,{className:`w-2 h-2 rounded-full bg-blue-500`}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`div`,{className:`font-medium text-sm`,children:r||`root`}),(0,Q.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:i})]})]})},t)}function Ws(){let e=(0,Z.c)(6),[t,n]=(0,X.useState)(!0),r,i;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(r=()=>{let e=!0;return(async()=>{try{let t=await fetch(`${Me()}/health`,{method:`GET`});e&&n(t.ok)}catch{e&&n(!1)}})(),()=>{e=!1}},i=[],e[0]=r,e[1]=i):(r=e[0],i=e[1]),(0,X.useEffect)(r,i);let a=Gs;if(t)return null;let o;e[2]===Symbol.for(`react.memo_cache_sentinel`)?(o=Me(),e[2]=o):o=e[2];let s=o,c,l;e[3]===Symbol.for(`react.memo_cache_sentinel`)?(c=(0,Q.jsxs)(yi,{children:[(0,Q.jsx)(xi,{children:`Service unavailable`}),(0,Q.jsx)(Si,{children:`Service is not currently up. Please ensure the backend is running at the address below, then retry.`})]}),l=(0,Q.jsx)(`div`,{className:`rounded-md bg-muted px-3 py-2 text-xs font-mono text-muted-foreground`,children:s}),e[3]=c,e[4]=l):(c=e[3],l=e[4]);let u;return e[5]===Symbol.for(`react.memo_cache_sentinel`)?(u=(0,Q.jsx)(hi,{open:!0,children:(0,Q.jsxs)(vi,{children:[c,l,(0,Q.jsx)(bi,{children:(0,Q.jsx)(q,{onClick:a,children:`Retry`})})]})}),e[5]=u):u=e[5],u}function Gs(){window.location.assign(window.location.href)}var Ks=e=>{let t=(0,Z.c)(8),n,r;t[0]===e?(n=t[1],r=t[2]):({className:n,...r}=e,t[0]=e,t[1]=n,t[2]=r);let i;t[3]===n?i=t[4]:(i=K(`flex h-full w-full data-[panel-group-direction=vertical]:flex-col`,n),t[3]=n,t[4]=i);let a;return t[5]!==r||t[6]!==i?(a=(0,Q.jsx)(Rn,{className:i,...r}),t[5]=r,t[6]=i,t[7]=a):a=t[7],a},qs=$n,Js=e=>{let t=(0,Z.c)(12),n,r,i;t[0]===e?(n=t[1],r=t[2],i=t[3]):({withHandle:i,className:n,...r}=e,t[0]=e,t[1]=n,t[2]=r,t[3]=i);let a;t[4]===n?a=t[5]:(a=K(`relative flex w-px items-center justify-center bg-transparent after:absolute after:inset-y-0 after:left-1/2 after:w-1 after:-translate-x-1/2 focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring focus-visible:ring-offset-1 data-[panel-group-direction=vertical]:h-px data-[panel-group-direction=vertical]:w-full data-[panel-group-direction=vertical]:after:left-0 data-[panel-group-direction=vertical]:after:h-1 data-[panel-group-direction=vertical]:after:w-full data-[panel-group-direction=vertical]:after:-translate-y-1/2 data-[panel-group-direction=vertical]:after:translate-x-0 [&[data-panel-group-direction=vertical]>div]:rotate-90`,n),t[4]=n,t[5]=a);let o;t[6]===i?o=t[7]:(o=i&&(0,Q.jsx)(`div`,{className:`hidden z-10 flex h-4 w-3 items-center justify-center rounded-sm border bg-border`,children:(0,Q.jsx)(Ct,{className:`h-2.5 w-2.5`})}),t[6]=i,t[7]=o);let s;return t[8]!==r||t[9]!==a||t[10]!==o?(s=(0,Q.jsx)(Ln,{className:a,...r,children:o}),t[8]=r,t[9]=a,t[10]=o,t[11]=s):s=t[11],s},Ys=Or,Xs=X.forwardRef((e,t)=>{let n=(0,Z.c)(9),r,i;n[0]===e?(r=n[1],i=n[2]):({className:r,...i}=e,n[0]=e,n[1]=r,n[2]=i);let a;n[3]===r?a=n[4]:(a=K(`fixed top-0 z-[100] flex max-h-screen w-full flex-col-reverse p-4 sm:bottom-0 sm:right-0 sm:top-auto sm:flex-col md:max-w-[420px]`,r),n[3]=r,n[4]=a);let o;return n[5]!==i||n[6]!==t||n[7]!==a?(o=(0,Q.jsx)(Dr,{ref:t,className:a,...i}),n[5]=i,n[6]=t,n[7]=a,n[8]=o):o=n[8],o});Xs.displayName=Dr.displayName;var Zs=de(`group pointer-events-auto relative flex w-full items-center justify-between space-x-4 overflow-hidden rounded-md border p-6 pr-8 shadow-lg transition-all data-[swipe=cancel]:translate-x-0 data-[swipe=end]:translate-x-[var(--radix-toast-swipe-end-x)] data-[swipe=move]:translate-x-[var(--radix-toast-swipe-move-x)] data-[swipe=move]:transition-none data-[state=open]:animate-in data-[state=closed]:animate-out data-[swipe=end]:animate-out data-[state=closed]:fade-out-80 data-[state=closed]:slide-out-to-right-full data-[state=open]:slide-in-from-top-full data-[state=open]:sm:slide-in-from-bottom-full`,{variants:{variant:{default:`border bg-background text-foreground`,destructive:`destructive group border-destructive bg-destructive text-destructive-foreground`}},defaultVariants:{variant:`default`}}),Qs=X.forwardRef((e,t)=>{let n=(0,Z.c)(11),r,i,a;n[0]===e?(r=n[1],i=n[2],a=n[3]):({className:r,variant:a,...i}=e,n[0]=e,n[1]=r,n[2]=i,n[3]=a);let o;n[4]!==r||n[5]!==a?(o=K(Zs({variant:a}),r),n[4]=r,n[5]=a,n[6]=o):o=n[6];let s;return n[7]!==i||n[8]!==t||n[9]!==o?(s=(0,Q.jsx)(Qn,{ref:t,className:o,...i}),n[7]=i,n[8]=t,n[9]=o,n[10]=s):s=n[10],s});Qs.displayName=Qn.displayName;var $s=X.forwardRef((e,t)=>{let n=(0,Z.c)(9),r,i;n[0]===e?(r=n[1],i=n[2]):({className:r,...i}=e,n[0]=e,n[1]=r,n[2]=i);let a;n[3]===r?a=n[4]:(a=K(`inline-flex h-8 shrink-0 items-center justify-center rounded-md border bg-transparent px-3 text-sm font-medium ring-offset-background transition-colors hover:bg-secondary focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 group-[.destructive]:border-muted/40 group-[.destructive]:hover:border-destructive/30 group-[.destructive]:hover:bg-destructive group-[.destructive]:hover:text-destructive-foreground group-[.destructive]:focus:ring-destructive`,r),n[3]=r,n[4]=a);let o;return n[5]!==i||n[6]!==t||n[7]!==a?(o=(0,Q.jsx)(Tr,{ref:t,className:a,...i}),n[5]=i,n[6]=t,n[7]=a,n[8]=o):o=n[8],o});$s.displayName=Tr.displayName;var ec=X.forwardRef((e,t)=>{let n=(0,Z.c)(10),r,i;n[0]===e?(r=n[1],i=n[2]):({className:r,...i}=e,n[0]=e,n[1]=r,n[2]=i);let a;n[3]===r?a=n[4]:(a=K(`absolute right-2 top-2 rounded-md p-1 text-foreground/50 opacity-0 transition-opacity hover:text-foreground focus:opacity-100 focus:outline-none focus:ring-2 group-hover:opacity-100 group-[.destructive]:text-red-300 group-[.destructive]:hover:text-red-50 group-[.destructive]:focus:ring-red-400 group-[.destructive]:focus:ring-offset-red-600`,r),n[3]=r,n[4]=a);let o;n[5]===Symbol.for(`react.memo_cache_sentinel`)?(o=(0,Q.jsx)(w,{className:`h-4 w-4`}),n[5]=o):o=n[5];let s;return n[6]!==i||n[7]!==t||n[8]!==a?(s=(0,Q.jsx)(kr,{ref:t,className:a,"toast-close":``,...i,children:o}),n[6]=i,n[7]=t,n[8]=a,n[9]=s):s=n[9],s});ec.displayName=kr.displayName;var tc=X.forwardRef((e,t)=>{let n=(0,Z.c)(9),r,i;n[0]===e?(r=n[1],i=n[2]):({className:r,...i}=e,n[0]=e,n[1]=r,n[2]=i);let a;n[3]===r?a=n[4]:(a=K(`text-sm font-semibold`,r),n[3]=r,n[4]=a);let o;return n[5]!==i||n[6]!==t||n[7]!==a?(o=(0,Q.jsx)(In,{ref:t,className:a,...i}),n[5]=i,n[6]=t,n[7]=a,n[8]=o):o=n[8],o});tc.displayName=In.displayName;var nc=X.forwardRef((e,t)=>{let n=(0,Z.c)(9),r,i;n[0]===e?(r=n[1],i=n[2]):({className:r,...i}=e,n[0]=e,n[1]=r,n[2]=i);let a;n[3]===r?a=n[4]:(a=K(`text-sm opacity-90`,r),n[3]=r,n[4]=a);let o;return n[5]!==i||n[6]!==t||n[7]!==a?(o=(0,Q.jsx)(sr,{ref:t,className:a,...i}),n[5]=i,n[6]=t,n[7]=a,n[8]=o):o=n[8],o});nc.displayName=sr.displayName;function rc(){let e=(0,Z.c)(5),{toasts:t}=di(),n;e[0]===t?n=e[1]:(n=t.map(ic),e[0]=t,e[1]=n);let r;e[2]===Symbol.for(`react.memo_cache_sentinel`)?(r=(0,Q.jsx)(Xs,{}),e[2]=r):r=e[2];let i;return e[3]===n?i=e[4]:(i=(0,Q.jsxs)(Ys,{children:[n,r]}),e[3]=n,e[4]=i),i}function ic(e){let{id:t,title:n,description:r,action:i,...a}=e;return(0,Q.jsxs)(Qs,{...a,children:[(0,Q.jsxs)(`div`,{className:`grid gap-1`,children:[n&&(0,Q.jsx)(tc,{children:n}),r&&(0,Q.jsx)(nc,{children:r})]}),i,(0,Q.jsx)(ec,{})]},t)}function ac(){let e=(0,Z.c)(4),{resolvedTheme:t,theme:n}=qr(),r,i;return e[0]!==t||e[1]!==n?(r=()=>{if(window.tarsk?.setNativeTheme){let e=n===`system`?`system`:t||`system`;window.tarsk.setNativeTheme(e)}},i=[t,n],e[0]=t,e[1]=n,e[2]=r,e[3]=i):(r=e[2],i=e[3]),(0,X.useEffect)(r,i),null}function oc(e){let t=(0,Z.c)(7),n,r;t[0]===e?(n=t[1],r=t[2]):({children:n,...r}=e,t[0]=e,t[1]=n,t[2]=r);let i;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(i=(0,Q.jsx)(ac,{}),t[3]=i):i=t[3];let a;return t[4]!==n||t[5]!==r?(a=(0,Q.jsxs)(Jr,{...r,children:[i,n]}),t[4]=n,t[5]=r,t[6]=a):a=t[6],a}function sc(){let{state:e,dispatch:t}=Ar(),{toast:n}=di(),r=Lr(`project-creation`).dispatch,[i,a]=(0,X.useState)(null),o=(0,X.useCallback)(async()=>{try{t({type:Y.SetProjectsLoading,projectsLoading:!0});let e=await ut();t({type:Y.SetProjects,projects:e.projects})}catch(e){console.error(`Failed to refresh projects:`,e)}finally{t({type:Y.SetProjectsLoading,projectsLoading:!1})}},[t]),s=(0,X.useCallback)(async(n,r)=>{try{await on(n,r)}catch(e){console.error(`Failed to select thread:`,e)}(e.selectedThreadId!==r||e.selectedProjectId!==n)&&t({type:Y.SelectThread,threadId:r,projectId:n})},[t,e.selectedThreadId,e.selectedProjectId]),c=(0,X.useCallback)(async e=>{t({type:Y.SetCreatingProject,isCreating:!0});try{let n=await e.apiCall();if(!n){t({type:Y.SetCreatingProject,isCreating:!1}),await o();return}let i=e.useTerminalDispatch?r:t;i({type:Y.ClearTerminalOutput}),i({type:Y.SetTerminalOpen,open:!0}),i({type:Y.AppendTerminalLine,line:{type:`system`,content:e.initialMessage}});let s=n.getReader(),c=new TextDecoder,l=``,u=null,d=!1,f=null,p=null;for(;;){let{done:n,value:r}=await s.read();if(n)break;l+=c.decode(r,{stream:!0});let o=l.split(`
|
|
28
|
+
`);l=o.pop()??``;for(let n of o){let r=n.trim();if(r)try{let n=JSON.parse(r);if(n.type===`progress`)!d&&n.threadId&&n.projectId&&(d=!0,f=n.projectId,p=n.threadId,t({type:Y.AddCreatingProject,projectId:n.projectId,threadId:n.threadId,projectName:e.optimisticProjectName,gitUrl:e.gitUrl??``}),t({type:Y.AddProcessingThread,threadId:n.threadId})),t({type:Y.AppendTerminalLine,...e.useTerminalDispatch?{threadId:p??`project-creation`}:{},line:{type:`output`,content:n.message}});else if(n.type===`complete`){if(n.project){u=n.project.id;let r=e.includeThreadPath&&n.project.threads?.length>0?`${n.project.path}/${n.project.threads[0]}`:n.project.path;i({type:Y.AppendTerminalLine,line:{type:`system`,content:`Project created successfully at: ${r}`}}),t({type:Y.SetTerminalOpen,open:!1}),e.handleSetupScript&&n.suggestedSetupScript&&a({projectId:n.project.id,command:n.suggestedSetupScript,remainingScripts:n.project.pendingSetupScripts??[]})}}else n.type===`error`&&(d&&f&&(t({type:Y.RemoveCreatingProject,projectId:f}),p&&t({type:Y.RemoveProcessingThread,threadId:p})),t({type:Y.AppendTerminalLine,...e.useTerminalDispatch?{threadId:p??`project-creation`}:{},line:{type:`error`,content:`Error: ${n.message}`}}))}catch(t){console.error(`Failed to parse ${e.logTag} event`,t)}}}t({type:Y.SetCreatingProject,isCreating:!1}),d&&p&&t({type:Y.RemoveProcessingThread,threadId:p}),N();let m=await ut();if(t({type:Y.SetProjects,projects:m.projects}),t({type:Y.SetProjectsLoading,projectsLoading:!1}),u){let e=m.projects.find(e=>e.projectId===u);if(e&&e.threads.length>0){let n=e.threads[0].threadId;t({type:Y.SelectThread,threadId:n,projectId:u,focusInput:!0})}}}catch(n){console.error(`Failed to ${e.logTag}:`,n),t({type:Y.SetCreatingProject,isCreating:!1}),(e.useTerminalDispatch?r:t)({type:Y.AppendTerminalLine,line:{type:`error`,content:`${e.catchErrorPrefix}: ${n instanceof Error?n.message:`Unknown error`}`}})}},[t,o,r]),l=(0,X.useCallback)(async(e,t)=>{let n=e.split(`/`).pop()?.replace(`.git`,``)??`project`;await c({apiCall:()=>me(e,t),initialMessage:`Cloning repository: ${e}...`,optimisticProjectName:n,gitUrl:e,useTerminalDispatch:!0,includeThreadPath:!0,handleSetupScript:!0,logTag:`create project`,catchErrorPrefix:`Failed to create project`})},[c]),u=(0,X.useCallback)(async(e,t,n)=>{await c({apiCall:()=>Ft(e,t,n),initialMessage:`Creating app "${e}"...`,optimisticProjectName:e,useTerminalDispatch:!1,handleSetupScript:!1,logTag:`create web app`,catchErrorPrefix:`Failed to create web app`})},[c]),d=(0,X.useCallback)(async(r,i)=>{try{let a=i??(()=>{let t=e.projects.find(e=>e.projectId===r)?.threads.map(e=>e.title)??[],n=/^thread-(\d+)$/i,i=0;for(let e of t){let t=e.match(n);t&&(i=Math.max(i,parseInt(t[1],10)))}return`thread-${i+1}`})(),s=await jt(r,i);if(!s){await o();return}let c=s.getReader(),l=new TextDecoder,u=``,d=!1,f=null,p=!0,m=[{type:`system`,content:`Creating thread "${a}"...`}];try{for(;;){let{done:e,value:i}=await c.read();if(e)break;u+=l.decode(i,{stream:!0});let o=u.split(`
|
|
29
|
+
`);u=o.pop()??``;for(let e of o){let i=e.trim();if(i)try{let e=JSON.parse(i);if(e.type===`progress`){if(!d&&e.threadId){d=!0,f=e.threadId,t({type:Y.AddCreatingThread,projectId:r,threadId:e.threadId,title:a}),t({type:Y.AddProcessingThread,threadId:e.threadId}),t({type:Y.ClearTerminalOutput,threadId:f});for(let e of m)t({type:Y.AppendTerminalLine,threadId:f,line:e});m.length=0}let n={type:`output`,content:e.message};f?t({type:Y.AppendTerminalLine,threadId:f,line:n}):m.push(n)}else if(e.type===`error`){d&&f&&(t({type:Y.RemoveCreatingThread,projectId:r,threadId:f}),t({type:Y.RemoveProcessingThread,threadId:f}));let i={type:`error`,content:`Error: ${e.message}`};f?t({type:Y.AppendTerminalLine,threadId:f,line:i}):m.push(i),console.error(`Thread creation error:`,e.message),n({title:`Thread Creation Failed`,description:e.message,variant:`destructive`}),p=!1}}catch(e){console.error(`Failed to parse thread event`,e)}}}d&&f&&t({type:Y.RemoveProcessingThread,threadId:f}),N(),await o(),f&&p&&t({type:Y.SelectThread,threadId:f,projectId:r,focusInput:!0})}catch(e){throw d&&f&&(t({type:Y.RemoveCreatingThread,projectId:r,threadId:f}),t({type:Y.RemoveProcessingThread,threadId:f})),n({title:`Thread Creation Failed`,description:e instanceof Error?e.message:String(e),variant:`destructive`}),e}}catch(e){console.error(`Failed to create thread:`,e);let r=`Failed to create thread: ${e instanceof Error?e.message:`Unknown error`}`;throw t({type:Y.AppendTerminalLine,line:{type:`error`,content:r}}),n({variant:`destructive`,title:`Thread Creation Failed`,description:r}),e}},[o,t,e.projects,n]),f=(0,X.useCallback)(async(n,r)=>{t({type:Y.AddDeletingThread,threadId:r});try{await Te(n,r),N(),await o(),e.selectedThreadId===r&&t({type:Y.SelectThread,threadId:``,projectId:``})}catch(e){console.error(`Failed to delete thread:`,e)}finally{t({type:Y.RemoveDeletingThread,threadId:r})}},[o,e.selectedThreadId,t]),p=(0,X.useCallback)(async n=>{t({type:Y.AddDeletingProject,projectId:n});let r=e.projects.find(e=>e.projectId===n)?.threads.map(e=>e.threadId)??[];for(let e of r)t({type:Y.AddDeletingThread,threadId:e});try{await P(n),await o(),e.selectedProjectId===n&&t({type:Y.SelectThread,threadId:``,projectId:``})}catch(e){console.error(`Failed to delete project:`,e)}finally{t({type:Y.RemoveDeletingProject,projectId:n});for(let e of r)t({type:Y.RemoveDeletingThread,threadId:e})}},[o,e.selectedProjectId,e.projects,t]),m=(0,X.useCallback)(async e=>{let n=i;if(a(null),!n||!e)return;let{projectId:r,command:s,remainingScripts:c}=n,l=[s,...c||[]];try{t({type:Y.SetCreatingProject,isCreating:!0}),t({type:Y.SetTerminalOpen,open:!0}),t({type:Y.AppendTerminalLine,line:{type:`system`,content:`Installing dependencies for ${l.length} package${l.length===1?``:`s`}...`}});for(let e=0;e<l.length;e++){let n=l[e],i=n.match(/^cd "([^"]+)" && (.+)$/),a=i?i[1]:`root`;t({type:Y.AppendTerminalLine,line:{type:`system`,content:`Installing package ${e+1}/${l.length} in ${a}...`}}),t({type:Y.AppendTerminalLine,line:{type:`output`,content:`📦 Installing dependencies in ${a}: ${n}`}});let o=await Dt(r,n,!0);if(o){let e=o.getReader(),n=new TextDecoder,r=``;for(;;){let{done:i,value:a}=await e.read();if(i)break;r+=n.decode(a,{stream:!0});let o=r.split(`
|
|
30
|
+
`);r=o.pop()??``;for(let e of o)if(e.trim())try{let n=JSON.parse(e);typeof n==`string`?t({type:Y.AppendTerminalLine,line:{type:`output`,content:n}}):n.type===`error`&&t({type:Y.AppendTerminalLine,line:{type:`error`,content:n.message}})}catch{t({type:Y.AppendTerminalLine,line:{type:`output`,content:e}})}}if(r.trim())try{let e=JSON.parse(r);typeof e==`string`?t({type:Y.AppendTerminalLine,line:{type:`output`,content:e}}):e.type===`error`&&t({type:Y.AppendTerminalLine,line:{type:`error`,content:e.message}})}catch{t({type:Y.AppendTerminalLine,line:{type:`output`,content:r}})}}e<l.length-1&&(t({type:Y.AppendTerminalLine,line:{type:`system`,content:``}}),t({type:Y.AppendTerminalLine,line:{type:`system`,content:`---`}}),t({type:Y.AppendTerminalLine,line:{type:`system`,content:``}}))}t({type:Y.AppendTerminalLine,line:{type:`system`,content:`All dependencies installed successfully!`}}),t({type:Y.SetCreatingProject,isCreating:!1}),await o()}catch(e){t({type:Y.SetCreatingProject,isCreating:!1}),console.error(`Failed to run setup script:`,e),t({type:Y.AppendTerminalLine,line:{type:`error`,content:`Failed to run setup script: ${e instanceof Error?e.message:`Unknown error`}`}})}},[i,t,o]);(0,X.useEffect)(()=>{let n=!0;async function r(){try{t({type:Y.SetProjectsLoading,projectsLoading:!0});let r=await ut();if(!n)return;if(t({type:Y.SetProjects,projects:r.projects}),!e.selectedThreadId)for(let e of r.projects){let n=e.threads.find(e=>e.isSelected);if(n){t({type:Y.SelectThread,threadId:n.threadId,projectId:e.projectId});break}}}catch(e){console.error(`Failed to load projects:`,e)}finally{n&&t({type:Y.SetProjectsLoading,projectsLoading:!1})}}return r(),()=>{n=!1}},[t,e.selectedThreadId,e.configUpdatedAt]);let h=(0,X.useCallback)(async()=>{await c({apiCall:A,initialMessage:`Opening folder...`,optimisticProjectName:`Opening folder...`,useTerminalDispatch:!0,handleSetupScript:!0,logTag:`open folder`,catchErrorPrefix:`Failed to open folder`})},[c]);return{projects:e.projects,selectedProjectId:e.selectedProjectId,selectedThreadId:e.selectedThreadId,refreshProjects:o,handleSelectThread:s,handleCreateProject:l,handleCreateWebApp:u,handleOpenFolder:h,handleCreateThread:d,handleDeleteThread:f,confirmDeleteProject:p,pendingSetupScriptConfirmation:i,resolveSetupScriptConfirmation:m}}function cc(){let e=(0,Z.c)(2),[t,n]=(0,X.useState)(lc),r,i;return e[0]===Symbol.for(`react.memo_cache_sentinel`)?(r=()=>{let e=()=>n(!0),t=()=>n(!1);return window.addEventListener(`focus`,e),window.addEventListener(`blur`,t),()=>{window.removeEventListener(`focus`,e),window.removeEventListener(`blur`,t)}},i=[],e[0]=r,e[1]=i):(r=e[0],i=e[1]),(0,X.useEffect)(r,i),t}function lc(){return document.hasFocus()}var uc=null;function dc(){uc??=new Audio(`/pop.wav`),uc.currentTime=0,uc.play().catch(e=>{console.debug(`Could not play completion sound:`,e)})}function fc(){let{state:e,dispatch:t}=Ar(),n=cc(),r=(0,X.useRef)(null),i=(0,X.useRef)(!1),a=(0,X.useRef)([]),o=(0,X.useRef)(e),s=(0,X.useRef)(n);(0,X.useEffect)(()=>{o.current=e},[e]),(0,X.useEffect)(()=>{s.current=n},[n]);let c=(0,X.useCallback)(async()=>{try{let e=await rt(),n=a.current.filter(t=>!e.includes(t));for(let e of n)e!==o.current.selectedThreadId&&t({type:Y.MarkThreadCompleted,threadId:e});return n.length>0&&!s.current&&dc(),a.current=e,t({type:Y.SetProcessingThreads,threadIds:e}),e}catch(e){return console.error(`Failed to fetch processing threads:`,e),[]}},[t]);(0,X.useEffect)(()=>{let e=()=>{if(r.current||i.current)return;i.current=!0;let e=async()=>{(await c()).length>0||o.current.isStreaming||o.current.isCreatingProject?r.current=setTimeout(e,1e3):(r.current=null,i.current=!1)};e()},t=()=>{r.current&&=(clearTimeout(r.current),null),i.current=!1};return e(),()=>{t()}},[e.isStreaming,e.isCreatingProject,c]);let l=(0,X.useCallback)(e=>{t({type:Y.ClearThreadCompleted,threadId:e})},[t]);return{processingThreadIds:e.processingThreadIds,completedThreadIds:e.completedThreadIds,isThreadProcessing:t=>e.processingThreadIds.includes(t),isThreadCompleted:t=>e.completedThreadIds.includes(t),clearCompleted:l}}var pc=768;function mc(){let e=(0,Z.c)(2),[t,n]=X.useState(void 0),r,i;return e[0]===Symbol.for(`react.memo_cache_sentinel`)?(r=()=>{let e=window.matchMedia(`(max-width: ${pc-1}px)`),t=()=>{n(window.innerWidth<pc)};return e.addEventListener(`change`,t),n(window.innerWidth<pc),()=>e.removeEventListener(`change`,t)},i=[],e[0]=r,e[1]=i):(r=e[0],i=e[1]),X.useEffect(r,i),!!t}var hc=(0,X.lazy)(()=>ar(()=>import(`./terminal-panel-Zyr6xth3.js`).then(e=>({default:e.TerminalPanel})),__vite__mapDeps([13,1,0,11]))),gc=(0,X.lazy)(()=>ar(()=>import(`./todos-view-yiH-gaUK.js`).then(e=>({default:e.TodosView})),__vite__mapDeps([14,4,1,5,0,6,7,11]))),_c=(0,X.lazy)(()=>ar(()=>import(`./diff-view-C-Kz7R_T.js`),__vite__mapDeps([8,1,4,5,0,6,9,10,7,11,12]))),vc=(0,X.lazy)(()=>ar(()=>import(`./explorer-tab-view-DC8arYcw.js`),__vite__mapDeps([15,1,4,5,0,6,11]))),yc=(0,X.lazy)(()=>ar(()=>import(`./browser-tab-BdzIB5R4.js`).then(e=>({default:e.BrowserTab})),__vite__mapDeps([16,1,0]))),bc=(0,X.lazy)(()=>ar(()=>import(`./dialogs-config-Ofxg1Bn0.js`).then(e=>e.t),__vite__mapDeps([0,1]))),xc=(0,X.lazy)(()=>ar(()=>import(`./onboarding-dialog-BQvu_Nac.js`),__vite__mapDeps([17,5,1,0,9]))),Sc=(0,X.lazy)(()=>ar(()=>import(`./conversation-history-view-C6iUsZjA.js`),__vite__mapDeps([18,5,1,0]))),Cc=(0,X.lazy)(()=>ar(()=>import(`./settings-view-D6FAPBQP.js`),__vite__mapDeps([19,1,4,5,0,6])));function wc(){let{state:e,dispatch:t}=Ar(),n=fr(),r=_r(),i=mc(),{projects:a,handleSelectThread:o,handleCreateProject:s,handleCreateWebApp:c,handleOpenFolder:l,handleCreateThread:u,handleDeleteThread:d,confirmDeleteProject:f,refreshProjects:p,pendingSetupScriptConfirmation:m,resolveSetupScriptConfirmation:h}=sc(),{processingThreadIds:g,completedThreadIds:_,clearCompleted:v}=fc(),[y,b]=(0,X.useState)(`chat`),[x,S]=(0,X.useState)(null),[C,w]=(0,X.useState)(!1),[T,E]=(0,X.useState)(null),[D,O]=(0,X.useState)(0),[k,A]=(0,X.useState)(null),{terminalState:j}=Lr(e.selectedThreadId),M=(0,X.useRef)(null);(0,X.useEffect)(()=>{j.open&&e.selectedThreadId===M.current&&b(`terminal`),M.current=e.selectedThreadId},[j.open,e.selectedThreadId]);let[N,P]=(0,X.useState)(!1),[F,I]=(0,X.useState)(!1),[L,R]=(0,X.useState)(!1),[z,B]=(0,X.useState)(null),[V,ee]=(0,X.useState)(!1),[H,te]=(0,X.useState)(!1),ne=(0,X.useRef)(null),re=r.pathname.startsWith(`/settings`),U=r.pathname===`/review`,W=r.pathname===`/todos`;(0,X.useEffect)(()=>{r.pathname===`/`&&y===`tasks`&&b(`chat`)},[r.pathname]);let ie=(0,X.useRef)(null);(0,X.useEffect)(()=>{let n=re||U||W;if(n&&ie.current===null)ie.current=e.sidebarOpen,e.sidebarOpen&&t({type:Y.ToggleSidebar});else if(!n&&ie.current!==null){let n=ie.current;ie.current=null,n&&!e.sidebarOpen&&t({type:Y.ToggleSidebar})}},[re,U,W]),(0,X.useEffect)(()=>{(async()=>{try{(await Ae()).updateAvailable&&ee(!0)}catch{}})()},[]);let ae=(0,X.useCallback)(async()=>{te(!0);try{await Cn()}catch{te(!1)}},[]);(0,X.useEffect)(()=>{L||(async()=>{try{(await hn()).onboardingCompleted||I(!0)}catch(e){console.error(`Failed to check onboarding status:`,e)}finally{R(!0)}})()},[L]),(0,X.useEffect)(()=>{F||t({type:Y.ConfigUpdated})},[F,t]);let oe=(0,X.useCallback)(e=>{let t=a.find(t=>t.projectId===e);t&&B({id:t.projectId,name:Le(t)})},[a]),se=(0,X.useCallback)(e=>{u(e,void 0)},[u]),ce=(0,X.useCallback)(async(a,s)=>{v(s),r.pathname!==`/`&&n(`/`),b(`chat`),await o(a,s),i&&e.sidebarOpen&&t({type:Y.ToggleSidebar})},[o,i,e.sidebarOpen,t,v,r.pathname,n]);(0,X.useEffect)(()=>{e.sidebarOpen?ne.current?.expand():ne.current?.collapse()},[e.sidebarOpen]);let le={activeMainTab:y,setActiveMainTab:b,devServerUrl:x,setDevServerUrl:S,terminalNotification:C,setTerminalNotification:w,pendingExplorerPath:T,setPendingExplorerPath:E,explorerRefreshTick:D,triggerExplorerRefresh:()=>O(e=>e+1),explorerClearPath:k,setExplorerClearPath:A};return(0,Q.jsx)(hs.Provider,{value:le,children:(0,Q.jsxs)(Wr,{delayDuration:200,children:[(0,Q.jsxs)(Ks,{direction:`horizontal`,className:`h-screen bg-background`,children:[(0,Q.jsx)(qs,{ref:ne,defaultSize:i?100:25,minSize:i?50:12,maxSize:i?100:32,collapsible:!0,collapsedSize:0,className:`border-r border-transparent`,children:(0,Q.jsx)(`div`,{className:`h-full overflow-hidden`,children:(0,Q.jsx)(ki,{projects:a,selectedThreadId:e.selectedThreadId,selectedProjectId:e.selectedProjectId,processingThreadIds:g,completedThreadIds:_,deletingThreadIds:e.deletingThreadIds,deletingProjectIds:e.deletingProjectIds,onSelectThread:ce,onCreateProject:()=>P(!0),onCreateThread:se,onDeleteThread:d,onDeleteProject:oe,onNavigateToSettings:()=>void n(`/settings/providers`),onDeselect:()=>t({type:Y.ClearSelection}),updateAvailable:V,updatingApp:H,onUpdateApp:ae,onRefreshProjects:p})})}),!i&&(0,Q.jsx)(Js,{withHandle:!0,className:e.sidebarOpen?`ml-[-40px]`:``}),(0,Q.jsx)(qs,{minSize:40,className:`overflow-hidden ${i&&e.sidebarOpen?`hidden`:``}`,children:(0,Q.jsxs)(`div`,{className:`flex h-full flex-col overflow-hidden`,children:[!U&&!re&&!W&&(0,Q.jsx)(Bs,{}),!U&&!re&&!W&&e.selectedThreadId&&(0,Q.jsx)(`div`,{className:`flex border-b border-border shrink-0`,children:[`Chat`,`Explorer`,`Review`,`Browser`,`Terminal`,`Tasks`,`History`].map(e=>{let t=e.toLowerCase();return(0,Q.jsxs)(`button`,{onClick:()=>{b(t),t===`terminal`&&w(!1)},className:`relative px-4 py-2 text-sm font-medium transition-colors ${y===t?`border-b-2 border-primary text-foreground -mb-px`:`text-muted-foreground hover:text-foreground`}`,children:[e,t===`terminal`&&C&&y!==`terminal`&&(0,Q.jsx)(`span`,{className:`absolute top-1.5 right-1 h-1.5 w-1.5 rounded-full bg-brand`})]},t)})}),(0,Q.jsx)(`main`,{className:`flex-1 overflow-hidden${!U&&!re&&!W&&y!==`chat`?` hidden`:``}`,children:(0,Q.jsxs)(br,{children:[(0,Q.jsx)(dr,{path:`/settings/:tab?`,element:(0,Q.jsx)(X.Suspense,{fallback:null,children:(0,Q.jsx)(Cc,{})})}),(0,Q.jsx)(dr,{path:`/settings/project/:projectId`,element:(0,Q.jsx)(X.Suspense,{fallback:null,children:(0,Q.jsx)(Cc,{})})}),(0,Q.jsx)(dr,{path:`/settings/add-skill`,element:(0,Q.jsx)(X.Suspense,{fallback:null,children:(0,Q.jsx)(Cc,{})})}),(0,Q.jsx)(dr,{path:`/settings/add-command`,element:(0,Q.jsx)(X.Suspense,{fallback:null,children:(0,Q.jsx)(Cc,{})})}),(0,Q.jsx)(dr,{path:`/settings/mcp-server-edit`,element:(0,Q.jsx)(X.Suspense,{fallback:null,children:(0,Q.jsx)(Cc,{})})}),(0,Q.jsx)(dr,{path:`*`,element:(0,Q.jsx)(To,{onCreateThread:se})})]})}),(0,Q.jsx)(`div`,{className:`flex-1 overflow-hidden${y===`terminal`&&!U&&!re&&!W?``:` hidden`}`,children:(0,Q.jsx)(X.Suspense,{fallback:null,children:(0,Q.jsx)(hc,{})})}),(0,Q.jsx)(`div`,{className:`flex-1 overflow-hidden${y===`browser`&&!U&&!re&&!W?``:` hidden`}`,children:(0,Q.jsx)(X.Suspense,{fallback:null,children:(0,Q.jsx)(yc,{})})}),!U&&!re&&!W&&y!==`chat`&&y!==`terminal`&&y!==`browser`&&(y===`explorer`?(0,Q.jsx)(X.Suspense,{fallback:null,children:(0,Q.jsx)(vc,{})}):y===`tasks`&&e.selectedProjectId?(0,Q.jsx)(X.Suspense,{fallback:null,children:(0,Q.jsx)(gc,{projectId:e.selectedProjectId})}):y===`history`?(0,Q.jsx)(X.Suspense,{fallback:null,children:(0,Q.jsx)(Sc,{isOpen:!0,onClose:()=>b(`chat`),initialFilter:e.selectedProjectId?{type:`project`,id:e.selectedProjectId}:void 0,projects:a,inline:!0})}):y===`review`&&e.selectedThreadId?(0,Q.jsx)(X.Suspense,{fallback:null,children:(0,Q.jsx)(_c,{threadId:e.selectedThreadId,onExit:()=>b(`chat`)})}):(0,Q.jsx)(`div`,{className:`flex-1 overflow-hidden`}))]})}),(0,Q.jsx)(X.Suspense,{fallback:null,children:(0,Q.jsx)(bc,{open:N,onOpenChange:P,onSubmitClone:s,onSubmitWebApp:c,onOpenFolder:l})}),(0,Q.jsx)(Vs,{open:z!==null,projectName:z?.name,onOpenChange:e=>!e&&B(null),onConfirm:()=>{z&&(f(z.id),B(null))}}),(0,Q.jsx)(Hs,{open:m!==null,setupScripts:m?[m.command,...m.remainingScripts||[]]:[],onConfirm:h}),(0,Q.jsx)(X.Suspense,{fallback:null,children:(0,Q.jsx)(xc,{open:F,onOpenChange:I,onComplete:()=>{R(!0),p()}})}),(0,Q.jsx)(Ws,{})]}),(0,Q.jsx)(rc,{})]})})}function Tc(){let e=(0,Z.c)(5),[t,n]=(0,X.useReducer)(zr,Pr),r;e[0]===t?r=e[1]:(r={state:t,dispatch:n},e[0]=t,e[1]=r);let i;e[2]===Symbol.for(`react.memo_cache_sentinel`)?(i=(0,Q.jsx)(wc,{}),e[2]=i):i=e[2];let a;return e[3]===r?a=e[4]:(a=(0,Q.jsx)(oc,{attribute:`class`,defaultTheme:`system`,enableSystem:!0,storageKey:`tarsk-theme`,children:(0,Q.jsx)(Ir.Provider,{value:r,children:i})}),e[3]=r,e[4]=a),a}var Ec=!1;window.addEventListener(`resize`,()=>{Ec||=(window.__electrobunWebviewId&&(document.body.style.height=`calc(100% - 26px)`),!0)}),(0,Zr.createRoot)(document.getElementById(`root`)).render((0,Q.jsx)(X.StrictMode,{children:(0,Q.jsx)(lr,{children:(0,Q.jsx)(Tc,{})})}));export{Si as _,Is as a,$ as b,gs as c,lo as d,Ei as f,vi as g,wi as h,Ns as i,Do as l,Ci as m,qs as n,Ps as o,hi as p,Ks as r,Fs as s,Js as t,So as u,xi as v,ei as x,mi as y};
|