@hienlh/ppm 0.9.91 → 0.9.92

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 (27) hide show
  1. package/CHANGELOG.md +2 -1
  2. package/dist/web/assets/{chat-tab-BPoQy-Fp.js → chat-tab-B3sYWC6s.js} +1 -1
  3. package/dist/web/assets/{code-editor-DDW9dlUL.js → code-editor-GQ-BPapW.js} +1 -1
  4. package/dist/web/assets/{conflict-editor-Bt24HTjk.js → conflict-editor-BzEbBMdo.js} +1 -1
  5. package/dist/web/assets/{database-viewer-DbD8rfQF.js → database-viewer-hoe7AAOc.js} +1 -1
  6. package/dist/web/assets/{diff-viewer-DVWJoL2y.js → diff-viewer-tjZrVKtL.js} +1 -1
  7. package/dist/web/assets/{extension-webview-nq9rDNgj.js → extension-webview-BeqBWL7v.js} +2 -2
  8. package/dist/web/assets/{index-DK4yJlIj.js → index-fzSsl_Dg.js} +3 -3
  9. package/dist/web/assets/keybindings-store-DpSn1fWY.js +1 -0
  10. package/dist/web/assets/{markdown-renderer-CCq6xBWp.js → markdown-renderer-Pch6Q5AB.js} +1 -1
  11. package/dist/web/assets/{port-forwarding-tab-BBwfD-s_.js → port-forwarding-tab-2emRdRba.js} +1 -1
  12. package/dist/web/assets/{postgres-viewer-Dqnhi-ci.js → postgres-viewer-3yrH60xU.js} +1 -1
  13. package/dist/web/assets/{settings-tab-DX9zkGvD.js → settings-tab-DdyI-_Vr.js} +1 -1
  14. package/dist/web/assets/{sql-query-editor-CxODOF9o.js → sql-query-editor-DkBHKM2i.js} +1 -1
  15. package/dist/web/assets/{sqlite-viewer-DAgT72tD.js → sqlite-viewer-DnCkYz-y.js} +1 -1
  16. package/dist/web/assets/{terminal-tab-5ib6rUAO.js → terminal-tab-C5lCh18X.js} +1 -1
  17. package/dist/web/assets/{use-monaco-theme-vmoBT6np.js → use-monaco-theme-BEX-OBkP.js} +1 -1
  18. package/dist/web/index.html +1 -1
  19. package/dist/web/sw.js +1 -1
  20. package/package.json +1 -1
  21. package/packages/vscode-compat/src/window.ts +14 -0
  22. package/src/server/ws/extensions.ts +12 -0
  23. package/src/services/extension-host-worker.ts +12 -0
  24. package/src/types/extension-messages.ts +1 -0
  25. package/src/web/components/extensions/extension-webview.tsx +15 -0
  26. package/src/web/hooks/use-extension-ws.ts +8 -0
  27. package/dist/web/assets/keybindings-store-CpFk-yNF.js +0 -1
package/CHANGELOG.md CHANGED
@@ -1,8 +1,9 @@
1
1
  # Changelog
2
2
 
3
- ## [0.9.91] - 2026-04-15
3
+ ## [0.9.92] - 2026-04-15
4
4
 
5
5
  ### Fixed
6
+ - **Webview panel lifecycle**: Closing a git-graph tab now properly disposes the panel on the extension side. Previously, the extension kept a stale `activePanel` reference and refused to create a new panel on reopen.
6
7
  - **Git Graph broken after stash visualization**: Stash virtual commits were inserted after parent in array but graph algorithm scans forward — graph silently broke when stashes existed. Fixed insertion order (stash before parent, same pattern as uncommitted).
7
8
 
8
9
  ## [0.9.90] - 2026-04-15
