@jingyi0605/codingns 0.7.1 → 0.7.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. package/dist/public/assets/{AdaptiveButlerPage-Cd8nPdO0.js → AdaptiveButlerPage-CgBX49t-.js} +3 -3
  2. package/dist/public/assets/{App-CyxK-Nos.js → App-tXOqoHNl.js} +3 -3
  3. package/dist/public/assets/{BootstrapPage-DEwPKWR8.js → BootstrapPage-DoRMz87R.js} +1 -1
  4. package/dist/public/assets/ConversationPage-DXR6Hp4O.js +9 -0
  5. package/dist/public/assets/{DesktopDetachPreviewPage-DDOWolgB.js → DesktopDetachPreviewPage-Cyk-ZYCk.js} +1 -1
  6. package/dist/public/assets/{DesktopWindowPage-CtS9D8FD.js → DesktopWindowPage-DNVNK3hs.js} +1 -1
  7. package/dist/public/assets/{FileContextPanel-CNOjhsi5.js → FileContextPanel-xGTYDclT.js} +1 -1
  8. package/dist/public/assets/{GitSidebar-DpC4UhFy.js → GitSidebar-Cr3Z9OUI.js} +1 -1
  9. package/dist/public/assets/{MobileCreateSessionSheet-DE4pTyXj.js → MobileCreateSessionSheet-DMW0V6GJ.js} +1 -1
  10. package/dist/public/assets/{MobileTopHeaderFrame-D_ZbS0qi.js → MobileTopHeaderFrame-CkdnZ_MU.js} +1 -1
  11. package/dist/public/assets/{MobileWorkspaceSwitcherHeader-Dc12IAXc.js → MobileWorkspaceSwitcherHeader-KIbqBYJN.js} +1 -1
  12. package/dist/public/assets/{RelayConnectEntryPage-D8kyZfdm.js → RelayConnectEntryPage-DIRBH3hw.js} +1 -1
  13. package/dist/public/assets/{ServerSettingsModal-8eRu6VXr.js → ServerSettingsModal-C-9RxdWP.js} +1 -1
  14. package/dist/public/assets/{SessionIndexPage-DIi0JWKP.js → SessionIndexPage-bRlIydRA.js} +1 -1
  15. package/dist/public/assets/{SettingsPage-OQq3kp32.js → SettingsPage-CMEt4ua9.js} +1 -1
  16. package/dist/public/assets/{TerminalManagerPanel-BEMzisSy.js → TerminalManagerPanel-2bi9wVhT.js} +1 -1
  17. package/dist/public/assets/{TerminalPage-CXLQfwjU.js → TerminalPage-DayZz2Tf.js} +1 -1
  18. package/dist/public/assets/{TerminalRuntimeFallbackModal-BY_VUAbq.js → TerminalRuntimeFallbackModal-DgwYcp-Y.js} +1 -1
  19. package/dist/public/assets/{ToolFilesPage-CYx3DgHg.js → ToolFilesPage-YvnP_FXW.js} +1 -1
  20. package/dist/public/assets/{ToolGitPage-fgQcvF6v.js → ToolGitPage-GMcQKtV9.js} +1 -1
  21. package/dist/public/assets/{ToolProcessesPage-BL6yDDPV.js → ToolProcessesPage-DFIQ7BCd.js} +1 -1
  22. package/dist/public/assets/{ToolsHomePage-B1n2OeVw.js → ToolsHomePage-CSilFzXR.js} +1 -1
  23. package/dist/public/assets/{WorkbenchLandingPage-Cu9yAWYo.js → WorkbenchLandingPage-1VtToSz9.js} +1 -1
  24. package/dist/public/assets/WorkbenchLayout-DScHaza9.js +244 -0
  25. package/dist/public/assets/{WorkbenchModal-Bpb_G1-U.js → WorkbenchModal-BWXYSXmC.js} +1 -1
  26. package/dist/public/assets/WorkbenchShellRoute-DN6LdrqC.js +1 -0
  27. package/dist/public/assets/{WorkspaceDebugDetailPage-CZwT99iQ.js → WorkspaceDebugDetailPage-Ux8_Q7la.js} +1 -1
  28. package/dist/public/assets/{WorkspaceDetailPage-DCM-olfU.js → WorkspaceDetailPage-B402p99m.js} +1 -1
  29. package/dist/public/assets/{WorkspaceHomePage-CsIIqIma.js → WorkspaceHomePage-D2pob6HI.js} +1 -1
  30. package/dist/public/assets/{client-runtime-manager-CMK7kLp8.js → client-runtime-manager-C5D76ewj.js} +1 -1
  31. package/dist/public/assets/{file-tree-icon-Bv-apgA1.js → file-tree-icon-lfU9Ag77.js} +1 -1
  32. package/dist/public/assets/index-CFYXCsyx.css +1 -0
  33. package/dist/public/assets/{index-O3gOb1E0.js → index-NGxWr8Ix.js} +3 -3
  34. package/dist/public/assets/{login-direct-candidate-resolver-Bn4I5JHh.js → login-direct-candidate-resolver-wXSaB0i7.js} +1 -1
  35. package/dist/public/assets/{model-switch-api-ZGnyVir7.js → model-switch-api-CPtou49j.js} +1 -1
  36. package/dist/public/assets/{preferences-service-scuqVhuA.js → preferences-service-CdaK7zA8.js} +1 -1
  37. package/dist/public/assets/{realtime-client-TRootbbB.js → realtime-client-BjQazYsK.js} +1 -1
  38. package/dist/public/assets/{relay-entry-eyCjVFMA.js → relay-entry-BwE5nw0l.js} +1 -1
  39. package/dist/public/assets/{terminal-runtime-meta-BGcnzxqn.js → terminal-runtime-meta-C-Lbyx2i.js} +1 -1
  40. package/dist/public/assets/{useRegisteredDebugTemplates-BdgPIDVM.js → useRegisteredDebugTemplates-BM7-c-gx.js} +1 -1
  41. package/dist/public/index.html +2 -2
  42. package/dist/server/config/env.js +36 -29
  43. package/dist/server/config/env.js.map +1 -1
  44. package/dist/server/modules/sessions/session-history-service.d.ts +3 -1
  45. package/dist/server/modules/sessions/session-history-service.js +55 -2
  46. package/dist/server/modules/sessions/session-history-service.js.map +1 -1
  47. package/dist/server/modules/sessions/session-provider-error-mapper.js +2 -2
  48. package/dist/server/modules/sessions/session-provider-error-mapper.js.map +1 -1
  49. package/dist/server/server/release-manifest-sync.d.ts +7 -0
  50. package/dist/server/server/release-manifest-sync.js +96 -0
  51. package/dist/server/server/release-manifest-sync.js.map +1 -0
  52. package/dist/server/server/start-host.js +2 -0
  53. package/dist/server/server/start-host.js.map +1 -1
  54. package/dist/server/ws/ws-server.js +1 -1
  55. package/dist/server/ws/ws-server.js.map +1 -1
  56. package/node_modules/@codingns/session-sync-core/package.json +1 -1
  57. package/package.json +3 -2
  58. package/scripts/postinstall.mjs +167 -22
  59. package/dist/public/assets/ConversationPage-CxWtRhfz.js +0 -6
  60. package/dist/public/assets/WorkbenchLayout-D6hGXWGE.js +0 -244
  61. package/dist/public/assets/WorkbenchShellRoute-BCjcGWhl.js +0 -1
  62. package/dist/public/assets/index-CkkzIvxs.css +0 -1
