tarsk 0.4.8 → 0.4.10

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.
Files changed (59) hide show
  1. package/dist/index.js +272 -164
  2. package/dist/public/assets/account-view-D1x7ZeLs.js +1 -0
  3. package/dist/public/assets/add-agent-view-Ctbm0EgW.js +1 -0
  4. package/dist/public/assets/add-rule-view-xKAYGOl5.js +7 -0
  5. package/dist/public/assets/add-skill-view-D63xCrVn.js +1 -0
  6. package/dist/public/assets/add-slash-command-view-paJjkCml.js +1 -0
  7. package/dist/public/assets/browser-tab-CWkk3b20.js +1 -0
  8. package/dist/public/assets/conversation-history-view-BdJJ-7zE.js +1 -0
  9. package/dist/public/assets/{dialogs-config-DiFQjCeA.js → dialogs-config-CB7G-sX6.js} +13 -13
  10. package/dist/public/assets/diff-view-kPjfhf7_.js +3 -0
  11. package/dist/public/assets/file-tree-sidebar-D58ROyfi.js +1 -0
  12. package/dist/public/assets/files-tab-view-DhnLTfaB.js +2 -0
  13. package/dist/public/assets/files-view-C1vg37wD.js +1 -0
  14. package/dist/public/assets/history-view-D-hEB6Qt.js +1 -0
  15. package/dist/public/assets/index-D7yQjYyf.js +16 -0
  16. package/dist/public/assets/index-DVHw8RF4.css +1 -0
  17. package/dist/public/assets/mcp-manager-J9VCn8-1.js +1 -0
  18. package/dist/public/assets/{mcp-server-edit-view-BAwMNOAH.js → mcp-server-edit-view-yd_q5UVd.js} +3 -3
  19. package/dist/public/assets/mcp-servers-sidebar-Bwg40dY8.js +1 -0
  20. package/dist/public/assets/mcp-view-BYzQiRVC.js +1 -0
  21. package/dist/public/assets/onboarding-CxK4aR2J.js +1 -0
  22. package/dist/public/assets/onboarding-dialog-DX7DCkK0.js +1 -0
  23. package/dist/public/assets/project-settings-view-CkAqtfjP.js +1 -0
  24. package/dist/public/assets/provider-details-view-CzsPzv6h.js +1 -0
  25. package/dist/public/assets/{providers-sidebar-C4MF6i9d.js → providers-sidebar-BokZx2tk.js} +1 -1
  26. package/dist/public/assets/radio-group-BpmnaKJk.js +1 -0
  27. package/dist/public/assets/react-vendor-CR4cAsbx.js +17 -0
  28. package/dist/public/assets/settings-view-CoL0k8nt.js +2 -0
  29. package/dist/public/assets/side-panel-resizer-CVC2NC75.js +1 -0
  30. package/dist/public/assets/store-CxlaVYZ6.js +2 -0
  31. package/dist/public/assets/terminal-panel-Bv2hLEfW.js +2 -0
  32. package/dist/public/assets/todos-view-FJ5GkG21.js +1 -0
  33. package/dist/public/assets/{utils-DY_quHB8.js → utils-DVGxCyLB.js} +1 -1
  34. package/dist/public/index.html +9 -10
  35. package/package.json +1 -1
  36. package/dist/public/assets/add-agent-view-B9IQjAwU.js +0 -1
  37. package/dist/public/assets/add-rule-view-BdZHurB3.js +0 -7
  38. package/dist/public/assets/add-skill-view-Cuu6Z0fr.js +0 -1
  39. package/dist/public/assets/add-slash-command-view-uW75Jvbh.js +0 -1
  40. package/dist/public/assets/conversation-history-view-D0OBxJMC.js +0 -1
  41. package/dist/public/assets/diff-view-B5XBM5UZ.js +0 -3
  42. package/dist/public/assets/file-tree-sidebar-DMX7fHi7.js +0 -1
  43. package/dist/public/assets/files-view-CUZn7G0o.js +0 -1
  44. package/dist/public/assets/history-view-B8HM78Wa.js +0 -1
  45. package/dist/public/assets/index-C-p81QYw.js +0 -17
  46. package/dist/public/assets/index-DhVMb7D6.css +0 -1
  47. package/dist/public/assets/mcp-manager-CEm1L3dn.js +0 -1
  48. package/dist/public/assets/mcp-servers-sidebar-Ncxq9Oj5.js +0 -1
  49. package/dist/public/assets/mcp-view-Cz7nelGQ.js +0 -1
  50. package/dist/public/assets/onboarding-CvpvkF3X.js +0 -1
  51. package/dist/public/assets/onboarding-dialog-CKJw0ULj.js +0 -1
  52. package/dist/public/assets/project-settings-view-DJ1uvrTL.js +0 -1
  53. package/dist/public/assets/provider-details-view-CkS6WbnK.js +0 -1
  54. package/dist/public/assets/radio-group-BItFbSTw.js +0 -1
  55. package/dist/public/assets/react-vendor-DkKo9QGO.js +0 -17
  56. package/dist/public/assets/settings-view-C45kmAGH.js +0 -2
  57. package/dist/public/assets/store-BVVGurzl.js +0 -2
  58. package/dist/public/assets/use-toast-DEJkXPN4.js +0 -1
  59. /package/dist/public/assets/{monaco-DvsnxTfD.js → monaco-Cp3BWanQ.js} +0 -0
