@vantran-se/openchamber-web 2.0.3 → 2.0.5

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 (265) hide show
  1. package/README.md +20 -28
  2. package/bin/cli.js +3 -1
  3. package/bin/cli.test.js +13 -4
  4. package/bin/lib/DOCUMENTATION.md +4 -1
  5. package/bin/lib/commands-serve.js +9 -0
  6. package/dist/assets/{CodeMirrorCommentWidgets-CWhdh0wf.js → CodeMirrorCommentWidgets-DCAQTLMM.js} +1 -1
  7. package/dist/assets/DiffView-uzNpHBlV.js +4 -0
  8. package/dist/assets/FilesView-Bkq0sjNx.js +17 -0
  9. package/dist/assets/{GitView-DKIjpnu4.js → GitView-BmibZC7n.js} +4 -4
  10. package/dist/assets/{GuestAttachDialog-BIa9jCfL.js → GuestAttachDialog-D7TJG1rt.js} +1 -1
  11. package/dist/assets/GuestSurfacePane-PAcYaFzP.js +1 -0
  12. package/dist/assets/{JsonTreeView-CtI1Mqwo.js → JsonTreeView-BNT2yUVu.js} +1 -1
  13. package/dist/assets/{LinearIssuesView-BD2zLu-r.js → LinearIssuesView-D3Azksju.js} +1 -1
  14. package/dist/assets/MarkdownImageGallery-BGY6tuiK.js +1 -0
  15. package/dist/assets/MarkdownRendererImpl-DJmhQ37f.js +12 -0
  16. package/dist/assets/{OnboardingScreen-B8TxloXZ.js → OnboardingScreen-D_41H2qC.js} +1 -1
  17. package/dist/assets/{PatchDiff--Civs1xY.js → PatchDiff-C0RSqa9W.js} +1 -1
  18. package/dist/assets/{PierreDiffViewer-BlDmw3-A.js → PierreDiffViewer-BBE7tTY2.js} +3 -3
  19. package/dist/assets/{PlanView-DyH2SyCP.js → PlanView-Bqc-xuDe.js} +4 -4
  20. package/dist/assets/PluginPane-DQ0k41Q-.js +3 -0
  21. package/dist/assets/SettingsView-BAiJU5hJ.js +30 -0
  22. package/dist/assets/{SettingsWindow-y9WpZqK6.js → SettingsWindow-DuC4ecLw.js} +1 -1
  23. package/dist/assets/{SubmoduleDiffSummary-DeFmhPFZ.js → SubmoduleDiffSummary-0HgmcMXz.js} +1 -1
  24. package/dist/assets/{ToolOutputDialog-8DmF7_PZ.js → ToolOutputDialog-DdHkQJEE.js} +6 -6
  25. package/dist/assets/{ToolPartDiffPreview-Ca15DKE1.js → ToolPartDiffPreview-DWdN0r5K.js} +2 -2
  26. package/dist/assets/{VirtualizedFileDiff-BfEBad09.js → VirtualizedFileDiff-ClDezf2d.js} +1 -1
  27. package/dist/assets/{WalkthroughView-Cj3K8Xz6.js → WalkthroughView-BJicp0RC.js} +2 -2
  28. package/dist/assets/{appThemeRegistry-DAdawJZn.js → appThemeRegistry-CiuyzfSW.js} +1 -1
  29. package/dist/assets/changesTree-CePHbFcj.js +1 -0
  30. package/dist/assets/commitAndPush-DTKb6IwT.js +1 -0
  31. package/dist/assets/{computeVirtualFileMetrics-RF-KjfUH.js → computeVirtualFileMetrics-kM_zJNMt.js} +2 -2
  32. package/dist/assets/de-BMnfXm-G.js +10 -0
  33. package/dist/assets/es-DKEvCCL6.js +16 -0
  34. package/dist/assets/fr-D9fgE2xE.js +14 -0
  35. package/dist/assets/index-DUke1nme.css +1 -0
  36. package/dist/assets/{index-CL7ZQ94-.js → index-DWB8bR_g.js} +1 -1
  37. package/dist/assets/index-Di6zUe5h.js +41 -0
  38. package/dist/assets/{isDiffPlainText-D2yJ9fO6.js → isDiffPlainText-DOoIsGqs.js} +1 -1
  39. package/dist/assets/{isFilePlainText-BwMEq1Ey.js → isFilePlainText-bt5VHvcd.js} +1 -1
  40. package/dist/assets/ja-BEXad-KW.js +16 -0
  41. package/dist/assets/ko-DGrQ0lEe.js +16 -0
  42. package/dist/assets/{main-quLSA7jc.js → main-BpLQbZC2.js} +2 -2
  43. package/dist/assets/main-CI9DtHJv.js +896 -0
  44. package/dist/assets/{markdown-shiki.worker-CahLvHIq.js → markdown-shiki.worker-Bg8SoAJJ.js} +8 -5
  45. package/dist/assets/markdownCore-DK2KK5RW.js +7 -0
  46. package/dist/assets/{miniChat-D-lJJibr.js → miniChat-CIWaR8wG.js} +2 -2
  47. package/dist/assets/{mobile-VTtphbW6.js → mobile-CnWKEYIP.js} +2 -2
  48. package/dist/assets/patchFileDiff-Cqn0C0az.js +13 -0
  49. package/dist/assets/pl-BlhkmR5b.js +16 -0
  50. package/dist/assets/pt-BR-Bs96Ew9I.js +16 -0
  51. package/dist/assets/{renderElectronMiniChatApp-DF7ch5eM.js → renderElectronMiniChatApp-D9t0-9nV.js} +2 -2
  52. package/dist/assets/renderMobileApp-CW7fVs_s.js +25 -0
  53. package/dist/assets/runtimeEndpointReset-D0PcCb3K.js +27 -0
  54. package/dist/assets/scheduledTasksApi-Dahv3ws0.js +1 -0
  55. package/dist/assets/{shikiHighlight-_HeCCHx1.js → shikiHighlight-l-MbaNS4.js} +1 -1
  56. package/dist/assets/{textMateThemeFromAppTheme-C95XdFGj.js → textMateThemeFromAppTheme-C-kGcOpD.js} +1 -1
  57. package/dist/assets/tr-CehUK1M9.js +7 -0
  58. package/dist/assets/uk-Bno5WGNz.js +16 -0
  59. package/dist/assets/{useAppFontEffects-ZM9ij19-.js → useAppFontEffects-DDjuwVqi.js} +160 -156
  60. package/dist/assets/{useInlineCommentController-CkfxMJPy.js → useInlineCommentController-Clg8EO3A.js} +2 -2
  61. package/dist/assets/{useRootScrollLock-BtiAC1fj.js → useRootScrollLock-nDcRrgJ1.js} +2 -2
  62. package/dist/assets/{vendor-codemirror-language-data-U-lXzXNK.js → vendor-codemirror-language-data-oKF0MAwd.js} +2 -2
  63. package/dist/assets/vendor-opencode-client-DSZl7jSi.js +12 -0
  64. package/dist/assets/vendor-zod-BSoePkpP.js +39 -0
  65. package/dist/assets/{web-components-C583Pmfm.js → web-components-Bc1WPd4i.js} +1 -1
  66. package/dist/assets/zh-CN-DnAweIWo.js +16 -0
  67. package/dist/assets/zh-TW-BbBBK25p.js +16 -0
  68. package/dist/index.html +5 -5
  69. package/dist/mini-chat.html +5 -5
  70. package/dist/mobile.html +5 -5
  71. package/package.json +3 -3
  72. package/server/index.d.ts +2 -0
  73. package/server/index.js +196 -52
  74. package/server/lib/agent-tool/DOCUMENTATION.md +5 -0
  75. package/server/lib/agent-tool/runtime.js +89 -51
  76. package/server/lib/agent-tool/runtime.test.js +17 -0
  77. package/server/lib/browser-control/DOCUMENTATION.md +14 -2
  78. package/server/lib/event-stream/DOCUMENTATION.md +2 -2
  79. package/server/lib/event-stream/global-hub.js +45 -7
  80. package/server/lib/event-stream/global-hub.test.js +128 -2
  81. package/server/lib/event-stream/global-ws-bridge.js +3 -1
  82. package/server/lib/event-stream/rebind.test.js +1 -0
  83. package/server/lib/event-stream/runtime.js +1 -2
  84. package/server/lib/event-stream/upstream-reader.js +3 -2
  85. package/server/lib/git/DOCUMENTATION.md +1 -1
  86. package/server/lib/git/service.js +22 -0
  87. package/server/lib/git/service.test.js +8 -0
  88. package/server/lib/guests/DOCUMENTATION.md +4 -3
  89. package/server/lib/guests/catalog.js +19 -1
  90. package/server/lib/guests/catalog.test.js +22 -0
  91. package/server/lib/guests/html-styles.js +5 -3
  92. package/server/lib/guests/html-styles.test.js +3 -1
  93. package/server/lib/guests/routes.js +11 -3
  94. package/server/lib/guests/service.js +5 -0
  95. package/server/lib/guests/surface.js +55 -9
  96. package/server/lib/guests/surface.test.js +56 -6
  97. package/server/lib/notifications/DOCUMENTATION.md +10 -0
  98. package/server/lib/notifications/emit-route.js +118 -0
  99. package/server/lib/notifications/emit-route.test.js +112 -0
  100. package/server/lib/openchamber-control/actions.js +16 -2
  101. package/server/lib/openchamber-control/service.js +23 -0
  102. package/server/lib/openchamber-control/service.test.js +31 -0
  103. package/server/lib/openchamber-sessions/fork-inheritance.js +103 -0
  104. package/server/lib/openchamber-sessions/fork-inheritance.test.js +69 -0
  105. package/server/lib/openchamber-sessions/routes.js +11 -0
  106. package/server/lib/openchamber-sessions/routes.test.js +18 -0
  107. package/server/lib/opencode/DOCUMENTATION.md +23 -23
  108. package/server/lib/opencode/bootstrap-runtime.js +14 -1
  109. package/server/lib/opencode/compatibility.js +6 -3
  110. package/server/lib/opencode/compatibility.test.js +8 -0
  111. package/server/lib/opencode/config-entity-v2.test.js +27 -0
  112. package/server/lib/opencode/config-paths.test.js +12 -0
  113. package/server/lib/opencode/config-v2.d.ts +2 -0
  114. package/server/lib/opencode/config-v2.js +42 -0
  115. package/server/lib/opencode/config-v2.test.js +17 -0
  116. package/server/lib/opencode/core-routes.js +20 -4
  117. package/server/lib/opencode/core-routes.test.js +41 -0
  118. package/server/lib/opencode/env-runtime.js +1 -8
  119. package/server/lib/opencode/feature-routes-runtime.js +2 -1
  120. package/server/lib/opencode/lifecycle.js +156 -2
  121. package/server/lib/opencode/lifecycle.test.js +255 -1
  122. package/server/lib/opencode/managed-config-file.js +18 -6
  123. package/server/lib/opencode/managed-config-file.test.js +23 -7
  124. package/server/lib/opencode/mcp.js +7 -2
  125. package/server/lib/opencode/network-runtime.js +16 -7
  126. package/server/lib/opencode/network-runtime.test.js +29 -1
  127. package/server/lib/opencode/npm-registry-config.d.ts +1 -0
  128. package/server/lib/opencode/npm-registry-config.js +123 -0
  129. package/server/lib/opencode/npm-registry-config.test.js +167 -0
  130. package/server/lib/opencode/npm-registry.js +5 -6
  131. package/server/lib/opencode/npm-registry.test.js +30 -0
  132. package/server/lib/opencode/openchamber-routes.js +29 -11
  133. package/server/lib/opencode/openchamber-routes.test.js +18 -0
  134. package/server/lib/opencode/project-directory-runtime.js +8 -0
  135. package/server/lib/opencode/project-directory-runtime.test.js +13 -0
  136. package/server/lib/opencode/provider-source-route.test.js +59 -0
  137. package/server/lib/opencode/providers.js +3 -0
  138. package/server/lib/opencode/providers.test.js +62 -0
  139. package/server/lib/opencode/proxy.js +53 -16
  140. package/server/lib/opencode/routes-upgrade.test.js +1 -1
  141. package/server/lib/opencode/routes.js +36 -1
  142. package/server/lib/opencode/server-startup-runtime.js +25 -0
  143. package/server/lib/opencode/server-startup-runtime.test.js +67 -1
  144. package/server/lib/opencode/server-utils-runtime.js +5 -0
  145. package/server/lib/opencode/settings-helpers.js +10 -0
  146. package/server/lib/opencode/settings-helpers.test.js +2 -2
  147. package/server/lib/opencode/settings-registry.json +17 -0
  148. package/server/lib/opencode/settings-runtime.js +1 -0
  149. package/server/lib/opencode/shared-service-runtime.js +155 -0
  150. package/server/lib/opencode/shared-service-runtime.test.js +180 -0
  151. package/server/lib/opencode/shared.js +49 -4
  152. package/server/lib/opencode/shared.test.js +78 -1
  153. package/server/lib/opencode/shutdown-runtime.js +14 -5
  154. package/server/lib/opencode/shutdown-runtime.test.js +77 -2
  155. package/server/lib/opencode/skill-routes.js +28 -12
  156. package/server/lib/opencode/skill-routes.test.js +121 -1
  157. package/server/lib/opencode/startup-pipeline-runtime.js +5 -4
  158. package/server/lib/opencode/startup-pipeline-runtime.test.js +18 -7
  159. package/server/lib/opencode/upgrade-capability.js +0 -14
  160. package/server/lib/opencode/v1-migration-topup.js +21 -15
  161. package/server/lib/opencode/v1-migration-topup.test.js +14 -6
  162. package/server/lib/opencode/v2-install.d.ts +1 -0
  163. package/server/lib/opencode/v2-install.js +8 -7
  164. package/server/lib/opencode/v2-install.test.js +13 -4
  165. package/server/lib/opencode/watcher.js +3 -1
  166. package/server/lib/opencode/watcher.test.js +54 -0
  167. package/server/lib/opencode/websearch-config.js +13 -1
  168. package/server/lib/quota/providers/kimi.js +1 -1
  169. package/server/lib/realtime-proxy.js +5 -1
  170. package/server/lib/realtime-proxy.test.js +29 -0
  171. package/server/lib/relay/tunnel-host.js +4 -1
  172. package/server/lib/relay/tunnel-host.test.js +11 -0
  173. package/server/lib/session-assist/DOCUMENTATION.md +17 -5
  174. package/server/lib/session-assist/runtime.js +19 -2
  175. package/server/lib/session-assist/runtime.test.js +8 -0
  176. package/server/lib/session-goal/DOCUMENTATION.md +11 -0
  177. package/server/lib/small-model/DOCUMENTATION.md +11 -10
  178. package/server/lib/small-model/index.js +27 -32
  179. package/server/lib/small-model/index.test.js +28 -16
  180. package/server/lib/spaces/DOCUMENTATION.md +404 -32
  181. package/server/lib/spaces/code-in-bait.js +145 -6
  182. package/server/lib/spaces/code-in.js +10 -150
  183. package/server/lib/spaces/code-in.test.js +7 -83
  184. package/server/lib/spaces/code-out.js +1819 -0
  185. package/server/lib/spaces/code-out.test.js +3945 -0
  186. package/server/lib/spaces/code-transfer.js +173 -0
  187. package/server/lib/spaces/command-stream.test.js +181 -0
  188. package/server/lib/spaces/dispatcher.js +670 -0
  189. package/server/lib/spaces/dispatcher.test.js +582 -0
  190. package/server/lib/spaces/gatekeeper-channel.js +61 -7
  191. package/server/lib/spaces/gatekeeper-channel.test.js +43 -7
  192. package/server/lib/spaces/gatekeeper-program.cjs +68 -14
  193. package/server/lib/spaces/gatekeeper-program.test.js +118 -3
  194. package/server/lib/spaces/hardening.js +20 -4
  195. package/server/lib/spaces/hardening.test.js +18 -3
  196. package/server/lib/spaces/host-git.js +7 -4
  197. package/server/lib/spaces/host-git.test.js +6 -2
  198. package/server/lib/spaces/host.js +310 -0
  199. package/server/lib/spaces/host.test.js +273 -0
  200. package/server/lib/spaces/journey.js +552 -0
  201. package/server/lib/spaces/journey.test.js +589 -0
  202. package/server/lib/spaces/layout.js +42 -8
  203. package/server/lib/spaces/manager.js +4 -3
  204. package/server/lib/spaces/manager.test.js +6 -0
  205. package/server/lib/spaces/places/code-out.docker.live.test.js +412 -0
  206. package/server/lib/spaces/places/contract-suite.js +36 -0
  207. package/server/lib/spaces/places/dispatcher.docker.live.test.js +296 -0
  208. package/server/lib/spaces/places/docker-live-support.js +27 -4
  209. package/server/lib/spaces/places/docker.js +33 -5
  210. package/server/lib/spaces/places/docker.test.js +42 -3
  211. package/server/lib/spaces/places/escape-suite.js +118 -14
  212. package/server/lib/spaces/places/fake-docker.js +3 -1
  213. package/server/lib/spaces/places/grants.docker.live.test.js +197 -0
  214. package/server/lib/spaces/places/memory-place.js +24 -1
  215. package/server/lib/spaces/places/registry.js +1 -1
  216. package/server/lib/spaces/places/server.docker.live.test.js +69 -33
  217. package/server/lib/spaces/places/sessions.docker.live.test.js +222 -0
  218. package/server/lib/spaces/routes.js +216 -0
  219. package/server/lib/spaces/routes.test.js +213 -0
  220. package/server/lib/spaces/run-command.js +261 -8
  221. package/server/lib/spaces/run-command.test.js +193 -3
  222. package/server/lib/spaces/space-events.js +153 -0
  223. package/server/lib/spaces/space-events.test.js +160 -0
  224. package/server/lib/spaces/space-opencode.js +52 -0
  225. package/server/lib/spaces/space-opencode.test.js +41 -0
  226. package/server/lib/spaces/space-records.js +150 -0
  227. package/server/lib/spaces/space-records.test.js +113 -0
  228. package/server/lib/spaces/space-sessions.js +210 -0
  229. package/server/lib/spaces/space-sessions.test.js +161 -0
  230. package/server/lib/spaces/websocket.js +329 -0
  231. package/server/lib/spaces/websocket.test.js +345 -0
  232. package/server/lib/ui-auth/ui-auth.js +8 -2
  233. package/server/lib/ui-auth/ui-auth.test.js +29 -0
  234. package/server/opencode-proxy.test.js +271 -0
  235. package/server/proxy-headers.js +8 -2
  236. package/server/proxy-headers.test.js +20 -0
  237. package/dist/assets/DiffView-CX3wAX2S.js +0 -4
  238. package/dist/assets/FilesView-OL3CON3r.js +0 -17
  239. package/dist/assets/GuestSurfacePane-B_cqX5I5.js +0 -1
  240. package/dist/assets/MarkdownImageGallery-DFiTFZgj.js +0 -1
  241. package/dist/assets/MarkdownRendererImpl-DZm5sf1W.js +0 -12
  242. package/dist/assets/PluginPane-BibJit86.js +0 -3
  243. package/dist/assets/SettingsView-h-VpVO47.js +0 -29
  244. package/dist/assets/commitAndPush-BIPfOMXY.js +0 -1
  245. package/dist/assets/de-BqCNGROu.js +0 -10
  246. package/dist/assets/es-BTPpTRgN.js +0 -16
  247. package/dist/assets/fr-hxbzMdAg.js +0 -14
  248. package/dist/assets/index-CLcM8HKx.css +0 -1
  249. package/dist/assets/index-CvLgnuNI.js +0 -41
  250. package/dist/assets/ja-_zLwwYiy.js +0 -16
  251. package/dist/assets/ko-CFn3Dzhc.js +0 -16
  252. package/dist/assets/main-BLJaug9I.js +0 -896
  253. package/dist/assets/markdownCore-DS9FdwrI.js +0 -5
  254. package/dist/assets/patchFileDiff-D9iBcTEi.js +0 -13
  255. package/dist/assets/pl-DFHE7xac.js +0 -16
  256. package/dist/assets/pt-BR-CUjZF179.js +0 -16
  257. package/dist/assets/renderMobileApp-CNQhdXsi.js +0 -25
  258. package/dist/assets/runtimeEndpointReset-DeaERc0M.js +0 -27
  259. package/dist/assets/scheduledTasksApi-BD6Vx9pu.js +0 -1
  260. package/dist/assets/tr-BB6sA_zH.js +0 -7
  261. package/dist/assets/uk-CB4o8g-o.js +0 -16
  262. package/dist/assets/vendor-opencode-client-_BAHQo4R.js +0 -12
  263. package/dist/assets/vendor-zod-Gea9uBlY.js +0 -39
  264. package/dist/assets/zh-CN-BRyDuWhc.js +0 -16
  265. package/dist/assets/zh-TW-BDGbWA1Q.js +0 -16
