meshy-node 0.1.10 → 0.2.2

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/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # meshy-node
2
2
 
3
- Version: 0.1.10
3
+ Version: 0.2.2
4
4
 
5
5
  This package contains the built Meshy standalone node runtime only.
6
6
  It intentionally excludes repository source files and TypeScript sources.
@@ -0,0 +1,182 @@
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/FilesTab-BTvBjcVj.js","assets/index-kMP08Pcy.js","assets/index-Dl1FKoUn.css","assets/file-f8EEICoF.js","assets/PreviewTab-K1eOyj6G.js","assets/DiffTab-Cp1x6gu_.js"])))=>i.map(i=>d[i]);
2
+ import{c as z,r as o,j as e,a as A,b as pa,d as ga,e as ba,D as ja,f as ya,g as va,B as ye,h as Na,i as M,X as qe,C as Pe,k as Yt,l as Os,m as We,R as ka,T as wa,n as Us,P as Ca,u as yt,W as Sa,o as _a,p as Ft,q as Aa,s as Ta,t as Bs,O as Ea,v as Da,w as zs,x as Vs,y as Ma,z as Pa,A as $a,F as Ra,E as La,G as le,S as ke,H as we,I as Me,J as Ce,K as je,L as qs,M as Ws,N as Ia,Q as Hs,U as Ie,V as Fe,_ as Xt,Y as Fa,Z as Ks,$ as Js,a0 as Gs,a1 as Oa,a2 as Zt,a3 as Ua,a4 as Ba,a5 as za,a6 as Va,a7 as qa,a8 as Wa,a9 as Ha,aa as Ka,ab as Ja,ac as Ga,ad as Ya,ae as Xa,af as Za,ag as Qa,ah as en,ai as tn,aj as sn,ak as rn,al as an,am as nn,an as on,ao as ln}from"./index-kMP08Pcy.js";/**
3
+ * @license lucide-react v1.7.0 - ISC
4
+ *
5
+ * This source code is licensed under the ISC license.
6
+ * See the LICENSE file in the root directory of this source tree.
7
+ */const dn=[["rect",{width:"20",height:"5",x:"2",y:"3",rx:"1",key:"1wp1u1"}],["path",{d:"M4 8v11a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8",key:"1s80jp"}],["path",{d:"M10 12h4",key:"a56b0p"}]],cn=z("archive",dn);/**
8
+ * @license lucide-react v1.7.0 - ISC
9
+ *
10
+ * This source code is licensed under the ISC license.
11
+ * See the LICENSE file in the root directory of this source tree.
12
+ */const un=[["path",{d:"m5 12 7-7 7 7",key:"hav0vg"}],["path",{d:"M12 19V5",key:"x0mq9r"}]],mn=z("arrow-up",un);/**
13
+ * @license lucide-react v1.7.0 - ISC
14
+ *
15
+ * This source code is licensed under the ISC license.
16
+ * See the LICENSE file in the root directory of this source tree.
17
+ */const xn=[["path",{d:"M12 18V5",key:"adv99a"}],["path",{d:"M15 13a4.17 4.17 0 0 1-3-4 4.17 4.17 0 0 1-3 4",key:"1e3is1"}],["path",{d:"M17.598 6.5A3 3 0 1 0 12 5a3 3 0 1 0-5.598 1.5",key:"1gqd8o"}],["path",{d:"M17.997 5.125a4 4 0 0 1 2.526 5.77",key:"iwvgf7"}],["path",{d:"M18 18a4 4 0 0 0 2-7.464",key:"efp6ie"}],["path",{d:"M19.967 17.483A4 4 0 1 1 12 18a4 4 0 1 1-7.967-.517",key:"1gq6am"}],["path",{d:"M6 18a4 4 0 0 1-2-7.464",key:"k1g0md"}],["path",{d:"M6.003 5.125a4 4 0 0 0-2.526 5.77",key:"q97ue3"}]],hn=z("brain",xn);/**
18
+ * @license lucide-react v1.7.0 - ISC
19
+ *
20
+ * This source code is licensed under the ISC license.
21
+ * See the LICENSE file in the root directory of this source tree.
22
+ */const fn=[["path",{d:"m9 18 6-6-6-6",key:"mthhwq"}]],Ze=z("chevron-right",fn);/**
23
+ * @license lucide-react v1.7.0 - ISC
24
+ *
25
+ * This source code is licensed under the ISC license.
26
+ * See the LICENSE file in the root directory of this source tree.
27
+ */const pn=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M9.09 9a3 3 0 0 1 5.83 1c0 2-3 3-3 3",key:"1u773s"}],["path",{d:"M12 17h.01",key:"p32p05"}]],gn=z("circle-question-mark",pn);/**
28
+ * @license lucide-react v1.7.0 - ISC
29
+ *
30
+ * This source code is licensed under the ISC license.
31
+ * See the LICENSE file in the root directory of this source tree.
32
+ */const bn=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}]],jn=z("circle",bn);/**
33
+ * @license lucide-react v1.7.0 - ISC
34
+ *
35
+ * This source code is licensed under the ISC license.
36
+ * See the LICENSE file in the root directory of this source tree.
37
+ */const yn=[["rect",{width:"14",height:"14",x:"8",y:"8",rx:"2",ry:"2",key:"17jyea"}],["path",{d:"M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2",key:"zix9uf"}]],vt=z("copy",yn);/**
38
+ * @license lucide-react v1.7.0 - ISC
39
+ *
40
+ * This source code is licensed under the ISC license.
41
+ * See the LICENSE file in the root directory of this source tree.
42
+ */const vn=[["path",{d:"M4 22V4a1 1 0 0 1 .4-.8A6 6 0 0 1 8 2c3 0 5 2 7.333 2q2 0 3.067-.8A1 1 0 0 1 20 4v10a1 1 0 0 1-.4.8A6 6 0 0 1 16 16c-3 0-5-2-8-2a6 6 0 0 0-4 1.528",key:"1jaruq"}]],Nn=z("flag",vn);/**
43
+ * @license lucide-react v1.7.0 - ISC
44
+ *
45
+ * This source code is licensed under the ISC license.
46
+ * See the LICENSE file in the root directory of this source tree.
47
+ */const kn=[["path",{d:"M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z",key:"1kt360"}]],wn=z("folder",kn);/**
48
+ * @license lucide-react v1.7.0 - ISC
49
+ *
50
+ * This source code is licensed under the ISC license.
51
+ * See the LICENSE file in the root directory of this source tree.
52
+ */const Cn=[["path",{d:"M10 20a1 1 0 0 0 .553.895l2 1A1 1 0 0 0 14 21v-7a2 2 0 0 1 .517-1.341L21.74 4.67A1 1 0 0 0 21 3H3a1 1 0 0 0-.742 1.67l7.225 7.989A2 2 0 0 1 10 14z",key:"sc7q7i"}]],Sn=z("funnel",Cn);/**
53
+ * @license lucide-react v1.7.0 - ISC
54
+ *
55
+ * This source code is licensed under the ISC license.
56
+ * See the LICENSE file in the root directory of this source tree.
57
+ */const _n=[["path",{d:"M15 6a9 9 0 0 0-9 9V3",key:"1cii5b"}],["circle",{cx:"18",cy:"6",r:"3",key:"1h7g24"}],["circle",{cx:"6",cy:"18",r:"3",key:"fqmcym"}]],ys=z("git-branch",_n);/**
58
+ * @license lucide-react v1.7.0 - ISC
59
+ *
60
+ * This source code is licensed under the ISC license.
61
+ * See the LICENSE file in the root directory of this source tree.
62
+ */const An=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M12 2a14.5 14.5 0 0 0 0 20 14.5 14.5 0 0 0 0-20",key:"13o1zl"}],["path",{d:"M2 12h20",key:"9i4pu4"}]],Tn=z("globe",An);/**
63
+ * @license lucide-react v1.7.0 - ISC
64
+ *
65
+ * This source code is licensed under the ISC license.
66
+ * See the LICENSE file in the root directory of this source tree.
67
+ */const En=[["path",{d:"M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8",key:"1357e3"}],["path",{d:"M3 3v5h5",key:"1xhq8a"}],["path",{d:"M12 7v5l4 2",key:"1fdv2h"}]],Ot=z("history",En);/**
68
+ * @license lucide-react v1.7.0 - ISC
69
+ *
70
+ * This source code is licensed under the ISC license.
71
+ * See the LICENSE file in the root directory of this source tree.
72
+ */const Dn=[["path",{d:"M16 5h6",key:"1vod17"}],["path",{d:"M19 2v6",key:"4bpg5p"}],["path",{d:"M21 11.5V19a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h7.5",key:"1ue2ih"}],["path",{d:"m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21",key:"1xmnt7"}],["circle",{cx:"9",cy:"9",r:"2",key:"af1f0g"}]],Ut=z("image-plus",Dn);/**
73
+ * @license lucide-react v1.7.0 - ISC
74
+ *
75
+ * This source code is licensed under the ISC license.
76
+ * See the LICENSE file in the root directory of this source tree.
77
+ */const Mn=[["path",{d:"M18 5a2 2 0 0 1 2 2v8.526a2 2 0 0 0 .212.897l1.068 2.127a1 1 0 0 1-.9 1.45H3.62a1 1 0 0 1-.9-1.45l1.068-2.127A2 2 0 0 0 4 15.526V7a2 2 0 0 1 2-2z",key:"1pdavp"}],["path",{d:"M20.054 15.987H3.946",key:"14rxg9"}]],Pn=z("laptop",Mn);/**
78
+ * @license lucide-react v1.7.0 - ISC
79
+ *
80
+ * This source code is licensed under the ISC license.
81
+ * See the LICENSE file in the root directory of this source tree.
82
+ */const $n=[["path",{d:"M13 5h8",key:"a7qcls"}],["path",{d:"M13 12h8",key:"h98zly"}],["path",{d:"M13 19h8",key:"c3s6r1"}],["path",{d:"m3 17 2 2 4-4",key:"1jhpwq"}],["path",{d:"m3 7 2 2 4-4",key:"1obspn"}]],Rn=z("list-checks",$n);/**
83
+ * @license lucide-react v1.7.0 - ISC
84
+ *
85
+ * This source code is licensed under the ISC license.
86
+ * See the LICENSE file in the root directory of this source tree.
87
+ */const Ln=[["path",{d:"M21 12a9 9 0 1 1-6.219-8.56",key:"13zald"}]],me=z("loader-circle",Ln);/**
88
+ * @license lucide-react v1.7.0 - ISC
89
+ *
90
+ * This source code is licensed under the ISC license.
91
+ * See the LICENSE file in the root directory of this source tree.
92
+ */const In=[["path",{d:"M22 17a2 2 0 0 1-2 2H6.828a2 2 0 0 0-1.414.586l-2.202 2.202A.71.71 0 0 1 2 21.286V5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2z",key:"18887p"}],["path",{d:"M12 8v6",key:"1ib9pf"}],["path",{d:"M9 11h6",key:"1fldmi"}]],Ys=z("message-square-plus",In);/**
93
+ * @license lucide-react v1.7.0 - ISC
94
+ *
95
+ * This source code is licensed under the ISC license.
96
+ * See the LICENSE file in the root directory of this source tree.
97
+ */const Fn=[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M9 3v18",key:"fh3hqa"}],["path",{d:"m16 15-3-3 3-3",key:"14y99z"}]],Xs=z("panel-left-close",Fn);/**
98
+ * @license lucide-react v1.7.0 - ISC
99
+ *
100
+ * This source code is licensed under the ISC license.
101
+ * See the LICENSE file in the root directory of this source tree.
102
+ */const On=[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M9 3v18",key:"fh3hqa"}],["path",{d:"m14 9 3 3-3 3",key:"8010ee"}]],Un=z("panel-left-open",On);/**
103
+ * @license lucide-react v1.7.0 - ISC
104
+ *
105
+ * This source code is licensed under the ISC license.
106
+ * See the LICENSE file in the root directory of this source tree.
107
+ */const Bn=[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M15 3v18",key:"14nvp0"}],["path",{d:"m8 9 3 3-3 3",key:"12hl5m"}]],Zs=z("panel-right-close",Bn);/**
108
+ * @license lucide-react v1.7.0 - ISC
109
+ *
110
+ * This source code is licensed under the ISC license.
111
+ * See the LICENSE file in the root directory of this source tree.
112
+ */const zn=[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M15 3v18",key:"14nvp0"}],["path",{d:"m10 15-3-3 3-3",key:"1pgupc"}]],Vn=z("panel-right-open",zn);/**
113
+ * @license lucide-react v1.7.0 - ISC
114
+ *
115
+ * This source code is licensed under the ISC license.
116
+ * See the LICENSE file in the root directory of this source tree.
117
+ */const qn=[["path",{d:"M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z",key:"1a8usu"}],["path",{d:"m15 5 4 4",key:"1mk7zo"}]],Nt=z("pencil",qn);/**
118
+ * @license lucide-react v1.7.0 - ISC
119
+ *
120
+ * This source code is licensed under the ISC license.
121
+ * See the LICENSE file in the root directory of this source tree.
122
+ */const Wn=[["path",{d:"M5 12h14",key:"1ays0h"}],["path",{d:"M12 5v14",key:"s699le"}]],Hn=z("plus",Wn);/**
123
+ * @license lucide-react v1.7.0 - ISC
124
+ *
125
+ * This source code is licensed under the ISC license.
126
+ * See the LICENSE file in the root directory of this source tree.
127
+ */const Kn=[["path",{d:"M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8",key:"1357e3"}],["path",{d:"M3 3v5h5",key:"1xhq8a"}]],Jn=z("rotate-ccw",Kn);/**
128
+ * @license lucide-react v1.7.0 - ISC
129
+ *
130
+ * This source code is licensed under the ISC license.
131
+ * See the LICENSE file in the root directory of this source tree.
132
+ */const Gn=[["path",{d:"m21 21-4.34-4.34",key:"14j7rj"}],["circle",{cx:"11",cy:"11",r:"8",key:"4ej97u"}]],vs=z("search",Gn);/**
133
+ * @license lucide-react v1.7.0 - ISC
134
+ *
135
+ * This source code is licensed under the ISC license.
136
+ * See the LICENSE file in the root directory of this source tree.
137
+ */const Yn=[["path",{d:"M14.536 21.686a.5.5 0 0 0 .937-.024l6.5-19a.496.496 0 0 0-.635-.635l-19 6.5a.5.5 0 0 0-.024.937l7.93 3.18a2 2 0 0 1 1.112 1.11z",key:"1ffxy3"}],["path",{d:"m21.854 2.147-10.94 10.939",key:"12cjpa"}]],Qs=z("send",Yn);/**
138
+ * @license lucide-react v1.7.0 - ISC
139
+ *
140
+ * This source code is licensed under the ISC license.
141
+ * See the LICENSE file in the root directory of this source tree.
142
+ */const Xn=[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z",key:"oel41y"}],["path",{d:"M12 8v4",key:"1got3b"}],["path",{d:"M12 16h.01",key:"1drbdi"}]],Zn=z("shield-alert",Xn);/**
143
+ * @license lucide-react v1.7.0 - ISC
144
+ *
145
+ * This source code is licensed under the ISC license.
146
+ * See the LICENSE file in the root directory of this source tree.
147
+ */const Qn=[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z",key:"oel41y"}],["path",{d:"m9 12 2 2 4-4",key:"dzmm74"}]],eo=z("shield-check",Qn);/**
148
+ * @license lucide-react v1.7.0 - ISC
149
+ *
150
+ * This source code is licensed under the ISC license.
151
+ * See the LICENSE file in the root directory of this source tree.
152
+ */const to=[["path",{d:"M10 5H3",key:"1qgfaw"}],["path",{d:"M12 19H3",key:"yhmn1j"}],["path",{d:"M14 3v4",key:"1sua03"}],["path",{d:"M16 17v4",key:"1q0r14"}],["path",{d:"M21 12h-9",key:"1o4lsq"}],["path",{d:"M21 19h-5",key:"1rlt1p"}],["path",{d:"M21 5h-7",key:"1oszz2"}],["path",{d:"M8 10v4",key:"tgpxqk"}],["path",{d:"M8 12H3",key:"a7s4jb"}]],so=z("sliders-horizontal",to);/**
153
+ * @license lucide-react v1.7.0 - ISC
154
+ *
155
+ * This source code is licensed under the ISC license.
156
+ * See the LICENSE file in the root directory of this source tree.
157
+ */const ro=[["path",{d:"M10 11v6",key:"nco0om"}],["path",{d:"M14 11v6",key:"outv1u"}],["path",{d:"M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6",key:"miytrc"}],["path",{d:"M3 6h18",key:"d0wm0j"}],["path",{d:"M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2",key:"e791ji"}]],ao=z("trash-2",ro);/**
158
+ * @license lucide-react v1.7.0 - ISC
159
+ *
160
+ * This source code is licensed under the ISC license.
161
+ * See the LICENSE file in the root directory of this source tree.
162
+ */const no=[["path",{d:"M19 21v-2a4 4 0 0 0-4-4H9a4 4 0 0 0-4 4v2",key:"975kel"}],["circle",{cx:"12",cy:"7",r:"4",key:"17ys0d"}]],oo=z("user",no);/**
163
+ * @license lucide-react v1.7.0 - ISC
164
+ *
165
+ * This source code is licensed under the ISC license.
166
+ * See the LICENSE file in the root directory of this source tree.
167
+ */const lo=[["path",{d:"M14.7 6.3a1 1 0 0 0 0 1.4l1.6 1.6a1 1 0 0 0 1.4 0l3.106-3.105c.32-.322.863-.22.983.218a6 6 0 0 1-8.259 7.057l-7.91 7.91a1 1 0 0 1-2.999-3l7.91-7.91a6 6 0 0 1 7.057-8.259c.438.12.54.662.219.984z",key:"1ngwbx"}]],er=z("wrench",lo),io=new Set(["assigned","running"]);function co(t,s){return t.reduce((r,a)=>a.assignedTo===s&&io.has(a.status)?r+1:r,0)}function Ke(t){return(t==null?void 0:t.toLowerCase())==="devtunnel"}function uo(t){return t?Ke(t)?"DevTunnel":t.charAt(0).toUpperCase()+t.slice(1):"Direct"}function Qt(t,s){return Ke(s??t.transportType)||!!t.devtunnelEndpoint}function tr(t,s){return!Ke(s??t.transportType)}function sr(t,s){const r=s??t.transportType;return Ke(r)?"DevTunnel":t.devtunnelEndpoint?"Direct + DevTunnel":uo(r)}function Ns(t,s){return!t&&!s}function mo({routeTaskId:t,creatingTask:s,internalSelectedTaskId:r,sortedTaskIds:a}){return t||(s?null:r??a[0]??null)}function xo(t,s){return[s,...t.filter(r=>r.id!==s.id)]}const ho=new Set(["completed","failed","cancelled","archived"]);function fo(t,s){const r=new Set(s);return new Set(Array.from(t).filter(a=>r.has(a)))}function po(t,s){const r=new Set(s);if(r.size===0)return!1;const a=t.filter(n=>r.has(n.id));return a.length===r.size&&a.every(n=>ho.has(n.status))}function go(t,s){var a;const r=new Set(s);return((a=t.find(n=>!r.has(n.id)))==null?void 0:a.id)??null}function ct(t){return typeof t=="object"&&t!==null}function bo(t){if(!ct(t))return null;if(t.type==="text"&&typeof t.text=="string"){const s=t.text.trim();return s?{type:"text",text:s}:null}if(t.type==="image"&&typeof t.mediaType=="string"&&typeof t.data=="string"){const s=t.mediaType.trim(),r=t.data;return!s||!r?null:{type:"image",mediaType:s,data:r,...typeof t.filename=="string"&&t.filename.trim()?{filename:t.filename.trim()}:{}}}if(t.type==="tool_result"&&typeof t.toolUseId=="string"&&typeof t.content=="string"){const s=t.toolUseId.trim(),r=t.content.trim();return!s||!r?null:{type:"tool_result",toolUseId:s,content:r,...typeof t.isError=="boolean"?{isError:t.isError}:{}}}return null}function jo(t){if(!ct(t))return null;if(t.type==="text"&&typeof t.text=="string"){const a=t.text.trim();return a?{type:"text",text:a}:null}if(t.type!=="image"||!ct(t.source)){if(t.type==="tool_result"&&typeof t.tool_use_id=="string"&&typeof t.content=="string"){const a=t.tool_use_id.trim(),n=t.content.trim();return!a||!n?null:{type:"tool_result",toolUseId:a,content:n,...typeof t.is_error=="boolean"?{isError:t.is_error}:{}}}return null}const s=typeof t.source.media_type=="string"?t.source.media_type.trim():"",r=typeof t.source.data=="string"?t.source.data:"";return!s||!r?null:{type:"image",mediaType:s,data:r}}function Ye(t){if(typeof t=="string"){const s=t.trim();return s?[{type:"text",text:s}]:[]}return Array.isArray(t)?t.map(s=>bo(s)??jo(s)).filter(s=>s!==null):[]}function rr(t,s){const r=t.trim();return[...r?[{type:"text",text:r}]:[],...s]}function yo(t){return{role:"user",content:t.map(s=>s.type==="text"?{type:"text",text:s.text}:s.type==="tool_result"?{type:"tool_result",tool_use_id:s.toolUseId,content:s.content,...typeof s.isError=="boolean"?{is_error:s.isError}:{}}:{type:"image",source:{type:"base64",media_type:s.mediaType,data:s.data}})}}function $t(t,s=new Date().toISOString()){return{type:"user",message:yo(t),timestamp:s}}function rt(t){if(t.type!=="user"||t.isSynthetic===!0)return null;if(typeof t.message=="string"){const s=Ye(t.message);return s.length>0?s:null}if(ct(t.message)&&Array.isArray(t.message.content)){const s=Ye(t.message.content);return s.length>0?s:null}if(Array.isArray(t.content)){const s=Ye(t.content);return s.length>0?s:null}return null}function vo(t){return Ye(t.payload.initialMessage)}function Qe(t){return t.map(s=>{if(s.type==="text")return`t:${s.text}`;if(s.type==="tool_result")return`r:${s.toolUseId}:${s.isError===!0?"1":"0"}:${s.content}`;const r=s.data.slice(0,32),a=s.data.slice(-32);return`i:${s.mediaType}:${s.data.length}:${r}:${a}`}).join("|")}function No(t){return t.map(s=>s.type==="text"?s.text:s.type==="tool_result"?s.content:"").filter(Boolean).join(`
168
+ `)}function es(t){return`data:${t.mediaType};base64,${t.data}`}function ko(t){var n,l;if(!t)return[];const s=[],r=t.items;if(r)for(const c of Array.from(r)){if((c==null?void 0:c.kind)!=="file"||!((n=c.type)!=null&&n.startsWith("image/")))continue;const u=(l=c.getAsFile)==null?void 0:l.call(c);u&&u.type.startsWith("image/")&&s.push(u)}if(s.length>0)return s;const a=t.files;return a?Array.from(a).filter(c=>c.type.startsWith("image/")):[]}function wo(t){return new Promise((s,r)=>{const a=new FileReader;a.onload=()=>{if(typeof a.result!="string"){r(new Error(`Failed to read ${t.name}`));return}s(a.result)},a.onerror=()=>r(a.error??new Error(`Failed to read ${t.name}`)),a.readAsDataURL(t)})}async function ks(t){return Promise.all(Array.from(t).map(async s=>{if(!s.type.startsWith("image/"))throw new Error(`${s.name} is not an image`);const r=await wo(s),a=r.indexOf(",");if(a===-1)throw new Error(`Failed to parse ${s.name}`);return{type:"image",mediaType:s.type||"image/png",data:r.slice(a+1),filename:s.name}}))}function at(t){return typeof t=="object"&&t!==null}function Co(t){return at(t)&&typeof t.name=="string"&&t.name.toLowerCase()==="askuserquestion"}function So(t){return!at(t)||typeof t.label!="string"||!t.label.trim()?null:{label:t.label.trim(),description:typeof t.description=="string"?t.description.trim():""}}function _o(t){if(!at(t)||typeof t.question!="string"||!t.question.trim())return null;const s=Array.isArray(t.options)?t.options.map(So).filter(r=>r!==null):[];return s.length===0?null:{header:typeof t.header=="string"&&t.header.trim()?t.header.trim():void 0,question:t.question.trim(),multiSelect:t.multiSelect===!0,options:s}}function Bt(t){if(!at(t)||!Array.isArray(t.questions))return null;const s=t.questions.map(_o).filter(r=>r!==null);return s.length===0?null:{questions:s}}function Je(t){return JSON.stringify({questions:t.questions})}function kt(t){const s=Bt(t);if(s)return s;if(Co(t)){const r=at(t.input)?t.input:void 0,a=Bt(r);return a?{...a,...typeof t.id=="string"&&t.id.trim()?{toolUseId:t.id.trim()}:{}}:null}return null}function Ao(t){var n;const s=t.trim();if(!s)return[];const r=[s],a=s.matchAll(/```(?:json)?\s*([\s\S]*?)```/gi);for(const l of a){const c=(n=l[1])==null?void 0:n.trim();c&&r.push(c)}return r}function wt(t){for(const s of Ao(t))try{const r=JSON.parse(s),a=Bt(r);if(a)return a}catch{}return null}function To(t){return t.questions.map(s=>s.options.length>0?[0]:[])}function Eo(t,s){return t.questions.every((r,a)=>(s[a]??[]).length>0)}function Do(t,s){const a=t.questions.map((n,l)=>{const c=[...new Set(s[l]??[])].sort((u,x)=>u-x).filter(u=>n.options[u]!==void 0);return{header:n.header??null,question:n.question,multiSelect:n.multiSelect,selectedOptions:c.map(u=>n.options[u]).filter(u=>u!==void 0)}}).map(n=>{const l=n.header??n.question,c=n.selectedOptions.map(u=>u.label).join(n.multiSelect?", ":"");return`${l}: ${c}`}).join(`
169
+ `);return t.toolUseId?[{type:"tool_result",toolUseId:t.toolUseId,content:a,isError:!1}]:[{type:"text",text:a}]}function et(t){return typeof t=="object"&&t!==null}function Mo(t){if(!t)return;const s=["file_path","path","command"].map(r=>t[r]).find(r=>typeof r=="string"&&r.trim().length>0);return s==null?void 0:s.trim()}function Po(t){const s=t.toLowerCase();return s.includes(" permission to write ")?"Write":s.includes(" permission to edit ")?"Edit":s.includes(" permission to run ")||s.includes(" permission to execute ")?"Bash":"Action"}function zt(t){const s=t.trim();if(!s.startsWith("Awaiting your permission to "))return null;const r=s.match(/`([^`]+)`/);return{requests:[{toolName:Po(s),target:r==null?void 0:r[1],summary:s}]}}function $o(t){if(!Array.isArray(t.permission_denials))return null;const s=[];for(const r of t.permission_denials){if(!et(r)||typeof r.tool_name!="string")continue;const a=et(r.tool_input)?r.tool_input:void 0,n=Mo(a),l=typeof t.result=="string"&&t.result.trim().length>0?t.result.trim():`Awaiting your permission to use ${r.tool_name}${n?` on \`${n}\``:""}.`;s.push({toolName:r.tool_name,...typeof r.tool_use_id=="string"?{toolUseId:r.tool_use_id}:{},...n?{target:n}:{},summary:l})}return s.length>0?{requests:s}:null}function ws(t){if(!Array.isArray(t))return null;for(const s of t){if(!et(s)||s.type!=="text"||typeof s.text!="string")continue;const r=zt(s.text);if(r)return r}return null}function ts(t){if(!et(t))return null;const s=$o(t);if(s)return s;if(typeof t.result=="string"){const a=zt(t.result);if(a)return a}if(typeof t.message=="string"){const a=zt(t.message);if(a)return a}if(et(t.message)){const a=ts(t.message);if(a)return a;const n=ws(t.message.content);if(n)return n}const r=ws(t.content);return r||null}function Ro(t){return JSON.stringify(t.requests.map(s=>({toolName:s.toolName,target:s.target??null,summary:s.summary})))}function Lo(t,s){return t.requests.map(r=>{const a=r.target?` for \`${r.target}\``:"",n=s==="approve"?`Approved. Proceed with the requested ${r.toolName} action${a}.`:`Denied. Do not proceed with the requested ${r.toolName} action${a}. Ask for another approach if needed.`;return r.toolUseId?{type:"tool_result",toolUseId:r.toolUseId,content:n,isError:s==="deny"}:s==="approve"?{type:"text",text:n}:{type:"text",text:n}})}function ar(t){return rt(t)!==null}function ut(t){if(t.type==="user"){const s=rt(t),r=typeof t.timestamp=="string"?t.timestamp:"";if(s)return`user:${r}:${Qe(s)}`}return JSON.stringify(t)}function Vt(t){const s=kt(t);return s?`question:${Je(s)}`:null}function Io(t){const s=ts(t);return s?`permission:${Ro(s)}`:null}function Cs(t){if(!Array.isArray(t))return null;const s=new Set;for(const r of t){const a=Vt(r);if(a){s.add(a);continue}if(typeof r=="object"&&r!==null&&r.type==="text"&&typeof r.text=="string"){const n=wt(r.text);n&&s.add(Je(n))}}return s.size===0?null:Array.from(s).sort().join("|")}function Fo(t){const s=Vt(t);if(s)return s;if(typeof t.message=="string"){const r=wt(t.message);return r?Je(r):null}if(typeof t.message=="object"&&t.message!==null){const r=Vt(t.message);return r||Cs(t.message.content)}return Cs(t.content)}function Oo(t){return Io(t)}function Uo(t,s,r){const a=typeof s.timestamp=="string"?s.timestamp:"";return`${t}-${a}-${r}`}function Bo(t,s){const r=s.map(n=>({...n})),a=new Set(r.map(ut));for(const n of t){const l=ut(n);a.has(l)||(r.push(n),a.add(l))}return r}function zo(t,s){const r=ut(s);return t.some(a=>ut(a)===r)?t:[...t,{...s}]}function Vo(t,s){const r=new Map;for(const a of s){const n=rt(a);if(!n)continue;const l=Qe(n);r.set(l,(r.get(l)??0)+1)}return t.filter(a=>{const n=Qe(a.content),l=r.get(n)??0;return l<=0?!0:(r.set(n,l-1),!1)})}function qo(t,s){const r=Qe(s),a=t.findIndex(n=>Qe(n.content)===r);return a===-1?t:t.filter((n,l)=>l!==a)}function Wo(t){return t.some(ar)}function Ho(t){const s=[];let r=null;for(const a of t){if(ar(a)){r=null,s.push(a);continue}const n=Oo(a)??Fo(a);n&&n===r||(s.push(a),n&&(r=n))}return s}const Le=o.forwardRef(({className:t,type:s,...r},a)=>e.jsx("input",{type:s,className:A("flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground 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",t),ref:a,...r}));Le.displayName="Input";var Ko=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],Jo=Ko.reduce((t,s)=>{const r=pa(`Primitive.${s}`),a=o.forwardRef((n,l)=>{const{asChild:c,...u}=n,x=c?r:s;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),e.jsx(x,{...u,ref:l})});return a.displayName=`Primitive.${s}`,{...t,[s]:a}},{}),Go="Label",nr=o.forwardRef((t,s)=>e.jsx(Jo.label,{...t,ref:s,onMouseDown:r=>{var n;r.target.closest("button, input, select, textarea")||((n=t.onMouseDown)==null||n.call(t,r),!r.defaultPrevented&&r.detail>1&&r.preventDefault())}}));nr.displayName=Go;var or=nr;const Yo=ga("text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"),Ee=o.forwardRef(({className:t,...s},r)=>e.jsx(or,{ref:r,className:A(Yo(),t),...s}));Ee.displayName=or.displayName;function Xo({onAdded:t}){const[s,r]=o.useState(""),[a,n]=o.useState(!1),[l,c]=o.useState(null),u=o.useCallback(async x=>{if(x.preventDefault(),!!s.trim()){n(!0),c(null);try{await ba({leaderEndpoint:s.trim(),transport:"devtunnel"}),t()}catch(h){c(h instanceof Error?h.message:"Failed to join node")}finally{n(!1)}}},[s,t]);return e.jsx(ja,{className:"overflow-hidden border-border/60 bg-transparent p-0 shadow-none sm:max-w-xl",children:e.jsxs("div",{className:"overflow-hidden rounded-[28px] border border-border/60 bg-background/95 p-0 shadow-[0_40px_120px_-60px_rgba(0,0,0,0.88)] backdrop-blur-xl",children:[e.jsx("div",{className:"border-b border-border/60 px-6 py-5",children:e.jsxs(ya,{className:"space-y-2 text-left",children:[e.jsx(va,{className:"text-2xl tracking-tight",children:"Join node"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Verify the remote leader's DevTunnel endpoint, sync this node's tasks to that leader, and join the cluster as a follower."})]})}),e.jsxs("form",{onSubmit:u,className:"space-y-4 px-6 py-5",children:[l&&e.jsx("div",{className:"rounded-[20px] border border-destructive/20 bg-destructive/10 px-4 py-3 text-sm text-destructive",children:l}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx(Ee,{htmlFor:"leader-endpoint",children:"Leader endpoint"}),e.jsx(ye,{variant:"outline",className:"rounded-full border-border/70 bg-background/60 text-[10px] uppercase tracking-[0.16em]",children:"DevTunnel only"})]}),e.jsx(Le,{id:"leader-endpoint",type:"url",value:s,onChange:x=>r(x.target.value),placeholder:"https://your-leader.devtunnels.ms",className:"h-11 rounded-2xl border-border/70 bg-background/70"})]}),e.jsx("div",{className:"rounded-[20px] border border-border/60 bg-background/45 px-4 py-3 text-sm text-muted-foreground",children:"This does not switch the local node transport or auto-enable a local DevTunnel. Leaving later will detach this node from the remote leader and make it leader of its own cluster again."}),e.jsx(Na,{className:"border-t border-border/60 pt-4",children:e.jsx(M,{type:"submit",disabled:!s.trim()||a,className:"rounded-2xl",children:a?"Joining...":"Join node"})})]})]})})}function lr(){const[t,s]=o.useState([]),[r,a]=o.useState(null),n=o.useRef(null),l=o.useCallback(()=>{var m;(m=n.current)==null||m.click()},[]),c=o.useCallback(async m=>{const f=Array.from(m.target.files??[]);if(f.length!==0)try{const p=await ks(f);s(g=>[...g,...p]),a(null)}catch(p){a(p instanceof Error?p.message:"Failed to attach image")}finally{m.target.value=""}},[]),u=o.useCallback(async m=>{const f=ko(m.clipboardData);if(f.length!==0){m.preventDefault();try{const p=await ks(f);s(g=>[...g,...p]),a(null)}catch(p){a(p instanceof Error?p.message:"Failed to attach image")}}},[]),x=o.useCallback(m=>{s(f=>f.filter((p,g)=>g!==m))},[]),h=o.useCallback(()=>{s([]),a(null)},[]);return{images:t,error:r,fileInputRef:n,pickImages:l,handleFileChange:c,handlePaste:u,removeImage:x,clearImages:h}}function Zo({onSend:t,disabled:s,disabledReason:r="Chat is waiting on the agent.",placeholder:a="Send a follow-up message...",contextItems:n=[],running:l=!1,onStop:c}){const[u,x]=o.useState(""),h=o.useRef(null),{images:m,error:f,fileInputRef:p,pickImages:g,handleFileChange:d,handlePaste:N,removeImage:C,clearImages:j}=lr(),w=o.useCallback(()=>{h.current&&(h.current.style.height="auto")},[]),D=o.useCallback(()=>{const L=rr(u,m);L.length===0||s||(t(L),x(""),j(),w())},[u,m,s,t,j,w]),O=o.useCallback(L=>{L.key==="Enter"&&!L.shiftKey&&(L.preventDefault(),D())},[D]),T=o.useCallback(()=>{h.current&&(h.current.style.height="auto",h.current.style.height=`${Math.min(h.current.scrollHeight,220)}px`)},[]),H=!s&&!l&&(u.trim().length>0||m.length>0),K=l&&!!c,R=l?c?"Task is running — click to stop":"Task is running...":s?r:"Enter sends, Shift+Enter adds a line";return e.jsxs("div",{className:"border-t border-border/60 bg-background/55 px-2 py-1.5 backdrop-blur-xl sm:px-4 sm:py-2",children:[n.length>0&&e.jsx("div",{className:"flex flex-wrap items-center gap-2 px-3 pb-2.5",children:n.map(L=>e.jsxs("div",{className:"inline-flex max-w-full items-center gap-1.5 rounded-full border border-border/60 bg-muted/40 px-3 py-1 text-xs",children:[e.jsx("span",{className:"shrink-0 text-[9px] font-medium uppercase tracking-[0.12em] text-muted-foreground/80",children:L.label}),e.jsx("span",{className:`truncate text-foreground/90 ${L.mono?"font-mono text-[11px]":""}`,children:L.value})]},`${L.label}:${L.value}`))}),e.jsxs("div",{className:"overflow-hidden rounded-3xl border border-border/65 bg-card/85 shadow-[0_28px_90px_-62px_rgba(0,0,0,var(--panel-shadow-alpha))] sm:rounded-[40px]",children:[e.jsx("input",{ref:p,type:"file",accept:"image/*",multiple:!0,onChange:d,className:"hidden"}),m.length>0&&e.jsx("div",{className:"px-3 pt-3 sm:px-6 sm:pt-6",children:e.jsx("div",{className:"flex flex-wrap gap-3",children:m.map((L,I)=>e.jsxs("div",{className:"relative",children:[e.jsx("img",{src:es(L),alt:L.filename??`attachment ${I+1}`,className:"h-24 w-24 rounded-[22px] border border-border/70 object-cover"}),e.jsx("button",{type:"button",onClick:()=>C(I),className:"absolute -top-2 -right-2 flex h-7 w-7 items-center justify-center rounded-full border border-border/70 bg-background text-muted-foreground transition-colors hover:text-foreground","aria-label":`Remove ${L.filename??`image ${I+1}`}`,children:e.jsx(qe,{className:"h-3.5 w-3.5"})})]},`${L.filename??"image"}-${I}`))})}),e.jsxs("div",{className:"flex items-end gap-2 px-3 pt-3 pb-3 sm:px-6 sm:pt-4 sm:pb-4",children:[e.jsx("textarea",{ref:h,value:u,onChange:L=>x(L.target.value),onKeyDown:O,onPaste:N,onInput:T,placeholder:a,disabled:s,rows:1,className:"min-h-[2.5rem] flex-1 resize-none bg-transparent px-0 py-1 text-sm leading-7 text-foreground placeholder:text-muted-foreground/70 focus-visible:outline-none disabled:cursor-not-allowed disabled:opacity-50"}),e.jsxs(M,{type:"button",variant:"ghost",onClick:g,disabled:s,className:"mb-0.5 h-9 shrink-0 gap-1.5 rounded-full px-2 text-xs text-muted-foreground hover:text-foreground sm:px-3",title:"Attach images",children:[e.jsx(Ut,{className:"h-4 w-4 sm:h-3.5 sm:w-3.5"}),e.jsx("span",{className:"hidden sm:inline",children:"Images"})]}),e.jsx("span",{title:R,children:e.jsx(M,{onClick:l?c:D,disabled:l?!K:!H,size:"icon","aria-label":l?"Stop running task":"Send message",className:"mb-0.5 h-9 w-9 shrink-0 rounded-full bg-primary/85 text-primary-foreground shadow-sm hover:bg-primary",children:l?e.jsx(me,{className:"h-4 w-4 animate-spin"}):e.jsx(Qs,{className:"h-4 w-4"})})})]}),f&&e.jsx("div",{className:"border-t border-destructive/20 bg-destructive/10 px-3 py-2 text-xs text-destructive sm:px-6 sm:py-3",children:f})]})]})}function tt({payload:t,disabled:s=!1,bypassEnabled:r=!1,onBypassChange:a,onSubmit:n}){const[l,c]=o.useState(()=>r?To(t):t.questions.map(()=>[])),[u,x]=o.useState(!1),[h,m]=o.useState(!1);o.useEffect(()=>{r&&c(d=>d.map((N,C)=>{var j;return N.length>0?N:(j=t.questions[C])!=null&&j.options.length?[0]:[]}))},[r,t]);const f=Eo(t,l)&&!s&&!u&&!h&&!!n,p=(d,N)=>{s||h||u||c(C=>C.map((j,w)=>{if(w!==d)return j;const D=t.questions[w];return D?D.multiSelect?j.includes(N)?j.filter(O=>O!==N):[...j,N].sort((O,T)=>O-T):[N]:j}))},g=async()=>{if(!f||!n)return;x(!0);const d=await n(Do(t,l));x(!1),d&&m(!0)};return e.jsxs("div",{className:"rounded-[24px] border border-primary/20 bg-primary/5 p-4 shadow-[0_24px_80px_-60px_hsl(var(--primary)/0.9)]",children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx("div",{className:"mt-0.5 flex h-8 w-8 shrink-0 items-center justify-center rounded-full border border-primary/20 bg-primary/10 text-primary",children:e.jsx(gn,{className:"h-4 w-4"})}),e.jsxs("div",{children:[e.jsx("div",{className:"text-[11px] font-semibold uppercase tracking-[0.22em] text-primary/80",children:"Ask User Question"}),e.jsx("div",{className:"mt-1 text-sm leading-6 text-muted-foreground",children:"Select the answer you want to send back to the agent."})]})]}),e.jsxs(M,{type:"button",variant:r?"secondary":"outline",size:"sm",onClick:()=>a==null?void 0:a(!r),className:"rounded-full",children:[e.jsx(eo,{className:"h-4 w-4"}),r?"Bypass on":"Bypass future questions"]})]}),e.jsx("div",{className:"mt-4 space-y-4",children:t.questions.map((d,N)=>{const C=l[N]??[];return e.jsxs("div",{className:"space-y-3 rounded-[20px] border border-border/60 bg-background/75 p-4",children:[e.jsxs("div",{children:[d.header&&e.jsx("div",{className:"text-[10px] font-semibold uppercase tracking-[0.24em] text-muted-foreground",children:d.header}),e.jsx("div",{className:"mt-1 text-sm font-medium leading-6 text-foreground",children:d.question}),e.jsx("div",{className:"mt-1 text-xs text-muted-foreground",children:d.multiSelect?"Select one or more options.":"Select one option."})]}),e.jsx("div",{className:"space-y-2",children:d.options.map((j,w)=>{const D=C.includes(w);return e.jsxs("button",{type:"button",onClick:()=>p(N,w),disabled:s||u||h,"aria-pressed":D,className:A("flex w-full items-start gap-3 rounded-[18px] border px-4 py-3 text-left transition-colors",D?"border-primary/50 bg-primary/10 text-foreground":"border-border/60 bg-background/80 text-foreground hover:border-primary/30 hover:bg-primary/5"),children:[e.jsx("span",{className:A("mt-0.5 flex h-5 w-5 shrink-0 items-center justify-center rounded-full border",D?"border-primary bg-primary text-primary-foreground":"border-border/70 bg-background text-transparent"),children:e.jsx(Pe,{className:"h-3.5 w-3.5"})}),e.jsxs("span",{className:"min-w-0",children:[e.jsx("span",{className:"block text-sm font-medium leading-5",children:j.label}),j.description&&e.jsx("span",{className:"mt-1 block text-xs leading-5 text-muted-foreground",children:j.description})]})]},`${j.label}-${w}`)})})]},`${d.header??"question"}-${N}`)})}),e.jsxs("div",{className:"mt-4 flex flex-wrap items-center justify-between gap-3",children:[e.jsx("div",{className:"text-xs text-muted-foreground",children:r?"Bypass is enabled. New question cards will default to the first option.":"Enable bypass if you want future question cards to preselect the first option."}),e.jsx(M,{type:"button",onClick:()=>void g(),disabled:!f,className:"rounded-full px-5",children:h?"Sent":u?"Sending...":t.questions.length>1?"Send answers":"Send answer"})]})]})}function Qo({payload:t,disabled:s=!1,onSubmit:r}){const[a,n]=o.useState(null),[l,c]=o.useState(!1),u=!s&&!l&&!!r,x=async h=>{if(!u||!r)return;n(h);const m=await r(Lo(t,h));n(null),m&&c(!0)};return e.jsxs("div",{className:"rounded-[24px] border border-amber-500/25 bg-amber-500/5 p-4 shadow-[0_24px_80px_-60px_rgba(245,158,11,0.8)]",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"mt-0.5 flex h-8 w-8 shrink-0 items-center justify-center rounded-full border border-amber-500/25 bg-amber-500/10 text-amber-600 dark:text-amber-400",children:e.jsx(Zn,{className:"h-4 w-4"})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"text-[11px] font-semibold uppercase tracking-[0.22em] text-amber-700/80 dark:text-amber-300/80",children:"Permission Request"}),e.jsx("div",{className:"mt-1 space-y-3",children:t.requests.map((h,m)=>e.jsxs("div",{className:"rounded-[18px] border border-border/60 bg-background/75 px-4 py-3",children:[e.jsx("div",{className:"text-sm font-medium leading-6 text-foreground",children:h.summary}),(h.toolName||h.target)&&e.jsxs("div",{className:"mt-2 flex flex-wrap gap-2 text-[11px] uppercase tracking-[0.18em] text-muted-foreground",children:[e.jsx("span",{children:h.toolName}),h.target&&e.jsx("span",{className:"font-mono normal-case tracking-normal",children:h.target})]})]},`${h.toolUseId??h.toolName}-${m}`))})]})]}),e.jsxs("div",{className:"mt-4 flex flex-wrap items-center justify-end gap-2",children:[e.jsxs(M,{type:"button",variant:"outline",onClick:()=>void x("deny"),disabled:!u||a!==null,className:"rounded-full",children:[e.jsx(qe,{className:"h-4 w-4"}),l?"Sent":a==="deny"?"Sending...":"Deny"]}),e.jsxs(M,{type:"button",onClick:()=>void x("approve"),disabled:!u||a!==null,className:"rounded-full",children:[e.jsx(Pe,{className:"h-4 w-4"}),l?"Sent":a==="approve"?"Sending...":"Approve"]})]})]})}function Ss({event:t,questionBypassEnabled:s=!1,onQuestionBypassChange:r,onSubmitQuestionResponse:a,questionResponseDisabled:n=!1}){const l=t.type,c=ts(t),u=kt(t);if(c)return e.jsx(Xe,{children:e.jsx(Qo,{payload:c,onSubmit:a,disabled:n})});if(u)return e.jsx(Xe,{children:e.jsx(tt,{payload:u,bypassEnabled:s,onBypassChange:r,onSubmit:a,disabled:n})});if(l==="user"){const x=el(t),h=x.filter(f=>f.type==="tool_result");if(h.length>0&&x.every(f=>f.type==="tool_result"))return e.jsx(Xe,{children:h.map((f,p)=>e.jsx(dr,{block:f,questionBypassEnabled:s,onQuestionBypassChange:r,onSubmitQuestionResponse:a,questionResponseDisabled:n},p))});const m=rt(t);return m?e.jsx(al,{content:m}):null}return l==="assistant"?e.jsx(nl,{event:t,questionBypassEnabled:s,onQuestionBypassChange:r,onSubmitQuestionResponse:a,questionResponseDisabled:n}):null}function el(t){const s=t.message,r=s==null?void 0:s.content;if(Array.isArray(r))return r.filter(n=>typeof n=="object"&&n!==null);const a=t.content;return Array.isArray(a)?a.filter(n=>typeof n=="object"&&n!==null):[]}function Rt(t){var r;const s=t.replace(/\r\n/g,`
170
+ `).split(`
171
+ `);for(;s.length>0&&((r=s[0])==null?void 0:r.trim())==="";)s.shift();return s.join(`
172
+ `)}function ir({text:t,className:s=""}){const[r,a]=o.useState(!1);if(!t)return null;const n=async l=>{l.stopPropagation();try{await navigator.clipboard.writeText(t),a(!0),setTimeout(()=>a(!1),1500)}catch{}};return e.jsx("button",{type:"button",onClick:n,"aria-label":r?"Copied":"Copy message",className:`flex h-6 w-6 items-center justify-center rounded-full border border-border/60 bg-background/80 text-muted-foreground opacity-0 shadow-sm backdrop-blur transition-opacity hover:text-foreground group-hover:opacity-100 focus-visible:opacity-100 ${s}`,children:r?e.jsx(Pe,{className:"h-3 w-3 text-emerald-500"}):e.jsx(vt,{className:"h-3 w-3"})})}async function tl(t){let r=await(await fetch(t)).blob();r.type!=="image/png"&&(r=await sl(r)),await navigator.clipboard.write([new ClipboardItem({[r.type]:r})])}async function sl(t){const s=await createImageBitmap(t),r=document.createElement("canvas");r.width=s.width,r.height=s.height;const a=r.getContext("2d");if(!a)throw new Error("canvas 2d context unavailable");return a.drawImage(s,0,0),await new Promise((n,l)=>{r.toBlob(c=>c?n(c):l(new Error("toBlob failed")),"image/png")})}function rl({dataUrl:t,className:s=""}){const[r,a]=o.useState(!1),n=async l=>{l.stopPropagation();try{await tl(t),a(!0),setTimeout(()=>a(!1),1500)}catch(c){console.error("copy image failed",c)}};return e.jsx("button",{type:"button",onClick:n,"aria-label":r?"Copied":"Copy image",className:`flex h-6 w-6 items-center justify-center rounded-full border border-border/60 bg-background/80 text-muted-foreground opacity-0 shadow-sm backdrop-blur transition-opacity hover:text-foreground group-hover:opacity-100 focus-visible:opacity-100 ${s}`,children:r?e.jsx(Pe,{className:"h-3 w-3 text-emerald-500"}):e.jsx(vt,{className:"h-3 w-3"})})}function al({content:t}){const s=No(t),r=t.filter(a=>a.type==="image");return e.jsx("div",{className:"animate-message-rise flex justify-end",children:e.jsxs("div",{className:"group relative flex max-w-[88%] items-start gap-3",children:[e.jsx(ir,{text:s,className:"absolute -left-8 top-2"}),e.jsxs("div",{className:"space-y-1 rounded-[26px] rounded-tr-md border border-primary/25 bg-primary px-4 py-3 text-[13px] leading-5 text-primary-foreground shadow-[0_20px_70px_-42px_hsl(var(--primary)/0.95)]",children:[e.jsx("div",{className:"text-[10px] font-semibold uppercase tracking-[0.28em] text-primary-foreground/75",children:"You"}),s&&e.jsx("div",{className:"whitespace-pre-wrap",children:s}),r.length>0&&e.jsx("div",{className:"grid gap-2 sm:grid-cols-2",children:r.map((a,n)=>{const l=es(a);return e.jsxs("div",{className:"relative",children:[e.jsx("img",{src:l,alt:a.filename??`attachment ${n+1}`,className:"max-h-72 w-full rounded-2xl border border-primary-foreground/15 object-cover"}),e.jsx(rl,{dataUrl:l,className:"absolute right-2 top-2"})]},`${a.filename??"image"}-${n}`)})})]}),e.jsx("div",{className:"mt-1 flex h-9 w-9 shrink-0 items-center justify-center rounded-full border border-primary/20 bg-primary/10 text-primary",children:e.jsx(oo,{className:"h-4 w-4"})})]})})}function Xe({children:t}){return e.jsx("div",{className:"animate-message-rise flex justify-start",children:e.jsxs("div",{className:"flex max-w-[92%] items-start gap-3",children:[e.jsx("div",{className:"mt-1 flex h-9 w-9 shrink-0 items-center justify-center rounded-full border border-border/70 bg-muted/70 text-muted-foreground",children:e.jsx(Yt,{className:"h-4 w-4"})}),e.jsxs("div",{className:"min-w-0 space-y-3",children:[e.jsx("div",{className:"text-[10px] font-semibold uppercase tracking-[0.28em] text-muted-foreground",children:"Agent"}),t]})]})})}function nl({event:t,questionBypassEnabled:s,onQuestionBypassChange:r,onSubmitQuestionResponse:a,questionResponseDisabled:n}){const l=t.message;if(!l)return null;const c=kt(l);if(c)return e.jsx(Xe,{children:e.jsx(tt,{payload:c,bypassEnabled:s,onBypassChange:r,onSubmit:a,disabled:n})});const u=l.content;if(!u||!Array.isArray(u))return null;const x=new Set,h=u.filter(d=>d.type==="text").map(d=>({...d,text:Rt(String(d.text??"")),questionPayload:wt(Rt(String(d.text??"")))})).filter(d=>d.text.length>0||d.questionPayload),m=u.filter(d=>d.type==="thinking").map(d=>Rt(String(d.thinking??""))).filter(Boolean).join(`
173
+
174
+ `),f=u.filter(d=>d.type==="tool_use"),p=u.filter(d=>d.type==="tool_result");return h.length>0||m.length>0||f.length>0||p.length>0?e.jsxs(Xe,{children:[m.length>0&&e.jsx(dl,{text:m}),h.map((d,N)=>{if(d.questionPayload){const C=Je(d.questionPayload);return x.has(C)?null:(x.add(C),e.jsx(tt,{payload:d.questionPayload,bypassEnabled:s,onBypassChange:r,onSubmit:a,disabled:n},N))}return e.jsxs("div",{className:"group relative rounded-[26px] rounded-tl-md border border-border/70 bg-card/80 px-4 py-3 text-[13px] leading-5 text-foreground shadow-[0_20px_70px_-58px_rgba(0,0,0,0.9)] backdrop-blur-sm",children:[e.jsx(ir,{text:d.text,className:"absolute right-2 top-2"}),e.jsx("div",{className:"whitespace-pre-wrap",children:d.text})]},N)}),f.map((d,N)=>e.jsx(cl,{block:d,renderedQuestionSignatures:x,questionBypassEnabled:s,onQuestionBypassChange:r,onSubmitQuestionResponse:a,questionResponseDisabled:n},N)),p.map((d,N)=>e.jsx(dr,{block:d,renderedQuestionSignatures:x,questionBypassEnabled:s,onQuestionBypassChange:r,onSubmitQuestionResponse:a,questionResponseDisabled:n},N))]}):null}function ol(t){return t.replace(/\s+/g," ").trim()}function ze(t,s=132){const r=ol(t);return r?r.length>s?`${r.slice(0,s-3)}...`:r:""}function qt(t,s=84){if(typeof t=="string")return ze(t,s);if(typeof t=="number"||typeof t=="boolean")return String(t);if(Array.isArray(t)){const r=t.slice(0,3).map(a=>qt(a,28)).filter(Boolean).join(", ");return ze(r||JSON.stringify(t),s)}if(typeof t=="object"&&t!==null){const r=Object.entries(t).slice(0,3).map(([a,n])=>`${a}: ${qt(n,32)}`).join(" · ");return ze(r||JSON.stringify(t),s)}return""}function ll(t){if(!t)return"No input";const s=Object.entries(t).slice(0,4).map(([r,a])=>`${r}: ${qt(a,40)}`).filter(r=>r.trim().length>0).join(" · ");return ze(s||JSON.stringify(t),156)||"No input"}function il({expanded:t}){return e.jsxs("span",{className:"inline-flex shrink-0 items-center gap-1 rounded-full border border-border/60 bg-background/70 px-2 py-1 text-[10px] font-medium uppercase tracking-[0.18em] text-muted-foreground",children:[t?"Less":"More",t?e.jsx(Os,{className:"h-3 w-3"}):e.jsx(We,{className:"h-3 w-3"})]})}function ss({title:t,preview:s,icon:r,children:a,accentClassName:n,previewClassName:l="font-mono text-[11px] text-muted-foreground/90"}){const[c,u]=o.useState(!1);return e.jsxs("div",{className:`overflow-hidden rounded-[22px] border border-border/60 ${n}`,children:[e.jsxs("button",{type:"button",onClick:()=>u(x=>!x),className:"flex w-full items-start gap-3 px-4 py-3 text-left transition-colors hover:bg-background/30",children:[e.jsx("div",{className:"mt-0.5 flex h-7 w-7 shrink-0 items-center justify-center rounded-full border border-border/60 bg-background/70 text-muted-foreground",children:r}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"flex flex-wrap items-center gap-2",children:e.jsx("span",{className:"text-[10px] font-semibold uppercase tracking-[0.22em] text-muted-foreground",children:t})}),e.jsx("div",{className:`mt-1 whitespace-pre-wrap break-words text-[12px] leading-5 ${l}`,children:s})]}),e.jsx(il,{expanded:c})]}),c&&e.jsx("div",{className:"border-t border-border/60 px-4 py-3",children:a})]})}function dl({text:t}){const s=ze(t,156);return e.jsx(ss,{title:"Thinking",preview:s,icon:e.jsx(hn,{className:"h-3.5 w-3.5"}),accentClassName:"bg-muted/35",previewClassName:"text-[12px] leading-5 text-muted-foreground/90",children:e.jsx("div",{className:"whitespace-pre-wrap text-[13px] leading-5 text-muted-foreground/90",children:t})})}function cl({block:t,renderedQuestionSignatures:s,questionBypassEnabled:r,onQuestionBypassChange:a,onSubmitQuestionResponse:n,questionResponseDisabled:l}){const c=String(t.name??"tool"),u=t.input,x=kt(t);if(x){const m=Je(x);return s!=null&&s.has(m)?null:(s==null||s.add(m),e.jsx(tt,{payload:x,bypassEnabled:r,onBypassChange:a,onSubmit:n,disabled:l}))}const h=ll(u);if(c==="TodoWrite"){const m=ul(u==null?void 0:u.todos);if(m.length>0)return e.jsx(ml,{todos:m})}return e.jsx(ss,{title:`Tool: ${c}`,preview:h,icon:e.jsx(er,{className:"h-3.5 w-3.5"}),accentClassName:"bg-muted/25",children:e.jsx("pre",{className:"overflow-x-auto whitespace-pre-wrap text-xs leading-5 text-muted-foreground",children:JSON.stringify(u??{},null,2)})})}function dr({block:t,renderedQuestionSignatures:s,questionBypassEnabled:r,onQuestionBypassChange:a,onSubmitQuestionResponse:n,questionResponseDisabled:l}){const c=t.content,u=typeof c=="string"?c:Array.isArray(c)?c.map(m=>String(m.text??"")).join(`
175
+ `):"";if(!u)return null;const x=wt(u);if(x){const m=Je(x);return s!=null&&s.has(m)?null:(s==null||s.add(m),e.jsx(tt,{payload:x,bypassEnabled:r,onBypassChange:a,onSubmit:n,disabled:l}))}const h=ze(u,156);return e.jsx(ss,{title:"Result",preview:h,icon:e.jsx(er,{className:"h-3.5 w-3.5"}),accentClassName:"bg-background/65",children:e.jsx("pre",{className:"overflow-x-auto whitespace-pre-wrap text-xs leading-5 text-muted-foreground",children:u})})}function ul(t){return Array.isArray(t)?t.map(s=>{if(typeof s!="object"||s===null)return null;const r=s,a=typeof r.content=="string"?r.content:"";if(!a)return null;const n=typeof r.activeForm=="string"?r.activeForm:a,l=typeof r.status=="string"?r.status:"pending";return{content:a,activeForm:n,status:l==="completed"||l==="in_progress"?l:"pending"}}).filter(s=>s!==null):[]}function ml({todos:t}){const s=t.filter(n=>n.status==="completed").length,r=t.length,a=t.find(n=>n.status==="in_progress");return e.jsxs("div",{className:"overflow-hidden rounded-[22px] border border-border/60 bg-muted/20",children:[e.jsxs("div",{className:"flex items-center gap-3 border-b border-border/50 px-4 py-3",children:[e.jsx("div",{className:"flex h-7 w-7 shrink-0 items-center justify-center rounded-full border border-border/60 bg-background/70 text-muted-foreground",children:e.jsx(Rn,{className:"h-3.5 w-3.5"})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"text-[10px] font-semibold uppercase tracking-[0.22em] text-muted-foreground",children:"Todos"}),e.jsx("div",{className:"mt-0.5 truncate text-[12px] leading-5 text-muted-foreground/90",children:a?a.activeForm:r===0?"No items":s===r?"All complete":"Up next"})]}),e.jsxs("div",{className:"shrink-0 rounded-full border border-border/60 bg-background/70 px-2 py-0.5 font-mono text-[10px] tracking-wide text-muted-foreground",children:[s,"/",r]})]}),e.jsx("ul",{className:"divide-y divide-border/40",children:t.map((n,l)=>e.jsxs("li",{className:"flex items-start gap-3 px-4 py-2.5",children:[e.jsx(xl,{status:n.status}),e.jsx("span",{className:n.status==="completed"?"text-[13px] leading-5 text-muted-foreground line-through decoration-muted-foreground/60":n.status==="in_progress"?"text-[13px] font-medium leading-5 text-foreground":"text-[13px] leading-5 text-foreground/85",children:n.status==="in_progress"?n.activeForm:n.content})]},`${l}-${n.content}`))})]})}function xl({status:t}){return t==="completed"?e.jsx("span",{className:"mt-0.5 flex h-4 w-4 shrink-0 items-center justify-center rounded-full bg-emerald-500/15 text-emerald-500 dark:text-emerald-400",children:e.jsx(Pe,{className:"h-3 w-3"})}):t==="in_progress"?e.jsx("span",{className:"mt-0.5 flex h-4 w-4 shrink-0 items-center justify-center text-primary",children:e.jsx(me,{className:"h-3.5 w-3.5 animate-spin"})}):e.jsx("span",{className:"mt-0.5 flex h-4 w-4 shrink-0 items-center justify-center text-muted-foreground/60",children:e.jsx(jn,{className:"h-3 w-3"})})}var cr="AlertDialog",[hl]=zs(cr,[Us]),$e=Us(),ur=t=>{const{__scopeAlertDialog:s,...r}=t,a=$e(s);return e.jsx(ka,{...a,...r,modal:!0})};ur.displayName=cr;var fl="AlertDialogTrigger",mr=o.forwardRef((t,s)=>{const{__scopeAlertDialog:r,...a}=t,n=$e(r);return e.jsx(wa,{...n,...a,ref:s})});mr.displayName=fl;var pl="AlertDialogPortal",xr=t=>{const{__scopeAlertDialog:s,...r}=t,a=$e(s);return e.jsx(Ca,{...a,...r})};xr.displayName=pl;var gl="AlertDialogOverlay",hr=o.forwardRef((t,s)=>{const{__scopeAlertDialog:r,...a}=t,n=$e(r);return e.jsx(Ea,{...n,...a,ref:s})});hr.displayName=gl;var Ve="AlertDialogContent",[bl,jl]=hl(Ve),yl=Da("AlertDialogContent"),fr=o.forwardRef((t,s)=>{const{__scopeAlertDialog:r,children:a,...n}=t,l=$e(r),c=o.useRef(null),u=yt(s,c),x=o.useRef(null);return e.jsx(Sa,{contentName:Ve,titleName:pr,docsSlug:"alert-dialog",children:e.jsx(bl,{scope:r,cancelRef:x,children:e.jsxs(_a,{role:"alertdialog",...l,...n,ref:u,onOpenAutoFocus:Ft(n.onOpenAutoFocus,h=>{var m;h.preventDefault(),(m=x.current)==null||m.focus({preventScroll:!0})}),onPointerDownOutside:h=>h.preventDefault(),onInteractOutside:h=>h.preventDefault(),children:[e.jsx(yl,{children:a}),e.jsx(Nl,{contentRef:c})]})})})});fr.displayName=Ve;var pr="AlertDialogTitle",gr=o.forwardRef((t,s)=>{const{__scopeAlertDialog:r,...a}=t,n=$e(r);return e.jsx(Aa,{...n,...a,ref:s})});gr.displayName=pr;var br="AlertDialogDescription",jr=o.forwardRef((t,s)=>{const{__scopeAlertDialog:r,...a}=t,n=$e(r);return e.jsx(Ta,{...n,...a,ref:s})});jr.displayName=br;var vl="AlertDialogAction",yr=o.forwardRef((t,s)=>{const{__scopeAlertDialog:r,...a}=t,n=$e(r);return e.jsx(Bs,{...n,...a,ref:s})});yr.displayName=vl;var vr="AlertDialogCancel",Nr=o.forwardRef((t,s)=>{const{__scopeAlertDialog:r,...a}=t,{cancelRef:n}=jl(vr,r),l=$e(r),c=yt(s,n);return e.jsx(Bs,{...l,...a,ref:c})});Nr.displayName=vr;var Nl=({contentRef:t})=>{const s=`\`${Ve}\` requires a description for the component to be accessible for screen reader users.
176
+
177
+ You can add a description to the \`${Ve}\` by passing a \`${br}\` component as a child, which also benefits sighted users by adding visible context to the dialog.
178
+
179
+ Alternatively, you can use your own component as a description by assigning it an \`id\` and passing the same value to the \`aria-describedby\` prop in \`${Ve}\`. If the description is confusing or duplicative for sighted users, you can use the \`@radix-ui/react-visually-hidden\` primitive as a wrapper around your description component.
180
+
181
+ For more information, see https://radix-ui.com/primitives/docs/components/alert-dialog`;return o.useEffect(()=>{var a;document.getElementById((a=t.current)==null?void 0:a.getAttribute("aria-describedby"))||console.warn(s)},[s,t]),null},kl=ur,wl=mr,Cl=xr,kr=hr,wr=fr,Cr=yr,Sr=Nr,_r=gr,Ar=jr;const Wt=kl,_s=wl,Sl=Cl,Tr=o.forwardRef(({className:t,...s},r)=>e.jsx(kr,{className:A("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",t),...s,ref:r}));Tr.displayName=kr.displayName;const mt=o.forwardRef(({className:t,...s},r)=>e.jsxs(Sl,{children:[e.jsx(Tr,{}),e.jsx(wr,{ref:r,className:A("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",t),...s})]}));mt.displayName=wr.displayName;const xt=({className:t,...s})=>e.jsx("div",{className:A("flex flex-col space-y-2 text-center sm:text-left",t),...s});xt.displayName="AlertDialogHeader";const ht=({className:t,...s})=>e.jsx("div",{className:A("flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",t),...s});ht.displayName="AlertDialogFooter";const ft=o.forwardRef(({className:t,...s},r)=>e.jsx(_r,{ref:r,className:A("text-lg font-semibold",t),...s}));ft.displayName=_r.displayName;const pt=o.forwardRef(({className:t,...s},r)=>e.jsx(Ar,{ref:r,className:A("text-sm text-muted-foreground",t),...s}));pt.displayName=Ar.displayName;const gt=o.forwardRef(({className:t,...s},r)=>e.jsx(Cr,{ref:r,className:A(Vs(),t),...s}));gt.displayName=Cr.displayName;const bt=o.forwardRef(({className:t,...s},r)=>e.jsx(Sr,{ref:r,className:A(Vs({variant:"outline"}),"mt-2 sm:mt-0",t),...s}));bt.displayName=Sr.displayName;const Ht="bypass",rs=[{value:"claudecode",label:"claudecode",supportsFollowUp:!0},{value:"codex",label:"codex",supportsFollowUp:!0},{value:"mars",label:"mars",disabled:!0,description:"coming soon"},{value:"eureka",label:"eureka",disabled:!0,description:"coming soon"}],Er=[{value:"bypass",label:"Bypass"},{value:"plan",label:"Plan"},{value:"edit",label:"Edit"},{value:"dangerous",label:"Dangerous"}],_l=new Set(rs.filter(t=>t.supportsFollowUp).map(t=>t.value));function Al(t,s,r){return t!=="auto"?s.find(a=>a.id===t)??null:r.length===1?r[0]??null:null}function Tl(t){return t.trim()||"."}function As({value:t,onChange:s,project:r,assignTo:a,nodes:n,assignableNodes:l,layout:c="default",chipClassName:u,chipActiveClassName:x,chipInactiveClassName:h,labelClassName:m,triggerClassName:f}){const[p,g]=o.useState(!1),[d,N]=o.useState(null),[C,j]=o.useState(!1),[w,D]=o.useState(!1),[O,T]=o.useState(!1),[H,K]=o.useState(null),[R,L]=o.useState(""),[I,ee]=o.useState(""),[S,V]=o.useState(""),[Y,U]=o.useState(!1),ie=o.useRef(null),q=o.useMemo(()=>Al(a,n,l),[a,n,l]),F=q==null?void 0:q.id,X=o.useMemo(()=>Tl(r),[r]),xe=o.useCallback(async(_=0,P=!1)=>{if(!F){N(null);return}K(null),P?D(!0):j(!0);try{const E=await Ma(F,{path:X,limit:20,offset:_,allowAbsolute:!0});N(v=>P&&v?{...E,branches:[...v.branches,...E.branches]}:E)}catch(E){K(E instanceof Error?E.message:"Failed to load branch info"),P||N(null)}finally{j(!1),D(!1)}},[F,X]);o.useEffect(()=>{if(!F){N(null),K(null);return}xe()},[F,X,xe]),o.useEffect(()=>{d!=null&&d.available&&d.currentBranch&&!t.trim()&&s(d.currentBranch)},[d==null?void 0:d.available,d==null?void 0:d.currentBranch,s,t]),o.useEffect(()=>{if(!p)return;const _=E=>{ie.current&&(ie.current.contains(E.target)||g(!1))},P=E=>{E.key==="Escape"&&g(!1)};return document.addEventListener("mousedown",_),document.addEventListener("keydown",P),()=>{document.removeEventListener("mousedown",_),document.removeEventListener("keydown",P)}},[p]),o.useEffect(()=>{p&&(ee(""),V(""),U(!1))},[p,F,X]);const oe=o.useCallback(async()=>{if(!F)return;const _=R.trim(),P=Y?S.trim():I.trim();if(!(!_||!P)){T(!0),K(null);try{const E=await Pa(F,{path:X,branchName:_,startPoint:P,limit:20,offset:0,allowAbsolute:!0});N(E),s(E.currentBranch??E.createdBranch),L(""),ee(""),V(""),U(!1),g(!1)}catch(E){K(E instanceof Error?E.message:"Failed to create branch")}finally{T(!1)}}},[F,X,Y,S,R,s,I]),de=o.useCallback(()=>{d!=null&&d.hasMore&&xe(d.branches.length,!0)},[d,xe]),Z=t.trim()||(d==null?void 0:d.currentBranch)||(d&&!d.available?"No git repo":"Branch"),ce=Y?S.trim():I.trim(),te=!!(d!=null&&d.available&&R.trim()&&ce&&!O),y=c==="composer"?e.jsxs(M,{type:"button",variant:"ghost",onClick:()=>g(_=>!_),title:Z,"aria-label":`Branch: ${Z}`,className:A(u,f,"min-w-0 max-w-full",t.trim()?x:h),children:[C&&!d?e.jsx(me,{className:"h-3.5 w-3.5 shrink-0 animate-spin"}):e.jsx(ys,{className:"h-3.5 w-3.5 shrink-0"}),e.jsx("span",{className:A("min-w-0 truncate",m),children:Z})]}):e.jsxs(M,{type:"button",variant:"outline",onClick:()=>g(_=>!_),className:"h-11 w-full justify-between rounded-2xl border-border/70 bg-background/70 px-4",title:Z,children:[e.jsx("span",{className:A("truncate",t.trim()?"font-mono text-foreground":"text-muted-foreground"),children:Z}),e.jsx("span",{className:"ml-3 shrink-0 text-xs text-muted-foreground",children:q?q.name:"Manual"})]});return e.jsxs("div",{className:A("relative inline-block",c==="composer"?"min-w-0 shrink-0":"w-full"),ref:ie,children:[c==="default"?e.jsxs("div",{className:"space-y-2",children:[e.jsx(Ee,{className:"text-sm font-medium",children:"Branch"}),y]}):y,p&&e.jsxs("div",{className:A("absolute z-50 mt-2 w-[240px] overflow-hidden rounded-2xl border border-border/60 bg-background/95 shadow-lg backdrop-blur",c==="composer"?"left-0":"left-0 right-0 w-auto min-w-[240px]"),children:[e.jsxs("div",{className:"flex items-center gap-2 border-b border-border/60 px-3 py-2",children:[e.jsx(ys,{className:"h-3 w-3 shrink-0 text-muted-foreground"}),e.jsx("span",{className:"min-w-0 flex-1 truncate font-mono text-[11px] text-foreground",title:d!=null&&d.repoRoot?`${(d==null?void 0:d.currentBranch)??Z} · ${d.repoRoot}`:(d==null?void 0:d.currentBranch)??Z,children:(d==null?void 0:d.currentBranch)??Z}),C?e.jsx(me,{className:"h-3 w-3 shrink-0 animate-spin text-muted-foreground"}):null]}),q?C&&!d?e.jsxs("div",{className:"flex items-center justify-center px-3 py-4 text-[11px] text-muted-foreground",children:[e.jsx(me,{className:"mr-1.5 h-3 w-3 animate-spin"}),"Loading..."]}):d&&!d.available?e.jsx("div",{className:"px-3 py-4 text-center text-[11px] text-muted-foreground",children:"Not a git repository."}):e.jsx(e.Fragment,{children:e.jsxs("div",{className:"space-y-2 px-3 py-2.5",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(Le,{value:R,onChange:_=>L(_.target.value),placeholder:"New branch name",className:"h-8 flex-1 rounded-md border-border/60 bg-background/70 font-mono text-[11px]"}),e.jsx(M,{type:"button",size:"sm",onClick:()=>void oe(),disabled:!te,title:te?"Create branch":"Enter a name and pick a base","aria-label":"Create branch",className:"h-8 w-8 shrink-0 rounded-md p-0",children:O?e.jsx(me,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(Hn,{className:"h-3.5 w-3.5"})})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("span",{className:"text-[10px] text-muted-foreground",children:"Base from"}),!Y&&e.jsxs("button",{type:"button",onClick:()=>U(!0),className:"flex items-center gap-1 rounded px-1 py-0.5 text-[10px] text-muted-foreground hover:bg-background/60 hover:text-foreground",children:[e.jsx(Nt,{className:"h-2.5 w-2.5"}),"Manual"]})]}),Y?e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(Le,{value:S,onChange:_=>V(_.target.value),placeholder:"upstream/release/1.0",className:"h-8 flex-1 rounded-md border-border/60 bg-background/70 font-mono text-[11px]"}),e.jsx("button",{type:"button",onClick:()=>{U(!1),V("")},className:"flex h-8 w-8 shrink-0 items-center justify-center rounded-md text-muted-foreground hover:bg-background/60 hover:text-foreground",title:"Cancel manual input","aria-label":"Cancel manual input",children:e.jsx(qe,{className:"h-3.5 w-3.5"})})]}):d!=null&&d.branches.length?e.jsxs("div",{className:"max-h-44 overflow-y-auto rounded-md border border-border/40 bg-background/40",children:[d.branches.map(_=>{const P=I===_.ref,E=_.branch==="main"||_.branch==="master";return e.jsxs("button",{type:"button",onClick:()=>ee(_.ref),className:A("flex w-full items-center gap-2 border-b border-border/20 px-2.5 py-1.5 text-left text-[11px] last:border-b-0 hover:bg-background/60",P&&"bg-background/70"),title:_.ref,children:[e.jsx("span",{className:A("shrink-0 text-[10px]",E?"text-amber-500 dark:text-amber-400":"text-muted-foreground/60"),"aria-hidden":!0,children:E?"★":"·"}),e.jsx("span",{className:"min-w-0 flex-1 truncate font-mono text-foreground",children:_.ref}),P?e.jsx(Pe,{className:"h-3 w-3 shrink-0 text-primary"}):null]},_.ref)}),d.hasMore&&e.jsxs("button",{type:"button",onClick:de,disabled:w,className:"flex w-full items-center justify-center gap-1 border-t border-border/20 py-1 text-[10px] text-muted-foreground hover:bg-background/60 hover:text-foreground disabled:opacity-50",children:[w?e.jsx(me,{className:"h-3 w-3 animate-spin"}):e.jsx(Ot,{className:"h-3 w-3"}),"Load more"]})]}):e.jsx("div",{className:"rounded-md border border-dashed border-border/40 px-2.5 py-2 text-[11px] text-muted-foreground",children:"No remote branches found."})]})]})}):e.jsx("div",{className:"px-3 py-4 text-center text-[11px] text-muted-foreground",children:"Select a specific node first."}),H&&e.jsx("div",{className:"border-t border-destructive/20 bg-destructive/10 px-3 py-1.5 text-[11px] text-destructive",children:H})]})]})}const El=20,Dl=3,Ts="meshy-working-dir-recents-by-node";function Ml(t){return t.startsWith("/")||t.startsWith("\\\\")||/^[A-Za-z]:[\\/]/.test(t)}function Pl(t){const s=t.trim();return s||"."}function Kt(t){const s=[],r=new Set;for(const a of t){const n=a.trim();if(!(!n||r.has(n))&&(r.add(n),s.push(n),s.length===Dl))break}return s}function $l(t,s){const r=s.trim();return Kt(r?[r,...t]:t)}function Rl(t){if(!t||typeof t!="object"||Array.isArray(t))return{};const s={};for(const[r,a]of Object.entries(t)){if(!r||!Array.isArray(a))continue;const n=a.filter(c=>typeof c=="string"),l=Kt(n);l.length>0&&(s[r]=l)}return s}function Ll(t,s,r){if(!s)return t;const a=t[s]??[],n=$l(a,r);if(n.length===0){if(!(s in t))return t;const{[s]:l,...c}=t;return c}return{...t,[s]:n}}function Il(t,s,r){return t!=="auto"?s.find(a=>a.id===t)??null:r.length===1?r[0]??null:null}function Fl(t,s){const r=s.trim();return r?Ml(r)||!t?r:`${t.replace(/[/\\]+$/,"")}/${r}`:""}function Ol(t,s){return t?t.isAbsolute?t.currentPath:t.currentPath==="."||t.currentPath===""?t.rootPath||(s==null?void 0:s.workDir)||"Node root":t.currentPath:(s==null?void 0:s.workDir)??"Node root"}function Es({value:t,onChange:s,assignTo:r,nodes:a,assignableNodes:n,layout:l="default",chipClassName:c,chipActiveClassName:u,chipInactiveClassName:x,labelClassName:h,triggerClassName:m}){const[f,p]=o.useState(!1),[g,d]=o.useState(null),[N,C]=o.useState(!1),[j,w]=o.useState(!1),[D,O]=o.useState(null),[T,H]=o.useState(""),[K,R]=o.useState(!1),[L,I]=o.useState({}),ee=o.useRef(null),S=o.useMemo(()=>Il(r,a,n),[r,a,n]),V=S==null?void 0:S.id,Y=o.useMemo(()=>V?L[V]??[]:[],[L,V]),U=o.useMemo(()=>t.trim()?Fl(S==null?void 0:S.workDir,t):"Use node default",[t,S==null?void 0:S.workDir]);o.useEffect(()=>{if(!(typeof window>"u"))try{const y=window.localStorage.getItem(Ts);if(!y)return;const _=JSON.parse(y);I(Rl(_))}catch{}},[]);const ie=o.useCallback(y=>{V&&I(_=>{const P=Ll(_,V,y);if(P===_)return _;if(typeof window<"u")try{window.localStorage.setItem(Ts,JSON.stringify(P))}catch{}return P})},[V]),q=o.useCallback((y,_=!0)=>{const P=y.trim();s(P),_&&P&&ie(P),p(!1)},[s,ie]),F=o.useCallback(async(y,_=0,P=!1)=>{if(V){O(null),P?w(!0):C(!0);try{const E=await $a(V,{path:y,limit:El,offset:_,directoriesOnly:!0,allowAbsolute:!0});d(v=>P&&v?{...E,entries:[...v.entries,...E.entries]}:E)}catch(E){O(E instanceof Error?E.message:"Failed to browse directories"),P||d(null)}finally{C(!1),w(!1)}}},[V]),X=o.useRef(t);X.current=t;const xe=o.useRef(F);xe.current=F,o.useEffect(()=>{if(!f)return;const y=X.current;H(y),R(!1),d(null),O(null),V&&xe.current(Pl(y))},[f,V]),o.useEffect(()=>{if(!f)return;const y=P=>{ee.current&&(ee.current.contains(P.target)||p(!1))},_=P=>{P.key==="Escape"&&p(!1)};return document.addEventListener("mousedown",y),document.addEventListener("keydown",_),()=>{document.removeEventListener("mousedown",y),document.removeEventListener("keydown",_)}},[f]);const oe=o.useCallback(y=>{F(y)},[F]),de=o.useCallback(()=>{g&&F(g.currentPath,g.entries.length,!0)},[g,F]),Z=l==="composer"?e.jsxs(M,{type:"button",variant:"ghost",onClick:()=>p(y=>!y),title:U,"aria-label":`Working directory: ${U}`,className:A(c,m,"min-w-0 max-w-full",t.trim()?u:x),children:[e.jsx(Ra,{className:"h-3.5 w-3.5 shrink-0"}),e.jsx("span",{className:A("min-w-0 truncate",h),children:U})]}):e.jsxs(M,{type:"button",variant:"outline",onClick:()=>p(y=>!y),className:"h-11 w-full justify-between rounded-2xl border-border/70 bg-background/70 px-4",title:U,children:[e.jsx("span",{className:A("truncate",t.trim()?"font-mono text-foreground":"text-muted-foreground"),children:U}),e.jsx("span",{className:"ml-3 shrink-0 text-xs text-muted-foreground",children:S?S.name:"Manual"})]}),ce=Ol(g,S),te=!!(g!=null&&g.parentPath);return e.jsxs("div",{className:A("relative inline-block",l==="composer"?"min-w-0 max-w-[60%] shrink":"w-full"),ref:ee,children:[l==="default"?e.jsxs("div",{className:"space-y-2",children:[e.jsx(Ee,{className:"text-sm font-medium",children:"Working directory"}),Z]}):Z,f&&e.jsxs("div",{className:A("absolute z-50 mt-2 w-[240px] overflow-hidden rounded-2xl border border-border/60 bg-background/95 shadow-lg backdrop-blur",l==="composer"?"left-0":"left-0 right-0 w-auto min-w-[240px]"),children:[Y.length>0&&e.jsxs("div",{className:"border-b border-border/60 px-3 py-2",children:[e.jsxs("div",{className:"mb-1 flex items-center gap-1 text-[10px] text-muted-foreground",children:[e.jsx(Ot,{className:"h-2.5 w-2.5"}),"Recent"]}),e.jsx("div",{className:"flex flex-col",children:Y.map(y=>e.jsx("button",{type:"button",onClick:()=>q(y,!1),className:"truncate rounded px-1.5 py-0.5 text-left font-mono text-[11px] text-foreground hover:bg-background/60",title:y,children:y},y))})]}),e.jsxs("div",{className:"flex items-center gap-1.5 border-b border-border/60 px-2.5 py-1.5",children:[e.jsx("button",{type:"button",onClick:()=>(g==null?void 0:g.parentPath)&&oe(g.parentPath),disabled:!te||N,className:"flex h-6 w-6 shrink-0 items-center justify-center rounded-md border border-border/60 text-muted-foreground transition-colors hover:bg-background/60 hover:text-foreground disabled:opacity-40",title:"Parent directory",children:e.jsx(mn,{className:"h-3 w-3"})}),e.jsx("div",{className:"min-w-0 flex-1 truncate font-mono text-[11px] text-muted-foreground",title:ce,children:ce}),g&&e.jsx("button",{type:"button",onClick:()=>q(g.isAbsolute?g.currentPath:g.currentPath==="."?"":g.currentPath),className:"shrink-0 rounded px-1.5 py-0.5 text-[10px] font-medium text-foreground hover:bg-background/60",title:"Use this folder",children:"Use"})]}),e.jsxs("div",{className:"max-h-56 overflow-y-auto",children:[S?N?e.jsxs("div",{className:"flex items-center justify-center px-3 py-4 text-[11px] text-muted-foreground",children:[e.jsx(me,{className:"mr-1.5 h-3 w-3 animate-spin"}),"Loading..."]}):g&&g.entries.length>0?e.jsxs(e.Fragment,{children:[g.entries.map(y=>e.jsxs("div",{className:"group flex items-stretch border-b border-border/30 last:border-b-0",children:[e.jsxs("button",{type:"button",onClick:()=>q(y.path),className:"flex min-w-0 flex-1 items-center gap-2 px-2.5 py-1.5 text-left hover:bg-background/55",title:`Use ${y.path}`,children:[e.jsx(wn,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}),e.jsx("span",{className:"truncate text-[11px] text-foreground",children:y.name})]}),e.jsx("button",{type:"button",onClick:()=>oe(y.path),className:"flex w-9 shrink-0 items-center justify-center border-l border-border/30 text-muted-foreground hover:bg-background/70 hover:text-foreground",title:"Open subfolder","aria-label":`Open ${y.name}`,children:e.jsx(Ze,{className:"h-3.5 w-3.5"})})]},y.path)),g.hasMore&&e.jsxs("button",{type:"button",onClick:de,disabled:j,className:"flex w-full items-center justify-center gap-1 border-t border-border/40 py-1 text-[10px] text-muted-foreground hover:bg-background/60 hover:text-foreground disabled:opacity-50",children:[j?e.jsx(me,{className:"h-3 w-3 animate-spin"}):e.jsx(Ot,{className:"h-3 w-3"}),"Load more"]})]}):e.jsx("div",{className:"px-3 py-4 text-center text-[11px] text-muted-foreground",children:D??"No subfolders."}):e.jsx("div",{className:"px-3 py-4 text-center text-[11px] text-muted-foreground",children:"Select a node to browse."}),D&&g&&g.entries.length>0&&e.jsx("div",{className:"border-t border-border/60 px-3 py-1.5 text-[11px] text-destructive",children:D})]}),e.jsx("div",{className:"flex items-center gap-1 border-t border-border/60 bg-background/40 px-2.5 py-1.5",children:K?e.jsxs(e.Fragment,{children:[e.jsx(Le,{value:T,onChange:y=>H(y.target.value),onKeyDown:y=>{y.key==="Enter"&&T.trim()?(y.preventDefault(),q(T)):y.key==="Escape"&&(y.preventDefault(),R(!1),H(t))},autoFocus:!0,placeholder:"Path (relative or absolute)",className:"h-7 flex-1 rounded-md border-border/60 bg-background/70 font-mono text-[11px]"}),e.jsx("button",{type:"button",onClick:()=>q(T),disabled:!T.trim(),className:"flex h-7 w-7 shrink-0 items-center justify-center rounded-md text-foreground hover:bg-background/60 disabled:opacity-40",title:"Apply","aria-label":"Apply manual path",children:e.jsx(Pe,{className:"h-3.5 w-3.5"})}),e.jsx("button",{type:"button",onClick:()=>{R(!1),H(t)},className:"flex h-7 w-7 shrink-0 items-center justify-center rounded-md text-muted-foreground hover:bg-background/60 hover:text-foreground",title:"Cancel","aria-label":"Cancel manual path",children:e.jsx(qe,{className:"h-3.5 w-3.5"})})]}):e.jsxs("button",{type:"button",onClick:()=>{H(t),R(!0)},className:"flex h-7 flex-1 items-center justify-between rounded-md px-1.5 text-[11px] text-muted-foreground hover:bg-background/60 hover:text-foreground",title:"Enter a manual path",children:[e.jsx("span",{children:"Manual input"}),e.jsx(Nt,{className:"h-3 w-3"})]})})]})]})}function Ul(t,s={}){const r=t.filter(a=>a.status==="online");return s.currentNodeRole!=="follower"||!s.leaderNodeId?r:r.filter(a=>a.id!==s.leaderNodeId)}function Ds(){return rs.map(t=>e.jsx(je,{value:t.value,disabled:t.disabled,children:e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx("span",{children:t.label}),t.description&&e.jsx("span",{className:"text-[10px] uppercase tracking-[0.18em] text-muted-foreground",children:t.description})]})},t.value))}function Ms(){return Er.map(t=>e.jsx(je,{value:t.value,children:e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx("span",{children:t.label}),t.description&&e.jsx("span",{className:"text-[10px] uppercase tracking-[0.18em] text-muted-foreground",children:t.description})]})},t.value))}function Dr({isCurrent:t}){return t?e.jsx(Pn,{className:"h-3.5 w-3.5 shrink-0 text-emerald-500 dark:text-emerald-400","aria-label":"current node"}):e.jsx(Tn,{className:"h-3.5 w-3.5 shrink-0 text-sky-500 dark:text-sky-400","aria-label":"remote follower node"})}function Ps(t,s){return t.map(r=>{const a=!!s&&r.id===s;return e.jsx(je,{value:r.id,children:e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx(Dr,{isCurrent:a}),e.jsx("span",{className:"truncate",children:r.name}),e.jsx("span",{className:"text-[10px] uppercase tracking-[0.18em] text-muted-foreground",children:a?"current":"remote"})]})},r.id)})}function Bl(t){var s;return((s=rs.find(r=>r.value===t))==null?void 0:s.label)??t}function zl(t){var s;return((s=Er.find(r=>r.value===t))==null?void 0:s.label)??t}function Mr(t,s,r=!1){const a=t.trim();if(a)return a;const n=s.trim().split(`
182
+ `).map(l=>l.trim()).find(Boolean);return n?n.length>72?`${n.slice(0,69).trimEnd()}...`:n:r?"Image task":""}function Vl(t){var l;const s=Mr(t.title,t.description,t.images.length>0),r=t.description.trim()||s,a=t.mode??Ht,n=rr(t.description,t.images);return!s||!r||!t.agent?null:{title:s,description:r,agent:t.agent,project:t.project.trim()||null,branch:((l=t.branch)==null?void 0:l.trim())||null,payload:{initialMessage:n,mode:a},priority:t.priority,assignTo:t.assignTo==="auto"?void 0:t.assignTo}}function ql({nodes:t,currentNodeRole:s,currentNodeId:r,leaderNodeId:a,onCreated:n,onCancel:l,className:c,footerClassName:u,submitLabel:x="Create chat",cancelLabel:h="Cancel",autoFocus:m=!1,layout:f="default"}){const[p,g]=o.useState(""),[d,N]=o.useState(""),[C,j]=o.useState("claudecode"),[w,D]=o.useState(Ht),[O,T]=o.useState(""),[H,K]=o.useState(""),[R,L]=o.useState("normal"),I=o.useMemo(()=>Ul(t,{currentNodeRole:s,leaderNodeId:a}),[t,s,a]),ee=o.useMemo(()=>{var $;return r&&I.some(he=>he.id===r)?r:(($=I[0])==null?void 0:$.id)??""},[I,r]),[S,V]=o.useState(ee),[Y,U]=o.useState(!1),[ie,q]=o.useState(!1),{images:F,error:X,fileInputRef:xe,pickImages:oe,handleFileChange:de,handlePaste:Z,removeImage:ce}=lr(),te=o.useMemo(()=>I.find($=>$.id===S)??null,[S,I]),y=!!(r&&(te==null?void 0:te.id)===r),_=Bl(C),P=zl(w);o.useEffect(()=>{S&&I.some($=>$.id===S)||V(ee)},[S,I,ee]),o.useEffect(()=>{T(""),K("")},[S]),o.useEffect(()=>{K("")},[O]);const E=o.useCallback(async $=>{$.preventDefault();const he=Vl({title:p,description:d,agent:C,project:O,branch:H,priority:R,assignTo:S,mode:w,images:F});if(he){U(!0);try{const be=await La(he);n(be)}catch(be){le.error(be instanceof Error?be.message:"Failed to create task")}finally{U(!1)}}},[p,d,C,O,H,R,S,w,F,n]),v=Mr(p,d,F.length>0),re=!!(v&&C&&S&&(d.trim()||F.length>0)),J=o.useCallback($=>{var he;$.nativeEvent.isComposing||$.key==="Enter"&&($.ctrlKey||$.metaKey)&&re&&!Y&&($.preventDefault(),(he=$.currentTarget.form)==null||he.requestSubmit())},[re,Y]),Q=F.length>0&&e.jsx("div",{className:"flex flex-wrap gap-3",children:F.map(($,he)=>e.jsxs("div",{className:"relative",children:[e.jsx("img",{src:es($),alt:$.filename??`attachment ${he+1}`,className:"h-24 w-24 rounded-2xl border border-border/70 object-cover"}),e.jsx("button",{type:"button",onClick:()=>ce(he),className:"absolute -top-2 -right-2 flex h-6 w-6 items-center justify-center rounded-full border border-border/70 bg-background text-muted-foreground transition-colors hover:text-foreground","aria-label":`Remove ${$.filename??`image ${he+1}`}`,children:e.jsx(qe,{className:"h-3.5 w-3.5"})})]},`${$.filename??"image"}-${he}`))}),ae=e.jsxs("div",{className:"space-y-2",children:[e.jsx(Ee,{className:"text-sm font-medium",children:"Assign to"}),e.jsxs(ke,{value:S,onValueChange:V,children:[e.jsx(we,{className:"h-11 rounded-2xl border-border/70 bg-background/70",children:e.jsx(Me,{placeholder:"Select node"})}),e.jsx(Ce,{children:Ps(I,r)})]})]}),ve=e.jsxs("div",{className:"space-y-2",children:[e.jsx(Ee,{className:"text-sm font-medium",children:"Agent"}),e.jsxs(ke,{value:C,onValueChange:j,children:[e.jsx(we,{className:"h-11 rounded-2xl border-border/70 bg-background/70",children:e.jsx(Me,{placeholder:"Select agent"})}),e.jsx(Ce,{children:Ds()})]})]}),Se=e.jsxs("div",{className:"space-y-2",children:[e.jsx(Ee,{className:"text-sm font-medium",children:"Mode"}),e.jsxs(ke,{value:w,onValueChange:$=>D($),children:[e.jsx(we,{className:"h-11 rounded-2xl border-border/70 bg-background/70",children:e.jsx(Me,{placeholder:"Select mode"})}),e.jsx(Ce,{children:Ms()})]})]}),ue=e.jsxs("div",{className:"space-y-2",children:[e.jsx(Ee,{className:"text-sm font-medium",children:"Priority"}),e.jsxs(ke,{value:R,onValueChange:L,children:[e.jsx(we,{className:"h-11 rounded-2xl border-border/70 bg-background/70",children:e.jsx(Me,{placeholder:"Select priority"})}),e.jsxs(Ce,{children:[e.jsx(je,{value:"low",children:"Low"}),e.jsx(je,{value:"normal",children:"Normal"}),e.jsx(je,{value:"high",children:"High"}),e.jsx(je,{value:"critical",children:"Critical"})]})]})]}),ge=e.jsx(Es,{value:O,onChange:T,assignTo:S,nodes:t,assignableNodes:I}),St=e.jsx(As,{value:H,onChange:K,project:O,assignTo:S,nodes:t,assignableNodes:I});return f==="composer"?e.jsxs("form",{onSubmit:E,className:A("space-y-4",c),children:[e.jsx("input",{ref:xe,type:"file",accept:"image/*",multiple:!0,onChange:de,className:"hidden"}),(()=>{const $="chat-composer__chip h-9 w-auto gap-1.5 rounded-full px-3.5 text-xs shadow-none transition-colors",he="border-transparent bg-transparent text-muted-foreground hover:bg-background/40 hover:text-foreground",be="border-border/70 bg-background/55 text-foreground",Te=C==="claudecode",De=w===Ht;return e.jsxs("div",{className:"chat-composer space-y-2",children:[e.jsxs("div",{className:"rounded-[24px] border border-border/60 bg-background/45 shadow-[0_20px_80px_-40px_rgba(0,0,0,0.6)]",children:[e.jsxs("div",{className:"chat-composer__header flex min-w-0 items-center justify-between gap-3 px-4 pt-3",children:[e.jsxs(ke,{value:S,onValueChange:V,children:[e.jsx(we,{className:A($,be,"chat-composer__node-trigger border-transparent bg-transparent hover:bg-background/40"),title:`Assigned node: ${(te==null?void 0:te.name)??"unassigned"}`,"aria-label":`Assigned node: ${(te==null?void 0:te.name)??"unassigned"}`,children:te?e.jsxs(e.Fragment,{children:[e.jsx(Dr,{isCurrent:y}),e.jsx("span",{className:"min-w-0 truncate",children:te.name}),e.jsx("span",{className:"chat-composer__header-meta shrink-0 text-[10px] uppercase tracking-[0.18em] text-muted-foreground",children:y?"current":"remote"})]}):e.jsx(Me,{placeholder:"Select node"})}),e.jsx(Ce,{children:Ps(I,r)})]}),ie?e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(Le,{id:"task-title-composer",type:"text",value:p,onChange:pe=>g(pe.target.value),onKeyDown:pe=>{(pe.key==="Enter"||pe.key==="Escape")&&(pe.preventDefault(),q(!1))},autoFocus:!0,placeholder:"Chat title",className:"h-8 w-48 min-w-0 rounded-full border-border/70 bg-background/55 px-3 text-xs shadow-none"}),e.jsx(M,{type:"button",variant:"ghost",size:"icon",onClick:()=>q(!1),"aria-label":"Save title",className:"h-8 w-8 shrink-0 rounded-full text-muted-foreground hover:text-foreground",children:e.jsx(Pe,{className:"h-3.5 w-3.5"})})]}):e.jsxs("button",{type:"button",onClick:()=>q(!0),className:"chat-composer__title-button flex min-w-0 items-center gap-1.5 rounded-full px-2 py-1 text-xs text-muted-foreground transition-colors hover:bg-background/55 hover:text-foreground",title:v||"Title","aria-label":v?`Edit title: ${v}`:"Edit title",children:[e.jsx("span",{className:"chat-composer__title-text max-w-[220px] truncate",children:v||"Title"}),e.jsx(Nt,{className:"h-3 w-3 shrink-0"})]})]}),e.jsx("textarea",{id:"task-description",value:d,onChange:pe=>N(pe.target.value),onKeyDown:J,onPaste:Z,placeholder:"Ask anything...",rows:4,autoFocus:m,"aria-label":"Opening prompt",className:"min-h-[140px] w-full resize-none rounded-[24px] bg-transparent px-5 pt-2 pb-2 text-[15px] leading-7 text-foreground ring-offset-background placeholder:text-muted-foreground/70 focus-visible:outline-none"}),e.jsxs("div",{className:"chat-composer__rail flex flex-nowrap items-center gap-2 px-3 pb-3",children:[e.jsx(M,{type:"button",variant:"ghost",size:"icon",onClick:oe,"aria-label":"Add images",className:"h-9 w-9 shrink-0 rounded-full text-muted-foreground hover:text-foreground",children:e.jsx(Ut,{className:"h-4 w-4"})}),e.jsx("span",{className:"mx-0.5 h-5 w-px bg-border/60","aria-hidden":!0}),e.jsxs(ke,{value:C,onValueChange:j,children:[e.jsxs(we,{className:A($,"chat-composer__icon-trigger",Te?he:be),title:`Agent: ${_}`,"aria-label":`Agent: ${_}`,children:[e.jsx(Yt,{className:"h-3.5 w-3.5 shrink-0"}),e.jsx("span",{className:"chat-composer__footer-label truncate",children:_})]}),e.jsx(Ce,{children:Ds()})]}),e.jsxs(ke,{value:w,onValueChange:pe=>D(pe),children:[e.jsxs(we,{className:A($,"chat-composer__icon-trigger",De?he:be),title:`Mode: ${P}`,"aria-label":`Mode: ${P}`,children:[e.jsx(so,{className:"h-3.5 w-3.5 shrink-0"}),e.jsx("span",{className:"chat-composer__footer-label truncate",children:P})]}),e.jsx(Ce,{children:Ms()})]}),e.jsxs("div",{className:"ml-auto flex shrink-0 items-center gap-2",children:[e.jsxs(ke,{value:R,onValueChange:L,children:[e.jsx(we,{"aria-label":`Priority: ${R}`,title:`Priority: ${R}`,className:A("h-9 w-9 justify-center gap-0 rounded-full p-0 text-xs shadow-none [&>svg:last-child]:hidden",R==="normal"?"border-transparent bg-transparent text-muted-foreground hover:bg-background/40":"border-border/70 bg-background/55",R==="critical"&&"text-destructive",R==="high"&&"text-amber-600 dark:text-amber-400",R==="low"&&"text-muted-foreground"),children:e.jsx(Nn,{className:A("h-4 w-4",R==="critical"&&"fill-destructive/20")})}),e.jsxs(Ce,{children:[e.jsx(je,{value:"low",children:"Low"}),e.jsx(je,{value:"normal",children:"Normal"}),e.jsx(je,{value:"high",children:"High"}),e.jsx(je,{value:"critical",children:"Critical"})]})]}),l&&e.jsxs(M,{type:"button",variant:"ghost",size:"sm",onClick:l,"aria-label":h,className:"chat-composer__cancel h-9 rounded-full px-4 text-xs text-muted-foreground",children:[e.jsx(qe,{className:"chat-composer__cancel-icon h-4 w-4 shrink-0"}),e.jsx("span",{className:"chat-composer__footer-label",children:h})]}),e.jsxs(M,{type:"submit",size:"icon",disabled:!re||Y,className:"h-10 w-10 rounded-full shadow-[0_8px_30px_-8px_hsl(var(--primary)/0.6)]",children:[Y?e.jsx(me,{className:"h-4 w-4 animate-spin"}):e.jsx(Qs,{className:"h-4 w-4"}),e.jsx("span",{className:"sr-only",children:Y?"Creating chat":x})]})]})]})]}),e.jsx("div",{className:"chat-composer__location flex flex-wrap items-center gap-2 px-1",children:(()=>{const pe="border-border/40 bg-muted/40 text-foreground/80 hover:bg-muted/60 hover:text-foreground";return e.jsxs(e.Fragment,{children:[e.jsx(Es,{value:O,onChange:T,assignTo:S,nodes:t,assignableNodes:I,layout:"composer",chipClassName:$,chipActiveClassName:pe,chipInactiveClassName:pe,triggerClassName:"chat-composer__icon-trigger",labelClassName:"chat-composer__location-label"}),e.jsx(As,{value:H,onChange:K,project:O,assignTo:S,nodes:t,assignableNodes:I,layout:"composer",chipClassName:$,chipActiveClassName:pe,chipInactiveClassName:pe,triggerClassName:"chat-composer__icon-trigger",labelClassName:"chat-composer__location-label"})]})})()})]})})(),(Q||X)&&e.jsxs("div",{className:"space-y-3 rounded-[20px] border border-border/60 bg-background/45 p-4",children:[Q,X&&e.jsx("div",{className:"text-xs text-destructive",children:X}),!X&&e.jsx("div",{className:"text-xs text-muted-foreground",children:"Ctrl/Cmd+Enter starts the chat. Enter adds a new line. Paste screenshots directly into the prompt box or use the Images button."})]})]}):e.jsxs("form",{onSubmit:E,className:A("space-y-5",c),children:[e.jsx("input",{ref:xe,type:"file",accept:"image/*",multiple:!0,onChange:de,className:"hidden"}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(Ee,{htmlFor:"task-description",className:"text-sm font-medium",children:"Opening prompt"}),e.jsx("textarea",{id:"task-description",value:d,onChange:$=>N($.target.value),onKeyDown:J,onPaste:Z,placeholder:"Describe what the agent should do. This becomes the first message in the chat.",rows:6,autoFocus:m,className:"flex min-h-[144px] w-full resize-none rounded-[22px] border border-border/70 bg-background/70 px-4 py-3 text-sm leading-6 ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2"}),e.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[e.jsxs(M,{type:"button",variant:"outline",onClick:oe,className:"rounded-2xl",children:[e.jsx(Ut,{className:"h-4 w-4"}),"Add images"]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Ctrl/Cmd+Enter starts the chat. Enter adds a new line. Upload or paste screenshots and reference images with the opening prompt."})]}),Q,X&&e.jsx("p",{className:"text-xs text-destructive",children:X})]}),e.jsxs("div",{className:"grid gap-5 lg:grid-cols-[minmax(0,1fr)_220px_220px]",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(Ee,{htmlFor:"task-title",className:"text-sm font-medium",children:"Chat title"}),e.jsx(Le,{id:"task-title",type:"text",value:p,onChange:$=>g($.target.value),placeholder:"Optional. Leave blank to derive it from the prompt.",className:"h-11 rounded-2xl border-border/70 bg-background/70"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:v?`Will appear as: ${v}`:"A title will be generated from the first line of the prompt."})]}),ve,Se]}),ge,St,e.jsxs("div",{className:"grid gap-5 md:grid-cols-2",children:[ue,ae]}),e.jsxs("div",{className:A("flex flex-col-reverse gap-2 sm:flex-row sm:justify-end",u),children:[l&&e.jsx(M,{type:"button",variant:"ghost",onClick:l,className:"rounded-2xl",children:h}),e.jsx(M,{type:"submit",disabled:!re||Y,className:"rounded-2xl px-5",children:Y?"Creating...":x})]})]})}const Wl=[{value:"active",label:"Active"},{value:"running",label:"Running"},{value:"waiting",label:"Waiting"},{value:"closed",label:"Closed"},{value:"archived",label:"Archived"}],jt=new Set(["pending","assigned"]),Pr=new Set(["running"]),Hl=new Set(["completed","failed","cancelled"]);function Kl(t,s){switch(s){case"running":return Pr.has(t.status);case"waiting":return jt.has(t.status);case"closed":return Hl.has(t.status);case"archived":return t.status==="archived";case"active":default:return t.status!=="archived"}}function Jl(t,s){const r=s.trim().toLowerCase();return r?[t.title,t.description,t.id,t.agent,t.assignedTo??"",t.assignedNodeName??"",t.project??"",t.effectiveProjectPath??""].some(a=>a.toLowerCase().includes(r)):!0}function as(t,s,r){if(!t)return"unassigned";const a=s==null?void 0:s.find(n=>n.id===t);return(a==null?void 0:a.name)??r??t.slice(0,8)}function Gl(t,s,r){return as(t,s,r).toLowerCase()}function Yl(t,s){return[...t].sort((r,a)=>r.id===s?-1:a.id===s?1:r.name.localeCompare(a.name))}function Xl(t){if(!t||typeof t!="object")return null;const s=t;return{draftNewTask:s.draftNewTask===!0,returnRoute:typeof s.returnRoute=="string"?s.returnRoute:void 0,returnTaskId:typeof s.returnTaskId=="string"||s.returnTaskId===null?s.returnTaskId:void 0}}function Zl(t){switch(t){case"running":return"bg-amber-500";case"completed":return"bg-emerald-500";case"failed":return"bg-destructive";case"cancelled":case"archived":return"bg-slate-400";case"assigned":return"bg-teal-500";case"pending":default:return"bg-muted-foreground"}}function Ql(t){return t==="default workspace"?t:t.replace(/\\/g,"/").split("/").filter(Boolean).at(-1)??t}function ei(t){const s=Date.now()-t;return s<6e4?"just now":s<36e5?`${Math.floor(s/6e4)}m`:s<864e5?`${Math.floor(s/36e5)}h`:`${Math.floor(s/864e5)}d`}function ti(t){return new Date(t).toLocaleString()}function si(t){const s=Math.floor(t/1e3),r=Math.floor(s/3600),a=Math.floor(s%3600/60),n=s%60;return`${String(r).padStart(2,"0")}:${String(a).padStart(2,"0")}:${String(n).padStart(2,"0")}`}async function He(t,s="Copied to clipboard"){var r,a,n;try{if((a=(r=globalThis.navigator)==null?void 0:r.clipboard)!=null&&a.writeText)return await globalThis.navigator.clipboard.writeText(t),le.success(s),!0;const l=globalThis.document,c=(n=l==null?void 0:l.execCommand)==null?void 0:n.bind(l);if(!(l!=null&&l.body)||typeof l.createElement!="function"||typeof c!="function")throw new Error("Clipboard access is unavailable");const u=l.createElement("textarea"),x=l.activeElement,h=x&&typeof x.focus=="function"?x:null;u.value=t,u.setAttribute("readonly","true"),u.style.position="fixed",u.style.opacity="0",u.style.pointerEvents="none",l.body.appendChild(u),u.select(),u.setSelectionRange(0,u.value.length);const m=c("copy");if(l.body.removeChild(u),h==null||h.focus(),!m)throw new Error("Clipboard access is unavailable");return le.success(s),!0}catch(l){return le.error(l instanceof Error?l.message:"Failed to copy"),!1}}function ri(t,s){const r=new Map;for(const n of t){const l=n.assignedTo??null,c=l??"__unassigned__",u=l?s.get(l)??n.assignedNodeName??l.slice(0,8):"Unassigned",x=n.effectiveProjectPath??n.project??"default workspace";r.has(c)||r.set(c,{nodeId:l,nodeName:u,dirMap:new Map});const h=r.get(c);h.dirMap.has(x)||h.dirMap.set(x,[]),h.dirMap.get(x).push(n)}const a=Array.from(r.values()).map(({nodeId:n,nodeName:l,dirMap:c})=>{const u=Array.from(c.entries()).map(([x,h])=>({path:x,tasks:h})).sort((x,h)=>h.tasks.length-x.tasks.length||x.path.localeCompare(h.path));return{nodeId:n,nodeName:l,dirs:u}});return a.sort((n,l)=>n.nodeId===null?1:l.nodeId===null?-1:n.nodeName.localeCompare(l.nodeName)),a}function Be({label:t,value:s}){return e.jsxs("div",{className:"min-w-[7.25rem] flex-1 rounded-[20px] border border-border/60 bg-background/45 px-3 py-3",children:[e.jsx("div",{className:"text-[10px] font-medium uppercase tracking-[0.22em] text-muted-foreground",children:t}),e.jsx("div",{className:"mt-1 text-lg font-semibold tracking-tight text-foreground",children:s})]})}function Lt({label:t}){return e.jsx("div",{className:"flex h-64 items-center justify-center text-sm text-muted-foreground",children:t})}function Ae({label:t,value:s,mono:r,action:a}){return e.jsxs("div",{className:"grid grid-cols-[5.25rem,minmax(0,1fr)] items-start gap-3",children:[e.jsx("span",{className:"pt-0.5 text-[11px] font-medium uppercase tracking-[0.18em] text-muted-foreground",children:t}),e.jsxs("div",{className:"flex min-w-0 items-start gap-2",children:[e.jsx("span",{className:A("min-w-0 flex-1 break-all text-sm text-foreground",r&&"font-mono text-[11px] leading-5"),children:s}),a]})]})}function Jt({label:t,value:s,mono:r}){return e.jsxs("div",{className:"rounded-[18px] border border-border/60 bg-background/60 px-3 py-3",children:[e.jsx("div",{className:"text-[10px] font-medium uppercase tracking-[0.22em] text-muted-foreground",children:t}),e.jsx("div",{className:A("mt-1 text-sm font-medium text-foreground",r&&"font-mono text-[11px]"),children:s})]})}function $r({capabilities:t,action:s}){return e.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-start sm:justify-between sm:gap-4",children:[e.jsxs("div",{className:"min-w-0 flex-1 space-y-2",children:[e.jsx("div",{className:"text-[11px] font-medium uppercase tracking-[0.22em] text-muted-foreground",children:"Capabilities"}),e.jsx("div",{className:"flex flex-wrap items-center gap-2 text-xs",children:t.length>0?t.map(r=>e.jsx(ye,{variant:"secondary",className:"rounded-full",children:r},r)):e.jsx("span",{className:"text-sm text-muted-foreground",children:"None declared"})})]}),s&&e.jsx("div",{className:"shrink-0 self-start",children:s})]})}const ai=o.lazy(async()=>({default:(await Xt(()=>import("./FilesTab-BTvBjcVj.js"),__vite__mapDeps([0,1,2,3]))).FilesTab})),ni=o.lazy(async()=>({default:(await Xt(()=>import("./PreviewTab-K1eOyj6G.js"),__vite__mapDeps([4,1,2]))).PreviewTab})),oi=o.lazy(async()=>({default:(await Xt(()=>import("./DiffTab-Cp1x6gu_.js"),__vite__mapDeps([5,1,2,3]))).DiffTab}));function li({onToggleTasks:t,desktopTasksOpen:s,mobileTasksPanelOpen:r,operationsOpen:a,onToggleOperations:n,cluster:l,sseConnected:c,activeTab:u,setActiveTab:x,creatingTask:h,activeTask:m,assignedNode:f,taskLoading:p,taskError:g,displayEvents:d,hasUserMessageInLogs:N,initialPrompt:C,supportsFollowUp:j,taskUnavailable:w,chatDisabled:D,chatDisabledReason:O,questionBypassEnabled:T,isRunning:H,hasPendingFollowUp:K,canCancel:R,canRetry:L,onRetry:I,onCancel:ee,onStartCreateTask:S,onCancelCreateTask:V,onCreateTask:Y,onSendMessage:U,onQuestionBypassChange:ie,onSubmitQuestionResponse:q,messagesEndRef:F}){const[X,xe]=o.useState(!1),[oe,de]=o.useState(!1),[Z,ce]=o.useState(!1),te=o.useRef(0),y=o.useRef(!1),_=o.useCallback(J=>{const Q=J.currentTarget,ae=te.current;if(te.current=Q.scrollTop,y.current)return;if(Q.scrollHeight-Q.scrollTop-Q.clientHeight<30){de(!1),y.current=!0,setTimeout(()=>{y.current=!1},300);return}Q.scrollTop<ae&&ae-Q.scrollTop>10&&de(!0),Q.scrollTop<=0&&de(!0)},[]),P=(m==null?void 0:m.effectiveProjectPath)??(m==null?void 0:m.project)??"default workspace",E=m?(f==null?void 0:f.name)??as(m.assignedTo,l==null?void 0:l.nodes,m.assignedNodeName):"unassigned",v=m?[{label:"Working dir",value:P,mono:!0},...m.branch?[{label:"Branch",value:m.branch,mono:!0}]:[],{label:"Agent",value:m.agent,mono:!0},{label:"Node",value:E}]:[],re=m!=null&&m.description&&m.description!==m.title?m.description:null;return h?e.jsx(ii,{onToggleTasks:t,desktopTasksOpen:s,mobileTasksPanelOpen:r,operationsOpen:a,onToggleOperations:n,cluster:l,sseConnected:c,onCancel:V,onCreated:Y}):!m&&p?e.jsxs("div",{className:"flex h-full min-h-0 flex-col overflow-hidden rounded-2xl sm:rounded-[32px] border border-border/60 bg-background/78 shadow-[0_30px_120px_-60px_rgba(0,0,0,var(--panel-shadow-alpha))] backdrop-blur-xl",children:[e.jsx("div",{className:"shrink-0 border-b border-border/60 px-4 py-4 sm:px-5",children:e.jsx(dt,{onToggleTasks:t,desktopTasksOpen:s,mobileTasksPanelOpen:r,operationsOpen:a,onToggleOperations:n,cluster:l,sseConnected:c})}),e.jsx("div",{className:"flex min-h-0 flex-1 items-center justify-center overflow-y-auto px-6 py-10 sm:px-8",children:e.jsxs("div",{className:"space-y-4 text-center",children:[e.jsx("div",{className:"mx-auto flex h-16 w-16 items-center justify-center rounded-full border border-primary/20 bg-primary/10 text-primary",children:e.jsx(me,{className:"h-7 w-7 animate-spin"})}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("h2",{className:"text-2xl font-semibold tracking-tight text-foreground",children:"Loading conversation"}),e.jsxs("div",{className:"flex items-center justify-center gap-3 text-sm text-muted-foreground",children:[e.jsx(me,{className:"h-4 w-4 animate-spin"}),"Fetching the selected chat thread..."]})]})]})})]}):m?e.jsxs(qs,{value:u,onValueChange:x,className:"flex h-full min-h-0 flex-col overflow-hidden rounded-2xl sm:rounded-[32px] border border-border/60 bg-background/78 shadow-[0_30px_120px_-60px_rgba(0,0,0,var(--panel-shadow-alpha))] backdrop-blur-xl",children:[e.jsxs("div",{className:"shrink-0 border-b border-border/60 px-4 py-2.5 sm:px-5",children:[e.jsx("div",{className:"flex items-center gap-3",children:e.jsx(dt,{onToggleTasks:t,desktopTasksOpen:s,mobileTasksPanelOpen:r,operationsOpen:a,onToggleOperations:n,cluster:l,sseConnected:c})}),e.jsxs("div",{className:"mt-2 flex items-center gap-2",children:[e.jsx("h2",{className:"min-w-0 truncate text-base font-semibold tracking-tight text-foreground sm:text-lg",title:m.title,children:m.title}),e.jsx(Ws,{status:m.status}),e.jsx(Ia,{priority:m.priority}),e.jsx(M,{variant:"ghost",size:"icon",className:"ml-auto h-6 w-6 shrink-0 rounded-full text-muted-foreground",onClick:()=>xe(J=>!J),children:X?e.jsx(Os,{className:"h-3.5 w-3.5"}):e.jsx(We,{className:"h-3.5 w-3.5"})})]}),X&&e.jsxs("div",{className:"mt-2 space-y-2",children:[re&&e.jsx("p",{className:"max-w-3xl text-sm leading-5 text-muted-foreground",children:re}),g&&e.jsx("div",{className:"w-fit rounded-full border border-destructive/25 bg-destructive/10 px-3 py-1 text-xs text-destructive",children:g}),e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"flex flex-col text-xs text-muted-foreground",children:[e.jsxs("span",{children:["updated ",ti(m.updatedAt)]}),e.jsx("span",{className:"font-mono",children:m.id.slice(0,8)})]}),e.jsx("div",{className:"flex items-center gap-2",children:L&&e.jsxs(M,{variant:"outline",size:"sm",onClick:I,className:"shrink-0 rounded-full",children:[e.jsx(Jn,{className:"h-3.5 w-3.5"}),"Retry"]})})]})]}),e.jsxs("div",{className:"mt-2 flex items-center gap-3",children:[e.jsxs(Hs,{className:"h-auto max-w-full overflow-x-auto rounded-full bg-muted/70 p-1",children:[e.jsx(Ie,{value:"transcript",className:"rounded-full px-2.5 sm:px-4",children:"Transcript"}),e.jsx(Ie,{value:"files",className:"rounded-full px-2.5 sm:px-4",children:"Files"}),e.jsx(Ie,{value:"preview",className:"rounded-full px-2.5 sm:px-4",children:"Preview"}),e.jsx(Ie,{value:"diff",className:"rounded-full px-2.5 sm:px-4",children:"Diff"})]}),H&&e.jsx(ye,{variant:"outline",className:"hidden rounded-full border-amber-500/30 bg-amber-500/10 text-amber-700 sm:inline-flex dark:text-amber-300",children:"Working"}),K&&e.jsx(ye,{variant:"outline",className:"hidden rounded-full border-primary/30 bg-primary/10 text-primary sm:inline-flex",children:"Queued"}),w&&e.jsx(ye,{variant:"outline",className:"hidden rounded-full border-destructive/25 bg-destructive/10 text-destructive sm:inline-flex",children:"Unavailable"})]})]}),e.jsx(Fe,{value:"transcript",className:"mt-0 min-h-0 flex-1",children:e.jsxs("div",{className:"relative flex h-full min-h-0 flex-col",children:[e.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto px-4 py-5 sm:px-5",onScroll:_,children:e.jsxs("div",{className:"mx-auto flex max-w-[72rem] flex-col gap-5",children:[C&&!N&&e.jsx(Ss,{event:C,questionBypassEnabled:T,onQuestionBypassChange:ie,onSubmitQuestionResponse:q,questionResponseDisabled:!j||D}),d.map((J,Q)=>e.jsx(Ss,{event:J,questionBypassEnabled:T,onQuestionBypassChange:ie,onSubmitQuestionResponse:q,questionResponseDisabled:!j||D},Uo("transcript",J,Q))),d.length===0&&e.jsxs("div",{className:"rounded-[28px] border border-dashed border-border/70 bg-background/35 px-5 py-8 text-center",children:[e.jsx("div",{className:"text-sm font-medium text-foreground",children:"Transcript is warming up"}),e.jsx("div",{className:"mt-2 text-sm leading-6 text-muted-foreground",children:p?"Fetching task output...":"The opening prompt has been stored, but the agent has not emitted conversation output yet."})]}),(!j&&m.result||m.error)&&e.jsxs("div",{className:"space-y-3",children:[!j&&m.result&&e.jsxs("div",{className:"rounded-[26px] border border-border/70 bg-card/80 px-4 py-4",children:[e.jsx("div",{className:"text-[11px] font-medium uppercase tracking-[0.22em] text-muted-foreground",children:"Stored result"}),e.jsx("pre",{className:"mt-3 overflow-x-auto whitespace-pre-wrap text-xs leading-5 text-muted-foreground",children:JSON.stringify(m.result,null,2)})]}),m.error&&e.jsxs("div",{className:"rounded-[26px] border border-destructive/20 bg-destructive/10 px-4 py-4 text-destructive",children:[e.jsx("div",{className:"text-[11px] font-medium uppercase tracking-[0.22em]",children:"Stored error"}),e.jsx("pre",{className:"mt-3 overflow-x-auto whitespace-pre-wrap text-xs leading-5",children:m.error})]})]}),(H||K)&&d.length>0&&e.jsxs("div",{className:"flex items-center gap-3 rounded-[24px] border border-border/60 bg-background/45 px-4 py-3 text-sm text-muted-foreground",children:[e.jsx(me,{className:"h-4 w-4 animate-spin"}),"The agent is still working on this conversation."]}),e.jsx("div",{ref:F})]})}),j?oe?e.jsx(M,{size:"icon",onClick:()=>de(!1),className:"absolute bottom-4 right-4 z-10 h-12 w-12 rounded-full shadow-lg",children:e.jsx(Nt,{className:"h-5 w-5"})}):e.jsx("div",{className:"shrink-0",children:e.jsx("div",{className:"mx-auto w-full max-w-[72rem]",children:e.jsx(Zo,{onSend:U,disabled:D,disabledReason:O,contextItems:v,placeholder:D?O:"Continue the conversation...",running:H||K,onStop:R?()=>ce(!0):void 0})})}):e.jsx("div",{className:"shrink-0 border-t border-border/60 px-4 py-4 text-sm text-muted-foreground sm:px-5",children:"This task does not expose follow-up chat messages. Use Files, Preview, or Diff to inspect the result."})]})}),e.jsx(Fe,{value:"files",className:"mt-0 min-h-0 flex-1 overflow-hidden",children:e.jsx(o.Suspense,{fallback:e.jsx(Lt,{label:"Loading files..."}),children:e.jsx(ai,{taskId:m.id})})}),e.jsx(Fe,{value:"preview",className:"mt-0 min-h-0 flex-1 overflow-hidden",children:e.jsx(o.Suspense,{fallback:e.jsx(Lt,{label:"Loading preview..."}),children:e.jsx(ni,{taskId:m.id})})}),e.jsx(Fe,{value:"diff",className:"mt-0 min-h-0 flex-1 overflow-hidden",children:e.jsx(o.Suspense,{fallback:e.jsx(Lt,{label:"Loading diff..."}),children:e.jsx(oi,{taskId:m.id})})}),e.jsx(Wt,{open:Z,onOpenChange:ce,children:e.jsxs(mt,{children:[e.jsxs(xt,{children:[e.jsx(ft,{children:"Stop this task?"}),e.jsx(pt,{children:"The task will stop and move to a cancelled state."})]}),e.jsxs(ht,{children:[e.jsx(bt,{children:"Keep running"}),e.jsx(gt,{onClick:ee,children:"Stop task"})]})]})})]}):e.jsxs("div",{className:"flex h-full min-h-0 flex-col overflow-hidden rounded-2xl sm:rounded-[32px] border border-border/60 bg-background/78 shadow-[0_30px_120px_-60px_rgba(0,0,0,var(--panel-shadow-alpha))] backdrop-blur-xl",children:[e.jsx("div",{className:"shrink-0 border-b border-border/60 px-4 py-4 sm:px-5",children:e.jsx(dt,{onToggleTasks:t,desktopTasksOpen:s,mobileTasksPanelOpen:r,operationsOpen:a,onToggleOperations:n,cluster:l,sseConnected:c})}),e.jsx("div",{className:"flex min-h-0 flex-1 items-center justify-center overflow-y-auto px-6 py-10 sm:px-8",children:e.jsxs("div",{className:"w-full max-w-2xl text-center",children:[e.jsx("div",{className:"mx-auto flex h-16 w-16 items-center justify-center rounded-full border border-primary/20 bg-primary/10 text-primary",children:e.jsx(Yt,{className:"h-7 w-7"})}),e.jsx("h2",{className:"mt-5 text-xl font-semibold tracking-tight text-foreground sm:text-3xl",children:"No chat selected"}),e.jsx("p",{className:"mx-auto mt-3 max-w-xl text-sm leading-6 text-muted-foreground",children:"Open a task from the left sidebar to continue the conversation, or start a new task to create a fresh chat thread."}),e.jsxs(M,{onClick:S,className:"mt-6 rounded-full px-5",children:[e.jsx(Ys,{className:"h-4 w-4"}),"Start new chat"]}),g&&e.jsx("div",{className:"mx-auto mt-4 max-w-lg rounded-[20px] border border-destructive/20 bg-destructive/10 px-4 py-3 text-sm text-destructive",children:g})]})})]})}function ii({onToggleTasks:t,desktopTasksOpen:s,mobileTasksPanelOpen:r,operationsOpen:a,onToggleOperations:n,cluster:l,sseConnected:c,onCancel:u,onCreated:x}){var h,m,f;return e.jsxs("div",{className:"flex h-full min-h-0 flex-col overflow-hidden rounded-2xl sm:rounded-[32px] border border-border/60 bg-background/78 shadow-[0_30px_120px_-60px_rgba(0,0,0,var(--panel-shadow-alpha))] backdrop-blur-xl",children:[e.jsx("div",{className:"shrink-0 border-b border-border/60 px-4 py-4 sm:px-5",children:e.jsx(dt,{onToggleTasks:t,desktopTasksOpen:s,mobileTasksPanelOpen:r,operationsOpen:a,onToggleOperations:n,cluster:l,sseConnected:c})}),e.jsx("div",{className:"flex min-h-0 flex-1 flex-col items-center justify-center overflow-y-auto px-6 py-10 sm:px-8",children:e.jsx("div",{className:"w-full max-w-2xl",children:e.jsx(ql,{nodes:(l==null?void 0:l.nodes)??[],currentNodeRole:(h=l==null?void 0:l.self)==null?void 0:h.role,currentNodeId:((m=l==null?void 0:l.self)==null?void 0:m.id)??null,leaderNodeId:((f=l==null?void 0:l.leader)==null?void 0:f.id)??null,onCreated:x,onCancel:u,submitLabel:"Start chat",autoFocus:!0,layout:"composer"})})})]})}function dt({onToggleTasks:t,desktopTasksOpen:s,mobileTasksPanelOpen:r,operationsOpen:a,onToggleOperations:n,cluster:l,sseConnected:c}){var u;return e.jsxs("div",{className:"flex w-full items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-2",children:[e.jsx(di,{desktopTasksOpen:s,mobileTasksPanelOpen:r,onToggleTasks:t}),e.jsx(ye,{variant:"outline",className:"hidden rounded-full border-border/70 bg-background/60 sm:inline-flex",children:c?"Live":"Retrying"}),((u=l==null?void 0:l.leader)==null?void 0:u.name)&&e.jsxs(ye,{variant:"outline",className:"hidden rounded-full border-border/70 bg-background/60 sm:inline-flex",children:["leader ",l.leader.name]})]}),e.jsxs(M,{variant:"outline",onClick:n,className:"shrink-0 rounded-full border-border/70 bg-background/60 px-3 sm:px-4",children:[a?e.jsx(Zs,{className:"h-4 w-4"}):e.jsx(Vn,{className:"h-4 w-4"}),e.jsx("span",{className:"hidden sm:inline",children:a?"Hide cluster":"Show cluster"})]})]})}function di({desktopTasksOpen:t,mobileTasksPanelOpen:s,onToggleTasks:r}){var n,l;const a=(l=(n=globalThis.window)==null?void 0:n.matchMedia("(min-width: 1024px)"))!=null&&l.matches?t:s;return e.jsxs(M,{variant:"outline",onClick:r,className:"rounded-full border-border/70 bg-background/60 px-3 sm:px-4",children:[a?e.jsx(Xs,{className:"h-4 w-4"}):e.jsx(Un,{className:"h-4 w-4"}),e.jsx("span",{className:"hidden sm:inline",children:a?"Hide tasks":"Show tasks"})]})}const ci={node:"border-teal-500/30 bg-teal-500/10 text-teal-700 dark:text-teal-300",task:"border-amber-500/30 bg-amber-500/10 text-amber-700 dark:text-amber-300",election:"border-indigo-500/30 bg-indigo-500/10 text-indigo-700 dark:text-indigo-300",cluster:"border-emerald-500/30 bg-emerald-500/10 text-emerald-700 dark:text-emerald-300"};function ui(t){return t.split(".")[0]??"unknown"}function mi(t){return new Date(t).toLocaleTimeString("en-US",{hour12:!1})}function It(t,s){return(s==null?void 0:s.get(t))??t}function xi(t,s){const r=t.data;switch(t.type){case"node.joined":return`${r.name} joined the cluster`;case"node.left":return`${It(r.nodeId,s)} left (${r.reason})`;case"node.status":return`${It(r.nodeId,s)} is now ${r.status}`;case"task.created":return`"${r.title}" created`;case"task.assigned":return`task assigned to ${It(r.nodeId,s)}`;case"task.status":return`task ${r.taskId.slice(0,8)} -> ${r.status}`;case"election.started":return`candidate ${r.candidateId.slice(0,8)} term ${r.term}`;case"election.complete":return`leader elected, term ${r.term}`;case"cluster.state":return`${r.nodeCount} nodes, term ${r.term}`;default:return JSON.stringify(r)}}function hi(t){return JSON.stringify(t,null,2)}function fi({events:t,maxHeight:s="400px",emptyTitle:r="No live events yet",emptyDescription:a="Cluster activity appears here as it happens.",nodeNameById:n}){return t.length===0?e.jsx("div",{className:"flex h-28 items-center justify-center rounded-[20px] border border-dashed border-border/70 bg-background/40 text-center",children:e.jsxs("div",{children:[e.jsx("div",{className:"text-sm text-muted-foreground",children:r}),e.jsx("div",{className:"mt-1 text-xs text-muted-foreground/70",children:a})]})}):e.jsx("div",{className:"overflow-y-auto pr-1",style:{maxHeight:s},children:e.jsx("div",{className:"space-y-2",children:t.map(l=>{const c=ui(l.type);return e.jsx("div",{className:"rounded-[20px] border border-border/60 bg-background/45 px-4 py-3 transition-colors hover:border-border hover:bg-background/65",children:e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("div",{className:"font-mono text-[11px] text-muted-foreground",children:mi(l.timestamp)}),e.jsx(ye,{variant:"outline",className:A("w-fit text-[10px] font-medium uppercase tracking-[0.16em]",ci[c]),children:l.type})]}),e.jsx(M,{type:"button",variant:"ghost",size:"icon",className:"h-7 w-7 shrink-0 rounded-full text-muted-foreground",onClick:()=>void He(hi(l),"Event copied"),"aria-label":`Copy ${l.type} event`,title:"Copy event",children:e.jsx(vt,{className:"h-3.5 w-3.5"})})]}),e.jsx("div",{className:"text-sm leading-6 text-foreground/85",children:xi(l,n)})]})},l.id)})})})}function $s({cluster:t,systemInfo:s,nodeNameById:r,nodeBlockingTaskCounts:a,eventTypeFilter:n,onEventTypeFilterChange:l,eventTypeOptions:c,filteredEvents:u,sseConnected:x,clusterLoading:h,clusterError:m,promotePending:f,onPromote:p,onAddNode:g,leavePending:d,onLeaveCluster:N,onToggleNodeDevTunnel:C,devTunnelNodeId:j,onClose:w}){var I,ee,S,V,Y;const D=((I=t==null?void 0:t.self)==null?void 0:I.role)==="leader",O=((ee=t==null?void 0:t.self)==null?void 0:ee.role)==="follower"&&!(t!=null&&t.leader),T=(t==null?void 0:t.self)??null,K=Yl((t==null?void 0:t.nodes)??[],T==null?void 0:T.id).filter(U=>U.id!==(T==null?void 0:T.id)),R=(T==null?void 0:T.role)==="leader"&&K.length===0,L=(T==null?void 0:T.role)==="follower";return e.jsx("aside",{className:"flex h-full min-h-0 flex-col overflow-hidden rounded-[32px] border border-border/60 bg-background/84 shadow-[0_30px_120px_-60px_rgba(0,0,0,var(--panel-shadow-alpha))] backdrop-blur-xl",children:e.jsxs(qs,{defaultValue:"overview",className:"flex h-full min-h-0 flex-col",children:[e.jsxs("div",{className:"shrink-0 border-b border-border/60 px-4 py-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-lg font-semibold tracking-tight",children:"Operations"}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:"Node, cluster, and live events."})]}),e.jsx(M,{variant:"ghost",size:"icon",onClick:w,className:"rounded-full",children:e.jsx(Zs,{className:"h-4 w-4"})})]}),e.jsxs(Hs,{className:"mt-4 grid h-auto w-full grid-cols-3 rounded-full bg-muted/70 p-1",children:[e.jsx(Ie,{value:"overview",className:"rounded-full px-3 text-xs",children:"Overview"}),e.jsx(Ie,{value:"nodes",className:"rounded-full px-3 text-xs",children:"Nodes"}),e.jsx(Ie,{value:"events",className:"rounded-full px-3 text-xs",children:"Live events"})]})]}),e.jsx(Fe,{value:"overview",className:"mt-0 min-h-0 flex-1",children:e.jsx("div",{className:"flex h-full min-h-0 flex-col overflow-y-auto px-4 py-5",children:e.jsxs("div",{className:"space-y-7",children:[T&&e.jsx(Rs,{node:T,systemInfo:s,blockingTaskCount:a.get(T.id)??0,devTunnelNodeId:j,onToggleNodeDevTunnel:C,showActions:!1,defaultExpanded:!1}),e.jsxs("section",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("div",{className:"text-sm font-medium text-foreground",children:"Cluster snapshot"}),e.jsx(ye,{variant:"outline",className:"rounded-full border-border/70 bg-background/60",children:x?"Connected":"Reconnecting"})]}),h&&!t?e.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[e.jsx(me,{className:"h-4 w-4 animate-spin"}),"Loading cluster state..."]}):m&&!t?e.jsx("div",{className:"rounded-[22px] border border-destructive/20 bg-destructive/10 px-4 py-3 text-sm text-destructive",children:m}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(Be,{label:"Term",value:String((t==null?void 0:t.term)??0)}),e.jsx(Be,{label:"Nodes",value:String((t==null?void 0:t.nodes.length)??0)}),e.jsx(Be,{label:"Pending",value:String((t==null?void 0:t.taskSummary.pending)??0)}),e.jsx(Be,{label:"Running",value:String((t==null?void 0:t.taskSummary.running)??0)}),e.jsx(Be,{label:"Completed",value:String((t==null?void 0:t.taskSummary.completed)??0)}),e.jsx(Be,{label:"Failed",value:String((t==null?void 0:t.taskSummary.failed)??0)})]}),e.jsxs("div",{className:"space-y-3 rounded-[24px] border border-border/60 bg-background/45 px-4 py-4",children:[e.jsx(Ae,{label:"Leader",value:((S=t==null?void 0:t.leader)==null?void 0:S.name)??"None"}),e.jsx(Ae,{label:"Leader URL",value:((V=t==null?void 0:t.leader)==null?void 0:V.endpoint)??"Unavailable",mono:!0,action:(Y=t==null?void 0:t.leader)!=null&&Y.endpoint?e.jsx(st,{label:"Copy leader URL",onClick:()=>{var U;return void He(((U=t.leader)==null?void 0:U.endpoint)??"","Leader URL copied")}}):void 0}),e.jsx(Ae,{label:"Feed",value:x?"Receiving live updates":"Reconnecting to event stream"})]}),e.jsx("div",{className:"flex flex-wrap gap-2",children:O&&e.jsxs(M,{variant:"outline",size:"sm",onClick:p,disabled:f,className:"rounded-full",children:[f&&e.jsx(me,{className:"h-3.5 w-3.5 animate-spin"}),"Promote self"]})})]})]})]})})}),e.jsx(Fe,{value:"nodes",className:"mt-0 min-h-0 flex-1",children:e.jsx("div",{className:"flex h-full min-h-0 flex-col overflow-y-auto px-4 py-5",children:e.jsxs("div",{className:"space-y-7",children:[e.jsxs("section",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("div",{className:"text-sm font-medium text-foreground",children:"This node"}),R?e.jsx(M,{variant:"outline",size:"sm",onClick:g,className:"rounded-full",children:"Join node"}):L?e.jsxs(M,{variant:"outline",size:"sm",onClick:N,disabled:d,className:"rounded-full",children:[d&&e.jsx(me,{className:"h-3.5 w-3.5 animate-spin"}),"Leave cluster"]}):null]}),T&&e.jsx(Rs,{node:T,systemInfo:s,blockingTaskCount:a.get(T.id)??0,devTunnelNodeId:j,onToggleNodeDevTunnel:C,showActions:!0,defaultExpanded:!0})]}),e.jsxs("section",{className:"space-y-4",children:[e.jsxs("div",{className:"text-sm font-medium text-foreground",children:["Peer nodes (",K.length,")"]}),K.length>0?e.jsx("div",{className:"space-y-3",children:K.map(U=>e.jsx(pi,{node:U,isLeader:!!D,blockingTaskCount:a.get(U.id)??0,devTunnelNodeId:j,onToggleNodeDevTunnel:C},U.id))}):e.jsx("div",{className:"rounded-[24px] border border-dashed border-border/70 bg-background/35 px-4 py-5 text-sm text-muted-foreground",children:"No peer nodes are connected yet."})]})]})})}),e.jsx(Fe,{value:"events",className:"mt-0 min-h-0 flex-1",children:e.jsxs("div",{className:"flex h-full min-h-0 flex-col px-4 py-5",children:[e.jsxs("div",{className:"mb-4 space-y-3",children:[e.jsx("div",{children:e.jsxs("div",{className:"flex items-center gap-2 text-sm font-medium text-foreground",children:[e.jsx(Fa,{className:A("h-4 w-4",x?"text-emerald-500":"text-destructive")}),"Live events"]})}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs(ke,{value:n,onValueChange:l,children:[e.jsx(we,{className:"h-9 min-w-[11rem] flex-1 rounded-full border-border/70 bg-background/55 text-[12px] sm:max-w-[15rem]",children:e.jsx(Me,{placeholder:"Event type"})}),e.jsx(Ce,{children:c.map(U=>e.jsx(je,{value:U,className:"text-[12px]",children:U==="all"?"All event types":U},U))})]}),e.jsx(ye,{variant:"outline",className:"rounded-full border-border/70 bg-background/60",children:x?"Connected":"Reconnecting"})]})]}),e.jsx("div",{className:"min-h-0 flex-1",children:e.jsx(fi,{events:u,maxHeight:"100%",emptyTitle:n==="all"?"No live events yet":"No matching events",emptyDescription:n==="all"?"Cluster activity appears here as it happens.":`No "${n}" events are in the current stream.`,nodeNameById:r})})]})})]})})}function Rs({node:t,systemInfo:s,blockingTaskCount:r,devTunnelNodeId:a,onToggleNodeDevTunnel:n,showActions:l=!0,defaultExpanded:c=!1}){const[u,x]=o.useState(c),h=(s==null?void 0:s.dashboardOrigin)??t.dashboardOrigin,m=t.devtunnelEndpoint??t.endpoint,f=h??t.endpoint,p=(s==null?void 0:s.workDir)??t.workDir,g=sr(t,s==null?void 0:s.transportType),d=Qt(t,s==null?void 0:s.transportType),N=d&&Ke((s==null?void 0:s.transportType)??t.transportType)?!0:tr(t,s==null?void 0:s.transportType),C=r>0;return e.jsxs("section",{className:"rounded-[28px] border border-primary/20 bg-primary/8 shadow-[0_24px_80px_-60px_hsl(var(--primary)/0.9)]",children:[e.jsxs("button",{type:"button",onClick:()=>x(j=>!j),className:"w-full px-4 py-3.5 text-left",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[u?e.jsx(We,{className:"h-4 w-4 shrink-0 text-muted-foreground"}):e.jsx(Ze,{className:"h-4 w-4 shrink-0 text-muted-foreground"}),e.jsx(Ks,{status:t.status}),e.jsx("span",{className:"text-[11px] font-medium uppercase tracking-[0.18em] text-muted-foreground",children:"Current node"}),e.jsx("a",{href:f,target:"_blank",rel:"noreferrer",onClick:j=>j.stopPropagation(),className:"ml-auto shrink-0 text-muted-foreground transition-colors hover:text-primary",title:"Open Dashboard",children:e.jsx(Js,{className:"h-3.5 w-3.5"})})]}),e.jsxs("div",{className:"mt-1.5 flex items-center gap-2 pl-6",children:[e.jsx("span",{className:"text-sm font-semibold tracking-tight text-foreground",children:t.name}),e.jsx(Gs,{role:t.role}),e.jsx(ye,{variant:"outline",className:"rounded-full border-primary/30 bg-background/60 text-[10px] capitalize",children:t.status})]})]}),u&&e.jsxs("div",{className:"space-y-4 border-t border-primary/15 px-4 pb-4 pt-3",children:[e.jsxs("div",{className:"space-y-3 rounded-[20px] border border-primary/20 bg-background/72 px-3.5 py-3.5",children:[e.jsx(Ae,{label:"Node ID",value:t.id,mono:!0}),h&&e.jsx(Ae,{label:"Dashboard",value:h,mono:!0,action:e.jsx(st,{label:"Copy dashboard URL",onClick:()=>void He(h,"Dashboard URL copied")})}),e.jsx(Ae,{label:"Node URL",value:m,mono:!0,action:e.jsx(st,{label:"Copy node URL",onClick:()=>void He(m,"Node URL copied")})}),p&&e.jsx(Ae,{label:"Workspace",value:p,mono:!0})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsx(Jt,{label:"Transport",value:g}),s&&e.jsx(Jt,{label:"Uptime",value:si(s.uptime),mono:!0})]}),e.jsx($r,{capabilities:t.capabilities,action:l&&N?e.jsxs(M,{variant:"outline",size:"sm",onClick:()=>n(t),disabled:a===t.id||C,className:"rounded-full",title:C?"Finish assigned or running tasks before changing remote access":void 0,children:[a===t.id&&e.jsx(me,{className:"h-3.5 w-3.5 animate-spin"}),d?"Disable Remote Access":"Enable Remote Access"]}):void 0}),l&&N&&C&&e.jsxs("div",{className:"text-xs text-muted-foreground",children:[r," active task",r===1?"":"s"," on this node."]})]})]})}function pi({node:t,isLeader:s,blockingTaskCount:r,devTunnelNodeId:a,onToggleNodeDevTunnel:n}){const[l,c]=o.useState(!1),u=t.dashboardOrigin,x=t.devtunnelEndpoint??t.endpoint,h=u??t.endpoint,m=sr(t),f=Qt(t),p=tr(t),g=r>0;return e.jsxs("div",{className:"rounded-[24px] border border-border/60 bg-background/45",children:[e.jsxs("button",{type:"button",onClick:()=>c(d=>!d),className:"w-full px-4 py-3 text-left",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[l?e.jsx(We,{className:"h-4 w-4 shrink-0 text-muted-foreground"}):e.jsx(Ze,{className:"h-4 w-4 shrink-0 text-muted-foreground"}),e.jsx(Ks,{status:t.status}),e.jsx("span",{className:"text-[11px] font-medium uppercase tracking-[0.18em] text-muted-foreground",children:"Peer node"}),e.jsx("a",{href:h,target:"_blank",rel:"noreferrer",onClick:d=>d.stopPropagation(),className:"ml-auto shrink-0 text-muted-foreground transition-colors hover:text-primary",title:"Open Dashboard",children:e.jsx(Js,{className:"h-3.5 w-3.5"})})]}),e.jsxs("div",{className:"mt-1.5 flex items-center gap-2 pl-6",children:[e.jsx("span",{className:"text-sm font-semibold text-foreground",children:t.name}),e.jsx(Gs,{role:t.role}),e.jsx(ye,{variant:"outline",className:"rounded-full border-border/70 bg-background/60 text-[10px] capitalize",children:t.status})]})]}),l&&e.jsxs("div",{className:"space-y-4 border-t border-border/50 px-4 pb-4 pt-3",children:[e.jsxs("div",{className:"space-y-3",children:[e.jsx(Ae,{label:"Node ID",value:t.id,mono:!0}),u&&e.jsx(Ae,{label:"Dashboard",value:u,mono:!0,action:e.jsx(st,{label:"Copy dashboard URL",onClick:()=>void He(u,"Dashboard URL copied")})}),e.jsx(Ae,{label:"Node URL",value:x,mono:!0,action:e.jsx(st,{label:"Copy node URL",onClick:()=>void He(x,"Node URL copied")})}),t.workDir&&e.jsx(Ae,{label:"Workspace",value:t.workDir,mono:!0}),e.jsx(Jt,{label:"Transport",value:m})]}),e.jsx($r,{capabilities:t.capabilities,action:s&&p?e.jsxs(M,{variant:"outline",size:"sm",onClick:()=>n(t),disabled:a===t.id||g,className:"rounded-full",title:g?"Finish assigned or running tasks before changing remote access":void 0,children:[a===t.id&&e.jsx(me,{className:"h-3.5 w-3.5 animate-spin"}),f?"Disable Remote Access":"Enable Remote Access"]}):void 0}),s&&p&&g&&e.jsxs("div",{className:"text-xs text-muted-foreground",children:[r," active task",r===1?"":"s"," on this node."]})]})]})}function st({label:t,onClick:s}){return e.jsx(M,{type:"button",variant:"ghost",size:"icon",className:"h-7 w-7 shrink-0 rounded-full text-muted-foreground",onClick:s,"aria-label":t,title:t,children:e.jsx(vt,{className:"h-3.5 w-3.5"})})}function gi(t,s,r,a){var c;if(!t)return{taskUnavailable:!1,chatDisabled:!0,chatDisabledReason:"Select a task to continue the conversation."};const n=((c=s==null?void 0:s.self)==null?void 0:c.role)==="follower";return t.assignedTo!==null&&t.assignedNodeAvailable===!1?{taskUnavailable:!0,chatDisabled:!0,chatDisabledReason:`${t.assignedNodeName??"Assigned node"} is unavailable. Leave the cluster on that node or re-run the task elsewhere.`}:n?{taskUnavailable:!1,chatDisabled:!0,chatDisabledReason:"Follower nodes are read-only. Use the leader dashboard to manage chat, or leave the cluster first."}:r||a?{taskUnavailable:!1,chatDisabled:!0,chatDisabledReason:"Waiting for the current turn to finish..."}:jt.has(t.status)||t.status==="archived"?{taskUnavailable:!1,chatDisabled:!0,chatDisabledReason:jt.has(t.status)?"Task has not started yet...":"Archived tasks are read-only."}:{taskUnavailable:!1,chatDisabled:!1,chatDisabledReason:"Continue the conversation..."}}var Ct="Checkbox",[bi]=zs(Ct),[ji,ns]=bi(Ct);function yi(t){const{__scopeCheckbox:s,checked:r,children:a,defaultChecked:n,disabled:l,form:c,name:u,onCheckedChange:x,required:h,value:m="on",internal_do_not_use_render:f}=t,[p,g]=Ua({prop:r,defaultProp:n??!1,onChange:x,caller:Ct}),[d,N]=o.useState(null),[C,j]=o.useState(null),w=o.useRef(!1),D=d?!!c||!!d.closest("form"):!0,O={checked:p,disabled:l,setChecked:g,control:d,setControl:N,name:u,form:c,value:m,hasConsumerStoppedPropagationRef:w,required:h,defaultChecked:Re(n)?!1:n,isFormControl:D,bubbleInput:C,setBubbleInput:j};return e.jsx(ji,{scope:s,...O,children:vi(f)?f(O):a})}var Rr="CheckboxTrigger",Lr=o.forwardRef(({__scopeCheckbox:t,onKeyDown:s,onClick:r,...a},n)=>{const{control:l,value:c,disabled:u,checked:x,required:h,setControl:m,setChecked:f,hasConsumerStoppedPropagationRef:p,isFormControl:g,bubbleInput:d}=ns(Rr,t),N=yt(n,m),C=o.useRef(x);return o.useEffect(()=>{const j=l==null?void 0:l.form;if(j){const w=()=>f(C.current);return j.addEventListener("reset",w),()=>j.removeEventListener("reset",w)}},[l,f]),e.jsx(Zt.button,{type:"button",role:"checkbox","aria-checked":Re(x)?"mixed":x,"aria-required":h,"data-state":Br(x),"data-disabled":u?"":void 0,disabled:u,value:c,...a,ref:N,onKeyDown:Ft(s,j=>{j.key==="Enter"&&j.preventDefault()}),onClick:Ft(r,j=>{f(w=>Re(w)?!0:!w),d&&g&&(p.current=j.isPropagationStopped(),p.current||j.stopPropagation())})})});Lr.displayName=Rr;var os=o.forwardRef((t,s)=>{const{__scopeCheckbox:r,name:a,checked:n,defaultChecked:l,required:c,disabled:u,value:x,onCheckedChange:h,form:m,...f}=t;return e.jsx(yi,{__scopeCheckbox:r,checked:n,defaultChecked:l,disabled:u,required:c,onCheckedChange:h,name:a,form:m,value:x,internal_do_not_use_render:({isFormControl:p})=>e.jsxs(e.Fragment,{children:[e.jsx(Lr,{...f,ref:s,__scopeCheckbox:r}),p&&e.jsx(Ur,{__scopeCheckbox:r})]})})});os.displayName=Ct;var Ir="CheckboxIndicator",Fr=o.forwardRef((t,s)=>{const{__scopeCheckbox:r,forceMount:a,...n}=t,l=ns(Ir,r);return e.jsx(Oa,{present:a||Re(l.checked)||l.checked===!0,children:e.jsx(Zt.span,{"data-state":Br(l.checked),"data-disabled":l.disabled?"":void 0,...n,ref:s,style:{pointerEvents:"none",...t.style}})})});Fr.displayName=Ir;var Or="CheckboxBubbleInput",Ur=o.forwardRef(({__scopeCheckbox:t,...s},r)=>{const{control:a,hasConsumerStoppedPropagationRef:n,checked:l,defaultChecked:c,required:u,disabled:x,name:h,value:m,form:f,bubbleInput:p,setBubbleInput:g}=ns(Or,t),d=yt(r,g),N=Ba(l),C=za(a);o.useEffect(()=>{const w=p;if(!w)return;const D=window.HTMLInputElement.prototype,T=Object.getOwnPropertyDescriptor(D,"checked").set,H=!n.current;if(N!==l&&T){const K=new Event("click",{bubbles:H});w.indeterminate=Re(l),T.call(w,Re(l)?!1:l),w.dispatchEvent(K)}},[p,N,l,n]);const j=o.useRef(Re(l)?!1:l);return e.jsx(Zt.input,{type:"checkbox","aria-hidden":!0,defaultChecked:c??j.current,required:u,disabled:x,name:h,value:m,form:f,...s,tabIndex:-1,ref:d,style:{...s.style,...C,position:"absolute",pointerEvents:"none",opacity:0,margin:0,transform:"translateX(-100%)"}})});Ur.displayName=Or;function vi(t){return typeof t=="function"}function Re(t){return t==="indeterminate"}function Br(t){return Re(t)?"indeterminate":t?"checked":"unchecked"}const Gt=o.forwardRef(({className:t,...s},r)=>e.jsx(os,{ref:r,className:A("peer h-4 w-4 shrink-0 rounded-sm border border-primary ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground",t),...s,children:e.jsx(Fr,{className:A("flex items-center justify-center text-current"),children:e.jsx(Pe,{className:"h-3.5 w-3.5"})})}));Gt.displayName=os.displayName;function Ls({toolbarTasks:t,activeTaskId:s,tasksLoading:r,tasksError:a,isLeader:n,scope:l,agentFilter:c,nodeFilter:u,agentOptions:x,nodeOptions:h,nodeNameById:m,searchQuery:f,selectedTaskIds:p,allVisibleTasksSelected:g,someVisibleTasksSelected:d,canBatchArchive:N,onSearchChange:C,onScopeChange:j,onAgentFilterChange:w,onNodeFilterChange:D,onToggleTaskSelected:O,onToggleAllVisibleTasks:T,onBatchArchive:H,onBatchDelete:K,onCreateTask:R,onSelectTask:L,onClose:I}){const[ee,S]=o.useState(!!f),[V,Y]=o.useState(!1),U=o.useRef(null),ie=o.useRef(null),q=p.size,F=l!=="active"||u!=="all"||c!=="all",X=f.trim().length>0,[xe,oe]=o.useState(new Set),[de,Z]=o.useState(new Set),ce=o.useMemo(()=>ri(t,m),[t,m]),te=ce.length===1,y=!te||F||X,_=te&&(F||X),P=o.useCallback(v=>{oe(re=>{const J=new Set(re);return J.has(v)?J.delete(v):J.add(v),J})},[]),E=o.useCallback(v=>{Z(re=>{const J=new Set(re);return J.has(v)?J.delete(v):J.add(v),J})},[]);return o.useEffect(()=>{f&&S(!0)},[f]),o.useEffect(()=>{var v;ee&&((v=U.current)==null||v.focus())},[ee]),o.useEffect(()=>{if(!ee)return;const v=J=>{var ae;const Q=J.target;Q instanceof Node&&((ae=ie.current)!=null&&ae.contains(Q)||S(!1))},re=J=>{J.key==="Escape"&&S(!1)};return document.addEventListener("mousedown",v),document.addEventListener("keydown",re),()=>{document.removeEventListener("mousedown",v),document.removeEventListener("keydown",re)}},[ee]),e.jsxs("aside",{className:"flex h-full min-h-0 flex-col overflow-hidden rounded-[32px] border border-border/60 bg-background/80 shadow-[0_30px_120px_-60px_rgba(0,0,0,var(--panel-shadow-alpha))] backdrop-blur-xl",children:[e.jsxs("div",{className:"shrink-0 border-b border-border/60 px-4 py-4",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("div",{className:"text-lg font-semibold tracking-tight text-foreground",children:"Tasks"}),e.jsx(M,{variant:"ghost",size:"icon",onClick:I,className:"rounded-full",children:e.jsx(Xs,{className:"h-4 w-4"})})]}),e.jsxs("div",{ref:ie,className:"mt-4 flex items-center gap-2",children:[e.jsxs(M,{onClick:R,className:A("justify-start rounded-[22px] px-4 py-6 text-left shadow-[0_24px_60px_-32px_hsl(var(--primary)/0.95)] transition-[flex] duration-200",ee?"flex-[2]":"flex-1"),children:[e.jsx(Ys,{className:"h-4 w-4"}),"New chat"]}),ee?e.jsxs("div",{className:"flex min-w-0 flex-[3] items-center gap-2",children:[e.jsxs("div",{className:"relative min-w-0 flex-1",children:[e.jsx(vs,{className:"pointer-events-none absolute left-4 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"}),e.jsx(Le,{ref:U,value:f,onChange:v=>C(v.target.value),placeholder:"Search tasks",className:"h-11 rounded-full border-border/70 bg-background/60 pl-11 text-sm"})]}),e.jsx(M,{variant:"outline",size:"icon",onClick:()=>S(!1),className:"rounded-full border-border/70 bg-background/60",children:e.jsx(Va,{className:"h-4 w-4"})})]}):e.jsxs(e.Fragment,{children:[e.jsxs(M,{variant:"outline",onClick:()=>S(!0),className:A("rounded-full border-border/70 bg-background/60 px-4 text-sm",f&&"border-primary/40 bg-primary/8 text-primary"),children:[e.jsx(vs,{className:"h-4 w-4"}),"Search"]}),e.jsx(M,{variant:V||F?"secondary":"outline",size:"icon",onClick:()=>Y(v=>!v),className:A("shrink-0 rounded-full border-border/70 bg-background/60",F&&"border-primary/40 bg-primary/8 text-primary"),title:"Filters",children:e.jsx(Sn,{className:"h-4 w-4"})})]})]}),(V||F)&&e.jsxs("div",{className:"mt-2 grid grid-cols-1 gap-2 sm:grid-cols-3",children:[e.jsxs(ke,{value:l,onValueChange:v=>j(v),children:[e.jsx(we,{className:"h-9 rounded-full border-border/70 bg-background/55 text-[12px]",children:e.jsx(Me,{})}),e.jsx(Ce,{children:Wl.map(v=>e.jsx(je,{value:v.value,className:"text-[12px]",children:v.label},v.value))})]}),e.jsxs(ke,{value:u,onValueChange:D,children:[e.jsx(we,{className:"h-9 rounded-full border-border/70 bg-background/55 text-[12px]",children:e.jsx(Me,{placeholder:"Node"})}),e.jsx(Ce,{children:h.map(v=>e.jsx(je,{value:v.value,className:"text-[12px]",children:v.label},v.value))})]}),e.jsxs(ke,{value:c,onValueChange:w,children:[e.jsx(we,{className:"h-9 rounded-full border-border/70 bg-background/55 text-[12px]",children:e.jsx(Me,{placeholder:"Agent"})}),e.jsx(Ce,{children:x.map(v=>e.jsx(je,{value:v,className:"text-[12px]",children:v==="all"?"All agents":v},v))})]})]})]}),e.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto px-3 py-3",children:ce.length>0?e.jsxs("div",{className:"space-y-1",children:[n&&e.jsxs("div",{className:"mb-1 flex items-center justify-between px-1 py-1",children:[e.jsxs("label",{className:"flex items-center gap-2 text-[11px] font-medium uppercase tracking-[0.18em] text-muted-foreground",children:[e.jsx(Gt,{checked:d&&!g?"indeterminate":g,onCheckedChange:v=>T(v===!0),"aria-label":"Select all visible tasks"}),e.jsx("span",{children:"Select all"})]}),q>0&&e.jsx(M,{variant:"ghost",size:"sm",onClick:()=>T(!1),className:"h-7 rounded-full px-3 text-xs",children:"Clear"})]}),ce.map(v=>{const re=v.nodeId??"__unassigned__",J=y&&!_&&xe.has(re);return e.jsxs("div",{className:"space-y-1",children:[y&&e.jsxs("button",{type:"button",onClick:()=>P(re),"aria-expanded":!J,className:"flex w-full items-center gap-1.5 rounded-xl px-2 py-1.5 text-left text-[11px] font-semibold uppercase tracking-[0.16em] text-muted-foreground transition-colors hover:bg-muted/50 hover:text-foreground",children:[J?e.jsx(Ze,{className:"h-3.5 w-3.5 shrink-0"}):e.jsx(We,{className:"h-3.5 w-3.5 shrink-0"}),e.jsx("span",{className:"truncate",children:v.nodeName}),e.jsx("span",{className:"ml-auto shrink-0 tabular-nums text-muted-foreground/60",children:v.dirs.reduce((Q,ae)=>Q+ae.tasks.length,0)})]}),!J&&v.dirs.map(Q=>{const ae=`${re}::${Q.path}`,ve=de.has(ae),Se=Ql(Q.path);return e.jsxs("div",{className:A("space-y-1",y&&"pl-3"),children:[e.jsxs("button",{type:"button",onClick:()=>E(ae),"aria-expanded":!ve,title:Q.path,className:"flex w-full items-center gap-1.5 rounded-xl px-2 py-1 text-left text-[11px] font-medium text-muted-foreground/80 transition-colors hover:bg-muted/40 hover:text-foreground",children:[ve?e.jsx(Ze,{className:"h-3 w-3 shrink-0"}):e.jsx(We,{className:"h-3 w-3 shrink-0"}),e.jsx("span",{className:"truncate font-mono",children:Se}),e.jsx("span",{className:"ml-auto shrink-0 tabular-nums text-muted-foreground/50",children:Q.tasks.length})]}),!ve&&e.jsx("div",{className:A("space-y-2",y?"pl-2":"pl-0"),children:Q.tasks.map(ue=>e.jsxs("div",{className:A("flex items-start gap-3 rounded-[24px] border px-3 py-3 transition-all",ue.id===s?"border-primary/45 bg-primary/9 shadow-[0_24px_80px_-54px_hsl(var(--primary)/0.95)]":"border-border/60 bg-background/40 hover:border-border hover:bg-background/60"),children:[n&&e.jsx("div",{className:"flex shrink-0 pt-1",onClick:ge=>ge.stopPropagation(),children:e.jsx(Gt,{checked:p.has(ue.id),onCheckedChange:ge=>O(ue.id,ge===!0),"aria-label":`Select ${ue.title}`})}),e.jsx("button",{type:"button",onClick:()=>L(ue.id),className:"min-w-0 flex-1 text-left",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("span",{className:A("mt-1 h-2.5 w-2.5 shrink-0 rounded-full",Zl(ue.status))}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"truncate text-sm font-semibold text-foreground",children:ue.title}),e.jsxs("div",{className:"mt-1 flex flex-wrap items-center gap-2 text-[11px] text-muted-foreground",children:[e.jsx("span",{className:"font-mono",children:ue.agent}),e.jsx("span",{className:"h-1 w-1 rounded-full bg-border"}),e.jsx("span",{children:ei(ue.updatedAt)})]}),e.jsxs("div",{className:"mt-3 flex items-center gap-2 text-[11px] text-muted-foreground",children:[e.jsx(Ws,{status:ue.status}),ue.assignedNodeAvailable===!1&&e.jsx(ye,{variant:"outline",className:"border-destructive/25 bg-destructive/10 text-[10px] text-destructive",children:"unavailable"})]})]})]})})]},ue.id))})]},ae)})]},re)})]}):e.jsx("div",{className:"rounded-[24px] border border-dashed border-border/70 bg-background/35 px-4 py-5 text-sm text-muted-foreground",children:r?"Loading tasks...":a||"No tasks match this view."})}),n&&q>0?e.jsxs("div",{className:"shrink-0 border-t border-border/60 px-4 py-4",children:[e.jsx("div",{className:"text-[11px] font-medium uppercase tracking-[0.22em] text-muted-foreground",children:"Batch actions"}),e.jsxs("div",{className:"mt-2 text-sm font-semibold text-foreground",children:[q," task",q!==1?"s":""," selected"]}),!N&&e.jsx("div",{className:"mt-2 text-xs text-muted-foreground",children:"Only completed, failed, cancelled, or archived tasks can be archived."}),e.jsxs("div",{className:"mt-3 flex flex-wrap gap-2",children:[e.jsxs(Wt,{children:[e.jsx(_s,{asChild:!0,children:e.jsxs(M,{variant:"outline",size:"sm",disabled:!N,className:"rounded-full",children:[e.jsx(cn,{className:"h-3.5 w-3.5"}),"Archive"]})}),e.jsxs(mt,{children:[e.jsxs(xt,{children:[e.jsxs(ft,{children:["Archive ",q," task",q!==1?"s":"","?"]}),e.jsx(pt,{children:"Archived tasks stay hidden from the default task view and can be reopened from the archived scope."})]}),e.jsxs(ht,{children:[e.jsx(bt,{children:"Cancel"}),e.jsx(gt,{onClick:H,disabled:!N,children:"Archive"})]})]})]}),e.jsxs(Wt,{children:[e.jsx(_s,{asChild:!0,children:e.jsxs(M,{variant:"destructive",size:"sm",className:"rounded-full",children:[e.jsx(ao,{className:"h-3.5 w-3.5"}),"Delete"]})}),e.jsxs(mt,{children:[e.jsxs(xt,{children:[e.jsxs(ft,{children:["Delete ",q," task",q!==1?"s":"","?"]}),e.jsx(pt,{children:"This removes the selected tasks and their saved logs."})]}),e.jsxs(ht,{children:[e.jsx(bt,{children:"Cancel"}),e.jsx(gt,{onClick:K,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:"Delete"})]})]})]})]})]}):null]})}function Is(t,s,r){const a=o.useRef(s);a.current=s,o.useEffect(()=>{let c=0,u=0;const x=f=>{const p=f.touches[0];p&&(c=p.clientX,u=p.clientY)},h=f=>{var N,C,j,w;const p=f.changedTouches[0];if(!p)return;const g=p.clientX-c;Math.abs(p.clientY-u)>100||Math.abs(g)<50||(g>0?(C=(N=a.current).onSwipeRight)==null||C.call(N):(w=(j=a.current).onSwipeLeft)==null||w.call(j))},m=(t==null?void 0:t.current)??document;return m.addEventListener("touchstart",x,{passive:!0}),m.addEventListener("touchend",h,{passive:!0}),()=>{m.removeEventListener("touchstart",x),m.removeEventListener("touchend",h)}},[t,r==null?void 0:r.threshold,r==null?void 0:r.maxVertical])}const Ni="(min-width: 1024px)",ki="(min-width: 1280px)";function Fs(t){var s,r,a;return((a=(r=(s=globalThis.window)==null?void 0:s.matchMedia)==null?void 0:r.call(s,t))==null?void 0:a.matches)??!1}function wi(){const[t,s]=o.useState(!0),[r,a]=o.useState(!1),[n,l]=o.useState(()=>Fs(ki)),c=o.useRef(null),u=o.useRef(null);Is(c,{onSwipeLeft:()=>a(!1)}),Is(u,{onSwipeRight:()=>l(!1)});const x=o.useCallback(()=>{if(Fs(Ni)){s(h=>!h);return}a(h=>!h)},[]);return{desktopTasksOpen:t,mobileTasksPanelOpen:r,mobileTasksPanelRef:c,operationsOpen:n,operationsPanelRef:u,setMobileTasksPanelOpen:a,setOperationsOpen:l,toggleTasksPanel:x}}function Ci(t,s){return s.data.nodeId===t.self.id||s.data.name===t.self.name||s.data.endpoint===t.self.endpoint}function Si({cluster:t,subscribe:s}){o.useEffect(()=>{var r;if(((r=t==null?void 0:t.self)==null?void 0:r.role)==="leader")return s("node",a=>{const n=String(a.data.name??a.data.nodeId??"node"),l=Ci(t,a);a.type==="node.joined"&&!l&&le.success(`${n} joined the cluster`),a.type==="node.left"&&!l&&le.message(`${n} left the cluster`)})},[t,s])}function _i(){var fs,ps,gs;const{id:t}=qa(),s=Wa(),r=Ha(),{cluster:a,systemInfo:n,events:l,sseConnected:c,subscribe:u,refresh:x,loading:h,error:m}=Ka(),f=o.useMemo(()=>Xl(s.state),[s.state]),[p,g]=o.useState([]),[d,N]=o.useState(!0),[C,j]=o.useState(null),[w,D]=o.useState(null),[O,T]=o.useState("active"),[H,K]=o.useState("all"),[R,L]=o.useState("all"),[I,ee]=o.useState(""),S=o.useDeferredValue(I),{desktopTasksOpen:V,mobileTasksPanelOpen:Y,mobileTasksPanelRef:U,operationsOpen:ie,operationsPanelRef:q,setMobileTasksPanelOpen:F,setOperationsOpen:X,toggleTasksPanel:xe}=wi(),[oe,de]=o.useState(()=>!!(f!=null&&f.draftNewTask)),[Z,ce]=o.useState(()=>f!=null&&f.draftNewTask?{route:f.returnRoute??"/",taskId:f.returnTaskId??null}:null),[te,y]=o.useState(!1),[_,P]=o.useState("transcript"),[E,v]=o.useState("all"),[re,J]=o.useState(!1),[Q,ae]=o.useState(null),[ve,Se]=o.useState([]),[ue,ge]=o.useState([]),[St,$]=o.useState(!1),[he,be]=o.useState(null),[Te,De]=o.useState(new Set),[pe,ls]=o.useState(!1),[zr,is]=o.useState(!1),[Vr,ds]=o.useState(null),cs=o.useRef(null),Ge=o.useRef(null),Oe=((fs=a==null?void 0:a.self)==null?void 0:fs.role)==="leader",_t=(ps=a==null?void 0:a.self)==null?void 0:ps.id;Si({cluster:a,subscribe:u});const fe=o.useCallback(async()=>{try{const i=await Ja({assignedTo:!Oe&&_t?_t:void 0,limit:100});g(i),j(null)}catch(i){j(i instanceof Error?i.message:"Failed to load tasks")}finally{N(!1)}},[Oe,_t]);Ga(fe,1e4),o.useEffect(()=>{fe()},[fe]),o.useEffect(()=>u("task",fe),[u,fe]);const ne=o.useMemo(()=>[...p].sort((i,b)=>b.updatedAt-i.updatedAt),[p]),qr=o.useMemo(()=>{const i=new Map;for(const b of(a==null?void 0:a.nodes)??[]){const k=co(ne,b.id);k>0&&i.set(b.id,k)}return i},[a==null?void 0:a.nodes,ne]),_e=o.useMemo(()=>ne.filter(i=>!Kl(i,O)||H!=="all"&&i.agent!==H||R==="unassigned"&&i.assignedTo||R!=="all"&&R!=="unassigned"&&Gl(i.assignedTo,a==null?void 0:a.nodes,i.assignedNodeName)!==R?!1:S.trim()?Jl(i,S):!0),[ne,O,H,R,S]);o.useEffect(()=>{De(i=>{const b=fo(i,_e.map(k=>k.id));return b.size===i.size?i:b})},[_e]),o.useEffect(()=>{Oe||De(new Set)},[Oe]);const Wr=o.useMemo(()=>["all",...Array.from(new Set(ne.map(i=>i.agent))).sort()],[ne]),Hr=o.useMemo(()=>{const b=Array.from(new Set(ne.map(k=>k.assignedTo).filter(k=>!!k))).map(k=>{const se=ne.find(B=>B.assignedTo===k);return(a==null?void 0:a.nodes.find(B=>B.id===k))??{id:k,name:as(k,a==null?void 0:a.nodes,se==null?void 0:se.assignedNodeName)}}).sort((k,se)=>k.name.localeCompare(se.name));return[{value:"all",label:"All nodes"},{value:"unassigned",label:"Unassigned"},...b.map(k=>({value:k.name.toLowerCase(),label:k.name}))]},[ne,a==null?void 0:a.nodes]),us=o.useMemo(()=>{const i=new Map;for(const b of(a==null?void 0:a.nodes)??[])i.set(b.id,b.name);for(const b of ne)b.assignedTo&&b.assignedNodeName&&!i.has(b.assignedTo)&&i.set(b.assignedTo,b.assignedNodeName);return i},[a==null?void 0:a.nodes,ne]),At=o.useMemo(()=>["all",...Array.from(new Set(l.map(i=>i.type))).sort()],[l]),Kr=o.useMemo(()=>E==="all"?l:l.filter(i=>i.type===E),[l,E]),Jr=_e.length>0&&_e.every(i=>Te.has(i.id)),Gr=_e.some(i=>Te.has(i.id)),Yr=po(_e,Te);o.useEffect(()=>{f!=null&&f.draftNewTask&&(de(!0),ce({route:f.returnRoute??"/",taskId:f.returnTaskId??null}))},[f]),o.useEffect(()=>{E!=="all"&&!At.includes(E)&&v("all")},[E,At]),o.useEffect(()=>{Ns(t,oe)&&!w&&ne[0]&&D(ne[0].id)},[t,oe,w,ne]),o.useEffect(()=>{var i;Ns(t,oe)&&(w&&p.some(b=>b.id===w)||D(((i=ne[0])==null?void 0:i.id)??null))},[t,oe,w,ne,p]);const G=mo({routeTaskId:t,creatingTask:oe,internalSelectedTaskId:w,sortedTaskIds:ne.map(i=>i.id)}),Ue=o.useMemo(()=>p.find(i=>i.id===G)??null,[p,G]);o.useEffect(()=>{Ge.current=G??null},[G]);const nt=o.useCallback(()=>{ae(null),Se([]),ge([]),be(null)},[]),Ne=o.useCallback(async()=>{const i=G;if(i)try{const b=await Ya(i);if(Ge.current!==i)return;ae(b),be(null)}catch(b){if(Ge.current!==i)return;ae(null),Se([]),ge([]),be(b instanceof Error?b.message:"Failed to load task")}finally{Ge.current===i&&$(!1)}},[G]),ot=o.useCallback(async()=>{const i=G;if(i)try{const b=await Xa(i);if(Ge.current!==i)return;Se(k=>Bo(k,b.logs)),ge(k=>Vo(k,b.logs))}catch{}},[G]);o.useEffect(()=>{if(!G){ae(null),Se([]),ge([]),be(null),$(!1);return}P("transcript"),ae(Ue),Se([]),ge([]),be(null),$(!0),Ne(),ot()},[G,ot,Ne]),o.useEffect(()=>{var b;if(!G||oe||d||p.some(k=>k.id===G))return;const i=((b=ne[0])==null?void 0:b.id)??null;D(i),nt(),o.startTransition(()=>{r(i?`/tasks/${i}`:"/",{state:null})})},[G,nt,oe,r,ne,p,d]),o.useEffect(()=>{Ue&&ae(i=>!i||i.id!==Ue.id?i:{...i,...Ue})},[Ue]),o.useEffect(()=>{if(G)return u("task",i=>{const b=i.data.taskId;if(!(typeof b!="string"||b!==G)){if(i.type==="task.output"){const k=i.data.event;if(k){Se(B=>zo(B,k));const se=rt(k);se&&ge(B=>qo(B,se))}}i.type==="task.status"&&(Ne(),ot())}})},[u,G,Ne,ot]),o.useEffect(()=>{var i;_==="transcript"&&((i=cs.current)==null||i.scrollIntoView({behavior:"smooth"}))},[ve,ue,_]);const W=Q??Ue,Xr=W!=null&&W.assignedTo?(a==null?void 0:a.nodes.find(i=>i.id===W.assignedTo))??null:null,Tt=ue.length>0,Zr=W?_l.has(W.agent):!1,Et=(W==null?void 0:W.status)==="running",Qr=W?jt.has(W.status)||Pr.has(W.status):!1,ea=!!(W&&Oe&&W.status==="failed"),Dt=o.useMemo(()=>gi(W,a,Tt,!!Et),[W,a,Tt,Et]),ta=o.useMemo(()=>Wo(ve),[ve]),Mt=o.useMemo(()=>Ho([...ve,...ue.map(i=>$t(i.content,i.timestamp))]),[ve,ue]),sa=o.useMemo(()=>{if(!W)return null;const i=vo(W);if(i.length>0)return $t(i,new Date(W.createdAt).toISOString());if(Mt.length>0)return null;const b=Ye(W.description||W.title);return b.length>0?$t(b,new Date(W.createdAt).toISOString()):null},[W,Mt]),Pt=o.useCallback(()=>{const i={route:t?`/tasks/${t}`:"/",taskId:G};ce(i),de(!0),o.startTransition(()=>{r("/",{state:{draftNewTask:!0,returnRoute:i.route,returnTaskId:i.taskId}})})},[t,G,r]),ra=o.useCallback(()=>{var b;const i=(Z==null?void 0:Z.taskId)??((b=ne[0])==null?void 0:b.id)??null;de(!1),ce(null),D(i),o.startTransition(()=>{r((Z==null?void 0:Z.route)??"/",{state:null})})},[Z,ne,r]),ms=o.useCallback(i=>{de(!1),ce(null),D(i),o.startTransition(()=>{r(`/tasks/${i}`,{state:null})})},[r]),aa=o.useCallback(i=>{de(!1),ce(null),g(b=>xo(b,i)),ae(i),Se([]),ge([]),be(null),$(!1),P("transcript"),D(i.id),fe(),o.startTransition(()=>{r(`/tasks/${i.id}`,{state:null})})},[fe,r]),lt=o.useCallback(async i=>{if(!G)return!1;const b=`local-${Date.now()}-${Math.random().toString(16).slice(2)}`;ge(k=>[...k,{id:b,content:i,timestamp:new Date().toISOString()}]);try{return await Za(G,i),Ne(),!0}catch(k){return ge(se=>se.filter(B=>B.id!==b)),le.error(k instanceof Error?k.message:"Failed to send message"),!1}},[G,Ne]),na=o.useCallback(i=>{lt(i)},[lt]),oa=o.useCallback(i=>lt(i),[lt]),la=o.useCallback(async()=>{if(W)try{await Qa(W.id),Ne(),fe()}catch(i){le.error(i instanceof Error?i.message:"Failed to cancel task")}},[W,Ne,fe]),ia=o.useCallback(async()=>{if(W)try{await en(W.id),Ne(),fe()}catch(i){le.error(i instanceof Error?i.message:"Failed to retry task")}},[W,Ne,fe]),it=o.useCallback((i,b=!1)=>{const k=go(_e,i);return D(k),(b||!k)&&nt(),o.startTransition(()=>{r(k?`/tasks/${k}`:"/",{state:null})}),k},[nt,_e,r]),da=o.useCallback((i,b)=>{De(k=>{const se=new Set(k);return b?se.add(i):se.delete(i),se})},[]),ca=o.useCallback(i=>{if(!i){De(new Set);return}De(new Set(_e.map(b=>b.id)))},[_e]),ua=o.useCallback(async()=>{const i=Array.from(Te);if(i.length!==0)try{const{results:b}=await tn(i),k=b.filter(B=>!B.ok),se=b.filter(B=>B.ok).map(B=>B.id);G&&se.includes(G)&&it(se),k.length>0?le.error(`Failed to archive ${k.length} task(s): ${k.map(B=>B.error??B.id).join(", ")}`):le.success(`Archived ${se.length} task(s)`),De(new Set(k.map(B=>B.id))),fe()}catch(b){le.error(b instanceof Error?b.message:"Failed to archive tasks")}},[G,fe,it,Te]),ma=o.useCallback(async()=>{const i=Array.from(Te);if(i.length!==0)try{const{results:b}=await sn(i),k=b.filter(B=>!B.ok),se=b.filter(B=>B.ok).map(B=>B.id);G&&se.includes(G)&&it(se,!0),k.length>0?le.error(`Failed to delete ${k.length} task(s): ${k.map(B=>B.error??B.id).join(", ")}`):le.success(`Deleted ${se.length} task(s)`),De(new Set(k.map(B=>B.id))),fe()}catch(b){le.error(b instanceof Error?b.message:"Failed to delete tasks")}},[G,fe,it,Te]),xa=o.useCallback(async()=>{ls(!0);try{await rn(),x()}catch(i){le.error(i instanceof Error?i.message:"Failed to promote node")}finally{ls(!1)}},[x]),ha=o.useCallback(async()=>{is(!0);try{await an(),le.success("This node left the remote cluster and is leading itself again."),fe(),Ne(),x()}catch(i){le.error(i instanceof Error?i.message:"Failed to leave cluster")}finally{is(!1)}},[Ne,fe,x]),fa=o.useCallback(async i=>{var bs;const b=!Qt(i),k=i.id===((bs=a==null?void 0:a.self)==null?void 0:bs.id),se=k?(n==null?void 0:n.transportType)??i.transportType:i.transportType,B=k&&!b&&Ke(se);ds(i.id);try{B?await nn("direct"):await on(i.id,b),le.success(b?`Enabled remote access on ${i.name}`:`Disabled remote access on ${i.name}`),x()}catch(js){le.error(js instanceof Error?js.message:"Failed to update remote access")}finally{ds(null)}},[(gs=a==null?void 0:a.self)==null?void 0:gs.id,x,n==null?void 0:n.transportType]),xs={toolbarTasks:_e,activeTaskId:G,tasksLoading:d,tasksError:C,isLeader:Oe,scope:O,agentFilter:H,nodeFilter:R,agentOptions:Wr,nodeOptions:Hr,nodeNameById:us,searchQuery:I,selectedTaskIds:Te,allVisibleTasksSelected:Jr,someVisibleTasksSelected:Gr,canBatchArchive:Yr,onSearchChange:ee,onScopeChange:T,onAgentFilterChange:K,onNodeFilterChange:L,onToggleTaskSelected:da,onToggleAllVisibleTasks:ca,onBatchArchive:ua,onBatchDelete:ma,onCreateTask:Pt,onSelectTask:ms,onClose:xe},hs={cluster:a,systemInfo:n,nodeNameById:us,nodeBlockingTaskCounts:qr,eventTypeFilter:E,onEventTypeFilterChange:v,eventTypeOptions:At,filteredEvents:Kr,sseConnected:c,clusterLoading:h,clusterError:m,promotePending:pe,onPromote:xa,onAddNode:()=>y(!0),leavePending:zr,onLeaveCluster:ha,onToggleNodeDevTunnel:fa,devTunnelNodeId:Vr,onClose:()=>X(!1)};return e.jsxs("div",{className:"flex h-full min-h-0 flex-col overflow-hidden pb-2",children:[e.jsxs("div",{className:"flex min-h-0 flex-1 overflow-hidden",children:[e.jsx("div",{className:A("hidden lg:block lg:shrink-0 lg:transition-all lg:duration-300",V?"lg:mr-3 lg:w-[24rem]":"lg:w-0 lg:overflow-hidden"),children:V&&e.jsx(Ls,{...xs})}),e.jsx("section",{className:"min-h-0 min-w-0 flex-1",children:e.jsx(li,{onToggleTasks:xe,desktopTasksOpen:V,mobileTasksPanelOpen:Y,operationsOpen:ie,onToggleOperations:()=>X(i=>!i),cluster:a,sseConnected:c,activeTab:_,setActiveTab:P,creatingTask:oe,activeTask:W,assignedNode:Xr,taskLoading:St,taskError:he,displayEvents:Mt,hasUserMessageInLogs:ta,initialPrompt:sa,supportsFollowUp:Zr,taskUnavailable:Dt.taskUnavailable,chatDisabled:Dt.chatDisabled,chatDisabledReason:Dt.chatDisabledReason,questionBypassEnabled:re,isRunning:!!Et,hasPendingFollowUp:Tt,canCancel:!!Qr,canRetry:!!ea,onRetry:ia,onCancel:la,onStartCreateTask:Pt,onCancelCreateTask:ra,onCreateTask:aa,onSendMessage:na,onQuestionBypassChange:J,onSubmitQuestionResponse:oa,messagesEndRef:cs})}),e.jsx("div",{className:A("hidden xl:block xl:shrink-0 xl:transition-all xl:duration-300",ie?"xl:ml-3 xl:w-[26rem]":"xl:w-0 xl:overflow-hidden"),children:ie&&e.jsx($s,{...hs})})]}),ie&&e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button","aria-label":"Close operations panel",onClick:()=>X(!1),className:"fixed inset-0 z-30 bg-black/45 backdrop-blur-sm xl:hidden"}),e.jsx("div",{ref:q,className:"fixed inset-y-0 right-0 z-40 w-full p-2 sm:max-w-sm sm:p-3 xl:hidden",children:e.jsx($s,{...hs})})]}),Y&&e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button","aria-label":"Close task list",onClick:()=>F(!1),className:"fixed inset-0 z-30 bg-black/45 backdrop-blur-sm lg:hidden"}),e.jsx("div",{ref:U,className:"fixed inset-y-0 left-0 z-40 w-full p-2 sm:max-w-sm sm:p-3 lg:hidden",children:e.jsx(Ls,{...xs,onCreateTask:()=>{F(!1),Pt()},onSelectTask:i=>{F(!1),ms(i)},onClose:()=>F(!1)})})]}),e.jsx(ln,{open:te,onOpenChange:y,children:e.jsx(Xo,{onAdded:()=>{y(!1),x()}})})]})}const Ti=Object.freeze(Object.defineProperty({__proto__:null,DashboardPage:_i},Symbol.toStringTag,{value:"Module"}));export{Ze as C,Ti as D,wn as F,ys as G};