tarsk 0.4.7 → 0.4.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +254 -129
- package/dist/public/assets/account-view-D2dv34vY.js +1 -0
- package/dist/public/assets/{add-agent-view-B9IQjAwU.js → add-agent-view-DM__lVyy.js} +1 -1
- package/dist/public/assets/add-rule-view-BomwxNHB.js +7 -0
- package/dist/public/assets/{add-skill-view-Cuu6Z0fr.js → add-skill-view-JiUioTS0.js} +1 -1
- package/dist/public/assets/{add-slash-command-view-uW75Jvbh.js → add-slash-command-view--JU5d22L.js} +1 -1
- package/dist/public/assets/conversation-history-view-C2i3vP6t.js +1 -0
- package/dist/public/assets/{dialogs-config-DiFQjCeA.js → dialogs-config-CdogKQE6.js} +13 -13
- package/dist/public/assets/diff-view-BOokQeYx.js +3 -0
- package/dist/public/assets/file-tree-sidebar-BXedO8ZD.js +1 -0
- package/dist/public/assets/{files-view-CUZn7G0o.js → files-view-BK-J3s66.js} +1 -1
- package/dist/public/assets/history-view-DtTMEZIl.js +1 -0
- package/dist/public/assets/index-BR4u03pf.js +17 -0
- package/dist/public/assets/index-LCD_R39p.css +1 -0
- package/dist/public/assets/mcp-manager-BNA3V6Cy.js +1 -0
- package/dist/public/assets/{mcp-server-edit-view-BAwMNOAH.js → mcp-server-edit-view-B_xPUXV1.js} +3 -3
- package/dist/public/assets/mcp-servers-sidebar-Cv-D6sy7.js +1 -0
- package/dist/public/assets/{mcp-view-Cz7nelGQ.js → mcp-view-TSM0sRuR.js} +1 -1
- package/dist/public/assets/onboarding-dialog-C3veuByQ.js +1 -0
- package/dist/public/assets/onboarding-gO0dp5Em.js +1 -0
- package/dist/public/assets/project-settings-view-CwvIMmXu.js +1 -0
- package/dist/public/assets/provider-details-view-Dcm9ZdOm.js +1 -0
- package/dist/public/assets/{providers-sidebar-C4MF6i9d.js → providers-sidebar-B5hxgXyK.js} +1 -1
- package/dist/public/assets/radio-group-BQ7i054U.js +1 -0
- package/dist/public/assets/react-vendor-BNQTbRKd.js +17 -0
- package/dist/public/assets/settings-view-Di5K8IgA.js +2 -0
- package/dist/public/assets/{store-BVVGurzl.js → store-CB5vVIg-.js} +2 -2
- package/dist/public/assets/{use-toast-DEJkXPN4.js → use-toast-DCmq-wgl.js} +1 -1
- package/dist/public/assets/{utils-DY_quHB8.js → utils-B7eoN2Bj.js} +1 -1
- package/dist/public/index.html +10 -10
- package/package.json +1 -1
- package/dist/public/assets/add-rule-view-BdZHurB3.js +0 -7
- package/dist/public/assets/conversation-history-view-D0OBxJMC.js +0 -1
- package/dist/public/assets/diff-view-B5XBM5UZ.js +0 -3
- package/dist/public/assets/file-tree-sidebar-DMX7fHi7.js +0 -1
- package/dist/public/assets/history-view-B8HM78Wa.js +0 -1
- package/dist/public/assets/index-C-p81QYw.js +0 -17
- package/dist/public/assets/index-DhVMb7D6.css +0 -1
- package/dist/public/assets/mcp-manager-CEm1L3dn.js +0 -1
- package/dist/public/assets/mcp-servers-sidebar-Ncxq9Oj5.js +0 -1
- package/dist/public/assets/onboarding-CvpvkF3X.js +0 -1
- package/dist/public/assets/onboarding-dialog-CKJw0ULj.js +0 -1
- package/dist/public/assets/project-settings-view-DJ1uvrTL.js +0 -1
- package/dist/public/assets/provider-details-view-CkS6WbnK.js +0 -1
- package/dist/public/assets/radio-group-BItFbSTw.js +0 -1
- package/dist/public/assets/react-vendor-DkKo9QGO.js +0 -17
- package/dist/public/assets/settings-view-C45kmAGH.js +0 -2
- /package/dist/public/assets/{monaco-DvsnxTfD.js → monaco-DKN4dKR5.js} +0 -0
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/dialogs-config-DiFQjCeA.js","assets/rolldown-runtime-Dw2cE7zH.js","assets/diff-view-B5XBM5UZ.js","assets/react-vendor-DkKo9QGO.js","assets/history-view-B8HM78Wa.js","assets/monaco-DvsnxTfD.js","assets/onboarding-CvpvkF3X.js","assets/store-BVVGurzl.js","assets/utils-DY_quHB8.js","assets/onboarding-dialog-CKJw0ULj.js","assets/conversation-history-view-D0OBxJMC.js","assets/settings-view-C45kmAGH.js","assets/use-toast-DEJkXPN4.js"])))=>i.map(i=>d[i]);
|
|
2
|
-
import{r as e}from"./rolldown-runtime-Dw2cE7zH.js";import{$n as t,$r as n,$t as r,A as i,Ai as a,Ar as o,At as s,B as c,Br as l,Ci as u,Cr as d,Ct as f,D as p,Di as m,Dr as h,Dt as g,Er as _,Et as v,Ft as y,Gn as b,Gr as x,Gt as S,Hr as C,Ht as w,Ir as T,J as E,Jn as D,Jr as O,Jt as k,Kn as A,Kr as j,Kt as M,L as N,Lr as P,Lt as F,M as I,Mi as L,Mn as R,Mr as z,Mt as B,Nr as V,Nt as H,Oi as U,Or as ee,Ot as te,P as W,Pr as ne,Pt as re,Q as ie,Qt as ae,Rr as oe,Rt as se,S as ce,Si as le,Sr as G,St as ue,T as de,Ti as fe,Tr as pe,Tt as me,Ur as he,Ut as ge,V as _e,Wn as K,Wr as ve,Wt as ye,X as be,Xr as xe,Y as Se,Z as Ce,Zn as q,Zr as we,_ as Te,_i as Ee,_r as De,ai as Oe,an as ke,ar as Ae,at as je,b as Me,bi as Ne,br as Pe,bt as Fe,c as Ie,ci as Le,cn as Re,cr as ze,dn as Be,dr as Ve,dt as He,ei as Ue,en as We,er as Ge,et as Ke,fi as qe,fr as Je,ft as Ye,g as Xe,gi as Ze,gr as Qe,gt as $e,h as et,hi as tt,hr as nt,ht as rt,ii as it,in as at,ir as ot,j as st,jt as ct,k as lt,kr as ut,kt as dt,l as ft,li as pt,ln as mt,lr as ht,lt as gt,mi as _t,mr as vt,ni as yt,nn as bt,nr as xt,nt as St,on as Ct,or as wt,ot as Tt,pi as Et,q as Dt,qn as Ot,qr as kt,qt as At,rn as jt,rr as Mt,rt as Nt,si as Pt,sn as Ft,sr as It,st as Lt,ti as Rt,tr as zt,u as Bt,ui as Vt,un as Ht,ur as Ut,v as Wt,vi as Gt,vr as Kt,w as qt,wi as Jt,wr as Yt,wt as Xt,x as Zt,xi as Qt,xr as $t,xt as en,y as tn,yt as nn,z as rn,zr as an}from"./dialogs-config-DiFQjCeA.js";import{$ as on,A as sn,B as cn,C as ln,D as un,F as dn,G as fn,H as pn,I as mn,J as hn,K as gn,L as _n,M as vn,N as yn,O as bn,S as xn,T as Sn,U as Cn,V as wn,W as Tn,X as En,Y as Dn,_ as On,b as kn,c as An,d as jn,et as Mn,f as Nn,g as Pn,h as Fn,j as In,l as Ln,m as Rn,p as zn,q as Bn,u as Vn,v as Hn,w as Un,x as Wn,y as Gn,z as Kn}from"./react-vendor-DkKo9QGO.js";import{a as qn,c as Jn,d as Yn,f as Xn,i as Zn,l as Qn,n as $n,o as er,p as tr,r as nr,s as rr,t as J,u as ir}from"./store-BVVGurzl.js";import{c as Y,l as ar,s as or,u as sr}from"./history-view-B8HM78Wa.js";import{n as cr,t as lr}from"./utils-DY_quHB8.js";import{n as ur,r as dr}from"./onboarding-CvpvkF3X.js";import{n as fr,t as X}from"./use-toast-DEJkXPN4.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 pr=Mn(),Z=a(),Q=e(L(),1),$=D();function mr(e){let t=(0,Z.c)(24),{node:n,level:r,renderNode:i,defaultOpen:a,indent:o,childContainerClassName:s,openState:c,onToggle:l}=e,u=!!(n.children&&n.children.length>0),d=c[n.id]??a,f;t[0]!==n.id||t[1]!==l?(f=()=>l(n.id),t[0]=n.id,t[1]=l,t[2]=f):f=t[2];let p=f,m;t[3]!==u||t[4]!==d||t[5]!==r||t[6]!==n||t[7]!==i||t[8]!==p?(m=i(n,{isOpen:d,level:r,toggle:p,hasChildren:u}),t[3]=u,t[4]=d,t[5]=r,t[6]=n,t[7]=i,t[8]=p,t[9]=m):m=t[9];let h;t[10]!==s||t[11]!==a||t[12]!==u||t[13]!==o||t[14]!==d||t[15]!==r||t[16]!==n.children||t[17]!==l||t[18]!==c||t[19]!==i?(h=u&&d&&(0,$.jsx)(`div`,{style:{paddingLeft:o},className:s,children:n.children.map(e=>(0,$.jsx)(mr,{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,$.jsxs)(`div`,{className:`min-w-0`,children:[m,h]}),t[21]=m,t[22]=h,t[23]=g):g=t[23],g}function hr(e){let t=(0,Z.c)(23),{nodes:n,renderNode:r,resetKey:i,defaultOpen:a,indent:o,childContainerClassName:s,className:c}=e,l=a===void 0?!1:a,u=o===void 0?16:o,d;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(d={},t[0]=d):d=t[0];let[f,p]=(0,Q.useState)(d),[m,h]=(0,Q.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=q(`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,$.jsx)(mr,{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,$.jsx)(`div`,{className:v,children:y}),t[20]=v,t[21]=y,t[22]=b):b=t[22],b}function gr(){let e=(0,Z.c)(8),{theme:t,setTheme:n}=cr(),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,s;e[3]===Symbol.for(`react.memo_cache_sentinel`)?(i=(0,$.jsx)(Je,{className:`h-[1.2rem] w-[1.2rem] rotate-0 scale-100 transition-all dark:-rotate-90 dark:scale-0`}),a=(0,$.jsx)(o,{className:`absolute h-[1.2rem] w-[1.2rem] rotate-90 scale-0 transition-all dark:rotate-0 dark:scale-100`}),s=(0,$.jsx)(`span`,{className:`sr-only`,children:`Toggle theme`}),e[3]=i,e[4]=a,e[5]=s):(i=e[3],a=e[4],s=e[5]);let c;return e[6]===r?c=e[7]:(c=(0,$.jsxs)(K,{variant:`ghost`,size:`icon`,className:`h-8 w-8 text-sidebar-foreground`,onClick:r,children:[i,a,s]}),e[6]=r,e[7]=c),c}function _r({children:e,collapsed:t,title:n,onTitleClose:r,subtitle:i,headerAction:a,footer:o,onResetOnboarding:s}){let c=(0,Q.useRef)(0),l=(0,Q.useRef)(null);return(0,Q.useEffect)(()=>()=>{l.current&&clearTimeout(l.current)},[]),(0,$.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,$.jsxs)(`div`,{className:`flex items-center justify-between border-b border-sidebar-border px-4 py-3 h-[61px]`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(`div`,{className:`flex h-7 w-7 items-center justify-center overflow-hidden rounded-md border border-sidebar-border shadow-sm`,children:(0,$.jsx)(`img`,{src:`/tarsk.svg`,alt:`Tarsk`,className:`h-full w-full cursor-pointer`,onClick:s?async()=>{if(l.current&&clearTimeout(l.current),c.current+=1,c.current>=3){c.current=0;let{resetOnboarding:e}=await on(async()=>{let{resetOnboarding:e}=await import(`./dialogs-config-DiFQjCeA.js`).then(e=>e.C);return{resetOnboarding:e}},__vite__mapDeps([0,1]));e()}else l.current=setTimeout(()=>{c.current=0},500)}:void 0})}),!t&&(0,$.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,$.jsx)(`span`,{className:`text-sm font-semibold tracking-tight`,children:`Tarsk`}),i&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Gt,{className:`h-3 w-3 text-sidebar-foreground/60`}),(0,$.jsx)(`span`,{className:`text-sm font-medium text-sidebar-foreground/80`,children:i})]})]})]}),(n??r??a)&&(0,$.jsxs)(`div`,{className:`flex items-center gap-2 ml-auto`,children:[a&&!t&&a,n&&(0,$.jsx)(`span`,{className:`text-xs font-medium text-sidebar-foreground/80`,children:n}),r&&(0,$.jsxs)(K,{variant:`ghost`,size:`icon`,className:`h-7 w-7 text-sidebar-foreground`,onClick:r,children:[(0,$.jsx)(ot,{className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:`sr-only`,children:`Close`})]})]})]}),(0,$.jsx)(R,{className:`flex-1`,children:e}),o&&(0,$.jsx)(`div`,{className:`border-t border-sidebar-border`,children:o})]})}var vr=Q.forwardRef((e,t)=>{let n=(0,Z.c)(23),r,i,a,o,s,c,l,u,d;n[0]===e?(r=n[1],i=n[2],a=n[3],o=n[4],s=n[5],c=n[6],l=n[7],u=n[8],d=n[9]):({className:i,selected:c,noBackground:o,level:a,basePadding:r,indentSize:u,asChild:d,style:l,...s}=e,n[0]=e,n[1]=r,n[2]=i,n[3]=a,n[4]=o,n[5]=s,n[6]=c,n[7]=l,n[8]=u,n[9]=d);let f=u===void 0?20:u,p=d===void 0?!1:d,m=a===void 0?void 0:(r??12)+a*f,h=p?Ot:`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=q(`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,$.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});vr.displayName=`StandardListItem`;function yr(e){let n=(0,Z.c)(52),{projects:r,selectedThreadId:i,selectedProjectId:a,processingThreadIds:o,completedThreadIds:s,deletingThreadIds:c,deletingProjectIds:l,onSelectThread:u,onCreateProject:d,onCreateThread:f,onDeleteThread:p,onDeleteProject:m,onNavigateToSettings:h,onProjectSettings:g,onViewHistory:_,collapsed:v,updateAvailable:y,updatingApp:b,onUpdateApp:x}=e,S;n[0]===r?S=n[1]:(S=r.map(br),n[0]=r,n[1]=S);let C=S,w;n[2]!==v||n[3]!==d?(w=!v&&(0,$.jsxs)(K,{variant:`outline`,size:`sm`,className:`gap-2`,onClick:d,children:[(0,$.jsx)(G,{className:`h-4 w-4 shrink-0`}),(0,$.jsx)(`span`,{className:`truncate`,children:`New Project`})]}),n[2]=v,n[3]=d,n[4]=w):w=n[4];let T;n[5]!==v||n[6]!==x||n[7]!==y||n[8]!==b?(T=y&&(0,$.jsxs)(K,{variant:`ghost`,size:`sm`,className:`w-full justify-start gap-2 text-emerald-600 dark:text-emerald-400`,onClick:x,disabled:b,children:[b?(0,$.jsx)(P,{className:`h-4 w-4 animate-spin`}):(0,$.jsx)(Oe,{className:`h-4 w-4`}),!v&&(0,$.jsx)(`span`,{className:`truncate`,children:b?`Updating...`:`Update to Latest`})]}),n[5]=v,n[6]=x,n[7]=y,n[8]=b,n[9]=T):T=n[9];let E;n[10]!==h||n[11]!==g||n[12]!==a?(E=()=>a&&g?g(a):h(),n[10]=h,n[11]=g,n[12]=a,n[13]=E):E=n[13];let D;n[14]===Symbol.for(`react.memo_cache_sentinel`)?(D=(0,$.jsx)(De,{className:`h-4 w-4`}),n[14]=D):D=n[14];let O;n[15]===v?O=n[16]:(O=!v&&(0,$.jsx)(`span`,{className:`truncate`,children:`Settings`}),n[15]=v,n[16]=O);let k;n[17]!==E||n[18]!==O?(k=(0,$.jsxs)(K,{variant:`ghost`,size:`sm`,className:`flex-1 justify-start gap-2 text-sidebar-foreground`,onClick:E,children:[D,O]}),n[17]=E,n[18]=O,n[19]=k):k=n[19];let A;n[20]===Symbol.for(`react.memo_cache_sentinel`)?(A=(0,$.jsx)(gr,{}),n[20]=A):A=n[20];let j;n[21]===k?j=n[22]:(j=(0,$.jsxs)(`div`,{className:`flex items-center gap-1`,children:[k,A]}),n[21]=k,n[22]=j);let M;n[23]!==T||n[24]!==j?(M=(0,$.jsxs)(`div`,{className:`px-3 py-2 flex flex-col gap-1`,children:[T,j]}),n[23]=T,n[24]=j,n[25]=M):M=n[25];let N;n[26]===r.length?N=n[27]:(N=r.length===0&&(0,$.jsx)(`p`,{className:`px-3 py-6 text-center text-xs text-muted-foreground`,children:`No projects yet. Clone a repository to get started.`}),n[26]=r.length,n[27]=N);let F;n[28]!==s||n[29]!==l||n[30]!==c||n[31]!==f||n[32]!==m||n[33]!==p||n[34]!==u||n[35]!==_||n[36]!==o||n[37]!==r||n[38]!==a||n[39]!==i?(F=(e,n)=>{let{isOpen:d,toggle:h}=n;return e.kind===`project`?(0,$.jsx)(xr,{project:e.project,isOpen:d,onToggle:h,isDeletingProject:l.includes(e.project.projectId),isSelected:a?e.project.projectId===a:!1,onViewHistory:_,onCreateThread:f,onDeleteProject:m,hasSelectedThread:e.project.threads.some(e=>e.threadId===i)}):(0,$.jsx)(Sr,{thread:e.thread,projectId:e.projectId,selectedThreadId:i,isProcessing:o.includes(e.thread.threadId),isDeleting:c.includes(e.thread.threadId),isCompleted:s.includes(e.thread.threadId),projectTitlePrefix:`${t(r.find(t=>t.projectId===e.projectId))} - `,onSelectThread:u,onDeleteThread:p})},n[28]=s,n[29]=l,n[30]=c,n[31]=f,n[32]=m,n[33]=p,n[34]=u,n[35]=_,n[36]=o,n[37]=r,n[38]=a,n[39]=i,n[40]=F):F=n[40];let I;n[41]!==C||n[42]!==F?(I=(0,$.jsx)(hr,{nodes:C,defaultOpen:!0,childContainerClassName:`ml-4 border-l border-sidebar-border pl-2`,renderNode:F}),n[41]=C,n[42]=F,n[43]=I):I=n[43];let L;n[44]!==N||n[45]!==I?(L=(0,$.jsx)(R,{className:`flex-1 w-full`,children:(0,$.jsxs)(`div`,{className:`px-2 py-2 w-full max-w-full overflow-hidden`,children:[N,I]})}),n[44]=N,n[45]=I,n[46]=L):L=n[46];let z;return n[47]!==v||n[48]!==M||n[49]!==L||n[50]!==w?(z=(0,$.jsx)(_r,{collapsed:v,headerAction:w,footer:M,children:L}),n[47]=v,n[48]=M,n[49]=L,n[50]=w,n[51]=z):z=n[51],z}function br(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 xr(e){let n=(0,Z.c)(26),{project:r,isOpen:i,onToggle:a,isDeletingProject:o,hasSelectedThread:s,isSelected:c,onViewHistory:l,onCreateThread:u,onDeleteProject:d}=e,f;n[0]===r?f=n[1]:(f=t(r),n[0]=r,n[1]=f);let p=f,m=s||c,h=i&&`rotate-90`,g;n[2]===h?g=n[3]:(g=q(`h-3.5 w-3.5 shrink-0 text-muted-foreground transition-transform`,h),n[2]=h,n[3]=g);let _;n[4]===g?_=n[5]:(_=(0,$.jsx)(Gt,{className:g}),n[4]=g,n[5]=_);let v;n[6]===Symbol.for(`react.memo_cache_sentinel`)?(v=(0,$.jsx)(we,{className:`h-3.5 w-3.5 shrink-0 text-muted-foreground`}),n[6]=v):v=n[6];let y=(s||c)&&`font-bold text-foreground`,b;n[7]===y?b=n[8]:(b=q(`min-w-0 truncate transition-all block`,y),n[7]=y,n[8]=b);let x;n[9]!==p||n[10]!==b?(x=(0,$.jsx)(`span`,{className:b,children:p}),n[9]=p,n[10]=b,n[11]=x):x=n[11];let S;n[12]!==_||n[13]!==x?(S=(0,$.jsxs)(`div`,{className:`flex min-w-0 flex-1 items-center gap-1.5 w-0`,children:[_,v,x]}),n[12]=_,n[13]=x,n[14]=S):S=n[14];let C;n[15]!==o||n[16]!==u||n[17]!==d||n[18]!==l||n[19]!==r?(C=(0,$.jsx)(`div`,{className:`flex shrink-0 items-center ml-auto`,children:o?(0,$.jsx)(P,{className:`h-3.5 w-3.5 shrink-0 animate-spin text-muted-foreground mr-1`}):(0,$.jsxs)(ar,{children:[(0,$.jsxs)(or,{children:[(0,$.jsx)(sr,{asChild:!0,children:(0,$.jsxs)(K,{variant:`ghost`,size:`icon`,className:`h-7 w-7 shrink-0 hidden group-hover:flex items-center justify-center`,onClick:e=>{e.stopPropagation(),l({type:`project`,id:r.projectId})},children:[(0,$.jsx)(qe,{className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:`sr-only`,children:`View project history`})]})}),(0,$.jsx)(Y,{side:`right`,children:`View project history`})]}),(0,$.jsxs)(or,{children:[(0,$.jsx)(sr,{asChild:!0,children:(0,$.jsxs)(K,{variant:`action`,size:`icon-sm`,className:`shrink-0 hidden group-hover:flex items-center justify-center`,onClick:e=>{e.stopPropagation(),u(r.projectId)},children:[(0,$.jsx)(G,{}),(0,$.jsx)(`span`,{className:`sr-only`,children:`Add thread`})]})}),(0,$.jsx)(Y,{side:`right`,children:`Add thread`})]}),r.threads.length===0&&(0,$.jsxs)(or,{children:[(0,$.jsx)(sr,{asChild:!0,children:(0,$.jsxs)(K,{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(),d(r.projectId)},children:[(0,$.jsx)(Ut,{}),(0,$.jsx)(`span`,{className:`sr-only`,children:`Delete project`})]})}),(0,$.jsx)(Y,{side:`right`,children:`Delete project`})]})]})}),n[15]=o,n[16]=u,n[17]=d,n[18]=l,n[19]=r,n[20]=C):C=n[20];let w;return n[21]!==a||n[22]!==S||n[23]!==C||n[24]!==m?(w=(0,$.jsxs)(vr,{selected:m,noBackground:!0,className:`mb-1 h-9`,onClick:a,children:[S,C]}),n[21]=a,n[22]=S,n[23]=C,n[24]=m,n[25]=w):w=n[25],w}function Sr(e){let t=(0,Z.c)(27),{thread:n,projectId:r,selectedThreadId:i,isProcessing:a,isDeleting:o,isCompleted:s,projectTitlePrefix:c,onSelectThread:l,onDeleteThread:u}=e,d=n.threadId===i,f,p;t[0]!==l||t[1]!==r||t[2]!==n.threadId?(f=()=>l(r,n.threadId),p=e=>{(e.key===`Enter`||e.key===` `)&&l(r,n.threadId)},t[0]=l,t[1]=r,t[2]=n.threadId,t[3]=f,t[4]=p):(f=t[3],p=t[4]);let m;t[5]===n.gitStatusDot?m=t[6]:(m=n.gitStatusDot?(0,$.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,$.jsx)(`circle`,{cx:`6`,cy:`6`,r:`5`})}):(0,$.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,$.jsx)(`circle`,{cx:`6`,cy:`6`,r:`4.5`})}),t[5]=n.gitStatusDot,t[6]=m);let h;t[7]!==c||t[8]!==n.threadId||t[9]!==n.title?(h=n.title?.startsWith(c)?n.title.slice(c.length):n.title||n.threadId,t[7]=c,t[8]=n.threadId,t[9]=n.title,t[10]=h):h=t[10];let g;t[11]===h?g=t[12]:(g=(0,$.jsx)(`div`,{className:`flex-1 min-w-0 w-0`,children:(0,$.jsx)(`span`,{className:`text-sm truncate block`,children:h})}),t[11]=h,t[12]=g);let _;t[13]!==s||t[14]!==o||t[15]!==a||t[16]!==u||t[17]!==r||t[18]!==n.threadId?(_=a||o?(0,$.jsx)(P,{className:`ml-auto h-3 w-3 shrink-0 animate-spin text-muted-foreground`}):s?(0,$.jsx)(Qt,{className:`ml-auto h-3 w-3 shrink-0 text-green-500`}):(0,$.jsx)(`div`,{className:`ml-auto flex items-center gap-1`,children:(0,$.jsxs)(or,{children:[(0,$.jsx)(sr,{asChild:!0,children:(0,$.jsxs)(K,{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:e=>{e.stopPropagation(),u(r,n.threadId)},children:[(0,$.jsx)(Ut,{}),(0,$.jsx)(`span`,{className:`sr-only`,children:`Delete thread`})]})}),(0,$.jsx)(Y,{side:`right`,children:`Delete thread and files from the repo`})]})}),t[13]=s,t[14]=o,t[15]=a,t[16]=u,t[17]=r,t[18]=n.threadId,t[19]=_):_=t[19];let v;return t[20]!==d||t[21]!==f||t[22]!==p||t[23]!==m||t[24]!==g||t[25]!==_?(v=(0,$.jsxs)(vr,{selected:d,onClick:f,onKeyDown:p,role:`button`,tabIndex:0,children:[m,g,_]}),t[20]=d,t[21]=f,t[22]=p,t[23]=m,t[24]=g,t[25]=_,t[26]=v):v=t[26],v}function Cr(e){let t=(0,Z.c)(10),{content:n,className:r}=e,i;bb0:{if(!n||typeof n!=`string`){let e;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(e=[],t[0]=e):e=t[0],i=e;break bb0}let e;t[1]===n?e=t[2]:(e=Tr(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=q(`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(wr),t[5]=a,t[6]=s);let c;return t[7]!==o||t[8]!==s?(c=(0,$.jsx)(`div`,{className:o,children:s}),t[7]=o,t[8]=s,t[9]=c):c=t[9],c}function wr(e,t){return(0,$.jsx)(Er,{block:e},t)}function Tr(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 Er(e){let t=(0,Z.c)(37),{block:n}=e;switch(n.type){case`heading`:{let e=`h${n.level}`,r,i;t[0]!==e||t[1]!==n.level?(r=e,i=q({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,$.jsx)(jr,{text:n.text}),t[4]=n.text,t[5]=a);let o;return t[6]!==r||t[7]!==i||t[8]!==a?(o=(0,$.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,$.jsx)(Pr,{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,$.jsx)(`blockquote`,{className:`border-l-2 border-border pl-4 text-muted-foreground italic`,children:(0,$.jsx)(jr,{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=q(`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(Ar),t[17]=n.items,t[18]=a);let o;return t[19]!==e||t[20]!==i||t[21]!==a?(o=(0,$.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,$.jsx)(`p`,{className:`text-sm leading-relaxed text-foreground whitespace-pre-wrap break-words`,children:(0,$.jsx)(jr,{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,$.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(kr),t[26]=n.headers,t[27]=e);let r;t[28]===e?r=t[29]:(r=(0,$.jsx)(`thead`,{children:(0,$.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(Dr),t[30]=n.rows,t[31]=i);let a;t[32]===i?a=t[33]:(a=(0,$.jsx)(`tbody`,{children:i}),t[32]=i,t[33]=a);let o;return t[34]!==r||t[35]!==a?(o=(0,$.jsx)(`div`,{className:`overflow-x-auto rounded-md border border-border max-w-full`,children:(0,$.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 Dr(e,t){return(0,$.jsx)(`tr`,{className:`border-b border-border last:border-0`,children:e.map(Or)},t)}function Or(e,t){return(0,$.jsx)(`td`,{className:`px-3 py-2 text-foreground`,children:e},t)}function kr(e,t){return(0,$.jsx)(`th`,{className:`px-3 py-2 text-left font-medium text-foreground`,children:e},t)}function Ar(e,t){return(0,$.jsx)(`li`,{children:(0,$.jsx)(jr,{text:e})},t)}function jr(e){let t=(0,Z.c)(4),{text:n}=e,r;t[0]===n?r=t[1]:(r=Nr(n).map(Mr),t[0]=n,t[1]=r);let i;return t[2]===r?i=t[3]:(i=(0,$.jsx)($.Fragment,{children:r}),t[2]=r,t[3]=i),i}function Mr(e,t){switch(e.type){case`bold`:return(0,$.jsx)(`strong`,{className:`font-semibold`,children:e.text},t);case`italic`:return(0,$.jsx)(`em`,{children:e.text},t);case`strikethrough`:return(0,$.jsx)(`del`,{className:`text-muted-foreground`,children:e.text},t);case`code`:return(0,$.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,$.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,$.jsx)(`span`,{children:e.text},t)}}function Nr(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 Pr(e){let t=(0,Z.c)(18),{language:n,code:r}=e,[i,a]=(0,Q.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,$.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,$.jsx)(Qt,{}):(0,$.jsx)(pt,{}),t[4]=i,t[5]=u);let d;t[6]===Symbol.for(`react.memo_cache_sentinel`)?(d=(0,$.jsx)(`span`,{className:`sr-only`,children:`Copy code`}),t[6]=d):d=t[6];let f;t[7]!==s||t[8]!==u?(f=(0,$.jsxs)(K,{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,$.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,$.jsx)(`pre`,{className:`overflow-x-auto p-4 max-w-full`,children:(0,$.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,$.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 Fr=Tn,Ir=fn,Lr=Q.forwardRef((e,t)=>{let n=(0,Z.c)(13),r,i,a,o;n[0]===e?(r=n[1],i=n[2],a=n[3],o=n[4]):({className:r,align:a,sideOffset:o,...i}=e,n[0]=e,n[1]=r,n[2]=i,n[3]=a,n[4]=o);let s=a===void 0?`center`:a,c=o===void 0?4:o,l;n[5]===r?l=n[6]:(l=q(`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,$.jsx)(Cn,{children:(0,$.jsx)(pn,{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});Lr.displayName=pn.displayName;function Rr(e){let t=e.toLowerCase();return t.includes(`read`)||t.includes(`file`)?Jt:t.includes(`create`)?G:t.includes(`replace`)||t.includes(`edit`)?nt:t.includes(`delete`)?Ze:t.includes(`terminal`)||t.includes(`bash`)||t.includes(`shell`)?Ve:t.includes(`run`)?Mt:t.includes(`git`)||t.includes(`branch`)?O:t.includes(`search`)||t.includes(`grep`)||t.includes(`find`)?$t:t.includes(`code`)||t.includes(`debug`)?Vt:t.includes(`test`)?tt:t.includes(`agent`)||t.includes(`subagent`)?ut:t.includes(`copy`)?pt:t.includes(`dir`)||t.includes(`list`)||t.includes(`ls`)?T:t.includes(`view`)||t.includes(`show`)?yt:t.includes(`config`)||t.includes(`setting`)?De:t.includes(`chat`)||t.includes(`message`)||t.includes(`ask`)?ne:Ae}function zr(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 Br(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 Vr(e){return typeof e==`string`?e:typeof e==`object`&&e?JSON.stringify(e,null,2):String(e)}function Hr(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 Ur(e){if(typeof e!=`object`||!e)return e;if(Array.isArray(e))return e.map(Ur);let t={};for(let[n,r]of Object.entries(e))if(typeof r==`string`){let e=Hr(r);t[n]=typeof e==`object`?Ur(e):r}else t[n]=Ur(r);return t}function Wr(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 Gr(e){if(e==null)return``;let t=typeof e==`object`&&e?Ur(e):e;return Wr(typeof t==`string`?t:t==null?``:JSON.stringify(t,null,2))}function Kr(e){let t=(0,Z.c)(113),{block:n,inline:r,resultContent:i}=e,[a,o]=(0,Q.useState)(!1),[s,c]=(0,Q.useState)(!1),{state:l}=qn(),u,d,f,p,m,h,g,_,v,y,b;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;b=n.name??`Unknown Tool`,v=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),g=s,f=i&&typeof i==`object`?i:null,u=b===`agent`&&f&&typeof f.agentName==`string`?f.agentName:null,y=a?null:Br(Vr(i),r),h=Br(a?String(i.prompt):null,r),d=Br(f&&typeof f.command==`string`?f.command:null,r),m=f&&typeof f.pattern==`string`?f.pattern:null,p=f&&typeof f.lang==`string`?f.lang:null,_=Br(f&&typeof f.path==`string`?f.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]=d,t[8]=f,t[9]=p,t[10]=m,t[11]=h,t[12]=g,t[13]=_,t[14]=v,t[15]=y,t[16]=b}else u=t[6],d=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];let x=_,S=f&&typeof f.offset==`number`?f.offset:null,C=f&&typeof f.limit==`number`?f.limit:null,w,T,E,D,O,k;if(t[21]!==u||t[22]!==d||t[23]!==s||t[24]!==a||t[25]!==r||t[26]!==f||t[27]!==p||t[28]!==C||t[29]!==S||t[30]!==x||t[31]!==m||t[32]!==h||t[33]!==i||t[34]!==g||t[35]!==v||t[36]!==y||t[37]!==b){k=Symbol.for(`react.early_return_sentinel`);bb0:{let e=Rr(b),n=b===`todo`&&f?f.status:void 0,l=(b===`todo`?n===`done`?tt:n===`working`?_t:Et:null)??e,_;t[44]!==C||t[45]!==S||t[46]!==b?(_=()=>{let e=b.charAt(0).toUpperCase()+b.slice(1);if(b.toLowerCase()===`bash`&&(e=`Ran`),b.toLowerCase()===`ast_grep`&&(e=`Code Search`),b.toLowerCase().includes(`read`)&&(S!==null||C!==null)){let t=S===null?1:S+1,n=C!==null&&S!==null?t+C-1:null;e+=` lines ${t}${n?` to ${n}`:`+`}`}return e},t[44]=C,t[45]=S,t[46]=b,t[47]=_):_=t[47];let A=_;if(r){if(b===`todo`){k=null;break bb0}if(d!==null&&i){let e;t[48]===Symbol.for(`react.memo_cache_sentinel`)?(e=()=>c(!0),t[48]=e):e=t[48];let n=(0,Q.createElement)(l,{className:`h-3.5 w-3.5 shrink-0 text-brand`}),r=A(),a;t[49]===r?a=t[50]:(a=(0,$.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:r}),t[49]=r,t[50]=a);let o;t[51]===d?o=t[52]:(o=(0,$.jsx)(`code`,{className:`text-xs font-mono text-muted-foreground break-all rounded bg-muted/60 px-1 py-0.5`,children:d}),t[51]=d,t[52]=o);let u;t[53]===d?u=t[54]:(u=(0,$.jsx)(Ht,{children:(0,$.jsx)(Be,{children:(0,$.jsx)(`code`,{className:`text-sm font-mono`,children:d})})}),t[53]=d,t[54]=u);let f;t[55]===i?f=t[56]:(f=(0,$.jsx)(`pre`,{className:`text-xs bg-muted p-3 rounded font-mono whitespace-pre-wrap overflow-auto flex-1 text-foreground`,children:i}),t[55]=i,t[56]=f);let p;t[57]!==u||t[58]!==f?(p=(0,$.jsxs)(Ft,{className:`max-w-3xl max-h-[80vh] flex flex-col`,children:[u,f]}),t[57]=u,t[58]=f,t[59]=p):p=t[59];let m;t[60]!==s||t[61]!==p?(m=(0,$.jsx)(Ct,{open:s,onOpenChange:c,children:p}),t[60]=s,t[61]=p,t[62]=m):m=t[62],k=(0,$.jsxs)($.Fragment,{children:[(0,$.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=h??(y&&!d&&!x&&!m)?(0,$.jsxs)(Fr,{children:[(0,$.jsx)(Ir,{asChild:!0,children:(0,$.jsx)(`span`,{title:b,className:`inline-flex`,children:(0,$.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,Q.createElement)(l,{className:`h-3.5 w-3.5 text-brand`}),(0,$.jsx)(`span`,{className:`text-xs`,children:A()})]})})}),(0,$.jsx)(Lr,{className:`w-80 max-h-80 overflow-auto`,align:`start`,children:(0,$.jsxs)(`div`,{className:`text-xs text-muted-foreground space-y-2`,children:[(0,$.jsxs)(`div`,{className:`font-mono`,children:[`ID: `,v]}),h?(0,$.jsx)(`div`,{className:`whitespace-pre-wrap leading-relaxed`,children:h}):y?(0,$.jsx)(`pre`,{className:`font-mono whitespace-pre-wrap overflow-auto max-h-48`,children:y}):null]})})]}):(0,$.jsxs)(`span`,{title:b,className:`inline-flex items-center gap-1`,children:[(0,Q.createElement)(l,{className:`h-3.5 w-3.5 shrink-0 text-brand`}),(0,$.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:A()})]}),n;t[63]===d?n=t[64]:(n=d!==null&&(0,$.jsx)(`code`,{className:`text-xs font-mono text-muted-foreground break-all rounded bg-muted/60 px-1 py-0.5`,children:d}),t[63]=d,t[64]=n);let r;t[65]===m?r=t[66]:(r=m!==null&&(0,$.jsx)(`code`,{className:`text-xs font-mono text-muted-foreground break-all rounded bg-muted/60 px-1 py-0.5`,children:m}),t[65]=m,t[66]=r);let a;t[67]===p?a=t[68]:(a=p!==null&&(0,$.jsx)(`span`,{className:`text-xs px-1.5 py-0.5 rounded bg-muted text-muted-foreground`,children:p}),t[67]=p,t[68]=a);let o;t[69]===x?o=t[70]:(o=x!==null&&(0,$.jsx)(`span`,{className:`text-xs font-mono text-muted-foreground truncate max-w-[200px] sm:max-w-[320px]`,title:x,children:x}),t[69]=x,t[70]=o);let f;t[71]===u?f=t[72]:(f=u&&(0,$.jsx)(`span`,{className:`text-xs px-1.5 py-0.5 rounded bg-muted text-muted-foreground font-mono`,children:u}),t[71]=u,t[72]=f);let _;t[73]===g?_=t[74]:(_=g&&(0,$.jsx)(`span`,{className:`text-xs px-2 py-0.5 rounded bg-muted text-muted-foreground`,children:g}),t[73]=g,t[74]=_);let S;t[75]!==n||t[76]!==r||t[77]!==a||t[78]!==o||t[79]!==f||t[80]!==_||t[81]!==e?(S=(0,$.jsxs)(`div`,{className:`py-0.5 flex items-center gap-2 flex-wrap`,children:[e,n,r,a,o,f,_]}),t[75]=n,t[76]=r,t[77]=a,t[78]=o,t[79]=f,t[80]=_,t[81]=e,t[82]=S):S=t[82],k=S;break bb0}O=`mb-3 rounded-lg border border-blue-200 dark:border-blue-800 bg-blue-50 dark:bg-blue-900/20 overflow-hidden`,t[83]===a?w=t[84]:(w=()=>o(!a),t[83]=a,t[84]=w),T=`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`,E=b,D=(0,Q.createElement)(l,{className:`h-4 w-4 text-brand`})}t[21]=u,t[22]=d,t[23]=s,t[24]=a,t[25]=r,t[26]=f,t[27]=p,t[28]=C,t[29]=S,t[30]=x,t[31]=m,t[32]=h,t[33]=i,t[34]=g,t[35]=v,t[36]=y,t[37]=b,t[38]=w,t[39]=T,t[40]=E,t[41]=D,t[42]=O,t[43]=k}else w=t[38],T=t[39],E=t[40],D=t[41],O=t[42],k=t[43];if(k!==Symbol.for(`react.early_return_sentinel`))return k;let A;t[85]===b?A=t[86]:(A=zr(b),t[85]=b,t[86]=A);let j;t[87]===A?j=t[88]:(j=(0,$.jsx)(`span`,{className:`flex-1 text-left min-w-0 truncate`,children:A}),t[87]=A,t[88]=j);let M;t[89]===u?M=t[90]:(M=u&&(0,$.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[89]=u,t[90]=M);let N;t[91]===g?N=t[92]:(N=g&&(0,$.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:g}),t[91]=g,t[92]=N);let P;t[93]===a?P=t[94]:(P=a?(0,$.jsx)(Ne,{className:`h-4 w-4 shrink-0`}):(0,$.jsx)(Gt,{className:`h-4 w-4 shrink-0`}),t[93]=a,t[94]=P);let F;t[95]!==M||t[96]!==N||t[97]!==P||t[98]!==w||t[99]!==T||t[100]!==E||t[101]!==D||t[102]!==j?(F=(0,$.jsxs)(`button`,{onClick:w,className:T,title:E,children:[D,j,M,N,P]}),t[95]=M,t[96]=N,t[97]=P,t[98]=w,t[99]=T,t[100]=E,t[101]=D,t[102]=j,t[103]=F):F=t[103];let I;t[104]!==a||t[105]!==h||t[106]!==v||t[107]!==y?(I=a&&(0,$.jsxs)(`div`,{className:`px-3 py-2 bg-white dark:bg-slate-950 border-t border-blue-200 dark:border-blue-800`,children:[(0,$.jsxs)(`div`,{className:`text-xs text-muted-foreground mb-2 font-mono text-blue-700 dark:text-blue-300`,children:[`ID: `,v]}),h?(0,$.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:h}):y?(0,$.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:y}):null]}),t[104]=a,t[105]=h,t[106]=v,t[107]=y,t[108]=I):I=t[108];let L;return t[109]!==F||t[110]!==I||t[111]!==O?(L=(0,$.jsxs)(`div`,{className:O,children:[F,I]}),t[109]=F,t[110]=I,t[111]=O,t[112]=L):L=t[112],L}var qr=(0,Q.createContext)({todos:[],setTodos:()=>{}});function Jr(e){let t=(0,Z.c)(7),{children:n}=e,r;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(r=[],t[0]=r):r=t[0];let[i,a]=(0,Q.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,$.jsx)(qr.Provider,{value:c,children:n}),t[4]=n,t[5]=c,t[6]=l):l=t[6],l}function Yr(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 Xr(e){let t=(0,Z.c)(17),{todos:n}=e,{todos:r,setTodos:i}=(0,Q.useContext)(qr),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,Q.useEffect)(a,o);let s=r.length>0?r:n,c;t[4]===s?c=t[5]:(c=s.filter(Qr),t[4]=s,t[5]=c);let l=c.length,u;t[6]===s.length?u=t[7]:(u=s.length===0&&(0,$.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(Zr),t[8]=s,t[9]=d);let f;t[10]!==l||t[11]!==s.length?(f=s.length>0&&(0,$.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,$.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 Zr(e){return(0,$.jsxs)(`div`,{className:`flex items-start gap-2 text-sm`,children:[e.status===`done`?(0,$.jsx)(tt,{className:`h-4 w-4 shrink-0 mt-0.5 text-green-500`}):e.status===`working`?(0,$.jsx)(qe,{className:`h-4 w-4 shrink-0 mt-0.5 text-yellow-500`}):(0,$.jsx)(Et,{className:`h-4 w-4 shrink-0 mt-0.5 text-muted-foreground`}),(0,$.jsx)(`span`,{className:e.status===`done`?`line-through text-muted-foreground`:`text-foreground`,children:e.description})]},e.id)}function Qr(e){return e.status===`done`}function $r(e){let t=(0,Z.c)(4),{todos:n}=e,{setTodos:r}=(0,Q.useContext)(qr),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,Q.useEffect)(i,a),null}function ei(e){let t=(0,Z.c)(19),{todos:n}=e,[r,i]=(0,Q.useState)(!0),a;t[0]===n?a=t[1]:(a=n.filter(ti),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,$.jsx)(oe,{className:`h-4 w-4 shrink-0`}),t[4]=l):l=t[4];let u;t[5]===s?u=t[6]:(u=(0,$.jsx)(`span`,{className:`flex-1 text-left min-w-0 truncate`,children:s}),t[5]=s,t[6]=u);let d;t[7]===r?d=t[8]:(d=r?(0,$.jsx)(Ne,{className:`h-4 w-4 shrink-0`}):(0,$.jsx)(Gt,{className:`h-4 w-4 shrink-0`}),t[7]=r,t[8]=d);let f;t[9]!==c||t[10]!==u||t[11]!==d?(f=(0,$.jsxs)(`button`,{onClick:c,className:`w-full px-3 py-2 flex items-center gap-2 text-sm font-medium text-foreground hover:bg-muted transition-colors text-left`,title:`Todo list`,children:[l,u,d]}),t[9]=c,t[10]=u,t[11]=d,t[12]=f):f=t[12];let p;t[13]!==r||t[14]!==n?(p=r&&(0,$.jsx)(`div`,{className:`px-3 py-3 bg-background border-t border-border`,children:(0,$.jsx)(Xr,{todos:n})}),t[13]=r,t[14]=n,t[15]=p):p=t[15];let m;return t[16]!==f||t[17]!==p?(m=(0,$.jsxs)(`div`,{className:`mb-3 rounded-lg border border-border bg-muted/50 overflow-hidden`,children:[f,p]}),t[16]=f,t[17]=p,t[18]=m):m=t[18],m}function ti(e){return e.status===`done`}function ni(e){let t=(0,Z.c)(65),{block:n,inline:r}=e,[i,a]=(0,Q.useState)(!1),[o,s]=(0,Q.useState)(!1),{state:c}=qn(),l=c.projects,u,d,f,p,m,h,g,_;if(t[0]!==n||t[1]!==r||t[2]!==c.projects||t[3]!==c.selectedProjectId||t[4]!==c.selectedThreadId){h=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;_=n.toolName??`Unknown Tool`,g=n.toolCallId??`unknown`;let a=n,o=n.result??a.content,s;t[15]!==a||t[16]!==_?(s=_===`todo`?Yr(a):null,t[15]=a,t[16]=_,t[17]=s):s=t[17];let v=s;if(f=Br(Gr(o),i),!(f.length>0)&&v===null){h=null;break bb0}if(u=zr(_),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(_===`read`||_===`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]===_?e=t[23]:(e=zr(_),t[22]=_,t[23]=e),u=`${e} (no result)`}if(u=Br(u,i),v!==null){let e;t[24]===v?e=t[25]:(e=(0,$.jsx)($r,{todos:v}),t[24]=v,t[25]=e),h=e;break bb0}if(r){h=null;break bb0}let y;t[26]===_?y=t[27]:(y=_.toLowerCase().includes(`bash`),t[26]=_,t[27]=y),d=y,p=f?f.split(`
|
|
9
|
-
`):[],m=d?p.slice(0,3).join(`
|
|
10
|
-
`):f}t[0]=n,t[1]=r,t[2]=c.projects,t[3]=c.selectedProjectId,t[4]=c.selectedThreadId,t[5]=u,t[6]=d,t[7]=f,t[8]=p,t[9]=m,t[10]=h,t[11]=g,t[12]=_}else u=t[5],d=t[6],f=t[7],p=t[8],m=t[9],h=t[10],g=t[11],_=t[12];if(h!==Symbol.for(`react.early_return_sentinel`))return h;let v=m,y=d&&p.length>3;if(d){let e;t[28]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,$.jsx)(tt,{className:`h-4 w-4 shrink-0`}),t[28]=e):e=t[28];let n;t[29]===u?n=t[30]:(n=(0,$.jsxs)(`div`,{className:`px-3 py-2 flex items-center gap-2 text-sm font-medium text-foreground`,children:[e,(0,$.jsx)(`span`,{className:`flex-1 text-left min-w-0 truncate`,children:u})]}),t[29]=u,t[30]=n);let r;t[31]!==y||t[32]!==v||t[33]!==f||t[34]!==p?(r=f&&(0,$.jsxs)(`div`,{className:`px-3 pb-2 bg-background border-t border-border`,children:[(0,$.jsxs)(`pre`,{className:`text-xs bg-muted p-2 rounded font-mono whitespace-pre-wrap overflow-auto text-foreground text-left mt-2${y?` cursor-pointer hover:bg-muted/80`:``}`,onClick:y?()=>s(!0):void 0,title:y?`Click to see full output`:void 0,children:[v,y&&(0,$.jsxs)(`span`,{className:`text-muted-foreground`,children:[`
|
|
11
|
-
`,`...`]})]}),y&&(0,$.jsxs)(`button`,{type:`button`,onClick:()=>s(!0),className:`mt-1 text-xs text-brand hover:underline`,children:[`Show full output (`,p.length,` lines)`]})]}),t[31]=y,t[32]=v,t[33]=f,t[34]=p,t[35]=r):r=t[35];let i;t[36]!==n||t[37]!==r?(i=(0,$.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]!==y||t[41]!==f?(a=y&&(0,$.jsx)(Ct,{open:o,onOpenChange:s,children:(0,$.jsxs)(Ft,{className:`max-w-3xl max-h-[80vh] flex flex-col`,children:[(0,$.jsx)(Ht,{children:(0,$.jsx)(Be,{children:`Full Output`})}),(0,$.jsx)(`pre`,{className:`text-xs bg-muted p-3 rounded font-mono whitespace-pre-wrap overflow-auto flex-1 text-foreground`,children:f})]})}),t[39]=o,t[40]=y,t[41]=f,t[42]=a):a=t[42];let c;return t[43]!==i||t[44]!==a?(c=(0,$.jsxs)($.Fragment,{children:[i,a]}),t[43]=i,t[44]=a,t[45]=c):c=t[45],c}let b;t[46]===i?b=t[47]:(b=()=>a(!i),t[46]=i,t[47]=b);let x=`${_} result`,S;t[48]===Symbol.for(`react.memo_cache_sentinel`)?(S=(0,$.jsx)(tt,{className:`h-4 w-4 shrink-0`}),t[48]=S):S=t[48];let C;t[49]===u?C=t[50]:(C=(0,$.jsx)(`span`,{className:`flex-1 text-left min-w-0 truncate`,children:u}),t[49]=u,t[50]=C);let w;t[51]===i?w=t[52]:(w=i?(0,$.jsx)(Ne,{className:`h-4 w-4 shrink-0`}):(0,$.jsx)(Gt,{className:`h-4 w-4 shrink-0`}),t[51]=i,t[52]=w);let T;t[53]!==b||t[54]!==x||t[55]!==C||t[56]!==w?(T=(0,$.jsxs)(`button`,{onClick:b,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:x,children:[S,C,w]}),t[53]=b,t[54]=x,t[55]=C,t[56]=w,t[57]=T):T=t[57];let E;t[58]!==i||t[59]!==f||t[60]!==g?(E=i&&(0,$.jsxs)(`div`,{className:`px-3 py-2 bg-background border-t border-border`,children:[(0,$.jsxs)(`div`,{className:`text-xs text-muted-foreground mb-2 font-mono`,children:[`Call ID: `,g]}),f&&(0,$.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:f})]}),t[58]=i,t[59]=f,t[60]=g,t[61]=E):E=t[61];let D;return t[62]!==E||t[63]!==T?(D=(0,$.jsxs)(`div`,{className:`mb-3 rounded-lg border border-border bg-muted/50 overflow-hidden`,children:[T,E]}),t[62]=E,t[63]=T,t[64]=D):D=t[64],D}function ri(e){let t=(0,Z.c)(19),{text:n,isStreaming:r,hasContentAfter:i}=e,a=r===void 0?!1:r,o=i===void 0?!1:i,[s,c]=(0,Q.useState)(null),l=(0,Q.useRef)(a),u=(0,Q.useRef)(o),d,f;if(t[0]!==o||t[1]!==a?(d=()=>{(l.current&&!a||!u.current&&o)&&(0,Q.startTransition)(()=>{c(!1)}),l.current=a,u.current=o},f=[a,o,c],t[0]=o,t[1]=a,t[2]=d,t[3]=f):(d=t[2],f=t[3]),(0,Q.useEffect)(d,f),!n?.trim())return null;let p=s??a,m;t[4]===p?m=t[5]:(m=()=>c(!p),t[4]=p,t[5]=m);let h,g;t[6]===Symbol.for(`react.memo_cache_sentinel`)?(h=(0,$.jsx)(le,{className:`h-4 w-4 shrink-0 text-brand`}),g=(0,$.jsx)(`span`,{className:`flex-1 text-left min-w-0 truncate`,children:`Thinking`}),t[6]=h,t[7]=g):(h=t[6],g=t[7]);let _;t[8]===p?_=t[9]:(_=p?(0,$.jsx)(Ne,{className:`h-4 w-4 shrink-0`}):(0,$.jsx)(Gt,{className:`h-4 w-4 shrink-0`}),t[8]=p,t[9]=_);let v;t[10]!==m||t[11]!==_?(v=(0,$.jsxs)(`button`,{onClick:m,className:`w-full py-2 flex items-center gap-2 text-sm font-medium text-foreground hover:bg-muted/50 transition-colors text-left`,title:`Thinking`,children:[h,g,_]}),t[10]=m,t[11]=_,t[12]=v):v=t[12];let y;t[13]!==p||t[14]!==n?(y=p&&(0,$.jsx)(`div`,{className:`py-2 border-t border-border`,children:(0,$.jsx)(`div`,{className:`text-xs text-muted-foreground leading-relaxed whitespace-pre-wrap`,children:n})}),t[13]=p,t[14]=n,t[15]=y):y=t[15];let b;return t[16]!==y||t[17]!==v?(b=(0,$.jsxs)(`div`,{className:`overflow-hidden`,children:[v,y]}),t[16]=y,t[17]=v,t[18]=b):b=t[18],b}function ii({toolCall:e,className:t}){let{state:n,dispatch:r}=qn(),[i,a]=(0,Q.useState)(!1),o=n.toolCallProgress[e.id];return(0,Q.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,$.jsxs)(`div`,{className:q(`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,$.jsxs)(`div`,{className:`px-3 py-2 flex items-center gap-2`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5 flex-1`,children:[(0,$.jsx)(P,{className:`h-3.5 w-3.5 animate-spin`}),(0,$.jsx)(`span`,{className:`text-sm font-medium text-blue-900 dark:text-blue-100`,children:e.name}),(0,$.jsx)(`span`,{className:`text-xs text-blue-700 dark:text-blue-300`,children:`running`})]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,$.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,$.jsx)(Ee,{className:`h-3.5 w-3.5`}):(0,$.jsx)(Ne,{className:`h-3.5 w-3.5`})}),(0,$.jsx)(`button`,{onClick:()=>{r({type:J.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:J.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,$.jsx)(ot,{className:`h-3.5 w-3.5`})})]})]}),i&&(0,$.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,$.jsxs)(`div`,{className:`text-xs text-muted-foreground mb-2 font-mono text-blue-700 dark:text-blue-300`,children:[`ID: `,e.id]}),(0,$.jsxs)(`div`,{className:`mb-2`,children:[(0,$.jsx)(`div`,{className:`text-xs font-medium text-muted-foreground mb-1`,children:`Input:`}),(0,$.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,$.jsxs)(`div`,{className:`mb-2`,children:[(0,$.jsx)(`div`,{className:`text-xs font-medium text-muted-foreground mb-1`,children:`Progress:`}),(0,$.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,$.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,$.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,$.jsxs)(`div`,{className:`flex items-center gap-2 text-xs text-blue-600 dark:text-blue-400`,children:[(0,$.jsx)(P,{className:`h-3 w-3 animate-spin`}),`Executing`,o&&` with progress`,`...`]})]})]}):null}function ai(e){let t=(0,Z.c)(51),{toolCallId:n,question:r,options:i,context:a}=e,[o,s]=(0,Q.useState)(``),[c,l]=(0,Q.useState)(!1),[u,d]=(0,Q.useState)(``),[f,p]=(0,Q.useState)(!1),[m,h]=(0,Q.useState)(null),g;t[0]!==f||t[1]!==n?(g=async e=>{if(!(!e.trim()||f)){p(!0);try{await At(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,$.jsx)(Qt,{className:`h-4 w-4`}),n=(0,$.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,$.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,$.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-green-800 dark:text-green-200`,children:[e,n,(0,$.jsx)(`span`,{children:u})]})}),t[16]=u,t[17]=r),r}let w;t[18]===Symbol.for(`react.memo_cache_sentinel`)?(w=(0,$.jsx)(_t,{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,$.jsx)(`div`,{className:`text-sm font-medium text-foreground`,children:(0,$.jsx)(Cr,{content:r})}),t[19]=r,t[20]=T);let E;t[21]===a?E=t[22]:(E=a&&(0,$.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,$.jsxs)(`div`,{className:`flex items-start gap-2 mb-3`,children:[w,(0,$.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,$.jsx)(`div`,{className:`flex flex-wrap gap-2 mb-3`,children:i.map(e=>{let t=m===e;return(0,$.jsxs)(`button`,{type:`button`,onClick:()=>y(e),disabled:f,className:q(`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,$.jsx)(Qt,{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,$.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,$.jsx)(Pe,{className:`h-4 w-4`}),t[40]=N):N=t[40];let P;t[41]!==x||t[42]!==M?(P=(0,$.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,$.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,$.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 oi(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 si(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 ci(e,t,n,r){return e.name===`ask_user`?(0,$.jsx)(ai,{toolCallId:e.id,question:JSON.stringify(e.input?.question??``),options:e.input?.options,context:e.input?.context},t):n?(0,$.jsxs)(`span`,{children:[(0,$.jsx)(ii,{toolCall:e}),(0,$.jsx)(Kr,{inline:!0,block:e,resultContent:r})]},t):(0,$.jsx)(Kr,{inline:!0,block:e,resultContent:r},t)}function li(e){let t=(0,Z.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:Xn(n.content),d;t[14]===n.timestamp?d=t[15]:(d=n.timestamp?new Date(n.timestamp).toLocaleTimeString([],{hour:`2-digit`,minute:`2-digit`}):``,t[14]=n.timestamp,t[15]=d);let f=d,p=r?`flex-row-reverse`:`flex-row`;t[16]===p?c=t[17]:(c=q(`group flex gap-3 px-4 py-4`,p),t[16]=p,t[17]=c);let m=r?`bg-foreground`:`bg-muted`,h;t[18]===m?h=t[19]:(h=q(`flex h-7 w-7 shrink-0 items-center justify-center rounded-full`,m),t[18]=m,t[19]=h);let g;t[20]===r?g=t[21]:(g=r?(0,$.jsx)(wt,{className:`h-3.5 w-3.5 text-background`}):(0,$.jsx)(u,{className:`h-3.5 w-3.5 text-muted-foreground`}),t[20]=r,t[21]=g),t[22]!==h||t[23]!==g?(l=(0,$.jsx)(`div`,{className:h,children:g}),t[22]=h,t[23]=g,t[24]=l):l=t[24];let _=r&&`items-end`;t[25]===_?o=t[26]:(o=q(`flex flex-1 flex-col gap-1 min-w-0`,_),t[25]=_,t[26]=o);let v=r&&`flex-row-reverse`,y;t[27]===v?y=t[28]:(y=q(`flex items-center gap-2`,v),t[27]=v,t[28]=y);let b=r?`You`:`Agent`,x;t[29]===b?x=t[30]:(x=(0,$.jsx)(`span`,{className:`text-xs font-medium text-foreground`,children:b}),t[29]=b,t[30]=x);let S;t[31]===f?S=t[32]:(S=f&&(0,$.jsxs)(`span`,{className:`flex items-center gap-1 text-[10px] text-muted-foreground opacity-0 group-hover:opacity-100 transition-opacity`,children:[(0,$.jsx)(qe,{className:`h-2.5 w-2.5`}),f]}),t[31]=f,t[32]=S);let C;t[33]===n.model?C=t[34]:(C=n.model&&(0,$.jsxs)(`span`,{className:`flex items-center gap-1 text-[10px] text-muted-foreground opacity-0 group-hover:opacity-100 transition-opacity`,children:[(0,$.jsx)(Pt,{className:`h-2.5 w-2.5`}),dr(n.model)]}),t[33]=n.model,t[34]=C);let w;t[35]===n.metadata?w=t[36]:(w=n.metadata?.tokenCount&&(0,$.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]!==y||t[38]!==x||t[39]!==S||t[40]!==C||t[41]!==w?(s=(0,$.jsxs)(`div`,{className:y,children:[x,S,C,w]}),t[37]=y,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=q(`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=tr(n.content);return e?.length?e.map((t,n)=>t.type===`tool_use`?ci(t,n,!1,si(e,t.id)):t.type===`tool-result`?(0,$.jsx)(ni,{inline:!0,block:t},n):t.type===`reasoning`&&`text`in t?(0,$.jsx)(ri,{text:Yn(t.text)},n):null):(0,$.jsx)(`div`,{className:`text-xs text-muted-foreground leading-relaxed whitespace-pre-wrap`,children:(0,$.jsx)(Cr,{content:Yn(n.content)})})})():e?(()=>{let t=oi(e);return(0,$.jsxs)($.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,$.jsx)(ni,{inline:!0,block:t},n):null:(0,$.jsx)(`div`,{children:t.type===`reasoning`&&`text`in t?(0,$.jsx)(ri,{text:Yn(t.text)}):t.type===`text`&&`text`in t?(0,$.jsx)(Cr,{content:Yn(t.text)}):t.type===`tool_use`?ci(t,void 0,!1,si(e,t.id)):t.type===`tool-result`?(0,$.jsx)(ni,{inline:!0,block:t}):null},n)),t.length>0&&(0,$.jsx)(ei,{todos:t})]})})():n.contentType===`markdown`||n.sender===`agent`?(0,$.jsx)(Cr,{content:Yn(n.content)}):(0,$.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 d;t[45]!==i||t[46]!==a?(d=(0,$.jsx)(`div`,{className:i,children:a}),t[45]=i,t[46]=a,t[47]=d):d=t[47];let f;t[48]===n.attachments?f=t[49]:(f=n.attachments&&n.attachments.length>0&&(0,$.jsx)(`div`,{className:`flex flex-wrap gap-1.5 mt-1`,children:n.attachments.map(ui)}),t[48]=n.attachments,t[49]=f);let p;t[50]!==o||t[51]!==s||t[52]!==d||t[53]!==f?(p=(0,$.jsxs)(`div`,{className:o,children:[s,d,f]}),t[50]=o,t[51]=s,t[52]=d,t[53]=f,t[54]=p):p=t[54];let m;return t[55]!==c||t[56]!==l||t[57]!==p?(m=(0,$.jsxs)(`div`,{className:c,children:[l,p]}),t[55]=c,t[56]=l,t[57]=p,t[58]=m):m=t[58],m}function ui(e,t){return(0,$.jsxs)(`span`,{className:`flex items-center gap-1 rounded-md bg-muted px-2 py-1 text-[10px] text-muted-foreground`,children:[(0,$.jsx)(pe,{className:`h-2.5 w-2.5`}),e.fileName]},t)}function di(e){let t=(0,Z.c)(21),{segments:n,model:r}=e,i,a,o,s,c;if(t[0]!==r||t[1]!==n){let e=Jn(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,$.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,$.jsx)(u,{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 d;t[8]===Symbol.for(`react.memo_cache_sentinel`)?(d=(0,$.jsx)(`span`,{className:`text-xs font-medium text-foreground`,children:`Agent`}),t[8]=d):d=t[8];let f;t[9]===r?f=t[10]:(f=r&&(0,$.jsxs)(`span`,{className:`flex items-center gap-1 text-[10px] text-muted-foreground opacity-0 group-hover:opacity-100 transition-opacity`,children:[(0,$.jsx)(Pt,{className:`h-2.5 w-2.5`}),dr(r)]}),t[9]=r,t[10]=f),t[11]===f?a=t[12]:(a=(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[d,f]}),t[11]=f,t[12]=a),o=e.length>0?(()=>{let t=oi(e);return(0,$.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,$.jsx)(ni,{inline:!0,block:t},`b-${n}`):null:(0,$.jsx)(`div`,{children:t.type===`reasoning`&&`text`in t?(0,$.jsx)(ri,{text:Yn(t.text),isStreaming:!0,hasContentAfter:l(n)}):t.type===`text`&&`text`in t?(0,$.jsx)(Cr,{content:Yn(t.text)}):t.type===`tool_use`?ci(t,void 0,!0,si(e,t.id)):t.type===`tool-result`?(0,$.jsx)(ni,{inline:!0,block:t}):null},`b-${n}`)),t.length>0&&(0,$.jsx)(ei,{todos:t})]})})():(0,$.jsx)(`div`,{className:`rounded-xl bg-muted px-4 py-3 min-w-0`,children:(0,$.jsxs)(`div`,{className:`flex items-center justify-center gap-1.5`,children:[(0,$.jsx)(`div`,{className:`h-2 w-2 rounded-full bg-muted-foreground/40 animate-bounce [animation-delay:0ms]`}),(0,$.jsx)(`div`,{className:`h-2 w-2 rounded-full bg-muted-foreground/40 animate-bounce [animation-delay:150ms]`}),(0,$.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,$.jsxs)(`div`,{className:i,children:[a,o]}),t[13]=i,t[14]=a,t[15]=o,t[16]=l):l=t[16];let d;return t[17]!==s||t[18]!==c||t[19]!==l?(d=(0,$.jsxs)(`div`,{className:s,children:[c,l]}),t[17]=s,t[18]=c,t[19]=l,t[20]=d):d=t[20],d}var fi=(0,Q.memo)(di,(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 pi(e){let t=(0,Z.c)(34),{projects:n,onSelectProject:r,onCreateThread:i,onConnectRepo:a,onNewApp:o,onOpenFolder:s}=e,c;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(c=(0,$.jsx)(`img`,{src:`/tarsk-color.svg`,alt:`Tarsk`,className:`h-16 w-16 rounded-lg`}),t[0]=c):c=t[0];let l;t[1]===Symbol.for(`react.memo_cache_sentinel`)?(l=(0,$.jsx)(`h1`,{className:`text-2xl font-semibold tracking-tight text-foreground text-balance`,children:`Let's build it!`}),t[1]=l):l=t[1];let u=n.length===0?`Start or connect your first project`:`Select a project to start coding`,d;t[2]===u?d=t[3]:(d=(0,$.jsxs)(`div`,{className:`flex flex-col items-center gap-3`,children:[c,(0,$.jsxs)(`div`,{className:`text-center`,children:[l,(0,$.jsx)(`p`,{className:`mt-1 text-base text-muted-foreground`,children:u})]})]}),t[2]=u,t[3]=d);let f;if(t[4]!==i||t[5]!==r||t[6]!==n){let e;t[8]!==i||t[9]!==r?(e=e=>(0,$.jsxs)(`button`,{type:`button`,className:`flex w-56 flex-col gap-2 rounded-xl border border-border bg-background p-4 text-left shadow-sm transition-colors hover:bg-muted`,onClick:()=>{e.threads.length===0?i(e.projectId):r(e.projectId,e.threads[0].threadId)},children:[(0,$.jsx)(we,{className:`h-5 w-5 text-muted-foreground`}),(0,$.jsx)(`span`,{className:`text-sm text-foreground leading-snug font-medium`,children:e.name}),(0,$.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[e.threads.length,` thread`,e.threads.length===1?``:`s`]})]},e.projectId),t[8]=i,t[9]=r,t[10]=e):e=t[10],f=n.map(e),t[4]=i,t[5]=r,t[6]=n,t[7]=f}else f=t[7];let p,m,h;t[11]===Symbol.for(`react.memo_cache_sentinel`)?(p=(0,$.jsx)(O,{className:`h-5 w-5 text-muted-foreground`}),m=(0,$.jsx)(`span`,{className:`text-sm text-foreground leading-snug font-medium`,children:`Connect a repo`}),h=(0,$.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`Clone an existing repository`}),t[11]=p,t[12]=m,t[13]=h):(p=t[11],m=t[12],h=t[13]);let g;t[14]===a?g=t[15]:(g=(0,$.jsxs)(`button`,{type:`button`,className:`flex w-56 flex-col gap-2 rounded-xl border border-border bg-background p-4 text-left shadow-sm transition-colors hover:bg-muted`,onClick:a,children:[p,m,h]}),t[14]=a,t[15]=g);let _,v,y;t[16]===Symbol.for(`react.memo_cache_sentinel`)?(_=(0,$.jsx)(Yt,{className:`h-5 w-5 text-muted-foreground`}),v=(0,$.jsx)(`span`,{className:`text-sm text-foreground leading-snug font-medium`,children:`New App`}),y=(0,$.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`Create a new project from template`}),t[16]=_,t[17]=v,t[18]=y):(_=t[16],v=t[17],y=t[18]);let b;t[19]===o?b=t[20]:(b=(0,$.jsxs)(`button`,{type:`button`,className:`flex w-56 flex-col gap-2 rounded-xl border border-border bg-background p-4 text-left shadow-sm transition-colors hover:bg-muted`,onClick:o,children:[_,v,y]}),t[19]=o,t[20]=b);let x,S,C;t[21]===Symbol.for(`react.memo_cache_sentinel`)?(x=(0,$.jsx)(xe,{className:`h-5 w-5 text-muted-foreground`}),S=(0,$.jsx)(`span`,{className:`text-sm text-foreground leading-snug font-medium`,children:`Open Folder`}),C=(0,$.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`Use an existing local folder`}),t[21]=x,t[22]=S,t[23]=C):(x=t[21],S=t[22],C=t[23]);let w;t[24]===s?w=t[25]:(w=(0,$.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:[x,S,C]}),t[24]=s,t[25]=w);let T;t[26]!==b||t[27]!==w||t[28]!==f||t[29]!==g?(T=(0,$.jsxs)(`div`,{className:`flex flex-wrap justify-center gap-3`,children:[f,g,b,w]}),t[26]=b,t[27]=w,t[28]=f,t[29]=g,t[30]=T):T=t[30];let E;return t[31]!==T||t[32]!==d?(E=(0,$.jsxs)(`div`,{className:`mx-auto flex max-w-3xl flex-1 flex-col items-center justify-center gap-8 px-4`,children:[d,T]}),t[31]=T,t[32]=d,t[33]=E):E=t[33],E}function mi(e){let t=(0,Z.c)(37),{messages:n,isStreaming:r,streamingSegments:i,streamingModel:a,isCreatingProject:o,isProcessingThread:s,selectedThreadId:c,projects:l,projectsLoading:u,onSelectThread:d,onCreateThread:f,onConnectRepo:p,onNewApp:m,onOpenFolder:h,error:g,onClearError:_}=e,v=(0,Q.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,Q.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=q(`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,$.jsx)(`div`,{className:`transition-opacity duration-500 ease-in-out ${u?`opacity-0`:`opacity-100`}`,children:(0,$.jsx)(pi,{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(hi),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,$.jsx)(fi,{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,$.jsxs)(`div`,{className:`mx-4 my-2 rounded-lg border border-destructive/30 bg-destructive/5 px-4 py-3`,children:[(0,$.jsx)(`p`,{className:`text-sm text-destructive`,children:g}),(0,$.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,$.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,$.jsx)(Jr,{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,$.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 hi(e){return(0,$.jsx)(li,{message:e},e.messageId)}var gi=()=>{if(typeof window>`u`)return null;let e=window.SpeechRecognition||window.webkitSpeechRecognition;return e?new e:null};function _i(){let e=(0,Z.c)(14),[t,n]=(0,Q.useState)(!1),[r,i]=(0,Q.useState)(``),[a,o]=(0,Q.useState)(null),[s,c]=(0,Q.useState)(!1),l=(0,Q.useRef)(null),u=(0,Q.useRef)(``),d,f;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(d=()=>{try{let e=gi();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,Q.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 vi({initialValue:e}={}){let{state:t,dispatch:n}=qn(),[r,i]=(0,Q.useState)(e??``),[a,o]=(0,Q.useState)(-1),[s,c]=(0,Q.useState)(``),[l,u]=(0,Q.useState)(0),[d,f]=(0,Q.useState)([]),[m,h]=(0,Q.useState)(()=>(t.selectedThreadId?t.projectModelSelections[t.selectedThreadId]:void 0)??null),g=(0,Q.useRef)(m?.id??``),[_,v]=(0,Q.useState)(!1),[y,b]=(0,Q.useState)(!1),[x,S]=(0,Q.useState)([]),[C,w]=(0,Q.useState)(!1),[T,E]=(0,Q.useState)([]),[D,O]=(0,Q.useState)(!1),[k,A]=(0,Q.useState)(``),[j,M]=(0,Q.useState)(0),[N,P]=(0,Q.useState)([]),[F,I]=(0,Q.useState)([]),[L,R]=(0,Q.useState)(!1),[z,B]=(0,Q.useState)(``),V=(0,Q.useRef)(null),H=(0,Q.useRef)(null),U=(0,Q.useRef)(null),ee=(0,Q.useRef)(null),te=(0,Q.useRef)(null),W=(0,Q.useRef)(null);(0,Q.useEffect)(()=>{g.current=m?.id??``},[m?.id]);let ne=(0,Q.useCallback)(e=>{h(e);let r=t.selectedThreadId;r&&(n({type:J.SetProjectModel,threadId:r,model:e}),bt(r,{model:e.id,modelProvider:e.provider}).catch(e=>console.error(`Failed to save model to thread:`,e)))},[t.selectedThreadId,n]);(0,Q.useEffect)(()=>{(async()=>{let e=t.selectedProjectId?t.projects.find(e=>e.projectId===t.selectedProjectId)?.threads.find(e=>e.threadId===t.selectedThreadId):void 0,n=t.selectedThreadId?t.projectModelSelections[t.selectedThreadId]:void 0,r=n?.id??e?.model??null,i=n?.provider??e?.modelProvider??null;try{let e=await Se(),t=Object.values(e).flat();if(t.length>0){f(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)}})()},[t.selectedThreadId,t.selectedProjectId,t.projects,t.projectModelSelections,ne]),(0,Q.useEffect)(()=>{t.configUpdatedAt!==0&&(async()=>{try{let e=await Se(),t=Object.values(e).flat();if(t.length>0){f(t);let e=g.current;t.some(t=>t.id===e)||ne(t[0])}}catch(e){console.error(`Failed to reload enabled models:`,e)}})()},[t.configUpdatedAt,t.selectedProjectId,ne]);let[re,ie]=(0,Q.useState)(t.selectedThreadId);return(0,Q.useEffect)(()=>{t.selectedThreadId!==re&&setTimeout(()=>{ie(t.selectedThreadId),E([]),O(!1),P([]),I([]),R(!1),w(!1)},0)},[t.selectedThreadId,re]),(0,Q.useEffect)(()=>{t.selectedThreadId&&rt(t.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))},[t.selectedThreadId]),(0,Q.useEffect)(()=>{t.focusChatInput&&t.selectedThreadId&&!t.isStreaming&&(H.current?.focus(),n({type:J.ClearFocusChatInput}))},[t.focusChatInput,t.selectedThreadId,t.isStreaming,n]),(0,Q.useEffect)(()=>{let e=e=>{U.current&&!U.current.contains(e.target)&&v(!1),ee.current&&!ee.current.contains(e.target)&&b(!1)};if(_||y)return document.addEventListener(`mousedown`,e),()=>{document.removeEventListener(`mousedown`,e)}},[_,y]),{message:r,setMessage:i,historyIndex:a,setHistoryIndex:o,draftMessage:s,setDraftMessage:c,cursorPosition:l,setCursorPosition:u,availableModels:d,setAvailableModels:f,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:ee,suggestionsRef:te,commandSuggestionsRef:W,handleNewChat:async()=>{if(t.selectedThreadId)try{let e=await p(t.selectedThreadId);n({type:J.ClearMessages}),console.log(`New conversation started:`,e);let r=await Ce(t.selectedThreadId);n({type:J.SetMessages,messages:r.messages})}catch(e){console.error(`Failed to start new chat:`,e)}},state:t,dispatch:n}}var yi=e=>{et(e)};function bi(e){let t=(0,Z.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:J.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),yi(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,te,W,ne,re;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){ne=e=>{if(D){if(e.key===`ArrowDown`){e.preventDefault(),E((T+1)%te.length);return}if(e.key===`ArrowUp`){e.preventDefault(),E((T-1+te.length)%te.length);return}if(e.key===`Enter`||e.key===`Tab`){e.preventDefault();let t=te[T];t&&(t.type===`command`?H(t.data):ee(t.data));return}if(e.key===`Escape`){O(!1);return}}if(y){let t=W.length>0;if(e.key===`ArrowDown`&&t){e.preventDefault(),E((T+1)%W.length);return}if(e.key===`ArrowUp`&&t){e.preventDefault(),E((T-1+W.length)%W.length);return}if(e.key===`Enter`||e.key===`Tab`){e.preventDefault(),W[T]&&B(W[T]);return}if(e.key===`Escape`){b(!1);return}}if(e.key===`Enter`&&!e.shiftKey){e.preventDefault(),R();return}let t=Wt();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&&nn(c).then(e=>{w(e)}).catch(Ci))}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],re=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(Si),...a.map(xi)],t[80]=k,t[81]=M,t[82]=j,t[83]=i}else i=t[83];te=i.slice(0,10),W=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]=te,t[66]=W,t[67]=ne,t[68]=re}else te=t[65],W=t[66],ne=t[67],re=t[68];let ie;return t[88]!==te||t[89]!==W||t[90]!==ne||t[91]!==R||t[92]!==re||t[93]!==H||t[94]!==B||t[95]!==ee?(ie={handleSend:R,handleKeyDown:ne,handleTextareaInput:re,insertFileReference:B,insertCommand:H,insertSkill:ee,allSuggestions:te,fileSuggestions:W},t[88]=te,t[89]=W,t[90]=ne,t[91]=R,t[92]=re,t[93]=H,t[94]=B,t[95]=ee,t[96]=ie):ie=t[96],ie}function xi(e){return{type:`skill`,data:e}}function Si(e){return{type:`command`,data:e}}function Ci(e){return console.error(`Failed to fetch files:`,e)}function wi(e){let t=(0,Z.c)(21),{visible:n,commands:r,skills:i,query:a,selectedIndex:o,onSelectCommand:s,onSelectSkill:c,onMouseEnterSuggestion:l,containerRef:u}=e;if(!n)return null;let d;if(t[0]!==r||t[1]!==a||t[2]!==i){let e;t[4]===a?e=t[5]:(e=e=>e.name.toLowerCase().includes(a.toLowerCase()),t[4]=a,t[5]=e);let n=r.filter(e),o;t[6]===a?o=t[7]:(o=e=>e.name.toLowerCase().includes(a.toLowerCase()),t[6]=a,t[7]=o);let s=i.filter(o);d=[...n.map(Ei),...s.map(Ti)].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,$.jsx)(Ve,{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,$.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,$.jsxs)(`button`,{type:`button`,className:q(`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,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(Ve,{className:`h-3 w-3 text-muted-foreground`}),(0,$.jsxs)(`span`,{className:`font-medium`,children:[`/`,r.name]}),r.metadata.argumentHint&&(0,$.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:r.metadata.argumentHint}),r.scope===`project`&&(0,$.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,$.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:r.metadata.description})]},`cmd-${r.name}`)}else{let r=e.data;return(0,$.jsxs)(`button`,{type:`button`,className:q(`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,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(Mt,{className:`h-3 w-3 text-amber-500`}),(0,$.jsxs)(`span`,{className:`font-medium`,children:[`/`,r.name]}),(0,$.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,$.jsx)(`span`,{className:`text-[10px] rounded-full bg-primary/10 px-1.5 py-0.5 text-primary`,children:`project`})]}),(0,$.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:r.description})]},`skill-${r.name}`)}}):(0,$.jsxs)(`div`,{className:`px-3 py-4 text-center text-xs text-muted-foreground`,children:[`No commands or skills found.`,(0,$.jsx)(`br`,{}),(0,$.jsxs)(`span`,{className:`text-[10px]`,children:[`Create commands in `,(0,$.jsx)(`code`,{className:`bg-muted px-1 rounded`,children:`~/.tarsk/commands/`}),` or skills in `,(0,$.jsx)(`code`,{className:`bg-muted px-1 rounded`,children:`~/.tarsk/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,$.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 Ti(e){return{type:`skill`,data:e}}function Ei(e){return{type:`command`,data:e}}function Di(e){return e.startsWith(`image/`)}function Oi(e){let t=(0,Z.c)(7),{attachments:n,onRemove:r}=e;if(n.length===0)return null;let i;if(t[0]!==n||t[1]!==r){let e;t[3]===r?e=t[4]:(e=(e,t)=>(0,$.jsx)(`div`,{className:`group relative flex items-center gap-1 rounded-md bg-muted text-xs text-muted-foreground`,children:Di(e.mimeType)?(0,$.jsxs)(`div`,{className:`relative`,children:[(0,$.jsx)(`img`,{src:`data:${e.mimeType};base64,${e.content}`,alt:e.fileName,className:`h-16 w-16 rounded-md object-cover`}),(0,$.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,$.jsx)(ot,{className:`h-2.5 w-2.5`}),(0,$.jsx)(`span`,{className:`sr-only`,children:`Remove attachment`})]})]}):(0,$.jsxs)(`span`,{className:`flex items-center gap-1 px-2 py-1`,children:[(0,$.jsx)(pe,{className:`h-3 w-3`}),e.fileName,(0,$.jsxs)(`button`,{type:`button`,onClick:()=>r(t),className:`ml-1 hover:text-foreground`,children:[(0,$.jsx)(ot,{className:`h-3 w-3`}),(0,$.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,$.jsx)(`div`,{className:`mb-2 flex flex-wrap gap-1.5`,children:i}),t[5]=i,t[6]=a),a}function ki(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 Ai(e){let t=(0,Z.c)(16),{showSuggestions:r,fileSuggestions:i,suggestionQuery:a,selectedIndex:o,onSelectFile:s,onMouseEnterSuggestion:c,containerRef:l}=e;if(!r||i.length===0)return null;let u;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(u=(0,$.jsx)($t,{className:`h-3 w-3`}),t[0]=u):u=t[0];let d;t[1]===a?d=t[2]:(d=(0,$.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:[u,`Files matching "`,a,`"`]}),t[1]=a,t[2]=d);let f;if(t[3]!==i||t[4]!==c||t[5]!==s||t[6]!==o){let e;t[8]!==c||t[9]!==s||t[10]!==o?(e=(e,t)=>{let r=e.split(`/`).pop()??e;return(0,$.jsxs)(`button`,{type:`button`,className:q(`flex w-full items-center gap-2 rounded-lg px-3 py-2 text-sm text-left transition-colors`,t===o?`bg-accent text-accent-foreground`:`text-popover-foreground hover:bg-accent/50`),onClick:()=>s(e),onMouseEnter:()=>c(t),children:[e.endsWith(`.ts`)||e.endsWith(`.tsx`)||e.endsWith(`.js`)||e.endsWith(`.jsx`)?(0,$.jsx)(Rt,{className:`h-4 w-4 text-blue-500`}):(0,$.jsx)(n,{className:`h-4 w-4 text-muted-foreground`}),(0,$.jsxs)(`div`,{className:`flex flex-col overflow-hidden`,children:[(0,$.jsx)(`span`,{className:`truncate font-medium`,children:r}),(0,$.jsx)(`span`,{className:`truncate text-[10px] text-muted-foreground opacity-70`,children:e})]})]},e)},t[8]=c,t[9]=s,t[10]=o,t[11]=e):e=t[11],f=i.map(e),t[3]=i,t[4]=c,t[5]=s,t[6]=o,t[7]=f}else f=t[7];let p;return t[12]!==l||t[13]!==d||t[14]!==f?(p=(0,$.jsxs)(`div`,{ref:l,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:[d,f]}),t[12]=l,t[13]=d,t[14]=f,t[15]=p):p=t[15],p}function ji(e){let t=(0,Z.c)(3),{provider:n}=e;if(!n)return null;let r=`https://models.tarsk.io/svg/${n}.svg`,i=`${n} logo`,a;return t[0]!==r||t[1]!==i?(a=(0,$.jsx)(`img`,{src:r,alt:i,className:`h-3.5 w-3.5 flex-shrink-0`,onError:Mi}),t[0]=r,t[1]=i,t[2]=a):a=t[2],a}function Mi(e){e.currentTarget.style.visibility=`hidden`}function Ni(e){let t=(0,Z.c)(24),{availableModels:n,selectedModel:r,onModelSelect:i}=e,[a,o]=Q.useState(!1),s=Q.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),Q.useEffect(c,l);let u;t[3]===i?u=t[4]:(u=e=>{i(e),o(!1)},t[3]=i,t[4]=u);let d=u,f;t[5]===a?f=t[6]:(f=()=>o(!a),t[5]=a,t[6]=f);let p=r?.provider,m;t[7]===p?m=t[8]:(m=(0,$.jsx)(ji,{provider:p}),t[7]=p,t[8]=m);let h;t[9]===r?h=t[10]:(h=r?dr(r.id):`No model`,t[9]=r,t[10]=h);let g;t[11]===Symbol.for(`react.memo_cache_sentinel`)?(g=(0,$.jsx)(Ne,{className:`h-3 w-3`}),t[11]=g):g=t[11];let _;t[12]!==f||t[13]!==m||t[14]!==h?(_=(0,$.jsxs)(`button`,{type:`button`,className:`flex items-center gap-1 rounded-md px-2 py-1 text-xs text-muted-foreground hover:bg-muted hover:text-foreground transition-colors`,onClick:f,children:[m,h,g]}),t[12]=f,t[13]=m,t[14]=h,t[15]=_):_=t[15];let v;t[16]!==n||t[17]!==d||t[18]!==r?.id||t[19]!==a?(v=a&&(0,$.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(Pi,{})).map(e=>{let[t,n]=e;return(0,$.jsxs)(`div`,{children:[(0,$.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,$.jsx)(ji,{provider:t}),t]}),n.map(e=>(0,$.jsx)(`button`,{type:`button`,className:`flex w-full items-center whitespace-nowrap rounded-md px-3 py-1.5 pl-8 text-sm text-popover-foreground hover:bg-accent ${e.id===r?.id?`bg-accent font-medium`:``}`,onClick:()=>d(e),children:dr(e.id)},e.id))]},t)})}),t[16]=n,t[17]=d,t[18]=r?.id,t[19]=a,t[20]=v):v=t[20];let y;return t[21]!==v||t[22]!==_?(y=(0,$.jsxs)(`div`,{className:`relative`,ref:s,children:[_,v]}),t[21]=v,t[22]=_,t[23]=y):y=t[23],y}function Pi(e,t){let n=t.provider??`Other`;return e[n]||(e[n]=[]),e[n].push(t),e}function Fi(e){let t=(0,Z.c)(23),{onFileAttach:n,onPlanModeToggle:r,onNewChat:i}=e,[a,o]=Q.useState(!1),s=Q.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),Q.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,g;t[9]===a?g=t[10]:(g=()=>o(!a),t[9]=a,t[10]=g);let _,v;t[11]===Symbol.for(`react.memo_cache_sentinel`)?(_=(0,$.jsx)(G,{}),v=(0,$.jsx)(`span`,{className:`sr-only`,children:`More options`}),t[11]=_,t[12]=v):(_=t[11],v=t[12]);let y;t[13]===g?y=t[14]:(y=(0,$.jsxs)(K,{variant:`action`,size:`icon-sm`,onClick:g,children:[_,v]}),t[13]=g,t[14]=y);let b;t[15]!==d||t[16]!==h||t[17]!==p||t[18]!==a?(b=a&&(0,$.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,$.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,$.jsx)(pe,{className:`h-3.5 w-3.5`}),`Attach File`]}),(0,$.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,$.jsx)(an,{className:`h-3.5 w-3.5`}),`Plan Mode`]}),(0,$.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,$.jsx)(Ue,{className:`h-3.5 w-3.5`}),`New Chat`]})]}),t[15]=d,t[16]=h,t[17]=p,t[18]=a,t[19]=b):b=t[19];let x;return t[20]!==b||t[21]!==y?(x=(0,$.jsxs)(`div`,{className:`relative`,ref:s,children:[y,b]}),t[20]=b,t[21]=y,t[22]=x):x=t[22],x}function Ii(e){let t=(0,Z.c)(14),{onToggleSpeech:n}=e,{isListening:r,isSupported:i}=_i();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,$.jsx)(V,{}):(0,$.jsx)(z,{}),t[0]=r,t[1]=o);let s=r?`Stop listening`:`Start listening`,c;t[2]===s?c=t[3]:(c=(0,$.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,$.jsx)(sr,{asChild:!0,children:(0,$.jsxs)(K,{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,$.jsx)(Y,{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,$.jsxs)(or,{children:[l,d]}),t[11]=l,t[12]=d,t[13]=f):f=t[13],f}function Li({threadId:e,currentConversationId:t,children:n}){let[r,i]=(0,Q.useState)(null),[a,o]=(0,Q.useState)(null),[s,c]=(0,Q.useState)(null),[l,u]=(0,Q.useState)(!1),[d,f]=(0,Q.useState)(null),[p,m]=(0,Q.useState)(!1),[h,g]=(0,Q.useState)(!1);if((0,Q.useEffect)(()=>{if(!p||h||!e)return;async function n(){u(!0),f(null);try{let n=(await $e(e)).currentConversationId??t,[r,a]=await Promise.allSettled([Fe(e).catch(e=>{throw console.error(`Thread usage summary failed:`,e),e}),n?Ke(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+`)`),je(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,$.jsx)($.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,$.jsxs)(or,{open:p,onOpenChange:e=>{m(e),!e&&h&&g(!1)},children:[(0,$.jsx)(sr,{asChild:!0,children:n}),(0,$.jsx)(Y,{side:`top`,align:`center`,className:`max-w-xs`,children:(0,$.jsxs)(`div`,{className:`text-xs text-muted-foreground space-y-2`,children:[l&&(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(le,{className:`h-3 w-3 animate-pulse`}),(0,$.jsx)(`span`,{children:`Loading usage...`})]}),d&&(0,$.jsxs)(`div`,{className:`flex items-center gap-2 text-red-500`,children:[(0,$.jsx)(le,{className:`h-3 w-3`}),(0,$.jsx)(`span`,{children:`Failed to load usage`})]}),!l&&!d&&r&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`space-y-1`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(le,{className:`h-3 w-3`}),(0,$.jsxs)(`span`,{className:`font-medium`,children:[_(r.totalTokens),` tokens`]})]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(ht,{className:`h-3 w-3`}),(0,$.jsxs)(`span`,{children:[r.conversationCount,` chats`]})]})]}),a&&(0,$.jsxs)(`div`,{className:`border-t border-border pt-2 space-y-1`,children:[(0,$.jsx)(`div`,{className:`text-xs font-semibold text-foreground`,children:`Current Chat:`}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(Mt,{className:`h-3 w-3`}),(0,$.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,$.jsxs)(`div`,{className:`text-muted-foreground`,children:[a.model.model,s?.context_length&&(0,$.jsxs)(`span`,{className:`ml-1`,children:[_(typeof s.context_length==`number`?s.context_length:0),` `,`context)`]})]})]}),(0,$.jsxs)(`div`,{className:`border-t border-border pt-2 flex items-center gap-3 text-[10px] text-muted-foreground`,children:[(0,$.jsxs)(`span`,{children:[`In: `,_(r.totalInputTokens)]}),(0,$.jsxs)(`span`,{children:[`Out: `,_(r.totalOutputTokens)]}),(0,$.jsxs)(`span`,{children:[`Avg: `,_(r.averageTokensPerConversation),`/chat`]})]})]})]})})]}):(0,$.jsx)($.Fragment,{children:n})}function Ri(e){let t=(0,Z.c)(7),{threadId:n}=e,[r,i]=(0,Q.useState)(),a,o;if(t[0]===n?(a=t[1],o=t[2]):(a=()=>{(async function(){if(n)try{i((await $e(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,Q.useEffect)(a,o),!n||n===``)return null;let s;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(s=(0,$.jsxs)(K,{variant:`ghost`,size:`icon-sm`,className:`text-muted-foreground hover:text-background`,children:[(0,$.jsx)(ht,{className:`h-4 w-4`}),(0,$.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,$.jsx)(Li,{threadId:n,currentConversationId:r,children:s}),t[4]=r,t[5]=n,t[6]=c):c=t[6],c}function zi(e){let t=(0,Z.c)(8),{queuedMessages:n,onRemoveQueuedMessage:r}=e;if(n.length===0)return null;let i;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(i=(0,$.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,$.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,$.jsx)(`p`,{className:`flex-1 whitespace-pre-wrap text-foreground`,children:e.message}),(0,$.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,$.jsx)(ot,{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,$.jsxs)(`div`,{className:`mb-3 rounded-lg border border-border/60 bg-muted/30 px-4 py-3`,children:[i,(0,$.jsx)(`div`,{className:`mt-2 flex flex-col gap-2`,children:a})]}),t[6]=a,t[7]=o),o}function Bi(e){let t=(0,Z.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}=_i(),_;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:te,setCommandQuery:W,fileInputRef:ne,textareaRef:re,suggestionsRef:ie,commandSuggestionsRef:ae,handleNewChat:oe,state:se,dispatch:ce}=vi(_),le=se.selectedThreadId??void 0,G;t[2]!==N||t[3]!==k||t[4]!==te||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]!==W||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?(G={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:te,setCommandQuery:W,slashCommands:V,skills:H,textareaRef:re,setAttachments:A,planMode:j,setPlanMode:M},t[2]=N,t[3]=k,t[4]=te,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]=W,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]=G):G=t[37];let{handleSend:ue,handleKeyDown:de,handleTextareaInput:pe,insertFileReference:me,insertCommand:he,insertSkill:ge,fileSuggestions:_e}=bi(G),ve=Q.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]),Q.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(Hi);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 q=Ce,we=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`,Te;t[49]!==j||t[50]!==M?(Te=j&&(0,$.jsxs)(`div`,{className:`mb-2 flex items-center gap-2 rounded-md bg-accent px-3 py-1.5`,children:[(0,$.jsx)(an,{className:`h-3.5 w-3.5 text-accent-foreground`}),(0,$.jsx)(`span`,{className:`text-xs text-accent-foreground font-medium`,children:`Plan Mode`}),(0,$.jsxs)(`button`,{type:`button`,onClick:()=>M(!1),className:`ml-auto`,children:[(0,$.jsx)(ot,{className:`h-3 w-3 text-accent-foreground`}),(0,$.jsx)(`span`,{className:`sr-only`,children:`Exit plan mode`})]})]}),t[49]=j,t[50]=M,t[51]=Te):Te=t[51];let Ee=`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`}`,De;t[52]!==c||t[53]!==s?(De=(0,$.jsx)(zi,{queuedMessages:s,onRemoveQueuedMessage:c}),t[52]=c,t[53]=s,t[54]=De):De=t[54];let Oe;t[55]!==a||t[56]!==de||t[57]!==Se||t[58]!==pe||t[59]!==v||t[60]!==re?(Oe=(0,$.jsx)(`textarea`,{ref:re,value:v,onChange:pe,onKeyDown:de,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]=de,t[57]=Se,t[58]=pe,t[59]=v,t[60]=re,t[61]=Oe):Oe=t[61];let ke;t[62]!==te||t[63]!==ae||t[64]!==he||t[65]!==ge||t[66]!==z||t[67]!==B||t[68]!==U||t[69]!==H||t[70]!==V?(ke=(0,$.jsx)(wi,{visible:U,commands:V,skills:H,query:te,selectedIndex:z,onSelectCommand:he,onSelectSkill:ge,onMouseEnterSuggestion:B,containerRef:ae}),t[62]=te,t[63]=ae,t[64]=he,t[65]=ge,t[66]=z,t[67]=B,t[68]=U,t[69]=H,t[70]=V,t[71]=ke):ke=t[71];let Ae;t[72]!==_e||t[73]!==me||t[74]!==z||t[75]!==B||t[76]!==F||t[77]!==L||t[78]!==ie?(Ae=(0,$.jsx)(Ai,{showSuggestions:F,fileSuggestions:_e,suggestionQuery:L,selectedIndex:z,onSelectFile:me,onMouseEnterSuggestion:B,containerRef:ie}),t[72]=_e,t[73]=me,t[74]=z,t[75]=B,t[76]=F,t[77]=L,t[78]=ie,t[79]=Ae):Ae=t[79];let je;t[80]!==k||t[81]!==D?.id||t[82]!==D?.name||t[83]!==D?.supportsImages||t[84]!==A?(je=k.length>0&&(0,$.jsxs)(`div`,{className:`px-4`,children:[(0,$.jsx)(Oi,{attachments:k,onRemove:e=>A(t=>t.filter((t,n)=>n!==e))}),k.some(Vi)&&D?.supportsImages===!1&&(0,$.jsxs)(`div`,{className:`mb-2 flex items-center gap-1.5 text-xs text-amber-500`,children:[(0,$.jsx)(ze,{className:`h-3 w-3 shrink-0`}),(0,$.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]=je):je=t[85];let Me;t[86]===ne?Me=t[87]:(Me=()=>ne.current?.click(),t[86]=ne,t[87]=Me);let Ne;t[88]===M?Ne=t[89]:(Ne=()=>M(!0),t[88]=M,t[89]=Ne);let Pe;t[90]!==oe||t[91]!==Me||t[92]!==Ne?(Pe=(0,$.jsx)(Fi,{onFileAttach:Me,onPlanModeToggle:Ne,onNewChat:oe}),t[90]=oe,t[91]=Me,t[92]=Ne,t[93]=Pe):Pe=t[93];let Fe;t[94]===q?Fe=t[95]:(Fe=(0,$.jsx)(Ii,{onToggleSpeech:q}),t[94]=q,t[95]=Fe);let Ie=se.selectedThreadId??void 0,Le;t[96]===Ie?Le=t[97]:(Le=(0,$.jsx)(Ri,{threadId:Ie}),t[96]=Ie,t[97]=Le);let Re;t[98]!==E||t[99]!==D||t[100]!==O?(Re=(0,$.jsx)(Ni,{availableModels:E,selectedModel:D,onModelSelect:O}),t[98]=E,t[99]=D,t[100]=O,t[101]=Re):Re=t[101];let Be;t[102]!==Pe||t[103]!==Fe||t[104]!==Le||t[105]!==Re?(Be=(0,$.jsxs)(`div`,{className:`flex items-center gap-1`,children:[Pe,Fe,Le,Re]}),t[102]=Pe,t[103]=Fe,t[104]=Le,t[105]=Re,t[106]=Be):Be=t[106];let Ve=u?r:ue,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,$.jsx)(vt,{className:`h-3 w-3 fill-current`}):(0,$.jsx)(fe,{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,$.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,$.jsxs)(K,{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,$.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]!==Ee||t[126]!==De||t[127]!==Oe||t[128]!==ke||t[129]!==Ae||t[130]!==je||t[131]!==qe?(Je=(0,$.jsxs)(`div`,{className:Ee,children:[De,Oe,ke,Ae,je,qe]}),t[125]=Ee,t[126]=De,t[127]=Oe,t[128]=ke,t[129]=Ae,t[130]=je,t[131]=qe,t[132]=Je):Je=t[132];let Ye;t[133]===A?Ye=t[134]:(Ye=e=>ki(e,e=>A(t=>[...t,...e])),t[133]=A,t[134]=Ye);let Xe;t[135]!==ne||t[136]!==Ye?(Xe=(0,$.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]!==we||t[139]!==Te||t[140]!==Je||t[141]!==Xe?(Ze=(0,$.jsxs)(`div`,{className:we,children:[Te,Je,Xe]}),t[138]=we,t[139]=Te,t[140]=Je,t[141]=Xe,t[142]=Ze):Ze=t[142],Ze}function Vi(e){return e.mimeType.startsWith(`image/`)}function Hi(e){return e.type.startsWith(`image/`)}function Ui({threadId:e}){let[t,n]=(0,Q.useState)(!1);return(0,$.jsx)(`div`,{className:`flex items-center justify-end gap-2 px-8 py-2 mt-[-1rem] min-h-[2.25rem]`,children:e&&(0,$.jsxs)(or,{children:[(0,$.jsx)(sr,{asChild:!0,children:(0,$.jsx)(K,{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 ie(e);await navigator.clipboard.writeText(t)}finally{n(!1)}}},disabled:t,"aria-label":`Copy repository folder path`,children:(0,$.jsx)(xe,{className:`h-3 w-3`})})}),(0,$.jsx)(Y,{side:`top`,className:`bg-slate-900 text-white`,children:`Copy repository folder path`})]})})}function Wi(){let{state:e,dispatch:t}=qn(),[n,r]=(0,Q.useState)(null),i=(0,Q.useRef)(``),a=(0,Q.useRef)(``),o=(0,Q.useRef)([]),s=(0,Q.useRef)(!1),c=(0,Q.useRef)(null),l=(0,Q.useRef)(null),u=(0,Q.useRef)(()=>{}),[d,f]=(0,Q.useState)(null),p=(0,Q.useRef)(!1),m=(0,Q.useRef)(!1),h=(0,Q.useRef)(null),g=(0,Q.useRef)(null),_=(0,Q.useRef)(null),{selectedThreadId:v,selectedProjectId:b,messages:x,queuedChatMessages:C,isStreaming:w,streamingModel:T,processingThreadIds:E}=e,D=!!(v&&E.includes(v)),O=(0,Q.useCallback)(n=>{if(c.current=null,l.current=null,p.current){p.current=!1;return}let r=o.current,s=rr(r)||`...`;if(h.current&&(r.length===0||s===`...`)){let r={messageId:`msg-${Date.now()}-error`,sender:`agent`,content:`Error: ${h.current}`,contentType:`text`,timestamp:new Date().toISOString(),model:e.streamingModel||n,isThinking:!1};t({type:J.AddMessage,message:r}),t({type:J.ResetStream}),v&&t({type:J.RemoveProcessingThread,threadId:v}),h.current=null;return}let u={messageId:`msg-${Date.now()}-agent`,sender:`agent`,content:s,contentType:`markdown`,timestamp:new Date().toISOString(),model:e.streamingModel||n,isThinking:!1};i.current=``,a.current=``,o.current=[],h.current=null,t({type:J.AddMessage,message:u}),t({type:J.ResetStream}),v&&(t({type:J.MarkThreadCompleted,threadId:v}),t({type:J.RemoveProcessingThread,threadId:v}))},[e.streamingModel,t,v]);(0,Q.useEffect)(()=>{u.current=O},[O]);let A=(0,Q.useCallback)(()=>{v&&f(v),p.current=!0,v&&S(v),c.current&&=(c.current.abort(),null),l.current&&=(l.current(),null),i.current=``,a.current=``,o.current=[],h.current=null;let n={messageId:`msg-${Date.now()}-stopped`,sender:`agent`,content:`I've stopped working on your request.`,contentType:`text`,timestamp:new Date().toISOString(),model:e.streamingModel||`default`,isThinking:!1};t({type:J.AddMessage,message:n}),t({type:J.ResetStream}),v&&(t({type:J.MarkThreadCompleted,threadId:v}),t({type:J.RemoveProcessingThread,threadId:v}))},[v,t,e.streamingModel]);(0,Q.useEffect)(()=>{m.current&&!w&&c.current&&(c.current.abort(),c.current=null,l.current&&=(l.current(),null),u.current(T||`default`)),m.current=w},[w,T]),(0,Q.useEffect)(()=>{if(g.current&&=(clearTimeout(g.current),null),w){let e=12e4,t=n=>{g.current&&=(clearTimeout(g.current),null),g.current=setTimeout(()=>{let n=Date.now(),r=_?.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`),c.current&&=(c.current.abort(),null),l.current&&=(l.current(),null),u.current(T||`default`)},n)},n=e;if(_?.current!=null){let t=Date.now()-_.current;n=t>=e?0:e-t}t(n)}return()=>{g.current&&=(clearTimeout(g.current),null)}},[w,T]),(0,Q.useEffect)(()=>()=>{c.current&&=(c.current.abort(),null),l.current&&=(l.current(),null),t({type:J.ResetStream})},[v,t]),(0,Q.useEffect)(()=>{if(!v)return;let e=!1;async function n(){try{let n=await Ce(v);e||t({type:J.SetMessages,messages:n.messages})}catch(n){console.error(`Failed to load chat history:`,n),e||t({type:J.SetMessages,messages:[]})}}return n(),()=>{e=!0}},[v,b,t]),(0,Q.useEffect)(()=>{if(!v||!D||w)return;let e=new AbortController;return c.current=e,t({type:J.ResetStream}),t({type:J.SetStreaming,isStreaming:!0}),i.current=``,a.current=``,o.current=[],s.current=!1,h.current=null,k(v,e.signal).then(n=>{if(!n||e.signal.aborted){u.current(`default`);return}l.current=y(n,e=>{if(e.type===`error`){let t=e.content||`Unknown error occurred`;h.current=t,r(t);return}if(e.type!==`message`){if(e.type===`toolcall_delta`){e.partial?.content?.[0]?.id&&e.delta&&t({type:J.UpdateToolCallProgress,toolCallId:e.partial.content[0].id,progress:{toolCallId:e.partial.content[0].id,toolName:e.partial.content[0].name,delta:e.delta,partial:e.partial}});return}if(e.model&&t({type:J.SetStreamModel,model:e.model}),e.type===`thinking`||e.isThinking){a.current+=e.content??``;let n=Qn(o.current,`thinking`,e.content??``);o.current=n,t({type:J.AppendStreamChunk,chunkType:`thinking`,content:e.content??``,segments:n})}else if(e.type===`result`)s.current=!0,i.current=e.content??``,o.current=ir(o.current,e.content??``),t({type:J.SetStreamContent,content:e.content??``});else{if(s.current)return;i.current+=e.content??``;let n=Qn(o.current,`content`,e.content??``);o.current=n,t({type:J.AppendStreamChunk,chunkType:`content`,content:e.content??``,segments:n})}}},()=>{u.current(`default`)},e=>{if(e.includes(`AbortError`)||e.includes(`canceled`)||e.includes(`BodyStreamBuffer was aborted`)){u.current(`default`);return}h.current=e,r(e)},e=>{if(e.role===`assistant`){let n=e.content??``,r=typeof n==`string`?n:JSON.stringify(n);if(e.isThinking??!1){a.current+=r;let e=Qn(o.current,`thinking`,r);o.current=e,t({type:J.AppendStreamChunk,chunkType:`thinking`,content:r,segments:e});return}let c=!1;if(typeof n==`object`&&Array.isArray(n)&&n.length>0)c=!0;else if(typeof r==`string`&&r.trim().startsWith(`[`))try{let e=JSON.parse(r);c=Array.isArray(e)&&e.length>0}catch{}if(c)s.current=!0,i.current=r,o.current=ir(o.current,r),t({type:J.SetStreamContent,content:r});else{i.current+=r;let e=Qn(o.current,`content`,r);o.current=e,t({type:J.AppendStreamChunk,chunkType:`content`,content:r,segments:e})}}else if(e.role===`tool`){let n=e.content??``,r=typeof n==`string`?n:JSON.stringify(n);if(r){i.current+=r;let e=Qn(o.current,`content`,r);o.current=e,t({type:J.AppendStreamChunk,chunkType:`content`,content:r,segments:e})}}})}).catch(e=>{if(e instanceof Error&&e.name===`AbortError`){t({type:J.ResetStream});return}if(e instanceof Error&&e.message.includes(`not currently processing`)){t({type:J.ResetStream});return}console.error(`Failed to subscribe to chat stream:`,e),t({type:J.ResetStream})}),()=>{e.abort(),l.current&&=(l.current(),null)}},[v,D]);let j=(0,Q.useCallback)(async(e,n,d,p,m)=>{if(!v)return;r(null),f(null),c.current&&c.current.abort(),l.current&&l.current();let g={messageId:`msg-${Date.now()}`,sender:`user`,content:e,contentType:`text`,timestamp:new Date().toISOString(),model:n,attachments:d.map(e=>({fileName:e.fileName,content:e.content,mimeType:e.mimeType}))};t({type:J.AddMessage,message:g});let _=e.trim().replace(/\n/g,` `).slice(0,100);b&&v&&(bt(v,{title:_}).catch(e=>{console.error(`Failed to update thread title:`,e)}),t({type:J.UpdateThreadTitle,projectId:b,threadId:v,title:_})),t({type:J.ResetStream}),t({type:J.SetStreaming,isStreaming:!0}),i.current=``,s.current=!1;let x=new AbortController;c.current=x;try{let c=await ge(v,e,n,d,x.signal,p,m);if(!c){u.current(n);return}l.current=y(c,e=>{if(e.type===`error`){let t=e.content||`Unknown error occurred`;h.current=t,r(t);return}if(e.type!==`message`){if(e.type===`toolcall_delta`){if(e.partial?.content?.[0]?.id&&e.delta){let n=e.partial.content[0].id,r=e.partial.content[0].name;t({type:J.UpdateToolCallProgress,toolCallId:n,progress:{toolCallId:n,toolName:r,delta:e.delta,partial:e.partial}})}return}if(e.model&&t({type:J.SetStreamModel,model:e.model}),e.type===`thinking`||e.isThinking){a.current+=e.content??``;let n=Qn(o.current,`thinking`,e.content??``);o.current=n,t({type:J.AppendStreamChunk,chunkType:`thinking`,content:e.content??``,segments:n})}else if(e.type===`result`)s.current=!0,i.current=e.content??``,o.current=ir(o.current,e.content??``),t({type:J.SetStreamContent,content:e.content??``});else{if(s.current)return;i.current+=e.content??``;let n=Qn(o.current,`content`,e.content??``);o.current=n,t({type:J.AppendStreamChunk,chunkType:`content`,content:e.content??``,segments:n})}}},()=>{u.current(n)},e=>{if(e.includes(`AbortError`)||e.includes(`canceled`)||e.includes(`BodyStreamBuffer was aborted`)){u.current(n);return}h.current=e,r(e)},e=>{if(e.role===`assistant`){let n=e.content??``,r=typeof n==`string`?n:JSON.stringify(n);if(e.isThinking??!1){a.current+=r;let e=Qn(o.current,`thinking`,r);o.current=e,t({type:J.AppendStreamChunk,chunkType:`thinking`,content:r,segments:e});return}let c=!1;if(typeof n==`object`&&Array.isArray(n)&&n.length>0)c=!0;else if(typeof r==`string`&&r.trim().startsWith(`[`))try{let e=JSON.parse(r);c=Array.isArray(e)&&e.length>0}catch{}if(c)s.current=!0,i.current=r,o.current=ir(o.current,r),t({type:J.SetStreamContent,content:r});else{i.current+=r;let e=Qn(o.current,`content`,r);o.current=e,t({type:J.AppendStreamChunk,chunkType:`content`,content:r,segments:e})}}else if(e.role===`tool`){let n=e.content??``,r=typeof n==`string`?n:JSON.stringify(n);if(r){i.current+=r;let e=Qn(o.current,`content`,r);o.current=e,t({type:J.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;r(e instanceof Error?e.message:`Failed to send message. Please ensure the CLI server is running on localhost:641`),h.current=e instanceof Error?e.message:`Failed to send message. Please ensure the CLI server is running on localhost:641`,t({type:J.ResetStream})}},[v,b,t]);(0,Q.useEffect)(()=>{let n=e.pendingChatMessage;if(!n||w||n.threadId!==v)return;let r=setTimeout(()=>{t({type:J.ClearPendingChatMessage}),j(n.message,n.model,[],n.provider)},100);return()=>clearTimeout(r)},[e.pendingChatMessage,w,v,t,j]);let M=(0,Q.useMemo)(()=>v?C.filter(e=>e.threadId===v):[],[v,C]),N=(0,Q.useRef)(!1);return(0,Q.useEffect)(()=>{if(w||!v||M.length===0||N.current)return;let[e]=M;N.current=!0,t({type:J.RemoveQueuedChatMessage,queuedMessageId:e.id});let n=setTimeout(()=>{j(e.message,e.model,e.attachments,e.provider,e.planMode),N.current=!1},0);return()=>{clearTimeout(n),N.current=!1}},[t,j,w,M,v]),{error:n,setError:r,handleSend:j,handleStop:A,isStreaming:w,selectedThreadId:v,queuedMessagesForThread:M,handleRemoveQueuedMessage:(0,Q.useCallback)(e=>{let n=M.find(t=>t.id===e);t({type:J.RemoveQueuedChatMessage,queuedMessageId:e}),!(!n||w||x.length>0||!v)&&j(n.message,n.model,n.attachments,n.provider,n.planMode)},[t,j,w,x.length,M,v])}}function Gi(){let e=(0,Z.c)(12),{state:t}=qn(),{isCreatingProject:n}=t,{handleSend:r,handleStop:i,isStreaming:a,selectedThreadId:o,queuedMessagesForThread:s,handleRemoveQueuedMessage:c}=Wi(),l=t.pendingChatMessage?.threadId===o,u=a||l,d=!o&&!n,f;e[0]!==u||e[1]!==c||e[2]!==r||e[3]!==i||e[4]!==s||e[5]!==d?(f=(0,$.jsx)(Bi,{onSend:r,onStop:i,isStreaming:u,disabled:d,initialValue:``,queuedMessages:s,onRemoveQueuedMessage:c,isOverlay:!1}),e[0]=u,e[1]=c,e[2]=r,e[3]=i,e[4]=s,e[5]=d,e[6]=f):f=e[6];let p=o??void 0,m;e[7]===p?m=e[8]:(m=(0,$.jsx)(Ui,{threadId:p}),e[7]=p,e[8]=m);let h;return e[9]!==f||e[10]!==m?(h=(0,$.jsx)($.Fragment,{children:(0,$.jsxs)(`div`,{className:`relative mx-auto min-w-[400px] w-[90vw] max-w-3xl`,children:[f,m]})}),e[9]=f,e[10]=m,e[11]=h):h=e[11],h}function Ki(){let e=qn().state,{selectedProjectId:t,selectedThreadId:n}=e,{terminalState:r,dispatch:i}=er(n),{open:a,queuedCommand:o,queuedRelativeFolder:s,outputLines:c,height:l,history:u,historyIndex:d,cwd:f,isRunning:p}=r,[m,h]=(0,Q.useState)(``),[g,_]=(0,Q.useState)([]),[v,y]=(0,Q.useState)(!1),[b,x]=(0,Q.useState)(!1),S=e.projects.flatMap(e=>e.threads).find(e=>e.threadId===n)?.path??null,C=!f||f===`.`||f===`./`?S:f,w=(0,Q.useCallback)(()=>{navigator.clipboard.writeText(`terminal`).then(()=>{x(!0),setTimeout(()=>x(!1),1500)})},[]),T=!C||C===S,E=(0,Q.useRef)(null),D=(0,Q.useRef)(null),O=(0,Q.useRef)(null),k=(0,Q.useRef)(0),A=(0,Q.useCallback)(e=>{e.preventDefault(),y(!0)},[]),j=(0,Q.useCallback)(()=>{y(!1)},[]),M=(0,Q.useCallback)(e=>{if(v&&O.current){let t=O.current.getBoundingClientRect().bottom-e.clientY;t>=150&&t<=window.innerHeight*.8&&i({type:J.SetTerminalHeight,height:t})}},[v,i]);(0,Q.useEffect)(()=>(v?(window.addEventListener(`mousemove`,M),window.addEventListener(`mouseup`,j),document.body.style.cursor=`ns-resize`,document.body.style.userSelect=`none`):(window.removeEventListener(`mousemove`,M),window.removeEventListener(`mouseup`,j),document.body.style.cursor=``,document.body.style.userSelect=``),()=>{window.removeEventListener(`mousemove`,M),window.removeEventListener(`mouseup`,j)}),[v,M,j]),(0,Q.useEffect)(()=>{E.current&&(E.current.scrollTop=E.current.scrollHeight)},[g]),(0,Q.useEffect)(()=>{_(c),k.current=c.length},[n,c]),(0,Q.useEffect)(()=>{if(c.length===0)_([]),k.current=0;else if(c.length>k.current){let e=c.slice(k.current);_(t=>[...t,...e]),k.current=c.length}},[c]),(0,Q.useEffect)(()=>{a&&!p&&D.current?.focus()},[a,p]);let N=(0,Q.useCallback)(async(e,r)=>{if(!(!t||!n||!e.trim())){i({type:J.AppendTerminalLine,line:{type:`input`,content:e}}),i({type:J.SetTerminalHistory,history:[e,...u.filter(t=>t!==e)].slice(0,50)}),i({type:J.SetTerminalHistoryIndex,index:-1}),h(``),i({type:J.SetTerminalRunning,isRunning:!0});try{let a=await F(t,n,e,r??void 0);if(!a){i({type:J.AppendTerminalLine,line:{type:`system`,content:`Command started but no output stream received.`}}),i({type:J.SetTerminalRunning,isRunning:!1});return}let o=a.getReader(),s=new TextDecoder,c=``;for(;;){let{done:e,value:t}=await o.read();if(e)break;c+=s.decode(t,{stream:!0});let n=c.split(`
|
|
12
|
-
`);c=n.pop()??``;for(let e of n)if(e.trim())try{let t=JSON.parse(e);typeof t==`string`?i({type:J.AppendTerminalLine,line:{type:`output`,content:t}}):t.type===`error`?i({type:J.AppendTerminalLine,line:{type:`error`,content:t.message}}):t.type===`cwd`&&i({type:J.SetTerminalCwd,cwd:t.path})}catch{i({type:J.AppendTerminalLine,line:{type:`output`,content:e}})}}if(c.trim())try{let e=JSON.parse(c);typeof e==`string`?i({type:J.AppendTerminalLine,line:{type:`output`,content:e}}):e.type===`error`?i({type:J.AppendTerminalLine,line:{type:`error`,content:e.message}}):e.type===`cwd`&&i({type:J.SetTerminalCwd,cwd:e.path})}catch{i({type:J.AppendTerminalLine,line:{type:`output`,content:c}})}}catch(e){i({type:J.AppendTerminalLine,line:{type:`error`,content:e instanceof Error?e.message:`Failed to run command`}})}finally{i({type:J.SetTerminalRunning,isRunning:!1})}}},[t,n,i,u]);return(0,Q.useEffect)(()=>{o&&!p&&(N(o,s??void 0),i({type:J.ClearQueuedTerminalCommand}))},[o,s,p,i,N]),a?(0,$.jsxs)(`div`,{ref:O,className:`flex flex-col border-t border-border bg-neutral-950 text-neutral-200 font-mono text-sm overflow-hidden animate-in slide-in-from-bottom-2 relative`,style:{height:`${l}px`},children:[(0,$.jsx)(`div`,{className:`absolute top-0 left-0 right-0 h-1 cursor-ns-resize hover:bg-primary/50 transition-colors z-50`,onMouseDown:A}),(0,$.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-1.5 border-b border-white/10 bg-white/5`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(Ve,{className:`h-3.5 w-3.5 text-neutral-400`}),(0,$.jsx)(ar,{children:(0,$.jsxs)(or,{children:[(0,$.jsx)(sr,{asChild:!0,children:(0,$.jsx)(`span`,{className:`text-xs font-medium text-neutral-400 cursor-pointer hover:text-neutral-200 transition-colors select-none`,onClick:w,children:b?`Copied!`:`Terminal`})}),(0,$.jsx)(Y,{side:`bottom`,children:(0,$.jsx)(`span`,{className:`font-mono text-xs`,children:C??`/`})})]})}),!T&&(0,$.jsx)(`span`,{className:`text-[10px] text-neutral-500 font-mono bg-white/5 px-1.5 py-0.5 rounded border border-white/5`,children:C}),p&&(0,$.jsxs)(`div`,{className:`flex gap-1 items-center ml-2`,children:[(0,$.jsx)(`div`,{className:`h-1 w-1 rounded-full bg-primary animate-pulse`}),(0,$.jsx)(`span`,{className:`text-[10px] text-neutral-500 italic`,children:`processing...`})]})]}),(0,$.jsx)(`div`,{className:`flex items-center gap-1`,children:(0,$.jsx)(K,{variant:`ghost`,size:`icon`,className:`h-6 w-6 text-neutral-500 hover:text-neutral-200 hover:bg-white/10`,onClick:()=>i({type:J.ToggleTerminal}),children:(0,$.jsx)(ot,{className:`h-3.5 w-3.5`})})})]}),(0,$.jsxs)(`div`,{ref:E,className:`flex-1 overflow-y-auto p-4 space-y-0.5 terminal-scrollbar`,onClick:e=>{e.target===e.currentTarget&&D.current?.focus()},children:[g.length===0&&!p&&(0,$.jsx)(`div`,{className:`text-neutral-600 italic text-xs`,children:`Enter your commands below...`}),g.map((e,t)=>(0,$.jsxs)(`div`,{className:`whitespace-pre-wrap break-all leading-6 ${e.type===`input`?`flex items-start gap-2 text-neutral-200`:e.type===`error`?`text-red-400`:e.type===`system`?`text-blue-400`:``}`,children:[e.type===`input`&&(0,$.jsx)(Gt,{className:`h-4 w-4 mt-1 shrink-0 text-blue-400/70`}),(0,$.jsx)(`span`,{children:e.content})]},t))]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2 px-4 py-2 border-t border-white/5 bg-white/5`,children:[!T&&(0,$.jsx)(`span`,{className:`text-blue-400 text-xs font-bold whitespace-nowrap`,children:C.split(`/`).pop()}),(0,$.jsx)(Gt,{className:`h-4 w-4 text-blue-400 ${T?``:`-ml-1`}`}),(0,$.jsx)(`input`,{ref:D,type:`text`,className:`flex-1 bg-transparent border-none outline-none text-neutral-200 placeholder:text-neutral-700 h-6`,placeholder:p?`Running...`:`Type a command...`,value:m,onChange:e=>h(e.target.value),onKeyDown:e=>{if(e.key===`Enter`)N(m);else if(e.key===`ArrowUp`){e.preventDefault();let t=d+1;t<u.length&&(i({type:J.SetTerminalHistoryIndex,index:t}),h(u[t]))}else if(e.key===`ArrowDown`){e.preventDefault();let t=d-1;t>=0?(i({type:J.SetTerminalHistoryIndex,index:t}),h(u[t])):(i({type:J.SetTerminalHistoryIndex,index:-1}),h(``))}},disabled:p}),(0,$.jsxs)(`div`,{className:`flex items-center gap-1 px-1.5 py-0.5 rounded border border-white/10 bg-white/5`,children:[(0,$.jsx)(Le,{className:`h-3 w-3 text-neutral-600`}),(0,$.jsx)(`span`,{className:`text-[10px] text-neutral-600 uppercase font-bold`,children:`Enter`})]})]})]}):null}function qi(e){let t=(0,Z.c)(5),{children:n,className:r}=e,i;t[0]===r?i=t[1]:(i=q(`flex min-h-[71px] shrink-0 items-center gap-2 border-b border-border px-4 py-2`,r),t[0]=r,t[1]=i);let a;return t[2]!==n||t[3]!==i?(a=(0,$.jsx)(`header`,{className:i,children:n}),t[2]=n,t[3]=i,t[4]=a):a=t[4],a}var Ji={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 Yi({todo:e,projectId:t,onUpdate:n,onEdit:r,onAction:i,onThreadSelect:a}){let[o,s]=(0,Q.useState)(!1),c=Ji[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 We(t,e.id,{status:a,working:!0}))}finally{s(!1)}}return(0,$.jsxs)(`div`,{className:q(`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,$.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,$.jsx)(`p`,{className:`text-sm font-medium leading-tight`,children:e.title}),e.working&&(0,$.jsx)(P,{className:`h-3 w-3 animate-spin text-primary shrink-0`})]}),(c.length>0||e.status!==`Ready`&&e.threadId&&a)&&(0,$.jsxs)(`div`,{className:`flex gap-1.5 flex-wrap items-center pt-1`,children:[c.map(t=>(0,$.jsxs)(or,{children:[(0,$.jsx)(sr,{asChild:!0,children:(0,$.jsx)(K,{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,$.jsx)(Y,{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,$.jsxs)(or,{children:[(0,$.jsx)(sr,{asChild:!0,children:(0,$.jsxs)(K,{size:`icon`,variant:`ghost`,className:`h-7 w-7 shrink-0 group-hover:flex items-center justify-center`,onClick:l,children:[(0,$.jsx)(it,{className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:`sr-only`,children:`Open thread`})]})}),(0,$.jsx)(Y,{side:`right`,children:`Open thread`})]})]})]})}var Xi=Q.forwardRef((e,t)=>{let n=(0,Z.c)(9),r,i;n[0]===e?(r=n[1],i=n[2]):({className:r,...i}=e,n[0]=e,n[1]=r,n[2]=i);let a;n[3]===r?a=n[4]:(a=q(`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,$.jsx)(`textarea`,{className:a,ref:t,...i}),n[5]=i,n[6]=t,n[7]=a,n[8]=o):o=n[8],o});Xi.displayName=`Textarea`;var Zi=[`Ready`,`Plan`,`Build`,`Test`,`Review`,`Done`],Qi={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 $i(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(`
|
|
13
|
-
`);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 ea(e){let t=e.getReader();try{for(;;){let{done:e}=await t.read();if(e)break}}catch{}}function ta({projectId:e,addOpen:t,onAddOpenChange:n,onThreadSelect:r}){let{state:i,dispatch:a}=qn(),[o,s]=(0,Q.useState)([]),[l,u]=(0,Q.useState)(!0),[d,f]=(0,Q.useState)(null),[p,m]=(0,Q.useState)(``),[h,g]=(0,Q.useState)(!1),_=(0,Q.useCallback)(async()=>{try{let t=await He(e),n=t.filter(e=>e.threadId&&e.status!==`Done`),r=[...t];await Promise.all(n.map(async t=>{try{await $e(t.threadId)}catch(n){if(n instanceof Error&&n.message.includes(`not found`)){let n=await We(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{u(!1)}},[e]);(0,Q.useEffect)(()=>{_()},[_]),(0,Q.useEffect)(()=>{if(!o.some(e=>e.working))return;let t=setInterval(async()=>{try{let n=await He(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,Q.useEffect)(()=>{t&&m(``)},[t]);function v(e){m(e.description),f({todo:e})}function y(){f(null),m(``)}async function b(){if(p.trim()){g(!0);try{let t=await st(e,p);s(e=>[...e,t]),n(!1),m(``)}finally{g(!1)}}}async function x(){if(!(!p.trim()||!d)){g(!0);try{let t=await We(e,d.todo.id,{description:p});s(e=>e.map(e=>e.id===t.id?t:e)),y()}finally{g(!1)}}}async function S(){if(d){g(!0);try{await c(e,d.todo.id),s(e=>e.filter(e=>e.id!==d.todo.id)),y()}finally{g(!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 W(e);if(!c)return;let l=null,u=await $i(c,n=>{We(e,t.id,{status:`Plan`,working:!0,threadId:n}).then(e=>{l=e,C(e)})});if(!u)return;l||C(await We(e,t.id,{status:`Plan`,working:!0,threadId:u}));let d=n??{id:o,provider:s,name:o,description:``};a({type:J.SetProjectModel,threadId:u,model:d}),bt(u,{model:o,modelProvider:s});let f=await ge(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&&ea(f)}async function T(t){let n=await W(e);if(!n)return;let r=null,i=await $i(n,n=>{We(e,t.id,{status:`Build`,working:!0,threadId:n}).then(e=>{r=e,C(e)})});if(!i)return;r||C(await We(e,t.id,{status:`Build`,working:!0,threadId:i}));let o=await $e(i),s=o.model,c=o.modelProvider;if(!s||!c)try{let t=(await at(`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:J.SetProjectModel,threadId:i,model:{id:s,provider:c,name:s,description:``}}),bt(i,{model:s,modelProvider:c}),console.log(`Sending chat message with provider:`,i,t.description,c);let l=await ge(i,t.description,s,[],void 0,c);l&&ea(l)}async function E(t,n){n===`Plan`?await w(t):n===`Build`?await T(t):C(await We(e,t.id,{status:n,working:!0}))}return l?(0,$.jsx)(`div`,{className:`flex items-center justify-center h-64`,children:(0,$.jsx)(P,{className:`h-6 w-6 animate-spin text-muted-foreground`})}):(0,$.jsxs)(`div`,{className:`flex h-full min-h-0`,children:[(0,$.jsx)(`div`,{className:`flex gap-3 overflow-x-auto pb-2 flex-1 min-h-0`,children:Zi.map(t=>{let i=o.filter(e=>e.status===t),a=t===`Ready`;return(0,$.jsxs)(`div`,{className:q(`flex flex-col rounded-lg border border-t-4 bg-muted/30 min-w-[200px] w-[200px] shrink-0`,Qi[t]),children:[(0,$.jsxs)(`div`,{className:`px-3 py-2 flex items-center justify-between`,children:[(0,$.jsx)(`h3`,{className:`text-xs font-semibold text-muted-foreground uppercase tracking-wide`,children:t}),(0,$.jsx)(`span`,{className:`text-xs text-muted-foreground bg-muted rounded-full px-1.5 py-0.5`,children:i.length})]}),(0,$.jsx)(R,{className:`flex-1 px-2 pb-2`,children:(0,$.jsxs)(`div`,{className:`space-y-2`,children:[a&&(0,$.jsxs)(K,{variant:`outline`,size:`sm`,className:`w-full h-8 border-dashed text-muted-foreground hover:text-foreground`,onClick:()=>n(!0),children:[(0,$.jsx)(G,{className:`h-3 w-3 mr-1`}),`Add Task`]}),i.map(t=>(0,$.jsx)(Yi,{todo:t,projectId:e,onUpdate:C,onEdit:v,onAction:E,onThreadSelect:r},t.id))]})})]},t)})}),(0,$.jsx)(Ct,{open:t,onOpenChange:n,children:(0,$.jsxs)(Ft,{className:`sm:max-w-2xl`,children:[(0,$.jsx)(Ht,{children:(0,$.jsx)(Be,{children:`Add Task`})}),(0,$.jsxs)(`div`,{className:`py-2`,children:[(0,$.jsx)(Xi,{placeholder:`Describe what needs to be done...`,value:p,onChange:e=>m(e.target.value),rows:12,className:`resize-none text-sm`,autoFocus:!0,onKeyDown:e=>{e.key===`Enter`&&(e.metaKey||e.ctrlKey)&&b()}}),(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground mt-1.5`,children:`A title will be generated automatically from your description.`})]}),(0,$.jsx)(mt,{children:(0,$.jsx)(K,{onClick:()=>void b(),disabled:h||!p.trim(),children:h?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(P,{className:`h-3 w-3 animate-spin mr-1`}),`Generating title...`]}):`Add`})})]})}),(0,$.jsx)(Ct,{open:d!==null,onOpenChange:e=>!e&&y(),children:(0,$.jsxs)(Ft,{className:`sm:max-w-2xl`,children:[(0,$.jsx)(Ht,{children:(0,$.jsx)(Be,{children:`Edit Task`})}),(0,$.jsx)(`div`,{className:`py-2`,children:(0,$.jsx)(Xi,{placeholder:`Describe what needs to be done...`,value:p,onChange:e=>m(e.target.value),rows:12,className:`resize-none text-sm`,autoFocus:!0,onKeyDown:e=>{e.key===`Enter`&&(e.metaKey||e.ctrlKey)&&x()}})}),(0,$.jsxs)(mt,{className:`gap-2 sm:gap-0`,children:[(0,$.jsx)(K,{variant:`destructive`,onClick:()=>void S(),disabled:h,className:`mr-auto`,children:`Delete`}),(0,$.jsx)(K,{onClick:()=>void x(),disabled:h||!p.trim(),children:h?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(P,{className:`h-3 w-3 animate-spin mr-1`}),`Saving...`]}):`Save`})]})]})})]})}function na({projectId:e,onExit:t}){let{state:n,dispatch:r}=qn(),{projects:i}=n,[a,o]=(0,Q.useState)(!1),s=En(),c=Ge(i,e);async function l(t){if(i.find(t=>t.projectId===e)){s(`/`);try{let{getProjects:n,invalidateProjectsCache:i}=await on(async()=>{let{getProjects:e,invalidateProjectsCache:t}=await import(`./dialogs-config-DiFQjCeA.js`).then(e=>e.C);return{getProjects:e,invalidateProjectsCache:t}},__vite__mapDeps([0,1]));i();let a=await n();r({type:J.SetProjects,projects:a.projects});let o=a.projects.find(t=>t.projectId===e);if(o&&o.threads.find(e=>e.threadId===t)){r({type:J.SelectThread,threadId:t,projectId:e});try{let e=await gt();r({type:J.SetProcessingThreads,threadIds:e})}catch(e){console.error(`Failed to fetch processing threads after thread selection:`,e)}}}catch(n){console.error(`Failed to refresh projects for thread selection:`,n),r({type:J.SelectThread,threadId:t,projectId:e});try{let e=await gt();r({type:J.SetProcessingThreads,threadIds:e})}catch(e){console.error(`Failed to fetch processing threads after fallback thread selection:`,e)}}}}return(0,$.jsxs)(`div`,{className:`flex h-full flex-col overflow-hidden`,children:[(0,$.jsx)(qi,{children:(0,$.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,$.jsxs)(or,{children:[(0,$.jsx)(sr,{asChild:!0,children:(0,$.jsxs)(K,{variant:`ghost`,size:`icon`,className:`h-8 w-8 text-muted-foreground`,onClick:t,children:[(0,$.jsx)(m,{className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:`sr-only`,children:`Back`})]})}),(0,$.jsx)(Y,{children:`Back`})]}),(0,$.jsxs)(`div`,{className:`flex flex-col`,children:[c&&(0,$.jsx)(`span`,{className:`text-sm font-medium text-foreground`,children:c}),(0,$.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`Tasks`})]})]})}),(0,$.jsx)(`div`,{className:`flex-1 overflow-hidden p-6`,children:(0,$.jsx)(ta,{projectId:e,addOpen:a,onAddOpenChange:o,onThreadSelect:l})})]})}var ra=(0,Q.lazy)(()=>on(()=>import(`./diff-view-B5XBM5UZ.js`),__vite__mapDeps([2,1,3,4,0,5,6,7,8]))),ia=(0,Q.lazy)(()=>on(()=>import(`./dialogs-config-DiFQjCeA.js`).then(e=>e.t),__vite__mapDeps([0,1])));function aa(e){let t=(0,Z.c)(41),{onCreateThread:n}=e,{state:r,dispatch:a}=qn(),o=En(),s=Dn(),[c,l]=(0,Q.useState)(!1),[u,d]=(0,Q.useState)(null),{selectedThreadId:f,messages:p,isCreatingProject:m,processingThreadIds:h,projects:g,projectsLoading:_,isStreaming:v,streamingSegments:y,streamingModel:b}=r,x;t[0]!==h||t[1]!==f?(x=f&&h.includes(f),t[0]=h,t[1]=f,t[2]=x):x=t[2];let S=!!x,C;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(C=()=>{d(`clone`),l(!0)},t[3]=C):C=t[3];let w=C,T;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(T=()=>{d(`webapp`),l(!0)},t[4]=T):T=t[4];let E=T,D;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(D=async(e,t)=>{try{await i(e,t),l(!1),d(null)}catch(e){let t=e;console.error(`Failed to clone repository:`,t)}},t[5]=D):D=t[5];let O=D,k;t[6]===Symbol.for(`react.memo_cache_sentinel`)?(k=async(e,t,n)=>{try{await I(e,t,n),l(!1),d(null)}catch(e){let t=e;console.error(`Failed to create project:`,t)}},t[6]=k):k=t[6];let A=k,j;t[7]===Symbol.for(`react.memo_cache_sentinel`)?(j=async()=>{try{await B(),l(!1),d(null)}catch(e){let t=e;console.error(`Failed to open folder:`,t)}},t[7]=j):j=t[7];let M=j,N=s.pathname===`/review`,P=s.pathname===`/todos`,F;t[8]===o?F=t[9]:(F=()=>{o(`/`)},t[8]=o,t[9]=F);let L=F,R;t[10]!==a||t[11]!==o?(R=()=>{dt(),Ye().then(e=>{a({type:J.SetProjects,projects:e.projects})}).catch(sa),o(`/`)},t[10]=a,t[11]=o,t[12]=R):R=t[12];let z=R,{selectedProjectId:V}=r,H;t[13]!==a||t[14]!==L||t[15]!==z||t[16]!==m||t[17]!==S||t[18]!==v||t[19]!==p||t[20]!==n||t[21]!==g||t[22]!==_||t[23]!==N||t[24]!==V||t[25]!==f||t[26]!==b||t[27]!==y||t[28]!==P?(H=P&&V?(0,$.jsx)(na,{projectId:V,onExit:z}):N&&f?(0,$.jsx)(Q.Suspense,{fallback:(0,$.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:`Loading diff view...`}),children:(0,$.jsx)(ra,{threadId:f,onExit:L})}):(0,$.jsx)(mi,{messages:p,isStreaming:v,streamingSegments:y,streamingModel:b,isCreatingProject:m,isProcessingThread:S,selectedThreadId:f,projects:g,projectsLoading:_,onSelectThread:(e,t)=>{a({type:J.SelectThread,projectId:e,threadId:t})},onCreateThread:n,onConnectRepo:w,onNewApp:E,onOpenFolder:M,error:null,onClearError:oa}),t[13]=a,t[14]=L,t[15]=z,t[16]=m,t[17]=S,t[18]=v,t[19]=p,t[20]=n,t[21]=g,t[22]=_,t[23]=N,t[24]=V,t[25]=f,t[26]=b,t[27]=y,t[28]=P,t[29]=H):H=t[29];let U;t[30]!==N||t[31]!==P?(U=!N&&!P&&(0,$.jsx)(Gi,{}),t[30]=N,t[31]=P,t[32]=U):U=t[32];let ee;t[33]===Symbol.for(`react.memo_cache_sentinel`)?(ee=(0,$.jsx)(Ki,{}),t[33]=ee):ee=t[33];let te=u??void 0,W;t[34]!==c||t[35]!==te?(W=(0,$.jsx)(Q.Suspense,{fallback:null,children:(0,$.jsx)(ia,{open:c,onOpenChange:l,initialMode:te,onSubmitClone:O,onSubmitWebApp:A,onOpenFolder:M})}),t[34]=c,t[35]=te,t[36]=W):W=t[36];let ne;return t[37]!==U||t[38]!==W||t[39]!==H?(ne=(0,$.jsxs)(`div`,{className:`flex h-full flex-col`,children:[H,U,ee,W]}),t[37]=U,t[38]=W,t[39]=H,t[40]=ne):ne=t[40],ne}function oa(){}function sa(e){console.error(`Failed to refresh projects on todo exit:`,e)}var ca=mn,la=wn,ua=Q.forwardRef((e,t)=>{let n=(0,Z.c)(14),r,i,a,o;n[0]===e?(r=n[1],i=n[2],a=n[3],o=n[4]):({className:i,inset:a,children:r,...o}=e,n[0]=e,n[1]=r,n[2]=i,n[3]=a,n[4]=o);let s=a&&`pl-8`,c;n[5]!==i||n[6]!==s?(c=q(`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,$.jsx)(Gt,{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,$.jsxs)(cn,{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});ua.displayName=cn.displayName;var da=Q.forwardRef((e,t)=>{let n=(0,Z.c)(9),r,i;n[0]===e?(r=n[1],i=n[2]):({className:r,...i}=e,n[0]=e,n[1]=r,n[2]=i);let a;n[3]===r?a=n[4]:(a=q(`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,$.jsx)(Kn,{ref:t,className:a,...i}),n[5]=i,n[6]=t,n[7]=a,n[8]=o):o=n[8],o});da.displayName=Kn.displayName;var fa=Q.forwardRef((e,t)=>{let n=(0,Z.c)(11),r,i,a;n[0]===e?(r=n[1],i=n[2],a=n[3]):({className:r,sideOffset:a,...i}=e,n[0]=e,n[1]=r,n[2]=i,n[3]=a);let o=a===void 0?4:a,s;n[4]===r?s=n[5]:(s=q(`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,$.jsx)(yn,{children:(0,$.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});fa.displayName=bn.displayName;var pa=Q.forwardRef((e,t)=>{let n=(0,Z.c)(11),r,i,a;n[0]===e?(r=n[1],i=n[2],a=n[3]):({className:r,inset:i,...a}=e,n[0]=e,n[1]=r,n[2]=i,n[3]=a);let o=i&&`pl-8`,s;n[4]!==r||n[5]!==o?(s=q(`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,$.jsx)(sn,{ref:t,className:s,...a}),n[7]=a,n[8]=t,n[9]=s,n[10]=c):c=n[10],c});pa.displayName=sn.displayName;var ma=Q.forwardRef((e,t)=>{let n=(0,Z.c)(14),r,i,a,o;n[0]===e?(r=n[1],i=n[2],a=n[3],o=n[4]):({className:a,children:i,checked:r,...o}=e,n[0]=e,n[1]=r,n[2]=i,n[3]=a,n[4]=o);let s;n[5]===a?s=n[6]:(s=q(`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,$.jsx)(`span`,{className:`absolute left-2 flex h-3.5 w-3.5 items-center justify-center`,children:(0,$.jsx)(In,{children:(0,$.jsx)(Qt,{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,$.jsxs)(un,{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});ma.displayName=un.displayName;var ha=Q.forwardRef((e,t)=>{let n=(0,Z.c)(12),r,i,a;n[0]===e?(r=n[1],i=n[2],a=n[3]):({className:i,children:r,...a}=e,n[0]=e,n[1]=r,n[2]=i,n[3]=a);let o;n[4]===i?o=n[5]:(o=q(`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,$.jsx)(`span`,{className:`absolute left-2 flex h-3.5 w-3.5 items-center justify-center`,children:(0,$.jsx)(In,{children:(0,$.jsx)(Et,{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,$.jsxs)(dn,{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});ha.displayName=dn.displayName;var ga=Q.forwardRef((e,t)=>{let n=(0,Z.c)(11),r,i,a;n[0]===e?(r=n[1],i=n[2],a=n[3]):({className:r,inset:i,...a}=e,n[0]=e,n[1]=r,n[2]=i,n[3]=a);let o=i&&`pl-8`,s;n[4]!==r||n[5]!==o?(s=q(`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,$.jsx)(vn,{ref:t,className:s,...a}),n[7]=a,n[8]=t,n[9]=s,n[10]=c):c=n[10],c});ga.displayName=vn.displayName;var _a=Q.forwardRef((e,t)=>{let n=(0,Z.c)(9),r,i;n[0]===e?(r=n[1],i=n[2]):({className:r,...i}=e,n[0]=e,n[1]=r,n[2]=i);let a;n[3]===r?a=n[4]:(a=q(`-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,$.jsx)(_n,{ref:t,className:a,...i}),n[5]=i,n[6]=t,n[7]=a,n[8]=o):o=n[8],o});_a.displayName=_n.displayName;var va=e=>{let t=(0,Z.c)(8),n,r;t[0]===e?(n=t[1],r=t[2]):({className:n,...r}=e,t[0]=e,t[1]=n,t[2]=r);let i;t[3]===n?i=t[4]:(i=q(`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,$.jsx)(`span`,{className:i,...r}),t[5]=r,t[6]=i,t[7]=a):a=t[7],a};va.displayName=`DropdownMenuShortcut`;var ya=`VS Code`,ba={"VS Code":`vscode`,Cursor:`cursor`,Windsurf:`windsurf`,Xcode:`xcode`,"Android Studio":`android-studio`,Kiro:`kiro`,Terminal:`terminal`};function xa({projectId:e,threadId:t,openWith:n}){let[r,i]=(0,Q.useState)(!1),[a,o]=(0,Q.useState)([]),[s,c]=(0,Q.useState)(n??ya),[l,u]=(0,Q.useState)(!0);(0,Q.useEffect)(()=>{(async()=>{try{let e=await be();o(e),!s&&e.length>0&&c(e[0])}catch(e){console.error(`Failed to fetch available programs:`,e),o([ya])}finally{u(!1)}})()},[]),(0,Q.useEffect)(()=>{n&&a.includes(n)&&c(n)},[n,a,c]);let d=async n=>{try{i(!0),c(n),await ae(e,n),t?await re(t,n):await H(e,n),X({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}X({title:`Error`,description:t,variant:`destructive`})}finally{i(!1)}};return l?(0,$.jsx)(K,{variant:`outline`,size:`sm`,className:`h-8`,disabled:!0,children:(0,$.jsx)(`div`,{className:`h-4 w-4 animate-pulse bg-muted rounded`})}):(0,$.jsxs)(`div`,{className:`flex items-center gap-0`,children:[(0,$.jsx)(K,{variant:`outline`,size:`sm`,className:`h-8 rounded-r-none border-r-0 border-transparent`,disabled:r,onClick:async()=>{await d(s)},title:`Open in ${s}`,children:(0,$.jsx)(`img`,{src:`/ide/${ba[s]||ba[ya]}.svg`,alt:s,className:`h-4 w-4`})}),(0,$.jsxs)(ca,{children:[(0,$.jsx)(la,{asChild:!0,children:(0,$.jsx)(K,{variant:`outline`,size:`sm`,className:`h-8 w-8 rounded-l-none px-1 border-transparent`,disabled:r,children:(0,$.jsx)(Ne,{className:`h-3.5 w-3.5`})})}),(0,$.jsx)(fa,{align:`end`,children:a.map(e=>(0,$.jsxs)(pa,{onClick:()=>d(e),disabled:r,className:`flex items-center gap-2`,children:[(0,$.jsx)(`img`,{src:`/ide/${ba[e]||ba[ya]}.svg`,alt:e,className:`h-4 w-4`}),e]},e))})]})]})}function Sa(){return{autoGenerateCommitMessage:Xe(),autoGeneratePRInfo:Te(),privateRepositoryDefault:tn()}}function Ca(e){e.autoGenerateCommitMessage!==void 0&&Me(e.autoGenerateCommitMessage),e.autoGeneratePRInfo!==void 0&&Zt(e.autoGeneratePRInfo),e.privateRepositoryDefault!==void 0&&ce(e.privateRepositoryDefault)}function wa(e){return e?!0:(X({title:`Error`,description:`No thread selected`,variant:`destructive`}),!1)}function Ta(e){let t=(0,Z.c)(57),{open:n,onOpenChange:r,commitMessage:i,onCommitMessageChange:a,autoGenerateCommitMessage:o,onAutoGenerateChange:s,isGeneratingMessage:c,isLoading:l,onGenerateMessage:u,onCommit:d,currentBranch:f}=e,p;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(p=(0,$.jsx)(Be,{children:`Commit Changes`}),t[0]=p):p=t[0];let m;t[1]===f?m=t[2]:(m=(0,$.jsxs)(Ht,{children:[p,(0,$.jsxs)(Re,{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,$.jsx)(ft,{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,$.jsx)(Xi,{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,$.jsx)(P,{className:`h-3.5 w-3.5 animate-spin`}):(0,$.jsx)(Qe,{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,$.jsx)(sr,{asChild:!0,children:(0,$.jsx)(K,{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,$.jsx)(Y,{children:x}),t[15]=x,t[16]=S);let C;t[17]!==S||t[18]!==b?(C=(0,$.jsx)(ar,{children:(0,$.jsxs)(or,{children:[b,S]})}),t[17]=S,t[18]=b,t[19]=C):C=t[19];let w;t[20]!==C||t[21]!==_?(w=(0,$.jsxs)(`div`,{className:`grid gap-2`,children:[h,(0,$.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,$.jsx)(ur,{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,$.jsx)(ft,{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,$.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,$.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,$.jsx)(K,{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`,F;t[42]!==d||t[43]!==M||t[44]!==N?(F=(0,$.jsx)(K,{onClick:d,disabled:M,children:N}),t[42]=d,t[43]=M,t[44]=N,t[45]=F):F=t[45];let I;t[46]!==j||t[47]!==F?(I=(0,$.jsxs)(mt,{children:[j,F]}),t[46]=j,t[47]=F,t[48]=I):I=t[48];let L;t[49]!==k||t[50]!==m||t[51]!==I?(L=(0,$.jsxs)(Ft,{children:[m,k,I]}),t[49]=k,t[50]=m,t[51]=I,t[52]=L):L=t[52];let R;return t[53]!==r||t[54]!==n||t[55]!==L?(R=(0,$.jsx)(Ct,{open:n,onOpenChange:r,children:L}),t[53]=r,t[54]=n,t[55]=L,t[56]=R):R=t[56],R}function Ea(e){let t=(0,Z.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,$.jsx)(Be,{children:`Create Pull Request`}),t[0]=h):h=t[0];let g;t[1]===f?g=t[2]:(g=(0,$.jsxs)(Ht,{children:[h,(0,$.jsxs)(Re,{children:[`Create a pull request for branch `,f]})]}),t[1]=f,t[2]=g);let _;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(_=(0,$.jsx)(ft,{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,$.jsxs)(`div`,{className:`grid gap-2`,children:[_,(0,$.jsx)(Ie,{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,$.jsx)(ft,{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,$.jsx)(Xi,{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,$.jsx)(P,{className:`h-3.5 w-3.5 animate-spin`}):(0,$.jsx)(Qe,{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,$.jsx)(sr,{asChild:!0,children:(0,$.jsx)(K,{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,$.jsx)(Y,{children:D}),t[22]=D,t[23]=O);let k;t[24]!==E||t[25]!==O?(k=(0,$.jsx)(ar,{children:(0,$.jsxs)(or,{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,$.jsxs)(`div`,{className:`grid gap-2`,children:[x,(0,$.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,$.jsx)(ur,{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,$.jsx)(ft,{htmlFor:`auto-generate-pr`,className:`text-sm font-normal`,children:`Auto generate PR title and description`}),t[35]=N):N=t[35];let F;t[36]===M?F=t[37]:(F=(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[M,N]}),t[36]=M,t[37]=F);let I;t[38]!==A||t[39]!==F||t[40]!==b?(I=(0,$.jsxs)(`div`,{className:`grid gap-4 py-4`,children:[b,A,F]}),t[38]=A,t[39]=F,t[40]=b,t[41]=I):I=t[41];let L;t[42]===r?L=t[43]:(L=()=>r(!1),t[42]=r,t[43]=L);let R;t[44]!==l||t[45]!==L?(R=(0,$.jsx)(K,{variant:`outline`,onClick:L,disabled:l,children:`Cancel`}),t[44]=l,t[45]=L,t[46]=R):R=t[46];let z=l?`Creating...`:`Create PR`,B;t[47]!==l||t[48]!==d||t[49]!==z?(B=(0,$.jsx)(K,{onClick:d,disabled:l,children:z}),t[47]=l,t[48]=d,t[49]=z,t[50]=B):B=t[50];let V;t[51]!==R||t[52]!==B?(V=(0,$.jsxs)(mt,{children:[R,B]}),t[51]=R,t[52]=B,t[53]=V):V=t[53];let H;t[54]!==g||t[55]!==I||t[56]!==V?(H=(0,$.jsxs)(Ft,{children:[g,I,V]}),t[54]=g,t[55]=I,t[56]=V,t[57]=H):H=t[57];let U;return t[58]!==r||t[59]!==n||t[60]!==H?(U=(0,$.jsx)(Ct,{open:n,onOpenChange:r,children:H}),t[58]=r,t[59]=n,t[60]=H,t[61]=U):U=t[61],U}function Da(e){let t=(0,Z.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,$.jsxs)(Ht,{children:[(0,$.jsx)(Be,{children:`Create GitHub Repository`}),(0,$.jsx)(Re,{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,$.jsx)(ft,{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,$.jsxs)(`div`,{className:`grid gap-2`,children:[m,(0,$.jsx)(Ie,{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,$.jsx)(ft,{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,$.jsxs)(`div`,{className:`grid gap-2`,children:[_,(0,$.jsx)(Xi,{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,$.jsx)(ur,{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,$.jsx)(ft,{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,$.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,$.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,$.jsx)(K,{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,$.jsx)(K,{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,$.jsxs)(mt,{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,$.jsxs)(Ft,{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,$.jsx)(Ct,{open:n,onOpenChange:f,children:A}),t[44]=n,t[45]=f,t[46]=A,t[47]=j):j=t[47],j}function Oa(e){let t=(0,Z.c)(28),{open:n,onOpenChange:r,commits:i,displayedCommits:a,isLoadingMore:o,onScroll:s,currentBranch:c}=e,l;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(l=(0,$.jsx)(Be,{children:`Commit History`}),t[0]=l):l=t[0];let u;t[1]===c?u=t[2]:(u=(0,$.jsxs)(Ht,{children:[l,(0,$.jsxs)(Re,{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(ka):(0,$.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,$.jsx)(`div`,{className:`p-3 text-center`,children:(0,$.jsx)(P,{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,$.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,$.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,$.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,$.jsx)(mt,{children:(0,$.jsx)(K,{onClick:()=>r(!1),children:`Close`})}),t[18]=r,t[19]=g);let _;t[20]!==u||t[21]!==h||t[22]!==g?(_=(0,$.jsxs)(Ft,{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,$.jsx)(Ct,{open:n,onOpenChange:r,children:_}),t[24]=r,t[25]=n,t[26]=_,t[27]=v):v=t[27],v}function ka(e){return(0,$.jsxs)(`div`,{className:`p-3 hover:bg-slate-50 dark:hover:bg-slate-900 transition-colors`,children:[(0,$.jsx)(`p`,{className:`text-sm font-medium break-words`,children:e.message}),(0,$.jsxs)(`p`,{className:`text-xs text-slate-600 dark:text-slate-400 mt-1`,children:[(0,$.jsx)(`span`,{className:`font-mono`,children:e.hash.substring(0,7)}),` •`,` `,e.author,` • `,new Date(e.date).toLocaleDateString()]})]},e.hash)}function Aa(e){let t=(0,Z.c)(15),{open:n,onOpenChange:r,isLoading:i,onPushAndCreatePR:a,onCancel:o}=e,s;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(s=(0,$.jsxs)(Ht,{children:[(0,$.jsx)(Be,{children:`Push Branch First`}),(0,$.jsx)(Re,{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,$.jsx)(K,{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,$.jsx)(K,{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,$.jsxs)(Ft,{children:[s,(0,$.jsxs)(mt,{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,$.jsx)(Ct,{open:n,onOpenChange:r,children:d}),t[11]=r,t[12]=n,t[13]=d,t[14]=f):f=t[14],f}function ja(e){let t=(0,Z.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,$.jsxs)(Ht,{children:[(0,$.jsxs)(Be,{className:`flex items-center gap-2`,children:[(0,$.jsx)(ze,{className:`h-5 w-5 text-amber-500`}),`Uncommitted Changes Detected`]}),(0,$.jsx)(Re,{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,$.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,$.jsx)(kt,{className:`h-4 w-4 mr-2`}),t[2]=d):d=t[2];let f;t[3]!==c||t[4]!==i?(f=(0,$.jsxs)(K,{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,$.jsx)(ee,{className:`h-4 w-4 mr-2`}),t[6]=p):p=t[6];let m;t[7]!==c||t[8]!==a?(m=(0,$.jsxs)(K,{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,$.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,$.jsx)(`strong`,{children:`Commit first:`}),t[13]=g):g=t[13];let _;t[14]===Symbol.for(`react.memo_cache_sentinel`)?(_=(0,$.jsxs)(`div`,{className:`text-xs text-muted-foreground mt-4`,children:[g,` Safe option, preserves changes in your commit history`,(0,$.jsx)(`br`,{}),(0,$.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,$.jsx)(`div`,{className:`py-4`,children:(0,$.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,$.jsx)(mt,{children:(0,$.jsx)(K,{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,$.jsxs)(Ft,{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,$.jsx)(Ct,{open:n,onOpenChange:r,children:b}),t[23]=r,t[24]=n,t[25]=b,t[26]=x):x=t[26],x}function Ma(e){let t=(0,Z.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,$.jsx)(Be,{children:`Pull Request Merged`}),t[0]=c):c=t[0];let l=o?` from ${o}`:``,u;t[1]===l?u=t[2]:(u=(0,$.jsxs)(Ht,{children:[c,(0,$.jsxs)(Re,{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,$.jsx)(mt,{children:(0,$.jsx)(K,{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,$.jsxs)(Ft,{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,$.jsx)(Ct,{open:n,onOpenChange:r,children:f}),t[9]=r,t[10]=n,t[11]=f,t[12]=p):p=t[12],p}var Na=3e4;function Pa(e){let[t,n]=(0,Q.useState)(!1),[r,i]=(0,Q.useState)(0),[a,o]=(0,Q.useState)(!1),[s,c]=(0,Q.useState)(``),[l,u]=(0,Q.useState)(!1),[d,f]=(0,Q.useState)(``),[p,m]=(0,Q.useState)(!1),[h,g]=(0,Q.useState)(void 0),[_,v]=(0,Q.useState)(!1),[y,b]=(0,Q.useState)(`Up to date`),[x,S]=(0,Q.useState)(null),[C,w]=(0,Q.useState)(!1),[T,E]=(0,Q.useState)(void 0),[D,O]=(0,Q.useState)(void 0),[k,A]=(0,Q.useState)(!1),[j,M]=(0,Q.useState)(!1),N=(0,Q.useRef)(!0),P=(0,Q.useCallback)(e=>{n(e.hasChanges),i(e.changedFilesCount),o(e.hasUnpushedCommits),c(e.currentBranch),v(e.hasRemoteBranch),u(e.isOnGitHub),f(e.remoteUrl),m(e.canCreateRepo),g(e.repoUrl),b(e.status),S(e.defaultBranch??null),w(e.prExists),E(e.prUrl),O(e.prState),A(e.commitsAheadOfDefault??!1)},[]),F=(0,Q.useCallback)(async(t=!1)=>{if(!e)return;let n=setTimeout(()=>M(!0),100);try{let n=`unified-git-status-${e}`;t&&jt.invalidate(n),P(await jt.get(n,()=>en(e,t),Na))}catch(e){console.error(`Failed to fetch unified git status:`,e)}finally{clearTimeout(n),M(!1)}},[e,P]);return(0,Q.useEffect)(()=>{e&&(async()=>{if(N.current){let t=`unified-git-status-${e}`,n=jt.getSync(t);n&&P(n),N.current=!1}await F()})()},[e,F,P]),{hasChanges:t,changedFilesCount:r,hasUnpushedCommits:a,hasRemoteBranch:_,currentBranch:s,isOnGitHub:l,remoteUrl:d,canCreateRepo:p,repoUrl:h,status:y,defaultBranch:x,prExists:C,prUrl:T,prState:D,commitsAheadOfDefault:k,isRefreshing:j,fetchUnifiedStatus:F}}function Fa(e){let t=e.split(`/`);return t.length>=2?{provider:t[0],model:t.slice(1).join(`/`)}:{provider:void 0,model:e}}function Ia(e,t,n){let[r,i]=(0,Q.useState)(!1),[a,o]=(0,Q.useState)(!1),s=()=>{let t=e?n[e]:void 0;return t?.id?t.provider?{provider:t.provider,model:t.id}:Fa(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 Dt(e,n,t)}catch(e){return console.error(`Failed to generate commit message:`,e),X({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 E(e,n,t);return X({title:`Success`,description:`PR title and description generated`}),r}catch(e){return console.error(`Failed to generate PR info:`,e),X({title:`Error`,description:e instanceof Error?e.message:`Failed to generate PR info`,variant:`destructive`}),null}finally{o(!1)}}}}function La({projectId:e,threadId:t}){let{state:n,dispatch:r}=qn(),[i,a]=(0,Q.useState)(!1),[o,s]=(0,Q.useState)(!1),[c,l]=(0,Q.useState)(!1),[u,d]=(0,Q.useState)(``),[p,m]=(0,Q.useState)(``),[h,_]=(0,Q.useState)(``),[y,b]=(0,Q.useState)(!1),[S,w]=(0,Q.useState)(null),T=(0,Q.useRef)(!1),E=(0,Q.useRef)(!1),[D,k]=(0,Q.useState)(!1),[A,j]=(0,Q.useState)([]),[M,N]=(0,Q.useState)(!1),[F,I]=(0,Q.useState)([]),[L,R]=(0,Q.useState)(!1),[z,B]=(0,Q.useState)(!1),[V,H]=(0,Q.useState)(``),[ee,W]=(0,Q.useState)(``),[ne,re]=(0,Q.useState)(``),[ie,ae]=(0,Q.useState)(!1),[oe,se]=(0,Q.useState)(!1),[ce,le]=(0,Q.useState)(!1),G=Pa(t),de=Ia(t,e,n.projectModelSelections),fe=async()=>{dt();let e=await Ye();r({type:J.SetProjects,projects:e.projects})},[pe,he]=(0,Q.useState)(()=>Sa()),ge=n.projects.find(t=>t.projectId===e),_e=ge?.commitMethod===Bt.Direct;(0,Q.useEffect)(()=>{let e=()=>{document.visibilityState===`visible`&&G.fetchUnifiedStatus(!0)};return document.addEventListener(`visibilitychange`,e),()=>document.removeEventListener(`visibilitychange`,e)},[G.fetchUnifiedStatus]),(0,Q.useEffect)(()=>{z&&ge?.name&&!V&&H(ge.name)},[z,ge?.name,V]),(0,Q.useEffect)(()=>{Ca(pe)},[pe]),(0,Q.useEffect)(()=>{let e=!0;return Nt().then(t=>{e&&re(t)}).catch(()=>{}),()=>{e=!1}},[]),(0,Q.useEffect)(()=>{if(!o){E.current=!1;return}o&&pe.autoGenerateCommitMessage&&!u.trim()&&t&&!E.current&&(E.current=!0,(async()=>{let e=await de.generateCommitMessageWithAI();e&&d(e)})())},[o,pe.autoGenerateCommitMessage,t,de,u]),(0,Q.useEffect)(()=>{if(!c){T.current=!1;return}console.log(`[pr-auto-gen] useEffect triggered`,{isPRDialogOpen:c,autoGeneratePRInfo:pe.autoGeneratePRInfo,prTitleEmpty:!p.trim(),prDescriptionEmpty:!h.trim(),threadId:t,hasThreadId:!!t,generationAlreadyStarted:T.current}),c&&pe.autoGeneratePRInfo&&!p.trim()&&!h.trim()&&t&&!T.current?(console.log(`[pr-auto-gen] Starting auto-generation...`),T.current=!0,(async()=>{let e=await de.generatePRInfoWithAI();e&&(console.log(`[pr-auto-gen] Setting PR info:`,e.title.substring(0,50)),m(e.title),_(e.description))})()):console.log(`[pr-auto-gen] Skipping auto-generation - conditions not met`)},[c,pe.autoGeneratePRInfo,t,de,p,h]),(0,Q.useEffect)(()=>{console.log(`Unified status changed:`,{prExists:G.prExists,prState:G.prState,threadId:t}),G.prExists&&G.prState===`MERGED`&&(console.log(`Merged PR detected, opening dialog`),le(!0))},[G.prExists,G.prState,t]),(0,Q.useEffect)(()=>{!n.isStreaming&&n.completedThreadIds.includes(n.selectedThreadId??``)&&(G.fetchUnifiedStatus(!0),r({type:J.ClearThreadCompleted,threadId:n.selectedThreadId??``}))},[n.isStreaming,n.completedThreadIds,n.selectedThreadId,G,r]);let ye=async()=>{if(u.trim()&&wa(t))try{a(!0),await ue(t,u),d(``),s(!1),await G.fetchUnifiedStatus(!0),fe(),X({title:`Changes committed successfully`,description:`Your changes have been committed to '${G.currentBranch}'.`}),oe&&(se(!1),await ke())}catch(e){console.error(`Failed to commit:`,e),X({title:`Commit failed`,description:e instanceof Error?e.message:`Failed to commit changes`,variant:`destructive`})}finally{a(!1)}},be=async()=>{if(G.status===`Behind`&&!G.hasChanges&&!G.hasUnpushedCommits){await Pe();return}if(G.hasChanges){s(!0);return}if(G.prExists&&G.prState===`OPEN`&&!G.hasChanges&&!G.hasUnpushedCommits){G.prUrl&&await ct(G.prUrl);return}if(G.commitsAheadOfDefault&&!G.prExists&&!G.hasChanges){l(!0);return}if(G.hasUnpushedCommits&&G.prExists){await Ee();return}},xe=()=>G.status===`Behind`&&!G.hasChanges&&!G.hasUnpushedCommits?`Sync`:G.hasChanges?`Commit`:G.prExists&&G.prState===`OPEN`&&!G.hasChanges&&!G.hasUnpushedCommits?`Open PR`:G.commitsAheadOfDefault&&!G.prExists&&!G.hasChanges?`Create PR`:G.hasUnpushedCommits&&G.prExists?`Update PR`:`Commit`,Se=()=>G.status===`Behind`&&!G.hasChanges&&!G.hasUnpushedCommits?(0,$.jsx)(U,{className:`h-3.5 w-3.5`}):G.hasChanges?(0,$.jsx)(kt,{className:`h-3.5 w-3.5`}):G.prExists&&G.prState===`OPEN`&&!G.hasChanges&&!G.hasUnpushedCommits?(0,$.jsx)(it,{className:`h-3.5 w-3.5`}):(0,$.jsx)(x,{className:`h-3.5 w-3.5`}),Ce=()=>G.status===`Behind`&&!G.hasChanges&&!G.hasUnpushedCommits?`Your branch "${G.currentBranch}" is behind "${G.defaultBranch??`main`}". This will rebase and sync with the latest changes`:G.hasChanges?G.changedFilesCount>0?`Commit ${G.changedFilesCount} changed file${G.changedFilesCount===1?``:`s`}`:`No changes to commit`:G.prExists&&G.prState===`OPEN`&&!G.hasChanges&&!G.hasUnpushedCommits?`View pull request in GitHub`:G.commitsAheadOfDefault&&!G.prExists&&!G.hasChanges?`Create pull request for committed changes`:G.hasUnpushedCommits&&G.prExists?`Update pull request with unpushed commits`:`No actions available`,q=()=>i?!0:G.status===`Behind`&&!G.hasChanges&&!G.hasUnpushedCommits||G.prExists&&G.prState===`OPEN`&&!G.hasChanges&&!G.hasUnpushedCommits||G.commitsAheadOfDefault&&!G.prExists&&!G.hasChanges?!1:!G.hasChanges&&!G.hasUnpushedCommits,we=async()=>{let e=await de.generateCommitMessageWithAI();e&&d(e)},Te=async()=>{if(wa(t))try{a(!0),await me(t),await G.fetchUnifiedStatus()}catch(e){console.error(`Failed to fetch:`,e)}finally{a(!1)}},Ee=async()=>{if(wa(t))try{a(!0),await g(t),await G.fetchUnifiedStatus(!0),fe(),G.hasRemoteBranch?X({title:`Branch pushed successfully`,description:`Your branch '${G.currentBranch}' has been pushed to the remote.`}):X({title:`Push completed`,description:`Changes have been pushed successfully.`})}catch(e){console.error(`Failed to push:`,e),X({title:`Push failed`,description:e instanceof Error?e.message:`Failed to push to remote`,variant:`destructive`})}finally{a(!1)}},De=async()=>{if(wa(t)){if(G.hasChanges){ae(!0);return}await ke()}},ke=async()=>{try{a(!0),await v(t),await G.fetchUnifiedStatus(!0),fe(),X({title:`Pull successful`,description:`Latest changes have been pulled from remote.`})}catch(e){console.error(`Failed to pull:`,e),X({title:`Pull failed`,description:e instanceof Error?e.message:`Failed to pull from remote`,variant:`destructive`})}finally{a(!1)}},Ae=()=>{ae(!1),se(!0),s(!0)},je=async()=>{ae(!1),await ke()},Me=async()=>{if(t)try{a(!0);let e=await f(t,G.defaultBranch??void 0);dt();let n=await Ye();r({type:J.SetProjects,projects:n.projects}),X({title:`New branch created`,description:`Created new branch "${e.branchName}" on current thread`}),le(!1),await G.fetchUnifiedStatus(!0),setTimeout(()=>void G.fetchUnifiedStatus(!0),1500)}catch(e){console.error(`Failed to create new branch:`,e),X({title:`Failed to create new branch`,description:e instanceof Error?e.message:`Unknown error occurred`,variant:`destructive`})}finally{a(!1)}},Pe=async()=>{if(!wa(t)){console.log(`[sync] Thread operation validation failed`);return}try{console.log(`[sync] Starting branch sync for thread: ${t}`),console.log(`[sync] Current branch: ${G.currentBranch}, Default branch: ${G.defaultBranch}`),a(!0),console.log(`[sync] Calling gitSyncBranch API...`);let e=await te(t);console.log(`[sync] ✓ gitSyncBranch API call successful`),console.log(`[sync] Result:`,e),console.log(`[sync] Refreshing git status...`),await G.fetchUnifiedStatus(!0),fe(),console.log(`[sync] ✓ Git status refreshed`),X({title:`Branch synced successfully`,description:`Your branch '${G.currentBranch}' has been synced with the latest changes`}),console.log(`[sync] ✓ Sync operation completed successfully`)}catch(e){console.error(`[sync] ✗ Failed to sync branch:`,e),X({title:`Sync failed`,description:e instanceof Error?e.message:`Failed to sync with default branch`,variant:`destructive`})}finally{a(!1)}},Fe=async()=>{if(wa(t))try{a(!0);let e=await Xt(t,p,h);e.prUrl&&await ct(e.prUrl),m(``),_(``),l(!1),await G.fetchUnifiedStatus(),fe()}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`)?(l(!1),Re({title:p,description:h})):X({title:`Create PR Failed`,description:t,variant:`destructive`})}finally{a(!1)}},Ie=async()=>{if(wa(t))try{a(!0);let e=await lt(t,V,ee,pe.privateRepositoryDefault);e.repoUrl&&setTimeout(()=>{ct(e.repoUrl)},3e3),H(``),W(``),B(!1),await G.fetchUnifiedStatus(),fe()}catch(e){console.error(`Failed to create repo:`,e)}finally{a(!1)}},Le=async()=>{let e=await de.generatePRInfoWithAI();e&&(m(e.title),_(e.description))},Re=async e=>{let n=e??S;if(!(!t||!n))try{a(!0);try{await g(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...`),X({title:`Syncing branch before push`,description:`Your branch is behind remote. Pulling latest changes first...`});try{await te(t),console.log(`[push-and-pr] ✓ Pull completed, retrying push...`),await g(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 Xt(t,n.title,n.description);e.prUrl&&await ct(e.prUrl),m(``),_(``),w(null),b(!1),await G.fetchUnifiedStatus(),fe()}catch(e){console.error(`Failed to push and create PR:`,e),X({title:`Push & Create PR Failed`,description:e instanceof Error?e.message:`Failed to push and create PR`,variant:`destructive`})}finally{a(!1)}},ze=async()=>{if(wa(t))try{N(!0);let e=await St(t,100);j(e),I(e.slice(0,10)),k(!0)}catch(e){console.error(`Failed to fetch git history:`,e)}finally{N(!1)}},Be=()=>{L||(R(!0),setTimeout(()=>{let e=F.length+10;I(A.slice(0,e)),R(!1)},300))},Ve=e=>{let t=e.currentTarget;t.scrollHeight-t.scrollTop-t.clientHeight<100&&F.length<A.length&&!L&&Be()},He=G.hasChanges||G.status===`Behind`&&!G.hasChanges&&!G.hasUnpushedCommits||G.commitsAheadOfDefault&&!G.prExists&&!G.hasChanges;return(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-0`,children:[(0,$.jsx)(ar,{children:(0,$.jsxs)(or,{children:[(0,$.jsx)(sr,{asChild:!0,children:(0,$.jsxs)(K,{variant:`outline`,size:`sm`,className:`h-8 rounded-r-none border-r-0 gap-1.5 border-transparent${He?` bg-brand text-brand-foreground hover:bg-brand/90 hover:text-brand-foreground`:``}`,disabled:q(),onClick:be,children:[Se(),xe()]})}),(0,$.jsx)(Y,{children:Ce()})]})}),(0,$.jsxs)(ca,{children:[(0,$.jsx)(la,{asChild:!0,children:(0,$.jsx)(K,{variant:`outline`,size:`sm`,className:`h-8 w-8 rounded-l-none px-1 border-transparent${He?` bg-brand text-brand-foreground hover:bg-brand/90 hover:text-brand-foreground`:``}`,disabled:i,children:G.isRefreshing?(0,$.jsx)(P,{className:`h-3.5 w-3.5 animate-spin`}):(0,$.jsx)(Ne,{className:`h-3.5 w-3.5`})})}),(0,$.jsxs)(fa,{align:`end`,children:[(0,$.jsxs)(`div`,{className:`px-2 py-1.5`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2 text-xs text-muted-foreground`,children:[(0,$.jsx)(O,{className:`h-3 w-3`}),(0,$.jsx)(`span`,{className:`font-medium`,children:G.currentBranch||`Unknown`})]}),G.status===`Behind`&&(0,$.jsx)(`div`,{className:`flex items-center gap-2 text-xs text-amber-600 mt-1`,children:(0,$.jsxs)(`span`,{className:`font-medium`,children:[`Your branch is behind `,G.remoteUrl?`origin`:`remote`]})}),ne&&(0,$.jsxs)(`div`,{className:`flex items-center gap-2 text-xs text-muted-foreground mt-1`,children:[(0,$.jsx)(`span`,{className:`font-medium`,children:`User:`}),(0,$.jsx)(`span`,{children:ne})]})]}),(0,$.jsx)(_a,{}),(0,$.jsx)(ar,{children:(0,$.jsxs)(or,{children:[(0,$.jsx)(sr,{asChild:!0,children:(0,$.jsxs)(pa,{onClick:Te,disabled:i,children:[(0,$.jsx)(Oe,{className:`h-3.5 w-3.5 mr-2`}),`Fetch`]})}),(0,$.jsx)(Y,{side:`right`,children:`Download latest information from remote without merging changes`})]})}),(0,$.jsx)(ar,{children:(0,$.jsxs)(or,{children:[(0,$.jsx)(sr,{asChild:!0,children:(0,$.jsxs)(pa,{onClick:()=>{G.hasRemoteBranch&&!i&&De()},className:!G.hasRemoteBranch||i?`opacity-50 cursor-not-allowed`:``,children:[(0,$.jsx)(U,{className:`h-3.5 w-3.5 mr-2`}),`Pull`]})}),(0,$.jsx)(Y,{side:`right`,children:G.hasRemoteBranch?`Pull latest changes from remote`:`No remote branch to pull from`})]})}),!G.hasRemoteBranch&&(0,$.jsx)(ar,{children:(0,$.jsxs)(or,{children:[(0,$.jsx)(sr,{asChild:!0,children:(0,$.jsxs)(pa,{onClick:Ee,disabled:i,children:[(0,$.jsx)(It,{className:`h-3.5 w-3.5 mr-2`}),`Push Branch to Remote`]})}),(0,$.jsx)(Y,{side:`right`,children:`Create remote branch and push local commits`})]})}),(0,$.jsx)(ar,{children:(0,$.jsxs)(or,{children:[(0,$.jsx)(sr,{asChild:!0,children:(0,$.jsxs)(pa,{onClick:()=>{G.hasUnpushedCommits&&!i&&Ee()},className:!G.hasUnpushedCommits||i?`opacity-50 cursor-not-allowed`:``,children:[(0,$.jsx)(It,{className:`h-3.5 w-3.5 mr-2`}),`Push Commits`]})}),(0,$.jsx)(Y,{side:`right`,children:G.hasUnpushedCommits?i?`Push in progress...`:`Push your uncommitted commits to the remote branch`:`No commits to push - your branch is up to date with remote`})]})}),(0,$.jsxs)(pa,{onClick:ze,disabled:i||M,children:[(0,$.jsx)(C,{className:`h-3.5 w-3.5 mr-2`}),`History`]}),!_e&&(0,$.jsxs)(pa,{onClick:()=>l(!0),disabled:i,children:[(0,$.jsx)(x,{className:`h-3.5 w-3.5 mr-2`}),`Create Pull Request`]}),G.canCreateRepo&&(0,$.jsxs)(pa,{onClick:()=>B(!0),disabled:i,children:[(0,$.jsx)(ve,{className:`h-3.5 w-3.5 mr-2`}),`Create Repo`]}),G.repoUrl&&(0,$.jsxs)(pa,{onClick:()=>{G.repoUrl&&ct(G.repoUrl)},disabled:i,children:[(0,$.jsx)(it,{className:`h-3.5 w-3.5 mr-2`}),`View in GitHub`]})]})]})]}),(0,$.jsx)(Ta,{open:o,onOpenChange:s,commitMessage:u,onCommitMessageChange:d,autoGenerateCommitMessage:pe.autoGenerateCommitMessage,onAutoGenerateChange:e=>he(t=>({...t,autoGenerateCommitMessage:e})),isGeneratingMessage:de.isGeneratingMessage,isLoading:i,onGenerateMessage:we,onCommit:ye,currentBranch:G.currentBranch}),(0,$.jsx)(Ea,{open:c,onOpenChange:l,prTitle:p,onPrTitleChange:m,prDescription:h,onPrDescriptionChange:_,isGeneratingPRInfo:de.isGeneratingPRInfo,isLoading:i,onGeneratePRInfo:Le,onCreatePR:Fe,currentBranch:G.currentBranch,autoGeneratePRInfo:pe.autoGeneratePRInfo,onAutoGeneratePRInfoChange:e=>he(t=>({...t,autoGeneratePRInfo:e}))}),(0,$.jsx)(Aa,{open:y,onOpenChange:b,isLoading:i,onPushAndCreatePR:Re,onCancel:()=>{b(!1),w(null)}}),(0,$.jsx)(Da,{open:z,onOpenChange:B,repoName:V,onRepoNameChange:H,repoDescription:ee,onRepoDescriptionChange:W,isPrivateRepo:pe.privateRepositoryDefault,onPrivateRepoChange:e=>he(t=>({...t,privateRepositoryDefault:e})),isLoading:i,onCreateRepo:Ie}),(0,$.jsx)(Oa,{open:D,onOpenChange:k,commits:A,displayedCommits:F,isLoadingMore:L,onScroll:Ve,currentBranch:G.currentBranch}),(0,$.jsx)(ja,{open:ie,onOpenChange:ae,onCommitFirst:Ae,onStashAndPull:je,onCancel:()=>ae(!1),isLoading:i}),(0,$.jsx)(Ma,{open:ce,onOpenChange:le,onOk:Me,isLoading:i,defaultBranch:G.defaultBranch??void 0})]})}var Ra=`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 za({open:e,onOpenChange:t,projectId:n,commands:r,onRefresh:i}){let[a,o]=(0,Q.useState)(null),[s,c]=(0,Q.useState)(!1),[l,u]=(0,Q.useState)(!1),[f,p]=(0,Q.useState)([]),[m,h]=(0,Q.useState)(0),[g,_]=(0,Q.useState)(!1),v=(0,Q.useRef)(null),y=(0,Q.useRef)(null),b=()=>{o({id:crypto.randomUUID(),name:``,icon:`Play`,commandLine:``}),u(!1),p([])},x=e=>{o({...e}),u(!1),p([])},S=async()=>{try{_(!0);let e=await Lt(n);p(e.scripts),h(0),u(e.scripts.length>0)}catch(e){console.error(`Failed to load package scripts:`,e),X({title:`Error`,description:`Failed to load package scripts`,variant:`destructive`})}finally{_(!1)}},C=e=>{o(t=>t?{...t,name:e.name,commandLine:e.commandLine,relativeFolder:e.relativePath||``}:null),u(!1),p([]),v.current?.focus()},w=e=>{l&&(e.key===`ArrowDown`?(e.preventDefault(),h(e=>e<f.length-1?e+1:e)):e.key===`ArrowUp`?(e.preventDefault(),h(e=>e>0?e-1:0)):e.key===`Enter`?(e.preventDefault(),m<f.length&&C(f[m])):e.key===`Escape`&&(e.preventDefault(),u(!1),p([])))};(0,Q.useEffect)(()=>{let e=e=>{y.current&&!y.current.contains(e.target)&&(u(!1),p([]))};return l&&document.addEventListener(`mousedown`,e),()=>{document.removeEventListener(`mousedown`,e)}},[l]);let T=async e=>{try{await N(n,e),X({title:`Success`,description:`Command deleted`}),i()}catch{X({title:`Error`,description:`Failed to delete command`,variant:`destructive`})}};return(0,$.jsx)(Ct,{open:e,onOpenChange:t,children:(0,$.jsxs)(Ft,{className:`sm:max-w-[500px]`,children:[(0,$.jsxs)(Ht,{children:[(0,$.jsx)(Be,{children:`Project Commands`}),(0,$.jsx)(Re,{children:`Manage custom commands for this project.`})]}),(0,$.jsx)(`div`,{className:`py-4 flex flex-col gap-4`,children:a?(0,$.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,$.jsxs)(`div`,{className:`grid gap-2`,children:[(0,$.jsx)(ft,{htmlFor:`name`,children:`Command Name`}),(0,$.jsx)(Ie,{id:`name`,value:a.name,onChange:e=>o({...a,name:e.target.value}),placeholder:`e.g. Run Tests`,autoComplete:`off`})]}),(0,$.jsxs)(`div`,{className:`grid gap-2 relative`,children:[(0,$.jsx)(ft,{htmlFor:`commandLine`,children:`Command Line`}),(0,$.jsxs)(`div`,{className:`relative`,children:[(0,$.jsx)(Xi,{ref:v,id:`commandLine`,value:a.commandLine,onChange:e=>o({...a,commandLine:e.target.value}),onKeyDown:w,placeholder:`e.g. npm test`,className:`font-mono text-xs min-h-[100px] resize-none pr-10`}),(0,$.jsx)(ar,{children:(0,$.jsxs)(or,{children:[(0,$.jsx)(sr,{asChild:!0,children:(0,$.jsx)(K,{type:`button`,variant:`ghost`,size:`icon`,className:`absolute right-2 top-2 h-6 w-6 text-muted-foreground transition-colors`,onClick:()=>void S(),disabled:g,children:(0,$.jsx)(Ne,{className:`h-4 w-4`})})}),(0,$.jsx)(Y,{children:(0,$.jsx)(`p`,{children:`Discover package scripts`})})]})})]}),l&&(0,$.jsx)(`div`,{ref:y,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,$.jsxs)(`div`,{className:`p-2`,children:[(0,$.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,$.jsx)(Ne,{className:`h-3 w-3`}),`Available Scripts `,g&&`(loading...)`]}),f.length>0?(()=>{let e={};f.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,$.jsxs)(`div`,{children:[(0,$.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===m;return n++,(0,$.jsxs)(`button`,{type:`button`,className:q(`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:()=>C(e),onMouseEnter:()=>h(n-1),children:[(0,$.jsx)(`span`,{className:`font-medium`,children:e.name}),(0,$.jsx)(`span`,{className:`text-xs text-muted-foreground font-mono`,children:e.commandLine})]},e.commandLine)})]},t)})})():(0,$.jsx)(`div`,{className:`px-3 py-4 text-center text-xs text-muted-foreground`,children:g?`Loading scripts...`:`No package scripts found`})]})})]}),(0,$.jsxs)(`div`,{className:`grid gap-2`,children:[(0,$.jsx)(ft,{htmlFor:`relativeFolder`,children:`Relative Folder`}),(0,$.jsx)(Ie,{id:`relativeFolder`,value:a.relativeFolder??``,onChange:e=>o({...a,relativeFolder:e.target.value}),placeholder:`e.g. frontend, packages/api (optional)`,autoComplete:`off`}),(0,$.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,$.jsxs)(`div`,{className:`grid gap-2`,children:[(0,$.jsx)(ft,{children:`Icon`}),(0,$.jsx)(`div`,{className:`grid grid-cols-10 gap-1 p-2 bg-background rounded-md border border-border`,children:Ra.map(e=>{let t=xt[e]||_t;return(0,$.jsx)(K,{variant:a.icon===e?`default`:`ghost`,size:`icon`,className:`h-8 w-8`,onClick:()=>o({...a,icon:e}),title:e,children:(0,$.jsx)(t,{className:`h-4 w-4`})},e)})})]}),(0,$.jsxs)(`div`,{className:`flex justify-end gap-2 mt-2`,children:[(0,$.jsxs)(K,{variant:`ghost`,size:`sm`,onClick:()=>o(null),children:[(0,$.jsx)(ot,{className:`h-4 w-4 mr-2`}),` Cancel`]}),(0,$.jsxs)(K,{size:`sm`,onClick:async()=>{if(!a?.name||!a?.commandLine){X({title:`Error`,description:`Name and Command Line are required`,variant:`destructive`});return}try{c(!0),await se(n,a),X({title:`Success`,description:`Command saved`}),o(null),i()}catch{X({title:`Error`,description:`Failed to save command`,variant:`destructive`})}finally{c(!1)}},disabled:s,children:[(0,$.jsx)(Qt,{className:`h-4 w-4 mr-2`}),` `,s?`Saving...`:`Save Command`]})]})]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`flex flex-col gap-2 max-h-[400px] overflow-y-auto pr-2`,children:[r.length===0&&(0,$.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,$.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:()=>x(e),children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,$.jsx)(`div`,{className:`p-2 bg-muted rounded`,children:(0,$.jsx)(xt[e.icon]||d,{className:`h-4 w-4`})}),(0,$.jsxs)(`div`,{className:`flex flex-col`,children:[(0,$.jsx)(`span`,{className:`text-sm font-medium`,children:e.name}),(0,$.jsx)(`span`,{className:`text-xs text-muted-foreground line-clamp-1 font-mono`,children:e.commandLine})]})]}),(0,$.jsx)(`div`,{className:`flex items-center gap-1 opacity-0 group-hover:opacity-100 transition-opacity`,children:(0,$.jsx)(K,{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(),T(e.id)},children:(0,$.jsx)(Ut,{className:`h-4 w-4`})})})]},e.id))]}),(0,$.jsxs)(K,{variant:`outline`,className:`w-full border-dashed`,onClick:b,children:[(0,$.jsx)(G,{className:`h-4 w-4 mr-2`}),` Add New Command`]})]})})]})})}function Ba(){let e=(0,Z.c)(27),{state:t}=qn(),{selectedProjectId:n,selectedThreadId:r,projects:i}=t,{dispatch:a}=er(r),[o,s]=(0,Q.useState)(!1),c,l,u,f,p;if(e[0]!==a||e[1]!==i||e[2]!==n||e[3]!==r||e[4]!==t.isRunningCommand){p=Symbol.for(`react.early_return_sentinel`);bb0:{let o;e[10]===n?o=e[11]:(o=e=>e.projectId===n,e[10]=n,e[11]=o),c=i.find(o)?.commands??[];let m;e[12]!==a||e[13]!==n||e[14]!==r?(m=e=>{!n||!r||a({type:J.QueueTerminalCommand,threadId:r,command:e.commandLine,relativeFolder:e.relativeFolder})},e[12]=a,e[13]=n,e[14]=r,e[15]=m):m=e[15];let h=m,g;if(e[16]===a?g=e[17]:(g=async()=>{a({type:J.ConfigUpdated})},e[16]=a,e[17]=g),l=g,!n){p=null;break bb0}u=`flex items-center gap-1 mr-2`,f=c.length===0?(0,$.jsx)(ar,{children:(0,$.jsxs)(or,{children:[(0,$.jsx)(sr,{asChild:!0,children:(0,$.jsx)(K,{variant:`action`,size:`icon-md`,onClick:()=>s(!0),children:(0,$.jsx)(Kt,{})})}),(0,$.jsx)(Y,{children:`Manage commands`})]})}):(0,$.jsx)($.Fragment,{children:(0,$.jsxs)(ar,{children:[c.map(e=>{let n=xt[e.icon]||d;return(0,$.jsxs)(or,{children:[(0,$.jsx)(sr,{asChild:!0,children:(0,$.jsx)(K,{variant:`action`,size:`icon-md`,onClick:()=>h({commandLine:e.commandLine,relativeFolder:e.relativeFolder}),disabled:t.isRunningCommand,children:(0,$.jsx)(n,{})})}),(0,$.jsx)(Y,{children:(0,$.jsxs)(`div`,{className:`flex flex-col gap-0.5`,children:[(0,$.jsx)(`span`,{className:`font-medium`,children:e.name}),(0,$.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,$.jsxs)(or,{children:[(0,$.jsx)(sr,{asChild:!0,children:(0,$.jsx)(K,{variant:`action`,size:`icon-md`,className:`ml-1`,onClick:()=>s(!0),children:(0,$.jsx)(Kt,{})})}),(0,$.jsx)(Y,{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]=f,e[9]=p}else c=e[5],l=e[6],u=e[7],f=e[8],p=e[9];if(p!==Symbol.for(`react.early_return_sentinel`))return p;let m;e[18]!==c||e[19]!==l||e[20]!==n||e[21]!==o?(m=(0,$.jsx)(za,{open:o,onOpenChange:s,projectId:n,commands:c,onRefresh:l}),e[18]=c,e[19]=l,e[20]=n,e[21]=o,e[22]=m):m=e[22];let h;return e[23]!==u||e[24]!==f||e[25]!==m?(h=(0,$.jsxs)(`div`,{className:u,children:[f,m]}),e[23]=u,e[24]=f,e[25]=m,e[26]=h):h=e[26],h}function Va({projectId:e,runCommand:t}){let{state:n}=qn(),{selectedThreadId:r}=n,{dispatch:i}=er(r),[a,o]=(0,Q.useState)(!1),[c,l]=(0,Q.useState)(!1);(0,Q.useEffect)(()=>{(async()=>{try{o((await s(e)).isRunning)}catch{o(!1)}})()},[e]);let u=async()=>{if(!t)return;l(!0),i({type:J.ClearTerminalOutput}),i({type:J.SetTerminalOpen,open:!1}),i({type:J.AppendTerminalLine,line:{type:`system`,content:`Starting dev server: ${t}`}});let n=!1,a=setTimeout(()=>{n=!0,i({type:J.SetTerminalOpen,open:!0})},3e3);try{console.log(`Starting dev server for project:`,e,`thread:`,r);let t=await ye(e,r??void 0);if(!t){clearTimeout(a),X({title:`Error`,description:`Failed to start dev server`,variant:`destructive`}),i({type:J.AppendTerminalLine,line:{type:`error`,content:`Failed to start dev server`}}),l(!1);return}let s=t.getReader(),c=new TextDecoder;o(!0);let u=!1,d=!1,f=null;for(f=setTimeout(()=>{d||l(!1)},3e3);;){let{done:e,value:t}=await s.read();if(e)break;let r=c.decode(t,{stream:!0});try{let e=r.split(`
|
|
14
|
-
`).filter(e=>e.trim());for(let t of e)try{let e=JSON.parse(t);d||(d=!0,l(!1),f&&clearTimeout(f)),(e.type===`stdout`||e.type===`stderr`)&&i({type:J.AppendTerminalLine,line:{type:`output`,content:e.content}}),e.type===`url`&&e.url&&(clearTimeout(a),i({type:J.AppendTerminalLine,line:{type:`system`,content:`✓ Server running at: ${e.url}`}}),console.log(`Opening URL: ${e.url}`),window.open(e.url),n&&setTimeout(()=>{i({type:J.SetTerminalOpen,open:!1})},100),X({title:`Dev server started`,description:`Server running at ${e.url}`}),u=!0),e.type===`error`&&e.content&&i({type:J.AppendTerminalLine,line:{type:`error`,content:e.content}})}catch{r.trim()&&i({type:J.AppendTerminalLine,line:{type:`output`,content:r}})}}catch{r.trim()&&i({type:J.AppendTerminalLine,line:{type:`output`,content:r}})}}clearTimeout(a),f&&clearTimeout(f),l(!1),u||(i({type:J.AppendTerminalLine,line:{type:`system`,content:`Server is running but URL could not be detected`}}),X({title:`Dev server started`,description:`Server is running but URL could not be detected`}))}catch(e){clearTimeout(a),o(!1),l(!1);let t=e instanceof Error?e.message:`Failed to start dev server`;i({type:J.AppendTerminalLine,line:{type:`error`,content:t}}),X({title:`Error`,description:t,variant:`destructive`})}},f=async()=>{l(!0);try{await M(e),o(!1),i({type:J.AppendTerminalLine,line:{type:`system`,content:`Server stopped`}})}catch(e){let t=e instanceof Error?e.message:`Failed to stop dev server`;i({type:J.AppendTerminalLine,line:{type:`error`,content:t}}),X({title:`Error`,description:t,variant:`destructive`})}finally{l(!1)}},p=!!t;return(0,$.jsx)($.Fragment,{children:(0,$.jsx)(ar,{children:(0,$.jsxs)(or,{children:[(0,$.jsx)(sr,{asChild:!0,children:(0,$.jsxs)(K,{variant:`ghost`,size:`icon`,className:`h-8 w-8 ${a?`text-orange-500 bg-orange-500/10`:`text-muted-foreground`}`,onClick:a?f:u,disabled:c||!a&&!p,children:[c?(0,$.jsx)(P,{className:`h-4 w-4 animate-spin`}):a?(0,$.jsx)(vt,{className:`h-4 w-4 fill-current`}):(0,$.jsx)(d,{className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:`sr-only`,children:a?`Stop dev server`:`Start dev server`})]})}),(0,$.jsx)(Y,{children:a?`Stop dev server`:p?`Start dev server: ${t}`:`Set run command in project settings`})]})})})}function Ha(){let e=(0,Z.c)(10),{state:t}=qn(),{selectedThreadId:n}=t,{terminalState:r,dispatch:i}=er(n),{open:a}=r,o=`${a?`text-primary`:`text-muted-foreground`} hover:text-background`,s;e[0]===i?s=e[1]:(s=()=>i({type:J.ToggleTerminal}),e[0]=i,e[1]=s);let c,l;e[2]===Symbol.for(`react.memo_cache_sentinel`)?(c=(0,$.jsx)(Ve,{}),l=(0,$.jsx)(`span`,{className:`sr-only`,children:`Toggle terminal`}),e[2]=c,e[3]=l):(c=e[2],l=e[3]);let u;e[4]!==o||e[5]!==s?(u=(0,$.jsx)(sr,{asChild:!0,children:(0,$.jsxs)(K,{variant:`ghost`,size:`icon-md`,className:o,onClick:s,children:[c,l]})}),e[4]=o,e[5]=s,e[6]=u):u=e[6];let d;e[7]===Symbol.for(`react.memo_cache_sentinel`)?(d=(0,$.jsx)(Y,{children:`Show Terminal`}),e[7]=d):d=e[7];let f;return e[8]===u?f=e[9]:(f=(0,$.jsx)(ar,{children:(0,$.jsxs)(or,{children:[u,d]})}),e[8]=u,e[9]=f),f}function Ua(){let e=(0,Z.c)(11),t=En(),n=Dn().pathname===`/review`,r=`${n?`text-primary`:`text-muted-foreground`} hover:text-background`,i;e[0]!==n||e[1]!==t?(i=()=>void t(n?`/`:`/review`),e[0]=n,e[1]=t,e[2]=i):i=e[2];let a,o;e[3]===Symbol.for(`react.memo_cache_sentinel`)?(a=(0,$.jsx)(j,{}),o=(0,$.jsx)(`span`,{className:`sr-only`,children:`Review changes`}),e[3]=a,e[4]=o):(a=e[3],o=e[4]);let s;e[5]!==r||e[6]!==i?(s=(0,$.jsx)(sr,{asChild:!0,children:(0,$.jsxs)(K,{variant:`ghost`,size:`icon-md`,className:r,onClick:i,children:[a,o]})}),e[5]=r,e[6]=i,e[7]=s):s=e[7];let c;e[8]===Symbol.for(`react.memo_cache_sentinel`)?(c=(0,$.jsx)(Y,{children:`Review Changes`}),e[8]=c):c=e[8];let l;return e[9]===s?l=e[10]:(l=(0,$.jsx)(ar,{children:(0,$.jsxs)(or,{children:[s,c]})}),e[9]=s,e[10]=l),l}function Wa(e){let t=(0,Z.c)(3),{children:n,className:r}=e,i=`flex items-center gap-2 rounded-full shadow-md ${r===void 0?``:r}`,a;return t[0]!==n||t[1]!==i?(a=(0,$.jsx)(`div`,{className:i,children:n}),t[0]=n,t[1]=i,t[2]=a):a=t[2],a}function Ga(){let e=(0,Z.c)(48),{state:t,dispatch:n}=qn(),r=En(),{selectedThreadId:i,selectedProjectId:a,projects:o,sidebarOpen:s}=t,c;if(e[0]!==o||e[1]!==a){let t;e[3]===a?t=e[4]:(t=e=>e.projectId===a,e[3]=a,e[4]=t),c=o.find(t),e[0]=o,e[1]=a,e[2]=c}else c=e[2];let u=c,d=!s,f=d&&`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`,p;e[5]===f?p=e[6]:(p=q(f),e[5]=f,e[6]=p);let m;e[7]===n?m=e[8]:(m=()=>n({type:J.ToggleSidebar}),e[7]=n,e[8]=m);let g;e[9]===s?g=e[10]:(g=s?(0,$.jsx)(h,{className:`h-4 w-4`}):(0,$.jsx)(_,{className:`h-4 w-4`}),e[9]=s,e[10]=g);let v;e[11]===Symbol.for(`react.memo_cache_sentinel`)?(v=(0,$.jsx)(`span`,{className:`sr-only`,children:`Toggle sidebar`}),e[11]=v):v=e[11];let y;e[12]!==m||e[13]!==g?(y=(0,$.jsxs)(K,{variant:`ghost`,size:`icon`,className:`h-8 w-8 text-muted-foreground shrink-0`,onClick:m,children:[g,v]}),e[12]=m,e[13]=g,e[14]=y):y=e[14];let b;e[15]!==o||e[16]!==a||e[17]!==i?(b=i&&(0,$.jsxs)(`div`,{className:`flex flex-col`,children:[(0,$.jsx)(`span`,{className:`text-sm font-medium text-foreground`,children:Ge(o,a)}),(0,$.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:zt(o,i)})]}),e[15]=o,e[16]=a,e[17]=i,e[18]=b):b=e[18];let x;e[19]!==y||e[20]!==b?(x=(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[y,b]}),e[19]=y,e[20]=b,e[21]=x):x=e[21];let S=d?`ml-0`:`ml-auto`,C;e[22]===S?C=e[23]:(C=q(`flex flex-wrap items-center justify-end gap-2`,S,`md:ml-auto`),e[22]=S,e[23]=C);let w;e[24]!==u?.runCommand||e[25]!==a||e[26]!==i?(w=a&&(0,$.jsxs)(Wa,{children:[i&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Ua,{}),(0,$.jsx)(Ha,{})]}),(0,$.jsx)(Va,{projectId:a,runCommand:u?.runCommand}),i&&(0,$.jsx)($.Fragment,{children:(0,$.jsx)(Ba,{})})]}),e[24]=u?.runCommand,e[25]=a,e[26]=i,e[27]=w):w=e[27];let T;e[28]!==a||e[29]!==i?(T=i&&a&&(0,$.jsx)(Wa,{children:(0,$.jsx)(La,{projectId:a,threadId:i})}),e[28]=a,e[29]=i,e[30]=T):T=e[30];let E;e[31]!==r||e[32]!==a?(E=a&&(0,$.jsx)(Wa,{children:(0,$.jsx)(ar,{children:(0,$.jsxs)(or,{children:[(0,$.jsx)(sr,{asChild:!0,children:(0,$.jsxs)(K,{variant:`ghost`,size:`icon`,className:`h-8 w-8 text-muted-foreground`,onClick:()=>void r(`/todos`),children:[(0,$.jsx)(l,{className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:`sr-only`,children:`Project Tarks`})]})}),(0,$.jsx)(Y,{children:`Project Tarsks`})]})})}),e[31]=r,e[32]=a,e[33]=E):E=e[33];let D;e[34]!==u?.openWith||e[35]!==a||e[36]!==i?(D=i&&a&&(0,$.jsx)(Wa,{children:(0,$.jsx)(xa,{projectId:a,threadId:i,openWith:u?.openWith})}),e[34]=u?.openWith,e[35]=a,e[36]=i,e[37]=D):D=e[37];let O;e[38]!==C||e[39]!==w||e[40]!==T||e[41]!==E||e[42]!==D?(O=(0,$.jsxs)(`div`,{className:C,children:[w,T,E,D]}),e[38]=C,e[39]=w,e[40]=T,e[41]=E,e[42]=D,e[43]=O):O=e[43];let k;return e[44]!==O||e[45]!==p||e[46]!==x?(k=(0,$.jsxs)(qi,{className:p,children:[x,O]}),e[44]=O,e[45]=p,e[46]=x,e[47]=k):k=e[47],k}var Ka=Un,qa=ln,Ja=Q.forwardRef((e,t)=>{let n=(0,Z.c)(9),r,i;n[0]===e?(r=n[1],i=n[2]):({className:r,...i}=e,n[0]=e,n[1]=r,n[2]=i);let a;n[3]===r?a=n[4]:(a=q(`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,$.jsx)(xn,{className:a,...i,ref:t}),n[5]=i,n[6]=t,n[7]=a,n[8]=o):o=n[8],o});Ja.displayName=xn.displayName;var Ya=Q.forwardRef((e,t)=>{let n=(0,Z.c)(10),r,i;n[0]===e?(r=n[1],i=n[2]):({className:r,...i}=e,n[0]=e,n[1]=r,n[2]=i);let a;n[3]===Symbol.for(`react.memo_cache_sentinel`)?(a=(0,$.jsx)(Ja,{}),n[3]=a):a=n[3];let o;n[4]===r?o=n[5]:(o=q(`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,$.jsxs)(qa,{children:[a,(0,$.jsx)(kn,{ref:t,className:o,...i})]}),n[6]=i,n[7]=t,n[8]=o,n[9]=s):s=n[9],s});Ya.displayName=kn.displayName;var Xa=e=>{let t=(0,Z.c)(8),n,r;t[0]===e?(n=t[1],r=t[2]):({className:n,...r}=e,t[0]=e,t[1]=n,t[2]=r);let i;t[3]===n?i=t[4]:(i=q(`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,$.jsx)(`div`,{className:i,...r}),t[5]=r,t[6]=i,t[7]=a):a=t[7],a};Xa.displayName=`AlertDialogHeader`;var Za=e=>{let t=(0,Z.c)(8),n,r;t[0]===e?(n=t[1],r=t[2]):({className:n,...r}=e,t[0]=e,t[1]=n,t[2]=r);let i;t[3]===n?i=t[4]:(i=q(`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,$.jsx)(`div`,{className:i,...r}),t[5]=r,t[6]=i,t[7]=a):a=t[7],a};Za.displayName=`AlertDialogFooter`;var Qa=Q.forwardRef((e,t)=>{let n=(0,Z.c)(9),r,i;n[0]===e?(r=n[1],i=n[2]):({className:r,...i}=e,n[0]=e,n[1]=r,n[2]=i);let a;n[3]===r?a=n[4]:(a=q(`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,$.jsx)(Sn,{ref:t,className:a,...i}),n[5]=i,n[6]=t,n[7]=a,n[8]=o):o=n[8],o});Qa.displayName=Sn.displayName;var $a=Q.forwardRef((e,t)=>{let n=(0,Z.c)(9),r,i;n[0]===e?(r=n[1],i=n[2]):({className:r,...i}=e,n[0]=e,n[1]=r,n[2]=i);let a;n[3]===r?a=n[4]:(a=q(`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,$.jsx)(Wn,{ref:t,className:a,...i}),n[5]=i,n[6]=t,n[7]=a,n[8]=o):o=n[8],o});$a.displayName=Wn.displayName;var eo=Q.forwardRef((e,t)=>{let n=(0,Z.c)(9),r,i;n[0]===e?(r=n[1],i=n[2]):({className:r,...i}=e,n[0]=e,n[1]=r,n[2]=i);let a;n[3]===r?a=n[4]:(a=q(b(),r),n[3]=r,n[4]=a);let o;return n[5]!==i||n[6]!==t||n[7]!==a?(o=(0,$.jsx)(Hn,{ref:t,className:a,...i}),n[5]=i,n[6]=t,n[7]=a,n[8]=o):o=n[8],o});eo.displayName=Hn.displayName;var to=Q.forwardRef((e,t)=>{let n=(0,Z.c)(9),r,i;n[0]===e?(r=n[1],i=n[2]):({className:r,...i}=e,n[0]=e,n[1]=r,n[2]=i);let a;n[3]===r?a=n[4]:(a=q(b({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,$.jsx)(Gn,{ref:t,className:a,...i}),n[5]=i,n[6]=t,n[7]=a,n[8]=o):o=n[8],o});to.displayName=Gn.displayName;function no(e){let t=(0,Z.c)(13),{open:n,projectName:r,onOpenChange:i,onConfirm:a}=e,o;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(o=(0,$.jsx)(Qa,{children:`Delete Project`}),t[0]=o):o=t[0];let s;t[1]===r?s=t[2]:(s=(0,$.jsxs)(Xa,{children:[o,(0,$.jsxs)($a,{children:[`Are you sure you want to delete`,` `,(0,$.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,$.jsx)(to,{children:`Cancel`}),t[3]=c):c=t[3];let l;t[4]===a?l=t[5]:(l=(0,$.jsxs)(Za,{children:[c,(0,$.jsx)(eo,{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,$.jsxs)(Ya,{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,$.jsx)(Ka,{open:n,onOpenChange:i,children:u}),t[9]=i,t[10]=n,t[11]=u,t[12]=d):d=t[12],d}function ro(e){let t=(0,Z.c)(28),{open:n,setupScripts:r,onConfirm:i}=e;if(r.length===0)return null;let a;t[0]===i?a=t[1]:(a=e=>{e||i(!1)},t[0]=i,t[1]=a);let o;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(o=(0,$.jsx)(Qa,{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,$.jsxs)(Xa,{children:[o,(0,$.jsxs)($a,{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(io),t[6]=r,t[7]=l);let u;t[8]===l?u=t[9]:(u=(0,$.jsx)(`div`,{className:`my-4 max-h-60 overflow-y-auto`,children:(0,$.jsx)(`div`,{className:`space-y-2`,children:l})}),t[8]=l,t[9]=u);let d;t[10]===i?d=t[11]:(d=(0,$.jsx)(to,{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,$.jsxs)(eo,{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,$.jsxs)(Za,{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,$.jsxs)(Ya,{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,$.jsx)(Ka,{open:n,onOpenChange:a,children:h}),t[24]=n,t[25]=a,t[26]=h,t[27]=g):g=t[27],g}function io(e,t){let n=e.match(/^cd "([^"]+)" && (.+)$/),r=n?n[1]:`root`,i=n?n[2]:e;return(0,$.jsx)(`div`,{className:`flex items-center justify-between p-3 rounded-lg border bg-muted/50`,children:(0,$.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,$.jsx)(`div`,{className:`w-2 h-2 rounded-full bg-blue-500`}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`div`,{className:`font-medium text-sm`,children:r||`root`}),(0,$.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:i})]})]})},t)}function ao(){let e=(0,Z.c)(6),[t,n]=(0,Q.useState)(!0),r,i;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(r=()=>{let e=!0;return(async()=>{try{let t=await fetch(`${ke()}/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,Q.useEffect)(r,i);let a=oo;if(t)return null;let o;e[2]===Symbol.for(`react.memo_cache_sentinel`)?(o=ke(),e[2]=o):o=e[2];let s=o,c,l;e[3]===Symbol.for(`react.memo_cache_sentinel`)?(c=(0,$.jsxs)(Xa,{children:[(0,$.jsx)(Qa,{children:`Service unavailable`}),(0,$.jsx)($a,{children:`Service is not currently up. Please ensure the backend is running at the address below, then retry.`})]}),l=(0,$.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,$.jsx)(Ka,{open:!0,children:(0,$.jsxs)(Ya,{children:[c,l,(0,$.jsx)(Za,{children:(0,$.jsx)(K,{onClick:a,children:`Retry`})})]})}),e[5]=u):u=e[5],u}function oo(){window.location.assign(window.location.href)}var so=e=>{let t=(0,Z.c)(8),n,r;t[0]===e?(n=t[1],r=t[2]):({className:n,...r}=e,t[0]=e,t[1]=n,t[2]=r);let i;t[3]===n?i=t[4]:(i=q(`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,$.jsx)(Pn,{className:i,...r}),t[5]=r,t[6]=i,t[7]=a):a=t[7],a},co=Fn,lo=e=>{let t=(0,Z.c)(12),n,r,i;t[0]===e?(n=t[1],r=t[2],i=t[3]):({withHandle:i,className:n,...r}=e,t[0]=e,t[1]=n,t[2]=r,t[3]=i);let a;t[4]===n?a=t[5]:(a=q(`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,$.jsx)(`div`,{className:`hidden z-10 flex h-4 w-3 items-center justify-center rounded-sm border bg-border`,children:(0,$.jsx)(he,{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,$.jsx)(On,{className:a,...r,children:o}),t[8]=r,t[9]=a,t[10]=o,t[11]=s):s=t[11],s},uo=jn,fo=Q.forwardRef((e,t)=>{let n=(0,Z.c)(9),r,i;n[0]===e?(r=n[1],i=n[2]):({className:r,...i}=e,n[0]=e,n[1]=r,n[2]=i);let a;n[3]===r?a=n[4]:(a=q(`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,$.jsx)(Rn,{ref:t,className:a,...i}),n[5]=i,n[6]=t,n[7]=a,n[8]=o):o=n[8],o});fo.displayName=Rn.displayName;var po=A(`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`}}),mo=Q.forwardRef((e,t)=>{let n=(0,Z.c)(11),r,i,a;n[0]===e?(r=n[1],i=n[2],a=n[3]):({className:r,variant:a,...i}=e,n[0]=e,n[1]=r,n[2]=i,n[3]=a);let o;n[4]!==r||n[5]!==a?(o=q(po({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,$.jsx)(Nn,{ref:t,className:o,...i}),n[7]=i,n[8]=t,n[9]=o,n[10]=s):s=n[10],s});mo.displayName=Nn.displayName;var ho=Q.forwardRef((e,t)=>{let n=(0,Z.c)(9),r,i;n[0]===e?(r=n[1],i=n[2]):({className:r,...i}=e,n[0]=e,n[1]=r,n[2]=i);let a;n[3]===r?a=n[4]:(a=q(`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,$.jsx)(An,{ref:t,className:a,...i}),n[5]=i,n[6]=t,n[7]=a,n[8]=o):o=n[8],o});ho.displayName=An.displayName;var go=Q.forwardRef((e,t)=>{let n=(0,Z.c)(10),r,i;n[0]===e?(r=n[1],i=n[2]):({className:r,...i}=e,n[0]=e,n[1]=r,n[2]=i);let a;n[3]===r?a=n[4]:(a=q(`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,$.jsx)(ot,{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,$.jsx)(Ln,{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});go.displayName=Ln.displayName;var _o=Q.forwardRef((e,t)=>{let n=(0,Z.c)(9),r,i;n[0]===e?(r=n[1],i=n[2]):({className:r,...i}=e,n[0]=e,n[1]=r,n[2]=i);let a;n[3]===r?a=n[4]:(a=q(`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,$.jsx)(zn,{ref:t,className:a,...i}),n[5]=i,n[6]=t,n[7]=a,n[8]=o):o=n[8],o});_o.displayName=zn.displayName;var vo=Q.forwardRef((e,t)=>{let n=(0,Z.c)(9),r,i;n[0]===e?(r=n[1],i=n[2]):({className:r,...i}=e,n[0]=e,n[1]=r,n[2]=i);let a;n[3]===r?a=n[4]:(a=q(`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,$.jsx)(Vn,{ref:t,className:a,...i}),n[5]=i,n[6]=t,n[7]=a,n[8]=o):o=n[8],o});vo.displayName=Vn.displayName;function yo(){let e=(0,Z.c)(5),{toasts:t}=fr(),n;e[0]===t?n=e[1]:(n=t.map(bo),e[0]=t,e[1]=n);let r;e[2]===Symbol.for(`react.memo_cache_sentinel`)?(r=(0,$.jsx)(fo,{}),e[2]=r):r=e[2];let i;return e[3]===n?i=e[4]:(i=(0,$.jsxs)(uo,{children:[n,r]}),e[3]=n,e[4]=i),i}function bo(e){let{id:t,title:n,description:r,action:i,...a}=e;return(0,$.jsxs)(mo,{...a,children:[(0,$.jsxs)(`div`,{className:`grid gap-1`,children:[n&&(0,$.jsx)(_o,{children:n}),r&&(0,$.jsx)(vo,{children:r})]}),i,(0,$.jsx)(go,{})]},t)}function xo(){let e=(0,Z.c)(4),{resolvedTheme:t,theme:n}=cr(),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,Q.useEffect)(r,i),null}function So(e){let t=(0,Z.c)(7),n,r;t[0]===e?(n=t[1],r=t[2]):({children:n,...r}=e,t[0]=e,t[1]=n,t[2]=r);let i;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(i=(0,$.jsx)(xo,{}),t[3]=i):i=t[3];let a;return t[4]!==n||t[5]!==r?(a=(0,$.jsxs)(lr,{...r,children:[i,n]}),t[4]=n,t[5]=r,t[6]=a):a=t[6],a}function Co(){let{state:e,dispatch:t}=qn(),{toast:n}=fr(),a=er(`project-creation`).dispatch,[o,s]=(0,Q.useState)(null),c=(0,Q.useCallback)(async()=>{try{t({type:J.SetProjectsLoading,projectsLoading:!0});let e=await Ye();t({type:J.SetProjects,projects:e.projects})}catch(e){console.error(`Failed to refresh projects:`,e)}finally{t({type:J.SetProjectsLoading,projectsLoading:!1})}},[t]),l=(0,Q.useCallback)(async(n,r)=>{try{await w(n,r)}catch(e){console.error(`Failed to select thread:`,e)}(e.selectedThreadId!==r||e.selectedProjectId!==n)&&t({type:J.SelectThread,threadId:r,projectId:n})},[t,e.selectedThreadId,e.selectedProjectId]),u=(0,Q.useCallback)(async e=>{t({type:J.SetCreatingProject,isCreating:!0});try{let n=await e.apiCall();if(!n){t({type:J.SetCreatingProject,isCreating:!1}),await c();return}let r=e.useTerminalDispatch?a:t;r({type:J.ClearTerminalOutput}),r({type:J.SetTerminalOpen,open:!0}),r({type:J.AppendTerminalLine,line:{type:`system`,content:e.initialMessage}});let i=n.getReader(),o=new TextDecoder,l=``,u=null,d=!1,f=null,p=null;for(;;){let{done:n,value:a}=await i.read();if(n)break;l+=o.decode(a,{stream:!0});let c=l.split(`
|
|
15
|
-
`);l=c.pop()??``;for(let n of c){let i=n.trim();if(i)try{let n=JSON.parse(i);if(n.type===`progress`)!d&&n.threadId&&n.projectId&&(d=!0,f=n.projectId,p=n.threadId,t({type:J.AddCreatingProject,projectId:n.projectId,threadId:n.threadId,projectName:e.optimisticProjectName,gitUrl:e.gitUrl??``}),t({type:J.AddProcessingThread,threadId:n.threadId})),t({type:J.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 i=e.includeThreadPath&&n.project.threads?.length>0?`${n.project.path}/${n.project.threads[0]}`:n.project.path;r({type:J.AppendTerminalLine,line:{type:`system`,content:`Project created successfully at: ${i}`}}),t({type:J.SetTerminalOpen,open:!1}),e.handleSetupScript&&n.suggestedSetupScript&&s({projectId:n.project.id,command:n.suggestedSetupScript,remainingScripts:n.project.pendingSetupScripts??[]})}}else n.type===`error`&&(d&&f&&(t({type:J.RemoveCreatingProject,projectId:f}),p&&t({type:J.RemoveProcessingThread,threadId:p})),t({type:J.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:J.SetCreatingProject,isCreating:!1}),d&&p&&t({type:J.RemoveProcessingThread,threadId:p}),dt();let m=await Ye();if(t({type:J.SetProjects,projects:m.projects}),t({type:J.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:J.SelectThread,threadId:n,projectId:u,focusInput:!0})}}}catch(n){console.error(`Failed to ${e.logTag}:`,n),t({type:J.SetCreatingProject,isCreating:!1}),(e.useTerminalDispatch?a:t)({type:J.AppendTerminalLine,line:{type:`error`,content:`${e.catchErrorPrefix}: ${n instanceof Error?n.message:`Unknown error`}`}})}},[t,c,a]),d=(0,Q.useCallback)(async(e,t)=>{let n=e.split(`/`).pop()?.replace(`.git`,``)??`project`;await u({apiCall:()=>i(e,t),initialMessage:`Cloning repository: ${e}...`,optimisticProjectName:n,gitUrl:e,useTerminalDispatch:!0,includeThreadPath:!0,handleSetupScript:!0,logTag:`create project`,catchErrorPrefix:`Failed to create project`})},[u]),f=(0,Q.useCallback)(async(e,t,n)=>{await u({apiCall:()=>I(e,t,n),initialMessage:`Creating app "${e}"...`,optimisticProjectName:e,useTerminalDispatch:!1,handleSetupScript:!1,logTag:`create web app`,catchErrorPrefix:`Failed to create web app`})},[u]),p=(0,Q.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}`})(),o=await W(r,i);if(!o){await c();return}let s=o.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 s.read();if(e)break;u+=l.decode(i,{stream:!0});let o=u.split(`
|
|
16
|
-
`);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:J.AddCreatingThread,projectId:r,threadId:e.threadId,title:a}),t({type:J.AddProcessingThread,threadId:e.threadId}),t({type:J.ClearTerminalOutput,threadId:f});for(let e of m)t({type:J.AppendTerminalLine,threadId:f,line:e});m.length=0}let n={type:`output`,content:e.message};f?t({type:J.AppendTerminalLine,threadId:f,line:n}):m.push(n)}else if(e.type===`error`){d&&f&&(t({type:J.RemoveCreatingThread,projectId:r,threadId:f}),t({type:J.RemoveProcessingThread,threadId:f}));let i={type:`error`,content:`Error: ${e.message}`};f?t({type:J.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:J.RemoveProcessingThread,threadId:f}),dt(),await c(),f&&p&&t({type:J.SelectThread,threadId:f,projectId:r,focusInput:!0})}catch(e){throw d&&f&&(t({type:J.RemoveCreatingThread,projectId:r,threadId:f}),t({type:J.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:J.AppendTerminalLine,line:{type:`error`,content:r}}),n({variant:`destructive`,title:`Thread Creation Failed`,description:r}),e}},[c,t,e.projects,n]),m=(0,Q.useCallback)(async(n,r)=>{t({type:J.AddDeletingThread,threadId:r});try{await _e(n,r),dt(),await c(),e.selectedThreadId===r&&t({type:J.SelectThread,threadId:``,projectId:``})}catch(e){console.error(`Failed to delete thread:`,e)}finally{t({type:J.RemoveDeletingThread,threadId:r})}},[c,e.selectedThreadId,t]),h=(0,Q.useCallback)(async n=>{t({type:J.AddDeletingProject,projectId:n});let r=e.projects.find(e=>e.projectId===n)?.threads.map(e=>e.threadId)??[];for(let e of r)t({type:J.AddDeletingThread,threadId:e});try{await rn(n),await c(),e.selectedProjectId===n&&t({type:J.SelectThread,threadId:``,projectId:``})}catch(e){console.error(`Failed to delete project:`,e)}finally{t({type:J.RemoveDeletingProject,projectId:n});for(let e of r)t({type:J.RemoveDeletingThread,threadId:e})}},[c,e.selectedProjectId,e.projects,t]),g=(0,Q.useCallback)(async e=>{let n=o;if(s(null),!n||!e)return;let{projectId:i,command:a,remainingScripts:l}=n,u=[a,...l||[]];try{t({type:J.SetCreatingProject,isCreating:!0}),t({type:J.SetTerminalOpen,open:!0}),t({type:J.AppendTerminalLine,line:{type:`system`,content:`Installing dependencies for ${u.length} package${u.length===1?``:`s`}...`}});for(let e=0;e<u.length;e++){let n=u[e],a=n.match(/^cd "([^"]+)" && (.+)$/),o=a?a[1]:`root`;t({type:J.AppendTerminalLine,line:{type:`system`,content:`Installing package ${e+1}/${u.length} in ${o}...`}}),t({type:J.AppendTerminalLine,line:{type:`output`,content:`📦 Installing dependencies in ${o}: ${n}`}});let s=await r(i,n,!0);if(s){let e=s.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(`
|
|
17
|
-
`);r=o.pop()??``;for(let e of o)if(e.trim())try{let n=JSON.parse(e);typeof n==`string`?t({type:J.AppendTerminalLine,line:{type:`output`,content:n}}):n.type===`error`&&t({type:J.AppendTerminalLine,line:{type:`error`,content:n.message}})}catch{t({type:J.AppendTerminalLine,line:{type:`output`,content:e}})}}if(r.trim())try{let e=JSON.parse(r);typeof e==`string`?t({type:J.AppendTerminalLine,line:{type:`output`,content:e}}):e.type===`error`&&t({type:J.AppendTerminalLine,line:{type:`error`,content:e.message}})}catch{t({type:J.AppendTerminalLine,line:{type:`output`,content:r}})}}e<u.length-1&&(t({type:J.AppendTerminalLine,line:{type:`system`,content:``}}),t({type:J.AppendTerminalLine,line:{type:`system`,content:`---`}}),t({type:J.AppendTerminalLine,line:{type:`system`,content:``}}))}t({type:J.AppendTerminalLine,line:{type:`system`,content:`All dependencies installed successfully!`}}),t({type:J.SetCreatingProject,isCreating:!1}),await c()}catch(e){t({type:J.SetCreatingProject,isCreating:!1}),console.error(`Failed to run setup script:`,e),t({type:J.AppendTerminalLine,line:{type:`error`,content:`Failed to run setup script: ${e instanceof Error?e.message:`Unknown error`}`}})}},[o,t,c]);(0,Q.useEffect)(()=>{let n=!0;async function r(){try{t({type:J.SetProjectsLoading,projectsLoading:!0});let r=await Ye();if(!n)return;if(t({type:J.SetProjects,projects:r.projects}),!e.selectedThreadId)for(let e of r.projects){let n=e.threads.find(e=>e.isSelected);if(n){t({type:J.SelectThread,threadId:n.threadId,projectId:e.projectId});break}}}catch(e){console.error(`Failed to load projects:`,e)}finally{n&&t({type:J.SetProjectsLoading,projectsLoading:!1})}}return r(),()=>{n=!1}},[t,e.selectedThreadId,e.configUpdatedAt]);let _=(0,Q.useCallback)(async()=>{await u({apiCall:B,initialMessage:`Opening folder...`,optimisticProjectName:`Opening folder...`,useTerminalDispatch:!0,handleSetupScript:!0,logTag:`open folder`,catchErrorPrefix:`Failed to open folder`})},[u]);return{projects:e.projects,selectedProjectId:e.selectedProjectId,selectedThreadId:e.selectedThreadId,refreshProjects:c,handleSelectThread:l,handleCreateProject:d,handleCreateWebApp:f,handleOpenFolder:_,handleCreateThread:p,handleDeleteThread:m,confirmDeleteProject:h,pendingSetupScriptConfirmation:o,resolveSetupScriptConfirmation:g}}function wo(){let e=(0,Z.c)(2),[t,n]=(0,Q.useState)(To),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,Q.useEffect)(r,i),t}function To(){return document.hasFocus()}var Eo=null;function Do(){Eo??=new Audio(`/pop.wav`),Eo.currentTime=0,Eo.play().catch(e=>{console.debug(`Could not play completion sound:`,e)})}function Oo(){let{state:e,dispatch:t}=qn(),n=wo(),r=(0,Q.useRef)(null),i=(0,Q.useRef)(!1),a=(0,Q.useRef)([]),o=(0,Q.useRef)(e),s=(0,Q.useRef)(n);(0,Q.useEffect)(()=>{o.current=e},[e]),(0,Q.useEffect)(()=>{s.current=n},[n]);let c=(0,Q.useCallback)(async()=>{try{let e=await gt(),n=a.current.filter(t=>!e.includes(t));for(let e of n)e!==o.current.selectedThreadId&&t({type:J.MarkThreadCompleted,threadId:e});return n.length>0&&!s.current&&Do(),a.current=e,t({type:J.SetProcessingThreads,threadIds:e}),e}catch(e){return console.error(`Failed to fetch processing threads:`,e),[]}},[t]);(0,Q.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,Q.useCallback)(e=>{t({type:J.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 ko=768;function Ao(){let e=(0,Z.c)(2),[t,n]=Q.useState(void 0),r,i;return e[0]===Symbol.for(`react.memo_cache_sentinel`)?(r=()=>{let e=window.matchMedia(`(max-width: ${ko-1}px)`),t=()=>{n(window.innerWidth<ko)};return e.addEventListener(`change`,t),n(window.innerWidth<ko),()=>e.removeEventListener(`change`,t)},i=[],e[0]=r,e[1]=i):(r=e[0],i=e[1]),Q.useEffect(r,i),!!t}var jo=(0,Q.lazy)(()=>on(()=>import(`./dialogs-config-DiFQjCeA.js`).then(e=>e.t),__vite__mapDeps([0,1]))),Mo=(0,Q.lazy)(()=>on(()=>import(`./onboarding-dialog-CKJw0ULj.js`),__vite__mapDeps([9,4,1,0,6]))),No=(0,Q.lazy)(()=>on(()=>import(`./conversation-history-view-D0OBxJMC.js`),__vite__mapDeps([10,4,1,0]))),Po=(0,Q.lazy)(()=>on(()=>import(`./settings-view-C45kmAGH.js`),__vite__mapDeps([11,1,3,4,0,5,12,7])));function Fo(){let{state:e,dispatch:n}=qn(),r=En(),i=Dn(),a=Ao(),{projects:o,handleSelectThread:s,handleCreateProject:c,handleCreateWebApp:l,handleOpenFolder:u,handleCreateThread:d,handleDeleteThread:f,confirmDeleteProject:p,refreshProjects:m,pendingSetupScriptConfirmation:h,resolveSetupScriptConfirmation:g}=Co(),{processingThreadIds:_,completedThreadIds:v,clearCompleted:y}=Oo(),[b,x]=(0,Q.useState)(!1),[S,C]=(0,Q.useState)(!1),[w,T]=(0,Q.useState)(!1),[E,D]=(0,Q.useState)(null),[O,k]=(0,Q.useState)(!1),[A,j]=(0,Q.useState)(!1),M=(0,Q.useRef)(null),N=i.pathname.startsWith(`/settings`),P=i.pathname===`/review`,F=i.pathname===`/todos`,I=i.pathname.startsWith(`/history`),L=(()=>{let e=i.pathname.match(/^\/history\/(thread|project)\/(.+)$/);if(e)return{type:e[1],id:e[2]}})(),R=(0,Q.useRef)(null);(0,Q.useEffect)(()=>{let t=N||P||F;if(t&&R.current===null)R.current=e.sidebarOpen,e.sidebarOpen&&n({type:J.ToggleSidebar});else if(!t&&R.current!==null){let t=R.current;R.current=null,t&&!e.sidebarOpen&&n({type:J.ToggleSidebar})}},[N,P,F]),(0,Q.useEffect)(()=>{(async()=>{try{(await de()).updateAvailable&&k(!0)}catch{}})()},[]);let z=(0,Q.useCallback)(async()=>{j(!0);try{await qt()}catch{j(!1)}},[]);(0,Q.useEffect)(()=>{w||(async()=>{try{(await Tt()).onboardingCompleted||C(!0)}catch(e){console.error(`Failed to check onboarding status:`,e)}finally{T(!0)}})()},[w]),(0,Q.useEffect)(()=>{S||n({type:J.ConfigUpdated})},[S,n]);let B=(0,Q.useCallback)(e=>{let n=o.find(t=>t.projectId===e);n&&D({id:n.projectId,name:t(n)})},[o]),V=(0,Q.useCallback)(e=>{d(e,void 0)},[d]),H=(0,Q.useCallback)(e=>{r(`/settings/project/${e}`)},[r]),U=(0,Q.useCallback)(e=>{r(`/history/${e.type}/${e.id}`)},[r]),ee=(0,Q.useCallback)(async(t,o)=>{y(o),i.pathname!==`/`&&r(`/`),await s(t,o),a&&e.sidebarOpen&&n({type:J.ToggleSidebar})},[s,a,e.sidebarOpen,n,y,i.pathname,r]);return(0,Q.useEffect)(()=>{e.sidebarOpen?M.current?.expand():M.current?.collapse()},[e.sidebarOpen]),(0,$.jsxs)(ar,{delayDuration:200,children:[(0,$.jsxs)(so,{direction:`horizontal`,className:`h-screen bg-background`,children:[(0,$.jsx)(co,{ref:M,defaultSize:a?100:25,minSize:a?50:12,maxSize:a?100:32,collapsible:!0,collapsedSize:0,className:`border-r border-transparent`,children:(0,$.jsx)(`div`,{className:`h-full overflow-hidden`,children:(0,$.jsx)(yr,{projects:o,selectedThreadId:e.selectedThreadId,selectedProjectId:e.selectedProjectId,processingThreadIds:_,completedThreadIds:v,deletingThreadIds:e.deletingThreadIds,deletingProjectIds:e.deletingProjectIds,onSelectThread:ee,onCreateProject:()=>x(!0),onCreateThread:V,onDeleteThread:f,onDeleteProject:B,onNavigateToSettings:()=>void r(`/settings`),onProjectSettings:H,onViewHistory:U,updateAvailable:O,updatingApp:A,onUpdateApp:z})})}),!a&&(0,$.jsx)(lo,{withHandle:!0,className:e.sidebarOpen?`ml-[-40px]`:``}),(0,$.jsx)(co,{minSize:40,className:`overflow-hidden ${a&&e.sidebarOpen?`hidden`:``}`,children:(0,$.jsxs)(`div`,{className:`flex h-full flex-col overflow-hidden`,children:[!P&&!N&&!F&&(0,$.jsx)(Ga,{}),(0,$.jsx)(`main`,{className:`flex-1 overflow-hidden`,children:(0,$.jsxs)(hn,{children:[(0,$.jsx)(Bn,{path:`/settings/:tab?`,element:(0,$.jsx)(Q.Suspense,{fallback:null,children:(0,$.jsx)(Po,{})})}),(0,$.jsx)(Bn,{path:`/settings/project/:projectId`,element:(0,$.jsx)(Q.Suspense,{fallback:null,children:(0,$.jsx)(Po,{})})}),(0,$.jsx)(Bn,{path:`/settings/add-skill`,element:(0,$.jsx)(Q.Suspense,{fallback:null,children:(0,$.jsx)(Po,{})})}),(0,$.jsx)(Bn,{path:`/settings/add-command`,element:(0,$.jsx)(Q.Suspense,{fallback:null,children:(0,$.jsx)(Po,{})})}),(0,$.jsx)(Bn,{path:`/settings/mcp-server-edit`,element:(0,$.jsx)(Q.Suspense,{fallback:null,children:(0,$.jsx)(Po,{})})}),(0,$.jsx)(Bn,{path:`*`,element:(0,$.jsx)(aa,{onCreateThread:V})})]})})]})}),(0,$.jsx)(Q.Suspense,{fallback:null,children:(0,$.jsx)(jo,{open:b,onOpenChange:x,onSubmitClone:c,onSubmitWebApp:l,onOpenFolder:u})}),(0,$.jsx)(no,{open:E!==null,projectName:E?.name,onOpenChange:e=>!e&&D(null),onConfirm:()=>{E&&(p(E.id),D(null))}}),(0,$.jsx)(ro,{open:h!==null,setupScripts:h?[h.command,...h.remainingScripts||[]]:[],onConfirm:g}),(0,$.jsx)(Q.Suspense,{fallback:null,children:(0,$.jsx)(Mo,{open:S,onOpenChange:C,onComplete:()=>{T(!0),m()}})}),(0,$.jsx)(ao,{}),(0,$.jsx)(Q.Suspense,{fallback:null,children:(0,$.jsx)(No,{isOpen:I,onClose:()=>void r(`/`),initialFilter:L,projects:o})})]}),(0,$.jsx)(yo,{})]})}function Io(){let e=(0,Z.c)(5),[t,n]=(0,Q.useReducer)(nr,Zn),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,$.jsx)(Fo,{}),e[2]=i):i=e[2];let a;return e[3]===r?a=e[4]:(a=(0,$.jsx)(So,{attribute:`class`,defaultTheme:`system`,enableSystem:!0,storageKey:`tarsk-theme`,children:(0,$.jsx)($n.Provider,{value:r,children:i})}),e[3]=r,e[4]=a),a}var Lo=!1;window.addEventListener(`resize`,()=>{Lo||=(window.__electrobunWebviewId&&(document.body.style.height=`calc(100% - 26px)`),!0)}),(0,pr.createRoot)(document.getElementById(`root`)).render((0,$.jsx)(Q.StrictMode,{children:(0,$.jsx)(gn,{children:(0,$.jsx)(Io,{})})}));export{Ka as a,Ya as c,Xi as d,qi as f,hr as g,_r as h,so as i,$a as l,vr as m,lo as n,eo as o,Gi as p,co as r,to as s,Co as t,Qa as u};
|