@@ -1 +1 @@
1
- import{b as c,j as n,t as r,A as Yn}from"./index-O3gOb1E0.js";import{f as Zn,e as Di,g as ki}from"./App-CyxK-Nos.js";import{aq as Ei,u as Mi,h as Ri,v as _i}from"./model-switch-api-ZGnyVir7.js";import{bh as Ti,bi as Jn,b as en,w as wt,bj as Fi,u as Ai,ac as Me,bk as Li,bl as yt,bm as Ve,bn as Bi,bo as Wi,bp as $i}from"./WorkbenchLayout-D6hGXWGE.js";import{W as Ln}from"./WorkbenchModal-Bpb_G1-U.js";import{r as Mt,a as Rt,F as Oi}from"./file-tree-icon-Bv-apgA1.js";import"./window-BVUB8gMK.js";import"./event-DvH9tcej.js";import"./relay-entry-eyCjVFMA.js";const Hi=new Set([".ds_store","thumbs.db","ehthumbs.db","desktop.ini",".spotlight-v100",".trashes",".fseventsd","__macosx","$recycle.bin","system volume information",".apdisk",".appledouble",".temporaryitems"]),zi=["._"];function xt(t){return t.split(/[/\\]/).filter(Boolean).pop()??t}function Ui(t){const i=t.trim().toLowerCase();return i?Hi.has(i)||zi.some(l=>i.startsWith(l)):!1}function nn(t,i,l){return l?[...t]:t.filter(o=>!Ui(i(o)))}function Nt(t,i){return nn(t,l=>l.name,i)}function Vi(t,i){return i?t:Object.entries(t).reduce((l,[o,h])=>(l[o]=Nt(h,!1),l),{})}async function Zt(t,i){const[l,o]=await Promise.all([Ti(i),Ei(t)]);return Ki(l.changes,o.items)}function Ki(t,i){const l=new Set(i.map(o=>kt(o.path)));return t.filter(o=>l.has(kt(o.path))||o.oldPath!==null&&l.has(kt(o.oldPath)))}function Gi(t){const i=Bn("","");for(const l of t){const o=kt(l.path),h=o.split("/").filter(Boolean);let d=i;h.forEach((b,y)=>{const C=h.slice(0,y+1).join("/");if(y===h.length-1){d.children.set(`file:${C}`,{kind:"file",name:b,path:o,change:l});return}const T=`directory:${C}`,M=d.children.get(T);if(M&&M.kind==="directory"){d=M;return}const Y=Bn(b,C);d.children.set(T,Y),d=Y})}return ei(In([...i.children.values()]))}function Qn(t,i){const l=t.oldPath?`${t.oldPath} -> ${t.path}`:t.path;return an(t)?`${l} ${i}`:l}function an(t){return t.status==="D"||t.stagedStatus==="D"||t.worktreeStatus==="D"}function Dt(t){return t.split("/").filter(Boolean).pop()??t}function kt(t){return t.replace(/\\/g,"/").replace(/^\.\//,"").trim()}function Bn(t,i){return{kind:"directory",name:t,path:i,children:new Map}}function In(t){return[...t].sort((i,l)=>i.kind!==l.kind?i.kind==="directory"?-1:1:i.name.localeCompare(l.name,"zh-CN")).map(i=>i.kind==="directory"?{kind:"directory",name:i.name,path:i.path,children:In([...i.children.values()])}:i)}function ei(t){return t.map(i=>{var b;if(i.kind!=="directory")return i;const l=ei(i.children);let o=i.name,h=i.path,d=l;for(;d.length===1&&((b=d[0])==null?void 0:b.kind)==="directory";){const y=d[0];o=`${o}/${y.name}`,h=y.path,d=y.children}return{kind:"directory",name:o,path:h,children:d}})}const Xi=450,qi=60*1e3,Wn=20,$n=16;function Yi({sessionId:t,workspaceId:i,showSystemFiles:l,selectedPath:o,refreshVersion:h,onCountChange:d,onSelectFile:b,onOpenFile:y}){const[C,T]=c.useState("tree"),[M,Y]=c.useState([]),[me,U]=c.useState(!0),[pe,be]=c.useState(!1),[V,ft]=c.useState([]),k=c.useRef(null),Tt=Jn(),{showToast:je}=Zn();c.useEffect(()=>{const m=en(gt(i,t),qi);T("tree"),Y(m??[]),U(m===null),be(!1),ft([]),k.current=null},[t,i]),c.useEffect(()=>{let m=!1;async function j(){U(!0);try{const v=await Zt(t,i);m||(Y(v),wt(gt(i,t),v))}catch(v){m||je({title:Jt(v,r("conversation.filePanelSessionLoadFailed")),tone:"error"})}finally{m||U(!1)}}return j(),()=>{m=!0}},[h,t,je,i]);async function Se(){U(!0);try{const m=await Zt(t,i);Y(m),wt(gt(i,t),m)}catch(m){je({title:Jt(m,r("conversation.filePanelSessionLoadFailed")),tone:"error"})}finally{U(!1)}}async function D(){if(R.length!==0){be(!0);try{await Fi(i,R.map(j=>j.path));const m=await Zt(t,i);Y(m),wt(gt(i,t),m),je({title:r("conversation.filePanelSessionStageSuccess"),tone:"success"})}catch(m){je({title:Jt(m,r("git.stageFailed")),tone:"error"})}finally{be(!1)}}}function F(m){ft(j=>j.includes(m)?j.filter(v=>v!==m):[...j,m])}function K(m){const j=Date.now(),v=k.current;return k.current={filePath:m,timestamp:j},(v==null?void 0:v.filePath)===m&&j-v.timestamp<=Xi}async function $(m,j){if(j&&K(m)){await y(m),k.current=null;return}j||(k.current=null),await b(m)}const ne=c.useMemo(()=>nn(M,m=>Dt(m.path),l),[M,l]),R=ne.filter(m=>!m.staged),Re=Gi(ne),ie=new Set(V);return c.useEffect(()=>{d==null||d(ne.length)},[d,ne.length]),n.jsxs(n.Fragment,{children:[n.jsxs("div",{className:"file-panel-session-toolbar",children:[n.jsxs("div",{className:"file-panel-view-modes",role:"tablist","aria-label":r("conversation.filePanelSessionViewLabel"),children:[n.jsx("button",{className:C==="tree"?"file-panel-view-button active":"file-panel-view-button",type:"button",role:"tab","aria-selected":C==="tree",onClick:()=>T("tree"),children:r("conversation.filePanelSessionTreeView")}),n.jsx("button",{className:C==="list"?"file-panel-view-button active":"file-panel-view-button",type:"button",role:"tab","aria-selected":C==="list",onClick:()=>T("list"),children:r("conversation.filePanelSessionListView")})]}),n.jsxs("div",{className:"file-panel-session-actions",children:[n.jsx("button",{className:"secondary-button",type:"button",onClick:()=>void Se(),disabled:me||pe,children:r("conversation.filePanelRefresh")}),n.jsx("button",{className:"primary-button",type:"button",onClick:()=>void D(),disabled:pe||R.length===0,children:r("conversation.filePanelSessionStageAll")})]})]}),n.jsxs("div",{className:"file-panel-session-summary",children:[n.jsx("span",{children:`${r("conversation.filePanelSessionSummary")} ${ne.length}`}),n.jsx("span",{children:`${r("conversation.filePanelSessionUnstagedSummary")} ${R.length}`})]}),n.jsx("div",{ref:Tt,className:"file-tree","data-scrollbar-autohide":"true",children:me?n.jsx("p",{className:"file-tree-status status-text",children:r("conversation.filePanelSessionLoading")}):ne.length===0?n.jsx("p",{className:"file-tree-status status-text",children:r("conversation.filePanelSessionEmpty")}):C==="tree"?ti({nodes:Re,depth:0,collapsedPathSet:ie,selectedPath:o,onToggleTreePath:F,onFileClick:$}):Zi({items:ne,selectedPath:o,onFileClick:$})})]})}function ti({nodes:t,depth:i,collapsedPathSet:l,selectedPath:o,onToggleTreePath:h,onFileClick:d}){return t.map(b=>{if(b.kind==="directory"){const y=!l.has(b.path);return n.jsxs("div",{className:"file-tree-node",children:[n.jsxs("button",{className:"file-tree-item",type:"button","data-kind":"directory","aria-expanded":y,style:{paddingInlineStart:`${Wn+i*$n}px`},onClick:()=>h(b.path),children:[n.jsx("span",{className:"file-tree-chevron","aria-hidden":"true",children:y?"v":">"}),n.jsx("span",{className:"file-tree-label",children:b.name})]}),y?n.jsx("div",{className:"file-tree-children",children:ti({nodes:b.children,depth:i+1,collapsedPathSet:l,selectedPath:o,onToggleTreePath:h,onFileClick:d})}):null]},`session-directory:${b.path}`)}return n.jsx("div",{className:"file-tree-node",children:n.jsxs("button",{className:"file-tree-item is-session-change",type:"button","data-active":o===b.change.path,"data-kind":"file",style:{paddingInlineStart:`${Wn+i*$n}px`},onClick:()=>void d(b.change.path,!an(b.change)),children:[n.jsx("span",{className:"file-tree-chevron is-hidden","aria-hidden":"true",children:">"}),n.jsx("span",{className:"git-tree-file-icon","data-kind":Rt(b.name),"aria-hidden":"true",children:Mt(b.name)}),n.jsxs("span",{className:"file-tree-label",children:[n.jsx("span",{className:"file-tree-name",children:b.name}),n.jsx("span",{className:"file-tree-path",children:Qn(b.change,r("conversation.filePanelSessionDeleted"))})]}),n.jsxs("span",{className:"file-session-item-meta",children:[n.jsx("span",{className:"file-session-badge","data-status":b.change.status,children:b.change.status}),n.jsx("span",{className:"file-session-badge subtle",children:b.change.staged?r("git.stagedLabel"):r("git.workingTreeLabel")})]})]})},`session-file:${b.path}`)})}function Zi({items:t,selectedPath:i,onFileClick:l}){return t.map(o=>n.jsx("div",{className:"file-session-list-item",children:n.jsxs("button",{className:"file-session-list-button",type:"button","data-active":i===o.path,onClick:()=>void l(o.path,!an(o)),children:[n.jsx("span",{className:"git-tree-file-icon","data-kind":Rt(Dt(o.path)),"aria-hidden":"true",children:Mt(Dt(o.path))}),n.jsxs("span",{className:"file-tree-label",children:[n.jsx("span",{className:"file-tree-name",children:Dt(o.path)}),n.jsx("span",{className:"file-tree-path",children:Qn(o,r("conversation.filePanelSessionDeleted"))})]}),n.jsxs("span",{className:"file-session-item-meta",children:[n.jsx("span",{className:"file-session-badge","data-status":o.status,children:o.status}),n.jsx("span",{className:"file-session-badge subtle",children:o.staged?r("git.stagedLabel"):r("git.workingTreeLabel")})]})]})},`session-list:${o.path}`))}function gt(t,i){return`file-panel.session-changes.${t}.${i}`}function Jt(t,i){return t instanceof Yn?t.message:typeof t=="object"&&t&&"message"in t?String(t.message??i):i}const g="",Ji=450,ee=8,Pt=4,Qi=176,Ii=120,ea=300*1e3,ta=60*1e3,On=1600,na=20,ia=16;function qa({className:t,sessionId:i,workspaceId:l,hideHeading:o=!1,hideTabs:h=!1,externalRevealRequest:d=null,externalWindowMode:b=!1,workbenchShellOverrides:y}){var Tn,Fn;const C=Ai(),{navigationGroups:T,subscribeFileTree:M,requestFileTreeRefresh:Y,addFileTreeSnapshotListener:me,subscribeGitSnapshot:U,requestGitRefresh:pe,addGitSnapshotListener:be}={...C,...y},[V,ft]=c.useState({}),[k,Tt]=c.useState([]),[je,Se]=c.useState([]),[D,F]=c.useState(g),[K,$]=c.useState([]),[ne,R]=c.useState(null),[Re,ie]=c.useState(!1),[m,j]=c.useState(!1),[v,dt]=c.useState(!1),[Ge,Xe]=c.useState(!1),[A,qe]=c.useState(""),[Ft,G]=c.useState(null),[ht,mt]=c.useState(!1),[we,Ye]=c.useState(null),[X,Ze]=c.useState("workspace"),[sn,_e]=c.useState(0),[rn,At]=c.useState(0),[Je,Z]=c.useState(!1),[Qe,L]=c.useState(!1),[ae,O]=c.useState(null),[ve,Te]=c.useState(null),[B,Fe]=c.useState(null),[P,Lt]=c.useState(null),[w,Ie]=c.useState(null),[Bt,Ae]=c.useState(""),[on,cn]=c.useState([]),[J,Wt]=c.useState(!1),[oi,ye]=c.useState(null),un=c.useId(),le=c.useRef({}),se=c.useRef({}),_=c.useRef([]),Q=c.useRef(g),et=c.useRef(!1),tt=c.useRef(null),ci=Jn(),fn=c.useRef(null),dn=c.useRef(null),$t=c.useRef(null),hn=c.useRef(null),mn=c.useRef(null),xe=c.useRef(0),re=c.useRef(new Map),{showToast:S}=Zn(),nt=Di(),I=Mi(e=>e.showSystemFiles),it=!!(i!=null&&i.trim()),pn=o&&nt.isMobile;c.useEffect(()=>{Me("file_panel.props",{sessionId:i,workspaceId:l,externalWindowMode:b})},[b,i,l]),c.useEffect(()=>{Q.current=D},[D]);function Ne(e){ft(a=>{const s=typeof e=="function"?e(a):e;return le.current=s,s})}function Le(e){Tt(a=>{const s=typeof e=="function"?e(a):e;return _.current=s,s})}c.useEffect(()=>{var f,p;if(Ut(),!l){Ut(),et.current=!1,le.current={},se.current={},_.current=[],Q.current=g,Ne({}),Le([]),Se([]),F(g),Xe(!1),qe(""),G(null),mt(!1),ie(!1),Wt(!1),ye(null),$([]),R(null),O(null),Te(null),Fe(null),Ie(null),Ae("");return}et.current=!0;const e=en(Kn(l),ea);Me("file_panel.workspace_snapshot",{workspaceId:l,cached:!!e,cachedRootItems:((p=(f=e==null?void 0:e.treeCache)==null?void 0:f[g])==null?void 0:p.length)??0,cachedDirectoryCount:Object.keys((e==null?void 0:e.treeCache)??{}).length});const a=Pa((e==null?void 0:e.activeDirectoryPath)??g,(e==null?void 0:e.treeCache)??{}),s=Vn((e==null?void 0:e.expandedDirectories)??[],a),u=St((e==null?void 0:e.treeCache)??{},a,s);le.current=u,se.current=Gn((e==null?void 0:e.treeRevisionByPath)??{},u),_.current=s,Q.current=a,Ne(u),Le(s),Se([]),F(a),ie(!1),j(!1),Xe(!1),qe(""),G(null),mt(!1),queueMicrotask(()=>{et.current=!1})},[l]),c.useEffect(()=>{if(!d||d.workspaceId!==l)return;const e=()=>{if(mn.current===d.requestId)return;mn.current=d.requestId,Ze("workspace"),(d.openViewer?He(d.filePath):ce(d.filePath)).catch(s=>{S({title:te(s,r("conversation.filePanelOpenFailed")),tone:"error"})})};if(et.current){queueMicrotask(e);return}e()},[d,He,ce,S,l]),c.useEffect(()=>{if(l)return me(e=>{e.workspaceId===l&&(se.current={...se.current,[e.path]:typeof e.revision=="string"?e.revision:null},Ne(a=>({...a,[e.path]:e.items})),e.path===g&&ie(!1),Se(a=>a.filter(s=>s!==e.path)),di(e.path,e.items))})},[me,l]),c.useEffect(()=>()=>{Ut()},[]),c.useEffect(()=>{l&&M(l,It(_.current,Q.current),{knownRevisionByPath:se.current})},[D,k,M,l]),c.useEffect(()=>{$([]),R(null),Ye(null),ye(null),_e(0),Z(!1),L(!1),O(null),Te(null),Fe(null),Ie(null),Ae(""),tt.current=null,xe.current+=1},[i]),c.useEffect(()=>{!it&&X==="session"&&Ze("workspace")},[X,it]),c.useEffect(()=>{h&&X!=="workspace"&&Ze("workspace")},[X,h]),c.useEffect(()=>{if(!Je&&!Qe&&!ae)return;function e(s){var x,N,fe;if(!(s.target instanceof Node))return;const u=((x=fn.current)==null?void 0:x.contains(s.target))??!1,f=((N=dn.current)==null?void 0:N.contains(s.target))??!1,p=((fe=$t.current)==null?void 0:fe.contains(s.target))??!1;!u&&!f&&!p&&(Z(!1),L(!1),O(null),Te(null))}function a(s){s.key==="Escape"&&(Z(!1),L(!1),O(null),Te(null))}return document.addEventListener("pointerdown",e),document.addEventListener("keydown",a),()=>{document.removeEventListener("pointerdown",e),document.removeEventListener("keydown",a)}},[Je,Qe,ae]),c.useLayoutEffect(()=>{if(!ae||typeof window>"u"){Te(null);return}const e=ae;function a(){const u=$t.current;if(!u)return;const f=u.getBoundingClientRect();Te(fa({x:e.positionX,y:e.positionY},{width:f.width||Qi,height:f.height||u.scrollHeight||0},{width:window.innerWidth,height:window.innerHeight}))}a();const s=window.requestAnimationFrame(a);return window.addEventListener("resize",a),window.addEventListener("scroll",a,!0),()=>{window.cancelAnimationFrame(s),window.removeEventListener("resize",a),window.removeEventListener("scroll",a,!0)}},[ae]),c.useEffect(()=>{if(!l)return;const e=Vn(k,D),a=St(V,D,e);wt(Kn(l),{treeCache:a,treeRevisionByPath:Gn(se.current,a),expandedDirectories:e,activeDirectoryPath:D})},[D,k,V,l]),c.useEffect(()=>{if(et.current)return;const e=St(V,D,k);ja(V,e)||Ne(e)},[D,k,V]),c.useEffect(()=>{let e=!1;const a=(l==null?void 0:l.trim())??null;async function s(f){if(!a)return;const p=Nt(le.current[g]??[],I),x=(f==null?void 0:f.silent)!==!0&&p.length===0;x&&ie(!0),Me("file_panel.load_root_tree.start",{sessionId:i,workspaceId:a,silent:(f==null?void 0:f.silent)===!0,cachedRootItems:p.length});try{const N=await zt(g,{force:!0});e||(Me("file_panel.load_root_tree.end",{sessionId:i,workspaceId:a,itemCount:N.length}),Ne(fe=>({...St(fe,Q.current,_.current),[g]:N})))}catch(N){!e&&!Xn(N)&&S({title:te(N,r("conversation.filePanelLoadFailed")),tone:"error"})}finally{!e&&x&&ie(!1)}}if(Nt(le.current[g]??[],I).length>0){const f=window.setTimeout(()=>{a&&(M(a,It(_.current,Q.current),{knownRevisionByPath:se.current}),s({silent:!0}))},1500);return()=>{e=!0,window.clearTimeout(f)}}return s(),()=>{e=!0}},[i,I,S,l]),c.useEffect(()=>{if(!l||!i){At(0);return}const e=en(Sa(l,i),ta);Me("file_panel.session_change_count.snapshot",{sessionId:i,workspaceId:l,cached:e!==null,cachedCount:e}),At(e??0)},[i,sn,l]),c.useEffect(()=>{if(!l){cn([]);return}const e=l.trim();U(e),pe(e)},[l,U,pe]),c.useEffect(()=>{if(!l)return;const e=l.trim();return be(a=>{var s;a.workspaceId===e&&cn(((s=a.status)==null?void 0:s.changes)??[])})},[be,l]);const pt=c.useMemo(()=>nn(on,e=>xt(e.path),I),[on,I]),W=c.useMemo(()=>{const e=new Map,a=new Set;for(const s of pt){const u=s.path.replace(/\\/g,"/"),f=s.worktreeStatus??s.stagedStatus??s.status;e.set(u,f);const p=u.split("/");for(let x=1;x<p.length;x++)a.add(p.slice(0,x).join("/"))}return{statusByPath:e,changedDirs:a}},[pt]),De=c.useMemo(()=>Vi(V,I),[I,V]),ke=c.useMemo(()=>Ft===null?null:Nt(Ft,I),[Ft,I]),Be=De[g]??[],oe=Ge&&ke!==null,bt=c.useMemo(()=>J?tn(Be,De,W.statusByPath,W.changedDirs):Be,[W.changedDirs,W.statusByPath,Be,J,De]),ui=c.useMemo(()=>oe?(ke??[]).map(e=>z(e.path,e.kind)):ni(bt,De,k,J,W.statusByPath,W.changedDirs),[k,W.changedDirs,W.statusByPath,oe,J,ke,De,bt]),We=((Tn=T.find(e=>e.workspace.id===l))==null?void 0:Tn.workspace)??null,E=Un(K),Ot=(E==null?void 0:E.path)??null,ge=(E==null?void 0:E.kind)==="file"?E.path:null,vt=c.useMemo(()=>new Set(K.map(e=>e.path)),[K]),at=c.useMemo(()=>jt(K),[K]),Ht=!!(We!=null&&We.path&&K.length===1&&Ot),bn=K.length===1&&(E==null?void 0:E.kind)==="file",vn=at.length>0,Ee=at.length>0,lt=!!(P!=null&&P.items.length&&l),yn=!!l&&K.length===1&&E!==null,xn=!!((ge?he(ge):D)&&k.length),gn=P?P.mode==="copy"?r("conversation.filePanelClipboardCopyReady",{count:P.items.length}):r("conversation.filePanelClipboardCutReady",{count:P.items.length}):null,H=w?pa(w):null;async function Pn(e,a=!1){if(!l)return[];if(!a){const s=le.current[e];if(s)return s}e===g?ie(!0):Se(s=>Et(s,e));try{const s=await zt(e,{force:a});return Ne(u=>({...u,[e]:s})),s}catch(s){throw Xn(s)||S({title:te(s,r("conversation.filePanelLoadFailed")),tone:"error"}),s}finally{e===g?ie(!1):Se(s=>s.filter(u=>u!==e))}}async function Pe(e){if(!l)return;const a=(e==null?void 0:e.activeDirectoryPath)??Q.current,s=(e==null?void 0:e.expandedDirectories)??_.current,u=Ca(le.current,a,s);Me("file_panel.refresh_tree_cache.start",{sessionId:i,workspaceId:l,targetDirectories:u});const p=(await Promise.all(u.map(async x=>{const N=await zt(x,{force:!0});return[x,N]}))).reduce((x,[N,fe])=>(x[N]=fe,x),{});Me("file_panel.refresh_tree_cache.end",{sessionId:i,workspaceId:l,targetDirectories:u,directoryCount:Object.keys(p).length}),Ne(p)}async function zt(e,a){if(!l)return[];if(!(a!=null&&a.force)){const u=le.current[e];if(u)return u}const s=It(Et(_.current,e),e||Q.current);return M(l,s,{knownRevisionByPath:se.current}),Y(l,[e],{knownRevisionByPath:se.current}),fi(e,On,{allowCached:(a==null?void 0:a.force)!==!0})}function fi(e,a=On,s){const u=le.current[e];return(s==null?void 0:s.allowCached)!==!1&&u?Promise.resolve(u):new Promise((f,p)=>{const x=window.setTimeout(()=>{hi(e,x),p(new Error(`FILE_TREE_SNAPSHOT_TIMEOUT:${e}`))},a),N=re.current.get(e)??[];re.current.set(e,[...N,{resolve:f,reject:p,timerId:x}])})}function di(e,a){const s=re.current.get(e)??[];s.length!==0&&(re.current.delete(e),s.forEach(u=>{window.clearTimeout(u.timerId),u.resolve(a)}))}function hi(e,a){const u=(re.current.get(e)??[]).filter(f=>f.timerId!==a);if(u.length===0){re.current.delete(e);return}re.current.set(e,u)}function Ut(){for(const[e,a]of re.current.entries())a.forEach(s=>{window.clearTimeout(s.timerId),s.reject(new Error(`FILE_TREE_ABORTED:${e}`))});re.current.clear()}function $e(e){$([e]),R(e.path)}function st(e){F(e.kind==="directory"?e.path:he(e.path))}function mi(e){const a=sa(ui,ne,e);$(a),R(e.path),st(e)}function pi(e){const a=la(K,e),s=Un(a);$(a),R(e.path),s&&st(s)}function Cn(e){$e(e),st(e)}function Oe(e,a){if(a!=null&&a.shiftKey){mi(e);return}if(Ct(a)){pi(e);return}Cn(e)}async function rt(e,a=!1){const s=ut(e,a);if(!s.length){F(g);return}Le(u=>si(u,s)),F(s[s.length-1]??g);for(const u of s)try{await Pn(u)}catch{return}}async function ce(e){const a=z(e,"file");$e(a),st(a),await rt(e)}async function He(e){Ye(e),ye(null),tt.current=null,xe.current+=1,ce(e);const a=xe.current,s=e.replace(/\\/g,"/"),u=W.statusByPath.get(s);if(l&&u&&u!=="?"&&u!=="D")try{const f=await Li(l,e,!1);xe.current===a&&ye(f.content||null)}catch{xe.current===a&&ye(null)}}function jn(e){const a=Date.now(),s=tt.current;return tt.current={filePath:e,timestamp:a},(s==null?void 0:s.filePath)===e&&a-s.timestamp<=Ji}function Ce(){tt.current=null}async function bi(e,a){const s=z(e,"file");if(a!=null&&a.shiftKey||Ct(a)){Ce(),Oe(s,a);return}if(jn(e)){await He(e);return}Oe(s,a),await rt(e)}function Sn(){Xe(!1),qe(""),G(null),Ce()}async function vi(e,a){const s=z(e.path,e.kind);if(a!=null&&a.shiftKey||Ct(a)){Ce(),Oe(s,a);return}if(e.kind==="directory"){Sn(),Oe(s,a),await wn(e.path);return}if(jn(e.path)){Sn(),await He(e.path);return}await ce(e.path)}async function wn(e){if($e(z(e,"directory")),F(e),!_.current.includes(e))try{await Pn(e),Le(a=>Et(a,e))}catch{}}async function Nn(e){if($e(z(e,"directory")),F(e),_.current.includes(e)){Dn(e);return}await wn(e)}function Dn(e){Le(a=>a.filter(s=>s!==e&&!s.startsWith(`${e}/`))),F(he(e)),$([]),R(null)}async function kn(){if(!l)return;const e=l;try{if(pe(e),await Pe(),ge&&await rt(ge),oe&&A.trim()){const a=await Ve(e,A.trim());G(a.items)}}catch(a){S({title:te(a,r("conversation.filePanelLoadFailed")),tone:"error"})}}async function yi(e){if(e==null||e.preventDefault(),!l||!A.trim()){G(null);return}mt(!0);try{const a=await Ve(l,A.trim());G(a.items)}catch(a){S({title:te(a,r("conversation.filePanelSearchFailed")),tone:"error"})}finally{mt(!1)}}function En(){if(Ge){Xe(!1),qe(""),G(null);return}Xe(!0)}function q(e){L(!1),e()}function Mn(){var e;(e=hn.current)==null||e.click()}async function xi(e){var p;const a=((p=e.target.files)==null?void 0:p[0])??null;if(e.target.value="",!a||!l)return;const s=aa(a.name);if(!s){S({title:r("conversation.filePanelUploadFailed"),tone:"error"});return}const u=Hn(D,E),f=zn(u,s);dt(!0);try{const x=await ba(a);await Bi({workspaceId:l,path:f,contentBase64:x}),await Pe(),await ce(f),S({title:r("conversation.filePanelUploadSuccess",{name:s}),tone:"success"})}catch(x){S({title:te(x,r("conversation.filePanelUploadFailed")),tone:"error"})}finally{dt(!1)}}async function Vt(e=ge){if(!(!l||!e)){dt(!0);try{const a=await Wi(l,e),s=va(a.contentBase64);ya(a.fileName,new Blob([s],{type:"application/octet-stream"})),S({title:r("conversation.filePanelDownloadSuccess",{name:a.fileName}),tone:"success"})}catch(a){S({title:te(a,r("conversation.filePanelDownloadFailed")),tone:"error"})}finally{dt(!1)}}}function Rn(){const e=ge?he(ge):D;!e||!_.current.includes(e)||Dn(e)}function Kt(){Ie(null),Ae("")}function Gt(){m||Kt()}function ze(e,a=Hn(D,E)){if(!l)return;const s=a,u=s?`${s}/`:"";Z(!1),L(!1),O(null),Ie({mode:e,baseDirectory:s}),Ae(u)}function Xt(e=E){!l||!e||(Z(!1),L(!1),O(null),Ie({mode:"rename",target:e}),Ae(e.path))}async function gi(e){if(e==null||e.preventDefault(),!l||!w)return;const a=(Bt??"").trim();if(a){if(w.mode==="rename"&&Ke(w.target.path)===Ke(a)){Gt();return}j(!0);try{if(w.mode==="rename"){const s=w.target.path,u=z(a,w.target.kind),f=we?li(we,s,a):null;if(await yt({workspaceId:l,opType:"rename",srcPath:s,dstPath:a}),P&&Lt({...P,items:ma(P.items,s,a)}),Kt(),Ce(),await Pe(),w.target.kind==="directory"?(await rt(a,!0),$e(u),F(a)):await ce(a),f!==we&&(xe.current+=1,Ye(f),ye(null)),oe&&A.trim()){const p=await Ve(l,A.trim());G(p.items)}_e(p=>p+1),S({title:r("conversation.filePanelRenameSuccess",{name:xt(a)||a}),tone:"success"});return}if(await yt({workspaceId:l,opType:w.mode,dstPath:a,content:w.mode==="create_file"?"":void 0}),Kt(),await Pe(),w.mode==="create_directory"?(await rt(a,!0),$e(z(a,"directory")),F(a)):await ce(a),oe&&A.trim()){const s=await Ve(l,A.trim());G(s.items)}_e(s=>s+1)}catch(s){S({title:te(s,r("conversation.filePanelMutateFailed")),tone:"error"})}finally{j(!1)}}}function ue(e,a=at){var u;if(a.length===0)return;const s=jt(a);Lt({mode:e,items:s}),$(s),R(((u=s[s.length-1])==null?void 0:u.path)??null),S({title:e==="copy"?r("conversation.filePanelCopySelectionSuccess",{count:s.length}):r("conversation.filePanelCutSelectionSuccess",{count:s.length}),tone:"success"}),O(null)}async function ot(e=ca(E,D)){if(!l||!P||!P.items.length)return;const a=e??g,s=P.items.map(u=>({source:u,destinationPath:zn(a,xt(u.path)||u.path)}));j(!0);try{for(const p of s)P.mode==="cut"&&Ke(p.source.path)===Ke(p.destinationPath)||await yt({workspaceId:l,opType:P.mode==="copy"?"copy":"move",srcPath:p.source.path,dstPath:p.destinationPath});const u=s.map(p=>z(p.destinationPath,p.source.kind)),f=u[u.length-1]??null;if(P.mode==="cut"&&Lt(null),$(u),R((f==null?void 0:f.path)??null),f&&st(f),Ce(),await Pe({activeDirectoryPath:(f==null?void 0:f.kind)==="directory"?f.path:f?he(f.path):Q.current,expandedDirectories:_.current}),oe&&A.trim()){const p=await Ve(l,A.trim());G(p.items)}_e(p=>p+1),S({title:r("conversation.filePanelPasteSuccess",{count:u.length}),tone:"success"}),O(null)}catch(u){await Pe().catch(()=>{}),S({title:te(u,r("conversation.filePanelPasteFailed")),tone:"error"})}finally{j(!1)}}function qt(e=at){!e.length||m||(Fe(jt(e)),O(null))}async function Pi(){var a,s;if(!l||!(B!=null&&B.length))return;const e=jt(B);j(!0);try{for(const p of e)await yt({workspaceId:l,opType:"delete",srcPath:p.path});const u=ua(D,e),f=_.current.filter(p=>!e.some(x=>x.kind==="directory"&&_t(x.path,p)));if(we&&e.some(p=>_t(p.path,we))&&(xe.current+=1,Ye(null),ye(null)),Fe(null),$([]),R(null),Q.current=u,_.current=f,F(u),Le(f),Ce(),await Pe({activeDirectoryPath:u,expandedDirectories:f}),oe&&A.trim()){const p=await Ve(l,A.trim());G(p.items)}_e(p=>p+1),S({title:e.length===1?r("conversation.filePanelDeleteSuccess",{name:xt(((a=e[0])==null?void 0:a.path)??"")||((s=e[0])==null?void 0:s.path)||""}):r("conversation.filePanelDeleteSelectionSuccess",{count:e.length}),tone:"success"})}catch(u){S({title:te(u,r("conversation.filePanelMutateFailed")),tone:"error"})}finally{j(!1)}}async function Ue(e,a=E){const s=(We==null?void 0:We.path)??"",u=(a==null?void 0:a.path)??null;if(u===null||!s){Z(!1);return}try{const f=ha(s),p=e==="absolute"?da(s,u,f):Ke(u,f);await xa(p,nt),S({title:e==="absolute"?r("conversation.filePanelCopyAbsolutePathSuccess"):r("conversation.filePanelCopyRelativePathSuccess"),tone:"success"})}catch(f){S({title:f instanceof Error?f.message:r("conversation.filePanelCopyPathFailed"),tone:"error"})}finally{Z(!1),O(null)}}function Ci(e,a,s){return[{id:`open-${e.path}`,label:e.kind==="directory"?k.includes(e.path)?r("conversation.filePanelCollapseDirectory"):r("conversation.filePanelExpandDirectory"):r("conversation.filePanelOpenFile"),onSelect:()=>{if(e.kind==="directory"){Nn(e.path);return}He(e.path)}},{id:`download-${e.path}`,label:r("conversation.filePanelDownload"),disabled:e.kind!=="file"||v,onSelect:()=>{Vt(e.kind==="file"?e.path:null)}},{id:`create-file-${e.path}`,label:r("conversation.filePanelNewFile"),disabled:!l||m||v,onSelect:()=>{ze("create_file",s)}},{id:`create-directory-${e.path}`,label:r("conversation.filePanelNewDirectory"),disabled:!l||m||v,onSelect:()=>{ze("create_directory",s)}},{id:`rename-${e.path}`,label:r("conversation.filePanelRenameMove"),disabled:a.length!==1||m||v,onSelect:()=>Xt(e)},{id:`copy-${e.path}`,label:r("conversation.filePanelCopy"),disabled:a.length===0,onSelect:()=>ue("copy",a)},{id:`cut-${e.path}`,label:r("conversation.filePanelCut"),disabled:a.length===0,onSelect:()=>ue("cut",a)},{id:`paste-${e.path}`,label:r("conversation.filePanelPaste"),disabled:!lt,onSelect:()=>{ot(s)}},{id:`copy-relative-${e.path}`,label:r("conversation.filePanelCopyRelativePath"),onSelect:()=>{Ue("relative",e)}},{id:`copy-absolute-${e.path}`,label:r("conversation.filePanelCopyAbsolutePath"),onSelect:()=>{Ue("absolute",e)}},{id:`delete-${e.path}`,label:r("conversation.filePanelDelete"),disabled:a.length===0||m||v,onSelect:()=>qt(a)}]}async function _n(e,a){if(nt.isMobile)return;e.preventDefault();const s=z(a.path,a.kind),u=vt.has(s.path)?at:[s],f=s.kind==="directory"?s.path:he(s.path);vt.has(s.path)||Cn(s);const p=Ci(s,u,f);if(nt.isDesktop){await $i(p);return}nt.isWeb&&(Z(!1),L(!1),O({positionX:e.clientX,positionY:e.clientY,items:p}))}c.useEffect(()=>{if(X!=="workspace")return;function e(a){if(!ra(a)||a.altKey||a.shiftKey||oa(a.target))return;const s=a.key.toLowerCase();if(s==="c"&&Ee){a.preventDefault(),ue("copy");return}if(s==="x"&&Ee){a.preventDefault(),ue("cut");return}s==="v"&&lt&&(a.preventDefault(),ot())}return document.addEventListener("keydown",e),()=>{document.removeEventListener("keydown",e)}},[X,Ee,lt,ue,ot]);function Yt(e,a){return n.jsx(n.Fragment,{children:e.map(s=>{const u=z(s.path,s.kind),f=s.kind==="directory",p=f&&k.includes(s.path),x=f&&je.includes(s.path),N=De[s.path]??[],fe=J?tn(N,De,W.statusByPath,W.changedDirs):N,Si=vt.has(s.path),wi=Ot===s.path,ct=W.statusByPath.get(s.path.replace(/\\/g,"/")),An=f&&W.changedDirs.has(s.path.replace(/\\/g,"/")),Ni=(P==null?void 0:P.mode)==="cut"&&P.items.some(de=>de.path===s.path);return n.jsxs("div",{className:"file-tree-node",children:[n.jsxs("button",{className:"file-tree-item",type:"button","data-active":wi,"data-selected":Si,"data-cut-pending":Ni||void 0,"data-kind":s.kind,"aria-expanded":f?p:void 0,style:{paddingInlineStart:`${na+a*ia}px`},onClick:de=>{if(f){if(de.shiftKey||Ct(de)){Ce(),Oe(u,de);return}Ce(),Oe(u,de),Nn(s.path);return}bi(s.path,de)},onContextMenu:de=>{_n(de,s)},children:[n.jsx("span",{className:`file-tree-chevron${f?"":" is-hidden"}`,"aria-hidden":"true",children:p?"v":">"}),f?null:n.jsx("span",{className:"git-tree-file-icon","data-kind":Rt(s.name),"aria-hidden":"true",children:Mt(s.name)}),n.jsx("span",{className:"file-tree-label","data-status":ct??void 0,"data-has-changes":An||void 0,children:s.name}),!f&&ct?n.jsx("span",{className:"git-status-badge","data-status":ct,"aria-label":ct,children:ct}):null,f&&An?n.jsx("span",{className:"file-tree-dir-badge","aria-hidden":"true"}):null,x?n.jsx("span",{className:"file-tree-meta",children:r("common.loading")}):null]}),f&&p?n.jsx("div",{className:"file-tree-children",children:x&&!N.length?n.jsx("p",{className:"file-tree-empty",children:r("common.loading")}):fe.length?Yt(fe,a+1):n.jsx("p",{className:"file-tree-empty",children:r("conversation.filePanelEmptyDirectory")})}):null]},`${s.kind}-${s.path}`)})})}function ji(e){return n.jsx(n.Fragment,{children:e.map(a=>{const s=a.kind==="directory",u=vt.has(a.path),f=Ot===a.path;return n.jsx("div",{className:"file-tree-node",children:n.jsxs("button",{className:"file-tree-item is-search-result",type:"button","data-active":f,"data-selected":u,"data-kind":a.kind,onClick:p=>{vi(a,p)},onContextMenu:p=>{_n(p,a)},children:[n.jsx("span",{className:"file-tree-chevron is-hidden","aria-hidden":"true",children:">"}),s?null:n.jsx("span",{className:"git-tree-file-icon","data-kind":Rt(a.name),"aria-hidden":"true",children:Mt(a.name)}),n.jsxs("span",{className:"file-tree-label",children:[n.jsx("span",{className:"file-tree-name",children:a.name}),n.jsx("span",{className:"file-tree-path",children:a.path})]})]})},`search-${a.kind}-${a.path}`)})})}return n.jsx("section",{className:["conversation-panel","surface-card","file-panel",t].filter(Boolean).join(" "),"data-testid":"file-context-panel",children:l?n.jsxs(n.Fragment,{children:[n.jsx(Oi,{workspaceId:l,filePath:we,open:we!==null,onClose:()=>{xe.current+=1,Ye(null),ye(null)},onSaved:async e=>{await Pe(),await ce(e),_e(a=>a+1)},diffContent:oi}),o?null:n.jsx("div",{className:"file-panel-heading-row",children:n.jsx("h2",{className:"file-panel-heading",children:r("conversation.filePanelTitle")})}),h?null:n.jsxs("div",{className:"file-panel-tabs",role:"tablist","aria-label":r("conversation.filePanelTitle"),children:[n.jsx("button",{className:X==="workspace"?"file-panel-tab active":"file-panel-tab",type:"button",role:"tab","aria-selected":X==="workspace",onClick:()=>Ze("workspace"),children:r("conversation.filePanelWorkspaceTab")}),n.jsxs("button",{className:X==="session"?"file-panel-tab active":"file-panel-tab",type:"button",role:"tab","aria-selected":X==="session",onClick:()=>{it&&Ze("session")},disabled:!it,children:[r("conversation.filePanelSessionTab"),n.jsx("span",{className:"file-panel-tab-badge","aria-label":`${r("conversation.filePanelSessionTab")} ${rn}`,children:rn})]})]}),X==="workspace"?n.jsxs(n.Fragment,{children:[n.jsx("input",{ref:hn,"data-testid":"file-panel-upload-input",type:"file",hidden:!0,onChange:e=>void xi(e)}),pn?n.jsx("div",{className:"file-panel-toolbar file-panel-toolbar-mobile","aria-label":r("conversation.filePanelTitle"),children:n.jsxs("div",{className:"file-mobile-action-shell",ref:dn,children:[n.jsxs("button",{className:"secondary-button file-mobile-action-trigger",type:"button","aria-label":r("conversation.filePanelActionsMenu"),"aria-haspopup":"menu","aria-expanded":Qe,"data-active":Qe,onClick:()=>{Z(!1),L(e=>!e)},children:[n.jsx("span",{children:r("conversation.filePanelActionsMenu")}),n.jsx(Ba,{})]}),Qe?n.jsxs("div",{className:"file-mobile-action-menu",role:"menu","aria-label":r("conversation.filePanelActionsMenu"),children:[n.jsx("button",{className:"file-mobile-action-menu-item",type:"button",role:"menuitem",onClick:()=>q(()=>ue("copy")),disabled:!Ee,children:r("conversation.filePanelCopy")}),n.jsx("button",{className:"file-mobile-action-menu-item",type:"button",role:"menuitem",onClick:()=>q(()=>ue("cut")),disabled:!Ee,children:r("conversation.filePanelCut")}),n.jsx("button",{className:"file-mobile-action-menu-item",type:"button",role:"menuitem",onClick:()=>q(()=>ot()),disabled:!lt||m||v,children:r("conversation.filePanelPaste")}),n.jsx("button",{className:"file-mobile-action-menu-item",type:"button",role:"menuitem",onClick:()=>{L(!1),En()},children:Ge?r("conversation.filePanelHideSearch"):r("conversation.filePanelShowSearch")}),n.jsx("button",{className:"file-mobile-action-menu-item",type:"button",role:"menuitem",onClick:()=>{L(!1),Wt(e=>!e)},disabled:pt.length===0,children:J?r("conversation.filePanelShowAll"):r("conversation.filePanelFilterChanges")}),n.jsx("button",{className:"file-mobile-action-menu-item",type:"button",role:"menuitem",onClick:()=>q(kn),disabled:Re||m||ht,children:r("conversation.filePanelRefresh")}),n.jsx("button",{className:"file-mobile-action-menu-item",type:"button",role:"menuitem",onClick:()=>{L(!1),Rn()},disabled:!xn,children:r("conversation.filePanelCollapseCurrent")}),n.jsx("button",{className:"file-mobile-action-menu-item",type:"button",role:"menuitem",onClick:()=>{L(!1),Mn()},disabled:m||v,children:r("conversation.filePanelUpload")}),n.jsx("button",{className:"file-mobile-action-menu-item",type:"button",role:"menuitem",onClick:()=>q(Vt),disabled:!bn||v,children:r("conversation.filePanelDownload")}),n.jsx("button",{className:"file-mobile-action-menu-item",type:"button",role:"menuitem",onClick:()=>q(Xt),disabled:!yn||m||v,children:r("conversation.filePanelRenameMove")}),n.jsx("button",{className:"file-mobile-action-menu-item danger",type:"button",role:"menuitem",onClick:()=>q(qt),disabled:!vn||m||v,children:r("conversation.filePanelDelete")}),n.jsx("button",{className:"file-mobile-action-menu-item",type:"button",role:"menuitem",onClick:()=>q(()=>ze("create_file")),disabled:m||v,children:r("conversation.filePanelNewFile")}),n.jsx("button",{className:"file-mobile-action-menu-item",type:"button",role:"menuitem",onClick:()=>q(()=>ze("create_directory")),disabled:m||v,children:r("conversation.filePanelNewDirectory")}),n.jsx("button",{className:"file-mobile-action-menu-item",type:"button",role:"menuitem",onClick:()=>q(()=>Ue("absolute")),disabled:!Ht,children:r("conversation.filePanelCopyAbsolutePath")}),n.jsx("button",{className:"file-mobile-action-menu-item",type:"button",role:"menuitem",onClick:()=>q(()=>Ue("relative")),disabled:!Ht,children:r("conversation.filePanelCopyRelativePath")})]}):null]})}):n.jsxs("div",{className:"file-panel-toolbar","aria-label":r("conversation.filePanelTitle"),children:[n.jsx("button",{className:"file-toolbar-button",type:"button",title:r("conversation.filePanelCopy"),"aria-label":r("conversation.filePanelCopy"),onClick:()=>ue("copy"),disabled:!Ee,children:n.jsx(ka,{})}),n.jsx("button",{className:"file-toolbar-button",type:"button",title:r("conversation.filePanelCut"),"aria-label":r("conversation.filePanelCut"),onClick:()=>ue("cut"),disabled:!Ee,children:n.jsx(Ea,{})}),n.jsx("button",{className:"file-toolbar-button",type:"button",title:r("conversation.filePanelPaste"),"aria-label":r("conversation.filePanelPaste"),onClick:()=>void ot(),disabled:!lt||m||v,children:n.jsx(Ma,{})}),n.jsxs("div",{className:"file-toolbar-menu-shell",ref:fn,children:[n.jsx("button",{className:"file-toolbar-button",type:"button",title:r("conversation.filePanelCopyPath"),"aria-label":r("conversation.filePanelCopyPath"),"aria-haspopup":"menu","aria-expanded":Je,"data-active":Je,onClick:()=>{L(!1),Z(e=>!e)},disabled:!Ht,children:n.jsx(Da,{})}),Je?n.jsxs("div",{className:"file-toolbar-menu",role:"menu",children:[n.jsx("button",{className:"file-toolbar-menu-item",type:"button",role:"menuitem",onClick:()=>void Ue("absolute"),children:r("conversation.filePanelCopyAbsolutePath")}),n.jsx("button",{className:"file-toolbar-menu-item",type:"button",role:"menuitem",onClick:()=>void Ue("relative"),children:r("conversation.filePanelCopyRelativePath")})]}):null]}),n.jsx("button",{className:"file-toolbar-button",type:"button",title:r("conversation.filePanelCollapseCurrent"),"aria-label":r("conversation.filePanelCollapseCurrent"),onClick:Rn,disabled:!xn,children:n.jsx(wa,{})}),n.jsx("button",{className:"file-toolbar-button",type:"button",title:r("conversation.filePanelRefresh"),"aria-label":r("conversation.filePanelRefresh"),onClick:()=>void kn(),disabled:Re||m||ht,children:n.jsx(Na,{})}),n.jsx("button",{className:"file-toolbar-button",type:"button",title:r("conversation.filePanelSearchButton"),"aria-label":r("conversation.filePanelSearchButton"),"data-active":Ge,onClick:En,disabled:Re,children:n.jsx(qn,{})}),pt.length>0?n.jsx("button",{className:"file-toolbar-button",type:"button",title:J?r("conversation.filePanelShowAll"):r("conversation.filePanelFilterChanges"),"aria-label":J?r("conversation.filePanelShowAll"):r("conversation.filePanelFilterChanges"),"data-active":J,onClick:()=>Wt(e=>!e),children:n.jsx(Wa,{})}):null,n.jsx("button",{className:"file-toolbar-button",type:"button",title:r("conversation.filePanelUpload"),"aria-label":r("conversation.filePanelUpload"),onClick:Mn,disabled:m||v,children:n.jsx(_a,{})}),n.jsx("button",{className:"file-toolbar-button",type:"button",title:r("conversation.filePanelDownload"),"aria-label":r("conversation.filePanelDownload"),onClick:()=>void Vt(),disabled:!bn||v,children:n.jsx(Ta,{})}),n.jsx("button",{className:"file-toolbar-button",type:"button",title:r("conversation.filePanelRenameMove"),"aria-label":r("conversation.filePanelRenameMove"),onClick:()=>Xt(),disabled:!yn||m||v,children:n.jsx(La,{})}),n.jsx("button",{className:"file-toolbar-button danger",type:"button",title:r("conversation.filePanelDelete"),"aria-label":r("conversation.filePanelDelete"),onClick:()=>qt(),disabled:!vn||m||v,children:n.jsx(Fa,{})}),n.jsx("button",{className:"file-toolbar-button",type:"button",title:r("conversation.filePanelNewFile"),"aria-label":r("conversation.filePanelNewFile"),onClick:()=>void ze("create_file"),disabled:m||v,children:n.jsx(Ra,{})}),n.jsx("button",{className:"file-toolbar-button",type:"button",title:r("conversation.filePanelNewDirectory"),"aria-label":r("conversation.filePanelNewDirectory"),onClick:()=>void ze("create_directory"),disabled:m||v,children:n.jsx(Aa,{})})]}),ae&&typeof document<"u"?ki.createPortal(n.jsx("div",{className:"file-web-context-menu",ref:$t,role:"menu","aria-label":r("conversation.filePanelActionsMenu"),style:{left:`${(ve==null?void 0:ve.left)??Math.max(8,ae.positionX)}px`,top:`${(ve==null?void 0:ve.top)??Math.max(8,ae.positionY)}px`,maxHeight:ve?`${ve.maxHeight}px`:void 0},children:ae.items.map(e=>n.jsx("button",{className:["file-web-context-menu-item",e.label===r("conversation.filePanelDelete")?"danger":""].filter(Boolean).join(" "),type:"button",role:"menuitem",disabled:e.disabled,onClick:()=>{O(null),e.onSelect()},children:e.label},e.id))}),document.body):null,gn?n.jsx("p",{className:"file-panel-clipboard-status","data-mode":P==null?void 0:P.mode,children:gn}):null,Ge?n.jsxs("form",{className:"file-toolbar-search",onSubmit:e=>void yi(e),children:[n.jsx("input",{value:A,onChange:e=>qe(e.target.value),placeholder:r("conversation.filePanelSearchPlaceholder")}),pn?n.jsx("button",{className:"secondary-button file-mobile-search-submit",type:"submit","aria-label":r("conversation.filePanelSearchButton"),disabled:ht,children:r("conversation.filePanelSearchButton")}):n.jsx("button",{className:"file-toolbar-button",type:"submit",title:r("conversation.filePanelSearchButton"),"aria-label":r("conversation.filePanelSearchButton"),disabled:ht,children:n.jsx(qn,{})})]}):null,n.jsx("div",{ref:ci,className:"file-tree","data-search-mode":oe,"data-scrollbar-autohide":"true",children:Re&&Be.length===0?n.jsx("p",{className:"file-tree-status status-text",children:r("common.loading")}):oe?ke!=null&&ke.length?ji(ke):n.jsx("p",{className:"file-tree-status status-text",children:r("conversation.filePanelSearchEmpty")}):J?bt.length?Yt(bt,0):n.jsx("p",{className:"file-tree-status status-text",children:r("conversation.filePanelNoChanges")}):Be.length?Yt(Be,0):n.jsx("p",{className:"file-tree-status status-text",children:r("conversation.filePanelEmptyDirectory")})}),n.jsx(Ln,{open:w!==null,title:(H==null?void 0:H.title)??"",description:H==null?void 0:H.description,onClose:Gt,children:n.jsxs("form",{className:"workbench-rename-form",onSubmit:e=>void gi(e),children:[n.jsx(Ri,{label:r("conversation.filePanelPathFieldLabel"),htmlFor:un,description:(w==null?void 0:w.mode)==="rename"?w.target.path:(w==null?void 0:w.baseDirectory)||void 0,children:n.jsx("input",{id:un,type:"text",value:Bt??"",placeholder:r("conversation.filePanelPathFieldPlaceholder"),autoFocus:!0,onChange:e=>Ae(e.target.value)})}),n.jsxs(_i,{children:[n.jsx("button",{type:"button",className:"secondary-button",disabled:m,onClick:Gt,children:r("common.cancel")}),n.jsx("button",{type:"submit",className:"primary-button",disabled:m||!(Bt??"").trim(),children:m?(H==null?void 0:H.pendingLabel)??r("common.loading"):(H==null?void 0:H.submitLabel)??r("common.save")})]})]})}),n.jsxs(Ln,{open:B!==null,title:r("conversation.filePanelDeleteConfirmTitle"),description:r("conversation.filePanelDeleteConfirmDescription"),onClose:()=>{m||Fe(null)},children:[n.jsx("p",{className:"workbench-section-empty",children:B!=null&&B.length?B.length===1?((Fn=B[0])==null?void 0:Fn.kind)==="directory"?r("conversation.filePanelDeleteDirectoryConfirm",{path:B[0].path}):r("conversation.filePanelDeleteFileConfirm",{path:B[0].path}):r("conversation.filePanelDeleteSelectionConfirm",{count:B.length}):""}),n.jsxs("div",{className:"workbench-modal-actions",children:[n.jsx("button",{type:"button",className:"secondary-button",disabled:m,onClick:()=>Fe(null),children:r("common.cancel")}),n.jsx("button",{type:"button",className:"secondary-button workbench-danger-button",disabled:m,onClick:()=>{Pi()},children:m?r("conversation.filePanelDeleting"):r("conversation.filePanelDelete")})]})]})]}):it&&i?n.jsx(Yi,{sessionId:i,workspaceId:l,showSystemFiles:I,selectedPath:ge,refreshVersion:sn,onCountChange:At,onSelectFile:ce,onOpenFile:He}):n.jsx("section",{className:"file-panel-section",children:n.jsx("p",{className:"status-text",children:r("conversation.filePanelSessionNoSession")})})]}):n.jsx("section",{className:"file-panel-section",children:n.jsx("p",{className:"status-text",children:r("conversation.filePanelNoWorkspace")})})})}function he(t){return t.includes("/")?t.split("/").slice(0,-1).join("/"):g}function ut(t,i=!1){const l=t.split("/").filter(Boolean),o=i?l.length:l.length-1,h=[];for(let d=0;d<o;d+=1)h.push(l.slice(0,d+1).join("/"));return h}function Hn(t,i){return t||((i==null?void 0:i.kind)==="directory"?i.path:i!=null&&i.path?he(i.path):g)}function zn(t,i){return t?`${t}/${i}`:i}function aa(t){var i;return((i=t.split(/[/\\]/).pop())==null?void 0:i.trim())??""}function z(t,i){return{path:t,kind:i}}function Un(t){return t[t.length-1]??null}function la(t,i){return t.findIndex(o=>o.path===i.path)>=0?t.filter(o=>o.path!==i.path):[...t,i]}function sa(t,i,l){const o=t.findIndex(y=>y.path===l.path);if(o<0)return[l];const h=i?t.findIndex(y=>y.path===i):o;if(h<0)return[l];const d=Math.min(h,o),b=Math.max(h,o);return t.slice(d,b+1)}function Ct(t){return!!(t!=null&&t.ctrlKey||t!=null&&t.metaKey)}function ra(t){return t.ctrlKey||t.metaKey}function oa(t){if(!(t instanceof HTMLElement))return!1;const i=t.tagName.toLowerCase();return i==="input"||i==="textarea"||i==="select"||t.isContentEditable}function jt(t){const i=[...new Map(t.map(o=>[o.path,o])).values()].sort((o,h)=>o.path.localeCompare(h.path)),l=[];for(const o of i)l.some(h=>h.kind==="directory"&&_t(h.path,o.path))||l.push(o);return l}function ca(t,i){return(t==null?void 0:t.kind)==="directory"?t.path:t!=null&&t.path?he(t.path):i}function ua(t,i){let l=t;for(;l&&i.some(o=>o.kind==="directory"&&_t(o.path,l));)l=he(l);return l}function ni(t,i,l,o,h,d){const b=[];for(const y of t){if(b.push(z(y.path,y.kind)),y.kind!=="directory"||!l.includes(y.path))continue;const C=i[y.path]??[],T=o?tn(C,i,h,d):C;b.push(...ni(T,i,l,o,h,d))}return b}function fa(t,i,l){const o=Math.max(0,l.width),h=Math.max(0,l.height),d=Math.max(0,h-ee*2),b=Math.max(0,o-ee*2),y=Math.min(Math.max(i.width,0),b),C=Math.max(0,h-t.y-Pt-ee),T=Math.max(0,t.y-Pt-ee),M=C<i.height&&T>C,me=Qt(Math.max(M?T:C,Ii),0,d),U=Math.min(Math.max(i.height,0),me),pe=M?t.y-Pt-U:t.y+Pt,be=Math.max(ee,h-ee-U),V=Math.max(ee,o-ee-y);return{top:Qt(pe,ee,be),left:Qt(t.x,ee,V),maxHeight:Math.max(0,me)}}function Qt(t,i,l){return!Number.isFinite(t)||l<i?i:Math.min(Math.max(t,i),l)}function Ke(t,i="posix"){return t?ii(t,i):"."}function da(t,i,l){const o=ii(t,l),h=Ke(i,l).replace(/^\.[/\\]?/,"");if(!h)return o;const d=ai(l),b=h.replace(/^[/\\]+/,"");return b?o.endsWith("/")||o.endsWith("\\")?`${o}${b}`:`${o}${d}${b}`:o}function ha(t){return/^[a-zA-Z]:[\\/]/.test(t)||t.includes("\\")?"windows":"posix"}function ii(t,i){return t&&(ai(i)==="\\"?t.replace(/\//g,"\\"):t.replace(/\\/g,"/"))}function ai(t){return t==="windows"?"\\":"/"}function _t(t,i){return i===t||i.startsWith(`${t}/`)}function li(t,i,l){return t===i?l:t.startsWith(`${i}/`)?`${l}${t.slice(i.length)}`:t}function ma(t,i,l){return t.map(o=>({...o,path:li(o.path,i,l)}))}function pa(t){return t.mode==="create_file"?{title:r("conversation.filePanelNewFile"),description:r("conversation.filePanelCreateFileDescription"),submitLabel:r("conversation.filePanelCreateFileSubmit"),pendingLabel:r("conversation.filePanelCreatingFile")}:t.mode==="create_directory"?{title:r("conversation.filePanelNewDirectory"),description:r("conversation.filePanelCreateDirectoryDescription"),submitLabel:r("conversation.filePanelCreateDirectorySubmit"),pendingLabel:r("conversation.filePanelCreatingDirectory")}:{title:r("conversation.filePanelRenameMove"),description:r("conversation.filePanelRenameDescription"),submitLabel:r("conversation.filePanelRenameSubmit"),pendingLabel:r("conversation.filePanelRenaming")}}async function ba(t){const i=await t.arrayBuffer(),l=new Uint8Array(i),o=32768;let h="";for(let d=0;d<l.length;d+=o){const b=l.subarray(d,d+o);h+=String.fromCharCode(...b)}return btoa(h)}function va(t){const i=atob(t),l=new Uint8Array(i.length);for(let o=0;o<i.length;o+=1)l[o]=i.charCodeAt(o);return l.buffer.slice(l.byteOffset,l.byteOffset+l.byteLength)}function ya(t,i){if(typeof document>"u")throw new Error(r("conversation.filePanelDownloadFailed"));const l=window.URL.createObjectURL(i),o=document.createElement("a");o.href=l,o.download=t,document.body.append(o),o.click(),o.remove(),window.URL.revokeObjectURL(l)}async function xa(t,i){var l;if(!(i.isDesktop&&(await i.bridge.writeClipboardText(t)).ok)){if(typeof navigator<"u"&&((l=navigator.clipboard)!=null&&l.writeText))try{await navigator.clipboard.writeText(t);return}catch{}if(!ga(t))throw new Error(r("conversation.filePanelCopyPathFailed"))}}function ga(t){if(typeof document>"u"||typeof document.execCommand!="function")return!1;const i=document.createElement("textarea");i.value=t,i.setAttribute("readonly","true"),i.style.position="fixed",i.style.top="-9999px",i.style.left="-9999px",i.style.opacity="0",document.body.appendChild(i),i.focus(),i.select();try{return document.execCommand("copy")}catch{return!1}finally{document.body.removeChild(i)}}function Pa(t,i){return t&&ut(t,!0).every(h=>h in i)?t:g}function Vn(t,i){if(!i)return[];const l=ut(i,!0);return t.filter(o=>l.includes(o))}function St(t,i,l){const o=ln(i,l);return Object.entries(t).reduce((h,[d,b])=>(o.has(d)&&(h[d]=b),h),{})}function Ca(t,i,l){const h=[...ln(i,l)].filter(d=>d===g||d in t);return h.length?h:[g]}function ln(t,i){const l=new Set([g]),o=si(i,ut(t,!0));for(const h of o){l.add(h);for(const d of ut(h,!0))l.add(d)}return l}function ja(t,i){const l=Object.keys(t),o=Object.keys(i);return l.length!==o.length?!1:l.every(h=>t[h]===i[h])}function Et(t,i){return t.includes(i)?t:[...t,i]}function si(t,i){return i.reduce((l,o)=>Et(l,o),t)}function Kn(t){return`file-panel.workspace-tree.${t}`}function Sa(t,i){return`file-panel.session-change-count.${t}.${i}`}function Gn(t,i){return Object.fromEntries(Object.keys(i).map(l=>[l,t[l]??null]))}function It(t,i){return[...ln(i,t)]}function te(t,i){return t instanceof Yn?t.message:i}function Xn(t){return t instanceof Error&&(t.message.startsWith("FILE_TREE_SNAPSHOT_TIMEOUT:")||t.message.startsWith("FILE_TREE_ABORTED:"))}function wa(){return n.jsx("svg",{viewBox:"0 0 16 16","aria-hidden":"true",children:n.jsx("path",{d:"M2.5 4.5h11v2h-11zM2.5 7.5h7v2h-7zM2.5 10.5h4v2h-4z",fill:"currentColor"})})}function Na(){return n.jsx("svg",{viewBox:"0 0 16 16","aria-hidden":"true",children:n.jsx("path",{d:"M12.8 5.2A5.5 5.5 0 1 0 13.5 8h-1.8A3.7 3.7 0 1 1 10.6 5l-1.4 1.4h4V2l-1.4 1.4z",fill:"currentColor"})})}function qn(){return n.jsx("svg",{viewBox:"0 0 16 16","aria-hidden":"true",children:n.jsx("path",{d:"M11.2 10.1l3 3-1.1 1.1-3-3a5 5 0 1 1 1.1-1.1zM6.8 10.3a3.5 3.5 0 1 0 0-7 3.5 3.5 0 0 0 0 7z",fill:"currentColor"})})}function Da(){return n.jsxs("svg",{viewBox:"0 0 16 16","aria-hidden":"true",children:[n.jsx("path",{d:"M3.5 4.3h5.2v1.4H4.9v5.4H3.5zm3.8-2.1h5.2v9.5H7.3z",fill:"none",stroke:"currentColor",strokeWidth:"1.2"}),n.jsx("path",{d:"M5.7 10.8h4.5",fill:"none",stroke:"currentColor",strokeWidth:"1.2"})]})}function ka(){return n.jsxs("svg",{viewBox:"0 0 16 16","aria-hidden":"true",children:[n.jsx("path",{d:"M5 2.5h7.5v9H5z",fill:"none",stroke:"currentColor",strokeWidth:"1.2"}),n.jsx("path",{d:"M3.5 5H2.4V13.5H10V12.4",fill:"none",stroke:"currentColor",strokeWidth:"1.2"})]})}function Ea(){return n.jsx("svg",{viewBox:"0 0 16 16","aria-hidden":"true",children:n.jsx("path",{d:"M4.2 4.2a1.4 1.4 0 1 1 0 2.8 1.4 1.4 0 0 1 0-2.8zm0 5.4a1.4 1.4 0 1 1 0 2.8 1.4 1.4 0 0 1 0-2.8zm1-3.2 6.6 5.6M5.2 9.6l6.6-5.6",fill:"none",stroke:"currentColor",strokeWidth:"1.2",strokeLinecap:"round"})})}function Ma(){return n.jsxs("svg",{viewBox:"0 0 16 16","aria-hidden":"true",children:[n.jsx("path",{d:"M4 3.5h8v10H4zM6 2.2h4v2H6z",fill:"none",stroke:"currentColor",strokeWidth:"1.2"}),n.jsx("path",{d:"M6 7.2h4M6 9.6h4",fill:"none",stroke:"currentColor",strokeWidth:"1.2"})]})}function Ra(){return n.jsxs("svg",{viewBox:"0 0 16 16","aria-hidden":"true",children:[n.jsx("path",{d:"M4 1.5h5l3 3v10H4z",fill:"none",stroke:"currentColor",strokeWidth:"1.2"}),n.jsx("path",{d:"M9 1.5v3h3",fill:"none",stroke:"currentColor",strokeWidth:"1.2"}),n.jsx("path",{d:"M8 6.5v5M5.5 9h5",fill:"none",stroke:"currentColor",strokeWidth:"1.2"})]})}function _a(){return n.jsxs("svg",{viewBox:"0 0 16 16","aria-hidden":"true",children:[n.jsx("path",{d:"M3 11.5v2h10v-2",fill:"none",stroke:"currentColor",strokeWidth:"1.2"}),n.jsx("path",{d:"M8 2.5v8",fill:"none",stroke:"currentColor",strokeWidth:"1.2"}),n.jsx("path",{d:"m5.5 5 2.5-2.5L10.5 5",fill:"none",stroke:"currentColor",strokeWidth:"1.2",strokeLinecap:"round",strokeLinejoin:"round"})]})}function Ta(){return n.jsxs("svg",{viewBox:"0 0 16 16","aria-hidden":"true",children:[n.jsx("path",{d:"M3 11.5v2h10v-2",fill:"none",stroke:"currentColor",strokeWidth:"1.2"}),n.jsx("path",{d:"M8 2.5v8",fill:"none",stroke:"currentColor",strokeWidth:"1.2"}),n.jsx("path",{d:"m5.5 8.5 2.5 2.5 2.5-2.5",fill:"none",stroke:"currentColor",strokeWidth:"1.2",strokeLinecap:"round",strokeLinejoin:"round"})]})}function Fa(){return n.jsx("svg",{viewBox:"0 0 16 16","aria-hidden":"true",children:n.jsx("path",{d:"M3.5 4.5h9M6.2 2.5h3.6l.6 1.4H13v1.2H3V3.9h2.6zM5.2 5.7v6.1m2.8-6.1v6.1m2.8-6.1v6.1M4.4 13.5h7.2",fill:"none",stroke:"currentColor",strokeWidth:"1.2",strokeLinecap:"round",strokeLinejoin:"round"})})}function Aa(){return n.jsxs("svg",{viewBox:"0 0 16 16","aria-hidden":"true",children:[n.jsx("path",{d:"M1.8 4.5h4l1.2 1.3h7.2v6.7H1.8z",fill:"none",stroke:"currentColor",strokeWidth:"1.2"}),n.jsx("path",{d:"M8.5 7.2v4M6.5 9.2h4",fill:"none",stroke:"currentColor",strokeWidth:"1.2"})]})}function La(){return n.jsx("svg",{viewBox:"0 0 16 16","aria-hidden":"true",children:n.jsx("path",{d:"M3.2 11.9h2.2l5.9-5.9-2.2-2.2-5.9 5.9zM8.3 3.8l2.2 2.2M2.8 13.2h10.4",fill:"none",stroke:"currentColor",strokeWidth:"1.2",strokeLinecap:"round",strokeLinejoin:"round"})})}function Ba(){return n.jsx("svg",{viewBox:"0 0 16 16","aria-hidden":"true",children:n.jsx("path",{d:"m4 6 4 4 4-4",fill:"none",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round"})})}function Wa(){return n.jsx("svg",{viewBox:"0 0 16 16","aria-hidden":"true",children:n.jsx("path",{d:"M1.5 2h13l-5 6v5l-3 1.5V8z",fill:"none",stroke:"currentColor",strokeWidth:"1.2",strokeLinejoin:"round"})})}function tn(t,i,l,o){const h=[];for(const d of t){const b=d.path.replace(/\\/g,"/");d.kind==="file"?l.has(b)&&h.push(d):ri(b,i,l,o)&&h.push(d)}return h}function ri(t,i,l,o,h){const d=h??new Set;if(d.has(t))return!1;d.add(t);const b=i[t];if(!b)return o.has(t);for(const y of b){const C=y.path.replace(/\\/g,"/");if(y.kind==="file"){if(l.has(C))return!0}else if(ri(C,i,l,o,d))return!0}return!1}export{qa as FileContextPanel};
1
+ import{b as c,j as n,t as r,A as Yn}from"./index-NGxWr8Ix.js";import{f as Zn,e as Di,g as Ei}from"./App-tXOqoHNl.js";import{aq as ki,u as Mi,h as Ri,v as _i}from"./model-switch-api-CPtou49j.js";import{bl as Ti,bm as Jn,b as en,w as wt,bn as Fi,u as Ai,a7 as Me,bo as Li,bp as yt,bq as Ve,br as Bi,bs as Wi,bt as $i}from"./WorkbenchLayout-DScHaza9.js";import{W as Ln}from"./WorkbenchModal-BWXYSXmC.js";import{r as Mt,a as Rt,F as Oi}from"./file-tree-icon-lfU9Ag77.js";import"./window-BVUB8gMK.js";import"./event-DvH9tcej.js";import"./relay-entry-BwE5nw0l.js";const Hi=new Set([".ds_store","thumbs.db","ehthumbs.db","desktop.ini",".spotlight-v100",".trashes",".fseventsd","__macosx","$recycle.bin","system volume information",".apdisk",".appledouble",".temporaryitems"]),zi=["._"];function xt(t){return t.split(/[/\\]/).filter(Boolean).pop()??t}function Ui(t){const i=t.trim().toLowerCase();return i?Hi.has(i)||zi.some(l=>i.startsWith(l)):!1}function nn(t,i,l){return l?[...t]:t.filter(o=>!Ui(i(o)))}function Nt(t,i){return nn(t,l=>l.name,i)}function Vi(t,i){return i?t:Object.entries(t).reduce((l,[o,h])=>(l[o]=Nt(h,!1),l),{})}async function Zt(t,i){const[l,o]=await Promise.all([Ti(i),ki(t)]);return Ki(l.changes,o.items)}function Ki(t,i){const l=new Set(i.map(o=>Et(o.path)));return t.filter(o=>l.has(Et(o.path))||o.oldPath!==null&&l.has(Et(o.oldPath)))}function Gi(t){const i=Bn("","");for(const l of t){const o=Et(l.path),h=o.split("/").filter(Boolean);let d=i;h.forEach((b,y)=>{const C=h.slice(0,y+1).join("/");if(y===h.length-1){d.children.set(`file:${C}`,{kind:"file",name:b,path:o,change:l});return}const T=`directory:${C}`,M=d.children.get(T);if(M&&M.kind==="directory"){d=M;return}const Y=Bn(b,C);d.children.set(T,Y),d=Y})}return ei(In([...i.children.values()]))}function Qn(t,i){const l=t.oldPath?`${t.oldPath} -> ${t.path}`:t.path;return an(t)?`${l} ${i}`:l}function an(t){return t.status==="D"||t.stagedStatus==="D"||t.worktreeStatus==="D"}function Dt(t){return t.split("/").filter(Boolean).pop()??t}function Et(t){return t.replace(/\\/g,"/").replace(/^\.\//,"").trim()}function Bn(t,i){return{kind:"directory",name:t,path:i,children:new Map}}function In(t){return[...t].sort((i,l)=>i.kind!==l.kind?i.kind==="directory"?-1:1:i.name.localeCompare(l.name,"zh-CN")).map(i=>i.kind==="directory"?{kind:"directory",name:i.name,path:i.path,children:In([...i.children.values()])}:i)}function ei(t){return t.map(i=>{var b;if(i.kind!=="directory")return i;const l=ei(i.children);let o=i.name,h=i.path,d=l;for(;d.length===1&&((b=d[0])==null?void 0:b.kind)==="directory";){const y=d[0];o=`${o}/${y.name}`,h=y.path,d=y.children}return{kind:"directory",name:o,path:h,children:d}})}const Xi=450,qi=60*1e3,Wn=20,$n=16;function Yi({sessionId:t,workspaceId:i,showSystemFiles:l,selectedPath:o,refreshVersion:h,onCountChange:d,onSelectFile:b,onOpenFile:y}){const[C,T]=c.useState("tree"),[M,Y]=c.useState([]),[me,U]=c.useState(!0),[pe,be]=c.useState(!1),[V,ft]=c.useState([]),E=c.useRef(null),Tt=Jn(),{showToast:je}=Zn();c.useEffect(()=>{const m=en(gt(i,t),qi);T("tree"),Y(m??[]),U(m===null),be(!1),ft([]),E.current=null},[t,i]),c.useEffect(()=>{let m=!1;async function j(){U(!0);try{const v=await Zt(t,i);m||(Y(v),wt(gt(i,t),v))}catch(v){m||je({title:Jt(v,r("conversation.filePanelSessionLoadFailed")),tone:"error"})}finally{m||U(!1)}}return j(),()=>{m=!0}},[h,t,je,i]);async function Se(){U(!0);try{const m=await Zt(t,i);Y(m),wt(gt(i,t),m)}catch(m){je({title:Jt(m,r("conversation.filePanelSessionLoadFailed")),tone:"error"})}finally{U(!1)}}async function D(){if(R.length!==0){be(!0);try{await Fi(i,R.map(j=>j.path));const m=await Zt(t,i);Y(m),wt(gt(i,t),m),je({title:r("conversation.filePanelSessionStageSuccess"),tone:"success"})}catch(m){je({title:Jt(m,r("git.stageFailed")),tone:"error"})}finally{be(!1)}}}function F(m){ft(j=>j.includes(m)?j.filter(v=>v!==m):[...j,m])}function K(m){const j=Date.now(),v=E.current;return E.current={filePath:m,timestamp:j},(v==null?void 0:v.filePath)===m&&j-v.timestamp<=Xi}async function $(m,j){if(j&&K(m)){await y(m),E.current=null;return}j||(E.current=null),await b(m)}const ne=c.useMemo(()=>nn(M,m=>Dt(m.path),l),[M,l]),R=ne.filter(m=>!m.staged),Re=Gi(ne),ie=new Set(V);return c.useEffect(()=>{d==null||d(ne.length)},[d,ne.length]),n.jsxs(n.Fragment,{children:[n.jsxs("div",{className:"file-panel-session-toolbar",children:[n.jsxs("div",{className:"file-panel-view-modes",role:"tablist","aria-label":r("conversation.filePanelSessionViewLabel"),children:[n.jsx("button",{className:C==="tree"?"file-panel-view-button active":"file-panel-view-button",type:"button",role:"tab","aria-selected":C==="tree",onClick:()=>T("tree"),children:r("conversation.filePanelSessionTreeView")}),n.jsx("button",{className:C==="list"?"file-panel-view-button active":"file-panel-view-button",type:"button",role:"tab","aria-selected":C==="list",onClick:()=>T("list"),children:r("conversation.filePanelSessionListView")})]}),n.jsxs("div",{className:"file-panel-session-actions",children:[n.jsx("button",{className:"secondary-button",type:"button",onClick:()=>void Se(),disabled:me||pe,children:r("conversation.filePanelRefresh")}),n.jsx("button",{className:"primary-button",type:"button",onClick:()=>void D(),disabled:pe||R.length===0,children:r("conversation.filePanelSessionStageAll")})]})]}),n.jsxs("div",{className:"file-panel-session-summary",children:[n.jsx("span",{children:`${r("conversation.filePanelSessionSummary")} ${ne.length}`}),n.jsx("span",{children:`${r("conversation.filePanelSessionUnstagedSummary")} ${R.length}`})]}),n.jsx("div",{ref:Tt,className:"file-tree","data-scrollbar-autohide":"true",children:me?n.jsx("p",{className:"file-tree-status status-text",children:r("conversation.filePanelSessionLoading")}):ne.length===0?n.jsx("p",{className:"file-tree-status status-text",children:r("conversation.filePanelSessionEmpty")}):C==="tree"?ti({nodes:Re,depth:0,collapsedPathSet:ie,selectedPath:o,onToggleTreePath:F,onFileClick:$}):Zi({items:ne,selectedPath:o,onFileClick:$})})]})}function ti({nodes:t,depth:i,collapsedPathSet:l,selectedPath:o,onToggleTreePath:h,onFileClick:d}){return t.map(b=>{if(b.kind==="directory"){const y=!l.has(b.path);return n.jsxs("div",{className:"file-tree-node",children:[n.jsxs("button",{className:"file-tree-item",type:"button","data-kind":"directory","aria-expanded":y,style:{paddingInlineStart:`${Wn+i*$n}px`},onClick:()=>h(b.path),children:[n.jsx("span",{className:"file-tree-chevron","aria-hidden":"true",children:y?"v":">"}),n.jsx("span",{className:"file-tree-label",children:b.name})]}),y?n.jsx("div",{className:"file-tree-children",children:ti({nodes:b.children,depth:i+1,collapsedPathSet:l,selectedPath:o,onToggleTreePath:h,onFileClick:d})}):null]},`session-directory:${b.path}`)}return n.jsx("div",{className:"file-tree-node",children:n.jsxs("button",{className:"file-tree-item is-session-change",type:"button","data-active":o===b.change.path,"data-kind":"file",style:{paddingInlineStart:`${Wn+i*$n}px`},onClick:()=>void d(b.change.path,!an(b.change)),children:[n.jsx("span",{className:"file-tree-chevron is-hidden","aria-hidden":"true",children:">"}),n.jsx("span",{className:"git-tree-file-icon","data-kind":Rt(b.name),"aria-hidden":"true",children:Mt(b.name)}),n.jsxs("span",{className:"file-tree-label",children:[n.jsx("span",{className:"file-tree-name",children:b.name}),n.jsx("span",{className:"file-tree-path",children:Qn(b.change,r("conversation.filePanelSessionDeleted"))})]}),n.jsxs("span",{className:"file-session-item-meta",children:[n.jsx("span",{className:"file-session-badge","data-status":b.change.status,children:b.change.status}),n.jsx("span",{className:"file-session-badge subtle",children:b.change.staged?r("git.stagedLabel"):r("git.workingTreeLabel")})]})]})},`session-file:${b.path}`)})}function Zi({items:t,selectedPath:i,onFileClick:l}){return t.map(o=>n.jsx("div",{className:"file-session-list-item",children:n.jsxs("button",{className:"file-session-list-button",type:"button","data-active":i===o.path,onClick:()=>void l(o.path,!an(o)),children:[n.jsx("span",{className:"git-tree-file-icon","data-kind":Rt(Dt(o.path)),"aria-hidden":"true",children:Mt(Dt(o.path))}),n.jsxs("span",{className:"file-tree-label",children:[n.jsx("span",{className:"file-tree-name",children:Dt(o.path)}),n.jsx("span",{className:"file-tree-path",children:Qn(o,r("conversation.filePanelSessionDeleted"))})]}),n.jsxs("span",{className:"file-session-item-meta",children:[n.jsx("span",{className:"file-session-badge","data-status":o.status,children:o.status}),n.jsx("span",{className:"file-session-badge subtle",children:o.staged?r("git.stagedLabel"):r("git.workingTreeLabel")})]})]})},`session-list:${o.path}`))}function gt(t,i){return`file-panel.session-changes.${t}.${i}`}function Jt(t,i){return t instanceof Yn?t.message:typeof t=="object"&&t&&"message"in t?String(t.message??i):i}const g="",Ji=450,ee=8,Pt=4,Qi=176,Ii=120,ea=300*1e3,ta=60*1e3,On=1600,na=20,ia=16;function qa({className:t,sessionId:i,workspaceId:l,hideHeading:o=!1,hideTabs:h=!1,externalRevealRequest:d=null,externalWindowMode:b=!1,workbenchShellOverrides:y}){var Tn,Fn;const C=Ai(),{navigationGroups:T,subscribeFileTree:M,requestFileTreeRefresh:Y,addFileTreeSnapshotListener:me,subscribeGitSnapshot:U,requestGitRefresh:pe,addGitSnapshotListener:be}={...C,...y},[V,ft]=c.useState({}),[E,Tt]=c.useState([]),[je,Se]=c.useState([]),[D,F]=c.useState(g),[K,$]=c.useState([]),[ne,R]=c.useState(null),[Re,ie]=c.useState(!1),[m,j]=c.useState(!1),[v,dt]=c.useState(!1),[Ge,Xe]=c.useState(!1),[A,qe]=c.useState(""),[Ft,G]=c.useState(null),[ht,mt]=c.useState(!1),[we,Ye]=c.useState(null),[X,Ze]=c.useState("workspace"),[sn,_e]=c.useState(0),[rn,At]=c.useState(0),[Je,Z]=c.useState(!1),[Qe,L]=c.useState(!1),[ae,O]=c.useState(null),[ve,Te]=c.useState(null),[B,Fe]=c.useState(null),[P,Lt]=c.useState(null),[w,Ie]=c.useState(null),[Bt,Ae]=c.useState(""),[on,cn]=c.useState([]),[J,Wt]=c.useState(!1),[oi,ye]=c.useState(null),un=c.useId(),le=c.useRef({}),se=c.useRef({}),_=c.useRef([]),Q=c.useRef(g),et=c.useRef(!1),tt=c.useRef(null),ci=Jn(),fn=c.useRef(null),dn=c.useRef(null),$t=c.useRef(null),hn=c.useRef(null),mn=c.useRef(null),xe=c.useRef(0),re=c.useRef(new Map),{showToast:S}=Zn(),nt=Di(),I=Mi(e=>e.showSystemFiles),it=!!(i!=null&&i.trim()),pn=o&&nt.isMobile;c.useEffect(()=>{Me("file_panel.props",{sessionId:i,workspaceId:l,externalWindowMode:b})},[b,i,l]),c.useEffect(()=>{Q.current=D},[D]);function Ne(e){ft(a=>{const s=typeof e=="function"?e(a):e;return le.current=s,s})}function Le(e){Tt(a=>{const s=typeof e=="function"?e(a):e;return _.current=s,s})}c.useEffect(()=>{var f,p;if(Ut(),!l){Ut(),et.current=!1,le.current={},se.current={},_.current=[],Q.current=g,Ne({}),Le([]),Se([]),F(g),Xe(!1),qe(""),G(null),mt(!1),ie(!1),Wt(!1),ye(null),$([]),R(null),O(null),Te(null),Fe(null),Ie(null),Ae("");return}et.current=!0;const e=en(Kn(l),ea);Me("file_panel.workspace_snapshot",{workspaceId:l,cached:!!e,cachedRootItems:((p=(f=e==null?void 0:e.treeCache)==null?void 0:f[g])==null?void 0:p.length)??0,cachedDirectoryCount:Object.keys((e==null?void 0:e.treeCache)??{}).length});const a=Pa((e==null?void 0:e.activeDirectoryPath)??g,(e==null?void 0:e.treeCache)??{}),s=Vn((e==null?void 0:e.expandedDirectories)??[],a),u=St((e==null?void 0:e.treeCache)??{},a,s);le.current=u,se.current=Gn((e==null?void 0:e.treeRevisionByPath)??{},u),_.current=s,Q.current=a,Ne(u),Le(s),Se([]),F(a),ie(!1),j(!1),Xe(!1),qe(""),G(null),mt(!1),queueMicrotask(()=>{et.current=!1})},[l]),c.useEffect(()=>{if(!d||d.workspaceId!==l)return;const e=()=>{if(mn.current===d.requestId)return;mn.current=d.requestId,Ze("workspace"),(d.openViewer?He(d.filePath):ce(d.filePath)).catch(s=>{S({title:te(s,r("conversation.filePanelOpenFailed")),tone:"error"})})};if(et.current){queueMicrotask(e);return}e()},[d,He,ce,S,l]),c.useEffect(()=>{if(l)return me(e=>{e.workspaceId===l&&(se.current={...se.current,[e.path]:typeof e.revision=="string"?e.revision:null},Ne(a=>({...a,[e.path]:e.items})),e.path===g&&ie(!1),Se(a=>a.filter(s=>s!==e.path)),di(e.path,e.items))})},[me,l]),c.useEffect(()=>()=>{Ut()},[]),c.useEffect(()=>{l&&M(l,It(_.current,Q.current),{knownRevisionByPath:se.current})},[D,E,M,l]),c.useEffect(()=>{$([]),R(null),Ye(null),ye(null),_e(0),Z(!1),L(!1),O(null),Te(null),Fe(null),Ie(null),Ae(""),tt.current=null,xe.current+=1},[i]),c.useEffect(()=>{!it&&X==="session"&&Ze("workspace")},[X,it]),c.useEffect(()=>{h&&X!=="workspace"&&Ze("workspace")},[X,h]),c.useEffect(()=>{if(!Je&&!Qe&&!ae)return;function e(s){var x,N,fe;if(!(s.target instanceof Node))return;const u=((x=fn.current)==null?void 0:x.contains(s.target))??!1,f=((N=dn.current)==null?void 0:N.contains(s.target))??!1,p=((fe=$t.current)==null?void 0:fe.contains(s.target))??!1;!u&&!f&&!p&&(Z(!1),L(!1),O(null),Te(null))}function a(s){s.key==="Escape"&&(Z(!1),L(!1),O(null),Te(null))}return document.addEventListener("pointerdown",e),document.addEventListener("keydown",a),()=>{document.removeEventListener("pointerdown",e),document.removeEventListener("keydown",a)}},[Je,Qe,ae]),c.useLayoutEffect(()=>{if(!ae||typeof window>"u"){Te(null);return}const e=ae;function a(){const u=$t.current;if(!u)return;const f=u.getBoundingClientRect();Te(fa({x:e.positionX,y:e.positionY},{width:f.width||Qi,height:f.height||u.scrollHeight||0},{width:window.innerWidth,height:window.innerHeight}))}a();const s=window.requestAnimationFrame(a);return window.addEventListener("resize",a),window.addEventListener("scroll",a,!0),()=>{window.cancelAnimationFrame(s),window.removeEventListener("resize",a),window.removeEventListener("scroll",a,!0)}},[ae]),c.useEffect(()=>{if(!l)return;const e=Vn(E,D),a=St(V,D,e);wt(Kn(l),{treeCache:a,treeRevisionByPath:Gn(se.current,a),expandedDirectories:e,activeDirectoryPath:D})},[D,E,V,l]),c.useEffect(()=>{if(et.current)return;const e=St(V,D,E);ja(V,e)||Ne(e)},[D,E,V]),c.useEffect(()=>{let e=!1;const a=(l==null?void 0:l.trim())??null;async function s(f){if(!a)return;const p=Nt(le.current[g]??[],I),x=(f==null?void 0:f.silent)!==!0&&p.length===0;x&&ie(!0),Me("file_panel.load_root_tree.start",{sessionId:i,workspaceId:a,silent:(f==null?void 0:f.silent)===!0,cachedRootItems:p.length});try{const N=await zt(g,{force:!0});e||(Me("file_panel.load_root_tree.end",{sessionId:i,workspaceId:a,itemCount:N.length}),Ne(fe=>({...St(fe,Q.current,_.current),[g]:N})))}catch(N){!e&&!Xn(N)&&S({title:te(N,r("conversation.filePanelLoadFailed")),tone:"error"})}finally{!e&&x&&ie(!1)}}if(Nt(le.current[g]??[],I).length>0){const f=window.setTimeout(()=>{a&&(M(a,It(_.current,Q.current),{knownRevisionByPath:se.current}),s({silent:!0}))},1500);return()=>{e=!0,window.clearTimeout(f)}}return s(),()=>{e=!0}},[i,I,S,l]),c.useEffect(()=>{if(!l||!i){At(0);return}const e=en(Sa(l,i),ta);Me("file_panel.session_change_count.snapshot",{sessionId:i,workspaceId:l,cached:e!==null,cachedCount:e}),At(e??0)},[i,sn,l]),c.useEffect(()=>{if(!l){cn([]);return}const e=l.trim();U(e),pe(e)},[l,U,pe]),c.useEffect(()=>{if(!l)return;const e=l.trim();return be(a=>{var s;a.workspaceId===e&&cn(((s=a.status)==null?void 0:s.changes)??[])})},[be,l]);const pt=c.useMemo(()=>nn(on,e=>xt(e.path),I),[on,I]),W=c.useMemo(()=>{const e=new Map,a=new Set;for(const s of pt){const u=s.path.replace(/\\/g,"/"),f=s.worktreeStatus??s.stagedStatus??s.status;e.set(u,f);const p=u.split("/");for(let x=1;x<p.length;x++)a.add(p.slice(0,x).join("/"))}return{statusByPath:e,changedDirs:a}},[pt]),De=c.useMemo(()=>Vi(V,I),[I,V]),Ee=c.useMemo(()=>Ft===null?null:Nt(Ft,I),[Ft,I]),Be=De[g]??[],oe=Ge&&Ee!==null,bt=c.useMemo(()=>J?tn(Be,De,W.statusByPath,W.changedDirs):Be,[W.changedDirs,W.statusByPath,Be,J,De]),ui=c.useMemo(()=>oe?(Ee??[]).map(e=>z(e.path,e.kind)):ni(bt,De,E,J,W.statusByPath,W.changedDirs),[E,W.changedDirs,W.statusByPath,oe,J,Ee,De,bt]),We=((Tn=T.find(e=>e.workspace.id===l))==null?void 0:Tn.workspace)??null,k=Un(K),Ot=(k==null?void 0:k.path)??null,ge=(k==null?void 0:k.kind)==="file"?k.path:null,vt=c.useMemo(()=>new Set(K.map(e=>e.path)),[K]),at=c.useMemo(()=>jt(K),[K]),Ht=!!(We!=null&&We.path&&K.length===1&&Ot),bn=K.length===1&&(k==null?void 0:k.kind)==="file",vn=at.length>0,ke=at.length>0,lt=!!(P!=null&&P.items.length&&l),yn=!!l&&K.length===1&&k!==null,xn=!!((ge?he(ge):D)&&E.length),gn=P?P.mode==="copy"?r("conversation.filePanelClipboardCopyReady",{count:P.items.length}):r("conversation.filePanelClipboardCutReady",{count:P.items.length}):null,H=w?pa(w):null;async function Pn(e,a=!1){if(!l)return[];if(!a){const s=le.current[e];if(s)return s}e===g?ie(!0):Se(s=>kt(s,e));try{const s=await zt(e,{force:a});return Ne(u=>({...u,[e]:s})),s}catch(s){throw Xn(s)||S({title:te(s,r("conversation.filePanelLoadFailed")),tone:"error"}),s}finally{e===g?ie(!1):Se(s=>s.filter(u=>u!==e))}}async function Pe(e){if(!l)return;const a=(e==null?void 0:e.activeDirectoryPath)??Q.current,s=(e==null?void 0:e.expandedDirectories)??_.current,u=Ca(le.current,a,s);Me("file_panel.refresh_tree_cache.start",{sessionId:i,workspaceId:l,targetDirectories:u});const p=(await Promise.all(u.map(async x=>{const N=await zt(x,{force:!0});return[x,N]}))).reduce((x,[N,fe])=>(x[N]=fe,x),{});Me("file_panel.refresh_tree_cache.end",{sessionId:i,workspaceId:l,targetDirectories:u,directoryCount:Object.keys(p).length}),Ne(p)}async function zt(e,a){if(!l)return[];if(!(a!=null&&a.force)){const u=le.current[e];if(u)return u}const s=It(kt(_.current,e),e||Q.current);return M(l,s,{knownRevisionByPath:se.current}),Y(l,[e],{knownRevisionByPath:se.current}),fi(e,On,{allowCached:(a==null?void 0:a.force)!==!0})}function fi(e,a=On,s){const u=le.current[e];return(s==null?void 0:s.allowCached)!==!1&&u?Promise.resolve(u):new Promise((f,p)=>{const x=window.setTimeout(()=>{hi(e,x),p(new Error(`FILE_TREE_SNAPSHOT_TIMEOUT:${e}`))},a),N=re.current.get(e)??[];re.current.set(e,[...N,{resolve:f,reject:p,timerId:x}])})}function di(e,a){const s=re.current.get(e)??[];s.length!==0&&(re.current.delete(e),s.forEach(u=>{window.clearTimeout(u.timerId),u.resolve(a)}))}function hi(e,a){const u=(re.current.get(e)??[]).filter(f=>f.timerId!==a);if(u.length===0){re.current.delete(e);return}re.current.set(e,u)}function Ut(){for(const[e,a]of re.current.entries())a.forEach(s=>{window.clearTimeout(s.timerId),s.reject(new Error(`FILE_TREE_ABORTED:${e}`))});re.current.clear()}function $e(e){$([e]),R(e.path)}function st(e){F(e.kind==="directory"?e.path:he(e.path))}function mi(e){const a=sa(ui,ne,e);$(a),R(e.path),st(e)}function pi(e){const a=la(K,e),s=Un(a);$(a),R(e.path),s&&st(s)}function Cn(e){$e(e),st(e)}function Oe(e,a){if(a!=null&&a.shiftKey){mi(e);return}if(Ct(a)){pi(e);return}Cn(e)}async function rt(e,a=!1){const s=ut(e,a);if(!s.length){F(g);return}Le(u=>si(u,s)),F(s[s.length-1]??g);for(const u of s)try{await Pn(u)}catch{return}}async function ce(e){const a=z(e,"file");$e(a),st(a),await rt(e)}async function He(e){Ye(e),ye(null),tt.current=null,xe.current+=1,ce(e);const a=xe.current,s=e.replace(/\\/g,"/"),u=W.statusByPath.get(s);if(l&&u&&u!=="?"&&u!=="D")try{const f=await Li(l,e,!1);xe.current===a&&ye(f.content||null)}catch{xe.current===a&&ye(null)}}function jn(e){const a=Date.now(),s=tt.current;return tt.current={filePath:e,timestamp:a},(s==null?void 0:s.filePath)===e&&a-s.timestamp<=Ji}function Ce(){tt.current=null}async function bi(e,a){const s=z(e,"file");if(a!=null&&a.shiftKey||Ct(a)){Ce(),Oe(s,a);return}if(jn(e)){await He(e);return}Oe(s,a),await rt(e)}function Sn(){Xe(!1),qe(""),G(null),Ce()}async function vi(e,a){const s=z(e.path,e.kind);if(a!=null&&a.shiftKey||Ct(a)){Ce(),Oe(s,a);return}if(e.kind==="directory"){Sn(),Oe(s,a),await wn(e.path);return}if(jn(e.path)){Sn(),await He(e.path);return}await ce(e.path)}async function wn(e){if($e(z(e,"directory")),F(e),!_.current.includes(e))try{await Pn(e),Le(a=>kt(a,e))}catch{}}async function Nn(e){if($e(z(e,"directory")),F(e),_.current.includes(e)){Dn(e);return}await wn(e)}function Dn(e){Le(a=>a.filter(s=>s!==e&&!s.startsWith(`${e}/`))),F(he(e)),$([]),R(null)}async function En(){if(!l)return;const e=l;try{if(pe(e),await Pe(),ge&&await rt(ge),oe&&A.trim()){const a=await Ve(e,A.trim());G(a.items)}}catch(a){S({title:te(a,r("conversation.filePanelLoadFailed")),tone:"error"})}}async function yi(e){if(e==null||e.preventDefault(),!l||!A.trim()){G(null);return}mt(!0);try{const a=await Ve(l,A.trim());G(a.items)}catch(a){S({title:te(a,r("conversation.filePanelSearchFailed")),tone:"error"})}finally{mt(!1)}}function kn(){if(Ge){Xe(!1),qe(""),G(null);return}Xe(!0)}function q(e){L(!1),e()}function Mn(){var e;(e=hn.current)==null||e.click()}async function xi(e){var p;const a=((p=e.target.files)==null?void 0:p[0])??null;if(e.target.value="",!a||!l)return;const s=aa(a.name);if(!s){S({title:r("conversation.filePanelUploadFailed"),tone:"error"});return}const u=Hn(D,k),f=zn(u,s);dt(!0);try{const x=await ba(a);await Bi({workspaceId:l,path:f,contentBase64:x}),await Pe(),await ce(f),S({title:r("conversation.filePanelUploadSuccess",{name:s}),tone:"success"})}catch(x){S({title:te(x,r("conversation.filePanelUploadFailed")),tone:"error"})}finally{dt(!1)}}async function Vt(e=ge){if(!(!l||!e)){dt(!0);try{const a=await Wi(l,e),s=va(a.contentBase64);ya(a.fileName,new Blob([s],{type:"application/octet-stream"})),S({title:r("conversation.filePanelDownloadSuccess",{name:a.fileName}),tone:"success"})}catch(a){S({title:te(a,r("conversation.filePanelDownloadFailed")),tone:"error"})}finally{dt(!1)}}}function Rn(){const e=ge?he(ge):D;!e||!_.current.includes(e)||Dn(e)}function Kt(){Ie(null),Ae("")}function Gt(){m||Kt()}function ze(e,a=Hn(D,k)){if(!l)return;const s=a,u=s?`${s}/`:"";Z(!1),L(!1),O(null),Ie({mode:e,baseDirectory:s}),Ae(u)}function Xt(e=k){!l||!e||(Z(!1),L(!1),O(null),Ie({mode:"rename",target:e}),Ae(e.path))}async function gi(e){if(e==null||e.preventDefault(),!l||!w)return;const a=(Bt??"").trim();if(a){if(w.mode==="rename"&&Ke(w.target.path)===Ke(a)){Gt();return}j(!0);try{if(w.mode==="rename"){const s=w.target.path,u=z(a,w.target.kind),f=we?li(we,s,a):null;if(await yt({workspaceId:l,opType:"rename",srcPath:s,dstPath:a}),P&&Lt({...P,items:ma(P.items,s,a)}),Kt(),Ce(),await Pe(),w.target.kind==="directory"?(await rt(a,!0),$e(u),F(a)):await ce(a),f!==we&&(xe.current+=1,Ye(f),ye(null)),oe&&A.trim()){const p=await Ve(l,A.trim());G(p.items)}_e(p=>p+1),S({title:r("conversation.filePanelRenameSuccess",{name:xt(a)||a}),tone:"success"});return}if(await yt({workspaceId:l,opType:w.mode,dstPath:a,content:w.mode==="create_file"?"":void 0}),Kt(),await Pe(),w.mode==="create_directory"?(await rt(a,!0),$e(z(a,"directory")),F(a)):await ce(a),oe&&A.trim()){const s=await Ve(l,A.trim());G(s.items)}_e(s=>s+1)}catch(s){S({title:te(s,r("conversation.filePanelMutateFailed")),tone:"error"})}finally{j(!1)}}}function ue(e,a=at){var u;if(a.length===0)return;const s=jt(a);Lt({mode:e,items:s}),$(s),R(((u=s[s.length-1])==null?void 0:u.path)??null),S({title:e==="copy"?r("conversation.filePanelCopySelectionSuccess",{count:s.length}):r("conversation.filePanelCutSelectionSuccess",{count:s.length}),tone:"success"}),O(null)}async function ot(e=ca(k,D)){if(!l||!P||!P.items.length)return;const a=e??g,s=P.items.map(u=>({source:u,destinationPath:zn(a,xt(u.path)||u.path)}));j(!0);try{for(const p of s)P.mode==="cut"&&Ke(p.source.path)===Ke(p.destinationPath)||await yt({workspaceId:l,opType:P.mode==="copy"?"copy":"move",srcPath:p.source.path,dstPath:p.destinationPath});const u=s.map(p=>z(p.destinationPath,p.source.kind)),f=u[u.length-1]??null;if(P.mode==="cut"&&Lt(null),$(u),R((f==null?void 0:f.path)??null),f&&st(f),Ce(),await Pe({activeDirectoryPath:(f==null?void 0:f.kind)==="directory"?f.path:f?he(f.path):Q.current,expandedDirectories:_.current}),oe&&A.trim()){const p=await Ve(l,A.trim());G(p.items)}_e(p=>p+1),S({title:r("conversation.filePanelPasteSuccess",{count:u.length}),tone:"success"}),O(null)}catch(u){await Pe().catch(()=>{}),S({title:te(u,r("conversation.filePanelPasteFailed")),tone:"error"})}finally{j(!1)}}function qt(e=at){!e.length||m||(Fe(jt(e)),O(null))}async function Pi(){var a,s;if(!l||!(B!=null&&B.length))return;const e=jt(B);j(!0);try{for(const p of e)await yt({workspaceId:l,opType:"delete",srcPath:p.path});const u=ua(D,e),f=_.current.filter(p=>!e.some(x=>x.kind==="directory"&&_t(x.path,p)));if(we&&e.some(p=>_t(p.path,we))&&(xe.current+=1,Ye(null),ye(null)),Fe(null),$([]),R(null),Q.current=u,_.current=f,F(u),Le(f),Ce(),await Pe({activeDirectoryPath:u,expandedDirectories:f}),oe&&A.trim()){const p=await Ve(l,A.trim());G(p.items)}_e(p=>p+1),S({title:e.length===1?r("conversation.filePanelDeleteSuccess",{name:xt(((a=e[0])==null?void 0:a.path)??"")||((s=e[0])==null?void 0:s.path)||""}):r("conversation.filePanelDeleteSelectionSuccess",{count:e.length}),tone:"success"})}catch(u){S({title:te(u,r("conversation.filePanelMutateFailed")),tone:"error"})}finally{j(!1)}}async function Ue(e,a=k){const s=(We==null?void 0:We.path)??"",u=(a==null?void 0:a.path)??null;if(u===null||!s){Z(!1);return}try{const f=ha(s),p=e==="absolute"?da(s,u,f):Ke(u,f);await xa(p,nt),S({title:e==="absolute"?r("conversation.filePanelCopyAbsolutePathSuccess"):r("conversation.filePanelCopyRelativePathSuccess"),tone:"success"})}catch(f){S({title:f instanceof Error?f.message:r("conversation.filePanelCopyPathFailed"),tone:"error"})}finally{Z(!1),O(null)}}function Ci(e,a,s){return[{id:`open-${e.path}`,label:e.kind==="directory"?E.includes(e.path)?r("conversation.filePanelCollapseDirectory"):r("conversation.filePanelExpandDirectory"):r("conversation.filePanelOpenFile"),onSelect:()=>{if(e.kind==="directory"){Nn(e.path);return}He(e.path)}},{id:`download-${e.path}`,label:r("conversation.filePanelDownload"),disabled:e.kind!=="file"||v,onSelect:()=>{Vt(e.kind==="file"?e.path:null)}},{id:`create-file-${e.path}`,label:r("conversation.filePanelNewFile"),disabled:!l||m||v,onSelect:()=>{ze("create_file",s)}},{id:`create-directory-${e.path}`,label:r("conversation.filePanelNewDirectory"),disabled:!l||m||v,onSelect:()=>{ze("create_directory",s)}},{id:`rename-${e.path}`,label:r("conversation.filePanelRenameMove"),disabled:a.length!==1||m||v,onSelect:()=>Xt(e)},{id:`copy-${e.path}`,label:r("conversation.filePanelCopy"),disabled:a.length===0,onSelect:()=>ue("copy",a)},{id:`cut-${e.path}`,label:r("conversation.filePanelCut"),disabled:a.length===0,onSelect:()=>ue("cut",a)},{id:`paste-${e.path}`,label:r("conversation.filePanelPaste"),disabled:!lt,onSelect:()=>{ot(s)}},{id:`copy-relative-${e.path}`,label:r("conversation.filePanelCopyRelativePath"),onSelect:()=>{Ue("relative",e)}},{id:`copy-absolute-${e.path}`,label:r("conversation.filePanelCopyAbsolutePath"),onSelect:()=>{Ue("absolute",e)}},{id:`delete-${e.path}`,label:r("conversation.filePanelDelete"),disabled:a.length===0||m||v,onSelect:()=>qt(a)}]}async function _n(e,a){if(nt.isMobile)return;e.preventDefault();const s=z(a.path,a.kind),u=vt.has(s.path)?at:[s],f=s.kind==="directory"?s.path:he(s.path);vt.has(s.path)||Cn(s);const p=Ci(s,u,f);if(nt.isDesktop){await $i(p);return}nt.isWeb&&(Z(!1),L(!1),O({positionX:e.clientX,positionY:e.clientY,items:p}))}c.useEffect(()=>{if(X!=="workspace")return;function e(a){if(!ra(a)||a.altKey||a.shiftKey||oa(a.target))return;const s=a.key.toLowerCase();if(s==="c"&&ke){a.preventDefault(),ue("copy");return}if(s==="x"&&ke){a.preventDefault(),ue("cut");return}s==="v"&&lt&&(a.preventDefault(),ot())}return document.addEventListener("keydown",e),()=>{document.removeEventListener("keydown",e)}},[X,ke,lt,ue,ot]);function Yt(e,a){return n.jsx(n.Fragment,{children:e.map(s=>{const u=z(s.path,s.kind),f=s.kind==="directory",p=f&&E.includes(s.path),x=f&&je.includes(s.path),N=De[s.path]??[],fe=J?tn(N,De,W.statusByPath,W.changedDirs):N,Si=vt.has(s.path),wi=Ot===s.path,ct=W.statusByPath.get(s.path.replace(/\\/g,"/")),An=f&&W.changedDirs.has(s.path.replace(/\\/g,"/")),Ni=(P==null?void 0:P.mode)==="cut"&&P.items.some(de=>de.path===s.path);return n.jsxs("div",{className:"file-tree-node",children:[n.jsxs("button",{className:"file-tree-item",type:"button","data-active":wi,"data-selected":Si,"data-cut-pending":Ni||void 0,"data-kind":s.kind,"aria-expanded":f?p:void 0,style:{paddingInlineStart:`${na+a*ia}px`},onClick:de=>{if(f){if(de.shiftKey||Ct(de)){Ce(),Oe(u,de);return}Ce(),Oe(u,de),Nn(s.path);return}bi(s.path,de)},onContextMenu:de=>{_n(de,s)},children:[n.jsx("span",{className:`file-tree-chevron${f?"":" is-hidden"}`,"aria-hidden":"true",children:p?"v":">"}),f?null:n.jsx("span",{className:"git-tree-file-icon","data-kind":Rt(s.name),"aria-hidden":"true",children:Mt(s.name)}),n.jsx("span",{className:"file-tree-label","data-status":ct??void 0,"data-has-changes":An||void 0,children:s.name}),!f&&ct?n.jsx("span",{className:"git-status-badge","data-status":ct,"aria-label":ct,children:ct}):null,f&&An?n.jsx("span",{className:"file-tree-dir-badge","aria-hidden":"true"}):null,x?n.jsx("span",{className:"file-tree-meta",children:r("common.loading")}):null]}),f&&p?n.jsx("div",{className:"file-tree-children",children:x&&!N.length?n.jsx("p",{className:"file-tree-empty",children:r("common.loading")}):fe.length?Yt(fe,a+1):n.jsx("p",{className:"file-tree-empty",children:r("conversation.filePanelEmptyDirectory")})}):null]},`${s.kind}-${s.path}`)})})}function ji(e){return n.jsx(n.Fragment,{children:e.map(a=>{const s=a.kind==="directory",u=vt.has(a.path),f=Ot===a.path;return n.jsx("div",{className:"file-tree-node",children:n.jsxs("button",{className:"file-tree-item is-search-result",type:"button","data-active":f,"data-selected":u,"data-kind":a.kind,onClick:p=>{vi(a,p)},onContextMenu:p=>{_n(p,a)},children:[n.jsx("span",{className:"file-tree-chevron is-hidden","aria-hidden":"true",children:">"}),s?null:n.jsx("span",{className:"git-tree-file-icon","data-kind":Rt(a.name),"aria-hidden":"true",children:Mt(a.name)}),n.jsxs("span",{className:"file-tree-label",children:[n.jsx("span",{className:"file-tree-name",children:a.name}),n.jsx("span",{className:"file-tree-path",children:a.path})]})]})},`search-${a.kind}-${a.path}`)})})}return n.jsx("section",{className:["conversation-panel","surface-card","file-panel",t].filter(Boolean).join(" "),"data-testid":"file-context-panel",children:l?n.jsxs(n.Fragment,{children:[n.jsx(Oi,{workspaceId:l,filePath:we,open:we!==null,onClose:()=>{xe.current+=1,Ye(null),ye(null)},onSaved:async e=>{await Pe(),await ce(e),_e(a=>a+1)},diffContent:oi}),o?null:n.jsx("div",{className:"file-panel-heading-row",children:n.jsx("h2",{className:"file-panel-heading",children:r("conversation.filePanelTitle")})}),h?null:n.jsxs("div",{className:"file-panel-tabs",role:"tablist","aria-label":r("conversation.filePanelTitle"),children:[n.jsx("button",{className:X==="workspace"?"file-panel-tab active":"file-panel-tab",type:"button",role:"tab","aria-selected":X==="workspace",onClick:()=>Ze("workspace"),children:r("conversation.filePanelWorkspaceTab")}),n.jsxs("button",{className:X==="session"?"file-panel-tab active":"file-panel-tab",type:"button",role:"tab","aria-selected":X==="session",onClick:()=>{it&&Ze("session")},disabled:!it,children:[r("conversation.filePanelSessionTab"),n.jsx("span",{className:"file-panel-tab-badge","aria-label":`${r("conversation.filePanelSessionTab")} ${rn}`,children:rn})]})]}),X==="workspace"?n.jsxs(n.Fragment,{children:[n.jsx("input",{ref:hn,"data-testid":"file-panel-upload-input",type:"file",hidden:!0,onChange:e=>void xi(e)}),pn?n.jsx("div",{className:"file-panel-toolbar file-panel-toolbar-mobile","aria-label":r("conversation.filePanelTitle"),children:n.jsxs("div",{className:"file-mobile-action-shell",ref:dn,children:[n.jsxs("button",{className:"secondary-button file-mobile-action-trigger",type:"button","aria-label":r("conversation.filePanelActionsMenu"),"aria-haspopup":"menu","aria-expanded":Qe,"data-active":Qe,onClick:()=>{Z(!1),L(e=>!e)},children:[n.jsx("span",{children:r("conversation.filePanelActionsMenu")}),n.jsx(Ba,{})]}),Qe?n.jsxs("div",{className:"file-mobile-action-menu",role:"menu","aria-label":r("conversation.filePanelActionsMenu"),children:[n.jsx("button",{className:"file-mobile-action-menu-item",type:"button",role:"menuitem",onClick:()=>q(()=>ue("copy")),disabled:!ke,children:r("conversation.filePanelCopy")}),n.jsx("button",{className:"file-mobile-action-menu-item",type:"button",role:"menuitem",onClick:()=>q(()=>ue("cut")),disabled:!ke,children:r("conversation.filePanelCut")}),n.jsx("button",{className:"file-mobile-action-menu-item",type:"button",role:"menuitem",onClick:()=>q(()=>ot()),disabled:!lt||m||v,children:r("conversation.filePanelPaste")}),n.jsx("button",{className:"file-mobile-action-menu-item",type:"button",role:"menuitem",onClick:()=>{L(!1),kn()},children:Ge?r("conversation.filePanelHideSearch"):r("conversation.filePanelShowSearch")}),n.jsx("button",{className:"file-mobile-action-menu-item",type:"button",role:"menuitem",onClick:()=>{L(!1),Wt(e=>!e)},disabled:pt.length===0,children:J?r("conversation.filePanelShowAll"):r("conversation.filePanelFilterChanges")}),n.jsx("button",{className:"file-mobile-action-menu-item",type:"button",role:"menuitem",onClick:()=>q(En),disabled:Re||m||ht,children:r("conversation.filePanelRefresh")}),n.jsx("button",{className:"file-mobile-action-menu-item",type:"button",role:"menuitem",onClick:()=>{L(!1),Rn()},disabled:!xn,children:r("conversation.filePanelCollapseCurrent")}),n.jsx("button",{className:"file-mobile-action-menu-item",type:"button",role:"menuitem",onClick:()=>{L(!1),Mn()},disabled:m||v,children:r("conversation.filePanelUpload")}),n.jsx("button",{className:"file-mobile-action-menu-item",type:"button",role:"menuitem",onClick:()=>q(Vt),disabled:!bn||v,children:r("conversation.filePanelDownload")}),n.jsx("button",{className:"file-mobile-action-menu-item",type:"button",role:"menuitem",onClick:()=>q(Xt),disabled:!yn||m||v,children:r("conversation.filePanelRenameMove")}),n.jsx("button",{className:"file-mobile-action-menu-item danger",type:"button",role:"menuitem",onClick:()=>q(qt),disabled:!vn||m||v,children:r("conversation.filePanelDelete")}),n.jsx("button",{className:"file-mobile-action-menu-item",type:"button",role:"menuitem",onClick:()=>q(()=>ze("create_file")),disabled:m||v,children:r("conversation.filePanelNewFile")}),n.jsx("button",{className:"file-mobile-action-menu-item",type:"button",role:"menuitem",onClick:()=>q(()=>ze("create_directory")),disabled:m||v,children:r("conversation.filePanelNewDirectory")}),n.jsx("button",{className:"file-mobile-action-menu-item",type:"button",role:"menuitem",onClick:()=>q(()=>Ue("absolute")),disabled:!Ht,children:r("conversation.filePanelCopyAbsolutePath")}),n.jsx("button",{className:"file-mobile-action-menu-item",type:"button",role:"menuitem",onClick:()=>q(()=>Ue("relative")),disabled:!Ht,children:r("conversation.filePanelCopyRelativePath")})]}):null]})}):n.jsxs("div",{className:"file-panel-toolbar","aria-label":r("conversation.filePanelTitle"),children:[n.jsx("button",{className:"file-toolbar-button",type:"button",title:r("conversation.filePanelCopy"),"aria-label":r("conversation.filePanelCopy"),onClick:()=>ue("copy"),disabled:!ke,children:n.jsx(Ea,{})}),n.jsx("button",{className:"file-toolbar-button",type:"button",title:r("conversation.filePanelCut"),"aria-label":r("conversation.filePanelCut"),onClick:()=>ue("cut"),disabled:!ke,children:n.jsx(ka,{})}),n.jsx("button",{className:"file-toolbar-button",type:"button",title:r("conversation.filePanelPaste"),"aria-label":r("conversation.filePanelPaste"),onClick:()=>void ot(),disabled:!lt||m||v,children:n.jsx(Ma,{})}),n.jsxs("div",{className:"file-toolbar-menu-shell",ref:fn,children:[n.jsx("button",{className:"file-toolbar-button",type:"button",title:r("conversation.filePanelCopyPath"),"aria-label":r("conversation.filePanelCopyPath"),"aria-haspopup":"menu","aria-expanded":Je,"data-active":Je,onClick:()=>{L(!1),Z(e=>!e)},disabled:!Ht,children:n.jsx(Da,{})}),Je?n.jsxs("div",{className:"file-toolbar-menu",role:"menu",children:[n.jsx("button",{className:"file-toolbar-menu-item",type:"button",role:"menuitem",onClick:()=>void Ue("absolute"),children:r("conversation.filePanelCopyAbsolutePath")}),n.jsx("button",{className:"file-toolbar-menu-item",type:"button",role:"menuitem",onClick:()=>void Ue("relative"),children:r("conversation.filePanelCopyRelativePath")})]}):null]}),n.jsx("button",{className:"file-toolbar-button",type:"button",title:r("conversation.filePanelCollapseCurrent"),"aria-label":r("conversation.filePanelCollapseCurrent"),onClick:Rn,disabled:!xn,children:n.jsx(wa,{})}),n.jsx("button",{className:"file-toolbar-button",type:"button",title:r("conversation.filePanelRefresh"),"aria-label":r("conversation.filePanelRefresh"),onClick:()=>void En(),disabled:Re||m||ht,children:n.jsx(Na,{})}),n.jsx("button",{className:"file-toolbar-button",type:"button",title:r("conversation.filePanelSearchButton"),"aria-label":r("conversation.filePanelSearchButton"),"data-active":Ge,onClick:kn,disabled:Re,children:n.jsx(qn,{})}),pt.length>0?n.jsx("button",{className:"file-toolbar-button",type:"button",title:J?r("conversation.filePanelShowAll"):r("conversation.filePanelFilterChanges"),"aria-label":J?r("conversation.filePanelShowAll"):r("conversation.filePanelFilterChanges"),"data-active":J,onClick:()=>Wt(e=>!e),children:n.jsx(Wa,{})}):null,n.jsx("button",{className:"file-toolbar-button",type:"button",title:r("conversation.filePanelUpload"),"aria-label":r("conversation.filePanelUpload"),onClick:Mn,disabled:m||v,children:n.jsx(_a,{})}),n.jsx("button",{className:"file-toolbar-button",type:"button",title:r("conversation.filePanelDownload"),"aria-label":r("conversation.filePanelDownload"),onClick:()=>void Vt(),disabled:!bn||v,children:n.jsx(Ta,{})}),n.jsx("button",{className:"file-toolbar-button",type:"button",title:r("conversation.filePanelRenameMove"),"aria-label":r("conversation.filePanelRenameMove"),onClick:()=>Xt(),disabled:!yn||m||v,children:n.jsx(La,{})}),n.jsx("button",{className:"file-toolbar-button danger",type:"button",title:r("conversation.filePanelDelete"),"aria-label":r("conversation.filePanelDelete"),onClick:()=>qt(),disabled:!vn||m||v,children:n.jsx(Fa,{})}),n.jsx("button",{className:"file-toolbar-button",type:"button",title:r("conversation.filePanelNewFile"),"aria-label":r("conversation.filePanelNewFile"),onClick:()=>void ze("create_file"),disabled:m||v,children:n.jsx(Ra,{})}),n.jsx("button",{className:"file-toolbar-button",type:"button",title:r("conversation.filePanelNewDirectory"),"aria-label":r("conversation.filePanelNewDirectory"),onClick:()=>void ze("create_directory"),disabled:m||v,children:n.jsx(Aa,{})})]}),ae&&typeof document<"u"?Ei.createPortal(n.jsx("div",{className:"file-web-context-menu",ref:$t,role:"menu","aria-label":r("conversation.filePanelActionsMenu"),style:{left:`${(ve==null?void 0:ve.left)??Math.max(8,ae.positionX)}px`,top:`${(ve==null?void 0:ve.top)??Math.max(8,ae.positionY)}px`,maxHeight:ve?`${ve.maxHeight}px`:void 0},children:ae.items.map(e=>n.jsx("button",{className:["file-web-context-menu-item",e.label===r("conversation.filePanelDelete")?"danger":""].filter(Boolean).join(" "),type:"button",role:"menuitem",disabled:e.disabled,onClick:()=>{O(null),e.onSelect()},children:e.label},e.id))}),document.body):null,gn?n.jsx("p",{className:"file-panel-clipboard-status","data-mode":P==null?void 0:P.mode,children:gn}):null,Ge?n.jsxs("form",{className:"file-toolbar-search",onSubmit:e=>void yi(e),children:[n.jsx("input",{value:A,onChange:e=>qe(e.target.value),placeholder:r("conversation.filePanelSearchPlaceholder")}),pn?n.jsx("button",{className:"secondary-button file-mobile-search-submit",type:"submit","aria-label":r("conversation.filePanelSearchButton"),disabled:ht,children:r("conversation.filePanelSearchButton")}):n.jsx("button",{className:"file-toolbar-button",type:"submit",title:r("conversation.filePanelSearchButton"),"aria-label":r("conversation.filePanelSearchButton"),disabled:ht,children:n.jsx(qn,{})})]}):null,n.jsx("div",{ref:ci,className:"file-tree","data-search-mode":oe,"data-scrollbar-autohide":"true",children:Re&&Be.length===0?n.jsx("p",{className:"file-tree-status status-text",children:r("common.loading")}):oe?Ee!=null&&Ee.length?ji(Ee):n.jsx("p",{className:"file-tree-status status-text",children:r("conversation.filePanelSearchEmpty")}):J?bt.length?Yt(bt,0):n.jsx("p",{className:"file-tree-status status-text",children:r("conversation.filePanelNoChanges")}):Be.length?Yt(Be,0):n.jsx("p",{className:"file-tree-status status-text",children:r("conversation.filePanelEmptyDirectory")})}),n.jsx(Ln,{open:w!==null,title:(H==null?void 0:H.title)??"",description:H==null?void 0:H.description,onClose:Gt,children:n.jsxs("form",{className:"workbench-rename-form",onSubmit:e=>void gi(e),children:[n.jsx(Ri,{label:r("conversation.filePanelPathFieldLabel"),htmlFor:un,description:(w==null?void 0:w.mode)==="rename"?w.target.path:(w==null?void 0:w.baseDirectory)||void 0,children:n.jsx("input",{id:un,type:"text",value:Bt??"",placeholder:r("conversation.filePanelPathFieldPlaceholder"),autoFocus:!0,onChange:e=>Ae(e.target.value)})}),n.jsxs(_i,{children:[n.jsx("button",{type:"button",className:"secondary-button",disabled:m,onClick:Gt,children:r("common.cancel")}),n.jsx("button",{type:"submit",className:"primary-button",disabled:m||!(Bt??"").trim(),children:m?(H==null?void 0:H.pendingLabel)??r("common.loading"):(H==null?void 0:H.submitLabel)??r("common.save")})]})]})}),n.jsxs(Ln,{open:B!==null,title:r("conversation.filePanelDeleteConfirmTitle"),description:r("conversation.filePanelDeleteConfirmDescription"),onClose:()=>{m||Fe(null)},children:[n.jsx("p",{className:"workbench-section-empty",children:B!=null&&B.length?B.length===1?((Fn=B[0])==null?void 0:Fn.kind)==="directory"?r("conversation.filePanelDeleteDirectoryConfirm",{path:B[0].path}):r("conversation.filePanelDeleteFileConfirm",{path:B[0].path}):r("conversation.filePanelDeleteSelectionConfirm",{count:B.length}):""}),n.jsxs("div",{className:"workbench-modal-actions",children:[n.jsx("button",{type:"button",className:"secondary-button",disabled:m,onClick:()=>Fe(null),children:r("common.cancel")}),n.jsx("button",{type:"button",className:"secondary-button workbench-danger-button",disabled:m,onClick:()=>{Pi()},children:m?r("conversation.filePanelDeleting"):r("conversation.filePanelDelete")})]})]})]}):it&&i?n.jsx(Yi,{sessionId:i,workspaceId:l,showSystemFiles:I,selectedPath:ge,refreshVersion:sn,onCountChange:At,onSelectFile:ce,onOpenFile:He}):n.jsx("section",{className:"file-panel-section",children:n.jsx("p",{className:"status-text",children:r("conversation.filePanelSessionNoSession")})})]}):n.jsx("section",{className:"file-panel-section",children:n.jsx("p",{className:"status-text",children:r("conversation.filePanelNoWorkspace")})})})}function he(t){return t.includes("/")?t.split("/").slice(0,-1).join("/"):g}function ut(t,i=!1){const l=t.split("/").filter(Boolean),o=i?l.length:l.length-1,h=[];for(let d=0;d<o;d+=1)h.push(l.slice(0,d+1).join("/"));return h}function Hn(t,i){return t||((i==null?void 0:i.kind)==="directory"?i.path:i!=null&&i.path?he(i.path):g)}function zn(t,i){return t?`${t}/${i}`:i}function aa(t){var i;return((i=t.split(/[/\\]/).pop())==null?void 0:i.trim())??""}function z(t,i){return{path:t,kind:i}}function Un(t){return t[t.length-1]??null}function la(t,i){return t.findIndex(o=>o.path===i.path)>=0?t.filter(o=>o.path!==i.path):[...t,i]}function sa(t,i,l){const o=t.findIndex(y=>y.path===l.path);if(o<0)return[l];const h=i?t.findIndex(y=>y.path===i):o;if(h<0)return[l];const d=Math.min(h,o),b=Math.max(h,o);return t.slice(d,b+1)}function Ct(t){return!!(t!=null&&t.ctrlKey||t!=null&&t.metaKey)}function ra(t){return t.ctrlKey||t.metaKey}function oa(t){if(!(t instanceof HTMLElement))return!1;const i=t.tagName.toLowerCase();return i==="input"||i==="textarea"||i==="select"||t.isContentEditable}function jt(t){const i=[...new Map(t.map(o=>[o.path,o])).values()].sort((o,h)=>o.path.localeCompare(h.path)),l=[];for(const o of i)l.some(h=>h.kind==="directory"&&_t(h.path,o.path))||l.push(o);return l}function ca(t,i){return(t==null?void 0:t.kind)==="directory"?t.path:t!=null&&t.path?he(t.path):i}function ua(t,i){let l=t;for(;l&&i.some(o=>o.kind==="directory"&&_t(o.path,l));)l=he(l);return l}function ni(t,i,l,o,h,d){const b=[];for(const y of t){if(b.push(z(y.path,y.kind)),y.kind!=="directory"||!l.includes(y.path))continue;const C=i[y.path]??[],T=o?tn(C,i,h,d):C;b.push(...ni(T,i,l,o,h,d))}return b}function fa(t,i,l){const o=Math.max(0,l.width),h=Math.max(0,l.height),d=Math.max(0,h-ee*2),b=Math.max(0,o-ee*2),y=Math.min(Math.max(i.width,0),b),C=Math.max(0,h-t.y-Pt-ee),T=Math.max(0,t.y-Pt-ee),M=C<i.height&&T>C,me=Qt(Math.max(M?T:C,Ii),0,d),U=Math.min(Math.max(i.height,0),me),pe=M?t.y-Pt-U:t.y+Pt,be=Math.max(ee,h-ee-U),V=Math.max(ee,o-ee-y);return{top:Qt(pe,ee,be),left:Qt(t.x,ee,V),maxHeight:Math.max(0,me)}}function Qt(t,i,l){return!Number.isFinite(t)||l<i?i:Math.min(Math.max(t,i),l)}function Ke(t,i="posix"){return t?ii(t,i):"."}function da(t,i,l){const o=ii(t,l),h=Ke(i,l).replace(/^\.[/\\]?/,"");if(!h)return o;const d=ai(l),b=h.replace(/^[/\\]+/,"");return b?o.endsWith("/")||o.endsWith("\\")?`${o}${b}`:`${o}${d}${b}`:o}function ha(t){return/^[a-zA-Z]:[\\/]/.test(t)||t.includes("\\")?"windows":"posix"}function ii(t,i){return t&&(ai(i)==="\\"?t.replace(/\//g,"\\"):t.replace(/\\/g,"/"))}function ai(t){return t==="windows"?"\\":"/"}function _t(t,i){return i===t||i.startsWith(`${t}/`)}function li(t,i,l){return t===i?l:t.startsWith(`${i}/`)?`${l}${t.slice(i.length)}`:t}function ma(t,i,l){return t.map(o=>({...o,path:li(o.path,i,l)}))}function pa(t){return t.mode==="create_file"?{title:r("conversation.filePanelNewFile"),description:r("conversation.filePanelCreateFileDescription"),submitLabel:r("conversation.filePanelCreateFileSubmit"),pendingLabel:r("conversation.filePanelCreatingFile")}:t.mode==="create_directory"?{title:r("conversation.filePanelNewDirectory"),description:r("conversation.filePanelCreateDirectoryDescription"),submitLabel:r("conversation.filePanelCreateDirectorySubmit"),pendingLabel:r("conversation.filePanelCreatingDirectory")}:{title:r("conversation.filePanelRenameMove"),description:r("conversation.filePanelRenameDescription"),submitLabel:r("conversation.filePanelRenameSubmit"),pendingLabel:r("conversation.filePanelRenaming")}}async function ba(t){const i=await t.arrayBuffer(),l=new Uint8Array(i),o=32768;let h="";for(let d=0;d<l.length;d+=o){const b=l.subarray(d,d+o);h+=String.fromCharCode(...b)}return btoa(h)}function va(t){const i=atob(t),l=new Uint8Array(i.length);for(let o=0;o<i.length;o+=1)l[o]=i.charCodeAt(o);return l.buffer.slice(l.byteOffset,l.byteOffset+l.byteLength)}function ya(t,i){if(typeof document>"u")throw new Error(r("conversation.filePanelDownloadFailed"));const l=window.URL.createObjectURL(i),o=document.createElement("a");o.href=l,o.download=t,document.body.append(o),o.click(),o.remove(),window.URL.revokeObjectURL(l)}async function xa(t,i){var l;if(!(i.isDesktop&&(await i.bridge.writeClipboardText(t)).ok)){if(typeof navigator<"u"&&((l=navigator.clipboard)!=null&&l.writeText))try{await navigator.clipboard.writeText(t);return}catch{}if(!ga(t))throw new Error(r("conversation.filePanelCopyPathFailed"))}}function ga(t){if(typeof document>"u"||typeof document.execCommand!="function")return!1;const i=document.createElement("textarea");i.value=t,i.setAttribute("readonly","true"),i.style.position="fixed",i.style.top="-9999px",i.style.left="-9999px",i.style.opacity="0",document.body.appendChild(i),i.focus(),i.select();try{return document.execCommand("copy")}catch{return!1}finally{document.body.removeChild(i)}}function Pa(t,i){return t&&ut(t,!0).every(h=>h in i)?t:g}function Vn(t,i){if(!i)return[];const l=ut(i,!0);return t.filter(o=>l.includes(o))}function St(t,i,l){const o=ln(i,l);return Object.entries(t).reduce((h,[d,b])=>(o.has(d)&&(h[d]=b),h),{})}function Ca(t,i,l){const h=[...ln(i,l)].filter(d=>d===g||d in t);return h.length?h:[g]}function ln(t,i){const l=new Set([g]),o=si(i,ut(t,!0));for(const h of o){l.add(h);for(const d of ut(h,!0))l.add(d)}return l}function ja(t,i){const l=Object.keys(t),o=Object.keys(i);return l.length!==o.length?!1:l.every(h=>t[h]===i[h])}function kt(t,i){return t.includes(i)?t:[...t,i]}function si(t,i){return i.reduce((l,o)=>kt(l,o),t)}function Kn(t){return`file-panel.workspace-tree.${t}`}function Sa(t,i){return`file-panel.session-change-count.${t}.${i}`}function Gn(t,i){return Object.fromEntries(Object.keys(i).map(l=>[l,t[l]??null]))}function It(t,i){return[...ln(i,t)]}function te(t,i){return t instanceof Yn?t.message:i}function Xn(t){return t instanceof Error&&(t.message.startsWith("FILE_TREE_SNAPSHOT_TIMEOUT:")||t.message.startsWith("FILE_TREE_ABORTED:"))}function wa(){return n.jsx("svg",{viewBox:"0 0 16 16","aria-hidden":"true",children:n.jsx("path",{d:"M2.5 4.5h11v2h-11zM2.5 7.5h7v2h-7zM2.5 10.5h4v2h-4z",fill:"currentColor"})})}function Na(){return n.jsx("svg",{viewBox:"0 0 16 16","aria-hidden":"true",children:n.jsx("path",{d:"M12.8 5.2A5.5 5.5 0 1 0 13.5 8h-1.8A3.7 3.7 0 1 1 10.6 5l-1.4 1.4h4V2l-1.4 1.4z",fill:"currentColor"})})}function qn(){return n.jsx("svg",{viewBox:"0 0 16 16","aria-hidden":"true",children:n.jsx("path",{d:"M11.2 10.1l3 3-1.1 1.1-3-3a5 5 0 1 1 1.1-1.1zM6.8 10.3a3.5 3.5 0 1 0 0-7 3.5 3.5 0 0 0 0 7z",fill:"currentColor"})})}function Da(){return n.jsxs("svg",{viewBox:"0 0 16 16","aria-hidden":"true",children:[n.jsx("path",{d:"M3.5 4.3h5.2v1.4H4.9v5.4H3.5zm3.8-2.1h5.2v9.5H7.3z",fill:"none",stroke:"currentColor",strokeWidth:"1.2"}),n.jsx("path",{d:"M5.7 10.8h4.5",fill:"none",stroke:"currentColor",strokeWidth:"1.2"})]})}function Ea(){return n.jsxs("svg",{viewBox:"0 0 16 16","aria-hidden":"true",children:[n.jsx("path",{d:"M5 2.5h7.5v9H5z",fill:"none",stroke:"currentColor",strokeWidth:"1.2"}),n.jsx("path",{d:"M3.5 5H2.4V13.5H10V12.4",fill:"none",stroke:"currentColor",strokeWidth:"1.2"})]})}function ka(){return n.jsx("svg",{viewBox:"0 0 16 16","aria-hidden":"true",children:n.jsx("path",{d:"M4.2 4.2a1.4 1.4 0 1 1 0 2.8 1.4 1.4 0 0 1 0-2.8zm0 5.4a1.4 1.4 0 1 1 0 2.8 1.4 1.4 0 0 1 0-2.8zm1-3.2 6.6 5.6M5.2 9.6l6.6-5.6",fill:"none",stroke:"currentColor",strokeWidth:"1.2",strokeLinecap:"round"})})}function Ma(){return n.jsxs("svg",{viewBox:"0 0 16 16","aria-hidden":"true",children:[n.jsx("path",{d:"M4 3.5h8v10H4zM6 2.2h4v2H6z",fill:"none",stroke:"currentColor",strokeWidth:"1.2"}),n.jsx("path",{d:"M6 7.2h4M6 9.6h4",fill:"none",stroke:"currentColor",strokeWidth:"1.2"})]})}function Ra(){return n.jsxs("svg",{viewBox:"0 0 16 16","aria-hidden":"true",children:[n.jsx("path",{d:"M4 1.5h5l3 3v10H4z",fill:"none",stroke:"currentColor",strokeWidth:"1.2"}),n.jsx("path",{d:"M9 1.5v3h3",fill:"none",stroke:"currentColor",strokeWidth:"1.2"}),n.jsx("path",{d:"M8 6.5v5M5.5 9h5",fill:"none",stroke:"currentColor",strokeWidth:"1.2"})]})}function _a(){return n.jsxs("svg",{viewBox:"0 0 16 16","aria-hidden":"true",children:[n.jsx("path",{d:"M3 11.5v2h10v-2",fill:"none",stroke:"currentColor",strokeWidth:"1.2"}),n.jsx("path",{d:"M8 2.5v8",fill:"none",stroke:"currentColor",strokeWidth:"1.2"}),n.jsx("path",{d:"m5.5 5 2.5-2.5L10.5 5",fill:"none",stroke:"currentColor",strokeWidth:"1.2",strokeLinecap:"round",strokeLinejoin:"round"})]})}function Ta(){return n.jsxs("svg",{viewBox:"0 0 16 16","aria-hidden":"true",children:[n.jsx("path",{d:"M3 11.5v2h10v-2",fill:"none",stroke:"currentColor",strokeWidth:"1.2"}),n.jsx("path",{d:"M8 2.5v8",fill:"none",stroke:"currentColor",strokeWidth:"1.2"}),n.jsx("path",{d:"m5.5 8.5 2.5 2.5 2.5-2.5",fill:"none",stroke:"currentColor",strokeWidth:"1.2",strokeLinecap:"round",strokeLinejoin:"round"})]})}function Fa(){return n.jsx("svg",{viewBox:"0 0 16 16","aria-hidden":"true",children:n.jsx("path",{d:"M3.5 4.5h9M6.2 2.5h3.6l.6 1.4H13v1.2H3V3.9h2.6zM5.2 5.7v6.1m2.8-6.1v6.1m2.8-6.1v6.1M4.4 13.5h7.2",fill:"none",stroke:"currentColor",strokeWidth:"1.2",strokeLinecap:"round",strokeLinejoin:"round"})})}function Aa(){return n.jsxs("svg",{viewBox:"0 0 16 16","aria-hidden":"true",children:[n.jsx("path",{d:"M1.8 4.5h4l1.2 1.3h7.2v6.7H1.8z",fill:"none",stroke:"currentColor",strokeWidth:"1.2"}),n.jsx("path",{d:"M8.5 7.2v4M6.5 9.2h4",fill:"none",stroke:"currentColor",strokeWidth:"1.2"})]})}function La(){return n.jsx("svg",{viewBox:"0 0 16 16","aria-hidden":"true",children:n.jsx("path",{d:"M3.2 11.9h2.2l5.9-5.9-2.2-2.2-5.9 5.9zM8.3 3.8l2.2 2.2M2.8 13.2h10.4",fill:"none",stroke:"currentColor",strokeWidth:"1.2",strokeLinecap:"round",strokeLinejoin:"round"})})}function Ba(){return n.jsx("svg",{viewBox:"0 0 16 16","aria-hidden":"true",children:n.jsx("path",{d:"m4 6 4 4 4-4",fill:"none",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round"})})}function Wa(){return n.jsx("svg",{viewBox:"0 0 16 16","aria-hidden":"true",children:n.jsx("path",{d:"M1.5 2h13l-5 6v5l-3 1.5V8z",fill:"none",stroke:"currentColor",strokeWidth:"1.2",strokeLinejoin:"round"})})}function tn(t,i,l,o){const h=[];for(const d of t){const b=d.path.replace(/\\/g,"/");d.kind==="file"?l.has(b)&&h.push(d):ri(b,i,l,o)&&h.push(d)}return h}function ri(t,i,l,o,h){const d=h??new Set;if(d.has(t))return!1;d.add(t);const b=i[t];if(!b)return o.has(t);for(const y of b){const C=y.path.replace(/\\/g,"/");if(y.kind==="file"){if(l.has(C))return!0}else if(ri(C,i,l,o,d))return!0}return!1}export{qa as FileContextPanel};