@@ -1,5 +1,5 @@
1
1
  const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/api-client-BvxmRZUi.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-I9-21gkR.js";import{a,c as o,f as s,g as c,h as l,i as u,l as d,m as f,n as p,o as m,p as h,r as g,s as _,t as v,u as y}from"./ai-settings-section-Bo9lCaTd.js";import{i as b,n as x,r as S}from"./dist-CM0oD8tQ.js";import{n as C,r as w,t as T}from"./plus-DQGIb4mQ.js";import{t as E}from"./chevron-right-DY_wImxB.js";import{R as D,a as O,i as k,l as A,n as j,o as M,r as N,s as P,t as F}from"./input-BHj0veau.js";import{n as I,t as L}from"./markdown-renderer-CCq6xBWp.js";import{t as R}from"./columns-2-IeETSfON.js";import{n as z,r as B,t as V}from"./x-Dw3TjeY_.js";import{t as H}from"./refresh-cw-Clk8fdUD.js";import{t as ee}from"./square-vBdqj0bF.js";import{t as U}from"./trash-2-CNuB-htI.js";import{t as te}from"./preload-helper-mr3rCizq.js";import{n as W,r as ne,t as G}from"./utils-DX8jb5qv.js";import{i as K,r as q,t as J}from"./api-client-BvxmRZUi.js";import{a as Y,c as re,f as X,g as ie,i as ae,l as oe,m as se,o as ce,p as le,r as ue,s as de,t as fe,u as pe}from"./api-settings-CUxg9RE5.js";import{A as me,B as Z,D as he,E as ge,F as _e,G as ve,H as ye,I as be,J as xe,M as Se,N as Ce,O as we,Q as Te,R as Ee,U as De,Y as Oe,Z as ke,et as Ae,g as je,i as Me,j as Ne,k as Pe,r as Fe,t as Ie,z as Le}from"./index-DK4yJlIj.js";import"./chunk-GEFDOKGD-86LFbsAC.js";import"./src-CqyWLlNZ.js";import"./chunk-7R4GIKGN-y8bfHEy-.js";import"./chunk-HHEYEP7N-C45i5G_3.js";import"./dist-DZmJeHOA.js";import"./chunk-PU5JKC2W-DD95Rx35.js";import"./chunk-MX3YWQON-B6g1ZH9X.js";import"./chunk-YBOYWFTD-D_ILLe6_.js";import"./chunk-PQ6SQG4A-Bik13fTV.js";import"./chunk-KYZI473N-gqRLpJ4w.js";import"./chunk-O4XLMI2P-Vp_V4P-b.js";import"./chunk-GLR3WWYH-Re-5eSlQ.js";import"./chunk-XPW4576I-CgLyyW03.js";var Re=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`}]]),ze=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`}]]),Be=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`}]]),Ve=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`}]]),He=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`}]]),Ue=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`}]]),We=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`}]]),Ge=n(`list-ordered`,[[`path`,{d:`M11 5h10`,key:`1cz7ny`}],[`path`,{d:`M11 12h10`,key:`1438ji`}],[`path`,{d:`M11 19h10`,key:`11t30w`}],[`path`,{d:`M4 4h1v5`,key:`10yrso`}],[`path`,{d:`M4 9h2`,key:`r1h2o0`}],[`path`,{d:`M6.5 20H3.4c0-1 2.6-1.925 2.6-3.5a1.5 1.5 0 0 0-2.6-1.02`,key:`xtkcd5`}]]),Ke=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`}]]),qe=n(`maximize-2`,[[`path`,{d:`M15 3h6v6`,key:`1q9fwt`}],[`path`,{d:`m21 3-7 7`,key:`1l2asr`}],[`path`,{d:`m3 21 7-7`,key:`tjx5ai`}],[`path`,{d:`M9 21H3v-6`,key:`wtvkvv`}]]),Je=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`}]]),Ye=n(`minimize-2`,[[`path`,{d:`m14 10 7-7`,key:`oa77jy`}],[`path`,{d:`M20 10h-6V4`,key:`mjg0md`}],[`path`,{d:`m3 21 7-7`,key:`tjx5ai`}],[`path`,{d:`M4 14h6v6`,key:`rmj7iw`}]]),Xe=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`}]]),Ze=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`}]]),Qe=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`}]]),$e=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`}]]),et=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`}]]),tt=n(`tag`,[[`path`,{d:`M12.586 2.586A2 2 0 0 0 11.172 2H4a2 2 0 0 0-2 2v7.172a2 2 0 0 0 .586 1.414l8.704 8.704a2.426 2.426 0 0 0 3.42 0l6.58-6.58a2.426 2.426 0 0 0 0-3.42z`,key:`vktsd0`}],[`circle`,{cx:`7.5`,cy:`7.5`,r:`.5`,fill:`currentColor`,key:`kqv944`}]]),nt=n(`users`,[[`path`,{d:`M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2`,key:`1yyitq`}],[`path`,{d:`M16 3.128a4 4 0 0 1 0 7.744`,key:`16gr8j`}],[`path`,{d:`M22 21v-2a4 4 0 0 0-3-3.87`,key:`kshegd`}],[`circle`,{cx:`9`,cy:`7`,r:`4`,key:`nufk8`}]]),rt=n(`zap`,[[`path`,{d:`M4 14a1 1 0 0 1-.78-1.63l9.9-10.2a.5.5 0 0 1 .86.46l-1.92 6.02A1 1 0 0 0 13 10h7a1 1 0 0 1 .78 1.63l-9.9 10.2a.5.5 0 0 1-.86-.46l1.92-6.02A1 1 0 0 0 11 14z`,key:`1xq2db`}]]),Q=e(t(),1);function it({url:e,onMessage:t,autoConnect:n=!0}){let r=(0,Q.useRef)(null);return(0,Q.useEffect)(()=>{let i=new Ie(e);return r.current=i,t&&i.onMessage(t),n&&i.connect(),()=>{i.disconnect(),r.current=null}},[e,n]),{send:(0,Q.useCallback)(e=>{r.current?.send(e)},[]),connect:(0,Q.useCallback)(()=>{r.current?.connect()},[]),disconnect:(0,Q.useCallback)(()=>{r.current?.disconnect()},[])}}var at=null;function ot(){return at||=new AudioContext,at}function st(e,t,n,r,i=`sine`){let a=ot(),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 ct(){let e=ot().currentTime;st(523,.15,e,.15),st(659,.2,e+.12,.15)}function lt(){let e=ot().currentTime;st(880,.12,e,.18,`square`),st(698,.12,e+.15,.18,`square`),st(880,.15,e+.3,.15,`square`)}function ut(){let e=ot().currentTime;st(440,.12,e,.12),st(523,.12,e+.1,.12),st(659,.18,e+.2,.12)}var dt={done:ct,approval_request:lt,question:ut};function ft(e){try{dt[e]?.()}catch{}}var pt={hasTeams:!1,teamNames:[],messageCount:0,unreadCount:0};function mt(e){if(document.hidden)return!1;let{panels:t,focusedPanelId:n}=we.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 ht(e,t=`claude`,n=``){let[r,i]=(0,Q.useState)([]),[a,o]=(0,Q.useState)(!1),[s,c]=(0,Q.useState)(`idle`),[l,u]=(0,Q.useState)(!1),[d,f]=(0,Q.useState)(0),[p,m]=(0,Q.useState)(null),[h,g]=(0,Q.useState)(null),[_,v]=(0,Q.useState)(null),[y,b]=(0,Q.useState)(null),[S,C]=(0,Q.useState)(null),[w,T]=(0,Q.useState)(!1),E=(0,Q.useRef)(``),D=(0,Q.useRef)([]),O=(0,Q.useRef)(null),k=(0,Q.useRef)(`idle`),A=(0,Q.useRef)(null),j=(0,Q.useRef)(()=>{}),M=(0,Q.useRef)(null),N=(0,Q.useRef)(e);N.current=e;let P=(0,Q.useRef)(n);P.current=n;let F=(0,Q.useRef)(null),I=(0,Q.useRef)({teamNames:new Set,messages:[]}),L=(0,Q.useRef)(0),[R,z]=(0,Q.useState)(pt),[B,V]=(0,Q.useState)([]),H=(0,Q.useCallback)(()=>{let e=I.current;z({hasTeams:e.teamNames.size>0,teamNames:Array.from(e.teamNames),messageCount:e.messages.length,unreadCount:L.current}),V([...e.messages])},[]),ee=(0,Q.useCallback)(()=>{L.current=0,H()},[H]),U=s!==`idle`,te=(0,Q.useCallback)((e,t)=>{let n=D.current.findIndex(e=>e.type===`tool_use`&&(e.tool===`Agent`||e.tool===`Task`)&&e.toolUseId===t);if(n===-1)return!1;let r=D.current[n];if(r.type!==`tool_use`)return!1;let i=[...r.children??[],e];return D.current[n]={...r,children:i},!0},[]),W=(0,Q.useCallback)(()=>{let e=E.current,t=[...D.current],n=O.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}]})},[]),ne=(0,Q.useCallback)(e=>{let t=e,n=t?.type;if(n)switch(n){case`account_info`:O.current={accountId:t.accountId,accountLabel:t.accountLabel},b(null);break;case`account_retry`:t.accountId&&t.accountLabel&&(O.current={accountId:t.accountId,accountLabel:t.accountLabel}),D.current.push(t),W();break;case`status_update`:{let e=t.accountLabel?` (${t.accountLabel})`:``;b(`${t.message}${e}`);break}case`text`:{let e=t.parentToolUseId;if(e&&te(t,e)){W();break}E.current+=t.content,D.current.push(t),W();break}case`thinking`:{let e=t.parentToolUseId;if(e&&te(t,e)){W();break}D.current.push(t),W();break}case`tool_use`:{let e=t.parentToolUseId;if(e&&te(t,e)){W();break}D.current.push(t),W();break}case`tool_result`:{let e=t.parentToolUseId;if(e&&te(t,e)){W();break}D.current.push(t),W();break}case`approval_request`:if(D.current.push(t),m({requestId:t.requestId,tool:t.tool,input:t.input}),N.current&&!mt(N.current)){let e=t.tool===`AskUserQuestion`?`question`:`approval_request`;je.getState().addNotification(N.current,e,P.current),ft(e);let n=N.current,r=t.tool===`AskUserQuestion`;F.current=x[r?`info`:`warning`](r?`AI has a question`:`${t.tool} needs permission`,{description:P.current||`Session ${n.slice(0,8)}`,duration:1/0,action:{label:`Go to session`,onClick:()=>{let{panels:e}=we.getState();for(let[t,r]of Object.entries(e)){let e=r.tabs.find(e=>e.metadata?.sessionId===n);if(e){we.getState().setActiveTab(e.id,t);break}}}}})}break;case`error`:{D.current.push(t);let e=[...D.current];i(n=>{let r=n[n.length-1];return r?.role===`assistant`?[...n.slice(0,-1),{...r,events:e}]:[...n,{id:`error-${Date.now()}`,role:`system`,content:t.message,events:[t],timestamp:new Date().toISOString()}]});break}case`team_detected`:{let e=t.teamName;e&&(I.current.teamNames.add(e),J.get(`/api/teams/${encodeURIComponent(e)}`).then(e=>{if(e?.messages){let t=I.current.messages,n=e.messages.filter(e=>!t.some(t=>t.timestamp===e.timestamp&&t.from===e.from));t.push(...n),t.sort((e,t)=>new Date(e.timestamp).getTime()-new Date(t.timestamp).getTime())}H()}).catch(()=>{}),H());break}case`team_inbox`:{let e=t.messages;Array.isArray(e)&&(I.current.messages.push(...e),L.current+=e.length,H());break}case`team_updated`:H();break;case`done`:{if(k.current===`idle`)break;t.contextWindowPct!=null&&g(t.contextWindowPct),N.current&&!mt(N.current)&&(je.getState().addNotification(N.current,`done`,P.current),ft(`done`));let e=E.current,n=[...D.current],r=t.lastMessageUuid;i(t=>{let i=t[t.length-1];return i?.role===`assistant`?[...t.slice(0,-1),{...i,id:`final-${Date.now()}`,content:e||i.content,events:n.length>0?n:i.events,...r&&{sdkUuid:r}}]:t}),E.current=``,D.current=[],O.current=null,b(null);break}}},[te,W]),G=(0,Q.useCallback)(e=>{let t;try{t=JSON.parse(e.data)}catch{return}if(t.type!==`ping`){if(t.type===`title_updated`){C(t.title??null);return}if(t.type===`compact_status`){let e=t.status;e===`compacting`?v(`compacting`):e===`done`&&(v(null),M.current?.());return}if(t.type===`phase_changed`){let e=t.phase;c(e),k.current=e,f(e===`connecting`?t.elapsed??0:0);return}if(t.type===`session_state`){T(!0);let e=t,n=e.phase;c(n),k.current=n,e.sessionTitle&&C(e.sessionTitle),e.pendingApproval&&m({requestId:e.pendingApproval.requestId,tool:e.pendingApproval.tool,input:e.pendingApproval.input}),n===`idle`&&(M.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}),E.current=``,D.current=[],O.current=null;let n=0,r=()=>{let t=Math.min(n+100,e.length);for(let r=n;r<t;r++)ne(e[r]);n=t,n<e.length?requestAnimationFrame(r):u(!1)};requestAnimationFrame(r);return}ne(t)}},[ne]),{send:Y,connect:re}=it({url:e&&n?`/ws/project/${encodeURIComponent(n)}/chat/${e}`:``,onMessage:G,autoConnect:!!e&&!!n});j.current=Y,(0,Q.useEffect)(()=>{let r=!1;return c(`idle`),k.current=`idle`,m(null),F.current!=null&&(x.dismiss(F.current),F.current=null),v(null),E.current=``,D.current=[],T(!1),I.current={teamNames:new Set,messages:[]},L.current=0,z(pt),V([]),e&&n?(o(!0),fetch(`${K(n)}/chat/sessions/${e}/messages?providerId=${t}`,{headers:{Authorization:`Bearer ${q()}`}}).then(e=>e.json()).then(e=>{r||k.current!==`idle`||(e.ok&&Array.isArray(e.data)&&e.data.length>0?i(e.data):i([]))}).catch(()=>{!r&&k.current===`idle`&&i([])}).finally(()=>{r||o(!1)})):i([]),()=>{r=!0}},[e,t,n]);let X=(0,Q.useCallback)((e,t)=>{if(!e.trim())return;let n=k.current!==`idle`;if(n){let e=E.current,t=[...D.current];i(n=>{let r=n[n.length-1];return r?.role===`assistant`?[...n.slice(0,-1),{...r,id:`final-${Date.now()}`,content:e||r.content,events:t.length>0?t:r.events}]:n})}i(t=>[...t,{id:`user-${Date.now()}`,role:`user`,content:e,timestamp:new Date().toISOString()}]),E.current=``,D.current=[],A.current=null,n?(c(`thinking`),k.current=`thinking`):(c(`initializing`),k.current=`initializing`),m(null),F.current!=null&&(x.dismiss(F.current),F.current=null),Y(JSON.stringify({type:`message`,content:e,permissionMode:t?.permissionMode,priority:t?.priority,images:t?.images}))},[Y]),ie=(0,Q.useCallback)((e,t,n)=>{if(Y(JSON.stringify({type:`approval_response`,requestId:e,approved:t,data:n})),t&&n){let t=D.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),F.current!=null&&(x.dismiss(F.current),F.current=null)},[Y]),ae=(0,Q.useCallback)(()=>{if(k.current===`idle`)return;Y(JSON.stringify({type:`cancel`}));let e=E.current,t=[...D.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}),E.current=``,D.current=[],A.current=null,c(`idle`),k.current=`idle`,m(null),F.current!=null&&(x.dismiss(F.current),F.current=null)},[Y]),oe=(0,Q.useCallback)(()=>{T(!1),u(!0),re()},[re]),se=(0,Q.useCallback)(()=>{!e||!n||(o(!0),fetch(`${K(n)}/chat/sessions/${e}/messages?providerId=${t}`,{headers:{Authorization:`Bearer ${q()}`}}).then(e=>e.json()).then(e=>{e.ok&&Array.isArray(e.data)&&e.data.length>0&&(i(e.data),E.current=``,D.current=[])}).catch(()=>{}).finally(()=>o(!1)))},[e,t,n]);return M.current=se,{messages:r,messagesLoading:a,isStreaming:U,phase:s,isReconnecting:l,connectingElapsed:d,pendingApproval:p,contextWindowPct:h,compactStatus:_,statusMessage:y,sessionTitle:S,teamActivity:R,teamMessages:B,markTeamRead:ee,sendMessage:X,respondToApproval:ie,cancelStreaming:ae,reconnect:oe,refetchMessages:se,isConnected:w}}var gt=12e4;function _t(e,t=`claude`){let[n,r]=(0,Q.useState)({}),[i,a]=(0,Q.useState)(!1),[o,s]=(0,Q.useState)(null),c=(0,Q.useRef)(null),l=(0,Q.useCallback)((n=!1)=>{if(!e)return;a(!0);let i=n?`&refresh=1`:``;fetch(`${K(e)}/chat/usage?providerId=${t}${i}`,{headers:{Authorization:`Bearer ${q()}`}}).then(e=>e.json()).then(e=>{e.ok&&e.data&&(r(t=>({...t,...e.data})),e.data.lastFetchedAt&&s(e.data.lastFetchedAt))}).catch(()=>{}).finally(()=>a(!1))},[e,t]);return(0,Q.useEffect)(()=>(l(),c.current=setInterval(()=>l(),gt),()=>{c.current&&clearInterval(c.current)}),[l]),{usageInfo:n,usageLoading:i,lastFetchedAt:o,refreshUsage:(0,Q.useCallback)(()=>l(!0),[l])}}var vt={damping:.7,stiffness:.05,mass:1.25},yt=70,bt=1e3/60,xt=350,St=!1;globalThis.document?.addEventListener(`mousedown`,()=>{St=!0}),globalThis.document?.addEventListener(`mouseup`,()=>{St=!1}),globalThis.document?.addEventListener(`click`,()=>{St=!1});var Ct=(e={})=>{let[t,n]=(0,Q.useState)(!1),[r,i]=(0,Q.useState)(e.initial!==!1),[a,o]=(0,Q.useState)(!1),s=(0,Q.useRef)(null);s.current=e;let c=(0,Q.useCallback)(()=>{if(!St)return!1;let e=window.getSelection();if(!e||!e.rangeCount)return!1;let t=e.getRangeAt(0);return t.commonAncestorContainer.contains(g.current)||g.current?.contains(t.commonAncestorContainer)},[]),l=(0,Q.useCallback)(e=>{d.isAtBottom=e,i(e)},[]),u=(0,Q.useCallback)(e=>{d.escapedFromLock=e,n(e)},[]),d=(0,Q.useMemo)(()=>{let n;return{escapedFromLock:t,isAtBottom:r,resizeDifference:0,accumulated:0,velocity:0,listeners:new Set,get scrollTop(){return g.current?.scrollTop??0},set scrollTop(e){g.current&&(g.current.scrollTop=e,d.ignoreScrollToTop=g.current.scrollTop)},get targetScrollTop(){return!g.current||!_.current?0:g.current.scrollHeight-1-g.current.clientHeight},get calculatedTargetScrollTop(){if(!g.current||!_.current)return 0;let{targetScrollTop:t}=this;if(!e.targetScrollTop)return t;if(n?.targetScrollTop===t)return n.calculatedScrollTop;let r=Math.max(Math.min(e.targetScrollTop(t,{scrollElement:g.current,contentElement:_.current}),t),0);return n={targetScrollTop:t,calculatedScrollTop:r},requestAnimationFrame(()=>{n=void 0}),r},get scrollDifference(){return this.calculatedTargetScrollTop-this.scrollTop},get isNearBottom(){return this.scrollDifference<=yt}}},[]),f=(0,Q.useCallback)((e={})=>{typeof e==`string`&&(e={animation:e}),e.preserveScrollPosition||l(!0);let t=Date.now()+(Number(e.wait)||0),n=Et(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))/bt;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:Et(s.current,s.current.resize),ignoreEscapes:r,duration:Math.max(0,i-Date.now())||void 0}):d.isAtBottom)});return e.then(e=>(requestAnimationFrame(()=>{d.animation||(d.lastTick=void 0,d.velocity=0)}),e))};return e.wait!==!0&&(d.animation=void 0),d.animation?.behavior===n?d.animation.promise:o()},[l,c,d]),p=(0,Q.useCallback)(()=>{u(!0),l(!1)},[u,l]),m=(0,Q.useCallback)(({target:e})=>{if(e!==g.current)return;let{scrollTop:t,ignoreScrollToTop:n}=d,{lastScrollTop:r=t}=d;d.lastScrollTop=t,d.ignoreScrollToTop=void 0,n&&n>t&&(r=n),o(d.isNearBottom),setTimeout(()=>{if(d.resizeDifference||t===n)return;if(c()){u(!0),l(!1);return}let e=t>r,i=t<r;if(d.animation?.ignoreEscapes){d.scrollTop=r;return}i&&(u(!0),l(!1)),e&&u(!1),!d.escapedFromLock&&d.isNearBottom&&l(!0)},1)},[u,l,c,d]),h=(0,Q.useCallback)(({target:e,deltaY:t})=>{let n=e;for(;![`scroll`,`auto`].includes(getComputedStyle(n).overflow);){if(!n.parentElement)return;n=n.parentElement}n===g.current&&t<0&&g.current.scrollHeight>g.current.clientHeight&&!d.animation?.ignoreEscapes&&(u(!0),l(!1))},[u,l,d]),g=wt(e=>{g.current?.removeEventListener(`scroll`,m),g.current?.removeEventListener(`wheel`,h),e?.addEventListener(`scroll`,m,{passive:!0}),e?.addEventListener(`wheel`,h,{passive:!0})},[]),_=wt(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=Et(s.current,t?s.current.resize:s.current.initial);f({animation:e,wait:!0,preserveScrollPosition:!0,duration:e===`instant`?void 0:xt})}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 wt(e,t){let n=(0,Q.useCallback)(t=>(n.current=t,e(t)),t);return n}var Tt=new Map;function Et(...e){let t={...vt},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 Tt.has(r)||Tt.set(r,Object.freeze(t)),n?`instant`:Tt.get(r)}var Dt=(0,Q.createContext)(null),Ot=typeof window<`u`?Q.useLayoutEffect:Q.useEffect;function kt({instance:e,children:t,resize:n,initial:r,mass:i,damping:a,stiffness:o,targetScrollTop:s,contextRef:c,...l}){let u=(0,Q.useRef)(null),d=Ct({mass:i,damping:a,stiffness:o,resize:n,initial:r,targetScrollTop:Q.useCallback((e,t)=>(y?.targetScrollTop??s)?.(e,t)??e,[s])}),{scrollRef:f,contentRef:p,scrollToBottom:m,stopScroll:h,isAtBottom:g,escapedFromLock:_,state:v}=e??d,y=(0,Q.useMemo)(()=>({scrollToBottom:m,stopScroll:h,scrollRef:f,isAtBottom:g,escapedFromLock:_,contentRef:p,state:v,get targetScrollTop(){return u.current},set targetScrollTop(e){u.current=e}}),[m,g,p,f,h,_,v]);return(0,Q.useImperativeHandle)(c,()=>y,[y]),Ot(()=>{f.current&&getComputedStyle(f.current).overflow===`visible`&&(f.current.style.overflow=`auto`)},[]),Q.createElement(Dt.Provider,{value:y},Q.createElement(`div`,{...l},typeof t==`function`?t(y):t))}(function(e){function t({children:e,scrollClassName:t,...n}){let r=At();return Q.createElement(`div`,{ref:r.scrollRef,style:{height:`100%`,width:`100%`,scrollbarGutter:`stable both-edges`},className:t},Q.createElement(`div`,{...n,ref:r.contentRef},typeof e==`function`?e(r):e))}e.Content=t})(kt||={});function At(){let e=(0,Q.useContext)(Dt);if(!e)throw Error(`use-stick-to-bottom component context must be used within a StickToBottom component`);return e}var $=r();function jt(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,Q.useState)(!1);if(e.type===`error`)return(0,$.jsxs)(`div`,{className:`flex items-center gap-2 rounded bg-red-500/10 border border-red-500/20 px-2 py-1.5 text-xs text-red-400`,children:[(0,$.jsx)(Te,{className:`size-3`}),(0,$.jsx)(`span`,{children:e.message})]});let{toolName:o,input:s}=jt(e),c=t?.type===`tool_result`,l=c&&!!t.isError,u=o===`AskUserQuestion`&&!!s?.answers,d=(o===`Agent`||o===`Task`)&&e.type===`tool_use`,f=d?e.children:void 0,p=f&&f.length>0;return(0,$.jsxs)(`div`,{className:`rounded border text-xs ${d?`border-accent/30 bg-accent/5`:`border-border bg-background`}`,children:[(0,$.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,$.jsx)(w,{className:`size-3 shrink-0`}):(0,$.jsx)(E,{className:`size-3 shrink-0`}),l?(0,$.jsx)(ze,{className:`size-3 text-red-400 shrink-0`}):c||u||n?(0,$.jsx)(ke,{className:`size-3 text-green-400 shrink-0`}):(0,$.jsx)(Z,{className:`size-3 text-yellow-400 shrink-0 animate-spin`}),(0,$.jsx)(`span`,{className:`truncate text-text-primary`,children:(0,$.jsx)(Nt,{name:o,input:s})}),p&&(0,$.jsxs)(`span`,{className:`ml-auto text-[10px] text-text-subtle shrink-0`,children:[f.length,` steps`]})]}),i&&(0,$.jsxs)(`div`,{className:`px-2 pb-2 space-y-1.5`,children:[(e.type===`tool_use`||e.type===`approval_request`)&&(0,$.jsx)(Pt,{name:o,input:s,projectName:r}),p&&(0,$.jsx)(Rt,{events:f,projectName:r}),c&&(0,$.jsx)(It,{toolName:o,output:t.output})]})]})}function Nt({name:e,input:t}){let n=e=>String(e??``);switch(e){case`Read`:case`Write`:case`Edit`:case`MultiEdit`:case`NotebookEdit`:return(0,$.jsxs)($.Fragment,{children:[e,` `,(0,$.jsx)(`span`,{className:`text-text-subtle`,children:G(n(t.file_path))})]});case`Bash`:return(0,$.jsxs)($.Fragment,{children:[e,` `,(0,$.jsx)(`span`,{className:`font-mono text-text-subtle`,children:Bt(n(t.command),60)})]});case`Glob`:return(0,$.jsxs)($.Fragment,{children:[e,` `,(0,$.jsx)(`span`,{className:`font-mono text-text-subtle`,children:n(t.pattern)})]});case`Grep`:return(0,$.jsxs)($.Fragment,{children:[e,` `,(0,$.jsx)(`span`,{className:`font-mono text-text-subtle`,children:Bt(n(t.pattern),40)})]});case`WebSearch`:return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Ce,{className:`size-3 inline`}),` `,e,` `,(0,$.jsx)(`span`,{className:`text-text-subtle`,children:Bt(n(t.query),50)})]});case`WebFetch`:return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(S,{className:`size-3 inline`}),` `,e,` `,(0,$.jsx)(`span`,{className:`text-text-subtle`,children:Bt(n(t.url),50)})]});case`ToolSearch`:return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Ce,{className:`size-3 inline`}),` `,e,` `,(0,$.jsx)(`span`,{className:`text-text-subtle`,children:Bt(n(t.query),50)})]});case`Agent`:case`Task`:return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(l,{className:`size-3 inline`}),` `,e,` `,(0,$.jsx)(`span`,{className:`text-text-subtle`,children:Bt(n(t.description||t.prompt),60)})]});case`TodoWrite`:{let n=Array.isArray(t.todos)?t.todos:[],r=n.filter(e=>e.status===`completed`).length;return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Ke,{className:`size-3 inline`}),` `,e,` `,(0,$.jsxs)(`span`,{className:`text-text-subtle`,children:[r,`/`,n.length,` done`]})]})}case`AskUserQuestion`:{let n=Array.isArray(t.questions)?t.questions:[],r=!!t.answers;return(0,$.jsxs)($.Fragment,{children:[e,` `,(0,$.jsxs)(`span`,{className:`text-text-subtle`,children:[n.length,` question`,n.length===1?``:`s`,r?` ✓`:``]})]})}default:return(0,$.jsx)($.Fragment,{children:e})}}function Pt({name:e,input:t,projectName:n}){let r=e=>String(e??``),{openTab:i}=ge(),a=e=>{n&&i({type:`editor`,title:G(e),metadata:{filePath:e,projectName:n},projectId:n,closable:!0})},o=(e,t,r)=>{i({type:`git-diff`,title:`Diff ${G(e)}`,metadata:{filePath:e,projectName:n,original:t,modified:r},projectId:n??null,closable:!0})};switch(e){case`Bash`:return(0,$.jsxs)(`div`,{className:`space-y-1`,children:[!!t.description&&(0,$.jsx)(`p`,{className:`text-text-subtle italic`,children:r(t.description)}),(0,$.jsx)(`pre`,{className:`font-mono text-text-secondary overflow-x-auto whitespace-pre-wrap break-all`,children:r(t.command)})]});case`Read`:case`Write`:case`Edit`:case`MultiEdit`:case`NotebookEdit`:{let n=r(t.file_path);return(0,$.jsxs)(`div`,{className:`space-y-1`,children:[(0,$.jsxs)(`button`,{type:`button`,className:`font-mono text-text-secondary break-all hover:text-primary hover:underline text-left flex items-center gap-1`,onClick:()=>a(n),title:`Open file in editor`,children:[(0,$.jsx)(xe,{className:`size-3 shrink-0`}),n]}),e===`Edit`&&(!!t.old_string||!!t.new_string)&&(0,$.jsxs)(`button`,{type:`button`,className:`text-text-subtle hover:text-primary hover:underline text-left flex items-center gap-1`,onClick:()=>o(n,r(t.old_string),r(t.new_string)),title:`View diff in new tab`,children:[(0,$.jsx)(R,{className:`size-3 shrink-0`}),`View Diff`]}),e===`Write`&&!!t.content&&(0,$.jsx)(`pre`,{className:`font-mono text-text-subtle overflow-x-auto max-h-32 whitespace-pre-wrap`,children:Bt(r(t.content),300)})]})}case`Glob`:return(0,$.jsxs)(`p`,{className:`font-mono text-text-secondary`,children:[r(t.pattern),t.path?` in ${r(t.path)}`:``]});case`Grep`:return(0,$.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,$.jsxs)(`p`,{className:`font-mono text-text-secondary`,children:[`/`,r(t.pattern),`/`]}),!!t.path&&(0,$.jsxs)(`p`,{className:`text-text-subtle`,children:[`in `,r(t.path)]})]});case`TodoWrite`:return(0,$.jsx)(Ft,{todos:t.todos??[]});case`Agent`:case`Task`:return(0,$.jsxs)(`div`,{className:`space-y-1`,children:[!!t.description&&(0,$.jsx)(`p`,{className:`text-text-secondary font-medium`,children:r(t.description)}),!!t.subagent_type&&(0,$.jsxs)(`p`,{className:`text-text-subtle`,children:[`Type: `,r(t.subagent_type)]}),!!t.prompt&&(0,$.jsx)(zt,{content:r(t.prompt),maxHeight:`max-h-48`})]});case`ToolSearch`:return(0,$.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,$.jsx)(`p`,{className:`font-mono text-text-secondary`,children:r(t.query)}),!!t.max_results&&(0,$.jsxs)(`p`,{className:`text-text-subtle`,children:[`Max results: `,r(t.max_results)]})]});case`WebFetch`:return(0,$.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,$.jsxs)(`a`,{href:r(t.url),target:`_blank`,rel:`noopener noreferrer`,className:`font-mono text-primary hover:underline break-all flex items-center gap-1`,children:[(0,$.jsx)(S,{className:`size-3 shrink-0`}),r(t.url)]}),!!t.prompt&&(0,$.jsx)(`p`,{className:`text-text-subtle`,children:Bt(r(t.prompt),100)})]});case`AskUserQuestion`:{let e=t.questions??[],n=t.answers??{};return(0,$.jsx)(`div`,{className:`space-y-2`,children:e.map((e,t)=>(0,$.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,$.jsxs)(`p`,{className:`text-text-primary font-medium`,children:[e.header?`${e.header}: `:``,e.question]}),(0,$.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:e.options.map((t,r)=>(0,$.jsx)(`span`,{className:`inline-block rounded px-1.5 py-0.5 text-xs border ${(n[e.question]??``).split(`, `).includes(t.label)?`border-accent bg-accent/20 text-text-primary`:`border-border text-text-subtle`}`,children:t.label},r))}),n[e.question]&&(0,$.jsxs)(`p`,{className:`text-foreground text-xs`,children:[`Answer: `,n[e.question]]})]},t))})}default:return(0,$.jsx)(`pre`,{className:`overflow-x-auto text-text-secondary font-mono whitespace-pre-wrap break-all`,children:JSON.stringify(t,null,2)})}}function Ft({todos:e}){return(0,$.jsx)(`div`,{className:`space-y-0.5`,children:e.map((e,t)=>(0,$.jsxs)(`div`,{className:`flex items-start gap-1.5`,children:[(0,$.jsx)(`span`,{className:`shrink-0 mt-0.5 ${e.status===`completed`?`text-green-400`:e.status===`in_progress`?`text-yellow-400`:`text-text-subtle`}`,children:e.status===`completed`?`✓`:e.status===`in_progress`?`▶`:`○`}),(0,$.jsx)(`span`,{className:e.status===`completed`?`line-through text-text-subtle`:`text-text-secondary`,children:e.content})]},t))})}function It({toolName:e,output:t}){let[n,r]=(0,Q.useState)(!1),i=(0,Q.useMemo)(()=>{if(e!==`Agent`&&e!==`Task`)return null;try{let e=JSON.parse(t);if(Array.isArray(e)){let t=e.filter(e=>e.type===`text`&&e.text).map(e=>e.text).join(`
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-I9-21gkR.js";import{a,c as o,f as s,g as c,h as l,i as u,l as d,m as f,n as p,o as m,p as h,r as g,s as _,t as v,u as y}from"./ai-settings-section-Bo9lCaTd.js";import{i as b,n as x,r as S}from"./dist-CM0oD8tQ.js";import{n as C,r as w,t as T}from"./plus-DQGIb4mQ.js";import{t as E}from"./chevron-right-DY_wImxB.js";import{R as D,a as O,i as k,l as A,n as j,o as M,r as N,s as P,t as F}from"./input-BHj0veau.js";import{n as I,t as L}from"./markdown-renderer-Pch6Q5AB.js";import{t as R}from"./columns-2-IeETSfON.js";import{n as z,r as B,t as V}from"./x-Dw3TjeY_.js";import{t as H}from"./refresh-cw-Clk8fdUD.js";import{t as ee}from"./square-vBdqj0bF.js";import{t as U}from"./trash-2-CNuB-htI.js";import{t as te}from"./preload-helper-mr3rCizq.js";import{n as W,r as ne,t as G}from"./utils-DX8jb5qv.js";import{i as K,r as q,t as J}from"./api-client-BvxmRZUi.js";import{a as Y,c as re,f as X,g as ie,i as ae,l as oe,m as se,o as ce,p as le,r as ue,s as de,t as fe,u as pe}from"./api-settings-CUxg9RE5.js";import{A as me,B as Z,D as he,E as ge,F as _e,G as ve,H as ye,I as be,J as xe,M as Se,N as Ce,O as we,Q as Te,R as Ee,U as De,Y as Oe,Z as ke,et as Ae,g as je,i as Me,j as Ne,k as Pe,r as Fe,t as Ie,z as Le}from"./index-fzSsl_Dg.js";import"./chunk-GEFDOKGD-86LFbsAC.js";import"./src-CqyWLlNZ.js";import"./chunk-7R4GIKGN-y8bfHEy-.js";import"./chunk-HHEYEP7N-C45i5G_3.js";import"./dist-DZmJeHOA.js";import"./chunk-PU5JKC2W-DD95Rx35.js";import"./chunk-MX3YWQON-B6g1ZH9X.js";import"./chunk-YBOYWFTD-D_ILLe6_.js";import"./chunk-PQ6SQG4A-Bik13fTV.js";import"./chunk-KYZI473N-gqRLpJ4w.js";import"./chunk-O4XLMI2P-Vp_V4P-b.js";import"./chunk-GLR3WWYH-Re-5eSlQ.js";import"./chunk-XPW4576I-CgLyyW03.js";var Re=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`}]]),ze=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`}]]),Be=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`}]]),Ve=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`}]]),He=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`}]]),Ue=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`}]]),We=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`}]]),Ge=n(`list-ordered`,[[`path`,{d:`M11 5h10`,key:`1cz7ny`}],[`path`,{d:`M11 12h10`,key:`1438ji`}],[`path`,{d:`M11 19h10`,key:`11t30w`}],[`path`,{d:`M4 4h1v5`,key:`10yrso`}],[`path`,{d:`M4 9h2`,key:`r1h2o0`}],[`path`,{d:`M6.5 20H3.4c0-1 2.6-1.925 2.6-3.5a1.5 1.5 0 0 0-2.6-1.02`,key:`xtkcd5`}]]),Ke=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`}]]),qe=n(`maximize-2`,[[`path`,{d:`M15 3h6v6`,key:`1q9fwt`}],[`path`,{d:`m21 3-7 7`,key:`1l2asr`}],[`path`,{d:`m3 21 7-7`,key:`tjx5ai`}],[`path`,{d:`M9 21H3v-6`,key:`wtvkvv`}]]),Je=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`}]]),Ye=n(`minimize-2`,[[`path`,{d:`m14 10 7-7`,key:`oa77jy`}],[`path`,{d:`M20 10h-6V4`,key:`mjg0md`}],[`path`,{d:`m3 21 7-7`,key:`tjx5ai`}],[`path`,{d:`M4 14h6v6`,key:`rmj7iw`}]]),Xe=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`}]]),Ze=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`}]]),Qe=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`}]]),$e=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`}]]),et=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`}]]),tt=n(`tag`,[[`path`,{d:`M12.586 2.586A2 2 0 0 0 11.172 2H4a2 2 0 0 0-2 2v7.172a2 2 0 0 0 .586 1.414l8.704 8.704a2.426 2.426 0 0 0 3.42 0l6.58-6.58a2.426 2.426 0 0 0 0-3.42z`,key:`vktsd0`}],[`circle`,{cx:`7.5`,cy:`7.5`,r:`.5`,fill:`currentColor`,key:`kqv944`}]]),nt=n(`users`,[[`path`,{d:`M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2`,key:`1yyitq`}],[`path`,{d:`M16 3.128a4 4 0 0 1 0 7.744`,key:`16gr8j`}],[`path`,{d:`M22 21v-2a4 4 0 0 0-3-3.87`,key:`kshegd`}],[`circle`,{cx:`9`,cy:`7`,r:`4`,key:`nufk8`}]]),rt=n(`zap`,[[`path`,{d:`M4 14a1 1 0 0 1-.78-1.63l9.9-10.2a.5.5 0 0 1 .86.46l-1.92 6.02A1 1 0 0 0 13 10h7a1 1 0 0 1 .78 1.63l-9.9 10.2a.5.5 0 0 1-.86-.46l1.92-6.02A1 1 0 0 0 11 14z`,key:`1xq2db`}]]),Q=e(t(),1);function it({url:e,onMessage:t,autoConnect:n=!0}){let r=(0,Q.useRef)(null);return(0,Q.useEffect)(()=>{let i=new Ie(e);return r.current=i,t&&i.onMessage(t),n&&i.connect(),()=>{i.disconnect(),r.current=null}},[e,n]),{send:(0,Q.useCallback)(e=>{r.current?.send(e)},[]),connect:(0,Q.useCallback)(()=>{r.current?.connect()},[]),disconnect:(0,Q.useCallback)(()=>{r.current?.disconnect()},[])}}var at=null;function ot(){return at||=new AudioContext,at}function st(e,t,n,r,i=`sine`){let a=ot(),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 ct(){let e=ot().currentTime;st(523,.15,e,.15),st(659,.2,e+.12,.15)}function lt(){let e=ot().currentTime;st(880,.12,e,.18,`square`),st(698,.12,e+.15,.18,`square`),st(880,.15,e+.3,.15,`square`)}function ut(){let e=ot().currentTime;st(440,.12,e,.12),st(523,.12,e+.1,.12),st(659,.18,e+.2,.12)}var dt={done:ct,approval_request:lt,question:ut};function ft(e){try{dt[e]?.()}catch{}}var pt={hasTeams:!1,teamNames:[],messageCount:0,unreadCount:0};function mt(e){if(document.hidden)return!1;let{panels:t,focusedPanelId:n}=we.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 ht(e,t=`claude`,n=``){let[r,i]=(0,Q.useState)([]),[a,o]=(0,Q.useState)(!1),[s,c]=(0,Q.useState)(`idle`),[l,u]=(0,Q.useState)(!1),[d,f]=(0,Q.useState)(0),[p,m]=(0,Q.useState)(null),[h,g]=(0,Q.useState)(null),[_,v]=(0,Q.useState)(null),[y,b]=(0,Q.useState)(null),[S,C]=(0,Q.useState)(null),[w,T]=(0,Q.useState)(!1),E=(0,Q.useRef)(``),D=(0,Q.useRef)([]),O=(0,Q.useRef)(null),k=(0,Q.useRef)(`idle`),A=(0,Q.useRef)(null),j=(0,Q.useRef)(()=>{}),M=(0,Q.useRef)(null),N=(0,Q.useRef)(e);N.current=e;let P=(0,Q.useRef)(n);P.current=n;let F=(0,Q.useRef)(null),I=(0,Q.useRef)({teamNames:new Set,messages:[]}),L=(0,Q.useRef)(0),[R,z]=(0,Q.useState)(pt),[B,V]=(0,Q.useState)([]),H=(0,Q.useCallback)(()=>{let e=I.current;z({hasTeams:e.teamNames.size>0,teamNames:Array.from(e.teamNames),messageCount:e.messages.length,unreadCount:L.current}),V([...e.messages])},[]),ee=(0,Q.useCallback)(()=>{L.current=0,H()},[H]),U=s!==`idle`,te=(0,Q.useCallback)((e,t)=>{let n=D.current.findIndex(e=>e.type===`tool_use`&&(e.tool===`Agent`||e.tool===`Task`)&&e.toolUseId===t);if(n===-1)return!1;let r=D.current[n];if(r.type!==`tool_use`)return!1;let i=[...r.children??[],e];return D.current[n]={...r,children:i},!0},[]),W=(0,Q.useCallback)(()=>{let e=E.current,t=[...D.current],n=O.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}]})},[]),ne=(0,Q.useCallback)(e=>{let t=e,n=t?.type;if(n)switch(n){case`account_info`:O.current={accountId:t.accountId,accountLabel:t.accountLabel},b(null);break;case`account_retry`:t.accountId&&t.accountLabel&&(O.current={accountId:t.accountId,accountLabel:t.accountLabel}),D.current.push(t),W();break;case`status_update`:{let e=t.accountLabel?` (${t.accountLabel})`:``;b(`${t.message}${e}`);break}case`text`:{let e=t.parentToolUseId;if(e&&te(t,e)){W();break}E.current+=t.content,D.current.push(t),W();break}case`thinking`:{let e=t.parentToolUseId;if(e&&te(t,e)){W();break}D.current.push(t),W();break}case`tool_use`:{let e=t.parentToolUseId;if(e&&te(t,e)){W();break}D.current.push(t),W();break}case`tool_result`:{let e=t.parentToolUseId;if(e&&te(t,e)){W();break}D.current.push(t),W();break}case`approval_request`:if(D.current.push(t),m({requestId:t.requestId,tool:t.tool,input:t.input}),N.current&&!mt(N.current)){let e=t.tool===`AskUserQuestion`?`question`:`approval_request`;je.getState().addNotification(N.current,e,P.current),ft(e);let n=N.current,r=t.tool===`AskUserQuestion`;F.current=x[r?`info`:`warning`](r?`AI has a question`:`${t.tool} needs permission`,{description:P.current||`Session ${n.slice(0,8)}`,duration:1/0,action:{label:`Go to session`,onClick:()=>{let{panels:e}=we.getState();for(let[t,r]of Object.entries(e)){let e=r.tabs.find(e=>e.metadata?.sessionId===n);if(e){we.getState().setActiveTab(e.id,t);break}}}}})}break;case`error`:{D.current.push(t);let e=[...D.current];i(n=>{let r=n[n.length-1];return r?.role===`assistant`?[...n.slice(0,-1),{...r,events:e}]:[...n,{id:`error-${Date.now()}`,role:`system`,content:t.message,events:[t],timestamp:new Date().toISOString()}]});break}case`team_detected`:{let e=t.teamName;e&&(I.current.teamNames.add(e),J.get(`/api/teams/${encodeURIComponent(e)}`).then(e=>{if(e?.messages){let t=I.current.messages,n=e.messages.filter(e=>!t.some(t=>t.timestamp===e.timestamp&&t.from===e.from));t.push(...n),t.sort((e,t)=>new Date(e.timestamp).getTime()-new Date(t.timestamp).getTime())}H()}).catch(()=>{}),H());break}case`team_inbox`:{let e=t.messages;Array.isArray(e)&&(I.current.messages.push(...e),L.current+=e.length,H());break}case`team_updated`:H();break;case`done`:{if(k.current===`idle`)break;t.contextWindowPct!=null&&g(t.contextWindowPct),N.current&&!mt(N.current)&&(je.getState().addNotification(N.current,`done`,P.current),ft(`done`));let e=E.current,n=[...D.current],r=t.lastMessageUuid;i(t=>{let i=t[t.length-1];return i?.role===`assistant`?[...t.slice(0,-1),{...i,id:`final-${Date.now()}`,content:e||i.content,events:n.length>0?n:i.events,...r&&{sdkUuid:r}}]:t}),E.current=``,D.current=[],O.current=null,b(null);break}}},[te,W]),G=(0,Q.useCallback)(e=>{let t;try{t=JSON.parse(e.data)}catch{return}if(t.type!==`ping`){if(t.type===`title_updated`){C(t.title??null);return}if(t.type===`compact_status`){let e=t.status;e===`compacting`?v(`compacting`):e===`done`&&(v(null),M.current?.());return}if(t.type===`phase_changed`){let e=t.phase;c(e),k.current=e,f(e===`connecting`?t.elapsed??0:0);return}if(t.type===`session_state`){T(!0);let e=t,n=e.phase;c(n),k.current=n,e.sessionTitle&&C(e.sessionTitle),e.pendingApproval&&m({requestId:e.pendingApproval.requestId,tool:e.pendingApproval.tool,input:e.pendingApproval.input}),n===`idle`&&(M.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}),E.current=``,D.current=[],O.current=null;let n=0,r=()=>{let t=Math.min(n+100,e.length);for(let r=n;r<t;r++)ne(e[r]);n=t,n<e.length?requestAnimationFrame(r):u(!1)};requestAnimationFrame(r);return}ne(t)}},[ne]),{send:Y,connect:re}=it({url:e&&n?`/ws/project/${encodeURIComponent(n)}/chat/${e}`:``,onMessage:G,autoConnect:!!e&&!!n});j.current=Y,(0,Q.useEffect)(()=>{let r=!1;return c(`idle`),k.current=`idle`,m(null),F.current!=null&&(x.dismiss(F.current),F.current=null),v(null),E.current=``,D.current=[],T(!1),I.current={teamNames:new Set,messages:[]},L.current=0,z(pt),V([]),e&&n?(o(!0),fetch(`${K(n)}/chat/sessions/${e}/messages?providerId=${t}`,{headers:{Authorization:`Bearer ${q()}`}}).then(e=>e.json()).then(e=>{r||k.current!==`idle`||(e.ok&&Array.isArray(e.data)&&e.data.length>0?i(e.data):i([]))}).catch(()=>{!r&&k.current===`idle`&&i([])}).finally(()=>{r||o(!1)})):i([]),()=>{r=!0}},[e,t,n]);let X=(0,Q.useCallback)((e,t)=>{if(!e.trim())return;let n=k.current!==`idle`;if(n){let e=E.current,t=[...D.current];i(n=>{let r=n[n.length-1];return r?.role===`assistant`?[...n.slice(0,-1),{...r,id:`final-${Date.now()}`,content:e||r.content,events:t.length>0?t:r.events}]:n})}i(t=>[...t,{id:`user-${Date.now()}`,role:`user`,content:e,timestamp:new Date().toISOString()}]),E.current=``,D.current=[],A.current=null,n?(c(`thinking`),k.current=`thinking`):(c(`initializing`),k.current=`initializing`),m(null),F.current!=null&&(x.dismiss(F.current),F.current=null),Y(JSON.stringify({type:`message`,content:e,permissionMode:t?.permissionMode,priority:t?.priority,images:t?.images}))},[Y]),ie=(0,Q.useCallback)((e,t,n)=>{if(Y(JSON.stringify({type:`approval_response`,requestId:e,approved:t,data:n})),t&&n){let t=D.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),F.current!=null&&(x.dismiss(F.current),F.current=null)},[Y]),ae=(0,Q.useCallback)(()=>{if(k.current===`idle`)return;Y(JSON.stringify({type:`cancel`}));let e=E.current,t=[...D.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}),E.current=``,D.current=[],A.current=null,c(`idle`),k.current=`idle`,m(null),F.current!=null&&(x.dismiss(F.current),F.current=null)},[Y]),oe=(0,Q.useCallback)(()=>{T(!1),u(!0),re()},[re]),se=(0,Q.useCallback)(()=>{!e||!n||(o(!0),fetch(`${K(n)}/chat/sessions/${e}/messages?providerId=${t}`,{headers:{Authorization:`Bearer ${q()}`}}).then(e=>e.json()).then(e=>{e.ok&&Array.isArray(e.data)&&e.data.length>0&&(i(e.data),E.current=``,D.current=[])}).catch(()=>{}).finally(()=>o(!1)))},[e,t,n]);return M.current=se,{messages:r,messagesLoading:a,isStreaming:U,phase:s,isReconnecting:l,connectingElapsed:d,pendingApproval:p,contextWindowPct:h,compactStatus:_,statusMessage:y,sessionTitle:S,teamActivity:R,teamMessages:B,markTeamRead:ee,sendMessage:X,respondToApproval:ie,cancelStreaming:ae,reconnect:oe,refetchMessages:se,isConnected:w}}var gt=12e4;function _t(e,t=`claude`){let[n,r]=(0,Q.useState)({}),[i,a]=(0,Q.useState)(!1),[o,s]=(0,Q.useState)(null),c=(0,Q.useRef)(null),l=(0,Q.useCallback)((n=!1)=>{if(!e)return;a(!0);let i=n?`&refresh=1`:``;fetch(`${K(e)}/chat/usage?providerId=${t}${i}`,{headers:{Authorization:`Bearer ${q()}`}}).then(e=>e.json()).then(e=>{e.ok&&e.data&&(r(t=>({...t,...e.data})),e.data.lastFetchedAt&&s(e.data.lastFetchedAt))}).catch(()=>{}).finally(()=>a(!1))},[e,t]);return(0,Q.useEffect)(()=>(l(),c.current=setInterval(()=>l(),gt),()=>{c.current&&clearInterval(c.current)}),[l]),{usageInfo:n,usageLoading:i,lastFetchedAt:o,refreshUsage:(0,Q.useCallback)(()=>l(!0),[l])}}var vt={damping:.7,stiffness:.05,mass:1.25},yt=70,bt=1e3/60,xt=350,St=!1;globalThis.document?.addEventListener(`mousedown`,()=>{St=!0}),globalThis.document?.addEventListener(`mouseup`,()=>{St=!1}),globalThis.document?.addEventListener(`click`,()=>{St=!1});var Ct=(e={})=>{let[t,n]=(0,Q.useState)(!1),[r,i]=(0,Q.useState)(e.initial!==!1),[a,o]=(0,Q.useState)(!1),s=(0,Q.useRef)(null);s.current=e;let c=(0,Q.useCallback)(()=>{if(!St)return!1;let e=window.getSelection();if(!e||!e.rangeCount)return!1;let t=e.getRangeAt(0);return t.commonAncestorContainer.contains(g.current)||g.current?.contains(t.commonAncestorContainer)},[]),l=(0,Q.useCallback)(e=>{d.isAtBottom=e,i(e)},[]),u=(0,Q.useCallback)(e=>{d.escapedFromLock=e,n(e)},[]),d=(0,Q.useMemo)(()=>{let n;return{escapedFromLock:t,isAtBottom:r,resizeDifference:0,accumulated:0,velocity:0,listeners:new Set,get scrollTop(){return g.current?.scrollTop??0},set scrollTop(e){g.current&&(g.current.scrollTop=e,d.ignoreScrollToTop=g.current.scrollTop)},get targetScrollTop(){return!g.current||!_.current?0:g.current.scrollHeight-1-g.current.clientHeight},get calculatedTargetScrollTop(){if(!g.current||!_.current)return 0;let{targetScrollTop:t}=this;if(!e.targetScrollTop)return t;if(n?.targetScrollTop===t)return n.calculatedScrollTop;let r=Math.max(Math.min(e.targetScrollTop(t,{scrollElement:g.current,contentElement:_.current}),t),0);return n={targetScrollTop:t,calculatedScrollTop:r},requestAnimationFrame(()=>{n=void 0}),r},get scrollDifference(){return this.calculatedTargetScrollTop-this.scrollTop},get isNearBottom(){return this.scrollDifference<=yt}}},[]),f=(0,Q.useCallback)((e={})=>{typeof e==`string`&&(e={animation:e}),e.preserveScrollPosition||l(!0);let t=Date.now()+(Number(e.wait)||0),n=Et(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))/bt;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:Et(s.current,s.current.resize),ignoreEscapes:r,duration:Math.max(0,i-Date.now())||void 0}):d.isAtBottom)});return e.then(e=>(requestAnimationFrame(()=>{d.animation||(d.lastTick=void 0,d.velocity=0)}),e))};return e.wait!==!0&&(d.animation=void 0),d.animation?.behavior===n?d.animation.promise:o()},[l,c,d]),p=(0,Q.useCallback)(()=>{u(!0),l(!1)},[u,l]),m=(0,Q.useCallback)(({target:e})=>{if(e!==g.current)return;let{scrollTop:t,ignoreScrollToTop:n}=d,{lastScrollTop:r=t}=d;d.lastScrollTop=t,d.ignoreScrollToTop=void 0,n&&n>t&&(r=n),o(d.isNearBottom),setTimeout(()=>{if(d.resizeDifference||t===n)return;if(c()){u(!0),l(!1);return}let e=t>r,i=t<r;if(d.animation?.ignoreEscapes){d.scrollTop=r;return}i&&(u(!0),l(!1)),e&&u(!1),!d.escapedFromLock&&d.isNearBottom&&l(!0)},1)},[u,l,c,d]),h=(0,Q.useCallback)(({target:e,deltaY:t})=>{let n=e;for(;![`scroll`,`auto`].includes(getComputedStyle(n).overflow);){if(!n.parentElement)return;n=n.parentElement}n===g.current&&t<0&&g.current.scrollHeight>g.current.clientHeight&&!d.animation?.ignoreEscapes&&(u(!0),l(!1))},[u,l,d]),g=wt(e=>{g.current?.removeEventListener(`scroll`,m),g.current?.removeEventListener(`wheel`,h),e?.addEventListener(`scroll`,m,{passive:!0}),e?.addEventListener(`wheel`,h,{passive:!0})},[]),_=wt(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=Et(s.current,t?s.current.resize:s.current.initial);f({animation:e,wait:!0,preserveScrollPosition:!0,duration:e===`instant`?void 0:xt})}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 wt(e,t){let n=(0,Q.useCallback)(t=>(n.current=t,e(t)),t);return n}var Tt=new Map;function Et(...e){let t={...vt},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 Tt.has(r)||Tt.set(r,Object.freeze(t)),n?`instant`:Tt.get(r)}var Dt=(0,Q.createContext)(null),Ot=typeof window<`u`?Q.useLayoutEffect:Q.useEffect;function kt({instance:e,children:t,resize:n,initial:r,mass:i,damping:a,stiffness:o,targetScrollTop:s,contextRef:c,...l}){let u=(0,Q.useRef)(null),d=Ct({mass:i,damping:a,stiffness:o,resize:n,initial:r,targetScrollTop:Q.useCallback((e,t)=>(y?.targetScrollTop??s)?.(e,t)??e,[s])}),{scrollRef:f,contentRef:p,scrollToBottom:m,stopScroll:h,isAtBottom:g,escapedFromLock:_,state:v}=e??d,y=(0,Q.useMemo)(()=>({scrollToBottom:m,stopScroll:h,scrollRef:f,isAtBottom:g,escapedFromLock:_,contentRef:p,state:v,get targetScrollTop(){return u.current},set targetScrollTop(e){u.current=e}}),[m,g,p,f,h,_,v]);return(0,Q.useImperativeHandle)(c,()=>y,[y]),Ot(()=>{f.current&&getComputedStyle(f.current).overflow===`visible`&&(f.current.style.overflow=`auto`)},[]),Q.createElement(Dt.Provider,{value:y},Q.createElement(`div`,{...l},typeof t==`function`?t(y):t))}(function(e){function t({children:e,scrollClassName:t,...n}){let r=At();return Q.createElement(`div`,{ref:r.scrollRef,style:{height:`100%`,width:`100%`,scrollbarGutter:`stable both-edges`},className:t},Q.createElement(`div`,{...n,ref:r.contentRef},typeof e==`function`?e(r):e))}e.Content=t})(kt||={});function At(){let e=(0,Q.useContext)(Dt);if(!e)throw Error(`use-stick-to-bottom component context must be used within a StickToBottom component`);return e}var $=r();function jt(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,Q.useState)(!1);if(e.type===`error`)return(0,$.jsxs)(`div`,{className:`flex items-center gap-2 rounded bg-red-500/10 border border-red-500/20 px-2 py-1.5 text-xs text-red-400`,children:[(0,$.jsx)(Te,{className:`size-3`}),(0,$.jsx)(`span`,{children:e.message})]});let{toolName:o,input:s}=jt(e),c=t?.type===`tool_result`,l=c&&!!t.isError,u=o===`AskUserQuestion`&&!!s?.answers,d=(o===`Agent`||o===`Task`)&&e.type===`tool_use`,f=d?e.children:void 0,p=f&&f.length>0;return(0,$.jsxs)(`div`,{className:`rounded border text-xs ${d?`border-accent/30 bg-accent/5`:`border-border bg-background`}`,children:[(0,$.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,$.jsx)(w,{className:`size-3 shrink-0`}):(0,$.jsx)(E,{className:`size-3 shrink-0`}),l?(0,$.jsx)(ze,{className:`size-3 text-red-400 shrink-0`}):c||u||n?(0,$.jsx)(ke,{className:`size-3 text-green-400 shrink-0`}):(0,$.jsx)(Z,{className:`size-3 text-yellow-400 shrink-0 animate-spin`}),(0,$.jsx)(`span`,{className:`truncate text-text-primary`,children:(0,$.jsx)(Nt,{name:o,input:s})}),p&&(0,$.jsxs)(`span`,{className:`ml-auto text-[10px] text-text-subtle shrink-0`,children:[f.length,` steps`]})]}),i&&(0,$.jsxs)(`div`,{className:`px-2 pb-2 space-y-1.5`,children:[(e.type===`tool_use`||e.type===`approval_request`)&&(0,$.jsx)(Pt,{name:o,input:s,projectName:r}),p&&(0,$.jsx)(Rt,{events:f,projectName:r}),c&&(0,$.jsx)(It,{toolName:o,output:t.output})]})]})}function Nt({name:e,input:t}){let n=e=>String(e??``);switch(e){case`Read`:case`Write`:case`Edit`:case`MultiEdit`:case`NotebookEdit`:return(0,$.jsxs)($.Fragment,{children:[e,` `,(0,$.jsx)(`span`,{className:`text-text-subtle`,children:G(n(t.file_path))})]});case`Bash`:return(0,$.jsxs)($.Fragment,{children:[e,` `,(0,$.jsx)(`span`,{className:`font-mono text-text-subtle`,children:Bt(n(t.command),60)})]});case`Glob`:return(0,$.jsxs)($.Fragment,{children:[e,` `,(0,$.jsx)(`span`,{className:`font-mono text-text-subtle`,children:n(t.pattern)})]});case`Grep`:return(0,$.jsxs)($.Fragment,{children:[e,` `,(0,$.jsx)(`span`,{className:`font-mono text-text-subtle`,children:Bt(n(t.pattern),40)})]});case`WebSearch`:return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Ce,{className:`size-3 inline`}),` `,e,` `,(0,$.jsx)(`span`,{className:`text-text-subtle`,children:Bt(n(t.query),50)})]});case`WebFetch`:return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(S,{className:`size-3 inline`}),` `,e,` `,(0,$.jsx)(`span`,{className:`text-text-subtle`,children:Bt(n(t.url),50)})]});case`ToolSearch`:return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Ce,{className:`size-3 inline`}),` `,e,` `,(0,$.jsx)(`span`,{className:`text-text-subtle`,children:Bt(n(t.query),50)})]});case`Agent`:case`Task`:return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(l,{className:`size-3 inline`}),` `,e,` `,(0,$.jsx)(`span`,{className:`text-text-subtle`,children:Bt(n(t.description||t.prompt),60)})]});case`TodoWrite`:{let n=Array.isArray(t.todos)?t.todos:[],r=n.filter(e=>e.status===`completed`).length;return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Ke,{className:`size-3 inline`}),` `,e,` `,(0,$.jsxs)(`span`,{className:`text-text-subtle`,children:[r,`/`,n.length,` done`]})]})}case`AskUserQuestion`:{let n=Array.isArray(t.questions)?t.questions:[],r=!!t.answers;return(0,$.jsxs)($.Fragment,{children:[e,` `,(0,$.jsxs)(`span`,{className:`text-text-subtle`,children:[n.length,` question`,n.length===1?``:`s`,r?` ✓`:``]})]})}default:return(0,$.jsx)($.Fragment,{children:e})}}function Pt({name:e,input:t,projectName:n}){let r=e=>String(e??``),{openTab:i}=ge(),a=e=>{n&&i({type:`editor`,title:G(e),metadata:{filePath:e,projectName:n},projectId:n,closable:!0})},o=(e,t,r)=>{i({type:`git-diff`,title:`Diff ${G(e)}`,metadata:{filePath:e,projectName:n,original:t,modified:r},projectId:n??null,closable:!0})};switch(e){case`Bash`:return(0,$.jsxs)(`div`,{className:`space-y-1`,children:[!!t.description&&(0,$.jsx)(`p`,{className:`text-text-subtle italic`,children:r(t.description)}),(0,$.jsx)(`pre`,{className:`font-mono text-text-secondary overflow-x-auto whitespace-pre-wrap break-all`,children:r(t.command)})]});case`Read`:case`Write`:case`Edit`:case`MultiEdit`:case`NotebookEdit`:{let n=r(t.file_path);return(0,$.jsxs)(`div`,{className:`space-y-1`,children:[(0,$.jsxs)(`button`,{type:`button`,className:`font-mono text-text-secondary break-all hover:text-primary hover:underline text-left flex items-center gap-1`,onClick:()=>a(n),title:`Open file in editor`,children:[(0,$.jsx)(xe,{className:`size-3 shrink-0`}),n]}),e===`Edit`&&(!!t.old_string||!!t.new_string)&&(0,$.jsxs)(`button`,{type:`button`,className:`text-text-subtle hover:text-primary hover:underline text-left flex items-center gap-1`,onClick:()=>o(n,r(t.old_string),r(t.new_string)),title:`View diff in new tab`,children:[(0,$.jsx)(R,{className:`size-3 shrink-0`}),`View Diff`]}),e===`Write`&&!!t.content&&(0,$.jsx)(`pre`,{className:`font-mono text-text-subtle overflow-x-auto max-h-32 whitespace-pre-wrap`,children:Bt(r(t.content),300)})]})}case`Glob`:return(0,$.jsxs)(`p`,{className:`font-mono text-text-secondary`,children:[r(t.pattern),t.path?` in ${r(t.path)}`:``]});case`Grep`:return(0,$.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,$.jsxs)(`p`,{className:`font-mono text-text-secondary`,children:[`/`,r(t.pattern),`/`]}),!!t.path&&(0,$.jsxs)(`p`,{className:`text-text-subtle`,children:[`in `,r(t.path)]})]});case`TodoWrite`:return(0,$.jsx)(Ft,{todos:t.todos??[]});case`Agent`:case`Task`:return(0,$.jsxs)(`div`,{className:`space-y-1`,children:[!!t.description&&(0,$.jsx)(`p`,{className:`text-text-secondary font-medium`,children:r(t.description)}),!!t.subagent_type&&(0,$.jsxs)(`p`,{className:`text-text-subtle`,children:[`Type: `,r(t.subagent_type)]}),!!t.prompt&&(0,$.jsx)(zt,{content:r(t.prompt),maxHeight:`max-h-48`})]});case`ToolSearch`:return(0,$.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,$.jsx)(`p`,{className:`font-mono text-text-secondary`,children:r(t.query)}),!!t.max_results&&(0,$.jsxs)(`p`,{className:`text-text-subtle`,children:[`Max results: `,r(t.max_results)]})]});case`WebFetch`:return(0,$.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,$.jsxs)(`a`,{href:r(t.url),target:`_blank`,rel:`noopener noreferrer`,className:`font-mono text-primary hover:underline break-all flex items-center gap-1`,children:[(0,$.jsx)(S,{className:`size-3 shrink-0`}),r(t.url)]}),!!t.prompt&&(0,$.jsx)(`p`,{className:`text-text-subtle`,children:Bt(r(t.prompt),100)})]});case`AskUserQuestion`:{let e=t.questions??[],n=t.answers??{};return(0,$.jsx)(`div`,{className:`space-y-2`,children:e.map((e,t)=>(0,$.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,$.jsxs)(`p`,{className:`text-text-primary font-medium`,children:[e.header?`${e.header}: `:``,e.question]}),(0,$.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:e.options.map((t,r)=>(0,$.jsx)(`span`,{className:`inline-block rounded px-1.5 py-0.5 text-xs border ${(n[e.question]??``).split(`, `).includes(t.label)?`border-accent bg-accent/20 text-text-primary`:`border-border text-text-subtle`}`,children:t.label},r))}),n[e.question]&&(0,$.jsxs)(`p`,{className:`text-foreground text-xs`,children:[`Answer: `,n[e.question]]})]},t))})}default:return(0,$.jsx)(`pre`,{className:`overflow-x-auto text-text-secondary font-mono whitespace-pre-wrap break-all`,children:JSON.stringify(t,null,2)})}}function Ft({todos:e}){return(0,$.jsx)(`div`,{className:`space-y-0.5`,children:e.map((e,t)=>(0,$.jsxs)(`div`,{className:`flex items-start gap-1.5`,children:[(0,$.jsx)(`span`,{className:`shrink-0 mt-0.5 ${e.status===`completed`?`text-green-400`:e.status===`in_progress`?`text-yellow-400`:`text-text-subtle`}`,children:e.status===`completed`?`✓`:e.status===`in_progress`?`▶`:`○`}),(0,$.jsx)(`span`,{className:e.status===`completed`?`line-through text-text-subtle`:`text-text-secondary`,children:e.content})]},t))})}function It({toolName:e,output:t}){let[n,r]=(0,Q.useState)(!1),i=(0,Q.useMemo)(()=>{if(e!==`Agent`&&e!==`Task`)return null;try{let e=JSON.parse(t);if(Array.isArray(e)){let t=e.filter(e=>e.type===`text`&&e.text).map(e=>e.text).join(`
3
3
 
