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