@hienlh/ppm 0.13.32 → 0.13.33

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/assets/skills/ppm/SKILL.md +1 -1
  3. package/assets/skills/ppm/references/http-api.md +1 -1
  4. package/dist/web/assets/{audio-preview-CUQyzUCl.js → audio-preview-Cr3GjyH_.js} +1 -1
  5. package/dist/web/assets/{chat-tab-BAouVHJG.js → chat-tab-Bq8AuPPE.js} +3 -3
  6. package/dist/web/assets/{code-editor-CkZzq2Sd.js → code-editor-abfRXkgG.js} +2 -2
  7. package/dist/web/assets/{conflict-editor-CEilXhpo.js → conflict-editor-UXzd5iEO.js} +1 -1
  8. package/dist/web/assets/{database-viewer-oCfOGBqv.js → database-viewer-iQGshdho.js} +1 -1
  9. package/dist/web/assets/{diff-viewer-B3A6C9W2.js → diff-viewer-Bl-l5K9W.js} +1 -1
  10. package/dist/web/assets/{extension-webview-rH3etns9.js → extension-webview-CCTVAjaU.js} +1 -1
  11. package/dist/web/assets/{glide-data-grid-DdE7PkYl.js → glide-data-grid-DYxTrchL.js} +1 -1
  12. package/dist/web/assets/{image-preview-DsJpgEWA.js → image-preview-DLoL90K7.js} +1 -1
  13. package/dist/web/assets/{index-BQYpBWiY.js → index-BgTyEXDi.js} +10 -10
  14. package/dist/web/assets/keybindings-store-BP0-WBfA.js +1 -0
  15. package/dist/web/assets/{markdown-renderer-C_5GH1wX.js → markdown-renderer-Bv_VAy7V.js} +1 -1
  16. package/dist/web/assets/notification-store-SdYMFZ_D.js +1 -0
  17. package/dist/web/assets/{pdf-preview-CKw0C1oI.js → pdf-preview-DOnr5kiK.js} +1 -1
  18. package/dist/web/assets/{port-forwarding-tab-qO3QPsXx.js → port-forwarding-tab-BVT5RR_9.js} +1 -1
  19. package/dist/web/assets/{postgres-viewer-D5gFlUwQ.js → postgres-viewer-BfLZMw6J.js} +1 -1
  20. package/dist/web/assets/{settings-tab-NbsTG_aq.js → settings-tab-D-G5nGIJ.js} +1 -1
  21. package/dist/web/assets/{sql-query-editor-BUCPRiyQ.js → sql-query-editor-Di1gqWnG.js} +1 -1
  22. package/dist/web/assets/{sqlite-viewer-PKK_aXhw.js → sqlite-viewer-DT_m_XY3.js} +1 -1
  23. package/dist/web/assets/{terminal-tab-CGsnXNWR.js → terminal-tab-CBOCgoJn.js} +1 -1
  24. package/dist/web/assets/{video-preview-BLk5vtRN.js → video-preview-B4Jz9ymO.js} +1 -1
  25. package/dist/web/index.html +1 -1
  26. package/dist/web/sw.js +1 -1
  27. package/package.json +1 -1
  28. package/src/server/ws/chat.ts +4 -2
  29. package/src/web/components/layout/notification-bell-popover.tsx +6 -9
  30. package/src/web/components/layout/project-bar.tsx +3 -1
  31. package/src/web/hooks/use-chat.ts +2 -2
  32. package/src/web/stores/notification-store.ts +7 -5
  33. package/dist/web/assets/keybindings-store-D4HbcnQd.js +0 -1
  34. package/dist/web/assets/notification-store-ByLxhBXA.js +0 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.13.33] - 2026-04-25
4
+
5
+ ### Added
6
+ - **Notification bell in project bar**: Bell button with unread session count badge in sidebar footer. Popover lists unread sessions grouped by project with session titles — click to navigate directly
7
+ - **Session titles in notifications**: Backend `getAllUnread()` JOINs session titles, WS broadcasts include `sessionTitle` for display in bell popover
8
+
9
+ ### Fixed
10
+ - **Web title unread count inflated**: `selectTotalUnread` was summing event counts instead of counting sessions — reading one session could subtract multiple from the `(N)` title badge. Now counts unique sessions
11
+
3
12
  ## [0.13.32] - 2026-04-25
4
13
 
5
14
  ### Fixed
@@ -71,4 +71,4 @@ This skill covers the `ppm` CLI, its HTTP API, and its config DB. It does **not*
71
71
  - Third-party extensions (inspect via `ppm ext list`).
72
72
  - The Claude Agent SDK internals (separate skill).
73
73
 
