@jingyi0605/codingns 0.9.6 → 0.9.8

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 (170) hide show
  1. package/dist/public/assets/{AdaptiveButlerPage-khJQh6a_.js → AdaptiveButlerPage-D-gXre7Y.js} +2 -2
  2. package/dist/public/assets/{App-CcDXqFl1.css → App-7zrCMhE-.css} +1 -1
  3. package/dist/public/assets/App-Dl-mcdqy.js +30 -0
  4. package/dist/public/assets/{BootstrapPage-DcfYtoLC.js → BootstrapPage-B-yMdfpQ.js} +1 -1
  5. package/dist/public/assets/ConversationPage-DRQ5Sg_d.js +9 -0
  6. package/dist/public/assets/{DesktopDetachPreviewPage-CXUPMcBz.js → DesktopDetachPreviewPage-D1DMaGcy.js} +1 -1
  7. package/dist/public/assets/{DesktopModal-bMdI1jEe.js → DesktopModal-BnfGW2gk.js} +1 -1
  8. package/dist/public/assets/DesktopWindowPage-2SWAi0xz.js +2 -0
  9. package/dist/public/assets/FileContextPanel-fbPuE9dO.js +1 -0
  10. package/dist/public/assets/GitSidebar-BkmesJJR.js +6 -0
  11. package/dist/public/assets/{MobileCreateSessionSheet-DWPBsEx8.js → MobileCreateSessionSheet-CEJcDBZJ.js} +1 -1
  12. package/dist/public/assets/{MobileSheet-BXvQPkxt.js → MobileSheet-rkn_CUOY.js} +1 -1
  13. package/dist/public/assets/{MobileTopHeaderFrame-vdYOyaaB.js → MobileTopHeaderFrame-CU0wsYSS.js} +1 -1
  14. package/dist/public/assets/MobileWorkspaceSwitcherHeader-idl8o1OB.js +1 -0
  15. package/dist/public/assets/{PluginAccessOverview-C77TeZTK.js → PluginAccessOverview-BBgM6tb0.js} +1 -1
  16. package/dist/public/assets/{PluginContainerPage-DdSwOCw-.js → PluginContainerPage-D-ly3i3H.js} +1 -1
  17. package/dist/public/assets/{PluginDetailPage-BK1yTzvO.js → PluginDetailPage-CWAHYyyG.js} +1 -1
  18. package/dist/public/assets/{PluginsListPage-DAAwSc6W.js → PluginsListPage-Cte3vBgR.js} +1 -1
  19. package/dist/public/assets/{RelayConnectEntryPage-4Yyo2p8b.js → RelayConnectEntryPage-sRJlstx9.js} +1 -1
  20. package/dist/public/assets/{ServerSettingsModal-C_DEisHs.js → ServerSettingsModal-BBft9KEC.js} +1 -1
  21. package/dist/public/assets/SessionIndexPage-CN7cEdl9.js +1 -0
  22. package/dist/public/assets/SettingsPage-BGT-YqG2.js +2 -0
  23. package/dist/public/assets/TerminalManagerPanel-6-ZJ8vGn.js +1 -0
  24. package/dist/public/assets/TerminalPage-CUXXQYU2.js +55 -0
  25. package/dist/public/assets/{TerminalRuntimeFallbackModal-KvG6k4AQ.js → TerminalRuntimeFallbackModal-zc3qqMKJ.js} +1 -1
  26. package/dist/public/assets/ToolFilesPage-QzsZyr0F.js +1 -0
  27. package/dist/public/assets/ToolGitPage-CXg4ncuT.js +1 -0
  28. package/dist/public/assets/ToolProcessesPage-BPsOsg4w.js +1 -0
  29. package/dist/public/assets/ToolsHomePage-D1n4FU1s.js +1 -0
  30. package/dist/public/assets/WorkbenchLandingPage-BaU_dXls.js +1 -0
  31. package/dist/public/assets/WorkbenchLayout-DViAJhHz.js +1027 -0
  32. package/dist/public/assets/{WorkbenchModal-xbx1o6MO.js → WorkbenchModal-DWsNm2B2.js} +1 -1
  33. package/dist/public/assets/WorkbenchShellRoute-BGfRqBUa.js +1 -0
  34. package/dist/public/assets/WorkbenchShellRoute-f2jWjHWu.css +1 -0
  35. package/dist/public/assets/WorkspaceDebugDetailPage-BX0zVSsI.js +1 -0
  36. package/dist/public/assets/WorkspaceDetailPage-Dx6JX4jx.js +1 -0
  37. package/dist/public/assets/WorkspaceHomePage-DQVJ042Z.js +1 -0
  38. package/dist/public/assets/{client-runtime-manager-Bwau7p1v.js → client-runtime-manager-D9VbgJZ_.js} +1 -1
  39. package/dist/public/assets/host-alias-0TfFnYxR.js +1 -0
  40. package/dist/public/assets/index-DREvg1Yu.css +1 -0
  41. package/dist/public/assets/index-FOhyOpGY.js +50 -0
  42. package/dist/public/assets/{login-direct-candidate-resolver-CKUQ07IA.js → login-direct-candidate-resolver-17wEvjhh.js} +1 -1
  43. package/dist/public/assets/peer-host-config-sync-vYkmqzNz.js +1 -0
  44. package/dist/public/assets/{plugin-permission-copy-DIVk5jNp.js → plugin-permission-copy-apDn8EWG.js} +1 -1
  45. package/dist/public/assets/{plugins-api-DHJVvPZw.js → plugins-api-CnZYRKoS.js} +1 -1
  46. package/dist/public/assets/{preferences-service-CyxxeBmS.js → preferences-service-PZlLLAWH.js} +1 -1
  47. package/dist/public/assets/relay-entry-DhHwflXl.js +1 -0
  48. package/dist/public/assets/styles-BhKoKfQ_.css +1 -0
  49. package/dist/public/assets/terminal-runtime-meta-2zvacxvM.js +1 -0
  50. package/dist/public/assets/{useRegisteredDebugTemplates-wCGD2SLW.js → useRegisteredDebugTemplates-CJ-o4tFl.js} +1 -1
  51. package/dist/public/assets/workbench-navigation-aqJ1ay4M.js +1 -0
  52. package/dist/public/index.html +2 -2
  53. package/dist/server/middlewares/auth-guard.js +1 -0
  54. package/dist/server/middlewares/auth-guard.js.map +1 -1
  55. package/dist/server/modules/peer-host/host-api-proxy-service.d.ts +9 -0
  56. package/dist/server/modules/peer-host/host-api-proxy-service.js +174 -0
  57. package/dist/server/modules/peer-host/host-api-proxy-service.js.map +1 -0
  58. package/dist/server/modules/peer-host/host-handshake-controller.d.ts +7 -0
  59. package/dist/server/modules/peer-host/host-handshake-controller.js +10 -0
  60. package/dist/server/modules/peer-host/host-handshake-controller.js.map +1 -0
  61. package/dist/server/modules/peer-host/host-handshake.d.ts +15 -0
  62. package/dist/server/modules/peer-host/host-handshake.js +20 -0
  63. package/dist/server/modules/peer-host/host-handshake.js.map +1 -0
  64. package/dist/server/modules/peer-host/host-ws-proxy-service.d.ts +14 -0
  65. package/dist/server/modules/peer-host/host-ws-proxy-service.js +256 -0
  66. package/dist/server/modules/peer-host/host-ws-proxy-service.js.map +1 -0
  67. package/dist/server/modules/peer-host/peer-host-controller.d.ts +55 -0
  68. package/dist/server/modules/peer-host/peer-host-controller.js +62 -0
  69. package/dist/server/modules/peer-host/peer-host-controller.js.map +1 -0
  70. package/dist/server/modules/peer-host/peer-host-service.d.ts +77 -0
  71. package/dist/server/modules/peer-host/peer-host-service.js +529 -0
  72. package/dist/server/modules/peer-host/peer-host-service.js.map +1 -0
  73. package/dist/server/modules/provider/provider-discovery-runtime.js +16 -1
  74. package/dist/server/modules/provider/provider-discovery-runtime.js.map +1 -1
  75. package/dist/server/modules/sessions/codex-app-server-helper-client.js +14 -0
  76. package/dist/server/modules/sessions/codex-app-server-helper-client.js.map +1 -1
  77. package/dist/server/modules/sessions/codex-app-server-helper-process.js +59 -0
  78. package/dist/server/modules/sessions/codex-app-server-helper-process.js.map +1 -1
  79. package/dist/server/modules/sessions/codex-session-title-generator.d.ts +19 -0
  80. package/dist/server/modules/sessions/codex-session-title-generator.js +308 -0
  81. package/dist/server/modules/sessions/codex-session-title-generator.js.map +1 -0
  82. package/dist/server/modules/sessions/session-history-service.d.ts +16 -0
  83. package/dist/server/modules/sessions/session-history-service.js +208 -12
  84. package/dist/server/modules/sessions/session-history-service.js.map +1 -1
  85. package/dist/server/modules/sessions/session-live-runtime-service.d.ts +6 -0
  86. package/dist/server/modules/sessions/session-live-runtime-service.js +181 -80
  87. package/dist/server/modules/sessions/session-live-runtime-service.js.map +1 -1
  88. package/dist/server/modules/sessions/session-title-utils.d.ts +3 -0
  89. package/dist/server/modules/sessions/session-title-utils.js +25 -0
  90. package/dist/server/modules/sessions/session-title-utils.js.map +1 -0
  91. package/dist/server/modules/sessions/workspace-office-mcp-config.d.ts +2 -1
  92. package/dist/server/modules/sessions/workspace-office-mcp-config.js +44 -3
  93. package/dist/server/modules/sessions/workspace-office-mcp-config.js.map +1 -1
  94. package/dist/server/modules/tasks/task-manager.d.ts +2 -1
  95. package/dist/server/modules/tasks/task-manager.js +3 -0
  96. package/dist/server/modules/tasks/task-manager.js.map +1 -1
  97. package/dist/server/modules/tasks/task-scheduler.d.ts +2 -1
  98. package/dist/server/modules/tasks/task-scheduler.js +21 -0
  99. package/dist/server/modules/tasks/task-scheduler.js.map +1 -1
  100. package/dist/server/modules/tasks/task-types.d.ts +6 -0
  101. package/dist/server/modules/tasks/task-types.js +1 -0
  102. package/dist/server/modules/tasks/task-types.js.map +1 -1
  103. package/dist/server/modules/workbench/workbench-controller.js +3 -2
  104. package/dist/server/modules/workbench/workbench-controller.js.map +1 -1
  105. package/dist/server/modules/workspace/affairs-library-service.d.ts +1 -0
  106. package/dist/server/modules/workspace/affairs-library-service.js +80 -0
  107. package/dist/server/modules/workspace/affairs-library-service.js.map +1 -1
  108. package/dist/server/modules/workspace/affairs-lightweight-session-service.js +13 -9
  109. package/dist/server/modules/workspace/affairs-lightweight-session-service.js.map +1 -1
  110. package/dist/server/routes/peer-hosts.d.ts +3 -0
  111. package/dist/server/routes/peer-hosts.js +18 -0
  112. package/dist/server/routes/peer-hosts.js.map +1 -0
  113. package/dist/server/routes/public.d.ts +2 -1
  114. package/dist/server/routes/public.js +2 -1
  115. package/dist/server/routes/public.js.map +1 -1
  116. package/dist/server/server/create-server.d.ts +4 -0
  117. package/dist/server/server/create-server.js +30 -2
  118. package/dist/server/server/create-server.js.map +1 -1
  119. package/dist/server/shared/http/error-handler.js +12 -0
  120. package/dist/server/shared/http/error-handler.js.map +1 -1
  121. package/dist/server/storage/repositories/peer-host-repository.d.ts +44 -0
  122. package/dist/server/storage/repositories/peer-host-repository.js +271 -0
  123. package/dist/server/storage/repositories/peer-host-repository.js.map +1 -0
  124. package/dist/server/storage/sqlite/client.js +81 -0
  125. package/dist/server/storage/sqlite/client.js.map +1 -1
  126. package/dist/server/storage/sqlite/schema.sql +64 -0
  127. package/dist/server/types/domain.d.ts +43 -0
  128. package/dist/server/ws/workbench-ws-hub.js +5 -14
  129. package/dist/server/ws/workbench-ws-hub.js.map +1 -1
  130. package/dist/server/ws/ws-server.d.ts +2 -1
  131. package/dist/server/ws/ws-server.js +5 -1
  132. package/dist/server/ws/ws-server.js.map +1 -1
  133. package/node_modules/@codingns/session-sync-core/dist/providers/codex.d.ts +7 -0
  134. package/node_modules/@codingns/session-sync-core/dist/providers/codex.js +623 -9
  135. package/node_modules/@codingns/session-sync-core/dist/providers/codex.js.map +1 -1
  136. package/node_modules/@codingns/session-sync-core/dist/runtime/active-run-registry.js +8 -1
  137. package/node_modules/@codingns/session-sync-core/dist/runtime/active-run-registry.js.map +1 -1
  138. package/node_modules/@codingns/session-sync-core/dist/runtime/codex-runtime.d.ts +4 -0
  139. package/node_modules/@codingns/session-sync-core/dist/runtime/codex-runtime.js +375 -15
  140. package/node_modules/@codingns/session-sync-core/dist/runtime/codex-runtime.js.map +1 -1
  141. package/node_modules/@codingns/session-sync-core/dist/types.d.ts +11 -0
  142. package/package.json +1 -1
  143. package/dist/public/assets/App-If9gThKM.js +0 -30
  144. package/dist/public/assets/ConversationPage-Bfb7GLTM.js +0 -9
  145. package/dist/public/assets/DesktopWindowPage-D1xwgS-7.js +0 -2
  146. package/dist/public/assets/FileContextPanel-C4syif3B.js +0 -1
  147. package/dist/public/assets/GitSidebar-DduL9aTV.js +0 -6
  148. package/dist/public/assets/MobileWorkspaceSwitcherHeader-DT330cAx.js +0 -1
  149. package/dist/public/assets/SessionIndexPage-DyMikN_x.js +0 -1
  150. package/dist/public/assets/SettingsPage-CDAVsPr3.js +0 -2
  151. package/dist/public/assets/TerminalManagerPanel-4OR47vcf.js +0 -1
  152. package/dist/public/assets/TerminalPage-Pvx396YX.js +0 -55
  153. package/dist/public/assets/ToolFilesPage-DrYHk0N-.js +0 -1
  154. package/dist/public/assets/ToolGitPage-Dz1q-Ns_.js +0 -1
  155. package/dist/public/assets/ToolProcessesPage-CRhphOmM.js +0 -1
  156. package/dist/public/assets/ToolsHomePage-BJSDLR6T.js +0 -1
  157. package/dist/public/assets/WorkbenchLandingPage-BlkxdOLC.js +0 -1
  158. package/dist/public/assets/WorkbenchLayout-D-U7ghT0.js +0 -1022
  159. package/dist/public/assets/WorkbenchShellRoute-DyWSCHz_.js +0 -1
  160. package/dist/public/assets/WorkbenchShellRoute-htbkGbtW.css +0 -1
  161. package/dist/public/assets/WorkspaceDebugDetailPage-B4ol2_a5.js +0 -1
  162. package/dist/public/assets/WorkspaceDetailPage-DMakfmHR.js +0 -1
  163. package/dist/public/assets/WorkspaceHomePage-tmCafatd.js +0 -1
  164. package/dist/public/assets/index-DmUJ8tIw.css +0 -1
  165. package/dist/public/assets/index-_OCkVmfl.js +0 -50
  166. package/dist/public/assets/relay-entry-B5GmiOrR.js +0 -1
  167. package/dist/public/assets/styles-DkbkRgWw.css +0 -1
  168. package/dist/public/assets/terminal-runtime-meta-DBsyT35T.js +0 -1
  169. package/dist/public/assets/workbench-navigation-RyUjchbD.js +0 -1
  170. /package/dist/public/assets/{styles-JKFlsYFv.js → styles-DwSuZo1w.js} +0 -0
