@hienlh/ppm 0.8.68 → 0.8.70

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 (30) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/dist/web/assets/{browser-tab-CtCbYDuw.js → browser-tab-sn8vZniz.js} +1 -1
  3. package/dist/web/assets/chat-tab-CVN2falD.js +8 -0
  4. package/dist/web/assets/{code-editor-B1u2B_S9.js → code-editor-BNAZzdyF.js} +1 -1
  5. package/dist/web/assets/{database-viewer-D9fH7muY.js → database-viewer-BOnawWoi.js} +1 -1
  6. package/dist/web/assets/{diff-viewer-CdAqWeV-.js → diff-viewer-CYSw0YBG.js} +1 -1
  7. package/dist/web/assets/{git-graph-BDUvkX0f.js → git-graph-BNTU6kmo.js} +1 -1
  8. package/dist/web/assets/{index-DtlqB_mF.js → index-ButO-DnP.js} +8 -8
  9. package/dist/web/assets/index-DJ1Bqwo4.css +2 -0
  10. package/dist/web/assets/keybindings-store-BxDBTcFM.js +1 -0
  11. package/dist/web/assets/{markdown-renderer-Bwac0-W_.js → markdown-renderer-CW2c3h_9.js} +1 -1
  12. package/dist/web/assets/{postgres-viewer-CqT43D2z.js → postgres-viewer-D95__akI.js} +1 -1
  13. package/dist/web/assets/{settings-tab-G59ZwloQ.js → settings-tab-CwLkeZaa.js} +1 -1
  14. package/dist/web/assets/{sqlite-viewer-D6sxS0bk.js → sqlite-viewer-J18kIhk2.js} +1 -1
  15. package/dist/web/assets/{terminal-tab-IkfhM5s1.js → terminal-tab-BKETi9uD.js} +1 -1
  16. package/dist/web/assets/{use-monaco-theme-gi_EBBX3.js → use-monaco-theme-Dsn8sLad.js} +1 -1
  17. package/dist/web/index.html +2 -2
  18. package/dist/web/sw.js +1 -1
  19. package/package.json +1 -1
  20. package/src/providers/claude-agent-sdk.ts +51 -8
  21. package/src/server/routes/chat.ts +17 -0
  22. package/src/server/ws/chat.ts +2 -2
  23. package/src/types/chat.ts +2 -1
  24. package/src/web/components/chat/chat-history-bar.tsx +34 -1
  25. package/src/web/components/chat/message-list.tsx +7 -0
  26. package/src/web/components/layout/editor-panel.tsx +96 -17
  27. package/src/web/hooks/use-chat.ts +11 -0
  28. package/dist/web/assets/chat-tab-Bx_6S_UY.js +0 -7
  29. package/dist/web/assets/index-DPI-YVJI.css +0 -2
  30. package/dist/web/assets/keybindings-store-DiM6OAOI.js +0 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,20 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.8.70] - 2026-03-31