74
- <!-- Generated for PPM v0.13.32 at build time. Re-run `ppm export skill --install` to refresh. -->
74
+ <!-- Generated for PPM v0.13.33 at build time. Re-run `ppm export skill --install` to refresh. -->
@@ -201,4 +201,4 @@ _Base URL: `http://localhost:8080` (default; override via `ppm config set port <
201
201
  - `ws://<host>/ws/terminal` — PTY terminal multiplexer
202
202
  - `ws://<host>/ws/extensions` — extension host channel
203
203
 
204
- <!-- Generated from src/server/routes/ for PPM v0.13.32 -->
204
+ <!-- Generated from src/server/routes/ for PPM v0.13.33 -->
@@ -1 +1 @@
1
- import{b as e}from"./vendor-markdown-0Mxgxy0L.js";import{t}from"./createLucideIcon-BjHrJDVb.js";import{t as n}from"./file-exclamation-point-BwzaQ50n.js";import"./api-client-DIhJ5qVW.js";import{t as r}from"./utils-CQux7CsO.js";import{G as i}from"./index-BQYpBWiY.js";import{t as a}from"./use-blob-url-QX-XajU8.js";var o=t(`music`,[[`path`,{d:`M9 18V5l12-2v13`,key:`1jmyc2`}],[`circle`,{cx:`6`,cy:`18`,r:`3`,key:`fqmcym`}],[`circle`,{cx:`18`,cy:`16`,r:`3`,key:`1hluhg`}]]),s=e();function c({filePath:e,projectName:t}){let{blobUrl:c,error:l}=a(e,t);return l?(0,s.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full gap-3 text-text-secondary`,children:[(0,s.jsx)(n,{className:`size-10 text-text-subtle`}),(0,s.jsx)(`p`,{className:`text-sm`,children:`Failed to load audio.`})]}):c?(0,s.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full gap-4 p-4 bg-surface`,children:[(0,s.jsx)(o,{className:`size-16 text-text-subtle`}),(0,s.jsx)(`p`,{className:`text-sm text-text-secondary truncate max-w-xs`,children:r(e)}),(0,s.jsx)(`audio`,{src:c,controls:!0,className:`w-full max-w-md`})]}):(0,s.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,s.jsx)(i,{className:`size-5 animate-spin text-text-subtle`})})}export{c as AudioPreview};
1
+ import{b as e}from"./vendor-markdown-0Mxgxy0L.js";import{t}from"./createLucideIcon-BjHrJDVb.js";import{t as n}from"./file-exclamation-point-BwzaQ50n.js";import"./api-client-DIhJ5qVW.js";import{t as r}from"./utils-CQux7CsO.js";import{G as i}from"./index-BgTyEXDi.js";import{t as a}from"./use-blob-url-QX-XajU8.js";var o=t(`music`,[[`path`,{d:`M9 18V5l12-2v13`,key:`1jmyc2`}],[`circle`,{cx:`6`,cy:`18`,r:`3`,key:`fqmcym`}],[`circle`,{cx:`18`,cy:`16`,r:`3`,key:`1hluhg`}]]),s=e();function c({filePath:e,projectName:t}){let{blobUrl:c,error:l}=a(e,t);return l?(0,s.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full gap-3 text-text-secondary`,children:[(0,s.jsx)(n,{className:`size-10 text-text-subtle`}),(0,s.jsx)(`p`,{className:`text-sm`,children:`Failed to load audio.`})]}):c?(0,s.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full gap-4 p-4 bg-surface`,children:[(0,s.jsx)(o,{className:`size-16 text-text-subtle`}),(0,s.jsx)(`p`,{className:`text-sm text-text-secondary truncate max-w-xs`,children:r(e)}),(0,s.jsx)(`audio`,{src:c,controls:!0,className:`w-full max-w-md`})]}):(0,s.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,s.jsx)(i,{className:`size-5 animate-spin text-text-subtle`})})}export{c as AudioPreview};
@@ -1,10 +1,10 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/markdown-renderer-C_5GH1wX.js","assets/rolldown-runtime-FhOqtrmT.js","assets/index-BQYpBWiY.js","assets/vendor-mermaid-Cl50p6TB.js","assets/vendor-ui-B-89Uj8i.js","assets/vendor-markdown-0Mxgxy0L.js","assets/input-4ll___Gh.js","assets/utils-CQux7CsO.js","assets/createLucideIcon-BjHrJDVb.js","assets/x-BPReZWnP.js","assets/settings-store-CVrIYYCB.js","assets/react-DMIOAtcX.js","assets/api-client-DIhJ5qVW.js","assets/scroll-area-iv39O3VN.js","assets/ai-settings-section-DN4egS8e.js","assets/dist-CaKCIxem.js","assets/refresh-cw-BjrAbUJe.js","assets/api-settings-DnHv6JgF.js","assets/database-DOWH9-Vv.js","assets/chevron-right-DnHIvvcy.js","assets/search-tM8K5zWU.js","assets/file-store-DOxcU_7s.js","assets/tab-store-S9w6U5gm.js","assets/index-C9ej6g0c.css"])))=>i.map(i=>d[i]);
2
- import{o as e}from"./rolldown-runtime-FhOqtrmT.js";import{b as t,x as n}from"./vendor-markdown-0Mxgxy0L.js";import"./vendor-ui-B-89Uj8i.js";import{t as r}from"./createLucideIcon-BjHrJDVb.js";import{t as i}from"./arrow-up-Rcw6_KKu.js";import{_ as a,a as o,c as s,d as c,f as l,g as u,h as d,i as f,l as p,m,n as h,o as g,p as _,r as v,s as y,t as b,u as x}from"./ai-settings-section-DN4egS8e.js";import{i as S,n as C,r as w}from"./dist-CaKCIxem.js";import{t as T}from"./chevron-right-DnHIvvcy.js";import{a as E,i as D,l as O,n as k,o as A,r as j,s as M,t as N,u as P}from"./input-4ll___Gh.js";import{t as F}from"./code-DGBecc50.js";import{i as I,n as L,r as ee,t as R}from"./search-tM8K5zWU.js";import{a as z,i as B,n as te,r as V,t as H}from"./x-BPReZWnP.js";import{t as U}from"./refresh-cw-BjrAbUJe.js";import{t as ne}from"./sparkles-CulWHe4c.js";import{i as W,r as re,t as G}from"./api-client-DIhJ5qVW.js";import{n as K}from"./settings-store-CVrIYYCB.js";import{K as ie}from"./vendor-mermaid-Cl50p6TB.js";import{n as q,r as ae,t as J}from"./utils-CQux7CsO.js";import{n as Y,t as X}from"./tab-store-S9w6U5gm.js";import{i as oe,n as se}from"./file-store-DOxcU_7s.js";import{a as ce,c as le,f as ue,g as de,i as fe,l as pe,m as me,o as he,p as ge,r as _e,s as ve,t as ye,u as be}from"./api-settings-DnHv6JgF.js";import{$ as xe,B as Se,F as Ce,G as Z,H as we,J as Te,L as Ee,M as De,N as Oe,P as ke,R as Ae,S as je,V as Me,W as Ne,X as Pe,_ as Fe,et as Ie,h as Le,i as Re,j as ze,nt as Be,q as Ve,r as He,rt as Ue,t as We,y as Ge,z as Ke}from"./index-BQYpBWiY.js";var qe=r(`activity`,[[`path`,{d:`M22 12h-2.48a2 2 0 0 0-1.93 1.46l-2.35 8.36a.25.25 0 0 1-.48 0L9.24 2.18a.25.25 0 0 0-.48 0l-2.35 8.36A2 2 0 0 1 4.49 12H2`,key:`169zse`}]]),Je=r(`calendar-x-2`,[[`path`,{d:`M8 2v4`,key:`1cmpym`}],[`path`,{d:`M16 2v4`,key:`4m81vk`}],[`path`,{d:`M21 13V6a2 2 0 0 0-2-2H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h8`,key:`3spt84`}],[`path`,{d:`M3 10h18`,key:`8toen8`}],[`path`,{d:`m17 22 5-5`,key:`1k6ppv`}],[`path`,{d:`m17 17 5 5`,key:`p7ous7`}]]),Ye=r(`circle-x`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`m15 9-6 6`,key:`1uzhvr`}],[`path`,{d:`m9 9 6 6`,key:`z0biqf`}]]),Xe=r(`clipboard-check`,[[`rect`,{width:`8`,height:`4`,x:`8`,y:`2`,rx:`1`,ry:`1`,key:`tgr4d6`}],[`path`,{d:`M16 4h2a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2h2`,key:`116196`}],[`path`,{d:`m9 14 2 2 4-4`,key:`df797q`}]]),Ze=r(`clipboard-list`,[[`rect`,{width:`8`,height:`4`,x:`8`,y:`2`,rx:`1`,ry:`1`,key:`tgr4d6`}],[`path`,{d:`M16 4h2a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2h2`,key:`116196`}],[`path`,{d:`M12 11h4`,key:`1jrz19`}],[`path`,{d:`M12 16h4`,key:`n85exb`}],[`path`,{d:`M8 11h.01`,key:`1dfujw`}],[`path`,{d:`M8 16h.01`,key:`18s6g9`}]]),Qe=r(`hand`,[[`path`,{d:`M18 11V6a2 2 0 0 0-2-2a2 2 0 0 0-2 2`,key:`1fvzgz`}],[`path`,{d:`M14 10V4a2 2 0 0 0-2-2a2 2 0 0 0-2 2v2`,key:`1kc0my`}],[`path`,{d:`M10 10.5V6a2 2 0 0 0-2-2a2 2 0 0 0-2 2v8`,key:`10h0bg`}],[`path`,{d:`M18 8a2 2 0 1 1 4 0v6a8 8 0 0 1-8 8h-2c-2.8 0-4.5-.86-5.99-2.34l-3.6-3.6a2 2 0 0 1 2.83-2.82L7 15`,key:`1s1gnw`}]]),$e=r(`history`,[[`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`}]]),et=r(`image`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,ry:`2`,key:`1m3agn`}],[`circle`,{cx:`9`,cy:`9`,r:`2`,key:`af1f0g`}],[`path`,{d:`m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21`,key:`1xmnt7`}]]),tt=r(`list-ordered`,[[`path`,{d:`M11 5h10`,key:`1cz7ny`}],[`path`,{d:`M11 12h10`,key:`1438ji`}],[`path`,{d:`M11 19h10`,key:`11t30w`}],[`path`,{d:`M4 4h1v5`,key:`10yrso`}],[`path`,{d:`M4 9h2`,key:`r1h2o0`}],[`path`,{d:`M6.5 20H3.4c0-1 2.6-1.925 2.6-3.5a1.5 1.5 0 0 0-2.6-1.02`,key:`xtkcd5`}]]),nt=r(`list-todo`,[[`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`}],[`rect`,{x:`3`,y:`4`,width:`6`,height:`6`,rx:`1`,key:`cif1o7`}]]),rt=r(`maximize-2`,[[`path`,{d:`M15 3h6v6`,key:`1q9fwt`}],[`path`,{d:`m21 3-7 7`,key:`1l2asr`}],[`path`,{d:`m3 21 7-7`,key:`tjx5ai`}],[`path`,{d:`M9 21H3v-6`,key:`wtvkvv`}]]),it=r(`mic-off`,[[`path`,{d:`M12 19v3`,key:`npa21l`}],[`path`,{d:`M15 9.34V5a3 3 0 0 0-5.68-1.33`,key:`1gzdoj`}],[`path`,{d:`M16.95 16.95A7 7 0 0 1 5 12v-2`,key:`cqa7eg`}],[`path`,{d:`M18.89 13.23A7 7 0 0 0 19 12v-2`,key:`16hl24`}],[`path`,{d:`m2 2 20 20`,key:`1ooewy`}],[`path`,{d:`M9 9v3a3 3 0 0 0 5.12 2.12`,key:`r2i35w`}]]),at=r(`minimize-2`,[[`path`,{d:`m14 10 7-7`,key:`oa77jy`}],[`path`,{d:`M20 10h-6V4`,key:`mjg0md`}],[`path`,{d:`m3 21 7-7`,key:`tjx5ai`}],[`path`,{d:`M4 14h6v6`,key:`rmj7iw`}]]),ot=r(`paperclip`,[[`path`,{d:`m16 6-8.414 8.586a2 2 0 0 0 2.829 2.829l8.414-8.586a4 4 0 1 0-5.657-5.657l-8.379 8.551a6 6 0 1 0 8.485 8.485l8.379-8.551`,key:`1miecu`}]]),st=r(`shield-alert`,[[`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`}]]),ct=r(`shield-off`,[[`path`,{d:`m2 2 20 20`,key:`1ooewy`}],[`path`,{d:`M5 5a1 1 0 0 0-1 1v7c0 5 3.5 7.5 7.67 8.94a1 1 0 0 0 .67.01c2.35-.82 4.48-1.97 5.9-3.71`,key:`1jlk70`}],[`path`,{d:`M9.309 3.652A12.252 12.252 0 0 0 11.24 2.28a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1v7a9.784 9.784 0 0 1-.08 1.264`,key:`18rp1v`}]]),lt=r(`slash`,[[`path`,{d:`M22 2 2 22`,key:`y4kqgn`}]]),ut=r(`tags`,[[`path`,{d:`M13.172 2a2 2 0 0 1 1.414.586l6.71 6.71a2.4 2.4 0 0 1 0 3.408l-4.592 4.592a2.4 2.4 0 0 1-3.408 0l-6.71-6.71A2 2 0 0 1 6 9.172V3a1 1 0 0 1 1-1z`,key:`16rjxf`}],[`path`,{d:`M2 7v6.172a2 2 0 0 0 .586 1.414l6.71 6.71a2.4 2.4 0 0 0 3.191.193`,key:`178nd4`}],[`circle`,{cx:`10.5`,cy:`6.5`,r:`.5`,fill:`currentColor`,key:`12ikhr`}]]),dt=r(`users`,[[`path`,{d:`M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2`,key:`1yyitq`}],[`path`,{d:`M16 3.128a4 4 0 0 1 0 7.744`,key:`16gr8j`}],[`path`,{d:`M22 21v-2a4 4 0 0 0-3-3.87`,key:`kshegd`}],[`circle`,{cx:`9`,cy:`7`,r:`4`,key:`nufk8`}]]),ft=r(`zap`,[[`path`,{d:`M4 14a1 1 0 0 1-.78-1.63l9.9-10.2a.5.5 0 0 1 .86.46l-1.92 6.02A1 1 0 0 0 13 10h7a1 1 0 0 1 .78 1.63l-9.9 10.2a.5.5 0 0 1-.86-.46l1.92-6.02A1 1 0 0 0 11 14z`,key:`1xq2db`}]]),Q=e(n(),1);function pt({url:e,onMessage:t,autoConnect:n=!0}){let r=(0,Q.useRef)(null);return(0,Q.useEffect)(()=>{let i=new We(e);return r.current=i,t&&i.onMessage(t),n&&i.connect(),()=>{i.disconnect(),r.current=null}},[e,n]),{send:(0,Q.useCallback)(e=>{r.current?.send(e)},[]),connect:(0,Q.useCallback)(()=>{r.current?.connect()},[]),disconnect:(0,Q.useCallback)(()=>{r.current?.disconnect()},[])}}function mt(e){let t=0;for(let n=0;n<e.length;n++)t=(t<<5)-t+e.charCodeAt(n)|0;return Math.abs(t).toString(36)}function ht(e,t){let n=`pc-${mt(t)}-`;return e.map(e=>e.id?{...e,id:`${n}${e.id}`}:e)}function gt(e,t){if(t.size===0)return e;let n=[];for(let r of e){let e=r.id?t.get(r.id):void 0;e&&e.length>0&&n.push(...e),n.push(r)}return n}var _t=null;function vt(){return _t||=new AudioContext,_t}function yt(e,t,n,r,i=`sine`){let a=vt(),o=a.createOscillator(),s=a.createGain();o.type=i,o.frequency.value=e,s.gain.setValueAtTime(r,n),s.gain.exponentialRampToValueAtTime(.001,n+t),o.connect(s),s.connect(a.destination),o.start(n),o.stop(n+t)}function bt(){let e=vt().currentTime;yt(523,.15,e,.15),yt(659,.2,e+.12,.15)}function xt(){let e=vt().currentTime;yt(880,.12,e,.18,`square`),yt(698,.12,e+.15,.18,`square`),yt(880,.15,e+.3,.15,`square`)}function St(){let e=vt().currentTime;yt(440,.12,e,.12),yt(523,.12,e+.1,.12),yt(659,.18,e+.2,.12)}var Ct={done:bt,approval_request:xt,question:St};function wt(e){try{Ct[e]?.()}catch{}}var Tt={hasTeams:!1,teamNames:[],messageCount:0,unreadCount:0};function Et(e){if(document.hidden)return!1;let{panels:t,focusedPanelId:n}=Y.getState(),r=t[n];if(!r)return!1;let i=r.tabs.find(e=>e.id===r.activeTabId);return i?.type===`chat`&&i.metadata?.sessionId===e}function Dt(e,t=`claude`,n=``){let[r,i]=(0,Q.useState)([]),[a,o]=(0,Q.useState)(new Map),[s,c]=(0,Q.useState)(!1),[l,u]=(0,Q.useState)(`idle`),[d,f]=(0,Q.useState)(!1),[p,m]=(0,Q.useState)(0),[h,g]=(0,Q.useState)(null),[_,v]=(0,Q.useState)(null),[y,b]=(0,Q.useState)(null),[x,S]=(0,Q.useState)(null),[w,T]=(0,Q.useState)(null),[E,D]=(0,Q.useState)(!1),O=(0,Q.useRef)(``),k=(0,Q.useRef)([]),A=(0,Q.useRef)(new Map),j=(0,Q.useRef)(null),M=(0,Q.useRef)(`idle`),N=(0,Q.useRef)(null),P=(0,Q.useRef)(()=>{}),F=(0,Q.useRef)(null),I=(0,Q.useRef)(!1),L=(0,Q.useRef)(e);L.current=e;let ee=(0,Q.useRef)(n);ee.current=n;let R=(0,Q.useRef)(null),z=(0,Q.useRef)(0),B=(0,Q.useRef)({teamNames:new Set,messages:[]}),te=(0,Q.useRef)(0),[V,H]=(0,Q.useState)(Tt),[U,ne]=(0,Q.useState)([]),K=(0,Q.useCallback)(()=>{let e=B.current;H({hasTeams:e.teamNames.size>0,teamNames:Array.from(e.teamNames),messageCount:e.messages.length,unreadCount:te.current}),ne([...e.messages])},[]),ie=(0,Q.useCallback)(()=>{te.current=0,K()},[K]),q=l!==`idle`;(0,Q.useEffect)(()=>{if(e)return Fe.getState().setStreaming(e,l!==`idle`),()=>{Fe.getState().setStreaming(e,!1)}},[e,l]);let ae=(0,Q.useCallback)((e,t)=>{let n=k.current.findIndex(e=>e.type===`tool_use`&&(e.tool===`Agent`||e.tool===`Task`)&&e.toolUseId===t);if(n===-1)return!1;let r=k.current[n];if(r.type!==`tool_use`)return!1;let i=[...r.children??[],e];return k.current[n]={...r,children:i},!0},[]),J=(0,Q.useCallback)(()=>{z.current=0;let e=O.current,t=[...k.current],n=j.current;(0,Q.startTransition)(()=>{i(r=>{let i=r[r.length-1];return i?.role===`assistant`&&!i.id.startsWith(`final-`)?[...r.slice(0,-1),{...i,content:e,events:t,...n}]:[...r,{id:`streaming-${Date.now()}`,role:`assistant`,content:e,events:t,timestamp:new Date().toISOString(),...n}]})})},[]),X=(0,Q.useCallback)(()=>{z.current||=window.setTimeout(J,100)},[J]),oe=(0,Q.useCallback)(e=>{let t=e,n=t?.type;if(n)switch(n){case`account_info`:j.current={accountId:t.accountId,accountLabel:t.accountLabel},S(null);break;case`account_retry`:t.accountId&&t.accountLabel&&(j.current={accountId:t.accountId,accountLabel:t.accountLabel}),k.current=[t],X();break;case`status_update`:{let e=t.accountLabel?` (${t.accountLabel})`:``;S(`${t.message}${e}`);break}case`text`:{let e=t.parentToolUseId;if(e&&ae(t,e)){X();break}O.current+=t.content,k.current.push(t),X();break}case`thinking`:{let e=t.parentToolUseId;if(e&&ae(t,e)){X();break}k.current.push(t),X();break}case`tool_use`:{let e=t.parentToolUseId;if(e&&ae(t,e)){X();break}k.current.push(t),X();break}case`tool_result`:{let e=t.toolUseId;e&&A.current.delete(e);let n=t.parentToolUseId;if(n&&ae(t,n)){X();break}k.current.push(t),X();break}case`approval_request`:if(k.current.push(t),I.current)break;if(g({requestId:t.requestId,tool:t.tool,input:t.input}),L.current&&!Et(L.current)){wt(t.tool===`AskUserQuestion`?`question`:`approval_request`);let e=L.current,n=t.tool===`AskUserQuestion`;R.current=C[n?`info`:`warning`](n?`AI has a question`:`${t.tool} needs permission`,{description:ee.current||`Session ${e.slice(0,8)}`,duration:1/0,action:{label:`Go to session`,onClick:()=>{let{panels:t}=Y.getState();for(let[n,r]of Object.entries(t)){let t=r.tabs.find(t=>t.metadata?.sessionId===e);if(t){Y.getState().setActiveTab(t.id,n);break}}}}})}break;case`error`:{k.current.push(t);let e=[...k.current];i(n=>{let r=n[n.length-1];return r?.role===`assistant`?[...n.slice(0,-1),{...r,events:e}]:[...n,{id:`error-${Date.now()}`,role:`system`,content:t.message,events:[t],timestamp:new Date().toISOString()}]});break}case`team_detected`:{let e=t.teamName;e&&(B.current.teamNames.add(e),G.get(`/api/teams/${encodeURIComponent(e)}`).then(e=>{if(e?.messages){let t=B.current.messages,n=e.messages.filter(e=>!t.some(t=>t.timestamp===e.timestamp&&t.from===e.from));t.push(...n),t.sort((e,t)=>new Date(e.timestamp).getTime()-new Date(t.timestamp).getTime()),t.length>500&&t.splice(0,t.length-500)}K()}).catch(()=>{}),K());break}case`team_inbox`:{let e=t.messages;if(Array.isArray(e)){let t=B.current.messages;t.push(...e),t.length>500&&t.splice(0,t.length-500),te.current+=e.length,K()}break}case`team_updated`:K();break;case`bash_output`:{let e=t.toolUseId;if(e){let n=A.current.get(e);n?(n.content+=t.content,n.content.length>5e5&&(n.content=n.content.slice(-5e5)),n.lineCount=t.lineCount):A.current.set(e,{content:t.content,lineCount:t.lineCount}),X()}break}case`done`:{if(M.current===`idle`)break;t.contextWindowPct!=null&&v(t.contextWindowPct),L.current&&!Et(L.current)&&wt(`done`),z.current&&=(clearTimeout(z.current),0);let e=O.current,n=[...k.current],r=j.current,a=t.lastMessageUuid;i(t=>{let i=t[t.length-1];return i?.role===`assistant`?[...t.slice(0,-1),{...i,id:`final-${Date.now()}`,content:e||i.content,events:n.length>0?n:i.events,...a&&{sdkUuid:a}}]:e||n.length>0?[...t,{id:`final-${Date.now()}`,role:`assistant`,content:e,events:n,timestamp:new Date().toISOString(),...a&&{sdkUuid:a},...r}]:t}),O.current=``,k.current=[],j.current=null,A.current.clear(),S(null);break}}},[ae,X]),se=(0,Q.useCallback)(e=>{let t;try{t=JSON.parse(e.data)}catch{return}if(t.type!==`ping`){if(t.type===`file:changed`){window.dispatchEvent(new CustomEvent(`file:changed`,{detail:t}));return}if(t.type===`session:unread_changed`){let{sessionId:e,unreadCount:n,unreadType:r,projectName:i}=t;je.getState().handleUnreadChanged(e,n,r,i);return}if(typeof t.type==`string`&&t.type.startsWith(`jira:`)){window.dispatchEvent(new CustomEvent(t.type,{detail:t}));return}if(t.type===`title_updated`){T(t.title??null);return}if(t.type===`compact_status`){let e=t.status;e===`compacting`?b(`compacting`):e===`done`&&b(null);return}if(t.type===`phase_changed`){let e=t.phase;u(e),M.current=e,m(e===`connecting`?t.elapsed??0:0),e===`idle`&&b(null);return}if(t.type===`session_state`){D(!0);let e=t,n=e.phase;u(n),M.current=n,e.sessionTitle&&T(e.sessionTitle),e.pendingApproval&&g({requestId:e.pendingApproval.requestId,tool:e.pendingApproval.tool,input:e.pendingApproval.input}),b(e.compactStatus===`compacting`?`compacting`:null),n===`idle`&&(F.current?.(),f(!1));return}if(t.type===`turn_events`){let e=t.events,n=t.userMessage;if(!e?.length&&!n){f(!1);return}i(e=>{let t=e,r=t[t.length-1];if(r?.role===`assistant`&&r.id.startsWith(`streaming-`)&&(t=t.slice(0,-1)),n){let e=t[t.length-1];(e?.role!==`user`||e.content!==n)&&(t=[...t,{id:`user-replay-${Date.now()}`,role:`user`,content:n,timestamp:new Date().toISOString()}])}return t}),O.current=``,k.current=[],j.current=null,I.current=!0;let r=0,a=()=>{let t=Math.min(r+100,e.length);for(let n=r;n<t;n++)oe(e[n]);r=t,r<e.length?requestAnimationFrame(a):(I.current=!1,f(!1))};requestAnimationFrame(a);return}oe(t)}},[oe]),{send:ce,connect:le}=pt({url:e&&n?`/ws/project/${encodeURIComponent(n)}/chat/${e}`:``,onMessage:se,autoConnect:!!e&&!!n});P.current=ce,(0,Q.useEffect)(()=>{let r=!1;return u(`idle`),M.current=`idle`,g(null),R.current!=null&&(C.dismiss(R.current),R.current=null),b(null),o(new Map),O.current=``,k.current=[],A.current.clear(),z.current&&=(clearTimeout(z.current),0),D(!1),B.current={teamNames:new Set,messages:[]},te.current=0,H(Tt),ne([]),e&&n?(c(!0),fetch(`${W(n)}/chat/sessions/${e}/messages?providerId=${t}`,{headers:{Authorization:`Bearer ${re()}`}}).then(e=>e.json()).then(e=>{r||M.current!==`idle`||(e.ok&&Array.isArray(e.data)&&e.data.length>0?i(e.data):i([]))}).catch(()=>{!r&&M.current===`idle`&&i([])}).finally(()=>{r||c(!1)})):i([]),()=>{r=!0}},[e,t,n]);let ue=(0,Q.useCallback)((e,t)=>{if(!e.trim())return;let n=M.current!==`idle`;if(n){z.current&&=(clearTimeout(z.current),0);let e=O.current,t=[...k.current];i(n=>{let r=n[n.length-1];return r?.role===`assistant`?[...n.slice(0,-1),{...r,id:`final-${Date.now()}`,content:e||r.content,events:t.length>0?t:r.events}]:n})}i(t=>[...t,{id:`user-${Date.now()}`,role:`user`,content:e,timestamp:new Date().toISOString()}]),O.current=``,k.current=[],N.current=null,n?(u(`thinking`),M.current=`thinking`):(u(`initializing`),M.current=`initializing`),g(null),R.current!=null&&(C.dismiss(R.current),R.current=null),ce(JSON.stringify({type:`message`,content:e,permissionMode:t?.permissionMode,priority:t?.priority,images:t?.images}))},[ce]),de=(0,Q.useCallback)((e,t,n)=>{if(ce(JSON.stringify({type:`approval_response`,requestId:e,approved:t,data:n})),t&&n){let t=k.current.find(t=>t.type===`approval_request`&&t.requestId===e&&t.tool===`AskUserQuestion`);if(t){let e=t.input;e&&typeof e==`object`&&(e.answers=n)}i(e=>[...e])}g(null),R.current!=null&&(C.dismiss(R.current),R.current=null)},[ce]),fe=(0,Q.useCallback)(()=>{if(M.current===`idle`)return;ce(JSON.stringify({type:`cancel`}));let e=O.current,t=[...k.current];i(n=>{let r=n[n.length-1];return r?.role===`assistant`?[...n.slice(0,-1),{...r,id:`final-${Date.now()}`,content:e||r.content,events:t.length>0?t:r.events}]:n}),O.current=``,k.current=[],A.current.clear(),N.current=null,u(`idle`),M.current=`idle`,g(null),R.current!=null&&(C.dismiss(R.current),R.current=null)},[ce]),pe=(0,Q.useCallback)(()=>{D(!1),f(!0),le()},[le]),me=(0,Q.useCallback)(()=>{!e||!n||fetch(`${W(n)}/chat/sessions/${e}/messages?providerId=${t}`,{headers:{Authorization:`Bearer ${re()}`}}).then(e=>e.json()).then(e=>{e.ok&&Array.isArray(e.data)&&e.data.length>0&&(i(e.data),O.current=``,k.current=[])}).catch(()=>{})},[e,t,n]);F.current=me;let he=(0,Q.useCallback)(async(e,t)=>{if(!n)throw Error(`No project context available`);let r=e.replace(/^pc-[^-]+-/,``),i=`${W(n)}/chat/pre-compact-messages?jsonlPath=${encodeURIComponent(t)}&before=${encodeURIComponent(r)}`,a=ht(await G.get(i),t);return o(t=>{let n=new Map(t);return n.set(e,a),n}),a.length},[n]),ge=(0,Q.useCallback)(e=>a.has(e),[a]);return{messages:r,renderedMessages:(0,Q.useMemo)(()=>gt(r,a),[r,a]),expandCompact:he,isCompactExpanded:ge,messagesLoading:s,isStreaming:q,phase:l,isReconnecting:d,connectingElapsed:p,pendingApproval:h,contextWindowPct:_,compactStatus:y,statusMessage:x,sessionTitle:w,teamActivity:V,teamMessages:U,markTeamRead:ie,bashPartialOutput:A,sendMessage:ue,respondToApproval:de,cancelStreaming:fe,reconnect:pe,refetchMessages:me,isConnected:E}}var Ot=12e4;function kt(e,t=`claude`){let[n,r]=(0,Q.useState)({}),[i,a]=(0,Q.useState)(!1),[o,s]=(0,Q.useState)(null),c=(0,Q.useRef)(null),l=(0,Q.useCallback)((n=!1)=>{if(!e)return;a(!0);let i=n?`&refresh=1`:``;fetch(`${W(e)}/chat/usage?providerId=${t}${i}`,{headers:{Authorization:`Bearer ${re()}`}}).then(e=>e.json()).then(e=>{e.ok&&e.data&&(r(t=>({...t,...e.data})),e.data.lastFetchedAt&&s(e.data.lastFetchedAt))}).catch(()=>{}).finally(()=>a(!1))},[e,t]);return(0,Q.useEffect)(()=>(l(),c.current=setInterval(()=>l(),Ot),()=>{c.current&&clearInterval(c.current)}),[l]),{usageInfo:n,usageLoading:i,lastFetchedAt:o,refreshUsage:(0,Q.useCallback)(()=>l(!0),[l])}}var At={damping:.7,stiffness:.05,mass:1.25},jt=70,Mt=1e3/60,Nt=350,Pt=!1;globalThis.document?.addEventListener(`mousedown`,()=>{Pt=!0}),globalThis.document?.addEventListener(`mouseup`,()=>{Pt=!1}),globalThis.document?.addEventListener(`click`,()=>{Pt=!1});var Ft=(e={})=>{let[t,n]=(0,Q.useState)(!1),[r,i]=(0,Q.useState)(e.initial!==!1),[a,o]=(0,Q.useState)(!1),s=(0,Q.useRef)(null);s.current=e;let c=(0,Q.useCallback)(()=>{if(!Pt)return!1;let e=window.getSelection();if(!e||!e.rangeCount)return!1;let t=e.getRangeAt(0);return t.commonAncestorContainer.contains(g.current)||g.current?.contains(t.commonAncestorContainer)},[]),l=(0,Q.useCallback)(e=>{d.isAtBottom=e,i(e)},[]),u=(0,Q.useCallback)(e=>{d.escapedFromLock=e,n(e)},[]),d=(0,Q.useMemo)(()=>{let n;return{escapedFromLock:t,isAtBottom:r,resizeDifference:0,accumulated:0,velocity:0,listeners:new Set,get scrollTop(){return g.current?.scrollTop??0},set scrollTop(e){g.current&&(g.current.scrollTop=e,d.ignoreScrollToTop=g.current.scrollTop)},get targetScrollTop(){return!g.current||!_.current?0:g.current.scrollHeight-1-g.current.clientHeight},get calculatedTargetScrollTop(){if(!g.current||!_.current)return 0;let{targetScrollTop:t}=this;if(!e.targetScrollTop)return t;if(n?.targetScrollTop===t)return n.calculatedScrollTop;let r=Math.max(Math.min(e.targetScrollTop(t,{scrollElement:g.current,contentElement:_.current}),t),0);return n={targetScrollTop:t,calculatedScrollTop:r},requestAnimationFrame(()=>{n=void 0}),r},get scrollDifference(){return this.calculatedTargetScrollTop-this.scrollTop},get isNearBottom(){return this.scrollDifference<=jt}}},[]),f=(0,Q.useCallback)((e={})=>{typeof e==`string`&&(e={animation:e}),e.preserveScrollPosition||l(!0);let t=Date.now()+(Number(e.wait)||0),n=Rt(s.current,e.animation),{ignoreEscapes:r=!1}=e,i,a=d.calculatedTargetScrollTop;e.duration instanceof Promise?e.duration.finally(()=>{i=Date.now()}):i=t+(e.duration??0);let o=async()=>{let e=new Promise(requestAnimationFrame).then(()=>{if(!d.isAtBottom)return d.animation=void 0,!1;let{scrollTop:l}=d,u=performance.now(),p=(u-(d.lastTick??u))/Mt;if(d.animation||={behavior:n,promise:e,ignoreEscapes:r},d.animation.behavior===n&&(d.lastTick=u),c()||t>Date.now())return o();if(l<Math.min(a,d.calculatedTargetScrollTop)){if(d.animation?.behavior===n){if(n===`instant`)return d.scrollTop=d.calculatedTargetScrollTop,o();d.velocity=(n.damping*d.velocity+n.stiffness*d.scrollDifference)/n.mass,d.accumulated+=d.velocity*p,d.scrollTop+=d.accumulated,d.scrollTop!==l&&(d.accumulated=0)}return o()}return i>Date.now()?(a=d.calculatedTargetScrollTop,o()):(d.animation=void 0,d.scrollTop<d.calculatedTargetScrollTop?f({animation:Rt(s.current,s.current.resize),ignoreEscapes:r,duration:Math.max(0,i-Date.now())||void 0}):d.isAtBottom)});return e.then(e=>(requestAnimationFrame(()=>{d.animation||(d.lastTick=void 0,d.velocity=0)}),e))};return e.wait!==!0&&(d.animation=void 0),d.animation?.behavior===n?d.animation.promise:o()},[l,c,d]),p=(0,Q.useCallback)(()=>{u(!0),l(!1)},[u,l]),m=(0,Q.useCallback)(({target:e})=>{if(e!==g.current)return;let{scrollTop:t,ignoreScrollToTop:n}=d,{lastScrollTop:r=t}=d;d.lastScrollTop=t,d.ignoreScrollToTop=void 0,n&&n>t&&(r=n),o(d.isNearBottom),setTimeout(()=>{if(d.resizeDifference||t===n)return;if(c()){u(!0),l(!1);return}let e=t>r,i=t<r;if(d.animation?.ignoreEscapes){d.scrollTop=r;return}i&&(u(!0),l(!1)),e&&u(!1),!d.escapedFromLock&&d.isNearBottom&&l(!0)},1)},[u,l,c,d]),h=(0,Q.useCallback)(({target:e,deltaY:t})=>{let n=e;for(;![`scroll`,`auto`].includes(getComputedStyle(n).overflow);){if(!n.parentElement)return;n=n.parentElement}n===g.current&&t<0&&g.current.scrollHeight>g.current.clientHeight&&!d.animation?.ignoreEscapes&&(u(!0),l(!1))},[u,l,d]),g=It(e=>{g.current?.removeEventListener(`scroll`,m),g.current?.removeEventListener(`wheel`,h),e?.addEventListener(`scroll`,m,{passive:!0}),e?.addEventListener(`wheel`,h,{passive:!0})},[]),_=It(e=>{if(d.resizeObserver?.disconnect(),!e)return;let t;d.resizeObserver=new ResizeObserver(([e])=>{let{height:n}=e.contentRect,r=n-(t??n);if(d.resizeDifference=r,d.scrollTop>d.targetScrollTop&&(d.scrollTop=d.targetScrollTop),o(d.isNearBottom),r>=0){let e=Rt(s.current,t?s.current.resize:s.current.initial);f({animation:e,wait:!0,preserveScrollPosition:!0,duration:e===`instant`?void 0:Nt})}else d.isNearBottom&&(u(!1),l(!0));t=n,requestAnimationFrame(()=>{setTimeout(()=>{d.resizeDifference===r&&(d.resizeDifference=0)},1)})}),d.resizeObserver?.observe(e)},[]);return{contentRef:_,scrollRef:g,scrollToBottom:f,stopScroll:p,isAtBottom:r||a,isNearBottom:a,escapedFromLock:t,state:d}};function It(e,t){let n=(0,Q.useCallback)(t=>(n.current=t,e(t)),t);return n}var Lt=new Map;function Rt(...e){let t={...At},n=!1;for(let r of e){if(r===`instant`){n=!0;continue}typeof r==`object`&&(n=!1,t.damping=r.damping??t.damping,t.stiffness=r.stiffness??t.stiffness,t.mass=r.mass??t.mass)}let r=JSON.stringify(t);return Lt.has(r)||Lt.set(r,Object.freeze(t)),n?`instant`:Lt.get(r)}var zt=(0,Q.createContext)(null),Bt=typeof window<`u`?Q.useLayoutEffect:Q.useEffect;function Vt({instance:e,children:t,resize:n,initial:r,mass:i,damping:a,stiffness:o,targetScrollTop:s,contextRef:c,...l}){let u=(0,Q.useRef)(null),d=Ft({mass:i,damping:a,stiffness:o,resize:n,initial:r,targetScrollTop:Q.useCallback((e,t)=>(y?.targetScrollTop??s)?.(e,t)??e,[s])}),{scrollRef:f,contentRef:p,scrollToBottom:m,stopScroll:h,isAtBottom:g,escapedFromLock:_,state:v}=e??d,y=(0,Q.useMemo)(()=>({scrollToBottom:m,stopScroll:h,scrollRef:f,isAtBottom:g,escapedFromLock:_,contentRef:p,state:v,get targetScrollTop(){return u.current},set targetScrollTop(e){u.current=e}}),[m,g,p,f,h,_,v]);return(0,Q.useImperativeHandle)(c,()=>y,[y]),Bt(()=>{f.current&&getComputedStyle(f.current).overflow===`visible`&&(f.current.style.overflow=`auto`)},[]),Q.createElement(zt.Provider,{value:y},Q.createElement(`div`,{...l},typeof t==`function`?t(y):t))}(function(e){function t({children:e,scrollClassName:t,...n}){let r=Ht();return Q.createElement(`div`,{ref:r.scrollRef,style:{height:`100%`,width:`100%`,scrollbarGutter:`stable both-edges`},className:t},Q.createElement(`div`,{...n,ref:r.contentRef},typeof e==`function`?e(r):e))}e.Content=t})(Vt||={});function Ht(){let e=(0,Q.useContext)(zt);if(!e)throw Error(`use-stick-to-bottom component context must be used within a StickToBottom component`);return e}var $=t(),Ut=(0,Q.lazy)(()=>ie(()=>import(`./markdown-renderer-C_5GH1wX.js`).then(e=>({default:e.MarkdownRenderer})),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23])));function Wt(e){let t=e.type===`approval_request`;return{toolName:e.type===`tool_use`?e.tool:t?e.tool??`Tool`:`Tool`,input:e.type===`tool_use`?e.input:t?e.input??{}:{}}}function Gt({tool:e,result:t,completed:n,projectName:r,bashPartialOutput:i}){let[a,o]=(0,Q.useState)(!1);if(e.type===`error`)return(0,$.jsxs)(`div`,{className:`flex items-center gap-2 rounded bg-red-500/10 border border-red-500/20 px-2 py-1.5 text-xs text-red-400`,children:[(0,$.jsx)(Ue,{className:`size-3`}),(0,$.jsx)(`span`,{children:e.message})]});let{toolName:s,input:c}=Wt(e),l=t?.type===`tool_result`,u=l&&!!t.isError,d=s===`AskUserQuestion`&&!!c?.answers,f=e.type===`approval_request`&&e.approved!=null,p=(s===`Agent`||s===`Task`)&&e.type===`tool_use`,h=p?e.children:void 0,g=h&&h.length>0,_=l||d||f||n,v=e.type===`tool_use`?e.toolUseId:void 0,y=s===`Bash`&&!l&&v?i?.current?.get(v):void 0,b=!!y;return(0,Q.useEffect)(()=>{b&&!a&&o(!0)},[b]),(0,$.jsxs)(`div`,{className:`rounded border text-xs ${p?`border-accent/30 bg-accent/5`:`border-border bg-background`}`,children:[(0,$.jsxs)(`button`,{onClick:()=>o(!a),className:`flex items-center gap-2 px-2 py-1.5 w-full text-left hover:bg-surface transition-colors min-w-0`,children:[a?(0,$.jsx)(m,{className:`size-3 shrink-0`}):(0,$.jsx)(T,{className:`size-3 shrink-0`}),u?(0,$.jsx)(Ye,{className:`size-3 text-red-400 shrink-0`}):_?(0,$.jsx)(Be,{className:`size-3 text-green-400 shrink-0`}):(0,$.jsx)(Z,{className:`size-3 text-yellow-400 shrink-0 animate-spin`}),(0,$.jsx)(`span`,{className:`truncate text-text-primary`,children:(0,$.jsx)(Kt,{name:s,input:c})}),b&&(0,$.jsxs)(`span`,{className:`ml-auto text-[10px] text-yellow-400 shrink-0`,children:[y.lineCount,` line`,y.lineCount===1?``:`s`,` streaming...`]}),g&&!b&&(0,$.jsxs)(`span`,{className:`ml-auto text-[10px] text-text-subtle shrink-0`,children:[h.length,` steps`]})]}),a&&(0,$.jsxs)(`div`,{className:`px-2 pb-2 space-y-1.5 select-text`,children:[(e.type===`tool_use`||e.type===`approval_request`)&&(0,$.jsx)(qt,{name:s,input:c,projectName:r}),y&&(0,$.jsx)($t,{content:y.content,lineCount:y.lineCount}),g&&(0,$.jsx)(Zt,{events:h,projectName:r}),l&&(0,$.jsx)(Yt,{toolName:s,output:t.output})]})]})}function Kt({name:e,input:t}){let n=e=>String(e??``);switch(e){case`Read`:case`Write`:case`Edit`:case`MultiEdit`:case`NotebookEdit`:return(0,$.jsxs)($.Fragment,{children:[e,` `,(0,$.jsx)(`span`,{className:`text-text-subtle`,children:J(n(t.file_path))})]});case`Bash`:{let r=t.description?n(t.description):n(t.command);return(0,$.jsxs)($.Fragment,{children:[e,` `,(0,$.jsx)(`span`,{className:`text-text-subtle${t.description?``:` font-mono`}`,children:en(r,60)})]})}case`Glob`:return(0,$.jsxs)($.Fragment,{children:[e,` `,(0,$.jsx)(`span`,{className:`font-mono text-text-subtle`,children:n(t.pattern)})]});case`Grep`:return(0,$.jsxs)($.Fragment,{children:[e,` `,(0,$.jsx)(`span`,{className:`font-mono text-text-subtle`,children:en(n(t.pattern),40)})]});case`WebSearch`:return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(R,{className:`size-3 inline`}),` `,e,` `,(0,$.jsx)(`span`,{className:`text-text-subtle`,children:en(n(t.query),50)})]});case`WebFetch`:return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(w,{className:`size-3 inline`}),` `,e,` `,(0,$.jsx)(`span`,{className:`text-text-subtle`,children:en(n(t.url),50)})]});case`ToolSearch`:return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(R,{className:`size-3 inline`}),` `,e,` `,(0,$.jsx)(`span`,{className:`text-text-subtle`,children:en(n(t.query),50)})]});case`Agent`:case`Task`:return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(u,{className:`size-3 inline`}),` `,e,` `,(0,$.jsx)(`span`,{className:`text-text-subtle`,children:en(n(t.description||t.prompt),60)})]});case`TodoWrite`:{let n=Array.isArray(t.todos)?t.todos:[],r=n.filter(e=>e.status===`completed`).length;return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(nt,{className:`size-3 inline`}),` `,e,` `,(0,$.jsxs)(`span`,{className:`text-text-subtle`,children:[r,`/`,n.length,` done`]})]})}case`AskUserQuestion`:{let n=Array.isArray(t.questions)?t.questions:[],r=!!t.answers;return(0,$.jsxs)($.Fragment,{children:[e,` `,(0,$.jsxs)(`span`,{className:`text-text-subtle`,children:[n.length,` question`,n.length===1?``:`s`,r?` ✓`:``]})]})}default:return(0,$.jsx)($.Fragment,{children:e})}}function qt({name:e,input:t,projectName:n}){let r=e=>String(e??``),{openTab:i}=X(Le(e=>({openTab:e.openTab}))),a=e=>{n&&i({type:`editor`,title:J(e),metadata:{filePath:e,projectName:n},projectId:n,closable:!0})},o=(e,t,r)=>{i({type:`git-diff`,title:`Diff ${J(e)}`,metadata:{filePath:e,projectName:n,original:t,modified:r},projectId:n??null,closable:!0})};switch(e){case`Bash`:return(0,$.jsxs)(`div`,{className:`space-y-1`,children:[!!t.description&&(0,$.jsx)(`p`,{className:`text-text-subtle italic`,children:r(t.description)}),(0,$.jsx)(`pre`,{className:`font-mono text-text-secondary overflow-x-auto whitespace-pre-wrap break-all`,children:r(t.command)})]});case`Read`:case`Write`:case`Edit`:case`MultiEdit`:case`NotebookEdit`:{let n=r(t.file_path);return(0,$.jsxs)(`div`,{className:`space-y-1`,children:[(0,$.jsxs)(`button`,{type:`button`,className:`font-mono text-text-secondary break-all hover:text-primary hover:underline text-left flex items-center gap-1`,onClick:()=>a(n),title:`Open file in editor`,children:[(0,$.jsx)(xe,{className:`size-3 shrink-0`}),n]}),e===`Edit`&&(!!t.old_string||!!t.new_string)&&(0,$.jsxs)(`button`,{type:`button`,className:`text-text-subtle hover:text-primary hover:underline text-left flex items-center gap-1`,onClick:()=>o(n,r(t.old_string),r(t.new_string)),title:`View diff in new tab`,children:[(0,$.jsx)(I,{className:`size-3 shrink-0`}),`View Diff`]}),e===`Write`&&!!t.content&&(0,$.jsx)(`pre`,{className:`font-mono text-text-subtle overflow-x-auto max-h-32 whitespace-pre-wrap`,children:en(r(t.content),300)})]})}case`Glob`:return(0,$.jsxs)(`p`,{className:`font-mono text-text-secondary`,children:[r(t.pattern),t.path?` in ${r(t.path)}`:``]});case`Grep`:return(0,$.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,$.jsxs)(`p`,{className:`font-mono text-text-secondary`,children:[`/`,r(t.pattern),`/`]}),!!t.path&&(0,$.jsxs)(`p`,{className:`text-text-subtle`,children:[`in `,r(t.path)]})]});case`TodoWrite`:return(0,$.jsx)(Jt,{todos:t.todos??[]});case`Agent`:case`Task`:return(0,$.jsxs)(`div`,{className:`space-y-1`,children:[!!t.description&&(0,$.jsx)(`p`,{className:`text-text-secondary font-medium`,children:r(t.description)}),!!t.subagent_type&&(0,$.jsxs)(`p`,{className:`text-text-subtle`,children:[`Type: `,r(t.subagent_type)]}),!!t.prompt&&(0,$.jsx)(Qt,{content:r(t.prompt),maxHeight:`max-h-48`})]});case`ToolSearch`:return(0,$.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,$.jsx)(`p`,{className:`font-mono text-text-secondary`,children:r(t.query)}),!!t.max_results&&(0,$.jsxs)(`p`,{className:`text-text-subtle`,children:[`Max results: `,r(t.max_results)]})]});case`WebFetch`:return(0,$.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,$.jsxs)(`a`,{href:r(t.url),target:`_blank`,rel:`noopener noreferrer`,className:`font-mono text-primary hover:underline break-all flex items-center gap-1`,children:[(0,$.jsx)(w,{className:`size-3 shrink-0`}),r(t.url)]}),!!t.prompt&&(0,$.jsx)(`p`,{className:`text-text-subtle`,children:en(r(t.prompt),100)})]});case`AskUserQuestion`:{let e=t.questions??[],n=t.answers??{};return(0,$.jsx)(`div`,{className:`space-y-2`,children:e.map((e,t)=>(0,$.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,$.jsxs)(`p`,{className:`text-text-primary font-medium`,children:[e.header?`${e.header}: `:``,e.question]}),(0,$.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:e.options.map((t,r)=>(0,$.jsx)(`span`,{className:`inline-block rounded px-1.5 py-0.5 text-xs border ${(n[e.question]??``).split(`, `).includes(t.label)?`border-accent bg-accent/20 text-text-primary`:`border-border text-text-subtle`}`,children:t.label},r))}),n[e.question]&&(0,$.jsxs)(`p`,{className:`text-foreground text-xs`,children:[`Answer: `,n[e.question]]})]},t))})}default:return(0,$.jsx)(`pre`,{className:`overflow-x-auto text-text-secondary font-mono whitespace-pre-wrap break-all`,children:JSON.stringify(t,null,2)})}}function Jt({todos:e}){return(0,$.jsx)(`div`,{className:`space-y-0.5`,children:e.map((e,t)=>(0,$.jsxs)(`div`,{className:`flex items-start gap-1.5`,children:[(0,$.jsx)(`span`,{className:`shrink-0 mt-0.5 ${e.status===`completed`?`text-green-400`:e.status===`in_progress`?`text-yellow-400`:`text-text-subtle`}`,children:e.status===`completed`?`✓`:e.status===`in_progress`?`▶`:`○`}),(0,$.jsx)(`span`,{className:e.status===`completed`?`line-through text-text-subtle`:`text-text-secondary`,children:e.content})]},t))})}function Yt({toolName:e,output:t}){let[n,r]=(0,Q.useState)(!1),i=(0,Q.useMemo)(()=>{if(e!==`Agent`&&e!==`Task`)return null;try{let e=JSON.parse(t);if(Array.isArray(e)){let t=e.filter(e=>e.type===`text`&&e.text).map(e=>e.text).join(`
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/markdown-renderer-Bv_VAy7V.js","assets/rolldown-runtime-FhOqtrmT.js","assets/index-BgTyEXDi.js","assets/vendor-mermaid-Cl50p6TB.js","assets/vendor-ui-B-89Uj8i.js","assets/vendor-markdown-0Mxgxy0L.js","assets/input-4ll___Gh.js","assets/utils-CQux7CsO.js","assets/createLucideIcon-BjHrJDVb.js","assets/x-BPReZWnP.js","assets/settings-store-CVrIYYCB.js","assets/react-DMIOAtcX.js","assets/api-client-DIhJ5qVW.js","assets/scroll-area-iv39O3VN.js","assets/ai-settings-section-DN4egS8e.js","assets/dist-CaKCIxem.js","assets/refresh-cw-BjrAbUJe.js","assets/api-settings-DnHv6JgF.js","assets/database-DOWH9-Vv.js","assets/chevron-right-DnHIvvcy.js","assets/search-tM8K5zWU.js","assets/file-store-DOxcU_7s.js","assets/tab-store-S9w6U5gm.js","assets/index-C9ej6g0c.css"])))=>i.map(i=>d[i]);
2
+ import{o as e}from"./rolldown-runtime-FhOqtrmT.js";import{b as t,x as n}from"./vendor-markdown-0Mxgxy0L.js";import"./vendor-ui-B-89Uj8i.js";import{t as r}from"./createLucideIcon-BjHrJDVb.js";import{t as i}from"./arrow-up-Rcw6_KKu.js";import{_ as a,a as o,c as s,d as c,f as l,g as u,h as d,i as f,l as p,m,n as h,o as g,p as _,r as v,s as y,t as b,u as x}from"./ai-settings-section-DN4egS8e.js";import{i as S,n as C,r as w}from"./dist-CaKCIxem.js";import{t as T}from"./chevron-right-DnHIvvcy.js";import{a as E,i as D,l as O,n as k,o as A,r as j,s as M,t as N,u as P}from"./input-4ll___Gh.js";import{t as F}from"./code-DGBecc50.js";import{i as I,n as L,r as ee,t as R}from"./search-tM8K5zWU.js";import{a as z,i as B,n as te,r as V,t as H}from"./x-BPReZWnP.js";import{t as U}from"./refresh-cw-BjrAbUJe.js";import{t as ne}from"./sparkles-CulWHe4c.js";import{i as W,r as re,t as G}from"./api-client-DIhJ5qVW.js";import{n as K}from"./settings-store-CVrIYYCB.js";import{K as ie}from"./vendor-mermaid-Cl50p6TB.js";import{n as q,r as ae,t as J}from"./utils-CQux7CsO.js";import{n as Y,t as X}from"./tab-store-S9w6U5gm.js";import{i as oe,n as se}from"./file-store-DOxcU_7s.js";import{a as ce,c as le,f as ue,g as de,i as fe,l as pe,m as me,o as he,p as ge,r as _e,s as ve,t as ye,u as be}from"./api-settings-DnHv6JgF.js";import{$ as xe,B as Se,F as Ce,G as Z,H as we,J as Te,L as Ee,M as De,N as Oe,P as ke,R as Ae,S as je,V as Me,W as Ne,X as Pe,_ as Fe,et as Ie,h as Le,i as Re,j as ze,nt as Be,q as Ve,r as He,rt as Ue,t as We,y as Ge,z as Ke}from"./index-BgTyEXDi.js";var qe=r(`activity`,[[`path`,{d:`M22 12h-2.48a2 2 0 0 0-1.93 1.46l-2.35 8.36a.25.25 0 0 1-.48 0L9.24 2.18a.25.25 0 0 0-.48 0l-2.35 8.36A2 2 0 0 1 4.49 12H2`,key:`169zse`}]]),Je=r(`calendar-x-2`,[[`path`,{d:`M8 2v4`,key:`1cmpym`}],[`path`,{d:`M16 2v4`,key:`4m81vk`}],[`path`,{d:`M21 13V6a2 2 0 0 0-2-2H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h8`,key:`3spt84`}],[`path`,{d:`M3 10h18`,key:`8toen8`}],[`path`,{d:`m17 22 5-5`,key:`1k6ppv`}],[`path`,{d:`m17 17 5 5`,key:`p7ous7`}]]),Ye=r(`circle-x`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`m15 9-6 6`,key:`1uzhvr`}],[`path`,{d:`m9 9 6 6`,key:`z0biqf`}]]),Xe=r(`clipboard-check`,[[`rect`,{width:`8`,height:`4`,x:`8`,y:`2`,rx:`1`,ry:`1`,key:`tgr4d6`}],[`path`,{d:`M16 4h2a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2h2`,key:`116196`}],[`path`,{d:`m9 14 2 2 4-4`,key:`df797q`}]]),Ze=r(`clipboard-list`,[[`rect`,{width:`8`,height:`4`,x:`8`,y:`2`,rx:`1`,ry:`1`,key:`tgr4d6`}],[`path`,{d:`M16 4h2a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2h2`,key:`116196`}],[`path`,{d:`M12 11h4`,key:`1jrz19`}],[`path`,{d:`M12 16h4`,key:`n85exb`}],[`path`,{d:`M8 11h.01`,key:`1dfujw`}],[`path`,{d:`M8 16h.01`,key:`18s6g9`}]]),Qe=r(`hand`,[[`path`,{d:`M18 11V6a2 2 0 0 0-2-2a2 2 0 0 0-2 2`,key:`1fvzgz`}],[`path`,{d:`M14 10V4a2 2 0 0 0-2-2a2 2 0 0 0-2 2v2`,key:`1kc0my`}],[`path`,{d:`M10 10.5V6a2 2 0 0 0-2-2a2 2 0 0 0-2 2v8`,key:`10h0bg`}],[`path`,{d:`M18 8a2 2 0 1 1 4 0v6a8 8 0 0 1-8 8h-2c-2.8 0-4.5-.86-5.99-2.34l-3.6-3.6a2 2 0 0 1 2.83-2.82L7 15`,key:`1s1gnw`}]]),$e=r(`history`,[[`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`}]]),et=r(`image`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,ry:`2`,key:`1m3agn`}],[`circle`,{cx:`9`,cy:`9`,r:`2`,key:`af1f0g`}],[`path`,{d:`m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21`,key:`1xmnt7`}]]),tt=r(`list-ordered`,[[`path`,{d:`M11 5h10`,key:`1cz7ny`}],[`path`,{d:`M11 12h10`,key:`1438ji`}],[`path`,{d:`M11 19h10`,key:`11t30w`}],[`path`,{d:`M4 4h1v5`,key:`10yrso`}],[`path`,{d:`M4 9h2`,key:`r1h2o0`}],[`path`,{d:`M6.5 20H3.4c0-1 2.6-1.925 2.6-3.5a1.5 1.5 0 0 0-2.6-1.02`,key:`xtkcd5`}]]),nt=r(`list-todo`,[[`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`}],[`rect`,{x:`3`,y:`4`,width:`6`,height:`6`,rx:`1`,key:`cif1o7`}]]),rt=r(`maximize-2`,[[`path`,{d:`M15 3h6v6`,key:`1q9fwt`}],[`path`,{d:`m21 3-7 7`,key:`1l2asr`}],[`path`,{d:`m3 21 7-7`,key:`tjx5ai`}],[`path`,{d:`M9 21H3v-6`,key:`wtvkvv`}]]),it=r(`mic-off`,[[`path`,{d:`M12 19v3`,key:`npa21l`}],[`path`,{d:`M15 9.34V5a3 3 0 0 0-5.68-1.33`,key:`1gzdoj`}],[`path`,{d:`M16.95 16.95A7 7 0 0 1 5 12v-2`,key:`cqa7eg`}],[`path`,{d:`M18.89 13.23A7 7 0 0 0 19 12v-2`,key:`16hl24`}],[`path`,{d:`m2 2 20 20`,key:`1ooewy`}],[`path`,{d:`M9 9v3a3 3 0 0 0 5.12 2.12`,key:`r2i35w`}]]),at=r(`minimize-2`,[[`path`,{d:`m14 10 7-7`,key:`oa77jy`}],[`path`,{d:`M20 10h-6V4`,key:`mjg0md`}],[`path`,{d:`m3 21 7-7`,key:`tjx5ai`}],[`path`,{d:`M4 14h6v6`,key:`rmj7iw`}]]),ot=r(`paperclip`,[[`path`,{d:`m16 6-8.414 8.586a2 2 0 0 0 2.829 2.829l8.414-8.586a4 4 0 1 0-5.657-5.657l-8.379 8.551a6 6 0 1 0 8.485 8.485l8.379-8.551`,key:`1miecu`}]]),st=r(`shield-alert`,[[`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`}]]),ct=r(`shield-off`,[[`path`,{d:`m2 2 20 20`,key:`1ooewy`}],[`path`,{d:`M5 5a1 1 0 0 0-1 1v7c0 5 3.5 7.5 7.67 8.94a1 1 0 0 0 .67.01c2.35-.82 4.48-1.97 5.9-3.71`,key:`1jlk70`}],[`path`,{d:`M9.309 3.652A12.252 12.252 0 0 0 11.24 2.28a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1v7a9.784 9.784 0 0 1-.08 1.264`,key:`18rp1v`}]]),lt=r(`slash`,[[`path`,{d:`M22 2 2 22`,key:`y4kqgn`}]]),ut=r(`tags`,[[`path`,{d:`M13.172 2a2 2 0 0 1 1.414.586l6.71 6.71a2.4 2.4 0 0 1 0 3.408l-4.592 4.592a2.4 2.4 0 0 1-3.408 0l-6.71-6.71A2 2 0 0 1 6 9.172V3a1 1 0 0 1 1-1z`,key:`16rjxf`}],[`path`,{d:`M2 7v6.172a2 2 0 0 0 .586 1.414l6.71 6.71a2.4 2.4 0 0 0 3.191.193`,key:`178nd4`}],[`circle`,{cx:`10.5`,cy:`6.5`,r:`.5`,fill:`currentColor`,key:`12ikhr`}]]),dt=r(`users`,[[`path`,{d:`M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2`,key:`1yyitq`}],[`path`,{d:`M16 3.128a4 4 0 0 1 0 7.744`,key:`16gr8j`}],[`path`,{d:`M22 21v-2a4 4 0 0 0-3-3.87`,key:`kshegd`}],[`circle`,{cx:`9`,cy:`7`,r:`4`,key:`nufk8`}]]),ft=r(`zap`,[[`path`,{d:`M4 14a1 1 0 0 1-.78-1.63l9.9-10.2a.5.5 0 0 1 .86.46l-1.92 6.02A1 1 0 0 0 13 10h7a1 1 0 0 1 .78 1.63l-9.9 10.2a.5.5 0 0 1-.86-.46l1.92-6.02A1 1 0 0 0 11 14z`,key:`1xq2db`}]]),Q=e(n(),1);function pt({url:e,onMessage:t,autoConnect:n=!0}){let r=(0,Q.useRef)(null);return(0,Q.useEffect)(()=>{let i=new We(e);return r.current=i,t&&i.onMessage(t),n&&i.connect(),()=>{i.disconnect(),r.current=null}},[e,n]),{send:(0,Q.useCallback)(e=>{r.current?.send(e)},[]),connect:(0,Q.useCallback)(()=>{r.current?.connect()},[]),disconnect:(0,Q.useCallback)(()=>{r.current?.disconnect()},[])}}function mt(e){let t=0;for(let n=0;n<e.length;n++)t=(t<<5)-t+e.charCodeAt(n)|0;return Math.abs(t).toString(36)}function ht(e,t){let n=`pc-${mt(t)}-`;return e.map(e=>e.id?{...e,id:`${n}${e.id}`}:e)}function gt(e,t){if(t.size===0)return e;let n=[];for(let r of e){let e=r.id?t.get(r.id):void 0;e&&e.length>0&&n.push(...e),n.push(r)}return n}var _t=null;function vt(){return _t||=new AudioContext,_t}function yt(e,t,n,r,i=`sine`){let a=vt(),o=a.createOscillator(),s=a.createGain();o.type=i,o.frequency.value=e,s.gain.setValueAtTime(r,n),s.gain.exponentialRampToValueAtTime(.001,n+t),o.connect(s),s.connect(a.destination),o.start(n),o.stop(n+t)}function bt(){let e=vt().currentTime;yt(523,.15,e,.15),yt(659,.2,e+.12,.15)}function xt(){let e=vt().currentTime;yt(880,.12,e,.18,`square`),yt(698,.12,e+.15,.18,`square`),yt(880,.15,e+.3,.15,`square`)}function St(){let e=vt().currentTime;yt(440,.12,e,.12),yt(523,.12,e+.1,.12),yt(659,.18,e+.2,.12)}var Ct={done:bt,approval_request:xt,question:St};function wt(e){try{Ct[e]?.()}catch{}}var Tt={hasTeams:!1,teamNames:[],messageCount:0,unreadCount:0};function Et(e){if(document.hidden)return!1;let{panels:t,focusedPanelId:n}=Y.getState(),r=t[n];if(!r)return!1;let i=r.tabs.find(e=>e.id===r.activeTabId);return i?.type===`chat`&&i.metadata?.sessionId===e}function Dt(e,t=`claude`,n=``){let[r,i]=(0,Q.useState)([]),[a,o]=(0,Q.useState)(new Map),[s,c]=(0,Q.useState)(!1),[l,u]=(0,Q.useState)(`idle`),[d,f]=(0,Q.useState)(!1),[p,m]=(0,Q.useState)(0),[h,g]=(0,Q.useState)(null),[_,v]=(0,Q.useState)(null),[y,b]=(0,Q.useState)(null),[x,S]=(0,Q.useState)(null),[w,T]=(0,Q.useState)(null),[E,D]=(0,Q.useState)(!1),O=(0,Q.useRef)(``),k=(0,Q.useRef)([]),A=(0,Q.useRef)(new Map),j=(0,Q.useRef)(null),M=(0,Q.useRef)(`idle`),N=(0,Q.useRef)(null),P=(0,Q.useRef)(()=>{}),F=(0,Q.useRef)(null),I=(0,Q.useRef)(!1),L=(0,Q.useRef)(e);L.current=e;let ee=(0,Q.useRef)(n);ee.current=n;let R=(0,Q.useRef)(null),z=(0,Q.useRef)(0),B=(0,Q.useRef)({teamNames:new Set,messages:[]}),te=(0,Q.useRef)(0),[V,H]=(0,Q.useState)(Tt),[U,ne]=(0,Q.useState)([]),K=(0,Q.useCallback)(()=>{let e=B.current;H({hasTeams:e.teamNames.size>0,teamNames:Array.from(e.teamNames),messageCount:e.messages.length,unreadCount:te.current}),ne([...e.messages])},[]),ie=(0,Q.useCallback)(()=>{te.current=0,K()},[K]),q=l!==`idle`;(0,Q.useEffect)(()=>{if(e)return Fe.getState().setStreaming(e,l!==`idle`),()=>{Fe.getState().setStreaming(e,!1)}},[e,l]);let ae=(0,Q.useCallback)((e,t)=>{let n=k.current.findIndex(e=>e.type===`tool_use`&&(e.tool===`Agent`||e.tool===`Task`)&&e.toolUseId===t);if(n===-1)return!1;let r=k.current[n];if(r.type!==`tool_use`)return!1;let i=[...r.children??[],e];return k.current[n]={...r,children:i},!0},[]),J=(0,Q.useCallback)(()=>{z.current=0;let e=O.current,t=[...k.current],n=j.current;(0,Q.startTransition)(()=>{i(r=>{let i=r[r.length-1];return i?.role===`assistant`&&!i.id.startsWith(`final-`)?[...r.slice(0,-1),{...i,content:e,events:t,...n}]:[...r,{id:`streaming-${Date.now()}`,role:`assistant`,content:e,events:t,timestamp:new Date().toISOString(),...n}]})})},[]),X=(0,Q.useCallback)(()=>{z.current||=window.setTimeout(J,100)},[J]),oe=(0,Q.useCallback)(e=>{let t=e,n=t?.type;if(n)switch(n){case`account_info`:j.current={accountId:t.accountId,accountLabel:t.accountLabel},S(null);break;case`account_retry`:t.accountId&&t.accountLabel&&(j.current={accountId:t.accountId,accountLabel:t.accountLabel}),k.current=[t],X();break;case`status_update`:{let e=t.accountLabel?` (${t.accountLabel})`:``;S(`${t.message}${e}`);break}case`text`:{let e=t.parentToolUseId;if(e&&ae(t,e)){X();break}O.current+=t.content,k.current.push(t),X();break}case`thinking`:{let e=t.parentToolUseId;if(e&&ae(t,e)){X();break}k.current.push(t),X();break}case`tool_use`:{let e=t.parentToolUseId;if(e&&ae(t,e)){X();break}k.current.push(t),X();break}case`tool_result`:{let e=t.toolUseId;e&&A.current.delete(e);let n=t.parentToolUseId;if(n&&ae(t,n)){X();break}k.current.push(t),X();break}case`approval_request`:if(k.current.push(t),I.current)break;if(g({requestId:t.requestId,tool:t.tool,input:t.input}),L.current&&!Et(L.current)){wt(t.tool===`AskUserQuestion`?`question`:`approval_request`);let e=L.current,n=t.tool===`AskUserQuestion`;R.current=C[n?`info`:`warning`](n?`AI has a question`:`${t.tool} needs permission`,{description:ee.current||`Session ${e.slice(0,8)}`,duration:1/0,action:{label:`Go to session`,onClick:()=>{let{panels:t}=Y.getState();for(let[n,r]of Object.entries(t)){let t=r.tabs.find(t=>t.metadata?.sessionId===e);if(t){Y.getState().setActiveTab(t.id,n);break}}}}})}break;case`error`:{k.current.push(t);let e=[...k.current];i(n=>{let r=n[n.length-1];return r?.role===`assistant`?[...n.slice(0,-1),{...r,events:e}]:[...n,{id:`error-${Date.now()}`,role:`system`,content:t.message,events:[t],timestamp:new Date().toISOString()}]});break}case`team_detected`:{let e=t.teamName;e&&(B.current.teamNames.add(e),G.get(`/api/teams/${encodeURIComponent(e)}`).then(e=>{if(e?.messages){let t=B.current.messages,n=e.messages.filter(e=>!t.some(t=>t.timestamp===e.timestamp&&t.from===e.from));t.push(...n),t.sort((e,t)=>new Date(e.timestamp).getTime()-new Date(t.timestamp).getTime()),t.length>500&&t.splice(0,t.length-500)}K()}).catch(()=>{}),K());break}case`team_inbox`:{let e=t.messages;if(Array.isArray(e)){let t=B.current.messages;t.push(...e),t.length>500&&t.splice(0,t.length-500),te.current+=e.length,K()}break}case`team_updated`:K();break;case`bash_output`:{let e=t.toolUseId;if(e){let n=A.current.get(e);n?(n.content+=t.content,n.content.length>5e5&&(n.content=n.content.slice(-5e5)),n.lineCount=t.lineCount):A.current.set(e,{content:t.content,lineCount:t.lineCount}),X()}break}case`done`:{if(M.current===`idle`)break;t.contextWindowPct!=null&&v(t.contextWindowPct),L.current&&!Et(L.current)&&wt(`done`),z.current&&=(clearTimeout(z.current),0);let e=O.current,n=[...k.current],r=j.current,a=t.lastMessageUuid;i(t=>{let i=t[t.length-1];return i?.role===`assistant`?[...t.slice(0,-1),{...i,id:`final-${Date.now()}`,content:e||i.content,events:n.length>0?n:i.events,...a&&{sdkUuid:a}}]:e||n.length>0?[...t,{id:`final-${Date.now()}`,role:`assistant`,content:e,events:n,timestamp:new Date().toISOString(),...a&&{sdkUuid:a},...r}]:t}),O.current=``,k.current=[],j.current=null,A.current.clear(),S(null);break}}},[ae,X]),se=(0,Q.useCallback)(e=>{let t;try{t=JSON.parse(e.data)}catch{return}if(t.type!==`ping`){if(t.type===`file:changed`){window.dispatchEvent(new CustomEvent(`file:changed`,{detail:t}));return}if(t.type===`session:unread_changed`){let{sessionId:e,unreadCount:n,unreadType:r,projectName:i,sessionTitle:a}=t;je.getState().handleUnreadChanged(e,n,r,i,a);return}if(typeof t.type==`string`&&t.type.startsWith(`jira:`)){window.dispatchEvent(new CustomEvent(t.type,{detail:t}));return}if(t.type===`title_updated`){T(t.title??null);return}if(t.type===`compact_status`){let e=t.status;e===`compacting`?b(`compacting`):e===`done`&&b(null);return}if(t.type===`phase_changed`){let e=t.phase;u(e),M.current=e,m(e===`connecting`?t.elapsed??0:0),e===`idle`&&b(null);return}if(t.type===`session_state`){D(!0);let e=t,n=e.phase;u(n),M.current=n,e.sessionTitle&&T(e.sessionTitle),e.pendingApproval&&g({requestId:e.pendingApproval.requestId,tool:e.pendingApproval.tool,input:e.pendingApproval.input}),b(e.compactStatus===`compacting`?`compacting`:null),n===`idle`&&(F.current?.(),f(!1));return}if(t.type===`turn_events`){let e=t.events,n=t.userMessage;if(!e?.length&&!n){f(!1);return}i(e=>{let t=e,r=t[t.length-1];if(r?.role===`assistant`&&r.id.startsWith(`streaming-`)&&(t=t.slice(0,-1)),n){let e=t[t.length-1];(e?.role!==`user`||e.content!==n)&&(t=[...t,{id:`user-replay-${Date.now()}`,role:`user`,content:n,timestamp:new Date().toISOString()}])}return t}),O.current=``,k.current=[],j.current=null,I.current=!0;let r=0,a=()=>{let t=Math.min(r+100,e.length);for(let n=r;n<t;n++)oe(e[n]);r=t,r<e.length?requestAnimationFrame(a):(I.current=!1,f(!1))};requestAnimationFrame(a);return}oe(t)}},[oe]),{send:ce,connect:le}=pt({url:e&&n?`/ws/project/${encodeURIComponent(n)}/chat/${e}`:``,onMessage:se,autoConnect:!!e&&!!n});P.current=ce,(0,Q.useEffect)(()=>{let r=!1;return u(`idle`),M.current=`idle`,g(null),R.current!=null&&(C.dismiss(R.current),R.current=null),b(null),o(new Map),O.current=``,k.current=[],A.current.clear(),z.current&&=(clearTimeout(z.current),0),D(!1),B.current={teamNames:new Set,messages:[]},te.current=0,H(Tt),ne([]),e&&n?(c(!0),fetch(`${W(n)}/chat/sessions/${e}/messages?providerId=${t}`,{headers:{Authorization:`Bearer ${re()}`}}).then(e=>e.json()).then(e=>{r||M.current!==`idle`||(e.ok&&Array.isArray(e.data)&&e.data.length>0?i(e.data):i([]))}).catch(()=>{!r&&M.current===`idle`&&i([])}).finally(()=>{r||c(!1)})):i([]),()=>{r=!0}},[e,t,n]);let ue=(0,Q.useCallback)((e,t)=>{if(!e.trim())return;let n=M.current!==`idle`;if(n){z.current&&=(clearTimeout(z.current),0);let e=O.current,t=[...k.current];i(n=>{let r=n[n.length-1];return r?.role===`assistant`?[...n.slice(0,-1),{...r,id:`final-${Date.now()}`,content:e||r.content,events:t.length>0?t:r.events}]:n})}i(t=>[...t,{id:`user-${Date.now()}`,role:`user`,content:e,timestamp:new Date().toISOString()}]),O.current=``,k.current=[],N.current=null,n?(u(`thinking`),M.current=`thinking`):(u(`initializing`),M.current=`initializing`),g(null),R.current!=null&&(C.dismiss(R.current),R.current=null),ce(JSON.stringify({type:`message`,content:e,permissionMode:t?.permissionMode,priority:t?.priority,images:t?.images}))},[ce]),de=(0,Q.useCallback)((e,t,n)=>{if(ce(JSON.stringify({type:`approval_response`,requestId:e,approved:t,data:n})),t&&n){let t=k.current.find(t=>t.type===`approval_request`&&t.requestId===e&&t.tool===`AskUserQuestion`);if(t){let e=t.input;e&&typeof e==`object`&&(e.answers=n)}i(e=>[...e])}g(null),R.current!=null&&(C.dismiss(R.current),R.current=null)},[ce]),fe=(0,Q.useCallback)(()=>{if(M.current===`idle`)return;ce(JSON.stringify({type:`cancel`}));let e=O.current,t=[...k.current];i(n=>{let r=n[n.length-1];return r?.role===`assistant`?[...n.slice(0,-1),{...r,id:`final-${Date.now()}`,content:e||r.content,events:t.length>0?t:r.events}]:n}),O.current=``,k.current=[],A.current.clear(),N.current=null,u(`idle`),M.current=`idle`,g(null),R.current!=null&&(C.dismiss(R.current),R.current=null)},[ce]),pe=(0,Q.useCallback)(()=>{D(!1),f(!0),le()},[le]),me=(0,Q.useCallback)(()=>{!e||!n||fetch(`${W(n)}/chat/sessions/${e}/messages?providerId=${t}`,{headers:{Authorization:`Bearer ${re()}`}}).then(e=>e.json()).then(e=>{e.ok&&Array.isArray(e.data)&&e.data.length>0&&(i(e.data),O.current=``,k.current=[])}).catch(()=>{})},[e,t,n]);F.current=me;let he=(0,Q.useCallback)(async(e,t)=>{if(!n)throw Error(`No project context available`);let r=e.replace(/^pc-[^-]+-/,``),i=`${W(n)}/chat/pre-compact-messages?jsonlPath=${encodeURIComponent(t)}&before=${encodeURIComponent(r)}`,a=ht(await G.get(i),t);return o(t=>{let n=new Map(t);return n.set(e,a),n}),a.length},[n]),ge=(0,Q.useCallback)(e=>a.has(e),[a]);return{messages:r,renderedMessages:(0,Q.useMemo)(()=>gt(r,a),[r,a]),expandCompact:he,isCompactExpanded:ge,messagesLoading:s,isStreaming:q,phase:l,isReconnecting:d,connectingElapsed:p,pendingApproval:h,contextWindowPct:_,compactStatus:y,statusMessage:x,sessionTitle:w,teamActivity:V,teamMessages:U,markTeamRead:ie,bashPartialOutput:A,sendMessage:ue,respondToApproval:de,cancelStreaming:fe,reconnect:pe,refetchMessages:me,isConnected:E}}var Ot=12e4;function kt(e,t=`claude`){let[n,r]=(0,Q.useState)({}),[i,a]=(0,Q.useState)(!1),[o,s]=(0,Q.useState)(null),c=(0,Q.useRef)(null),l=(0,Q.useCallback)((n=!1)=>{if(!e)return;a(!0);let i=n?`&refresh=1`:``;fetch(`${W(e)}/chat/usage?providerId=${t}${i}`,{headers:{Authorization:`Bearer ${re()}`}}).then(e=>e.json()).then(e=>{e.ok&&e.data&&(r(t=>({...t,...e.data})),e.data.lastFetchedAt&&s(e.data.lastFetchedAt))}).catch(()=>{}).finally(()=>a(!1))},[e,t]);return(0,Q.useEffect)(()=>(l(),c.current=setInterval(()=>l(),Ot),()=>{c.current&&clearInterval(c.current)}),[l]),{usageInfo:n,usageLoading:i,lastFetchedAt:o,refreshUsage:(0,Q.useCallback)(()=>l(!0),[l])}}var At={damping:.7,stiffness:.05,mass:1.25},jt=70,Mt=1e3/60,Nt=350,Pt=!1;globalThis.document?.addEventListener(`mousedown`,()=>{Pt=!0}),globalThis.document?.addEventListener(`mouseup`,()=>{Pt=!1}),globalThis.document?.addEventListener(`click`,()=>{Pt=!1});var Ft=(e={})=>{let[t,n]=(0,Q.useState)(!1),[r,i]=(0,Q.useState)(e.initial!==!1),[a,o]=(0,Q.useState)(!1),s=(0,Q.useRef)(null);s.current=e;let c=(0,Q.useCallback)(()=>{if(!Pt)return!1;let e=window.getSelection();if(!e||!e.rangeCount)return!1;let t=e.getRangeAt(0);return t.commonAncestorContainer.contains(g.current)||g.current?.contains(t.commonAncestorContainer)},[]),l=(0,Q.useCallback)(e=>{d.isAtBottom=e,i(e)},[]),u=(0,Q.useCallback)(e=>{d.escapedFromLock=e,n(e)},[]),d=(0,Q.useMemo)(()=>{let n;return{escapedFromLock:t,isAtBottom:r,resizeDifference:0,accumulated:0,velocity:0,listeners:new Set,get scrollTop(){return g.current?.scrollTop??0},set scrollTop(e){g.current&&(g.current.scrollTop=e,d.ignoreScrollToTop=g.current.scrollTop)},get targetScrollTop(){return!g.current||!_.current?0:g.current.scrollHeight-1-g.current.clientHeight},get calculatedTargetScrollTop(){if(!g.current||!_.current)return 0;let{targetScrollTop:t}=this;if(!e.targetScrollTop)return t;if(n?.targetScrollTop===t)return n.calculatedScrollTop;let r=Math.max(Math.min(e.targetScrollTop(t,{scrollElement:g.current,contentElement:_.current}),t),0);return n={targetScrollTop:t,calculatedScrollTop:r},requestAnimationFrame(()=>{n=void 0}),r},get scrollDifference(){return this.calculatedTargetScrollTop-this.scrollTop},get isNearBottom(){return this.scrollDifference<=jt}}},[]),f=(0,Q.useCallback)((e={})=>{typeof e==`string`&&(e={animation:e}),e.preserveScrollPosition||l(!0);let t=Date.now()+(Number(e.wait)||0),n=Rt(s.current,e.animation),{ignoreEscapes:r=!1}=e,i,a=d.calculatedTargetScrollTop;e.duration instanceof Promise?e.duration.finally(()=>{i=Date.now()}):i=t+(e.duration??0);let o=async()=>{let e=new Promise(requestAnimationFrame).then(()=>{if(!d.isAtBottom)return d.animation=void 0,!1;let{scrollTop:l}=d,u=performance.now(),p=(u-(d.lastTick??u))/Mt;if(d.animation||={behavior:n,promise:e,ignoreEscapes:r},d.animation.behavior===n&&(d.lastTick=u),c()||t>Date.now())return o();if(l<Math.min(a,d.calculatedTargetScrollTop)){if(d.animation?.behavior===n){if(n===`instant`)return d.scrollTop=d.calculatedTargetScrollTop,o();d.velocity=(n.damping*d.velocity+n.stiffness*d.scrollDifference)/n.mass,d.accumulated+=d.velocity*p,d.scrollTop+=d.accumulated,d.scrollTop!==l&&(d.accumulated=0)}return o()}return i>Date.now()?(a=d.calculatedTargetScrollTop,o()):(d.animation=void 0,d.scrollTop<d.calculatedTargetScrollTop?f({animation:Rt(s.current,s.current.resize),ignoreEscapes:r,duration:Math.max(0,i-Date.now())||void 0}):d.isAtBottom)});return e.then(e=>(requestAnimationFrame(()=>{d.animation||(d.lastTick=void 0,d.velocity=0)}),e))};return e.wait!==!0&&(d.animation=void 0),d.animation?.behavior===n?d.animation.promise:o()},[l,c,d]),p=(0,Q.useCallback)(()=>{u(!0),l(!1)},[u,l]),m=(0,Q.useCallback)(({target:e})=>{if(e!==g.current)return;let{scrollTop:t,ignoreScrollToTop:n}=d,{lastScrollTop:r=t}=d;d.lastScrollTop=t,d.ignoreScrollToTop=void 0,n&&n>t&&(r=n),o(d.isNearBottom),setTimeout(()=>{if(d.resizeDifference||t===n)return;if(c()){u(!0),l(!1);return}let e=t>r,i=t<r;if(d.animation?.ignoreEscapes){d.scrollTop=r;return}i&&(u(!0),l(!1)),e&&u(!1),!d.escapedFromLock&&d.isNearBottom&&l(!0)},1)},[u,l,c,d]),h=(0,Q.useCallback)(({target:e,deltaY:t})=>{let n=e;for(;![`scroll`,`auto`].includes(getComputedStyle(n).overflow);){if(!n.parentElement)return;n=n.parentElement}n===g.current&&t<0&&g.current.scrollHeight>g.current.clientHeight&&!d.animation?.ignoreEscapes&&(u(!0),l(!1))},[u,l,d]),g=It(e=>{g.current?.removeEventListener(`scroll`,m),g.current?.removeEventListener(`wheel`,h),e?.addEventListener(`scroll`,m,{passive:!0}),e?.addEventListener(`wheel`,h,{passive:!0})},[]),_=It(e=>{if(d.resizeObserver?.disconnect(),!e)return;let t;d.resizeObserver=new ResizeObserver(([e])=>{let{height:n}=e.contentRect,r=n-(t??n);if(d.resizeDifference=r,d.scrollTop>d.targetScrollTop&&(d.scrollTop=d.targetScrollTop),o(d.isNearBottom),r>=0){let e=Rt(s.current,t?s.current.resize:s.current.initial);f({animation:e,wait:!0,preserveScrollPosition:!0,duration:e===`instant`?void 0:Nt})}else d.isNearBottom&&(u(!1),l(!0));t=n,requestAnimationFrame(()=>{setTimeout(()=>{d.resizeDifference===r&&(d.resizeDifference=0)},1)})}),d.resizeObserver?.observe(e)},[]);return{contentRef:_,scrollRef:g,scrollToBottom:f,stopScroll:p,isAtBottom:r||a,isNearBottom:a,escapedFromLock:t,state:d}};function It(e,t){let n=(0,Q.useCallback)(t=>(n.current=t,e(t)),t);return n}var Lt=new Map;function Rt(...e){let t={...At},n=!1;for(let r of e){if(r===`instant`){n=!0;continue}typeof r==`object`&&(n=!1,t.damping=r.damping??t.damping,t.stiffness=r.stiffness??t.stiffness,t.mass=r.mass??t.mass)}let r=JSON.stringify(t);return Lt.has(r)||Lt.set(r,Object.freeze(t)),n?`instant`:Lt.get(r)}var zt=(0,Q.createContext)(null),Bt=typeof window<`u`?Q.useLayoutEffect:Q.useEffect;function Vt({instance:e,children:t,resize:n,initial:r,mass:i,damping:a,stiffness:o,targetScrollTop:s,contextRef:c,...l}){let u=(0,Q.useRef)(null),d=Ft({mass:i,damping:a,stiffness:o,resize:n,initial:r,targetScrollTop:Q.useCallback((e,t)=>(y?.targetScrollTop??s)?.(e,t)??e,[s])}),{scrollRef:f,contentRef:p,scrollToBottom:m,stopScroll:h,isAtBottom:g,escapedFromLock:_,state:v}=e??d,y=(0,Q.useMemo)(()=>({scrollToBottom:m,stopScroll:h,scrollRef:f,isAtBottom:g,escapedFromLock:_,contentRef:p,state:v,get targetScrollTop(){return u.current},set targetScrollTop(e){u.current=e}}),[m,g,p,f,h,_,v]);return(0,Q.useImperativeHandle)(c,()=>y,[y]),Bt(()=>{f.current&&getComputedStyle(f.current).overflow===`visible`&&(f.current.style.overflow=`auto`)},[]),Q.createElement(zt.Provider,{value:y},Q.createElement(`div`,{...l},typeof t==`function`?t(y):t))}(function(e){function t({children:e,scrollClassName:t,...n}){let r=Ht();return Q.createElement(`div`,{ref:r.scrollRef,style:{height:`100%`,width:`100%`,scrollbarGutter:`stable both-edges`},className:t},Q.createElement(`div`,{...n,ref:r.contentRef},typeof e==`function`?e(r):e))}e.Content=t})(Vt||={});function Ht(){let e=(0,Q.useContext)(zt);if(!e)throw Error(`use-stick-to-bottom component context must be used within a StickToBottom component`);return e}var $=t(),Ut=(0,Q.lazy)(()=>ie(()=>import(`./markdown-renderer-Bv_VAy7V.js`).then(e=>({default:e.MarkdownRenderer})),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23])));function Wt(e){let t=e.type===`approval_request`;return{toolName:e.type===`tool_use`?e.tool:t?e.tool??`Tool`:`Tool`,input:e.type===`tool_use`?e.input:t?e.input??{}:{}}}function Gt({tool:e,result:t,completed:n,projectName:r,bashPartialOutput:i}){let[a,o]=(0,Q.useState)(!1);if(e.type===`error`)return(0,$.jsxs)(`div`,{className:`flex items-center gap-2 rounded bg-red-500/10 border border-red-500/20 px-2 py-1.5 text-xs text-red-400`,children:[(0,$.jsx)(Ue,{className:`size-3`}),(0,$.jsx)(`span`,{children:e.message})]});let{toolName:s,input:c}=Wt(e),l=t?.type===`tool_result`,u=l&&!!t.isError,d=s===`AskUserQuestion`&&!!c?.answers,f=e.type===`approval_request`&&e.approved!=null,p=(s===`Agent`||s===`Task`)&&e.type===`tool_use`,h=p?e.children:void 0,g=h&&h.length>0,_=l||d||f||n,v=e.type===`tool_use`?e.toolUseId:void 0,y=s===`Bash`&&!l&&v?i?.current?.get(v):void 0,b=!!y;return(0,Q.useEffect)(()=>{b&&!a&&o(!0)},[b]),(0,$.jsxs)(`div`,{className:`rounded border text-xs ${p?`border-accent/30 bg-accent/5`:`border-border bg-background`}`,children:[(0,$.jsxs)(`button`,{onClick:()=>o(!a),className:`flex items-center gap-2 px-2 py-1.5 w-full text-left hover:bg-surface transition-colors min-w-0`,children:[a?(0,$.jsx)(m,{className:`size-3 shrink-0`}):(0,$.jsx)(T,{className:`size-3 shrink-0`}),u?(0,$.jsx)(Ye,{className:`size-3 text-red-400 shrink-0`}):_?(0,$.jsx)(Be,{className:`size-3 text-green-400 shrink-0`}):(0,$.jsx)(Z,{className:`size-3 text-yellow-400 shrink-0 animate-spin`}),(0,$.jsx)(`span`,{className:`truncate text-text-primary`,children:(0,$.jsx)(Kt,{name:s,input:c})}),b&&(0,$.jsxs)(`span`,{className:`ml-auto text-[10px] text-yellow-400 shrink-0`,children:[y.lineCount,` line`,y.lineCount===1?``:`s`,` streaming...`]}),g&&!b&&(0,$.jsxs)(`span`,{className:`ml-auto text-[10px] text-text-subtle shrink-0`,children:[h.length,` steps`]})]}),a&&(0,$.jsxs)(`div`,{className:`px-2 pb-2 space-y-1.5 select-text`,children:[(e.type===`tool_use`||e.type===`approval_request`)&&(0,$.jsx)(qt,{name:s,input:c,projectName:r}),y&&(0,$.jsx)($t,{content:y.content,lineCount:y.lineCount}),g&&(0,$.jsx)(Zt,{events:h,projectName:r}),l&&(0,$.jsx)(Yt,{toolName:s,output:t.output})]})]})}function Kt({name:e,input:t}){let n=e=>String(e??``);switch(e){case`Read`:case`Write`:case`Edit`:case`MultiEdit`:case`NotebookEdit`:return(0,$.jsxs)($.Fragment,{children:[e,` `,(0,$.jsx)(`span`,{className:`text-text-subtle`,children:J(n(t.file_path))})]});case`Bash`:{let r=t.description?n(t.description):n(t.command);return(0,$.jsxs)($.Fragment,{children:[e,` `,(0,$.jsx)(`span`,{className:`text-text-subtle${t.description?``:` font-mono`}`,children:en(r,60)})]})}case`Glob`:return(0,$.jsxs)($.Fragment,{children:[e,` `,(0,$.jsx)(`span`,{className:`font-mono text-text-subtle`,children:n(t.pattern)})]});case`Grep`:return(0,$.jsxs)($.Fragment,{children:[e,` `,(0,$.jsx)(`span`,{className:`font-mono text-text-subtle`,children:en(n(t.pattern),40)})]});case`WebSearch`:return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(R,{className:`size-3 inline`}),` `,e,` `,(0,$.jsx)(`span`,{className:`text-text-subtle`,children:en(n(t.query),50)})]});case`WebFetch`:return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(w,{className:`size-3 inline`}),` `,e,` `,(0,$.jsx)(`span`,{className:`text-text-subtle`,children:en(n(t.url),50)})]});case`ToolSearch`:return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(R,{className:`size-3 inline`}),` `,e,` `,(0,$.jsx)(`span`,{className:`text-text-subtle`,children:en(n(t.query),50)})]});case`Agent`:case`Task`:return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(u,{className:`size-3 inline`}),` `,e,` `,(0,$.jsx)(`span`,{className:`text-text-subtle`,children:en(n(t.description||t.prompt),60)})]});case`TodoWrite`:{let n=Array.isArray(t.todos)?t.todos:[],r=n.filter(e=>e.status===`completed`).length;return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(nt,{className:`size-3 inline`}),` `,e,` `,(0,$.jsxs)(`span`,{className:`text-text-subtle`,children:[r,`/`,n.length,` done`]})]})}case`AskUserQuestion`:{let n=Array.isArray(t.questions)?t.questions:[],r=!!t.answers;return(0,$.jsxs)($.Fragment,{children:[e,` `,(0,$.jsxs)(`span`,{className:`text-text-subtle`,children:[n.length,` question`,n.length===1?``:`s`,r?` ✓`:``]})]})}default:return(0,$.jsx)($.Fragment,{children:e})}}function qt({name:e,input:t,projectName:n}){let r=e=>String(e??``),{openTab:i}=X(Le(e=>({openTab:e.openTab}))),a=e=>{n&&i({type:`editor`,title:J(e),metadata:{filePath:e,projectName:n},projectId:n,closable:!0})},o=(e,t,r)=>{i({type:`git-diff`,title:`Diff ${J(e)}`,metadata:{filePath:e,projectName:n,original:t,modified:r},projectId:n??null,closable:!0})};switch(e){case`Bash`:return(0,$.jsxs)(`div`,{className:`space-y-1`,children:[!!t.description&&(0,$.jsx)(`p`,{className:`text-text-subtle italic`,children:r(t.description)}),(0,$.jsx)(`pre`,{className:`font-mono text-text-secondary overflow-x-auto whitespace-pre-wrap break-all`,children:r(t.command)})]});case`Read`:case`Write`:case`Edit`:case`MultiEdit`:case`NotebookEdit`:{let n=r(t.file_path);return(0,$.jsxs)(`div`,{className:`space-y-1`,children:[(0,$.jsxs)(`button`,{type:`button`,className:`font-mono text-text-secondary break-all hover:text-primary hover:underline text-left flex items-center gap-1`,onClick:()=>a(n),title:`Open file in editor`,children:[(0,$.jsx)(xe,{className:`size-3 shrink-0`}),n]}),e===`Edit`&&(!!t.old_string||!!t.new_string)&&(0,$.jsxs)(`button`,{type:`button`,className:`text-text-subtle hover:text-primary hover:underline text-left flex items-center gap-1`,onClick:()=>o(n,r(t.old_string),r(t.new_string)),title:`View diff in new tab`,children:[(0,$.jsx)(I,{className:`size-3 shrink-0`}),`View Diff`]}),e===`Write`&&!!t.content&&(0,$.jsx)(`pre`,{className:`font-mono text-text-subtle overflow-x-auto max-h-32 whitespace-pre-wrap`,children:en(r(t.content),300)})]})}case`Glob`:return(0,$.jsxs)(`p`,{className:`font-mono text-text-secondary`,children:[r(t.pattern),t.path?` in ${r(t.path)}`:``]});case`Grep`:return(0,$.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,$.jsxs)(`p`,{className:`font-mono text-text-secondary`,children:[`/`,r(t.pattern),`/`]}),!!t.path&&(0,$.jsxs)(`p`,{className:`text-text-subtle`,children:[`in `,r(t.path)]})]});case`TodoWrite`:return(0,$.jsx)(Jt,{todos:t.todos??[]});case`Agent`:case`Task`:return(0,$.jsxs)(`div`,{className:`space-y-1`,children:[!!t.description&&(0,$.jsx)(`p`,{className:`text-text-secondary font-medium`,children:r(t.description)}),!!t.subagent_type&&(0,$.jsxs)(`p`,{className:`text-text-subtle`,children:[`Type: `,r(t.subagent_type)]}),!!t.prompt&&(0,$.jsx)(Qt,{content:r(t.prompt),maxHeight:`max-h-48`})]});case`ToolSearch`:return(0,$.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,$.jsx)(`p`,{className:`font-mono text-text-secondary`,children:r(t.query)}),!!t.max_results&&(0,$.jsxs)(`p`,{className:`text-text-subtle`,children:[`Max results: `,r(t.max_results)]})]});case`WebFetch`:return(0,$.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,$.jsxs)(`a`,{href:r(t.url),target:`_blank`,rel:`noopener noreferrer`,className:`font-mono text-primary hover:underline break-all flex items-center gap-1`,children:[(0,$.jsx)(w,{className:`size-3 shrink-0`}),r(t.url)]}),!!t.prompt&&(0,$.jsx)(`p`,{className:`text-text-subtle`,children:en(r(t.prompt),100)})]});case`AskUserQuestion`:{let e=t.questions??[],n=t.answers??{};return(0,$.jsx)(`div`,{className:`space-y-2`,children:e.map((e,t)=>(0,$.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,$.jsxs)(`p`,{className:`text-text-primary font-medium`,children:[e.header?`${e.header}: `:``,e.question]}),(0,$.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:e.options.map((t,r)=>(0,$.jsx)(`span`,{className:`inline-block rounded px-1.5 py-0.5 text-xs border ${(n[e.question]??``).split(`, `).includes(t.label)?`border-accent bg-accent/20 text-text-primary`:`border-border text-text-subtle`}`,children:t.label},r))}),n[e.question]&&(0,$.jsxs)(`p`,{className:`text-foreground text-xs`,children:[`Answer: `,n[e.question]]})]},t))})}default:return(0,$.jsx)(`pre`,{className:`overflow-x-auto text-text-secondary font-mono whitespace-pre-wrap break-all`,children:JSON.stringify(t,null,2)})}}function Jt({todos:e}){return(0,$.jsx)(`div`,{className:`space-y-0.5`,children:e.map((e,t)=>(0,$.jsxs)(`div`,{className:`flex items-start gap-1.5`,children:[(0,$.jsx)(`span`,{className:`shrink-0 mt-0.5 ${e.status===`completed`?`text-green-400`:e.status===`in_progress`?`text-yellow-400`:`text-text-subtle`}`,children:e.status===`completed`?`✓`:e.status===`in_progress`?`▶`:`○`}),(0,$.jsx)(`span`,{className:e.status===`completed`?`line-through text-text-subtle`:`text-text-secondary`,children:e.content})]},t))})}function Yt({toolName:e,output:t}){let[n,r]=(0,Q.useState)(!1),i=(0,Q.useMemo)(()=>{if(e!==`Agent`&&e!==`Task`)return null;try{let e=JSON.parse(t);if(Array.isArray(e)){let t=e.filter(e=>e.type===`text`&&e.text).map(e=>e.text).join(`
3
3
 
4
4
  `);if(t)return t}if(typeof e==`string`)return e}catch{if(t&&!t.startsWith(`[{`))return t}return null},[e,t]);return i?(0,$.jsxs)(`div`,{className:`border-t border-border pt-1.5 space-y-1`,children:[(0,$.jsx)(Qt,{content:i,maxHeight:`max-h-60`}),(0,$.jsxs)(`button`,{type:`button`,onClick:()=>r(!n),className:`flex items-center gap-1 text-[10px] text-text-subtle hover:text-text-secondary transition-colors`,children:[(0,$.jsx)(F,{className:`size-3`}),n?`Hide`:`Show`,` raw`]}),n&&(0,$.jsx)(`pre`,{className:`overflow-x-auto text-text-subtle font-mono max-h-40 whitespace-pre-wrap break-all text-[10px]`,children:t})]}):(0,$.jsx)(Xt,{output:t})}function Xt({output:e}){let t=e.split(`
5
5
  `).length,n=t>3||e.length>200,[r,i]=(0,Q.useState)(n);return(0,$.jsxs)(`div`,{className:`border-t border-border pt-1.5`,children:[n&&(0,$.jsxs)(`button`,{type:`button`,onClick:()=>i(!r),className:`flex items-center gap-1 text-[10px] text-text-subtle hover:text-text-secondary transition-colors mb-1`,children:[r?(0,$.jsx)(T,{className:`size-3`}):(0,$.jsx)(m,{className:`size-3`}),`Output (`,t,` lines)`]}),(0,$.jsx)(`pre`,{className:`overflow-x-auto text-text-subtle font-mono whitespace-pre-wrap break-all ${r?`max-h-16 overflow-hidden`:`max-h-60`}`,children:e})]})}function Zt({events:e,projectName:t}){let n=[],r=``;for(let t of e)if(t.type===`text`)r+=t.content;else if(t.type===`tool_use`)r&&=(n.push({kind:`text`,content:r}),``),n.push({kind:`tool`,tool:t});else if(t.type===`tool_result`){let e=t.toolUseId,r=e?n.find(t=>t.kind===`tool`&&t.tool.type===`tool_use`&&t.tool.toolUseId===e&&!t.result):n.findLast(e=>e.kind===`tool`&&!e.result);r&&(r.result=t)}return r&&n.push({kind:`text`,content:r}),(0,$.jsx)(`div`,{className:`border-l-2 border-accent/20 pl-2 space-y-1 mt-1`,children:n.map((e,n)=>e.kind===`text`?(0,$.jsx)(`div`,{className:`text-text-secondary text-[11px]`,children:(0,$.jsx)(Qt,{content:e.content,maxHeight:`max-h-24`})},`st-${n}`):(0,$.jsx)(Gt,{tool:e.tool,result:e.result,completed:!!e.result,projectName:t},`sc-${n}`))})}function Qt({content:e,maxHeight:t=`max-h-48`}){return(0,$.jsx)(Q.Suspense,{fallback:(0,$.jsx)(`div`,{className:`animate-pulse h-4 bg-muted rounded`}),children:(0,$.jsx)(Ut,{content:e,className:`text-text-secondary overflow-auto ${t}`})})}function $t({content:e,lineCount:t}){let n=(0,Q.useRef)(null),r=(0,Q.useRef)(!1);return(0,Q.useEffect)(()=>{n.current&&!r.current&&(n.current.scrollTop=n.current.scrollHeight)},[e]),(0,$.jsxs)(`div`,{className:`border-t border-border pt-1.5`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-1 text-[10px] text-yellow-400 mb-1`,children:[(0,$.jsx)(Z,{className:`size-3 animate-spin`}),(0,$.jsxs)(`span`,{children:[`Output (`,t,` line`,t===1?``:`s`,`, streaming...)`]})]}),(0,$.jsx)(`pre`,{ref:n,onScroll:e=>{let t=e.currentTarget;r.current=t.scrollTop+t.clientHeight<t.scrollHeight-20},className:`overflow-x-auto overflow-y-auto max-h-60 text-text-subtle font-mono whitespace-pre-wrap break-all text-[11px]`,children:e.split(`
6
6
  `).slice(-200).join(`
7
- `)})]})}function en(e,t=50){return e?e.length>t?e.slice(0,t)+`…`:e:``}var tn=/read the full transcript at:\s*(\S+\.jsonl)/i;function nn(e){return e.match(tn)?.[1]?.trim()??null}var rn=class extends Q.Component{state={hasError:!1};static getDerivedStateFromError(){return{hasError:!0}}render(){return this.state.hasError?this.props.fallback?this.props.fallback:this.props.fallbackContent?(0,$.jsx)(`div`,{className:`text-sm whitespace-pre-wrap break-words text-text-primary opacity-80`,children:this.props.fallbackContent}):null:this.props.children}};function an({projectName:e,onSelectSession:t}){return(0,$.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full gap-6 text-text-secondary overflow-y-auto`,children:[(0,$.jsxs)(`div`,{className:`flex flex-col items-center gap-3`,children:[(0,$.jsx)(u,{className:`size-10 text-text-subtle`}),(0,$.jsx)(`p`,{className:`text-sm`,children:`Send a message to start a new conversation`})]}),(0,$.jsx)(ze,{projectName:e,onSelectSession:t,className:`w-full px-4`})]})}function on(e){let[t,n]=(0,Q.useState)({}),[r,i]=(0,Q.useState)({}),[a,o]=(0,Q.useState)(0),s=(0,Q.useCallback)((e,t)=>{n(n=>({...n,[e]:[t]})),i(t=>({...t,[e]:``}))},[]),c=(0,Q.useCallback)((e,t)=>{n(n=>{let r=n[e]||[];return{...n,[e]:r.includes(t)?r.filter(e=>e!==t):[...r,t]}})},[]),l=(0,Q.useCallback)((e,t)=>{i(n=>({...n,[e]:t})),t&&n(t=>({...t,[e]:[]}))},[]),u=(0,Q.useCallback)(e=>(t[e]?.length??0)>0||(r[e]?.trim().length??0)>0,[t,r]);return{answers:t,customInputs:r,activeTab:a,setActiveTab:o,handleSingleSelect:s,handleMultiSelect:c,handleCustomInput:l,hasAnswer:u,allAnswered:(0,Q.useMemo)(()=>e.every((e,t)=>u(t)),[e,u]),getFinalAnswer:(0,Q.useCallback)(e=>r[e]?.trim()||(t[e]??[]).join(`, `),[t,r]),goToNextTab:(0,Q.useCallback)(()=>o(t=>Math.min(t+1,e.length-1)),[e.length]),goToPrevTab:(0,Q.useCallback)(()=>o(e=>Math.max(e-1,0)),[])}}function sn(e){let[t,n]=(0,Q.useState)(0),r=(0,Q.useRef)(null);return(0,Q.useEffect)(()=>n(0),[e.activeTab]),(0,Q.useEffect)(()=>{if(!e.enabled)return;let i=r=>{let i=document.activeElement===e.customInputRef.current;if(!i&&r.key>=`1`&&r.key<=`9`){r.preventDefault();let t=parseInt(r.key)-1;t<e.totalOptions-1&&(n(t),e.onSelectOption(t));return}if(!i&&(r.key===`o`||r.key===`O`||r.key===`0`)){r.preventDefault(),e.customInputRef.current?.focus(),n(e.totalOptions-1);return}if(r.key===`Tab`&&e.questions.length>1){r.preventDefault(),r.shiftKey?e.goToPrevTab():e.goToNextTab();return}if(!i){if(r.key===`ArrowLeft`){r.preventDefault(),e.goToPrevTab();return}if(r.key===`ArrowRight`){r.preventDefault(),e.goToNextTab();return}if(r.key===`ArrowUp`){r.preventDefault(),n(e=>Math.max(0,e-1));return}if(r.key===`ArrowDown`){r.preventDefault(),n(t=>Math.min(e.totalOptions-1,t+1));return}if(r.key===` `){r.preventDefault(),e.onSelectOption(t);return}}if(r.key===`Enter`){r.preventDefault(),e.allAnswered?e.onSubmit():e.hasAnswer(e.activeTab)&&e.goToNextTab();return}r.key===`Escape`&&i&&e.customInputRef.current?.blur()},a=r.current;return a&&(a.addEventListener(`keydown`,i),a.setAttribute(`tabindex`,`0`),a.contains(document.activeElement)||a.focus()),()=>{a?.removeEventListener(`keydown`,i)}},[e,t]),{focusedOption:t,setFocusedOption:n,containerRef:r}}function cn({questions:e,onSubmit:t,onSkip:n}){let r=(0,Q.useRef)(null),i=on(e),a=e[i.activeTab],o=a?a.options.length+1:0,s=e.length>1,c=(0,Q.useCallback)(()=>{if(!i.allAnswered)return;let n={};e.forEach((e,t)=>{n[e.question]=i.getFinalAnswer(t)}),t(n)},[i.allAnswered,i.getFinalAnswer,e,t]),l=(0,Q.useCallback)(e=>{if(!(!a||e<0))if(e<a.options.length){let t=a.options[e]?.label;if(!t)return;a.multiSelect?i.handleMultiSelect(i.activeTab,t):i.handleSingleSelect(i.activeTab,t)}else e===a.options.length&&r.current?.focus()},[a,i]),u=sn({questions:e,activeTab:i.activeTab,totalOptions:o,allAnswered:i.allAnswered,hasAnswer:i.hasAnswer,onSelectOption:l,goToNextTab:i.goToNextTab,goToPrevTab:i.goToPrevTab,onSubmit:c,customInputRef:r,enabled:!0}),d=(0,Q.useCallback)(e=>{l(e),u.setFocusedOption(e)},[l,u.setFocusedOption]);return(0,$.jsxs)(`div`,{ref:u.containerRef,className:`rounded-lg border-2 border-primary/30 bg-primary/5 p-3 space-y-3 outline-none animate-in slide-in-from-bottom-2`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between text-sm font-medium text-text-primary`,children:[(0,$.jsxs)(`span`,{children:[`AI has `,s?`${e.length} questions`:`a question`]}),(0,$.jsxs)(`span`,{className:`text-[10px] text-text-secondary font-normal`,children:[s?`←→ tabs · `:``,`↑↓ options · 1-`,Math.min(o-1,9),` select · Enter submit`]})]}),s&&(0,$.jsx)(`div`,{className:`flex gap-1 p-1 bg-background rounded-md overflow-x-auto border border-border`,children:e.map((e,t)=>(0,$.jsxs)(`button`,{className:`flex items-center gap-1.5 px-3 py-1.5 rounded text-xs whitespace-nowrap transition-all ${i.activeTab===t?`bg-primary text-primary-foreground`:i.hasAnswer(t)?`text-primary bg-transparent`:`text-text-secondary hover:bg-surface-elevated`}`,onClick:()=>{i.setActiveTab(t),u.setFocusedOption(0)},tabIndex:-1,children:[(0,$.jsx)(`span`,{className:`flex items-center justify-center w-4 h-4 rounded-full text-[10px] font-semibold ${i.activeTab===t?`bg-white/20`:i.hasAnswer(t)?`bg-primary/20 text-primary`:`bg-surface-elevated text-text-secondary`}`,children:i.hasAnswer(t)?`✓`:t+1}),(0,$.jsx)(`span`,{className:`max-w-[100px] overflow-hidden text-ellipsis`,children:e.header||`Q${t+1}`})]},t))}),a&&(0,$.jsxs)(`div`,{className:`space-y-2`,children:[!s&&a.header&&(0,$.jsx)(`div`,{className:`text-[11px] font-semibold uppercase tracking-wide text-text-secondary`,children:a.header}),(0,$.jsx)(`div`,{className:`text-sm text-text-primary`,children:a.question}),a.multiSelect&&(0,$.jsx)(`div`,{className:`text-[11px] text-text-secondary`,children:`Select multiple`}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[a.options.map((e,t)=>{let n=(i.answers[i.activeTab]||[]).includes(e.label),r=u.focusedOption===t;return(0,$.jsxs)(`button`,{onClick:()=>d(t),className:`text-left flex items-start gap-2.5 rounded px-2.5 py-2 text-xs border transition-all ${n?`border-primary bg-primary/10 text-text-primary`:`border-border bg-background text-text-secondary hover:border-primary/40 hover:bg-primary/5`} ${r?`ring-2 ring-primary/40 ring-offset-1 ring-offset-background`:``}`,children:[(0,$.jsx)(`span`,{className:`flex items-center justify-center w-4.5 h-4.5 rounded text-[10px] font-semibold shrink-0 mt-px ${n?`bg-primary/20 text-primary`:`bg-surface-elevated text-text-secondary`}`,children:t+1}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-0.5 flex-1`,children:[(0,$.jsx)(`span`,{className:`font-medium text-text-primary`,children:e.label}),e.description&&(0,$.jsx)(`span`,{className:`text-[11px] text-text-secondary`,children:e.description})]})]},t)}),(0,$.jsxs)(`div`,{className:`flex items-start gap-2.5 rounded px-2.5 py-2 text-xs border border-dashed transition-all border-border bg-transparent ${u.focusedOption===o-1?`ring-2 ring-primary/40 ring-offset-1 ring-offset-background`:``}`,children:[(0,$.jsx)(`span`,{className:`flex items-center justify-center w-4.5 h-4.5 rounded bg-surface-elevated text-text-secondary text-[10px] font-semibold shrink-0 mt-px`,children:`O`}),(0,$.jsx)(`input`,{ref:r,type:`text`,className:`flex-1 px-2 py-1 text-xs bg-surface border border-border rounded text-text-primary outline-none placeholder:text-text-subtle focus:border-primary`,placeholder:`Other (press O to type)...`,value:i.customInputs[i.activeTab]||``,onChange:e=>i.handleCustomInput(i.activeTab,e.target.value),onFocus:()=>u.setFocusedOption(o-1)})]})]})]}),(0,$.jsxs)(`div`,{className:`flex gap-2 justify-end pt-1`,children:[s&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`button`,{className:`px-3 py-1.5 text-xs rounded border border-border bg-background text-text-primary hover:bg-surface-elevated disabled:opacity-40 disabled:cursor-not-allowed transition-colors`,onClick:i.goToPrevTab,disabled:i.activeTab===0,tabIndex:-1,children:`← Prev`}),(0,$.jsx)(`button`,{className:`px-3 py-1.5 text-xs rounded border border-border bg-background text-text-primary hover:bg-surface-elevated disabled:opacity-40 disabled:cursor-not-allowed transition-colors`,onClick:i.goToNextTab,disabled:i.activeTab===e.length-1,tabIndex:-1,children:`Next →`})]}),(0,$.jsx)(`button`,{onClick:n,className:`px-4 py-1.5 rounded border border-border bg-background text-text-secondary text-xs hover:bg-surface-elevated transition-colors`,tabIndex:-1,children:`Skip`}),(0,$.jsxs)(`button`,{onClick:c,disabled:!i.allAnswered,className:`px-4 py-1.5 rounded bg-primary text-primary-foreground text-xs font-medium hover:bg-primary/80 transition-colors disabled:opacity-40 disabled:cursor-not-allowed`,tabIndex:-1,children:[`Submit `,i.allAnswered?`✓`:`(${e.filter((e,t)=>i.hasAnswer(t)).length}/${e.length})`]})]})]})}var ln=(0,Q.lazy)(()=>ie(()=>import(`./markdown-renderer-C_5GH1wX.js`).then(e=>({default:e.MarkdownRenderer})),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23])));function un({messages:e,messagesLoading:t,pendingApproval:n,onApprovalResponse:r,isStreaming:i,phase:a,onSelectSession:o,connectingElapsed:s,statusMessage:c,compactStatus:l,projectName:d,onFork:f,bashPartialOutput:p,onExpandCompact:m,isCompactExpanded:h}){let[g,_]=(0,Q.useState)(50),v=e[0]?.id;(0,Q.useEffect)(()=>{_(50)},[v]);let y=(0,Q.useMemo)(()=>e.filter(e=>{let t=e.content&&e.content.trim().length>0,n=e.events&&e.events.length>0;return e.role===`user`?t:t||n}),[e]),b=(0,Q.useMemo)(()=>{let e=Math.max(0,y.length-g);return y.slice(e)},[y,g]),x=g<y.length,S=(0,Q.useCallback)((e,t)=>{f?.(e,t)},[f]),C=(0,Q.useRef)(null),w=(0,Q.useCallback)(()=>{if(!m||!h)return null;for(let e of b){if(h(e.id))continue;let t=nn(e.content||``);if(t)return{id:e.id,jsonlPath:t};if(e.events){for(let t of e.events)if(t.type===`text`){let n=nn(t.content||``);if(n)return{id:e.id,jsonlPath:n}}}}return null},[b,m,h]),[T,E]=(0,Q.useState)(!1),D=(0,Q.useCallback)(async()=>{if(x){C.current?.capture(),_(e=>e+50),requestAnimationFrame(()=>requestAnimationFrame(()=>C.current?.restore()));return}let e=w();if(!(!e||!m||T)){E(!0);try{C.current?.capture();let t=await m(e.id,e.jsonlPath);_(e=>e+t),requestAnimationFrame(()=>requestAnimationFrame(()=>C.current?.restore()))}finally{E(!1)}}},[x,w,m,T]),O=x||!!w();return t?(0,$.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full gap-3 text-text-secondary`,children:[(0,$.jsx)(u,{className:`size-10 text-text-subtle animate-pulse`}),(0,$.jsx)(`p`,{className:`text-sm`,children:`Loading messages...`})]}):e.length===0&&!i?(0,$.jsx)(an,{projectName:d||``,onSelectSession:o||(()=>{})}):(0,$.jsx)(`div`,{className:`relative flex-1 overflow-hidden flex flex-col min-h-0`,children:(0,$.jsxs)(Vt,{className:`flex-1 overflow-y-auto overflow-x-hidden [contain:strict] [overflow-anchor:auto]`,resize:`smooth`,initial:`instant`,children:[(0,$.jsxs)(Vt.Content,{className:`p-4 space-y-4 select-none [&>*]:[overflow-anchor:auto]`,children:[(0,$.jsx)(dn,{bridgeRef:C}),O&&(0,$.jsx)(pn,{onLoadMore:D,loading:T}),b.map((e,t)=>{let n=y.length-b.length+t,r=n>0?y[n-1]:void 0;return(0,$.jsx)(rn,{fallbackContent:e.content,children:(0,$.jsx)(mn,{message:e,isStreaming:i&&e.id.startsWith(`streaming-`),projectName:d,onFork:e.role===`user`&&f?S:void 0,prevMsgId:r?.sdkUuid??r?.id,bashPartialOutput:p})},e.id)}),n&&(n.tool===`AskUserQuestion`?(0,$.jsx)(Vn,{approval:n,onRespond:r}):(0,$.jsx)(Bn,{approval:n,onRespond:r})),i&&(0,$.jsx)(In,{lastMessage:e[e.length-1],phase:a,elapsed:s,statusMessage:l===`compacting`?`Compacting messages...`:c})]}),(0,$.jsx)(fn,{})]})})}function dn({bridgeRef:e}){let{scrollRef:t,isAtBottom:n}=Ht(),r=(0,Q.useRef)(null);return(0,Q.useEffect)(()=>(e.current={capture:()=>{let e=t.current;if(!e||n){r.current=null;return}r.current={top:e.scrollTop,height:e.scrollHeight}},restore:()=>{let e=t.current,n=r.current;if(!e||!n)return;let i=e.scrollHeight-n.height;i!==0&&(e.scrollTop=n.top+i),r.current=null}},()=>{e.current=null}),[e,t,n]),null}function fn(){let{isAtBottom:e,scrollToBottom:t}=Ht();return e?null:(0,$.jsxs)(`button`,{onClick:()=>t(),className:`absolute bottom-4 left-1/2 -translate-x-1/2 z-10 flex items-center gap-1 px-3 py-1 rounded-full bg-surface-elevated border border-border text-xs text-text-secondary hover:text-foreground shadow-lg transition-all`,children:[(0,$.jsx)(m,{className:`size-3`}),`Scroll to bottom`]})}function pn({onLoadMore:e,loading:t}){let n=(0,Q.useRef)(null),r=(0,Q.useRef)(e);return r.current=e,(0,Q.useEffect)(()=>{let e=n.current;if(!e)return;let t=new IntersectionObserver(([e])=>{e?.isIntersecting&&r.current()},{rootMargin:`200px 0px 0px 0px`});return t.observe(e),()=>t.disconnect()},[]),(0,$.jsx)(`div`,{ref:n,className:`flex items-center justify-center py-2 text-xs text-text-secondary`,children:t&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Z,{className:`size-3 animate-spin mr-1.5`}),`Loading previous conversation...`]})})}var mn=(0,Q.memo)(function({message:e,isStreaming:t,projectName:n,onFork:r,prevMsgId:i,bashPartialOutput:a}){if(e.role===`user`){let t=r?()=>r(e.content,i):void 0;return(0,$.jsx)(wn,{content:e.content,messageId:e.id,projectName:n,onFork:t})}return e.role===`system`?(0,$.jsxs)(`div`,{className:`flex items-center gap-2 rounded-lg bg-red-500/10 border border-red-500/20 px-3 py-2 text-sm text-red-400`,children:[(0,$.jsx)(Ue,{className:`size-4 shrink-0`}),(0,$.jsx)(`p`,{children:e.content})]}):(0,$.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[e.events&&e.events.length>0?(0,$.jsx)(Nn,{events:e.events,isStreaming:t,projectName:n,bashPartialOutput:a}):e.content&&(0,$.jsx)(`div`,{className:`text-sm text-text-primary select-text`,children:(0,$.jsx)(zn,{content:e.content,projectName:n})}),e.accountLabel&&(0,$.jsxs)(`p`,{className:`text-[10px] select-none`,style:{color:`var(--color-text-subtle)`},children:[`via `,e.accountLabel]})]})}),hn=new Set([`.png`,`.jpg`,`.jpeg`,`.gif`,`.webp`]),gn={"system-reminder":`Context`,claudeMd:`CLAUDE.md`,gitStatus:`Git Status`,currentDate:`Date`,fast_mode_info:`Fast Mode`,"available-deferred-tools":`Tools`,"task-notification":`Task Result`,environment_details:`Environment`};function _n(e){let t=[],n=/<(system-reminder|available-deferred-tools|antml:[\w-]+|fast_mode_info|claudeMd|gitStatus|currentDate|task-notification|environment_details)[^>]*>([\s\S]*?)<\/\1>/g,r;for(;(r=n.exec(e))!==null;){let e=r[1];t.push({name:e,label:gn[e]??e.replace(/^antml:/,``).replace(/-/g,` `),content:r[2].trim()})}return{cleanText:e.replace(n,``).trim(),tags:t}}var vn=/<command-message>[\s\S]*?<\/command-message>\s*<command-name>([\s\S]*?)<\/command-name>(?:\s*<command-args>([\s\S]*?)<\/command-args>)?/;function yn(e){let t=e.match(vn);if(!t)return{command:null,cleanText:e};let n=t[1].trim(),r=t[2]?.trim()||void 0,i=e.replace(vn,``).trim();return{command:{name:n,args:r},cleanText:i}}function bn(e){let t=e.match(/^\[Attached file: (.+?)\]\n\n?/);if(t)return{files:[t[1]],text:e.slice(t[0].length)};let n=e.match(/^\[Attached files:\n([\s\S]+?)\]\n\n?/);return n?{files:n[1].split(`
7
+ `)})]})}function en(e,t=50){return e?e.length>t?e.slice(0,t)+`…`:e:``}var tn=/read the full transcript at:\s*(\S+\.jsonl)/i;function nn(e){return e.match(tn)?.[1]?.trim()??null}var rn=class extends Q.Component{state={hasError:!1};static getDerivedStateFromError(){return{hasError:!0}}render(){return this.state.hasError?this.props.fallback?this.props.fallback:this.props.fallbackContent?(0,$.jsx)(`div`,{className:`text-sm whitespace-pre-wrap break-words text-text-primary opacity-80`,children:this.props.fallbackContent}):null:this.props.children}};function an({projectName:e,onSelectSession:t}){return(0,$.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full gap-6 text-text-secondary overflow-y-auto`,children:[(0,$.jsxs)(`div`,{className:`flex flex-col items-center gap-3`,children:[(0,$.jsx)(u,{className:`size-10 text-text-subtle`}),(0,$.jsx)(`p`,{className:`text-sm`,children:`Send a message to start a new conversation`})]}),(0,$.jsx)(ze,{projectName:e,onSelectSession:t,className:`w-full px-4`})]})}function on(e){let[t,n]=(0,Q.useState)({}),[r,i]=(0,Q.useState)({}),[a,o]=(0,Q.useState)(0),s=(0,Q.useCallback)((e,t)=>{n(n=>({...n,[e]:[t]})),i(t=>({...t,[e]:``}))},[]),c=(0,Q.useCallback)((e,t)=>{n(n=>{let r=n[e]||[];return{...n,[e]:r.includes(t)?r.filter(e=>e!==t):[...r,t]}})},[]),l=(0,Q.useCallback)((e,t)=>{i(n=>({...n,[e]:t})),t&&n(t=>({...t,[e]:[]}))},[]),u=(0,Q.useCallback)(e=>(t[e]?.length??0)>0||(r[e]?.trim().length??0)>0,[t,r]);return{answers:t,customInputs:r,activeTab:a,setActiveTab:o,handleSingleSelect:s,handleMultiSelect:c,handleCustomInput:l,hasAnswer:u,allAnswered:(0,Q.useMemo)(()=>e.every((e,t)=>u(t)),[e,u]),getFinalAnswer:(0,Q.useCallback)(e=>r[e]?.trim()||(t[e]??[]).join(`, `),[t,r]),goToNextTab:(0,Q.useCallback)(()=>o(t=>Math.min(t+1,e.length-1)),[e.length]),goToPrevTab:(0,Q.useCallback)(()=>o(e=>Math.max(e-1,0)),[])}}function sn(e){let[t,n]=(0,Q.useState)(0),r=(0,Q.useRef)(null);return(0,Q.useEffect)(()=>n(0),[e.activeTab]),(0,Q.useEffect)(()=>{if(!e.enabled)return;let i=r=>{let i=document.activeElement===e.customInputRef.current;if(!i&&r.key>=`1`&&r.key<=`9`){r.preventDefault();let t=parseInt(r.key)-1;t<e.totalOptions-1&&(n(t),e.onSelectOption(t));return}if(!i&&(r.key===`o`||r.key===`O`||r.key===`0`)){r.preventDefault(),e.customInputRef.current?.focus(),n(e.totalOptions-1);return}if(r.key===`Tab`&&e.questions.length>1){r.preventDefault(),r.shiftKey?e.goToPrevTab():e.goToNextTab();return}if(!i){if(r.key===`ArrowLeft`){r.preventDefault(),e.goToPrevTab();return}if(r.key===`ArrowRight`){r.preventDefault(),e.goToNextTab();return}if(r.key===`ArrowUp`){r.preventDefault(),n(e=>Math.max(0,e-1));return}if(r.key===`ArrowDown`){r.preventDefault(),n(t=>Math.min(e.totalOptions-1,t+1));return}if(r.key===` `){r.preventDefault(),e.onSelectOption(t);return}}if(r.key===`Enter`){r.preventDefault(),e.allAnswered?e.onSubmit():e.hasAnswer(e.activeTab)&&e.goToNextTab();return}r.key===`Escape`&&i&&e.customInputRef.current?.blur()},a=r.current;return a&&(a.addEventListener(`keydown`,i),a.setAttribute(`tabindex`,`0`),a.contains(document.activeElement)||a.focus()),()=>{a?.removeEventListener(`keydown`,i)}},[e,t]),{focusedOption:t,setFocusedOption:n,containerRef:r}}function cn({questions:e,onSubmit:t,onSkip:n}){let r=(0,Q.useRef)(null),i=on(e),a=e[i.activeTab],o=a?a.options.length+1:0,s=e.length>1,c=(0,Q.useCallback)(()=>{if(!i.allAnswered)return;let n={};e.forEach((e,t)=>{n[e.question]=i.getFinalAnswer(t)}),t(n)},[i.allAnswered,i.getFinalAnswer,e,t]),l=(0,Q.useCallback)(e=>{if(!(!a||e<0))if(e<a.options.length){let t=a.options[e]?.label;if(!t)return;a.multiSelect?i.handleMultiSelect(i.activeTab,t):i.handleSingleSelect(i.activeTab,t)}else e===a.options.length&&r.current?.focus()},[a,i]),u=sn({questions:e,activeTab:i.activeTab,totalOptions:o,allAnswered:i.allAnswered,hasAnswer:i.hasAnswer,onSelectOption:l,goToNextTab:i.goToNextTab,goToPrevTab:i.goToPrevTab,onSubmit:c,customInputRef:r,enabled:!0}),d=(0,Q.useCallback)(e=>{l(e),u.setFocusedOption(e)},[l,u.setFocusedOption]);return(0,$.jsxs)(`div`,{ref:u.containerRef,className:`rounded-lg border-2 border-primary/30 bg-primary/5 p-3 space-y-3 outline-none animate-in slide-in-from-bottom-2`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between text-sm font-medium text-text-primary`,children:[(0,$.jsxs)(`span`,{children:[`AI has `,s?`${e.length} questions`:`a question`]}),(0,$.jsxs)(`span`,{className:`text-[10px] text-text-secondary font-normal`,children:[s?`←→ tabs · `:``,`↑↓ options · 1-`,Math.min(o-1,9),` select · Enter submit`]})]}),s&&(0,$.jsx)(`div`,{className:`flex gap-1 p-1 bg-background rounded-md overflow-x-auto border border-border`,children:e.map((e,t)=>(0,$.jsxs)(`button`,{className:`flex items-center gap-1.5 px-3 py-1.5 rounded text-xs whitespace-nowrap transition-all ${i.activeTab===t?`bg-primary text-primary-foreground`:i.hasAnswer(t)?`text-primary bg-transparent`:`text-text-secondary hover:bg-surface-elevated`}`,onClick:()=>{i.setActiveTab(t),u.setFocusedOption(0)},tabIndex:-1,children:[(0,$.jsx)(`span`,{className:`flex items-center justify-center w-4 h-4 rounded-full text-[10px] font-semibold ${i.activeTab===t?`bg-white/20`:i.hasAnswer(t)?`bg-primary/20 text-primary`:`bg-surface-elevated text-text-secondary`}`,children:i.hasAnswer(t)?`✓`:t+1}),(0,$.jsx)(`span`,{className:`max-w-[100px] overflow-hidden text-ellipsis`,children:e.header||`Q${t+1}`})]},t))}),a&&(0,$.jsxs)(`div`,{className:`space-y-2`,children:[!s&&a.header&&(0,$.jsx)(`div`,{className:`text-[11px] font-semibold uppercase tracking-wide text-text-secondary`,children:a.header}),(0,$.jsx)(`div`,{className:`text-sm text-text-primary`,children:a.question}),a.multiSelect&&(0,$.jsx)(`div`,{className:`text-[11px] text-text-secondary`,children:`Select multiple`}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[a.options.map((e,t)=>{let n=(i.answers[i.activeTab]||[]).includes(e.label),r=u.focusedOption===t;return(0,$.jsxs)(`button`,{onClick:()=>d(t),className:`text-left flex items-start gap-2.5 rounded px-2.5 py-2 text-xs border transition-all ${n?`border-primary bg-primary/10 text-text-primary`:`border-border bg-background text-text-secondary hover:border-primary/40 hover:bg-primary/5`} ${r?`ring-2 ring-primary/40 ring-offset-1 ring-offset-background`:``}`,children:[(0,$.jsx)(`span`,{className:`flex items-center justify-center w-4.5 h-4.5 rounded text-[10px] font-semibold shrink-0 mt-px ${n?`bg-primary/20 text-primary`:`bg-surface-elevated text-text-secondary`}`,children:t+1}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-0.5 flex-1`,children:[(0,$.jsx)(`span`,{className:`font-medium text-text-primary`,children:e.label}),e.description&&(0,$.jsx)(`span`,{className:`text-[11px] text-text-secondary`,children:e.description})]})]},t)}),(0,$.jsxs)(`div`,{className:`flex items-start gap-2.5 rounded px-2.5 py-2 text-xs border border-dashed transition-all border-border bg-transparent ${u.focusedOption===o-1?`ring-2 ring-primary/40 ring-offset-1 ring-offset-background`:``}`,children:[(0,$.jsx)(`span`,{className:`flex items-center justify-center w-4.5 h-4.5 rounded bg-surface-elevated text-text-secondary text-[10px] font-semibold shrink-0 mt-px`,children:`O`}),(0,$.jsx)(`input`,{ref:r,type:`text`,className:`flex-1 px-2 py-1 text-xs bg-surface border border-border rounded text-text-primary outline-none placeholder:text-text-subtle focus:border-primary`,placeholder:`Other (press O to type)...`,value:i.customInputs[i.activeTab]||``,onChange:e=>i.handleCustomInput(i.activeTab,e.target.value),onFocus:()=>u.setFocusedOption(o-1)})]})]})]}),(0,$.jsxs)(`div`,{className:`flex gap-2 justify-end pt-1`,children:[s&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`button`,{className:`px-3 py-1.5 text-xs rounded border border-border bg-background text-text-primary hover:bg-surface-elevated disabled:opacity-40 disabled:cursor-not-allowed transition-colors`,onClick:i.goToPrevTab,disabled:i.activeTab===0,tabIndex:-1,children:`← Prev`}),(0,$.jsx)(`button`,{className:`px-3 py-1.5 text-xs rounded border border-border bg-background text-text-primary hover:bg-surface-elevated disabled:opacity-40 disabled:cursor-not-allowed transition-colors`,onClick:i.goToNextTab,disabled:i.activeTab===e.length-1,tabIndex:-1,children:`Next →`})]}),(0,$.jsx)(`button`,{onClick:n,className:`px-4 py-1.5 rounded border border-border bg-background text-text-secondary text-xs hover:bg-surface-elevated transition-colors`,tabIndex:-1,children:`Skip`}),(0,$.jsxs)(`button`,{onClick:c,disabled:!i.allAnswered,className:`px-4 py-1.5 rounded bg-primary text-primary-foreground text-xs font-medium hover:bg-primary/80 transition-colors disabled:opacity-40 disabled:cursor-not-allowed`,tabIndex:-1,children:[`Submit `,i.allAnswered?`✓`:`(${e.filter((e,t)=>i.hasAnswer(t)).length}/${e.length})`]})]})]})}var ln=(0,Q.lazy)(()=>ie(()=>import(`./markdown-renderer-Bv_VAy7V.js`).then(e=>({default:e.MarkdownRenderer})),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23])));function un({messages:e,messagesLoading:t,pendingApproval:n,onApprovalResponse:r,isStreaming:i,phase:a,onSelectSession:o,connectingElapsed:s,statusMessage:c,compactStatus:l,projectName:d,onFork:f,bashPartialOutput:p,onExpandCompact:m,isCompactExpanded:h}){let[g,_]=(0,Q.useState)(50),v=e[0]?.id;(0,Q.useEffect)(()=>{_(50)},[v]);let y=(0,Q.useMemo)(()=>e.filter(e=>{let t=e.content&&e.content.trim().length>0,n=e.events&&e.events.length>0;return e.role===`user`?t:t||n}),[e]),b=(0,Q.useMemo)(()=>{let e=Math.max(0,y.length-g);return y.slice(e)},[y,g]),x=g<y.length,S=(0,Q.useCallback)((e,t)=>{f?.(e,t)},[f]),C=(0,Q.useRef)(null),w=(0,Q.useCallback)(()=>{if(!m||!h)return null;for(let e of b){if(h(e.id))continue;let t=nn(e.content||``);if(t)return{id:e.id,jsonlPath:t};if(e.events){for(let t of e.events)if(t.type===`text`){let n=nn(t.content||``);if(n)return{id:e.id,jsonlPath:n}}}}return null},[b,m,h]),[T,E]=(0,Q.useState)(!1),D=(0,Q.useCallback)(async()=>{if(x){C.current?.capture(),_(e=>e+50),requestAnimationFrame(()=>requestAnimationFrame(()=>C.current?.restore()));return}let e=w();if(!(!e||!m||T)){E(!0);try{C.current?.capture();let t=await m(e.id,e.jsonlPath);_(e=>e+t),requestAnimationFrame(()=>requestAnimationFrame(()=>C.current?.restore()))}finally{E(!1)}}},[x,w,m,T]),O=x||!!w();return t?(0,$.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full gap-3 text-text-secondary`,children:[(0,$.jsx)(u,{className:`size-10 text-text-subtle animate-pulse`}),(0,$.jsx)(`p`,{className:`text-sm`,children:`Loading messages...`})]}):e.length===0&&!i?(0,$.jsx)(an,{projectName:d||``,onSelectSession:o||(()=>{})}):(0,$.jsx)(`div`,{className:`relative flex-1 overflow-hidden flex flex-col min-h-0`,children:(0,$.jsxs)(Vt,{className:`flex-1 overflow-y-auto overflow-x-hidden [contain:strict] [overflow-anchor:auto]`,resize:`smooth`,initial:`instant`,children:[(0,$.jsxs)(Vt.Content,{className:`p-4 space-y-4 select-none [&>*]:[overflow-anchor:auto]`,children:[(0,$.jsx)(dn,{bridgeRef:C}),O&&(0,$.jsx)(pn,{onLoadMore:D,loading:T}),b.map((e,t)=>{let n=y.length-b.length+t,r=n>0?y[n-1]:void 0;return(0,$.jsx)(rn,{fallbackContent:e.content,children:(0,$.jsx)(mn,{message:e,isStreaming:i&&e.id.startsWith(`streaming-`),projectName:d,onFork:e.role===`user`&&f?S:void 0,prevMsgId:r?.sdkUuid??r?.id,bashPartialOutput:p})},e.id)}),n&&(n.tool===`AskUserQuestion`?(0,$.jsx)(Vn,{approval:n,onRespond:r}):(0,$.jsx)(Bn,{approval:n,onRespond:r})),i&&(0,$.jsx)(In,{lastMessage:e[e.length-1],phase:a,elapsed:s,statusMessage:l===`compacting`?`Compacting messages...`:c})]}),(0,$.jsx)(fn,{})]})})}function dn({bridgeRef:e}){let{scrollRef:t,isAtBottom:n}=Ht(),r=(0,Q.useRef)(null);return(0,Q.useEffect)(()=>(e.current={capture:()=>{let e=t.current;if(!e||n){r.current=null;return}r.current={top:e.scrollTop,height:e.scrollHeight}},restore:()=>{let e=t.current,n=r.current;if(!e||!n)return;let i=e.scrollHeight-n.height;i!==0&&(e.scrollTop=n.top+i),r.current=null}},()=>{e.current=null}),[e,t,n]),null}function fn(){let{isAtBottom:e,scrollToBottom:t}=Ht();return e?null:(0,$.jsxs)(`button`,{onClick:()=>t(),className:`absolute bottom-4 left-1/2 -translate-x-1/2 z-10 flex items-center gap-1 px-3 py-1 rounded-full bg-surface-elevated border border-border text-xs text-text-secondary hover:text-foreground shadow-lg transition-all`,children:[(0,$.jsx)(m,{className:`size-3`}),`Scroll to bottom`]})}function pn({onLoadMore:e,loading:t}){let n=(0,Q.useRef)(null),r=(0,Q.useRef)(e);return r.current=e,(0,Q.useEffect)(()=>{let e=n.current;if(!e)return;let t=new IntersectionObserver(([e])=>{e?.isIntersecting&&r.current()},{rootMargin:`200px 0px 0px 0px`});return t.observe(e),()=>t.disconnect()},[]),(0,$.jsx)(`div`,{ref:n,className:`flex items-center justify-center py-2 text-xs text-text-secondary`,children:t&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Z,{className:`size-3 animate-spin mr-1.5`}),`Loading previous conversation...`]})})}var mn=(0,Q.memo)(function({message:e,isStreaming:t,projectName:n,onFork:r,prevMsgId:i,bashPartialOutput:a}){if(e.role===`user`){let t=r?()=>r(e.content,i):void 0;return(0,$.jsx)(wn,{content:e.content,messageId:e.id,projectName:n,onFork:t})}return e.role===`system`?(0,$.jsxs)(`div`,{className:`flex items-center gap-2 rounded-lg bg-red-500/10 border border-red-500/20 px-3 py-2 text-sm text-red-400`,children:[(0,$.jsx)(Ue,{className:`size-4 shrink-0`}),(0,$.jsx)(`p`,{children:e.content})]}):(0,$.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[e.events&&e.events.length>0?(0,$.jsx)(Nn,{events:e.events,isStreaming:t,projectName:n,bashPartialOutput:a}):e.content&&(0,$.jsx)(`div`,{className:`text-sm text-text-primary select-text`,children:(0,$.jsx)(zn,{content:e.content,projectName:n})}),e.accountLabel&&(0,$.jsxs)(`p`,{className:`text-[10px] select-none`,style:{color:`var(--color-text-subtle)`},children:[`via `,e.accountLabel]})]})}),hn=new Set([`.png`,`.jpg`,`.jpeg`,`.gif`,`.webp`]),gn={"system-reminder":`Context`,claudeMd:`CLAUDE.md`,gitStatus:`Git Status`,currentDate:`Date`,fast_mode_info:`Fast Mode`,"available-deferred-tools":`Tools`,"task-notification":`Task Result`,environment_details:`Environment`};function _n(e){let t=[],n=/<(system-reminder|available-deferred-tools|antml:[\w-]+|fast_mode_info|claudeMd|gitStatus|currentDate|task-notification|environment_details)[^>]*>([\s\S]*?)<\/\1>/g,r;for(;(r=n.exec(e))!==null;){let e=r[1];t.push({name:e,label:gn[e]??e.replace(/^antml:/,``).replace(/-/g,` `),content:r[2].trim()})}return{cleanText:e.replace(n,``).trim(),tags:t}}var vn=/<command-message>[\s\S]*?<\/command-message>\s*<command-name>([\s\S]*?)<\/command-name>(?:\s*<command-args>([\s\S]*?)<\/command-args>)?/;function yn(e){let t=e.match(vn);if(!t)return{command:null,cleanText:e};let n=t[1].trim(),r=t[2]?.trim()||void 0,i=e.replace(vn,``).trim();return{command:{name:n,args:r},cleanText:i}}function bn(e){let t=e.match(/^\[Attached file: (.+?)\]\n\n?/);if(t)return{files:[t[1]],text:e.slice(t[0].length)};let n=e.match(/^\[Attached files:\n([\s\S]+?)\]\n\n?/);return n?{files:n[1].split(`
8
8
  `).map(e=>e.trim()).filter(Boolean),text:e.slice(n[0].length)}:{files:[],text:e}}function xn(e,t){let n=J(e);return`/api/project/${encodeURIComponent(t??`_`)}/chat/uploads/${encodeURIComponent(n)}`}function Sn(e){let t=e.lastIndexOf(`.`);return t===-1?!1:hn.has(e.slice(t).toLowerCase())}var Cn=new Set([`task-notification`,`environment_details`]);function wn({content:e,messageId:t,projectName:n,onFork:r}){let{files:i,text:a,tags:o,command:s}=(0,Q.useMemo)(()=>{let t=bn(e),{cleanText:n,tags:r}=_n(t.text),{command:i,cleanText:a}=yn(n),o=i?.args?a?`${i.args}\n\n${a}`:i.args:a;return{files:t.files,text:o,tags:r,command:i}},[e]),c=o.some(e=>Cn.has(e.name)),[l,u]=(0,Q.useState)(!1),[d,f]=(0,Q.useState)(!1),p=(0,Q.useRef)(null);return(0,Q.useEffect)(()=>{let e=p.current;if(!e)return;let t=()=>f(e.scrollHeight>e.clientHeight+2);t();let n=new ResizeObserver(t);return n.observe(e),()=>n.disconnect()},[a]),(0,$.jsxs)(`div`,{className:q(`group/user relative rounded-lg px-3 py-2 text-sm border shadow-sm`,c?`bg-surface/40 border-border/40 text-text-secondary`:`bg-primary/10 border-primary/15 text-text-primary`),children:[o.length>0&&(0,$.jsx)(Tn,{tags:o}),s&&(0,$.jsx)(`div`,{className:`flex items-center gap-1.5 mb-0.5`,children:(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded-md bg-primary/15 border border-primary/20 px-2 py-0.5 text-xs font-medium text-primary`,children:[(0,$.jsx)(lt,{className:`size-3 shrink-0`}),s.name]})}),i.length>0&&(0,$.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:i.map((e,t)=>Sn(e)?(0,$.jsx)(Mn,{filePath:e,projectName:n},t):(0,$.jsxs)(`div`,{className:`flex items-center gap-1 rounded-md border border-border/60 bg-background/40 px-1.5 py-0.5 text-[11px] text-text-secondary`,children:[(0,$.jsx)(Pe,{className:`size-3 shrink-0`}),(0,$.jsx)(`span`,{className:`truncate max-w-32`,children:J(e)})]},t))}),a&&(0,$.jsx)(`div`,{ref:p,className:q(`whitespace-pre-wrap break-words transition-all duration-200 select-text`,!l&&`line-clamp-2`,l&&`max-h-[50vh] overflow-y-auto`),children:c?(0,$.jsx)(An,{text:a,projectName:n}):a}),(d||l)&&(0,$.jsx)(`button`,{onClick:()=>u(!l),className:q(`flex items-center gap-1 text-xs mt-1 transition-colors`,c?`text-text-subtle hover:text-text-secondary`:`text-primary/70 hover:text-primary`),children:l?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(_,{className:`size-3`}),`Show less`]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(m,{className:`size-3`}),`Show more`]})}),!c&&r&&(0,$.jsx)(`button`,{onClick:r,title:`Retry from this message (fork session)`,className:`absolute top-1.5 right-1.5 can-hover:opacity-0 can-hover:group-hover/user:opacity-100 transition-opacity size-5 flex items-center justify-center rounded text-text-subtle hover:text-text-primary`,children:(0,$.jsx)(we,{className:`size-3`})})]})}function Tn({tags:e}){return(0,$.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:e.map((e,t)=>(0,$.jsx)(En,{tag:e},t))})}function En({tag:e}){let[t,n]=(0,Q.useState)(!1);return e.name===`task-notification`?(0,$.jsx)(On,{content:e.content}):(0,$.jsxs)(`div`,{className:`text-xs`,children:[(0,$.jsxs)(`button`,{onClick:()=>n(!t),className:`flex items-center gap-1 rounded-full border border-border/60 bg-surface/50 px-2 py-0.5 text-text-subtle hover:text-text-secondary hover:bg-surface transition-colors`,children:[(0,$.jsx)(Ae,{className:`size-2.5`}),(0,$.jsx)(`span`,{children:e.label}),(0,$.jsx)(T,{className:q(`size-2.5 transition-transform`,t&&`rotate-90`)})]}),t&&(0,$.jsx)(`div`,{className:`mt-1 rounded border border-border/40 bg-surface/30 px-2 py-1.5 text-[11px] text-text-subtle/80 whitespace-pre-wrap max-h-40 overflow-y-auto leading-relaxed`,children:e.content})]})}function Dn(e,t){return e.match(RegExp(`<${t}>([\\s\\S]*?)</${t}>`))?.[1]?.trim()||void 0}function On({content:e}){let[t,n]=(0,Q.useState)(!1),r=Dn(e,`status`),i=Dn(e,`summary`),a=Dn(e,`output-file`),o=Dn(e,`result`);return(0,$.jsxs)(`div`,{className:`text-xs`,children:[(0,$.jsxs)(`button`,{onClick:()=>n(!t),className:`flex items-center gap-1.5 rounded-full border border-border/60 bg-surface/50 px-2 py-0.5 text-text-subtle hover:text-text-secondary hover:bg-surface transition-colors`,children:[r===`completed`?(0,$.jsx)(Be,{className:`size-2.5 text-green-500`}):(0,$.jsx)(Ye,{className:`size-2.5 text-yellow-500`}),(0,$.jsx)(`span`,{className:`truncate max-w-80`,children:i??`Task notification`}),(0,$.jsx)(T,{className:q(`size-2.5 transition-transform shrink-0`,t&&`rotate-90`)})]}),t&&(0,$.jsxs)(`div`,{className:`mt-1 rounded border border-border/40 bg-surface/30 px-2 py-1.5 space-y-1.5`,children:[i&&(0,$.jsx)(`p`,{className:`text-[11px] text-text-secondary`,children:i}),a&&(0,$.jsx)(kn,{path:a}),o&&(0,$.jsx)(`div`,{className:`text-[11px] text-text-subtle/80 max-h-60 overflow-y-auto leading-relaxed`,children:(0,$.jsx)(zn,{content:o})})]})]})}function kn({path:e,projectName:t}){return(0,$.jsxs)(`button`,{type:`button`,onClick:(0,Q.useCallback)(()=>{let n=X.getState().openTab,r=t??oe.getState().activeProject?.name,i=J(e),a={filePath:e};r&&(a.projectName=r),G.get(`/api/fs/read?path=${encodeURIComponent(e)}`).then(()=>{n({type:`editor`,title:i,metadata:a,projectId:null,closable:!0})}).catch(()=>{n({type:`editor`,title:i,metadata:a,projectId:null,closable:!0})})},[e,t]),className:`inline-flex items-center gap-1 rounded border border-border/50 bg-surface/50 px-1.5 py-0.5 font-mono text-[10px] text-text-secondary hover:text-text-primary hover:bg-surface transition-colors cursor-pointer`,children:[(0,$.jsx)(Pe,{className:`size-2.5 shrink-0`}),(0,$.jsx)(`span`,{className:`truncate max-w-60`,children:J(e)}),(0,$.jsx)(xe,{className:`size-2 shrink-0 opacity-50`})]})}function An({text:e,projectName:t}){return(0,$.jsx)($.Fragment,{children:(0,Q.useMemo)(()=>{let t=/(\/(?:[\w.\-]+\/)+[\w.\-]+)/g,n=[],r=0,i;for(;(i=t.exec(e))!==null;)i.index>r&&n.push({kind:`text`,value:e.slice(r,i.index)}),n.push({kind:`path`,value:i[1]}),r=i.index+i[0].length;return r<e.length&&n.push({kind:`text`,value:e.slice(r)}),n},[e]).map((e,n)=>e.kind===`path`?(0,$.jsx)(kn,{path:e.value,projectName:t},n):(0,$.jsx)(`span`,{children:e.value},n))})}function jn(e){let[t,n]=(0,Q.useState)(null),[r,i]=(0,Q.useState)(!1);return(0,Q.useEffect)(()=>{let t=!1,r,a=re();return fetch(e,{headers:a?{Authorization:`Bearer ${a}`}:{}}).then(e=>{if(!e.ok)throw Error(`Failed`);return e.blob()}).then(e=>{t||(r=URL.createObjectURL(e),n(r))}).catch(()=>{t||i(!0)}),()=>{t=!0,r&&URL.revokeObjectURL(r)}},[e]),{blobUrl:t,error:r}}function Mn({filePath:e,projectName:t}){let{blobUrl:n,error:r}=jn(xn(e,t)),i=He(e=>e.open),a=J(e);return(0,$.jsxs)(`button`,{type:`button`,onClick:()=>n&&i(n,a),className:`flex items-center gap-1 rounded-md border border-border/60 bg-background/40 px-1.5 py-0.5 text-[11px] text-text-secondary hover:bg-surface transition-colors cursor-pointer`,children:[n?(0,$.jsx)(`img`,{src:n,alt:a,className:`size-4 rounded-sm object-cover shrink-0`}):r?(0,$.jsx)(et,{className:`size-3 shrink-0`}):(0,$.jsx)(`div`,{className:`size-4 rounded-sm bg-surface animate-pulse shrink-0`}),(0,$.jsx)(`span`,{className:`truncate max-w-32`,children:a})]})}function Nn({events:e,isStreaming:t,projectName:n,bashPartialOutput:r}){let i=[],a=``,o=``;for(let t=0;t<e.length;t++){let n=e[t];if(n.type===`thinking`){a&&=(i.push({kind:`text`,content:a}),``),o+=n.content;continue}if(o&&=(i.push({kind:`thinking`,content:o}),``),n.type===`account_retry`){a&&=(i.push({kind:`text`,content:a}),``);let e=n.accountLabel??`another account`,t=n.reason??`Auth failed`;i.push({kind:`text`,content:`\n\n> ↻ ${t} — retrying with **${e}**...\n\n`});continue}n.type===`text`?a+=n.content:n.type===`tool_use`?(a&&=(i.push({kind:`text`,content:a}),``),i.push({kind:`tool`,tool:n})):n.type===`tool_result`||(a&&=(i.push({kind:`text`,content:a}),``),i.push({kind:`tool`,tool:n}))}o&&i.push({kind:`thinking`,content:o}),a&&i.push({kind:`text`,content:a});let s=e.filter(e=>e.type===`tool_result`);for(let e of s){let t=e.toolUseId;if(t){let n=i.find(e=>e.kind===`tool`&&e.tool.type===`tool_use`&&e.tool.toolUseId===t);if(n){n.result=e;continue}}let n=i.find(e=>e.kind===`tool`&&!e.result);n&&(n.result=e)}for(let e of i)if(e.kind===`tool`&&!e.result&&e.tool.type===`tool_use`){let t=e.tool.result;t&&(e.result={type:`tool_result`,output:t.output,isError:t.isError})}for(let e=0;e<i.length;e++){let n=i[e];if(n.kind===`tool`&&!n.result){let r=!1;if(n.tool.type===`tool_use`&&n.tool.tool===`Read`){let t=n.tool.input?.file_path;t&&(r=i.slice(e+1).some(e=>e.kind===`tool`&&e.result&&e.tool.type===`tool_use`&&e.tool.tool===`Edit`&&e.tool.input?.file_path===t))}n.completed=r||!t}}return(0,$.jsx)($.Fragment,{children:i.map((e,a)=>{if(e.kind===`thinking`)return(0,$.jsx)(Pn,{content:e.content,isStreaming:t&&a===i.length-1},`think-${a}`);if(e.kind===`text`){let r=t&&a===i.length-1;return(0,$.jsx)(`div`,{className:`text-sm text-text-primary select-text`,children:(0,$.jsx)(Fn,{content:e.content,animate:r,projectName:n})},`text-${a}`)}return(0,$.jsx)(Gt,{tool:e.tool,result:e.result,completed:e.completed,projectName:n,bashPartialOutput:r},`tool-${a}`)})})}function Pn({content:e,isStreaming:t}){let[n,r]=(0,Q.useState)(t),i=(0,Q.useRef)(null);return(0,Q.useEffect)(()=>{!t&&e.length>0&&r(!1)},[t,e.length]),(0,Q.useEffect)(()=>{t&&n&&i.current&&(i.current.scrollTop=i.current.scrollHeight)},[e,t,n]),(0,$.jsxs)(`div`,{className:`rounded border border-border/50 bg-surface/30 text-xs`,children:[(0,$.jsxs)(`button`,{onClick:()=>r(!n),className:`flex items-center gap-2 px-2 py-1.5 w-full text-left hover:bg-surface transition-colors text-text-subtle`,children:[t?(0,$.jsx)(Z,{className:`size-3 animate-spin`}):(0,$.jsx)(T,{className:`size-3 transition-transform ${n?`rotate-90`:``}`}),(0,$.jsxs)(`span`,{children:[`Thinking`,t?`...`:``]}),!t&&(0,$.jsx)(`span`,{className:`text-text-subtle/50 ml-auto`,children:e.length>100?`${Math.round(e.length/4)} tokens`:``})]}),n&&(0,$.jsx)(`div`,{ref:i,className:`max-h-60 overflow-y-auto`,children:(0,$.jsx)(`div`,{className:`px-2 pb-2 text-text-subtle/80 whitespace-pre-wrap text-[11px] leading-relaxed`,children:e})})]})}function Fn({content:e,animate:t,projectName:n}){return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(zn,{content:e,projectName:n,isStreaming:t}),t&&(0,$.jsx)(`span`,{className:`text-text-subtle text-sm animate-pulse`,children:`Thinking...`})]})}function In({lastMessage:e,phase:t,elapsed:n,statusMessage:r}){let i=!e||e.role!==`assistant`,a=e?.events?.length?e.events[e.events.length-1].type===`tool_result`:!1;return!r&&!i&&!a?null:(0,$.jsxs)(`div`,{className:`flex flex-col gap-1 text-sm`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2 text-text-subtle`,children:[(0,$.jsx)(Z,{className:`size-3 animate-spin`}),(0,$.jsxs)(`span`,{children:[r||(t===`initializing`?`Initializing`:t===`connecting`?`Connecting`:t===`thinking`?`Thinking`:`Processing`),i&&(n??0)>0&&(0,$.jsxs)(`span`,{className:`text-text-subtle/60`,children:[`... (`,n,`s)`]})]})]}),t===`connecting`&&(n??0)>=30&&(0,$.jsx)(`p`,{className:`text-xs text-yellow-500/80 ml-5`,children:`Taking longer than usual — may be rate-limited or API slow. Try sending a new message to retry.`})]})}var Ln=/<teammate-message[^>]*>[\s\S]*?<\/teammate-message>/g;function Rn(e){return e.replace(Ln,``).replace(/\n{3,}/g,`
9
9
 
10
10
  `).trim()}function zn({content:e,projectName:t,isStreaming:n}){let r=Rn(e);return r?(0,$.jsx)(rn,{fallbackContent:r,children:(0,$.jsx)(Q.Suspense,{fallback:(0,$.jsx)(`div`,{className:`animate-pulse h-4 bg-muted rounded`}),children:(0,$.jsx)(ln,{content:r,projectName:t,codeActions:!0,isStreaming:n})})}):null}function Bn({approval:e,onRespond:t}){return(0,$.jsxs)(`div`,{className:`rounded-lg border-2 border-yellow-500/40 bg-yellow-500/10 p-3 space-y-2`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2 text-yellow-400 text-sm font-medium`,children:[(0,$.jsx)(st,{className:`size-4`}),(0,$.jsx)(`span`,{children:`Tool Approval Required`})]}),(0,$.jsx)(`div`,{className:`text-xs text-text-primary`,children:(0,$.jsx)(`span`,{className:`font-medium`,children:e.tool})}),(0,$.jsx)(`pre`,{className:`text-xs font-mono text-text-secondary overflow-x-auto bg-background rounded p-2 border border-border`,children:JSON.stringify(e.input,null,2)}),(0,$.jsxs)(`div`,{className:`flex gap-2`,children:[(0,$.jsx)(`button`,{onClick:()=>t(e.requestId,!0),className:`px-4 py-1.5 rounded bg-green-600 text-white text-xs font-medium hover:bg-green-500 transition-colors`,children:`Allow`}),(0,$.jsx)(`button`,{onClick:()=>t(e.requestId,!1),className:`px-4 py-1.5 rounded bg-red-600 text-white text-xs font-medium hover:bg-red-500 transition-colors`,children:`Deny`})]})]})}function Vn({approval:e,onRespond:t}){return(0,$.jsx)(cn,{questions:e.input.questions??[],onSubmit:n=>t(e.requestId,!0,n),onSkip:()=>t(e.requestId,!1)})}function Hn(){let e=window;return e.SpeechRecognition??e.webkitSpeechRecognition??null}function Un(e){let[t,n]=(0,Q.useState)(!1),[r,i]=(0,Q.useState)(``),a=(0,Q.useRef)(null),o=(0,Q.useRef)(``),s=typeof window<`u`&&Hn()!==null;return{isListening:t,interimText:r,start:(0,Q.useCallback)(t=>{let r=Hn();if(!r)return;a.current?.abort();let s=new r;s.lang=e?.lang??`vi-VN`,s.continuous=!0,s.interimResults=!0,o.current=``,s.onresult=e=>{let n=``,r=``;for(let t=0;t<e.results.length;t++){let i=e.results[t];i.isFinal?r+=i[0].transcript:n+=i[0].transcript}r&&(o.current=r);let a=(o.current+` `+n).trim();i(n),t(a,n.length===0&&o.current.length>0)},s.onend=()=>{n(!1),i(``),o.current&&t(o.current.trim(),!0)},s.onerror=e=>{e.error!==`no-speech`&&e.error!==`aborted`&&console.warn(`[voice-input] error:`,e.error),n(!1),i(``)},a.current=s,s.start(),n(!0)},[e?.lang]),stop:(0,Q.useCallback)(()=>{a.current?.stop(),a.current=null,n(!1),i(``)},[]),supported:s}}var Wn=new Set([`image/png`,`image/jpeg`,`image/gif`,`image/webp`]),Gn=new Set([`application/pdf`]),Kn=[`text/`,`application/json`,`application/xml`,`application/javascript`,`application/typescript`,`application/x-yaml`,`application/toml`,`application/x-sh`],qn=new Set(`.ts,.tsx,.js,.jsx,.mjs,.cjs,.py,.rb,.go,.rs,.java,.kt,.swift,.c,.cpp,.h,.hpp,.cs,.json,.yaml,.yml,.toml,.xml,.md,.mdx,.txt,.csv,.tsv,.html,.css,.scss,.less,.sass,.sh,.bash,.zsh,.fish,.sql,.graphql,.gql,.env,.ini,.cfg,.conf,.dockerfile,.makefile,.vue,.svelte,.astro,.ipynb`.split(`,`));function Jn(e){return Wn.has(e.type)}function Yn(e){if(Wn.has(e.type)||Gn.has(e.type)||Kn.some(t=>e.type.startsWith(t)))return!0;let t=Xn(e.name);return!!(t&&qn.has(t))}function Xn(e){let t=e.lastIndexOf(`.`);return t===-1?``:e.slice(t).toLowerCase()}function Zn({attachments:e,onRemove:t}){return e.length===0?null:(0,$.jsx)(`div`,{className:`flex flex-wrap gap-1.5 px-2 md:px-4 pt-2`,children:e.map(e=>(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5 rounded-md border border-border bg-surface px-2 py-1 text-xs text-text-secondary max-w-48`,children:[e.previewUrl?(0,$.jsx)(`img`,{src:e.previewUrl,alt:e.name,className:`size-5 rounded object-cover shrink-0`}):e.isImage?(0,$.jsx)(et,{className:`size-3.5 shrink-0 text-text-subtle`}):(0,$.jsx)(Pe,{className:`size-3.5 shrink-0 text-text-subtle`}),(0,$.jsx)(`span`,{className:`truncate`,children:e.name}),e.status===`uploading`?(0,$.jsx)(Z,{className:`size-3 shrink-0 animate-spin text-text-subtle`}):e.status===`error`?(0,$.jsx)(`span`,{className:`text-red-500 shrink-0`,title:`Upload failed`,children:`!`}):null,(0,$.jsx)(`button`,{type:`button`,onClick:()=>t(e.id),className:`shrink-0 rounded-sm p-0.5 hover:bg-border/50 transition-colors`,"aria-label":`Remove ${e.name}`,children:(0,$.jsx)(H,{className:`size-3`})})]},e.id))})}var Qn=[{id:`default`,label:`Ask before edits`,icon:Qe,description:`Claude will ask for approval before making each edit`},{id:`acceptEdits`,label:`Edit automatically`,icon:F,description:`Claude will edit files without asking first`},{id:`plan`,label:`Plan mode`,icon:Ze,description:`Claude will present a plan before editing`},{id:`bypassPermissions`,label:`Bypass permissions`,icon:ct,description:`Claude will not ask before running commands`}];function $n(e){return Qn.find(t=>t.id===e)?.label??`Unknown`}function er(e){return Qn.find(t=>t.id===e)?.icon??Qe}function tr({value:e,onChange:t,open:n,onOpenChange:r}){let i=(0,Q.useRef)(null),a=(0,Q.useRef)(0);(0,Q.useEffect)(()=>{if(!n)return;let e=e=>{i.current&&!i.current.contains(e.target)&&r(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[n,r]),(0,Q.useEffect)(()=>{n&&(a.current=Qn.findIndex(t=>t.id===e),a.current<0&&(a.current=0))},[n,e]);let o=(0,Q.useCallback)(e=>{if(e.key===`Escape`){r(!1);return}if(e.key===`ArrowDown`||e.key===`ArrowUp`){e.preventDefault();let t=e.key===`ArrowDown`?1:-1;a.current=(a.current+t+Qn.length)%Qn.length,(i.current?.querySelector(`[data-idx="${a.current}"]`))?.focus()}if(e.key===`Enter`){e.preventDefault();let n=Qn[a.current];n&&(t(n.id),r(!1))}},[t,r]);return n?(0,$.jsxs)(`div`,{ref:i,role:`listbox`,"aria-label":`Permission modes`,onKeyDown:o,onMouseDown:e=>e.stopPropagation(),onClick:e=>e.stopPropagation(),className:`absolute bottom-full left-0 mb-1 z-50 w-72 md:w-80 rounded-lg border border-border bg-surface shadow-lg`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between px-3 py-2 border-b border-border`,children:[(0,$.jsx)(`span`,{className:`text-xs font-medium text-text-secondary`,children:`Modes`}),(0,$.jsx)(`kbd`,{className:`text-[10px] px-1.5 py-0.5 rounded bg-surface-elevated text-text-subtle border border-border`,children:`Shift + Tab`})]}),(0,$.jsx)(`div`,{className:`py-1`,children:Qn.map((n,i)=>{let a=n.icon,o=n.id===e;return(0,$.jsxs)(`button`,{"data-idx":i,role:`option`,"aria-selected":o,tabIndex:0,onClick:()=>{t(n.id),r(!1)},className:`w-full flex items-start gap-3 px-3 py-2.5 text-left transition-colors hover:bg-surface-elevated focus:bg-surface-elevated focus:outline-none ${o?`bg-surface-elevated`:``}`,children:[(0,$.jsx)(a,{className:`size-4 mt-0.5 shrink-0 text-text-secondary`}),(0,$.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,$.jsx)(`div`,{className:`text-sm font-medium text-text-primary`,children:n.label}),(0,$.jsx)(`div`,{className:`text-xs text-text-subtle leading-snug`,children:n.description})]}),o&&(0,$.jsx)(S,{className:`size-4 mt-0.5 shrink-0 text-primary`})]},n.id)})})]}):null}var nr=(0,Q.memo)(function({onSend:e,isStreaming:t,onCancel:n,disabled:r,projectName:a,onSlashStateChange:o,onSlashItemsLoaded:s,slashSelected:c,onFileStateChange:l,onFileItemsLoaded:u,fileSelected:d,externalFiles:f,externalPaths:p,onExternalPathsConsumed:m,onDisambiguate:h,initialValue:g,autoFocus:_,permissionMode:y,onModeChange:b,providerId:x,onProviderChange:S}){let C=(0,Q.useRef)(g??``),[w,T]=(0,Q.useState)(()=>(g??``).trim().length>0),[E,D]=(0,Q.useState)([]),[O,k]=(0,Q.useState)(!1),[A,j]=(0,Q.useState)(!1),[M,N]=(0,Q.useState)(`next`),P=(0,Q.useRef)(null),F=(0,Q.useRef)(null),I=(0,Q.useRef)(null),L=(0,Q.useRef)([]),ee=(0,Q.useRef)([]),R=(0,Q.useRef)(0),z=(0,Q.useRef)(!1),B=(0,Q.useRef)(!1),te=(0,Q.useRef)(typeof CSS>`u`||!CSS.supports(`field-sizing`,`content`)),V=(0,Q.useCallback)(e=>{C.current=e,P.current&&(P.current.value=e),F.current&&(F.current.value=e),T(e.trim().length>0)},[]),H=(0,Q.useCallback)(()=>window.matchMedia(`(min-width: 768px)`).matches?P.current:F.current,[]),U=Un(),ne=(0,Q.useRef)(``),K=(0,Q.useCallback)(e=>{let t=ne.current;V(t?t+` `+e:e),te.current&&requestAnimationFrame(()=>{let e=H();e&&(e.style.height=`auto`,e.style.height=Math.min(e.scrollHeight,160)+`px`)})},[V,H]),ie=(0,Q.useCallback)(()=>{U.isListening?U.stop():(ne.current=C.current.trim(),U.start(K))},[U.isListening,U.start,U.stop,K]);(0,Q.useEffect)(()=>{let e=()=>{U.supported&&ie()};return window.addEventListener(`toggle-voice-input`,e),()=>window.removeEventListener(`toggle-voice-input`,e)},[U.supported,ie]),(0,Q.useEffect)(()=>{g&&(V(g),setTimeout(()=>{let e=P.current;e&&(e.focus(),e.selectionStart=e.selectionEnd=e.value.length)},50))},[g]),(0,Q.useEffect)(()=>{_&&setTimeout(()=>{H()?.focus()},100)},[]);let q=(0,Q.useCallback)(()=>{if(!a){L.current=[],s?.([],[]);return}G.get(`${W(a)}/chat/slash-items`).then(e=>{L.current=e.items,s?.(e.items,e.recentNames)}).catch(()=>{L.current=[],s?.([],[])})},[a,s]);(0,Q.useEffect)(()=>{q()},[q]),(0,Q.useEffect)(()=>{let e=()=>q();return window.addEventListener(`ppm:slash-items-refresh`,e),()=>window.removeEventListener(`ppm:slash-items-refresh`,e)},[q]),(0,Q.useEffect)(()=>{let e=()=>{if(!a){ee.current=[],u?.([]);return}let{fileIndex:e}=se.getState(),t=e.map(e=>({name:e.name,path:e.path,type:e.type}));ee.current=t,u?.(t)};e();let t=se.getState().fileIndex,n=se.getState().indexStatus;return se.subscribe(r=>{(r.fileIndex!==t||r.indexStatus!==n)&&(t=r.fileIndex,n=r.indexStatus,e())})},[a]),(0,Q.useEffect)(()=>{if(!c)return;let e=H();if(!e)return;let t=e.value,n=e.selectionStart,r=t.slice(0,n),i=t.slice(n),a=r.replace(/(?:^|\s)\/\S*$/,e=>`${e.startsWith(`/`)?``:e[0]}/${c.name} `);V(a+i),o?.(!1,``),z.current=!1,l?.(!1,``),B.current=!1,e.focus(),setTimeout(()=>{e.selectionStart=e.selectionEnd=a.length},0)},[c]),(0,Q.useEffect)(()=>{if(!d)return;let e=H();if(!e)return;let t=e.value,n=e.selectionStart,r=t.slice(0,n),i=t.slice(n),a=r.match(/@(\S*)$/);if(a){let t=r.length-a[0].length;V(r.slice(0,t)+`@${d.path} `+i);let n=t+d.path.length+2;setTimeout(()=>{e.selectionStart=e.selectionEnd=n,e.focus()},0)}else{let n=t+`@${d.path} `;V(n),setTimeout(()=>{e.selectionStart=e.selectionEnd=n.length,e.focus()},0)}l?.(!1,``),B.current=!1},[d]),(0,Q.useEffect)(()=>{!f||f.length===0||Y(f)},[f]),(0,Q.useEffect)(()=>{if(!p||p.length===0)return;let e=p.map(e=>`@${e}`).join(` `),t=C.current;V(t+(t.length>0&&!t.endsWith(` `)?` `:``)+e+` `),H()?.focus(),m?.()},[p]);let J=(0,Q.useCallback)(async e=>{if(!a)return null;try{let t=new FormData;t.append(`files`,e);let n={},r=re();r&&(n.Authorization=`Bearer ${r}`);let i=await(await fetch(`${W(a)}/chat/upload`,{method:`POST`,headers:n,body:t})).json();return i.ok&&Array.isArray(i.data)&&i.data.length>0?i.data[0].path:null}catch{return null}},[a]),Y=(0,Q.useCallback)(async e=>{for(let t of e){if(a)try{let e=await G.get(`${W(a)}/files/resolve?name=${encodeURIComponent(t.name)}`);if(e.matches.length===1){let t=C.current;V(t+(t.length>0&&!t.endsWith(` `)?` `:``)+`@${e.matches[0].path} `);continue}if(e.matches.length>1){h?.(e.matches);continue}}catch{}if(!Yn(t)){let e=C.current;V(e+(e.length>0&&!e.endsWith(` `)?` `:``)+t.name);continue}let e=ae(),n=Jn(t),r=n?URL.createObjectURL(t):void 0,i={id:e,name:t.name,file:t,isImage:n,previewUrl:r,status:`uploading`};D(e=>[...e,i]),J(t).then(t=>{D(n=>n.map(n=>n.id===e?{...n,serverPath:t??void 0,status:t?`ready`:`error`}:n))})}(F.current??P.current)?.focus()},[J,V,a,h]),X=(0,Q.useCallback)(e=>{D(t=>{let n=t.find(t=>t.id===e);return n?.previewUrl&&URL.revokeObjectURL(n.previewUrl),t.filter(t=>t.id!==e)})},[]),oe=(0,Q.useCallback)(()=>{let n=C.current.trim(),r=E.filter(e=>e.status===`ready`);if(!n&&r.length===0){j(!1);return}o?.(!1,``),z.current=!1,l?.(!1,``),B.current=!1,U.isListening&&U.stop(),e(n,r,t?M:void 0),V(``);for(let e of E)e.previewUrl&&URL.revokeObjectURL(e.previewUrl);D([]),j(!1),N(`next`),te.current&&(P.current&&(P.current.style.height=`auto`),F.current&&(F.current.style.height=`auto`))},[E,e,o,l,t,M,V]),ce=(0,Q.useCallback)(()=>{if(!r){if(E.some(e=>e.status===`uploading`)){(C.current.trim()||E.some(e=>e.status!==`error`))&&j(!0);return}oe()}},[E,r,oe]);(0,Q.useEffect)(()=>{A&&(E.some(e=>e.status===`uploading`)||oe())},[A,E,oe]);let le=(0,Q.useCallback)(e=>{if(e.key===`Enter`&&!e.shiftKey){e.preventDefault(),ce();return}if(e.shiftKey&&e.key===`Tab`){e.preventDefault();let t=[`default`,`acceptEdits`,`plan`,`bypassPermissions`],n=t[(t.indexOf(y??`bypassPermissions`)+1)%t.length];b?.(n)}},[ce,y,b]),ue=(0,Q.useCallback)((e,t)=>{let n=e.slice(0,t),r=n.includes(`/`),i=n.includes(`@`);if(!r&&!i){z.current&&=(o?.(!1,``),!1),B.current&&=(l?.(!1,``),!1);return}if(r){let e=n.match(/(?:^|\s)\/(\S*)$/);if(e&&L.current.length>0){let t=e[1]??``;o?.(!0,t),z.current=!0,B.current&&=(l?.(!1,``),!1);return}}if(i){let e=n.match(/@(\S*)$/);if(e&&ee.current.length>0){l?.(!0,e[1]??``),B.current=!0,z.current&&=(o?.(!1,``),!1);return}}z.current&&=(o?.(!1,``),!1),B.current&&=(l?.(!1,``),!1)},[o,l]),de=(0,Q.useCallback)(e=>{let t=e.target,n=t.value;C.current=n;let r=t===P.current?F.current:P.current;r&&(r.value=n),T(n.trim().length>0),ue(n,t.selectionStart),te.current&&(R.current&&cancelAnimationFrame(R.current),R.current=requestAnimationFrame(()=>{R.current=0,t.style.height=`auto`,t.style.height=Math.min(t.scrollHeight,t===F.current?80:160)+`px`}))},[ue]),fe=(0,Q.useCallback)(e=>{let t=e.clipboardData?.items;if(!t)return;let n=[];for(let e of t)if(e.kind===`file`){let t=e.getAsFile();t&&n.push(t)}n.length>0&&(e.preventDefault(),Y(n))},[Y]),pe=(0,Q.useCallback)(e=>{e.preventDefault();let t=e.dataTransfer.getData(`application/x-ppm-path`);if(t){let e=C.current;V(e+(e.length>0&&!e.endsWith(` `)?` `:``)+`@${t} `),H()?.focus();return}let n=Array.from(e.dataTransfer.files);n.length>0&&Y(n)},[Y,V,H]),me=(0,Q.useCallback)(e=>{e.preventDefault()},[]),he=(0,Q.useCallback)(()=>{I.current?.click()},[]),ge=(0,Q.useCallback)(e=>{let t=Array.from(e.target.files??[]);t.length>0&&Y(t),e.target.value=``},[Y]),_e=w||E.some(e=>e.status!==`error`),ve=t&&!_e;return(0,$.jsxs)(`div`,{className:`p-2 md:p-3 bg-background`,children:[(0,$.jsxs)(`div`,{className:`border border-border rounded-xl md:rounded-2xl bg-surface shadow-sm cursor-text`,onClick:e=>{r||e.target instanceof HTMLTextAreaElement||H()?.focus()},children:[(0,$.jsx)(Zn,{attachments:E,onRemove:X}),(0,$.jsxs)(`div`,{className:`flex items-center gap-1 px-2 pt-2 md:hidden relative`,children:[(0,$.jsx)(rr,{mode:y??`bypassPermissions`,onClick:()=>k(e=>!e)}),(0,$.jsx)(tr,{value:y??`bypassPermissions`,onChange:e=>b?.(e),open:O,onOpenChange:k}),S&&a&&(0,$.jsx)(v,{value:x??`claude`,onChange:S,projectName:a}),t&&(0,$.jsx)(ar,{value:M,onChange:N})]}),(0,$.jsxs)(`div`,{className:`flex items-end gap-1 md:hidden px-2 py-2`,children:[(0,$.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),he()},disabled:r,className:`flex items-center justify-center size-7 shrink-0 rounded-full text-text-subtle hover:text-text-primary transition-colors disabled:opacity-50`,"aria-label":`Attach file`,children:(0,$.jsx)(ot,{className:`size-4`})}),(0,$.jsx)(`textarea`,{ref:F,defaultValue:g??``,onChange:de,onKeyDown:le,onPaste:fe,onDrop:pe,onDragOver:me,placeholder:t?`Follow-up...`:`Ask anything...`,disabled:r,rows:1,className:`flex-1 resize-none bg-transparent py-1.5 text-sm text-foreground placeholder:text-text-subtle focus:outline-none disabled:opacity-50 max-h-20 [field-sizing:content]`}),U.supported&&(0,$.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),ie()},disabled:r,className:`flex items-center justify-center size-7 shrink-0 rounded-full transition-colors disabled:opacity-50 ${U.isListening?`bg-red-600 text-white animate-pulse`:`text-text-subtle hover:text-text-primary`}`,"aria-label":U.isListening?`Stop voice input`:`Start voice input`,children:U.isListening?(0,$.jsx)(it,{className:`size-4`}):(0,$.jsx)(Ne,{className:`size-4`})}),ve?(0,$.jsx)(`button`,{onClick:e=>{e.stopPropagation(),n?.()},className:`flex items-center justify-center size-7 shrink-0 rounded-full bg-red-600 text-white hover:bg-red-500 transition-colors`,"aria-label":`Stop`,children:(0,$.jsx)(Ke,{className:`size-3`})}):(0,$.jsx)(`button`,{onClick:e=>{e.stopPropagation(),A?j(!1):ce()},disabled:r||!_e,className:`flex items-center justify-center size-7 shrink-0 rounded-full bg-primary text-primary-foreground hover:bg-primary/90 disabled:opacity-30 transition-colors`,"aria-label":A?`Cancel queued send`:`Send`,children:A?(0,$.jsx)(Z,{className:`size-3.5 animate-spin`}):(0,$.jsx)(i,{className:`size-3.5`})})]}),(0,$.jsxs)(`div`,{className:`hidden md:block`,children:[(0,$.jsx)(`textarea`,{ref:P,defaultValue:g??``,onChange:de,onKeyDown:le,onPaste:fe,onDrop:pe,onDragOver:me,placeholder:t?`Follow-up or Stop...`:`Ask anything...`,disabled:r,rows:1,className:`w-full resize-none bg-transparent px-4 pt-3 pb-1 text-sm text-foreground placeholder:text-text-subtle focus:outline-none disabled:opacity-50 max-h-40 [field-sizing:content]`}),(0,$.jsxs)(`div`,{className:`flex items-center justify-between px-3 pb-2`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,$.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),he()},disabled:r,className:`flex items-center justify-center size-8 rounded-full text-text-subtle hover:text-text-primary hover:bg-surface-elevated transition-colors disabled:opacity-50`,"aria-label":`Attach file`,children:(0,$.jsx)(ot,{className:`size-4`})}),(0,$.jsxs)(`div`,{className:`relative`,children:[(0,$.jsx)(rr,{mode:y??`bypassPermissions`,onClick:()=>k(e=>!e)}),(0,$.jsx)(tr,{value:y??`bypassPermissions`,onChange:e=>b?.(e),open:O,onOpenChange:k})]}),S&&a&&(0,$.jsx)(v,{value:x??`claude`,onChange:S,projectName:a}),t&&(0,$.jsx)(ar,{value:M,onChange:N})]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-1`,children:[U.supported&&(0,$.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),ie()},disabled:r,className:`flex items-center justify-center size-8 rounded-full transition-colors disabled:opacity-50 ${U.isListening?`bg-red-600 text-white animate-pulse`:`text-text-subtle hover:text-text-primary hover:bg-surface-elevated`}`,"aria-label":U.isListening?`Stop voice input`:`Start voice input`,children:U.isListening?(0,$.jsx)(it,{className:`size-4`}):(0,$.jsx)(Ne,{className:`size-4`})}),ve?(0,$.jsx)(`button`,{onClick:e=>{e.stopPropagation(),n?.()},className:`flex items-center justify-center size-8 rounded-full bg-red-600 text-white hover:bg-red-500 transition-colors`,"aria-label":`Stop response`,children:(0,$.jsx)(Ke,{className:`size-3.5`})}):(0,$.jsx)(`button`,{onClick:e=>{e.stopPropagation(),A?j(!1):ce()},disabled:r||!_e,className:`flex items-center justify-center size-8 rounded-full bg-primary text-primary-foreground hover:bg-primary/90 disabled:opacity-30 disabled:cursor-not-allowed transition-colors`,"aria-label":A?`Cancel queued send`:`Send message`,children:A?(0,$.jsx)(Z,{className:`size-4 animate-spin`}):(0,$.jsx)(i,{className:`size-4`})})]})]})]})]}),(0,$.jsx)(`input`,{ref:I,type:`file`,multiple:!0,className:`hidden`,onChange:ge})]})});function rr({mode:e,onClick:t}){let n=er(e),r=$n(e);return(0,$.jsxs)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),t()},className:`inline-flex items-center gap-1 px-2 py-1 rounded-md text-[11px] text-text-subtle hover:text-text-primary hover:bg-surface-elevated transition-colors border border-transparent hover:border-border`,"aria-label":`Permission mode: ${r}`,children:[(0,$.jsx)(n,{className:`size-3`}),(0,$.jsx)(`span`,{className:`max-w-[100px] truncate`,children:r})]})}var ir=[{value:`now`,label:`Interrupt`,Icon:ft},{value:`next`,label:`Queue`,Icon:tt},{value:`later`,label:`Later`,Icon:P}];function ar({value:e,onChange:t}){let n=(0,Q.useCallback)(()=>{let n=[`next`,`later`,`now`];t(n[(n.indexOf(e)+1)%n.length])},[e,t]),r=ir.find(t=>t.value===e)??ir[1],i=r.Icon;return(0,$.jsxs)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),n()},className:`inline-flex items-center gap-1 px-2 py-1 rounded-md text-[11px] text-text-subtle hover:text-text-primary hover:bg-surface-elevated transition-colors border border-transparent hover:border-border`,"aria-label":`Message priority: ${r.label}`,title:`Priority: ${r.label} (click to cycle)`,children:[(0,$.jsx)(i,{className:`size-3`}),(0,$.jsx)(`span`,{children:r.label})]})}function or(e,t){if(e===t)return 0;if(e.length===0)return t.length;if(t.length===0)return e.length;let n=Array.from({length:t.length+1},(e,t)=>t),r=Array(t.length+1);for(let i=1;i<=e.length;i++){r[0]=i;for(let a=1;a<=t.length;a++){let o=e[i-1]===t[a-1]?0:1;r[a]=Math.min(r[a-1]+1,n[a]+1,n[a-1]+o)}[n,r]=[r,n]}return n[t.length]}function sr(e,t){let n=e.toLowerCase(),r=t.toLowerCase();if(r.startsWith(n))return{rank:0,distance:0};if(r.includes(n))return{rank:1,distance:r.indexOf(n)};let i=Math.max(Math.floor(n.length*.4),2),a=or(n,r.slice(0,n.length+i));return a<=i?{rank:2,distance:a}:null}function cr(e,t,n=20,r=[]){if(!t)return e;t=t.slice(0,50);let i=new Set(r),a=[];for(let n of e){let e=[sr(t,n.name),sr(t,n.description)].filter(e=>e!==null).sort((e,t)=>e.rank-t.rank||e.distance-t.distance)[0];e&&a.push({item:n,rank:e.rank,distance:e.distance,recent:i.has(n.name)})}return a.sort((e,t)=>e.rank-t.rank||e.distance-t.distance||(e.recent===t.recent?0:e.recent?-1:1)||e.item.name.localeCompare(t.item.name)),a.slice(0,n).map(e=>e.item)}function lr({items:e,filter:t,onSelect:n,onClose:r,visible:i,recentNames:a=[],projectName:o}){let[s,c]=(0,Q.useState)(0),[l,u]=(0,Q.useState)(!1),d=(0,Q.useRef)(null),f=(0,Q.useMemo)(()=>new Set(a),[a]),p=(0,Q.useMemo)(()=>{if(t)return{items:cr(e,t,20,a),recentCount:0};if(a.length>0){let t=[],n=[];for(let r of e)f.has(r.name)?t.push(r):n.push(r);return t.sort((e,t)=>a.indexOf(e.name)-a.indexOf(t.name)),{items:[...t,...n],recentCount:t.length}}return{items:e,recentCount:0}},[e,t,a,f]),m=p.items,h=p.recentCount;(0,Q.useEffect)(()=>{c(0)},[t]),(0,Q.useEffect)(()=>{let e=d.current;e&&e.children[s]?.scrollIntoView({block:`nearest`})},[s]);let g=(0,Q.useCallback)(e=>{if(!i||m.length===0)return!1;switch(e.key){case`ArrowUp`:return e.preventDefault(),c(e=>e>0?e-1:m.length-1),!0;case`ArrowDown`:return e.preventDefault(),c(e=>e<m.length-1?e+1:0),!0;case`Enter`:case`Tab`:return e.preventDefault(),m[s]&&n(m[s]),!0;case`Escape`:return e.preventDefault(),r(),!0}return!1},[i,m,s,n,r]);(0,Q.useEffect)(()=>{if(!i)return;let e=e=>{g(e)&&e.stopPropagation()};return document.addEventListener(`keydown`,e,!0),()=>document.removeEventListener(`keydown`,e,!0)},[i,g]);let _=(0,Q.useCallback)(()=>{!o||l||(u(!0),G.del(`${W(o)}/chat/slash-items/cache`).then(()=>{window.dispatchEvent(new CustomEvent(`ppm:slash-items-refresh`))}).finally(()=>u(!1)))},[o,l]);return!i||m.length===0?null:(0,$.jsx)(`div`,{className:`max-h-52 overflow-y-auto border-b border-border bg-surface`,children:(0,$.jsx)(`div`,{ref:d,className:`py-1`,children:m.map((e,t)=>{let r=h>0&&t===0,i=h>0&&t===h;return(0,$.jsxs)(`div`,{children:[r&&(0,$.jsxs)(`div`,{className:`flex items-center justify-between px-3 pt-1 pb-0.5`,children:[(0,$.jsxs)(`span`,{className:`text-[10px] font-medium text-text-subtle uppercase tracking-wider flex items-center gap-1`,children:[(0,$.jsx)(P,{className:`size-3`}),`Recent`]}),o&&(0,$.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),_()},className:`text-text-subtle hover:text-text-primary transition-colors p-0.5 rounded`,title:`Refresh skill list`,"aria-label":`Refresh skill list`,children:(0,$.jsx)(U,{className:`size-3 ${l?`animate-spin`:``}`})})]}),i&&(0,$.jsx)(`div`,{className:`px-3 pt-1.5 pb-0.5`,children:(0,$.jsx)(`span`,{className:`text-[10px] font-medium text-text-subtle uppercase tracking-wider`,children:`All`})}),(0,$.jsxs)(`button`,{className:`flex items-start gap-3 w-full px-3 py-2 text-left transition-colors ${t===s?`bg-primary/10 text-primary`:`hover:bg-surface-hover text-text-primary`}`,onMouseEnter:()=>c(t),onClick:()=>n(e),children:[(0,$.jsx)(`span`,{className:`shrink-0 mt-0.5`,children:e.type===`builtin`?(0,$.jsx)(ft,{className:`size-4 text-emerald-500`}):e.type===`skill`?(0,$.jsx)(ne,{className:`size-4 text-amber-500`}):(0,$.jsx)(Ee,{className:`size-4 text-blue-500`})}),(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,$.jsxs)(`div`,{className:`flex items-baseline gap-2`,children:[(0,$.jsxs)(`span`,{className:`font-medium text-sm`,children:[`/`,e.name]}),e.argumentHint&&(0,$.jsx)(`span`,{className:`text-xs text-text-subtle`,children:e.argumentHint}),(0,$.jsx)(`span`,{className:`text-xs text-text-subtle capitalize ml-auto`,children:e.scope===`bundled`?`PPM`:e.scope===`user`?`global`:e.type})]}),e.description&&(0,$.jsx)(`p`,{className:`text-xs text-text-subtle mt-0.5 line-clamp-2`,children:e.description})]})]})]},`${e.type}-${e.name}`)})})})}function ur({items:e,filter:t,onSelect:n,onClose:r,visible:i}){let[a,o]=(0,Q.useState)(0),s=(0,Q.useRef)(null),c=(()=>{if(!t)return e.slice(0,50);let n=t.toLowerCase();return e.filter(e=>e.path.toLowerCase().includes(n)||e.name.toLowerCase().includes(n)).slice(0,50)})();(0,Q.useEffect)(()=>{o(0)},[t]),(0,Q.useEffect)(()=>{let e=s.current;e&&e.children[a]?.scrollIntoView({block:`nearest`})},[a]);let l=(0,Q.useCallback)(e=>{if(!i||c.length===0)return!1;switch(e.key){case`ArrowUp`:return e.preventDefault(),o(e=>e>0?e-1:c.length-1),!0;case`ArrowDown`:return e.preventDefault(),o(e=>e<c.length-1?e+1:0),!0;case`Enter`:case`Tab`:return e.preventDefault(),c[a]&&n(c[a]),!0;case`Escape`:return e.preventDefault(),r(),!0}return!1},[i,c,a,n,r]);return(0,Q.useEffect)(()=>{if(!i)return;let e=e=>{l(e)&&e.stopPropagation()};return document.addEventListener(`keydown`,e,!0),()=>document.removeEventListener(`keydown`,e,!0)},[i,l]),!i||c.length===0?null:(0,$.jsx)(`div`,{className:`max-h-52 overflow-y-auto border-b border-border bg-surface`,children:(0,$.jsx)(`div`,{ref:s,className:`py-1`,children:c.map((e,t)=>(0,$.jsxs)(`button`,{className:`flex items-center gap-2 w-full px-3 py-1.5 text-left transition-colors ${t===a?`bg-primary/10 text-primary`:`hover:bg-surface-hover text-text-primary`}`,onMouseEnter:()=>o(t),onClick:()=>n(e),children:[(0,$.jsx)(`span`,{className:`shrink-0`,children:e.type===`directory`?(0,$.jsx)(Ve,{className:`size-4 text-amber-500`}):(0,$.jsx)(Te,{className:`size-4 text-blue-400`})}),(0,$.jsx)(`span`,{className:`text-sm truncate`,children:e.path})]},e.path))})})}function dr({projectName:e,onTagsChanged:t}){let[n,r]=(0,Q.useState)([]),[i,a]=(0,Q.useState)(null),[o,s]=(0,Q.useState)(!0),[l,u]=(0,Q.useState)(null),[d,f]=(0,Q.useState)(``),[p,m]=(0,Q.useState)(``),[h,g]=(0,Q.useState)(``),[_,v]=(0,Q.useState)(`#22c55e`),[y,b]=(0,Q.useState)(!1),x=`${W(e)}/tags`,C=(0,Q.useCallback)(async()=>{try{let e=await G.get(x);r(e.tags),a(e.defaultTagId)}catch{}s(!1)},[x]);(0,Q.useEffect)(()=>{C()},[C]);let w=async()=>{if(h.trim())try{await G.post(x,{name:h.trim(),color:_}),g(``),b(!1),C(),t?.()}catch{}},T=async e=>{try{await G.patch(`${x}/${e}`,{name:d.trim()||void 0,color:p||void 0}),u(null),C(),t?.()}catch{}},E=async(e,n)=>{if(window.confirm(`Delete tag "${n}"? Sessions with this tag will become untagged.`))try{await G.del(`${x}/${e}`),C(),t?.()}catch{}},D=async e=>{let t=e===i?null:e;try{await G.patch(`${x}/default-tag`,{tagId:t}),a(t)}catch{}};return o?(0,$.jsx)(`p`,{className:`text-[11px] text-muted-foreground animate-pulse`,children:`Loading tags...`}):(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,$.jsx)(`h3`,{className:`text-xs font-medium text-muted-foreground`,children:`Session Tags`}),(0,$.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,$.jsx)(`button`,{onClick:async()=>{try{await G.post(`${x}/reset`,{}),C(),t?.()}catch{}},className:`p-1 rounded text-text-subtle hover:text-text-secondary`,title:`Reset to defaults`,children:(0,$.jsx)(we,{className:`size-3`})}),(0,$.jsx)(`button`,{onClick:()=>b(!y),className:`p-1 rounded text-primary hover:bg-primary/10`,title:`Add tag`,children:(0,$.jsx)(V,{className:`size-3.5`})})]})]}),y&&(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5 px-1`,children:[(0,$.jsx)(`input`,{type:`color`,value:_,onChange:e=>v(e.target.value),className:`size-6 rounded cursor-pointer border-0 p-0`}),(0,$.jsx)(`input`,{value:h,onChange:e=>g(e.target.value),onKeyDown:e=>{e.key===`Enter`&&w(),e.key===`Escape`&&b(!1)},placeholder:`Tag name`,className:`flex-1 min-w-0 bg-surface-elevated text-[11px] text-text-primary px-2 py-1 rounded border border-border outline-none focus:border-primary`,autoFocus:!0}),(0,$.jsx)(`button`,{onClick:w,className:`p-1 text-green-500 hover:text-green-400`,children:(0,$.jsx)(S,{className:`size-3.5`})}),(0,$.jsx)(`button`,{onClick:()=>b(!1),className:`p-1 text-text-subtle hover:text-text-secondary`,children:(0,$.jsx)(H,{className:`size-3.5`})})]}),(0,$.jsxs)(`div`,{className:`space-y-0.5`,children:[n.map(e=>(0,$.jsx)(`div`,{className:`flex items-center gap-1.5 px-1 py-1 rounded hover:bg-surface-elevated group`,children:l===e.id?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`input`,{type:`color`,value:p,onChange:e=>m(e.target.value),className:`size-5 rounded cursor-pointer border-0 p-0`}),(0,$.jsx)(`input`,{value:d,onChange:e=>f(e.target.value),onKeyDown:t=>{t.key===`Enter`&&T(e.id),t.key===`Escape`&&u(null)},className:`flex-1 min-w-0 bg-surface-elevated text-[11px] px-1.5 py-0.5 rounded border border-border outline-none focus:border-primary`,autoFocus:!0}),(0,$.jsx)(`button`,{onClick:()=>T(e.id),className:`p-0.5 text-green-500`,children:(0,$.jsx)(S,{className:`size-3`})}),(0,$.jsx)(`button`,{onClick:()=>u(null),className:`p-0.5 text-text-subtle`,children:(0,$.jsx)(H,{className:`size-3`})})]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`span`,{className:`size-3 rounded-full shrink-0`,style:{backgroundColor:e.color}}),(0,$.jsx)(`span`,{className:`flex-1 text-[11px] text-text-primary truncate`,children:e.name}),(0,$.jsx)(`button`,{onClick:()=>D(e.id),className:`px-1.5 py-0.5 rounded text-[9px] font-medium transition-colors ${e.id===i?`bg-primary/15 text-primary border border-primary/30`:`text-text-subtle border border-transparent can-hover:opacity-0 can-hover:group-hover:opacity-100 hover:bg-surface-elevated hover:border-border`}`,title:e.id===i?`Default tag (click to unset)`:`Set as default for new sessions`,children:e.id===i?`Default`:`Set default`}),(0,$.jsx)(`button`,{onClick:()=>{u(e.id),f(e.name),m(e.color)},className:`p-0.5 rounded text-text-subtle hover:text-text-secondary can-hover:opacity-0 can-hover:group-hover:opacity-100`,children:(0,$.jsx)(c,{className:`size-3`})}),(0,$.jsx)(`button`,{onClick:()=>E(e.id,e.name),className:`p-0.5 rounded text-text-subtle hover:text-red-400 can-hover:opacity-0 can-hover:group-hover:opacity-100`,children:(0,$.jsx)(te,{className:`size-3`})})]})},e.id)),n.length===0&&(0,$.jsx)(`p`,{className:`text-[11px] text-muted-foreground py-2 text-center`,children:`No tags. Click + to create one.`})]})]})}var fr=`ppm-hienlh`;function pr({open:e,onOpenChange:t,onSuccess:n}){let[r,i]=(0,Q.useState)(``),[a,o]=(0,Q.useState)(``),[s,c]=(0,Q.useState)(!1),[l,u]=(0,Q.useState)(null),[d,f]=(0,Q.useState)(null),[p,m]=(0,Q.useState)(``),[h,g]=(0,Q.useState)(!1),[_,v]=(0,Q.useState)(`idle`);function y(){f(null),m(``),v(`idle`),u(null)}function b(){t(!1),y(),i(``),o(``),u(null)}async function S(){g(!0),u(null);try{let{url:e,state:t}=await be();f(t),v(`waiting`),window.open(e,`_blank`)}catch(e){u(e.message)}g(!1)}async function C(){if(!(!p.trim()||!d)){g(!0),u(null);try{let e=p.trim();e.includes(`#`)&&(e=e.split(`#`)[0]??e),await fe(e,d),b(),n(`Account connected via OAuth!`)}catch(e){u(e.message)}g(!1)}}async function w(){if(r.trim()){c(!0),u(null);try{await ye({apiKey:r.trim(),label:a.trim()||void 0}),b(),n(`Account added!`)}catch(e){u(e.message)}c(!1)}}let T=r.trim()?r.trim().startsWith(`sk-ant-oat`)?`OAuth token (Claude Max/Pro)`:r.trim().startsWith(`sk-ant-api`)?`API key`:`Unknown format`:``;return(0,$.jsx)(k,{open:e,onOpenChange:e=>{e||b()},children:(0,$.jsxs)(j,{className:`sm:max-w-md`,children:[(0,$.jsxs)(A,{children:[(0,$.jsx)(M,{className:`text-sm`,children:`Add Claude Account`}),(0,$.jsx)(D,{className:`text-xs leading-relaxed`,children:`Connect via OAuth (recommended) or paste a token manually.`})]}),(0,$.jsxs)(`div`,{className:`space-y-3`,children:[(0,$.jsxs)(`div`,{className:`rounded-md border p-3 space-y-2`,children:[(0,$.jsx)(`p`,{className:`text-[11px] font-medium`,children:`Recommended: Login with Claude`}),_===`idle`?(0,$.jsx)(O,{size:`sm`,className:`w-full h-8 text-xs`,onClick:S,disabled:h,children:h?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Z,{className:`size-3 animate-spin mr-1`}),` Opening...`]}):`Login with Claude`}):(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsx)(`p`,{className:`text-[10px] text-muted-foreground`,children:`Authorize in the opened tab, then paste the code:`}),(0,$.jsx)(N,{placeholder:`Paste code here...`,value:p,onChange:e=>m(e.target.value),className:`text-xs h-8 font-mono`,autoFocus:!0}),(0,$.jsxs)(`div`,{className:`flex gap-1.5`,children:[(0,$.jsx)(O,{size:`sm`,className:`flex-1 h-7 text-xs`,onClick:C,disabled:!p.trim()||h,children:h?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Z,{className:`size-3 animate-spin mr-1`}),` Connecting...`]}):`Connect`}),(0,$.jsx)(O,{size:`sm`,variant:`ghost`,className:`h-7 text-xs`,onClick:y,children:`Cancel`})]})]})]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(`div`,{className:`flex-1 border-t`}),(0,$.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:`or paste token`}),(0,$.jsx)(`div`,{className:`flex-1 border-t`})]}),(0,$.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,$.jsx)(x,{htmlFor:`add-token`,className:`text-xs`,children:`Token`}),(0,$.jsx)(N,{id:`add-token`,type:`password`,placeholder:`sk-ant-...`,value:r,onChange:e=>i(e.target.value),className:`text-xs h-8 font-mono`}),T&&(0,$.jsxs)(`p`,{className:`text-[10px] text-muted-foreground`,children:[`Detected: `,T]})]}),(0,$.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,$.jsx)(x,{htmlFor:`add-label`,className:`text-xs`,children:`Label (optional)`}),(0,$.jsx)(N,{id:`add-label`,placeholder:`e.g. Personal, Work`,value:a,onChange:e=>o(e.target.value),className:`text-xs h-8`})]})]}),l&&(0,$.jsx)(`div`,{className:`text-[11px] p-2 rounded bg-red-500/10 text-red-600`,children:l}),(0,$.jsxs)(E,{children:[(0,$.jsx)(O,{size:`sm`,variant:`outline`,className:`text-xs h-7`,onClick:b,children:`Cancel`}),(0,$.jsx)(O,{size:`sm`,className:`text-xs h-7`,onClick:w,disabled:!r.trim()||s,children:s?`Adding...`:`Add Token`})]})]})})}function mr({open:e,onOpenChange:t,accounts:n,preselectId:r,onMessage:i}){let a=n.filter(e=>e.hasRefreshToken),[o,s]=(0,Q.useState)(new Set),[c,u]=(0,Q.useState)(``),[d,f]=(0,Q.useState)(!1),[p,m]=(0,Q.useState)(!1),[h,g]=(0,Q.useState)(!1),[_,v]=(0,Q.useState)(!1);e&&!_&&(s(r?new Set([r]):new Set(a.map(e=>e.id))),v(!0)),!e&&_&&v(!1);function y(){t(!1),u(``),f(!1),m(!1)}async function b(e){if(o.size===0)return;g(!0);let t=c.trim()||fr;try{let n={"Content-Type":`application/json`},r=re();r&&(n.Authorization=`Bearer ${r}`);let a=await fetch(`/api/accounts/export`,{method:`POST`,headers:n,body:JSON.stringify({password:t,accountIds:[...o],includeRefreshToken:d,refreshBeforeExport:p})});if(!a.ok){let e=await a.json();throw Error(e.error??`Export failed: ${a.status}`)}let s=await a.text();if(e)try{await navigator.clipboard.writeText(s),i?.(`Backup copied to clipboard!`)}catch{gr(s),i?.(`Backup downloaded.`)}else gr(s),i?.(`Backup downloaded.`);y()}catch{}g(!1)}let S=o.size>0&&!h;return(0,$.jsx)(k,{open:e,onOpenChange:e=>{e||y()},children:(0,$.jsxs)(j,{className:`sm:max-w-md`,children:[(0,$.jsxs)(A,{children:[(0,$.jsxs)(M,{className:`text-sm flex items-center gap-1.5`,children:[(0,$.jsx)(l,{className:`size-3.5`}),` Export Accounts`]}),(0,$.jsx)(D,{className:`text-xs`,children:`Select accounts and set a password to protect the backup.`})]}),(0,$.jsxs)(`div`,{className:`space-y-3`,children:[(0,$.jsxs)(`div`,{className:`space-y-1`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between mb-1`,children:[(0,$.jsx)(`p`,{className:`text-[11px] font-medium text-muted-foreground`,children:`Accounts to export`}),(0,$.jsx)(`button`,{className:`text-[10px] text-primary hover:underline cursor-pointer`,onClick:()=>s(o.size===a.length?new Set:new Set(a.map(e=>e.id))),children:o.size===a.length?`Deselect all`:`Select all`})]}),a.length===0?(0,$.jsx)(`p`,{className:`text-[10px] text-muted-foreground p-2 border rounded`,children:`No exportable accounts.`}):(0,$.jsx)(`div`,{className:`max-h-36 overflow-y-auto space-y-1 border rounded p-2`,children:a.map(e=>(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(`input`,{type:`checkbox`,id:`exp-${e.id}`,checked:o.has(e.id),onChange:t=>{let n=new Set(o);t.target.checked?n.add(e.id):n.delete(e.id),s(n)},className:`size-3.5 accent-primary cursor-pointer`}),(0,$.jsx)(`label`,{htmlFor:`exp-${e.id}`,className:`text-xs cursor-pointer truncate`,children:e.label??e.email??e.id.slice(0,8)})]},e.id))})]}),(0,$.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,$.jsxs)(x,{className:`text-xs`,children:[`Password `,(0,$.jsx)(`span`,{className:`text-muted-foreground font-normal`,children:`(optional)`})]}),(0,$.jsx)(N,{type:`password`,placeholder:`Leave empty for default`,value:c,onChange:e=>u(e.target.value),className:`text-xs h-8`,autoComplete:`new-password`})]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(`input`,{type:`checkbox`,id:`exp-full`,checked:d,onChange:e=>f(e.target.checked),className:`size-3.5 accent-primary cursor-pointer`}),(0,$.jsx)(`label`,{htmlFor:`exp-full`,className:`text-[11px] cursor-pointer`,children:`Include refresh tokens (full transfer)`})]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(`input`,{type:`checkbox`,id:`exp-refresh`,checked:p,onChange:e=>m(e.target.checked),className:`size-3.5 accent-primary cursor-pointer`}),(0,$.jsx)(`label`,{htmlFor:`exp-refresh`,className:`text-[11px] cursor-pointer`,children:`Refresh tokens before export`})]}),d?(0,$.jsxs)(`div`,{className:`rounded-md border border-red-500/30 bg-red-500/5 p-2.5`,children:[(0,$.jsx)(`p`,{className:`text-[10px] font-medium text-red-600`,children:`Full transfer — source accounts will expire`}),(0,$.jsx)(`p`,{className:`text-[10px] text-muted-foreground`,children:`Refresh tokens included. Source machine expires in ~1h after target refreshes.`})]}):p?(0,$.jsx)(`div`,{className:`rounded-md border border-amber-500/30 bg-amber-500/5 p-2.5`,children:(0,$.jsx)(`p`,{className:`text-[10px] font-medium text-amber-600`,children:`Refresh before export — invalidates previous shares`})}):(0,$.jsx)(`div`,{className:`rounded-md border border-green-500/30 bg-green-500/5 p-2.5`,children:(0,$.jsx)(`p`,{className:`text-[10px] font-medium text-green-600`,children:`Share current token (safe)`})}),(0,$.jsx)(`p`,{className:`text-[10px] text-muted-foreground`,children:`Encrypted with AES-256-GCM + scrypt.`})]}),(0,$.jsxs)(E,{className:`gap-1.5 flex-col sm:flex-row`,children:[(0,$.jsx)(O,{size:`sm`,variant:`outline`,className:`text-xs h-7 cursor-pointer`,onClick:y,children:`Cancel`}),(0,$.jsxs)(O,{size:`sm`,variant:`outline`,className:`text-xs h-7 cursor-pointer`,disabled:!S,onClick:()=>b(!0),children:[(0,$.jsx)(Ie,{className:`size-3 mr-1`}),` Copy`]}),(0,$.jsx)(O,{size:`sm`,className:`text-xs h-7 cursor-pointer`,disabled:!S,onClick:()=>b(!1),children:h?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Z,{className:`size-3 animate-spin mr-1`}),` Exporting...`]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(z,{className:`size-3 mr-1`}),` Download`]})})]})]})})}function hr({open:e,onOpenChange:t,onSuccess:n}){let[r,i]=(0,Q.useState)(``),[a,o]=(0,Q.useState)(``),[s,c]=(0,Q.useState)(!1),[u,d]=(0,Q.useState)(null);function f(){t(!1),i(``),o(``),d(null)}async function p(){if(r.trim()){c(!0),d(null);try{let e=await ge({data:r.trim(),password:a.trim()||fr});f(),n(`Imported ${e.imported} account(s)`)}catch(e){d(e.message||`Import failed`)}c(!1)}}return(0,$.jsx)(k,{open:e,onOpenChange:e=>{e||f()},children:(0,$.jsxs)(j,{className:`sm:max-w-md`,children:[(0,$.jsxs)(A,{children:[(0,$.jsxs)(M,{className:`text-sm flex items-center gap-1.5`,children:[(0,$.jsx)(l,{className:`size-3.5`}),` Import Accounts`]}),(0,$.jsx)(D,{className:`text-xs`,children:`Paste backup data and enter the export password. Imported accounts are temporary (~1h).`})]}),(0,$.jsxs)(`div`,{className:`space-y-3`,children:[(0,$.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,$.jsx)(x,{className:`text-xs`,children:`Backup data`}),(0,$.jsx)(`textarea`,{value:r,onChange:e=>i(e.target.value),placeholder:`Paste backup JSON here...`,rows:4,className:`w-full text-xs p-2 rounded border border-border bg-background font-mono resize-none focus:outline-none focus:ring-1 focus:ring-primary`})]}),(0,$.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,$.jsxs)(x,{className:`text-xs`,children:[`Password `,(0,$.jsx)(`span`,{className:`text-muted-foreground font-normal`,children:`(optional)`})]}),(0,$.jsx)(N,{type:`password`,placeholder:`Leave empty for default`,value:a,onChange:e=>o(e.target.value),className:`text-xs h-8`,autoComplete:`current-password`})]})]}),u&&(0,$.jsx)(`div`,{className:`text-[11px] p-2 rounded bg-red-500/10 text-red-600`,children:u}),(0,$.jsxs)(E,{children:[(0,$.jsx)(O,{size:`sm`,variant:`outline`,className:`text-xs h-7 cursor-pointer`,onClick:f,children:`Cancel`}),(0,$.jsx)(O,{size:`sm`,className:`text-xs h-7 cursor-pointer`,disabled:!r.trim()||s,onClick:p,children:s?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Z,{className:`size-3 animate-spin mr-1`}),` Importing...`]}):`Import`})]})]})})}function gr(e){let t=new Blob([e],{type:`application/json`}),n=document.createElement(`a`);n.href=URL.createObjectURL(t),n.download=`ppm-accounts-backup.json`,n.click(),URL.revokeObjectURL(n.href)}var _r=typeof window<`u`?window.matchMedia(`(min-width: 768px)`):null;function vr(e){return _r?.addEventListener(`change`,e),()=>_r?.removeEventListener(`change`,e)}function yr(){return _r?.matches??!0}function br(){let[e,t]=(0,Q.useState)(null),[n,r]=(0,Q.useState)(!0);return(0,Q.useEffect)(()=>{r(!0),he().then(t).finally(()=>r(!1))},[]),n?(0,$.jsx)(`p`,{className:`text-xs text-text-subtle py-4 text-center`,children:`Loading...`}):e?(0,$.jsxs)(`div`,{className:`space-y-4`,children:[(0,$.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,$.jsx)(`label`,{className:`text-xs font-medium text-text-primary`,children:`Rotation Strategy`}),(0,$.jsxs)(f,{value:e.strategy,onValueChange:async e=>{t(await de({strategy:e}))},children:[(0,$.jsx)(y,{className:`w-full h-9 text-xs`,children:(0,$.jsx)(s,{})}),(0,$.jsxs)(o,{children:[(0,$.jsx)(g,{value:`round-robin`,children:`Round-robin`}),(0,$.jsx)(g,{value:`fill-first`,children:`Fill-first`}),(0,$.jsx)(g,{value:`lowest-usage`,children:`Lowest usage`})]})]}),(0,$.jsxs)(`p`,{className:`text-[10px] text-text-subtle`,children:[e.strategy===`round-robin`&&`Cycles through accounts evenly`,e.strategy===`fill-first`&&`Uses one account until its limit, then moves on`,e.strategy===`lowest-usage`&&`Picks the account with the lowest current usage`]})]}),(0,$.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,$.jsx)(`label`,{className:`text-xs font-medium text-text-primary`,children:`Max Retry`}),(0,$.jsx)(`input`,{type:`number`,min:0,value:e.maxRetry,className:`w-full h-9 text-xs border rounded-md px-3 bg-background`,onChange:async e=>{let n=parseInt(e.target.value,10);!isNaN(n)&&n>=0&&t(await de({maxRetry:n}))}}),(0,$.jsx)(`p`,{className:`text-[10px] text-text-subtle`,children:`How many accounts to try on failure. 0 = try all available accounts.`})]}),(0,$.jsxs)(`div`,{className:`flex items-center justify-between text-xs border-t border-border pt-3`,children:[(0,$.jsx)(`span`,{className:`text-text-subtle`,children:`Active accounts`}),(0,$.jsx)(`span`,{className:`font-medium text-text-primary`,children:e.activeCount})]})]}):(0,$.jsx)(`p`,{className:`text-xs text-text-subtle py-4 text-center`,children:`Failed to load settings`})}function xr({open:e,onOpenChange:t}){let n=(0,Q.useSyncExternalStore)(vr,yr);return e?n?(0,$.jsx)(k,{open:e,onOpenChange:t,children:(0,$.jsxs)(j,{className:`sm:max-w-sm`,children:[(0,$.jsx)(A,{children:(0,$.jsxs)(M,{className:`text-sm flex items-center gap-2`,children:[(0,$.jsx)(Se,{className:`size-4`}),` Rotation & Retry`]})}),(0,$.jsx)(br,{})]})}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`div`,{className:`fixed inset-0 z-50 transition-opacity duration-200 opacity-100`,onClick:()=>t(!1),style:{backgroundColor:`rgba(0,0,0,0.5)`}}),(0,$.jsxs)(`div`,{className:q(`fixed bottom-0 left-0 right-0 z-50 bg-background rounded-t-2xl border-t border-border shadow-2xl`,`transition-transform duration-300 ease-out max-h-[85vh] overflow-y-auto`,`translate-y-0`),children:[(0,$.jsx)(`div`,{className:`flex justify-center pt-3 pb-1`,children:(0,$.jsx)(`div`,{className:`w-10 h-1 rounded-full bg-border`})}),(0,$.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-2 border-b border-border`,children:[(0,$.jsxs)(`span`,{className:`text-sm font-semibold flex items-center gap-2`,children:[(0,$.jsx)(Se,{className:`size-4`}),` Rotation & Retry`]}),(0,$.jsx)(`button`,{onClick:()=>t(!1),className:`flex items-center justify-center size-7 rounded-md hover:bg-surface-elevated transition-colors`,children:(0,$.jsx)(H,{className:`size-4`})})]}),(0,$.jsx)(`div`,{className:`px-4 py-4 pb-8`,children:(0,$.jsx)(br,{})})]})]}):null}var Sr=[`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`,`Sun`],Cr=Array.from({length:24},(e,t)=>t);function wr(e,t){let n=Array.from({length:7},()=>Array.from({length:24},()=>({sum:0,count:0,avg:0})));for(let r of e){let e=t===`5h`?r.five_hour_util:r.weekly_util;if(e==null)continue;let i=new Date(r.recorded_at+(r.recorded_at.endsWith(`Z`)?``:`Z`)),a=(i.getDay()+6)%7,o=i.getHours();n[a][o].sum+=e,n[a][o].count+=1}for(let e of n)for(let t of e)t.avg=t.count>0?t.sum/t.count:0;return n}function Tr(e){return e.map(e=>{let t=e.reduce((e,t)=>e+t.sum,0),n=e.reduce((e,t)=>e+t.count,0);return n>0?t/n:0})}function Er(e){return Cr.map(t=>{let n=0,r=0;for(let i of e)n+=i[t].sum,r+=i[t].count;return r>0?n/r:0})}function Dr(e){return e===0?`bg-surface-elevated`:e<.3?`bg-green-500/30`:e<.5?`bg-green-500/60`:e<.7?`bg-amber-500/50`:e<.9?`bg-amber-500/80`:`bg-red-500/80`}function Or(e){return e<.3?`bg-green-500`:e<.7?`bg-amber-500`:`bg-red-500`}function kr({accountId:e}){let[t,n]=(0,Q.useState)(null),[r,i]=(0,Q.useState)(!0),[a,o]=(0,Q.useState)(`5h`);(0,Q.useEffect)(()=>{i(!0),ue(e).then(n).catch(()=>n([])).finally(()=>i(!1))},[e]);let s=(0,Q.useMemo)(()=>t?wr(t,a):null,[t,a]),c=(0,Q.useMemo)(()=>s?Tr(s):[],[s]),l=(0,Q.useMemo)(()=>s?Er(s):[],[s]),u=Math.max(...c,.01);if(Math.max(...l,.01),r)return(0,$.jsx)(`div`,{className:`flex items-center justify-center py-3`,children:(0,$.jsx)(Z,{className:`size-3 animate-spin text-text-subtle`})});if(!t||t.length===0)return(0,$.jsx)(`div`,{className:`text-[10px] text-text-subtle py-2 text-center`,children:`No usage history yet`});let d=t.length,f=new Set(t.map(e=>new Date(e.recorded_at+(e.recorded_at.endsWith(`Z`)?``:`Z`)).toDateString())).size;return(0,$.jsxs)(`div`,{className:`mt-2 space-y-2`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,$.jsx)(`span`,{className:`text-[10px] font-medium text-text-subtle`,children:`Usage Pattern (7d)`}),(0,$.jsxs)(`div`,{className:`flex gap-0.5 text-[9px]`,children:[(0,$.jsx)(`button`,{onClick:()=>o(`5h`),className:`px-1.5 py-0.5 rounded cursor-pointer transition-colors ${a===`5h`?`bg-primary/15 text-primary`:`text-text-subtle hover:text-text-secondary`}`,title:`5-hour rolling window limit — resets every 5 hours`,children:`5h`}),(0,$.jsx)(`button`,{onClick:()=>o(`weekly`),className:`px-1.5 py-0.5 rounded cursor-pointer transition-colors ${a===`weekly`?`bg-primary/15 text-primary`:`text-text-subtle hover:text-text-secondary`}`,title:`Weekly limit — resets every 7 days`,children:`Wk`})]})]}),(0,$.jsxs)(`p`,{className:`text-[9px] text-text-subtle leading-tight`,children:[`Avg `,a===`5h`?`5-hour`:`weekly`,` limit usage over `,f,`d (`,d,` samples). Higher % = closer to rate limit. Hover cells for details.`]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`span`,{className:`text-[9px] text-text-subtle`,children:`Avg usage by day of week`}),(0,$.jsx)(`div`,{className:`flex flex-col gap-[2px] mt-0.5`,children:Sr.map((e,t)=>{let n=c[t]??0;return(0,$.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,$.jsx)(`span`,{className:`text-[8px] text-text-subtle w-5 shrink-0 text-right tabular-nums`,children:e}),(0,$.jsx)(`div`,{className:`flex-1 h-2.5 bg-surface-elevated rounded-sm overflow-hidden`,children:(0,$.jsx)(`div`,{className:`h-full rounded-sm transition-all ${Or(n)}`,style:{width:`${Math.round(n/u*100)}%`}})}),(0,$.jsxs)(`span`,{className:`text-[8px] text-text-subtle w-6 shrink-0 text-right tabular-nums`,children:[Math.round(n*100),`%`]})]},e)})})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`span`,{className:`text-[9px] text-text-subtle`,children:`Avg usage by hour (0h-23h)`}),(0,$.jsx)(`div`,{className:`flex gap-[1px] mt-0.5`,children:Cr.map(e=>{let t=l[e]??0;return(0,$.jsxs)(`div`,{className:`flex-1 flex flex-col items-center gap-[1px]`,children:[(0,$.jsx)(`div`,{className:`w-full aspect-square rounded-[2px] ${Dr(t)}`,title:`${e}:00 — avg ${Math.round(t*100)}% usage`}),e%6==0&&(0,$.jsx)(`span`,{className:`text-[7px] text-text-subtle tabular-nums`,children:e})]},e)})})]}),s&&(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`span`,{className:`text-[9px] text-text-subtle`,children:`Day x Hour heatmap`}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-[1px] mt-0.5`,children:[Sr.map((e,t)=>(0,$.jsxs)(`div`,{className:`flex items-center gap-[1px]`,children:[(0,$.jsx)(`span`,{className:`text-[7px] text-text-subtle w-4 shrink-0 text-right`,children:e.charAt(0)}),Cr.map(n=>{let r=s[t][n];return(0,$.jsx)(`div`,{className:`flex-1 aspect-square rounded-[1px] ${Dr(r.avg)}`,title:`${e} ${n}:00 — ${r.count>0?`avg ${Math.round(r.avg*100)}% (${r.count} samples)`:`no data`}`},n)})]},e)),(0,$.jsxs)(`div`,{className:`flex items-center gap-[1px]`,children:[(0,$.jsx)(`span`,{className:`w-4 shrink-0`}),Cr.map(e=>(0,$.jsx)(`div`,{className:`flex-1 text-center`,children:e%6==0&&(0,$.jsx)(`span`,{className:`text-[7px] text-text-subtle tabular-nums`,children:e})},e))]})]})]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[8px] text-text-subtle`,children:[(0,$.jsx)(`span`,{children:`Low`}),(0,$.jsxs)(`div`,{className:`flex gap-[2px]`,children:[(0,$.jsx)(`div`,{className:`size-2 rounded-[1px] bg-green-500/30`}),(0,$.jsx)(`div`,{className:`size-2 rounded-[1px] bg-green-500/60`}),(0,$.jsx)(`div`,{className:`size-2 rounded-[1px] bg-amber-500/50`}),(0,$.jsx)(`div`,{className:`size-2 rounded-[1px] bg-amber-500/80`}),(0,$.jsx)(`div`,{className:`size-2 rounded-[1px] bg-red-500/80`})]}),(0,$.jsx)(`span`,{children:`High`}),(0,$.jsx)(`span`,{className:`ml-1`,children:`|`}),(0,$.jsx)(`div`,{className:`size-2 rounded-[1px] bg-surface-elevated border border-border/30`}),(0,$.jsx)(`span`,{children:`No data`})]})]})}function Ar(e){return e>=90?`text-red-500`:e>=70?`text-amber-500`:`text-green-500`}function jr(e){return e>=90?`bg-red-500`:e>=70?`bg-amber-500`:`bg-green-500`}function Mr(e){if(!e)return null;let t=null;if(e.resetsInMinutes!=null)t=e.resetsInMinutes;else if(e.resetsInHours!=null)t=Math.round(e.resetsInHours*60);else if(e.resetsAt){let n=new Date(e.resetsAt).getTime()-Date.now();t=n>0?Math.ceil(n/6e4):0}if(t==null)return null;if(t<=0)return`now`;let n=Math.floor(t/1440),r=Math.floor(t%1440/60),i=t%60;return n>0?i>0?`${n}d ${r}h ${i}m`:r>0?`${n}d ${r}h`:`${n}d`:r>0?i>0?`${r}h ${i}m`:`${r}h`:`${i}m`}function Nr({label:e,bucket:t}){if(!t)return null;let n=Math.round(t.utilization*100),r=Mr(t);return(0,$.jsxs)(`div`,{className:`space-y-1`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,$.jsx)(`span`,{className:`text-xs font-medium text-text-primary`,children:e}),r&&(0,$.jsxs)(`span`,{className:`text-[10px] text-text-subtle`,title:`Resets in`,children:[`↻ `,r]})]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(`div`,{className:`flex-1 h-2 rounded-full bg-border overflow-hidden`,children:(0,$.jsx)(`div`,{className:`h-full rounded-full transition-all ${jr(n)}`,style:{width:`${Math.min(n,100)}%`}})}),(0,$.jsxs)(`span`,{className:`text-xs font-medium tabular-nums w-10 text-right ${Ar(n)}`,children:[n,`%`]})]})]})}function Pr(e){let t=e-Date.now();if(t<=0)return`expired`;let n=Math.ceil(t/6e4),r=Math.floor(n/60),i=Math.floor(r/24);return i>0?`${i}d ${r%24}h`:r>0?`${r}h ${n%60}m`:`${n}m`}function Fr(e){if(!e)return{label:`unknown`,tip:`No account info available`,color:`text-text-subtle`};if(!e.expiresAt)return{label:`key`,tip:`API key (no expiry)`,color:`text-text-subtle`};let t=e.expiresAt*1e3<Date.now();return t&&e.hasRefreshToken?{label:`expired`,tip:`Token expired but has refresh token — will auto-renew`,color:`text-amber-500`}:t?{label:`expired`,tip:`Token expired, no refresh token`,color:`text-red-500`}:e.hasRefreshToken?{label:`long-lived`,tip:`OAuth token with refresh — long-lived`,color:`text-green-500`}:{label:`temp`,tip:`Temporary token without refresh — will expire`,color:`text-amber-500`}}function Ir(e){if(!e)return null;let t=Math.round((Date.now()-e)/1e3);if(t<5)return`just now`;if(t<60)return`${t}s ago`;let n=Math.floor(t/60);if(n<60)return`${n}m ago`;let r=Math.floor(n/60),i=n%60;return r<24?i>0?`${r}h ${i}m ago`:`${r}h ago`:`${Math.floor(r/24)}d ago`}function Lr({entry:e,isActive:t,accountInfo:n,onToggle:r,onDelete:i,onExport:a,onViewProfile:o,flash:s,fullscreen:c}){let{usage:l}=e,u=l.session||l.weekly||l.weeklyOpus||l.weeklySonnet,d=n?.status??e.accountStatus,f=!!(n&&!n.hasRefreshToken&&n.expiresAt&&n.expiresAt<Math.floor(Date.now()/1e3));return(0,$.jsxs)(`div`,{className:`rounded-md border p-2 transition-colors duration-500 ${c?`flex flex-col gap-1.5 overflow-hidden`:`space-y-1.5 min-w-[200px] shrink-0 snap-start`} ${f?`opacity-50`:``} ${s?`bg-primary/10 border-primary/40`:``} ${t?`border-primary/30 bg-primary/5`:`border-border/50`}`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(`span`,{className:`text-xs font-medium truncate flex-1 min-w-0`,children:e.accountLabel??e.accountId.slice(0,8)}),f&&(0,$.jsx)(`span`,{className:`text-[9px] text-red-500 shrink-0 font-medium`,children:`Expired`}),!e.isOAuth&&!f&&(0,$.jsx)(`span`,{className:`text-[9px] text-text-subtle shrink-0`,children:`API key`}),(0,$.jsxs)(`div`,{className:`flex items-center gap-0.5 shrink-0`,children:[!f&&o&&n?.profileData&&(0,$.jsx)(`button`,{className:`p-1 rounded cursor-pointer text-text-subtle hover:text-foreground hover:bg-surface-elevated transition-colors`,onClick:()=>o(n.profileData,e.accountId),title:`View profile`,children:(0,$.jsx)(B,{className:`size-3`})}),!f&&a&&e.isOAuth&&(0,$.jsx)(`button`,{className:`p-1 rounded cursor-pointer text-text-subtle hover:text-blue-500 hover:bg-surface-elevated transition-colors`,onClick:()=>a(e.accountId),title:`Export this account`,children:(0,$.jsx)(z,{className:`size-3`})}),!f&&r&&(0,$.jsx)(p,{checked:d!==`disabled`,onCheckedChange:()=>r(e.accountId,d),disabled:d===`cooldown`,className:`scale-[0.6] cursor-pointer`}),i&&(0,$.jsx)(`button`,{className:`p-1 rounded cursor-pointer text-text-subtle hover:text-red-500 hover:bg-surface-elevated transition-colors`,onClick:()=>i(e.accountId,e.accountLabel??e.accountId.slice(0,8)),title:`Remove account`,children:(0,$.jsx)(te,{className:`size-3`})})]})]}),u?(0,$.jsxs)(`div`,{className:c?`flex-1 flex flex-col justify-evenly min-h-0`:`space-y-1.5`,children:[(0,$.jsx)(Nr,{label:`5-Hour Session`,bucket:l.session}),(0,$.jsx)(Nr,{label:`Weekly`,bucket:l.weekly}),(0,$.jsx)(Nr,{label:`Weekly (Opus)`,bucket:l.weeklyOpus}),(0,$.jsx)(Nr,{label:`Weekly (Sonnet)`,bucket:l.weeklySonnet})]}):(0,$.jsx)(`p`,{className:`text-[10px] text-text-subtle`,children:e.isOAuth?`No usage data yet`:`Usage tracking not available for API keys`}),(()=>{let e=Fr(n);return(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[9px] text-text-subtle flex-wrap`,children:[l.lastFetchedAt&&(0,$.jsxs)(`span`,{title:`Last usage data update`,children:[`↻ `,Ir(new Date(l.lastFetchedAt).getTime())]}),n?.expiresAt&&n.expiresAt*1e3>Date.now()&&(0,$.jsxs)(`span`,{title:`Token expires in`,children:[`⏱ `,Pr(n.expiresAt*1e3)]}),(0,$.jsxs)(`span`,{className:e.color,title:e.tip,children:[`© `,e.label]})]})})()]})}function Rr({usage:e,visible:t,onClose:n,onReload:r,loading:i,lastFetchedAt:a}){let[o,s]=(0,Q.useState)([]),[c,l]=(0,Q.useState)([]),[u,d]=(0,Q.useState)(null),[f,p]=(0,Q.useState)(!0),[m,h]=(0,Q.useState)(!1),[g,_]=(0,Q.useState)(new Set),[v,y]=(0,Q.useState)(null),[b,x]=(0,Q.useState)(!1),[S,C]=(0,Q.useState)(!1),[w,T]=(0,Q.useState)(!1),[E,D]=(0,Q.useState)(!1),[O,k]=(0,Q.useState)(null),[A,j]=(0,Q.useState)(null),[M,N]=(0,Q.useState)(!1),[P,F]=(0,Q.useState)(null),I=(0,Q.useRef)(void 0),L=(0,Q.useRef)([]);function ee(e){I.current&&clearTimeout(I.current),F(e),I.current=setTimeout(()=>F(null),4e3)}function R(e){B(),e&&ee(e)}async function B(){let e=o.length>0;e?h(!0):p(!0);let[t,n,r]=await Promise.allSettled([pe(),ve(),le()]);if(t.status===`fulfilled`){let n=t.value;if(e&&L.current.length>0){let e=new Set,t=new Map(L.current.map(e=>[e.accountId,e]));for(let r of n){let n=t.get(r.accountId);if(!n){e.add(r.accountId);continue}let i=n.usage,a=r.usage;(i.session?.utilization!==a.session?.utilization||i.weekly?.utilization!==a.weekly?.utilization||i.weeklyOpus?.utilization!==a.weeklyOpus?.utilization||i.weeklySonnet?.utilization!==a.weeklySonnet?.utilization)&&e.add(r.accountId)}e.size>0&&(_(e),setTimeout(()=>_(new Set),1500))}L.current=n,s(n)}n.status===`fulfilled`&&l(n.value),r.status===`fulfilled`&&d(r.value?.id??null),p(!1),h(!1)}if((0,Q.useEffect)(()=>{t&&B()},[t]),(0,Q.useEffect)(()=>{!t||!a||B()},[a]),!t)return null;let te=new Map(c.map(e=>[e.id,e])),ne=e.queryCostUsd!=null||e.totalCostUsd!=null,W=o.length>0,re=o.length||1,G=Math.ceil(Math.sqrt(re)),K=Math.ceil(re/G);async function ie(e,t){await me(e,{status:t===`disabled`?`active`:`disabled`}),B(),r?.()}async function q(){if(O){try{await _e(O.id),ee(`Account "${O.display}" removed.`),B(),r?.()}catch(e){ee(`Failed to remove: ${e.message}`)}k(null)}}function ae(){j(null),C(!0)}return(0,$.jsxs)(`div`,{className:`relative border-b border-border bg-surface px-3 py-2.5 ${M?`fixed inset-0 z-50 flex flex-col gap-2.5 overflow-hidden`:`space-y-2.5 max-h-[350px] overflow-y-auto`}`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between shrink-0`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(`span`,{className:`text-xs font-semibold text-text-primary`,children:`Usage & Accounts`}),a&&(0,$.jsx)(`span`,{className:`text-[10px] text-text-subtle`,children:Ir(new Date(a).getTime())})]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,$.jsx)(`button`,{onClick:()=>D(!0),className:`text-xs text-text-subtle hover:text-text-primary px-1 cursor-pointer`,title:`Rotation & retry settings`,children:(0,$.jsx)(Se,{className:`size-3`})}),W&&(0,$.jsx)(`button`,{onClick:()=>N(e=>!e),className:`text-xs text-text-subtle hover:text-text-primary px-1 cursor-pointer`,title:M?`Exit fullscreen`:`Fullscreen view`,children:M?(0,$.jsx)(at,{className:`size-3`}):(0,$.jsx)(rt,{className:`size-3`})}),r&&(0,$.jsx)(`button`,{onClick:()=>{r(),B()},disabled:i||m,className:`text-xs text-text-subtle hover:text-text-primary px-1 disabled:opacity-50 cursor-pointer`,title:`Refresh`,children:(0,$.jsx)(U,{className:`size-3 ${i||m?`animate-spin`:``}`})}),(0,$.jsx)(`button`,{onClick:()=>{N(!1),n()},className:`text-xs text-text-subtle hover:text-text-primary px-1 cursor-pointer`,children:(0,$.jsx)(H,{className:`size-3`})})]})]}),P&&(0,$.jsx)(`div`,{className:`text-[11px] p-1.5 rounded bg-green-500/10 text-green-600 text-center animate-in fade-in duration-200`,children:P}),W||f?(0,$.jsx)(`div`,{className:M?`flex-1 min-h-0 grid gap-2 overflow-hidden`:`flex gap-1.5 overflow-x-auto pb-1 -mx-3 px-3 snap-x snap-mandatory scrollbar-thin`,style:M?{gridTemplateColumns:`repeat(${G}, minmax(0, 1fr))`,gridTemplateRows:`repeat(${K}, minmax(0, 1fr))`}:void 0,children:f?(0,$.jsx)(`p`,{className:`text-[10px] text-text-subtle`,children:`Loading...`}):o.map(t=>(0,$.jsx)(Lr,{entry:t,isActive:t.accountId===(u??e.activeAccountId),accountInfo:te.get(t.accountId),onToggle:ie,onDelete:(e,t)=>k({id:e,display:t}),onExport:e=>{j(e),C(!0)},onViewProfile:(e,t)=>y({profile:e,accountId:t}),flash:g.has(t.accountId),fullscreen:M},t.accountId))}):(0,$.jsx)($.Fragment,{children:e.session||e.weekly||e.weeklyOpus||e.weeklySonnet?(0,$.jsxs)(`div`,{className:`space-y-2.5`,children:[(0,$.jsx)(Nr,{label:`5-Hour Session`,bucket:e.session}),(0,$.jsx)(Nr,{label:`Weekly`,bucket:e.weekly}),(0,$.jsx)(Nr,{label:`Weekly (Opus)`,bucket:e.weeklyOpus}),(0,$.jsx)(Nr,{label:`Weekly (Sonnet)`,bucket:e.weeklySonnet})]}):(0,$.jsx)(`p`,{className:`text-xs text-text-subtle`,children:`No usage data available`})}),ne&&(0,$.jsxs)(`div`,{className:`border-t border-border pt-2 space-y-1`,children:[e.queryCostUsd!=null&&(0,$.jsxs)(`div`,{className:`flex items-center justify-between text-xs`,children:[(0,$.jsx)(`span`,{className:`text-text-subtle`,children:`Last query`}),(0,$.jsxs)(`span`,{className:`text-text-primary font-medium tabular-nums`,children:[`$`,e.queryCostUsd.toFixed(4)]})]}),e.totalCostUsd!=null&&(0,$.jsxs)(`div`,{className:`flex items-center justify-between text-xs`,children:[(0,$.jsx)(`span`,{className:`text-text-subtle`,children:`Session total`}),(0,$.jsxs)(`span`,{className:`text-text-primary font-medium tabular-nums`,children:[`$`,e.totalCostUsd.toFixed(4)]})]})]}),v&&(0,$.jsxs)(`div`,{className:`border-t border-border pt-2`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between mb-1`,children:[(0,$.jsx)(`span`,{className:`text-[10px] font-medium text-text-subtle`,children:`Profile`}),(0,$.jsx)(`button`,{className:`text-text-subtle hover:text-foreground cursor-pointer`,onClick:()=>y(null),children:(0,$.jsx)(H,{className:`size-3`})})]}),(0,$.jsxs)(`div`,{className:`grid grid-cols-[70px_1fr] gap-x-2 gap-y-0.5 text-[10px]`,children:[v.profile.account?.display_name&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`span`,{className:`text-text-subtle`,children:`Name`}),(0,$.jsx)(`span`,{children:v.profile.account.display_name})]}),v.profile.account?.email&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`span`,{className:`text-text-subtle`,children:`Email`}),(0,$.jsx)(`span`,{children:v.profile.account.email})]}),v.profile.organization?.name&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`span`,{className:`text-text-subtle`,children:`Org`}),(0,$.jsx)(`span`,{children:v.profile.organization.name})]}),v.profile.organization?.organization_type&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`span`,{className:`text-text-subtle`,children:`Type`}),(0,$.jsx)(`span`,{children:v.profile.organization.organization_type})]}),v.profile.organization?.rate_limit_tier&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`span`,{className:`text-text-subtle`,children:`Tier`}),(0,$.jsx)(`span`,{children:v.profile.organization.rate_limit_tier})]}),v.profile.organization?.subscription_status&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`span`,{className:`text-text-subtle`,children:`Status`}),(0,$.jsx)(`span`,{children:v.profile.organization.subscription_status})]})]}),(0,$.jsx)(kr,{accountId:v.accountId})]}),(0,$.jsxs)(`div`,{className:`border-t border-border pt-2 flex gap-1.5 shrink-0`,children:[(0,$.jsxs)(`button`,{onClick:()=>x(!0),className:`flex-1 flex items-center justify-center gap-1 rounded-md border border-border px-2 py-1 text-[11px] text-text-secondary hover:bg-surface-hover transition-colors cursor-pointer`,children:[(0,$.jsx)(V,{className:`size-3`}),` Add`]}),(0,$.jsxs)(`button`,{onClick:ae,className:`flex-1 flex items-center justify-center gap-1 rounded-md border border-border px-2 py-1 text-[11px] text-text-secondary hover:bg-surface-hover transition-colors cursor-pointer`,children:[(0,$.jsx)(z,{className:`size-3`}),` Export`]}),(0,$.jsxs)(`button`,{onClick:()=>T(!0),className:`flex-1 flex items-center justify-center gap-1 rounded-md border border-border px-2 py-1 text-[11px] text-text-secondary hover:bg-surface-hover transition-colors cursor-pointer`,children:[(0,$.jsx)(Ce,{className:`size-3`}),` Import`]})]}),O&&(0,$.jsx)(`div`,{className:`absolute inset-0 z-10 flex items-center justify-center bg-background/80 backdrop-blur-sm rounded-md`,children:(0,$.jsxs)(`div`,{className:`bg-surface border border-border rounded-lg shadow-lg p-4 mx-4 max-w-[280px] w-full space-y-3`,children:[(0,$.jsxs)(`p`,{className:`text-xs text-text-primary text-center`,children:[`Remove `,(0,$.jsx)(`strong`,{className:`text-foreground`,children:O.display}),`?`]}),(0,$.jsxs)(`div`,{className:`flex gap-2`,children:[(0,$.jsx)(`button`,{onClick:()=>k(null),className:`flex-1 px-3 py-1.5 rounded-md text-xs border border-border text-text-secondary hover:bg-surface-hover cursor-pointer transition-colors`,children:`Cancel`}),(0,$.jsx)(`button`,{onClick:q,className:`flex-1 px-3 py-1.5 rounded-md text-xs bg-red-500 text-white hover:bg-red-600 cursor-pointer transition-colors`,children:`Remove`})]})]})}),(0,$.jsx)(pr,{open:b,onOpenChange:x,onSuccess:R}),(0,$.jsx)(mr,{open:S,onOpenChange:e=>{C(e),e||j(null)},accounts:c,preselectId:A,onMessage:ee}),(0,$.jsx)(hr,{open:w,onOpenChange:T,onSuccess:R}),(0,$.jsx)(xr,{open:E,onOpenChange:D})]})}var zr={active:`bg-green-500`,idle:`bg-yellow-500`,shutdown:`bg-zinc-400`},Br={task_assignment:{label:`task`,className:`bg-blue-500/20 text-blue-400`},idle_notification:{label:`idle`,className:`bg-yellow-500/20 text-yellow-400`},completion:{label:`done`,className:`bg-green-500/20 text-green-400`},shutdown_request:{label:`shutdown`,className:`bg-red-500/20 text-red-400`},shutdown_approved:{label:`shutdown ✓`,className:`bg-zinc-500/20 text-zinc-400`}};function Vr({teamNames:e,messages:t}){let[n,r]=(0,Q.useState)(e[0]??``),[i,a]=(0,Q.useState)([]),[o,s]=(0,Q.useState)(!1),c=(0,Q.useRef)(null);(0,Q.useEffect)(()=>{e.length>0&&!e.includes(n)&&r(e[0])},[e,n]);let l=(0,Q.useCallback)(async e=>{s(!0);try{a((await G.get(`/api/teams/${encodeURIComponent(e)}`))?.members??[])}catch{a([])}s(!1)},[]);(0,Q.useEffect)(()=>{n&&l(n)},[n,l]),(0,Q.useEffect)(()=>{c.current?.scrollIntoView({behavior:`smooth`})},[t.length]);let u=t.slice(-200);return(0,$.jsxs)(`div`,{className:`space-y-0`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-1 mb-2`,children:[(0,$.jsx)(`div`,{className:`flex items-center gap-1 overflow-x-auto min-w-0 flex-1`,children:e.map(e=>(0,$.jsx)(`button`,{onClick:()=>r(e),className:q(`px-2 py-0.5 text-[11px] rounded-md whitespace-nowrap transition-colors`,n===e?`bg-primary/10 text-primary font-medium`:`text-text-subtle hover:text-text-primary`),children:e},e))}),(0,$.jsx)(`button`,{onClick:()=>n&&l(n),className:`text-text-subtle hover:text-foreground p-1 shrink-0`,"aria-label":`Refresh`,children:(0,$.jsx)(U,{className:q(`size-3`,o&&`animate-spin`)})})]}),i.length>0&&(0,$.jsxs)(`div`,{className:`pb-2 mb-2 border-b border-border/30`,children:[(0,$.jsx)(`div`,{className:`text-[10px] text-text-subtle uppercase tracking-wider mb-1`,children:`Members`}),(0,$.jsx)(`div`,{className:`space-y-1`,children:i.map(e=>(0,$.jsxs)(`div`,{className:`flex items-center gap-2 text-xs`,children:[(0,$.jsx)(`span`,{className:q(`size-1.5 rounded-full shrink-0`,zr[e.status]??`bg-zinc-400`)}),(0,$.jsx)(`span`,{className:`font-medium truncate`,children:e.name}),e.model&&e.model!==`unknown`&&(0,$.jsxs)(`span`,{className:`text-text-subtle text-[10px]`,children:[`(`,e.model,`)`]}),(0,$.jsx)(`span`,{className:`ml-auto text-text-subtle text-[10px]`,children:e.status})]},e.name))})]}),(0,$.jsx)(`div`,{className:`max-h-40 overflow-y-auto`,children:u.length===0?(0,$.jsx)(`p`,{className:`text-xs text-text-subtle text-center py-2`,children:`No messages yet`}):(0,$.jsxs)(`div`,{className:`space-y-2`,children:[u.map((e,t)=>{let n=e.parsedType?Br[e.parsedType]:null,r=Hr(e.timestamp);return(0,$.jsxs)(`div`,{className:`text-xs`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-1 text-text-subtle`,children:[(0,$.jsx)(`span`,{className:`font-medium`,style:Ur(e.color),children:e.from}),(0,$.jsx)(`span`,{children:`→`}),(0,$.jsx)(`span`,{children:e.to}),(0,$.jsx)(`span`,{className:`ml-auto text-[10px]`,children:r})]}),(0,$.jsxs)(`div`,{className:`mt-0.5 text-foreground/90 break-words`,children:[n&&(0,$.jsx)(`span`,{className:q(`inline-block px-1 py-0 rounded text-[9px] mr-1`,n.className),children:n.label}),e.summary??Wr(e.text)]})]},`${e.timestamp}-${t}`)}),(0,$.jsx)(`div`,{ref:c})]})})]})}function Hr(e){try{return new Date(e).toLocaleTimeString([],{hour:`2-digit`,minute:`2-digit`,second:`2-digit`})}catch{return``}}function Ur(e){if(e&&(/^#[0-9a-fA-F]{3,8}$/.test(e)||/^[a-zA-Z]{3,20}$/.test(e)))return{color:e}}function Wr(e,t=120){if(!e)return``;try{let n=JSON.parse(e);return n.summary??n.text??e.slice(0,t)}catch{}return e.length>t?e.slice(0,t)+`...`:e}function Gr(e){return e>=90?`text-red-500`:e>=70?`text-amber-500`:`text-green-500`}function Kr({sessionId:e,projectName:t}){let[n,r]=(0,Q.useState)(!1);return(0,$.jsx)(`button`,{onClick:()=>{try{let n=G.get(`${W(t)}/chat/sessions/${e}/debug?project=${encodeURIComponent(t)}`).then(e=>{let t=[`PPM Session: ${e.ppmSessionId}`,`SDK Session: ${e.sdkSessionId}`,e.jsonlPath?`JSONL: ${e.jsonlPath}`:`JSONL: not found`,e.projectPath?`Project: ${e.projectPath}`:null].filter(Boolean).join(`
@@ -1,5 +1,5 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/markdown-renderer-C_5GH1wX.js","assets/rolldown-runtime-FhOqtrmT.js","assets/index-BQYpBWiY.js","assets/vendor-mermaid-Cl50p6TB.js","assets/vendor-ui-B-89Uj8i.js","assets/vendor-markdown-0Mxgxy0L.js","assets/input-4ll___Gh.js","assets/utils-CQux7CsO.js","assets/createLucideIcon-BjHrJDVb.js","assets/x-BPReZWnP.js","assets/settings-store-CVrIYYCB.js","assets/react-DMIOAtcX.js","assets/api-client-DIhJ5qVW.js","assets/scroll-area-iv39O3VN.js","assets/ai-settings-section-DN4egS8e.js","assets/dist-CaKCIxem.js","assets/refresh-cw-BjrAbUJe.js","assets/api-settings-DnHv6JgF.js","assets/database-DOWH9-Vv.js","assets/chevron-right-DnHIvvcy.js","assets/search-tM8K5zWU.js","assets/file-store-DOxcU_7s.js","assets/tab-store-S9w6U5gm.js","assets/index-C9ej6g0c.css","assets/csv-preview-BIfojSWd.js","assets/lib-Bu71-TFS.js","assets/csv-parser-Dly5nqE1.js","assets/arrow-up-Rcw6_KKu.js","assets/image-preview-DsJpgEWA.js","assets/file-exclamation-point-BwzaQ50n.js","assets/use-blob-url-QX-XajU8.js","assets/pdf-preview-CKw0C1oI.js","assets/video-preview-BLk5vtRN.js","assets/audio-preview-CUQyzUCl.js"])))=>i.map(i=>d[i]);
2
- import{o as e}from"./rolldown-runtime-FhOqtrmT.js";import{b as t,x as n}from"./vendor-markdown-0Mxgxy0L.js";import"./vendor-ui-B-89Uj8i.js";import{t as r}from"./createLucideIcon-BjHrJDVb.js";import"./scroll-area-iv39O3VN.js";import{t as i}from"./database-DOWH9-Vv.js";import{t as a}from"./chevron-right-DnHIvvcy.js";import{a as o,l as s,n as c,o as l,r as u,s as d,t as f}from"./input-4ll___Gh.js";import{t as p}from"./code-DGBecc50.js";import{a as m,i as h,t as g}from"./x-BPReZWnP.js";import{t as _}from"./file-exclamation-point-BwzaQ50n.js";import{i as ee,r as v,t as y}from"./glide-data-grid-DdE7PkYl.js";import{t as b}from"./table-BzjWcs87.js";import{t as x}from"./text-wrap-DJz9Bgpa.js";import{i as te,t as S}from"./api-client-DIhJ5qVW.js";import{n as ne}from"./settings-store-CVrIYYCB.js";import{K as C}from"./vendor-mermaid-Cl50p6TB.js";import{t as w}from"./utils-CQux7CsO.js";import{n as re,t as ie}from"./tab-store-S9w6U5gm.js";import{i as T,n as E}from"./file-store-DOxcU_7s.js";import{$ as ae,G as D,I as oe,J as O,K as k,Q as A,U as se,X as j,Y as M,Z as N,a as ce,c as P,d as F,f as le,g as ue,h as de,l as fe,m as pe,o as me,p as I,q as he,tt as ge,u as L}from"./index-BQYpBWiY.js";import"./data-grid-types-BISkUXAY.js";import{n as _e,t as ve}from"./use-monaco-theme-BePWbY58.js";var ye=r(`redo-2`,[[`path`,{d:`m15 14 5-5-5-5`,key:`12vg1m`}],[`path`,{d:`M20 9H9.5A5.5 5.5 0 0 0 4 14.5A5.5 5.5 0 0 0 9.5 20H13`,key:`6uklza`}]]),R=e(n(),1),z=t(),B={ts:N,tsx:N,js:N,jsx:N,py:N,rs:N,go:N,html:N,css:N,scss:N,json:A,md:j,txt:j,yaml:M,yml:M};function be(e,t){return t?he:B[e.split(`.`).pop()?.toLowerCase()??``]??O}function xe(e,t){let n=[],r=e,i=``;for(let e=0;e<t.length;e++){let a=t[e],o=t.slice(0,e+1).join(`/`),s=r.find(e=>e.name===a);if(n.push({name:a,fullPath:o,node:s??null,siblings:r,parentPath:i}),s?.children)i=s.path,r=s.children;else{for(let r=e+1;r<t.length;r++)n.push({name:t[r],fullPath:t.slice(0,r+1).join(`/`),node:null,siblings:[],parentPath:t.slice(0,r).join(`/`)});break}}return n}function V(e){return[...e].sort((e,t)=>e.type===t.type?e.name.localeCompare(t.name):e.type===`directory`?-1:1)}function Se({filePath:e,projectName:t,tabId:n,className:r}){let i=E(e=>e.tree),{updateTab:o,openTab:s}=ie(de(e=>({updateTab:e.updateTab,openTab:e.openTab}))),c=T(e=>e.projects.find(e=>e.name===t)?.path??``),l=(0,R.useRef)(null),{prefixParts:u,relativePath:d}=(0,R.useMemo)(()=>{let t=e.startsWith(`/`)?e.slice(1):e,n=c.startsWith(`/`)?c.slice(1):c;if(n&&t.startsWith(n+`/`)){let e=t.slice(n.length+1);return{prefixParts:n.split(`/`),relativePath:e}}return{prefixParts:[],relativePath:t}},[e,c]),f=(0,R.useMemo)(()=>xe(i,d.split(`/`).filter(Boolean)),[i,d]);(0,R.useEffect)(()=>{l.current&&(l.current.scrollLeft=l.current.scrollWidth)},[f]);function p(e,r){let i=w(e);r.metaKey||r.ctrlKey?s({type:`editor`,title:i,metadata:{filePath:e,projectName:t},projectId:t,closable:!0}):o(n,{title:i,metadata:{filePath:e,projectName:t}})}return(0,z.jsxs)(`div`,{ref:l,className:r,children:[u.map((e,t)=>(0,z.jsxs)(`div`,{className:`flex items-center shrink-0`,children:[t>0&&(0,z.jsx)(a,{className:`size-3 text-muted-foreground shrink-0 mx-0.5`}),(0,z.jsx)(`span`,{className:`text-xs text-muted-foreground px-1 py-0.5`,children:e})]},`prefix-${t}`)),f.map((e,n)=>(0,z.jsxs)(`div`,{className:`flex items-center shrink-0`,children:[(n>0||u.length>0)&&(0,z.jsx)(a,{className:`size-3 text-muted-foreground shrink-0 mx-0.5`}),(0,z.jsx)(Ce,{segment:e,isLast:n===f.length-1,projectName:t,onFileClick:p})]},e.fullPath))]})}function Ce({segment:e,isLast:t,projectName:n,onFileClick:r}){let i=E(e=>e.loadChildren),a=E(e=>e.loadedPaths),o=(0,R.useMemo)(()=>V(e.siblings),[e.siblings]),s=a.has(e.parentPath);function c(t){t&&!s&&i(n,e.parentPath)}return(0,z.jsxs)(P,{onOpenChange:c,children:[(0,z.jsx)(pe,{asChild:!0,children:(0,z.jsx)(`button`,{type:`button`,className:`text-xs px-1 py-0.5 rounded hover:bg-muted transition-colors truncate max-w-[120px] ${t?`text-foreground font-medium`:`text-muted-foreground`}`,children:e.name})}),(0,z.jsx)(fe,{align:`start`,className:`max-h-[300px] p-1`,children:o.length===0?(0,z.jsx)(L,{disabled:!0,className:`text-xs text-muted-foreground`,children:`Loading…`}):o.map(t=>(0,z.jsx)(H,{node:t,projectName:n,activePath:e.fullPath,onFileClick:r},t.path))})]})}function H({node:e,projectName:t,activePath:n,onFileClick:r}){let i=be(e.name,e.type===`directory`),a=e.path===n,o=E(e=>e.loadChildren),s=E(e=>e.loadedPaths);if(e.type===`directory`){let c=e.children??[],l=s.has(e.path);function u(n){n&&!l&&o(t,e.path)}return(0,z.jsxs)(F,{onOpenChange:u,children:[(0,z.jsxs)(I,{className:`text-xs gap-1.5 ${a?`bg-muted`:``}`,children:[(0,z.jsx)(i,{className:`size-3.5 shrink-0 text-muted-foreground`}),(0,z.jsx)(`span`,{className:`truncate`,children:e.name})]}),(0,z.jsx)(le,{className:`max-h-[300px] overflow-y-auto p-1`,children:c.length===0?(0,z.jsx)(L,{disabled:!0,className:`text-xs text-muted-foreground`,children:`Loading…`}):V(c).map(e=>(0,z.jsx)(H,{node:e,projectName:t,activePath:n,onFileClick:r},e.path))})]})}return(0,z.jsxs)(L,{className:`text-xs gap-1.5 cursor-pointer ${a?`bg-muted`:``}`,onSelect:e=>{},onClick:t=>{r(e.path,t)},children:[(0,z.jsx)(i,{className:`size-3.5 shrink-0 text-muted-foreground`}),(0,z.jsx)(`span`,{className:`truncate`,children:e.name})]})}function U({active:e,onClick:t,icon:n,label:r}){return(0,z.jsxs)(`button`,{type:`button`,onClick:t,className:`flex items-center gap-1 px-2 py-1 rounded text-xs transition-colors ${e?`bg-muted text-foreground`:`text-muted-foreground hover:text-foreground`}`,children:[(0,z.jsx)(n,{className:`size-3`}),(0,z.jsx)(`span`,{className:`hidden sm:inline`,children:r})]})}function we({ext:e,mdMode:t,onMdModeChange:n,csvMode:r,onCsvModeChange:i,wordWrap:a,onToggleWordWrap:o,filePath:s,projectName:c,className:l}){return(0,z.jsxs)(`div`,{className:l,children:[(e===`md`||e===`mdx`)&&n&&(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(U,{active:t===`edit`,onClick:()=>n(`edit`),icon:p,label:`Edit`}),(0,z.jsx)(U,{active:t===`preview`,onClick:()=>n(`preview`),icon:h,label:`Preview`})]}),e===`csv`&&i&&(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(U,{active:r===`table`,onClick:()=>i(`table`),icon:b,label:`Table`}),(0,z.jsx)(U,{active:r===`raw`,onClick:()=>i(`raw`),icon:p,label:`Raw`})]}),(0,z.jsx)(U,{active:a,onClick:o,icon:x,label:`Wrap`}),s&&c&&(0,z.jsx)(U,{active:!1,onClick:()=>ue(c,s),icon:m,label:`Download`})]})}function Te({open:e,defaultName:t,content:n,onSave:r,onCancel:i}){let[a,p]=(0,R.useState)(t),[m,h]=(0,R.useState)(!1),[g,_]=(0,R.useState)(``),ee=T(e=>e.activeProject),v=(0,R.useCallback)(()=>{let e=a.trim();if(!e){_(`Filename cannot be empty`);return}if(/[/\\]/.test(e)){_(`Filename cannot contain / or \\`);return}_(``),h(!0)},[a]),y=(0,R.useCallback)(e=>{let t=e.includes(`\\`)?`\\`:`/`;r(e.endsWith(t)?`${e}${a.trim()}`:`${e}${t}${a.trim()}`,n)},[a,n,r]);return m?(0,z.jsx)(me,{open:!0,mode:`folder`,root:ee?.path,title:`Save "${a.trim()}" to...`,onSelect:y,onCancel:()=>h(!1)}):(0,z.jsx)(c,{open:e,onOpenChange:e=>{e||i()},children:(0,z.jsxs)(u,{className:`sm:max-w-md`,children:[(0,z.jsx)(l,{children:(0,z.jsx)(d,{children:`Save As`})}),(0,z.jsxs)(`div`,{className:`flex flex-col gap-2 py-2`,children:[(0,z.jsx)(`label`,{className:`text-sm text-muted-foreground`,children:`Filename`}),(0,z.jsx)(f,{value:a,onChange:e=>{p(e.target.value),_(``)},onKeyDown:e=>{e.key===`Enter`&&v()},placeholder:`e.g. my-file.ts`,autoFocus:!0}),g&&(0,z.jsx)(`p`,{className:`text-xs text-destructive`,children:g})]}),(0,z.jsxs)(o,{children:[(0,z.jsx)(s,{variant:`outline`,onClick:i,children:`Cancel`}),(0,z.jsx)(s,{onClick:v,children:`Choose Folder...`})]})]})})}var W=typeof window<`u`&&window.isSecureContext,Ee=[`(`,`)`,`{`,`}`,`[`,`]`,`<`,`>`,`;`,`:`,`=`,`"`,`'`,"`",`/`,`\\`,`_`,`#`],G=`px-2 py-1.5 rounded text-xs min-w-[36px] min-h-[32px] bg-surface-elevated text-text-primary active:bg-primary active:text-primary-foreground transition-colors select-none`,K=`px-3 py-1.5 rounded text-xs font-mono min-w-[36px] min-h-[32px] bg-surface-elevated text-text-primary active:bg-primary active:text-primary-foreground transition-colors select-none`,De=`w-px h-5 bg-border mx-0.5 shrink-0`;function Oe({editorRef:e,readOnly:t}){let n=(0,R.useCallback)(()=>e.current,[e]),r=(0,R.useCallback)(e=>{let t=n();if(!t)return;t.focus();let r=t.getSelection();r&&t.executeEdits(`mobile-toolbar`,[{range:r,text:e}])},[n]),[i,a]=(0,R.useState)(!1),o=(0,R.useRef)(null),s=(0,R.useCallback)(async()=>{try{let e=await navigator.clipboard.readText();e&&r(e)}catch{}},[r]),c=(0,R.useCallback)(()=>{a(!0),requestAnimationFrame(()=>o.current?.focus())},[]),l=(0,R.useCallback)(e=>{e.preventDefault();let t=e.clipboardData.getData(`text/plain`);t&&(a(!1),r(t))},[r]),u=(0,R.useCallback)(()=>{let e=n();e&&(e.focus(),e.trigger(`mobile-toolbar`,`undo`,null))},[n]),d=(0,R.useCallback)(()=>{let e=n();e&&(e.focus(),e.trigger(`mobile-toolbar`,`redo`,null))},[n]),f=(0,R.useCallback)(()=>{let e=n();e&&(e.focus(),e.trigger(`mobile-toolbar`,`tab`,null))},[n]);return t?null:(0,z.jsxs)(`div`,{className:`shrink-0 border-t border-border bg-surface`,children:[!W&&i&&(0,z.jsxs)(`div`,{className:`flex items-center gap-2 px-2 py-1.5 border-b border-border bg-muted/50`,children:[(0,z.jsx)(`textarea`,{ref:o,onPaste:l,placeholder:`Long-press here → Paste`,className:`flex-1 h-8 rounded border border-border bg-background text-foreground text-xs px-2 py-1.5 resize-none focus:outline-none focus:ring-1 focus:ring-primary`}),(0,z.jsx)(`button`,{type:`button`,onClick:()=>a(!1),className:`p-1.5 rounded text-muted-foreground active:bg-muted transition-colors`,children:(0,z.jsx)(g,{size:14})})]}),(0,z.jsxs)(`div`,{className:`flex items-center gap-1 px-2 py-1.5 overflow-x-auto`,children:[(0,z.jsx)(`button`,{type:`button`,onClick:W?s:c,className:G,title:`Paste`,children:(0,z.jsx)(ge,{size:14})}),(0,z.jsx)(`button`,{type:`button`,onClick:u,className:G,title:`Undo`,children:(0,z.jsx)(oe,{size:14})}),(0,z.jsx)(`button`,{type:`button`,onClick:d,className:G,title:`Redo`,children:(0,z.jsx)(ye,{size:14})}),(0,z.jsx)(`div`,{className:De}),(0,z.jsx)(`button`,{type:`button`,onClick:f,className:K,children:`Tab`}),(0,z.jsx)(`div`,{className:De}),Ee.map(e=>(0,z.jsx)(`button`,{type:`button`,onClick:()=>r(e),className:K,children:e},e))]})]})}var ke=(0,R.lazy)(()=>C(()=>import(`./markdown-renderer-C_5GH1wX.js`).then(e=>({default:e.MarkdownRenderer})),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23]))),Ae=(0,R.lazy)(()=>C(()=>import(`./csv-preview-BIfojSWd.js`).then(e=>({default:e.CsvPreview})),__vite__mapDeps([24,1,4,5,25,26,8,27]))),je=(0,R.lazy)(()=>C(()=>import(`./image-preview-DsJpgEWA.js`).then(e=>({default:e.ImagePreview})),__vite__mapDeps([28,2,1,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,29,30]))),Me=(0,R.lazy)(()=>C(()=>import(`./pdf-preview-CKw0C1oI.js`).then(e=>({default:e.PdfPreview})),__vite__mapDeps([31,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,29,30]))),Ne=(0,R.lazy)(()=>C(()=>import(`./video-preview-BLk5vtRN.js`).then(e=>({default:e.VideoPreview})),__vite__mapDeps([32,2,1,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,29,30]))),Pe=(0,R.lazy)(()=>C(()=>import(`./audio-preview-CUQyzUCl.js`).then(e=>({default:e.AudioPreview})),__vite__mapDeps([33,2,1,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,29,30]))),Fe=new Set([`png`,`jpg`,`jpeg`,`gif`,`webp`,`svg`,`ico`]),Ie=new Set([`mp4`,`webm`,`mov`,`ogg`,`avi`,`mkv`]),Le=new Set([`mp3`,`wav`,`flac`,`aac`,`m4a`,`wma`]),Re=new Set([`db`,`sqlite`,`sqlite3`]);function ze(e){return e.split(`.`).pop()?.toLowerCase()??``}function Be(e){return{js:`javascript`,jsx:`javascript`,ts:`typescript`,tsx:`typescript`,py:`python`,html:`html`,css:`css`,scss:`scss`,json:`json`,md:`markdown`,mdx:`markdown`,yaml:`yaml`,yml:`yaml`,sh:`shell`,bash:`shell`,sql:`sql`}[ze(e)]??`plaintext`}var q=(0,R.memo)(function({metadata:e,tabId:t}){let n=e?.filePath,r=e?.projectName,a=e?.inlineContent,o=e?.inlineLanguage,[s,c]=(0,R.useState)(a??null),[l,u]=(0,R.useState)(`utf-8`),[d,f]=(0,R.useState)(!0),[p,m]=(0,R.useState)(null),[h,g]=(0,R.useState)(!1),y=(0,R.useRef)(null),b=(0,R.useRef)(``),x=(0,R.useRef)(null),{tabs:C,updateTab:T}=ie(de(e=>({tabs:e.tabs,updateTab:e.updateTab}))),{wordWrap:E,toggleWordWrap:ae}=ne(de(e=>({wordWrap:e.wordWrap,toggleWordWrap:e.toggleWordWrap}))),oe=ve(),O=e?.isUntitled===!0,k=e?.unsavedContent,[A,j]=(0,R.useState)(!1),M=C.find(e=>e.id===t),N=n?ze(n):``,P=Fe.has(N),F=N===`pdf`,le=Ie.has(N),ue=Le.has(N),fe=Re.has(N),pe=N===`md`||N===`mdx`,me=N===`csv`,I=N===`sql`,[he,ge]=(0,R.useState)(`preview`),[L,ye]=(0,R.useState)(`table`),{connections:B,cachedTables:be,refreshTables:xe}=ce(),[V,Ce]=(0,R.useState)(()=>{if(!I||!n)return null;let e=localStorage.getItem(`ppm:sql-conn:${n}`);return e?Number(e):null}),H=(0,R.useRef)(null),U=(0,R.useRef)(null),W=(0,R.useMemo)(()=>B.find(e=>e.id===V)??null,[B,V]),Ee=a!=null&&(o===`json`||o===`xml`),[G,K]=(0,R.useState)(!1),De=(0,R.useCallback)(()=>{if(a)if(G)c(a),K(!1);else{let e=a.trimStart();if(o===`json`)try{c(JSON.stringify(JSON.parse(e),null,2)),K(!0)}catch{}else if(o===`xml`){let t=0;c(e.replace(/(>)(<)(\/*)/g,`$1
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/markdown-renderer-Bv_VAy7V.js","assets/rolldown-runtime-FhOqtrmT.js","assets/index-BgTyEXDi.js","assets/vendor-mermaid-Cl50p6TB.js","assets/vendor-ui-B-89Uj8i.js","assets/vendor-markdown-0Mxgxy0L.js","assets/input-4ll___Gh.js","assets/utils-CQux7CsO.js","assets/createLucideIcon-BjHrJDVb.js","assets/x-BPReZWnP.js","assets/settings-store-CVrIYYCB.js","assets/react-DMIOAtcX.js","assets/api-client-DIhJ5qVW.js","assets/scroll-area-iv39O3VN.js","assets/ai-settings-section-DN4egS8e.js","assets/dist-CaKCIxem.js","assets/refresh-cw-BjrAbUJe.js","assets/api-settings-DnHv6JgF.js","assets/database-DOWH9-Vv.js","assets/chevron-right-DnHIvvcy.js","assets/search-tM8K5zWU.js","assets/file-store-DOxcU_7s.js","assets/tab-store-S9w6U5gm.js","assets/index-C9ej6g0c.css","assets/csv-preview-BIfojSWd.js","assets/lib-Bu71-TFS.js","assets/csv-parser-Dly5nqE1.js","assets/arrow-up-Rcw6_KKu.js","assets/image-preview-DLoL90K7.js","assets/file-exclamation-point-BwzaQ50n.js","assets/use-blob-url-QX-XajU8.js","assets/pdf-preview-DOnr5kiK.js","assets/video-preview-B4Jz9ymO.js","assets/audio-preview-Cr3GjyH_.js"])))=>i.map(i=>d[i]);
2
+ import{o as e}from"./rolldown-runtime-FhOqtrmT.js";import{b as t,x as n}from"./vendor-markdown-0Mxgxy0L.js";import"./vendor-ui-B-89Uj8i.js";import{t as r}from"./createLucideIcon-BjHrJDVb.js";import"./scroll-area-iv39O3VN.js";import{t as i}from"./database-DOWH9-Vv.js";import{t as a}from"./chevron-right-DnHIvvcy.js";import{a as o,l as s,n as c,o as l,r as u,s as d,t as f}from"./input-4ll___Gh.js";import{t as p}from"./code-DGBecc50.js";import{a as m,i as h,t as g}from"./x-BPReZWnP.js";import{t as _}from"./file-exclamation-point-BwzaQ50n.js";import{i as ee,r as v,t as y}from"./glide-data-grid-DYxTrchL.js";import{t as b}from"./table-BzjWcs87.js";import{t as x}from"./text-wrap-DJz9Bgpa.js";import{i as te,t as S}from"./api-client-DIhJ5qVW.js";import{n as ne}from"./settings-store-CVrIYYCB.js";import{K as C}from"./vendor-mermaid-Cl50p6TB.js";import{t as w}from"./utils-CQux7CsO.js";import{n as re,t as ie}from"./tab-store-S9w6U5gm.js";import{i as T,n as E}from"./file-store-DOxcU_7s.js";import{$ as ae,G as D,I as oe,J as O,K as k,Q as A,U as se,X as j,Y as M,Z as N,a as ce,c as P,d as F,f as le,g as ue,h as de,l as fe,m as pe,o as me,p as I,q as he,tt as ge,u as L}from"./index-BgTyEXDi.js";import"./data-grid-types-BISkUXAY.js";import{n as _e,t as ve}from"./use-monaco-theme-BePWbY58.js";var ye=r(`redo-2`,[[`path`,{d:`m15 14 5-5-5-5`,key:`12vg1m`}],[`path`,{d:`M20 9H9.5A5.5 5.5 0 0 0 4 14.5A5.5 5.5 0 0 0 9.5 20H13`,key:`6uklza`}]]),R=e(n(),1),z=t(),B={ts:N,tsx:N,js:N,jsx:N,py:N,rs:N,go:N,html:N,css:N,scss:N,json:A,md:j,txt:j,yaml:M,yml:M};function be(e,t){return t?he:B[e.split(`.`).pop()?.toLowerCase()??``]??O}function xe(e,t){let n=[],r=e,i=``;for(let e=0;e<t.length;e++){let a=t[e],o=t.slice(0,e+1).join(`/`),s=r.find(e=>e.name===a);if(n.push({name:a,fullPath:o,node:s??null,siblings:r,parentPath:i}),s?.children)i=s.path,r=s.children;else{for(let r=e+1;r<t.length;r++)n.push({name:t[r],fullPath:t.slice(0,r+1).join(`/`),node:null,siblings:[],parentPath:t.slice(0,r).join(`/`)});break}}return n}function V(e){return[...e].sort((e,t)=>e.type===t.type?e.name.localeCompare(t.name):e.type===`directory`?-1:1)}function Se({filePath:e,projectName:t,tabId:n,className:r}){let i=E(e=>e.tree),{updateTab:o,openTab:s}=ie(de(e=>({updateTab:e.updateTab,openTab:e.openTab}))),c=T(e=>e.projects.find(e=>e.name===t)?.path??``),l=(0,R.useRef)(null),{prefixParts:u,relativePath:d}=(0,R.useMemo)(()=>{let t=e.startsWith(`/`)?e.slice(1):e,n=c.startsWith(`/`)?c.slice(1):c;if(n&&t.startsWith(n+`/`)){let e=t.slice(n.length+1);return{prefixParts:n.split(`/`),relativePath:e}}return{prefixParts:[],relativePath:t}},[e,c]),f=(0,R.useMemo)(()=>xe(i,d.split(`/`).filter(Boolean)),[i,d]);(0,R.useEffect)(()=>{l.current&&(l.current.scrollLeft=l.current.scrollWidth)},[f]);function p(e,r){let i=w(e);r.metaKey||r.ctrlKey?s({type:`editor`,title:i,metadata:{filePath:e,projectName:t},projectId:t,closable:!0}):o(n,{title:i,metadata:{filePath:e,projectName:t}})}return(0,z.jsxs)(`div`,{ref:l,className:r,children:[u.map((e,t)=>(0,z.jsxs)(`div`,{className:`flex items-center shrink-0`,children:[t>0&&(0,z.jsx)(a,{className:`size-3 text-muted-foreground shrink-0 mx-0.5`}),(0,z.jsx)(`span`,{className:`text-xs text-muted-foreground px-1 py-0.5`,children:e})]},`prefix-${t}`)),f.map((e,n)=>(0,z.jsxs)(`div`,{className:`flex items-center shrink-0`,children:[(n>0||u.length>0)&&(0,z.jsx)(a,{className:`size-3 text-muted-foreground shrink-0 mx-0.5`}),(0,z.jsx)(Ce,{segment:e,isLast:n===f.length-1,projectName:t,onFileClick:p})]},e.fullPath))]})}function Ce({segment:e,isLast:t,projectName:n,onFileClick:r}){let i=E(e=>e.loadChildren),a=E(e=>e.loadedPaths),o=(0,R.useMemo)(()=>V(e.siblings),[e.siblings]),s=a.has(e.parentPath);function c(t){t&&!s&&i(n,e.parentPath)}return(0,z.jsxs)(P,{onOpenChange:c,children:[(0,z.jsx)(pe,{asChild:!0,children:(0,z.jsx)(`button`,{type:`button`,className:`text-xs px-1 py-0.5 rounded hover:bg-muted transition-colors truncate max-w-[120px] ${t?`text-foreground font-medium`:`text-muted-foreground`}`,children:e.name})}),(0,z.jsx)(fe,{align:`start`,className:`max-h-[300px] p-1`,children:o.length===0?(0,z.jsx)(L,{disabled:!0,className:`text-xs text-muted-foreground`,children:`Loading…`}):o.map(t=>(0,z.jsx)(H,{node:t,projectName:n,activePath:e.fullPath,onFileClick:r},t.path))})]})}function H({node:e,projectName:t,activePath:n,onFileClick:r}){let i=be(e.name,e.type===`directory`),a=e.path===n,o=E(e=>e.loadChildren),s=E(e=>e.loadedPaths);if(e.type===`directory`){let c=e.children??[],l=s.has(e.path);function u(n){n&&!l&&o(t,e.path)}return(0,z.jsxs)(F,{onOpenChange:u,children:[(0,z.jsxs)(I,{className:`text-xs gap-1.5 ${a?`bg-muted`:``}`,children:[(0,z.jsx)(i,{className:`size-3.5 shrink-0 text-muted-foreground`}),(0,z.jsx)(`span`,{className:`truncate`,children:e.name})]}),(0,z.jsx)(le,{className:`max-h-[300px] overflow-y-auto p-1`,children:c.length===0?(0,z.jsx)(L,{disabled:!0,className:`text-xs text-muted-foreground`,children:`Loading…`}):V(c).map(e=>(0,z.jsx)(H,{node:e,projectName:t,activePath:n,onFileClick:r},e.path))})]})}return(0,z.jsxs)(L,{className:`text-xs gap-1.5 cursor-pointer ${a?`bg-muted`:``}`,onSelect:e=>{},onClick:t=>{r(e.path,t)},children:[(0,z.jsx)(i,{className:`size-3.5 shrink-0 text-muted-foreground`}),(0,z.jsx)(`span`,{className:`truncate`,children:e.name})]})}function U({active:e,onClick:t,icon:n,label:r}){return(0,z.jsxs)(`button`,{type:`button`,onClick:t,className:`flex items-center gap-1 px-2 py-1 rounded text-xs transition-colors ${e?`bg-muted text-foreground`:`text-muted-foreground hover:text-foreground`}`,children:[(0,z.jsx)(n,{className:`size-3`}),(0,z.jsx)(`span`,{className:`hidden sm:inline`,children:r})]})}function we({ext:e,mdMode:t,onMdModeChange:n,csvMode:r,onCsvModeChange:i,wordWrap:a,onToggleWordWrap:o,filePath:s,projectName:c,className:l}){return(0,z.jsxs)(`div`,{className:l,children:[(e===`md`||e===`mdx`)&&n&&(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(U,{active:t===`edit`,onClick:()=>n(`edit`),icon:p,label:`Edit`}),(0,z.jsx)(U,{active:t===`preview`,onClick:()=>n(`preview`),icon:h,label:`Preview`})]}),e===`csv`&&i&&(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(U,{active:r===`table`,onClick:()=>i(`table`),icon:b,label:`Table`}),(0,z.jsx)(U,{active:r===`raw`,onClick:()=>i(`raw`),icon:p,label:`Raw`})]}),(0,z.jsx)(U,{active:a,onClick:o,icon:x,label:`Wrap`}),s&&c&&(0,z.jsx)(U,{active:!1,onClick:()=>ue(c,s),icon:m,label:`Download`})]})}function Te({open:e,defaultName:t,content:n,onSave:r,onCancel:i}){let[a,p]=(0,R.useState)(t),[m,h]=(0,R.useState)(!1),[g,_]=(0,R.useState)(``),ee=T(e=>e.activeProject),v=(0,R.useCallback)(()=>{let e=a.trim();if(!e){_(`Filename cannot be empty`);return}if(/[/\\]/.test(e)){_(`Filename cannot contain / or \\`);return}_(``),h(!0)},[a]),y=(0,R.useCallback)(e=>{let t=e.includes(`\\`)?`\\`:`/`;r(e.endsWith(t)?`${e}${a.trim()}`:`${e}${t}${a.trim()}`,n)},[a,n,r]);return m?(0,z.jsx)(me,{open:!0,mode:`folder`,root:ee?.path,title:`Save "${a.trim()}" to...`,onSelect:y,onCancel:()=>h(!1)}):(0,z.jsx)(c,{open:e,onOpenChange:e=>{e||i()},children:(0,z.jsxs)(u,{className:`sm:max-w-md`,children:[(0,z.jsx)(l,{children:(0,z.jsx)(d,{children:`Save As`})}),(0,z.jsxs)(`div`,{className:`flex flex-col gap-2 py-2`,children:[(0,z.jsx)(`label`,{className:`text-sm text-muted-foreground`,children:`Filename`}),(0,z.jsx)(f,{value:a,onChange:e=>{p(e.target.value),_(``)},onKeyDown:e=>{e.key===`Enter`&&v()},placeholder:`e.g. my-file.ts`,autoFocus:!0}),g&&(0,z.jsx)(`p`,{className:`text-xs text-destructive`,children:g})]}),(0,z.jsxs)(o,{children:[(0,z.jsx)(s,{variant:`outline`,onClick:i,children:`Cancel`}),(0,z.jsx)(s,{onClick:v,children:`Choose Folder...`})]})]})})}var W=typeof window<`u`&&window.isSecureContext,Ee=[`(`,`)`,`{`,`}`,`[`,`]`,`<`,`>`,`;`,`:`,`=`,`"`,`'`,"`",`/`,`\\`,`_`,`#`],G=`px-2 py-1.5 rounded text-xs min-w-[36px] min-h-[32px] bg-surface-elevated text-text-primary active:bg-primary active:text-primary-foreground transition-colors select-none`,K=`px-3 py-1.5 rounded text-xs font-mono min-w-[36px] min-h-[32px] bg-surface-elevated text-text-primary active:bg-primary active:text-primary-foreground transition-colors select-none`,De=`w-px h-5 bg-border mx-0.5 shrink-0`;function Oe({editorRef:e,readOnly:t}){let n=(0,R.useCallback)(()=>e.current,[e]),r=(0,R.useCallback)(e=>{let t=n();if(!t)return;t.focus();let r=t.getSelection();r&&t.executeEdits(`mobile-toolbar`,[{range:r,text:e}])},[n]),[i,a]=(0,R.useState)(!1),o=(0,R.useRef)(null),s=(0,R.useCallback)(async()=>{try{let e=await navigator.clipboard.readText();e&&r(e)}catch{}},[r]),c=(0,R.useCallback)(()=>{a(!0),requestAnimationFrame(()=>o.current?.focus())},[]),l=(0,R.useCallback)(e=>{e.preventDefault();let t=e.clipboardData.getData(`text/plain`);t&&(a(!1),r(t))},[r]),u=(0,R.useCallback)(()=>{let e=n();e&&(e.focus(),e.trigger(`mobile-toolbar`,`undo`,null))},[n]),d=(0,R.useCallback)(()=>{let e=n();e&&(e.focus(),e.trigger(`mobile-toolbar`,`redo`,null))},[n]),f=(0,R.useCallback)(()=>{let e=n();e&&(e.focus(),e.trigger(`mobile-toolbar`,`tab`,null))},[n]);return t?null:(0,z.jsxs)(`div`,{className:`shrink-0 border-t border-border bg-surface`,children:[!W&&i&&(0,z.jsxs)(`div`,{className:`flex items-center gap-2 px-2 py-1.5 border-b border-border bg-muted/50`,children:[(0,z.jsx)(`textarea`,{ref:o,onPaste:l,placeholder:`Long-press here → Paste`,className:`flex-1 h-8 rounded border border-border bg-background text-foreground text-xs px-2 py-1.5 resize-none focus:outline-none focus:ring-1 focus:ring-primary`}),(0,z.jsx)(`button`,{type:`button`,onClick:()=>a(!1),className:`p-1.5 rounded text-muted-foreground active:bg-muted transition-colors`,children:(0,z.jsx)(g,{size:14})})]}),(0,z.jsxs)(`div`,{className:`flex items-center gap-1 px-2 py-1.5 overflow-x-auto`,children:[(0,z.jsx)(`button`,{type:`button`,onClick:W?s:c,className:G,title:`Paste`,children:(0,z.jsx)(ge,{size:14})}),(0,z.jsx)(`button`,{type:`button`,onClick:u,className:G,title:`Undo`,children:(0,z.jsx)(oe,{size:14})}),(0,z.jsx)(`button`,{type:`button`,onClick:d,className:G,title:`Redo`,children:(0,z.jsx)(ye,{size:14})}),(0,z.jsx)(`div`,{className:De}),(0,z.jsx)(`button`,{type:`button`,onClick:f,className:K,children:`Tab`}),(0,z.jsx)(`div`,{className:De}),Ee.map(e=>(0,z.jsx)(`button`,{type:`button`,onClick:()=>r(e),className:K,children:e},e))]})]})}var ke=(0,R.lazy)(()=>C(()=>import(`./markdown-renderer-Bv_VAy7V.js`).then(e=>({default:e.MarkdownRenderer})),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23]))),Ae=(0,R.lazy)(()=>C(()=>import(`./csv-preview-BIfojSWd.js`).then(e=>({default:e.CsvPreview})),__vite__mapDeps([24,1,4,5,25,26,8,27]))),je=(0,R.lazy)(()=>C(()=>import(`./image-preview-DLoL90K7.js`).then(e=>({default:e.ImagePreview})),__vite__mapDeps([28,2,1,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,29,30]))),Me=(0,R.lazy)(()=>C(()=>import(`./pdf-preview-DOnr5kiK.js`).then(e=>({default:e.PdfPreview})),__vite__mapDeps([31,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,29,30]))),Ne=(0,R.lazy)(()=>C(()=>import(`./video-preview-B4Jz9ymO.js`).then(e=>({default:e.VideoPreview})),__vite__mapDeps([32,2,1,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,29,30]))),Pe=(0,R.lazy)(()=>C(()=>import(`./audio-preview-Cr3GjyH_.js`).then(e=>({default:e.AudioPreview})),__vite__mapDeps([33,2,1,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,29,30]))),Fe=new Set([`png`,`jpg`,`jpeg`,`gif`,`webp`,`svg`,`ico`]),Ie=new Set([`mp4`,`webm`,`mov`,`ogg`,`avi`,`mkv`]),Le=new Set([`mp3`,`wav`,`flac`,`aac`,`m4a`,`wma`]),Re=new Set([`db`,`sqlite`,`sqlite3`]);function ze(e){return e.split(`.`).pop()?.toLowerCase()??``}function Be(e){return{js:`javascript`,jsx:`javascript`,ts:`typescript`,tsx:`typescript`,py:`python`,html:`html`,css:`css`,scss:`scss`,json:`json`,md:`markdown`,mdx:`markdown`,yaml:`yaml`,yml:`yaml`,sh:`shell`,bash:`shell`,sql:`sql`}[ze(e)]??`plaintext`}var q=(0,R.memo)(function({metadata:e,tabId:t}){let n=e?.filePath,r=e?.projectName,a=e?.inlineContent,o=e?.inlineLanguage,[s,c]=(0,R.useState)(a??null),[l,u]=(0,R.useState)(`utf-8`),[d,f]=(0,R.useState)(!0),[p,m]=(0,R.useState)(null),[h,g]=(0,R.useState)(!1),y=(0,R.useRef)(null),b=(0,R.useRef)(``),x=(0,R.useRef)(null),{tabs:C,updateTab:T}=ie(de(e=>({tabs:e.tabs,updateTab:e.updateTab}))),{wordWrap:E,toggleWordWrap:ae}=ne(de(e=>({wordWrap:e.wordWrap,toggleWordWrap:e.toggleWordWrap}))),oe=ve(),O=e?.isUntitled===!0,k=e?.unsavedContent,[A,j]=(0,R.useState)(!1),M=C.find(e=>e.id===t),N=n?ze(n):``,P=Fe.has(N),F=N===`pdf`,le=Ie.has(N),ue=Le.has(N),fe=Re.has(N),pe=N===`md`||N===`mdx`,me=N===`csv`,I=N===`sql`,[he,ge]=(0,R.useState)(`preview`),[L,ye]=(0,R.useState)(`table`),{connections:B,cachedTables:be,refreshTables:xe}=ce(),[V,Ce]=(0,R.useState)(()=>{if(!I||!n)return null;let e=localStorage.getItem(`ppm:sql-conn:${n}`);return e?Number(e):null}),H=(0,R.useRef)(null),U=(0,R.useRef)(null),W=(0,R.useMemo)(()=>B.find(e=>e.id===V)??null,[B,V]),Ee=a!=null&&(o===`json`||o===`xml`),[G,K]=(0,R.useState)(!1),De=(0,R.useCallback)(()=>{if(a)if(G)c(a),K(!1);else{let e=a.trimStart();if(o===`json`)try{c(JSON.stringify(JSON.parse(e),null,2)),K(!0)}catch{}else if(o===`xml`){let t=0;c(e.replace(/(>)(<)(\/*)/g,`$1
3
3
  $2$3`).split(`
4
4
  `).map(e=>{let n=e.trim();n.startsWith(`</`)&&(t=Math.max(0,t-1));let r=` `.repeat(t)+n;return n.startsWith(`<`)&&!n.startsWith(`</`)&&!n.endsWith(`/>`)&&!n.includes(`</`)&&t++,r}).join(`
5
5
  `)),K(!0)}}},[a,o,G]),ke=(0,R.useCallback)(e=>{Ce(e),n&&localStorage.setItem(`ppm:sql-conn:${n}`,String(e)),xe(e).catch(()=>{})},[n,xe]),q=(0,R.useMemo)(()=>{if(!I||!V)return;let e=(be.get(V)??[]).map(e=>({name:e.tableName,schema:e.schemaName}));if(e.length!==0)return{tables:e,getColumns:async(e,t)=>S.get(`/api/db/connections/${V}/schema?table=${encodeURIComponent(e)}${t?`&schema=${encodeURIComponent(t)}`:``}`)}},[I,V,be]);(0,R.useEffect)(()=>{if(!(!H.current||!q))return U.current?.dispose(),v(),U.current=H.current.languages.registerCompletionItemProvider(`sql`,ee(H.current,q)),()=>{U.current?.dispose()}},[q]);let J=ie(e=>e.openTab),[Ue,We]=(0,R.useState)(null),[Ge,Ke]=(0,R.useState)(null),[qe,Je]=(0,R.useState)(!1),[Ye,Xe]=(0,R.useState)(``),X=(0,R.useCallback)(async e=>{if(W){Je(!0),Ke(null),Xe(e);try{We(await S.post(`/api/db/connections/${W.id}/query`,{sql:e}))}catch(e){Ke(e.message),We(null)}finally{Je(!1)}}},[W]),Ze=(0,R.useCallback)(()=>{!W||!Ye||J({type:`database`,title:`${W.name} · Query`,projectId:null,closable:!0,metadata:{connectionId:W.id,connectionName:W.name,dbType:W.type,initialSql:Ye}})},[W,J,Ye]),Qe=(0,R.useCallback)(()=>{if(!x.current||!W)return;let e=x.current,t=e.getSelection();X(t&&!t.isEmpty()?e.getModel()?.getValueInRange(t)??e.getValue():e.getValue())},[W,X]),$e=typeof window<`u`&&`ontouchstart`in window,et=(0,R.useRef)(null),[tt,nt]=(0,R.useState)(null);(0,R.useEffect)(()=>{if(!$e)return;let e=window.visualViewport;if(!e)return;let t=()=>{let t=et.current;if(!t)return;let n=t.getBoundingClientRect().top;nt(e.height-Math.max(0,n))};return e.addEventListener(`resize`,t),e.addEventListener(`scroll`,t),()=>{e.removeEventListener(`resize`,t),e.removeEventListener(`scroll`,t)}},[$e]);let Z=(0,R.useRef)([]),rt=(0,R.useRef)(X);rt.current=X,(0,R.useEffect)(()=>()=>{Z.current.forEach(e=>e.dispose()),Z.current=[]},[]),(0,R.useEffect)(()=>{fe&&t&&T(t,{type:`sqlite`})},[fe,t,T]);let Q=n?/^(\/|[A-Za-z]:[/\\])/.test(n):!1;(0,R.useEffect)(()=>{if(a!=null){f(!1);return}if(O){c(k??``),b.current=k??``,f(!1),k&&g(!0);return}if(!n||!Q&&!r)return;if(P||F||le||ue){f(!1);return}f(!0),m(null);let e=Q?`/api/fs/read?path=${encodeURIComponent(n)}`:`${te(r)}/files/read?path=${encodeURIComponent(n)}`;return S.get(e).then(e=>{c(e.content),e.encoding&&u(e.encoding),b.current=e.content,f(!1)}).catch(e=>{m(e instanceof Error?e.message:`Failed to load file`),f(!1)}),()=>{y.current&&clearTimeout(y.current)}},[n,r,P,F,Q,O]);let it=(0,R.useRef)(h);it.current=h,(0,R.useEffect)(()=>{if(!n||!r||a!=null||O)return;let e=e=>{let t=e.detail;if(t.projectName!==r||t.path!==n||it.current)return;let i=Q?`/api/fs/read?path=${encodeURIComponent(n)}`:`${te(r)}/files/read?path=${encodeURIComponent(n)}`;S.get(i).then(e=>{e.content!==b.current&&(c(e.content),b.current=e.content,e.encoding&&u(e.encoding))}).catch(()=>{})};return window.addEventListener(`file:changed`,e),()=>window.removeEventListener(`file:changed`,e)},[n,r,Q,a,O]),(0,R.useEffect)(()=>{if(!M||a!=null)return;let t=O?`Untitled-${e?.untitledNumber??1}`:n?w(n):`Untitled`,r=h?`${t} \u25CF`:t;M.title!==r&&T(M.id,{title:r})},[h]);let at=(0,R.useCallback)(async e=>{if(n&&!(!Q&&!r))try{Q?await S.put(`/api/fs/write`,{path:n,content:e}):await S.put(`${te(r)}/files/write`,{path:n,content:e}),g(!1)}catch{}},[n,r,Q]);function ot(n){let r=n??``;c(r),b.current=r,g(!0),y.current&&clearTimeout(y.current),O?y.current=setTimeout(()=>{t&&T(t,{metadata:{...e,unsavedContent:b.current}})},2e3):y.current=setTimeout(()=>at(b.current),1e3)}let st=(0,R.useCallback)(async(e,n)=>{try{if(y.current&&clearTimeout(y.current),await S.put(`/api/fs/write`,{path:e,content:n}),t){let{closeTab:n,openTab:r}=re.getState();n(t),r({type:`editor`,title:w(e),projectId:null,metadata:{filePath:e},closable:!0})}g(!1),j(!1)}catch{}},[t]),$=e?.lineNumber,ct=(0,R.useCallback)((e,t)=>{if(x.current=e,H.current=t,$&&$>0&&setTimeout(()=>{e.revealLineInCenter($),e.setPosition({lineNumber:$,column:1}),e.focus()},100),O&&e.addCommand(t.KeyMod.CtrlCmd|t.KeyCode.KeyS,()=>j(!0)),e.addCommand(t.KeyMod.Alt|t.KeyCode.KeyZ,()=>ne.getState().toggleWordWrap()),t.languages.typescript.typescriptDefaults.setDiagnosticsOptions({noSemanticValidation:!0,noSyntaxValidation:!0,noSuggestionDiagnostics:!0}),t.languages.typescript.javascriptDefaults.setDiagnosticsOptions({noSemanticValidation:!0,noSyntaxValidation:!0,noSuggestionDiagnostics:!0}),q&&(U.current?.dispose(),U.current=t.languages.registerCompletionItemProvider(`sql`,ee(t,q))),I){Z.current.forEach(e=>e.dispose()),Z.current=[];let n=e.getModel(),r=e.addCommand(0,(e,t)=>{t&&rt.current(t)});if(r&&n){let e=t.languages.registerCodeLensProvider(`sql`,{provideCodeLenses:e=>{if(e!==n)return{lenses:[],dispose:()=>{}};let t=[],i=e.getValue().split(`