@@ -0,0 +1,12 @@
1
+ import{R as C,f as ae,j as re}from"./vendor-react-BUCujlKS.js";import{m as Vt}from"./vendor-morphdom-B7dS_VPB.js";import{r as Kt,a as Ut}from"./vendor-beautiful-mermaid-DztCUpLZ.js";import{gN as lt,gO as jt,gP as Xt,gQ as Zt,gR as Gt,gS as Yt,g as ye,bp as Qt,bs as Jt,gT as en,gU as tn,_ as ct,ai as dt,gV as ut,f as mt,h as pt,eH as nn,eI as Be,gW as rn,gX as on,gY as sn,gZ as an,g_ as ln,g$ as cn,o as dn}from"./useAppFontEffects-DDjuwVqi.js";import{h as un,P as ft,N as oe,d2 as mn,u as Y,a as pn,bb as fn}from"./index-Di6zUe5h.js";import{getCachedMarkdownBlocks as $e,renderMarkdownSync as hn,renderMarkdownBlocks as gn}from"./markdownCore-DK2KK5RW.js";import{b as bn,r as wn}from"./textMateThemeFromAppTheme-C-kGcOpD.js";import"./vendor-scheduler-7OC5HNn7.js";import"./vendor-elkjs-BRwcR927.js";import"./vendor-entities-C3BA0AJP.js";import"./vendor-zod-BSoePkpP.js";import"./vendor-simplewebauthn-browser-VDA66rT_.js";import"./vendor-vite-runtime-DD1OZmLC.js";import"./vendor-zustand-BAGL70zf.js";import"./vendor-base-ui-CsXYnR5c.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-tanstack-react-virtual-ClYN8CzB.js";import"./vendor-tanstack-virtual-core-BewVQryB.js";import"./vendor-framer-motion-Bq3iTZ6r.js";import"./vendor-motion-dom-DcCgeG69.js";import"./vendor-motion-utils-BGh8QBgx.js";import"./contextPanelEmbeddedChat-CirXEPJq.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-oKF0MAwd.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-BuBPBC3R.js";import"./vendor-tailwind-merge-CPcsbTWB.js";import"./vendor-fuse.js-Dw8P0qyA.js";import"./vendor-opencode-client-DSZl7jSi.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-CHD9BdDO.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 ht=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},Re=(t,e)=>{if(t.defaultPrevented)return!1;const r=ht(t)?.getAttribute("href")??"";return jt(r)?(t.preventDefault(),t.stopPropagation(),e?.(r),!0):!1},yn=t=>t.button===0&&!t.metaKey&&!t.ctrlKey&&!t.altKey&&!t.shiftKey,An=(t,e)=>{const n=o=>{if(Re(o,e.openAppLink)||!e.allowExternalHttp||o.defaultPrevented||!yn(o))return;const i=ht(o)?.getAttribute("href")??"";lt(i)&&(o.preventDefault(),o.stopPropagation(),e.openExternalHttp(i))},r=o=>{o.button===1&&Re(o,e.openAppLink)},s=o=>{Re(o)};return t.addEventListener("click",n),t.addEventListener("auxclick",r),t.addEventListener("dragstart",s),()=>{t.removeEventListener("click",n),t.removeEventListener("auxclick",r),t.removeEventListener("dragstart",s)}},gt='[data-openchamber-file-link="true"]',vn=t=>{if(!(t instanceof Element))return null;const e=t.closest(gt);return e instanceof HTMLElement?e:null},kn=(t,e)=>{if(!(t instanceof Element))return null;const n=t.closest("a[href]");if(!(n instanceof HTMLAnchorElement))return null;const r=e.hrefCandidate(n);return!r||!e.isResolvable(r)?null:n},Cn=(t,e)=>{const n=r=>{const s=vn(r.target)??kn(r.target,e);s&&(r.preventDefault(),r.stopPropagation(),e.openFileReference(s))};return t.addEventListener("click",n),()=>t.removeEventListener("click",n)},bt="openchamber-md",Ae={background:"transparent",foreground:"var(--md-syntax-foreground)",comment:"var(--md-syntax-comment)",keyword:"var(--md-syntax-keyword)",string:"var(--md-syntax-string)",number:"var(--md-syntax-number)",function:"var(--md-syntax-function)",variable:"var(--md-syntax-variable)",type:"var(--md-syntax-type)",operator:"var(--md-syntax-operator)"},En=Object.fromEntries(Object.keys(Xt({base:Ae})).map(t=>[t,`var(--md-token-${t})`])),Sn={name:bt,colors:{"editor.background":"transparent","editor.foreground":Ae.foreground},tokenColors:[...bn({base:Ae,tokens:En}),{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:Ae.keyword,fontStyle:"bold"}},{scope:["markup.inserted","punctuation.definition.inserted"],settings:{foreground:"var(--md-syntax-inserted)"}},{scope:["markup.deleted","punctuation.definition.deleted","invalid","invalid.illegal"],settings:{foreground:"var(--md-syntax-deleted)"}}]};let He=!1;const Ln=()=>{He||(He=!0,wn(bt,()=>Promise.resolve(Sn)))},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},Te=(t,e,n)=>Math.min(n,Math.max(e,t)),Mn=6,Ve=1.25,Nn=1.0015,Rn=.5,Tn=12,Ke=3,_n=400,se='[data-markdown="mermaid-block"]',F=t=>t.querySelector(se)!==null,xn=t=>[t.x,t.y,t.width,t.height].map(e=>{const n=Number(e.toFixed(Mn));return Object.is(n,-0)?"0":String(n)}).join(" "),Pn=t=>{const e=t.viewBox?.trim().split(/[\s,]+/).map(s=>Number.parseFloat(s));if(e?.length===4){const[s,o,i,a]=e;if(Number.isFinite(s)&&Number.isFinite(o)&&T(i)&&T(a))return{x:s,y:o,width:i,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}},In=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)},Fn=t=>{const e=t.renderMode||"unknown",n=t.svgMarkup??"";if(!n){const r=[t.viewBox??"",t.width??"",t.height??""];return r.some(s=>s!=="")?`${e}:bounds:${r.join(":")}`:`${e}:no-svg`}return[e,In(n)].join(":")},wt=(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 s=t.height*r;return{x:t.x-(s-t.width)/2,y:t.y,width:s,height:t.height}},Dn=({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},On=(t,e)=>{const n=e.x-t.x,r=e.y-t.y;return n*n+r*r>Ke*Ke},Wn=({currentBox:t,contentBox:e,viewport:n,pointer:r,zoomFactor:s,minScale:o,maxScale:i})=>{if(!T(n.width)||!T(n.height)||!T(s)||!T(t.width)||!T(t.height)||!T(e.width)||!T(e.height)||!T(o)||!T(i))return t;const a=Math.min(o,i),l=Math.max(o,i),c=wt(e,n),u=c.width/t.width,p=Te(u*s,a,l),m=c.width/p,h=m/(t.width/t.height),y=Te(r.x/n.width,0,1),A=Te(r.y/n.height,0,1),E=t.x+y*t.width,f=t.y+A*t.height;return{x:E-y*m,y:f-A*h,width:m,height:h}},ve=new WeakMap,Fe=new WeakMap,U=new Set,ie=new Set;let K=null,ne=null,J=null;const qn=t=>t.querySelector('[data-markdown="mermaid-viewport"]')??t.querySelector('[data-markdown="mermaid"]'),yt=t=>{const e=t.querySelector('[data-markdown="mermaid"] svg'),n=t.querySelector('[data-markdown="mermaid"]');return Fn({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")})},G=t=>{const e=t.getBoundingClientRect();return{width:e.width,height:e.height}},Bn=(t,e)=>{const n=e.getBoundingClientRect();return{x:t.clientX-n.left,y:t.clientY-n.top}},$n=t=>t instanceof Element&&!!t.closest('button, a, [role="button"]'),At=t=>{const e=t.map(n=>G(n.viewport));t.forEach((n,r)=>{const s=e[r];s&&n.fitToViewport(s)})},vt=()=>{J!==null||U.size===0||(J=window.requestAnimationFrame(()=>{J=null,At(Array.from(U))}))},Hn=()=>{if(K)return K;const t=globalThis.ResizeObserver;return t?(K=new t(e=>{for(const n of e)n.target instanceof HTMLElement&&Fe.get(n.target)?.fitToViewport({width:n.contentRect.width,height:n.contentRect.height})}),K):null},zn=t=>{if(U.has(t))return;const e=U.size===0;U.add(t),Fe.set(t.viewport,t),Hn()?.observe(t.viewport),e&&window.addEventListener("resize",vt)},Vn=t=>{U.delete(t)&&(K?.unobserve(t.viewport),Fe.delete(t.viewport),!(U.size>0)&&(K?.disconnect(),K=null,window.removeEventListener("resize",vt),J!==null&&(window.cancelAnimationFrame(J),J=null)))},Kn=t=>{const e=qn(t),n=t.querySelector('[data-markdown="mermaid"] svg');if(!e||!n)return null;const r=Pn({viewBox:n.getAttribute("viewBox"),width:n.getAttribute("width"),height:n.getAttribute("height")});if(!r)return null;let s=r,o=null,i=null,a=null,l=null;const c=d=>{s=d,n.setAttribute("viewBox",xn(d)),n.removeAttribute("width"),n.removeAttribute("height")},u=d=>{c(wt(r,d))},p=()=>{u(G(e))},m=(d,b)=>{c(Wn({currentBox:s,contentBox:r,viewport:G(e),pointer:d,zoomFactor:b,minScale:Rn,maxScale:Tn}))},h=()=>{const d=G(e);m({x:d.width/2,y:d.height/2},Ve)},y=()=>{const d=G(e);m({x:d.width/2,y:d.height/2},1/Ve)},A=d=>{!d.ctrlKey&&!d.metaKey||(d.preventDefault(),d.stopPropagation(),m(Bn(d,e),Math.pow(Nn,-d.deltaY)))},E=d=>{d.button!==0||$n(d.target)||(o=d.pointerId,i={x:d.clientX,y:d.clientY},a=i,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())},f=d=>{if(o!==d.pointerId||!a)return;const b={x:d.clientX,y:d.clientY};c(Dn({currentBox:s,viewport:G(e),delta:{x:b.x-a.x,y:b.y-a.y}})),a=b,i&&On(i,b)&&t.setAttribute("data-mermaid-suppress-click","true"),d.preventDefault()},g=d=>{o===d.pointerId&&(e.releasePointerCapture?.(d.pointerId),o=null,i=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},_n)))};e.addEventListener("wheel",A,{passive:!1}),e.addEventListener("pointerdown",E),e.addEventListener("pointermove",f),e.addEventListener("pointerup",g),e.addEventListener("pointercancel",g);const k={viewport:e,zoomIn:h,zoomOut:y,fit:p,fitToViewport:u,cleanup:()=>{Vn(k),e.removeEventListener("wheel",A),e.removeEventListener("pointerdown",E),e.removeEventListener("pointermove",f),e.removeEventListener("pointerup",g),e.removeEventListener("pointercancel",g),l!==null&&window.clearTimeout(l),t.removeAttribute("data-mermaid-panning"),t.removeAttribute("data-mermaid-suppress-click"),ve.delete(t)}};return k},kt=t=>{for(const[e,n]of t.controllers){const r=yt(e);(!t.container.contains(e)||r!==t.signatures.get(e))&&(n.cleanup(),t.controllers.delete(e),t.signatures.delete(e))}},Un=t=>{if(t.disposed)return[];const e=[];for(const n of Array.from(t.container.querySelectorAll(se))){if(t.controllers.has(n)||n.querySelector('[data-markdown="mermaid"] svg')===null)continue;const r=Kn(n);r&&(t.controllers.set(n,r),t.signatures.set(n,yt(n)),ve.set(n,r),e.push(r))}return e},Ct=()=>{const t=Array.from(ie);ie.clear();const e=[];for(const n of t)n.disposed||(kt(n),e.push(...Un(n)));At(e);for(const n of e)zn(n)},jn=()=>{ne===null&&(ne=window.requestAnimationFrame(()=>{ne=null,ne=window.requestAnimationFrame(()=>{ne=null,Ct()})}))},Xn=t=>{t.disposed||(kt(t),ie.add(t),jn())},Zn=t=>{if(!(t instanceof HTMLElement))return null;const e=ve.get(t);if(e)return e;for(const n of ie)if(n.container.contains(t))return Ct(),ve.get(t)??null;return null},Gn=t=>{const e={container:t,controllers:new Map,signatures:new Map,disposed:!1},n=()=>Xn(e),r=()=>{e.disposed=!0,ie.delete(e);for(const s of e.controllers.values())s.cleanup();e.controllers.clear(),e.signatures.clear()};return n(),{refresh:n,cleanup:r}},Yn={copy:"file-copy",check:"check",download:"download",zoomIn:"add",zoomOut:"subtract",fit:"refresh",textWrap:"text-wrap",image:"file-image",disclosure:"arrow-right-s"},Et="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)]",ee=(t,e)=>{const n=Yn[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 s=t.ownerDocument.createElementNS("http://www.w3.org/2000/svg","use");s.setAttribute("href",`#oc-${n}`),r.appendChild(s),t.replaceChildren(r)},Qn=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"),ee(n,"image"),e.prepend(n)}},Jn=t=>{for(const e of t.querySelectorAll("details[data-md-details] > summary")){if(e.querySelector("[data-md-disclosure-icon]"))continue;const n=document.createElement("span");n.append(...Array.from(e.childNodes));const r=document.createElement("span");r.setAttribute("data-md-disclosure-icon",""),r.setAttribute("aria-hidden","true"),ee(r,"disclosure"),e.append(r,n)}},B=(t,e,n)=>{const r=document.createElement("button");return r.type="button",r.className=Et,r.setAttribute("data-md-action",n),r.setAttribute("title",e),r.setAttribute("aria-label",e),ee(r,t),r},St=(t,e,n)=>{const r=t.querySelector("[data-md-code-body]"),s=t.querySelector("pre"),o=t.querySelector("pre code"),i=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),s?.classList.toggle("whitespace-pre-wrap",e),s?.classList.toggle("break-words",e),o?.classList.toggle("whitespace-pre-wrap",e),o?.classList.toggle("break-words",e),s&&(s.style.whiteSpace=e?"pre-wrap":"pre",s.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(i))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")}},Lt=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
+ `),s=r?n.slice(0,-1).split(`
3
+ `):n.split(`
4
+ `),o=s.length>0?s:[""],i=Array.from(e.children).filter(c=>c.classList.contains("line"));r&&i.length===o.length+1&&i.at(-1)?.textContent===""&&i.pop();const a=i.length===o.length,l=document.createDocumentFragment();o.forEach((c,u)=>{const p=document.createElement("span");p.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 h=document.createElement("span");if(h.setAttribute("data-md-code-line-content",""),a){const y=i[u];y&&h.append(...Array.from(y.childNodes))}else h.textContent=c;if(p.append(m,h),l.appendChild(p),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)},Mt=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},Ue=(t,e,n)=>{const r=t.querySelectorAll('[data-component="markdown-code"]');for(const s of Array.from(r)){const o=s.querySelector("pre");o&&Lt(o),St(s,e,n)}},je=(t,e,n,r)=>{ee(t,"check"),t.setAttribute("title",e),t.setAttribute("aria-label",e),window.setTimeout(()=>{ee(t,n),t.setAttribute("title",r),t.setAttribute("aria-label",r)},2e3)},er=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"),n.closest("table")&&n.classList.add("whitespace-nowrap")},tr=(t,e)=>{const n=t.querySelectorAll("pre");for(const r of Array.from(n)){if(r.querySelector("code.language-mermaid"))continue;const s=r.parentElement;if(!s||s.closest('[data-component="markdown-code"]'))continue;const o=r.querySelector("code")?.className.match(/language-([\w+#.-]+)/)?.[1],i=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=i;const u=B("copy",e.labels.copy,"copy-code"),p=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(p),m.appendChild(u),l.appendChild(m);const h=document.createElement("div");h.setAttribute("data-md-code-body",""),h.className="px-3 py-2.5 overflow-x-auto",s.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",""):Lt(r),h.appendChild(r),a.appendChild(l),a.appendChild(h),St(a,e.codeBlockLineWrap,e.labels)}},Xe=t=>{const e=[],n=[],r=t.querySelectorAll("thead th");for(const o of Array.from(r))e.push((o.textContent??"").trim());const s=t.querySelectorAll("tbody tr");for(const o of Array.from(s)){const i=Array.from(o.querySelectorAll("td")).map(a=>(a.textContent??"").trim());i.length>0&&n.push(i)}return{headers:e,rows:n}},nr=t=>/[",\n]/.test(t)?`"${t.replace(/"/g,'""')}"`:t,Ze=({headers:t,rows:e})=>[t,...e].map(n=>n.map(nr).join(",")).join(`
8
+ `),rr=({headers:t,rows:e})=>[t,...e].map(n=>n.join(" ")).join(`
9
+ `),Ge=({headers:t,rows:e})=>{const n=`| ${t.join(" | ")} |`,r=`| ${t.map(()=>"---").join(" | ")} |`,s=e.map(o=>`| ${o.join(" | ")} |`).join(`
10
+ `);return`${n}
11
+ ${r}
12
+ ${s}`},Ye=(t,e)=>{const n=document.createElement("div");n.className=`absolute top-full right-0 mt-1 hidden ${Qt}`,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 s=document.createElement("button");s.type="button",s.className=`w-full text-left ${Jt}`,s.setAttribute("data-md-action",`${t}-${r.key}`),s.textContent=r.label,n.appendChild(s)}return n},Qe=120,or=320,Ie="data-md-table-layout",sr=(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 w-fit max-w-full flex-col space-y-2",o.setAttribute("data-markdown","table-wrapper");const i=document.createElement("div");i.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(Ye("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(Ye("table-download",[{key:"csv",label:"CSV"},{key:"markdown",label:"Markdown"}])),i.appendChild(a),i.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(Ie,"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 p=r.querySelector("tbody tr:last-child");p?.classList.remove("border-b"),p?.classList.add("border-0");for(const m of Array.from(r.querySelectorAll("th")))m.classList.add("min-w-[120px]","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]","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(i),o.appendChild(c)}},ir=t=>{const e=Array.from(t.querySelectorAll(`table[data-markdown="table"]:not([${Ie}="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 i=p=>Array.from(p.children).filter(m=>m.tagName==="TH"||m.tagName==="TD"),a=Array.from(o.querySelectorAll("tbody tr")),l=a.some(p=>i(p).length>0)?a:Array.from(o.querySelectorAll("thead tr")),c=Math.max(0,...Array.from(o.querySelectorAll("tr")).map(p=>i(p).length)),u=[];for(let p=0;p<c;p+=1){const m=t.ownerDocument.createElement("table");m.className=o.className,m.style.tableLayout="auto",m.style.width="max-content";const h=t.ownerDocument.createElement("tbody");for(const y of l){const A=i(y)[p];if(!A)continue;const E=t.ownerDocument.createElement("tr"),f=A.cloneNode(!0);f instanceof HTMLElement&&(f.style.width="auto",f.style.minWidth="0",f.style.maxWidth="none",f.style.whiteSpace="nowrap",f.style.overflowWrap="normal",E.appendChild(f),h.appendChild(E))}m.appendChild(h),n.appendChild(m),u.push(m)}return{table:o,columnProbes:u}});t.appendChild(n);const s=r.map(({table:o,columnProbes:i})=>{const a=o.parentElement?.clientWidth??0,l=Math.max(Qe,a||or),c=i.map(u=>Math.ceil(u.getBoundingClientRect().width));return{table:o,widths:c.map(u=>Math.min(l,Math.max(Qe,u))),cappedColumns:c.map(u=>u>l)}});n.remove();for(const{table:o,widths:i,cappedColumns:a}of s){for(const p of Array.from(o.querySelectorAll("tr")))Array.from(p.children).filter(h=>h.tagName==="TH"||h.tagName==="TD").forEach((h,y)=>{const A=!a[y];for(const E of Array.from(h.querySelectorAll('code[data-markdown="inline-code"]')))E.classList.toggle("whitespace-nowrap",A)});Array.from(o.children).find(p=>p.matches("colgroup[data-md-table-columns]"))?.remove();const c=t.ownerDocument.createElement("colgroup");c.setAttribute("data-md-table-columns","");for(const p of i){const m=t.ownerDocument.createElement("col");m.style.width=`${p}px`,c.appendChild(m)}const u=Array.from(o.children).find(p=>p.tagName==="THEAD"||p.tagName==="TBODY"||p.tagName==="TFOOT")??null;o.insertBefore(c,u),o.style.tableLayout="fixed",o.style.width=`${i.reduce((p,m)=>p+m,0)}px`,o.setAttribute(Ie,"fixed")}},ar=(t,e)=>{const n=t.querySelectorAll("pre > code.language-mermaid");for(const r of Array.from(n)){const s=r.parentElement;if(!s)continue;const o=(r.textContent??"").replace(/\s+$/,""),i=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",i.svg){a.setAttribute("data-mermaid-render","svg");const p=document.createElement("div");p.setAttribute("data-markdown","mermaid-viewport");const m=document.createElement("div");if(m.setAttribute("data-markdown","mermaid"),m.setAttribute("data-md-original-svg",i.svg),m.innerHTML=i.svg,p.appendChild(m),l.appendChild(p),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 h=B("copy",e.labels.copyDiagram,"mermaid-copy");h.setAttribute("data-md-source",o),c.appendChild(h)}if(e.mermaidControls.download){const h=B("download",e.labels.downloadDiagram,"mermaid-download");h.setAttribute("data-md-svg","1"),c.appendChild(h)}}else{a.setAttribute("data-mermaid-render","ascii");const p=document.createElement("pre");if(p.setAttribute("data-markdown","mermaid-ascii"),p.textContent=i.ascii||o,l.appendChild(p),e.mermaidControls.copy){const m=B("copy",e.labels.copyDiagram,"mermaid-copy");m.setAttribute("data-md-source",i.ascii||o),c.appendChild(m)}}a.appendChild(l),a.appendChild(c);const u=s.parentElement;u&&u.replaceChild(a,s)}},lr=(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 s=r.getAttribute("href")??"";if(!lt(s))continue;r.setAttribute("data-md-link-decorated","true");const o=Zt(s);if(o){const i=document.createElement("span");i.setAttribute(Gt,"true"),i.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",()=>i.remove(),{once:!0}),i.appendChild(a),r.parentNode?.insertBefore(i,r)}if(e.onPreviewLoopback&&Yt(s)){const i=document.createElement("button");i.type="button",i.className=`ml-1 align-middle ${Et}`,i.setAttribute("data-md-action","preview-loopback"),i.setAttribute("data-md-url",s),i.setAttribute("title",e.labels.previewTitle),i.setAttribute("aria-label",e.labels.previewLabel),ee(i,"download"),r.parentNode?.insertBefore(i,r.nextSibling)}}},pe=(t,e)=>{Jn(t),Qn(t),er(t),ar(t,e),tr(t,e),sr(t,e.labels),lr(t,e)},Je=(t,e,n)=>{const r=new Blob([e],{type:n}),s=URL.createObjectURL(r),o=document.createElement("a");o.href=s,o.download=t,document.body.appendChild(o),o.click(),document.body.removeChild(o),URL.revokeObjectURL(s)},fe=t=>{for(const e of Array.from(t.querySelectorAll("[data-md-menu]")))e.classList.add("hidden")},et=t=>(t.nodeType===1?t:t.parentElement)?.closest("pre code[data-md-code-lines]")??null,cr=t=>{const e=et(t.startContainer);return!e||e!==et(t.endContainer)?null:t.toString()},he=new WeakMap,dr=t=>{let e=he.get(t);if(!e){const n=()=>{const o=t.getSelection();return!o||o.rangeCount!==1||o.isCollapsed?null:cr(o.getRangeAt(0))},r=o=>{if(!o.clipboardData)return;const i=n();i!==null&&(o.preventDefault(),o.stopPropagation(),o.clipboardData.setData("text/plain",i))},s=o=>{const i=n();i!==null&&(o.preventDefault(),ye(i))};e={registrations:0,handler:r,menuHandler:s},he.set(t,e),t.addEventListener("copy",r,!0),t.defaultView?.addEventListener("openchamber:copy",s)}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("openchamber:copy",n.menuHandler),he.delete(t)))}},ur=(t,e)=>{const n=dr(t.ownerDocument),r=s=>{const o=s.target;if(!(o instanceof Element))return;const i=o.closest("[data-md-action]");if(!i){fe(t);return}const a=i.getAttribute("data-md-action")??"";if(a==="copy-code"){const l=i.closest('[data-component="markdown-code"]')?.querySelector("code"),c=l?Mt(l):"";c&&(i.setAttribute("data-md-copy-pending",""),ye(c).then(()=>je(i,e.labels.copied,"copy",e.labels.copy)).finally(()=>i.removeAttribute("data-md-copy-pending")));return}if(a==="toggle-code-wrap"){s.preventDefault(),e.onToggleCodeBlockLineWrap?.();return}if(a==="table-copy-toggle"||a==="table-download-toggle"){s.preventDefault();const l=i.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=i.closest('[data-markdown="table-wrapper"]')?.querySelector("table");if(c instanceof HTMLTableElement){const u=Xe(c),p=l==="csv"?Ze(u):l==="tsv"?rr(u):Ge(u);ye(p)}fe(t);return}if(a.startsWith("table-download-")){const l=a.replace("table-download-",""),c=i.closest('[data-markdown="table-wrapper"]')?.querySelector("table");if(c instanceof HTMLTableElement){const u=Xe(c),p=l==="csv"?Ze(u):Ge(u);Je(l==="csv"?"table.csv":"table.md",p,l==="csv"?"text/csv":"text/markdown")}fe(t);return}if(a==="mermaid-copy"){const l=i.getAttribute("data-md-source")??"";l&&ye(l).then(()=>je(i,e.labels.copied,"copy",e.labels.copyDiagram));return}if(a==="mermaid-zoom-in"||a==="mermaid-zoom-out"||a==="mermaid-fit"){s.preventDefault();const l=i.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=i.closest('[data-markdown="mermaid-block"]')?.querySelector('[data-markdown="mermaid"]'),c=l?.getAttribute("data-md-original-svg")??l?.innerHTML??"";c&&Je("diagram.svg",c,"image/svg+xml;charset=utf-8");return}if(a==="preview-loopback"){s.preventDefault();const l=i.getAttribute("data-md-url")??"";l&&e.onPreviewLoopback?.(l);return}};return t.addEventListener("click",r),()=>{n(),t.removeEventListener("click",r)}},tt=(t,e,n)=>{let r=0;for(const o of t){const i=r+o.data.length;if(e<i||e===i&&n==="left")return{node:o,offset:Math.max(0,e-r)};r=i}const s=t.at(-1);return s?{node:s,offset:s.data.length}:null},mr=new Set(["dockerfile","makefile","readme","license",".env",".gitignore",".npmrc"]),nt=Array.from(mr).map(t=>t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")).join("|"),Nt=t=>en(t),pr=t=>tn(t),Rt=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}},ke=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=ke(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 s=nt.length>0?e.match(new RegExp(`^(.*(?:/|^)(${nt})):.*$`,"i")):null;return s&&(e=s[1]??e),ke(e)},Tt=t=>{const e=ke(t);if(!e)return null;const n=e.indexOf(";"),r=n>=0?ke(e.slice(0,n)):e;if(!r)return null;const s=r.match(/^(.*?):(\d+)-(\d+)$/);if(s){const l=ge(s[1]??""),c=Number.parseInt(s[2]??"",10),u=Number.parseInt(s[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 i=r.match(/^(.*?):(\d+)(?::(\d+))?$/);if(i){const l=ge(i[1]??""),c=Number.parseInt(i[2]??"",10),u=i[3]?Number.parseInt(i[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},_e=/(?:[A-Za-z]:[\\/])?[\w.\-/@+]*[\w\-/@+]\.[A-Za-z0-9]{1,8}(?::\d+(?:-\d+)?(?::\d+)?)?/g,fr=4,hr=1e3,gr=200,H=new Map;let be=0;const rt=[],br=()=>ft()?gr:hr,wr=(t,e)=>`${t}\0${e}`,yr=(t,e)=>{const n=Nt(t);if(!n)return Promise.resolve(!1);const r=wr(e,n),s=H.get(r);if(s)return H.delete(r),H.set(r,s),s;const o=new Promise(a=>{const l=()=>{be+=1,un(`/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),rt.shift()?.()})};if(be<fr){l();return}rt.push(l)}),i=br();for(;H.size>=i;){const a=H.keys().next().value;if(typeof a!="string")break;H.delete(a)}return H.set(r,o),o},Ar={maxSessions:8,maxEntriesPerSession:4};class vr{maxSessions;maxEntriesPerSession;sessions=new Map;constructor(e=Ar){this.maxSessions=Math.max(1,e.maxSessions),this.maxEntriesPerSession=Math.max(1,e.maxEntriesPerSession)}store(e){const n=e.scope,r=e.id;let s=this.sessions.get(n);for(s===void 0?(s=new Map,this.sessions.set(n,s)):this.refreshSession(n,s),s.delete(r),s.set(r,e);s.size>this.maxEntriesPerSession;)this.removeOldestEntry(s);for(;this.sessions.size>this.maxSessions;)this.removeOldestSession()}take(e){const n=e.scope,r=this.sessions.get(n);if(!r)return null;const s=e.id;this.refreshSession(n,r);const o=r.get(s);return o===void 0||o.locale!==e.locale||o.directory!==e.directory?null:(r.delete(s),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 ot=new vr,_t=()=>{const t=ae.c(4),e=nn();let n;t[0]===Symbol.for("react.memo_cache_sentinel")?(n=Be(!1),t[0]=n):n=t[0];const r=n;let s;t[1]===Symbol.for("react.memo_cache_sentinel")?(s=Be(!0),t[1]=s):s=t[1];const o=s;let i;return t[2]!==e?.currentTheme?(i=e?.currentTheme??(typeof window<"u"&&window.matchMedia("(prefers-color-scheme: dark)").matches?o:r),t[2]=e?.currentTheme,t[3]=i):i=t[3],i},xt=t=>{const e=ae.c(4),{containerRef:n,enabled:r}=t;let s,o;e[0]!==n||e[1]!==r?(s=()=>{const i=n.current;if(i)return An(i,{allowExternalHttp:r!==!1,openAppLink:Hr,openExternalHttp:zr})},o=[n,r],e[0]=n,e[1]=r,e[2]=s,e[3]=o):(s=e[2],o=e[3]),C.useEffect(s,o)},te={download:!0,copy:!0,showPanZoomControls:!0},Pt=!0,kr=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},It="data-openchamber-block-path-token",Ft=`[${It}]`,Q="data-openchamber-block-paths-scanned",Cr=2e5,Er=80,Sr=40,st=160,Lr=()=>ft()?Sr:Er,Mr=new Set(["dockerfile","makefile","readme","license",".env",".gitignore",".npmrc"]),Dt=t=>Nt(t),Nr=t=>pr(t),Rr=(t,e)=>an(t,e),Tr=t=>{const e=t.split("/").filter(Boolean).pop()??"";return!e||e.endsWith(".")?!1:/\.[A-Za-z0-9_-]{1,16}$/.test(e)},Ot=t=>{if(!t||t.startsWith("--")||t.includes("://")||/[<>]/.test(t)||/\s{2,}/.test(t))return!1;const e=Dt(t),n=e.split("/").filter(Boolean).pop()??e;if(!n||n==="."||n==="..")return!1;const r=n.toLowerCase();return Mr.has(r)||r.startsWith(".")&&r.length>1?!0:Tr(e)},De=t=>{const e=Tt(t);return e?Ot(e.path):!1},_r=t=>{const e=t.querySelectorAll(Ft);for(const r of Array.from(e))r.replaceWith(t.ownerDocument.createTextNode(r.textContent??""));const n=t.querySelectorAll(`code[${Q}]`);for(const r of Array.from(n))r.removeAttribute(Q),r.normalize()},xe=t=>{if(t.tagName.toLowerCase()==="a"){const e=t.getAttribute("href")?.trim(),n=e?Rt(e):null;if(n)return n;if(e&&De(e))return e}return(t.textContent||"").trim()},xr=t=>{const e=t.getAttribute("href")?.trim();if(!e)return null;const n=Rt(e);return n||(De(e)?e:null)},Pr=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(Q)==="true")continue;if((r.textContent??"").length>Cr){r.setAttribute(Q,"true");continue}const s=n.createTreeWalker(r,NodeFilter.SHOW_TEXT),o=[];let i=s.nextNode();for(;i;){const u=i;u.parentElement?.closest("[data-md-code-line-number]")||o.push(u),i=s.nextNode()}const a=Mt(r);if(!a.includes(".")){r.setAttribute(Q,"true");continue}_e.lastIndex=0;const l=[];let c=_e.exec(a);for(;c;){const u=c[0];u&&De(u)&&l.push({start:c.index,end:c.index+u.length,raw:u}),c=_e.exec(a)}for(const{start:u,end:p,raw:m}of l.reverse()){const h=tt(o,u,"right"),y=tt(o,p,"left");if(!h||!y)continue;const A=n.createRange();A.setStart(h.node,h.offset),A.setEnd(y.node,y.offset);const E=n.createElement("span");E.setAttribute(It,"true"),E.textContent=m,A.deleteContents(),A.insertNode(E)}r.setAttribute(Q,"true")}},we=(t,e)=>{const n=Tt(t);if(!n||!Ot(n.path))return null;const r=Nr(n.path)?Dt(n.path):Rr(e,n.path);return r?{...n,resolvedPath:r}:null},Ir=(t,e)=>t||sn(t,e),Wt=({containerRef:t,effectiveDirectory:e,editor:n,preferRuntimeEditor:r,enabled:s})=>{const o=C.useRef(null);C.useEffect(()=>{const i=t.current;if(!i||s&&!e)return;let a=!1;const l=Lr(),c=s&&!fn(),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"))},p=()=>{const d=i.querySelectorAll(gt);for(const b of Array.from(d))u(b);_r(i)};if(!c){p();return}const m=(d=0)=>{if(o.current!==null&&typeof window<"u"&&window.clearTimeout(o.current),typeof window>"u"){h();return}o.current=window.setTimeout(()=>{o.current=null,window.requestAnimationFrame(()=>{a||h()})},d)},h=()=>{f+=1;try{y()}finally{queueMicrotask(()=>{f-=1})}},y=()=>{c&&Pr(i);const d=i.querySelectorAll(`[data-markdown="inline-code"], a, ${Ft}`);let b=0;for(const w of Array.from(d)){const v=xe(w),M=we(v,e);if(u(w),!M||b>=l)continue;b+=1,(!on(M.resolvedPath,e)?Promise.resolve(!0):yr(M.resolvedPath,e)).then(x=>{if(a||!x||!i.contains(w))return;const L=xe(w),R=we(L,e);!R||R.resolvedPath!==M.resolvedPath||(w.setAttribute("data-openchamber-file-link","true"),w.setAttribute("data-openchamber-file-ref",L),w.setAttribute("data-openchamber-file-path",R.resolvedPath),w.setAttribute("title","Open file"),w.tagName.toLowerCase()!=="a"&&(w.setAttribute("role","button"),w.setAttribute("tabindex","0")))})}},A=async d=>{const b=d.getAttribute("data-openchamber-file-ref")||xe(d),w=we(b,e);if(!w)return;const v=Ir(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}const M=Y.getState();Number.isFinite(w.line??Number.NaN)?M.openContextFileAtLine(v,w.resolvedPath,Math.max(1,Math.trunc(w.line)),Number.isFinite(w.column??Number.NaN)?Math.max(1,Math.trunc(w.column)):1):M.openContextFile(v,w.resolvedPath)},E=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(),A(b))};m(st);let f=0;const g=new MutationObserver(()=>{f>0||m(st)});g.observe(i,{childList:!0,subtree:!0}),i.addEventListener("keydown",E);const k=Cn(i,{hrefCandidate:xr,isResolvable:d=>we(d,e)!==null,openFileReference:A});return()=>{a=!0,o.current!==null&&typeof window<"u"&&window.clearTimeout(o.current),o.current=null,g.disconnect(),k(),i.removeEventListener("keydown",E)}},[t,n,e,r,s])},qt=t=>{const e=ae.c(7),{containerRef:n,onShowPopup:r,enableFullscreen:s,enablePanZoom:o,allowMermaidWheelEvents:i}=t;let a,l;e[0]!==i||e[1]!==n||e[2]!==s||e[3]!==o||e[4]!==r?(a=()=>{const c=n.current;if(!c)return;const u=m=>{if(!s||!r)return;const h=m.target;if(!(h instanceof Element)||h.closest('button, a, [role="button"]'))return;const y=h.closest(se);if(!y)return;if(y instanceof HTMLElement&&y.hasAttribute("data-mermaid-suppress-click")){y.removeAttribute("data-mermaid-suppress-click");return}const E=Array.from(c.querySelectorAll(se)).indexOf(y);if(E<0)return;const f=y instanceof HTMLElement?y.getAttribute("data-md-source"):null;if(!f||f.trim().length===0)return;const g=`Diagram ${E+1}`;r({open:!0,title:g,content:"",metadata:{tool:"mermaid-preview",filename:g},mermaid:{url:`data:text/plain;charset=utf-8,${encodeURIComponent(f)}`,source:f,filename:g}})},p=m=>{if(i||(m.ctrlKey||m.metaKey)&&o)return;const h=m.target;!(h instanceof Element)||!h.closest(se)||m.stopPropagation()};return c.addEventListener("click",u),c.addEventListener("wheel",p,{capture:!0,passive:!0}),()=>{c.removeEventListener("click",u),c.removeEventListener("wheel",p,!0)}},l=[i,n,s,o,r],e[0]=i,e[1]=n,e[2]=s,e[3]=o,e[4]=r,e[5]=a,e[6]=l):(a=e[5],l=e[6]),C.useEffect(a,l)},z=new Map,Fr=100,V="data-md-decoration-id",Dr=(t,e,n)=>{const r=t.children;if(r.length!==e.length)return!1;for(let s=0;s<e.length;s+=1){const o=r[s];if(!o||o.getAttribute("data-md-id")!==e[s]?.id||o.getAttribute(V)!==n)return!1}return!0},it=new WeakMap;let at=0;const Or=2e5,Pe=t=>{const e=it.get(t);if(e)return e;const n=`decoration-${at}`;return at+=1,it.set(t,n),n},Wr=(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>Fr){const s=z.keys().next().value;s&&z.delete(s)}return r},qr=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"}),Bt=(t,e,n,r=te)=>{const{t:s}=mt(),o=C.useMemo(()=>({copy:s("markdownRenderer.code.actions.copyTitle"),copied:s("markdownRenderer.code.actions.copiedTitle"),enableCodeWrap:s("markdownRenderer.code.actions.enableWrapTitle"),disableCodeWrap:s("markdownRenderer.code.actions.disableWrapTitle"),copyTable:s("markdownRenderer.table.actions.copyTitle"),downloadTable:s("markdownRenderer.table.actions.downloadTitle"),copyDiagram:s("markdownRenderer.mermaid.actions.copySourceTitle"),downloadDiagram:s("markdownRenderer.mermaid.actions.downloadSvgTitle"),zoomInDiagram:s("markdownRenderer.mermaid.actions.zoomInTitle"),zoomOutDiagram:s("markdownRenderer.mermaid.actions.zoomOutTitle"),resetDiagramView:s("markdownRenderer.mermaid.actions.resetViewTitle"),previewLabel:s("terminalView.preview.open"),previewTitle:s("terminalView.preview.openTitle")}),[s]),i=Y(c=>c.codeBlockLineWrap),a=Y(c=>c.setCodeBlockLineWrap),l=C.useCallback(()=>{a(!Y.getState().codeBlockLineWrap)},[a]);return C.useMemo(()=>{const c=qr(t),u=Y.getState().mermaidRenderingMode,p=t.metadata?.id??"theme";return{labels:o,mermaidControls:r,codeBlockLineWrap:i,deferCodeLineNumberSync:e,onToggleCodeBlockLineWrap:l,renderMermaid:h=>Wr(`${p}:${u}:${h}`,()=>{try{return u==="ascii"?{ascii:Kt(h)}:{svg:Ut(h,c)}}catch{return{}}}),onPreviewLoopback:n}},[t,o,r,i,e,l,n])},$t=({containerRef:t,text:e,streaming:n,imageMode:r="inline",syntaxVars:s,ctx:o,domCacheKey:i,tableLayoutSettled:a})=>{C.useEffect(()=>{Ln()},[]);const l=C.useRef(null),c=C.useRef(0),u=C.useRef(null),p=C.useContext(rn),m=C.useRef(null),h=C.useCallback(()=>{m.current?.(),m.current=null},[]);C.useEffect(()=>h,[h]);const y=C.useRef(null),A=C.useCallback(()=>{const f=t.current;if(f){if(!l.current){if(!F(f))return;l.current=Gn(f);return}l.current.refresh()}},[t]),E=C.useCallback(()=>{if(!a)return;const f=u.current;f!==null&&window.cancelAnimationFrame(f);const g=c.current,k=window.requestAnimationFrame(()=>{if(u.current!==k||(u.current=null,c.current!==g))return;const d=t.current,b=d?.querySelector("[data-markdown-content]")??d;b&&ir(b)});u.current=k},[t,a]);C.useEffect(()=>()=>{const f=u.current;f!==null&&(window.cancelAnimationFrame(f),u.current=null)},[]),C.useLayoutEffect(()=>{c.current+=1,y.current=null},[o,r,n,e]),C.useLayoutEffect(()=>{if(!i)return;const f=t.current,g=f?.querySelector("[data-markdown-content]")??f;if(!g||g.childNodes.length>0)return;const k=ot.take(i);if(k){g.appendChild(k);const d=Pe(o);for(const b of Array.from(g.children))b.setAttribute(V,d);for(const[b,w]of Object.entries(s))g.style.setProperty(b,w);Ue(g,o.codeBlockLineWrap,o.labels),y.current={key:i,copiedLabel:o.labels.copied},oe("ui.markdown_renderer.dom_cache.hit")}},[t,o,i,s,e.length]),C.useLayoutEffect(()=>{const f=t.current,g=f?.querySelector("[data-markdown-content]")??f;if(g)return()=>{const k=y.current;if(!k||g.childNodes.length===0||F(g)||Array.from(g.children).some(M=>!M.hasAttribute("data-md-id"))||g.querySelector("[data-md-copy-pending]"))return;const d=window.getSelection();if(d?.rangeCount&&!d.isCollapsed&&d.getRangeAt(0).intersectsNode(g))return;const b=g.querySelector("[data-md-menu]:not(.hidden)"),w=Array.from(g.querySelectorAll("[data-md-action]")).some(M=>M.getAttribute("title")===k.copiedLabel);if(b||w)return;const v=document.createDocumentFragment();v.append(...Array.from(g.childNodes)),ot.store({...k.key,fragment:v}),oe("ui.markdown_renderer.dom_cache.capture")}},[t]),C.useLayoutEffect(()=>{const f=t.current,g=f?.querySelector("[data-markdown-content]")??f;if(!g)return;const k=Pe(o);if(e&&g.childNodes.length===0){const d=n?null:$e(e,r);if(d){let b=!1;for(const w of d){const v=document.createElement("div");v.setAttribute("data-md-block",""),v.style.display="contents",v.innerHTML=w.html,pe(v,o),v.setAttribute("data-md-id",w.id),v.setAttribute(V,k),b||=F(v),g.appendChild(v)}b&&A()}else{!n&&!m.current&&(m.current=p?.hold()??null);const b=document.createElement("div");b.setAttribute("data-md-block",""),b.style.display="contents",b.innerHTML=hn(e,r),pe(b,o),b.setAttribute(V,k),g.appendChild(b),F(b)&&A()}}else!l.current&&F(g)&&A()},[t,e,n,r,o,A,p]),C.useEffect(()=>()=>{l.current?.cleanup(),l.current=null},[]),C.useEffect(()=>{const f=t.current;if(!f)return;const g=f.querySelector("[data-markdown-content]")??f;let k=!0;const d=c.current,b=Pe(o);if(!n){const w=$e(e,r);if(w&&Dr(g,w,b)){y.current=i?{key:i,copiedLabel:o.labels.copied}:null,oe("ui.markdown_renderer.settled_paint.reused"),E(),h();return}}return gn(e,n,r).then(w=>{if(!k||c.current!==d)return;const v=Array.from(g.children),M=Array.from(g.querySelectorAll("details[data-md-details]")).map(L=>({summary:L.querySelector("summary")?.textContent,open:L.open}));let D=0;w.forEach((L,R)=>{let S=v[R],P=!1;if(S||(S=document.createElement("div"),S.setAttribute("data-md-block",""),S.style.display="contents",g.appendChild(S),P=!0),S.getAttribute("data-md-id")===L.id){if(S.getAttribute(V)!==b){const I=F(S);I&&(l.current?.cleanup(),l.current=null);const N=document.createElement("div");N.setAttribute("data-md-block",""),N.style.display="contents",N.innerHTML=L.html,pe(N,o),N.setAttribute("data-md-id",L.id),N.setAttribute(V,b),S.replaceWith(N),(I||F(N))&&A()}!l.current&&F(S)&&A();return}const _=document.createElement("div");if(_.innerHTML=L.html,pe(_,o),P&&n&&R>0){const I=Math.min(D,4)*55;D+=1;for(const N of Array.from(_.children))N.classList.add("oc-md-block-enter"),I>0&&N instanceof HTMLElement&&N.style.setProperty("--oc-md-enter-delay",`${I}ms`)}const O=F(S),W=F(_);Vt(S,_,{childrenOnly:!0,onBeforeElUpdated:(I,N)=>(I.matches("details[data-md-details]")&&N.matches("details[data-md-details]")&&I.querySelector("summary")?.textContent===N.querySelector("summary")?.textContent&&N.toggleAttribute("open",I.hasAttribute("open")),!I.isEqualNode(N))}),S.setAttribute("data-md-id",L.id),S.setAttribute(V,b),(O||W||F(S))&&A()});const $=F(g);let x=!1;for(let L=v.length-1;L>=w.length;L-=1){const R=v[L];R&&F(R)&&(x=!0),R?.remove()}(x||v.length>w.length&&$)&&A(),M.length>0&&g.querySelectorAll("details[data-md-details]").forEach((L,R)=>{const S=M[R];S&&S.summary===L.querySelector("summary")?.textContent&&(L.open=S.open)}),y.current=i?{key:i,copiedLabel:o.labels.copied}:null,E(),h()}),()=>{k=!1}},[t,o,i,r,A,h,E,n,e]),C.useEffect(()=>{const f=t.current;if(f)return ur(f,o)},[t,o]),C.useEffect(()=>{const f=t.current,g=f?.querySelector("[data-markdown-content]")??f;if(g)for(const[k,d]of Object.entries(s))g.style.setProperty(k,d)},[t,s]),C.useEffect(()=>{const f=t.current,g=f?.querySelector("[data-markdown-content]")??f;g&&(o.deferCodeLineNumberSync||Ue(g,o.codeBlockLineWrap,o.labels))},[t,o.codeBlockLineWrap,o.deferCodeLineNumberSync,o.labels])},Ht=t=>t==="tool"?"markdown-content markdown-tool":t==="reasoning"?"markdown-content markdown-reasoning":"markdown-content leading-relaxed",Br=t=>{const e=ae.c(40),{content:n,part:r,messageId:s,isAnimated:o,skipFadeIn:i,className:a,isStreaming:l,disableStreamAnimation:c,variant:u,onShowPopup:p,enableFileReferences:m}=t,h=o===void 0?!0:o,y=i===void 0?!1:i,A=l===void 0?!1:l,E=c===void 0?!1:c,f=u===void 0?"assistant":u,g=m===void 0?!0:m;oe("ui.markdown_renderer.render"),A&&oe("ui.markdown_renderer.render.streaming"),mn("ui.markdown_renderer.content_len",n.length);const k=_t(),{editor:d,runtime:b}=ct(),w=C.useRef(null),v=dt()??"",M=Y(Vr);let D;e[0]!==v||e[1]!==M?(D=q=>{v&&M(v,q)},e[0]=v,e[1]=M,e[2]=D):D=e[2];const $=D,x=A&&!E;let L;e[3]!==p?(L={containerRef:w,onShowPopup:p,enableFullscreen:Pt,enablePanZoom:te.showPanZoomControls},e[3]=p,e[4]=L):L=e[4],qt(L);const R=g&&!A;let S;e[5]!==d||e[6]!==v||e[7]!==b.isVSCode||e[8]!==R?(S={containerRef:w,effectiveDirectory:v,editor:d,preferRuntimeEditor:b.isVSCode,enabled:R},e[5]=d,e[6]=v,e[7]=b.isVSCode,e[8]=R,e[9]=S):S=e[9],Wt(S);let P;e[10]===Symbol.for("react.memo_cache_sentinel")?(P={containerRef:w},e[10]=P):P=e[10],xt(P);let _;e[11]!==k?(_=ut(k),e[11]=k,e[12]=_):_=e[12];const O=_,W=Bt(k,x,v?$:void 0,te),{locale:I}=mt(),N=f==="assistant"?"label":"inline",Ce=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=pn(),e[13]=le):le=e[13];const zt=le,Oe=Ce?.sessionID,We=Ce?.messageID,qe=Ce?.id;let Ee;e:{if(A||!Oe||!We||!qe||n.length===0||n.length>Or){Ee=null;break e}const q=`${zt}\0${Oe}`,Ne=`${We}\0${qe}\0${N}\0${n.length}`;let me;e[14]!==v||e[15]!==I||e[16]!==q||e[17]!==Ne?(me={scope:q,id:Ne,locale:I,directory:v},e[14]=v,e[15]=I,e[16]=q,e[17]=Ne,e[18]=me):me=e[18],Ee=me}const Se=Ee,Le=`markdown-${r?.id?`part-${r.id}`:`message-${s}`}`,Me=!A;let ce;e[19]!==n||e[20]!==W||e[21]!==Se||e[22]!==N||e[23]!==x||e[24]!==O||e[25]!==Me?(ce={containerRef:w,text:n,streaming:x,imageMode:N,syntaxVars:O,ctx:W,domCacheKey:Se,tableLayoutSettled:Me},e[19]=n,e[20]=W,e[21]=Se,e[22]=N,e[23]=x,e[24]=O,e[25]=Me,e[26]=ce):ce=e[26],$t(ce);let j;e[27]!==a?(j=pt("break-words w-full min-w-0",a),e[27]=a,e[28]=j):j=e[28];let X;e[29]!==f?(X=Ht(f),e[29]=f,e[30]=X):X=e[30];let Z;e[31]!==X?(Z=re.jsx("div",{className:X,"data-markdown-content":!0}),e[31]=X,e[32]=Z):Z=e[32];let de;e[33]!==j||e[34]!==Z?(de=re.jsx("div",{className:j,ref:w,children:Z}),e[33]=j,e[34]=Z,e[35]=de):de=e[35];const ue=de;if(h){let q;return e[36]!==Le||e[37]!==ue||e[38]!==y?(q=re.jsx(ln,{skipAnimation:y,children:ue},Le),e[36]=Le,e[37]=ue,e[38]=y,e[39]=q):q=e[39],q}return ue},Xs=C.memo(Br,(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),$r=t=>{const e=ae.c(29),{content:n,className:r,variant:s,disableLinkSafety:o,stripFrontmatter:i,onShowPopup:a,mermaidControls:l,allowMermaidWheelEvents:c,enableFileReferences:u}=t,p=s===void 0?"assistant":s,m=i===void 0?!1:i,h=l===void 0?te:l,y=c===void 0?!1:c,A=u===void 0?!0:u,{editor:E,runtime:f}=ct(),g=_t(),k=C.useRef(null),d=dt()??"";let b;e[0]!==n||e[1]!==m?(b=m?kr(n):n,e[0]=n,e[1]=m,e[2]=b):b=e[2];const w=b;let v;e[3]!==y||e[4]!==h.showPanZoomControls||e[5]!==a?(v={containerRef:k,onShowPopup:a,enableFullscreen:Pt,enablePanZoom:h.showPanZoomControls,allowMermaidWheelEvents:y},e[3]=y,e[4]=h.showPanZoomControls,e[5]=a,e[6]=v):v=e[6],qt(v);let M;e[7]!==E||e[8]!==d||e[9]!==A||e[10]!==f.isVSCode?(M={containerRef:k,effectiveDirectory:d,editor:E,preferRuntimeEditor:f.isVSCode,enabled:A},e[7]=E,e[8]=d,e[9]=A,e[10]=f.isVSCode,e[11]=M):M=e[11],Wt(M);const D=!o;let $;e[12]!==D?($={containerRef:k,enabled:D},e[12]=D,e[13]=$):$=e[13],xt($);let x;e[14]!==g?(x=ut(g),e[14]=g,e[15]=x):x=e[15];const L=x,R=Bt(g,!1,void 0,h);let S;e[16]!==R||e[17]!==w||e[18]!==L?(S={containerRef:k,text:w,streaming:!1,syntaxVars:L,ctx:R,tableLayoutSettled:!0},e[16]=R,e[17]=w,e[18]=L,e[19]=S):S=e[19],$t(S);let P;e[20]!==r?(P=pt("break-words w-full min-w-0",r),e[20]=r,e[21]=P):P=e[21];let _;e[22]!==p?(_=Ht(p),e[22]=p,e[23]=_):_=e[23];let O;e[24]!==_?(O=re.jsx("div",{className:_,"data-markdown-content":!0}),e[24]=_,e[25]=O):O=e[25];let W;return e[26]!==P||e[27]!==O?(W=re.jsx("div",{className:P,ref:k,children:O}),e[26]=P,e[27]=O,e[28]=W):W=e[28],W},Zs=C.memo($r,(t,e)=>{const n=t.mermaidControls??te,r=e.mermaidControls??te;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 Hr(t){cn(t)}function zr(t){dn(t)}function Vr(t){return t.openContextPreview}export{Xs as MarkdownRenderer,Zs as SimpleMarkdownRenderer};
@@ -1 +1 @@
1
- import{r as D,j as e,R as c,f as G}from"./vendor-react-BUCujlKS.js";import{f as J,B as U,X as z,g as me,O as Ce,h as ne,I as O}from"./useAppFontEffects-ZM9ij19-.js";import{P as W,cR as Ne,cO as le,cK as V,E as B,aw as H,e2 as Se,aD as ue,X as pe,h as X,aM as he,t as xe,U as re}from"./index-CvLgnuNI.js";import"./vendor-scheduler-7OC5HNn7.js";import"./vendor-zod-Gea9uBlY.js";import"./vendor-simplewebauthn-browser-VDA66rT_.js";import"./vendor-vite-runtime-DD1OZmLC.js";import"./vendor-zustand-BAGL70zf.js";import"./vendor-base-ui-CsXYnR5c.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-Bq3iTZ6r.js";import"./vendor-motion-dom-DcCgeG69.js";import"./vendor-motion-utils-BGh8QBgx.js";import"./vendor-tanstack-react-virtual-ClYN8CzB.js";import"./vendor-tanstack-virtual-core-BewVQryB.js";import"./contextPanelEmbeddedChat-CirXEPJq.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-U-lXzXNK.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-BuBPBC3R.js";import"./vendor-tailwind-merge-CPcsbTWB.js";import"./vendor-fuse.js-Dw8P0qyA.js";import"./vendor-opencode-client-_BAHQo4R.js";function Re(a){switch(a){case"ok":return null;case"auth":return"onboarding.remoteConnection.probe.authMessage";case"update-recommended":return"onboarding.remoteConnection.probe.updateRecommendedMessage";case"incompatible":return"onboarding.remoteConnection.probe.incompatibleMessage";case"wrong-service":return"onboarding.remoteConnection.probe.wrongServiceMessage";case"unreachable":return"onboarding.remoteConnection.probe.unreachableMessage";default:return null}}function oe(a){return a==="wrong-service"||a==="unreachable"||a==="incompatible"}function fe({onBack:a,showBackButton:t=!0,initialUrl:s="",initialLabel:i="",isRecoveryMode:n=!1,onConnect:l,onSwitchToLocal:u,showInstancePicker:r=!1}){const{t:o}=J(),[w,R]=D.useState(s),[j,T]=D.useState(i),[I,x]=D.useState("idle"),[m,k]=D.useState(null),[C,b]=D.useState(""),[N,K]=D.useState([]),[y,f]=D.useState(()=>r?"instances":"add"),[g,L]=D.useState("");D.useEffect(()=>{r&&W().then(h=>K(h.hosts)).catch(h=>{b(h instanceof Error?h.message:String(h))})},[r]);const S=Ne(w),A=S?.persistedUrl??null,E=D.useCallback(h=>{R(h.target.value),x("idle"),k(null),b("")},[]),F=D.useCallback(h=>{T(h.target.value)},[]),d=D.useCallback(async()=>{if(A){x("testing"),k(null),b("");try{const h=await le(A);k(h),x(h.status==="ok"||h.status==="update-recommended"?"success":"error")}catch(h){b(h instanceof Error?h.message:o("onboarding.remoteConnection.errors.connectionTestFailed")),x("error")}}},[A,o]),_=D.useCallback(async()=>{if(!S)return;const h=S.persistedUrl;x("testing"),k(null),b("");try{const M=await le(h);if(k(M),oe(M.status)){x("error");return}const Z=await W(),je=j.trim()||h,ee=Z.hosts.find(q=>q.url===h),te=ee?ee.id:`host-${Date.now().toString(16)}`,ie={id:te,label:je,url:h,apiUrl:h},ke=ee?Z.hosts.map(q=>q.id===te?ie:q):[...Z.hosts,ie];if(await V({hosts:ke,defaultHostId:te,initialHostChoiceCompleted:!0}),l?.(),S.redeemUrl){window.location.assign(S.redeemUrl);return}B()&&await H()}catch(M){b(M instanceof Error?M.message:o("onboarding.remoteConnection.errors.failedToSaveConnection")),x("error")}},[S,j,l,o]),$=D.useCallback(async h=>{const M=await W();await V({hosts:M.hosts,defaultHostId:h,initialHostChoiceCompleted:!0}),await H()},[]),p=D.useCallback(async()=>{x("testing"),b("");try{const h=await W(),M=await Se(g,h.hosts);await V({hosts:M.hosts,defaultHostId:M.hostId,initialHostChoiceCompleted:!0}),await H()}catch(h){b(h instanceof Error&&h.message==="invalid-connect-link"?o("settings.remoteInstances.direct.error.invalidConnectLink"):o("onboarding.remoteConnection.errors.failedToSaveConnection")),x("error")}},[g,o]),v=I==="testing",P=A!==null&&!v,Q=A!==null&&!v&&!oe(m?.status??null),Y=Re(m?.status??null),ye=m?.status==="ok",ve=m?.status==="update-recommended",we=m?.status==="auth",ae=oe(m?.status??null);return r&&y==="instances"?e.jsx("div",{className:"flex flex-col items-center justify-center h-full p-8",children:e.jsxs("div",{className:"w-full max-w-md space-y-6",children:[e.jsxs("div",{className:"space-y-2 text-center",children:[e.jsx("h1",{className:"typography-ui-header text-xl font-semibold text-foreground",children:o("desktopHostSwitcher.actions.switchInstance")}),e.jsx("p",{className:"text-muted-foreground text-sm",children:o("settings.remoteInstances.direct.description")})]}),C?e.jsx("div",{className:"text-sm text-[var(--status-error)]",children:C}):null,e.jsx("div",{className:"space-y-2",children:N.length===0?e.jsx("div",{className:"py-4 text-center text-sm text-muted-foreground",children:o("settings.remoteInstances.direct.state.empty")}):N.map(h=>e.jsx(U,{variant:"outline",className:"w-full justify-start",onClick:()=>{$(h.id)},children:e.jsx("span",{className:"min-w-0 truncate",children:h.label})},h.id))}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(U,{variant:"outline",className:"flex-1",onClick:()=>f("import"),children:o("settings.remoteInstances.direct.import.action")}),e.jsx(U,{className:"flex-1",onClick:()=>f("add"),children:o("settings.remoteInstances.direct.actions.add")})]})]})}):r&&y==="import"?e.jsx("div",{className:"flex flex-col items-center justify-center h-full p-8",children:e.jsxs("div",{className:"w-full max-w-md space-y-6",children:[e.jsx(U,{variant:"ghost",onClick:()=>f("instances"),className:"p-0 text-muted-foreground",children:o("onboarding.common.actions.back")}),e.jsxs("div",{className:"space-y-2 text-center",children:[e.jsx("h1",{className:"typography-ui-header text-xl font-semibold text-foreground",children:o("settings.remoteInstances.direct.import.action")}),e.jsx("p",{className:"text-muted-foreground text-sm",children:o("settings.remoteInstances.direct.import.description")})]}),e.jsx(z,{value:g,onChange:h=>L(h.target.value),placeholder:o("settings.remoteInstances.direct.import.placeholder"),disabled:v,autoFocus:!0}),C?e.jsx("div",{className:"text-sm text-[var(--status-error)]",children:C}):null,e.jsx(U,{onClick:()=>{p()},disabled:v||!g.trim(),children:o("settings.remoteInstances.direct.import.action")})]})}):e.jsx("div",{className:"flex flex-col items-center justify-center h-full p-8",children:e.jsxs("div",{className:"w-full max-w-md space-y-6",children:[(t||r)&&e.jsx("div",{className:"flex items-center",children:e.jsx(U,{variant:"ghost",onClick:r?()=>f("instances"):a,className:"p-0 text-muted-foreground hover:text-foreground",children:o("onboarding.common.actions.back")})}),e.jsxs("div",{className:"space-y-2 text-center",children:[e.jsx("h1",{className:"typography-ui-header text-xl font-semibold text-foreground",children:o(n?"onboarding.remoteConnection.titleRecovery":"onboarding.remoteConnection.title")}),e.jsx("p",{className:"text-muted-foreground text-sm",children:o("onboarding.remoteConnection.description")})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{htmlFor:"remote-url",className:"text-sm text-foreground",children:o("onboarding.remoteConnection.field.serverAddress")}),e.jsx(z,{id:"remote-url",type:"url",value:w,onChange:E,placeholder:o("onboarding.remoteConnection.field.serverAddressPlaceholder"),disabled:v})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{htmlFor:"remote-label",className:"text-sm text-foreground",children:o("onboarding.remoteConnection.field.nameOptional")}),e.jsx(z,{id:"remote-label",type:"text",value:j,onChange:F,placeholder:o("onboarding.remoteConnection.field.namePlaceholder"),disabled:v})]})]}),m&&ye&&e.jsx("div",{className:"rounded-lg border p-3 text-sm",style:{borderColor:"var(--status-success)",color:"var(--status-success)"},children:o("onboarding.remoteConnection.status.connectedSuccessfully",{latencyMs:m.latencyMs})}),m&&we&&e.jsx("div",{className:"rounded-lg border p-3 text-sm",style:{borderColor:"var(--status-warning)",color:"var(--status-warning)"},children:o("onboarding.remoteConnection.status.authWarning")}),m&&ve&&e.jsx("div",{className:"rounded-lg border p-3 text-sm",style:{borderColor:"var(--status-warning)",color:"var(--status-warning)"},children:Y?o(Y):null}),m&&ae&&e.jsxs("div",{className:"rounded-lg border p-3 text-sm space-y-3",style:{borderColor:"var(--status-error)",color:"var(--status-error)"},children:[e.jsxs("div",{children:[e.jsx("div",{className:"font-semibold mb-1",children:o("onboarding.remoteConnection.status.connectionFailed")}),e.jsx("div",{className:"opacity-90",children:Y?o(Y):null})]}),e.jsx("div",{className:"text-xs opacity-80",children:m.status==="unreachable"?o("onboarding.remoteConnection.status.suggestionsUnreachable"):o("onboarding.remoteConnection.status.suggestionsWrongService")})]}),C&&e.jsx("div",{className:"rounded-lg border p-3 text-sm",style:{borderColor:"var(--status-error)",color:"var(--status-error)"},children:C}),e.jsxs("div",{className:"flex gap-3",children:[e.jsx(U,{variant:"outline",onClick:d,disabled:!P,children:o(v?"onboarding.remoteConnection.actions.testing":"onboarding.remoteConnection.actions.testConnection")}),e.jsx(U,{onClick:_,disabled:!Q,children:o("onboarding.remoteConnection.actions.connectAndRestart")})]}),ae&&e.jsxs("div",{className:"flex flex-col gap-2 pt-2 border-t border-border",children:[e.jsx("div",{className:"text-xs text-muted-foreground text-center",children:o("onboarding.remoteConnection.actions.whatToDo")}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(U,{variant:"outline",size:"sm",onClick:a,className:"flex-1",children:o("onboarding.remoteConnection.actions.chooseDifferentServer")}),!n&&u&&e.jsx(U,{variant:"outline",size:"sm",onClick:u,className:"flex-1",children:o("onboarding.remoteConnection.actions.useLocalInstead")})]})]})]})})}const Le="curl -fsSL https://opencode.ai/v2/install | bash",ge="npm install -g @opencode/cli",Ue="https://opencode.ai/download",ce=2500;function Ie(a){const t=G.c(9),{windows:s,onCopy:i,copyTitle:n}=a;let l;t[0]!==s?(l=e.jsx("code",{className:"flex-1 min-w-0 text-left overflow-x-auto whitespace-nowrap",children:s?e.jsx("span",{style:{color:"var(--syntax-keyword)"},children:ge}):e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{color:"var(--syntax-keyword)"},children:"curl"}),e.jsx("span",{className:"text-muted-foreground",children:" -fsSL "}),e.jsx("span",{style:{color:"var(--syntax-string)"},children:"https://opencode.ai/v2/install"}),e.jsx("span",{className:"text-muted-foreground",children:" | "}),e.jsx("span",{style:{color:"var(--syntax-keyword)"},children:"bash"})]})}),t[0]=s,t[1]=l):l=t[1];let u;t[2]===Symbol.for("react.memo_cache_sentinel")?(u=e.jsx(O,{name:"file-copy",className:"h-4 w-4"}),t[2]=u):u=t[2];let r;t[3]!==n||t[4]!==i?(r=e.jsx("button",{onClick:i,className:"inline-flex items-center text-muted-foreground hover:text-foreground transition-colors shrink-0",title:n,"aria-label":n,children:u}),t[3]=n,t[4]=i,t[5]=r):r=t[5];let o;return t[6]!==l||t[7]!==r?(o=e.jsxs("div",{className:"flex items-center justify-between gap-3 w-full",children:[l,r]}),t[6]=l,t[7]=r,t[8]=o):o=t[8],o}function Te({onCliAvailable:a,localAvailable:t=!0}){const{t:s}=J(),[i,n]=c.useState(!1),[l,u]=c.useState(!1),[r,o]=c.useState(!1),[w,R]=c.useState(!1),[j,T]=c.useState(""),[I,x]=c.useState("unknown"),[m,k]=c.useState(()=>t?"local":"remote"),[C,b]=c.useState(!1),[N,K]=c.useState(!1);c.useEffect(()=>{u(B())},[]),c.useEffect(()=>{if(typeof navigator>"u"){x("unknown");return}const p=navigator.userAgent||"";/Windows/i.test(p)?x("windows"):/Macintosh|Mac OS X/i.test(p)?x("macos"):/Linux/i.test(p)?x("linux"):x("unknown")},[]),c.useEffect(()=>{let p=!1;return(async()=>{try{const v=await ue();if(!v||p)return;const P=v.opencodeBinary??"";P&&T(P)}catch{}})(),()=>{p=!0}},[]);const y=c.useCallback(async p=>{const v=p.target;v.closest(".app-region-no-drag")||v.closest("button, a, input, select, textarea, code, summary, details")||p.button===0&&l&&await pe()},[l]),f=c.useCallback(async()=>{try{const p=await X("/health");if(!p.ok)return!1;const v=await p.json();return v.openCodeRunning===!0||v.isOpenCodeReady===!0}catch{return!1}},[]),g=c.useCallback(async p=>{if(!l)return;const v=await W();await V({...v,...p==="local"?{defaultHostId:"local"}:{},initialHostChoiceCompleted:!0})},[l]),L=c.useCallback(async()=>{l&&await g("local"),a?.()},[l,a,g]);c.useEffect(()=>{if(!t||m!=="local")return;let p=!1,v=null;const P=async()=>{if(!p){try{const Q=await f();if(p)return;if(Q){await L();return}}catch{}p||(v=setTimeout(P,ce))}};return v=setTimeout(P,ce),()=>{p=!0,v&&clearTimeout(v)}},[m,f,L,t]);const S=c.useCallback(async()=>{R(!0);try{await f()&&await L()}finally{R(!1)}},[f,L]),A=c.useCallback(async()=>{if(!(typeof window>"u")&&l)try{const p=await he();p.success&&p.path&&p.path.trim().length>0&&T(p.path.trim())}catch{}},[l]),E=c.useCallback(async()=>{o(!0);try{if(await xe({opencodeBinary:j.trim()}),l){await g("local"),await H();return}await X("/api/config/reload",{method:"POST"})}finally{setTimeout(()=>o(!1),1e3)}},[l,j,g]),F=c.useCallback(async()=>{const p=await me(I==="windows"?ge:Le);p.ok?(n(!0),setTimeout(()=>n(!1),2e3)):console.error("Failed to copy:",p.error)},[I]),d=Ue,_=I==="windows"?"C:\\Users\\you\\AppData\\Roaming\\npm\\opencode.cmd":I==="linux"?"/home/you/.opencode/bin/opencode":"/Users/you/.opencode/bin/opencode",$=t&&(!l||m==="local");return e.jsx("div",{className:"app-region-drag h-full flex items-center justify-center bg-transparent p-8 cursor-default select-none overflow-y-auto",onMouseDown:y,children:e.jsxs("div",{className:"w-full max-w-md",children:[e.jsxs("header",{className:"flex flex-col items-center text-center",children:[e.jsx(Ce,{width:48,height:48}),e.jsx("h1",{className:"mt-6 text-xl font-semibold tracking-tight text-foreground",children:s("onboarding.chooser.title")}),e.jsx("p",{className:"mt-2 text-sm text-muted-foreground",children:s("onboarding.chooser.description")})]}),l&&t&&e.jsxs("div",{role:"tablist",className:"app-region-no-drag mt-7 flex gap-1 rounded-lg border border-border p-1",children:[e.jsx("button",{type:"button",role:"tab","aria-selected":m==="local",className:ne("flex-1 rounded-md px-3 py-1.5 text-sm transition-colors",m==="local"?"bg-[var(--interactive-selection)] text-[var(--interactive-selection-foreground)]":"text-muted-foreground hover:text-foreground"),onClick:()=>k("local"),children:s("onboarding.chooser.tabs.localInstall")}),e.jsx("button",{type:"button",role:"tab","aria-selected":m==="remote",className:ne("flex-1 rounded-md px-3 py-1.5 text-sm transition-colors",m==="remote"?"bg-[var(--interactive-selection)] text-[var(--interactive-selection-foreground)]":"text-muted-foreground hover:text-foreground"),onClick:()=>k("remote"),children:s("onboarding.chooser.tabs.connectRemote")})]}),l&&m==="remote"?e.jsx("div",{className:"app-region-no-drag mt-6",children:e.jsx(fe,{onBack:()=>t&&k("local"),showBackButton:!1,showInstancePicker:!t,onSwitchToLocal:t?()=>k("local"):void 0})}):null,$&&e.jsxs("div",{className:"mt-6",children:[I==="windows"&&e.jsxs("div",{className:"mb-4 rounded-lg border border-border p-4",children:[e.jsx("div",{className:"text-sm text-foreground",children:s("onboarding.localSetup.windows.title")}),e.jsxs("ol",{className:"mt-2 list-decimal space-y-1 pl-5 text-sm text-muted-foreground",children:[e.jsx("li",{children:s("onboarding.localSetup.windows.stepRunInstallInWsl")}),e.jsx("li",{children:s("onboarding.localSetup.windows.stepSetBinaryPath")})]})]}),e.jsx("p",{className:"text-center text-sm leading-relaxed text-muted-foreground text-balance",children:s("onboarding.localSetup.intro")}),e.jsx("div",{className:"app-region-no-drag mt-3 rounded-lg border border-border bg-background/60 px-4 py-3 font-mono text-sm",children:i?e.jsxs("div",{className:"flex items-center gap-2",style:{color:"var(--status-success)"},children:[e.jsx(O,{name:"check",className:"h-4 w-4"}),s("onboarding.common.status.copiedToClipboard")]}):e.jsx(Ie,{windows:I==="windows",onCopy:F,copyTitle:s("onboarding.common.copyToClipboard")})}),e.jsxs("div",{className:"app-region-no-drag mt-3 flex items-center gap-2.5 px-1",role:"status","aria-live":"polite",children:[e.jsx("span",{className:"relative inline-flex h-2 w-2 shrink-0","aria-hidden":!0,children:e.jsx("span",{className:"absolute inset-0 rounded-full",style:{backgroundColor:"var(--primary-base)",animation:"pulse-opacity 1.6s ease-in-out infinite"}})}),e.jsxs("span",{className:"min-w-0 flex-1 text-xs text-muted-foreground",children:[e.jsx("span",{className:"text-foreground",children:s("onboarding.localSetup.status.watching")})," · ",s("onboarding.localSetup.status.autoContinue")]}),e.jsx("button",{type:"button",onClick:S,disabled:w,className:"shrink-0 text-xs text-muted-foreground transition-colors hover:text-foreground disabled:opacity-50",children:s(w?"onboarding.localSetup.actions.checking":"onboarding.localSetup.actions.checkNow")})]}),e.jsxs("div",{className:"mt-6 divide-y divide-border/60 border-y border-border/60",children:[e.jsxs("details",{className:"app-region-no-drag group",open:C,onToggle:p=>b(p.currentTarget.open),children:[e.jsxs("summary",{className:"flex cursor-pointer list-none items-center justify-between py-3 text-sm text-muted-foreground transition-colors hover:text-foreground [&::-webkit-details-marker]:hidden",children:[e.jsx("span",{children:s("onboarding.localSetup.advanced.title")}),e.jsx(O,{name:"arrow-down-s",className:"h-4 w-4 transition-transform group-open:rotate-180"})]}),e.jsxs("div",{className:"space-y-2 pb-4",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsx(z,{value:j,onChange:p=>T(p.target.value),placeholder:_,disabled:r,className:"flex-1 font-mono text-xs"}),e.jsx(U,{type:"button",variant:"secondary",size:"sm",onClick:A,disabled:r||!l,children:s("onboarding.localSetup.actions.browse")}),e.jsx(U,{type:"button",size:"sm",onClick:E,disabled:r||!j.trim(),children:s("onboarding.localSetup.actions.apply")})]}),e.jsx("p",{className:"text-xs text-muted-foreground/70",children:s("onboarding.localSetup.helper.saveAndReload")})]})]}),e.jsxs("details",{className:"app-region-no-drag group",open:N,onToggle:p=>K(p.currentTarget.open),children:[e.jsxs("summary",{className:"flex cursor-pointer list-none items-center justify-between py-3 text-sm text-muted-foreground transition-colors hover:text-foreground [&::-webkit-details-marker]:hidden",children:[e.jsx("span",{children:s("onboarding.localSetup.troubleshoot.title")}),e.jsx(O,{name:"arrow-down-s",className:"h-4 w-4 transition-transform group-open:rotate-180"})]}),e.jsx("ul",{className:"list-disc space-y-1.5 pb-4 pl-4 text-xs text-muted-foreground",children:I==="windows"?e.jsx("li",{children:s("onboarding.localSetup.windows.hintDetectionFailed")}):e.jsxs(e.Fragment,{children:[e.jsx("li",{children:s("onboarding.localSetup.hint.ensurePath")}),e.jsx("li",{children:s("onboarding.localSetup.hint.setEnv")}),e.jsx("li",{children:s("onboarding.localSetup.hint.missingRuntime")})]})})]})]}),e.jsx("div",{className:"app-region-no-drag mt-5 text-center",children:e.jsxs("a",{href:d,target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-1 text-xs text-muted-foreground transition-colors hover:text-foreground",children:[s(I==="windows"?"onboarding.localSetup.docs.windows":"onboarding.localSetup.docs.default"),e.jsx(O,{name:"external-link",className:"h-3 w-3"})]})})]})]})})}const Ke="curl -fsSL https://opencode.ai/v2/install | bash",be="npm install -g @opencode/cli",De="https://opencode.ai/download";function _e(a){const t=G.c(9),{windows:s,onCopy:i,copyTitle:n}=a;let l;t[0]!==s?(l=e.jsx("code",{className:"flex-1 min-w-0 text-left overflow-x-auto whitespace-nowrap",children:s?e.jsx("span",{style:{color:"var(--syntax-keyword)"},children:be}):e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{color:"var(--syntax-keyword)"},children:"curl"}),e.jsx("span",{className:"text-muted-foreground",children:" -fsSL "}),e.jsx("span",{style:{color:"var(--syntax-string)"},children:"https://opencode.ai/v2/install"}),e.jsx("span",{className:"text-muted-foreground",children:" | "}),e.jsx("span",{style:{color:"var(--syntax-keyword)"},children:"bash"})]})}),t[0]=s,t[1]=l):l=t[1];let u;t[2]===Symbol.for("react.memo_cache_sentinel")?(u=e.jsx(O,{name:"file-copy",className:"h-4 w-4"}),t[2]=u):u=t[2];let r;t[3]!==n||t[4]!==i?(r=e.jsx("button",{onClick:i,className:"inline-flex items-center text-muted-foreground hover:text-foreground transition-colors",title:n,"aria-label":n,children:u}),t[3]=n,t[4]=i,t[5]=r):r=t[5];let o;return t[6]!==l||t[7]!==r?(o=e.jsxs("div",{className:"flex items-center justify-center gap-3",children:[l,r]}),t[6]=l,t[7]=r,t[8]=o):o=t[8],o}const Ae=3e4;function Oe({onBack:a,onCliAvailable:t,isFromRecovery:s=!1,onSwitchToRemote:i}){const{t:n}=J(),[l,u]=c.useState(!1),[r,o]=c.useState(!1),[w,R]=c.useState(!1),[j,T]=c.useState(!1),[I,x]=c.useState(!1),[m,k]=c.useState(null),[C,b]=c.useState(""),[N,K]=c.useState("unknown");c.useEffect(()=>{const d=setTimeout(()=>o(!0),Ae);return()=>clearTimeout(d)},[]),c.useEffect(()=>{R(B())},[]),c.useEffect(()=>{if(typeof navigator>"u"){K("unknown");return}const d=navigator.userAgent||"";if(/Windows/i.test(d)){K("windows");return}if(/Macintosh|Mac OS X/i.test(d)){K("macos");return}if(/Linux/i.test(d)){K("linux");return}K("unknown")},[]),c.useEffect(()=>{let d=!1;return(async()=>{try{const _=await ue();if(!_||d)return;const $=_.opencodeBinary??"";$&&b($)}catch{}})(),()=>{d=!0}},[]);const y=c.useCallback(async d=>{d.target.closest("button, a, input, select, textarea, code")||d.button===0&&w&&await pe()},[w]),f=c.useCallback(async()=>{try{const d=await X("/health");if(!d.ok)return!1;const _=await d.json();return _.openCodeRunning===!0||_.isOpenCodeReady===!0}catch{return!1}},[]),g=c.useCallback(async()=>{if(!(typeof window>"u")&&w)try{const d=await he();d.success&&d.path&&d.path.trim().length>0&&b(d.path.trim())}catch{}},[w]),L=c.useCallback(async()=>{T(!0);try{if(await xe({opencodeBinary:C.trim()}),w){await H();return}await X("/api/config/reload",{method:"POST"})}finally{setTimeout(()=>T(!1),1e3)}},[w,C]),S=c.useCallback(async()=>{const d=await me(N==="windows"?be:Ke);d.ok?(u(!0),setTimeout(()=>u(!1),2e3)):console.error("Failed to copy:",d.error)},[N]),A=c.useCallback(async()=>{x(!0),k(null);try{await f()?t?.():k(n("onboarding.localSetup.errors.cliNotReady"))}catch(d){k(d instanceof Error?d.message:n("onboarding.localSetup.errors.detectionFailed"))}finally{x(!1)}},[f,t,n]),E=De,F=N==="windows"?"C:\\Users\\you\\AppData\\Roaming\\npm\\opencode.cmd":N==="linux"?"/home/you/.opencode/bin/opencode":"/Users/you/.opencode/bin/opencode";return e.jsxs("div",{className:"h-full flex items-center justify-center bg-transparent p-8 relative cursor-default select-none",onMouseDown:y,children:[e.jsxs("div",{className:"w-full max-w-lg space-y-4 text-center",children:[e.jsx("div",{className:"flex items-center",children:e.jsx(U,{variant:"ghost",onClick:a,className:"p-0 text-muted-foreground hover:text-foreground",children:n("onboarding.common.actions.back")})}),e.jsxs("div",{className:"space-y-4",children:[e.jsx("h1",{className:"text-3xl font-semibold tracking-tight text-foreground",children:n("onboarding.localSetup.title")}),e.jsx("p",{className:"text-muted-foreground",children:n("onboarding.localSetup.description")})]}),N==="windows"&&e.jsxs("div",{className:"mx-auto max-w-2xl rounded-lg border border-border bg-background/50 p-4 text-left",children:[e.jsx("div",{className:"text-sm text-foreground",children:n("onboarding.localSetup.windows.title")}),e.jsxs("ol",{className:"mt-2 list-decimal space-y-1 pl-5 text-sm text-muted-foreground",children:[e.jsx("li",{children:n("onboarding.localSetup.windows.stepRunInstallInWsl")}),e.jsx("li",{children:n("onboarding.localSetup.windows.stepSetBinaryPath")})]})]}),e.jsx("div",{className:"flex justify-center",children:e.jsx("div",{className:"bg-background/60 backdrop-blur-sm border border-border rounded-lg px-5 py-3 font-mono text-sm w-fit",children:l?e.jsxs("div",{className:"flex items-center justify-center gap-2",style:{color:"var(--status-success)"},children:[e.jsx(O,{name:"check",className:"h-4 w-4"}),n("onboarding.common.status.copiedToClipboard")]}):e.jsx(_e,{windows:N==="windows",onCopy:S,copyTitle:n("onboarding.common.copyToClipboard")})})}),e.jsxs("a",{href:E,target:"_blank",rel:"noopener noreferrer",className:"text-sm text-muted-foreground hover:text-foreground transition-colors inline-flex items-center gap-1 justify-center",children:[n(N==="windows"?"onboarding.localSetup.docs.windows":"onboarding.localSetup.docs.default"),e.jsx(O,{name:"external-link",className:"h-3 w-3"})]}),m&&e.jsx("div",{className:"mx-auto max-w-md rounded-lg border border-destructive/50 bg-destructive/10 p-3 text-sm text-destructive",children:m}),e.jsxs("div",{className:"space-y-3",children:[e.jsx(U,{type:"button",onClick:A,disabled:I,className:"w-full max-w-xs",size:"lg",children:n(I?"onboarding.localSetup.actions.checking":"onboarding.localSetup.actions.checkAndContinue")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:n("onboarding.localSetup.helper.checkAndContinue")})]}),e.jsx("div",{className:"mx-auto w-full max-w-xl pt-4",children:e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"text-sm text-muted-foreground",children:n("onboarding.localSetup.field.alreadyInstalled")}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(z,{value:C,onChange:d=>b(d.target.value),placeholder:F,disabled:j,className:"flex-1 font-mono text-xs"}),e.jsx(U,{type:"button",variant:"secondary",onClick:g,disabled:j||!w,children:n("onboarding.localSetup.actions.browse")}),e.jsx(U,{type:"button",onClick:L,disabled:j,children:n("onboarding.localSetup.actions.apply")})]}),e.jsx("div",{className:"text-xs text-muted-foreground/70",children:n("onboarding.localSetup.helper.saveAndReload")})]})}),s&&i&&e.jsxs("div",{className:"text-center pt-4",children:[e.jsx("p",{className:"text-sm text-muted-foreground mb-2",children:n("onboarding.localSetup.remotePreference")}),e.jsx(U,{variant:"link",onClick:i,children:n("onboarding.localSetup.actions.connectRemoteServer")})]})]}),r&&e.jsx("div",{className:"absolute bottom-8 left-0 right-0 text-center space-y-1",children:N==="windows"?e.jsx(e.Fragment,{children:e.jsx("p",{className:"text-sm text-muted-foreground/70",children:n("onboarding.localSetup.windows.hintDetectionFailed")})}):e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-sm text-muted-foreground/70",children:n("onboarding.localSetup.hint.ensurePath")}),e.jsx("p",{className:"text-sm text-muted-foreground/70",children:n("onboarding.localSetup.hint.setEnv")}),e.jsx("p",{className:"text-sm text-muted-foreground/70",children:n("onboarding.localSetup.hint.missingRuntime")})]})})]})}function se(a,t){if(a?.trim())return re(a.trim());if(t)return re(t)}function Ee(a,t,s){switch(a){case"local-unavailable":return{title:"Local OpenCode Unavailable",description:"OpenCode CLI could not be started or is not installed. Install OpenCode or connect to a remote server instead.",titleKey:"onboarding.desktopRecovery.localUnavailable.title",descriptionKey:"onboarding.desktopRecovery.localUnavailable.description",iconKey:"local",showRetry:!0,retryLabel:"Retry Local",retryLabelKey:"onboarding.desktopRecovery.localUnavailable.retry",showUseLocal:!0,showUseRemote:!0,useLocalLabel:"Set Up Local",useLocalLabelKey:"onboarding.desktopRecovery.localUnavailable.useLocal",useRemoteLabel:"Use Remote",useRemoteLabelKey:"onboarding.desktopRecovery.common.useRemote"};case"remote-missing":return{title:"No Default Connection",description:"Your saved default connection could not be found. Choose how you want to connect.",titleKey:"onboarding.desktopRecovery.noDefaultConnection.title",descriptionKey:"onboarding.desktopRecovery.noDefaultConnection.description",iconKey:"local",showRetry:!1,showUseLocal:!0,showUseRemote:!0,useLocalLabel:"Use Local",useLocalLabelKey:"onboarding.desktopRecovery.common.useLocal",useRemoteLabel:"Use Remote",useRemoteLabelKey:"onboarding.desktopRecovery.common.useRemote"};case"remote-unreachable":{const i=se(t,s);return{title:"Remote Server Unreachable",description:`Could not connect to "${i||"the remote server"}". Check your network connection and verify the server address.`,titleKey:"onboarding.desktopRecovery.remoteUnreachable.title",descriptionKey:"onboarding.desktopRecovery.remoteUnreachable.description",descriptionParams:i?{host:i}:void 0,iconKey:"remote",showRetry:!0,retryLabel:"Retry Connection",retryLabelKey:"onboarding.desktopRecovery.remoteUnreachable.retry",showUseLocal:!0,showUseRemote:!0,useLocalLabel:"Use Local",useLocalLabelKey:"onboarding.desktopRecovery.common.useLocal",useRemoteLabel:"Use Remote",useRemoteLabelKey:"onboarding.desktopRecovery.common.useRemote"}}case"remote-wrong-service":{const i=se(t,s);return{title:"Incompatible Server",description:`The server at "${i||"unknown"}" is not running OpenChamber. Verify the address points to an OpenChamber server.`,titleKey:"onboarding.desktopRecovery.incompatibleServer.title",descriptionKey:"onboarding.desktopRecovery.incompatibleServer.description",descriptionParams:i?{host:i}:void 0,iconKey:"remote",showRetry:!1,showUseLocal:!0,showUseRemote:!0,useLocalLabel:"Use Local",useLocalLabelKey:"onboarding.desktopRecovery.common.useLocal",useRemoteLabel:"Use Remote",useRemoteLabelKey:"onboarding.desktopRecovery.common.useRemote"}}case"remote-incompatible":{const i=se(t,s);return{title:"Server Update Required",description:`The OpenChamber server at "${i||"unknown"}" is not compatible with this app version. Update OpenChamber on the server, then try again.`,titleKey:"onboarding.desktopRecovery.remoteIncompatible.title",descriptionKey:"onboarding.desktopRecovery.remoteIncompatible.description",descriptionParams:i?{host:i}:void 0,iconKey:"remote",showRetry:!0,retryLabel:"Retry Connection",retryLabelKey:"onboarding.desktopRecovery.remoteUnreachable.retry",showUseLocal:!0,showUseRemote:!0,useLocalLabel:"Use Local",useLocalLabelKey:"onboarding.desktopRecovery.common.useLocal",useRemoteLabel:"Use Remote",useRemoteLabelKey:"onboarding.desktopRecovery.common.useRemote"}}case"missing-default-host":return{title:"No Default Connection",description:"Your saved default connection could not be found. Choose how you want to connect.",titleKey:"onboarding.desktopRecovery.noDefaultConnection.title",descriptionKey:"onboarding.desktopRecovery.noDefaultConnection.description",iconKey:"local",showRetry:!1,showUseLocal:!0,showUseRemote:!0,useLocalLabel:"Use Local",useLocalLabelKey:"onboarding.desktopRecovery.common.useLocal",useRemoteLabel:"Use Remote",useRemoteLabelKey:"onboarding.desktopRecovery.common.useRemote"};default:{const i=a;throw new Error(`Unknown recovery variant: ${i}`)}}}function Me(a){switch(a){case"local":return e.jsx(O,{name:"macbook",className:"h-8 w-8"});case"remote":return e.jsx(O,{name:"server",className:"h-8 w-8"})}}function Fe({variant:a,hostLabel:t,hostUrl:s,onRetry:i,onUseLocal:n,onUseRemote:l,isRetrying:u=!1}){const{t:r}=J(),o=Ee(a,t,s),w=o.retryLabelKey??"onboarding.desktopRecovery.actions.retryConnection",R=c.useMemo(()=>{if(o.descriptionParams?.host)return o.descriptionParams;if(a==="remote-unreachable")return{host:r("onboarding.desktopRecovery.placeholders.remoteServer")};if(a==="remote-wrong-service"||a==="remote-incompatible")return{host:r("onboarding.desktopRecovery.placeholders.unknownServer")}},[o.descriptionParams,r,a]);return e.jsx("div",{className:"flex flex-col items-center justify-center h-full p-8",children:e.jsxs("div",{className:"w-full max-w-md space-y-6",children:[e.jsxs("div",{className:"flex flex-col items-center space-y-3 text-center",children:[e.jsx("div",{className:"p-3 rounded-full",style:{backgroundColor:"var(--status-warning)",opacity:.15},children:e.jsx("div",{style:{color:"var(--status-warning)"},children:Me(o.iconKey)})}),e.jsx("h1",{className:"typography-ui-header text-xl font-semibold text-foreground",children:r(o.titleKey)}),e.jsx("p",{className:"text-muted-foreground text-sm max-w-sm",children:r(o.descriptionKey,R)})]}),s&&(a==="remote-unreachable"||a==="remote-wrong-service"||a==="remote-incompatible")&&e.jsxs("div",{className:"rounded-lg border border-border bg-background/50 p-3",children:[e.jsx("div",{className:"text-xs text-muted-foreground mb-1",children:r("onboarding.remoteConnection.field.serverAddress")}),e.jsx("div",{className:"font-mono text-sm text-foreground truncate",children:re(s)})]}),e.jsxs("div",{className:"flex flex-col gap-2",children:[o.showRetry&&i&&e.jsxs(U,{onClick:i,disabled:u,className:"w-full",children:[e.jsx(O,{name:"refresh",className:ne("h-4 w-4",u&&"animate-spin")}),r(u?"onboarding.desktopRecovery.actions.retrying":w)]}),e.jsxs("div",{className:"flex gap-2",children:[o.showUseLocal&&n&&e.jsxs(U,{variant:"outline",onClick:n,disabled:u,className:"flex-1",children:[e.jsx(O,{name:"macbook",className:"h-4 w-4"}),r(o.useLocalLabelKey)]}),o.showUseRemote&&l&&e.jsxs(U,{variant:"outline",onClick:l,disabled:u,className:"flex-1",children:[e.jsx(O,{name:"server",className:"h-4 w-4"}),r(o.useRemoteLabelKey)]})]})]})]})})}function de(a,t){if(t==="use-remote")return{kind:"remote-form"};switch(a){case"local-unavailable":return{kind:"local-setup"};case"remote-unreachable":case"remote-incompatible":case"remote-wrong-service":case"remote-missing":case"missing-default-host":return{kind:"switch-default-to-local"};default:{const s=a;throw new Error(`Unhandled RecoveryVariant: ${s}`)}}}function He(a){const t=G.c(29),{variant:s,hostUrl:i,hostLabel:n,onRetry:l,onChooseRemote:u,showRemoteForm:r,onCloseRemoteForm:o,onSwitchToLocalFromRemote:w,onEnterLocalSetup:R,isRetrying:j,localAvailable:T}=a,I=r===void 0?!1:r,x=j===void 0?!1:j,m=T===void 0?!0:T,k=Pe;let C;t[0]!==l?(C=async()=>{if(B()){await H();return}await X("/api/config/reload",{method:"POST"}),l?.()},t[0]=l,t[1]=C):C=t[1];const b=C;let N;t[2]!==R||t[3]!==s?(N=async()=>{if(de(s,"use-local").kind==="local-setup"){R?.();return}if(await k("local"),B()){await H();return}window.location.reload()},t[2]=R,t[3]=s,t[4]=N):N=t[4];const K=N;let y;t[5]!==u||t[6]!==s?(y=()=>{de(s,"use-remote").kind==="remote-form"&&u?.()},t[5]=u,t[6]=s,t[7]=y):y=t[7];const f=y;if(I){const S=s==="remote-wrong-service"?"":i||"",A=s==="remote-wrong-service"?"":n||"";let E;t[8]!==u||t[9]!==o?(E=o||(()=>u?.()),t[8]=u,t[9]=o,t[10]=E):E=t[10];const F=!m;let d;t[11]!==m||t[12]!==R||t[13]!==w?(d=m?w||(()=>{k("local").then(()=>{B()?H():R?.()})}):void 0,t[11]=m,t[12]=R,t[13]=w,t[14]=d):d=t[14];let _;return t[15]!==A||t[16]!==S||t[17]!==E||t[18]!==F||t[19]!==d?(_=e.jsx(fe,{onBack:E,initialUrl:S,initialLabel:A,isRecoveryMode:!0,showInstancePicker:F,onSwitchToLocal:d}),t[15]=A,t[16]=S,t[17]=E,t[18]=F,t[19]=d,t[20]=_):_=t[20],_}const g=m?K:void 0;let L;return t[21]!==b||t[22]!==f||t[23]!==n||t[24]!==i||t[25]!==x||t[26]!==g||t[27]!==s?(L=e.jsx(Fe,{variant:s,hostLabel:n,hostUrl:i,onRetry:b,onUseLocal:g,onUseRemote:f,isRetrying:x}),t[21]=b,t[22]=f,t[23]=n,t[24]=i,t[25]=x,t[26]=g,t[27]=s,t[28]=L):L=t[28],L}async function Pe(a){if(!B())return;const t=await W();await V({...t,...a==="local"?{defaultHostId:"local"}:{},initialHostChoiceCompleted:!0})}function fo(a){const t=G.c(29),{onBack:s,onCliAvailable:i,mode:n,recoveryVariant:l,recoveryHostUrl:u,recoveryHostLabel:r,onEnterLocalSetup:o,localAvailable:w}=a,R=n===void 0?"first-launch":n,j=l===void 0?"missing-default-host":l,T=w===void 0?!0:w,[I,x]=c.useState(!1),[m,k]=c.useState(!1);let C;t[0]===Symbol.for("react.memo_cache_sentinel")?(C=()=>{k(!1),x(!1)},t[0]=C):C=t[0];let b;t[1]!==R||t[2]!==r||t[3]!==u||t[4]!==j?(b=[R,j,u,r],t[1]=R,t[2]=r,t[3]=u,t[4]=j,t[5]=b):b=t[5],c.useEffect(C,b);const N=m?"local-setup":R;if(N==="recovery"){let y;t[6]===Symbol.for("react.memo_cache_sentinel")?(y=()=>x(!0),t[6]=y):y=t[6];let f,g;t[7]===Symbol.for("react.memo_cache_sentinel")?(f=()=>x(!1),g=()=>{x(!1),k(!0)},t[7]=f,t[8]=g):(f=t[7],g=t[8]);let L;t[9]!==o?(L=()=>{k(!0),o?.()},t[9]=o,t[10]=L):L=t[10];let S;return t[11]!==T||t[12]!==r||t[13]!==u||t[14]!==j||t[15]!==I||t[16]!==L?(S=e.jsx(He,{variant:j,hostUrl:u,hostLabel:r,onChooseRemote:y,showRemoteForm:I,onCloseRemoteForm:f,onSwitchToLocalFromRemote:g,onEnterLocalSetup:L,localAvailable:T}),t[11]=T,t[12]=r,t[13]=u,t[14]=j,t[15]=I,t[16]=L,t[17]=S):S=t[17],S}if(N==="local-setup"){let y;t[18]!==s||t[19]!==m?(y=()=>{m?k(!1):s?.()},t[18]=s,t[19]=m,t[20]=y):y=t[20];let f;t[21]===Symbol.for("react.memo_cache_sentinel")?(f=()=>x(!0),t[21]=f):f=t[21];let g;return t[22]!==i||t[23]!==m||t[24]!==y?(g=e.jsx(Oe,{onBack:y,onCliAvailable:i,isFromRecovery:m,onSwitchToRemote:f}),t[22]=i,t[23]=m,t[24]=y,t[25]=g):g=t[25],g}let K;return t[26]!==T||t[27]!==i?(K=e.jsx(Te,{onCliAvailable:i,localAvailable:T}),t[26]=T,t[27]=i,t[28]=K):K=t[28],K}export{fo as OnboardingScreen};
1
+ import{r as D,j as e,R as c,f as G}from"./vendor-react-BUCujlKS.js";import{f as Q,B as U,X as V,g as me,O as Ce,h as ne,I as O}from"./useAppFontEffects-DDjuwVqi.js";import{Q as W,cU as Ne,cR as le,cN as z,F as B,ay as H,ec as Se,aF as ue,Y as pe,h as Y,aO as he,v as xe,V as re}from"./index-Di6zUe5h.js";import"./vendor-scheduler-7OC5HNn7.js";import"./vendor-zod-BSoePkpP.js";import"./vendor-simplewebauthn-browser-VDA66rT_.js";import"./vendor-vite-runtime-DD1OZmLC.js";import"./vendor-zustand-BAGL70zf.js";import"./vendor-base-ui-CsXYnR5c.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-tanstack-react-virtual-ClYN8CzB.js";import"./vendor-tanstack-virtual-core-BewVQryB.js";import"./vendor-framer-motion-Bq3iTZ6r.js";import"./vendor-motion-dom-DcCgeG69.js";import"./vendor-motion-utils-BGh8QBgx.js";import"./contextPanelEmbeddedChat-CirXEPJq.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-oKF0MAwd.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-BuBPBC3R.js";import"./vendor-tailwind-merge-CPcsbTWB.js";import"./vendor-fuse.js-Dw8P0qyA.js";import"./vendor-opencode-client-DSZl7jSi.js";function Re(a){switch(a){case"ok":return null;case"auth":return"onboarding.remoteConnection.probe.authMessage";case"update-recommended":return"onboarding.remoteConnection.probe.updateRecommendedMessage";case"incompatible":return"onboarding.remoteConnection.probe.incompatibleMessage";case"wrong-service":return"onboarding.remoteConnection.probe.wrongServiceMessage";case"unreachable":return"onboarding.remoteConnection.probe.unreachableMessage";default:return null}}function oe(a){return a==="wrong-service"||a==="unreachable"||a==="incompatible"}function fe({onBack:a,showBackButton:t=!0,initialUrl:s="",initialLabel:i="",isRecoveryMode:n=!1,onConnect:l,onSwitchToLocal:u,showInstancePicker:r=!1}){const{t:o}=Q(),[w,R]=D.useState(s),[j,T]=D.useState(i),[I,x]=D.useState("idle"),[m,k]=D.useState(null),[C,b]=D.useState(""),[N,K]=D.useState([]),[y,f]=D.useState(()=>r?"instances":"add"),[g,L]=D.useState("");D.useEffect(()=>{r&&W().then(h=>K(h.hosts)).catch(h=>{b(h instanceof Error?h.message:String(h))})},[r]);const S=Ne(w),A=S?.persistedUrl??null,E=D.useCallback(h=>{R(h.target.value),x("idle"),k(null),b("")},[]),M=D.useCallback(h=>{T(h.target.value)},[]),d=D.useCallback(async()=>{if(A){x("testing"),k(null),b("");try{const h=await le(A);k(h),x(h.status==="ok"||h.status==="update-recommended"?"success":"error")}catch(h){b(h instanceof Error?h.message:o("onboarding.remoteConnection.errors.connectionTestFailed")),x("error")}}},[A,o]),_=D.useCallback(async()=>{if(!S)return;const h=S.persistedUrl;x("testing"),k(null),b("");try{const F=await le(h);if(k(F),oe(F.status)){x("error");return}const Z=await W(),je=j.trim()||h,ee=Z.hosts.find(q=>q.url===h),te=ee?ee.id:`host-${Date.now().toString(16)}`,ie={id:te,label:je,url:h,apiUrl:h},ke=ee?Z.hosts.map(q=>q.id===te?ie:q):[...Z.hosts,ie];if(await z({hosts:ke,defaultHostId:te,initialHostChoiceCompleted:!0}),l?.(),S.redeemUrl){window.location.assign(S.redeemUrl);return}B()&&await H()}catch(F){b(F instanceof Error?F.message:o("onboarding.remoteConnection.errors.failedToSaveConnection")),x("error")}},[S,j,l,o]),$=D.useCallback(async h=>{const F=await W();await z({hosts:F.hosts,defaultHostId:h,initialHostChoiceCompleted:!0}),await H()},[]),p=D.useCallback(async()=>{x("testing"),b("");try{const h=await W(),F=await Se(g,h.hosts);await z({hosts:F.hosts,defaultHostId:F.hostId,initialHostChoiceCompleted:!0}),await H()}catch(h){b(h instanceof Error&&h.message==="invalid-connect-link"?o("settings.remoteInstances.direct.error.invalidConnectLink"):o("onboarding.remoteConnection.errors.failedToSaveConnection")),x("error")}},[g,o]),v=I==="testing",P=A!==null&&!v,J=A!==null&&!v&&!oe(m?.status??null),X=Re(m?.status??null),ye=m?.status==="ok",ve=m?.status==="update-recommended",we=m?.status==="auth",ae=oe(m?.status??null);return r&&y==="instances"?e.jsx("div",{className:"flex flex-col items-center justify-center h-full p-8",children:e.jsxs("div",{className:"w-full max-w-md space-y-6",children:[e.jsxs("div",{className:"space-y-2 text-center",children:[e.jsx("h1",{className:"typography-ui-header text-xl font-semibold text-foreground",children:o("desktopHostSwitcher.actions.switchInstance")}),e.jsx("p",{className:"text-muted-foreground text-sm",children:o("settings.remoteInstances.direct.description")})]}),C?e.jsx("div",{className:"text-sm text-[var(--status-error)]",children:C}):null,e.jsx("div",{className:"space-y-2",children:N.length===0?e.jsx("div",{className:"py-4 text-center text-sm text-muted-foreground",children:o("settings.remoteInstances.direct.state.empty")}):N.map(h=>e.jsx(U,{variant:"outline",className:"w-full justify-start",onClick:()=>{$(h.id)},children:e.jsx("span",{className:"min-w-0 truncate",children:h.label})},h.id))}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(U,{variant:"outline",className:"flex-1",onClick:()=>f("import"),children:o("settings.remoteInstances.direct.import.action")}),e.jsx(U,{className:"flex-1",onClick:()=>f("add"),children:o("settings.remoteInstances.direct.actions.add")})]})]})}):r&&y==="import"?e.jsx("div",{className:"flex flex-col items-center justify-center h-full p-8",children:e.jsxs("div",{className:"w-full max-w-md space-y-6",children:[e.jsx(U,{variant:"ghost",onClick:()=>f("instances"),className:"p-0 text-muted-foreground",children:o("onboarding.common.actions.back")}),e.jsxs("div",{className:"space-y-2 text-center",children:[e.jsx("h1",{className:"typography-ui-header text-xl font-semibold text-foreground",children:o("settings.remoteInstances.direct.import.action")}),e.jsx("p",{className:"text-muted-foreground text-sm",children:o("settings.remoteInstances.direct.import.description")})]}),e.jsx(V,{value:g,onChange:h=>L(h.target.value),placeholder:o("settings.remoteInstances.direct.import.placeholder"),disabled:v,autoFocus:!0}),C?e.jsx("div",{className:"text-sm text-[var(--status-error)]",children:C}):null,e.jsx(U,{onClick:()=>{p()},disabled:v||!g.trim(),children:o("settings.remoteInstances.direct.import.action")})]})}):e.jsx("div",{className:"flex flex-col items-center justify-center h-full p-8",children:e.jsxs("div",{className:"w-full max-w-md space-y-6",children:[(t||r)&&e.jsx("div",{className:"flex items-center",children:e.jsx(U,{variant:"ghost",onClick:r?()=>f("instances"):a,className:"p-0 text-muted-foreground hover:text-foreground",children:o("onboarding.common.actions.back")})}),e.jsxs("div",{className:"space-y-2 text-center",children:[e.jsx("h1",{className:"typography-ui-header text-xl font-semibold text-foreground",children:o(n?"onboarding.remoteConnection.titleRecovery":"onboarding.remoteConnection.title")}),e.jsx("p",{className:"text-muted-foreground text-sm",children:o("onboarding.remoteConnection.description")})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{htmlFor:"remote-url",className:"text-sm text-foreground",children:o("onboarding.remoteConnection.field.serverAddress")}),e.jsx(V,{id:"remote-url",type:"url",value:w,onChange:E,placeholder:o("onboarding.remoteConnection.field.serverAddressPlaceholder"),disabled:v})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{htmlFor:"remote-label",className:"text-sm text-foreground",children:o("onboarding.remoteConnection.field.nameOptional")}),e.jsx(V,{id:"remote-label",type:"text",value:j,onChange:M,placeholder:o("onboarding.remoteConnection.field.namePlaceholder"),disabled:v})]})]}),m&&ye&&e.jsx("div",{className:"rounded-lg border p-3 text-sm",style:{borderColor:"var(--status-success)",color:"var(--status-success)"},children:o("onboarding.remoteConnection.status.connectedSuccessfully",{latencyMs:m.latencyMs})}),m&&we&&e.jsx("div",{className:"rounded-lg border p-3 text-sm",style:{borderColor:"var(--status-warning)",color:"var(--status-warning)"},children:o("onboarding.remoteConnection.status.authWarning")}),m&&ve&&e.jsx("div",{className:"rounded-lg border p-3 text-sm",style:{borderColor:"var(--status-warning)",color:"var(--status-warning)"},children:X?o(X):null}),m&&ae&&e.jsxs("div",{className:"rounded-lg border p-3 text-sm space-y-3",style:{borderColor:"var(--status-error)",color:"var(--status-error)"},children:[e.jsxs("div",{children:[e.jsx("div",{className:"font-semibold mb-1",children:o("onboarding.remoteConnection.status.connectionFailed")}),e.jsx("div",{className:"opacity-90",children:X?o(X):null})]}),e.jsx("div",{className:"text-xs opacity-80",children:m.status==="unreachable"?o("onboarding.remoteConnection.status.suggestionsUnreachable"):o("onboarding.remoteConnection.status.suggestionsWrongService")})]}),C&&e.jsx("div",{className:"rounded-lg border p-3 text-sm",style:{borderColor:"var(--status-error)",color:"var(--status-error)"},children:C}),e.jsxs("div",{className:"flex gap-3",children:[e.jsx(U,{variant:"outline",onClick:d,disabled:!P,children:o(v?"onboarding.remoteConnection.actions.testing":"onboarding.remoteConnection.actions.testConnection")}),e.jsx(U,{onClick:_,disabled:!J,children:o("onboarding.remoteConnection.actions.connectAndRestart")})]}),ae&&e.jsxs("div",{className:"flex flex-col gap-2 pt-2 border-t border-border",children:[e.jsx("div",{className:"text-xs text-muted-foreground text-center",children:o("onboarding.remoteConnection.actions.whatToDo")}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(U,{variant:"outline",size:"sm",onClick:a,className:"flex-1",children:o("onboarding.remoteConnection.actions.chooseDifferentServer")}),!n&&u&&e.jsx(U,{variant:"outline",size:"sm",onClick:u,className:"flex-1",children:o("onboarding.remoteConnection.actions.useLocalInstead")})]})]})]})})}const Le="curl -fsSL https://opencode.ai/v2/install | bash",ge="npm install -g @opencode/cli",Ue="https://opencode.ai/download",ce=2500;function Ie(a){const t=G.c(9),{windows:s,onCopy:i,copyTitle:n}=a;let l;t[0]!==s?(l=e.jsx("code",{className:"flex-1 min-w-0 text-left overflow-x-auto whitespace-nowrap",children:s?e.jsx("span",{style:{color:"var(--syntax-keyword)"},children:ge}):e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{color:"var(--syntax-keyword)"},children:"curl"}),e.jsx("span",{className:"text-muted-foreground",children:" -fsSL "}),e.jsx("span",{style:{color:"var(--syntax-string)"},children:"https://opencode.ai/v2/install"}),e.jsx("span",{className:"text-muted-foreground",children:" | "}),e.jsx("span",{style:{color:"var(--syntax-keyword)"},children:"bash"})]})}),t[0]=s,t[1]=l):l=t[1];let u;t[2]===Symbol.for("react.memo_cache_sentinel")?(u=e.jsx(O,{name:"file-copy",className:"h-4 w-4"}),t[2]=u):u=t[2];let r;t[3]!==n||t[4]!==i?(r=e.jsx("button",{onClick:i,className:"inline-flex items-center text-muted-foreground hover:text-foreground transition-colors shrink-0",title:n,"aria-label":n,children:u}),t[3]=n,t[4]=i,t[5]=r):r=t[5];let o;return t[6]!==l||t[7]!==r?(o=e.jsxs("div",{className:"flex items-center justify-between gap-3 w-full",children:[l,r]}),t[6]=l,t[7]=r,t[8]=o):o=t[8],o}function Te({onCliAvailable:a,localAvailable:t=!0}){const{t:s}=Q(),[i,n]=c.useState(!1),[l,u]=c.useState(!1),[r,o]=c.useState(!1),[w,R]=c.useState(!1),[j,T]=c.useState(""),[I,x]=c.useState("unknown"),[m,k]=c.useState(()=>t?"local":"remote"),[C,b]=c.useState(!1),[N,K]=c.useState(!1);c.useEffect(()=>{u(B())},[]),c.useEffect(()=>{if(typeof navigator>"u"){x("unknown");return}const p=navigator.userAgent||"";/Windows/i.test(p)?x("windows"):/Macintosh|Mac OS X/i.test(p)?x("macos"):/Linux/i.test(p)?x("linux"):x("unknown")},[]),c.useEffect(()=>{let p=!1;return(async()=>{try{const v=await ue();if(!v||p)return;const P=v.opencodeBinary??"";P&&T(P)}catch{}})(),()=>{p=!0}},[]);const y=c.useCallback(async p=>{const v=p.target;v.closest(".app-region-no-drag")||v.closest("button, a, input, select, textarea, code, summary, details")||p.button===0&&l&&await pe()},[l]),f=c.useCallback(async()=>{try{const p=await Y("/health");if(!p.ok)return!1;const v=await p.json();return v.openCodeRunning===!0||v.isOpenCodeReady===!0}catch{return!1}},[]),g=c.useCallback(async p=>{if(!l)return;const v=await W();await z({...v,...p==="local"?{defaultHostId:"local"}:{},initialHostChoiceCompleted:!0})},[l]),L=c.useCallback(async()=>{l&&await g("local"),a?.()},[l,a,g]);c.useEffect(()=>{if(!t||m!=="local")return;let p=!1,v=null;const P=async()=>{if(!p){try{const J=await f();if(p)return;if(J){await L();return}}catch{}p||(v=setTimeout(P,ce))}};return v=setTimeout(P,ce),()=>{p=!0,v&&clearTimeout(v)}},[m,f,L,t]);const S=c.useCallback(async()=>{R(!0);try{await f()&&await L()}finally{R(!1)}},[f,L]),A=c.useCallback(async()=>{if(!(typeof window>"u")&&l)try{const p=await he();p.success&&p.path&&p.path.trim().length>0&&T(p.path.trim())}catch{}},[l]),E=c.useCallback(async()=>{o(!0);try{if(await xe({opencodeBinary:j.trim()}),l){await g("local"),await H();return}await Y("/api/config/reload",{method:"POST"})}finally{setTimeout(()=>o(!1),1e3)}},[l,j,g]),M=c.useCallback(async()=>{const p=await me(I==="windows"?ge:Le);p.ok?(n(!0),setTimeout(()=>n(!1),2e3)):console.error("Failed to copy:",p.error)},[I]),d=Ue,_=I==="windows"?"C:\\Users\\you\\AppData\\Roaming\\npm\\opencode.cmd":I==="linux"?"/home/you/.opencode/bin/opencode":"/Users/you/.opencode/bin/opencode",$=t&&(!l||m==="local");return e.jsx("div",{className:"app-region-drag h-full flex items-center justify-center bg-transparent p-8 cursor-default select-none overflow-y-auto",onMouseDown:y,children:e.jsxs("div",{className:"w-full max-w-md",children:[e.jsxs("header",{className:"flex flex-col items-center text-center",children:[e.jsx(Ce,{width:48,height:48}),e.jsx("h1",{className:"mt-6 text-xl font-semibold tracking-tight text-foreground",children:s("onboarding.chooser.title")}),e.jsx("p",{className:"mt-2 text-sm text-muted-foreground",children:s("onboarding.chooser.description")})]}),l&&t&&e.jsxs("div",{role:"tablist",className:"app-region-no-drag mt-7 flex gap-1 rounded-lg border border-border p-1",children:[e.jsx("button",{type:"button",role:"tab","aria-selected":m==="local",className:ne("flex-1 rounded-md px-3 py-1.5 text-sm transition-colors",m==="local"?"bg-[var(--interactive-selection)] text-[var(--interactive-selection-foreground)]":"text-muted-foreground hover:text-foreground"),onClick:()=>k("local"),children:s("onboarding.chooser.tabs.localInstall")}),e.jsx("button",{type:"button",role:"tab","aria-selected":m==="remote",className:ne("flex-1 rounded-md px-3 py-1.5 text-sm transition-colors",m==="remote"?"bg-[var(--interactive-selection)] text-[var(--interactive-selection-foreground)]":"text-muted-foreground hover:text-foreground"),onClick:()=>k("remote"),children:s("onboarding.chooser.tabs.connectRemote")})]}),l&&m==="remote"?e.jsx("div",{className:"app-region-no-drag mt-6",children:e.jsx(fe,{onBack:()=>t&&k("local"),showBackButton:!1,showInstancePicker:!t,onSwitchToLocal:t?()=>k("local"):void 0})}):null,$&&e.jsxs("div",{className:"mt-6",children:[I==="windows"&&e.jsxs("div",{className:"mb-4 rounded-lg border border-border p-4",children:[e.jsx("div",{className:"text-sm text-foreground",children:s("onboarding.localSetup.windows.title")}),e.jsxs("ol",{className:"mt-2 list-decimal space-y-1 pl-5 text-sm text-muted-foreground",children:[e.jsx("li",{children:s("onboarding.localSetup.windows.stepRunInstallInWsl")}),e.jsx("li",{children:s("onboarding.localSetup.windows.stepSetBinaryPath")})]})]}),e.jsx("p",{className:"text-center text-sm leading-relaxed text-muted-foreground text-balance",children:s("onboarding.localSetup.intro")}),e.jsx("div",{className:"app-region-no-drag mt-3 rounded-lg border border-border bg-background/60 px-4 py-3 font-mono text-sm",children:i?e.jsxs("div",{className:"flex items-center gap-2",style:{color:"var(--status-success)"},children:[e.jsx(O,{name:"check",className:"h-4 w-4"}),s("onboarding.common.status.copiedToClipboard")]}):e.jsx(Ie,{windows:I==="windows",onCopy:M,copyTitle:s("onboarding.common.copyToClipboard")})}),e.jsxs("div",{className:"app-region-no-drag mt-3 flex items-center gap-2.5 px-1",role:"status","aria-live":"polite",children:[e.jsx("span",{className:"relative inline-flex h-2 w-2 shrink-0","aria-hidden":!0,children:e.jsx("span",{className:"absolute inset-0 rounded-full",style:{backgroundColor:"var(--primary-base)",animation:"pulse-opacity 1.6s ease-in-out infinite"}})}),e.jsxs("span",{className:"min-w-0 flex-1 text-xs text-muted-foreground",children:[e.jsx("span",{className:"text-foreground",children:s("onboarding.localSetup.status.watching")})," · ",s("onboarding.localSetup.status.autoContinue")]}),e.jsx("button",{type:"button",onClick:S,disabled:w,className:"shrink-0 text-xs text-muted-foreground transition-colors hover:text-foreground disabled:opacity-50",children:s(w?"onboarding.localSetup.actions.checking":"onboarding.localSetup.actions.checkNow")})]}),e.jsxs("div",{className:"mt-6 divide-y divide-border/60 border-y border-border/60",children:[e.jsxs("details",{className:"app-region-no-drag group",open:C,onToggle:p=>b(p.currentTarget.open),children:[e.jsxs("summary",{className:"flex cursor-pointer list-none items-center justify-between py-3 text-sm text-muted-foreground transition-colors hover:text-foreground [&::-webkit-details-marker]:hidden",children:[e.jsx("span",{children:s("onboarding.localSetup.advanced.title")}),e.jsx(O,{name:"arrow-down-s",className:"h-4 w-4 transition-transform group-open:rotate-180"})]}),e.jsxs("div",{className:"space-y-2 pb-4",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsx(V,{value:j,onChange:p=>T(p.target.value),placeholder:_,disabled:r,className:"flex-1 font-mono text-xs"}),e.jsx(U,{type:"button",variant:"secondary",size:"sm",onClick:A,disabled:r||!l,children:s("onboarding.localSetup.actions.browse")}),e.jsx(U,{type:"button",size:"sm",onClick:E,disabled:r||!j.trim(),children:s("onboarding.localSetup.actions.apply")})]}),e.jsx("p",{className:"text-xs text-muted-foreground/70",children:s("onboarding.localSetup.helper.saveAndReload")})]})]}),e.jsxs("details",{className:"app-region-no-drag group",open:N,onToggle:p=>K(p.currentTarget.open),children:[e.jsxs("summary",{className:"flex cursor-pointer list-none items-center justify-between py-3 text-sm text-muted-foreground transition-colors hover:text-foreground [&::-webkit-details-marker]:hidden",children:[e.jsx("span",{children:s("onboarding.localSetup.troubleshoot.title")}),e.jsx(O,{name:"arrow-down-s",className:"h-4 w-4 transition-transform group-open:rotate-180"})]}),e.jsx("ul",{className:"list-disc space-y-1.5 pb-4 pl-4 text-xs text-muted-foreground",children:I==="windows"?e.jsx("li",{children:s("onboarding.localSetup.windows.hintDetectionFailed")}):e.jsxs(e.Fragment,{children:[e.jsx("li",{children:s("onboarding.localSetup.hint.ensurePath")}),e.jsx("li",{children:s("onboarding.localSetup.hint.setEnv")}),e.jsx("li",{children:s("onboarding.localSetup.hint.missingRuntime")})]})})]})]}),e.jsx("div",{className:"app-region-no-drag mt-5 text-center",children:e.jsxs("a",{href:d,target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-1 text-xs text-muted-foreground transition-colors hover:text-foreground",children:[s(I==="windows"?"onboarding.localSetup.docs.windows":"onboarding.localSetup.docs.default"),e.jsx(O,{name:"external-link",className:"h-3 w-3"})]})})]})]})})}const Ke="curl -fsSL https://opencode.ai/v2/install | bash",be="npm install -g @opencode/cli",De="https://opencode.ai/download";function _e(a){const t=G.c(9),{windows:s,onCopy:i,copyTitle:n}=a;let l;t[0]!==s?(l=e.jsx("code",{className:"flex-1 min-w-0 text-left overflow-x-auto whitespace-nowrap",children:s?e.jsx("span",{style:{color:"var(--syntax-keyword)"},children:be}):e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{color:"var(--syntax-keyword)"},children:"curl"}),e.jsx("span",{className:"text-muted-foreground",children:" -fsSL "}),e.jsx("span",{style:{color:"var(--syntax-string)"},children:"https://opencode.ai/v2/install"}),e.jsx("span",{className:"text-muted-foreground",children:" | "}),e.jsx("span",{style:{color:"var(--syntax-keyword)"},children:"bash"})]})}),t[0]=s,t[1]=l):l=t[1];let u;t[2]===Symbol.for("react.memo_cache_sentinel")?(u=e.jsx(O,{name:"file-copy",className:"h-4 w-4"}),t[2]=u):u=t[2];let r;t[3]!==n||t[4]!==i?(r=e.jsx("button",{onClick:i,className:"inline-flex items-center text-muted-foreground hover:text-foreground transition-colors",title:n,"aria-label":n,children:u}),t[3]=n,t[4]=i,t[5]=r):r=t[5];let o;return t[6]!==l||t[7]!==r?(o=e.jsxs("div",{className:"flex items-center justify-center gap-3",children:[l,r]}),t[6]=l,t[7]=r,t[8]=o):o=t[8],o}const Ae=3e4;function Oe({onBack:a,onCliAvailable:t,isFromRecovery:s=!1,onSwitchToRemote:i}){const{t:n}=Q(),[l,u]=c.useState(!1),[r,o]=c.useState(!1),[w,R]=c.useState(!1),[j,T]=c.useState(!1),[I,x]=c.useState(!1),[m,k]=c.useState(null),[C,b]=c.useState(""),[N,K]=c.useState("unknown");c.useEffect(()=>{const d=setTimeout(()=>o(!0),Ae);return()=>clearTimeout(d)},[]),c.useEffect(()=>{R(B())},[]),c.useEffect(()=>{if(typeof navigator>"u"){K("unknown");return}const d=navigator.userAgent||"";if(/Windows/i.test(d)){K("windows");return}if(/Macintosh|Mac OS X/i.test(d)){K("macos");return}if(/Linux/i.test(d)){K("linux");return}K("unknown")},[]),c.useEffect(()=>{let d=!1;return(async()=>{try{const _=await ue();if(!_||d)return;const $=_.opencodeBinary??"";$&&b($)}catch{}})(),()=>{d=!0}},[]);const y=c.useCallback(async d=>{d.target.closest("button, a, input, select, textarea, code")||d.button===0&&w&&await pe()},[w]),f=c.useCallback(async()=>{try{const d=await Y("/health");if(!d.ok)return!1;const _=await d.json();return _.openCodeRunning===!0||_.isOpenCodeReady===!0}catch{return!1}},[]),g=c.useCallback(async()=>{if(!(typeof window>"u")&&w)try{const d=await he();d.success&&d.path&&d.path.trim().length>0&&b(d.path.trim())}catch{}},[w]),L=c.useCallback(async()=>{T(!0);try{if(await xe({opencodeBinary:C.trim()}),w){await H();return}await Y("/api/config/reload",{method:"POST"})}finally{setTimeout(()=>T(!1),1e3)}},[w,C]),S=c.useCallback(async()=>{const d=await me(N==="windows"?be:Ke);d.ok?(u(!0),setTimeout(()=>u(!1),2e3)):console.error("Failed to copy:",d.error)},[N]),A=c.useCallback(async()=>{x(!0),k(null);try{await f()?t?.():k(n("onboarding.localSetup.errors.cliNotReady"))}catch(d){k(d instanceof Error?d.message:n("onboarding.localSetup.errors.detectionFailed"))}finally{x(!1)}},[f,t,n]),E=De,M=N==="windows"?"C:\\Users\\you\\AppData\\Roaming\\npm\\opencode.cmd":N==="linux"?"/home/you/.opencode/bin/opencode":"/Users/you/.opencode/bin/opencode";return e.jsxs("div",{className:"h-full flex items-center justify-center bg-transparent p-8 relative cursor-default select-none",onMouseDown:y,children:[e.jsxs("div",{className:"w-full max-w-lg space-y-4 text-center",children:[e.jsx("div",{className:"flex items-center",children:e.jsx(U,{variant:"ghost",onClick:a,className:"p-0 text-muted-foreground hover:text-foreground",children:n("onboarding.common.actions.back")})}),e.jsxs("div",{className:"space-y-4",children:[e.jsx("h1",{className:"text-3xl font-semibold tracking-tight text-foreground",children:n("onboarding.localSetup.title")}),e.jsx("p",{className:"text-muted-foreground",children:n("onboarding.localSetup.description")})]}),N==="windows"&&e.jsxs("div",{className:"mx-auto max-w-2xl rounded-lg border border-border bg-background/50 p-4 text-left",children:[e.jsx("div",{className:"text-sm text-foreground",children:n("onboarding.localSetup.windows.title")}),e.jsxs("ol",{className:"mt-2 list-decimal space-y-1 pl-5 text-sm text-muted-foreground",children:[e.jsx("li",{children:n("onboarding.localSetup.windows.stepRunInstallInWsl")}),e.jsx("li",{children:n("onboarding.localSetup.windows.stepSetBinaryPath")})]})]}),e.jsx("div",{className:"flex justify-center",children:e.jsx("div",{className:"bg-background/60 backdrop-blur-sm border border-border rounded-lg px-5 py-3 font-mono text-sm w-fit",children:l?e.jsxs("div",{className:"flex items-center justify-center gap-2",style:{color:"var(--status-success)"},children:[e.jsx(O,{name:"check",className:"h-4 w-4"}),n("onboarding.common.status.copiedToClipboard")]}):e.jsx(_e,{windows:N==="windows",onCopy:S,copyTitle:n("onboarding.common.copyToClipboard")})})}),e.jsxs("a",{href:E,target:"_blank",rel:"noopener noreferrer",className:"text-sm text-muted-foreground hover:text-foreground transition-colors inline-flex items-center gap-1 justify-center",children:[n(N==="windows"?"onboarding.localSetup.docs.windows":"onboarding.localSetup.docs.default"),e.jsx(O,{name:"external-link",className:"h-3 w-3"})]}),m&&e.jsx("div",{className:"mx-auto max-w-md rounded-lg border border-destructive/50 bg-destructive/10 p-3 text-sm text-destructive",children:m}),e.jsxs("div",{className:"space-y-3",children:[e.jsx(U,{type:"button",onClick:A,disabled:I,className:"w-full max-w-xs",size:"lg",children:n(I?"onboarding.localSetup.actions.checking":"onboarding.localSetup.actions.checkAndContinue")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:n("onboarding.localSetup.helper.checkAndContinue")})]}),e.jsx("div",{className:"mx-auto w-full max-w-xl pt-4",children:e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"text-sm text-muted-foreground",children:n("onboarding.localSetup.field.alreadyInstalled")}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(V,{value:C,onChange:d=>b(d.target.value),placeholder:M,disabled:j,className:"flex-1 font-mono text-xs"}),e.jsx(U,{type:"button",variant:"secondary",onClick:g,disabled:j||!w,children:n("onboarding.localSetup.actions.browse")}),e.jsx(U,{type:"button",onClick:L,disabled:j,children:n("onboarding.localSetup.actions.apply")})]}),e.jsx("div",{className:"text-xs text-muted-foreground/70",children:n("onboarding.localSetup.helper.saveAndReload")})]})}),s&&i&&e.jsxs("div",{className:"text-center pt-4",children:[e.jsx("p",{className:"text-sm text-muted-foreground mb-2",children:n("onboarding.localSetup.remotePreference")}),e.jsx(U,{variant:"link",onClick:i,children:n("onboarding.localSetup.actions.connectRemoteServer")})]})]}),r&&e.jsx("div",{className:"absolute bottom-8 left-0 right-0 text-center space-y-1",children:N==="windows"?e.jsx(e.Fragment,{children:e.jsx("p",{className:"text-sm text-muted-foreground/70",children:n("onboarding.localSetup.windows.hintDetectionFailed")})}):e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-sm text-muted-foreground/70",children:n("onboarding.localSetup.hint.ensurePath")}),e.jsx("p",{className:"text-sm text-muted-foreground/70",children:n("onboarding.localSetup.hint.setEnv")}),e.jsx("p",{className:"text-sm text-muted-foreground/70",children:n("onboarding.localSetup.hint.missingRuntime")})]})})]})}function se(a,t){if(a?.trim())return re(a.trim());if(t)return re(t)}function Ee(a,t,s){switch(a){case"local-unavailable":return{title:"Local OpenCode Unavailable",description:"OpenCode CLI could not be started or is not installed. Install OpenCode or connect to a remote server instead.",titleKey:"onboarding.desktopRecovery.localUnavailable.title",descriptionKey:"onboarding.desktopRecovery.localUnavailable.description",iconKey:"local",showRetry:!0,retryLabel:"Retry Local",retryLabelKey:"onboarding.desktopRecovery.localUnavailable.retry",showUseLocal:!0,showUseRemote:!0,useLocalLabel:"Set Up Local",useLocalLabelKey:"onboarding.desktopRecovery.localUnavailable.useLocal",useRemoteLabel:"Use Remote",useRemoteLabelKey:"onboarding.desktopRecovery.common.useRemote"};case"remote-missing":return{title:"No Default Connection",description:"Your saved default connection could not be found. Choose how you want to connect.",titleKey:"onboarding.desktopRecovery.noDefaultConnection.title",descriptionKey:"onboarding.desktopRecovery.noDefaultConnection.description",iconKey:"local",showRetry:!1,showUseLocal:!0,showUseRemote:!0,useLocalLabel:"Use Local",useLocalLabelKey:"onboarding.desktopRecovery.common.useLocal",useRemoteLabel:"Use Remote",useRemoteLabelKey:"onboarding.desktopRecovery.common.useRemote"};case"remote-unreachable":{const i=se(t,s);return{title:"Remote Server Unreachable",description:`Could not connect to "${i||"the remote server"}". Check your network connection and verify the server address.`,titleKey:"onboarding.desktopRecovery.remoteUnreachable.title",descriptionKey:"onboarding.desktopRecovery.remoteUnreachable.description",descriptionParams:i?{host:i}:void 0,iconKey:"remote",showRetry:!0,retryLabel:"Retry Connection",retryLabelKey:"onboarding.desktopRecovery.remoteUnreachable.retry",showUseLocal:!0,showUseRemote:!0,useLocalLabel:"Use Local",useLocalLabelKey:"onboarding.desktopRecovery.common.useLocal",useRemoteLabel:"Use Remote",useRemoteLabelKey:"onboarding.desktopRecovery.common.useRemote"}}case"remote-wrong-service":{const i=se(t,s);return{title:"Incompatible Server",description:`The server at "${i||"unknown"}" is not running OpenChamber. Verify the address points to an OpenChamber server.`,titleKey:"onboarding.desktopRecovery.incompatibleServer.title",descriptionKey:"onboarding.desktopRecovery.incompatibleServer.description",descriptionParams:i?{host:i}:void 0,iconKey:"remote",showRetry:!1,showUseLocal:!0,showUseRemote:!0,useLocalLabel:"Use Local",useLocalLabelKey:"onboarding.desktopRecovery.common.useLocal",useRemoteLabel:"Use Remote",useRemoteLabelKey:"onboarding.desktopRecovery.common.useRemote"}}case"remote-incompatible":{const i=se(t,s);return{title:"Server Update Required",description:`The OpenChamber server at "${i||"unknown"}" is not compatible with this app version. Update OpenChamber on the server, then try again.`,titleKey:"onboarding.desktopRecovery.remoteIncompatible.title",descriptionKey:"onboarding.desktopRecovery.remoteIncompatible.description",descriptionParams:i?{host:i}:void 0,iconKey:"remote",showRetry:!0,retryLabel:"Retry Connection",retryLabelKey:"onboarding.desktopRecovery.remoteUnreachable.retry",showUseLocal:!0,showUseRemote:!0,useLocalLabel:"Use Local",useLocalLabelKey:"onboarding.desktopRecovery.common.useLocal",useRemoteLabel:"Use Remote",useRemoteLabelKey:"onboarding.desktopRecovery.common.useRemote"}}case"missing-default-host":return{title:"No Default Connection",description:"Your saved default connection could not be found. Choose how you want to connect.",titleKey:"onboarding.desktopRecovery.noDefaultConnection.title",descriptionKey:"onboarding.desktopRecovery.noDefaultConnection.description",iconKey:"local",showRetry:!1,showUseLocal:!0,showUseRemote:!0,useLocalLabel:"Use Local",useLocalLabelKey:"onboarding.desktopRecovery.common.useLocal",useRemoteLabel:"Use Remote",useRemoteLabelKey:"onboarding.desktopRecovery.common.useRemote"};default:{const i=a;throw new Error(`Unknown recovery variant: ${i}`)}}}function Fe(a){switch(a){case"local":return e.jsx(O,{name:"macbook",className:"h-8 w-8"});case"remote":return e.jsx(O,{name:"server",className:"h-8 w-8"})}}function Me({variant:a,hostLabel:t,hostUrl:s,onRetry:i,onUseLocal:n,onUseRemote:l,isRetrying:u=!1}){const{t:r}=Q(),o=Ee(a,t,s),w=o.retryLabelKey??"onboarding.desktopRecovery.actions.retryConnection",R=c.useMemo(()=>{if(o.descriptionParams?.host)return o.descriptionParams;if(a==="remote-unreachable")return{host:r("onboarding.desktopRecovery.placeholders.remoteServer")};if(a==="remote-wrong-service"||a==="remote-incompatible")return{host:r("onboarding.desktopRecovery.placeholders.unknownServer")}},[o.descriptionParams,r,a]);return e.jsx("div",{className:"flex flex-col items-center justify-center h-full p-8",children:e.jsxs("div",{className:"w-full max-w-md space-y-6",children:[e.jsxs("div",{className:"flex flex-col items-center space-y-3 text-center",children:[e.jsx("div",{className:"p-3 rounded-full",style:{backgroundColor:"var(--status-warning)",opacity:.15},children:e.jsx("div",{style:{color:"var(--status-warning)"},children:Fe(o.iconKey)})}),e.jsx("h1",{className:"typography-ui-header text-xl font-semibold text-foreground",children:r(o.titleKey)}),e.jsx("p",{className:"text-muted-foreground text-sm max-w-sm",children:r(o.descriptionKey,R)})]}),s&&(a==="remote-unreachable"||a==="remote-wrong-service"||a==="remote-incompatible")&&e.jsxs("div",{className:"rounded-lg border border-border bg-background/50 p-3",children:[e.jsx("div",{className:"text-xs text-muted-foreground mb-1",children:r("onboarding.remoteConnection.field.serverAddress")}),e.jsx("div",{className:"font-mono text-sm text-foreground truncate",children:re(s)})]}),e.jsxs("div",{className:"flex flex-col gap-2",children:[o.showRetry&&i&&e.jsxs(U,{onClick:i,disabled:u,className:"w-full",children:[e.jsx(O,{name:"refresh",className:ne("h-4 w-4",u&&"animate-spin")}),r(u?"onboarding.desktopRecovery.actions.retrying":w)]}),e.jsxs("div",{className:"flex gap-2",children:[o.showUseLocal&&n&&e.jsxs(U,{variant:"outline",onClick:n,disabled:u,className:"flex-1",children:[e.jsx(O,{name:"macbook",className:"h-4 w-4"}),r(o.useLocalLabelKey)]}),o.showUseRemote&&l&&e.jsxs(U,{variant:"outline",onClick:l,disabled:u,className:"flex-1",children:[e.jsx(O,{name:"server",className:"h-4 w-4"}),r(o.useRemoteLabelKey)]})]})]})]})})}function de(a,t){if(t==="use-remote")return{kind:"remote-form"};switch(a){case"local-unavailable":return{kind:"local-setup"};case"remote-unreachable":case"remote-incompatible":case"remote-wrong-service":case"remote-missing":case"missing-default-host":return{kind:"switch-default-to-local"};default:{const s=a;throw new Error(`Unhandled RecoveryVariant: ${s}`)}}}function He(a){const t=G.c(29),{variant:s,hostUrl:i,hostLabel:n,onRetry:l,onChooseRemote:u,showRemoteForm:r,onCloseRemoteForm:o,onSwitchToLocalFromRemote:w,onEnterLocalSetup:R,isRetrying:j,localAvailable:T}=a,I=r===void 0?!1:r,x=j===void 0?!1:j,m=T===void 0?!0:T,k=Pe;let C;t[0]!==l?(C=async()=>{if(B()){await H();return}await Y("/api/config/reload",{method:"POST"}),l?.()},t[0]=l,t[1]=C):C=t[1];const b=C;let N;t[2]!==R||t[3]!==s?(N=async()=>{if(de(s,"use-local").kind==="local-setup"){R?.();return}if(await k("local"),B()){await H();return}window.location.reload()},t[2]=R,t[3]=s,t[4]=N):N=t[4];const K=N;let y;t[5]!==u||t[6]!==s?(y=()=>{de(s,"use-remote").kind==="remote-form"&&u?.()},t[5]=u,t[6]=s,t[7]=y):y=t[7];const f=y;if(I){const S=s==="remote-wrong-service"?"":i||"",A=s==="remote-wrong-service"?"":n||"";let E;t[8]!==u||t[9]!==o?(E=o||(()=>u?.()),t[8]=u,t[9]=o,t[10]=E):E=t[10];const M=!m;let d;t[11]!==m||t[12]!==R||t[13]!==w?(d=m?w||(()=>{k("local").then(()=>{B()?H():R?.()})}):void 0,t[11]=m,t[12]=R,t[13]=w,t[14]=d):d=t[14];let _;return t[15]!==A||t[16]!==S||t[17]!==E||t[18]!==M||t[19]!==d?(_=e.jsx(fe,{onBack:E,initialUrl:S,initialLabel:A,isRecoveryMode:!0,showInstancePicker:M,onSwitchToLocal:d}),t[15]=A,t[16]=S,t[17]=E,t[18]=M,t[19]=d,t[20]=_):_=t[20],_}const g=m?K:void 0;let L;return t[21]!==b||t[22]!==f||t[23]!==n||t[24]!==i||t[25]!==x||t[26]!==g||t[27]!==s?(L=e.jsx(Me,{variant:s,hostLabel:n,hostUrl:i,onRetry:b,onUseLocal:g,onUseRemote:f,isRetrying:x}),t[21]=b,t[22]=f,t[23]=n,t[24]=i,t[25]=x,t[26]=g,t[27]=s,t[28]=L):L=t[28],L}async function Pe(a){if(!B())return;const t=await W();await z({...t,...a==="local"?{defaultHostId:"local"}:{},initialHostChoiceCompleted:!0})}function fo(a){const t=G.c(29),{onBack:s,onCliAvailable:i,mode:n,recoveryVariant:l,recoveryHostUrl:u,recoveryHostLabel:r,onEnterLocalSetup:o,localAvailable:w}=a,R=n===void 0?"first-launch":n,j=l===void 0?"missing-default-host":l,T=w===void 0?!0:w,[I,x]=c.useState(!1),[m,k]=c.useState(!1);let C;t[0]===Symbol.for("react.memo_cache_sentinel")?(C=()=>{k(!1),x(!1)},t[0]=C):C=t[0];let b;t[1]!==R||t[2]!==r||t[3]!==u||t[4]!==j?(b=[R,j,u,r],t[1]=R,t[2]=r,t[3]=u,t[4]=j,t[5]=b):b=t[5],c.useEffect(C,b);const N=m?"local-setup":R;if(N==="recovery"){let y;t[6]===Symbol.for("react.memo_cache_sentinel")?(y=()=>x(!0),t[6]=y):y=t[6];let f,g;t[7]===Symbol.for("react.memo_cache_sentinel")?(f=()=>x(!1),g=()=>{x(!1),k(!0)},t[7]=f,t[8]=g):(f=t[7],g=t[8]);let L;t[9]!==o?(L=()=>{k(!0),o?.()},t[9]=o,t[10]=L):L=t[10];let S;return t[11]!==T||t[12]!==r||t[13]!==u||t[14]!==j||t[15]!==I||t[16]!==L?(S=e.jsx(He,{variant:j,hostUrl:u,hostLabel:r,onChooseRemote:y,showRemoteForm:I,onCloseRemoteForm:f,onSwitchToLocalFromRemote:g,onEnterLocalSetup:L,localAvailable:T}),t[11]=T,t[12]=r,t[13]=u,t[14]=j,t[15]=I,t[16]=L,t[17]=S):S=t[17],S}if(N==="local-setup"){let y;t[18]!==s||t[19]!==m?(y=()=>{m?k(!1):s?.()},t[18]=s,t[19]=m,t[20]=y):y=t[20];let f;t[21]===Symbol.for("react.memo_cache_sentinel")?(f=()=>x(!0),t[21]=f):f=t[21];let g;return t[22]!==i||t[23]!==m||t[24]!==y?(g=e.jsx(Oe,{onBack:y,onCliAvailable:i,isFromRecovery:m,onSwitchToRemote:f}),t[22]=i,t[23]=m,t[24]=y,t[25]=g):g=t[25],g}let K;return t[26]!==T||t[27]!==i?(K=e.jsx(Te,{onCliAvailable:i,localAvailable:T}),t[26]=T,t[27]=i,t[28]=K):K=t[28],K}export{fo as OnboardingScreen};
@@ -1 +1 @@
1
- import{k4 as k,k9 as j,kh as y}from"./useAppFontEffects-ZM9ij19-.js";import{k as D,a as C}from"./web-components-C583Pmfm.js";import{M as P,G as O,u as L,W as A,a as M,b as R,n as F,t as H}from"./Virtualizer-CZlLSacm.js";import{j as d,r as w}from"./vendor-react-BUCujlKS.js";import{V as _,F as N}from"./VirtualizedFileDiff-BfEBad09.js";function T({hunkIndex:e,lineIndex:t,conflictIndex:n}){return`merge-conflict-action-${e}-${t}-${n}`}function V(e,t){const n=t.hunks[e.hunkIndex];if(n!=null)return{hunkIndex:e.hunkIndex,lineIndex:z(n,e.startContentIndex)}}function z(e,t){let n=e.unifiedLineStart;for(let l=0;l<t;l++){const o=e.hunkContent[l];n+=o.type==="context"?o.lines:o.deletions+o.additions}return n}function U(e){const t=k(e);if(t.length!==1)throw console.error(t),new Error("PatchDiff: Provided patch must include only 1 patch, with 1 diff");const{files:n}=t[0];if(n.length!==1)throw console.error(n),new Error("FileDiff: Provided patch must contain exactly 1 file diff");return n[0]}function $({fileDiff:e,actions:t,renderCustomHeader:n,renderHeaderPrefix:l,renderHeaderFilenameSuffix:o,renderHeaderMetadata:x,renderAnnotation:f,renderGutterUtility:u,renderMergeConflictUtility:s,lineAnnotations:a,getHoveredLine:p,getInstance:m}){const g=n?.(e),c=l?.(e),i=o?.(e),v=x?.(e);return d.jsxs(d.Fragment,{children:[g!=null?d.jsx("div",{slot:j,children:g}):d.jsxs(d.Fragment,{children:[c!=null&&d.jsx("div",{slot:"header-prefix",children:c}),i!=null&&d.jsx("div",{slot:"header-filename-suffix",children:i}),v!=null&&d.jsx("div",{slot:"header-metadata",children:v})]}),f!=null&&a?.map((r,h)=>d.jsx("div",{slot:D(r),children:f(r)},h)),t!=null&&s!=null&&m!=null&&t.map(r=>{if(r==null)return;const h=b(r,e);return d.jsx("div",{slot:h,style:P,children:s(r,m)},h)}),u!=null&&d.jsx("div",{slot:"gutter-utility-slot",style:O,children:u(p)})]})}function b(e,t){const n=V(e,t);return n!=null?T({hunkIndex:n.hunkIndex,lineIndex:n.lineIndex,conflictIndex:e.conflictIndex}):void 0}const S=typeof window>"u"?w.useEffect:w.useLayoutEffect;function G({fileDiff:e,options:t,lineAnnotations:n,selectedLines:l,prerenderedHTML:o,metrics:x,hasGutterRenderUtility:f,hasCustomHeader:u,disableWorkerPool:s,contentEditable:a}){const p=L(),m=l!==void 0,g=w.useContext(A),c=M(),i=w.useRef(null),v=R(r=>{if(r!=null){if(i.current!=null)throw new Error("useFileDiffInstance: An instance should not already exist when a node is created");p!=null?i.current=new _(E({controlledSelection:m,contentEditable:a,hasCustomHeader:u,hasEditor:c!==void 0,hasGutterRenderUtility:f,options:t}),p,x,s?void 0:g,!0):i.current=new N(E({controlledSelection:m,contentEditable:a,hasCustomHeader:u,hasEditor:c!==void 0,hasGutterRenderUtility:f,options:t}),s?void 0:g,!0),i.current.hydrate({fileDiff:e,fileContainer:r,lineAnnotations:n,prerenderedHTML:o})}else{if(i.current==null)throw new Error("useFileDiffInstance: A FileDiff instance should exist when unmounting");i.current.cleanUp(),i.current=null}});return S(()=>{const{current:r}=i;if(r==null)return;const h=E({controlledSelection:m,contentEditable:a,hasCustomHeader:u,hasEditor:c!==void 0,hasGutterRenderUtility:f,options:t}),I=!C(r.options,h);r.setOptions(h),r.render({forceRender:I,fileDiff:e,lineAnnotations:n}),l!==void 0&&r.setSelectedLines(l)}),S(()=>{if(a&&i.current!=null){if(c===void 0)throw new Error("FileDiff: Editor is not attached");return c.edit(i.current)}},[a,c]),{ref:v,getHoveredLine:w.useCallback(()=>i.current?.getHoveredLine(),[])}}function E({options:e,controlledSelection:t,contentEditable:n,hasCustomHeader:l,hasEditor:o,hasGutterRenderUtility:x}){const f=n&&o,u=t||x||l;if(!u&&!f)return e;let s={...e};return u&&(s={...s,controlledSelection:t,renderCustomHeader:l?F:e?.renderCustomHeader,renderGutterUtility:x?F:e?.renderGutterUtility}),f&&(s={...s,useTokenTransformer:!0,enableGutterUtility:!1,enableLineSelection:!1,expandUnchanged:!0,lineHoverHighlight:"disabled"}),s}function X({patch:e,options:t,metrics:n,lineAnnotations:l,selectedLines:o,className:x,style:f,prerenderedHTML:u,renderAnnotation:s,renderCustomHeader:a,renderHeaderPrefix:p,renderHeaderFilenameSuffix:m,renderHeaderMetadata:g,renderGutterUtility:c,disableWorkerPool:i=!1,contentEditable:v=!1}){const r=q(e),{ref:h,getHoveredLine:I}=G({fileDiff:r,options:t,metrics:n,lineAnnotations:l,selectedLines:o,prerenderedHTML:u,hasGutterRenderUtility:c!=null,hasCustomHeader:a!=null,disableWorkerPool:i,contentEditable:v});return d.jsx(y,{ref:h,className:x,style:f,children:H($({fileDiff:r,renderCustomHeader:a,renderHeaderPrefix:p,renderHeaderFilenameSuffix:m,renderHeaderMetadata:g,renderAnnotation:s,lineAnnotations:l,renderGutterUtility:c,getHoveredLine:I}),u)})}function q(e){return w.useMemo(()=>U(e),[e])}export{X as P};
1
+ import{kf as S,kk as j,ks as y}from"./useAppFontEffects-DDjuwVqi.js";import{k as D,a as C}from"./web-components-Bc1WPd4i.js";import{M as P,G as O,u as L,W as A,a as M,b as R,n as F,t as H}from"./Virtualizer-CZlLSacm.js";import{j as d,r as w}from"./vendor-react-BUCujlKS.js";import{V as _,F as N}from"./VirtualizedFileDiff-ClDezf2d.js";function T({hunkIndex:e,lineIndex:t,conflictIndex:n}){return`merge-conflict-action-${e}-${t}-${n}`}function V(e,t){const n=t.hunks[e.hunkIndex];if(n!=null)return{hunkIndex:e.hunkIndex,lineIndex:z(n,e.startContentIndex)}}function z(e,t){let n=e.unifiedLineStart;for(let l=0;l<t;l++){const o=e.hunkContent[l];n+=o.type==="context"?o.lines:o.deletions+o.additions}return n}function U(e){const t=S(e);if(t.length!==1)throw console.error(t),new Error("PatchDiff: Provided patch must include only 1 patch, with 1 diff");const{files:n}=t[0];if(n.length!==1)throw console.error(n),new Error("FileDiff: Provided patch must contain exactly 1 file diff");return n[0]}function $({fileDiff:e,actions:t,renderCustomHeader:n,renderHeaderPrefix:l,renderHeaderFilenameSuffix:o,renderHeaderMetadata:x,renderAnnotation:f,renderGutterUtility:u,renderMergeConflictUtility:s,lineAnnotations:a,getHoveredLine:p,getInstance:m}){const g=n?.(e),c=l?.(e),i=o?.(e),v=x?.(e);return d.jsxs(d.Fragment,{children:[g!=null?d.jsx("div",{slot:j,children:g}):d.jsxs(d.Fragment,{children:[c!=null&&d.jsx("div",{slot:"header-prefix",children:c}),i!=null&&d.jsx("div",{slot:"header-filename-suffix",children:i}),v!=null&&d.jsx("div",{slot:"header-metadata",children:v})]}),f!=null&&a?.map((r,h)=>d.jsx("div",{slot:D(r),children:f(r)},h)),t!=null&&s!=null&&m!=null&&t.map(r=>{if(r==null)return;const h=b(r,e);return d.jsx("div",{slot:h,style:P,children:s(r,m)},h)}),u!=null&&d.jsx("div",{slot:"gutter-utility-slot",style:O,children:u(p)})]})}function b(e,t){const n=V(e,t);return n!=null?T({hunkIndex:n.hunkIndex,lineIndex:n.lineIndex,conflictIndex:e.conflictIndex}):void 0}const k=typeof window>"u"?w.useEffect:w.useLayoutEffect;function G({fileDiff:e,options:t,lineAnnotations:n,selectedLines:l,prerenderedHTML:o,metrics:x,hasGutterRenderUtility:f,hasCustomHeader:u,disableWorkerPool:s,contentEditable:a}){const p=L(),m=l!==void 0,g=w.useContext(A),c=M(),i=w.useRef(null),v=R(r=>{if(r!=null){if(i.current!=null)throw new Error("useFileDiffInstance: An instance should not already exist when a node is created");p!=null?i.current=new _(E({controlledSelection:m,contentEditable:a,hasCustomHeader:u,hasEditor:c!==void 0,hasGutterRenderUtility:f,options:t}),p,x,s?void 0:g,!0):i.current=new N(E({controlledSelection:m,contentEditable:a,hasCustomHeader:u,hasEditor:c!==void 0,hasGutterRenderUtility:f,options:t}),s?void 0:g,!0),i.current.hydrate({fileDiff:e,fileContainer:r,lineAnnotations:n,prerenderedHTML:o})}else{if(i.current==null)throw new Error("useFileDiffInstance: A FileDiff instance should exist when unmounting");i.current.cleanUp(),i.current=null}});return k(()=>{const{current:r}=i;if(r==null)return;const h=E({controlledSelection:m,contentEditable:a,hasCustomHeader:u,hasEditor:c!==void 0,hasGutterRenderUtility:f,options:t}),I=!C(r.options,h);r.setOptions(h),r.render({forceRender:I,fileDiff:e,lineAnnotations:n}),l!==void 0&&r.setSelectedLines(l)}),k(()=>{if(a&&i.current!=null){if(c===void 0)throw new Error("FileDiff: Editor is not attached");return c.edit(i.current)}},[a,c]),{ref:v,getHoveredLine:w.useCallback(()=>i.current?.getHoveredLine(),[])}}function E({options:e,controlledSelection:t,contentEditable:n,hasCustomHeader:l,hasEditor:o,hasGutterRenderUtility:x}){const f=n&&o,u=t||x||l;if(!u&&!f)return e;let s={...e};return u&&(s={...s,controlledSelection:t,renderCustomHeader:l?F:e?.renderCustomHeader,renderGutterUtility:x?F:e?.renderGutterUtility}),f&&(s={...s,useTokenTransformer:!0,enableGutterUtility:!1,enableLineSelection:!1,expandUnchanged:!0,lineHoverHighlight:"disabled"}),s}function X({patch:e,options:t,metrics:n,lineAnnotations:l,selectedLines:o,className:x,style:f,prerenderedHTML:u,renderAnnotation:s,renderCustomHeader:a,renderHeaderPrefix:p,renderHeaderFilenameSuffix:m,renderHeaderMetadata:g,renderGutterUtility:c,disableWorkerPool:i=!1,contentEditable:v=!1}){const r=q(e),{ref:h,getHoveredLine:I}=G({fileDiff:r,options:t,metrics:n,lineAnnotations:l,selectedLines:o,prerenderedHTML:u,hasGutterRenderUtility:c!=null,hasCustomHeader:a!=null,disableWorkerPool:i,contentEditable:v});return d.jsx(y,{ref:h,className:x,style:f,children:H($({fileDiff:r,renderCustomHeader:a,renderHeaderPrefix:p,renderHeaderFilenameSuffix:m,renderHeaderMetadata:g,renderAnnotation:s,lineAnnotations:l,renderGutterUtility:c,getHoveredLine:I}),u)})}function q(e){return w.useMemo(()=>U(e),[e])}export{X as P};
@@ -1,4 +1,4 @@
1
- import{R as $,j as F,c as we,r as l}from"./vendor-react-BUCujlKS.js";import{a as nt}from"./web-components-C583Pmfm.js";import{f as We}from"./computeVirtualFileMetrics-RF-KjfUH.js";import{V as rt,F as it}from"./VirtualizedFileDiff-BfEBad09.js";import{V as ot}from"./Virtualizer-D_a8gKmg.js";import{eE as st,eF as je,bj as at,c8 as lt,h as Be}from"./useAppFontEffects-ZM9ij19-.js";import{I as _e,a as ct,u as dt}from"./useInlineCommentController-CkfxMJPy.js";import"./index-CvLgnuNI.js";import{at as ut}from"./runtimeEndpointReset-DeaERc0M.js";import{ensurePierreThemeRegistered as Ve,getResolvedShikiTheme as Ue}from"./appThemeRegistry-DAdawJZn.js";const xe=n=>{if(n.type==="new"){const r=Math.min(n.selection.start,n.selection.end),i=Math.max(n.selection.start,n.selection.end);return`new-comment-${n.selection.side??"additions"}-${r}-${i}`}return`draft-${n.draft.id}`},ft=n=>{const{drafts:r,editingDraftId:i,selection:s}=n,c=[];for(const m of r){if(!Number.isFinite(m.endLine))continue;const x=Math.max(1,Math.floor(m.endLine)),M=m.side==="original"?"deletions":"additions";c.push({lineNumber:x,side:M,metadata:{type:m.id===i?"edit":"saved",draft:m}})}return s&&!i&&c.push({lineNumber:Math.max(s.start,s.end),side:s.side??"additions",metadata:{type:"new",selection:s}}),c};function ht(n){const r=n.trim();if(!r)return null;if(/^-?\d+(\.\d+)?$/.test(r)){const i=Number.parseFloat(r);return Number.isFinite(i)?i:null}if(r.endsWith("px")){const i=Number.parseFloat(r.slice(0,-2));return Number.isFinite(i)?i:null}return null}function Ke(n){if(!(!n||n<=0))return Math.max(200,Math.floor(n))}function pt(n){const{diffRootRef:r,drafts:i,selection:s,editingDraftId:c,commentText:m,onTextChange:x,fileLabel:M,onSave:d,onCancel:R,onEdit:z,onDelete:N}=n,[ue,W]=$.useState(0),[O,U]=$.useState(null),D=$.useMemo(()=>!s||c?null:xe({type:"new",selection:s}),[c,s]),Z=$.useMemo(()=>{const h=i.map(E=>xe({type:E.id===c?"edit":"saved",draft:E}));return D&&h.push(D),h},[i,c,D]),A=$.useCallback(h=>{const E=r.current;if(!E)return null;const T=E.querySelector("diffs-container");if(!(T instanceof HTMLElement))return null;const w=T.querySelector(`[data-annotation-id="${h}"]`);if(w instanceof HTMLElement)return w;const C=T.shadowRoot;return C?C.querySelector(`[data-annotation-id="${h}"]`):null},[r]);$.useEffect(()=>{if(Z.length===0)return;let h=!1,E=0;const T=12,w=()=>{h||Z.every(q=>!!A(q))||E>=T||(E+=1,requestAnimationFrame(()=>{h||(W(q=>q+1),w())}))};return w(),()=>{h=!0}},[Z,A]),$.useEffect(()=>{const h=r.current;if(!h)return;const E=()=>{const w=getComputedStyle(h),C=ht(w.getPropertyValue("--oc-context-panel-width")),q=h.getBoundingClientRect(),I=C??q.width;U(I>0?I:null)};E();const T=new ResizeObserver(()=>{E()});return T.observe(h),window.addEventListener("resize",E),()=>{T.disconnect(),window.removeEventListener("resize",E)}},[r]);const ee=$.useCallback(h=>{const T=r.current?.getBoundingClientRect(),w=h.closest("[data-annotation-content]"),C=w instanceof HTMLElement?w.getBoundingClientRect():h.getBoundingClientRect(),q=[C.width];T&&q.push(T.right-C.left);const I=q.filter(K=>Number.isFinite(K)&&K>0);return I.length>0?Ke(Math.min(...I)):Ke(O)},[r,O]);return F.jsxs(F.Fragment,{children:[i.map(h=>{const E=xe({type:h.id===c?"edit":"saved",draft:h}),T=A(E);if(!T)return null;const w=ee(T);return h.id===c?we.createPortal(F.jsx(_e,{initialText:m,onTextChange:x,fileLabel:M,lineRange:{start:h.startLine,end:h.endLine,side:h.side==="original"?"deletions":"additions"},isEditing:!0,onSave:d,onCancel:R,maxWidth:w}),T,`draft-edit-${h.id}`):we.createPortal(F.jsx(ct,{draft:h,onEdit:()=>z(h),onDelete:()=>N(h),maxWidth:w}),T,`draft-card-${h.id}`)}),s&&!c&&D&&(()=>{const h=A(D);if(!h)return null;const E=ee(h);return we.createPortal(F.jsx(_e,{initialText:m,onTextChange:x,fileLabel:M,lineRange:s,isEditing:!1,onSave:d,onCancel:R,maxWidth:E}),h,D)})()]})}const Ge=[],mt=`
1
+ import{R as $,j as F,c as we,r as l}from"./vendor-react-BUCujlKS.js";import{a as nt}from"./web-components-Bc1WPd4i.js";import{f as We}from"./computeVirtualFileMetrics-kM_zJNMt.js";import{V as rt,F as it}from"./VirtualizedFileDiff-ClDezf2d.js";import{V as ot}from"./Virtualizer-D_a8gKmg.js";import{eH as st,eI as je,bj as at,c8 as lt,h as Be}from"./useAppFontEffects-DDjuwVqi.js";import{I as _e,a as ct,u as dt}from"./useInlineCommentController-Clg8EO3A.js";import"./index-Di6zUe5h.js";import{ay as ut}from"./runtimeEndpointReset-D0PcCb3K.js";import{ensurePierreThemeRegistered as Ve,getResolvedShikiTheme as Ue}from"./appThemeRegistry-CiuyzfSW.js";const xe=n=>{if(n.type==="new"){const r=Math.min(n.selection.start,n.selection.end),i=Math.max(n.selection.start,n.selection.end);return`new-comment-${n.selection.side??"additions"}-${r}-${i}`}return`draft-${n.draft.id}`},ft=n=>{const{drafts:r,editingDraftId:i,selection:s}=n,c=[];for(const m of r){if(!Number.isFinite(m.endLine))continue;const x=Math.max(1,Math.floor(m.endLine)),M=m.side==="original"?"deletions":"additions";c.push({lineNumber:x,side:M,metadata:{type:m.id===i?"edit":"saved",draft:m}})}return s&&!i&&c.push({lineNumber:Math.max(s.start,s.end),side:s.side??"additions",metadata:{type:"new",selection:s}}),c};function ht(n){const r=n.trim();if(!r)return null;if(/^-?\d+(\.\d+)?$/.test(r)){const i=Number.parseFloat(r);return Number.isFinite(i)?i:null}if(r.endsWith("px")){const i=Number.parseFloat(r.slice(0,-2));return Number.isFinite(i)?i:null}return null}function Ke(n){if(!(!n||n<=0))return Math.max(200,Math.floor(n))}function pt(n){const{diffRootRef:r,drafts:i,selection:s,editingDraftId:c,commentText:m,onTextChange:x,fileLabel:M,onSave:d,onCancel:R,onEdit:z,onDelete:N}=n,[ue,W]=$.useState(0),[O,U]=$.useState(null),D=$.useMemo(()=>!s||c?null:xe({type:"new",selection:s}),[c,s]),Z=$.useMemo(()=>{const h=i.map(T=>xe({type:T.id===c?"edit":"saved",draft:T}));return D&&h.push(D),h},[i,c,D]),A=$.useCallback(h=>{const T=r.current;if(!T)return null;const E=T.querySelector("diffs-container");if(!(E instanceof HTMLElement))return null;const w=E.querySelector(`[data-annotation-id="${h}"]`);if(w instanceof HTMLElement)return w;const C=E.shadowRoot;return C?C.querySelector(`[data-annotation-id="${h}"]`):null},[r]);$.useEffect(()=>{if(Z.length===0)return;let h=!1,T=0;const E=12,w=()=>{h||Z.every(q=>!!A(q))||T>=E||(T+=1,requestAnimationFrame(()=>{h||(W(q=>q+1),w())}))};return w(),()=>{h=!0}},[Z,A]),$.useEffect(()=>{const h=r.current;if(!h)return;const T=()=>{const w=getComputedStyle(h),C=ht(w.getPropertyValue("--oc-context-panel-width")),q=h.getBoundingClientRect(),I=C??q.width;U(I>0?I:null)};T();const E=new ResizeObserver(()=>{T()});return E.observe(h),window.addEventListener("resize",T),()=>{E.disconnect(),window.removeEventListener("resize",T)}},[r]);const ee=$.useCallback(h=>{const E=r.current?.getBoundingClientRect(),w=h.closest("[data-annotation-content]"),C=w instanceof HTMLElement?w.getBoundingClientRect():h.getBoundingClientRect(),q=[C.width];E&&q.push(E.right-C.left);const I=q.filter(K=>Number.isFinite(K)&&K>0);return I.length>0?Ke(Math.min(...I)):Ke(O)},[r,O]);return F.jsxs(F.Fragment,{children:[i.map(h=>{const T=xe({type:h.id===c?"edit":"saved",draft:h}),E=A(T);if(!E)return null;const w=ee(E);return h.id===c?we.createPortal(F.jsx(_e,{initialText:m,onTextChange:x,fileLabel:M,lineRange:{start:h.startLine,end:h.endLine,side:h.side==="original"?"deletions":"additions"},isEditing:!0,onSave:d,onCancel:R,maxWidth:w}),E,`draft-edit-${h.id}`):we.createPortal(F.jsx(ct,{draft:h,onEdit:()=>z(h),onDelete:()=>N(h),maxWidth:w}),E,`draft-card-${h.id}`)}),s&&!c&&D&&(()=>{const h=A(D);if(!h)return null;const T=ee(h);return we.createPortal(F.jsx(_e,{initialText:m,onTextChange:x,fileLabel:M,lineRange:s,isEditing:!1,onSave:d,onCancel:R,maxWidth:T}),h,D)})()]})}const Ge=[],mt=`
2
2
  [data-gutter-buffer="annotation"] { min-height: 0; }
3
3
  [data-code] { min-height: 2.5rem; align-content: start; }
4
4
  `,Ye=5e5,gt=`
@@ -206,5 +206,5 @@ import{R as $,j as F,c as we,r as l}from"./vendor-react-BUCujlKS.js";import{a as
206
206
  `)),n.newObjectId??ke(n.additionLines.join(`
207
207
  `))].join(":");let d=!1;const R=()=>{d||(d=!0,ue(),clearTimeout(W))},z=()=>{d||(R(),x())},N=()=>{r.getDiffResultCache(n)&&z()},ue=r.subscribeToStatChanges(N),W=setTimeout(z,bt);return r.primeDiffHighlightCache(n),N(),R},[n,r]),i},wt=(n,r,i,s)=>{const c=s.side==="deletions",x=(i?(c?i.deletionLines:i.additionLines).join(""):c?n:r).split(`
208
208
  `),M=Math.min(s.start,s.end),d=Math.max(s.start,s.end),R=Math.max(1,M),z=Math.min(x.length,d);return R>z?"":x.slice(R-1,z).join(`
209
- `)},xt=(n,r)=>n===r?!0:!n||!r?!1:n.start===r.start&&n.end===r.end&&n.side===r.side,kt=n=>n==="auto"||n==="scroll"||n==="overlay",Rt=n=>{let r=n?.parentElement??null;for(;r;){const i=window.getComputedStyle(r);if(kt(i.overflowY))return r;r=r.parentElement}return null},St=(n,r)=>{if(!n||!r||typeof window>"u")return()=>{};const i=Rt(n);if(!i)return()=>{};const s=r.getBoundingClientRect().height;if(!s)return()=>{};const c=n.getBoundingClientRect().top-i.getBoundingClientRect().top,m=r.style.minHeight;r.style.minHeight=`${Math.ceil(s)}px`;let x=!1;return()=>{if(x)return;x=!0,r.style.minHeight=m;const d=n.getBoundingClientRect().top-i.getBoundingClientRect().top-c;d&&(i.scrollTop+=d)}},Lt=(n,r)=>{const i=n.find(R=>R instanceof HTMLElement&&R.hasAttribute("data-separator"));if(!i)return null;let s=i.nextElementSibling;for(;s&&!s.hasAttribute("data-line-index");)s=s.nextElementSibling;const[c,m]=s?.getAttribute("data-line-index")?.split(",")??[],x=Number.parseInt(c??"",10),M=Number.parseInt(m??"",10);if(Number.isNaN(x)||Number.isNaN(M))return null;const d=r.hunks.find(R=>R.unifiedLineStart<=x&&x<R.unifiedLineStart+R.unifiedLineCount&&R.splitLineStart<=M&&M<R.splitLineStart+R.splitLineCount);return d?{additionStart:d.additionStart,direction:i.hasAttribute("data-separator-first")?"down":"both"}:null},Ae=(n,r)=>{if(typeof window>"u")return()=>{};let i=null,s=null,c=!1;const m=()=>{c||(s?.disconnect(),s=null,i=window.requestAnimationFrame(()=>{i=window.requestAnimationFrame(()=>{c||r()})}))},x=()=>n.querySelector("diffs-container")?.shadowRoot??void 0,M=(d=x())=>!!d?.querySelector("[data-line]");return M()?m():typeof MutationObserver<"u"?(s=new MutationObserver(()=>{const d=x();if(d){if(M(d)){m();return}s?.disconnect(),s=new MutationObserver(()=>{M(d)&&m()}),s.observe(d,{childList:!0,subtree:!0})}}),s.observe(n,{childList:!0,subtree:!0})):i=window.requestAnimationFrame(m),()=>{c=!0,s?.disconnect(),i!==null&&window.cancelAnimationFrame(i)}},ve=new WeakMap,Et={lineHeight:24,hunkSeparatorHeight:24,spacing:0};function Tt(n){const r=n.closest("[data-diff-virtual-root]");if(r instanceof HTMLElement){const i=r.querySelector("[data-diff-virtual-content]");return{key:r,root:r,content:i instanceof HTMLElement?i:void 0}}return{key:document,root:document,content:void 0}}function Mt(n){if(typeof document>"u")return null;const r=Tt(n);let i=ve.get(r.key);if(!i){const c=new ot;c.setup(r.root,r.content),i={virtualizer:c,refs:0},ve.set(r.key,i)}i.refs+=1;let s=!1;return{virtualizer:i.virtualizer,root:r.root,release:()=>{if(s)return;s=!0;const c=ve.get(r.key);c&&(c.refs-=1,!(c.refs>0)&&(c.virtualizer.cleanUp(),ve.delete(r.key)))}}}const Pt=(n,r,i)=>{if(typeof window>"u")return()=>{};const s=[],c=()=>{try{n.rerender()}catch{}const m=r?.root;m instanceof HTMLElement?m.dispatchEvent(new Event("scroll",{bubbles:!1})):document.dispatchEvent(new Event("scroll",{bubbles:!1})),window.dispatchEvent(new Event("resize")),i()};return s.push(window.requestAnimationFrame(c)),s.push(window.requestAnimationFrame(()=>{s.push(window.requestAnimationFrame(c))})),()=>{for(const m of s)window.cancelAnimationFrame(m)}},Ot=({original:n,modified:r,fileDiff:i,language:s,fileName:c,renderSideBySide:m,wrapLines:x,layout:M="fill",enableComments:d=!0,hunkActions:R,onExpandContextRequest:z,pendingContextExpansion:N=null,contextLoading:ue=!1})=>{const W=st(),O=W?.currentTheme.metadata.variant==="dark",U=W?.availableThemes.find(e=>e.metadata.id===W.lightThemeId)??je(!1),D=W?.availableThemes.find(e=>e.metadata.id===W.darkThemeId)??je(!0),{isMobile:Z}=at(),A=R?.anchors??Ge,[ee,h]=$.useState(()=>({fileDiff:void 0,anchors:Ge,targets:new Map})),E=dt({source:"diff",fileLabel:c||"unknown",language:s,getCodeForRange:e=>wt(n,r,i,e),toStoreRange:e=>({startLine:e.start,endLine:e.end,side:e.side==="deletions"?"original":"modified"}),fromDraftRange:e=>({start:e.startLine,end:e.endLine,side:e.side==="original"?"deletions":"additions"})}),{drafts:T,selection:w,setSelection:C,commentText:q,setCommentText:I,editingDraftId:K,saveComment:Ie,cancel:Fe,startEdit:Je,deleteDraft:Qe}=E,fe=l.useRef(null),Y=l.useRef(null),re=l.useRef(""),j=l.useRef(!1),he=l.useRef(null);l.useEffect(()=>{fe.current=w},[w]),l.useEffect(()=>{Y.current=K},[K]),l.useEffect(()=>{re.current=q},[q]);const pe=l.useCallback(e=>{if(!d||j.current)return;const t=fe.current;if(!(!e&&t&&re.current.trim())){if(Z&&t&&e&&e.side===t.side){const o=Math.min(t.start,e.start),a=Math.max(t.end,e.end);C({...e,start:o,end:a})}else C(e);e&&(Y.current||I(""))}},[d,Z,I,C]),Ze=l.useCallback(()=>{Fe()},[Fe]),Ne=l.useCallback(e=>{const t=document.createElement("div");if(t.style.position="relative",e.metadata.type==="hunk-action")return t.dataset.hunkActionTarget=String(e.metadata.index),t.style.height="0px",t;const o=xe(e.metadata);return t.dataset.annotationId=o,t.dataset.annotationSide=e.side,t.dataset.annotationLine=String(e.lineNumber),t},[]),De=l.useCallback((e,t,o)=>{const a=new Map;if(o!=="unmount"){const u=Number.parseFloat(getComputedStyle(document.documentElement).fontSize)*2,b=new Map,S=[];for(const k of e.shadowRoot?.querySelectorAll("slot")??[])for(const P of k.assignedElements()){const v=P.querySelector("[data-hunk-action-target]"),f=Number(v?.dataset.hunkActionTarget);if(!v||!Number.isInteger(f)||f<0)continue;a.set(f,v);const p=k.closest("[data-code]");if(!p)continue;let y=b.get(p);y||(y=p.getBoundingClientRect(),b.set(p,y));const G=v.getBoundingClientRect().top,ce=Math.max(y.top+4,Math.min(G+4,y.bottom-u-4));S.push({target:v,offset:ce-G})}for(const{target:k,offset:P}of S){const v=`${P}px`;k.style.getPropertyValue("--oc-hunk-action-offset")!==v&&k.style.setProperty("--oc-hunk-action-offset",v)}}const g=t.fileDiff;h(u=>u.fileDiff===g&&u.anchors===A&&u.targets.size===a.size&&[...a].every(([b,S])=>u.targets.get(b)===S)?u:{fileDiff:g,anchors:A,targets:a})},[A]),et=l.useCallback((e,t)=>{Ie(e,t??w??void 0)},[Ie,w]),X=l.useCallback(e=>{C(e);const t=H.current;if(t)try{j.current=!0,t.setSelectedLines(e),he.current=e}catch{}finally{j.current=!1}},[C]),ie=l.useRef(null),Re=l.useRef(null);l.useEffect(()=>{if(!d)return;const e=ne.current;if(!e)return;const t=()=>{const f=e.querySelector("diffs-container");return f instanceof HTMLElement?f.shadowRoot:null},o=f=>{const p=e.querySelector("diffs-container");p instanceof HTMLElement&&(f?p.setAttribute("data-oc-comment-drag",""):p.removeAttribute("data-oc-comment-drag"))},a=(f,p)=>{const G=t()?.elementFromPoint(f,p)??document.elementFromPoint(f,p);if(!(G instanceof Element))return null;const ce=!!G.closest("[data-column-number]"),de=G.closest("[data-line]");if(!(de instanceof HTMLElement))return null;const Ce=Number.parseInt(de.getAttribute("data-line")??"",10);if(!Number.isFinite(Ce)||Ce<=0)return null;const tt=de.getAttribute("data-line-type")==="change-deletion"||de.closest("[data-code][data-deletions]")!=null?"deletions":"additions";return{line:Ce,side:tt,numberColumn:ce}};let g=null,u=!1,b=null;const S=f=>{ie.current=f;const p=H.current;if(p)try{j.current=!0,p.setSelectedLines(f)}catch{}finally{j.current=!1}},k=f=>{if(f.button!==0||f.pointerType!=="mouse")return;const p=a(f.clientX,f.clientY);if(!p||p.numberColumn){g=null;return}g={line:p.line,side:p.side},u=!1,b=f.pointerId},P=f=>{if(g==null||f.pointerId!==b)return;const p=a(f.clientX,f.clientY);if(p){if(!u){if(p.line===g.line)return;u=!0,o(!0),window.getSelection()?.removeAllRanges();const y=t();y&&"getSelection"in y&&y.getSelection()?.removeAllRanges()}S({start:Math.min(g.line,p.line),end:Math.max(g.line,p.line),side:g.side})}},v=f=>{if(g==null||f.pointerId!==b)return;const p=u;if(g=null,u=!1,b=null,o(!1),!p)return;const y=ie.current;ie.current=null,y&&(fe.current&&re.current.trim()&&!Y.current||(X(y),Y.current||I("")))};return e.addEventListener("pointerdown",k),document.addEventListener("pointermove",P,{passive:!0}),document.addEventListener("pointerup",v),()=>{e.removeEventListener("pointerdown",k),document.removeEventListener("pointermove",P),document.removeEventListener("pointerup",v),o(!1)}},[X,d,I]);const He=l.useCallback(e=>{if(!d)return;const t=ie.current,o=t&&e.start>=t.start&&e.end<=t.end&&(e.side==null||e.side===t.side);Re.current!==null&&(window.clearTimeout(Re.current),Re.current=null),ie.current=null,X(o&&t?t:e),Y.current||I("")},[X,d,I]),ze=l.useCallback(e=>{if(!d||e.numberColumn||window.getSelection()?.toString().trim())return;const t=e.annotationSide,o={start:e.lineNumber,end:e.lineNumber,side:t},a=fe.current;if(a&&a.start===o.start&&a.end===o.end&&a.side===o.side){if(!re.current.trim()){C(null);const g=H.current;try{j.current=!0,g?.setSelectedLines(null)}finally{j.current=!1}}return}a&&re.current.trim()&&!Y.current||(X(o),Y.current||I(""))},[X,d,I,C]),qe=l.useCallback(e=>{const t=e.closest("[data-line-type]")?.getAttribute("data-line-type")??e.getAttribute("data-line-type");if(t==="change-deletion")return"deletions";if(t==="change-addition")return"additions";const o=e.getAttribute("data-column-side")??e.getAttribute("data-side")??e.closest("[data-column-side]")?.getAttribute("data-column-side");if(o==="deletions"||o==="left"||o==="original")return"deletions";if(o==="additions"||o==="right"||o==="modified")return"additions";const a=e.closest("[data-line-type]");if(a instanceof HTMLElement){const g=a.getBoundingClientRect(),u=e.getBoundingClientRect(),b=g.left+g.width/2;return u.left+u.width/2<b?"deletions":"additions"}return"additions"},[]);Ve(U),Ve(D);const te=`${U.metadata.id}:${D.metadata.id}:${O?"dark":"light"}`,oe=l.useMemo(()=>{if(i){const e=i.deletionLines.reduce((o,a)=>o+a.length,0),t=i.additionLines.reduce((o,a)=>o+a.length,0);return Math.max(e,t)>Ye}return Math.max(n.length,r.length)>Ye},[i,r.length,n.length]),ne=l.useRef(null),B=l.useRef(null),H=l.useRef(null),se=l.useRef(null),Se=l.useRef(null),Le=l.useRef(null),Ee=l.useRef(void 0),me=l.useRef(void 0),ge=l.useRef(void 0),ye=l.useRef(void 0),[,Te]=$.useReducer(e=>e+1,0),J=ut(oe?"unified":m?"split":"unified"),L=vt(i,J),_=l.useMemo(()=>Ue(U),[U]),V=l.useMemo(()=>Ue(D),[D]);$.useLayoutEffect(()=>{const e=ne.current;if(!e)return;const t=e.querySelector("diffs-container");if(!t)return;const o=O?V:_,a=(G,ce)=>G.colors?.[ce],g=a(_,"terminal.ansiGreen"),u=a(_,"terminal.ansiRed"),b=a(_,"terminal.ansiBlue"),S=a(V,"terminal.ansiGreen"),k=a(V,"terminal.ansiRed"),P=a(V,"terminal.ansiBlue");t.style.setProperty("--shiki-light",_.fg),t.style.setProperty("--shiki-light-bg",_.bg),g&&t.style.setProperty("--shiki-light-addition-color",g),u&&t.style.setProperty("--shiki-light-deletion-color",u),b&&t.style.setProperty("--shiki-light-modified-color",b),t.style.setProperty("--shiki-dark",V.fg),t.style.setProperty("--shiki-dark-bg",V.bg),S&&t.style.setProperty("--shiki-dark-addition-color",S),k&&t.style.setProperty("--shiki-dark-deletion-color",k),P&&t.style.setProperty("--shiki-dark-modified-color",P),t.style.setProperty("--diffs-bg",o.bg),t.style.setProperty("--diffs-fg",o.fg);const v=O?S:g,f=O?k:u,p=O?P:b;v&&t.style.setProperty("--diffs-addition-color-override",v),f&&t.style.setProperty("--diffs-deletion-color-override",f),p&&t.style.setProperty("--diffs-modified-color-override",p);const y=t.shadowRoot?.querySelector("pre");y&&(y.style.setProperty("--shiki-light",_.fg),y.style.setProperty("--shiki-light-bg",_.bg),g&&y.style.setProperty("--shiki-light-addition-color",g),u&&y.style.setProperty("--shiki-light-deletion-color",u),b&&y.style.setProperty("--shiki-light-modified-color",b),y.style.setProperty("--shiki-dark",V.fg),y.style.setProperty("--shiki-dark-bg",V.bg),S&&y.style.setProperty("--shiki-dark-addition-color",S),k&&y.style.setProperty("--shiki-dark-deletion-color",k),P&&y.style.setProperty("--shiki-dark-modified-color",P),y.style.setProperty("--diffs-bg",o.bg),y.style.setProperty("--diffs-fg",o.fg),v&&y.style.setProperty("--diffs-addition-color-override",v),f&&y.style.setProperty("--diffs-deletion-color-override",f),p&&y.style.setProperty("--diffs-modified-color-override",p))},[V,te,O,_]);const Q=l.useMemo(()=>({theme:{dark:D.metadata.id,light:U.metadata.id},themeType:O?"dark":"light",diffStyle:m?"split":"unified",diffIndicators:"none",hunkSeparators:"line-info-basic",lineDiffType:"none",maxLineDiffLength:oe?0:1e3,maxLineLengthForHighlighting:oe?1:1e3,tokenizeMaxLineLength:oe?1:1e3,collapsedContextThreshold:0,expansionLineCount:20,overflow:x?"wrap":"scroll",disableFileHeader:!0,enableLineSelection:d,enableGutterUtility:d,onGutterUtilityClick:d?He:void 0,onLineClick:d?ze:void 0,onLineSelected:d?pe:void 0,unsafeCSS:A.length>0?`${Xe}
210
- ${mt}`:Xe,renderAnnotation:d||A.length>0?Ne:void 0,onPostRender:A.length>0?De:void 0}),[De,A.length,D.metadata.id,d,O,oe,U.metadata.id,m,x,pe,He,ze,Ne]),ae=l.useMemo(()=>{const e=d?ft({drafts:T,editingDraftId:K,selection:w}):[];for(const t of A)e.push({side:t.side,lineNumber:t.lineNumber,metadata:{type:"hunk-action",index:t.index}});return e},[K,d,T,A,w]),Me=l.useRef(ae);l.useEffect(()=>{Me.current=ae},[ae]),l.useEffect(()=>{const e=B.current;return()=>{H.current?.cleanUp(),H.current=null,se.current?.release(),se.current=null,Se.current=null,Le.current=null,Ee.current=void 0,me.current=void 0,ge.current=void 0,ye.current=void 0,e&&(e.innerHTML="")}},[]),l.useEffect(()=>{if(typeof window>"u")return;const e=B.current,t=ne.current;if(!e||!J)return;const o=St(t,e);let a=se.current;a||(a=Mt(e),se.current=a),se.current=a;const g=a?.virtualizer??null,u=L?void 0:{name:c||"",contents:n,lang:s,cacheKey:`old:${te}:${c}:${ke(n)}`},b=L?void 0:{name:c||"",contents:r,lang:s,cacheKey:`new:${te}:${c}:${ke(r)}`},S=L?me.current!==L:me.current!==void 0||!u||!b||!ge.current||!ye.current||!We(ge.current,u)||!We(ye.current,b),k=H.current,P=!!(k&&(Se.current!==g||Le.current!==J||g&&(Ee.current!==Q.hunkSeparators||S)));P&&(k?.cleanUp(),H.current=null,e.innerHTML="");let v=H.current;const f=!P&&k?!nt(k.options,Q):!1;if(v?v.setOptions(Q):(v=a?new rt(Q,a.virtualizer,Et,J):new it(Q,J),H.current=v,he.current=null),Se.current=g,Le.current=J,Ee.current=g?Q.hunkSeparators:void 0,me.current=L,ge.current=u,ye.current=b,L)v.render({fileDiff:L,forceRender:f,lineAnnotations:Me.current,containerWrapper:e});else{if(!u||!b)return;v.render({oldFile:u,newFile:b,forceRender:f,lineAnnotations:Me.current,containerWrapper:e})}const p=Ae(e,()=>{o(),Pt(v,a,Te)});return()=>{p(),o()}},[te,L,c,s,r,Q,n,J]),l.useEffect(()=>{const e=H.current;if(e){try{e.setLineAnnotations(ae)}catch(t){console.error("Failed to apply diff line annotations",t);try{e.setLineAnnotations([])}catch{}}requestAnimationFrame(()=>{if(H.current===e){try{e.rerender()}catch{}Te()}})}},[ae]),l.useEffect(()=>{const e=H.current;if(!e||w!==null)return;const t=he.current;if(!xt(w,t))try{j.current=!0,e.setSelectedLines(w),he.current=w}catch{}finally{j.current=!1}},[w]),l.useEffect(()=>{if(!d)return;const e=B.current;if(!e)return;let t=null,o=()=>{};const a=()=>{const u=e.querySelector("diffs-container")?.shadowRoot;if(!u){t=requestAnimationFrame(a);return}const b=S=>{if(!(S instanceof MouseEvent)||S.button!==0||!(S.target instanceof Element))return;const k=S.target.closest("[data-column-number]");if(!(k instanceof HTMLElement))return;const P=k.getAttribute("data-column-number"),v=P?parseInt(P,10):NaN;if(Number.isNaN(v))return;const f=qe(k);pe({start:v,end:v,side:f}),S.preventDefault(),S.stopPropagation()};u.addEventListener("click",b,!0),o=()=>{u.removeEventListener("click",b,!0)}};return a(),()=>{t!==null&&cancelAnimationFrame(t),o()}},[te,d,c,pe,qe]),l.useEffect(()=>{const e=B.current;if(!e)return;let t=null,o=null;const g=setTimeout(()=>{const u=e.querySelector("diffs-container");if(!(u instanceof HTMLElement))return;const b=u.shadowRoot;t=new MutationObserver(()=>{o&&cancelAnimationFrame(o),o=requestAnimationFrame(()=>{Te(),o=null})}),t.observe(u,{childList:!0,subtree:!0}),b&&t.observe(b,{childList:!0,subtree:!0})},100);return()=>{clearTimeout(g),o&&cancelAnimationFrame(o),t?.disconnect()}},[te,c]);const le=!!z&&L?.isPartial===!0,be=le&&(ue||i!==L);l.useEffect(()=>{const e=B.current;if(e)return Ae(e,()=>{const t=e.querySelector("diffs-container");t instanceof HTMLElement&&(t.toggleAttribute("data-oc-expand-on-demand",le),t.toggleAttribute("data-oc-expand-loading",be))})},[be,le,L]),l.useEffect(()=>{const e=B.current;if(!e||!le||be||!L||!z)return;const t=o=>{if(o.button!==0)return;const a=Lt(o.composedPath(),L);a&&(o.preventDefault(),o.stopPropagation(),z(a))};return e.addEventListener("click",t),()=>e.removeEventListener("click",t)},[be,le,L,z]);const Pe=l.useRef(null);if(l.useEffect(()=>{if(!N||!L||L.isPartial||Pe.current===N)return;const e=B.current;if(e)return Ae(e,()=>{const t=H.current;if(!t||t.fileDiff!==L||Pe.current===N)return;Pe.current=N;const o=L.hunks.findIndex(a=>a.additionStart<=N.additionStart&&N.additionStart<a.additionStart+Math.max(a.additionCount,1));o<0||t.expandHunk(o,N.direction)})},[L,N]),typeof window>"u")return null;const $e=d?F.jsx(pt,{diffRootRef:ne,drafts:T,selection:w,editingDraftId:K,commentText:q,onTextChange:I,fileLabel:c?.split("/").pop()??"",onSave:et,onCancel:Ze,onEdit:e=>{X({start:e.startLine,end:e.endLine,side:e.side==="original"?"deletions":"additions"}),Je(e)},onDelete:Qe}):null,Oe=R&&L&&ee.fileDiff===L&&ee.anchors===A?[...ee.targets].map(([e,t])=>we.createPortal(R.render(e),t,`hunk-${e}`)):null;return M==="fill"?F.jsx("div",{className:Be("flex flex-col relative","size-full"),"data-diff-virtual-root":!0,children:F.jsxs("div",{className:"flex-1 relative min-h-0",children:[F.jsx(lt,{outerClassName:"pierre-diff-wrapper size-full",disableHorizontal:!1,fillContainer:!0,"data-diff-virtual-content":!0,children:F.jsx("div",{ref:ne,className:"size-full relative",children:F.jsx("div",{ref:B,className:"size-full"})})}),$e,Oe]})}):F.jsxs("div",{className:Be("relative","w-full"),children:[F.jsx("div",{ref:ne,className:"pierre-diff-wrapper w-full overflow-x-auto overflow-y-visible relative",children:F.jsx("div",{ref:B,className:"w-full"})}),$e,Oe]})};export{Ot as P};
209
+ `)},xt=(n,r)=>n===r?!0:!n||!r?!1:n.start===r.start&&n.end===r.end&&n.side===r.side,kt=n=>n==="auto"||n==="scroll"||n==="overlay",Rt=n=>{let r=n?.parentElement??null;for(;r;){const i=window.getComputedStyle(r);if(kt(i.overflowY))return r;r=r.parentElement}return null},St=(n,r)=>{if(!n||!r||typeof window>"u")return()=>{};const i=Rt(n);if(!i)return()=>{};const s=r.getBoundingClientRect().height;if(!s)return()=>{};const c=n.getBoundingClientRect().top-i.getBoundingClientRect().top,m=r.style.minHeight;r.style.minHeight=`${Math.ceil(s)}px`;let x=!1;return()=>{if(x)return;x=!0,r.style.minHeight=m;const d=n.getBoundingClientRect().top-i.getBoundingClientRect().top-c;d&&(i.scrollTop+=d)}},Lt=(n,r)=>{const i=n.find(R=>R instanceof HTMLElement&&R.hasAttribute("data-separator"));if(!i)return null;let s=i.nextElementSibling;for(;s&&!s.hasAttribute("data-line-index");)s=s.nextElementSibling;const[c,m]=s?.getAttribute("data-line-index")?.split(",")??[],x=Number.parseInt(c??"",10),M=Number.parseInt(m??"",10);if(Number.isNaN(x)||Number.isNaN(M))return null;const d=r.hunks.find(R=>R.unifiedLineStart<=x&&x<R.unifiedLineStart+R.unifiedLineCount&&R.splitLineStart<=M&&M<R.splitLineStart+R.splitLineCount);return d?{additionStart:d.additionStart,direction:i.hasAttribute("data-separator-first")?"down":"both"}:null},Ae=(n,r)=>{if(typeof window>"u")return()=>{};let i=null,s=null,c=!1;const m=()=>{c||(s?.disconnect(),s=null,i=window.requestAnimationFrame(()=>{i=window.requestAnimationFrame(()=>{c||r()})}))},x=()=>n.querySelector("diffs-container")?.shadowRoot??void 0,M=(d=x())=>!!d?.querySelector("[data-line]");return M()?m():typeof MutationObserver<"u"?(s=new MutationObserver(()=>{const d=x();if(d){if(M(d)){m();return}s?.disconnect(),s=new MutationObserver(()=>{M(d)&&m()}),s.observe(d,{childList:!0,subtree:!0})}}),s.observe(n,{childList:!0,subtree:!0})):i=window.requestAnimationFrame(m),()=>{c=!0,s?.disconnect(),i!==null&&window.cancelAnimationFrame(i)}},ve=new WeakMap,Tt={lineHeight:24,hunkSeparatorHeight:24,spacing:0};function Et(n){const r=n.closest("[data-diff-virtual-root]");if(r instanceof HTMLElement){const i=r.querySelector("[data-diff-virtual-content]");return{key:r,root:r,content:i instanceof HTMLElement?i:void 0}}return{key:document,root:document,content:void 0}}function Mt(n){if(typeof document>"u")return null;const r=Et(n);let i=ve.get(r.key);if(!i){const c=new ot;c.setup(r.root,r.content),i={virtualizer:c,refs:0},ve.set(r.key,i)}i.refs+=1;let s=!1;return{virtualizer:i.virtualizer,root:r.root,release:()=>{if(s)return;s=!0;const c=ve.get(r.key);c&&(c.refs-=1,!(c.refs>0)&&(c.virtualizer.cleanUp(),ve.delete(r.key)))}}}const Pt=(n,r,i)=>{if(typeof window>"u")return()=>{};const s=[],c=()=>{try{n.rerender()}catch{}const m=r?.root;m instanceof HTMLElement?m.dispatchEvent(new Event("scroll",{bubbles:!1})):document.dispatchEvent(new Event("scroll",{bubbles:!1})),window.dispatchEvent(new Event("resize")),i()};return s.push(window.requestAnimationFrame(c)),s.push(window.requestAnimationFrame(()=>{s.push(window.requestAnimationFrame(c))})),()=>{for(const m of s)window.cancelAnimationFrame(m)}},Ot=({original:n,modified:r,fileDiff:i,language:s,fileName:c,renderSideBySide:m,wrapLines:x,layout:M="fill",enableComments:d=!0,hunkActions:R,onExpandContextRequest:z,pendingContextExpansion:N=null,contextLoading:ue=!1})=>{const W=st(),O=W?.currentTheme.metadata.variant==="dark",U=W?.availableThemes.find(e=>e.metadata.id===W.lightThemeId)??je(!1),D=W?.availableThemes.find(e=>e.metadata.id===W.darkThemeId)??je(!0),{isMobile:Z}=at(),A=R?.anchors??Ge,[ee,h]=$.useState(()=>({fileDiff:void 0,anchors:Ge,targets:new Map})),T=dt({source:"diff",fileLabel:c||"unknown",language:s,getCodeForRange:e=>wt(n,r,i,e),toStoreRange:e=>({startLine:e.start,endLine:e.end,side:e.side==="deletions"?"original":"modified"}),fromDraftRange:e=>({start:e.startLine,end:e.endLine,side:e.side==="original"?"deletions":"additions"})}),{drafts:E,selection:w,setSelection:C,commentText:q,setCommentText:I,editingDraftId:K,saveComment:Ie,cancel:Fe,startEdit:Je,deleteDraft:Qe}=T,fe=l.useRef(null),Y=l.useRef(null),re=l.useRef(""),j=l.useRef(!1),he=l.useRef(null);l.useEffect(()=>{fe.current=w},[w]),l.useEffect(()=>{Y.current=K},[K]),l.useEffect(()=>{re.current=q},[q]);const pe=l.useCallback(e=>{if(!d||j.current)return;const t=fe.current;if(!(!e&&t&&re.current.trim())){if(Z&&t&&e&&e.side===t.side){const o=Math.min(t.start,e.start),a=Math.max(t.end,e.end);C({...e,start:o,end:a})}else C(e);e&&(Y.current||I(""))}},[d,Z,I,C]),Ze=l.useCallback(()=>{Fe()},[Fe]),Ne=l.useCallback(e=>{const t=document.createElement("div");if(t.style.position="relative",e.metadata.type==="hunk-action")return t.dataset.hunkActionTarget=String(e.metadata.index),t.style.height="0px",t;const o=xe(e.metadata);return t.dataset.annotationId=o,t.dataset.annotationSide=e.side,t.dataset.annotationLine=String(e.lineNumber),t},[]),De=l.useCallback((e,t,o)=>{const a=new Map;if(o!=="unmount"){const u=Number.parseFloat(getComputedStyle(document.documentElement).fontSize)*2,b=new Map,S=[];for(const k of e.shadowRoot?.querySelectorAll("slot")??[])for(const P of k.assignedElements()){const v=P.querySelector("[data-hunk-action-target]"),f=Number(v?.dataset.hunkActionTarget);if(!v||!Number.isInteger(f)||f<0)continue;a.set(f,v);const p=k.closest("[data-code]");if(!p)continue;let y=b.get(p);y||(y=p.getBoundingClientRect(),b.set(p,y));const G=v.getBoundingClientRect().top,ce=Math.max(y.top+4,Math.min(G+4,y.bottom-u-4));S.push({target:v,offset:ce-G})}for(const{target:k,offset:P}of S){const v=`${P}px`;k.style.getPropertyValue("--oc-hunk-action-offset")!==v&&k.style.setProperty("--oc-hunk-action-offset",v)}}const g=t.fileDiff;h(u=>u.fileDiff===g&&u.anchors===A&&u.targets.size===a.size&&[...a].every(([b,S])=>u.targets.get(b)===S)?u:{fileDiff:g,anchors:A,targets:a})},[A]),et=l.useCallback((e,t)=>{Ie(e,t??w??void 0)},[Ie,w]),X=l.useCallback(e=>{C(e);const t=H.current;if(t)try{j.current=!0,t.setSelectedLines(e),he.current=e}catch{}finally{j.current=!1}},[C]),ie=l.useRef(null),Re=l.useRef(null);l.useEffect(()=>{if(!d)return;const e=ne.current;if(!e)return;const t=()=>{const f=e.querySelector("diffs-container");return f instanceof HTMLElement?f.shadowRoot:null},o=f=>{const p=e.querySelector("diffs-container");p instanceof HTMLElement&&(f?p.setAttribute("data-oc-comment-drag",""):p.removeAttribute("data-oc-comment-drag"))},a=(f,p)=>{const G=t()?.elementFromPoint(f,p)??document.elementFromPoint(f,p);if(!(G instanceof Element))return null;const ce=!!G.closest("[data-column-number]"),de=G.closest("[data-line]");if(!(de instanceof HTMLElement))return null;const Ce=Number.parseInt(de.getAttribute("data-line")??"",10);if(!Number.isFinite(Ce)||Ce<=0)return null;const tt=de.getAttribute("data-line-type")==="change-deletion"||de.closest("[data-code][data-deletions]")!=null?"deletions":"additions";return{line:Ce,side:tt,numberColumn:ce}};let g=null,u=!1,b=null;const S=f=>{ie.current=f;const p=H.current;if(p)try{j.current=!0,p.setSelectedLines(f)}catch{}finally{j.current=!1}},k=f=>{if(f.button!==0||f.pointerType!=="mouse")return;const p=a(f.clientX,f.clientY);if(!p||p.numberColumn){g=null;return}g={line:p.line,side:p.side},u=!1,b=f.pointerId},P=f=>{if(g==null||f.pointerId!==b)return;const p=a(f.clientX,f.clientY);if(p){if(!u){if(p.line===g.line)return;u=!0,o(!0),window.getSelection()?.removeAllRanges();const y=t();y&&"getSelection"in y&&y.getSelection()?.removeAllRanges()}S({start:Math.min(g.line,p.line),end:Math.max(g.line,p.line),side:g.side})}},v=f=>{if(g==null||f.pointerId!==b)return;const p=u;if(g=null,u=!1,b=null,o(!1),!p)return;const y=ie.current;ie.current=null,y&&(fe.current&&re.current.trim()&&!Y.current||(X(y),Y.current||I("")))};return e.addEventListener("pointerdown",k),document.addEventListener("pointermove",P,{passive:!0}),document.addEventListener("pointerup",v),()=>{e.removeEventListener("pointerdown",k),document.removeEventListener("pointermove",P),document.removeEventListener("pointerup",v),o(!1)}},[X,d,I]);const He=l.useCallback(e=>{if(!d)return;const t=ie.current,o=t&&e.start>=t.start&&e.end<=t.end&&(e.side==null||e.side===t.side);Re.current!==null&&(window.clearTimeout(Re.current),Re.current=null),ie.current=null,X(o&&t?t:e),Y.current||I("")},[X,d,I]),ze=l.useCallback(e=>{if(!d||e.numberColumn||window.getSelection()?.toString().trim())return;const t=e.annotationSide,o={start:e.lineNumber,end:e.lineNumber,side:t},a=fe.current;if(a&&a.start===o.start&&a.end===o.end&&a.side===o.side){if(!re.current.trim()){C(null);const g=H.current;try{j.current=!0,g?.setSelectedLines(null)}finally{j.current=!1}}return}a&&re.current.trim()&&!Y.current||(X(o),Y.current||I(""))},[X,d,I,C]),qe=l.useCallback(e=>{const t=e.closest("[data-line-type]")?.getAttribute("data-line-type")??e.getAttribute("data-line-type");if(t==="change-deletion")return"deletions";if(t==="change-addition")return"additions";const o=e.getAttribute("data-column-side")??e.getAttribute("data-side")??e.closest("[data-column-side]")?.getAttribute("data-column-side");if(o==="deletions"||o==="left"||o==="original")return"deletions";if(o==="additions"||o==="right"||o==="modified")return"additions";const a=e.closest("[data-line-type]");if(a instanceof HTMLElement){const g=a.getBoundingClientRect(),u=e.getBoundingClientRect(),b=g.left+g.width/2;return u.left+u.width/2<b?"deletions":"additions"}return"additions"},[]);Ve(U),Ve(D);const te=`${U.metadata.id}:${D.metadata.id}:${O?"dark":"light"}`,oe=l.useMemo(()=>{if(i){const e=i.deletionLines.reduce((o,a)=>o+a.length,0),t=i.additionLines.reduce((o,a)=>o+a.length,0);return Math.max(e,t)>Ye}return Math.max(n.length,r.length)>Ye},[i,r.length,n.length]),ne=l.useRef(null),B=l.useRef(null),H=l.useRef(null),se=l.useRef(null),Se=l.useRef(null),Le=l.useRef(null),Te=l.useRef(void 0),me=l.useRef(void 0),ge=l.useRef(void 0),ye=l.useRef(void 0),[,Ee]=$.useReducer(e=>e+1,0),J=ut(oe?"unified":m?"split":"unified"),L=vt(i,J),_=l.useMemo(()=>Ue(U),[U]),V=l.useMemo(()=>Ue(D),[D]);$.useLayoutEffect(()=>{const e=ne.current;if(!e)return;const t=e.querySelector("diffs-container");if(!t)return;const o=O?V:_,a=(G,ce)=>G.colors?.[ce],g=a(_,"terminal.ansiGreen"),u=a(_,"terminal.ansiRed"),b=a(_,"terminal.ansiBlue"),S=a(V,"terminal.ansiGreen"),k=a(V,"terminal.ansiRed"),P=a(V,"terminal.ansiBlue");t.style.setProperty("--shiki-light",_.fg),t.style.setProperty("--shiki-light-bg",_.bg),g&&t.style.setProperty("--shiki-light-addition-color",g),u&&t.style.setProperty("--shiki-light-deletion-color",u),b&&t.style.setProperty("--shiki-light-modified-color",b),t.style.setProperty("--shiki-dark",V.fg),t.style.setProperty("--shiki-dark-bg",V.bg),S&&t.style.setProperty("--shiki-dark-addition-color",S),k&&t.style.setProperty("--shiki-dark-deletion-color",k),P&&t.style.setProperty("--shiki-dark-modified-color",P),t.style.setProperty("--diffs-bg",o.bg),t.style.setProperty("--diffs-fg",o.fg);const v=O?S:g,f=O?k:u,p=O?P:b;v&&t.style.setProperty("--diffs-addition-color-override",v),f&&t.style.setProperty("--diffs-deletion-color-override",f),p&&t.style.setProperty("--diffs-modified-color-override",p);const y=t.shadowRoot?.querySelector("pre");y&&(y.style.setProperty("--shiki-light",_.fg),y.style.setProperty("--shiki-light-bg",_.bg),g&&y.style.setProperty("--shiki-light-addition-color",g),u&&y.style.setProperty("--shiki-light-deletion-color",u),b&&y.style.setProperty("--shiki-light-modified-color",b),y.style.setProperty("--shiki-dark",V.fg),y.style.setProperty("--shiki-dark-bg",V.bg),S&&y.style.setProperty("--shiki-dark-addition-color",S),k&&y.style.setProperty("--shiki-dark-deletion-color",k),P&&y.style.setProperty("--shiki-dark-modified-color",P),y.style.setProperty("--diffs-bg",o.bg),y.style.setProperty("--diffs-fg",o.fg),v&&y.style.setProperty("--diffs-addition-color-override",v),f&&y.style.setProperty("--diffs-deletion-color-override",f),p&&y.style.setProperty("--diffs-modified-color-override",p))},[V,te,O,_]);const Q=l.useMemo(()=>({theme:{dark:D.metadata.id,light:U.metadata.id},themeType:O?"dark":"light",diffStyle:m?"split":"unified",diffIndicators:"none",hunkSeparators:"line-info-basic",lineDiffType:"none",maxLineDiffLength:oe?0:1e3,maxLineLengthForHighlighting:oe?1:1e3,tokenizeMaxLineLength:oe?1:1e3,collapsedContextThreshold:0,expansionLineCount:20,overflow:x?"wrap":"scroll",disableFileHeader:!0,enableLineSelection:d,enableGutterUtility:d,onGutterUtilityClick:d?He:void 0,onLineClick:d?ze:void 0,onLineSelected:d?pe:void 0,unsafeCSS:A.length>0?`${Xe}
210
+ ${mt}`:Xe,renderAnnotation:d||A.length>0?Ne:void 0,onPostRender:A.length>0?De:void 0}),[De,A.length,D.metadata.id,d,O,oe,U.metadata.id,m,x,pe,He,ze,Ne]),ae=l.useMemo(()=>{const e=d?ft({drafts:E,editingDraftId:K,selection:w}):[];for(const t of A)e.push({side:t.side,lineNumber:t.lineNumber,metadata:{type:"hunk-action",index:t.index}});return e},[K,d,E,A,w]),Me=l.useRef(ae);l.useEffect(()=>{Me.current=ae},[ae]),l.useEffect(()=>{const e=B.current;return()=>{H.current?.cleanUp(),H.current=null,se.current?.release(),se.current=null,Se.current=null,Le.current=null,Te.current=void 0,me.current=void 0,ge.current=void 0,ye.current=void 0,e&&(e.innerHTML="")}},[]),l.useEffect(()=>{if(typeof window>"u")return;const e=B.current,t=ne.current;if(!e||!J)return;const o=St(t,e);let a=se.current;a||(a=Mt(e),se.current=a),se.current=a;const g=a?.virtualizer??null,u=L?void 0:{name:c||"",contents:n,lang:s,cacheKey:`old:${te}:${c}:${ke(n)}`},b=L?void 0:{name:c||"",contents:r,lang:s,cacheKey:`new:${te}:${c}:${ke(r)}`},S=L?me.current!==L:me.current!==void 0||!u||!b||!ge.current||!ye.current||!We(ge.current,u)||!We(ye.current,b),k=H.current,P=!!(k&&(Se.current!==g||Le.current!==J||g&&(Te.current!==Q.hunkSeparators||S)));P&&(k?.cleanUp(),H.current=null,e.innerHTML="");let v=H.current;const f=!P&&k?!nt(k.options,Q):!1;if(v?v.setOptions(Q):(v=a?new rt(Q,a.virtualizer,Tt,J):new it(Q,J),H.current=v,he.current=null),Se.current=g,Le.current=J,Te.current=g?Q.hunkSeparators:void 0,me.current=L,ge.current=u,ye.current=b,L)v.render({fileDiff:L,forceRender:f,lineAnnotations:Me.current,containerWrapper:e});else{if(!u||!b)return;v.render({oldFile:u,newFile:b,forceRender:f,lineAnnotations:Me.current,containerWrapper:e})}const p=Ae(e,()=>{o(),Pt(v,a,Ee)});return()=>{p(),o()}},[te,L,c,s,r,Q,n,J]),l.useEffect(()=>{const e=H.current;if(e){try{e.setLineAnnotations(ae)}catch(t){console.error("Failed to apply diff line annotations",t);try{e.setLineAnnotations([])}catch{}}requestAnimationFrame(()=>{if(H.current===e){try{e.rerender()}catch{}Ee()}})}},[ae]),l.useEffect(()=>{const e=H.current;if(!e||w!==null)return;const t=he.current;if(!xt(w,t))try{j.current=!0,e.setSelectedLines(w),he.current=w}catch{}finally{j.current=!1}},[w]),l.useEffect(()=>{if(!d)return;const e=B.current;if(!e)return;let t=null,o=()=>{};const a=()=>{const u=e.querySelector("diffs-container")?.shadowRoot;if(!u){t=requestAnimationFrame(a);return}const b=S=>{if(!(S instanceof MouseEvent)||S.button!==0||!(S.target instanceof Element))return;const k=S.target.closest("[data-column-number]");if(!(k instanceof HTMLElement))return;const P=k.getAttribute("data-column-number"),v=P?parseInt(P,10):NaN;if(Number.isNaN(v))return;const f=qe(k);pe({start:v,end:v,side:f}),S.preventDefault(),S.stopPropagation()};u.addEventListener("click",b,!0),o=()=>{u.removeEventListener("click",b,!0)}};return a(),()=>{t!==null&&cancelAnimationFrame(t),o()}},[te,d,c,pe,qe]),l.useEffect(()=>{const e=B.current;if(!e)return;let t=null,o=null;const g=setTimeout(()=>{const u=e.querySelector("diffs-container");if(!(u instanceof HTMLElement))return;const b=u.shadowRoot;t=new MutationObserver(()=>{o&&cancelAnimationFrame(o),o=requestAnimationFrame(()=>{Ee(),o=null})}),t.observe(u,{childList:!0,subtree:!0}),b&&t.observe(b,{childList:!0,subtree:!0})},100);return()=>{clearTimeout(g),o&&cancelAnimationFrame(o),t?.disconnect()}},[te,c]);const le=!!z&&L?.isPartial===!0,be=le&&(ue||i!==L);l.useEffect(()=>{const e=B.current;if(e)return Ae(e,()=>{const t=e.querySelector("diffs-container");t instanceof HTMLElement&&(t.toggleAttribute("data-oc-expand-on-demand",le),t.toggleAttribute("data-oc-expand-loading",be))})},[be,le,L]),l.useEffect(()=>{const e=B.current;if(!e||!le||be||!L||!z)return;const t=o=>{if(o.button!==0)return;const a=Lt(o.composedPath(),L);a&&(o.preventDefault(),o.stopPropagation(),z(a))};return e.addEventListener("click",t),()=>e.removeEventListener("click",t)},[be,le,L,z]);const Pe=l.useRef(null);if(l.useEffect(()=>{if(!N||!L||L.isPartial||Pe.current===N)return;const e=B.current;if(e)return Ae(e,()=>{const t=H.current;if(!t||t.fileDiff!==L||Pe.current===N)return;Pe.current=N;const o=L.hunks.findIndex(a=>a.additionStart<=N.additionStart&&N.additionStart<a.additionStart+Math.max(a.additionCount,1));o<0||t.expandHunk(o,N.direction)})},[L,N]),typeof window>"u")return null;const $e=d?F.jsx(pt,{diffRootRef:ne,drafts:E,selection:w,editingDraftId:K,commentText:q,onTextChange:I,fileLabel:c?.split("/").pop()??"",onSave:et,onCancel:Ze,onEdit:e=>{X({start:e.startLine,end:e.endLine,side:e.side==="original"?"deletions":"additions"}),Je(e)},onDelete:Qe}):null,Oe=R&&L&&ee.fileDiff===L&&ee.anchors===A?[...ee.targets].map(([e,t])=>we.createPortal(R.render(e),t,`hunk-${e}`)):null;return M==="fill"?F.jsx("div",{className:Be("flex flex-col relative","size-full"),"data-diff-virtual-root":!0,children:F.jsxs("div",{className:"flex-1 relative min-h-0",children:[F.jsx(lt,{outerClassName:"pierre-diff-wrapper size-full",disableHorizontal:!1,fillContainer:!0,"data-diff-virtual-content":!0,children:F.jsx("div",{ref:ne,className:"size-full relative",children:F.jsx("div",{ref:B,className:"size-full"})})}),$e,Oe]})}):F.jsxs("div",{className:Be("relative","w-full"),children:[F.jsx("div",{ref:ne,className:"pierre-diff-wrapper w-full overflow-x-auto overflow-y-visible relative",children:F.jsx("div",{ref:B,className:"w-full"})}),$e,Oe]})};export{Ot as P};