4
+
5
+ ### Added
6
+ - **Recent chats on empty state**: When no tabs are open, show up to 5 recent chat sessions for quick access — click to reopen directly
7
+
8
+ ## [0.8.69] - 2026-03-31
9
+
10
+ ### Fixed
11
+ - **Auth 401 auto-retry**: Detect 401 errors returned as assistant text content (SDK doesn't always set error field) — refresh OAuth token and retry with fresh session automatically instead of showing raw error to user
12
+ - **Result-level 401 retry**: 401 in SDK result events now triggers token refresh + retry (previously only refreshed without retrying)
13
+
14
+ ### Added
15
+ - **Account retry notification**: FE shows inline status when auth retry happens (e.g. "↻ Token refreshed — retrying with **Alex**...")
16
+ - **Session debug button**: Bug icon in chat toolbar copies session IDs + JSONL path to clipboard for quick debugging
17
+
3
18
  ## [0.8.68] - 2026-03-31
4
19
 
5
20
  ### Fixed
@@ -1 +1 @@
1
- import{o as e}from"./chunk-CFjPhJqf.js";import{t}from"./react-nm2Ru1Pt.js";import{t as n}from"./jsx-runtime-BRW_vwa9.js";import{o as r,t as i}from"./tab-store-BCfMgMKM.js";import{t as a}from"./api-client-BfBM3I7n.js";import{F as o,J as s,V as c,Y as l}from"./index-DtlqB_mF.js";var u=e(t(),1),d=n();function f({metadata:e,tabId:t}){let n=e?.port||0,[f,p]=(0,u.useState)(n?String(n):``),[m,h]=(0,u.useState)(null),[g,_]=(0,u.useState)(!1),[v,y]=(0,u.useState)(null),b=(0,u.useRef)(null),x=i(e=>e.updateTab),S=(0,u.useCallback)(async n=>{_(!0),y(null),h(null);try{h((await a.post(`/api/preview/tunnel`,{port:n})).url),t&&x(t,{title:`localhost:${n}`,metadata:{...e,port:n}})}catch(e){y(e.message||`Failed to start tunnel for port ${n}`)}finally{_(!1)}},[t,e,x]),C=(0,u.useCallback)(async()=>{let e=parseInt(f,10);if(e){try{await a.del(`/api/preview/tunnel/${e}`)}catch{}h(null),t&&x(t,{title:`Browser`})}},[f,t,x]);return m?(0,d.jsxs)(`div`,{className:`flex flex-col h-full w-full bg-background`,children:[(0,d.jsxs)(`div`,{className:`flex items-center gap-1.5 px-2 py-1.5 border-b border-border bg-surface shrink-0`,children:[(0,d.jsx)(l,{className:`size-4 text-text-subtle shrink-0`}),(0,d.jsxs)(`span`,{className:`text-xs text-text-primary font-medium`,children:[`localhost:`,f]}),(0,d.jsxs)(`span`,{className:`text-xs text-text-subtle truncate ml-1`,children:[`(`,m,`)`]}),(0,d.jsx)(`div`,{className:`flex-1`}),(0,d.jsx)(`button`,{onClick:()=>{if(b.current){let e=b.current.src;b.current.src=``,requestAnimationFrame(()=>{b.current&&(b.current.src=e)})}},className:`p-1.5 rounded hover:bg-surface-elevated transition-colors`,title:`Reload`,children:(0,d.jsx)(c,{className:`size-3.5`})}),(0,d.jsx)(`button`,{onClick:()=>window.open(m,`_blank`),className:`p-1.5 rounded hover:bg-surface-elevated transition-colors`,title:`Open in browser`,children:(0,d.jsx)(r,{className:`size-3.5`})}),(0,d.jsx)(`button`,{onClick:C,className:`p-1.5 rounded hover:bg-surface-elevated text-red-400 transition-colors`,title:`Stop tunnel`,children:(0,d.jsx)(o,{className:`size-3.5`})})]}),(0,d.jsxs)(`div`,{className:`flex-1 relative min-h-0`,children:[(0,d.jsx)(`iframe`,{ref:b,src:m,className:`w-full h-full border-0`,sandbox:`allow-scripts allow-forms allow-same-origin allow-popups allow-modals`,onLoad:()=>_(!1)}),g&&(0,d.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center bg-background/50`,children:(0,d.jsx)(s,{className:`size-5 animate-spin text-text-secondary`})})]})]}):(0,d.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full gap-4 p-6`,children:[(0,d.jsx)(l,{className:`size-12 text-text-subtle`}),(0,d.jsx)(`h2`,{className:`text-lg font-medium text-text-primary`,children:`Open Localhost`}),(0,d.jsx)(`p`,{className:`text-sm text-text-secondary text-center max-w-sm`,children:`Enter the port of your local dev server to preview it here.`}),(0,d.jsxs)(`form`,{onSubmit:e=>{e.preventDefault();let t=parseInt(f,10);t>=1&&t<=65535?S(t):y(`Port must be 1-65535`)},className:`flex items-center gap-2 w-full max-w-xs`,children:[(0,d.jsxs)(`div`,{className:`flex-1 flex items-center gap-2 px-3 py-2.5 rounded-lg bg-surface border border-border focus-within:border-accent/50 transition-colors`,children:[(0,d.jsx)(`span`,{className:`text-sm text-text-subtle shrink-0`,children:`localhost:`}),(0,d.jsx)(`input`,{type:`number`,value:f,onChange:e=>p(e.target.value),placeholder:`3000`,min:1,max:65535,autoFocus:!0,className:`flex-1 bg-transparent text-sm text-text-primary outline-none placeholder:text-text-subtle min-w-0 [appearance:textfield] [&::-webkit-inner-spin-button]:appearance-none [&::-webkit-outer-spin-button]:appearance-none`})]}),(0,d.jsx)(`button`,{type:`submit`,disabled:g||!f,className:`px-4 py-2.5 rounded-lg bg-accent text-white text-sm font-medium hover:bg-accent/90 disabled:opacity-50 transition-colors shrink-0`,children:g?(0,d.jsx)(s,{className:`size-4 animate-spin`}):`Open`})]}),v&&(0,d.jsx)(`p`,{className:`text-sm text-red-400`,children:v}),g&&(0,d.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-text-secondary`,children:[(0,d.jsx)(s,{className:`size-4 animate-spin`}),(0,d.jsx)(`span`,{children:`Starting tunnel... (may take a few seconds)`})]})]})}export{f as BrowserTab};
1
+ import{o as e}from"./chunk-CFjPhJqf.js";import{t}from"./react-nm2Ru1Pt.js";import{t as n}from"./jsx-runtime-BRW_vwa9.js";import{o as r,t as i}from"./tab-store-BCfMgMKM.js";import{t as a}from"./api-client-BfBM3I7n.js";import{F as o,J as s,V as c,Y as l}from"./index-ButO-DnP.js";var u=e(t(),1),d=n();function f({metadata:e,tabId:t}){let n=e?.port||0,[f,p]=(0,u.useState)(n?String(n):``),[m,h]=(0,u.useState)(null),[g,_]=(0,u.useState)(!1),[v,y]=(0,u.useState)(null),b=(0,u.useRef)(null),x=i(e=>e.updateTab),S=(0,u.useCallback)(async n=>{_(!0),y(null),h(null);try{h((await a.post(`/api/preview/tunnel`,{port:n})).url),t&&x(t,{title:`localhost:${n}`,metadata:{...e,port:n}})}catch(e){y(e.message||`Failed to start tunnel for port ${n}`)}finally{_(!1)}},[t,e,x]),C=(0,u.useCallback)(async()=>{let e=parseInt(f,10);if(e){try{await a.del(`/api/preview/tunnel/${e}`)}catch{}h(null),t&&x(t,{title:`Browser`})}},[f,t,x]);return m?(0,d.jsxs)(`div`,{className:`flex flex-col h-full w-full bg-background`,children:[(0,d.jsxs)(`div`,{className:`flex items-center gap-1.5 px-2 py-1.5 border-b border-border bg-surface shrink-0`,children:[(0,d.jsx)(l,{className:`size-4 text-text-subtle shrink-0`}),(0,d.jsxs)(`span`,{className:`text-xs text-text-primary font-medium`,children:[`localhost:`,f]}),(0,d.jsxs)(`span`,{className:`text-xs text-text-subtle truncate ml-1`,children:[`(`,m,`)`]}),(0,d.jsx)(`div`,{className:`flex-1`}),(0,d.jsx)(`button`,{onClick:()=>{if(b.current){let e=b.current.src;b.current.src=``,requestAnimationFrame(()=>{b.current&&(b.current.src=e)})}},className:`p-1.5 rounded hover:bg-surface-elevated transition-colors`,title:`Reload`,children:(0,d.jsx)(c,{className:`size-3.5`})}),(0,d.jsx)(`button`,{onClick:()=>window.open(m,`_blank`),className:`p-1.5 rounded hover:bg-surface-elevated transition-colors`,title:`Open in browser`,children:(0,d.jsx)(r,{className:`size-3.5`})}),(0,d.jsx)(`button`,{onClick:C,className:`p-1.5 rounded hover:bg-surface-elevated text-red-400 transition-colors`,title:`Stop tunnel`,children:(0,d.jsx)(o,{className:`size-3.5`})})]}),(0,d.jsxs)(`div`,{className:`flex-1 relative min-h-0`,children:[(0,d.jsx)(`iframe`,{ref:b,src:m,className:`w-full h-full border-0`,sandbox:`allow-scripts allow-forms allow-same-origin allow-popups allow-modals`,onLoad:()=>_(!1)}),g&&(0,d.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center bg-background/50`,children:(0,d.jsx)(s,{className:`size-5 animate-spin text-text-secondary`})})]})]}):(0,d.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full gap-4 p-6`,children:[(0,d.jsx)(l,{className:`size-12 text-text-subtle`}),(0,d.jsx)(`h2`,{className:`text-lg font-medium text-text-primary`,children:`Open Localhost`}),(0,d.jsx)(`p`,{className:`text-sm text-text-secondary text-center max-w-sm`,children:`Enter the port of your local dev server to preview it here.`}),(0,d.jsxs)(`form`,{onSubmit:e=>{e.preventDefault();let t=parseInt(f,10);t>=1&&t<=65535?S(t):y(`Port must be 1-65535`)},className:`flex items-center gap-2 w-full max-w-xs`,children:[(0,d.jsxs)(`div`,{className:`flex-1 flex items-center gap-2 px-3 py-2.5 rounded-lg bg-surface border border-border focus-within:border-accent/50 transition-colors`,children:[(0,d.jsx)(`span`,{className:`text-sm text-text-subtle shrink-0`,children:`localhost:`}),(0,d.jsx)(`input`,{type:`number`,value:f,onChange:e=>p(e.target.value),placeholder:`3000`,min:1,max:65535,autoFocus:!0,className:`flex-1 bg-transparent text-sm text-text-primary outline-none placeholder:text-text-subtle min-w-0 [appearance:textfield] [&::-webkit-inner-spin-button]:appearance-none [&::-webkit-outer-spin-button]:appearance-none`})]}),(0,d.jsx)(`button`,{type:`submit`,disabled:g||!f,className:`px-4 py-2.5 rounded-lg bg-accent text-white text-sm font-medium hover:bg-accent/90 disabled:opacity-50 transition-colors shrink-0`,children:g?(0,d.jsx)(s,{className:`size-4 animate-spin`}):`Open`})]}),v&&(0,d.jsx)(`p`,{className:`text-sm text-red-400`,children:v}),g&&(0,d.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-text-secondary`,children:[(0,d.jsx)(s,{className:`size-4 animate-spin`}),(0,d.jsx)(`span`,{children:`Starting tunnel... (may take a few seconds)`})]})]})}export{f as BrowserTab};
@@ -0,0 +1,8 @@
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/api-client-BfBM3I7n.js","assets/chunk-CFjPhJqf.js"])))=>i.map(i=>d[i]);
2
+ import{o as e}from"./chunk-CFjPhJqf.js";import{t}from"./react-nm2Ru1Pt.js";import"./react-dom-Bpkvzu3U.js";import{n,t as r}from"./jsx-runtime-BRW_vwa9.js";import{t as i}from"./arrow-up--LjUXLEt.js";import{a,i as o,n as s,r as c,t as l}from"./input-BglMT33g.js";import{t as u}from"./chevron-right-DeV0ehiG.js";import{n as d,t as f}from"./markdown-renderer-CW2c3h_9.js";import{t as p}from"./columns-2-DpsNbZOc.js";import{n as m,o as h,t as g}from"./tab-store-BCfMgMKM.js";import{t as _}from"./tag-CCtdV063.js";import{t as v}from"./preload-helper-uTix4PVD.js";import"./dist-lF8CoYII.js";import{n as y,r as b,t as x}from"./utils-BNytJOb1.js";import{i as S,r as C,t as w}from"./api-client-BfBM3I7n.js";import{a as T,c as E,d as D,i as O,o as k,r as A,s as j,t as M,u as N}from"./api-settings-D21InCnR.js";import{B as P,D as F,F as I,G as L,H as R,I as z,J as B,K as V,N as H,P as U,Q as W,R as ee,U as te,V as ne,Y as G,Z as re,_ as ie,a as ae,b as oe,ct as se,et as K,ft as q,g as ce,h as le,it as ue,lt as de,mt as fe,n as pe,o as me,ot as he,pt as ge,q as _e,r as ve,rt as ye,s as be,ut as xe,v as Se,y as Ce}from"./index-ButO-DnP.js";import"./chunk-GEFDOKGD-BbQkJu8C.js";import"./src-BqX54PbV.js";import"./chunk-7R4GIKGN-BbIFzsIv.js";import"./chunk-HHEYEP7N-HRhYy3kG.js";import"./dist-CSJdAyA9.js";import"./chunk-PU5JKC2W-Dw8ClWch.js";import"./chunk-MX3YWQON-BpS_PtKp.js";import"./chunk-YBOYWFTD-CeU4Q-xC.js";import"./chunk-PQ6SQG4A-D6BTbCQw.js";import"./chunk-KYZI473N-BcUZNnwd.js";import"./chunk-O4XLMI2P-JC6EGoUz.js";import"./chunk-GLR3WWYH-CzYx4w-r.js";import"./chunk-XPW4576I-BPQQBakK.js";var we=n(`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`}]]),Te=n(`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`}]]),Ee=n(`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`}]]),De=n(`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`}]]),Oe=n(`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`}]]),ke=n(`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`}]]),Ae=n(`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`}]]),je=n(`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`}]]),Me=n(`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`}]]),Ne=n(`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`}]]),Pe=n(`settings-2`,[[`path`,{d:`M14 17H5`,key:`gfn3mx`}],[`path`,{d:`M19 7h-9`,key:`6i9tg`}],[`circle`,{cx:`17`,cy:`17`,r:`3`,key:`18b49y`}],[`circle`,{cx:`7`,cy:`7`,r:`3`,key:`dfmy0x`}]]),Fe=n(`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`}]]),Ie=n(`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`}]]),Le=n(`sparkles`,[[`path`,{d:`M11.017 2.814a1 1 0 0 1 1.966 0l1.051 5.558a2 2 0 0 0 1.594 1.594l5.558 1.051a1 1 0 0 1 0 1.966l-5.558 1.051a2 2 0 0 0-1.594 1.594l-1.051 5.558a1 1 0 0 1-1.966 0l-1.051-5.558a2 2 0 0 0-1.594-1.594l-5.558-1.051a1 1 0 0 1 0-1.966l5.558-1.051a2 2 0 0 0 1.594-1.594z`,key:`1s2grr`}],[`path`,{d:`M20 2v4`,key:`1rf3ol`}],[`path`,{d:`M22 4h-4`,key:`gwowj6`}],[`circle`,{cx:`4`,cy:`20`,r:`2`,key:`6kqj1y`}]]),Re=n(`square`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}]]),J=e(t(),1),ze=3e4,Be=1e3,Ve=class{ws=null;url;handlers=[];reconnectAttempts=0;reconnectTimer=null;intentionalClose=!1;pendingMessages=[];constructor(e){this.url=e}connect(){this.intentionalClose=!1,this.cleanup();let e=window.location.protocol===`https:`?`wss:`:`ws:`,t=this.url.startsWith(`ws`)?this.url:`${e}//${window.location.host}${this.url}`;this.ws=new WebSocket(t),this.ws.onopen=()=>{this.reconnectAttempts=0;try{this.ws?.send(JSON.stringify({type:`ready`}))}catch{}if(this.pendingMessages.length>0){console.log(`[ws] flushing ${this.pendingMessages.length} queued message(s)`);for(let e of this.pendingMessages)try{this.ws?.send(e)}catch{}this.pendingMessages=[]}},this.ws.onmessage=e=>{for(let t of this.handlers)t(e)},this.ws.onclose=()=>{this.intentionalClose||this.scheduleReconnect()},this.ws.onerror=()=>{this.ws?.close()}}disconnect(){this.intentionalClose=!0,this.pendingMessages=[],this.cleanup(),this.reconnectTimer&&=(clearTimeout(this.reconnectTimer),null)}send(e){this.ws?.readyState===WebSocket.OPEN?this.ws.send(e):this.ws?.readyState===WebSocket.CONNECTING?(console.warn(`[ws] WS still CONNECTING — queuing message`),this.pendingMessages.push(e)):console.warn(`[ws] message dropped — readyState=${this.ws?.readyState??`no-ws`}`)}onMessage(e){return this.handlers.push(e),()=>{this.handlers=this.handlers.filter(t=>t!==e)}}get isConnected(){return this.ws?.readyState===WebSocket.OPEN}cleanup(){this.ws&&=(this.ws.onopen=null,this.ws.onclose=null,this.ws.onmessage=null,this.ws.onerror=null,(this.ws.readyState===WebSocket.OPEN||this.ws.readyState===WebSocket.CONNECTING)&&this.ws.close(),null)}scheduleReconnect(){let e=Math.min(Be*2**this.reconnectAttempts,ze);this.reconnectAttempts++,this.reconnectTimer=setTimeout(()=>this.connect(),e)}};function He({url:e,onMessage:t,autoConnect:n=!0}){let r=(0,J.useRef)(null);return(0,J.useEffect)(()=>{let i=new Ve(e);return r.current=i,t&&i.onMessage(t),n&&i.connect(),()=>{i.disconnect(),r.current=null}},[e,n]),{send:(0,J.useCallback)(e=>{r.current?.send(e)},[]),connect:(0,J.useCallback)(()=>{r.current?.connect()},[]),disconnect:(0,J.useCallback)(()=>{r.current?.disconnect()},[])}}var Ue=null;function We(){return Ue||=new AudioContext,Ue}function Y(e,t,n,r,i=`sine`){let a=We(),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 Ge(){let e=We().currentTime;Y(523,.15,e,.15),Y(659,.2,e+.12,.15)}function Ke(){let e=We().currentTime;Y(880,.12,e,.18,`square`),Y(698,.12,e+.15,.18,`square`),Y(880,.15,e+.3,.15,`square`)}function qe(){let e=We().currentTime;Y(440,.12,e,.12),Y(523,.12,e+.1,.12),Y(659,.18,e+.2,.12)}var Je={done:Ge,approval_request:Ke,question:qe};function Ye(e){try{Je[e]?.()}catch{}}function Xe(e){if(document.hidden)return!1;let{panels:t,focusedPanelId:n}=m.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 Ze(e,t=`claude`,n=``){let[r,i]=(0,J.useState)([]),[a,o]=(0,J.useState)(!1),[s,c]=(0,J.useState)(`idle`),[l,u]=(0,J.useState)(!1),[d,f]=(0,J.useState)(0),[p,m]=(0,J.useState)(null),[h,g]=(0,J.useState)(null),[_,v]=(0,J.useState)(null),[y,b]=(0,J.useState)(!1),x=(0,J.useRef)(``),w=(0,J.useRef)([]),T=(0,J.useRef)(null),E=(0,J.useRef)(`idle`),D=(0,J.useRef)(null),O=(0,J.useRef)(()=>{}),k=(0,J.useRef)(null),A=(0,J.useRef)(e);A.current=e;let j=(0,J.useRef)(n);j.current=n;let M=s!==`idle`,N=(0,J.useCallback)((e,t)=>{let n=w.current.findIndex(e=>e.type===`tool_use`&&(e.tool===`Agent`||e.tool===`Task`)&&e.toolUseId===t);if(n===-1)return!1;let r=w.current[n];if(r.type!==`tool_use`)return!1;let i=[...r.children??[],e];return w.current[n]={...r,children:i},!0},[]),P=(0,J.useCallback)(()=>{let e=x.current,t=[...w.current],n=T.current;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}]})},[]),I=(0,J.useCallback)(e=>{let t=e,n=t?.type;if(n)switch(n){case`account_info`:T.current={accountId:t.accountId,accountLabel:t.accountLabel};break;case`account_retry`:t.accountId&&t.accountLabel&&(T.current={accountId:t.accountId,accountLabel:t.accountLabel}),w.current.push(t),P();break;case`text`:{let e=t.parentToolUseId;if(e&&N(t,e)){P();break}x.current+=t.content,w.current.push(t),P();break}case`thinking`:{let e=t.parentToolUseId;if(e&&N(t,e)){P();break}w.current.push(t),P();break}case`tool_use`:{let e=t.parentToolUseId;if(e&&N(t,e)){P();break}w.current.push(t),P();break}case`tool_result`:{let e=t.parentToolUseId;if(e&&N(t,e)){P();break}w.current.push(t),P();break}case`approval_request`:if(w.current.push(t),m({requestId:t.requestId,tool:t.tool,input:t.input}),A.current&&!Xe(A.current)){let e=t.tool===`AskUserQuestion`?`question`:`approval_request`;F.getState().addNotification(A.current,e,j.current),Ye(e)}break;case`error`:{w.current.push(t);let e=[...w.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`done`:{if(E.current===`idle`)break;t.contextWindowPct!=null&&g(t.contextWindowPct),A.current&&!Xe(A.current)&&(F.getState().addNotification(A.current,`done`,j.current),Ye(`done`));let e=x.current,n=[...w.current];i(t=>{let r=t[t.length-1];return r?.role===`assistant`?[...t.slice(0,-1),{...r,id:`final-${Date.now()}`,content:e||r.content,events:n.length>0?n:r.events}]:t}),x.current=``,w.current=[],T.current=null;break}}},[N,P]),L=(0,J.useCallback)(e=>{let t;try{t=JSON.parse(e.data)}catch{return}if(t.type!==`ping`){if(t.type===`title_updated`){v(t.title??null);return}if(t.type===`phase_changed`){let e=t.phase;c(e),E.current=e,f(e===`connecting`?t.elapsed??0:0);return}if(t.type===`session_state`){b(!0);let e=t,n=e.phase;c(n),E.current=n,e.sessionTitle&&v(e.sessionTitle),e.pendingApproval&&m({requestId:e.pendingApproval.requestId,tool:e.pendingApproval.tool,input:e.pendingApproval.input}),n===`idle`&&(k.current?.(),u(!1));return}if(t.type===`turn_events`){let e=t.events;if(!e?.length){u(!1);return}i(e=>{let t=e.findLastIndex(e=>e.role===`user`);return t>=0?e.slice(0,t+1):e}),x.current=``,w.current=[],T.current=null;let n=0,r=()=>{let t=Math.min(n+100,e.length);for(let r=n;r<t;r++)I(e[r]);n=t,n<e.length?requestAnimationFrame(r):u(!1)};requestAnimationFrame(r);return}I(t)}},[I]),{send:R,connect:z}=He({url:e&&n?`/ws/project/${encodeURIComponent(n)}/chat/${e}`:``,onMessage:L,autoConnect:!!e&&!!n});O.current=R,(0,J.useEffect)(()=>{let r=!1;return c(`idle`),E.current=`idle`,m(null),x.current=``,w.current=[],b(!1),e&&n?(o(!0),fetch(`${S(n)}/chat/sessions/${e}/messages?providerId=${t}`,{headers:{Authorization:`Bearer ${C()}`}}).then(e=>e.json()).then(e=>{r||E.current!==`idle`||(e.ok&&Array.isArray(e.data)&&e.data.length>0?i(e.data):i([]))}).catch(()=>{!r&&E.current===`idle`&&i([])}).finally(()=>{r||o(!1)})):i([]),()=>{r=!0}},[e,t,n]);let B=(0,J.useCallback)((e,t)=>{if(e.trim()){if(E.current!==`idle`){let e=x.current,t=[...w.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}),R(JSON.stringify({type:`cancel`}))}i(t=>[...t,{id:`user-${Date.now()}`,role:`user`,content:e,timestamp:new Date().toISOString()}]),x.current=``,w.current=[],D.current=null,c(`initializing`),E.current=`initializing`,m(null),R(JSON.stringify({type:`message`,content:e,permissionMode:t?.permissionMode}))}},[R]),V=(0,J.useCallback)((e,t,n)=>{if(R(JSON.stringify({type:`approval_response`,requestId:e,approved:t,data:n})),t&&n){let t=w.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])}m(null)},[R]),H=(0,J.useCallback)(()=>{if(E.current===`idle`)return;R(JSON.stringify({type:`cancel`}));let e=x.current,t=[...w.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}),x.current=``,w.current=[],D.current=null,c(`idle`),E.current=`idle`,m(null)},[R]),U=(0,J.useCallback)(()=>{b(!1),u(!0),z()},[z]),W=(0,J.useCallback)(()=>{!e||!n||(o(!0),fetch(`${S(n)}/chat/sessions/${e}/messages?providerId=${t}`,{headers:{Authorization:`Bearer ${C()}`}}).then(e=>e.json()).then(e=>{e.ok&&Array.isArray(e.data)&&e.data.length>0&&(i(e.data),x.current=``,w.current=[])}).catch(()=>{}).finally(()=>o(!1)))},[e,t,n]);return k.current=W,{messages:r,messagesLoading:a,isStreaming:M,phase:s,isReconnecting:l,connectingElapsed:d,pendingApproval:p,contextWindowPct:h,sessionTitle:_,sendMessage:B,respondToApproval:V,cancelStreaming:H,reconnect:U,refetchMessages:W,isConnected:y}}var Qe=12e4;function $e(e,t=`claude`){let[n,r]=(0,J.useState)({}),[i,a]=(0,J.useState)(!1),[o,s]=(0,J.useState)(null),c=(0,J.useRef)(null),l=(0,J.useCallback)((n=!1)=>{if(!e)return;a(!0);let i=n?`&refresh=1`:``;fetch(`${S(e)}/chat/usage?providerId=${t}${i}`,{headers:{Authorization:`Bearer ${C()}`}}).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,J.useEffect)(()=>(l(),c.current=setInterval(()=>l(),Qe),()=>{c.current&&clearInterval(c.current)}),[l]),{usageInfo:n,usageLoading:i,lastFetchedAt:o,refreshUsage:(0,J.useCallback)(()=>l(!0),[l])}}var et={damping:.7,stiffness:.05,mass:1.25},tt=70,nt=1e3/60,rt=350,it=!1;globalThis.document?.addEventListener(`mousedown`,()=>{it=!0}),globalThis.document?.addEventListener(`mouseup`,()=>{it=!1}),globalThis.document?.addEventListener(`click`,()=>{it=!1});var at=(e={})=>{let[t,n]=(0,J.useState)(!1),[r,i]=(0,J.useState)(e.initial!==!1),[a,o]=(0,J.useState)(!1),s=(0,J.useRef)(null);s.current=e;let c=(0,J.useCallback)(()=>{if(!it)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,J.useCallback)(e=>{d.isAtBottom=e,i(e)},[]),u=(0,J.useCallback)(e=>{d.escapedFromLock=e,n(e)},[]),d=(0,J.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<=tt}}},[]),f=(0,J.useCallback)((e={})=>{typeof e==`string`&&(e={animation:e}),e.preserveScrollPosition||l(!0);let t=Date.now()+(Number(e.wait)||0),n=ct(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))/nt;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:ct(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,J.useCallback)(()=>{u(!0),l(!1)},[u,l]),m=(0,J.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,J.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=ot(e=>{g.current?.removeEventListener(`scroll`,m),g.current?.removeEventListener(`wheel`,h),e?.addEventListener(`scroll`,m,{passive:!0}),e?.addEventListener(`wheel`,h,{passive:!0})},[]),_=ot(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=ct(s.current,t?s.current.resize:s.current.initial);f({animation:e,wait:!0,preserveScrollPosition:!0,duration:e===`instant`?void 0:rt})}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 ot(e,t){let n=(0,J.useCallback)(t=>(n.current=t,e(t)),t);return n}var st=new Map;function ct(...e){let t={...et},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 st.has(r)||st.set(r,Object.freeze(t)),n?`instant`:st.get(r)}var lt=(0,J.createContext)(null),ut=typeof window<`u`?J.useLayoutEffect:J.useEffect;function dt({instance:e,children:t,resize:n,initial:r,mass:i,damping:a,stiffness:o,targetScrollTop:s,contextRef:c,...l}){let u=(0,J.useRef)(null),d=at({mass:i,damping:a,stiffness:o,resize:n,initial:r,targetScrollTop:J.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,J.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,J.useImperativeHandle)(c,()=>y,[y]),ut(()=>{f.current&&getComputedStyle(f.current).overflow===`visible`&&(f.current.style.overflow=`auto`)},[]),J.createElement(lt.Provider,{value:y},J.createElement(`div`,{...l},typeof t==`function`?t(y):t))}(function(e){function t({children:e,scrollClassName:t,...n}){let r=ft();return J.createElement(`div`,{ref:r.scrollRef,style:{height:`100%`,width:`100%`,scrollbarGutter:`stable both-edges`},className:t},J.createElement(`div`,{...n,ref:r.contentRef},typeof e==`function`?e(r):e))}e.Content=t})(dt||={});function ft(){let e=(0,J.useContext)(lt);if(!e)throw Error(`use-stick-to-bottom component context must be used within a StickToBottom component`);return e}var X=r();function pt(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 mt({tool:e,result:t,completed:n,projectName:r}){let[i,a]=(0,J.useState)(!1);if(e.type===`error`)return(0,X.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,X.jsx)(de,{className:`size-3`}),(0,X.jsx)(`span`,{children:e.message})]});let{toolName:s,input:c}=pt(e),l=t?.type===`tool_result`,d=l&&!!t.isError,f=s===`AskUserQuestion`&&!!c?.answers,p=(s===`Agent`||s===`Task`)&&e.type===`tool_use`,m=p?e.children:void 0,h=m&&m.length>0;return(0,X.jsxs)(`div`,{className:`rounded border text-xs ${p?`border-accent/30 bg-accent/5`:`border-border bg-background`}`,children:[(0,X.jsxs)(`button`,{onClick:()=>a(!i),className:`flex items-center gap-2 px-2 py-1.5 w-full text-left hover:bg-surface transition-colors min-w-0`,children:[i?(0,X.jsx)(o,{className:`size-3 shrink-0`}):(0,X.jsx)(u,{className:`size-3 shrink-0`}),d?(0,X.jsx)(Te,{className:`size-3 text-red-400 shrink-0`}):l||f||n?(0,X.jsx)(se,{className:`size-3 text-green-400 shrink-0`}):(0,X.jsx)(B,{className:`size-3 text-yellow-400 shrink-0 animate-spin`}),(0,X.jsx)(`span`,{className:`truncate text-text-primary`,children:(0,X.jsx)(ht,{name:s,input:c})}),h&&(0,X.jsxs)(`span`,{className:`ml-auto text-[10px] text-text-subtle shrink-0`,children:[m.length,` steps`]})]}),i&&(0,X.jsxs)(`div`,{className:`px-2 pb-2 space-y-1.5`,children:[(e.type===`tool_use`||e.type===`approval_request`)&&(0,X.jsx)(gt,{name:s,input:c,projectName:r}),h&&(0,X.jsx)(bt,{events:m,projectName:r}),l&&(0,X.jsx)(vt,{toolName:s,output:t.output})]})]})}function ht({name:e,input:t}){let n=e=>String(e??``);switch(e){case`Read`:case`Write`:case`Edit`:case`MultiEdit`:case`NotebookEdit`:return(0,X.jsxs)(X.Fragment,{children:[e,` `,(0,X.jsx)(`span`,{className:`text-text-subtle`,children:x(n(t.file_path))})]});case`Bash`:return(0,X.jsxs)(X.Fragment,{children:[e,` `,(0,X.jsx)(`span`,{className:`font-mono text-text-subtle`,children:Z(n(t.command),60)})]});case`Glob`:return(0,X.jsxs)(X.Fragment,{children:[e,` `,(0,X.jsx)(`span`,{className:`font-mono text-text-subtle`,children:n(t.pattern)})]});case`Grep`:return(0,X.jsxs)(X.Fragment,{children:[e,` `,(0,X.jsx)(`span`,{className:`font-mono text-text-subtle`,children:Z(n(t.pattern),40)})]});case`WebSearch`:return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(P,{className:`size-3 inline`}),` `,e,` `,(0,X.jsx)(`span`,{className:`text-text-subtle`,children:Z(n(t.query),50)})]});case`WebFetch`:return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(G,{className:`size-3 inline`}),` `,e,` `,(0,X.jsx)(`span`,{className:`text-text-subtle`,children:Z(n(t.url),50)})]});case`ToolSearch`:return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(P,{className:`size-3 inline`}),` `,e,` `,(0,X.jsx)(`span`,{className:`text-text-subtle`,children:Z(n(t.query),50)})]});case`Agent`:case`Task`:return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(ge,{className:`size-3 inline`}),` `,e,` `,(0,X.jsx)(`span`,{className:`text-text-subtle`,children:Z(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,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(je,{className:`size-3 inline`}),` `,e,` `,(0,X.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,X.jsxs)(X.Fragment,{children:[e,` `,(0,X.jsxs)(`span`,{className:`text-text-subtle`,children:[n.length,` question`,n.length===1?``:`s`,r?` ✓`:``]})]})}default:return(0,X.jsx)(X.Fragment,{children:e})}}function gt({name:e,input:t,projectName:n}){let r=e=>String(e??``),{openTab:i}=g(),a=e=>{n&&i({type:`editor`,title:x(e),metadata:{filePath:e,projectName:n},projectId:n,closable:!0})},o=(e,t,r)=>{i({type:`git-diff`,title:`Diff ${x(e)}`,metadata:{filePath:e,projectName:n,original:t,modified:r},projectId:n??null,closable:!0})};switch(e){case`Bash`:return(0,X.jsxs)(`div`,{className:`space-y-1`,children:[!!t.description&&(0,X.jsx)(`p`,{className:`text-text-subtle italic`,children:r(t.description)}),(0,X.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,X.jsxs)(`div`,{className:`space-y-1`,children:[(0,X.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,X.jsx)(h,{className:`size-3 shrink-0`}),n]}),e===`Edit`&&(!!t.old_string||!!t.new_string)&&(0,X.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,X.jsx)(p,{className:`size-3 shrink-0`}),`View Diff`]}),e===`Write`&&!!t.content&&(0,X.jsx)(`pre`,{className:`font-mono text-text-subtle overflow-x-auto max-h-32 whitespace-pre-wrap`,children:Z(r(t.content),300)})]})}case`Glob`:return(0,X.jsxs)(`p`,{className:`font-mono text-text-secondary`,children:[r(t.pattern),t.path?` in ${r(t.path)}`:``]});case`Grep`:return(0,X.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,X.jsxs)(`p`,{className:`font-mono text-text-secondary`,children:[`/`,r(t.pattern),`/`]}),!!t.path&&(0,X.jsxs)(`p`,{className:`text-text-subtle`,children:[`in `,r(t.path)]})]});case`TodoWrite`:return(0,X.jsx)(_t,{todos:t.todos??[]});case`Agent`:case`Task`:return(0,X.jsxs)(`div`,{className:`space-y-1`,children:[!!t.description&&(0,X.jsx)(`p`,{className:`text-text-secondary font-medium`,children:r(t.description)}),!!t.subagent_type&&(0,X.jsxs)(`p`,{className:`text-text-subtle`,children:[`Type: `,r(t.subagent_type)]}),!!t.prompt&&(0,X.jsx)(xt,{content:r(t.prompt),maxHeight:`max-h-48`})]});case`ToolSearch`:return(0,X.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,X.jsx)(`p`,{className:`font-mono text-text-secondary`,children:r(t.query)}),!!t.max_results&&(0,X.jsxs)(`p`,{className:`text-text-subtle`,children:[`Max results: `,r(t.max_results)]})]});case`WebFetch`:return(0,X.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,X.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,X.jsx)(G,{className:`size-3 shrink-0`}),r(t.url)]}),!!t.prompt&&(0,X.jsx)(`p`,{className:`text-text-subtle`,children:Z(r(t.prompt),100)})]});case`AskUserQuestion`:{let e=t.questions??[],n=t.answers??{};return(0,X.jsx)(`div`,{className:`space-y-2`,children:e.map((e,t)=>(0,X.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,X.jsxs)(`p`,{className:`text-text-primary font-medium`,children:[e.header?`${e.header}: `:``,e.question]}),(0,X.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:e.options.map((t,r)=>(0,X.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,X.jsxs)(`p`,{className:`text-foreground text-xs`,children:[`Answer: `,n[e.question]]})]},t))})}default:return(0,X.jsx)(`pre`,{className:`overflow-x-auto text-text-secondary font-mono whitespace-pre-wrap break-all`,children:JSON.stringify(t,null,2)})}}function _t({todos:e}){return(0,X.jsx)(`div`,{className:`space-y-0.5`,children:e.map((e,t)=>(0,X.jsxs)(`div`,{className:`flex items-start gap-1.5`,children:[(0,X.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,X.jsx)(`span`,{className:e.status===`completed`?`line-through text-text-subtle`:`text-text-secondary`,children:e.content})]},t))})}function vt({toolName:e,output:t}){let[n,r]=(0,J.useState)(!1),i=(0,J.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
+
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,X.jsxs)(`div`,{className:`border-t border-border pt-1.5 space-y-1`,children:[(0,X.jsx)(xt,{content:i,maxHeight:`max-h-60`}),(0,X.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,X.jsx)(d,{className:`size-3`}),n?`Hide`:`Show`,` raw`]}),n&&(0,X.jsx)(`pre`,{className:`overflow-x-auto text-text-subtle font-mono max-h-40 whitespace-pre-wrap break-all text-[10px]`,children:t})]}):(0,X.jsx)(yt,{output:t})}function yt({output:e}){let t=e.split(`
5
+ `).length,n=t>3||e.length>200,[r,i]=(0,J.useState)(n);return(0,X.jsxs)(`div`,{className:`border-t border-border pt-1.5`,children:[n&&(0,X.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,X.jsx)(u,{className:`size-3`}):(0,X.jsx)(o,{className:`size-3`}),`Output (`,t,` lines)`]}),(0,X.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 bt({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,X.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,X.jsx)(`div`,{className:`text-text-secondary text-[11px]`,children:(0,X.jsx)(xt,{content:e.content,maxHeight:`max-h-24`})},`st-${n}`):(0,X.jsx)(mt,{tool:e.tool,result:e.result,completed:!!e.result,projectName:t},`sc-${n}`))})}function xt({content:e,maxHeight:t=`max-h-48`}){return(0,X.jsx)(f,{content:e,className:`text-text-secondary overflow-auto ${t}`})}function Z(e,t=50){return e?e.length>t?e.slice(0,t)+`…`:e:``}function St(e){let[t,n]=(0,J.useState)({}),[r,i]=(0,J.useState)({}),[a,o]=(0,J.useState)(0),s=(0,J.useCallback)((e,t)=>{n(n=>({...n,[e]:[t]})),i(t=>({...t,[e]:``}))},[]),c=(0,J.useCallback)((e,t)=>{n(n=>{let r=n[e]||[];return{...n,[e]:r.includes(t)?r.filter(e=>e!==t):[...r,t]}})},[]),l=(0,J.useCallback)((e,t)=>{i(n=>({...n,[e]:t})),t&&n(t=>({...t,[e]:[]}))},[]),u=(0,J.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,J.useMemo)(()=>e.every((e,t)=>u(t)),[e,u]),getFinalAnswer:(0,J.useCallback)(e=>r[e]?.trim()||(t[e]??[]).join(`, `),[t,r]),goToNextTab:(0,J.useCallback)(()=>o(t=>Math.min(t+1,e.length-1)),[e.length]),goToPrevTab:(0,J.useCallback)(()=>o(e=>Math.max(e-1,0)),[])}}function Ct(e){let[t,n]=(0,J.useState)(0),r=(0,J.useRef)(null);return(0,J.useEffect)(()=>n(0),[e.activeTab]),(0,J.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 wt({questions:e,onSubmit:t,onSkip:n}){let r=(0,J.useRef)(null),i=St(e),a=e[i.activeTab],o=a?a.options.length+1:0,s=e.length>1,c=(0,J.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,J.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=Ct({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,J.useCallback)(e=>{l(e),u.setFocusedOption(e)},[l,u.setFocusedOption]);return(0,X.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,X.jsxs)(`div`,{className:`flex items-center justify-between text-sm font-medium text-text-primary`,children:[(0,X.jsxs)(`span`,{children:[`AI has `,s?`${e.length} questions`:`a question`]}),(0,X.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,X.jsx)(`div`,{className:`flex gap-1 p-1 bg-background rounded-md overflow-x-auto border border-border`,children:e.map((e,t)=>(0,X.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,X.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,X.jsx)(`span`,{className:`max-w-[100px] overflow-hidden text-ellipsis`,children:e.header||`Q${t+1}`})]},t))}),a&&(0,X.jsxs)(`div`,{className:`space-y-2`,children:[!s&&a.header&&(0,X.jsx)(`div`,{className:`text-[11px] font-semibold uppercase tracking-wide text-text-secondary`,children:a.header}),(0,X.jsx)(`div`,{className:`text-sm text-text-primary`,children:a.question}),a.multiSelect&&(0,X.jsx)(`div`,{className:`text-[11px] text-text-secondary`,children:`Select multiple`}),(0,X.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,X.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,X.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,X.jsxs)(`div`,{className:`flex flex-col gap-0.5 flex-1`,children:[(0,X.jsx)(`span`,{className:`font-medium text-text-primary`,children:e.label}),e.description&&(0,X.jsx)(`span`,{className:`text-[11px] text-text-secondary`,children:e.description})]})]},t)}),(0,X.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,X.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,X.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,X.jsxs)(`div`,{className:`flex gap-2 justify-end pt-1`,children:[s&&(0,X.jsxs)(X.Fragment,{children:[(0,X.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,X.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,X.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,X.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})`]})]})]})}function Tt({messages:e,messagesLoading:t,pendingApproval:n,onApprovalResponse:r,isStreaming:i,phase:a,connectingElapsed:o,projectName:s,onFork:c}){if(t)return(0,X.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full gap-3 text-text-secondary`,children:[(0,X.jsx)(ge,{className:`size-10 text-text-subtle animate-pulse`}),(0,X.jsx)(`p`,{className:`text-sm`,children:`Loading messages...`})]});if(e.length===0&&!i)return(0,X.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full gap-3 text-text-secondary`,children:[(0,X.jsx)(ge,{className:`size-10 text-text-subtle`}),(0,X.jsx)(`p`,{className:`text-sm`,children:`Send a message to start the conversation`})]});let l=(0,J.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]);return(0,X.jsx)(`div`,{className:`relative flex-1 overflow-hidden flex flex-col min-h-0`,children:(0,X.jsxs)(dt,{className:`flex-1 overflow-y-auto overflow-x-hidden`,resize:`smooth`,initial:`instant`,children:[(0,X.jsxs)(dt.Content,{className:`p-4 space-y-4`,children:[l.map(e=>(0,X.jsx)(Dt,{message:e,isStreaming:i&&e.id.startsWith(`streaming-`),projectName:s,onFork:e.role===`user`&&c?()=>c(e.content):void 0},e.id)),n&&(n.tool===`AskUserQuestion`?(0,X.jsx)(Xt,{approval:n,onRespond:r}):(0,X.jsx)(Yt,{approval:n,onRespond:r})),i&&(0,X.jsx)(qt,{lastMessage:e[e.length-1],phase:a,elapsed:o})]}),(0,X.jsx)(Et,{})]})})}function Et(){let{isAtBottom:e,scrollToBottom:t}=ft();return e?null:(0,X.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,X.jsx)(o,{className:`size-3`}),`Scroll to bottom`]})}function Dt({message:e,isStreaming:t,projectName:n,onFork:r}){return e.role===`user`?(0,X.jsx)(Ft,{content:e.content,projectName:n,onFork:r}):e.role===`system`?(0,X.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,X.jsx)(de,{className:`size-4 shrink-0`}),(0,X.jsx)(`p`,{children:e.content})]}):(0,X.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[e.events&&e.events.length>0?(0,X.jsx)(Wt,{events:e.events,isStreaming:t,projectName:n}):e.content&&(0,X.jsx)(`div`,{className:`text-sm text-text-primary`,children:(0,X.jsx)(Jt,{content:e.content,projectName:n})}),e.accountLabel&&(0,X.jsxs)(`p`,{className:`text-[10px] select-none`,style:{color:`var(--color-text-subtle)`},children:[`via `,e.accountLabel]})]})}var Ot=new Set([`.png`,`.jpg`,`.jpeg`,`.gif`,`.webp`]),kt={"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 At(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:kt[e]??e.replace(/^antml:/,``).replace(/-/g,` `),content:r[2].trim()})}return{cleanText:e.replace(n,``).trim(),tags:t}}function jt(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(`
6
+ `).map(e=>e.trim()).filter(Boolean),text:e.slice(n[0].length)}:{files:[],text:e}}function Mt(e,t){let n=x(e);return`/api/project/${encodeURIComponent(t??`_`)}/chat/uploads/${encodeURIComponent(n)}`}function Nt(e){let t=e.lastIndexOf(`.`);return t===-1?!1:Ot.has(e.slice(t).toLowerCase())}var Pt=new Set([`task-notification`,`environment_details`]);function Ft({content:e,projectName:t,onFork:n}){let{files:r,text:i,tags:a}=(0,J.useMemo)(()=>{let t=jt(e),{cleanText:n,tags:r}=At(t.text);return{files:t.files,text:n,tags:r}},[e]),s=a.some(e=>Pt.has(e.name)),[l,u]=(0,J.useState)(!1),[d,f]=(0,J.useState)(!1),p=(0,J.useRef)(null);return(0,J.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()},[i]),(0,X.jsxs)(`div`,{className:y(`group/user relative rounded-lg px-3 py-2 text-sm border shadow-sm`,s?`bg-surface/40 border-border/40 text-text-secondary`:`bg-primary/10 border-primary/15 text-text-primary`),children:[a.length>0&&(0,X.jsx)(It,{tags:a}),r.length>0&&(0,X.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:r.map((e,n)=>Nt(e)?(0,X.jsx)(Ut,{filePath:e,projectName:t},n):(0,X.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,X.jsx)(K,{className:`size-3 shrink-0`}),(0,X.jsx)(`span`,{className:`truncate max-w-32`,children:x(e)})]},n))}),i&&(0,X.jsx)(`div`,{ref:p,className:y(`whitespace-pre-wrap break-words transition-all duration-200`,!l&&`line-clamp-2`,l&&`max-h-[50vh] overflow-y-auto`),children:s?(0,X.jsx)(Vt,{text:i,projectName:t}):i}),(d||l)&&(0,X.jsx)(`button`,{onClick:()=>u(!l),className:y(`flex items-center gap-1 text-xs mt-1 transition-colors`,s?`text-text-subtle hover:text-text-secondary`:`text-primary/70 hover:text-primary`),children:l?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(xe,{className:`size-3`}),`Show less`]}):(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(o,{className:`size-3`}),`Show more`]})}),!s&&n&&(0,X.jsx)(`button`,{onClick:n,title:`Retry from this message (fork session)`,className:`absolute top-1.5 right-1.5 opacity-0 group-hover/user:opacity-100 transition-opacity size-5 flex items-center justify-center rounded text-text-subtle hover:text-text-primary`,children:(0,X.jsx)(c,{className:`size-3`})})]})}function It({tags:e}){return(0,X.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:e.map((e,t)=>(0,X.jsx)(Lt,{tag:e},t))})}function Lt({tag:e}){let[t,n]=(0,J.useState)(!1);return e.name===`task-notification`?(0,X.jsx)(zt,{content:e.content}):(0,X.jsxs)(`div`,{className:`text-xs`,children:[(0,X.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,X.jsx)(_,{className:`size-2.5`}),(0,X.jsx)(`span`,{children:e.label}),(0,X.jsx)(u,{className:y(`size-2.5 transition-transform`,t&&`rotate-90`)})]}),t&&(0,X.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 Rt(e,t){return e.match(RegExp(`<${t}>([\\s\\S]*?)</${t}>`))?.[1]?.trim()||void 0}function zt({content:e}){let[t,n]=(0,J.useState)(!1),r=Rt(e,`status`),i=Rt(e,`summary`),a=Rt(e,`output-file`),o=Rt(e,`result`);return(0,X.jsxs)(`div`,{className:`text-xs`,children:[(0,X.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,X.jsx)(se,{className:`size-2.5 text-green-500`}):(0,X.jsx)(Te,{className:`size-2.5 text-yellow-500`}),(0,X.jsx)(`span`,{className:`truncate max-w-80`,children:i??`Task notification`}),(0,X.jsx)(u,{className:y(`size-2.5 transition-transform shrink-0`,t&&`rotate-90`)})]}),t&&(0,X.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,X.jsx)(`p`,{className:`text-[11px] text-text-secondary`,children:i}),a&&(0,X.jsx)(Bt,{path:a}),o&&(0,X.jsx)(`div`,{className:`text-[11px] text-text-subtle/80 max-h-60 overflow-y-auto leading-relaxed`,children:(0,X.jsx)(Jt,{content:o})})]})]})}function Bt({path:e,projectName:t}){return(0,X.jsxs)(`button`,{type:`button`,onClick:(0,J.useCallback)(()=>{let n=g.getState().openTab,r=t??H.getState().activeProject?.name,i=x(e),a={filePath:e};r&&(a.projectName=r),w.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,X.jsx)(K,{className:`size-2.5 shrink-0`}),(0,X.jsx)(`span`,{className:`truncate max-w-60`,children:x(e)}),(0,X.jsx)(h,{className:`size-2 shrink-0 opacity-50`})]})}function Vt({text:e,projectName:t}){return(0,X.jsx)(X.Fragment,{children:(0,J.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,X.jsx)(Bt,{path:e.value,projectName:t},n):(0,X.jsx)(`span`,{children:e.value},n))})}function Ht(e){let[t,n]=(0,J.useState)(null),[r,i]=(0,J.useState)(!1);return(0,J.useEffect)(()=>{let t=!1,r,a=C();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 Ut({filePath:e,projectName:t}){let{blobUrl:n,error:r}=Ht(Mt(e,t)),i=pe(e=>e.open),a=x(e);return(0,X.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,X.jsx)(`img`,{src:n,alt:a,className:`size-4 rounded-sm object-cover shrink-0`}):r?(0,X.jsx)(Ae,{className:`size-3 shrink-0`}):(0,X.jsx)(`div`,{className:`size-4 rounded-sm bg-surface animate-pulse shrink-0`}),(0,X.jsx)(`span`,{className:`truncate max-w-32`,children:a})]})}function Wt({events:e,isStreaming:t,projectName:n}){let r=[],i=``,a=``;for(let t=0;t<e.length;t++){let n=e[t];if(n.type===`thinking`){i&&=(r.push({kind:`text`,content:i}),``),a+=n.content;continue}if(a&&=(r.push({kind:`thinking`,content:a}),``),n.type===`account_retry`){i&&=(r.push({kind:`text`,content:i}),``);let e=n.accountLabel??`another account`,t=n.reason??`Auth failed`;r.push({kind:`text`,content:`\n\n> ↻ ${t} — retrying with **${e}**...\n\n`});continue}n.type===`text`?i+=n.content:n.type===`tool_use`?(i&&=(r.push({kind:`text`,content:i}),``),r.push({kind:`tool`,tool:n})):n.type===`tool_result`||(i&&=(r.push({kind:`text`,content:i}),``),r.push({kind:`tool`,tool:n}))}a&&r.push({kind:`thinking`,content:a}),i&&r.push({kind:`text`,content:i});let o=e.filter(e=>e.type===`tool_result`);for(let e of o){let t=e.toolUseId;if(t){let n=r.find(e=>e.kind===`tool`&&e.tool.type===`tool_use`&&e.tool.toolUseId===t);if(n){n.result=e;continue}}let n=r.find(e=>e.kind===`tool`&&!e.result);n&&(n.result=e)}for(let e=0;e<r.length;e++){let n=r[e];if(n.kind===`tool`&&!n.result){let i=!1;if(n.tool.type===`tool_use`&&n.tool.tool===`Read`){let t=n.tool.input?.file_path;t&&(i=r.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=i||!t}}return(0,X.jsx)(X.Fragment,{children:r.map((e,i)=>{if(e.kind===`thinking`)return(0,X.jsx)(Gt,{content:e.content,isStreaming:t&&i===r.length-1},`think-${i}`);if(e.kind===`text`){let a=t&&i===r.length-1;return(0,X.jsx)(`div`,{className:`text-sm text-text-primary`,children:(0,X.jsx)(Kt,{content:e.content,animate:a,projectName:n})},`text-${i}`)}return(0,X.jsx)(mt,{tool:e.tool,result:e.result,completed:e.completed,projectName:n},`tool-${i}`)})})}function Gt({content:e,isStreaming:t}){let[n,r]=(0,J.useState)(t);return(0,J.useEffect)(()=>{!t&&e.length>0&&r(!1)},[t,e.length]),(0,X.jsxs)(`div`,{className:`rounded border border-border/50 bg-surface/30 text-xs`,children:[(0,X.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,X.jsx)(B,{className:`size-3 animate-spin`}):(0,X.jsx)(u,{className:`size-3 transition-transform ${n?`rotate-90`:``}`}),(0,X.jsxs)(`span`,{children:[`Thinking`,t?`...`:``]}),!t&&(0,X.jsx)(`span`,{className:`text-text-subtle/50 ml-auto`,children:e.length>100?`${Math.round(e.length/4)} tokens`:``})]}),n&&(0,X.jsx)(`div`,{className:`px-2 pb-2 text-text-subtle/80 whitespace-pre-wrap max-h-60 overflow-y-auto text-[11px] leading-relaxed`,children:e})]})}function Kt({content:e,animate:t,projectName:n}){return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(Jt,{content:e,projectName:n}),t&&(0,X.jsx)(`span`,{className:`text-text-subtle text-sm animate-pulse`,children:`Thinking...`})]})}function qt({lastMessage:e,phase:t,elapsed:n}){let r=!e||e.role!==`assistant`,i=e?.events?.length?e.events[e.events.length-1].type===`tool_result`:!1;return!r&&!i?null:(0,X.jsxs)(`div`,{className:`flex flex-col gap-1 text-sm`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2 text-text-subtle`,children:[(0,X.jsx)(B,{className:`size-3 animate-spin`}),(0,X.jsxs)(`span`,{children:[t===`initializing`?`Initializing`:t===`connecting`?`Connecting`:t===`thinking`?`Thinking`:`Processing`,r&&(n??0)>0&&(0,X.jsxs)(`span`,{className:`text-text-subtle/60`,children:[`... (`,n,`s)`]})]})]}),t===`connecting`&&(n??0)>=30&&(0,X.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.`})]})}function Jt({content:e,projectName:t}){return(0,X.jsx)(f,{content:e,projectName:t,codeActions:!0})}function Yt({approval:e,onRespond:t}){return(0,X.jsxs)(`div`,{className:`rounded-lg border-2 border-yellow-500/40 bg-yellow-500/10 p-3 space-y-2`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2 text-yellow-400 text-sm font-medium`,children:[(0,X.jsx)(Fe,{className:`size-4`}),(0,X.jsx)(`span`,{children:`Tool Approval Required`})]}),(0,X.jsx)(`div`,{className:`text-xs text-text-primary`,children:(0,X.jsx)(`span`,{className:`font-medium`,children:e.tool})}),(0,X.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,X.jsxs)(`div`,{className:`flex gap-2`,children:[(0,X.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,X.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 Xt({approval:e,onRespond:t}){return(0,X.jsx)(wt,{questions:e.input.questions??[],onSubmit:n=>t(e.requestId,!0,n),onSkip:()=>t(e.requestId,!1)})}function Zt(){let e=window;return e.SpeechRecognition??e.webkitSpeechRecognition??null}function Qt(e){let[t,n]=(0,J.useState)(!1),[r,i]=(0,J.useState)(``),a=(0,J.useRef)(null),o=(0,J.useRef)(``),s=typeof window<`u`&&Zt()!==null;return{isListening:t,interimText:r,start:(0,J.useCallback)(t=>{let r=Zt();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,J.useCallback)(()=>{a.current?.stop(),a.current=null,n(!1),i(``)},[]),supported:s}}var $t=new Set([`image/png`,`image/jpeg`,`image/gif`,`image/webp`]),en=new Set([`application/pdf`]),tn=[`text/`,`application/json`,`application/xml`,`application/javascript`,`application/typescript`,`application/x-yaml`,`application/toml`,`application/x-sh`],nn=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 rn(e){return $t.has(e.type)}function an(e){if($t.has(e.type)||en.has(e.type)||tn.some(t=>e.type.startsWith(t)))return!0;let t=on(e.name);return!!(t&&nn.has(t))}function on(e){let t=e.lastIndexOf(`.`);return t===-1?``:e.slice(t).toLowerCase()}function sn({attachments:e,onRemove:t}){return e.length===0?null:(0,X.jsx)(`div`,{className:`flex flex-wrap gap-1.5 px-2 md:px-4 pt-2`,children:e.map(e=>(0,X.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,X.jsx)(`img`,{src:e.previewUrl,alt:e.name,className:`size-5 rounded object-cover shrink-0`}):e.isImage?(0,X.jsx)(Ae,{className:`size-3.5 shrink-0 text-text-subtle`}):(0,X.jsx)(K,{className:`size-3.5 shrink-0 text-text-subtle`}),(0,X.jsx)(`span`,{className:`truncate`,children:e.name}),e.status===`uploading`?(0,X.jsx)(B,{className:`size-3 shrink-0 animate-spin text-text-subtle`}):e.status===`error`?(0,X.jsx)(`span`,{className:`text-red-500 shrink-0`,title:`Upload failed`,children:`!`}):null,(0,X.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,X.jsx)(I,{className:`size-3`})})]},e.id))})}var Q=[{id:`default`,label:`Ask before edits`,icon:Oe,description:`Claude will ask for approval before making each edit`},{id:`acceptEdits`,label:`Edit automatically`,icon:d,description:`Claude will edit files without asking first`},{id:`plan`,label:`Plan mode`,icon:De,description:`Claude will present a plan before editing`},{id:`bypassPermissions`,label:`Bypass permissions`,icon:Ie,description:`Claude will not ask before running commands`}];function cn(e){return Q.find(t=>t.id===e)?.label??`Unknown`}function ln(e){return Q.find(t=>t.id===e)?.icon??Oe}function un({value:e,onChange:t,open:n,onOpenChange:r}){let i=(0,J.useRef)(null),o=(0,J.useRef)(0);(0,J.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,J.useEffect)(()=>{n&&(o.current=Q.findIndex(t=>t.id===e),o.current<0&&(o.current=0))},[n,e]);let s=(0,J.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;o.current=(o.current+t+Q.length)%Q.length,(i.current?.querySelector(`[data-idx="${o.current}"]`))?.focus()}if(e.key===`Enter`){e.preventDefault();let n=Q[o.current];n&&(t(n.id),r(!1))}},[t,r]);return n?(0,X.jsxs)(`div`,{ref:i,role:`listbox`,"aria-label":`Permission modes`,onKeyDown:s,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,X.jsxs)(`div`,{className:`flex items-center justify-between px-3 py-2 border-b border-border`,children:[(0,X.jsx)(`span`,{className:`text-xs font-medium text-text-secondary`,children:`Modes`}),(0,X.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,X.jsx)(`div`,{className:`py-1`,children:Q.map((n,i)=>{let o=n.icon,s=n.id===e;return(0,X.jsxs)(`button`,{"data-idx":i,role:`option`,"aria-selected":s,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 ${s?`bg-surface-elevated`:``}`,children:[(0,X.jsx)(o,{className:`size-4 mt-0.5 shrink-0 text-text-secondary`}),(0,X.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,X.jsx)(`div`,{className:`text-sm font-medium text-text-primary`,children:n.label}),(0,X.jsx)(`div`,{className:`text-xs text-text-subtle leading-snug`,children:n.description})]}),s&&(0,X.jsx)(a,{className:`size-4 mt-0.5 shrink-0 text-primary`})]},n.id)})})]}):null}function dn(e){let t=[];function n(e){for(let r of e)t.push(r),r.children&&n(r.children)}return n(e),t}function fn({items:e,filter:t,onSelect:n,onClose:r,visible:i}){let[a,o]=(0,J.useState)(0),s=(0,J.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,J.useEffect)(()=>{o(0)},[t]),(0,J.useEffect)(()=>{let e=s.current;e&&e.children[a]?.scrollIntoView({block:`nearest`})},[a]);let l=(0,J.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,J.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,X.jsx)(`div`,{className:`max-h-52 overflow-y-auto border-b border-border bg-surface`,children:(0,X.jsx)(`div`,{ref:s,className:`py-1`,children:c.map((e,t)=>(0,X.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,X.jsx)(`span`,{className:`shrink-0`,children:e.type===`directory`?(0,X.jsx)(re,{className:`size-4 text-amber-500`}):(0,X.jsx)(W,{className:`size-4 text-blue-400`})}),(0,X.jsx)(`span`,{className:`text-sm truncate`,children:e.path})]},e.path))})})}var pn=(0,J.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,initialValue:p,autoFocus:m,permissionMode:h,onModeChange:g}){let[_,v]=(0,J.useState)(p??``),[y,x]=(0,J.useState)([]),[T,E]=(0,J.useState)(!1),[D,O]=(0,J.useState)(!1),k=(0,J.useRef)(null),A=(0,J.useRef)(null),j=(0,J.useRef)(null),M=(0,J.useRef)([]),N=(0,J.useRef)([]),P=Qt(),F=(0,J.useRef)(``),I=(0,J.useCallback)(e=>{let t=F.current;v(t?t+` `+e:e),requestAnimationFrame(()=>{let e=window.matchMedia(`(min-width: 768px)`).matches?k.current:A.current;e&&(e.style.height=`auto`,e.style.height=Math.min(e.scrollHeight,160)+`px`)})},[]),R=(0,J.useCallback)(()=>{P.isListening?P.stop():(F.current=_.trim(),P.start(I))},[P.isListening,P.start,P.stop,_,I]);(0,J.useEffect)(()=>{let e=()=>{P.supported&&R()};return window.addEventListener(`toggle-voice-input`,e),()=>window.removeEventListener(`toggle-voice-input`,e)},[P.supported,R]),(0,J.useEffect)(()=>{p&&(v(p),setTimeout(()=>{let e=k.current;e&&(e.focus(),e.selectionStart=e.selectionEnd=e.value.length)},50))},[p]),(0,J.useEffect)(()=>{m&&setTimeout(()=>{(window.matchMedia(`(min-width: 768px)`).matches?k.current:A.current)?.focus()},100)},[]),(0,J.useEffect)(()=>{if(!a){M.current=[],s?.([]);return}w.get(`${S(a)}/chat/slash-items`).then(e=>{M.current=e,s?.(e)}).catch(()=>{M.current=[],s?.([])})},[a]),(0,J.useEffect)(()=>{if(!a){N.current=[],u?.([]);return}w.get(`${S(a)}/files/tree?depth=5`).then(e=>{let t=dn(e);N.current=t,u?.(t)}).catch(()=>{N.current=[],u?.([])})},[a]),(0,J.useEffect)(()=>{if(!c)return;let e=k.current,t=e?.selectionStart??_.length,n=_.slice(0,t),r=_.slice(t),i=n.replace(/(?:^|\s)\/\S*$/,e=>`${e.startsWith(`/`)?``:e[0]}/${c.name} `);v(i+r),o?.(!1,``),l?.(!1,``),e&&(e.focus(),setTimeout(()=>{e.selectionStart=e.selectionEnd=i.length},0))},[c]),(0,J.useEffect)(()=>{if(!d)return;let e=k.current;if(!e)return;let t=e.selectionStart,n=_.slice(0,t),r=_.slice(t),i=n.match(/@(\S*)$/);if(i){let t=n.length-i[0].length;v(n.slice(0,t)+`@${d.path} `+r);let a=t+d.path.length+2;setTimeout(()=>{e.selectionStart=e.selectionEnd=a,e.focus()},0)}else{let t=_+`@${d.path} `;v(t),setTimeout(()=>{e.selectionStart=e.selectionEnd=t.length,e.focus()},0)}l?.(!1,``)},[d]),(0,J.useEffect)(()=>{!f||f.length===0||V(f)},[f]);let z=(0,J.useCallback)(async e=>{if(!a)return null;try{let t=new FormData;t.append(`files`,e);let n={},r=C();r&&(n.Authorization=`Bearer ${r}`);let i=await(await fetch(`${S(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]),V=(0,J.useCallback)(e=>{for(let t of e){if(!an(t)){v(e=>e+(e.length>0&&!e.endsWith(` `)?` `:``)+t.name);continue}let e=b(),n=rn(t),r=n?URL.createObjectURL(t):void 0,i={id:e,name:t.name,file:t,isImage:n,previewUrl:r,status:`uploading`};x(e=>[...e,i]),z(t).then(t=>{x(n=>n.map(n=>n.id===e?{...n,serverPath:t??void 0,status:t?`ready`:`error`}:n))})}(A.current??k.current)?.focus()},[z]),H=(0,J.useCallback)(e=>{x(t=>{let n=t.find(t=>t.id===e);return n?.previewUrl&&URL.revokeObjectURL(n.previewUrl),t.filter(t=>t.id!==e)})},[]),U=(0,J.useCallback)(()=>{let t=_.trim(),n=y.filter(e=>e.status===`ready`);if(!t&&n.length===0){O(!1);return}o?.(!1,``),l?.(!1,``),P.isListening&&P.stop(),e(t,n),v(``);for(let e of y)e.previewUrl&&URL.revokeObjectURL(e.previewUrl);x([]),O(!1),k.current&&(k.current.style.height=`auto`),A.current&&(A.current.style.height=`auto`)},[_,y,e,o,l]),W=(0,J.useCallback)(()=>{if(!r){if(y.some(e=>e.status===`uploading`)){(_.trim()||y.some(e=>e.status!==`error`))&&O(!0);return}U()}},[_,y,r,U]);(0,J.useEffect)(()=>{D&&(y.some(e=>e.status===`uploading`)||U())},[D,y,U]);let ee=(0,J.useCallback)(e=>{if(e.key===`Enter`&&!e.shiftKey){e.preventDefault(),W();return}if(e.shiftKey&&e.key===`Tab`){e.preventDefault();let t=[`default`,`acceptEdits`,`plan`,`bypassPermissions`],n=t[(t.indexOf(h??`bypassPermissions`)+1)%t.length];g?.(n)}},[W,h,g]),te=(0,J.useCallback)((e,t)=>{let n=e.slice(0,t),r=n.match(/(?:^|\s)\/(\S*)$/);if(r&&M.current.length>0){o?.(!0,r[1]??``),l?.(!1,``);return}let i=n.match(/@(\S*)$/);if(i&&N.current.length>0){l?.(!0,i[1]??``),o?.(!1,``);return}o?.(!1,``),l?.(!1,``)},[o,l]),ne=(0,J.useCallback)((e,t)=>{v(e),te(e,t)},[te]),G=(0,J.useCallback)(e=>{let t=e?.target??k.current;t&&(t.style.height=`auto`,t.style.height=Math.min(t.scrollHeight,160)+`px`)},[]),re=(0,J.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(),V(n))},[V]),ie=(0,J.useCallback)(e=>{e.preventDefault();let t=Array.from(e.dataTransfer.files);t.length>0&&V(t)},[V]),ae=(0,J.useCallback)(e=>{e.preventDefault()},[]),oe=(0,J.useCallback)(()=>{j.current?.click()},[]),se=(0,J.useCallback)(e=>{let t=Array.from(e.target.files??[]);t.length>0&&V(t),e.target.value=``},[V]),K=_.trim().length>0||y.some(e=>e.status!==`error`),q=t&&!K;return(0,X.jsxs)(`div`,{className:`p-2 md:p-3 bg-background`,children:[(0,X.jsxs)(`div`,{className:`border border-border rounded-xl md:rounded-2xl bg-surface shadow-sm cursor-text`,onClick:e=>{r||e.target instanceof HTMLTextAreaElement||(window.matchMedia(`(min-width: 768px)`).matches?k.current:A.current)?.focus()},children:[(0,X.jsx)(sn,{attachments:y,onRemove:H}),(0,X.jsxs)(`div`,{className:`flex items-center gap-1 px-2 pt-2 md:hidden relative`,children:[(0,X.jsx)(mn,{mode:h??`bypassPermissions`,onClick:()=>E(e=>!e)}),(0,X.jsx)(un,{value:h??`bypassPermissions`,onChange:e=>g?.(e),open:T,onOpenChange:E})]}),(0,X.jsxs)(`div`,{className:`flex items-end gap-1 md:hidden px-2 py-2`,children:[(0,X.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),oe()},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,X.jsx)(Ne,{className:`size-4`})}),P.supported&&(0,X.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),R()},disabled:r,className:`flex items-center justify-center size-7 shrink-0 rounded-full transition-colors disabled:opacity-50 ${P.isListening?`bg-red-600 text-white animate-pulse`:`text-text-subtle hover:text-text-primary`}`,"aria-label":P.isListening?`Stop voice input`:`Start voice input`,children:P.isListening?(0,X.jsx)(Me,{className:`size-4`}):(0,X.jsx)(L,{className:`size-4`})}),(0,X.jsx)(`textarea`,{ref:A,value:_,onChange:e=>{ne(e.target.value,e.target.selectionStart),G(e)},onKeyDown:ee,onPaste:re,onDrop:ie,onDragOver:ae,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`}),q?(0,X.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,X.jsx)(Re,{className:`size-3`})}):(0,X.jsx)(`button`,{onClick:e=>{e.stopPropagation(),D?O(!1):W()},disabled:r||!K,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":D?`Cancel queued send`:`Send`,children:D?(0,X.jsx)(B,{className:`size-3.5 animate-spin`}):(0,X.jsx)(i,{className:`size-3.5`})})]}),(0,X.jsxs)(`div`,{className:`hidden md:block`,children:[(0,X.jsx)(`textarea`,{ref:k,value:_,onChange:e=>{ne(e.target.value,e.target.selectionStart),G(e)},onKeyDown:ee,onPaste:re,onDrop:ie,onDragOver:ae,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`}),(0,X.jsxs)(`div`,{className:`flex items-center justify-between px-3 pb-2`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,X.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),oe()},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,X.jsx)(Ne,{className:`size-4`})}),P.supported&&(0,X.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),R()},disabled:r,className:`flex items-center justify-center size-8 rounded-full transition-colors disabled:opacity-50 ${P.isListening?`bg-red-600 text-white animate-pulse`:`text-text-subtle hover:text-text-primary hover:bg-surface-elevated`}`,"aria-label":P.isListening?`Stop voice input`:`Start voice input`,children:P.isListening?(0,X.jsx)(Me,{className:`size-4`}):(0,X.jsx)(L,{className:`size-4`})}),(0,X.jsxs)(`div`,{className:`relative`,children:[(0,X.jsx)(mn,{mode:h??`bypassPermissions`,onClick:()=>E(e=>!e)}),(0,X.jsx)(un,{value:h??`bypassPermissions`,onChange:e=>g?.(e),open:T,onOpenChange:E})]})]}),(0,X.jsx)(`div`,{className:`flex items-center gap-1`,children:q?(0,X.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,X.jsx)(Re,{className:`size-3.5`})}):(0,X.jsx)(`button`,{onClick:e=>{e.stopPropagation(),D?O(!1):W()},disabled:r||!K,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":D?`Cancel queued send`:`Send message`,children:D?(0,X.jsx)(B,{className:`size-4 animate-spin`}):(0,X.jsx)(i,{className:`size-4`})})})]})]})]}),(0,X.jsx)(`input`,{ref:j,type:`file`,multiple:!0,className:`hidden`,onChange:se})]})});function mn({mode:e,onClick:t}){let n=ln(e),r=cn(e);return(0,X.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,X.jsx)(n,{className:`size-3`}),(0,X.jsx)(`span`,{className:`max-w-[100px] truncate`,children:r})]})}function hn({items:e,filter:t,onSelect:n,onClose:r,visible:i}){let[a,o]=(0,J.useState)(0),s=(0,J.useRef)(null),c=e.filter(e=>{let n=t.toLowerCase();return e.name.toLowerCase().includes(n)||e.description.toLowerCase().includes(n)});(0,J.useEffect)(()=>{o(0)},[t]),(0,J.useEffect)(()=>{let e=s.current;e&&e.children[a]?.scrollIntoView({block:`nearest`})},[a]);let l=(0,J.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,J.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,X.jsx)(`div`,{className:`max-h-52 overflow-y-auto border-b border-border bg-surface`,children:(0,X.jsx)(`div`,{ref:s,className:`py-1`,children:c.map((e,t)=>(0,X.jsxs)(`button`,{className:`flex items-start gap-3 w-full px-3 py-2 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,X.jsx)(`span`,{className:`shrink-0 mt-0.5`,children:e.type===`skill`?(0,X.jsx)(Le,{className:`size-4 text-amber-500`}):(0,X.jsx)(ee,{className:`size-4 text-blue-500`})}),(0,X.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,X.jsxs)(`div`,{className:`flex items-baseline gap-2`,children:[(0,X.jsxs)(`span`,{className:`font-medium text-sm`,children:[`/`,e.name]}),e.argumentHint&&(0,X.jsx)(`span`,{className:`text-xs text-text-subtle`,children:e.argumentHint}),(0,X.jsx)(`span`,{className:`text-xs text-text-subtle capitalize ml-auto`,children:e.scope===`user`?`global`:e.type})]}),e.description&&(0,X.jsx)(`p`,{className:`text-xs text-text-subtle mt-0.5 line-clamp-2`,children:e.description})]})]},`${e.type}-${e.name}`))})})}var gn=`ppm-hienlh`;function _n({open:e,onOpenChange:t,onSuccess:n}){let[r,i]=(0,J.useState)(``),[a,o]=(0,J.useState)(``),[c,u]=(0,J.useState)(!1),[d,f]=(0,J.useState)(null),[p,m]=(0,J.useState)(null),[h,g]=(0,J.useState)(``),[_,v]=(0,J.useState)(!1),[y,b]=(0,J.useState)(`idle`);function x(){m(null),g(``),b(`idle`),f(null)}function S(){t(!1),x(),i(``),o(``),f(null)}async function C(){v(!0),f(null);try{let{url:e,state:t}=await E();m(t),b(`waiting`),window.open(e,`_blank`)}catch(e){f(e.message)}v(!1)}async function w(){if(!(!h.trim()||!p)){v(!0),f(null);try{let e=h.trim();e.includes(`#`)&&(e=e.split(`#`)[0]??e),await A(e,p),S(),n(`Account connected via OAuth!`)}catch(e){f(e.message)}v(!1)}}async function T(){if(r.trim()){u(!0),f(null);try{await M({apiKey:r.trim(),label:a.trim()||void 0}),S(),n(`Account added!`)}catch(e){f(e.message)}u(!1)}}let D=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,X.jsx)(le,{open:e,onOpenChange:e=>{e||S()},children:(0,X.jsxs)(ce,{className:`sm:max-w-md`,children:[(0,X.jsxs)(Ce,{children:[(0,X.jsx)(oe,{className:`text-sm`,children:`Add Claude Account`}),(0,X.jsx)(ie,{className:`text-xs leading-relaxed`,children:`Connect via OAuth (recommended) or paste a token manually.`})]}),(0,X.jsxs)(`div`,{className:`space-y-3`,children:[(0,X.jsxs)(`div`,{className:`rounded-md border p-3 space-y-2`,children:[(0,X.jsx)(`p`,{className:`text-[11px] font-medium`,children:`Recommended: Login with Claude`}),y===`idle`?(0,X.jsx)(s,{size:`sm`,className:`w-full h-8 text-xs`,onClick:C,disabled:_,children:_?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(B,{className:`size-3 animate-spin mr-1`}),` Opening...`]}):`Login with Claude`}):(0,X.jsxs)(`div`,{className:`space-y-2`,children:[(0,X.jsx)(`p`,{className:`text-[10px] text-muted-foreground`,children:`Authorize in the opened tab, then paste the code:`}),(0,X.jsx)(l,{placeholder:`Paste code here...`,value:h,onChange:e=>g(e.target.value),className:`text-xs h-8 font-mono`,autoFocus:!0}),(0,X.jsxs)(`div`,{className:`flex gap-1.5`,children:[(0,X.jsx)(s,{size:`sm`,className:`flex-1 h-7 text-xs`,onClick:w,disabled:!h.trim()||_,children:_?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(B,{className:`size-3 animate-spin mr-1`}),` Connecting...`]}):`Connect`}),(0,X.jsx)(s,{size:`sm`,variant:`ghost`,className:`h-7 text-xs`,onClick:x,children:`Cancel`})]})]})]}),(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsx)(`div`,{className:`flex-1 border-t`}),(0,X.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:`or paste token`}),(0,X.jsx)(`div`,{className:`flex-1 border-t`})]}),(0,X.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,X.jsx)(be,{htmlFor:`add-token`,className:`text-xs`,children:`Token`}),(0,X.jsx)(l,{id:`add-token`,type:`password`,placeholder:`sk-ant-...`,value:r,onChange:e=>i(e.target.value),className:`text-xs h-8 font-mono`}),D&&(0,X.jsxs)(`p`,{className:`text-[10px] text-muted-foreground`,children:[`Detected: `,D]})]}),(0,X.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,X.jsx)(be,{htmlFor:`add-label`,className:`text-xs`,children:`Label (optional)`}),(0,X.jsx)(l,{id:`add-label`,placeholder:`e.g. Personal, Work`,value:a,onChange:e=>o(e.target.value),className:`text-xs h-8`})]})]}),d&&(0,X.jsx)(`div`,{className:`text-[11px] p-2 rounded bg-red-500/10 text-red-600`,children:d}),(0,X.jsxs)(Se,{children:[(0,X.jsx)(s,{size:`sm`,variant:`outline`,className:`text-xs h-7`,onClick:S,children:`Cancel`}),(0,X.jsx)(s,{size:`sm`,className:`text-xs h-7`,onClick:T,disabled:!r.trim()||c,children:c?`Adding...`:`Add Token`})]})]})})}function vn({open:e,onOpenChange:t,accounts:n,preselectId:r,onMessage:i}){let a=n.filter(e=>e.hasRefreshToken),[o,c]=(0,J.useState)(new Set),[u,d]=(0,J.useState)(``),[f,p]=(0,J.useState)(!1),[m,h]=(0,J.useState)(!1),[g,_]=(0,J.useState)(!1),[v,y]=(0,J.useState)(!1);e&&!v&&(c(r?new Set([r]):new Set(a.map(e=>e.id))),y(!0)),!e&&v&&y(!1);function b(){t(!1),d(``),p(!1),h(!1)}async function x(e){if(o.size===0)return;_(!0);let t=u.trim()||gn;try{let n={"Content-Type":`application/json`},r=C();r&&(n.Authorization=`Bearer ${r}`);let a=await fetch(`/api/accounts/export`,{method:`POST`,headers:n,body:JSON.stringify({password:t,accountIds:[...o],includeRefreshToken:f,refreshBeforeExport:m})});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{bn(s),i?.(`Backup downloaded.`)}else bn(s),i?.(`Backup downloaded.`);b()}catch{}_(!1)}let S=o.size>0&&!g;return(0,X.jsx)(le,{open:e,onOpenChange:e=>{e||b()},children:(0,X.jsxs)(ce,{className:`sm:max-w-md`,children:[(0,X.jsxs)(Ce,{children:[(0,X.jsxs)(oe,{className:`text-sm flex items-center gap-1.5`,children:[(0,X.jsx)(_e,{className:`size-3.5`}),` Export Accounts`]}),(0,X.jsx)(ie,{className:`text-xs`,children:`Select accounts and set a password to protect the backup.`})]}),(0,X.jsxs)(`div`,{className:`space-y-3`,children:[(0,X.jsxs)(`div`,{className:`space-y-1`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between mb-1`,children:[(0,X.jsx)(`p`,{className:`text-[11px] font-medium text-muted-foreground`,children:`Accounts to export`}),(0,X.jsx)(`button`,{className:`text-[10px] text-primary hover:underline cursor-pointer`,onClick:()=>c(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,X.jsx)(`p`,{className:`text-[10px] text-muted-foreground p-2 border rounded`,children:`No exportable accounts.`}):(0,X.jsx)(`div`,{className:`max-h-36 overflow-y-auto space-y-1 border rounded p-2`,children:a.map(e=>(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.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),c(n)},className:`size-3.5 accent-primary cursor-pointer`}),(0,X.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,X.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,X.jsxs)(be,{className:`text-xs`,children:[`Password `,(0,X.jsx)(`span`,{className:`text-muted-foreground font-normal`,children:`(optional)`})]}),(0,X.jsx)(l,{type:`password`,placeholder:`Leave empty for default`,value:u,onChange:e=>d(e.target.value),className:`text-xs h-8`,autoComplete:`new-password`})]}),(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsx)(`input`,{type:`checkbox`,id:`exp-full`,checked:f,onChange:e=>p(e.target.checked),className:`size-3.5 accent-primary cursor-pointer`}),(0,X.jsx)(`label`,{htmlFor:`exp-full`,className:`text-[11px] cursor-pointer`,children:`Include refresh tokens (full transfer)`})]}),(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsx)(`input`,{type:`checkbox`,id:`exp-refresh`,checked:m,onChange:e=>h(e.target.checked),className:`size-3.5 accent-primary cursor-pointer`}),(0,X.jsx)(`label`,{htmlFor:`exp-refresh`,className:`text-[11px] cursor-pointer`,children:`Refresh tokens before export`})]}),f?(0,X.jsxs)(`div`,{className:`rounded-md border border-red-500/30 bg-red-500/5 p-2.5`,children:[(0,X.jsx)(`p`,{className:`text-[10px] font-medium text-red-600`,children:`Full transfer — source accounts will expire`}),(0,X.jsx)(`p`,{className:`text-[10px] text-muted-foreground`,children:`Refresh tokens included. Source machine expires in ~1h after target refreshes.`})]}):m?(0,X.jsx)(`div`,{className:`rounded-md border border-amber-500/30 bg-amber-500/5 p-2.5`,children:(0,X.jsx)(`p`,{className:`text-[10px] font-medium text-amber-600`,children:`Refresh before export — invalidates previous shares`})}):(0,X.jsx)(`div`,{className:`rounded-md border border-green-500/30 bg-green-500/5 p-2.5`,children:(0,X.jsx)(`p`,{className:`text-[10px] font-medium text-green-600`,children:`Share current token (safe)`})}),(0,X.jsx)(`p`,{className:`text-[10px] text-muted-foreground`,children:`Encrypted with AES-256-GCM + scrypt.`})]}),(0,X.jsxs)(Se,{className:`gap-1.5 flex-col sm:flex-row`,children:[(0,X.jsx)(s,{size:`sm`,variant:`outline`,className:`text-xs h-7 cursor-pointer`,onClick:b,children:`Cancel`}),(0,X.jsxs)(s,{size:`sm`,variant:`outline`,className:`text-xs h-7 cursor-pointer`,disabled:!S,onClick:()=>x(!0),children:[(0,X.jsx)(he,{className:`size-3 mr-1`}),` Copy`]}),(0,X.jsx)(s,{size:`sm`,className:`text-xs h-7 cursor-pointer`,disabled:!S,onClick:()=>x(!1),children:g?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(B,{className:`size-3 animate-spin mr-1`}),` Exporting...`]}):(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(ue,{className:`size-3 mr-1`}),` Download`]})})]})]})})}function yn({open:e,onOpenChange:t,onSuccess:n}){let[r,i]=(0,J.useState)(``),[a,o]=(0,J.useState)(``),[c,u]=(0,J.useState)(!1),[d,f]=(0,J.useState)(null);function p(){t(!1),i(``),o(``),f(null)}async function m(){if(r.trim()){u(!0),f(null);try{let e=await N({data:r.trim(),password:a.trim()||gn});p(),n(`Imported ${e.imported} account(s)`)}catch(e){f(e.message||`Import failed`)}u(!1)}}return(0,X.jsx)(le,{open:e,onOpenChange:e=>{e||p()},children:(0,X.jsxs)(ce,{className:`sm:max-w-md`,children:[(0,X.jsxs)(Ce,{children:[(0,X.jsxs)(oe,{className:`text-sm flex items-center gap-1.5`,children:[(0,X.jsx)(_e,{className:`size-3.5`}),` Import Accounts`]}),(0,X.jsx)(ie,{className:`text-xs`,children:`Paste backup data and enter the export password. Imported accounts are temporary (~1h).`})]}),(0,X.jsxs)(`div`,{className:`space-y-3`,children:[(0,X.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,X.jsx)(be,{className:`text-xs`,children:`Backup data`}),(0,X.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,X.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,X.jsxs)(be,{className:`text-xs`,children:[`Password `,(0,X.jsx)(`span`,{className:`text-muted-foreground font-normal`,children:`(optional)`})]}),(0,X.jsx)(l,{type:`password`,placeholder:`Leave empty for default`,value:a,onChange:e=>o(e.target.value),className:`text-xs h-8`,autoComplete:`current-password`})]})]}),d&&(0,X.jsx)(`div`,{className:`text-[11px] p-2 rounded bg-red-500/10 text-red-600`,children:d}),(0,X.jsxs)(Se,{children:[(0,X.jsx)(s,{size:`sm`,variant:`outline`,className:`text-xs h-7 cursor-pointer`,onClick:p,children:`Cancel`}),(0,X.jsx)(s,{size:`sm`,className:`text-xs h-7 cursor-pointer`,disabled:!r.trim()||c,onClick:m,children:c?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(B,{className:`size-3 animate-spin mr-1`}),` Importing...`]}):`Import`})]})]})})}function bn(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)}function xn(e){return e>=90?`text-red-500`:e>=70?`text-amber-500`:`text-green-500`}function Sn(e){return e>=90?`bg-red-500`:e>=70?`bg-amber-500`:`bg-green-500`}function Cn(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 $({label:e,bucket:t}){if(!t)return null;let n=Math.round(t.utilization*100),r=Cn(t);return(0,X.jsxs)(`div`,{className:`space-y-1`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,X.jsx)(`span`,{className:`text-xs font-medium text-text-primary`,children:e}),r&&(0,X.jsxs)(`span`,{className:`text-[10px] text-text-subtle`,title:`Resets in`,children:[`↻ `,r]})]}),(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsx)(`div`,{className:`flex-1 h-2 rounded-full bg-border overflow-hidden`,children:(0,X.jsx)(`div`,{className:`h-full rounded-full transition-all ${Sn(n)}`,style:{width:`${Math.min(n,100)}%`}})}),(0,X.jsxs)(`span`,{className:`text-xs font-medium tabular-nums w-10 text-right ${xn(n)}`,children:[n,`%`]})]})]})}function wn(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 Tn(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 En(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 Dn({entry:e,isActive:t,accountInfo:n,onToggle:r,onExport:i,onViewProfile:a,flash:o}){let{usage:s}=e,c=s.session||s.weekly||s.weeklyOpus||s.weeklySonnet,l=n?.status??e.accountStatus;return(0,X.jsxs)(`div`,{className:`rounded-md border p-2 space-y-1.5 transition-colors duration-500 min-w-[200px] shrink-0 snap-start ${o?`bg-primary/10 border-primary/40`:``} ${t?`border-primary/30 bg-primary/5`:`border-border/50`}`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,X.jsx)(`span`,{className:`text-xs font-medium truncate flex-1 min-w-0`,children:e.accountLabel??e.accountId.slice(0,8)}),!e.isOAuth&&(0,X.jsx)(`span`,{className:`text-[9px] text-text-subtle shrink-0`,children:`API key`}),(0,X.jsxs)(`div`,{className:`flex items-center gap-0.5 shrink-0`,children:[a&&n?.profileData&&(0,X.jsx)(`button`,{className:`p-1 rounded cursor-pointer text-text-subtle hover:text-foreground hover:bg-surface-elevated transition-colors`,onClick:()=>a(n.profileData),title:`View profile`,children:(0,X.jsx)(ye,{className:`size-3`})}),i&&e.isOAuth&&(0,X.jsx)(`button`,{className:`p-1 rounded cursor-pointer text-text-subtle hover:text-blue-500 hover:bg-surface-elevated transition-colors`,onClick:()=>i(e.accountId),title:`Export this account`,children:(0,X.jsx)(ue,{className:`size-3`})}),r&&(0,X.jsx)(ae,{checked:l!==`disabled`,onCheckedChange:()=>r(e.accountId,l),disabled:l===`cooldown`,className:`scale-[0.6] cursor-pointer`})]})]}),c?(0,X.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,X.jsx)($,{label:`5-Hour Session`,bucket:s.session}),(0,X.jsx)($,{label:`Weekly`,bucket:s.weekly}),(0,X.jsx)($,{label:`Weekly (Opus)`,bucket:s.weeklyOpus}),(0,X.jsx)($,{label:`Weekly (Sonnet)`,bucket:s.weeklySonnet})]}):(0,X.jsx)(`p`,{className:`text-[10px] text-text-subtle`,children:e.isOAuth?`No usage data yet`:`Usage tracking not available for API keys`}),(()=>{let e=Tn(n);return(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[9px] text-text-subtle flex-wrap`,children:[s.lastFetchedAt&&(0,X.jsxs)(`span`,{title:`Last usage data update`,children:[`↻ `,En(new Date(s.lastFetchedAt).getTime())]}),n?.expiresAt&&n.expiresAt*1e3>Date.now()&&(0,X.jsxs)(`span`,{title:`Token expires in`,children:[`⏱ `,wn(n.expiresAt*1e3)]}),(0,X.jsxs)(`span`,{className:e.color,title:e.tip,children:[`© `,e.label]})]})})()]})}function On({usage:e,visible:t,onClose:n,onReload:r,loading:i,lastFetchedAt:a}){let[o,s]=(0,J.useState)([]),[c,l]=(0,J.useState)([]),[u,d]=(0,J.useState)(null),[f,p]=(0,J.useState)(!0),[m,h]=(0,J.useState)(!1),[g,_]=(0,J.useState)(new Set),[v,y]=(0,J.useState)(null),[b,x]=(0,J.useState)(!1),[S,C]=(0,J.useState)(!1),[w,E]=(0,J.useState)(!1),[O,A]=(0,J.useState)(null),[M,N]=(0,J.useState)(null),P=(0,J.useRef)(void 0),F=(0,J.useRef)([]);function L(e){P.current&&clearTimeout(P.current),N(e),P.current=setTimeout(()=>N(null),4e3)}function B(e){V(),e&&L(e)}async function V(){let e=o.length>0;e?h(!0):p(!0);let[t,n,r]=await Promise.allSettled([j(),T(),k()]);if(t.status===`fulfilled`){let n=t.value;if(e&&F.current.length>0){let e=new Set,t=new Map(F.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))}F.current=n,s(n)}n.status===`fulfilled`&&l(n.value),r.status===`fulfilled`&&d(r.value?.id??null),p(!1),h(!1)}if((0,J.useEffect)(()=>{t&&V()},[t]),(0,J.useEffect)(()=>{!t||!a||V()},[a]),!t)return null;let H=new Map(c.map(e=>[e.id,e])),U=e.queryCostUsd!=null||e.totalCostUsd!=null,W=o.length>0;async function ee(e,t){await D(e,{status:t===`disabled`?`active`:`disabled`}),V(),r?.()}function te(){A(null),C(!0)}return(0,X.jsxs)(`div`,{className:`border-b border-border bg-surface px-3 py-2.5 space-y-2.5 max-h-[350px] overflow-y-auto`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsx)(`span`,{className:`text-xs font-semibold text-text-primary`,children:`Usage & Accounts`}),a&&(0,X.jsx)(`span`,{className:`text-[10px] text-text-subtle`,children:En(new Date(a).getTime())})]}),(0,X.jsxs)(`div`,{className:`flex items-center gap-1`,children:[r&&(0,X.jsx)(`button`,{onClick:()=>{r(),V()},disabled:i||m,className:`text-xs text-text-subtle hover:text-text-primary px-1 disabled:opacity-50 cursor-pointer`,title:`Refresh`,children:(0,X.jsx)(ne,{className:`size-3 ${i||m?`animate-spin`:``}`})}),(0,X.jsx)(`button`,{onClick:n,className:`text-xs text-text-subtle hover:text-text-primary px-1 cursor-pointer`,children:(0,X.jsx)(I,{className:`size-3`})})]})]}),M&&(0,X.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:M}),W||f?(0,X.jsx)(`div`,{className:`flex gap-1.5 overflow-x-auto pb-1 -mx-3 px-3 snap-x snap-mandatory scrollbar-thin`,children:f?(0,X.jsx)(`p`,{className:`text-[10px] text-text-subtle`,children:`Loading...`}):o.map(t=>(0,X.jsx)(Dn,{entry:t,isActive:t.accountId===(u??e.activeAccountId),accountInfo:H.get(t.accountId),onToggle:ee,onExport:e=>{A(e),C(!0)},onViewProfile:y,flash:g.has(t.accountId)},t.accountId))}):(0,X.jsx)(X.Fragment,{children:e.session||e.weekly||e.weeklyOpus||e.weeklySonnet?(0,X.jsxs)(`div`,{className:`space-y-2.5`,children:[(0,X.jsx)($,{label:`5-Hour Session`,bucket:e.session}),(0,X.jsx)($,{label:`Weekly`,bucket:e.weekly}),(0,X.jsx)($,{label:`Weekly (Opus)`,bucket:e.weeklyOpus}),(0,X.jsx)($,{label:`Weekly (Sonnet)`,bucket:e.weeklySonnet})]}):(0,X.jsx)(`p`,{className:`text-xs text-text-subtle`,children:`No usage data available`})}),U&&(0,X.jsxs)(`div`,{className:`border-t border-border pt-2 space-y-1`,children:[e.queryCostUsd!=null&&(0,X.jsxs)(`div`,{className:`flex items-center justify-between text-xs`,children:[(0,X.jsx)(`span`,{className:`text-text-subtle`,children:`Last query`}),(0,X.jsxs)(`span`,{className:`text-text-primary font-medium tabular-nums`,children:[`$`,e.queryCostUsd.toFixed(4)]})]}),e.totalCostUsd!=null&&(0,X.jsxs)(`div`,{className:`flex items-center justify-between text-xs`,children:[(0,X.jsx)(`span`,{className:`text-text-subtle`,children:`Session total`}),(0,X.jsxs)(`span`,{className:`text-text-primary font-medium tabular-nums`,children:[`$`,e.totalCostUsd.toFixed(4)]})]})]}),v&&(0,X.jsxs)(`div`,{className:`border-t border-border pt-2`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between mb-1`,children:[(0,X.jsx)(`span`,{className:`text-[10px] font-medium text-text-subtle`,children:`Profile`}),(0,X.jsx)(`button`,{className:`text-text-subtle hover:text-foreground cursor-pointer`,onClick:()=>y(null),children:(0,X.jsx)(I,{className:`size-3`})})]}),(0,X.jsxs)(`div`,{className:`grid grid-cols-[70px_1fr] gap-x-2 gap-y-0.5 text-[10px]`,children:[v.account?.display_name&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`span`,{className:`text-text-subtle`,children:`Name`}),(0,X.jsx)(`span`,{children:v.account.display_name})]}),v.account?.email&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`span`,{className:`text-text-subtle`,children:`Email`}),(0,X.jsx)(`span`,{children:v.account.email})]}),v.organization?.name&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`span`,{className:`text-text-subtle`,children:`Org`}),(0,X.jsx)(`span`,{children:v.organization.name})]}),v.organization?.organization_type&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`span`,{className:`text-text-subtle`,children:`Type`}),(0,X.jsx)(`span`,{children:v.organization.organization_type})]}),v.organization?.rate_limit_tier&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`span`,{className:`text-text-subtle`,children:`Tier`}),(0,X.jsx)(`span`,{children:v.organization.rate_limit_tier})]}),v.organization?.subscription_status&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`span`,{className:`text-text-subtle`,children:`Status`}),(0,X.jsx)(`span`,{children:v.organization.subscription_status})]})]})]}),(0,X.jsxs)(`div`,{className:`border-t border-border pt-2 flex gap-1.5`,children:[(0,X.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,X.jsx)(R,{className:`size-3`}),` Add`]}),(0,X.jsxs)(`button`,{onClick:te,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,X.jsx)(ue,{className:`size-3`}),` Export`]}),(0,X.jsxs)(`button`,{onClick:()=>E(!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,X.jsx)(z,{className:`size-3`}),` Import`]})]}),(0,X.jsx)(_n,{open:b,onOpenChange:x,onSuccess:B}),(0,X.jsx)(vn,{open:S,onOpenChange:e=>{C(e),e||A(null)},accounts:c,preselectId:O,onMessage:L}),(0,X.jsx)(yn,{open:w,onOpenChange:E,onSuccess:B})]})}function kn(e){try{return new Date(e).toLocaleDateString(void 0,{month:`short`,day:`numeric`})}catch{return``}}function An(e){return e>=90?`text-red-500`:e>=70?`text-amber-500`:`text-green-500`}function jn({sessionId:e,projectName:t}){let[n,r]=(0,J.useState)(!1);return(0,X.jsx)(`button`,{onClick:async()=>{try{let n=await w.get(`${S(t)}/chat/sessions/${e}/debug?project=${encodeURIComponent(t)}`),i=[`PPM Session: ${n.ppmSessionId}`,`SDK Session: ${n.sdkSessionId}`,n.jsonlPath?`JSONL: ${n.jsonlPath}`:`JSONL: not found`,n.projectPath?`Project: ${n.projectPath}`:null].filter(Boolean).join(`
7
+ `);await navigator.clipboard.writeText(i),r(!0),setTimeout(()=>r(!1),1500)}catch{}},className:`p-1 rounded transition-colors ${n?`text-green-500 bg-green-500/10`:`text-text-subtle hover:text-text-secondary hover:bg-surface-elevated`}`,title:n?`Copied!`:`Copy session debug info`,children:n?(0,X.jsx)(Ee,{className:`size-3`}):(0,X.jsx)(q,{className:`size-3`})})}function Mn({projectName:e,usageInfo:t,contextWindowPct:n,usageLoading:r,refreshUsage:i,lastFetchedAt:o,sessionId:s,onSelectSession:c,onBugReport:l,isConnected:u,onReconnect:d}){let[f,p]=(0,J.useState)(null),[m,h]=(0,J.useState)([]),[_,v]=(0,J.useState)(!1),y=F(e=>s?e.notifications.has(s):!1),b=F(e=>e.clearForSession),[x,C]=(0,J.useState)(``),[T,E]=(0,J.useState)(null),[D,O]=(0,J.useState)(``),k=(0,J.useRef)(null),A=g(e=>e.openTab),j=e=>{p(t=>t===e?null:e)},M=(0,J.useCallback)(async()=>{if(e){v(!0);try{h(await w.get(`${S(e)}/chat/sessions`))}catch{}finally{v(!1)}}},[e]);(0,J.useEffect)(()=>{f===`history`&&m.length===0&&M()},[f]);function N(t){c?(c(t),p(null)):A({type:`chat`,title:t.title||`Chat`,projectId:e??null,metadata:{projectName:e,sessionId:t.id},closable:!0})}let L=(0,J.useCallback)((e,t)=>{t.stopPropagation(),E(e.id),O(e.title||``),setTimeout(()=>k.current?.select(),0)},[]),R=(0,J.useCallback)(async()=>{if(!T||!D.trim()||!e){E(null);return}try{await w.patch(`${S(e)}/chat/sessions/${T}`,{title:D.trim()}),h(e=>e.map(e=>e.id===T?{...e,title:D.trim()}:e))}catch{}E(null)},[T,D,e]),z=(0,J.useCallback)(()=>E(null),[]),H=x.trim()?m.filter(e=>(e.title||``).toLowerCase().includes(x.toLowerCase())):m,U=t.fiveHour==null?null:Math.round(t.fiveHour*100),W=t.sevenDay==null?null:Math.round(t.sevenDay*100),ee=U!=null||W!=null?An(Math.max(U??0,W??0)):`text-text-subtle`;return(0,X.jsxs)(`div`,{className:`border-b border-border/50`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-1 px-2 py-1`,children:[(0,X.jsxs)(`button`,{onClick:()=>j(`history`),className:`flex items-center gap-1 px-1.5 py-0.5 rounded text-[11px] transition-colors ${f===`history`?`text-primary bg-primary/10`:`text-text-secondary hover:text-foreground hover:bg-surface-elevated`}`,children:[(0,X.jsx)(ke,{className:`size-3`}),(0,X.jsx)(`span`,{children:`History`})]}),(0,X.jsx)(`button`,{onClick:()=>j(`config`),className:`p-1 rounded transition-colors ${f===`config`?`text-primary bg-primary/10`:`text-text-subtle hover:text-text-secondary hover:bg-surface-elevated`}`,title:`AI Settings`,children:(0,X.jsx)(Pe,{className:`size-3`})}),(0,X.jsxs)(`button`,{onClick:()=>j(`usage`),className:`flex items-center gap-1 px-1.5 py-0.5 rounded text-[11px] font-medium tabular-nums transition-colors hover:bg-surface-elevated ${f===`usage`?`bg-primary/10`:``} ${ee}`,title:`Usage limits`,children:[(0,X.jsx)(we,{className:`size-3`}),t.activeAccountLabel&&(0,X.jsxs)(`span`,{className:`text-text-secondary font-normal truncate max-w-[60px]`,children:[`[`,t.activeAccountLabel,`]`]}),(0,X.jsxs)(`span`,{children:[`5h:`,U==null?`--%`:`${U}%`]}),(0,X.jsx)(`span`,{className:`text-text-subtle`,children:`·`}),(0,X.jsxs)(`span`,{children:[`Wk:`,W==null?`--%`:`${W}%`]}),n!=null&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`span`,{className:`text-text-subtle`,children:`·`}),(0,X.jsxs)(`span`,{className:An(n),children:[`Ctx:`,n,`%`]})]})]}),(0,X.jsx)(`div`,{className:`flex-1`}),y&&s&&(0,X.jsx)(`button`,{onClick:()=>b(s),className:`p-1 rounded text-amber-500 hover:text-amber-400 hover:bg-surface-elevated transition-colors`,title:`Mark as read`,children:(0,X.jsx)(fe,{className:`size-3`})}),s&&(0,X.jsx)(jn,{sessionId:s,projectName:e}),d&&(0,X.jsx)(`button`,{onClick:d,className:`size-4 flex items-center justify-center`,title:u?`Connected`:`Disconnected — click to reconnect`,children:(0,X.jsx)(`span`,{className:`size-2 rounded-full ${u?`bg-green-500`:`bg-red-500 animate-pulse`}`})})]}),f===`history`&&(0,X.jsxs)(`div`,{className:`border-t border-border/30 bg-surface`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5 px-2 py-1 border-b border-border/30`,children:[(0,X.jsx)(P,{className:`size-3 text-text-subtle shrink-0`}),(0,X.jsx)(`input`,{type:`text`,value:x,onChange:e=>C(e.target.value),placeholder:`Search sessions...`,className:`flex-1 bg-transparent text-[11px] text-text-primary outline-none placeholder:text-text-subtle`}),(0,X.jsx)(`button`,{onClick:M,disabled:_,className:`p-0.5 rounded text-text-subtle hover:text-text-secondary transition-colors disabled:opacity-50`,title:`Refresh`,children:(0,X.jsx)(ne,{className:`size-3 ${_?`animate-spin`:``}`})})]}),(0,X.jsx)(`div`,{className:`max-h-[200px] overflow-y-auto`,children:_&&m.length===0?(0,X.jsx)(`div`,{className:`flex items-center justify-center py-3`,children:(0,X.jsx)(B,{className:`size-3.5 animate-spin text-text-subtle`})}):H.length===0?(0,X.jsx)(`div`,{className:`flex items-center justify-center py-3 text-[11px] text-text-subtle`,children:x?`No matching sessions`:`No sessions yet`}):H.map(e=>(0,X.jsxs)(`div`,{className:`flex items-center gap-2 w-full px-3 py-1.5 text-left hover:bg-surface-elevated transition-colors group`,children:[(0,X.jsx)(V,{className:`size-3 shrink-0 text-text-subtle`}),T===e.id?(0,X.jsxs)(`form`,{className:`flex items-center gap-1 flex-1 min-w-0`,onSubmit:e=>{e.preventDefault(),R()},children:[(0,X.jsx)(`input`,{ref:k,value:D,onChange:e=>O(e.target.value),onBlur:R,onKeyDown:e=>{e.key===`Escape`&&z()},className:`flex-1 min-w-0 bg-surface-elevated text-[11px] text-text-primary px-1 py-0.5 rounded border border-border outline-none focus:border-primary`,autoFocus:!0}),(0,X.jsx)(`button`,{type:`submit`,className:`p-0.5 text-green-500 hover:text-green-400`,onClick:e=>e.stopPropagation(),children:(0,X.jsx)(a,{className:`size-3`})}),(0,X.jsx)(`button`,{type:`button`,className:`p-0.5 text-text-subtle hover:text-text-secondary`,onClick:e=>{e.stopPropagation(),z()},children:(0,X.jsx)(I,{className:`size-3`})})]}):(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`button`,{onClick:()=>N(e),className:`text-[11px] truncate flex-1 text-left`,children:e.title||`Untitled`}),(0,X.jsx)(`button`,{onClick:t=>L(e,t),className:`p-0.5 rounded text-text-subtle hover:text-text-secondary opacity-0 group-hover:opacity-100 transition-opacity`,title:`Rename session`,children:(0,X.jsx)(te,{className:`size-3`})})]}),T!==e.id&&e.updatedAt&&(0,X.jsx)(`span`,{className:`text-[10px] text-text-subtle shrink-0`,children:kn(e.updatedAt)})]},e.id))})]}),f===`config`&&(0,X.jsx)(`div`,{className:`border-t border-border/30 bg-surface px-3 py-2 max-h-[280px] overflow-y-auto`,children:(0,X.jsx)(me,{compact:!0})}),f===`usage`&&(0,X.jsx)(On,{usage:t,visible:!0,onClose:()=>p(null),onReload:i,loading:r,lastFetchedAt:o})]})}function Nn({metadata:e,tabId:t}){let[n,r]=(0,J.useState)(e?.sessionId??null),[i,a]=(0,J.useState)(e?.providerId??`claude`),[o,s]=(0,J.useState)([]),[c,l]=(0,J.useState)(!1),[u,d]=(0,J.useState)(``),[f,p]=(0,J.useState)(null),[h,_]=(0,J.useState)([]),[y,b]=(0,J.useState)(!1),[x,C]=(0,J.useState)(``),[T,E]=(0,J.useState)(null),[D,k]=(0,J.useState)(e?.permissionMode??void 0),[A,j]=(0,J.useState)(!1),[M,N]=(0,J.useState)(null),P=(0,J.useRef)(0),I=e?.projectName??``,L=g(e=>e.updateTab),R=U(e=>e.version),{usageInfo:V,usageLoading:H,lastFetchedAt:W,refreshUsage:ee}=$e(I,i);(0,J.useEffect)(()=>{D||O().then(e=>{let t=e.providers[e.default_provider??`claude`];k(t?.permission_mode??`bypassPermissions`)}).catch(()=>{})},[]),(0,J.useEffect)(()=>{!t||!n||L(t,{metadata:{...e,sessionId:n,providerId:i,permissionMode:D}})},[n,i,D]);let{messages:te,messagesLoading:ne,isStreaming:G,phase:re,isReconnecting:ie,connectingElapsed:ae,pendingApproval:oe,contextWindowPct:se,sessionTitle:K,sendMessage:q,respondToApproval:ce,cancelStreaming:le,reconnect:ue,refetchMessages:de,isConnected:fe}=Ze(n,i,I);(0,J.useEffect)(()=>{if(!n||!t)return;let e=()=>{if(document.hidden)return;let{panels:e,focusedPanelId:r}=m.getState();e[r]?.activeTabId===t&&F.getState().clearForSession(n)};e(),document.addEventListener(`visibilitychange`,e);let r=m.subscribe(e);return()=>{document.removeEventListener(`visibilitychange`,e),r()}},[n,t]),(0,J.useEffect)(()=>{t&&K&&L(t,{title:K})},[K]);let pe=(0,J.useRef)(e?.pendingMessage);(0,J.useEffect)(()=>{if(pe.current&&fe&&n){let n=pe.current;pe.current=void 0,t&&L(t,{metadata:{...e,pendingMessage:void 0}}),setTimeout(()=>q(n,{permissionMode:D}),100)}},[fe,n]),(0,J.useCallback)(()=>{g.getState().openTab({type:`chat`,title:`AI Chat`,metadata:{projectName:I},projectId:I||null,closable:!0})},[I]);let me=(0,J.useCallback)(e=>{r(e.id),a(e.providerId),t&&L(t,{title:e.title||`Chat`})},[t,L]),he=(0,J.useCallback)(async e=>{if(!(!n||!I))try{let{api:t,projectUrl:r}=await v(async()=>{let{api:e,projectUrl:t}=await import(`./api-client-BfBM3I7n.js`).then(e=>e.n);return{api:e,projectUrl:t}},__vite__mapDeps([0,1])),a=await t.post(`${r(I)}/chat/sessions/${n}/fork?providerId=${i}`);g.getState().openTab({type:`chat`,title:`Fork: ${e.slice(0,30)}`,metadata:{projectName:I,sessionId:a.id,providerId:i,pendingMessage:e},projectId:I||null,closable:!0})}catch(e){console.error(`Fork failed:`,e)}},[n,I,i]),ge=(0,J.useCallback)((e,t)=>{if(t.length===0)return e;let n=t.filter(e=>e.serverPath).map(e=>e.serverPath).join(`
8
+ `);return n?(t.length===1?`[Attached file: ${n}]\n\n`:`[Attached files:\n${n}\n]\n\n`)+e:e},[]),_e=(0,J.useCallback)(async(e,t=[])=>{let o=ge(e,t);if(o.trim()){if(!n)try{let t=I,n=await w.post(`${S(t)}/chat/sessions`,{providerId:i,title:e.slice(0,50)});r(n.id),a(n.providerId),setTimeout(()=>{q(o,{permissionMode:D})},500);return}catch(e){console.error(`Failed to create session:`,e);return}q(o,{permissionMode:D})}},[n,i,I,q,ge,D]),ye=(0,J.useCallback)((e,t)=>{l(e),d(t)},[]),be=(0,J.useCallback)(e=>{p(e),l(!1),d(``),setTimeout(()=>p(null),50)},[]),xe=(0,J.useCallback)(()=>{l(!1),d(``)},[]),Se=(0,J.useCallback)((e,t)=>{b(e),C(t)},[]),Ce=(0,J.useCallback)(e=>{E(e),b(!1),C(``),setTimeout(()=>E(null),50)},[]),we=(0,J.useCallback)(()=>{b(!1),C(``)},[]);return(0,X.jsxs)(`div`,{className:`flex flex-col h-full relative`,onDragEnter:(0,J.useCallback)(e=>{e.preventDefault(),P.current++,e.dataTransfer.types.includes(`Files`)&&j(!0)},[]),onDragLeave:(0,J.useCallback)(e=>{e.preventDefault(),P.current--,P.current===0&&j(!1)},[]),onDragOver:(0,J.useCallback)(e=>{e.preventDefault()},[]),onDrop:(0,J.useCallback)(e=>{e.preventDefault(),P.current=0,j(!1);let t=Array.from(e.dataTransfer.files);t.length>0&&(N(t),setTimeout(()=>N(null),100))},[]),children:[A&&(0,X.jsx)(`div`,{className:`absolute inset-0 z-50 flex items-center justify-center bg-background/80 backdrop-blur-sm border-2 border-dashed border-primary rounded-lg pointer-events-none`,children:(0,X.jsxs)(`div`,{className:`flex flex-col items-center gap-2 text-primary`,children:[(0,X.jsx)(z,{className:`size-8`}),(0,X.jsx)(`span`,{className:`text-sm font-medium`,children:`Drop files to attach`})]})}),ie&&(0,X.jsx)(`div`,{className:`absolute inset-0 z-50 flex items-center justify-center bg-background/60 backdrop-blur-sm`,children:(0,X.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-muted-foreground`,children:[(0,X.jsx)(B,{className:`size-4 animate-spin`}),(0,X.jsx)(`span`,{children:`Reconnecting...`})]})}),(0,X.jsx)(Tt,{messages:te,messagesLoading:ne,pendingApproval:oe,onApprovalResponse:ce,isStreaming:G,phase:re,connectingElapsed:ae,projectName:I,onFork:G?void 0:he}),(0,X.jsxs)(`div`,{className:`border-t border-border bg-background shrink-0`,children:[(0,X.jsx)(Mn,{projectName:I,usageInfo:V,contextWindowPct:se,usageLoading:H,refreshUsage:ee,lastFetchedAt:W,sessionId:n,onSelectSession:me,onBugReport:n?()=>ve(R,{sessionId:n,projectName:I}):void 0,isConnected:fe,onReconnect:()=>{fe||ue(),de()}}),(0,X.jsx)(hn,{items:o,filter:u,onSelect:be,onClose:xe,visible:c}),(0,X.jsx)(fn,{items:h,filter:x,onSelect:Ce,onClose:we,visible:y}),(0,X.jsx)(pn,{onSend:_e,isStreaming:G,onCancel:le,autoFocus:!e?.sessionId,projectName:I,onSlashStateChange:ye,onSlashItemsLoaded:s,slashSelected:f,onFileStateChange:Se,onFileItemsLoaded:_,fileSelected:T,externalFiles:M,permissionMode:D,onModeChange:k})]})]})}export{Nn as ChatTab};
@@ -1,2 +1,2 @@
1
1
  const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/csv-preview-DLqYtXxt.js","assets/chunk-CFjPhJqf.js","assets/lib-BQ34Db2e.js","assets/react-nm2Ru1Pt.js","assets/jsx-runtime-BRW_vwa9.js","assets/arrow-up--LjUXLEt.js","assets/react-dom-Bpkvzu3U.js"])))=>i.map(i=>d[i]);
