@aiworker/web 1.22.2 → 1.23.1

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 (217) hide show
  1. package/bin/cli.js +7 -0
  2. package/dist/assets/{CodeMirrorCommentWidgets-CSICpWQD.js → CodeMirrorCommentWidgets-teB3HmBT.js} +1 -1
  3. package/dist/assets/DiffView-DC9RX3MF.js +4 -0
  4. package/dist/assets/{DirtyBranchSwitchDialog-C22HdWj4.js → DirtyBranchSwitchDialog-DwPkzXsS.js} +1 -1
  5. package/dist/assets/FilesView-BFZkuu4O.js +13 -0
  6. package/dist/assets/{GitView-VQQkYuUw.js → GitView-B_x52MHY.js} +4 -4
  7. package/dist/assets/{JsonTreeView-6lrhwD3q.js → JsonTreeView-cmAzUTiw.js} +1 -1
  8. package/dist/assets/{LinearIssuesView-Ba6Q9569.js → LinearIssuesView-Dehh5afm.js} +1 -1
  9. package/dist/assets/MarkdownImageGallery-DgNOqqhE.js +1 -0
  10. package/dist/assets/MarkdownRendererImpl-DusmMZ_p.js +12 -0
  11. package/dist/assets/OnboardingScreen-B8fm1H4m.js +1 -0
  12. package/dist/assets/{PatchDiff-BzcZPlOq.js → PatchDiff-BVr7gJU0.js} +1 -1
  13. package/dist/assets/PierreDiffViewer-DzLt-nel.js +161 -0
  14. package/dist/assets/PlanView-BmQUYT_z.js +5 -0
  15. package/dist/assets/SettingsView-ChWmAcZT.js +28 -0
  16. package/dist/assets/{SettingsWindow-DDQYaKWQ.js → SettingsWindow-Dy3M6ZB9.js} +1 -1
  17. package/dist/assets/SymbolsNerdFontMono-Regular-aK5vsLov.woff2 +0 -0
  18. package/dist/assets/{ToolOutputDialog-iYF8Y2bz.js → ToolOutputDialog-cTl_eLIH.js} +5 -5
  19. package/dist/assets/{ToolPartDiffPreview-CdjbOVMM.js → ToolPartDiffPreview-C_3iYNJQ.js} +1 -1
  20. package/dist/assets/{VirtualizedFileDiff-fFFm2QgH.js → VirtualizedFileDiff-CAWthkoy.js} +4 -4
  21. package/dist/assets/WalkthroughView-C7AHOpCA.js +4 -0
  22. package/dist/assets/{computeVirtualFileMetrics-CzgLum_K.js → computeVirtualFileMetrics-BkiDSlTW.js} +2 -2
  23. package/dist/assets/contextPanelEmbeddedChat-BdA6bdky.js +1 -0
  24. package/dist/assets/de-DJsQr-p7.js +10 -0
  25. package/dist/assets/es-BuYMlA9g.js +16 -0
  26. package/dist/assets/fr-ePDay33C.js +14 -0
  27. package/dist/assets/ghostty-vt-DdA0Zryv.wasm +0 -0
  28. package/dist/assets/index-BD8ILbxF.js +40 -0
  29. package/dist/assets/{index-Bl3LSbjn.js → index-n6O3hklM.js} +1 -1
  30. package/dist/assets/index-zhgg-SDz.css +1 -0
  31. package/dist/assets/{isDiffPlainText-Dx-dB_8l.js → isDiffPlainText-GMdPz-71.js} +1 -1
  32. package/dist/assets/{isFilePlainText-CWFPwmnU.js → isFilePlainText-BVuH1zH9.js} +1 -1
  33. package/dist/assets/ja-BzR9xOY_.js +16 -0
  34. package/dist/assets/ko-BEjHAm14.js +16 -0
  35. package/dist/assets/main-BydQ1tr_.js +930 -0
  36. package/dist/assets/{main-DnBAoktx.js → main-D3ZDQglc.js} +2 -2
  37. package/dist/assets/markdownCore-Cb2MdZnV.js +5 -0
  38. package/dist/assets/{miniChat-BKyvLseN.js → miniChat-d01k801U.js} +2 -2
  39. package/dist/assets/{mobile-DKjeFgMN.js → mobile-D7VV-Ufz.js} +2 -2
  40. package/dist/assets/patchFileDiff-CdztVMz0.js +13 -0
  41. package/dist/assets/pl-rQmpxNIF.js +16 -0
  42. package/dist/assets/pt-BR-CorbsSW-.js +16 -0
  43. package/dist/assets/renderElectronMiniChatApp-BGG9UIlh.js +2 -0
  44. package/dist/assets/renderMobileApp-BRP3J1iv.js +25 -0
  45. package/dist/assets/runtimeEndpointReset-BhT_-c52.js +41 -0
  46. package/dist/assets/scheduledTasksApi-BEuUF_cj.js +1 -0
  47. package/dist/assets/{shikiHighlight-TEQCmzW8.js → shikiHighlight-BzXUjlby.js} +1 -1
  48. package/dist/assets/surface-COKb77Ua.js +1 -0
  49. package/dist/assets/tr-CoAMXPtI.js +7 -0
  50. package/dist/assets/uk-YlAX0rRU.js +16 -0
  51. package/dist/assets/{useAppFontEffects-D7sNpuL2.js → useAppFontEffects-Cwyhjfl5.js} +141 -140
  52. package/dist/assets/useGitComparison-BCZVefdE.js +1 -0
  53. package/dist/assets/useInlineCommentController-DDkpBEU8.js +2 -0
  54. package/dist/assets/useRootScrollLock-CwjoWuC4.js +1 -0
  55. package/dist/assets/{vendor-base-ui-BeMD8X_w.js → vendor-base-ui-BY_5qla_.js} +1 -1
  56. package/dist/assets/{vendor-codemirror-language-data-Dp3KMRQG.js → vendor-codemirror-language-data-Cb1YnICj.js} +2 -2
  57. package/dist/assets/vendor-legendapp-list-BuBPBC3R.js +1 -0
  58. package/dist/assets/vendor-zod-B6551dwG.js +39 -0
  59. package/dist/assets/{web-components-_mNEMjFY.js → web-components-LV3vjTxy.js} +1 -1
  60. package/dist/assets/zh-CN-DDYg0Jl7.js +16 -0
  61. package/dist/assets/zh-TW-CQKaCayr.js +16 -0
  62. package/dist/index.html +5 -43
  63. package/dist/mini-chat.html +4 -4
  64. package/dist/mobile.html +4 -4
  65. package/package.json +2 -3
  66. package/server/index.d.ts +15 -0
  67. package/server/index.js +48 -22
  68. package/server/lib/agent-memory/runtime.js +7 -2
  69. package/server/lib/agent-memory/runtime.test.js +22 -0
  70. package/server/lib/data-dir-migration.js +40 -0
  71. package/server/lib/data-dir-migration.test.js +59 -0
  72. package/server/lib/event-stream/DOCUMENTATION.md +3 -0
  73. package/server/lib/event-stream/global-hub.js +29 -4
  74. package/server/lib/event-stream/global-hub.test.js +22 -0
  75. package/server/lib/event-stream/global-ws-bridge.js +15 -18
  76. package/server/lib/event-stream/protocol.js +21 -7
  77. package/server/lib/event-stream/runtime.js +9 -6
  78. package/server/lib/event-stream/runtime.test.js +72 -12
  79. package/server/lib/fs/DOCUMENTATION.md +3 -0
  80. package/server/lib/fs/routes.js +31 -0
  81. package/server/lib/fs/routes.test.js +110 -1
  82. package/server/lib/git/DOCUMENTATION.md +39 -6
  83. package/server/lib/git/routes.js +45 -12
  84. package/server/lib/git/routes.test.js +78 -0
  85. package/server/lib/git/service.js +343 -202
  86. package/server/lib/git/service.test.js +496 -25
  87. package/server/lib/github/DOCUMENTATION.md +5 -0
  88. package/server/lib/github/routes.js +2 -2
  89. package/server/lib/inherited-env.js +16 -9
  90. package/server/lib/inherited-env.test.js +8 -9
  91. package/server/lib/message-queue/DOCUMENTATION.md +11 -1
  92. package/server/lib/message-queue/runtime.js +13 -0
  93. package/server/lib/message-queue/runtime.test.js +31 -1
  94. package/server/lib/network-defaults.js +23 -0
  95. package/server/lib/network-defaults.test.js +52 -0
  96. package/server/lib/notifications/DOCUMENTATION.md +1 -1
  97. package/server/lib/notifications/emitter-runtime.js +4 -3
  98. package/server/lib/opencode/DOCUMENTATION.md +35 -5
  99. package/server/lib/opencode/bootstrap-runtime.js +2 -0
  100. package/server/lib/opencode/env-runtime.js +5 -1
  101. package/server/lib/opencode/env-runtime.test.js +72 -0
  102. package/server/lib/opencode/feature-routes-runtime.js +17 -1
  103. package/server/lib/opencode/lifecycle.js +4 -3
  104. package/server/lib/opencode/lifecycle.test.js +29 -0
  105. package/server/lib/opencode/managed-plugin-config.js +1 -1
  106. package/server/lib/opencode/openchamber-routes.js +64 -4
  107. package/server/lib/opencode/openchamber-routes.test.js +128 -1
  108. package/server/lib/opencode/proxy.js +33 -0
  109. package/server/lib/opencode/routes.js +5 -3
  110. package/server/lib/opencode/settings-files.js +214 -0
  111. package/server/lib/opencode/settings-helpers.js +88 -41
  112. package/server/lib/opencode/settings-helpers.test.js +176 -1
  113. package/server/lib/opencode/settings-registry.json +750 -0
  114. package/server/lib/opencode/settings-runtime.js +175 -27
  115. package/server/lib/opencode/settings-runtime.test.js +321 -7
  116. package/server/lib/project-context/DOCUMENTATION.md +38 -4
  117. package/server/lib/project-context/routes.http.test.js +18 -0
  118. package/server/lib/project-context/routes.js +15 -0
  119. package/server/lib/project-context/runtime.js +256 -25
  120. package/server/lib/project-context/runtime.test.js +160 -3
  121. package/server/lib/projects/DOCUMENTATION.md +77 -0
  122. package/server/lib/projects/project-config.js +179 -17
  123. package/server/lib/projects/project-config.test.js +97 -0
  124. package/server/lib/projects/project-id.js +43 -0
  125. package/server/lib/projects/project-setup.js +409 -0
  126. package/server/lib/projects/project-setup.test.js +557 -0
  127. package/server/lib/projects/routes.js +59 -0
  128. package/server/lib/quota/DOCUMENTATION.md +31 -1
  129. package/server/lib/quota/providers/cline-pass.js +125 -0
  130. package/server/lib/quota/providers/cline-pass.test.js +103 -0
  131. package/server/lib/quota/providers/index.js +7 -0
  132. package/server/lib/quota/providers/neuralwatt.js +3 -6
  133. package/server/lib/quota/providers/neuralwatt.test.js +7 -7
  134. package/server/lib/quota/providers/ollama-cloud.js +31 -0
  135. package/server/lib/quota/providers/ollama-cloud.test.js +33 -1
  136. package/server/lib/quota/providers/opencode-go.js +1 -1
  137. package/server/lib/quota/providers/opencode-go.test.js +26 -1
  138. package/server/lib/quota/providers/openrouter.js +119 -24
  139. package/server/lib/quota/providers/openrouter.test.js +330 -0
  140. package/server/lib/relay/DOCUMENTATION.md +75 -0
  141. package/server/lib/relay/cross-compat.test.js +26 -0
  142. package/server/lib/relay/downstream-scheduler.js +154 -0
  143. package/server/lib/relay/downstream-scheduler.test.js +162 -0
  144. package/server/lib/relay/e2ee.js +10 -8
  145. package/server/lib/relay/flow-control.test.js +177 -0
  146. package/server/lib/relay/host-client.js +44 -8
  147. package/server/lib/relay/host-client.test.js +14 -0
  148. package/server/lib/relay/tunnel-codec.js +9 -0
  149. package/server/lib/relay/tunnel-host.js +66 -17
  150. package/server/lib/scheduled-tasks/DOCUMENTATION.md +9 -1
  151. package/server/lib/scheduled-tasks/issue-2710-double-execution.test.js +28 -0
  152. package/server/lib/scheduled-tasks/runtime.js +12 -2
  153. package/server/lib/scheduled-tasks/runtime.test.js +53 -0
  154. package/server/lib/session-assist/DOCUMENTATION.md +131 -66
  155. package/server/lib/session-assist/context.js +127 -0
  156. package/server/lib/session-assist/context.test.js +132 -0
  157. package/server/lib/session-assist/prompt.js +54 -0
  158. package/server/lib/session-assist/runtime.js +117 -267
  159. package/server/lib/session-assist/runtime.test.js +203 -0
  160. package/server/lib/session-goal/runtime.js +4 -9
  161. package/server/lib/small-model/DOCUMENTATION.md +3 -2
  162. package/server/lib/small-model/call.js +9 -4
  163. package/server/lib/small-model/call.test.js +29 -0
  164. package/server/lib/small-model/index.js +5 -10
  165. package/server/lib/small-model/runtime-providers.js +15 -7
  166. package/server/lib/small-model/runtime-providers.test.js +7 -1
  167. package/server/lib/terminal/DOCUMENTATION.md +4 -4
  168. package/server/lib/terminal/runtime.js +11 -6
  169. package/server/lib/terminal/runtime.test.js +20 -13
  170. package/server/lib/walkthrough/DOCUMENTATION.md +49 -20
  171. package/server/lib/walkthrough/model-settings.js +8 -12
  172. package/server/lib/walkthrough/pr-source.test.js +21 -0
  173. package/server/lib/walkthrough/prompt.js +3 -1
  174. package/server/lib/walkthrough/pull-request.js +7 -4
  175. package/server/lib/walkthrough/pull-request.test.js +16 -0
  176. package/server/lib/walkthrough/routes.js +19 -0
  177. package/server/lib/walkthrough/routes.test.js +26 -0
  178. package/server/lib/walkthrough/sources.js +36 -4
  179. package/server/opencode-worktree-readiness.test.js +130 -0
  180. package/dist/assets/DiffView-hDBKesA_.js +0 -4
  181. package/dist/assets/FilesView-CdWzeOp9.js +0 -17
  182. package/dist/assets/MarkdownImageGallery-Czv_mhvS.js +0 -1
  183. package/dist/assets/MarkdownRendererImpl-BrMcswiy.js +0 -12
  184. package/dist/assets/OnboardingScreen-ChxQoAkx.js +0 -1
  185. package/dist/assets/PierreDiffViewer-BchBtZlp.js +0 -157
  186. package/dist/assets/PlanView-DyDt_nZ_.js +0 -5
  187. package/dist/assets/SettingsView-BKf5xBsP.js +0 -28
  188. package/dist/assets/WalkthroughView-DOeCsMju.js +0 -4
  189. package/dist/assets/contextPanelEmbeddedChat-C0ZLAepL.js +0 -1
  190. package/dist/assets/de-B5JaA3SA.js +0 -10
  191. package/dist/assets/es-EPIH88ii.js +0 -16
  192. package/dist/assets/fr-CAMfxUdZ.js +0 -14
  193. package/dist/assets/index-DF5kMP-i.js +0 -39
  194. package/dist/assets/index-Dl3xbAB_.css +0 -1
  195. package/dist/assets/ja-CifOE1VN.js +0 -16
  196. package/dist/assets/ko-BBDyAyYQ.js +0 -16
  197. package/dist/assets/main-MhSaOZoB.js +0 -930
  198. package/dist/assets/markdownCore-BrBwOOMn.js +0 -3
  199. package/dist/assets/patchFileDiff-o8ms1me8.js +0 -10
  200. package/dist/assets/pl-DgEHYfFM.js +0 -16
  201. package/dist/assets/pt-BR-DuWHojUw.js +0 -16
  202. package/dist/assets/renderElectronMiniChatApp-CDgBwwCS.js +0 -2
  203. package/dist/assets/renderMobileApp-DJIKIK1r.js +0 -25
  204. package/dist/assets/runtimeEndpointReset-CYJ9O_xX.js +0 -17
  205. package/dist/assets/scheduledTasksApi-D8yamh1b.js +0 -1
  206. package/dist/assets/tr-D5m2yIWL.js +0 -7
  207. package/dist/assets/uk-D_q60oog.js +0 -16
  208. package/dist/assets/useInlineCommentController-Brz_cLcQ.js +0 -2
  209. package/dist/assets/useRootScrollLock-lXEnWlaU.js +0 -1
  210. package/dist/assets/vendor-ghostty-web-CrxinGGH.js +0 -13
  211. package/dist/assets/vendor-legendapp-list-gg7YLRW7.js +0 -1
  212. package/dist/assets/vendor-zod-CK21ihK-.js +0 -39
  213. package/dist/assets/zh-CN-D8QvsVeg.js +0 -16
  214. package/dist/assets/zh-TW-B9t7rQQO.js +0 -16
  215. package/server/lib/mcp-reconnect/DOCUMENTATION.md +0 -55
  216. package/server/lib/mcp-reconnect/runtime.js +0 -122
  217. package/server/lib/mcp-reconnect/runtime.test.js +0 -140
