@openchamber/web 1.18.2 → 1.18.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (136) hide show
  1. package/bin/lib/commands-models.js +1 -1
  2. package/dist/assets/{CodeMirrorCommentWidgets-CxcJ5x9h.js → CodeMirrorCommentWidgets-DbUi6I9s.js} +1 -1
  3. package/dist/assets/{CommitSection-C9sBBYAJ.js → CommitSection-Jc2_hNPE.js} +1 -1
  4. package/dist/assets/{DiagramEditor-C7nUw7p3.js → DiagramEditor-PCrYHBko.js} +1 -1
  5. package/dist/assets/{DiagramView-cYxZP-HS.js → DiagramView-CndEcZNu.js} +1 -1
  6. package/dist/assets/{DiffView-1zd0slLu.js → DiffView-DEGlNjMH.js} +2 -2
  7. package/dist/assets/FilesView-CzUgIvUm.js +14 -0
  8. package/dist/assets/{GitView-OSVIn5V1.js → GitView-C-n17voy.js} +1 -1
  9. package/dist/assets/{JsonTreeView-Kgepz4pR.js → JsonTreeView-BYcgdTOQ.js} +1 -1
  10. package/dist/assets/MarkdownImageGallery-DzHwkVIH.js +1 -0
  11. package/dist/assets/MarkdownRendererImpl-DUcIcWgs.js +12 -0
  12. package/dist/assets/OnboardingScreen-BmN0lhk4.js +1 -0
  13. package/dist/assets/{PatchDiff-Cddz02Ya.js → PatchDiff-Bn7bfgUv.js} +1 -1
  14. package/dist/assets/{PierreDiffViewer-B5k0KvPW.js → PierreDiffViewer-D1fWvrUn.js} +2 -2
  15. package/dist/assets/{PlanView-BYgHBHDt.js → PlanView-CWM0iyFk.js} +3 -3
  16. package/dist/assets/{SessionSwitcherDropdown-ig2OT22Z.js → SessionSwitcherDropdown-Cez-9xRh.js} +1 -1
  17. package/dist/assets/SettingsView-Bl1drwPw.js +28 -0
  18. package/dist/assets/{SettingsWindow-CNHM8ifT.js → SettingsWindow-DL5axjDZ.js} +1 -1
  19. package/dist/assets/{ToolOutputDialog-DrGeYq2p.js → ToolOutputDialog-BtIJkFno.js} +7 -7
  20. package/dist/assets/{ToolPartDiffPreview-BRmPpe94.js → ToolPartDiffPreview-i3PQo6_0.js} +1 -1
  21. package/dist/assets/{VirtualizedFileDiff-Dcu8Q-5P.js → VirtualizedFileDiff-DkcusvMa.js} +1 -1
  22. package/dist/assets/{WalkthroughView-HStEYdD2.js → WalkthroughView-Cc5Hd6P5.js} +2 -2
  23. package/dist/assets/{computeVirtualFileMetrics-DQE7R9IY.js → computeVirtualFileMetrics-xPena3W2.js} +2 -2
  24. package/dist/assets/contextPanelEmbeddedChat-tQekJUAF.js +1 -0
  25. package/dist/assets/de-u7gSnqWs.js +9 -0
  26. package/dist/assets/es-T9O7aAOr.js +15 -0
  27. package/dist/assets/fr-Oor7ewbE.js +13 -0
  28. package/dist/assets/index-CVNuER6G.css +1 -0
  29. package/dist/assets/{index-BgQEgA2a.js → index-Crz1YOFl.js} +1 -1
  30. package/dist/assets/index-iFY_N5aO.js +7 -0
  31. package/dist/assets/{isDiffPlainText-XyBCe4eD.js → isDiffPlainText-Dudf-dWx.js} +1 -1
  32. package/dist/assets/{isFilePlainText-JbqDfa3n.js → isFilePlainText-DS4QV1dd.js} +1 -1
  33. package/dist/assets/ja-DHpqbVmr.js +15 -0
  34. package/dist/assets/ko-CwLkS3nx.js +15 -0
  35. package/dist/assets/{main-LfcbGv7C.js → main-C0DyIwTb.js} +2 -2
  36. package/dist/assets/main-CAxX6DAN.js +915 -0
  37. package/dist/assets/markdownCore-DhfzuGXu.js +2 -0
  38. package/dist/assets/markdownImageAssets-BTNlRyjd.js +1 -0
  39. package/dist/assets/{miniChat-CUp_elRz.js → miniChat-CGfrxKpJ.js} +2 -2
  40. package/dist/assets/{mobile-CBSN7BsH.js → mobile-DEmhwNcV.js} +2 -2
  41. package/dist/assets/{patchFileDiff-DCIXUHRJ.js → patchFileDiff-C5D1OPCa.js} +2 -2
  42. package/dist/assets/{pl-tHTP6XQx.js → pl-CcZILN8q.js} +4 -4
  43. package/dist/assets/pt-BR-DYHhVK6o.js +15 -0
  44. package/dist/assets/{renderElectronMiniChatApp-eZl-5STF.js → renderElectronMiniChatApp-Dpbswpom.js} +2 -2
  45. package/dist/assets/renderMobileApp-B5HA4qbi.js +25 -0
  46. package/dist/assets/runtimeEndpointReset-cbahJ3hD.js +13 -0
  47. package/dist/assets/scheduledTasksApi-BxgGWTL8.js +1 -0
  48. package/dist/assets/{shikiHighlight-eU8abJ3T.js → shikiHighlight-CmanopUB.js} +1 -1
  49. package/dist/assets/uk-BA2kZR38.js +15 -0
  50. package/dist/assets/{useAppFontEffects-Bbpz77To.js → useAppFontEffects-sHmU5b8u.js} +137 -137
  51. package/dist/assets/useInlineCommentController-gt56WkxJ.js +2 -0
  52. package/dist/assets/{vendor-codemirror-language-data-Dzt9rWZZ.js → vendor-codemirror-language-data-Dihw9MtL.js} +2 -2
  53. package/dist/assets/{vendor-marked-i_gIkIP3.js → vendor-marked-CX41MkDF.js} +1 -1
  54. package/dist/assets/{web-components-DGvnI0zx.js → web-components-BL-Ur2Tb.js} +1 -1
  55. package/dist/assets/zh-CN-dlOQK6v9.js +15 -0
  56. package/dist/assets/zh-TW-BnqQ-WL5.js +15 -0
  57. package/dist/index.html +4 -4
  58. package/dist/mini-chat.html +3 -3
  59. package/dist/mobile.html +3 -3
  60. package/package.json +2 -2
  61. package/server/index.js +65 -19
  62. package/server/lib/agent-tool/DOCUMENTATION.md +21 -6
  63. package/server/lib/agent-tool/runtime.js +90 -16
  64. package/server/lib/agent-tool/runtime.test.js +86 -0
  65. package/server/lib/browser-control/DOCUMENTATION.md +50 -0
  66. package/server/lib/browser-control/broker.js +154 -0
  67. package/server/lib/browser-control/broker.test.js +191 -0
  68. package/server/lib/browser-control/routes.js +48 -0
  69. package/server/lib/browser-control/routes.test.js +108 -0
  70. package/server/lib/dev-servers/parse.js +203 -0
  71. package/server/lib/dev-servers/parse.test.js +174 -0
  72. package/server/lib/dev-servers/routes.js +135 -0
  73. package/server/lib/dev-tunnel/DOCUMENTATION.md +57 -0
  74. package/server/lib/dev-tunnel/client.js +174 -0
  75. package/server/lib/dev-tunnel/runtime.js +189 -0
  76. package/server/lib/dev-tunnel/tunnel.test.js +282 -0
  77. package/server/lib/git/credentials.js +0 -33
  78. package/server/lib/github/DOCUMENTATION.md +1 -1
  79. package/server/lib/openchamber-control/DOCUMENTATION.md +9 -0
  80. package/server/lib/openchamber-control/actions.js +33 -1
  81. package/server/lib/openchamber-control/screenshots.js +83 -0
  82. package/server/lib/openchamber-control/screenshots.test.js +84 -0
  83. package/server/lib/openchamber-control/service.js +141 -2
  84. package/server/lib/openchamber-control/service.test.js +55 -0
  85. package/server/lib/opencode/core-routes.js +31 -52
  86. package/server/lib/opencode/core-routes.test.js +37 -9
  87. package/server/lib/opencode/feature-routes-runtime.js +4 -0
  88. package/server/lib/opencode/settings-helpers.js +3 -9
  89. package/server/lib/projects/project-config.js +181 -2
  90. package/server/lib/projects/project-config.test.js +295 -0
  91. package/server/lib/quota/DOCUMENTATION.md +4 -2
  92. package/server/lib/quota/credentials/providers.js +0 -7
  93. package/server/lib/quota/credentials/store.js +11 -1
  94. package/server/lib/quota/credentials/store.test.js +9 -1
  95. package/server/lib/quota/providers/opencode-go.js +35 -35
  96. package/server/lib/quota/providers/opencode-go.test.js +52 -7
  97. package/server/lib/quota/routes.js +0 -2
  98. package/server/lib/relay/DOCUMENTATION.md +2 -0
  99. package/server/lib/relay/tunnel-host.js +157 -33
  100. package/server/lib/relay/tunnel-host.test.js +147 -0
  101. package/server/lib/scheduled-tasks/DOCUMENTATION.md +49 -0
  102. package/server/lib/scheduled-tasks/issue-2710-double-execution.test.js +488 -0
  103. package/server/lib/scheduled-tasks/routes.js +6 -0
  104. package/server/lib/scheduled-tasks/runtime.js +369 -108
  105. package/server/lib/scheduled-tasks/service.js +7 -1
  106. package/server/lib/scheduled-tasks/service.test.js +20 -0
  107. package/server/lib/walkthrough/index.js +0 -2
  108. package/server/sse-routes.test.js +3 -0
  109. package/dist/assets/FilesView-WkxsWHBE.js +0 -14
  110. package/dist/assets/MarkdownRendererImpl-CKAsRfIk.js +0 -12
  111. package/dist/assets/OnboardingScreen-BCgYA7J5.js +0 -1
  112. package/dist/assets/SettingsView-e7Fmxnz8.js +0 -28
  113. package/dist/assets/contextPanelEmbeddedChat-5VGWIT_J.js +0 -1
  114. package/dist/assets/de-B6t6T54h.js +0 -9
  115. package/dist/assets/es-DH9NUKge.js +0 -15
  116. package/dist/assets/fr-Do4t2KmA.js +0 -13
  117. package/dist/assets/index-B45s9aAX.css +0 -1
  118. package/dist/assets/index-CNrN5qDs.js +0 -7
  119. package/dist/assets/ja-DJT9EM80.js +0 -15
  120. package/dist/assets/ko-CfWRq2p4.js +0 -15
  121. package/dist/assets/main-B4oBRI9u.js +0 -193
  122. package/dist/assets/markdownCore-A3_L34oS.js +0 -2
  123. package/dist/assets/pt-BR-BDEzzltP.js +0 -15
  124. package/dist/assets/renderMobileApp-DA7wpIBi.js +0 -23
  125. package/dist/assets/runtimeEndpointReset-D5izT-u5.js +0 -13
  126. package/dist/assets/scheduledTasksApi-CTJdfSWc.js +0 -1
  127. package/dist/assets/uk-B6Q32nyk.js +0 -15
  128. package/dist/assets/useInlineCommentController-D7zs7-BQ.js +0 -2
  129. package/dist/assets/vendor-zumer-snapdom-Btyu_Xi2.js +0 -8
  130. package/dist/assets/zh-CN-7MGcwGaC.js +0 -15
  131. package/dist/assets/zh-TW-CFPfqxlL.js +0 -15
  132. package/server/lib/preview/proxy-runtime.js +0 -1604
  133. package/server/lib/preview/proxy-runtime.test.js +0 -528
  134. package/server/lib/quota/opencode-go-credentials.js +0 -11
  135. package/server/lib/quota/opencode-go-credentials.test.js +0 -32
  136. package/server/lib/quota/routes.test.js +0 -40
