@hienlh/ppm 0.9.53 → 0.9.55
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/dist/web/assets/{chat-tab-DvNEQYEe.js → chat-tab-SfXtOm9d.js} +1 -1
- package/dist/web/assets/{code-editor-CoT017Ah.js → code-editor-DAZvtAlT.js} +1 -1
- package/dist/web/assets/database-viewer-C5fco1jm.js +1 -0
- package/dist/web/assets/{diff-viewer-D0tuen4I.js → diff-viewer-ShRSPvsf.js} +1 -1
- package/dist/web/assets/{extension-webview-Ba5aeo9r.js → extension-webview-CWJRMPfV.js} +1 -1
- package/dist/web/assets/{git-graph-BnJrVPxJ.js → git-graph-h0QmXMdZ.js} +1 -1
- package/dist/web/assets/{index-DUQgLj0D.js → index-CDlrGSwd.js} +4 -4
- package/dist/web/assets/{index-BEfMoc_W.css → index-DVuSY0BZ.css} +1 -1
- package/dist/web/assets/keybindings-store-wbHg-S_v.js +1 -0
- package/dist/web/assets/{markdown-renderer-BuGSrE3y.js → markdown-renderer-CSEmmMWt.js} +1 -1
- package/dist/web/assets/{port-forwarding-tab-DsbrWNUP.js → port-forwarding-tab-Cts6tMFn.js} +1 -1
- package/dist/web/assets/{postgres-viewer-Bh6YmZPq.js → postgres-viewer-CiQC1sf9.js} +1 -1
- package/dist/web/assets/{settings-tab-BnzFtexC.js → settings-tab-CQx6aHtO.js} +1 -1
- package/dist/web/assets/sqlite-viewer-FQfCkjU6.js +1 -0
- package/dist/web/assets/{terminal-tab-fnZvscaH.js → terminal-tab-C2SnOqxn.js} +1 -1
- package/dist/web/assets/{use-monaco-theme-BdcKAZ69.js → use-monaco-theme-VPgvhMpB.js} +1 -1
- package/dist/web/index.html +2 -2
- package/dist/web/sw.js +1 -1
- package/docs/codebase-summary.md +52 -13
- package/docs/project-changelog.md +45 -1
- package/docs/project-roadmap.md +1 -1
- package/docs/system-architecture.md +121 -9
- package/package.json +1 -1
- package/src/cli/commands/bot-cmd.ts +144 -240
- package/src/server/routes/database.ts +31 -0
- package/src/server/routes/settings.ts +13 -0
- package/src/server/routes/sqlite.ts +14 -0
- package/src/services/database/postgres-adapter.ts +8 -0
- package/src/services/database/sqlite-adapter.ts +5 -0
- package/src/services/db.service.ts +109 -1
- package/src/services/postgres.service.ts +12 -0
- package/src/services/ppmbot/ppmbot-delegation.ts +112 -0
- package/src/services/ppmbot/ppmbot-service.ts +194 -369
- package/src/services/ppmbot/ppmbot-session.ts +85 -108
- package/src/services/ppmbot/ppmbot-telegram.ts +5 -16
- package/src/services/sqlite.service.ts +10 -0
- package/src/types/config.ts +1 -3
- package/src/types/database.ts +3 -0
- package/src/types/ppmbot.ts +21 -0
- package/src/web/components/database/database-viewer.tsx +50 -8
- package/src/web/components/database/use-database.ts +13 -1
- package/src/web/components/settings/ppmbot-settings-section.tsx +87 -26
- package/src/web/components/sqlite/sqlite-data-grid.tsx +55 -8
- package/src/web/components/sqlite/sqlite-viewer.tsx +1 -0
- package/src/web/components/sqlite/use-sqlite.ts +16 -1
- package/dist/web/assets/database-viewer-C3wK7cDk.js +0 -1
- package/dist/web/assets/keybindings-store-CkGFjxkX.js +0 -1
- package/dist/web/assets/sqlite-viewer-Cu3_hf07.js +0 -1
- package/docs/streaming-input-guide.md +0 -267
- package/snapshot-state.md +0 -1526
- package/test-session-ops.mjs +0 -444
- package/test-tokens.mjs +0 -212
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.9.55] - 2026-04-07
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
- **Database row deletion**: Delete rows from SQLite and PostgreSQL tables via data grid UI. Hover row to reveal trash icon, click to confirm/cancel inline. Works for both project-scoped SQLite viewer and unified database connections viewer.
|
|
7
|
+
- **Delete row API**: `DELETE /sqlite/row` (project-scoped) and `DELETE /api/db/connections/:id/row` (unified) endpoints with readonly enforcement.
|
|
8
|
+
|
|
3
9
|
## [0.9.53] - 2026-04-07
|
|
4
10
|
|
|
5
11
|
### Added
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/api-client-BKIT_Qeg.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{t as n}from"./createLucideIcon-PuMiQgHl.js";import{t as r}from"./arrow-up-BYhx9ckd.js";import{t as i}from"./chevron-right-5HgK6l7K.js";import{n as a,t as o}from"./markdown-renderer-BuGSrE3y.js";import{t as s}from"./columns-2-cEVJHYd7.js";import{A as c}from"./dist-DRTW9IWi.js";import{t as l}from"./square-oPKIkJiw.js";import{t as u}from"./tag-CXMT0QB6.js";import{t as d}from"./preload-helper-Bf_JiD2A.js";import{t as f}from"./jsx-runtime-kMwlnEGE.js";import{n as p,r as m,t as h}from"./utils-DMiycH3O.js";import{i as g,r as _,t as v}from"./api-client-BKIT_Qeg.js";import{a as y,c as b,f as x,h as S,i as C,l as w,o as T,p as E,r as D,s as O,t as k,u as A}from"./api-settings-Bid0NHuI.js";import{$ as j,A as M,At as N,Ct as P,D as F,E as I,Et as L,Ft as R,G as z,It as ee,J as te,K as B,Mt as V,Nt as H,O as U,Ot as W,Pt as G,Q as ne,S as K,St as q,T as J,Tt as re,X as Y,Z as ie,_t as ae,c as oe,ct as se,d as ce,dt as le,et as ue,f as de,ft as fe,gt as pe,i as me,it as he,j as X,k as ge,kt as _e,l as ve,m as ye,mt as be,nt as xe,o as Se,ot as Ce,p as we,pt as Z,q as Te,r as Ee,rt as De,s as Oe,st as ke,t as Ae,tt as je,u as Me,ut as Ne,w as Pe,yt as Fe,z as Ie}from"./index-DUQgLj0D.js";import"./chunk-GEFDOKGD-tDjHsAUs.js";import"./src-Dw4QhedI.js";import"./chunk-7R4GIKGN-Dvbyu4Zw.js";import"./chunk-HHEYEP7N-BBw_z0fW.js";import"./dist-Cep75xXf.js";import"./chunk-PU5JKC2W-C7Gry6md.js";import"./chunk-MX3YWQON-C2UEioMs.js";import"./chunk-YBOYWFTD-av5aeHLq.js";import"./chunk-PQ6SQG4A-DX0xW7kO.js";import"./chunk-KYZI473N-Djw13C-3.js";import"./chunk-O4XLMI2P-BsUWb9d0.js";import"./chunk-GLR3WWYH-DBdWQ3zy.js";import"./chunk-XPW4576I-BPEX8KhL.js";var Le=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`}]]),Re=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`}]]),ze=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`}]]),Be=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`}]]),Ve=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`}]]),He=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`}]]),Ue=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`}]]),We=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`}]]),Ge=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`}]]),Ke=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`}]]),qe=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`}]]),Je=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`}]]),Ye=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`}]]),Xe=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`}]]),Ze=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`}]]),Qe=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`}]]),$e=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`}]]),et=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`}]]),tt=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 nt({url:e,onMessage:t,autoConnect:n=!0}){let r=(0,Q.useRef)(null);return(0,Q.useEffect)(()=>{let i=new Ae(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 rt=null;function it(){return rt||=new AudioContext,rt}function at(e,t,n,r,i=`sine`){let a=it(),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 ot(){let e=it().currentTime;at(523,.15,e,.15),at(659,.2,e+.12,.15)}function st(){let e=it().currentTime;at(880,.12,e,.18,`square`),at(698,.12,e+.15,.18,`square`),at(880,.15,e+.3,.15,`square`)}function ct(){let e=it().currentTime;at(440,.12,e,.12),at(523,.12,e+.1,.12),at(659,.18,e+.2,.12)}var lt={done:ot,approval_request:st,question:ct};function ut(e){try{lt[e]?.()}catch{}}var dt={hasTeams:!1,teamNames:[],messageCount:0,unreadCount:0};function ft(e){if(document.hidden)return!1;let{panels:t,focusedPanelId:n}=Te.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 pt(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,y]=(0,Q.useState)(null),[b,x]=(0,Q.useState)(null),[S,C]=(0,Q.useState)(null),[w,T]=(0,Q.useState)(!1),[E,D]=(0,Q.useState)(null),O=(0,Q.useRef)(``),k=(0,Q.useRef)([]),A=(0,Q.useRef)(null),j=(0,Q.useRef)(`idle`),M=(0,Q.useRef)(null),N=(0,Q.useRef)(()=>{}),P=(0,Q.useRef)(null),F=(0,Q.useRef)(e);F.current=e;let I=(0,Q.useRef)(n);I.current=n;let L=(0,Q.useRef)({teamNames:new Set,messages:[]}),R=(0,Q.useRef)(0),[z,ee]=(0,Q.useState)(dt),[te,B]=(0,Q.useState)([]),V=(0,Q.useCallback)(()=>{let e=L.current;ee({hasTeams:e.teamNames.size>0,teamNames:Array.from(e.teamNames),messageCount:e.messages.length,unreadCount:R.current}),B([...e.messages])},[]),H=(0,Q.useCallback)(()=>{R.current=0,V()},[V]),U=s!==`idle`,W=(0,Q.useCallback)((e,t)=>{let n=k.current.findIndex(e=>e.type===`tool_use`&&(e.tool===`Agent`||e.tool===`Task`)&&e.toolUseId===t);if(n===-1)return!1;let r=k.current[n];if(r.type!==`tool_use`)return!1;let i=[...r.children??[],e];return k.current[n]={...r,children:i},!0},[]),G=(0,Q.useCallback)(()=>{let e=O.current,t=[...k.current],n=A.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`:A.current={accountId:t.accountId,accountLabel:t.accountLabel};break;case`account_retry`:t.accountId&&t.accountLabel&&(A.current={accountId:t.accountId,accountLabel:t.accountLabel}),k.current.push(t),G();break;case`text`:{let e=t.parentToolUseId;if(e&&W(t,e)){G();break}O.current+=t.content,k.current.push(t),G();break}case`thinking`:{let e=t.parentToolUseId;if(e&&W(t,e)){G();break}k.current.push(t),G();break}case`tool_use`:{let e=t.parentToolUseId;if(e&&W(t,e)){G();break}k.current.push(t),G();break}case`tool_result`:{let e=t.parentToolUseId;if(e&&W(t,e)){G();break}k.current.push(t),G();break}case`approval_request`:if(k.current.push(t),m({requestId:t.requestId,tool:t.tool,input:t.input}),F.current&&!ft(F.current)){let e=t.tool===`AskUserQuestion`?`question`:`approval_request`;Ie.getState().addNotification(F.current,e,I.current),ut(e)}break;case`error`:{k.current.push(t);let e=[...k.current];i(n=>{let r=n[n.length-1];return r?.role===`assistant`?[...n.slice(0,-1),{...r,events:e}]:[...n,{id:`error-${Date.now()}`,role:`system`,content:t.message,events:[t],timestamp:new Date().toISOString()}]});break}case`team_detected`:{let e=t.teamName;e&&(L.current.teamNames.add(e),v.get(`/api/teams/${encodeURIComponent(e)}`).then(e=>{if(e?.messages){let t=L.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())}V()}).catch(()=>{}),V());break}case`team_inbox`:{let e=t.messages;Array.isArray(e)&&(L.current.messages.push(...e),R.current+=e.length,V());break}case`team_updated`:V();break;case`done`:{if(j.current===`idle`)break;t.contextWindowPct!=null&&y(t.contextWindowPct),F.current&&!ft(F.current)&&(Ie.getState().addNotification(F.current,`done`,I.current),ut(`done`));let e=O.current,n=[...k.current];i(t=>{let r=t[t.length-1];return r?.role===`assistant`?[...t.slice(0,-1),{...r,id:`final-${Date.now()}`,content:e||r.content,events:n.length>0?n:r.events}]:t}),O.current=``,k.current=[],A.current=null;break}}},[W,G]),K=(0,Q.useCallback)(e=>{let t;try{t=JSON.parse(e.data)}catch{return}if(t.type!==`ping`){if(t.type===`session_migrated`){let e=t.newSessionId;e&&D(e);return}if(t.type===`title_updated`){C(t.title??null);return}if(t.type===`compact_status`){let e=t.status;e===`compacting`?x(`compacting`):e===`done`&&(x(null),P.current?.());return}if(t.type===`phase_changed`){let e=t.phase;c(e),j.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),j.current=n,e.sessionTitle&&C(e.sessionTitle),e.pendingApproval&&m({requestId:e.pendingApproval.requestId,tool:e.pendingApproval.tool,input:e.pendingApproval.input}),n===`idle`&&(P.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}),O.current=``,k.current=[],A.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:q,connect:J}=nt({url:e&&n?`/ws/project/${encodeURIComponent(n)}/chat/${e}`:``,onMessage:K,autoConnect:!!e&&!!n});N.current=q,(0,Q.useEffect)(()=>{let r=!1;return c(`idle`),j.current=`idle`,m(null),x(null),O.current=``,k.current=[],T(!1),L.current={teamNames:new Set,messages:[]},R.current=0,ee(dt),B([]),e&&n?(o(!0),fetch(`${g(n)}/chat/sessions/${e}/messages?providerId=${t}`,{headers:{Authorization:`Bearer ${_()}`}}).then(e=>e.json()).then(e=>{r||j.current!==`idle`||(e.ok&&Array.isArray(e.data)&&e.data.length>0?i(e.data):i([]))}).catch(()=>{!r&&j.current===`idle`&&i([])}).finally(()=>{r||o(!1)})):i([]),()=>{r=!0}},[e,t,n]);let re=(0,Q.useCallback)((e,t)=>{if(!e.trim())return;let n=j.current!==`idle`;if(n){let e=O.current,t=[...k.current];i(n=>{let r=n[n.length-1];return r?.role===`assistant`?[...n.slice(0,-1),{...r,id:`final-${Date.now()}`,content:e||r.content,events:t.length>0?t:r.events}]:n})}i(t=>[...t,{id:`user-${Date.now()}`,role:`user`,content:e,timestamp:new Date().toISOString()}]),O.current=``,k.current=[],M.current=null,n?(c(`thinking`),j.current=`thinking`):(c(`initializing`),j.current=`initializing`),m(null),q(JSON.stringify({type:`message`,content:e,permissionMode:t?.permissionMode,priority:t?.priority,images:t?.images}))},[q]),Y=(0,Q.useCallback)((e,t,n)=>{if(q(JSON.stringify({type:`approval_response`,requestId:e,approved:t,data:n})),t&&n){let t=k.current.find(t=>t.type===`approval_request`&&t.requestId===e&&t.tool===`AskUserQuestion`);if(t){let e=t.input;e&&typeof e==`object`&&(e.answers=n)}i(e=>[...e])}m(null)},[q]),ie=(0,Q.useCallback)(()=>{if(j.current===`idle`)return;q(JSON.stringify({type:`cancel`}));let e=O.current,t=[...k.current];i(n=>{let r=n[n.length-1];return r?.role===`assistant`?[...n.slice(0,-1),{...r,id:`final-${Date.now()}`,content:e||r.content,events:t.length>0?t:r.events}]:n}),O.current=``,k.current=[],M.current=null,c(`idle`),j.current=`idle`,m(null)},[q]),ae=(0,Q.useCallback)(()=>{T(!1),u(!0),J()},[J]),oe=(0,Q.useCallback)(()=>{!e||!n||(o(!0),fetch(`${g(n)}/chat/sessions/${e}/messages?providerId=${t}`,{headers:{Authorization:`Bearer ${_()}`}}).then(e=>e.json()).then(e=>{e.ok&&Array.isArray(e.data)&&e.data.length>0&&(i(e.data),O.current=``,k.current=[])}).catch(()=>{}).finally(()=>o(!1)))},[e,t,n]);return P.current=oe,{messages:r,messagesLoading:a,isStreaming:U,phase:s,isReconnecting:l,connectingElapsed:d,pendingApproval:p,contextWindowPct:h,compactStatus:b,sessionTitle:S,migratedSessionId:E,teamActivity:z,teamMessages:te,markTeamRead:H,sendMessage:re,respondToApproval:Y,cancelStreaming:ie,reconnect:ae,refetchMessages:oe,isConnected:w}}var mt=12e4;function ht(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(`${g(e)}/chat/usage?providerId=${t}${i}`,{headers:{Authorization:`Bearer ${_()}`}}).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(),mt),()=>{c.current&&clearInterval(c.current)}),[l]),{usageInfo:n,usageLoading:i,lastFetchedAt:o,refreshUsage:(0,Q.useCallback)(()=>l(!0),[l])}}var gt={damping:.7,stiffness:.05,mass:1.25},_t=70,vt=1e3/60,yt=350,bt=!1;globalThis.document?.addEventListener(`mousedown`,()=>{bt=!0}),globalThis.document?.addEventListener(`mouseup`,()=>{bt=!1}),globalThis.document?.addEventListener(`click`,()=>{bt=!1});var xt=(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(!bt)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<=_t}}},[]),f=(0,Q.useCallback)((e={})=>{typeof e==`string`&&(e={animation:e}),e.preserveScrollPosition||l(!0);let t=Date.now()+(Number(e.wait)||0),n=wt(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))/vt;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:wt(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=St(e=>{g.current?.removeEventListener(`scroll`,m),g.current?.removeEventListener(`wheel`,h),e?.addEventListener(`scroll`,m,{passive:!0}),e?.addEventListener(`wheel`,h,{passive:!0})},[]),_=St(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=wt(s.current,t?s.current.resize:s.current.initial);f({animation:e,wait:!0,preserveScrollPosition:!0,duration:e===`instant`?void 0:yt})}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 St(e,t){let n=(0,Q.useCallback)(t=>(n.current=t,e(t)),t);return n}var Ct=new Map;function wt(...e){let t={...gt},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 Ct.has(r)||Ct.set(r,Object.freeze(t)),n?`instant`:Ct.get(r)}var Tt=(0,Q.createContext)(null),Et=typeof window<`u`?Q.useLayoutEffect:Q.useEffect;function Dt({instance:e,children:t,resize:n,initial:r,mass:i,damping:a,stiffness:o,targetScrollTop:s,contextRef:c,...l}){let u=(0,Q.useRef)(null),d=xt({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]),Et(()=>{f.current&&getComputedStyle(f.current).overflow===`visible`&&(f.current.style.overflow=`auto`)},[]),Q.createElement(Tt.Provider,{value:y},Q.createElement(`div`,{...l},typeof t==`function`?t(y):t))}(function(e){function t({children:e,scrollClassName:t,...n}){let r=Ot();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})(Dt||={});function Ot(){let e=(0,Q.useContext)(Tt);if(!e)throw Error(`use-stick-to-bottom component context must be used within a StickToBottom component`);return e}var $=f();function kt(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 At({tool:e,result:t,completed:n,projectName:r}){let[a,o]=(0,Q.useState)(!1);if(e.type===`error`)return(0,$.jsxs)(`div`,{className:`flex items-center gap-2 rounded bg-red-500/10 border border-red-500/20 px-2 py-1.5 text-xs text-red-400`,children:[(0,$.jsx)(_e,{className:`size-3`}),(0,$.jsx)(`span`,{children:e.message})]});let{toolName:s,input:c}=kt(e),l=t?.type===`tool_result`,u=l&&!!t.isError,d=s===`AskUserQuestion`&&!!c?.answers,f=(s===`Agent`||s===`Task`)&&e.type===`tool_use`,p=f?e.children:void 0,m=p&&p.length>0;return(0,$.jsxs)(`div`,{className:`rounded border text-xs ${f?`border-accent/30 bg-accent/5`:`border-border bg-background`}`,children:[(0,$.jsxs)(`button`,{onClick:()=>o(!a),className:`flex items-center gap-2 px-2 py-1.5 w-full text-left hover:bg-surface transition-colors min-w-0`,children:[a?(0,$.jsx)(V,{className:`size-3 shrink-0`}):(0,$.jsx)(i,{className:`size-3 shrink-0`}),u?(0,$.jsx)(Re,{className:`size-3 text-red-400 shrink-0`}):l||d||n?(0,$.jsx)(W,{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)(jt,{name:s,input:c})}),m&&(0,$.jsxs)(`span`,{className:`ml-auto text-[10px] text-text-subtle shrink-0`,children:[p.length,` steps`]})]}),a&&(0,$.jsxs)(`div`,{className:`px-2 pb-2 space-y-1.5`,children:[(e.type===`tool_use`||e.type===`approval_request`)&&(0,$.jsx)(Mt,{name:s,input:c,projectName:r}),m&&(0,$.jsx)(It,{events:p,projectName:r}),l&&(0,$.jsx)(Pt,{toolName:s,output:t.output})]})]})}function jt({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:h(n(t.file_path))})]});case`Bash`:return(0,$.jsxs)($.Fragment,{children:[e,` `,(0,$.jsx)(`span`,{className:`font-mono text-text-subtle`,children:Rt(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:Rt(n(t.pattern),40)})]});case`WebSearch`:return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(je,{className:`size-3 inline`}),` `,e,` `,(0,$.jsx)(`span`,{className:`text-text-subtle`,children:Rt(n(t.query),50)})]});case`WebFetch`:return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(be,{className:`size-3 inline`}),` `,e,` `,(0,$.jsx)(`span`,{className:`text-text-subtle`,children:Rt(n(t.url),50)})]});case`ToolSearch`:return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(je,{className:`size-3 inline`}),` `,e,` `,(0,$.jsx)(`span`,{className:`text-text-subtle`,children:Rt(n(t.query),50)})]});case`Agent`:case`Task`:return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(R,{className:`size-3 inline`}),` `,e,` `,(0,$.jsx)(`span`,{className:`text-text-subtle`,children:Rt(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)(Ge,{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 Mt({name:e,input:t,projectName:n}){let r=e=>String(e??``),{openTab:i}=z(),a=e=>{n&&i({type:`editor`,title:h(e),metadata:{filePath:e,projectName:n},projectId:n,closable:!0})},o=(e,t,r)=>{i({type:`git-diff`,title:`Diff ${h(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)(P,{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)(s,{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:Rt(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)(Nt,{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)(Lt,{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)(be,{className:`size-3 shrink-0`}),r(t.url)]}),!!t.prompt&&(0,$.jsx)(`p`,{className:`text-text-subtle`,children:Rt(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 Nt({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 Pt({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{t as n}from"./createLucideIcon-PuMiQgHl.js";import{t as r}from"./arrow-up-BYhx9ckd.js";import{t as i}from"./chevron-right-5HgK6l7K.js";import{n as a,t as o}from"./markdown-renderer-CSEmmMWt.js";import{t as s}from"./columns-2-cEVJHYd7.js";import{A as c}from"./dist-DRTW9IWi.js";import{t as l}from"./square-oPKIkJiw.js";import{t as u}from"./tag-CXMT0QB6.js";import{t as d}from"./preload-helper-Bf_JiD2A.js";import{t as f}from"./jsx-runtime-kMwlnEGE.js";import{n as p,r as m,t as h}from"./utils-DMiycH3O.js";import{i as g,r as _,t as v}from"./api-client-BKIT_Qeg.js";import{a as y,c as b,f as x,h as S,i as C,l as w,o as T,p as E,r as D,s as O,t as k,u as A}from"./api-settings-Bid0NHuI.js";import{$ as j,A as M,At as N,Ct as P,D as F,E as I,Et as L,Ft as R,G as z,It as ee,J as te,K as B,Mt as V,Nt as H,O as U,Ot as W,Pt as G,Q as ne,S as K,St as q,T as J,Tt as re,X as Y,Z as ie,_t as ae,c as oe,ct as se,d as ce,dt as le,et as ue,f as de,ft as fe,gt as pe,i as me,it as he,j as X,k as ge,kt as _e,l as ve,m as ye,mt as be,nt as xe,o as Se,ot as Ce,p as we,pt as Z,q as Te,r as Ee,rt as De,s as Oe,st as ke,t as Ae,tt as je,u as Me,ut as Ne,w as Pe,yt as Fe,z as Ie}from"./index-CDlrGSwd.js";import"./chunk-GEFDOKGD-tDjHsAUs.js";import"./src-Dw4QhedI.js";import"./chunk-7R4GIKGN-Dvbyu4Zw.js";import"./chunk-HHEYEP7N-BBw_z0fW.js";import"./dist-Cep75xXf.js";import"./chunk-PU5JKC2W-C7Gry6md.js";import"./chunk-MX3YWQON-C2UEioMs.js";import"./chunk-YBOYWFTD-av5aeHLq.js";import"./chunk-PQ6SQG4A-DX0xW7kO.js";import"./chunk-KYZI473N-Djw13C-3.js";import"./chunk-O4XLMI2P-BsUWb9d0.js";import"./chunk-GLR3WWYH-DBdWQ3zy.js";import"./chunk-XPW4576I-BPEX8KhL.js";var Le=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`}]]),Re=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`}]]),ze=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`}]]),Be=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`}]]),Ve=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`}]]),He=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`}]]),Ue=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`}]]),We=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`}]]),Ge=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`}]]),Ke=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`}]]),qe=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`}]]),Je=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`}]]),Ye=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`}]]),Xe=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`}]]),Ze=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`}]]),Qe=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`}]]),$e=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`}]]),et=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`}]]),tt=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 nt({url:e,onMessage:t,autoConnect:n=!0}){let r=(0,Q.useRef)(null);return(0,Q.useEffect)(()=>{let i=new Ae(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 rt=null;function it(){return rt||=new AudioContext,rt}function at(e,t,n,r,i=`sine`){let a=it(),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 ot(){let e=it().currentTime;at(523,.15,e,.15),at(659,.2,e+.12,.15)}function st(){let e=it().currentTime;at(880,.12,e,.18,`square`),at(698,.12,e+.15,.18,`square`),at(880,.15,e+.3,.15,`square`)}function ct(){let e=it().currentTime;at(440,.12,e,.12),at(523,.12,e+.1,.12),at(659,.18,e+.2,.12)}var lt={done:ot,approval_request:st,question:ct};function ut(e){try{lt[e]?.()}catch{}}var dt={hasTeams:!1,teamNames:[],messageCount:0,unreadCount:0};function ft(e){if(document.hidden)return!1;let{panels:t,focusedPanelId:n}=Te.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 pt(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,y]=(0,Q.useState)(null),[b,x]=(0,Q.useState)(null),[S,C]=(0,Q.useState)(null),[w,T]=(0,Q.useState)(!1),[E,D]=(0,Q.useState)(null),O=(0,Q.useRef)(``),k=(0,Q.useRef)([]),A=(0,Q.useRef)(null),j=(0,Q.useRef)(`idle`),M=(0,Q.useRef)(null),N=(0,Q.useRef)(()=>{}),P=(0,Q.useRef)(null),F=(0,Q.useRef)(e);F.current=e;let I=(0,Q.useRef)(n);I.current=n;let L=(0,Q.useRef)({teamNames:new Set,messages:[]}),R=(0,Q.useRef)(0),[z,ee]=(0,Q.useState)(dt),[te,B]=(0,Q.useState)([]),V=(0,Q.useCallback)(()=>{let e=L.current;ee({hasTeams:e.teamNames.size>0,teamNames:Array.from(e.teamNames),messageCount:e.messages.length,unreadCount:R.current}),B([...e.messages])},[]),H=(0,Q.useCallback)(()=>{R.current=0,V()},[V]),U=s!==`idle`,W=(0,Q.useCallback)((e,t)=>{let n=k.current.findIndex(e=>e.type===`tool_use`&&(e.tool===`Agent`||e.tool===`Task`)&&e.toolUseId===t);if(n===-1)return!1;let r=k.current[n];if(r.type!==`tool_use`)return!1;let i=[...r.children??[],e];return k.current[n]={...r,children:i},!0},[]),G=(0,Q.useCallback)(()=>{let e=O.current,t=[...k.current],n=A.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`:A.current={accountId:t.accountId,accountLabel:t.accountLabel};break;case`account_retry`:t.accountId&&t.accountLabel&&(A.current={accountId:t.accountId,accountLabel:t.accountLabel}),k.current.push(t),G();break;case`text`:{let e=t.parentToolUseId;if(e&&W(t,e)){G();break}O.current+=t.content,k.current.push(t),G();break}case`thinking`:{let e=t.parentToolUseId;if(e&&W(t,e)){G();break}k.current.push(t),G();break}case`tool_use`:{let e=t.parentToolUseId;if(e&&W(t,e)){G();break}k.current.push(t),G();break}case`tool_result`:{let e=t.parentToolUseId;if(e&&W(t,e)){G();break}k.current.push(t),G();break}case`approval_request`:if(k.current.push(t),m({requestId:t.requestId,tool:t.tool,input:t.input}),F.current&&!ft(F.current)){let e=t.tool===`AskUserQuestion`?`question`:`approval_request`;Ie.getState().addNotification(F.current,e,I.current),ut(e)}break;case`error`:{k.current.push(t);let e=[...k.current];i(n=>{let r=n[n.length-1];return r?.role===`assistant`?[...n.slice(0,-1),{...r,events:e}]:[...n,{id:`error-${Date.now()}`,role:`system`,content:t.message,events:[t],timestamp:new Date().toISOString()}]});break}case`team_detected`:{let e=t.teamName;e&&(L.current.teamNames.add(e),v.get(`/api/teams/${encodeURIComponent(e)}`).then(e=>{if(e?.messages){let t=L.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())}V()}).catch(()=>{}),V());break}case`team_inbox`:{let e=t.messages;Array.isArray(e)&&(L.current.messages.push(...e),R.current+=e.length,V());break}case`team_updated`:V();break;case`done`:{if(j.current===`idle`)break;t.contextWindowPct!=null&&y(t.contextWindowPct),F.current&&!ft(F.current)&&(Ie.getState().addNotification(F.current,`done`,I.current),ut(`done`));let e=O.current,n=[...k.current];i(t=>{let r=t[t.length-1];return r?.role===`assistant`?[...t.slice(0,-1),{...r,id:`final-${Date.now()}`,content:e||r.content,events:n.length>0?n:r.events}]:t}),O.current=``,k.current=[],A.current=null;break}}},[W,G]),K=(0,Q.useCallback)(e=>{let t;try{t=JSON.parse(e.data)}catch{return}if(t.type!==`ping`){if(t.type===`session_migrated`){let e=t.newSessionId;e&&D(e);return}if(t.type===`title_updated`){C(t.title??null);return}if(t.type===`compact_status`){let e=t.status;e===`compacting`?x(`compacting`):e===`done`&&(x(null),P.current?.());return}if(t.type===`phase_changed`){let e=t.phase;c(e),j.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),j.current=n,e.sessionTitle&&C(e.sessionTitle),e.pendingApproval&&m({requestId:e.pendingApproval.requestId,tool:e.pendingApproval.tool,input:e.pendingApproval.input}),n===`idle`&&(P.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}),O.current=``,k.current=[],A.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:q,connect:J}=nt({url:e&&n?`/ws/project/${encodeURIComponent(n)}/chat/${e}`:``,onMessage:K,autoConnect:!!e&&!!n});N.current=q,(0,Q.useEffect)(()=>{let r=!1;return c(`idle`),j.current=`idle`,m(null),x(null),O.current=``,k.current=[],T(!1),L.current={teamNames:new Set,messages:[]},R.current=0,ee(dt),B([]),e&&n?(o(!0),fetch(`${g(n)}/chat/sessions/${e}/messages?providerId=${t}`,{headers:{Authorization:`Bearer ${_()}`}}).then(e=>e.json()).then(e=>{r||j.current!==`idle`||(e.ok&&Array.isArray(e.data)&&e.data.length>0?i(e.data):i([]))}).catch(()=>{!r&&j.current===`idle`&&i([])}).finally(()=>{r||o(!1)})):i([]),()=>{r=!0}},[e,t,n]);let re=(0,Q.useCallback)((e,t)=>{if(!e.trim())return;let n=j.current!==`idle`;if(n){let e=O.current,t=[...k.current];i(n=>{let r=n[n.length-1];return r?.role===`assistant`?[...n.slice(0,-1),{...r,id:`final-${Date.now()}`,content:e||r.content,events:t.length>0?t:r.events}]:n})}i(t=>[...t,{id:`user-${Date.now()}`,role:`user`,content:e,timestamp:new Date().toISOString()}]),O.current=``,k.current=[],M.current=null,n?(c(`thinking`),j.current=`thinking`):(c(`initializing`),j.current=`initializing`),m(null),q(JSON.stringify({type:`message`,content:e,permissionMode:t?.permissionMode,priority:t?.priority,images:t?.images}))},[q]),Y=(0,Q.useCallback)((e,t,n)=>{if(q(JSON.stringify({type:`approval_response`,requestId:e,approved:t,data:n})),t&&n){let t=k.current.find(t=>t.type===`approval_request`&&t.requestId===e&&t.tool===`AskUserQuestion`);if(t){let e=t.input;e&&typeof e==`object`&&(e.answers=n)}i(e=>[...e])}m(null)},[q]),ie=(0,Q.useCallback)(()=>{if(j.current===`idle`)return;q(JSON.stringify({type:`cancel`}));let e=O.current,t=[...k.current];i(n=>{let r=n[n.length-1];return r?.role===`assistant`?[...n.slice(0,-1),{...r,id:`final-${Date.now()}`,content:e||r.content,events:t.length>0?t:r.events}]:n}),O.current=``,k.current=[],M.current=null,c(`idle`),j.current=`idle`,m(null)},[q]),ae=(0,Q.useCallback)(()=>{T(!1),u(!0),J()},[J]),oe=(0,Q.useCallback)(()=>{!e||!n||(o(!0),fetch(`${g(n)}/chat/sessions/${e}/messages?providerId=${t}`,{headers:{Authorization:`Bearer ${_()}`}}).then(e=>e.json()).then(e=>{e.ok&&Array.isArray(e.data)&&e.data.length>0&&(i(e.data),O.current=``,k.current=[])}).catch(()=>{}).finally(()=>o(!1)))},[e,t,n]);return P.current=oe,{messages:r,messagesLoading:a,isStreaming:U,phase:s,isReconnecting:l,connectingElapsed:d,pendingApproval:p,contextWindowPct:h,compactStatus:b,sessionTitle:S,migratedSessionId:E,teamActivity:z,teamMessages:te,markTeamRead:H,sendMessage:re,respondToApproval:Y,cancelStreaming:ie,reconnect:ae,refetchMessages:oe,isConnected:w}}var mt=12e4;function ht(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(`${g(e)}/chat/usage?providerId=${t}${i}`,{headers:{Authorization:`Bearer ${_()}`}}).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(),mt),()=>{c.current&&clearInterval(c.current)}),[l]),{usageInfo:n,usageLoading:i,lastFetchedAt:o,refreshUsage:(0,Q.useCallback)(()=>l(!0),[l])}}var gt={damping:.7,stiffness:.05,mass:1.25},_t=70,vt=1e3/60,yt=350,bt=!1;globalThis.document?.addEventListener(`mousedown`,()=>{bt=!0}),globalThis.document?.addEventListener(`mouseup`,()=>{bt=!1}),globalThis.document?.addEventListener(`click`,()=>{bt=!1});var xt=(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(!bt)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<=_t}}},[]),f=(0,Q.useCallback)((e={})=>{typeof e==`string`&&(e={animation:e}),e.preserveScrollPosition||l(!0);let t=Date.now()+(Number(e.wait)||0),n=wt(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))/vt;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:wt(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=St(e=>{g.current?.removeEventListener(`scroll`,m),g.current?.removeEventListener(`wheel`,h),e?.addEventListener(`scroll`,m,{passive:!0}),e?.addEventListener(`wheel`,h,{passive:!0})},[]),_=St(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=wt(s.current,t?s.current.resize:s.current.initial);f({animation:e,wait:!0,preserveScrollPosition:!0,duration:e===`instant`?void 0:yt})}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 St(e,t){let n=(0,Q.useCallback)(t=>(n.current=t,e(t)),t);return n}var Ct=new Map;function wt(...e){let t={...gt},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 Ct.has(r)||Ct.set(r,Object.freeze(t)),n?`instant`:Ct.get(r)}var Tt=(0,Q.createContext)(null),Et=typeof window<`u`?Q.useLayoutEffect:Q.useEffect;function Dt({instance:e,children:t,resize:n,initial:r,mass:i,damping:a,stiffness:o,targetScrollTop:s,contextRef:c,...l}){let u=(0,Q.useRef)(null),d=xt({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]),Et(()=>{f.current&&getComputedStyle(f.current).overflow===`visible`&&(f.current.style.overflow=`auto`)},[]),Q.createElement(Tt.Provider,{value:y},Q.createElement(`div`,{...l},typeof t==`function`?t(y):t))}(function(e){function t({children:e,scrollClassName:t,...n}){let r=Ot();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})(Dt||={});function Ot(){let e=(0,Q.useContext)(Tt);if(!e)throw Error(`use-stick-to-bottom component context must be used within a StickToBottom component`);return e}var $=f();function kt(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 At({tool:e,result:t,completed:n,projectName:r}){let[a,o]=(0,Q.useState)(!1);if(e.type===`error`)return(0,$.jsxs)(`div`,{className:`flex items-center gap-2 rounded bg-red-500/10 border border-red-500/20 px-2 py-1.5 text-xs text-red-400`,children:[(0,$.jsx)(_e,{className:`size-3`}),(0,$.jsx)(`span`,{children:e.message})]});let{toolName:s,input:c}=kt(e),l=t?.type===`tool_result`,u=l&&!!t.isError,d=s===`AskUserQuestion`&&!!c?.answers,f=(s===`Agent`||s===`Task`)&&e.type===`tool_use`,p=f?e.children:void 0,m=p&&p.length>0;return(0,$.jsxs)(`div`,{className:`rounded border text-xs ${f?`border-accent/30 bg-accent/5`:`border-border bg-background`}`,children:[(0,$.jsxs)(`button`,{onClick:()=>o(!a),className:`flex items-center gap-2 px-2 py-1.5 w-full text-left hover:bg-surface transition-colors min-w-0`,children:[a?(0,$.jsx)(V,{className:`size-3 shrink-0`}):(0,$.jsx)(i,{className:`size-3 shrink-0`}),u?(0,$.jsx)(Re,{className:`size-3 text-red-400 shrink-0`}):l||d||n?(0,$.jsx)(W,{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)(jt,{name:s,input:c})}),m&&(0,$.jsxs)(`span`,{className:`ml-auto text-[10px] text-text-subtle shrink-0`,children:[p.length,` steps`]})]}),a&&(0,$.jsxs)(`div`,{className:`px-2 pb-2 space-y-1.5`,children:[(e.type===`tool_use`||e.type===`approval_request`)&&(0,$.jsx)(Mt,{name:s,input:c,projectName:r}),m&&(0,$.jsx)(It,{events:p,projectName:r}),l&&(0,$.jsx)(Pt,{toolName:s,output:t.output})]})]})}function jt({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:h(n(t.file_path))})]});case`Bash`:return(0,$.jsxs)($.Fragment,{children:[e,` `,(0,$.jsx)(`span`,{className:`font-mono text-text-subtle`,children:Rt(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:Rt(n(t.pattern),40)})]});case`WebSearch`:return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(je,{className:`size-3 inline`}),` `,e,` `,(0,$.jsx)(`span`,{className:`text-text-subtle`,children:Rt(n(t.query),50)})]});case`WebFetch`:return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(be,{className:`size-3 inline`}),` `,e,` `,(0,$.jsx)(`span`,{className:`text-text-subtle`,children:Rt(n(t.url),50)})]});case`ToolSearch`:return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(je,{className:`size-3 inline`}),` `,e,` `,(0,$.jsx)(`span`,{className:`text-text-subtle`,children:Rt(n(t.query),50)})]});case`Agent`:case`Task`:return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(R,{className:`size-3 inline`}),` `,e,` `,(0,$.jsx)(`span`,{className:`text-text-subtle`,children:Rt(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)(Ge,{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 Mt({name:e,input:t,projectName:n}){let r=e=>String(e??``),{openTab:i}=z(),a=e=>{n&&i({type:`editor`,title:h(e),metadata:{filePath:e,projectName:n},projectId:n,closable:!0})},o=(e,t,r)=>{i({type:`git-diff`,title:`Diff ${h(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)(P,{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)(s,{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:Rt(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)(Nt,{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)(Lt,{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)(be,{className:`size-3 shrink-0`}),r(t.url)]}),!!t.prompt&&(0,$.jsx)(`p`,{className:`text-text-subtle`,children:Rt(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 Nt({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 Pt({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)(Lt,{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)(a,{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)(Ft,{output:t})}function Ft({output:e}){let t=e.split(`
|
|
5
5
|
`).length,n=t>3||e.length>200,[r,a]=(0,Q.useState)(n);return(0,$.jsxs)(`div`,{className:`border-t border-border pt-1.5`,children:[n&&(0,$.jsxs)(`button`,{type:`button`,onClick:()=>a(!r),className:`flex items-center gap-1 text-[10px] text-text-subtle hover:text-text-secondary transition-colors mb-1`,children:[r?(0,$.jsx)(i,{className:`size-3`}):(0,$.jsx)(V,{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 It({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)(Lt,{content:e.content,maxHeight:`max-h-24`})},`st-${n}`):(0,$.jsx)(At,{tool:e.tool,result:e.result,completed:!!e.result,projectName:t},`sc-${n}`))})}function Lt({content:e,maxHeight:t=`max-h-48`}){return(0,$.jsx)(o,{content:e,className:`text-text-secondary overflow-auto ${t}`})}function Rt(e,t=50){return e?e.length>t?e.slice(0,t)+`…`:e:``}var zt=5,Bt=20;function Vt(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 Ht({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 v.get(`${g(e)}/chat/sessions`)).slice(0,Bt))}catch{}finally{a(!1)}}},[e]);(0,Q.useEffect)(()=>{c()},[c]);let l=(0,Q.useCallback)(async(t,n)=>{if(t.stopPropagation(),!e)return;let i=`${g(e)}/chat/sessions/${n.id}/pin`;try{n.pinned?await v.del(i):await v.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]),u=n.filter(e=>e.pinned),d=n.filter(e=>!e.pinned),f=o?d:d.slice(0,zt),p=d.length>zt;function m(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:Vt(e.updatedAt)}),(0,$.jsx)(`span`,{role:`button`,tabIndex:0,onClick:t=>l(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)(ke,{className:`size-3`}):(0,$.jsx)(Ce,{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)(R,{className:`size-10 text-text-subtle`}),(0,$.jsx)(`p`,{className:`text-sm`,children:`Send a message to start a new conversation`})]}),!i&&u.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:u.map(m)})]}),!i&&f.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:f.map(m)}),p&&(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)(N,{className:`size-3`}):(0,$.jsx)(V,{className:`size-3`}),o?`Show less`:`Show more (${d.length-zt})`]})]})]})}function Ut(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 Wt(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 Gt({questions:e,onSubmit:t,onSkip:n}){let r=(0,Q.useRef)(null),i=Ut(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=Wt({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 Kt({messages:e,messagesLoading:t,pendingApproval:n,onApprovalResponse:r,isStreaming:i,phase:a,onSelectSession:o,connectingElapsed:s,projectName:c,onFork:l}){if(t)return(0,$.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full gap-3 text-text-secondary`,children:[(0,$.jsx)(R,{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)(Ht,{projectName:c||``,onSelectSession:o||(()=>{})});let u=(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)(Dt,{className:`flex-1 overflow-y-auto overflow-x-hidden`,resize:`smooth`,initial:`instant`,children:[(0,$.jsxs)(Dt.Content,{className:`p-4 space-y-4`,children:[u.map((e,t)=>(0,$.jsx)(Jt,{message:e,isStreaming:i&&e.id.startsWith(`streaming-`),projectName:c,onFork:e.role===`user`&&l?()=>{let n=t>0?u[t-1]:void 0;l(e.content,n?.id)}:void 0},e.id)),n&&(n.tool===`AskUserQuestion`?(0,$.jsx)(bn,{approval:n,onRespond:r}):(0,$.jsx)(yn,{approval:n,onRespond:r})),i&&(0,$.jsx)(hn,{lastMessage:e[e.length-1],phase:a,elapsed:s})]}),(0,$.jsx)(qt,{})]})})}function qt(){let{isAtBottom:e,scrollToBottom:t}=Ot();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)(V,{className:`size-3`}),`Scroll to bottom`]})}function Jt({message:e,isStreaming:t,projectName:n,onFork:r}){return e.role===`user`?(0,$.jsx)(nn,{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)(_e,{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)(fn,{events:e.events,isStreaming:t,projectName:n}):e.content&&(0,$.jsx)(`div`,{className:`text-sm text-text-primary`,children:(0,$.jsx)(vn,{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 Yt=new Set([`.png`,`.jpg`,`.jpeg`,`.gif`,`.webp`]),Xt={"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 Zt(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:Xt[e]??e.replace(/^antml:/,``).replace(/-/g,` `),content:r[2].trim()})}return{cleanText:e.replace(n,``).trim(),tags:t}}function Qt(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,2 +1,2 @@
|
|
|
1
1
|
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/csv-preview-sx6DC51G.js","assets/chunk-CFjPhJqf.js","assets/lib-mag4ySk-.js","assets/react-nm2Ru1Pt.js","assets/createLucideIcon-PuMiQgHl.js","assets/arrow-up-BYhx9ckd.js","assets/react-dom-Bpkvzu3U.js","assets/jsx-runtime-kMwlnEGE.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{t as n}from"./createLucideIcon-PuMiQgHl.js";import{t as r}from"./chevron-right-5HgK6l7K.js";import{n as i,t as a}from"./markdown-renderer-BuGSrE3y.js";import{A as o}from"./dist-DRTW9IWi.js";import{t as s}from"./table-DFevCOMd.js";import{i as c,n as l,t as u}from"./use-monaco-theme-BdcKAZ69.js";import{t as d}from"./preload-helper-Bf_JiD2A.js";import{t as f}from"./jsx-runtime-kMwlnEGE.js";import{t as p}from"./utils-DMiycH3O.js";import{i as m,r as h,t as g}from"./api-client-BKIT_Qeg.js";import{C as _,Ct as v,G as y,J as b,L as x,St as S,_ as C,_t as w,b as T,bt as E,g as D,gt as O,h as k,pt as A,v as j,vt as M,x as N,xt as P,y as F,yt as I}from"./index-DUQgLj0D.js";import"./chunk-GEFDOKGD-tDjHsAUs.js";import"./src-Dw4QhedI.js";import"./chunk-7R4GIKGN-Dvbyu4Zw.js";import"./chunk-HHEYEP7N-BBw_z0fW.js";import"./dist-Cep75xXf.js";import"./chunk-PU5JKC2W-C7Gry6md.js";import"./chunk-MX3YWQON-C2UEioMs.js";import"./chunk-YBOYWFTD-av5aeHLq.js";import"./chunk-PQ6SQG4A-DX0xW7kO.js";import"./chunk-KYZI473N-Djw13C-3.js";import"./chunk-O4XLMI2P-BsUWb9d0.js";import"./chunk-GLR3WWYH-DBdWQ3zy.js";import"./chunk-XPW4576I-BPEX8KhL.js";var L=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`}]]),R=e(t(),1),z=f(),B={ts:E,tsx:E,js:E,jsx:E,py:E,rs:E,go:E,html:E,css:E,scss:E,json:P,md:I,txt:I,yaml:M,yml:M};function V(e,t){return t?O:B[e.split(`.`).pop()?.toLowerCase()??``]??w}function H(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 U(e){return[...e].sort((e,t)=>e.type===t.type?e.name.localeCompare(t.name):e.type===`directory`?-1:1)}function W({filePath:e,projectName:t,tabId:n,className:i}){let a=x(e=>e.tree),{updateTab:o,openTab:s}=y(),c=(0,R.useRef)(null),l=(0,R.useMemo)(()=>H(a,e.split(`/`).filter(Boolean)),[a,e]);(0,R.useEffect)(()=>{c.current&&(c.current.scrollLeft=c.current.scrollWidth)},[l]);function u(e,r){let i=p(e);r.metaKey||r.ctrlKey?s({type:`editor`,title:i,metadata:{filePath:e,projectName:t},projectId:t,closable:!0}):o(n,{title:i,metadata:{filePath:e,projectName:t}})}return(0,z.jsx)(`div`,{ref:c,className:i,children:l.map((e,n)=>(0,z.jsxs)(`div`,{className:`flex items-center shrink-0`,children:[n>0&&(0,z.jsx)(r,{className:`size-3 text-muted-foreground shrink-0 mx-0.5`}),e.siblings.length>0?(0,z.jsx)(G,{segment:e,isLast:n===l.length-1,projectName:t,onFileClick:u}):(0,z.jsx)(`span`,{className:`text-xs text-muted-foreground px-1 py-0.5`,children:e.name})]},e.fullPath))})}function G({segment:e,isLast:t,projectName:n,onFileClick:r}){let i=(0,R.useMemo)(()=>U(e.siblings),[e.siblings]);return(0,z.jsxs)(k,{children:[(0,z.jsx)(N,{asChild:!0,children:(0,z.jsx)(`button`,{type:`button`,className:`text-xs px-1 py-0.5 rounded hover:bg-muted transition-colors truncate max-w-[120px] ${t?`text-foreground font-medium`:`text-muted-foreground`}`,children:e.name})}),(0,z.jsx)(D,{align:`start`,className:`max-h-[300px] p-1`,children:i.map(t=>(0,z.jsx)(K,{node:t,projectName:n,activePath:e.fullPath,onFileClick:r},t.path))})]})}function K({node:e,projectName:t,activePath:n,onFileClick:r}){let i=V(e.name,e.type===`directory`),a=e.path===n;return e.type===`directory`&&e.children&&e.children.length>0?(0,z.jsxs)(j,{children:[(0,z.jsxs)(T,{className:`text-xs gap-1.5 ${a?`bg-muted`:``}`,children:[(0,z.jsx)(i,{className:`size-3.5 shrink-0 text-muted-foreground`}),(0,z.jsx)(`span`,{className:`truncate`,children:e.name})]}),(0,z.jsx)(F,{className:`max-h-[300px] overflow-y-auto p-1`,children:U(e.children).map(e=>(0,z.jsx)(K,{node:e,projectName:t,activePath:n,onFileClick:r},e.path))})]}):(0,z.jsxs)(C,{className:`text-xs gap-1.5 cursor-pointer ${a?`bg-muted`:``}`,onSelect:e=>{},onClick:t=>{e.type!==`directory`&&r(e.path,t)},children:[(0,z.jsx)(i,{className:`size-3.5 shrink-0 text-muted-foreground`}),(0,z.jsx)(`span`,{className:`truncate`,children:e.name})]})}function q({active:e,onClick:t,icon:n,label:r}){return(0,z.jsxs)(`button`,{type:`button`,onClick:t,className:`flex items-center gap-1 px-2 py-1 rounded text-xs transition-colors ${e?`bg-muted text-foreground`:`text-muted-foreground hover:text-foreground`}`,children:[(0,z.jsx)(n,{className:`size-3`}),(0,z.jsx)(`span`,{className:`hidden sm:inline`,children:r})]})}function J({ext:e,mdMode:t,onMdModeChange:n,csvMode:r,onCsvModeChange:a,wordWrap:l,onToggleWordWrap:u,filePath:d,projectName:f,className:p}){return(0,z.jsxs)(`div`,{className:p,children:[(e===`md`||e===`mdx`)&&n&&(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(q,{active:t===`edit`,onClick:()=>n(`edit`),icon:i,label:`Edit`}),(0,z.jsx)(q,{active:t===`preview`,onClick:()=>n(`preview`),icon:S,label:`Preview`})]}),e===`csv`&&a&&(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(q,{active:r===`table`,onClick:()=>a(`table`),icon:s,label:`Table`}),(0,z.jsx)(q,{active:r===`raw`,onClick:()=>a(`raw`),icon:i,label:`Raw`})]}),(0,z.jsx)(q,{active:l,onClick:u,icon:c,label:`Wrap`}),d&&f&&(0,z.jsx)(q,{active:!1,onClick:()=>_(f,d),icon:o,label:`Download`})]})}var Y=(0,R.lazy)(()=>d(()=>import(`./csv-preview-sx6DC51G.js`).then(e=>({default:e.CsvPreview})),__vite__mapDeps([0,1,2,3,4,5,6,7]))),X=new Set([`png`,`jpg`,`jpeg`,`gif`,`webp`,`svg`,`ico`]),Z=new Set([`db`,`sqlite`,`sqlite3`]);function Q(e){return e.split(`.`).pop()?.toLowerCase()??``}function ee(e){return{js:`javascript`,jsx:`javascript`,ts:`typescript`,tsx:`typescript`,py:`python`,html:`html`,css:`css`,scss:`scss`,json:`json`,md:`markdown`,mdx:`markdown`,yaml:`yaml`,yml:`yaml`,sh:`shell`,bash:`shell`}[Q(e)]??`plaintext`}function $({metadata:e,tabId:t}){let n=e?.filePath,r=e?.projectName,[i,a]=(0,R.useState)(null),[o,s]=(0,R.useState)(`utf-8`),[c,d]=(0,R.useState)(!0),[f,h]=(0,R.useState)(null),[_,v]=(0,R.useState)(!1),x=(0,R.useRef)(null),S=(0,R.useRef)(``),C=(0,R.useRef)(null),{tabs:w,updateTab:T}=y(),{wordWrap:E,toggleWordWrap:D}=b(),O=u(),k=w.find(e=>e.id===t),j=n?Q(n):``,M=X.has(j),N=j===`pdf`,P=Z.has(j),F=j===`md`||j===`mdx`,I=j===`csv`,[B,V]=(0,R.useState)(`preview`),[H,U]=(0,R.useState)(`table`);(0,R.useEffect)(()=>{P&&t&&T(t,{type:`sqlite`})},[P,t,T]);let G=n?/^(\/|[A-Za-z]:[/\\])/.test(n):!1;(0,R.useEffect)(()=>{if(!n||!G&&!r)return;if(M||N){d(!1);return}d(!0),h(null);let e=G?`/api/fs/read?path=${encodeURIComponent(n)}`:`${m(r)}/files/read?path=${encodeURIComponent(n)}`;return g.get(e).then(e=>{a(e.content),e.encoding&&s(e.encoding),S.current=e.content,d(!1)}).catch(e=>{h(e instanceof Error?e.message:`Failed to load file`),d(!1)}),()=>{x.current&&clearTimeout(x.current)}},[n,r,M,N,G]),(0,R.useEffect)(()=>{if(!k)return;let e=n?p(n):`Untitled`,t=_?`${e} \u25CF`:e;k.title!==t&&T(k.id,{title:t})},[_]);let K=(0,R.useCallback)(async e=>{if(n&&!(!G&&!r))try{G?await g.put(`/api/fs/write`,{path:n,content:e}):await g.put(`${m(r)}/files/write`,{path:n,content:e}),v(!1)}catch{}},[n,r,G]);function q(e){let t=e??``;a(t),S.current=t,v(!0),x.current&&clearTimeout(x.current),x.current=setTimeout(()=>K(S.current),1e3)}let $=e?.lineNumber,ie=(0,R.useCallback)((e,t)=>{C.current=e,$&&$>0&&setTimeout(()=>{e.revealLineInCenter($),e.setPosition({lineNumber:$,column:1}),e.focus()},100),e.addCommand(t.KeyMod.Alt|t.KeyCode.KeyZ,()=>b.getState().toggleWordWrap()),t.languages.typescript.typescriptDefaults.setDiagnosticsOptions({noSemanticValidation:!0,noSyntaxValidation:!0,noSuggestionDiagnostics:!0}),t.languages.typescript.javascriptDefaults.setDiagnosticsOptions({noSemanticValidation:!0,noSyntaxValidation:!0,noSuggestionDiagnostics:!0})},[]);return!n||!G&&!r?(0,z.jsx)(`div`,{className:`flex items-center justify-center h-full text-text-secondary text-sm`,children:`No file selected.`}):c?(0,z.jsxs)(`div`,{className:`flex items-center justify-center h-full gap-2 text-text-secondary`,children:[(0,z.jsx)(A,{className:`size-5 animate-spin`}),(0,z.jsx)(`span`,{className:`text-sm`,children:`Loading file...`})]}):f?(0,z.jsx)(`div`,{className:`flex items-center justify-center h-full text-error text-sm`,children:f}):M?(0,z.jsx)(ne,{filePath:n,projectName:r}):N?(0,z.jsx)(re,{filePath:n,projectName:r}):o===`base64`?(0,z.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full gap-3 text-text-secondary`,children:[(0,z.jsx)(L,{className:`size-10 text-text-subtle`}),(0,z.jsx)(`p`,{className:`text-sm`,children:`This file is a binary format and cannot be displayed.`}),(0,z.jsx)(`p`,{className:`text-xs text-text-subtle`,children:n})]}):(0,z.jsxs)(`div`,{className:`flex flex-col h-full w-full overflow-hidden`,children:[n&&r&&t&&(0,z.jsxs)(`div`,{className:`hidden md:flex items-center h-7 border-b border-border bg-background shrink-0`,children:[(0,z.jsx)(W,{filePath:n,projectName:r,tabId:t,className:`flex items-center flex-1 min-w-0 overflow-x-auto scrollbar-none px-2 gap-0.5`}),(0,z.jsx)(J,{ext:j,mdMode:B,onMdModeChange:V,csvMode:H,onCsvModeChange:U,wordWrap:E,onToggleWordWrap:D,filePath:n,projectName:r,className:`shrink-0 flex items-center gap-1 px-2`})]}),I&&H===`table`?(0,z.jsx)(R.Suspense,{fallback:(0,z.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,z.jsx)(A,{className:`size-5 animate-spin text-text-subtle`})}),children:(0,z.jsx)(Y,{content:i??``,onContentChange:q,wordWrap:E})}):F&&B===`preview`?(0,z.jsx)(te,{content:i??``}):(0,z.jsx)(`div`,{className:`flex-1 overflow-hidden`,children:(0,z.jsx)(l,{height:`100%`,language:ee(n),value:i??``,onChange:q,onMount:ie,theme:O,options:{fontSize:13,fontFamily:`Menlo, Monaco, Consolas, monospace`,wordWrap:E?`on`:`off`,minimap:{enabled:!1},scrollBeyondLastLine:!1,automaticLayout:!0,lineNumbers:`on`,folding:!0,bracketPairColorization:{enabled:!0}},loading:(0,z.jsx)(A,{className:`size-5 animate-spin text-text-subtle`})})})]})}function te({content:e}){return(0,z.jsx)(a,{content:e,className:`flex-1 overflow-auto p-4`})}function ne({filePath:e,projectName:t}){let[n,r]=(0,R.useState)(null),[i,a]=(0,R.useState)(!1);return(0,R.useEffect)(()=>{let n,i=`${m(t)}/files/raw?path=${encodeURIComponent(e)}`,o=h();return fetch(i,{headers:o?{Authorization:`Bearer ${o}`}:{}}).then(e=>{if(!e.ok)throw Error(`Failed`);return e.blob()}).then(e=>{let t=URL.createObjectURL(e);n=t,r(t)}).catch(()=>a(!0)),()=>{n&&URL.revokeObjectURL(n)}},[e,t]),i?(0,z.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full gap-3 text-text-secondary`,children:[(0,z.jsx)(L,{className:`size-10 text-text-subtle`}),(0,z.jsx)(`p`,{className:`text-sm`,children:`Failed to load image.`})]}):n?(0,z.jsx)(`div`,{className:`flex items-center justify-center h-full p-4 bg-surface overflow-auto`,children:(0,z.jsx)(`img`,{src:n,alt:e,className:`max-w-full max-h-full object-contain`})}):(0,z.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,z.jsx)(A,{className:`size-5 animate-spin text-text-subtle`})})}function re({filePath:e,projectName:t}){let[n,r]=(0,R.useState)(null),[i,a]=(0,R.useState)(!1);(0,R.useEffect)(()=>{let n,i=`${m(t)}/files/raw?path=${encodeURIComponent(e)}`,o=h();return fetch(i,{headers:o?{Authorization:`Bearer ${o}`}:{}}).then(e=>{if(!e.ok)throw Error(`Failed`);return e.blob()}).then(e=>{let t=URL.createObjectURL(new Blob([e],{type:`application/pdf`}));n=t,r(t)}).catch(()=>a(!0)),()=>{n&&URL.revokeObjectURL(n)}},[e,t]);let o=(0,R.useCallback)(()=>{n&&window.open(n,`_blank`)},[n]);return i?(0,z.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full gap-3 text-text-secondary`,children:[(0,z.jsx)(L,{className:`size-10 text-text-subtle`}),(0,z.jsx)(`p`,{className:`text-sm`,children:`Failed to load PDF.`})]}):n?(0,z.jsxs)(`div`,{className:`flex flex-col h-full`,children:[(0,z.jsxs)(`div`,{className:`flex items-center justify-between px-3 py-1.5 border-b border-border bg-background shrink-0`,children:[(0,z.jsx)(`span`,{className:`text-xs text-text-secondary truncate`,children:e}),(0,z.jsxs)(`button`,{onClick:o,className:`flex items-center gap-1 text-xs text-text-secondary hover:text-text-primary transition-colors`,children:[(0,z.jsx)(v,{className:`size-3`}),` Open in new tab`]})]}),(0,z.jsx)(`iframe`,{src:n,title:e,className:`flex-1 w-full border-none`})]}):(0,z.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,z.jsx)(A,{className:`size-5 animate-spin text-text-subtle`})})}export{$ as CodeEditor};
|
|
2
|
+
import{o as e}from"./chunk-CFjPhJqf.js";import{t}from"./react-nm2Ru1Pt.js";import"./react-dom-Bpkvzu3U.js";import{t as n}from"./createLucideIcon-PuMiQgHl.js";import{t as r}from"./chevron-right-5HgK6l7K.js";import{n as i,t as a}from"./markdown-renderer-CSEmmMWt.js";import{A as o}from"./dist-DRTW9IWi.js";import{t as s}from"./table-DFevCOMd.js";import{i as c,n as l,t as u}from"./use-monaco-theme-VPgvhMpB.js";import{t as d}from"./preload-helper-Bf_JiD2A.js";import{t as f}from"./jsx-runtime-kMwlnEGE.js";import{t as p}from"./utils-DMiycH3O.js";import{i as m,r as h,t as g}from"./api-client-BKIT_Qeg.js";import{C as _,Ct as v,G as y,J as b,L as x,St as S,_ as C,_t as w,b as T,bt as E,g as D,gt as O,h as k,pt as A,v as j,vt as M,x as N,xt as P,y as F,yt as I}from"./index-CDlrGSwd.js";import"./chunk-GEFDOKGD-tDjHsAUs.js";import"./src-Dw4QhedI.js";import"./chunk-7R4GIKGN-Dvbyu4Zw.js";import"./chunk-HHEYEP7N-BBw_z0fW.js";import"./dist-Cep75xXf.js";import"./chunk-PU5JKC2W-C7Gry6md.js";import"./chunk-MX3YWQON-C2UEioMs.js";import"./chunk-YBOYWFTD-av5aeHLq.js";import"./chunk-PQ6SQG4A-DX0xW7kO.js";import"./chunk-KYZI473N-Djw13C-3.js";import"./chunk-O4XLMI2P-BsUWb9d0.js";import"./chunk-GLR3WWYH-DBdWQ3zy.js";import"./chunk-XPW4576I-BPEX8KhL.js";var L=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`}]]),R=e(t(),1),z=f(),B={ts:E,tsx:E,js:E,jsx:E,py:E,rs:E,go:E,html:E,css:E,scss:E,json:P,md:I,txt:I,yaml:M,yml:M};function V(e,t){return t?O:B[e.split(`.`).pop()?.toLowerCase()??``]??w}function H(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 U(e){return[...e].sort((e,t)=>e.type===t.type?e.name.localeCompare(t.name):e.type===`directory`?-1:1)}function W({filePath:e,projectName:t,tabId:n,className:i}){let a=x(e=>e.tree),{updateTab:o,openTab:s}=y(),c=(0,R.useRef)(null),l=(0,R.useMemo)(()=>H(a,e.split(`/`).filter(Boolean)),[a,e]);(0,R.useEffect)(()=>{c.current&&(c.current.scrollLeft=c.current.scrollWidth)},[l]);function u(e,r){let i=p(e);r.metaKey||r.ctrlKey?s({type:`editor`,title:i,metadata:{filePath:e,projectName:t},projectId:t,closable:!0}):o(n,{title:i,metadata:{filePath:e,projectName:t}})}return(0,z.jsx)(`div`,{ref:c,className:i,children:l.map((e,n)=>(0,z.jsxs)(`div`,{className:`flex items-center shrink-0`,children:[n>0&&(0,z.jsx)(r,{className:`size-3 text-muted-foreground shrink-0 mx-0.5`}),e.siblings.length>0?(0,z.jsx)(G,{segment:e,isLast:n===l.length-1,projectName:t,onFileClick:u}):(0,z.jsx)(`span`,{className:`text-xs text-muted-foreground px-1 py-0.5`,children:e.name})]},e.fullPath))})}function G({segment:e,isLast:t,projectName:n,onFileClick:r}){let i=(0,R.useMemo)(()=>U(e.siblings),[e.siblings]);return(0,z.jsxs)(k,{children:[(0,z.jsx)(N,{asChild:!0,children:(0,z.jsx)(`button`,{type:`button`,className:`text-xs px-1 py-0.5 rounded hover:bg-muted transition-colors truncate max-w-[120px] ${t?`text-foreground font-medium`:`text-muted-foreground`}`,children:e.name})}),(0,z.jsx)(D,{align:`start`,className:`max-h-[300px] p-1`,children:i.map(t=>(0,z.jsx)(K,{node:t,projectName:n,activePath:e.fullPath,onFileClick:r},t.path))})]})}function K({node:e,projectName:t,activePath:n,onFileClick:r}){let i=V(e.name,e.type===`directory`),a=e.path===n;return e.type===`directory`&&e.children&&e.children.length>0?(0,z.jsxs)(j,{children:[(0,z.jsxs)(T,{className:`text-xs gap-1.5 ${a?`bg-muted`:``}`,children:[(0,z.jsx)(i,{className:`size-3.5 shrink-0 text-muted-foreground`}),(0,z.jsx)(`span`,{className:`truncate`,children:e.name})]}),(0,z.jsx)(F,{className:`max-h-[300px] overflow-y-auto p-1`,children:U(e.children).map(e=>(0,z.jsx)(K,{node:e,projectName:t,activePath:n,onFileClick:r},e.path))})]}):(0,z.jsxs)(C,{className:`text-xs gap-1.5 cursor-pointer ${a?`bg-muted`:``}`,onSelect:e=>{},onClick:t=>{e.type!==`directory`&&r(e.path,t)},children:[(0,z.jsx)(i,{className:`size-3.5 shrink-0 text-muted-foreground`}),(0,z.jsx)(`span`,{className:`truncate`,children:e.name})]})}function q({active:e,onClick:t,icon:n,label:r}){return(0,z.jsxs)(`button`,{type:`button`,onClick:t,className:`flex items-center gap-1 px-2 py-1 rounded text-xs transition-colors ${e?`bg-muted text-foreground`:`text-muted-foreground hover:text-foreground`}`,children:[(0,z.jsx)(n,{className:`size-3`}),(0,z.jsx)(`span`,{className:`hidden sm:inline`,children:r})]})}function J({ext:e,mdMode:t,onMdModeChange:n,csvMode:r,onCsvModeChange:a,wordWrap:l,onToggleWordWrap:u,filePath:d,projectName:f,className:p}){return(0,z.jsxs)(`div`,{className:p,children:[(e===`md`||e===`mdx`)&&n&&(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(q,{active:t===`edit`,onClick:()=>n(`edit`),icon:i,label:`Edit`}),(0,z.jsx)(q,{active:t===`preview`,onClick:()=>n(`preview`),icon:S,label:`Preview`})]}),e===`csv`&&a&&(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(q,{active:r===`table`,onClick:()=>a(`table`),icon:s,label:`Table`}),(0,z.jsx)(q,{active:r===`raw`,onClick:()=>a(`raw`),icon:i,label:`Raw`})]}),(0,z.jsx)(q,{active:l,onClick:u,icon:c,label:`Wrap`}),d&&f&&(0,z.jsx)(q,{active:!1,onClick:()=>_(f,d),icon:o,label:`Download`})]})}var Y=(0,R.lazy)(()=>d(()=>import(`./csv-preview-sx6DC51G.js`).then(e=>({default:e.CsvPreview})),__vite__mapDeps([0,1,2,3,4,5,6,7]))),X=new Set([`png`,`jpg`,`jpeg`,`gif`,`webp`,`svg`,`ico`]),Z=new Set([`db`,`sqlite`,`sqlite3`]);function Q(e){return e.split(`.`).pop()?.toLowerCase()??``}function ee(e){return{js:`javascript`,jsx:`javascript`,ts:`typescript`,tsx:`typescript`,py:`python`,html:`html`,css:`css`,scss:`scss`,json:`json`,md:`markdown`,mdx:`markdown`,yaml:`yaml`,yml:`yaml`,sh:`shell`,bash:`shell`}[Q(e)]??`plaintext`}function $({metadata:e,tabId:t}){let n=e?.filePath,r=e?.projectName,[i,a]=(0,R.useState)(null),[o,s]=(0,R.useState)(`utf-8`),[c,d]=(0,R.useState)(!0),[f,h]=(0,R.useState)(null),[_,v]=(0,R.useState)(!1),x=(0,R.useRef)(null),S=(0,R.useRef)(``),C=(0,R.useRef)(null),{tabs:w,updateTab:T}=y(),{wordWrap:E,toggleWordWrap:D}=b(),O=u(),k=w.find(e=>e.id===t),j=n?Q(n):``,M=X.has(j),N=j===`pdf`,P=Z.has(j),F=j===`md`||j===`mdx`,I=j===`csv`,[B,V]=(0,R.useState)(`preview`),[H,U]=(0,R.useState)(`table`);(0,R.useEffect)(()=>{P&&t&&T(t,{type:`sqlite`})},[P,t,T]);let G=n?/^(\/|[A-Za-z]:[/\\])/.test(n):!1;(0,R.useEffect)(()=>{if(!n||!G&&!r)return;if(M||N){d(!1);return}d(!0),h(null);let e=G?`/api/fs/read?path=${encodeURIComponent(n)}`:`${m(r)}/files/read?path=${encodeURIComponent(n)}`;return g.get(e).then(e=>{a(e.content),e.encoding&&s(e.encoding),S.current=e.content,d(!1)}).catch(e=>{h(e instanceof Error?e.message:`Failed to load file`),d(!1)}),()=>{x.current&&clearTimeout(x.current)}},[n,r,M,N,G]),(0,R.useEffect)(()=>{if(!k)return;let e=n?p(n):`Untitled`,t=_?`${e} \u25CF`:e;k.title!==t&&T(k.id,{title:t})},[_]);let K=(0,R.useCallback)(async e=>{if(n&&!(!G&&!r))try{G?await g.put(`/api/fs/write`,{path:n,content:e}):await g.put(`${m(r)}/files/write`,{path:n,content:e}),v(!1)}catch{}},[n,r,G]);function q(e){let t=e??``;a(t),S.current=t,v(!0),x.current&&clearTimeout(x.current),x.current=setTimeout(()=>K(S.current),1e3)}let $=e?.lineNumber,ie=(0,R.useCallback)((e,t)=>{C.current=e,$&&$>0&&setTimeout(()=>{e.revealLineInCenter($),e.setPosition({lineNumber:$,column:1}),e.focus()},100),e.addCommand(t.KeyMod.Alt|t.KeyCode.KeyZ,()=>b.getState().toggleWordWrap()),t.languages.typescript.typescriptDefaults.setDiagnosticsOptions({noSemanticValidation:!0,noSyntaxValidation:!0,noSuggestionDiagnostics:!0}),t.languages.typescript.javascriptDefaults.setDiagnosticsOptions({noSemanticValidation:!0,noSyntaxValidation:!0,noSuggestionDiagnostics:!0})},[]);return!n||!G&&!r?(0,z.jsx)(`div`,{className:`flex items-center justify-center h-full text-text-secondary text-sm`,children:`No file selected.`}):c?(0,z.jsxs)(`div`,{className:`flex items-center justify-center h-full gap-2 text-text-secondary`,children:[(0,z.jsx)(A,{className:`size-5 animate-spin`}),(0,z.jsx)(`span`,{className:`text-sm`,children:`Loading file...`})]}):f?(0,z.jsx)(`div`,{className:`flex items-center justify-center h-full text-error text-sm`,children:f}):M?(0,z.jsx)(ne,{filePath:n,projectName:r}):N?(0,z.jsx)(re,{filePath:n,projectName:r}):o===`base64`?(0,z.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full gap-3 text-text-secondary`,children:[(0,z.jsx)(L,{className:`size-10 text-text-subtle`}),(0,z.jsx)(`p`,{className:`text-sm`,children:`This file is a binary format and cannot be displayed.`}),(0,z.jsx)(`p`,{className:`text-xs text-text-subtle`,children:n})]}):(0,z.jsxs)(`div`,{className:`flex flex-col h-full w-full overflow-hidden`,children:[n&&r&&t&&(0,z.jsxs)(`div`,{className:`hidden md:flex items-center h-7 border-b border-border bg-background shrink-0`,children:[(0,z.jsx)(W,{filePath:n,projectName:r,tabId:t,className:`flex items-center flex-1 min-w-0 overflow-x-auto scrollbar-none px-2 gap-0.5`}),(0,z.jsx)(J,{ext:j,mdMode:B,onMdModeChange:V,csvMode:H,onCsvModeChange:U,wordWrap:E,onToggleWordWrap:D,filePath:n,projectName:r,className:`shrink-0 flex items-center gap-1 px-2`})]}),I&&H===`table`?(0,z.jsx)(R.Suspense,{fallback:(0,z.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,z.jsx)(A,{className:`size-5 animate-spin text-text-subtle`})}),children:(0,z.jsx)(Y,{content:i??``,onContentChange:q,wordWrap:E})}):F&&B===`preview`?(0,z.jsx)(te,{content:i??``}):(0,z.jsx)(`div`,{className:`flex-1 overflow-hidden`,children:(0,z.jsx)(l,{height:`100%`,language:ee(n),value:i??``,onChange:q,onMount:ie,theme:O,options:{fontSize:13,fontFamily:`Menlo, Monaco, Consolas, monospace`,wordWrap:E?`on`:`off`,minimap:{enabled:!1},scrollBeyondLastLine:!1,automaticLayout:!0,lineNumbers:`on`,folding:!0,bracketPairColorization:{enabled:!0}},loading:(0,z.jsx)(A,{className:`size-5 animate-spin text-text-subtle`})})})]})}function te({content:e}){return(0,z.jsx)(a,{content:e,className:`flex-1 overflow-auto p-4`})}function ne({filePath:e,projectName:t}){let[n,r]=(0,R.useState)(null),[i,a]=(0,R.useState)(!1);return(0,R.useEffect)(()=>{let n,i=`${m(t)}/files/raw?path=${encodeURIComponent(e)}`,o=h();return fetch(i,{headers:o?{Authorization:`Bearer ${o}`}:{}}).then(e=>{if(!e.ok)throw Error(`Failed`);return e.blob()}).then(e=>{let t=URL.createObjectURL(e);n=t,r(t)}).catch(()=>a(!0)),()=>{n&&URL.revokeObjectURL(n)}},[e,t]),i?(0,z.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full gap-3 text-text-secondary`,children:[(0,z.jsx)(L,{className:`size-10 text-text-subtle`}),(0,z.jsx)(`p`,{className:`text-sm`,children:`Failed to load image.`})]}):n?(0,z.jsx)(`div`,{className:`flex items-center justify-center h-full p-4 bg-surface overflow-auto`,children:(0,z.jsx)(`img`,{src:n,alt:e,className:`max-w-full max-h-full object-contain`})}):(0,z.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,z.jsx)(A,{className:`size-5 animate-spin text-text-subtle`})})}function re({filePath:e,projectName:t}){let[n,r]=(0,R.useState)(null),[i,a]=(0,R.useState)(!1);(0,R.useEffect)(()=>{let n,i=`${m(t)}/files/raw?path=${encodeURIComponent(e)}`,o=h();return fetch(i,{headers:o?{Authorization:`Bearer ${o}`}:{}}).then(e=>{if(!e.ok)throw Error(`Failed`);return e.blob()}).then(e=>{let t=URL.createObjectURL(new Blob([e],{type:`application/pdf`}));n=t,r(t)}).catch(()=>a(!0)),()=>{n&&URL.revokeObjectURL(n)}},[e,t]);let o=(0,R.useCallback)(()=>{n&&window.open(n,`_blank`)},[n]);return i?(0,z.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full gap-3 text-text-secondary`,children:[(0,z.jsx)(L,{className:`size-10 text-text-subtle`}),(0,z.jsx)(`p`,{className:`text-sm`,children:`Failed to load PDF.`})]}):n?(0,z.jsxs)(`div`,{className:`flex flex-col h-full`,children:[(0,z.jsxs)(`div`,{className:`flex items-center justify-between px-3 py-1.5 border-b border-border bg-background shrink-0`,children:[(0,z.jsx)(`span`,{className:`text-xs text-text-secondary truncate`,children:e}),(0,z.jsxs)(`button`,{onClick:o,className:`flex items-center gap-1 text-xs text-text-secondary hover:text-text-primary transition-colors`,children:[(0,z.jsx)(v,{className:`size-3`}),` Open in new tab`]})]}),(0,z.jsx)(`iframe`,{src:n,title:e,className:`flex-1 w-full border-none`})]}):(0,z.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,z.jsx)(A,{className:`size-5 animate-spin text-text-subtle`})})}export{$ as CodeEditor};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{o as e}from"./chunk-CFjPhJqf.js";import{t}from"./react-nm2Ru1Pt.js";import{t as n}from"./chevron-right-5HgK6l7K.js";import{t as r}from"./jsx-runtime-kMwlnEGE.js";import{t as i}from"./api-client-BKIT_Qeg.js";import{Q as a,at as o,jt as s,pt as c,rt as l,wt as u}from"./index-CDlrGSwd.js";import{n as d,r as f,t as p}from"./lib-mag4ySk-.js";import{i as m,n as h,r as g,t as _}from"./dist-C40JmyoH.js";var v=e(t(),1);function y(e,t,n,r){return`ppm-db-${e}-${n}.${t}-p${r}`}function b(e,t,n,r){try{let i=sessionStorage.getItem(y(e,t,n,r));return i?JSON.parse(i):null}catch{return null}}function x(e,t,n,r,i,a){try{sessionStorage.setItem(y(e,t,n,r),JSON.stringify({data:i,cols:a}))}catch{}}function S(e){let t=`/api/db/connections/${e}`,[n,r]=(0,v.useState)(null),[a,o]=(0,v.useState)(`public`),[s,c]=(0,v.useState)(null),[l,u]=(0,v.useState)([]),[d,f]=(0,v.useState)(!0),[p,m]=(0,v.useState)(null),[h,g]=(0,v.useState)(1),[_,y]=(0,v.useState)(null),[S,C]=(0,v.useState)(null),[w,T]=(0,v.useState)(!1),E=(0,v.useCallback)(async(r,o,s)=>{let l=r??n,d=o??a;if(l){f(!0);try{let[n,r]=await Promise.all([i.get(`${t}/data?table=${encodeURIComponent(l)}&schema=${d}&page=${s??h}&limit=100`),i.get(`${t}/schema?table=${encodeURIComponent(l)}&schema=${d}`)]);c(n),u(r),x(e,l,d,s??h,n,r)}catch(e){m(e.message)}finally{f(!1)}}},[t,e,n,a,h]);return{selectedTable:n,selectTable:(0,v.useCallback)((t,n=`public`)=>{r(t),o(n),g(1),y(null);let i=b(e,t,n,1);i?(c(i.data),u(i.cols),f(!1),E(t,n,1)):E(t,n,1)},[e,E]),tableData:s,schema:l,loading:d,error:p,page:h,setPage:(0,v.useCallback)(e=>{g(e),E(void 0,void 0,e)},[E]),queryResult:_,queryError:S,queryLoading:w,executeQuery:(0,v.useCallback)(async e=>{T(!0),C(null);try{let r=await i.post(`${t}/query`,{sql:e});y(r),r.changeType===`modify`&&E(n??void 0,a)}catch(e){C(e.message)}finally{T(!1)}},[t,n,a,E]),updateCell:(0,v.useCallback)(async(e,r,o,s)=>{if(!n)return;let c=n,l=a;try{await i.put(`${t}/cell`,{table:c,schema:l,pkColumn:e,pkValue:r,column:o,value:s}),E(c,l)}catch(e){m(e.message)}},[t,n,a,E]),deleteRow:(0,v.useCallback)(async(e,r)=>{if(!n)return;let o=n,s=a;try{await i.del(`${t}/row`,{table:o,schema:s,pkColumn:e,pkValue:r}),E(o,s)}catch(e){m(e.message)}},[t,n,a,E]),refreshData:E}}var C=r(),w={postgres:_,sqlite:h};function T({metadata:e}){let t=e?.connectionId,n=e?.connectionName,r=e?.dbType??`postgres`,i=e?.tableName,a=e?.schemaName??`public`,o=S(t),[s,c]=(0,v.useState)(!1),d=(0,v.useRef)(!1);return(0,v.useEffect)(()=>{!i||d.current||(d.current=!0,o.selectTable(i,a))},[i,a]),(0,C.jsx)(`div`,{className:`flex h-full w-full overflow-hidden`,children:(0,C.jsxs)(`div`,{className:`flex-1 flex flex-col overflow-hidden`,children:[(0,C.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-1.5 border-b border-border bg-background shrink-0`,children:[(0,C.jsx)(u,{className:`size-3.5 text-muted-foreground`}),(0,C.jsx)(`span`,{className:`text-xs text-muted-foreground truncate`,children:n??`Database`}),o.selectedTable&&(0,C.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[`/ `,o.selectedTable]}),(0,C.jsxs)(`div`,{className:`ml-auto flex items-center gap-1`,children:[(0,C.jsx)(`button`,{type:`button`,onClick:()=>o.refreshData(),title:`Reload data`,className:`p-1 rounded text-muted-foreground hover:text-foreground transition-colors`,children:(0,C.jsx)(l,{className:`size-3 ${o.loading?`animate-spin`:``}`})}),(0,C.jsx)(`button`,{type:`button`,onClick:()=>c(e=>!e),className:`px-2 py-1 rounded text-xs transition-colors ${s?`bg-muted text-foreground`:`text-muted-foreground hover:text-foreground`}`,children:`SQL`})]})]}),(0,C.jsx)(`div`,{className:`flex-1 overflow-hidden ${s?`max-h-[60%]`:``}`,children:(0,C.jsx)(E,{tableData:o.tableData,schema:o.schema,loading:o.loading,page:o.page,onPageChange:o.setPage,onCellUpdate:o.updateCell,onRowDelete:o.deleteRow})}),s&&(0,C.jsx)(`div`,{className:`border-t border-border h-[40%] shrink-0`,children:(0,C.jsx)(D,{dialect:w[r]??_,onExecute:o.executeQuery,result:o.queryResult,error:o.queryError,loading:o.queryLoading})})]})})}function E({tableData:e,schema:t,loading:r,page:i,onPageChange:o,onCellUpdate:l,onRowDelete:u}){let[m,h]=(0,v.useState)(null),[g,_]=(0,v.useState)(``),[y,b]=(0,v.useState)(null),x=(0,v.useMemo)(()=>t.find(e=>e.pk)?.name??null,[t]),S=(0,v.useCallback)((e,t,n)=>{h({rowIdx:e,col:t}),_(n==null?``:String(n))},[]),w=(0,v.useCallback)(()=>{if(!m||!e||!x)return;let t=e.rows[m.rowIdx];if(!t)return;let n=t[m.col];String(n??``)!==g&&l(x,t[x],m.col,g===``?null:g),h(null)},[m,g,e,x,l]),T=(0,v.useCallback)(()=>h(null),[]),E=(0,v.useCallback)(t=>{if(!e||!x||!u)return;let n=e.rows[t];n&&(u(x,n[x]),b(null))},[e,x,u]),D=(0,v.useMemo)(()=>{let n=(e?.columns??[]).map(e=>({id:e,accessorFn:t=>t[e],header:()=>(0,C.jsx)(`span`,{className:t.find(t=>t.name===e)?.pk?`font-bold`:``,children:e}),cell:({row:t,getValue:n})=>{let r=m?.rowIdx===t.index&&m?.col===e,i=n();return r?(0,C.jsx)(`input`,{autoFocus:!0,className:`w-full bg-transparent border border-primary/50 rounded px-1 py-0 text-xs outline-none`,value:g,onChange:e=>_(e.target.value),onBlur:w,onKeyDown:e=>{e.key===`Enter`&&w(),e.key===`Escape`&&T()}}):(0,C.jsx)(`span`,{className:`cursor-pointer truncate block ${i==null?`text-muted-foreground/40 italic`:``}`,onDoubleClick:()=>x&&S(t.index,e,i),title:i==null?`NULL`:String(i),children:i==null?`NULL`:String(i)})}}));return u&&x&&n.push({id:`_actions`,header:()=>null,cell:({row:e})=>{let t=e.index;return y===t?(0,C.jsxs)(`span`,{className:`flex items-center gap-1 whitespace-nowrap`,children:[(0,C.jsx)(`button`,{type:`button`,onClick:()=>E(t),className:`text-destructive text-[10px] font-medium hover:underline`,children:`Confirm`}),(0,C.jsx)(`button`,{type:`button`,onClick:()=>b(null),className:`text-muted-foreground text-[10px] hover:underline`,children:`Cancel`})]}):(0,C.jsx)(`button`,{type:`button`,onClick:()=>b(t),className:`p-0.5 rounded opacity-0 group-hover:opacity-100 hover:bg-destructive/10 hover:text-destructive transition-opacity`,title:`Delete row`,children:(0,C.jsx)(a,{className:`size-3`})})},size:60}),n},[e?.columns,t,m,g,w,T,S,x,u,y,E]),O=d({data:e?.rows??[],columns:D,getCoreRowModel:f()});if(!e)return(0,C.jsx)(`div`,{className:`flex items-center justify-center h-full text-xs text-muted-foreground`,children:r?(0,C.jsx)(c,{className:`size-4 animate-spin`}):`Select a table`});let k=Math.ceil(e.total/e.limit)||1;return(0,C.jsxs)(`div`,{className:`flex flex-col h-full overflow-hidden`,children:[(0,C.jsx)(`div`,{className:`flex-1 overflow-auto`,children:(0,C.jsxs)(`table`,{className:`w-full text-xs border-collapse`,children:[(0,C.jsx)(`thead`,{className:`sticky top-0 z-10 bg-muted`,children:O.getHeaderGroups().map(e=>(0,C.jsx)(`tr`,{children:e.headers.map(e=>(0,C.jsx)(`th`,{className:`px-2 py-1.5 text-left font-medium text-muted-foreground border-b border-border whitespace-nowrap`,children:p(e.column.columnDef.header,e.getContext())},e.id))},e.id))}),(0,C.jsxs)(`tbody`,{children:[O.getRowModel().rows.map(e=>(0,C.jsx)(`tr`,{className:`group hover:bg-muted/30 border-b border-border/50`,children:e.getVisibleCells().map(e=>(0,C.jsx)(`td`,{className:`px-2 py-1 max-w-[300px]`,children:p(e.column.columnDef.cell,e.getContext())},e.id))},e.id)),e.rows.length===0&&(0,C.jsx)(`tr`,{children:(0,C.jsx)(`td`,{colSpan:e.columns.length,className:`px-2 py-8 text-center text-muted-foreground`,children:`No data`})})]})]})}),(0,C.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,C.jsxs)(`span`,{children:[e.total.toLocaleString(),` rows`]}),(0,C.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,C.jsx)(`button`,{type:`button`,disabled:i<=1,onClick:()=>o(i-1),className:`p-0.5 rounded hover:bg-muted disabled:opacity-30`,children:(0,C.jsx)(s,{className:`size-3.5`})}),(0,C.jsxs)(`span`,{children:[i,` / `,k]}),(0,C.jsx)(`button`,{type:`button`,disabled:i>=k,onClick:()=>o(i+1),className:`p-0.5 rounded hover:bg-muted disabled:opacity-30`,children:(0,C.jsx)(n,{className:`size-3.5`})})]})]})]})}function D({dialect:e,onExecute:t,result:n,error:r,loading:i}){let[a,s]=(0,v.useState)(`SELECT * FROM `),l=(0,v.useCallback)(()=>{let e=a.trim();e&&t(e)},[a,t]);return(0,C.jsxs)(`div`,{className:`flex flex-col h-full overflow-hidden`,children:[(0,C.jsxs)(`div`,{className:`flex items-start gap-1 border-b border-border bg-background`,onKeyDown:(0,v.useCallback)(e=>{(e.metaKey||e.ctrlKey)&&e.key===`Enter`&&(e.preventDefault(),l())},[l]),children:[(0,C.jsx)(`div`,{className:`flex-1 max-h-[120px] overflow-auto`,children:(0,C.jsx)(m,{value:a,onChange:s,extensions:[g({dialect:e})],basicSetup:{lineNumbers:!1,foldGutter:!1,highlightActiveLine:!1},className:`text-xs [&_.cm-editor]:!outline-none [&_.cm-scroller]:!overflow-auto`})}),(0,C.jsx)(`button`,{type:`button`,onClick:l,disabled:i,title:`Execute (Cmd+Enter)`,className:`shrink-0 m-1 p-1.5 rounded bg-primary text-primary-foreground hover:bg-primary/90 disabled:opacity-50 transition-colors`,children:i?(0,C.jsx)(c,{className:`size-3.5 animate-spin`}):(0,C.jsx)(o,{className:`size-3.5`})})]}),(0,C.jsxs)(`div`,{className:`flex-1 overflow-auto text-xs`,children:[r&&(0,C.jsx)(`div`,{className:`px-3 py-2 text-destructive bg-destructive/5`,children:r}),n?.changeType===`modify`&&(0,C.jsxs)(`div`,{className:`px-3 py-2 text-green-500`,children:[`Query executed. `,n.rowsAffected,` row(s) affected.`]}),n?.changeType===`select`&&n.rows.length>0&&(0,C.jsxs)(`table`,{className:`w-full border-collapse`,children:[(0,C.jsx)(`thead`,{className:`sticky top-0 bg-muted`,children:(0,C.jsx)(`tr`,{children:n.columns.map(e=>(0,C.jsx)(`th`,{className:`px-2 py-1 text-left font-medium text-muted-foreground border-b border-border whitespace-nowrap`,children:e},e))})}),(0,C.jsx)(`tbody`,{children:n.rows.map((e,t)=>(0,C.jsx)(`tr`,{className:`hover:bg-muted/30 border-b border-border/50`,children:n.columns.map(t=>(0,C.jsx)(`td`,{className:`px-2 py-1 max-w-[300px] truncate`,title:e[t]==null?`NULL`:String(e[t]),children:e[t]==null?(0,C.jsx)(`span`,{className:`text-muted-foreground/40 italic`,children:`NULL`}):String(e[t])},t))},t))})]}),n?.changeType===`select`&&n.rows.length===0&&(0,C.jsx)(`div`,{className:`px-3 py-2 text-muted-foreground`,children:`No results`})]})]})}export{T as DatabaseViewer};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{o as e}from"./chunk-CFjPhJqf.js";import{t}from"./react-nm2Ru1Pt.js";import{t as n}from"./createLucideIcon-PuMiQgHl.js";import{t as r}from"./columns-2-cEVJHYd7.js";import{i,r as a,t as o}from"./use-monaco-theme-
|
|
1
|
+
import{o as e}from"./chunk-CFjPhJqf.js";import{t}from"./react-nm2Ru1Pt.js";import{t as n}from"./createLucideIcon-PuMiQgHl.js";import{t as r}from"./columns-2-cEVJHYd7.js";import{i,r as a,t as o}from"./use-monaco-theme-VPgvhMpB.js";import{t as s}from"./jsx-runtime-kMwlnEGE.js";import{i as c,t as l}from"./api-client-BKIT_Qeg.js";import{J as u,bt as d,lt as f,pt as p}from"./index-CDlrGSwd.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=s();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,s=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}=u(),R=o(),z=(0,h.useRef)(null),[B,V]=(0,h.useState)();(0,h.useEffect)(()=>{let e=z.current;if(!e)return;let t=new ResizeObserver(([e])=>{e&&V(Math.floor(e.contentRect.height))});return t.observe(e),()=>t.disconnect()},[A,M]),(0,h.useEffect)(()=>{if(w||!n)return;if(j(!0),N(null),b&&x){let e=new URLSearchParams({file1:b,file2:x});l.get(`${c(n)}/files/compare?${e}`).then(e=>{k(e),j(!1)}).catch(e=>{N(e instanceof Error?e.message:`Failed to compare files`),j(!1)});return}let e;if(t){let r=new URLSearchParams({file:t});s&&r.set(`ref`,s),e=`${c(n)}/git/file-diff?${r}`}else if(s||v){let t=new URLSearchParams;s&&t.set(`ref1`,s),v&&t.set(`ref2`,v),e=`${c(n)}/git/diff?${t}`}else e=`${c(n)}/git/diff`;l.get(e).then(e=>{D(e.diff),j(!1)}).catch(e=>{N(e instanceof Error?e.message:`Failed to load diff`),j(!1)})},[t,n,s,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)(p,{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)(d,{className:`size-8`}),(0,g.jsx)(`p`,{className:`text-sm`,children:`No content changes`}),t&&(0,g.jsx)(`p`,{className:`text-xs font-mono`,children:t})]}):(0,g.jsxs)(`div`,{className:`flex flex-col h-full`,children:[!G&&(0,g.jsxs)(`div`,{className:`flex items-center justify-end gap-0.5 px-2 py-0.5 border-b border-border shrink-0`,children:[(0,g.jsx)(`button`,{type:`button`,onClick:()=>F(P===`left`?`both`:`left`),className:`p-1 rounded hover:bg-muted transition-colors ${P===`left`?`bg-muted text-foreground`:``}`,title:`Expand original`,children:(0,g.jsx)(f,{className:`size-3.5`})}),(0,g.jsx)(`button`,{type:`button`,onClick:()=>F(`both`),className:`p-1 rounded hover:bg-muted transition-colors ${P===`both`?`bg-muted text-foreground`:``}`,title:`Side by side`,children:(0,g.jsx)(r,{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)(i,{className:`size-3.5`})})]}),(0,g.jsx)(`div`,{ref:z,className:`flex-1 overflow-hidden`,children:B&&B>0?(0,g.jsx)(a,{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)(p,{className:`size-5 animate-spin text-muted-foreground`})}):(0,g.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,g.jsx)(p,{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-kMwlnEGE.js";import{R as r}from"./index-
|
|
1
|
+
import{o as e}from"./chunk-CFjPhJqf.js";import{t}from"./react-nm2Ru1Pt.js";import{t as n}from"./jsx-runtime-kMwlnEGE.js";import{R as r}from"./index-CDlrGSwd.js";var i=e(t(),1),a=n(),o=`<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
3
|
<\/script>`;function s(e){if(!e)return e;let t=e.indexOf(`<head>`);return t===-1?o+e:e.slice(0,t+6)+o+e.slice(t+6)}function c({metadata:e}){let t=e?.panelId,n=r(e=>t?e.webviewPanels[t]:void 0),o=(0,i.useRef)(null),c=s(n?.html??``);return(0,i.useEffect)(()=>{let e=e=>{o.current&&e.source===o.current.contentWindow&&window.dispatchEvent(new CustomEvent(`ext:webview:send`,{detail:{panelId:t,message:e.data}}))};return window.addEventListener(`message`,e),()=>window.removeEventListener(`message`,e)},[t]),(0,i.useEffect)(()=>{let e=e=>{let{panelId:n,message:r}=e.detail;n===t&&o.current?.contentWindow?.postMessage(r,`*`)};return window.addEventListener(`ext:webview:message`,e),()=>window.removeEventListener(`ext:webview:message`,e)},[t]),n?(0,a.jsx)(`div`,{className:`h-full w-full relative`,children:(0,a.jsx)(`iframe`,{ref:o,srcDoc:c,sandbox:`allow-scripts`,className:`w-full h-full border-0 bg-white dark:bg-zinc-900`,title:n.title})}):(0,a.jsx)(`div`,{className:`flex items-center justify-center h-full text-sm text-text-subtle`,children:`Webview panel not found`})}export{c as ExtensionWebview};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{o as e}from"./chunk-CFjPhJqf.js";import{t}from"./react-nm2Ru1Pt.js";import"./react-dom-Bpkvzu3U.js";import{t as n}from"./createLucideIcon-PuMiQgHl.js";import{A as r}from"./dist-DRTW9IWi.js";import{t as i}from"./tag-CXMT0QB6.js";import{t as a}from"./jsx-runtime-kMwlnEGE.js";import{t as o}from"./utils-DMiycH3O.js";import{i as s,t as c}from"./api-client-BKIT_Qeg.js";import{A as l,Ct as u,E as d,F as f,G as p,I as m,Lt as h,M as g,Mt as _,N as v,Nt as y,O as b,P as x,Q as S,T as C,Tt as w,X as T,et as E,ht as D,j as O,k,nt as A,pt as j,rt as M,tt as N,w as P}from"./index-DUQgLj0D.js";var F=n(`cherry`,[[`path`,{d:`M2 17a5 5 0 0 0 10 0c0-2.76-2.5-5-5-3-2.5-2-5 .24-5 3Z`,key:`cvxqlc`}],[`path`,{d:`M12 17a5 5 0 0 0 10 0c0-2.76-2.5-5-5-3-2.5-2-5 .24-5 3Z`,key:`1ostrc`}],[`path`,{d:`M7 14c3.22-2.91 4.29-8.75 5-12 1.66 2.38 4.94 9 5 12`,key:`hqx58h`}],[`path`,{d:`M22 9c-4.29 0-7.14-2.33-10-7 5.71 0 10 4.67 10 7Z`,key:`eykp1o`}]]),I=n(`git-merge`,[[`circle`,{cx:`18`,cy:`18`,r:`3`,key:`1xkwt0`}],[`circle`,{cx:`6`,cy:`6`,r:`3`,key:`1lh9wr`}],[`path`,{d:`M6 21V9a9 9 0 0 0 9 9`,key:`7kw0sc`}]]),L=e(t(),1),R=[`#0085d9`,`#d73a49`,`#6f42c1`,`#2cbe4e`,`#e36209`,`#005cc5`,`#b31d28`,`#5a32a3`,`#22863a`,`#cb2431`];function ee(e){let t=new Map;if(!e)return t;let n=new Set;for(let t of e.branches)if(!t.remote)for(let e of t.remotes)n.add(`remotes/${e}/${t.name}`);for(let r of e.branches)if(r.remote){if(n.has(r.name))continue;let e=t.get(r.commitHash)??[],i=r.name.replace(/^remotes\//,``);e.push({name:i,type:`branch`,remotes:[],current:!1}),t.set(r.commitHash,e)}else{let e=t.get(r.commitHash)??[];e.push({name:r.name,type:`branch`,remotes:r.remotes,current:r.current}),t.set(r.commitHash,e)}for(let n of e.commits)for(let e of n.refs)if(e.startsWith(`tag: `)){let r=e.replace(`tag: `,``),i=t.get(n.hash)??[];i.push({name:r,type:`tag`,remotes:[],current:!1}),t.set(n.hash,i)}return t}function te(e){let t=new Map;if(!e)return{laneMap:t,maxLane:0,unloadedParentLanes:new Map};let n=0,r=0,i=new Map,a=new Set(e.commits.map(e=>e.hash)),o=[],s=()=>o.length>0?(o.sort((e,t)=>e-t),o.shift()):n++;for(let n of e.commits){let e=i.get(n.hash);e===void 0&&(e=s()),t.set(n.hash,e),e>r&&(r=e),i.delete(n.hash);let a=!1;for(let t=0;t<n.parents.length;t++){let o=n.parents[t];if(!i.has(o))if(t===0)i.set(o,e),a=!0;else{let e=s();i.set(o,e),e>r&&(r=e)}}a||o.push(e)}let c=new Map;for(let[e,t]of i)a.has(e)||c.set(e,t);return{laneMap:t,maxLane:r,unloadedParentLanes:c}}function ne(e,t,n,r){if(!e)return[];let i=[],a=new Set(e.commits.map(e=>e.hash));for(let o=0;o<e.commits.length;o++){let s=e.commits[o],c=t.get(s.hash)??0,l=R[c%R.length];for(let u of s.parents){let d=e.commits.findIndex(e=>e.hash===u);if(d>=0){let e=t.get(u)??0,n=R[e%R.length],r=c*16+16/2,a=o*24+24/2,f=e*16+16/2,p=d*24+24/2,m,h=s.parents.indexOf(u)>0;if(r===f)m=`M ${r} ${a} L ${f} ${p}`;else if(h){let e=a+24;m=`M ${r} ${a} C ${r} ${e} ${f} ${a} ${f} ${e} L ${f} ${p}`}else{let e=p-24;m=`M ${r} ${a} L ${r} ${e} C ${r} ${p} ${f} ${e} ${f} ${p}`}let g=s.parents.indexOf(u)===0?l:n;i.push({d:m,color:g})}else if(!a.has(u)){let e=n.get(u)??c,t=R[e%R.length],a=c*16+16/2,s=o*24+24/2,d=e*16+16/2;if(a===d)i.push({d:`M ${a} ${s} L ${a} ${r}`,color:l});else{let e=s+24,n=`M ${a} ${s} C ${a} ${e} ${d} ${s} ${d} ${e} L ${d} ${r}`;i.push({d:n,color:t})}}}}return i}function z(e){let t=new Date(e),n=new Date().getTime()-t.getTime(),r=Math.floor(n/6e4);if(r<1)return`just now`;if(r<60)return`${r}m ago`;let i=Math.floor(r/60);if(i<24)return`${i}h ago`;let a=Math.floor(i/24);if(a<30)return`${a}d ago`;let o=Math.floor(a/30);return o<12?`${o}mo ago`:`${Math.floor(o/12)}y ago`}var B=200;function re(e){let[t,n]=(0,L.useState)(null),[r,i]=(0,L.useState)(!0),[a,o]=(0,L.useState)(!1),[l,u]=(0,L.useState)(!0),[d,f]=(0,L.useState)(null),[m,h]=(0,L.useState)(!1),[g,_]=(0,L.useState)(null),[v,y]=(0,L.useState)([]),[b,x]=(0,L.useState)(!1),[S,C]=(0,L.useState)(`__all__`),[w,T]=(0,L.useState)(``),[E,D]=(0,L.useState)(!1),{openTab:O}=p(),k=(0,L.useRef)(0),A=(0,L.useCallback)(async()=>{if(e)try{i(!0);let t=Math.max(B,k.current),r=await c.get(`${s(e)}/git/graph?max=${t}`);n(r),k.current=r.commits.length,u(r.commits.length>=t),f(null)}catch(e){f(e instanceof Error?e.message:`Failed to fetch graph`)}finally{i(!1)}},[e]),j=(0,L.useCallback)(async()=>{if(!(!e||a||!l))try{o(!0);let t=k.current,r=await c.get(`${s(e)}/git/graph?max=${B}&skip=${t}`);if(r.commits.length===0){u(!1);return}n(e=>{if(!e)return r;let t=new Set(e.commits.map(e=>e.hash)),n=r.commits.filter(e=>!t.has(e.hash)),i=new Set(e.branches.map(e=>e.name)),a=r.branches.filter(e=>!i.has(e.name));return{commits:[...e.commits,...n],branches:[...e.branches,...a],head:e.head}}),k.current=t+r.commits.length,u(r.commits.length>=B)}catch(e){f(e instanceof Error?e.message:`Failed to load more`)}finally{o(!1)}},[e,a,l]);(0,L.useEffect)(()=>{A();let e=setInterval(A,1e4);return()=>clearInterval(e)},[A]);let M=async(t,n)=>{if(e){h(!0);try{await c.post(`${s(e)}${t}`,n),await A()}catch(e){f(e instanceof Error?e.message:`Action failed`)}finally{h(!1)}}},N=()=>M(`/git/fetch`,{}),P=e=>M(`/git/checkout`,{ref:e}),F=e=>M(`/git/cherry-pick`,{hash:e}),I=e=>M(`/git/revert`,{hash:e}),R=e=>M(`/git/merge`,{source:e}),z=e=>M(`/git/branch/delete`,{name:e}),re=e=>M(`/git/push`,{branch:e}),V=(e,t)=>M(`/git/tag`,{name:e,hash:t}),H=e=>navigator.clipboard.writeText(e),U=async(e,n)=>{if(t?.branches.some(t=>t.name===e||t.name.endsWith(`/${e}`))){if(!window.confirm(`Branch "${e}" already exists.\nDelete and recreate from this commit?`))return;await M(`/git/branch/delete`,{name:e})}await M(`/git/branch/create`,{name:e,from:n})},W=async t=>{if(e)try{let n=await c.get(`${s(e)}/git/pr-url?branch=${encodeURIComponent(t)}`);n.url&&window.open(n.url,`_blank`)}catch{}},G=async t=>{if(g?.hash===t.hash){_(null);return}_(t),x(!0);try{let n=t.parents[0]??``,r=n?`ref1=${encodeURIComponent(n)}&`:``,i=await c.get(`${s(e)}/git/diff-stat?${r}ref2=${encodeURIComponent(t.hash)}`);y(Array.isArray(i)?i:[])}catch{y([])}finally{x(!1)}},K=t=>O({type:`git-diff`,title:`Diff ${t.abbreviatedHash}`,closable:!0,metadata:{projectName:e,ref1:t.parents[0]??void 0,ref2:t.hash},projectId:e??null}),q=(0,L.useMemo)(()=>ee(t),[t]),J=t?.branches.find(e=>e.current),Y=t?.head??``,X=(0,L.useMemo)(()=>{if(!t)return[];let e=t.commits;if(S!==`__all__`){let n=t.branches.find(e=>e.name===S);if(n){let r=new Set,i=[n.commitHash];for(;i.length>0;){let e=i.pop();if(r.has(e))continue;r.add(e);let n=t.commits.find(t=>t.hash===e);n&&i.push(...n.parents)}e=e.filter(e=>r.has(e.hash))}}if(w.trim()){let t=w.toLowerCase();e=e.filter(e=>e.subject.toLowerCase().includes(t)||e.authorName.toLowerCase().includes(t)||e.abbreviatedHash.includes(t)||e.hash.includes(t))}return e},[t,S,w]),Z=(0,L.useMemo)(()=>t?{...t,commits:X}:null,[t,X]),Q=(0,L.useMemo)(()=>te(Z),[Z]),$=X.length*24+48;return{data:t,loading:r,loadingMore:a,hasMore:l,error:d,acting:m,selectedCommit:g,setSelectedCommit:_,commitFiles:v,loadingDetail:b,branchFilter:S,setBranchFilter:C,searchQuery:w,setSearchQuery:T,showSearch:E,setShowSearch:D,fetchGraph:A,fetchFromRemotes:N,loadMore:j,handleCheckout:P,handleCherryPick:F,handleRevert:I,handleMerge:R,handleDeleteBranch:z,handlePushBranch:re,handleCreateBranch:U,handleCreateTag:V,handleCreatePr:W,copyHash:H,selectCommit:G,openDiffForCommit:K,commitLabels:q,currentBranch:J,headHash:Y,filteredCommits:X,filteredLanes:Q,svgHeight:$,svgPaths:(0,L.useMemo)(()=>ne(Z,Q.laneMap,Q.unloadedParentLanes,$),[Z,Q.laneMap,Q.unloadedParentLanes,$])}}function V(e){let[t,n]=(0,L.useState)(e),r=(0,L.useRef)(e);r.current=t;let i=(0,L.useRef)(!1);return{widths:t,startResize:(e,t)=>{i.current=!0;let a=r.current[e]??80,o=r=>{if(!i.current)return;let o=`touches`in r?r.touches[0].clientX:r.clientX,s=Math.max(40,a+o-t);n(t=>({...t,[e]:s}))},s=()=>{i.current=!1,window.removeEventListener(`mousemove`,o),window.removeEventListener(`mouseup`,s),window.removeEventListener(`touchmove`,o),window.removeEventListener(`touchend`,s)};window.addEventListener(`mousemove`,o),window.addEventListener(`mouseup`,s),window.addEventListener(`touchmove`,o,{passive:!1}),window.addEventListener(`touchend`,s)}}}var H=a();function U({branches:e,branchFilter:t,onBranchFilterChange:n,searchQuery:i,onSearchQueryChange:a,showSearch:o,onToggleSearch:s,onFetch:c,onRefresh:l,onOpenSettings:u,loading:d,acting:f,projectName:p}){let m=e.filter(e=>!e.remote),[h,g]=(0,L.useState)(!1),[v,y]=(0,L.useState)(``),b=(0,L.useRef)(null);(0,L.useEffect)(()=>{if(!h)return;let e=e=>{b.current&&!b.current.contains(e.target)&&(g(!1),y(``))};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[h]);let x=v?m.filter(e=>e.name.toLowerCase().includes(v.toLowerCase())):m,S=t===`__all__`?`Show All`:m.find(e=>e.name===t)?.name??`Show All`;return(0,H.jsx)(`div`,{className:`border-b bg-background`,children:(0,H.jsxs)(`div`,{className:`flex items-center gap-1.5 px-2 py-1.5`,children:[(0,H.jsxs)(`div`,{className:`flex items-center gap-1 text-xs text-muted-foreground shrink-0`,children:[(0,H.jsx)(`span`,{className:`font-semibold`,children:`Repo:`}),(0,H.jsx)(`span`,{className:`font-medium text-foreground truncate max-w-[120px]`,children:p??`—`})]}),(0,H.jsx)(`div`,{className:`w-px h-4 bg-border mx-1`}),(0,H.jsxs)(`div`,{className:`relative shrink-0`,ref:b,children:[(0,H.jsxs)(`button`,{type:`button`,className:`flex items-center gap-1 h-6 px-2 text-xs border rounded-md bg-transparent hover:bg-muted/50`,onClick:()=>{g(e=>!e),y(``)},children:[(0,H.jsx)(`span`,{className:`font-semibold text-muted-foreground`,children:`Branches:`}),(0,H.jsx)(`span`,{className:`max-w-[100px] truncate`,children:S}),(0,H.jsx)(_,{className:`size-3 opacity-50`})]}),h&&(0,H.jsxs)(`div`,{className:`absolute top-full left-0 mt-1 z-50 w-[220px] rounded-md border bg-popover shadow-md`,children:[(0,H.jsx)(`div`,{className:`p-1.5`,children:(0,H.jsx)(P,{className:`h-6 text-xs px-2`,placeholder:`Filter branches...`,value:v,onChange:e=>y(e.target.value),autoFocus:!0})}),(0,H.jsxs)(`div`,{className:`max-h-[200px] overflow-y-auto p-1`,children:[(0,H.jsx)(W,{label:`Show All`,selected:t===`__all__`,onClick:()=>{n(`__all__`),g(!1)}}),x.map(e=>(0,H.jsx)(W,{label:e.name,current:e.current,selected:t===e.name,onClick:()=>{n(e.name),g(!1)}},e.name)),x.length===0&&v&&(0,H.jsx)(`div`,{className:`px-2 py-1.5 text-xs text-muted-foreground`,children:`No branches found`})]})]})]}),(0,H.jsx)(`div`,{className:`flex-1`}),o&&(0,H.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,H.jsx)(P,{className:`h-6 text-xs w-[160px] px-2`,placeholder:`Search commits...`,value:i,onChange:e=>a(e.target.value),autoFocus:!0}),(0,H.jsx)(O,{variant:`ghost`,size:`icon-xs`,onClick:s,children:(0,H.jsx)(T,{className:`size-3`})})]}),!o&&(0,H.jsx)(O,{variant:`ghost`,size:`icon-xs`,onClick:s,title:`Find`,children:(0,H.jsx)(N,{className:`size-3.5`})}),(0,H.jsx)(O,{variant:`ghost`,size:`icon-xs`,onClick:u,title:`Settings`,children:(0,H.jsx)(E,{className:`size-3.5`})}),(0,H.jsx)(O,{variant:`ghost`,size:`icon-xs`,onClick:c,disabled:f,title:`Fetch`,children:(0,H.jsx)(r,{className:`size-3.5`})}),(0,H.jsx)(O,{variant:`ghost`,size:`icon-xs`,onClick:l,disabled:f,title:`Refresh`,children:(0,H.jsx)(M,{className:`size-3.5 ${d?`animate-spin`:``}`})})]})})}function W({label:e,selected:t,current:n,onClick:r}){return(0,H.jsxs)(`button`,{type:`button`,className:`flex items-center gap-2 w-full px-2 py-1 text-xs rounded-sm hover:bg-accent hover:text-accent-foreground text-left`,onClick:r,children:[(0,H.jsx)(y,{className:`size-3 shrink-0 ${t?`opacity-100`:`opacity-0`}`}),(0,H.jsx)(`span`,{className:`truncate flex-1`,children:e}),n&&(0,H.jsx)(`span`,{className:`text-[10px] text-muted-foreground italic`,children:`current`})]})}function G({commits:e,laneMap:t,svgPaths:n,width:r,height:i,headHash:a}){return(0,H.jsxs)(`svg`,{width:r,height:i,children:[n.map((e,t)=>(0,H.jsx)(`path`,{d:e.d,stroke:e.color,strokeWidth:2,fill:`none`},t)),e.map((e,n)=>{let r=t.get(e.hash)??0,i=r*16+16/2,o=n*24+24/2,s=R[r%R.length],c=e.hash===a;return(0,H.jsx)(`circle`,{cx:i,cy:o,r:c?5:4,fill:s,stroke:c?`#000`:`none`,strokeWidth:c?2:0},e.hash)})]})}function K({name:e,type:t,remotes:n,isCurrent:r,color:a,currentBranch:o,onCheckout:s,onMerge:c,onPush:l,onCreatePr:d,onDelete:p}){return t===`tag`?(0,H.jsxs)(`span`,{className:`inline-flex items-center gap-0.5 px-1.5 py-0.5 rounded text-[10px] font-medium shrink-0 bg-amber-500/20 text-amber-500 border border-amber-500/30`,children:[(0,H.jsx)(i,{className:`size-2.5`}),e]}):(0,H.jsxs)(g,{children:[(0,H.jsx)(m,{asChild:!0,children:(0,H.jsxs)(`span`,{className:`inline-flex items-center rounded text-[10px] font-medium shrink-0 cursor-context-menu overflow-hidden`,style:{border:r?`1.5px solid ${a}`:`1px solid ${a}50`},children:[(0,H.jsxs)(`span`,{className:`inline-flex items-center gap-0.5 px-1.5 py-0.5`,style:{backgroundColor:r?a:`${a}30`,color:r?`#fff`:a},children:[(0,H.jsx)(D,{className:`size-2.5`}),e]}),n.map(e=>(0,H.jsx)(`span`,{className:`px-1.5 py-0.5 italic opacity-70`,style:{borderLeft:`1px solid ${a}40`,color:a,backgroundColor:`${a}15`},children:e},e))]})}),(0,H.jsxs)(v,{children:[(0,H.jsx)(x,{onClick:()=>s(e),children:`Checkout`}),(0,H.jsxs)(x,{onClick:()=>c(e),disabled:e===o?.name,children:[(0,H.jsx)(I,{className:`size-3`}),`Merge into current`]}),(0,H.jsx)(f,{}),(0,H.jsxs)(x,{onClick:()=>l(e),children:[(0,H.jsx)(h,{className:`size-3`}),`Push`]}),(0,H.jsxs)(x,{onClick:()=>d(e),children:[(0,H.jsx)(u,{className:`size-3`}),`Create PR`]}),(0,H.jsx)(f,{}),(0,H.jsxs)(x,{variant:`destructive`,onClick:()=>p(e),disabled:e===o?.name,children:[(0,H.jsx)(S,{className:`size-3`}),`Delete`]})]})]})}function q({commit:e,lane:t,isSelected:n,isHead:r,labels:a,currentBranch:o,onSelect:s,onCheckout:c,onCherryPick:l,onRevert:u,onMerge:d,onDeleteBranch:p,onPushBranch:h,onCreatePr:_,onOpenCreateBranch:y,onOpenCreateTag:b,onOpenDiff:S,onCopyHash:C}){let T=R[t%R.length],E=a.filter(e=>e.type===`branch`),O=a.filter(e=>e.type===`tag`);return(0,H.jsxs)(g,{children:[(0,H.jsx)(m,{asChild:!0,children:(0,H.jsxs)(`tr`,{className:`hover:bg-muted/50 cursor-pointer border-b border-border/20 ${n?`bg-primary/10`:``} ${r?`font-medium`:``}`,style:{height:`24px`},onClick:s,children:[(0,H.jsx)(`td`,{className:`px-2 truncate max-w-0`,children:(0,H.jsxs)(`div`,{className:`flex items-center gap-1.5 min-w-0`,children:[E.map(e=>(0,H.jsx)(K,{name:e.name,type:`branch`,remotes:e.remotes,isCurrent:e.current,color:T,currentBranch:o,onCheckout:c,onMerge:d,onPush:h,onCreatePr:_,onDelete:p},`branch-${e.name}`)),O.map(e=>(0,H.jsx)(K,{name:e.name,type:`tag`,remotes:[],isCurrent:!1,color:T,currentBranch:o,onCheckout:c,onMerge:d,onPush:h,onCreatePr:_,onDelete:p},`tag-${e.name}`)),(0,H.jsx)(`span`,{className:`truncate text-xs`,children:e.subject})]})}),(0,H.jsx)(`td`,{className:`px-2 text-xs text-muted-foreground whitespace-nowrap shrink-0`,children:z(e.authorDate)}),(0,H.jsx)(`td`,{className:`px-2 text-xs text-muted-foreground truncate max-w-[120px]`,children:e.authorName}),(0,H.jsx)(`td`,{className:`px-2 text-xs text-muted-foreground font-mono whitespace-nowrap`,children:e.abbreviatedHash})]})}),(0,H.jsxs)(v,{children:[(0,H.jsx)(x,{onClick:()=>c(e.hash),children:`Checkout`}),(0,H.jsxs)(x,{onClick:()=>y(e.hash),children:[(0,H.jsx)(D,{className:`size-3`}),`Create Branch...`]}),(0,H.jsx)(f,{}),(0,H.jsxs)(x,{onClick:()=>l(e.hash),children:[(0,H.jsx)(F,{className:`size-3`}),`Cherry Pick`]}),(0,H.jsxs)(x,{onClick:()=>u(e.hash),children:[(0,H.jsx)(A,{className:`size-3`}),`Revert`]}),(0,H.jsxs)(x,{onClick:()=>b(e.hash),children:[(0,H.jsx)(i,{className:`size-3`}),`Create Tag...`]}),(0,H.jsx)(f,{}),(0,H.jsx)(x,{onClick:S,children:`View Diff`}),(0,H.jsxs)(x,{onClick:C,children:[(0,H.jsx)(w,{className:`size-3`}),`Copy Hash`]})]})]})}function J({commit:e,files:t,loadingDetail:n,projectName:r,onClose:i,copyHash:a}){let{openTab:s}=p();return(0,H.jsxs)(`div`,{className:`border-t bg-muted/30 max-h-[40%] overflow-auto`,children:[(0,H.jsxs)(`div`,{className:`px-3 py-2 border-b flex items-center justify-between`,children:[(0,H.jsxs)(`span`,{className:`text-sm font-medium truncate`,children:[e.abbreviatedHash,` — `,e.subject]}),(0,H.jsx)(O,{variant:`ghost`,size:`icon-xs`,onClick:i,children:`✕`})]}),(0,H.jsxs)(`div`,{className:`px-3 py-2 text-xs space-y-1`,children:[(0,H.jsxs)(`div`,{className:`flex gap-4`,children:[(0,H.jsx)(`span`,{className:`text-muted-foreground w-12 shrink-0`,children:`Author`}),(0,H.jsxs)(`span`,{children:[e.authorName,` <`,e.authorEmail,`>`]})]}),(0,H.jsxs)(`div`,{className:`flex gap-4`,children:[(0,H.jsx)(`span`,{className:`text-muted-foreground w-12 shrink-0`,children:`Date`}),(0,H.jsx)(`span`,{children:new Date(e.authorDate).toLocaleString()})]}),(0,H.jsxs)(`div`,{className:`flex gap-4`,children:[(0,H.jsx)(`span`,{className:`text-muted-foreground w-12 shrink-0`,children:`Hash`}),(0,H.jsx)(`span`,{className:`font-mono cursor-pointer hover:text-primary`,onClick:()=>a(e.hash),children:e.hash})]}),e.parents.length>0&&(0,H.jsxs)(`div`,{className:`flex gap-4`,children:[(0,H.jsx)(`span`,{className:`text-muted-foreground w-12 shrink-0`,children:`Parents`}),(0,H.jsx)(`span`,{className:`font-mono`,children:e.parents.map(e=>e.slice(0,7)).join(`, `)})]}),e.body&&(0,H.jsx)(`div`,{className:`mt-2 p-2 bg-background rounded text-xs whitespace-pre-wrap`,children:e.body})]}),(0,H.jsxs)(`div`,{className:`px-3 py-1 border-t`,children:[(0,H.jsx)(`div`,{className:`text-xs text-muted-foreground py-1`,children:n?`Loading files...`:`${t.length} file${t.length===1?``:`s`} changed`}),t.map(t=>(0,H.jsxs)(`div`,{className:`flex items-center gap-2 py-0.5 text-xs hover:bg-muted/50 rounded px-1 cursor-pointer`,onClick:()=>s({type:`git-diff`,title:`Diff ${o(t.path)}`,closable:!0,metadata:{projectName:r,ref1:e.parents[0]??void 0,ref2:e.hash,filePath:t.path},projectId:r}),children:[(0,H.jsx)(`span`,{className:`flex-1 truncate font-mono`,children:t.path}),t.additions>0&&(0,H.jsxs)(`span`,{className:`text-green-500`,children:[`+`,t.additions]}),t.deletions>0&&(0,H.jsxs)(`span`,{className:`text-red-500`,children:[`-`,t.deletions]})]},t.path))]})]})}function Y({type:e,hash:t,onClose:n,onCreateBranch:r,onCreateTag:i}){let[a,o]=(0,L.useState)(``),s=()=>{a.trim()&&(e===`branch`?r(a.trim(),t):i(a.trim(),t),n())};return(0,H.jsx)(C,{open:e!==null,onOpenChange:e=>{e||n()},children:(0,H.jsxs)(d,{children:[(0,H.jsx)(k,{children:(0,H.jsx)(l,{children:e===`branch`?`Create Branch`:`Create Tag`})}),(0,H.jsx)(P,{placeholder:e===`branch`?`Branch name`:`Tag name`,value:a,onChange:e=>o(e.target.value),onKeyDown:e=>{e.key===`Enter`&&s()},autoFocus:!0}),(0,H.jsxs)(b,{children:[(0,H.jsx)(O,{variant:`outline`,onClick:n,children:`Cancel`}),(0,H.jsx)(O,{disabled:!a.trim(),onClick:s,children:`Create`})]})]})})}function X({open:e,onClose:t,projectName:n,branches:r}){let i=r.filter(e=>!e.remote),a=r.filter(e=>e.remote),o=new Map;for(let e of a){let t=e.name.replace(/^remotes\//,``),n=t.indexOf(`/`);if(n<0)continue;let r=t.slice(0,n),i=t.slice(n+1),a=o.get(r)??[];a.push(i),o.set(r,a)}return(0,H.jsx)(C,{open:e,onOpenChange:e=>{e||t()},children:(0,H.jsxs)(d,{className:`max-w-md`,children:[(0,H.jsx)(k,{children:(0,H.jsx)(l,{children:`Repository Settings`})}),(0,H.jsxs)(`div`,{className:`space-y-4 text-sm`,children:[(0,H.jsxs)(Z,{title:`General`,children:[(0,H.jsx)(Q,{label:`Name`,value:n}),(0,H.jsx)(Q,{label:`Branches`,value:`${i.length} local, ${a.length} remote`})]}),(0,H.jsx)(Z,{title:`Local Branches`,children:i.map(e=>(0,H.jsxs)(`div`,{className:`flex items-center gap-2 py-0.5`,children:[(0,H.jsx)(`span`,{className:`text-xs ${e.current?`font-semibold text-primary`:`text-foreground`}`,children:e.name}),e.current&&(0,H.jsx)(`span`,{className:`text-[10px] text-muted-foreground italic`,children:`HEAD`}),e.remotes.length>0&&(0,H.jsxs)(`span`,{className:`text-[10px] text-muted-foreground`,children:[`(`,e.remotes.join(`, `),`)`]})]},e.name))}),(0,H.jsxs)(Z,{title:`Remotes`,children:[[...o.entries()].map(([e,t])=>(0,H.jsxs)(`div`,{className:`py-0.5`,children:[(0,H.jsx)(`span`,{className:`text-xs font-medium`,children:e}),(0,H.jsxs)(`span`,{className:`text-[10px] text-muted-foreground ml-2`,children:[t.length,` branch`,t.length===1?``:`es`]})]},e)),o.size===0&&(0,H.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`No remotes configured`})]})]})]})})}function Z({title:e,children:t}){return(0,H.jsxs)(`div`,{children:[(0,H.jsx)(`h4`,{className:`text-xs font-semibold text-muted-foreground uppercase tracking-wider mb-1.5`,children:e}),(0,H.jsx)(`div`,{className:`pl-1`,children:t})]})}function Q({label:e,value:t}){return(0,H.jsxs)(`div`,{className:`flex items-center gap-3 py-0.5`,children:[(0,H.jsx)(`span`,{className:`text-xs text-muted-foreground w-16 shrink-0`,children:e}),(0,H.jsx)(`span`,{className:`text-xs`,children:t})]})}function $({metadata:e}){let t=e?.projectName,n=re(t),[r,i]=(0,L.useState)({type:null}),[a,o]=(0,L.useState)(!1),s=(typeof window<`u`&&window.innerWidth<768?6:10)*16+16,[c,l]=(0,L.useState)(s),u=(0,L.useRef)(s);u.current=c;let d=(0,L.useRef)(!1),f=e=>{d.current=!0;let t=u.current,n=n=>{if(!d.current)return;let r=`touches`in n?n.touches[0].clientX:n.clientX;l(Math.max(40,t+r-e))},r=()=>{d.current=!1,window.removeEventListener(`mousemove`,n),window.removeEventListener(`mouseup`,r),window.removeEventListener(`touchmove`,n),window.removeEventListener(`touchend`,r)};window.addEventListener(`mousemove`,n),window.addEventListener(`mouseup`,r),window.addEventListener(`touchmove`,n,{passive:!1}),window.addEventListener(`touchend`,r)},{widths:p,startResize:m}=V({date:80,author:120,commit:70}),h=(0,L.useRef)(n.loadMore);h.current=n.loadMore;let g=(0,L.useCallback)(e=>{let t=e.currentTarget;t.scrollHeight-t.scrollTop-t.clientHeight<200&&h.current()},[]);return t?n.loading&&!n.data?(0,H.jsx)(oe,{}):n.error&&!n.data?(0,H.jsx)(se,{error:n.error,onRetry:n.fetchGraph}):(0,H.jsxs)(`div`,{className:`flex flex-col h-full`,children:[(0,H.jsx)(U,{branches:n.data?.branches??[],branchFilter:n.branchFilter,onBranchFilterChange:n.setBranchFilter,searchQuery:n.searchQuery,onSearchQueryChange:n.setSearchQuery,showSearch:n.showSearch,onToggleSearch:()=>n.setShowSearch(!n.showSearch),onFetch:n.fetchFromRemotes,onRefresh:n.fetchGraph,onOpenSettings:()=>o(!0),loading:n.loading,acting:n.acting,projectName:t}),n.error&&(0,H.jsx)(`div`,{className:`px-3 py-1.5 text-xs text-destructive bg-destructive/10`,children:n.error}),(0,H.jsx)(`div`,{className:`flex-1 overflow-auto`,onScroll:g,children:(0,H.jsxs)(`div`,{className:`flex min-w-max md:min-w-0`,children:[(0,H.jsxs)(`div`,{className:`sticky left-0 z-10 shrink-0 bg-background relative overflow-hidden`,style:{width:`${c}px`},children:[(0,H.jsx)(`div`,{className:`text-[11px] font-semibold text-muted-foreground px-2 border-b bg-background sticky top-0 z-20`,style:{height:`24px`,lineHeight:`24px`},children:`Graph`}),(0,H.jsx)(G,{commits:n.filteredCommits,laneMap:n.filteredLanes.laneMap,svgPaths:n.svgPaths,width:(n.filteredLanes.maxLane+2)*16,height:n.svgHeight,headHash:n.headHash}),(0,H.jsx)(`div`,{className:`absolute top-0 right-0 w-1.5 h-full cursor-col-resize hover:bg-primary/30`,onMouseDown:e=>{e.preventDefault(),f(e.clientX)},onTouchStart:e=>f(e.touches[0].clientX)})]}),(0,H.jsxs)(`div`,{className:`flex-1 min-w-[400px]`,children:[(0,H.jsxs)(`table`,{className:`w-full border-collapse text-xs`,style:{tableLayout:`fixed`},children:[(0,H.jsxs)(`colgroup`,{children:[(0,H.jsx)(`col`,{}),(0,H.jsx)(`col`,{style:{width:`${p.date}px`}}),(0,H.jsx)(`col`,{style:{width:`${p.author}px`}}),(0,H.jsx)(`col`,{style:{width:`${p.commit}px`}})]}),(0,H.jsx)(`thead`,{className:`sticky top-0 z-10 bg-background`,children:(0,H.jsxs)(`tr`,{className:`border-b text-[11px] font-semibold text-muted-foreground`,style:{height:`24px`},children:[(0,H.jsx)(`th`,{className:`text-left px-2 font-semibold`,children:`Description`}),(0,H.jsx)(ie,{label:`Date`,colKey:`date`,onStartResize:m}),(0,H.jsx)(ie,{label:`Author`,colKey:`author`,onStartResize:m}),(0,H.jsx)(`th`,{className:`text-left px-2 font-semibold`,children:`Commit`})]})}),(0,H.jsx)(`tbody`,{children:n.filteredCommits.map(e=>(0,H.jsx)(q,{commit:e,lane:n.filteredLanes.laneMap.get(e.hash)??0,isSelected:n.selectedCommit?.hash===e.hash,isHead:e.hash===n.headHash,labels:n.commitLabels.get(e.hash)??[],currentBranch:n.currentBranch,onSelect:()=>n.selectCommit(e),onCheckout:n.handleCheckout,onCherryPick:n.handleCherryPick,onRevert:n.handleRevert,onMerge:n.handleMerge,onDeleteBranch:n.handleDeleteBranch,onPushBranch:n.handlePushBranch,onCreatePr:n.handleCreatePr,onOpenCreateBranch:e=>i({type:`branch`,hash:e}),onOpenCreateTag:e=>i({type:`tag`,hash:e}),onOpenDiff:()=>n.openDiffForCommit(e),onCopyHash:()=>n.copyHash(e.hash)},e.hash))})]}),n.loadingMore&&(0,H.jsxs)(`div`,{className:`flex items-center justify-center gap-2 py-3 text-xs text-muted-foreground`,children:[(0,H.jsx)(j,{className:`size-3.5 animate-spin`}),` Loading more commits...`]}),!n.hasMore&&n.data&&n.data.commits.length>0&&(0,H.jsxs)(`div`,{className:`text-center py-2 text-xs text-muted-foreground`,children:[n.data.commits.length,` commits loaded`]})]})]})}),n.selectedCommit&&t&&(0,H.jsx)(J,{commit:n.selectedCommit,files:n.commitFiles,loadingDetail:n.loadingDetail,projectName:t,onClose:()=>n.setSelectedCommit(null),copyHash:n.copyHash}),(0,H.jsx)(Y,{type:r.type,hash:r.hash,onClose:()=>i({type:null}),onCreateBranch:n.handleCreateBranch,onCreateTag:n.handleCreateTag}),(0,H.jsx)(X,{open:a,onClose:()=>o(!1),projectName:t,branches:n.data?.branches??[]})]}):(0,H.jsx)(ae,{msg:`No project selected.`})}function ie({label:e,colKey:t,onStartResize:n}){return(0,H.jsxs)(`th`,{className:`text-left px-2 font-semibold relative`,children:[e,(0,H.jsx)(`div`,{className:`absolute top-0 right-0 w-1.5 h-full cursor-col-resize hover:bg-primary/30`,onMouseDown:e=>{e.preventDefault(),n(t,e.clientX)},onTouchStart:e=>n(t,e.touches[0].clientX)})]})}function ae({msg:e}){return(0,H.jsx)(`div`,{className:`flex items-center justify-center h-full text-muted-foreground text-sm`,children:e})}function oe(){return(0,H.jsxs)(`div`,{className:`flex items-center justify-center h-full gap-2 text-muted-foreground`,children:[(0,H.jsx)(j,{className:`size-5 animate-spin`}),(0,H.jsx)(`span`,{className:`text-sm`,children:`Loading git graph...`})]})}function se({error:e,onRetry:t}){return(0,H.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full gap-2 text-destructive text-sm`,children:[(0,H.jsx)(`p`,{children:e}),(0,H.jsx)(O,{variant:`outline`,size:`sm`,onClick:t,children:`Retry`})]})}export{$ as GitGraph};
|
|
1
|
+
import{o as e}from"./chunk-CFjPhJqf.js";import{t}from"./react-nm2Ru1Pt.js";import"./react-dom-Bpkvzu3U.js";import{t as n}from"./createLucideIcon-PuMiQgHl.js";import{A as r}from"./dist-DRTW9IWi.js";import{t as i}from"./tag-CXMT0QB6.js";import{t as a}from"./jsx-runtime-kMwlnEGE.js";import{t as o}from"./utils-DMiycH3O.js";import{i as s,t as c}from"./api-client-BKIT_Qeg.js";import{A as l,Ct as u,E as d,F as f,G as p,I as m,Lt as h,M as g,Mt as _,N as v,Nt as y,O as b,P as x,Q as S,T as C,Tt as w,X as T,et as E,ht as D,j as O,k,nt as A,pt as j,rt as M,tt as N,w as P}from"./index-CDlrGSwd.js";var F=n(`cherry`,[[`path`,{d:`M2 17a5 5 0 0 0 10 0c0-2.76-2.5-5-5-3-2.5-2-5 .24-5 3Z`,key:`cvxqlc`}],[`path`,{d:`M12 17a5 5 0 0 0 10 0c0-2.76-2.5-5-5-3-2.5-2-5 .24-5 3Z`,key:`1ostrc`}],[`path`,{d:`M7 14c3.22-2.91 4.29-8.75 5-12 1.66 2.38 4.94 9 5 12`,key:`hqx58h`}],[`path`,{d:`M22 9c-4.29 0-7.14-2.33-10-7 5.71 0 10 4.67 10 7Z`,key:`eykp1o`}]]),I=n(`git-merge`,[[`circle`,{cx:`18`,cy:`18`,r:`3`,key:`1xkwt0`}],[`circle`,{cx:`6`,cy:`6`,r:`3`,key:`1lh9wr`}],[`path`,{d:`M6 21V9a9 9 0 0 0 9 9`,key:`7kw0sc`}]]),L=e(t(),1),R=[`#0085d9`,`#d73a49`,`#6f42c1`,`#2cbe4e`,`#e36209`,`#005cc5`,`#b31d28`,`#5a32a3`,`#22863a`,`#cb2431`];function ee(e){let t=new Map;if(!e)return t;let n=new Set;for(let t of e.branches)if(!t.remote)for(let e of t.remotes)n.add(`remotes/${e}/${t.name}`);for(let r of e.branches)if(r.remote){if(n.has(r.name))continue;let e=t.get(r.commitHash)??[],i=r.name.replace(/^remotes\//,``);e.push({name:i,type:`branch`,remotes:[],current:!1}),t.set(r.commitHash,e)}else{let e=t.get(r.commitHash)??[];e.push({name:r.name,type:`branch`,remotes:r.remotes,current:r.current}),t.set(r.commitHash,e)}for(let n of e.commits)for(let e of n.refs)if(e.startsWith(`tag: `)){let r=e.replace(`tag: `,``),i=t.get(n.hash)??[];i.push({name:r,type:`tag`,remotes:[],current:!1}),t.set(n.hash,i)}return t}function te(e){let t=new Map;if(!e)return{laneMap:t,maxLane:0,unloadedParentLanes:new Map};let n=0,r=0,i=new Map,a=new Set(e.commits.map(e=>e.hash)),o=[],s=()=>o.length>0?(o.sort((e,t)=>e-t),o.shift()):n++;for(let n of e.commits){let e=i.get(n.hash);e===void 0&&(e=s()),t.set(n.hash,e),e>r&&(r=e),i.delete(n.hash);let a=!1;for(let t=0;t<n.parents.length;t++){let o=n.parents[t];if(!i.has(o))if(t===0)i.set(o,e),a=!0;else{let e=s();i.set(o,e),e>r&&(r=e)}}a||o.push(e)}let c=new Map;for(let[e,t]of i)a.has(e)||c.set(e,t);return{laneMap:t,maxLane:r,unloadedParentLanes:c}}function ne(e,t,n,r){if(!e)return[];let i=[],a=new Set(e.commits.map(e=>e.hash));for(let o=0;o<e.commits.length;o++){let s=e.commits[o],c=t.get(s.hash)??0,l=R[c%R.length];for(let u of s.parents){let d=e.commits.findIndex(e=>e.hash===u);if(d>=0){let e=t.get(u)??0,n=R[e%R.length],r=c*16+16/2,a=o*24+24/2,f=e*16+16/2,p=d*24+24/2,m,h=s.parents.indexOf(u)>0;if(r===f)m=`M ${r} ${a} L ${f} ${p}`;else if(h){let e=a+24;m=`M ${r} ${a} C ${r} ${e} ${f} ${a} ${f} ${e} L ${f} ${p}`}else{let e=p-24;m=`M ${r} ${a} L ${r} ${e} C ${r} ${p} ${f} ${e} ${f} ${p}`}let g=s.parents.indexOf(u)===0?l:n;i.push({d:m,color:g})}else if(!a.has(u)){let e=n.get(u)??c,t=R[e%R.length],a=c*16+16/2,s=o*24+24/2,d=e*16+16/2;if(a===d)i.push({d:`M ${a} ${s} L ${a} ${r}`,color:l});else{let e=s+24,n=`M ${a} ${s} C ${a} ${e} ${d} ${s} ${d} ${e} L ${d} ${r}`;i.push({d:n,color:t})}}}}return i}function z(e){let t=new Date(e),n=new Date().getTime()-t.getTime(),r=Math.floor(n/6e4);if(r<1)return`just now`;if(r<60)return`${r}m ago`;let i=Math.floor(r/60);if(i<24)return`${i}h ago`;let a=Math.floor(i/24);if(a<30)return`${a}d ago`;let o=Math.floor(a/30);return o<12?`${o}mo ago`:`${Math.floor(o/12)}y ago`}var B=200;function re(e){let[t,n]=(0,L.useState)(null),[r,i]=(0,L.useState)(!0),[a,o]=(0,L.useState)(!1),[l,u]=(0,L.useState)(!0),[d,f]=(0,L.useState)(null),[m,h]=(0,L.useState)(!1),[g,_]=(0,L.useState)(null),[v,y]=(0,L.useState)([]),[b,x]=(0,L.useState)(!1),[S,C]=(0,L.useState)(`__all__`),[w,T]=(0,L.useState)(``),[E,D]=(0,L.useState)(!1),{openTab:O}=p(),k=(0,L.useRef)(0),A=(0,L.useCallback)(async()=>{if(e)try{i(!0);let t=Math.max(B,k.current),r=await c.get(`${s(e)}/git/graph?max=${t}`);n(r),k.current=r.commits.length,u(r.commits.length>=t),f(null)}catch(e){f(e instanceof Error?e.message:`Failed to fetch graph`)}finally{i(!1)}},[e]),j=(0,L.useCallback)(async()=>{if(!(!e||a||!l))try{o(!0);let t=k.current,r=await c.get(`${s(e)}/git/graph?max=${B}&skip=${t}`);if(r.commits.length===0){u(!1);return}n(e=>{if(!e)return r;let t=new Set(e.commits.map(e=>e.hash)),n=r.commits.filter(e=>!t.has(e.hash)),i=new Set(e.branches.map(e=>e.name)),a=r.branches.filter(e=>!i.has(e.name));return{commits:[...e.commits,...n],branches:[...e.branches,...a],head:e.head}}),k.current=t+r.commits.length,u(r.commits.length>=B)}catch(e){f(e instanceof Error?e.message:`Failed to load more`)}finally{o(!1)}},[e,a,l]);(0,L.useEffect)(()=>{A();let e=setInterval(A,1e4);return()=>clearInterval(e)},[A]);let M=async(t,n)=>{if(e){h(!0);try{await c.post(`${s(e)}${t}`,n),await A()}catch(e){f(e instanceof Error?e.message:`Action failed`)}finally{h(!1)}}},N=()=>M(`/git/fetch`,{}),P=e=>M(`/git/checkout`,{ref:e}),F=e=>M(`/git/cherry-pick`,{hash:e}),I=e=>M(`/git/revert`,{hash:e}),R=e=>M(`/git/merge`,{source:e}),z=e=>M(`/git/branch/delete`,{name:e}),re=e=>M(`/git/push`,{branch:e}),V=(e,t)=>M(`/git/tag`,{name:e,hash:t}),H=e=>navigator.clipboard.writeText(e),U=async(e,n)=>{if(t?.branches.some(t=>t.name===e||t.name.endsWith(`/${e}`))){if(!window.confirm(`Branch "${e}" already exists.\nDelete and recreate from this commit?`))return;await M(`/git/branch/delete`,{name:e})}await M(`/git/branch/create`,{name:e,from:n})},W=async t=>{if(e)try{let n=await c.get(`${s(e)}/git/pr-url?branch=${encodeURIComponent(t)}`);n.url&&window.open(n.url,`_blank`)}catch{}},G=async t=>{if(g?.hash===t.hash){_(null);return}_(t),x(!0);try{let n=t.parents[0]??``,r=n?`ref1=${encodeURIComponent(n)}&`:``,i=await c.get(`${s(e)}/git/diff-stat?${r}ref2=${encodeURIComponent(t.hash)}`);y(Array.isArray(i)?i:[])}catch{y([])}finally{x(!1)}},K=t=>O({type:`git-diff`,title:`Diff ${t.abbreviatedHash}`,closable:!0,metadata:{projectName:e,ref1:t.parents[0]??void 0,ref2:t.hash},projectId:e??null}),q=(0,L.useMemo)(()=>ee(t),[t]),J=t?.branches.find(e=>e.current),Y=t?.head??``,X=(0,L.useMemo)(()=>{if(!t)return[];let e=t.commits;if(S!==`__all__`){let n=t.branches.find(e=>e.name===S);if(n){let r=new Set,i=[n.commitHash];for(;i.length>0;){let e=i.pop();if(r.has(e))continue;r.add(e);let n=t.commits.find(t=>t.hash===e);n&&i.push(...n.parents)}e=e.filter(e=>r.has(e.hash))}}if(w.trim()){let t=w.toLowerCase();e=e.filter(e=>e.subject.toLowerCase().includes(t)||e.authorName.toLowerCase().includes(t)||e.abbreviatedHash.includes(t)||e.hash.includes(t))}return e},[t,S,w]),Z=(0,L.useMemo)(()=>t?{...t,commits:X}:null,[t,X]),Q=(0,L.useMemo)(()=>te(Z),[Z]),$=X.length*24+48;return{data:t,loading:r,loadingMore:a,hasMore:l,error:d,acting:m,selectedCommit:g,setSelectedCommit:_,commitFiles:v,loadingDetail:b,branchFilter:S,setBranchFilter:C,searchQuery:w,setSearchQuery:T,showSearch:E,setShowSearch:D,fetchGraph:A,fetchFromRemotes:N,loadMore:j,handleCheckout:P,handleCherryPick:F,handleRevert:I,handleMerge:R,handleDeleteBranch:z,handlePushBranch:re,handleCreateBranch:U,handleCreateTag:V,handleCreatePr:W,copyHash:H,selectCommit:G,openDiffForCommit:K,commitLabels:q,currentBranch:J,headHash:Y,filteredCommits:X,filteredLanes:Q,svgHeight:$,svgPaths:(0,L.useMemo)(()=>ne(Z,Q.laneMap,Q.unloadedParentLanes,$),[Z,Q.laneMap,Q.unloadedParentLanes,$])}}function V(e){let[t,n]=(0,L.useState)(e),r=(0,L.useRef)(e);r.current=t;let i=(0,L.useRef)(!1);return{widths:t,startResize:(e,t)=>{i.current=!0;let a=r.current[e]??80,o=r=>{if(!i.current)return;let o=`touches`in r?r.touches[0].clientX:r.clientX,s=Math.max(40,a+o-t);n(t=>({...t,[e]:s}))},s=()=>{i.current=!1,window.removeEventListener(`mousemove`,o),window.removeEventListener(`mouseup`,s),window.removeEventListener(`touchmove`,o),window.removeEventListener(`touchend`,s)};window.addEventListener(`mousemove`,o),window.addEventListener(`mouseup`,s),window.addEventListener(`touchmove`,o,{passive:!1}),window.addEventListener(`touchend`,s)}}}var H=a();function U({branches:e,branchFilter:t,onBranchFilterChange:n,searchQuery:i,onSearchQueryChange:a,showSearch:o,onToggleSearch:s,onFetch:c,onRefresh:l,onOpenSettings:u,loading:d,acting:f,projectName:p}){let m=e.filter(e=>!e.remote),[h,g]=(0,L.useState)(!1),[v,y]=(0,L.useState)(``),b=(0,L.useRef)(null);(0,L.useEffect)(()=>{if(!h)return;let e=e=>{b.current&&!b.current.contains(e.target)&&(g(!1),y(``))};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[h]);let x=v?m.filter(e=>e.name.toLowerCase().includes(v.toLowerCase())):m,S=t===`__all__`?`Show All`:m.find(e=>e.name===t)?.name??`Show All`;return(0,H.jsx)(`div`,{className:`border-b bg-background`,children:(0,H.jsxs)(`div`,{className:`flex items-center gap-1.5 px-2 py-1.5`,children:[(0,H.jsxs)(`div`,{className:`flex items-center gap-1 text-xs text-muted-foreground shrink-0`,children:[(0,H.jsx)(`span`,{className:`font-semibold`,children:`Repo:`}),(0,H.jsx)(`span`,{className:`font-medium text-foreground truncate max-w-[120px]`,children:p??`—`})]}),(0,H.jsx)(`div`,{className:`w-px h-4 bg-border mx-1`}),(0,H.jsxs)(`div`,{className:`relative shrink-0`,ref:b,children:[(0,H.jsxs)(`button`,{type:`button`,className:`flex items-center gap-1 h-6 px-2 text-xs border rounded-md bg-transparent hover:bg-muted/50`,onClick:()=>{g(e=>!e),y(``)},children:[(0,H.jsx)(`span`,{className:`font-semibold text-muted-foreground`,children:`Branches:`}),(0,H.jsx)(`span`,{className:`max-w-[100px] truncate`,children:S}),(0,H.jsx)(_,{className:`size-3 opacity-50`})]}),h&&(0,H.jsxs)(`div`,{className:`absolute top-full left-0 mt-1 z-50 w-[220px] rounded-md border bg-popover shadow-md`,children:[(0,H.jsx)(`div`,{className:`p-1.5`,children:(0,H.jsx)(P,{className:`h-6 text-xs px-2`,placeholder:`Filter branches...`,value:v,onChange:e=>y(e.target.value),autoFocus:!0})}),(0,H.jsxs)(`div`,{className:`max-h-[200px] overflow-y-auto p-1`,children:[(0,H.jsx)(W,{label:`Show All`,selected:t===`__all__`,onClick:()=>{n(`__all__`),g(!1)}}),x.map(e=>(0,H.jsx)(W,{label:e.name,current:e.current,selected:t===e.name,onClick:()=>{n(e.name),g(!1)}},e.name)),x.length===0&&v&&(0,H.jsx)(`div`,{className:`px-2 py-1.5 text-xs text-muted-foreground`,children:`No branches found`})]})]})]}),(0,H.jsx)(`div`,{className:`flex-1`}),o&&(0,H.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,H.jsx)(P,{className:`h-6 text-xs w-[160px] px-2`,placeholder:`Search commits...`,value:i,onChange:e=>a(e.target.value),autoFocus:!0}),(0,H.jsx)(O,{variant:`ghost`,size:`icon-xs`,onClick:s,children:(0,H.jsx)(T,{className:`size-3`})})]}),!o&&(0,H.jsx)(O,{variant:`ghost`,size:`icon-xs`,onClick:s,title:`Find`,children:(0,H.jsx)(N,{className:`size-3.5`})}),(0,H.jsx)(O,{variant:`ghost`,size:`icon-xs`,onClick:u,title:`Settings`,children:(0,H.jsx)(E,{className:`size-3.5`})}),(0,H.jsx)(O,{variant:`ghost`,size:`icon-xs`,onClick:c,disabled:f,title:`Fetch`,children:(0,H.jsx)(r,{className:`size-3.5`})}),(0,H.jsx)(O,{variant:`ghost`,size:`icon-xs`,onClick:l,disabled:f,title:`Refresh`,children:(0,H.jsx)(M,{className:`size-3.5 ${d?`animate-spin`:``}`})})]})})}function W({label:e,selected:t,current:n,onClick:r}){return(0,H.jsxs)(`button`,{type:`button`,className:`flex items-center gap-2 w-full px-2 py-1 text-xs rounded-sm hover:bg-accent hover:text-accent-foreground text-left`,onClick:r,children:[(0,H.jsx)(y,{className:`size-3 shrink-0 ${t?`opacity-100`:`opacity-0`}`}),(0,H.jsx)(`span`,{className:`truncate flex-1`,children:e}),n&&(0,H.jsx)(`span`,{className:`text-[10px] text-muted-foreground italic`,children:`current`})]})}function G({commits:e,laneMap:t,svgPaths:n,width:r,height:i,headHash:a}){return(0,H.jsxs)(`svg`,{width:r,height:i,children:[n.map((e,t)=>(0,H.jsx)(`path`,{d:e.d,stroke:e.color,strokeWidth:2,fill:`none`},t)),e.map((e,n)=>{let r=t.get(e.hash)??0,i=r*16+16/2,o=n*24+24/2,s=R[r%R.length],c=e.hash===a;return(0,H.jsx)(`circle`,{cx:i,cy:o,r:c?5:4,fill:s,stroke:c?`#000`:`none`,strokeWidth:c?2:0},e.hash)})]})}function K({name:e,type:t,remotes:n,isCurrent:r,color:a,currentBranch:o,onCheckout:s,onMerge:c,onPush:l,onCreatePr:d,onDelete:p}){return t===`tag`?(0,H.jsxs)(`span`,{className:`inline-flex items-center gap-0.5 px-1.5 py-0.5 rounded text-[10px] font-medium shrink-0 bg-amber-500/20 text-amber-500 border border-amber-500/30`,children:[(0,H.jsx)(i,{className:`size-2.5`}),e]}):(0,H.jsxs)(g,{children:[(0,H.jsx)(m,{asChild:!0,children:(0,H.jsxs)(`span`,{className:`inline-flex items-center rounded text-[10px] font-medium shrink-0 cursor-context-menu overflow-hidden`,style:{border:r?`1.5px solid ${a}`:`1px solid ${a}50`},children:[(0,H.jsxs)(`span`,{className:`inline-flex items-center gap-0.5 px-1.5 py-0.5`,style:{backgroundColor:r?a:`${a}30`,color:r?`#fff`:a},children:[(0,H.jsx)(D,{className:`size-2.5`}),e]}),n.map(e=>(0,H.jsx)(`span`,{className:`px-1.5 py-0.5 italic opacity-70`,style:{borderLeft:`1px solid ${a}40`,color:a,backgroundColor:`${a}15`},children:e},e))]})}),(0,H.jsxs)(v,{children:[(0,H.jsx)(x,{onClick:()=>s(e),children:`Checkout`}),(0,H.jsxs)(x,{onClick:()=>c(e),disabled:e===o?.name,children:[(0,H.jsx)(I,{className:`size-3`}),`Merge into current`]}),(0,H.jsx)(f,{}),(0,H.jsxs)(x,{onClick:()=>l(e),children:[(0,H.jsx)(h,{className:`size-3`}),`Push`]}),(0,H.jsxs)(x,{onClick:()=>d(e),children:[(0,H.jsx)(u,{className:`size-3`}),`Create PR`]}),(0,H.jsx)(f,{}),(0,H.jsxs)(x,{variant:`destructive`,onClick:()=>p(e),disabled:e===o?.name,children:[(0,H.jsx)(S,{className:`size-3`}),`Delete`]})]})]})}function q({commit:e,lane:t,isSelected:n,isHead:r,labels:a,currentBranch:o,onSelect:s,onCheckout:c,onCherryPick:l,onRevert:u,onMerge:d,onDeleteBranch:p,onPushBranch:h,onCreatePr:_,onOpenCreateBranch:y,onOpenCreateTag:b,onOpenDiff:S,onCopyHash:C}){let T=R[t%R.length],E=a.filter(e=>e.type===`branch`),O=a.filter(e=>e.type===`tag`);return(0,H.jsxs)(g,{children:[(0,H.jsx)(m,{asChild:!0,children:(0,H.jsxs)(`tr`,{className:`hover:bg-muted/50 cursor-pointer border-b border-border/20 ${n?`bg-primary/10`:``} ${r?`font-medium`:``}`,style:{height:`24px`},onClick:s,children:[(0,H.jsx)(`td`,{className:`px-2 truncate max-w-0`,children:(0,H.jsxs)(`div`,{className:`flex items-center gap-1.5 min-w-0`,children:[E.map(e=>(0,H.jsx)(K,{name:e.name,type:`branch`,remotes:e.remotes,isCurrent:e.current,color:T,currentBranch:o,onCheckout:c,onMerge:d,onPush:h,onCreatePr:_,onDelete:p},`branch-${e.name}`)),O.map(e=>(0,H.jsx)(K,{name:e.name,type:`tag`,remotes:[],isCurrent:!1,color:T,currentBranch:o,onCheckout:c,onMerge:d,onPush:h,onCreatePr:_,onDelete:p},`tag-${e.name}`)),(0,H.jsx)(`span`,{className:`truncate text-xs`,children:e.subject})]})}),(0,H.jsx)(`td`,{className:`px-2 text-xs text-muted-foreground whitespace-nowrap shrink-0`,children:z(e.authorDate)}),(0,H.jsx)(`td`,{className:`px-2 text-xs text-muted-foreground truncate max-w-[120px]`,children:e.authorName}),(0,H.jsx)(`td`,{className:`px-2 text-xs text-muted-foreground font-mono whitespace-nowrap`,children:e.abbreviatedHash})]})}),(0,H.jsxs)(v,{children:[(0,H.jsx)(x,{onClick:()=>c(e.hash),children:`Checkout`}),(0,H.jsxs)(x,{onClick:()=>y(e.hash),children:[(0,H.jsx)(D,{className:`size-3`}),`Create Branch...`]}),(0,H.jsx)(f,{}),(0,H.jsxs)(x,{onClick:()=>l(e.hash),children:[(0,H.jsx)(F,{className:`size-3`}),`Cherry Pick`]}),(0,H.jsxs)(x,{onClick:()=>u(e.hash),children:[(0,H.jsx)(A,{className:`size-3`}),`Revert`]}),(0,H.jsxs)(x,{onClick:()=>b(e.hash),children:[(0,H.jsx)(i,{className:`size-3`}),`Create Tag...`]}),(0,H.jsx)(f,{}),(0,H.jsx)(x,{onClick:S,children:`View Diff`}),(0,H.jsxs)(x,{onClick:C,children:[(0,H.jsx)(w,{className:`size-3`}),`Copy Hash`]})]})]})}function J({commit:e,files:t,loadingDetail:n,projectName:r,onClose:i,copyHash:a}){let{openTab:s}=p();return(0,H.jsxs)(`div`,{className:`border-t bg-muted/30 max-h-[40%] overflow-auto`,children:[(0,H.jsxs)(`div`,{className:`px-3 py-2 border-b flex items-center justify-between`,children:[(0,H.jsxs)(`span`,{className:`text-sm font-medium truncate`,children:[e.abbreviatedHash,` — `,e.subject]}),(0,H.jsx)(O,{variant:`ghost`,size:`icon-xs`,onClick:i,children:`✕`})]}),(0,H.jsxs)(`div`,{className:`px-3 py-2 text-xs space-y-1`,children:[(0,H.jsxs)(`div`,{className:`flex gap-4`,children:[(0,H.jsx)(`span`,{className:`text-muted-foreground w-12 shrink-0`,children:`Author`}),(0,H.jsxs)(`span`,{children:[e.authorName,` <`,e.authorEmail,`>`]})]}),(0,H.jsxs)(`div`,{className:`flex gap-4`,children:[(0,H.jsx)(`span`,{className:`text-muted-foreground w-12 shrink-0`,children:`Date`}),(0,H.jsx)(`span`,{children:new Date(e.authorDate).toLocaleString()})]}),(0,H.jsxs)(`div`,{className:`flex gap-4`,children:[(0,H.jsx)(`span`,{className:`text-muted-foreground w-12 shrink-0`,children:`Hash`}),(0,H.jsx)(`span`,{className:`font-mono cursor-pointer hover:text-primary`,onClick:()=>a(e.hash),children:e.hash})]}),e.parents.length>0&&(0,H.jsxs)(`div`,{className:`flex gap-4`,children:[(0,H.jsx)(`span`,{className:`text-muted-foreground w-12 shrink-0`,children:`Parents`}),(0,H.jsx)(`span`,{className:`font-mono`,children:e.parents.map(e=>e.slice(0,7)).join(`, `)})]}),e.body&&(0,H.jsx)(`div`,{className:`mt-2 p-2 bg-background rounded text-xs whitespace-pre-wrap`,children:e.body})]}),(0,H.jsxs)(`div`,{className:`px-3 py-1 border-t`,children:[(0,H.jsx)(`div`,{className:`text-xs text-muted-foreground py-1`,children:n?`Loading files...`:`${t.length} file${t.length===1?``:`s`} changed`}),t.map(t=>(0,H.jsxs)(`div`,{className:`flex items-center gap-2 py-0.5 text-xs hover:bg-muted/50 rounded px-1 cursor-pointer`,onClick:()=>s({type:`git-diff`,title:`Diff ${o(t.path)}`,closable:!0,metadata:{projectName:r,ref1:e.parents[0]??void 0,ref2:e.hash,filePath:t.path},projectId:r}),children:[(0,H.jsx)(`span`,{className:`flex-1 truncate font-mono`,children:t.path}),t.additions>0&&(0,H.jsxs)(`span`,{className:`text-green-500`,children:[`+`,t.additions]}),t.deletions>0&&(0,H.jsxs)(`span`,{className:`text-red-500`,children:[`-`,t.deletions]})]},t.path))]})]})}function Y({type:e,hash:t,onClose:n,onCreateBranch:r,onCreateTag:i}){let[a,o]=(0,L.useState)(``),s=()=>{a.trim()&&(e===`branch`?r(a.trim(),t):i(a.trim(),t),n())};return(0,H.jsx)(C,{open:e!==null,onOpenChange:e=>{e||n()},children:(0,H.jsxs)(d,{children:[(0,H.jsx)(k,{children:(0,H.jsx)(l,{children:e===`branch`?`Create Branch`:`Create Tag`})}),(0,H.jsx)(P,{placeholder:e===`branch`?`Branch name`:`Tag name`,value:a,onChange:e=>o(e.target.value),onKeyDown:e=>{e.key===`Enter`&&s()},autoFocus:!0}),(0,H.jsxs)(b,{children:[(0,H.jsx)(O,{variant:`outline`,onClick:n,children:`Cancel`}),(0,H.jsx)(O,{disabled:!a.trim(),onClick:s,children:`Create`})]})]})})}function X({open:e,onClose:t,projectName:n,branches:r}){let i=r.filter(e=>!e.remote),a=r.filter(e=>e.remote),o=new Map;for(let e of a){let t=e.name.replace(/^remotes\//,``),n=t.indexOf(`/`);if(n<0)continue;let r=t.slice(0,n),i=t.slice(n+1),a=o.get(r)??[];a.push(i),o.set(r,a)}return(0,H.jsx)(C,{open:e,onOpenChange:e=>{e||t()},children:(0,H.jsxs)(d,{className:`max-w-md`,children:[(0,H.jsx)(k,{children:(0,H.jsx)(l,{children:`Repository Settings`})}),(0,H.jsxs)(`div`,{className:`space-y-4 text-sm`,children:[(0,H.jsxs)(Z,{title:`General`,children:[(0,H.jsx)(Q,{label:`Name`,value:n}),(0,H.jsx)(Q,{label:`Branches`,value:`${i.length} local, ${a.length} remote`})]}),(0,H.jsx)(Z,{title:`Local Branches`,children:i.map(e=>(0,H.jsxs)(`div`,{className:`flex items-center gap-2 py-0.5`,children:[(0,H.jsx)(`span`,{className:`text-xs ${e.current?`font-semibold text-primary`:`text-foreground`}`,children:e.name}),e.current&&(0,H.jsx)(`span`,{className:`text-[10px] text-muted-foreground italic`,children:`HEAD`}),e.remotes.length>0&&(0,H.jsxs)(`span`,{className:`text-[10px] text-muted-foreground`,children:[`(`,e.remotes.join(`, `),`)`]})]},e.name))}),(0,H.jsxs)(Z,{title:`Remotes`,children:[[...o.entries()].map(([e,t])=>(0,H.jsxs)(`div`,{className:`py-0.5`,children:[(0,H.jsx)(`span`,{className:`text-xs font-medium`,children:e}),(0,H.jsxs)(`span`,{className:`text-[10px] text-muted-foreground ml-2`,children:[t.length,` branch`,t.length===1?``:`es`]})]},e)),o.size===0&&(0,H.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`No remotes configured`})]})]})]})})}function Z({title:e,children:t}){return(0,H.jsxs)(`div`,{children:[(0,H.jsx)(`h4`,{className:`text-xs font-semibold text-muted-foreground uppercase tracking-wider mb-1.5`,children:e}),(0,H.jsx)(`div`,{className:`pl-1`,children:t})]})}function Q({label:e,value:t}){return(0,H.jsxs)(`div`,{className:`flex items-center gap-3 py-0.5`,children:[(0,H.jsx)(`span`,{className:`text-xs text-muted-foreground w-16 shrink-0`,children:e}),(0,H.jsx)(`span`,{className:`text-xs`,children:t})]})}function $({metadata:e}){let t=e?.projectName,n=re(t),[r,i]=(0,L.useState)({type:null}),[a,o]=(0,L.useState)(!1),s=(typeof window<`u`&&window.innerWidth<768?6:10)*16+16,[c,l]=(0,L.useState)(s),u=(0,L.useRef)(s);u.current=c;let d=(0,L.useRef)(!1),f=e=>{d.current=!0;let t=u.current,n=n=>{if(!d.current)return;let r=`touches`in n?n.touches[0].clientX:n.clientX;l(Math.max(40,t+r-e))},r=()=>{d.current=!1,window.removeEventListener(`mousemove`,n),window.removeEventListener(`mouseup`,r),window.removeEventListener(`touchmove`,n),window.removeEventListener(`touchend`,r)};window.addEventListener(`mousemove`,n),window.addEventListener(`mouseup`,r),window.addEventListener(`touchmove`,n,{passive:!1}),window.addEventListener(`touchend`,r)},{widths:p,startResize:m}=V({date:80,author:120,commit:70}),h=(0,L.useRef)(n.loadMore);h.current=n.loadMore;let g=(0,L.useCallback)(e=>{let t=e.currentTarget;t.scrollHeight-t.scrollTop-t.clientHeight<200&&h.current()},[]);return t?n.loading&&!n.data?(0,H.jsx)(oe,{}):n.error&&!n.data?(0,H.jsx)(se,{error:n.error,onRetry:n.fetchGraph}):(0,H.jsxs)(`div`,{className:`flex flex-col h-full`,children:[(0,H.jsx)(U,{branches:n.data?.branches??[],branchFilter:n.branchFilter,onBranchFilterChange:n.setBranchFilter,searchQuery:n.searchQuery,onSearchQueryChange:n.setSearchQuery,showSearch:n.showSearch,onToggleSearch:()=>n.setShowSearch(!n.showSearch),onFetch:n.fetchFromRemotes,onRefresh:n.fetchGraph,onOpenSettings:()=>o(!0),loading:n.loading,acting:n.acting,projectName:t}),n.error&&(0,H.jsx)(`div`,{className:`px-3 py-1.5 text-xs text-destructive bg-destructive/10`,children:n.error}),(0,H.jsx)(`div`,{className:`flex-1 overflow-auto`,onScroll:g,children:(0,H.jsxs)(`div`,{className:`flex min-w-max md:min-w-0`,children:[(0,H.jsxs)(`div`,{className:`sticky left-0 z-10 shrink-0 bg-background relative overflow-hidden`,style:{width:`${c}px`},children:[(0,H.jsx)(`div`,{className:`text-[11px] font-semibold text-muted-foreground px-2 border-b bg-background sticky top-0 z-20`,style:{height:`24px`,lineHeight:`24px`},children:`Graph`}),(0,H.jsx)(G,{commits:n.filteredCommits,laneMap:n.filteredLanes.laneMap,svgPaths:n.svgPaths,width:(n.filteredLanes.maxLane+2)*16,height:n.svgHeight,headHash:n.headHash}),(0,H.jsx)(`div`,{className:`absolute top-0 right-0 w-1.5 h-full cursor-col-resize hover:bg-primary/30`,onMouseDown:e=>{e.preventDefault(),f(e.clientX)},onTouchStart:e=>f(e.touches[0].clientX)})]}),(0,H.jsxs)(`div`,{className:`flex-1 min-w-[400px]`,children:[(0,H.jsxs)(`table`,{className:`w-full border-collapse text-xs`,style:{tableLayout:`fixed`},children:[(0,H.jsxs)(`colgroup`,{children:[(0,H.jsx)(`col`,{}),(0,H.jsx)(`col`,{style:{width:`${p.date}px`}}),(0,H.jsx)(`col`,{style:{width:`${p.author}px`}}),(0,H.jsx)(`col`,{style:{width:`${p.commit}px`}})]}),(0,H.jsx)(`thead`,{className:`sticky top-0 z-10 bg-background`,children:(0,H.jsxs)(`tr`,{className:`border-b text-[11px] font-semibold text-muted-foreground`,style:{height:`24px`},children:[(0,H.jsx)(`th`,{className:`text-left px-2 font-semibold`,children:`Description`}),(0,H.jsx)(ie,{label:`Date`,colKey:`date`,onStartResize:m}),(0,H.jsx)(ie,{label:`Author`,colKey:`author`,onStartResize:m}),(0,H.jsx)(`th`,{className:`text-left px-2 font-semibold`,children:`Commit`})]})}),(0,H.jsx)(`tbody`,{children:n.filteredCommits.map(e=>(0,H.jsx)(q,{commit:e,lane:n.filteredLanes.laneMap.get(e.hash)??0,isSelected:n.selectedCommit?.hash===e.hash,isHead:e.hash===n.headHash,labels:n.commitLabels.get(e.hash)??[],currentBranch:n.currentBranch,onSelect:()=>n.selectCommit(e),onCheckout:n.handleCheckout,onCherryPick:n.handleCherryPick,onRevert:n.handleRevert,onMerge:n.handleMerge,onDeleteBranch:n.handleDeleteBranch,onPushBranch:n.handlePushBranch,onCreatePr:n.handleCreatePr,onOpenCreateBranch:e=>i({type:`branch`,hash:e}),onOpenCreateTag:e=>i({type:`tag`,hash:e}),onOpenDiff:()=>n.openDiffForCommit(e),onCopyHash:()=>n.copyHash(e.hash)},e.hash))})]}),n.loadingMore&&(0,H.jsxs)(`div`,{className:`flex items-center justify-center gap-2 py-3 text-xs text-muted-foreground`,children:[(0,H.jsx)(j,{className:`size-3.5 animate-spin`}),` Loading more commits...`]}),!n.hasMore&&n.data&&n.data.commits.length>0&&(0,H.jsxs)(`div`,{className:`text-center py-2 text-xs text-muted-foreground`,children:[n.data.commits.length,` commits loaded`]})]})]})}),n.selectedCommit&&t&&(0,H.jsx)(J,{commit:n.selectedCommit,files:n.commitFiles,loadingDetail:n.loadingDetail,projectName:t,onClose:()=>n.setSelectedCommit(null),copyHash:n.copyHash}),(0,H.jsx)(Y,{type:r.type,hash:r.hash,onClose:()=>i({type:null}),onCreateBranch:n.handleCreateBranch,onCreateTag:n.handleCreateTag}),(0,H.jsx)(X,{open:a,onClose:()=>o(!1),projectName:t,branches:n.data?.branches??[]})]}):(0,H.jsx)(ae,{msg:`No project selected.`})}function ie({label:e,colKey:t,onStartResize:n}){return(0,H.jsxs)(`th`,{className:`text-left px-2 font-semibold relative`,children:[e,(0,H.jsx)(`div`,{className:`absolute top-0 right-0 w-1.5 h-full cursor-col-resize hover:bg-primary/30`,onMouseDown:e=>{e.preventDefault(),n(t,e.clientX)},onTouchStart:e=>n(t,e.touches[0].clientX)})]})}function ae({msg:e}){return(0,H.jsx)(`div`,{className:`flex items-center justify-center h-full text-muted-foreground text-sm`,children:e})}function oe(){return(0,H.jsxs)(`div`,{className:`flex items-center justify-center h-full gap-2 text-muted-foreground`,children:[(0,H.jsx)(j,{className:`size-5 animate-spin`}),(0,H.jsx)(`span`,{className:`text-sm`,children:`Loading git graph...`})]})}function se({error:e,onRetry:t}){return(0,H.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full gap-2 text-destructive text-sm`,children:[(0,H.jsx)(`p`,{children:e}),(0,H.jsx)(O,{variant:`outline`,size:`sm`,onClick:t,children:`Retry`})]})}export{$ as GitGraph};
|