@@ -1,17 +0,0 @@
1
- import{f as pt,R as n,c as Vn,j as r,r as us}from"./vendor-react-BUCujlKS.js";import{W as fa,X as ma,Y as ha,Z as pa,n as Ge,u as ht,dy as ga,C as En,w as xa,r as Dn,$ as Pn,e as va,dw as wa,a2 as ba,dx as ya,a as ja}from"./index-DF5kMP-i.js";import{f as $t,y as Mn,ac as ri,bR as Fa,h as G,ht as Na,fm as Ca,T as nr,B as z,I as y,W as Sa,N as ka,b7 as Ra,ae as Ta,c6 as Va,eb as zn,hu as Ln,hv as Ea,g_ as Da,fn as Pa,t as Y,l as An,ao as ds,c1 as sr,cD as Ma,b as za,hw as Tr,bE as La,ap as fs,hx as In,c2 as On,c3 as Bn,ge as Aa,hy as Ia,hz as Oa,hA as Ba,bF as si,bG as ni,bH as ii,bI as ai,bJ as oi,bK as li,b6 as vs,b3 as ws,ar as Er,b5 as bs,b2 as Dr,c0 as ms,aq as hs,bZ as $n,a7 as Lt,a8 as At,a9 as It,bC as $a,bD as Wa,g as Mr,b4 as _a,bf as Ua}from"./useAppFontEffects-D7sNpuL2.js";import{a6 as Ka,G as Ha,H as Ga,I as qa,J as Xa,K as Ja}from"./runtimeEndpointReset-CYJ9O_xX.js";import{c as Wn,s as Ya,C as _n,P as ps}from"./shikiHighlight-TEQCmzW8.js";import{a as Za}from"./vendor-codemirror-state-C9awkmn-.js";import{E as jt}from"./vendor-codemirror-view-CiLROUVV.js";import{J as Qa,F as eo}from"./JsonTreeView-6lrhwD3q.js";import{ensurePierreThemeRegistered as Un,getResolvedShikiTheme as to}from"./appThemeRegistry-BK0dHKa6.js";import{V as ro,W as so}from"./Virtualizer-CZlLSacm.js";import{V as no}from"./Virtualizer-D_a8gKmg.js";import{u as Vr,c as io,e as ao}from"./scheduledTasksApi-D8yamh1b.js";import{D as oo}from"./vendor-react-drawio-Ct3Q0DsD.js";import{I as lo,u as co,n as uo}from"./useInlineCommentController-Brz_cLcQ.js";import{b as fo}from"./CodeMirrorCommentWidgets-CSICpWQD.js";import"./vendor-scheduler-7OC5HNn7.js";import"./vendor-vite-runtime-DD1OZmLC.js";import"./vendor-zustand-BAGL70zf.js";import"./vendor-zod-CK21ihK-.js";import"./vendor-opencode-sdk-BJ73u-bH.js";import"./vendor-simplewebauthn-browser-VDA66rT_.js";import"./vendor-base-ui-BeMD8X_w.js";import"./vendor-floating-ui-utils-D6FqdtJt.js";import"./vendor-floating-ui-react-dom-DxYCWdHj.js";import"./vendor-floating-ui-dom-BTvzWks8.js";import"./vendor-floating-ui-core-PuGzNPnN.js";import"./vendor-use-sync-external-store-D6wYuSt-.js";import"./contextPanelEmbeddedChat-C0ZLAepL.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-framer-motion-livSKyyV.js";import"./vendor-motion-dom-D_o3BTI3.js";import"./vendor-motion-utils-BGh8QBgx.js";import"./vendor-tanstack-react-virtual-g05Cx3z9.js";import"./vendor-tanstack-virtual-core-Dubg10g5.js";import"./vendor-sonner-DFyL3AvE.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-BgPj_McA.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-Cc2ZYbgX.js";import"./vendor-lezer-javascript-D7Tj24ot.js";import"./vendor-lezer-lr-bhwg1HMg.js";import"./vendor-codemirror-autocomplete-DzPz9Wgq.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-CMBS2tG9.js";import"./vendor-lezer-json-Iaex0UN-.js";import"./vendor-codemirror-lang-css-O0cZX78y.js";import"./vendor-lezer-css-C5xB6jxd.js";import"./vendor-codemirror-lang-html-CfgK872x.js";import"./vendor-lezer-html-C0I1p52t.js";import"./vendor-codemirror-lang-markdown-BPGOH9ye.js";import"./vendor-lezer-markdown-C6g-d6P3.js";import"./vendor-codemirror-language-data-Dp3KMRQG.js";import"./vendor-codemirror-lang-python-HahnQaAS.js";import"./vendor-lezer-python-CvuFxeZl.js";import"./vendor-codemirror-commands-B7H_j0iU.js";import"./vendor-legendapp-list-gg7YLRW7.js";import"./vendor-tailwind-merge-CPcsbTWB.js";import"./vendor-fuse.js-Dw8P0qyA.js";import"./vendor-codemirror-search-BmS-GmcX.js";import"./vendor-replit-codemirror-vim-B2DJlAhT.js";import"./vendor-replit-codemirror-vim-core-FHzKdNUS.js";import"./web-components-_mNEMjFY.js";import"./computeVirtualFileMetrics-CzgLum_K.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"./isFilePlainText-CWFPwmnU.js";import"./registerCustomTheme-BBXUCRnG.js";function Kn(a){const e=pt.c(41),{containerRef:s,filePath:d,fileContent:x}=a,{t:g}=$t(),v=Mn(bo),b=Mn(wo),f=ri(),C=Fa(vo),[p,F]=n.useState(null),[N,R]=n.useState(""),[j,T]=n.useState(!1),o=n.useRef(!1),A=n.useRef(null),I=n.useRef(null),[W,L]=n.useState(null);let E;e[0]===Symbol.for("react.memo_cache_sentinel")?(E=()=>{F(null),R(""),T(!1),o.current=!1,I.current=null,L(null)},e[0]=E):E=e[0];const V=E;let S,M;e[1]!==s?(S=()=>{const B=s.current;if(!B)return;const H=()=>{if(o.current)return;const se=window.getSelection(),Se=se?.toString().trim()??"";if(!se||!Se||se.rangeCount===0){V();return}const ae=se.getRangeAt(0);if(!B.contains(ae.commonAncestorContainer)){V();return}const oe=ae.getBoundingClientRect();I.current=ae.cloneRange(),R(Se),F({x:oe.left+oe.width/2,y:oe.top-10})},re=se=>{A.current?.contains(se.target)||o.current&&V()};return document.addEventListener("selectionchange",H),document.addEventListener("pointerdown",re),()=>{document.removeEventListener("selectionchange",H),document.removeEventListener("pointerdown",re)}},M=[s,V],e[1]=s,e[2]=S,e[3]=M):(S=e[2],M=e[3]),n.useEffect(S,M);let $;e[4]!==x?($=B=>{const H=de=>x.slice(0,de).split(`
2
- `).length,re=go,se=(de,Ve)=>{for(const Ee of re(de)){const ke=x.indexOf(Ee,Ve);if(ke>=0)return ke}return-1},Se=B.length>=8?x.indexOf(B):-1;if(Se>=0){const de=H(Se);return{start:de,end:de+B.split(`
3
- `).length-1}}const ae=B.split(`
4
- `).map(po).filter(Boolean);if(ae.length===0)return null;const oe=se(ae[0],0);if(oe<0)return null;const be=H(oe);if(ae.length===1)return{start:be,end:be};const Te=se(ae[ae.length-1],oe);return Te<0?null:{start:be,end:Math.max(be,H(Te))}},e[4]=x,e[5]=$):$=e[5];const P=$;let X;e[6]===Symbol.for("react.memo_cache_sentinel")?(X=()=>{const B=I.current;if(!B){L(null);return}L(Na(B))},e[6]=X):X=e[6];const Ne=X;let _,Z;e[7]!==j?(_=()=>{if(!j)return;let B=null;const H=()=>{B===null&&(B=window.requestAnimationFrame(()=>{B=null,Ne()}))};return document.addEventListener("scroll",H,{capture:!0,passive:!0}),window.addEventListener("resize",H),()=>{B!==null&&window.cancelAnimationFrame(B),document.removeEventListener("scroll",H,{capture:!0}),window.removeEventListener("resize",H)}},Z=[j,Ne],e[7]=j,e[8]=_,e[9]=Z):(_=e[8],Z=e[9]),n.useEffect(_,Z);let ee;e[10]!==N?(ee=()=>{N&&(T(!0),o.current=!0,Ne(),window.getSelection()?.removeAllRanges())},e[10]=N,e[11]=ee):ee=e[11];const le=ee;let te;e[12]!==C||e[13]!==v||e[14]!==f||e[15]!==d||e[16]!==b||e[17]!==P||e[18]!==N?(te=B=>{const H=v??(b?"draft":null);if(!N||!H||!f){V();return}const re=P(N);C({directory:f,sessionKey:H},{source:"file-quote",fileLabel:d,startLine:re?.start??0,endLine:re?.end??0,code:N,language:"",text:B.trim()}),V(),queueMicrotask(ho)},e[12]=C,e[13]=v,e[14]=f,e[15]=d,e[16]=b,e[17]=P,e[18]=N,e[19]=te):te=e[19];const Ce=te;if(!p)return null;let O;e[20]!==j||e[21]!==P||e[22]!==N?(O=j?P(N):null,e[20]=j,e[21]=P,e[22]=N,e[23]=O):O=e[23];const xe=O;let ve;e[24]!==p.x||e[25]!==p.y?(ve={left:p.x,top:p.y,transform:"translate(-50%, -100%)"},e[24]=p.x,e[25]=p.y,e[26]=ve):ve=e[26];let ce;e[27]!==j||e[28]!==W?(ce=j&&W&&W.length>0?Vn.createPortal(r.jsx("div",{className:"pointer-events-none fixed inset-0 z-40",children:W.map(mo)}),document.body):null,e[27]=j,e[28]=W,e[29]=ce):ce=e[29];let ue;e[30]!==j||e[31]!==d||e[32]!==xe||e[33]!==le||e[34]!==Ce||e[35]!==g?(ue=j?r.jsx("div",{className:"w-[min(420px,80vw)]",children:r.jsx(lo,{fileLabel:d,lineRange:xe?{start:xe.start,end:xe.end}:void 0,onSave:Ce,onCancel:V})}):r.jsx("div",{className:G("flex items-center whitespace-nowrap","oc-glass-popover rounded-full border border-[var(--interactive-border)]","shadow-[0_4px_16px_-4px_rgb(0_0_0_/_0.12)]","p-1"),children:r.jsx("button",{type:"button",onClick:le,className:G("px-3.5 py-1.5 rounded-full","text-sm font-medium","text-[var(--surface-foreground)]","hover:bg-[var(--interactive-hover)]","transition-colors duration-150"),title:g("chat.textSelection.title.commentOnSelection"),children:g("chat.textSelection.actions.comment")})}),e[30]=j,e[31]=d,e[32]=xe,e[33]=le,e[34]=Ce,e[35]=g,e[36]=ue):ue=e[36];let we;return e[37]!==ve||e[38]!==ce||e[39]!==ue?(we=Vn.createPortal(r.jsxs("div",{ref:A,className:"fixed z-50",style:ve,children:[ce,ue]}),document.body),e[37]=ve,e[38]=ce,e[39]=ue,e[40]=we):we=e[40],we}function mo(a,e){return r.jsx("div",{className:"oc-chat-comment-rect absolute",style:{left:a.left,top:a.top,width:a.width,height:a.height}},e)}function ho(){Ca()}function po(a){return a.trim()}function go(a){const e=a.trim();return[e,e.slice(0,32),e.split(" ").slice(0,4).join(" ")].filter(xo)}function xo(a){return a.length>=8}function vo(a){return a.addDraft}function wo(a){return a.newSessionDraft?.open}function bo(a){return a.currentSessionId}const yo=(a,e)=>{if(!e)return null;const s=Number.parseInt(a.trim(),10);return!Number.isFinite(s)||s<1?null:Math.min(s,e.state.doc.lines)},Hn=(a,e)=>{const s=a.state.doc.lineAt(e.main.head);return{lineNumber:s.number,character:e.main.head-s.from+1,selection:e}},Gn=(a,e,s)=>{const d=a.state.doc.line(e),x=Math.max(1,Math.min(s,d.length+1)),g=d.from+x-1;a.dispatch({selection:Za.cursor(g),effects:jt.scrollIntoView(g,{y:"center"})})};function jo({open:a,onOpenChange:e,view:s,variant:d="overlay"}){const{t:x}=$t(),[g,v]=n.useState(""),b=n.useRef(null),f=n.useRef(!1),C=n.useRef(null),p=n.useRef(null),F=n.useMemo(()=>yo(g,s),[g,s]);n.useEffect(()=>{!a||!s||(f.current=!1,b.current=Hn(s,s.state.selection),v(""))},[a,s]),n.useEffect(()=>{a&&window.requestAnimationFrame(()=>{p.current?.focus(),p.current?.select()})},[a]),n.useEffect(()=>{if(!(!a||!s||!b.current)){if(F===null){const{selection:o}=b.current;s.dispatch({selection:o,effects:jt.scrollIntoView(o.main.from,{y:"center"})});return}Gn(s,F,b.current.character)}},[F,a,s]);const N=n.useCallback(()=>{if(!s||f.current||!b.current)return;const{selection:o}=b.current;s.dispatch({selection:o,effects:jt.scrollIntoView(o.main.from,{y:"center"})})},[s]),R=n.useCallback(o=>{o||N(),e(o)},[e,N]),j=n.useCallback(()=>{!s||F===null||!b.current||(f.current=!0,Gn(s,F,b.current.character),e(!1),s.focus())},[F,e,s]);n.useEffect(()=>{if(!a)return;const o=I=>{const W=C.current,L=I.target;!W||!(L instanceof Node)||W.contains(L)||R(!1)},A=I=>{I.key==="Escape"&&(I.preventDefault(),R(!1))};return document.addEventListener("pointerdown",o,!0),document.addEventListener("keydown",A,!0),()=>{document.removeEventListener("pointerdown",o,!0),document.removeEventListener("keydown",A,!0)}},[R,a,d]);const T=n.useMemo(()=>{if(!s)return x("goToLineDialog.helper.editorUnavailable");if(F===null){const o=b.current??Hn(s,s.state.selection);return x("goToLineDialog.helper.currentLineRange",{current:o.lineNumber,max:s.state.doc.lines})}return x("goToLineDialog.helper.goToLine",{line:F})},[F,x,s]);return d==="inline"?a?r.jsxs("div",{ref:C,className:"ml-1 flex h-6 items-center gap-1",children:[r.jsx(nr,{ref:p,type:"number",min:1,step:1,inputMode:"numeric",value:g,onChange:o=>v(o.target.value),onKeyDown:o=>{o.key==="Enter"&&(o.preventDefault(),j())},placeholder:x("goToLineDialog.field.linePlaceholderShort"),className:"h-6 w-20 rounded-md border-border/70 bg-transparent px-2 typography-meta"}),r.jsx(z,{variant:"outline",size:"xs",onClick:j,disabled:!s||F===null,className:"h-6 px-2",children:x("goToLineDialog.actions.go")})]}):null:r.jsx("div",{ref:C,className:G("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",a?"pointer-events-auto translate-y-0 opacity-100":"pointer-events-none -translate-y-1 opacity-0"),children:r.jsxs("div",{className:"min-w-0",children:[r.jsx(nr,{ref:p,type:"number",min:1,step:1,inputMode:"numeric",value:g,onChange:o=>v(o.target.value),onKeyDown:o=>{o.key==="Enter"&&(o.preventDefault(),j())},placeholder:x("goToLineDialog.field.linePlaceholder"),className:"h-8 w-full rounded-md border-border/70 bg-background/60 typography-ui-label"}),r.jsx("div",{className:"mt-2 rounded-md bg-primary/15 px-3 py-1.5 typography-ui-label text-foreground/95",children:T})]})})}const Fo=(a,e)=>{const s=e.trim().toLowerCase(),d=[];if(!s)return d;const x=a.toLowerCase();let g=0;for(;;){const v=x.indexOf(s,g);if(v===-1)break;d.push({start:v,end:v+s.length}),g=v+s.length}return d},Lr="data-md-find",gs="data-md-find-current",ci="rounded-[2px] bg-status-warning/30 text-foreground",No="rounded-[2px] bg-status-warning/60 text-foreground",Co=120,So=a=>a instanceof Element&&a.hasAttribute(Lr),ko=a=>a.target instanceof Element&&a.target.hasAttribute(Lr)?!0:[...a.addedNodes].some(e=>So(e)),ui=a=>{const e=new Set;a.querySelectorAll(`mark[${Lr}]`).forEach(s=>{const d=s.parentNode;d&&(d.replaceChild(document.createTextNode(s.textContent??""),s),e.add(d))}),e.forEach(s=>s.normalize())},Ro=(a,e)=>{ui(a);const s=e.trim().toLowerCase();if(!s)return[];const d=[],x=document.createTreeWalker(a,NodeFilter.SHOW_TEXT,{acceptNode(v){const b=v.parentElement;return!b||b.closest("svg, script, style")?NodeFilter.FILTER_REJECT:NodeFilter.FILTER_ACCEPT}}),g=[];for(;x.nextNode();){const v=x.currentNode;v instanceof Text&&g.push(v)}for(const v of g){const b=v.nodeValue??"";if(!b)continue;const f=Fo(b,s);if(f.length===0)continue;const C=v.parentNode;if(!C)continue;const p=document.createDocumentFragment();let F=0;for(const N of f){N.start>F&&p.appendChild(document.createTextNode(b.slice(F,N.start)));const R=document.createElement("mark");R.setAttribute(Lr,""),R.className=ci,R.textContent=b.slice(N.start,N.end),p.appendChild(R),d.push(R),F=N.end}F<b.length&&p.appendChild(document.createTextNode(b.slice(F))),C.replaceChild(p,v)}return d},qn=({containerRef:a,open:e,onOpenChange:s,focusNonce:d,className:x})=>{const{t:g}=$t(),[v,b]=n.useState(""),[f,C]=n.useState(0),[p,F]=n.useState(0),N=n.useRef(null),R=n.useRef([]),j=n.useRef(v);j.current=v;const T=n.useRef(null),o=n.useRef(null),A=n.useCallback((S,M=!1)=>{const $=a.current;if(!$){R.current=[],C(0),F(0);return}R.current=Ro($,S);const P=R.current.length;C(P),F(X=>!M||P===0?0:Math.min(X,P-1))},[a]),I=n.useCallback((S,M=!1)=>{T.current&&clearTimeout(T.current),T.current=setTimeout(()=>{T.current=null,A(S,M)},Co)},[A]);n.useEffect(()=>()=>{T.current&&clearTimeout(T.current)},[]);const W=n.useCallback(()=>{s(!1);const S=o.current;o.current=null,S?.isConnected&&S.focus()},[s]);n.useEffect(()=>{const S=a.current;if(!e||!S)return;const M=new MutationObserver($=>{!j.current.trim()||!$.some(X=>!ko(X))||I(j.current,!0)});return M.observe(S,{childList:!0,subtree:!0,characterData:!0}),()=>{M.disconnect(),ui(S)}},[a,e,I]),n.useEffect(()=>{if(!e)return;const S=document.activeElement;S instanceof HTMLElement&&!o.current&&(o.current=S),N.current?.focus()},[e]),n.useEffect(()=>{e&&d>0&&(N.current?.focus(),N.current?.select())},[e,d]),n.useEffect(()=>{const S=a.current;if(!S||(S.querySelectorAll(`mark[${gs}]`).forEach($=>{$.removeAttribute(gs),$.className=ci}),f===0))return;const M=R.current[Math.min(Math.max(p,0),f-1)];M&&(M.setAttribute(gs,""),M.className=No,M.scrollIntoView({block:"nearest"}))},[a,p,f]);const L=n.useCallback(()=>{F(S=>f===0?0:(S+1)%f)},[f]),E=n.useCallback(()=>{F(S=>f===0?0:(S-1+f)%f)},[f]),V=n.useCallback(S=>{S.key==="Enter"?(S.preventDefault(),S.shiftKey?E():L()):S.key==="Escape"&&(S.preventDefault(),W())},[W,L,E]);return e?r.jsxs("div",{className:G("absolute right-3 top-3 z-10 flex items-center gap-1 rounded-lg border border-border/60 bg-[var(--surface-elevated)] px-1.5 py-1 shadow-lg",x),children:[r.jsx(y,{name:"search",className:"ml-0.5 size-3.5 text-muted-foreground"}),r.jsx(nr,{ref:N,value:v,onChange:S=>{b(S.target.value),I(S.target.value)},onKeyDown:V,placeholder:g("filesView.preview.find.placeholder"),"aria-label":g("filesView.preview.find.placeholder"),className:"h-7 w-40 rounded-md px-2 py-0 text-sm md:w-56"}),r.jsx("span",{className:"min-w-12 px-1 text-center typography-micro text-muted-foreground tabular-nums","aria-live":"polite","aria-label":f>0?g("filesView.preview.find.countAria",{current:p+1,total:f}):g("filesView.preview.find.noMatches"),children:v.trim()&&f===0?g("filesView.preview.find.noMatches"):f>0?`${p+1}/${f}`:""}),r.jsx(z,{type:"button",variant:"ghost",size:"sm",className:"size-6 p-0 text-muted-foreground",onClick:E,title:g("filesView.preview.find.previousAria"),"aria-label":g("filesView.preview.find.previousAria"),disabled:f===0,children:r.jsx(y,{name:"arrow-up",className:"size-3.5"})}),r.jsx(z,{type:"button",variant:"ghost",size:"sm",className:"size-6 p-0 text-muted-foreground",onClick:L,title:g("filesView.preview.find.nextAria"),"aria-label":g("filesView.preview.find.nextAria"),disabled:f===0,children:r.jsx(y,{name:"arrow-down",className:"size-3.5"})}),r.jsx(z,{type:"button",variant:"ghost",size:"sm",className:"size-6 p-0 text-muted-foreground",onClick:W,title:g("filesView.preview.find.closeAria"),"aria-label":g("filesView.preview.find.closeAria"),children:r.jsx(y,{name:"close",className:"size-3.5"})})]}):null},To=a=>{let e=!0;return{poll:async()=>{if(!e||a.isDirty())return!1;const s=a.getLoadedContent(),d=a.getLoadedRevision();try{const x=await a.readContent();if(!e||a.isDirty()||d!==a.getLoadedRevision())return!1;if(x===s)return!0;const g=await a.readContent();return!e||a.isDirty()||g!==x||d!==a.getLoadedRevision()?!1:(a.applyContent(x),!0)}catch{return!1}},dispose:()=>{e=!1}}},Vo=1,Eo=(a,e)=>e.size!==a.size||e.mtimeMs!==void 0&&a.mtimeMs!==void 0&&Math.abs(e.mtimeMs-a.mtimeMs)>=Vo;function Xn(){const a=pt.c(8),[e]=us.useState(Do),s=us.useRef(!1);let d;a[0]!==e?(d=f=>{if(f==null){e.cleanUp(),s.current=!1;return}s.current||(s.current=!0,e.setup(f,f.firstElementChild??void 0))},a[0]=e,a[1]=d):d=a[1];const x=d;let g,v;a[2]!==e?(g=()=>()=>{s.current=!1,e.cleanUp()},v=[e],a[2]=e,a[3]=g,a[4]=v):(g=a[3],v=a[4]),us.useLayoutEffect(g,v);let b;return a[5]!==x||a[6]!==e?(b={virtualizer:e,setScroller:x},a[5]=x,a[6]=e,a[7]=b):b=a[7],b}function Do(){return new no}function Po(a){return!(!a.autoSaveEnabled||!a.isDirty||!a.canWrite||a.isSaving||a.fileLoading||a.isNonEditableBinary||!a.selectedFilePath||a.loadedFilePath!==a.selectedFilePath)}function Mo(a){return a.selectedFilePath?a.isDirty?!(a.fileLoading||a.loadedFilePath!==a.selectedFilePath||a.isNonEditableBinary||a.draftContent===""&&a.fileContent!==""&&a.loadedFilePath!==a.selectedFilePath):!0:!1}const zo='<mxfile><diagram id="new" name="Page-1"><mxGraphModel dx="0" dy="0" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="827" pageHeight="1169" math="0" shadow="0"><root><mxCell id="0"/><mxCell id="1" parent="0"/></root></mxGraphModel></diagram></mxfile>';function Jn(){if(typeof document>"u")return!1;const a=document.documentElement.getAttribute("data-theme");return a==="dark"||!a&&window.matchMedia("(prefers-color-scheme: dark)").matches}const Lo=n.forwardRef(function({xml:e,readOnly:s,className:d,onChange:x},g){const v=n.useRef(e),b=n.useRef(null),f=n.useRef(!1),[C,p]=n.useState(Jn),F=n.useRef(e),N=n.useRef(e);N.current!==e&&(N.current=e,F.current=e,v.current=e);const R=n.useRef(C);R.current!==C&&(R.current=C,F.current=v.current);const j=n.useRef(null);n.useEffect(()=>{const A=()=>p(Jn());A();const I=new MutationObserver(A);return I.observe(document.documentElement,{attributes:!0,attributeFilter:["data-theme"]}),()=>I.disconnect()},[]),n.useEffect(()=>{const A=setTimeout(()=>{j.current?.querySelector(".diagrams-iframe")?.focus()},600);return()=>clearTimeout(A)},[]),n.useImperativeHandle(g,()=>({getXml:()=>v.current}));const T=n.useCallback(()=>{!e&&!f.current&&(f.current=!0,setTimeout(()=>{b.current?.template({})},500))},[e]),o=n.useCallback(A=>{v.current=A.xml,x?.(A.xml)},[x]);return r.jsx("div",{ref:j,className:G("h-full w-full",d),children:r.jsx(oo,{ref:b,xml:F.current||zo,autosave:!0,urlParameters:{ui:s?"simple":C?"dark":"kennedy",spin:!0,libraries:!s,chrome:s,nav:s,layers:s,noSaveBtn:!0,noExitBtn:!0,saveAndExit:!1},onLoad:T,onAutoSave:o},C?"dark":"light")})}),Ao=a=>{const e=K(a);if(!e)return"";if(e==="/"||/^[A-Za-z]:\/$/.test(e))return e;const s=e.lastIndexOf("/");if(s<0)return e;if(s===0)return"/";const d=e.slice(0,s);return/^[A-Za-z]:$/.test(d)?`${d}/`:d},Io=a=>{const e=pt.c(8),{label:s,iconDataUrl:d}=a,[x,g]=n.useState(!1);let v;e[0]!==s?(v=s.trim().slice(0,1).toUpperCase()||"?",e[0]=s,e[1]=v):v=e[1];const b=v;if(d&&!x){let p;e[2]===Symbol.for("react.memo_cache_sentinel")?(p=()=>g(!0),e[2]=p):p=e[2];let F;return e[3]!==d?(F=r.jsx("img",{src:d,alt:"",className:"size-4 rounded-sm",onError:p}),e[3]=d,e[4]=F):F=e[4],F}let f;e[5]===Symbol.for("react.memo_cache_sentinel")?(f=G("size-4 rounded-sm flex items-center justify-center","bg-[var(--surface-muted)] text-[9px] font-medium text-muted-foreground"),e[5]=f):f=e[5];let C;return e[6]!==b?(C=r.jsx("span",{className:f,children:b}),e[6]=b,e[7]=C):C=e[7],C},Oo=a=>a.slice().sort((e,s)=>e.type!==s.type?e.type==="directory"?-1:1:e.name.localeCompare(s.name)),K=a=>{if(!a)return"";const e=a.replace(/\\/g,"/"),s=e.startsWith("//");let d=e.replace(/\/+/g,"/");s&&!d.startsWith("//")&&(d=`/${d}`);const x=d==="/",g=/^[A-Za-z]:\/$/.test(d);return!x&&!g&&(d=d.replace(/\/+$/,"")),d},Bo=a=>a.startsWith("/")||a.startsWith("//")||/^[A-Za-z]:\//.test(a),Bt=a=>/^[A-Za-z]:\//.test(a)?a.toLowerCase():a,zr=(a,e)=>{const s=K(e),d=K(a);if(!s||!d)return!1;const x=Bt(s),g=Bt(d);return g===x||g.startsWith(`${x}/`)},Yn=(a,e)=>{const s=K(e),d=K(a);if(!zr(d,s))return[];const g=d.slice(s.length).replace(/^\//,"").split("/"),v=[];let b=s;for(let f=0;f<g.length-1;f++)b=b?`${b}/${g[f]}`:g[f],v.push(b);return v},Pr=(a,e)=>{if(!e)return"";const s=K(e);if(!a||!zr(s,a))return s;const d=s.slice(a.length);return d.startsWith("/")?d.slice(1):d},$o=new Set(["node_modules"]),Wo=a=>{const e=pt.c(3),{status:s}=a;let d;e[0]===Symbol.for("react.memo_cache_sentinel")?(d={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]=d):d=e[0];const x=d[s];let g;return e[1]!==x?(g=r.jsx("span",{className:"size-2 rounded-full",style:{backgroundColor:x}}),e[1]=x,e[2]=g):g=e[2],g},Zn=a=>{const e=pt.c(11),{name:s}=a,d=n.useRef(null),x=n.useRef(null),[g,v]=n.useState(!1);let b;e[0]===Symbol.for("react.memo_cache_sentinel")?(b=()=>{const N=d.current,R=x.current;if(!N||!R)return;const j=()=>{v(R.scrollWidth>N.clientWidth+1)};j();const T=new ResizeObserver(j);return T.observe(N),T.observe(R),()=>{T.disconnect()}},e[0]=b):b=e[0];let f;e[1]!==s?(f=[s],e[1]=s,e[2]=f):f=e[2],n.useLayoutEffect(b,f);let C;e[3]!==s?(C=r.jsx("span",{ref:x,"aria-hidden":"true",className:"invisible absolute whitespace-nowrap",children:s}),e[3]=s,e[4]=C):C=e[4];let p;e[5]!==s||e[6]!==g?(p=g?r.jsxs("span",{className:"open-file-name-marquee-track",children:[r.jsx("span",{className:"open-file-name-marquee-item",children:s}),r.jsx("span",{className:"open-file-name-marquee-item","aria-hidden":"true",children:s})]}):r.jsx("span",{className:"block min-w-0 truncate",children:s}),e[5]=s,e[6]=g,e[7]=p):p=e[7];let F;return e[8]!==C||e[9]!==p?(F=r.jsxs("span",{ref:d,className:"relative block min-w-0 flex-1 overflow-hidden whitespace-nowrap",children:[C,p]}),e[8]=C,e[9]=p,e[10]=F):F=e[10],F},_o=a=>$o.has(a),Uo=a=>{const e=K(a);return e==="node_modules"||e.endsWith("/node_modules")||e.includes("/node_modules/")},Ko=a=>{const s=(a instanceof Error?a.message:String(a??"")).toLowerCase();return s.includes("is a directory")||s.includes("eisdir")},Qn=a=>{const s=(a instanceof Error?a.message:String(a??"")).toLowerCase();return s.includes("file not found")||s.includes("enoent")||s.includes("no such file")||s.includes("does not exist")},Ot=2e5,Ho=2e5;function Go(a){const e=a.length>400?`${a.slice(0,200)}${a.slice(-200)}`:a;let s=2166136261;for(let d=0;d<e.length;d+=1)s^=e.charCodeAt(d),s=s+((s<<1)+(s<<4)+(s<<7)+(s<<8)+(s<<24))>>>0;return`${a.length}:${s.toString(16)}`}const qo=a=>{let e=0,s=0;for(let d=0;d<a.length;d+=1)a.charCodeAt(d)===10&&(d>0&&a.charCodeAt(d-1)===13?e+=1:s+=1);return e>s?`\r
5
- `:`
6
- `},di=a=>a.replace(/\r\n/g,`
7
- `).replace(/\r/g,`
8
- `),Xo=(a,e)=>{const s=di(a);return e===`\r
9
- `?s.replace(/\n/g,`\r
10
- `):s},fi=(a,e)=>r.jsx(Er,{filePath:a,extension:e}),ei=a=>{if(!a)return!1;const e=a.toLowerCase().split(".").pop();return e==="md"||e==="markdown"},Jo=a=>{if(!a)return!1;const e=a.toLowerCase().split(".").pop();return e==="json"||e==="jsonc"||e==="json5"||e==="geojson"},xs=a=>{if(!a)return!1;const e=a.toLowerCase().split(".").pop();return e==="html"||e==="htm"},Yo=a=>{const e=pt.c(76),{node:s,root:d,isExpanded:x,isActive:g,isMobile:v,isBrowserClient:b,alwaysShowActions:f,status:C,badge:p,permissions:F,downloadFile:N,contextMenuPath:R,setContextMenuPath:j,rightClickMenuPath:T,setRightClickMenuPath:o,onSelect:A,onToggle:I,onRevealPath:W,onOpenDialog:L}=a,{t:E}=$t(),V=s.type==="directory",{canRename:S,canCreateFile:M,canCreateFolder:$,canDelete:P,canReveal:X}=F,Ne=!V&&!!N,_=X&&!b,Z=S||M||$||P||Ne||_;let ee;e[0]!==Z||e[1]!==s.path||e[2]!==o?(ee=fe=>{Z&&(fe?.preventDefault(),o(s.path))},e[0]=Z,e[1]=s.path,e[2]=o,e[3]=ee):ee=e[3];const le=ee;let te;e[4]!==V||e[5]!==s||e[6]!==A||e[7]!==I?(te=()=>{V?I(s.path):A(s)},e[4]=V,e[5]=s,e[6]=A,e[7]=I,e[8]=te):te=e[8];const Ce=te;let O;e[9]!==s.path||e[10]!==j||e[11]!==o?(O=fe=>{fe.stopPropagation(),o(null),j(s.path)},e[9]=s.path,e[10]=j,e[11]=o,e[12]=O):O=e[12];const xe=O;let ve;e[13]!==M||e[14]!==$||e[15]!==P||e[16]!==S||e[17]!==_||e[18]!==N||e[19]!==b||e[20]!==V||e[21]!==s||e[22]!==L||e[23]!==W||e[24]!==d||e[25]!==E?(ve=fe=>{const{Item:pe,Separator:et}=fe;return r.jsxs(r.Fragment,{children:[S&&r.jsxs(pe,{onClick:q=>{q.stopPropagation(),L("rename",s)},children:[r.jsx(y,{name:"edit",className:"mr-2 size-4"})," ",E("sidebarFilesTree.menu.rename")]}),r.jsxs(pe,{onClick:q=>{q.stopPropagation(),Mr(s.path).then(at=>{if(at.ok){Y.success(E("sidebarFilesTree.toast.pathCopied"));return}Y.error(E("sidebarFilesTree.toast.copyFailed"))})},children:[r.jsx(y,{name:"file-copy",className:"mr-2 size-4"})," ",E("sidebarFilesTree.menu.copyPath")]}),r.jsxs(pe,{onClick:q=>{q.stopPropagation();const at=Pr(d,s.path)||s.path;Mr(at).then(me=>{if(me.ok){Y.success(E("filesView.toast.relativePathCopied"));return}Y.error(E("sidebarFilesTree.toast.copyFailed"))})},children:[r.jsx(y,{name:"file-copy-2",className:"mr-2 size-4"})," ",E("filesView.tree.menu.copyRelativePath")]}),!V&&N&&r.jsxs(pe,{onClick:q=>{q.stopPropagation(),N(s.path).catch(at=>{console.error("Download failed:",at),Y.error(E("sidebarFilesTree.toast.operationFailed"))})},children:[r.jsx(y,{name:"download",className:"mr-2 size-4"})," ",E(b?"sidebarFilesTree.menu.download":"sidebarFilesTree.menu.save")]}),_&&r.jsxs(pe,{onClick:q=>{q.stopPropagation(),W(s.path)},children:[r.jsx(y,{name:"folder-received",className:"mr-2 size-4"})," ",E(Ua())]}),V&&(M||$)&&r.jsxs(r.Fragment,{children:[r.jsx(et,{}),M&&r.jsxs(pe,{onClick:q=>{q.stopPropagation(),L("createFile",s)},children:[r.jsx(y,{name:"file-add",className:"mr-2 size-4"})," ",E("sidebarFilesTree.menu.newFile")]}),$&&r.jsxs(pe,{onClick:q=>{q.stopPropagation(),L("createFolder",s)},children:[r.jsx(y,{name:"folder-add",className:"mr-2 size-4"})," ",E("sidebarFilesTree.menu.newFolder")]})]}),P&&r.jsxs(r.Fragment,{children:[r.jsx(et,{}),r.jsxs(pe,{onClick:q=>{q.stopPropagation(),L("delete",s)},className:"text-destructive focus:text-destructive",children:[r.jsx(y,{name:"delete-bin",className:"mr-2 size-4"})," ",E("sidebarFilesTree.menu.delete")]})]})]})},e[13]=M,e[14]=$,e[15]=P,e[16]=S,e[17]=_,e[18]=N,e[19]=b,e[20]=V,e[21]=s,e[22]=L,e[23]=W,e[24]=d,e[25]=E,e[26]=ve):ve=e[26];const ce=ve,ue=T===s.path;let we;e[27]!==s.path||e[28]!==o?(we=fe=>o(fe?s.path:null),e[27]=s.path,e[28]=o,e[29]=we):we=e[29];const B=v?void 0:le;let H;e[30]!==B?(H=r.jsx("div",{className:"group relative flex items-center",onContextMenu:B}),e[30]=B,e[31]=H):H=e[31];const re=v?void 0:le,se=g?"bg-interactive-selection/70":"hover:bg-interactive-hover/40";let Se;e[32]!==se?(Se=G("flex w-full items-center gap-1.5 rounded-md px-2 py-1 text-left text-foreground transition-colors pr-8 select-none",se),e[32]=se,e[33]=Se):Se=e[33];let ae;e[34]!==V||e[35]!==x||e[36]!==s.extension||e[37]!==s.path?(ae=V?x?r.jsx(y,{name:"folder-open",className:"size-4 flex-shrink-0 text-muted-foreground"}):r.jsx(y,{name:"folder-3",className:"size-4 flex-shrink-0 text-muted-foreground"}):fi(s.path,s.extension),e[34]=V,e[35]=x,e[36]=s.extension,e[37]=s.path,e[38]=ae):ae=e[38];let oe;e[39]!==s.name||e[40]!==s.path?(oe=r.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta",title:s.path,children:s.name}),e[39]=s.name,e[40]=s.path,e[41]=oe):oe=e[41];let be;e[42]!==V||e[43]!==C?(be=!V&&C&&r.jsx(Wo,{status:C}),e[42]=V,e[43]=C,e[44]=be):be=e[44];let Te;e[45]!==p||e[46]!==V?(Te=V&&p&&r.jsxs("span",{className:"text-xs flex items-center gap-1 ml-auto mr-1",children:[p.modified>0&&r.jsxs("span",{className:"text-[var(--status-warning)]",children:["M",p.modified]}),p.added>0&&r.jsxs("span",{className:"text-[var(--status-success)]",children:["+",p.added]})]}),e[45]=p,e[46]=V,e[47]=Te):Te=e[47];let de;e[48]!==Ce||e[49]!==Se||e[50]!==ae||e[51]!==oe||e[52]!==be||e[53]!==Te||e[54]!==re?(de=r.jsxs("button",{type:"button",onClick:Ce,onContextMenu:re,className:Se,children:[ae,oe,be,Te]}),e[48]=Ce,e[49]=Se,e[50]=ae,e[51]=oe,e[52]=be,e[53]=Te,e[54]=re,e[55]=de):de=e[55];let Ve;e[56]!==f||e[57]!==R||e[58]!==xe||e[59]!==Z||e[60]!==v||e[61]!==s.path||e[62]!==ce||e[63]!==j?(Ve=Z&&r.jsx("div",{className:G("absolute right-1 top-1/2 -translate-y-1/2",f?"opacity-100":"opacity-0 focus-within:opacity-100 group-hover:opacity-100"),children:r.jsxs(vs,{open:R===s.path,onOpenChange:fe=>j(fe?s.path:null),children:[r.jsx(ws,{asChild:!0,children:r.jsx(z,{variant:"ghost",size:"icon",className:"size-6",onClick:xe,children:r.jsx(y,{name:"more-2-fill",className:"size-4"})})}),r.jsx(bs,{align:"end",side:"bottom",onCloseAutoFocus:()=>j(null),children:ce({Item:Dr,Separator:_a})})]})}),e[56]=f,e[57]=R,e[58]=xe,e[59]=Z,e[60]=v,e[61]=s.path,e[62]=ce,e[63]=j,e[64]=Ve):Ve=e[64];let Ee;e[65]!==de||e[66]!==Ve||e[67]!==H?(Ee=r.jsxs(Xa,{render:H,children:[de,Ve]}),e[65]=de,e[66]=Ve,e[67]=H,e[68]=Ee):Ee=e[68];let ke;e[69]!==ce?(ke=r.jsx(Ha,{className:"min-w-[180px]",children:ce({Item:qa,Separator:Ga})}),e[69]=ce,e[70]=ke):ke=e[70];let Q;return e[71]!==Ee||e[72]!==ke||e[73]!==ue||e[74]!==we?(Q=r.jsxs(Ja,{open:ue,onOpenChange:we,children:[Ee,ke]}),e[71]=Ee,e[72]=ke,e[73]=ue,e[74]=we,e[75]=Q):Q=e[75],Q},Zo=a=>{const e=pt.c(83),{activeDialog:s,dialogData:d,dialogInputValue:x,onDialogInputChange:g,isDialogSubmitting:v,onDialogSubmit:b,onClose:f,inputRef:C}=a,{t:p}=$t(),F=!!s;let N;e[0]!==f?(N=O=>!O&&f(),e[0]=f,e[1]=N):N=e[1];let R;e[2]!==s||e[3]!==p?(R=s==="createFile"&&p("filesView.dialog.createFile.title"),e[2]=s,e[3]=p,e[4]=R):R=e[4];let j;e[5]!==s||e[6]!==p?(j=s==="createFolder"&&p("filesView.dialog.createFolder.title"),e[5]=s,e[6]=p,e[7]=j):j=e[7];let T;e[8]!==s||e[9]!==p?(T=s==="rename"&&p("filesView.dialog.rename.title"),e[8]=s,e[9]=p,e[10]=T):T=e[10];let o;e[11]!==s||e[12]!==p?(o=s==="delete"&&p("filesView.dialog.delete.title"),e[11]=s,e[12]=p,e[13]=o):o=e[13];let A;e[14]!==R||e[15]!==j||e[16]!==T||e[17]!==o?(A=r.jsxs(ai,{children:[R,j,T,o]}),e[14]=R,e[15]=j,e[16]=T,e[17]=o,e[18]=A):A=e[18];let I;e[19]!==s||e[20]!==d?.path||e[21]!==p?(I=s==="createFile"&&p("filesView.dialog.createFile.description",{path:d?.path??p("filesView.dialog.rootFallback")}),e[19]=s,e[20]=d?.path,e[21]=p,e[22]=I):I=e[22];let W;e[23]!==s||e[24]!==d?.path||e[25]!==p?(W=s==="createFolder"&&p("filesView.dialog.createFolder.description",{path:d?.path??p("filesView.dialog.rootFallback")}),e[23]=s,e[24]=d?.path,e[25]=p,e[26]=W):W=e[26];let L;e[27]!==s||e[28]!==d?.name||e[29]!==p?(L=s==="rename"&&p("filesView.dialog.rename.description",{name:d?.name??""}),e[27]=s,e[28]=d?.name,e[29]=p,e[30]=L):L=e[30];let E;e[31]!==s||e[32]!==d?.name||e[33]!==p?(E=s==="delete"&&p("filesView.dialog.delete.description",{name:d?.name??""}),e[31]=s,e[32]=d?.name,e[33]=p,e[34]=E):E=e[34];let V;e[35]!==L||e[36]!==E||e[37]!==I||e[38]!==W?(V=r.jsxs(oi,{children:[I,W,L,E]}),e[35]=L,e[36]=E,e[37]=I,e[38]=W,e[39]=V):V=e[39];let S;e[40]!==V||e[41]!==A?(S=r.jsxs(ii,{children:[A,V]}),e[40]=V,e[41]=A,e[42]=S):S=e[42];let M;e[43]!==s||e[44]!==x||e[45]!==C||e[46]!==g||e[47]!==b||e[48]!==p?(M=s!=="delete"&&r.jsx("div",{className:"py-4",children:r.jsx(nr,{value:x,onChange:O=>g(O.target.value),placeholder:p(s==="rename"?"filesView.dialog.rename.placeholder":"filesView.dialog.namePlaceholder"),onKeyDown:O=>{O.key==="Enter"&&b()},ref:C})}),e[43]=s,e[44]=x,e[45]=C,e[46]=g,e[47]=b,e[48]=p,e[49]=M):M=e[49];let $;e[50]!==p?($=p("filesView.dialog.cancel"),e[50]=p,e[51]=$):$=e[51];let P;e[52]!==v||e[53]!==f||e[54]!==$?(P=r.jsx(z,{variant:"outline",onClick:f,disabled:v,children:$}),e[52]=v,e[53]=f,e[54]=$,e[55]=P):P=e[55];const X=s==="delete"?"destructive":"default";let Ne;e[56]!==b?(Ne=()=>{b()},e[56]=b,e[57]=Ne):Ne=e[57];let _;e[58]!==s||e[59]!==x||e[60]!==v?(_=v||s!=="delete"&&!x.trim(),e[58]=s,e[59]=x,e[60]=v,e[61]=_):_=e[61];let Z;e[62]!==s||e[63]!==v||e[64]!==p?(Z=v?r.jsx(y,{name:"loader-4",className:"size-4 animate-spin"}):p(s==="delete"?"filesView.dialog.delete.confirm":"filesView.dialog.confirm"),e[62]=s,e[63]=v,e[64]=p,e[65]=Z):Z=e[65];let ee;e[66]!==X||e[67]!==Ne||e[68]!==_||e[69]!==Z?(ee=r.jsx(z,{variant:X,onClick:Ne,disabled:_,children:Z}),e[66]=X,e[67]=Ne,e[68]=_,e[69]=Z,e[70]=ee):ee=e[70];let le;e[71]!==P||e[72]!==ee?(le=r.jsxs(li,{children:[P,ee]}),e[71]=P,e[72]=ee,e[73]=le):le=e[73];let te;e[74]!==C||e[75]!==S||e[76]!==M||e[77]!==le?(te=r.jsxs(ni,{initialFocus:C,children:[S,M,le]}),e[74]=C,e[75]=S,e[76]=M,e[77]=le,e[78]=te):te=e[78];let Ce;return e[79]!==F||e[80]!==N||e[81]!==te?(Ce=r.jsx(si,{open:F,onOpenChange:N,children:te}),e[79]=F,e[80]=N,e[81]=te,e[82]=Ce):Ce=e[82],Ce},ti=(a,e,s)=>{const d=pt.c(8),[x,g]=n.useState(""),[v,b]=n.useState(0);let f,C;d[0]!==a||d[1]!==s||d[2]!==e?(f=()=>{if(!a){g("");return}let F=!1;g("");const N=va(),R=wa(N);ba(N).then(T=>{F||!T||(g(a),e(null))}).catch(T=>{F||(e(T instanceof Error?T.message:s),g(a))});const j=ya(()=>{F||(g(a),b(Qo),e(null))});return()=>{F=!0,R(),j()}},C=[a,e,s],d[0]=a,d[1]=s,d[2]=e,d[3]=f,d[4]=C):(f=d[3],C=d[4]),n.useEffect(f,C);let p;return d[5]!==v||d[6]!==x?(p={readyKey:x,nonce:v},d[5]=v,d[6]=x,d[7]=p):p=d[7],p},bu=({mode:a="full"})=>{const{t:e}=$t(),{files:s,runtime:d}=Sa(),{currentTheme:x,availableThemes:g,lightThemeId:v,darkThemeId:b}=ka(),{isMobile:f,isTablet:C,screenWidth:p}=Ra(),F=fa(d.platform),N=f||C,R=ma(),j=ha(),T=ri()??"",o=K(T.trim()),A=a!=="editor-only",I=a==="editor-only"&&!f,W=pa(t=>t.searchFiles),L=Ta(T),[E,V]=n.useState(""),S=Va(E,200),M=n.useRef(null),[$,P]=n.useState(!1),[X,Ne]=n.useState(!0),[_,Z]=n.useState(!1),[ee,le]=n.useState(!1),te=n.useRef(0),Ce=n.useCallback(t=>{te.current=Math.max(0,te.current+(t?1:-1))},[]),[O,xe]=n.useState("edit"),[ve,ce]=n.useState("edit"),[ue,we]=n.useState("tree"),[B,H]=n.useState("edit"),[re,se]=n.useState("preview"),[Se,ae]=n.useState(0),oe=n.useRef({}),be=n.useRef({}),Te=n.useRef({}),de=n.useRef({}),Ve=n.useMemo(()=>g.find(t=>t.metadata.id===v)??zn(!1),[g,v]),Ee=n.useMemo(()=>g.find(t=>t.metadata.id===b)??zn(!0),[g,b]);n.useEffect(()=>{Un(Ve),Un(Ee)},[Ve,Ee]);const ke=n.useMemo(()=>[],[]),Q=Ge(t=>o?t.byRoot[o]?.openPaths??ke:ke),fe=Ge(t=>o?t.byRoot[o]?.selectedPath??null:null),pe=Ge(t=>o?t.byRoot[o]?.expandedPaths??ke:ke),et=Ge(t=>t.removeOpenPath),q=Ge(t=>t.removeOpenPathsByPrefix),at=Ge(t=>t.removeExpandedPathsByPrefix),me=Ge(t=>t.setSelectedPath),ys=Ge(t=>t.toggleExpandedPath),ir=Ge(t=>t.expandPaths),Ft=n.useCallback(t=>{const i=K(t),l=i.split("/"),u=l[l.length-1]||i,h=u.includes(".")?u.split(".").pop()?.toLowerCase():void 0;return{name:u,path:i,type:"file",extension:h}},[]),Nt=n.useMemo(()=>Q.map(Ft),[Q,Ft]),Ar=n.useMemo(()=>{if(fe){const t=Bt(fe);if(Q.some(i=>Bt(i)===t))return fe}return Q[0]??null},[Q,fe]),c=n.useMemo(()=>Ar?Ft(Ar):null,[Ar,Ft]),qe=c?.path??"",[,mi]=n.useState(0);n.useEffect(()=>{if(!o||!fe)return;const t=Bt(fe);Q.some(l=>Bt(l)===t)||me(o,Q[0]??null)},[Q,o,fe,me]);const ar=!!(o&&qe&&!zr(qe,o)),js=ar?Ln(qe):void 0,gt=n.useMemo(()=>({allowOutsideWorkspace:a==="editor-only"&&ar,outsideFileGrant:js,directory:o||void 0}),[a,ar,js,o]),Xe=n.useCallback(async t=>{const i=Ln(t),l=await Ea(t,o,a==="editor-only");return l.outsideFileGrant&&l.outsideFileGrant!==i&&mi(u=>u+1),l},[a,o]),Ir=n.useRef(null),[Fs,hi]=n.useState({left:!1,right:!1}),Ns=n.useCallback(()=>{const t=Ir.current;t&&hi({left:t.scrollLeft>2,right:t.scrollLeft+t.clientWidth<t.scrollWidth-2})},[]),Cs=n.useRef(Ns);Cs.current=Ns,n.useEffect(()=>{const t=Ir.current;if(!t)return;const i=()=>Cs.current();i(),t.addEventListener("scroll",i,{passive:!0});const l=new ResizeObserver(i);return l.observe(t),()=>{t.removeEventListener("scroll",i),l.disconnect()}},[Nt.length]);const[Ss,Or]=n.useState({}),[or,Wt]=n.useState({}),ze=n.useRef(new Set),Le=n.useRef(new Set),tt=n.useRef(new Map),ks=n.useRef(0),[Rs,lr]=n.useState([]),[pi,cr]=n.useState(!1),[D,he]=n.useState(""),{isPlaying:ur,play:gi,stop:xi}=Da(),[Ae,ot]=n.useState(!1),[rt,ge]=n.useState(null),[vi,Ie]=n.useState(""),[De,ne]=n.useState(null),[ie,ye]=n.useState(""),[_t,Br]=n.useState(!1),[Ts,wi]=n.useState(`
11
- `),bi=n.useRef(null),Je=n.useRef(null),Pe=n.useRef(null),lt=n.useRef(""),Ut=n.useRef(""),st=n.useRef(null),Vs=n.useRef(null),We=n.useRef(null),$r=n.useRef(""),Wr=n.useRef(0),Kt=n.useRef(0),Ct=n.useRef(null),[dr,yi]=n.useState(0),[ji,St]=n.useState("idle"),[Fi,fr]=n.useState(!1),[xt,Es]=n.useState(!1),je=ht(t=>t.autoSaveEnabled),Ni=ht(t=>t.setAutoSaveEnabled),[_r,Ht]=n.useState(!1),kt=n.useRef(null),Gt=n.useRef(null),qt=n.useRef(!1),Xt=n.useRef(null),Jt=n.useRef(null),_e=n.useRef(null),mr=n.useRef(null),[Ci,Ur]=n.useState(0),Rt=n.useRef(null),vt=n.useRef({key:"",attempts:0});n.useEffect(()=>()=>{Rt.current!==null&&typeof window<"u"&&(window.cancelAnimationFrame(Rt.current),Rt.current=null)},[]);const[wt,Kr]=n.useState(null),[bt,Si]=n.useState(null),[ct,Ds]=n.useState(""),[ki,Hr]=n.useState(!1),[Ri,Ti]=n.useState(null),[Vi,Ei]=n.useState(null),[Di,Ps]=n.useState(!1),[Pi,Ms]=n.useState(!1),[Mi,Gr]=n.useState(!1),[zs,hr]=n.useState(!1),[Ls,As]=n.useState(0),pr=n.useRef(null),gr=n.useCallback(t=>{const i=t?.currentTarget??pr.current;if(!i)return;const l=document.activeElement;l&&l!==document.body&&l!==i&&(Pa(l)||i.contains(l))||i.focus({preventScroll:!0})},[]),qr=n.useRef(null),Is=!!s.writeFile,Os=!!s.createDirectory,Bs=!!s.rename,$s=!!s.delete,Ws=!!s.revealPath,zi=Vr(t=>t.availableApps),Li=Vr(t=>t.isCacheStale),_s=Vr(t=>t.initialize),Ai=Vr(t=>t.loadInstalledApps);n.useEffect(()=>{_s()},[_s]);const Ii=n.useCallback(t=>{s.revealPath&&s.revealPath(t).catch(()=>{Y.error(e("sidebarFilesTree.toast.revealFailed"))})},[s,e]),Oi=n.useCallback(async t=>{if(!c?.path||await ga(c.path,t.id,t.appName)||await En(c.path,t.appName))return;const u=Ao(c.path)||o;u&&await En(u,t.appName)||Y.error(e("filesView.toast.openInAppFailed",{app:t.appName}))},[o,c?.path,e]),Xr=n.useCallback((t,i)=>{Kr(t),Si(i),Ds(t==="rename"&&i.name||""),Hr(!1)},[]),[U,Ue]=n.useState(null),Tt=n.useRef(!1),ut=n.useRef(null),[Us,Vt]=n.useState(!1),Ye=ht(t=>t.pendingFileNavigation),xr=ht(t=>t.setPendingFileNavigation),Jr=ht(t=>t.pendingFileFocusPath),Yr=ht(t=>t.setPendingFileFocusPath),Ks=ht(t=>t.fileEditorKeymap),Yt=An(t=>t.settingsDefaultFileViewerPreview),Bi=An(t=>t.showMessageTTSButtons);n.useEffect(()=>{const t=()=>{Tt.current=!1,ut.current=null,Vt(!1)};return document.addEventListener("mouseup",t),()=>document.removeEventListener("mouseup",t)},[]),n.useEffect(()=>()=>{Xt.current!==null&&window.clearTimeout(Xt.current),Jt.current!==null&&window.clearTimeout(Jt.current)},[]);const $i=n.useCallback((t,i)=>{const l=t.split(`
12
- `),u=Math.max(1,i.start),h=Math.min(l.length,i.end);return u>h?"":l.slice(u-1,h).join(`
13
- `)},[]),vr=n.useRef(null),Wi=co({source:"file",fileLabel:c?.path??null,language:c?.path&&ds(c.path)||"text",getCodeForRange:t=>$i(D,uo(t)),toStoreRange:t=>({startLine:t.start,endLine:t.end}),fromDraftRange:t=>({start:t.startLine,end:t.endLine})}),{drafts:Hs,commentText:wr,setCommentText:Gs,editingDraftId:br,setSelection:qs,saveComment:Xs,cancel:Zt,reset:Js,startEdit:Ys,deleteDraft:Zs}=Wi;n.useEffect(()=>{Ue(null),Js(),ye(""),Br(!1)},[c?.path,Js]),n.useEffect(()=>{qs(U)},[U,qs]),n.useEffect(()=>{if(!U&&!br)return;const t=l=>{const u=l.target;u.closest('[data-comment-input="true"]')||u.closest('[data-comment-card="true"]')||u.closest(".cm-gutterElement")||u.closest("[data-sonner-toast]")||u.closest("[data-sonner-toaster]")||wr.trim()||(Ue(null),Zt())},i=setTimeout(()=>{document.addEventListener("click",t)},100);return()=>{clearTimeout(i),document.removeEventListener("click",t)}},[Zt,wr,br,U]);const Qs=n.useCallback((t,i)=>{const l=i??U??void 0;i&&Ue(i),Xs(t,l),Ue(null)},[U,Xs]),en=n.useCallback((t,i)=>{const l=[];for(const u of i){if(!(u&&typeof u.name=="string"&&u.name.length>0)||!R&&u.name.startsWith(".")||!j&&_o(u.name))continue;const h=u.name,m=K(u.path||""),w=m?Bo(m)?m:K(`${t}/${m}`):K(`${t}/${h}`),k=u.isDirectory?"directory":"file",J=k==="file"&&h.includes(".")?h.split(".").pop()?.toLowerCase():void 0;l.push({name:h,path:w,type:k,extension:J})}return Oo(l)},[j,R]),Oe=n.useCallback(async t=>{const i=K(t.trim());if(!i||ze.current.has(i)||Le.current.has(i))return;Le.current=new Set(Le.current),Le.current.add(i);const l=ks.current+1;ks.current=l,tt.current=new Map(tt.current),tt.current.set(i,l);const u=()=>tt.current.get(i)===l;await(s.listDirectory?s.listDirectory(i).then(m=>m.entries.map(w=>({name:w.name,path:w.path,isDirectory:w.isDirectory}))):xa.listLocalDirectory(i).then(m=>m.map(w=>({name:w.name,path:w.path,isDirectory:w.isDirectory})))).then(m=>{if(!u())return;const w=en(i,m);ze.current=new Set(ze.current),ze.current.add(i),Wt(k=>{if(!k[i])return k;const J={...k};return delete J[i],J}),Or(k=>({...k,[i]:w}))}).catch(m=>{if(!u())return;const w=m instanceof Error?m.message:String(m??"");if(w==="Directory not found"&&o&&i!==o){at(o,i),Wt(k=>{if(!k[i])return k;const J={...k};return delete J[i],J});return}console.error("Failed to load files directory:",m),Wt(k=>({...k,[i]:w}))}).finally(()=>{u()&&(tt.current=new Map(tt.current),tt.current.delete(i),Le.current=new Set(Le.current),Le.current.delete(i))})},[s,en,at,o]),yr=n.useCallback(async()=>{o&&(ze.current=new Set,Le.current=new Set,tt.current=new Map,Wt({}),Or(t=>Object.keys(t).length===0?t:{}),await Oe(o))},[Oe,o]),Ze=n.useCallback(async t=>{if(!t){await yr();return}const i=K(t);ze.current=new Set(ze.current),ze.current.delete(i),Le.current=new Set(Le.current),Le.current.delete(i),await Oe(i)},[Oe,yr]),tn=n.useRef(""),rn=n.useRef("");n.useEffect(()=>{if(!o)return;const t=`${o}|h${R?"1":"0"}|g${j?"1":"0"}`,i=tn.current!==o,l=rn.current!==t;!i&&!l||(i&&(tn.current=o,he(""),ge(null),Ie(""),ne(null),P(!1)),l&&(rn.current=t,ze.current=new Set,Le.current=new Set,tt.current=new Map,Wt({}),Or(u=>Object.keys(u).length===0?u:{}),Oe(o)))},[Oe,o,j,R]),n.useEffect(()=>{if(!s.listDirectory)return;const t=()=>{if(!document.hidden&&pe.length>0)for(const i of pe)Ze(i)};return document.addEventListener("visibilitychange",t),()=>document.removeEventListener("visibilitychange",t)},[pe,s.listDirectory,Ze]),n.useEffect(()=>{if(!s.listDirectory||pe.length===0)return;const t=setInterval(()=>{if(!document.hidden)for(const i of pe)Ze(i)},8e3);return()=>clearInterval(t)},[pe,s.listDirectory,Ze]);const _i=n.useCallback(async t=>{if(t?.preventDefault(),!bt||!wt)return;Hr(!0);const i=()=>{Kr(null)},l=h=>{Y.error(h)},u=()=>{Hr(!1)};if(wt==="createFile"){if(!ct.trim()){l(e("sidebarFilesTree.toast.filenameRequired")),u();return}if(!s.writeFile){l(e("sidebarFilesTree.toast.writeNotSupported")),u();return}const h=bt.path,m=h?`${h}/`:"",w=K(`${m}${ct.trim()}`);await s.writeFile(w,"").then(async k=>{k.success&&(Y.success(e("sidebarFilesTree.toast.fileCreated")),await Ze(h)),i()}).catch(()=>l(e("sidebarFilesTree.toast.operationFailed"))).finally(u);return}if(wt==="createFolder"){if(!ct.trim()){l(e("sidebarFilesTree.toast.folderNameRequired")),u();return}const h=bt.path,m=h?`${h}/`:"",w=K(`${m}${ct.trim()}`);await s.createDirectory(w).then(async k=>{k.success&&(Y.success(e("sidebarFilesTree.toast.folderCreated")),await Ze(h)),i()}).catch(()=>l(e("sidebarFilesTree.toast.operationFailed"))).finally(u);return}if(wt==="rename"){if(!ct.trim()){l(e("sidebarFilesTree.toast.nameRequired")),u();return}if(!s.rename){l(e("sidebarFilesTree.toast.renameNotSupported")),u();return}const h=bt.path,m=h.split("/").slice(0,-1).join("/"),w=m?`${m}/`:"",k=K(`${w}${ct.trim()}`);await s.rename(h,k).then(async J=>{J.success&&(Y.success(e("sidebarFilesTree.toast.renamedSuccessfully")),await Ze(m),o&&q(o,h),(c?.path===h||c?.path.startsWith(`${h}/`))&&(o&&me(o,null),he(""),ge(null),Ie(""),ne(null),f&&P(!1))),i()}).catch(()=>l(e("sidebarFilesTree.toast.operationFailed"))).finally(u);return}if(wt==="delete"){if(!s.delete){l(e("sidebarFilesTree.toast.deleteNotSupported")),u();return}const h=bt.path,m=h.split("/").slice(0,-1).join("/");await s.delete(h).then(async w=>{w.success&&(Y.success(e("sidebarFilesTree.toast.deletedSuccessfully")),await Ze(m),o&&q(o,h),(c?.path===h||c?.path.startsWith(`${h}/`))&&(o&&me(o,null),he(""),ge(null),Ie(""),ne(null),f&&P(!1))),i()}).catch(()=>l(e("sidebarFilesTree.toast.operationFailed"))).finally(u);return}u()},[wt,bt,ct,s,Ze,f,q,o,c?.path,me,e]);n.useEffect(()=>{if(!T){lr([]),cr(!1);return}const t=S.trim();if(!t){lr([]),cr(!1);return}let i=!1;return cr(!0),W(T,t,150,{includeHidden:R,respectGitignore:!j,type:"file"}).then(l=>{if(i)return;const h=l.filter(m=>j||!Uo(m.path)).map(m=>({name:m.name,path:K(m.path),type:"file",extension:m.extension,relativePath:m.relativePath}));lr(h)}).catch(()=>{i||lr([])}).finally(()=>{i||cr(!1)}),()=>{i=!0}},[T,S,W,R,j]);const jr=n.useCallback(async(t,i)=>{const l=await Xe(t);if(s.readFile)return(await s.readFile(t,{...l,directory:o||void 0,...i})).content??"";const u=new URLSearchParams({path:t});l.allowOutsideWorkspace&&u.set("allowOutsideWorkspace","true"),l.outsideFileGrant&&u.set("outsideFileGrant",l.outsideFileGrant),o&&u.set("directory",o);const h=await Dn(`/api/fs/read?${u.toString()}`,i?.fresh?{cache:"no-store"}:void 0);if(!h.ok){const m=await h.json().catch(()=>({error:h.statusText}));throw new Error(m.error||e("filesView.error.readFileFailed"))}return h.text()},[s,Xe,o,e]),dt=n.useCallback(async t=>{if(s.statFile){const i=await Xe(t),l=await s.statFile(t,{...i,directory:o||void 0});return{path:l.path,size:l.size,mtimeMs:l.mtimeMs}}return null},[s,Xe,o]);n.useEffect(()=>{if(!o||!s.statFile||Q.length===0)return;let t=!1;const i=[...Q];return Promise.all(i.map(async l=>{try{const u=await Xe(l),h=await s.statFile?.(l,{...u,directory:o||void 0});!t&&h&&!h.isFile&&q(o,l)}catch(u){!t&&Qn(u)&&q(o,l)}})),()=>{t=!0}},[s,Q,q,Xe,o]);const Zr=n.useMemo(()=>D.length>Ot?`${D.slice(0,Ot)}
14
-
15
- … truncated …`:D,[D]),Me=ie!==Zr,Et=n.useCallback(async()=>{if(!c||!s.writeFile)return Y.error(e("filesView.toast.savingNotSupported")),!1;const t=sr(c.path)||xt;if(!Mo({selectedFilePath:c.path,loadedFilePath:De,fileLoading:Ae,isDirty:Me,draftContent:ie,fileContent:D,isNonEditableBinary:t}))return t?console.warn(`[saveDraft] refusing to save binary file "${c.path}".`):ie===""&&D!==""&&De!==c.path&&console.warn(`[saveDraft] refusing to save empty draft for "${c.path}" (${D.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(!Me)return!0;Br(!0);try{const i=Xo(ie,Ts);if(!(await s.writeFile(c.path,i))?.success)return Y.error(e("filesView.toast.writeFileFailed")),!1;if(he(ie),$r.current=i,Wr.current+=1,o&&zr(c.path,o)){const u=Pr(o,c.path);u&&Ma.requestGitRefresh({directory:o,paths:[u]})}if(o&&/(?:^|\/)\.agents\/loops\/[^/]+\.md$/i.test(K(c.path))){const u=za.getState().projects.find(h=>K(h.path)===K(o));if(u)try{await io(u.id)}catch{Y.error(e("sessions.scheduledTasks.dialog.toast.updateFailed"))}}return c?.path&&Tr(c.path)&&(lt.current=ie,Ut.current=ie),dt(c.path).then(u=>{u&&(We.current=u)}).catch(()=>{}),!0}catch(i){return Y.error(i instanceof Error?i.message:e("filesView.toast.saveFailed")),!1}finally{Br(!1)}},[xt,ie,D,Ae,s,Me,Ts,De,dt,o,c,e]);n.useEffect(()=>{je||(St("idle"),Je.current&&(clearTimeout(Je.current),Je.current=null))},[je]);const sn=1500;n.useEffect(()=>{const t=!!(c&&s.writeFile),i=!!(c?.path&&(sr(c.path)||xt));if(Po({autoSaveEnabled:je,isDirty:Me,canWrite:t,isSaving:_t,fileLoading:Ae,selectedFilePath:c?.path,loadedFilePath:De,isNonEditableBinary:i}))return Je.current=setTimeout(()=>{Et().then(l=>{l&&(St("saved"),setTimeout(()=>St("idle"),2e3))})},sn),()=>{Je.current&&(clearTimeout(Je.current),Je.current=null)}},[je,xt,ie,Ae,Me,De,c,s.writeFile,_t,Et]),n.useEffect(()=>{St("idle")},[c?.path]),La({save_file:t=>{if(!(t.target instanceof Node)||!mr.current?.contains(t.target))return!1;Je.current&&(clearTimeout(Je.current),Je.current=null),_t||Et().then(i=>{i&&(St("saved"),setTimeout(()=>St("idle"),2e3))})},find_in_file:t=>{if(!(t.target instanceof Node))return!1;if(Qe&&$e()==="preview"){if(f||!(_?qr.current:pr.current)?.contains(t.target))return!1;hr(!0),As(l=>l+1);return}if(!mr.current?.contains(t.target))return!1;le(!0)}});const Dt=n.useCallback(t=>{const i=di(t);$r.current=t,Wr.current+=1,wi(qo(t)),he(i),lt.current=i,Ut.current=i,ye(i.length>Ot?`${i.slice(0,Ot)}
16
-
17
- … truncated …`:i)},[]),nn=n.useCallback(async t=>{const i=Kt.current+1;Kt.current=i;const l=()=>{if(!o)return!1;const k=Ge.getState().byRoot[o],J=k?.selectedPath??k?.openPaths[0]??null;return Kt.current===i&&J===t.path};if(ge(null),Ie(""),ne(null),Es(!1),ot(!0),await Xe(t.path),!l())return;const u=fs(t.path),h=In(t.path),m=On(t.path),w=sr(t.path);if(f&&P(!0),d.isDesktop&&u&&!h){he(""),ye("");return}if(!d.isDesktop&&u&&!h){he(""),ye(""),ne(t.path),ot(!1);return}if(m){he(""),ye(""),ne(t.path),ot(!1);return}if(w){he(""),ye(""),ne(t.path),ot(!1);return}await jr(t.path).then(k=>{if(l()){if(Bn(k)){Es(!0),he(""),ye(""),ne(t.path);return}Dt(k),ne(t.path),dt(t.path).then(J=>{J&&l()&&(We.current=J)}).catch(()=>{})}}).catch(k=>{if(l()){if(Ko(k)){if(ot(!1),o&&me(o,null),ge(null),he(""),ye(""),ne(null),We.current=null,E.trim().length>0&&V(""),f&&P(!1),o){const rr=[...Yn(t.path,o),t.path];rr.length>0&&ir(o,rr);for(const mt of rr)ze.current.has(mt)||Oe(mt)}return}if(Qn(k)){o&&q(o,t.path),he(""),ye(""),ge(null),We.current=null,f&&P(!1);return}he(""),ye(""),ge(k instanceof Error?k.message:e("filesView.error.readFileFailed")),We.current=null}}).finally(()=>{l()&&ot(!1)})},[Dt,ir,f,Oe,jr,dt,q,Xe,o,d.isDesktop,E,me,e]),Fr=n.useCallback(async(t,i)=>{if(!o)return;const l=Yn(t,o),u=i?[...l,t]:l;u.length>0&&ir(o,u);const h=u.map(m=>{if(!ze.current.has(m))return Oe(m)}).filter(Boolean);await Promise.all(h)},[ir,Oe,o]),an=n.useCallback((t,i)=>{const l=i.findIndex(u=>u.path===t);return l===-1||i.length<=1?null:i[l+1]??i[l-1]??null},[]),Re=n.useCallback(async t=>{if(qt.current)qt.current=!1;else if(Me){Ht(!0),kt.current=t;return}o&&(me(o,t.path),Fr(t.path,!1)),ge(null),Ie(""),he(""),lt.current="",Ut.current="",ye(""),ne(null),f&&P(!0)},[Fr,Me,f,o,me]);n.useEffect(()=>{c?.path&&Fr(c.path,!1)},[Fr,c?.path]),n.useEffect(()=>{if(!c){Kt.current+=1,Ct.current=null,ot(!1);return}if(De===c.path||Ct.current===c.path)return;const t=c.path;Ct.current=t,nn(c).finally(()=>{Ct.current===t&&(Ct.current=null)})},[dr,nn,De,c]);const Nr=n.useRef(Me);Nr.current=Me,n.useEffect(()=>ao(({runtimeKey:t,paths:i})=>{const l=c?.path;t!==ja()||!l||Nr.current||!i.includes(K(l))||(Kt.current+=1,Ct.current=null,We.current=null,Ie(""),ge(null),ne(null),yi(u=>u+1))}),[c?.path]),n.useEffect(()=>{if(!c?.path||De!==c.path)return;const t=c.path,i=()=>Nr.current||Tr(t)&&lt.current!==Ut.current,l=!sr(t)&&!fs(t)&&!xt?To({readContent:()=>jr(t,{fresh:!0}),getLoadedContent:()=>$r.current,getLoadedRevision:()=>Wr.current,isDirty:i,applyContent:w=>{if(Bn(w)){ne(null);return}Dt(w)}}):null;let u=!1,h=!1;const m=window.setInterval(()=>{document.hidden||h||(h=!0,dt(t).then(async w=>{if(u||!w)return;const k=We.current;if(!k||k.path!==t){We.current=w;return}if(Eo(k,w)){if(l&&w.size<=Ho){await l.poll()&&!u&&(We.current=w);return}Nr.current||(We.current=w,ne(null))}}).catch(()=>{}).finally(()=>{h=!1}))},2e3);return()=>{u=!0,l?.dispose(),window.clearInterval(m)}},[Dt,xt,De,jr,dt,c?.path]);const Ui=n.useCallback(()=>{const t=kt.current,i=Gt.current;if(kt.current=null,Gt.current=null,qt.current=!0,Ht(!1),ye(Zr),i){o&&et(o,i),c?.path===i&&(t?Re(t):(o&&me(o,null),he(""),ge(null),Ie(""),ne(null),f&&P(!1)));return}if(t){Re(t);return}},[Zr,Re,f,et,o,c?.path,me]),Ki=n.useCallback(async()=>{const t=kt.current,i=Gt.current;if(!await Et()){qt.current=!1;return}if(kt.current=null,Gt.current=null,qt.current=!0,Ht(!1),i){o&&et(o,i),c?.path===i&&(t?await Re(t):(o&&me(o,null),he(""),ge(null),Ie(""),ne(null),f&&P(!1)));return}if(t){await Re(t);return}},[Re,f,et,o,Et,c?.path,me]),on=n.useCallback(t=>{const i=c?.path===t,l=an(t,Nt);if(i&&Me){Ht(!0),kt.current=l,Gt.current=t;return}if(o&&et(o,t),!!i){if(l){Re(l);return}o&&me(o,null),he(""),ge(null),Ie(""),ne(null),f&&P(!1)}},[an,Re,Me,f,Nt,et,o,c?.path,me]),Hi=n.useCallback(t=>{if(Q.includes(t))return"open";if(L?.files){const i=t.startsWith(o+"/")?t.slice(o.length+1):t,l=L.files.find(u=>u.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},[Q,L,o]),Gi=n.useCallback(t=>{if(!L?.files)return null;const i=t.startsWith(o+"/")?t.slice(o.length+1):t,l=i?`${i}/`:"";let u=0,h=0;for(const m of L.files)m.path.startsWith(l)&&((m.index==="M"||m.working_dir==="M")&&u++,(m.index==="A"||m.working_dir==="?")&&h++);return u+h>0?{modified:u,added:h}:null},[L,o]),qi=n.useCallback(async t=>{const i=K(t);o&&(ys(o,i),ze.current.has(i)||await Oe(i))},[Oe,o,ys]),Xi=n.useMemo(()=>({canRename:Bs,canCreateFile:Is,canCreateFolder:Os,canDelete:$s,canReveal:Ws}),[Bs,Is,Os,$s,Ws]);function ln(t,i){const l=Ss[t]??[];return l.map((u,h)=>{const m=u.type==="directory",w=m&&pe.includes(u.path),k=c?.path===u.path,J=h===l.length-1;return r.jsxs("li",{className:"relative",children:[i>0&&r.jsxs(r.Fragment,{children:[r.jsx("span",{className:"absolute top-3.5 left-[-12px] w-3 h-px bg-border/40"}),J&&r.jsx("span",{className:"absolute top-3.5 bottom-0 left-[-13px] w-[2px] bg-background"})]}),r.jsx(Yo,{node:u,root:o,isExpanded:w,isActive:k,isMobile:f,isBrowserClient:F,alwaysShowActions:N,status:m?void 0:Hi(u.path),badge:m?Gi(u.path):void 0,permissions:Xi,downloadFile:s.downloadFile,contextMenuPath:Ri,setContextMenuPath:Ti,rightClickMenuPath:Vi,setRightClickMenuPath:Ei,onSelect:Re,onToggle:qi,onRevealPath:Ii,onOpenDialog:Xr}),m&&w&&r.jsxs("ul",{className:"flex flex-col gap-1 ml-3 pl-3 border-l border-border/40 relative",children:[or[u.path]?r.jsxs("li",{className:"flex items-center gap-2 px-2 py-1 typography-meta text-muted-foreground",children:[r.jsx("span",{className:"min-w-0 flex-1 truncate text-[var(--status-error)]",title:or[u.path],children:or[u.path]}),r.jsxs(z,{variant:"ghost",size:"xs",className:"h-6 gap-1",onClick:()=>{Ze(u.path)},children:[r.jsx(y,{name:"refresh",className:"size-3.5"}),e("filesView.tree.actions.refreshTitle")]})]}):null,ln(u.path,i+1)]})]},u.path)})}const Fe=!!(c?.path&&fs(c.path)),Cr=!!(c?.path&&In(c.path)),Be=!!(c?.path&&On(c.path)),Qr=!!(c?.path&&(sr(c.path)||xt)),nt=Qr&&!Fe&&!Be,cn=n.useMemo(()=>K(Ye?.path??""),[Ye?.path]),Pt=!!(Ye&&cn&&qe&&qe===cn&&!Ae&&!rt&&!Fe&&!Be&&!nt),ft=n.useMemo(()=>Pr(o,qe),[qe,o]),Ji=!!(c&&(!Fe||Cr)&&!Be&&!nt&&D.length>0),Yi=!!(c&&ft.length>0),Ke=!!(c&&!ar&&!Qr&&!Fe&&s.writeFile&&D.length<=Ot),Qe=!!(c?.path&&ei(c.path)),Qt=!!(c?.path&&Jo(c.path)),Mt=!!(c?.path&&xs(c.path)),er=!!(c?.path&&Tr(c.path)),es=!!(c&&!Qr&&!Fe)&&!Qe&&!er&&!(Mt&&B==="preview"),Zi=Qe&&ve==="edit"||Mt&&B==="edit"||Qt&&ue==="text"||!Qe&&!Mt&&!Qt&&O==="edit",Sr=n.useMemo(()=>qe?Aa(qe):null,[qe]),[un,ts]=n.useState(null);n.useEffect(()=>{let t=!1;const i=c?.path;if(!i||Sr){ts(null);return}return ts(null),Ia(i).then(l=>{t||ts(l)}),()=>{t=!0}},[c?.path,Sr]),n.useEffect(()=>{!Ke&&O==="edit"&&xe("view")},[Ke,O]);const rs="aiworker:files:md-viewer-mode",ss="aiworker:files:html-viewer-mode",ns="aiworker:files:json-viewer-mode";n.useEffect(()=>{const t=c?.path;if(!t)return;xe(oe.current[t]??"edit");let i=Yt?"preview":"edit";try{const h=localStorage.getItem(rs);(h==="preview"||h==="edit")&&(i=h)}catch{}ce(be.current[t]??i);let l=Yt?"preview":"edit";try{const h=localStorage.getItem(ss);(h==="preview"||h==="edit")&&(l=h)}catch{}H(Te.current[t]??l),se(de.current[t]??(Yt?"preview":"edit"));let u=Yt?"tree":"text";try{const h=localStorage.getItem(ns);(h==="tree"||h==="text")&&(u=h)}catch{}we(u)},[c?.path,Yt]);const Qi=n.useCallback(t=>{const i=c?.path;i&&(oe.current[i]=t),xe(t)},[c?.path]),ea=n.useCallback(t=>{const i=c?.path;i&&(be.current[i]=t),ce(t);try{localStorage.setItem(rs,t)}catch{}},[c?.path]),$e=n.useCallback(()=>ve,[ve]),dn=c&&Qe&&$e()==="preview"&&!Ae?c.path:null;n.useEffect(()=>{!dn||f||gr()},[gr,_,f,dn]);const ta=n.useCallback(t=>{we(t);try{localStorage.setItem(ns,t)}catch{}},[]),ra=n.useCallback(t=>{const i=c?.path;i&&(Te.current[i]=t),H(t);try{localStorage.setItem(ss,t)}catch{}},[c?.path]),sa=n.useCallback(t=>{const i=c?.path;if(i&&(de.current[i]=t),Pe.current&&(clearTimeout(Pe.current),Pe.current=null),st.current!==null&&(cancelAnimationFrame(st.current),st.current=null),t==="edit")ye(lt.current||D),se(t);else{lt.current=ie;const l=i;se("edit"),st.current=requestAnimationFrame(()=>{st.current=requestAnimationFrame(()=>{st.current=null,!(o&&l&&Ge.getState().byRoot[o]?.selectedPath!==l)&&(ae(u=>u+1),se("preview"))})});return}},[ie,D,o,c?.path]),is=n.useCallback(async(t,i)=>{if(!s.writeFile||i===Ut.current)return!1;if(!(await s.writeFile(t,i))?.success)return Y.error(e("filesView.toast.writeFileFailed")),!1;Dt(i);const u=await dt(t).catch(()=>null);return u&&(We.current=u),!0},[Dt,s,dt,e]);n.useEffect(()=>()=>{Pe.current&&(clearTimeout(Pe.current),Pe.current=null),st.current!==null&&(cancelAnimationFrame(st.current),st.current=null)},[re,c?.path]);const na=n.useCallback(t=>{if(lt.current=t,!je||!c?.path||re!=="preview"||!s.writeFile)return;Pe.current&&clearTimeout(Pe.current);const i=c.path;Pe.current=setTimeout(()=>{Pe.current=null,is(i,t).then(l=>{l&&(fr(!0),setTimeout(()=>fr(!1),1500))}).catch(l=>{Y.error(l instanceof Error?l.message:e("filesView.toast.saveFailed"))})},sn)},[je,re,s.writeFile,is,c?.path,e]),ia=n.useMemo(()=>er&&(lt.current||ie)||D,[ie,D,er]),fn=n.useCallback(()=>B,[B]);n.useEffect(()=>{const t=l=>{const u=l?"preview":"edit",h=l?"tree":"text";for(const m of Q)oe.current[m]="edit",ei(m)&&(be.current[m]=u),xs(m)&&(Te.current[m]=u),Tr(m)&&(de.current[m]=u);xe("edit"),ce(u),H(u),se(u),we(h);try{localStorage.setItem(rs,u),localStorage.setItem(ss,u),localStorage.setItem(ns,h)}catch{}},i=l=>{const u=!!l.detail?.enabled;t(u)};return window.addEventListener("aiworker:file-viewer-preview-mode-changed",i),()=>{window.removeEventListener("aiworker:file-viewer-preview-mode-changed",i)}},[Q]),n.useEffect(()=>{if(!Ye||!o)return;const t=()=>{typeof window>"u"||Rt.current===null&&(Rt.current=window.requestAnimationFrame(()=>{Rt.current=null,Ur(it=>it+1)}))},i=(it,yt)=>{if(it.state.doc.length!==yt.length)return!1;if(yt.length===0)return!0;const cs=Math.min(128,yt.length);if(it.state.sliceDoc(0,cs)!==yt.slice(0,cs))return!1;const Tn=Math.max(0,yt.length-cs);return it.state.sliceDoc(Tn,yt.length)===yt.slice(Tn)},l=K(Ye.path);if(!l){xr(null),vt.current={key:"",attempts:0};return}const u=`${l}:${Ye.line}:${Ye.column??1}`;if(vt.current.key!==u&&(vt.current={key:u,attempts:0}),c?.path!==l){if(_r)return;Re(Ft(l));return}if(Ae||De!==l)return;if(rt||Fe||Be||nt){xr(null),vt.current={key:"",attempts:0};return}if(!Ke)return;if(O!=="edit"){xe("edit");return}const h=_e.current;if(!h){t();return}if(!i(h,ie)){t();return}const m=Math.max(1,Math.min(Ye.line,h.state.doc.lines)),w=h.state.doc.line(m),k=Math.max(1,Ye.column||1),J=Math.max(0,w.to-w.from),rr=Math.min(J,k-1),mt=w.from+rr;if(!(h.state.selection.main.head===mt)||vt.current.attempts===0){vt.current.attempts+=1,h.dispatch({selection:{anchor:mt},effects:jt.scrollIntoView(mt,{y:"center"})}),h.focus(),t();return}typeof window<"u"&&window.requestAnimationFrame(()=>{const it=_e.current;it&&(it.dispatch({selection:{anchor:mt},effects:jt.scrollIntoView(mt,{y:"center"})}),it.focus())}),xr(null),vt.current={key:"",attempts:0}},[Ke,_r,ie,Ci,rt,Ae,Fe,Be,nt,De,Re,Ye,o,c?.path,xr,O,Ft]),n.useEffect(()=>{if(!Jr||!o)return;const t=K(Jr);if(!t){Yr(null);return}c?.path===t&&(Ae||De!==t||(!rt&&!Fe&&!Be&&!nt&&Ke&&O==="edit"&&_e.current?.focus(),Yr(null)))},[Ke,rt,Ae,Fe,Be,nt,De,Jr,o,c?.path,Yr,O]);const zt=n.useCallback(t=>{if(!f||!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 h=t.state.selection.main.head,m=t.coordsAtPos(h);if(!m)return;const w=Math.round(i.offsetTop+i.height),J=m.bottom+20-w;J<=0||(t.scrollDOM.scrollTop+=J)},[f]);n.useEffect(()=>{if(!f||typeof window>"u")return;const t=()=>{window.requestAnimationFrame(()=>{zt(_e.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)}},[f,zt]),Oa("open_go_to_line",t=>{if(!Ke||O!=="edit"||f)return!1;const i=t.target;if(i?.closest('[role="dialog"]')||!(i instanceof Node)||!mr.current?.contains(i))return!1;const l=!!i?.closest(".cm-editor");if(!!i?.closest('input, textarea, [contenteditable="true"], [role="textbox"]')&&!l)return!1;Gr(!0)});const kr=ht(t=>t.editorFontSize),mn=n.useMemo(()=>{if(!c?.path)return[Wn(x,{fontSize:kr})];const t=ds(c.path),i=[Wn(x,t?{syntaxColors:!1,fontSize:kr}:{fontSize:kr})],l=Sr??un;return l&&i.push(l),t&&i.push(Ya({language:t,themeName:x.metadata.id,theme:to(x)})),X&&i.push(jt.lineWrapping),f&&i.push(jt.updateListener.of(u=>{u.view.hasFocus&&(u.selectionSet||u.focusChanged||u.viewportChanged||u.geometryChanged)&&window.requestAnimationFrame(()=>{zt(u.view)})})),i},[x,c?.path,Sr,un,X,f,zt,kr]),hn=n.useMemo(()=>({light:Ve.metadata.id,dark:Ee.metadata.id}),[Ve.metadata.id,Ee.metadata.id]),tr=c?.path&&Be&&(!gt.allowOutsideWorkspace||gt.outsideFileGrant)?`${c.path}|${gt.allowOutsideWorkspace?"outside":"workspace"}|${gt.outsideFileGrant??""}|${dr}`:"",Rr=c?.path&&Mt&&B==="preview"&&!d.isVSCode?`${c.path}|${dr}`:"",pn=e("filesView.error.readFileFailed"),{readyKey:gn,nonce:aa}=ti(Rr,ge,pn),{readyKey:xn,nonce:vn}=ti(tr,ge,pn),oa=!!(Rr&&gn!==Rr),wn=!!(tr&&xn!==tr),bn=c?.path&&Fe?Cr?`data:${Ba(c.path)};utf8,${encodeURIComponent(D)}`:vi:"",yn=c?.path&&Be&&tr&&xn===tr?Pn().authenticatedAsset("/api/fs/raw",{path:c.path,allowOutsideWorkspace:gt.allowOutsideWorkspace?"true":void 0,outsideFileGrant:gt.outsideFileGrant,directory:o||void 0}):"",jn=n.useCallback(t=>r.jsx("div",{className:"h-full overflow-hidden bg-[var(--surface-background)]",children:r.jsx("iframe",{src:yn,className:"h-full w-full border-0",title:t.name},vn)}),[yn,vn]);n.useEffect(()=>{let t=!1,i="";return(async()=>{if(!c?.path||!Fe||Cr){Ie("");return}ge(null);const u=await Xe(c.path);if(t)return;await(s.readFileBinary?s.readFileBinary(c.path,u).then(m=>m.dataUrl):(async()=>{const m=await Dn("/api/fs/raw",{query:{path:c.path,allowOutsideWorkspace:u.allowOutsideWorkspace?"true":void 0,outsideFileGrant:u.outsideFileGrant,directory:o||void 0}});if(!m.ok)throw new Error(e("filesView.error.readFileFailed"));const w=await m.blob();return i=URL.createObjectURL(w),t?(URL.revokeObjectURL(i),i="",""):i})()).then(m=>{t||(Ie(m),ne(c.path))}).catch(m=>{t||(Ie(""),ge(m instanceof Error?m.message:e("filesView.error.readFileFailed")),ne(null))}).finally(()=>{t||ot(!1)})})(),()=>{t=!0,i&&URL.revokeObjectURL(i)}},[dr,s,Fe,Cr,Xe,o,c?.path,gt,e]);const la=n.useCallback(()=>Kr(null),[]),ca=n.useMemo(()=>fo({drafts:Hs,editingDraftId:br,commentText:wr,onTextChange:Gs,selection:U,isDragging:Us,fileLabel:c?.path??"",newWidgetId:"files-new-comment-input",mapDraftToRange:t=>({start:t.startLine,end:t.endLine}),onSave:Qs,onCancel:()=>{Ue(null),Zt()},onEdit:t=>{Ys(t),Ue({start:t.startLine,end:t.endLine})},onDelete:Zs}),[Zt,wr,Zs,br,Hs,Qs,Us,U,c?.path,Gs,Ys]),Fn=Xn(),Nn=Xn(),as=Ka("unified"),He=D.length>Ot,os=n.useMemo(()=>He?Go(D):void 0,[D,He]),Cn=n.useCallback((t,i,l)=>{const u={name:t.name,contents:i,lang:ds(t.path)||void 0},h=m=>r.jsx(eo,{file:He&&os?{...u,cacheKey:`${t.path}:${os}`}:u,options:{disableFileHeader:!0,overflow:X?"wrap":"scroll",theme:hn,themeType:x.metadata.variant==="dark"?"dark":"light"},className:He?"block w-full":"block h-full w-full",style:He?void 0:{height:"100%"}},m);return He?r.jsx("div",{className:"h-full",children:r.jsx(ro.Provider,{value:l.virtualizer,children:r.jsx(so.Provider,{value:as,children:h(`${t.path}:${as?"pool":"pending"}`)})})}):r.jsx("div",{className:"h-full",children:h(t.path)})},[x.metadata.variant,He,os,hn,as,X]),Sn=({exitFullscreenOnly:t=!1,layout:i="floating"}={})=>{if(!c)return null;const l=i==="docked",u=$a(Wa("save_file")),h=l?"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",m=(w,k)=>r.jsxs(Lt,{children:[r.jsx(At,{asChild:!0,children:r.jsx("span",{className:"inline-flex",children:k})}),r.jsx(It,{side:"bottom",sideOffset:6,children:w})]});return r.jsxs("div",{className:h,children:[Ke&&Zi&&r.jsxs(r.Fragment,{children:[_t?r.jsxs("span",{className:"flex items-center gap-1 px-1 text-muted-foreground typography-meta",children:[r.jsx(y,{name:"loader-4",className:"size-3.5 animate-spin"}),e("filesView.editor.saving")]}):je&&ji==="saved"&&!Me?r.jsxs("span",{className:"flex items-center gap-1 px-1 text-[color:var(--status-success)] typography-meta",children:[r.jsx(y,{name:"check",className:"size-3.5"}),e("filesView.editor.saved")]}):Me?m(e(je?"filesView.editor.saveNowTitle":"filesView.editor.saveNowManualTitle",{shortcut:u}),r.jsx(z,{variant:"ghost",size:"sm",onClick:()=>{Et()},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(je?"filesView.editor.saveNowTitle":"filesView.editor.saveNowManualTitle",{shortcut:u}),"aria-label":e("filesView.editor.saveAria",{shortcut:u}),children:r.jsx(y,{name:"save-3",className:"size-4"})})):null,m(e(je?"filesView.editor.autoSaveOn":"filesView.editor.manualSave"),r.jsx(z,{variant:"ghost",size:"sm",onClick:()=>Ni(!je),className:G("size-6 p-0 transition-opacity hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",je?"text-foreground opacity-100":"text-muted-foreground opacity-65 hover:opacity-100"),title:e(je?"filesView.editor.autoSaveOn":"filesView.editor.manualSave"),"aria-label":e(je?"filesView.editor.autoSaveOn":"filesView.editor.manualSave"),children:je?r.jsx(y,{name:"file-check-fill",className:"size-4"}):r.jsx(y,{name:"file-check",className:"size-4"})}))]}),r.jsxs(vs,{onOpenChange:Ce,children:[r.jsxs(Lt,{children:[r.jsx(At,{asChild:!0,children:r.jsx("span",{className:"inline-flex",children:r.jsx(ws,{asChild:!0,children:r.jsx(z,{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:r.jsx(y,{name:"file-transfer",className:"size-4"})})})})}),r.jsx(It,{side:"bottom",sideOffset:6,children:e("filesView.editor.openInDesktopApp")})]}),r.jsxs(bs,{align:"end",className:"w-56 max-h-[70vh] overflow-y-auto",children:[zi.map(w=>r.jsxs(Dr,{className:"flex items-center gap-2",onClick:()=>{Oi(w)},children:[r.jsx(Io,{label:w.label,iconDataUrl:w.iconDataUrl}),r.jsx("span",{className:"typography-ui-label text-foreground",children:w.label})]},w.id)),Li?r.jsxs(Dr,{className:"flex items-center gap-2",onClick:()=>{Ai(!0)},children:[r.jsx(y,{name:"refresh",className:"size-4"}),r.jsx("span",{className:"typography-ui-label text-foreground",children:e("filesView.editor.refreshApps")})]}):null]})]}),!Fe&&!Be&&!nt&&r.jsxs(r.Fragment,{children:[m(e(X?"filesView.editor.disableLineWrap":"filesView.editor.enableLineWrap"),r.jsx(z,{variant:"ghost",size:"sm",onClick:()=>Ne(!X),className:G("size-6 p-0 transition-opacity hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",X?"text-foreground opacity-100":"text-muted-foreground opacity-65 hover:opacity-100"),title:e(X?"filesView.editor.disableLineWrap":"filesView.editor.enableLineWrap"),children:r.jsx(y,{name:"text-wrap",className:"size-4"})})),O==="edit"&&r.jsxs(r.Fragment,{children:[m(e("filesView.editor.findInFile"),r.jsx(z,{variant:"ghost",size:"sm",onClick:w=>{le(!ee),w.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:r.jsx(y,{name:"search",className:"size-4"})})),m(e("filesView.editor.goToLine"),r.jsx(z,{variant:"ghost",size:"sm",onClick:w=>{Gr(k=>!k),w.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:r.jsx(y,{name:"menu-fold-2",className:"size-4"})})),r.jsx(jo,{open:Mi,onOpenChange:Gr,view:_e.current,variant:"inline"})]})]}),es&&Ke&&!Qt&&!Mt&&r.jsx(ps,{currentMode:O==="view"?"preview":"edit",onToggle:()=>{Qi(O==="view"?"edit":"view")}}),Qe&&m(e($e()==="preview"?"filesView.editor.switchToEditMode":"filesView.editor.switchToPreviewMode"),r.jsx(z,{variant:"ghost",size:"sm",onClick:()=>ea($e()==="preview"?"edit":"preview"),className:G("size-6 p-0 transition-colors hover:bg-[var(--interactive-hover)] focus-visible:bg-[var(--interactive-hover)] active:bg-[var(--interactive-hover)]",$e()==="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($e()==="preview"?"filesView.editor.switchToEditMode":"filesView.editor.switchToPreviewMode"),"aria-label":e($e()==="preview"?"filesView.editor.switchToEditMode":"filesView.editor.switchToPreviewMode"),children:r.jsx(y,{name:$e()==="preview"?"eye":"eye-off",className:"size-4"})})),xs(c?.path??"")&&r.jsx(ps,{currentMode:fn(),onToggle:()=>{ra(fn()==="preview"?"edit":"preview")}}),Qe&&$e()==="preview"&&m(e("filesView.editor.findInFile"),r.jsx(z,{variant:"ghost",size:"sm",onClick:()=>{hr(!0),As(w=>w+1)},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:r.jsx(y,{name:"search",className:"size-4"})})),Qe&&$e()==="preview"&&Bi&&r.jsxs(Lt,{children:[r.jsx(At,{asChild:!0,children:r.jsx(z,{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(ur?"filesView.tts.stopSpeaking":"filesView.tts.readAloud"),onClick:()=>{ur?xi():D.trim()&&gi(D)},children:ur?r.jsx(y,{name:"stop",className:"size-4 text-[color:var(--status-success)]"}):r.jsx(y,{name:"volume-up",className:"size-4"})})}),r.jsx(It,{sideOffset:8,children:e(ur?"filesView.tts.stopSpeaking":"filesView.tts.readAloud")})]}),er&&r.jsxs(r.Fragment,{children:[r.jsx(ps,{currentMode:re,onToggle:()=>sa(re==="preview"?"edit":"preview")}),re==="preview"&&r.jsx(z,{variant:"ghost",size:"sm",onClick:async()=>{const w=Vs.current?.getXml();if(Pe.current&&(clearTimeout(Pe.current),Pe.current=null),c?.path&&w){if(!await is(c.path,w))return;fr(!0),setTimeout(()=>fr(!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:Fi?r.jsx(y,{name:"check",className:"size-4 text-[color:var(--status-success)]"}):r.jsx(y,{name:"save-3",className:"size-4"})})]}),Qt&&m(e(ue==="tree"?"filesView.editor.switchToTextView":"filesView.editor.switchToTreeView"),r.jsx(z,{variant:"ghost",size:"sm",onClick:()=>ta(ue==="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(ue==="tree"?"filesView.editor.switchToTextView":"filesView.editor.switchToTreeView"),children:ue==="tree"?r.jsx(y,{name:"code-sslash",className:"size-4"}):r.jsx(y,{name:"node-tree",className:"size-4"})})),Ji&&m(e("filesView.editor.copyFileContents"),r.jsx(z,{variant:"ghost",size:"sm",onClick:async()=>{(await Mr(D)).ok?(Ps(!0),Xt.current!==null&&window.clearTimeout(Xt.current),Xt.current=window.setTimeout(()=>{Ps(!1)},1200)):Y.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:Di?r.jsx(y,{name:"check",className:"size-4 text-[color:var(--status-success)]"}):r.jsx(y,{name:"clipboard",className:"size-4"})})),Yi&&m(e("filesView.editor.copyFilePathTitle",{path:ft}),r.jsx(z,{variant:"ghost",size:"sm",onClick:async()=>{(await Mr(ft)).ok?(Ms(!0),Jt.current!==null&&window.clearTimeout(Jt.current),Jt.current=window.setTimeout(()=>{Ms(!1)},1200)):Y.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:ft}),"aria-label":e("filesView.editor.copyFilePathTitle",{path:ft}),children:Pi?r.jsx(y,{name:"check",className:"size-4 text-[color:var(--status-success)]"}):r.jsx(y,{name:"file-copy-2",className:"size-4"})})),s.downloadFile&&m(e("filesView.editor.saveFile"),r.jsx(z,{variant:"ghost",size:"sm",onClick:()=>{const w=s.downloadFile;w&&w(c.path).catch(k=>{console.error("Download failed:",k),Y.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:r.jsx(y,{name:"download",className:"size-4"})})),t?m(e("filesView.editor.exitFullscreen"),r.jsx(z,{variant:"ghost",size:"sm",onClick:()=>Z(!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:r.jsx(y,{name:"fullscreen-exit",className:"size-4"})})):!f&&a==="full"&&m(e(_?"filesView.editor.exitFullscreen":"filesView.editor.fullscreen"),r.jsx(z,{variant:"ghost",size:"sm",onClick:()=>Z(!_),className:"size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e(_?"filesView.editor.exitFullscreen":"filesView.editor.fullscreen"),"aria-label":e(_?"filesView.editor.exitFullscreen":"filesView.editor.fullscreen"),children:_?r.jsx(y,{name:"fullscreen-exit",className:"size-4"}):r.jsx(y,{name:"fullscreen",className:"size-4"})}))]})},ls=r.jsxs("div",{className:"relative flex h-full min-h-0 min-w-0 w-full flex-col overflow-hidden",children:[r.jsx(si,{open:_r,onOpenChange:t=>{t||Ht(!0)},children:r.jsxs(ni,{showCloseButton:!1,className:"max-w-md",children:[r.jsxs(ii,{children:[r.jsx(ai,{children:e("filesView.unsaved.title")}),r.jsx(oi,{children:e("filesView.unsaved.description")})]}),r.jsxs(li,{children:[r.jsx(z,{variant:"outline",onClick:()=>{Ki()},disabled:_t,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")}),r.jsx(z,{variant:"destructive",onClick:Ui,children:e("filesView.unsaved.discard")})]})]})}),r.jsxs("div",{className:G("flex flex-col flex-shrink-0",A&&"border-b border-border/40"),children:[A?r.jsxs("div",{className:"flex min-w-0 items-center px-3 py-1.5",children:[f&&$&&r.jsx("button",{type:"button",onClick:()=>P(!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:r.jsx(y,{name:"arrow-left-s",className:"size-5"})}),f?c?r.jsxs(vs,{children:[r.jsx(ws,{asChild:!0,children:r.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:[r.jsx(Er,{filePath:c.path,extension:c.extension,className:"size-3.5 flex-shrink-0"}),r.jsx(Zn,{name:c.name}),r.jsx(y,{name:"arrow-down-s",className:"size-4 flex-shrink-0 text-muted-foreground"})]})}),r.jsx(bs,{align:"start",className:"w-[min(24rem,calc(100vw-2rem))] max-w-[calc(100vw-2rem)]",children:Nt.map(t=>{const i=c?.path===t.path;return r.jsxs(Dr,{onSelect:l=>{if(l.target.closest("[data-close-open-file]")){l.preventDefault();return}i||Re(t)},className:G("flex min-w-0 items-center justify-between gap-2 overflow-hidden",i&&"bg-[var(--interactive-selection)] text-[var(--interactive-selection-foreground)]"),children:[r.jsxs("span",{className:"flex min-w-0 flex-1 items-center gap-2 overflow-hidden",children:[r.jsx(Er,{filePath:t.path,extension:t.extension,className:"size-3.5 flex-shrink-0"}),r.jsx(Zn,{name:t.name})]}),r.jsx("button",{type:"button","data-close-open-file":!0,onPointerDown:l=>{l.preventDefault(),l.stopPropagation()},onClick:l=>{l.preventDefault(),l.stopPropagation(),on(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:r.jsx(y,{name:"close",className:"size-3.5"})})]},t.path)})})]}):r.jsx("div",{className:"typography-ui-label font-medium truncate",children:e("filesView.editor.selectFile")}):Nt.length>0?r.jsxs("div",{className:"relative min-w-0 flex-1",children:[Fs.left&&r.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"}),Fs.right&&r.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"}),r.jsx("div",{ref:Ir,className:"flex min-w-0 items-center gap-1 overflow-x-auto scrollbar-none",style:{scrollbarWidth:"none",msOverflowStyle:"none"},children:Nt.map(t=>{const i=c?.path===t.path;return r.jsxs("div",{title:Pr(o,t.path),className:G("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:[r.jsx(Er,{filePath:t.path,extension:t.extension,className:"size-3.5 flex-shrink-0"}),r.jsx("button",{type:"button",onClick:()=>{i||Re(t)},className:"max-w-[12rem] truncate text-left",children:t.name}),r.jsx("button",{type:"button",onClick:l=>{l.stopPropagation(),on(t.path)},className:G("rounded-sm p-0.5 text-[var(--surface-muted-foreground)] hover:text-[var(--surface-foreground)]",!i&&!N&&"opacity-0 group-hover:opacity-100"),"aria-label":e("filesView.editor.closeFileAria",{name:t.name}),children:r.jsx(y,{name:"close",className:"size-3.5"})})]},t.path)})})]}):r.jsx("div",{className:"typography-ui-label font-medium truncate",children:e("filesView.editor.selectFile")})]}):null,c?r.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:[ft&&!f?r.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta text-muted-foreground",title:ft,children:ft}):null,r.jsx("div",{className:"ml-auto min-w-0 shrink-0 overflow-x-auto",children:Sn({layout:"docked"})})]}):null]}),r.jsx("div",{className:"flex-1 min-h-0 min-w-0 relative",children:r.jsx(ms,{ref:Fn.setScroller,outerClassName:"h-full min-w-0",className:G("h-full min-w-0",He&&"[overflow-anchor:none]"),children:c?Ae||wn?I?r.jsx("div",{className:"p-3"}):r.jsxs("div",{className:"p-3 flex items-center gap-2 typography-ui text-muted-foreground",children:[r.jsx(y,{name:"loader-4",className:"size-4 animate-spin"}),e("filesView.state.loading")]}):rt?r.jsx("div",{className:"p-3 typography-ui text-[color:var(--status-error)]",children:rt}):Fe?r.jsx("div",{className:"flex h-full items-center justify-center p-3",children:r.jsx("img",{src:bn,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"},c.path)}):Be?jn(c):nt?r.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-3 p-6 text-center",children:[r.jsx("div",{className:"typography-ui-header text-foreground",children:e("filesView.editor.cannotPreviewBinary")}),r.jsx("div",{className:"max-w-md typography-ui text-muted-foreground",children:e("filesView.editor.binaryFileDescription")}),s.downloadFile?r.jsxs(z,{type:"button",variant:"outline",size:"sm",onClick:()=>{const t=s.downloadFile;!t||!c||t(c.path).catch(i=>{console.error("Download failed:",i),Y.error(e("sidebarFilesTree.toast.operationFailed"))})},children:[r.jsx(y,{name:"download",className:"mr-2 size-4"}),e("filesView.editor.saveFile")]}):null]}):c&&er&&re==="preview"?r.jsx("div",{className:"h-full overflow-hidden",style:{minHeight:"400px"},children:r.jsx(Lo,{ref:Vs,xml:ia,onChange:na},`${c.path}:${Se}`)}):c&&Qt&&ue==="tree"?r.jsx(hs,{fallback:r.jsxs("div",{className:"rounded-md border border-destructive/20 bg-destructive/10 px-3 py-2",children:[r.jsx("div",{className:"mb-1 font-medium text-destructive",children:e("filesView.error.jsonViewerUnavailable")}),r.jsx("div",{className:"text-sm text-muted-foreground",children:e("filesView.error.switchToTextMode")})]}),children:r.jsx("div",{className:"h-full overflow-auto",children:r.jsx(Qa,{jsonString:D,maxHeight:"100%",initiallyExpandedDepth:2})})}):c&&Qe&&$e()==="preview"?r.jsxs("div",{className:"relative h-full min-h-0",children:[r.jsxs("div",{className:"oc-file-preview h-full overflow-auto p-3 outline-none",tabIndex:-1,onMouseDown:gr,ref:t=>{vr.current=t,pr.current=t},children:[r.jsx(Kn,{containerRef:vr,filePath:c.path,fileContent:D}),D.length>500*1024&&r.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(D.length/1024)})}),r.jsx(hs,{fallback:r.jsxs("div",{className:"rounded-md border border-destructive/20 bg-destructive/10 px-3 py-2",children:[r.jsx("div",{className:"mb-1 font-medium text-destructive",children:e("filesView.error.previewUnavailable")}),r.jsx("div",{className:"text-sm text-muted-foreground",children:e("filesView.error.switchToEditMode")})]}),children:r.jsx($n,{content:D,className:"typography-markdown-body",stripFrontmatter:!0,enableFileReferences:!1})})]}),!_&&r.jsx(qn,{containerRef:pr,open:zs,onOpenChange:hr,focusNonce:Ls})]}):c&&Mt&&B==="preview"?oa?r.jsx("div",{className:"flex h-full items-center justify-center text-muted-foreground typography-ui-label",children:e("common.loading")}):r.jsx("div",{className:"h-full overflow-hidden",children:r.jsx("iframe",{src:!d.isVSCode&&gn===Rr?(()=>{const t=c.path.split("/").map(i=>encodeURIComponent(i)).join("/");return Pn().authenticatedAsset(`/api/fs/serve${t.startsWith("/")?t:`/${t}`}`)})():void 0,srcDoc:d.isVSCode?(()=>{const t=c.path.substring(0,c.path.lastIndexOf("/")+1);return t?D.replace(/<head([^>]*)>/i,`<head$1><base href="${t}">`):D})():void 0,className:"w-full h-full border-none",sandbox:"allow-scripts allow-same-origin allow-forms",title:e("filesView.editor.htmlPreviewTitle")},aa)}):c&&es&&O==="view"?Cn(c,He?D:ie,Fn):r.jsxs("div",{className:G("relative h-full",Pt&&"overflow-hidden"),ref:mr,children:[r.jsx("div",{className:G("h-full",Pt&&"invisible"),children:r.jsx(_n,{value:ie,onChange:ye,readOnly:!Ke,vimMode:Ks==="vim",extensions:mn,className:"h-full",blockWidgets:ca,onViewReady:t=>{_e.current=t,Ur(i=>i+1),window.requestAnimationFrame(()=>{zt(t)})},onViewDestroy:()=>{_e.current&&(_e.current=null),Ur(t=>t+1)},enableSearch:!0,searchOpen:ee,onSearchOpenChange:le,highlightLines:U?{start:Math.min(U.start,U.end),end:Math.max(U.start,U.end)}:void 0,lineNumbersConfig:{domEventHandlers:{mousedown:(t,i,l)=>{if(!(l instanceof MouseEvent)||l.button!==0)return!1;l.preventDefault();const u=t.state.doc.lineAt(i.from).number;if(U&&!l.shiftKey&&Math.min(U.start,U.end)===u&&Math.max(U.start,U.end)===u)return Ue(null),Zt(),Tt.current=!1,ut.current=null,Vt(!1),!0;if(f&&U&&!l.shiftKey){const h=Math.min(U.start,U.end,u),m=Math.max(U.start,U.end,u);return Ue({start:h,end:m}),Tt.current=!1,ut.current=null,Vt(!1),!0}if(Tt.current=!0,ut.current=u,Vt(!0),U&&l.shiftKey){const h=Math.min(U.start,u),m=Math.max(U.end,u);Ue({start:h,end:m})}else Ue({start:u,end:u});return!0},mouseover:(t,i,l)=>{if(!(l instanceof MouseEvent)||l.buttons!==1||!Tt.current||ut.current===null)return!1;const u=t.state.doc.lineAt(i.from).number,h=Math.min(ut.current,u),m=Math.max(ut.current,u);return Ue({start:h,end:m}),Vt(!0),!1},mouseup:()=>(Tt.current=!1,ut.current=null,Vt(!1),!1)}}})}),Pt&&r.jsx("div",{className:"pointer-events-none absolute inset-0 flex items-center justify-center bg-background",children:r.jsxs("div",{className:"flex items-center gap-2 typography-ui text-muted-foreground",children:[r.jsx(y,{name:"loader-4",className:"size-4 animate-spin"}),e("filesView.state.openingFileAtChange")]})})]}):r.jsx("div",{className:"p-3 typography-ui text-muted-foreground",children:e("filesView.editor.pickFileFromTree")})})})]}),ua=!!(o&&Ss[o]),kn=o?or[o]:null,Rn=r.jsxs("section",{className:G("flex min-h-0 flex-col overflow-hidden",f?"h-full w-full bg-background":"h-full rounded-xl border border-border/60 bg-background/70"),children:[r.jsx("div",{className:G("flex flex-col gap-2 py-2",f?"px-3":"px-2"),children:r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsxs("div",{className:"relative flex-1 min-w-0",children:[r.jsx(y,{name:"search",className:"pointer-events-none absolute left-2 top-2 size-4 text-muted-foreground"}),r.jsx(nr,{ref:M,value:E,onChange:t=>V(t.target.value),placeholder:e("filesView.tree.search.placeholder"),className:"h-8 pl-8 pr-8 typography-meta"}),E.trim().length>0&&r.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(""),M.current?.focus()},children:r.jsx(y,{name:"close",className:"size-4"})})]}),r.jsxs(Lt,{children:[r.jsx(At,{asChild:!0,children:r.jsx("span",{className:"inline-flex flex-shrink-0",children:r.jsx(z,{variant:"ghost",size:"sm",onClick:()=>Xr("createFile",{path:T,type:"directory"}),className:"size-8 p-0 flex-shrink-0",title:e("filesView.tree.actions.newFileTitle"),"aria-label":e("filesView.tree.actions.newFileTitle"),children:r.jsx(y,{name:"file-add",className:"size-4"})})})}),r.jsx(It,{side:"bottom",sideOffset:6,children:e("filesView.tree.actions.newFileTitle")})]}),r.jsxs(Lt,{children:[r.jsx(At,{asChild:!0,children:r.jsx("span",{className:"inline-flex flex-shrink-0",children:r.jsx(z,{variant:"ghost",size:"sm",onClick:()=>Xr("createFolder",{path:T,type:"directory"}),className:"size-8 p-0 flex-shrink-0",title:e("filesView.tree.actions.newFolderTitle"),"aria-label":e("filesView.tree.actions.newFolderTitle"),children:r.jsx(y,{name:"folder-add",className:"size-4"})})})}),r.jsx(It,{side:"bottom",sideOffset:6,children:e("filesView.tree.actions.newFolderTitle")})]}),r.jsxs(Lt,{children:[r.jsx(At,{asChild:!0,children:r.jsx("span",{className:"inline-flex flex-shrink-0",children:r.jsx(z,{variant:"ghost",size:"sm",onClick:()=>{yr()},className:"size-8 p-0 flex-shrink-0",title:e("filesView.tree.actions.refreshTitle"),"aria-label":e("filesView.tree.actions.refreshTitle"),children:r.jsx(y,{name:"refresh",className:"size-4"})})})}),r.jsx(It,{side:"bottom",sideOffset:6,children:e("filesView.tree.actions.refreshTitle")})]})]})}),r.jsx(ms,{outerClassName:"flex-1 min-h-0",className:G("py-2",f?"px-3":"px-2"),children:r.jsx("ul",{className:"flex flex-col",children:pi?r.jsxs("li",{className:"flex items-center gap-1.5 px-2 py-1 typography-meta text-muted-foreground",children:[r.jsx(y,{name:"loader-4",className:"size-4 animate-spin"}),e("filesView.tree.search.searching")]}):Rs.length>0?Rs.map(t=>{const i=c?.path===t.path;return r.jsx("li",{children:r.jsxs("button",{type:"button",onClick:()=>{Re(t)},className:G("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:[fi(t.path,t.extension),r.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)}):kn?r.jsxs("li",{className:"flex flex-col gap-2 px-2 py-1 typography-meta text-muted-foreground",children:[r.jsx("span",{className:"text-[var(--status-error)]",children:kn}),r.jsxs(z,{variant:"outline",size:"xs",className:"w-fit gap-1.5",onClick:()=>{yr()},children:[r.jsx(y,{name:"refresh",className:"size-3.5"}),e("filesView.tree.actions.refreshTitle")]})]}):ua?ln(o,0):r.jsx("li",{className:"px-2 py-1 typography-meta text-muted-foreground",children:e("filesView.state.loading")})})})]}),da=a==="full"&&_&&c&&r.jsx("div",{className:"absolute inset-0 z-50 flex flex-col bg-background",children:r.jsxs("div",{className:"flex-1 min-h-0 min-w-0 relative",children:[r.jsx("div",{className:"absolute right-4 top-4 z-30",children:Sn({exitFullscreenOnly:!0})}),r.jsx(ms,{ref:Nn.setScroller,outerClassName:"h-full min-w-0",className:G("h-full min-w-0",He&&"[overflow-anchor:none]"),children:Ae||wn?I?r.jsx("div",{className:"p-4"}):r.jsxs("div",{className:"p-4 flex items-center gap-2 typography-ui text-muted-foreground",children:[r.jsx(y,{name:"loader-4",className:"size-4 animate-spin"}),"Loading…"]}):rt?r.jsx("div",{className:"p-4 typography-ui text-[color:var(--status-error)]",children:rt}):Fe?r.jsx("div",{className:"flex h-full items-center justify-center p-4",children:r.jsx("img",{src:bn,alt:c.name,className:"max-w-full max-h-full object-contain rounded-md border border-border/30 bg-primary/10"},c.path)}):Be?jn(c):nt?r.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-3 p-6 text-center",children:[r.jsx("div",{className:"typography-ui-header text-foreground",children:e("filesView.editor.cannotPreviewBinary")}),r.jsx("div",{className:"max-w-md typography-ui text-muted-foreground",children:e("filesView.editor.binaryFileDescription")}),s.downloadFile?r.jsxs(z,{type:"button",variant:"outline",size:"sm",onClick:()=>{const t=s.downloadFile;!t||!c||t(c.path).catch(i=>{console.error("Download failed:",i),Y.error(e("sidebarFilesTree.toast.operationFailed"))})},children:[r.jsx(y,{name:"download",className:"mr-2 size-4"}),e("filesView.editor.saveFile")]}):null]}):Qe&&$e()==="preview"?r.jsxs("div",{className:"relative h-full min-h-0",children:[r.jsxs("div",{className:"oc-file-preview h-full overflow-auto p-4 outline-none",tabIndex:-1,onMouseDown:gr,ref:t=>{vr.current=t,qr.current=t},children:[c?r.jsx(Kn,{containerRef:vr,filePath:c.path,fileContent:D}):null,D.length>500*1024&&r.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(D.length/1024)})}),r.jsx(hs,{fallback:r.jsxs("div",{className:"rounded-md border border-destructive/20 bg-destructive/10 px-3 py-2",children:[r.jsx("div",{className:"mb-1 font-medium text-destructive",children:e("filesView.error.previewUnavailable")}),r.jsx("div",{className:"text-sm text-muted-foreground",children:e("filesView.error.switchToEditMode")})]}),children:r.jsx($n,{content:D,className:"typography-markdown-body",stripFrontmatter:!0,enableFileReferences:!1})})]}),r.jsx(qn,{containerRef:qr,open:zs,onOpenChange:hr,focusNonce:Ls,className:"right-4 top-16"})]}):es&&O==="view"?Cn(c,He?D:ie,Nn):r.jsxs("div",{className:G("relative h-full",Pt&&"overflow-hidden"),children:[r.jsx("div",{className:G("h-full",Pt&&"invisible"),children:r.jsx(_n,{value:ie,onChange:ye,readOnly:!Ke,vimMode:Ks==="vim",extensions:mn,className:"h-full",onViewReady:t=>{_e.current=t,window.requestAnimationFrame(()=>{zt(t)})},onViewDestroy:()=>{_e.current&&(_e.current=null)}})}),Pt&&r.jsx("div",{className:"pointer-events-none absolute inset-0 flex items-center justify-center bg-background",children:r.jsxs("div",{className:"flex items-center gap-2 typography-ui text-muted-foreground",children:[r.jsx(y,{name:"loader-4",className:"size-4 animate-spin"}),e("filesView.state.openingFileAtChange")]})})]})})]})});return r.jsxs("div",{className:"flex h-full min-h-0 overflow-hidden bg-background relative",children:[r.jsx(Zo,{activeDialog:wt,dialogData:bt,dialogInputValue:ct,onDialogInputChange:Ds,isDialogSubmitting:ki,onDialogSubmit:_i,onClose:la,inputRef:bi}),da,f?$?ls:Rn:a==="editor-only"?r.jsx("div",{className:"flex flex-1 min-h-0 min-w-0 overflow-hidden",children:r.jsx("div",{className:"flex-1 min-h-0 min-w-0 overflow-hidden bg-background",children:ls})}):r.jsxs("div",{className:"flex flex-1 min-h-0 min-w-0 gap-3 px-3 pb-3 pt-2",children:[p>=700&&r.jsx("div",{className:"w-72 flex-shrink-0 min-h-0 overflow-hidden",children:Rn}),r.jsx("div",{className:"flex-1 min-h-0 min-w-0 overflow-hidden rounded-xl border border-border/60 bg-background",children:ls})]})]})};function Qo(a){return a+1}export{bu as FilesView};
@@ -1 +0,0 @@
1
- import{f as B,R as h,j as P}from"./vendor-react-BUCujlKS.js";import{toast as H}from"./vendor-sonner-DFyL3AvE.js";import{fF as K,fC as J,ac as Z,f as Q,I as W}from"./useAppFontEffects-D7sNpuL2.js";import{r as G,$ as Y,G as ee,e as te,dw as re,dx as oe,a2 as ae}from"./index-DF5kMP-i.js";import{extractMarkdownImageCandidates as se,MAX_MARKDOWN_IMAGE_COUNT as ne}from"./markdownCore-BrBwOOMn.js";import"./vendor-scheduler-7OC5HNn7.js";import"./vendor-simplewebauthn-browser-VDA66rT_.js";import"./vendor-vite-runtime-DD1OZmLC.js";import"./vendor-zustand-BAGL70zf.js";import"./vendor-base-ui-BeMD8X_w.js";import"./vendor-floating-ui-utils-D6FqdtJt.js";import"./vendor-floating-ui-react-dom-DxYCWdHj.js";import"./vendor-floating-ui-dom-BTvzWks8.js";import"./vendor-floating-ui-core-PuGzNPnN.js";import"./vendor-use-sync-external-store-D6wYuSt-.js";import"./contextPanelEmbeddedChat-C0ZLAepL.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-framer-motion-livSKyyV.js";import"./vendor-motion-dom-D_o3BTI3.js";import"./vendor-motion-utils-BGh8QBgx.js";import"./vendor-tanstack-react-virtual-g05Cx3z9.js";import"./vendor-tanstack-virtual-core-Dubg10g5.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-BgPj_McA.js";import"./vendor-lezer-common-B3-cUCR_.js";import"./vendor-codemirror-state-C9awkmn-.js";import"./vendor-marijn-find-cluster-break-DXwl3gUT.js";import"./vendor-codemirror-view-CiLROUVV.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-Cc2ZYbgX.js";import"./vendor-lezer-javascript-D7Tj24ot.js";import"./vendor-lezer-lr-bhwg1HMg.js";import"./vendor-codemirror-autocomplete-DzPz9Wgq.js";import"./vendor-codemirror-lang-json-CMBS2tG9.js";import"./vendor-lezer-json-Iaex0UN-.js";import"./vendor-codemirror-lang-css-O0cZX78y.js";import"./vendor-lezer-css-C5xB6jxd.js";import"./vendor-codemirror-lang-html-CfgK872x.js";import"./vendor-lezer-html-C0I1p52t.js";import"./vendor-codemirror-lang-markdown-BPGOH9ye.js";import"./vendor-lezer-markdown-C6g-d6P3.js";import"./vendor-codemirror-language-data-Dp3KMRQG.js";import"./vendor-codemirror-lang-python-HahnQaAS.js";import"./vendor-lezer-python-CvuFxeZl.js";import"./vendor-codemirror-commands-B7H_j0iU.js";import"./vendor-legendapp-list-gg7YLRW7.js";import"./vendor-tailwind-merge-CPcsbTWB.js";import"./vendor-fuse.js-Dw8P0qyA.js";import"./vendor-zod-CK21ihK-.js";import"./vendor-opencode-sdk-BJ73u-bH.js";import"./vendor-marked-CX41MkDF.js";import"./vendor-marked-linkify-it-CXI_LHIE.js";import"./vendor-linkify-it-DZCzzDkK.js";import"./vendor-uc.micro-BAd0H0z4.js";import"./vendor-remend-BWYYytN3.js";import"./vendor-katex-k3Ppq1Ha.js";import"./vendor-dompurify-r8glNMJW.js";const $=10*1024*1024,ie=1024,le=3e4,ce=new Set(["image/png","image/jpeg","image/gif","image/webp"]),z=new WeakMap,L=r=>{if(r.aborted)throw new DOMException("Image load aborted","AbortError")},me=r=>{let e=r;if(/^file:\/\//i.test(e))try{const o=new URL(e);if(o.protocol!=="file:")return"";e=o.host&&o.host!=="localhost"?`//${o.host}${o.pathname}`:o.pathname,/^\/[A-Za-z]:\//.test(e)&&(e=e.slice(1))}catch{return""}const t=e.split(/[?#]/,1)[0]??"";try{return decodeURIComponent(t)}catch{return t}},ue=r=>new Promise((e,t)=>{const o=new FileReader;o.onload=()=>{typeof o.result=="string"?e(o.result):t(new Error("Unable to encode image"))},o.onerror=()=>t(o.error??new Error("Unable to encode image")),o.readAsDataURL(r)}),pe=async(r,e)=>{const t=new Uint8Array(await r.slice(0,12).arrayBuffer()),o=(n,u)=>String.fromCharCode(...t.slice(n,u));switch(e){case"image/png":return t[0]===137&&o(1,4)==="PNG"&&t[4]===13&&t[5]===10&&t[6]===26&&t[7]===10;case"image/jpeg":return t[0]===255&&t[1]===216&&t[2]===255;case"image/gif":{const n=o(0,6);return n==="GIF87a"||n==="GIF89a"}case"image/webp":return o(0,4)==="RIFF"&&o(8,12)==="WEBP";default:return!1}},V=async(r,e)=>{if(!ce.has(e))throw new Error("Unsupported image type");if(r.size>$)throw new Error("Image is too large");if(!await pe(r,e))throw new Error("Unsupported image data")},fe=async r=>{const e=/^data:(image\/(?:png|jpeg|gif|webp));base64,([\s\S]*)$/i.exec(r);if(!e?.[1]||e[2]===void 0)throw new Error("Invalid image data URL");if(e[2].length>Math.ceil($*4/3)+4)throw new Error("Image is too large");let t;try{t=atob(e[2])}catch{throw new Error("Invalid image data URL")}const o=Uint8Array.from(t,n=>n.charCodeAt(0));await V(new Blob([o]),e[1].toLowerCase())},q=r=>!/^(?:https?:)?\/\//i.test(r)&&!/^data:image\/(?:png|jpeg|gif|webp);base64,/i.test(r),de=async({sources:r,directory:e,sessionId:t,messageId:o,signal:n})=>{const u=Y();let s=z.get(u);s||(s=new Map,z.set(u,s));const c=`${t}\0${o}\0${e}\0${r.join("\0")}`,i=s.get(c);if(i&&i.expiresAt>Date.now())return s.delete(c),s.set(c,i),i.result;i&&s.delete(c);const p=await G(`/api/openchamber/sessions/${encodeURIComponent(t)}/markdown-image-grants`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({directory:e,messageId:o,sources:r}),signal:n});if(!p.ok)throw new Error(`Unable to prepare images (${p.status})`);const m=await p.json(),l=new Map;for(const a of m.results??[])a.source&&(a.status==="ready"&&a.path?l.set(a.source,{status:"ready",path:a.path,outsideFileGrant:a.outsideFileGrant,expiresAt:a.expiresAt}):a.status==="missing"?l.set(a.source,{status:"missing"}):l.set(a.source,{status:"error"}));for(const a of r)l.has(a)||l.set(a,{status:"error"});for(;s.size>=ie;)s.delete(s.keys().next().value);const w=[...l.values()].every(a=>a.status==="ready"),y=Math.min(...[...l.values()].filter(a=>a.status==="ready").map(a=>a.expiresAt??Number.POSITIVE_INFINITY));return s.set(c,{result:l,expiresAt:w?y:Date.now()+le}),l},ge=async(r,e)=>{if(L(e),/^(?:https?:)?\/\//i.test(r))return r;if(/^data:image\/(?:png|jpeg|gif|webp);base64,/i.test(r))return await fe(r),L(e),r;throw new Error("Local image has not been prepared")},he=async(r,e,t)=>{L(t);const o=me(r),n=K(e,o);if(!e||!o||!J(n,e))throw new Error("Image path is outside the active workspace");const u=await G("/api/fs/stat",{query:{path:n,directory:e,optional:"true"},signal:t});if(!u.ok)throw new Error(`Unable to inspect image (${u.status})`);const s=await u.json();if(!s.isFile)throw new Error("Image path is not a file");if(typeof s.size=="number"&&s.size>$)throw new Error("Image is too large");const c=await G("/api/fs/raw",{query:{path:n,directory:e},signal:t});if(!c.ok)throw new Error(`Unable to load image (${c.status})`);const i=(c.headers.get("content-type")??"").split(";",1)[0]?.toLowerCase()??"",p=Number(c.headers.get("content-length"));if(Number.isFinite(p)&&p>$)throw new Error("Image is too large");const m=await c.blob();return await V(m,i),L(t),ue(m)},we=(r,e)=>Y().authenticatedAsset("/api/fs/raw",{path:r.path,directory:e,allowOutsideWorkspace:r.outsideFileGrant?"true":void 0,outsideFileGrant:r.outsideFileGrant}),be=r=>{const e=B.c(7),[t,o]=h.useState(!1),[n,u]=h.useState(0);let s;e[0]===Symbol.for("react.memo_cache_sentinel")?(s=te(),e[0]=s):s=e[0];const c=s;let i,p;e[1]!==r?(i=()=>{if(!r){o(!1);return}let w=!1,y;const a=re(c),g=oe(()=>{w||u(Ie)}),I=()=>{ae(c).then(()=>{w||o(!0)}).catch(()=>{w||(y=setTimeout(I,1e3))})};return I(),()=>{w=!0,y&&clearTimeout(y),a(),g()}},p=[c,r],e[1]=r,e[2]=i,e[3]=p):(i=e[2],p=e[3]),h.useEffect(i,p);const m=!r||t;let l;return e[4]!==n||e[5]!==m?(l={ready:m,nonce:n},e[4]=n,e[5]=m,e[6]=l):l=e[6],l},ye=r=>{const e=B.c(46),{candidate:t,preparation:o,directory:n,assetAuthReady:u,assetAuthNonce:s,useWorkspaceFsBridge:c,onShowPopup:i}=r,{t:p}=Q(),m=h.useRef(null),[l,w]=h.useState(!1);let y;e[0]===Symbol.for("react.memo_cache_sentinel")?(y={url:"",status:"loading"},e[0]=y):y=e[0];const[a,g]=h.useState(y);let I;e[1]!==t.source?(I=q(t.source),e[1]=t.source,e[2]=I):I=e[2];const b=I;let A,f;e[3]!==l?(A=()=>{const N=m.current;if(!N||l)return;if(typeof IntersectionObserver>"u"){w(!0);return}const E=new IntersectionObserver(F=>{F.some(Ee)&&(w(!0),E.disconnect())},{rootMargin:"200px"});return E.observe(N),()=>E.disconnect()},f=[l],e[3]=l,e[4]=A,e[5]=f):(A=e[4],f=e[5]),h.useEffect(A,f);let v;e[6]!==u||e[7]!==t.source||e[8]!==n||e[9]!==b||e[10]!==o||e[11]!==l||e[12]!==c?(v=()=>{if(!l||b&&!c&&!o)return;if(b&&c){const E=new AbortController;return g({url:"",status:"loading"}),he(t.source,n,E.signal).then(F=>{E.signal.aborted||g({url:F,status:"loading"})}).catch(()=>{E.signal.aborted||g({url:"",status:"error"})}),()=>E.abort()}if(b){if(o?.status!=="ready"){g({url:"",status:"error"});return}if(!u)return;g({url:we(o,n),status:"loading"});return}const N=new AbortController;return g({url:"",status:"loading"}),ge(t.source,N.signal).then(E=>{N.signal.aborted||g({url:E,status:"loading"})}).catch(()=>{N.signal.aborted||g({url:"",status:"error"})}),()=>N.abort()},e[6]=u,e[7]=t.source,e[8]=n,e[9]=b,e[10]=o,e[11]=l,e[12]=c,e[13]=v):v=e[13];let k;e[14]!==s||e[15]!==u||e[16]!==t.source||e[17]!==n||e[18]!==b||e[19]!==o||e[20]!==l||e[21]!==c?(k=[s,u,t.source,n,b,o,l,c],e[14]=s,e[15]=u,e[16]=t.source,e[17]=n,e[18]=b,e[19]=o,e[20]=l,e[21]=c,e[22]=k):k=e[22],h.useEffect(v,k);let R;e[23]!==t.filename||e[24]!==a.status||e[25]!==a.url||e[26]!==i||e[27]!==p?(R=()=>{if(a.status==="error"){H.error(p("filesView.error.previewUnavailable"));return}a.status!=="ready"||!i||i({open:!0,title:t.filename,content:"",metadata:{tool:"markdown-image-preview",filename:t.filename},image:{url:a.url,filename:t.filename}})},e[23]=t.filename,e[24]=a.status,e[25]=a.url,e[26]=i,e[27]=p,e[28]=R):R=e[28];const U=R,j=a.status==="loading";let x;e[29]!==t.filename||e[30]!==a.status||e[31]!==a.url?(x=P.jsx("span",{className:"flex h-[72px] w-[100px] items-center justify-center overflow-hidden rounded-lg border border-border/40 bg-muted/10",children:a.url&&a.status!=="error"?P.jsx("img",{src:a.url,alt:t.filename,className:"h-full w-full object-contain",loading:"lazy",decoding:"async",referrerPolicy:"no-referrer",onLoad:()=>g(xe),onError:()=>g({url:"",status:"error"}),"data-openchamber-markdown-image":"true","data-openchamber-markdown-image-thumbnail":"true","data-openchamber-markdown-image-state":a.status}):P.jsx(W,{name:"file-image",className:"h-5 w-5 text-muted-foreground"})}),e[29]=t.filename,e[30]=a.status,e[31]=a.url,e[32]=x):x=e[32];let _;e[33]===Symbol.for("react.memo_cache_sentinel")?(_=P.jsx(W,{name:"file-image",className:"h-3 w-3 shrink-0"}),e[33]=_):_=e[33];let S;e[34]!==t.filename?(S=P.jsx("span",{className:"min-w-0 truncate typography-meta",children:t.filename}),e[34]=t.filename,e[35]=S):S=e[35];let C;e[36]!==t.filename||e[37]!==S?(C=P.jsxs("span",{className:"mt-1 flex w-[100px] items-center justify-center gap-1 text-muted-foreground",title:t.filename,"data-openchamber-markdown-image-caption":"true",children:[_,S]}),e[36]=t.filename,e[37]=S,e[38]=C):C=e[38];let M;return e[39]!==t.filename||e[40]!==t.source||e[41]!==U||e[42]!==C||e[43]!==j||e[44]!==x?(M=P.jsxs("button",{ref:m,type:"button",className:"w-[100px] shrink-0 text-left outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)]","aria-label":t.filename,disabled:j,onClick:U,"data-openchamber-markdown-image-action":"true","data-openchamber-markdown-image-source":t.source,"data-openchamber-markdown-image-filename":t.filename,children:[x,C]}),e[39]=t.filename,e[40]=t.source,e[41]=U,e[42]=C,e[43]=j,e[44]=x,e[45]=M):M=e[45],M},pr=r=>{const e=B.c(34),{sessionId:t,messageId:o,contents:n,onShowPopup:u}=r,s=Z()??"",c=h.useRef(null),[i,p]=h.useState(!1),[m,l]=h.useState(null),[w,y]=h.useState(0);let a;e[0]===Symbol.for("react.memo_cache_sentinel")?(a=ee(),e[0]=a):a=e[0];const g=a;let I;e[1]!==n?(I=se(n,ne),e[1]=n,e[2]=I):I=e[2];const b=I;let A;e[3]!==b?(A=g?[]:b.filter(Ae).map(ve),e[3]=b,e[4]=A):A=e[4];const f=A;let v,k;e[5]!==f.length||e[6]!==i?(v=()=>{if(f.length===0||i)return;const d=c.current;if(!d||typeof IntersectionObserver>"u"){p(!0);return}const T=new IntersectionObserver(X=>{X.some(ke)&&(p(!0),T.disconnect())},{rootMargin:"200px"});return T.observe(d),()=>T.disconnect()},k=[f.length,i],e[5]=f.length,e[6]=i,e[7]=v,e[8]=k):(v=e[7],k=e[8]),h.useEffect(v,k);let R;e[9]!==s||e[10]!==o||e[11]!==f||e[12]!==t||e[13]!==i?(R=()=>{if(!i||!t||f.length===0)return;const d=new AbortController;return de({sources:f,directory:s,sessionId:t,messageId:o,signal:d.signal}).then(T=>{d.signal.aborted||l(T)}).catch(()=>{d.signal.aborted||l(new Map(f.map(Re)))}),()=>d.abort()},e[9]=s,e[10]=o,e[11]=f,e[12]=t,e[13]=i,e[14]=R):R=e[14];let U;e[15]!==s||e[16]!==o||e[17]!==w||e[18]!==f||e[19]!==t||e[20]!==i?(U=[s,o,w,f,t,i],e[15]=s,e[16]=o,e[17]=w,e[18]=f,e[19]=t,e[20]=i,e[21]=U):U=e[21],h.useEffect(R,U);let j,x;e[22]!==m?(j=()=>{const d=Math.min(...[...m?.values()??[]].filter(_e).map(Se));if(!Number.isFinite(d))return;const T=setTimeout(()=>y(Me),Math.max(0,d-Date.now()));return()=>clearTimeout(T)},x=[m],e[22]=m,e[23]=j,e[24]=x):(j=e[23],x=e[24]),h.useEffect(j,x);let _;e[25]!==m?(_=d=>m?.get(d.source)?.status!=="missing",e[25]=m,e[26]=_):_=e[26];const S=b.filter(_),C=[...m?.values()??[]].some(Ne),M=be(C);if(S.length===0)return null;const N="mt-3 flex max-w-full gap-2 overflow-x-auto pb-1",E="true";let F;e[27]!==M||e[28]!==s||e[29]!==u||e[30]!==m?(F=d=>P.jsx(ye,{candidate:d,preparation:m?.get(d.source),directory:s,assetAuthReady:M.ready,assetAuthNonce:M.nonce,useWorkspaceFsBridge:g,onShowPopup:u},d.source),e[27]=M,e[28]=s,e[29]=u,e[30]=m,e[31]=F):F=e[31];const D=S.map(F);let O;return e[32]!==D?(O=P.jsx("div",{ref:c,className:N,"data-openchamber-markdown-image-gallery":E,children:D}),e[32]=D,e[33]=O):O=e[33],O};function Ie(r){return r+1}function Ee(r){return r.isIntersecting}function xe(r){return{...r,status:"ready"}}function Ae(r){return q(r.source)}function ve(r){return r.source}function ke(r){return r.isIntersecting}function Re(r){return[r,{status:"error"}]}function _e(r){return r.status==="ready"}function Se(r){return r.expiresAt??Number.POSITIVE_INFINITY}function Me(r){return r+1}function Ne(r){return r.status==="ready"}export{pr as MarkdownImageGallery};
@@ -1,12 +0,0 @@
1
- import{R as E,f as se,j as te}from"./vendor-react-BUCujlKS.js";import{m as zt}from"./vendor-morphdom-B7dS_VPB.js";import{r as Ht,a as Vt}from"./vendor-beautiful-mermaid-DztCUpLZ.js";import{fu as at,fv as Kt,fw as jt,fx as Ut,g as we,bb as Zt,be as Xt,fy as Gt,fz as Yt,W as lt,ac as ct,fA as dt,f as ut,h as mt,ea as Jt,eb as We,fB as Qt,fC as qe,fD as en,fE as tn,fF as nn,fG as rn,fH as on,o as sn}from"./useAppFontEffects-D7sNpuL2.js";import{r as an,G as pt,J as ne,cB as ln,u as G,a as cn,z as dn,A as un}from"./index-DF5kMP-i.js";import{h as mn}from"./contextPanelEmbeddedChat-C0ZLAepL.js";import{getCachedMarkdownBlocks as Be,renderMarkdownSync as pn,renderMarkdownBlocks as fn}from"./markdownCore-BrBwOOMn.js";import{r as hn}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-BeMD8X_w.js";import"./vendor-floating-ui-utils-D6FqdtJt.js";import"./vendor-floating-ui-react-dom-DxYCWdHj.js";import"./vendor-floating-ui-dom-BTvzWks8.js";import"./vendor-floating-ui-core-PuGzNPnN.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-framer-motion-livSKyyV.js";import"./vendor-motion-dom-D_o3BTI3.js";import"./vendor-motion-utils-BGh8QBgx.js";import"./vendor-tanstack-react-virtual-g05Cx3z9.js";import"./vendor-tanstack-virtual-core-Dubg10g5.js";import"./vendor-sonner-DFyL3AvE.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-BgPj_McA.js";import"./vendor-lezer-common-B3-cUCR_.js";import"./vendor-codemirror-state-C9awkmn-.js";import"./vendor-marijn-find-cluster-break-DXwl3gUT.js";import"./vendor-codemirror-view-CiLROUVV.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-Cc2ZYbgX.js";import"./vendor-lezer-javascript-D7Tj24ot.js";import"./vendor-lezer-lr-bhwg1HMg.js";import"./vendor-codemirror-autocomplete-DzPz9Wgq.js";import"./vendor-codemirror-lang-json-CMBS2tG9.js";import"./vendor-lezer-json-Iaex0UN-.js";import"./vendor-codemirror-lang-css-O0cZX78y.js";import"./vendor-lezer-css-C5xB6jxd.js";import"./vendor-codemirror-lang-html-CfgK872x.js";import"./vendor-lezer-html-C0I1p52t.js";import"./vendor-codemirror-lang-markdown-BPGOH9ye.js";import"./vendor-lezer-markdown-C6g-d6P3.js";import"./vendor-codemirror-language-data-Dp3KMRQG.js";import"./vendor-codemirror-lang-python-HahnQaAS.js";import"./vendor-lezer-python-CvuFxeZl.js";import"./vendor-codemirror-commands-B7H_j0iU.js";import"./vendor-legendapp-list-gg7YLRW7.js";import"./vendor-tailwind-merge-CPcsbTWB.js";import"./vendor-fuse.js-Dw8P0qyA.js";import"./vendor-zod-CK21ihK-.js";import"./vendor-opencode-sdk-BJ73u-bH.js";import"./vendor-marked-CX41MkDF.js";import"./vendor-marked-linkify-it-CXI_LHIE.js";import"./vendor-linkify-it-DZCzzDkK.js";import"./vendor-uc.micro-BAd0H0z4.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 ft=t=>{const e=t.target;if(!(e instanceof Element))return null;const n=e.closest("a[href]");return!(n instanceof HTMLAnchorElement)||n.getAttribute("data-openchamber-file-link")==="true"?null:n},Me=(t,e)=>{if(t.defaultPrevented)return!1;const r=ft(t)?.getAttribute("href")??"";return Kt(r)?(t.preventDefault(),t.stopPropagation(),e?.(r),!0):!1},gn=t=>t.button===0&&!t.metaKey&&!t.ctrlKey&&!t.altKey&&!t.shiftKey,bn=(t,e)=>{const n=o=>{if(Me(o,e.openAppLink)||!e.allowExternalHttp||o.defaultPrevented||!gn(o))return;const s=ft(o)?.getAttribute("href")??"";at(s)&&(o.preventDefault(),o.stopPropagation(),e.openExternalHttp(s))},r=o=>{o.button===1&&Me(o,e.openAppLink)},i=o=>{Me(o)};return t.addEventListener("click",n),t.addEventListener("auxclick",r),t.addEventListener("dragstart",i),()=>{t.removeEventListener("click",n),t.removeEventListener("auxclick",r),t.removeEventListener("dragstart",i)}},ht="openchamber-md",wn={name:ht,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 $e=!1;const yn=()=>{$e||($e=!0,hn(ht,()=>Promise.resolve(wn)))},T=t=>Number.isFinite(t)&&t>0,ze=t=>{if(t==null)return null;const e=String(t).trim().match(/^([+-]?(?:(?:\d+\.?\d*)|(?:\.\d+))(?:[eE][+-]?\d+)?)(?:px)?$/);if(!e)return null;const n=Number(e[1]);return T(n)?n:null},Ne=(t,e,n)=>Math.min(n,Math.max(e,t)),An=6,He=1.25,vn=1.0015,kn=.5,En=12,Ve=3,Cn=400,re='[data-markdown="mermaid-block"]',I=t=>t.querySelector(re)!==null,Sn=t=>[t.x,t.y,t.width,t.height].map(e=>{const n=Number(e.toFixed(An));return Object.is(n,-0)?"0":String(n)}).join(" "),Ln=t=>{const e=t.viewBox?.trim().split(/[\s,]+/).map(i=>Number.parseFloat(i));if(e?.length===4){const[i,o,s,a]=e;if(Number.isFinite(i)&&Number.isFinite(o)&&T(s)&&T(a))return{x:i,y:o,width:s,height:a}}const n=ze(t.width),r=ze(t.height);return n===null||r===null?null:{x:0,y:0,width:n,height:r}},Mn=t=>{let e=2166136261;for(let n=0;n<t.length;n+=1)e^=t.charCodeAt(n),e=Math.imul(e,16777619);return(e>>>0).toString(36)},Nn=t=>{const e=t.renderMode||"unknown",n=t.svgMarkup??"";if(!n){const r=[t.viewBox??"",t.width??"",t.height??""];return r.some(i=>i!=="")?`${e}:bounds:${r.join(":")}`:`${e}:no-svg`}return[e,Mn(n)].join(":")},gt=(t,e)=>{if(!T(e.width)||!T(e.height))return t;const n=t.width/t.height,r=e.width/e.height;if(n>r){const o=t.width/r;return{x:t.x,y:t.y-(o-t.height)/2,width:t.width,height:o}}const i=t.height*r;return{x:t.x-(i-t.width)/2,y:t.y,width:i,height:t.height}},Rn=({currentBox:t,viewport:e,delta:n})=>!T(e.width)||!T(e.height)||!T(t.width)||!T(t.height)?t:{x:t.x-n.x/e.width*t.width,y:t.y-n.y/e.height*t.height,width:t.width,height:t.height},Tn=(t,e)=>{const n=e.x-t.x,r=e.y-t.y;return n*n+r*r>Ve*Ve},_n=({currentBox:t,contentBox:e,viewport:n,pointer:r,zoomFactor:i,minScale:o,maxScale:s})=>{if(!T(n.width)||!T(n.height)||!T(i)||!T(t.width)||!T(t.height)||!T(e.width)||!T(e.height)||!T(o)||!T(s))return t;const a=Math.min(o,s),l=Math.max(o,s),c=gt(e,n),u=c.width/t.width,f=Ne(u*i,a,l),m=c.width/f,g=m/(t.width/t.height),y=Ne(r.x/n.width,0,1),v=Ne(r.y/n.height,0,1),C=t.x+y*t.width,p=t.y+v*t.height;return{x:C-y*m,y:p-v*g,width:m,height:g}},ye=new WeakMap,Ie=new WeakMap,K=new Set,oe=new Set;let V=null,ee=null,J=null;const xn=t=>t.querySelector('[data-markdown="mermaid-viewport"]')??t.querySelector('[data-markdown="mermaid"]'),bt=t=>{const e=t.querySelector('[data-markdown="mermaid"] svg'),n=t.querySelector('[data-markdown="mermaid"]');return Nn({renderMode:t.getAttribute("data-mermaid-render"),svgMarkup:n?.getAttribute("data-md-original-svg")??e?.outerHTML??null,viewBox:e?.getAttribute("viewBox"),width:e?.getAttribute("width"),height:e?.getAttribute("height")})},X=t=>{const e=t.getBoundingClientRect();return{width:e.width,height:e.height}},Pn=(t,e)=>{const n=e.getBoundingClientRect();return{x:t.clientX-n.left,y:t.clientY-n.top}},In=t=>t instanceof Element&&!!t.closest('button, a, [role="button"]'),wt=t=>{const e=t.map(n=>X(n.viewport));t.forEach((n,r)=>{const i=e[r];i&&n.fitToViewport(i)})},yt=()=>{J!==null||K.size===0||(J=window.requestAnimationFrame(()=>{J=null,wt(Array.from(K))}))},Fn=()=>{if(V)return V;const t=globalThis.ResizeObserver;return t?(V=new t(e=>{for(const n of e)n.target instanceof HTMLElement&&Ie.get(n.target)?.fitToViewport({width:n.contentRect.width,height:n.contentRect.height})}),V):null},Dn=t=>{if(K.has(t))return;const e=K.size===0;K.add(t),Ie.set(t.viewport,t),Fn()?.observe(t.viewport),e&&window.addEventListener("resize",yt)},On=t=>{K.delete(t)&&(V?.unobserve(t.viewport),Ie.delete(t.viewport),!(K.size>0)&&(V?.disconnect(),V=null,window.removeEventListener("resize",yt),J!==null&&(window.cancelAnimationFrame(J),J=null)))},Wn=t=>{const e=xn(t),n=t.querySelector('[data-markdown="mermaid"] svg');if(!e||!n)return null;const r=Ln({viewBox:n.getAttribute("viewBox"),width:n.getAttribute("width"),height:n.getAttribute("height")});if(!r)return null;let i=r,o=null,s=null,a=null,l=null;const c=d=>{i=d,n.setAttribute("viewBox",Sn(d)),n.removeAttribute("width"),n.removeAttribute("height")},u=d=>{c(gt(r,d))},f=()=>{u(X(e))},m=(d,b)=>{c(_n({currentBox:i,contentBox:r,viewport:X(e),pointer:d,zoomFactor:b,minScale:kn,maxScale:En}))},g=()=>{const d=X(e);m({x:d.width/2,y:d.height/2},He)},y=()=>{const d=X(e);m({x:d.width/2,y:d.height/2},1/He)},v=d=>{!d.ctrlKey&&!d.metaKey||(d.preventDefault(),d.stopPropagation(),m(Pn(d,e),Math.pow(vn,-d.deltaY)))},C=d=>{d.button!==0||In(d.target)||(o=d.pointerId,s={x:d.clientX,y:d.clientY},a=s,l!==null&&(window.clearTimeout(l),l=null),t.removeAttribute("data-mermaid-suppress-click"),e.setPointerCapture?.(d.pointerId),t.setAttribute("data-mermaid-panning","true"),d.preventDefault())},p=d=>{if(o!==d.pointerId||!a)return;const b={x:d.clientX,y:d.clientY};c(Rn({currentBox:i,viewport:X(e),delta:{x:b.x-a.x,y:b.y-a.y}})),a=b,s&&Tn(s,b)&&t.setAttribute("data-mermaid-suppress-click","true"),d.preventDefault()},h=d=>{o===d.pointerId&&(e.releasePointerCapture?.(d.pointerId),o=null,s=null,a=null,t.removeAttribute("data-mermaid-panning"),t.hasAttribute("data-mermaid-suppress-click")&&(l=window.setTimeout(()=>{t.removeAttribute("data-mermaid-suppress-click"),l=null},Cn)))};e.addEventListener("wheel",v,{passive:!1}),e.addEventListener("pointerdown",C),e.addEventListener("pointermove",p),e.addEventListener("pointerup",h),e.addEventListener("pointercancel",h);const k={viewport:e,zoomIn:g,zoomOut:y,fit:f,fitToViewport:u,cleanup:()=>{On(k),e.removeEventListener("wheel",v),e.removeEventListener("pointerdown",C),e.removeEventListener("pointermove",p),e.removeEventListener("pointerup",h),e.removeEventListener("pointercancel",h),l!==null&&window.clearTimeout(l),t.removeAttribute("data-mermaid-panning"),t.removeAttribute("data-mermaid-suppress-click"),ye.delete(t)}};return k},At=t=>{for(const[e,n]of t.controllers){const r=bt(e);(!t.container.contains(e)||r!==t.signatures.get(e))&&(n.cleanup(),t.controllers.delete(e),t.signatures.delete(e))}},qn=t=>{if(t.disposed)return[];const e=[];for(const n of Array.from(t.container.querySelectorAll(re))){if(t.controllers.has(n)||n.querySelector('[data-markdown="mermaid"] svg')===null)continue;const r=Wn(n);r&&(t.controllers.set(n,r),t.signatures.set(n,bt(n)),ye.set(n,r),e.push(r))}return e},vt=()=>{const t=Array.from(oe);oe.clear();const e=[];for(const n of t)n.disposed||(At(n),e.push(...qn(n)));wt(e);for(const n of e)Dn(n)},Bn=()=>{ee===null&&(ee=window.requestAnimationFrame(()=>{ee=null,ee=window.requestAnimationFrame(()=>{ee=null,vt()})}))},$n=t=>{t.disposed||(At(t),oe.add(t),Bn())},zn=t=>{if(!(t instanceof HTMLElement))return null;const e=ye.get(t);if(e)return e;for(const n of oe)if(n.container.contains(t))return vt(),ye.get(t)??null;return null},Hn=t=>{const e={container:t,controllers:new Map,signatures:new Map,disposed:!1},n=()=>$n(e),r=()=>{e.disposed=!0,oe.delete(e);for(const i of e.controllers.values())i.cleanup();e.controllers.clear(),e.signatures.clear()};return n(),{refresh:n,cleanup:r}},Vn={copy:"file-copy",check:"check",download:"download",zoomIn:"add",zoomOut:"subtract",fit:"refresh",textWrap:"text-wrap",image:"file-image"},kt="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)]",ie=(t,e)=>{const n=Vn[e],r=t.ownerDocument.createElementNS("http://www.w3.org/2000/svg","svg");r.setAttribute("class","remixicon size-3.5"),r.setAttribute("viewBox","0 0 24 24"),r.setAttribute("aria-hidden","true");const i=t.ownerDocument.createElementNS("http://www.w3.org/2000/svg","use");i.setAttribute("href",`#oc-${n}`),r.appendChild(i),t.replaceChildren(r)},Kn=t=>{for(const e of Array.from(t.querySelectorAll('[data-openchamber-markdown-image-label="true"]'))){if(e.querySelector("[data-openchamber-markdown-image-label-icon]"))continue;const n=document.createElement("span");n.className="inline-flex shrink-0",n.setAttribute("aria-hidden","true"),n.setAttribute("data-openchamber-markdown-image-label-icon","true"),ie(n,"image"),e.prepend(n)}},B=(t,e,n)=>{const r=document.createElement("button");return r.type="button",r.className=kt,r.setAttribute("data-md-action",n),r.setAttribute("title",e),r.setAttribute("aria-label",e),ie(r,t),r},Et=(t,e,n)=>{const r=t.querySelector("[data-md-code-body]"),i=t.querySelector("pre"),o=t.querySelector("pre code"),s=t.querySelectorAll("[data-md-code-line-content]"),a=t.querySelector('[data-md-action="toggle-code-wrap"]');t.setAttribute("data-code-wrap",e?"true":"false"),r?.classList.toggle("overflow-x-auto",!e),r?.classList.toggle("overflow-x-hidden",e),i?.classList.toggle("whitespace-pre-wrap",e),i?.classList.toggle("break-words",e),o?.classList.toggle("whitespace-pre-wrap",e),o?.classList.toggle("break-words",e),i&&(i.style.whiteSpace=e?"pre-wrap":"pre",i.style.overflowWrap=e?"anywhere":"normal"),o&&(o.style.whiteSpace=e?"pre-wrap":"pre",o.style.overflowWrap=e?"anywhere":"normal");for(const l of Array.from(s))l.style.whiteSpace=e?"pre-wrap":"pre",l.style.overflowWrap=e?"anywhere":"normal";if(a){const l=e?n.disableCodeWrap:n.enableCodeWrap;a.setAttribute("title",l),a.setAttribute("aria-label",l),a.classList.toggle("text-foreground",e),a.classList.toggle("opacity-100",e),a.classList.toggle("text-muted-foreground",!e),a.classList.toggle("opacity-65",!e),a.setAttribute("aria-pressed",e?"true":"false")}},Ct=t=>{const e=t.querySelector(":scope > code");if(!e||e.hasAttribute("data-md-code-lines"))return;t.removeAttribute("data-md-gutter-reserved");const n=e.textContent??"",r=n.endsWith(`
2
- `),i=r?n.slice(0,-1).split(`
3
- `):n.split(`
4
- `),o=i.length>0?i:[""],s=Array.from(e.children).filter(c=>c.classList.contains("line"));r&&s.length===o.length+1&&s.at(-1)?.textContent===""&&s.pop();const a=s.length===o.length,l=document.createDocumentFragment();o.forEach((c,u)=>{const f=document.createElement("span");f.setAttribute("data-md-code-line","");const m=document.createElement("span");m.setAttribute("data-md-code-line-number",String(u+1)),m.setAttribute("aria-hidden","true");const g=document.createElement("span");if(g.setAttribute("data-md-code-line-content",""),a){const y=s[u];y&&g.append(...Array.from(y.childNodes))}else g.textContent=c;if(f.append(m,g),l.appendChild(f),u<o.length-1||r){const y=document.createElement("span");y.setAttribute("data-md-code-line-break",""),y.textContent=`
5
- `,l.appendChild(y)}}),e.replaceChildren(l),e.setAttribute("data-md-code-lines",""),e.toggleAttribute("data-md-code-trailing-newline",r)},St=t=>{const e=Array.from(t.querySelectorAll("[data-md-code-line-content]"));if(e.length===0)return t.textContent??"";const n=e.map(r=>r.textContent??"").join(`
6
- `);return t.hasAttribute("data-md-code-trailing-newline")?`${n}
7
- `:n},Ke=(t,e,n)=>{const r=t.querySelectorAll('[data-component="markdown-code"]');for(const i of Array.from(r)){const o=i.querySelector("pre");o&&Ct(o),Et(i,e,n)}},je=(t,e,n,r)=>{ie(t,"check"),t.setAttribute("title",e),t.setAttribute("aria-label",e),window.setTimeout(()=>{ie(t,n),t.setAttribute("title",r),t.setAttribute("aria-label",r)},2e3)},jn=t=>{const e=t.querySelectorAll(":not(pre) > code");for(const n of Array.from(e))n.getAttribute("data-markdown")!=="inline-code"&&n.setAttribute("data-markdown","inline-code")},Un=(t,e)=>{const n=t.querySelectorAll("pre");for(const r of Array.from(n)){if(r.querySelector("code.language-mermaid"))continue;const i=r.parentElement;if(!i||i.closest('[data-component="markdown-code"]'))continue;const o=r.querySelector("code")?.className.match(/language-([\w+#.-]+)/)?.[1],s=r.getAttribute("data-md-lang")??o??"text",a=document.createElement("div");a.setAttribute("data-component","markdown-code"),a.className="my-4 group overflow-hidden rounded-2xl border border-border/80 bg-[var(--surface-elevated)]";const l=document.createElement("div");l.className="flex items-center justify-between border-b border-border/70 px-3 py-1.5";const c=document.createElement("span");c.className="font-mono text-[13px] text-muted-foreground",c.textContent=s;const u=B("copy",e.labels.copy,"copy-code"),f=B("textWrap",e.codeBlockLineWrap?e.labels.disableCodeWrap:e.labels.enableCodeWrap,"toggle-code-wrap");l.appendChild(c);const m=document.createElement("div");m.className="flex items-center gap-1",m.setAttribute("data-md-code-actions",""),m.appendChild(f),m.appendChild(u),l.appendChild(m);const g=document.createElement("div");g.setAttribute("data-md-code-body",""),g.className="px-3 py-2.5 overflow-x-auto",i.replaceChild(a,r),r.style.margin="0",r.style.background="transparent",r.classList.add("min-w-0","w-full","flex-1"),e.deferCodeLineNumberSync?r.setAttribute("data-md-gutter-reserved",""):Ct(r),g.appendChild(r),a.appendChild(l),a.appendChild(g),Et(a,e.codeBlockLineWrap,e.labels)}},Ue=t=>{const e=[],n=[],r=t.querySelectorAll("thead th");for(const o of Array.from(r))e.push((o.textContent??"").trim());const i=t.querySelectorAll("tbody tr");for(const o of Array.from(i)){const s=Array.from(o.querySelectorAll("td")).map(a=>(a.textContent??"").trim());s.length>0&&n.push(s)}return{headers:e,rows:n}},Zn=t=>/[",\n]/.test(t)?`"${t.replace(/"/g,'""')}"`:t,Ze=({headers:t,rows:e})=>[t,...e].map(n=>n.map(Zn).join(",")).join(`
8
- `),Xn=({headers:t,rows:e})=>[t,...e].map(n=>n.join(" ")).join(`
9
- `),Xe=({headers:t,rows:e})=>{const n=`| ${t.join(" | ")} |`,r=`| ${t.map(()=>"---").join(" | ")} |`,i=e.map(o=>`| ${o.join(" | ")} |`).join(`
10
- `);return`${n}
11
- ${r}
12
- ${i}`},Ge=(t,e)=>{const n=document.createElement("div");n.className=`absolute top-full right-0 mt-1 hidden ${Zt}`,n.style.backgroundColor="var(--surface-elevated)",n.style.color="var(--surface-elevated-foreground)",n.setAttribute("data-md-menu",t);for(const r of e){const i=document.createElement("button");i.type="button",i.className=`w-full text-left ${Xt}`,i.setAttribute("data-md-action",`${t}-${r.key}`),i.textContent=r.label,n.appendChild(i)}return n},Gn=120,Yn=320,Pe="data-md-table-layout",Jn=(t,e)=>{const n=t.querySelectorAll("table");for(const r of Array.from(n)){if(r.closest('[data-markdown="table-wrapper"]'))continue;const o=document.createElement("div");o.className="group my-4 flex flex-col space-y-2",o.setAttribute("data-markdown","table-wrapper");const s=document.createElement("div");s.className="flex items-center justify-end gap-1";const a=document.createElement("div");a.className="relative",a.appendChild(B("copy",e.copyTable,"table-copy-toggle")),a.appendChild(Ge("table-copy",[{key:"csv",label:"CSV"},{key:"tsv",label:"TSV"},{key:"markdown",label:"Markdown"}]));const l=document.createElement("div");l.className="relative",l.appendChild(B("download",e.downloadTable,"table-download-toggle")),l.appendChild(Ge("table-download",[{key:"csv",label:"CSV"},{key:"markdown",label:"Markdown"}])),s.appendChild(a),s.appendChild(l);const c=document.createElement("div");c.className="overflow-x-auto rounded-lg border border-border/80 bg-[var(--surface-elevated)]";const u=r.parentElement;if(!u)continue;u.replaceChild(o,r),r.setAttribute("data-markdown","table"),r.setAttribute(Pe,"pending"),r.classList.add("w-max","border-collapse","text-sm");for(const m of Array.from(r.querySelectorAll("tr")))m.classList.add("border-b","border-border/60");const f=r.querySelector("tbody tr:last-child");f?.classList.remove("border-b"),f?.classList.add("border-0");for(const m of Array.from(r.querySelectorAll("th")))m.classList.add("min-w-[120px]","max-w-[320px]","whitespace-normal","[overflow-wrap:anywhere]","border-r","border-border/60","px-4","py-2.5","text-left","align-middle","font-semibold","text-foreground","last:border-r-0");for(const m of Array.from(r.querySelectorAll("td")))m.classList.add("min-w-[120px]","max-w-[320px]","whitespace-normal","[overflow-wrap:anywhere]","border-r","border-border/60","px-4","py-2.5","align-middle","text-foreground/90","last:border-r-0");c.appendChild(r),o.appendChild(s),o.appendChild(c)}},Qn=t=>{const e=Array.from(t.querySelectorAll(`table[data-markdown="table"]:not([${Pe}="fixed"])`));if(e.length===0||!t.isConnected)return;const n=t.ownerDocument.createElement("div");n.setAttribute("aria-hidden","true"),n.setAttribute("data-md-table-measure",""),n.style.position="fixed",n.style.left="-100000px",n.style.top="0",n.style.visibility="hidden",n.style.pointerEvents="none",n.style.width="max-content";const r=e.map(o=>{const s=f=>Array.from(f.children).filter(m=>m.tagName==="TH"||m.tagName==="TD"),a=Array.from(o.querySelectorAll("tbody tr")),l=a.some(f=>s(f).length>0)?a:Array.from(o.querySelectorAll("thead tr")),c=Math.max(0,...Array.from(o.querySelectorAll("tr")).map(f=>s(f).length)),u=[];for(let f=0;f<c;f+=1){const m=t.ownerDocument.createElement("table");m.className=o.className,m.style.tableLayout="auto",m.style.width="max-content";const g=t.ownerDocument.createElement("tbody");for(const y of l){const v=s(y)[f];if(!v)continue;const C=t.ownerDocument.createElement("tr"),p=v.cloneNode(!0);p instanceof HTMLElement&&(p.style.width="auto",p.style.minWidth="0",p.style.maxWidth="none",p.style.whiteSpace="nowrap",p.style.overflowWrap="normal",C.appendChild(p),g.appendChild(C))}m.appendChild(g),n.appendChild(m),u.push(m)}return{table:o,columnProbes:u}});t.appendChild(n);const i=r.map(({table:o,columnProbes:s})=>({table:o,widths:s.map(a=>Math.min(Yn,Math.max(Gn,Math.ceil(a.getBoundingClientRect().width))))}));n.remove();for(const{table:o,widths:s}of i){Array.from(o.children).find(u=>u.matches("colgroup[data-md-table-columns]"))?.remove();const l=t.ownerDocument.createElement("colgroup");l.setAttribute("data-md-table-columns","");for(const u of s){const f=t.ownerDocument.createElement("col");f.style.width=`${u}px`,l.appendChild(f)}const c=Array.from(o.children).find(u=>u.tagName==="THEAD"||u.tagName==="TBODY"||u.tagName==="TFOOT")??null;o.insertBefore(l,c),o.style.tableLayout="fixed",o.style.width=`${s.reduce((u,f)=>u+f,0)}px`,o.setAttribute(Pe,"fixed")}},er=(t,e)=>{const n=t.querySelectorAll("pre > code.language-mermaid");for(const r of Array.from(n)){const i=r.parentElement;if(!i)continue;const o=(r.textContent??"").replace(/\s+$/,""),s=e.renderMermaid(o),a=document.createElement("div");a.setAttribute("data-markdown","mermaid-block"),a.setAttribute("data-md-source",o),a.className="group relative";const l=document.createElement("div");l.setAttribute("data-markdown","mermaid-scroll");const c=document.createElement("div");if(c.setAttribute("data-markdown","mermaid-toolbar"),c.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){a.setAttribute("data-mermaid-render","svg");const f=document.createElement("div");f.setAttribute("data-markdown","mermaid-viewport");const m=document.createElement("div");if(m.setAttribute("data-markdown","mermaid"),m.setAttribute("data-md-original-svg",s.svg),m.innerHTML=s.svg,f.appendChild(m),l.appendChild(f),e.mermaidControls.showPanZoomControls&&(c.appendChild(B("zoomIn",e.labels.zoomInDiagram,"mermaid-zoom-in")),c.appendChild(B("zoomOut",e.labels.zoomOutDiagram,"mermaid-zoom-out")),c.appendChild(B("fit",e.labels.resetDiagramView,"mermaid-fit"))),e.mermaidControls.copy){const g=B("copy",e.labels.copyDiagram,"mermaid-copy");g.setAttribute("data-md-source",o),c.appendChild(g)}if(e.mermaidControls.download){const g=B("download",e.labels.downloadDiagram,"mermaid-download");g.setAttribute("data-md-svg","1"),c.appendChild(g)}}else{a.setAttribute("data-mermaid-render","ascii");const f=document.createElement("pre");if(f.setAttribute("data-markdown","mermaid-ascii"),f.textContent=s.ascii||o,l.appendChild(f),e.mermaidControls.copy){const m=B("copy",e.labels.copyDiagram,"mermaid-copy");m.setAttribute("data-md-source",s.ascii||o),c.appendChild(m)}}a.appendChild(l),a.appendChild(c);const u=i.parentElement;u&&u.replaceChild(a,i)}},tr=(t,e)=>{const n=t.querySelectorAll("a[href]");for(const r of Array.from(n)){if(r.getAttribute("data-md-link-decorated")==="true"||r.getAttribute("data-openchamber-file-link")==="true")continue;const i=r.getAttribute("href")??"";if(!at(i))continue;r.setAttribute("data-md-link-decorated","true");const o=jt(i);if(o){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 a=document.createElement("img");a.src=o,a.alt="",a.setAttribute("aria-hidden","true"),a.loading="lazy",a.decoding="async",a.className="size-3.5 rounded-sm",a.addEventListener("error",()=>s.remove(),{once:!0}),s.appendChild(a),r.parentNode?.insertBefore(s,r)}if(e.onPreviewLoopback&&Ut(i)){const s=document.createElement("button");s.type="button",s.className=`ml-1 align-middle ${kt}`,s.setAttribute("data-md-action","preview-loopback"),s.setAttribute("data-md-url",i),s.setAttribute("title",e.labels.previewTitle),s.setAttribute("aria-label",e.labels.previewLabel),ie(s,"download"),r.parentNode?.insertBefore(s,r.nextSibling)}}},pe=(t,e)=>{Kn(t),jn(t),er(t,e),Un(t,e),Jn(t,e.labels),tr(t,e)},Ye=(t,e,n)=>{const r=new Blob([e],{type:n}),i=URL.createObjectURL(r),o=document.createElement("a");o.href=i,o.download=t,document.body.appendChild(o),o.click(),document.body.removeChild(o),URL.revokeObjectURL(i)},fe=t=>{for(const e of Array.from(t.querySelectorAll("[data-md-menu]")))e.classList.add("hidden")},Je=t=>(t.nodeType===1?t:t.parentElement)?.closest("pre code[data-md-code-lines]")??null,nr=t=>{const e=Je(t.startContainer);return!e||e!==Je(t.endContainer)?null:t.toString()},he=new WeakMap,rr=t=>{let e=he.get(t);if(!e){const n=()=>{const o=t.getSelection();return!o||o.rangeCount!==1||o.isCollapsed?null:nr(o.getRangeAt(0))},r=o=>{if(!o.clipboardData)return;const s=n();s!==null&&(o.preventDefault(),o.stopPropagation(),o.clipboardData.setData("text/plain",s))},i=o=>{const s=n();s!==null&&(o.preventDefault(),we(s))};e={registrations:0,handler:r,menuHandler:i},he.set(t,e),t.addEventListener("copy",r,!0),t.defaultView?.addEventListener("aiworker:copy",i)}return e.registrations+=1,()=>{const n=he.get(t);n&&(n.registrations-=1,!(n.registrations>0)&&(t.removeEventListener("copy",n.handler,!0),t.defaultView?.removeEventListener("aiworker:copy",n.menuHandler),he.delete(t)))}},or=(t,e)=>{const n=rr(t.ownerDocument),r=i=>{const o=i.target;if(!(o instanceof Element))return;const s=o.closest("[data-md-action]");if(!s){fe(t);return}const a=s.getAttribute("data-md-action")??"";if(a==="copy-code"){const l=s.closest('[data-component="markdown-code"]')?.querySelector("code"),c=l?St(l):"";c&&(s.setAttribute("data-md-copy-pending",""),we(c).then(()=>je(s,e.labels.copied,"copy",e.labels.copy)).finally(()=>s.removeAttribute("data-md-copy-pending")));return}if(a==="toggle-code-wrap"){i.preventDefault(),e.onToggleCodeBlockLineWrap?.();return}if(a==="table-copy-toggle"||a==="table-download-toggle"){i.preventDefault();const l=s.parentElement?.querySelector("[data-md-menu]")??null,c=l?.classList.contains("hidden")??!1;fe(t),l&&c&&l.classList.remove("hidden");return}if(a.startsWith("table-copy-")){const l=a.replace("table-copy-",""),c=s.closest('[data-markdown="table-wrapper"]')?.querySelector("table");if(c instanceof HTMLTableElement){const u=Ue(c),f=l==="csv"?Ze(u):l==="tsv"?Xn(u):Xe(u);we(f)}fe(t);return}if(a.startsWith("table-download-")){const l=a.replace("table-download-",""),c=s.closest('[data-markdown="table-wrapper"]')?.querySelector("table");if(c instanceof HTMLTableElement){const u=Ue(c),f=l==="csv"?Ze(u):Xe(u);Ye(l==="csv"?"table.csv":"table.md",f,l==="csv"?"text/csv":"text/markdown")}fe(t);return}if(a==="mermaid-copy"){const l=s.getAttribute("data-md-source")??"";l&&we(l).then(()=>je(s,e.labels.copied,"copy",e.labels.copyDiagram));return}if(a==="mermaid-zoom-in"||a==="mermaid-zoom-out"||a==="mermaid-fit"){i.preventDefault();const l=s.closest('[data-markdown="mermaid-block"]'),c=zn(l);a==="mermaid-zoom-in"?c?.zoomIn():a==="mermaid-zoom-out"?c?.zoomOut():c?.fit();return}if(a==="mermaid-download"){const l=s.closest('[data-markdown="mermaid-block"]')?.querySelector('[data-markdown="mermaid"]'),c=l?.getAttribute("data-md-original-svg")??l?.innerHTML??"";c&&Ye("diagram.svg",c,"image/svg+xml;charset=utf-8");return}if(a==="preview-loopback"){i.preventDefault();const l=s.getAttribute("data-md-url")??"";l&&e.onPreviewLoopback?.(l);return}};return t.addEventListener("click",r),()=>{n(),t.removeEventListener("click",r)}},Qe=(t,e,n)=>{let r=0;for(const o of t){const s=r+o.data.length;if(e<s||e===s&&n==="left")return{node:o,offset:Math.max(0,e-r)};r=s}const i=t.at(-1);return i?{node:i,offset:i.data.length}:null},ir=new Set(["dockerfile","makefile","readme","license",".env",".gitignore",".npmrc"]),et=Array.from(ir).map(t=>t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")).join("|"),Lt=t=>Gt(t),sr=t=>Yt(t),ar=t=>{let e;try{e=new URL(t.trim())}catch{return null}if(e.protocol!=="file:"||e.hostname&&e.hostname!=="localhost")return null;try{const n=decodeURIComponent(e.pathname);return/^\/[A-Za-z]:\//.test(n)?n.slice(1):n.startsWith("/")?n:null}catch{return null}},Ae=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):""},ge=t=>{let e=Ae(t);if(!e)return"";const n=e.indexOf(";");n>=0&&(e=e.slice(0,n)),e=e.replace(/#.*$/,"");const r=e.match(/^(.*\.[A-Za-z0-9_-]{1,16}):.*$/);r&&(e=r[1]??e);const i=et.length>0?e.match(new RegExp(`^(.*(?:/|^)(${et})):.*$`,"i")):null;return i&&(e=i[1]??e),Ae(e)},Mt=t=>{const e=Ae(t);if(!e)return null;const n=e.indexOf(";"),r=n>=0?Ae(e.slice(0,n)):e;if(!r)return null;const i=r.match(/^(.*?):(\d+)-(\d+)$/);if(i){const l=ge(i[1]??""),c=Number.parseInt(i[2]??"",10),u=Number.parseInt(i[3]??"",10);return!l||!Number.isFinite(c)||!Number.isFinite(u)||u<c?null:{path:l,line:c,endLine:u}}const o=r.match(/^(.*)#L(\d+)(?:C(\d+))?$/i);if(o){const l=ge(o[1]??""),c=Number.parseInt(o[2]??"",10),u=o[3]?Number.parseInt(o[3],10):void 0;return!l||!Number.isFinite(c)?null:{path:l,line:c,column:Number.isFinite(u??Number.NaN)?u:void 0}}const s=r.match(/^(.*?):(\d+)(?::(\d+))?$/);if(s){const l=ge(s[1]??""),c=Number.parseInt(s[2]??"",10),u=s[3]?Number.parseInt(s[3],10):void 0;return!l||!Number.isFinite(c)?null:{path:l,line:c,column:Number.isFinite(u??Number.NaN)?u:void 0}}const a=ge(r);return a?{path:a}:null},Re=/(?:[A-Za-z]:[\\/])?[\w.\-/@+]*[\w\-/@+]\.[A-Za-z0-9]{1,8}(?::\d+(?:-\d+)?(?::\d+)?)?/g,lr=4,cr=1e3,dr=200,$=new Map;let be=0;const tt=[],ur=()=>pt()?dr:cr,mr=(t,e)=>`${t}\0${e}`,pr=(t,e)=>{const n=Lt(t);if(!n)return Promise.resolve(!1);const r=mr(e,n),i=$.get(r);if(i)return $.delete(r),$.set(r,i),i;const o=new Promise(a=>{const l=()=>{be+=1,an(`/api/fs/stat?path=${encodeURIComponent(n)}&optional=true`,{method:"GET",cache:"no-store",headers:e?{"x-opencode-directory":e}:void 0}).then(async c=>{if(!c.ok){a(!1);return}const u=await c.json().catch(()=>null);a(u?.exists!==!1)}).catch(()=>a(!1)).finally(()=>{be=Math.max(0,be-1),tt.shift()?.()})};if(be<lr){l();return}tt.push(l)}),s=ur();for(;$.size>=s;){const a=$.keys().next().value;if(typeof a!="string")break;$.delete(a)}return $.set(r,o),o},fr={maxSessions:8,maxEntriesPerSession:4};class hr{maxSessions;maxEntriesPerSession;sessions=new Map;constructor(e=fr){this.maxSessions=Math.max(1,e.maxSessions),this.maxEntriesPerSession=Math.max(1,e.maxEntriesPerSession)}store(e){const n=e.scope,r=e.id;let i=this.sessions.get(n);for(i===void 0?(i=new Map,this.sessions.set(n,i)):this.refreshSession(n,i),i.delete(r),i.set(r,e);i.size>this.maxEntriesPerSession;)this.removeOldestEntry(i);for(;this.sessions.size>this.maxSessions;)this.removeOldestSession()}take(e){const n=e.scope,r=this.sessions.get(n);if(!r)return null;const i=e.id;this.refreshSession(n,r);const o=r.get(i);return o===void 0||o.locale!==e.locale||o.directory!==e.directory?null:(r.delete(i),r.size===0&&this.sessions.delete(n),o.fragment)}clear(){this.sessions.clear()}stats(){let e=0;for(const n of this.sessions.values())e+=n.size;return{sessions:this.sessions.size,entries:e}}refreshSession(e,n){this.sessions.delete(e),this.sessions.set(e,n)}removeOldestEntry(e){const n=e.keys().next().value;n!==void 0&&e.delete(n)}removeOldestSession(){const e=this.sessions.keys().next().value;e!==void 0&&this.sessions.delete(e)}}const nt=new hr,Nt=()=>{const t=se.c(4),e=Jt();let n;t[0]===Symbol.for("react.memo_cache_sentinel")?(n=We(!1),t[0]=n):n=t[0];const r=n;let i;t[1]===Symbol.for("react.memo_cache_sentinel")?(i=We(!0),t[1]=i):i=t[1];const o=i;let s;return t[2]!==e?.currentTheme?(s=e?.currentTheme??(typeof window<"u"&&window.matchMedia("(prefers-color-scheme: dark)").matches?o:r),t[2]=e?.currentTheme,t[3]=s):s=t[3],s},Rt=t=>{const e=se.c(4),{containerRef:n,enabled:r}=t;let i,o;e[0]!==n||e[1]!==r?(i=()=>{const s=n.current;if(s)return bn(s,{allowExternalHttp:r!==!1,openAppLink:Fr,openExternalHttp:Dr})},o=[n,r],e[0]=n,e[1]=r,e[2]=i,e[3]=o):(i=e[2],o=e[3]),E.useEffect(i,o)},Q={download:!0,copy:!0,showPanZoomControls:!0},Tt=!0,gr=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},rt='[data-openchamber-file-link="true"]',_t="data-openchamber-block-path-token",xt=`[${_t}]`,Y="data-openchamber-block-paths-scanned",br=2e5,wr=80,yr=40,ot=160,Ar=()=>pt()?yr:wr,vr=new Set(["dockerfile","makefile","readme","license",".env",".gitignore",".npmrc"]),Pt=t=>Lt(t),kr=t=>sr(t),Er=(t,e)=>nn(t,e),Cr=t=>{const e=t.split("/").filter(Boolean).pop()??"";return!e||e.endsWith(".")?!1:/\.[A-Za-z0-9_-]{1,16}$/.test(e)},It=t=>{if(!t||t.startsWith("--")||t.includes("://")||/[<>]/.test(t)||/\s{2,}/.test(t))return!1;const e=Pt(t),n=e.split("/").filter(Boolean).pop()??e;if(!n||n==="."||n==="..")return!1;const r=n.toLowerCase();return vr.has(r)||r.startsWith(".")&&r.length>1?!0:Cr(e)},Ft=t=>{const e=Mt(t);return e?It(e.path):!1},Sr=t=>{const e=t.querySelectorAll(xt);for(const r of Array.from(e))r.replaceWith(t.ownerDocument.createTextNode(r.textContent??""));const n=t.querySelectorAll(`code[${Y}]`);for(const r of Array.from(n))r.removeAttribute(Y),r.normalize()},Te=t=>{if(t.tagName.toLowerCase()==="a"){const e=t.getAttribute("href")?.trim(),n=e?ar(e):null;if(n)return n;if(e&&Ft(e))return e}return(t.textContent||"").trim()},Lr=t=>{const e=t.querySelectorAll("pre code");if(e.length===0)return;const n=t.ownerDocument;if(n)for(const r of Array.from(e)){if(r.getAttribute(Y)==="true")continue;if((r.textContent??"").length>br){r.setAttribute(Y,"true");continue}const i=n.createTreeWalker(r,NodeFilter.SHOW_TEXT),o=[];let s=i.nextNode();for(;s;){const u=s;u.parentElement?.closest("[data-md-code-line-number]")||o.push(u),s=i.nextNode()}const a=St(r);if(!a.includes(".")){r.setAttribute(Y,"true");continue}Re.lastIndex=0;const l=[];let c=Re.exec(a);for(;c;){const u=c[0];u&&Ft(u)&&l.push({start:c.index,end:c.index+u.length,raw:u}),c=Re.exec(a)}for(const{start:u,end:f,raw:m}of l.reverse()){const g=Qe(o,u,"right"),y=Qe(o,f,"left");if(!g||!y)continue;const v=n.createRange();v.setStart(g.node,g.offset),v.setEnd(y.node,y.offset);const C=n.createElement("span");C.setAttribute(_t,"true"),C.textContent=m,v.deleteContents(),v.insertNode(C)}r.setAttribute(Y,"true")}},_e=(t,e)=>{const n=Mt(t);if(!n||!It(n.path))return null;const r=kr(n.path)?Pt(n.path):Er(e,n.path);return r?{...n,resolvedPath:r}:null},Mr=(t,e)=>t||tn(t,e),Dt=({containerRef:t,effectiveDirectory:e,editor:n,preferRuntimeEditor:r,enabled:i})=>{const o=E.useRef(null);E.useEffect(()=>{const s=t.current;if(!s||i&&!e)return;let a=!1;const l=Ar(),c=i&&!mn(),u=d=>{d.removeAttribute("data-openchamber-file-link"),d.removeAttribute("data-openchamber-file-ref"),d.removeAttribute("data-openchamber-file-path"),d.getAttribute("title")==="Open file"&&d.removeAttribute("title"),d.tagName.toLowerCase()!=="a"&&(d.removeAttribute("role"),d.removeAttribute("tabindex"))},f=()=>{const d=s.querySelectorAll(rt);for(const b of Array.from(d))u(b);Sr(s)};if(!c){f();return}const m=(d=0)=>{if(o.current!==null&&typeof window<"u"&&window.clearTimeout(o.current),typeof window>"u"){g();return}o.current=window.setTimeout(()=>{o.current=null,window.requestAnimationFrame(()=>{a||g()})},d)},g=()=>{h+=1;try{y()}finally{queueMicrotask(()=>{h-=1})}},y=()=>{c&&Lr(s);const d=s.querySelectorAll(`[data-markdown="inline-code"], a, ${xt}`);let b=0;for(const w of Array.from(d)){const A=Te(w),L=_e(A,e);if(u(w),!L||b>=l)continue;b+=1,(dn()&&un()&&!qe(L.resolvedPath,e)?Promise.resolve(!0):pr(L.resolvedPath,e)).then(M=>{if(a||!M||!s.contains(w))return;const N=Te(w),S=_e(N,e);!S||S.resolvedPath!==L.resolvedPath||(w.setAttribute("data-openchamber-file-link","true"),w.setAttribute("data-openchamber-file-ref",N),w.setAttribute("data-openchamber-file-path",S.resolvedPath),w.setAttribute("title","Open file"),w.tagName.toLowerCase()!=="a"&&(w.setAttribute("role","button"),w.setAttribute("tabindex","0")))})}},v=async d=>{const b=d.getAttribute("data-openchamber-file-ref")||Te(d),w=_e(b,e);if(!w)return;const A=Mr(e,w.resolvedPath);if(r&&n){n.openFile(w.resolvedPath,Number.isFinite(w.line??Number.NaN)?Math.max(1,Math.trunc(w.line)):void 0,Number.isFinite(w.column??Number.NaN)?Math.max(1,Math.trunc(w.column)):void 0);return}qe(w.resolvedPath,e)||await en(w.resolvedPath,e);const L=G.getState();Number.isFinite(w.line??Number.NaN)?L.openContextFileAtLine(A,w.resolvedPath,Math.max(1,Math.trunc(w.line)),Number.isFinite(w.column??Number.NaN)?Math.max(1,Math.trunc(w.column)):1):L.openContextFile(A,w.resolvedPath)},C=d=>{const b=d.target;if(!(b instanceof Element))return;const w=b.closest(rt);w instanceof HTMLElement&&(d.preventDefault(),d.stopPropagation(),v(w))},p=d=>{if(d.key!=="Enter"&&d.key!==" ")return;const b=d.target;!(b instanceof HTMLElement)||b.getAttribute("data-openchamber-file-link")!=="true"||(d.preventDefault(),d.stopPropagation(),v(b))};m(ot);let h=0;const k=new MutationObserver(()=>{h>0||m(ot)});return k.observe(s,{childList:!0,subtree:!0}),s.addEventListener("click",C),s.addEventListener("keydown",p),()=>{a=!0,o.current!==null&&typeof window<"u"&&window.clearTimeout(o.current),o.current=null,k.disconnect(),s.removeEventListener("click",C),s.removeEventListener("keydown",p)}},[t,n,e,r,i])},Ot=t=>{const e=se.c(7),{containerRef:n,onShowPopup:r,enableFullscreen:i,enablePanZoom:o,allowMermaidWheelEvents:s}=t;let a,l;e[0]!==s||e[1]!==n||e[2]!==i||e[3]!==o||e[4]!==r?(a=()=>{const c=n.current;if(!c)return;const u=m=>{if(!i||!r)return;const g=m.target;if(!(g instanceof Element)||g.closest('button, a, [role="button"]'))return;const y=g.closest(re);if(!y)return;if(y instanceof HTMLElement&&y.hasAttribute("data-mermaid-suppress-click")){y.removeAttribute("data-mermaid-suppress-click");return}const C=Array.from(c.querySelectorAll(re)).indexOf(y);if(C<0)return;const p=y instanceof HTMLElement?y.getAttribute("data-md-source"):null;if(!p||p.trim().length===0)return;const h=`Diagram ${C+1}`;r({open:!0,title:h,content:"",metadata:{tool:"mermaid-preview",filename:h},mermaid:{url:`data:text/plain;charset=utf-8,${encodeURIComponent(p)}`,source:p,filename:h}})},f=m=>{if(s||(m.ctrlKey||m.metaKey)&&o)return;const g=m.target;!(g instanceof Element)||!g.closest(re)||m.stopPropagation()};return c.addEventListener("click",u),c.addEventListener("wheel",f,{capture:!0,passive:!0}),()=>{c.removeEventListener("click",u),c.removeEventListener("wheel",f,!0)}},l=[s,n,i,o,r],e[0]=s,e[1]=n,e[2]=i,e[3]=o,e[4]=r,e[5]=a,e[6]=l):(a=e[5],l=e[6]),E.useEffect(a,l)},z=new Map,Nr=100,H="data-md-decoration-id",Rr=(t,e,n)=>{const r=t.children;if(r.length!==e.length)return!1;for(let i=0;i<e.length;i+=1){const o=r[i];if(!o||o.getAttribute("data-md-id")!==e[i]?.id||o.getAttribute(H)!==n)return!1}return!0},it=new WeakMap;let st=0;const Tr=2e5,xe=t=>{const e=it.get(t);if(e)return e;const n=`decoration-${st}`;return st+=1,it.set(t,n),n},_r=(t,e)=>{const n=z.get(t);if(n)return z.delete(t),z.set(t,n),n;const r=e();if(z.set(t,r),z.size>Nr){const i=z.keys().next().value;i&&z.delete(i)}return r},xr=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"}),Wt=(t,e,n,r=Q)=>{const{t:i}=ut(),o=E.useMemo(()=>({copy:i("markdownRenderer.code.actions.copyTitle"),copied:i("markdownRenderer.code.actions.copiedTitle"),enableCodeWrap:i("markdownRenderer.code.actions.enableWrapTitle"),disableCodeWrap:i("markdownRenderer.code.actions.disableWrapTitle"),copyTable:i("markdownRenderer.table.actions.copyTitle"),downloadTable:i("markdownRenderer.table.actions.downloadTitle"),copyDiagram:i("markdownRenderer.mermaid.actions.copySourceTitle"),downloadDiagram:i("markdownRenderer.mermaid.actions.downloadSvgTitle"),zoomInDiagram:i("markdownRenderer.mermaid.actions.zoomInTitle"),zoomOutDiagram:i("markdownRenderer.mermaid.actions.zoomOutTitle"),resetDiagramView:i("markdownRenderer.mermaid.actions.resetViewTitle"),previewLabel:i("terminalView.preview.open"),previewTitle:i("terminalView.preview.openTitle")}),[i]),s=G(c=>c.codeBlockLineWrap),a=G(c=>c.setCodeBlockLineWrap),l=E.useCallback(()=>{a(!G.getState().codeBlockLineWrap)},[a]);return E.useMemo(()=>{const c=xr(t),u=G.getState().mermaidRenderingMode,f=t.metadata?.id??"theme";return{labels:o,mermaidControls:r,codeBlockLineWrap:s,deferCodeLineNumberSync:e,onToggleCodeBlockLineWrap:l,renderMermaid:g=>_r(`${f}:${u}:${g}`,()=>{try{return u==="ascii"?{ascii:Ht(g)}:{svg:Vt(g,c)}}catch{return{}}}),onPreviewLoopback:n}},[t,o,r,s,e,l,n])},qt=({containerRef:t,text:e,streaming:n,imageMode:r="inline",syntaxVars:i,ctx:o,domCacheKey:s,tableLayoutSettled:a})=>{E.useEffect(()=>{yn()},[]);const l=E.useRef(null),c=E.useRef(0),u=E.useRef(null),f=E.useContext(Qt),m=E.useRef(null),g=E.useCallback(()=>{m.current?.(),m.current=null},[]);E.useEffect(()=>g,[g]);const y=E.useRef(null),v=E.useCallback(()=>{const p=t.current;if(p){if(!l.current){if(!I(p))return;l.current=Hn(p);return}l.current.refresh()}},[t]),C=E.useCallback(()=>{if(!a)return;const p=u.current;p!==null&&window.cancelAnimationFrame(p);const h=c.current,k=window.requestAnimationFrame(()=>{if(u.current!==k||(u.current=null,c.current!==h))return;const d=t.current,b=d?.querySelector("[data-markdown-content]")??d;b&&Qn(b)});u.current=k},[t,a]);E.useEffect(()=>()=>{const p=u.current;p!==null&&(window.cancelAnimationFrame(p),u.current=null)},[]),E.useLayoutEffect(()=>{c.current+=1,y.current=null},[o,r,n,e]),E.useLayoutEffect(()=>{if(!s)return;const p=t.current,h=p?.querySelector("[data-markdown-content]")??p;if(!h||h.childNodes.length>0)return;const k=nt.take(s);if(k){h.appendChild(k);const d=xe(o);for(const b of Array.from(h.children))b.setAttribute(H,d);for(const[b,w]of Object.entries(i))h.style.setProperty(b,w);Ke(h,o.codeBlockLineWrap,o.labels),y.current={key:s,copiedLabel:o.labels.copied},ne("ui.markdown_renderer.dom_cache.hit")}},[t,o,s,i,e.length]),E.useLayoutEffect(()=>{const p=t.current,h=p?.querySelector("[data-markdown-content]")??p;if(h)return()=>{const k=y.current;if(!k||h.childNodes.length===0||I(h)||Array.from(h.children).some(L=>!L.hasAttribute("data-md-id"))||h.querySelector("[data-md-copy-pending]"))return;const d=window.getSelection();if(d?.rangeCount&&!d.isCollapsed&&d.getRangeAt(0).intersectsNode(h))return;const b=h.querySelector("[data-md-menu]:not(.hidden)"),w=Array.from(h.querySelectorAll("[data-md-action]")).some(L=>L.getAttribute("title")===k.copiedLabel);if(b||w)return;const A=document.createDocumentFragment();A.append(...Array.from(h.childNodes)),nt.store({...k.key,fragment:A}),ne("ui.markdown_renderer.dom_cache.capture")}},[t]),E.useLayoutEffect(()=>{const p=t.current,h=p?.querySelector("[data-markdown-content]")??p;if(!h)return;const k=xe(o);if(e&&h.childNodes.length===0){const d=n?null:Be(e,r);if(d){let b=!1;for(const w of d){const A=document.createElement("div");A.setAttribute("data-md-block",""),A.style.display="contents",A.innerHTML=w.html,pe(A,o),A.setAttribute("data-md-id",w.id),A.setAttribute(H,k),b||=I(A),h.appendChild(A)}b&&v()}else{!n&&!m.current&&(m.current=f?.hold()??null);const b=document.createElement("div");b.setAttribute("data-md-block",""),b.style.display="contents",b.innerHTML=pn(e,r),pe(b,o),b.setAttribute(H,k),h.appendChild(b),I(b)&&v()}}else!l.current&&I(h)&&v()},[t,e,n,r,o,v,f]),E.useEffect(()=>()=>{l.current?.cleanup(),l.current=null},[]),E.useEffect(()=>{const p=t.current;if(!p)return;const h=p.querySelector("[data-markdown-content]")??p;let k=!0;const d=c.current,b=xe(o);if(!n){const w=Be(e,r);if(w&&Rr(h,w,b)){y.current=s?{key:s,copiedLabel:o.labels.copied}:null,ne("ui.markdown_renderer.settled_paint.reused"),C(),g();return}}return fn(e,n,r).then(w=>{if(!k||c.current!==d)return;const A=Array.from(h.children);let L=0;w.forEach((M,N)=>{let S=A[N],F=!1;if(S||(S=document.createElement("div"),S.setAttribute("data-md-block",""),S.style.display="contents",h.appendChild(S),F=!0),S.getAttribute("data-md-id")===M.id){if(S.getAttribute(H)!==b){const x=I(S);x&&(l.current?.cleanup(),l.current=null);const R=document.createElement("div");R.setAttribute("data-md-block",""),R.style.display="contents",R.innerHTML=M.html,pe(R,o),R.setAttribute("data-md-id",M.id),R.setAttribute(H,b),S.replaceWith(R),(x||I(R))&&v()}!l.current&&I(S)&&v();return}const _=document.createElement("div");if(_.innerHTML=M.html,pe(_,o),F&&n&&N>0){const x=Math.min(L,4)*55;L+=1;for(const R of Array.from(_.children))R.classList.add("oc-md-block-enter"),x>0&&R instanceof HTMLElement&&R.style.setProperty("--oc-md-enter-delay",`${x}ms`)}const P=I(S),D=I(_);zt(S,_,{childrenOnly:!0,onBeforeElUpdated:(x,R)=>!x.isEqualNode(R)}),S.setAttribute("data-md-id",M.id),S.setAttribute(H,b),(P||D||I(S))&&v()});const O=I(h);let W=!1;for(let M=A.length-1;M>=w.length;M-=1){const N=A[M];N&&I(N)&&(W=!0),N?.remove()}(W||A.length>w.length&&O)&&v(),y.current=s?{key:s,copiedLabel:o.labels.copied}:null,C(),g()}),()=>{k=!1}},[t,o,s,r,v,g,C,n,e]),E.useEffect(()=>{const p=t.current;if(p)return or(p,o)},[t,o]),E.useEffect(()=>{const p=t.current,h=p?.querySelector("[data-markdown-content]")??p;if(h)for(const[k,d]of Object.entries(i))h.style.setProperty(k,d)},[t,i]),E.useEffect(()=>{const p=t.current,h=p?.querySelector("[data-markdown-content]")??p;h&&(o.deferCodeLineNumberSync||Ke(h,o.codeBlockLineWrap,o.labels))},[t,o.codeBlockLineWrap,o.deferCodeLineNumberSync,o.labels])},Bt=t=>t==="tool"?"markdown-content markdown-tool":t==="reasoning"?"markdown-content markdown-reasoning":"markdown-content leading-relaxed",Pr=t=>{const e=se.c(40),{content:n,part:r,messageId:i,isAnimated:o,skipFadeIn:s,className:a,isStreaming:l,disableStreamAnimation:c,variant:u,onShowPopup:f,enableFileReferences:m}=t,g=o===void 0?!0:o,y=s===void 0?!1:s,v=l===void 0?!1:l,C=c===void 0?!1:c,p=u===void 0?"assistant":u,h=m===void 0?!0:m;ne("ui.markdown_renderer.render"),v&&ne("ui.markdown_renderer.render.streaming"),ln("ui.markdown_renderer.content_len",n.length);const k=Nt(),{editor:d,runtime:b}=lt(),w=E.useRef(null),A=ct()??"",L=G(Or);let O;e[0]!==A||e[1]!==L?(O=q=>{A&&L(A,q)},e[0]=A,e[1]=L,e[2]=O):O=e[2];const W=O,M=v&&!C;let N;e[3]!==f?(N={containerRef:w,onShowPopup:f,enableFullscreen:Tt,enablePanZoom:Q.showPanZoomControls},e[3]=f,e[4]=N):N=e[4],Ot(N);const S=h&&!v;let F;e[5]!==d||e[6]!==A||e[7]!==b.isVSCode||e[8]!==S?(F={containerRef:w,effectiveDirectory:A,editor:d,preferRuntimeEditor:b.isVSCode,enabled:S},e[5]=d,e[6]=A,e[7]=b.isVSCode,e[8]=S,e[9]=F):F=e[9],Dt(F);let _;e[10]===Symbol.for("react.memo_cache_sentinel")?(_={containerRef:w},e[10]=_):_=e[10],Rt(_);let P;e[11]!==k?(P=dt(k),e[11]=k,e[12]=P):P=e[12];const D=P,x=Wt(k,M,A?W:void 0,Q),{locale:R}=ut(),ae=p==="assistant"?"label":"inline",ve=r&&(r.type==="text"||r.type==="reasoning")&&r.time?.end!==void 0?r:null;let le;e[13]===Symbol.for("react.memo_cache_sentinel")?(le=cn(),e[13]=le):le=e[13];const $t=le,Fe=ve?.sessionID,De=ve?.messageID,Oe=ve?.id;let ke;e:{if(v||!Fe||!De||!Oe||n.length===0||n.length>Tr){ke=null;break e}const q=`${$t}\0${Fe}`,Le=`${De}\0${Oe}\0${ae}\0${n.length}`;let me;e[14]!==A||e[15]!==R||e[16]!==q||e[17]!==Le?(me={scope:q,id:Le,locale:R,directory:A},e[14]=A,e[15]=R,e[16]=q,e[17]=Le,e[18]=me):me=e[18],ke=me}const Ee=ke,Ce=`markdown-${r?.id?`part-${r.id}`:`message-${i}`}`,Se=!v;let ce;e[19]!==n||e[20]!==x||e[21]!==Ee||e[22]!==ae||e[23]!==M||e[24]!==D||e[25]!==Se?(ce={containerRef:w,text:n,streaming:M,imageMode:ae,syntaxVars:D,ctx:x,domCacheKey:Ee,tableLayoutSettled:Se},e[19]=n,e[20]=x,e[21]=Ee,e[22]=ae,e[23]=M,e[24]=D,e[25]=Se,e[26]=ce):ce=e[26],qt(ce);let j;e[27]!==a?(j=mt("break-words w-full min-w-0",a),e[27]=a,e[28]=j):j=e[28];let U;e[29]!==p?(U=Bt(p),e[29]=p,e[30]=U):U=e[30];let Z;e[31]!==U?(Z=te.jsx("div",{className:U,"data-markdown-content":!0}),e[31]=U,e[32]=Z):Z=e[32];let de;e[33]!==j||e[34]!==Z?(de=te.jsx("div",{className:j,ref:w,children:Z}),e[33]=j,e[34]=Z,e[35]=de):de=e[35];const ue=de;if(g){let q;return e[36]!==Ce||e[37]!==ue||e[38]!==y?(q=te.jsx(rn,{skipAnimation:y,children:ue},Ce),e[36]=Ce,e[37]=ue,e[38]=y,e[39]=q):q=e[39],q}return ue},$i=E.memo(Pr,(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),Ir=t=>{const e=se.c(29),{content:n,className:r,variant:i,disableLinkSafety:o,stripFrontmatter:s,onShowPopup:a,mermaidControls:l,allowMermaidWheelEvents:c,enableFileReferences:u}=t,f=i===void 0?"assistant":i,m=s===void 0?!1:s,g=l===void 0?Q:l,y=c===void 0?!1:c,v=u===void 0?!0:u,{editor:C,runtime:p}=lt(),h=Nt(),k=E.useRef(null),d=ct()??"";let b;e[0]!==n||e[1]!==m?(b=m?gr(n):n,e[0]=n,e[1]=m,e[2]=b):b=e[2];const w=b;let A;e[3]!==y||e[4]!==g.showPanZoomControls||e[5]!==a?(A={containerRef:k,onShowPopup:a,enableFullscreen:Tt,enablePanZoom:g.showPanZoomControls,allowMermaidWheelEvents:y},e[3]=y,e[4]=g.showPanZoomControls,e[5]=a,e[6]=A):A=e[6],Ot(A);let L;e[7]!==C||e[8]!==d||e[9]!==v||e[10]!==p.isVSCode?(L={containerRef:k,effectiveDirectory:d,editor:C,preferRuntimeEditor:p.isVSCode,enabled:v},e[7]=C,e[8]=d,e[9]=v,e[10]=p.isVSCode,e[11]=L):L=e[11],Dt(L);const O=!o;let W;e[12]!==O?(W={containerRef:k,enabled:O},e[12]=O,e[13]=W):W=e[13],Rt(W);let M;e[14]!==h?(M=dt(h),e[14]=h,e[15]=M):M=e[15];const N=M,S=Wt(h,!1,void 0,g);let F;e[16]!==S||e[17]!==w||e[18]!==N?(F={containerRef:k,text:w,streaming:!1,syntaxVars:N,ctx:S,tableLayoutSettled:!0},e[16]=S,e[17]=w,e[18]=N,e[19]=F):F=e[19],qt(F);let _;e[20]!==r?(_=mt("break-words w-full min-w-0",r),e[20]=r,e[21]=_):_=e[21];let P;e[22]!==f?(P=Bt(f),e[22]=f,e[23]=P):P=e[23];let D;e[24]!==P?(D=te.jsx("div",{className:P,"data-markdown-content":!0}),e[24]=P,e[25]=D):D=e[25];let x;return e[26]!==_||e[27]!==D?(x=te.jsx("div",{className:_,ref:k,children:D}),e[26]=_,e[27]=D,e[28]=x):x=e[28],x},zi=E.memo(Ir,(t,e)=>{const n=t.mermaidControls??Q,r=e.mermaidControls??Q;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&&n.download===r.download&&n.copy===r.copy&&n.showPanZoomControls===r.showPanZoomControls&&t.allowMermaidWheelEvents===e.allowMermaidWheelEvents&&t.enableFileReferences===e.enableFileReferences});function Fr(t){on(t)}function Dr(t){sn(t)}function Or(t){return t.openContextPreview}export{$i as MarkdownRenderer,zi as SimpleMarkdownRenderer};