4
4
  `);if(t)return t}if(typeof e==`string`)return e}catch{if(t&&!t.startsWith(`[{`))return t}return null},[e,t]);return i?(0,$.jsxs)(`div`,{className:`border-t border-border pt-1.5 space-y-1`,children:[(0,$.jsx)(zt,{content:i,maxHeight:`max-h-60`}),(0,$.jsxs)(`button`,{type:`button`,onClick:()=>r(!n),className:`flex items-center gap-1 text-[10px] text-text-subtle hover:text-text-secondary transition-colors`,children:[(0,$.jsx)(I,{className:`size-3`}),n?`Hide`:`Show`,` raw`]}),n&&(0,$.jsx)(`pre`,{className:`overflow-x-auto text-text-subtle font-mono max-h-40 whitespace-pre-wrap break-all text-[10px]`,children:t})]}):(0,$.jsx)(Lt,{output:t})}function Lt({output:e}){let t=e.split(`
5
5
  `).length,n=t>3||e.length>200,[r,i]=(0,Q.useState)(n);return(0,$.jsxs)(`div`,{className:`border-t border-border pt-1.5`,children:[n&&(0,$.jsxs)(`button`,{type:`button`,onClick:()=>i(!r),className:`flex items-center gap-1 text-[10px] text-text-subtle hover:text-text-secondary transition-colors mb-1`,children:[r?(0,$.jsx)(E,{className:`size-3`}):(0,$.jsx)(w,{className:`size-3`}),`Output (`,t,` lines)`]}),(0,$.jsx)(`pre`,{className:`overflow-x-auto text-text-subtle font-mono whitespace-pre-wrap break-all ${r?`max-h-16 overflow-hidden`:`max-h-60`}`,children:e})]})}function Rt({events:e,projectName:t}){let n=[],r=``;for(let t of e)if(t.type===`text`)r+=t.content;else if(t.type===`tool_use`)r&&=(n.push({kind:`text`,content:r}),``),n.push({kind:`tool`,tool:t});else if(t.type===`tool_result`){let e=t.toolUseId,r=e?n.find(t=>t.kind===`tool`&&t.tool.type===`tool_use`&&t.tool.toolUseId===e&&!t.result):n.findLast(e=>e.kind===`tool`&&!e.result);r&&(r.result=t)}return r&&n.push({kind:`text`,content:r}),(0,$.jsx)(`div`,{className:`border-l-2 border-accent/20 pl-2 space-y-1 mt-1`,children:n.map((e,n)=>e.kind===`text`?(0,$.jsx)(`div`,{className:`text-text-secondary text-[11px]`,children:(0,$.jsx)(zt,{content:e.content,maxHeight:`max-h-24`})},`st-${n}`):(0,$.jsx)(Mt,{tool:e.tool,result:e.result,completed:!!e.result,projectName:t},`sc-${n}`))})}function zt({content:e,maxHeight:t=`max-h-48`}){return(0,$.jsx)(L,{content:e,className:`text-text-secondary overflow-auto ${t}`})}function Bt(e,t=50){return e?e.length>t?e.slice(0,t)+`…`:e:``}var Vt=5,Ht=20;function Ut(e){try{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);return a<7?`${a}d ago`:t.toLocaleDateString(void 0,{month:`short`,day:`numeric`})}catch{return``}}function Wt({projectName:e,onSelectSession:t}){let[n,r]=(0,Q.useState)([]),[i,a]=(0,Q.useState)(!1),[o,s]=(0,Q.useState)(!1),c=(0,Q.useCallback)(async()=>{if(e){a(!0);try{r((await J.get(`${K(e)}/chat/sessions?limit=${Ht}`)).sessions.slice(0,Ht))}catch{}finally{a(!1)}}},[e]);(0,Q.useEffect)(()=>{c()},[c]);let u=(0,Q.useCallback)(async(t,n)=>{if(t.stopPropagation(),!e)return;let i=`${K(e)}/chat/sessions/${n.id}/pin`;try{n.pinned?await J.del(i):await J.put(i),r(e=>e.map(e=>e.id===n.id?{...e,pinned:!e.pinned}:e).sort((e,t)=>e.pinned&&!t.pinned?-1:!e.pinned&&t.pinned?1:new Date(t.createdAt).getTime()-new Date(e.createdAt).getTime()))}catch{}},[e]),d=n.filter(e=>e.pinned),f=n.filter(e=>!e.pinned),p=o?f:f.slice(0,Vt),m=f.length>Vt;function h(e){return(0,$.jsxs)(`button`,{onClick:()=>t(e),className:`group flex items-center gap-2.5 w-full px-3 py-2.5 text-left hover:bg-surface-elevated active:bg-surface-elevated transition-colors border-b border-border/50 last:border-0`,children:[(0,$.jsx)(Le,{className:`size-3.5 shrink-0 text-text-subtle`}),(0,$.jsx)(`span`,{className:`flex-1 min-w-0 text-xs font-medium truncate text-text-primary`,children:e.title||`Untitled`}),e.updatedAt&&(0,$.jsx)(`span`,{className:`text-[10px] text-text-subtle shrink-0`,children:Ut(e.updatedAt)}),(0,$.jsx)(`span`,{role:`button`,tabIndex:0,onClick:t=>u(t,e),className:`p-1 rounded transition-colors shrink-0 ${e.pinned?`text-primary hover:text-primary/70`:`text-text-subtle can-hover:opacity-0 can-hover:group-hover:opacity-100 hover:text-text-primary`}`,"aria-label":e.pinned?`Unpin session`:`Pin session`,children:e.pinned?(0,$.jsx)(be,{className:`size-3`}):(0,$.jsx)(_e,{className:`size-3`})})]},e.id)}return(0,$.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full gap-6 text-text-secondary overflow-y-auto`,children:[(0,$.jsxs)(`div`,{className:`flex flex-col items-center gap-3`,children:[(0,$.jsx)(l,{className:`size-10 text-text-subtle`}),(0,$.jsx)(`p`,{className:`text-sm`,children:`Send a message to start a new conversation`})]}),!i&&d.length>0&&(0,$.jsxs)(`div`,{className:`flex flex-col gap-2 w-full max-w-sm px-4`,children:[(0,$.jsx)(`p`,{className:`text-xs text-text-subtle text-center`,children:`Pinned`}),(0,$.jsx)(`div`,{className:`w-full rounded-md border border-border bg-surface overflow-hidden`,children:d.map(h)})]}),!i&&p.length>0&&(0,$.jsxs)(`div`,{className:`flex flex-col gap-2 w-full max-w-sm px-4`,children:[(0,$.jsx)(`p`,{className:`text-xs text-text-subtle text-center`,children:`Recent chats`}),(0,$.jsx)(`div`,{className:`w-full rounded-md border border-border bg-surface overflow-hidden`,children:p.map(h)}),m&&(0,$.jsxs)(`button`,{onClick:()=>s(!o),className:`flex items-center justify-center gap-1 text-[11px] text-text-subtle hover:text-text-primary transition-colors py-1`,children:[o?(0,$.jsx)(C,{className:`size-3`}):(0,$.jsx)(w,{className:`size-3`}),o?`Show less`:`Show more (${f.length-Vt})`]})]})]})}function Gt(e){let[t,n]=(0,Q.useState)({}),[r,i]=(0,Q.useState)({}),[a,o]=(0,Q.useState)(0),s=(0,Q.useCallback)((e,t)=>{n(n=>({...n,[e]:[t]})),i(t=>({...t,[e]:``}))},[]),c=(0,Q.useCallback)((e,t)=>{n(n=>{let r=n[e]||[];return{...n,[e]:r.includes(t)?r.filter(e=>e!==t):[...r,t]}})},[]),l=(0,Q.useCallback)((e,t)=>{i(n=>({...n,[e]:t})),t&&n(t=>({...t,[e]:[]}))},[]),u=(0,Q.useCallback)(e=>(t[e]?.length??0)>0||(r[e]?.trim().length??0)>0,[t,r]);return{answers:t,customInputs:r,activeTab:a,setActiveTab:o,handleSingleSelect:s,handleMultiSelect:c,handleCustomInput:l,hasAnswer:u,allAnswered:(0,Q.useMemo)(()=>e.every((e,t)=>u(t)),[e,u]),getFinalAnswer:(0,Q.useCallback)(e=>r[e]?.trim()||(t[e]??[]).join(`, `),[t,r]),goToNextTab:(0,Q.useCallback)(()=>o(t=>Math.min(t+1,e.length-1)),[e.length]),goToPrevTab:(0,Q.useCallback)(()=>o(e=>Math.max(e-1,0)),[])}}function Kt(e){let[t,n]=(0,Q.useState)(0),r=(0,Q.useRef)(null);return(0,Q.useEffect)(()=>n(0),[e.activeTab]),(0,Q.useEffect)(()=>{if(!e.enabled)return;let i=r=>{let i=document.activeElement===e.customInputRef.current;if(!i&&r.key>=`1`&&r.key<=`9`){r.preventDefault();let t=parseInt(r.key)-1;t<e.totalOptions-1&&(n(t),e.onSelectOption(t));return}if(!i&&(r.key===`o`||r.key===`O`||r.key===`0`)){r.preventDefault(),e.customInputRef.current?.focus(),n(e.totalOptions-1);return}if(r.key===`Tab`&&e.questions.length>1){r.preventDefault(),r.shiftKey?e.goToPrevTab():e.goToNextTab();return}if(!i){if(r.key===`ArrowLeft`){r.preventDefault(),e.goToPrevTab();return}if(r.key===`ArrowRight`){r.preventDefault(),e.goToNextTab();return}if(r.key===`ArrowUp`){r.preventDefault(),n(e=>Math.max(0,e-1));return}if(r.key===`ArrowDown`){r.preventDefault(),n(t=>Math.min(e.totalOptions-1,t+1));return}if(r.key===` `){r.preventDefault(),e.onSelectOption(t);return}}if(r.key===`Enter`){r.preventDefault(),e.allAnswered?e.onSubmit():e.hasAnswer(e.activeTab)&&e.goToNextTab();return}r.key===`Escape`&&i&&e.customInputRef.current?.blur()},a=r.current;return a&&(a.addEventListener(`keydown`,i),a.setAttribute(`tabindex`,`0`),a.contains(document.activeElement)||a.focus()),()=>{a?.removeEventListener(`keydown`,i)}},[e,t]),{focusedOption:t,setFocusedOption:n,containerRef:r}}function qt({questions:e,onSubmit:t,onSkip:n}){let r=(0,Q.useRef)(null),i=Gt(e),a=e[i.activeTab],o=a?a.options.length+1:0,s=e.length>1,c=(0,Q.useCallback)(()=>{if(!i.allAnswered)return;let n={};e.forEach((e,t)=>{n[e.question]=i.getFinalAnswer(t)}),t(n)},[i.allAnswered,i.getFinalAnswer,e,t]),l=(0,Q.useCallback)(e=>{if(!(!a||e<0))if(e<a.options.length){let t=a.options[e]?.label;if(!t)return;a.multiSelect?i.handleMultiSelect(i.activeTab,t):i.handleSingleSelect(i.activeTab,t)}else e===a.options.length&&r.current?.focus()},[a,i]),u=Kt({questions:e,activeTab:i.activeTab,totalOptions:o,allAnswered:i.allAnswered,hasAnswer:i.hasAnswer,onSelectOption:l,goToNextTab:i.goToNextTab,goToPrevTab:i.goToPrevTab,onSubmit:c,customInputRef:r,enabled:!0}),d=(0,Q.useCallback)(e=>{l(e),u.setFocusedOption(e)},[l,u.setFocusedOption]);return(0,$.jsxs)(`div`,{ref:u.containerRef,className:`rounded-lg border-2 border-primary/30 bg-primary/5 p-3 space-y-3 outline-none animate-in slide-in-from-bottom-2`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between text-sm font-medium text-text-primary`,children:[(0,$.jsxs)(`span`,{children:[`AI has `,s?`${e.length} questions`:`a question`]}),(0,$.jsxs)(`span`,{className:`text-[10px] text-text-secondary font-normal`,children:[s?`←→ tabs · `:``,`↑↓ options · 1-`,Math.min(o-1,9),` select · Enter submit`]})]}),s&&(0,$.jsx)(`div`,{className:`flex gap-1 p-1 bg-background rounded-md overflow-x-auto border border-border`,children:e.map((e,t)=>(0,$.jsxs)(`button`,{className:`flex items-center gap-1.5 px-3 py-1.5 rounded text-xs whitespace-nowrap transition-all ${i.activeTab===t?`bg-primary text-primary-foreground`:i.hasAnswer(t)?`text-primary bg-transparent`:`text-text-secondary hover:bg-surface-elevated`}`,onClick:()=>{i.setActiveTab(t),u.setFocusedOption(0)},tabIndex:-1,children:[(0,$.jsx)(`span`,{className:`flex items-center justify-center w-4 h-4 rounded-full text-[10px] font-semibold ${i.activeTab===t?`bg-white/20`:i.hasAnswer(t)?`bg-primary/20 text-primary`:`bg-surface-elevated text-text-secondary`}`,children:i.hasAnswer(t)?`✓`:t+1}),(0,$.jsx)(`span`,{className:`max-w-[100px] overflow-hidden text-ellipsis`,children:e.header||`Q${t+1}`})]},t))}),a&&(0,$.jsxs)(`div`,{className:`space-y-2`,children:[!s&&a.header&&(0,$.jsx)(`div`,{className:`text-[11px] font-semibold uppercase tracking-wide text-text-secondary`,children:a.header}),(0,$.jsx)(`div`,{className:`text-sm text-text-primary`,children:a.question}),a.multiSelect&&(0,$.jsx)(`div`,{className:`text-[11px] text-text-secondary`,children:`Select multiple`}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[a.options.map((e,t)=>{let n=(i.answers[i.activeTab]||[]).includes(e.label),r=u.focusedOption===t;return(0,$.jsxs)(`button`,{onClick:()=>d(t),className:`text-left flex items-start gap-2.5 rounded px-2.5 py-2 text-xs border transition-all ${n?`border-primary bg-primary/10 text-text-primary`:`border-border bg-background text-text-secondary hover:border-primary/40 hover:bg-primary/5`} ${r?`ring-2 ring-primary/40 ring-offset-1 ring-offset-background`:``}`,children:[(0,$.jsx)(`span`,{className:`flex items-center justify-center w-4.5 h-4.5 rounded text-[10px] font-semibold shrink-0 mt-px ${n?`bg-primary/20 text-primary`:`bg-surface-elevated text-text-secondary`}`,children:t+1}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-0.5 flex-1`,children:[(0,$.jsx)(`span`,{className:`font-medium text-text-primary`,children:e.label}),e.description&&(0,$.jsx)(`span`,{className:`text-[11px] text-text-secondary`,children:e.description})]})]},t)}),(0,$.jsxs)(`div`,{className:`flex items-start gap-2.5 rounded px-2.5 py-2 text-xs border border-dashed transition-all border-border bg-transparent ${u.focusedOption===o-1?`ring-2 ring-primary/40 ring-offset-1 ring-offset-background`:``}`,children:[(0,$.jsx)(`span`,{className:`flex items-center justify-center w-4.5 h-4.5 rounded bg-surface-elevated text-text-secondary text-[10px] font-semibold shrink-0 mt-px`,children:`O`}),(0,$.jsx)(`input`,{ref:r,type:`text`,className:`flex-1 px-2 py-1 text-xs bg-surface border border-border rounded text-text-primary outline-none placeholder:text-text-subtle focus:border-primary`,placeholder:`Other (press O to type)...`,value:i.customInputs[i.activeTab]||``,onChange:e=>i.handleCustomInput(i.activeTab,e.target.value),onFocus:()=>u.setFocusedOption(o-1)})]})]})]}),(0,$.jsxs)(`div`,{className:`flex gap-2 justify-end pt-1`,children:[s&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`button`,{className:`px-3 py-1.5 text-xs rounded border border-border bg-background text-text-primary hover:bg-surface-elevated disabled:opacity-40 disabled:cursor-not-allowed transition-colors`,onClick:i.goToPrevTab,disabled:i.activeTab===0,tabIndex:-1,children:`← Prev`}),(0,$.jsx)(`button`,{className:`px-3 py-1.5 text-xs rounded border border-border bg-background text-text-primary hover:bg-surface-elevated disabled:opacity-40 disabled:cursor-not-allowed transition-colors`,onClick:i.goToNextTab,disabled:i.activeTab===e.length-1,tabIndex:-1,children:`Next →`})]}),(0,$.jsx)(`button`,{onClick:n,className:`px-4 py-1.5 rounded border border-border bg-background text-text-secondary text-xs hover:bg-surface-elevated transition-colors`,tabIndex:-1,children:`Skip`}),(0,$.jsxs)(`button`,{onClick:c,disabled:!i.allAnswered,className:`px-4 py-1.5 rounded bg-primary text-primary-foreground text-xs font-medium hover:bg-primary/80 transition-colors disabled:opacity-40 disabled:cursor-not-allowed`,tabIndex:-1,children:[`Submit `,i.allAnswered?`✓`:`(${e.filter((e,t)=>i.hasAnswer(t)).length}/${e.length})`]})]})]})}function Jt({messages:e,messagesLoading:t,pendingApproval:n,onApprovalResponse:r,isStreaming:i,phase:a,onSelectSession:o,connectingElapsed:s,statusMessage:c,compactStatus:u,projectName:d,onFork:f}){if(t)return(0,$.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full gap-3 text-text-secondary`,children:[(0,$.jsx)(l,{className:`size-10 text-text-subtle animate-pulse`}),(0,$.jsx)(`p`,{className:`text-sm`,children:`Loading messages...`})]});if(e.length===0&&!i)return(0,$.jsx)(Wt,{projectName:d||``,onSelectSession:o||(()=>{})});let p=(0,Q.useMemo)(()=>e.filter(e=>{let t=e.content&&e.content.trim().length>0,n=e.events&&e.events.length>0;return e.role===`user`?t:t||n}),[e]);return(0,$.jsx)(`div`,{className:`relative flex-1 overflow-hidden flex flex-col min-h-0`,children:(0,$.jsxs)(kt,{className:`flex-1 overflow-y-auto overflow-x-hidden`,resize:`smooth`,initial:`instant`,children:[(0,$.jsxs)(kt.Content,{className:`p-4 space-y-4`,children:[p.map((e,t)=>(0,$.jsx)(Xt,{message:e,isStreaming:i&&e.id.startsWith(`streaming-`),projectName:d,onFork:e.role===`user`&&f?()=>{let n=t>0?p[t-1]:void 0;f(e.content,n?.sdkUuid??n?.id)}:void 0},e.id)),n&&(n.tool===`AskUserQuestion`?(0,$.jsx)(Sn,{approval:n,onRespond:r}):(0,$.jsx)(xn,{approval:n,onRespond:r})),i&&(0,$.jsx)(_n,{lastMessage:e[e.length-1],phase:a,elapsed:s,statusMessage:c}),!i&&u===`compacting`&&(0,$.jsx)(_n,{lastMessage:void 0,phase:`thinking`,elapsed:void 0,statusMessage:`Compacting messages...`})]}),(0,$.jsx)(Yt,{})]})})}function Yt(){let{isAtBottom:e,scrollToBottom:t}=At();return e?null:(0,$.jsxs)(`button`,{onClick:()=>t(),className:`absolute bottom-4 left-1/2 -translate-x-1/2 z-10 flex items-center gap-1 px-3 py-1 rounded-full bg-surface-elevated border border-border text-xs text-text-secondary hover:text-foreground shadow-lg transition-all`,children:[(0,$.jsx)(w,{className:`size-3`}),`Scroll to bottom`]})}function Xt({message:e,isStreaming:t,projectName:n,onFork:r}){return e.role===`user`?(0,$.jsx)(an,{content:e.content,projectName:n,onFork:r}):e.role===`system`?(0,$.jsxs)(`div`,{className:`flex items-center gap-2 rounded-lg bg-red-500/10 border border-red-500/20 px-3 py-2 text-sm text-red-400`,children:[(0,$.jsx)(Te,{className:`size-4 shrink-0`}),(0,$.jsx)(`p`,{children:e.content})]}):(0,$.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[e.events&&e.events.length>0?(0,$.jsx)(mn,{events:e.events,isStreaming:t,projectName:n}):e.content&&(0,$.jsx)(`div`,{className:`text-sm text-text-primary`,children:(0,$.jsx)(bn,{content:e.content,projectName:n})}),e.accountLabel&&(0,$.jsxs)(`p`,{className:`text-[10px] select-none`,style:{color:`var(--color-text-subtle)`},children:[`via `,e.accountLabel]})]})}var Zt=new Set([`.png`,`.jpg`,`.jpeg`,`.gif`,`.webp`]),Qt={"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 $t(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:Qt[e]??e.replace(/^antml:/,``).replace(/-/g,` `),content:r[2].trim()})}return{cleanText:e.replace(n,``).trim(),tags:t}}function en(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(`
@@ -1,5 +1,5 @@
1
1
  const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/csv-preview-BZRICDP0.js","assets/chunk-CFjPhJqf.js","assets/lib-DSLzfeW0.js","assets/react-nm2Ru1Pt.js","assets/jsx-runtime-BRW_vwa9.js","assets/arrow-up-I9-21gkR.js","assets/react-dom-Bpkvzu3U.js","assets/csv-parser-i7fjqP2H.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"./scroll-area-BpXCNme3.js";import{t as i}from"./chevron-right-DY_wImxB.js";import{a,l as o,n as s,o as c,r as l,s as ee,t as u}from"./input-BHj0veau.js";import{n as d,t as f}from"./markdown-renderer-CCq6xBWp.js";import{t as te}from"./database-CgTomMxt.js";import{n as p,r as m}from"./x-Dw3TjeY_.js";import{t as h}from"./table-Bi27fEaN.js";import{t as g}from"./text-wrap-D_OmSzhp.js";import{t as _}from"./preload-helper-mr3rCizq.js";import{t as v}from"./utils-DX8jb5qv.js";import{i as y,r as b,t as x}from"./api-client-BvxmRZUi.js";import{B as S,D as C,E as w,G as T,H as ne,J as re,K as E,O as ie,P as ae,T as D,U as O,W as k,a as oe,c as A,d as j,f as M,h as N,k as se,l as ce,m as le,o as ue,p as P,q as F,u as de}from"./index-DK4yJlIj.js";import"./chunk-GEFDOKGD-86LFbsAC.js";import"./src-CqyWLlNZ.js";import"./chunk-7R4GIKGN-y8bfHEy-.js";import"./chunk-HHEYEP7N-C45i5G_3.js";import"./dist-DZmJeHOA.js";import"./chunk-PU5JKC2W-DD95Rx35.js";import"./chunk-MX3YWQON-B6g1ZH9X.js";import"./chunk-YBOYWFTD-D_ILLe6_.js";import"./chunk-PQ6SQG4A-Bik13fTV.js";import"./chunk-KYZI473N-gqRLpJ4w.js";import"./chunk-O4XLMI2P-Vp_V4P-b.js";import"./chunk-GLR3WWYH-Re-5eSlQ.js";import"./chunk-XPW4576I-CgLyyW03.js";import{n as fe,t as pe}from"./use-monaco-theme-vmoBT6np.js";import{n as me,t as he}from"./sql-completion-provider-B8uUWWej.js";var I=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`}]]),L=e(t(),1),R=r(),z={ts:E,tsx:E,js:E,jsx:E,py:E,rs:E,go:E,html:E,css:E,scss:E,json:F,md:T,txt:T,yaml:k,yml:k};function ge(e,t){return t?ne:z[e.split(`.`).pop()?.toLowerCase()??``]??O}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 _e({filePath:e,projectName:t,tabId:n,className:r}){let a=D(e=>e.tree),{updateTab:o,openTab:s}=w(),c=(0,L.useRef)(null),l=(0,L.useMemo)(()=>B(a,e.split(`/`).filter(Boolean)),[a,e]);(0,L.useEffect)(()=>{c.current&&(c.current.scrollLeft=c.current.scrollWidth)},[l]);function ee(e,r){let i=v(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,R.jsx)(`div`,{ref:c,className:r,children:l.map((e,n)=>(0,R.jsxs)(`div`,{className:`flex items-center shrink-0`,children:[n>0&&(0,R.jsx)(i,{className:`size-3 text-muted-foreground shrink-0 mx-0.5`}),e.siblings.length>0?(0,R.jsx)(H,{segment:e,isLast:n===l.length-1,projectName:t,onFileClick:ee}):(0,R.jsx)(`span`,{className:`text-xs text-muted-foreground px-1 py-0.5`,children:e.name})]},e.fullPath))})}function H({segment:e,isLast:t,projectName:n,onFileClick:r}){let i=(0,L.useMemo)(()=>V(e.siblings),[e.siblings]);return(0,R.jsxs)(A,{children:[(0,R.jsx)(le,{asChild:!0,children:(0,R.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,R.jsx)(ce,{align:`start`,className:`max-h-[300px] p-1`,children:i.map(t=>(0,R.jsx)(U,{node:t,projectName:n,activePath:e.fullPath,onFileClick:r},t.path))})]})}function U({node:e,projectName:t,activePath:n,onFileClick:r}){let i=ge(e.name,e.type===`directory`),a=e.path===n;return e.type===`directory`&&e.children&&e.children.length>0?(0,R.jsxs)(j,{children:[(0,R.jsxs)(P,{className:`text-xs gap-1.5 ${a?`bg-muted`:``}`,children:[(0,R.jsx)(i,{className:`size-3.5 shrink-0 text-muted-foreground`}),(0,R.jsx)(`span`,{className:`truncate`,children:e.name})]}),(0,R.jsx)(M,{className:`max-h-[300px] overflow-y-auto p-1`,children:V(e.children).map(e=>(0,R.jsx)(U,{node:e,projectName:t,activePath:n,onFileClick:r},e.path))})]}):(0,R.jsxs)(de,{className:`text-xs gap-1.5 cursor-pointer ${a?`bg-muted`:``}`,onSelect:e=>{},onClick:t=>{e.type!==`directory`&&r(e.path,t)},children:[(0,R.jsx)(i,{className:`size-3.5 shrink-0 text-muted-foreground`}),(0,R.jsx)(`span`,{className:`truncate`,children:e.name})]})}function W({active:e,onClick:t,icon:n,label:r}){return(0,R.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,R.jsx)(n,{className:`size-3`}),(0,R.jsx)(`span`,{className:`hidden sm:inline`,children:r})]})}function ve({ext:e,mdMode:t,onMdModeChange:n,csvMode:r,onCsvModeChange:i,wordWrap:a,onToggleWordWrap:o,filePath:s,projectName:c,className:l}){return(0,R.jsxs)(`div`,{className:l,children:[(e===`md`||e===`mdx`)&&n&&(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(W,{active:t===`edit`,onClick:()=>n(`edit`),icon:d,label:`Edit`}),(0,R.jsx)(W,{active:t===`preview`,onClick:()=>n(`preview`),icon:p,label:`Preview`})]}),e===`csv`&&i&&(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(W,{active:r===`table`,onClick:()=>i(`table`),icon:h,label:`Table`}),(0,R.jsx)(W,{active:r===`raw`,onClick:()=>i(`raw`),icon:d,label:`Raw`})]}),(0,R.jsx)(W,{active:a,onClick:o,icon:g,label:`Wrap`}),s&&c&&(0,R.jsx)(W,{active:!1,onClick:()=>N(c,s),icon:m,label:`Download`})]})}function ye({open:e,defaultName:t,content:n,onSave:r,onCancel:i}){let[d,f]=(0,L.useState)(t),[te,p]=(0,L.useState)(!1),[m,h]=(0,L.useState)(``),g=C(e=>e.activeProject),_=(0,L.useCallback)(()=>{let e=d.trim();if(!e){h(`Filename cannot be empty`);return}if(/[/\\]/.test(e)){h(`Filename cannot contain / or \\`);return}h(``),p(!0)},[d]),v=(0,L.useCallback)(e=>{let t=e.includes(`\\`)?`\\`:`/`;r(e.endsWith(t)?`${e}${d.trim()}`:`${e}${t}${d.trim()}`,n)},[d,n,r]);return te?(0,R.jsx)(ue,{open:!0,mode:`folder`,root:g?.path,title:`Save "${d.trim()}" to...`,onSelect:v,onCancel:()=>p(!1)}):(0,R.jsx)(s,{open:e,onOpenChange:e=>{e||i()},children:(0,R.jsxs)(l,{className:`sm:max-w-md`,children:[(0,R.jsx)(c,{children:(0,R.jsx)(ee,{children:`Save As`})}),(0,R.jsxs)(`div`,{className:`flex flex-col gap-2 py-2`,children:[(0,R.jsx)(`label`,{className:`text-sm text-muted-foreground`,children:`Filename`}),(0,R.jsx)(u,{value:d,onChange:e=>{f(e.target.value),h(``)},onKeyDown:e=>{e.key===`Enter`&&_()},placeholder:`e.g. my-file.ts`,autoFocus:!0}),m&&(0,R.jsx)(`p`,{className:`text-xs text-destructive`,children:m})]}),(0,R.jsxs)(a,{children:[(0,R.jsx)(o,{variant:`outline`,onClick:i,children:`Cancel`}),(0,R.jsx)(o,{onClick:_,children:`Choose Folder...`})]})]})})}var be=(0,L.lazy)(()=>_(()=>import(`./csv-preview-BZRICDP0.js`).then(e=>({default:e.CsvPreview})),__vite__mapDeps([0,1,2,3,4,5,6,7]))),xe=new Set([`png`,`jpg`,`jpeg`,`gif`,`webp`,`svg`,`ico`]),Se=new Set([`db`,`sqlite`,`sqlite3`]);function Ce(e){return e.split(`.`).pop()?.toLowerCase()??``}function we(e){return{js:`javascript`,jsx:`javascript`,ts:`typescript`,tsx:`typescript`,py:`python`,html:`html`,css:`css`,scss:`scss`,json:`json`,md:`markdown`,mdx:`markdown`,yaml:`yaml`,yml:`yaml`,sh:`shell`,bash:`shell`,sql:`sql`}[Ce(e)]??`plaintext`}function G({metadata:e,tabId:t}){let n=e?.filePath,r=e?.projectName,i=e?.inlineContent,a=e?.inlineLanguage,[o,s]=(0,L.useState)(i??null),[c,l]=(0,L.useState)(`utf-8`),[ee,u]=(0,L.useState)(!0),[d,f]=(0,L.useState)(null),[p,m]=(0,L.useState)(!1),h=(0,L.useRef)(null),g=(0,L.useRef)(``),_=(0,L.useRef)(null),{tabs:b,updateTab:C}=w(),{wordWrap:T,toggleWordWrap:ne}=se(),re=pe(),E=e?.isUntitled===!0,D=e?.unsavedContent,[O,k]=(0,L.useState)(!1),A=b.find(e=>e.id===t),j=n?Ce(n):``,M=xe.has(j),N=j===`pdf`,ce=Se.has(j),le=j===`md`||j===`mdx`,ue=j===`csv`,P=j===`sql`,[F,de]=(0,L.useState)(`preview`),[z,ge]=(0,L.useState)(`table`),{connections:B,cachedTables:V,refreshTables:H}=oe(),[U,W]=(0,L.useState)(()=>{if(!P||!n)return null;let e=localStorage.getItem(`ppm:sql-conn:${n}`);return e?Number(e):null}),G=(0,L.useRef)(null),K=(0,L.useRef)(null),q=(0,L.useMemo)(()=>B.find(e=>e.id===U)??null,[B,U]),Oe=i!=null&&(a===`json`||a===`xml`),[J,ke]=(0,L.useState)(!1),Ae=(0,L.useCallback)(()=>{if(i)if(J)s(i),ke(!1);else{let e=i.trimStart();if(a===`json`)try{s(JSON.stringify(JSON.parse(e),null,2)),ke(!0)}catch{}else if(a===`xml`){let t=0;s(e.replace(/(>)(<)(\/*)/g,`$1
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"./scroll-area-BpXCNme3.js";import{t as i}from"./chevron-right-DY_wImxB.js";import{a,l as o,n as s,o as c,r as l,s as ee,t as u}from"./input-BHj0veau.js";import{n as d,t as f}from"./markdown-renderer-Pch6Q5AB.js";import{t as te}from"./database-CgTomMxt.js";import{n as p,r as m}from"./x-Dw3TjeY_.js";import{t as h}from"./table-Bi27fEaN.js";import{t as g}from"./text-wrap-D_OmSzhp.js";import{t as _}from"./preload-helper-mr3rCizq.js";import{t as v}from"./utils-DX8jb5qv.js";import{i as y,r as b,t as x}from"./api-client-BvxmRZUi.js";import{B as S,D as C,E as w,G as T,H as ne,J as re,K as E,O as ie,P as ae,T as D,U as O,W as k,a as oe,c as A,d as j,f as M,h as N,k as se,l as ce,m as le,o as ue,p as P,q as F,u as de}from"./index-fzSsl_Dg.js";import"./chunk-GEFDOKGD-86LFbsAC.js";import"./src-CqyWLlNZ.js";import"./chunk-7R4GIKGN-y8bfHEy-.js";import"./chunk-HHEYEP7N-C45i5G_3.js";import"./dist-DZmJeHOA.js";import"./chunk-PU5JKC2W-DD95Rx35.js";import"./chunk-MX3YWQON-B6g1ZH9X.js";import"./chunk-YBOYWFTD-D_ILLe6_.js";import"./chunk-PQ6SQG4A-Bik13fTV.js";import"./chunk-KYZI473N-gqRLpJ4w.js";import"./chunk-O4XLMI2P-Vp_V4P-b.js";import"./chunk-GLR3WWYH-Re-5eSlQ.js";import"./chunk-XPW4576I-CgLyyW03.js";import{n as fe,t as pe}from"./use-monaco-theme-BEX-OBkP.js";import{n as me,t as he}from"./sql-completion-provider-B8uUWWej.js";var I=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`}]]),L=e(t(),1),R=r(),z={ts:E,tsx:E,js:E,jsx:E,py:E,rs:E,go:E,html:E,css:E,scss:E,json:F,md:T,txt:T,yaml:k,yml:k};function ge(e,t){return t?ne:z[e.split(`.`).pop()?.toLowerCase()??``]??O}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 _e({filePath:e,projectName:t,tabId:n,className:r}){let a=D(e=>e.tree),{updateTab:o,openTab:s}=w(),c=(0,L.useRef)(null),l=(0,L.useMemo)(()=>B(a,e.split(`/`).filter(Boolean)),[a,e]);(0,L.useEffect)(()=>{c.current&&(c.current.scrollLeft=c.current.scrollWidth)},[l]);function ee(e,r){let i=v(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,R.jsx)(`div`,{ref:c,className:r,children:l.map((e,n)=>(0,R.jsxs)(`div`,{className:`flex items-center shrink-0`,children:[n>0&&(0,R.jsx)(i,{className:`size-3 text-muted-foreground shrink-0 mx-0.5`}),e.siblings.length>0?(0,R.jsx)(H,{segment:e,isLast:n===l.length-1,projectName:t,onFileClick:ee}):(0,R.jsx)(`span`,{className:`text-xs text-muted-foreground px-1 py-0.5`,children:e.name})]},e.fullPath))})}function H({segment:e,isLast:t,projectName:n,onFileClick:r}){let i=(0,L.useMemo)(()=>V(e.siblings),[e.siblings]);return(0,R.jsxs)(A,{children:[(0,R.jsx)(le,{asChild:!0,children:(0,R.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,R.jsx)(ce,{align:`start`,className:`max-h-[300px] p-1`,children:i.map(t=>(0,R.jsx)(U,{node:t,projectName:n,activePath:e.fullPath,onFileClick:r},t.path))})]})}function U({node:e,projectName:t,activePath:n,onFileClick:r}){let i=ge(e.name,e.type===`directory`),a=e.path===n;return e.type===`directory`&&e.children&&e.children.length>0?(0,R.jsxs)(j,{children:[(0,R.jsxs)(P,{className:`text-xs gap-1.5 ${a?`bg-muted`:``}`,children:[(0,R.jsx)(i,{className:`size-3.5 shrink-0 text-muted-foreground`}),(0,R.jsx)(`span`,{className:`truncate`,children:e.name})]}),(0,R.jsx)(M,{className:`max-h-[300px] overflow-y-auto p-1`,children:V(e.children).map(e=>(0,R.jsx)(U,{node:e,projectName:t,activePath:n,onFileClick:r},e.path))})]}):(0,R.jsxs)(de,{className:`text-xs gap-1.5 cursor-pointer ${a?`bg-muted`:``}`,onSelect:e=>{},onClick:t=>{e.type!==`directory`&&r(e.path,t)},children:[(0,R.jsx)(i,{className:`size-3.5 shrink-0 text-muted-foreground`}),(0,R.jsx)(`span`,{className:`truncate`,children:e.name})]})}function W({active:e,onClick:t,icon:n,label:r}){return(0,R.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,R.jsx)(n,{className:`size-3`}),(0,R.jsx)(`span`,{className:`hidden sm:inline`,children:r})]})}function ve({ext:e,mdMode:t,onMdModeChange:n,csvMode:r,onCsvModeChange:i,wordWrap:a,onToggleWordWrap:o,filePath:s,projectName:c,className:l}){return(0,R.jsxs)(`div`,{className:l,children:[(e===`md`||e===`mdx`)&&n&&(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(W,{active:t===`edit`,onClick:()=>n(`edit`),icon:d,label:`Edit`}),(0,R.jsx)(W,{active:t===`preview`,onClick:()=>n(`preview`),icon:p,label:`Preview`})]}),e===`csv`&&i&&(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(W,{active:r===`table`,onClick:()=>i(`table`),icon:h,label:`Table`}),(0,R.jsx)(W,{active:r===`raw`,onClick:()=>i(`raw`),icon:d,label:`Raw`})]}),(0,R.jsx)(W,{active:a,onClick:o,icon:g,label:`Wrap`}),s&&c&&(0,R.jsx)(W,{active:!1,onClick:()=>N(c,s),icon:m,label:`Download`})]})}function ye({open:e,defaultName:t,content:n,onSave:r,onCancel:i}){let[d,f]=(0,L.useState)(t),[te,p]=(0,L.useState)(!1),[m,h]=(0,L.useState)(``),g=C(e=>e.activeProject),_=(0,L.useCallback)(()=>{let e=d.trim();if(!e){h(`Filename cannot be empty`);return}if(/[/\\]/.test(e)){h(`Filename cannot contain / or \\`);return}h(``),p(!0)},[d]),v=(0,L.useCallback)(e=>{let t=e.includes(`\\`)?`\\`:`/`;r(e.endsWith(t)?`${e}${d.trim()}`:`${e}${t}${d.trim()}`,n)},[d,n,r]);return te?(0,R.jsx)(ue,{open:!0,mode:`folder`,root:g?.path,title:`Save "${d.trim()}" to...`,onSelect:v,onCancel:()=>p(!1)}):(0,R.jsx)(s,{open:e,onOpenChange:e=>{e||i()},children:(0,R.jsxs)(l,{className:`sm:max-w-md`,children:[(0,R.jsx)(c,{children:(0,R.jsx)(ee,{children:`Save As`})}),(0,R.jsxs)(`div`,{className:`flex flex-col gap-2 py-2`,children:[(0,R.jsx)(`label`,{className:`text-sm text-muted-foreground`,children:`Filename`}),(0,R.jsx)(u,{value:d,onChange:e=>{f(e.target.value),h(``)},onKeyDown:e=>{e.key===`Enter`&&_()},placeholder:`e.g. my-file.ts`,autoFocus:!0}),m&&(0,R.jsx)(`p`,{className:`text-xs text-destructive`,children:m})]}),(0,R.jsxs)(a,{children:[(0,R.jsx)(o,{variant:`outline`,onClick:i,children:`Cancel`}),(0,R.jsx)(o,{onClick:_,children:`Choose Folder...`})]})]})})}var be=(0,L.lazy)(()=>_(()=>import(`./csv-preview-BZRICDP0.js`).then(e=>({default:e.CsvPreview})),__vite__mapDeps([0,1,2,3,4,5,6,7]))),xe=new Set([`png`,`jpg`,`jpeg`,`gif`,`webp`,`svg`,`ico`]),Se=new Set([`db`,`sqlite`,`sqlite3`]);function Ce(e){return e.split(`.`).pop()?.toLowerCase()??``}function we(e){return{js:`javascript`,jsx:`javascript`,ts:`typescript`,tsx:`typescript`,py:`python`,html:`html`,css:`css`,scss:`scss`,json:`json`,md:`markdown`,mdx:`markdown`,yaml:`yaml`,yml:`yaml`,sh:`shell`,bash:`shell`,sql:`sql`}[Ce(e)]??`plaintext`}function G({metadata:e,tabId:t}){let n=e?.filePath,r=e?.projectName,i=e?.inlineContent,a=e?.inlineLanguage,[o,s]=(0,L.useState)(i??null),[c,l]=(0,L.useState)(`utf-8`),[ee,u]=(0,L.useState)(!0),[d,f]=(0,L.useState)(null),[p,m]=(0,L.useState)(!1),h=(0,L.useRef)(null),g=(0,L.useRef)(``),_=(0,L.useRef)(null),{tabs:b,updateTab:C}=w(),{wordWrap:T,toggleWordWrap:ne}=se(),re=pe(),E=e?.isUntitled===!0,D=e?.unsavedContent,[O,k]=(0,L.useState)(!1),A=b.find(e=>e.id===t),j=n?Ce(n):``,M=xe.has(j),N=j===`pdf`,ce=Se.has(j),le=j===`md`||j===`mdx`,ue=j===`csv`,P=j===`sql`,[F,de]=(0,L.useState)(`preview`),[z,ge]=(0,L.useState)(`table`),{connections:B,cachedTables:V,refreshTables:H}=oe(),[U,W]=(0,L.useState)(()=>{if(!P||!n)return null;let e=localStorage.getItem(`ppm:sql-conn:${n}`);return e?Number(e):null}),G=(0,L.useRef)(null),K=(0,L.useRef)(null),q=(0,L.useMemo)(()=>B.find(e=>e.id===U)??null,[B,U]),Oe=i!=null&&(a===`json`||a===`xml`),[J,ke]=(0,L.useState)(!1),Ae=(0,L.useCallback)(()=>{if(i)if(J)s(i),ke(!1);else{let e=i.trimStart();if(a===`json`)try{s(JSON.stringify(JSON.parse(e),null,2)),ke(!0)}catch{}else if(a===`xml`){let t=0;s(e.replace(/(>)(<)(\/*)/g,`$1
3
3
  $2$3`).split(`
4
4
  `).map(e=>{let n=e.trim();n.startsWith(`</`)&&(t=Math.max(0,t-1));let r=` `.repeat(t)+n;return n.startsWith(`<`)&&!n.startsWith(`</`)&&!n.endsWith(`/>`)&&!n.includes(`</`)&&t++,r}).join(`
5
5
  `)),ke(!0)}}},[i,a,J]),je=(0,L.useCallback)(e=>{W(e),n&&localStorage.setItem(`ppm:sql-conn:${n}`,String(e)),H(e).catch(()=>{})},[n,H]),Y=(0,L.useMemo)(()=>{if(!P||!U)return;let e=(V.get(U)??[]).map(e=>({name:e.tableName,schema:e.schemaName}));if(e.length!==0)return{tables:e,getColumns:async(e,t)=>x.get(`/api/db/connections/${U}/schema?table=${encodeURIComponent(e)}${t?`&schema=${encodeURIComponent(t)}`:``}`)}},[P,U,V]);(0,L.useEffect)(()=>{if(!(!G.current||!Y))return K.current?.dispose(),he(),K.current=G.current.languages.registerCompletionItemProvider(`sql`,me(G.current,Y)),()=>{K.current?.dispose()}},[Y]);let Me=w(e=>e.openTab),X=(0,L.useCallback)(e=>{q&&Me({type:`database`,title:`${q.name} · Query`,projectId:null,closable:!0,metadata:{connectionId:q.id,connectionName:q.name,dbType:q.type,initialSql:e}})},[q,Me]),Ne=(0,L.useCallback)(()=>{if(!_.current||!q)return;let e=_.current,t=e.getSelection();X(t&&!t.isEmpty()?e.getModel()?.getValueInRange(t)??e.getValue():e.getValue())},[q,X]),Z=(0,L.useRef)([]),Pe=(0,L.useRef)(X);Pe.current=X,(0,L.useEffect)(()=>()=>{Z.current.forEach(e=>e.dispose()),Z.current=[]},[]),(0,L.useEffect)(()=>{ce&&t&&C(t,{type:`sqlite`})},[ce,t,C]);let Q=n?/^(\/|[A-Za-z]:[/\\])/.test(n):!1;(0,L.useEffect)(()=>{if(i!=null){u(!1);return}if(E){s(D??``),g.current=D??``,u(!1),D&&m(!0);return}if(!n||!Q&&!r)return;if(M||N){u(!1);return}u(!0),f(null);let e=Q?`/api/fs/read?path=${encodeURIComponent(n)}`:`${y(r)}/files/read?path=${encodeURIComponent(n)}`;return x.get(e).then(e=>{s(e.content),e.encoding&&l(e.encoding),g.current=e.content,u(!1)}).catch(e=>{f(e instanceof Error?e.message:`Failed to load file`),u(!1)}),()=>{h.current&&clearTimeout(h.current)}},[n,r,M,N,Q,E]),(0,L.useEffect)(()=>{if(!A)return;let t=E?`Untitled-${e?.untitledNumber??1}`:n?v(n):`Untitled`,r=p?`${t} \u25CF`:t;A.title!==r&&C(A.id,{title:r})},[p]);let Fe=(0,L.useCallback)(async e=>{if(n&&!(!Q&&!r))try{Q?await x.put(`/api/fs/write`,{path:n,content:e}):await x.put(`${y(r)}/files/write`,{path:n,content:e}),m(!1)}catch{}},[n,r,Q]);function Ie(n){let r=n??``;s(r),g.current=r,m(!0),h.current&&clearTimeout(h.current),E?h.current=setTimeout(()=>{t&&C(t,{metadata:{...e,unsavedContent:g.current}})},2e3):h.current=setTimeout(()=>Fe(g.current),1e3)}let Le=(0,L.useCallback)(async(e,n)=>{try{if(h.current&&clearTimeout(h.current),await x.put(`/api/fs/write`,{path:e,content:n}),t){let{closeTab:n,openTab:r}=ie.getState();n(t),r({type:`editor`,title:v(e),projectId:null,metadata:{filePath:e},closable:!0})}m(!1),k(!1)}catch{}},[t]),$=e?.lineNumber,Re=(0,L.useCallback)((e,t)=>{if(_.current=e,G.current=t,$&&$>0&&setTimeout(()=>{e.revealLineInCenter($),e.setPosition({lineNumber:$,column:1}),e.focus()},100),E&&e.addCommand(t.KeyMod.CtrlCmd|t.KeyCode.KeyS,()=>k(!0)),e.addCommand(t.KeyMod.Alt|t.KeyCode.KeyZ,()=>se.getState().toggleWordWrap()),t.languages.typescript.typescriptDefaults.setDiagnosticsOptions({noSemanticValidation:!0,noSyntaxValidation:!0,noSuggestionDiagnostics:!0}),t.languages.typescript.javascriptDefaults.setDiagnosticsOptions({noSemanticValidation:!0,noSyntaxValidation:!0,noSuggestionDiagnostics:!0}),Y&&(K.current?.dispose(),K.current=t.languages.registerCompletionItemProvider(`sql`,me(t,Y))),P){Z.current.forEach(e=>e.dispose()),Z.current=[];let n=e.getModel(),r=e.addCommand(0,(e,t)=>{t&&Pe.current(t)});if(r&&n){let e=t.languages.registerCodeLensProvider(`sql`,{provideCodeLenses:e=>{if(e!==n)return{lenses:[],dispose:()=>{}};let t=[],i=e.getValue().split(`
@@ -1,4 +1,4 @@
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{i as r,t as i}from"./api-client-BvxmRZUi.js";import{B as a,k as o}from"./index-DK4yJlIj.js";import{n as s,t as c}from"./use-monaco-theme-vmoBT6np.js";var l=e(t(),1),u=n();function d(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`,go:`go`,rs:`rust`,java:`java`,rb:`ruby`,php:`php`,swift:`swift`,sql:`sql`,xml:`xml`,toml:`toml`}[e.split(`.`).pop()?.toLowerCase()??``]??`plaintext`}function f(e){let t=e.split(`
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{i as r,t as i}from"./api-client-BvxmRZUi.js";import{B as a,k as o}from"./index-fzSsl_Dg.js";import{n as s,t as c}from"./use-monaco-theme-BEX-OBkP.js";var l=e(t(),1),u=n();function d(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`,go:`go`,rs:`rust`,java:`java`,rb:`ruby`,php:`php`,swift:`swift`,sql:`sql`,xml:`xml`,toml:`toml`}[e.split(`.`).pop()?.toLowerCase()??``]??`plaintext`}function f(e){let t=e.split(`
2
2
  `),n=[],r=0,i=0;for(;r<t.length;){let e=t[r];if(e.startsWith(`<<<<<<<`)){let a=r,o=e.substring(7).trim(),s=[];for(r++;r<t.length&&!t[r].startsWith(`=======`);)s.push(t[r]),r++;if(r>=t.length)break;let c=r,l=[];for(r++;r<t.length&&!t[r].startsWith(`>>>>>>>`);)l.push(t[r]),r++;if(r>=t.length)break;let u=t[r].substring(7).trim();n.push({id:i++,startLine:a+1,separatorLine:c+1,endLine:r+1,currentContent:s.join(`
3
3
  `),incomingContent:l.join(`
4
4
  `),currentLabel:o,incomingLabel:u})}r++}return n}function p({metadata:e}){let t=e?.filePath,n=e?.projectName,[p,h]=(0,l.useState)(null),[g,_]=(0,l.useState)(!0),[v,y]=(0,l.useState)(null),[b,x]=(0,l.useState)(0),S=(0,l.useRef)(null),C=(0,l.useRef)(null),w=(0,l.useRef)([]),T=(0,l.useRef)(null),{wordWrap:E}=o(),D=c(),O=(0,l.useRef)(null),[k,A]=(0,l.useState)();(0,l.useEffect)(()=>{let e=O.current;if(!e)return;let t=new ResizeObserver(([e])=>{e&&A(Math.floor(e.contentRect.height))});return t.observe(e),()=>t.disconnect()},[]),(0,l.useEffect)(()=>{!t||!n||(_(!0),i.get(`${r(n)}/files/read?path=${encodeURIComponent(t)}`).then(e=>{h(e.content),_(!1)}).catch(e=>{y(e.message||`Failed to load file`),_(!1)}))},[t,n]);let j=(0,l.useCallback)(()=>{let e=S.current,t=C.current;if(!e||!t)return;let n=f(e.getModel()?.getValue()||``);x(n.length);for(let t of w.current)e.removeContentWidget(t);if(w.current=[],T.current&&T.current.clear(),n.length===0)return;let r=[];for(let e of n)r.push({range:new t.Range(e.startLine,1,e.startLine,1),options:{isWholeLine:!0,className:`conflict-marker-line`,glyphMarginClassName:`conflict-glyph-current`}}),r.push({range:new t.Range(e.separatorLine,1,e.separatorLine,1),options:{isWholeLine:!0,className:`conflict-marker-line`}}),r.push({range:new t.Range(e.endLine,1,e.endLine,1),options:{isWholeLine:!0,className:`conflict-marker-line`,glyphMarginClassName:`conflict-glyph-incoming`}}),e.separatorLine-e.startLine>1&&r.push({range:new t.Range(e.startLine+1,1,e.separatorLine-1,1),options:{isWholeLine:!0,className:`conflict-current-content`}}),e.endLine-e.separatorLine>1&&r.push({range:new t.Range(e.separatorLine+1,1,e.endLine-1,1),options:{isWholeLine:!0,className:`conflict-incoming-content`}});T.current=e.createDecorationsCollection(r);for(let r of n){let n=`conflict-widget-${r.id}`,i=document.createElement(`div`);i.className=`conflict-actions`,i.innerHTML=`<span class="conflict-label">Current Change (${m(r.currentLabel||`HEAD`)})</span><button class="conflict-btn conflict-btn-current" data-action="current">Accept Current</button><button class="conflict-btn conflict-btn-incoming" data-action="incoming">Accept Incoming</button><button class="conflict-btn conflict-btn-both" data-action="both">Accept Both</button>`,i.addEventListener(`click`,e=>{let t=e.target.closest(`[data-action]`);if(!t)return;let n=t.getAttribute(`data-action`);M(r.id,n)});let a={getId:()=>n,getDomNode:()=>i,getPosition:()=>({position:{lineNumber:r.startLine,column:1},preference:[t.editor.ContentWidgetPositionPreference.ABOVE]})};e.addContentWidget(a),w.current.push(a)}},[]),M=(0,l.useCallback)((e,t)=>{let n=S.current,r=C.current;if(!n||!r)return;let i=n.getModel();if(!i)return;let a=f(i.getValue()).find(t=>t.id===e);if(!a)return;let o;switch(t){case`current`:o=a.currentContent;break;case`incoming`:o=a.incomingContent;break;case`both`:o=a.currentContent+`
@@ -1,2 +1,2 @@
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{n as i,r as a,t as o}from"./plus-DQGIb4mQ.js";import{t as s}from"./chevron-right-DY_wImxB.js";import{t as c}from"./database-CgTomMxt.js";import{n as l,r as u,t as d}from"./x-Dw3TjeY_.js";import{t as f}from"./refresh-cw-Clk8fdUD.js";import{t as p}from"./trash-2-CNuB-htI.js";import{t as m}from"./api-client-BvxmRZUi.js";import{$ as h,B as g,E as _,F as v,I as y,N as b,V as x}from"./index-DK4yJlIj.js";import"./use-monaco-theme-vmoBT6np.js";import{t as S}from"./sql-query-editor-CxODOF9o.js";import{n as C}from"./csv-parser-i7fjqP2H.js";var w=n(`columns-3`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M9 3v18`,key:`fh3hqa`}],[`path`,{d:`M15 3v18`,key:`14nvp0`}]]),T=n(`funnel`,[[`path`,{d:`M10 20a1 1 0 0 0 .553.895l2 1A1 1 0 0 0 14 21v-7a2 2 0 0 1 .517-1.341L21.74 4.67A1 1 0 0 0 21 3H3a1 1 0 0 0-.742 1.67l7.225 7.989A2 2 0 0 1 10 14z`,key:`sc7q7i`}]]),E=e(t(),1);function D(e,t,n,r){return`ppm-db-${e}-${n}.${t}-p${r}`}function O(e,t,n,r){try{let i=sessionStorage.getItem(D(e,t,n,r));return i?JSON.parse(i):null}catch{return null}}function ee(e,t,n,r,i,a){try{sessionStorage.setItem(D(e,t,n,r),JSON.stringify({data:i,cols:a}))}catch{}}function k(e){let t=`/api/db/connections/${e}`,[n,r]=(0,E.useState)(null),[i,a]=(0,E.useState)(`public`),[o,s]=(0,E.useState)(null),[c,l]=(0,E.useState)([]),[u,d]=(0,E.useState)(!1),[f,p]=(0,E.useState)(null),[h,g]=(0,E.useState)(1),[_,v]=(0,E.useState)(null),[y,b]=(0,E.useState)(null),[x,S]=(0,E.useState)(!1),[C,w]=(0,E.useState)(null),[T,D]=(0,E.useState)(`ASC`),k=(0,E.useCallback)(async(r,a,o,c,u)=>{let f=r??n,g=a??i;if(!f)return;d(!0);let _=c===void 0?C:c,v=u??T;try{let n=_?`&orderBy=${encodeURIComponent(_)}&orderDir=${v}`:``,[r,i]=await Promise.all([m.get(`${t}/data?table=${encodeURIComponent(f)}&schema=${g}&page=${o??h}&limit=100${n}`),m.get(`${t}/schema?table=${encodeURIComponent(f)}&schema=${g}`)]);s(r),l(i),ee(e,f,g,o??h,r,i)}catch(e){p(e.message)}finally{d(!1)}},[t,e,n,i,h,C,T]),A=(0,E.useCallback)((t,n=`public`)=>{r(t),a(n),g(1),v(null);let i=O(e,t,n,1);i?(s(i.data),l(i.cols),d(!1),k(t,n,1)):k(t,n,1)},[e,k]),j=(0,E.useCallback)(e=>{g(e),k(void 0,void 0,e)},[k]),te=(0,E.useCallback)(async e=>{S(!0),b(null);try{let r=await m.post(`${t}/query`,{sql:e});v(r),r.changeType===`modify`&&k(n??void 0,i)}catch(e){b(e.message)}finally{S(!1)}},[t,n,i,k]),M=(0,E.useCallback)(async(e,r,a,o)=>{if(!n)return;let s=n,c=i;try{await m.put(`${t}/cell`,{table:s,schema:c,pkColumn:e,pkValue:r,column:a,value:o}),k(s,c)}catch(e){p(e.message)}},[t,n,i,k]),N=(0,E.useCallback)(async(e,r)=>{if(!n)return;let a=n,o=i;try{await m.del(`${t}/row`,{table:a,schema:o,pkColumn:e,pkValue:r}),k(a,o)}catch(e){p(e.message)}},[t,n,i,k]);return{selectedTable:n,selectedSchema:i,selectTable:A,tableData:o,schema:c,loading:u,error:f,page:h,setPage:j,orderBy:C,orderDir:T,toggleSort:(0,E.useCallback)(e=>{let t,n=`ASC`;C===e?T===`ASC`?(t=e,n=`DESC`):(t=null,n=`ASC`):(t=e,n=`ASC`),w(t),D(n),g(1),k(void 0,void 0,1,t,n)},[C,T,k]),queryResult:_,queryError:y,queryLoading:x,executeQuery:te,updateCell:M,deleteRow:N,bulkDelete:(0,E.useCallback)(async(e,r)=>{if(!n)return;let a=n,o=i;try{await m.post(`${t}/rows/delete`,{table:a,schema:o,pkColumn:e,pkValues:r}),k(a,o)}catch(e){p(e.message)}},[t,n,i,k]),insertRow:(0,E.useCallback)(async e=>{if(!n)return;let r=n,a=i;try{await m.post(`${t}/row`,{table:r,schema:a,values:e}),k(r,a)}catch(e){throw p(e.message),e}},[t,n,i,k]),refreshData:k,queryAsTable:(0,E.useCallback)(async e=>{d(!0);try{let n=await m.post(`${t}/query`,{sql:e});n.changeType===`select`&&s({columns:n.columns,rows:n.rows,total:n.rows.length,page:1,limit:n.rows.length})}catch(e){p(e.message)}finally{d(!1)}},[t])}}var A=r();function j(e,t,n){let r=new Blob([t],{type:n}),i=URL.createObjectURL(r),a=document.createElement(`a`);a.href=i,a.download=e,a.click(),URL.revokeObjectURL(i)}function te({columns:e,rows:t,filename:n=`export`,exportAllUrl:r}){let[i,a]=(0,E.useState)(!1),[o,s]=(0,E.useState)(!1),c=(0,E.useRef)(null);(0,E.useEffect)(()=>{if(!i)return;let e=e=>{c.current&&!c.current.contains(e.target)&&a(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[i]);let l=()=>{let r=C(e,t.map(t=>e.map(e=>String(t[e]??``))));j(`${n}.csv`,r,`text/csv`),a(!1)},d=()=>{let e=JSON.stringify(t,null,2);j(`${n}.json`,e,`application/json`),a(!1)},f=async e=>{if(r){s(!0);try{let t=await(await fetch(`${r}&format=${e}&limit=10000`)).text(),i=e===`csv`?`text/csv`:`application/json`;j(`${n}-all.${e}`,t,i)}catch{}s(!1),a(!1)}};return e.length===0||t.length===0?null:(0,A.jsxs)(`div`,{className:`relative`,ref:c,children:[(0,A.jsx)(`button`,{type:`button`,onClick:()=>a(e=>!e),className:`p-1 rounded text-muted-foreground hover:text-foreground transition-colors`,title:`Export`,children:(0,A.jsx)(u,{className:`size-3.5`})}),i&&(0,A.jsxs)(`div`,{className:`absolute right-0 top-full mt-1 z-50 bg-popover border border-border rounded-md shadow-md py-1 min-w-[160px] text-xs`,children:[(0,A.jsx)(`button`,{onClick:l,className:`w-full text-left px-3 py-1.5 hover:bg-muted transition-colors`,children:`Export Page (CSV)`}),(0,A.jsx)(`button`,{onClick:d,className:`w-full text-left px-3 py-1.5 hover:bg-muted transition-colors`,children:`Export Page (JSON)`}),r&&(0,A.jsxs)(A.Fragment,{children:[(0,A.jsx)(`div`,{className:`border-t border-border my-1`}),(0,A.jsx)(`button`,{onClick:()=>f(`csv`),disabled:o,className:`w-full text-left px-3 py-1.5 hover:bg-muted transition-colors disabled:opacity-50`,children:o?`Exporting…`:`Export All (CSV)`}),(0,A.jsx)(`button`,{onClick:()=>f(`json`),disabled:o,className:`w-full text-left px-3 py-1.5 hover:bg-muted transition-colors disabled:opacity-50`,children:o?`Exporting…`:`Export All (JSON)`})]})]})]})}function M({tableData:e,schema:t,loading:n,page:r,onPageChange:c,onCellUpdate:l,onRowDelete:u,orderBy:f,orderDir:m,onToggleSort:x,onBulkDelete:S,onInsertRow:C,connectionId:D,selectedTable:O,selectedSchema:ee,connectionName:k,columnFilters:j={},onColumnFilter:M}){let[N,P]=(0,E.useState)(null),[F,I]=(0,E.useState)(``),[L,R]=(0,E.useState)(null),[z,ae]=(0,E.useState)(``),[B,V]=(0,E.useState)(new Set),[oe,se]=(0,E.useState)(!1),[ce,le]=(0,E.useState)({}),[ue,de]=(0,E.useState)(null),[fe,pe]=(0,E.useState)(!1),{openTab:H}=_(),me=(0,E.useCallback)(e=>{H({type:`editor`,title:e.col,projectId:null,closable:!0,metadata:{inlineContent:e.value,inlineLanguage:ne(e.value)}})},[H]),[U,he]=(0,E.useState)(new Set),[ge,_e]=(0,E.useState)(new Set),[ve,ye]=(0,E.useState)(null),[be,W]=(0,E.useState)(!1),xe=(0,E.useRef)(null),G=(0,E.useMemo)(()=>t.find(e=>e.pk)?.name||(t.find(e=>e.name.toLowerCase()===`id`)?.name??null),[t]),Se=(0,E.useCallback)(e=>{let t=JSON.stringify(e,null,2),n=G?String(e[G]??``):``;H({type:`editor`,title:n?`Row ${n}`:`Row`,projectId:null,closable:!0,metadata:{inlineContent:t,inlineLanguage:`json`}})},[H,G]),Ce=(0,E.useRef)(N);Ce.current=N;let K=(0,E.useRef)(F);K.current=F;let we=(0,E.useRef)(B);we.current=B;let Te=(0,E.useRef)(L);Te.current=L;let Ee=(0,E.useCallback)((e,t,n)=>{P({rowIdx:e,col:t}),I(n==null?``:typeof n==`object`?JSON.stringify(n):String(n))},[]),De=(0,E.useCallback)(()=>{let t=Ce.current;if(!t||!e||!G)return;let n=e.rows[t.rowIdx];if(!n)return;let r=n[t.col];String(r??``)!==K.current&&l(G,n[G],t.col,K.current===``?null:K.current),P(null)},[e,G,l]),Oe=(0,E.useCallback)(()=>P(null),[]),ke=(0,E.useCallback)(t=>{if(!e||!G||!u)return;let n=e.rows[t];n&&(u(G,n[G]),R(null))},[e,G,u]),Ae=(0,E.useCallback)(e=>{he(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),je=(0,E.useCallback)(e=>{_e(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),Me=(0,E.useCallback)((e,t)=>{let n={...j};t?n[e]=t:delete n[e],M?.(n)},[j,M]),Ne=(0,E.useCallback)(e=>{V(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),Pe=(0,E.useCallback)(()=>{e&&V(t=>t.size===e.rows.length?new Set:new Set(e.rows.map((e,t)=>t)))},[e]),Fe=(0,E.useCallback)(()=>{!e||!G||!S||(S(G,Array.from(B).map(t=>e.rows[t]?.[G]).filter(e=>e!=null)),V(new Set),pe(!1))},[e,G,S,B]),Ie=(0,E.useCallback)(async()=>{if(C){de(null);try{let e={};for(let[t,n]of Object.entries(ce))n!==``&&(e[t]=n);await C(e),se(!1),le({})}catch(e){de(e.message)}}},[C,ce]),q=(0,E.useMemo)(()=>{if(!e||!z)return e?.rows??[];let t=z.toLowerCase();return e.rows.filter(n=>e.columns.some(e=>String(n[e]??``).toLowerCase().includes(t)))},[e,z]),Le=(0,E.useRef)(null);(0,E.useEffect)(()=>{let t=Le.current;if(!t)return;let n=t=>{if(t.key===`Escape`){W(!1);return}let n=t.target?.tagName;if(!(n===`INPUT`||n===`TEXTAREA`)){if(t.key===`/`){t.preventDefault(),W(!0);return}if(!(!(t.metaKey||t.ctrlKey)||!e)&&(t.key===`a`&&(t.preventDefault(),V(new Set(e.rows.map((e,t)=>t)))),t.key===`c`&&B.size>0)){t.preventDefault();let n=e.columns,r=n.join(` `),i=Array.from(B).sort((e,t)=>e-t).map(t=>n.map(n=>{let r=e.rows[t]?.[n];return r==null?``:typeof r==`object`?JSON.stringify(r):String(r)}).join(` `));navigator.clipboard.writeText([r,...i].join(`
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{n as i,r as a,t as o}from"./plus-DQGIb4mQ.js";import{t as s}from"./chevron-right-DY_wImxB.js";import{t as c}from"./database-CgTomMxt.js";import{n as l,r as u,t as d}from"./x-Dw3TjeY_.js";import{t as f}from"./refresh-cw-Clk8fdUD.js";import{t as p}from"./trash-2-CNuB-htI.js";import{t as m}from"./api-client-BvxmRZUi.js";import{$ as h,B as g,E as _,F as v,I as y,N as b,V as x}from"./index-fzSsl_Dg.js";import"./use-monaco-theme-BEX-OBkP.js";import{t as S}from"./sql-query-editor-DkBHKM2i.js";import{n as C}from"./csv-parser-i7fjqP2H.js";var w=n(`columns-3`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M9 3v18`,key:`fh3hqa`}],[`path`,{d:`M15 3v18`,key:`14nvp0`}]]),T=n(`funnel`,[[`path`,{d:`M10 20a1 1 0 0 0 .553.895l2 1A1 1 0 0 0 14 21v-7a2 2 0 0 1 .517-1.341L21.74 4.67A1 1 0 0 0 21 3H3a1 1 0 0 0-.742 1.67l7.225 7.989A2 2 0 0 1 10 14z`,key:`sc7q7i`}]]),E=e(t(),1);function D(e,t,n,r){return`ppm-db-${e}-${n}.${t}-p${r}`}function O(e,t,n,r){try{let i=sessionStorage.getItem(D(e,t,n,r));return i?JSON.parse(i):null}catch{return null}}function ee(e,t,n,r,i,a){try{sessionStorage.setItem(D(e,t,n,r),JSON.stringify({data:i,cols:a}))}catch{}}function k(e){let t=`/api/db/connections/${e}`,[n,r]=(0,E.useState)(null),[i,a]=(0,E.useState)(`public`),[o,s]=(0,E.useState)(null),[c,l]=(0,E.useState)([]),[u,d]=(0,E.useState)(!1),[f,p]=(0,E.useState)(null),[h,g]=(0,E.useState)(1),[_,v]=(0,E.useState)(null),[y,b]=(0,E.useState)(null),[x,S]=(0,E.useState)(!1),[C,w]=(0,E.useState)(null),[T,D]=(0,E.useState)(`ASC`),k=(0,E.useCallback)(async(r,a,o,c,u)=>{let f=r??n,g=a??i;if(!f)return;d(!0);let _=c===void 0?C:c,v=u??T;try{let n=_?`&orderBy=${encodeURIComponent(_)}&orderDir=${v}`:``,[r,i]=await Promise.all([m.get(`${t}/data?table=${encodeURIComponent(f)}&schema=${g}&page=${o??h}&limit=100${n}`),m.get(`${t}/schema?table=${encodeURIComponent(f)}&schema=${g}`)]);s(r),l(i),ee(e,f,g,o??h,r,i)}catch(e){p(e.message)}finally{d(!1)}},[t,e,n,i,h,C,T]),A=(0,E.useCallback)((t,n=`public`)=>{r(t),a(n),g(1),v(null);let i=O(e,t,n,1);i?(s(i.data),l(i.cols),d(!1),k(t,n,1)):k(t,n,1)},[e,k]),j=(0,E.useCallback)(e=>{g(e),k(void 0,void 0,e)},[k]),te=(0,E.useCallback)(async e=>{S(!0),b(null);try{let r=await m.post(`${t}/query`,{sql:e});v(r),r.changeType===`modify`&&k(n??void 0,i)}catch(e){b(e.message)}finally{S(!1)}},[t,n,i,k]),M=(0,E.useCallback)(async(e,r,a,o)=>{if(!n)return;let s=n,c=i;try{await m.put(`${t}/cell`,{table:s,schema:c,pkColumn:e,pkValue:r,column:a,value:o}),k(s,c)}catch(e){p(e.message)}},[t,n,i,k]),N=(0,E.useCallback)(async(e,r)=>{if(!n)return;let a=n,o=i;try{await m.del(`${t}/row`,{table:a,schema:o,pkColumn:e,pkValue:r}),k(a,o)}catch(e){p(e.message)}},[t,n,i,k]);return{selectedTable:n,selectedSchema:i,selectTable:A,tableData:o,schema:c,loading:u,error:f,page:h,setPage:j,orderBy:C,orderDir:T,toggleSort:(0,E.useCallback)(e=>{let t,n=`ASC`;C===e?T===`ASC`?(t=e,n=`DESC`):(t=null,n=`ASC`):(t=e,n=`ASC`),w(t),D(n),g(1),k(void 0,void 0,1,t,n)},[C,T,k]),queryResult:_,queryError:y,queryLoading:x,executeQuery:te,updateCell:M,deleteRow:N,bulkDelete:(0,E.useCallback)(async(e,r)=>{if(!n)return;let a=n,o=i;try{await m.post(`${t}/rows/delete`,{table:a,schema:o,pkColumn:e,pkValues:r}),k(a,o)}catch(e){p(e.message)}},[t,n,i,k]),insertRow:(0,E.useCallback)(async e=>{if(!n)return;let r=n,a=i;try{await m.post(`${t}/row`,{table:r,schema:a,values:e}),k(r,a)}catch(e){throw p(e.message),e}},[t,n,i,k]),refreshData:k,queryAsTable:(0,E.useCallback)(async e=>{d(!0);try{let n=await m.post(`${t}/query`,{sql:e});n.changeType===`select`&&s({columns:n.columns,rows:n.rows,total:n.rows.length,page:1,limit:n.rows.length})}catch(e){p(e.message)}finally{d(!1)}},[t])}}var A=r();function j(e,t,n){let r=new Blob([t],{type:n}),i=URL.createObjectURL(r),a=document.createElement(`a`);a.href=i,a.download=e,a.click(),URL.revokeObjectURL(i)}function te({columns:e,rows:t,filename:n=`export`,exportAllUrl:r}){let[i,a]=(0,E.useState)(!1),[o,s]=(0,E.useState)(!1),c=(0,E.useRef)(null);(0,E.useEffect)(()=>{if(!i)return;let e=e=>{c.current&&!c.current.contains(e.target)&&a(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[i]);let l=()=>{let r=C(e,t.map(t=>e.map(e=>String(t[e]??``))));j(`${n}.csv`,r,`text/csv`),a(!1)},d=()=>{let e=JSON.stringify(t,null,2);j(`${n}.json`,e,`application/json`),a(!1)},f=async e=>{if(r){s(!0);try{let t=await(await fetch(`${r}&format=${e}&limit=10000`)).text(),i=e===`csv`?`text/csv`:`application/json`;j(`${n}-all.${e}`,t,i)}catch{}s(!1),a(!1)}};return e.length===0||t.length===0?null:(0,A.jsxs)(`div`,{className:`relative`,ref:c,children:[(0,A.jsx)(`button`,{type:`button`,onClick:()=>a(e=>!e),className:`p-1 rounded text-muted-foreground hover:text-foreground transition-colors`,title:`Export`,children:(0,A.jsx)(u,{className:`size-3.5`})}),i&&(0,A.jsxs)(`div`,{className:`absolute right-0 top-full mt-1 z-50 bg-popover border border-border rounded-md shadow-md py-1 min-w-[160px] text-xs`,children:[(0,A.jsx)(`button`,{onClick:l,className:`w-full text-left px-3 py-1.5 hover:bg-muted transition-colors`,children:`Export Page (CSV)`}),(0,A.jsx)(`button`,{onClick:d,className:`w-full text-left px-3 py-1.5 hover:bg-muted transition-colors`,children:`Export Page (JSON)`}),r&&(0,A.jsxs)(A.Fragment,{children:[(0,A.jsx)(`div`,{className:`border-t border-border my-1`}),(0,A.jsx)(`button`,{onClick:()=>f(`csv`),disabled:o,className:`w-full text-left px-3 py-1.5 hover:bg-muted transition-colors disabled:opacity-50`,children:o?`Exporting…`:`Export All (CSV)`}),(0,A.jsx)(`button`,{onClick:()=>f(`json`),disabled:o,className:`w-full text-left px-3 py-1.5 hover:bg-muted transition-colors disabled:opacity-50`,children:o?`Exporting…`:`Export All (JSON)`})]})]})]})}function M({tableData:e,schema:t,loading:n,page:r,onPageChange:c,onCellUpdate:l,onRowDelete:u,orderBy:f,orderDir:m,onToggleSort:x,onBulkDelete:S,onInsertRow:C,connectionId:D,selectedTable:O,selectedSchema:ee,connectionName:k,columnFilters:j={},onColumnFilter:M}){let[N,P]=(0,E.useState)(null),[F,I]=(0,E.useState)(``),[L,R]=(0,E.useState)(null),[z,ae]=(0,E.useState)(``),[B,V]=(0,E.useState)(new Set),[oe,se]=(0,E.useState)(!1),[ce,le]=(0,E.useState)({}),[ue,de]=(0,E.useState)(null),[fe,pe]=(0,E.useState)(!1),{openTab:H}=_(),me=(0,E.useCallback)(e=>{H({type:`editor`,title:e.col,projectId:null,closable:!0,metadata:{inlineContent:e.value,inlineLanguage:ne(e.value)}})},[H]),[U,he]=(0,E.useState)(new Set),[ge,_e]=(0,E.useState)(new Set),[ve,ye]=(0,E.useState)(null),[be,W]=(0,E.useState)(!1),xe=(0,E.useRef)(null),G=(0,E.useMemo)(()=>t.find(e=>e.pk)?.name||(t.find(e=>e.name.toLowerCase()===`id`)?.name??null),[t]),Se=(0,E.useCallback)(e=>{let t=JSON.stringify(e,null,2),n=G?String(e[G]??``):``;H({type:`editor`,title:n?`Row ${n}`:`Row`,projectId:null,closable:!0,metadata:{inlineContent:t,inlineLanguage:`json`}})},[H,G]),Ce=(0,E.useRef)(N);Ce.current=N;let K=(0,E.useRef)(F);K.current=F;let we=(0,E.useRef)(B);we.current=B;let Te=(0,E.useRef)(L);Te.current=L;let Ee=(0,E.useCallback)((e,t,n)=>{P({rowIdx:e,col:t}),I(n==null?``:typeof n==`object`?JSON.stringify(n):String(n))},[]),De=(0,E.useCallback)(()=>{let t=Ce.current;if(!t||!e||!G)return;let n=e.rows[t.rowIdx];if(!n)return;let r=n[t.col];String(r??``)!==K.current&&l(G,n[G],t.col,K.current===``?null:K.current),P(null)},[e,G,l]),Oe=(0,E.useCallback)(()=>P(null),[]),ke=(0,E.useCallback)(t=>{if(!e||!G||!u)return;let n=e.rows[t];n&&(u(G,n[G]),R(null))},[e,G,u]),Ae=(0,E.useCallback)(e=>{he(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),je=(0,E.useCallback)(e=>{_e(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),Me=(0,E.useCallback)((e,t)=>{let n={...j};t?n[e]=t:delete n[e],M?.(n)},[j,M]),Ne=(0,E.useCallback)(e=>{V(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),Pe=(0,E.useCallback)(()=>{e&&V(t=>t.size===e.rows.length?new Set:new Set(e.rows.map((e,t)=>t)))},[e]),Fe=(0,E.useCallback)(()=>{!e||!G||!S||(S(G,Array.from(B).map(t=>e.rows[t]?.[G]).filter(e=>e!=null)),V(new Set),pe(!1))},[e,G,S,B]),Ie=(0,E.useCallback)(async()=>{if(C){de(null);try{let e={};for(let[t,n]of Object.entries(ce))n!==``&&(e[t]=n);await C(e),se(!1),le({})}catch(e){de(e.message)}}},[C,ce]),q=(0,E.useMemo)(()=>{if(!e||!z)return e?.rows??[];let t=z.toLowerCase();return e.rows.filter(n=>e.columns.some(e=>String(n[e]??``).toLowerCase().includes(t)))},[e,z]),Le=(0,E.useRef)(null);(0,E.useEffect)(()=>{let t=Le.current;if(!t)return;let n=t=>{if(t.key===`Escape`){W(!1);return}let n=t.target?.tagName;if(!(n===`INPUT`||n===`TEXTAREA`)){if(t.key===`/`){t.preventDefault(),W(!0);return}if(!(!(t.metaKey||t.ctrlKey)||!e)&&(t.key===`a`&&(t.preventDefault(),V(new Set(e.rows.map((e,t)=>t)))),t.key===`c`&&B.size>0)){t.preventDefault();let n=e.columns,r=n.join(` `),i=Array.from(B).sort((e,t)=>e-t).map(t=>n.map(n=>{let r=e.rows[t]?.[n];return r==null?``:typeof r==`object`?JSON.stringify(r):String(r)}).join(` `));navigator.clipboard.writeText([r,...i].join(`
2
2
  `))}}};return t.addEventListener(`keydown`,n),()=>t.removeEventListener(`keydown`,n)},[e,B]);let J=(0,E.useMemo)(()=>{if(!e)return[];let t=e.columns.filter(e=>U.has(e)),n=e.columns.filter(e=>!U.has(e));return[...t,...n]},[e?.columns,U]),Re=(0,E.useRef)(null),[Y,ze]=(0,E.useState)(0),[X,Be]=(0,E.useState)(new Map);(0,E.useEffect)(()=>{let e=Re.current;if(!e)return;let t=()=>{ze(e.offsetHeight);let t=new Map;e.querySelectorAll(`th[data-col]`).forEach(e=>{t.set(e.dataset.col,e.offsetWidth)});let n=e.querySelector(`th[data-col='_cb']`);n&&t.set(`_cb`,n.offsetWidth),Be(t)};t();let n=new ResizeObserver(t);return n.observe(e),()=>n.disconnect()},[e?.columns,U]);let Z=(0,E.useMemo)(()=>{let e=new Map,t=X.get(`_cb`)??(G?40:0);for(let n of J){if(!U.has(n))break;e.set(n,t),t+=X.get(n)??100}return e},[J,U,G,X]),Q=(0,E.useMemo)(()=>Array.from(ge).sort((e,t)=>e-t).map(e=>({idx:e,row:q[e]})).filter(e=>e.row),[ge,q]),Ve=(0,E.useRef)(new Map),[$,He]=(0,E.useState)(new Map),Ue=(0,E.useCallback)((e,t)=>{t?Ve.current.set(e,t):Ve.current.delete(e)},[]);(0,E.useEffect)(()=>{if(Q.length===0){$.size>0&&He(new Map);return}let e=requestAnimationFrame(()=>{let e=new Map;for(let{idx:t}of Q){let n=Ve.current.get(t);n&&e.set(t,n.offsetHeight)}He(e)});return()=>cancelAnimationFrame(e)},[Q,e]);let We=(0,E.useMemo)(()=>{let e=new Map,t=Y;for(let{idx:n}of Q)e.set(n,t),t+=$.get(n)??28;return e},[Y,Q,$]),Ge=(0,E.useCallback)(e=>{let t=xe.current,n=t?.querySelector(`th[data-col="${e}"]`);if(!t||!n)return;let r=0,i=t.querySelector(`th[data-col="_cb"]`);i&&(r+=i.offsetWidth);for(let[t,n]of Z)t!==e&&(r=Math.max(r,n+(X.get(t)??0)));let a=n.offsetLeft-r;t.scrollTo({left:a,behavior:`smooth`}),W(!1)},[Z,X]);if(!e)return(0,A.jsx)(`div`,{className:`flex items-center justify-center h-full text-xs text-muted-foreground`,children:n?(0,A.jsx)(g,{className:`size-4 animate-spin`}):`Select a table`});let Ke=Math.ceil(e.total/e.limit)||1,qe=B.size>0,Je=B.size===e.rows.length&&e.rows.length>0;return(0,A.jsxs)(`div`,{ref:Le,tabIndex:0,className:`flex flex-col h-full overflow-hidden outline-none`,children:[(0,A.jsxs)(`div`,{className:`flex items-center gap-2 px-2 py-1 border-b border-border bg-background shrink-0`,children:[(0,A.jsxs)(`div`,{className:`flex items-center gap-1 flex-1`,children:[(0,A.jsx)(b,{className:`size-3 text-muted-foreground`}),(0,A.jsx)(`input`,{type:`text`,value:z,onChange:e=>ae(e.target.value),placeholder:`Search current page…`,className:`flex-1 text-xs bg-transparent outline-none text-foreground placeholder:text-muted-foreground`}),z&&(0,A.jsx)(`button`,{type:`button`,onClick:()=>ae(``),className:`text-muted-foreground hover:text-foreground`,children:(0,A.jsx)(d,{className:`size-3`})})]}),(0,A.jsxs)(`div`,{className:`relative`,children:[(0,A.jsx)(`button`,{type:`button`,onClick:()=>W(!be),className:`p-0.5 rounded transition-colors ${be?`text-primary`:`text-muted-foreground hover:text-foreground`}`,title:`Jump to column ( / )`,children:(0,A.jsx)(w,{className:`size-3.5`})}),be&&(0,A.jsx)(re,{columns:e.columns,onSelect:Ge,onClose:()=>W(!1)})]}),qe&&(0,A.jsxs)(`div`,{className:`flex items-center gap-1.5 text-xs`,children:[(0,A.jsxs)(`span`,{className:`text-muted-foreground`,children:[B.size,` selected`]}),S&&G&&(fe?(0,A.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,A.jsxs)(`button`,{type:`button`,onClick:Fe,className:`text-destructive text-[10px] font-medium hover:underline`,children:[`Delete `,B.size,`?`]}),(0,A.jsx)(`button`,{type:`button`,onClick:()=>pe(!1),className:`text-muted-foreground text-[10px] hover:underline`,children:`Cancel`})]}):(0,A.jsx)(`button`,{type:`button`,onClick:()=>pe(!0),className:`p-0.5 text-muted-foreground hover:text-destructive`,children:(0,A.jsx)(p,{className:`size-3`})})),(0,A.jsx)(te,{columns:e.columns,rows:Array.from(B).map(t=>e.rows[t]).filter(Boolean),filename:`${k??`db`}-selected`})]}),C&&(0,A.jsx)(`button`,{type:`button`,onClick:()=>{se(!0),le({}),de(null)},className:`p-0.5 rounded text-muted-foreground hover:text-primary transition-colors`,title:`Insert row`,children:(0,A.jsx)(o,{className:`size-3.5`})})]}),oe&&(0,A.jsxs)(`div`,{className:`px-2 py-1.5 border-b border-border bg-muted/30 text-xs space-y-1`,children:[(0,A.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:t.filter(e=>!e.pk).map(e=>(0,A.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,A.jsx)(`label`,{className:`text-muted-foreground text-[10px] w-16 truncate`,title:e.name,children:e.name}),(0,A.jsx)(`input`,{value:ce[e.name]??``,onChange:t=>le(n=>({...n,[e.name]:t.target.value})),placeholder:e.defaultValue??(e.nullable?`NULL`:``),className:`h-5 w-24 text-[11px] px-1 rounded border border-border bg-background outline-none focus:border-primary`})]},e.name))}),(0,A.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,A.jsx)(`button`,{type:`button`,onClick:Ie,className:`text-[10px] px-2 py-0.5 rounded bg-primary text-primary-foreground hover:bg-primary/90`,children:`Save`}),(0,A.jsx)(`button`,{type:`button`,onClick:()=>se(!1),className:`text-[10px] text-muted-foreground hover:underline`,children:`Cancel`}),ue&&(0,A.jsx)(`span`,{className:`text-[10px] text-destructive`,children:ue})]})]}),(0,A.jsxs)(`div`,{ref:xe,className:`flex-1 overflow-auto relative`,children:[n&&(0,A.jsx)(`div`,{className:`absolute inset-0 z-30 flex items-center justify-center bg-background/60`,children:(0,A.jsx)(g,{className:`size-5 animate-spin text-primary`})}),(0,A.jsxs)(`table`,{className:`w-full text-xs`,style:{borderCollapse:`separate`,borderSpacing:0},children:[(0,A.jsx)(`thead`,{ref:Re,className:`sticky top-0 z-20 bg-muted`,children:(0,A.jsxs)(`tr`,{children:[G&&(0,A.jsx)(`th`,{"data-col":`_cb`,className:`px-2 py-1.5 text-left font-medium text-muted-foreground border-b border-border w-10 bg-muted`,style:{position:`sticky`,left:0,zIndex:30},children:(0,A.jsx)(`input`,{type:`checkbox`,checked:Je,onChange:Pe,className:`size-3 accent-primary`})}),J.map(e=>{let n=t.find(t=>t.name===e)?.pk,r=f===e,o=U.has(e),s=!!j[e],c=ve===e,l=Z.get(e);return(0,A.jsxs)(`th`,{"data-col":e,className:`group/th px-2 py-1.5 text-left font-medium text-muted-foreground border-b border-border whitespace-nowrap bg-muted ${o?`border-r border-r-primary/20`:``}`,style:l==null?void 0:{position:`sticky`,left:l,zIndex:25},children:[(0,A.jsxs)(`div`,{className:`flex items-center gap-0.5`,children:[(0,A.jsxs)(`button`,{type:`button`,onClick:()=>x(e),className:`flex items-center gap-0.5 ${n?`font-bold`:``} hover:text-foreground transition-colors`,children:[e,r&&m===`ASC`&&(0,A.jsx)(i,{className:`size-3`}),r&&m===`DESC`&&(0,A.jsx)(a,{className:`size-3`})]}),M&&(0,A.jsx)(`button`,{type:`button`,title:`Filter column`,onClick:()=>ye(c?null:e),className:`p-0.5 rounded transition-colors ${s||c?`text-primary`:`text-muted-foreground/40 md:opacity-0 md:group-hover/th:opacity-100 hover:text-foreground`}`,children:(0,A.jsx)(T,{className:`size-2.5`})}),(0,A.jsx)(`button`,{type:`button`,title:o?`Unpin column`:`Pin column`,onClick:()=>Ae(e),className:`p-0.5 rounded transition-colors ${o?`text-primary`:`text-muted-foreground/40 md:opacity-0 md:group-hover/th:opacity-100 hover:text-foreground`}`,children:o?(0,A.jsx)(y,{className:`size-2.5`}):(0,A.jsx)(v,{className:`size-2.5`})})]}),c&&(0,A.jsxs)(`div`,{className:`mt-1 flex items-center gap-1`,children:[(0,A.jsx)(`input`,{autoFocus:!0,type:`text`,value:j[e]??``,placeholder:`ILIKE filter…`,onChange:t=>Me(e,t.target.value),onKeyDown:e=>{e.key===`Escape`&&ye(null)},className:`w-full h-5 text-[10px] px-1 rounded border border-border bg-background outline-none focus:border-primary`}),s&&(0,A.jsx)(`button`,{type:`button`,onClick:()=>Me(e,``),className:`text-muted-foreground hover:text-foreground`,children:(0,A.jsx)(d,{className:`size-2.5`})})]})]},e)}),u&&G&&(0,A.jsx)(`th`,{className:`px-2 py-1.5 border-b border-border w-14 bg-muted`})]})}),(0,A.jsxs)(`tbody`,{children:[Q.map(({idx:e,row:t})=>(0,A.jsx)(ie,{row:t,rowIdx:e,columns:J,selected:B.has(e),onToggleSelect:Ne,pkCol:G,editingCell:N,editValue:F,onStartEdit:Ee,onCommitEdit:De,onCancelEdit:Oe,onSetEditValue:I,showDelete:!!u,confirmingDelete:L===e,onDelete:ke,onConfirmDelete:R,onViewCell:me,onViewRow:Se,pinned:!0,onTogglePin:je,pinnedCols:U,pinnedColOffsets:Z,stickyTop:We.get(e)??Y,trRef:t=>Ue(e,t)},`pin-${e}`)),q.map((e,t)=>ge.has(t)?null:(0,A.jsx)(ie,{row:e,rowIdx:t,columns:J,selected:B.has(t),onToggleSelect:Ne,pkCol:G,editingCell:N,editValue:F,onStartEdit:Ee,onCommitEdit:De,onCancelEdit:Oe,onSetEditValue:I,showDelete:!!u,confirmingDelete:L===t,onDelete:ke,onConfirmDelete:R,onViewCell:me,onViewRow:Se,pinned:!1,onTogglePin:je,pinnedCols:U,pinnedColOffsets:Z},t)),q.length===0&&(0,A.jsx)(`tr`,{children:(0,A.jsx)(`td`,{colSpan:J.length+2,className:`px-2 py-8 text-center text-muted-foreground`,children:`No data`})})]})]})]}),(0,A.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,A.jsxs)(`span`,{children:[e.total.toLocaleString(),` rows`]}),(0,A.jsxs)(`div`,{className:`hidden md:flex items-center gap-2 text-[10px] text-muted-foreground/50`,children:[(0,A.jsxs)(`span`,{children:[(0,A.jsx)(`kbd`,{className:`px-1 py-0.5 rounded bg-muted text-[9px]`,children:`/`}),` columns`]}),(0,A.jsxs)(`span`,{children:[(0,A.jsxs)(`kbd`,{className:`px-1 py-0.5 rounded bg-muted text-[9px]`,children:[`⌘`,`A`]}),` select all`]}),(0,A.jsxs)(`span`,{children:[(0,A.jsxs)(`kbd`,{className:`px-1 py-0.5 rounded bg-muted text-[9px]`,children:[`⌘`,`C`]}),` copy`]})]}),(0,A.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,A.jsx)(`button`,{type:`button`,disabled:r<=1,onClick:()=>c(r-1),className:`p-0.5 rounded hover:bg-muted disabled:opacity-30`,children:(0,A.jsx)(h,{className:`size-3.5`})}),(0,A.jsxs)(`span`,{children:[r,` / `,Ke]}),(0,A.jsx)(`button`,{type:`button`,disabled:r>=Ke,onClick:()=>c(r+1),className:`p-0.5 rounded hover:bg-muted disabled:opacity-30`,children:(0,A.jsx)(s,{className:`size-3.5`})})]})]})]})}function N(e){return e==null?`NULL`:typeof e==`object`?JSON.stringify(e):String(e)}var P=200;function F(e){if(e==null)return!1;if(typeof e==`object`)return!0;let t=String(e);if(t.length>=P)return!0;let n=t.trimStart();return!!((n[0]===`{`||n[0]===`[`)&&(n.endsWith(`}`)||n.endsWith(`]`))||n.startsWith(`<?xml`)||n.startsWith(`<`)&&n.endsWith(`>`))}function ne(e){let t=e.trimStart();if(t[0]===`{`||t[0]===`[`)try{return JSON.parse(t),`json`}catch{}return t.startsWith(`<?xml`)||t.startsWith(`<`)&&/<\/\w+>/.test(t)?`xml`:t.startsWith(`---`)||/^\w+:\s/m.test(t)?`yaml`:`plaintext`}function re({columns:e,onSelect:t,onClose:n}){let[r,i]=(0,E.useState)(``),[a,o]=(0,E.useState)(0),s=(0,E.useMemo)(()=>{if(!r)return e;let t=r.toLowerCase();return e.filter(e=>e.toLowerCase().includes(t))},[e,r]),c=(0,E.useRef)(null);return(0,E.useEffect)(()=>{c.current?.scrollIntoView({block:`nearest`})},[a]),(0,A.jsxs)(`div`,{className:`absolute top-full right-0 mt-1 z-50 w-52 max-h-56 bg-popover border border-border rounded-md shadow-lg overflow-hidden flex flex-col`,children:[(0,A.jsx)(`input`,{autoFocus:!0,type:`text`,value:r,onChange:e=>{i(e.target.value),o(0)},onKeyDown:e=>{e.key===`Escape`?n():e.key===`ArrowDown`?(e.preventDefault(),o(e=>Math.min(e+1,s.length-1))):e.key===`ArrowUp`?(e.preventDefault(),o(e=>Math.max(e-1,0))):e.key===`Enter`&&s[a]&&t(s[a])},placeholder:`Search columns…`,className:`px-2 py-1.5 text-xs bg-transparent outline-none border-b border-border text-foreground placeholder:text-muted-foreground`}),(0,A.jsx)(`div`,{className:`overflow-auto flex-1`,children:s.map((e,n)=>(0,A.jsx)(`button`,{type:`button`,onClick:()=>t(e),ref:n===a?c:void 0,className:`w-full text-left px-2 py-1 text-xs truncate ${n===a?`bg-primary/10 text-primary`:`text-foreground hover:bg-muted`}`,children:e},e))})]})}var ie=(0,E.memo)(function({row:e,rowIdx:t,columns:n,selected:r,onToggleSelect:i,pkCol:a,editingCell:o,editValue:s,onStartEdit:c,onCommitEdit:u,onCancelEdit:d,onSetEditValue:f,showDelete:m,confirmingDelete:h,onDelete:g,onConfirmDelete:_,onViewCell:b,onViewRow:x,pinned:S,onTogglePin:C,pinnedCols:w,pinnedColOffsets:T,stickyTop:E,trRef:D}){let O=S?`bg-muted`:r?`bg-primary/5`:`bg-background`;return(0,A.jsxs)(`tr`,{ref:D,className:`group ${S?``:`hover:bg-muted/30`}`,style:S?{position:`sticky`,top:E,zIndex:15}:void 0,children:[a&&(0,A.jsx)(`td`,{className:`px-2 py-1 border-b border-border/50 ${O}`,style:{position:`sticky`,left:0,zIndex:12},children:(0,A.jsxs)(`span`,{className:`flex items-center gap-0.5`,children:[(0,A.jsx)(`input`,{type:`checkbox`,checked:r,onChange:()=>i(t),className:`size-3 accent-primary`}),(0,A.jsx)(`button`,{type:`button`,title:`View row as JSON`,onClick:()=>x(e),className:`p-0.5 rounded transition-colors text-muted-foreground/30 md:opacity-0 md:group-hover:opacity-100 hover:text-foreground`,children:(0,A.jsx)(l,{className:`size-2.5`})}),(0,A.jsx)(`button`,{type:`button`,title:S?`Unpin row`:`Pin row`,onClick:()=>C(t),className:`p-0.5 rounded transition-colors ${S?`text-primary`:`text-muted-foreground/30 md:opacity-0 md:group-hover:opacity-100 hover:text-foreground`}`,children:S?(0,A.jsx)(y,{className:`size-2.5`}):(0,A.jsx)(v,{className:`size-2.5`})})]})}),n.map(n=>{let r=o?.rowIdx===t&&o?.col===n,i=e[n],p=!r&&F(i),m=w.has(n),h=T.get(n);return(0,A.jsx)(`td`,{className:`px-2 py-1 max-w-[300px] border-b border-border/50 ${m?`border-r border-r-primary/20`:``} ${m||S?O:``}`,style:h==null?void 0:{position:`sticky`,left:h,zIndex:10},children:r?(0,A.jsx)(`input`,{autoFocus:!0,className:`w-full bg-transparent border border-primary/50 rounded px-1 py-0 text-xs outline-none`,value:s,onChange:e=>f(e.target.value),onBlur:u,onKeyDown:e=>{e.key===`Enter`&&u(),e.key===`Escape`&&d()}}):(0,A.jsxs)(`span`,{className:`flex items-center gap-0.5`,children:[(0,A.jsx)(`span`,{className:`cursor-pointer truncate flex-1 ${i==null?`text-muted-foreground/40 italic`:``}`,onDoubleClick:()=>a&&c(t,n,i),title:N(i),children:N(i)}),p&&(0,A.jsx)(`button`,{type:`button`,title:`View full content`,onClick:()=>b({col:n,value:N(i)}),className:`shrink-0 p-0.5 rounded text-muted-foreground/50 hover:text-foreground transition-colors`,children:(0,A.jsx)(l,{className:`size-3`})})]})},n)}),m&&a&&(0,A.jsx)(`td`,{className:`px-2 py-1 border-b border-border/50 ${S?O:``}`,children:h?(0,A.jsxs)(`span`,{className:`flex items-center gap-1 whitespace-nowrap`,children:[(0,A.jsx)(`button`,{type:`button`,onClick:()=>g(t),className:`text-destructive text-[10px] font-medium hover:underline`,children:`Confirm`}),(0,A.jsx)(`button`,{type:`button`,onClick:()=>_(null),className:`text-muted-foreground text-[10px] hover:underline`,children:`Cancel`})]}):(0,A.jsx)(`button`,{type:`button`,onClick:()=>_(t),className:`p-0.5 rounded md:opacity-0 md:group-hover:opacity-100 hover:bg-destructive/10 hover:text-destructive transition-opacity`,title:`Delete row`,children:(0,A.jsx)(p,{className:`size-3`})})})]})});function I(e){let t={},n=/"(\w+)"\s+ILIKE\s+'%([^']*?)%'/gi,r;for(;(r=n.exec(e))!==null;)t[r[1]]=r[2].replace(/''/g,`'`);return t}function L({metadata:e}){let t=e?.connectionId,n=e?.connectionName,r=e?.tableName,i=e?.schemaName??`public`,a=e?.initialSql,o=k(t),[s,l]=(0,E.useState)([]),[u,d]=(0,E.useState)(180),p=(0,E.useRef)(null),[h,g]=(0,E.useState)({}),_=(0,E.useMemo)(()=>{if(a&&!o.selectedTable)return a;if(o.selectedTable){let e=`SELECT * FROM "${o.selectedTable}"`,t=Object.entries(h).filter(([,e])=>e.trim()).map(([e,t])=>`"${e}" ILIKE '%${t.replace(/'/g,`''`)}%'`);t.length>0&&(e+=` WHERE ${t.join(` AND `)}`),o.orderBy&&(e+=` ORDER BY "${o.orderBy}" ${o.orderDir}`);let n=(o.page-1)*100;return e+=` LIMIT 100`,n>0&&(e+=` OFFSET ${n}`),e}return`SELECT * FROM `},[a,o.selectedTable,o.orderBy,o.orderDir,o.page,h]),v=(0,E.useCallback)(e=>{g(e)},[]),y=(0,E.useRef)(void 0);(0,E.useEffect)(()=>{if(!(!o.selectedTable||Object.keys(h).length===0))return clearTimeout(y.current),y.current=setTimeout(()=>{o.queryAsTable(_)},500),()=>clearTimeout(y.current)},[h]);let b=(0,E.useCallback)(e=>{e.preventDefault();let t=e.clientY,n=u,r=e=>{let r=e.clientY-t;d(Math.max(80,Math.min(n+r,(p.current?.clientHeight??600)-100)))},i=()=>{document.removeEventListener(`mousemove`,r),document.removeEventListener(`mouseup`,i)};document.addEventListener(`mousemove`,r),document.addEventListener(`mouseup`,i)},[u]);(0,E.useEffect)(()=>{m.get(`/api/db/connections/${t}/tables?cached=1`).then(e=>l(e.map(e=>({name:e.name,schema:e.schema})))).catch(()=>{})},[t]);let C=(0,E.useMemo)(()=>{if(s.length!==0)return{tables:s,getColumns:async(e,n)=>await m.get(`/api/db/connections/${t}/schema?table=${encodeURIComponent(e)}${n?`&schema=${encodeURIComponent(n)}`:``}`)}},[t,s]),w=(0,E.useRef)(!1);(0,E.useEffect)(()=>{w.current||(w.current=!0,a?o.executeQuery(a):r&&o.selectTable(r,i))},[r,i,a]);let[T,D]=(0,E.useState)(!!a),O=(0,E.useCallback)(e=>{let t=e.trim();if(o.selectedTable&&RegExp(`^SELECT\\s+\\*\\s+FROM\\s+"?${o.selectedTable.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)}"?\\b`,`i`).test(t)){g(I(t)),o.queryAsTable(t);return}D(!0),o.executeQuery(e)},[o.executeQuery,o.queryAsTable,o.selectedTable]),ee=(0,E.useCallback)(e=>{D(!1),o.toggleSort(e)},[o.toggleSort]),j=(0,E.useCallback)(e=>{D(!1),o.setPage(e)},[o.setPage]),N=o.queryResult,P=T&&!!(N||o.queryError),F=o.selectedTable&&!P;return(0,A.jsx)(`div`,{ref:p,className:`flex h-full w-full overflow-hidden`,children:(0,A.jsxs)(`div`,{className:`flex-1 flex flex-col overflow-hidden`,children:[(0,A.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-1.5 border-b border-border bg-background shrink-0`,children:[(0,A.jsx)(c,{className:`size-3.5 text-muted-foreground`}),(0,A.jsx)(`span`,{className:`text-xs text-muted-foreground truncate`,children:n??`Database`}),o.selectedTable&&(0,A.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[`/ `,o.selectedTable]}),(0,A.jsxs)(`div`,{className:`ml-auto flex items-center gap-1`,children:[o.tableData&&(0,A.jsx)(te,{columns:o.tableData.columns,rows:o.tableData.rows,filename:n?`${n}-${o.selectedTable??`data`}`:o.selectedTable??`data`,exportAllUrl:o.selectedTable?`/api/db/connections/${t}/export?table=${encodeURIComponent(o.selectedTable)}&schema=${o.selectedSchema}`:void 0}),(0,A.jsx)(`button`,{type:`button`,onClick:()=>o.refreshData(),title:`Reload data`,className:`p-1 rounded text-muted-foreground hover:text-foreground transition-colors`,children:(0,A.jsx)(f,{className:`size-3 ${o.loading?`animate-spin`:``}`})})]})]}),(0,A.jsx)(`div`,{className:`shrink-0 border-b border-border`,style:{height:u},children:(0,A.jsx)(S,{onExecute:O,loading:o.queryLoading,defaultValue:_,schemaInfo:C})}),(0,A.jsx)(`div`,{onMouseDown:b,className:`shrink-0 h-1.5 cursor-row-resize bg-border/50 hover:bg-primary/30 flex items-center justify-center transition-colors`,children:(0,A.jsx)(x,{className:`size-3 text-muted-foreground/50`})}),(0,A.jsxs)(`div`,{className:`flex-1 overflow-hidden`,children:[F&&(0,A.jsx)(M,{tableData:o.tableData,schema:o.schema,loading:o.loading,page:o.page,onPageChange:j,onCellUpdate:o.updateCell,onRowDelete:o.deleteRow,orderBy:o.orderBy,orderDir:o.orderDir,onToggleSort:ee,onBulkDelete:o.bulkDelete,onInsertRow:o.insertRow,connectionId:t,selectedTable:o.selectedTable,selectedSchema:o.selectedSchema,connectionName:n,columnFilters:h,onColumnFilter:v}),P&&(0,A.jsx)(z,{result:N,error:o.queryError,loading:o.queryLoading,schema:o.schema,connectionName:n})]})]})})}var R=()=>{};function z({result:e,error:t,loading:n,schema:r,connectionName:i}){let a=(0,E.useMemo)(()=>e?.changeType===`select`&&e.rows.length>0?{columns:e.columns,rows:e.rows,total:e.rows.length,limit:e.rows.length}:null,[e]),o=(0,E.useMemo)(()=>r?.length?r:(e?.columns??[]).map(e=>({name:e,type:`text`,nullable:!0,pk:!1,defaultValue:null})),[r,e?.columns]);return(0,A.jsxs)(`div`,{className:`flex flex-col h-full overflow-hidden text-xs`,children:[t&&(0,A.jsx)(`div`,{className:`px-3 py-2 text-destructive bg-destructive/5 shrink-0`,children:t}),e?.changeType===`modify`&&(0,A.jsxs)(`div`,{className:`px-3 py-2 text-green-500 shrink-0`,children:[e.rowsAffected,` row(s) affected`,e.executionTimeMs!=null&&(0,A.jsxs)(`span`,{className:`text-muted-foreground ml-2`,children:[e.executionTimeMs,`ms`]})]}),a&&(0,A.jsxs)(`div`,{className:`flex-1 overflow-hidden`,children:[(0,A.jsx)(M,{tableData:a,schema:o,loading:!!n,page:1,onPageChange:R,onCellUpdate:R,orderBy:null,orderDir:`ASC`,onToggleSort:R,connectionName:i}),e?.executionTimeMs!=null&&(0,A.jsxs)(`div`,{className:`px-3 py-0.5 border-t border-border text-[10px] text-muted-foreground shrink-0`,children:[e.rows.length,` rows · `,e.executionTimeMs,`ms`]})]}),e?.changeType===`select`&&e.rows.length===0&&(0,A.jsxs)(`div`,{className:`px-3 py-2 text-muted-foreground shrink-0`,children:[`No results`,e.executionTimeMs!=null&&(0,A.jsxs)(`span`,{className:`ml-2 text-muted-foreground/60`,children:[e.executionTimeMs,`ms`]})]}),!e&&!t&&(0,A.jsx)(`div`,{className:`flex items-center justify-center h-full text-muted-foreground`,children:n?(0,A.jsx)(g,{className:`size-4 animate-spin`}):`Run a query to see results`})]})}export{L 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-IeETSfON.js";import{t as a}from"./text-wrap-D_OmSzhp.js";import{i as o,t as s}from"./api-client-BvxmRZUi.js";import{B as c,K as l,L as u,k as d}from"./index-DK4yJlIj.js";import{r as f,t as p}from"./use-monaco-theme-vmoBT6np.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=p(),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});s.get(`${o(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=`${o(n)}/git/file-diff?${i}`}else if(r||v){let t=new URLSearchParams;r&&t.set(`ref1`,r),v&&t.set(`ref2`,v),e=`${o(n)}/git/diff?${t}`}else e=`${o(n)}/git/diff`;s.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)(c,{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)(l,{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)(u,{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)(f,{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)(c,{className:`size-5 animate-spin text-muted-foreground`})}):(0,g.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,g.jsx)(c,{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-IeETSfON.js";import{t as a}from"./text-wrap-D_OmSzhp.js";import{i as o,t as s}from"./api-client-BvxmRZUi.js";import{B as c,K as l,L as u,k as d}from"./index-fzSsl_Dg.js";import{r as f,t as p}from"./use-monaco-theme-BEX-OBkP.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=p(),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});s.get(`${o(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=`${o(n)}/git/file-diff?${i}`}else if(r||v){let t=new URLSearchParams;r&&t.set(`ref1`,r),v&&t.set(`ref2`,v),e=`${o(n)}/git/diff?${t}`}else e=`${o(n)}/git/diff`;s.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)(c,{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)(l,{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)(u,{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)(f,{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)(c,{className:`size-5 animate-spin text-muted-foreground`})}):(0,g.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,g.jsx)(c,{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,3 +1,3 @@
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{B as r,E as i,v as a}from"./index-DK4yJlIj.js";var o=e(t(),1),s=n(),c=`<script>
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{B as r,E as i,v as a}from"./index-fzSsl_Dg.js";var o=e(t(),1),s=n(),c=`<script>
2
2
  function acquireVsCodeApi(){return{postMessage:function(m){window.parent.postMessage(m,"*")},getState:function(){try{return JSON.parse(sessionStorage.getItem("vscode-state")||"null")}catch{return null}},setState:function(s){sessionStorage.setItem("vscode-state",JSON.stringify(s));return s}}}
3
- <\/script>`;function l(e){if(!e)return e;let t=e.indexOf(`<head>`);return t===-1?c+e:e.slice(0,t+6)+c+e.slice(t+6)}function u({metadata:e}){let t=e?.panelId,n=e?.viewType,c=i(e=>e.currentProject),u=e?.projectName||c||void 0,[d,f]=(0,o.useState)(!1),p=a(e=>{if(t&&e.webviewPanels[t])return e.webviewPanels[t];if(n){let t=n.includes(`.`)?n:`${n}.view`;return Object.values(e.webviewPanels).find(e=>e.viewType===n||e.viewType===t)}}),m=p?.id??t,h=(0,o.useRef)(null),g=l(p?.html??``);(0,o.useEffect)(()=>{if(p||!n)return;let e=n.includes(`.`)?n:`${n}.view`,t=!1,r=null;async function i(){if(r)return r;if(!u)return[];try{let e=(await(await fetch(`/api/projects`)).json()).data?.find(e=>e.name===u);r=e?[e.path]:[]}catch{r=[]}return r}async function a(){let n=await i();t||window.dispatchEvent(new CustomEvent(`ext:command:execute`,{detail:{command:e,args:n}}))}let o=setTimeout(()=>{t||a()},500),s=setInterval(()=>{t||a()},2e3);return()=>{t=!0,clearTimeout(o),clearInterval(s)}},[p,n,u]);let _=(0,o.useRef)(null);(0,o.useEffect)(()=>{if(!p||!n||!u||u===_.current)return;_.current=u;let e=n.includes(`.`)?n:`${n}.view`;(async()=>{try{let t=(await(await fetch(`/api/projects`)).json()).data?.find(e=>e.name===u);t&&window.dispatchEvent(new CustomEvent(`ext:command:execute`,{detail:{command:e,args:[t.path]}}))}catch{}})()},[p,n,u]);let v=e?.extensionId,y=a(e=>{if(v&&e.activationErrors[v])return e.activationErrors[v];if(n){for(let[t,r]of Object.entries(e.activationErrors))if(t===`ext-${n}`)return r}}),b=(0,o.useCallback)(()=>{if(f(!1),!n)return;let e=n.includes(`.`)?n:`${n}.view`;(async()=>{try{let t=(await(await fetch(`/api/projects`)).json()).data?.find(e=>e.name===u),n=t?[t.path]:[];window.dispatchEvent(new CustomEvent(`ext:command:execute`,{detail:{command:e,args:n}}))}catch{}})()},[n,u]);return(0,o.useEffect)(()=>{if(p){f(!1);return}let e=setTimeout(()=>f(!0),1e4);return()=>clearTimeout(e)},[p]),(0,o.useEffect)(()=>{if(!m)return;let e=e=>{h.current&&e.source===h.current.contentWindow&&window.dispatchEvent(new CustomEvent(`ext:webview:send`,{detail:{panelId:m,message:e.data}}))};return window.addEventListener(`message`,e),()=>window.removeEventListener(`message`,e)},[m]),(0,o.useEffect)(()=>{if(!m)return;let e=e=>{let{panelId:t,message:n}=e.detail;t===m&&h.current?.contentWindow?.postMessage(n,`*`)};return window.addEventListener(`ext:webview:message`,e),()=>window.removeEventListener(`ext:webview:message`,e)},[m]),p?(0,s.jsx)(`div`,{className:`h-full w-full relative`,children:(0,s.jsx)(`iframe`,{ref:h,srcDoc:g,sandbox:`allow-scripts`,className:`w-full h-full border-0 bg-white dark:bg-zinc-900`,title:p.title})}):(0,s.jsx)(`div`,{className:`flex flex-col items-center justify-center h-full gap-3 text-sm text-text-subtle`,children:d?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(`span`,{className:`text-destructive font-medium`,children:`Extension failed to load`}),y&&(0,s.jsx)(`span`,{className:`text-xs text-muted-foreground max-w-md text-center`,children:y}),(0,s.jsx)(`button`,{onClick:b,className:`text-xs text-primary hover:underline`,children:`Retry`})]}):(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(r,{className:`size-5 animate-spin`}),(0,s.jsx)(`span`,{children:`Loading extension...`})]})})}export{u as ExtensionWebview};
3
+ <\/script>`;function l(e){if(!e)return e;let t=e.indexOf(`<head>`);return t===-1?c+e:e.slice(0,t+6)+c+e.slice(t+6)}function u({metadata:e}){let t=e?.panelId,n=e?.viewType,c=i(e=>e.currentProject),u=e?.projectName||c||void 0,[d,f]=(0,o.useState)(!1),p=a(e=>{if(t&&e.webviewPanels[t])return e.webviewPanels[t];if(n){let t=n.includes(`.`)?n:`${n}.view`;return Object.values(e.webviewPanels).find(e=>e.viewType===n||e.viewType===t)}}),m=p?.id??t,h=(0,o.useRef)(null),g=l(p?.html??``);(0,o.useEffect)(()=>{if(p||!n)return;let e=n.includes(`.`)?n:`${n}.view`,t=!1,r=null;async function i(){if(r)return r;if(!u)return[];try{let e=(await(await fetch(`/api/projects`)).json()).data?.find(e=>e.name===u);r=e?[e.path]:[]}catch{r=[]}return r}async function a(){let n=await i();t||window.dispatchEvent(new CustomEvent(`ext:command:execute`,{detail:{command:e,args:n}}))}let o=setTimeout(()=>{t||a()},500),s=setInterval(()=>{t||a()},2e3);return()=>{t=!0,clearTimeout(o),clearInterval(s)}},[p,n,u]);let _=(0,o.useRef)(null);(0,o.useEffect)(()=>{if(!p||!n||!u||u===_.current)return;_.current=u;let e=n.includes(`.`)?n:`${n}.view`;(async()=>{try{let t=(await(await fetch(`/api/projects`)).json()).data?.find(e=>e.name===u);t&&window.dispatchEvent(new CustomEvent(`ext:command:execute`,{detail:{command:e,args:[t.path]}}))}catch{}})()},[p,n,u]);let v=e?.extensionId,y=a(e=>{if(v&&e.activationErrors[v])return e.activationErrors[v];if(n){for(let[t,r]of Object.entries(e.activationErrors))if(t===`ext-${n}`)return r}}),b=(0,o.useCallback)(()=>{if(f(!1),!n)return;let e=n.includes(`.`)?n:`${n}.view`;(async()=>{try{let t=(await(await fetch(`/api/projects`)).json()).data?.find(e=>e.name===u),n=t?[t.path]:[];window.dispatchEvent(new CustomEvent(`ext:command:execute`,{detail:{command:e,args:n}}))}catch{}})()},[n,u]),x=(0,o.useRef)(null);return(0,o.useEffect)(()=>{x.current=m??null},[m]),(0,o.useEffect)(()=>()=>{let e=x.current;e&&(a.getState().removeWebviewPanel(e),window.dispatchEvent(new CustomEvent(`ext:webview:close`,{detail:{panelId:e}})))},[]),(0,o.useEffect)(()=>{if(p){f(!1);return}let e=setTimeout(()=>f(!0),1e4);return()=>clearTimeout(e)},[p]),(0,o.useEffect)(()=>{if(!m)return;let e=e=>{h.current&&e.source===h.current.contentWindow&&window.dispatchEvent(new CustomEvent(`ext:webview:send`,{detail:{panelId:m,message:e.data}}))};return window.addEventListener(`message`,e),()=>window.removeEventListener(`message`,e)},[m]),(0,o.useEffect)(()=>{if(!m)return;let e=e=>{let{panelId:t,message:n}=e.detail;t===m&&h.current?.contentWindow?.postMessage(n,`*`)};return window.addEventListener(`ext:webview:message`,e),()=>window.removeEventListener(`ext:webview:message`,e)},[m]),p?(0,s.jsx)(`div`,{className:`h-full w-full relative`,children:(0,s.jsx)(`iframe`,{ref:h,srcDoc:g,sandbox:`allow-scripts`,className:`w-full h-full border-0 bg-white dark:bg-zinc-900`,title:p.title})}):(0,s.jsx)(`div`,{className:`flex flex-col items-center justify-center h-full gap-3 text-sm text-text-subtle`,children:d?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(`span`,{className:`text-destructive font-medium`,children:`Extension failed to load`}),y&&(0,s.jsx)(`span`,{className:`text-xs text-muted-foreground max-w-md text-center`,children:y}),(0,s.jsx)(`button`,{onClick:b,className:`text-xs text-primary hover:underline`,children:`Retry`})]}):(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(r,{className:`size-5 animate-spin`}),(0,s.jsx)(`span`,{children:`Loading extension...`})]})})}export{u as ExtensionWebview};