2
- import{o as e}from"./chunk-CFjPhJqf.js";import{t}from"./react-nm2Ru1Pt.js";import"./react-dom-Bpkvzu3U.js";import{n,t as r}from"./jsx-runtime-BRW_vwa9.js";import{t as i}from"./chevron-right-DeV0ehiG.js";import{n as a,t as o}from"./markdown-renderer-Bwac0-W_.js";import{o as s,t as c}from"./tab-store-BCfMgMKM.js";import{t as l}from"./table-C7X5UAEI.js";import{i as u,n as d,t as f}from"./use-monaco-theme-gi_EBBX3.js";import{t as p}from"./preload-helper-uTix4PVD.js";import"./dist-lF8CoYII.js";import{t as m}from"./utils-BNytJOb1.js";import{i as h,r as g,t as _}from"./api-client-BfBM3I7n.js";import{$ as v,E as y,J as b,P as x,Q as S,Z as C,c as w,d as T,et as E,f as D,l as O,m as k,nt as A,p as j,rt as M,tt as N,u as P}from"./index-DtlqB_mF.js";import"./chunk-GEFDOKGD-BbQkJu8C.js";import"./src-BqX54PbV.js";import"./chunk-7R4GIKGN-BbIFzsIv.js";import"./chunk-HHEYEP7N-HRhYy3kG.js";import"./dist-CSJdAyA9.js";import"./chunk-PU5JKC2W-Dw8ClWch.js";import"./chunk-MX3YWQON-BpS_PtKp.js";import"./chunk-YBOYWFTD-CeU4Q-xC.js";import"./chunk-PQ6SQG4A-D6BTbCQw.js";import"./chunk-KYZI473N-BcUZNnwd.js";import"./chunk-O4XLMI2P-JC6EGoUz.js";import"./chunk-GLR3WWYH-CzYx4w-r.js";import"./chunk-XPW4576I-BPQQBakK.js";var F=n(`file-exclamation-point`,[[`path`,{d:`M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z`,key:`1oefj6`}],[`path`,{d:`M12 9v4`,key:`juzpu7`}],[`path`,{d:`M12 17h.01`,key:`p32p05`}]]),I=e(t(),1),L=r(),R={ts:N,tsx:N,js:N,jsx:N,py:N,rs:N,go:N,html:N,css:N,scss:N,json:A,md:E,txt:E,yaml:v,yml:v};function z(e,t){return t?C:R[e.split(`.`).pop()?.toLowerCase()??``]??S}function B(e,t){let n=[],r=e;for(let e=0;e<t.length;e++){let i=t[e],a=t.slice(0,e+1).join(`/`),o=r.find(e=>e.name===i);if(n.push({name:i,fullPath:a,node:o??null,siblings:r}),o?.children)r=o.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:[]});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 H({filePath:e,projectName:t,tabId:n,className:r}){let a=y(e=>e.tree),{updateTab:o,openTab:s}=c(),l=(0,I.useRef)(null),u=(0,I.useMemo)(()=>B(a,e.split(`/`).filter(Boolean)),[a,e]);(0,I.useEffect)(()=>{l.current&&(l.current.scrollLeft=l.current.scrollWidth)},[u]);function d(e,r){let i=m(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,L.jsx)(`div`,{ref:l,className:r,children:u.map((e,n)=>(0,L.jsxs)(`div`,{className:`flex items-center shrink-0`,children:[n>0&&(0,L.jsx)(i,{className:`size-3 text-muted-foreground shrink-0 mx-0.5`}),e.siblings.length>0?(0,L.jsx)(U,{segment:e,isLast:n===u.length-1,projectName:t,onFileClick:d}):(0,L.jsx)(`span`,{className:`text-xs text-muted-foreground px-1 py-0.5`,children:e.name})]},e.fullPath))})}function U({segment:e,isLast:t,projectName:n,onFileClick:r}){let i=(0,I.useMemo)(()=>V(e.siblings),[e.siblings]);return(0,L.jsxs)(w,{children:[(0,L.jsx)(k,{asChild:!0,children:(0,L.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,L.jsx)(O,{align:`start`,className:`max-h-[300px] p-1`,children:i.map(t=>(0,L.jsx)(W,{node:t,projectName:n,activePath:e.fullPath,onFileClick:r},t.path))})]})}function W({node:e,projectName:t,activePath:n,onFileClick:r}){let i=z(e.name,e.type===`directory`),a=e.path===n;return e.type===`directory`&&e.children&&e.children.length>0?(0,L.jsxs)(T,{children:[(0,L.jsxs)(j,{className:`text-xs gap-1.5 ${a?`bg-muted`:``}`,children:[(0,L.jsx)(i,{className:`size-3.5 shrink-0 text-muted-foreground`}),(0,L.jsx)(`span`,{className:`truncate`,children:e.name})]}),(0,L.jsx)(D,{className:`max-h-[300px] overflow-y-auto p-1`,children:V(e.children).map(e=>(0,L.jsx)(W,{node:e,projectName:t,activePath:n,onFileClick:r},e.path))})]}):(0,L.jsxs)(P,{className:`text-xs gap-1.5 cursor-pointer ${a?`bg-muted`:``}`,onSelect:e=>{},onClick:t=>{e.type!==`directory`&&r(e.path,t)},children:[(0,L.jsx)(i,{className:`size-3.5 shrink-0 text-muted-foreground`}),(0,L.jsx)(`span`,{className:`truncate`,children:e.name})]})}function G({active:e,onClick:t,icon:n,label:r}){return(0,L.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,L.jsx)(n,{className:`size-3`}),(0,L.jsx)(`span`,{className:`hidden sm:inline`,children:r})]})}function K({ext:e,mdMode:t,onMdModeChange:n,csvMode:r,onCsvModeChange:i,wordWrap:o,onToggleWordWrap:s,className:c}){return(0,L.jsxs)(`div`,{className:c,children:[(e===`md`||e===`mdx`)&&n&&(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(G,{active:t===`edit`,onClick:()=>n(`edit`),icon:a,label:`Edit`}),(0,L.jsx)(G,{active:t===`preview`,onClick:()=>n(`preview`),icon:M,label:`Preview`})]}),e===`csv`&&i&&(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(G,{active:r===`table`,onClick:()=>i(`table`),icon:l,label:`Table`}),(0,L.jsx)(G,{active:r===`raw`,onClick:()=>i(`raw`),icon:a,label:`Raw`})]}),(0,L.jsx)(G,{active:o,onClick:s,icon:u,label:`Wrap`})]})}var q=(0,I.lazy)(()=>p(()=>import(`./csv-preview-DLqYtXxt.js`).then(e=>({default:e.CsvPreview})),__vite__mapDeps([0,1,2,3,4,5,6]))),J=new Set([`png`,`jpg`,`jpeg`,`gif`,`webp`,`svg`,`ico`]),Y=new Set([`db`,`sqlite`,`sqlite3`]);function X(e){return e.split(`.`).pop()?.toLowerCase()??``}function ee(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`}[X(e)]??`plaintext`}function Z({metadata:e,tabId:t}){let n=e?.filePath,r=e?.projectName,[i,a]=(0,I.useState)(null),[o,s]=(0,I.useState)(`utf-8`),[l,u]=(0,I.useState)(!0),[p,g]=(0,I.useState)(null),[v,y]=(0,I.useState)(!1),S=(0,I.useRef)(null),C=(0,I.useRef)(``),w=(0,I.useRef)(null),{tabs:T,updateTab:E}=c(),{wordWrap:D,toggleWordWrap:O}=x(),k=f(),A=T.find(e=>e.id===t),j=n?X(n):``,M=J.has(j),N=j===`pdf`,P=Y.has(j),R=j===`md`||j===`mdx`,z=j===`csv`,[B,V]=(0,I.useState)(`preview`),[U,W]=(0,I.useState)(`table`);(0,I.useEffect)(()=>{P&&t&&E(t,{type:`sqlite`})},[P,t,E]);let G=n?/^(\/|[A-Za-z]:[/\\])/.test(n):!1;(0,I.useEffect)(()=>{if(!n||!G&&!r)return;if(M||N){u(!1);return}u(!0),g(null);let e=G?`/api/fs/read?path=${encodeURIComponent(n)}`:`${h(r)}/files/read?path=${encodeURIComponent(n)}`;return _.get(e).then(e=>{a(e.content),e.encoding&&s(e.encoding),C.current=e.content,u(!1)}).catch(e=>{g(e instanceof Error?e.message:`Failed to load file`),u(!1)}),()=>{S.current&&clearTimeout(S.current)}},[n,r,M,N,G]),(0,I.useEffect)(()=>{if(!A)return;let e=n?m(n):`Untitled`,t=v?`${e} \u25CF`:e;A.title!==t&&E(A.id,{title:t})},[v]);let Z=(0,I.useCallback)(async e=>{if(n&&!(!G&&!r))try{G?await _.put(`/api/fs/write`,{path:n,content:e}):await _.put(`${h(r)}/files/write`,{path:n,content:e}),y(!1)}catch{}},[n,r,G]);function Q(e){let t=e??``;a(t),C.current=t,y(!0),S.current&&clearTimeout(S.current),S.current=setTimeout(()=>Z(C.current),1e3)}let $=e?.lineNumber,ie=(0,I.useCallback)((e,t)=>{w.current=e,$&&$>0&&setTimeout(()=>{e.revealLineInCenter($),e.setPosition({lineNumber:$,column:1}),e.focus()},100),e.addCommand(t.KeyMod.Alt|t.KeyCode.KeyZ,()=>x.getState().toggleWordWrap()),t.languages.typescript.typescriptDefaults.setDiagnosticsOptions({noSemanticValidation:!0,noSyntaxValidation:!0,noSuggestionDiagnostics:!0}),t.languages.typescript.javascriptDefaults.setDiagnosticsOptions({noSemanticValidation:!0,noSyntaxValidation:!0,noSuggestionDiagnostics:!0})},[]);return!n||!G&&!r?(0,L.jsx)(`div`,{className:`flex items-center justify-center h-full text-text-secondary text-sm`,children:`No file selected.`}):l?(0,L.jsxs)(`div`,{className:`flex items-center justify-center h-full gap-2 text-text-secondary`,children:[(0,L.jsx)(b,{className:`size-5 animate-spin`}),(0,L.jsx)(`span`,{className:`text-sm`,children:`Loading file...`})]}):p?(0,L.jsx)(`div`,{className:`flex items-center justify-center h-full text-error text-sm`,children:p}):M?(0,L.jsx)(ne,{filePath:n,projectName:r}):N?(0,L.jsx)(re,{filePath:n,projectName:r}):o===`base64`?(0,L.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full gap-3 text-text-secondary`,children:[(0,L.jsx)(F,{className:`size-10 text-text-subtle`}),(0,L.jsx)(`p`,{className:`text-sm`,children:`This file is a binary format and cannot be displayed.`}),(0,L.jsx)(`p`,{className:`text-xs text-text-subtle`,children:n})]}):(0,L.jsxs)(`div`,{className:`flex flex-col h-full w-full overflow-hidden`,children:[n&&r&&t&&(0,L.jsxs)(`div`,{className:`hidden md:flex items-center h-7 border-b border-border bg-background shrink-0`,children:[(0,L.jsx)(H,{filePath:n,projectName:r,tabId:t,className:`flex items-center flex-1 min-w-0 overflow-x-auto scrollbar-none px-2 gap-0.5`}),(0,L.jsx)(K,{ext:j,mdMode:B,onMdModeChange:V,csvMode:U,onCsvModeChange:W,wordWrap:D,onToggleWordWrap:O,className:`shrink-0 flex items-center gap-1 px-2`})]}),z&&U===`table`?(0,L.jsx)(I.Suspense,{fallback:(0,L.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,L.jsx)(b,{className:`size-5 animate-spin text-text-subtle`})}),children:(0,L.jsx)(q,{content:i??``,onContentChange:Q,wordWrap:D})}):R&&B===`preview`?(0,L.jsx)(te,{content:i??``}):(0,L.jsx)(`div`,{className:`flex-1 overflow-hidden`,children:(0,L.jsx)(d,{height:`100%`,language:ee(n),value:i??``,onChange:Q,onMount:ie,theme:k,options:{fontSize:13,fontFamily:`Menlo, Monaco, Consolas, monospace`,wordWrap:D?`on`:`off`,minimap:{enabled:!1},scrollBeyondLastLine:!1,automaticLayout:!0,lineNumbers:`on`,folding:!0,bracketPairColorization:{enabled:!0}},loading:(0,L.jsx)(b,{className:`size-5 animate-spin text-text-subtle`})})})]})}function te({content:e}){return(0,L.jsx)(o,{content:e,className:`flex-1 overflow-auto p-4`})}function ne({filePath:e,projectName:t}){let[n,r]=(0,I.useState)(null),[i,a]=(0,I.useState)(!1);return(0,I.useEffect)(()=>{let n,i=`${h(t)}/files/raw?path=${encodeURIComponent(e)}`,o=g();return fetch(i,{headers:o?{Authorization:`Bearer ${o}`}:{}}).then(e=>{if(!e.ok)throw Error(`Failed`);return e.blob()}).then(e=>{let t=URL.createObjectURL(e);n=t,r(t)}).catch(()=>a(!0)),()=>{n&&URL.revokeObjectURL(n)}},[e,t]),i?(0,L.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full gap-3 text-text-secondary`,children:[(0,L.jsx)(F,{className:`size-10 text-text-subtle`}),(0,L.jsx)(`p`,{className:`text-sm`,children:`Failed to load image.`})]}):n?(0,L.jsx)(`div`,{className:`flex items-center justify-center h-full p-4 bg-surface overflow-auto`,children:(0,L.jsx)(`img`,{src:n,alt:e,className:`max-w-full max-h-full object-contain`})}):(0,L.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,L.jsx)(b,{className:`size-5 animate-spin text-text-subtle`})})}function re({filePath:e,projectName:t}){let[n,r]=(0,I.useState)(null),[i,a]=(0,I.useState)(!1);(0,I.useEffect)(()=>{let n,i=`${h(t)}/files/raw?path=${encodeURIComponent(e)}`,o=g();return fetch(i,{headers:o?{Authorization:`Bearer ${o}`}:{}}).then(e=>{if(!e.ok)throw Error(`Failed`);return e.blob()}).then(e=>{let t=URL.createObjectURL(new Blob([e],{type:`application/pdf`}));n=t,r(t)}).catch(()=>a(!0)),()=>{n&&URL.revokeObjectURL(n)}},[e,t]);let o=(0,I.useCallback)(()=>{n&&window.open(n,`_blank`)},[n]);return i?(0,L.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full gap-3 text-text-secondary`,children:[(0,L.jsx)(F,{className:`size-10 text-text-subtle`}),(0,L.jsx)(`p`,{className:`text-sm`,children:`Failed to load PDF.`})]}):n?(0,L.jsxs)(`div`,{className:`flex flex-col h-full`,children:[(0,L.jsxs)(`div`,{className:`flex items-center justify-between px-3 py-1.5 border-b border-border bg-background shrink-0`,children:[(0,L.jsx)(`span`,{className:`text-xs text-text-secondary truncate`,children:e}),(0,L.jsxs)(`button`,{onClick:o,className:`flex items-center gap-1 text-xs text-text-secondary hover:text-text-primary transition-colors`,children:[(0,L.jsx)(s,{className:`size-3`}),` Open in new tab`]})]}),(0,L.jsx)(`iframe`,{src:n,title:e,className:`flex-1 w-full border-none`})]}):(0,L.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,L.jsx)(b,{className:`size-5 animate-spin text-text-subtle`})})}export{Z as CodeEditor};
2
+ import{o as e}from"./chunk-CFjPhJqf.js";import{t}from"./react-nm2Ru1Pt.js";import"./react-dom-Bpkvzu3U.js";import{n,t as r}from"./jsx-runtime-BRW_vwa9.js";import{t as i}from"./chevron-right-DeV0ehiG.js";import{n as a,t as o}from"./markdown-renderer-CW2c3h_9.js";import{o as s,t as c}from"./tab-store-BCfMgMKM.js";import{t as l}from"./table-C7X5UAEI.js";import{i as u,n as d,t as f}from"./use-monaco-theme-Dsn8sLad.js";import{t as p}from"./preload-helper-uTix4PVD.js";import"./dist-lF8CoYII.js";import{t as m}from"./utils-BNytJOb1.js";import{i as h,r as g,t as _}from"./api-client-BfBM3I7n.js";import{$ as v,E as y,J as b,P as x,Q as S,Z as C,c as w,d as T,et as E,f as D,l as O,m as k,nt as A,p as j,rt as M,tt as N,u as P}from"./index-ButO-DnP.js";import"./chunk-GEFDOKGD-BbQkJu8C.js";import"./src-BqX54PbV.js";import"./chunk-7R4GIKGN-BbIFzsIv.js";import"./chunk-HHEYEP7N-HRhYy3kG.js";import"./dist-CSJdAyA9.js";import"./chunk-PU5JKC2W-Dw8ClWch.js";import"./chunk-MX3YWQON-BpS_PtKp.js";import"./chunk-YBOYWFTD-CeU4Q-xC.js";import"./chunk-PQ6SQG4A-D6BTbCQw.js";import"./chunk-KYZI473N-BcUZNnwd.js";import"./chunk-O4XLMI2P-JC6EGoUz.js";import"./chunk-GLR3WWYH-CzYx4w-r.js";import"./chunk-XPW4576I-BPQQBakK.js";var F=n(`file-exclamation-point`,[[`path`,{d:`M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z`,key:`1oefj6`}],[`path`,{d:`M12 9v4`,key:`juzpu7`}],[`path`,{d:`M12 17h.01`,key:`p32p05`}]]),I=e(t(),1),L=r(),R={ts:N,tsx:N,js:N,jsx:N,py:N,rs:N,go:N,html:N,css:N,scss:N,json:A,md:E,txt:E,yaml:v,yml:v};function z(e,t){return t?C:R[e.split(`.`).pop()?.toLowerCase()??``]??S}function B(e,t){let n=[],r=e;for(let e=0;e<t.length;e++){let i=t[e],a=t.slice(0,e+1).join(`/`),o=r.find(e=>e.name===i);if(n.push({name:i,fullPath:a,node:o??null,siblings:r}),o?.children)r=o.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:[]});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 H({filePath:e,projectName:t,tabId:n,className:r}){let a=y(e=>e.tree),{updateTab:o,openTab:s}=c(),l=(0,I.useRef)(null),u=(0,I.useMemo)(()=>B(a,e.split(`/`).filter(Boolean)),[a,e]);(0,I.useEffect)(()=>{l.current&&(l.current.scrollLeft=l.current.scrollWidth)},[u]);function d(e,r){let i=m(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,L.jsx)(`div`,{ref:l,className:r,children:u.map((e,n)=>(0,L.jsxs)(`div`,{className:`flex items-center shrink-0`,children:[n>0&&(0,L.jsx)(i,{className:`size-3 text-muted-foreground shrink-0 mx-0.5`}),e.siblings.length>0?(0,L.jsx)(U,{segment:e,isLast:n===u.length-1,projectName:t,onFileClick:d}):(0,L.jsx)(`span`,{className:`text-xs text-muted-foreground px-1 py-0.5`,children:e.name})]},e.fullPath))})}function U({segment:e,isLast:t,projectName:n,onFileClick:r}){let i=(0,I.useMemo)(()=>V(e.siblings),[e.siblings]);return(0,L.jsxs)(w,{children:[(0,L.jsx)(k,{asChild:!0,children:(0,L.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,L.jsx)(O,{align:`start`,className:`max-h-[300px] p-1`,children:i.map(t=>(0,L.jsx)(W,{node:t,projectName:n,activePath:e.fullPath,onFileClick:r},t.path))})]})}function W({node:e,projectName:t,activePath:n,onFileClick:r}){let i=z(e.name,e.type===`directory`),a=e.path===n;return e.type===`directory`&&e.children&&e.children.length>0?(0,L.jsxs)(T,{children:[(0,L.jsxs)(j,{className:`text-xs gap-1.5 ${a?`bg-muted`:``}`,children:[(0,L.jsx)(i,{className:`size-3.5 shrink-0 text-muted-foreground`}),(0,L.jsx)(`span`,{className:`truncate`,children:e.name})]}),(0,L.jsx)(D,{className:`max-h-[300px] overflow-y-auto p-1`,children:V(e.children).map(e=>(0,L.jsx)(W,{node:e,projectName:t,activePath:n,onFileClick:r},e.path))})]}):(0,L.jsxs)(P,{className:`text-xs gap-1.5 cursor-pointer ${a?`bg-muted`:``}`,onSelect:e=>{},onClick:t=>{e.type!==`directory`&&r(e.path,t)},children:[(0,L.jsx)(i,{className:`size-3.5 shrink-0 text-muted-foreground`}),(0,L.jsx)(`span`,{className:`truncate`,children:e.name})]})}function G({active:e,onClick:t,icon:n,label:r}){return(0,L.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,L.jsx)(n,{className:`size-3`}),(0,L.jsx)(`span`,{className:`hidden sm:inline`,children:r})]})}function K({ext:e,mdMode:t,onMdModeChange:n,csvMode:r,onCsvModeChange:i,wordWrap:o,onToggleWordWrap:s,className:c}){return(0,L.jsxs)(`div`,{className:c,children:[(e===`md`||e===`mdx`)&&n&&(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(G,{active:t===`edit`,onClick:()=>n(`edit`),icon:a,label:`Edit`}),(0,L.jsx)(G,{active:t===`preview`,onClick:()=>n(`preview`),icon:M,label:`Preview`})]}),e===`csv`&&i&&(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(G,{active:r===`table`,onClick:()=>i(`table`),icon:l,label:`Table`}),(0,L.jsx)(G,{active:r===`raw`,onClick:()=>i(`raw`),icon:a,label:`Raw`})]}),(0,L.jsx)(G,{active:o,onClick:s,icon:u,label:`Wrap`})]})}var q=(0,I.lazy)(()=>p(()=>import(`./csv-preview-DLqYtXxt.js`).then(e=>({default:e.CsvPreview})),__vite__mapDeps([0,1,2,3,4,5,6]))),J=new Set([`png`,`jpg`,`jpeg`,`gif`,`webp`,`svg`,`ico`]),Y=new Set([`db`,`sqlite`,`sqlite3`]);function X(e){return e.split(`.`).pop()?.toLowerCase()??``}function ee(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`}[X(e)]??`plaintext`}function Z({metadata:e,tabId:t}){let n=e?.filePath,r=e?.projectName,[i,a]=(0,I.useState)(null),[o,s]=(0,I.useState)(`utf-8`),[l,u]=(0,I.useState)(!0),[p,g]=(0,I.useState)(null),[v,y]=(0,I.useState)(!1),S=(0,I.useRef)(null),C=(0,I.useRef)(``),w=(0,I.useRef)(null),{tabs:T,updateTab:E}=c(),{wordWrap:D,toggleWordWrap:O}=x(),k=f(),A=T.find(e=>e.id===t),j=n?X(n):``,M=J.has(j),N=j===`pdf`,P=Y.has(j),R=j===`md`||j===`mdx`,z=j===`csv`,[B,V]=(0,I.useState)(`preview`),[U,W]=(0,I.useState)(`table`);(0,I.useEffect)(()=>{P&&t&&E(t,{type:`sqlite`})},[P,t,E]);let G=n?/^(\/|[A-Za-z]:[/\\])/.test(n):!1;(0,I.useEffect)(()=>{if(!n||!G&&!r)return;if(M||N){u(!1);return}u(!0),g(null);let e=G?`/api/fs/read?path=${encodeURIComponent(n)}`:`${h(r)}/files/read?path=${encodeURIComponent(n)}`;return _.get(e).then(e=>{a(e.content),e.encoding&&s(e.encoding),C.current=e.content,u(!1)}).catch(e=>{g(e instanceof Error?e.message:`Failed to load file`),u(!1)}),()=>{S.current&&clearTimeout(S.current)}},[n,r,M,N,G]),(0,I.useEffect)(()=>{if(!A)return;let e=n?m(n):`Untitled`,t=v?`${e} \u25CF`:e;A.title!==t&&E(A.id,{title:t})},[v]);let Z=(0,I.useCallback)(async e=>{if(n&&!(!G&&!r))try{G?await _.put(`/api/fs/write`,{path:n,content:e}):await _.put(`${h(r)}/files/write`,{path:n,content:e}),y(!1)}catch{}},[n,r,G]);function Q(e){let t=e??``;a(t),C.current=t,y(!0),S.current&&clearTimeout(S.current),S.current=setTimeout(()=>Z(C.current),1e3)}let $=e?.lineNumber,ie=(0,I.useCallback)((e,t)=>{w.current=e,$&&$>0&&setTimeout(()=>{e.revealLineInCenter($),e.setPosition({lineNumber:$,column:1}),e.focus()},100),e.addCommand(t.KeyMod.Alt|t.KeyCode.KeyZ,()=>x.getState().toggleWordWrap()),t.languages.typescript.typescriptDefaults.setDiagnosticsOptions({noSemanticValidation:!0,noSyntaxValidation:!0,noSuggestionDiagnostics:!0}),t.languages.typescript.javascriptDefaults.setDiagnosticsOptions({noSemanticValidation:!0,noSyntaxValidation:!0,noSuggestionDiagnostics:!0})},[]);return!n||!G&&!r?(0,L.jsx)(`div`,{className:`flex items-center justify-center h-full text-text-secondary text-sm`,children:`No file selected.`}):l?(0,L.jsxs)(`div`,{className:`flex items-center justify-center h-full gap-2 text-text-secondary`,children:[(0,L.jsx)(b,{className:`size-5 animate-spin`}),(0,L.jsx)(`span`,{className:`text-sm`,children:`Loading file...`})]}):p?(0,L.jsx)(`div`,{className:`flex items-center justify-center h-full text-error text-sm`,children:p}):M?(0,L.jsx)(ne,{filePath:n,projectName:r}):N?(0,L.jsx)(re,{filePath:n,projectName:r}):o===`base64`?(0,L.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full gap-3 text-text-secondary`,children:[(0,L.jsx)(F,{className:`size-10 text-text-subtle`}),(0,L.jsx)(`p`,{className:`text-sm`,children:`This file is a binary format and cannot be displayed.`}),(0,L.jsx)(`p`,{className:`text-xs text-text-subtle`,children:n})]}):(0,L.jsxs)(`div`,{className:`flex flex-col h-full w-full overflow-hidden`,children:[n&&r&&t&&(0,L.jsxs)(`div`,{className:`hidden md:flex items-center h-7 border-b border-border bg-background shrink-0`,children:[(0,L.jsx)(H,{filePath:n,projectName:r,tabId:t,className:`flex items-center flex-1 min-w-0 overflow-x-auto scrollbar-none px-2 gap-0.5`}),(0,L.jsx)(K,{ext:j,mdMode:B,onMdModeChange:V,csvMode:U,onCsvModeChange:W,wordWrap:D,onToggleWordWrap:O,className:`shrink-0 flex items-center gap-1 px-2`})]}),z&&U===`table`?(0,L.jsx)(I.Suspense,{fallback:(0,L.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,L.jsx)(b,{className:`size-5 animate-spin text-text-subtle`})}),children:(0,L.jsx)(q,{content:i??``,onContentChange:Q,wordWrap:D})}):R&&B===`preview`?(0,L.jsx)(te,{content:i??``}):(0,L.jsx)(`div`,{className:`flex-1 overflow-hidden`,children:(0,L.jsx)(d,{height:`100%`,language:ee(n),value:i??``,onChange:Q,onMount:ie,theme:k,options:{fontSize:13,fontFamily:`Menlo, Monaco, Consolas, monospace`,wordWrap:D?`on`:`off`,minimap:{enabled:!1},scrollBeyondLastLine:!1,automaticLayout:!0,lineNumbers:`on`,folding:!0,bracketPairColorization:{enabled:!0}},loading:(0,L.jsx)(b,{className:`size-5 animate-spin text-text-subtle`})})})]})}function te({content:e}){return(0,L.jsx)(o,{content:e,className:`flex-1 overflow-auto p-4`})}function ne({filePath:e,projectName:t}){let[n,r]=(0,I.useState)(null),[i,a]=(0,I.useState)(!1);return(0,I.useEffect)(()=>{let n,i=`${h(t)}/files/raw?path=${encodeURIComponent(e)}`,o=g();return fetch(i,{headers:o?{Authorization:`Bearer ${o}`}:{}}).then(e=>{if(!e.ok)throw Error(`Failed`);return e.blob()}).then(e=>{let t=URL.createObjectURL(e);n=t,r(t)}).catch(()=>a(!0)),()=>{n&&URL.revokeObjectURL(n)}},[e,t]),i?(0,L.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full gap-3 text-text-secondary`,children:[(0,L.jsx)(F,{className:`size-10 text-text-subtle`}),(0,L.jsx)(`p`,{className:`text-sm`,children:`Failed to load image.`})]}):n?(0,L.jsx)(`div`,{className:`flex items-center justify-center h-full p-4 bg-surface overflow-auto`,children:(0,L.jsx)(`img`,{src:n,alt:e,className:`max-w-full max-h-full object-contain`})}):(0,L.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,L.jsx)(b,{className:`size-5 animate-spin text-text-subtle`})})}function re({filePath:e,projectName:t}){let[n,r]=(0,I.useState)(null),[i,a]=(0,I.useState)(!1);(0,I.useEffect)(()=>{let n,i=`${h(t)}/files/raw?path=${encodeURIComponent(e)}`,o=g();return fetch(i,{headers:o?{Authorization:`Bearer ${o}`}:{}}).then(e=>{if(!e.ok)throw Error(`Failed`);return e.blob()}).then(e=>{let t=URL.createObjectURL(new Blob([e],{type:`application/pdf`}));n=t,r(t)}).catch(()=>a(!0)),()=>{n&&URL.revokeObjectURL(n)}},[e,t]);let o=(0,I.useCallback)(()=>{n&&window.open(n,`_blank`)},[n]);return i?(0,L.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full gap-3 text-text-secondary`,children:[(0,L.jsx)(F,{className:`size-10 text-text-subtle`}),(0,L.jsx)(`p`,{className:`text-sm`,children:`Failed to load PDF.`})]}):n?(0,L.jsxs)(`div`,{className:`flex flex-col h-full`,children:[(0,L.jsxs)(`div`,{className:`flex items-center justify-between px-3 py-1.5 border-b border-border bg-background shrink-0`,children:[(0,L.jsx)(`span`,{className:`text-xs text-text-secondary truncate`,children:e}),(0,L.jsxs)(`button`,{onClick:o,className:`flex items-center gap-1 text-xs text-text-secondary hover:text-text-primary transition-colors`,children:[(0,L.jsx)(s,{className:`size-3`}),` Open in new tab`]})]}),(0,L.jsx)(`iframe`,{src:n,title:e,className:`flex-1 w-full border-none`})]}):(0,L.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,L.jsx)(b,{className:`size-5 animate-spin text-text-subtle`})})}export{Z as CodeEditor};
@@ -1 +1 @@
1
- import{o as e}from"./chunk-CFjPhJqf.js";import{t}from"./react-nm2Ru1Pt.js";import{t as n}from"./jsx-runtime-BRW_vwa9.js";import{t as r}from"./chevron-right-DeV0ehiG.js";import{a as i,i as a,n as o,r as s,t as c}from"./dist-DylI9XxN.js";import{t as l}from"./api-client-BfBM3I7n.js";import{J as u,V as d,at as f,dt as p}from"./index-DtlqB_mF.js";import{n as m,r as h,t as g}from"./lib-BQ34Db2e.js";var _=e(t(),1);function v(e,t,n,r){return`ppm-db-${e}-${n}.${t}-p${r}`}function y(e,t,n,r){try{let i=sessionStorage.getItem(v(e,t,n,r));return i?JSON.parse(i):null}catch{return null}}function b(e,t,n,r,i,a){try{sessionStorage.setItem(v(e,t,n,r),JSON.stringify({data:i,cols:a}))}catch{}}function x(e){let t=`/api/db/connections/${e}`,[n,r]=(0,_.useState)(null),[i,a]=(0,_.useState)(`public`),[o,s]=(0,_.useState)(null),[c,u]=(0,_.useState)([]),[d,f]=(0,_.useState)(!0),[p,m]=(0,_.useState)(null),[h,g]=(0,_.useState)(1),[v,x]=(0,_.useState)(null),[S,C]=(0,_.useState)(null),[w,T]=(0,_.useState)(!1),E=(0,_.useCallback)(async(r,a,o)=>{let c=r??n,d=a??i;if(c){f(!0);try{let[n,r]=await Promise.all([l.get(`${t}/data?table=${encodeURIComponent(c)}&schema=${d}&page=${o??h}&limit=100`),l.get(`${t}/schema?table=${encodeURIComponent(c)}&schema=${d}`)]);s(n),u(r),b(e,c,d,o??h,n,r)}catch(e){m(e.message)}finally{f(!1)}}},[t,e,n,i,h]);return{selectedTable:n,selectTable:(0,_.useCallback)((t,n=`public`)=>{r(t),a(n),g(1),x(null);let i=y(e,t,n,1);i?(s(i.data),u(i.cols),f(!1),E(t,n,1)):E(t,n,1)},[e,E]),tableData:o,schema:c,loading:d,error:p,page:h,setPage:(0,_.useCallback)(e=>{g(e),E(void 0,void 0,e)},[E]),queryResult:v,queryError:S,queryLoading:w,executeQuery:(0,_.useCallback)(async e=>{T(!0),C(null);try{let r=await l.post(`${t}/query`,{sql:e});x(r),r.changeType===`modify`&&E(n??void 0,i)}catch(e){C(e.message)}finally{T(!1)}},[t,n,i,E]),updateCell:(0,_.useCallback)(async(e,r,a,o)=>{if(!n)return;let s=n,c=i;try{await l.put(`${t}/cell`,{table:s,schema:c,pkColumn:e,pkValue:r,column:a,value:o}),E(s,c)}catch(e){m(e.message)}},[t,n,i,E]),refreshData:E}}var S=n(),C={postgres:c,sqlite:o};function w({metadata:e}){let t=e?.connectionId,n=e?.connectionName,r=e?.dbType??`postgres`,i=e?.tableName,a=e?.schemaName??`public`,o=x(t),[s,l]=(0,_.useState)(!1),u=(0,_.useRef)(!1);return(0,_.useEffect)(()=>{!i||u.current||(u.current=!0,o.selectTable(i,a))},[i,a]),(0,S.jsx)(`div`,{className:`flex h-full w-full overflow-hidden`,children:(0,S.jsxs)(`div`,{className:`flex-1 flex flex-col overflow-hidden`,children:[(0,S.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-1.5 border-b border-border bg-background shrink-0`,children:[(0,S.jsx)(f,{className:`size-3.5 text-muted-foreground`}),(0,S.jsx)(`span`,{className:`text-xs text-muted-foreground truncate`,children:n??`Database`}),o.selectedTable&&(0,S.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[`/ `,o.selectedTable]}),(0,S.jsxs)(`div`,{className:`ml-auto flex items-center gap-1`,children:[(0,S.jsx)(`button`,{type:`button`,onClick:()=>o.refreshData(),title:`Reload data`,className:`p-1 rounded text-muted-foreground hover:text-foreground transition-colors`,children:(0,S.jsx)(d,{className:`size-3 ${o.loading?`animate-spin`:``}`})}),(0,S.jsx)(`button`,{type:`button`,onClick:()=>l(e=>!e),className:`px-2 py-1 rounded text-xs transition-colors ${s?`bg-muted text-foreground`:`text-muted-foreground hover:text-foreground`}`,children:`SQL`})]})]}),(0,S.jsx)(`div`,{className:`flex-1 overflow-hidden ${s?`max-h-[60%]`:``}`,children:(0,S.jsx)(T,{tableData:o.tableData,schema:o.schema,loading:o.loading,page:o.page,onPageChange:o.setPage,onCellUpdate:o.updateCell})}),s&&(0,S.jsx)(`div`,{className:`border-t border-border h-[40%] shrink-0`,children:(0,S.jsx)(E,{dialect:C[r]??c,onExecute:o.executeQuery,result:o.queryResult,error:o.queryError,loading:o.queryLoading})})]})})}function T({tableData:e,schema:t,loading:n,page:i,onPageChange:a,onCellUpdate:o}){let[s,c]=(0,_.useState)(null),[l,d]=(0,_.useState)(``),f=(0,_.useMemo)(()=>t.find(e=>e.pk)?.name??null,[t]),v=(0,_.useCallback)((e,t,n)=>{c({rowIdx:e,col:t}),d(n==null?``:String(n))},[]),y=(0,_.useCallback)(()=>{if(!s||!e||!f)return;let t=e.rows[s.rowIdx];if(!t)return;let n=t[s.col];String(n??``)!==l&&o(f,t[f],s.col,l===``?null:l),c(null)},[s,l,e,f,o]),b=(0,_.useCallback)(()=>c(null),[]),x=(0,_.useMemo)(()=>(e?.columns??[]).map(e=>({id:e,accessorFn:t=>t[e],header:()=>(0,S.jsx)(`span`,{className:t.find(t=>t.name===e)?.pk?`font-bold`:``,children:e}),cell:({row:t,getValue:n})=>{let r=s?.rowIdx===t.index&&s?.col===e,i=n();return r?(0,S.jsx)(`input`,{autoFocus:!0,className:`w-full bg-transparent border border-primary/50 rounded px-1 py-0 text-xs outline-none`,value:l,onChange:e=>d(e.target.value),onBlur:y,onKeyDown:e=>{e.key===`Enter`&&y(),e.key===`Escape`&&b()}}):(0,S.jsx)(`span`,{className:`cursor-pointer truncate block ${i==null?`text-muted-foreground/40 italic`:``}`,onDoubleClick:()=>f&&v(t.index,e,i),title:i==null?`NULL`:String(i),children:i==null?`NULL`:String(i)})}})),[e?.columns,t,s,l,y,b,v,f]),C=m({data:e?.rows??[],columns:x,getCoreRowModel:h()});if(!e)return(0,S.jsx)(`div`,{className:`flex items-center justify-center h-full text-xs text-muted-foreground`,children:n?(0,S.jsx)(u,{className:`size-4 animate-spin`}):`Select a table`});let w=Math.ceil(e.total/e.limit)||1;return(0,S.jsxs)(`div`,{className:`flex flex-col h-full overflow-hidden`,children:[(0,S.jsx)(`div`,{className:`flex-1 overflow-auto`,children:(0,S.jsxs)(`table`,{className:`w-full text-xs border-collapse`,children:[(0,S.jsx)(`thead`,{className:`sticky top-0 z-10 bg-muted`,children:C.getHeaderGroups().map(e=>(0,S.jsx)(`tr`,{children:e.headers.map(e=>(0,S.jsx)(`th`,{className:`px-2 py-1.5 text-left font-medium text-muted-foreground border-b border-border whitespace-nowrap`,children:g(e.column.columnDef.header,e.getContext())},e.id))},e.id))}),(0,S.jsxs)(`tbody`,{children:[C.getRowModel().rows.map(e=>(0,S.jsx)(`tr`,{className:`hover:bg-muted/30 border-b border-border/50`,children:e.getVisibleCells().map(e=>(0,S.jsx)(`td`,{className:`px-2 py-1 max-w-[300px]`,children:g(e.column.columnDef.cell,e.getContext())},e.id))},e.id)),e.rows.length===0&&(0,S.jsx)(`tr`,{children:(0,S.jsx)(`td`,{colSpan:e.columns.length,className:`px-2 py-8 text-center text-muted-foreground`,children:`No data`})})]})]})}),(0,S.jsxs)(`div`,{className:`flex items-center justify-between px-3 py-1.5 border-t border-border bg-background shrink-0 text-xs text-muted-foreground`,children:[(0,S.jsxs)(`span`,{children:[e.total.toLocaleString(),` rows`]}),(0,S.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,S.jsx)(`button`,{type:`button`,disabled:i<=1,onClick:()=>a(i-1),className:`p-0.5 rounded hover:bg-muted disabled:opacity-30`,children:(0,S.jsx)(p,{className:`size-3.5`})}),(0,S.jsxs)(`span`,{children:[i,` / `,w]}),(0,S.jsx)(`button`,{type:`button`,disabled:i>=w,onClick:()=>a(i+1),className:`p-0.5 rounded hover:bg-muted disabled:opacity-30`,children:(0,S.jsx)(r,{className:`size-3.5`})})]})]})]})}function E({dialect:e,onExecute:t,result:n,error:r,loading:o}){let[c,l]=(0,_.useState)(`SELECT * FROM `),d=(0,_.useCallback)(()=>{let e=c.trim();e&&t(e)},[c,t]);return(0,S.jsxs)(`div`,{className:`flex flex-col h-full overflow-hidden`,children:[(0,S.jsxs)(`div`,{className:`flex items-start gap-1 border-b border-border bg-background`,onKeyDown:(0,_.useCallback)(e=>{(e.metaKey||e.ctrlKey)&&e.key===`Enter`&&(e.preventDefault(),d())},[d]),children:[(0,S.jsx)(`div`,{className:`flex-1 max-h-[120px] overflow-auto`,children:(0,S.jsx)(a,{value:c,onChange:l,extensions:[s({dialect:e})],basicSetup:{lineNumbers:!1,foldGutter:!1,highlightActiveLine:!1},className:`text-xs [&_.cm-editor]:!outline-none [&_.cm-scroller]:!overflow-auto`})}),(0,S.jsx)(`button`,{type:`button`,onClick:d,disabled:o,title:`Execute (Cmd+Enter)`,className:`shrink-0 m-1 p-1.5 rounded bg-primary text-primary-foreground hover:bg-primary/90 disabled:opacity-50 transition-colors`,children:o?(0,S.jsx)(u,{className:`size-3.5 animate-spin`}):(0,S.jsx)(i,{className:`size-3.5`})})]}),(0,S.jsxs)(`div`,{className:`flex-1 overflow-auto text-xs`,children:[r&&(0,S.jsx)(`div`,{className:`px-3 py-2 text-destructive bg-destructive/5`,children:r}),n?.changeType===`modify`&&(0,S.jsxs)(`div`,{className:`px-3 py-2 text-green-500`,children:[`Query executed. `,n.rowsAffected,` row(s) affected.`]}),n?.changeType===`select`&&n.rows.length>0&&(0,S.jsxs)(`table`,{className:`w-full border-collapse`,children:[(0,S.jsx)(`thead`,{className:`sticky top-0 bg-muted`,children:(0,S.jsx)(`tr`,{children:n.columns.map(e=>(0,S.jsx)(`th`,{className:`px-2 py-1 text-left font-medium text-muted-foreground border-b border-border whitespace-nowrap`,children:e},e))})}),(0,S.jsx)(`tbody`,{children:n.rows.map((e,t)=>(0,S.jsx)(`tr`,{className:`hover:bg-muted/30 border-b border-border/50`,children:n.columns.map(t=>(0,S.jsx)(`td`,{className:`px-2 py-1 max-w-[300px] truncate`,title:e[t]==null?`NULL`:String(e[t]),children:e[t]==null?(0,S.jsx)(`span`,{className:`text-muted-foreground/40 italic`,children:`NULL`}):String(e[t])},t))},t))})]}),n?.changeType===`select`&&n.rows.length===0&&(0,S.jsx)(`div`,{className:`px-3 py-2 text-muted-foreground`,children:`No results`})]})]})}export{w as DatabaseViewer};
1
+ import{o as e}from"./chunk-CFjPhJqf.js";import{t}from"./react-nm2Ru1Pt.js";import{t as n}from"./jsx-runtime-BRW_vwa9.js";import{t as r}from"./chevron-right-DeV0ehiG.js";import{a as i,i as a,n as o,r as s,t as c}from"./dist-DylI9XxN.js";import{t as l}from"./api-client-BfBM3I7n.js";import{J as u,V as d,at as f,dt as p}from"./index-ButO-DnP.js";import{n as m,r as h,t as g}from"./lib-BQ34Db2e.js";var _=e(t(),1);function v(e,t,n,r){return`ppm-db-${e}-${n}.${t}-p${r}`}function y(e,t,n,r){try{let i=sessionStorage.getItem(v(e,t,n,r));return i?JSON.parse(i):null}catch{return null}}function b(e,t,n,r,i,a){try{sessionStorage.setItem(v(e,t,n,r),JSON.stringify({data:i,cols:a}))}catch{}}function x(e){let t=`/api/db/connections/${e}`,[n,r]=(0,_.useState)(null),[i,a]=(0,_.useState)(`public`),[o,s]=(0,_.useState)(null),[c,u]=(0,_.useState)([]),[d,f]=(0,_.useState)(!0),[p,m]=(0,_.useState)(null),[h,g]=(0,_.useState)(1),[v,x]=(0,_.useState)(null),[S,C]=(0,_.useState)(null),[w,T]=(0,_.useState)(!1),E=(0,_.useCallback)(async(r,a,o)=>{let c=r??n,d=a??i;if(c){f(!0);try{let[n,r]=await Promise.all([l.get(`${t}/data?table=${encodeURIComponent(c)}&schema=${d}&page=${o??h}&limit=100`),l.get(`${t}/schema?table=${encodeURIComponent(c)}&schema=${d}`)]);s(n),u(r),b(e,c,d,o??h,n,r)}catch(e){m(e.message)}finally{f(!1)}}},[t,e,n,i,h]);return{selectedTable:n,selectTable:(0,_.useCallback)((t,n=`public`)=>{r(t),a(n),g(1),x(null);let i=y(e,t,n,1);i?(s(i.data),u(i.cols),f(!1),E(t,n,1)):E(t,n,1)},[e,E]),tableData:o,schema:c,loading:d,error:p,page:h,setPage:(0,_.useCallback)(e=>{g(e),E(void 0,void 0,e)},[E]),queryResult:v,queryError:S,queryLoading:w,executeQuery:(0,_.useCallback)(async e=>{T(!0),C(null);try{let r=await l.post(`${t}/query`,{sql:e});x(r),r.changeType===`modify`&&E(n??void 0,i)}catch(e){C(e.message)}finally{T(!1)}},[t,n,i,E]),updateCell:(0,_.useCallback)(async(e,r,a,o)=>{if(!n)return;let s=n,c=i;try{await l.put(`${t}/cell`,{table:s,schema:c,pkColumn:e,pkValue:r,column:a,value:o}),E(s,c)}catch(e){m(e.message)}},[t,n,i,E]),refreshData:E}}var S=n(),C={postgres:c,sqlite:o};function w({metadata:e}){let t=e?.connectionId,n=e?.connectionName,r=e?.dbType??`postgres`,i=e?.tableName,a=e?.schemaName??`public`,o=x(t),[s,l]=(0,_.useState)(!1),u=(0,_.useRef)(!1);return(0,_.useEffect)(()=>{!i||u.current||(u.current=!0,o.selectTable(i,a))},[i,a]),(0,S.jsx)(`div`,{className:`flex h-full w-full overflow-hidden`,children:(0,S.jsxs)(`div`,{className:`flex-1 flex flex-col overflow-hidden`,children:[(0,S.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-1.5 border-b border-border bg-background shrink-0`,children:[(0,S.jsx)(f,{className:`size-3.5 text-muted-foreground`}),(0,S.jsx)(`span`,{className:`text-xs text-muted-foreground truncate`,children:n??`Database`}),o.selectedTable&&(0,S.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[`/ `,o.selectedTable]}),(0,S.jsxs)(`div`,{className:`ml-auto flex items-center gap-1`,children:[(0,S.jsx)(`button`,{type:`button`,onClick:()=>o.refreshData(),title:`Reload data`,className:`p-1 rounded text-muted-foreground hover:text-foreground transition-colors`,children:(0,S.jsx)(d,{className:`size-3 ${o.loading?`animate-spin`:``}`})}),(0,S.jsx)(`button`,{type:`button`,onClick:()=>l(e=>!e),className:`px-2 py-1 rounded text-xs transition-colors ${s?`bg-muted text-foreground`:`text-muted-foreground hover:text-foreground`}`,children:`SQL`})]})]}),(0,S.jsx)(`div`,{className:`flex-1 overflow-hidden ${s?`max-h-[60%]`:``}`,children:(0,S.jsx)(T,{tableData:o.tableData,schema:o.schema,loading:o.loading,page:o.page,onPageChange:o.setPage,onCellUpdate:o.updateCell})}),s&&(0,S.jsx)(`div`,{className:`border-t border-border h-[40%] shrink-0`,children:(0,S.jsx)(E,{dialect:C[r]??c,onExecute:o.executeQuery,result:o.queryResult,error:o.queryError,loading:o.queryLoading})})]})})}function T({tableData:e,schema:t,loading:n,page:i,onPageChange:a,onCellUpdate:o}){let[s,c]=(0,_.useState)(null),[l,d]=(0,_.useState)(``),f=(0,_.useMemo)(()=>t.find(e=>e.pk)?.name??null,[t]),v=(0,_.useCallback)((e,t,n)=>{c({rowIdx:e,col:t}),d(n==null?``:String(n))},[]),y=(0,_.useCallback)(()=>{if(!s||!e||!f)return;let t=e.rows[s.rowIdx];if(!t)return;let n=t[s.col];String(n??``)!==l&&o(f,t[f],s.col,l===``?null:l),c(null)},[s,l,e,f,o]),b=(0,_.useCallback)(()=>c(null),[]),x=(0,_.useMemo)(()=>(e?.columns??[]).map(e=>({id:e,accessorFn:t=>t[e],header:()=>(0,S.jsx)(`span`,{className:t.find(t=>t.name===e)?.pk?`font-bold`:``,children:e}),cell:({row:t,getValue:n})=>{let r=s?.rowIdx===t.index&&s?.col===e,i=n();return r?(0,S.jsx)(`input`,{autoFocus:!0,className:`w-full bg-transparent border border-primary/50 rounded px-1 py-0 text-xs outline-none`,value:l,onChange:e=>d(e.target.value),onBlur:y,onKeyDown:e=>{e.key===`Enter`&&y(),e.key===`Escape`&&b()}}):(0,S.jsx)(`span`,{className:`cursor-pointer truncate block ${i==null?`text-muted-foreground/40 italic`:``}`,onDoubleClick:()=>f&&v(t.index,e,i),title:i==null?`NULL`:String(i),children:i==null?`NULL`:String(i)})}})),[e?.columns,t,s,l,y,b,v,f]),C=m({data:e?.rows??[],columns:x,getCoreRowModel:h()});if(!e)return(0,S.jsx)(`div`,{className:`flex items-center justify-center h-full text-xs text-muted-foreground`,children:n?(0,S.jsx)(u,{className:`size-4 animate-spin`}):`Select a table`});let w=Math.ceil(e.total/e.limit)||1;return(0,S.jsxs)(`div`,{className:`flex flex-col h-full overflow-hidden`,children:[(0,S.jsx)(`div`,{className:`flex-1 overflow-auto`,children:(0,S.jsxs)(`table`,{className:`w-full text-xs border-collapse`,children:[(0,S.jsx)(`thead`,{className:`sticky top-0 z-10 bg-muted`,children:C.getHeaderGroups().map(e=>(0,S.jsx)(`tr`,{children:e.headers.map(e=>(0,S.jsx)(`th`,{className:`px-2 py-1.5 text-left font-medium text-muted-foreground border-b border-border whitespace-nowrap`,children:g(e.column.columnDef.header,e.getContext())},e.id))},e.id))}),(0,S.jsxs)(`tbody`,{children:[C.getRowModel().rows.map(e=>(0,S.jsx)(`tr`,{className:`hover:bg-muted/30 border-b border-border/50`,children:e.getVisibleCells().map(e=>(0,S.jsx)(`td`,{className:`px-2 py-1 max-w-[300px]`,children:g(e.column.columnDef.cell,e.getContext())},e.id))},e.id)),e.rows.length===0&&(0,S.jsx)(`tr`,{children:(0,S.jsx)(`td`,{colSpan:e.columns.length,className:`px-2 py-8 text-center text-muted-foreground`,children:`No data`})})]})]})}),(0,S.jsxs)(`div`,{className:`flex items-center justify-between px-3 py-1.5 border-t border-border bg-background shrink-0 text-xs text-muted-foreground`,children:[(0,S.jsxs)(`span`,{children:[e.total.toLocaleString(),` rows`]}),(0,S.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,S.jsx)(`button`,{type:`button`,disabled:i<=1,onClick:()=>a(i-1),className:`p-0.5 rounded hover:bg-muted disabled:opacity-30`,children:(0,S.jsx)(p,{className:`size-3.5`})}),(0,S.jsxs)(`span`,{children:[i,` / `,w]}),(0,S.jsx)(`button`,{type:`button`,disabled:i>=w,onClick:()=>a(i+1),className:`p-0.5 rounded hover:bg-muted disabled:opacity-30`,children:(0,S.jsx)(r,{className:`size-3.5`})})]})]})]})}function E({dialect:e,onExecute:t,result:n,error:r,loading:o}){let[c,l]=(0,_.useState)(`SELECT * FROM `),d=(0,_.useCallback)(()=>{let e=c.trim();e&&t(e)},[c,t]);return(0,S.jsxs)(`div`,{className:`flex flex-col h-full overflow-hidden`,children:[(0,S.jsxs)(`div`,{className:`flex items-start gap-1 border-b border-border bg-background`,onKeyDown:(0,_.useCallback)(e=>{(e.metaKey||e.ctrlKey)&&e.key===`Enter`&&(e.preventDefault(),d())},[d]),children:[(0,S.jsx)(`div`,{className:`flex-1 max-h-[120px] overflow-auto`,children:(0,S.jsx)(a,{value:c,onChange:l,extensions:[s({dialect:e})],basicSetup:{lineNumbers:!1,foldGutter:!1,highlightActiveLine:!1},className:`text-xs [&_.cm-editor]:!outline-none [&_.cm-scroller]:!overflow-auto`})}),(0,S.jsx)(`button`,{type:`button`,onClick:d,disabled:o,title:`Execute (Cmd+Enter)`,className:`shrink-0 m-1 p-1.5 rounded bg-primary text-primary-foreground hover:bg-primary/90 disabled:opacity-50 transition-colors`,children:o?(0,S.jsx)(u,{className:`size-3.5 animate-spin`}):(0,S.jsx)(i,{className:`size-3.5`})})]}),(0,S.jsxs)(`div`,{className:`flex-1 overflow-auto text-xs`,children:[r&&(0,S.jsx)(`div`,{className:`px-3 py-2 text-destructive bg-destructive/5`,children:r}),n?.changeType===`modify`&&(0,S.jsxs)(`div`,{className:`px-3 py-2 text-green-500`,children:[`Query executed. `,n.rowsAffected,` row(s) affected.`]}),n?.changeType===`select`&&n.rows.length>0&&(0,S.jsxs)(`table`,{className:`w-full border-collapse`,children:[(0,S.jsx)(`thead`,{className:`sticky top-0 bg-muted`,children:(0,S.jsx)(`tr`,{children:n.columns.map(e=>(0,S.jsx)(`th`,{className:`px-2 py-1 text-left font-medium text-muted-foreground border-b border-border whitespace-nowrap`,children:e},e))})}),(0,S.jsx)(`tbody`,{children:n.rows.map((e,t)=>(0,S.jsx)(`tr`,{className:`hover:bg-muted/30 border-b border-border/50`,children:n.columns.map(t=>(0,S.jsx)(`td`,{className:`px-2 py-1 max-w-[300px] truncate`,title:e[t]==null?`NULL`:String(e[t]),children:e[t]==null?(0,S.jsx)(`span`,{className:`text-muted-foreground/40 italic`,children:`NULL`}):String(e[t])},t))},t))})]}),n?.changeType===`select`&&n.rows.length===0&&(0,S.jsx)(`div`,{className:`px-3 py-2 text-muted-foreground`,children:`No results`})]})]})}export{w as DatabaseViewer};
@@ -1,4 +1,4 @@
1
- import{o as e}from"./chunk-CFjPhJqf.js";import{t}from"./react-nm2Ru1Pt.js";import{n,t as r}from"./jsx-runtime-BRW_vwa9.js";import{t as i}from"./columns-2-DpsNbZOc.js";import{i as a,r as o,t as s}from"./use-monaco-theme-gi_EBBX3.js";import{i as c,t as l}from"./api-client-BfBM3I7n.js";import{J as u,P as d,W as f,tt as p}from"./index-DtlqB_mF.js";var m=n(`panel-right-open`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M15 3v18`,key:`14nvp0`}],[`path`,{d:`m10 15-3-3 3-3`,key:`1pgupc`}]]),h=e(t(),1),g=r();function _(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`}[e.split(`.`).pop()?.toLowerCase()??``]??`plaintext`}function v({metadata:e}){let t=e?.filePath,n=e?.projectName,r=e?.ref1,v=e?.ref2,b=e?.file1,x=e?.file2,S=e?.original,C=e?.modified,w=S!=null||C!=null,T=!!(b&&x),[E,D]=(0,h.useState)(null),[O,k]=(0,h.useState)(null),[A,j]=(0,h.useState)(!w),[M,N]=(0,h.useState)(null),[P,F]=(0,h.useState)(`both`),{wordWrap:I,toggleWordWrap:L}=d(),R=s(),z=(0,h.useRef)(null),[B,V]=(0,h.useState)();(0,h.useEffect)(()=>{let e=z.current;if(!e)return;let t=new ResizeObserver(([e])=>{e&&V(Math.floor(e.contentRect.height))});return t.observe(e),()=>t.disconnect()},[A,M]),(0,h.useEffect)(()=>{if(w||!n)return;if(j(!0),N(null),b&&x){let e=new URLSearchParams({file1:b,file2:x});l.get(`${c(n)}/files/compare?${e}`).then(e=>{k(e),j(!1)}).catch(e=>{N(e instanceof Error?e.message:`Failed to compare files`),j(!1)});return}let e;if(t){let i=new URLSearchParams({file:t});r&&i.set(`ref`,r),e=`${c(n)}/git/file-diff?${i}`}else if(r||v){let t=new URLSearchParams;r&&t.set(`ref1`,r),v&&t.set(`ref2`,v),e=`${c(n)}/git/diff?${t}`}else e=`${c(n)}/git/diff`;l.get(e).then(e=>{D(e.diff),j(!1)}).catch(e=>{N(e instanceof Error?e.message:`Failed to load diff`),j(!1)})},[t,n,r,v,b,x,w]);let{original:H,modified:U}=(0,h.useMemo)(()=>w?{original:S??``,modified:C??``}:T&&O?O:E?y(E):{original:``,modified:``},[E,w,S,C,T,O]),W=(0,h.useMemo)(()=>{let e=t??x??b;return e?_(e):`plaintext`},[t,b,x]),G=typeof window<`u`&&window.innerWidth<768,K=!G&&P===`both`;return!n&&!w?(0,g.jsx)(`div`,{className:`flex items-center justify-center h-full text-muted-foreground text-sm`,children:`No project selected.`}):A?(0,g.jsxs)(`div`,{className:`flex items-center justify-center h-full gap-2 text-muted-foreground`,children:[(0,g.jsx)(u,{className:`size-5 animate-spin`}),(0,g.jsx)(`span`,{className:`text-sm`,children:`Loading diff...`})]}):M?(0,g.jsx)(`div`,{className:`flex items-center justify-center h-full text-destructive text-sm`,children:M}):!w&&!T&&!H&&!U?(0,g.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full gap-2 text-muted-foreground`,children:[(0,g.jsx)(p,{className:`size-8`}),(0,g.jsx)(`p`,{className:`text-sm`,children:`No content changes`}),t&&(0,g.jsx)(`p`,{className:`text-xs font-mono`,children:t})]}):(0,g.jsxs)(`div`,{className:`flex flex-col h-full`,children:[!G&&(0,g.jsxs)(`div`,{className:`flex items-center justify-end gap-0.5 px-2 py-0.5 border-b border-border shrink-0`,children:[(0,g.jsx)(`button`,{type:`button`,onClick:()=>F(P===`left`?`both`:`left`),className:`p-1 rounded hover:bg-muted transition-colors ${P===`left`?`bg-muted text-foreground`:``}`,title:`Expand original`,children:(0,g.jsx)(f,{className:`size-3.5`})}),(0,g.jsx)(`button`,{type:`button`,onClick:()=>F(`both`),className:`p-1 rounded hover:bg-muted transition-colors ${P===`both`?`bg-muted text-foreground`:``}`,title:`Side by side`,children:(0,g.jsx)(i,{className:`size-3.5`})}),(0,g.jsx)(`button`,{type:`button`,onClick:()=>F(P===`right`?`both`:`right`),className:`p-1 rounded hover:bg-muted transition-colors ${P===`right`?`bg-muted text-foreground`:``}`,title:`Expand modified`,children:(0,g.jsx)(m,{className:`size-3.5`})}),(0,g.jsx)(`div`,{className:`w-px h-3.5 bg-border mx-0.5 shrink-0`}),(0,g.jsx)(`button`,{type:`button`,onClick:L,title:`Toggle word wrap`,className:`p-1 rounded hover:bg-muted transition-colors ${I?`bg-muted text-foreground`:``}`,children:(0,g.jsx)(a,{className:`size-3.5`})})]}),(0,g.jsx)(`div`,{ref:z,className:`flex-1 overflow-hidden`,children:B&&B>0?(0,g.jsx)(o,{height:B,language:W,original:H,modified:U,theme:R,options:{fontSize:G?11:13,fontFamily:`Menlo, Monaco, Consolas, monospace`,wordWrap:G||I?`on`:`off`,renderSideBySide:K,readOnly:!0,automaticLayout:!0,scrollBeyondLastLine:!1},loading:(0,g.jsx)(u,{className:`size-5 animate-spin text-muted-foreground`})}):(0,g.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,g.jsx)(u,{className:`size-5 animate-spin text-muted-foreground`})})})]})}function y(e){let t=e.split(`
1
+ import{o as e}from"./chunk-CFjPhJqf.js";import{t}from"./react-nm2Ru1Pt.js";import{n,t as r}from"./jsx-runtime-BRW_vwa9.js";import{t as i}from"./columns-2-DpsNbZOc.js";import{i as a,r as o,t as s}from"./use-monaco-theme-Dsn8sLad.js";import{i as c,t as l}from"./api-client-BfBM3I7n.js";import{J as u,P as d,W as f,tt as p}from"./index-ButO-DnP.js";var m=n(`panel-right-open`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M15 3v18`,key:`14nvp0`}],[`path`,{d:`m10 15-3-3 3-3`,key:`1pgupc`}]]),h=e(t(),1),g=r();function _(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`}[e.split(`.`).pop()?.toLowerCase()??``]??`plaintext`}function v({metadata:e}){let t=e?.filePath,n=e?.projectName,r=e?.ref1,v=e?.ref2,b=e?.file1,x=e?.file2,S=e?.original,C=e?.modified,w=S!=null||C!=null,T=!!(b&&x),[E,D]=(0,h.useState)(null),[O,k]=(0,h.useState)(null),[A,j]=(0,h.useState)(!w),[M,N]=(0,h.useState)(null),[P,F]=(0,h.useState)(`both`),{wordWrap:I,toggleWordWrap:L}=d(),R=s(),z=(0,h.useRef)(null),[B,V]=(0,h.useState)();(0,h.useEffect)(()=>{let e=z.current;if(!e)return;let t=new ResizeObserver(([e])=>{e&&V(Math.floor(e.contentRect.height))});return t.observe(e),()=>t.disconnect()},[A,M]),(0,h.useEffect)(()=>{if(w||!n)return;if(j(!0),N(null),b&&x){let e=new URLSearchParams({file1:b,file2:x});l.get(`${c(n)}/files/compare?${e}`).then(e=>{k(e),j(!1)}).catch(e=>{N(e instanceof Error?e.message:`Failed to compare files`),j(!1)});return}let e;if(t){let i=new URLSearchParams({file:t});r&&i.set(`ref`,r),e=`${c(n)}/git/file-diff?${i}`}else if(r||v){let t=new URLSearchParams;r&&t.set(`ref1`,r),v&&t.set(`ref2`,v),e=`${c(n)}/git/diff?${t}`}else e=`${c(n)}/git/diff`;l.get(e).then(e=>{D(e.diff),j(!1)}).catch(e=>{N(e instanceof Error?e.message:`Failed to load diff`),j(!1)})},[t,n,r,v,b,x,w]);let{original:H,modified:U}=(0,h.useMemo)(()=>w?{original:S??``,modified:C??``}:T&&O?O:E?y(E):{original:``,modified:``},[E,w,S,C,T,O]),W=(0,h.useMemo)(()=>{let e=t??x??b;return e?_(e):`plaintext`},[t,b,x]),G=typeof window<`u`&&window.innerWidth<768,K=!G&&P===`both`;return!n&&!w?(0,g.jsx)(`div`,{className:`flex items-center justify-center h-full text-muted-foreground text-sm`,children:`No project selected.`}):A?(0,g.jsxs)(`div`,{className:`flex items-center justify-center h-full gap-2 text-muted-foreground`,children:[(0,g.jsx)(u,{className:`size-5 animate-spin`}),(0,g.jsx)(`span`,{className:`text-sm`,children:`Loading diff...`})]}):M?(0,g.jsx)(`div`,{className:`flex items-center justify-center h-full text-destructive text-sm`,children:M}):!w&&!T&&!H&&!U?(0,g.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full gap-2 text-muted-foreground`,children:[(0,g.jsx)(p,{className:`size-8`}),(0,g.jsx)(`p`,{className:`text-sm`,children:`No content changes`}),t&&(0,g.jsx)(`p`,{className:`text-xs font-mono`,children:t})]}):(0,g.jsxs)(`div`,{className:`flex flex-col h-full`,children:[!G&&(0,g.jsxs)(`div`,{className:`flex items-center justify-end gap-0.5 px-2 py-0.5 border-b border-border shrink-0`,children:[(0,g.jsx)(`button`,{type:`button`,onClick:()=>F(P===`left`?`both`:`left`),className:`p-1 rounded hover:bg-muted transition-colors ${P===`left`?`bg-muted text-foreground`:``}`,title:`Expand original`,children:(0,g.jsx)(f,{className:`size-3.5`})}),(0,g.jsx)(`button`,{type:`button`,onClick:()=>F(`both`),className:`p-1 rounded hover:bg-muted transition-colors ${P===`both`?`bg-muted text-foreground`:``}`,title:`Side by side`,children:(0,g.jsx)(i,{className:`size-3.5`})}),(0,g.jsx)(`button`,{type:`button`,onClick:()=>F(P===`right`?`both`:`right`),className:`p-1 rounded hover:bg-muted transition-colors ${P===`right`?`bg-muted text-foreground`:``}`,title:`Expand modified`,children:(0,g.jsx)(m,{className:`size-3.5`})}),(0,g.jsx)(`div`,{className:`w-px h-3.5 bg-border mx-0.5 shrink-0`}),(0,g.jsx)(`button`,{type:`button`,onClick:L,title:`Toggle word wrap`,className:`p-1 rounded hover:bg-muted transition-colors ${I?`bg-muted text-foreground`:``}`,children:(0,g.jsx)(a,{className:`size-3.5`})})]}),(0,g.jsx)(`div`,{ref:z,className:`flex-1 overflow-hidden`,children:B&&B>0?(0,g.jsx)(o,{height:B,language:W,original:H,modified:U,theme:R,options:{fontSize:G?11:13,fontFamily:`Menlo, Monaco, Consolas, monospace`,wordWrap:G||I?`on`:`off`,renderSideBySide:K,readOnly:!0,automaticLayout:!0,scrollBeyondLastLine:!1},loading:(0,g.jsx)(u,{className:`size-5 animate-spin text-muted-foreground`})}):(0,g.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,g.jsx)(u,{className:`size-5 animate-spin text-muted-foreground`})})})]})}function y(e){let t=e.split(`
2
2
  `),n=[],r=[],i=!1;for(let e of t)if(!(e.startsWith(`diff --git`)||e.startsWith(`diff --no-index`)||e.startsWith(`index `)||e.startsWith(`new file`)||e.startsWith(`deleted file`)||e.startsWith(`old mode`)||e.startsWith(`new mode`)||e.startsWith(`---`)||e.startsWith(`+++`)||e.startsWith(`Binary files`)||e.startsWith(`\\ No newline`))){if(e.startsWith(`@@`)){i=!0;continue}if(i)if(e.startsWith(`-`))n.push(e.slice(1));else if(e.startsWith(`+`))r.push(e.slice(1));else{let t=e.startsWith(` `)?e.slice(1):e;n.push(t),r.push(t)}}return{original:n.join(`
3
3
  `),modified:r.join(`
4
4
  `)}}export{v as DiffViewer};
@@ -1 +1 @@
1
- import{o as e}from"./chunk-CFjPhJqf.js";import{t}from"./react-nm2Ru1Pt.js";import"./react-dom-Bpkvzu3U.js";import{n,t as r}from"./jsx-runtime-BRW_vwa9.js";import{a as i,i as a,n as o,r as s,t as c}from"./input-BglMT33g.js";import{o as l,t as u}from"./tab-store-BCfMgMKM.js";import{t as d}from"./tag-CCtdV063.js";import"./dist-lF8CoYII.js";import{t as f}from"./utils-BNytJOb1.js";import{i as p,t as m}from"./api-client-BfBM3I7n.js";import{B as h,C as g,F as _,J as v,L as y,S as b,T as x,V as S,X as C,b as w,g as T,h as E,it as D,mt as O,ot as k,v as A,w as j,x as M,y as N,z as P}from"./index-DtlqB_mF.js";var F=n(`cherry`,[[`path`,{d:`M2 17a5 5 0 0 0 10 0c0-2.76-2.5-5-5-3-2.5-2-5 .24-5 3Z`,key:`cvxqlc`}],[`path`,{d:`M12 17a5 5 0 0 0 10 0c0-2.76-2.5-5-5-3-2.5-2-5 .24-5 3Z`,key:`1ostrc`}],[`path`,{d:`M7 14c3.22-2.91 4.29-8.75 5-12 1.66 2.38 4.94 9 5 12`,key:`hqx58h`}],[`path`,{d:`M22 9c-4.29 0-7.14-2.33-10-7 5.71 0 10 4.67 10 7Z`,key:`eykp1o`}]]),I=n(`git-merge`,[[`circle`,{cx:`18`,cy:`18`,r:`3`,key:`1xkwt0`}],[`circle`,{cx:`6`,cy:`6`,r:`3`,key:`1lh9wr`}],[`path`,{d:`M6 21V9a9 9 0 0 0 9 9`,key:`7kw0sc`}]]),L=e(t(),1),R=[`#0085d9`,`#d73a49`,`#6f42c1`,`#2cbe4e`,`#e36209`,`#005cc5`,`#b31d28`,`#5a32a3`,`#22863a`,`#cb2431`];function ee(e){let t=new Map;if(!e)return t;let n=new Set;for(let t of e.branches)if(!t.remote)for(let e of t.remotes)n.add(`remotes/${e}/${t.name}`);for(let r of e.branches)if(r.remote){if(n.has(r.name))continue;let e=t.get(r.commitHash)??[],i=r.name.replace(/^remotes\//,``);e.push({name:i,type:`branch`,remotes:[],current:!1}),t.set(r.commitHash,e)}else{let e=t.get(r.commitHash)??[];e.push({name:r.name,type:`branch`,remotes:r.remotes,current:r.current}),t.set(r.commitHash,e)}for(let n of e.commits)for(let e of n.refs)if(e.startsWith(`tag: `)){let r=e.replace(`tag: `,``),i=t.get(n.hash)??[];i.push({name:r,type:`tag`,remotes:[],current:!1}),t.set(n.hash,i)}return t}function te(e){let t=new Map;if(!e)return{laneMap:t,maxLane:0,unloadedParentLanes:new Map};let n=0,r=0,i=new Map,a=new Set(e.commits.map(e=>e.hash)),o=[],s=()=>o.length>0?(o.sort((e,t)=>e-t),o.shift()):n++;for(let n of e.commits){let e=i.get(n.hash);e===void 0&&(e=s()),t.set(n.hash,e),e>r&&(r=e),i.delete(n.hash);let a=!1;for(let t=0;t<n.parents.length;t++){let o=n.parents[t];if(!i.has(o))if(t===0)i.set(o,e),a=!0;else{let e=s();i.set(o,e),e>r&&(r=e)}}a||o.push(e)}let c=new Map;for(let[e,t]of i)a.has(e)||c.set(e,t);return{laneMap:t,maxLane:r,unloadedParentLanes:c}}function ne(e,t,n,r){if(!e)return[];let i=[],a=new Set(e.commits.map(e=>e.hash));for(let o=0;o<e.commits.length;o++){let s=e.commits[o],c=t.get(s.hash)??0,l=R[c%R.length];for(let u of s.parents){let d=e.commits.findIndex(e=>e.hash===u);if(d>=0){let e=t.get(u)??0,n=R[e%R.length],r=c*16+16/2,a=o*24+24/2,f=e*16+16/2,p=d*24+24/2,m,h=s.parents.indexOf(u)>0;if(r===f)m=`M ${r} ${a} L ${f} ${p}`;else if(h){let e=a+24;m=`M ${r} ${a} C ${r} ${e} ${f} ${a} ${f} ${e} L ${f} ${p}`}else{let e=p-24;m=`M ${r} ${a} L ${r} ${e} C ${r} ${p} ${f} ${e} ${f} ${p}`}let g=s.parents.indexOf(u)===0?l:n;i.push({d:m,color:g})}else if(!a.has(u)){let e=n.get(u)??c,t=R[e%R.length],a=c*16+16/2,s=o*24+24/2,d=e*16+16/2;if(a===d)i.push({d:`M ${a} ${s} L ${a} ${r}`,color:l});else{let e=s+24,n=`M ${a} ${s} C ${a} ${e} ${d} ${s} ${d} ${e} L ${d} ${r}`;i.push({d:n,color:t})}}}}return i}function re(e){let t=new Date(e),n=new Date().getTime()-t.getTime(),r=Math.floor(n/6e4);if(r<1)return`just now`;if(r<60)return`${r}m ago`;let i=Math.floor(r/60);if(i<24)return`${i}h ago`;let a=Math.floor(i/24);if(a<30)return`${a}d ago`;let o=Math.floor(a/30);return o<12?`${o}mo ago`:`${Math.floor(o/12)}y ago`}var z=200;function B(e){let[t,n]=(0,L.useState)(null),[r,i]=(0,L.useState)(!0),[a,o]=(0,L.useState)(!1),[s,c]=(0,L.useState)(!0),[l,d]=(0,L.useState)(null),[f,h]=(0,L.useState)(!1),[g,_]=(0,L.useState)(null),[v,y]=(0,L.useState)([]),[b,x]=(0,L.useState)(!1),[S,C]=(0,L.useState)(`__all__`),[w,T]=(0,L.useState)(``),[E,D]=(0,L.useState)(!1),{openTab:O}=u(),k=(0,L.useRef)(0),A=(0,L.useCallback)(async()=>{if(e)try{i(!0);let t=Math.max(z,k.current),r=await m.get(`${p(e)}/git/graph?max=${t}`);n(r),k.current=r.commits.length,c(r.commits.length>=t),d(null)}catch(e){d(e instanceof Error?e.message:`Failed to fetch graph`)}finally{i(!1)}},[e]),j=(0,L.useCallback)(async()=>{if(!(!e||a||!s))try{o(!0);let t=k.current,r=await m.get(`${p(e)}/git/graph?max=${z}&skip=${t}`);if(r.commits.length===0){c(!1);return}n(e=>{if(!e)return r;let t=new Set(e.commits.map(e=>e.hash)),n=r.commits.filter(e=>!t.has(e.hash)),i=new Set(e.branches.map(e=>e.name)),a=r.branches.filter(e=>!i.has(e.name));return{commits:[...e.commits,...n],branches:[...e.branches,...a],head:e.head}}),k.current=t+r.commits.length,c(r.commits.length>=z)}catch(e){d(e instanceof Error?e.message:`Failed to load more`)}finally{o(!1)}},[e,a,s]);(0,L.useEffect)(()=>{A();let e=setInterval(A,1e4);return()=>clearInterval(e)},[A]);let M=async(t,n)=>{if(e){h(!0);try{await m.post(`${p(e)}${t}`,n),await A()}catch(e){d(e instanceof Error?e.message:`Action failed`)}finally{h(!1)}}},N=()=>M(`/git/fetch`,{}),P=e=>M(`/git/checkout`,{ref:e}),F=e=>M(`/git/cherry-pick`,{hash:e}),I=e=>M(`/git/revert`,{hash:e}),R=e=>M(`/git/merge`,{source:e}),re=e=>M(`/git/branch/delete`,{name:e}),B=e=>M(`/git/push`,{branch:e}),V=(e,t)=>M(`/git/tag`,{name:e,hash:t}),H=e=>navigator.clipboard.writeText(e),U=async(e,n)=>{if(t?.branches.some(t=>t.name===e||t.name.endsWith(`/${e}`))){if(!window.confirm(`Branch "${e}" already exists.\nDelete and recreate from this commit?`))return;await M(`/git/branch/delete`,{name:e})}await M(`/git/branch/create`,{name:e,from:n})},W=async t=>{if(e)try{let n=await m.get(`${p(e)}/git/pr-url?branch=${encodeURIComponent(t)}`);n.url&&window.open(n.url,`_blank`)}catch{}},G=async t=>{if(g?.hash===t.hash){_(null);return}_(t),x(!0);try{let n=t.parents[0]??``,r=n?`ref1=${encodeURIComponent(n)}&`:``,i=await m.get(`${p(e)}/git/diff-stat?${r}ref2=${encodeURIComponent(t.hash)}`);y(Array.isArray(i)?i:[])}catch{y([])}finally{x(!1)}},K=t=>O({type:`git-diff`,title:`Diff ${t.abbreviatedHash}`,closable:!0,metadata:{projectName:e,ref1:t.parents[0]??void 0,ref2:t.hash},projectId:e??null}),q=(0,L.useMemo)(()=>ee(t),[t]),J=t?.branches.find(e=>e.current),Y=t?.head??``,X=(0,L.useMemo)(()=>{if(!t)return[];let e=t.commits;if(S!==`__all__`){let n=t.branches.find(e=>e.name===S);if(n){let r=new Set,i=[n.commitHash];for(;i.length>0;){let e=i.pop();if(r.has(e))continue;r.add(e);let n=t.commits.find(t=>t.hash===e);n&&i.push(...n.parents)}e=e.filter(e=>r.has(e.hash))}}if(w.trim()){let t=w.toLowerCase();e=e.filter(e=>e.subject.toLowerCase().includes(t)||e.authorName.toLowerCase().includes(t)||e.abbreviatedHash.includes(t)||e.hash.includes(t))}return e},[t,S,w]),Z=(0,L.useMemo)(()=>t?{...t,commits:X}:null,[t,X]),Q=(0,L.useMemo)(()=>te(Z),[Z]),$=X.length*24+48;return{data:t,loading:r,loadingMore:a,hasMore:s,error:l,acting:f,selectedCommit:g,setSelectedCommit:_,commitFiles:v,loadingDetail:b,branchFilter:S,setBranchFilter:C,searchQuery:w,setSearchQuery:T,showSearch:E,setShowSearch:D,fetchGraph:A,fetchFromRemotes:N,loadMore:j,handleCheckout:P,handleCherryPick:F,handleRevert:I,handleMerge:R,handleDeleteBranch:re,handlePushBranch:B,handleCreateBranch:U,handleCreateTag:V,handleCreatePr:W,copyHash:H,selectCommit:G,openDiffForCommit:K,commitLabels:q,currentBranch:J,headHash:Y,filteredCommits:X,filteredLanes:Q,svgHeight:$,svgPaths:(0,L.useMemo)(()=>ne(Z,Q.laneMap,Q.unloadedParentLanes,$),[Z,Q.laneMap,Q.unloadedParentLanes,$])}}function V(e){let[t,n]=(0,L.useState)(e),r=(0,L.useRef)(e);r.current=t;let i=(0,L.useRef)(!1);return{widths:t,startResize:(e,t)=>{i.current=!0;let a=r.current[e]??80,o=r=>{if(!i.current)return;let o=`touches`in r?r.touches[0].clientX:r.clientX,s=Math.max(40,a+o-t);n(t=>({...t,[e]:s}))},s=()=>{i.current=!1,window.removeEventListener(`mousemove`,o),window.removeEventListener(`mouseup`,s),window.removeEventListener(`touchmove`,o),window.removeEventListener(`touchend`,s)};window.addEventListener(`mousemove`,o),window.addEventListener(`mouseup`,s),window.addEventListener(`touchmove`,o,{passive:!1}),window.addEventListener(`touchend`,s)}}}var H=r();function U({branches:e,branchFilter:t,onBranchFilterChange:n,searchQuery:r,onSearchQueryChange:i,showSearch:s,onToggleSearch:l,onFetch:u,onRefresh:d,onOpenSettings:f,loading:p,acting:m,projectName:g}){let v=e.filter(e=>!e.remote),[y,b]=(0,L.useState)(!1),[x,C]=(0,L.useState)(``),w=(0,L.useRef)(null);(0,L.useEffect)(()=>{if(!y)return;let e=e=>{w.current&&!w.current.contains(e.target)&&(b(!1),C(``))};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[y]);let T=x?v.filter(e=>e.name.toLowerCase().includes(x.toLowerCase())):v,E=t===`__all__`?`Show All`:v.find(e=>e.name===t)?.name??`Show All`;return(0,H.jsx)(`div`,{className:`border-b bg-background`,children:(0,H.jsxs)(`div`,{className:`flex items-center gap-1.5 px-2 py-1.5`,children:[(0,H.jsxs)(`div`,{className:`flex items-center gap-1 text-xs text-muted-foreground shrink-0`,children:[(0,H.jsx)(`span`,{className:`font-semibold`,children:`Repo:`}),(0,H.jsx)(`span`,{className:`font-medium text-foreground truncate max-w-[120px]`,children:g??`—`})]}),(0,H.jsx)(`div`,{className:`w-px h-4 bg-border mx-1`}),(0,H.jsxs)(`div`,{className:`relative shrink-0`,ref:w,children:[(0,H.jsxs)(`button`,{type:`button`,className:`flex items-center gap-1 h-6 px-2 text-xs border rounded-md bg-transparent hover:bg-muted/50`,onClick:()=>{b(e=>!e),C(``)},children:[(0,H.jsx)(`span`,{className:`font-semibold text-muted-foreground`,children:`Branches:`}),(0,H.jsx)(`span`,{className:`max-w-[100px] truncate`,children:E}),(0,H.jsx)(a,{className:`size-3 opacity-50`})]}),y&&(0,H.jsxs)(`div`,{className:`absolute top-full left-0 mt-1 z-50 w-[220px] rounded-md border bg-popover shadow-md`,children:[(0,H.jsx)(`div`,{className:`p-1.5`,children:(0,H.jsx)(c,{className:`h-6 text-xs px-2`,placeholder:`Filter branches...`,value:x,onChange:e=>C(e.target.value),autoFocus:!0})}),(0,H.jsxs)(`div`,{className:`max-h-[200px] overflow-y-auto p-1`,children:[(0,H.jsx)(W,{label:`Show All`,selected:t===`__all__`,onClick:()=>{n(`__all__`),b(!1)}}),T.map(e=>(0,H.jsx)(W,{label:e.name,current:e.current,selected:t===e.name,onClick:()=>{n(e.name),b(!1)}},e.name)),T.length===0&&x&&(0,H.jsx)(`div`,{className:`px-2 py-1.5 text-xs text-muted-foreground`,children:`No branches found`})]})]})]}),(0,H.jsx)(`div`,{className:`flex-1`}),s&&(0,H.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,H.jsx)(c,{className:`h-6 text-xs w-[160px] px-2`,placeholder:`Search commits...`,value:r,onChange:e=>i(e.target.value),autoFocus:!0}),(0,H.jsx)(o,{variant:`ghost`,size:`icon-xs`,onClick:l,children:(0,H.jsx)(_,{className:`size-3`})})]}),!s&&(0,H.jsx)(o,{variant:`ghost`,size:`icon-xs`,onClick:l,title:`Find`,children:(0,H.jsx)(h,{className:`size-3.5`})}),(0,H.jsx)(o,{variant:`ghost`,size:`icon-xs`,onClick:f,title:`Settings`,children:(0,H.jsx)(P,{className:`size-3.5`})}),(0,H.jsx)(o,{variant:`ghost`,size:`icon-xs`,onClick:u,disabled:m,title:`Fetch`,children:(0,H.jsx)(D,{className:`size-3.5`})}),(0,H.jsx)(o,{variant:`ghost`,size:`icon-xs`,onClick:d,disabled:m,title:`Refresh`,children:(0,H.jsx)(S,{className:`size-3.5 ${p?`animate-spin`:``}`})})]})})}function W({label:e,selected:t,current:n,onClick:r}){return(0,H.jsxs)(`button`,{type:`button`,className:`flex items-center gap-2 w-full px-2 py-1 text-xs rounded-sm hover:bg-accent hover:text-accent-foreground text-left`,onClick:r,children:[(0,H.jsx)(i,{className:`size-3 shrink-0 ${t?`opacity-100`:`opacity-0`}`}),(0,H.jsx)(`span`,{className:`truncate flex-1`,children:e}),n&&(0,H.jsx)(`span`,{className:`text-[10px] text-muted-foreground italic`,children:`current`})]})}function G({commits:e,laneMap:t,svgPaths:n,width:r,height:i,headHash:a}){return(0,H.jsxs)(`svg`,{width:r,height:i,children:[n.map((e,t)=>(0,H.jsx)(`path`,{d:e.d,stroke:e.color,strokeWidth:2,fill:`none`},t)),e.map((e,n)=>{let r=t.get(e.hash)??0,i=r*16+16/2,o=n*24+24/2,s=R[r%R.length],c=e.hash===a;return(0,H.jsx)(`circle`,{cx:i,cy:o,r:c?5:4,fill:s,stroke:c?`#000`:`none`,strokeWidth:c?2:0},e.hash)})]})}function K({name:e,type:t,remotes:n,isCurrent:r,color:i,currentBranch:a,onCheckout:o,onMerge:s,onPush:c,onCreatePr:u,onDelete:f}){return t===`tag`?(0,H.jsxs)(`span`,{className:`inline-flex items-center gap-0.5 px-1.5 py-0.5 rounded text-[10px] font-medium shrink-0 bg-amber-500/20 text-amber-500 border border-amber-500/30`,children:[(0,H.jsx)(d,{className:`size-2.5`}),e]}):(0,H.jsxs)(M,{children:[(0,H.jsx)(x,{asChild:!0,children:(0,H.jsxs)(`span`,{className:`inline-flex items-center rounded text-[10px] font-medium shrink-0 cursor-context-menu overflow-hidden`,style:{border:r?`1.5px solid ${i}`:`1px solid ${i}50`},children:[(0,H.jsxs)(`span`,{className:`inline-flex items-center gap-0.5 px-1.5 py-0.5`,style:{backgroundColor:r?i:`${i}30`,color:r?`#fff`:i},children:[(0,H.jsx)(C,{className:`size-2.5`}),e]}),n.map(e=>(0,H.jsx)(`span`,{className:`px-1.5 py-0.5 italic opacity-70`,style:{borderLeft:`1px solid ${i}40`,color:i,backgroundColor:`${i}15`},children:e},e))]})}),(0,H.jsxs)(b,{children:[(0,H.jsx)(g,{onClick:()=>o(e),children:`Checkout`}),(0,H.jsxs)(g,{onClick:()=>s(e),disabled:e===a?.name,children:[(0,H.jsx)(I,{className:`size-3`}),`Merge into current`]}),(0,H.jsx)(j,{}),(0,H.jsxs)(g,{onClick:()=>c(e),children:[(0,H.jsx)(O,{className:`size-3`}),`Push`]}),(0,H.jsxs)(g,{onClick:()=>u(e),children:[(0,H.jsx)(l,{className:`size-3`}),`Create PR`]}),(0,H.jsx)(j,{}),(0,H.jsxs)(g,{variant:`destructive`,onClick:()=>f(e),disabled:e===a?.name,children:[(0,H.jsx)(y,{className:`size-3`}),`Delete`]})]})]})}function q({commit:e,lane:t,isSelected:n,isHead:r,labels:i,currentBranch:a,onSelect:o,onCheckout:c,onCherryPick:l,onRevert:u,onMerge:f,onDeleteBranch:p,onPushBranch:m,onCreatePr:h,onOpenCreateBranch:_,onOpenCreateTag:v,onOpenDiff:y,onCopyHash:S}){let w=R[t%R.length],T=i.filter(e=>e.type===`branch`),E=i.filter(e=>e.type===`tag`);return(0,H.jsxs)(M,{children:[(0,H.jsx)(x,{asChild:!0,children:(0,H.jsxs)(`tr`,{className:`hover:bg-muted/50 cursor-pointer border-b border-border/20 ${n?`bg-primary/10`:``} ${r?`font-medium`:``}`,style:{height:`24px`},onClick:o,children:[(0,H.jsx)(`td`,{className:`px-2 truncate max-w-0`,children:(0,H.jsxs)(`div`,{className:`flex items-center gap-1.5 min-w-0`,children:[T.map(e=>(0,H.jsx)(K,{name:e.name,type:`branch`,remotes:e.remotes,isCurrent:e.current,color:w,currentBranch:a,onCheckout:c,onMerge:f,onPush:m,onCreatePr:h,onDelete:p},`branch-${e.name}`)),E.map(e=>(0,H.jsx)(K,{name:e.name,type:`tag`,remotes:[],isCurrent:!1,color:w,currentBranch:a,onCheckout:c,onMerge:f,onPush:m,onCreatePr:h,onDelete:p},`tag-${e.name}`)),(0,H.jsx)(`span`,{className:`truncate text-xs`,children:e.subject})]})}),(0,H.jsx)(`td`,{className:`px-2 text-xs text-muted-foreground whitespace-nowrap shrink-0`,children:re(e.authorDate)}),(0,H.jsx)(`td`,{className:`px-2 text-xs text-muted-foreground truncate max-w-[120px]`,children:e.authorName}),(0,H.jsx)(`td`,{className:`px-2 text-xs text-muted-foreground font-mono whitespace-nowrap`,children:e.abbreviatedHash})]})}),(0,H.jsxs)(b,{children:[(0,H.jsx)(g,{onClick:()=>c(e.hash),children:`Checkout`}),(0,H.jsxs)(g,{onClick:()=>_(e.hash),children:[(0,H.jsx)(C,{className:`size-3`}),`Create Branch...`]}),(0,H.jsx)(j,{}),(0,H.jsxs)(g,{onClick:()=>l(e.hash),children:[(0,H.jsx)(F,{className:`size-3`}),`Cherry Pick`]}),(0,H.jsxs)(g,{onClick:()=>u(e.hash),children:[(0,H.jsx)(s,{className:`size-3`}),`Revert`]}),(0,H.jsxs)(g,{onClick:()=>v(e.hash),children:[(0,H.jsx)(d,{className:`size-3`}),`Create Tag...`]}),(0,H.jsx)(j,{}),(0,H.jsx)(g,{onClick:y,children:`View Diff`}),(0,H.jsxs)(g,{onClick:S,children:[(0,H.jsx)(k,{className:`size-3`}),`Copy Hash`]})]})]})}function J({commit:e,files:t,loadingDetail:n,projectName:r,onClose:i,copyHash:a}){let{openTab:s}=u();return(0,H.jsxs)(`div`,{className:`border-t bg-muted/30 max-h-[40%] overflow-auto`,children:[(0,H.jsxs)(`div`,{className:`px-3 py-2 border-b flex items-center justify-between`,children:[(0,H.jsxs)(`span`,{className:`text-sm font-medium truncate`,children:[e.abbreviatedHash,` — `,e.subject]}),(0,H.jsx)(o,{variant:`ghost`,size:`icon-xs`,onClick:i,children:`✕`})]}),(0,H.jsxs)(`div`,{className:`px-3 py-2 text-xs space-y-1`,children:[(0,H.jsxs)(`div`,{className:`flex gap-4`,children:[(0,H.jsx)(`span`,{className:`text-muted-foreground w-12 shrink-0`,children:`Author`}),(0,H.jsxs)(`span`,{children:[e.authorName,` <`,e.authorEmail,`>`]})]}),(0,H.jsxs)(`div`,{className:`flex gap-4`,children:[(0,H.jsx)(`span`,{className:`text-muted-foreground w-12 shrink-0`,children:`Date`}),(0,H.jsx)(`span`,{children:new Date(e.authorDate).toLocaleString()})]}),(0,H.jsxs)(`div`,{className:`flex gap-4`,children:[(0,H.jsx)(`span`,{className:`text-muted-foreground w-12 shrink-0`,children:`Hash`}),(0,H.jsx)(`span`,{className:`font-mono cursor-pointer hover:text-primary`,onClick:()=>a(e.hash),children:e.hash})]}),e.parents.length>0&&(0,H.jsxs)(`div`,{className:`flex gap-4`,children:[(0,H.jsx)(`span`,{className:`text-muted-foreground w-12 shrink-0`,children:`Parents`}),(0,H.jsx)(`span`,{className:`font-mono`,children:e.parents.map(e=>e.slice(0,7)).join(`, `)})]}),e.body&&(0,H.jsx)(`div`,{className:`mt-2 p-2 bg-background rounded text-xs whitespace-pre-wrap`,children:e.body})]}),(0,H.jsxs)(`div`,{className:`px-3 py-1 border-t`,children:[(0,H.jsx)(`div`,{className:`text-xs text-muted-foreground py-1`,children:n?`Loading files...`:`${t.length} file${t.length===1?``:`s`} changed`}),t.map(t=>(0,H.jsxs)(`div`,{className:`flex items-center gap-2 py-0.5 text-xs hover:bg-muted/50 rounded px-1 cursor-pointer`,onClick:()=>s({type:`git-diff`,title:`Diff ${f(t.path)}`,closable:!0,metadata:{projectName:r,ref1:e.parents[0]??void 0,ref2:e.hash,filePath:t.path},projectId:r}),children:[(0,H.jsx)(`span`,{className:`flex-1 truncate font-mono`,children:t.path}),t.additions>0&&(0,H.jsxs)(`span`,{className:`text-green-500`,children:[`+`,t.additions]}),t.deletions>0&&(0,H.jsxs)(`span`,{className:`text-red-500`,children:[`-`,t.deletions]})]},t.path))]})]})}function Y({type:e,hash:t,onClose:n,onCreateBranch:r,onCreateTag:i}){let[a,s]=(0,L.useState)(``),l=()=>{a.trim()&&(e===`branch`?r(a.trim(),t):i(a.trim(),t),n())};return(0,H.jsx)(E,{open:e!==null,onOpenChange:e=>{e||n()},children:(0,H.jsxs)(T,{children:[(0,H.jsx)(N,{children:(0,H.jsx)(w,{children:e===`branch`?`Create Branch`:`Create Tag`})}),(0,H.jsx)(c,{placeholder:e===`branch`?`Branch name`:`Tag name`,value:a,onChange:e=>s(e.target.value),onKeyDown:e=>{e.key===`Enter`&&l()},autoFocus:!0}),(0,H.jsxs)(A,{children:[(0,H.jsx)(o,{variant:`outline`,onClick:n,children:`Cancel`}),(0,H.jsx)(o,{disabled:!a.trim(),onClick:l,children:`Create`})]})]})})}function X({open:e,onClose:t,projectName:n,branches:r}){let i=r.filter(e=>!e.remote),a=r.filter(e=>e.remote),o=new Map;for(let e of a){let t=e.name.replace(/^remotes\//,``),n=t.indexOf(`/`);if(n<0)continue;let r=t.slice(0,n),i=t.slice(n+1),a=o.get(r)??[];a.push(i),o.set(r,a)}return(0,H.jsx)(E,{open:e,onOpenChange:e=>{e||t()},children:(0,H.jsxs)(T,{className:`max-w-md`,children:[(0,H.jsx)(N,{children:(0,H.jsx)(w,{children:`Repository Settings`})}),(0,H.jsxs)(`div`,{className:`space-y-4 text-sm`,children:[(0,H.jsxs)(Z,{title:`General`,children:[(0,H.jsx)(Q,{label:`Name`,value:n}),(0,H.jsx)(Q,{label:`Branches`,value:`${i.length} local, ${a.length} remote`})]}),(0,H.jsx)(Z,{title:`Local Branches`,children:i.map(e=>(0,H.jsxs)(`div`,{className:`flex items-center gap-2 py-0.5`,children:[(0,H.jsx)(`span`,{className:`text-xs ${e.current?`font-semibold text-primary`:`text-foreground`}`,children:e.name}),e.current&&(0,H.jsx)(`span`,{className:`text-[10px] text-muted-foreground italic`,children:`HEAD`}),e.remotes.length>0&&(0,H.jsxs)(`span`,{className:`text-[10px] text-muted-foreground`,children:[`(`,e.remotes.join(`, `),`)`]})]},e.name))}),(0,H.jsxs)(Z,{title:`Remotes`,children:[[...o.entries()].map(([e,t])=>(0,H.jsxs)(`div`,{className:`py-0.5`,children:[(0,H.jsx)(`span`,{className:`text-xs font-medium`,children:e}),(0,H.jsxs)(`span`,{className:`text-[10px] text-muted-foreground ml-2`,children:[t.length,` branch`,t.length===1?``:`es`]})]},e)),o.size===0&&(0,H.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`No remotes configured`})]})]})]})})}function Z({title:e,children:t}){return(0,H.jsxs)(`div`,{children:[(0,H.jsx)(`h4`,{className:`text-xs font-semibold text-muted-foreground uppercase tracking-wider mb-1.5`,children:e}),(0,H.jsx)(`div`,{className:`pl-1`,children:t})]})}function Q({label:e,value:t}){return(0,H.jsxs)(`div`,{className:`flex items-center gap-3 py-0.5`,children:[(0,H.jsx)(`span`,{className:`text-xs text-muted-foreground w-16 shrink-0`,children:e}),(0,H.jsx)(`span`,{className:`text-xs`,children:t})]})}function $({metadata:e}){let t=e?.projectName,n=B(t),[r,i]=(0,L.useState)({type:null}),[a,o]=(0,L.useState)(!1),s=(typeof window<`u`&&window.innerWidth<768?6:10)*16+16,[c,l]=(0,L.useState)(s),u=(0,L.useRef)(s);u.current=c;let d=(0,L.useRef)(!1),f=e=>{d.current=!0;let t=u.current,n=n=>{if(!d.current)return;let r=`touches`in n?n.touches[0].clientX:n.clientX;l(Math.max(40,t+r-e))},r=()=>{d.current=!1,window.removeEventListener(`mousemove`,n),window.removeEventListener(`mouseup`,r),window.removeEventListener(`touchmove`,n),window.removeEventListener(`touchend`,r)};window.addEventListener(`mousemove`,n),window.addEventListener(`mouseup`,r),window.addEventListener(`touchmove`,n,{passive:!1}),window.addEventListener(`touchend`,r)},{widths:p,startResize:m}=V({date:80,author:120,commit:70}),h=(0,L.useRef)(n.loadMore);h.current=n.loadMore;let g=(0,L.useCallback)(e=>{let t=e.currentTarget;t.scrollHeight-t.scrollTop-t.clientHeight<200&&h.current()},[]);return t?n.loading&&!n.data?(0,H.jsx)(oe,{}):n.error&&!n.data?(0,H.jsx)(se,{error:n.error,onRetry:n.fetchGraph}):(0,H.jsxs)(`div`,{className:`flex flex-col h-full`,children:[(0,H.jsx)(U,{branches:n.data?.branches??[],branchFilter:n.branchFilter,onBranchFilterChange:n.setBranchFilter,searchQuery:n.searchQuery,onSearchQueryChange:n.setSearchQuery,showSearch:n.showSearch,onToggleSearch:()=>n.setShowSearch(!n.showSearch),onFetch:n.fetchFromRemotes,onRefresh:n.fetchGraph,onOpenSettings:()=>o(!0),loading:n.loading,acting:n.acting,projectName:t}),n.error&&(0,H.jsx)(`div`,{className:`px-3 py-1.5 text-xs text-destructive bg-destructive/10`,children:n.error}),(0,H.jsx)(`div`,{className:`flex-1 overflow-auto`,onScroll:g,children:(0,H.jsxs)(`div`,{className:`flex min-w-max md:min-w-0`,children:[(0,H.jsxs)(`div`,{className:`sticky left-0 z-10 shrink-0 bg-background relative overflow-hidden`,style:{width:`${c}px`},children:[(0,H.jsx)(`div`,{className:`text-[11px] font-semibold text-muted-foreground px-2 border-b bg-background sticky top-0 z-20`,style:{height:`24px`,lineHeight:`24px`},children:`Graph`}),(0,H.jsx)(G,{commits:n.filteredCommits,laneMap:n.filteredLanes.laneMap,svgPaths:n.svgPaths,width:(n.filteredLanes.maxLane+2)*16,height:n.svgHeight,headHash:n.headHash}),(0,H.jsx)(`div`,{className:`absolute top-0 right-0 w-1.5 h-full cursor-col-resize hover:bg-primary/30`,onMouseDown:e=>{e.preventDefault(),f(e.clientX)},onTouchStart:e=>f(e.touches[0].clientX)})]}),(0,H.jsxs)(`div`,{className:`flex-1 min-w-[400px]`,children:[(0,H.jsxs)(`table`,{className:`w-full border-collapse text-xs`,style:{tableLayout:`fixed`},children:[(0,H.jsxs)(`colgroup`,{children:[(0,H.jsx)(`col`,{}),(0,H.jsx)(`col`,{style:{width:`${p.date}px`}}),(0,H.jsx)(`col`,{style:{width:`${p.author}px`}}),(0,H.jsx)(`col`,{style:{width:`${p.commit}px`}})]}),(0,H.jsx)(`thead`,{className:`sticky top-0 z-10 bg-background`,children:(0,H.jsxs)(`tr`,{className:`border-b text-[11px] font-semibold text-muted-foreground`,style:{height:`24px`},children:[(0,H.jsx)(`th`,{className:`text-left px-2 font-semibold`,children:`Description`}),(0,H.jsx)(ie,{label:`Date`,colKey:`date`,onStartResize:m}),(0,H.jsx)(ie,{label:`Author`,colKey:`author`,onStartResize:m}),(0,H.jsx)(`th`,{className:`text-left px-2 font-semibold`,children:`Commit`})]})}),(0,H.jsx)(`tbody`,{children:n.filteredCommits.map(e=>(0,H.jsx)(q,{commit:e,lane:n.filteredLanes.laneMap.get(e.hash)??0,isSelected:n.selectedCommit?.hash===e.hash,isHead:e.hash===n.headHash,labels:n.commitLabels.get(e.hash)??[],currentBranch:n.currentBranch,onSelect:()=>n.selectCommit(e),onCheckout:n.handleCheckout,onCherryPick:n.handleCherryPick,onRevert:n.handleRevert,onMerge:n.handleMerge,onDeleteBranch:n.handleDeleteBranch,onPushBranch:n.handlePushBranch,onCreatePr:n.handleCreatePr,onOpenCreateBranch:e=>i({type:`branch`,hash:e}),onOpenCreateTag:e=>i({type:`tag`,hash:e}),onOpenDiff:()=>n.openDiffForCommit(e),onCopyHash:()=>n.copyHash(e.hash)},e.hash))})]}),n.loadingMore&&(0,H.jsxs)(`div`,{className:`flex items-center justify-center gap-2 py-3 text-xs text-muted-foreground`,children:[(0,H.jsx)(v,{className:`size-3.5 animate-spin`}),` Loading more commits...`]}),!n.hasMore&&n.data&&n.data.commits.length>0&&(0,H.jsxs)(`div`,{className:`text-center py-2 text-xs text-muted-foreground`,children:[n.data.commits.length,` commits loaded`]})]})]})}),n.selectedCommit&&t&&(0,H.jsx)(J,{commit:n.selectedCommit,files:n.commitFiles,loadingDetail:n.loadingDetail,projectName:t,onClose:()=>n.setSelectedCommit(null),copyHash:n.copyHash}),(0,H.jsx)(Y,{type:r.type,hash:r.hash,onClose:()=>i({type:null}),onCreateBranch:n.handleCreateBranch,onCreateTag:n.handleCreateTag}),(0,H.jsx)(X,{open:a,onClose:()=>o(!1),projectName:t,branches:n.data?.branches??[]})]}):(0,H.jsx)(ae,{msg:`No project selected.`})}function ie({label:e,colKey:t,onStartResize:n}){return(0,H.jsxs)(`th`,{className:`text-left px-2 font-semibold relative`,children:[e,(0,H.jsx)(`div`,{className:`absolute top-0 right-0 w-1.5 h-full cursor-col-resize hover:bg-primary/30`,onMouseDown:e=>{e.preventDefault(),n(t,e.clientX)},onTouchStart:e=>n(t,e.touches[0].clientX)})]})}function ae({msg:e}){return(0,H.jsx)(`div`,{className:`flex items-center justify-center h-full text-muted-foreground text-sm`,children:e})}function oe(){return(0,H.jsxs)(`div`,{className:`flex items-center justify-center h-full gap-2 text-muted-foreground`,children:[(0,H.jsx)(v,{className:`size-5 animate-spin`}),(0,H.jsx)(`span`,{className:`text-sm`,children:`Loading git graph...`})]})}function se({error:e,onRetry:t}){return(0,H.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full gap-2 text-destructive text-sm`,children:[(0,H.jsx)(`p`,{children:e}),(0,H.jsx)(o,{variant:`outline`,size:`sm`,onClick:t,children:`Retry`})]})}export{$ as GitGraph};
1
+ import{o as e}from"./chunk-CFjPhJqf.js";import{t}from"./react-nm2Ru1Pt.js";import"./react-dom-Bpkvzu3U.js";import{n,t as r}from"./jsx-runtime-BRW_vwa9.js";import{a as i,i as a,n as o,r as s,t as c}from"./input-BglMT33g.js";import{o as l,t as u}from"./tab-store-BCfMgMKM.js";import{t as d}from"./tag-CCtdV063.js";import"./dist-lF8CoYII.js";import{t as f}from"./utils-BNytJOb1.js";import{i as p,t as m}from"./api-client-BfBM3I7n.js";import{B as h,C as g,F as _,J as v,L as y,S as b,T as x,V as S,X as C,b as w,g as T,h as E,ht as D,it as O,ot as k,v as A,w as j,x as M,y as N,z as P}from"./index-ButO-DnP.js";var F=n(`cherry`,[[`path`,{d:`M2 17a5 5 0 0 0 10 0c0-2.76-2.5-5-5-3-2.5-2-5 .24-5 3Z`,key:`cvxqlc`}],[`path`,{d:`M12 17a5 5 0 0 0 10 0c0-2.76-2.5-5-5-3-2.5-2-5 .24-5 3Z`,key:`1ostrc`}],[`path`,{d:`M7 14c3.22-2.91 4.29-8.75 5-12 1.66 2.38 4.94 9 5 12`,key:`hqx58h`}],[`path`,{d:`M22 9c-4.29 0-7.14-2.33-10-7 5.71 0 10 4.67 10 7Z`,key:`eykp1o`}]]),I=n(`git-merge`,[[`circle`,{cx:`18`,cy:`18`,r:`3`,key:`1xkwt0`}],[`circle`,{cx:`6`,cy:`6`,r:`3`,key:`1lh9wr`}],[`path`,{d:`M6 21V9a9 9 0 0 0 9 9`,key:`7kw0sc`}]]),L=e(t(),1),R=[`#0085d9`,`#d73a49`,`#6f42c1`,`#2cbe4e`,`#e36209`,`#005cc5`,`#b31d28`,`#5a32a3`,`#22863a`,`#cb2431`];function ee(e){let t=new Map;if(!e)return t;let n=new Set;for(let t of e.branches)if(!t.remote)for(let e of t.remotes)n.add(`remotes/${e}/${t.name}`);for(let r of e.branches)if(r.remote){if(n.has(r.name))continue;let e=t.get(r.commitHash)??[],i=r.name.replace(/^remotes\//,``);e.push({name:i,type:`branch`,remotes:[],current:!1}),t.set(r.commitHash,e)}else{let e=t.get(r.commitHash)??[];e.push({name:r.name,type:`branch`,remotes:r.remotes,current:r.current}),t.set(r.commitHash,e)}for(let n of e.commits)for(let e of n.refs)if(e.startsWith(`tag: `)){let r=e.replace(`tag: `,``),i=t.get(n.hash)??[];i.push({name:r,type:`tag`,remotes:[],current:!1}),t.set(n.hash,i)}return t}function te(e){let t=new Map;if(!e)return{laneMap:t,maxLane:0,unloadedParentLanes:new Map};let n=0,r=0,i=new Map,a=new Set(e.commits.map(e=>e.hash)),o=[],s=()=>o.length>0?(o.sort((e,t)=>e-t),o.shift()):n++;for(let n of e.commits){let e=i.get(n.hash);e===void 0&&(e=s()),t.set(n.hash,e),e>r&&(r=e),i.delete(n.hash);let a=!1;for(let t=0;t<n.parents.length;t++){let o=n.parents[t];if(!i.has(o))if(t===0)i.set(o,e),a=!0;else{let e=s();i.set(o,e),e>r&&(r=e)}}a||o.push(e)}let c=new Map;for(let[e,t]of i)a.has(e)||c.set(e,t);return{laneMap:t,maxLane:r,unloadedParentLanes:c}}function ne(e,t,n,r){if(!e)return[];let i=[],a=new Set(e.commits.map(e=>e.hash));for(let o=0;o<e.commits.length;o++){let s=e.commits[o],c=t.get(s.hash)??0,l=R[c%R.length];for(let u of s.parents){let d=e.commits.findIndex(e=>e.hash===u);if(d>=0){let e=t.get(u)??0,n=R[e%R.length],r=c*16+16/2,a=o*24+24/2,f=e*16+16/2,p=d*24+24/2,m,h=s.parents.indexOf(u)>0;if(r===f)m=`M ${r} ${a} L ${f} ${p}`;else if(h){let e=a+24;m=`M ${r} ${a} C ${r} ${e} ${f} ${a} ${f} ${e} L ${f} ${p}`}else{let e=p-24;m=`M ${r} ${a} L ${r} ${e} C ${r} ${p} ${f} ${e} ${f} ${p}`}let g=s.parents.indexOf(u)===0?l:n;i.push({d:m,color:g})}else if(!a.has(u)){let e=n.get(u)??c,t=R[e%R.length],a=c*16+16/2,s=o*24+24/2,d=e*16+16/2;if(a===d)i.push({d:`M ${a} ${s} L ${a} ${r}`,color:l});else{let e=s+24,n=`M ${a} ${s} C ${a} ${e} ${d} ${s} ${d} ${e} L ${d} ${r}`;i.push({d:n,color:t})}}}}return i}function re(e){let t=new Date(e),n=new Date().getTime()-t.getTime(),r=Math.floor(n/6e4);if(r<1)return`just now`;if(r<60)return`${r}m ago`;let i=Math.floor(r/60);if(i<24)return`${i}h ago`;let a=Math.floor(i/24);if(a<30)return`${a}d ago`;let o=Math.floor(a/30);return o<12?`${o}mo ago`:`${Math.floor(o/12)}y ago`}var z=200;function B(e){let[t,n]=(0,L.useState)(null),[r,i]=(0,L.useState)(!0),[a,o]=(0,L.useState)(!1),[s,c]=(0,L.useState)(!0),[l,d]=(0,L.useState)(null),[f,h]=(0,L.useState)(!1),[g,_]=(0,L.useState)(null),[v,y]=(0,L.useState)([]),[b,x]=(0,L.useState)(!1),[S,C]=(0,L.useState)(`__all__`),[w,T]=(0,L.useState)(``),[E,D]=(0,L.useState)(!1),{openTab:O}=u(),k=(0,L.useRef)(0),A=(0,L.useCallback)(async()=>{if(e)try{i(!0);let t=Math.max(z,k.current),r=await m.get(`${p(e)}/git/graph?max=${t}`);n(r),k.current=r.commits.length,c(r.commits.length>=t),d(null)}catch(e){d(e instanceof Error?e.message:`Failed to fetch graph`)}finally{i(!1)}},[e]),j=(0,L.useCallback)(async()=>{if(!(!e||a||!s))try{o(!0);let t=k.current,r=await m.get(`${p(e)}/git/graph?max=${z}&skip=${t}`);if(r.commits.length===0){c(!1);return}n(e=>{if(!e)return r;let t=new Set(e.commits.map(e=>e.hash)),n=r.commits.filter(e=>!t.has(e.hash)),i=new Set(e.branches.map(e=>e.name)),a=r.branches.filter(e=>!i.has(e.name));return{commits:[...e.commits,...n],branches:[...e.branches,...a],head:e.head}}),k.current=t+r.commits.length,c(r.commits.length>=z)}catch(e){d(e instanceof Error?e.message:`Failed to load more`)}finally{o(!1)}},[e,a,s]);(0,L.useEffect)(()=>{A();let e=setInterval(A,1e4);return()=>clearInterval(e)},[A]);let M=async(t,n)=>{if(e){h(!0);try{await m.post(`${p(e)}${t}`,n),await A()}catch(e){d(e instanceof Error?e.message:`Action failed`)}finally{h(!1)}}},N=()=>M(`/git/fetch`,{}),P=e=>M(`/git/checkout`,{ref:e}),F=e=>M(`/git/cherry-pick`,{hash:e}),I=e=>M(`/git/revert`,{hash:e}),R=e=>M(`/git/merge`,{source:e}),re=e=>M(`/git/branch/delete`,{name:e}),B=e=>M(`/git/push`,{branch:e}),V=(e,t)=>M(`/git/tag`,{name:e,hash:t}),H=e=>navigator.clipboard.writeText(e),U=async(e,n)=>{if(t?.branches.some(t=>t.name===e||t.name.endsWith(`/${e}`))){if(!window.confirm(`Branch "${e}" already exists.\nDelete and recreate from this commit?`))return;await M(`/git/branch/delete`,{name:e})}await M(`/git/branch/create`,{name:e,from:n})},W=async t=>{if(e)try{let n=await m.get(`${p(e)}/git/pr-url?branch=${encodeURIComponent(t)}`);n.url&&window.open(n.url,`_blank`)}catch{}},G=async t=>{if(g?.hash===t.hash){_(null);return}_(t),x(!0);try{let n=t.parents[0]??``,r=n?`ref1=${encodeURIComponent(n)}&`:``,i=await m.get(`${p(e)}/git/diff-stat?${r}ref2=${encodeURIComponent(t.hash)}`);y(Array.isArray(i)?i:[])}catch{y([])}finally{x(!1)}},K=t=>O({type:`git-diff`,title:`Diff ${t.abbreviatedHash}`,closable:!0,metadata:{projectName:e,ref1:t.parents[0]??void 0,ref2:t.hash},projectId:e??null}),q=(0,L.useMemo)(()=>ee(t),[t]),J=t?.branches.find(e=>e.current),Y=t?.head??``,X=(0,L.useMemo)(()=>{if(!t)return[];let e=t.commits;if(S!==`__all__`){let n=t.branches.find(e=>e.name===S);if(n){let r=new Set,i=[n.commitHash];for(;i.length>0;){let e=i.pop();if(r.has(e))continue;r.add(e);let n=t.commits.find(t=>t.hash===e);n&&i.push(...n.parents)}e=e.filter(e=>r.has(e.hash))}}if(w.trim()){let t=w.toLowerCase();e=e.filter(e=>e.subject.toLowerCase().includes(t)||e.authorName.toLowerCase().includes(t)||e.abbreviatedHash.includes(t)||e.hash.includes(t))}return e},[t,S,w]),Z=(0,L.useMemo)(()=>t?{...t,commits:X}:null,[t,X]),Q=(0,L.useMemo)(()=>te(Z),[Z]),$=X.length*24+48;return{data:t,loading:r,loadingMore:a,hasMore:s,error:l,acting:f,selectedCommit:g,setSelectedCommit:_,commitFiles:v,loadingDetail:b,branchFilter:S,setBranchFilter:C,searchQuery:w,setSearchQuery:T,showSearch:E,setShowSearch:D,fetchGraph:A,fetchFromRemotes:N,loadMore:j,handleCheckout:P,handleCherryPick:F,handleRevert:I,handleMerge:R,handleDeleteBranch:re,handlePushBranch:B,handleCreateBranch:U,handleCreateTag:V,handleCreatePr:W,copyHash:H,selectCommit:G,openDiffForCommit:K,commitLabels:q,currentBranch:J,headHash:Y,filteredCommits:X,filteredLanes:Q,svgHeight:$,svgPaths:(0,L.useMemo)(()=>ne(Z,Q.laneMap,Q.unloadedParentLanes,$),[Z,Q.laneMap,Q.unloadedParentLanes,$])}}function V(e){let[t,n]=(0,L.useState)(e),r=(0,L.useRef)(e);r.current=t;let i=(0,L.useRef)(!1);return{widths:t,startResize:(e,t)=>{i.current=!0;let a=r.current[e]??80,o=r=>{if(!i.current)return;let o=`touches`in r?r.touches[0].clientX:r.clientX,s=Math.max(40,a+o-t);n(t=>({...t,[e]:s}))},s=()=>{i.current=!1,window.removeEventListener(`mousemove`,o),window.removeEventListener(`mouseup`,s),window.removeEventListener(`touchmove`,o),window.removeEventListener(`touchend`,s)};window.addEventListener(`mousemove`,o),window.addEventListener(`mouseup`,s),window.addEventListener(`touchmove`,o,{passive:!1}),window.addEventListener(`touchend`,s)}}}var H=r();function U({branches:e,branchFilter:t,onBranchFilterChange:n,searchQuery:r,onSearchQueryChange:i,showSearch:s,onToggleSearch:l,onFetch:u,onRefresh:d,onOpenSettings:f,loading:p,acting:m,projectName:g}){let v=e.filter(e=>!e.remote),[y,b]=(0,L.useState)(!1),[x,C]=(0,L.useState)(``),w=(0,L.useRef)(null);(0,L.useEffect)(()=>{if(!y)return;let e=e=>{w.current&&!w.current.contains(e.target)&&(b(!1),C(``))};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[y]);let T=x?v.filter(e=>e.name.toLowerCase().includes(x.toLowerCase())):v,E=t===`__all__`?`Show All`:v.find(e=>e.name===t)?.name??`Show All`;return(0,H.jsx)(`div`,{className:`border-b bg-background`,children:(0,H.jsxs)(`div`,{className:`flex items-center gap-1.5 px-2 py-1.5`,children:[(0,H.jsxs)(`div`,{className:`flex items-center gap-1 text-xs text-muted-foreground shrink-0`,children:[(0,H.jsx)(`span`,{className:`font-semibold`,children:`Repo:`}),(0,H.jsx)(`span`,{className:`font-medium text-foreground truncate max-w-[120px]`,children:g??`—`})]}),(0,H.jsx)(`div`,{className:`w-px h-4 bg-border mx-1`}),(0,H.jsxs)(`div`,{className:`relative shrink-0`,ref:w,children:[(0,H.jsxs)(`button`,{type:`button`,className:`flex items-center gap-1 h-6 px-2 text-xs border rounded-md bg-transparent hover:bg-muted/50`,onClick:()=>{b(e=>!e),C(``)},children:[(0,H.jsx)(`span`,{className:`font-semibold text-muted-foreground`,children:`Branches:`}),(0,H.jsx)(`span`,{className:`max-w-[100px] truncate`,children:E}),(0,H.jsx)(a,{className:`size-3 opacity-50`})]}),y&&(0,H.jsxs)(`div`,{className:`absolute top-full left-0 mt-1 z-50 w-[220px] rounded-md border bg-popover shadow-md`,children:[(0,H.jsx)(`div`,{className:`p-1.5`,children:(0,H.jsx)(c,{className:`h-6 text-xs px-2`,placeholder:`Filter branches...`,value:x,onChange:e=>C(e.target.value),autoFocus:!0})}),(0,H.jsxs)(`div`,{className:`max-h-[200px] overflow-y-auto p-1`,children:[(0,H.jsx)(W,{label:`Show All`,selected:t===`__all__`,onClick:()=>{n(`__all__`),b(!1)}}),T.map(e=>(0,H.jsx)(W,{label:e.name,current:e.current,selected:t===e.name,onClick:()=>{n(e.name),b(!1)}},e.name)),T.length===0&&x&&(0,H.jsx)(`div`,{className:`px-2 py-1.5 text-xs text-muted-foreground`,children:`No branches found`})]})]})]}),(0,H.jsx)(`div`,{className:`flex-1`}),s&&(0,H.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,H.jsx)(c,{className:`h-6 text-xs w-[160px] px-2`,placeholder:`Search commits...`,value:r,onChange:e=>i(e.target.value),autoFocus:!0}),(0,H.jsx)(o,{variant:`ghost`,size:`icon-xs`,onClick:l,children:(0,H.jsx)(_,{className:`size-3`})})]}),!s&&(0,H.jsx)(o,{variant:`ghost`,size:`icon-xs`,onClick:l,title:`Find`,children:(0,H.jsx)(h,{className:`size-3.5`})}),(0,H.jsx)(o,{variant:`ghost`,size:`icon-xs`,onClick:f,title:`Settings`,children:(0,H.jsx)(P,{className:`size-3.5`})}),(0,H.jsx)(o,{variant:`ghost`,size:`icon-xs`,onClick:u,disabled:m,title:`Fetch`,children:(0,H.jsx)(O,{className:`size-3.5`})}),(0,H.jsx)(o,{variant:`ghost`,size:`icon-xs`,onClick:d,disabled:m,title:`Refresh`,children:(0,H.jsx)(S,{className:`size-3.5 ${p?`animate-spin`:``}`})})]})})}function W({label:e,selected:t,current:n,onClick:r}){return(0,H.jsxs)(`button`,{type:`button`,className:`flex items-center gap-2 w-full px-2 py-1 text-xs rounded-sm hover:bg-accent hover:text-accent-foreground text-left`,onClick:r,children:[(0,H.jsx)(i,{className:`size-3 shrink-0 ${t?`opacity-100`:`opacity-0`}`}),(0,H.jsx)(`span`,{className:`truncate flex-1`,children:e}),n&&(0,H.jsx)(`span`,{className:`text-[10px] text-muted-foreground italic`,children:`current`})]})}function G({commits:e,laneMap:t,svgPaths:n,width:r,height:i,headHash:a}){return(0,H.jsxs)(`svg`,{width:r,height:i,children:[n.map((e,t)=>(0,H.jsx)(`path`,{d:e.d,stroke:e.color,strokeWidth:2,fill:`none`},t)),e.map((e,n)=>{let r=t.get(e.hash)??0,i=r*16+16/2,o=n*24+24/2,s=R[r%R.length],c=e.hash===a;return(0,H.jsx)(`circle`,{cx:i,cy:o,r:c?5:4,fill:s,stroke:c?`#000`:`none`,strokeWidth:c?2:0},e.hash)})]})}function K({name:e,type:t,remotes:n,isCurrent:r,color:i,currentBranch:a,onCheckout:o,onMerge:s,onPush:c,onCreatePr:u,onDelete:f}){return t===`tag`?(0,H.jsxs)(`span`,{className:`inline-flex items-center gap-0.5 px-1.5 py-0.5 rounded text-[10px] font-medium shrink-0 bg-amber-500/20 text-amber-500 border border-amber-500/30`,children:[(0,H.jsx)(d,{className:`size-2.5`}),e]}):(0,H.jsxs)(M,{children:[(0,H.jsx)(x,{asChild:!0,children:(0,H.jsxs)(`span`,{className:`inline-flex items-center rounded text-[10px] font-medium shrink-0 cursor-context-menu overflow-hidden`,style:{border:r?`1.5px solid ${i}`:`1px solid ${i}50`},children:[(0,H.jsxs)(`span`,{className:`inline-flex items-center gap-0.5 px-1.5 py-0.5`,style:{backgroundColor:r?i:`${i}30`,color:r?`#fff`:i},children:[(0,H.jsx)(C,{className:`size-2.5`}),e]}),n.map(e=>(0,H.jsx)(`span`,{className:`px-1.5 py-0.5 italic opacity-70`,style:{borderLeft:`1px solid ${i}40`,color:i,backgroundColor:`${i}15`},children:e},e))]})}),(0,H.jsxs)(b,{children:[(0,H.jsx)(g,{onClick:()=>o(e),children:`Checkout`}),(0,H.jsxs)(g,{onClick:()=>s(e),disabled:e===a?.name,children:[(0,H.jsx)(I,{className:`size-3`}),`Merge into current`]}),(0,H.jsx)(j,{}),(0,H.jsxs)(g,{onClick:()=>c(e),children:[(0,H.jsx)(D,{className:`size-3`}),`Push`]}),(0,H.jsxs)(g,{onClick:()=>u(e),children:[(0,H.jsx)(l,{className:`size-3`}),`Create PR`]}),(0,H.jsx)(j,{}),(0,H.jsxs)(g,{variant:`destructive`,onClick:()=>f(e),disabled:e===a?.name,children:[(0,H.jsx)(y,{className:`size-3`}),`Delete`]})]})]})}function q({commit:e,lane:t,isSelected:n,isHead:r,labels:i,currentBranch:a,onSelect:o,onCheckout:c,onCherryPick:l,onRevert:u,onMerge:f,onDeleteBranch:p,onPushBranch:m,onCreatePr:h,onOpenCreateBranch:_,onOpenCreateTag:v,onOpenDiff:y,onCopyHash:S}){let w=R[t%R.length],T=i.filter(e=>e.type===`branch`),E=i.filter(e=>e.type===`tag`);return(0,H.jsxs)(M,{children:[(0,H.jsx)(x,{asChild:!0,children:(0,H.jsxs)(`tr`,{className:`hover:bg-muted/50 cursor-pointer border-b border-border/20 ${n?`bg-primary/10`:``} ${r?`font-medium`:``}`,style:{height:`24px`},onClick:o,children:[(0,H.jsx)(`td`,{className:`px-2 truncate max-w-0`,children:(0,H.jsxs)(`div`,{className:`flex items-center gap-1.5 min-w-0`,children:[T.map(e=>(0,H.jsx)(K,{name:e.name,type:`branch`,remotes:e.remotes,isCurrent:e.current,color:w,currentBranch:a,onCheckout:c,onMerge:f,onPush:m,onCreatePr:h,onDelete:p},`branch-${e.name}`)),E.map(e=>(0,H.jsx)(K,{name:e.name,type:`tag`,remotes:[],isCurrent:!1,color:w,currentBranch:a,onCheckout:c,onMerge:f,onPush:m,onCreatePr:h,onDelete:p},`tag-${e.name}`)),(0,H.jsx)(`span`,{className:`truncate text-xs`,children:e.subject})]})}),(0,H.jsx)(`td`,{className:`px-2 text-xs text-muted-foreground whitespace-nowrap shrink-0`,children:re(e.authorDate)}),(0,H.jsx)(`td`,{className:`px-2 text-xs text-muted-foreground truncate max-w-[120px]`,children:e.authorName}),(0,H.jsx)(`td`,{className:`px-2 text-xs text-muted-foreground font-mono whitespace-nowrap`,children:e.abbreviatedHash})]})}),(0,H.jsxs)(b,{children:[(0,H.jsx)(g,{onClick:()=>c(e.hash),children:`Checkout`}),(0,H.jsxs)(g,{onClick:()=>_(e.hash),children:[(0,H.jsx)(C,{className:`size-3`}),`Create Branch...`]}),(0,H.jsx)(j,{}),(0,H.jsxs)(g,{onClick:()=>l(e.hash),children:[(0,H.jsx)(F,{className:`size-3`}),`Cherry Pick`]}),(0,H.jsxs)(g,{onClick:()=>u(e.hash),children:[(0,H.jsx)(s,{className:`size-3`}),`Revert`]}),(0,H.jsxs)(g,{onClick:()=>v(e.hash),children:[(0,H.jsx)(d,{className:`size-3`}),`Create Tag...`]}),(0,H.jsx)(j,{}),(0,H.jsx)(g,{onClick:y,children:`View Diff`}),(0,H.jsxs)(g,{onClick:S,children:[(0,H.jsx)(k,{className:`size-3`}),`Copy Hash`]})]})]})}function J({commit:e,files:t,loadingDetail:n,projectName:r,onClose:i,copyHash:a}){let{openTab:s}=u();return(0,H.jsxs)(`div`,{className:`border-t bg-muted/30 max-h-[40%] overflow-auto`,children:[(0,H.jsxs)(`div`,{className:`px-3 py-2 border-b flex items-center justify-between`,children:[(0,H.jsxs)(`span`,{className:`text-sm font-medium truncate`,children:[e.abbreviatedHash,` — `,e.subject]}),(0,H.jsx)(o,{variant:`ghost`,size:`icon-xs`,onClick:i,children:`✕`})]}),(0,H.jsxs)(`div`,{className:`px-3 py-2 text-xs space-y-1`,children:[(0,H.jsxs)(`div`,{className:`flex gap-4`,children:[(0,H.jsx)(`span`,{className:`text-muted-foreground w-12 shrink-0`,children:`Author`}),(0,H.jsxs)(`span`,{children:[e.authorName,` <`,e.authorEmail,`>`]})]}),(0,H.jsxs)(`div`,{className:`flex gap-4`,children:[(0,H.jsx)(`span`,{className:`text-muted-foreground w-12 shrink-0`,children:`Date`}),(0,H.jsx)(`span`,{children:new Date(e.authorDate).toLocaleString()})]}),(0,H.jsxs)(`div`,{className:`flex gap-4`,children:[(0,H.jsx)(`span`,{className:`text-muted-foreground w-12 shrink-0`,children:`Hash`}),(0,H.jsx)(`span`,{className:`font-mono cursor-pointer hover:text-primary`,onClick:()=>a(e.hash),children:e.hash})]}),e.parents.length>0&&(0,H.jsxs)(`div`,{className:`flex gap-4`,children:[(0,H.jsx)(`span`,{className:`text-muted-foreground w-12 shrink-0`,children:`Parents`}),(0,H.jsx)(`span`,{className:`font-mono`,children:e.parents.map(e=>e.slice(0,7)).join(`, `)})]}),e.body&&(0,H.jsx)(`div`,{className:`mt-2 p-2 bg-background rounded text-xs whitespace-pre-wrap`,children:e.body})]}),(0,H.jsxs)(`div`,{className:`px-3 py-1 border-t`,children:[(0,H.jsx)(`div`,{className:`text-xs text-muted-foreground py-1`,children:n?`Loading files...`:`${t.length} file${t.length===1?``:`s`} changed`}),t.map(t=>(0,H.jsxs)(`div`,{className:`flex items-center gap-2 py-0.5 text-xs hover:bg-muted/50 rounded px-1 cursor-pointer`,onClick:()=>s({type:`git-diff`,title:`Diff ${f(t.path)}`,closable:!0,metadata:{projectName:r,ref1:e.parents[0]??void 0,ref2:e.hash,filePath:t.path},projectId:r}),children:[(0,H.jsx)(`span`,{className:`flex-1 truncate font-mono`,children:t.path}),t.additions>0&&(0,H.jsxs)(`span`,{className:`text-green-500`,children:[`+`,t.additions]}),t.deletions>0&&(0,H.jsxs)(`span`,{className:`text-red-500`,children:[`-`,t.deletions]})]},t.path))]})]})}function Y({type:e,hash:t,onClose:n,onCreateBranch:r,onCreateTag:i}){let[a,s]=(0,L.useState)(``),l=()=>{a.trim()&&(e===`branch`?r(a.trim(),t):i(a.trim(),t),n())};return(0,H.jsx)(E,{open:e!==null,onOpenChange:e=>{e||n()},children:(0,H.jsxs)(T,{children:[(0,H.jsx)(N,{children:(0,H.jsx)(w,{children:e===`branch`?`Create Branch`:`Create Tag`})}),(0,H.jsx)(c,{placeholder:e===`branch`?`Branch name`:`Tag name`,value:a,onChange:e=>s(e.target.value),onKeyDown:e=>{e.key===`Enter`&&l()},autoFocus:!0}),(0,H.jsxs)(A,{children:[(0,H.jsx)(o,{variant:`outline`,onClick:n,children:`Cancel`}),(0,H.jsx)(o,{disabled:!a.trim(),onClick:l,children:`Create`})]})]})})}function X({open:e,onClose:t,projectName:n,branches:r}){let i=r.filter(e=>!e.remote),a=r.filter(e=>e.remote),o=new Map;for(let e of a){let t=e.name.replace(/^remotes\//,``),n=t.indexOf(`/`);if(n<0)continue;let r=t.slice(0,n),i=t.slice(n+1),a=o.get(r)??[];a.push(i),o.set(r,a)}return(0,H.jsx)(E,{open:e,onOpenChange:e=>{e||t()},children:(0,H.jsxs)(T,{className:`max-w-md`,children:[(0,H.jsx)(N,{children:(0,H.jsx)(w,{children:`Repository Settings`})}),(0,H.jsxs)(`div`,{className:`space-y-4 text-sm`,children:[(0,H.jsxs)(Z,{title:`General`,children:[(0,H.jsx)(Q,{label:`Name`,value:n}),(0,H.jsx)(Q,{label:`Branches`,value:`${i.length} local, ${a.length} remote`})]}),(0,H.jsx)(Z,{title:`Local Branches`,children:i.map(e=>(0,H.jsxs)(`div`,{className:`flex items-center gap-2 py-0.5`,children:[(0,H.jsx)(`span`,{className:`text-xs ${e.current?`font-semibold text-primary`:`text-foreground`}`,children:e.name}),e.current&&(0,H.jsx)(`span`,{className:`text-[10px] text-muted-foreground italic`,children:`HEAD`}),e.remotes.length>0&&(0,H.jsxs)(`span`,{className:`text-[10px] text-muted-foreground`,children:[`(`,e.remotes.join(`, `),`)`]})]},e.name))}),(0,H.jsxs)(Z,{title:`Remotes`,children:[[...o.entries()].map(([e,t])=>(0,H.jsxs)(`div`,{className:`py-0.5`,children:[(0,H.jsx)(`span`,{className:`text-xs font-medium`,children:e}),(0,H.jsxs)(`span`,{className:`text-[10px] text-muted-foreground ml-2`,children:[t.length,` branch`,t.length===1?``:`es`]})]},e)),o.size===0&&(0,H.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`No remotes configured`})]})]})]})})}function Z({title:e,children:t}){return(0,H.jsxs)(`div`,{children:[(0,H.jsx)(`h4`,{className:`text-xs font-semibold text-muted-foreground uppercase tracking-wider mb-1.5`,children:e}),(0,H.jsx)(`div`,{className:`pl-1`,children:t})]})}function Q({label:e,value:t}){return(0,H.jsxs)(`div`,{className:`flex items-center gap-3 py-0.5`,children:[(0,H.jsx)(`span`,{className:`text-xs text-muted-foreground w-16 shrink-0`,children:e}),(0,H.jsx)(`span`,{className:`text-xs`,children:t})]})}function $({metadata:e}){let t=e?.projectName,n=B(t),[r,i]=(0,L.useState)({type:null}),[a,o]=(0,L.useState)(!1),s=(typeof window<`u`&&window.innerWidth<768?6:10)*16+16,[c,l]=(0,L.useState)(s),u=(0,L.useRef)(s);u.current=c;let d=(0,L.useRef)(!1),f=e=>{d.current=!0;let t=u.current,n=n=>{if(!d.current)return;let r=`touches`in n?n.touches[0].clientX:n.clientX;l(Math.max(40,t+r-e))},r=()=>{d.current=!1,window.removeEventListener(`mousemove`,n),window.removeEventListener(`mouseup`,r),window.removeEventListener(`touchmove`,n),window.removeEventListener(`touchend`,r)};window.addEventListener(`mousemove`,n),window.addEventListener(`mouseup`,r),window.addEventListener(`touchmove`,n,{passive:!1}),window.addEventListener(`touchend`,r)},{widths:p,startResize:m}=V({date:80,author:120,commit:70}),h=(0,L.useRef)(n.loadMore);h.current=n.loadMore;let g=(0,L.useCallback)(e=>{let t=e.currentTarget;t.scrollHeight-t.scrollTop-t.clientHeight<200&&h.current()},[]);return t?n.loading&&!n.data?(0,H.jsx)(oe,{}):n.error&&!n.data?(0,H.jsx)(se,{error:n.error,onRetry:n.fetchGraph}):(0,H.jsxs)(`div`,{className:`flex flex-col h-full`,children:[(0,H.jsx)(U,{branches:n.data?.branches??[],branchFilter:n.branchFilter,onBranchFilterChange:n.setBranchFilter,searchQuery:n.searchQuery,onSearchQueryChange:n.setSearchQuery,showSearch:n.showSearch,onToggleSearch:()=>n.setShowSearch(!n.showSearch),onFetch:n.fetchFromRemotes,onRefresh:n.fetchGraph,onOpenSettings:()=>o(!0),loading:n.loading,acting:n.acting,projectName:t}),n.error&&(0,H.jsx)(`div`,{className:`px-3 py-1.5 text-xs text-destructive bg-destructive/10`,children:n.error}),(0,H.jsx)(`div`,{className:`flex-1 overflow-auto`,onScroll:g,children:(0,H.jsxs)(`div`,{className:`flex min-w-max md:min-w-0`,children:[(0,H.jsxs)(`div`,{className:`sticky left-0 z-10 shrink-0 bg-background relative overflow-hidden`,style:{width:`${c}px`},children:[(0,H.jsx)(`div`,{className:`text-[11px] font-semibold text-muted-foreground px-2 border-b bg-background sticky top-0 z-20`,style:{height:`24px`,lineHeight:`24px`},children:`Graph`}),(0,H.jsx)(G,{commits:n.filteredCommits,laneMap:n.filteredLanes.laneMap,svgPaths:n.svgPaths,width:(n.filteredLanes.maxLane+2)*16,height:n.svgHeight,headHash:n.headHash}),(0,H.jsx)(`div`,{className:`absolute top-0 right-0 w-1.5 h-full cursor-col-resize hover:bg-primary/30`,onMouseDown:e=>{e.preventDefault(),f(e.clientX)},onTouchStart:e=>f(e.touches[0].clientX)})]}),(0,H.jsxs)(`div`,{className:`flex-1 min-w-[400px]`,children:[(0,H.jsxs)(`table`,{className:`w-full border-collapse text-xs`,style:{tableLayout:`fixed`},children:[(0,H.jsxs)(`colgroup`,{children:[(0,H.jsx)(`col`,{}),(0,H.jsx)(`col`,{style:{width:`${p.date}px`}}),(0,H.jsx)(`col`,{style:{width:`${p.author}px`}}),(0,H.jsx)(`col`,{style:{width:`${p.commit}px`}})]}),(0,H.jsx)(`thead`,{className:`sticky top-0 z-10 bg-background`,children:(0,H.jsxs)(`tr`,{className:`border-b text-[11px] font-semibold text-muted-foreground`,style:{height:`24px`},children:[(0,H.jsx)(`th`,{className:`text-left px-2 font-semibold`,children:`Description`}),(0,H.jsx)(ie,{label:`Date`,colKey:`date`,onStartResize:m}),(0,H.jsx)(ie,{label:`Author`,colKey:`author`,onStartResize:m}),(0,H.jsx)(`th`,{className:`text-left px-2 font-semibold`,children:`Commit`})]})}),(0,H.jsx)(`tbody`,{children:n.filteredCommits.map(e=>(0,H.jsx)(q,{commit:e,lane:n.filteredLanes.laneMap.get(e.hash)??0,isSelected:n.selectedCommit?.hash===e.hash,isHead:e.hash===n.headHash,labels:n.commitLabels.get(e.hash)??[],currentBranch:n.currentBranch,onSelect:()=>n.selectCommit(e),onCheckout:n.handleCheckout,onCherryPick:n.handleCherryPick,onRevert:n.handleRevert,onMerge:n.handleMerge,onDeleteBranch:n.handleDeleteBranch,onPushBranch:n.handlePushBranch,onCreatePr:n.handleCreatePr,onOpenCreateBranch:e=>i({type:`branch`,hash:e}),onOpenCreateTag:e=>i({type:`tag`,hash:e}),onOpenDiff:()=>n.openDiffForCommit(e),onCopyHash:()=>n.copyHash(e.hash)},e.hash))})]}),n.loadingMore&&(0,H.jsxs)(`div`,{className:`flex items-center justify-center gap-2 py-3 text-xs text-muted-foreground`,children:[(0,H.jsx)(v,{className:`size-3.5 animate-spin`}),` Loading more commits...`]}),!n.hasMore&&n.data&&n.data.commits.length>0&&(0,H.jsxs)(`div`,{className:`text-center py-2 text-xs text-muted-foreground`,children:[n.data.commits.length,` commits loaded`]})]})]})}),n.selectedCommit&&t&&(0,H.jsx)(J,{commit:n.selectedCommit,files:n.commitFiles,loadingDetail:n.loadingDetail,projectName:t,onClose:()=>n.setSelectedCommit(null),copyHash:n.copyHash}),(0,H.jsx)(Y,{type:r.type,hash:r.hash,onClose:()=>i({type:null}),onCreateBranch:n.handleCreateBranch,onCreateTag:n.handleCreateTag}),(0,H.jsx)(X,{open:a,onClose:()=>o(!1),projectName:t,branches:n.data?.branches??[]})]}):(0,H.jsx)(ae,{msg:`No project selected.`})}function ie({label:e,colKey:t,onStartResize:n}){return(0,H.jsxs)(`th`,{className:`text-left px-2 font-semibold relative`,children:[e,(0,H.jsx)(`div`,{className:`absolute top-0 right-0 w-1.5 h-full cursor-col-resize hover:bg-primary/30`,onMouseDown:e=>{e.preventDefault(),n(t,e.clientX)},onTouchStart:e=>n(t,e.touches[0].clientX)})]})}function ae({msg:e}){return(0,H.jsx)(`div`,{className:`flex items-center justify-center h-full text-muted-foreground text-sm`,children:e})}function oe(){return(0,H.jsxs)(`div`,{className:`flex items-center justify-center h-full gap-2 text-muted-foreground`,children:[(0,H.jsx)(v,{className:`size-5 animate-spin`}),(0,H.jsx)(`span`,{className:`text-sm`,children:`Loading git graph...`})]})}function se({error:e,onRetry:t}){return(0,H.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full gap-2 text-destructive text-sm`,children:[(0,H.jsx)(`p`,{children:e}),(0,H.jsx)(o,{variant:`outline`,size:`sm`,onClick:t,children:`Retry`})]})}export{$ as GitGraph};