@openchamber/web 1.18.4 → 1.20.0
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.
- package/README.md +1 -0
- package/dist/assets/{CodeMirrorCommentWidgets-4qZbrEXU.js → CodeMirrorCommentWidgets-C36E738Y.js} +1 -1
- package/dist/assets/{CommitSection-MJmntVPJ.js → CommitSection-C-F3AX6D.js} +1 -1
- package/dist/assets/{DiagramEditor-jnG3Hbxg.js → DiagramEditor-BPECg1jS.js} +1 -1
- package/dist/assets/DiagramView-D0YNMix8.js +1 -0
- package/dist/assets/DiffView-BHWaMYCC.js +4 -0
- package/dist/assets/FilesView-NMBCW2Tm.js +14 -0
- package/dist/assets/{GitView-DBFrDDBv.js → GitView-Rp8P1KEI.js} +4 -4
- package/dist/assets/{JsonTreeView-DLW2Wy1g.js → JsonTreeView-KnXFN2A-.js} +1 -1
- package/dist/assets/MarkdownImageGallery-BMn3mtor.js +1 -0
- package/dist/assets/MarkdownRendererImpl-kD6N03pH.js +12 -0
- package/dist/assets/OnboardingScreen-CenIeD4v.js +1 -0
- package/dist/assets/{PatchDiff-BuLPx7AN.js → PatchDiff-BzVOVog8.js} +1 -1
- package/dist/assets/{PierreDiffViewer-BHm4Yr0X.js → PierreDiffViewer-Dlby4XqT.js} +2 -2
- package/dist/assets/PlanView-Czu1KMJa.js +4 -0
- package/dist/assets/SessionSwitcherDropdown-IETz58DB.js +1 -0
- package/dist/assets/SettingsView-B6vmuf-c.js +28 -0
- package/dist/assets/SettingsWindow-CauZpdD3.js +1 -0
- package/dist/assets/ToolOutputDialog-BB1c--Zr.js +15 -0
- package/dist/assets/ToolPartDiffPreview-DaOIDISD.js +8 -0
- package/dist/assets/{VirtualizedFileDiff-CwGocYQd.js → VirtualizedFileDiff-lESMT-2b.js} +4 -4
- package/dist/assets/{WalkthroughView-5DyvN03T.js → WalkthroughView-CaSYE0lw.js} +2 -2
- package/dist/assets/{computeVirtualFileMetrics-Da00Jg7M.js → computeVirtualFileMetrics-DkRR5b75.js} +2 -2
- package/dist/assets/contextPanelEmbeddedChat-BEARQjgn.js +1 -0
- package/dist/assets/de-DFdX3ABv.js +9 -0
- package/dist/assets/document-attachments-DFAWlG3U.js +31 -0
- package/dist/assets/es-iC-FKvV9.js +15 -0
- package/dist/assets/fr-BBbi_1AL.js +13 -0
- package/dist/assets/index-BiEgzzkg.js +1 -0
- package/dist/assets/index-Cwmuwk3V.js +7 -0
- package/dist/assets/index-GNm1wgUH.css +1 -0
- package/dist/assets/{isDiffPlainText-D9YpoLrV.js → isDiffPlainText-BG53Ixxy.js} +1 -1
- package/dist/assets/{isFilePlainText-gTibdNIe.js → isFilePlainText-BbV-39jl.js} +1 -1
- package/dist/assets/ja-DQLQJL2J.js +15 -0
- package/dist/assets/ko-BeElEB4Y.js +15 -0
- package/dist/assets/{lua-BgMRiT3U.js → lua-VAEuO923.js} +1 -1
- package/dist/assets/main-Dpzo18z7.js +2 -0
- package/dist/assets/main-WMjtYzJs.js +921 -0
- package/dist/assets/markdownCore--tDmyI_v.js +2 -0
- package/dist/assets/miniChat-ldEghBLB.js +2 -0
- package/dist/assets/mobile-Dk-VGreF.js +2 -0
- package/dist/assets/{patchFileDiff-KNkxM1C1.js → patchFileDiff-BcFaMtMu.js} +1 -1
- package/dist/assets/pl-CLHt2_vV.js +15 -0
- package/dist/assets/pt-BR-C_MPUq7e.js +15 -0
- package/dist/assets/renderElectronMiniChatApp-DIgCOmXY.js +2 -0
- package/dist/assets/renderMobileApp-CDfHS5rr.js +25 -0
- package/dist/assets/runtimeEndpointReset-ovNbaZ-x.js +15 -0
- package/dist/assets/scheduledTasksApi-BFSlqgnG.js +1 -0
- package/dist/assets/{shikiHighlight-C7LTbwFx.js → shikiHighlight-DCT2Sq_z.js} +1 -1
- package/dist/assets/uk-PhsC-c4-.js +15 -0
- package/dist/assets/{useAppFontEffects-BikB6enL.js → useAppFontEffects-B53Rb6m7.js} +168 -164
- package/dist/assets/useInlineCommentController-DSfrIBKT.js +2 -0
- package/dist/assets/{vendor-base-ui-D_V6hAcE.js → vendor-base-ui-DsHmyMwp.js} +1 -1
- package/dist/assets/vendor-codemirror-autocomplete-DzPz9Wgq.js +1 -0
- package/dist/assets/vendor-codemirror-commands-B7H_j0iU.js +1 -0
- package/dist/assets/{vendor-codemirror-lang-angular-CgY7_gQ1.js → vendor-codemirror-lang-angular-DEPs2M5t.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-cpp-B5Ta4enQ.js → vendor-codemirror-lang-cpp-DhkseaMo.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-css-VgNqFSH-.js → vendor-codemirror-lang-css-O0cZX78y.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-go-LxLz62pp.js → vendor-codemirror-lang-go-fMdQYcON.js} +1 -1
- package/dist/assets/vendor-codemirror-lang-html-CfgK872x.js +1 -0
- package/dist/assets/{vendor-codemirror-lang-java-Bksi1PH4.js → vendor-codemirror-lang-java-CQj4S3zl.js} +1 -1
- package/dist/assets/vendor-codemirror-lang-javascript-Cc2ZYbgX.js +13 -0
- package/dist/assets/{vendor-codemirror-lang-jinja-C7npuDD7.js → vendor-codemirror-lang-jinja-BmZZv8g-.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-json-ryCw7nab.js → vendor-codemirror-lang-json-CMBS2tG9.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-less-BxsZJD6N.js → vendor-codemirror-lang-less-C6Eo8hVS.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-liquid-De6qch10.js → vendor-codemirror-lang-liquid-DSTR47-H.js} +1 -1
- package/dist/assets/vendor-codemirror-lang-markdown-BPGOH9ye.js +1 -0
- package/dist/assets/{vendor-codemirror-lang-php-Cm1es33p.js → vendor-codemirror-lang-php-DD9udfPH.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-python-N414WYK-.js → vendor-codemirror-lang-python-HahnQaAS.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-rust-C_WuUStH.js → vendor-codemirror-lang-rust-nLTovbjv.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-sass-8UHTCAOM.js → vendor-codemirror-lang-sass-pL2Yc72v.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-sql-CV3sMA5D.js → vendor-codemirror-lang-sql-BVBnan19.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-vue-DzvC1Dhk.js → vendor-codemirror-lang-vue-BqGzJVm1.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-wast-jlr-LDdA.js → vendor-codemirror-lang-wast-B0_m5DqU.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-xml-CrO63OVp.js → vendor-codemirror-lang-xml-Dj3voadT.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-yaml-dxi6CISW.js → vendor-codemirror-lang-yaml-yu-9Z5u7.js} +1 -1
- package/dist/assets/vendor-codemirror-language-BgPj_McA.js +3 -0
- package/dist/assets/{vendor-codemirror-language-data-CLHw8NWn.js → vendor-codemirror-language-data-vch3tJ4c.js} +2 -2
- package/dist/assets/vendor-codemirror-search-BmS-GmcX.js +2 -0
- package/dist/assets/{vendor-codemirror-state-CNWM3Q8V.js → vendor-codemirror-state-C9awkmn-.js} +5 -5
- package/dist/assets/vendor-codemirror-view-CiLROUVV.js +4 -0
- package/dist/assets/vendor-replit-codemirror-vim-B2DJlAhT.js +6 -0
- package/dist/assets/vendor-replit-codemirror-vim-core-FHzKdNUS.js +34 -0
- package/dist/assets/vendor-zod-C9ioTTSo.js +39 -0
- package/dist/assets/{web-components-GMc3oR3i.js → web-components-pcwCTWjC.js} +4 -4
- package/dist/assets/zh-CN-wF-NOFHM.js +15 -0
- package/dist/assets/zh-TW-4m4-A7rT.js +15 -0
- package/dist/index.html +5 -4
- package/dist/mini-chat.html +4 -3
- package/dist/mobile.html +4 -3
- package/package.json +3 -5
- package/server/index.js +152 -3
- package/server/lib/agent-memory/actions.js +243 -0
- package/server/lib/agent-memory/actions.test.js +343 -0
- package/server/lib/agent-memory/feature-flag.js +19 -0
- package/server/lib/agent-memory/feature-flag.test.js +38 -0
- package/server/lib/agent-memory/project-resolution.js +65 -0
- package/server/lib/agent-memory/project-resolution.test.js +94 -0
- package/server/lib/agent-memory/routes.http.test.js +270 -0
- package/server/lib/agent-memory/routes.js +169 -0
- package/server/lib/agent-memory/runtime.js +432 -0
- package/server/lib/agent-memory/runtime.test.js +344 -0
- package/server/lib/agent-memory/threat-patterns.js +61 -0
- package/server/lib/agent-memory/threat-patterns.test.js +61 -0
- package/server/lib/agent-tool/DOCUMENTATION.md +14 -0
- package/server/lib/agent-tool/runtime.js +63 -13
- package/server/lib/agent-tool/runtime.test.js +85 -2
- package/server/lib/context-obligatory/runtime.js +34 -3
- package/server/lib/context-obligatory/runtime.test.js +114 -0
- package/server/lib/dictation/DOCUMENTATION.md +32 -8
- package/server/lib/dictation/local/sherpa-recognizer.js +35 -78
- package/server/lib/dictation/local/worker-process.js +2 -2
- package/server/lib/dictation/openai-compatible-session.js +3 -2
- package/server/lib/dictation/stream-manager.js +77 -34
- package/server/lib/dictation/stream-manager.test.js +60 -2
- package/server/lib/fs/DOCUMENTATION.md +3 -0
- package/server/lib/fs/routes.js +149 -32
- package/server/lib/fs/routes.test.js +301 -0
- package/server/lib/git/DOCUMENTATION.md +8 -0
- package/server/lib/git/routes.js +43 -0
- package/server/lib/git/service.js +206 -72
- package/server/lib/git/service.test.js +222 -0
- package/server/lib/github/DOCUMENTATION.md +14 -3
- package/server/lib/github/pr-status.js +188 -83
- package/server/lib/github/pr-status.test.js +182 -0
- package/server/lib/github/routes.js +36 -30
- package/server/lib/notifications/template-runtime.js +2 -3
- package/server/lib/openchamber-control/action-resolution.test.js +65 -0
- package/server/lib/openchamber-control/actions.js +78 -0
- package/server/lib/openchamber-control/service.js +7 -0
- package/server/lib/openchamber-sessions/routes.js +14 -0
- package/server/lib/opencode/DOCUMENTATION.md +12 -6
- package/server/lib/opencode/claude-cli-auth.js +60 -0
- package/server/lib/opencode/claude-cli-auth.test.js +54 -0
- package/server/lib/opencode/feature-routes-runtime.js +16 -9
- package/server/lib/opencode/lifecycle.js +202 -26
- package/server/lib/opencode/lifecycle.test.js +179 -1
- package/server/lib/opencode/plugins.js +12 -3
- package/server/lib/opencode/plugins.test.js +18 -0
- package/server/lib/opencode/providers.js +9 -4
- package/server/lib/opencode/providers.test.js +27 -0
- package/server/lib/opencode/proxy-agent-wiring.test.js +152 -0
- package/server/lib/opencode/proxy.js +116 -6
- package/server/lib/opencode/proxy.test.js +158 -1
- package/server/lib/opencode/restart-session-recovery.test.js +59 -0
- package/server/lib/opencode/routes.js +4 -1
- package/server/lib/opencode/session-runtime.js +39 -2
- package/server/lib/opencode/session-runtime.test.js +74 -0
- package/server/lib/opencode/settings-helpers.js +26 -0
- package/server/lib/opencode/settings-helpers.test.js +57 -0
- package/server/lib/opencode/settings-normalization-runtime.js +3 -0
- package/server/lib/opencode/settings-normalization-runtime.test.js +16 -0
- package/server/lib/opencode/settings-runtime.js +83 -10
- package/server/lib/opencode/settings-runtime.test.js +85 -0
- package/server/lib/opencode/shared.js +120 -16
- package/server/lib/opencode/shared.test.js +185 -1
- package/server/lib/opencode/skill-routes.js +29 -73
- package/server/lib/opencode/skill-routes.test.js +2 -5
- package/server/lib/project-context/DOCUMENTATION.md +160 -0
- package/server/lib/project-context/routes.http.test.js +264 -0
- package/server/lib/project-context/routes.js +237 -0
- package/server/lib/project-context/runtime.js +672 -0
- package/server/lib/project-context/runtime.test.js +498 -0
- package/server/lib/projects/project-config.js +7 -2
- package/server/lib/quota/DOCUMENTATION.md +17 -2
- package/server/lib/quota/providers/claude/auth.js +113 -0
- package/server/lib/quota/providers/claude/auth.test.js +117 -0
- package/server/lib/quota/providers/claude/index.js +151 -0
- package/server/lib/quota/providers/claude/index.test.js +147 -0
- package/server/lib/quota/providers/claude/transforms.js +127 -0
- package/server/lib/quota/providers/claude/transforms.test.js +82 -0
- package/server/lib/quota/providers/command-code.js +90 -0
- package/server/lib/quota/providers/command-code.test.js +85 -0
- package/server/lib/quota/providers/index.js +30 -2
- package/server/lib/quota/providers/index.test.js +10 -1
- package/server/lib/quota/providers/zai.js +26 -6
- package/server/lib/quota/providers/zai.test.js +33 -0
- package/server/lib/quota/utils/formatters.js +2 -1
- package/server/lib/scheduled-tasks/runtime.js +21 -2
- package/server/lib/session-knowledge/DOCUMENTATION.md +89 -0
- package/server/lib/session-knowledge/routes.js +107 -0
- package/server/lib/session-knowledge/runtime.js +331 -0
- package/server/lib/session-knowledge/runtime.test.js +275 -0
- package/server/lib/skills-catalog/DOCUMENTATION.md +18 -45
- package/server/lib/skills-catalog/cache.js +120 -1
- package/server/lib/skills-catalog/cache.test.js +77 -0
- package/server/lib/skills-catalog/curated-sources.js +21 -5
- package/server/lib/skills-catalog/curated-sources.test.js +10 -0
- package/server/lib/skills-catalog/disk-cache.js +52 -0
- package/server/lib/skills-catalog/github-meta.js +139 -0
- package/server/lib/skills-catalog/github-meta.test.js +71 -0
- package/server/lib/skills-catalog/source.js +0 -5
- package/server/lib/small-model/DOCUMENTATION.md +74 -6
- package/server/lib/small-model/call.js +46 -12
- package/server/lib/small-model/call.test.js +79 -0
- package/server/lib/small-model/index.js +57 -6
- package/server/lib/small-model/index.test.js +102 -2
- package/server/lib/small-model/routes.js +4 -2
- package/server/lib/small-model/runtime-providers.js +156 -0
- package/server/lib/small-model/runtime-providers.test.js +112 -0
- package/dist/assets/DiagramView-CFXxgg_a.js +0 -1
- package/dist/assets/DiffView-DZIoOnV7.js +0 -4
- package/dist/assets/FilesView-BKL6YlKG.js +0 -14
- package/dist/assets/MarkdownImageGallery-DKIylIK7.js +0 -1
- package/dist/assets/MarkdownRendererImpl-CLv8hxvv.js +0 -12
- package/dist/assets/OnboardingScreen-D2Y6djMw.js +0 -1
- package/dist/assets/PlanView-ZYEJn8A_.js +0 -4
- package/dist/assets/SessionSwitcherDropdown-rro-SsaO.js +0 -1
- package/dist/assets/SettingsView-5RmswFZe.js +0 -28
- package/dist/assets/SettingsWindow-BZhAYFdS.js +0 -1
- package/dist/assets/ToolOutputDialog-Za6V4VMJ.js +0 -15
- package/dist/assets/ToolPartDiffPreview-BL-9ixyC.js +0 -8
- package/dist/assets/contextPanelEmbeddedChat-B-bSg3P5.js +0 -1
- package/dist/assets/de-u7gSnqWs.js +0 -9
- package/dist/assets/document-attachments-CX_YaDsu.js +0 -30
- package/dist/assets/es-T9O7aAOr.js +0 -15
- package/dist/assets/fr-Oor7ewbE.js +0 -13
- package/dist/assets/index-BzIpNlNE.css +0 -1
- package/dist/assets/index-C0yNhuZw.js +0 -1
- package/dist/assets/index-DRpChWux.js +0 -7
- package/dist/assets/ja-DHpqbVmr.js +0 -15
- package/dist/assets/ko-CwLkS3nx.js +0 -15
- package/dist/assets/main-D7UcL3VQ.js +0 -2
- package/dist/assets/main-DPMd2iKS.js +0 -915
- package/dist/assets/markdownCore-DDrHVneM.js +0 -2
- package/dist/assets/miniChat-O_GVoEbc.js +0 -2
- package/dist/assets/mobile-Br4TtAqc.js +0 -2
- package/dist/assets/pl-CcZILN8q.js +0 -15
- package/dist/assets/pt-BR-DYHhVK6o.js +0 -15
- package/dist/assets/renderElectronMiniChatApp-CJpdxTT1.js +0 -2
- package/dist/assets/renderMobileApp-toj9cXoh.js +0 -25
- package/dist/assets/runtimeEndpointReset-BVmispdD.js +0 -13
- package/dist/assets/scheduledTasksApi-ByKya3Un.js +0 -1
- package/dist/assets/uk-BA2kZR38.js +0 -15
- package/dist/assets/useInlineCommentController-CYPvYJDt.js +0 -2
- package/dist/assets/vendor-codemirror-autocomplete-BjbBRsUA.js +0 -1
- package/dist/assets/vendor-codemirror-commands-ARAOgp1x.js +0 -1
- package/dist/assets/vendor-codemirror-lang-html-B3Qe3OpS.js +0 -1
- package/dist/assets/vendor-codemirror-lang-javascript-Bbw3D7r0.js +0 -13
- package/dist/assets/vendor-codemirror-lang-markdown-FGQydhTc.js +0 -1
- package/dist/assets/vendor-codemirror-language-DUOssd4j.js +0 -3
- package/dist/assets/vendor-codemirror-search-8kyQdB3f.js +0 -2
- package/dist/assets/vendor-codemirror-view-DSzLbZiS.js +0 -4
- package/dist/assets/vendor-replit-codemirror-vim-B0Ecqnlh.js +0 -39
- package/dist/assets/zh-CN-dlOQK6v9.js +0 -15
- package/dist/assets/zh-TW-BnqQ-WL5.js +0 -15
- package/server/lib/quota/providers/claude.js +0 -107
- package/server/lib/skills-catalog/clawdhub/api.js +0 -126
- package/server/lib/skills-catalog/clawdhub/install.js +0 -238
- package/server/lib/skills-catalog/clawdhub/install.test.js +0 -100
- package/server/lib/skills-catalog/clawdhub/scan.js +0 -61
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import{R as n,j as s,f as Ut}from"./vendor-react-BUCujlKS.js";import{P as Un,Q as Gn,R as Kn,S as Hn,ag as xi,m as ze,u as he,cS as qn,A as vi,t as _n,r as wi,T as bi,e as Qn,cQ as Jn,aG as Xn,cR as Yn}from"./index-DRpChWux.js";import{f as Vs,S as ks,B as S,h as O,V as Zn,L as ea,aV as ta,a0 as sa,a1 as ra,b_ as ia,gO as yi,gm as na,t as I,l as ji,aa as er,bV as js,cq as aa,b as oa,gP as tr,ab as Fi,gQ as Ni,bW as Ci,bX as la,fI as ca,gR as da,br as ua,gS as fa,bs as Ai,bt as Ii,bu as Oi,bv as Bi,bw as $i,bx as Wi,I as g,aU as or,aR as lr,ad as Ns,aT as cr,aQ as Cs,aX as ht,aY as pt,aZ as gt,bU as sr,ac as rr,bQ as Si,by as ma,bz as ha,gk as ir,g as Ts,aS as pa,a_ as ga}from"./useAppFontEffects-BikB6enL.js";import{w as xa,x as va,y as wa,z as ba,A as ya}from"./runtimeEndpointReset-BVmispdD.js";import{c as ki,s as ja,C as Ti,P as nr}from"./shikiHighlight-C7LTbwFx.js";import{a as Fa}from"./vendor-codemirror-state-CNWM3Q8V.js";import{E as kt}from"./vendor-codemirror-view-DSzLbZiS.js";import{F as Na,J as Ca}from"./JsonTreeView-DLW2Wy1g.js";import{ensurePierreThemeRegistered as Vi,getResolvedShikiTheme as Sa}from"./appThemeRegistry-BK0dHKa6.js";import{D as ka}from"./DiagramEditor-jnG3Hbxg.js";import{u as Ta,n as Va}from"./useInlineCommentController-CYPvYJDt.js";import{b as Da}from"./CodeMirrorCommentWidgets-4qZbrEXU.js";import{u as Fs,c as Ea}from"./scheduledTasksApi-ByKya3Un.js";import"./vendor-scheduler-7OC5HNn7.js";import"./vendor-vite-runtime-DD1OZmLC.js";import"./vendor-opencode-sdk-BJ73u-bH.js";import"./vendor-zustand-BAGL70zf.js";import"./vendor-simplewebauthn-browser-VDA66rT_.js";import"./vendor-base-ui-D_V6hAcE.js";import"./vendor-floating-ui-utils-BzXdqYpP.js";import"./vendor-floating-ui-dom-WyXykhNi.js";import"./vendor-floating-ui-core-CXmKXOXc.js";import"./vendor-floating-ui-react-dom-DKpLs02S.js";import"./vendor-use-sync-external-store-D6wYuSt-.js";import"./contextPanelEmbeddedChat-B-bSg3P5.js";import"./vendor-class-variance-authority-5VPnzWs2.js";import"./vendor-clsx-B-dksMZM.js";import"./vendor-dnd-kit-core-BZknOX2w.js";import"./vendor-dnd-kit-utilities-B_MdXhJC.js";import"./vendor-dnd-kit-accessibility-BHxJPORy.js";import"./vendor-dnd-kit-sortable-CsEagZ81.js";import"./vendor-cmdk-DgLInKvT.js";import"./vendor-radix-ui-react-dialog-B94Bt2qq.js";import"./vendor-radix-ui-primitive-Dc_FVRD7.js";import"./vendor-radix-ui-react-compose-refs-DcAh5WdT.js";import"./vendor-radix-ui-react-context-Czxm7Z62.js";import"./vendor-radix-ui-react-id-f5BLKEVw.js";import"./vendor-radix-ui-react-use-layout-effect-D_3IhJdJ.js";import"./vendor-radix-ui-react-use-controllable-state-BFT5YmkA.js";import"./vendor-radix-ui-react-dismissable-layer-D7kXcwgJ.js";import"./vendor-radix-ui-react-primitive-DhVoX9SD.js";import"./vendor-radix-ui-react-slot-BQgQOasS.js";import"./vendor-radix-ui-react-use-callback-ref-BZPnuXAC.js";import"./vendor-radix-ui-react-use-escape-keydown-oph88g-F.js";import"./vendor-radix-ui-react-focus-scope-CiaxW4dD.js";import"./vendor-radix-ui-react-portal-BMJYHWck.js";import"./vendor-radix-ui-react-presence-CNxf-uq4.js";import"./vendor-radix-ui-react-focus-guards-B6qJXYua.js";import"./vendor-react-remove-scroll-DO7dCTnK.js";import"./vendor-tslib-De9GV7Vy.js";import"./vendor-react-remove-scroll-bar-BcFYyj3E.js";import"./vendor-react-style-singleton-q6EMHnwf.js";import"./vendor-get-nonce-C-Z93AgS.js";import"./vendor-use-sidecar-zDC0RhA3.js";import"./vendor-use-callback-ref-D3RC8gqK.js";import"./vendor-aria-hidden-DvXkyWUv.js";import"./vendor-codemirror-language-DUOssd4j.js";import"./vendor-lezer-common-B3-cUCR_.js";import"./vendor-lezer-highlight-CDMHUZ74.js";import"./vendor-style-mod-NZ5MEPvj.js";import"./vendor-codemirror-lang-javascript-Bbw3D7r0.js";import"./vendor-lezer-javascript-D7Tj24ot.js";import"./vendor-lezer-lr-bhwg1HMg.js";import"./vendor-codemirror-autocomplete-BjbBRsUA.js";import"./vendor-marijn-find-cluster-break-DXwl3gUT.js";import"./vendor-w3c-keyname-Vcq4gwWv.js";import"./vendor-crelt-C8TCjufn.js";import"./vendor-codemirror-lang-json-ryCw7nab.js";import"./vendor-lezer-json-Iaex0UN-.js";import"./vendor-codemirror-lang-css-VgNqFSH-.js";import"./vendor-lezer-css-C5xB6jxd.js";import"./vendor-codemirror-lang-html-B3Qe3OpS.js";import"./vendor-lezer-html-C0I1p52t.js";import"./vendor-codemirror-lang-markdown-FGQydhTc.js";import"./vendor-lezer-markdown-C6g-d6P3.js";import"./vendor-codemirror-language-data-CLHw8NWn.js";import"./vendor-codemirror-lang-python-N414WYK-.js";import"./vendor-lezer-python-CvuFxeZl.js";import"./vendor-codemirror-commands-ARAOgp1x.js";import"./vendor-tanstack-react-virtual-g05Cx3z9.js";import"./vendor-tanstack-virtual-core-Dubg10g5.js";import"./vendor-framer-motion-CRSgBxjL.js";import"./vendor-motion-dom-DJLgZh4Q.js";import"./vendor-motion-utils-BGh8QBgx.js";import"./vendor-sonner-DFyL3AvE.js";import"./vendor-tailwind-merge-CPcsbTWB.js";import"./vendor-fuse.js-Dw8P0qyA.js";import"./vendor-codemirror-search-8kyQdB3f.js";import"./vendor-replit-codemirror-vim-B0Ecqnlh.js";import"./web-components-GMc3oR3i.js";import"./computeVirtualFileMetrics-Da00Jg7M.js";import"./vendor-shiki-Bbf2GEcE.js";import"./vendor-shikijs-core-CGM_jqPK.js";import"./vendor-shikijs-types-CPSbSeK6.js";import"./vendor-shikijs-vscode-textmate-BgLrS_2D.js";import"./vendor-hast-util-to-html-BKBhbTDb.js";import"./vendor-html-void-elements-CkdplsNl.js";import"./vendor-property-information-rJCbAzvX.js";import"./vendor-zwitch-C2o2j-tx.js";import"./vendor-stringify-entities-CsH1VEn9.js";import"./vendor-character-entities-legacy-BpoLgcEt.js";import"./vendor-character-entities-html4-D7taRCQ7.js";import"./vendor-ccount-c2V3InAJ.js";import"./vendor-comma-separated-tokens-D8TqSuIK.js";import"./vendor-space-separated-tokens-DD3iYX1K.js";import"./vendor-hast-util-whitespace-D4Wp6AEg.js";import"./vendor-shikijs-engine-oniguruma-DPWuIF1G.js";import"./themeResolver-BmJyTmjJ.js";import"./vendor-pierre-theming-C6Z4M5_u.js";import"./vendor-shikijs-engine-javascript-Cme4830A.js";import"./vendor-oniguruma-to-es-DLBnFDCE.js";import"./vendor-oniguruma-parser-C0D4_9rT.js";import"./vendor-regex-BBWcyTkg.js";import"./vendor-regex-utilities-2BQyy0xI.js";import"./vendor-regex-recursion-JU4mF-dD.js";import"./vendor-shikijs-transformers-CZWsLLKm.js";import"./Virtualizer-X_7XPoTH.js";import"./isFilePlainText-gTibdNIe.js";import"./registerCustomTheme-BBXUCRnG.js";import"./vendor-react-drawio-Ct3Q0DsD.js";const Pa=(d,e)=>{if(!e)return null;const r=Number.parseInt(d.trim(),10);return!Number.isFinite(r)||r<1?null:Math.min(r,e.state.doc.lines)},Di=(d,e)=>{const r=d.state.doc.lineAt(e.main.head);return{lineNumber:r.number,character:e.main.head-r.from+1,selection:e}},Ei=(d,e,r)=>{const m=d.state.doc.line(e),x=Math.max(1,Math.min(r,m.length+1)),v=m.from+x-1;d.dispatch({selection:Fa.cursor(v),effects:kt.scrollIntoView(v,{y:"center"})})};function Ra({open:d,onOpenChange:e,view:r,variant:m="overlay"}){const{t:x}=Vs(),[v,y]=n.useState(""),b=n.useRef(null),h=n.useRef(!1),j=n.useRef(null),p=n.useRef(null),F=n.useMemo(()=>Pa(v,r),[v,r]);n.useEffect(()=>{!d||!r||(h.current=!1,b.current=Di(r,r.state.selection),y(""))},[d,r]),n.useEffect(()=>{d&&window.requestAnimationFrame(()=>{p.current?.focus(),p.current?.select()})},[d]),n.useEffect(()=>{if(!(!d||!r||!b.current)){if(F===null){const{selection:a}=b.current;r.dispatch({selection:a,effects:kt.scrollIntoView(a.main.from,{y:"center"})});return}Ei(r,F,b.current.character)}},[F,d,r]);const M=n.useCallback(()=>{if(!r||h.current||!b.current)return;const{selection:a}=b.current;r.dispatch({selection:a,effects:kt.scrollIntoView(a.main.from,{y:"center"})})},[r]),E=n.useCallback(a=>{a||M(),e(a)},[e,M]),N=n.useCallback(()=>{!r||F===null||!b.current||(h.current=!0,Ei(r,F,b.current.character),e(!1),r.focus())},[F,e,r]);n.useEffect(()=>{if(!d)return;const a=W=>{const _=j.current,L=W.target;!_||!(L instanceof Node)||_.contains(L)||E(!1)},q=W=>{W.key==="Escape"&&(W.preventDefault(),E(!1))};return document.addEventListener("pointerdown",a,!0),document.addEventListener("keydown",q,!0),()=>{document.removeEventListener("pointerdown",a,!0),document.removeEventListener("keydown",q,!0)}},[E,d,m]);const P=n.useMemo(()=>{if(!r)return x("goToLineDialog.helper.editorUnavailable");if(F===null){const a=b.current??Di(r,r.state.selection);return x("goToLineDialog.helper.currentLineRange",{current:a.lineNumber,max:r.state.doc.lines})}return x("goToLineDialog.helper.goToLine",{line:F})},[F,x,r]);return m==="inline"?d?s.jsxs("div",{ref:j,className:"ml-1 flex h-6 items-center gap-1",children:[s.jsx(ks,{ref:p,type:"number",min:1,step:1,inputMode:"numeric",value:v,onChange:a=>y(a.target.value),onKeyDown:a=>{a.key==="Enter"&&(a.preventDefault(),N())},placeholder:x("goToLineDialog.field.linePlaceholderShort"),className:"h-6 w-20 rounded-md border-border/70 bg-transparent px-2 typography-meta"}),s.jsx(S,{variant:"outline",size:"xs",onClick:N,disabled:!r||F===null,className:"h-6 px-2",children:x("goToLineDialog.actions.go")})]}):null:s.jsx("div",{ref:j,className:O("absolute left-3 top-3 z-40 w-[min(32rem,calc(100%-1.5rem))] rounded-xl border border-[var(--interactive-border)] bg-[color:color-mix(in_srgb,var(--surface-elevated)_94%,transparent)] p-2.5 shadow-lg backdrop-blur-sm transition-all",d?"pointer-events-auto translate-y-0 opacity-100":"pointer-events-none -translate-y-1 opacity-0"),children:s.jsxs("div",{className:"min-w-0",children:[s.jsx(ks,{ref:p,type:"number",min:1,step:1,inputMode:"numeric",value:v,onChange:a=>y(a.target.value),onKeyDown:a=>{a.key==="Enter"&&(a.preventDefault(),N())},placeholder:x("goToLineDialog.field.linePlaceholder"),className:"h-8 w-full rounded-md border-border/70 bg-background/60 typography-ui-label"}),s.jsx("div",{className:"mt-2 rounded-md bg-primary/15 px-3 py-1.5 typography-ui-label text-foreground/95",children:P})]})})}function Ma(d){return!(!d.autoSaveEnabled||!d.isDirty||!d.canWrite||d.isSaving||d.fileLoading||d.isNonEditableBinary||!d.selectedFilePath||d.loadedFilePath!==d.selectedFilePath)}function za(d){return d.selectedFilePath?d.isDirty?!(d.fileLoading||d.loadedFilePath!==d.selectedFilePath||d.isNonEditableBinary||d.draftContent===""&&d.fileContent!==""&&d.loadedFilePath!==d.selectedFilePath):!0:!1}const La=d=>{const e=z(d);if(!e)return"";if(e==="/"||/^[A-Za-z]:\/$/.test(e))return e;const r=e.lastIndexOf("/");if(r<0)return e;if(r===0)return"/";const m=e.slice(0,r);return/^[A-Za-z]:$/.test(m)?`${m}/`:m},Aa=d=>{const e=Ut.c(8),{label:r,iconDataUrl:m}=d,[x,v]=n.useState(!1);let y;e[0]!==r?(y=r.trim().slice(0,1).toUpperCase()||"?",e[0]=r,e[1]=y):y=e[1];const b=y;if(m&&!x){let p;e[2]===Symbol.for("react.memo_cache_sentinel")?(p=()=>v(!0),e[2]=p):p=e[2];let F;return e[3]!==m?(F=s.jsx("img",{src:m,alt:"",className:"size-4 rounded-sm",onError:p}),e[3]=m,e[4]=F):F=e[4],F}let h;e[5]===Symbol.for("react.memo_cache_sentinel")?(h=O("size-4 rounded-sm flex items-center justify-center","bg-[var(--surface-muted)] text-[9px] font-medium text-muted-foreground"),e[5]=h):h=e[5];let j;return e[6]!==b?(j=s.jsx("span",{className:h,children:b}),e[6]=b,e[7]=j):j=e[7],j},Ia=d=>d.slice().sort((e,r)=>e.type!==r.type?e.type==="directory"?-1:1:e.name.localeCompare(r.name)),z=d=>{if(!d)return"";const e=d.replace(/\\/g,"/"),r=e.startsWith("//");let m=e.replace(/\/+/g,"/");r&&!m.startsWith("//")&&(m=`/${m}`);const x=m==="/",v=/^[A-Za-z]:\/$/.test(m);return!x&&!v&&(m=m.replace(/\/+$/,"")),m},Oa=d=>d.startsWith("/")||d.startsWith("//")||/^[A-Za-z]:\//.test(d),Wt=d=>/^[A-Za-z]:\//.test(d)?d.toLowerCase():d,rs=(d,e)=>{const r=z(e),m=z(d);if(!r||!m)return!1;const x=Wt(r),v=Wt(m);return v===x||v.startsWith(`${x}/`)},Pi=(d,e)=>{const r=z(e),m=z(d);if(!rs(m,r))return[];const v=m.slice(r.length).replace(/^\//,"").split("/"),y=[];let b=r;for(let h=0;h<v.length-1;h++)b=b?`${b}/${v[h]}`:v[h],y.push(b);return y},Ss=(d,e)=>{if(!e)return"";const r=z(e);if(!d||!rs(r,d))return r;const m=r.slice(d.length);return m.startsWith("/")?m.slice(1):m},Ba=new Set(["node_modules"]),$a=d=>{const e=Ut.c(3),{status:r}=d;let m;e[0]===Symbol.for("react.memo_cache_sentinel")?(m={open:"var(--status-info)",modified:"var(--status-warning)","git-modified":"var(--status-warning)","git-added":"var(--status-success)","git-deleted":"var(--status-error)"},e[0]=m):m=e[0];const x=m[r];let v;return e[1]!==x?(v=s.jsx("span",{className:"size-2 rounded-full",style:{backgroundColor:x}}),e[1]=x,e[2]=v):v=e[2],v},Ri=d=>{const e=Ut.c(11),{name:r}=d,m=n.useRef(null),x=n.useRef(null),[v,y]=n.useState(!1);let b;e[0]===Symbol.for("react.memo_cache_sentinel")?(b=()=>{const M=m.current,E=x.current;if(!M||!E)return;const N=()=>{y(E.scrollWidth>M.clientWidth+1)};N();const P=new ResizeObserver(N);return P.observe(M),P.observe(E),()=>{P.disconnect()}},e[0]=b):b=e[0];let h;e[1]!==r?(h=[r],e[1]=r,e[2]=h):h=e[2],n.useLayoutEffect(b,h);let j;e[3]!==r?(j=s.jsx("span",{ref:x,"aria-hidden":"true",className:"invisible absolute whitespace-nowrap",children:r}),e[3]=r,e[4]=j):j=e[4];let p;e[5]!==r||e[6]!==v?(p=v?s.jsxs("span",{className:"open-file-name-marquee-track",children:[s.jsx("span",{className:"open-file-name-marquee-item",children:r}),s.jsx("span",{className:"open-file-name-marquee-item","aria-hidden":"true",children:r})]}):s.jsx("span",{className:"block min-w-0 truncate",children:r}),e[5]=r,e[6]=v,e[7]=p):p=e[7];let F;return e[8]!==j||e[9]!==p?(F=s.jsxs("span",{ref:m,className:"relative block min-w-0 flex-1 overflow-hidden whitespace-nowrap",children:[j,p]}),e[8]=j,e[9]=p,e[10]=F):F=e[10],F},Wa=d=>Ba.has(d),Ua=d=>{const e=z(d);return e==="node_modules"||e.endsWith("/node_modules")||e.includes("/node_modules/")},Ga=d=>{const r=(d instanceof Error?d.message:String(d??"")).toLowerCase();return r.includes("is a directory")||r.includes("eisdir")},Mi=d=>{const r=(d instanceof Error?d.message:String(d??"")).toLowerCase();return r.includes("file not found")||r.includes("enoent")||r.includes("no such file")||r.includes("does not exist")},ss=2e5,Ka=d=>{let e=0,r=0;for(let m=0;m<d.length;m+=1)d.charCodeAt(m)===10&&(m>0&&d.charCodeAt(m-1)===13?e+=1:r+=1);return e>r?`\r
|
|
2
|
-
`:`
|
|
3
|
-
`},Ui=d=>d.replace(/\r\n/g,`
|
|
4
|
-
`).replace(/\r/g,`
|
|
5
|
-
`),Ha=(d,e)=>{const r=Ui(d);return e===`\r
|
|
6
|
-
`?r.replace(/\n/g,`\r
|
|
7
|
-
`):r},Gi=(d,e)=>s.jsx(Ns,{filePath:d,extension:e}),zi=d=>{if(!d)return!1;const e=d.toLowerCase().split(".").pop();return e==="md"||e==="markdown"},qa=d=>{if(!d)return!1;const e=d.toLowerCase().split(".").pop();return e==="json"||e==="jsonc"||e==="json5"||e==="geojson"},ar=d=>{if(!d)return!1;const e=d.toLowerCase().split(".").pop();return e==="html"||e==="htm"},_a=d=>{const e=Ut.c(76),{node:r,root:m,isExpanded:x,isActive:v,isMobile:y,isBrowserClient:b,alwaysShowActions:h,status:j,badge:p,permissions:F,downloadFile:M,contextMenuPath:E,setContextMenuPath:N,rightClickMenuPath:P,setRightClickMenuPath:a,onSelect:q,onToggle:W,onRevealPath:_,onOpenDialog:L}=d,{t:T}=Vs(),V=r.type==="directory",{canRename:le,canCreateFile:X,canCreateFolder:Y,canDelete:A,canReveal:ce}=F,Le=!V&&!!M,U=ce&&!b,Q=le||X||Y||A||Le||U;let Z;e[0]!==Q||e[1]!==r.path||e[2]!==a?(Z=fe=>{Q&&(fe?.preventDefault(),a(r.path))},e[0]=Q,e[1]=r.path,e[2]=a,e[3]=Z):Z=e[3];const pe=Z;let ee;e[4]!==V||e[5]!==r||e[6]!==q||e[7]!==W?(ee=()=>{V?W(r.path):q(r)},e[4]=V,e[5]=r,e[6]=q,e[7]=W,e[8]=ee):ee=e[8];const ge=ee;let de;e[9]!==r.path||e[10]!==N||e[11]!==a?(de=fe=>{fe.stopPropagation(),a(null),N(r.path)},e[9]=r.path,e[10]=N,e[11]=a,e[12]=de):de=e[12];const rt=de;let Tt;e[13]!==X||e[14]!==Y||e[15]!==A||e[16]!==le||e[17]!==U||e[18]!==M||e[19]!==b||e[20]!==V||e[21]!==r||e[22]!==L||e[23]!==_||e[24]!==m||e[25]!==T?(Tt=fe=>{const{Item:ve,Separator:wt}=fe;return s.jsxs(s.Fragment,{children:[le&&s.jsxs(ve,{onClick:C=>{C.stopPropagation(),L("rename",r)},children:[s.jsx(g,{name:"edit",className:"mr-2 size-4"})," ",T("sidebarFilesTree.menu.rename")]}),s.jsxs(ve,{onClick:C=>{C.stopPropagation(),Ts(r.path).then(we=>{if(we.ok){I.success(T("sidebarFilesTree.toast.pathCopied"));return}I.error(T("sidebarFilesTree.toast.copyFailed"))})},children:[s.jsx(g,{name:"file-copy",className:"mr-2 size-4"})," ",T("sidebarFilesTree.menu.copyPath")]}),s.jsxs(ve,{onClick:C=>{C.stopPropagation();const we=Ss(m,r.path)||r.path;Ts(we).then(Qe=>{if(Qe.ok){I.success(T("filesView.toast.relativePathCopied"));return}I.error(T("sidebarFilesTree.toast.copyFailed"))})},children:[s.jsx(g,{name:"file-copy-2",className:"mr-2 size-4"})," ",T("filesView.tree.menu.copyRelativePath")]}),!V&&M&&s.jsxs(ve,{onClick:C=>{C.stopPropagation(),M(r.path).catch(we=>{console.error("Download failed:",we),I.error(T("sidebarFilesTree.toast.operationFailed"))})},children:[s.jsx(g,{name:"download",className:"mr-2 size-4"})," ",T(b?"sidebarFilesTree.menu.download":"sidebarFilesTree.menu.save")]}),U&&s.jsxs(ve,{onClick:C=>{C.stopPropagation(),_(r.path)},children:[s.jsx(g,{name:"folder-received",className:"mr-2 size-4"})," ",T(ga())]}),V&&(X||Y)&&s.jsxs(s.Fragment,{children:[s.jsx(wt,{}),X&&s.jsxs(ve,{onClick:C=>{C.stopPropagation(),L("createFile",r)},children:[s.jsx(g,{name:"file-add",className:"mr-2 size-4"})," ",T("sidebarFilesTree.menu.newFile")]}),Y&&s.jsxs(ve,{onClick:C=>{C.stopPropagation(),L("createFolder",r)},children:[s.jsx(g,{name:"folder-add",className:"mr-2 size-4"})," ",T("sidebarFilesTree.menu.newFolder")]})]}),A&&s.jsxs(s.Fragment,{children:[s.jsx(wt,{}),s.jsxs(ve,{onClick:C=>{C.stopPropagation(),L("delete",r)},className:"text-destructive focus:text-destructive",children:[s.jsx(g,{name:"delete-bin",className:"mr-2 size-4"})," ",T("sidebarFilesTree.menu.delete")]})]})]})},e[13]=X,e[14]=Y,e[15]=A,e[16]=le,e[17]=U,e[18]=M,e[19]=b,e[20]=V,e[21]=r,e[22]=L,e[23]=_,e[24]=m,e[25]=T,e[26]=Tt):Tt=e[26];const _e=Tt,G=P===r.path;let Fe;e[27]!==r.path||e[28]!==a?(Fe=fe=>a(fe?r.path:null),e[27]=r.path,e[28]=a,e[29]=Fe):Fe=e[29];const xt=y?void 0:pe;let Ae;e[30]!==xt?(Ae=s.jsx("div",{className:"group relative flex items-center",onContextMenu:xt}),e[30]=xt,e[31]=Ae):Ae=e[31];const Ie=y?void 0:pe,vt=v?"bg-interactive-selection/70":"hover:bg-interactive-hover/40";let xe;e[32]!==vt?(xe=O("flex w-full items-center gap-1.5 rounded-md px-2 py-1 text-left text-foreground transition-colors pr-8 select-none",vt),e[32]=vt,e[33]=xe):xe=e[33];let Oe;e[34]!==V||e[35]!==x||e[36]!==r.extension||e[37]!==r.path?(Oe=V?x?s.jsx(g,{name:"folder-open",className:"size-4 flex-shrink-0 text-muted-foreground"}):s.jsx(g,{name:"folder-3",className:"size-4 flex-shrink-0 text-muted-foreground"}):Gi(r.path,r.extension),e[34]=V,e[35]=x,e[36]=r.extension,e[37]=r.path,e[38]=Oe):Oe=e[38];let ue;e[39]!==r.name||e[40]!==r.path?(ue=s.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta",title:r.path,children:r.name}),e[39]=r.name,e[40]=r.path,e[41]=ue):ue=e[41];let Ne;e[42]!==V||e[43]!==j?(Ne=!V&&j&&s.jsx($a,{status:j}),e[42]=V,e[43]=j,e[44]=Ne):Ne=e[44];let it;e[45]!==p||e[46]!==V?(it=V&&p&&s.jsxs("span",{className:"text-xs flex items-center gap-1 ml-auto mr-1",children:[p.modified>0&&s.jsxs("span",{className:"text-[var(--status-warning)]",children:["M",p.modified]}),p.added>0&&s.jsxs("span",{className:"text-[var(--status-success)]",children:["+",p.added]})]}),e[45]=p,e[46]=V,e[47]=it):it=e[47];let nt;e[48]!==ge||e[49]!==xe||e[50]!==Oe||e[51]!==ue||e[52]!==Ne||e[53]!==it||e[54]!==Ie?(nt=s.jsxs("button",{type:"button",onClick:ge,onContextMenu:Ie,className:xe,children:[Oe,ue,Ne,it]}),e[48]=ge,e[49]=xe,e[50]=Oe,e[51]=ue,e[52]=Ne,e[53]=it,e[54]=Ie,e[55]=nt):nt=e[55];let Be;e[56]!==h||e[57]!==E||e[58]!==rt||e[59]!==Q||e[60]!==y||e[61]!==r.path||e[62]!==_e||e[63]!==N?(Be=Q&&s.jsx("div",{className:O("absolute right-1 top-1/2 -translate-y-1/2",h?"opacity-100":"opacity-0 focus-within:opacity-100 group-hover:opacity-100"),children:s.jsxs(or,{open:E===r.path,onOpenChange:fe=>N(fe?r.path:null),children:[s.jsx(lr,{asChild:!0,children:s.jsx(S,{variant:"ghost",size:"icon",className:"size-6",onClick:rt,children:s.jsx(g,{name:"more-2-fill",className:"size-4"})})}),s.jsx(cr,{align:"end",side:"bottom",onCloseAutoFocus:()=>N(null),children:_e({Item:Cs,Separator:pa})})]})}),e[56]=h,e[57]=E,e[58]=rt,e[59]=Q,e[60]=y,e[61]=r.path,e[62]=_e,e[63]=N,e[64]=Be):Be=e[64];let $e;e[65]!==nt||e[66]!==Be||e[67]!==Ae?($e=s.jsxs(ba,{render:Ae,children:[nt,Be]}),e[65]=nt,e[66]=Be,e[67]=Ae,e[68]=$e):$e=e[68];let We;e[69]!==_e?(We=s.jsx(xa,{className:"min-w-[180px]",children:_e({Item:wa,Separator:va})}),e[69]=_e,e[70]=We):We=e[70];let at;return e[71]!==$e||e[72]!==We||e[73]!==G||e[74]!==Fe?(at=s.jsxs(ya,{open:G,onOpenChange:Fe,children:[$e,We]}),e[71]=$e,e[72]=We,e[73]=G,e[74]=Fe,e[75]=at):at=e[75],at},Qa=d=>{const e=Ut.c(83),{activeDialog:r,dialogData:m,dialogInputValue:x,onDialogInputChange:v,isDialogSubmitting:y,onDialogSubmit:b,onClose:h,inputRef:j}=d,{t:p}=Vs(),F=!!r;let M;e[0]!==h?(M=de=>!de&&h(),e[0]=h,e[1]=M):M=e[1];let E;e[2]!==r||e[3]!==p?(E=r==="createFile"&&p("filesView.dialog.createFile.title"),e[2]=r,e[3]=p,e[4]=E):E=e[4];let N;e[5]!==r||e[6]!==p?(N=r==="createFolder"&&p("filesView.dialog.createFolder.title"),e[5]=r,e[6]=p,e[7]=N):N=e[7];let P;e[8]!==r||e[9]!==p?(P=r==="rename"&&p("filesView.dialog.rename.title"),e[8]=r,e[9]=p,e[10]=P):P=e[10];let a;e[11]!==r||e[12]!==p?(a=r==="delete"&&p("filesView.dialog.delete.title"),e[11]=r,e[12]=p,e[13]=a):a=e[13];let q;e[14]!==E||e[15]!==N||e[16]!==P||e[17]!==a?(q=s.jsxs(Bi,{children:[E,N,P,a]}),e[14]=E,e[15]=N,e[16]=P,e[17]=a,e[18]=q):q=e[18];let W;e[19]!==r||e[20]!==m?.path||e[21]!==p?(W=r==="createFile"&&p("filesView.dialog.createFile.description",{path:m?.path??p("filesView.dialog.rootFallback")}),e[19]=r,e[20]=m?.path,e[21]=p,e[22]=W):W=e[22];let _;e[23]!==r||e[24]!==m?.path||e[25]!==p?(_=r==="createFolder"&&p("filesView.dialog.createFolder.description",{path:m?.path??p("filesView.dialog.rootFallback")}),e[23]=r,e[24]=m?.path,e[25]=p,e[26]=_):_=e[26];let L;e[27]!==r||e[28]!==m?.name||e[29]!==p?(L=r==="rename"&&p("filesView.dialog.rename.description",{name:m?.name??""}),e[27]=r,e[28]=m?.name,e[29]=p,e[30]=L):L=e[30];let T;e[31]!==r||e[32]!==m?.name||e[33]!==p?(T=r==="delete"&&p("filesView.dialog.delete.description",{name:m?.name??""}),e[31]=r,e[32]=m?.name,e[33]=p,e[34]=T):T=e[34];let V;e[35]!==L||e[36]!==T||e[37]!==W||e[38]!==_?(V=s.jsxs($i,{children:[W,_,L,T]}),e[35]=L,e[36]=T,e[37]=W,e[38]=_,e[39]=V):V=e[39];let le;e[40]!==V||e[41]!==q?(le=s.jsxs(Oi,{children:[q,V]}),e[40]=V,e[41]=q,e[42]=le):le=e[42];let X;e[43]!==r||e[44]!==x||e[45]!==j||e[46]!==v||e[47]!==b||e[48]!==p?(X=r!=="delete"&&s.jsx("div",{className:"py-4",children:s.jsx(ks,{value:x,onChange:de=>v(de.target.value),placeholder:p(r==="rename"?"filesView.dialog.rename.placeholder":"filesView.dialog.namePlaceholder"),onKeyDown:de=>{de.key==="Enter"&&b()},ref:j})}),e[43]=r,e[44]=x,e[45]=j,e[46]=v,e[47]=b,e[48]=p,e[49]=X):X=e[49];let Y;e[50]!==p?(Y=p("filesView.dialog.cancel"),e[50]=p,e[51]=Y):Y=e[51];let A;e[52]!==y||e[53]!==h||e[54]!==Y?(A=s.jsx(S,{variant:"outline",onClick:h,disabled:y,children:Y}),e[52]=y,e[53]=h,e[54]=Y,e[55]=A):A=e[55];const ce=r==="delete"?"destructive":"default";let Le;e[56]!==b?(Le=()=>{b()},e[56]=b,e[57]=Le):Le=e[57];let U;e[58]!==r||e[59]!==x||e[60]!==y?(U=y||r!=="delete"&&!x.trim(),e[58]=r,e[59]=x,e[60]=y,e[61]=U):U=e[61];let Q;e[62]!==r||e[63]!==y||e[64]!==p?(Q=y?s.jsx(g,{name:"loader-4",className:"size-4 animate-spin"}):p(r==="delete"?"filesView.dialog.delete.confirm":"filesView.dialog.confirm"),e[62]=r,e[63]=y,e[64]=p,e[65]=Q):Q=e[65];let Z;e[66]!==ce||e[67]!==Le||e[68]!==U||e[69]!==Q?(Z=s.jsx(S,{variant:ce,onClick:Le,disabled:U,children:Q}),e[66]=ce,e[67]=Le,e[68]=U,e[69]=Q,e[70]=Z):Z=e[70];let pe;e[71]!==A||e[72]!==Z?(pe=s.jsxs(Wi,{children:[A,Z]}),e[71]=A,e[72]=Z,e[73]=pe):pe=e[73];let ee;e[74]!==j||e[75]!==le||e[76]!==X||e[77]!==pe?(ee=s.jsxs(Ii,{initialFocus:j,children:[le,X,pe]}),e[74]=j,e[75]=le,e[76]=X,e[77]=pe,e[78]=ee):ee=e[78];let ge;return e[79]!==F||e[80]!==M||e[81]!==ee?(ge=s.jsx(Ai,{open:F,onOpenChange:M,children:ee}),e[79]=F,e[80]=M,e[81]=ee,e[82]=ge):ge=e[82],ge},Li=(d,e,r)=>{const m=Ut.c(8),[x,v]=n.useState(""),[y,b]=n.useState(0);let h,j;m[0]!==d||m[1]!==r||m[2]!==e?(h=()=>{if(!d){v("");return}let F=!1;v("");const M=Qn(),E=Jn(M);Xn(M).then(P=>{F||!P||(v(d),e(null))}).catch(P=>{F||(e(P instanceof Error?P.message:r),v(d))});const N=Yn(()=>{F||(v(d),b(Ja),e(null))});return()=>{F=!0,E(),N()}},j=[d,e,r],m[0]=d,m[1]=r,m[2]=e,m[3]=h,m[4]=j):(h=m[3],j=m[4]),n.useEffect(h,j);let p;return m[5]!==y||m[6]!==x?(p={readyKey:x,nonce:y},m[5]=y,m[6]=x,m[7]=p):p=m[7],p},mc=({mode:d="full"})=>{const{t:e}=Vs(),{files:r,runtime:m}=Zn(),{currentTheme:x,availableThemes:v,lightThemeId:y,darkThemeId:b}=ea(),{isMobile:h,isTablet:j,screenWidth:p}=ta(),F=Un(m.platform),M=h||j,E=Gn(),N=Kn(),P=sa()??"",a=z(P.trim()),q=d!=="editor-only",W=d==="editor-only"&&!h,_=Hn(t=>t.searchFiles),L=ra(P),[T,V]=n.useState(""),le=ia(T,200),X=n.useRef(null),[Y,A]=n.useState(!1),[ce,Le]=n.useState(!0),[U,Q]=n.useState(!1),[Z,pe]=n.useState(!1),[ee,ge]=n.useState(!1),de=n.useRef(null),rt=n.useRef(0),Tt=n.useCallback(t=>{rt.current=Math.max(0,rt.current+(t?1:-1))},[]),_e=n.useCallback(t=>t instanceof Element?t.closest('[data-slot="dropdown-menu-content"], [data-slot="dropdown-menu-item"]')!==null:!1,[]);n.useEffect(()=>{if(!ee)return;const t=i=>{rt.current>0||_e(i.target)||de.current&&!de.current.contains(i.target)&&ge(!1)};return document.addEventListener("mousedown",t),()=>document.removeEventListener("mousedown",t)},[_e,ee]);const[G,Fe]=n.useState("edit"),[xt,Ae]=n.useState("edit"),[Ie,vt]=n.useState("tree"),[xe,Oe]=n.useState("edit"),[ue,Ne]=n.useState("preview"),[it,nt]=n.useState(0),Be=n.useRef({}),$e=n.useRef({}),We=n.useRef({}),at=n.useRef({}),fe=n.useMemo(()=>v.find(t=>t.metadata.id===y)??xi(!1),[v,y]),ve=n.useMemo(()=>v.find(t=>t.metadata.id===b)??xi(!0),[v,b]);n.useEffect(()=>{Vi(fe),Vi(ve)},[fe,ve]);const wt=n.useMemo(()=>[],[]),C=ze(t=>a?t.byRoot[a]?.openPaths??wt:wt),we=ze(t=>a?t.byRoot[a]?.selectedPath??null:null),Qe=ze(t=>a?t.byRoot[a]?.expandedPaths??wt:wt),Vt=ze(t=>t.removeOpenPath),ot=ze(t=>t.removeOpenPathsByPrefix),dr=ze(t=>t.removeExpandedPathsByPrefix),te=ze(t=>t.setSelectedPath),ur=ze(t=>t.toggleExpandedPath),is=ze(t=>t.expandPaths),Dt=n.useCallback(t=>{const i=z(t),o=i.split("/"),c=o[o.length-1]||i,u=c.includes(".")?c.split(".").pop()?.toLowerCase():void 0;return{name:c,path:i,type:"file",extension:u}},[]),Et=n.useMemo(()=>C.map(Dt),[C,Dt]),Ds=n.useMemo(()=>{if(we){const t=Wt(we);if(C.some(i=>Wt(i)===t))return we}return C[0]??null},[C,we]),l=n.useMemo(()=>Ds?Dt(Ds):null,[Ds,Dt]),Ue=l?.path??"";n.useEffect(()=>{if(!a||!we)return;const t=Wt(we);C.some(o=>Wt(o)===t)||te(a,C[0]??null)},[C,a,we,te]);const ns=!!(a&&Ue&&!rs(Ue,a)),fr=ns?yi(Ue):void 0,Ce=n.useMemo(()=>({allowOutsideWorkspace:d==="editor-only"&&ns,outsideFileGrant:fr,directory:a||void 0}),[d,ns,fr,a]),Es=n.useRef(null),[mr,Ki]=n.useState({left:!1,right:!1}),hr=n.useCallback(()=>{const t=Es.current;t&&Ki({left:t.scrollLeft>2,right:t.scrollLeft+t.clientWidth<t.scrollWidth-2})},[]),pr=n.useRef(hr);pr.current=hr,n.useEffect(()=>{const t=Es.current;if(!t)return;const i=()=>pr.current();i(),t.addEventListener("scroll",i,{passive:!0});const o=new ResizeObserver(i);return o.observe(t),()=>{t.removeEventListener("scroll",i),o.disconnect()}},[Et.length]);const[gr,Ps]=n.useState({}),[as,Gt]=n.useState({}),Se=n.useRef(new Set),ke=n.useRef(new Set),Je=n.useRef(new Map),xr=n.useRef(0),[vr,os]=n.useState([]),[Hi,ls]=n.useState(!1),[k,K]=n.useState(""),{isPlaying:cs,play:qi,stop:_i}=na(),[Ee,Xe]=n.useState(!1),[Ye,se]=n.useState(null),[Qi,Pe]=n.useState(""),[be,H]=n.useState(null),[B,J]=n.useState(""),[Pt,Rs]=n.useState(!1),[wr,Ji]=n.useState(`
|
|
8
|
-
`),Xi=n.useRef(null),Ge=n.useRef(null),ye=n.useRef(null),lt=n.useRef(""),Kt=n.useRef(""),Ze=n.useRef(null),br=n.useRef(null),et=n.useRef(null),ds=n.useRef(0),Ht=n.useRef(null),[Yi,Rt]=n.useState("idle"),[Zi,us]=n.useState(!1),[qt,yr]=n.useState(!1),re=he(t=>t.autoSaveEnabled),en=he(t=>t.setAutoSaveEnabled),[Ms,Mt]=n.useState(!1),zt=n.useRef(null),_t=n.useRef(null),Qt=n.useRef(null),bt=n.useRef(!1),Jt=n.useRef(null),Xt=n.useRef(null),Re=n.useRef(null),tn=n.useRef(null),[sn,zs]=n.useState(0),Lt=n.useRef(null),yt=n.useRef({key:"",attempts:0});n.useEffect(()=>()=>{Lt.current!==null&&typeof window<"u"&&(window.cancelAnimationFrame(Lt.current),Lt.current=null)},[]);const[jt,Ls]=n.useState(null),[Ft,rn]=n.useState(null),[ct,jr]=n.useState(""),[nn,As]=n.useState(!1),[an,on]=n.useState(null),[ln,cn]=n.useState(null),[dn,Fr]=n.useState(!1),[un,Nr]=n.useState(!1),[fn,Is]=n.useState(!1),Cr=!!r.writeFile,Sr=!!r.createDirectory,kr=!!r.rename,Tr=!!r.delete,Vr=!!r.revealPath,mn=Fs(t=>t.availableApps),hn=Fs(t=>t.isCacheStale),Dr=Fs(t=>t.initialize),pn=Fs(t=>t.loadInstalledApps);n.useEffect(()=>{Dr()},[Dr]);const gn=n.useCallback(t=>{r.revealPath&&r.revealPath(t).catch(()=>{I.error(e("sidebarFilesTree.toast.revealFailed"))})},[r,e]),xn=n.useCallback(async t=>{if(!l?.path||await qn(l.path,t.id,t.appName)||await vi(l.path,t.appName))return;const c=La(l.path)||a;c&&await vi(c,t.appName)||I.error(e("filesView.toast.openInAppFailed",{app:t.appName}))},[a,l?.path,e]),Os=n.useCallback((t,i)=>{Ls(t),rn(i),jr(t==="rename"&&i.name||""),As(!1)},[]),[R,Me]=n.useState(null),At=n.useRef(!1),dt=n.useRef(null),[Er,It]=n.useState(!1),Ke=he(t=>t.setMainTabGuard),He=he(t=>t.pendingFileNavigation),fs=he(t=>t.setPendingFileNavigation),Bs=he(t=>t.pendingFileFocusPath),$s=he(t=>t.setPendingFileFocusPath),Pr=he(t=>t.shortcutOverrides),Rr=he(t=>t.fileEditorKeymap),Yt=ji(t=>t.settingsDefaultFileViewerPreview),vn=ji(t=>t.showMessageTTSButtons),Mr=he(t=>t.expandedEditorToolbar);n.useEffect(()=>{const t=()=>{At.current=!1,dt.current=null,It(!1)};return document.addEventListener("mouseup",t),()=>document.removeEventListener("mouseup",t)},[]),n.useEffect(()=>()=>{Jt.current!==null&&window.clearTimeout(Jt.current),Xt.current!==null&&window.clearTimeout(Xt.current)},[]);const wn=n.useCallback((t,i)=>{const o=t.split(`
|
|
9
|
-
`),c=Math.max(1,i.start),u=Math.min(o.length,i.end);return c>u?"":o.slice(c-1,u).join(`
|
|
10
|
-
`)},[]),bn=Ta({source:"file",fileLabel:l?.path??null,language:l?.path&&er(l.path)||"text",getCodeForRange:t=>wn(k,Va(t)),toStoreRange:t=>({startLine:t.start,endLine:t.end}),fromDraftRange:t=>({start:t.startLine,end:t.endLine})}),{drafts:zr,commentText:ms,setCommentText:Lr,editingDraftId:hs,setSelection:Ar,saveComment:Ir,cancel:Zt,reset:Or,startEdit:Br,deleteDraft:$r}=bn;n.useEffect(()=>{Me(null),Or(),Ke(null),J(""),Rs(!1)},[l?.path,Or,Ke]),n.useEffect(()=>{Ar(R)},[R,Ar]),n.useEffect(()=>{if(!R&&!hs)return;const t=o=>{const c=o.target;c.closest('[data-comment-input="true"]')||c.closest('[data-comment-card="true"]')||c.closest(".cm-gutterElement")||c.closest("[data-sonner-toast]")||c.closest("[data-sonner-toaster]")||ms.trim()||(Me(null),Zt())},i=setTimeout(()=>{document.addEventListener("click",t)},100);return()=>{clearTimeout(i),document.removeEventListener("click",t)}},[Zt,ms,hs,R]);const Wr=n.useCallback((t,i)=>{const o=i??R??void 0;i&&Me(i),Ir(t,o),Me(null)},[R,Ir]),Ur=n.useCallback((t,i)=>{const o=[];for(const c of i){if(!(c&&typeof c.name=="string"&&c.name.length>0)||!E&&c.name.startsWith(".")||!N&&Wa(c.name))continue;const u=c.name,f=z(c.path||""),w=f?Oa(f)?f:z(`${t}/${f}`):z(`${t}/${u}`),D=c.isDirectory?"directory":"file",$=D==="file"&&u.includes(".")?u.split(".").pop()?.toLowerCase():void 0;o.push({name:u,path:w,type:D,extension:$})}return Ia(o)},[N,E]),Te=n.useCallback(async t=>{const i=z(t.trim());if(!i||Se.current.has(i)||ke.current.has(i))return;ke.current=new Set(ke.current),ke.current.add(i);const o=xr.current+1;xr.current=o,Je.current=new Map(Je.current),Je.current.set(i,o);const c=()=>Je.current.get(i)===o;await(r.listDirectory?r.listDirectory(i).then(f=>f.entries.map(w=>({name:w.name,path:w.path,isDirectory:w.isDirectory}))):_n.listLocalDirectory(i).then(f=>f.map(w=>({name:w.name,path:w.path,isDirectory:w.isDirectory})))).then(f=>{if(!c())return;const w=Ur(i,f);Se.current=new Set(Se.current),Se.current.add(i),Gt(D=>{if(!D[i])return D;const $={...D};return delete $[i],$}),Ps(D=>({...D,[i]:w}))}).catch(f=>{if(!c())return;const w=f instanceof Error?f.message:String(f??"");if(w==="Directory not found"&&a&&i!==a){dr(a,i),Gt(D=>{if(!D[i])return D;const $={...D};return delete $[i],$});return}console.error("Failed to load files directory:",f),Gt(D=>({...D,[i]:w}))}).finally(()=>{c()&&(Je.current=new Map(Je.current),Je.current.delete(i),ke.current=new Set(ke.current),ke.current.delete(i))})},[r,Ur,dr,a]),ps=n.useCallback(async()=>{a&&(Se.current=new Set,ke.current=new Set,Je.current=new Map,Gt({}),Ps(t=>Object.keys(t).length===0?t:{}),await Te(a))},[Te,a]),qe=n.useCallback(async t=>{if(!t){await ps();return}const i=z(t);Se.current=new Set(Se.current),Se.current.delete(i),ke.current=new Set(ke.current),ke.current.delete(i),await Te(i)},[Te,ps]),Gr=n.useRef(""),Kr=n.useRef("");n.useEffect(()=>{if(!a)return;const t=`${a}|h${E?"1":"0"}|g${N?"1":"0"}`,i=Gr.current!==a,o=Kr.current!==t;!i&&!o||(i&&(Gr.current=a,K(""),se(null),Pe(""),H(null),A(!1)),o&&(Kr.current=t,Se.current=new Set,ke.current=new Set,Je.current=new Map,Gt({}),Ps(c=>Object.keys(c).length===0?c:{}),Te(a)))},[Te,a,N,E]),n.useEffect(()=>{if(!r.listDirectory)return;const t=()=>{if(!document.hidden&&Qe.length>0)for(const i of Qe)qe(i)};return document.addEventListener("visibilitychange",t),()=>document.removeEventListener("visibilitychange",t)},[Qe,r.listDirectory,qe]),n.useEffect(()=>{if(!r.listDirectory||Qe.length===0)return;const t=setInterval(()=>{if(!document.hidden)for(const i of Qe)qe(i)},8e3);return()=>clearInterval(t)},[Qe,r.listDirectory,qe]);const yn=n.useCallback(async t=>{if(t?.preventDefault(),!Ft||!jt)return;As(!0);const i=()=>{Ls(null)},o=u=>{I.error(u)},c=()=>{As(!1)};if(jt==="createFile"){if(!ct.trim()){o(e("sidebarFilesTree.toast.filenameRequired")),c();return}if(!r.writeFile){o(e("sidebarFilesTree.toast.writeNotSupported")),c();return}const u=Ft.path,f=u?`${u}/`:"",w=z(`${f}${ct.trim()}`);await r.writeFile(w,"").then(async D=>{D.success&&(I.success(e("sidebarFilesTree.toast.fileCreated")),await qe(u)),i()}).catch(()=>o(e("sidebarFilesTree.toast.operationFailed"))).finally(c);return}if(jt==="createFolder"){if(!ct.trim()){o(e("sidebarFilesTree.toast.folderNameRequired")),c();return}const u=Ft.path,f=u?`${u}/`:"",w=z(`${f}${ct.trim()}`);await r.createDirectory(w).then(async D=>{D.success&&(I.success(e("sidebarFilesTree.toast.folderCreated")),await qe(u)),i()}).catch(()=>o(e("sidebarFilesTree.toast.operationFailed"))).finally(c);return}if(jt==="rename"){if(!ct.trim()){o(e("sidebarFilesTree.toast.nameRequired")),c();return}if(!r.rename){o(e("sidebarFilesTree.toast.renameNotSupported")),c();return}const u=Ft.path,f=u.split("/").slice(0,-1).join("/"),w=f?`${f}/`:"",D=z(`${w}${ct.trim()}`);await r.rename(u,D).then(async $=>{$.success&&(I.success(e("sidebarFilesTree.toast.renamedSuccessfully")),await qe(f),a&&ot(a,u),(l?.path===u||l?.path.startsWith(`${u}/`))&&(a&&te(a,null),K(""),se(null),Pe(""),H(null),h&&A(!1))),i()}).catch(()=>o(e("sidebarFilesTree.toast.operationFailed"))).finally(c);return}if(jt==="delete"){if(!r.delete){o(e("sidebarFilesTree.toast.deleteNotSupported")),c();return}const u=Ft.path,f=u.split("/").slice(0,-1).join("/");await r.delete(u).then(async w=>{w.success&&(I.success(e("sidebarFilesTree.toast.deletedSuccessfully")),await qe(f),a&&ot(a,u),(l?.path===u||l?.path.startsWith(`${u}/`))&&(a&&te(a,null),K(""),se(null),Pe(""),H(null),h&&A(!1))),i()}).catch(()=>o(e("sidebarFilesTree.toast.operationFailed"))).finally(c);return}c()},[jt,Ft,ct,r,qe,h,ot,a,l?.path,te,e]);n.useEffect(()=>{if(!P){os([]),ls(!1);return}const t=le.trim();if(!t){os([]),ls(!1);return}let i=!1;return ls(!0),_(P,t,150,{includeHidden:E,respectGitignore:!N,type:"file"}).then(o=>{if(i)return;const u=o.filter(f=>N||!Ua(f.path)).map(f=>({name:f.name,path:z(f.path),type:"file",extension:f.extension,relativePath:f.relativePath}));os(u)}).catch(()=>{i||os([])}).finally(()=>{i||ls(!1)}),()=>{i=!0}},[P,le,_,E,N]);const Hr=n.useCallback(async(t,i)=>{if(r.readFile)return(await r.readFile(t,{...i??{},directory:a||void 0})).content??"";const o=new URLSearchParams({path:t});i?.allowOutsideWorkspace&&o.set("allowOutsideWorkspace","true"),i?.outsideFileGrant&&o.set("outsideFileGrant",i.outsideFileGrant),i?.optional&&o.set("optional","true"),a&&o.set("directory",a);const c=await wi(`/api/fs/read?${o.toString()}`,{cache:i?.optional?"no-store":"default"});if(!c.ok){const u=await c.json().catch(()=>({error:c.statusText}));throw new Error(u.error||e("filesView.error.readFileFailed"))}return c.text()},[r,a,e]),ut=n.useCallback(async(t,i)=>{if(r.statFile){const o=await r.statFile(t,{...i??{},directory:a||void 0});return{path:o.path,size:o.size,mtimeMs:o.mtimeMs}}return null},[r,a]);n.useEffect(()=>{if(!a||!r.statFile||C.length===0)return;let t=!1;const i=[...C];return Promise.all(i.map(async o=>{try{const c=await r.statFile?.(o,{directory:a||void 0});!t&&c&&!c.isFile&&ot(a,o)}catch(c){!t&&Mi(c)&&ot(a,o)}})),()=>{t=!0}},[r,C,ot,a]);const Ws=n.useMemo(()=>k.length>ss?`${k.slice(0,ss)}
|
|
11
|
-
|
|
12
|
-
… truncated …`:k,[k]),ie=B!==Ws,Nt=n.useCallback(async()=>{if(!l||!r.writeFile)return I.error(e("filesView.toast.savingNotSupported")),!1;const t=js(l.path)||qt;if(!za({selectedFilePath:l.path,loadedFilePath:be,fileLoading:Ee,isDirty:ie,draftContent:B,fileContent:k,isNonEditableBinary:t}))return t?console.warn(`[saveDraft] refusing to save binary file "${l.path}".`):B===""&&k!==""&&be!==l.path&&console.warn(`[saveDraft] refusing to save empty draft for "${l.path}" (${k.length} bytes were expected). The file may have been read during a concurrent write (O_TRUNC race). Try again after content finishes loading if the save was intentional.`),!1;if(!ie)return!0;Rs(!0);try{const i=Ha(B,wr);if(!(await r.writeFile(l.path,i))?.success)return I.error(e("filesView.toast.writeFileFailed")),!1;if(K(B),a&&rs(l.path,a)){const c=Ss(a,l.path);c&&aa.requestGitRefresh({directory:a,paths:[c]})}if(a&&/(?:^|\/)\.agents\/loops\/[^/]+\.md$/i.test(z(l.path))){const c=oa.getState().projects.find(u=>z(u.path)===z(a));if(c)try{await Ea(c.id)}catch{I.error(e("sessions.scheduledTasks.dialog.toast.updateFailed"))}}return l?.path&&tr(l.path)&&(lt.current=B,Kt.current=B),ut(l.path).then(c=>{c&&(et.current=c)}).catch(()=>{}),!0}catch(i){return I.error(i instanceof Error?i.message:e("filesView.toast.saveFailed")),!1}finally{Rs(!1)}},[qt,B,k,Ee,r,ie,wr,be,ut,a,l,e]);n.useEffect(()=>{if(!ie){Ke(null);return}const t=i=>bt.current?(bt.current=!1,!0):(Mt(!0),_t.current=i,!1);return Ke(t),()=>{he.getState().mainTabGuard===t&&Ke(null)}},[ie,Ke]),n.useEffect(()=>{re||(Rt("idle"),Ge.current&&(clearTimeout(Ge.current),Ge.current=null))},[re]);const qr=1500;n.useEffect(()=>{const t=!!(l&&r.writeFile),i=!!(l?.path&&(js(l.path)||qt));if(Ma({autoSaveEnabled:re,isDirty:ie,canWrite:t,isSaving:Pt,fileLoading:Ee,selectedFilePath:l?.path,loadedFilePath:be,isNonEditableBinary:i}))return Ge.current=setTimeout(()=>{Nt().then(o=>{o&&(Rt("saved"),setTimeout(()=>Rt("idle"),2e3))})},qr),()=>{Ge.current&&(clearTimeout(Ge.current),Ge.current=null)}},[re,qt,B,Ee,ie,be,l,r.writeFile,Pt,Nt]),n.useEffect(()=>{Rt("idle")},[l?.path]),n.useEffect(()=>{const t=i=>{ma(i)&&(i.key.toLowerCase()==="s"?(i.preventDefault(),Ge.current&&(clearTimeout(Ge.current),Ge.current=null),Pt||Nt().then(o=>{o&&(Rt("saved"),setTimeout(()=>Rt("idle"),2e3))})):i.key.toLowerCase()==="f"&&(i.preventDefault(),pe(!0)))};return window.addEventListener("keydown",t),()=>window.removeEventListener("keydown",t)},[Pt,Nt]);const _r=n.useCallback(async t=>{const i=ds.current+1;ds.current=i;const o=()=>{if(!a)return!1;const je=ze.getState().byRoot[a],oe=je?.selectedPath??je?.openPaths[0]??null;return ds.current===i&&oe===t.path};se(null),Pe(""),H(null),yr(!1);const c=Fi(t.path),u=Ni(t.path),f=Ci(t.path),w=js(t.path);if(h&&A(!0),m.isDesktop&&c&&!u){K(""),J(""),Xe(!0);return}if(!m.isDesktop&&c&&!u){K(""),J(""),H(t.path),Xe(!1);return}if(f){K(""),J(""),H(t.path),Xe(!1);return}if(w){K(""),J(""),H(t.path),Xe(!1);return}Xe(!0);const D=yi(t.path),$={allowOutsideWorkspace:d==="editor-only"&&!!a&&!rs(t.path,a),outsideFileGrant:D};await Hr(t.path,$).then(je=>{if(!o())return;if(la(je)){yr(!0),K(""),J(""),H(t.path);return}const oe=Ui(je);Ji(Ka(je)),K(oe),lt.current=oe,Kt.current=oe,J(oe.length>ss?`${oe.slice(0,ss)}
|
|
13
|
-
|
|
14
|
-
… truncated …`:oe),H(t.path),ut(t.path,$).then(Ct=>{Ct&&o()&&(et.current=Ct)}).catch(()=>{})}).catch(je=>{if(o()){if(Ga(je)){if(Xe(!1),a&&te(a,null),se(null),K(""),J(""),H(null),et.current=null,T.trim().length>0&&V(""),h&&A(!1),a){const Ct=[...Pi(t.path,a),t.path];Ct.length>0&&is(a,Ct);for(const Ys of Ct)Se.current.has(Ys)||Te(Ys)}return}if(Mi(je)){a&&ot(a,t.path),K(""),J(""),se(null),et.current=null,h&&A(!1);return}K(""),J(""),se(je instanceof Error?je.message:e("filesView.error.readFileFailed")),et.current=null}}).finally(()=>{o()&&Xe(!1)})},[is,h,Te,d,Hr,ut,ot,a,m.isDesktop,T,te,e]),gs=n.useCallback(async(t,i)=>{if(!a)return;const o=Pi(t,a),c=i?[...o,t]:o;c.length>0&&is(a,c);const u=c.map(f=>{if(!Se.current.has(f))return Te(f)}).filter(Boolean);await Promise.all(u)},[is,Te,a]),Qr=n.useCallback((t,i)=>{const o=i.findIndex(c=>c.path===t);return o===-1||i.length<=1?null:i[o+1]??i[o-1]??null},[]),me=n.useCallback(async t=>{if(bt.current)bt.current=!1;else if(ie){Mt(!0),zt.current=t;return}a&&(te(a,t.path),gs(t.path,!1)),se(null),Pe(""),K(""),lt.current="",Kt.current="",J(""),H(null),h&&A(!0)},[gs,ie,h,a,te]);n.useEffect(()=>{l?.path&&gs(l.path,!1)},[gs,l?.path]),n.useEffect(()=>{if(!l){ds.current+=1,Ht.current=null,Xe(!1);return}if(be===l.path||Ht.current===l.path)return;const t=l.path;Ht.current=t,_r(l).finally(()=>{Ht.current===t&&(Ht.current=null)})},[_r,be,l]);const Jr=n.useRef(ie);Jr.current=ie,n.useEffect(()=>{if(!l?.path||be!==l.path)return;let t=!1;const i=window.setInterval(()=>{document.hidden||ut(l.path,Ce).then(o=>{if(t||!o)return;const c=et.current;if(!c||c.path!==l.path){et.current=o;return}const u=o.mtimeMs!==void 0&&c.mtimeMs!==void 0&&o.mtimeMs!==c.mtimeMs,f=o.size!==c.size;!u&&!f||Jr.current||(et.current=o,H(null))}).catch(()=>{})},2e3);return()=>{t=!0,window.clearInterval(i)}},[be,ut,l?.path,Ce]);const jn=n.useCallback(()=>{const t=zt.current,i=_t.current,o=Qt.current;if(zt.current=null,_t.current=null,Qt.current=null,bt.current=!0,Mt(!1),J(Ws),o){a&&Vt(a,o),l?.path===o&&(t?me(t):(a&&te(a,null),K(""),se(null),Pe(""),H(null),h&&A(!1)));return}if(t){me(t);return}i&&(Ke(null),he.getState().setActiveMainTab(i))},[Ws,me,h,Vt,a,l?.path,Ke,te]),Fn=n.useCallback(async()=>{const t=zt.current,i=_t.current,o=Qt.current;if(!await Nt()){bt.current=!1;return}if(zt.current=null,_t.current=null,Qt.current=null,bt.current=!0,Mt(!1),o){a&&Vt(a,o),l?.path===o&&(t?await me(t):(a&&te(a,null),K(""),se(null),Pe(""),H(null),h&&A(!1)));return}if(t){await me(t);return}i&&(Ke(null),he.getState().setActiveMainTab(i))},[me,h,Vt,a,Nt,l?.path,Ke,te]),Xr=n.useCallback(t=>{const i=l?.path===t,o=Qr(t,Et);if(i&&ie){Mt(!0),zt.current=o,Qt.current=t;return}if(a&&Vt(a,t),!!i){if(o){me(o);return}a&&te(a,null),K(""),se(null),Pe(""),H(null),h&&A(!1)}},[Qr,me,ie,h,Et,Vt,a,l?.path,te]),Nn=n.useCallback(t=>{if(C.includes(t))return"open";if(L?.files){const i=t.startsWith(a+"/")?t.slice(a.length+1):t,o=L.files.find(c=>c.path===i);if(o){if(o.index==="A"||o.working_dir==="?")return"git-added";if(o.index==="D")return"git-deleted";if(o.index==="M"||o.working_dir==="M")return"git-modified"}}return null},[C,L,a]),Cn=n.useCallback(t=>{if(!L?.files)return null;const i=t.startsWith(a+"/")?t.slice(a.length+1):t,o=i?`${i}/`:"";let c=0,u=0;for(const f of L.files)f.path.startsWith(o)&&((f.index==="M"||f.working_dir==="M")&&c++,(f.index==="A"||f.working_dir==="?")&&u++);return c+u>0?{modified:c,added:u}:null},[L,a]),Sn=n.useCallback(async t=>{const i=z(t);a&&(ur(a,i),Se.current.has(i)||await Te(i))},[Te,a,ur]),kn=n.useMemo(()=>({canRename:kr,canCreateFile:Cr,canCreateFolder:Sr,canDelete:Tr,canReveal:Vr}),[kr,Cr,Sr,Tr,Vr]);function Yr(t,i){const o=gr[t]??[];return o.map((c,u)=>{const f=c.type==="directory",w=f&&Qe.includes(c.path),D=l?.path===c.path,$=u===o.length-1;return s.jsxs("li",{className:"relative",children:[i>0&&s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"absolute top-3.5 left-[-12px] w-3 h-px bg-border/40"}),$&&s.jsx("span",{className:"absolute top-3.5 bottom-0 left-[-13px] w-[2px] bg-background"})]}),s.jsx(_a,{node:c,root:a,isExpanded:w,isActive:D,isMobile:h,isBrowserClient:F,alwaysShowActions:M,status:f?void 0:Nn(c.path),badge:f?Cn(c.path):void 0,permissions:kn,downloadFile:r.downloadFile,contextMenuPath:an,setContextMenuPath:on,rightClickMenuPath:ln,setRightClickMenuPath:cn,onSelect:me,onToggle:Sn,onRevealPath:gn,onOpenDialog:Os}),f&&w&&s.jsxs("ul",{className:"flex flex-col gap-1 ml-3 pl-3 border-l border-border/40 relative",children:[as[c.path]?s.jsxs("li",{className:"flex items-center gap-2 px-2 py-1 typography-meta text-muted-foreground",children:[s.jsx("span",{className:"min-w-0 flex-1 truncate text-[var(--status-error)]",title:as[c.path],children:as[c.path]}),s.jsxs(S,{variant:"ghost",size:"xs",className:"h-6 gap-1",onClick:()=>{qe(c.path)},children:[s.jsx(g,{name:"refresh",className:"size-3.5"}),e("filesView.tree.actions.refreshTitle")]})]}):null,Yr(c.path,i+1)]})]},c.path)})}const ne=!!(l?.path&&Fi(l.path)),xs=!!(l?.path&&Ni(l.path)),Ve=!!(l?.path&&Ci(l.path)),Us=!!(l?.path&&(js(l.path)||qt)),tt=Us&&!ne&&!Ve,Zr=n.useMemo(()=>z(He?.path??""),[He?.path]),Ot=!!(He&&Zr&&Ue&&Ue===Zr&&!Ee&&!Ye&&!ne&&!Ve&&!tt),ft=n.useMemo(()=>Ss(a,Ue),[Ue,a]),Tn=!!(l&&(!ne||xs)&&!Ve&&!tt&&k.length>0),Vn=!!(l&&ft.length>0),De=!!(l&&!ns&&!Us&&!ne&&r.writeFile&&k.length<=ss),mt=!!(l?.path&&zi(l.path)),es=!!(l?.path&&qa(l.path)),Bt=!!(l?.path&&ar(l.path)),ts=!!(l?.path&&tr(l.path)),Gs=!!(l&&!Us&&!ne)&&!mt&&!ts&&!(Bt&&xe==="preview"),Dn=mt&&xt==="edit"||Bt&&xe==="edit"||es&&Ie==="text"||!mt&&!Bt&&!es&&G==="edit",vs=n.useMemo(()=>Ue?ca(Ue):null,[Ue]),[ei,Ks]=n.useState(null);n.useEffect(()=>{let t=!1;const i=l?.path;if(!i||vs){Ks(null);return}return Ks(null),da(i).then(o=>{t||Ks(o)}),()=>{t=!0}},[l?.path,vs]),n.useEffect(()=>{!De&&G==="edit"&&Fe("view")},[De,G]);const Hs="openchamber:files:md-viewer-mode",qs="openchamber:files:html-viewer-mode",_s="openchamber:files:json-viewer-mode";n.useEffect(()=>{const t=l?.path;if(!t)return;Fe(Be.current[t]??"edit");let i=Yt?"preview":"edit";try{const u=localStorage.getItem(Hs);(u==="preview"||u==="edit")&&(i=u)}catch{}Ae($e.current[t]??i);let o=Yt?"preview":"edit";try{const u=localStorage.getItem(qs);(u==="preview"||u==="edit")&&(o=u)}catch{}Oe(We.current[t]??o),Ne(at.current[t]??(Yt?"preview":"edit"));let c=Yt?"tree":"text";try{const u=localStorage.getItem(_s);(u==="tree"||u==="text")&&(c=u)}catch{}vt(c)},[l?.path,Yt]);const En=n.useCallback(t=>{const i=l?.path;i&&(Be.current[i]=t),Fe(t)},[l?.path]),ti=n.useCallback(t=>{const i=l?.path;i&&($e.current[i]=t),Ae(t);try{localStorage.setItem(Hs,t)}catch{}},[l?.path]),ae=n.useCallback(()=>xt,[xt]),Pn=n.useCallback(t=>{vt(t);try{localStorage.setItem(_s,t)}catch{}},[]),Rn=n.useCallback(t=>{const i=l?.path;i&&(We.current[i]=t),Oe(t);try{localStorage.setItem(qs,t)}catch{}},[l?.path]),Mn=n.useCallback(t=>{const i=l?.path;if(i&&(at.current[i]=t),ye.current&&(clearTimeout(ye.current),ye.current=null),Ze.current!==null&&(cancelAnimationFrame(Ze.current),Ze.current=null),t==="edit")J(lt.current||k),Ne(t);else{lt.current=B;const o=i;Ne("edit"),Ze.current=requestAnimationFrame(()=>{Ze.current=requestAnimationFrame(()=>{Ze.current=null,!(a&&o&&ze.getState().byRoot[a]?.selectedPath!==o)&&(nt(c=>c+1),Ne("preview"))})});return}},[B,k,a,l?.path]),Qs=n.useCallback(async(t,i)=>{if(!r.writeFile||i===Kt.current)return!1;if(!(await r.writeFile(t,i))?.success)return I.error(e("filesView.toast.writeFileFailed")),!1;lt.current=i,Kt.current=i,J(i);const c=await ut(t,Ce).catch(()=>null);return c&&(et.current=c),!0},[r,ut,Ce,e]);n.useEffect(()=>()=>{ye.current&&(clearTimeout(ye.current),ye.current=null),Ze.current!==null&&(cancelAnimationFrame(Ze.current),Ze.current=null)},[ue,l?.path]);const zn=n.useCallback(t=>{if(lt.current=t,!re||!l?.path||ue!=="preview"||!r.writeFile)return;ye.current&&clearTimeout(ye.current);const i=l.path;ye.current=setTimeout(()=>{ye.current=null,Qs(i,t).then(o=>{o&&(us(!0),setTimeout(()=>us(!1),1500))}).catch(o=>{I.error(o instanceof Error?o.message:e("filesView.toast.saveFailed"))})},qr)},[re,ue,r.writeFile,Qs,l?.path,e]),Ln=n.useMemo(()=>ts&&(lt.current||B)||k,[B,k,ts]),si=n.useCallback(()=>xe,[xe]);n.useEffect(()=>{const t=o=>{const c=o?"preview":"edit",u=o?"tree":"text";for(const f of C)Be.current[f]="edit",zi(f)&&($e.current[f]=c),ar(f)&&(We.current[f]=c),tr(f)&&(at.current[f]=c);Fe("edit"),Ae(c),Oe(c),Ne(c),vt(u);try{localStorage.setItem(Hs,c),localStorage.setItem(qs,c),localStorage.setItem(_s,u)}catch{}},i=o=>{const c=!!o.detail?.enabled;t(c)};return window.addEventListener("openchamber:file-viewer-preview-mode-changed",i),()=>{window.removeEventListener("openchamber:file-viewer-preview-mode-changed",i)}},[C]),n.useEffect(()=>{if(!He||!a)return;const t=()=>{typeof window>"u"||Lt.current===null&&(Lt.current=window.requestAnimationFrame(()=>{Lt.current=null,zs(st=>st+1)}))},i=(st,St)=>{if(st.state.doc.length!==St.length)return!1;if(St.length===0)return!0;const Zs=Math.min(128,St.length);if(st.state.sliceDoc(0,Zs)!==St.slice(0,Zs))return!1;const gi=Math.max(0,St.length-Zs);return st.state.sliceDoc(gi,St.length)===St.slice(gi)},o=z(He.path);if(!o){fs(null),yt.current={key:"",attempts:0};return}const c=`${o}:${He.line}:${He.column??1}`;if(yt.current.key!==c&&(yt.current={key:c,attempts:0}),l?.path!==o){if(Ms)return;me(Dt(o));return}if(Ee||be!==o)return;if(Ye||ne||Ve||tt){fs(null),yt.current={key:"",attempts:0};return}if(!De)return;if(G!=="edit"){Fe("edit");return}const u=Re.current;if(!u){t();return}if(!i(u,B)){t();return}const f=Math.max(1,Math.min(He.line,u.state.doc.lines)),w=u.state.doc.line(f),D=Math.max(1,He.column||1),$=Math.max(0,w.to-w.from),je=Math.min($,D-1),oe=w.from+je;if(!(u.state.selection.main.head===oe)||yt.current.attempts===0){yt.current.attempts+=1,u.dispatch({selection:{anchor:oe},effects:kt.scrollIntoView(oe,{y:"center"})}),u.focus(),t();return}typeof window<"u"&&window.requestAnimationFrame(()=>{const st=Re.current;st&&(st.dispatch({selection:{anchor:oe},effects:kt.scrollIntoView(oe,{y:"center"})}),st.focus())}),fs(null),yt.current={key:"",attempts:0}},[De,Ms,B,sn,Ye,Ee,ne,Ve,tt,be,me,He,a,l?.path,fs,G,Dt]),n.useEffect(()=>{if(!Bs||!a)return;const t=z(Bs);if(!t){$s(null);return}l?.path===t&&(Ee||be!==t||(!Ye&&!ne&&!Ve&&!tt&&De&&G==="edit"&&Re.current?.focus(),$s(null)))},[De,Ye,Ee,ne,Ve,tt,be,Bs,a,l?.path,$s,G]);const $t=n.useCallback(t=>{if(!h||!t||!t.hasFocus||typeof window>"u")return;const i=window.visualViewport;if(!i)return;const o=document.documentElement.clientHeight||window.innerHeight;if(Math.max(0,o-(i.offsetTop+i.height))<=0)return;const u=t.state.selection.main.head,f=t.coordsAtPos(u);if(!f)return;const w=Math.round(i.offsetTop+i.height),$=f.bottom+20-w;$<=0||(t.scrollDOM.scrollTop+=$)},[h]);n.useEffect(()=>{if(!h||typeof window>"u")return;const t=()=>{window.requestAnimationFrame(()=>{$t(Re.current)})},i=window.visualViewport;return i?.addEventListener("resize",t),i?.addEventListener("scroll",t,{passive:!0}),document.addEventListener("selectionchange",t),()=>{i?.removeEventListener("resize",t),i?.removeEventListener("scroll",t),document.removeEventListener("selectionchange",t)}},[h,$t]),n.useEffect(()=>{if(!De||G!=="edit"||h)return;const t=ua("open_go_to_line",Pr),i=o=>{const c=o.target;if(c?.closest('[role="dialog"]'))return;const u=!!c?.closest(".cm-editor");c?.closest('input, textarea, [contenteditable="true"], [role="textbox"]')&&!u||!document.activeElement?.closest(".cm-editor")||ha(o,t)&&(o.preventDefault(),Is(!0))};return window.addEventListener("keydown",i),()=>window.removeEventListener("keydown",i)},[De,h,Pr,G]);const ws=he(t=>t.editorFontSize),ri=n.useMemo(()=>{if(!l?.path)return[ki(x,{fontSize:ws})];const t=er(l.path),i=[ki(x,t?{syntaxColors:!1,fontSize:ws}:{fontSize:ws})],o=vs??ei;return o&&i.push(o),t&&i.push(ja({language:t,themeName:x.metadata.id,theme:Sa(x)})),ce&&i.push(kt.lineWrapping),h&&i.push(kt.updateListener.of(c=>{c.view.hasFocus&&(c.selectionSet||c.focusChanged||c.viewportChanged||c.geometryChanged)&&window.requestAnimationFrame(()=>{$t(c.view)})})),i},[x,l?.path,vs,ei,ce,h,$t,ws]),ii=n.useMemo(()=>({light:fe.metadata.id,dark:ve.metadata.id}),[fe.metadata.id,ve.metadata.id]),bs=l?.path&&Ve?`${l.path}|${Ce.allowOutsideWorkspace?"outside":"workspace"}|${Ce.outsideFileGrant??""}`:"",ys=l?.path&&Bt&&xe==="preview"&&!m.isVSCode?l.path:"",ni=e("filesView.error.readFileFailed"),{readyKey:ai,nonce:An}=Li(ys,se,ni),{readyKey:oi,nonce:li}=Li(bs,se,ni),In=!!(ys&&ai!==ys),ci=!!(bs&&oi!==bs),di=l?.path&&ne?xs?`data:${fa(l.path)};utf8,${encodeURIComponent(k)}`:Qi:"",ui=l?.path&&Ve&&oi===bs?bi().authenticatedAsset("/api/fs/raw",{path:l.path,allowOutsideWorkspace:Ce.allowOutsideWorkspace?"true":void 0,outsideFileGrant:Ce.outsideFileGrant,directory:a||void 0}):"",fi=n.useCallback(t=>s.jsx("div",{className:"h-full overflow-hidden bg-[var(--surface-background)]",children:s.jsx("iframe",{src:ui,className:"h-full w-full border-0",title:t.name},li)}),[ui,li]);n.useEffect(()=>{let t=!1,i="";return(async()=>{if(!l?.path||!ne||xs){Pe("");return}se(null),await(r.readFileBinary?r.readFileBinary(l.path,Ce).then(u=>u.dataUrl):(async()=>{const u=await wi("/api/fs/raw",{query:{path:l.path,allowOutsideWorkspace:Ce.allowOutsideWorkspace?"true":void 0,outsideFileGrant:Ce.outsideFileGrant,directory:a||void 0}});if(!u.ok)throw new Error(e("filesView.error.readFileFailed"));const f=await u.blob();return i=URL.createObjectURL(f),t?(URL.revokeObjectURL(i),i="",""):i})()).then(u=>{t||(Pe(u),H(l.path))}).catch(u=>{t||(Pe(""),se(u instanceof Error?u.message:e("filesView.error.readFileFailed")),H(null))}).finally(()=>{t||Xe(!1)})})(),()=>{t=!0,i&&URL.revokeObjectURL(i)}},[r,ne,xs,a,l?.path,Ce,e]);const On=n.useCallback(()=>Ls(null),[]),Bn=n.useMemo(()=>Da({drafts:zr,editingDraftId:hs,commentText:ms,onTextChange:Lr,selection:R,isDragging:Er,fileLabel:l?.path??"",newWidgetId:"files-new-comment-input",mapDraftToRange:t=>({start:t.startLine,end:t.endLine}),onSave:Wr,onCancel:()=>{Me(null),Zt()},onEdit:t=>{Br(t),Me({start:t.startLine,end:t.endLine})},onDelete:$r}),[Zt,ms,$r,hs,zr,Wr,Er,R,l?.path,Lr,Br]),mi=n.useCallback((t,i)=>s.jsx("div",{className:"h-full",children:s.jsx(Na,{file:{name:t.name,contents:i,lang:er(t.path)||void 0},options:{disableFileHeader:!0,overflow:ce?"wrap":"scroll",theme:ii,themeType:x.metadata.variant==="dark"?"dark":"light"},className:"block h-full w-full",style:{height:"100%"}})}),[x.metadata.variant,ii,ce]),Js=({exitFullscreenOnly:t=!1,layout:i="floating"}={})=>{if(!l)return null;const c=i==="docked"?"pointer-events-auto flex flex-wrap items-center gap-1":"pointer-events-auto flex items-center gap-1 rounded-lg border border-[var(--interactive-border)] bg-[var(--surface-elevated)] p-1 shadow-sm",u=(f,w)=>s.jsxs(ht,{children:[s.jsx(pt,{asChild:!0,children:s.jsx("span",{className:"inline-flex",children:w})}),s.jsx(gt,{side:"bottom",sideOffset:6,children:f})]});return s.jsxs("div",{className:c,children:[De&&Dn&&s.jsxs(s.Fragment,{children:[Pt?s.jsxs("span",{className:"flex items-center gap-1 px-1 text-muted-foreground typography-meta",children:[s.jsx(g,{name:"loader-4",className:"size-3.5 animate-spin"}),e("filesView.editor.saving")]}):re&&Yi==="saved"&&!ie?s.jsxs("span",{className:"flex items-center gap-1 px-1 text-[color:var(--status-success)] typography-meta",children:[s.jsx(g,{name:"check",className:"size-3.5"}),e("filesView.editor.saved")]}):ie?u(e(re?"filesView.editor.saveNowTitle":"filesView.editor.saveNowManualTitle",{shortcut:`${ir()}+S`}),s.jsx(S,{variant:"ghost",size:"sm",onClick:()=>{Nt()},className:"h-6 gap-1 px-1 text-muted-foreground opacity-80 hover:bg-transparent hover:opacity-100 focus-visible:bg-transparent active:bg-transparent",title:e(re?"filesView.editor.saveNowTitle":"filesView.editor.saveNowManualTitle",{shortcut:`${ir()}+S`}),"aria-label":e("filesView.editor.saveAria",{shortcut:`${ir()}+S`}),children:s.jsx(g,{name:"save-3",className:"size-4"})})):null,u(e(re?"filesView.editor.autoSaveOn":"filesView.editor.manualSave"),s.jsx(S,{variant:"ghost",size:"sm",onClick:()=>en(!re),className:O("size-6 p-0 transition-opacity hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",re?"text-foreground opacity-100":"text-muted-foreground opacity-65 hover:opacity-100"),title:e(re?"filesView.editor.autoSaveOn":"filesView.editor.manualSave"),"aria-label":e(re?"filesView.editor.autoSaveOn":"filesView.editor.manualSave"),children:re?s.jsx(g,{name:"file-check-fill",className:"size-4"}):s.jsx(g,{name:"file-check",className:"size-4"})}))]}),s.jsxs(or,{onOpenChange:Tt,children:[s.jsxs(ht,{children:[s.jsx(pt,{asChild:!0,children:s.jsx("span",{className:"inline-flex",children:s.jsx(lr,{asChild:!0,children:s.jsx(S,{variant:"ghost",size:"sm",className:"size-6 p-0 text-foreground opacity-100 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e("filesView.editor.openInDesktopApp"),"aria-label":e("filesView.editor.openInDesktopApp"),children:s.jsx(g,{name:"file-transfer",className:"size-4"})})})})}),s.jsx(gt,{side:"bottom",sideOffset:6,children:e("filesView.editor.openInDesktopApp")})]}),s.jsxs(cr,{align:"end",className:"w-56 max-h-[70vh] overflow-y-auto",children:[mn.map(f=>s.jsxs(Cs,{className:"flex items-center gap-2",onClick:()=>{xn(f)},children:[s.jsx(Aa,{label:f.label,iconDataUrl:f.iconDataUrl}),s.jsx("span",{className:"typography-ui-label text-foreground",children:f.label})]},f.id)),hn?s.jsxs(Cs,{className:"flex items-center gap-2",onClick:()=>{pn(!0)},children:[s.jsx(g,{name:"refresh",className:"size-4"}),s.jsx("span",{className:"typography-ui-label text-foreground",children:e("filesView.editor.refreshApps")})]}):null]})]}),!ne&&!Ve&&!tt&&s.jsxs(s.Fragment,{children:[u(e(ce?"filesView.editor.disableLineWrap":"filesView.editor.enableLineWrap"),s.jsx(S,{variant:"ghost",size:"sm",onClick:()=>Le(!ce),className:O("size-6 p-0 transition-opacity hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",ce?"text-foreground opacity-100":"text-muted-foreground opacity-65 hover:opacity-100"),title:e(ce?"filesView.editor.disableLineWrap":"filesView.editor.enableLineWrap"),children:s.jsx(g,{name:"text-wrap",className:"size-4"})})),G==="edit"&&s.jsxs(s.Fragment,{children:[u(e("filesView.editor.findInFile"),s.jsx(S,{variant:"ghost",size:"sm",onClick:f=>{pe(!Z),f.currentTarget.blur()},className:"size-6 p-0 text-foreground opacity-100 transition-opacity hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e("filesView.editor.findInFile"),children:s.jsx(g,{name:"search",className:"size-4"})})),u(e("filesView.editor.goToLine"),s.jsx(S,{variant:"ghost",size:"sm",onClick:f=>{Is(w=>!w),f.currentTarget.blur()},className:"size-6 p-0 text-foreground opacity-100 transition-opacity hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e("filesView.editor.goToLine"),children:s.jsx(g,{name:"menu-fold-2",className:"size-4"})})),s.jsx(Ra,{open:fn,onOpenChange:Is,view:Re.current,variant:"inline"})]})]}),Gs&&De&&!es&&!Bt&&s.jsx(nr,{currentMode:G==="view"?"preview":"edit",onToggle:()=>{En(G==="view"?"edit":"view")}}),mt&&u(e(ae()==="preview"?"filesView.editor.switchToEditMode":"filesView.editor.switchToPreviewMode"),s.jsx(S,{variant:"ghost",size:"sm",onClick:()=>ti(ae()==="preview"?"edit":"preview"),className:O("size-6 p-0 transition-colors hover:bg-[var(--interactive-hover)] focus-visible:bg-[var(--interactive-hover)] active:bg-[var(--interactive-hover)]",ae()==="preview"?"bg-[var(--interactive-selection)] text-[var(--interactive-selection-foreground)] hover:bg-[var(--interactive-selection)] focus-visible:bg-[var(--interactive-selection)] active:bg-[var(--interactive-selection)]":"text-muted-foreground opacity-65 hover:opacity-100"),title:e(ae()==="preview"?"filesView.editor.switchToEditMode":"filesView.editor.switchToPreviewMode"),"aria-label":e(ae()==="preview"?"filesView.editor.switchToEditMode":"filesView.editor.switchToPreviewMode"),children:s.jsx(g,{name:ae()==="preview"?"eye":"eye-off",className:"size-4"})})),ar(l?.path??"")&&s.jsx(nr,{currentMode:si(),onToggle:()=>{Rn(si()==="preview"?"edit":"preview")}}),mt&&ae()==="preview"&&vn&&s.jsxs(ht,{children:[s.jsx(pt,{asChild:!0,children:s.jsx(S,{variant:"ghost",size:"sm",className:"size-6 p-0 text-muted-foreground opacity-65 hover:bg-transparent hover:opacity-100 focus-visible:bg-transparent active:bg-transparent","aria-label":e(cs?"filesView.tts.stopSpeaking":"filesView.tts.readAloud"),onClick:()=>{cs?_i():k.trim()&&qi(k)},children:cs?s.jsx(g,{name:"stop",className:"size-4 text-[color:var(--status-success)]"}):s.jsx(g,{name:"volume-up",className:"size-4"})})}),s.jsx(gt,{sideOffset:8,children:e(cs?"filesView.tts.stopSpeaking":"filesView.tts.readAloud")})]}),ts&&s.jsxs(s.Fragment,{children:[s.jsx(nr,{currentMode:ue,onToggle:()=>Mn(ue==="preview"?"edit":"preview")}),ue==="preview"&&s.jsx(S,{variant:"ghost",size:"sm",onClick:async()=>{const f=br.current?.getXml();if(ye.current&&(clearTimeout(ye.current),ye.current=null),l?.path&&f){if(!await Qs(l.path,f))return;us(!0),setTimeout(()=>us(!1),1500)}},className:"size-6 p-0 text-foreground hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e("filesView.diagram.saveDiagram"),children:Zi?s.jsx(g,{name:"check",className:"size-4 text-[color:var(--status-success)]"}):s.jsx(g,{name:"save-3",className:"size-4"})})]}),es&&u(e(Ie==="tree"?"filesView.editor.switchToTextView":"filesView.editor.switchToTreeView"),s.jsx(S,{variant:"ghost",size:"sm",onClick:()=>Pn(Ie==="tree"?"text":"tree"),className:"size-6 p-0 text-muted-foreground opacity-65 hover:bg-transparent hover:opacity-100 focus-visible:bg-transparent active:bg-transparent",title:e(Ie==="tree"?"filesView.editor.switchToTextView":"filesView.editor.switchToTreeView"),children:Ie==="tree"?s.jsx(g,{name:"code-sslash",className:"size-4"}):s.jsx(g,{name:"node-tree",className:"size-4"})})),Tn&&u(e("filesView.editor.copyFileContents"),s.jsx(S,{variant:"ghost",size:"sm",onClick:async()=>{(await Ts(k)).ok?(Fr(!0),Jt.current!==null&&window.clearTimeout(Jt.current),Jt.current=window.setTimeout(()=>{Fr(!1)},1200)):I.error(e("filesView.toast.copyFailed"))},className:"size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e("filesView.editor.copyFileContents"),"aria-label":e("filesView.editor.copyFileContents"),children:dn?s.jsx(g,{name:"check",className:"size-4 text-[color:var(--status-success)]"}):s.jsx(g,{name:"clipboard",className:"size-4"})})),Vn&&u(e("filesView.editor.copyFilePathTitle",{path:ft}),s.jsx(S,{variant:"ghost",size:"sm",onClick:async()=>{(await Ts(ft)).ok?(Nr(!0),Xt.current!==null&&window.clearTimeout(Xt.current),Xt.current=window.setTimeout(()=>{Nr(!1)},1200)):I.error(e("filesView.toast.copyFailed"))},className:"size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e("filesView.editor.copyFilePathTitle",{path:ft}),"aria-label":e("filesView.editor.copyFilePathTitle",{path:ft}),children:un?s.jsx(g,{name:"check",className:"size-4 text-[color:var(--status-success)]"}):s.jsx(g,{name:"file-copy-2",className:"size-4"})})),r.downloadFile&&u(e("filesView.editor.saveFile"),s.jsx(S,{variant:"ghost",size:"sm",onClick:()=>{const f=r.downloadFile;f&&f(l.path).catch(w=>{console.error("Download failed:",w),I.error(e("sidebarFilesTree.toast.operationFailed"))})},className:"size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e("filesView.editor.saveFile"),"aria-label":e("filesView.editor.saveFile"),children:s.jsx(g,{name:"download",className:"size-4"})})),t?u(e("filesView.editor.exitFullscreen"),s.jsx(S,{variant:"ghost",size:"sm",onClick:()=>Q(!1),className:"size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e("filesView.editor.exitFullscreen"),"aria-label":e("filesView.editor.exitFullscreen"),children:s.jsx(g,{name:"fullscreen-exit",className:"size-4"})})):!h&&d==="full"&&u(e(U?"filesView.editor.exitFullscreen":"filesView.editor.fullscreen"),s.jsx(S,{variant:"ghost",size:"sm",onClick:()=>Q(!U),className:"size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e(U?"filesView.editor.exitFullscreen":"filesView.editor.fullscreen"),"aria-label":e(U?"filesView.editor.exitFullscreen":"filesView.editor.fullscreen"),children:U?s.jsx(g,{name:"fullscreen-exit",className:"size-4"}):s.jsx(g,{name:"fullscreen",className:"size-4"})}))]})},Xs=s.jsxs("div",{className:"relative flex h-full min-h-0 min-w-0 w-full flex-col overflow-hidden",children:[s.jsx(Ai,{open:Ms,onOpenChange:t=>{t||Mt(!0)},children:s.jsxs(Ii,{showCloseButton:!1,className:"max-w-md",children:[s.jsxs(Oi,{children:[s.jsx(Bi,{children:e("filesView.unsaved.title")}),s.jsx($i,{children:e("filesView.unsaved.description")})]}),s.jsxs(Wi,{children:[s.jsx(S,{variant:"outline",onClick:()=>{Fn()},disabled:Pt,className:"border-[var(--status-success-border)] bg-[var(--status-success-background)] text-[var(--status-success)] hover:bg-[rgb(var(--status-success)/0.2)]",children:e("filesView.unsaved.saveChanges")}),s.jsx(S,{variant:"destructive",onClick:jn,children:e("filesView.unsaved.discard")})]})]})}),s.jsxs("div",{className:O("flex flex-col flex-shrink-0",q&&"border-b border-border/40"),children:[q?s.jsxs("div",{className:"flex min-w-0 items-center px-3 py-1.5",children:[h&&Y&&s.jsx("button",{type:"button",onClick:()=>A(!1),"aria-label":e("filesView.editor.back"),className:"inline-flex size-7 flex-shrink-0 items-center justify-center mr-1 text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",children:s.jsx(g,{name:"arrow-left-s",className:"size-5"})}),h?l?s.jsxs(or,{children:[s.jsx(lr,{asChild:!0,children:s.jsxs("button",{type:"button",className:"inline-flex min-w-0 max-w-full items-center gap-1 text-left typography-ui-label font-medium","aria-label":e("filesView.editor.openFilesAria"),children:[s.jsx(Ns,{filePath:l.path,extension:l.extension,className:"size-3.5 flex-shrink-0"}),s.jsx(Ri,{name:l.name}),s.jsx(g,{name:"arrow-down-s",className:"size-4 flex-shrink-0 text-muted-foreground"})]})}),s.jsx(cr,{align:"start",className:"w-[min(24rem,calc(100vw-2rem))] max-w-[calc(100vw-2rem)]",children:Et.map(t=>{const i=l?.path===t.path;return s.jsxs(Cs,{onSelect:o=>{if(o.target.closest("[data-close-open-file]")){o.preventDefault();return}i||me(t)},className:O("flex min-w-0 items-center justify-between gap-2 overflow-hidden",i&&"bg-[var(--interactive-selection)] text-[var(--interactive-selection-foreground)]"),children:[s.jsxs("span",{className:"flex min-w-0 flex-1 items-center gap-2 overflow-hidden",children:[s.jsx(Ns,{filePath:t.path,extension:t.extension,className:"size-3.5 flex-shrink-0"}),s.jsx(Ri,{name:t.name})]}),s.jsx("button",{type:"button","data-close-open-file":!0,onPointerDown:o=>{o.preventDefault(),o.stopPropagation()},onClick:o=>{o.preventDefault(),o.stopPropagation(),Xr(t.path)},className:"inline-flex size-6 shrink-0 items-center justify-center rounded-md text-[var(--surface-muted-foreground)] hover:text-[var(--surface-foreground)]","aria-label":e("filesView.editor.closeFileAria",{name:t.name}),children:s.jsx(g,{name:"close",className:"size-3.5"})})]},t.path)})})]}):s.jsx("div",{className:"typography-ui-label font-medium truncate",children:e("filesView.editor.selectFile")}):Et.length>0?s.jsxs("div",{className:"relative min-w-0 flex-1",children:[mr.left&&s.jsx("div",{className:"pointer-events-none absolute left-0 top-0 bottom-0 w-6 z-10 bg-gradient-to-r from-background to-transparent"}),mr.right&&s.jsx("div",{className:"pointer-events-none absolute right-0 top-0 bottom-0 w-6 z-10 bg-gradient-to-l from-background to-transparent"}),s.jsx("div",{ref:Es,className:"flex min-w-0 items-center gap-1 overflow-x-auto scrollbar-none",style:{scrollbarWidth:"none",msOverflowStyle:"none"},children:Et.map(t=>{const i=l?.path===t.path;return s.jsxs("div",{title:Ss(a,t.path),className:O("group inline-flex items-center gap-1 rounded-md border px-2 py-1 typography-ui-label transition-colors whitespace-nowrap",i?"bg-[var(--interactive-selection)] border-[var(--primary-muted)] text-[var(--interactive-selection-foreground)]":"bg-transparent border-[var(--interactive-border)] text-[var(--surface-muted-foreground)] hover:bg-[var(--interactive-hover)] hover:text-[var(--surface-foreground)]"),children:[s.jsx(Ns,{filePath:t.path,extension:t.extension,className:"size-3.5 flex-shrink-0"}),s.jsx("button",{type:"button",onClick:()=>{i||me(t)},className:"max-w-[12rem] truncate text-left",children:t.name}),s.jsx("button",{type:"button",onClick:o=>{o.stopPropagation(),Xr(t.path)},className:O("rounded-sm p-0.5 text-[var(--surface-muted-foreground)] hover:text-[var(--surface-foreground)]",!i&&!M&&"opacity-0 group-hover:opacity-100"),"aria-label":e("filesView.editor.closeFileAria",{name:t.name}),children:s.jsx(g,{name:"close",className:"size-3.5"})})]},t.path)})})]}):s.jsx("div",{className:"typography-ui-label font-medium truncate",children:e("filesView.editor.selectFile")})]}):null,(Mr||h)&&l?s.jsxs("div",{className:"flex min-w-0 items-center gap-3 border-t border-border/40 bg-[var(--surface-subtle)] px-3 py-1",children:[ft&&!h?s.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta text-muted-foreground",title:ft,children:ft}):null,s.jsx("div",{className:"ml-auto min-w-0 shrink-0 overflow-x-auto",children:Js({layout:"docked"})})]}):null]}),s.jsxs("div",{className:"flex-1 min-h-0 min-w-0 relative",children:[l&&!Z&&!(Mr||h)&&s.jsx("div",{ref:de,className:"absolute right-3 top-3 z-30",onMouseLeave:()=>{rt.current>0||ge(!1)},children:ee?Js():s.jsxs("div",{className:"flex items-center gap-1",children:[mt?s.jsxs(ht,{children:[s.jsx(pt,{asChild:!0,children:s.jsx("span",{className:"inline-flex",children:s.jsx(S,{variant:"ghost",size:"sm",onClick:()=>ti(ae()==="preview"?"edit":"preview"),className:O("size-8 rounded-lg border border-[var(--interactive-border)] bg-[var(--surface-elevated)] p-0 shadow-sm transition-colors",ae()==="preview"?"bg-[var(--interactive-selection)] text-[var(--interactive-selection-foreground)] hover:bg-[var(--interactive-selection)]":"text-muted-foreground hover:text-foreground"),"aria-label":e(ae()==="preview"?"filesView.editor.switchToEditMode":"filesView.editor.switchToPreviewMode"),title:e(ae()==="preview"?"filesView.editor.switchToEditMode":"filesView.editor.switchToPreviewMode"),children:s.jsx(g,{name:ae()==="preview"?"eye":"eye-off",className:"size-4"})})})}),s.jsx(gt,{side:"bottom",sideOffset:6,children:e(ae()==="preview"?"filesView.editor.switchToEditMode":"filesView.editor.switchToPreviewMode")})]}):null,s.jsxs(ht,{children:[s.jsx(pt,{asChild:!0,children:s.jsx("span",{className:"inline-flex",onMouseEnter:()=>ge(!0),children:s.jsx(S,{variant:"ghost",size:"sm",onClick:()=>ge(!0),className:"size-8 rounded-lg border border-[var(--interactive-border)] bg-[var(--surface-elevated)] p-0 text-muted-foreground shadow-sm hover:text-foreground","aria-label":e("filesView.editor.showControlsAria"),title:e("filesView.editor.controlsTitle"),children:s.jsx(g,{name:"more-2-fill",className:"size-4"})})})}),s.jsx(gt,{side:"bottom",sideOffset:6,children:e("filesView.editor.controlsTitle")})]})]})}),s.jsx(sr,{outerClassName:"h-full min-w-0",className:"h-full min-w-0",children:l?Ee||ci?W?s.jsx("div",{className:"p-3"}):s.jsxs("div",{className:"p-3 flex items-center gap-2 typography-ui text-muted-foreground",children:[s.jsx(g,{name:"loader-4",className:"size-4 animate-spin"}),e("filesView.state.loading")]}):Ye?s.jsx("div",{className:"p-3 typography-ui text-[color:var(--status-error)]",children:Ye}):ne?s.jsx("div",{className:"flex h-full items-center justify-center p-3",children:s.jsx("img",{src:di,alt:l?.name??e("filesView.editor.imageAltFallback"),className:"max-w-full max-h-[70vh] object-contain rounded-md border border-border/30 bg-primary/10"},l.path)}):Ve?fi(l):tt?s.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-3 p-6 text-center",children:[s.jsx("div",{className:"typography-ui-header text-foreground",children:e("filesView.editor.cannotPreviewBinary")}),s.jsx("div",{className:"max-w-md typography-ui text-muted-foreground",children:e("filesView.editor.binaryFileDescription")}),r.downloadFile?s.jsxs(S,{type:"button",variant:"outline",size:"sm",onClick:()=>{const t=r.downloadFile;!t||!l||t(l.path).catch(i=>{console.error("Download failed:",i),I.error(e("sidebarFilesTree.toast.operationFailed"))})},children:[s.jsx(g,{name:"download",className:"mr-2 size-4"}),e("filesView.editor.saveFile")]}):null]}):l&&ts&&ue==="preview"?s.jsx("div",{className:"h-full overflow-hidden",style:{minHeight:"400px"},children:s.jsx(ka,{ref:br,xml:Ln,onChange:zn},`${l.path}:${it}`)}):l&&es&&Ie==="tree"?s.jsx(rr,{fallback:s.jsxs("div",{className:"rounded-md border border-destructive/20 bg-destructive/10 px-3 py-2",children:[s.jsx("div",{className:"mb-1 font-medium text-destructive",children:e("filesView.error.jsonViewerUnavailable")}),s.jsx("div",{className:"text-sm text-muted-foreground",children:e("filesView.error.switchToTextMode")})]}),children:s.jsx("div",{className:"h-full overflow-auto",children:s.jsx(Ca,{jsonString:k,maxHeight:"100%",initiallyExpandedDepth:2})})}):l&&mt&&ae()==="preview"?s.jsxs("div",{className:"h-full overflow-auto p-3",children:[k.length>500*1024&&s.jsx("div",{className:"mb-3 rounded-md border border-status-warning/20 bg-status-warning/10 px-3 py-2 text-sm text-status-warning",children:e("filesView.warning.largeFilePreviewLimited",{sizeKb:Math.round(k.length/1024)})}),s.jsx(rr,{fallback:s.jsxs("div",{className:"rounded-md border border-destructive/20 bg-destructive/10 px-3 py-2",children:[s.jsx("div",{className:"mb-1 font-medium text-destructive",children:e("filesView.error.previewUnavailable")}),s.jsx("div",{className:"text-sm text-muted-foreground",children:e("filesView.error.switchToEditMode")})]}),children:s.jsx(Si,{content:k,className:"typography-markdown-body",stripFrontmatter:!0,enableFileReferences:!1})})]}):l&&Bt&&xe==="preview"?In?s.jsx("div",{className:"flex h-full items-center justify-center text-muted-foreground typography-ui-label",children:e("common.loading")}):s.jsx("div",{className:"h-full overflow-hidden",children:s.jsx("iframe",{src:!m.isVSCode&&ai===ys?(()=>{const t=l.path.split("/").map(i=>encodeURIComponent(i)).join("/");return bi().authenticatedAsset(`/api/fs/serve${t.startsWith("/")?t:`/${t}`}`)})():void 0,srcDoc:m.isVSCode?(()=>{const t=l.path.substring(0,l.path.lastIndexOf("/")+1);return t?k.replace(/<head([^>]*)>/i,`<head$1><base href="${t}">`):k})():void 0,className:"w-full h-full border-none",sandbox:"allow-scripts allow-same-origin allow-forms",title:e("filesView.editor.htmlPreviewTitle")},An)}):l&&Gs&&G==="view"?mi(l,B):s.jsxs("div",{className:O("relative h-full",Ot&&"overflow-hidden"),ref:tn,children:[s.jsx("div",{className:O("h-full",Ot&&"invisible"),children:s.jsx(Ti,{value:B,onChange:J,readOnly:!De,vimMode:Rr==="vim",extensions:ri,className:"h-full",blockWidgets:Bn,onViewReady:t=>{Re.current=t,zs(i=>i+1),window.requestAnimationFrame(()=>{$t(t)})},onViewDestroy:()=>{Re.current&&(Re.current=null),zs(t=>t+1)},enableSearch:!0,searchOpen:Z,onSearchOpenChange:pe,highlightLines:R?{start:Math.min(R.start,R.end),end:Math.max(R.start,R.end)}:void 0,lineNumbersConfig:{domEventHandlers:{mousedown:(t,i,o)=>{if(!(o instanceof MouseEvent)||o.button!==0)return!1;o.preventDefault();const c=t.state.doc.lineAt(i.from).number;if(R&&!o.shiftKey&&Math.min(R.start,R.end)===c&&Math.max(R.start,R.end)===c)return Me(null),Zt(),At.current=!1,dt.current=null,It(!1),!0;if(h&&R&&!o.shiftKey){const u=Math.min(R.start,R.end,c),f=Math.max(R.start,R.end,c);return Me({start:u,end:f}),At.current=!1,dt.current=null,It(!1),!0}if(At.current=!0,dt.current=c,It(!0),R&&o.shiftKey){const u=Math.min(R.start,c),f=Math.max(R.end,c);Me({start:u,end:f})}else Me({start:c,end:c});return!0},mouseover:(t,i,o)=>{if(!(o instanceof MouseEvent)||o.buttons!==1||!At.current||dt.current===null)return!1;const c=t.state.doc.lineAt(i.from).number,u=Math.min(dt.current,c),f=Math.max(dt.current,c);return Me({start:u,end:f}),It(!0),!1},mouseup:()=>(At.current=!1,dt.current=null,It(!1),!1)}}})}),Ot&&s.jsx("div",{className:"pointer-events-none absolute inset-0 flex items-center justify-center bg-background",children:s.jsxs("div",{className:"flex items-center gap-2 typography-ui text-muted-foreground",children:[s.jsx(g,{name:"loader-4",className:"size-4 animate-spin"}),e("filesView.state.openingFileAtChange")]})})]}):s.jsx("div",{className:"p-3 typography-ui text-muted-foreground",children:e("filesView.editor.pickFileFromTree")})})]})]}),$n=!!(a&&gr[a]),hi=a?as[a]:null,pi=s.jsxs("section",{className:O("flex min-h-0 flex-col overflow-hidden",h?"h-full w-full bg-background":"h-full rounded-xl border border-border/60 bg-background/70"),children:[s.jsx("div",{className:O("flex flex-col gap-2 py-2",h?"px-3":"px-2"),children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsxs("div",{className:"relative flex-1 min-w-0",children:[s.jsx(g,{name:"search",className:"pointer-events-none absolute left-2 top-2 size-4 text-muted-foreground"}),s.jsx(ks,{ref:X,value:T,onChange:t=>V(t.target.value),placeholder:e("filesView.tree.search.placeholder"),className:"h-8 pl-8 pr-8 typography-meta"}),T.trim().length>0&&s.jsx("button",{type:"button","aria-label":e("filesView.tree.search.clearAria"),className:"absolute right-2 top-2 inline-flex size-4 items-center justify-center text-muted-foreground hover:text-foreground",onClick:()=>{V(""),X.current?.focus()},children:s.jsx(g,{name:"close",className:"size-4"})})]}),s.jsxs(ht,{children:[s.jsx(pt,{asChild:!0,children:s.jsx("span",{className:"inline-flex flex-shrink-0",children:s.jsx(S,{variant:"ghost",size:"sm",onClick:()=>Os("createFile",{path:P,type:"directory"}),className:"size-8 p-0 flex-shrink-0",title:e("filesView.tree.actions.newFileTitle"),"aria-label":e("filesView.tree.actions.newFileTitle"),children:s.jsx(g,{name:"file-add",className:"size-4"})})})}),s.jsx(gt,{side:"bottom",sideOffset:6,children:e("filesView.tree.actions.newFileTitle")})]}),s.jsxs(ht,{children:[s.jsx(pt,{asChild:!0,children:s.jsx("span",{className:"inline-flex flex-shrink-0",children:s.jsx(S,{variant:"ghost",size:"sm",onClick:()=>Os("createFolder",{path:P,type:"directory"}),className:"size-8 p-0 flex-shrink-0",title:e("filesView.tree.actions.newFolderTitle"),"aria-label":e("filesView.tree.actions.newFolderTitle"),children:s.jsx(g,{name:"folder-add",className:"size-4"})})})}),s.jsx(gt,{side:"bottom",sideOffset:6,children:e("filesView.tree.actions.newFolderTitle")})]}),s.jsxs(ht,{children:[s.jsx(pt,{asChild:!0,children:s.jsx("span",{className:"inline-flex flex-shrink-0",children:s.jsx(S,{variant:"ghost",size:"sm",onClick:()=>{ps()},className:"size-8 p-0 flex-shrink-0",title:e("filesView.tree.actions.refreshTitle"),"aria-label":e("filesView.tree.actions.refreshTitle"),children:s.jsx(g,{name:"refresh",className:"size-4"})})})}),s.jsx(gt,{side:"bottom",sideOffset:6,children:e("filesView.tree.actions.refreshTitle")})]})]})}),s.jsx(sr,{outerClassName:"flex-1 min-h-0",className:O("py-2",h?"px-3":"px-2"),children:s.jsx("ul",{className:"flex flex-col",children:Hi?s.jsxs("li",{className:"flex items-center gap-1.5 px-2 py-1 typography-meta text-muted-foreground",children:[s.jsx(g,{name:"loader-4",className:"size-4 animate-spin"}),e("filesView.tree.search.searching")]}):vr.length>0?vr.map(t=>{const i=l?.path===t.path;return s.jsx("li",{children:s.jsxs("button",{type:"button",onClick:()=>{me(t)},className:O("flex w-full items-center gap-1.5 rounded-md px-2 py-1 text-left text-foreground transition-colors",i?"bg-interactive-selection/70":"hover:bg-interactive-hover/40"),children:[Gi(t.path,t.extension),s.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta",style:{direction:"rtl",textAlign:"left"},title:t.path,children:t.relativePath??t.path})]})},t.path)}):hi?s.jsxs("li",{className:"flex flex-col gap-2 px-2 py-1 typography-meta text-muted-foreground",children:[s.jsx("span",{className:"text-[var(--status-error)]",children:hi}),s.jsxs(S,{variant:"outline",size:"xs",className:"w-fit gap-1.5",onClick:()=>{ps()},children:[s.jsx(g,{name:"refresh",className:"size-3.5"}),e("filesView.tree.actions.refreshTitle")]})]}):$n?Yr(a,0):s.jsx("li",{className:"px-2 py-1 typography-meta text-muted-foreground",children:e("filesView.state.loading")})})})]}),Wn=d==="full"&&U&&l&&s.jsx("div",{className:"absolute inset-0 z-50 flex flex-col bg-background",children:s.jsxs("div",{className:"flex-1 min-h-0 min-w-0 relative",children:[s.jsx("div",{className:"absolute right-4 top-4 z-30",children:Js({exitFullscreenOnly:!0})}),s.jsx(sr,{outerClassName:"h-full min-w-0",className:"h-full min-w-0",children:Ee||ci?W?s.jsx("div",{className:"p-4"}):s.jsxs("div",{className:"p-4 flex items-center gap-2 typography-ui text-muted-foreground",children:[s.jsx(g,{name:"loader-4",className:"size-4 animate-spin"}),"Loading…"]}):Ye?s.jsx("div",{className:"p-4 typography-ui text-[color:var(--status-error)]",children:Ye}):ne?s.jsx("div",{className:"flex h-full items-center justify-center p-4",children:s.jsx("img",{src:di,alt:l.name,className:"max-w-full max-h-full object-contain rounded-md border border-border/30 bg-primary/10"},l.path)}):Ve?fi(l):tt?s.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-3 p-6 text-center",children:[s.jsx("div",{className:"typography-ui-header text-foreground",children:e("filesView.editor.cannotPreviewBinary")}),s.jsx("div",{className:"max-w-md typography-ui text-muted-foreground",children:e("filesView.editor.binaryFileDescription")}),r.downloadFile?s.jsxs(S,{type:"button",variant:"outline",size:"sm",onClick:()=>{const t=r.downloadFile;!t||!l||t(l.path).catch(i=>{console.error("Download failed:",i),I.error(e("sidebarFilesTree.toast.operationFailed"))})},children:[s.jsx(g,{name:"download",className:"mr-2 size-4"}),e("filesView.editor.saveFile")]}):null]}):mt&&ae()==="preview"?s.jsxs("div",{className:"h-full overflow-auto p-4",children:[k.length>500*1024&&s.jsx("div",{className:"mb-3 rounded-md border border-status-warning/20 bg-status-warning/10 px-3 py-2 text-sm text-status-warning",children:e("filesView.warning.largeFilePreviewLimited",{sizeKb:Math.round(k.length/1024)})}),s.jsx(rr,{fallback:s.jsxs("div",{className:"rounded-md border border-destructive/20 bg-destructive/10 px-3 py-2",children:[s.jsx("div",{className:"mb-1 font-medium text-destructive",children:e("filesView.error.previewUnavailable")}),s.jsx("div",{className:"text-sm text-muted-foreground",children:e("filesView.error.switchToEditMode")})]}),children:s.jsx(Si,{content:k,className:"typography-markdown-body",stripFrontmatter:!0,enableFileReferences:!1})})]}):Gs&&G==="view"?mi(l,B):s.jsxs("div",{className:O("relative h-full",Ot&&"overflow-hidden"),children:[s.jsx("div",{className:O("h-full",Ot&&"invisible"),children:s.jsx(Ti,{value:B,onChange:J,readOnly:!De,vimMode:Rr==="vim",extensions:ri,className:"h-full",onViewReady:t=>{Re.current=t,window.requestAnimationFrame(()=>{$t(t)})},onViewDestroy:()=>{Re.current&&(Re.current=null)}})}),Ot&&s.jsx("div",{className:"pointer-events-none absolute inset-0 flex items-center justify-center bg-background",children:s.jsxs("div",{className:"flex items-center gap-2 typography-ui text-muted-foreground",children:[s.jsx(g,{name:"loader-4",className:"size-4 animate-spin"}),e("filesView.state.openingFileAtChange")]})})]})})]})});return s.jsxs("div",{className:"flex h-full min-h-0 overflow-hidden bg-background relative",children:[s.jsx(Qa,{activeDialog:jt,dialogData:Ft,dialogInputValue:ct,onDialogInputChange:jr,isDialogSubmitting:nn,onDialogSubmit:yn,onClose:On,inputRef:Xi}),Wn,h?Y?Xs:pi:d==="editor-only"?s.jsx("div",{className:"flex flex-1 min-h-0 min-w-0 overflow-hidden",children:s.jsx("div",{className:"flex-1 min-h-0 min-w-0 overflow-hidden bg-background",children:Xs})}):s.jsxs("div",{className:"flex flex-1 min-h-0 min-w-0 gap-3 px-3 pb-3 pt-2",children:[p>=700&&s.jsx("div",{className:"w-72 flex-shrink-0 min-h-0 overflow-hidden",children:pi}),s.jsx("div",{className:"flex-1 min-h-0 min-w-0 overflow-hidden rounded-xl border border-border/60 bg-background",children:Xs})]})]})};function Ja(d){return d+1}export{mc as FilesView};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{f as B,R as h,j as P}from"./vendor-react-BUCujlKS.js";import{toast as H}from"./vendor-sonner-DFyL3AvE.js";import{f7 as K,f4 as J,a0 as Q,f as Z,I as W}from"./useAppFontEffects-BikB6enL.js";import{r as G,T as Y,C as ee,e as te,cQ as re,cR as oe,aG as ae}from"./index-DRpChWux.js";import{extractMarkdownImageCandidates as se,MAX_MARKDOWN_IMAGE_COUNT as ne}from"./markdownCore-DDrHVneM.js";import"./vendor-scheduler-7OC5HNn7.js";import"./vendor-simplewebauthn-browser-VDA66rT_.js";import"./vendor-vite-runtime-DD1OZmLC.js";import"./vendor-zustand-BAGL70zf.js";import"./vendor-base-ui-D_V6hAcE.js";import"./vendor-floating-ui-utils-BzXdqYpP.js";import"./vendor-floating-ui-dom-WyXykhNi.js";import"./vendor-floating-ui-core-CXmKXOXc.js";import"./vendor-floating-ui-react-dom-DKpLs02S.js";import"./vendor-use-sync-external-store-D6wYuSt-.js";import"./contextPanelEmbeddedChat-B-bSg3P5.js";import"./vendor-class-variance-authority-5VPnzWs2.js";import"./vendor-clsx-B-dksMZM.js";import"./vendor-dnd-kit-core-BZknOX2w.js";import"./vendor-dnd-kit-utilities-B_MdXhJC.js";import"./vendor-dnd-kit-accessibility-BHxJPORy.js";import"./vendor-dnd-kit-sortable-CsEagZ81.js";import"./vendor-cmdk-DgLInKvT.js";import"./vendor-radix-ui-react-dialog-B94Bt2qq.js";import"./vendor-radix-ui-primitive-Dc_FVRD7.js";import"./vendor-radix-ui-react-compose-refs-DcAh5WdT.js";import"./vendor-radix-ui-react-context-Czxm7Z62.js";import"./vendor-radix-ui-react-id-f5BLKEVw.js";import"./vendor-radix-ui-react-use-layout-effect-D_3IhJdJ.js";import"./vendor-radix-ui-react-use-controllable-state-BFT5YmkA.js";import"./vendor-radix-ui-react-dismissable-layer-D7kXcwgJ.js";import"./vendor-radix-ui-react-primitive-DhVoX9SD.js";import"./vendor-radix-ui-react-slot-BQgQOasS.js";import"./vendor-radix-ui-react-use-callback-ref-BZPnuXAC.js";import"./vendor-radix-ui-react-use-escape-keydown-oph88g-F.js";import"./vendor-radix-ui-react-focus-scope-CiaxW4dD.js";import"./vendor-radix-ui-react-portal-BMJYHWck.js";import"./vendor-radix-ui-react-presence-CNxf-uq4.js";import"./vendor-radix-ui-react-focus-guards-B6qJXYua.js";import"./vendor-react-remove-scroll-DO7dCTnK.js";import"./vendor-tslib-De9GV7Vy.js";import"./vendor-react-remove-scroll-bar-BcFYyj3E.js";import"./vendor-react-style-singleton-q6EMHnwf.js";import"./vendor-get-nonce-C-Z93AgS.js";import"./vendor-use-sidecar-zDC0RhA3.js";import"./vendor-use-callback-ref-D3RC8gqK.js";import"./vendor-aria-hidden-DvXkyWUv.js";import"./vendor-codemirror-language-DUOssd4j.js";import"./vendor-lezer-common-B3-cUCR_.js";import"./vendor-codemirror-state-CNWM3Q8V.js";import"./vendor-marijn-find-cluster-break-DXwl3gUT.js";import"./vendor-codemirror-view-DSzLbZiS.js";import"./vendor-style-mod-NZ5MEPvj.js";import"./vendor-w3c-keyname-Vcq4gwWv.js";import"./vendor-crelt-C8TCjufn.js";import"./vendor-lezer-highlight-CDMHUZ74.js";import"./vendor-codemirror-lang-javascript-Bbw3D7r0.js";import"./vendor-lezer-javascript-D7Tj24ot.js";import"./vendor-lezer-lr-bhwg1HMg.js";import"./vendor-codemirror-autocomplete-BjbBRsUA.js";import"./vendor-codemirror-lang-json-ryCw7nab.js";import"./vendor-lezer-json-Iaex0UN-.js";import"./vendor-codemirror-lang-css-VgNqFSH-.js";import"./vendor-lezer-css-C5xB6jxd.js";import"./vendor-codemirror-lang-html-B3Qe3OpS.js";import"./vendor-lezer-html-C0I1p52t.js";import"./vendor-codemirror-lang-markdown-FGQydhTc.js";import"./vendor-lezer-markdown-C6g-d6P3.js";import"./vendor-codemirror-language-data-CLHw8NWn.js";import"./vendor-codemirror-lang-python-N414WYK-.js";import"./vendor-lezer-python-CvuFxeZl.js";import"./vendor-codemirror-commands-ARAOgp1x.js";import"./vendor-tanstack-react-virtual-g05Cx3z9.js";import"./vendor-tanstack-virtual-core-Dubg10g5.js";import"./vendor-framer-motion-CRSgBxjL.js";import"./vendor-motion-dom-DJLgZh4Q.js";import"./vendor-motion-utils-BGh8QBgx.js";import"./vendor-tailwind-merge-CPcsbTWB.js";import"./vendor-fuse.js-Dw8P0qyA.js";import"./vendor-opencode-sdk-BJ73u-bH.js";import"./vendor-marked-CX41MkDF.js";import"./vendor-remend-BWYYytN3.js";import"./vendor-katex-k3Ppq1Ha.js";import"./vendor-dompurify-r8glNMJW.js";const L=10*1024*1024,ie=1024,le=3e4,ce=new Set(["image/png","image/jpeg","image/gif","image/webp"]),z=new WeakMap,$=r=>{if(r.aborted)throw new DOMException("Image load aborted","AbortError")},me=r=>{let e=r;if(/^file:\/\//i.test(e))try{const o=new URL(e);if(o.protocol!=="file:")return"";e=o.host&&o.host!=="localhost"?`//${o.host}${o.pathname}`:o.pathname,/^\/[A-Za-z]:\//.test(e)&&(e=e.slice(1))}catch{return""}const t=e.split(/[?#]/,1)[0]??"";try{return decodeURIComponent(t)}catch{return t}},ue=r=>new Promise((e,t)=>{const o=new FileReader;o.onload=()=>{typeof o.result=="string"?e(o.result):t(new Error("Unable to encode image"))},o.onerror=()=>t(o.error??new Error("Unable to encode image")),o.readAsDataURL(r)}),pe=async(r,e)=>{const t=new Uint8Array(await r.slice(0,12).arrayBuffer()),o=(n,u)=>String.fromCharCode(...t.slice(n,u));switch(e){case"image/png":return t[0]===137&&o(1,4)==="PNG"&&t[4]===13&&t[5]===10&&t[6]===26&&t[7]===10;case"image/jpeg":return t[0]===255&&t[1]===216&&t[2]===255;case"image/gif":{const n=o(0,6);return n==="GIF87a"||n==="GIF89a"}case"image/webp":return o(0,4)==="RIFF"&&o(8,12)==="WEBP";default:return!1}},V=async(r,e)=>{if(!ce.has(e))throw new Error("Unsupported image type");if(r.size>L)throw new Error("Image is too large");if(!await pe(r,e))throw new Error("Unsupported image data")},fe=async r=>{const e=/^data:(image\/(?:png|jpeg|gif|webp));base64,([\s\S]*)$/i.exec(r);if(!e?.[1]||e[2]===void 0)throw new Error("Invalid image data URL");if(e[2].length>Math.ceil(L*4/3)+4)throw new Error("Image is too large");let t;try{t=atob(e[2])}catch{throw new Error("Invalid image data URL")}const o=Uint8Array.from(t,n=>n.charCodeAt(0));await V(new Blob([o]),e[1].toLowerCase())},q=r=>!/^(?:https?:)?\/\//i.test(r)&&!/^data:image\/(?:png|jpeg|gif|webp);base64,/i.test(r),de=async({sources:r,directory:e,sessionId:t,messageId:o,signal:n})=>{const u=Y();let s=z.get(u);s||(s=new Map,z.set(u,s));const c=`${t}\0${o}\0${e}\0${r.join("\0")}`,i=s.get(c);if(i&&i.expiresAt>Date.now())return s.delete(c),s.set(c,i),i.result;i&&s.delete(c);const p=await G(`/api/openchamber/sessions/${encodeURIComponent(t)}/markdown-image-grants`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({directory:e,messageId:o,sources:r}),signal:n});if(!p.ok)throw new Error(`Unable to prepare images (${p.status})`);const m=await p.json(),l=new Map;for(const a of m.results??[])a.source&&(a.status==="ready"&&a.path?l.set(a.source,{status:"ready",path:a.path,outsideFileGrant:a.outsideFileGrant,expiresAt:a.expiresAt}):a.status==="missing"?l.set(a.source,{status:"missing"}):l.set(a.source,{status:"error"}));for(const a of r)l.has(a)||l.set(a,{status:"error"});for(;s.size>=ie;)s.delete(s.keys().next().value);const w=[...l.values()].every(a=>a.status==="ready"),y=Math.min(...[...l.values()].filter(a=>a.status==="ready").map(a=>a.expiresAt??Number.POSITIVE_INFINITY));return s.set(c,{result:l,expiresAt:w?y:Date.now()+le}),l},ge=async(r,e)=>{if($(e),/^(?:https?:)?\/\//i.test(r))return r;if(/^data:image\/(?:png|jpeg|gif|webp);base64,/i.test(r))return await fe(r),$(e),r;throw new Error("Local image has not been prepared")},he=async(r,e,t)=>{$(t);const o=me(r),n=K(e,o);if(!e||!o||!J(n,e))throw new Error("Image path is outside the active workspace");const u=await G("/api/fs/stat",{query:{path:n,directory:e,optional:"true"},signal:t});if(!u.ok)throw new Error(`Unable to inspect image (${u.status})`);const s=await u.json();if(!s.isFile)throw new Error("Image path is not a file");if(typeof s.size=="number"&&s.size>L)throw new Error("Image is too large");const c=await G("/api/fs/raw",{query:{path:n,directory:e},signal:t});if(!c.ok)throw new Error(`Unable to load image (${c.status})`);const i=(c.headers.get("content-type")??"").split(";",1)[0]?.toLowerCase()??"",p=Number(c.headers.get("content-length"));if(Number.isFinite(p)&&p>L)throw new Error("Image is too large");const m=await c.blob();return await V(m,i),$(t),ue(m)},we=(r,e)=>Y().authenticatedAsset("/api/fs/raw",{path:r.path,directory:e,allowOutsideWorkspace:r.outsideFileGrant?"true":void 0,outsideFileGrant:r.outsideFileGrant}),be=r=>{const e=B.c(7),[t,o]=h.useState(!1),[n,u]=h.useState(0);let s;e[0]===Symbol.for("react.memo_cache_sentinel")?(s=te(),e[0]=s):s=e[0];const c=s;let i,p;e[1]!==r?(i=()=>{if(!r){o(!1);return}let w=!1,y;const a=re(c),g=oe(()=>{w||u(Ie)}),I=()=>{ae(c).then(()=>{w||o(!0)}).catch(()=>{w||(y=setTimeout(I,1e3))})};return I(),()=>{w=!0,y&&clearTimeout(y),a(),g()}},p=[c,r],e[1]=r,e[2]=i,e[3]=p):(i=e[2],p=e[3]),h.useEffect(i,p);const m=!r||t;let l;return e[4]!==n||e[5]!==m?(l={ready:m,nonce:n},e[4]=n,e[5]=m,e[6]=l):l=e[6],l},ye=r=>{const e=B.c(46),{candidate:t,preparation:o,directory:n,assetAuthReady:u,assetAuthNonce:s,useWorkspaceFsBridge:c,onShowPopup:i}=r,{t:p}=Z(),m=h.useRef(null),[l,w]=h.useState(!1);let y;e[0]===Symbol.for("react.memo_cache_sentinel")?(y={url:"",status:"loading"},e[0]=y):y=e[0];const[a,g]=h.useState(y);let I;e[1]!==t.source?(I=q(t.source),e[1]=t.source,e[2]=I):I=e[2];const b=I;let x,f;e[3]!==l?(x=()=>{const N=m.current;if(!N||l)return;if(typeof IntersectionObserver>"u"){w(!0);return}const E=new IntersectionObserver(T=>{T.some(Ee)&&(w(!0),E.disconnect())},{rootMargin:"200px"});return E.observe(N),()=>E.disconnect()},f=[l],e[3]=l,e[4]=x,e[5]=f):(x=e[4],f=e[5]),h.useEffect(x,f);let v;e[6]!==u||e[7]!==t.source||e[8]!==n||e[9]!==b||e[10]!==o||e[11]!==l||e[12]!==c?(v=()=>{if(!l||b&&!c&&!o)return;if(b&&c){const E=new AbortController;return g({url:"",status:"loading"}),he(t.source,n,E.signal).then(T=>{E.signal.aborted||g({url:T,status:"loading"})}).catch(()=>{E.signal.aborted||g({url:"",status:"error"})}),()=>E.abort()}if(b){if(o?.status!=="ready"){g({url:"",status:"error"});return}if(!u)return;g({url:we(o,n),status:"loading"});return}const N=new AbortController;return g({url:"",status:"loading"}),ge(t.source,N.signal).then(E=>{N.signal.aborted||g({url:E,status:"loading"})}).catch(()=>{N.signal.aborted||g({url:"",status:"error"})}),()=>N.abort()},e[6]=u,e[7]=t.source,e[8]=n,e[9]=b,e[10]=o,e[11]=l,e[12]=c,e[13]=v):v=e[13];let R;e[14]!==s||e[15]!==u||e[16]!==t.source||e[17]!==n||e[18]!==b||e[19]!==o||e[20]!==l||e[21]!==c?(R=[s,u,t.source,n,b,o,l,c],e[14]=s,e[15]=u,e[16]=t.source,e[17]=n,e[18]=b,e[19]=o,e[20]=l,e[21]=c,e[22]=R):R=e[22],h.useEffect(v,R);let k;e[23]!==t.filename||e[24]!==a.status||e[25]!==a.url||e[26]!==i||e[27]!==p?(k=()=>{if(a.status==="error"){H.error(p("filesView.error.previewUnavailable"));return}a.status!=="ready"||!i||i({open:!0,title:t.filename,content:"",metadata:{tool:"markdown-image-preview",filename:t.filename},image:{url:a.url,filename:t.filename}})},e[23]=t.filename,e[24]=a.status,e[25]=a.url,e[26]=i,e[27]=p,e[28]=k):k=e[28];const U=k,j=a.status==="loading";let A;e[29]!==t.filename||e[30]!==a.status||e[31]!==a.url?(A=P.jsx("span",{className:"flex h-[72px] w-[100px] items-center justify-center overflow-hidden rounded-lg border border-border/40 bg-muted/10",children:a.url&&a.status!=="error"?P.jsx("img",{src:a.url,alt:t.filename,className:"h-full w-full object-contain",loading:"lazy",decoding:"async",referrerPolicy:"no-referrer",onLoad:()=>g(Ae),onError:()=>g({url:"",status:"error"}),"data-openchamber-markdown-image":"true","data-openchamber-markdown-image-thumbnail":"true","data-openchamber-markdown-image-state":a.status}):P.jsx(W,{name:"file-image",className:"h-5 w-5 text-muted-foreground"})}),e[29]=t.filename,e[30]=a.status,e[31]=a.url,e[32]=A):A=e[32];let _;e[33]===Symbol.for("react.memo_cache_sentinel")?(_=P.jsx(W,{name:"file-image",className:"h-3 w-3 shrink-0"}),e[33]=_):_=e[33];let S;e[34]!==t.filename?(S=P.jsx("span",{className:"min-w-0 truncate typography-meta",children:t.filename}),e[34]=t.filename,e[35]=S):S=e[35];let C;e[36]!==t.filename||e[37]!==S?(C=P.jsxs("span",{className:"mt-1 flex w-[100px] items-center justify-center gap-1 text-muted-foreground",title:t.filename,"data-openchamber-markdown-image-caption":"true",children:[_,S]}),e[36]=t.filename,e[37]=S,e[38]=C):C=e[38];let M;return e[39]!==t.filename||e[40]!==t.source||e[41]!==U||e[42]!==C||e[43]!==j||e[44]!==A?(M=P.jsxs("button",{ref:m,type:"button",className:"w-[100px] shrink-0 text-left outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)]","aria-label":t.filename,disabled:j,onClick:U,"data-openchamber-markdown-image-action":"true","data-openchamber-markdown-image-source":t.source,"data-openchamber-markdown-image-filename":t.filename,children:[A,C]}),e[39]=t.filename,e[40]=t.source,e[41]=U,e[42]=C,e[43]=j,e[44]=A,e[45]=M):M=e[45],M},ir=r=>{const e=B.c(34),{sessionId:t,messageId:o,contents:n,onShowPopup:u}=r,s=Q()??"",c=h.useRef(null),[i,p]=h.useState(!1),[m,l]=h.useState(null),[w,y]=h.useState(0);let a;e[0]===Symbol.for("react.memo_cache_sentinel")?(a=ee(),e[0]=a):a=e[0];const g=a;let I;e[1]!==n?(I=se(n,ne),e[1]=n,e[2]=I):I=e[2];const b=I;let x;e[3]!==b?(x=g?[]:b.filter(xe).map(ve),e[3]=b,e[4]=x):x=e[4];const f=x;let v,R;e[5]!==f.length||e[6]!==i?(v=()=>{if(f.length===0||i)return;const d=c.current;if(!d||typeof IntersectionObserver>"u"){p(!0);return}const F=new IntersectionObserver(X=>{X.some(Re)&&(p(!0),F.disconnect())},{rootMargin:"200px"});return F.observe(d),()=>F.disconnect()},R=[f.length,i],e[5]=f.length,e[6]=i,e[7]=v,e[8]=R):(v=e[7],R=e[8]),h.useEffect(v,R);let k;e[9]!==s||e[10]!==o||e[11]!==f||e[12]!==t||e[13]!==i?(k=()=>{if(!i||!t||f.length===0)return;const d=new AbortController;return de({sources:f,directory:s,sessionId:t,messageId:o,signal:d.signal}).then(F=>{d.signal.aborted||l(F)}).catch(()=>{d.signal.aborted||l(new Map(f.map(ke)))}),()=>d.abort()},e[9]=s,e[10]=o,e[11]=f,e[12]=t,e[13]=i,e[14]=k):k=e[14];let U;e[15]!==s||e[16]!==o||e[17]!==w||e[18]!==f||e[19]!==t||e[20]!==i?(U=[s,o,w,f,t,i],e[15]=s,e[16]=o,e[17]=w,e[18]=f,e[19]=t,e[20]=i,e[21]=U):U=e[21],h.useEffect(k,U);let j,A;e[22]!==m?(j=()=>{const d=Math.min(...[...m?.values()??[]].filter(_e).map(Se));if(!Number.isFinite(d))return;const F=setTimeout(()=>y(Me),Math.max(0,d-Date.now()));return()=>clearTimeout(F)},A=[m],e[22]=m,e[23]=j,e[24]=A):(j=e[23],A=e[24]),h.useEffect(j,A);let _;e[25]!==m?(_=d=>m?.get(d.source)?.status!=="missing",e[25]=m,e[26]=_):_=e[26];const S=b.filter(_),C=[...m?.values()??[]].some(Ne),M=be(C);if(S.length===0)return null;const N="mt-3 flex max-w-full gap-2 overflow-x-auto pb-1",E="true";let T;e[27]!==M||e[28]!==s||e[29]!==u||e[30]!==m?(T=d=>P.jsx(ye,{candidate:d,preparation:m?.get(d.source),directory:s,assetAuthReady:M.ready,assetAuthNonce:M.nonce,useWorkspaceFsBridge:g,onShowPopup:u},d.source),e[27]=M,e[28]=s,e[29]=u,e[30]=m,e[31]=T):T=e[31];const D=S.map(T);let O;return e[32]!==D?(O=P.jsx("div",{ref:c,className:N,"data-openchamber-markdown-image-gallery":E,children:D}),e[32]=D,e[33]=O):O=e[33],O};function Ie(r){return r+1}function Ee(r){return r.isIntersecting}function Ae(r){return{...r,status:"ready"}}function xe(r){return q(r.source)}function ve(r){return r.source}function Re(r){return r.isIntersecting}function ke(r){return[r,{status:"error"}]}function _e(r){return r.status==="ready"}function Se(r){return r.expiresAt??Number.POSITIVE_INFINITY}function Me(r){return r+1}function Ne(r){return r.status==="ready"}export{ir as MarkdownImageGallery};
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import{R as _,f as K,j as ee}from"./vendor-react-BUCujlKS.js";import{m as lt}from"./vendor-morphdom-B7dS_VPB.js";import{r as ct,a as dt}from"./vendor-beautiful-mermaid-DztCUpLZ.js";import{eZ as De,e_ as mt,e$ as ut,g as de,d3 as pt,d4 as ft,f0 as ht,f1 as gt,V as We,a0 as $e,f2 as qe,h as Be,dZ as bt,f as wt,f3 as yt,o as vt,f4 as be,f5 as At,f6 as kt,f7 as Et}from"./useAppFontEffects-BikB6enL.js";import{G as we,cf as Ct,u as G,ag as ye,C as ze,x as St,y as Lt,r as Mt}from"./index-DRpChWux.js";import{d as Nt}from"./contextPanelEmbeddedChat-B-bSg3P5.js";import{renderMarkdownSync as Rt,renderMarkdownBlocks as xt}from"./markdownCore-DDrHVneM.js";import{r as _t}from"./registerCustomTheme-BBXUCRnG.js";import"./vendor-scheduler-7OC5HNn7.js";import"./vendor-elkjs-BRwcR927.js";import"./vendor-entities-C3BA0AJP.js";import"./vendor-simplewebauthn-browser-VDA66rT_.js";import"./vendor-vite-runtime-DD1OZmLC.js";import"./vendor-zustand-BAGL70zf.js";import"./vendor-base-ui-D_V6hAcE.js";import"./vendor-floating-ui-utils-BzXdqYpP.js";import"./vendor-floating-ui-dom-WyXykhNi.js";import"./vendor-floating-ui-core-CXmKXOXc.js";import"./vendor-floating-ui-react-dom-DKpLs02S.js";import"./vendor-use-sync-external-store-D6wYuSt-.js";import"./vendor-class-variance-authority-5VPnzWs2.js";import"./vendor-clsx-B-dksMZM.js";import"./vendor-dnd-kit-core-BZknOX2w.js";import"./vendor-dnd-kit-utilities-B_MdXhJC.js";import"./vendor-dnd-kit-accessibility-BHxJPORy.js";import"./vendor-dnd-kit-sortable-CsEagZ81.js";import"./vendor-cmdk-DgLInKvT.js";import"./vendor-radix-ui-react-dialog-B94Bt2qq.js";import"./vendor-radix-ui-primitive-Dc_FVRD7.js";import"./vendor-radix-ui-react-compose-refs-DcAh5WdT.js";import"./vendor-radix-ui-react-context-Czxm7Z62.js";import"./vendor-radix-ui-react-id-f5BLKEVw.js";import"./vendor-radix-ui-react-use-layout-effect-D_3IhJdJ.js";import"./vendor-radix-ui-react-use-controllable-state-BFT5YmkA.js";import"./vendor-radix-ui-react-dismissable-layer-D7kXcwgJ.js";import"./vendor-radix-ui-react-primitive-DhVoX9SD.js";import"./vendor-radix-ui-react-slot-BQgQOasS.js";import"./vendor-radix-ui-react-use-callback-ref-BZPnuXAC.js";import"./vendor-radix-ui-react-use-escape-keydown-oph88g-F.js";import"./vendor-radix-ui-react-focus-scope-CiaxW4dD.js";import"./vendor-radix-ui-react-portal-BMJYHWck.js";import"./vendor-radix-ui-react-presence-CNxf-uq4.js";import"./vendor-radix-ui-react-focus-guards-B6qJXYua.js";import"./vendor-react-remove-scroll-DO7dCTnK.js";import"./vendor-tslib-De9GV7Vy.js";import"./vendor-react-remove-scroll-bar-BcFYyj3E.js";import"./vendor-react-style-singleton-q6EMHnwf.js";import"./vendor-get-nonce-C-Z93AgS.js";import"./vendor-use-sidecar-zDC0RhA3.js";import"./vendor-use-callback-ref-D3RC8gqK.js";import"./vendor-aria-hidden-DvXkyWUv.js";import"./vendor-codemirror-language-DUOssd4j.js";import"./vendor-lezer-common-B3-cUCR_.js";import"./vendor-codemirror-state-CNWM3Q8V.js";import"./vendor-marijn-find-cluster-break-DXwl3gUT.js";import"./vendor-codemirror-view-DSzLbZiS.js";import"./vendor-style-mod-NZ5MEPvj.js";import"./vendor-w3c-keyname-Vcq4gwWv.js";import"./vendor-crelt-C8TCjufn.js";import"./vendor-lezer-highlight-CDMHUZ74.js";import"./vendor-codemirror-lang-javascript-Bbw3D7r0.js";import"./vendor-lezer-javascript-D7Tj24ot.js";import"./vendor-lezer-lr-bhwg1HMg.js";import"./vendor-codemirror-autocomplete-BjbBRsUA.js";import"./vendor-codemirror-lang-json-ryCw7nab.js";import"./vendor-lezer-json-Iaex0UN-.js";import"./vendor-codemirror-lang-css-VgNqFSH-.js";import"./vendor-lezer-css-C5xB6jxd.js";import"./vendor-codemirror-lang-html-B3Qe3OpS.js";import"./vendor-lezer-html-C0I1p52t.js";import"./vendor-codemirror-lang-markdown-FGQydhTc.js";import"./vendor-lezer-markdown-C6g-d6P3.js";import"./vendor-codemirror-language-data-CLHw8NWn.js";import"./vendor-codemirror-lang-python-N414WYK-.js";import"./vendor-lezer-python-CvuFxeZl.js";import"./vendor-codemirror-commands-ARAOgp1x.js";import"./vendor-tanstack-react-virtual-g05Cx3z9.js";import"./vendor-tanstack-virtual-core-Dubg10g5.js";import"./vendor-framer-motion-CRSgBxjL.js";import"./vendor-motion-dom-DJLgZh4Q.js";import"./vendor-motion-utils-BGh8QBgx.js";import"./vendor-sonner-DFyL3AvE.js";import"./vendor-tailwind-merge-CPcsbTWB.js";import"./vendor-fuse.js-Dw8P0qyA.js";import"./vendor-opencode-sdk-BJ73u-bH.js";import"./vendor-marked-CX41MkDF.js";import"./vendor-remend-BWYYytN3.js";import"./vendor-katex-k3Ppq1Ha.js";import"./vendor-dompurify-r8glNMJW.js";import"./themeResolver-BmJyTmjJ.js";import"./vendor-pierre-theming-C6Z4M5_u.js";import"./vendor-shikijs-core-CGM_jqPK.js";import"./vendor-shikijs-types-CPSbSeK6.js";import"./vendor-shikijs-vscode-textmate-BgLrS_2D.js";import"./vendor-hast-util-to-html-BKBhbTDb.js";import"./vendor-html-void-elements-CkdplsNl.js";import"./vendor-property-information-rJCbAzvX.js";import"./vendor-zwitch-C2o2j-tx.js";import"./vendor-stringify-entities-CsH1VEn9.js";import"./vendor-character-entities-legacy-BpoLgcEt.js";import"./vendor-character-entities-html4-D7taRCQ7.js";import"./vendor-ccount-c2V3InAJ.js";import"./vendor-comma-separated-tokens-D8TqSuIK.js";import"./vendor-space-separated-tokens-DD3iYX1K.js";import"./vendor-hast-util-whitespace-D4Wp6AEg.js";const Ve="openchamber-md",Tt={name:Ve,colors:{"editor.background":"transparent","editor.foreground":"var(--md-syntax-foreground)"},tokenColors:[{scope:["comment","punctuation.definition.comment","string.comment"],settings:{foreground:"var(--md-syntax-comment)",fontStyle:"italic"}},{scope:["string","punctuation.definition.string","string.template"],settings:{foreground:"var(--md-syntax-string)"}},{scope:["constant.numeric","constant.language","constant.character","constant"],settings:{foreground:"var(--md-syntax-number)"}},{scope:["keyword","storage","storage.type","storage.modifier","keyword.control"],settings:{foreground:"var(--md-syntax-keyword)"}},{scope:["keyword.operator","punctuation.separator","punctuation.terminator"],settings:{foreground:"var(--md-syntax-operator)"}},{scope:["entity.name.function","support.function","meta.function-call"],settings:{foreground:"var(--md-syntax-function)"}},{scope:["entity.name.type","entity.name.class","support.type","support.class","entity.other.inherited-class"],settings:{foreground:"var(--md-syntax-type)"}},{scope:["variable","variable.other","variable.parameter","meta.definition.variable"],settings:{foreground:"var(--md-syntax-variable)"}},{scope:["variable.other.property","meta.property-name","support.type.property-name"],settings:{foreground:"var(--md-syntax-property)"}},{scope:["entity.name.tag","punctuation.definition.tag"],settings:{foreground:"var(--md-syntax-keyword)"}},{scope:["entity.other.attribute-name"],settings:{foreground:"var(--md-syntax-property)"}},{scope:["markup.bold","punctuation.definition.bold"],settings:{fontStyle:"bold"}},{scope:["markup.italic","punctuation.definition.italic"],settings:{fontStyle:"italic"}},{scope:["markup.heading","markup.heading entity.name"],settings:{foreground:"var(--md-syntax-keyword)",fontStyle:"bold"}},{scope:["markup.inserted","punctuation.definition.inserted"],settings:{foreground:"var(--md-syntax-inserted)"}},{scope:["markup.deleted","punctuation.definition.deleted"],settings:{foreground:"var(--md-syntax-deleted)"}},{scope:["invalid","invalid.illegal"],settings:{foreground:"var(--md-syntax-deleted)"}}]};let ve=!1;const Pt=()=>{ve||(ve=!0,_t(Ve,()=>Promise.resolve(Tt)))},x=t=>Number.isFinite(t)&&t>0,Ae=t=>{if(typeof t=="number")return x(t)?t:null;if(typeof t!="string")return null;const e=t.trim().match(/^([+-]?(?:(?:\d+\.?\d*)|(?:\.\d+))(?:[eE][+-]?\d+)?)(?:px)?$/);if(!e)return null;const r=Number(e[1]);return x(r)?r:null},me=(t,e,r)=>Math.min(r,Math.max(e,t)),Ft=6,ke=1.25,It=1.0015,Ot=.5,Dt=12,Ee=3,Wt=400,te='[data-markdown="mermaid-block"]',z=t=>t.querySelector(te)!==null,$t=t=>[t.x,t.y,t.width,t.height].map(e=>{const r=Number(e.toFixed(Ft));return Object.is(r,-0)?"0":String(r)}).join(" "),qt=t=>{const e=t.viewBox?.trim().split(/[\s,]+/).map(i=>Number.parseFloat(i));if(e?.length===4){const[i,o,s,a]=e;if(Number.isFinite(i)&&Number.isFinite(o)&&x(s)&&x(a))return{x:i,y:o,width:s,height:a}}const r=Ae(t.width),n=Ae(t.height);return r===null||n===null?null:{x:0,y:0,width:r,height:n}},Bt=t=>{let e=2166136261;for(let r=0;r<t.length;r+=1)e^=t.charCodeAt(r),e=Math.imul(e,16777619);return(e>>>0).toString(36)},zt=t=>{const e=t.renderMode||"unknown",r=t.svgMarkup??"";if(!r){const n=[t.viewBox??"",t.width??"",t.height??""];return n.some(i=>i!=="")?`${e}:bounds:${n.join(":")}`:`${e}:no-svg`}return[e,Bt(r)].join(":")},He=(t,e)=>{if(!x(e.width)||!x(e.height))return t;const r=t.width/t.height,n=e.width/e.height;if(r>n){const o=t.width/n;return{x:t.x,y:t.y-(o-t.height)/2,width:t.width,height:o}}const i=t.height*n;return{x:t.x-(i-t.width)/2,y:t.y,width:i,height:t.height}},Vt=({currentBox:t,viewport:e,delta:r})=>!x(e.width)||!x(e.height)||!x(t.width)||!x(t.height)?t:{x:t.x-r.x/e.width*t.width,y:t.y-r.y/e.height*t.height,width:t.width,height:t.height},Ht=(t,e)=>{const r=e.x-t.x,n=e.y-t.y;return r*r+n*n>Ee*Ee},Kt=({currentBox:t,contentBox:e,viewport:r,pointer:n,zoomFactor:i,minScale:o,maxScale:s})=>{if(!x(r.width)||!x(r.height)||!x(i)||!x(t.width)||!x(t.height)||!x(e.width)||!x(e.height)||!x(o)||!x(s))return t;const a=Math.min(o,s),l=Math.max(o,s),c=He(e,r),d=c.width/t.width,f=me(d*i,a,l),u=c.width/f,m=u/(t.width/t.height),g=me(n.x/r.width,0,1),A=me(n.y/r.height,0,1),k=t.x+g*t.width,v=t.y+A*t.height;return{x:k-g*u,y:v-A*m,width:u,height:m}},he=new WeakMap,jt=t=>t instanceof HTMLElement?he.get(t)??null:null,Ut=t=>t.querySelector('[data-markdown="mermaid-viewport"]')??t.querySelector('[data-markdown="mermaid"]'),Ce=t=>{const e=t.querySelector('[data-markdown="mermaid"] svg'),r=t.querySelector('[data-markdown="mermaid"]');return zt({renderMode:t.getAttribute("data-mermaid-render"),svgMarkup:r?.getAttribute("data-md-original-svg")??e?.outerHTML??null,viewBox:e?.getAttribute("viewBox"),width:e?.getAttribute("width"),height:e?.getAttribute("height")})},Q=t=>{const e=t.getBoundingClientRect();return{width:e.width,height:e.height}},Zt=(t,e)=>{const r=e.getBoundingClientRect();return{x:t.clientX-r.left,y:t.clientY-r.top}},Xt=t=>t instanceof Element&&!!t.closest('button, a, [role="button"]'),Gt=t=>{const e=Ut(t),r=t.querySelector('[data-markdown="mermaid"] svg');if(!e||!r)return null;const n=qt({viewBox:r.getAttribute("viewBox"),width:r.getAttribute("width"),height:r.getAttribute("height")});if(!n)return null;let i=n,o=null,s=null,a=null,l=null;const c=p=>{i=p,r.setAttribute("viewBox",$t(p)),r.removeAttribute("width"),r.removeAttribute("height")},d=()=>{c(He(n,Q(e)))},f=(p,C)=>{c(Kt({currentBox:i,contentBox:n,viewport:Q(e),pointer:p,zoomFactor:C,minScale:Ot,maxScale:Dt}))},u=()=>{const p=Q(e);f({x:p.width/2,y:p.height/2},ke)},m=()=>{const p=Q(e);f({x:p.width/2,y:p.height/2},1/ke)},g=p=>{!p.ctrlKey&&!p.metaKey||(p.preventDefault(),p.stopPropagation(),f(Zt(p,e),Math.pow(It,-p.deltaY)))},A=p=>{p.button!==0||Xt(p.target)||(o=p.pointerId,s={x:p.clientX,y:p.clientY},a=s,l!==null&&(window.clearTimeout(l),l=null),t.removeAttribute("data-mermaid-suppress-click"),e.setPointerCapture?.(p.pointerId),t.setAttribute("data-mermaid-panning","true"),p.preventDefault())},k=p=>{if(o!==p.pointerId||!a)return;const C={x:p.clientX,y:p.clientY};c(Vt({currentBox:i,viewport:Q(e),delta:{x:C.x-a.x,y:C.y-a.y}})),a=C,s&&Ht(s,C)&&t.setAttribute("data-mermaid-suppress-click","true"),p.preventDefault()},v=p=>{o===p.pointerId&&(e.releasePointerCapture?.(p.pointerId),o=null,s=null,a=null,t.removeAttribute("data-mermaid-panning"),t.hasAttribute("data-mermaid-suppress-click")&&(l=window.setTimeout(()=>{t.removeAttribute("data-mermaid-suppress-click"),l=null},Wt)))},S=()=>{d()};e.addEventListener("wheel",g,{passive:!1}),e.addEventListener("pointerdown",A),e.addEventListener("pointermove",k),e.addEventListener("pointerup",v),e.addEventListener("pointercancel",v),window.addEventListener("resize",S);const M=typeof ResizeObserver>"u"?null:new ResizeObserver(S);return M?.observe(e),d(),{zoomIn:u,zoomOut:m,fit:d,cleanup:()=>{e.removeEventListener("wheel",g),e.removeEventListener("pointerdown",A),e.removeEventListener("pointermove",k),e.removeEventListener("pointerup",v),e.removeEventListener("pointercancel",v),window.removeEventListener("resize",S),M?.disconnect(),l!==null&&window.clearTimeout(l),t.removeAttribute("data-mermaid-panning"),t.removeAttribute("data-mermaid-suppress-click"),he.delete(t)}}},Yt=t=>{const e=new Map,r=new Map,n=()=>{for(const[o,s]of Array.from(e.entries())){const a=Ce(o);(!t.contains(o)||a!==r.get(o))&&(s.cleanup(),e.delete(o),r.delete(o))}for(const o of Array.from(t.querySelectorAll(te))){if(e.has(o)||o.querySelector('[data-markdown="mermaid"] svg')===null)continue;const s=Gt(o);s&&(e.set(o,s),r.set(o,Ce(o)),he.set(o,s))}},i=()=>{for(const o of e.values())o.cleanup();e.clear(),r.clear()};return n(),{refresh:n,cleanup:i}},B=t=>`<svg class="remixicon size-3.5" viewBox="0 0 24 24" aria-hidden="true"><use href="#oc-${t}"></use></svg>`,re={copy:B("file-copy"),check:B("check"),download:B("download"),zoomIn:B("add"),zoomOut:B("subtract"),fit:B("refresh"),textWrap:B("text-wrap"),image:B("file-image")},Ke="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)]",ne=(t,e)=>{t.innerHTML=e},Jt=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 r=document.createElement("span");r.className="inline-flex shrink-0",r.setAttribute("aria-hidden","true"),r.setAttribute("data-openchamber-markdown-image-label-icon","true"),ne(r,re.image),e.prepend(r)}},W=(t,e,r)=>{const n=document.createElement("button");return n.type="button",n.className=Ke,n.setAttribute("data-md-action",r),n.setAttribute("title",e),n.setAttribute("aria-label",e),ne(n,re[t]),n},je=(t,e,r)=>{const n=t.querySelector("[data-md-code-body]"),i=t.querySelector("pre"),o=t.querySelector("pre code"),s=t.querySelectorAll("[data-md-code-line-content]"),a=t.querySelector('[data-md-action="toggle-code-wrap"]');t.setAttribute("data-code-wrap",e?"true":"false"),n?.classList.toggle("overflow-x-auto",!e),n?.classList.toggle("overflow-x-hidden",e),i?.classList.toggle("whitespace-pre-wrap",e),i?.classList.toggle("break-words",e),o?.classList.toggle("whitespace-pre-wrap",e),o?.classList.toggle("break-words",e),i&&(i.style.whiteSpace=e?"pre-wrap":"pre",i.style.overflowWrap=e?"anywhere":"normal"),o&&(o.style.whiteSpace=e?"pre-wrap":"pre",o.style.overflowWrap=e?"anywhere":"normal");for(const l of Array.from(s))l.style.whiteSpace=e?"pre-wrap":"pre",l.style.overflowWrap=e?"anywhere":"normal";if(a){const l=e?r.disableCodeWrap:r.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")}},Ue=t=>{const e=t.querySelector(":scope > code");if(!e||e.hasAttribute("data-md-code-lines"))return;const r=e.textContent??"",n=r.endsWith(`
|
|
2
|
-
`),i=n?r.slice(0,-1).split(`
|
|
3
|
-
`):r.split(`
|
|
4
|
-
`),o=i.length>0?i:[""],s=Array.from(e.children).filter(c=>c.classList.contains("line"));n&&s.length===o.length+1&&s.at(-1)?.textContent===""&&s.pop();const a=s.length===o.length,l=document.createDocumentFragment();o.forEach((c,d)=>{const f=document.createElement("span");f.setAttribute("data-md-code-line","");const u=document.createElement("span");u.setAttribute("data-md-code-line-number",""),u.setAttribute("aria-hidden","true"),u.textContent=String(d+1);const m=document.createElement("span");if(m.setAttribute("data-md-code-line-content",""),a){const g=s[d];g&&m.append(...Array.from(g.childNodes))}else m.textContent=c;if(f.append(u,m),l.appendChild(f),d<o.length-1||n){const g=document.createElement("span");g.setAttribute("data-md-code-line-break",""),g.textContent=`
|
|
5
|
-
`,l.appendChild(g)}}),e.replaceChildren(l),e.setAttribute("data-md-code-lines",""),e.toggleAttribute("data-md-code-trailing-newline",n)},Ze=t=>{const e=Array.from(t.querySelectorAll("[data-md-code-line-content]"));if(e.length===0)return t.textContent??"";const r=e.map(n=>n.textContent??"").join(`
|
|
6
|
-
`);return t.hasAttribute("data-md-code-trailing-newline")?`${r}
|
|
7
|
-
`:r},Qt=(t,e,r)=>{const n=t.querySelectorAll('[data-component="markdown-code"]');for(const i of Array.from(n)){const o=i.querySelector("pre");o&&Ue(o),je(i,e,r)}},Se=(t,e,r,n)=>{ne(t,re.check),t.setAttribute("title",e),t.setAttribute("aria-label",e),window.setTimeout(()=>{ne(t,re[r]),t.setAttribute("title",n),t.setAttribute("aria-label",n)},2e3)},er=t=>{const e=t.querySelectorAll(":not(pre) > code");for(const r of Array.from(e))r.getAttribute("data-markdown")!=="inline-code"&&r.setAttribute("data-markdown","inline-code")},tr=(t,e)=>{const r=t.querySelectorAll("pre");for(const n of Array.from(r)){if(n.querySelector("code.language-mermaid"))continue;const i=n.parentElement;if(!i||i.closest('[data-component="markdown-code"]'))continue;const o=n.querySelector("code")?.className.match(/language-([\w+#.-]+)/)?.[1],s=n.getAttribute("data-md-lang")??o??"text",a=document.createElement("div");a.setAttribute("data-component","markdown-code"),a.className="my-4 group overflow-hidden rounded-2xl border border-border/80 bg-[var(--surface-elevated)]";const l=document.createElement("div");l.className="flex items-center justify-between border-b border-border/70 px-3 py-1.5";const c=document.createElement("span");c.className="font-mono text-[13px] text-muted-foreground",c.textContent=s;const d=W("copy",e.labels.copy,"copy-code"),f=W("textWrap",e.codeBlockLineWrap?e.labels.disableCodeWrap:e.labels.enableCodeWrap,"toggle-code-wrap");l.appendChild(c);const u=document.createElement("div");u.className="flex items-center gap-1",u.setAttribute("data-md-code-actions",""),u.appendChild(f),u.appendChild(d),l.appendChild(u);const m=document.createElement("div");m.setAttribute("data-md-code-body",""),m.className="px-3 py-2.5 overflow-x-auto",i.replaceChild(a,n),n.style.margin="0",n.style.background="transparent",n.classList.add("min-w-0","w-full","flex-1"),e.deferCodeLineNumberSync||Ue(n),m.appendChild(n),a.appendChild(l),a.appendChild(m),je(a,e.codeBlockLineWrap,e.labels)}},Le=t=>{const e=[],r=[],n=t.querySelectorAll("thead th");for(const o of Array.from(n))e.push((o.textContent??"").trim());const i=t.querySelectorAll("tbody tr");for(const o of Array.from(i)){const s=Array.from(o.querySelectorAll("td")).map(a=>(a.textContent??"").trim());s.length>0&&r.push(s)}return{headers:e,rows:r}},rr=t=>/[",\n]/.test(t)?`"${t.replace(/"/g,'""')}"`:t,Me=({headers:t,rows:e})=>[t,...e].map(r=>r.map(rr).join(",")).join(`
|
|
8
|
-
`),nr=({headers:t,rows:e})=>[t,...e].map(r=>r.join(" ")).join(`
|
|
9
|
-
`),Ne=({headers:t,rows:e})=>{const r=`| ${t.join(" | ")} |`,n=`| ${t.map(()=>"---").join(" | ")} |`,i=e.map(o=>`| ${o.join(" | ")} |`).join(`
|
|
10
|
-
`);return`${r}
|
|
11
|
-
${n}
|
|
12
|
-
${i}`},Re=(t,e)=>{const r=document.createElement("div");r.className=`absolute top-full right-0 mt-1 hidden ${pt}`,r.style.backgroundColor="var(--surface-elevated)",r.style.color="var(--surface-elevated-foreground)",r.setAttribute("data-md-menu",t);for(const n of e){const i=document.createElement("button");i.type="button",i.className=`w-full text-left ${ft}`,i.setAttribute("data-md-action",`${t}-${n.key}`),i.textContent=n.label,r.appendChild(i)}return r},or=(t,e)=>{const r=t.querySelectorAll("table");for(const n of Array.from(r)){if(n.closest('[data-markdown="table-wrapper"]'))continue;const o=document.createElement("div");o.className="group my-4 flex flex-col space-y-2",o.setAttribute("data-markdown","table-wrapper");const s=document.createElement("div");s.className="flex items-center justify-end gap-1";const a=document.createElement("div");a.className="relative",a.appendChild(W("copy",e.copyTable,"table-copy-toggle")),a.appendChild(Re("table-copy",[{key:"csv",label:"CSV"},{key:"tsv",label:"TSV"},{key:"markdown",label:"Markdown"}]));const l=document.createElement("div");l.className="relative",l.appendChild(W("download",e.downloadTable,"table-download-toggle")),l.appendChild(Re("table-download",[{key:"csv",label:"CSV"},{key:"markdown",label:"Markdown"}])),s.appendChild(a),s.appendChild(l);const c=document.createElement("div");c.className="overflow-x-auto rounded-lg border border-border/80 bg-[var(--surface-elevated)]";const d=n.parentElement;if(!d)continue;d.replaceChild(o,n),n.setAttribute("data-markdown","table"),n.classList.add("w-full","border-collapse","text-sm");for(const u of Array.from(n.querySelectorAll("tr")))u.classList.add("border-b","border-border/60");const f=n.querySelector("tbody tr:last-child");f?.classList.remove("border-b"),f?.classList.add("border-0");for(const u of Array.from(n.querySelectorAll("th")))u.classList.add("border-r","border-border/60","px-4","py-2.5","text-left","align-middle","font-semibold","text-foreground","last:border-r-0");for(const u of Array.from(n.querySelectorAll("td")))u.classList.add("border-r","border-border/60","px-4","py-2.5","align-middle","text-foreground/90","last:border-r-0");c.appendChild(n),o.appendChild(s),o.appendChild(c)}},ir=(t,e)=>{const r=t.querySelectorAll("pre > code.language-mermaid");for(const n of Array.from(r)){const i=n.parentElement;if(!i)continue;const o=(n.textContent??"").replace(/\s+$/,""),s=e.renderMermaid(o),a=document.createElement("div");a.setAttribute("data-markdown","mermaid-block"),a.setAttribute("data-md-source",o),a.className="group relative";const l=document.createElement("div");l.setAttribute("data-markdown","mermaid-scroll");const c=document.createElement("div");if(c.setAttribute("data-markdown","mermaid-toolbar"),c.className="absolute top-1 right-2 flex items-center gap-1 opacity-0 group-hover:opacity-100 group-focus-within:opacity-100 transition-opacity",s.svg){a.setAttribute("data-mermaid-render","svg");const f=document.createElement("div");f.setAttribute("data-markdown","mermaid-viewport");const u=document.createElement("div");if(u.setAttribute("data-markdown","mermaid"),u.setAttribute("data-md-original-svg",s.svg),u.innerHTML=s.svg,f.appendChild(u),l.appendChild(f),e.mermaidControls.showPanZoomControls&&(c.appendChild(W("zoomIn",e.labels.zoomInDiagram,"mermaid-zoom-in")),c.appendChild(W("zoomOut",e.labels.zoomOutDiagram,"mermaid-zoom-out")),c.appendChild(W("fit",e.labels.resetDiagramView,"mermaid-fit"))),e.mermaidControls.copy){const m=W("copy",e.labels.copyDiagram,"mermaid-copy");m.setAttribute("data-md-source",o),c.appendChild(m)}if(e.mermaidControls.download){const m=W("download",e.labels.downloadDiagram,"mermaid-download");m.setAttribute("data-md-svg","1"),c.appendChild(m)}}else{a.setAttribute("data-mermaid-render","ascii");const f=document.createElement("pre");if(f.setAttribute("data-markdown","mermaid-ascii"),f.textContent=s.ascii||o,l.appendChild(f),e.mermaidControls.copy){const u=W("copy",e.labels.copyDiagram,"mermaid-copy");u.setAttribute("data-md-source",s.ascii||o),c.appendChild(u)}}a.appendChild(l),a.appendChild(c);const d=i.parentElement;d&&d.replaceChild(a,i)}},ar=(t,e)=>{const r=t.querySelectorAll("a[href]");for(const n of Array.from(r)){if(n.getAttribute("data-md-link-decorated")==="true"||n.getAttribute("data-openchamber-file-link")==="true")continue;const i=n.getAttribute("href")??"";if(!De(i))continue;n.setAttribute("data-md-link-decorated","true");const o=mt(i);if(o){const s=document.createElement("span");s.className="mr-1 inline-flex size-[18px] items-center justify-center rounded border border-[var(--border)] bg-[var(--interactive-hover)] align-middle";const a=document.createElement("img");a.src=o,a.alt="",a.setAttribute("aria-hidden","true"),a.loading="lazy",a.decoding="async",a.className="size-3.5 rounded-sm",a.addEventListener("error",()=>s.remove(),{once:!0}),s.appendChild(a),n.parentNode?.insertBefore(s,n)}if(e.onPreviewLoopback&&ut(i)){const s=document.createElement("button");s.type="button",s.className=`ml-1 align-middle ${Ke}`,s.setAttribute("data-md-action","preview-loopback"),s.setAttribute("data-md-url",i),s.setAttribute("title",e.labels.previewTitle),s.setAttribute("aria-label",e.labels.previewLabel),ne(s,re.download),n.parentNode?.insertBefore(s,n.nextSibling)}}},xe=(t,e)=>{Jt(t),er(t),ir(t,e),tr(t,e),or(t,e.labels),ar(t,e)},_e=(t,e,r)=>{const n=new Blob([e],{type:r}),i=URL.createObjectURL(n),o=document.createElement("a");o.href=i,o.download=t,document.body.appendChild(o),o.click(),document.body.removeChild(o),URL.revokeObjectURL(i)},ae=t=>{for(const e of Array.from(t.querySelectorAll("[data-md-menu]")))e.classList.add("hidden")},sr=(t,e)=>{const r=n=>{const i=n.target;if(!(i instanceof Element))return;const o=i.closest("[data-md-action]");if(!o){ae(t);return}const s=o.getAttribute("data-md-action")??"";if(s==="copy-code"){const a=o.closest('[data-component="markdown-code"]')?.querySelector("code"),l=a?Ze(a):"";l&&de(l).then(()=>Se(o,e.labels.copied,"copy",e.labels.copy));return}if(s==="toggle-code-wrap"){n.preventDefault(),e.onToggleCodeBlockLineWrap?.();return}if(s==="table-copy-toggle"||s==="table-download-toggle"){n.preventDefault();const a=o.parentElement?.querySelector("[data-md-menu]")??null,l=a?.classList.contains("hidden")??!1;ae(t),a&&l&&a.classList.remove("hidden");return}if(s.startsWith("table-copy-")){const a=s.replace("table-copy-",""),l=o.closest('[data-markdown="table-wrapper"]')?.querySelector("table");if(l instanceof HTMLTableElement){const c=Le(l),d=a==="csv"?Me(c):a==="tsv"?nr(c):Ne(c);de(d)}ae(t);return}if(s.startsWith("table-download-")){const a=s.replace("table-download-",""),l=o.closest('[data-markdown="table-wrapper"]')?.querySelector("table");if(l instanceof HTMLTableElement){const c=Le(l),d=a==="csv"?Me(c):Ne(c);_e(a==="csv"?"table.csv":"table.md",d,a==="csv"?"text/csv":"text/markdown")}ae(t);return}if(s==="mermaid-copy"){const a=o.getAttribute("data-md-source")??"";a&&de(a).then(()=>Se(o,e.labels.copied,"copy",e.labels.copyDiagram));return}if(s==="mermaid-zoom-in"||s==="mermaid-zoom-out"||s==="mermaid-fit"){n.preventDefault();const a=o.closest('[data-markdown="mermaid-block"]'),l=jt(a);s==="mermaid-zoom-in"?l?.zoomIn():s==="mermaid-zoom-out"?l?.zoomOut():l?.fit();return}if(s==="mermaid-download"){const a=o.closest('[data-markdown="mermaid-block"]')?.querySelector('[data-markdown="mermaid"]'),l=a?.getAttribute("data-md-original-svg")??a?.innerHTML??"";l&&_e("diagram.svg",l,"image/svg+xml;charset=utf-8");return}if(s==="preview-loopback"){n.preventDefault();const a=o.getAttribute("data-md-url")??"";a&&e.onPreviewLoopback?.(a);return}};return t.addEventListener("click",r),()=>t.removeEventListener("click",r)},Te=(t,e,r)=>{let n=0;for(const o of t){const s=n+o.data.length;if(e<s||e===s&&r==="left")return{node:o,offset:Math.max(0,e-n)};n=s}const i=t.at(-1);return i?{node:i,offset:i.data.length}:null},lr=new Set(["dockerfile","makefile","readme","license",".env",".gitignore",".npmrc"]),Pe=Array.from(lr).map(t=>t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")).join("|"),cr=t=>gt(t),dr=t=>ht(t),mr=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 r=decodeURIComponent(e.pathname);return/^\/[A-Za-z]:\//.test(r)?r.slice(1):r.startsWith("/")?r:null}catch{return null}},ce=t=>{let e=(t||"").trim();return e?((e.startsWith("`")&&e.endsWith("`")||e.startsWith('"')&&e.endsWith('"')||e.startsWith("'")&&e.endsWith("'"))&&(e=e.slice(1,-1).trim()),e=e.replace(/[.,;!?]+$/g,""),e.endsWith(")")&&!e.includes("(")&&(e=e.slice(0,-1)),e.endsWith("]")&&!e.includes("[")&&(e=e.slice(0,-1)),e):""},se=t=>{let e=ce(t);if(!e)return"";const r=e.indexOf(";");r>=0&&(e=e.slice(0,r)),e=e.replace(/#.*$/,"");const n=e.match(/^(.*\.[A-Za-z0-9_-]{1,16}):.*$/);n&&(e=n[1]??e);const i=Pe.length>0?e.match(new RegExp(`^(.*(?:/|^)(${Pe})):.*$`,"i")):null;return i&&(e=i[1]??e),ce(e)},Xe=t=>{const e=ce(t);if(!e)return null;const r=e.indexOf(";"),n=r>=0?ce(e.slice(0,r)):e;if(!n)return null;const i=n.match(/^(.*?):(\d+)-(\d+)$/);if(i){const l=se(i[1]??""),c=Number.parseInt(i[2]??"",10),d=Number.parseInt(i[3]??"",10);return!l||!Number.isFinite(c)||!Number.isFinite(d)||d<c?null:{path:l,line:c,endLine:d}}const o=n.match(/^(.*)#L(\d+)(?:C(\d+))?$/i);if(o){const l=se(o[1]??""),c=Number.parseInt(o[2]??"",10),d=o[3]?Number.parseInt(o[3],10):void 0;return!l||!Number.isFinite(c)?null:{path:l,line:c,column:Number.isFinite(d??Number.NaN)?d:void 0}}const s=n.match(/^(.*?):(\d+)(?::(\d+))?$/);if(s){const l=se(s[1]??""),c=Number.parseInt(s[2]??"",10),d=s[3]?Number.parseInt(s[3],10):void 0;return!l||!Number.isFinite(c)?null:{path:l,line:c,column:Number.isFinite(d??Number.NaN)?d:void 0}}const a=se(n);return a?{path:a}:null},ue=/(?:[A-Za-z]:[\\/])?[\w.\-/@+]*[\w\-/@+]\.[A-Za-z0-9]{1,8}(?::\d+(?:-\d+)?(?::\d+)?)?/g,Ge=()=>{const t=K.c(4),e=bt();let r;t[0]===Symbol.for("react.memo_cache_sentinel")?(r=ye(!1),t[0]=r):r=t[0];const n=r;let i;t[1]===Symbol.for("react.memo_cache_sentinel")?(i=ye(!0),t[1]=i):i=t[1];const o=i;let s;return t[2]!==e?.currentTheme?(s=e?.currentTheme??(typeof window<"u"&&window.matchMedia("(prefers-color-scheme: dark)").matches?o:n),t[2]=e?.currentTheme,t[3]=s):s=t[3],s},Ye=t=>{const e=K.c(4),{containerRef:r,enabled:n}=t;let i,o;e[0]!==r||e[1]!==n?(i=()=>{if(n===!1)return;const s=r.current;if(!s)return;const a=Fr;return s.addEventListener("click",a),()=>{s.removeEventListener("click",a)}},o=[r,n],e[0]=r,e[1]=n,e[2]=i,e[3]=o):(i=e[2],o=e[3]),_.useEffect(i,o)},J={download:!0,copy:!0,showPanZoomControls:!0},Je=!0,ur=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},Fe='[data-openchamber-file-link="true"]',Qe="data-openchamber-block-path-token",et=`[${Qe}]`,Y="data-openchamber-block-paths-scanned",pr=2e5,fr=4,hr=1e3,gr=200,br=80,wr=40,Ie=160,V=new Map;let le=0;const Oe=[],yr=()=>ze()?gr:hr,vr=()=>ze()?wr:br,Ar=new Set(["dockerfile","makefile","readme","license",".env",".gitignore",".npmrc"]),ge=t=>cr(t),kr=t=>dr(t),Er=(t,e)=>Et(t,e),Cr=t=>{const e=t.split("/").filter(Boolean).pop()??"";return!e||e.endsWith(".")?!1:/\.[A-Za-z0-9_-]{1,16}$/.test(e)},tt=t=>{if(!t||t.startsWith("--")||t.includes("://")||/[<>]/.test(t)||/\s{2,}/.test(t))return!1;const e=ge(t),r=e.split("/").filter(Boolean).pop()??e;if(!r||r==="."||r==="..")return!1;const n=r.toLowerCase();return Ar.has(n)||n.startsWith(".")&&n.length>1?!0:Cr(e)},rt=t=>{const e=Xe(t);return e?tt(e.path):!1},Sr=t=>{const e=t.querySelectorAll(et);for(const n of Array.from(e))n.replaceWith(t.ownerDocument.createTextNode(n.textContent??""));const r=t.querySelectorAll(`code[${Y}]`);for(const n of Array.from(r))n.removeAttribute(Y),n.normalize()},pe=t=>{if(t.tagName.toLowerCase()==="a"){const e=t.getAttribute("href")?.trim(),r=e?mr(e):null;if(r)return r;if(e&&rt(e))return e}return(t.textContent||"").trim()},Lr=t=>{const e=t.querySelectorAll("pre code");if(e.length===0)return;const r=t.ownerDocument;if(r)for(const n of Array.from(e)){if(n.getAttribute(Y)==="true")continue;if((n.textContent??"").length>pr){n.setAttribute(Y,"true");continue}const i=r.createTreeWalker(n,NodeFilter.SHOW_TEXT),o=[];let s=i.nextNode();for(;s;){const d=s;d.parentElement?.closest("[data-md-code-line-number]")||o.push(d),s=i.nextNode()}const a=Ze(n);if(!a.includes(".")){n.setAttribute(Y,"true");continue}ue.lastIndex=0;const l=[];let c=ue.exec(a);for(;c;){const d=c[0];d&&rt(d)&&l.push({start:c.index,end:c.index+d.length,raw:d}),c=ue.exec(a)}for(const{start:d,end:f,raw:u}of l.reverse()){const m=Te(o,d,"right"),g=Te(o,f,"left");if(!m||!g)continue;const A=r.createRange();A.setStart(m.node,m.offset),A.setEnd(g.node,g.offset);const k=r.createElement("span");k.setAttribute(Qe,"true"),k.textContent=u,A.deleteContents(),A.insertNode(k)}n.setAttribute(Y,"true")}},fe=(t,e)=>{const r=Xe(t);if(!r||!tt(r.path))return null;const n=kr(r.path)?ge(r.path):Er(e,r.path);return n?{...r,resolvedPath:n}:null},Mr=t=>{const e=ge(t);if(!e)return Promise.resolve(!1);const r=V.get(e);if(r)return V.delete(e),V.set(e,r),r;const n=new Promise(o=>{const s=()=>{le+=1,Mt(`/api/fs/stat?path=${encodeURIComponent(e)}&optional=true`,{method:"GET",cache:"no-store"}).then(async a=>{if(!a.ok){o(!1);return}const l=await a.json().catch(()=>null);o(l?.exists!==!1)}).catch(()=>o(!1)).finally(()=>{le=Math.max(0,le-1),Oe.shift()?.()})};if(le<fr){s();return}Oe.push(s)}),i=yr();for(;V.size>=i;){const o=V.keys().next().value;if(typeof o!="string")break;V.delete(o)}return V.set(e,n),n},Nr=(t,e)=>t||kt(t,e),nt=t=>{const e=K.c(7),{containerRef:r,effectiveDirectory:n,editor:i,preferRuntimeEditor:o,enabled:s}=t,a=_.useRef(null);let l,c;e[0]!==r||e[1]!==i||e[2]!==n||e[3]!==s||e[4]!==o?(l=()=>{const d=r.current;if(!d)return;let f=!1;const u=vr(),m=s&&!Nt(),g=Ir,A=()=>{const y=d.querySelectorAll(Fe);for(const b of Array.from(y))g(b);Sr(d)};if(!m){A();return}const k=y=>{const b=y;if(a.current!==null&&typeof window<"u"&&window.clearTimeout(a.current),typeof window>"u"){v();return}a.current=window.setTimeout(()=>{a.current=null,window.requestAnimationFrame(()=>{f||v()})},b)},v=()=>{m&&Lr(d);const y=d.querySelectorAll(`[data-markdown="inline-code"], a, ${et}`);let b=0;for(const h of Array.from(y)){const T=pe(h),w=fe(T,n);if(g(h),!w||b>=u)continue;b=b+1,(St()&&Lt()&&!be(w.resolvedPath,n)?Promise.resolve(!0):Mr(w.resolvedPath)).then(I=>{if(f||!I||!d.contains(h))return;const P=pe(h),O=fe(P,n);!O||O.resolvedPath!==w.resolvedPath||(h.setAttribute("data-openchamber-file-link","true"),h.setAttribute("data-openchamber-file-ref",P),h.setAttribute("data-openchamber-file-path",O.resolvedPath),h.setAttribute("title","Open file"),h.tagName.toLowerCase()!=="a"&&(h.setAttribute("role","button"),h.setAttribute("tabindex","0")))})}},S=async y=>{const b=y.getAttribute("data-openchamber-file-ref")||pe(y),h=fe(b,n);if(!h)return;const T=Nr(n,h.resolvedPath);if(o&&i){i.openFile(h.resolvedPath,Number.isFinite(h.line??Number.NaN)?Math.max(1,Math.trunc(h.line)):void 0,Number.isFinite(h.column??Number.NaN)?Math.max(1,Math.trunc(h.column)):void 0);return}be(h.resolvedPath,n)||await At(h.resolvedPath,n);const w=G.getState();Number.isFinite(h.line??Number.NaN)?w.openContextFileAtLine(T,h.resolvedPath,Math.max(1,Math.trunc(h.line)),Number.isFinite(h.column??Number.NaN)?Math.max(1,Math.trunc(h.column)):1):w.openContextFile(T,h.resolvedPath)},M=y=>{const b=y.target;if(!(b instanceof Element))return;const h=b.closest(Fe);h instanceof HTMLElement&&(y.preventDefault(),y.stopPropagation(),S(h))},p=y=>{if(y.key!=="Enter"&&y.key!==" ")return;const b=y.target;!(b instanceof HTMLElement)||b.getAttribute("data-openchamber-file-link")!=="true"||(y.preventDefault(),y.stopPropagation(),S(b))};k(Ie);const C=new MutationObserver(()=>{k(Ie)});return C.observe(d,{childList:!0,subtree:!0}),d.addEventListener("click",M),d.addEventListener("keydown",p),()=>{f=!0,a.current!==null&&typeof window<"u"&&window.clearTimeout(a.current),a.current=null,C.disconnect(),d.removeEventListener("click",M),d.removeEventListener("keydown",p)}},c=[r,i,n,o,s],e[0]=r,e[1]=i,e[2]=n,e[3]=s,e[4]=o,e[5]=l,e[6]=c):(l=e[5],c=e[6]),_.useEffect(l,c)},ot=t=>{const e=K.c(7),{containerRef:r,onShowPopup:n,enableFullscreen:i,enablePanZoom:o,allowMermaidWheelEvents:s}=t;let a,l;e[0]!==s||e[1]!==r||e[2]!==i||e[3]!==o||e[4]!==n?(a=()=>{const c=r.current;if(!c)return;const d=u=>{if(!i||!n)return;const m=u.target;if(!(m instanceof Element)||m.closest('button, a, [role="button"]'))return;const g=m.closest(te);if(!g)return;if(g instanceof HTMLElement&&g.hasAttribute("data-mermaid-suppress-click")){g.removeAttribute("data-mermaid-suppress-click");return}const k=Array.from(c.querySelectorAll(te)).indexOf(g);if(k<0)return;const v=g instanceof HTMLElement?g.getAttribute("data-md-source"):null;if(!v||v.trim().length===0)return;const S=`Diagram ${k+1}`;n({open:!0,title:S,content:"",metadata:{tool:"mermaid-preview",filename:S},mermaid:{url:`data:text/plain;charset=utf-8,${encodeURIComponent(v)}`,source:v,filename:S}})},f=u=>{if(s||(u.ctrlKey||u.metaKey)&&o)return;const m=u.target;!(m instanceof Element)||!m.closest(te)||u.stopPropagation()};return c.addEventListener("click",d),c.addEventListener("wheel",f,{capture:!0,passive:!0}),()=>{c.removeEventListener("click",d),c.removeEventListener("wheel",f,!0)}},l=[s,r,i,o,n],e[0]=s,e[1]=r,e[2]=i,e[3]=o,e[4]=n,e[5]=a,e[6]=l):(a=e[5],l=e[6]),_.useEffect(a,l)},H=new Map,Rr=100,xr=(t,e)=>{const r=H.get(t);if(r)return H.delete(t),H.set(t,r),r;const n=e();if(H.set(t,n),H.size>Rr){const i=H.keys().next().value;i&&H.delete(i)}return n},_r=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"}),it=(t,e,r,n=J)=>{const{t:i}=wt(),o=_.useMemo(()=>({copy:i("markdownRenderer.code.actions.copyTitle"),copied:i("markdownRenderer.code.actions.copiedTitle"),enableCodeWrap:i("markdownRenderer.code.actions.enableWrapTitle"),disableCodeWrap:i("markdownRenderer.code.actions.disableWrapTitle"),copyTable:i("markdownRenderer.table.actions.copyTitle"),downloadTable:i("markdownRenderer.table.actions.downloadTitle"),copyDiagram:i("markdownRenderer.mermaid.actions.copySourceTitle"),downloadDiagram:i("markdownRenderer.mermaid.actions.downloadSvgTitle"),zoomInDiagram:i("markdownRenderer.mermaid.actions.zoomInTitle"),zoomOutDiagram:i("markdownRenderer.mermaid.actions.zoomOutTitle"),resetDiagramView:i("markdownRenderer.mermaid.actions.resetViewTitle"),previewLabel:i("terminalView.preview.open"),previewTitle:i("terminalView.preview.openTitle")}),[i]),s=G(c=>c.codeBlockLineWrap),a=G(c=>c.setCodeBlockLineWrap),l=_.useCallback(()=>{a(!G.getState().codeBlockLineWrap)},[a]);return _.useMemo(()=>{const c=_r(t),d=G.getState().mermaidRenderingMode,f=t.metadata?.id??"theme";return{labels:o,mermaidControls:n,codeBlockLineWrap:s,deferCodeLineNumberSync:e,onToggleCodeBlockLineWrap:l,renderMermaid:m=>xr(`${f}:${d}:${m}`,()=>{try{return d==="ascii"?{ascii:ct(m)}:{svg:dt(m,c)}}catch{return{}}}),onPreviewLoopback:r}},[t,o,n,s,e,l,r])},at=t=>{const e=K.c(35),{containerRef:r,text:n,streaming:i,cacheKey:o,imageMode:s,syntaxVars:a,ctx:l}=t,c=s===void 0?"inline":s;let d;e[0]===Symbol.for("react.memo_cache_sentinel")?(d=[],e[0]=d):d=e[0],_.useEffect(Or,d);const f=_.useRef(null);let u;e[1]!==r?(u=()=>{const w=r.current;if(w){if(!f.current){if(!z(w))return;f.current=Yt(w);return}f.current.refresh()}},e[1]=r,e[2]=u):u=e[2];const m=u;let g,A;e[3]!==r||e[4]!==l||e[5]!==c||e[6]!==m||e[7]!==n?(g=()=>{const w=r.current,E=w?.querySelector("[data-markdown-content]")??w;if(E&&n&&E.childNodes.length===0){const N=document.createElement("div");N.setAttribute("data-md-block",""),N.style.display="contents",N.innerHTML=Rt(n,c),xe(N,l),E.appendChild(N),z(N)&&m()}},A=[r,n,c,l,m],e[3]=r,e[4]=l,e[5]=c,e[6]=m,e[7]=n,e[8]=g,e[9]=A):(g=e[8],A=e[9]),_.useLayoutEffect(g,A);let k,v;e[10]===Symbol.for("react.memo_cache_sentinel")?(k=()=>()=>{f.current?.cleanup(),f.current=null},v=[],e[10]=k,e[11]=v):(k=e[10],v=e[11]),_.useEffect(k,v);let S,M;e[12]!==o||e[13]!==r||e[14]!==l||e[15]!==c||e[16]!==m||e[17]!==i||e[18]!==n?(S=()=>{const w=r.current;if(!w)return;const E=w.querySelector("[data-markdown-content]")??w;let N=!0;return xt(n,i,o,c).then(I=>{if(!N)return;const P=Array.from(E.children);I.forEach((R,F)=>{let L=P[F];if(L||(L=document.createElement("div"),L.setAttribute("data-md-block",""),L.style.display="contents",E.appendChild(L)),L.getAttribute("data-md-id")===R.id)return;const $=document.createElement("div");$.innerHTML=R.html,xe($,l);const j=z(L),q=z($);lt(L,$,{childrenOnly:!0,onBeforeElUpdated:Dr}),L.setAttribute("data-md-id",R.id),(j||q||z(L))&&m()});const O=z(E);let D=!1;for(let R=P.length-1;R>=I.length;R=R-1,R){const F=P[R];F&&z(F)&&(D=!0),F?.remove()}(D||P.length>I.length&&O)&&m()}),()=>{N=!1}},M=[r,n,i,o,c,l,m],e[12]=o,e[13]=r,e[14]=l,e[15]=c,e[16]=m,e[17]=i,e[18]=n,e[19]=S,e[20]=M):(S=e[19],M=e[20]),_.useEffect(S,M);let p,C;e[21]!==r||e[22]!==l?(p=()=>{const w=r.current;if(w)return sr(w,l)},C=[r,l],e[21]=r,e[22]=l,e[23]=p,e[24]=C):(p=e[23],C=e[24]),_.useEffect(p,C);let y,b;e[25]!==r||e[26]!==a?(y=()=>{const w=r.current,E=w?.querySelector("[data-markdown-content]")??w;if(E)for(const[N,I]of Object.entries(a))E.style.setProperty(N,I)},b=[r,a],e[25]=r,e[26]=a,e[27]=y,e[28]=b):(y=e[27],b=e[28]),_.useEffect(y,b);let h,T;e[29]!==r||e[30]!==l.codeBlockLineWrap||e[31]!==l.deferCodeLineNumberSync||e[32]!==l.labels?(h=()=>{const w=r.current,E=w?.querySelector("[data-markdown-content]")??w;E&&(l.deferCodeLineNumberSync||Qt(E,l.codeBlockLineWrap,l.labels))},T=[r,l.codeBlockLineWrap,l.deferCodeLineNumberSync,l.labels],e[29]=r,e[30]=l.codeBlockLineWrap,e[31]=l.deferCodeLineNumberSync,e[32]=l.labels,e[33]=h,e[34]=T):(h=e[33],T=e[34]),_.useEffect(h,T)},st=t=>t==="tool"?"markdown-content markdown-tool":t==="reasoning"?"markdown-content markdown-reasoning":"markdown-content leading-relaxed",Tr=t=>{const e=K.c(33),{content:r,part:n,messageId:i,isAnimated:o,skipFadeIn:s,className:a,isStreaming:l,disableStreamAnimation:c,variant:d,onShowPopup:f,enableFileReferences:u}=t,m=o===void 0?!0:o,g=s===void 0?!1:s,A=l===void 0?!1:l,k=c===void 0?!1:c,v=d===void 0?"assistant":d,S=u===void 0?!0:u;we("ui.markdown_renderer.render"),A&&we("ui.markdown_renderer.render.streaming"),Ct("ui.markdown_renderer.content_len",r.length);const M=Ge(),{editor:p,runtime:C}=We(),y=_.useRef(null),b=$e()??"",h=G(Wr);let T;e[0]!==b||e[1]!==h?(T=X=>{b&&h(b,X)},e[0]=b,e[1]=h,e[2]=T):T=e[2];const w=T,E=A&&!k;let N;e[3]!==f?(N={containerRef:y,onShowPopup:f,enableFullscreen:Je,enablePanZoom:J.showPanZoomControls},e[3]=f,e[4]=N):N=e[4],ot(N);const I=S&&!A;let P;e[5]!==p||e[6]!==b||e[7]!==C.isVSCode||e[8]!==I?(P={containerRef:y,effectiveDirectory:b,editor:p,preferRuntimeEditor:C.isVSCode,enabled:I},e[5]=p,e[6]=b,e[7]=C.isVSCode,e[8]=I,e[9]=P):P=e[9],nt(P);let O;e[10]===Symbol.for("react.memo_cache_sentinel")?(O={containerRef:y},e[10]=O):O=e[10],Ye(O);let D;e[11]!==M?(D=qe(M),e[11]=M,e[12]=D):D=e[12];const R=D,F=it(M,E,b?w:void 0,J),L=`markdown-${n?.id?`part-${n.id}`:`message-${i}`}`,$=v==="assistant"?"label":"inline";let j;e[13]!==L||e[14]!==r||e[15]!==F||e[16]!==E||e[17]!==R||e[18]!==$?(j={containerRef:y,text:r,streaming:E,cacheKey:L,imageMode:$,syntaxVars:R,ctx:F},e[13]=L,e[14]=r,e[15]=F,e[16]=E,e[17]=R,e[18]=$,e[19]=j):j=e[19],at(j);let q;e[20]!==a?(q=Be("break-words w-full min-w-0",a),e[20]=a,e[21]=q):q=e[21];let U;e[22]!==v?(U=st(v),e[22]=v,e[23]=U):U=e[23];let Z;e[24]!==U?(Z=ee.jsx("div",{className:U,"data-markdown-content":!0}),e[24]=U,e[25]=Z):Z=e[25];let oe;e[26]!==q||e[27]!==Z?(oe=ee.jsx("div",{className:q,ref:y,children:Z}),e[26]=q,e[27]=Z,e[28]=oe):oe=e[28];const ie=oe;if(m){let X;return e[29]!==L||e[30]!==ie||e[31]!==g?(X=ee.jsx(yt,{skipAnimation:g,children:ie},L),e[29]=L,e[30]=ie,e[31]=g,e[32]=X):X=e[32],X}return ie},Wo=_.memo(Tr,(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),Pr=t=>{const e=K.c(30),{content:r,className:n,variant:i,disableLinkSafety:o,stripFrontmatter:s,onShowPopup:a,mermaidControls:l,allowMermaidWheelEvents:c,enableFileReferences:d}=t,f=i===void 0?"assistant":i,u=s===void 0?!1:s,m=l===void 0?J:l,g=c===void 0?!1:c,A=d===void 0?!0:d,{editor:k,runtime:v}=We(),S=Ge(),M=_.useRef(null),p=$e()??"";let C;e[0]!==r||e[1]!==u?(C=u?ur(r):r,e[0]=r,e[1]=u,e[2]=C):C=e[2];const y=C;let b;e[3]!==g||e[4]!==m.showPanZoomControls||e[5]!==a?(b={containerRef:M,onShowPopup:a,enableFullscreen:Je,enablePanZoom:m.showPanZoomControls,allowMermaidWheelEvents:g},e[3]=g,e[4]=m.showPanZoomControls,e[5]=a,e[6]=b):b=e[6],ot(b);let h;e[7]!==k||e[8]!==p||e[9]!==A||e[10]!==v.isVSCode?(h={containerRef:M,effectiveDirectory:p,editor:k,preferRuntimeEditor:v.isVSCode,enabled:A},e[7]=k,e[8]=p,e[9]=A,e[10]=v.isVSCode,e[11]=h):h=e[11],nt(h);const T=!o;let w;e[12]!==T?(w={containerRef:M,enabled:T},e[12]=T,e[13]=w):w=e[13],Ye(w);let E;e[14]!==S?(E=qe(S),e[14]=S,e[15]=E):E=e[15];const N=E,I=it(S,!1,void 0,m),P=`simple:${f}`;let O;e[16]!==I||e[17]!==y||e[18]!==N||e[19]!==P?(O={containerRef:M,text:y,streaming:!1,cacheKey:P,syntaxVars:N,ctx:I},e[16]=I,e[17]=y,e[18]=N,e[19]=P,e[20]=O):O=e[20],at(O);let D;e[21]!==n?(D=Be("break-words w-full min-w-0",n),e[21]=n,e[22]=D):D=e[22];let R;e[23]!==f?(R=st(f),e[23]=f,e[24]=R):R=e[24];let F;e[25]!==R?(F=ee.jsx("div",{className:R,"data-markdown-content":!0}),e[25]=R,e[26]=F):F=e[26];let L;return e[27]!==D||e[28]!==F?(L=ee.jsx("div",{className:D,ref:M,children:F}),e[27]=D,e[28]=F,e[29]=L):L=e[29],L},$o=_.memo(Pr,(t,e)=>{const r=t.mermaidControls??J,n=e.mermaidControls??J;return t.content===e.content&&t.variant===e.variant&&t.className===e.className&&t.disableLinkSafety===e.disableLinkSafety&&t.stripFrontmatter===e.stripFrontmatter&&t.onShowPopup===e.onShowPopup&&r.download===n.download&&r.copy===n.copy&&r.showPanZoomControls===n.showPanZoomControls&&t.allowMermaidWheelEvents===e.allowMermaidWheelEvents&&t.enableFileReferences===e.enableFileReferences});function Fr(t){if(t.defaultPrevented||t.button!==0||t.metaKey||t.ctrlKey||t.altKey||t.shiftKey)return;const e=t.target;if(!(e instanceof Element))return;const r=e.closest("a[href]");if(!(r instanceof HTMLAnchorElement)||r.getAttribute("data-openchamber-file-link")==="true")return;const n=r.getAttribute("href")??"";De(n)&&(t.preventDefault(),t.stopPropagation(),vt(n))}function Ir(t){t.removeAttribute("data-openchamber-file-link"),t.removeAttribute("data-openchamber-file-ref"),t.removeAttribute("data-openchamber-file-path"),t.getAttribute("title")==="Open file"&&t.removeAttribute("title"),t.tagName.toLowerCase()!=="a"&&(t.removeAttribute("role"),t.removeAttribute("tabindex"))}function Or(){Pt()}function Dr(t,e){return!t.isEqualNode(e)}function Wr(t){return t.openContextPreview}export{Wo as MarkdownRenderer,$o as SimpleMarkdownRenderer};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{r as _,j as e,R as i,f as J}from"./vendor-react-BUCujlKS.js";import{I as V,b$ as we,b_ as le,bY as Y,x as $,af as P,cT as je,r as W,N as ue,ap as me,K as pe,J as ne}from"./index-DRpChWux.js";import{f as Q,B as L,S as G,g as he,h as re,I as A}from"./useAppFontEffects-BikB6enL.js";import"./vendor-scheduler-7OC5HNn7.js";import"./vendor-vite-runtime-DD1OZmLC.js";import"./vendor-opencode-sdk-BJ73u-bH.js";import"./vendor-zustand-BAGL70zf.js";import"./vendor-simplewebauthn-browser-VDA66rT_.js";import"./vendor-base-ui-D_V6hAcE.js";import"./vendor-floating-ui-utils-BzXdqYpP.js";import"./vendor-floating-ui-dom-WyXykhNi.js";import"./vendor-floating-ui-core-CXmKXOXc.js";import"./vendor-floating-ui-react-dom-DKpLs02S.js";import"./vendor-use-sync-external-store-D6wYuSt-.js";import"./contextPanelEmbeddedChat-B-bSg3P5.js";import"./vendor-class-variance-authority-5VPnzWs2.js";import"./vendor-clsx-B-dksMZM.js";import"./vendor-dnd-kit-core-BZknOX2w.js";import"./vendor-dnd-kit-utilities-B_MdXhJC.js";import"./vendor-dnd-kit-accessibility-BHxJPORy.js";import"./vendor-dnd-kit-sortable-CsEagZ81.js";import"./vendor-cmdk-DgLInKvT.js";import"./vendor-radix-ui-react-dialog-B94Bt2qq.js";import"./vendor-radix-ui-primitive-Dc_FVRD7.js";import"./vendor-radix-ui-react-compose-refs-DcAh5WdT.js";import"./vendor-radix-ui-react-context-Czxm7Z62.js";import"./vendor-radix-ui-react-id-f5BLKEVw.js";import"./vendor-radix-ui-react-use-layout-effect-D_3IhJdJ.js";import"./vendor-radix-ui-react-use-controllable-state-BFT5YmkA.js";import"./vendor-radix-ui-react-dismissable-layer-D7kXcwgJ.js";import"./vendor-radix-ui-react-primitive-DhVoX9SD.js";import"./vendor-radix-ui-react-slot-BQgQOasS.js";import"./vendor-radix-ui-react-use-callback-ref-BZPnuXAC.js";import"./vendor-radix-ui-react-use-escape-keydown-oph88g-F.js";import"./vendor-radix-ui-react-focus-scope-CiaxW4dD.js";import"./vendor-radix-ui-react-portal-BMJYHWck.js";import"./vendor-radix-ui-react-presence-CNxf-uq4.js";import"./vendor-radix-ui-react-focus-guards-B6qJXYua.js";import"./vendor-react-remove-scroll-DO7dCTnK.js";import"./vendor-tslib-De9GV7Vy.js";import"./vendor-react-remove-scroll-bar-BcFYyj3E.js";import"./vendor-react-style-singleton-q6EMHnwf.js";import"./vendor-get-nonce-C-Z93AgS.js";import"./vendor-use-sidecar-zDC0RhA3.js";import"./vendor-use-callback-ref-D3RC8gqK.js";import"./vendor-aria-hidden-DvXkyWUv.js";import"./vendor-codemirror-language-DUOssd4j.js";import"./vendor-lezer-common-B3-cUCR_.js";import"./vendor-codemirror-state-CNWM3Q8V.js";import"./vendor-marijn-find-cluster-break-DXwl3gUT.js";import"./vendor-codemirror-view-DSzLbZiS.js";import"./vendor-style-mod-NZ5MEPvj.js";import"./vendor-w3c-keyname-Vcq4gwWv.js";import"./vendor-crelt-C8TCjufn.js";import"./vendor-lezer-highlight-CDMHUZ74.js";import"./vendor-codemirror-lang-javascript-Bbw3D7r0.js";import"./vendor-lezer-javascript-D7Tj24ot.js";import"./vendor-lezer-lr-bhwg1HMg.js";import"./vendor-codemirror-autocomplete-BjbBRsUA.js";import"./vendor-codemirror-lang-json-ryCw7nab.js";import"./vendor-lezer-json-Iaex0UN-.js";import"./vendor-codemirror-lang-css-VgNqFSH-.js";import"./vendor-lezer-css-C5xB6jxd.js";import"./vendor-codemirror-lang-html-B3Qe3OpS.js";import"./vendor-lezer-html-C0I1p52t.js";import"./vendor-codemirror-lang-markdown-FGQydhTc.js";import"./vendor-lezer-markdown-C6g-d6P3.js";import"./vendor-codemirror-language-data-CLHw8NWn.js";import"./vendor-codemirror-lang-python-N414WYK-.js";import"./vendor-lezer-python-CvuFxeZl.js";import"./vendor-codemirror-commands-ARAOgp1x.js";import"./vendor-tanstack-react-virtual-g05Cx3z9.js";import"./vendor-tanstack-virtual-core-Dubg10g5.js";import"./vendor-framer-motion-CRSgBxjL.js";import"./vendor-motion-dom-DJLgZh4Q.js";import"./vendor-motion-utils-BGh8QBgx.js";import"./vendor-sonner-DFyL3AvE.js";import"./vendor-tailwind-merge-CPcsbTWB.js";import"./vendor-fuse.js-Dw8P0qyA.js";function ke(a){switch(a){case"ok":return null;case"auth":return"onboarding.remoteConnection.probe.authMessage";case"update-recommended":return"onboarding.remoteConnection.probe.updateRecommendedMessage";case"incompatible":return"onboarding.remoteConnection.probe.incompatibleMessage";case"wrong-service":return"onboarding.remoteConnection.probe.wrongServiceMessage";case"unreachable":return"onboarding.remoteConnection.probe.unreachableMessage";default:return null}}function oe(a){return a==="wrong-service"||a==="unreachable"||a==="incompatible"}function xe({onBack:a,showBackButton:t=!0,initialUrl:s="",initialLabel:r="",isRecoveryMode:n=!1,onConnect:l,onSwitchToLocal:u,showInstancePicker:h=!1}){const{t:o}=Q(),[w,S]=_.useState(s),[j,U]=_.useState(r),[K,x]=_.useState("idle"),[m,k]=_.useState(null),[C,g]=_.useState(""),[T,I]=_.useState([]),[y,f]=_.useState(()=>h?"instances":"add"),[b,R]=_.useState("");_.useEffect(()=>{h&&V().then(p=>I(p.hosts)).catch(p=>{g(p instanceof Error?p.message:String(p))})},[h]);const N=we(w),E=N?.persistedUrl??null,F=_.useCallback(p=>{S(p.target.value),x("idle"),k(null),g("")},[]),O=_.useCallback(p=>{U(p.target.value)},[]),c=_.useCallback(async()=>{if(E){x("testing"),k(null),g("");try{const p=await le(E);k(p),x(p.status==="ok"||p.status==="update-recommended"?"success":"error")}catch(p){g(p instanceof Error?p.message:o("onboarding.remoteConnection.errors.connectionTestFailed")),x("error")}}},[E,o]),D=_.useCallback(async()=>{if(!N)return;const p=N.persistedUrl;x("testing"),k(null),g("");try{const H=await le(p);if(k(H),oe(H.status)){x("error");return}const Z=await V(),ye=j.trim()||p,ee=Z.hosts.find(X=>X.url===p),te=ee?ee.id:`host-${Date.now().toString(16)}`,ie={id:te,label:ye,url:p,apiUrl:p},ve=ee?Z.hosts.map(X=>X.id===te?ie:X):[...Z.hosts,ie];if(await Y({hosts:ve,defaultHostId:te,initialHostChoiceCompleted:!0}),l?.(),N.redeemUrl){window.location.assign(N.redeemUrl);return}$()&&await P()}catch(H){g(H instanceof Error?H.message:o("onboarding.remoteConnection.errors.failedToSaveConnection")),x("error")}},[N,j,l,o]),B=_.useCallback(async p=>{const H=await V();await Y({hosts:H.hosts,defaultHostId:p,initialHostChoiceCompleted:!0}),await P()},[]),d=_.useCallback(async()=>{x("testing"),g("");try{const p=await V(),H=await je(b,p.hosts);await Y({hosts:H.hosts,defaultHostId:H.hostId,initialHostChoiceCompleted:!0}),await P()}catch(p){g(p instanceof Error&&p.message==="invalid-connect-link"?o("settings.remoteInstances.direct.error.invalidConnectLink"):o("onboarding.remoteConnection.errors.failedToSaveConnection")),x("error")}},[b,o]),v=K==="testing",M=E!==null&&!v,z=E!==null&&!v&&!oe(m?.status??null),q=ke(m?.status??null),fe=m?.status==="ok",be=m?.status==="update-recommended",ge=m?.status==="auth",ae=oe(m?.status??null);return h&&y==="instances"?e.jsx("div",{className:"flex flex-col items-center justify-center h-full p-8",children:e.jsxs("div",{className:"w-full max-w-md space-y-6",children:[e.jsxs("div",{className:"space-y-2 text-center",children:[e.jsx("h1",{className:"typography-ui-header text-xl font-semibold text-foreground",children:o("desktopHostSwitcher.actions.switchInstance")}),e.jsx("p",{className:"text-muted-foreground text-sm",children:o("settings.remoteInstances.direct.description")})]}),C?e.jsx("div",{className:"text-sm text-[var(--status-error)]",children:C}):null,e.jsx("div",{className:"space-y-2",children:T.length===0?e.jsx("div",{className:"py-4 text-center text-sm text-muted-foreground",children:o("settings.remoteInstances.direct.state.empty")}):T.map(p=>e.jsx(L,{variant:"outline",className:"w-full justify-start",onClick:()=>{B(p.id)},children:e.jsx("span",{className:"min-w-0 truncate",children:p.label})},p.id))}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(L,{variant:"outline",className:"flex-1",onClick:()=>f("import"),children:o("settings.remoteInstances.direct.import.action")}),e.jsx(L,{className:"flex-1",onClick:()=>f("add"),children:o("settings.remoteInstances.direct.actions.add")})]})]})}):h&&y==="import"?e.jsx("div",{className:"flex flex-col items-center justify-center h-full p-8",children:e.jsxs("div",{className:"w-full max-w-md space-y-6",children:[e.jsx(L,{variant:"ghost",onClick:()=>f("instances"),className:"p-0 text-muted-foreground",children:o("onboarding.common.actions.back")}),e.jsxs("div",{className:"space-y-2 text-center",children:[e.jsx("h1",{className:"typography-ui-header text-xl font-semibold text-foreground",children:o("settings.remoteInstances.direct.import.action")}),e.jsx("p",{className:"text-muted-foreground text-sm",children:o("settings.remoteInstances.direct.import.description")})]}),e.jsx(G,{value:b,onChange:p=>R(p.target.value),placeholder:o("settings.remoteInstances.direct.import.placeholder"),disabled:v,autoFocus:!0}),C?e.jsx("div",{className:"text-sm text-[var(--status-error)]",children:C}):null,e.jsx(L,{onClick:()=>{d()},disabled:v||!b.trim(),children:o("settings.remoteInstances.direct.import.action")})]})}):e.jsx("div",{className:"flex flex-col items-center justify-center h-full p-8",children:e.jsxs("div",{className:"w-full max-w-md space-y-6",children:[(t||h)&&e.jsx("div",{className:"flex items-center",children:e.jsx(L,{variant:"ghost",onClick:h?()=>f("instances"):a,className:"p-0 text-muted-foreground hover:text-foreground",children:o("onboarding.common.actions.back")})}),e.jsxs("div",{className:"space-y-2 text-center",children:[e.jsx("h1",{className:"typography-ui-header text-xl font-semibold text-foreground",children:o(n?"onboarding.remoteConnection.titleRecovery":"onboarding.remoteConnection.title")}),e.jsx("p",{className:"text-muted-foreground text-sm",children:o("onboarding.remoteConnection.description")})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{htmlFor:"remote-url",className:"text-sm text-foreground",children:o("onboarding.remoteConnection.field.serverAddress")}),e.jsx(G,{id:"remote-url",type:"url",value:w,onChange:F,placeholder:o("onboarding.remoteConnection.field.serverAddressPlaceholder"),disabled:v})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{htmlFor:"remote-label",className:"text-sm text-foreground",children:o("onboarding.remoteConnection.field.nameOptional")}),e.jsx(G,{id:"remote-label",type:"text",value:j,onChange:O,placeholder:o("onboarding.remoteConnection.field.namePlaceholder"),disabled:v})]})]}),m&&fe&&e.jsx("div",{className:"rounded-lg border p-3 text-sm",style:{borderColor:"var(--status-success)",color:"var(--status-success)"},children:o("onboarding.remoteConnection.status.connectedSuccessfully",{latencyMs:m.latencyMs})}),m&&ge&&e.jsx("div",{className:"rounded-lg border p-3 text-sm",style:{borderColor:"var(--status-warning)",color:"var(--status-warning)"},children:o("onboarding.remoteConnection.status.authWarning")}),m&&be&&e.jsx("div",{className:"rounded-lg border p-3 text-sm",style:{borderColor:"var(--status-warning)",color:"var(--status-warning)"},children:q?o(q):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:q?o(q):null})]}),e.jsx("div",{className:"text-xs opacity-80",children:m.status==="unreachable"?o("onboarding.remoteConnection.status.suggestionsUnreachable"):o("onboarding.remoteConnection.status.suggestionsWrongService")})]}),C&&e.jsx("div",{className:"rounded-lg border p-3 text-sm",style:{borderColor:"var(--status-error)",color:"var(--status-error)"},children:C}),e.jsxs("div",{className:"flex gap-3",children:[e.jsx(L,{variant:"outline",onClick:c,disabled:!M,children:o(v?"onboarding.remoteConnection.actions.testing":"onboarding.remoteConnection.actions.testConnection")}),e.jsx(L,{onClick:D,disabled:!z,children:o("onboarding.remoteConnection.actions.connectAndRestart")})]}),ae&&e.jsxs("div",{className:"flex flex-col gap-2 pt-2 border-t border-border",children:[e.jsx("div",{className:"text-xs text-muted-foreground text-center",children:o("onboarding.remoteConnection.actions.whatToDo")}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(L,{variant:"outline",size:"sm",onClick:a,className:"flex-1",children:o("onboarding.remoteConnection.actions.chooseDifferentServer")}),!n&&u&&e.jsx(L,{variant:"outline",size:"sm",onClick:u,className:"flex-1",children:o("onboarding.remoteConnection.actions.useLocalInstead")})]})]})]})})}const Ce="curl -fsSL https://opencode.ai/install | bash",Ne="https://opencode.ai/docs",ce=2500;function Se(a){const t=J.c(5),{onCopy:s,copyTitle:r}=a;let n;t[0]===Symbol.for("react.memo_cache_sentinel")?(n=e.jsxs("code",{className:"flex-1 text-left overflow-x-auto whitespace-nowrap",children:[e.jsx("span",{style:{color:"var(--syntax-keyword)"},children:"curl"}),e.jsx("span",{className:"text-muted-foreground",children:" -fsSL "}),e.jsx("span",{style:{color:"var(--syntax-string)"},children:"https://opencode.ai/install"}),e.jsx("span",{className:"text-muted-foreground",children:" | "}),e.jsx("span",{style:{color:"var(--syntax-keyword)"},children:"bash"})]}),t[0]=n):n=t[0];let l;t[1]===Symbol.for("react.memo_cache_sentinel")?(l=e.jsx(A,{name:"file-copy",className:"h-4 w-4"}),t[1]=l):l=t[1];let u;return t[2]!==r||t[3]!==s?(u=e.jsxs("div",{className:"flex items-center justify-between gap-3 w-full",children:[n,e.jsx("button",{onClick:s,className:"inline-flex items-center text-muted-foreground hover:text-foreground transition-colors shrink-0",title:r,"aria-label":r,children:l})]}),t[2]=r,t[3]=s,t[4]=u):u=t[4],u}function Re({onCliAvailable:a,localAvailable:t=!0}){const{t:s}=Q(),[r,n]=i.useState(!1),[l,u]=i.useState(!1),[h,o]=i.useState(!1),[w,S]=i.useState(!1),[j,U]=i.useState(""),[K,x]=i.useState("unknown"),[m,k]=i.useState(()=>t?"local":"remote"),[C,g]=i.useState(!1),[T,I]=i.useState(!1);i.useEffect(()=>{u($())},[]),i.useEffect(()=>{if(typeof navigator>"u"){x("unknown");return}const d=navigator.userAgent||"";/Windows/i.test(d)?x("windows"):/Macintosh|Mac OS X/i.test(d)?x("macos"):/Linux/i.test(d)?x("linux"):x("unknown")},[]),i.useEffect(()=>{let d=!1;return(async()=>{try{const v=await W("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});if(!v.ok)return;const M=await v.json().catch(()=>null);if(!M||d)return;const z=typeof M.opencodeBinary=="string"?M.opencodeBinary.trim():"";z&&U(z)}catch{}})(),()=>{d=!0}},[]);const y=i.useCallback(async d=>{const v=d.target;v.closest(".app-region-no-drag")||v.closest("button, a, input, select, textarea, code, summary, details")||d.button===0&&l&&await ue()},[l]),f=i.useCallback(async()=>{try{const d=await W("/health");if(!d.ok)return!1;const v=await d.json();return v.openCodeRunning===!0||v.isOpenCodeReady===!0}catch{return!1}},[]),b=i.useCallback(async d=>{if(!l)return;const v=await V();await Y({...v,...d==="local"?{defaultHostId:"local"}:{},initialHostChoiceCompleted:!0})},[l]),R=i.useCallback(async()=>{l&&await b("local"),a?.()},[l,a,b]);i.useEffect(()=>{if(!t||m!=="local")return;let d=!1,v=null;const M=async()=>{if(!d){try{const z=await f();if(d)return;if(z){await R();return}}catch{}d||(v=setTimeout(M,ce))}};return v=setTimeout(M,ce),()=>{d=!0,v&&clearTimeout(v)}},[m,f,R,t]);const N=i.useCallback(async()=>{S(!0);try{await f()&&await R()}finally{S(!1)}},[f,R]),E=i.useCallback(async()=>{if(!(typeof window>"u")&&l)try{const d=await me();d.success&&d.path&&d.path.trim().length>0&&U(d.path.trim())}catch{}},[l]),F=i.useCallback(async()=>{o(!0);try{if(await pe({opencodeBinary:j.trim()}),l){await b("local"),await P();return}await W("/api/config/reload",{method:"POST"})}finally{setTimeout(()=>o(!1),1e3)}},[l,j,b]),O=i.useCallback(async()=>{const d=await he(Ce);d.ok?(n(!0),setTimeout(()=>n(!1),2e3)):console.error("Failed to copy:",d.error)},[]),c=Ne,D=K==="windows"?"C:\\Users\\you\\AppData\\Roaming\\npm\\opencode.cmd":K==="linux"?"/home/you/.bun/bin/opencode":"/Users/you/.bun/bin/opencode",B=t&&(!l||m==="local");return e.jsx("div",{className:"app-region-drag h-full flex items-center justify-center bg-transparent p-8 cursor-default select-none overflow-y-auto",onMouseDown:y,children:e.jsxs("div",{className:"w-full max-w-md space-y-7",children:[e.jsxs("header",{className:"text-center space-y-1.5",children:[e.jsx("h1",{className:"text-2xl font-semibold tracking-tight text-foreground",children:s("onboarding.chooser.title")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:s("onboarding.chooser.description")})]}),l&&t&&e.jsxs("div",{className:"app-region-no-drag flex gap-1.5",children:[e.jsx("button",{type:"button",className:re("flex-1 px-4 py-2 rounded-lg border transition-colors text-sm",m==="local"?"border-[var(--interactive-selection)] text-foreground bg-[var(--interactive-selection)]/10":"border-border text-muted-foreground hover:text-foreground hover:border-muted-foreground"),onClick:()=>k("local"),children:s("onboarding.chooser.tabs.localInstall")}),e.jsx("button",{type:"button",className:re("flex-1 px-4 py-2 rounded-lg border transition-colors text-sm",m==="remote"?"border-[var(--interactive-selection)] text-foreground bg-[var(--interactive-selection)]/10":"border-border text-muted-foreground hover:text-foreground hover:border-muted-foreground"),onClick:()=>k("remote"),children:s("onboarding.chooser.tabs.connectRemote")})]}),l&&m==="remote"?e.jsx("div",{className:"app-region-no-drag",children:e.jsx(xe,{onBack:()=>t&&k("local"),showBackButton:!1,showInstancePicker:!t,onSwitchToLocal:t?()=>k("local"):void 0})}):null,B&&e.jsxs("div",{className:"space-y-4",children:[K==="windows"&&e.jsxs("div",{className:"rounded-lg border border-border bg-background/50 p-4",children:[e.jsx("div",{className:"text-sm text-foreground",children:s("onboarding.localSetup.windows.title")}),e.jsxs("ol",{className:"mt-2 list-decimal space-y-1 pl-5 text-sm text-muted-foreground",children:[e.jsx("li",{children:s("onboarding.localSetup.windows.stepRunInstallInWsl")}),e.jsx("li",{children:s("onboarding.localSetup.windows.stepSetBinaryPath")})]})]}),e.jsx("p",{className:"text-sm text-muted-foreground text-center leading-relaxed",children:s("onboarding.localSetup.intro")}),e.jsx("div",{className:"app-region-no-drag rounded-lg border border-border bg-background/60 backdrop-blur-sm px-4 py-3 font-mono text-sm",children:r?e.jsxs("div",{className:"flex items-center gap-2",style:{color:"var(--status-success)"},children:[e.jsx(A,{name:"check",className:"h-4 w-4"}),s("onboarding.common.status.copiedToClipboard")]}):e.jsx(Se,{onCopy:O,copyTitle:s("onboarding.common.copyToClipboard")})}),e.jsxs("div",{className:"app-region-no-drag flex items-center justify-between",children:[e.jsxs("a",{href:c,target:"_blank",rel:"noopener noreferrer",className:"text-xs text-muted-foreground hover:text-foreground transition-colors inline-flex items-center gap-1",children:[s(K==="windows"?"onboarding.localSetup.docs.windows":"onboarding.localSetup.docs.default"),e.jsx(A,{name:"external-link",className:"h-3 w-3"})]}),e.jsx("button",{type:"button",onClick:N,disabled:w,className:"text-xs text-muted-foreground hover:text-foreground transition-colors disabled:opacity-50",children:s(w?"onboarding.localSetup.actions.checking":"onboarding.localSetup.actions.checkNow")})]}),e.jsxs("div",{className:"rounded-lg border px-4 py-3 flex items-center gap-3",style:{borderColor:"color-mix(in srgb, var(--primary-base) 20%, transparent)",backgroundColor:"color-mix(in srgb, var(--primary-base) 6%, transparent)"},role:"status","aria-live":"polite",children:[e.jsxs("span",{className:"relative inline-flex h-2.5 w-2.5 shrink-0","aria-hidden":!0,children:[e.jsx("span",{className:"absolute inset-0 rounded-full",style:{backgroundColor:"var(--primary-base)",animation:"pulse-opacity 1.6s ease-in-out infinite"}}),e.jsx("span",{className:"absolute inset-[-4px] rounded-full",style:{backgroundColor:"var(--primary-base)",animation:"pulse-opacity-dim 1.6s ease-in-out infinite",opacity:0}})]}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"text-sm text-foreground leading-tight",children:s("onboarding.localSetup.status.watching")}),e.jsx("div",{className:"text-xs text-muted-foreground leading-tight mt-0.5",children:s("onboarding.localSetup.status.autoContinue")})]})]}),e.jsxs("details",{className:"app-region-no-drag group rounded-lg border border-border/60 px-4 open:bg-background/40 transition-colors",open:C,onToggle:d=>g(d.currentTarget.open),children:[e.jsxs("summary",{className:"flex items-center justify-between cursor-pointer py-2.5 text-sm text-muted-foreground hover:text-foreground transition-colors list-none [&::-webkit-details-marker]:hidden",children:[e.jsx("span",{children:s("onboarding.localSetup.advanced.title")}),e.jsx(A,{name:"arrow-down-s",className:"h-4 w-4 transition-transform group-open:rotate-180"})]}),e.jsxs("div",{className:"pb-4 space-y-2",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsx(G,{value:j,onChange:d=>U(d.target.value),placeholder:D,disabled:h,className:"flex-1 font-mono text-xs"}),e.jsx(L,{type:"button",variant:"secondary",size:"sm",onClick:E,disabled:h||!l,children:s("onboarding.localSetup.actions.browse")}),e.jsx(L,{type:"button",size:"sm",onClick:F,disabled:h||!j.trim(),children:s("onboarding.localSetup.actions.apply")})]}),e.jsx("p",{className:"text-xs text-muted-foreground/70",children:s("onboarding.localSetup.helper.saveAndReload")})]})]}),e.jsxs("details",{className:"app-region-no-drag group rounded-lg border border-border/60 px-4 open:bg-background/40 transition-colors",open:T,onToggle:d=>I(d.currentTarget.open),children:[e.jsxs("summary",{className:"flex items-center justify-between cursor-pointer py-2.5 text-sm text-muted-foreground hover:text-foreground transition-colors list-none [&::-webkit-details-marker]:hidden",children:[e.jsx("span",{children:s("onboarding.localSetup.troubleshoot.title")}),e.jsx(A,{name:"arrow-down-s",className:"h-4 w-4 transition-transform group-open:rotate-180"})]}),e.jsx("ul",{className:"pb-4 space-y-1.5 text-xs text-muted-foreground list-disc pl-4",children:K==="windows"?e.jsx(e.Fragment,{children:e.jsx("li",{children:s("onboarding.localSetup.windows.hintDetectionFailed")})}):e.jsxs(e.Fragment,{children:[e.jsx("li",{children:s("onboarding.localSetup.hint.ensurePath")}),e.jsx("li",{children:s("onboarding.localSetup.hint.setEnv")}),e.jsx("li",{children:s("onboarding.localSetup.hint.missingRuntime")})]})})]})]})]})})}const Le="curl -fsSL https://opencode.ai/install | bash",Ue="https://opencode.ai/docs";function Te(a){const t=J.c(5),{onCopy:s,copyTitle:r}=a;let n;t[0]===Symbol.for("react.memo_cache_sentinel")?(n=e.jsxs("code",{children:[e.jsx("span",{style:{color:"var(--syntax-keyword)"},children:"curl"}),e.jsx("span",{className:"text-muted-foreground",children:" -fsSL "}),e.jsx("span",{style:{color:"var(--syntax-string)"},children:"https://opencode.ai/install"}),e.jsx("span",{className:"text-muted-foreground",children:" | "}),e.jsx("span",{style:{color:"var(--syntax-keyword)"},children:"bash"})]}),t[0]=n):n=t[0];let l;t[1]===Symbol.for("react.memo_cache_sentinel")?(l=e.jsx(A,{name:"file-copy",className:"h-4 w-4"}),t[1]=l):l=t[1];let u;return t[2]!==r||t[3]!==s?(u=e.jsxs("div",{className:"flex items-center justify-center gap-3",children:[n,e.jsx("button",{onClick:s,className:"inline-flex items-center text-muted-foreground hover:text-foreground transition-colors",title:r,children:l})]}),t[2]=r,t[3]=s,t[4]=u):u=t[4],u}const Ke=3e4;function Ie({onBack:a,onCliAvailable:t,isFromRecovery:s=!1,onSwitchToRemote:r}){const{t:n}=Q(),[l,u]=i.useState(!1),[h,o]=i.useState(!1),[w,S]=i.useState(!1),[j,U]=i.useState(!1),[K,x]=i.useState(!1),[m,k]=i.useState(null),[C,g]=i.useState(""),[T,I]=i.useState("unknown");i.useEffect(()=>{const c=setTimeout(()=>o(!0),Ke);return()=>clearTimeout(c)},[]),i.useEffect(()=>{S($())},[]),i.useEffect(()=>{if(typeof navigator>"u"){I("unknown");return}const c=navigator.userAgent||"";if(/Windows/i.test(c)){I("windows");return}if(/Macintosh|Mac OS X/i.test(c)){I("macos");return}if(/Linux/i.test(c)){I("linux");return}I("unknown")},[]),i.useEffect(()=>{let c=!1;return(async()=>{try{const D=await W("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});if(!D.ok)return;const B=await D.json().catch(()=>null);if(!B||c)return;const d=typeof B.opencodeBinary=="string"?B.opencodeBinary.trim():"";d&&g(d)}catch{}})(),()=>{c=!0}},[]);const y=i.useCallback(async c=>{c.target.closest("button, a, input, select, textarea, code")||c.button===0&&w&&await ue()},[w]),f=i.useCallback(async()=>{try{const c=await W("/health");if(!c.ok)return!1;const D=await c.json();return D.openCodeRunning===!0||D.isOpenCodeReady===!0}catch{return!1}},[]),b=i.useCallback(async()=>{if(!(typeof window>"u")&&w)try{const c=await me();c.success&&c.path&&c.path.trim().length>0&&g(c.path.trim())}catch{}},[w]),R=i.useCallback(async()=>{U(!0);try{if(await pe({opencodeBinary:C.trim()}),w){await P();return}await W("/api/config/reload",{method:"POST"})}finally{setTimeout(()=>U(!1),1e3)}},[w,C]),N=i.useCallback(async()=>{const c=await he(Le);c.ok?(u(!0),setTimeout(()=>u(!1),2e3)):console.error("Failed to copy:",c.error)},[]),E=i.useCallback(async()=>{x(!0),k(null);try{await f()?t?.():k(n("onboarding.localSetup.errors.cliNotReady"))}catch(c){k(c instanceof Error?c.message:n("onboarding.localSetup.errors.detectionFailed"))}finally{x(!1)}},[f,t,n]),F=Ue,O=T==="windows"?"C:\\Users\\you\\AppData\\Roaming\\npm\\opencode.cmd":T==="linux"?"/home/you/.bun/bin/opencode":"/Users/you/.bun/bin/opencode";return e.jsxs("div",{className:"h-full flex items-center justify-center bg-transparent p-8 relative cursor-default select-none",onMouseDown:y,children:[e.jsxs("div",{className:"w-full max-w-lg space-y-4 text-center",children:[e.jsx("div",{className:"flex items-center",children:e.jsx(L,{variant:"ghost",onClick:a,className:"p-0 text-muted-foreground hover:text-foreground",children:n("onboarding.common.actions.back")})}),e.jsxs("div",{className:"space-y-4",children:[e.jsx("h1",{className:"text-3xl font-semibold tracking-tight text-foreground",children:n("onboarding.localSetup.title")}),e.jsx("p",{className:"text-muted-foreground",children:n("onboarding.localSetup.description")})]}),T==="windows"&&e.jsxs("div",{className:"mx-auto max-w-2xl rounded-lg border border-border bg-background/50 p-4 text-left",children:[e.jsx("div",{className:"text-sm text-foreground",children:n("onboarding.localSetup.windows.title")}),e.jsxs("ol",{className:"mt-2 list-decimal space-y-1 pl-5 text-sm text-muted-foreground",children:[e.jsx("li",{children:n("onboarding.localSetup.windows.stepRunInstallInWsl")}),e.jsx("li",{children:n("onboarding.localSetup.windows.stepSetBinaryPath")})]})]}),e.jsx("div",{className:"flex justify-center",children:e.jsx("div",{className:"bg-background/60 backdrop-blur-sm border border-border rounded-lg px-5 py-3 font-mono text-sm w-fit",children:l?e.jsxs("div",{className:"flex items-center justify-center gap-2",style:{color:"var(--status-success)"},children:[e.jsx(A,{name:"check",className:"h-4 w-4"}),n("onboarding.common.status.copiedToClipboard")]}):e.jsx(Te,{onCopy:N,copyTitle:n("onboarding.common.copyToClipboard")})})}),e.jsxs("a",{href:F,target:"_blank",rel:"noopener noreferrer",className:"text-sm text-muted-foreground hover:text-foreground transition-colors inline-flex items-center gap-1 justify-center",children:[n(T==="windows"?"onboarding.localSetup.docs.windows":"onboarding.localSetup.docs.default"),e.jsx(A,{name:"external-link",className:"h-3 w-3"})]}),m&&e.jsx("div",{className:"mx-auto max-w-md rounded-lg border border-destructive/50 bg-destructive/10 p-3 text-sm text-destructive",children:m}),e.jsxs("div",{className:"space-y-3",children:[e.jsx(L,{type:"button",onClick:E,disabled:K,className:"w-full max-w-xs",size:"lg",children:n(K?"onboarding.localSetup.actions.checking":"onboarding.localSetup.actions.checkAndContinue")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:n("onboarding.localSetup.helper.checkAndContinue")})]}),e.jsx("div",{className:"mx-auto w-full max-w-xl pt-4",children:e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"text-sm text-muted-foreground",children:n("onboarding.localSetup.field.alreadyInstalled")}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(G,{value:C,onChange:c=>g(c.target.value),placeholder:O,disabled:j,className:"flex-1 font-mono text-xs"}),e.jsx(L,{type:"button",variant:"secondary",onClick:b,disabled:j||!w,children:n("onboarding.localSetup.actions.browse")}),e.jsx(L,{type:"button",onClick:R,disabled:j,children:n("onboarding.localSetup.actions.apply")})]}),e.jsx("div",{className:"text-xs text-muted-foreground/70",children:n("onboarding.localSetup.helper.saveAndReload")})]})}),s&&r&&e.jsxs("div",{className:"text-center pt-4",children:[e.jsx("p",{className:"text-sm text-muted-foreground mb-2",children:n("onboarding.localSetup.remotePreference")}),e.jsx(L,{variant:"link",onClick:r,children:n("onboarding.localSetup.actions.connectRemoteServer")})]})]}),h&&e.jsx("div",{className:"absolute bottom-8 left-0 right-0 text-center space-y-1",children:T==="windows"?e.jsx(e.Fragment,{children:e.jsx("p",{className:"text-sm text-muted-foreground/70",children:n("onboarding.localSetup.windows.hintDetectionFailed")})}):e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-sm text-muted-foreground/70",children:n("onboarding.localSetup.hint.ensurePath")}),e.jsx("p",{className:"text-sm text-muted-foreground/70",children:n("onboarding.localSetup.hint.setEnv")}),e.jsx("p",{className:"text-sm text-muted-foreground/70",children:n("onboarding.localSetup.hint.missingRuntime")})]})})]})}function se(a,t){if(a?.trim())return ne(a.trim());if(t)return ne(t)}function _e(a,t,s){switch(a){case"local-unavailable":return{title:"Local OpenCode Unavailable",description:"OpenCode CLI could not be started or is not installed. Install OpenCode or connect to a remote server instead.",titleKey:"onboarding.desktopRecovery.localUnavailable.title",descriptionKey:"onboarding.desktopRecovery.localUnavailable.description",iconKey:"local",showRetry:!0,retryLabel:"Retry Local",retryLabelKey:"onboarding.desktopRecovery.localUnavailable.retry",showUseLocal:!0,showUseRemote:!0,useLocalLabel:"Set Up Local",useLocalLabelKey:"onboarding.desktopRecovery.localUnavailable.useLocal",useRemoteLabel:"Use Remote",useRemoteLabelKey:"onboarding.desktopRecovery.common.useRemote"};case"remote-missing":return{title:"No Default Connection",description:"Your saved default connection could not be found. Choose how you want to connect.",titleKey:"onboarding.desktopRecovery.noDefaultConnection.title",descriptionKey:"onboarding.desktopRecovery.noDefaultConnection.description",iconKey:"local",showRetry:!1,showUseLocal:!0,showUseRemote:!0,useLocalLabel:"Use Local",useLocalLabelKey:"onboarding.desktopRecovery.common.useLocal",useRemoteLabel:"Use Remote",useRemoteLabelKey:"onboarding.desktopRecovery.common.useRemote"};case"remote-unreachable":{const r=se(t,s);return{title:"Remote Server Unreachable",description:`Could not connect to "${r||"the remote server"}". Check your network connection and verify the server address.`,titleKey:"onboarding.desktopRecovery.remoteUnreachable.title",descriptionKey:"onboarding.desktopRecovery.remoteUnreachable.description",descriptionParams:r?{host:r}:void 0,iconKey:"remote",showRetry:!0,retryLabel:"Retry Connection",retryLabelKey:"onboarding.desktopRecovery.remoteUnreachable.retry",showUseLocal:!0,showUseRemote:!0,useLocalLabel:"Use Local",useLocalLabelKey:"onboarding.desktopRecovery.common.useLocal",useRemoteLabel:"Use Remote",useRemoteLabelKey:"onboarding.desktopRecovery.common.useRemote"}}case"remote-wrong-service":{const r=se(t,s);return{title:"Incompatible Server",description:`The server at "${r||"unknown"}" is not running OpenChamber. Verify the address points to an OpenChamber server.`,titleKey:"onboarding.desktopRecovery.incompatibleServer.title",descriptionKey:"onboarding.desktopRecovery.incompatibleServer.description",descriptionParams:r?{host:r}:void 0,iconKey:"remote",showRetry:!1,showUseLocal:!0,showUseRemote:!0,useLocalLabel:"Use Local",useLocalLabelKey:"onboarding.desktopRecovery.common.useLocal",useRemoteLabel:"Use Remote",useRemoteLabelKey:"onboarding.desktopRecovery.common.useRemote"}}case"remote-incompatible":{const r=se(t,s);return{title:"Server Update Required",description:`The OpenChamber server at "${r||"unknown"}" is not compatible with this app version. Update OpenChamber on the server, then try again.`,titleKey:"onboarding.desktopRecovery.remoteIncompatible.title",descriptionKey:"onboarding.desktopRecovery.remoteIncompatible.description",descriptionParams:r?{host:r}:void 0,iconKey:"remote",showRetry:!0,retryLabel:"Retry Connection",retryLabelKey:"onboarding.desktopRecovery.remoteUnreachable.retry",showUseLocal:!0,showUseRemote:!0,useLocalLabel:"Use Local",useLocalLabelKey:"onboarding.desktopRecovery.common.useLocal",useRemoteLabel:"Use Remote",useRemoteLabelKey:"onboarding.desktopRecovery.common.useRemote"}}case"missing-default-host":return{title:"No Default Connection",description:"Your saved default connection could not be found. Choose how you want to connect.",titleKey:"onboarding.desktopRecovery.noDefaultConnection.title",descriptionKey:"onboarding.desktopRecovery.noDefaultConnection.description",iconKey:"local",showRetry:!1,showUseLocal:!0,showUseRemote:!0,useLocalLabel:"Use Local",useLocalLabelKey:"onboarding.desktopRecovery.common.useLocal",useRemoteLabel:"Use Remote",useRemoteLabelKey:"onboarding.desktopRecovery.common.useRemote"};default:{const r=a;throw new Error(`Unknown recovery variant: ${r}`)}}}function De(a){switch(a){case"local":return e.jsx(A,{name:"macbook",className:"h-8 w-8"});case"remote":return e.jsx(A,{name:"server",className:"h-8 w-8"})}}function Ee({variant:a,hostLabel:t,hostUrl:s,onRetry:r,onUseLocal:n,onUseRemote:l,isRetrying:u=!1}){const{t:h}=Q(),o=_e(a,t,s),w=o.retryLabelKey??"onboarding.desktopRecovery.actions.retryConnection",S=i.useMemo(()=>{if(o.descriptionParams?.host)return o.descriptionParams;if(a==="remote-unreachable")return{host:h("onboarding.desktopRecovery.placeholders.remoteServer")};if(a==="remote-wrong-service"||a==="remote-incompatible")return{host:h("onboarding.desktopRecovery.placeholders.unknownServer")}},[o.descriptionParams,h,a]);return e.jsx("div",{className:"flex flex-col items-center justify-center h-full p-8",children:e.jsxs("div",{className:"w-full max-w-md space-y-6",children:[e.jsxs("div",{className:"flex flex-col items-center space-y-3 text-center",children:[e.jsx("div",{className:"p-3 rounded-full",style:{backgroundColor:"var(--status-warning)",opacity:.15},children:e.jsx("div",{style:{color:"var(--status-warning)"},children:De(o.iconKey)})}),e.jsx("h1",{className:"typography-ui-header text-xl font-semibold text-foreground",children:h(o.titleKey)}),e.jsx("p",{className:"text-muted-foreground text-sm max-w-sm",children:h(o.descriptionKey,S)})]}),s&&(a==="remote-unreachable"||a==="remote-wrong-service"||a==="remote-incompatible")&&e.jsxs("div",{className:"rounded-lg border border-border bg-background/50 p-3",children:[e.jsx("div",{className:"text-xs text-muted-foreground mb-1",children:h("onboarding.remoteConnection.field.serverAddress")}),e.jsx("div",{className:"font-mono text-sm text-foreground truncate",children:ne(s)})]}),e.jsxs("div",{className:"flex flex-col gap-2",children:[o.showRetry&&r&&e.jsxs(L,{onClick:r,disabled:u,className:"w-full",children:[e.jsx(A,{name:"refresh",className:re("h-4 w-4",u&&"animate-spin")}),h(u?"onboarding.desktopRecovery.actions.retrying":w)]}),e.jsxs("div",{className:"flex gap-2",children:[o.showUseLocal&&n&&e.jsxs(L,{variant:"outline",onClick:n,disabled:u,className:"flex-1",children:[e.jsx(A,{name:"macbook",className:"h-4 w-4"}),h(o.useLocalLabelKey)]}),o.showUseRemote&&l&&e.jsxs(L,{variant:"outline",onClick:l,disabled:u,className:"flex-1",children:[e.jsx(A,{name:"server",className:"h-4 w-4"}),h(o.useRemoteLabelKey)]})]})]})]})})}function de(a,t){if(t==="use-remote")return{kind:"remote-form"};switch(a){case"local-unavailable":return{kind:"local-setup"};case"remote-unreachable":case"remote-incompatible":case"remote-wrong-service":case"remote-missing":case"missing-default-host":return{kind:"switch-default-to-local"};default:{const s=a;throw new Error(`Unhandled RecoveryVariant: ${s}`)}}}function Ae(a){const t=J.c(29),{variant:s,hostUrl:r,hostLabel:n,onRetry:l,onChooseRemote:u,showRemoteForm:h,onCloseRemoteForm:o,onSwitchToLocalFromRemote:w,onEnterLocalSetup:S,isRetrying:j,localAvailable:U}=a,K=h===void 0?!1:h,x=j===void 0?!1:j,m=U===void 0?!0:U,k=Fe;let C;t[0]!==l?(C=async()=>{if($()){await P();return}await W("/api/config/reload",{method:"POST"}),l?.()},t[0]=l,t[1]=C):C=t[1];const g=C;let T;t[2]!==S||t[3]!==s?(T=async()=>{if(de(s,"use-local").kind==="local-setup"){S?.();return}if(await k("local"),$()){await P();return}window.location.reload()},t[2]=S,t[3]=s,t[4]=T):T=t[4];const I=T;let y;t[5]!==u||t[6]!==s?(y=()=>{de(s,"use-remote").kind==="remote-form"&&u?.()},t[5]=u,t[6]=s,t[7]=y):y=t[7];const f=y;if(K){const N=s==="remote-wrong-service"?"":r||"",E=s==="remote-wrong-service"?"":n||"";let F;t[8]!==u||t[9]!==o?(F=o||(()=>u?.()),t[8]=u,t[9]=o,t[10]=F):F=t[10];const O=!m;let c;t[11]!==m||t[12]!==S||t[13]!==w?(c=m?w||(()=>{k("local").then(()=>{$()?P():S?.()})}):void 0,t[11]=m,t[12]=S,t[13]=w,t[14]=c):c=t[14];let D;return t[15]!==E||t[16]!==N||t[17]!==F||t[18]!==O||t[19]!==c?(D=e.jsx(xe,{onBack:F,initialUrl:N,initialLabel:E,isRecoveryMode:!0,showInstancePicker:O,onSwitchToLocal:c}),t[15]=E,t[16]=N,t[17]=F,t[18]=O,t[19]=c,t[20]=D):D=t[20],D}const b=m?I:void 0;let R;return t[21]!==g||t[22]!==f||t[23]!==n||t[24]!==r||t[25]!==x||t[26]!==b||t[27]!==s?(R=e.jsx(Ee,{variant:s,hostLabel:n,hostUrl:r,onRetry:g,onUseLocal:b,onUseRemote:f,isRetrying:x}),t[21]=g,t[22]=f,t[23]=n,t[24]=r,t[25]=x,t[26]=b,t[27]=s,t[28]=R):R=t[28],R}async function Fe(a){if(!$())return;const t=await V();await Y({...t,...a==="local"?{defaultHostId:"local"}:{},initialHostChoiceCompleted:!0})}function co(a){const t=J.c(29),{onBack:s,onCliAvailable:r,mode:n,recoveryVariant:l,recoveryHostUrl:u,recoveryHostLabel:h,onEnterLocalSetup:o,localAvailable:w}=a,S=n===void 0?"first-launch":n,j=l===void 0?"missing-default-host":l,U=w===void 0?!0:w,[K,x]=i.useState(!1),[m,k]=i.useState(!1);let C;t[0]===Symbol.for("react.memo_cache_sentinel")?(C=()=>{k(!1),x(!1)},t[0]=C):C=t[0];let g;t[1]!==S||t[2]!==h||t[3]!==u||t[4]!==j?(g=[S,j,u,h],t[1]=S,t[2]=h,t[3]=u,t[4]=j,t[5]=g):g=t[5],i.useEffect(C,g);const T=m?"local-setup":S;if(T==="recovery"){let y;t[6]===Symbol.for("react.memo_cache_sentinel")?(y=()=>x(!0),t[6]=y):y=t[6];let f,b;t[7]===Symbol.for("react.memo_cache_sentinel")?(f=()=>x(!1),b=()=>{x(!1),k(!0)},t[7]=f,t[8]=b):(f=t[7],b=t[8]);let R;t[9]!==o?(R=()=>{k(!0),o?.()},t[9]=o,t[10]=R):R=t[10];let N;return t[11]!==U||t[12]!==h||t[13]!==u||t[14]!==j||t[15]!==K||t[16]!==R?(N=e.jsx(Ae,{variant:j,hostUrl:u,hostLabel:h,onChooseRemote:y,showRemoteForm:K,onCloseRemoteForm:f,onSwitchToLocalFromRemote:b,onEnterLocalSetup:R,localAvailable:U}),t[11]=U,t[12]=h,t[13]=u,t[14]=j,t[15]=K,t[16]=R,t[17]=N):N=t[17],N}if(T==="local-setup"){let y;t[18]!==s||t[19]!==m?(y=()=>{m?k(!1):s?.()},t[18]=s,t[19]=m,t[20]=y):y=t[20];let f;t[21]===Symbol.for("react.memo_cache_sentinel")?(f=()=>x(!0),t[21]=f):f=t[21];let b;return t[22]!==r||t[23]!==m||t[24]!==y?(b=e.jsx(Ie,{onBack:y,onCliAvailable:r,isFromRecovery:m,onSwitchToRemote:f}),t[22]=r,t[23]=m,t[24]=y,t[25]=b):b=t[25],b}let I;return t[26]!==U||t[27]!==r?(I=e.jsx(Re,{onCliAvailable:r,localAvailable:U}),t[26]=U,t[27]=r,t[28]=I):I=t[28],I}export{co as OnboardingScreen};
|