@@ -0,0 +1 @@
1
+ import{b as c,F as nn,j as i,t as o,G as dt,B as ni}from"./index-FOhyOpGY.js";import{f as ii,e as Li,g as Bi}from"./App-Dl-mcdqy.js";import{bK as Wi,bL as Hi,bM as ai,bN as an,bO as $i,bP as Rt,bQ as Tt,b as Oi,u as Vi,Y as Fe,bR as Qt,bS as Ui,bT as zi,bU as Ki,bV as ft,bW as Ct,bX as qe,bY as Gi,bZ as Xi,b_ as qi,b$ as Ii,c0 as Yi}from"./WorkbenchLayout-DViAJhHz.js";import{d as Zi,M as Qi}from"./workbench-navigation-aqJ1ay4M.js";import{W as $n}from"./WorkbenchModal-DWsNm2B2.js";import"./window-BVUB8gMK.js";import"./event-DvH9tcej.js";import"./host-alias-0TfFnYxR.js";import"./DesktopModal-BnfGW2gk.js";import"./relay-entry-DhHwflXl.js";import"./MobileSheet-rkn_CUOY.js";async function Dt(t,n,l={}){const[s,h]=await Promise.all([Wi(n,{targetHostId:l.targetHostId}),Hi(t,{targetHostId:l.targetHostId})]);return Ji(s.changes,h.items)}function Ji(t,n){const l=new Set(n.map(s=>kt(s.path)));return t.filter(s=>l.has(kt(s.path))||s.oldPath!==null&&l.has(kt(s.oldPath)))}function ea(t){const n=On("","");for(const l of t){const s=kt(l.path),h=s.split("/").filter(Boolean);let m=n;h.forEach((b,g)=>{const D=h.slice(0,g+1).join("/");if(g===h.length-1){m.children.set(`file:${D}`,{kind:"file",name:b,path:s,change:l});return}const R=`directory:${D}`,T=m.children.get(R);if(T&&T.kind==="directory"){m=T;return}const xe=On(b,D);m.children.set(R,xe),m=xe})}return oi(ri([...n.children.values()]))}function li(t,n){const l=t.oldPath?`${t.oldPath} -> ${t.path}`:t.path;return rn(t)?`${l} ${n}`:l}function rn(t){return t.status==="D"||t.stagedStatus==="D"||t.worktreeStatus==="D"}function Et(t){return t.split("/").filter(Boolean).pop()??t}function kt(t){return t.replace(/\\/g,"/").replace(/^\.\//,"").trim()}function On(t,n){return{kind:"directory",name:t,path:n,children:new Map}}function ri(t){return[...t].sort((n,l)=>n.kind!==l.kind?n.kind==="directory"?-1:1:n.name.localeCompare(l.name,"zh-CN")).map(n=>n.kind==="directory"?{kind:"directory",name:n.name,path:n.path,children:ri([...n.children.values()])}:n)}function oi(t){return t.map(n=>{var b;if(n.kind!=="directory")return n;const l=oi(n.children);let s=n.name,h=n.path,m=l;for(;m.length===1&&((b=m[0])==null?void 0:b.kind)==="directory";){const g=m[0];s=`${s}/${g.name}`,h=g.path,m=g.children}return{kind:"directory",name:s,path:h,children:m}})}const ta=450,na=60*1e3,Vn=20,Un=16;function ia({sessionId:t,workspaceId:n,targetHostId:l,showSystemFiles:s,selectedPath:h,refreshVersion:m,onCountChange:b,onSelectFile:g,onOpenFile:D}){const[R,T]=c.useState("tree"),[xe,Q]=c.useState([]),[ge,G]=c.useState(!0),[Ne,v]=c.useState(!1),[ie,mt]=c.useState([]),k=c.useRef(null),Ft=ai(),{showToast:De}=ii();c.useEffect(()=>{const p=nn(Pt(n,t),na);T("tree"),Q(p??[]),G(p===null),v(!1),mt([]),k.current=null},[t,n]),c.useEffect(()=>{let p=!1;async function w(){G(!0);try{const y=await Dt(t,n,{targetHostId:l});p||(Q(y),dt(Pt(n,t),y))}catch(y){p||De({title:Jt(y,o("conversation.filePanelSessionLoadFailed")),tone:"error"})}finally{p||G(!1)}}return w(),()=>{p=!0}},[m,t,De,l,n]);async function Ee(){G(!0);try{const p=await Dt(t,n,{targetHostId:l});Q(p),dt(Pt(n,t),p)}catch(p){De({title:Jt(p,o("conversation.filePanelSessionLoadFailed")),tone:"error"})}finally{G(!1)}}async function E(){if(_.length!==0){v(!0);try{await $i(n,_.map(w=>w.path),{targetHostId:l});const p=await Dt(t,n,{targetHostId:l});Q(p),dt(Pt(n,t),p),De({title:o("conversation.filePanelSessionStageSuccess"),tone:"success"})}catch(p){De({title:Jt(p,o("git.stageFailed")),tone:"error"})}finally{v(!1)}}}function A(p){mt(w=>w.includes(p)?w.filter(y=>y!==p):[...w,p])}function X(p){const w=Date.now(),y=k.current;return k.current={filePath:p,timestamp:w},(y==null?void 0:y.filePath)===p&&w-y.timestamp<=ta}async function $(p,w){if(w&&X(p)){await D(p),k.current=null;return}w||(k.current=null),await g(p)}const ae=c.useMemo(()=>an(xe,p=>Et(p.path),s),[xe,s]),_=ae.filter(p=>!p.staged),Ae=ea(ae),le=new Set(ie);return c.useEffect(()=>{b==null||b(ae.length)},[b,ae.length]),i.jsxs(i.Fragment,{children:[i.jsxs("div",{className:"file-panel-session-toolbar",children:[i.jsxs("div",{className:"file-panel-view-modes",role:"tablist","aria-label":o("conversation.filePanelSessionViewLabel"),children:[i.jsx("button",{className:R==="tree"?"file-panel-view-button active":"file-panel-view-button",type:"button",role:"tab","aria-selected":R==="tree",onClick:()=>T("tree"),children:o("conversation.filePanelSessionTreeView")}),i.jsx("button",{className:R==="list"?"file-panel-view-button active":"file-panel-view-button",type:"button",role:"tab","aria-selected":R==="list",onClick:()=>T("list"),children:o("conversation.filePanelSessionListView")})]}),i.jsxs("div",{className:"file-panel-session-actions",children:[i.jsx("button",{className:"secondary-button",type:"button",onClick:()=>void Ee(),disabled:ge||Ne,children:o("conversation.filePanelRefresh")}),i.jsx("button",{className:"primary-button",type:"button",onClick:()=>void E(),disabled:Ne||_.length===0,children:o("conversation.filePanelSessionStageAll")})]})]}),i.jsxs("div",{className:"file-panel-session-summary",children:[i.jsx("span",{children:`${o("conversation.filePanelSessionSummary")} ${ae.length}`}),i.jsx("span",{children:`${o("conversation.filePanelSessionUnstagedSummary")} ${_.length}`})]}),i.jsx("div",{ref:Ft,className:"file-tree","data-scrollbar-autohide":"true",children:ge?i.jsx("p",{className:"file-tree-status status-text",children:o("conversation.filePanelSessionLoading")}):ae.length===0?i.jsx("p",{className:"file-tree-status status-text",children:o("conversation.filePanelSessionEmpty")}):R==="tree"?si({nodes:Ae,depth:0,collapsedPathSet:le,selectedPath:h,onToggleTreePath:A,onFileClick:$}):aa({items:ae,selectedPath:h,onFileClick:$})})]})}function si({nodes:t,depth:n,collapsedPathSet:l,selectedPath:s,onToggleTreePath:h,onFileClick:m}){return t.map(b=>{if(b.kind==="directory"){const g=!l.has(b.path);return i.jsxs("div",{className:"file-tree-node",children:[i.jsxs("button",{className:"file-tree-item",type:"button","data-kind":"directory","aria-expanded":g,style:{paddingInlineStart:`${Vn+n*Un}px`},onClick:()=>h(b.path),children:[i.jsx("span",{className:"file-tree-chevron","aria-hidden":"true",children:g?"v":">"}),i.jsx("span",{className:"file-tree-label",children:b.name})]}),g?i.jsx("div",{className:"file-tree-children",children:si({nodes:b.children,depth:n+1,collapsedPathSet:l,selectedPath:s,onToggleTreePath:h,onFileClick:m})}):null]},`session-directory:${b.path}`)}return i.jsx("div",{className:"file-tree-node",children:i.jsxs("button",{className:"file-tree-item is-session-change",type:"button","data-active":s===b.change.path,"data-kind":"file",style:{paddingInlineStart:`${Vn+n*Un}px`},onClick:()=>void m(b.change.path,!rn(b.change)),children:[i.jsx("span",{className:"file-tree-chevron is-hidden","aria-hidden":"true",children:">"}),i.jsx("span",{className:"git-tree-file-icon","data-kind":Tt(b.name),"aria-hidden":"true",children:Rt(b.name)}),i.jsxs("span",{className:"file-tree-label",children:[i.jsx("span",{className:"file-tree-name",children:b.name}),i.jsx("span",{className:"file-tree-path",children:li(b.change,o("conversation.filePanelSessionDeleted"))})]}),i.jsxs("span",{className:"file-session-item-meta",children:[i.jsx("span",{className:"file-session-badge","data-status":b.change.status,children:b.change.status}),i.jsx("span",{className:"file-session-badge subtle",children:b.change.staged?o("git.stagedLabel"):o("git.workingTreeLabel")})]})]})},`session-file:${b.path}`)})}function aa({items:t,selectedPath:n,onFileClick:l}){return t.map(s=>i.jsx("div",{className:"file-session-list-item",children:i.jsxs("button",{className:"file-session-list-button",type:"button","data-active":n===s.path,onClick:()=>void l(s.path,!rn(s)),children:[i.jsx("span",{className:"git-tree-file-icon","data-kind":Tt(Et(s.path)),"aria-hidden":"true",children:Rt(Et(s.path))}),i.jsxs("span",{className:"file-tree-label",children:[i.jsx("span",{className:"file-tree-name",children:Et(s.path)}),i.jsx("span",{className:"file-tree-path",children:li(s,o("conversation.filePanelSessionDeleted"))})]}),i.jsxs("span",{className:"file-session-item-meta",children:[i.jsx("span",{className:"file-session-badge","data-status":s.status,children:s.status}),i.jsx("span",{className:"file-session-badge subtle",children:s.staged?o("git.stagedLabel"):o("git.workingTreeLabel")})]})]})},`session-list:${s.path}`))}function Pt(t,n){return`file-panel.session-changes.${t}.${n}`}function Jt(t,n){return t instanceof ni?t.message:typeof t=="object"&&t&&"message"in t?String(t.message??n):n}const C="",la=450,ne=8,jt=4,ra=176,oa=120,sa=300*1e3,ca=60*1e3,zn=1600,ua=220,fa=20,da=16;function ha(){if(typeof document>"u")return;const t=document.querySelector(".workbench-modal-card.file-viewer-modal"),n=t==null?void 0:t.getBoundingClientRect();if(!(!n||n.width<=0||n.height<=0))return{width:Math.round(n.width),height:Math.round(n.height),minWidth:720,minHeight:480}}function rl({className:t,sessionId:n,workspaceId:l,hideHeading:s=!1,hideTabs:h=!1,externalRevealRequest:m=null,externalWindowMode:b=!1,workbenchShellOverrides:g}){var Bn,Wn;const D=Oi(),{navigationGroups:R,subscribeFileTree:T,requestFileTreeRefresh:xe,addFileTreeSnapshotListener:Q,subscribeGitSnapshot:ge,requestGitRefresh:G,addGitSnapshotListener:Ne,currentTargetHostId:v}={...D,...g},[ie,mt]=c.useState({}),[k,Ft]=c.useState([]),[De,Ee]=c.useState([]),[E,A]=c.useState(C),[X,$]=c.useState([]),[ae,_]=c.useState(null),[Ae,le]=c.useState(!1),[p,w]=c.useState(!1),[y,pt]=c.useState(!1),[Ye,Ze]=c.useState(!1),[L,Qe]=c.useState(""),[At,q]=c.useState(null),[bt,vt]=c.useState(!1),[re,Le]=c.useState(null),[O,Je]=c.useState("workspace"),[sn,ke]=c.useState(0),[cn,Lt]=c.useState(0),[et,J]=c.useState(!1),[tt,B]=c.useState(!1),[oe,V]=c.useState(null),[Ce,Be]=c.useState(null),[W,We]=c.useState(null),[P,Bt]=c.useState(null),[S,nt]=c.useState(null),[Wt,He]=c.useState(""),[un,fn]=c.useState([]),[ee,Ht]=c.useState(!1),[bi,se]=c.useState(null),dn=c.useId(),ce=c.useRef({}),I=c.useRef({}),F=c.useRef([]),te=c.useRef(C),it=c.useRef(!1),at=c.useRef(null),vi=ai(),hn=c.useRef(null),mn=c.useRef(null),$t=c.useRef(null),pn=c.useRef(null),bn=c.useRef(null),ue=c.useRef(0),fe=c.useRef(new Map),{showToast:j}=ii(),Pe=Li(),U=Vi(e=>e.showSystemFiles),$e=!!(n!=null&&n.trim()),vn=s&&Pe.isMobile;c.useEffect(()=>{Fe("file_panel.props",{sessionId:n,workspaceId:l,externalWindowMode:b})},[b,n,l]),c.useEffect(()=>{te.current=E},[E]);function Ot(e){Lt(e),!(!l||!n)&&dt(Qn(l,n),e)}async function yn(){if(!l||!n){Ot(0);return}const e=await Dt(n,l,{targetHostId:v}),a=an(e,r=>ft(r.path),U).length;Ot(a)}function Me(e){mt(a=>{const r=typeof e=="function"?e(a):e;return ce.current=r,r})}function Oe(e){Ft(a=>{const r=typeof e=="function"?e(a):e;return F.current=r,r})}c.useEffect(()=>{var f,d;if(Kt(),!l){Kt(),it.current=!1,ce.current={},I.current={},F.current=[],te.current=C,Me({}),Oe([]),Ee([]),A(C),Ze(!1),Qe(""),q(null),vt(!1),le(!1),Ht(!1),se(null),$([]),_(null),V(null),Be(null),We(null),nt(null),He("");return}it.current=!0;const e=nn(Zn(l),sa);Fe("file_panel.workspace_snapshot",{workspaceId:l,cached:!!e,cachedRootItems:((d=(f=e==null?void 0:e.treeCache)==null?void 0:f[C])==null?void 0:d.length)??0,cachedDirectoryCount:Object.keys((e==null?void 0:e.treeCache)??{}).length});const a=Ra((e==null?void 0:e.activeDirectoryPath)??C,(e==null?void 0:e.treeCache)??{}),r=Yn((e==null?void 0:e.expandedDirectories)??[],a),u=Nt((e==null?void 0:e.treeCache)??{},a,r);ce.current=u,I.current=Jn((e==null?void 0:e.treeRevisionByPath)??{},u),F.current=r,te.current=a,Me(u),Oe(r),Ee([]),A(a),le(!1),w(!1),Ze(!1),Qe(""),q(null),vt(!1),queueMicrotask(()=>{it.current=!1})},[l]),c.useEffect(()=>{if(!m||m.workspaceId!==l)return;const e=()=>{if(bn.current===m.requestId)return;bn.current=m.requestId,Je("workspace"),(m.openViewer?Ke(m.filePath):me(m.filePath)).catch(r=>{j({title:Z(r,o("conversation.filePanelOpenFailed")),tone:"error"})})};if(it.current){queueMicrotask(e);return}e()},[m,Ke,me,j,l]),c.useEffect(()=>{if(l)return Q(e=>{e.workspaceId!==l||!Gn(Kn(e),v)||(I.current={...I.current,[e.path]:typeof e.revision=="string"?e.revision:null},Me(a=>({...a,[e.path]:e.items})),e.path===C&&le(!1),Ee(a=>a.filter(r=>r!==e.path)),Sn(e.path,e.items))})},[Q,l]),c.useEffect(()=>()=>{Kt()},[]),c.useEffect(()=>{l&&T(l,tn(F.current,te.current),{knownRevisionByPath:I.current,targetHostId:v})},[E,v,k,T,l]),c.useEffect(()=>{$([]),_(null),Le(null),se(null),ke(0),J(!1),B(!1),V(null),Be(null),We(null),nt(null),He(""),at.current=null,ue.current+=1},[n]),c.useEffect(()=>{!$e&&O==="session"&&Je("workspace")},[O,$e]),c.useEffect(()=>{h&&O!=="workspace"&&Je("workspace")},[O,h]),c.useEffect(()=>{if(!et&&!tt&&!oe)return;function e(r){var x,N,be;if(!(r.target instanceof Node))return;const u=((x=hn.current)==null?void 0:x.contains(r.target))??!1,f=((N=mn.current)==null?void 0:N.contains(r.target))??!1,d=((be=$t.current)==null?void 0:be.contains(r.target))??!1;!u&&!f&&!d&&(J(!1),B(!1),V(null),Be(null))}function a(r){r.key==="Escape"&&(J(!1),B(!1),V(null),Be(null))}return document.addEventListener("pointerdown",e),document.addEventListener("keydown",a),()=>{document.removeEventListener("pointerdown",e),document.removeEventListener("keydown",a)}},[et,tt,oe]),c.useLayoutEffect(()=>{if(!oe||typeof window>"u"){Be(null);return}const e=oe;function a(){const u=$t.current;if(!u)return;const f=u.getBoundingClientRect();Be(Ca({x:e.positionX,y:e.positionY},{width:f.width||ra,height:f.height||u.scrollHeight||0},{width:window.innerWidth,height:window.innerHeight}))}a();const r=window.requestAnimationFrame(a);return window.addEventListener("resize",a),window.addEventListener("scroll",a,!0),()=>{window.cancelAnimationFrame(r),window.removeEventListener("resize",a),window.removeEventListener("scroll",a,!0)}},[oe]),c.useEffect(()=>{if(!l)return;const e=Yn(k,E),a=Nt(ie,E,e);dt(Zn(l),{treeCache:a,treeRevisionByPath:Jn(I.current,a),expandedDirectories:e,activeDirectoryPath:E})},[E,k,ie,l]),c.useEffect(()=>{if(it.current)return;const e=Nt(ie,E,k);_a(ie,e)||Me(e)},[E,k,ie]),c.useEffect(()=>{let e=!1;const a=(l==null?void 0:l.trim())??null;async function r(f){if(!a)return;const d=Qt(ce.current[C]??[],U),x=(f==null?void 0:f.silent)!==!0&&d.length===0;x&&le(!0),Fe("file_panel.load_root_tree.start",{sessionId:n,workspaceId:a,silent:(f==null?void 0:f.silent)===!0,cachedRootItems:d.length});try{const N=await zt(C,{force:!0});e||(Fe("file_panel.load_root_tree.end",{sessionId:n,workspaceId:a,itemCount:N.length}),Me(be=>({...Nt(be,te.current,F.current),[C]:N})))}catch(N){!e&&!ei(N)&&j({title:Z(N,o("conversation.filePanelLoadFailed")),tone:"error"})}finally{!e&&x&&le(!1)}}if(Qt(ce.current[C]??[],U).length>0){const f=window.setTimeout(()=>{a&&(T(a,tn(F.current,te.current),{knownRevisionByPath:I.current,targetHostId:v}),r({silent:!0}))},1500);return()=>{e=!0,window.clearTimeout(f)}}return r(),()=>{e=!0}},[n,U,j,l]),c.useEffect(()=>{if(!l||!n){Lt(0);return}const e=nn(Qn(l,n),ca);Fe("file_panel.session_change_count.snapshot",{sessionId:n,workspaceId:l,cached:e!==null,cachedCount:e}),Lt(e??0);let a=!1;return yn().catch(()=>{}),()=>{a=!0}},[n,sn,U,l]),c.useEffect(()=>{if(!l){fn([]);return}const e=l.trim();ge(e,{targetHostId:v}),G(e,{targetHostId:v})},[v,l,ge,G]),c.useEffect(()=>{if(!l)return;const e=l.trim();return Ne(a=>{var r;a.workspaceId!==e||!Gn(Kn(a),v)||fn(((r=a.status)==null?void 0:r.changes)??[])})},[Ne,l]);const yt=c.useMemo(()=>an(un,e=>ft(e.path),U),[un,U]),H=c.useMemo(()=>{const e=new Map,a=new Set;for(const r of yt){const u=r.path.replace(/\\/g,"/"),f=r.worktreeStatus??r.stagedStatus??r.status;e.set(u,f);const d=u.split("/");for(let x=1;x<d.length;x++)a.add(d.slice(0,x).join("/"))}return{statusByPath:e,changedDirs:a}},[yt]),Re=c.useMemo(()=>Ui(ie,U),[U,ie]),Te=c.useMemo(()=>At===null?null:Qt(At,U),[At,U]),Ve=Re[C]??[],de=Ye&&Te!==null,xt=c.useMemo(()=>ee?ln(Ve,Re,H.statusByPath,H.changedDirs):Ve,[H.changedDirs,H.statusByPath,Ve,ee,Re]),yi=c.useMemo(()=>de?(Te??[]).map(e=>K(e.path,e.kind)):ci(xt,Re,k,ee,H.statusByPath,H.changedDirs),[k,H.changedDirs,H.statusByPath,de,ee,Te,Re,xt]),he=((Bn=R.find(e=>e.workspace.id===l))==null?void 0:Bn.workspace)??null,M=In(X),Vt=(M==null?void 0:M.path)??null,je=(M==null?void 0:M.kind)==="file"?M.path:null,gt=c.useMemo(()=>new Set(X.map(e=>e.path)),[X]),lt=c.useMemo(()=>St(X),[X]),Ut=!!(he!=null&&he.path&&X.length===1&&Vt),xn=X.length===1&&(M==null?void 0:M.kind)==="file",gn=lt.length>0,_e=lt.length>0,rt=!!(P!=null&&P.items.length&&l),Cn=!!l&&X.length===1&&M!==null,Pn=!!((je?ye(je):E)&&k.length),jn=P?P.mode==="copy"?o("conversation.filePanelClipboardCopyReady",{count:P.items.length}):o("conversation.filePanelClipboardCutReady",{count:P.items.length}):null,z=S?Sa(S):null;async function wn(e,a=!1){if(!l)return[];if(!a){const r=ce.current[e];if(r)return r}e===C?le(!0):Ee(r=>Mt(r,e));try{const r=await zt(e,{force:a});return Me(u=>({...u,[e]:r})),r}catch(r){throw ei(r)||j({title:Z(r,o("conversation.filePanelLoadFailed")),tone:"error"}),r}finally{e===C?le(!1):Ee(r=>r.filter(u=>u!==e))}}async function we(e){if(!l)return;const a=(e==null?void 0:e.activeDirectoryPath)??te.current,r=(e==null?void 0:e.expandedDirectories)??F.current,u=Ta(ce.current,a,r);Fe("file_panel.refresh_tree_cache.start",{sessionId:n,workspaceId:l,targetDirectories:u});const d=(await Promise.all(u.map(async x=>{const N=await zt(x,{force:!0});return[x,N]}))).reduce((x,[N,be])=>(x[N]=be,x),{});Fe("file_panel.refresh_tree_cache.end",{sessionId:n,workspaceId:l,targetDirectories:u,directoryCount:Object.keys(d).length}),Me(d)}async function zt(e,a){if(!l)return[];if(!(a!=null&&a.force)){const d=ce.current[e];if(d)return d}const r=tn(Mt(F.current,e),e||te.current);T(l,r,{knownRevisionByPath:I.current,targetHostId:v}),xe(l,[e],{knownRevisionByPath:I.current,targetHostId:v});const u=xi(e,zn,{allowCached:(a==null?void 0:a.force)!==!0}),f=Fa(ua).then(async()=>{if(!l)return[];const x=(await Ii(l,e||void 0,{targetHostId:v})).items;return I.current={...I.current,[e]:null},Sn(e,x),x});try{return await Promise.race([u,f])}catch(d){if(!mi(d))throw d;return await f}}function xi(e,a=zn,r){const u=ce.current[e];return(r==null?void 0:r.allowCached)!==!1&&u?Promise.resolve(u):new Promise((f,d)=>{const x=window.setTimeout(()=>{gi(e,x),d(new Error(`FILE_TREE_SNAPSHOT_TIMEOUT:${e}`))},a),N=fe.current.get(e)??[];fe.current.set(e,[...N,{resolve:f,reject:d,timerId:x}])})}function Sn(e,a){const r=fe.current.get(e)??[];r.length!==0&&(fe.current.delete(e),r.forEach(u=>{window.clearTimeout(u.timerId),u.resolve(a)}))}function gi(e,a){const u=(fe.current.get(e)??[]).filter(f=>f.timerId!==a);if(u.length===0){fe.current.delete(e);return}fe.current.set(e,u)}function Kt(){for(const[e,a]of fe.current.entries())a.forEach(r=>{window.clearTimeout(r.timerId),r.reject(new Error(`FILE_TREE_ABORTED:${e}`))});fe.current.clear()}function Ue(e){$([e]),_(e.path)}function ot(e){A(e.kind==="directory"?e.path:ye(e.path))}function Ci(e){const a=ba(yi,ae,e);$(a),_(e.path),ot(e)}function Pi(e){const a=pa(X,e),r=In(a);$(a),_(e.path),r&&ot(r)}function Nn(e){Ue(e),ot(e)}function ze(e,a){if(a!=null&&a.shiftKey){Ci(e);return}if(wt(a)){Pi(e);return}Nn(e)}async function st(e,a=!1){const r=ht(e,a);if(!r.length){A(C);return}Oe(u=>hi(u,r)),A(r[r.length-1]??C);for(const u of r)try{await wn(u)}catch{return}}async function me(e){const a=K(e,"file");Ue(a),ot(a),await st(e)}async function Ke(e){Le(e),se(null),at.current=null,ue.current+=1,me(e),await ji(e)}async function ji(e){const a=ue.current,r=e.replace(/\\/g,"/"),u=H.statusByPath.get(r);if(l&&u&&u!=="?"&&u!=="D")try{const f=await zi(l,e,!1,{targetHostId:v});ue.current===a&&se(f.content||null)}catch{ue.current===a&&se(null)}}async function wi(e){if(!l)return;const a=ha(),r=await Gi(Pe,{workspaceId:l,workspaceName:(he==null?void 0:he.name)??null,sessionId:n??null,filePath:e,bounds:a});if(!r.ok){j({title:r.detail??o("conversation.fileViewerOpenInWindowFailed"),tone:"error"});return}ue.current+=1,Le(null),se(null)}function Dn(e){const a=Date.now(),r=at.current;return at.current={filePath:e,timestamp:a},(r==null?void 0:r.filePath)===e&&a-r.timestamp<=la}function Se(){at.current=null}async function Si(e,a){const r=K(e,"file");if(a!=null&&a.shiftKey||wt(a)){Se(),ze(r,a);return}if(Dn(e)){await Ke(e);return}ze(r,a),await st(e)}function En(){Ze(!1),Qe(""),q(null),Se()}async function Ni(e,a){const r=K(e.path,e.kind);if(a!=null&&a.shiftKey||wt(a)){Se(),ze(r,a);return}if(e.kind==="directory"){En(),ze(r,a),await kn(e.path);return}if(Dn(e.path)){En(),await Ke(e.path);return}await me(e.path)}async function kn(e){if(Ue(K(e,"directory")),A(e),!F.current.includes(e))try{await wn(e),Oe(a=>Mt(a,e))}catch{}}async function Mn(e){if(Ue(K(e,"directory")),A(e),F.current.includes(e)){Rn(e);return}await kn(e)}function Rn(e){Oe(a=>a.filter(r=>r!==e&&!r.startsWith(`${e}/`))),A(ye(e)),$([]),_(null)}async function Tn(){if(!l)return;const e=l;try{if(G(e,{targetHostId:v}),await we(),je&&await st(je),de&&L.trim()){const a=await qe(e,L.trim(),1,20,{targetHostId:v});q(a.items)}if($e&&n)if(O==="session")ke(a=>a+1);else try{await yn()}catch(a){j({title:Z(a,o("conversation.filePanelSessionLoadFailed")),tone:"error"})}}catch(a){j({title:Z(a,o("conversation.filePanelLoadFailed")),tone:"error"})}}async function Di(e){if(e==null||e.preventDefault(),!l||!L.trim()){q(null);return}vt(!0);try{const a=await qe(l,L.trim(),1,20,{targetHostId:v});q(a.items)}catch(a){j({title:Z(a,o("conversation.filePanelSearchFailed")),tone:"error"})}finally{vt(!1)}}function _n(){if(Ye){Ze(!1),Qe(""),q(null);return}Ze(!0)}function Y(e){B(!1),e()}function Fn(){var e;(e=pn.current)==null||e.click()}async function Ei(e){var d;const a=((d=e.target.files)==null?void 0:d[0])??null;if(e.target.value="",!a||!l)return;const r=ma(a.name);if(!r){j({title:o("conversation.filePanelUploadFailed"),tone:"error"});return}const u=Xn(E,M),f=qn(u,r);pt(!0);try{const x=await Na(a);await Xi({workspaceId:l,path:f,contentBase64:x},{targetHostId:v}),await we(),await me(f),j({title:o("conversation.filePanelUploadSuccess",{name:r}),tone:"success"})}catch(x){j({title:Z(x,o("conversation.filePanelUploadFailed")),tone:"error"})}finally{pt(!1)}}async function Gt(e=je){if(!(!l||!e)){pt(!0);try{const a=await qi(l,e,{targetHostId:v}),r=Da(a.contentBase64);Ea(a.fileName,new Blob([r],{type:"application/octet-stream"})),j({title:o("conversation.filePanelDownloadSuccess",{name:a.fileName}),tone:"success"})}catch(a){j({title:Z(a,o("conversation.filePanelDownloadFailed")),tone:"error"})}finally{pt(!1)}}}function An(){const e=je?ye(je):E;!e||!F.current.includes(e)||Rn(e)}function Xt(){nt(null),He("")}function qt(){p||Xt()}function Ge(e,a=Xn(E,M)){if(!l)return;const r=a,u=r?`${r}/`:"";J(!1),B(!1),V(null),nt({mode:e,baseDirectory:r}),He(u)}function It(e=M){!l||!e||(J(!1),B(!1),V(null),nt({mode:"rename",target:e}),He(e.path))}async function ki(e){if(e==null||e.preventDefault(),!l||!S)return;const a=(Wt??"").trim();if(a){if(S.mode==="rename"&&Ie(S.target.path)===Ie(a)){qt();return}w(!0);try{if(S.mode==="rename"){const r=S.target.path,u=K(a,S.target.kind),f=re?di(re,r,a):null;if(await Ct({workspaceId:l,opType:"rename",srcPath:r,dstPath:a},{targetHostId:v}),P&&Bt({...P,items:wa(P.items,r,a)}),Xt(),Se(),await we(),S.target.kind==="directory"?(await st(a,!0),Ue(u),A(a)):await me(a),f!==re&&(ue.current+=1,Le(f),se(null)),de&&L.trim()){const d=await qe(l,L.trim(),1,20,{targetHostId:v});q(d.items)}ke(d=>d+1),j({title:o("conversation.filePanelRenameSuccess",{name:ft(a)||a}),tone:"success"});return}if(await Ct({workspaceId:l,opType:S.mode,dstPath:a,content:S.mode==="create_file"?"":void 0},{targetHostId:v}),Xt(),await we(),S.mode==="create_directory"?(await st(a,!0),Ue(K(a,"directory")),A(a)):await me(a),de&&L.trim()){const r=await qe(l,L.trim(),1,20,{targetHostId:v});q(r.items)}ke(r=>r+1)}catch(r){j({title:Z(r,o("conversation.filePanelMutateFailed")),tone:"error"})}finally{w(!1)}}}function pe(e,a=lt){var u;if(a.length===0)return;const r=St(a);Bt({mode:e,items:r}),$(r),_(((u=r[r.length-1])==null?void 0:u.path)??null),j({title:e==="copy"?o("conversation.filePanelCopySelectionSuccess",{count:r.length}):o("conversation.filePanelCutSelectionSuccess",{count:r.length}),tone:"success"}),V(null)}async function ct(e=xa(M,E)){if(!l||!P||!P.items.length)return;const a=e??C,r=P.items.map(u=>({source:u,destinationPath:qn(a,ft(u.path)||u.path)}));w(!0);try{for(const d of r)P.mode==="cut"&&Ie(d.source.path)===Ie(d.destinationPath)||await Ct({workspaceId:l,opType:P.mode==="copy"?"copy":"move",srcPath:d.source.path,dstPath:d.destinationPath},{targetHostId:v});const u=r.map(d=>K(d.destinationPath,d.source.kind)),f=u[u.length-1]??null;if(P.mode==="cut"&&Bt(null),$(u),_((f==null?void 0:f.path)??null),f&&ot(f),Se(),await we({activeDirectoryPath:(f==null?void 0:f.kind)==="directory"?f.path:f?ye(f.path):te.current,expandedDirectories:F.current}),de&&L.trim()){const d=await qe(l,L.trim(),1,20,{targetHostId:v});q(d.items)}ke(d=>d+1),j({title:o("conversation.filePanelPasteSuccess",{count:u.length}),tone:"success"}),V(null)}catch(u){await we().catch(()=>{}),j({title:Z(u,o("conversation.filePanelPasteFailed")),tone:"error"})}finally{w(!1)}}function Yt(e=lt){!e.length||p||(We(St(e)),V(null))}async function Mi(){var a,r;if(!l||!(W!=null&&W.length))return;const e=St(W);w(!0);try{for(const d of e)await Ct({workspaceId:l,opType:"delete",srcPath:d.path},{targetHostId:v});const u=ga(E,e),f=F.current.filter(d=>!e.some(x=>x.kind==="directory"&&_t(x.path,d)));if(re&&e.some(d=>_t(d.path,re))&&(ue.current+=1,Le(null),se(null)),We(null),$([]),_(null),te.current=u,F.current=f,A(u),Oe(f),Se(),await we({activeDirectoryPath:u,expandedDirectories:f}),de&&L.trim()){const d=await qe(l,L.trim(),1,20,{targetHostId:v});q(d.items)}ke(d=>d+1),j({title:e.length===1?o("conversation.filePanelDeleteSuccess",{name:ft(((a=e[0])==null?void 0:a.path)??"")||((r=e[0])==null?void 0:r.path)||""}):o("conversation.filePanelDeleteSelectionSuccess",{count:e.length}),tone:"success"})}catch(u){j({title:Z(u,o("conversation.filePanelMutateFailed")),tone:"error"})}finally{w(!1)}}async function Xe(e,a=M){const r=(he==null?void 0:he.path)??"",u=(a==null?void 0:a.path)??null;if(u===null||!r){J(!1);return}try{const f=ja(r),d=e==="absolute"?Pa(r,u,f):Ie(u,f);await ka(d,Pe),j({title:e==="absolute"?o("conversation.filePanelCopyAbsolutePathSuccess"):o("conversation.filePanelCopyRelativePathSuccess"),tone:"success"})}catch(f){j({title:f instanceof Error?f.message:o("conversation.filePanelCopyPathFailed"),tone:"error"})}finally{J(!1),V(null)}}function Ri(e,a,r){return[{id:`open-${e.path}`,label:e.kind==="directory"?k.includes(e.path)?o("conversation.filePanelCollapseDirectory"):o("conversation.filePanelExpandDirectory"):o("conversation.filePanelOpenFile"),onSelect:()=>{if(e.kind==="directory"){Mn(e.path);return}Ke(e.path)}},{id:`download-${e.path}`,label:o("conversation.filePanelDownload"),disabled:e.kind!=="file"||y,onSelect:()=>{Gt(e.kind==="file"?e.path:null)}},{id:`create-file-${e.path}`,label:o("conversation.filePanelNewFile"),disabled:!l||p||y,onSelect:()=>{Ge("create_file",r)}},{id:`create-directory-${e.path}`,label:o("conversation.filePanelNewDirectory"),disabled:!l||p||y,onSelect:()=>{Ge("create_directory",r)}},{id:`rename-${e.path}`,label:o("conversation.filePanelRenameMove"),disabled:a.length!==1||p||y,onSelect:()=>It(e)},{id:`copy-${e.path}`,label:o("conversation.filePanelCopy"),disabled:a.length===0,onSelect:()=>pe("copy",a)},{id:`cut-${e.path}`,label:o("conversation.filePanelCut"),disabled:a.length===0,onSelect:()=>pe("cut",a)},{id:`paste-${e.path}`,label:o("conversation.filePanelPaste"),disabled:!rt,onSelect:()=>{ct(r)}},{id:`copy-relative-${e.path}`,label:o("conversation.filePanelCopyRelativePath"),onSelect:()=>{Xe("relative",e)}},{id:`copy-absolute-${e.path}`,label:o("conversation.filePanelCopyAbsolutePath"),onSelect:()=>{Xe("absolute",e)}},{id:`delete-${e.path}`,label:o("conversation.filePanelDelete"),disabled:a.length===0||p||y,onSelect:()=>Yt(a)}]}async function Ln(e,a){if(Pe.isMobile)return;e.preventDefault();const r=K(a.path,a.kind),u=gt.has(r.path)?lt:[r],f=r.kind==="directory"?r.path:ye(r.path);gt.has(r.path)||Nn(r);const d=Ri(r,u,f);if(Pe.isDesktop){await Yi(d);return}Pe.isWeb&&(J(!1),B(!1),V({positionX:e.clientX,positionY:e.clientY,items:d}))}c.useEffect(()=>{if(O!=="workspace")return;function e(a){if(!va(a)||a.altKey||a.shiftKey||ya(a.target))return;const r=a.key.toLowerCase();if(r==="c"&&_e){a.preventDefault(),pe("copy");return}if(r==="x"&&_e){a.preventDefault(),pe("cut");return}r==="v"&&rt&&(a.preventDefault(),ct())}return document.addEventListener("keydown",e),()=>{document.removeEventListener("keydown",e)}},[O,_e,rt,pe,ct]);function Zt(e,a){return i.jsx(i.Fragment,{children:e.map(r=>{const u=K(r.path,r.kind),f=r.kind==="directory",d=f&&k.includes(r.path),x=f&&De.includes(r.path),N=Re[r.path]??[],be=ee?ln(N,Re,H.statusByPath,H.changedDirs):N,_i=gt.has(r.path),Fi=Vt===r.path,ut=H.statusByPath.get(r.path.replace(/\\/g,"/")),Hn=f&&H.changedDirs.has(r.path.replace(/\\/g,"/")),Ai=(P==null?void 0:P.mode)==="cut"&&P.items.some(ve=>ve.path===r.path);return i.jsxs("div",{className:"file-tree-node",children:[i.jsxs("button",{className:"file-tree-item",type:"button","data-active":Fi,"data-selected":_i,"data-cut-pending":Ai||void 0,"data-kind":r.kind,"aria-expanded":f?d:void 0,style:{paddingInlineStart:`${fa+a*da}px`},onClick:ve=>{if(f){if(ve.shiftKey||wt(ve)){Se(),ze(u,ve);return}Se(),ze(u,ve),Mn(r.path);return}Si(r.path,ve)},onContextMenu:ve=>{Ln(ve,r)},children:[i.jsx("span",{className:`file-tree-chevron${f?"":" is-hidden"}`,"aria-hidden":"true",children:d?"v":">"}),f?null:i.jsx("span",{className:"git-tree-file-icon","data-kind":Tt(r.name),"aria-hidden":"true",children:Rt(r.name)}),i.jsx("span",{className:"file-tree-label","data-status":ut??void 0,"data-has-changes":Hn||void 0,children:r.name}),!f&&ut?i.jsx("span",{className:"git-status-badge","data-status":ut,"aria-label":ut,children:ut}):null,f&&Hn?i.jsx("span",{className:"file-tree-dir-badge","aria-hidden":"true"}):null,x?i.jsx("span",{className:"file-tree-meta",children:o("common.loading")}):null]}),f&&d?i.jsx("div",{className:"file-tree-children",children:x&&!N.length?i.jsx("p",{className:"file-tree-empty",children:o("common.loading")}):be.length?Zt(be,a+1):i.jsx("p",{className:"file-tree-empty",children:o("conversation.filePanelEmptyDirectory")})}):null]},`${r.kind}-${r.path}`)})})}function Ti(e){return i.jsx(i.Fragment,{children:e.map(a=>{const r=a.kind==="directory",u=gt.has(a.path),f=Vt===a.path;return i.jsx("div",{className:"file-tree-node",children:i.jsxs("button",{className:"file-tree-item is-search-result",type:"button","data-active":f,"data-selected":u,"data-kind":a.kind,onClick:d=>{Ni(a,d)},onContextMenu:d=>{Ln(d,a)},children:[i.jsx("span",{className:"file-tree-chevron is-hidden","aria-hidden":"true",children:">"}),r?null:i.jsx("span",{className:"git-tree-file-icon","data-kind":Tt(a.name),"aria-hidden":"true",children:Rt(a.name)}),i.jsxs("span",{className:"file-tree-label",children:[i.jsx("span",{className:"file-tree-name",children:a.name}),i.jsx("span",{className:"file-tree-path",children:a.path})]})]})},`search-${a.kind}-${a.path}`)})})}return i.jsx("section",{className:["conversation-panel","surface-card","file-panel",t].filter(Boolean).join(" "),"data-testid":"file-context-panel",children:l?i.jsxs(i.Fragment,{children:[i.jsx(Ki,{workspaceId:l,filePath:re,open:re!==null,onClose:()=>{ue.current+=1,Le(null),se(null)},onSaved:async e=>{await we(),await me(e),ke(a=>a+1)},diffContent:bi,showDetachAction:Pe.isDesktop&&Pe.bridge.supported,onDetach:()=>{re&&wi(re)}}),s?null:i.jsx("div",{className:"file-panel-heading-row",children:i.jsx("h2",{className:"file-panel-heading",children:o("conversation.filePanelTitle")})}),h?null:i.jsxs("div",{className:"file-panel-tabs",role:"tablist","aria-label":o("conversation.filePanelTitle"),children:[i.jsx("button",{className:O==="workspace"?"file-panel-tab active":"file-panel-tab",type:"button",role:"tab","aria-selected":O==="workspace",onClick:()=>Je("workspace"),children:o("conversation.filePanelWorkspaceTab")}),i.jsxs("button",{className:O==="session"?"file-panel-tab active":"file-panel-tab",type:"button",role:"tab","aria-selected":O==="session",onClick:()=>{$e&&Je("session")},disabled:!$e,children:[o("conversation.filePanelSessionTab"),i.jsx("span",{className:"file-panel-tab-badge","aria-label":`${o("conversation.filePanelSessionTab")} ${cn}`,children:cn})]})]}),O==="workspace"?i.jsxs(i.Fragment,{children:[i.jsx("input",{ref:pn,"data-testid":"file-panel-upload-input",type:"file",hidden:!0,onChange:e=>void Ei(e)}),vn?i.jsx("div",{className:"file-panel-toolbar file-panel-toolbar-mobile","aria-label":o("conversation.filePanelTitle"),children:i.jsxs("div",{className:"file-mobile-action-shell",ref:mn,children:[i.jsxs("button",{className:"secondary-button file-mobile-action-trigger",type:"button","aria-label":o("conversation.filePanelActionsMenu"),"aria-haspopup":"menu","aria-expanded":tt,"data-active":tt,onClick:()=>{J(!1),B(e=>!e)},children:[i.jsx("span",{children:o("conversation.filePanelActionsMenu")}),i.jsx(Xa,{})]}),tt?i.jsxs("div",{className:"file-mobile-action-menu",role:"menu","aria-label":o("conversation.filePanelActionsMenu"),children:[i.jsx("button",{className:"file-mobile-action-menu-item",type:"button",role:"menuitem",onClick:()=>Y(()=>pe("copy")),disabled:!_e,children:o("conversation.filePanelCopy")}),i.jsx("button",{className:"file-mobile-action-menu-item",type:"button",role:"menuitem",onClick:()=>Y(()=>pe("cut")),disabled:!_e,children:o("conversation.filePanelCut")}),i.jsx("button",{className:"file-mobile-action-menu-item",type:"button",role:"menuitem",onClick:()=>Y(()=>ct()),disabled:!rt||p||y,children:o("conversation.filePanelPaste")}),i.jsx("button",{className:"file-mobile-action-menu-item",type:"button",role:"menuitem",onClick:()=>{B(!1),_n()},children:Ye?o("conversation.filePanelHideSearch"):o("conversation.filePanelShowSearch")}),i.jsx("button",{className:"file-mobile-action-menu-item",type:"button",role:"menuitem",onClick:()=>{B(!1),Ht(e=>!e)},disabled:yt.length===0,children:ee?o("conversation.filePanelShowAll"):o("conversation.filePanelFilterChanges")}),i.jsx("button",{className:"file-mobile-action-menu-item",type:"button",role:"menuitem",onClick:()=>Y(Tn),disabled:Ae||p||bt,children:o("conversation.filePanelRefresh")}),i.jsx("button",{className:"file-mobile-action-menu-item",type:"button",role:"menuitem",onClick:()=>{B(!1),An()},disabled:!Pn,children:o("conversation.filePanelCollapseCurrent")}),i.jsx("button",{className:"file-mobile-action-menu-item",type:"button",role:"menuitem",onClick:()=>{B(!1),Fn()},disabled:p||y,children:o("conversation.filePanelUpload")}),i.jsx("button",{className:"file-mobile-action-menu-item",type:"button",role:"menuitem",onClick:()=>Y(Gt),disabled:!xn||y,children:o("conversation.filePanelDownload")}),i.jsx("button",{className:"file-mobile-action-menu-item",type:"button",role:"menuitem",onClick:()=>Y(It),disabled:!Cn||p||y,children:o("conversation.filePanelRenameMove")}),i.jsx("button",{className:"file-mobile-action-menu-item danger",type:"button",role:"menuitem",onClick:()=>Y(Yt),disabled:!gn||p||y,children:o("conversation.filePanelDelete")}),i.jsx("button",{className:"file-mobile-action-menu-item",type:"button",role:"menuitem",onClick:()=>Y(()=>Ge("create_file")),disabled:p||y,children:o("conversation.filePanelNewFile")}),i.jsx("button",{className:"file-mobile-action-menu-item",type:"button",role:"menuitem",onClick:()=>Y(()=>Ge("create_directory")),disabled:p||y,children:o("conversation.filePanelNewDirectory")}),i.jsx("button",{className:"file-mobile-action-menu-item",type:"button",role:"menuitem",onClick:()=>Y(()=>Xe("absolute")),disabled:!Ut,children:o("conversation.filePanelCopyAbsolutePath")}),i.jsx("button",{className:"file-mobile-action-menu-item",type:"button",role:"menuitem",onClick:()=>Y(()=>Xe("relative")),disabled:!Ut,children:o("conversation.filePanelCopyRelativePath")})]}):null]})}):i.jsxs("div",{className:"file-panel-toolbar","aria-label":o("conversation.filePanelTitle"),children:[i.jsx("button",{className:"file-toolbar-button",type:"button",title:o("conversation.filePanelCopy"),"aria-label":o("conversation.filePanelCopy"),onClick:()=>pe("copy"),disabled:!_e,children:i.jsx(Wa,{})}),i.jsx("button",{className:"file-toolbar-button",type:"button",title:o("conversation.filePanelCut"),"aria-label":o("conversation.filePanelCut"),onClick:()=>pe("cut"),disabled:!_e,children:i.jsx(Ha,{})}),i.jsx("button",{className:"file-toolbar-button",type:"button",title:o("conversation.filePanelPaste"),"aria-label":o("conversation.filePanelPaste"),onClick:()=>void ct(),disabled:!rt||p||y,children:i.jsx($a,{})}),i.jsxs("div",{className:"file-toolbar-menu-shell",ref:hn,children:[i.jsx("button",{className:"file-toolbar-button",type:"button",title:o("conversation.filePanelCopyPath"),"aria-label":o("conversation.filePanelCopyPath"),"aria-haspopup":"menu","aria-expanded":et,"data-active":et,onClick:()=>{B(!1),J(e=>!e)},disabled:!Ut,children:i.jsx(Ba,{})}),et?i.jsxs("div",{className:"file-toolbar-menu",role:"menu",children:[i.jsx("button",{className:"file-toolbar-menu-item",type:"button",role:"menuitem",onClick:()=>void Xe("absolute"),children:o("conversation.filePanelCopyAbsolutePath")}),i.jsx("button",{className:"file-toolbar-menu-item",type:"button",role:"menuitem",onClick:()=>void Xe("relative"),children:o("conversation.filePanelCopyRelativePath")})]}):null]}),i.jsx("button",{className:"file-toolbar-button",type:"button",title:o("conversation.filePanelCollapseCurrent"),"aria-label":o("conversation.filePanelCollapseCurrent"),onClick:An,disabled:!Pn,children:i.jsx(Aa,{})}),i.jsx("button",{className:"file-toolbar-button",type:"button",title:o("conversation.filePanelRefresh"),"aria-label":o("conversation.filePanelRefresh"),onClick:()=>void Tn(),disabled:Ae||p||bt,children:i.jsx(La,{})}),i.jsx("button",{className:"file-toolbar-button",type:"button",title:o("conversation.filePanelSearchButton"),"aria-label":o("conversation.filePanelSearchButton"),"data-active":Ye,onClick:_n,disabled:Ae,children:i.jsx(ti,{})}),yt.length>0?i.jsx("button",{className:"file-toolbar-button",type:"button",title:ee?o("conversation.filePanelShowAll"):o("conversation.filePanelFilterChanges"),"aria-label":ee?o("conversation.filePanelShowAll"):o("conversation.filePanelFilterChanges"),"data-active":ee,onClick:()=>Ht(e=>!e),children:i.jsx(qa,{})}):null,i.jsx("button",{className:"file-toolbar-button",type:"button",title:o("conversation.filePanelUpload"),"aria-label":o("conversation.filePanelUpload"),onClick:Fn,disabled:p||y,children:i.jsx(Va,{})}),i.jsx("button",{className:"file-toolbar-button",type:"button",title:o("conversation.filePanelDownload"),"aria-label":o("conversation.filePanelDownload"),onClick:()=>void Gt(),disabled:!xn||y,children:i.jsx(Ua,{})}),i.jsx("button",{className:"file-toolbar-button",type:"button",title:o("conversation.filePanelRenameMove"),"aria-label":o("conversation.filePanelRenameMove"),onClick:()=>It(),disabled:!Cn||p||y,children:i.jsx(Ga,{})}),i.jsx("button",{className:"file-toolbar-button danger",type:"button",title:o("conversation.filePanelDelete"),"aria-label":o("conversation.filePanelDelete"),onClick:()=>Yt(),disabled:!gn||p||y,children:i.jsx(za,{})}),i.jsx("button",{className:"file-toolbar-button",type:"button",title:o("conversation.filePanelNewFile"),"aria-label":o("conversation.filePanelNewFile"),onClick:()=>void Ge("create_file"),disabled:p||y,children:i.jsx(Oa,{})}),i.jsx("button",{className:"file-toolbar-button",type:"button",title:o("conversation.filePanelNewDirectory"),"aria-label":o("conversation.filePanelNewDirectory"),onClick:()=>void Ge("create_directory"),disabled:p||y,children:i.jsx(Ka,{})})]}),oe&&typeof document<"u"?Bi.createPortal(i.jsx("div",{className:"file-web-context-menu",ref:$t,role:"menu","aria-label":o("conversation.filePanelActionsMenu"),style:{left:`${(Ce==null?void 0:Ce.left)??Math.max(8,oe.positionX)}px`,top:`${(Ce==null?void 0:Ce.top)??Math.max(8,oe.positionY)}px`,maxHeight:Ce?`${Ce.maxHeight}px`:void 0},children:oe.items.map(e=>i.jsx("button",{className:["file-web-context-menu-item",e.label===o("conversation.filePanelDelete")?"danger":""].filter(Boolean).join(" "),type:"button",role:"menuitem",disabled:e.disabled,onClick:()=>{V(null),e.onSelect()},children:e.label},e.id))}),document.body):null,jn?i.jsx("p",{className:"file-panel-clipboard-status","data-mode":P==null?void 0:P.mode,children:jn}):null,Ye?i.jsxs("form",{className:"file-toolbar-search",onSubmit:e=>void Di(e),children:[i.jsx("input",{value:L,onChange:e=>Qe(e.target.value),placeholder:o("conversation.filePanelSearchPlaceholder")}),vn?i.jsx("button",{className:"secondary-button file-mobile-search-submit",type:"submit","aria-label":o("conversation.filePanelSearchButton"),disabled:bt,children:o("conversation.filePanelSearchButton")}):i.jsx("button",{className:"file-toolbar-button",type:"submit",title:o("conversation.filePanelSearchButton"),"aria-label":o("conversation.filePanelSearchButton"),disabled:bt,children:i.jsx(ti,{})})]}):null,i.jsx("div",{ref:vi,className:"file-tree","data-search-mode":de,"data-scrollbar-autohide":"true",children:Ae&&Ve.length===0?i.jsx("p",{className:"file-tree-status status-text",children:o("common.loading")}):de?Te!=null&&Te.length?Ti(Te):i.jsx("p",{className:"file-tree-status status-text",children:o("conversation.filePanelSearchEmpty")}):ee?xt.length?Zt(xt,0):i.jsx("p",{className:"file-tree-status status-text",children:o("conversation.filePanelNoChanges")}):Ve.length?Zt(Ve,0):i.jsx("p",{className:"file-tree-status status-text",children:o("conversation.filePanelEmptyDirectory")})}),i.jsx($n,{open:S!==null,title:(z==null?void 0:z.title)??"",description:z==null?void 0:z.description,onClose:qt,children:i.jsxs("form",{className:"workbench-rename-form",onSubmit:e=>void ki(e),children:[i.jsx(Zi,{label:o("conversation.filePanelPathFieldLabel"),htmlFor:dn,description:(S==null?void 0:S.mode)==="rename"?S.target.path:(S==null?void 0:S.baseDirectory)||void 0,children:i.jsx("input",{id:dn,type:"text",value:Wt??"",placeholder:o("conversation.filePanelPathFieldPlaceholder"),autoFocus:!0,onChange:e=>He(e.target.value)})}),i.jsxs(Qi,{children:[i.jsx("button",{type:"button",className:"secondary-button",disabled:p,onClick:qt,children:o("common.cancel")}),i.jsx("button",{type:"submit",className:"primary-button",disabled:p||!(Wt??"").trim(),children:p?(z==null?void 0:z.pendingLabel)??o("common.loading"):(z==null?void 0:z.submitLabel)??o("common.save")})]})]})}),i.jsxs($n,{open:W!==null,title:o("conversation.filePanelDeleteConfirmTitle"),description:o("conversation.filePanelDeleteConfirmDescription"),onClose:()=>{p||We(null)},children:[i.jsx("p",{className:"workbench-section-empty",children:W!=null&&W.length?W.length===1?((Wn=W[0])==null?void 0:Wn.kind)==="directory"?o("conversation.filePanelDeleteDirectoryConfirm",{path:W[0].path}):o("conversation.filePanelDeleteFileConfirm",{path:W[0].path}):o("conversation.filePanelDeleteSelectionConfirm",{count:W.length}):""}),i.jsxs("div",{className:"workbench-modal-actions",children:[i.jsx("button",{type:"button",className:"secondary-button",disabled:p,onClick:()=>We(null),children:o("common.cancel")}),i.jsx("button",{type:"button",className:"secondary-button workbench-danger-button",disabled:p,onClick:()=>{Mi()},children:p?o("conversation.filePanelDeleting"):o("conversation.filePanelDelete")})]})]})]}):$e&&n?i.jsx(ia,{sessionId:n,workspaceId:l,targetHostId:v,showSystemFiles:U,selectedPath:je,refreshVersion:sn,onCountChange:Ot,onSelectFile:me,onOpenFile:Ke}):i.jsx("section",{className:"file-panel-section",children:i.jsx("p",{className:"status-text",children:o("conversation.filePanelSessionNoSession")})})]}):i.jsx("section",{className:"file-panel-section",children:i.jsx("p",{className:"status-text",children:o("conversation.filePanelNoWorkspace")})})})}function Kn(t){const n=t==null?void 0:t.targetHostId;return typeof n=="string"&&n.trim()?n.trim():null}function Gn(t,n){return((t==null?void 0:t.trim())||null)===((n==null?void 0:n.trim())||null)}function ye(t){return t.includes("/")?t.split("/").slice(0,-1).join("/"):C}function ht(t,n=!1){const l=t.split("/").filter(Boolean),s=n?l.length:l.length-1,h=[];for(let m=0;m<s;m+=1)h.push(l.slice(0,m+1).join("/"));return h}function Xn(t,n){return t||((n==null?void 0:n.kind)==="directory"?n.path:n!=null&&n.path?ye(n.path):C)}function qn(t,n){return t?`${t}/${n}`:n}function ma(t){var n;return((n=t.split(/[/\\]/).pop())==null?void 0:n.trim())??""}function K(t,n){return{path:t,kind:n}}function In(t){return t[t.length-1]??null}function pa(t,n){return t.findIndex(s=>s.path===n.path)>=0?t.filter(s=>s.path!==n.path):[...t,n]}function ba(t,n,l){const s=t.findIndex(g=>g.path===l.path);if(s<0)return[l];const h=n?t.findIndex(g=>g.path===n):s;if(h<0)return[l];const m=Math.min(h,s),b=Math.max(h,s);return t.slice(m,b+1)}function wt(t){return!!(t!=null&&t.ctrlKey||t!=null&&t.metaKey)}function va(t){return t.ctrlKey||t.metaKey}function ya(t){if(!(t instanceof HTMLElement))return!1;const n=t.tagName.toLowerCase();return n==="input"||n==="textarea"||n==="select"||t.isContentEditable}function St(t){const n=[...new Map(t.map(s=>[s.path,s])).values()].sort((s,h)=>s.path.localeCompare(h.path)),l=[];for(const s of n)l.some(h=>h.kind==="directory"&&_t(h.path,s.path))||l.push(s);return l}function xa(t,n){return(t==null?void 0:t.kind)==="directory"?t.path:t!=null&&t.path?ye(t.path):n}function ga(t,n){let l=t;for(;l&&n.some(s=>s.kind==="directory"&&_t(s.path,l));)l=ye(l);return l}function ci(t,n,l,s,h,m){const b=[];for(const g of t){if(b.push(K(g.path,g.kind)),g.kind!=="directory"||!l.includes(g.path))continue;const D=n[g.path]??[],R=s?ln(D,n,h,m):D;b.push(...ci(R,n,l,s,h,m))}return b}function Ca(t,n,l){const s=Math.max(0,l.width),h=Math.max(0,l.height),m=Math.max(0,h-ne*2),b=Math.max(0,s-ne*2),g=Math.min(Math.max(n.width,0),b),D=Math.max(0,h-t.y-jt-ne),R=Math.max(0,t.y-jt-ne),T=D<n.height&&R>D,Q=en(Math.max(T?R:D,oa),0,m),ge=Math.min(Math.max(n.height,0),Q),G=T?t.y-jt-ge:t.y+jt,Ne=Math.max(ne,h-ne-ge),v=Math.max(ne,s-ne-g);return{top:en(G,ne,Ne),left:en(t.x,ne,v),maxHeight:Math.max(0,Q)}}function en(t,n,l){return!Number.isFinite(t)||l<n?n:Math.min(Math.max(t,n),l)}function Ie(t,n="posix"){return t?ui(t,n):"."}function Pa(t,n,l){const s=ui(t,l),h=Ie(n,l).replace(/^\.[/\\]?/,"");if(!h)return s;const m=fi(l),b=h.replace(/^[/\\]+/,"");return b?s.endsWith("/")||s.endsWith("\\")?`${s}${b}`:`${s}${m}${b}`:s}function ja(t){return/^[a-zA-Z]:[\\/]/.test(t)||t.includes("\\")?"windows":"posix"}function ui(t,n){return t&&(fi(n)==="\\"?t.replace(/\//g,"\\"):t.replace(/\\/g,"/"))}function fi(t){return t==="windows"?"\\":"/"}function _t(t,n){return n===t||n.startsWith(`${t}/`)}function di(t,n,l){return t===n?l:t.startsWith(`${n}/`)?`${l}${t.slice(n.length)}`:t}function wa(t,n,l){return t.map(s=>({...s,path:di(s.path,n,l)}))}function Sa(t){return t.mode==="create_file"?{title:o("conversation.filePanelNewFile"),description:o("conversation.filePanelCreateFileDescription"),submitLabel:o("conversation.filePanelCreateFileSubmit"),pendingLabel:o("conversation.filePanelCreatingFile")}:t.mode==="create_directory"?{title:o("conversation.filePanelNewDirectory"),description:o("conversation.filePanelCreateDirectoryDescription"),submitLabel:o("conversation.filePanelCreateDirectorySubmit"),pendingLabel:o("conversation.filePanelCreatingDirectory")}:{title:o("conversation.filePanelRenameMove"),description:o("conversation.filePanelRenameDescription"),submitLabel:o("conversation.filePanelRenameSubmit"),pendingLabel:o("conversation.filePanelRenaming")}}async function Na(t){const n=await t.arrayBuffer(),l=new Uint8Array(n),s=32768;let h="";for(let m=0;m<l.length;m+=s){const b=l.subarray(m,m+s);h+=String.fromCharCode(...b)}return btoa(h)}function Da(t){const n=atob(t),l=new Uint8Array(n.length);for(let s=0;s<n.length;s+=1)l[s]=n.charCodeAt(s);return l.buffer.slice(l.byteOffset,l.byteOffset+l.byteLength)}function Ea(t,n){if(typeof document>"u")throw new Error(o("conversation.filePanelDownloadFailed"));const l=window.URL.createObjectURL(n),s=document.createElement("a");s.href=l,s.download=t,document.body.append(s),s.click(),s.remove(),window.URL.revokeObjectURL(l)}async function ka(t,n){var l;if(!(n.isDesktop&&(await n.bridge.writeClipboardText(t)).ok)){if(typeof navigator<"u"&&((l=navigator.clipboard)!=null&&l.writeText))try{await navigator.clipboard.writeText(t);return}catch{}if(!Ma(t))throw new Error(o("conversation.filePanelCopyPathFailed"))}}function Ma(t){if(typeof document>"u"||typeof document.execCommand!="function")return!1;const n=document.createElement("textarea");n.value=t,n.setAttribute("readonly","true"),n.style.position="fixed",n.style.top="-9999px",n.style.left="-9999px",n.style.opacity="0",document.body.appendChild(n),n.focus(),n.select();try{return document.execCommand("copy")}catch{return!1}finally{document.body.removeChild(n)}}function Ra(t,n){return t&&ht(t,!0).every(h=>h in n)?t:C}function Yn(t,n){if(!n)return[];const l=ht(n,!0);return t.filter(s=>l.includes(s))}function Nt(t,n,l){const s=on(n,l);return Object.entries(t).reduce((h,[m,b])=>(s.has(m)&&(h[m]=b),h),{})}function Ta(t,n,l){const h=[...on(n,l)].filter(m=>m===C||m in t);return h.length?h:[C]}function on(t,n){const l=new Set([C]),s=hi(n,ht(t,!0));for(const h of s){l.add(h);for(const m of ht(h,!0))l.add(m)}return l}function _a(t,n){const l=Object.keys(t),s=Object.keys(n);return l.length!==s.length?!1:l.every(h=>t[h]===n[h])}function Mt(t,n){return t.includes(n)?t:[...t,n]}function hi(t,n){return n.reduce((l,s)=>Mt(l,s),t)}function Zn(t){return`file-panel.workspace-tree.${t}`}function Qn(t,n){return`file-panel.session-change-count.${t}.${n}`}function Jn(t,n){return Object.fromEntries(Object.keys(n).map(l=>[l,t[l]??null]))}function tn(t,n){return[...on(n,t)]}function Z(t,n){return t instanceof ni?t.message:n}function mi(t){return t instanceof Error&&t.message.startsWith("FILE_TREE_SNAPSHOT_TIMEOUT:")}function ei(t){return mi(t)||t instanceof Error&&t.message.startsWith("FILE_TREE_ABORTED:")}function Fa(t){return new Promise(n=>{window.setTimeout(n,t)})}function Aa(){return i.jsx("svg",{viewBox:"0 0 16 16","aria-hidden":"true",children:i.jsx("path",{d:"M2.5 4.5h11v2h-11zM2.5 7.5h7v2h-7zM2.5 10.5h4v2h-4z",fill:"currentColor"})})}function La(){return i.jsx("svg",{viewBox:"0 0 16 16","aria-hidden":"true",children:i.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 ti(){return i.jsx("svg",{viewBox:"0 0 16 16","aria-hidden":"true",children:i.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 Ba(){return i.jsxs("svg",{viewBox:"0 0 16 16","aria-hidden":"true",children:[i.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"}),i.jsx("path",{d:"M5.7 10.8h4.5",fill:"none",stroke:"currentColor",strokeWidth:"1.2"})]})}function Wa(){return i.jsxs("svg",{viewBox:"0 0 16 16","aria-hidden":"true",children:[i.jsx("path",{d:"M5 2.5h7.5v9H5z",fill:"none",stroke:"currentColor",strokeWidth:"1.2"}),i.jsx("path",{d:"M3.5 5H2.4V13.5H10V12.4",fill:"none",stroke:"currentColor",strokeWidth:"1.2"})]})}function Ha(){return i.jsx("svg",{viewBox:"0 0 16 16","aria-hidden":"true",children:i.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 $a(){return i.jsxs("svg",{viewBox:"0 0 16 16","aria-hidden":"true",children:[i.jsx("path",{d:"M4 3.5h8v10H4zM6 2.2h4v2H6z",fill:"none",stroke:"currentColor",strokeWidth:"1.2"}),i.jsx("path",{d:"M6 7.2h4M6 9.6h4",fill:"none",stroke:"currentColor",strokeWidth:"1.2"})]})}function Oa(){return i.jsxs("svg",{viewBox:"0 0 16 16","aria-hidden":"true",children:[i.jsx("path",{d:"M4 1.5h5l3 3v10H4z",fill:"none",stroke:"currentColor",strokeWidth:"1.2"}),i.jsx("path",{d:"M9 1.5v3h3",fill:"none",stroke:"currentColor",strokeWidth:"1.2"}),i.jsx("path",{d:"M8 6.5v5M5.5 9h5",fill:"none",stroke:"currentColor",strokeWidth:"1.2"})]})}function Va(){return i.jsxs("svg",{viewBox:"0 0 16 16","aria-hidden":"true",children:[i.jsx("path",{d:"M3 11.5v2h10v-2",fill:"none",stroke:"currentColor",strokeWidth:"1.2"}),i.jsx("path",{d:"M8 2.5v8",fill:"none",stroke:"currentColor",strokeWidth:"1.2"}),i.jsx("path",{d:"m5.5 5 2.5-2.5L10.5 5",fill:"none",stroke:"currentColor",strokeWidth:"1.2",strokeLinecap:"round",strokeLinejoin:"round"})]})}function Ua(){return i.jsxs("svg",{viewBox:"0 0 16 16","aria-hidden":"true",children:[i.jsx("path",{d:"M3 11.5v2h10v-2",fill:"none",stroke:"currentColor",strokeWidth:"1.2"}),i.jsx("path",{d:"M8 2.5v8",fill:"none",stroke:"currentColor",strokeWidth:"1.2"}),i.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 za(){return i.jsx("svg",{viewBox:"0 0 16 16","aria-hidden":"true",children:i.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 Ka(){return i.jsxs("svg",{viewBox:"0 0 16 16","aria-hidden":"true",children:[i.jsx("path",{d:"M1.8 4.5h4l1.2 1.3h7.2v6.7H1.8z",fill:"none",stroke:"currentColor",strokeWidth:"1.2"}),i.jsx("path",{d:"M8.5 7.2v4M6.5 9.2h4",fill:"none",stroke:"currentColor",strokeWidth:"1.2"})]})}function Ga(){return i.jsx("svg",{viewBox:"0 0 16 16","aria-hidden":"true",children:i.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 Xa(){return i.jsx("svg",{viewBox:"0 0 16 16","aria-hidden":"true",children:i.jsx("path",{d:"m4 6 4 4 4-4",fill:"none",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round"})})}function qa(){return i.jsx("svg",{viewBox:"0 0 16 16","aria-hidden":"true",children:i.jsx("path",{d:"M1.5 2h13l-5 6v5l-3 1.5V8z",fill:"none",stroke:"currentColor",strokeWidth:"1.2",strokeLinejoin:"round"})})}function ln(t,n,l,s){const h=[];for(const m of t){const b=m.path.replace(/\\/g,"/");m.kind==="file"?l.has(b)&&h.push(m):pi(b,n,l,s)&&h.push(m)}return h}function pi(t,n,l,s,h){const m=h??new Set;if(m.has(t))return!1;m.add(t);const b=n[t];if(!b)return s.has(t);for(const g of b){const D=g.path.replace(/\\/g,"/");if(g.kind==="file"){if(l.has(D))return!0}else if(pi(D,n,l,s,m))return!0}return!1}export{rl as FileContextPanel};
@@ -0,0 +1,6 @@
1
+ import{b as l,F as Rn,ab as wn,G as Gi,t as n,j as e,B as Yn}from"./index-FOhyOpGY.js";import{u as $i,e as Ui,f as Bi,g as Pn}from"./App-Dl-mcdqy.js";import{b as Ii,Y as dt,C as Vi,bU as Wi,c1 as zi,c2 as Ki,bK as Xi,c3 as An,c4 as qi,c5 as Yi,bT as Zi,c6 as Qi,bO as Ji,c7 as es,bM as Zn,c8 as ts,c0 as ns,c9 as Dn,x as is,w as ss,y as as,ca as rs,bP as Wt,bQ as zt,cb as os,cc as ls,ah as cs}from"./WorkbenchLayout-DViAJhHz.js";import{W as ke}from"./WorkbenchModal-DWsNm2B2.js";import{e as us}from"./workbench-navigation-aqJ1ay4M.js";import"./window-BVUB8gMK.js";import"./event-DvH9tcej.js";import"./host-alias-0TfFnYxR.js";import"./DesktopModal-BnfGW2gk.js";import"./relay-entry-DhHwflXl.js";import"./MobileSheet-rkn_CUOY.js";const kt=56,Ln=28,Gt=72,mt=8,_n=960,Fn=60*1e3,On=20,kn=9,Gn=9,$t=68,O=12,ht=8,Kt=260,ds=120,Ut=6e4,gt={authMode:"none",username:"",password:"",token:"",rememberOnHost:!1};function Us({className:a,workspaceId:i,panelActive:u=!0,externalWindowMode:h=!1,workbenchShellOverrides:g}){const C=$i(),f=Ui(),y=Ii(),{subscribeGitSnapshot:x,requestGitRefresh:v,addGitSnapshotListener:H,requestNavigationRefresh:S,selectWorkspace:T,upsertNavigationSession:p,currentTargetHostId:o}={...y,...g},[d,j]=l.useState(null),[E,R]=l.useState(null),[b,F]=l.useState([]),[P,se]=l.useState(0),[X,ae]=l.useState(null),[be,xt]=l.useState(!1),[U,ye]=l.useState(null),[re,q]=l.useState(null),[je,Ce]=l.useState(""),[Ue,B]=l.useState(!1),[N,A]=l.useState(!1),[ri,Qt]=l.useState([]),[te,Jt]=l.useState(!0),[ne,W]=l.useState(!1),[k,oi]=l.useState(()=>typeof window<"u"?window.innerWidth<=_n:!1),[bt,I]=l.useState([]),[Ne,z]=l.useState(null),[ve,oe]=l.useState("unstaged"),[Se,Y]=l.useState(null),[le,Z]=l.useState(null),[li,yt]=l.useState(!1),[ci,jt]=l.useState(null),[ui,Be]=l.useState(!1),[en,Ie]=l.useState(null),[_,Te]=l.useState(null),[tn,Me]=l.useState(null),[di,He]=l.useState(!1),[Ee,ce]=l.useState(null),[ie,Ct]=l.useState(!1),[mi,ue]=l.useState(!1),[Ve,Nt]=l.useState("push"),[We,ze]=l.useState([]),[hi,Ke]=l.useState(!1),[Xe,qe]=l.useState(new Set),[gi,de]=l.useState(new Map),[Ye,nn]=l.useState({}),[fi,me]=l.useState(!1),[Ze,sn]=l.useState(null),[D,Q]=l.useState(gt),[an,rn]=l.useState("generic"),[on,Qe]=l.useState(null),[G,vt]=l.useState(null),[$,St]=l.useState(null),[ln,cn]=l.useState(kt),[Tt,Mt]=l.useState(!1),[un,Re]=l.useState(null),[pi,we]=l.useState(null),dn=l.useRef(null),mn=l.useRef(null),hn=l.useRef(null),gn=l.useRef(null),fn=l.useRef(null),pn=l.useRef(null),Ht=l.useRef(null),Pe=l.useRef(new Map),Je=l.useRef(new Map),Ae=l.useRef(0),xn=l.useRef(u),bn=l.useRef(u),et=l.useRef(null),{showToast:M}=Bi(),yn=f.isDesktop&&!k;l.useEffect(()=>{dt("git_sidebar.props",{workspaceId:i,externalWindowMode:h})},[h,i]),l.useEffect(()=>{bn.current=u},[u]),l.useEffect(()=>{Qt([]),Jt(!0),se(0),ae(null),xt(!1),q(null),Ce(""),W(!1),I([]),z(null),oe("unstaged"),Y(null),Z(null),yt(!1),jt(null),Be(!1),Ie(null),Te(null),Me(null),He(!1),ce(null),Ct(!1),ue(!1),Nt("push"),ze([]),qe(new Set),de(new Map),nn({}),me(!1),sn(null),Q(gt),rn("generic"),Qe(null),vt(null),St(null),Mt(!1),cn(kt),Re(null),we(null),Je.current.clear(),Pe.current.clear()},[i]),l.useEffect(()=>{function t(){oi(window.innerWidth<=_n)}return t(),window.addEventListener("resize",t),()=>{window.removeEventListener("resize",t)}},[]),l.useEffect(()=>{if(!Tt)return;const t=document.body.style.cursor,s=document.body.style.userSelect;document.body.style.cursor="row-resize",document.body.style.userSelect="none";function r(m){Sn(m.clientY)}function c(){Mt(!1)}return window.addEventListener("pointermove",r),window.addEventListener("pointerup",c),()=>{document.body.style.cursor=t,document.body.style.userSelect=s,window.removeEventListener("pointermove",r),window.removeEventListener("pointerup",c)}},[Tt]),l.useEffect(()=>{var c,m;if(!(i!=null&&i.trim())){et.current=null,j(null),R(null),F([]),se(0),ae(null),ye(null),B(!1);return}const t=i.trim(),s=Rn(Ge(t,o),Fn),r=It(s);if(dt("git_sidebar.snapshot",{workspaceId:t,cached:r,cachedHistoryCount:((c=s==null?void 0:s.history)==null?void 0:c.length)??0,cachedChangedCount:((m=s==null?void 0:s.status)==null?void 0:m.changes.length)??0}),r&&s){Et(s,t),B(!1);return}et.current=null,wn(Ge(t,o)),j(null),R(null),F([]),se(0),ae(null),ye(null),B(!0)},[i]),l.useEffect(()=>{if(i!=null&&i.trim())return H(t=>{var s,r,c;t.workspaceId!==i.trim()||!Cs(js(t),o)||(dt("git_sidebar.snapshot_received",{workspaceId:t.workspaceId,changedCount:((s=t.status)==null?void 0:s.changes.length)??0,historyCount:t.history.length,branchCount:(((r=t.branches)==null?void 0:r.local.length)??0)+(((c=t.branches)==null?void 0:c.remote.length)??0)}),Et(t,t.workspaceId),B(!1))})},[H,i]),l.useEffect(()=>{if(!(i!=null&&i.trim()))return;const t=i.trim(),s=Rn(Ge(t,o),Fn),r=It(s)?(s==null?void 0:s.revision)??null:null;x(t,{knownRevision:r,targetHostId:o}),bn.current&&K()},[o,v,x,i]),l.useEffect(()=>{const t=xn.current;xn.current=u,i!=null&&i.trim()&&!t&&u&&v(i.trim(),{knownRevision:E,targetHostId:o})},[o,u,v,E,i]),l.useEffect(()=>{const t=i==null?void 0:i.trim();if(!t||et.current!==t)return;const s={revision:E,status:d,history:b,historyTotalCount:P,historyNextCursor:X,branches:U};if(!It(s)){wn(Ge(t,o));return}Gi(Ge(t,o),s)},[U,b,X,P,E,d,i]),l.useEffect(()=>{if(!d||!re)return;d.changes.find(s=>s.path===re)||q(null)},[re,d]),l.useEffect(()=>{bs(gn.current)},[je]),l.useEffect(()=>{k||(I([]),z(null),Y(null),Qe(null))},[k]),l.useEffect(()=>{if(!d){I([]);return}const t=new Set(d.changes.map(s=>s.path));I(s=>s.filter(r=>t.has(r)))},[d]);function xi(){const t=hn.current;if(!t)return;t.querySelectorAll(".git-tree-shell").forEach(r=>{r.scrollTop=0})}function Et(t,s){et.current=(s==null?void 0:s.trim())??(i==null?void 0:i.trim())??null,R(typeof t.revision=="string"?t.revision:null),j(t.status),F(Array.isArray(t.history)?t.history:[]),se(typeof t.historyTotalCount=="number"?t.historyTotalCount:0),ae(typeof t.historyNextCursor=="string"?t.historyNextCursor:null),ye(t.branches??null)}function K(t){i!=null&&i.trim()&&(B(!0),dt("git_sidebar.refresh_requested",{workspaceId:i.trim(),resetTreeScroll:!1}),v(i.trim(),{knownRevision:E,targetHostId:o}))}async function Rt(t){if(!(i!=null&&i.trim()))return;const s=i.trim();B(!0);try{const[r,c,m]=await Promise.all([Xi(s,{targetHostId:o}),An(s,On,null,{targetHostId:o}),qi(s,{targetHostId:o})]);Et({status:r,history:c.items,historyTotalCount:c.totalCount,historyNextCursor:c.nextCursor,branches:m}),v(s,{targetHostId:o}),t!=null&&t.resetTreeScroll&&requestAnimationFrame(()=>{xi()})}catch(r){M({title:L(r,n("git.panelLoadFailed")),tone:"error"})}finally{B(!1)}}async function tt(){if(!(!i||!X||be)){xt(!0);try{const t=await An(i,On,X,{targetHostId:o});F(s=>{const r=new Set(s.map(m=>m.commitHash)),c=t.items.filter(m=>!r.has(m.commitHash));return[...s,...c]}),se(t.totalCount),ae(t.nextCursor)}catch(t){M({title:L(t,n("git.panelLoadFailed")),tone:"error"})}finally{xt(!1)}}}function bi(t){if(!te||be||!X)return;const s=t.currentTarget;s.scrollHeight-s.scrollTop-s.clientHeight<=40&&tt()}async function yi(){if(i){A(!0);try{const t=await Ki(i,"ai",{targetHostId:o});Ce(t.validation.normalizedDraft.subject||t.draft.subject)}catch(t){M({title:L(t,n("git.draftFailed")),tone:"error"})}finally{A(!1)}}}async function nt(t,s){if(i&&t.length){A(!0);try{const r=s?await Qi(i,t,{targetHostId:o}):await Ji(i,t,{targetHostId:o});j(r),q(t[t.length-1]??null),I(c=>c.filter(m=>!t.includes(m))),z(null),K()}catch(r){B(!1),M({title:L(r,n("git.stageFailed")),tone:"error"})}finally{A(!1)}}}async function wt(t){if(i&&t.length){A(!0);try{const s=await ts(i,t,{targetHostId:o});j(s),t.includes(re??"")&&q(null),I(r=>r.filter(c=>!t.includes(c))),z(null),K()}catch(s){B(!1),M({title:L(s,n("git.discardFailed")),tone:"error"})}finally{A(!1)}}}async function ji(){if(!(!i||!je.trim())){A(!0);try{await Yi(i,fs(je),{targetHostId:o}),M({title:n("git.commitSuccess"),tone:"success"}),Ce(""),q(null),K()}catch(t){M({title:L(t,n("git.commitFailed")),tone:"error"})}finally{A(!1)}}}async function Ci(){if(i!=null&&i.trim()){A(!0),B(!0);try{const t=await zi(i.trim(),{targetHostId:o});j(t),F([]),se(0),ae(null),ye(null),M({title:n("git.initSuccess"),tone:"success"}),K()}catch(t){M({title:L(t,n("git.initFailed")),tone:"error"})}finally{A(!1),B(!1)}}}async function Pt(){const t=i==null?void 0:i.trim();if(!t)return[];const s=await rs(t,{targetHostId:o});return(i==null?void 0:i.trim())!==t?[]:(ze(s),s)}async function it(t){const s=await Pt(),r=ft(s,t);if(!r){M({title:n("git.noRemotes"),tone:"error"});return}const c=Ye[r.name]??null;sn(r.name),rn(Ms(s,r.name)),Q(Ss((c==null?void 0:c.auth)??null,(c==null?void 0:c.rememberOnHost)??!1)),me(!0)}async function Ni(){if(i!=null&&i.trim()){Ke(!0);try{const t=await Pt();if(t.length===0){M({title:n("git.noRemotes"),tone:"error"});return}if(t.length===1){await it(t[0].name);return}Nt("auth"),qe(new Set),de(new Map),ue(!0)}catch(t){M({title:L(t,n("git.remoteFailed")),tone:"error"})}finally{Ke(!1)}}}function vi(){const t=Ze==null?void 0:Ze.trim();if(!t){me(!1);return}const s=Ts(D),r=an==="github"?n("git.remoteAuthGithubPatPlaceholder"):n("shell.clonePasswordPlaceholder");if(D.authMode==="basic"){if(!D.username.trim()){M({title:n("shell.cloneUsernamePlaceholder"),tone:"error"});return}if(!D.password){M({title:r,tone:"error"});return}}if(D.authMode==="token"&&!D.token){M({title:n("shell.cloneTokenPlaceholder"),tone:"error"});return}nn(c=>{if(!s){const{[t]:m,...w}=c;return w}return{...c,[t]:{auth:s,rememberOnHost:D.rememberOnHost}}}),me(!1),M({title:s?n("git.remoteAuthSaved"):n("git.remoteAuthCleared"),description:s&&D.rememberOnHost?n("git.remoteAuthRememberHint"):void 0,tone:"success"})}async function jn(){if(i){Ke(!0);try{const t=await Pt();if(t.length===0){M({title:n("git.noRemotes"),tone:"error"});return}if(t.length===1){Cn([t[0].name]);return}Nt("push"),qe(new Set),de(new Map),ue(!0)}catch(t){M({title:L(t,n("git.remoteFailed")),tone:"error"})}finally{Ke(!1)}}}async function Cn(t){if(!i||t.length===0)return;A(!0),de(new Map);const s=new Map;let r=!1;try{for(const c of t){const m=Ye[c]??null;try{const w=await Dn(i,"push",c,m==null?void 0:m.auth,(m==null?void 0:m.rememberOnHost)??!1,{targetHostId:o});s.set(c,{ok:!0,summary:w.summary}),m!=null&&m.rememberOnHost&&m.auth&&ze(ki=>ki.map(Ot=>Ot.name===c?{...Ot,credentialConfigured:!0}:Ot))}catch(w){if(r=!0,s.set(c,{ok:!1,summary:L(w,n("git.remoteFailed"))}),de(new Map(s)),Kn(w)){it(c);return}}}de(s),K(),r||(M({title:n("git.pushAllSuccess",{count:String(t.length)}),tone:"success"}),ue(!1))}finally{A(!1)}}async function At(t){if(i){if(t==="push"){W(!1),jn();return}A(!0);try{const s=Xn(We),r=s?Ye[s]??null:null,c=await Dn(i,t,void 0,r==null?void 0:r.auth,(r==null?void 0:r.rememberOnHost)??!1,{targetHostId:o});M({title:c.summary,tone:"success"}),s&&(r!=null&&r.rememberOnHost)&&r.auth&&ze(m=>m.map(w=>w.name===s?{...w,credentialConfigured:!0}:w)),W(!1),K()}catch(s){if(Kn(s)){it(Xn(We));return}M({title:L(s,n("git.remoteFailed")),tone:"error"})}finally{A(!1)}}}async function he(){if(i){A(!0);try{const t=await es(i,{targetHostId:o});Ce(t.commitSubject??""),M({title:t.summary||n("git.undoLastCommitSuccess"),tone:"success"}),W(!1),K()}catch(t){M({title:L(t,n("git.undoLastCommitFailed")),tone:"error"})}finally{A(!1)}}}async function Si(t){if(i){A(!0);try{const s=await os(i,t,!1,{targetHostId:o});ye(s),W(!1),K()}catch(s){M({title:L(s,n("git.branchFailed")),tone:"error"})}finally{A(!1)}}}async function Dt(t){const s=i==null?void 0:i.trim();if(!s)throw new Error(n("git.panelLoadFailed"));const r=Je.current.get(t);if(r)return r;const c=await ls(s,t,{targetHostId:o});return Je.current.set(t,c),c}async function De(t){Z(null),Y(null),jt(t),Ie(null);const s=Je.current.get(t)??null;if(Te(s),Be(!s),s)return;const r=Ae.current+1;Ae.current=r;try{const c=await Dt(t);if(Ae.current!==r)return;Te(c)}catch(c){if(Ae.current!==r)return;Ie(L(c,n("git.commitDetailLoadFailed"))),Te(null)}finally{Ae.current===r&&Be(!1)}}function Ti(){jt(null),Be(!1),Ie(null),Te(null)}async function Le(t){try{const s=await Dt(t);await V(s.versionLabel,n("git.copyCommitVersionSuccess"))}catch(s){M({title:L(s,n("git.commitDetailLoadFailed")),tone:"error"})}}function _e(t){Z(null),Y(null),Me(t),ce(null),He(!0)}function Mi(t){var r;const s=((r=b[0])==null?void 0:r.commitHash)===t.commitHash&&t.commitKind==="local";return[{id:`view-changes:${t.commitHash}`,label:n("git.viewCommitChanges"),onSelect:()=>void De(t.commitHash)},{id:`copy-hash:${t.commitHash}`,label:n("git.copyCommitHash"),onSelect:()=>void V(t.commitHash,n("git.copyCommitHashSuccess"))},{id:`copy-message:${t.commitHash}`,label:n("git.copyCommitMessage"),onSelect:()=>void V(xe(t),n("git.copyCommitMessageSuccess"))},{id:`copy-version:${t.commitHash}`,label:n("git.copyCommitVersion"),onSelect:()=>void Le(t.commitHash)},{id:`explain:${t.commitHash}`,label:n("git.explainCommitAction"),onSelect:()=>_e(t.commitHash)},...s?[{id:`undo:${t.commitHash}`,label:n("git.undoLastCommit"),disabled:N,onSelect:()=>void he()}]:[]]}async function Nn(t){Z(null),Y(null),await ns(Mi(t))}async function Hi(){var t,s;if(!(!i||!tn||!Ee||ie)){Ct(!0);try{const r=await Dt(tn),c=await is({workspaceId:i,provider:Ee,content:xs(r),clientRequestId:((s=(t=globalThis.crypto)==null?void 0:t.randomUUID)==null?void 0:s.call(t))??`git-explain-${Date.now()}-${Math.random().toString(16).slice(2)}`,permissionMode:ss()}),m=c.session??await as(c.sessionId);p(m),S(),T(m.workspaceId),C(us(m.workspaceId,m.sessionId)),He(!1),Me(null),ce(null),M({title:n("git.explainCommitStarted"),tone:"success"})}catch(r){M({title:L(r,n("git.explainCommitFailed")),tone:"error"})}finally{Ct(!1)}}}function st(t){Qt(s=>s.includes(t)?s.filter(r=>r!==t):[...s,t])}const Ei=450;function vn(t){const s=Date.now(),r=dn.current;return dn.current={filePath:t,timestamp:s},(r==null?void 0:r.filePath)===t&&s-r.timestamp<=Ei}async function at(t,s){if(s.binary){M({title:n("git.binaryDiff"),tone:"info"});return}if(s.status==="A"||s.status==="?")we(null),Re(t);else if(i)try{const r=await Zi(i,t,s.staged,{targetHostId:o});we(r.content),Re(t)}catch{we(null),Re(t)}}function rt(t){q(t),z(null),I(s=>s.includes(t)?s.filter(r=>r!==t):[...s,t])}function Sn(t){const s=mn.current;if(!s||!Number.isFinite(t))return;const r=s.getBoundingClientRect(),c=r.height-mt;if(!Number.isFinite(r.top)||!Number.isFinite(r.height)||c<=0)return;const m=(t-r.top-mt/2)/c*100;if(!Number.isFinite(m))return;const w=Math.max(Ln,Math.min(Gt,Math.round(m)));cn(w)}function Ri(t){t.preventDefault(),Sn(t.clientY),Mt(!0)}const Fe=(d==null?void 0:d.changes)??[],J=Fe.filter(t=>Xt(t,"staged")),ge=Fe.filter(t=>Xt(t,"unstaged")),Tn=Wn(J,"staged"),Mn=Wn(ge,"unstaged"),ot=new Set(ri),lt=new Set(bt),fe=zn(bt,Fe,"staged"),pe=zn(bt,Fe,"unstaged"),Lt=Fe.length===0&&((d==null?void 0:d.snapshot.ahead)??0)>0,wi=J.length>0&&je.trim().length>0,ct=(U==null?void 0:U.currentBranch)??(d==null?void 0:d.snapshot.branch)??n("common.unknown"),ut=ft(We,Ze),Oe=an==="github",Pi=Oe?n("git.remoteAuthDescriptionGithub"):n("git.remoteAuthDescription"),Ai=Oe?n("git.remoteAuthGithubPatLabel"):n("shell.clonePasswordLabel"),Di=Oe?n("git.remoteAuthGithubPatPlaceholder"):n("shell.clonePasswordPlaceholder"),Li=Oe?n("git.remoteAuthGithubUsernamePlaceholder"):n("shell.cloneUsernamePlaceholder"),_t=Number.isFinite(ln)?ln:kt,_i=te?`minmax(120px, ${_t}fr) ${mt}px minmax(140px, ${100-_t}fr)`:`minmax(120px, 1fr) ${mt}px auto`,Fi=Ns(d);l.useEffect(()=>{Ne==="staged"&&fe.length===0&&z(null),Ne==="unstaged"&&pe.length===0&&z(null)},[Ne,fe.length,pe.length]),l.useEffect(()=>{if(!k)return;const t=ge.length>0?"unstaged":J.length>0?"staged":"history";oe(s=>s==="unstaged"&&ge.length>0||s==="staged"&&J.length>0?s:t)},[k,J.length,ge.length]),l.useEffect(()=>{Se&&(b.some(t=>t.commitHash===Se)||Y(null))},[b,Se]),l.useEffect(()=>{le&&(b.some(t=>t.commitHash===le)||Z(null))},[le,b]),l.useEffect(()=>{k&&ve!=="history"&&ne&&W(!1)},[k,ne,ve]),l.useLayoutEffect(()=>{if(k||!ne){vt(null);return}function t(){const r=fn.current,c=pn.current;!r||!c||typeof window>"u"||vt(qn(r.getBoundingClientRect(),{width:c.getBoundingClientRect().width||Kt,height:c.getBoundingClientRect().height||c.scrollHeight||0},{width:window.innerWidth,height:window.innerHeight}))}t();const s=window.requestAnimationFrame(t);return window.addEventListener("resize",t),window.addEventListener("scroll",t,!0),()=>{window.cancelAnimationFrame(s),window.removeEventListener("resize",t),window.removeEventListener("scroll",t,!0)}},[N,U==null?void 0:U.local.length,ct,k,ne]);const ee=Se??le;l.useLayoutEffect(()=>{if(!ee){St(null);return}const t=ee;function s(){const c=Pe.current.get(t)??null,m=Ht.current;!c||!m||typeof window>"u"||St(qn(c.getBoundingClientRect(),{width:m.getBoundingClientRect().width||Kt,height:m.getBoundingClientRect().height||m.scrollHeight||0},{width:window.innerWidth,height:window.innerHeight}))}s();const r=window.requestAnimationFrame(s);return window.addEventListener("resize",s),window.addEventListener("scroll",s,!0),()=>{window.cancelAnimationFrame(r),window.removeEventListener("resize",s),window.removeEventListener("scroll",s,!0)}},[ee,b.length]),l.useEffect(()=>{if(!ee||typeof document>"u")return;const t=ee;function s(r){const c=r.target;if(!(c instanceof Node))return;const m=Pe.current.get(t)??null,w=Ht.current;m!=null&&m.contains(c)||w!=null&&w.contains(c)||(Y(null),Z(null))}return document.addEventListener("pointerdown",s),()=>{document.removeEventListener("pointerdown",s)}},[ee]);async function V(t,s){var r;try{if(f.isDesktop&&(await f.bridge.writeClipboardText(t)).ok){M({title:s,tone:"success"});return}if(typeof navigator<"u"&&((r=navigator.clipboard)!=null&&r.writeText)){await navigator.clipboard.writeText(t),M({title:s,tone:"success"});return}if(ps(t)){M({title:s,tone:"success"});return}}catch{M({title:n("common.copyContentFailed"),tone:"error"})}}async function Hn(t,s){typeof window<"u"&&!window.confirm(n("git.discardConfirm",{path:s}))||await wt(t)}function En(t){const s=(t==null?void 0:t.desktopFloating)===!0&&!k,r=s?{top:(G==null?void 0:G.top)??O,left:(G==null?void 0:G.left)??O,maxHeight:G==null?void 0:G.maxHeight,transformOrigin:(G==null?void 0:G.transformOrigin)??"top right"}:void 0,c=e.jsxs("div",{ref:s?pn:void 0,className:"git-operations-menu","data-floating":s?"true":"false",style:r,children:[e.jsxs("div",{className:"git-menu-section",children:[e.jsx("span",{className:"git-menu-caption",children:n("git.currentBranch")}),e.jsx("strong",{className:"git-menu-branch",children:ct})]}),e.jsxs("div",{className:"git-menu-section",children:[e.jsx("span",{className:"git-menu-caption",children:n("git.remoteAuthStatusLabel")}),e.jsxs("div",{className:"git-menu-branch-list",children:[e.jsx("strong",{className:"git-menu-branch",children:n("git.remoteAuthManageHint")}),e.jsx("button",{className:"git-menu-item",type:"button",disabled:N||hi,onClick:()=>void Ni(),children:e.jsx("span",{children:n("git.remoteAuthAction")})})]})]}),e.jsxs("div",{className:"git-menu-section",children:[e.jsx("span",{className:"git-menu-caption",children:n("git.branchTitle")}),e.jsx("div",{className:"git-menu-branch-list",children:U==null?void 0:U.local.map(m=>e.jsx("button",{className:"git-menu-item",type:"button",disabled:N||m.current,onClick:()=>void Si(m.name),children:e.jsx("span",{children:m.current?`${n("git.switchBranch")} ${m.name}`:`${n("git.switchBranchTo")} ${m.name}`})},m.name))})]}),e.jsxs("div",{className:"git-menu-section",children:[e.jsx("button",{className:"git-menu-item",type:"button",disabled:N,onClick:()=>{W(!1),yt(!0)},children:e.jsx("span",{children:n("git.viewAllVersions")})}),e.jsx("button",{className:"git-menu-item",type:"button",disabled:N,onClick:()=>void At("fetch"),children:e.jsx("span",{children:n("git.fetch")})}),e.jsx("button",{className:"git-menu-item",type:"button",disabled:N,onClick:()=>void At("pull"),children:e.jsx("span",{children:n("git.pull")})}),e.jsx("button",{className:"git-menu-item",type:"button",disabled:N,onClick:()=>void At("push"),children:e.jsx("span",{children:n("git.push")})}),e.jsx("button",{className:"git-menu-item",type:"button",disabled:N,onClick:()=>void he(),children:e.jsx("span",{children:n("git.undoLastCommit")})}),e.jsx("button",{className:"git-menu-item",type:"button",disabled:N||Ue,onClick:()=>void Rt({resetTreeScroll:!0}),children:e.jsx("span",{children:n("git.refresh")})})]})]});return s?typeof document>"u"?null:Pn.createPortal(c,document.body):c}function Ft(t,s){if(s){Pe.current.set(t,s);return}Pe.current.delete(t)}function Oi(){var r;if(!ee||typeof document>"u")return null;const t=b.find(c=>c.commitHash===ee);if(!t)return null;const s=((r=b[0])==null?void 0:r.commitHash)===t.commitHash&&t.commitKind==="local";return Pn.createPortal(e.jsx("div",{ref:Ht,className:"git-history-entry-menu","data-floating":"true",style:{top:($==null?void 0:$.top)??O,left:($==null?void 0:$.left)??O,maxHeight:$==null?void 0:$.maxHeight,transformOrigin:($==null?void 0:$.transformOrigin)??"top right"},children:e.jsx(hs,{item:t,canUndo:s,actioning:N,onViewCommitChanges:c=>void De(c),onCopyCommitHash:c=>void V(c,n("git.copyCommitHashSuccess")),onCopyCommitMessage:c=>void V(xe(c),n("git.copyCommitMessageSuccess")),onCopyCommitVersion:c=>void Le(c),onExplainCommitChange:c=>void _e(c),onUndoLastCommit:()=>void he()})}),document.body)}return d&&!Fi?e.jsx("section",{className:["conversation-panel","surface-card","git-sidebar",a].filter(Boolean).join(" "),"data-testid":"git-sidebar",children:e.jsxs("section",{className:"git-card git-scaffold-section git-disabled-state",children:[e.jsxs("div",{className:"git-disabled-copy",children:[e.jsx("h3",{children:n("git.uninitializedTitle")}),e.jsx("p",{children:n("git.uninitializedDescription")})]}),e.jsx("div",{className:"git-primary-actions",children:e.jsx("button",{className:"primary-button git-primary-submit",type:"button",onClick:()=>void Ci(),disabled:N||Ue||!i,children:N?n("git.initInProgress"):n("git.initRepository")})})]})}):e.jsxs("section",{className:["conversation-panel","surface-card","git-sidebar",a].filter(Boolean).join(" "),"data-testid":"git-sidebar",children:[e.jsxs("section",{className:"git-card git-scaffold-section",children:[e.jsxs("div",{className:"git-editor-row",children:[e.jsx("textarea",{ref:gn,rows:1,value:je,onChange:t=>Ce(ni(t.target.value)),onKeyDown:t=>{t.key==="Enter"&&t.preventDefault()},placeholder:n("git.commitSubjectPlaceholder")}),e.jsx("button",{className:"git-icon-button",type:"button","aria-label":n("git.generateDraft"),title:n("git.generateDraft"),onClick:()=>void yi(),disabled:N||Ue,children:e.jsx(Rs,{})})]}),e.jsxs("div",{className:"git-primary-actions",children:[e.jsx("button",{className:"secondary-button",type:"button",onClick:()=>void Rt({resetTreeScroll:!0}),disabled:N||Ue||!i,children:n("git.refreshNow")}),e.jsx("button",{className:"primary-button git-primary-submit",type:"button",onClick:()=>{if(Lt){jn();return}ji()},disabled:N||!Lt&&!wi,children:Lt?n("git.pushNow"):n("git.commitNow")})]})]}),k?e.jsxs("div",{className:"git-mobile-sections",children:[e.jsx(Bt,{title:n("git.stagedChangesTitle"),count:J.length,expanded:ve==="staged",onToggle:()=>oe("staged"),children:e.jsx(Un,{title:n("git.stagedChangesTitle"),nodes:Tn,collapsedTreePathSet:ot,onToggleTreePath:st,onToggleMobileSelection:rt,selectedMobilePathSet:lt,selectedTargets:fe,actioning:N,variant:"staged",swipeRowState:on,onSwipeRowChange:Qe,onStageToggle:nt,onDiscardWithConfirm:Hn,onClearSelectedTargets:()=>I(t=>t.filter(s=>!fe.includes(s))),onPreviewFile:at})}),e.jsx(Bt,{title:n("git.changesTitle"),count:ge.length,expanded:ve==="unstaged",onToggle:()=>oe("unstaged"),children:e.jsx(Un,{title:n("git.changesTitle"),nodes:Mn,collapsedTreePathSet:ot,onToggleTreePath:st,onToggleMobileSelection:rt,selectedMobilePathSet:lt,selectedTargets:pe,actioning:N,variant:"unstaged",swipeRowState:on,onSwipeRowChange:Qe,onStageToggle:nt,onDiscardWithConfirm:Hn,onClearSelectedTargets:()=>I(t=>t.filter(s=>!pe.includes(s))),onPreviewFile:at})}),e.jsxs(Bt,{title:n("git.recentVersionsTitle"),count:P,expanded:ve==="history",onToggle:()=>oe("history"),trailingContent:e.jsx("span",{className:"badge",children:ct}),headerAction:e.jsx("button",{className:"git-icon-button git-mobile-section-action",type:"button","aria-label":n("git.operationMenu"),title:n("git.operationMenu"),"aria-expanded":ne,onClick:()=>{oe("history"),W(t=>!t)},disabled:N,children:e.jsx($e,{})}),children:[ne?e.jsx("div",{className:"git-mobile-operations-shell",children:En()}):null,e.jsx(ms,{history:b,historyLoadingMore:be,hasMore:!!X,actioning:N,openCommitHash:Se,onMenuTriggerRef:Ft,onToggleMenu:t=>Y(s=>s===t?null:t),onViewCommitChanges:t=>void De(t),onCopyCommitHash:t=>void V(t,n("git.copyCommitHashSuccess")),onCopyCommitMessage:t=>void V(xe(t),n("git.copyCommitMessageSuccess")),onCopyCommitVersion:t=>void Le(t),onExplainCommitChange:t=>void _e(t),onUndoLastCommit:()=>void he(),onLoadMore:()=>void tt()})]})]}):e.jsxs("div",{ref:mn,className:"git-content-split",style:{gridTemplateRows:_i},children:[e.jsx("section",{className:"git-card git-tree-panel",children:e.jsxs("div",{ref:hn,className:"git-tree-panel-body",children:[J.length>0?e.jsx($n,{title:n("git.stagedChangesTitle"),count:J.length,nodes:Tn,selectedPath:re,collapsedTreePathSet:ot,onToggleTreePath:st,onSelectFile:q,onPreviewFile:(t,s)=>{vn(t)&&at(t,s)},onToggleMobileSelection:rt,onStageToggle:nt,onDiscard:wt,actioning:N,variant:"staged",isMobileViewport:k,selectedMobilePathSet:lt,selectedTargets:fe,mobileActionMenuOpen:Ne==="staged",onToggleMobileActionMenu:()=>z(t=>t==="staged"?null:"staged"),onClearSelectedTargets:()=>I(t=>t.filter(s=>!fe.includes(s)))}):null,e.jsx($n,{title:n("git.changesTitle"),count:ge.length,nodes:Mn,selectedPath:re,collapsedTreePathSet:ot,onToggleTreePath:st,onSelectFile:q,onPreviewFile:(t,s)=>{vn(t)&&at(t,s)},onToggleMobileSelection:rt,onStageToggle:nt,onDiscard:wt,actioning:N,variant:"unstaged",isMobileViewport:k,selectedMobilePathSet:lt,selectedTargets:pe,mobileActionMenuOpen:Ne==="unstaged",onToggleMobileActionMenu:()=>z(t=>t==="unstaged"?null:"unstaged"),onClearSelectedTargets:()=>I(t=>t.filter(s=>!pe.includes(s)))})]})}),e.jsx("button",{className:"git-panel-divider",type:"button",role:"separator","aria-label":n("git.resizePanels"),"aria-orientation":"horizontal","aria-valuemin":Ln,"aria-valuemax":Gt,"aria-valuenow":te?_t:Gt,"data-dragging":Tt,onPointerDown:Ri,children:e.jsx("span",{className:"git-panel-divider-handle","aria-hidden":"true"})}),e.jsxs("section",{className:"git-card git-history-section",children:[e.jsxs("div",{className:"git-history-topbar",children:[e.jsxs("button",{className:"git-section-toggle",type:"button","aria-expanded":te,"aria-label":te?n("git.collapseRecentVersions"):n("git.expandRecentVersions"),onClick:()=>Jt(t=>!t),children:[e.jsxs("span",{className:"git-section-toggle-main",children:[e.jsx(pt,{expanded:te}),e.jsx("span",{children:n("git.recentVersionsTitle")})]}),e.jsx("span",{className:"workbench-section-counter",children:P})]}),e.jsxs("div",{className:"git-history-actions",children:[e.jsx("span",{className:"badge",children:ct}),e.jsx("button",{className:"git-icon-button",type:"button",ref:fn,"aria-label":n("git.operationMenu"),title:n("git.operationMenu"),onClick:()=>W(t=>!t),disabled:N,children:e.jsx($e,{})}),ne?En({desktopFloating:!0}):null]})]}),te?e.jsx(In,{history:b,historyLoadingMore:be,hasMore:!!X,actioning:N,openCommitHash:le,useNativeContextMenu:yn,onMenuTriggerRef:Ft,onScroll:bi,onToggleMenu:t=>{if(yn){const s=b.find(r=>r.commitHash===t);s&&Nn(s);return}Z(s=>s===t?null:t)},onOpenContextMenu:t=>void Nn(t),onViewCommitChanges:t=>void De(t),onCopyCommitHash:t=>void V(t,n("git.copyCommitHashSuccess")),onCopyCommitMessage:t=>void V(xe(t),n("git.copyCommitMessageSuccess")),onCopyCommitVersion:t=>void Le(t),onExplainCommitChange:t=>void _e(t),onUndoLastCommit:()=>void he(),onLoadMore:()=>void tt()}):null]})]}),e.jsxs(ke,{open:mi,title:Ve==="push"?n("git.selectRemoteTitle"):n("git.remoteAuthManageTitle"),description:Ve==="push"?n("git.selectRemoteDesc"):n("git.remoteAuthManageDescription"),onClose:()=>{N||ue(!1)},children:[e.jsx("div",{className:"git-remote-select-list",children:We.map(t=>{const s=Xe.has(t.name),r=gi.get(t.name),c=Hs(t,Ye[t.name]??null);return e.jsxs("div",{className:"git-remote-item",children:[Ve==="push"?e.jsxs("label",{className:"git-remote-item-selector",children:[e.jsx("input",{type:"checkbox",checked:s,disabled:N,onChange:()=>{qe(m=>{const w=new Set(m);return w.has(t.name)?w.delete(t.name):w.add(t.name),w})}}),e.jsxs("span",{className:"git-remote-item-body",children:[e.jsx("span",{className:"git-remote-name",children:t.name}),e.jsx("span",{className:"git-remote-url",children:t.pushUrl}),r&&e.jsx("span",{className:`git-remote-result ${r.ok?"ok":"err"}`,children:r.summary})]})]}):e.jsx("div",{className:"git-remote-item-selector git-remote-item-selector-static",children:e.jsxs("span",{className:"git-remote-item-body",children:[e.jsx("span",{className:"git-remote-name",children:t.name}),e.jsx("span",{className:"git-remote-url",children:t.pushUrl}),r&&e.jsx("span",{className:`git-remote-result ${r.ok?"ok":"err"}`,children:r.summary})]})}),e.jsxs("div",{className:"git-remote-item-meta",children:[e.jsx("span",{className:`git-remote-credential-badge ${c.kind}`,children:c.label}),e.jsx("button",{className:"secondary-button git-remote-inline-action",type:"button",disabled:N,onClick:()=>void it(t.name),children:n("git.remoteAuthAction")})]})]},t.name)})}),e.jsxs("div",{className:"git-remote-actions",children:[e.jsx("button",{className:"secondary-button",type:"button",disabled:N,onClick:()=>ue(!1),children:n("common.close")}),Ve==="push"?e.jsx("button",{className:"primary-button",type:"button",disabled:N||Xe.size===0,onClick:()=>void Cn(Array.from(Xe)),children:N?n("git.pushing"):n("git.pushSelected",{count:String(Xe.size)})}):null]})]}),e.jsxs(ke,{open:fi,title:n("git.remoteAuthTitle"),description:Pi,onClose:()=>{N||me(!1)},children:[ut?e.jsxs("div",{className:"git-remote-auth-target",children:[e.jsx("strong",{children:ut.name}),e.jsx("span",{children:ut.pushUrl||ut.fetchUrl})]}):null,e.jsxs("div",{className:"workbench-clone-form",children:[e.jsxs("label",{className:"workbench-modal-field",children:[e.jsx("span",{children:n("shell.cloneAuthModeLabel")}),e.jsxs("select",{value:D.authMode,disabled:N,onChange:t=>Q(s=>({...s,authMode:t.target.value})),children:[e.jsx("option",{value:"none",children:n("shell.cloneAuthModeNone")}),e.jsx("option",{value:"basic",children:n("shell.cloneAuthModeBasic")}),e.jsx("option",{value:"token",children:n("shell.cloneAuthModeToken")})]})]}),D.authMode==="basic"?e.jsxs(e.Fragment,{children:[e.jsxs("label",{className:"workbench-modal-field",children:[e.jsx("span",{children:n("shell.cloneUsernameLabel")}),e.jsx("input",{type:"text",value:D.username,placeholder:Li,autoComplete:"username",onChange:t=>Q(s=>({...s,username:t.target.value}))})]}),e.jsxs("label",{className:"workbench-modal-field",children:[e.jsx("span",{children:Ai}),e.jsx("input",{type:"password",value:D.password,placeholder:Di,autoComplete:"current-password",onChange:t=>Q(s=>({...s,password:t.target.value}))})]})]}):null,D.authMode==="token"?e.jsxs(e.Fragment,{children:[e.jsxs("label",{className:"workbench-modal-field",children:[e.jsx("span",{children:n("shell.cloneUsernameLabel")}),e.jsx("input",{type:"text",value:D.username,placeholder:n("shell.cloneTokenUsernamePlaceholder"),autoComplete:"username",onChange:t=>Q(s=>({...s,username:t.target.value}))})]}),e.jsxs("label",{className:"workbench-modal-field",children:[e.jsx("span",{children:n("shell.cloneTokenLabel")}),e.jsx("input",{type:"password",value:D.token,placeholder:n("shell.cloneTokenPlaceholder"),autoComplete:"current-password",onChange:t=>Q(s=>({...s,token:t.target.value}))})]})]}):null,Oe?e.jsx("p",{className:"git-remote-auth-hint",children:n("git.remoteAuthGithubPatHint")}):null,D.authMode!=="none"?e.jsxs("label",{className:"settings-checkbox git-remote-auth-remember-toggle",children:[e.jsx("input",{type:"checkbox",checked:D.rememberOnHost,onChange:t=>Q(s=>({...s,rememberOnHost:t.target.checked}))}),e.jsx("span",{children:n("git.remoteAuthRemember")})]}):null,e.jsx("p",{className:"git-remote-auth-hint",children:n("git.remoteAuthSessionHint")})]}),e.jsxs("div",{className:"git-remote-actions",children:[e.jsx("button",{className:"secondary-button",type:"button",disabled:N,onClick:()=>me(!1),children:n("common.close")}),e.jsx("button",{className:"primary-button",type:"button",disabled:N,onClick:vi,children:n("git.remoteAuthSave")})]})]}),e.jsx(ke,{open:li,title:n("git.viewAllVersions"),description:n("git.viewAllVersionsDescription",{count:String(P)}),onClose:()=>yt(!1),children:e.jsx(In,{history:b,historyLoadingMore:be,hasMore:!!X,actioning:N,openCommitHash:le,className:"git-history-modal-list",onMenuTriggerRef:Ft,onToggleMenu:t=>Z(s=>s===t?null:t),onViewCommitChanges:t=>void De(t),onCopyCommitHash:t=>void V(t,n("git.copyCommitHashSuccess")),onCopyCommitMessage:t=>void V(xe(t),n("git.copyCommitMessageSuccess")),onCopyCommitVersion:t=>void Le(t),onExplainCommitChange:t=>void _e(t),onUndoLastCommit:()=>void he(),onLoadMore:()=>void tt()})}),e.jsx(ke,{open:ci!==null,className:"git-commit-detail-modal",title:(_==null?void 0:_.subject)||n("git.commitDetailTitle"),description:_?n("git.commitDetailDescription",{hash:_.shortHash}):n("git.commitDetailLoading"),onClose:Ti,children:ui?e.jsx("div",{className:"git-commit-detail-state",children:e.jsx("p",{children:n("git.commitDetailLoading")})}):en?e.jsx("div",{className:"git-commit-detail-state is-error",children:e.jsx("p",{children:en})}):_?e.jsxs("div",{className:"git-commit-detail-shell",children:[e.jsxs("div",{className:"git-commit-detail-meta-grid",children:[e.jsxs("div",{className:"git-commit-detail-meta-card",children:[e.jsx("span",{children:n("git.commitVersionLabel")}),e.jsx("strong",{children:_.versionLabel})]}),e.jsxs("div",{className:"git-commit-detail-meta-card",children:[e.jsx("span",{children:n("git.commitHashLabel")}),e.jsx("strong",{children:_.commitHash})]}),e.jsxs("div",{className:"git-commit-detail-meta-card",children:[e.jsx("span",{children:n("git.commitAuthorLabel")}),e.jsx("strong",{children:_.authorName})]}),e.jsxs("div",{className:"git-commit-detail-meta-card",children:[e.jsx("span",{children:n("git.commitTimeLabel")}),e.jsx("strong",{children:ys(_.authoredAt)})]})]}),e.jsxs("section",{className:"git-commit-detail-section",children:[e.jsx("div",{className:"git-commit-detail-section-header",children:e.jsx("h3",{children:n("git.commitMessageLabel")})}),e.jsx("pre",{className:"git-commit-detail-message",children:xe(_)})]}),e.jsxs("section",{className:"git-commit-detail-section",children:[e.jsxs("div",{className:"git-commit-detail-section-header",children:[e.jsx("h3",{children:n("git.changedFilesTitle")}),e.jsx("span",{className:"workbench-section-counter",children:_.changedFiles.length})]}),e.jsx("div",{className:"git-commit-detail-file-list",children:_.changedFiles.map(t=>e.jsxs("div",{className:"git-commit-detail-file-item",children:[e.jsx("span",{className:"git-commit-detail-file-status","data-status":t.status,children:t.status}),e.jsxs("div",{className:"git-commit-detail-file-copy",children:[e.jsx("strong",{children:t.path}),t.oldPath?e.jsx("span",{children:n("git.renamedFromLabel",{path:t.oldPath})}):null]})]},`${t.status}:${t.oldPath??""}:${t.path}`))})]}),e.jsxs("section",{className:"git-commit-detail-section",children:[e.jsxs("div",{className:"git-commit-detail-section-header",children:[e.jsx("h3",{children:n("git.commitDiffLabel")}),_.diffTruncated?e.jsx("span",{className:"git-commit-detail-truncated",children:n("git.diffTruncated")}):null]}),e.jsx("pre",{className:"git-commit-detail-diff",children:_.diffContent||n("git.emptyDiff")})]})]}):e.jsx("div",{className:"git-commit-detail-state",children:e.jsx("p",{children:n("git.commitDetailEmpty")})})}),e.jsx(ke,{open:di,className:"git-explain-provider-modal",title:n("git.explainCommitTitle"),description:n("git.explainCommitDescription"),onClose:()=>{ie||(He(!1),Me(null),ce(null))},children:e.jsxs("div",{className:"git-explain-provider-shell",children:[e.jsx(Vi,{workspaceId:i,selectedProvider:Ee,pendingProvider:ie?Ee:null,disabled:ie,onSelect:t=>ce(t)}),e.jsxs("div",{className:"git-explain-provider-actions",children:[e.jsx("button",{type:"button",className:"secondary-button",disabled:ie,onClick:()=>{He(!1),Me(null),ce(null)},children:n("common.cancel")}),e.jsx("button",{type:"button",className:"primary-button",disabled:!Ee||ie,onClick:()=>void Hi(),children:ie?n("conversation.sendingState"):n("git.startExplainCommit")})]})]})}),e.jsx(Wi,{workspaceId:i,filePath:un,open:un!==null,onClose:()=>{Re(null),we(null)},onSaved:async()=>{await Rt({resetTreeScroll:!0})},diffContent:pi}),Oi()]})}function $n({title:a,count:i,nodes:u,selectedPath:h,collapsedTreePathSet:g,onToggleTreePath:C,onSelectFile:f,onPreviewFile:y,onToggleMobileSelection:x,onStageToggle:v,onDiscard:H,actioning:S,variant:T,isMobileViewport:p,selectedMobilePathSet:o,selectedTargets:d,mobileActionMenuOpen:j,onToggleMobileActionMenu:E,onClearSelectedTargets:R}){const b=Zn(),F=Zt(u),P=T==="staged"?n("git.unstageAll"):n("git.stageAll");return e.jsxs("section",{className:"git-tree-group","data-variant":T,children:[e.jsxs("div",{className:"git-section-header git-tree-group-header",children:[e.jsx("h3",{children:a}),e.jsxs("div",{className:"git-tree-group-actions",children:[e.jsx("span",{className:"workbench-section-counter",children:i}),!p&&F.length>0?e.jsxs(e.Fragment,{children:[e.jsx("button",{className:"git-icon-button",type:"button","aria-label":P,title:P,onClick:()=>void v(F,T==="staged"),disabled:S,children:e.jsx(qt,{staged:T==="staged"})}),T==="unstaged"?e.jsx("button",{className:"git-icon-button danger",type:"button","aria-label":n("git.discardAll"),title:n("git.discardAll"),onClick:()=>void H(F),disabled:S,children:e.jsx(Yt,{})}):null]}):null,p&&d.length>0?e.jsx("button",{className:"git-icon-button",type:"button","aria-label":n("git.operationMenu"),title:n("git.operationMenu"),onClick:E,disabled:S,children:e.jsx($e,{})}):null]}),p&&j?e.jsxs("div",{className:"git-selection-menu",children:[e.jsxs("div",{className:"git-menu-section",children:[e.jsx("span",{className:"git-menu-caption",children:n("git.selectedFiles")}),e.jsx("strong",{className:"git-menu-branch",children:d.length})]}),e.jsxs("div",{className:"git-menu-section",children:[e.jsx("button",{className:"git-menu-item",type:"button",disabled:S,onClick:()=>void v(d,T==="staged"),children:e.jsx("span",{children:T==="staged"?n("git.unstage"):n("git.stage")})}),T==="unstaged"?e.jsx("button",{className:"git-menu-item",type:"button",disabled:S,onClick:()=>void H(d),children:e.jsx("span",{children:n("git.discard")})}):null,e.jsx("button",{className:"git-menu-item",type:"button",disabled:S,onClick:R,children:e.jsx("span",{children:n("git.clearSelection")})})]})]}):null]}),e.jsx("div",{ref:b,className:"git-tree-shell",role:"tree","aria-label":a,"data-scrollbar-autohide":"true",children:u.length?Jn({nodes:u,depth:0,collapsedTreePathSet:g,selectedPath:h,onToggleTreePath:C,onSelectFile:f,onPreviewFile:y,onToggleMobileSelection:x,onStageToggle:v,onDiscard:H,actioning:S,variant:T,isMobileViewport:p,selectedMobilePathSet:o}):e.jsx("p",{className:"git-tree-status",children:n("git.noChanges")})})]})}function Bt({title:a,count:i,expanded:u,onToggle:h,trailingContent:g,headerAction:C,children:f}){return e.jsxs("section",{className:"git-mobile-section","data-expanded":u,children:[e.jsxs("div",{className:"git-mobile-section-header",children:[e.jsxs("button",{className:"git-mobile-section-toggle",type:"button","aria-expanded":u,onClick:h,children:[e.jsxs("span",{className:"git-mobile-section-toggle-main",children:[e.jsx(pt,{expanded:u}),e.jsx("h3",{children:a})]}),e.jsxs("span",{className:"git-mobile-section-toggle-meta",children:[g,e.jsx("span",{className:"workbench-section-counter",children:i})]})]}),C?e.jsx("div",{className:"git-mobile-section-header-action",children:C}):null]}),u?e.jsx("div",{className:"git-mobile-section-body",children:f}):null]})}function Un({title:a,nodes:i,collapsedTreePathSet:u,onToggleTreePath:h,onToggleMobileSelection:g,selectedMobilePathSet:C,selectedTargets:f,actioning:y,variant:x,swipeRowState:v,onSwipeRowChange:H,onStageToggle:S,onDiscardWithConfirm:T,onClearSelectedTargets:p,onPreviewFile:o}){return e.jsxs("div",{className:"git-mobile-record-shell",children:[f.length>0?e.jsxs("div",{className:"git-mobile-selection-toolbar",children:[e.jsxs("span",{className:"git-mobile-selection-count",children:[n("git.selectedFiles")," ",f.length]}),e.jsxs("div",{className:"git-mobile-selection-actions",children:[e.jsx("button",{type:"button",className:"secondary-button",disabled:y,onClick:()=>void S(f,x==="staged"),children:x==="staged"?n("git.unstage"):n("git.stage")}),x==="unstaged"?e.jsx("button",{type:"button",className:"secondary-button workbench-danger-button",disabled:y,onClick:()=>void T(f,`${f.length}`),children:n("git.discard")}):null,e.jsx("button",{type:"button",className:"secondary-button",disabled:y,onClick:p,children:n("git.clearSelection")})]})]}):null,e.jsx("div",{className:"git-mobile-record-list",role:"tree","aria-label":a,children:i.length?Qn({nodes:i,depth:0,collapsedTreePathSet:u,onToggleTreePath:h,onToggleMobileSelection:g,selectedMobilePathSet:C,actioning:y,variant:x,swipeRowState:v,onSwipeRowChange:H,onStageToggle:S,onDiscardWithConfirm:T,onPreviewFile:o}):e.jsx("p",{className:"git-tree-status",children:n("git.noChanges")})})]})}function Qn({nodes:a,depth:i,collapsedTreePathSet:u,onToggleTreePath:h,onToggleMobileSelection:g,selectedMobilePathSet:C,actioning:f,variant:y,swipeRowState:x,onSwipeRowChange:v,onStageToggle:H,onDiscardWithConfirm:S,onPreviewFile:T}){return a.map(p=>{if(p.kind==="directory"){const j=!u.has(p.path),E=Zt(p.children),R=`directory:${p.path}`;return e.jsxs("div",{className:"git-mobile-record-branch",children:[e.jsx(Bn,{rowKey:R,openState:(x==null?void 0:x.path)===R?x.direction:null,onOpenStateChange:b=>v(b?{path:R,direction:b}:null),trailingActions:E.length>0?[{label:y==="staged"?n("git.unstage"):n("git.stage"),tone:"accent",onPress:()=>void H(E,y==="staged")},...y==="unstaged"?[{label:n("git.discard"),tone:"danger",onPress:()=>void S(E,p.path)}]:[]]:null,children:e.jsxs("button",{className:"git-mobile-record git-mobile-record-directory",type:"button",style:{paddingInlineStart:`${kn+i*Gn}px`},onClick:()=>h(p.path),children:[e.jsxs("span",{className:"git-mobile-record-leading",children:[e.jsx("span",{className:"git-tree-chevron","data-expanded":j,children:e.jsx(pt,{expanded:j})}),e.jsx("span",{className:"git-mobile-record-title",children:p.name})]}),e.jsx("span",{className:"git-mobile-record-meta",children:E.length})]})}),j?e.jsx("div",{className:"git-mobile-record-children",role:"group",children:Qn({nodes:p.children,depth:i+1,collapsedTreePathSet:u,onToggleTreePath:h,onToggleMobileSelection:g,selectedMobilePathSet:C,actioning:f,variant:y,swipeRowState:x,onSwipeRowChange:v,onStageToggle:H,onDiscardWithConfirm:S,onPreviewFile:T})}):null]},R)}const o=`file:${p.path}`,d=C.has(p.path);return e.jsx(Bn,{rowKey:o,openState:(x==null?void 0:x.path)===o?x.direction:null,onOpenStateChange:j=>v(j?{path:o,direction:j}:null),trailingActions:[{label:n("git.preview"),tone:"neutral",onPress:()=>T(p.change.path,p.change)},{label:y==="staged"?n("git.unstage"):n("git.stage"),tone:"accent",onPress:()=>void H([p.change.path],y==="staged")},...y==="unstaged"?[{label:n("git.discard"),tone:"danger",onPress:()=>void S([p.change.path],p.path)}]:[]],children:e.jsxs("div",{className:"git-mobile-record git-mobile-record-file","data-active":d,style:{paddingInlineStart:`${kn+i*Gn}px`},children:[e.jsx("input",{className:"git-tree-select-checkbox",type:"checkbox",checked:d,"aria-label":`${n("git.selectFile")} ${p.name}`,onChange:()=>g(p.change.path)}),e.jsxs("button",{className:"git-mobile-record-file-main",type:"button",onClick:()=>g(p.change.path),children:[e.jsx("span",{className:"git-tree-file-icon","data-kind":zt(p.name),"aria-hidden":"true",children:Wt(p.name)}),e.jsxs("span",{className:"git-mobile-record-copy",children:[e.jsx("span",{className:"git-mobile-record-title",children:p.name}),e.jsx("span",{className:"git-mobile-record-path",children:p.path})]}),e.jsx("span",{className:"git-status-badge","data-status":p.status,children:p.status})]})]})},o)})}function Bn({rowKey:a,openState:i,onOpenStateChange:u,trailingActions:h,children:g}){const C=cs(),f=l.useRef(null),[y,x]=l.useState(0),v=((h==null?void 0:h.length)??0)*$t;l.useEffect(()=>{i||x(0)},[i,a]);const H=y!==0?y:i==="trailing"?-v:0;function S(d){var j,E;d.button===0&&(f.current={pointerId:d.pointerId,startX:d.clientX},(E=(j=d.currentTarget).setPointerCapture)==null||E.call(j,d.pointerId))}function T(d){const j=f.current;if(!j||j.pointerId!==d.pointerId)return;const E=v>0?v+10:0,R=Math.max(-E,Math.min(0,d.clientX-j.startX));x(R)}function p(d){var E,R;const j=f.current;if(!(!j||j.pointerId!==d.pointerId)){if((R=(E=d.currentTarget).releasePointerCapture)==null||R.call(E,d.pointerId),f.current=null,y<=-44&&(h!=null&&h.length)){C.trigger("gesture"),u("trailing"),x(0);return}u(null),x(0)}}function o(d){var E,R;const j=f.current;!j||j.pointerId!==d.pointerId||((R=(E=d.currentTarget).releasePointerCapture)==null||R.call(E,d.pointerId),f.current=null,x(0))}return e.jsxs("div",{className:"git-mobile-swipe-row","data-open-state":i??"closed","data-dragging":y!==0,children:[h==null?void 0:h.map((d,j)=>e.jsx("button",{type:"button",className:"git-mobile-swipe-action trailing","data-tone":d.tone,style:{right:j*$t,width:$t},onClick:()=>{C.trigger(d.tone==="danger"?"warning":"action"),u(null),d.onPress()},children:d.label},`trailing-${j}`)),e.jsx("div",{className:"git-mobile-swipe-content",style:{transform:`translateX(${H}px)`},onPointerDown:S,onPointerMove:T,onPointerUp:p,onPointerCancel:o,children:g})]})}function ms({history:a,historyLoadingMore:i,hasMore:u,actioning:h,openCommitHash:g,onMenuTriggerRef:C,onToggleMenu:f,onViewCommitChanges:y,onCopyCommitHash:x,onCopyCommitMessage:v,onCopyCommitVersion:H,onExplainCommitChange:S,onUndoLastCommit:T,onLoadMore:p}){return a.length?e.jsxs("div",{className:"git-mobile-history-list",children:[a.map(o=>e.jsx("article",{className:"git-mobile-history-entry","data-kind":o.commitKind,children:e.jsxs("div",{className:"git-mobile-history-entry-main",children:[e.jsx("span",{className:"git-history-marker","data-kind":o.commitKind,"aria-hidden":"true"}),e.jsxs("div",{className:"git-mobile-history-copy",children:[e.jsxs("div",{className:"git-history-title-row",children:[e.jsx("strong",{title:o.subject,children:o.subject}),e.jsx("span",{className:"git-history-kind-badge","data-kind":o.commitKind,children:ii(o.commitKind)})]}),o.refs.length>0?e.jsx("div",{className:"git-history-ref-list",children:o.refs.map(d=>e.jsx("span",{className:"git-history-ref-pill","data-kind":d.kind,"data-remote-index":String(si(d.remoteName)),children:d.name},`${o.commitHash}:${d.kind}:${d.name}`))}):null,e.jsxs("div",{className:"git-history-meta",children:[e.jsx("span",{className:"git-history-hash",children:o.commitHash.slice(0,8)}),e.jsx("span",{children:o.authorName}),e.jsx("time",{dateTime:o.authoredAt,children:ai(o.authoredAt)})]})]}),e.jsx("button",{type:"button",className:"git-icon-button",ref:d=>C(o.commitHash,d),"aria-label":n("git.historyItemMenu"),onClick:()=>f(o.commitHash),children:e.jsx($e,{})})]})},o.commitHash)),u?e.jsx("button",{type:"button",className:"secondary-button git-mobile-history-more",disabled:i,onClick:p,children:i?`${n("git.refreshNow")}...`:n("common.loadMore")}):null]}):e.jsx("p",{className:"git-tree-status",children:n("git.noHistory")})}function In({history:a,historyLoadingMore:i,hasMore:u,actioning:h,openCommitHash:g,className:C,useNativeContextMenu:f=!1,onMenuTriggerRef:y,onScroll:x,onToggleMenu:v,onOpenContextMenu:H,onViewCommitChanges:S,onCopyCommitHash:T,onCopyCommitMessage:p,onCopyCommitVersion:o,onExplainCommitChange:d,onUndoLastCommit:j,onLoadMore:E}){const R=Zn();return a.length?e.jsxs("div",{ref:R,className:["git-history-list",C].filter(Boolean).join(" "),onScroll:x,"data-scrollbar-autohide":"true",children:[a.map(b=>{const F=g===b.commitHash;return e.jsxs("article",{className:"git-history-entry","data-kind":b.commitKind,"data-menu-open":F?"true":"false",onContextMenu:P=>{!f||!H||(P.preventDefault(),P.stopPropagation(),H(b))},children:[e.jsx("span",{className:"git-history-marker","data-kind":b.commitKind,"aria-hidden":"true"}),e.jsxs("div",{className:"git-history-body",children:[e.jsxs("div",{className:"git-history-title-row",children:[e.jsx("strong",{title:b.subject,children:b.subject}),e.jsxs("div",{className:"git-history-title-actions",children:[e.jsx("span",{className:"git-history-kind-badge","data-kind":b.commitKind,children:ii(b.commitKind)}),f?null:e.jsx("button",{type:"button",className:"git-icon-button git-history-more",ref:P=>y(b.commitHash,P),"aria-label":n("git.historyItemMenu"),onClick:()=>{v(b.commitHash)},children:e.jsx($e,{})})]})]}),b.refs.length>0?e.jsx("div",{className:"git-history-ref-list",children:b.refs.map(P=>e.jsx("span",{className:"git-history-ref-pill","data-kind":P.kind,"data-remote-index":String(si(P.remoteName)),children:P.name},`${b.commitHash}:${P.kind}:${P.name}`))}):null,e.jsxs("div",{className:"git-history-meta",children:[e.jsx("span",{className:"git-history-hash",children:b.commitHash.slice(0,8)}),e.jsx("span",{children:b.authorName}),e.jsx("time",{dateTime:b.authoredAt,children:ai(b.authoredAt)})]})]})]},b.commitHash)}),i?e.jsxs("p",{className:"git-history-loading",children:[n("git.refreshNow"),"..."]}):null,u?e.jsx("button",{type:"button",className:"secondary-button git-mobile-history-more",disabled:i,onClick:E,children:i?`${n("git.refreshNow")}...`:n("common.loadMore")}):null]}):e.jsx("p",{className:"status-text",children:n("git.noHistory")})}function hs({item:a,canUndo:i,actioning:u,onViewCommitChanges:h,onCopyCommitHash:g,onCopyCommitMessage:C,onCopyCommitVersion:f,onExplainCommitChange:y,onUndoLastCommit:x}){return e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",className:"git-menu-item",onClick:()=>h(a.commitHash),children:e.jsx("span",{children:n("git.viewCommitChanges")})}),e.jsx("button",{type:"button",className:"git-menu-item",onClick:()=>g(a.commitHash),children:e.jsx("span",{children:n("git.copyCommitHash")})}),e.jsx("button",{type:"button",className:"git-menu-item",onClick:()=>C(a),children:e.jsx("span",{children:n("git.copyCommitMessage")})}),e.jsx("button",{type:"button",className:"git-menu-item",onClick:()=>f(a.commitHash),children:e.jsx("span",{children:n("git.copyCommitVersion")})}),e.jsx("button",{type:"button",className:"git-menu-item",onClick:()=>y(a.commitHash),children:e.jsx("span",{children:n("git.explainCommitAction")})}),i?e.jsx("button",{type:"button",className:"git-menu-item",disabled:u,onClick:x,children:e.jsx("span",{children:n("git.undoLastCommit")})}):null]})}function Jn({nodes:a,depth:i,collapsedTreePathSet:u,selectedPath:h,onToggleTreePath:g,onSelectFile:C,onPreviewFile:f,onToggleMobileSelection:y,onStageToggle:x,onDiscard:v,actioning:H,variant:S,isMobileViewport:T,selectedMobilePathSet:p}){return a.map(o=>{if(o.kind==="directory"){const E=!u.has(o.path),R=Zt(o.children),b=`${S==="staged"?n("git.unstage"):n("git.stage")} ${o.path}`,F=`${n("git.discard")} ${o.path}`;return e.jsxs("div",{className:"git-tree-node",children:[e.jsxs("div",{className:"git-tree-row",role:"treeitem","aria-expanded":E,children:[e.jsxs("button",{className:"git-tree-trigger",type:"button",style:{paddingInlineStart:`${6+i*8}px`},onClick:()=>g(o.path),children:[e.jsx("span",{className:"git-tree-chevron","data-expanded":E,children:e.jsx(pt,{expanded:E})}),e.jsx("span",{className:"git-tree-label git-tree-label-directory",children:o.name})]}),!T&&R.length>0?e.jsxs("div",{className:"git-row-actions",children:[e.jsx("button",{className:"git-icon-button",type:"button","aria-label":b,title:b,onClick:()=>void x(R,S==="staged"),disabled:H,children:e.jsx(qt,{staged:S==="staged"})}),S==="unstaged"?e.jsx("button",{className:"git-icon-button danger",type:"button","aria-label":F,title:F,onClick:()=>void v(R),disabled:H,children:e.jsx(Yt,{})}):null]}):null]}),E?e.jsx("div",{className:"git-tree-children",role:"group",children:Jn({nodes:o.children,depth:i+1,collapsedTreePathSet:u,selectedPath:h,onToggleTreePath:g,onSelectFile:C,onPreviewFile:f,onToggleMobileSelection:y,onStageToggle:x,onDiscard:v,actioning:H,variant:S,isMobileViewport:T,selectedMobilePathSet:p})}):null]},`directory:${o.path}`)}const d=p.has(o.path),j=T?d:h===o.path;return T?e.jsxs("div",{className:"git-tree-row",role:"treeitem","data-active":j,"data-mobile":"true",children:[e.jsx("input",{className:"git-tree-select-checkbox",type:"checkbox",checked:d,"aria-label":`${n("git.selectFile")} ${o.name}`,onChange:()=>y(o.change.path)}),e.jsxs("button",{className:"git-tree-file-button",type:"button","data-active":j,"data-mobile":"true",style:{paddingInlineStart:`${18+i*8}px`},onClick:()=>y(o.change.path),children:[e.jsx("span",{className:"git-tree-file-icon","data-kind":zt(o.name),"aria-hidden":"true",children:Wt(o.name)}),e.jsx("span",{className:"git-tree-label-wrap",children:e.jsx("span",{className:"git-tree-label",children:o.name})}),e.jsx("span",{className:"git-tree-file-meta",children:e.jsx("span",{className:"git-status-badge","data-status":o.status,children:o.status})})]})]},`file:${o.path}`):e.jsxs("div",{className:"git-tree-row",role:"treeitem","data-active":j,children:[e.jsxs("button",{className:"git-tree-file-button",type:"button","data-active":j,style:{paddingInlineStart:`${18+i*8}px`},onClick:()=>{C(o.change.path),f&&f(o.change.path,o.change)},children:[e.jsx("span",{className:"git-tree-file-icon","data-kind":zt(o.name),"aria-hidden":"true",children:Wt(o.name)}),e.jsx("span",{className:"git-tree-label-wrap",children:e.jsx("span",{className:"git-tree-label",children:o.name})}),e.jsx("span",{className:"git-tree-file-meta",children:e.jsx("span",{className:"git-status-badge","data-status":o.status,children:o.status})})]}),e.jsxs("div",{className:"git-row-actions",children:[e.jsx("button",{className:"git-icon-button",type:"button","aria-label":o.variant==="staged"?n("git.unstage"):n("git.stage"),title:o.variant==="staged"?n("git.unstage"):n("git.stage"),onClick:()=>void x([o.change.path],o.variant==="staged"),disabled:H,children:e.jsx(qt,{staged:o.variant==="staged"})}),S==="unstaged"?e.jsx("button",{className:"git-icon-button danger",type:"button","aria-label":n("git.discard"),title:n("git.discard"),onClick:()=>void v([o.change.path]),disabled:H,children:e.jsx(Yt,{})}):null]})]},`file:${o.path}`)})}function Vn(a,i){return{kind:"directory",name:a,path:i,children:new Map}}function Wn(a,i){const u=Vn("","");for(const h of a){const g=h.path.replace(/\\/g,"/"),C=g.split("/").filter(Boolean);let f=u;C.forEach((y,x)=>{const v=C.slice(0,x+1).join("/");if(x===C.length-1){f.children.set(`file:${v}`,{kind:"file",name:y,path:g,change:h,status:gs(h,i),variant:i});return}const H=`directory:${v}`,S=f.children.get(H);if(S&&S.kind==="directory"){f=S;return}const T=Vn(y,v);f.children.set(H,T),f=T})}return ti(ei([...u.children.values()]))}function ei(a){return[...a].sort((i,u)=>i.kind!==u.kind?i.kind==="directory"?-1:1:i.name.localeCompare(u.name,"zh-CN")).map(i=>i.kind==="directory"?{kind:"directory",name:i.name,path:i.path,children:ei([...i.children.values()])}:i)}function ti(a){return a.map(i=>{var f;if(i.kind!=="directory")return i;const u=ti(i.children);let h=i.name,g=i.path,C=u;for(;C.length===1&&((f=C[0])==null?void 0:f.kind)==="directory";){const y=C[0];h=`${h}/${y.name}`,g=y.path,C=y.children}return{kind:"directory",name:h,path:g,children:C}})}function zn(a,i,u){const h=new Set(a);return i.filter(g=>Xt(g,u)&&h.has(g.path)).map(g=>g.path)}function Zt(a){const i=[],u=new Set;function h(g){if(g.kind==="file"){u.has(g.path)||(u.add(g.path),i.push(g.path));return}g.children.forEach(h)}return a.forEach(h),i}function Xt(a,i){return i==="staged"?!!a.stagedStatus:!!a.worktreeStatus}function gs(a,i){return i==="staged"?a.stagedStatus??a.status:a.worktreeStatus??a.status}function fs(a){return{subject:ni(a).trim(),body:null,footer:null,source:"manual"}}function ni(a){return a.replace(/[\r\n]+/g," ")}function ps(a){if(typeof document>"u"||typeof document.execCommand!="function")return!1;const i=document.createElement("textarea");i.value=a,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 xe(a){const i=a.subject.trim(),u=a.body.trim();return u?`${i}
2
+
3
+ ${u}`:i}function xs(a){const i=a.changedFiles.map(g=>`- [${g.status}] ${g.path}${g.oldPath?` (from ${g.oldPath})`:""}`).join(`
4
+ `),u=a.diffContent.length>Ut?a.diffContent.slice(0,Ut):a.diffContent,h=a.diffContent.length>Ut||a.diffTruncated?`
5
+ 注意:diff 内容过长,下面已经截断,只分析可见部分,同时明确指出可能遗漏的区域。`:"";return["请你分析下面这个 Git 提交。","输出要求:","1. 先用 3 到 5 句话说明这次改动的核心目的。","2. 按文件说明关键改动点,不要泛泛而谈。","3. 指出潜在风险、边界情况和可能的回归点。","4. 如果提交信息写得差,给出一条更合适的中文提交说明。","",`版本号:${a.versionLabel}`,`Commit Hash:${a.commitHash}`,`提交标题:${a.subject}`,`提交作者:${a.authorName} <${a.authorEmail}>`,`提交时间:${a.authoredAt}`,"","变更文件:",i||"- 无",h,"","Diff:",u||"(empty diff)"].join(`
6
+ `)}function bs(a){if(!a)return;a.style.height="0px";const i=Math.min(Math.max(a.scrollHeight,34),120);a.style.height=`${i}px`,a.style.overflowY=a.scrollHeight>120?"auto":"hidden"}function ii(a){switch(a){case"local":return n("git.historyKindLocal");case"remote":return n("git.historyKindRemote");default:return n("git.historyKindShared")}}function si(a){if(!a)return 0;let i=0;for(const u of a)i=i*33+u.charCodeAt(0)>>>0;return i%6}function ys(a){const i=Date.parse(a);return Number.isNaN(i)?a:new Intl.DateTimeFormat("zh-CN",{month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",hour12:!1}).format(i)}function L(a,i){return a instanceof Yn?vs(a)??a.message:typeof a=="object"&&a&&"message"in a?a.message:i}function js(a){const i=a==null?void 0:a.targetHostId;return typeof i=="string"&&i.trim()?i.trim():null}function Cs(a,i){return((a==null?void 0:a.trim())||null)===((i==null?void 0:i.trim())||null)}function Ge(a,i){return`git-sidebar.snapshot.${i!=null&&i.trim()?`host.${encodeURIComponent(i.trim())}.`:""}${a}`}function It(a){return a?!!(a.status||a.branches||a.history.length>0||a.historyTotalCount>0||a.historyNextCursor||a.revision):!1}function Ns(a){return a?a.snapshot.enabled!==!1:!0}function vs(a){switch(a.errorCode){case"UNAUTHORIZED":return n("git.errors.unauthorized");case"WORKSPACE_NOT_FOUND":return n("git.errors.workspaceNotFound");case"INVALID_WORKSPACE":return n("git.errors.invalidWorkspace");case"NOT_GIT_REPOSITORY":return n("git.errors.notGitRepository");case"GIT_REPO_NOT_FOUND":return n("git.errors.repoNotFound");case"PATH_OUT_OF_WORKSPACE":return n("git.errors.pathOutOfWorkspace");case"INVALID_TARGET":return n("git.errors.invalidTarget");case"NOT_STAGED":return n("git.errors.notStaged");case"EMPTY_STAGED_CHANGES":return n("git.errors.emptyStagedChanges");case"BRANCH_CONFLICT":return n("git.errors.branchConflict");case"BRANCH_NOT_FOUND":return n("git.errors.branchNotFound");case"REMOTE_NOT_FOUND":return n("git.errors.remoteNotFound");case"GIT_REMOTE_AUTH_FAILED":return n("git.errors.remoteAuthFailed");case"GIT_PUSH_FAILED":return n("git.errors.pushFailed");case"GIT_PULL_FAILED":return n("git.errors.pullFailed");case"GIT_REMOTE_FAILED":return n("git.errors.remoteFailed");case"GIT_COMMAND_TIMEOUT":return n("git.errors.commandTimeout");case"GIT_INIT_FAILED":return n("git.errors.initFailed");case"GIT_DISCARD_FAILED":return n("git.discardFailed");case"GIT_UNDO_FAILED":return n("git.undoLastCommitFailed");default:return null}}function Kn(a){return a instanceof Yn&&a.errorCode==="GIT_REMOTE_AUTH_FAILED"}function Ss(a,i=!1){return!a||!a.mode||a.mode==="none"?gt:a.mode==="basic"?{authMode:"basic",username:a.username??"",password:a.password??"",token:"",rememberOnHost:i}:a.mode==="token"?{authMode:"token",username:a.username??"",password:"",token:a.token??"",rememberOnHost:i}:gt}function Ts(a){return a.authMode==="none"?null:a.authMode==="basic"?{mode:"basic",username:a.username.trim(),password:a.password}:{mode:"token",username:a.username.trim()||void 0,token:a.token}}function Ms(a,i){const u=ft(a,i);if(!u)return"generic";const h=u.pushUrl||u.fetchUrl;return Es(h)?"github":"generic"}function ft(a,i){return a.find(u=>u.name===i)??a.find(u=>u.name==="origin")??a[0]??null}function Xn(a){var i;return(i=ft(a))==null?void 0:i.name}function Hs(a,i){return i!=null&&i.auth?{kind:"session",label:n("git.remoteAuthConfiguredInSession")}:a.credentialConfigured?{kind:"host",label:n("git.remoteAuthConfiguredOnHost")}:{kind:"missing",label:n("git.remoteAuthNotConfigured")}}function Es(a){const i=(a==null?void 0:a.trim().toLowerCase())??"";return i.startsWith("https://github.com/")||i.startsWith("http://github.com/")||i.startsWith("ssh://git@github.com/")||i.startsWith("git@github.com:")}function qn(a,i,u){const h=Math.max(0,u.width),g=Math.max(0,u.height),C=Math.max(0,g-O*2),f=Math.max(0,h-O*2),y=Math.min(Math.max(i.width||Kt,0),f),x=Math.max(0,g-a.bottom-ht-O),v=Math.max(0,a.top-ht-O),H=x<i.height&&v>x,T=Vt(Math.max(H?v:x,ds),0,C),p=Math.min(Math.max(i.height,0),T),o=H?a.top-ht-p:a.bottom+ht,d=Math.max(O,g-O-p),j=Math.max(O,h-O-y);return{top:Vt(o,O,d),left:Vt(a.right-y,O,j),maxHeight:Math.max(0,T),transformOrigin:`${H?"bottom":"top"} right`}}function Vt(a,i,u){return!Number.isFinite(a)||u<i?i:Math.min(Math.max(a,i),u)}function pt({expanded:a}){return e.jsx("svg",{className:"git-chevron-icon",width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",style:{transform:a?"rotate(0deg)":"rotate(-90deg)"},"aria-hidden":"true",children:e.jsx("polyline",{points:"6 9 12 15 18 9"})})}function qt({staged:a}){return a?e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2","aria-hidden":"true",children:e.jsx("path",{d:"M5 12h14"})}):e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2","aria-hidden":"true",children:[e.jsx("path",{d:"M12 5v14"}),e.jsx("path",{d:"M5 12h14"})]})}function Yt(){return e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2","aria-hidden":"true",children:[e.jsx("path",{d:"M10 7L6 11l4 4",strokeLinecap:"round",strokeLinejoin:"round"}),e.jsx("path",{d:"M7 11h7c3.87 0 7 3.13 7 7 0 1.9-.76 3.63-2 4.89",strokeLinecap:"round",strokeLinejoin:"round"})]})}function Rs(){return e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2","aria-hidden":"true",children:e.jsx("path",{d:"M12 3l1.9 5.1L19 10l-5.1 1.9L12 17l-1.9-5.1L5 10l5.1-1.9L12 3z"})})}function $e(){return e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true",children:[e.jsx("circle",{cx:"5",cy:"12",r:"1.8"}),e.jsx("circle",{cx:"12",cy:"12",r:"1.8"}),e.jsx("circle",{cx:"19",cy:"12",r:"1.8"})]})}function ai(a){try{return new Intl.DateTimeFormat("zh-CN",{month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit"}).format(new Date(a))}catch{return a}}export{Us as GitSidebar,qn as resolveGitOperationsMenuPosition};
@@ -1 +1 @@
1
- import{b as c,j as e,t as n}from"./index-_OCkVmfl.js";import{c as k,d as j,u as f,v as g,K as v}from"./workbench-navigation-RyUjchbD.js";import{M}from"./MobileSheet-BXvQPkxt.js";import{ah as L,C as S}from"./WorkbenchLayout-D-U7ghT0.js";function H({open:o,workspaces:l,workspaceOptions:t,initialWorkspaceId:d,onClose:b,onSelect:x}){const[a,u]=c.useState(""),[h,m]=c.useState(!1),p=L(),i=c.useMemo(()=>t??l.map(s=>({workspace:s,label:s.name,subtitle:s.path,depth:0,kind:"workspace",meta:null})),[t,l]),w=c.useMemo(()=>i.map(s=>s.workspace.id).join("|"),[i]);if(c.useEffect(()=>{o&&(u(N(i,d)),m(!1))},[d,o,w]),!o)return null;const r=i.find(s=>s.workspace.id===a)??i[0]??null;return e.jsxs(M,{open:o,title:n("shell.createSessionModalTitle"),description:n("shell.createSessionModalDescription"),kind:"form",height:"three-quarter",className:"mobile-create-session-sheet",cardClassName:"mobile-create-session-sheet-card",bodyClassName:"mobile-feature-form mobile-workspace-home-form mobile-create-session-form",showHandle:!0,onClose:b,children:[e.jsx(k,{className:"mobile-create-session-section",tone:"accent",children:e.jsxs(j,{label:n("shell.createSessionWorkspaceLabel"),children:[e.jsxs("button",{type:"button",className:"mobile-create-session-workspace-trigger","aria-label":`${n("shell.createSessionWorkspaceLabel")} ${(r==null?void 0:r.label)??""}`.trim(),"aria-expanded":h?"true":"false",disabled:i.length===0,onClick:()=>{p.trigger("selection"),m(s=>!s)},children:[e.jsxs("span",{className:"mobile-create-session-workspace-copy",children:[e.jsx("strong",{children:(r==null?void 0:r.label)??n("common.unknown")}),e.jsx("span",{children:(r==null?void 0:r.subtitle)??n("common.unknown")})]}),e.jsx(C,{expanded:h})]}),h?e.jsx(f,{className:"mobile-workspace-home-group mobile-create-session-workspace-list",role:"list",children:i.map(s=>e.jsx(g,{as:"button",className:"mobile-workspace-home-row mobile-create-session-workspace-row","data-worktree-kind":s.kind,"data-worktree-depth":s.depth,selected:s.workspace.id===a,trailing:e.jsx("span",{className:"mobile-workspace-home-row-trailing",children:s.workspace.id===a?e.jsx(I,{}):e.jsx(y,{})}),style:{"--mobile-workspace-tree-depth":String(s.depth)},onClick:()=>{s.workspace.id!==a&&p.trigger("selection"),u(s.workspace.id),m(!1)},children:e.jsxs("span",{className:"mobile-create-session-workspace-option-copy",children:[e.jsxs("strong",{children:[s.kind==="worktree"?e.jsx(v,{className:"mobile-workspace-home-worktree-badge",children:n("shell.mobileWorktreeBadge")}):null,s.label]}),e.jsx("span",{children:s.subtitle})]})},s.workspace.id))}):null]})}),e.jsx(k,{className:"mobile-create-session-provider-block",heading:n("shell.createSessionProviderLabel"),children:e.jsx(S,{disabled:!a,workspaceId:a||null,onSelect:s=>{a&&x(a,s)}})})]})}function N(o,l){var t;return l&&o.some(d=>d.workspace.id===l)?l:((t=o[0])==null?void 0:t.workspace.id)??""}function C({expanded:o}){return e.jsx("svg",{viewBox:"0 0 16 16","aria-hidden":"true",className:"mobile-create-session-workspace-chevron","data-expanded":o?"true":"false",children:e.jsx("path",{d:"M4 6.5L8 10l4-3.5",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"1.6"})})}function y(){return e.jsx("svg",{viewBox:"0 0 16 16","aria-hidden":"true",children:e.jsx("path",{d:"M6 3.5L10.5 8 6 12.5",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"1.6"})})}function I(){return e.jsx("svg",{viewBox:"0 0 16 16","aria-hidden":"true",children:e.jsx("path",{d:"M3.5 8.5L6.5 11.5L12.5 5.5",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"1.8"})})}export{H as M};
1
+ import{b as c,j as e,t as n}from"./index-FOhyOpGY.js";import{c as k,d as j,u as f,v as g,K as v}from"./workbench-navigation-aqJ1ay4M.js";import{M}from"./MobileSheet-rkn_CUOY.js";import{ah as L,C as S}from"./WorkbenchLayout-DViAJhHz.js";function H({open:o,workspaces:l,workspaceOptions:t,initialWorkspaceId:d,onClose:b,onSelect:x}){const[a,u]=c.useState(""),[h,m]=c.useState(!1),p=L(),i=c.useMemo(()=>t??l.map(s=>({workspace:s,label:s.name,subtitle:s.path,depth:0,kind:"workspace",meta:null})),[t,l]),w=c.useMemo(()=>i.map(s=>s.workspace.id).join("|"),[i]);if(c.useEffect(()=>{o&&(u(N(i,d)),m(!1))},[d,o,w]),!o)return null;const r=i.find(s=>s.workspace.id===a)??i[0]??null;return e.jsxs(M,{open:o,title:n("shell.createSessionModalTitle"),description:n("shell.createSessionModalDescription"),kind:"form",height:"three-quarter",className:"mobile-create-session-sheet",cardClassName:"mobile-create-session-sheet-card",bodyClassName:"mobile-feature-form mobile-workspace-home-form mobile-create-session-form",showHandle:!0,onClose:b,children:[e.jsx(k,{className:"mobile-create-session-section",tone:"accent",children:e.jsxs(j,{label:n("shell.createSessionWorkspaceLabel"),children:[e.jsxs("button",{type:"button",className:"mobile-create-session-workspace-trigger","aria-label":`${n("shell.createSessionWorkspaceLabel")} ${(r==null?void 0:r.label)??""}`.trim(),"aria-expanded":h?"true":"false",disabled:i.length===0,onClick:()=>{p.trigger("selection"),m(s=>!s)},children:[e.jsxs("span",{className:"mobile-create-session-workspace-copy",children:[e.jsx("strong",{children:(r==null?void 0:r.label)??n("common.unknown")}),e.jsx("span",{children:(r==null?void 0:r.subtitle)??n("common.unknown")})]}),e.jsx(C,{expanded:h})]}),h?e.jsx(f,{className:"mobile-workspace-home-group mobile-create-session-workspace-list",role:"list",children:i.map(s=>e.jsx(g,{as:"button",className:"mobile-workspace-home-row mobile-create-session-workspace-row","data-worktree-kind":s.kind,"data-worktree-depth":s.depth,selected:s.workspace.id===a,trailing:e.jsx("span",{className:"mobile-workspace-home-row-trailing",children:s.workspace.id===a?e.jsx(I,{}):e.jsx(y,{})}),style:{"--mobile-workspace-tree-depth":String(s.depth)},onClick:()=>{s.workspace.id!==a&&p.trigger("selection"),u(s.workspace.id),m(!1)},children:e.jsxs("span",{className:"mobile-create-session-workspace-option-copy",children:[e.jsxs("strong",{children:[s.kind==="worktree"?e.jsx(v,{className:"mobile-workspace-home-worktree-badge",children:n("shell.mobileWorktreeBadge")}):null,s.label]}),e.jsx("span",{children:s.subtitle})]})},s.workspace.id))}):null]})}),e.jsx(k,{className:"mobile-create-session-provider-block",heading:n("shell.createSessionProviderLabel"),children:e.jsx(S,{disabled:!a,workspaceId:a||null,onSelect:s=>{a&&x(a,s)}})})]})}function N(o,l){var t;return l&&o.some(d=>d.workspace.id===l)?l:((t=o[0])==null?void 0:t.workspace.id)??""}function C({expanded:o}){return e.jsx("svg",{viewBox:"0 0 16 16","aria-hidden":"true",className:"mobile-create-session-workspace-chevron","data-expanded":o?"true":"false",children:e.jsx("path",{d:"M4 6.5L8 10l4-3.5",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"1.6"})})}function y(){return e.jsx("svg",{viewBox:"0 0 16 16","aria-hidden":"true",children:e.jsx("path",{d:"M6 3.5L10.5 8 6 12.5",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"1.6"})})}function I(){return e.jsx("svg",{viewBox:"0 0 16 16","aria-hidden":"true",children:e.jsx("path",{d:"M3.5 8.5L6.5 11.5L12.5 5.5",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"1.8"})})}export{H as M};
@@ -1 +1 @@
1
- import{b as n,j as e,t as g}from"./index-_OCkVmfl.js";import{g as $}from"./App-If9gThKM.js";function E({open:h,title:m,description:o,height:b="auto",kind:u="form",dismissible:t=!0,closeOnBackdrop:p=!0,backdropVisible:x=!0,showHandle:j=!1,showCancelButton:v=!0,cancelLabel:f,className:a,cardClassName:l,bodyClassName:s,footer:i,onClose:r,children:k}){const d=n.useId(),c=n.useId(),y=t&&p;return!h||typeof document>"u"?null:$.createPortal(e.jsx("div",{className:"ios-action-sheet-overlay mobile-sheet-overlay","data-backdrop-visible":x?"true":"false",role:"presentation",onClick:()=>{y&&r()},children:e.jsxs("div",{className:`mobile-workspace-home-sheet mobile-sheet${a?` ${a}`:""}`,"data-height":b,"data-kind":u,role:"dialog","aria-modal":"true","aria-labelledby":d,"aria-describedby":o?c:void 0,onClick:N=>N.stopPropagation(),children:[e.jsxs("div",{className:`mobile-workspace-home-sheet-card mobile-sheet-card${l?` ${l}`:""}`,children:[j?e.jsx("div",{className:"mobile-sheet-handle","aria-hidden":"true"}):null,e.jsx("div",{className:"mobile-workspace-home-sheet-header mobile-sheet-header",children:e.jsxs("div",{className:"mobile-sheet-title-wrap",children:[e.jsx("strong",{id:d,children:m}),o?e.jsx("p",{id:c,children:o}):null]})}),e.jsx("div",{className:s?`mobile-sheet-body ${s}`:"mobile-sheet-body",children:k}),i?e.jsx("div",{className:"mobile-sheet-footer",children:i}):null]}),v?e.jsx("button",{type:"button",className:"ios-action-sheet-cancel mobile-sheet-cancel",disabled:!t,onClick:()=>{t&&r()},children:f??g("common.cancel")}):null]})}),document.body)}export{E as M};
1
+ import{b as n,j as e,t as g}from"./index-FOhyOpGY.js";import{g as $}from"./App-Dl-mcdqy.js";function E({open:h,title:m,description:o,height:b="auto",kind:u="form",dismissible:t=!0,closeOnBackdrop:p=!0,backdropVisible:x=!0,showHandle:j=!1,showCancelButton:v=!0,cancelLabel:f,className:a,cardClassName:l,bodyClassName:s,footer:i,onClose:r,children:k}){const d=n.useId(),c=n.useId(),y=t&&p;return!h||typeof document>"u"?null:$.createPortal(e.jsx("div",{className:"ios-action-sheet-overlay mobile-sheet-overlay","data-backdrop-visible":x?"true":"false",role:"presentation",onClick:()=>{y&&r()},children:e.jsxs("div",{className:`mobile-workspace-home-sheet mobile-sheet${a?` ${a}`:""}`,"data-height":b,"data-kind":u,role:"dialog","aria-modal":"true","aria-labelledby":d,"aria-describedby":o?c:void 0,onClick:N=>N.stopPropagation(),children:[e.jsxs("div",{className:`mobile-workspace-home-sheet-card mobile-sheet-card${l?` ${l}`:""}`,children:[j?e.jsx("div",{className:"mobile-sheet-handle","aria-hidden":"true"}):null,e.jsx("div",{className:"mobile-workspace-home-sheet-header mobile-sheet-header",children:e.jsxs("div",{className:"mobile-sheet-title-wrap",children:[e.jsx("strong",{id:d,children:m}),o?e.jsx("p",{id:c,children:o}):null]})}),e.jsx("div",{className:s?`mobile-sheet-body ${s}`:"mobile-sheet-body",children:k}),i?e.jsx("div",{className:"mobile-sheet-footer",children:i}):null]}),v?e.jsx("button",{type:"button",className:"ios-action-sheet-cancel mobile-sheet-cancel",disabled:!t,onClick:()=>{t&&r()},children:f??g("common.cancel")}):null]})}),document.body)}export{E as M};
@@ -1 +1 @@
1
- import{j as i}from"./index-_OCkVmfl.js";function m({children:e,className:o,frameRef:r,...a}){return i.jsx("div",{ref:r,className:["mobile-top-header-frame",o].filter(Boolean).join(" "),...a,children:e})}export{m as M};
1
+ import{j as i}from"./index-FOhyOpGY.js";function m({children:e,className:o,frameRef:r,...a}){return i.jsx("div",{ref:r,className:["mobile-top-header-frame",o].filter(Boolean).join(" "),...a,children:e})}export{m as M};
@@ -0,0 +1 @@
1
+ import{b as m,f as G,i as q,j as t,t as i}from"./index-FOhyOpGY.js";import{u as V,v as X,K as v,y as Z}from"./workbench-navigation-aqJ1ay4M.js";import{M as J}from"./MobileSheet-rkn_CUOY.js";import{bk as Q,m as Y,ah as ee,bl as K,bm as se,bn as oe}from"./WorkbenchLayout-DViAJhHz.js";import{u as te,f as ae}from"./App-Dl-mcdqy.js";import{M as re}from"./MobileTopHeaderFrame-CU0wsYSS.js";function ne(e){return e.flatMap(o=>[{workspace:o.workspace,label:o.workspace.name,subtitle:o.workspace.path,depth:0,kind:"workspace",meta:null},...E(o.childWorktrees??[])])}function Le(e,o){const a=o==null?void 0:o.trim();if(!a)return null;for(const r of e){if(r.workspace.id===a)return{workspace:r.workspace,sessions:r.sessions,childWorktrees:r.childWorktrees??[],meta:null};const n=T(r.childWorktrees??[],a);if(n)return n}return null}function E(e){return e.flatMap(o=>[{workspace:o.workspace,label:o.meta.displayName||o.workspace.name,subtitle:o.workspace.path,depth:o.meta.depth,kind:"worktree",meta:o.meta},...E(o.children)])}function T(e,o){for(const a of e){if(a.workspace.id===o)return{workspace:a.workspace,sessions:a.sessions,childWorktrees:a.children,meta:a.meta};const r=T(a.children,o);if(r)return r}return null}const ie=10080*60*1e3;function le(e,o,a=[]){return de(e.hosts,e.activeHostId).flatMap(r=>{const n=pe(r.id,e.activeHostId),c=we(n,a),S=r.id===e.activeHostId?"active":c.length>0?"scoped":"cached",w=r.id===e.activeHostId?o:c.length>0?c:ue(r.id),p=ke(n,a,r.id===e.activeHostId),k=he(p);return[{kind:"host",host:r,scopedKey:ce(n),hostStatus:p,available:k,workspaceCount:w.length},...w.map(d=>({kind:"workspace",host:r,source:S,scopedKey:O(n,d.workspace.id),workspaceRef:{hostId:n,workspaceId:d.workspace.id},hostStatus:p,available:k,workspace:d.workspace,option:d}))]})}function ce(e){return`host:${y(e)}`}function O(e,o){return`workspace:${y(e)}:${y(o)}`}function he(e){return e===void 0||e==="current"||e==="reachable"||e==="unknown"}function de(e,o){return[...e].sort((a,r)=>{if(a.id===o)return-1;if(r.id===o)return 1;const n=a.lastConnectedAt??a.updatedAt??a.createdAt;return(r.lastConnectedAt??r.updatedAt??r.createdAt).localeCompare(n)})}function ue(e){const o=Q(ie,e);return o?ne(Y(o)):[]}function pe(e,o){return e===o?"current":e}function ke(e,o,a){var n;return a?"current":((n=o.find(c=>c.hostId===e))==null?void 0:n.hostStatus)??"unknown"}function we(e,o){return o.filter(a=>a.hostId===e).map(a=>({workspace:a.workspace,label:a.workspace.name,subtitle:a.workspace.path,depth:0,kind:"workspace",meta:null}))}function y(e){return encodeURIComponent(e)}function Ke({currentWorkspace:e,workspaces:o,workspaceOptions:a,scopedWorkspaces:r,onSelectWorkspace:n,className:c,containerRef:S,heading:w,content:p,sheetContent:k,triggerLabel:d,triggerAriaLabel:P,onTriggerClick:x,trailing:R,gestureHandlers:W}){const[f,b]=m.useState(!1),[M,C]=m.useState(null),[B,_]=m.useState([]),I=ee(),z=te(),{showToast:A}=ae(),l=G(s=>s),u=q(l),D=a??o.map(s=>({workspace:{...s,repoRoot:s.path},label:s.name,subtitle:s.path,depth:0,kind:"workspace",meta:null})),F=le(l,D,r??B),j=(e==null?void 0:e.name)??(u==null?void 0:u.name)??null,L=(e==null?void 0:e.path)??(u==null?void 0:u.baseUrl)??null;if(m.useEffect(()=>{if(!f||r)return;let s=!1;const H=l.hosts.filter(h=>h.id!==l.activeHostId);return Promise.allSettled([K(),...H.map(h=>K(h.id))]).then(h=>{s||_(h.flatMap(g=>g.status==="fulfilled"&&Array.isArray(g.value.items)?g.value.items:[]))}),()=>{s=!0}},[l.activeHostId,l.hosts,r,f]),!j)return null;async function $(s){const H=s.scopedKey;if(!M){C(H);try{if(!s.available){A({title:be(s),tone:"error"});return}s.host.id!==l.activeHostId&&(s.kind==="host"||s.source!=="scoped")&&(I.trigger("selection"),await se.switchHost(s.host.id)),s.kind==="host"?z(Z()):s.scopedKey!==N(l.activeHostId,e==null?void 0:e.id)&&await(n==null?void 0:n(s.workspace.id,s.workspaceRef)),b(!1)}catch(h){A({title:fe(h,s.host.name),tone:"error"})}finally{C(null)}}}return t.jsxs(t.Fragment,{children:[t.jsx(re,{className:c,frameRef:S,...W,children:t.jsxs("section",{className:"mobile-workspace-home-header",children:[t.jsx("h1",{className:"mobile-workspace-switcher-heading",children:w??j}),t.jsxs("div",{className:"mobile-workspace-home-toolbar-top",children:[t.jsxs("button",{type:"button",className:"mobile-workspace-home-switcher","aria-label":P??i("shell.workspaceHomeSwitcherLabel"),onClick:()=>{if(x){x();return}I.trigger("selection"),b(!0)},children:[t.jsx("span",{className:"mobile-workspace-home-switcher-label",children:d??j}),t.jsx(xe,{})]}),t.jsx("div",{className:"mobile-workspace-home-toolbar-actions",children:R})]}),L?t.jsx("p",{className:"mobile-workspace-home-path",children:L}):null,p]})}),f&&!x?t.jsxs(Se,{open:f,title:i("shell.hostWorkspaceSwitcherTitle"),onClose:()=>b(!1),children:[t.jsx(V,{className:"mobile-workspace-home-group mobile-workspace-home-sheet-group",children:F.map(s=>t.jsx(X,{as:"button",className:"mobile-workspace-home-row mobile-workspace-home-sheet-row","data-host-entry-kind":s.kind,"data-host-active":s.host.id===l.activeHostId,"data-host-available":s.available,"data-worktree-kind":s.kind==="workspace"?s.option.kind:void 0,"data-worktree-depth":s.kind==="workspace"?s.option.depth+1:0,disabled:M!==null,selected:s.kind==="host"&&s.host.id===l.activeHostId||s.kind==="workspace"&&s.scopedKey===N(l.activeHostId,e==null?void 0:e.id),trailing:t.jsx("span",{className:"mobile-workspace-home-row-trailing",children:s.kind==="host"&&s.host.id===l.activeHostId?t.jsx(U,{}):s.kind==="workspace"&&s.scopedKey===N(l.activeHostId,e==null?void 0:e.id)?t.jsx(U,{}):s.available?t.jsx(je,{}):t.jsx(He,{})}),style:{"--mobile-workspace-tree-depth":String(s.kind==="host"?0:s.option.depth+1)},onClick:()=>{$(s)},label:t.jsxs("span",{className:s.kind==="host"?"mobile-workspace-home-sheet-label mobile-host-workspace-switcher-host-label":"mobile-workspace-home-sheet-label",children:[s.kind==="host"?t.jsx(v,{className:"mobile-host-workspace-switcher-host-badge",children:i("shell.hostSwitcherNodeBadge")}):null,s.kind==="workspace"&&s.option.kind==="worktree"?t.jsx(v,{className:"mobile-workspace-home-worktree-badge",children:i("shell.mobileWorktreeBadge")}):null,s.kind==="workspace"&&s.host.id!==l.activeHostId?t.jsx(v,{className:"mobile-host-workspace-switcher-host-badge",children:s.host.name}):null,s.kind==="workspace"&&!s.available?t.jsx(v,{className:"mobile-host-workspace-switcher-host-badge",children:i("shell.hostSwitcherPeerUnavailableBadge")}):null,t.jsx("span",{className:"mobile-workspace-home-sheet-label-text",children:s.kind==="host"?s.host.name:s.option.label})]}),description:t.jsx("span",{className:"mobile-workspace-home-sheet-description",children:s.kind==="host"?ve(s.host,s.workspaceCount):me(s)})},s.scopedKey))}),k?k(()=>b(!1)):null]}):null]})}function fe(e,o){return e instanceof oe?e.code==="HOST_UNREACHABLE"?i("shell.hostSwitchUnreachable",{name:o}):i("shell.hostSwitchMissing"):i("shell.hostSwitchFailed")}function be(e){return e.hostStatus==="version_mismatch"?i("shell.hostSwitcherPeerVersionMismatch",{hostName:e.host.name}):e.hostStatus==="unauthorized"?i("shell.hostSwitcherPeerUnauthorized",{hostName:e.host.name}):i("shell.hostSwitcherPeerUnavailable",{hostName:e.host.name})}function N(e,o){return o?O("current",o):""}function me(e){return e.available?e.hostStatus==="current"?e.option.subtitle:i("shell.hostSwitcherPeerWorkspaceDescription",{hostName:e.host.name,path:e.option.subtitle}):i("shell.hostSwitcherPeerWorkspaceUnavailableDescription",{hostName:e.host.name})}function ve(e,o){return e?e.lastUsername?i("shell.hostSwitcherWorkspaceCountWithUser",{username:e.lastUsername,count:o}):o>0?i("shell.hostSwitcherWorkspaceCount",{count:o}):e.baseUrl:""}function Se({open:e,title:o,onClose:a,children:r}){return t.jsx(J,{open:e,title:o,kind:"picker",height:"three-quarter",className:"mobile-host-workspace-switcher-sheet",bodyClassName:"mobile-workspace-home-form",showHandle:!0,onClose:a,children:r})}function xe(){return t.jsx("svg",{viewBox:"0 0 16 16","aria-hidden":"true",children:t.jsx("path",{d:"M4 6.5L8 10l4-3.5",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"1.6"})})}function je(){return t.jsx("svg",{viewBox:"0 0 16 16","aria-hidden":"true",children:t.jsx("path",{d:"M6 3.5L10.5 8 6 12.5",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"1.6"})})}function U(){return t.jsx("svg",{viewBox:"0 0 16 16","aria-hidden":"true",children:t.jsx("path",{d:"M3.5 8.5L6.5 11.5L12.5 5.5",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"1.8"})})}function He(){return t.jsx("svg",{viewBox:"0 0 16 16","aria-hidden":"true",children:t.jsx("path",{d:"M4.5 4.5l7 7M12.5 8A4.5 4.5 0 1 1 8 3.5 4.5 4.5 0 0 1 12.5 8Z",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"1.5"})})}export{Ke as M,Le as a,ne as f};
@@ -1 +1 @@
1
- import{j as n,t as s}from"./index-_OCkVmfl.js";import{c as a,x as d,u as m,v as u,K as g}from"./workbench-navigation-RyUjchbD.js";import{b as l,a as y,g as f}from"./plugin-permission-copy-DIVk5jNp.js";function M({grants:i,auditEvents:r,loading:t,revokingGrantId:o,onRevokeGrant:p}){const c=r.filter(e=>e.eventType==="plugin.permission_granted"||e.eventType==="plugin.permission_revoked"||e.eventType==="plugin.permission_denied");return n.jsxs(n.Fragment,{children:[n.jsx(a,{heading:s("plugins.grantedPermissionTitle"),description:s("plugins.grantedPermissionDescription"),children:t?n.jsx("p",{className:"plugins-hint-text",children:s("plugins.permissionGrantLoading")}):i.length===0?n.jsx(d,{title:s("plugins.grantedPermissionEmptyTitle"),description:s("plugins.grantedPermissionEmptyDescription"),compact:!0}):n.jsx(m,{compact:!0,children:i.map(e=>n.jsx(u,{label:f(e.permissionKey),description:`${y(e.scopeType,e.scopePath)} · ${l(e.grantMode)}`,trailing:p?n.jsx("button",{type:"button",className:"ghost-button",disabled:o===e.id,onClick:()=>p(e),children:s("plugins.revokeGrantAction")}):n.jsx(g,{children:l(e.grantMode)})},e.id))})}),n.jsx(a,{heading:s("plugins.permissionAuditTitle"),description:s("plugins.permissionAuditDescription"),children:c.length===0?n.jsx(d,{title:s("plugins.permissionAuditEmptyTitle"),description:s("plugins.permissionAuditEmptyDescription"),compact:!0}):n.jsx(m,{compact:!0,children:c.slice(0,10).map(e=>n.jsx(u,{label:P(e),description:x(e),trailing:n.jsx(g,{children:e.createdAt})},e.id))})})]})}function P(i){const r=h(i.payloadJson),t=j(r.permissionKey),o=t?f(t):s("plugins.permissionEventUnknown");return i.eventType==="plugin.permission_granted"?s("plugins.permissionEventGranted",{permission:o}):i.eventType==="plugin.permission_revoked"?s("plugins.permissionEventRevoked",{permission:o}):s("plugins.permissionEventDenied",{permission:o})}function x(i){const r=h(i.payloadJson),t=b(r.scopeType),o=typeof r.scopePath=="string"?r.scopePath:null,p=t?y(t,o):s("plugins.permissionScopeUnknown");if(i.eventType==="plugin.permission_denied"){const e=r.reason==="declaration_missing"?s("plugins.permissionEventReasonDeclarationMissing"):s("plugins.permissionEventReasonGrantRequired");return`${p} · ${e}`}const c=E(r.grantMode);return c?`${p} · ${l(c)}`:p}function h(i){try{const r=JSON.parse(i);return r&&typeof r=="object"?r:{}}catch{return{}}}function j(i){return i==="workspace.read_file"||i==="workspace.list_dir"||i==="workspace.write_file"||i==="desktop.open_file"||i==="desktop.reveal_in_file_manager"?i:null}function b(i){return i==="workspace"||i==="directory"||i==="file"?i:null}function E(i){return i==="once"||i==="session"||i==="persistent"?i:null}export{M as P};
1
+ import{j as n,t as s}from"./index-FOhyOpGY.js";import{c as a,x as d,u as m,v as u,K as g}from"./workbench-navigation-aqJ1ay4M.js";import{b as l,a as y,g as f}from"./plugin-permission-copy-apDn8EWG.js";function M({grants:i,auditEvents:r,loading:t,revokingGrantId:o,onRevokeGrant:p}){const c=r.filter(e=>e.eventType==="plugin.permission_granted"||e.eventType==="plugin.permission_revoked"||e.eventType==="plugin.permission_denied");return n.jsxs(n.Fragment,{children:[n.jsx(a,{heading:s("plugins.grantedPermissionTitle"),description:s("plugins.grantedPermissionDescription"),children:t?n.jsx("p",{className:"plugins-hint-text",children:s("plugins.permissionGrantLoading")}):i.length===0?n.jsx(d,{title:s("plugins.grantedPermissionEmptyTitle"),description:s("plugins.grantedPermissionEmptyDescription"),compact:!0}):n.jsx(m,{compact:!0,children:i.map(e=>n.jsx(u,{label:f(e.permissionKey),description:`${y(e.scopeType,e.scopePath)} · ${l(e.grantMode)}`,trailing:p?n.jsx("button",{type:"button",className:"ghost-button",disabled:o===e.id,onClick:()=>p(e),children:s("plugins.revokeGrantAction")}):n.jsx(g,{children:l(e.grantMode)})},e.id))})}),n.jsx(a,{heading:s("plugins.permissionAuditTitle"),description:s("plugins.permissionAuditDescription"),children:c.length===0?n.jsx(d,{title:s("plugins.permissionAuditEmptyTitle"),description:s("plugins.permissionAuditEmptyDescription"),compact:!0}):n.jsx(m,{compact:!0,children:c.slice(0,10).map(e=>n.jsx(u,{label:P(e),description:x(e),trailing:n.jsx(g,{children:e.createdAt})},e.id))})})]})}function P(i){const r=h(i.payloadJson),t=j(r.permissionKey),o=t?f(t):s("plugins.permissionEventUnknown");return i.eventType==="plugin.permission_granted"?s("plugins.permissionEventGranted",{permission:o}):i.eventType==="plugin.permission_revoked"?s("plugins.permissionEventRevoked",{permission:o}):s("plugins.permissionEventDenied",{permission:o})}function x(i){const r=h(i.payloadJson),t=b(r.scopeType),o=typeof r.scopePath=="string"?r.scopePath:null,p=t?y(t,o):s("plugins.permissionScopeUnknown");if(i.eventType==="plugin.permission_denied"){const e=r.reason==="declaration_missing"?s("plugins.permissionEventReasonDeclarationMissing"):s("plugins.permissionEventReasonGrantRequired");return`${p} · ${e}`}const c=E(r.grantMode);return c?`${p} · ${l(c)}`:p}function h(i){try{const r=JSON.parse(i);return r&&typeof r=="object"?r:{}}catch{return{}}}function j(i){return i==="workspace.read_file"||i==="workspace.list_dir"||i==="workspace.write_file"||i==="desktop.open_file"||i==="desktop.reveal_in_file_manager"?i:null}function b(i){return i==="workspace"||i==="directory"||i==="file"?i:null}function E(i){return i==="once"||i==="session"||i==="persistent"?i:null}export{M as P};
@@ -1 +1 @@
1
- import{b as f,j as o,t as r,A as h,K as v,I as U,L as x,D as C}from"./index-_OCkVmfl.js";import{c as D,u as k,v as b,K as S,x as A,M as L,L as j}from"./workbench-navigation-RyUjchbD.js";import{e as G,i as M,T as F,P as K,c as B,u as z,f as H}from"./App-If9gThKM.js";import{c as Q,f as W,h as Y,i as $,o as V,j as X,k as J,w as Z,m as q}from"./plugins-api-DHJVvPZw.js";import{D as ee}from"./DesktopModal-bMdI1jEe.js";import{M as ne}from"./MobileSheet-BXvQPkxt.js";import{g as ie,a as te,b as se}from"./plugin-permission-copy-DIVk5jNp.js";function oe({open:e,request:n,submitting:t,onClose:s,onApprove:i}){const l=G(),c=f.useMemo(()=>re(n),[n]);if(!n)return null;const d=o.jsxs("div",{className:"plugins-permission-prompt",children:[o.jsx(D,{heading:r("plugins.permissionPromptSummaryTitle"),description:r("plugins.permissionPromptSummaryDescription",{pluginName:n.pluginName}),children:o.jsxs(k,{compact:!0,children:[o.jsx(b,{label:r("plugins.permissionPromptPermissionLabel"),description:ie(n.permissionKey),trailing:o.jsx(S,{tone:"warning",children:r("plugins.permissionPromptPendingTag")})}),o.jsx(b,{label:r("plugins.permissionPromptTargetLabel"),description:te(n.scopeType,n.scopePath)})]})}),o.jsx(D,{heading:r("plugins.permissionPromptOptionsTitle"),description:r("plugins.permissionPromptOptionsDescription"),children:c.length===0?o.jsx(A,{title:r("plugins.permissionPromptNoOptionTitle"),description:r("plugins.permissionPromptNoOptionDescription"),compact:!0}):o.jsx(k,{children:c.map(a=>o.jsx(b,{as:"button",disabled:t,label:a.label,description:a.description,trailing:o.jsx(S,{children:se(a.grantMode)}),onClick:()=>{i({scopeType:a.scopeType,scopePath:a.scopePath,grantMode:a.grantMode})}},a.id))})}),o.jsx(L,{align:"end",children:o.jsx("button",{type:"button",className:"secondary-button",disabled:t,onClick:s,children:r("plugins.permissionPromptDenyAction")})})]});return l.isMobile?o.jsx(ne,{open:e,title:r("plugins.permissionPromptTitle"),description:r("plugins.permissionPromptDescription"),height:"three-quarter",kind:"form",onClose:s,footer:null,children:d}):o.jsx(ee,{open:e,title:r("plugins.permissionPromptTitle"),description:r("plugins.permissionPromptDescription"),size:"regular",layout:"form",onClose:s,footer:null,children:d})}function re(e){var s;if(!e)return[];const n=[],t=((s=e.scopePath)==null?void 0:s.trim())||null;if(e.grantOptions.includes("once")&&n.push({id:"once-file",label:r("plugins.permissionPromptOptionOnce"),description:r("plugins.permissionPromptOptionOnceDescription"),grantMode:"once",scopeType:e.scopeType==="workspace"?"workspace":"file",scopePath:e.scopeType==="workspace"?null:t}),e.grantOptions.includes("session")&&n.push({id:"session-current",label:r("plugins.permissionPromptOptionSession"),description:r("plugins.permissionPromptOptionSessionDescription"),grantMode:"session",scopeType:e.scopeType==="workspace"?"workspace":"file",scopePath:e.scopeType==="workspace"?null:t}),e.grantOptions.includes("persistent")&&t&&e.scopeType!=="workspace"){const i=ae(t);i&&n.push({id:"persistent-directory",label:r("plugins.permissionPromptOptionDirectory"),description:r("plugins.permissionPromptOptionDirectoryDescription",{scopePath:i}),grantMode:"persistent",scopeType:"directory",scopePath:i})}return n}function ae(e){const n=e.replace(/\\/g,"/").replace(/^\/+|\/+$/g,"");if(!n)return null;const t=n.split("/");return t.length<=1?n:t.slice(0,-1).join("/")}const R="codingns-plugin:response",le="codingns-plugin:init",pe="codingns-plugin:ready",ce="codingns-plugin:request";async function de(e,n,t){const s=await Q(e,n);return Ee(s.context,t)}async function O(e,n){await W(e,n)}function ue(e){const{iframe:n,pluginId:t,hostOrigin:s,context:i}=e;function l(c){var m;if(c.source!==n.contentWindow||c.origin!==s)return;const d=c.data;if(!d||typeof d!="object")return;if(d.type===pe){(m=n.contentWindow)==null||m.postMessage({type:le,context:i},s);return}const a=d;a.type!==ce||typeof a.requestId!="string"||me({pluginId:t,pluginName:i.pluginName,runtimeSessionId:i.runtimeSessionId,request:a}).then(g=>{var u;(u=n.contentWindow)==null||u.postMessage({type:R,requestId:a.requestId,ok:!0,result:g},s)}).catch(g=>{var u;(u=n.contentWindow)==null||u.postMessage({type:R,requestId:a.requestId,ok:!1,error:Ne(g)},s)})}return window.addEventListener("message",l),()=>{window.removeEventListener("message",l)}}async function me(e){var c,d,a,m,g,u,P;const{pluginId:n,pluginName:t,runtimeSessionId:s,request:i}=e;if(i.action==="callAction"){const p=typeof((c=i.payload)==null?void 0:c.actionId)=="string"?i.payload.actionId.trim():"";if(!p)throw new h(400,{error_code:"PLUGIN_ACTION_ID_REQUIRED",detail:"插件动作请求缺少 actionId"});return await Y(n,p,s,(d=i.payload)==null?void 0:d.input)}if(i.action==="readFile"){const p=_((a=i.payload)==null?void 0:a.path,"插件读文件缺少路径");return await w({pluginId:n,pluginName:t,runtimeSessionId:s,permissionKey:"workspace.read_file",scopePath:p,execute:async()=>await J(n,s,p)})}if(i.action==="writeFile"){const p=_((m=i.payload)==null?void 0:m.path,"插件写文件缺少路径"),E=typeof((g=i.payload)==null?void 0:g.content)=="string"?i.payload.content:"";return await w({pluginId:n,pluginName:t,runtimeSessionId:s,permissionKey:"workspace.write_file",scopePath:p,execute:async()=>await Z(n,s,p,E)})}if(i.action==="listDir"){const p=typeof((u=i.payload)==null?void 0:u.path)=="string"?i.payload.path.trim():"";return{items:(await w({pluginId:n,pluginName:t,runtimeSessionId:s,permissionKey:"workspace.list_dir",scopePath:p||null,execute:async()=>await $(n,s,p||void 0)})).items.map(ge)}}const l=_((P=i.payload)==null?void 0:P.path,"插件桌面动作缺少路径");if(i.action==="openFile"){const p=await w({pluginId:n,pluginName:t,runtimeSessionId:s,permissionKey:"desktop.open_file",scopePath:l,execute:async()=>await V(n,s,l)}),y=await M().fs.openFile(p.absolutePath);if(!y.ok)throw new h(500,{error_code:y.errorCode??"PLUGIN_DESKTOP_OPEN_FAILED",detail:y.detail??"打开文件失败"});return p}if(i.action==="revealInFileManager"){const p=await w({pluginId:n,pluginName:t,runtimeSessionId:s,permissionKey:"desktop.reveal_in_file_manager",scopePath:l,execute:async()=>await X(n,s,l)}),y=await M().fs.revealInFileManager(p.absolutePath);if(!y.ok)throw new h(500,{error_code:y.errorCode??"PLUGIN_DESKTOP_REVEAL_FAILED",detail:y.detail??"打开所在目录失败"});return p}throw new h(400,{error_code:"PLUGIN_BRIDGE_ACTION_UNKNOWN",detail:`未知插件桥动作:${i.action}`})}function _(e,n){const t=typeof e=="string"?e.trim():"";if(!t)throw new h(400,{error_code:"PLUGIN_PATH_REQUIRED",detail:n});return t}function ge(e){return{path:e.path,name:e.name,kind:e.kind,size:e.size,updatedAt:e.updatedAt}}async function w(e){try{return await e.execute()}catch(n){const t=fe(n,e);if(!t||!await we(t))throw n;return await e.execute()}}function fe(e,n){var c,d,a,m;if(!(e instanceof h)||e.errorCode!=="PLUGIN_PERMISSION_GRANT_REQUIRED")return null;const t=Pe((c=e.data)==null?void 0:c.permissionKey,n.permissionKey),s=he((d=e.data)==null?void 0:d.scopeType,n.scopePath?"file":"workspace"),i=typeof((a=e.data)==null?void 0:a.scopePath)=="string"?e.data.scopePath:n.scopePath,l=ye((m=e.data)==null?void 0:m.grantOptions);return{pluginId:n.pluginId,pluginName:n.pluginName,runtimeSessionId:n.runtimeSessionId,permissionKey:t,scopeType:s,scopePath:i,grantOptions:l}}function Pe(e,n){return e==="workspace.read_file"||e==="workspace.list_dir"||e==="workspace.write_file"||e==="desktop.open_file"||e==="desktop.reveal_in_file_manager"?e:n}function he(e,n){return e==="workspace"||e==="directory"||e==="file"?e:n}function ye(e){return Array.isArray(e)?e.filter(n=>n==="once"||n==="session"||n==="persistent"):["once","session"]}let N=null,I=null;async function we(e){return typeof document>"u"?!1:await new Promise(n=>{Ie();const t=i=>{T({open:!1,request:null,submitting:!1,onClose:()=>t(!1),onApprove:()=>{}}),window.setTimeout(()=>n(i),0)};T({open:!0,request:e,submitting:!1,onClose:()=>t(!1),onApprove:async i=>{T({open:!0,request:e,submitting:!0,onClose:()=>{},onApprove:()=>{}});try{await q(e.pluginId,{runtimeSessionId:e.runtimeSessionId,permissionKey:e.permissionKey,scopeType:i.scopeType,scopePath:i.scopePath,grantMode:i.grantMode}),t(!0)}catch{t(!1)}}})})}function Ie(){I||(I=document.createElement("div"),I.dataset.pluginPermissionPrompt="true",document.body.appendChild(I)),N||(N=v.createRoot(I))}function T(e){N&&N.render(f.createElement(U,null,f.createElement(F,null,f.createElement(K,null,f.createElement(oe,{open:e.open,request:e.request,submitting:e.submitting,onClose:e.onClose,onApprove:e.onApprove})))))}function Ee(e,n){if(!e.frontendEntryUrl)throw new h(404,{error_code:"PLUGIN_FRONTEND_NOT_FOUND",detail:"当前插件没有可运行的前端入口"});return{pluginId:e.pluginId,workspaceId:e.workspaceId,runtimeSessionId:e.runtimeSessionId,pluginName:e.pluginName,pluginVersion:e.pluginVersion,frontendEntryUrl:e.frontendEntryUrl,hostOrigin:n}}function Ne(e){return e instanceof h?{code:e.errorCode??`HTTP_${e.status}`,detail:e.message}:e instanceof Error?{code:"PLUGIN_BRIDGE_REQUEST_FAILED",detail:e.message}:{code:"PLUGIN_BRIDGE_REQUEST_FAILED",detail:"插件桥请求失败"}}const be="allow-scripts allow-forms allow-modals allow-downloads";function Me(){const{workspaceId:e="",pluginId:n=""}=B(),t=z(),{showToast:s}=H(),i=f.useRef(null),[l,c]=f.useState(null),[d,a]=f.useState(!0),m=f.useMemo(()=>{const g=x();try{return new URL(g).origin}catch{return window.location.origin}},[]);return f.useEffect(()=>{let g=!1,u=null;return a(!0),c(null),de(n,e,m).then(P=>{if(g){O(n,P.runtimeSessionId).catch(()=>{});return}u=P,c(P)}).catch(P=>{g||s({title:P instanceof Error?P.message:r("plugins.containerLoadFailed"),tone:"error"})}).finally(()=>{g||a(!1)}),()=>{g=!0,u!=null&&u.runtimeSessionId&&O(n,u.runtimeSessionId).catch(()=>{})}},[m,n,s,e]),f.useEffect(()=>{if(!(!l||!i.current))return ue({iframe:i.current,pluginId:n,hostOrigin:m,context:l})},[l,m,n]),d?o.jsx("main",{className:"mobile-feature-page mobile-page-fixed-root plugins-page",children:o.jsx("article",{className:"surface-card plugins-panel plugins-container-panel",children:o.jsx("p",{className:"plugins-hint-text",children:r("plugins.loading")})})}):l?o.jsx("main",{className:"mobile-feature-page mobile-page-fixed-root plugins-page",children:o.jsxs("article",{className:"surface-card plugins-panel plugins-container-panel",children:[o.jsxs("header",{className:"plugins-page-header",children:[o.jsxs("div",{children:[o.jsx("h1",{children:l.pluginName}),o.jsx("p",{children:r("plugins.containerDescription")})]}),o.jsx(L,{children:o.jsx("button",{type:"button",className:"secondary-button",onClick:()=>t(j(e,n)),children:r("plugins.backToDetail")})})]}),o.jsx("div",{className:"plugins-runtime-shell",children:o.jsx("iframe",{ref:i,title:l.pluginName,className:"plugins-runtime-frame",src:C(l.frontendEntryUrl,x()),sandbox:be,referrerPolicy:"no-referrer"})})]})}):o.jsx("main",{className:"mobile-feature-page mobile-page-fixed-root plugins-page",children:o.jsx("article",{className:"surface-card plugins-panel plugins-container-panel",children:o.jsx(A,{title:r("plugins.containerMissingTitle"),description:r("plugins.containerMissingDescription"),action:o.jsx("button",{type:"button",className:"secondary-button",onClick:()=>t(j(e,n)),children:r("plugins.backToDetail")})})})})}export{Me as PluginContainerPage};
1
+ import{b as f,j as o,t as r,B as h,M as L,I as U,H as x,D as C}from"./index-FOhyOpGY.js";import{c as D,u as k,v as b,K as S,x as v,M as A,L as j}from"./workbench-navigation-aqJ1ay4M.js";import{e as G,i as M,T as F,P as K,c as B,u as z,f as H}from"./App-Dl-mcdqy.js";import{c as Q,f as W,h as Y,i as $,o as V,j as X,k as J,w as Z,m as q}from"./plugins-api-CnZYRKoS.js";import{D as ee}from"./DesktopModal-BnfGW2gk.js";import{M as ne}from"./MobileSheet-rkn_CUOY.js";import{g as ie,a as te,b as se}from"./plugin-permission-copy-apDn8EWG.js";function oe({open:e,request:n,submitting:t,onClose:s,onApprove:i}){const l=G(),c=f.useMemo(()=>re(n),[n]);if(!n)return null;const d=o.jsxs("div",{className:"plugins-permission-prompt",children:[o.jsx(D,{heading:r("plugins.permissionPromptSummaryTitle"),description:r("plugins.permissionPromptSummaryDescription",{pluginName:n.pluginName}),children:o.jsxs(k,{compact:!0,children:[o.jsx(b,{label:r("plugins.permissionPromptPermissionLabel"),description:ie(n.permissionKey),trailing:o.jsx(S,{tone:"warning",children:r("plugins.permissionPromptPendingTag")})}),o.jsx(b,{label:r("plugins.permissionPromptTargetLabel"),description:te(n.scopeType,n.scopePath)})]})}),o.jsx(D,{heading:r("plugins.permissionPromptOptionsTitle"),description:r("plugins.permissionPromptOptionsDescription"),children:c.length===0?o.jsx(v,{title:r("plugins.permissionPromptNoOptionTitle"),description:r("plugins.permissionPromptNoOptionDescription"),compact:!0}):o.jsx(k,{children:c.map(a=>o.jsx(b,{as:"button",disabled:t,label:a.label,description:a.description,trailing:o.jsx(S,{children:se(a.grantMode)}),onClick:()=>{i({scopeType:a.scopeType,scopePath:a.scopePath,grantMode:a.grantMode})}},a.id))})}),o.jsx(A,{align:"end",children:o.jsx("button",{type:"button",className:"secondary-button",disabled:t,onClick:s,children:r("plugins.permissionPromptDenyAction")})})]});return l.isMobile?o.jsx(ne,{open:e,title:r("plugins.permissionPromptTitle"),description:r("plugins.permissionPromptDescription"),height:"three-quarter",kind:"form",onClose:s,footer:null,children:d}):o.jsx(ee,{open:e,title:r("plugins.permissionPromptTitle"),description:r("plugins.permissionPromptDescription"),size:"regular",layout:"form",onClose:s,footer:null,children:d})}function re(e){var s;if(!e)return[];const n=[],t=((s=e.scopePath)==null?void 0:s.trim())||null;if(e.grantOptions.includes("once")&&n.push({id:"once-file",label:r("plugins.permissionPromptOptionOnce"),description:r("plugins.permissionPromptOptionOnceDescription"),grantMode:"once",scopeType:e.scopeType==="workspace"?"workspace":"file",scopePath:e.scopeType==="workspace"?null:t}),e.grantOptions.includes("session")&&n.push({id:"session-current",label:r("plugins.permissionPromptOptionSession"),description:r("plugins.permissionPromptOptionSessionDescription"),grantMode:"session",scopeType:e.scopeType==="workspace"?"workspace":"file",scopePath:e.scopeType==="workspace"?null:t}),e.grantOptions.includes("persistent")&&t&&e.scopeType!=="workspace"){const i=ae(t);i&&n.push({id:"persistent-directory",label:r("plugins.permissionPromptOptionDirectory"),description:r("plugins.permissionPromptOptionDirectoryDescription",{scopePath:i}),grantMode:"persistent",scopeType:"directory",scopePath:i})}return n}function ae(e){const n=e.replace(/\\/g,"/").replace(/^\/+|\/+$/g,"");if(!n)return null;const t=n.split("/");return t.length<=1?n:t.slice(0,-1).join("/")}const R="codingns-plugin:response",le="codingns-plugin:init",pe="codingns-plugin:ready",ce="codingns-plugin:request";async function de(e,n,t){const s=await Q(e,n);return Ee(s.context,t)}async function O(e,n){await W(e,n)}function ue(e){const{iframe:n,pluginId:t,hostOrigin:s,context:i}=e;function l(c){var m;if(c.source!==n.contentWindow||c.origin!==s)return;const d=c.data;if(!d||typeof d!="object")return;if(d.type===pe){(m=n.contentWindow)==null||m.postMessage({type:le,context:i},s);return}const a=d;a.type!==ce||typeof a.requestId!="string"||me({pluginId:t,pluginName:i.pluginName,runtimeSessionId:i.runtimeSessionId,request:a}).then(g=>{var u;(u=n.contentWindow)==null||u.postMessage({type:R,requestId:a.requestId,ok:!0,result:g},s)}).catch(g=>{var u;(u=n.contentWindow)==null||u.postMessage({type:R,requestId:a.requestId,ok:!1,error:Ne(g)},s)})}return window.addEventListener("message",l),()=>{window.removeEventListener("message",l)}}async function me(e){var c,d,a,m,g,u,P;const{pluginId:n,pluginName:t,runtimeSessionId:s,request:i}=e;if(i.action==="callAction"){const p=typeof((c=i.payload)==null?void 0:c.actionId)=="string"?i.payload.actionId.trim():"";if(!p)throw new h(400,{error_code:"PLUGIN_ACTION_ID_REQUIRED",detail:"插件动作请求缺少 actionId"});return await Y(n,p,s,(d=i.payload)==null?void 0:d.input)}if(i.action==="readFile"){const p=_((a=i.payload)==null?void 0:a.path,"插件读文件缺少路径");return await w({pluginId:n,pluginName:t,runtimeSessionId:s,permissionKey:"workspace.read_file",scopePath:p,execute:async()=>await J(n,s,p)})}if(i.action==="writeFile"){const p=_((m=i.payload)==null?void 0:m.path,"插件写文件缺少路径"),E=typeof((g=i.payload)==null?void 0:g.content)=="string"?i.payload.content:"";return await w({pluginId:n,pluginName:t,runtimeSessionId:s,permissionKey:"workspace.write_file",scopePath:p,execute:async()=>await Z(n,s,p,E)})}if(i.action==="listDir"){const p=typeof((u=i.payload)==null?void 0:u.path)=="string"?i.payload.path.trim():"";return{items:(await w({pluginId:n,pluginName:t,runtimeSessionId:s,permissionKey:"workspace.list_dir",scopePath:p||null,execute:async()=>await $(n,s,p||void 0)})).items.map(ge)}}const l=_((P=i.payload)==null?void 0:P.path,"插件桌面动作缺少路径");if(i.action==="openFile"){const p=await w({pluginId:n,pluginName:t,runtimeSessionId:s,permissionKey:"desktop.open_file",scopePath:l,execute:async()=>await V(n,s,l)}),y=await M().fs.openFile(p.absolutePath);if(!y.ok)throw new h(500,{error_code:y.errorCode??"PLUGIN_DESKTOP_OPEN_FAILED",detail:y.detail??"打开文件失败"});return p}if(i.action==="revealInFileManager"){const p=await w({pluginId:n,pluginName:t,runtimeSessionId:s,permissionKey:"desktop.reveal_in_file_manager",scopePath:l,execute:async()=>await X(n,s,l)}),y=await M().fs.revealInFileManager(p.absolutePath);if(!y.ok)throw new h(500,{error_code:y.errorCode??"PLUGIN_DESKTOP_REVEAL_FAILED",detail:y.detail??"打开所在目录失败"});return p}throw new h(400,{error_code:"PLUGIN_BRIDGE_ACTION_UNKNOWN",detail:`未知插件桥动作:${i.action}`})}function _(e,n){const t=typeof e=="string"?e.trim():"";if(!t)throw new h(400,{error_code:"PLUGIN_PATH_REQUIRED",detail:n});return t}function ge(e){return{path:e.path,name:e.name,kind:e.kind,size:e.size,updatedAt:e.updatedAt}}async function w(e){try{return await e.execute()}catch(n){const t=fe(n,e);if(!t||!await we(t))throw n;return await e.execute()}}function fe(e,n){var c,d,a,m;if(!(e instanceof h)||e.errorCode!=="PLUGIN_PERMISSION_GRANT_REQUIRED")return null;const t=Pe((c=e.data)==null?void 0:c.permissionKey,n.permissionKey),s=he((d=e.data)==null?void 0:d.scopeType,n.scopePath?"file":"workspace"),i=typeof((a=e.data)==null?void 0:a.scopePath)=="string"?e.data.scopePath:n.scopePath,l=ye((m=e.data)==null?void 0:m.grantOptions);return{pluginId:n.pluginId,pluginName:n.pluginName,runtimeSessionId:n.runtimeSessionId,permissionKey:t,scopeType:s,scopePath:i,grantOptions:l}}function Pe(e,n){return e==="workspace.read_file"||e==="workspace.list_dir"||e==="workspace.write_file"||e==="desktop.open_file"||e==="desktop.reveal_in_file_manager"?e:n}function he(e,n){return e==="workspace"||e==="directory"||e==="file"?e:n}function ye(e){return Array.isArray(e)?e.filter(n=>n==="once"||n==="session"||n==="persistent"):["once","session"]}let N=null,I=null;async function we(e){return typeof document>"u"?!1:await new Promise(n=>{Ie();const t=i=>{T({open:!1,request:null,submitting:!1,onClose:()=>t(!1),onApprove:()=>{}}),window.setTimeout(()=>n(i),0)};T({open:!0,request:e,submitting:!1,onClose:()=>t(!1),onApprove:async i=>{T({open:!0,request:e,submitting:!0,onClose:()=>{},onApprove:()=>{}});try{await q(e.pluginId,{runtimeSessionId:e.runtimeSessionId,permissionKey:e.permissionKey,scopeType:i.scopeType,scopePath:i.scopePath,grantMode:i.grantMode}),t(!0)}catch{t(!1)}}})})}function Ie(){I||(I=document.createElement("div"),I.dataset.pluginPermissionPrompt="true",document.body.appendChild(I)),N||(N=L.createRoot(I))}function T(e){N&&N.render(f.createElement(U,null,f.createElement(F,null,f.createElement(K,null,f.createElement(oe,{open:e.open,request:e.request,submitting:e.submitting,onClose:e.onClose,onApprove:e.onApprove})))))}function Ee(e,n){if(!e.frontendEntryUrl)throw new h(404,{error_code:"PLUGIN_FRONTEND_NOT_FOUND",detail:"当前插件没有可运行的前端入口"});return{pluginId:e.pluginId,workspaceId:e.workspaceId,runtimeSessionId:e.runtimeSessionId,pluginName:e.pluginName,pluginVersion:e.pluginVersion,frontendEntryUrl:e.frontendEntryUrl,hostOrigin:n}}function Ne(e){return e instanceof h?{code:e.errorCode??`HTTP_${e.status}`,detail:e.message}:e instanceof Error?{code:"PLUGIN_BRIDGE_REQUEST_FAILED",detail:e.message}:{code:"PLUGIN_BRIDGE_REQUEST_FAILED",detail:"插件桥请求失败"}}const be="allow-scripts allow-forms allow-modals allow-downloads";function Me(){const{workspaceId:e="",pluginId:n=""}=B(),t=z(),{showToast:s}=H(),i=f.useRef(null),[l,c]=f.useState(null),[d,a]=f.useState(!0),m=f.useMemo(()=>{const g=x();try{return new URL(g).origin}catch{return window.location.origin}},[]);return f.useEffect(()=>{let g=!1,u=null;return a(!0),c(null),de(n,e,m).then(P=>{if(g){O(n,P.runtimeSessionId).catch(()=>{});return}u=P,c(P)}).catch(P=>{g||s({title:P instanceof Error?P.message:r("plugins.containerLoadFailed"),tone:"error"})}).finally(()=>{g||a(!1)}),()=>{g=!0,u!=null&&u.runtimeSessionId&&O(n,u.runtimeSessionId).catch(()=>{})}},[m,n,s,e]),f.useEffect(()=>{if(!(!l||!i.current))return ue({iframe:i.current,pluginId:n,hostOrigin:m,context:l})},[l,m,n]),d?o.jsx("main",{className:"mobile-feature-page mobile-page-fixed-root plugins-page",children:o.jsx("article",{className:"surface-card plugins-panel plugins-container-panel",children:o.jsx("p",{className:"plugins-hint-text",children:r("plugins.loading")})})}):l?o.jsx("main",{className:"mobile-feature-page mobile-page-fixed-root plugins-page",children:o.jsxs("article",{className:"surface-card plugins-panel plugins-container-panel",children:[o.jsxs("header",{className:"plugins-page-header",children:[o.jsxs("div",{children:[o.jsx("h1",{children:l.pluginName}),o.jsx("p",{children:r("plugins.containerDescription")})]}),o.jsx(A,{children:o.jsx("button",{type:"button",className:"secondary-button",onClick:()=>t(j(e,n)),children:r("plugins.backToDetail")})})]}),o.jsx("div",{className:"plugins-runtime-shell",children:o.jsx("iframe",{ref:i,title:l.pluginName,className:"plugins-runtime-frame",src:C(l.frontendEntryUrl,x()),sandbox:be,referrerPolicy:"no-referrer"})})]})}):o.jsx("main",{className:"mobile-feature-page mobile-page-fixed-root plugins-page",children:o.jsx("article",{className:"surface-card plugins-panel plugins-container-panel",children:o.jsx(v,{title:r("plugins.containerMissingTitle"),description:r("plugins.containerMissingDescription"),action:o.jsx("button",{type:"button",className:"secondary-button",onClick:()=>t(j(e,n)),children:r("plugins.backToDetail")})})})})}export{Me as PluginContainerPage};
@@ -1 +1 @@
1
- import{b as t,j as e,t as s}from"./index-_OCkVmfl.js";import{x as R,N as S,K as o,c as u,u as f,v as d,M as $,O as F}from"./workbench-navigation-RyUjchbD.js";import{c as H,u as W,f as O}from"./App-If9gThKM.js";import{g as z,a as B,b as K,r as U,d as _,e as q}from"./plugins-api-DHJVvPZw.js";import{P as J}from"./PluginAccessOverview-C77TeZTK.js";import"./plugin-permission-copy-DIVk5jNp.js";function se(){var N,E;const{workspaceId:r="",pluginId:l=""}=H(),p=W(),{showToast:c}=O(),[n,T]=t.useState(null),[b,D]=t.useState([]),[L,g]=t.useState([]),[M,h]=t.useState(!0),[I,x]=t.useState(!1),[j,k]=t.useState(!1),[y,v]=t.useState(null);async function m(){h(!0);try{const[i,a]=await Promise.all([z(l),B(l)]);T(i),D(a.items)}catch(i){c({title:i instanceof Error?i.message:s("plugins.detailLoadFailed"),tone:"error"})}finally{h(!1)}}async function w(){const i=r.trim();if(!i||!l.trim()){g([]);return}x(!0);try{const a=await K(l,i);g(a.items)}catch(a){c({title:a instanceof Error?a.message:s("plugins.permissionGrantLoadFailed"),tone:"error"}),g([])}finally{x(!1)}}t.useEffect(()=>{m()},[l]),t.useEffect(()=>{w()},[l,r]);const P=t.useMemo(()=>(n==null?void 0:n.manifest.permissions.desktop)??[],[n]);async function A(){if(!(!n||j)){k(!0);try{n.enablement.enabled?await _(n.definition.id,s("plugins.disabledByUserReason")):await q(n.definition.id),await m(),c({title:n.enablement.enabled?s("plugins.disableSuccess"):s("plugins.enableSuccess"),tone:"success"})}catch(i){c({title:i instanceof Error?i.message:s("plugins.saveFailed"),tone:"error"})}finally{k(!1)}}}async function C(i){const a=r.trim();if(!(!a||y)){v(i.id);try{await U(l,i.id,a),await Promise.all([m(),w()]),c({title:s("plugins.revokeGrantSuccess"),tone:"success"})}catch(G){c({title:G instanceof Error?G.message:s("plugins.revokeGrantFailed"),tone:"error"})}finally{v(null)}}}return M?e.jsx("main",{className:"mobile-feature-page mobile-page-scroll-root plugins-page",children:e.jsx("article",{className:"surface-card plugins-panel",children:e.jsx("p",{className:"plugins-hint-text",children:s("plugins.loading")})})}):n?e.jsx("main",{className:"mobile-feature-page mobile-page-scroll-root plugins-page",children:e.jsxs("article",{className:"surface-card plugins-panel",children:[e.jsxs("header",{className:"plugins-page-header",children:[e.jsxs("div",{children:[e.jsx("h1",{children:n.manifest.name}),e.jsx("p",{children:n.manifest.description??n.definition.id})]}),e.jsxs("div",{className:"plugins-list-tags",children:[e.jsx(o,{tone:n.enablement.enabled?"success":"default",children:n.enablement.enabled?s("plugins.enabled"):s("plugins.disabled")}),e.jsx(o,{children:`v${n.manifest.version}`})]})]}),e.jsx(u,{heading:s("plugins.summaryTitle"),description:s("plugins.summaryDescription"),children:e.jsxs(f,{children:[e.jsx(d,{label:s("plugins.pluginIdLabel"),description:n.definition.id}),e.jsx(d,{label:s("plugins.installRootLabel"),description:n.definition.installRoot}),e.jsx(d,{label:s("plugins.runtimeLabel"),description:n.manifest.backend?`${s("plugins.backendTag")} · ${n.manifest.backend.mode??"on_demand"}`:s("plugins.frontendOnly")})]})}),e.jsx(u,{heading:s("plugins.permissionTitle"),description:s("plugins.permissionDescription"),children:e.jsxs("div",{className:"plugins-list-tags",children:[e.jsx(o,{tone:n.manifest.permissions.workspaceRead?"success":"default",children:n.manifest.permissions.workspaceRead?s("plugins.workspaceReadAllowed"):s("plugins.workspaceReadDenied")}),e.jsx(o,{tone:n.manifest.permissions.network?"warning":"default",children:n.manifest.permissions.network?s("plugins.networkAllowed"):s("plugins.networkDenied")}),P.length>0?P.map(i=>e.jsx(o,{children:i},i)):e.jsx(o,{tone:"default",children:s("plugins.noDesktopPermission")})]})}),e.jsx(J,{grants:L,auditEvents:n.auditEvents,loading:I,revokingGrantId:y,onRevokeGrant:i=>{C(i)}}),(E=(N=n.manifest.backend)==null?void 0:N.actions)!=null&&E.length?e.jsx(u,{heading:s("plugins.actionTitle"),description:s("plugins.actionDescription"),children:e.jsx(f,{children:n.manifest.backend.actions.map(i=>e.jsx(d,{label:i.title,description:`${i.id} · ${i.timeoutMs??3e4}ms`},i.id))})}):null,e.jsx(u,{heading:s("plugins.runHistoryTitle"),description:s("plugins.runHistoryDescription"),children:b.length===0?e.jsx(R,{title:s("plugins.runHistoryEmptyTitle"),description:s("plugins.runHistoryEmptyDescription")}):e.jsx(f,{children:b.slice(0,10).map(i=>e.jsx(d,{label:i.actionId??s("plugins.unknownAction"),description:`${i.status} · ${i.createdAt}`,trailing:i.errorCode?e.jsx(o,{tone:"danger",children:i.errorCode}):null},i.id))})}),e.jsxs($,{align:"between",stack:!0,children:[e.jsx("button",{type:"button",className:"secondary-button",onClick:()=>p(S(r)),children:s("plugins.backToList")}),e.jsxs("div",{className:"plugins-detail-actions",children:[n.frontend?e.jsx("button",{type:"button",className:"secondary-button",onClick:()=>p(F(r,n.definition.id)),children:s("plugins.openPlugin")}):null,e.jsx("button",{type:"button",className:n.enablement.enabled?"secondary-button":"primary-button",disabled:j,onClick:()=>{A()},children:n.enablement.enabled?s("plugins.disableAction"):s("plugins.enableAction")})]})]})]})}):e.jsx("main",{className:"mobile-feature-page mobile-page-scroll-root plugins-page",children:e.jsx("article",{className:"surface-card plugins-panel",children:e.jsx(R,{title:s("plugins.detailMissingTitle"),description:s("plugins.detailMissingDescription"),action:e.jsx("button",{type:"button",className:"secondary-button",onClick:()=>p(S(r)),children:s("plugins.backToList")})})})})}export{se as PluginDetailPage};
1
+ import{b as t,j as e,t as s}from"./index-FOhyOpGY.js";import{x as R,N as S,K as o,c as u,u as f,v as d,M as $,O as F}from"./workbench-navigation-aqJ1ay4M.js";import{c as H,u as W,f as O}from"./App-Dl-mcdqy.js";import{g as z,a as B,b as K,r as U,d as _,e as q}from"./plugins-api-CnZYRKoS.js";import{P as J}from"./PluginAccessOverview-BBgM6tb0.js";import"./plugin-permission-copy-apDn8EWG.js";function se(){var N,E;const{workspaceId:r="",pluginId:l=""}=H(),p=W(),{showToast:c}=O(),[n,T]=t.useState(null),[b,D]=t.useState([]),[L,g]=t.useState([]),[M,h]=t.useState(!0),[I,x]=t.useState(!1),[j,k]=t.useState(!1),[y,v]=t.useState(null);async function m(){h(!0);try{const[i,a]=await Promise.all([z(l),B(l)]);T(i),D(a.items)}catch(i){c({title:i instanceof Error?i.message:s("plugins.detailLoadFailed"),tone:"error"})}finally{h(!1)}}async function w(){const i=r.trim();if(!i||!l.trim()){g([]);return}x(!0);try{const a=await K(l,i);g(a.items)}catch(a){c({title:a instanceof Error?a.message:s("plugins.permissionGrantLoadFailed"),tone:"error"}),g([])}finally{x(!1)}}t.useEffect(()=>{m()},[l]),t.useEffect(()=>{w()},[l,r]);const P=t.useMemo(()=>(n==null?void 0:n.manifest.permissions.desktop)??[],[n]);async function A(){if(!(!n||j)){k(!0);try{n.enablement.enabled?await _(n.definition.id,s("plugins.disabledByUserReason")):await q(n.definition.id),await m(),c({title:n.enablement.enabled?s("plugins.disableSuccess"):s("plugins.enableSuccess"),tone:"success"})}catch(i){c({title:i instanceof Error?i.message:s("plugins.saveFailed"),tone:"error"})}finally{k(!1)}}}async function C(i){const a=r.trim();if(!(!a||y)){v(i.id);try{await U(l,i.id,a),await Promise.all([m(),w()]),c({title:s("plugins.revokeGrantSuccess"),tone:"success"})}catch(G){c({title:G instanceof Error?G.message:s("plugins.revokeGrantFailed"),tone:"error"})}finally{v(null)}}}return M?e.jsx("main",{className:"mobile-feature-page mobile-page-scroll-root plugins-page",children:e.jsx("article",{className:"surface-card plugins-panel",children:e.jsx("p",{className:"plugins-hint-text",children:s("plugins.loading")})})}):n?e.jsx("main",{className:"mobile-feature-page mobile-page-scroll-root plugins-page",children:e.jsxs("article",{className:"surface-card plugins-panel",children:[e.jsxs("header",{className:"plugins-page-header",children:[e.jsxs("div",{children:[e.jsx("h1",{children:n.manifest.name}),e.jsx("p",{children:n.manifest.description??n.definition.id})]}),e.jsxs("div",{className:"plugins-list-tags",children:[e.jsx(o,{tone:n.enablement.enabled?"success":"default",children:n.enablement.enabled?s("plugins.enabled"):s("plugins.disabled")}),e.jsx(o,{children:`v${n.manifest.version}`})]})]}),e.jsx(u,{heading:s("plugins.summaryTitle"),description:s("plugins.summaryDescription"),children:e.jsxs(f,{children:[e.jsx(d,{label:s("plugins.pluginIdLabel"),description:n.definition.id}),e.jsx(d,{label:s("plugins.installRootLabel"),description:n.definition.installRoot}),e.jsx(d,{label:s("plugins.runtimeLabel"),description:n.manifest.backend?`${s("plugins.backendTag")} · ${n.manifest.backend.mode??"on_demand"}`:s("plugins.frontendOnly")})]})}),e.jsx(u,{heading:s("plugins.permissionTitle"),description:s("plugins.permissionDescription"),children:e.jsxs("div",{className:"plugins-list-tags",children:[e.jsx(o,{tone:n.manifest.permissions.workspaceRead?"success":"default",children:n.manifest.permissions.workspaceRead?s("plugins.workspaceReadAllowed"):s("plugins.workspaceReadDenied")}),e.jsx(o,{tone:n.manifest.permissions.network?"warning":"default",children:n.manifest.permissions.network?s("plugins.networkAllowed"):s("plugins.networkDenied")}),P.length>0?P.map(i=>e.jsx(o,{children:i},i)):e.jsx(o,{tone:"default",children:s("plugins.noDesktopPermission")})]})}),e.jsx(J,{grants:L,auditEvents:n.auditEvents,loading:I,revokingGrantId:y,onRevokeGrant:i=>{C(i)}}),(E=(N=n.manifest.backend)==null?void 0:N.actions)!=null&&E.length?e.jsx(u,{heading:s("plugins.actionTitle"),description:s("plugins.actionDescription"),children:e.jsx(f,{children:n.manifest.backend.actions.map(i=>e.jsx(d,{label:i.title,description:`${i.id} · ${i.timeoutMs??3e4}ms`},i.id))})}):null,e.jsx(u,{heading:s("plugins.runHistoryTitle"),description:s("plugins.runHistoryDescription"),children:b.length===0?e.jsx(R,{title:s("plugins.runHistoryEmptyTitle"),description:s("plugins.runHistoryEmptyDescription")}):e.jsx(f,{children:b.slice(0,10).map(i=>e.jsx(d,{label:i.actionId??s("plugins.unknownAction"),description:`${i.status} · ${i.createdAt}`,trailing:i.errorCode?e.jsx(o,{tone:"danger",children:i.errorCode}):null},i.id))})}),e.jsxs($,{align:"between",stack:!0,children:[e.jsx("button",{type:"button",className:"secondary-button",onClick:()=>p(S(r)),children:s("plugins.backToList")}),e.jsxs("div",{className:"plugins-detail-actions",children:[n.frontend?e.jsx("button",{type:"button",className:"secondary-button",onClick:()=>p(F(r,n.definition.id)),children:s("plugins.openPlugin")}):null,e.jsx("button",{type:"button",className:n.enablement.enabled?"secondary-button":"primary-button",disabled:j,onClick:()=>{A()},children:n.enablement.enabled?s("plugins.disableAction"):s("plugins.enableAction")})]})]})]})}):e.jsx("main",{className:"mobile-feature-page mobile-page-scroll-root plugins-page",children:e.jsx("article",{className:"surface-card plugins-panel",children:e.jsx(R,{title:s("plugins.detailMissingTitle"),description:s("plugins.detailMissingDescription"),action:e.jsx("button",{type:"button",className:"secondary-button",onClick:()=>p(S(r)),children:s("plugins.backToList")})})})})}export{se as PluginDetailPage};
@@ -1 +1 @@
1
- import{b as i,t as a,j as e}from"./index-_OCkVmfl.js";import{x as m,u as g,v as h,L as x,K as n}from"./workbench-navigation-RyUjchbD.js";import{c as f,u as j,f as b}from"./App-If9gThKM.js";import{l as v}from"./plugins-api-DHJVvPZw.js";function k(){const{workspaceId:d=""}=f(),u=j(),{showToast:r}=b(),[l,p]=i.useState([]),[o,c]=i.useState(!0);return i.useEffect(()=>{let s=!1;return c(!0),v().then(t=>{s||p(t.items)}).catch(t=>{s||r({title:t instanceof Error?t.message:a("plugins.listLoadFailed"),tone:"error"})}).finally(()=>{s||c(!1)}),()=>{s=!0}},[r]),e.jsx("main",{className:"mobile-feature-page mobile-page-scroll-root plugins-page",children:e.jsxs("article",{className:"surface-card plugins-panel",children:[e.jsx("header",{className:"plugins-page-header",children:e.jsxs("div",{children:[e.jsx("h1",{children:a("plugins.listTitle")}),e.jsx("p",{children:a("plugins.listDescription")})]})}),o?e.jsx("p",{className:"plugins-hint-text",children:a("plugins.loading")}):null,!o&&l.length===0?e.jsx(m,{title:a("plugins.emptyTitle"),description:a("plugins.emptyDescription")}):null,l.length>0?e.jsx(g,{className:"plugins-list",children:l.map(s=>e.jsx(h,{as:"button",className:"plugins-list-item",label:s.name,description:`${s.id} · v${s.version}`,trailing:e.jsxs("div",{className:"plugins-list-tags",children:[e.jsx(n,{tone:s.enabled?"success":"default",children:s.enabled?a("plugins.enabled"):a("plugins.disabled")}),s.hasFrontend?e.jsx(n,{children:a("plugins.frontendTag")}):null,s.hasBackend?e.jsx(n,{children:a("plugins.backendTag")}):null]}),onClick:()=>u(x(d,s.id))},s.id))}):null]})})}export{k as PluginsListPage};
1
+ import{b as i,t as a,j as e}from"./index-FOhyOpGY.js";import{x as m,u as g,v as h,L as x,K as n}from"./workbench-navigation-aqJ1ay4M.js";import{c as f,u as j,f as b}from"./App-Dl-mcdqy.js";import{l as v}from"./plugins-api-CnZYRKoS.js";function k(){const{workspaceId:d=""}=f(),u=j(),{showToast:r}=b(),[l,p]=i.useState([]),[o,c]=i.useState(!0);return i.useEffect(()=>{let s=!1;return c(!0),v().then(t=>{s||p(t.items)}).catch(t=>{s||r({title:t instanceof Error?t.message:a("plugins.listLoadFailed"),tone:"error"})}).finally(()=>{s||c(!1)}),()=>{s=!0}},[r]),e.jsx("main",{className:"mobile-feature-page mobile-page-scroll-root plugins-page",children:e.jsxs("article",{className:"surface-card plugins-panel",children:[e.jsx("header",{className:"plugins-page-header",children:e.jsxs("div",{children:[e.jsx("h1",{children:a("plugins.listTitle")}),e.jsx("p",{children:a("plugins.listDescription")})]})}),o?e.jsx("p",{className:"plugins-hint-text",children:a("plugins.loading")}):null,!o&&l.length===0?e.jsx(m,{title:a("plugins.emptyTitle"),description:a("plugins.emptyDescription")}):null,l.length>0?e.jsx(g,{className:"plugins-list",children:l.map(s=>e.jsx(h,{as:"button",className:"plugins-list-item",label:s.name,description:`${s.id} · v${s.version}`,trailing:e.jsxs("div",{className:"plugins-list-tags",children:[e.jsx(n,{tone:s.enabled?"success":"default",children:s.enabled?a("plugins.enabled"):a("plugins.disabled")}),s.hasFrontend?e.jsx(n,{children:a("plugins.frontendTag")}):null,s.hasBackend?e.jsx(n,{children:a("plugins.backendTag")}):null]}),onClick:()=>u(x(d,s.id))},s.id))}):null]})})}export{k as PluginsListPage};
@@ -1 +1 @@
1
- import{o as m,b as d,e as g,j as n,t as i}from"./index-_OCkVmfl.js";import{u as p,c as f,d as y}from"./App-If9gThKM.js";import{b as E}from"./relay-entry-B5GmiOrR.js";function I(){const r=p(),{tunnelDomain:t}=f(),[e]=y(),s=m(),[a,c]=d.useState(null);return d.useEffect(()=>{var u;const l=((u=e.get("controlBaseUrl"))==null?void 0:u.trim())??"";if(!t||!l){c(s("auth.relayEntryInvalid"));return}let o=!1;const h=x(e.get("returnTo"));return g.update(E(g.getState(),{tunnelDomain:t,controlBaseUrl:l,bindingId:e.get("bindingId"),hostFingerprint:e.get("hostFingerprint")})).then(()=>{o||r(`/login?returnTo=${encodeURIComponent(h)}`,{replace:!0})}).catch(()=>{o||c(s("auth.relayEntryInvalid"))}),()=>{o=!0}},[r,e,s,t]),n.jsxs("section",{children:[n.jsx("h1",{children:i("auth.relayEntryTitle")}),n.jsx("p",{children:i("auth.relayEntryDescription")}),a?n.jsx("p",{children:a}):null,a?null:n.jsx("p",{children:i("common.loading")})]})}function x(r){const t=r==null?void 0:r.trim();return!t||!t.startsWith("/")?"/":t}export{I as RelayConnectEntryPage};
1
+ import{p as m,b as d,e as g,j as n,t as i}from"./index-FOhyOpGY.js";import{u as p,c as f,d as y}from"./App-Dl-mcdqy.js";import{b as E}from"./relay-entry-DhHwflXl.js";function I(){const r=p(),{tunnelDomain:t}=f(),[e]=y(),s=m(),[a,c]=d.useState(null);return d.useEffect(()=>{var u;const l=((u=e.get("controlBaseUrl"))==null?void 0:u.trim())??"";if(!t||!l){c(s("auth.relayEntryInvalid"));return}let o=!1;const h=x(e.get("returnTo"));return g.update(E(g.getState(),{tunnelDomain:t,controlBaseUrl:l,bindingId:e.get("bindingId"),hostFingerprint:e.get("hostFingerprint")})).then(()=>{o||r(`/login?returnTo=${encodeURIComponent(h)}`,{replace:!0})}).catch(()=>{o||c(s("auth.relayEntryInvalid"))}),()=>{o=!0}},[r,e,s,t]),n.jsxs("section",{children:[n.jsx("h1",{children:i("auth.relayEntryTitle")}),n.jsx("p",{children:i("auth.relayEntryDescription")}),a?n.jsx("p",{children:a}):null,a?null:n.jsx("p",{children:i("common.loading")})]})}function x(r){const t=r==null?void 0:r.trim();return!t||!t.startsWith("/")?"/":t}export{I as RelayConnectEntryPage};
@@ -1 +1 @@
1
- import{b as n,n as U,j as r,t as s,e as N}from"./index-_OCkVmfl.js";import{r as E,b as k}from"./relay-entry-B5GmiOrR.js";import{a as h,x as O,y as P,z as w}from"./App-If9gThKM.js";import{W as T}from"./WorkbenchModal-xbx1o6MO.js";import"./DesktopModal-bMdI1jEe.js";function A({isOpen:t,onClose:u,onSave:c,theme:$="dark"}){const d=h(e=>e.baseUrl),B=h(e=>e.options),p=h(e=>e.presetOptions),f=P(),[i,o]=n.useState(d),[g,l]=n.useState(null),[v,m]=n.useState(!1),a=n.useMemo(()=>{try{return U(i)}catch{return null}},[i]),x=O(a??i,B),S=p.find(e=>e.value===x)??null,b="server-settings-preset",j="server-settings-address";if(n.useEffect(()=>{t&&(o(d),l(null),m(!1))},[t,d]),!t)return null;async function I(){if(!a){l(s("auth.serverInvalid"));return}m(!0);try{const e=await E(a);e?await N.update(k(N.getState(),e)):w.setBaseUrl(a),c==null||c(a),u()}catch(e){l(e instanceof Error&&e.message.trim()?e.message:s("auth.serverInvalid"))}finally{m(!1)}}function C(){a&&o(a)}return r.jsx(T,{open:t,title:s("auth.serverSettingsTitle"),description:s("auth.serverHint"),className:"server-settings-modal-card",onClose:u,children:r.jsxs("form",{className:"server-settings-modal-form",onSubmit:e=>{e.preventDefault(),I()},children:[r.jsxs("label",{className:"workbench-modal-field",htmlFor:b,children:[r.jsx("span",{children:s("auth.serverPreset")}),r.jsxs("select",{id:b,"aria-label":s("auth.serverPreset"),value:x,onChange:e=>{const y=e.target.value;y!==f&&(o(y),l(null))},children:[p.map(e=>r.jsx("option",{value:e.value,children:V(e)},`${e.source}:${e.value}`)),r.jsx("option",{value:f,children:s("auth.serverCustomOption")})]})]}),S?r.jsx("div",{className:"server-settings-modal-tags","aria-live":"polite",children:S.source==="discovered"?r.jsx("span",{className:"server-settings-modal-tag","data-tone":"discovered",children:s("auth.serverDiscoveredTag")}):null}):null,r.jsxs("label",{className:"workbench-modal-field",htmlFor:j,children:[r.jsx("span",{children:s("auth.serverAddress")}),r.jsx("input",{id:j,"aria-label":s("auth.serverAddress"),value:i,placeholder:s("auth.serverPlaceholder"),disabled:v,onBlur:C,onChange:e=>{o(e.target.value),l(null)}})]}),g?r.jsx("p",{className:"server-settings-modal-status","data-tone":"error",children:g}):r.jsx("p",{className:"server-settings-modal-hint",children:s("auth.serverHint")}),r.jsxs("div",{className:"workbench-modal-actions",children:[r.jsx("button",{type:"button",className:"secondary-button",onClick:u,children:s("common.cancel")}),r.jsx("button",{type:"submit",className:"primary-button",disabled:v,children:v?s("common.loading"):s("auth.saveServerSettings")})]})]})})}function V(t){return t.source==="discovered"?`${t.value} · ${s("auth.serverDiscoveredTag")}`:t.value}export{A as ServerSettingsModal};
1
+ import{b as n,n as U,j as r,t as s,e as N}from"./index-FOhyOpGY.js";import{r as E,b as k}from"./relay-entry-DhHwflXl.js";import{a as h,B as O,C as P,D as w}from"./App-Dl-mcdqy.js";import{W as T}from"./WorkbenchModal-DWsNm2B2.js";import"./DesktopModal-BnfGW2gk.js";function A({isOpen:t,onClose:u,onSave:c,theme:V="dark"}){const d=h(e=>e.baseUrl),B=h(e=>e.options),p=h(e=>e.presetOptions),f=P(),[i,o]=n.useState(d),[g,l]=n.useState(null),[v,m]=n.useState(!1),a=n.useMemo(()=>{try{return U(i)}catch{return null}},[i]),x=O(a??i,B),S=p.find(e=>e.value===x)??null,b="server-settings-preset",j="server-settings-address";if(n.useEffect(()=>{t&&(o(d),l(null),m(!1))},[t,d]),!t)return null;async function C(){if(!a){l(s("auth.serverInvalid"));return}m(!0);try{const e=await E(a);e?await N.update(k(N.getState(),e)):w.setBaseUrl(a),c==null||c(a),u()}catch(e){l(e instanceof Error&&e.message.trim()?e.message:s("auth.serverInvalid"))}finally{m(!1)}}function I(){a&&o(a)}return r.jsx(T,{open:t,title:s("auth.serverSettingsTitle"),description:s("auth.serverHint"),className:"server-settings-modal-card",onClose:u,children:r.jsxs("form",{className:"server-settings-modal-form",onSubmit:e=>{e.preventDefault(),C()},children:[r.jsxs("label",{className:"workbench-modal-field",htmlFor:b,children:[r.jsx("span",{children:s("auth.serverPreset")}),r.jsxs("select",{id:b,"aria-label":s("auth.serverPreset"),value:x,onChange:e=>{const y=e.target.value;y!==f&&(o(y),l(null))},children:[p.map(e=>r.jsx("option",{value:e.value,children:D(e)},`${e.source}:${e.value}`)),r.jsx("option",{value:f,children:s("auth.serverCustomOption")})]})]}),S?r.jsx("div",{className:"server-settings-modal-tags","aria-live":"polite",children:S.source==="discovered"?r.jsx("span",{className:"server-settings-modal-tag","data-tone":"discovered",children:s("auth.serverDiscoveredTag")}):null}):null,r.jsxs("label",{className:"workbench-modal-field",htmlFor:j,children:[r.jsx("span",{children:s("auth.serverAddress")}),r.jsx("input",{id:j,"aria-label":s("auth.serverAddress"),value:i,placeholder:s("auth.serverPlaceholder"),disabled:v,onBlur:I,onChange:e=>{o(e.target.value),l(null)}})]}),g?r.jsx("p",{className:"server-settings-modal-status","data-tone":"error",children:g}):r.jsx("p",{className:"server-settings-modal-hint",children:s("auth.serverHint")}),r.jsxs("div",{className:"workbench-modal-actions",children:[r.jsx("button",{type:"button",className:"secondary-button",onClick:u,children:s("common.cancel")}),r.jsx("button",{type:"submit",className:"primary-button",disabled:v,children:v?s("common.loading"):s("auth.saveServerSettings")})]})]})})}function D(t){return t.source==="discovered"?`${t.value} · ${s("auth.serverDiscoveredTag")}`:t.value}export{A as ServerSettingsModal};