@@ -0,0 +1,16 @@
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/dialogs-config-CB7G-sX6.js","assets/rolldown-runtime-Dw2cE7zH.js","assets/account-view-D1x7ZeLs.js","assets/project-settings-view-CkAqtfjP.js","assets/react-vendor-CR4cAsbx.js","assets/history-view-D-hEB6Qt.js","assets/monaco-Cp3BWanQ.js","assets/diff-view-kPjfhf7_.js","assets/onboarding-CxK4aR2J.js","assets/side-panel-resizer-CVC2NC75.js","assets/store-CxlaVYZ6.js","assets/utils-DVGxCyLB.js","assets/terminal-panel-Bv2hLEfW.js","assets/todos-view-FJ5GkG21.js","assets/files-tab-view-DhnLTfaB.js","assets/browser-tab-CWkk3b20.js","assets/onboarding-dialog-DX7DCkK0.js","assets/conversation-history-view-BdJJ-7zE.js","assets/settings-view-CoL0k8nt.js"])))=>i.map(i=>d[i]);
2
+ import{r as e}from"./rolldown-runtime-Dw2cE7zH.js";import{$ as t,$r as n,A as r,Ai as i,Ar as a,At as o,B as s,Br as c,Bt as l,C as u,Ci as d,Cn as f,Cr as p,Ct as m,Di as h,Dr as g,Dt as _,E as v,Ei as y,Er as b,Et as x,F as S,Ft as C,Gr as w,Gt as T,H as E,Hr as D,Ir as O,It as k,J as A,Jr as j,Jt as M,Kr as N,Kt as P,Lr as F,Lt as I,M as L,Mi as R,Mr as z,Mt as B,N as V,Nr as H,Nt as U,O as ee,Oi as W,Ot as G,Pi as te,Pr as ne,Pt as re,Q as ie,Qr as ae,R as oe,Rr as se,S as ce,Sr as le,St as ue,T as de,Ti as K,Tn as fe,Tr as pe,Tt as me,Ur as he,V as ge,Vr as _e,Wt as ve,Xr as ye,Xt as be,Y as xe,Yr as Se,Yt as Ce,Z as we,_ as Te,_i as Ee,_n as De,_r as Oe,_t as ke,an as Ae,ar as je,at as Me,b as Ne,bi as Pe,bn as Fe,br as Ie,c as Le,cn as Re,cr as ze,ct as Be,dn as q,dr as Ve,dt as He,en as Ue,er as We,et as Ge,fi as Ke,fn as qe,fr as Je,g as Ye,gi as Xe,gn as Ze,gr as Qe,h as $e,hi as et,hn as tt,ii as nt,in as rt,ir as it,it as at,j as ot,jr as st,jt as ct,kt as lt,l as ut,lr as dt,lt as ft,mn as pt,mr as mt,mt as ht,ni as gt,nn as _t,nt as vt,oi as yt,on as bt,or as xt,pi as St,pn as Ct,pr as wt,pt as Tt,qr as Et,qt as Dt,ri as Ot,si as kt,sn as At,sr as jt,st as Mt,ti as Nt,tn as Pt,u as Ft,ui as It,ur as Lt,v as Rt,vi as zt,vn as Bt,vr as Vt,vt as Ht,wi as Ut,wn as Wt,wr as Gt,wt as Kt,x as qt,xi as Jt,xn as J,xt as Yt,y as Xt,yi as Zt,yn as Qt,yr as $t}from"./dialogs-config-CB7G-sX6.js";import{$ as en,A as tn,B as nn,C as rn,D as an,E as on,F as sn,H as cn,I as ln,J as un,K as dn,L as fn,M as pn,N as mn,O as hn,P as gn,R as _n,S as vn,U as yn,V as bn,W as xn,X as Sn,Y as Cn,_ as wn,c as Tn,d as En,et as Dn,f as On,g as kn,h as An,j as jn,l as Mn,m as Nn,p as Pn,q as Fn,u as In,v as Ln,w as Rn,x as zn,y as Bn,z as Vn}from"./react-vendor-CR4cAsbx.js";import{a as Hn,c as Un,d as Wn,f as Gn,i as Kn,l as qn,n as Jn,o as Yn,p as Xn,r as Zn,s as Qn,t as Y,u as $n}from"./store-CxlaVYZ6.js";import{c as er,l as tr,s as nr,u as rr}from"./history-view-D-hEB6Qt.js";import{n as ir,t as ar}from"./utils-DVGxCyLB.js";import{n as or,r as sr}from"./onboarding-CxK4aR2J.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 cr=Dn(),X=R(),Z=e(te(),1),Q=We();function lr(e){let t=(0,X.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)(lr,{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 ur(e){let t=(0,X.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,Z.useState)(d),[m,h]=(0,Z.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=J(`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)(lr,{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 dr=Z.forwardRef((e,t)=>{let n=(0,X.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?pt:`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=J(`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});dr.displayName=`StandardListItem`;var fr=yn,pr=cn,mr=Z.forwardRef((e,t)=>{let n=(0,X.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=J(`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)(bn,{className:a,...i,ref:t}),n[5]=i,n[6]=t,n[7]=a,n[8]=o):o=n[8],o});mr.displayName=bn.displayName;var hr=Z.forwardRef((e,t)=>{let n=(0,X.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)(mr,{}),n[3]=a):a=n[3];let o;n[4]===r?o=n[5]:(o=J(`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)(pr,{children:[a,(0,Q.jsx)(Vn,{ref:t,className:o,...i})]}),n[6]=i,n[7]=t,n[8]=o,n[9]=s):s=n[9],s});hr.displayName=Vn.displayName;var gr=e=>{let t=(0,X.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=J(`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};gr.displayName=`AlertDialogHeader`;var _r=e=>{let t=(0,X.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=J(`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};_r.displayName=`AlertDialogFooter`;var vr=Z.forwardRef((e,t)=>{let n=(0,X.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=J(`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)(xn,{ref:t,className:a,...i}),n[5]=i,n[6]=t,n[7]=a,n[8]=o):o=n[8],o});vr.displayName=xn.displayName;var yr=Z.forwardRef((e,t)=>{let n=(0,X.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=J(`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)(nn,{ref:t,className:a,...i}),n[5]=i,n[6]=t,n[7]=a,n[8]=o):o=n[8],o});yr.displayName=nn.displayName;var br=Z.forwardRef((e,t)=>{let n=(0,X.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=J(qe(),r),n[3]=r,n[4]=a);let o;return n[5]!==i||n[6]!==t||n[7]!==a?(o=(0,Q.jsx)(fn,{ref:t,className:a,...i}),n[5]=i,n[6]=t,n[7]=a,n[8]=o):o=n[8],o});br.displayName=fn.displayName;var xr=Z.forwardRef((e,t)=>{let n=(0,X.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=J(qe({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)(_n,{ref:t,className:a,...i}),n[5]=i,n[6]=t,n[7]=a,n[8]=o):o=n[8],o});xr.displayName=_n.displayName;function Sr(){let e=(0,X.c)(8),{theme:t,setTheme:n}=ir(),r;e[0]!==n||e[1]!==t?(r=()=>n(t===`dark`?`light`:`dark`),e[0]=n,e[1]=t,e[2]=r):r=e[2];let i,a,o;e[3]===Symbol.for(`react.memo_cache_sentinel`)?(i=(0,Q.jsx)(mt,{className:`h-[1.2rem] w-[1.2rem] rotate-0 scale-100 transition-all dark:-rotate-90 dark:scale-0`}),a=(0,Q.jsx)(ne,{className:`absolute h-[1.2rem] w-[1.2rem] rotate-90 scale-0 transition-all dark:rotate-0 dark:scale-100`}),o=(0,Q.jsx)(`span`,{className:`sr-only`,children:`Toggle theme`}),e[3]=i,e[4]=a,e[5]=o):(i=e[3],a=e[4],o=e[5]);let s;return e[6]===r?s=e[7]:(s=(0,Q.jsxs)(q,{variant:`ghost`,size:`icon`,className:`h-8 w-8 text-sidebar-foreground`,onClick:r,children:[i,a,o]}),e[6]=r,e[7]=s),s}function Cr({children:e,collapsed:t,title:n,onTitleClose:r,subtitle:i,headerAction:a,footer:o,onResetOnboarding:s,onLogoClick:c}){let l=(0,Z.useRef)(0),u=(0,Z.useRef)(null);return(0,Z.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 en(async()=>{let{resetOnboarding:e}=await import(`./dialogs-config-CB7G-sX6.js`).then(e=>e.w);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)(Jt,{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)(xt,{className:`h-4 w-4`}),(0,Q.jsx)(`span`,{className:`sr-only`,children:`Close`})]})]})]}),(0,Q.jsx)(Re,{className:`flex-1`,children:e}),o&&(0,Q.jsx)(`div`,{className:`border-t border-sidebar-border`,children:o})]})}var wr=(0,Z.lazy)(()=>en(()=>import(`./account-view-D1x7ZeLs.js`),__vite__mapDeps([2,1,0]))),Tr=(0,Z.lazy)(()=>en(()=>import(`./project-settings-view-CkAqtfjP.js`),__vite__mapDeps([3,1,4,5,0,6])));function Er(e){let t=(0,X.c)(65),{projects:n,selectedThreadId:r,selectedProjectId:i,processingThreadIds:a,completedThreadIds:o,deletingThreadIds:s,deletingProjectIds:c,onSelectThread:l,onCreateProject:u,onCreateThread:d,onDeleteThread:p,onDeleteProject:m,onNavigateToSettings:h,onDeselect:g,collapsed:_,updateAvailable:v,updatingApp:y,onUpdateApp:b,onRefreshProjects:x}=e,[S,C]=(0,Z.useState)(!1),[w,T]=(0,Z.useState)(null),E;t[0]===n?E=t[1]:(E=n.map(Dr),t[0]=n,t[1]=E);let D=E,O;t[2]!==_||t[3]!==u?(O=!_&&(0,Q.jsxs)(q,{variant:`outline`,size:`sm`,className:`gap-2`,onClick:u,children:[(0,Q.jsx)(Gt,{className:`h-4 w-4 shrink-0`}),(0,Q.jsx)(`span`,{className:`truncate`,children:`New Project`})]}),t[2]=_,t[3]=u,t[4]=O):O=t[4];let k;t[5]!==_||t[6]!==b||t[7]!==v||t[8]!==y?(k=v&&(0,Q.jsxs)(q,{variant:`ghost`,size:`sm`,className:`w-full justify-start gap-2 text-emerald-600 dark:text-emerald-400`,onClick:b,disabled:y,children:[y?(0,Q.jsx)(_e,{className:`h-4 w-4 animate-spin`}):(0,Q.jsx)(kt,{className:`h-4 w-4`}),!_&&(0,Q.jsx)(`span`,{className:`truncate`,children:y?`Updating...`:`Update to Latest`})]}),t[5]=_,t[6]=b,t[7]=v,t[8]=y,t[9]=k):k=t[9];let A;t[10]===Symbol.for(`react.memo_cache_sentinel`)?(A=(0,Q.jsx)($t,{className:`h-4 w-4`}),t[10]=A):A=t[10];let j;t[11]===_?j=t[12]:(j=!_&&(0,Q.jsx)(`span`,{className:`truncate`,children:`Providers`}),t[11]=_,t[12]=j);let M;t[13]!==h||t[14]!==j?(M=(0,Q.jsxs)(q,{variant:`ghost`,size:`sm`,className:`flex-1 justify-start gap-2 text-sidebar-foreground`,onClick:h,children:[A,j]}),t[13]=h,t[14]=j,t[15]=M):M=t[15];let N,P;t[16]===Symbol.for(`react.memo_cache_sentinel`)?(N=(0,Q.jsx)(q,{variant:`ghost`,size:`icon`,className:`h-8 w-8 text-sidebar-foreground shrink-0`,onClick:()=>C(!0),children:(0,Q.jsx)(ze,{className:`h-4 w-4`})}),P=(0,Q.jsx)(Sr,{}),t[16]=N,t[17]=P):(N=t[16],P=t[17]);let F;t[18]===M?F=t[19]:(F=(0,Q.jsxs)(`div`,{className:`flex items-center gap-1`,children:[M,N,P]}),t[18]=M,t[19]=F);let I;t[20]!==k||t[21]!==F?(I=(0,Q.jsxs)(`div`,{className:`px-3 py-2 flex flex-col gap-1`,children:[k,F]}),t[20]=k,t[21]=F,t[22]=I):I=t[22];let L;t[23]===n.length?L=t[24]:(L=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[23]=n.length,t[24]=L);let R;t[25]!==o||t[26]!==c||t[27]!==s||t[28]!==d||t[29]!==m||t[30]!==p||t[31]!==l||t[32]!==a||t[33]!==n||t[34]!==i||t[35]!==r?(R=(e,t)=>{let{isOpen:u,toggle:h}=t;return e.kind===`project`?(0,Q.jsx)(Or,{project:e.project,isOpen:u,onToggle:h,isDeletingProject:c.includes(e.project.projectId),isSelected:i?e.project.projectId===i:!1,onCreateThread:d,onDeleteProject:m,onProjectSettings:T,hasSelectedThread:e.project.threads.some(e=>e.threadId===r)}):(0,Q.jsx)(kr,{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:`${f(n.find(t=>t.projectId===e.projectId))} - `,onSelectThread:l,onDeleteThread:p})},t[25]=o,t[26]=c,t[27]=s,t[28]=d,t[29]=m,t[30]=p,t[31]=l,t[32]=a,t[33]=n,t[34]=i,t[35]=r,t[36]=R):R=t[36];let z;t[37]!==D||t[38]!==R?(z=(0,Q.jsx)(ur,{nodes:D,defaultOpen:!0,childContainerClassName:`ml-4 border-l border-sidebar-border pl-2`,renderNode:R}),t[37]=D,t[38]=R,t[39]=z):z=t[39];let B;t[40]!==L||t[41]!==z?(B=(0,Q.jsx)(Re,{className:`flex-1 w-full`,children:(0,Q.jsxs)(`div`,{className:`px-2 py-2 w-full max-w-full overflow-hidden`,children:[L,z]})}),t[40]=L,t[41]=z,t[42]=B):B=t[42];let V;t[43]!==_||t[44]!==g||t[45]!==I||t[46]!==B||t[47]!==O?(V=(0,Q.jsx)(Cr,{collapsed:_,onLogoClick:g,headerAction:O,footer:I,children:B}),t[43]=_,t[44]=g,t[45]=I,t[46]=B,t[47]=O,t[48]=V):V=t[48];let H=w!==null,U;t[49]===Symbol.for(`react.memo_cache_sentinel`)?(U=e=>!e&&T(null),t[49]=U):U=t[49];let ee;t[50]===x?ee=t[51]:(ee=()=>{x?.(),T(null)},t[50]=x,t[51]=ee);let W;t[52]!==w||t[53]!==ee?(W=(0,Q.jsx)(Ze,{className:`max-w-2xl p-0 overflow-auto max-h-[90vh]`,children:(0,Q.jsx)(Z.Suspense,{fallback:null,children:(0,Q.jsx)(Tr,{projectId:w,onProjectUpdated:ee})})}),t[52]=w,t[53]=ee,t[54]=W):W=t[54];let G;t[55]!==H||t[56]!==W?(G=(0,Q.jsx)(tt,{open:H,onOpenChange:U,children:W}),t[55]=H,t[56]=W,t[57]=G):G=t[57];let te;t[58]===Symbol.for(`react.memo_cache_sentinel`)?(te=(0,Q.jsx)(Ze,{className:`max-w-2xl p-0 overflow-auto max-h-[90vh]`,children:(0,Q.jsx)(Z.Suspense,{fallback:null,children:(0,Q.jsx)(wr,{})})}),t[58]=te):te=t[58];let ne;t[59]===S?ne=t[60]:(ne=(0,Q.jsx)(tt,{open:S,onOpenChange:C,children:te}),t[59]=S,t[60]=ne);let re;return t[61]!==V||t[62]!==G||t[63]!==ne?(re=(0,Q.jsxs)(Q.Fragment,{children:[V,G,ne]}),t[61]=V,t[62]=G,t[63]=ne,t[64]=re):re=t[64],re}function Dr(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 Or(e){let t=(0,X.c)(26),{project:r,isOpen:i,onToggle:a,isDeletingProject:o,hasSelectedThread:s,isSelected:c,onCreateThread:l,onDeleteProject:u,onProjectSettings:d}=e,p;t[0]===r?p=t[1]:(p=f(r),t[0]=r,t[1]=p);let m=p,h=s||c,g=i&&`rotate-90`,_;t[2]===g?_=t[3]:(_=J(`h-3.5 w-3.5 shrink-0 text-muted-foreground transition-transform`,g),t[2]=g,t[3]=_);let v;t[4]===_?v=t[5]:(v=(0,Q.jsx)(Jt,{className:_}),t[4]=_,t[5]=v);let y;t[6]===Symbol.for(`react.memo_cache_sentinel`)?(y=(0,Q.jsx)(n,{className:`h-3.5 w-3.5 shrink-0 text-muted-foreground`}),t[6]=y):y=t[6];let b=(s||c)&&`font-bold text-foreground`,x;t[7]===b?x=t[8]:(x=J(`min-w-0 truncate transition-all block`,b),t[7]=b,t[8]=x);let S;t[9]!==m||t[10]!==x?(S=(0,Q.jsx)(`span`,{className:x,children:m}),t[9]=m,t[10]=x,t[11]=S):S=t[11];let C;t[12]!==v||t[13]!==S?(C=(0,Q.jsxs)(`div`,{className:`flex min-w-0 flex-1 items-center gap-1.5 w-0`,children:[v,y,S]}),t[12]=v,t[13]=S,t[14]=C):C=t[14];let w;t[15]!==o||t[16]!==l||t[17]!==u||t[18]!==d||t[19]!==r?(w=(0,Q.jsx)(`div`,{className:`flex shrink-0 items-center ml-auto`,children:o?(0,Q.jsx)(_e,{className:`h-3.5 w-3.5 shrink-0 animate-spin text-muted-foreground mr-1`}):(0,Q.jsxs)(tr,{children:[(0,Q.jsxs)(nr,{children:[(0,Q.jsx)(rr,{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(),d(r.projectId)},children:[(0,Q.jsx)($t,{className:`h-4 w-4`}),(0,Q.jsx)(`span`,{className:`sr-only`,children:`Project settings`})]})}),(0,Q.jsx)(er,{side:`right`,children:`Project settings`})]}),(0,Q.jsxs)(nr,{children:[(0,Q.jsx)(rr,{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(),l(r.projectId)},children:[(0,Q.jsx)(Gt,{}),(0,Q.jsx)(`span`,{className:`sr-only`,children:`Add thread`})]})}),(0,Q.jsx)(er,{side:`right`,children:`Add thread`})]}),r.threads.length===0&&(0,Q.jsxs)(nr,{children:[(0,Q.jsx)(rr,{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(),u(r.projectId)},children:[(0,Q.jsx)(Je,{}),(0,Q.jsx)(`span`,{className:`sr-only`,children:`Delete project`})]})}),(0,Q.jsx)(er,{side:`right`,children:`Delete project`})]})]})}),t[15]=o,t[16]=l,t[17]=u,t[18]=d,t[19]=r,t[20]=w):w=t[20];let T;return t[21]!==a||t[22]!==C||t[23]!==w||t[24]!==h?(T=(0,Q.jsxs)(dr,{selected:h,noBackground:!0,className:`mb-1 h-9`,onClick:a,children:[C,w]}),t[21]=a,t[22]=C,t[23]=w,t[24]=h,t[25]=T):T=t[25],T}function kr(e){let t=(0,X.c)(47),{thread:n,projectId:r,selectedThreadId:i,isProcessing:a,isDeleting:o,isCompleted:s,projectTitlePrefix:c,onSelectThread:l,onDeleteThread:u}=e,[d,f]=(0,Z.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)(vr,{children:`Delete Thread`}),t[9]=_):_=t[9];let v;t[10]===g?v=t[11]:(v=(0,Q.jsxs)(yr,{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)(xr,{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)(br,{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)(hr,{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)(fr,{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)(_e,{className:`ml-auto h-3 w-3 shrink-0 animate-spin text-muted-foreground`}):s?(0,Q.jsx)(Ut,{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)(nr,{children:[(0,Q.jsx)(rr,{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)(Je,{}),(0,Q.jsx)(`span`,{className:`sr-only`,children:`Delete thread`})]})}),(0,Q.jsx)(er,{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)(dr,{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 Ar(e){let t=(0,X.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=Mr(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=J(`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(jr),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 jr(e,t){return(0,Q.jsx)(Nr,{block:e},t)}function Mr(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 Nr(e){let t=(0,X.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=J({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)(Rr,{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)(Vr,{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)(Rr,{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=J(`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(Lr),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)(Rr,{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(Ir),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(Pr),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 Pr(e,t){return(0,Q.jsx)(`tr`,{className:`border-b border-border last:border-0`,children:e.map(Fr)},t)}function Fr(e,t){return(0,Q.jsx)(`td`,{className:`px-3 py-2 text-foreground`,children:e},t)}function Ir(e,t){return(0,Q.jsx)(`th`,{className:`px-3 py-2 text-left font-medium text-foreground`,children:e},t)}function Lr(e,t){return(0,Q.jsx)(`li`,{children:(0,Q.jsx)(Rr,{text:e})},t)}function Rr(e){let t=(0,X.c)(4),{text:n}=e,r;t[0]===n?r=t[1]:(r=Br(n).map(zr),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 zr(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 Br(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 Vr(e){let t=(0,X.c)(18),{language:n,code:r}=e,[i,a]=(0,Z.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)(Ut,{}):(0,Q.jsx)(Ke,{}),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 Hr=sn,Ur=ln,Wr=Z.forwardRef((e,t)=>{let n=(0,X.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=J(`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)(gn,{children:(0,Q.jsx)(mn,{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});Wr.displayName=mn.displayName;function Gr(e){let t=e.toLowerCase();return t.includes(`read`)||t.includes(`file`)?h:t.includes(`create`)?Gt:t.includes(`replace`)||t.includes(`edit`)?Oe:t.includes(`delete`)?Zt:t.includes(`terminal`)||t.includes(`bash`)||t.includes(`shell`)?wt:t.includes(`run`)?je:t.includes(`git`)||t.includes(`branch`)?ye:t.includes(`search`)||t.includes(`grep`)||t.includes(`find`)?p:t.includes(`code`)||t.includes(`debug`)?St:t.includes(`test`)?zt:t.includes(`agent`)||t.includes(`subagent`)?H:t.includes(`copy`)?Ke:t.includes(`dir`)||t.includes(`list`)||t.includes(`ls`)?c:t.includes(`view`)||t.includes(`show`)?nt:t.includes(`config`)||t.includes(`setting`)?$t:t.includes(`chat`)||t.includes(`message`)||t.includes(`ask`)?se:jt}function Kr(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`:e}function qr(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 Jr(e){return typeof e==`string`?e:typeof e==`object`&&e?JSON.stringify(e,null,2):String(e)}function Yr(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 Xr(e){if(typeof e!=`object`||!e)return e;if(Array.isArray(e))return e.map(Xr);let t={};for(let[n,r]of Object.entries(e))if(typeof r==`string`){let e=Yr(r);t[n]=typeof e==`object`?Xr(e):r}else t[n]=Xr(r);return t}function Zr(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 Qr(e){if(e==null)return``;let t=typeof e==`object`&&e?Xr(e):e;return Zr(typeof t==`string`?t:t==null?``:JSON.stringify(t,null,2))}function $r(e){let t=(0,X.c)(112),{block:n,inline:r,resultContent:i}=e,[a,o]=(0,Z.useState)(!1),[s,c]=(0,Z.useState)(!1),{state:l}=Hn(),u,f,p,m,h,g,_,v,y,b,x;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;x=n.name??`Unknown Tool`,y=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),_=s,p=i&&typeof i==`object`?i:null,u=x===`agent`&&p&&typeof p.agentName==`string`?p.agentName:null,b=a?null:qr(Jr(i),r),g=qr(a?String(i.prompt):null,r),f=qr(p&&typeof p.command==`string`?p.command:null,r),h=p&&typeof p.pattern==`string`?p.pattern:null,m=p&&typeof p.lang==`string`?p.lang:null,v=qr(p&&typeof p.path==`string`?p.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]=u,t[7]=f,t[8]=p,t[9]=m,t[10]=h,t[11]=g,t[12]=_,t[13]=v,t[14]=y,t[15]=b,t[16]=x}else u=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];let S=v,C=p&&typeof p.offset==`number`?p.offset:null,w=p&&typeof p.limit==`number`?p.limit:null,T,E,D,O,k,A,j;if(t[21]!==u||t[22]!==f||t[23]!==s||t[24]!==a||t[25]!==r||t[26]!==p||t[27]!==m||t[28]!==w||t[29]!==C||t[30]!==S||t[31]!==h||t[32]!==g||t[33]!==i||t[34]!==_||t[35]!==y||t[36]!==b||t[37]!==x){j=Symbol.for(`react.early_return_sentinel`);bb0:{let e=Gr(x),n=x===`todo`&&p?p.status:void 0,l=(x===`todo`?n===`done`?zt:n===`working`?Ee:Xe:null)??e,d;if(t[45]!==w||t[46]!==C||t[47]!==x?(d=()=>{let e=x.charAt(0).toUpperCase()+x.slice(1);return x.toLowerCase()===`bash`&&(e=`Ran`),x.toLowerCase()===`ast_grep`&&(e=`Code Search`),x.toLowerCase().includes(`read`)&&(C!==null||w!==null)&&(C!==null&&w!==null?e+=` (lines ${C} to ${C+w})`:C===null?e+=` (${w} lines)`:e+=` (from line ${C})`),e},t[45]=w,t[46]=C,t[47]=x,t[48]=d):d=t[48],T=d,r){if(x===`todo`){j=null;break bb0}if(f!==null&&i){let e;t[49]===Symbol.for(`react.memo_cache_sentinel`)?(e=()=>c(!0),t[49]=e):e=t[49];let n=(0,Z.createElement)(l,{className:`h-3.5 w-3.5 shrink-0 text-brand`}),r=T(),a;t[50]===r?a=t[51]:(a=(0,Q.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:r}),t[50]=r,t[51]=a);let o;t[52]===f?o=t[53]:(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:f}),t[52]=f,t[53]=o);let u;t[54]===f?u=t[55]:(u=(0,Q.jsx)(Qt,{children:(0,Q.jsx)(Fe,{children:(0,Q.jsx)(`code`,{className:`text-sm font-mono`,children:f})})}),t[54]=f,t[55]=u);let d;t[56]===i?d=t[57]:(d=(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[56]=i,t[57]=d);let p;t[58]!==u||t[59]!==d?(p=(0,Q.jsxs)(Ze,{className:`max-w-3xl max-h-[80vh] flex flex-col`,children:[u,d]}),t[58]=u,t[59]=d,t[60]=p):p=t[60];let m;t[61]!==s||t[62]!==p?(m=(0,Q.jsx)(tt,{open:s,onOpenChange:c,children:p}),t[61]=s,t[62]=p,t[63]=m):m=t[63],j=(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]}),m]});break bb0}let e=g??(b&&!f&&!S&&!h)?(0,Q.jsxs)(Hr,{children:[(0,Q.jsx)(Ur,{asChild:!0,children:(0,Q.jsx)(`span`,{title:x,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,Z.createElement)(l,{className:`h-3.5 w-3.5 text-brand`}),(0,Q.jsx)(`span`,{className:`text-xs`,children:T()})]})})}),(0,Q.jsx)(Wr,{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: `,y]}),g?(0,Q.jsx)(`div`,{className:`whitespace-pre-wrap leading-relaxed`,children:g}):b?(0,Q.jsx)(`pre`,{className:`font-mono whitespace-pre-wrap overflow-auto max-h-48`,children:b}):null]})})]}):(0,Q.jsxs)(`span`,{title:x,className:`inline-flex items-center gap-1`,children:[(0,Z.createElement)(l,{className:`h-3.5 w-3.5 shrink-0 text-brand`}),(0,Q.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:T()})]}),n;t[64]===f?n=t[65]:(n=f!==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:f}),t[64]=f,t[65]=n);let r;t[66]===h?r=t[67]:(r=h!==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:h}),t[66]=h,t[67]=r);let a;t[68]===m?a=t[69]:(a=m!==null&&(0,Q.jsx)(`span`,{className:`text-xs px-1.5 py-0.5 rounded bg-muted text-muted-foreground`,children:m}),t[68]=m,t[69]=a);let o;t[70]===S?o=t[71]:(o=S!==null&&(0,Q.jsx)(`span`,{className:`text-xs font-mono text-muted-foreground truncate max-w-[200px] sm:max-w-[320px]`,title:S,children:S}),t[70]=S,t[71]=o);let d;t[72]===u?d=t[73]:(d=u&&(0,Q.jsx)(`span`,{className:`text-xs px-1.5 py-0.5 rounded bg-muted text-muted-foreground font-mono`,children:u}),t[72]=u,t[73]=d);let p;t[74]===_?p=t[75]:(p=_&&(0,Q.jsx)(`span`,{className:`text-xs px-2 py-0.5 rounded bg-muted text-muted-foreground`,children:_}),t[74]=_,t[75]=p);let v;t[76]!==n||t[77]!==r||t[78]!==a||t[79]!==o||t[80]!==d||t[81]!==p||t[82]!==e?(v=(0,Q.jsxs)(`div`,{className:`py-0.5 flex items-center gap-2 flex-wrap`,children:[e,n,r,a,o,d,p]}),t[76]=n,t[77]=r,t[78]=a,t[79]=o,t[80]=d,t[81]=p,t[82]=e,t[83]=v):v=t[83],j=v;break bb0}A=`mb-3 rounded-lg border border-blue-200 dark:border-blue-800 bg-blue-50 dark:bg-blue-900/20 overflow-hidden`,t[84]===a?E=t[85]:(E=()=>o(!a),t[84]=a,t[85]=E),D=`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`,O=x,k=(0,Z.createElement)(l,{className:`h-4 w-4 text-brand`})}t[21]=u,t[22]=f,t[23]=s,t[24]=a,t[25]=r,t[26]=p,t[27]=m,t[28]=w,t[29]=C,t[30]=S,t[31]=h,t[32]=g,t[33]=i,t[34]=_,t[35]=y,t[36]=b,t[37]=x,t[38]=T,t[39]=E,t[40]=D,t[41]=O,t[42]=k,t[43]=A,t[44]=j}else T=t[38],E=t[39],D=t[40],O=t[41],k=t[42],A=t[43],j=t[44];if(j!==Symbol.for(`react.early_return_sentinel`))return j;let M=T(),N;t[86]===M?N=t[87]:(N=(0,Q.jsx)(`span`,{className:`flex-1 text-left min-w-0 truncate`,children:M}),t[86]=M,t[87]=N);let P;t[88]===u?P=t[89]:(P=u&&(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:u}),t[88]=u,t[89]=P);let F;t[90]===_?F=t[91]:(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`,children:_}),t[90]=_,t[91]=F);let I;t[92]===a?I=t[93]:(I=a?(0,Q.jsx)(d,{className:`h-4 w-4 shrink-0`}):(0,Q.jsx)(Jt,{className:`h-4 w-4 shrink-0`}),t[92]=a,t[93]=I);let L;t[94]!==P||t[95]!==F||t[96]!==I||t[97]!==E||t[98]!==D||t[99]!==O||t[100]!==k||t[101]!==N?(L=(0,Q.jsxs)(`button`,{onClick:E,className:D,title:O,children:[k,N,P,F,I]}),t[94]=P,t[95]=F,t[96]=I,t[97]=E,t[98]=D,t[99]=O,t[100]=k,t[101]=N,t[102]=L):L=t[102];let R;t[103]!==a||t[104]!==g||t[105]!==y||t[106]!==b?(R=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: `,y]}),g?(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:g}):b?(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:b}):null]}),t[103]=a,t[104]=g,t[105]=y,t[106]=b,t[107]=R):R=t[107];let z;return t[108]!==L||t[109]!==R||t[110]!==A?(z=(0,Q.jsxs)(`div`,{className:A,children:[L,R]}),t[108]=L,t[109]=R,t[110]=A,t[111]=z):z=t[111],z}var ei=(0,Z.createContext)({todos:[],setTodos:()=>{}});function ti(e){let t=(0,X.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,Z.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)(ei.Provider,{value:c,children:n}),t[4]=n,t[5]=c,t[6]=l):l=t[6],l}function ni(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 ri(e){let t=(0,X.c)(17),{todos:n}=e,{todos:r,setTodos:i}=(0,Z.useContext)(ei),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,Z.useEffect)(a,o);let s=r.length>0?r:n,c;t[4]===s?c=t[5]:(c=s.filter(ai),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(ii),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 ii(e){return(0,Q.jsxs)(`div`,{className:`flex items-start gap-2 text-sm`,children:[e.status===`done`?(0,Q.jsx)(zt,{className:`h-4 w-4 shrink-0 mt-0.5 text-green-500`}):e.status===`working`?(0,Q.jsx)(et,{className:`h-4 w-4 shrink-0 mt-0.5 text-yellow-500`}):(0,Q.jsx)(Xe,{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 ai(e){return e.status===`done`}function oi(e){let t=(0,X.c)(4),{todos:n}=e,{setTodos:r}=(0,Z.useContext)(ei),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,Z.useEffect)(i,a),null}function si(e){let t=(0,X.c)(19),{todos:n}=e,[r,i]=(0,Z.useState)(!0),a;t[0]===n?a=t[1]:(a=n.filter(ci),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)(D,{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 f;t[7]===r?f=t[8]:(f=r?(0,Q.jsx)(d,{className:`h-4 w-4 shrink-0`}):(0,Q.jsx)(Jt,{className:`h-4 w-4 shrink-0`}),t[7]=r,t[8]=f);let p;t[9]!==c||t[10]!==u||t[11]!==f?(p=(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,f]}),t[9]=c,t[10]=u,t[11]=f,t[12]=p):p=t[12];let m;t[13]!==r||t[14]!==n?(m=r&&(0,Q.jsx)(`div`,{className:`px-3 py-3 bg-background border-t border-border`,children:(0,Q.jsx)(ri,{todos:n})}),t[13]=r,t[14]=n,t[15]=m):m=t[15];let h;return t[16]!==p||t[17]!==m?(h=(0,Q.jsxs)(`div`,{className:`mb-3 rounded-lg border border-border bg-muted/50 overflow-hidden`,children:[p,m]}),t[16]=p,t[17]=m,t[18]=h):h=t[18],h}function ci(e){return e.status===`done`}function li(e){let t=(0,X.c)(65),{block:n,inline:r}=e,[i,a]=(0,Z.useState)(!1),[o,s]=(0,Z.useState)(!1),{state:c}=Hn(),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`?ni(a):null,t[15]=a,t[16]=v,t[17]=s):s=t[17];let d=s;if(p=qr(Qr(o),i),!(p.length>0)&&d===null){g=null;break bb0}if(u=Kr(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=Kr(v),t[22]=v,t[23]=e),u=`${e} (no result)`}if(u=qr(u,i),d!==null){let e;t[24]===d?e=t[25]:(e=(0,Q.jsx)(oi,{todos:d}),t[24]=d,t[25]=e),g=e;break bb0}if(r){g=null;break bb0}let y;t[26]===v?y=t[27]:(y=v.toLowerCase().includes(`bash`),t[26]=v,t[27]=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[28]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,Q.jsx)(zt,{className:`h-4 w-4 shrink-0`}),t[28]=e):e=t[28];let n;t[29]===u?n=t[30]:(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[29]=u,t[30]=n);let r;t[31]!==b||t[32]!==y||t[33]!==p||t[34]!==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[31]=b,t[32]=y,t[33]=p,t[34]=m,t[35]=r):r=t[35];let i;t[36]!==n||t[37]!==r?(i=(0,Q.jsxs)(`div`,{className:`mb-3 rounded-lg border border-border bg-muted/50 overflow-hidden`,children:[n,r]}),t[36]=n,t[37]=r,t[38]=i):i=t[38];let a;t[39]!==o||t[40]!==b||t[41]!==p?(a=b&&(0,Q.jsx)(tt,{open:o,onOpenChange:s,children:(0,Q.jsxs)(Ze,{className:`max-w-3xl max-h-[80vh] flex flex-col`,children:[(0,Q.jsx)(Qt,{children:(0,Q.jsx)(Fe,{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[39]=o,t[40]=b,t[41]=p,t[42]=a):a=t[42];let c;return t[43]!==i||t[44]!==a?(c=(0,Q.jsxs)(Q.Fragment,{children:[i,a]}),t[43]=i,t[44]=a,t[45]=c):c=t[45],c}let x;t[46]===i?x=t[47]:(x=()=>a(!i),t[46]=i,t[47]=x);let S=`${v} result`,C;t[48]===Symbol.for(`react.memo_cache_sentinel`)?(C=(0,Q.jsx)(zt,{className:`h-4 w-4 shrink-0`}),t[48]=C):C=t[48];let w;t[49]===u?w=t[50]:(w=(0,Q.jsx)(`span`,{className:`flex-1 text-left min-w-0 truncate`,children:u}),t[49]=u,t[50]=w);let T;t[51]===i?T=t[52]:(T=i?(0,Q.jsx)(d,{className:`h-4 w-4 shrink-0`}):(0,Q.jsx)(Jt,{className:`h-4 w-4 shrink-0`}),t[51]=i,t[52]=T);let E;t[53]!==x||t[54]!==S||t[55]!==w||t[56]!==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[53]=x,t[54]=S,t[55]=w,t[56]=T,t[57]=E):E=t[57];let D;t[58]!==i||t[59]!==p||t[60]!==_?(D=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[58]=i,t[59]=p,t[60]=_,t[61]=D):D=t[61];let O;return t[62]!==D||t[63]!==E?(O=(0,Q.jsxs)(`div`,{className:`mb-3 rounded-lg border border-border bg-muted/50 overflow-hidden`,children:[E,D]}),t[62]=D,t[63]=E,t[64]=O):O=t[64],O}function ui(e){let t=(0,X.c)(19),{text:n,isStreaming:r,hasContentAfter:i}=e,a=r===void 0?!1:r,o=i===void 0?!1:i,[s,c]=(0,Z.useState)(null),l=(0,Z.useRef)(a),u=(0,Z.useRef)(o),f,p;if(t[0]!==o||t[1]!==a?(f=()=>{(l.current&&!a||!u.current&&o)&&(0,Z.startTransition)(()=>{c(!1)}),l.current=a,u.current=o},p=[a,o,c],t[0]=o,t[1]=a,t[2]=f,t[3]=p):(f=t[2],p=t[3]),(0,Z.useEffect)(f,p),!n?.trim())return null;let m=s??a,h;t[4]===m?h=t[5]:(h=()=>c(!m),t[4]=m,t[5]=h);let g,_;t[6]===Symbol.for(`react.memo_cache_sentinel`)?(g=(0,Q.jsx)(K,{className:`h-4 w-4 shrink-0 text-brand`}),_=(0,Q.jsx)(`span`,{className:`flex-1 text-left min-w-0 truncate`,children:`Thinking`}),t[6]=g,t[7]=_):(g=t[6],_=t[7]);let v;t[8]===m?v=t[9]:(v=m?(0,Q.jsx)(d,{className:`h-4 w-4 shrink-0`}):(0,Q.jsx)(Jt,{className:`h-4 w-4 shrink-0`}),t[8]=m,t[9]=v);let y;t[10]!==h||t[11]!==v?(y=(0,Q.jsxs)(`button`,{onClick:h,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:[g,_,v]}),t[10]=h,t[11]=v,t[12]=y):y=t[12];let b;t[13]!==m||t[14]!==n?(b=m&&(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]=m,t[14]=n,t[15]=b):b=t[15];let x;return t[16]!==b||t[17]!==y?(x=(0,Q.jsxs)(`div`,{className:`overflow-hidden`,children:[y,b]}),t[16]=b,t[17]=y,t[18]=x):x=t[18],x}function di({toolCall:e,className:t}){let{state:n,dispatch:r}=Hn(),[i,a]=(0,Z.useState)(!1),o=n.toolCallProgress[e.id];return(0,Z.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:J(`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)(_e,{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)(Pe,{className:`h-3.5 w-3.5`}):(0,Q.jsx)(d,{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)(xt,{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)(_e,{className:`h-3 w-3 animate-spin`}),`Executing`,o&&` with progress`,`...`]})]})]}):null}function fi(e){let t=(0,X.c)(51),{toolCallId:n,question:r,options:i,context:a}=e,[o,s]=(0,Z.useState)(``),[c,l]=(0,Z.useState)(!1),[u,d]=(0,Z.useState)(``),[f,p]=(0,Z.useState)(!1),[m,h]=(0,Z.useState)(null),g;t[0]!==f||t[1]!==n?(g=async e=>{if(!(!e.trim()||f)){p(!0);try{await Ce(n,e.trim()),d(e.trim()),l(!0)}catch(e){let t=e;console.error(`Failed to submit answer:`,t),p(!1),h(null)}}},t[0]=f,t[1]=n,t[2]=g):g=t[2];let _=g,v;t[3]!==_||t[4]!==f||t[5]!==c?(v=e=>{c||f||(h(e),_(e))},t[3]=_,t[4]=f,t[5]=c,t[6]=v):v=t[6];let y=v,b;t[7]!==o||t[8]!==_||t[9]!==f||t[10]!==c?(b=()=>{if(c||f)return;let e=o.trim();e&&_(e)},t[7]=o,t[8]=_,t[9]=f,t[10]=c,t[11]=b):b=t[11];let x=b,S;t[12]===x?S=t[13]:(S=e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),x())},t[12]=x,t[13]=S);let C=S;if(c){let e,n;t[14]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,Q.jsx)(Ut,{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]===u?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:u})]})}),t[16]=u,t[17]=r),r}let w;t[18]===Symbol.for(`react.memo_cache_sentinel`)?(w=(0,Q.jsx)(Ee,{className:`h-5 w-5 text-brand dark:text-brand shrink-0 mt-0.5`}),t[18]=w):w=t[18];let T;t[19]===r?T=t[20]:(T=(0,Q.jsx)(`div`,{className:`text-sm font-medium text-foreground`,children:(0,Q.jsx)(Ar,{content:r})}),t[19]=r,t[20]=T);let E;t[21]===a?E=t[22]:(E=a&&(0,Q.jsx)(`p`,{className:`text-xs text-muted-foreground mt-1`,children:a}),t[21]=a,t[22]=E);let D;t[23]!==T||t[24]!==E?(D=(0,Q.jsxs)(`div`,{className:`flex items-start gap-2 mb-3`,children:[w,(0,Q.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[T,E]})]}),t[23]=T,t[24]=E,t[25]=D):D=t[25];let O;t[26]!==y||t[27]!==f||t[28]!==i||t[29]!==m?(O=i&&i.length>0&&(0,Q.jsx)(`div`,{className:`flex flex-wrap gap-2 mb-3`,children:i.map(e=>{let t=m===e;return(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>y(e),disabled:f,className:J(`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)(Ut,{className:`h-3.5 w-3.5 text-brand`}),e]},e)})}),t[26]=y,t[27]=f,t[28]=i,t[29]=m,t[30]=O):O=t[30];let k;t[31]===Symbol.for(`react.memo_cache_sentinel`)?(k=e=>s(e.target.value),t[31]=k):k=t[31];let A=i?.length?`Or type a custom answer...`:`Type your answer...`,j;t[32]!==o||t[33]!==C||t[34]!==f||t[35]!==A?(j=(0,Q.jsx)(`input`,{type:`text`,value:o,onChange:k,onKeyDown:C,placeholder:A,disabled:f,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]=C,t[34]=f,t[35]=A,t[36]=j):j=t[36];let M;t[37]!==o||t[38]!==f?(M=f||!o.trim(),t[37]=o,t[38]=f,t[39]=M):M=t[39];let N;t[40]===Symbol.for(`react.memo_cache_sentinel`)?(N=(0,Q.jsx)(le,{className:`h-4 w-4`}),t[40]=N):N=t[40];let P;t[41]!==x||t[42]!==M?(P=(0,Q.jsx)(`button`,{type:`button`,onClick:x,disabled:M,className:`rounded-md bg-brand px-3 py-1.5 text-sm text-white hover:bg-brand/90 transition-colors disabled:opacity-50`,children:N}),t[41]=x,t[42]=M,t[43]=P):P=t[43];let F;t[44]!==j||t[45]!==P?(F=(0,Q.jsxs)(`div`,{className:`flex gap-2`,children:[j,P]}),t[44]=j,t[45]=P,t[46]=F):F=t[46];let I;return t[47]!==F||t[48]!==D||t[49]!==O?(I=(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:[D,O,F]}),t[47]=F,t[48]=D,t[49]=O,t[50]=I):I=t[50],I}function pi(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 mi(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 hi(e,t,n,r){return e.name===`ask_user`?(0,Q.jsx)(fi,{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)(di,{toolCall:e}),(0,Q.jsx)($r,{inline:!0,block:e,resultContent:r})]},t):(0,Q.jsx)($r,{inline:!0,block:e,resultContent:r},t)}function gi(e){let t=(0,X.c)(59),{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:Gn(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=J(`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=J(`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)(ze,{className:`h-3.5 w-3.5 text-background`}):(0,Q.jsx)(y,{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=J(`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=J(`flex items-center gap-2`,_),t[27]=_,t[28]=v);let b=r?`You`:`Agent`,x;t[29]===b?x=t[30]:(x=(0,Q.jsx)(`span`,{className:`text-xs font-medium text-foreground`,children:b}),t[29]=b,t[30]=x);let S;t[31]===d?S=t[32]:(S=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)(et,{className:`h-2.5 w-2.5`}),d]}),t[31]=d,t[32]=S);let C;t[33]===n.model?C=t[34]:(C=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)(It,{className:`h-2.5 w-2.5`}),sr(n.model)]}),t[33]=n.model,t[34]=C);let w;t[35]===n.metadata?w=t[36]:(w=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]=w),t[37]!==v||t[38]!==x||t[39]!==S||t[40]!==C||t[41]!==w?(s=(0,Q.jsxs)(`div`,{className:v,children:[x,S,C,w]}),t[37]=v,t[38]=x,t[39]=S,t[40]=C,t[41]=w,t[42]=s):s=t[42];let T=r?`bg-foreground text-background`:`bg-muted text-foreground`;t[43]===T?i=t[44]:(i=J(`rounded-xl px-4 py-3 flex flex-col gap-0.5 min-w-0`,T),t[43]=T,t[44]=i),a=n.isThinking?(()=>{let e=Xn(n.content);return e?.length?e.map((t,n)=>t.type===`tool_use`?hi(t,n,!1,mi(e,t.id)):t.type===`tool-result`?(0,Q.jsx)(li,{inline:!0,block:t},n):t.type===`reasoning`&&`text`in t?(0,Q.jsx)(ui,{text:Wn(t.text)},n):null):(0,Q.jsx)(`div`,{className:`text-xs text-muted-foreground leading-relaxed whitespace-pre-wrap`,children:(0,Q.jsx)(Ar,{content:Wn(n.content)})})})():e?(()=>{let t=pi(e);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)(li,{inline:!0,block:t},n):null:(0,Q.jsx)(`div`,{children:t.type===`reasoning`&&`text`in t?(0,Q.jsx)(ui,{text:Wn(t.text)}):t.type===`text`&&`text`in t?(0,Q.jsx)(Ar,{content:Wn(t.text)}):t.type===`tool_use`?hi(t,void 0,!1,mi(e,t.id)):t.type===`tool-result`?(0,Q.jsx)(li,{inline:!0,block:t}):null},n)),t.length>0&&(0,Q.jsx)(si,{todos:t})]})})():n.contentType===`markdown`||n.sender===`agent`?(0,Q.jsx)(Ar,{content:Wn(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.attachments?d=t[49]:(d=n.attachments&&n.attachments.length>0&&(0,Q.jsx)(`div`,{className:`flex flex-wrap gap-1.5 mt-1`,children:n.attachments.map(_i)}),t[48]=n.attachments,t[49]=d);let f;t[50]!==o||t[51]!==s||t[52]!==u||t[53]!==d?(f=(0,Q.jsxs)(`div`,{className:o,children:[s,u,d]}),t[50]=o,t[51]=s,t[52]=u,t[53]=d,t[54]=f):f=t[54];let p;return t[55]!==c||t[56]!==l||t[57]!==f?(p=(0,Q.jsxs)(`div`,{className:c,children:[l,f]}),t[55]=c,t[56]=l,t[57]=f,t[58]=p):p=t[58],p}function _i(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)(g,{className:`h-2.5 w-2.5`}),e.fileName]},t)}function vi(e){let t=(0,X.c)(21),{segments:n,model:r}=e,i,a,o,s,c;if(t[0]!==r||t[1]!==n){let e=Un(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)(y,{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)(It,{className:`h-2.5 w-2.5`}),sr(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=pi(e);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)(li,{inline:!0,block:t},`b-${n}`):null:(0,Q.jsx)(`div`,{children:t.type===`reasoning`&&`text`in t?(0,Q.jsx)(ui,{text:Wn(t.text),isStreaming:!0,hasContentAfter:l(n)}):t.type===`text`&&`text`in t?(0,Q.jsx)(Ar,{content:Wn(t.text)}):t.type===`tool_use`?hi(t,void 0,!0,mi(e,t.id)):t.type===`tool-result`?(0,Q.jsx)(li,{inline:!0,block:t}):null},`b-${n}`)),t.length>0&&(0,Q.jsx)(si,{todos:t})]})})():(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}var yi=(0,Z.memo)(vi,(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 bi(e){let t=(0,X.c)(34),{projects:r,onSelectProject:i,onCreateThread:a,onConnectRepo:o,onNewApp:s,onOpenFolder:c}=e,l;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(l=(0,Q.jsx)(`img`,{src:`/tarsk-color.svg`,alt:`Tarsk`,className:`h-16 w-16 rounded-lg`}),t[0]=l):l=t[0];let u;t[1]===Symbol.for(`react.memo_cache_sentinel`)?(u=(0,Q.jsx)(`h1`,{className:`text-2xl font-semibold tracking-tight text-foreground text-balance`,children:`Let's build it!`}),t[1]=u):u=t[1];let d=r.length===0?`Start or connect your first project`:`Select a project to start coding`,f;t[2]===d?f=t[3]:(f=(0,Q.jsxs)(`div`,{className:`flex flex-col items-center gap-3`,children:[l,(0,Q.jsxs)(`div`,{className:`text-center`,children:[u,(0,Q.jsx)(`p`,{className:`mt-1 text-base text-muted-foreground`,children:d})]})]}),t[2]=d,t[3]=f);let p;if(t[4]!==a||t[5]!==i||t[6]!==r){let e;t[8]!==a||t[9]!==i?(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?a(e.projectId):i(e.projectId,e.threads[0].threadId)},children:[(0,Q.jsx)(n,{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]=a,t[9]=i,t[10]=e):e=t[10],p=r.map(e),t[4]=a,t[5]=i,t[6]=r,t[7]=p}else p=t[7];let m,h,g;t[11]===Symbol.for(`react.memo_cache_sentinel`)?(m=(0,Q.jsx)(ye,{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]=m,t[12]=h,t[13]=g):(m=t[11],h=t[12],g=t[13]);let _;t[14]===o?_=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:o,children:[m,h,g]}),t[14]=o,t[15]=_);let v,y,x;t[16]===Symbol.for(`react.memo_cache_sentinel`)?(v=(0,Q.jsx)(b,{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`}),x=(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]=x):(v=t[16],y=t[17],x=t[18]);let S;t[19]===s?S=t[20]:(S=(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:[v,y,x]}),t[19]=s,t[20]=S);let C,w,T;t[21]===Symbol.for(`react.memo_cache_sentinel`)?(C=(0,Q.jsx)(ae,{className:`h-5 w-5 text-muted-foreground`}),w=(0,Q.jsx)(`span`,{className:`text-sm text-foreground leading-snug font-medium`,children:`Open Folder`}),T=(0,Q.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`Use an existing local folder`}),t[21]=C,t[22]=w,t[23]=T):(C=t[21],w=t[22],T=t[23]);let E;t[24]===c?E=t[25]:(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:c,children:[C,w,T]}),t[24]=c,t[25]=E);let D;t[26]!==S||t[27]!==E||t[28]!==p||t[29]!==_?(D=(0,Q.jsxs)(`div`,{className:`flex flex-wrap justify-center gap-3`,children:[p,_,S,E]}),t[26]=S,t[27]=E,t[28]=p,t[29]=_,t[30]=D):D=t[30];let O;return t[31]!==D||t[32]!==f?(O=(0,Q.jsxs)(`div`,{className:`mx-auto flex max-w-3xl flex-1 flex-col items-center justify-center gap-8 px-4`,children:[f,D]}),t[31]=D,t[32]=f,t[33]=O):O=t[33],O}function xi(e){let t=(0,X.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,Z.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,Z.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=J(`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)(bi,{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(Si),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)(yi,{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)(ti,{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 Si(e){return(0,Q.jsx)(gi,{message:e},e.messageId)}var Ci=()=>{if(typeof window>`u`)return null;let e=window.SpeechRecognition||window.webkitSpeechRecognition;return e?new e:null};function wi(){let e=(0,X.c)(14),[t,n]=(0,Z.useState)(!1),[r,i]=(0,Z.useState)(``),[a,o]=(0,Z.useState)(null),[s,c]=(0,Z.useState)(!1),l=(0,Z.useRef)(null),u=(0,Z.useRef)(``),d,f;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(d=()=>{try{let e=Ci();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,Z.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 Ti({initialValue:e}={}){let{state:n,dispatch:r}=Hn(),[i,a]=(0,Z.useState)(e??``),[o,s]=(0,Z.useState)(-1),[c,l]=(0,Z.useState)(``),[u,d]=(0,Z.useState)(0),[f,p]=(0,Z.useState)([]),[m,h]=(0,Z.useState)(()=>(n.selectedThreadId?n.projectModelSelections[n.selectedThreadId]:void 0)??null),g=(0,Z.useRef)(m?.id??``),[_,v]=(0,Z.useState)(!1),[y,b]=(0,Z.useState)(!1),[x,S]=(0,Z.useState)([]),[C,w]=(0,Z.useState)(!1),[T,E]=(0,Z.useState)([]),[D,O]=(0,Z.useState)(!1),[k,A]=(0,Z.useState)(``),[j,M]=(0,Z.useState)(0),[N,P]=(0,Z.useState)([]),[F,I]=(0,Z.useState)([]),[L,R]=(0,Z.useState)(!1),[z,B]=(0,Z.useState)(``),V=(0,Z.useRef)(null),H=(0,Z.useRef)(null),U=(0,Z.useRef)(null),W=(0,Z.useRef)(null),G=(0,Z.useRef)(null),te=(0,Z.useRef)(null);(0,Z.useEffect)(()=>{g.current=m?.id??``},[m?.id]);let ne=(0,Z.useCallback)(e=>{h(e);let t=n.selectedThreadId;t&&(r({type:Y.SetProjectModel,threadId:t,model:e}),rt(t,{model:e.id,modelProvider:e.provider}).catch(e=>console.error(`Failed to save model to thread:`,e)))},[n.selectedThreadId,r]);(0,Z.useEffect)(()=>{(async()=>{let e=n.selectedProjectId?n.projects.find(e=>e.projectId===n.selectedProjectId)?.threads.find(e=>e.threadId===n.selectedThreadId):void 0,t=n.selectedThreadId?n.projectModelSelections[n.selectedThreadId]:void 0,r=t?.id??e?.model??null,i=t?.provider??e?.modelProvider??null;try{let e=await we(),t=Object.values(e).flat();if(t.length>0){p(t);let e=r?t.find(e=>e.id===r):null;!e&&r&&i?e=t.find(e=>e.id===r&&e.provider===i):!e&&r&&(e=t.find(e=>e.id===r));let n=e??t[0];n.id!==g.current&&ne(n)}}catch(e){console.error(`Failed to load enabled models:`,e)}})()},[n.selectedThreadId,n.selectedProjectId,n.projects,n.projectModelSelections,ne]),(0,Z.useEffect)(()=>{n.configUpdatedAt!==0&&(async()=>{try{let e=await we(),t=Object.values(e).flat();if(t.length>0){p(t);let e=g.current;t.some(t=>t.id===e)||ne(t[0])}}catch(e){console.error(`Failed to reload enabled models:`,e)}})()},[n.configUpdatedAt,n.selectedProjectId,ne]);let[re,ie]=(0,Z.useState)(n.selectedThreadId);return(0,Z.useEffect)(()=>{n.selectedThreadId!==re&&setTimeout(()=>{ie(n.selectedThreadId),E([]),O(!1),P([]),I([]),R(!1),w(!1)},0)},[n.selectedThreadId,re]),(0,Z.useEffect)(()=>{n.selectedThreadId&&ke(n.selectedThreadId).then(({commands:e,skills:t})=>{console.log(`Loaded slash commands:`,e,`skills:`,t),P(e),I(t)}).catch(e=>console.error(`Failed to load slash commands and skills:`,e))},[n.selectedThreadId]),(0,Z.useEffect)(()=>{n.focusChatInput&&n.selectedThreadId&&!n.isStreaming&&(H.current?.focus(),r({type:Y.ClearFocusChatInput}))},[n.focusChatInput,n.selectedThreadId,n.isStreaming,r]),(0,Z.useEffect)(()=>{let e=e=>{U.current&&!U.current.contains(e.target)&&v(!1),W.current&&!W.current.contains(e.target)&&b(!1)};if(_||y)return document.addEventListener(`mousedown`,e),()=>{document.removeEventListener(`mousedown`,e)}},[_,y]),{message:i,setMessage:a,historyIndex:o,setHistoryIndex:s,draftMessage:c,setDraftMessage:l,cursorPosition:u,setCursorPosition:d,availableModels:f,setAvailableModels:p,selectedModel:m,setSelectedModel:ne,selectedModelIdRef:g,showModelMenu:_,setShowModelMenu:v,showPlusMenu:y,setShowPlusMenu:b,attachments:x,setAttachments:S,planMode:C,setPlanMode:w,allFiles:T,setAllFiles:E,showSuggestions:D,setShowSuggestions:O,suggestionQuery:k,setSuggestionQuery:A,selectedIndex:j,setSelectedIndex:M,slashCommands:N,setSlashCommands:P,skills:F,setSkills:I,showCommandSuggestions:L,setShowCommandSuggestions:R,commandQuery:z,setCommandQuery:B,fileInputRef:V,textareaRef:H,modelMenuRef:U,plusMenuRef:W,suggestionsRef:G,commandSuggestionsRef:te,handleNewChat:async()=>{if(n.selectedThreadId)try{let e=await ee(n.selectedThreadId);r({type:Y.ClearMessages}),console.log(`New conversation started:`,e);let i=await t(n.selectedThreadId);r({type:Y.SetMessages,messages:i.messages})}catch(e){console.error(`Failed to start new chat:`,e)}},state:n,dispatch:r}}var Ei=e=>{$e(e)};function Di(e){let t=(0,X.c)(97),{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}=e,L;t[0]!==i||t[1]!==f||t[2]!==l||t[3]!==s||t[4]!==n||t[5]!==o||t[6]!==F||t[7]!==d||t[8]!==a||t[9]!==c||t[10]!==P||t[11]!==g||t[12]!==m||t[13]!==r||t[14]!==u||t[15]!==N?(L=()=>{!n.trim()&&i.length===0||c&&a&&(l&&(u(),d()),s?f({type:Y.EnqueueChatMessage,message:{id:`queued-${Date.now()}`,threadId:c,message:n,model:a.id,attachments:i,provider:a.provider,planMode:F}}):o(n,a.id,i,a.provider,F),Ei(n),r(``),P([]),m(-1),g(``),N.current&&(N.current.style.height=`auto`))},t[0]=i,t[1]=f,t[2]=l,t[3]=s,t[4]=n,t[5]=o,t[6]=F,t[7]=d,t[8]=a,t[9]=c,t[10]=P,t[11]=g,t[12]=m,t[13]=r,t[14]=u,t[15]=N,t[16]=L):L=t[16];let R=L,z;t[17]!==_||t[18]!==n||t[19]!==r||t[20]!==b||t[21]!==x||t[22]!==N?(z=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[17]=_,t[18]=n,t[19]=r,t[20]=b,t[21]=x,t[22]=N,t[23]=z):z=t[23];let B=z,V;t[24]!==k||t[25]!==_||t[26]!==n||t[27]!==r||t[28]!==I||t[29]!==O||t[30]!==N?(V=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[24]=k,t[25]=_,t[26]=n,t[27]=r,t[28]=I,t[29]=O,t[30]=N,t[31]=V):V=t[31];let H=V,U;t[32]!==k||t[33]!==_||t[34]!==n||t[35]!==r||t[36]!==O||t[37]!==N?(U=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[32]=k,t[33]=_,t[34]=n,t[35]=r,t[36]=O,t[37]=N,t[38]=U):U=t[38];let ee=U,W,G,te,ne;if(t[39]!==C||t[40]!==k||t[41]!==h||t[42]!==R||t[43]!==p||t[44]!==H||t[45]!==B||t[46]!==ee||t[47]!==n||t[48]!==T||t[49]!==c||t[50]!==w||t[51]!==A||t[52]!==v||t[53]!==g||t[54]!==m||t[55]!==r||t[56]!==E||t[57]!==O||t[58]!==b||t[59]!==S||t[60]!==D||t[61]!==y||t[62]!==M||t[63]!==j||t[64]!==x){te=e=>{if(D){if(e.key===`ArrowDown`){e.preventDefault(),E((T+1)%W.length);return}if(e.key===`ArrowUp`){e.preventDefault(),E((T-1+W.length)%W.length);return}if(e.key===`Enter`||e.key===`Tab`){e.preventDefault();let t=W[T];t&&(t.type===`command`?H(t.data):ee(t.data));return}if(e.key===`Escape`){O(!1);return}}if(y){let t=G.length>0;if(e.key===`ArrowDown`&&t){e.preventDefault(),E((T+1)%G.length);return}if(e.key===`ArrowUp`&&t){e.preventDefault(),E((T-1+G.length)%G.length);return}if(e.key===`Enter`||e.key===`Tab`){e.preventDefault(),G[T]&&B(G[T]);return}if(e.key===`Escape`){b(!1);return}}if(e.key===`Enter`&&!e.shiftKey){e.preventDefault(),R();return}let t=Rt();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[69]!==C||t[70]!==c||t[71]!==w||t[72]!==A||t[73]!==v||t[74]!==r||t[75]!==E||t[76]!==O||t[77]!==b||t[78]!==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&&Yt(c).then(e=>{w(e)}).catch(Ai))}else b(!1)}else b(!1)}let o=e.target;o.style.height=`auto`,o.style.height=`${Math.min(o.scrollHeight,160)}px`},t[69]=C,t[70]=c,t[71]=w,t[72]=A,t[73]=v,t[74]=r,t[75]=E,t[76]=O,t[77]=b,t[78]=S,t[79]=e):e=t[79],ne=e;let i;if(t[80]!==k||t[81]!==M||t[82]!==j){let e;t[84]===k?e=t[85]:(e=e=>e.name.toLowerCase().includes(k.toLowerCase()),t[84]=k,t[85]=e);let n=j.filter(e),r;t[86]===k?r=t[87]:(r=e=>e.name.toLowerCase().includes(k.toLowerCase()),t[86]=k,t[87]=r);let a=M.filter(r);i=[...n.map(ki),...a.map(Oi)],t[80]=k,t[81]=M,t[82]=j,t[83]=i}else i=t[83];W=i.slice(0,10),G=y?C.filter(e=>e.toLowerCase().includes(x.toLowerCase())).slice(0,10):[],t[39]=C,t[40]=k,t[41]=h,t[42]=R,t[43]=p,t[44]=H,t[45]=B,t[46]=ee,t[47]=n,t[48]=T,t[49]=c,t[50]=w,t[51]=A,t[52]=v,t[53]=g,t[54]=m,t[55]=r,t[56]=E,t[57]=O,t[58]=b,t[59]=S,t[60]=D,t[61]=y,t[62]=M,t[63]=j,t[64]=x,t[65]=W,t[66]=G,t[67]=te,t[68]=ne}else W=t[65],G=t[66],te=t[67],ne=t[68];let re;return t[88]!==W||t[89]!==G||t[90]!==te||t[91]!==R||t[92]!==ne||t[93]!==H||t[94]!==B||t[95]!==ee?(re={handleSend:R,handleKeyDown:te,handleTextareaInput:ne,insertFileReference:B,insertCommand:H,insertSkill:ee,allSuggestions:W,fileSuggestions:G},t[88]=W,t[89]=G,t[90]=te,t[91]=R,t[92]=ne,t[93]=H,t[94]=B,t[95]=ee,t[96]=re):re=t[96],re}function Oi(e){return{type:`skill`,data:e}}function ki(e){return{type:`command`,data:e}}function Ai(e){return console.error(`Failed to fetch files:`,e)}function ji(e){let t=(0,X.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(Ni),...s.map(Mi)].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)(wt,{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:J(`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)(wt,{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:J(`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)(je,{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 Mi(e){return{type:`skill`,data:e}}function Ni(e){return{type:`command`,data:e}}function Pi(e){return e.startsWith(`image/`)}function Fi(e){let t=(0,X.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:Pi(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)(xt,{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)(g,{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)(xt,{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 Ii(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 Li(e){let t=(0,X.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)(p,{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:J(`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)(Ot,{className:`h-4 w-4 text-blue-500`}):(0,Q.jsx)(Nt,{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 Ri(e){let t=(0,X.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:zi}),t[0]=r,t[1]=i,t[2]=a):a=t[2],a}function zi(e){e.currentTarget.style.visibility=`hidden`}function Bi(e){let t=(0,X.c)(24),{availableModels:n,selectedModel:r,onModelSelect:i}=e,[a,o]=Z.useState(!1),s=Z.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),Z.useEffect(c,l);let u;t[3]===i?u=t[4]:(u=e=>{i(e),o(!1)},t[3]=i,t[4]=u);let f=u,p;t[5]===a?p=t[6]:(p=()=>o(!a),t[5]=a,t[6]=p);let m=r?.provider,h;t[7]===m?h=t[8]:(h=(0,Q.jsx)(Ri,{provider:m}),t[7]=m,t[8]=h);let g;t[9]===r?g=t[10]:(g=r?sr(r.id):`No model`,t[9]=r,t[10]=g);let _;t[11]===Symbol.for(`react.memo_cache_sentinel`)?(_=(0,Q.jsx)(d,{className:`h-3 w-3`}),t[11]=_):_=t[11];let v;t[12]!==p||t[13]!==h||t[14]!==g?(v=(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:p,children:[h,g,_]}),t[12]=p,t[13]=h,t[14]=g,t[15]=v):v=t[15];let y;t[16]!==n||t[17]!==f||t[18]!==r?.id||t[19]!==a?(y=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(Vi,{})).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)(Ri,{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:()=>f(e),children:sr(e.id)},e.id))]},t)})}),t[16]=n,t[17]=f,t[18]=r?.id,t[19]=a,t[20]=y):y=t[20];let b;return t[21]!==y||t[22]!==v?(b=(0,Q.jsxs)(`div`,{className:`relative`,ref:s,children:[v,y]}),t[21]=y,t[22]=v,t[23]=b):b=t[23],b}function Vi(e,t){let n=t.provider??`Other`;return e[n]||(e[n]=[]),e[n].push(t),e}function Hi(e){let t=(0,X.c)(23),{onFileAttach:n,onPlanModeToggle:r,onNewChat:i}=e,[a,o]=Z.useState(!1),s=Z.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),Z.useEffect(c,l);let u;t[3]===n?u=t[4]:(u=()=>{n(),o(!1)},t[3]=n,t[4]=u);let d=u,f;t[5]===r?f=t[6]:(f=()=>{r(),o(!1)},t[5]=r,t[6]=f);let p=f,m;t[7]===i?m=t[8]:(m=()=>{o(!1),i()},t[7]=i,t[8]=m);let h=m,_;t[9]===a?_=t[10]:(_=()=>o(!a),t[9]=a,t[10]=_);let v,y;t[11]===Symbol.for(`react.memo_cache_sentinel`)?(v=(0,Q.jsx)(Gt,{}),y=(0,Q.jsx)(`span`,{className:`sr-only`,children:`More options`}),t[11]=v,t[12]=y):(v=t[11],y=t[12]);let b;t[13]===_?b=t[14]:(b=(0,Q.jsxs)(q,{variant:`action`,size:`icon-sm`,onClick:_,children:[v,y]}),t[13]=_,t[14]=b);let x;t[15]!==d||t[16]!==h||t[17]!==p||t[18]!==a?(x=a&&(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:d,children:[(0,Q.jsx)(g,{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:p,children:[(0,Q.jsx)(he,{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:h,children:[(0,Q.jsx)(gt,{className:`h-3.5 w-3.5`}),`New Chat`]})]}),t[15]=d,t[16]=h,t[17]=p,t[18]=a,t[19]=x):x=t[19];let S;return t[20]!==x||t[21]!==b?(S=(0,Q.jsxs)(`div`,{className:`relative`,ref:s,children:[b,x]}),t[20]=x,t[21]=b,t[22]=S):S=t[22],S}function Ui(e){let t=(0,X.c)(14),{onToggleSpeech:n}=e,{isListening:r,isSupported:i}=wi();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)(F,{}):(0,Q.jsx)(O,{}),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)(rr,{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)(er,{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)(nr,{children:[l,d]}),t[11]=l,t[12]=d,t[13]=f):f=t[13],f}function Wi({threadId:e,currentConversationId:t,children:n}){let[r,i]=(0,Z.useState)(null),[a,o]=(0,Z.useState)(null),[s,c]=(0,Z.useState)(null),[l,u]=(0,Z.useState)(!1),[d,f]=(0,Z.useState)(null),[p,m]=(0,Z.useState)(!1),[h,g]=(0,Z.useState)(!1);if((0,Z.useEffect)(()=>{if(!p||h||!e)return;async function n(){u(!0),f(null);try{let n=(await Ht(e)).currentConversationId??t,[r,a]=await Promise.allSettled([ue(e).catch(e=>{throw console.error(`Thread usage summary failed:`,e),e}),n?vt(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+`)`),Mt(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)(nr,{open:p,onOpenChange:e=>{m(e),!e&&h&&g(!1)},children:[(0,Q.jsx)(rr,{asChild:!0,children:n}),(0,Q.jsx)(er,{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)(K,{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)(K,{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)(K,{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)(Ve,{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)(je,{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 Gi(e){let t=(0,X.c)(7),{threadId:n}=e,[r,i]=(0,Z.useState)(),a,o;if(t[0]===n?(a=t[1],o=t[2]):(a=()=>{(async function(){if(n)try{i((await Ht(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,Z.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)(Ve,{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)(Wi,{threadId:n,currentConversationId:r,children:s}),t[4]=r,t[5]=n,t[6]=c):c=t[6],c}function Ki(e){let t=(0,X.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)(xt,{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 qi(e){let t=(0,X.c)(143),{onSend:n,onStop:r,isStreaming:i,disabled:a,initialValue:o,queuedMessages:s,onRemoveQueuedMessage:c,isOverlay:l}=e,u=i===void 0?!1:i,d=l===void 0?!1:l,{isListening:f,transcript:p,startListening:m,stopListening:h,resetTranscript:g}=wi(),_;t[0]===o?_=t[1]:(_={initialValue:o},t[0]=o,t[1]=_);let{message:v,setMessage:y,historyIndex:b,setHistoryIndex:x,draftMessage:S,setDraftMessage:C,cursorPosition:w,setCursorPosition:T,availableModels:E,selectedModel:D,setSelectedModel:O,attachments:k,setAttachments:A,planMode:j,setPlanMode:M,allFiles:N,setAllFiles:P,showSuggestions:F,setShowSuggestions:I,suggestionQuery:L,setSuggestionQuery:R,selectedIndex:z,setSelectedIndex:B,slashCommands:V,skills:H,showCommandSuggestions:U,setShowCommandSuggestions:ee,commandQuery:G,setCommandQuery:te,fileInputRef:ne,textareaRef:re,suggestionsRef:ie,commandSuggestionsRef:ae,handleNewChat:oe,state:se,dispatch:ce}=Ti(_),le=se.selectedThreadId??void 0,ue;t[2]!==N||t[3]!==k||t[4]!==G||t[5]!==w||t[6]!==ce||t[7]!==S||t[8]!==b||t[9]!==f||t[10]!==u||t[11]!==v||t[12]!==n||t[13]!==j||t[14]!==g||t[15]!==z||t[16]!==D||t[17]!==P||t[18]!==A||t[19]!==te||t[20]!==T||t[21]!==C||t[22]!==x||t[23]!==y||t[24]!==M||t[25]!==B||t[26]!==ee||t[27]!==I||t[28]!==R||t[29]!==U||t[30]!==F||t[31]!==H||t[32]!==V||t[33]!==h||t[34]!==L||t[35]!==le||t[36]!==re?(ue={message:v,setMessage:y,attachments:k,selectedModel:D,onSend:n,isStreaming:u,selectedThreadId:le,isListening:f,stopListening:h,resetTranscript:g,dispatch:ce,historyIndex:b,setHistoryIndex:x,draftMessage:S,setDraftMessage:C,cursorPosition:w,setCursorPosition:T,showSuggestions:F,setShowSuggestions:I,suggestionQuery:L,setSuggestionQuery:R,allFiles:N,setAllFiles:P,selectedIndex:z,setSelectedIndex:B,showCommandSuggestions:U,setShowCommandSuggestions:ee,commandQuery:G,setCommandQuery:te,slashCommands:V,skills:H,textareaRef:re,setAttachments:A,planMode:j,setPlanMode:M},t[2]=N,t[3]=k,t[4]=G,t[5]=w,t[6]=ce,t[7]=S,t[8]=b,t[9]=f,t[10]=u,t[11]=v,t[12]=n,t[13]=j,t[14]=g,t[15]=z,t[16]=D,t[17]=P,t[18]=A,t[19]=te,t[20]=T,t[21]=C,t[22]=x,t[23]=y,t[24]=M,t[25]=B,t[26]=ee,t[27]=I,t[28]=R,t[29]=U,t[30]=F,t[31]=H,t[32]=V,t[33]=h,t[34]=L,t[35]=le,t[36]=re,t[37]=ue):ue=t[37];let{handleSend:de,handleKeyDown:K,handleTextareaInput:fe,insertFileReference:pe,insertCommand:me,insertSkill:ge,fileSuggestions:_e}=Di(ue),ve=Z.useRef(``),ye,be;t[38]!==y||t[39]!==p?(ye=()=>{if(p&&p!==ve.current){let e=p.substring(ve.current.length);y(t=>(t.endsWith(` `),t+e)),ve.current=p}},be=[p,y],t[38]=y,t[39]=p,t[40]=ye,t[41]=be):(ye=t[40],be=t[41]),Z.useEffect(ye,be);let xe;t[42]===A?xe=t[43]:(xe=e=>{let t=e.clipboardData?.items;if(!t)return;let n=Array.from(t).filter(Yi);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];A(n=>[...n,{fileName:t.name||`pasted-image.${t.type.split(`/`)[1]||`png`}`,content:e,mimeType:t.type}])},n.readAsDataURL(t)}}},t[42]=A,t[43]=xe);let Se=xe,Ce;t[44]!==f||t[45]!==g||t[46]!==m||t[47]!==h?(Ce=()=>{f?(h(),g()):(g(),m())},t[44]=f,t[45]=g,t[46]=m,t[47]=h,t[48]=Ce):Ce=t[48];let we=Ce,Te=d?`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`,Ee;t[49]!==j||t[50]!==M?(Ee=j&&(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)(he,{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:()=>M(!1),className:`ml-auto`,children:[(0,Q.jsx)(xt,{className:`h-3 w-3 text-accent-foreground`}),(0,Q.jsx)(`span`,{className:`sr-only`,children:`Exit plan mode`})]})]}),t[49]=j,t[50]=M,t[51]=Ee):Ee=t[51];let De=`flex flex-col rounded-2xl border focus-within:ring-2 focus-within:ring-brand pointer-events-auto ${d?`border-border/50 bg-background/80 shadow-lg backdrop-blur-sm`:`border-border bg-background shadow-2xl`}`,Oe;t[52]!==c||t[53]!==s?(Oe=(0,Q.jsx)(Ki,{queuedMessages:s,onRemoveQueuedMessage:c}),t[52]=c,t[53]=s,t[54]=Oe):Oe=t[54];let ke;t[55]!==a||t[56]!==K||t[57]!==Se||t[58]!==fe||t[59]!==v||t[60]!==re?(ke=(0,Q.jsx)(`textarea`,{ref:re,value:v,onChange:fe,onKeyDown:K,onPaste:Se,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[55]=a,t[56]=K,t[57]=Se,t[58]=fe,t[59]=v,t[60]=re,t[61]=ke):ke=t[61];let Ae;t[62]!==G||t[63]!==ae||t[64]!==me||t[65]!==ge||t[66]!==z||t[67]!==B||t[68]!==U||t[69]!==H||t[70]!==V?(Ae=(0,Q.jsx)(ji,{visible:U,commands:V,skills:H,query:G,selectedIndex:z,onSelectCommand:me,onSelectSkill:ge,onMouseEnterSuggestion:B,containerRef:ae}),t[62]=G,t[63]=ae,t[64]=me,t[65]=ge,t[66]=z,t[67]=B,t[68]=U,t[69]=H,t[70]=V,t[71]=Ae):Ae=t[71];let je;t[72]!==_e||t[73]!==pe||t[74]!==z||t[75]!==B||t[76]!==F||t[77]!==L||t[78]!==ie?(je=(0,Q.jsx)(Li,{showSuggestions:F,fileSuggestions:_e,suggestionQuery:L,selectedIndex:z,onSelectFile:pe,onMouseEnterSuggestion:B,containerRef:ie}),t[72]=_e,t[73]=pe,t[74]=z,t[75]=B,t[76]=F,t[77]=L,t[78]=ie,t[79]=je):je=t[79];let Me;t[80]!==k||t[81]!==D?.id||t[82]!==D?.name||t[83]!==D?.supportsImages||t[84]!==A?(Me=k.length>0&&(0,Q.jsxs)(`div`,{className:`px-4`,children:[(0,Q.jsx)(Fi,{attachments:k,onRemove:e=>A(t=>t.filter((t,n)=>n!==e))}),k.some(Ji)&&D?.supportsImages===!1&&(0,Q.jsxs)(`div`,{className:`mb-2 flex items-center gap-1.5 text-xs text-amber-500`,children:[(0,Q.jsx)(Lt,{className:`h-3 w-3 shrink-0`}),(0,Q.jsxs)(`span`,{children:[`Images are not supported by `,D?.name||D?.id]})]})]}),t[80]=k,t[81]=D?.id,t[82]=D?.name,t[83]=D?.supportsImages,t[84]=A,t[85]=Me):Me=t[85];let Ne;t[86]===ne?Ne=t[87]:(Ne=()=>ne.current?.click(),t[86]=ne,t[87]=Ne);let Pe;t[88]===M?Pe=t[89]:(Pe=()=>M(!0),t[88]=M,t[89]=Pe);let Fe;t[90]!==oe||t[91]!==Ne||t[92]!==Pe?(Fe=(0,Q.jsx)(Hi,{onFileAttach:Ne,onPlanModeToggle:Pe,onNewChat:oe}),t[90]=oe,t[91]=Ne,t[92]=Pe,t[93]=Fe):Fe=t[93];let Ie;t[94]===we?Ie=t[95]:(Ie=(0,Q.jsx)(Ui,{onToggleSpeech:we}),t[94]=we,t[95]=Ie);let Le=se.selectedThreadId??void 0,Re;t[96]===Le?Re=t[97]:(Re=(0,Q.jsx)(Gi,{threadId:Le}),t[96]=Le,t[97]=Re);let ze;t[98]!==E||t[99]!==D||t[100]!==O?(ze=(0,Q.jsx)(Bi,{availableModels:E,selectedModel:D,onModelSelect:O}),t[98]=E,t[99]=D,t[100]=O,t[101]=ze):ze=t[101];let Be;t[102]!==Fe||t[103]!==Ie||t[104]!==Re||t[105]!==ze?(Be=(0,Q.jsxs)(`div`,{className:`flex items-center gap-1`,children:[Fe,Ie,Re,ze]}),t[102]=Fe,t[103]=Ie,t[104]=Re,t[105]=ze,t[106]=Be):Be=t[106];let Ve=u?r:de,He;t[107]!==k.length||t[108]!==a||t[109]!==u||t[110]!==v||t[111]!==D?(He=!u&&((a??!1)||!v.trim()&&k.length===0||!D),t[107]=k.length,t[108]=a,t[109]=u,t[110]=v,t[111]=D,t[112]=He):He=t[112];let Ue;t[113]===u?Ue=t[114]:(Ue=u?(0,Q.jsx)(Qe,{className:`h-3 w-3 fill-current`}):(0,Q.jsx)(W,{className:`h-3 w-3`}),t[113]=u,t[114]=Ue);let We=u?`Stop generation`:`Send message`,Ge;t[115]===We?Ge=t[116]:(Ge=(0,Q.jsx)(`span`,{className:`sr-only`,children:We}),t[115]=We,t[116]=Ge);let Ke;t[117]!==Ve||t[118]!==He||t[119]!==Ue||t[120]!==Ge?(Ke=(0,Q.jsxs)(q,{size:`icon`,className:`h-7 w-7 rounded-full`,onClick:Ve,disabled:He,children:[Ue,Ge]}),t[117]=Ve,t[118]=He,t[119]=Ue,t[120]=Ge,t[121]=Ke):Ke=t[121];let qe;t[122]!==Be||t[123]!==Ke?(qe=(0,Q.jsxs)(`div`,{className:`flex items-center justify-between px-3 pb-2`,children:[Be,Ke]}),t[122]=Be,t[123]=Ke,t[124]=qe):qe=t[124];let Je;t[125]!==De||t[126]!==Oe||t[127]!==ke||t[128]!==Ae||t[129]!==je||t[130]!==Me||t[131]!==qe?(Je=(0,Q.jsxs)(`div`,{className:De,children:[Oe,ke,Ae,je,Me,qe]}),t[125]=De,t[126]=Oe,t[127]=ke,t[128]=Ae,t[129]=je,t[130]=Me,t[131]=qe,t[132]=Je):Je=t[132];let Ye;t[133]===A?Ye=t[134]:(Ye=e=>Ii(e,e=>A(t=>[...t,...e])),t[133]=A,t[134]=Ye);let Xe;t[135]!==ne||t[136]!==Ye?(Xe=(0,Q.jsx)(`input`,{ref:ne,type:`file`,multiple:!0,className:`hidden`,onChange:Ye}),t[135]=ne,t[136]=Ye,t[137]=Xe):Xe=t[137];let Ze;return t[138]!==Te||t[139]!==Ee||t[140]!==Je||t[141]!==Xe?(Ze=(0,Q.jsxs)(`div`,{className:Te,children:[Ee,Je,Xe]}),t[138]=Te,t[139]=Ee,t[140]=Je,t[141]=Xe,t[142]=Ze):Ze=t[142],Ze}function Ji(e){return e.mimeType.startsWith(`image/`)}function Yi(e){return e.type.startsWith(`image/`)}function Xi({threadId:e}){let[t,n]=(0,Z.useState)(!1);return(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)(nr,{children:[(0,Q.jsx)(rr,{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 Ge(e);await navigator.clipboard.writeText(t)}finally{n(!1)}}},disabled:t,"aria-label":`Copy repository folder path`,children:(0,Q.jsx)(ae,{className:`h-3 w-3`})})}),(0,Q.jsx)(er,{side:`top`,className:`bg-slate-900 text-white`,children:`Copy repository folder path`})]})})}function Zi(){let{state:e,dispatch:n}=Hn(),[r,i]=(0,Z.useState)(null),[a,o]=(0,Z.useState)(!1),s=(0,Z.useRef)(``),c=(0,Z.useRef)(``),l=(0,Z.useRef)([]),d=(0,Z.useRef)(!1),f=(0,Z.useRef)(null),p=(0,Z.useRef)(null),m=(0,Z.useRef)(()=>{}),[h,g]=(0,Z.useState)(null),_=(0,Z.useRef)(!1),v=(0,Z.useRef)(!1),y=(0,Z.useRef)(null),b=(0,Z.useRef)(null),x=(0,Z.useRef)(null),{selectedThreadId:S,selectedProjectId:C,messages:w,queuedChatMessages:E,isStreaming:D,streamingModel:O,processingThreadIds:k}=e,A=!!(S&&k.includes(S)),j=(0,Z.useCallback)(t=>{if(f.current=null,p.current=null,_.current){_.current=!1;return}let r=l.current,i=Qn(r)||`...`;if(y.current&&(r.length===0||i===`...`)){let r={messageId:`msg-${Date.now()}-error`,sender:`agent`,content:`Error: ${y.current}`,contentType:`text`,timestamp:new Date().toISOString(),model:e.streamingModel||t,isThinking:!1};n({type:Y.AddMessage,message:r}),n({type:Y.ResetStream}),S&&n({type:Y.RemoveProcessingThread,threadId:S}),y.current=null;return}let a={messageId:`msg-${Date.now()}-agent`,sender:`agent`,content:i,contentType:`markdown`,timestamp:new Date().toISOString(),model:e.streamingModel||t,isThinking:!1};s.current=``,c.current=``,l.current=[],y.current=null,n({type:Y.AddMessage,message:a}),n({type:Y.ResetStream}),S&&(n({type:Y.MarkThreadCompleted,threadId:S}),n({type:Y.RemoveProcessingThread,threadId:S}))},[e.streamingModel,n,S]);(0,Z.useEffect)(()=>{m.current=j},[j]);let M=(0,Z.useCallback)(()=>{S&&g(S),_.current=!0,S&&Dt(S),f.current&&=(f.current.abort(),null),p.current&&=(p.current(),null),s.current=``,c.current=``,l.current=[],y.current=null;let t={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};n({type:Y.AddMessage,message:t}),n({type:Y.ResetStream}),S&&(n({type:Y.MarkThreadCompleted,threadId:S}),n({type:Y.RemoveProcessingThread,threadId:S}))},[S,n,e.streamingModel]);(0,Z.useEffect)(()=>{v.current&&!D&&f.current&&(f.current.abort(),f.current=null,p.current&&=(p.current(),null),m.current(O||`default`)),v.current=D},[D,O]),(0,Z.useEffect)(()=>{if(b.current&&=(clearTimeout(b.current),null),D){let e=12e4,t=n=>{b.current&&=(clearTimeout(b.current),null),b.current=setTimeout(()=>{let n=Date.now(),r=x?.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`),f.current&&=(f.current.abort(),null),p.current&&=(p.current(),null),m.current(O||`default`)},n)},n=e;if(x?.current!=null){let t=Date.now()-x.current;n=t>=e?0:e-t}t(n)}return()=>{b.current&&=(clearTimeout(b.current),null)}},[D,O]),(0,Z.useEffect)(()=>()=>{f.current&&=(f.current.abort(),null),p.current&&=(p.current(),null),n({type:Y.ResetStream})},[S,n]),(0,Z.useEffect)(()=>{if(!S)return;let e=!1;async function r(){try{let r=await t(S);e||n({type:Y.SetMessages,messages:r.messages})}catch(t){console.error(`Failed to load chat history:`,t),e||n({type:Y.SetMessages,messages:[]})}}return r(),()=>{e=!0}},[S,C,n]),(0,Z.useEffect)(()=>{if(!S||!A||D)return;let e=new AbortController;return f.current=e,n({type:Y.ResetStream}),n({type:Y.SetStreaming,isStreaming:!0}),s.current=``,c.current=``,l.current=[],d.current=!1,y.current=null,be(S,e.signal).then(t=>{if(!t||e.signal.aborted){m.current(`default`);return}p.current=I(t,e=>{if(e.type===`error`){let t=e.content||`Unknown error occurred`;y.current=t,i(t);return}if(e.type!==`message`){if(e.type===`toolcall_delta`){e.partial?.content?.[0]?.id&&e.delta&&n({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&&n({type:Y.SetStreamModel,model:e.model}),e.type===`thinking`||e.isThinking){c.current+=e.content??``;let t=qn(l.current,`thinking`,e.content??``);l.current=t,n({type:Y.AppendStreamChunk,chunkType:`thinking`,content:e.content??``,segments:t})}else if(e.type===`result`)d.current=!0,s.current=e.content??``,l.current=$n(l.current,e.content??``),n({type:Y.SetStreamContent,content:e.content??``});else{if(d.current)return;s.current+=e.content??``;let t=qn(l.current,`content`,e.content??``);l.current=t,n({type:Y.AppendStreamChunk,chunkType:`content`,content:e.content??``,segments:t})}}},()=>{m.current(`default`)},e=>{if(e.includes(`AbortError`)||e.includes(`canceled`)||e.includes(`BodyStreamBuffer was aborted`)){m.current(`default`);return}y.current=e,i(e)},e=>{if(e.role===`assistant`){let t=e.content??``,r=typeof t==`string`?t:JSON.stringify(t);if(e.isThinking??!1){c.current+=r;let e=qn(l.current,`thinking`,r);l.current=e,n({type:Y.AppendStreamChunk,chunkType:`thinking`,content:r,segments:e});return}let i=!1;if(typeof t==`object`&&Array.isArray(t)&&t.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)d.current=!0,s.current=r,l.current=$n(l.current,r),n({type:Y.SetStreamContent,content:r});else{s.current+=r;let e=qn(l.current,`content`,r);l.current=e,n({type:Y.AppendStreamChunk,chunkType:`content`,content:r,segments:e})}}else if(e.role===`tool`){let t=e.content??``,r=typeof t==`string`?t:JSON.stringify(t);if(r){s.current+=r;let e=qn(l.current,`content`,r);l.current=e,n({type:Y.AppendStreamChunk,chunkType:`content`,content:r,segments:e})}}})}).catch(e=>{if(e instanceof Error&&e.name===`AbortError`){n({type:Y.ResetStream});return}if(e instanceof Error&&e.message.includes(`not currently processing`)){n({type:Y.ResetStream});return}console.error(`Failed to subscribe to chat stream:`,e),n({type:Y.ResetStream})}),()=>{e.abort(),p.current&&=(p.current(),null)}},[S,A]);let N=(0,Z.useCallback)(async(e,t,r,a,h)=>{if(!S)return;i(null),g(null),f.current&&f.current.abort(),p.current&&p.current();let _={messageId:`msg-${Date.now()}`,sender:`user`,content:e,contentType:`text`,timestamp:new Date().toISOString(),model:t,attachments:r.map(e=>({fileName:e.fileName,content:e.content,mimeType:e.mimeType}))};n({type:Y.AddMessage,message:_});let v=e.trim().replace(/\n/g,` `).slice(0,100);C&&S&&(rt(S,{title:v}).catch(e=>{console.error(`Failed to update thread title:`,e)}),n({type:Y.UpdateThreadTitle,projectId:C,threadId:S,title:v})),n({type:Y.ResetStream}),n({type:Y.SetStreaming,isStreaming:!0}),s.current=``,d.current=!1;let b=new AbortController;f.current=b;try{let o=await T(S,e,t,r,b.signal,a,h);if(!o){m.current(t);return}p.current=I(o,e=>{if(e.type===`error`){let t=e.content||`Unknown error occurred`;y.current=t,i(t);return}if(e.type!==`message`){if(e.type===`toolcall_delta`){if(e.partial?.content?.[0]?.id&&e.delta){let t=e.partial.content[0].id,r=e.partial.content[0].name;n({type:Y.UpdateToolCallProgress,toolCallId:t,progress:{toolCallId:t,toolName:r,delta:e.delta,partial:e.partial}})}return}if(e.model&&n({type:Y.SetStreamModel,model:e.model}),e.type===`thinking`||e.isThinking){c.current+=e.content??``;let t=qn(l.current,`thinking`,e.content??``);l.current=t,n({type:Y.AppendStreamChunk,chunkType:`thinking`,content:e.content??``,segments:t})}else if(e.type===`result`)d.current=!0,s.current=e.content??``,l.current=$n(l.current,e.content??``),n({type:Y.SetStreamContent,content:e.content??``});else{if(d.current)return;s.current+=e.content??``;let t=qn(l.current,`content`,e.content??``);l.current=t,n({type:Y.AppendStreamChunk,chunkType:`content`,content:e.content??``,segments:t})}}},()=>{m.current(t)},e=>{if(e.includes(`AbortError`)||e.includes(`canceled`)||e.includes(`BodyStreamBuffer was aborted`)){m.current(t);return}y.current=e,i(e)},e=>{if(e.role===`assistant`){let t=e.content??``,r=typeof t==`string`?t:JSON.stringify(t);if(e.isThinking??!1){c.current+=r;let e=qn(l.current,`thinking`,r);l.current=e,n({type:Y.AppendStreamChunk,chunkType:`thinking`,content:r,segments:e});return}let i=!1;if(typeof t==`object`&&Array.isArray(t)&&t.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)d.current=!0,s.current=r,l.current=$n(l.current,r),n({type:Y.SetStreamContent,content:r});else{s.current+=r;let e=qn(l.current,`content`,r);l.current=e,n({type:Y.AppendStreamChunk,chunkType:`content`,content:r,segments:e})}}else if(e.role===`tool`){let t=e.content??``,r=typeof t==`string`?t:JSON.stringify(t);if(r){s.current+=r;let e=qn(l.current,`content`,r);l.current=e,n({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 u){n({type:Y.ResetStream}),o(!0);return}i(e instanceof Error?e.message:`Failed to send message. Please ensure the CLI server is running on localhost:641`),y.current=e instanceof Error?e.message:`Failed to send message. Please ensure the CLI server is running on localhost:641`,n({type:Y.ResetStream})}},[S,C,n]);(0,Z.useEffect)(()=>{let t=e.pendingChatMessage;if(!t||D||t.threadId!==S)return;let r=setTimeout(()=>{n({type:Y.ClearPendingChatMessage}),N(t.message,t.model,[],t.provider)},100);return()=>clearTimeout(r)},[e.pendingChatMessage,D,S,n,N]);let P=(0,Z.useMemo)(()=>S?E.filter(e=>e.threadId===S):[],[S,E]),F=(0,Z.useRef)(!1);return(0,Z.useEffect)(()=>{if(D||!S||P.length===0||F.current)return;let[e]=P;F.current=!0,n({type:Y.RemoveQueuedChatMessage,queuedMessageId:e.id});let t=setTimeout(()=>{N(e.message,e.model,e.attachments,e.provider,e.planMode),F.current=!1},0);return()=>{clearTimeout(t),F.current=!1}},[n,N,D,P,S]),{error:r,setError:i,handleSend:N,handleStop:M,isStreaming:D,selectedThreadId:S,queuedMessagesForThread:P,handleRemoveQueuedMessage:(0,Z.useCallback)(e=>{let t=P.find(t=>t.id===e);n({type:Y.RemoveQueuedChatMessage,queuedMessageId:e}),!(!t||D||w.length>0||!S)&&N(t.message,t.model,t.attachments,t.provider,t.planMode)},[n,N,D,w.length,P,S]),showEmptyBalanceDialog:a,setShowEmptyBalanceDialog:o}}function Qi(e){let t=(0,X.c)(10),{open:n,onClose:r}=e,i=Sn(),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)(gr,{children:[(0,Q.jsx)(vr,{children:`Balance empty`}),(0,Q.jsx)(yr,{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)(hr,{children:[o,(0,Q.jsx)(_r,{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)(fr,{open:n,onOpenChange:a,children:s}),t[6]=n,t[7]=a,t[8]=s,t[9]=c):c=t[9],c}function $i(){let e=(0,X.c)(20),{state:t}=Hn(),{isCreatingProject:n}=t,{handleSend:r,handleStop:i,isStreaming:a,selectedThreadId:o,queuedMessagesForThread:s,handleRemoveQueuedMessage:c,showEmptyBalanceDialog:l,setShowEmptyBalanceDialog:u}=Zi(),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)(Qi,{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)(qi,{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)(Xi,{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}var ea={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 ta({todo:e,projectId:t,onUpdate:n,onEdit:r,onAction:i,onThreadSelect:a}){let[o,s]=(0,Z.useState)(!1),c=ea[e.status]??[];function l(t){t.stopPropagation(),e.threadId&&a&&a(e.threadId)}async function u(r,a){r.stopPropagation(),s(!0);try{i?await i(e,a):n(await _t(t,e.id,{status:a,working:!0}))}finally{s(!1)}}return(0,Q.jsxs)(`div`,{className:J(`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)(_e,{className:`h-3 w-3 animate-spin text-primary shrink-0`})]}),(c.length>0||e.status!==`Ready`&&e.threadId&&a)&&(0,Q.jsxs)(`div`,{className:`flex gap-1.5 flex-wrap items-center pt-1`,children:[c.map(t=>(0,Q.jsxs)(nr,{children:[(0,Q.jsx)(rr,{asChild:!0,children:(0,Q.jsx)(q,{size:`sm`,variant:`outline`,className:`h-6 px-2 text-xs`,onClick:e=>void u(e,t.target),disabled:o||e.working,children:t.label})}),(0,Q.jsx)(er,{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)(nr,{children:[(0,Q.jsx)(rr,{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:l,children:[(0,Q.jsx)(yt,{className:`h-4 w-4`}),(0,Q.jsx)(`span`,{className:`sr-only`,children:`Open thread`})]})}),(0,Q.jsx)(er,{side:`right`,children:`Open thread`})]})]})]})}var na=Z.forwardRef((e,t)=>{let n=(0,X.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=J(`flex min-h-[80px] w-full rounded-md border border-input bg-background px-3 py-2 text-base ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 md:text-sm`,r),n[3]=r,n[4]=a);let o;return n[5]!==i||n[6]!==t||n[7]!==a?(o=(0,Q.jsx)(`textarea`,{className:a,ref:t,...i}),n[5]=i,n[6]=t,n[7]=a,n[8]=o):o=n[8],o});na.displayName=`Textarea`;var ra=[`Ready`,`Plan`,`Build`,`Test`,`Review`,`Done`],ia={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 aa(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 oa(e){let t=e.getReader();try{for(;;){let{done:e}=await t.read();if(e)break}}catch{}}function sa({projectId:e,addOpen:t,onAddOpenChange:n,onThreadSelect:r}){let{state:i,dispatch:a}=Hn(),[o,s]=(0,Z.useState)([]),[c,l]=(0,Z.useState)(!0),[u,d]=(0,Z.useState)(null),[f,p]=(0,Z.useState)(``),[m,h]=(0,Z.useState)(!1),g=(0,Z.useCallback)(async()=>{try{let t=await Tt(e),n=t.filter(e=>e.threadId&&e.status!==`Done`),r=[...t];await Promise.all(n.map(async t=>{try{await Ht(t.threadId)}catch(n){if(n instanceof Error&&n.message.includes(`not found`)){let n=await _t(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,Z.useEffect)(()=>{g()},[g]),(0,Z.useEffect)(()=>{if(!o.some(e=>e.working))return;let t=setInterval(async()=>{try{let n=await Tt(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,Z.useEffect)(()=>{t&&p(``)},[t]);function _(e){p(e.description),d({todo:e})}function v(){d(null),p(``)}async function y(){if(f.trim()){h(!0);try{let t=await L(e,f);s(e=>[...e,t]),n(!1),p(``)}finally{h(!1)}}}async function b(){if(!(!f.trim()||!u)){h(!0);try{let t=await _t(e,u.todo.id,{description:f});s(e=>e.map(e=>e.id===t.id?t:e)),v()}finally{h(!1)}}}async function x(){if(u){h(!0);try{await ge(e,u.todo.id),s(e=>e.filter(e=>e.id!==u.todo.id)),v()}finally{h(!1)}}}function C(e){s(t=>t.map(t=>t.id===e.id?e:t))}async function w(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 S(e);if(!c)return;let l=null,u=await aa(c,n=>{_t(e,t.id,{status:`Plan`,working:!0,threadId:n}).then(e=>{l=e,C(e)})});if(!u)return;l||C(await _t(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}),rt(u,{model:o,modelProvider:s});let f=await T(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&&oa(f)}async function E(t){let n=await S(e);if(!n)return;let r=null,i=await aa(n,n=>{_t(e,t.id,{status:`Build`,working:!0,threadId:n}).then(e=>{r=e,C(e)})});if(!i)return;r||C(await _t(e,t.id,{status:`Build`,working:!0,threadId:i}));let o=await Ht(i),s=o.model,c=o.modelProvider;if(!s||!c)try{let t=(await bt(`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:``}}),rt(i,{model:s,modelProvider:c}),console.log(`Sending chat message with provider:`,i,t.description,c);let l=await T(i,t.description,s,[],void 0,c);l&&oa(l)}async function D(t,n){n===`Plan`?await w(t):n===`Build`?await E(t):C(await _t(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)(_e,{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:ra.map(t=>{let i=o.filter(e=>e.status===t),a=t===`Ready`;return(0,Q.jsxs)(`div`,{className:J(`flex flex-col rounded-lg border border-t-4 bg-muted/30 min-w-[200px] w-[200px] shrink-0`,ia[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)(Re,{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)(Gt,{className:`h-3 w-3 mr-1`}),`Add Task`]}),i.map(t=>(0,Q.jsx)(ta,{todo:t,projectId:e,onUpdate:C,onEdit:_,onAction:D,onThreadSelect:r},t.id))]})})]},t)})}),(0,Q.jsx)(tt,{open:t,onOpenChange:n,children:(0,Q.jsxs)(Ze,{className:`sm:max-w-2xl`,children:[(0,Q.jsx)(Qt,{children:(0,Q.jsx)(Fe,{children:`Add Task`})}),(0,Q.jsxs)(`div`,{className:`py-2`,children:[(0,Q.jsx)(na,{placeholder:`Describe what needs to be done...`,value:f,onChange:e=>p(e.target.value),rows:12,className:`resize-none text-sm`,autoFocus:!0,onKeyDown:e=>{e.key===`Enter`&&(e.metaKey||e.ctrlKey)&&y()}}),(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)(Bt,{children:(0,Q.jsx)(q,{onClick:()=>void y(),disabled:m||!f.trim(),children:m?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(_e,{className:`h-3 w-3 animate-spin mr-1`}),`Generating title...`]}):`Add`})})]})}),(0,Q.jsx)(tt,{open:u!==null,onOpenChange:e=>!e&&v(),children:(0,Q.jsxs)(Ze,{className:`sm:max-w-2xl`,children:[(0,Q.jsx)(Qt,{children:(0,Q.jsx)(Fe,{children:`Edit Task`})}),(0,Q.jsx)(`div`,{className:`py-2`,children:(0,Q.jsx)(na,{placeholder:`Describe what needs to be done...`,value:f,onChange:e=>p(e.target.value),rows:12,className:`resize-none text-sm`,autoFocus:!0,onKeyDown:e=>{e.key===`Enter`&&(e.metaKey||e.ctrlKey)&&b()}})}),(0,Q.jsxs)(Bt,{className:`gap-2 sm:gap-0`,children:[(0,Q.jsx)(q,{variant:`destructive`,onClick:()=>void x(),disabled:m,className:`mr-auto`,children:`Delete`}),(0,Q.jsx)(q,{onClick:()=>void b(),disabled:m||!f.trim(),children:m?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(_e,{className:`h-3 w-3 animate-spin mr-1`}),`Saving...`]}):`Save`})]})]})})]})}function ca({projectId:e}){let{state:t,dispatch:n}=Hn(),{projects:r}=t,[i,a]=(0,Z.useState)(!1),o=Sn();async function s(t){if(r.find(t=>t.projectId===e)){o(`/`);try{let{getProjects:r,invalidateProjectsCache:i}=await en(async()=>{let{getProjects:e,invalidateProjectsCache:t}=await import(`./dialogs-config-CB7G-sX6.js`).then(e=>e.w);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 He();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 He();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)(sa,{projectId:e,addOpen:i,onAddOpenChange:a,onThreadSelect:s})})})}var la=(0,Z.lazy)(()=>en(()=>import(`./diff-view-kPjfhf7_.js`),__vite__mapDeps([7,1,4,5,0,6,8,9,10,11]))),ua=(0,Z.lazy)(()=>en(()=>import(`./dialogs-config-CB7G-sX6.js`).then(e=>e.t),__vite__mapDeps([0,1])));function da(e){let t=(0,X.c)(48),{onCreateThread:n}=e,{state:r,dispatch:i}=Hn(),a=Sn(),o=Cn(),[s,c]=(0,Z.useState)(!1),[l,u]=(0,Z.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 ot(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,A;t[11]===Symbol.for(`react.memo_cache_sentinel`)?(A=async(e,t,n)=>{try{await V(e,t,n),c(!1),u(null)}catch(e){let t=e;console.error(`Failed to create project:`,t)}},t[11]=A):A=t[11];let j=A,M;t[12]===C?M=t[13]:(M=async()=>{C();try{await re(),c(!1),u(null)}catch(e){let t=e;console.error(`Failed to open folder:`,t)}},t[12]=C,t[13]=M);let N=M,P=o.pathname===`/review`,F=o.pathname===`/todos`,I;t[14]===a?I=t[15]:(I=()=>{a(`/`)},t[14]=a,t[15]=I);let L=I,{selectedProjectId:R}=r,z;t[16]!==C||t[17]!==i||t[18]!==T||t[19]!==L||t[20]!==D||t[21]!==N||t[22]!==p||t[23]!==x||t[24]!==_||t[25]!==f||t[26]!==n||t[27]!==h||t[28]!==g||t[29]!==P||t[30]!==R||t[31]!==d||t[32]!==y||t[33]!==v||t[34]!==F?(z=F&&R?(0,Q.jsx)(ca,{projectId:R}):P&&d?(0,Q.jsx)(Z.Suspense,{fallback:(0,Q.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:`Loading diff view...`}),children:(0,Q.jsx)(la,{threadId:d,onExit:L})}):(0,Q.jsx)(xi,{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:N,error:null,onClearError:fa}),t[16]=C,t[17]=i,t[18]=T,t[19]=L,t[20]=D,t[21]=N,t[22]=p,t[23]=x,t[24]=_,t[25]=f,t[26]=n,t[27]=h,t[28]=g,t[29]=P,t[30]=R,t[31]=d,t[32]=y,t[33]=v,t[34]=F,t[35]=z):z=t[35];let B;t[36]!==P||t[37]!==d||t[38]!==F?(B=!P&&!F&&d&&(0,Q.jsx)($i,{}),t[36]=P,t[37]=d,t[38]=F,t[39]=B):B=t[39];let H=l??void 0,U;t[40]!==s||t[41]!==N||t[42]!==H?(U=(0,Q.jsx)(Z.Suspense,{fallback:null,children:(0,Q.jsx)(ua,{open:s,onOpenChange:c,initialMode:H,onSubmitClone:k,onSubmitWebApp:j,onOpenFolder:N})}),t[40]=s,t[41]=N,t[42]=H,t[43]=U):U=t[43];let ee;return t[44]!==B||t[45]!==U||t[46]!==z?(ee=(0,Q.jsxs)(`div`,{className:`flex h-full flex-col`,children:[z,B,U]}),t[44]=B,t[45]=U,t[46]=z,t[47]=ee):ee=t[47],ee}function fa(){}function pa(e){let t=(0,X.c)(5),{children:n,className:r}=e,i;t[0]===r?i=t[1]:(i=J(`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 ma=an,ha=pn,ga=Z.forwardRef((e,t)=>{let n=(0,X.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=J(`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)(Jt,{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)(jn,{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});ga.displayName=jn.displayName;var _a=Z.forwardRef((e,t)=>{let n=(0,X.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=J(`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)(tn,{ref:t,className:a,...i}),n[5]=i,n[6]=t,n[7]=a,n[8]=o):o=n[8],o});_a.displayName=tn.displayName;var va=Z.forwardRef((e,t)=>{let n=(0,X.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=J(`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)(Rn,{children:(0,Q.jsx)(Bn,{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});va.displayName=Bn.displayName;var ya=Z.forwardRef((e,t)=>{let n=(0,X.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=J(`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)(zn,{ref:t,className:s,...a}),n[7]=a,n[8]=t,n[9]=s,n[10]=c):c=n[10],c});ya.displayName=zn.displayName;var ba=Z.forwardRef((e,t)=>{let n=(0,X.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=J(`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)(vn,{children:(0,Q.jsx)(Ut,{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)(Ln,{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});ba.displayName=Ln.displayName;var xa=Z.forwardRef((e,t)=>{let n=(0,X.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=J(`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)(vn,{children:(0,Q.jsx)(Xe,{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)(on,{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});xa.displayName=on.displayName;var Sa=Z.forwardRef((e,t)=>{let n=(0,X.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=J(`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)(rn,{ref:t,className:s,...a}),n[7]=a,n[8]=t,n[9]=s,n[10]=c):c=n[10],c});Sa.displayName=rn.displayName;var Ca=Z.forwardRef((e,t)=>{let n=(0,X.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=J(`-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)(hn,{ref:t,className:a,...i}),n[5]=i,n[6]=t,n[7]=a,n[8]=o):o=n[8],o});Ca.displayName=hn.displayName;var wa=e=>{let t=(0,X.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=J(`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};wa.displayName=`DropdownMenuShortcut`;var Ta=1,Ea=1e6,Da=0;function Oa(){return Da=(Da+1)%(2**53-1),Da.toString()}var ka=new Map,Aa=e=>{if(ka.has(e))return;let t=setTimeout(()=>{ka.delete(e),Pa({type:`REMOVE_TOAST`,toastId:e})},Ea);ka.set(e,t)},ja=(e,t)=>{switch(t.type){case`ADD_TOAST`:return{...e,toasts:[t.toast,...e.toasts].slice(0,Ta)};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?Aa(n):e.toasts.forEach(e=>{Aa(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)}}},Ma=[],Na={toasts:[]};function Pa(e){Na=ja(Na,e),Ma.forEach(e=>{e(Na)})}function $({...e}){let t=Oa(),n=e=>Pa({type:`UPDATE_TOAST`,toast:{...e,id:t}}),r=()=>Pa({type:`DISMISS_TOAST`,toastId:t});return Pa({type:`ADD_TOAST`,toast:{...e,id:t,open:!0,onOpenChange:e=>{e||r()}}}),{id:t,dismiss:r,update:n}}function Fa(){let e=(0,X.c)(5),[t,n]=Z.useState(Na),r;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(r=()=>(Ma.push(n),()=>{let e=Ma.indexOf(n);e>-1&&Ma.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),Z.useEffect(r,i);let a;return e[3]===t?a=e[4]:(a={...t,toast:$,dismiss:Ia},e[3]=t,e[4]=a),a}function Ia(e){return Pa({type:`DISMISS_TOAST`,toastId:e})}var La=`VS Code`,Ra={"VS Code":`vscode`,Cursor:`cursor`,Windsurf:`windsurf`,Xcode:`xcode`,"Android Studio":`android-studio`,Kiro:`kiro`,Terminal:`terminal`};function za({projectId:e,threadId:t,openWith:n}){let[r,i]=(0,Z.useState)(!1),[a,o]=(0,Z.useState)([]),[s,c]=(0,Z.useState)(n??La),[l,u]=(0,Z.useState)(!0);(0,Z.useEffect)(()=>{(async()=>{try{let e=await ie();o(e),!s&&e.length>0&&c(e[0])}catch(e){console.error(`Failed to fetch available programs:`,e),o([La])}finally{u(!1)}})()},[]),(0,Z.useEffect)(()=>{n&&a.includes(n)&&c(n)},[n,a,c]);let f=async n=>{try{i(!0),c(n),await Ue(e,n),t?await k(t,n):await C(e,n),$({title:`Success`,description:`Opened project in ${n}`})}catch(e){console.error(`Failed to open project in ${n}:`,e);let t=`Failed to open project in ${n}`;if(e instanceof Error){let n=e;t=n.details?n.details:e.message}$({title:`Error`,description:t,variant:`destructive`})}finally{i(!1)}};return l?(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:r,onClick:async()=>{await f(s)},title:`Open in ${s}`,children:(0,Q.jsx)(`img`,{src:`/ide/${Ra[s]||Ra[La]}.svg`,alt:s,className:`h-4 w-4`})}),(0,Q.jsxs)(ma,{children:[(0,Q.jsx)(ha,{asChild:!0,children:(0,Q.jsx)(q,{variant:`outline`,size:`sm`,className:`h-8 w-8 rounded-l-none px-1 border-transparent`,disabled:r,children:(0,Q.jsx)(d,{className:`h-3.5 w-3.5`})})}),(0,Q.jsx)(va,{align:`end`,children:a.map(e=>(0,Q.jsxs)(ya,{onClick:()=>f(e),disabled:r,className:`flex items-center gap-2`,children:[(0,Q.jsx)(`img`,{src:`/ide/${Ra[e]||Ra[La]}.svg`,alt:e,className:`h-4 w-4`}),e]},e))})]})]})}function Ba(){return{autoGenerateCommitMessage:Ye(),autoGeneratePRInfo:Te(),privateRepositoryDefault:Xt()}}function Va(e){e.autoGenerateCommitMessage!==void 0&&Ne(e.autoGenerateCommitMessage),e.autoGeneratePRInfo!==void 0&&qt(e.autoGeneratePRInfo),e.privateRepositoryDefault!==void 0&&ce(e.privateRepositoryDefault)}function Ha(e){return e?!0:($({title:`Error`,description:`No thread selected`,variant:`destructive`}),!1)}function Ua(e){let t=(0,X.c)(57),{open:n,onOpenChange:r,commitMessage:i,onCommitMessageChange:a,autoGenerateCommitMessage:o,onAutoGenerateChange:s,isGeneratingMessage:c,isLoading:l,onGenerateMessage:u,onCommit:d,currentBranch:f}=e,p;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(p=(0,Q.jsx)(Fe,{children:`Commit Changes`}),t[0]=p):p=t[0];let m;t[1]===f?m=t[2]:(m=(0,Q.jsxs)(Qt,{children:[p,(0,Q.jsxs)(De,{children:[`Enter a commit message for your changes on branch `,f]})]}),t[1]=f,t[2]=m);let h;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(h=(0,Q.jsx)(ut,{htmlFor:`commit-message`,children:`Commit Message`}),t[3]=h):h=t[3];let g;t[4]===a?g=t[5]:(g=e=>a(e.target.value),t[4]=a,t[5]=g);let _;t[6]!==i||t[7]!==g?(_=(0,Q.jsx)(na,{id:`commit-message`,placeholder:`Enter commit message...`,value:i,onChange:g,rows:4,className:`pr-10`}),t[6]=i,t[7]=g,t[8]=_):_=t[8];let v=c||l,y;t[9]===c?y=t[10]:(y=c?(0,Q.jsx)(_e,{className:`h-3.5 w-3.5 animate-spin`}):(0,Q.jsx)(Vt,{className:`h-3.5 w-3.5`}),t[9]=c,t[10]=y);let b;t[11]!==u||t[12]!==v||t[13]!==y?(b=(0,Q.jsx)(rr,{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:v,children:y})}),t[11]=u,t[12]=v,t[13]=y,t[14]=b):b=t[14];let x=c?`Generating commit message...`:`Generate commit message with AI`,S;t[15]===x?S=t[16]:(S=(0,Q.jsx)(er,{children:x}),t[15]=x,t[16]=S);let C;t[17]!==S||t[18]!==b?(C=(0,Q.jsx)(tr,{children:(0,Q.jsxs)(nr,{children:[b,S]})}),t[17]=S,t[18]=b,t[19]=C):C=t[19];let w;t[20]!==C||t[21]!==_?(w=(0,Q.jsxs)(`div`,{className:`grid gap-2`,children:[h,(0,Q.jsxs)(`div`,{className:`relative`,children:[_,C]})]}),t[20]=C,t[21]=_,t[22]=w):w=t[22];let T;t[23]===s?T=t[24]:(T=e=>s(e===!0),t[23]=s,t[24]=T);let E;t[25]!==o||t[26]!==T?(E=(0,Q.jsx)(or,{id:`auto-generate`,checked:o,onCheckedChange:T}),t[25]=o,t[26]=T,t[27]=E):E=t[27];let D;t[28]===Symbol.for(`react.memo_cache_sentinel`)?(D=(0,Q.jsx)(ut,{htmlFor:`auto-generate`,className:`text-sm font-normal`,children:`Auto generate commit messages`}),t[28]=D):D=t[28];let O;t[29]===E?O=t[30]:(O=(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[E,D]}),t[29]=E,t[30]=O);let k;t[31]!==w||t[32]!==O?(k=(0,Q.jsxs)(`div`,{className:`grid gap-4 py-4`,children:[w,O]}),t[31]=w,t[32]=O,t[33]=k):k=t[33];let A;t[34]===r?A=t[35]:(A=()=>r(!1),t[34]=r,t[35]=A);let j;t[36]!==l||t[37]!==A?(j=(0,Q.jsx)(q,{variant:`outline`,onClick:A,disabled:l,children:`Cancel`}),t[36]=l,t[37]=A,t[38]=j):j=t[38];let M;t[39]!==i||t[40]!==l?(M=l||!i.trim(),t[39]=i,t[40]=l,t[41]=M):M=t[41];let N=l?`Committing...`:`Commit`,P;t[42]!==d||t[43]!==M||t[44]!==N?(P=(0,Q.jsx)(q,{onClick:d,disabled:M,children:N}),t[42]=d,t[43]=M,t[44]=N,t[45]=P):P=t[45];let F;t[46]!==j||t[47]!==P?(F=(0,Q.jsxs)(Bt,{children:[j,P]}),t[46]=j,t[47]=P,t[48]=F):F=t[48];let I;t[49]!==k||t[50]!==m||t[51]!==F?(I=(0,Q.jsxs)(Ze,{children:[m,k,F]}),t[49]=k,t[50]=m,t[51]=F,t[52]=I):I=t[52];let L;return t[53]!==r||t[54]!==n||t[55]!==I?(L=(0,Q.jsx)(tt,{open:n,onOpenChange:r,children:I}),t[53]=r,t[54]=n,t[55]=I,t[56]=L):L=t[56],L}function Wa(e){let t=(0,X.c)(62),{open:n,onOpenChange:r,prTitle:i,onPrTitleChange:a,prDescription:o,onPrDescriptionChange:s,isGeneratingPRInfo:c,isLoading:l,onGeneratePRInfo:u,onCreatePR:d,currentBranch:f,autoGeneratePRInfo:p,onAutoGeneratePRInfoChange:m}=e,h;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(h=(0,Q.jsx)(Fe,{children:`Create Pull Request`}),t[0]=h):h=t[0];let g;t[1]===f?g=t[2]:(g=(0,Q.jsxs)(Qt,{children:[h,(0,Q.jsxs)(De,{children:[`Create a pull request for branch `,f]})]}),t[1]=f,t[2]=g);let _;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(_=(0,Q.jsx)(ut,{htmlFor:`pr-title`,children:`Title (optional)`}),t[3]=_):_=t[3];let v=f||`Enter PR title...`,y;t[4]===a?y=t[5]:(y=e=>a(e.target.value),t[4]=a,t[5]=y);let b;t[6]!==i||t[7]!==v||t[8]!==y?(b=(0,Q.jsxs)(`div`,{className:`grid gap-2`,children:[_,(0,Q.jsx)(Le,{id:`pr-title`,placeholder:v,value:i,onChange:y})]}),t[6]=i,t[7]=v,t[8]=y,t[9]=b):b=t[9];let x;t[10]===Symbol.for(`react.memo_cache_sentinel`)?(x=(0,Q.jsx)(ut,{htmlFor:`pr-description`,children:`Description (optional)`}),t[10]=x):x=t[10];let S;t[11]===s?S=t[12]:(S=e=>s(e.target.value),t[11]=s,t[12]=S);let C;t[13]!==o||t[14]!==S?(C=(0,Q.jsx)(na,{id:`pr-description`,placeholder:`Enter PR description...`,value:o,onChange:S,rows:4,className:`pr-10`}),t[13]=o,t[14]=S,t[15]=C):C=t[15];let w=c||l,T;t[16]===c?T=t[17]:(T=c?(0,Q.jsx)(_e,{className:`h-3.5 w-3.5 animate-spin`}):(0,Q.jsx)(Vt,{className:`h-3.5 w-3.5`}),t[16]=c,t[17]=T);let E;t[18]!==u||t[19]!==w||t[20]!==T?(E=(0,Q.jsx)(rr,{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:w,children:T})}),t[18]=u,t[19]=w,t[20]=T,t[21]=E):E=t[21];let D=c?`Generating PR description...`:`Generate PR title and description with AI`,O;t[22]===D?O=t[23]:(O=(0,Q.jsx)(er,{children:D}),t[22]=D,t[23]=O);let k;t[24]!==E||t[25]!==O?(k=(0,Q.jsx)(tr,{children:(0,Q.jsxs)(nr,{children:[E,O]})}),t[24]=E,t[25]=O,t[26]=k):k=t[26];let A;t[27]!==k||t[28]!==C?(A=(0,Q.jsxs)(`div`,{className:`grid gap-2`,children:[x,(0,Q.jsxs)(`div`,{className:`relative`,children:[C,k]})]}),t[27]=k,t[28]=C,t[29]=A):A=t[29];let j;t[30]===m?j=t[31]:(j=e=>m(e===!0),t[30]=m,t[31]=j);let M;t[32]!==p||t[33]!==j?(M=(0,Q.jsx)(or,{id:`auto-generate-pr`,checked:p,onCheckedChange:j}),t[32]=p,t[33]=j,t[34]=M):M=t[34];let N;t[35]===Symbol.for(`react.memo_cache_sentinel`)?(N=(0,Q.jsx)(ut,{htmlFor:`auto-generate-pr`,className:`text-sm font-normal`,children:`Auto generate PR title and description`}),t[35]=N):N=t[35];let P;t[36]===M?P=t[37]:(P=(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[M,N]}),t[36]=M,t[37]=P);let F;t[38]!==A||t[39]!==P||t[40]!==b?(F=(0,Q.jsxs)(`div`,{className:`grid gap-4 py-4`,children:[b,A,P]}),t[38]=A,t[39]=P,t[40]=b,t[41]=F):F=t[41];let I;t[42]===r?I=t[43]:(I=()=>r(!1),t[42]=r,t[43]=I);let L;t[44]!==l||t[45]!==I?(L=(0,Q.jsx)(q,{variant:`outline`,onClick:I,disabled:l,children:`Cancel`}),t[44]=l,t[45]=I,t[46]=L):L=t[46];let R=l?`Creating...`:`Create PR`,z;t[47]!==l||t[48]!==d||t[49]!==R?(z=(0,Q.jsx)(q,{onClick:d,disabled:l,children:R}),t[47]=l,t[48]=d,t[49]=R,t[50]=z):z=t[50];let B;t[51]!==L||t[52]!==z?(B=(0,Q.jsxs)(Bt,{children:[L,z]}),t[51]=L,t[52]=z,t[53]=B):B=t[53];let V;t[54]!==g||t[55]!==F||t[56]!==B?(V=(0,Q.jsxs)(Ze,{children:[g,F,B]}),t[54]=g,t[55]=F,t[56]=B,t[57]=V):V=t[57];let H;return t[58]!==r||t[59]!==n||t[60]!==V?(H=(0,Q.jsx)(tt,{open:n,onOpenChange:r,children:V}),t[58]=r,t[59]=n,t[60]=V,t[61]=H):H=t[61],H}function Ga(e){let t=(0,X.c)(48),{open:n,onOpenChange:r,repoName:i,onRepoNameChange:a,repoDescription:o,onRepoDescriptionChange:s,isPrivateRepo:c,onPrivateRepoChange:l,isLoading:u,onCreateRepo:d}=e,f;t[0]!==r||t[1]!==s||t[2]!==a?(f=e=>{e||(a(``),s(``)),r(e)},t[0]=r,t[1]=s,t[2]=a,t[3]=f):f=t[3];let p;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(p=(0,Q.jsxs)(Qt,{children:[(0,Q.jsx)(Fe,{children:`Create GitHub Repository`}),(0,Q.jsx)(De,{children:`Create a new GitHub repository and push your local repository`})]}),t[4]=p):p=t[4];let m;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(m=(0,Q.jsx)(ut,{htmlFor:`repo-name`,children:`Repository Name (optional)`}),t[5]=m):m=t[5];let h;t[6]===a?h=t[7]:(h=e=>a(e.target.value),t[6]=a,t[7]=h);let g;t[8]!==i||t[9]!==h?(g=(0,Q.jsxs)(`div`,{className:`grid gap-2`,children:[m,(0,Q.jsx)(Le,{id:`repo-name`,placeholder:`Leave empty to use current folder name`,value:i,onChange:h})]}),t[8]=i,t[9]=h,t[10]=g):g=t[10];let _;t[11]===Symbol.for(`react.memo_cache_sentinel`)?(_=(0,Q.jsx)(ut,{htmlFor:`repo-description`,children:`Description (optional)`}),t[11]=_):_=t[11];let v;t[12]===s?v=t[13]:(v=e=>s(e.target.value),t[12]=s,t[13]=v);let y;t[14]!==o||t[15]!==v?(y=(0,Q.jsxs)(`div`,{className:`grid gap-2`,children:[_,(0,Q.jsx)(na,{id:`repo-description`,placeholder:`Enter repository description...`,value:o,onChange:v,rows:3})]}),t[14]=o,t[15]=v,t[16]=y):y=t[16];let b;t[17]===l?b=t[18]:(b=e=>l(e===!0),t[17]=l,t[18]=b);let x;t[19]!==c||t[20]!==b?(x=(0,Q.jsx)(or,{id:`repo-private`,checked:c,onCheckedChange:b}),t[19]=c,t[20]=b,t[21]=x):x=t[21];let S;t[22]===Symbol.for(`react.memo_cache_sentinel`)?(S=(0,Q.jsx)(ut,{htmlFor:`repo-private`,className:`text-sm font-normal`,children:`Private repository`}),t[22]=S):S=t[22];let C;t[23]===x?C=t[24]:(C=(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[x,S]}),t[23]=x,t[24]=C);let w;t[25]!==C||t[26]!==g||t[27]!==y?(w=(0,Q.jsxs)(`div`,{className:`grid gap-4 py-4`,children:[g,y,C]}),t[25]=C,t[26]=g,t[27]=y,t[28]=w):w=t[28];let T;t[29]===r?T=t[30]:(T=()=>r(!1),t[29]=r,t[30]=T);let E;t[31]!==u||t[32]!==T?(E=(0,Q.jsx)(q,{variant:`outline`,onClick:T,disabled:u,children:`Cancel`}),t[31]=u,t[32]=T,t[33]=E):E=t[33];let D=u?`Creating...`:`Create & Push`,O;t[34]!==u||t[35]!==d||t[36]!==D?(O=(0,Q.jsx)(q,{onClick:d,disabled:u,children:D}),t[34]=u,t[35]=d,t[36]=D,t[37]=O):O=t[37];let k;t[38]!==E||t[39]!==O?(k=(0,Q.jsxs)(Bt,{children:[E,O]}),t[38]=E,t[39]=O,t[40]=k):k=t[40];let A;t[41]!==w||t[42]!==k?(A=(0,Q.jsxs)(Ze,{children:[p,w,k]}),t[41]=w,t[42]=k,t[43]=A):A=t[43];let j;return t[44]!==n||t[45]!==f||t[46]!==A?(j=(0,Q.jsx)(tt,{open:n,onOpenChange:f,children:A}),t[44]=n,t[45]=f,t[46]=A,t[47]=j):j=t[47],j}function Ka(e){let t=(0,X.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)(Fe,{children:`Commit History`}),t[0]=l):l=t[0];let u;t[1]===c?u=t[2]:(u=(0,Q.jsxs)(Qt,{children:[l,(0,Q.jsxs)(De,{children:[`Recent commits on branch `,c]})]}),t[1]=c,t[2]=u);let d;t[3]===a?d=t[4]:(d=a.length>0?a.map(qa):(0,Q.jsx)(`p`,{className:`text-sm text-slate-500 text-center py-8`,children:`No commits found`}),t[3]=a,t[4]=d);let f;t[5]===o?f=t[6]:(f=o&&(0,Q.jsx)(`div`,{className:`p-3 text-center`,children:(0,Q.jsx)(_e,{className:`h-4 w-4 animate-spin inline`})}),t[5]=o,t[6]=f);let p;t[7]!==i.length||t[8]!==a.length||t[9]!==o?(p=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]=p):p=t[10];let m;t[11]!==d||t[12]!==f||t[13]!==p?(m=(0,Q.jsxs)(`div`,{className:`divide-y`,children:[d,f,p]}),t[11]=d,t[12]=f,t[13]=p,t[14]=m):m=t[14];let h;t[15]!==s||t[16]!==m?(h=(0,Q.jsx)(`div`,{className:`flex-1 overflow-y-auto border rounded-lg`,onScroll:s,children:m}),t[15]=s,t[16]=m,t[17]=h):h=t[17];let g;t[18]===r?g=t[19]:(g=(0,Q.jsx)(Bt,{children:(0,Q.jsx)(q,{onClick:()=>r(!1),children:`Close`})}),t[18]=r,t[19]=g);let _;t[20]!==u||t[21]!==h||t[22]!==g?(_=(0,Q.jsxs)(Ze,{className:`max-w-2xl max-h-[80vh] flex flex-col`,children:[u,h,g]}),t[20]=u,t[21]=h,t[22]=g,t[23]=_):_=t[23];let v;return t[24]!==r||t[25]!==n||t[26]!==_?(v=(0,Q.jsx)(tt,{open:n,onOpenChange:r,children:_}),t[24]=r,t[25]=n,t[26]=_,t[27]=v):v=t[27],v}function qa(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 Ja(e){let t=(0,X.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)(Qt,{children:[(0,Q.jsx)(Fe,{children:`Push Branch First`}),(0,Q.jsx)(De,{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 d;t[8]!==c||t[9]!==u?(d=(0,Q.jsxs)(Ze,{children:[s,(0,Q.jsxs)(Bt,{children:[c,u]})]}),t[8]=c,t[9]=u,t[10]=d):d=t[10];let f;return t[11]!==r||t[12]!==n||t[13]!==d?(f=(0,Q.jsx)(tt,{open:n,onOpenChange:r,children:d}),t[11]=r,t[12]=n,t[13]=d,t[14]=f):f=t[14],f}function Ya(e){let t=(0,X.c)(27),{open:n,onOpenChange:r,onCommitFirst:i,onStashAndPull:a,onCancel:o,isLoading:s}=e,c=s===void 0?!1:s,l;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(l=(0,Q.jsxs)(Qt,{children:[(0,Q.jsxs)(Fe,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(Lt,{className:`h-5 w-5 text-amber-500`}),`Uncommitted Changes Detected`]}),(0,Q.jsx)(De,{children:`You have uncommitted changes. You need to handle them before pulling from the remote branch.`})]}),t[0]=l):l=t[0];let u;t[1]===Symbol.for(`react.memo_cache_sentinel`)?(u=(0,Q.jsx)(`div`,{className:`text-sm text-muted-foreground`,children:`Choose how you want to proceed:`}),t[1]=u):u=t[1];let d;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(d=(0,Q.jsx)(Se,{className:`h-4 w-4 mr-2`}),t[2]=d):d=t[2];let f;t[3]!==c||t[4]!==i?(f=(0,Q.jsxs)(q,{onClick:i,disabled:c,className:`w-full justify-start`,variant:`outline`,children:[d,`Commit changes first, then pull`]}),t[3]=c,t[4]=i,t[5]=f):f=t[5];let p;t[6]===Symbol.for(`react.memo_cache_sentinel`)?(p=(0,Q.jsx)(z,{className:`h-4 w-4 mr-2`}),t[6]=p):p=t[6];let m;t[7]!==c||t[8]!==a?(m=(0,Q.jsxs)(q,{onClick:a,disabled:c,className:`w-full justify-start`,variant:`outline`,children:[p,`Stash changes → Pull → Restore changes`]}),t[7]=c,t[8]=a,t[9]=m):m=t[9];let h;t[10]!==f||t[11]!==m?(h=(0,Q.jsxs)(`div`,{className:`space-y-2`,children:[f,m]}),t[10]=f,t[11]=m,t[12]=h):h=t[12];let g;t[13]===Symbol.for(`react.memo_cache_sentinel`)?(g=(0,Q.jsx)(`strong`,{children:`Commit first:`}),t[13]=g):g=t[13];let _;t[14]===Symbol.for(`react.memo_cache_sentinel`)?(_=(0,Q.jsxs)(`div`,{className:`text-xs text-muted-foreground mt-4`,children:[g,` 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]=_):_=t[14];let v;t[15]===h?v=t[16]:(v=(0,Q.jsx)(`div`,{className:`py-4`,children:(0,Q.jsxs)(`div`,{className:`space-y-3`,children:[u,h,_]})}),t[15]=h,t[16]=v);let y;t[17]!==c||t[18]!==o?(y=(0,Q.jsx)(Bt,{children:(0,Q.jsx)(q,{variant:`ghost`,onClick:o,disabled:c,children:`Cancel`})}),t[17]=c,t[18]=o,t[19]=y):y=t[19];let b;t[20]!==v||t[21]!==y?(b=(0,Q.jsxs)(Ze,{className:`sm:max-w-[425px]`,children:[l,v,y]}),t[20]=v,t[21]=y,t[22]=b):b=t[22];let x;return t[23]!==r||t[24]!==n||t[25]!==b?(x=(0,Q.jsx)(tt,{open:n,onOpenChange:r,children:b}),t[23]=r,t[24]=n,t[25]=b,t[26]=x):x=t[26],x}function Xa(e){let t=(0,X.c)(13),{open:n,onOpenChange:r,onOk:i,isLoading:a,defaultBranch:o}=e,s=a===void 0?!1:a,c;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(c=(0,Q.jsx)(Fe,{children:`Pull Request Merged`}),t[0]=c):c=t[0];let l=o?` from ${o}`:``,u;t[1]===l?u=t[2]:(u=(0,Q.jsxs)(Qt,{children:[c,(0,Q.jsxs)(De,{children:[`As the pull request has been merged a new branch will be created`,l,`.`]})]}),t[1]=l,t[2]=u);let d;t[3]!==s||t[4]!==i?(d=(0,Q.jsx)(Bt,{children:(0,Q.jsx)(q,{onClick:i,disabled:s,children:`Ok`})}),t[3]=s,t[4]=i,t[5]=d):d=t[5];let f;t[6]!==u||t[7]!==d?(f=(0,Q.jsxs)(Ze,{children:[u,d]}),t[6]=u,t[7]=d,t[8]=f):f=t[8];let p;return t[9]!==r||t[10]!==n||t[11]!==f?(p=(0,Q.jsx)(tt,{open:n,onOpenChange:r,children:f}),t[9]=r,t[10]=n,t[11]=f,t[12]=p):p=t[12],p}var Za=3e4;function Qa(e){let[t,n]=(0,Z.useState)(!1),[r,i]=(0,Z.useState)(0),[a,o]=(0,Z.useState)(!1),[s,c]=(0,Z.useState)(``),[l,u]=(0,Z.useState)(!1),[d,f]=(0,Z.useState)(``),[p,h]=(0,Z.useState)(!1),[g,_]=(0,Z.useState)(void 0),[v,y]=(0,Z.useState)(!1),[b,x]=(0,Z.useState)(`Up to date`),[S,C]=(0,Z.useState)(null),[w,T]=(0,Z.useState)(!1),[E,D]=(0,Z.useState)(void 0),[O,k]=(0,Z.useState)(void 0),[A,j]=(0,Z.useState)(!1),[M,N]=(0,Z.useState)(!1),P=(0,Z.useRef)(!0),F=(0,Z.useCallback)(e=>{n(e.hasChanges),i(e.changedFilesCount),o(e.hasUnpushedCommits),c(e.currentBranch),y(e.hasRemoteBranch),u(e.isOnGitHub),f(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,Z.useCallback)(async(t=!1)=>{if(!e)return;let n=setTimeout(()=>N(!0),100);try{let n=`unified-git-status-${e}`;t&&Ae.invalidate(n),F(await Ae.get(n,()=>m(e,t),Za))}catch(e){console.error(`Failed to fetch unified git status:`,e)}finally{clearTimeout(n),N(!1)}},[e,F]);return(0,Z.useEffect)(()=>{e&&(async()=>{if(P.current){let t=`unified-git-status-${e}`,n=Ae.getSync(t);n&&F(n),P.current=!1}await I()})()},[e,I,F]),{hasChanges:t,changedFilesCount:r,hasUnpushedCommits:a,hasRemoteBranch:v,currentBranch:s,isOnGitHub:l,remoteUrl:d,canCreateRepo:p,repoUrl:g,status:b,defaultBranch:S,prExists:w,prUrl:E,prState:O,commitsAheadOfDefault:A,isRefreshing:M,fetchUnifiedStatus:I}}function $a(e){let t=e.split(`/`);return t.length>=2?{provider:t[0],model:t.slice(1).join(`/`)}:{provider:void 0,model:e}}function eo(e,t,n){let[r,i]=(0,Z.useState)(!1),[a,o]=(0,Z.useState)(!1),s=()=>{let t=e?n[e]:void 0;return t?.id?t.provider?{provider:t.provider,model:t.id}:$a(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 A(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 xe(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 to({projectId:e,threadId:t}){let{state:n,dispatch:a}=Hn(),[s,c]=(0,Z.useState)(!1),[l,u]=(0,Z.useState)(!1),[f,p]=(0,Z.useState)(!1),[m,h]=(0,Z.useState)(!1),[g,v]=(0,Z.useState)(``),[y,b]=(0,Z.useState)(``),[S,C]=(0,Z.useState)(``),[T,E]=(0,Z.useState)(!1),[D,O]=(0,Z.useState)(null),k=(0,Z.useRef)(!1),A=(0,Z.useRef)(!1),[M,N]=(0,Z.useState)(!1),[P,F]=(0,Z.useState)([]),[I,L]=(0,Z.useState)(!1),[R,z]=(0,Z.useState)([]),[B,V]=(0,Z.useState)(!1),[H,ee]=(0,Z.useState)(!1),[W,te]=(0,Z.useState)(``),[ne,re]=(0,Z.useState)(``),[ie,ae]=(0,Z.useState)(``),[oe,se]=(0,Z.useState)(!1),[ce,le]=(0,Z.useState)(!1),[ue,de]=(0,Z.useState)(!1),K=Qa(t),fe=eo(t,e,n.projectModelSelections),pe=async()=>{ct();let e=await ht();a({type:Y.SetProjects,projects:e.projects})},[he,ge]=(0,Z.useState)(()=>Ba()),ve=n.projects.find(t=>t.projectId===e),be=ve?.commitMethod===Ft.Direct;(0,Z.useEffect)(()=>{let e=()=>{document.visibilityState===`visible`&&K.fetchUnifiedStatus(!0)};return document.addEventListener(`visibilitychange`,e),()=>document.removeEventListener(`visibilitychange`,e)},[K.fetchUnifiedStatus]),(0,Z.useEffect)(()=>{H&&ve?.name&&!W&&te(ve.name)},[H,ve?.name,W]),(0,Z.useEffect)(()=>{Va(he)},[he]),(0,Z.useEffect)(()=>{let e=!0;return Me().then(t=>{e&&ae(t)}).catch(()=>{}),()=>{e=!1}},[]),(0,Z.useEffect)(()=>{if(!f){A.current=!1;return}f&&he.autoGenerateCommitMessage&&!g.trim()&&t&&!A.current&&(A.current=!0,(async()=>{let e=await fe.generateCommitMessageWithAI();e&&v(e)})())},[f,he.autoGenerateCommitMessage,t,fe,g]),(0,Z.useEffect)(()=>{if(!m){k.current=!1;return}console.log(`[pr-auto-gen] useEffect triggered`,{isPRDialogOpen:m,autoGeneratePRInfo:he.autoGeneratePRInfo,prTitleEmpty:!y.trim(),prDescriptionEmpty:!S.trim(),threadId:t,hasThreadId:!!t,generationAlreadyStarted:k.current}),m&&he.autoGeneratePRInfo&&!y.trim()&&!S.trim()&&t&&!k.current?(console.log(`[pr-auto-gen] Starting auto-generation...`),k.current=!0,(async()=>{let e=await fe.generatePRInfoWithAI();e&&(console.log(`[pr-auto-gen] Setting PR info:`,e.title.substring(0,50)),b(e.title),C(e.description))})()):console.log(`[pr-auto-gen] Skipping auto-generation - conditions not met`)},[m,he.autoGeneratePRInfo,t,fe,y,S]),(0,Z.useEffect)(()=>{console.log(`Unified status changed:`,{prExists:K.prExists,prState:K.prState,threadId:t}),K.prExists&&K.prState===`MERGED`&&(console.log(`Merged PR detected, opening dialog`),de(!0))},[K.prExists,K.prState,t]),(0,Z.useEffect)(()=>{!n.isStreaming&&n.completedThreadIds.includes(n.selectedThreadId??``)&&(K.fetchUnifiedStatus(!0),a({type:Y.ClearThreadCompleted,threadId:n.selectedThreadId??``}))},[n.isStreaming,n.completedThreadIds,n.selectedThreadId,K,a]);let xe=async()=>{if(g.trim()&&Ha(t))try{c(!0),await Kt(t,g),v(``),p(!1),await K.fetchUnifiedStatus(!0),pe(),$({title:`Changes committed successfully`,description:`Your changes have been committed to '${K.currentBranch}'.`}),ce&&(le(!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{c(!1)}},Ce=async()=>{if(K.status===`Behind`&&!K.hasChanges&&!K.hasUnpushedCommits){await Le();return}if(K.hasChanges){p(!0);return}if(K.prExists&&K.prState===`OPEN`&&!K.hasChanges&&!K.hasUnpushedCommits){K.prUrl&&await U(K.prUrl);return}if(K.commitsAheadOfDefault&&!K.prExists&&!K.hasChanges){h(!0);return}if(K.hasUnpushedCommits&&K.prExists){await Ae();return}},we=()=>l?`Creating PR...`:K.status===`Behind`&&!K.hasChanges&&!K.hasUnpushedCommits?`Sync`:K.hasChanges?`Commit`:K.prExists&&K.prState===`OPEN`&&!K.hasChanges&&!K.hasUnpushedCommits?`Open PR`:K.commitsAheadOfDefault&&!K.prExists&&!K.hasChanges?`Create PR`:K.hasUnpushedCommits&&K.prExists?`Update PR`:`Commit`,Te=()=>l?(0,Q.jsx)(_e,{className:`h-3.5 w-3.5 animate-spin`}):K.status===`Behind`&&!K.hasChanges&&!K.hasUnpushedCommits?(0,Q.jsx)(i,{className:`h-3.5 w-3.5`}):K.hasChanges?(0,Q.jsx)(Se,{className:`h-3.5 w-3.5`}):K.prExists&&K.prState===`OPEN`&&!K.hasChanges&&!K.hasUnpushedCommits?(0,Q.jsx)(yt,{className:`h-3.5 w-3.5`}):(0,Q.jsx)(j,{className:`h-3.5 w-3.5`}),Ee=()=>K.status===`Behind`&&!K.hasChanges&&!K.hasUnpushedCommits?`Your branch "${K.currentBranch}" is behind "${K.defaultBranch??`main`}". This will rebase and sync with the latest changes`:K.hasChanges?K.changedFilesCount>0?`Commit ${K.changedFilesCount} changed file${K.changedFilesCount===1?``:`s`}`:`No changes to commit`:K.prExists&&K.prState===`OPEN`&&!K.hasChanges&&!K.hasUnpushedCommits?`View pull request in GitHub`:K.commitsAheadOfDefault&&!K.prExists&&!K.hasChanges?`Create pull request for committed changes`:K.hasUnpushedCommits&&K.prExists?`Update pull request with unpushed commits`:`No actions available`,De=()=>s?!0:K.status===`Behind`&&!K.hasChanges&&!K.hasUnpushedCommits||K.prExists&&K.prState===`OPEN`&&!K.hasChanges&&!K.hasUnpushedCommits||K.commitsAheadOfDefault&&!K.prExists&&!K.hasChanges?!1:!K.hasChanges&&!K.hasUnpushedCommits,Oe=async()=>{let e=await fe.generateCommitMessageWithAI();e&&v(e)},ke=async()=>{if(Ha(t))try{c(!0),await _(t),await K.fetchUnifiedStatus()}catch(e){console.error(`Failed to fetch:`,e)}finally{c(!1)}},Ae=async()=>{if(Ha(t))try{c(!0),await lt(t),await K.fetchUnifiedStatus(!0),pe(),K.hasRemoteBranch?$({title:`Branch pushed successfully`,description:`Your branch '${K.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{c(!1)}},je=async()=>{if(Ha(t)){if(K.hasChanges){se(!0);return}await Ne()}},Ne=async()=>{try{c(!0),await G(t),await K.fetchUnifiedStatus(!0),pe(),$({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{c(!1)}},Pe=()=>{se(!1),le(!0),p(!0)},Fe=async()=>{se(!1),await Ne()},Ie=async()=>{if(t)try{c(!0);let e=await me(t,K.defaultBranch??void 0);ct();let n=await ht();a({type:Y.SetProjects,projects:n.projects}),$({title:`New branch created`,description:`Created new branch "${e.branchName}" on current thread`}),de(!1),await K.fetchUnifiedStatus(!0),setTimeout(()=>void K.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{c(!1)}},Le=async()=>{if(!Ha(t)){console.log(`[sync] Thread operation validation failed`);return}try{console.log(`[sync] Starting branch sync for thread: ${t}`),console.log(`[sync] Current branch: ${K.currentBranch}, Default branch: ${K.defaultBranch}`),c(!0),console.log(`[sync] Calling gitSyncBranch API...`);let e=await o(t);console.log(`[sync] ✓ gitSyncBranch API call successful`),console.log(`[sync] Result:`,e),console.log(`[sync] Refreshing git status...`),await K.fetchUnifiedStatus(!0),pe(),console.log(`[sync] ✓ Git status refreshed`),$({title:`Branch synced successfully`,description:`Your branch '${K.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{c(!1)}},Re=async()=>{if(Ha(t))try{c(!0),u(!0);let e=await x(t,y,S);e.prUrl&&await U(e.prUrl),b(``),C(``),h(!1),await K.fetchUnifiedStatus(),pe()}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`)?(h(!1),Ve({title:y,description:S})):$({title:`Create PR Failed`,description:t,variant:`destructive`})}finally{c(!1),u(!1)}},ze=async()=>{if(Ha(t))try{c(!0);let e=await r(t,W,ne,he.privateRepositoryDefault);e.repoUrl&&setTimeout(()=>{U(e.repoUrl)},3e3),te(``),re(``),ee(!1),await K.fetchUnifiedStatus(),pe()}catch(e){console.error(`Failed to create repo:`,e)}finally{c(!1)}},Be=async()=>{let e=await fe.generatePRInfoWithAI();e&&(b(e.title),C(e.description))},Ve=async e=>{let n=e??D;if(!(!t||!n))try{c(!0),u(!0);try{await lt(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 o(t),console.log(`[push-and-pr] ✓ Pull completed, retrying push...`),await lt(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 x(t,n.title,n.description);e.prUrl&&await U(e.prUrl),b(``),C(``),O(null),E(!1),await K.fetchUnifiedStatus(),pe()}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{c(!1),u(!1)}},He=async()=>{if(Ha(t))try{L(!0);let e=await at(t,100);F(e),z(e.slice(0,10)),N(!0)}catch(e){console.error(`Failed to fetch git history:`,e)}finally{L(!1)}},Ue=()=>{B||(V(!0),setTimeout(()=>{let e=R.length+10;z(P.slice(0,e)),V(!1)},300))},We=e=>{let t=e.currentTarget;t.scrollHeight-t.scrollTop-t.clientHeight<100&&R.length<P.length&&!B&&Ue()},Ge=K.hasChanges||K.status===`Behind`&&!K.hasChanges&&!K.hasUnpushedCommits||K.commitsAheadOfDefault&&!K.prExists&&!K.hasChanges;return(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-0`,children:[(0,Q.jsx)(tr,{children:(0,Q.jsxs)(nr,{children:[(0,Q.jsx)(rr,{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:De(),onClick:Ce,children:[Te(),we()]})}),(0,Q.jsx)(er,{children:Ee()})]})}),(0,Q.jsxs)(ma,{children:[(0,Q.jsx)(ha,{asChild:!0,children:(0,Q.jsx)(q,{variant:`outline`,size:`sm`,className:`h-8 w-8 rounded-l-none px-1 border-transparent${Ge?` bg-brand text-brand-foreground hover:bg-brand/90 hover:text-brand-foreground`:``}`,disabled:s,children:K.isRefreshing?(0,Q.jsx)(_e,{className:`h-3.5 w-3.5 animate-spin`}):(0,Q.jsx)(d,{className:`h-3.5 w-3.5`})})}),(0,Q.jsxs)(va,{align:`end`,children:[(0,Q.jsxs)(`div`,{className:`px-2 py-1.5`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 text-xs text-muted-foreground`,children:[(0,Q.jsx)(ye,{className:`h-3 w-3`}),(0,Q.jsx)(`span`,{className:`font-medium`,children:K.currentBranch||`Unknown`})]}),K.status===`Behind`&&(0,Q.jsx)(`div`,{className:`flex items-center gap-2 text-xs text-amber-600 mt-1`,children:(0,Q.jsxs)(`span`,{className:`font-medium`,children:[`Your branch is behind `,K.remoteUrl?`origin`:`remote`]})}),ie&&(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 text-xs text-muted-foreground mt-1`,children:[(0,Q.jsx)(`span`,{className:`font-medium`,children:`User:`}),(0,Q.jsx)(`span`,{children:ie})]})]}),(0,Q.jsx)(Ca,{}),(0,Q.jsx)(tr,{children:(0,Q.jsxs)(nr,{children:[(0,Q.jsx)(rr,{asChild:!0,children:(0,Q.jsxs)(ya,{onClick:ke,disabled:s,children:[(0,Q.jsx)(kt,{className:`h-3.5 w-3.5 mr-2`}),`Fetch`]})}),(0,Q.jsx)(er,{side:`right`,children:`Download latest information from remote without merging changes`})]})}),(0,Q.jsx)(tr,{children:(0,Q.jsxs)(nr,{children:[(0,Q.jsx)(rr,{asChild:!0,children:(0,Q.jsxs)(ya,{onClick:()=>{K.hasRemoteBranch&&!s&&je()},className:!K.hasRemoteBranch||s?`opacity-50 cursor-not-allowed`:``,children:[(0,Q.jsx)(i,{className:`h-3.5 w-3.5 mr-2`}),`Pull`]})}),(0,Q.jsx)(er,{side:`right`,children:K.hasRemoteBranch?`Pull latest changes from remote`:`No remote branch to pull from`})]})}),!K.hasRemoteBranch&&(0,Q.jsx)(tr,{children:(0,Q.jsxs)(nr,{children:[(0,Q.jsx)(rr,{asChild:!0,children:(0,Q.jsxs)(ya,{onClick:Ae,disabled:s,children:[(0,Q.jsx)(dt,{className:`h-3.5 w-3.5 mr-2`}),`Push Branch to Remote`]})}),(0,Q.jsx)(er,{side:`right`,children:`Create remote branch and push local commits`})]})}),(0,Q.jsx)(tr,{children:(0,Q.jsxs)(nr,{children:[(0,Q.jsx)(rr,{asChild:!0,children:(0,Q.jsxs)(ya,{onClick:()=>{K.hasUnpushedCommits&&!s&&Ae()},className:!K.hasUnpushedCommits||s?`opacity-50 cursor-not-allowed`:``,children:[(0,Q.jsx)(dt,{className:`h-3.5 w-3.5 mr-2`}),`Push Commits`]})}),(0,Q.jsx)(er,{side:`right`,children:K.hasUnpushedCommits?s?`Push in progress...`:`Push your uncommitted commits to the remote branch`:`No commits to push - your branch is up to date with remote`})]})}),(0,Q.jsxs)(ya,{onClick:He,disabled:s||I,children:[(0,Q.jsx)(w,{className:`h-3.5 w-3.5 mr-2`}),`History`]}),!be&&(0,Q.jsxs)(ya,{onClick:()=>h(!0),disabled:s,children:[(0,Q.jsx)(j,{className:`h-3.5 w-3.5 mr-2`}),`Create Pull Request`]}),K.canCreateRepo&&(0,Q.jsxs)(ya,{onClick:()=>ee(!0),disabled:s,children:[(0,Q.jsx)(Et,{className:`h-3.5 w-3.5 mr-2`}),`Create Repo`]}),K.repoUrl&&(0,Q.jsxs)(ya,{onClick:()=>{K.repoUrl&&U(K.repoUrl)},disabled:s,children:[(0,Q.jsx)(yt,{className:`h-3.5 w-3.5 mr-2`}),`View in GitHub`]})]})]})]}),(0,Q.jsx)(Ua,{open:f,onOpenChange:p,commitMessage:g,onCommitMessageChange:v,autoGenerateCommitMessage:he.autoGenerateCommitMessage,onAutoGenerateChange:e=>ge(t=>({...t,autoGenerateCommitMessage:e})),isGeneratingMessage:fe.isGeneratingMessage,isLoading:s,onGenerateMessage:Oe,onCommit:xe,currentBranch:K.currentBranch}),(0,Q.jsx)(Wa,{open:m,onOpenChange:h,prTitle:y,onPrTitleChange:b,prDescription:S,onPrDescriptionChange:C,isGeneratingPRInfo:fe.isGeneratingPRInfo,isLoading:s,onGeneratePRInfo:Be,onCreatePR:Re,currentBranch:K.currentBranch,autoGeneratePRInfo:he.autoGeneratePRInfo,onAutoGeneratePRInfoChange:e=>ge(t=>({...t,autoGeneratePRInfo:e}))}),(0,Q.jsx)(Ja,{open:T,onOpenChange:E,isLoading:s,onPushAndCreatePR:Ve,onCancel:()=>{E(!1),O(null)}}),(0,Q.jsx)(Ga,{open:H,onOpenChange:ee,repoName:W,onRepoNameChange:te,repoDescription:ne,onRepoDescriptionChange:re,isPrivateRepo:he.privateRepositoryDefault,onPrivateRepoChange:e=>ge(t=>({...t,privateRepositoryDefault:e})),isLoading:s,onCreateRepo:ze}),(0,Q.jsx)(Ka,{open:M,onOpenChange:N,commits:P,displayedCommits:R,isLoadingMore:B,onScroll:We,currentBranch:K.currentBranch}),(0,Q.jsx)(Ya,{open:oe,onOpenChange:se,onCommitFirst:Pe,onStashAndPull:Fe,onCancel:()=>se(!1),isLoading:s}),(0,Q.jsx)(Xa,{open:ue,onOpenChange:de,onOk:Ie,isLoading:s,defaultBranch:K.defaultBranch??void 0})]})}var no=`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 ro({open:e,onOpenChange:t,projectId:n,commands:r,onRefresh:i}){let[a,o]=(0,Z.useState)(null),[s,c]=(0,Z.useState)(!1),[u,f]=(0,Z.useState)(!1),[p,m]=(0,Z.useState)([]),[h,g]=(0,Z.useState)(0),[_,v]=(0,Z.useState)(!1),y=(0,Z.useRef)(null),b=(0,Z.useRef)(null),x=()=>{o({id:crypto.randomUUID(),name:``,icon:`Play`,commandLine:``}),f(!1),m([])},S=e=>{o({...e}),f(!1),m([])},C=async()=>{try{v(!0);let e=await ft(n);m(e.scripts),g(0),f(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{v(!1)}},w=e=>{o(t=>t?{...t,name:e.name,commandLine:e.commandLine,relativeFolder:e.relativePath||``}:null),f(!1),m([]),y.current?.focus()},T=e=>{u&&(e.key===`ArrowDown`?(e.preventDefault(),g(e=>e<p.length-1?e+1:e)):e.key===`ArrowUp`?(e.preventDefault(),g(e=>e>0?e-1:0)):e.key===`Enter`?(e.preventDefault(),h<p.length&&w(p[h])):e.key===`Escape`&&(e.preventDefault(),f(!1),m([])))};(0,Z.useEffect)(()=>{let e=e=>{b.current&&!b.current.contains(e.target)&&(f(!1),m([]))};return u&&document.addEventListener(`mousedown`,e),()=>{document.removeEventListener(`mousedown`,e)}},[u]);let E=async e=>{try{await oe(n,e),$({title:`Success`,description:`Command deleted`}),i()}catch{$({title:`Error`,description:`Failed to delete command`,variant:`destructive`})}};return(0,Q.jsx)(tt,{open:e,onOpenChange:t,children:(0,Q.jsxs)(Ze,{className:`sm:max-w-[500px]`,children:[(0,Q.jsxs)(Qt,{children:[(0,Q.jsx)(Fe,{children:`Project Commands`}),(0,Q.jsx)(De,{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)(ut,{htmlFor:`name`,children:`Command Name`}),(0,Q.jsx)(Le,{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)(ut,{htmlFor:`commandLine`,children:`Command Line`}),(0,Q.jsxs)(`div`,{className:`relative`,children:[(0,Q.jsx)(na,{ref:y,id:`commandLine`,value:a.commandLine,onChange:e=>o({...a,commandLine:e.target.value}),onKeyDown:T,placeholder:`e.g. npm test`,className:`font-mono text-xs min-h-[100px] resize-none pr-10`}),(0,Q.jsx)(tr,{children:(0,Q.jsxs)(nr,{children:[(0,Q.jsx)(rr,{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 C(),disabled:_,children:(0,Q.jsx)(d,{className:`h-4 w-4`})})}),(0,Q.jsx)(er,{children:(0,Q.jsx)(`p`,{children:`Discover package scripts`})})]})})]}),u&&(0,Q.jsx)(`div`,{ref:b,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)(d,{className:`h-3 w-3`}),`Available Scripts `,_&&`(loading...)`]}),p.length>0?(()=>{let e={};p.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===h;return n++,(0,Q.jsxs)(`button`,{type:`button`,className:J(`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:()=>w(e),onMouseEnter:()=>g(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:_?`Loading scripts...`:`No package scripts found`})]})})]}),(0,Q.jsxs)(`div`,{className:`grid gap-2`,children:[(0,Q.jsx)(ut,{htmlFor:`relativeFolder`,children:`Relative Folder`}),(0,Q.jsx)(Le,{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)(ut,{children:`Icon`}),(0,Q.jsx)(`div`,{className:`grid grid-cols-10 gap-1 p-2 bg-background rounded-md border border-border`,children:no.map(e=>{let t=it[e]||Ee;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)(xt,{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{c(!0),await l(n,a),$({title:`Success`,description:`Command saved`}),o(null),i()}catch{$({title:`Error`,description:`Failed to save command`,variant:`destructive`})}finally{c(!1)}},disabled:s,children:[(0,Q.jsx)(Ut,{className:`h-4 w-4 mr-2`}),` `,s?`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:()=>S(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)(it[e.icon]||pe,{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(),E(e.id)},children:(0,Q.jsx)(Je,{className:`h-4 w-4`})})})]},e.id))]}),(0,Q.jsxs)(q,{variant:`outline`,className:`w-full border-dashed`,onClick:x,children:[(0,Q.jsx)(Gt,{className:`h-4 w-4 mr-2`}),` Add New Command`]})]})})]})})}function io(){let e=(0,X.c)(27),{state:t}=Hn(),{selectedProjectId:n,selectedThreadId:r,projects:i}=t,{dispatch:a}=Yn(r),[o,s]=(0,Z.useState)(!1),c,l,u,d,f;if(e[0]!==a||e[1]!==i||e[2]!==n||e[3]!==r||e[4]!==t.isRunningCommand){f=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 p;e[12]!==a||e[13]!==n||e[14]!==r?(p=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]=p):p=e[15];let m=p,h;if(e[16]===a?h=e[17]:(h=async()=>{a({type:Y.ConfigUpdated})},e[16]=a,e[17]=h),l=h,!n){f=null;break bb0}u=`flex items-center gap-1 mr-2`,d=c.length===0?(0,Q.jsx)(tr,{children:(0,Q.jsxs)(nr,{children:[(0,Q.jsx)(rr,{asChild:!0,children:(0,Q.jsx)(q,{variant:`action`,size:`icon-md`,onClick:()=>s(!0),children:(0,Q.jsx)(Ie,{})})}),(0,Q.jsx)(er,{children:`Manage commands`})]})}):(0,Q.jsx)(Q.Fragment,{children:(0,Q.jsxs)(tr,{children:[c.map(e=>{let n=it[e.icon]||pe;return(0,Q.jsxs)(nr,{children:[(0,Q.jsx)(rr,{asChild:!0,children:(0,Q.jsx)(q,{variant:`action`,size:`icon-md`,onClick:()=>m({commandLine:e.commandLine,relativeFolder:e.relativeFolder}),disabled:t.isRunningCommand,children:(0,Q.jsx)(n,{})})}),(0,Q.jsx)(er,{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)(nr,{children:[(0,Q.jsx)(rr,{asChild:!0,children:(0,Q.jsx)(q,{variant:`action`,size:`icon-md`,className:`ml-1`,onClick:()=>s(!0),children:(0,Q.jsx)(Ie,{})})}),(0,Q.jsx)(er,{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]=f}else c=e[5],l=e[6],u=e[7],d=e[8],f=e[9];if(f!==Symbol.for(`react.early_return_sentinel`))return f;let p;e[18]!==c||e[19]!==l||e[20]!==n||e[21]!==o?(p=(0,Q.jsx)(ro,{open:o,onOpenChange:s,projectId:n,commands:c,onRefresh:l}),e[18]=c,e[19]=l,e[20]=n,e[21]=o,e[22]=p):p=e[22];let m;return e[23]!==u||e[24]!==d||e[25]!==p?(m=(0,Q.jsxs)(`div`,{className:u,children:[d,p]}),e[23]=u,e[24]=d,e[25]=p,e[26]=m):m=e[26],m}var ao=(0,Z.createContext)({activeMainTab:`chat`,setActiveMainTab:()=>{},devServerUrl:null,setDevServerUrl:()=>{}});function oo(){return(0,Z.useContext)(ao)}function so({projectId:e,runCommand:t}){let{state:n}=Hn(),{selectedThreadId:r}=n,{dispatch:i}=Yn(r),{setActiveMainTab:a,setDevServerUrl:o}=oo(),[s,c]=(0,Z.useState)(!1),[l,u]=(0,Z.useState)(!1);(0,Z.useEffect)(()=>{(async()=>{try{c((await B(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 P(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 M(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)(tr,{children:(0,Q.jsxs)(nr,{children:[(0,Q.jsx)(rr,{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)(_e,{className:`h-4 w-4 animate-spin`}):s?(0,Q.jsx)(Qe,{className:`h-4 w-4 fill-current`}):(0,Q.jsx)(pe,{className:`h-4 w-4`}),(0,Q.jsx)(`span`,{className:`sr-only`,children:s?`Stop dev server`:`Start dev server`})]})}),(0,Q.jsx)(er,{children:s?`Stop dev server`:p?`Start dev server: ${t}`:`Set run command in project settings`})]})})})}function co(e){let t=(0,X.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 lo(){let e=(0,X.c)(44),{state:t,dispatch:n}=Hn(),{selectedThreadId:r,selectedProjectId:i,projects:o,sidebarOpen:s}=t,c;if(e[0]!==o||e[1]!==i){let t;e[3]===i?t=e[4]:(t=e=>e.projectId===i,e[3]=i,e[4]=t),c=o.find(t),e[0]=o,e[1]=i,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=J(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)(st,{className:`h-4 w-4`}):(0,Q.jsx)(a,{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]!==i||e[17]!==r?(_=r&&(0,Q.jsxs)(`div`,{className:`flex flex-col`,children:[(0,Q.jsx)(`span`,{className:`text-sm font-medium text-foreground`,children:Wt(o,i)}),(0,Q.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:fe(o,r)})]}),e[15]=o,e[16]=i,e[17]=r,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=J(`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]!==i||e[26]!==r?(x=i&&(0,Q.jsxs)(co,{children:[(0,Q.jsx)(so,{projectId:i,runCommand:l?.runCommand}),r&&(0,Q.jsx)(Q.Fragment,{children:(0,Q.jsx)(io,{})})]}),e[24]=l?.runCommand,e[25]=i,e[26]=r,e[27]=x):x=e[27];let S;e[28]!==i||e[29]!==r?(S=r&&i&&(0,Q.jsx)(co,{children:(0,Q.jsx)(to,{projectId:i,threadId:r})}),e[28]=i,e[29]=r,e[30]=S):S=e[30];let C;e[31]!==l?.openWith||e[32]!==i||e[33]!==r?(C=r&&i&&(0,Q.jsx)(co,{children:(0,Q.jsx)(za,{projectId:i,threadId:r,openWith:l?.openWith})}),e[31]=l?.openWith,e[32]=i,e[33]=r,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)(pa,{className:f,children:[v,w]}),e[40]=w,e[41]=f,e[42]=v,e[43]=T):T=e[43],T}function uo(e){let t=(0,X.c)(13),{open:n,projectName:r,onOpenChange:i,onConfirm:a}=e,o;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(o=(0,Q.jsx)(vr,{children:`Delete Project`}),t[0]=o):o=t[0];let s;t[1]===r?s=t[2]:(s=(0,Q.jsxs)(gr,{children:[o,(0,Q.jsxs)(yr,{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)(xr,{children:`Cancel`}),t[3]=c):c=t[3];let l;t[4]===a?l=t[5]:(l=(0,Q.jsxs)(_r,{children:[c,(0,Q.jsx)(br,{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)(hr,{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)(fr,{open:n,onOpenChange:i,children:u}),t[9]=i,t[10]=n,t[11]=u,t[12]=d):d=t[12],d}function fo(e){let t=(0,X.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)(vr,{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)(gr,{children:[o,(0,Q.jsxs)(yr,{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(po),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)(xr,{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)(br,{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)(_r,{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)(hr,{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)(fr,{open:n,onOpenChange:a,children:h}),t[24]=n,t[25]=a,t[26]=h,t[27]=g):g=t[27],g}function po(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 mo(){let e=(0,X.c)(6),[t,n]=(0,Z.useState)(!0),r,i;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(r=()=>{let e=!0;return(async()=>{try{let t=await fetch(`${At()}/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,Z.useEffect)(r,i);let a=ho;if(t)return null;let o;e[2]===Symbol.for(`react.memo_cache_sentinel`)?(o=At(),e[2]=o):o=e[2];let s=o,c,l;e[3]===Symbol.for(`react.memo_cache_sentinel`)?(c=(0,Q.jsxs)(gr,{children:[(0,Q.jsx)(vr,{children:`Service unavailable`}),(0,Q.jsx)(yr,{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)(fr,{open:!0,children:(0,Q.jsxs)(hr,{children:[c,l,(0,Q.jsx)(_r,{children:(0,Q.jsx)(q,{onClick:a,children:`Retry`})})]})}),e[5]=u):u=e[5],u}function ho(){window.location.assign(window.location.href)}var go=e=>{let t=(0,X.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=J(`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)(kn,{className:i,...r}),t[5]=r,t[6]=i,t[7]=a):a=t[7],a},_o=An,vo=e=>{let t=(0,X.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=J(`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)(N,{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)(wn,{className:a,...r,children:o}),t[8]=r,t[9]=a,t[10]=o,t[11]=s):s=t[11],s},yo=En,bo=Z.forwardRef((e,t)=>{let n=(0,X.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=J(`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)(Nn,{ref:t,className:a,...i}),n[5]=i,n[6]=t,n[7]=a,n[8]=o):o=n[8],o});bo.displayName=Nn.displayName;var xo=Ct(`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`}}),So=Z.forwardRef((e,t)=>{let n=(0,X.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=J(xo({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)(On,{ref:t,className:o,...i}),n[7]=i,n[8]=t,n[9]=o,n[10]=s):s=n[10],s});So.displayName=On.displayName;var Co=Z.forwardRef((e,t)=>{let n=(0,X.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=J(`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)(Tn,{ref:t,className:a,...i}),n[5]=i,n[6]=t,n[7]=a,n[8]=o):o=n[8],o});Co.displayName=Tn.displayName;var wo=Z.forwardRef((e,t)=>{let n=(0,X.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=J(`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)(xt,{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)(Mn,{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});wo.displayName=Mn.displayName;var To=Z.forwardRef((e,t)=>{let n=(0,X.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=J(`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)(Pn,{ref:t,className:a,...i}),n[5]=i,n[6]=t,n[7]=a,n[8]=o):o=n[8],o});To.displayName=Pn.displayName;var Eo=Z.forwardRef((e,t)=>{let n=(0,X.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=J(`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)(In,{ref:t,className:a,...i}),n[5]=i,n[6]=t,n[7]=a,n[8]=o):o=n[8],o});Eo.displayName=In.displayName;function Do(){let e=(0,X.c)(5),{toasts:t}=Fa(),n;e[0]===t?n=e[1]:(n=t.map(Oo),e[0]=t,e[1]=n);let r;e[2]===Symbol.for(`react.memo_cache_sentinel`)?(r=(0,Q.jsx)(bo,{}),e[2]=r):r=e[2];let i;return e[3]===n?i=e[4]:(i=(0,Q.jsxs)(yo,{children:[n,r]}),e[3]=n,e[4]=i),i}function Oo(e){let{id:t,title:n,description:r,action:i,...a}=e;return(0,Q.jsxs)(So,{...a,children:[(0,Q.jsxs)(`div`,{className:`grid gap-1`,children:[n&&(0,Q.jsx)(To,{children:n}),r&&(0,Q.jsx)(Eo,{children:r})]}),i,(0,Q.jsx)(wo,{})]},t)}function ko(){let e=(0,X.c)(4),{resolvedTheme:t,theme:n}=ir(),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,Z.useEffect)(r,i),null}function Ao(e){let t=(0,X.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)(ko,{}),t[3]=i):i=t[3];let a;return t[4]!==n||t[5]!==r?(a=(0,Q.jsxs)(ar,{...r,children:[i,n]}),t[4]=n,t[5]=r,t[6]=a):a=t[6],a}function jo(){let{state:e,dispatch:t}=Hn(),{toast:n}=Fa(),r=Yn(`project-creation`).dispatch,[i,a]=(0,Z.useState)(null),o=(0,Z.useCallback)(async()=>{try{t({type:Y.SetProjectsLoading,projectsLoading:!0});let e=await ht();t({type:Y.SetProjects,projects:e.projects})}catch(e){console.error(`Failed to refresh projects:`,e)}finally{t({type:Y.SetProjectsLoading,projectsLoading:!1})}},[t]),c=(0,Z.useCallback)(async(n,r)=>{try{await ve(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]),l=(0,Z.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(`
14
+ `);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}),ct();let m=await ht();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]),u=(0,Z.useCallback)(async(e,t)=>{let n=e.split(`/`).pop()?.replace(`.git`,``)??`project`;await l({apiCall:()=>ot(e,t),initialMessage:`Cloning repository: ${e}...`,optimisticProjectName:n,gitUrl:e,useTerminalDispatch:!0,includeThreadPath:!0,handleSetupScript:!0,logTag:`create project`,catchErrorPrefix:`Failed to create project`})},[l]),d=(0,Z.useCallback)(async(e,t,n)=>{await l({apiCall:()=>V(e,t,n),initialMessage:`Creating app "${e}"...`,optimisticProjectName:e,useTerminalDispatch:!1,handleSetupScript:!1,logTag:`create web app`,catchErrorPrefix:`Failed to create web app`})},[l]),f=(0,Z.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 S(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(`
15
+ `);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}),ct(),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]),p=(0,Z.useCallback)(async(n,r)=>{t({type:Y.AddDeletingThread,threadId:r});try{await E(n,r),ct(),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]),m=(0,Z.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 s(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]),h=(0,Z.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 Pt(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(`
16
+ `);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,Z.useEffect)(()=>{let n=!0;async function r(){try{t({type:Y.SetProjectsLoading,projectsLoading:!0});let r=await ht();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 g=(0,Z.useCallback)(async()=>{await l({apiCall:re,initialMessage:`Opening folder...`,optimisticProjectName:`Opening folder...`,useTerminalDispatch:!0,handleSetupScript:!0,logTag:`open folder`,catchErrorPrefix:`Failed to open folder`})},[l]);return{projects:e.projects,selectedProjectId:e.selectedProjectId,selectedThreadId:e.selectedThreadId,refreshProjects:o,handleSelectThread:c,handleCreateProject:u,handleCreateWebApp:d,handleOpenFolder:g,handleCreateThread:f,handleDeleteThread:p,confirmDeleteProject:m,pendingSetupScriptConfirmation:i,resolveSetupScriptConfirmation:h}}function Mo(){let e=(0,X.c)(2),[t,n]=(0,Z.useState)(No),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,Z.useEffect)(r,i),t}function No(){return document.hasFocus()}var Po=null;function Fo(){Po??=new Audio(`/pop.wav`),Po.currentTime=0,Po.play().catch(e=>{console.debug(`Could not play completion sound:`,e)})}function Io(){let{state:e,dispatch:t}=Hn(),n=Mo(),r=(0,Z.useRef)(null),i=(0,Z.useRef)(!1),a=(0,Z.useRef)([]),o=(0,Z.useRef)(e),s=(0,Z.useRef)(n);(0,Z.useEffect)(()=>{o.current=e},[e]),(0,Z.useEffect)(()=>{s.current=n},[n]);let c=(0,Z.useCallback)(async()=>{try{let e=await He(),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&&Fo(),a.current=e,t({type:Y.SetProcessingThreads,threadIds:e}),e}catch(e){return console.error(`Failed to fetch processing threads:`,e),[]}},[t]);(0,Z.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,Z.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 Lo=768;function Ro(){let e=(0,X.c)(2),[t,n]=Z.useState(void 0),r,i;return e[0]===Symbol.for(`react.memo_cache_sentinel`)?(r=()=>{let e=window.matchMedia(`(max-width: ${Lo-1}px)`),t=()=>{n(window.innerWidth<Lo)};return e.addEventListener(`change`,t),n(window.innerWidth<Lo),()=>e.removeEventListener(`change`,t)},i=[],e[0]=r,e[1]=i):(r=e[0],i=e[1]),Z.useEffect(r,i),!!t}var zo=(0,Z.lazy)(()=>en(()=>import(`./terminal-panel-Bv2hLEfW.js`).then(e=>({default:e.TerminalPanel})),__vite__mapDeps([12,1,0,10]))),Bo=(0,Z.lazy)(()=>en(()=>import(`./todos-view-FJ5GkG21.js`).then(e=>({default:e.TodosView})),__vite__mapDeps([13,4,1,5,0,6,10]))),Vo=(0,Z.lazy)(()=>en(()=>import(`./diff-view-kPjfhf7_.js`),__vite__mapDeps([7,1,4,5,0,6,8,9,10,11]))),Ho=(0,Z.lazy)(()=>en(()=>import(`./files-tab-view-DhnLTfaB.js`),__vite__mapDeps([14,1,4,5,0,6,9,10]))),Uo=(0,Z.lazy)(()=>en(()=>import(`./browser-tab-CWkk3b20.js`).then(e=>({default:e.BrowserTab})),__vite__mapDeps([15,1,0]))),Wo=(0,Z.lazy)(()=>en(()=>import(`./dialogs-config-CB7G-sX6.js`).then(e=>e.t),__vite__mapDeps([0,1]))),Go=(0,Z.lazy)(()=>en(()=>import(`./onboarding-dialog-DX7DCkK0.js`),__vite__mapDeps([16,5,1,0,8]))),Ko=(0,Z.lazy)(()=>en(()=>import(`./conversation-history-view-BdJJ-7zE.js`),__vite__mapDeps([17,5,1,0]))),qo=(0,Z.lazy)(()=>en(()=>import(`./settings-view-CoL0k8nt.js`),__vite__mapDeps([18,1,4,5,0,6])));function Jo(){let{state:e,dispatch:t}=Hn(),n=Sn(),r=Cn(),i=Ro(),{projects:a,handleSelectThread:o,handleCreateProject:s,handleCreateWebApp:c,handleOpenFolder:l,handleCreateThread:u,handleDeleteThread:d,confirmDeleteProject:p,refreshProjects:m,pendingSetupScriptConfirmation:h,resolveSetupScriptConfirmation:g}=jo(),{processingThreadIds:_,completedThreadIds:y,clearCompleted:b}=Io(),[x,S]=(0,Z.useState)(`chat`),[C,w]=(0,Z.useState)(null),{terminalState:T}=Yn(e.selectedThreadId);(0,Z.useEffect)(()=>{T.open&&S(`terminal`)},[T.open]);let[E,D]=(0,Z.useState)(!1),[O,k]=(0,Z.useState)(!1),[A,j]=(0,Z.useState)(!1),[M,N]=(0,Z.useState)(null),[P,F]=(0,Z.useState)(!1),[I,L]=(0,Z.useState)(!1),R=(0,Z.useRef)(null),z=r.pathname.startsWith(`/settings`),B=r.pathname===`/review`,V=r.pathname===`/todos`;(0,Z.useEffect)(()=>{r.pathname===`/`&&x===`tasks`&&S(`chat`)},[r.pathname]);let H=(0,Z.useRef)(null);(0,Z.useEffect)(()=>{let n=z||B||V;if(n&&H.current===null)H.current=e.sidebarOpen,e.sidebarOpen&&t({type:Y.ToggleSidebar});else if(!n&&H.current!==null){let n=H.current;H.current=null,n&&!e.sidebarOpen&&t({type:Y.ToggleSidebar})}},[z,B,V]),(0,Z.useEffect)(()=>{(async()=>{try{(await v()).updateAvailable&&F(!0)}catch{}})()},[]);let U=(0,Z.useCallback)(async()=>{L(!0);try{await de()}catch{L(!1)}},[]);(0,Z.useEffect)(()=>{A||(async()=>{try{(await Be()).onboardingCompleted||k(!0)}catch(e){console.error(`Failed to check onboarding status:`,e)}finally{j(!0)}})()},[A]),(0,Z.useEffect)(()=>{O||t({type:Y.ConfigUpdated})},[O,t]);let ee=(0,Z.useCallback)(e=>{let t=a.find(t=>t.projectId===e);t&&N({id:t.projectId,name:f(t)})},[a]),W=(0,Z.useCallback)(e=>{u(e,void 0)},[u]),G=(0,Z.useCallback)(async(a,s)=>{b(s),r.pathname!==`/`&&n(`/`),await o(a,s),i&&e.sidebarOpen&&t({type:Y.ToggleSidebar})},[o,i,e.sidebarOpen,t,b,r.pathname,n]);(0,Z.useEffect)(()=>{e.sidebarOpen?R.current?.expand():R.current?.collapse()},[e.sidebarOpen]);let te={activeMainTab:x,setActiveMainTab:S,devServerUrl:C,setDevServerUrl:w};return(0,Q.jsx)(ao.Provider,{value:te,children:(0,Q.jsxs)(tr,{delayDuration:200,children:[(0,Q.jsxs)(go,{direction:`horizontal`,className:`h-screen bg-background`,children:[(0,Q.jsx)(_o,{ref:R,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)(Er,{projects:a,selectedThreadId:e.selectedThreadId,selectedProjectId:e.selectedProjectId,processingThreadIds:_,completedThreadIds:y,deletingThreadIds:e.deletingThreadIds,deletingProjectIds:e.deletingProjectIds,onSelectThread:G,onCreateProject:()=>D(!0),onCreateThread:W,onDeleteThread:d,onDeleteProject:ee,onNavigateToSettings:()=>void n(`/settings/providers`),onDeselect:()=>t({type:Y.ClearSelection}),updateAvailable:P,updatingApp:I,onUpdateApp:U,onRefreshProjects:m})})}),!i&&(0,Q.jsx)(vo,{withHandle:!0,className:e.sidebarOpen?`ml-[-40px]`:``}),(0,Q.jsx)(_o,{minSize:40,className:`overflow-hidden ${i&&e.sidebarOpen?`hidden`:``}`,children:(0,Q.jsxs)(`div`,{className:`flex h-full flex-col overflow-hidden`,children:[!B&&!z&&!V&&(0,Q.jsx)(lo,{}),!B&&!z&&!V&&e.selectedThreadId&&(0,Q.jsx)(`div`,{className:`flex border-b border-border shrink-0`,children:[`Chat`,`Files`,`Review`,`Browser`,`Terminal`,`Tasks`,`History`].map(e=>{let t=e.toLowerCase();return(0,Q.jsx)(`button`,{onClick:()=>S(t),className:`px-4 py-2 text-sm font-medium transition-colors ${x===t?`border-b-2 border-primary text-foreground -mb-px`:`text-muted-foreground hover:text-foreground`}`,children:e},t)})}),(0,Q.jsx)(`main`,{className:`flex-1 overflow-hidden${!B&&!z&&!V&&x!==`chat`?` hidden`:``}`,children:(0,Q.jsxs)(un,{children:[(0,Q.jsx)(Fn,{path:`/settings/:tab?`,element:(0,Q.jsx)(Z.Suspense,{fallback:null,children:(0,Q.jsx)(qo,{})})}),(0,Q.jsx)(Fn,{path:`/settings/project/:projectId`,element:(0,Q.jsx)(Z.Suspense,{fallback:null,children:(0,Q.jsx)(qo,{})})}),(0,Q.jsx)(Fn,{path:`/settings/add-skill`,element:(0,Q.jsx)(Z.Suspense,{fallback:null,children:(0,Q.jsx)(qo,{})})}),(0,Q.jsx)(Fn,{path:`/settings/add-command`,element:(0,Q.jsx)(Z.Suspense,{fallback:null,children:(0,Q.jsx)(qo,{})})}),(0,Q.jsx)(Fn,{path:`/settings/mcp-server-edit`,element:(0,Q.jsx)(Z.Suspense,{fallback:null,children:(0,Q.jsx)(qo,{})})}),(0,Q.jsx)(Fn,{path:`*`,element:(0,Q.jsx)(da,{onCreateThread:W})})]})}),(0,Q.jsx)(`div`,{className:`flex-1 overflow-hidden${x===`terminal`&&!B&&!z&&!V?``:` hidden`}`,children:(0,Q.jsx)(Z.Suspense,{fallback:null,children:(0,Q.jsx)(zo,{})})}),(0,Q.jsx)(`div`,{className:`flex-1 overflow-hidden${x===`browser`&&!B&&!z&&!V?``:` hidden`}`,children:(0,Q.jsx)(Z.Suspense,{fallback:null,children:(0,Q.jsx)(Uo,{})})}),!B&&!z&&!V&&x!==`chat`&&x!==`terminal`&&x!==`browser`&&(x===`files`?(0,Q.jsx)(Z.Suspense,{fallback:null,children:(0,Q.jsx)(Ho,{})}):x===`tasks`&&e.selectedProjectId?(0,Q.jsx)(Z.Suspense,{fallback:null,children:(0,Q.jsx)(Bo,{projectId:e.selectedProjectId})}):x===`history`?(0,Q.jsx)(Z.Suspense,{fallback:null,children:(0,Q.jsx)(Ko,{isOpen:!0,onClose:()=>S(`chat`),initialFilter:e.selectedProjectId?{type:`project`,id:e.selectedProjectId}:void 0,projects:a,inline:!0})}):x===`review`&&e.selectedThreadId?(0,Q.jsx)(Z.Suspense,{fallback:null,children:(0,Q.jsx)(Vo,{threadId:e.selectedThreadId,onExit:()=>S(`chat`)})}):(0,Q.jsx)(`div`,{className:`flex-1 overflow-hidden`}))]})}),(0,Q.jsx)(Z.Suspense,{fallback:null,children:(0,Q.jsx)(Wo,{open:E,onOpenChange:D,onSubmitClone:s,onSubmitWebApp:c,onOpenFolder:l})}),(0,Q.jsx)(uo,{open:M!==null,projectName:M?.name,onOpenChange:e=>!e&&N(null),onConfirm:()=>{M&&(p(M.id),N(null))}}),(0,Q.jsx)(fo,{open:h!==null,setupScripts:h?[h.command,...h.remainingScripts||[]]:[],onConfirm:g}),(0,Q.jsx)(Z.Suspense,{fallback:null,children:(0,Q.jsx)(Go,{open:O,onOpenChange:k,onComplete:()=>{j(!0),m()}})}),(0,Q.jsx)(mo,{})]}),(0,Q.jsx)(Do,{})]})})}function Yo(){let e=(0,X.c)(5),[t,n]=(0,Z.useReducer)(Zn,Kn),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)(Jo,{}),e[2]=i):i=e[2];let a;return e[3]===r?a=e[4]:(a=(0,Q.jsx)(Ao,{attribute:`class`,defaultTheme:`system`,enableSystem:!0,storageKey:`tarsk-theme`,children:(0,Q.jsx)(Jn.Provider,{value:r,children:i})}),e[3]=r,e[4]=a),a}var Xo=!1;window.addEventListener(`resize`,()=>{Xo||=(window.__electrobunWebviewId&&(document.body.style.height=`calc(100% - 26px)`),!0)}),(0,cr.createRoot)(document.getElementById(`root`)).render((0,Q.jsx)(Z.StrictMode,{children:(0,Q.jsx)(dn,{children:(0,Q.jsx)(Yo,{})})}));export{dr as _,$ as a,na as c,fr as d,br as f,vr as g,yr as h,oo as i,$i as l,hr as m,_o as n,pa as o,xr as p,go as r,ca as s,vo as t,Cr as u,ur as v};