@@ -1,14 +0,0 @@
1
- import{R as n,j as s,f as Kt}from"./vendor-react-BUCujlKS.js";import{P as Jn,Q as Xn,R as Qn,S as Yn,ag as Ni,m as Le,u as he,cO as Zn,A as Ci,t as ea,r as ki,W as rr,e as ta,cP as sa,V as ra,cQ as ia}from"./index-CNrN5qDs.js";import{f as Rs,R as Vs,B as S,g as O,U as na,K as aa,aU as oa,$ as la,a0 as ca,b$ as da,gR as Si,gp as ua,t as I,k as Ti,a9 as ir,bW as Ns,cr as fa,b as ma,gS as nr,aa as Vi,gT as Di,bX as Ri,bY as pa,fL as ha,gU as ga,bq as xa,gV as Ei,br as Ui,bs as Gi,bt as Ki,bu as Hi,bv as qi,bw as _i,I as g,aT as fr,aQ as mr,ac as ks,aS as pr,aO as Ss,aW as ht,aX as gt,aY as xt,bV as ar,ab as or,bR as Pi,bx as va,by as wa,gn as lr,aP as Ds,aR as ba,aZ as ya}from"./useAppFontEffects-Bbpz77To.js";import{v as ja,w as Fa,x as Na,y as Ca,z as ka}from"./runtimeEndpointReset-D5izT-u5.js";import{c as Mi,s as Sa,C as zi,P as cr}from"./shikiHighlight-eU8abJ3T.js";import{a as Ta}from"./vendor-codemirror-state-CNWM3Q8V.js";import{E as Tt}from"./vendor-codemirror-view-DSzLbZiS.js";import{F as Va,J as Da}from"./JsonTreeView-Kgepz4pR.js";import{ensurePierreThemeRegistered as Li,getResolvedShikiTheme as Ra}from"./appThemeRegistry-BK0dHKa6.js";import{D as Ea}from"./DiagramEditor-C7nUw7p3.js";import{u as Pa,n as Ma}from"./useInlineCommentController-D7zs7-BQ.js";import{b as za}from"./CodeMirrorCommentWidgets-CxcJ5x9h.js";import{u as Cs,c as La}from"./scheduledTasksApi-CTJdfSWc.js";import"./vendor-scheduler-7OC5HNn7.js";import"./vendor-vite-runtime-DD1OZmLC.js";import"./vendor-opencode-sdk-BJ73u-bH.js";import"./vendor-zustand-BAGL70zf.js";import"./vendor-simplewebauthn-browser-VDA66rT_.js";import"./vendor-base-ui-D_V6hAcE.js";import"./vendor-floating-ui-utils-BzXdqYpP.js";import"./vendor-floating-ui-dom-WyXykhNi.js";import"./vendor-floating-ui-core-CXmKXOXc.js";import"./vendor-floating-ui-react-dom-DKpLs02S.js";import"./vendor-use-sync-external-store-D6wYuSt-.js";import"./contextPanelEmbeddedChat-5VGWIT_J.js";import"./vendor-class-variance-authority-5VPnzWs2.js";import"./vendor-clsx-B-dksMZM.js";import"./vendor-dnd-kit-core-BZknOX2w.js";import"./vendor-dnd-kit-utilities-B_MdXhJC.js";import"./vendor-dnd-kit-accessibility-BHxJPORy.js";import"./vendor-dnd-kit-sortable-CsEagZ81.js";import"./vendor-cmdk-DgLInKvT.js";import"./vendor-radix-ui-react-dialog-B94Bt2qq.js";import"./vendor-radix-ui-primitive-Dc_FVRD7.js";import"./vendor-radix-ui-react-compose-refs-DcAh5WdT.js";import"./vendor-radix-ui-react-context-Czxm7Z62.js";import"./vendor-radix-ui-react-id-f5BLKEVw.js";import"./vendor-radix-ui-react-use-layout-effect-D_3IhJdJ.js";import"./vendor-radix-ui-react-use-controllable-state-BFT5YmkA.js";import"./vendor-radix-ui-react-dismissable-layer-D7kXcwgJ.js";import"./vendor-radix-ui-react-primitive-DhVoX9SD.js";import"./vendor-radix-ui-react-slot-BQgQOasS.js";import"./vendor-radix-ui-react-use-callback-ref-BZPnuXAC.js";import"./vendor-radix-ui-react-use-escape-keydown-oph88g-F.js";import"./vendor-radix-ui-react-focus-scope-CiaxW4dD.js";import"./vendor-radix-ui-react-portal-BMJYHWck.js";import"./vendor-radix-ui-react-presence-CNxf-uq4.js";import"./vendor-radix-ui-react-focus-guards-B6qJXYua.js";import"./vendor-react-remove-scroll-DO7dCTnK.js";import"./vendor-tslib-De9GV7Vy.js";import"./vendor-react-remove-scroll-bar-BcFYyj3E.js";import"./vendor-react-style-singleton-q6EMHnwf.js";import"./vendor-get-nonce-C-Z93AgS.js";import"./vendor-use-sidecar-zDC0RhA3.js";import"./vendor-use-callback-ref-D3RC8gqK.js";import"./vendor-aria-hidden-DvXkyWUv.js";import"./vendor-codemirror-language-DUOssd4j.js";import"./vendor-lezer-common-B3-cUCR_.js";import"./vendor-lezer-highlight-CDMHUZ74.js";import"./vendor-style-mod-NZ5MEPvj.js";import"./vendor-codemirror-lang-javascript-Bbw3D7r0.js";import"./vendor-lezer-javascript-D7Tj24ot.js";import"./vendor-lezer-lr-bhwg1HMg.js";import"./vendor-codemirror-autocomplete-BjbBRsUA.js";import"./vendor-marijn-find-cluster-break-DXwl3gUT.js";import"./vendor-w3c-keyname-Vcq4gwWv.js";import"./vendor-crelt-C8TCjufn.js";import"./vendor-codemirror-lang-json-ryCw7nab.js";import"./vendor-lezer-json-Iaex0UN-.js";import"./vendor-codemirror-lang-css-VgNqFSH-.js";import"./vendor-lezer-css-C5xB6jxd.js";import"./vendor-codemirror-lang-html-B3Qe3OpS.js";import"./vendor-lezer-html-C0I1p52t.js";import"./vendor-codemirror-lang-markdown-FGQydhTc.js";import"./vendor-lezer-markdown-C6g-d6P3.js";import"./vendor-codemirror-language-data-Dzt9rWZZ.js";import"./vendor-codemirror-lang-python-N414WYK-.js";import"./vendor-lezer-python-CvuFxeZl.js";import"./vendor-codemirror-commands-ARAOgp1x.js";import"./vendor-tanstack-react-virtual-g05Cx3z9.js";import"./vendor-tanstack-virtual-core-Dubg10g5.js";import"./vendor-framer-motion-CRSgBxjL.js";import"./vendor-motion-dom-DJLgZh4Q.js";import"./vendor-motion-utils-BGh8QBgx.js";import"./vendor-sonner-DFyL3AvE.js";import"./vendor-tailwind-merge-CPcsbTWB.js";import"./vendor-fuse.js-Dw8P0qyA.js";import"./vendor-codemirror-search-8kyQdB3f.js";import"./vendor-replit-codemirror-vim-B0Ecqnlh.js";import"./web-components-DGvnI0zx.js";import"./computeVirtualFileMetrics-DQE7R9IY.js";import"./vendor-shiki-Bbf2GEcE.js";import"./vendor-shikijs-core-CGM_jqPK.js";import"./vendor-shikijs-types-CPSbSeK6.js";import"./vendor-shikijs-vscode-textmate-BgLrS_2D.js";import"./vendor-hast-util-to-html-BKBhbTDb.js";import"./vendor-html-void-elements-CkdplsNl.js";import"./vendor-property-information-rJCbAzvX.js";import"./vendor-zwitch-C2o2j-tx.js";import"./vendor-stringify-entities-CsH1VEn9.js";import"./vendor-character-entities-legacy-BpoLgcEt.js";import"./vendor-character-entities-html4-D7taRCQ7.js";import"./vendor-ccount-c2V3InAJ.js";import"./vendor-comma-separated-tokens-D8TqSuIK.js";import"./vendor-space-separated-tokens-DD3iYX1K.js";import"./vendor-hast-util-whitespace-D4Wp6AEg.js";import"./vendor-shikijs-engine-oniguruma-DPWuIF1G.js";import"./themeResolver-BmJyTmjJ.js";import"./vendor-pierre-theming-C6Z4M5_u.js";import"./vendor-shikijs-engine-javascript-Cme4830A.js";import"./vendor-oniguruma-to-es-DLBnFDCE.js";import"./vendor-oniguruma-parser-C0D4_9rT.js";import"./vendor-regex-BBWcyTkg.js";import"./vendor-regex-utilities-2BQyy0xI.js";import"./vendor-regex-recursion-JU4mF-dD.js";import"./vendor-shikijs-transformers-CZWsLLKm.js";import"./Virtualizer-X_7XPoTH.js";import"./isFilePlainText-JbqDfa3n.js";import"./registerCustomTheme-BBXUCRnG.js";import"./vendor-react-drawio-Ct3Q0DsD.js";const Aa=(d,e)=>{if(!e)return null;const r=Number.parseInt(d.trim(),10);return!Number.isFinite(r)||r<1?null:Math.min(r,e.state.doc.lines)},Ai=(d,e)=>{const r=d.state.doc.lineAt(e.main.head);return{lineNumber:r.number,character:e.main.head-r.from+1,selection:e}},Ii=(d,e,r)=>{const m=d.state.doc.line(e),x=Math.max(1,Math.min(r,m.length+1)),v=m.from+x-1;d.dispatch({selection:Ta.cursor(v),effects:Tt.scrollIntoView(v,{y:"center"})})};function Ia({open:d,onOpenChange:e,view:r,variant:m="overlay"}){const{t:x}=Rs(),[v,y]=n.useState(""),b=n.useRef(null),p=n.useRef(!1),j=n.useRef(null),h=n.useRef(null),F=n.useMemo(()=>Aa(v,r),[v,r]);n.useEffect(()=>{!d||!r||(p.current=!1,b.current=Ai(r,r.state.selection),y(""))},[d,r]),n.useEffect(()=>{d&&window.requestAnimationFrame(()=>{h.current?.focus(),h.current?.select()})},[d]),n.useEffect(()=>{if(!(!d||!r||!b.current)){if(F===null){const{selection:a}=b.current;r.dispatch({selection:a,effects:Tt.scrollIntoView(a.main.from,{y:"center"})});return}Ii(r,F,b.current.character)}},[F,d,r]);const M=n.useCallback(()=>{if(!r||p.current||!b.current)return;const{selection:a}=b.current;r.dispatch({selection:a,effects:Tt.scrollIntoView(a.main.from,{y:"center"})})},[r]),R=n.useCallback(a=>{a||M(),e(a)},[e,M]),N=n.useCallback(()=>{!r||F===null||!b.current||(p.current=!0,Ii(r,F,b.current.character),e(!1),r.focus())},[F,e,r]);n.useEffect(()=>{if(!d)return;const a=W=>{const _=j.current,L=W.target;!_||!(L instanceof Node)||_.contains(L)||R(!1)},q=W=>{W.key==="Escape"&&(W.preventDefault(),R(!1))};return document.addEventListener("pointerdown",a,!0),document.addEventListener("keydown",q,!0),()=>{document.removeEventListener("pointerdown",a,!0),document.removeEventListener("keydown",q,!0)}},[R,d,m]);const E=n.useMemo(()=>{if(!r)return x("goToLineDialog.helper.editorUnavailable");if(F===null){const a=b.current??Ai(r,r.state.selection);return x("goToLineDialog.helper.currentLineRange",{current:a.lineNumber,max:r.state.doc.lines})}return x("goToLineDialog.helper.goToLine",{line:F})},[F,x,r]);return m==="inline"?d?s.jsxs("div",{ref:j,className:"ml-1 flex h-6 items-center gap-1",children:[s.jsx(Vs,{ref:h,type:"number",min:1,step:1,inputMode:"numeric",value:v,onChange:a=>y(a.target.value),onKeyDown:a=>{a.key==="Enter"&&(a.preventDefault(),N())},placeholder:x("goToLineDialog.field.linePlaceholderShort"),className:"h-6 w-20 rounded-md border-border/70 bg-transparent px-2 typography-meta"}),s.jsx(S,{variant:"outline",size:"xs",onClick:N,disabled:!r||F===null,className:"h-6 px-2",children:x("goToLineDialog.actions.go")})]}):null:s.jsx("div",{ref:j,className:O("absolute left-3 top-3 z-40 w-[min(32rem,calc(100%-1.5rem))] rounded-xl border border-[var(--interactive-border)] bg-[color:color-mix(in_srgb,var(--surface-elevated)_94%,transparent)] p-2.5 shadow-lg backdrop-blur-sm transition-all",d?"pointer-events-auto translate-y-0 opacity-100":"pointer-events-none -translate-y-1 opacity-0"),children:s.jsxs("div",{className:"min-w-0",children:[s.jsx(Vs,{ref:h,type:"number",min:1,step:1,inputMode:"numeric",value:v,onChange:a=>y(a.target.value),onKeyDown:a=>{a.key==="Enter"&&(a.preventDefault(),N())},placeholder:x("goToLineDialog.field.linePlaceholder"),className:"h-8 w-full rounded-md border-border/70 bg-background/60 typography-ui-label"}),s.jsx("div",{className:"mt-2 rounded-md bg-primary/15 px-3 py-1.5 typography-ui-label text-foreground/95",children:E})]})})}function Oa(d){return!(!d.autoSaveEnabled||!d.isDirty||!d.canWrite||d.isSaving||d.fileLoading||d.isNonEditableBinary||!d.selectedFilePath||d.loadedFilePath!==d.selectedFilePath)}function Ba(d){return d.selectedFilePath?d.isDirty?!(d.fileLoading||d.loadedFilePath!==d.selectedFilePath||d.isNonEditableBinary||d.draftContent===""&&d.fileContent!==""&&d.loadedFilePath!==d.selectedFilePath):!0:!1}const $a=d=>{const e=z(d);if(!e)return"";if(e==="/"||/^[A-Za-z]:\/$/.test(e))return e;const r=e.lastIndexOf("/");if(r<0)return e;if(r===0)return"/";const m=e.slice(0,r);return/^[A-Za-z]:$/.test(m)?`${m}/`:m},Wa=d=>{const e=Kt.c(8),{label:r,iconDataUrl:m}=d,[x,v]=n.useState(!1);let y;e[0]!==r?(y=r.trim().slice(0,1).toUpperCase()||"?",e[0]=r,e[1]=y):y=e[1];const b=y;if(m&&!x){let h;e[2]===Symbol.for("react.memo_cache_sentinel")?(h=()=>v(!0),e[2]=h):h=e[2];let F;return e[3]!==m?(F=s.jsx("img",{src:m,alt:"",className:"size-4 rounded-sm",onError:h}),e[3]=m,e[4]=F):F=e[4],F}let p;e[5]===Symbol.for("react.memo_cache_sentinel")?(p=O("size-4 rounded-sm flex items-center justify-center","bg-[var(--surface-muted)] text-[9px] font-medium text-muted-foreground"),e[5]=p):p=e[5];let j;return e[6]!==b?(j=s.jsx("span",{className:p,children:b}),e[6]=b,e[7]=j):j=e[7],j},Ua=d=>d.slice().sort((e,r)=>e.type!==r.type?e.type==="directory"?-1:1:e.name.localeCompare(r.name)),z=d=>{if(!d)return"";const e=d.replace(/\\/g,"/"),r=e.startsWith("//");let m=e.replace(/\/+/g,"/");r&&!m.startsWith("//")&&(m=`/${m}`);const x=m==="/",v=/^[A-Za-z]:\/$/.test(m);return!x&&!v&&(m=m.replace(/\/+$/,"")),m},Ga=d=>d.startsWith("/")||d.startsWith("//")||/^[A-Za-z]:\//.test(d),Gt=d=>/^[A-Za-z]:\//.test(d)?d.toLowerCase():d,ns=(d,e)=>{const r=z(e),m=z(d);if(!r||!m)return!1;const x=Gt(r),v=Gt(m);return v===x||v.startsWith(`${x}/`)},Oi=(d,e)=>{const r=z(e),m=z(d);if(!ns(m,r))return[];const v=m.slice(r.length).replace(/^\//,"").split("/"),y=[];let b=r;for(let p=0;p<v.length-1;p++)b=b?`${b}/${v[p]}`:v[p],y.push(b);return y},Ts=(d,e)=>{if(!e)return"";const r=z(e);if(!d||!ns(r,d))return r;const m=r.slice(d.length);return m.startsWith("/")?m.slice(1):m},Ka=new Set(["node_modules"]),Ha=d=>{const e=Kt.c(3),{status:r}=d;let m;e[0]===Symbol.for("react.memo_cache_sentinel")?(m={open:"var(--status-info)",modified:"var(--status-warning)","git-modified":"var(--status-warning)","git-added":"var(--status-success)","git-deleted":"var(--status-error)"},e[0]=m):m=e[0];const x=m[r];let v;return e[1]!==x?(v=s.jsx("span",{className:"size-2 rounded-full",style:{backgroundColor:x}}),e[1]=x,e[2]=v):v=e[2],v},Bi=d=>{const e=Kt.c(11),{name:r}=d,m=n.useRef(null),x=n.useRef(null),[v,y]=n.useState(!1);let b;e[0]===Symbol.for("react.memo_cache_sentinel")?(b=()=>{const M=m.current,R=x.current;if(!M||!R)return;const N=()=>{y(R.scrollWidth>M.clientWidth+1)};N();const E=new ResizeObserver(N);return E.observe(M),E.observe(R),()=>{E.disconnect()}},e[0]=b):b=e[0];let p;e[1]!==r?(p=[r],e[1]=r,e[2]=p):p=e[2],n.useLayoutEffect(b,p);let j;e[3]!==r?(j=s.jsx("span",{ref:x,"aria-hidden":"true",className:"invisible absolute whitespace-nowrap",children:r}),e[3]=r,e[4]=j):j=e[4];let h;e[5]!==r||e[6]!==v?(h=v?s.jsxs("span",{className:"open-file-name-marquee-track",children:[s.jsx("span",{className:"open-file-name-marquee-item",children:r}),s.jsx("span",{className:"open-file-name-marquee-item","aria-hidden":"true",children:r})]}):s.jsx("span",{className:"block min-w-0 truncate",children:r}),e[5]=r,e[6]=v,e[7]=h):h=e[7];let F;return e[8]!==j||e[9]!==h?(F=s.jsxs("span",{ref:m,className:"relative block min-w-0 flex-1 overflow-hidden whitespace-nowrap",children:[j,h]}),e[8]=j,e[9]=h,e[10]=F):F=e[10],F},qa=d=>Ka.has(d),_a=d=>{const e=z(d);return e==="node_modules"||e.endsWith("/node_modules")||e.includes("/node_modules/")},Ja=d=>{const r=(d instanceof Error?d.message:String(d??"")).toLowerCase();return r.includes("is a directory")||r.includes("eisdir")},$i=d=>{const r=(d instanceof Error?d.message:String(d??"")).toLowerCase();return r.includes("file not found")||r.includes("enoent")||r.includes("no such file")||r.includes("does not exist")},is=2e5,Xa=d=>{let e=0,r=0;for(let m=0;m<d.length;m+=1)d.charCodeAt(m)===10&&(m>0&&d.charCodeAt(m-1)===13?e+=1:r+=1);return e>r?`\r
2
- `:`
3
- `},Ji=d=>d.replace(/\r\n/g,`
4
- `).replace(/\r/g,`
5
- `),Qa=(d,e)=>{const r=Ji(d);return e===`\r
6
- `?r.replace(/\n/g,`\r
7
- `):r},Xi=(d,e)=>s.jsx(ks,{filePath:d,extension:e}),Wi=d=>{if(!d)return!1;const e=d.toLowerCase().split(".").pop();return e==="md"||e==="markdown"},Ya=d=>{if(!d)return!1;const e=d.toLowerCase().split(".").pop();return e==="json"||e==="jsonc"||e==="json5"||e==="geojson"},dr=d=>{if(!d)return!1;const e=d.toLowerCase().split(".").pop();return e==="html"||e==="htm"},Za=d=>{const e=Kt.c(76),{node:r,root:m,isExpanded:x,isActive:v,isMobile:y,isBrowserClient:b,alwaysShowActions:p,status:j,badge:h,permissions:F,downloadFile:M,contextMenuPath:R,setContextMenuPath:N,rightClickMenuPath:E,setRightClickMenuPath:a,onSelect:q,onToggle:W,onRevealPath:_,onOpenDialog:L}=d,{t:T}=Rs(),V=r.type==="directory",{canRename:ce,canCreateFile:ee,canCreateFolder:te,canDelete:A,canReveal:de}=F,Ae=!V&&!!M,U=de&&!b,J=ce||ee||te||A||Ae||U;let se;e[0]!==J||e[1]!==r.path||e[2]!==a?(se=me=>{J&&(me?.preventDefault(),a(r.path))},e[0]=J,e[1]=r.path,e[2]=a,e[3]=se):se=e[3];const ge=se;let re;e[4]!==V||e[5]!==r||e[6]!==q||e[7]!==W?(re=()=>{V?W(r.path):q(r)},e[4]=V,e[5]=r,e[6]=q,e[7]=W,e[8]=re):re=e[8];const xe=re;let ue;e[9]!==r.path||e[10]!==N||e[11]!==a?(ue=me=>{me.stopPropagation(),a(null),N(r.path)},e[9]=r.path,e[10]=N,e[11]=a,e[12]=ue):ue=e[12];const it=ue;let Vt;e[13]!==ee||e[14]!==te||e[15]!==A||e[16]!==ce||e[17]!==U||e[18]!==M||e[19]!==b||e[20]!==V||e[21]!==r||e[22]!==L||e[23]!==_||e[24]!==m||e[25]!==T?(Vt=me=>{const{Item:we,Separator:bt}=me;return s.jsxs(s.Fragment,{children:[ce&&s.jsxs(we,{onClick:C=>{C.stopPropagation(),L("rename",r)},children:[s.jsx(g,{name:"edit",className:"mr-2 size-4"})," ",T("sidebarFilesTree.menu.rename")]}),s.jsxs(we,{onClick:C=>{C.stopPropagation(),Ds(r.path).then(be=>{if(be.ok){I.success(T("sidebarFilesTree.toast.pathCopied"));return}I.error(T("sidebarFilesTree.toast.copyFailed"))})},children:[s.jsx(g,{name:"file-copy",className:"mr-2 size-4"})," ",T("sidebarFilesTree.menu.copyPath")]}),s.jsxs(we,{onClick:C=>{C.stopPropagation();const be=Ts(m,r.path)||r.path;Ds(be).then(Xe=>{if(Xe.ok){I.success(T("filesView.toast.relativePathCopied"));return}I.error(T("sidebarFilesTree.toast.copyFailed"))})},children:[s.jsx(g,{name:"file-copy-2",className:"mr-2 size-4"})," ",T("filesView.tree.menu.copyRelativePath")]}),!V&&M&&s.jsxs(we,{onClick:C=>{C.stopPropagation(),M(r.path).catch(be=>{console.error("Download failed:",be),I.error(T("sidebarFilesTree.toast.operationFailed"))})},children:[s.jsx(g,{name:"download",className:"mr-2 size-4"})," ",T(b?"sidebarFilesTree.menu.download":"sidebarFilesTree.menu.save")]}),U&&s.jsxs(we,{onClick:C=>{C.stopPropagation(),_(r.path)},children:[s.jsx(g,{name:"folder-received",className:"mr-2 size-4"})," ",T(ya())]}),V&&(ee||te)&&s.jsxs(s.Fragment,{children:[s.jsx(bt,{}),ee&&s.jsxs(we,{onClick:C=>{C.stopPropagation(),L("createFile",r)},children:[s.jsx(g,{name:"file-add",className:"mr-2 size-4"})," ",T("sidebarFilesTree.menu.newFile")]}),te&&s.jsxs(we,{onClick:C=>{C.stopPropagation(),L("createFolder",r)},children:[s.jsx(g,{name:"folder-add",className:"mr-2 size-4"})," ",T("sidebarFilesTree.menu.newFolder")]})]}),A&&s.jsxs(s.Fragment,{children:[s.jsx(bt,{}),s.jsxs(we,{onClick:C=>{C.stopPropagation(),L("delete",r)},className:"text-destructive focus:text-destructive",children:[s.jsx(g,{name:"delete-bin",className:"mr-2 size-4"})," ",T("sidebarFilesTree.menu.delete")]})]})]})},e[13]=ee,e[14]=te,e[15]=A,e[16]=ce,e[17]=U,e[18]=M,e[19]=b,e[20]=V,e[21]=r,e[22]=L,e[23]=_,e[24]=m,e[25]=T,e[26]=Vt):Vt=e[26];const Je=Vt,G=E===r.path;let Ce;e[27]!==r.path||e[28]!==a?(Ce=me=>a(me?r.path:null),e[27]=r.path,e[28]=a,e[29]=Ce):Ce=e[29];const vt=y?void 0:ge;let Ie;e[30]!==vt?(Ie=s.jsx("div",{className:"group relative flex items-center",onContextMenu:vt}),e[30]=vt,e[31]=Ie):Ie=e[31];const Oe=y?void 0:ge,wt=v?"bg-interactive-selection/70":"hover:bg-interactive-hover/40";let ve;e[32]!==wt?(ve=O("flex w-full items-center gap-1.5 rounded-md px-2 py-1 text-left text-foreground transition-colors pr-8 select-none",wt),e[32]=wt,e[33]=ve):ve=e[33];let Be;e[34]!==V||e[35]!==x||e[36]!==r.extension||e[37]!==r.path?(Be=V?x?s.jsx(g,{name:"folder-open",className:"size-4 flex-shrink-0 text-muted-foreground"}):s.jsx(g,{name:"folder-3",className:"size-4 flex-shrink-0 text-muted-foreground"}):Xi(r.path,r.extension),e[34]=V,e[35]=x,e[36]=r.extension,e[37]=r.path,e[38]=Be):Be=e[38];let fe;e[39]!==r.name||e[40]!==r.path?(fe=s.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta",title:r.path,children:r.name}),e[39]=r.name,e[40]=r.path,e[41]=fe):fe=e[41];let ke;e[42]!==V||e[43]!==j?(ke=!V&&j&&s.jsx(Ha,{status:j}),e[42]=V,e[43]=j,e[44]=ke):ke=e[44];let nt;e[45]!==h||e[46]!==V?(nt=V&&h&&s.jsxs("span",{className:"text-xs flex items-center gap-1 ml-auto mr-1",children:[h.modified>0&&s.jsxs("span",{className:"text-[var(--status-warning)]",children:["M",h.modified]}),h.added>0&&s.jsxs("span",{className:"text-[var(--status-success)]",children:["+",h.added]})]}),e[45]=h,e[46]=V,e[47]=nt):nt=e[47];let at;e[48]!==xe||e[49]!==ve||e[50]!==Be||e[51]!==fe||e[52]!==ke||e[53]!==nt||e[54]!==Oe?(at=s.jsxs("button",{type:"button",onClick:xe,onContextMenu:Oe,className:ve,children:[Be,fe,ke,nt]}),e[48]=xe,e[49]=ve,e[50]=Be,e[51]=fe,e[52]=ke,e[53]=nt,e[54]=Oe,e[55]=at):at=e[55];let $e;e[56]!==p||e[57]!==R||e[58]!==it||e[59]!==J||e[60]!==y||e[61]!==r.path||e[62]!==Je||e[63]!==N?($e=J&&s.jsx("div",{className:O("absolute right-1 top-1/2 -translate-y-1/2",p?"opacity-100":"opacity-0 focus-within:opacity-100 group-hover:opacity-100"),children:s.jsxs(fr,{open:R===r.path,onOpenChange:me=>N(me?r.path:null),children:[s.jsx(mr,{asChild:!0,children:s.jsx(S,{variant:"ghost",size:"icon",className:"size-6",onClick:it,children:s.jsx(g,{name:"more-2-fill",className:"size-4"})})}),s.jsx(pr,{align:"end",side:"bottom",onCloseAutoFocus:()=>N(null),children:Je({Item:Ss,Separator:ba})})]})}),e[56]=p,e[57]=R,e[58]=it,e[59]=J,e[60]=y,e[61]=r.path,e[62]=Je,e[63]=N,e[64]=$e):$e=e[64];let We;e[65]!==at||e[66]!==$e||e[67]!==Ie?(We=s.jsxs(Ca,{render:Ie,children:[at,$e]}),e[65]=at,e[66]=$e,e[67]=Ie,e[68]=We):We=e[68];let Ue;e[69]!==Je?(Ue=s.jsx(ja,{className:"min-w-[180px]",children:Je({Item:Na,Separator:Fa})}),e[69]=Je,e[70]=Ue):Ue=e[70];let ot;return e[71]!==We||e[72]!==Ue||e[73]!==G||e[74]!==Ce?(ot=s.jsxs(ka,{open:G,onOpenChange:Ce,children:[We,Ue]}),e[71]=We,e[72]=Ue,e[73]=G,e[74]=Ce,e[75]=ot):ot=e[75],ot},eo=d=>{const e=Kt.c(83),{activeDialog:r,dialogData:m,dialogInputValue:x,onDialogInputChange:v,isDialogSubmitting:y,onDialogSubmit:b,onClose:p,inputRef:j}=d,{t:h}=Rs(),F=!!r;let M;e[0]!==p?(M=ue=>!ue&&p(),e[0]=p,e[1]=M):M=e[1];let R;e[2]!==r||e[3]!==h?(R=r==="createFile"&&h("filesView.dialog.createFile.title"),e[2]=r,e[3]=h,e[4]=R):R=e[4];let N;e[5]!==r||e[6]!==h?(N=r==="createFolder"&&h("filesView.dialog.createFolder.title"),e[5]=r,e[6]=h,e[7]=N):N=e[7];let E;e[8]!==r||e[9]!==h?(E=r==="rename"&&h("filesView.dialog.rename.title"),e[8]=r,e[9]=h,e[10]=E):E=e[10];let a;e[11]!==r||e[12]!==h?(a=r==="delete"&&h("filesView.dialog.delete.title"),e[11]=r,e[12]=h,e[13]=a):a=e[13];let q;e[14]!==R||e[15]!==N||e[16]!==E||e[17]!==a?(q=s.jsxs(Hi,{children:[R,N,E,a]}),e[14]=R,e[15]=N,e[16]=E,e[17]=a,e[18]=q):q=e[18];let W;e[19]!==r||e[20]!==m?.path||e[21]!==h?(W=r==="createFile"&&h("filesView.dialog.createFile.description",{path:m?.path??h("filesView.dialog.rootFallback")}),e[19]=r,e[20]=m?.path,e[21]=h,e[22]=W):W=e[22];let _;e[23]!==r||e[24]!==m?.path||e[25]!==h?(_=r==="createFolder"&&h("filesView.dialog.createFolder.description",{path:m?.path??h("filesView.dialog.rootFallback")}),e[23]=r,e[24]=m?.path,e[25]=h,e[26]=_):_=e[26];let L;e[27]!==r||e[28]!==m?.name||e[29]!==h?(L=r==="rename"&&h("filesView.dialog.rename.description",{name:m?.name??""}),e[27]=r,e[28]=m?.name,e[29]=h,e[30]=L):L=e[30];let T;e[31]!==r||e[32]!==m?.name||e[33]!==h?(T=r==="delete"&&h("filesView.dialog.delete.description",{name:m?.name??""}),e[31]=r,e[32]=m?.name,e[33]=h,e[34]=T):T=e[34];let V;e[35]!==L||e[36]!==T||e[37]!==W||e[38]!==_?(V=s.jsxs(qi,{children:[W,_,L,T]}),e[35]=L,e[36]=T,e[37]=W,e[38]=_,e[39]=V):V=e[39];let ce;e[40]!==V||e[41]!==q?(ce=s.jsxs(Ki,{children:[q,V]}),e[40]=V,e[41]=q,e[42]=ce):ce=e[42];let ee;e[43]!==r||e[44]!==x||e[45]!==j||e[46]!==v||e[47]!==b||e[48]!==h?(ee=r!=="delete"&&s.jsx("div",{className:"py-4",children:s.jsx(Vs,{value:x,onChange:ue=>v(ue.target.value),placeholder:h(r==="rename"?"filesView.dialog.rename.placeholder":"filesView.dialog.namePlaceholder"),onKeyDown:ue=>{ue.key==="Enter"&&b()},ref:j})}),e[43]=r,e[44]=x,e[45]=j,e[46]=v,e[47]=b,e[48]=h,e[49]=ee):ee=e[49];let te;e[50]!==h?(te=h("filesView.dialog.cancel"),e[50]=h,e[51]=te):te=e[51];let A;e[52]!==y||e[53]!==p||e[54]!==te?(A=s.jsx(S,{variant:"outline",onClick:p,disabled:y,children:te}),e[52]=y,e[53]=p,e[54]=te,e[55]=A):A=e[55];const de=r==="delete"?"destructive":"default";let Ae;e[56]!==b?(Ae=()=>{b()},e[56]=b,e[57]=Ae):Ae=e[57];let U;e[58]!==r||e[59]!==x||e[60]!==y?(U=y||r!=="delete"&&!x.trim(),e[58]=r,e[59]=x,e[60]=y,e[61]=U):U=e[61];let J;e[62]!==r||e[63]!==y||e[64]!==h?(J=y?s.jsx(g,{name:"loader-4",className:"size-4 animate-spin"}):h(r==="delete"?"filesView.dialog.delete.confirm":"filesView.dialog.confirm"),e[62]=r,e[63]=y,e[64]=h,e[65]=J):J=e[65];let se;e[66]!==de||e[67]!==Ae||e[68]!==U||e[69]!==J?(se=s.jsx(S,{variant:de,onClick:Ae,disabled:U,children:J}),e[66]=de,e[67]=Ae,e[68]=U,e[69]=J,e[70]=se):se=e[70];let ge;e[71]!==A||e[72]!==se?(ge=s.jsxs(_i,{children:[A,se]}),e[71]=A,e[72]=se,e[73]=ge):ge=e[73];let re;e[74]!==j||e[75]!==ce||e[76]!==ee||e[77]!==ge?(re=s.jsxs(Gi,{initialFocus:j,children:[ce,ee,ge]}),e[74]=j,e[75]=ce,e[76]=ee,e[77]=ge,e[78]=re):re=e[78];let xe;return e[79]!==F||e[80]!==M||e[81]!==re?(xe=s.jsx(Ui,{open:F,onOpenChange:M,children:re}),e[79]=F,e[80]=M,e[81]=re,e[82]=xe):xe=e[82],xe},ur=(d,e,r)=>{const m=Kt.c(8),[x,v]=n.useState(""),[y,b]=n.useState(0);let p,j;m[0]!==d||m[1]!==r||m[2]!==e?(p=()=>{if(!d){v("");return}let F=!1;v("");const M=ta(),R=sa(M);ra(M).then(E=>{F||!E||(v(d),e(null))}).catch(E=>{F||(e(E instanceof Error?E.message:r),v(d))});const N=ia(()=>{F||(v(d),b(to),e(null))});return()=>{F=!0,R(),N()}},j=[d,e,r],m[0]=d,m[1]=r,m[2]=e,m[3]=p,m[4]=j):(p=m[3],j=m[4]),n.useEffect(p,j);let h;return m[5]!==y||m[6]!==x?(h={readyKey:x,nonce:y},m[5]=y,m[6]=x,m[7]=h):h=m[7],h},vc=({mode:d="full"})=>{const{t:e}=Rs(),{files:r,runtime:m}=na(),{currentTheme:x,availableThemes:v,lightThemeId:y,darkThemeId:b}=aa(),{isMobile:p,isTablet:j,screenWidth:h}=oa(),F=Jn(m.platform),M=p||j,R=Xn(),N=Qn(),E=la()??"",a=z(E.trim()),q=d!=="editor-only",W=d==="editor-only"&&!p,_=Yn(t=>t.searchFiles),L=ca(E),[T,V]=n.useState(""),ce=da(T,200),ee=n.useRef(null),[te,A]=n.useState(!1),[de,Ae]=n.useState(!0),[U,J]=n.useState(!1),[se,ge]=n.useState(!1),[re,xe]=n.useState(!1),ue=n.useRef(null),it=n.useRef(0),Vt=n.useCallback(t=>{it.current=Math.max(0,it.current+(t?1:-1))},[]),Je=n.useCallback(t=>t instanceof Element?t.closest('[data-slot="dropdown-menu-content"], [data-slot="dropdown-menu-item"]')!==null:!1,[]);n.useEffect(()=>{if(!re)return;const t=i=>{it.current>0||Je(i.target)||ue.current&&!ue.current.contains(i.target)&&xe(!1)};return document.addEventListener("mousedown",t),()=>document.removeEventListener("mousedown",t)},[Je,re]);const[G,Ce]=n.useState("edit"),[vt,Ie]=n.useState("edit"),[Oe,wt]=n.useState("tree"),[ve,Be]=n.useState("edit"),[fe,ke]=n.useState("preview"),[nt,at]=n.useState(0),$e=n.useRef({}),We=n.useRef({}),Ue=n.useRef({}),ot=n.useRef({}),me=n.useMemo(()=>v.find(t=>t.metadata.id===y)??Ni(!1),[v,y]),we=n.useMemo(()=>v.find(t=>t.metadata.id===b)??Ni(!0),[v,b]);n.useEffect(()=>{Li(me),Li(we)},[me,we]);const bt=n.useMemo(()=>[],[]),C=Le(t=>a?t.byRoot[a]?.openPaths??bt:bt),be=Le(t=>a?t.byRoot[a]?.selectedPath??null:null),Xe=Le(t=>a?t.byRoot[a]?.expandedPaths??bt:bt),Dt=Le(t=>t.removeOpenPath),lt=Le(t=>t.removeOpenPathsByPrefix),hr=Le(t=>t.removeExpandedPathsByPrefix),ie=Le(t=>t.setSelectedPath),gr=Le(t=>t.toggleExpandedPath),as=Le(t=>t.expandPaths),Rt=n.useCallback(t=>{const i=z(t),l=i.split("/"),o=l[l.length-1]||i,u=o.includes(".")?o.split(".").pop()?.toLowerCase():void 0;return{name:o,path:i,type:"file",extension:u}},[]),Et=n.useMemo(()=>C.map(Rt),[C,Rt]),Es=n.useMemo(()=>{if(be){const t=Gt(be);if(C.some(i=>Gt(i)===t))return be}return C[0]??null},[C,be]),c=n.useMemo(()=>Es?Rt(Es):null,[Es,Rt]),Ge=c?.path??"";n.useEffect(()=>{if(!a||!be)return;const t=Gt(be);C.some(l=>Gt(l)===t)||ie(a,C[0]??null)},[C,a,be,ie]);const os=!!(a&&Ge&&!ns(Ge,a)),xr=os?Si(Ge):void 0,X=n.useMemo(()=>({allowOutsideWorkspace:d==="editor-only"&&os,outsideFileGrant:xr,directory:a||void 0}),[d,os,xr,a]),Ps=n.useRef(null),[vr,Qi]=n.useState({left:!1,right:!1}),wr=n.useCallback(()=>{const t=Ps.current;t&&Qi({left:t.scrollLeft>2,right:t.scrollLeft+t.clientWidth<t.scrollWidth-2})},[]),br=n.useRef(wr);br.current=wr,n.useEffect(()=>{const t=Ps.current;if(!t)return;const i=()=>br.current();i(),t.addEventListener("scroll",i,{passive:!0});const l=new ResizeObserver(i);return l.observe(t),()=>{t.removeEventListener("scroll",i),l.disconnect()}},[Et.length]);const[yr,Ms]=n.useState({}),[ls,Ht]=n.useState({}),Se=n.useRef(new Set),Te=n.useRef(new Set),Qe=n.useRef(new Map),jr=n.useRef(0),[Fr,cs]=n.useState([]),[Yi,ds]=n.useState(!1),[k,K]=n.useState(""),{isPlaying:us,play:Zi,stop:en}=ua(),[Ee,Ye]=n.useState(!1),[Ze,Q]=n.useState(null),[tn,Pe]=n.useState(""),ye=n.useRef(""),[je,H]=n.useState(null),[B,Y]=n.useState(""),[Pt,zs]=n.useState(!1),[Nr,sn]=n.useState(`
8
- `),rn=n.useRef(null),Ke=n.useRef(null),Fe=n.useRef(null),ct=n.useRef(""),qt=n.useRef(""),et=n.useRef(null),Cr=n.useRef(null),tt=n.useRef(null),fs=n.useRef(0),_t=n.useRef(null),[nn,Mt]=n.useState("idle"),[an,ms]=n.useState(!1),[Jt,kr]=n.useState(!1),ne=he(t=>t.autoSaveEnabled),on=he(t=>t.setAutoSaveEnabled),[Ls,zt]=n.useState(!1),Lt=n.useRef(null),Xt=n.useRef(null),Qt=n.useRef(null),yt=n.useRef(!1),Yt=n.useRef(null),Zt=n.useRef(null),Me=n.useRef(null),ln=n.useRef(null),[cn,As]=n.useState(0),At=n.useRef(null),jt=n.useRef({key:"",attempts:0});n.useEffect(()=>()=>{At.current!==null&&typeof window<"u"&&(window.cancelAnimationFrame(At.current),At.current=null)},[]);const[Ft,Is]=n.useState(null),[Nt,dn]=n.useState(null),[dt,Sr]=n.useState(""),[un,Os]=n.useState(!1),[fn,mn]=n.useState(null),[pn,hn]=n.useState(null),[gn,Tr]=n.useState(!1),[xn,Vr]=n.useState(!1),[vn,Bs]=n.useState(!1),Dr=!!r.writeFile,Rr=!!r.createDirectory,Er=!!r.rename,Pr=!!r.delete,Mr=!!r.revealPath,wn=Cs(t=>t.availableApps),bn=Cs(t=>t.isCacheStale),zr=Cs(t=>t.initialize),yn=Cs(t=>t.loadInstalledApps);n.useEffect(()=>{zr()},[zr]);const jn=n.useCallback(t=>{r.revealPath&&r.revealPath(t).catch(()=>{I.error(e("sidebarFilesTree.toast.revealFailed"))})},[r,e]),Fn=n.useCallback(async t=>{if(!c?.path||await Zn(c.path,t.id,t.appName)||await Ci(c.path,t.appName))return;const o=$a(c.path)||a;o&&await Ci(o,t.appName)||I.error(e("filesView.toast.openInAppFailed",{app:t.appName}))},[a,c?.path,e]),$s=n.useCallback((t,i)=>{Is(t),dn(i),Sr(t==="rename"&&i.name||""),Os(!1)},[]),[P,ze]=n.useState(null),It=n.useRef(!1),ut=n.useRef(null),[Lr,Ot]=n.useState(!1),He=he(t=>t.setMainTabGuard),qe=he(t=>t.pendingFileNavigation),ps=he(t=>t.setPendingFileNavigation),Ws=he(t=>t.pendingFileFocusPath),Us=he(t=>t.setPendingFileFocusPath),Ar=he(t=>t.shortcutOverrides),Ir=he(t=>t.fileEditorKeymap),es=Ti(t=>t.settingsDefaultFileViewerPreview),Nn=Ti(t=>t.showMessageTTSButtons),Or=he(t=>t.expandedEditorToolbar);n.useEffect(()=>{const t=()=>{It.current=!1,ut.current=null,Ot(!1)};return document.addEventListener("mouseup",t),()=>document.removeEventListener("mouseup",t)},[]),n.useEffect(()=>()=>{Yt.current!==null&&window.clearTimeout(Yt.current),Zt.current!==null&&window.clearTimeout(Zt.current)},[]);const Cn=n.useCallback((t,i)=>{const l=t.split(`
9
- `),o=Math.max(1,i.start),u=Math.min(l.length,i.end);return o>u?"":l.slice(o-1,u).join(`
10
- `)},[]),kn=Pa({source:"file",fileLabel:c?.path??null,language:c?.path&&ir(c.path)||"text",getCodeForRange:t=>Cn(k,Ma(t)),toStoreRange:t=>({startLine:t.start,endLine:t.end}),fromDraftRange:t=>({start:t.startLine,end:t.endLine})}),{drafts:Br,commentText:hs,setCommentText:$r,editingDraftId:gs,setSelection:Wr,saveComment:Ur,cancel:ts,reset:Gr,startEdit:Kr,deleteDraft:Hr}=kn;n.useEffect(()=>{ze(null),Gr(),He(null),Y(""),zs(!1)},[c?.path,Gr,He]),n.useEffect(()=>{Wr(P)},[P,Wr]),n.useEffect(()=>{if(!P&&!gs)return;const t=l=>{const o=l.target;o.closest('[data-comment-input="true"]')||o.closest('[data-comment-card="true"]')||o.closest(".cm-gutterElement")||o.closest("[data-sonner-toast]")||o.closest("[data-sonner-toaster]")||hs.trim()||(ze(null),ts())},i=setTimeout(()=>{document.addEventListener("click",t)},100);return()=>{clearTimeout(i),document.removeEventListener("click",t)}},[ts,hs,gs,P]);const qr=n.useCallback((t,i)=>{const l=i??P??void 0;i&&ze(i),Ur(t,l),ze(null)},[P,Ur]),_r=n.useCallback((t,i)=>{const l=[];for(const o of i){if(!(o&&typeof o.name=="string"&&o.name.length>0)||!R&&o.name.startsWith(".")||!N&&qa(o.name))continue;const u=o.name,f=z(o.path||""),w=f?Ga(f)?f:z(`${t}/${f}`):z(`${t}/${u}`),D=o.isDirectory?"directory":"file",$=D==="file"&&u.includes(".")?u.split(".").pop()?.toLowerCase():void 0;l.push({name:u,path:w,type:D,extension:$})}return Ua(l)},[N,R]),Ve=n.useCallback(async t=>{const i=z(t.trim());if(!i||Se.current.has(i)||Te.current.has(i))return;Te.current=new Set(Te.current),Te.current.add(i);const l=jr.current+1;jr.current=l,Qe.current=new Map(Qe.current),Qe.current.set(i,l);const o=()=>Qe.current.get(i)===l;await(r.listDirectory?r.listDirectory(i).then(f=>f.entries.map(w=>({name:w.name,path:w.path,isDirectory:w.isDirectory}))):ea.listLocalDirectory(i).then(f=>f.map(w=>({name:w.name,path:w.path,isDirectory:w.isDirectory})))).then(f=>{if(!o())return;const w=_r(i,f);Se.current=new Set(Se.current),Se.current.add(i),Ht(D=>{if(!D[i])return D;const $={...D};return delete $[i],$}),Ms(D=>({...D,[i]:w}))}).catch(f=>{if(!o())return;const w=f instanceof Error?f.message:String(f??"");if(w==="Directory not found"&&a&&i!==a){hr(a,i),Ht(D=>{if(!D[i])return D;const $={...D};return delete $[i],$});return}console.error("Failed to load files directory:",f),Ht(D=>({...D,[i]:w}))}).finally(()=>{o()&&(Qe.current=new Map(Qe.current),Qe.current.delete(i),Te.current=new Set(Te.current),Te.current.delete(i))})},[r,_r,hr,a]),xs=n.useCallback(async()=>{a&&(Se.current=new Set,Te.current=new Set,Qe.current=new Map,Ht({}),Ms(t=>Object.keys(t).length===0?t:{}),await Ve(a))},[Ve,a]),_e=n.useCallback(async t=>{if(!t){await xs();return}const i=z(t);Se.current=new Set(Se.current),Se.current.delete(i),Te.current=new Set(Te.current),Te.current.delete(i),await Ve(i)},[Ve,xs]),Jr=n.useRef(""),Xr=n.useRef("");n.useEffect(()=>{if(!a)return;const t=`${a}|h${R?"1":"0"}|g${N?"1":"0"}`,i=Jr.current!==a,l=Xr.current!==t;!i&&!l||(i&&(Jr.current=a,K(""),Q(null),Pe(""),H(null),A(!1)),l&&(Xr.current=t,Se.current=new Set,Te.current=new Set,Qe.current=new Map,Ht({}),Ms(o=>Object.keys(o).length===0?o:{}),Ve(a)))},[Ve,a,N,R]),n.useEffect(()=>{if(!r.listDirectory)return;const t=()=>{if(!document.hidden&&Xe.length>0)for(const i of Xe)_e(i)};return document.addEventListener("visibilitychange",t),()=>document.removeEventListener("visibilitychange",t)},[Xe,r.listDirectory,_e]),n.useEffect(()=>{if(!r.listDirectory||Xe.length===0)return;const t=setInterval(()=>{if(!document.hidden)for(const i of Xe)_e(i)},8e3);return()=>clearInterval(t)},[Xe,r.listDirectory,_e]);const Sn=n.useCallback(async t=>{if(t?.preventDefault(),!Nt||!Ft)return;Os(!0);const i=()=>{Is(null)},l=u=>{I.error(u)},o=()=>{Os(!1)};if(Ft==="createFile"){if(!dt.trim()){l(e("sidebarFilesTree.toast.filenameRequired")),o();return}if(!r.writeFile){l(e("sidebarFilesTree.toast.writeNotSupported")),o();return}const u=Nt.path,f=u?`${u}/`:"",w=z(`${f}${dt.trim()}`);await r.writeFile(w,"").then(async D=>{D.success&&(I.success(e("sidebarFilesTree.toast.fileCreated")),await _e(u)),i()}).catch(()=>l(e("sidebarFilesTree.toast.operationFailed"))).finally(o);return}if(Ft==="createFolder"){if(!dt.trim()){l(e("sidebarFilesTree.toast.folderNameRequired")),o();return}const u=Nt.path,f=u?`${u}/`:"",w=z(`${f}${dt.trim()}`);await r.createDirectory(w).then(async D=>{D.success&&(I.success(e("sidebarFilesTree.toast.folderCreated")),await _e(u)),i()}).catch(()=>l(e("sidebarFilesTree.toast.operationFailed"))).finally(o);return}if(Ft==="rename"){if(!dt.trim()){l(e("sidebarFilesTree.toast.nameRequired")),o();return}if(!r.rename){l(e("sidebarFilesTree.toast.renameNotSupported")),o();return}const u=Nt.path,f=u.split("/").slice(0,-1).join("/"),w=f?`${f}/`:"",D=z(`${w}${dt.trim()}`);await r.rename(u,D).then(async $=>{$.success&&(I.success(e("sidebarFilesTree.toast.renamedSuccessfully")),await _e(f),a&&lt(a,u),(c?.path===u||c?.path.startsWith(`${u}/`))&&(a&&ie(a,null),K(""),Q(null),Pe(""),H(null),p&&A(!1))),i()}).catch(()=>l(e("sidebarFilesTree.toast.operationFailed"))).finally(o);return}if(Ft==="delete"){if(!r.delete){l(e("sidebarFilesTree.toast.deleteNotSupported")),o();return}const u=Nt.path,f=u.split("/").slice(0,-1).join("/");await r.delete(u).then(async w=>{w.success&&(I.success(e("sidebarFilesTree.toast.deletedSuccessfully")),await _e(f),a&&lt(a,u),(c?.path===u||c?.path.startsWith(`${u}/`))&&(a&&ie(a,null),K(""),Q(null),Pe(""),H(null),p&&A(!1))),i()}).catch(()=>l(e("sidebarFilesTree.toast.operationFailed"))).finally(o);return}o()},[Ft,Nt,dt,r,_e,p,lt,a,c?.path,ie,e]);n.useEffect(()=>{if(!E){cs([]),ds(!1);return}const t=ce.trim();if(!t){cs([]),ds(!1);return}let i=!1;return ds(!0),_(E,t,150,{includeHidden:R,respectGitignore:!N,type:"file"}).then(l=>{if(i)return;const u=l.filter(f=>N||!_a(f.path)).map(f=>({name:f.name,path:z(f.path),type:"file",extension:f.extension,relativePath:f.relativePath}));cs(u)}).catch(()=>{i||cs([])}).finally(()=>{i||ds(!1)}),()=>{i=!0}},[E,ce,_,R,N]);const Qr=n.useCallback(async(t,i)=>{if(r.readFile)return(await r.readFile(t,{...i??{},directory:a||void 0})).content??"";const l=new URLSearchParams({path:t});i?.allowOutsideWorkspace&&l.set("allowOutsideWorkspace","true"),i?.outsideFileGrant&&l.set("outsideFileGrant",i.outsideFileGrant),i?.optional&&l.set("optional","true"),a&&l.set("directory",a);const o=await ki(`/api/fs/read?${l.toString()}`,{cache:i?.optional?"no-store":"default"});if(!o.ok){const u=await o.json().catch(()=>({error:o.statusText}));throw new Error(u.error||e("filesView.error.readFileFailed"))}return o.text()},[r,a,e]),ft=n.useCallback(async(t,i)=>{if(r.statFile){const l=await r.statFile(t,{...i??{},directory:a||void 0});return{path:l.path,size:l.size,mtimeMs:l.mtimeMs}}return null},[r,a]);n.useEffect(()=>{if(!a||!r.statFile||C.length===0)return;let t=!1;const i=[...C];return Promise.all(i.map(async l=>{try{const o=await r.statFile?.(l,{directory:a||void 0});!t&&o&&!o.isFile&&lt(a,l)}catch(o){!t&&$i(o)&&lt(a,l)}})),()=>{t=!0}},[r,C,lt,a]);const Gs=n.useMemo(()=>k.length>is?`${k.slice(0,is)}
11
-
12
- … truncated …`:k,[k]),ae=B!==Gs,Ct=n.useCallback(async()=>{if(!c||!r.writeFile)return I.error(e("filesView.toast.savingNotSupported")),!1;const t=Ns(c.path)||Jt;if(!Ba({selectedFilePath:c.path,loadedFilePath:je,fileLoading:Ee,isDirty:ae,draftContent:B,fileContent:k,isNonEditableBinary:t}))return t?console.warn(`[saveDraft] refusing to save binary file "${c.path}".`):B===""&&k!==""&&je!==c.path&&console.warn(`[saveDraft] refusing to save empty draft for "${c.path}" (${k.length} bytes were expected). The file may have been read during a concurrent write (O_TRUNC race). Try again after content finishes loading if the save was intentional.`),!1;if(!ae)return!0;zs(!0);try{const i=Qa(B,Nr);if(!(await r.writeFile(c.path,i))?.success)return I.error(e("filesView.toast.writeFileFailed")),!1;if(K(B),a&&ns(c.path,a)){const o=Ts(a,c.path);o&&fa.requestGitRefresh({directory:a,paths:[o]})}if(a&&/(?:^|\/)\.agents\/loops\/[^/]+\.md$/i.test(z(c.path))){const o=ma.getState().projects.find(u=>z(u.path)===z(a));if(o)try{await La(o.id)}catch{I.error(e("sessions.scheduledTasks.dialog.toast.updateFailed"))}}return c?.path&&nr(c.path)&&(ct.current=B,qt.current=B),ft(c.path).then(o=>{o&&(tt.current=o)}).catch(()=>{}),!0}catch(i){return I.error(i instanceof Error?i.message:e("filesView.toast.saveFailed")),!1}finally{zs(!1)}},[Jt,B,k,Ee,r,ae,Nr,je,ft,a,c,e]);n.useEffect(()=>{if(!ae){He(null);return}const t=i=>yt.current?(yt.current=!1,!0):(zt(!0),Xt.current=i,!1);return He(t),()=>{he.getState().mainTabGuard===t&&He(null)}},[ae,He]),n.useEffect(()=>{ne||(Mt("idle"),Ke.current&&(clearTimeout(Ke.current),Ke.current=null))},[ne]);const Yr=1500;n.useEffect(()=>{const t=!!(c&&r.writeFile),i=!!(c?.path&&(Ns(c.path)||Jt));if(Oa({autoSaveEnabled:ne,isDirty:ae,canWrite:t,isSaving:Pt,fileLoading:Ee,selectedFilePath:c?.path,loadedFilePath:je,isNonEditableBinary:i}))return Ke.current=setTimeout(()=>{Ct().then(l=>{l&&(Mt("saved"),setTimeout(()=>Mt("idle"),2e3))})},Yr),()=>{Ke.current&&(clearTimeout(Ke.current),Ke.current=null)}},[ne,Jt,B,Ee,ae,je,c,r.writeFile,Pt,Ct]),n.useEffect(()=>{Mt("idle")},[c?.path]),n.useEffect(()=>{const t=i=>{va(i)&&(i.key.toLowerCase()==="s"?(i.preventDefault(),Ke.current&&(clearTimeout(Ke.current),Ke.current=null),Pt||Ct().then(l=>{l&&(Mt("saved"),setTimeout(()=>Mt("idle"),2e3))})):i.key.toLowerCase()==="f"&&(i.preventDefault(),ge(!0)))};return window.addEventListener("keydown",t),()=>window.removeEventListener("keydown",t)},[Pt,Ct]);const Zr=n.useCallback(async t=>{const i=fs.current+1;fs.current=i;const l=()=>{if(!a)return!1;const Ne=Le.getState().byRoot[a],le=Ne?.selectedPath??Ne?.openPaths[0]??null;return fs.current===i&&le===t.path};Q(null),Pe(""),H(null),kr(!1);const o=Vi(t.path),u=Di(t.path),f=Ri(t.path),w=Ns(t.path);if(p&&A(!0),m.isDesktop&&o&&!u){K(""),Y(""),Ye(!0);return}if(!m.isDesktop&&o&&!u){K(""),Y(""),H(t.path),Ye(!1);return}if(f){K(""),Y(""),H(t.path),Ye(!1);return}if(w){K(""),Y(""),H(t.path),Ye(!1);return}Ye(!0);const D=Si(t.path),$={allowOutsideWorkspace:d==="editor-only"&&!!a&&!ns(t.path,a),outsideFileGrant:D};await Qr(t.path,$).then(Ne=>{if(!l())return;if(pa(Ne)){kr(!0),K(""),Y(""),H(t.path);return}const le=Ji(Ne);sn(Xa(Ne)),K(le),ct.current=le,qt.current=le,Y(le.length>is?`${le.slice(0,is)}
13
-
14
- … truncated …`:le),H(t.path),ft(t.path,$).then(kt=>{kt&&l()&&(tt.current=kt)}).catch(()=>{})}).catch(Ne=>{if(l()){if(Ja(Ne)){if(Ye(!1),a&&ie(a,null),Q(null),K(""),Y(""),H(null),tt.current=null,T.trim().length>0&&V(""),p&&A(!1),a){const kt=[...Oi(t.path,a),t.path];kt.length>0&&as(a,kt);for(const tr of kt)Se.current.has(tr)||Ve(tr)}return}if($i(Ne)){a&&lt(a,t.path),K(""),Y(""),Q(null),tt.current=null,p&&A(!1);return}K(""),Y(""),Q(Ne instanceof Error?Ne.message:e("filesView.error.readFileFailed")),tt.current=null}}).finally(()=>{l()&&Ye(!1)})},[as,p,Ve,d,Qr,ft,lt,a,m.isDesktop,T,ie,e]),vs=n.useCallback(async(t,i)=>{if(!a)return;const l=Oi(t,a),o=i?[...l,t]:l;o.length>0&&as(a,o);const u=o.map(f=>{if(!Se.current.has(f))return Ve(f)}).filter(Boolean);await Promise.all(u)},[as,Ve,a]),ei=n.useCallback((t,i)=>{const l=i.findIndex(o=>o.path===t);return l===-1||i.length<=1?null:i[l+1]??i[l-1]??null},[]),pe=n.useCallback(async t=>{if(yt.current)yt.current=!1;else if(ae){zt(!0),Lt.current=t;return}a&&(ie(a,t.path),vs(t.path,!1)),Q(null),Pe(""),K(""),ct.current="",qt.current="",Y(""),H(null),p&&A(!0)},[vs,ae,p,a,ie]);n.useEffect(()=>{c?.path&&vs(c.path,!1)},[vs,c?.path]),n.useEffect(()=>{if(!c){fs.current+=1,_t.current=null,Ye(!1);return}if(je===c.path||_t.current===c.path)return;const t=c.path;_t.current=t,Zr(c).finally(()=>{_t.current===t&&(_t.current=null)})},[Zr,je,c]);const ti=n.useRef(ae);ti.current=ae,n.useEffect(()=>{if(!c?.path||je!==c.path)return;let t=!1;const i=window.setInterval(()=>{document.hidden||ft(c.path,X).then(l=>{if(t||!l)return;const o=tt.current;if(!o||o.path!==c.path){tt.current=l;return}const u=l.mtimeMs!==void 0&&o.mtimeMs!==void 0&&l.mtimeMs!==o.mtimeMs,f=l.size!==o.size;!u&&!f||ti.current||(tt.current=l,H(null))}).catch(()=>{})},2e3);return()=>{t=!0,window.clearInterval(i)}},[je,ft,c?.path,X]);const Tn=n.useCallback(()=>{const t=Lt.current,i=Xt.current,l=Qt.current;if(Lt.current=null,Xt.current=null,Qt.current=null,yt.current=!0,zt(!1),Y(Gs),l){a&&Dt(a,l),c?.path===l&&(t?pe(t):(a&&ie(a,null),K(""),Q(null),Pe(""),H(null),p&&A(!1)));return}if(t){pe(t);return}i&&(He(null),he.getState().setActiveMainTab(i))},[Gs,pe,p,Dt,a,c?.path,He,ie]),Vn=n.useCallback(async()=>{const t=Lt.current,i=Xt.current,l=Qt.current;if(!await Ct()){yt.current=!1;return}if(Lt.current=null,Xt.current=null,Qt.current=null,yt.current=!0,zt(!1),l){a&&Dt(a,l),c?.path===l&&(t?await pe(t):(a&&ie(a,null),K(""),Q(null),Pe(""),H(null),p&&A(!1)));return}if(t){await pe(t);return}i&&(He(null),he.getState().setActiveMainTab(i))},[pe,p,Dt,a,Ct,c?.path,He,ie]),si=n.useCallback(t=>{const i=c?.path===t,l=ei(t,Et);if(i&&ae){zt(!0),Lt.current=l,Qt.current=t;return}if(a&&Dt(a,t),!!i){if(l){pe(l);return}a&&ie(a,null),K(""),Q(null),Pe(""),H(null),p&&A(!1)}},[ei,pe,ae,p,Et,Dt,a,c?.path,ie]),Dn=n.useCallback(t=>{if(C.includes(t))return"open";if(L?.files){const i=t.startsWith(a+"/")?t.slice(a.length+1):t,l=L.files.find(o=>o.path===i);if(l){if(l.index==="A"||l.working_dir==="?")return"git-added";if(l.index==="D")return"git-deleted";if(l.index==="M"||l.working_dir==="M")return"git-modified"}}return null},[C,L,a]),Rn=n.useCallback(t=>{if(!L?.files)return null;const i=t.startsWith(a+"/")?t.slice(a.length+1):t,l=i?`${i}/`:"";let o=0,u=0;for(const f of L.files)f.path.startsWith(l)&&((f.index==="M"||f.working_dir==="M")&&o++,(f.index==="A"||f.working_dir==="?")&&u++);return o+u>0?{modified:o,added:u}:null},[L,a]),En=n.useCallback(async t=>{const i=z(t);a&&(gr(a,i),Se.current.has(i)||await Ve(i))},[Ve,a,gr]),Pn=n.useMemo(()=>({canRename:Er,canCreateFile:Dr,canCreateFolder:Rr,canDelete:Pr,canReveal:Mr}),[Er,Dr,Rr,Pr,Mr]);function ri(t,i){const l=yr[t]??[];return l.map((o,u)=>{const f=o.type==="directory",w=f&&Xe.includes(o.path),D=c?.path===o.path,$=u===l.length-1;return s.jsxs("li",{className:"relative",children:[i>0&&s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"absolute top-3.5 left-[-12px] w-3 h-px bg-border/40"}),$&&s.jsx("span",{className:"absolute top-3.5 bottom-0 left-[-13px] w-[2px] bg-background"})]}),s.jsx(Za,{node:o,root:a,isExpanded:w,isActive:D,isMobile:p,isBrowserClient:F,alwaysShowActions:M,status:f?void 0:Dn(o.path),badge:f?Rn(o.path):void 0,permissions:Pn,downloadFile:r.downloadFile,contextMenuPath:fn,setContextMenuPath:mn,rightClickMenuPath:pn,setRightClickMenuPath:hn,onSelect:pe,onToggle:En,onRevealPath:jn,onOpenDialog:$s}),f&&w&&s.jsxs("ul",{className:"flex flex-col gap-1 ml-3 pl-3 border-l border-border/40 relative",children:[ls[o.path]?s.jsxs("li",{className:"flex items-center gap-2 px-2 py-1 typography-meta text-muted-foreground",children:[s.jsx("span",{className:"min-w-0 flex-1 truncate text-[var(--status-error)]",title:ls[o.path],children:ls[o.path]}),s.jsxs(S,{variant:"ghost",size:"xs",className:"h-6 gap-1",onClick:()=>{_e(o.path)},children:[s.jsx(g,{name:"refresh",className:"size-3.5"}),e("filesView.tree.actions.refreshTitle")]})]}):null,ri(o.path,i+1)]})]},o.path)})}const Z=!!(c?.path&&Vi(c.path)),Bt=!!(c?.path&&Di(c.path)),De=!!(c?.path&&Ri(c.path)),Ks=!!(c?.path&&(Ns(c.path)||Jt)),st=Ks&&!Z&&!De,ii=n.useMemo(()=>z(qe?.path??""),[qe?.path]),$t=!!(qe&&ii&&Ge&&Ge===ii&&!Ee&&!Ze&&!Z&&!De&&!st),mt=n.useMemo(()=>Ts(a,Ge),[Ge,a]),Mn=!!(c&&(!Z||Bt)&&!De&&!st&&k.length>0),zn=!!(c&&mt.length>0),Re=!!(c&&!os&&!Ks&&!Z&&r.writeFile&&k.length<=is),pt=!!(c?.path&&Wi(c.path)),ss=!!(c?.path&&Ya(c.path)),Wt=!!(c?.path&&dr(c.path)),rs=!!(c?.path&&nr(c.path)),Hs=!!(c&&!Ks&&!Z)&&!pt&&!rs&&!(Wt&&ve==="preview"),Ln=pt&&vt==="edit"||Wt&&ve==="edit"||ss&&Oe==="text"||!pt&&!Wt&&!ss&&G==="edit",ws=n.useMemo(()=>Ge?ha(Ge):null,[Ge]),[ni,qs]=n.useState(null);n.useEffect(()=>{let t=!1;const i=c?.path;if(!i||ws){qs(null);return}return qs(null),ga(i).then(l=>{t||qs(l)}),()=>{t=!0}},[c?.path,ws]),n.useEffect(()=>{!Re&&G==="edit"&&Ce("view")},[Re,G]);const _s="openchamber:files:md-viewer-mode",Js="openchamber:files:html-viewer-mode",Xs="openchamber:files:json-viewer-mode";n.useEffect(()=>{const t=c?.path;if(!t)return;Ce($e.current[t]??"edit");let i=es?"preview":"edit";try{const u=localStorage.getItem(_s);(u==="preview"||u==="edit")&&(i=u)}catch{}Ie(We.current[t]??i);let l=es?"preview":"edit";try{const u=localStorage.getItem(Js);(u==="preview"||u==="edit")&&(l=u)}catch{}Be(Ue.current[t]??l),ke(ot.current[t]??(es?"preview":"edit"));let o=es?"tree":"text";try{const u=localStorage.getItem(Xs);(u==="tree"||u==="text")&&(o=u)}catch{}wt(o)},[c?.path,es]);const An=n.useCallback(t=>{const i=c?.path;i&&($e.current[i]=t),Ce(t)},[c?.path]),ai=n.useCallback(t=>{const i=c?.path;i&&(We.current[i]=t),Ie(t);try{localStorage.setItem(_s,t)}catch{}},[c?.path]),oe=n.useCallback(()=>vt,[vt]),In=n.useCallback(t=>{wt(t);try{localStorage.setItem(Xs,t)}catch{}},[]),On=n.useCallback(t=>{const i=c?.path;i&&(Ue.current[i]=t),Be(t);try{localStorage.setItem(Js,t)}catch{}},[c?.path]),Bn=n.useCallback(t=>{const i=c?.path;if(i&&(ot.current[i]=t),Fe.current&&(clearTimeout(Fe.current),Fe.current=null),et.current!==null&&(cancelAnimationFrame(et.current),et.current=null),t==="edit")Y(ct.current||k),ke(t);else{ct.current=B;const l=i;ke("edit"),et.current=requestAnimationFrame(()=>{et.current=requestAnimationFrame(()=>{et.current=null,!(a&&l&&Le.getState().byRoot[a]?.selectedPath!==l)&&(at(o=>o+1),ke("preview"))})});return}},[B,k,a,c?.path]),Qs=n.useCallback(async(t,i)=>{if(!r.writeFile||i===qt.current)return!1;if(!(await r.writeFile(t,i))?.success)return I.error(e("filesView.toast.writeFileFailed")),!1;ct.current=i,qt.current=i,Y(i);const o=await ft(t,X).catch(()=>null);return o&&(tt.current=o),!0},[r,ft,X,e]);n.useEffect(()=>()=>{Fe.current&&(clearTimeout(Fe.current),Fe.current=null),et.current!==null&&(cancelAnimationFrame(et.current),et.current=null)},[fe,c?.path]);const $n=n.useCallback(t=>{if(ct.current=t,!ne||!c?.path||fe!=="preview"||!r.writeFile)return;Fe.current&&clearTimeout(Fe.current);const i=c.path;Fe.current=setTimeout(()=>{Fe.current=null,Qs(i,t).then(l=>{l&&(ms(!0),setTimeout(()=>ms(!1),1500))}).catch(l=>{I.error(l instanceof Error?l.message:e("filesView.toast.saveFailed"))})},Yr)},[ne,fe,r.writeFile,Qs,c?.path,e]),Wn=n.useMemo(()=>rs&&(ct.current||B)||k,[B,k,rs]),oi=n.useCallback(()=>ve,[ve]);n.useEffect(()=>{const t=l=>{const o=l?"preview":"edit",u=l?"tree":"text";for(const f of C)$e.current[f]="edit",Wi(f)&&(We.current[f]=o),dr(f)&&(Ue.current[f]=o),nr(f)&&(ot.current[f]=o);Ce("edit"),Ie(o),Be(o),ke(o),wt(u);try{localStorage.setItem(_s,o),localStorage.setItem(Js,o),localStorage.setItem(Xs,u)}catch{}},i=l=>{const o=!!l.detail?.enabled;t(o)};return window.addEventListener("openchamber:file-viewer-preview-mode-changed",i),()=>{window.removeEventListener("openchamber:file-viewer-preview-mode-changed",i)}},[C]),n.useEffect(()=>{if(!qe||!a)return;const t=()=>{typeof window>"u"||At.current===null&&(At.current=window.requestAnimationFrame(()=>{At.current=null,As(rt=>rt+1)}))},i=(rt,St)=>{if(rt.state.doc.length!==St.length)return!1;if(St.length===0)return!0;const sr=Math.min(128,St.length);if(rt.state.sliceDoc(0,sr)!==St.slice(0,sr))return!1;const Fi=Math.max(0,St.length-sr);return rt.state.sliceDoc(Fi,St.length)===St.slice(Fi)},l=z(qe.path);if(!l){ps(null),jt.current={key:"",attempts:0};return}const o=`${l}:${qe.line}:${qe.column??1}`;if(jt.current.key!==o&&(jt.current={key:o,attempts:0}),c?.path!==l){if(Ls)return;pe(Rt(l));return}if(Ee||je!==l)return;if(Ze||Z||De||st){ps(null),jt.current={key:"",attempts:0};return}if(!Re)return;if(G!=="edit"){Ce("edit");return}const u=Me.current;if(!u){t();return}if(!i(u,B)){t();return}const f=Math.max(1,Math.min(qe.line,u.state.doc.lines)),w=u.state.doc.line(f),D=Math.max(1,qe.column||1),$=Math.max(0,w.to-w.from),Ne=Math.min($,D-1),le=w.from+Ne;if(!(u.state.selection.main.head===le)||jt.current.attempts===0){jt.current.attempts+=1,u.dispatch({selection:{anchor:le},effects:Tt.scrollIntoView(le,{y:"center"})}),u.focus(),t();return}typeof window<"u"&&window.requestAnimationFrame(()=>{const rt=Me.current;rt&&(rt.dispatch({selection:{anchor:le},effects:Tt.scrollIntoView(le,{y:"center"})}),rt.focus())}),ps(null),jt.current={key:"",attempts:0}},[Re,Ls,B,cn,Ze,Ee,Z,De,st,je,pe,qe,a,c?.path,ps,G,Rt]),n.useEffect(()=>{if(!Ws||!a)return;const t=z(Ws);if(!t){Us(null);return}c?.path===t&&(Ee||je!==t||(!Ze&&!Z&&!De&&!st&&Re&&G==="edit"&&Me.current?.focus(),Us(null)))},[Re,Ze,Ee,Z,De,st,je,Ws,a,c?.path,Us,G]);const Ut=n.useCallback(t=>{if(!p||!t||!t.hasFocus||typeof window>"u")return;const i=window.visualViewport;if(!i)return;const l=document.documentElement.clientHeight||window.innerHeight;if(Math.max(0,l-(i.offsetTop+i.height))<=0)return;const u=t.state.selection.main.head,f=t.coordsAtPos(u);if(!f)return;const w=Math.round(i.offsetTop+i.height),$=f.bottom+20-w;$<=0||(t.scrollDOM.scrollTop+=$)},[p]);n.useEffect(()=>{if(!p||typeof window>"u")return;const t=()=>{window.requestAnimationFrame(()=>{Ut(Me.current)})},i=window.visualViewport;return i?.addEventListener("resize",t),i?.addEventListener("scroll",t,{passive:!0}),document.addEventListener("selectionchange",t),()=>{i?.removeEventListener("resize",t),i?.removeEventListener("scroll",t),document.removeEventListener("selectionchange",t)}},[p,Ut]),n.useEffect(()=>{if(!Re||G!=="edit"||p)return;const t=xa("open_go_to_line",Ar),i=l=>{const o=l.target;if(o?.closest('[role="dialog"]'))return;const u=!!o?.closest(".cm-editor");o?.closest('input, textarea, [contenteditable="true"], [role="textbox"]')&&!u||!document.activeElement?.closest(".cm-editor")||wa(l,t)&&(l.preventDefault(),Bs(!0))};return window.addEventListener("keydown",i),()=>window.removeEventListener("keydown",i)},[Re,p,Ar,G]);const bs=he(t=>t.editorFontSize),li=n.useMemo(()=>{if(!c?.path)return[Mi(x,{fontSize:bs})];const t=ir(c.path),i=[Mi(x,t?{syntaxColors:!1,fontSize:bs}:{fontSize:bs})],l=ws??ni;return l&&i.push(l),t&&i.push(Sa({language:t,themeName:x.metadata.id,theme:Ra(x)})),de&&i.push(Tt.lineWrapping),p&&i.push(Tt.updateListener.of(o=>{o.view.hasFocus&&(o.selectionSet||o.focusChanged||o.viewportChanged||o.geometryChanged)&&window.requestAnimationFrame(()=>{Ut(o.view)})})),i},[x,c?.path,ws,ni,de,p,Ut,bs]),ci=n.useMemo(()=>({light:me.metadata.id,dark:we.metadata.id}),[me.metadata.id,we.metadata.id]),ys=c?.path&&Z&&!m.isDesktop&&!Bt?`${c.path}|${X.allowOutsideWorkspace?"outside":"workspace"}|${X.outsideFileGrant??""}`:"",js=c?.path&&De?`${c.path}|${X.allowOutsideWorkspace?"outside":"workspace"}|${X.outsideFileGrant??""}`:"",Fs=c?.path&&Wt&&ve==="preview"&&!m.isVSCode?c.path:"",Ys=e("filesView.error.readFileFailed"),{readyKey:di,nonce:ui}=ur(ys,Q,Ys),{readyKey:fi,nonce:Un}=ur(Fs,Q,Ys),{readyKey:mi,nonce:pi}=ur(js,Q,Ys),hi=!!(ys&&di!==ys),Gn=!!(Fs&&fi!==Fs),gi=!!(js&&mi!==js),xi=c?.path&&Z?m.isDesktop?Bt?`data:${Ei(c.path)};utf8,${encodeURIComponent(k)}`:tn:Bt?`data:${Ei(c.path)};utf8,${encodeURIComponent(k)}`:di===ys?rr().authenticatedAsset("/api/fs/raw",{path:c.path,allowOutsideWorkspace:X.allowOutsideWorkspace?"true":void 0,outsideFileGrant:X.outsideFileGrant,directory:a||void 0}):"":"",vi=c?.path&&De&&mi===js?rr().authenticatedAsset("/api/fs/raw",{path:c.path,allowOutsideWorkspace:X.allowOutsideWorkspace?"true":void 0,outsideFileGrant:X.outsideFileGrant,directory:a||void 0}):"",wi=n.useCallback(t=>s.jsx("div",{className:"h-full overflow-hidden bg-[var(--surface-background)]",children:s.jsx("iframe",{src:vi,className:"h-full w-full border-0",title:t.name},pi)}),[vi,pi]);n.useEffect(()=>{let t=!1;return(async()=>{if(!m.isDesktop||!c?.path||!Z||Bt){ye.current&&(URL.revokeObjectURL(ye.current),ye.current=""),Pe("");return}Q(null),ye.current&&(URL.revokeObjectURL(ye.current),ye.current=""),await(r.readFileBinary?r.readFileBinary(c.path,X).then(o=>o.dataUrl):(async()=>{const o=await ki("/api/fs/raw",{query:{path:c.path,allowOutsideWorkspace:X.allowOutsideWorkspace?"true":void 0,outsideFileGrant:X.outsideFileGrant,directory:a||void 0}});if(!o.ok)throw new Error(e("filesView.error.readFileFailed"));const u=await o.blob(),f=URL.createObjectURL(u);return t?(URL.revokeObjectURL(f),""):(ye.current=f,f)})()).then(o=>{t||(Pe(o),H(c.path))}).catch(o=>{ye.current&&(URL.revokeObjectURL(ye.current),ye.current=""),t||(Pe(""),Q(o instanceof Error?o.message:e("filesView.error.readFileFailed")),H(null))}).finally(()=>{t||Ye(!1)})})(),()=>{t=!0}},[r,Z,Bt,a,m.isDesktop,c?.path,X,e]),n.useEffect(()=>()=>{ye.current&&(URL.revokeObjectURL(ye.current),ye.current="")},[]);const Kn=n.useCallback(()=>Is(null),[]),Hn=n.useMemo(()=>za({drafts:Br,editingDraftId:gs,commentText:hs,onTextChange:$r,selection:P,isDragging:Lr,fileLabel:c?.path??"",newWidgetId:"files-new-comment-input",mapDraftToRange:t=>({start:t.startLine,end:t.endLine}),onSave:qr,onCancel:()=>{ze(null),ts()},onEdit:t=>{Kr(t),ze({start:t.startLine,end:t.endLine})},onDelete:Hr}),[ts,hs,Hr,gs,Br,qr,Lr,P,c?.path,$r,Kr]),bi=n.useCallback((t,i)=>s.jsx("div",{className:"h-full",children:s.jsx(Va,{file:{name:t.name,contents:i,lang:ir(t.path)||void 0},options:{disableFileHeader:!0,overflow:de?"wrap":"scroll",theme:ci,themeType:x.metadata.variant==="dark"?"dark":"light"},className:"block h-full w-full",style:{height:"100%"}})}),[x.metadata.variant,ci,de]),Zs=({exitFullscreenOnly:t=!1,layout:i="floating"}={})=>{if(!c)return null;const o=i==="docked"?"pointer-events-auto flex flex-wrap items-center gap-1":"pointer-events-auto flex items-center gap-1 rounded-lg border border-[var(--interactive-border)] bg-[var(--surface-elevated)] p-1 shadow-sm",u=(f,w)=>s.jsxs(ht,{children:[s.jsx(gt,{asChild:!0,children:s.jsx("span",{className:"inline-flex",children:w})}),s.jsx(xt,{side:"bottom",sideOffset:6,children:f})]});return s.jsxs("div",{className:o,children:[Re&&Ln&&s.jsxs(s.Fragment,{children:[Pt?s.jsxs("span",{className:"flex items-center gap-1 px-1 text-muted-foreground typography-meta",children:[s.jsx(g,{name:"loader-4",className:"size-3.5 animate-spin"}),e("filesView.editor.saving")]}):ne&&nn==="saved"&&!ae?s.jsxs("span",{className:"flex items-center gap-1 px-1 text-[color:var(--status-success)] typography-meta",children:[s.jsx(g,{name:"check",className:"size-3.5"}),e("filesView.editor.saved")]}):ae?u(e(ne?"filesView.editor.saveNowTitle":"filesView.editor.saveNowManualTitle",{shortcut:`${lr()}+S`}),s.jsx(S,{variant:"ghost",size:"sm",onClick:()=>{Ct()},className:"h-6 gap-1 px-1 text-muted-foreground opacity-80 hover:bg-transparent hover:opacity-100 focus-visible:bg-transparent active:bg-transparent",title:e(ne?"filesView.editor.saveNowTitle":"filesView.editor.saveNowManualTitle",{shortcut:`${lr()}+S`}),"aria-label":e("filesView.editor.saveAria",{shortcut:`${lr()}+S`}),children:s.jsx(g,{name:"save-3",className:"size-4"})})):null,u(e(ne?"filesView.editor.autoSaveOn":"filesView.editor.manualSave"),s.jsx(S,{variant:"ghost",size:"sm",onClick:()=>on(!ne),className:O("size-6 p-0 transition-opacity hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",ne?"text-foreground opacity-100":"text-muted-foreground opacity-65 hover:opacity-100"),title:e(ne?"filesView.editor.autoSaveOn":"filesView.editor.manualSave"),"aria-label":e(ne?"filesView.editor.autoSaveOn":"filesView.editor.manualSave"),children:ne?s.jsx(g,{name:"file-check-fill",className:"size-4"}):s.jsx(g,{name:"file-check",className:"size-4"})}))]}),s.jsxs(fr,{onOpenChange:Vt,children:[s.jsxs(ht,{children:[s.jsx(gt,{asChild:!0,children:s.jsx("span",{className:"inline-flex",children:s.jsx(mr,{asChild:!0,children:s.jsx(S,{variant:"ghost",size:"sm",className:"size-6 p-0 text-foreground opacity-100 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e("filesView.editor.openInDesktopApp"),"aria-label":e("filesView.editor.openInDesktopApp"),children:s.jsx(g,{name:"file-transfer",className:"size-4"})})})})}),s.jsx(xt,{side:"bottom",sideOffset:6,children:e("filesView.editor.openInDesktopApp")})]}),s.jsxs(pr,{align:"end",className:"w-56 max-h-[70vh] overflow-y-auto",children:[wn.map(f=>s.jsxs(Ss,{className:"flex items-center gap-2",onClick:()=>{Fn(f)},children:[s.jsx(Wa,{label:f.label,iconDataUrl:f.iconDataUrl}),s.jsx("span",{className:"typography-ui-label text-foreground",children:f.label})]},f.id)),bn?s.jsxs(Ss,{className:"flex items-center gap-2",onClick:()=>{yn(!0)},children:[s.jsx(g,{name:"refresh",className:"size-4"}),s.jsx("span",{className:"typography-ui-label text-foreground",children:e("filesView.editor.refreshApps")})]}):null]})]}),!Z&&!De&&!st&&s.jsxs(s.Fragment,{children:[u(e(de?"filesView.editor.disableLineWrap":"filesView.editor.enableLineWrap"),s.jsx(S,{variant:"ghost",size:"sm",onClick:()=>Ae(!de),className:O("size-6 p-0 transition-opacity hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",de?"text-foreground opacity-100":"text-muted-foreground opacity-65 hover:opacity-100"),title:e(de?"filesView.editor.disableLineWrap":"filesView.editor.enableLineWrap"),children:s.jsx(g,{name:"text-wrap",className:"size-4"})})),G==="edit"&&s.jsxs(s.Fragment,{children:[u(e("filesView.editor.findInFile"),s.jsx(S,{variant:"ghost",size:"sm",onClick:f=>{ge(!se),f.currentTarget.blur()},className:"size-6 p-0 text-foreground opacity-100 transition-opacity hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e("filesView.editor.findInFile"),children:s.jsx(g,{name:"search",className:"size-4"})})),u(e("filesView.editor.goToLine"),s.jsx(S,{variant:"ghost",size:"sm",onClick:f=>{Bs(w=>!w),f.currentTarget.blur()},className:"size-6 p-0 text-foreground opacity-100 transition-opacity hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e("filesView.editor.goToLine"),children:s.jsx(g,{name:"menu-fold-2",className:"size-4"})})),s.jsx(Ia,{open:vn,onOpenChange:Bs,view:Me.current,variant:"inline"})]})]}),Hs&&Re&&!ss&&!Wt&&s.jsx(cr,{currentMode:G==="view"?"preview":"edit",onToggle:()=>{An(G==="view"?"edit":"view")}}),pt&&u(e(oe()==="preview"?"filesView.editor.switchToEditMode":"filesView.editor.switchToPreviewMode"),s.jsx(S,{variant:"ghost",size:"sm",onClick:()=>ai(oe()==="preview"?"edit":"preview"),className:O("size-6 p-0 transition-colors hover:bg-[var(--interactive-hover)] focus-visible:bg-[var(--interactive-hover)] active:bg-[var(--interactive-hover)]",oe()==="preview"?"bg-[var(--interactive-selection)] text-[var(--interactive-selection-foreground)] hover:bg-[var(--interactive-selection)] focus-visible:bg-[var(--interactive-selection)] active:bg-[var(--interactive-selection)]":"text-muted-foreground opacity-65 hover:opacity-100"),title:e(oe()==="preview"?"filesView.editor.switchToEditMode":"filesView.editor.switchToPreviewMode"),"aria-label":e(oe()==="preview"?"filesView.editor.switchToEditMode":"filesView.editor.switchToPreviewMode"),children:s.jsx(g,{name:oe()==="preview"?"eye":"eye-off",className:"size-4"})})),dr(c?.path??"")&&s.jsx(cr,{currentMode:oi(),onToggle:()=>{On(oi()==="preview"?"edit":"preview")}}),pt&&oe()==="preview"&&Nn&&s.jsxs(ht,{children:[s.jsx(gt,{asChild:!0,children:s.jsx(S,{variant:"ghost",size:"sm",className:"size-6 p-0 text-muted-foreground opacity-65 hover:bg-transparent hover:opacity-100 focus-visible:bg-transparent active:bg-transparent","aria-label":e(us?"filesView.tts.stopSpeaking":"filesView.tts.readAloud"),onClick:()=>{us?en():k.trim()&&Zi(k)},children:us?s.jsx(g,{name:"stop",className:"size-4 text-[color:var(--status-success)]"}):s.jsx(g,{name:"volume-up",className:"size-4"})})}),s.jsx(xt,{sideOffset:8,children:e(us?"filesView.tts.stopSpeaking":"filesView.tts.readAloud")})]}),rs&&s.jsxs(s.Fragment,{children:[s.jsx(cr,{currentMode:fe,onToggle:()=>Bn(fe==="preview"?"edit":"preview")}),fe==="preview"&&s.jsx(S,{variant:"ghost",size:"sm",onClick:async()=>{const f=Cr.current?.getXml();if(Fe.current&&(clearTimeout(Fe.current),Fe.current=null),c?.path&&f){if(!await Qs(c.path,f))return;ms(!0),setTimeout(()=>ms(!1),1500)}},className:"size-6 p-0 text-foreground hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e("filesView.diagram.saveDiagram"),children:an?s.jsx(g,{name:"check",className:"size-4 text-[color:var(--status-success)]"}):s.jsx(g,{name:"save-3",className:"size-4"})})]}),ss&&u(e(Oe==="tree"?"filesView.editor.switchToTextView":"filesView.editor.switchToTreeView"),s.jsx(S,{variant:"ghost",size:"sm",onClick:()=>In(Oe==="tree"?"text":"tree"),className:"size-6 p-0 text-muted-foreground opacity-65 hover:bg-transparent hover:opacity-100 focus-visible:bg-transparent active:bg-transparent",title:e(Oe==="tree"?"filesView.editor.switchToTextView":"filesView.editor.switchToTreeView"),children:Oe==="tree"?s.jsx(g,{name:"code-sslash",className:"size-4"}):s.jsx(g,{name:"node-tree",className:"size-4"})})),Mn&&u(e("filesView.editor.copyFileContents"),s.jsx(S,{variant:"ghost",size:"sm",onClick:async()=>{(await Ds(k)).ok?(Tr(!0),Yt.current!==null&&window.clearTimeout(Yt.current),Yt.current=window.setTimeout(()=>{Tr(!1)},1200)):I.error(e("filesView.toast.copyFailed"))},className:"size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e("filesView.editor.copyFileContents"),"aria-label":e("filesView.editor.copyFileContents"),children:gn?s.jsx(g,{name:"check",className:"size-4 text-[color:var(--status-success)]"}):s.jsx(g,{name:"clipboard",className:"size-4"})})),zn&&u(e("filesView.editor.copyFilePathTitle",{path:mt}),s.jsx(S,{variant:"ghost",size:"sm",onClick:async()=>{(await Ds(mt)).ok?(Vr(!0),Zt.current!==null&&window.clearTimeout(Zt.current),Zt.current=window.setTimeout(()=>{Vr(!1)},1200)):I.error(e("filesView.toast.copyFailed"))},className:"size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e("filesView.editor.copyFilePathTitle",{path:mt}),"aria-label":e("filesView.editor.copyFilePathTitle",{path:mt}),children:xn?s.jsx(g,{name:"check",className:"size-4 text-[color:var(--status-success)]"}):s.jsx(g,{name:"file-copy-2",className:"size-4"})})),r.downloadFile&&u(e("filesView.editor.saveFile"),s.jsx(S,{variant:"ghost",size:"sm",onClick:()=>{const f=r.downloadFile;f&&f(c.path).catch(w=>{console.error("Download failed:",w),I.error(e("sidebarFilesTree.toast.operationFailed"))})},className:"size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e("filesView.editor.saveFile"),"aria-label":e("filesView.editor.saveFile"),children:s.jsx(g,{name:"download",className:"size-4"})})),t?u(e("filesView.editor.exitFullscreen"),s.jsx(S,{variant:"ghost",size:"sm",onClick:()=>J(!1),className:"size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e("filesView.editor.exitFullscreen"),"aria-label":e("filesView.editor.exitFullscreen"),children:s.jsx(g,{name:"fullscreen-exit",className:"size-4"})})):!p&&d==="full"&&u(e(U?"filesView.editor.exitFullscreen":"filesView.editor.fullscreen"),s.jsx(S,{variant:"ghost",size:"sm",onClick:()=>J(!U),className:"size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e(U?"filesView.editor.exitFullscreen":"filesView.editor.fullscreen"),"aria-label":e(U?"filesView.editor.exitFullscreen":"filesView.editor.fullscreen"),children:U?s.jsx(g,{name:"fullscreen-exit",className:"size-4"}):s.jsx(g,{name:"fullscreen",className:"size-4"})}))]})},er=s.jsxs("div",{className:"relative flex h-full min-h-0 min-w-0 w-full flex-col overflow-hidden",children:[s.jsx(Ui,{open:Ls,onOpenChange:t=>{t||zt(!0)},children:s.jsxs(Gi,{showCloseButton:!1,className:"max-w-md",children:[s.jsxs(Ki,{children:[s.jsx(Hi,{children:e("filesView.unsaved.title")}),s.jsx(qi,{children:e("filesView.unsaved.description")})]}),s.jsxs(_i,{children:[s.jsx(S,{variant:"outline",onClick:()=>{Vn()},disabled:Pt,className:"border-[var(--status-success-border)] bg-[var(--status-success-background)] text-[var(--status-success)] hover:bg-[rgb(var(--status-success)/0.2)]",children:e("filesView.unsaved.saveChanges")}),s.jsx(S,{variant:"destructive",onClick:Tn,children:e("filesView.unsaved.discard")})]})]})}),s.jsxs("div",{className:O("flex flex-col flex-shrink-0",q&&"border-b border-border/40"),children:[q?s.jsxs("div",{className:"flex min-w-0 items-center px-3 py-1.5",children:[p&&te&&s.jsx("button",{type:"button",onClick:()=>A(!1),"aria-label":e("filesView.editor.back"),className:"inline-flex size-7 flex-shrink-0 items-center justify-center mr-1 text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",children:s.jsx(g,{name:"arrow-left-s",className:"size-5"})}),p?c?s.jsxs(fr,{children:[s.jsx(mr,{asChild:!0,children:s.jsxs("button",{type:"button",className:"inline-flex min-w-0 max-w-full items-center gap-1 text-left typography-ui-label font-medium","aria-label":e("filesView.editor.openFilesAria"),children:[s.jsx(ks,{filePath:c.path,extension:c.extension,className:"size-3.5 flex-shrink-0"}),s.jsx(Bi,{name:c.name}),s.jsx(g,{name:"arrow-down-s",className:"size-4 flex-shrink-0 text-muted-foreground"})]})}),s.jsx(pr,{align:"start",className:"w-[min(24rem,calc(100vw-2rem))] max-w-[calc(100vw-2rem)]",children:Et.map(t=>{const i=c?.path===t.path;return s.jsxs(Ss,{onSelect:l=>{if(l.target.closest("[data-close-open-file]")){l.preventDefault();return}i||pe(t)},className:O("flex min-w-0 items-center justify-between gap-2 overflow-hidden",i&&"bg-[var(--interactive-selection)] text-[var(--interactive-selection-foreground)]"),children:[s.jsxs("span",{className:"flex min-w-0 flex-1 items-center gap-2 overflow-hidden",children:[s.jsx(ks,{filePath:t.path,extension:t.extension,className:"size-3.5 flex-shrink-0"}),s.jsx(Bi,{name:t.name})]}),s.jsx("button",{type:"button","data-close-open-file":!0,onPointerDown:l=>{l.preventDefault(),l.stopPropagation()},onClick:l=>{l.preventDefault(),l.stopPropagation(),si(t.path)},className:"inline-flex size-6 shrink-0 items-center justify-center rounded-md text-[var(--surface-muted-foreground)] hover:text-[var(--surface-foreground)]","aria-label":e("filesView.editor.closeFileAria",{name:t.name}),children:s.jsx(g,{name:"close",className:"size-3.5"})})]},t.path)})})]}):s.jsx("div",{className:"typography-ui-label font-medium truncate",children:e("filesView.editor.selectFile")}):Et.length>0?s.jsxs("div",{className:"relative min-w-0 flex-1",children:[vr.left&&s.jsx("div",{className:"pointer-events-none absolute left-0 top-0 bottom-0 w-6 z-10 bg-gradient-to-r from-background to-transparent"}),vr.right&&s.jsx("div",{className:"pointer-events-none absolute right-0 top-0 bottom-0 w-6 z-10 bg-gradient-to-l from-background to-transparent"}),s.jsx("div",{ref:Ps,className:"flex min-w-0 items-center gap-1 overflow-x-auto scrollbar-none",style:{scrollbarWidth:"none",msOverflowStyle:"none"},children:Et.map(t=>{const i=c?.path===t.path;return s.jsxs("div",{title:Ts(a,t.path),className:O("group inline-flex items-center gap-1 rounded-md border px-2 py-1 typography-ui-label transition-colors whitespace-nowrap",i?"bg-[var(--interactive-selection)] border-[var(--primary-muted)] text-[var(--interactive-selection-foreground)]":"bg-transparent border-[var(--interactive-border)] text-[var(--surface-muted-foreground)] hover:bg-[var(--interactive-hover)] hover:text-[var(--surface-foreground)]"),children:[s.jsx(ks,{filePath:t.path,extension:t.extension,className:"size-3.5 flex-shrink-0"}),s.jsx("button",{type:"button",onClick:()=>{i||pe(t)},className:"max-w-[12rem] truncate text-left",children:t.name}),s.jsx("button",{type:"button",onClick:l=>{l.stopPropagation(),si(t.path)},className:O("rounded-sm p-0.5 text-[var(--surface-muted-foreground)] hover:text-[var(--surface-foreground)]",!i&&!M&&"opacity-0 group-hover:opacity-100"),"aria-label":e("filesView.editor.closeFileAria",{name:t.name}),children:s.jsx(g,{name:"close",className:"size-3.5"})})]},t.path)})})]}):s.jsx("div",{className:"typography-ui-label font-medium truncate",children:e("filesView.editor.selectFile")})]}):null,(Or||p)&&c?s.jsxs("div",{className:"flex min-w-0 items-center gap-3 border-t border-border/40 bg-[var(--surface-subtle)] px-3 py-1",children:[mt&&!p?s.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta text-muted-foreground",title:mt,children:mt}):null,s.jsx("div",{className:"ml-auto min-w-0 shrink-0 overflow-x-auto",children:Zs({layout:"docked"})})]}):null]}),s.jsxs("div",{className:"flex-1 min-h-0 min-w-0 relative",children:[c&&!se&&!(Or||p)&&s.jsx("div",{ref:ue,className:"absolute right-3 top-3 z-30",onMouseLeave:()=>{it.current>0||xe(!1)},children:re?Zs():s.jsxs("div",{className:"flex items-center gap-1",children:[pt?s.jsxs(ht,{children:[s.jsx(gt,{asChild:!0,children:s.jsx("span",{className:"inline-flex",children:s.jsx(S,{variant:"ghost",size:"sm",onClick:()=>ai(oe()==="preview"?"edit":"preview"),className:O("size-8 rounded-lg border border-[var(--interactive-border)] bg-[var(--surface-elevated)] p-0 shadow-sm transition-colors",oe()==="preview"?"bg-[var(--interactive-selection)] text-[var(--interactive-selection-foreground)] hover:bg-[var(--interactive-selection)]":"text-muted-foreground hover:text-foreground"),"aria-label":e(oe()==="preview"?"filesView.editor.switchToEditMode":"filesView.editor.switchToPreviewMode"),title:e(oe()==="preview"?"filesView.editor.switchToEditMode":"filesView.editor.switchToPreviewMode"),children:s.jsx(g,{name:oe()==="preview"?"eye":"eye-off",className:"size-4"})})})}),s.jsx(xt,{side:"bottom",sideOffset:6,children:e(oe()==="preview"?"filesView.editor.switchToEditMode":"filesView.editor.switchToPreviewMode")})]}):null,s.jsxs(ht,{children:[s.jsx(gt,{asChild:!0,children:s.jsx("span",{className:"inline-flex",onMouseEnter:()=>xe(!0),children:s.jsx(S,{variant:"ghost",size:"sm",onClick:()=>xe(!0),className:"size-8 rounded-lg border border-[var(--interactive-border)] bg-[var(--surface-elevated)] p-0 text-muted-foreground shadow-sm hover:text-foreground","aria-label":e("filesView.editor.showControlsAria"),title:e("filesView.editor.controlsTitle"),children:s.jsx(g,{name:"more-2-fill",className:"size-4"})})})}),s.jsx(xt,{side:"bottom",sideOffset:6,children:e("filesView.editor.controlsTitle")})]})]})}),s.jsx(ar,{outerClassName:"h-full min-w-0",className:"h-full min-w-0",children:c?Ee||hi||gi?W?s.jsx("div",{className:"p-3"}):s.jsxs("div",{className:"p-3 flex items-center gap-2 typography-ui text-muted-foreground",children:[s.jsx(g,{name:"loader-4",className:"size-4 animate-spin"}),e("filesView.state.loading")]}):Ze?s.jsx("div",{className:"p-3 typography-ui text-[color:var(--status-error)]",children:Ze}):Z?s.jsx("div",{className:"flex h-full items-center justify-center p-3",children:s.jsx("img",{src:xi,alt:c?.name??e("filesView.editor.imageAltFallback"),className:"max-w-full max-h-[70vh] object-contain rounded-md border border-border/30 bg-primary/10"},ui)}):De?wi(c):st?s.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-3 p-6 text-center",children:[s.jsx("div",{className:"typography-ui-header text-foreground",children:e("filesView.editor.cannotPreviewBinary")}),s.jsx("div",{className:"max-w-md typography-ui text-muted-foreground",children:e("filesView.editor.binaryFileDescription")}),r.downloadFile?s.jsxs(S,{type:"button",variant:"outline",size:"sm",onClick:()=>{const t=r.downloadFile;!t||!c||t(c.path).catch(i=>{console.error("Download failed:",i),I.error(e("sidebarFilesTree.toast.operationFailed"))})},children:[s.jsx(g,{name:"download",className:"mr-2 size-4"}),e("filesView.editor.saveFile")]}):null]}):c&&rs&&fe==="preview"?s.jsx("div",{className:"h-full overflow-hidden",style:{minHeight:"400px"},children:s.jsx(Ea,{ref:Cr,xml:Wn,onChange:$n},`${c.path}:${nt}`)}):c&&ss&&Oe==="tree"?s.jsx(or,{fallback:s.jsxs("div",{className:"rounded-md border border-destructive/20 bg-destructive/10 px-3 py-2",children:[s.jsx("div",{className:"mb-1 font-medium text-destructive",children:e("filesView.error.jsonViewerUnavailable")}),s.jsx("div",{className:"text-sm text-muted-foreground",children:e("filesView.error.switchToTextMode")})]}),children:s.jsx("div",{className:"h-full overflow-auto",children:s.jsx(Da,{jsonString:k,maxHeight:"100%",initiallyExpandedDepth:2})})}):c&&pt&&oe()==="preview"?s.jsxs("div",{className:"h-full overflow-auto p-3",children:[k.length>500*1024&&s.jsx("div",{className:"mb-3 rounded-md border border-status-warning/20 bg-status-warning/10 px-3 py-2 text-sm text-status-warning",children:e("filesView.warning.largeFilePreviewLimited",{sizeKb:Math.round(k.length/1024)})}),s.jsx(or,{fallback:s.jsxs("div",{className:"rounded-md border border-destructive/20 bg-destructive/10 px-3 py-2",children:[s.jsx("div",{className:"mb-1 font-medium text-destructive",children:e("filesView.error.previewUnavailable")}),s.jsx("div",{className:"text-sm text-muted-foreground",children:e("filesView.error.switchToEditMode")})]}),children:s.jsx(Pi,{content:k,className:"typography-markdown-body",stripFrontmatter:!0,enableFileReferences:!1})})]}):c&&Wt&&ve==="preview"?Gn?s.jsx("div",{className:"flex h-full items-center justify-center text-muted-foreground typography-ui-label",children:e("common.loading")}):s.jsx("div",{className:"h-full overflow-hidden",children:s.jsx("iframe",{src:!m.isVSCode&&fi===Fs?(()=>{const t=c.path.split("/").map(i=>encodeURIComponent(i)).join("/");return rr().authenticatedAsset(`/api/fs/serve${t.startsWith("/")?t:`/${t}`}`)})():void 0,srcDoc:m.isVSCode?(()=>{const t=c.path.substring(0,c.path.lastIndexOf("/")+1);return t?k.replace(/<head([^>]*)>/i,`<head$1><base href="${t}">`):k})():void 0,className:"w-full h-full border-none",sandbox:"allow-scripts allow-same-origin allow-forms",title:e("filesView.editor.htmlPreviewTitle")},Un)}):c&&Hs&&G==="view"?bi(c,B):s.jsxs("div",{className:O("relative h-full",$t&&"overflow-hidden"),ref:ln,children:[s.jsx("div",{className:O("h-full",$t&&"invisible"),children:s.jsx(zi,{value:B,onChange:Y,readOnly:!Re,vimMode:Ir==="vim",extensions:li,className:"h-full",blockWidgets:Hn,onViewReady:t=>{Me.current=t,As(i=>i+1),window.requestAnimationFrame(()=>{Ut(t)})},onViewDestroy:()=>{Me.current&&(Me.current=null),As(t=>t+1)},enableSearch:!0,searchOpen:se,onSearchOpenChange:ge,highlightLines:P?{start:Math.min(P.start,P.end),end:Math.max(P.start,P.end)}:void 0,lineNumbersConfig:{domEventHandlers:{mousedown:(t,i,l)=>{if(!(l instanceof MouseEvent)||l.button!==0)return!1;l.preventDefault();const o=t.state.doc.lineAt(i.from).number;if(P&&!l.shiftKey&&Math.min(P.start,P.end)===o&&Math.max(P.start,P.end)===o)return ze(null),ts(),It.current=!1,ut.current=null,Ot(!1),!0;if(p&&P&&!l.shiftKey){const u=Math.min(P.start,P.end,o),f=Math.max(P.start,P.end,o);return ze({start:u,end:f}),It.current=!1,ut.current=null,Ot(!1),!0}if(It.current=!0,ut.current=o,Ot(!0),P&&l.shiftKey){const u=Math.min(P.start,o),f=Math.max(P.end,o);ze({start:u,end:f})}else ze({start:o,end:o});return!0},mouseover:(t,i,l)=>{if(!(l instanceof MouseEvent)||l.buttons!==1||!It.current||ut.current===null)return!1;const o=t.state.doc.lineAt(i.from).number,u=Math.min(ut.current,o),f=Math.max(ut.current,o);return ze({start:u,end:f}),Ot(!0),!1},mouseup:()=>(It.current=!1,ut.current=null,Ot(!1),!1)}}})}),$t&&s.jsx("div",{className:"pointer-events-none absolute inset-0 flex items-center justify-center bg-background",children:s.jsxs("div",{className:"flex items-center gap-2 typography-ui text-muted-foreground",children:[s.jsx(g,{name:"loader-4",className:"size-4 animate-spin"}),e("filesView.state.openingFileAtChange")]})})]}):s.jsx("div",{className:"p-3 typography-ui text-muted-foreground",children:e("filesView.editor.pickFileFromTree")})})]})]}),qn=!!(a&&yr[a]),yi=a?ls[a]:null,ji=s.jsxs("section",{className:O("flex min-h-0 flex-col overflow-hidden",p?"h-full w-full bg-background":"h-full rounded-xl border border-border/60 bg-background/70"),children:[s.jsx("div",{className:O("flex flex-col gap-2 py-2",p?"px-3":"px-2"),children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsxs("div",{className:"relative flex-1 min-w-0",children:[s.jsx(g,{name:"search",className:"pointer-events-none absolute left-2 top-2 size-4 text-muted-foreground"}),s.jsx(Vs,{ref:ee,value:T,onChange:t=>V(t.target.value),placeholder:e("filesView.tree.search.placeholder"),className:"h-8 pl-8 pr-8 typography-meta"}),T.trim().length>0&&s.jsx("button",{type:"button","aria-label":e("filesView.tree.search.clearAria"),className:"absolute right-2 top-2 inline-flex size-4 items-center justify-center text-muted-foreground hover:text-foreground",onClick:()=>{V(""),ee.current?.focus()},children:s.jsx(g,{name:"close",className:"size-4"})})]}),s.jsxs(ht,{children:[s.jsx(gt,{asChild:!0,children:s.jsx("span",{className:"inline-flex flex-shrink-0",children:s.jsx(S,{variant:"ghost",size:"sm",onClick:()=>$s("createFile",{path:E,type:"directory"}),className:"size-8 p-0 flex-shrink-0",title:e("filesView.tree.actions.newFileTitle"),"aria-label":e("filesView.tree.actions.newFileTitle"),children:s.jsx(g,{name:"file-add",className:"size-4"})})})}),s.jsx(xt,{side:"bottom",sideOffset:6,children:e("filesView.tree.actions.newFileTitle")})]}),s.jsxs(ht,{children:[s.jsx(gt,{asChild:!0,children:s.jsx("span",{className:"inline-flex flex-shrink-0",children:s.jsx(S,{variant:"ghost",size:"sm",onClick:()=>$s("createFolder",{path:E,type:"directory"}),className:"size-8 p-0 flex-shrink-0",title:e("filesView.tree.actions.newFolderTitle"),"aria-label":e("filesView.tree.actions.newFolderTitle"),children:s.jsx(g,{name:"folder-add",className:"size-4"})})})}),s.jsx(xt,{side:"bottom",sideOffset:6,children:e("filesView.tree.actions.newFolderTitle")})]}),s.jsxs(ht,{children:[s.jsx(gt,{asChild:!0,children:s.jsx("span",{className:"inline-flex flex-shrink-0",children:s.jsx(S,{variant:"ghost",size:"sm",onClick:()=>{xs()},className:"size-8 p-0 flex-shrink-0",title:e("filesView.tree.actions.refreshTitle"),"aria-label":e("filesView.tree.actions.refreshTitle"),children:s.jsx(g,{name:"refresh",className:"size-4"})})})}),s.jsx(xt,{side:"bottom",sideOffset:6,children:e("filesView.tree.actions.refreshTitle")})]})]})}),s.jsx(ar,{outerClassName:"flex-1 min-h-0",className:O("py-2",p?"px-3":"px-2"),children:s.jsx("ul",{className:"flex flex-col",children:Yi?s.jsxs("li",{className:"flex items-center gap-1.5 px-2 py-1 typography-meta text-muted-foreground",children:[s.jsx(g,{name:"loader-4",className:"size-4 animate-spin"}),e("filesView.tree.search.searching")]}):Fr.length>0?Fr.map(t=>{const i=c?.path===t.path;return s.jsx("li",{children:s.jsxs("button",{type:"button",onClick:()=>{pe(t)},className:O("flex w-full items-center gap-1.5 rounded-md px-2 py-1 text-left text-foreground transition-colors",i?"bg-interactive-selection/70":"hover:bg-interactive-hover/40"),children:[Xi(t.path,t.extension),s.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta",style:{direction:"rtl",textAlign:"left"},title:t.path,children:t.relativePath??t.path})]})},t.path)}):yi?s.jsxs("li",{className:"flex flex-col gap-2 px-2 py-1 typography-meta text-muted-foreground",children:[s.jsx("span",{className:"text-[var(--status-error)]",children:yi}),s.jsxs(S,{variant:"outline",size:"xs",className:"w-fit gap-1.5",onClick:()=>{xs()},children:[s.jsx(g,{name:"refresh",className:"size-3.5"}),e("filesView.tree.actions.refreshTitle")]})]}):qn?ri(a,0):s.jsx("li",{className:"px-2 py-1 typography-meta text-muted-foreground",children:e("filesView.state.loading")})})})]}),_n=d==="full"&&U&&c&&s.jsx("div",{className:"absolute inset-0 z-50 flex flex-col bg-background",children:s.jsxs("div",{className:"flex-1 min-h-0 min-w-0 relative",children:[s.jsx("div",{className:"absolute right-4 top-4 z-30",children:Zs({exitFullscreenOnly:!0})}),s.jsx(ar,{outerClassName:"h-full min-w-0",className:"h-full min-w-0",children:Ee||hi||gi?W?s.jsx("div",{className:"p-4"}):s.jsxs("div",{className:"p-4 flex items-center gap-2 typography-ui text-muted-foreground",children:[s.jsx(g,{name:"loader-4",className:"size-4 animate-spin"}),"Loading…"]}):Ze?s.jsx("div",{className:"p-4 typography-ui text-[color:var(--status-error)]",children:Ze}):Z?s.jsx("div",{className:"flex h-full items-center justify-center p-4",children:s.jsx("img",{src:xi,alt:c.name,className:"max-w-full max-h-full object-contain rounded-md border border-border/30 bg-primary/10"},ui)}):De?wi(c):st?s.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-3 p-6 text-center",children:[s.jsx("div",{className:"typography-ui-header text-foreground",children:e("filesView.editor.cannotPreviewBinary")}),s.jsx("div",{className:"max-w-md typography-ui text-muted-foreground",children:e("filesView.editor.binaryFileDescription")}),r.downloadFile?s.jsxs(S,{type:"button",variant:"outline",size:"sm",onClick:()=>{const t=r.downloadFile;!t||!c||t(c.path).catch(i=>{console.error("Download failed:",i),I.error(e("sidebarFilesTree.toast.operationFailed"))})},children:[s.jsx(g,{name:"download",className:"mr-2 size-4"}),e("filesView.editor.saveFile")]}):null]}):pt&&oe()==="preview"?s.jsxs("div",{className:"h-full overflow-auto p-4",children:[k.length>500*1024&&s.jsx("div",{className:"mb-3 rounded-md border border-status-warning/20 bg-status-warning/10 px-3 py-2 text-sm text-status-warning",children:e("filesView.warning.largeFilePreviewLimited",{sizeKb:Math.round(k.length/1024)})}),s.jsx(or,{fallback:s.jsxs("div",{className:"rounded-md border border-destructive/20 bg-destructive/10 px-3 py-2",children:[s.jsx("div",{className:"mb-1 font-medium text-destructive",children:e("filesView.error.previewUnavailable")}),s.jsx("div",{className:"text-sm text-muted-foreground",children:e("filesView.error.switchToEditMode")})]}),children:s.jsx(Pi,{content:k,className:"typography-markdown-body",stripFrontmatter:!0,enableFileReferences:!1})})]}):Hs&&G==="view"?bi(c,B):s.jsxs("div",{className:O("relative h-full",$t&&"overflow-hidden"),children:[s.jsx("div",{className:O("h-full",$t&&"invisible"),children:s.jsx(zi,{value:B,onChange:Y,readOnly:!Re,vimMode:Ir==="vim",extensions:li,className:"h-full",onViewReady:t=>{Me.current=t,window.requestAnimationFrame(()=>{Ut(t)})},onViewDestroy:()=>{Me.current&&(Me.current=null)}})}),$t&&s.jsx("div",{className:"pointer-events-none absolute inset-0 flex items-center justify-center bg-background",children:s.jsxs("div",{className:"flex items-center gap-2 typography-ui text-muted-foreground",children:[s.jsx(g,{name:"loader-4",className:"size-4 animate-spin"}),e("filesView.state.openingFileAtChange")]})})]})})]})});return s.jsxs("div",{className:"flex h-full min-h-0 overflow-hidden bg-background relative",children:[s.jsx(eo,{activeDialog:Ft,dialogData:Nt,dialogInputValue:dt,onDialogInputChange:Sr,isDialogSubmitting:un,onDialogSubmit:Sn,onClose:Kn,inputRef:rn}),_n,p?te?er:ji:d==="editor-only"?s.jsx("div",{className:"flex flex-1 min-h-0 min-w-0 overflow-hidden",children:s.jsx("div",{className:"flex-1 min-h-0 min-w-0 overflow-hidden bg-background",children:er})}):s.jsxs("div",{className:"flex flex-1 min-h-0 min-w-0 gap-3 px-3 pb-3 pt-2",children:[h>=700&&s.jsx("div",{className:"w-72 flex-shrink-0 min-h-0 overflow-hidden",children:ji}),s.jsx("div",{className:"flex-1 min-h-0 min-w-0 overflow-hidden rounded-xl border border-border/60 bg-background",children:er})]})]})};function to(d){return d+1}export{vc as FilesView};
@@ -1,12 +0,0 @@
1
- import{R,f as V,j as Q}from"./vendor-react-BUCujlKS.js";import{m as st}from"./vendor-morphdom-B7dS_VPB.js";import{r as ct,a as lt}from"./vendor-beautiful-mermaid-DztCUpLZ.js";import{f0 as Oe,f1 as dt,f2 as mt,aP as le,d4 as ut,d5 as pt,f3 as ft,f4 as ht,U as De,$ as We,f5 as $e,g as qe,d_ as gt,f as bt,f6 as wt,o as yt,f7 as ge,f8 as vt,f9 as At,fa as kt}from"./useAppFontEffects-Bbpz77To.js";import{G as be,cf as Et,u as X,ag as we,C as Be,x as Ct,y as St,r as Lt}from"./index-CNrN5qDs.js";import{c as Mt}from"./contextPanelEmbeddedChat-5VGWIT_J.js";import{renderMarkdownSync as Nt,renderMarkdownBlocks as xt}from"./markdownCore-A3_L34oS.js";import{r as Rt}from"./registerCustomTheme-BBXUCRnG.js";import"./vendor-scheduler-7OC5HNn7.js";import"./vendor-elkjs-BRwcR927.js";import"./vendor-entities-C3BA0AJP.js";import"./vendor-simplewebauthn-browser-VDA66rT_.js";import"./vendor-vite-runtime-DD1OZmLC.js";import"./vendor-zustand-BAGL70zf.js";import"./vendor-base-ui-D_V6hAcE.js";import"./vendor-floating-ui-utils-BzXdqYpP.js";import"./vendor-floating-ui-dom-WyXykhNi.js";import"./vendor-floating-ui-core-CXmKXOXc.js";import"./vendor-floating-ui-react-dom-DKpLs02S.js";import"./vendor-use-sync-external-store-D6wYuSt-.js";import"./vendor-class-variance-authority-5VPnzWs2.js";import"./vendor-clsx-B-dksMZM.js";import"./vendor-dnd-kit-core-BZknOX2w.js";import"./vendor-dnd-kit-utilities-B_MdXhJC.js";import"./vendor-dnd-kit-accessibility-BHxJPORy.js";import"./vendor-dnd-kit-sortable-CsEagZ81.js";import"./vendor-cmdk-DgLInKvT.js";import"./vendor-radix-ui-react-dialog-B94Bt2qq.js";import"./vendor-radix-ui-primitive-Dc_FVRD7.js";import"./vendor-radix-ui-react-compose-refs-DcAh5WdT.js";import"./vendor-radix-ui-react-context-Czxm7Z62.js";import"./vendor-radix-ui-react-id-f5BLKEVw.js";import"./vendor-radix-ui-react-use-layout-effect-D_3IhJdJ.js";import"./vendor-radix-ui-react-use-controllable-state-BFT5YmkA.js";import"./vendor-radix-ui-react-dismissable-layer-D7kXcwgJ.js";import"./vendor-radix-ui-react-primitive-DhVoX9SD.js";import"./vendor-radix-ui-react-slot-BQgQOasS.js";import"./vendor-radix-ui-react-use-callback-ref-BZPnuXAC.js";import"./vendor-radix-ui-react-use-escape-keydown-oph88g-F.js";import"./vendor-radix-ui-react-focus-scope-CiaxW4dD.js";import"./vendor-radix-ui-react-portal-BMJYHWck.js";import"./vendor-radix-ui-react-presence-CNxf-uq4.js";import"./vendor-radix-ui-react-focus-guards-B6qJXYua.js";import"./vendor-react-remove-scroll-DO7dCTnK.js";import"./vendor-tslib-De9GV7Vy.js";import"./vendor-react-remove-scroll-bar-BcFYyj3E.js";import"./vendor-react-style-singleton-q6EMHnwf.js";import"./vendor-get-nonce-C-Z93AgS.js";import"./vendor-use-sidecar-zDC0RhA3.js";import"./vendor-use-callback-ref-D3RC8gqK.js";import"./vendor-aria-hidden-DvXkyWUv.js";import"./vendor-codemirror-language-DUOssd4j.js";import"./vendor-lezer-common-B3-cUCR_.js";import"./vendor-codemirror-state-CNWM3Q8V.js";import"./vendor-marijn-find-cluster-break-DXwl3gUT.js";import"./vendor-codemirror-view-DSzLbZiS.js";import"./vendor-style-mod-NZ5MEPvj.js";import"./vendor-w3c-keyname-Vcq4gwWv.js";import"./vendor-crelt-C8TCjufn.js";import"./vendor-lezer-highlight-CDMHUZ74.js";import"./vendor-codemirror-lang-javascript-Bbw3D7r0.js";import"./vendor-lezer-javascript-D7Tj24ot.js";import"./vendor-lezer-lr-bhwg1HMg.js";import"./vendor-codemirror-autocomplete-BjbBRsUA.js";import"./vendor-codemirror-lang-json-ryCw7nab.js";import"./vendor-lezer-json-Iaex0UN-.js";import"./vendor-codemirror-lang-css-VgNqFSH-.js";import"./vendor-lezer-css-C5xB6jxd.js";import"./vendor-codemirror-lang-html-B3Qe3OpS.js";import"./vendor-lezer-html-C0I1p52t.js";import"./vendor-codemirror-lang-markdown-FGQydhTc.js";import"./vendor-lezer-markdown-C6g-d6P3.js";import"./vendor-codemirror-language-data-Dzt9rWZZ.js";import"./vendor-codemirror-lang-python-N414WYK-.js";import"./vendor-lezer-python-CvuFxeZl.js";import"./vendor-codemirror-commands-ARAOgp1x.js";import"./vendor-tanstack-react-virtual-g05Cx3z9.js";import"./vendor-tanstack-virtual-core-Dubg10g5.js";import"./vendor-framer-motion-CRSgBxjL.js";import"./vendor-motion-dom-DJLgZh4Q.js";import"./vendor-motion-utils-BGh8QBgx.js";import"./vendor-sonner-DFyL3AvE.js";import"./vendor-tailwind-merge-CPcsbTWB.js";import"./vendor-fuse.js-Dw8P0qyA.js";import"./vendor-opencode-sdk-BJ73u-bH.js";import"./vendor-marked-i_gIkIP3.js";import"./vendor-remend-BWYYytN3.js";import"./vendor-katex-k3Ppq1Ha.js";import"./vendor-dompurify-r8glNMJW.js";import"./themeResolver-BmJyTmjJ.js";import"./vendor-pierre-theming-C6Z4M5_u.js";import"./vendor-shikijs-core-CGM_jqPK.js";import"./vendor-shikijs-types-CPSbSeK6.js";import"./vendor-shikijs-vscode-textmate-BgLrS_2D.js";import"./vendor-hast-util-to-html-BKBhbTDb.js";import"./vendor-html-void-elements-CkdplsNl.js";import"./vendor-property-information-rJCbAzvX.js";import"./vendor-zwitch-C2o2j-tx.js";import"./vendor-stringify-entities-CsH1VEn9.js";import"./vendor-character-entities-legacy-BpoLgcEt.js";import"./vendor-character-entities-html4-D7taRCQ7.js";import"./vendor-ccount-c2V3InAJ.js";import"./vendor-comma-separated-tokens-D8TqSuIK.js";import"./vendor-space-separated-tokens-DD3iYX1K.js";import"./vendor-hast-util-whitespace-D4Wp6AEg.js";const ze="openchamber-md",_t={name:ze,colors:{"editor.background":"transparent","editor.foreground":"var(--md-syntax-foreground)"},tokenColors:[{scope:["comment","punctuation.definition.comment","string.comment"],settings:{foreground:"var(--md-syntax-comment)",fontStyle:"italic"}},{scope:["string","punctuation.definition.string","string.template"],settings:{foreground:"var(--md-syntax-string)"}},{scope:["constant.numeric","constant.language","constant.character","constant"],settings:{foreground:"var(--md-syntax-number)"}},{scope:["keyword","storage","storage.type","storage.modifier","keyword.control"],settings:{foreground:"var(--md-syntax-keyword)"}},{scope:["keyword.operator","punctuation.separator","punctuation.terminator"],settings:{foreground:"var(--md-syntax-operator)"}},{scope:["entity.name.function","support.function","meta.function-call"],settings:{foreground:"var(--md-syntax-function)"}},{scope:["entity.name.type","entity.name.class","support.type","support.class","entity.other.inherited-class"],settings:{foreground:"var(--md-syntax-type)"}},{scope:["variable","variable.other","variable.parameter","meta.definition.variable"],settings:{foreground:"var(--md-syntax-variable)"}},{scope:["variable.other.property","meta.property-name","support.type.property-name"],settings:{foreground:"var(--md-syntax-property)"}},{scope:["entity.name.tag","punctuation.definition.tag"],settings:{foreground:"var(--md-syntax-keyword)"}},{scope:["entity.other.attribute-name"],settings:{foreground:"var(--md-syntax-property)"}},{scope:["markup.bold","punctuation.definition.bold"],settings:{fontStyle:"bold"}},{scope:["markup.italic","punctuation.definition.italic"],settings:{fontStyle:"italic"}},{scope:["markup.heading","markup.heading entity.name"],settings:{foreground:"var(--md-syntax-keyword)",fontStyle:"bold"}},{scope:["markup.inserted","punctuation.definition.inserted"],settings:{foreground:"var(--md-syntax-inserted)"}},{scope:["markup.deleted","punctuation.definition.deleted"],settings:{foreground:"var(--md-syntax-deleted)"}},{scope:["invalid","invalid.illegal"],settings:{foreground:"var(--md-syntax-deleted)"}}]};let ye=!1;const Tt=()=>{ye||(ye=!0,Rt(ze,()=>Promise.resolve(_t)))},x=t=>Number.isFinite(t)&&t>0,ve=t=>{if(typeof t=="number")return x(t)?t:null;if(typeof t!="string")return null;const e=t.trim().match(/^([+-]?(?:(?:\d+\.?\d*)|(?:\.\d+))(?:[eE][+-]?\d+)?)(?:px)?$/);if(!e)return null;const r=Number(e[1]);return x(r)?r:null},de=(t,e,r)=>Math.min(r,Math.max(e,t)),Pt=6,Ae=1.25,Ft=1.0015,It=.5,Ot=12,ke=3,Dt=400,ee='[data-markdown="mermaid-block"]',$=t=>t.querySelector(ee)!==null,Wt=t=>[t.x,t.y,t.width,t.height].map(e=>{const r=Number(e.toFixed(Pt));return Object.is(r,-0)?"0":String(r)}).join(" "),$t=t=>{const e=t.viewBox?.trim().split(/[\s,]+/).map(a=>Number.parseFloat(a));if(e?.length===4){const[a,i,s,o]=e;if(Number.isFinite(a)&&Number.isFinite(i)&&x(s)&&x(o))return{x:a,y:i,width:s,height:o}}const r=ve(t.width),n=ve(t.height);return r===null||n===null?null:{x:0,y:0,width:r,height:n}},qt=t=>{let e=2166136261;for(let r=0;r<t.length;r+=1)e^=t.charCodeAt(r),e=Math.imul(e,16777619);return(e>>>0).toString(36)},Bt=t=>{const e=t.renderMode||"unknown",r=t.svgMarkup??"";if(!r){const n=[t.viewBox??"",t.width??"",t.height??""];return n.some(a=>a!=="")?`${e}:bounds:${n.join(":")}`:`${e}:no-svg`}return[e,qt(r)].join(":")},Ve=(t,e)=>{if(!x(e.width)||!x(e.height))return t;const r=t.width/t.height,n=e.width/e.height;if(r>n){const i=t.width/n;return{x:t.x,y:t.y-(i-t.height)/2,width:t.width,height:i}}const a=t.height*n;return{x:t.x-(a-t.width)/2,y:t.y,width:a,height:t.height}},zt=({currentBox:t,viewport:e,delta:r})=>!x(e.width)||!x(e.height)||!x(t.width)||!x(t.height)?t:{x:t.x-r.x/e.width*t.width,y:t.y-r.y/e.height*t.height,width:t.width,height:t.height},Vt=(t,e)=>{const r=e.x-t.x,n=e.y-t.y;return r*r+n*n>ke*ke},Ht=({currentBox:t,contentBox:e,viewport:r,pointer:n,zoomFactor:a,minScale:i,maxScale:s})=>{if(!x(r.width)||!x(r.height)||!x(a)||!x(t.width)||!x(t.height)||!x(e.width)||!x(e.height)||!x(i)||!x(s))return t;const o=Math.min(i,s),c=Math.max(i,s),l=Ve(e,r),d=l.width/t.width,p=de(d*a,o,c),u=l.width/p,f=u/(t.width/t.height),g=de(n.x/r.width,0,1),A=de(n.y/r.height,0,1),E=t.x+g*t.width,y=t.y+A*t.height;return{x:E-g*u,y:y-A*f,width:u,height:f}},fe=new WeakMap,Kt=t=>t instanceof HTMLElement?fe.get(t)??null:null,jt=t=>t.querySelector('[data-markdown="mermaid-viewport"]')??t.querySelector('[data-markdown="mermaid"]'),Ee=t=>{const e=t.querySelector('[data-markdown="mermaid"] svg'),r=t.querySelector('[data-markdown="mermaid"]');return Bt({renderMode:t.getAttribute("data-mermaid-render"),svgMarkup:r?.getAttribute("data-md-original-svg")??e?.outerHTML??null,viewBox:e?.getAttribute("viewBox"),width:e?.getAttribute("width"),height:e?.getAttribute("height")})},J=t=>{const e=t.getBoundingClientRect();return{width:e.width,height:e.height}},Ut=(t,e)=>{const r=e.getBoundingClientRect();return{x:t.clientX-r.left,y:t.clientY-r.top}},Zt=t=>t instanceof Element&&!!t.closest('button, a, [role="button"]'),Xt=t=>{const e=jt(t),r=t.querySelector('[data-markdown="mermaid"] svg');if(!e||!r)return null;const n=$t({viewBox:r.getAttribute("viewBox"),width:r.getAttribute("width"),height:r.getAttribute("height")});if(!n)return null;let a=n,i=null,s=null,o=null,c=null;const l=h=>{a=h,r.setAttribute("viewBox",Wt(h)),r.removeAttribute("width"),r.removeAttribute("height")},d=()=>{l(Ve(n,J(e)))},p=(h,C)=>{l(Ht({currentBox:a,contentBox:n,viewport:J(e),pointer:h,zoomFactor:C,minScale:It,maxScale:Ot}))},u=()=>{const h=J(e);p({x:h.width/2,y:h.height/2},Ae)},f=()=>{const h=J(e);p({x:h.width/2,y:h.height/2},1/Ae)},g=h=>{!h.ctrlKey&&!h.metaKey||(h.preventDefault(),h.stopPropagation(),p(Ut(h,e),Math.pow(Ft,-h.deltaY)))},A=h=>{h.button!==0||Zt(h.target)||(i=h.pointerId,s={x:h.clientX,y:h.clientY},o=s,c!==null&&(window.clearTimeout(c),c=null),t.removeAttribute("data-mermaid-suppress-click"),e.setPointerCapture?.(h.pointerId),t.setAttribute("data-mermaid-panning","true"),h.preventDefault())},E=h=>{if(i!==h.pointerId||!o)return;const C={x:h.clientX,y:h.clientY};l(zt({currentBox:a,viewport:J(e),delta:{x:C.x-o.x,y:C.y-o.y}})),o=C,s&&Vt(s,C)&&t.setAttribute("data-mermaid-suppress-click","true"),h.preventDefault()},y=h=>{i===h.pointerId&&(e.releasePointerCapture?.(h.pointerId),i=null,s=null,o=null,t.removeAttribute("data-mermaid-panning"),t.hasAttribute("data-mermaid-suppress-click")&&(c=window.setTimeout(()=>{t.removeAttribute("data-mermaid-suppress-click"),c=null},Dt)))},L=()=>{d()};e.addEventListener("wheel",g,{passive:!1}),e.addEventListener("pointerdown",A),e.addEventListener("pointermove",E),e.addEventListener("pointerup",y),e.addEventListener("pointercancel",y),window.addEventListener("resize",L);const M=typeof ResizeObserver>"u"?null:new ResizeObserver(L);return M?.observe(e),d(),{zoomIn:u,zoomOut:f,fit:d,cleanup:()=>{e.removeEventListener("wheel",g),e.removeEventListener("pointerdown",A),e.removeEventListener("pointermove",E),e.removeEventListener("pointerup",y),e.removeEventListener("pointercancel",y),window.removeEventListener("resize",L),M?.disconnect(),c!==null&&window.clearTimeout(c),t.removeAttribute("data-mermaid-panning"),t.removeAttribute("data-mermaid-suppress-click"),fe.delete(t)}}},Gt=t=>{const e=new Map,r=new Map,n=()=>{for(const[i,s]of Array.from(e.entries())){const o=Ee(i);(!t.contains(i)||o!==r.get(i))&&(s.cleanup(),e.delete(i),r.delete(i))}for(const i of Array.from(t.querySelectorAll(ee))){if(e.has(i)||i.querySelector('[data-markdown="mermaid"] svg')===null)continue;const s=Xt(i);s&&(e.set(i,s),r.set(i,Ee(i)),fe.set(i,s))}},a=()=>{for(const i of e.values())i.cleanup();e.clear(),r.clear()};return n(),{refresh:n,cleanup:a}},q=t=>`<svg class="remixicon size-3.5" viewBox="0 0 24 24" aria-hidden="true"><use href="#oc-${t}"></use></svg>`,ae={copy:q("file-copy"),check:q("check"),download:q("download"),zoomIn:q("add"),zoomOut:q("subtract"),fit:q("refresh"),textWrap:q("text-wrap")},He="p-1 rounded hover:bg-interactive-hover/60 text-muted-foreground hover:text-foreground transition-colors focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-[var(--interactive-focus-ring)]",se=(t,e)=>{t.innerHTML=e},W=(t,e,r)=>{const n=document.createElement("button");return n.type="button",n.className=He,n.setAttribute("data-md-action",r),n.setAttribute("title",e),n.setAttribute("aria-label",e),se(n,ae[t]),n},Ke=(t,e,r)=>{const n=t.querySelector("[data-md-code-body]"),a=t.querySelector("pre"),i=t.querySelector("pre code"),s=t.querySelectorAll("[data-md-code-line-content]"),o=t.querySelector('[data-md-action="toggle-code-wrap"]');t.setAttribute("data-code-wrap",e?"true":"false"),n?.classList.toggle("overflow-x-auto",!e),n?.classList.toggle("overflow-x-hidden",e),a?.classList.toggle("whitespace-pre-wrap",e),a?.classList.toggle("break-words",e),i?.classList.toggle("whitespace-pre-wrap",e),i?.classList.toggle("break-words",e),a&&(a.style.whiteSpace=e?"pre-wrap":"pre",a.style.overflowWrap=e?"anywhere":"normal"),i&&(i.style.whiteSpace=e?"pre-wrap":"pre",i.style.overflowWrap=e?"anywhere":"normal");for(const c of Array.from(s))c.style.whiteSpace=e?"pre-wrap":"pre",c.style.overflowWrap=e?"anywhere":"normal";if(o){const c=e?r.disableCodeWrap:r.enableCodeWrap;o.setAttribute("title",c),o.setAttribute("aria-label",c),o.classList.toggle("text-foreground",e),o.classList.toggle("opacity-100",e),o.classList.toggle("text-muted-foreground",!e),o.classList.toggle("opacity-65",!e),o.setAttribute("aria-pressed",e?"true":"false")}},je=t=>{const e=t.querySelector(":scope > code");if(!e||e.hasAttribute("data-md-code-lines"))return;const r=e.textContent??"",n=r.endsWith(`
2
- `),a=n?r.slice(0,-1).split(`
3
- `):r.split(`
4
- `),i=a.length>0?a:[""],s=Array.from(e.children).filter(l=>l.classList.contains("line"));n&&s.length===i.length+1&&s.at(-1)?.textContent===""&&s.pop();const o=s.length===i.length,c=document.createDocumentFragment();i.forEach((l,d)=>{const p=document.createElement("span");p.setAttribute("data-md-code-line","");const u=document.createElement("span");u.setAttribute("data-md-code-line-number",""),u.setAttribute("aria-hidden","true"),u.textContent=String(d+1);const f=document.createElement("span");if(f.setAttribute("data-md-code-line-content",""),o){const g=s[d];g&&f.append(...Array.from(g.childNodes))}else f.textContent=l;if(p.append(u,f),c.appendChild(p),d<i.length-1||n){const g=document.createElement("span");g.setAttribute("data-md-code-line-break",""),g.textContent=`
5
- `,c.appendChild(g)}}),e.replaceChildren(c),e.setAttribute("data-md-code-lines",""),e.toggleAttribute("data-md-code-trailing-newline",n)},Ue=t=>{const e=Array.from(t.querySelectorAll("[data-md-code-line-content]"));if(e.length===0)return t.textContent??"";const r=e.map(n=>n.textContent??"").join(`
6
- `);return t.hasAttribute("data-md-code-trailing-newline")?`${r}
7
- `:r},Yt=(t,e,r)=>{const n=t.querySelectorAll('[data-component="markdown-code"]');for(const a of Array.from(n)){const i=a.querySelector("pre");i&&je(i),Ke(a,e,r)}},Ce=(t,e,r,n)=>{se(t,ae.check),t.setAttribute("title",e),t.setAttribute("aria-label",e),window.setTimeout(()=>{se(t,ae[r]),t.setAttribute("title",n),t.setAttribute("aria-label",n)},2e3)},Jt=t=>{const e=t.querySelectorAll(":not(pre) > code");for(const r of Array.from(e))r.getAttribute("data-markdown")!=="inline-code"&&r.setAttribute("data-markdown","inline-code")},Qt=(t,e)=>{const r=t.querySelectorAll("pre");for(const n of Array.from(r)){if(n.querySelector("code.language-mermaid"))continue;const a=n.parentElement;if(!a||a.closest('[data-component="markdown-code"]'))continue;const i=n.querySelector("code")?.className.match(/language-([\w+#.-]+)/)?.[1],s=n.getAttribute("data-md-lang")??i??"text",o=document.createElement("div");o.setAttribute("data-component","markdown-code"),o.className="my-4 group overflow-hidden rounded-2xl border border-border/80 bg-[var(--surface-elevated)]";const c=document.createElement("div");c.className="flex items-center justify-between border-b border-border/70 px-3 py-1.5";const l=document.createElement("span");l.className="font-mono text-[13px] text-muted-foreground",l.textContent=s;const d=W("copy",e.labels.copy,"copy-code"),p=W("textWrap",e.codeBlockLineWrap?e.labels.disableCodeWrap:e.labels.enableCodeWrap,"toggle-code-wrap");c.appendChild(l);const u=document.createElement("div");u.className="flex items-center gap-1",u.setAttribute("data-md-code-actions",""),u.appendChild(p),u.appendChild(d),c.appendChild(u);const f=document.createElement("div");f.setAttribute("data-md-code-body",""),f.className="px-3 py-2.5 overflow-x-auto",a.replaceChild(o,n),n.style.margin="0",n.style.background="transparent",n.classList.add("min-w-0","w-full","flex-1"),e.deferCodeLineNumberSync||je(n),f.appendChild(n),o.appendChild(c),o.appendChild(f),Ke(o,e.codeBlockLineWrap,e.labels)}},Se=t=>{const e=[],r=[],n=t.querySelectorAll("thead th");for(const i of Array.from(n))e.push((i.textContent??"").trim());const a=t.querySelectorAll("tbody tr");for(const i of Array.from(a)){const s=Array.from(i.querySelectorAll("td")).map(o=>(o.textContent??"").trim());s.length>0&&r.push(s)}return{headers:e,rows:r}},er=t=>/[",\n]/.test(t)?`"${t.replace(/"/g,'""')}"`:t,Le=({headers:t,rows:e})=>[t,...e].map(r=>r.map(er).join(",")).join(`
8
- `),tr=({headers:t,rows:e})=>[t,...e].map(r=>r.join(" ")).join(`
9
- `),Me=({headers:t,rows:e})=>{const r=`| ${t.join(" | ")} |`,n=`| ${t.map(()=>"---").join(" | ")} |`,a=e.map(i=>`| ${i.join(" | ")} |`).join(`
10
- `);return`${r}
11
- ${n}
12
- ${a}`},Ne=(t,e)=>{const r=document.createElement("div");r.className=`absolute top-full right-0 mt-1 hidden ${ut}`,r.style.backgroundColor="var(--surface-elevated)",r.style.color="var(--surface-elevated-foreground)",r.setAttribute("data-md-menu",t);for(const n of e){const a=document.createElement("button");a.type="button",a.className=`w-full text-left ${pt}`,a.setAttribute("data-md-action",`${t}-${n.key}`),a.textContent=n.label,r.appendChild(a)}return r},rr=(t,e)=>{const r=t.querySelectorAll("table");for(const n of Array.from(r)){if(n.closest('[data-markdown="table-wrapper"]'))continue;const i=document.createElement("div");i.className="group my-4 flex flex-col space-y-2",i.setAttribute("data-markdown","table-wrapper");const s=document.createElement("div");s.className="flex items-center justify-end gap-1";const o=document.createElement("div");o.className="relative",o.appendChild(W("copy",e.copyTable,"table-copy-toggle")),o.appendChild(Ne("table-copy",[{key:"csv",label:"CSV"},{key:"tsv",label:"TSV"},{key:"markdown",label:"Markdown"}]));const c=document.createElement("div");c.className="relative",c.appendChild(W("download",e.downloadTable,"table-download-toggle")),c.appendChild(Ne("table-download",[{key:"csv",label:"CSV"},{key:"markdown",label:"Markdown"}])),s.appendChild(o),s.appendChild(c);const l=document.createElement("div");l.className="overflow-x-auto rounded-lg border border-border/80 bg-[var(--surface-elevated)]";const d=n.parentElement;if(!d)continue;d.replaceChild(i,n),n.setAttribute("data-markdown","table"),n.classList.add("w-full","border-collapse","text-sm");for(const u of Array.from(n.querySelectorAll("tr")))u.classList.add("border-b","border-border/60");const p=n.querySelector("tbody tr:last-child");p?.classList.remove("border-b"),p?.classList.add("border-0");for(const u of Array.from(n.querySelectorAll("th")))u.classList.add("border-r","border-border/60","px-4","py-2.5","text-left","align-middle","font-semibold","text-foreground","last:border-r-0");for(const u of Array.from(n.querySelectorAll("td")))u.classList.add("border-r","border-border/60","px-4","py-2.5","align-middle","text-foreground/90","last:border-r-0");l.appendChild(n),i.appendChild(s),i.appendChild(l)}},nr=(t,e)=>{const r=t.querySelectorAll("pre > code.language-mermaid");for(const n of Array.from(r)){const a=n.parentElement;if(!a)continue;const i=(n.textContent??"").replace(/\s+$/,""),s=e.renderMermaid(i),o=document.createElement("div");o.setAttribute("data-markdown","mermaid-block"),o.setAttribute("data-md-source",i),o.className="group relative";const c=document.createElement("div");c.setAttribute("data-markdown","mermaid-scroll");const l=document.createElement("div");if(l.setAttribute("data-markdown","mermaid-toolbar"),l.className="absolute top-1 right-2 flex items-center gap-1 opacity-0 group-hover:opacity-100 group-focus-within:opacity-100 transition-opacity",s.svg){o.setAttribute("data-mermaid-render","svg");const p=document.createElement("div");p.setAttribute("data-markdown","mermaid-viewport");const u=document.createElement("div");if(u.setAttribute("data-markdown","mermaid"),u.setAttribute("data-md-original-svg",s.svg),u.innerHTML=s.svg,p.appendChild(u),c.appendChild(p),e.mermaidControls.showPanZoomControls&&(l.appendChild(W("zoomIn",e.labels.zoomInDiagram,"mermaid-zoom-in")),l.appendChild(W("zoomOut",e.labels.zoomOutDiagram,"mermaid-zoom-out")),l.appendChild(W("fit",e.labels.resetDiagramView,"mermaid-fit"))),e.mermaidControls.copy){const f=W("copy",e.labels.copyDiagram,"mermaid-copy");f.setAttribute("data-md-source",i),l.appendChild(f)}if(e.mermaidControls.download){const f=W("download",e.labels.downloadDiagram,"mermaid-download");f.setAttribute("data-md-svg","1"),l.appendChild(f)}}else{o.setAttribute("data-mermaid-render","ascii");const p=document.createElement("pre");if(p.setAttribute("data-markdown","mermaid-ascii"),p.textContent=s.ascii||i,c.appendChild(p),e.mermaidControls.copy){const u=W("copy",e.labels.copyDiagram,"mermaid-copy");u.setAttribute("data-md-source",s.ascii||i),l.appendChild(u)}}o.appendChild(c),o.appendChild(l);const d=a.parentElement;d&&d.replaceChild(o,a)}},or=(t,e)=>{const r=t.querySelectorAll("a[href]");for(const n of Array.from(r)){if(n.getAttribute("data-md-link-decorated")==="true"||n.getAttribute("data-openchamber-file-link")==="true")continue;const a=n.getAttribute("href")??"";if(!Oe(a))continue;n.setAttribute("data-md-link-decorated","true");const i=dt(a);if(i){const s=document.createElement("span");s.className="mr-1 inline-flex size-[18px] items-center justify-center rounded border border-[var(--border)] bg-[var(--interactive-hover)] align-middle";const o=document.createElement("img");o.src=i,o.alt="",o.setAttribute("aria-hidden","true"),o.loading="lazy",o.decoding="async",o.className="size-3.5 rounded-sm",o.addEventListener("error",()=>s.remove(),{once:!0}),s.appendChild(o),n.parentNode?.insertBefore(s,n)}if(e.onPreviewLoopback&&mt(a)){const s=document.createElement("button");s.type="button",s.className=`ml-1 align-middle ${He}`,s.setAttribute("data-md-action","preview-loopback"),s.setAttribute("data-md-url",a),s.setAttribute("title",e.labels.previewTitle),s.setAttribute("aria-label",e.labels.previewLabel),se(s,ae.download),n.parentNode?.insertBefore(s,n.nextSibling)}}},xe=(t,e)=>{Jt(t),nr(t,e),Qt(t,e),rr(t,e.labels),or(t,e)},Re=(t,e,r)=>{const n=new Blob([e],{type:r}),a=URL.createObjectURL(n),i=document.createElement("a");i.href=a,i.download=t,document.body.appendChild(i),i.click(),document.body.removeChild(i),URL.revokeObjectURL(a)},ne=t=>{for(const e of Array.from(t.querySelectorAll("[data-md-menu]")))e.classList.add("hidden")},ir=(t,e)=>{const r=n=>{const a=n.target;if(!(a instanceof Element))return;const i=a.closest("[data-md-action]");if(!i){ne(t);return}const s=i.getAttribute("data-md-action")??"";if(s==="copy-code"){const o=i.closest('[data-component="markdown-code"]')?.querySelector("code"),c=o?Ue(o):"";c&&le(c).then(()=>Ce(i,e.labels.copied,"copy",e.labels.copy));return}if(s==="toggle-code-wrap"){n.preventDefault(),e.onToggleCodeBlockLineWrap?.();return}if(s==="table-copy-toggle"||s==="table-download-toggle"){n.preventDefault();const o=i.parentElement?.querySelector("[data-md-menu]")??null,c=o?.classList.contains("hidden")??!1;ne(t),o&&c&&o.classList.remove("hidden");return}if(s.startsWith("table-copy-")){const o=s.replace("table-copy-",""),c=i.closest('[data-markdown="table-wrapper"]')?.querySelector("table");if(c instanceof HTMLTableElement){const l=Se(c),d=o==="csv"?Le(l):o==="tsv"?tr(l):Me(l);le(d)}ne(t);return}if(s.startsWith("table-download-")){const o=s.replace("table-download-",""),c=i.closest('[data-markdown="table-wrapper"]')?.querySelector("table");if(c instanceof HTMLTableElement){const l=Se(c),d=o==="csv"?Le(l):Me(l);Re(o==="csv"?"table.csv":"table.md",d,o==="csv"?"text/csv":"text/markdown")}ne(t);return}if(s==="mermaid-copy"){const o=i.getAttribute("data-md-source")??"";o&&le(o).then(()=>Ce(i,e.labels.copied,"copy",e.labels.copyDiagram));return}if(s==="mermaid-zoom-in"||s==="mermaid-zoom-out"||s==="mermaid-fit"){n.preventDefault();const o=i.closest('[data-markdown="mermaid-block"]'),c=Kt(o);s==="mermaid-zoom-in"?c?.zoomIn():s==="mermaid-zoom-out"?c?.zoomOut():c?.fit();return}if(s==="mermaid-download"){const o=i.closest('[data-markdown="mermaid-block"]')?.querySelector('[data-markdown="mermaid"]'),c=o?.getAttribute("data-md-original-svg")??o?.innerHTML??"";c&&Re("diagram.svg",c,"image/svg+xml;charset=utf-8");return}if(s==="preview-loopback"){n.preventDefault();const o=i.getAttribute("data-md-url")??"";o&&e.onPreviewLoopback?.(o);return}};return t.addEventListener("click",r),()=>t.removeEventListener("click",r)},_e=(t,e,r)=>{let n=0;for(const i of t){const s=n+i.data.length;if(e<s||e===s&&r==="left")return{node:i,offset:Math.max(0,e-n)};n=s}const a=t.at(-1);return a?{node:a,offset:a.data.length}:null},ar=new Set(["dockerfile","makefile","readme","license",".env",".gitignore",".npmrc"]),Te=Array.from(ar).map(t=>t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")).join("|"),sr=t=>ht(t),cr=t=>ft(t),ce=t=>{let e=(t||"").trim();return e?((e.startsWith("`")&&e.endsWith("`")||e.startsWith('"')&&e.endsWith('"')||e.startsWith("'")&&e.endsWith("'"))&&(e=e.slice(1,-1).trim()),e=e.replace(/[.,;!?]+$/g,""),e.endsWith(")")&&!e.includes("(")&&(e=e.slice(0,-1)),e.endsWith("]")&&!e.includes("[")&&(e=e.slice(0,-1)),e):""},oe=t=>{let e=ce(t);if(!e)return"";const r=e.indexOf(";");r>=0&&(e=e.slice(0,r)),e=e.replace(/#.*$/,"");const n=e.match(/^(.*\.[A-Za-z0-9_-]{1,16}):.*$/);n&&(e=n[1]??e);const a=Te.length>0?e.match(new RegExp(`^(.*(?:/|^)(${Te})):.*$`,"i")):null;return a&&(e=a[1]??e),ce(e)},Ze=t=>{const e=ce(t);if(!e)return null;const r=e.indexOf(";"),n=r>=0?ce(e.slice(0,r)):e;if(!n)return null;const a=n.match(/^(.*?):(\d+)-(\d+)$/);if(a){const c=oe(a[1]??""),l=Number.parseInt(a[2]??"",10),d=Number.parseInt(a[3]??"",10);return!c||!Number.isFinite(l)||!Number.isFinite(d)||d<l?null:{path:c,line:l,endLine:d}}const i=n.match(/^(.*)#L(\d+)(?:C(\d+))?$/i);if(i){const c=oe(i[1]??""),l=Number.parseInt(i[2]??"",10),d=i[3]?Number.parseInt(i[3],10):void 0;return!c||!Number.isFinite(l)?null:{path:c,line:l,column:Number.isFinite(d??Number.NaN)?d:void 0}}const s=n.match(/^(.*?):(\d+)(?::(\d+))?$/);if(s){const c=oe(s[1]??""),l=Number.parseInt(s[2]??"",10),d=s[3]?Number.parseInt(s[3],10):void 0;return!c||!Number.isFinite(l)?null:{path:c,line:l,column:Number.isFinite(d??Number.NaN)?d:void 0}}const o=oe(n);return o?{path:o}:null},me=/(?:[A-Za-z]:[\\/])?[\w.\-/@+]*[\w\-/@+]\.[A-Za-z0-9]{1,8}(?::\d+(?:-\d+)?(?::\d+)?)?/g,Xe=()=>{const t=V.c(4),e=gt();let r;t[0]===Symbol.for("react.memo_cache_sentinel")?(r=we(!1),t[0]=r):r=t[0];const n=r;let a;t[1]===Symbol.for("react.memo_cache_sentinel")?(a=we(!0),t[1]=a):a=t[1];const i=a;let s;return t[2]!==e?.currentTheme?(s=e?.currentTheme??(typeof window<"u"&&window.matchMedia("(prefers-color-scheme: dark)").matches?i:n),t[2]=e?.currentTheme,t[3]=s):s=t[3],s},Ge=t=>{const e=V.c(4),{containerRef:r,enabled:n}=t;let a,i;e[0]!==r||e[1]!==n?(a=()=>{if(n===!1)return;const s=r.current;if(!s)return;const o=_r;return s.addEventListener("click",o),()=>{s.removeEventListener("click",o)}},i=[r,n],e[0]=r,e[1]=n,e[2]=a,e[3]=i):(a=e[2],i=e[3]),R.useEffect(a,i)},Y={download:!0,copy:!0,showPanZoomControls:!0},Ye=!0,lr=t=>{const e=t.match(/^(?:\uFEFF)?(---|\+\+\+)[^\S\r\n]*\r?\n[\s\S]*?\r?\n\1[^\S\r\n]*(?:\r?\n|$)/);return e?t.slice(e[0].length):t},Pe='[data-openchamber-file-link="true"]',Je="data-openchamber-block-path-token",Qe=`[${Je}]`,G="data-openchamber-block-paths-scanned",dr=2e5,mr=4,ur=1e3,pr=200,fr=80,hr=40,Fe=160,B=new Map;let ie=0;const Ie=[],gr=()=>Be()?pr:ur,br=()=>Be()?hr:fr,wr=new Set(["dockerfile","makefile","readme","license",".env",".gitignore",".npmrc"]),he=t=>sr(t),yr=t=>cr(t),vr=(t,e)=>kt(t,e),Ar=t=>{const e=t.split("/").filter(Boolean).pop()??"";return!e||e.endsWith(".")?!1:/\.[A-Za-z0-9_-]{1,16}$/.test(e)},et=t=>{if(!t||t.startsWith("--")||t.includes("://")||/[<>]/.test(t)||/\s{2,}/.test(t))return!1;const e=he(t),r=e.split("/").filter(Boolean).pop()??e;if(!r||r==="."||r==="..")return!1;const n=r.toLowerCase();return wr.has(n)||n.startsWith(".")&&n.length>1?!0:Ar(e)},tt=t=>{const e=Ze(t);return e?et(e.path):!1},kr=t=>{const e=t.querySelectorAll(Qe);for(const n of Array.from(e))n.replaceWith(t.ownerDocument.createTextNode(n.textContent??""));const r=t.querySelectorAll(`code[${G}]`);for(const n of Array.from(r))n.removeAttribute(G),n.normalize()},ue=t=>{if(t.tagName.toLowerCase()==="a"){const e=t.getAttribute("href")?.trim();if(e&&tt(e))return e}return(t.textContent||"").trim()},Er=t=>{const e=t.querySelectorAll("pre code");if(e.length===0)return;const r=t.ownerDocument;if(r)for(const n of Array.from(e)){if(n.getAttribute(G)==="true")continue;if((n.textContent??"").length>dr){n.setAttribute(G,"true");continue}const a=r.createTreeWalker(n,NodeFilter.SHOW_TEXT),i=[];let s=a.nextNode();for(;s;){const d=s;d.parentElement?.closest("[data-md-code-line-number]")||i.push(d),s=a.nextNode()}const o=Ue(n);if(!o.includes(".")){n.setAttribute(G,"true");continue}me.lastIndex=0;const c=[];let l=me.exec(o);for(;l;){const d=l[0];d&&tt(d)&&c.push({start:l.index,end:l.index+d.length,raw:d}),l=me.exec(o)}for(const{start:d,end:p,raw:u}of c.reverse()){const f=_e(i,d,"right"),g=_e(i,p,"left");if(!f||!g)continue;const A=r.createRange();A.setStart(f.node,f.offset),A.setEnd(g.node,g.offset);const E=r.createElement("span");E.setAttribute(Je,"true"),E.textContent=u,A.deleteContents(),A.insertNode(E)}n.setAttribute(G,"true")}},pe=(t,e)=>{const r=Ze(t);if(!r||!et(r.path))return null;const n=yr(r.path)?he(r.path):vr(e,r.path);return n?{...r,resolvedPath:n}:null},Cr=t=>{const e=he(t);if(!e)return Promise.resolve(!1);const r=B.get(e);if(r)return B.delete(e),B.set(e,r),r;const n=new Promise(i=>{const s=()=>{ie+=1,Lt(`/api/fs/stat?path=${encodeURIComponent(e)}&optional=true`,{method:"GET",cache:"no-store"}).then(async o=>{if(!o.ok){i(!1);return}const c=await o.json().catch(()=>null);i(c?.exists!==!1)}).catch(()=>i(!1)).finally(()=>{ie=Math.max(0,ie-1),Ie.shift()?.()})};if(ie<mr){s();return}Ie.push(s)}),a=gr();for(;B.size>=a;){const i=B.keys().next().value;if(typeof i!="string")break;B.delete(i)}return B.set(e,n),n},Sr=(t,e)=>t||At(t,e),rt=t=>{const e=V.c(7),{containerRef:r,effectiveDirectory:n,editor:a,preferRuntimeEditor:i,enabled:s}=t,o=R.useRef(null);let c,l;e[0]!==r||e[1]!==a||e[2]!==n||e[3]!==s||e[4]!==i?(c=()=>{const d=r.current;if(!d)return;let p=!1;const u=br(),f=s&&!Mt(),g=Tr,A=()=>{const w=d.querySelectorAll(Pe);for(const b of Array.from(w))g(b);kr(d)};if(!f){A();return}const E=w=>{const b=w;if(o.current!==null&&typeof window<"u"&&window.clearTimeout(o.current),typeof window>"u"){y();return}o.current=window.setTimeout(()=>{o.current=null,window.requestAnimationFrame(()=>{p||y()})},b)},y=()=>{f&&Er(d);const w=d.querySelectorAll(`[data-markdown="inline-code"], a, ${Qe}`);let b=0;for(const m of Array.from(w)){const v=ue(m),k=pe(v,n);if(g(m),!k||b>=u)continue;b=b+1,(Ct()&&St()&&!ge(k.resolvedPath,n)?Promise.resolve(!0):Cr(k.resolvedPath)).then(D=>{if(p||!D||!d.contains(m))return;const I=ue(m),S=pe(I,n);!S||S.resolvedPath!==k.resolvedPath||(m.setAttribute("data-openchamber-file-link","true"),m.setAttribute("data-openchamber-file-ref",I),m.setAttribute("data-openchamber-file-path",S.resolvedPath),m.setAttribute("title","Open file"),m.tagName.toLowerCase()!=="a"&&(m.setAttribute("role","button"),m.setAttribute("tabindex","0")))})}},L=async w=>{const b=w.getAttribute("data-openchamber-file-ref")||ue(w),m=pe(b,n);if(!m)return;const v=Sr(n,m.resolvedPath);if(i&&a){a.openFile(m.resolvedPath,Number.isFinite(m.line??Number.NaN)?Math.max(1,Math.trunc(m.line)):void 0,Number.isFinite(m.column??Number.NaN)?Math.max(1,Math.trunc(m.column)):void 0);return}ge(m.resolvedPath,n)||await vt(m.resolvedPath,n);const k=X.getState();Number.isFinite(m.line??Number.NaN)?k.openContextFileAtLine(v,m.resolvedPath,Math.max(1,Math.trunc(m.line)),Number.isFinite(m.column??Number.NaN)?Math.max(1,Math.trunc(m.column)):1):k.openContextFile(v,m.resolvedPath)},M=w=>{const b=w.target;if(!(b instanceof Element))return;const m=b.closest(Pe);m instanceof HTMLElement&&(w.preventDefault(),w.stopPropagation(),L(m))},h=w=>{if(w.key!=="Enter"&&w.key!==" ")return;const b=w.target;!(b instanceof HTMLElement)||b.getAttribute("data-openchamber-file-link")!=="true"||(w.preventDefault(),w.stopPropagation(),L(b))};E(Fe);const C=new MutationObserver(()=>{E(Fe)});return C.observe(d,{childList:!0,subtree:!0}),d.addEventListener("click",M),d.addEventListener("keydown",h),()=>{p=!0,o.current!==null&&typeof window<"u"&&window.clearTimeout(o.current),o.current=null,C.disconnect(),d.removeEventListener("click",M),d.removeEventListener("keydown",h)}},l=[r,a,n,i,s],e[0]=r,e[1]=a,e[2]=n,e[3]=s,e[4]=i,e[5]=c,e[6]=l):(c=e[5],l=e[6]),R.useEffect(c,l)},nt=t=>{const e=V.c(7),{containerRef:r,onShowPopup:n,enableFullscreen:a,enablePanZoom:i,allowMermaidWheelEvents:s}=t;let o,c;e[0]!==s||e[1]!==r||e[2]!==a||e[3]!==i||e[4]!==n?(o=()=>{const l=r.current;if(!l)return;const d=u=>{if(!a||!n)return;const f=u.target;if(!(f instanceof Element)||f.closest('button, a, [role="button"]'))return;const g=f.closest(ee);if(!g)return;if(g instanceof HTMLElement&&g.hasAttribute("data-mermaid-suppress-click")){g.removeAttribute("data-mermaid-suppress-click");return}const E=Array.from(l.querySelectorAll(ee)).indexOf(g);if(E<0)return;const y=g instanceof HTMLElement?g.getAttribute("data-md-source"):null;if(!y||y.trim().length===0)return;const L=`Diagram ${E+1}`;n({open:!0,title:L,content:"",metadata:{tool:"mermaid-preview",filename:L},mermaid:{url:`data:text/plain;charset=utf-8,${encodeURIComponent(y)}`,source:y,filename:L}})},p=u=>{if(s||(u.ctrlKey||u.metaKey)&&i)return;const f=u.target;!(f instanceof Element)||!f.closest(ee)||u.stopPropagation()};return l.addEventListener("click",d),l.addEventListener("wheel",p,{capture:!0,passive:!0}),()=>{l.removeEventListener("click",d),l.removeEventListener("wheel",p,!0)}},c=[s,r,a,i,n],e[0]=s,e[1]=r,e[2]=a,e[3]=i,e[4]=n,e[5]=o,e[6]=c):(o=e[5],c=e[6]),R.useEffect(o,c)},z=new Map,Lr=100,Mr=(t,e)=>{const r=z.get(t);if(r)return z.delete(t),z.set(t,r),r;const n=e();if(z.set(t,n),z.size>Lr){const a=z.keys().next().value;a&&z.delete(a)}return n},Nr=t=>({bg:t.colors.surface.elevated,fg:t.colors.surface.foreground,line:t.colors.interactive.border,accent:t.colors.primary.base,muted:t.colors.surface.mutedForeground,surface:t.colors.surface.muted,border:t.colors.interactive.border,transparent:!0,font:"system-ui, sans-serif"}),ot=(t,e,r,n=Y)=>{const{t:a}=bt(),i=R.useMemo(()=>({copy:a("markdownRenderer.code.actions.copyTitle"),copied:a("markdownRenderer.code.actions.copiedTitle"),enableCodeWrap:a("markdownRenderer.code.actions.enableWrapTitle"),disableCodeWrap:a("markdownRenderer.code.actions.disableWrapTitle"),copyTable:a("markdownRenderer.table.actions.copyTitle"),downloadTable:a("markdownRenderer.table.actions.downloadTitle"),copyDiagram:a("markdownRenderer.mermaid.actions.copySourceTitle"),downloadDiagram:a("markdownRenderer.mermaid.actions.downloadSvgTitle"),zoomInDiagram:a("markdownRenderer.mermaid.actions.zoomInTitle"),zoomOutDiagram:a("markdownRenderer.mermaid.actions.zoomOutTitle"),resetDiagramView:a("markdownRenderer.mermaid.actions.resetViewTitle"),previewLabel:a("terminalView.preview.open"),previewTitle:a("terminalView.preview.openTitle")}),[a]),s=X(l=>l.codeBlockLineWrap),o=X(l=>l.setCodeBlockLineWrap),c=R.useCallback(()=>{o(!X.getState().codeBlockLineWrap)},[o]);return R.useMemo(()=>{const l=Nr(t),d=X.getState().mermaidRenderingMode,p=t.metadata?.id??"theme";return{labels:i,mermaidControls:n,codeBlockLineWrap:s,deferCodeLineNumberSync:e,onToggleCodeBlockLineWrap:c,renderMermaid:f=>Mr(`${p}:${d}:${f}`,()=>{try{return d==="ascii"?{ascii:ct(f)}:{svg:lt(f,l)}}catch{return{}}}),onPreviewLoopback:r}},[t,i,n,s,e,c,r])},it=t=>{const e=V.c(33),{containerRef:r,text:n,streaming:a,cacheKey:i,syntaxVars:s,ctx:o}=t;let c;e[0]===Symbol.for("react.memo_cache_sentinel")?(c=[],e[0]=c):c=e[0],R.useEffect(Pr,c);const l=R.useRef(null);let d;e[1]!==r?(d=()=>{const m=r.current;if(m){if(!l.current){if(!$(m))return;l.current=Gt(m);return}l.current.refresh()}},e[1]=r,e[2]=d):d=e[2];const p=d;let u,f;e[3]!==r||e[4]!==o||e[5]!==p||e[6]!==n?(u=()=>{const m=r.current,v=m?.querySelector("[data-markdown-content]")??m;if(v&&n&&v.childNodes.length===0){const k=document.createElement("div");k.setAttribute("data-md-block",""),k.style.display="contents",k.innerHTML=Nt(n),xe(k,o),v.appendChild(k),$(k)&&p()}},f=[r,n,o,p],e[3]=r,e[4]=o,e[5]=p,e[6]=n,e[7]=u,e[8]=f):(u=e[7],f=e[8]),R.useLayoutEffect(u,f);let g,A;e[9]===Symbol.for("react.memo_cache_sentinel")?(g=()=>()=>{l.current?.cleanup(),l.current=null},A=[],e[9]=g,e[10]=A):(g=e[9],A=e[10]),R.useEffect(g,A);let E,y;e[11]!==i||e[12]!==r||e[13]!==o||e[14]!==p||e[15]!==a||e[16]!==n?(E=()=>{const m=r.current;if(!m)return;const v=m.querySelector("[data-markdown-content]")??m;let k=!0;return xt(n,a,i).then(T=>{if(!k)return;const F=Array.from(v.children);T.forEach((S,_)=>{let N=F[_];if(N||(N=document.createElement("div"),N.setAttribute("data-md-block",""),N.style.display="contents",v.appendChild(N)),N.getAttribute("data-md-id")===S.id)return;const P=document.createElement("div");P.innerHTML=S.html,xe(P,o);const O=$(N),H=$(P);st(N,P,{childrenOnly:!0,onBeforeElUpdated:Fr}),N.setAttribute("data-md-id",S.id),(O||H||$(N))&&p()});const D=$(v);let I=!1;for(let S=F.length-1;S>=T.length;S=S-1,S){const _=F[S];_&&$(_)&&(I=!0),_?.remove()}(I||F.length>T.length&&D)&&p()}),()=>{k=!1}},y=[r,n,a,i,o,p],e[11]=i,e[12]=r,e[13]=o,e[14]=p,e[15]=a,e[16]=n,e[17]=E,e[18]=y):(E=e[17],y=e[18]),R.useEffect(E,y);let L,M;e[19]!==r||e[20]!==o?(M=()=>{const m=r.current;if(m)return ir(m,o)},L=[r,o],e[19]=r,e[20]=o,e[21]=L,e[22]=M):(L=e[21],M=e[22]),R.useEffect(M,L);let h,C;e[23]!==r||e[24]!==s?(h=()=>{const m=r.current,v=m?.querySelector("[data-markdown-content]")??m;if(v)for(const[k,T]of Object.entries(s))v.style.setProperty(k,T)},C=[r,s],e[23]=r,e[24]=s,e[25]=h,e[26]=C):(h=e[25],C=e[26]),R.useEffect(h,C);let w,b;e[27]!==r||e[28]!==o.codeBlockLineWrap||e[29]!==o.deferCodeLineNumberSync||e[30]!==o.labels?(w=()=>{const m=r.current,v=m?.querySelector("[data-markdown-content]")??m;v&&(o.deferCodeLineNumberSync||Yt(v,o.codeBlockLineWrap,o.labels))},b=[r,o.codeBlockLineWrap,o.deferCodeLineNumberSync,o.labels],e[27]=r,e[28]=o.codeBlockLineWrap,e[29]=o.deferCodeLineNumberSync,e[30]=o.labels,e[31]=w,e[32]=b):(w=e[31],b=e[32]),R.useEffect(w,b)},at=t=>t==="tool"?"markdown-content markdown-tool":t==="reasoning"?"markdown-content markdown-reasoning":"markdown-content leading-relaxed",xr=t=>{const e=V.c(32),{content:r,part:n,messageId:a,isAnimated:i,skipFadeIn:s,className:o,isStreaming:c,disableStreamAnimation:l,variant:d,onShowPopup:p,enableFileReferences:u}=t,f=i===void 0?!0:i,g=s===void 0?!1:s,A=c===void 0?!1:c,E=l===void 0?!1:l,y=d===void 0?"assistant":d,L=u===void 0?!0:u;be("ui.markdown_renderer.render"),A&&be("ui.markdown_renderer.render.streaming"),Et("ui.markdown_renderer.content_len",r.length);const M=Xe(),{editor:h,runtime:C}=De(),w=R.useRef(null),b=We()??"",m=X(Ir);let v;e[0]!==b||e[1]!==m?(v=Z=>{b&&m(b,Z)},e[0]=b,e[1]=m,e[2]=v):v=e[2];const k=v,T=A&&!E;let F;e[3]!==p?(F={containerRef:w,onShowPopup:p,enableFullscreen:Ye,enablePanZoom:Y.showPanZoomControls},e[3]=p,e[4]=F):F=e[4],nt(F);const D=L&&!A;let I;e[5]!==h||e[6]!==b||e[7]!==C.isVSCode||e[8]!==D?(I={containerRef:w,effectiveDirectory:b,editor:h,preferRuntimeEditor:C.isVSCode,enabled:D},e[5]=h,e[6]=b,e[7]=C.isVSCode,e[8]=D,e[9]=I):I=e[9],rt(I);let S;e[10]===Symbol.for("react.memo_cache_sentinel")?(S={containerRef:w},e[10]=S):S=e[10],Ge(S);let _;e[11]!==M?(_=$e(M),e[11]=M,e[12]=_):_=e[12];const N=_,P=ot(M,T,b?k:void 0,Y),O=`markdown-${n?.id?`part-${n.id}`:`message-${a}`}`;let H;e[13]!==O||e[14]!==r||e[15]!==P||e[16]!==T||e[17]!==N?(H={containerRef:w,text:r,streaming:T,cacheKey:O,syntaxVars:N,ctx:P},e[13]=O,e[14]=r,e[15]=P,e[16]=T,e[17]=N,e[18]=H):H=e[18],it(H);let K;e[19]!==o?(K=qe("break-words w-full min-w-0",o),e[19]=o,e[20]=K):K=e[20];let j;e[21]!==y?(j=at(y),e[21]=y,e[22]=j):j=e[22];let U;e[23]!==j?(U=Q.jsx("div",{className:j,"data-markdown-content":!0}),e[23]=j,e[24]=U):U=e[24];let te;e[25]!==K||e[26]!==U?(te=Q.jsx("div",{className:K,ref:w,children:U}),e[25]=K,e[26]=U,e[27]=te):te=e[27];const re=te;if(f){let Z;return e[28]!==O||e[29]!==re||e[30]!==g?(Z=Q.jsx(wt,{skipAnimation:g,children:re},O),e[28]=O,e[29]=re,e[30]=g,e[31]=Z):Z=e[31],Z}return re},Io=R.memo(xr,(t,e)=>t.content===e.content&&t.isStreaming===e.isStreaming&&t.disableStreamAnimation===e.disableStreamAnimation&&t.variant===e.variant&&t.isAnimated===e.isAnimated&&t.skipFadeIn===e.skipFadeIn&&t.className===e.className&&t.messageId===e.messageId&&t.onShowPopup===e.onShowPopup&&t.enableFileReferences===e.enableFileReferences&&t.part?.id===e.part?.id),Rr=t=>{const e=V.c(30),{content:r,className:n,variant:a,disableLinkSafety:i,stripFrontmatter:s,onShowPopup:o,mermaidControls:c,allowMermaidWheelEvents:l,enableFileReferences:d}=t,p=a===void 0?"assistant":a,u=s===void 0?!1:s,f=c===void 0?Y:c,g=l===void 0?!1:l,A=d===void 0?!0:d,{editor:E,runtime:y}=De(),L=Xe(),M=R.useRef(null),h=We()??"";let C;e[0]!==r||e[1]!==u?(C=u?lr(r):r,e[0]=r,e[1]=u,e[2]=C):C=e[2];const w=C;let b;e[3]!==g||e[4]!==f.showPanZoomControls||e[5]!==o?(b={containerRef:M,onShowPopup:o,enableFullscreen:Ye,enablePanZoom:f.showPanZoomControls,allowMermaidWheelEvents:g},e[3]=g,e[4]=f.showPanZoomControls,e[5]=o,e[6]=b):b=e[6],nt(b);let m;e[7]!==E||e[8]!==h||e[9]!==A||e[10]!==y.isVSCode?(m={containerRef:M,effectiveDirectory:h,editor:E,preferRuntimeEditor:y.isVSCode,enabled:A},e[7]=E,e[8]=h,e[9]=A,e[10]=y.isVSCode,e[11]=m):m=e[11],rt(m);const v=!i;let k;e[12]!==v?(k={containerRef:M,enabled:v},e[12]=v,e[13]=k):k=e[13],Ge(k);let T;e[14]!==L?(T=$e(L),e[14]=L,e[15]=T):T=e[15];const F=T,D=ot(L,!1,void 0,f),I=`simple:${p}`;let S;e[16]!==D||e[17]!==w||e[18]!==F||e[19]!==I?(S={containerRef:M,text:w,streaming:!1,cacheKey:I,syntaxVars:F,ctx:D},e[16]=D,e[17]=w,e[18]=F,e[19]=I,e[20]=S):S=e[20],it(S);let _;e[21]!==n?(_=qe("break-words w-full min-w-0",n),e[21]=n,e[22]=_):_=e[22];let N;e[23]!==p?(N=at(p),e[23]=p,e[24]=N):N=e[24];let P;e[25]!==N?(P=Q.jsx("div",{className:N,"data-markdown-content":!0}),e[25]=N,e[26]=P):P=e[26];let O;return e[27]!==_||e[28]!==P?(O=Q.jsx("div",{className:_,ref:M,children:P}),e[27]=_,e[28]=P,e[29]=O):O=e[29],O},Oo=R.memo(Rr,(t,e)=>{const r=t.mermaidControls??Y,n=e.mermaidControls??Y;return t.content===e.content&&t.variant===e.variant&&t.className===e.className&&t.disableLinkSafety===e.disableLinkSafety&&t.stripFrontmatter===e.stripFrontmatter&&t.onShowPopup===e.onShowPopup&&r.download===n.download&&r.copy===n.copy&&r.showPanZoomControls===n.showPanZoomControls&&t.allowMermaidWheelEvents===e.allowMermaidWheelEvents&&t.enableFileReferences===e.enableFileReferences});function _r(t){if(t.defaultPrevented||t.button!==0||t.metaKey||t.ctrlKey||t.altKey||t.shiftKey)return;const e=t.target;if(!(e instanceof Element))return;const r=e.closest("a[href]");if(!(r instanceof HTMLAnchorElement)||r.getAttribute("data-openchamber-file-link")==="true")return;const n=r.getAttribute("href")??"";Oe(n)&&(t.preventDefault(),t.stopPropagation(),yt(n))}function Tr(t){t.removeAttribute("data-openchamber-file-link"),t.removeAttribute("data-openchamber-file-ref"),t.removeAttribute("data-openchamber-file-path"),t.getAttribute("title")==="Open file"&&t.removeAttribute("title"),t.tagName.toLowerCase()!=="a"&&(t.removeAttribute("role"),t.removeAttribute("tabindex"))}function Pr(){Tt()}function Fr(t,e){return!t.isEqualNode(e)}function Ir(t){return t.openContextPreview}export{Io as MarkdownRenderer,Oo as SimpleMarkdownRenderer};
@@ -1 +0,0 @@
1
- import{r as _,j as e,R as i,f as J}from"./vendor-react-BUCujlKS.js";import{I as V,b$ as we,b_ as le,bY as Y,x as $,af as M,cR as je,r as W,N as ue,aq as me,K as pe,J as ne}from"./index-CNrN5qDs.js";import{f as Q,B as L,R as q,aP as he,g as re,I as A}from"./useAppFontEffects-Bbpz77To.js";import"./vendor-scheduler-7OC5HNn7.js";import"./vendor-vite-runtime-DD1OZmLC.js";import"./vendor-opencode-sdk-BJ73u-bH.js";import"./vendor-zustand-BAGL70zf.js";import"./vendor-simplewebauthn-browser-VDA66rT_.js";import"./vendor-base-ui-D_V6hAcE.js";import"./vendor-floating-ui-utils-BzXdqYpP.js";import"./vendor-floating-ui-dom-WyXykhNi.js";import"./vendor-floating-ui-core-CXmKXOXc.js";import"./vendor-floating-ui-react-dom-DKpLs02S.js";import"./vendor-use-sync-external-store-D6wYuSt-.js";import"./contextPanelEmbeddedChat-5VGWIT_J.js";import"./vendor-class-variance-authority-5VPnzWs2.js";import"./vendor-clsx-B-dksMZM.js";import"./vendor-dnd-kit-core-BZknOX2w.js";import"./vendor-dnd-kit-utilities-B_MdXhJC.js";import"./vendor-dnd-kit-accessibility-BHxJPORy.js";import"./vendor-dnd-kit-sortable-CsEagZ81.js";import"./vendor-cmdk-DgLInKvT.js";import"./vendor-radix-ui-react-dialog-B94Bt2qq.js";import"./vendor-radix-ui-primitive-Dc_FVRD7.js";import"./vendor-radix-ui-react-compose-refs-DcAh5WdT.js";import"./vendor-radix-ui-react-context-Czxm7Z62.js";import"./vendor-radix-ui-react-id-f5BLKEVw.js";import"./vendor-radix-ui-react-use-layout-effect-D_3IhJdJ.js";import"./vendor-radix-ui-react-use-controllable-state-BFT5YmkA.js";import"./vendor-radix-ui-react-dismissable-layer-D7kXcwgJ.js";import"./vendor-radix-ui-react-primitive-DhVoX9SD.js";import"./vendor-radix-ui-react-slot-BQgQOasS.js";import"./vendor-radix-ui-react-use-callback-ref-BZPnuXAC.js";import"./vendor-radix-ui-react-use-escape-keydown-oph88g-F.js";import"./vendor-radix-ui-react-focus-scope-CiaxW4dD.js";import"./vendor-radix-ui-react-portal-BMJYHWck.js";import"./vendor-radix-ui-react-presence-CNxf-uq4.js";import"./vendor-radix-ui-react-focus-guards-B6qJXYua.js";import"./vendor-react-remove-scroll-DO7dCTnK.js";import"./vendor-tslib-De9GV7Vy.js";import"./vendor-react-remove-scroll-bar-BcFYyj3E.js";import"./vendor-react-style-singleton-q6EMHnwf.js";import"./vendor-get-nonce-C-Z93AgS.js";import"./vendor-use-sidecar-zDC0RhA3.js";import"./vendor-use-callback-ref-D3RC8gqK.js";import"./vendor-aria-hidden-DvXkyWUv.js";import"./vendor-codemirror-language-DUOssd4j.js";import"./vendor-lezer-common-B3-cUCR_.js";import"./vendor-codemirror-state-CNWM3Q8V.js";import"./vendor-marijn-find-cluster-break-DXwl3gUT.js";import"./vendor-codemirror-view-DSzLbZiS.js";import"./vendor-style-mod-NZ5MEPvj.js";import"./vendor-w3c-keyname-Vcq4gwWv.js";import"./vendor-crelt-C8TCjufn.js";import"./vendor-lezer-highlight-CDMHUZ74.js";import"./vendor-codemirror-lang-javascript-Bbw3D7r0.js";import"./vendor-lezer-javascript-D7Tj24ot.js";import"./vendor-lezer-lr-bhwg1HMg.js";import"./vendor-codemirror-autocomplete-BjbBRsUA.js";import"./vendor-codemirror-lang-json-ryCw7nab.js";import"./vendor-lezer-json-Iaex0UN-.js";import"./vendor-codemirror-lang-css-VgNqFSH-.js";import"./vendor-lezer-css-C5xB6jxd.js";import"./vendor-codemirror-lang-html-B3Qe3OpS.js";import"./vendor-lezer-html-C0I1p52t.js";import"./vendor-codemirror-lang-markdown-FGQydhTc.js";import"./vendor-lezer-markdown-C6g-d6P3.js";import"./vendor-codemirror-language-data-Dzt9rWZZ.js";import"./vendor-codemirror-lang-python-N414WYK-.js";import"./vendor-lezer-python-CvuFxeZl.js";import"./vendor-codemirror-commands-ARAOgp1x.js";import"./vendor-tanstack-react-virtual-g05Cx3z9.js";import"./vendor-tanstack-virtual-core-Dubg10g5.js";import"./vendor-framer-motion-CRSgBxjL.js";import"./vendor-motion-dom-DJLgZh4Q.js";import"./vendor-motion-utils-BGh8QBgx.js";import"./vendor-sonner-DFyL3AvE.js";import"./vendor-tailwind-merge-CPcsbTWB.js";import"./vendor-fuse.js-Dw8P0qyA.js";function ke(a){switch(a){case"ok":return null;case"auth":return"onboarding.remoteConnection.probe.authMessage";case"update-recommended":return"onboarding.remoteConnection.probe.updateRecommendedMessage";case"incompatible":return"onboarding.remoteConnection.probe.incompatibleMessage";case"wrong-service":return"onboarding.remoteConnection.probe.wrongServiceMessage";case"unreachable":return"onboarding.remoteConnection.probe.unreachableMessage";default:return null}}function oe(a){return a==="wrong-service"||a==="unreachable"||a==="incompatible"}function xe({onBack:a,showBackButton:t=!0,initialUrl:s="",initialLabel:r="",isRecoveryMode:n=!1,onConnect:l,onSwitchToLocal:u,showInstancePicker:h=!1}){const{t:o}=Q(),[w,S]=_.useState(s),[j,U]=_.useState(r),[K,x]=_.useState("idle"),[m,k]=_.useState(null),[C,g]=_.useState(""),[T,I]=_.useState([]),[y,f]=_.useState(()=>h?"instances":"add"),[b,R]=_.useState("");_.useEffect(()=>{h&&V().then(p=>I(p.hosts)).catch(p=>{g(p instanceof Error?p.message:String(p))})},[h]);const N=we(w),E=N?.persistedUrl??null,F=_.useCallback(p=>{S(p.target.value),x("idle"),k(null),g("")},[]),O=_.useCallback(p=>{U(p.target.value)},[]),c=_.useCallback(async()=>{if(E){x("testing"),k(null),g("");try{const p=await le(E);k(p),x(p.status==="ok"||p.status==="update-recommended"?"success":"error")}catch(p){g(p instanceof Error?p.message:o("onboarding.remoteConnection.errors.connectionTestFailed")),x("error")}}},[E,o]),D=_.useCallback(async()=>{if(!N)return;const p=N.persistedUrl;x("testing"),k(null),g("");try{const H=await le(p);if(k(H),oe(H.status)){x("error");return}const Z=await V(),ye=j.trim()||p,ee=Z.hosts.find(X=>X.url===p),te=ee?ee.id:`host-${Date.now().toString(16)}`,ie={id:te,label:ye,url:p,apiUrl:p},ve=ee?Z.hosts.map(X=>X.id===te?ie:X):[...Z.hosts,ie];if(await Y({hosts:ve,defaultHostId:te,initialHostChoiceCompleted:!0}),l?.(),N.redeemUrl){window.location.assign(N.redeemUrl);return}$()&&await M()}catch(H){g(H instanceof Error?H.message:o("onboarding.remoteConnection.errors.failedToSaveConnection")),x("error")}},[N,j,l,o]),B=_.useCallback(async p=>{const H=await V();await Y({hosts:H.hosts,defaultHostId:p,initialHostChoiceCompleted:!0}),await M()},[]),d=_.useCallback(async()=>{x("testing"),g("");try{const p=await V(),H=await je(b,p.hosts);await Y({hosts:H.hosts,defaultHostId:H.hostId,initialHostChoiceCompleted:!0}),await M()}catch(p){g(p instanceof Error&&p.message==="invalid-connect-link"?o("settings.remoteInstances.direct.error.invalidConnectLink"):o("onboarding.remoteConnection.errors.failedToSaveConnection")),x("error")}},[b,o]),v=K==="testing",P=E!==null&&!v,z=E!==null&&!v&&!oe(m?.status??null),G=ke(m?.status??null),fe=m?.status==="ok",be=m?.status==="update-recommended",ge=m?.status==="auth",ae=oe(m?.status??null);return h&&y==="instances"?e.jsx("div",{className:"flex flex-col items-center justify-center h-full p-8",children:e.jsxs("div",{className:"w-full max-w-md space-y-6",children:[e.jsxs("div",{className:"space-y-2 text-center",children:[e.jsx("h1",{className:"typography-ui-header text-xl font-semibold text-foreground",children:o("desktopHostSwitcher.actions.switchInstance")}),e.jsx("p",{className:"text-muted-foreground text-sm",children:o("settings.remoteInstances.direct.description")})]}),C?e.jsx("div",{className:"text-sm text-[var(--status-error)]",children:C}):null,e.jsx("div",{className:"space-y-2",children:T.length===0?e.jsx("div",{className:"py-4 text-center text-sm text-muted-foreground",children:o("settings.remoteInstances.direct.state.empty")}):T.map(p=>e.jsx(L,{variant:"outline",className:"w-full justify-start",onClick:()=>{B(p.id)},children:e.jsx("span",{className:"min-w-0 truncate",children:p.label})},p.id))}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(L,{variant:"outline",className:"flex-1",onClick:()=>f("import"),children:o("settings.remoteInstances.direct.import.action")}),e.jsx(L,{className:"flex-1",onClick:()=>f("add"),children:o("settings.remoteInstances.direct.actions.add")})]})]})}):h&&y==="import"?e.jsx("div",{className:"flex flex-col items-center justify-center h-full p-8",children:e.jsxs("div",{className:"w-full max-w-md space-y-6",children:[e.jsx(L,{variant:"ghost",onClick:()=>f("instances"),className:"p-0 text-muted-foreground",children:o("onboarding.common.actions.back")}),e.jsxs("div",{className:"space-y-2 text-center",children:[e.jsx("h1",{className:"typography-ui-header text-xl font-semibold text-foreground",children:o("settings.remoteInstances.direct.import.action")}),e.jsx("p",{className:"text-muted-foreground text-sm",children:o("settings.remoteInstances.direct.import.description")})]}),e.jsx(q,{value:b,onChange:p=>R(p.target.value),placeholder:o("settings.remoteInstances.direct.import.placeholder"),disabled:v,autoFocus:!0}),C?e.jsx("div",{className:"text-sm text-[var(--status-error)]",children:C}):null,e.jsx(L,{onClick:()=>{d()},disabled:v||!b.trim(),children:o("settings.remoteInstances.direct.import.action")})]})}):e.jsx("div",{className:"flex flex-col items-center justify-center h-full p-8",children:e.jsxs("div",{className:"w-full max-w-md space-y-6",children:[(t||h)&&e.jsx("div",{className:"flex items-center",children:e.jsx(L,{variant:"ghost",onClick:h?()=>f("instances"):a,className:"p-0 text-muted-foreground hover:text-foreground",children:o("onboarding.common.actions.back")})}),e.jsxs("div",{className:"space-y-2 text-center",children:[e.jsx("h1",{className:"typography-ui-header text-xl font-semibold text-foreground",children:o(n?"onboarding.remoteConnection.titleRecovery":"onboarding.remoteConnection.title")}),e.jsx("p",{className:"text-muted-foreground text-sm",children:o("onboarding.remoteConnection.description")})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{htmlFor:"remote-url",className:"text-sm text-foreground",children:o("onboarding.remoteConnection.field.serverAddress")}),e.jsx(q,{id:"remote-url",type:"url",value:w,onChange:F,placeholder:o("onboarding.remoteConnection.field.serverAddressPlaceholder"),disabled:v})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{htmlFor:"remote-label",className:"text-sm text-foreground",children:o("onboarding.remoteConnection.field.nameOptional")}),e.jsx(q,{id:"remote-label",type:"text",value:j,onChange:O,placeholder:o("onboarding.remoteConnection.field.namePlaceholder"),disabled:v})]})]}),m&&fe&&e.jsx("div",{className:"rounded-lg border p-3 text-sm",style:{borderColor:"var(--status-success)",color:"var(--status-success)"},children:o("onboarding.remoteConnection.status.connectedSuccessfully",{latencyMs:m.latencyMs})}),m&&ge&&e.jsx("div",{className:"rounded-lg border p-3 text-sm",style:{borderColor:"var(--status-warning)",color:"var(--status-warning)"},children:o("onboarding.remoteConnection.status.authWarning")}),m&&be&&e.jsx("div",{className:"rounded-lg border p-3 text-sm",style:{borderColor:"var(--status-warning)",color:"var(--status-warning)"},children:G?o(G):null}),m&&ae&&e.jsxs("div",{className:"rounded-lg border p-3 text-sm space-y-3",style:{borderColor:"var(--status-error)",color:"var(--status-error)"},children:[e.jsxs("div",{children:[e.jsx("div",{className:"font-semibold mb-1",children:o("onboarding.remoteConnection.status.connectionFailed")}),e.jsx("div",{className:"opacity-90",children:G?o(G):null})]}),e.jsx("div",{className:"text-xs opacity-80",children:m.status==="unreachable"?o("onboarding.remoteConnection.status.suggestionsUnreachable"):o("onboarding.remoteConnection.status.suggestionsWrongService")})]}),C&&e.jsx("div",{className:"rounded-lg border p-3 text-sm",style:{borderColor:"var(--status-error)",color:"var(--status-error)"},children:C}),e.jsxs("div",{className:"flex gap-3",children:[e.jsx(L,{variant:"outline",onClick:c,disabled:!P,children:o(v?"onboarding.remoteConnection.actions.testing":"onboarding.remoteConnection.actions.testConnection")}),e.jsx(L,{onClick:D,disabled:!z,children:o("onboarding.remoteConnection.actions.connectAndRestart")})]}),ae&&e.jsxs("div",{className:"flex flex-col gap-2 pt-2 border-t border-border",children:[e.jsx("div",{className:"text-xs text-muted-foreground text-center",children:o("onboarding.remoteConnection.actions.whatToDo")}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(L,{variant:"outline",size:"sm",onClick:a,className:"flex-1",children:o("onboarding.remoteConnection.actions.chooseDifferentServer")}),!n&&u&&e.jsx(L,{variant:"outline",size:"sm",onClick:u,className:"flex-1",children:o("onboarding.remoteConnection.actions.useLocalInstead")})]})]})]})})}const Ce="curl -fsSL https://opencode.ai/install | bash",Ne="https://opencode.ai/docs",ce=2500;function Se(a){const t=J.c(5),{onCopy:s,copyTitle:r}=a;let n;t[0]===Symbol.for("react.memo_cache_sentinel")?(n=e.jsxs("code",{className:"flex-1 text-left overflow-x-auto whitespace-nowrap",children:[e.jsx("span",{style:{color:"var(--syntax-keyword)"},children:"curl"}),e.jsx("span",{className:"text-muted-foreground",children:" -fsSL "}),e.jsx("span",{style:{color:"var(--syntax-string)"},children:"https://opencode.ai/install"}),e.jsx("span",{className:"text-muted-foreground",children:" | "}),e.jsx("span",{style:{color:"var(--syntax-keyword)"},children:"bash"})]}),t[0]=n):n=t[0];let l;t[1]===Symbol.for("react.memo_cache_sentinel")?(l=e.jsx(A,{name:"file-copy",className:"h-4 w-4"}),t[1]=l):l=t[1];let u;return t[2]!==r||t[3]!==s?(u=e.jsxs("div",{className:"flex items-center justify-between gap-3 w-full",children:[n,e.jsx("button",{onClick:s,className:"inline-flex items-center text-muted-foreground hover:text-foreground transition-colors shrink-0",title:r,"aria-label":r,children:l})]}),t[2]=r,t[3]=s,t[4]=u):u=t[4],u}function Re({onCliAvailable:a,localAvailable:t=!0}){const{t:s}=Q(),[r,n]=i.useState(!1),[l,u]=i.useState(!1),[h,o]=i.useState(!1),[w,S]=i.useState(!1),[j,U]=i.useState(""),[K,x]=i.useState("unknown"),[m,k]=i.useState(()=>t?"local":"remote"),[C,g]=i.useState(!1),[T,I]=i.useState(!1);i.useEffect(()=>{u($())},[]),i.useEffect(()=>{if(typeof navigator>"u"){x("unknown");return}const d=navigator.userAgent||"";/Windows/i.test(d)?x("windows"):/Macintosh|Mac OS X/i.test(d)?x("macos"):/Linux/i.test(d)?x("linux"):x("unknown")},[]),i.useEffect(()=>{let d=!1;return(async()=>{try{const v=await W("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});if(!v.ok)return;const P=await v.json().catch(()=>null);if(!P||d)return;const z=typeof P.opencodeBinary=="string"?P.opencodeBinary.trim():"";z&&U(z)}catch{}})(),()=>{d=!0}},[]);const y=i.useCallback(async d=>{const v=d.target;v.closest(".app-region-no-drag")||v.closest("button, a, input, select, textarea, code, summary, details")||d.button===0&&l&&await ue()},[l]),f=i.useCallback(async()=>{try{const d=await W("/health");if(!d.ok)return!1;const v=await d.json();return v.openCodeRunning===!0||v.isOpenCodeReady===!0}catch{return!1}},[]),b=i.useCallback(async d=>{if(!l)return;const v=await V();await Y({...v,...d==="local"?{defaultHostId:"local"}:{},initialHostChoiceCompleted:!0})},[l]),R=i.useCallback(async()=>{l&&await b("local"),a?.()},[l,a,b]);i.useEffect(()=>{if(!t||m!=="local")return;let d=!1,v=null;const P=async()=>{if(!d){try{const z=await f();if(d)return;if(z){await R();return}}catch{}d||(v=setTimeout(P,ce))}};return v=setTimeout(P,ce),()=>{d=!0,v&&clearTimeout(v)}},[m,f,R,t]);const N=i.useCallback(async()=>{S(!0);try{await f()&&await R()}finally{S(!1)}},[f,R]),E=i.useCallback(async()=>{if(!(typeof window>"u")&&l)try{const d=await me();d.success&&d.path&&d.path.trim().length>0&&U(d.path.trim())}catch{}},[l]),F=i.useCallback(async()=>{o(!0);try{if(await pe({opencodeBinary:j.trim()}),l){await b("local"),await M();return}await W("/api/config/reload",{method:"POST"})}finally{setTimeout(()=>o(!1),1e3)}},[l,j,b]),O=i.useCallback(async()=>{const d=await he(Ce);d.ok?(n(!0),setTimeout(()=>n(!1),2e3)):console.error("Failed to copy:",d.error)},[]),c=Ne,D=K==="windows"?"C:\\Users\\you\\AppData\\Roaming\\npm\\opencode.cmd":K==="linux"?"/home/you/.bun/bin/opencode":"/Users/you/.bun/bin/opencode",B=t&&(!l||m==="local");return e.jsx("div",{className:"app-region-drag h-full flex items-center justify-center bg-transparent p-8 cursor-default select-none overflow-y-auto",onMouseDown:y,children:e.jsxs("div",{className:"w-full max-w-md space-y-7",children:[e.jsxs("header",{className:"text-center space-y-1.5",children:[e.jsx("h1",{className:"text-2xl font-semibold tracking-tight text-foreground",children:s("onboarding.chooser.title")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:s("onboarding.chooser.description")})]}),l&&t&&e.jsxs("div",{className:"app-region-no-drag flex gap-1.5",children:[e.jsx("button",{type:"button",className:re("flex-1 px-4 py-2 rounded-lg border transition-colors text-sm",m==="local"?"border-[var(--interactive-selection)] text-foreground bg-[var(--interactive-selection)]/10":"border-border text-muted-foreground hover:text-foreground hover:border-muted-foreground"),onClick:()=>k("local"),children:s("onboarding.chooser.tabs.localInstall")}),e.jsx("button",{type:"button",className:re("flex-1 px-4 py-2 rounded-lg border transition-colors text-sm",m==="remote"?"border-[var(--interactive-selection)] text-foreground bg-[var(--interactive-selection)]/10":"border-border text-muted-foreground hover:text-foreground hover:border-muted-foreground"),onClick:()=>k("remote"),children:s("onboarding.chooser.tabs.connectRemote")})]}),l&&m==="remote"?e.jsx("div",{className:"app-region-no-drag",children:e.jsx(xe,{onBack:()=>t&&k("local"),showBackButton:!1,showInstancePicker:!t,onSwitchToLocal:t?()=>k("local"):void 0})}):null,B&&e.jsxs("div",{className:"space-y-4",children:[K==="windows"&&e.jsxs("div",{className:"rounded-lg border border-border bg-background/50 p-4",children:[e.jsx("div",{className:"text-sm text-foreground",children:s("onboarding.localSetup.windows.title")}),e.jsxs("ol",{className:"mt-2 list-decimal space-y-1 pl-5 text-sm text-muted-foreground",children:[e.jsx("li",{children:s("onboarding.localSetup.windows.stepRunInstallInWsl")}),e.jsx("li",{children:s("onboarding.localSetup.windows.stepSetBinaryPath")})]})]}),e.jsx("p",{className:"text-sm text-muted-foreground text-center leading-relaxed",children:s("onboarding.localSetup.intro")}),e.jsx("div",{className:"app-region-no-drag rounded-lg border border-border bg-background/60 backdrop-blur-sm px-4 py-3 font-mono text-sm",children:r?e.jsxs("div",{className:"flex items-center gap-2",style:{color:"var(--status-success)"},children:[e.jsx(A,{name:"check",className:"h-4 w-4"}),s("onboarding.common.status.copiedToClipboard")]}):e.jsx(Se,{onCopy:O,copyTitle:s("onboarding.common.copyToClipboard")})}),e.jsxs("div",{className:"app-region-no-drag flex items-center justify-between",children:[e.jsxs("a",{href:c,target:"_blank",rel:"noopener noreferrer",className:"text-xs text-muted-foreground hover:text-foreground transition-colors inline-flex items-center gap-1",children:[s(K==="windows"?"onboarding.localSetup.docs.windows":"onboarding.localSetup.docs.default"),e.jsx(A,{name:"external-link",className:"h-3 w-3"})]}),e.jsx("button",{type:"button",onClick:N,disabled:w,className:"text-xs text-muted-foreground hover:text-foreground transition-colors disabled:opacity-50",children:s(w?"onboarding.localSetup.actions.checking":"onboarding.localSetup.actions.checkNow")})]}),e.jsxs("div",{className:"rounded-lg border px-4 py-3 flex items-center gap-3",style:{borderColor:"color-mix(in srgb, var(--primary-base) 20%, transparent)",backgroundColor:"color-mix(in srgb, var(--primary-base) 6%, transparent)"},role:"status","aria-live":"polite",children:[e.jsxs("span",{className:"relative inline-flex h-2.5 w-2.5 shrink-0","aria-hidden":!0,children:[e.jsx("span",{className:"absolute inset-0 rounded-full",style:{backgroundColor:"var(--primary-base)",animation:"pulse-opacity 1.6s ease-in-out infinite"}}),e.jsx("span",{className:"absolute inset-[-4px] rounded-full",style:{backgroundColor:"var(--primary-base)",animation:"pulse-opacity-dim 1.6s ease-in-out infinite",opacity:0}})]}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"text-sm text-foreground leading-tight",children:s("onboarding.localSetup.status.watching")}),e.jsx("div",{className:"text-xs text-muted-foreground leading-tight mt-0.5",children:s("onboarding.localSetup.status.autoContinue")})]})]}),e.jsxs("details",{className:"app-region-no-drag group rounded-lg border border-border/60 px-4 open:bg-background/40 transition-colors",open:C,onToggle:d=>g(d.currentTarget.open),children:[e.jsxs("summary",{className:"flex items-center justify-between cursor-pointer py-2.5 text-sm text-muted-foreground hover:text-foreground transition-colors list-none [&::-webkit-details-marker]:hidden",children:[e.jsx("span",{children:s("onboarding.localSetup.advanced.title")}),e.jsx(A,{name:"arrow-down-s",className:"h-4 w-4 transition-transform group-open:rotate-180"})]}),e.jsxs("div",{className:"pb-4 space-y-2",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsx(q,{value:j,onChange:d=>U(d.target.value),placeholder:D,disabled:h,className:"flex-1 font-mono text-xs"}),e.jsx(L,{type:"button",variant:"secondary",size:"sm",onClick:E,disabled:h||!l,children:s("onboarding.localSetup.actions.browse")}),e.jsx(L,{type:"button",size:"sm",onClick:F,disabled:h||!j.trim(),children:s("onboarding.localSetup.actions.apply")})]}),e.jsx("p",{className:"text-xs text-muted-foreground/70",children:s("onboarding.localSetup.helper.saveAndReload")})]})]}),e.jsxs("details",{className:"app-region-no-drag group rounded-lg border border-border/60 px-4 open:bg-background/40 transition-colors",open:T,onToggle:d=>I(d.currentTarget.open),children:[e.jsxs("summary",{className:"flex items-center justify-between cursor-pointer py-2.5 text-sm text-muted-foreground hover:text-foreground transition-colors list-none [&::-webkit-details-marker]:hidden",children:[e.jsx("span",{children:s("onboarding.localSetup.troubleshoot.title")}),e.jsx(A,{name:"arrow-down-s",className:"h-4 w-4 transition-transform group-open:rotate-180"})]}),e.jsx("ul",{className:"pb-4 space-y-1.5 text-xs text-muted-foreground list-disc pl-4",children:K==="windows"?e.jsx(e.Fragment,{children:e.jsx("li",{children:s("onboarding.localSetup.windows.hintDetectionFailed")})}):e.jsxs(e.Fragment,{children:[e.jsx("li",{children:s("onboarding.localSetup.hint.ensurePath")}),e.jsx("li",{children:s("onboarding.localSetup.hint.setEnv")}),e.jsx("li",{children:s("onboarding.localSetup.hint.missingRuntime")})]})})]})]})]})})}const Le="curl -fsSL https://opencode.ai/install | bash",Ue="https://opencode.ai/docs";function Te(a){const t=J.c(5),{onCopy:s,copyTitle:r}=a;let n;t[0]===Symbol.for("react.memo_cache_sentinel")?(n=e.jsxs("code",{children:[e.jsx("span",{style:{color:"var(--syntax-keyword)"},children:"curl"}),e.jsx("span",{className:"text-muted-foreground",children:" -fsSL "}),e.jsx("span",{style:{color:"var(--syntax-string)"},children:"https://opencode.ai/install"}),e.jsx("span",{className:"text-muted-foreground",children:" | "}),e.jsx("span",{style:{color:"var(--syntax-keyword)"},children:"bash"})]}),t[0]=n):n=t[0];let l;t[1]===Symbol.for("react.memo_cache_sentinel")?(l=e.jsx(A,{name:"file-copy",className:"h-4 w-4"}),t[1]=l):l=t[1];let u;return t[2]!==r||t[3]!==s?(u=e.jsxs("div",{className:"flex items-center justify-center gap-3",children:[n,e.jsx("button",{onClick:s,className:"inline-flex items-center text-muted-foreground hover:text-foreground transition-colors",title:r,children:l})]}),t[2]=r,t[3]=s,t[4]=u):u=t[4],u}const Ke=3e4;function Ie({onBack:a,onCliAvailable:t,isFromRecovery:s=!1,onSwitchToRemote:r}){const{t:n}=Q(),[l,u]=i.useState(!1),[h,o]=i.useState(!1),[w,S]=i.useState(!1),[j,U]=i.useState(!1),[K,x]=i.useState(!1),[m,k]=i.useState(null),[C,g]=i.useState(""),[T,I]=i.useState("unknown");i.useEffect(()=>{const c=setTimeout(()=>o(!0),Ke);return()=>clearTimeout(c)},[]),i.useEffect(()=>{S($())},[]),i.useEffect(()=>{if(typeof navigator>"u"){I("unknown");return}const c=navigator.userAgent||"";if(/Windows/i.test(c)){I("windows");return}if(/Macintosh|Mac OS X/i.test(c)){I("macos");return}if(/Linux/i.test(c)){I("linux");return}I("unknown")},[]),i.useEffect(()=>{let c=!1;return(async()=>{try{const D=await W("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});if(!D.ok)return;const B=await D.json().catch(()=>null);if(!B||c)return;const d=typeof B.opencodeBinary=="string"?B.opencodeBinary.trim():"";d&&g(d)}catch{}})(),()=>{c=!0}},[]);const y=i.useCallback(async c=>{c.target.closest("button, a, input, select, textarea, code")||c.button===0&&w&&await ue()},[w]),f=i.useCallback(async()=>{try{const c=await W("/health");if(!c.ok)return!1;const D=await c.json();return D.openCodeRunning===!0||D.isOpenCodeReady===!0}catch{return!1}},[]),b=i.useCallback(async()=>{if(!(typeof window>"u")&&w)try{const c=await me();c.success&&c.path&&c.path.trim().length>0&&g(c.path.trim())}catch{}},[w]),R=i.useCallback(async()=>{U(!0);try{if(await pe({opencodeBinary:C.trim()}),w){await M();return}await W("/api/config/reload",{method:"POST"})}finally{setTimeout(()=>U(!1),1e3)}},[w,C]),N=i.useCallback(async()=>{const c=await he(Le);c.ok?(u(!0),setTimeout(()=>u(!1),2e3)):console.error("Failed to copy:",c.error)},[]),E=i.useCallback(async()=>{x(!0),k(null);try{await f()?t?.():k(n("onboarding.localSetup.errors.cliNotReady"))}catch(c){k(c instanceof Error?c.message:n("onboarding.localSetup.errors.detectionFailed"))}finally{x(!1)}},[f,t,n]),F=Ue,O=T==="windows"?"C:\\Users\\you\\AppData\\Roaming\\npm\\opencode.cmd":T==="linux"?"/home/you/.bun/bin/opencode":"/Users/you/.bun/bin/opencode";return e.jsxs("div",{className:"h-full flex items-center justify-center bg-transparent p-8 relative cursor-default select-none",onMouseDown:y,children:[e.jsxs("div",{className:"w-full max-w-lg space-y-4 text-center",children:[e.jsx("div",{className:"flex items-center",children:e.jsx(L,{variant:"ghost",onClick:a,className:"p-0 text-muted-foreground hover:text-foreground",children:n("onboarding.common.actions.back")})}),e.jsxs("div",{className:"space-y-4",children:[e.jsx("h1",{className:"text-3xl font-semibold tracking-tight text-foreground",children:n("onboarding.localSetup.title")}),e.jsx("p",{className:"text-muted-foreground",children:n("onboarding.localSetup.description")})]}),T==="windows"&&e.jsxs("div",{className:"mx-auto max-w-2xl rounded-lg border border-border bg-background/50 p-4 text-left",children:[e.jsx("div",{className:"text-sm text-foreground",children:n("onboarding.localSetup.windows.title")}),e.jsxs("ol",{className:"mt-2 list-decimal space-y-1 pl-5 text-sm text-muted-foreground",children:[e.jsx("li",{children:n("onboarding.localSetup.windows.stepRunInstallInWsl")}),e.jsx("li",{children:n("onboarding.localSetup.windows.stepSetBinaryPath")})]})]}),e.jsx("div",{className:"flex justify-center",children:e.jsx("div",{className:"bg-background/60 backdrop-blur-sm border border-border rounded-lg px-5 py-3 font-mono text-sm w-fit",children:l?e.jsxs("div",{className:"flex items-center justify-center gap-2",style:{color:"var(--status-success)"},children:[e.jsx(A,{name:"check",className:"h-4 w-4"}),n("onboarding.common.status.copiedToClipboard")]}):e.jsx(Te,{onCopy:N,copyTitle:n("onboarding.common.copyToClipboard")})})}),e.jsxs("a",{href:F,target:"_blank",rel:"noopener noreferrer",className:"text-sm text-muted-foreground hover:text-foreground transition-colors inline-flex items-center gap-1 justify-center",children:[n(T==="windows"?"onboarding.localSetup.docs.windows":"onboarding.localSetup.docs.default"),e.jsx(A,{name:"external-link",className:"h-3 w-3"})]}),m&&e.jsx("div",{className:"mx-auto max-w-md rounded-lg border border-destructive/50 bg-destructive/10 p-3 text-sm text-destructive",children:m}),e.jsxs("div",{className:"space-y-3",children:[e.jsx(L,{type:"button",onClick:E,disabled:K,className:"w-full max-w-xs",size:"lg",children:n(K?"onboarding.localSetup.actions.checking":"onboarding.localSetup.actions.checkAndContinue")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:n("onboarding.localSetup.helper.checkAndContinue")})]}),e.jsx("div",{className:"mx-auto w-full max-w-xl pt-4",children:e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"text-sm text-muted-foreground",children:n("onboarding.localSetup.field.alreadyInstalled")}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(q,{value:C,onChange:c=>g(c.target.value),placeholder:O,disabled:j,className:"flex-1 font-mono text-xs"}),e.jsx(L,{type:"button",variant:"secondary",onClick:b,disabled:j||!w,children:n("onboarding.localSetup.actions.browse")}),e.jsx(L,{type:"button",onClick:R,disabled:j,children:n("onboarding.localSetup.actions.apply")})]}),e.jsx("div",{className:"text-xs text-muted-foreground/70",children:n("onboarding.localSetup.helper.saveAndReload")})]})}),s&&r&&e.jsxs("div",{className:"text-center pt-4",children:[e.jsx("p",{className:"text-sm text-muted-foreground mb-2",children:n("onboarding.localSetup.remotePreference")}),e.jsx(L,{variant:"link",onClick:r,children:n("onboarding.localSetup.actions.connectRemoteServer")})]})]}),h&&e.jsx("div",{className:"absolute bottom-8 left-0 right-0 text-center space-y-1",children:T==="windows"?e.jsx(e.Fragment,{children:e.jsx("p",{className:"text-sm text-muted-foreground/70",children:n("onboarding.localSetup.windows.hintDetectionFailed")})}):e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-sm text-muted-foreground/70",children:n("onboarding.localSetup.hint.ensurePath")}),e.jsx("p",{className:"text-sm text-muted-foreground/70",children:n("onboarding.localSetup.hint.setEnv")}),e.jsx("p",{className:"text-sm text-muted-foreground/70",children:n("onboarding.localSetup.hint.missingRuntime")})]})})]})}function se(a,t){if(a?.trim())return ne(a.trim());if(t)return ne(t)}function _e(a,t,s){switch(a){case"local-unavailable":return{title:"Local OpenCode Unavailable",description:"OpenCode CLI could not be started or is not installed. Install OpenCode or connect to a remote server instead.",titleKey:"onboarding.desktopRecovery.localUnavailable.title",descriptionKey:"onboarding.desktopRecovery.localUnavailable.description",iconKey:"local",showRetry:!0,retryLabel:"Retry Local",retryLabelKey:"onboarding.desktopRecovery.localUnavailable.retry",showUseLocal:!0,showUseRemote:!0,useLocalLabel:"Set Up Local",useLocalLabelKey:"onboarding.desktopRecovery.localUnavailable.useLocal",useRemoteLabel:"Use Remote",useRemoteLabelKey:"onboarding.desktopRecovery.common.useRemote"};case"remote-missing":return{title:"No Default Connection",description:"Your saved default connection could not be found. Choose how you want to connect.",titleKey:"onboarding.desktopRecovery.noDefaultConnection.title",descriptionKey:"onboarding.desktopRecovery.noDefaultConnection.description",iconKey:"local",showRetry:!1,showUseLocal:!0,showUseRemote:!0,useLocalLabel:"Use Local",useLocalLabelKey:"onboarding.desktopRecovery.common.useLocal",useRemoteLabel:"Use Remote",useRemoteLabelKey:"onboarding.desktopRecovery.common.useRemote"};case"remote-unreachable":{const r=se(t,s);return{title:"Remote Server Unreachable",description:`Could not connect to "${r||"the remote server"}". Check your network connection and verify the server address.`,titleKey:"onboarding.desktopRecovery.remoteUnreachable.title",descriptionKey:"onboarding.desktopRecovery.remoteUnreachable.description",descriptionParams:r?{host:r}:void 0,iconKey:"remote",showRetry:!0,retryLabel:"Retry Connection",retryLabelKey:"onboarding.desktopRecovery.remoteUnreachable.retry",showUseLocal:!0,showUseRemote:!0,useLocalLabel:"Use Local",useLocalLabelKey:"onboarding.desktopRecovery.common.useLocal",useRemoteLabel:"Use Remote",useRemoteLabelKey:"onboarding.desktopRecovery.common.useRemote"}}case"remote-wrong-service":{const r=se(t,s);return{title:"Incompatible Server",description:`The server at "${r||"unknown"}" is not running OpenChamber. Verify the address points to an OpenChamber server.`,titleKey:"onboarding.desktopRecovery.incompatibleServer.title",descriptionKey:"onboarding.desktopRecovery.incompatibleServer.description",descriptionParams:r?{host:r}:void 0,iconKey:"remote",showRetry:!1,showUseLocal:!0,showUseRemote:!0,useLocalLabel:"Use Local",useLocalLabelKey:"onboarding.desktopRecovery.common.useLocal",useRemoteLabel:"Use Remote",useRemoteLabelKey:"onboarding.desktopRecovery.common.useRemote"}}case"remote-incompatible":{const r=se(t,s);return{title:"Server Update Required",description:`The OpenChamber server at "${r||"unknown"}" is not compatible with this app version. Update OpenChamber on the server, then try again.`,titleKey:"onboarding.desktopRecovery.remoteIncompatible.title",descriptionKey:"onboarding.desktopRecovery.remoteIncompatible.description",descriptionParams:r?{host:r}:void 0,iconKey:"remote",showRetry:!0,retryLabel:"Retry Connection",retryLabelKey:"onboarding.desktopRecovery.remoteUnreachable.retry",showUseLocal:!0,showUseRemote:!0,useLocalLabel:"Use Local",useLocalLabelKey:"onboarding.desktopRecovery.common.useLocal",useRemoteLabel:"Use Remote",useRemoteLabelKey:"onboarding.desktopRecovery.common.useRemote"}}case"missing-default-host":return{title:"No Default Connection",description:"Your saved default connection could not be found. Choose how you want to connect.",titleKey:"onboarding.desktopRecovery.noDefaultConnection.title",descriptionKey:"onboarding.desktopRecovery.noDefaultConnection.description",iconKey:"local",showRetry:!1,showUseLocal:!0,showUseRemote:!0,useLocalLabel:"Use Local",useLocalLabelKey:"onboarding.desktopRecovery.common.useLocal",useRemoteLabel:"Use Remote",useRemoteLabelKey:"onboarding.desktopRecovery.common.useRemote"};default:{const r=a;throw new Error(`Unknown recovery variant: ${r}`)}}}function De(a){switch(a){case"local":return e.jsx(A,{name:"macbook",className:"h-8 w-8"});case"remote":return e.jsx(A,{name:"server",className:"h-8 w-8"})}}function Ee({variant:a,hostLabel:t,hostUrl:s,onRetry:r,onUseLocal:n,onUseRemote:l,isRetrying:u=!1}){const{t:h}=Q(),o=_e(a,t,s),w=o.retryLabelKey??"onboarding.desktopRecovery.actions.retryConnection",S=i.useMemo(()=>{if(o.descriptionParams?.host)return o.descriptionParams;if(a==="remote-unreachable")return{host:h("onboarding.desktopRecovery.placeholders.remoteServer")};if(a==="remote-wrong-service"||a==="remote-incompatible")return{host:h("onboarding.desktopRecovery.placeholders.unknownServer")}},[o.descriptionParams,h,a]);return e.jsx("div",{className:"flex flex-col items-center justify-center h-full p-8",children:e.jsxs("div",{className:"w-full max-w-md space-y-6",children:[e.jsxs("div",{className:"flex flex-col items-center space-y-3 text-center",children:[e.jsx("div",{className:"p-3 rounded-full",style:{backgroundColor:"var(--status-warning)",opacity:.15},children:e.jsx("div",{style:{color:"var(--status-warning)"},children:De(o.iconKey)})}),e.jsx("h1",{className:"typography-ui-header text-xl font-semibold text-foreground",children:h(o.titleKey)}),e.jsx("p",{className:"text-muted-foreground text-sm max-w-sm",children:h(o.descriptionKey,S)})]}),s&&(a==="remote-unreachable"||a==="remote-wrong-service"||a==="remote-incompatible")&&e.jsxs("div",{className:"rounded-lg border border-border bg-background/50 p-3",children:[e.jsx("div",{className:"text-xs text-muted-foreground mb-1",children:h("onboarding.remoteConnection.field.serverAddress")}),e.jsx("div",{className:"font-mono text-sm text-foreground truncate",children:ne(s)})]}),e.jsxs("div",{className:"flex flex-col gap-2",children:[o.showRetry&&r&&e.jsxs(L,{onClick:r,disabled:u,className:"w-full",children:[e.jsx(A,{name:"refresh",className:re("h-4 w-4",u&&"animate-spin")}),h(u?"onboarding.desktopRecovery.actions.retrying":w)]}),e.jsxs("div",{className:"flex gap-2",children:[o.showUseLocal&&n&&e.jsxs(L,{variant:"outline",onClick:n,disabled:u,className:"flex-1",children:[e.jsx(A,{name:"macbook",className:"h-4 w-4"}),h(o.useLocalLabelKey)]}),o.showUseRemote&&l&&e.jsxs(L,{variant:"outline",onClick:l,disabled:u,className:"flex-1",children:[e.jsx(A,{name:"server",className:"h-4 w-4"}),h(o.useRemoteLabelKey)]})]})]})]})})}function de(a,t){if(t==="use-remote")return{kind:"remote-form"};switch(a){case"local-unavailable":return{kind:"local-setup"};case"remote-unreachable":case"remote-incompatible":case"remote-wrong-service":case"remote-missing":case"missing-default-host":return{kind:"switch-default-to-local"};default:{const s=a;throw new Error(`Unhandled RecoveryVariant: ${s}`)}}}function Ae(a){const t=J.c(29),{variant:s,hostUrl:r,hostLabel:n,onRetry:l,onChooseRemote:u,showRemoteForm:h,onCloseRemoteForm:o,onSwitchToLocalFromRemote:w,onEnterLocalSetup:S,isRetrying:j,localAvailable:U}=a,K=h===void 0?!1:h,x=j===void 0?!1:j,m=U===void 0?!0:U,k=Fe;let C;t[0]!==l?(C=async()=>{if($()){await M();return}await W("/api/config/reload",{method:"POST"}),l?.()},t[0]=l,t[1]=C):C=t[1];const g=C;let T;t[2]!==S||t[3]!==s?(T=async()=>{if(de(s,"use-local").kind==="local-setup"){S?.();return}if(await k("local"),$()){await M();return}window.location.reload()},t[2]=S,t[3]=s,t[4]=T):T=t[4];const I=T;let y;t[5]!==u||t[6]!==s?(y=()=>{de(s,"use-remote").kind==="remote-form"&&u?.()},t[5]=u,t[6]=s,t[7]=y):y=t[7];const f=y;if(K){const N=s==="remote-wrong-service"?"":r||"",E=s==="remote-wrong-service"?"":n||"";let F;t[8]!==u||t[9]!==o?(F=o||(()=>u?.()),t[8]=u,t[9]=o,t[10]=F):F=t[10];const O=!m;let c;t[11]!==m||t[12]!==S||t[13]!==w?(c=m?w||(()=>{k("local").then(()=>{$()?M():S?.()})}):void 0,t[11]=m,t[12]=S,t[13]=w,t[14]=c):c=t[14];let D;return t[15]!==E||t[16]!==N||t[17]!==F||t[18]!==O||t[19]!==c?(D=e.jsx(xe,{onBack:F,initialUrl:N,initialLabel:E,isRecoveryMode:!0,showInstancePicker:O,onSwitchToLocal:c}),t[15]=E,t[16]=N,t[17]=F,t[18]=O,t[19]=c,t[20]=D):D=t[20],D}const b=m?I:void 0;let R;return t[21]!==g||t[22]!==f||t[23]!==n||t[24]!==r||t[25]!==x||t[26]!==b||t[27]!==s?(R=e.jsx(Ee,{variant:s,hostLabel:n,hostUrl:r,onRetry:g,onUseLocal:b,onUseRemote:f,isRetrying:x}),t[21]=g,t[22]=f,t[23]=n,t[24]=r,t[25]=x,t[26]=b,t[27]=s,t[28]=R):R=t[28],R}async function Fe(a){if(!$())return;const t=await V();await Y({...t,...a==="local"?{defaultHostId:"local"}:{},initialHostChoiceCompleted:!0})}function co(a){const t=J.c(29),{onBack:s,onCliAvailable:r,mode:n,recoveryVariant:l,recoveryHostUrl:u,recoveryHostLabel:h,onEnterLocalSetup:o,localAvailable:w}=a,S=n===void 0?"first-launch":n,j=l===void 0?"missing-default-host":l,U=w===void 0?!0:w,[K,x]=i.useState(!1),[m,k]=i.useState(!1);let C;t[0]===Symbol.for("react.memo_cache_sentinel")?(C=()=>{k(!1),x(!1)},t[0]=C):C=t[0];let g;t[1]!==S||t[2]!==h||t[3]!==u||t[4]!==j?(g=[S,j,u,h],t[1]=S,t[2]=h,t[3]=u,t[4]=j,t[5]=g):g=t[5],i.useEffect(C,g);const T=m?"local-setup":S;if(T==="recovery"){let y;t[6]===Symbol.for("react.memo_cache_sentinel")?(y=()=>x(!0),t[6]=y):y=t[6];let f,b;t[7]===Symbol.for("react.memo_cache_sentinel")?(f=()=>x(!1),b=()=>{x(!1),k(!0)},t[7]=f,t[8]=b):(f=t[7],b=t[8]);let R;t[9]!==o?(R=()=>{k(!0),o?.()},t[9]=o,t[10]=R):R=t[10];let N;return t[11]!==U||t[12]!==h||t[13]!==u||t[14]!==j||t[15]!==K||t[16]!==R?(N=e.jsx(Ae,{variant:j,hostUrl:u,hostLabel:h,onChooseRemote:y,showRemoteForm:K,onCloseRemoteForm:f,onSwitchToLocalFromRemote:b,onEnterLocalSetup:R,localAvailable:U}),t[11]=U,t[12]=h,t[13]=u,t[14]=j,t[15]=K,t[16]=R,t[17]=N):N=t[17],N}if(T==="local-setup"){let y;t[18]!==s||t[19]!==m?(y=()=>{m?k(!1):s?.()},t[18]=s,t[19]=m,t[20]=y):y=t[20];let f;t[21]===Symbol.for("react.memo_cache_sentinel")?(f=()=>x(!0),t[21]=f):f=t[21];let b;return t[22]!==r||t[23]!==m||t[24]!==y?(b=e.jsx(Ie,{onBack:y,onCliAvailable:r,isFromRecovery:m,onSwitchToRemote:f}),t[22]=r,t[23]=m,t[24]=y,t[25]=b):b=t[25],b}let I;return t[26]!==U||t[27]!==r?(I=e.jsx(Re,{onCliAvailable:r,localAvailable:U}),t[26]=U,t[27]=r,t[28]=I):I=t[28],I}export{co as OnboardingScreen};