@openchambery/web 1.19.5-beta.5 → 1.19.5-beta.7
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/dist/assets/{AssistantView-yBEtonie.js → AssistantView-DEZmCJfZ.js} +1 -1
- package/dist/assets/{ChatContainer-BOi9iz27.js → ChatContainer-7xklhgZ-.js} +14 -14
- package/dist/assets/{ContextPanel-AdZZ4JBG.js → ContextPanel-BxDa7ise.js} +5 -5
- package/dist/assets/{DiagramView-bQvW8jaw.js → DiagramView-BSMYmwZG.js} +1 -1
- package/dist/assets/MarkdownRendererImpl-nOIABlFe.js +7 -0
- package/dist/assets/{MobileDetailNavigation-CE1s2ZEr.js → MobileDetailNavigation-CROyz_Yw.js} +1 -1
- package/dist/assets/{MobileShareBridge-C5w6oHUJ.js → MobileShareBridge-CrE7VKlJ.js} +1 -1
- package/dist/assets/{MobileSurface-DMv5Y8M5.js → MobileSurface-B3dgnpZC.js} +1 -1
- package/dist/assets/{MultiRunWindow-C5_K_mdR.js → MultiRunWindow-uy0wv612.js} +1 -1
- package/dist/assets/{SettingsView-orus6n2g.js → SettingsView-bYtAIupZ.js} +1 -1
- package/dist/assets/{SettingsWindow-BW9mYwHR.js → SettingsWindow-CyxAWGwL.js} +1 -1
- package/dist/assets/{TerminalView-BSOUHyOO.js → TerminalView-CkpXj357.js} +1 -1
- package/dist/assets/{ToolOutputDialog-nSZ8-Kjx.js → ToolOutputDialog-GNBM3JdP.js} +1 -1
- package/dist/assets/{angular-html-BXZQHcPZ.js → angular-html-CtgxlIZT.js} +1 -1
- package/dist/assets/{angular-ts-D8x7dmpg.js → angular-ts-DrvebXRV.js} +1 -1
- package/dist/assets/{apl-ugbjmfzm.js → apl-ct3-l_ov.js} +1 -1
- package/dist/assets/{appThemeRegistry-BqqUte4z.js → appThemeRegistry-CSmVLXHb.js} +2 -2
- package/dist/assets/{astro-BrfzL78y.js → astro-9KCX_vNx.js} +1 -1
- package/dist/assets/{blade-D4cYRUdW.js → blade-DHzjLhcB.js} +1 -1
- package/dist/assets/{c-CMzMVpWc.js → c-CEfQ88z4.js} +1 -1
- package/dist/assets/{cobol-DthQPUuS.js → cobol-ffQsCDPB.js} +1 -1
- package/dist/assets/{coffee-8Pqo9WtM.js → coffee-DtRj345i.js} +1 -1
- package/dist/assets/{cpp-D18L7odM.js → cpp-NWnna9VM.js} +1 -1
- package/dist/assets/{crystal-9GeLf5Ic.js → crystal-CnnqEH_e.js} +1 -1
- package/dist/assets/{css-CCmJvSl6.js → css-BRwHOW3t.js} +1 -1
- package/dist/assets/{edge-BNU68miL.js → edge-BmL4YNvW.js} +1 -1
- package/dist/assets/{elixir-Clm-oycI.js → elixir-m9Mcv-AW.js} +1 -1
- package/dist/assets/{elm-DyuJMdF4.js → elm-Dazsuz2c.js} +1 -1
- package/dist/assets/{erb-BGQIoPeF.js → erb-CJ1X7LGG.js} +1 -1
- package/dist/assets/{git-rebase-ZHVbPCu8.js → git-rebase-DHqm8iFM.js} +1 -1
- package/dist/assets/{gitApi-DcgZ2eTY.js → gitApi-D_n3g-Ox.js} +1 -1
- package/dist/assets/{glimmer-js-Dx29eTyZ.js → glimmer-js-529w2Uvl.js} +1 -1
- package/dist/assets/{glimmer-ts-7AFohuRx.js → glimmer-ts-B38MdnnB.js} +1 -1
- package/dist/assets/{glsl-Nbih-1pG.js → glsl-IFfKD25X.js} +1 -1
- package/dist/assets/{graphql-IOG_4fSc.js → graphql-m-L9qWWB.js} +1 -1
- package/dist/assets/{hack-DyZU34CD.js → hack-S2S7pq0v.js} +1 -1
- package/dist/assets/{haml-mwEldSxy.js → haml-BE8HBwbH.js} +1 -1
- package/dist/assets/{handlebars-BRbCg-TR.js → handlebars-DPMWj4Da.js} +1 -1
- package/dist/assets/{html-derivative-DpusPW9p.js → html-derivative-D0yehinc.js} +1 -1
- package/dist/assets/{html-DH50wxss.js → html-gfIVmLgx.js} +1 -1
- package/dist/assets/{http-fM2Ft62a.js → http-Yj1uQSnx.js} +1 -1
- package/dist/assets/{hurl-C7ZRA11y.js → hurl-CiAC6gLf.js} +1 -1
- package/dist/assets/{insertionBoundaries-BvWyoeKg.js → insertionBoundaries-BWQFX2-v.js} +1 -1
- package/dist/assets/{java-CuLv1JzP.js → java-lPyr66Qw.js} +1 -1
- package/dist/assets/{javascript-e9R9mij1.js → javascript-BlmKDQ-I.js} +1 -1
- package/dist/assets/{jinja-BqL4dpCe.js → jinja-DrvjNn4y.js} +1 -1
- package/dist/assets/{jison-BU1E246U.js → jison-BZ-k3PlS.js} +1 -1
- package/dist/assets/{json-CWUAz4dE.js → json-CaQi8cq5.js} +1 -1
- package/dist/assets/{jsx-Tb9QFw4P.js → jsx-kfzB3oTi.js} +1 -1
- package/dist/assets/{julia-C6q7nYBJ.js → julia-Bup0jpIM.js} +1 -1
- package/dist/assets/{just-CLHVCPQG.js → just-XMsX5iKL.js} +1 -1
- package/dist/assets/{latex-DzR96v9w.js → latex-CHhOHp9u.js} +1 -1
- package/dist/assets/{liquid-UjsTutWK.js → liquid-C90FVKxw.js} +1 -1
- package/dist/assets/{lua-laWCoC7H.js → lua-BXPwTBAD.js} +1 -1
- package/dist/assets/{main-5aHBuDgM.js → main-CvXypdcN.js} +2 -2
- package/dist/assets/{main-C2UbPCo7.js → main-D8bG2Z4J.js} +3 -3
- package/dist/assets/markdown-shiki.worker-woF2hOAN.js +349 -0
- package/dist/assets/{markdown-worker-DqO-GnVj.js → markdown-worker-C7TuaOUy.js} +3 -3
- package/dist/assets/{marko-Cw81uHQK.js → marko-oFkW-Ef7.js} +1 -1
- package/dist/assets/{mdc-5VRIrvpo.js → mdc-Dt17Fv3G.js} +1 -1
- package/dist/assets/{miniChat-CUFkoTCJ.js → miniChat-DGAhFdQF.js} +2 -2
- package/dist/assets/{mobile-B_x6fY62.js → mobile-yPEbqNoZ.js} +2 -2
- package/dist/assets/{multirun-uwd4aNIT.js → multirun-BknRCqi_.js} +1 -1
- package/dist/assets/{nginx-OjbRtDTh.js → nginx-LfNI-F2k.js} +1 -1
- package/dist/assets/{nim-BqzUQFfL.js → nim-so0j2_Ky.js} +1 -1
- package/dist/assets/{perl-Bba2cEgf.js → perl-DQcGQU9O.js} +1 -1
- package/dist/assets/{php-CkVgF6HF.js → php-Dae1IcCM.js} +1 -1
- package/dist/assets/{projectMeta-engw2_70.js → projectMeta-DVNZvZ46.js} +1 -1
- package/dist/assets/{pug-Dj44SzNY.js → pug-CaHd5xEa.js} +1 -1
- package/dist/assets/{qml-DETHcUPx.js → qml-lLqImktD.js} +1 -1
- package/dist/assets/{r-CrbPkwLJ.js → r-C2VuzPsf.js} +1 -1
- package/dist/assets/{radio-BHGZb0sh.js → radio-BMoCQO6a.js} +1 -1
- package/dist/assets/{razor-56IyEPA5.js → razor-DTpzsAil.js} +1 -1
- package/dist/assets/{regexp-BEMDgR1N.js → regexp-DJeMtopQ.js} +1 -1
- package/dist/assets/{renderElectronMiniChatApp-kwVnDxKi.js → renderElectronMiniChatApp-B5xeh2ZJ.js} +2 -2
- package/dist/assets/{renderMobileApp-Bt-LuBXK.js → renderMobileApp-CUawlRGR.js} +4 -4
- package/dist/assets/{rst-C8BEzC8U.js → rst-c6kvN9mK.js} +1 -1
- package/dist/assets/{ruby-DWyeL44t.js → ruby-B68kNTjT.js} +1 -1
- package/dist/assets/{runtimeConfig-_JcGrrxY.js → runtimeConfig-CeCzxsbJ.js} +1 -1
- package/dist/assets/{runtimeEndpointReset-CN0a3Q6V.js → runtimeEndpointReset-DsyMqEdY.js} +1 -1
- package/dist/assets/{sas-Dt-MhHv8.js → sas-Br3BRi6f.js} +1 -1
- package/dist/assets/{scss-jmTM-KWO.js → scss-ugvUHawi.js} +1 -1
- package/dist/assets/{shellscript-BgI_n_Bv.js → shellscript-Ci5rJl0t.js} +1 -1
- package/dist/assets/{shellsession-DhmUadx_.js → shellsession-Dxn1WKgk.js} +1 -1
- package/dist/assets/{shikiHighlight-CUBUPsOF.js → shikiHighlight-H1oY_bZc.js} +1 -1
- package/dist/assets/{soy-qfQbh7dQ.js → soy-kgnQSRVZ.js} +1 -1
- package/dist/assets/{sql-CwyNz0Gh.js → sql-Cx3XaVwp.js} +1 -1
- package/dist/assets/{stata-D9MlkA-a.js → stata-B5YhL3cp.js} +1 -1
- package/dist/assets/{surrealql-xR93a923.js → surrealql-B8ysTfdK.js} +1 -1
- package/dist/assets/{svelte-BA7ahdky.js → svelte-D5-K3GME.js} +1 -1
- package/dist/assets/{templ-CxpzFYl8.js → templ-n2DDBrat.js} +1 -1
- package/dist/assets/{tex-CePKgOWg.js → tex-CpNhXIXy.js} +1 -1
- package/dist/assets/{ts-tags-DP2fsj53.js → ts-tags-CrtENrUj.js} +1 -1
- package/dist/assets/{tsx-CI52QFY8.js → tsx-DEnzboO-.js} +1 -1
- package/dist/assets/{twig-BjoebDgo.js → twig-B7PeheP0.js} +1 -1
- package/dist/assets/{typescript-cpHrN9Ya.js → typescript-CUlPIybL.js} +1 -1
- package/dist/assets/{useAppFontEffects-w2z4tQjp.js → useAppFontEffects-NG6gPkgZ.js} +2 -2
- package/dist/assets/{useDesktopWindowControlsLayout-CsOlndNX.js → useDesktopWindowControlsLayout-DLWjejno.js} +1 -1
- package/dist/assets/{useEffectiveDirectory-DztZ8U3M.js → useEffectiveDirectory-DA4GhF7a.js} +1 -1
- package/dist/assets/{useMobileNavigationStore-BzOSycct.js → useMobileNavigationStore-BU5I6tvY.js} +1 -1
- package/dist/assets/{useSessionAutoCleanup-PXfozK-R.js → useSessionAutoCleanup-4ropqZdl.js} +1 -1
- package/dist/assets/{useWorkerHighlightedLines-B8JOB6wA.js → useWorkerHighlightedLines-IDeqjpbY.js} +2 -2
- package/dist/assets/{vue-DK5KPkZ5.js → vue-C6ZZy2AI.js} +1 -1
- package/dist/assets/{vue-html-BlUa8woS.js → vue-html-DsvGlIY2.js} +1 -1
- package/dist/assets/{vue-vine-D3hlJyLi.js → vue-vine-C8VLalyn.js} +1 -1
- package/dist/assets/{xml-CspvrcYx.js → xml-ChNx2zKg.js} +1 -1
- package/dist/assets/{xsl-D10hdnv5.js → xsl-yWKkpZli.js} +1 -1
- package/dist/assets/{yaml-C00-kDDU.js → yaml-CENNGtdf.js} +1 -1
- package/dist/index.html +2 -2
- package/dist/mini-chat.html +2 -2
- package/dist/mobile.html +2 -2
- package/package.json +1 -1
- package/dist/assets/MarkdownRendererImpl-CykGqBa-.js +0 -7
- package/dist/assets/markdown-shiki.worker-CKKjvdhc.js +0 -12
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/ToolOutputDialog-
|
|
2
|
-
import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{C as t,E as n,I as r,K as i,P as a,T as o,U as s,t as c}from"./useUIStore-DOxLVeGb.js";import{$t as l,D as u,Rt as d,Xt as f,Yt as p,d as m,in as h,k as g,kn as _,qt as v,r as y,rn as b,st as x}from"./persistence-DE9RnVcA.js";import{a as S}from"./vendor-zustand-B4dlGEM2.js";import{nt as C,rt as w,tt as T}from"./vendor-base-ui-CnHfUmDN.js";import{Mt as E,Nt as D}from"./platform-MjT8iqKB.js";import{o as O}from"./vendor-aparajita-capacitor-secure-storage-CjQdwfjS.js";import{n as k}from"./vendor-react-DLPElpoQ.js";import{n as A,s as j}from"./vendor-tanstack-react-query-D7pys_c9.js";import{W as M,ct as N}from"./vendor-codemirror-autocomplete-DHomsvW7.js";import{n as P}from"./vendor-reactuses-core-DDoDDyM9.js";import{n as ee,o as F,r as I,t as te}from"./clipboard-CadKjjVT.js";import{i as ne,t as L}from"./store-DtS03LqZ.js";import{Ao as re,Ar as ie,Bt as R,En as ae,Gt as z,Ja as B,Kt as V,_n as oe,an as se,dn as H,ei as U,gn as W,gr as G,ha as K,hn as ce,in as le,jn as q,l as ue,ma as de,na as fe,nn as pe,on as me,rn as he,zt as ge}from"./useMobileNavigationStore-
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/ToolOutputDialog-GNBM3JdP.js","assets/rolldown-runtime-C0FnF6B9.js","assets/useUIStore-DOxLVeGb.js","assets/vendor-zustand-B4dlGEM2.js","assets/vendor-base-ui-CnHfUmDN.js","assets/persistence-DE9RnVcA.js","assets/vendor-pathe-vBmvQE8f.js","assets/vendor-react-DLPElpoQ.js","assets/vendor-tanstack-query-core-BWz0ose6.js","assets/vendor-reactuses-core-DDoDDyM9.js","assets/vendor-lodash-es-DfLbG5Af.js","assets/vendor-js-cookie-hSOiFTtX.js","assets/clipboard-CadKjjVT.js","assets/store-DtS03LqZ.js","assets/vendor-aparajita-capacitor-secure-storage-CjQdwfjS.js","assets/dialog-Dz2MBeLn.js","assets/utils-C2R0YoC5.js","assets/vendor-class-variance-authority-BLUaYARZ.js","assets/vendor-tailwind-merge-BicNWLTg.js","assets/Icon-BLWVqBee.js","assets/button-CeCkEpvn.js","assets/useThemeSystem-DMzWVJaW.js","assets/markdownTheme-H7_7lbuh.js","assets/vendor-pierre-diffs-BenIz2TM.js","assets/vendor-hast-util-to-html-B0p1k5Xa.js","assets/vendor-character-entities-legacy-Wut6vMuj.js","assets/vendor-character-entities-html4-DlN_yAFd.js","assets/vendor-ccount-CyGsA0u7.js","assets/vendor-comma-separated-tokens-B9ouxNNS.js","assets/vendor-oniguruma-to-es-CrHzjjSU.js","assets/vendor-oniguruma-parser-D2DIvhSP.js","assets/vendor-diff-Dq7CZNim.js","assets/vendor-lru_map-DpDied8H.js","assets/appThemeRegistry-CSmVLXHb.js","assets/platform-MjT8iqKB.js","assets/vendor-opencode-sdk-C07HQypa.js","assets/useMobileNavigationStore-BU5I6tvY.js","assets/vendor-tanstack-react-query-D7pys_c9.js","assets/vendor-sonner-DVzioF3d.js","assets/useAssistantUIStore-D2K7ksGj.js","assets/vendor-fuse.js-DB5wDJbI.js","assets/markdown-worker-C7TuaOUy.js","assets/useEffectiveDirectory-DA4GhF7a.js","assets/useWorkerHighlightedLines-IDeqjpbY.js","assets/tooltip-B__x-HDJ.js","assets/vendor-tanstack-react-virtual-tlDgH6PG.js"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{C as t,E as n,I as r,K as i,P as a,T as o,U as s,t as c}from"./useUIStore-DOxLVeGb.js";import{$t as l,D as u,Rt as d,Xt as f,Yt as p,d as m,in as h,k as g,kn as _,qt as v,r as y,rn as b,st as x}from"./persistence-DE9RnVcA.js";import{a as S}from"./vendor-zustand-B4dlGEM2.js";import{nt as C,rt as w,tt as T}from"./vendor-base-ui-CnHfUmDN.js";import{Mt as E,Nt as D}from"./platform-MjT8iqKB.js";import{o as O}from"./vendor-aparajita-capacitor-secure-storage-CjQdwfjS.js";import{n as k}from"./vendor-react-DLPElpoQ.js";import{n as A,s as j}from"./vendor-tanstack-react-query-D7pys_c9.js";import{W as M,ct as N}from"./vendor-codemirror-autocomplete-DHomsvW7.js";import{n as P}from"./vendor-reactuses-core-DDoDDyM9.js";import{n as ee,o as F,r as I,t as te}from"./clipboard-CadKjjVT.js";import{i as ne,t as L}from"./store-DtS03LqZ.js";import{Ao as re,Ar as ie,Bt as R,En as ae,Gt as z,Ja as B,Kt as V,_n as oe,an as se,dn as H,ei as U,gn as W,gr as G,ha as K,hn as ce,in as le,jn as q,l as ue,ma as de,na as fe,nn as pe,on as me,rn as he,zt as ge}from"./useMobileNavigationStore-BU5I6tvY.js";import{a as _e,i as ve,n as ye,o as be,r as xe,t as Se}from"./dialog-Dz2MBeLn.js";import{a as Ce,i as we,o as Te,t as J}from"./utils-C2R0YoC5.js";import{n as Y}from"./Icon-BLWVqBee.js";import{t as X}from"./button-CeCkEpvn.js";import{A as Ee,j as De,o as Oe}from"./projectMeta-DVNZvZ46.js";import{t as ke}from"./input-CyG05w-V.js";import{i as Ae,n as je,t as Me}from"./tooltip-B__x-HDJ.js";import{n as Ne,t as Pe}from"./useThemeSystem-DMzWVJaW.js";import{A as Fe,C as Ie,K as Le,P as Re,S as ze,V as Be,_ as Ve,c as He,n as Ue,s as We,v as Ge,w as Ke,x as qe,y as Je}from"./radio-BMoCQO6a.js";import{i as Ye,t as Xe}from"./OverlayScrollbar-GQgJusKL.js";import{f as Ze,g as Qe,h as $e,x as et}from"./markdownTheme-H7_7lbuh.js";import{G as tt,H as nt,I as rt,J as it,N as at,P as ot,R as st,X as ct,Y as lt,_ as ut,a as Z,c as dt,d as ft,et as pt,f as mt,g as ht,l as gt,m as _t,n as vt,nt as yt,o as bt,p as xt,q as St,s as Ct,z as wt}from"./ChatContainer-7xklhgZ-.js";import{n as Tt}from"./useRuntimeAPIs-DSLXJybW.js";import{F as Et,P as Dt,b as Ot,g as kt,x as At,y as jt}from"./insertionBoundaries-BWQFX2-v.js";import{i as Mt,n as Nt,t as Pt,u as Ft}from"./appThemeRegistry-CSmVLXHb.js";import{a as It}from"./url-CTuw7Rjf.js";import{_ as Lt,g as Rt,h as zt,m as Bt,p as Vt}from"./markdown-worker-C7TuaOUy.js";import{n as Ht}from"./useEffectiveDirectory-DA4GhF7a.js";import{o as Ut}from"./FadeInOnReveal-Cy3sf2M5.js";import{g as Wt,n as Gt}from"./useWorkerHighlightedLines-IDeqjpbY.js";import{t as Kt}from"./sortable-tabs-strip-xB36tCMU.js";import{a as qt,c as Jt,d as Yt,f as Xt,l as Zt,m as Qt,n as $t,o as en,p as tn,s as nn,t as rn,u as an}from"./vendor-pierre-diffs-BenIz2TM.js";import{a as on,c as sn,i as cn,l as ln,n as un,o as dn,r as fn,s as pn,t as mn}from"./shikiHighlight-H1oY_bZc.js";import{n as hn,r as gn,t as _n}from"./collapsible-B-aagADh.js";import{t as vn}from"./diagram-Cxma_IKI.js";import{t as yn}from"./vendor-zumer-snapdom-yq9vlCKr.js";import{n as bn,t as xn}from"./vendor-html-to-image-BDMm2v6d.js";var Q=e(w(),1),Sn=k(),$=C(),Cn=e(T(),1);function wn(){return new Worker(rn,{type:`module`})}var Tn=[`typescript`,`javascript`,`tsx`,`jsx`,`json`,`markdown`],En={unified:{poolSize:1,totalASTLRUCacheSize:24,lineDiffType:`none`},split:{poolSize:2,totalASTLRUCacheSize:56,lineDiffType:`word-alt`}},Dn,On,kn=e=>{let t=En[e],n=new tn({workerFactory:wn,poolSize:t.poolSize,totalASTLRUCacheSize:t.totalASTLRUCacheSize},{theme:{light:`pierre-light`,dark:`pierre-dark`},langs:Tn,lineDiffType:t.lineDiffType,preferredHighlighter:`shiki-wasm`});return n.initialize(),n},An=e=>{if(!(typeof window>`u`))return e===`split`?(On??=kn(`split`),On):(Dn??=kn(`unified`),Dn)},jn=e=>{let t=(0,Sn.c)(7),{children:n,renderTheme:r}=e,i=Nn(`unified`),a=Nn(`split`),o,s;t[0]!==r||t[1]!==a||t[2]!==i?(o=()=>{i&&i.setRenderOptions({theme:r,lineDiffType:En.unified.lineDiffType}),a&&a.setRenderOptions({theme:r,lineDiffType:En.split.lineDiffType})},s=[r,a,i],t[0]=r,t[1]=a,t[2]=i,t[3]=o,t[4]=s):(o=t[3],s=t[4]),(0,Q.useEffect)(o,s);let c;return t[5]===n?c=t[6]:(c=(0,$.jsx)($.Fragment,{children:n}),t[5]=n,t[6]=c),c},Mn=e=>{let t=(0,Sn.c)(11),{children:n}=e,r=Pe(),i,a;if(t[0]!==r?.availableThemes||t[1]!==r?.darkThemeId||t[2]!==r?.lightThemeId){let e=et(!1),n=et(!0),o=r?.lightThemeId??e.metadata.id,s=r?.darkThemeId??n.metadata.id;a=r?.availableThemes.find(e=>e.metadata.id===o)??e,i=r?.availableThemes.find(e=>e.metadata.id===s)??n,Pt(a),Pt(i),t[0]=r?.availableThemes,t[1]=r?.darkThemeId,t[2]=r?.lightThemeId,t[3]=i,t[4]=a}else i=t[3],a=t[4];let o;t[5]!==i.metadata.id||t[6]!==a.metadata.id?(o={light:a.metadata.id,dark:i.metadata.id},t[5]=i.metadata.id,t[6]=a.metadata.id,t[7]=o):o=t[7];let s=o,c;return t[8]!==n||t[9]!==s?(c=(0,$.jsx)(jn,{renderTheme:s,children:n}),t[8]=n,t[9]=s,t[10]=c):c=t[10],c},Nn=e=>{let t=(0,Sn.c)(2),n=e===void 0?`unified`:e,r;return t[0]===n?r=t[1]:(r=An(n),t[0]=n,t[1]=r),r};function Pn(e){let t=(0,Sn.c)(85),{draft:n,onEdit:r,onDelete:i,className:a,maxWidth:o}=e,{t:s}=ee(),c=Pe()?.currentTheme,[l,u]=(0,Q.useState)(!1),[d,f]=(0,Q.useState)(!1),p=typeof n.text==`string`?n.text:``,m;t[0]===p?m=t[1]:(m=p.length>150||p.split(`
|
|
3
3
|
`).length>3,t[0]=p,t[1]=m);let h=m,g;t[2]===a?g=t[3]:(g=J(`rounded-lg border shadow-none w-full max-w-[min(100%,calc(var(--oc-context-panel-width,100vw)-var(--oc-editor-gutter-width,0px)))] overflow-hidden transition-all duration-200`,a),t[2]=a,t[3]=g);let _=c?.colors?.surface?.elevated,v=c?.colors?.interactive?.border,y=o?`${Math.max(200,Math.floor(o))}px`:void 0,b;t[4]!==_||t[5]!==v||t[6]!==y?(b={backgroundColor:_,borderColor:v,maxWidth:y},t[4]=_,t[5]=v,t[6]=y,t[7]=b):b=t[7];let x;t[8]===Symbol.for(`react.memo_cache_sentinel`)?(x=e=>{e.preventDefault(),f(!0)},t[8]=x):x=t[8];let S;t[9]!==g||t[10]!==b?(S=(0,$.jsx)(`div`,{className:g,style:b,"data-comment-card":`true`,onContextMenu:x}),t[9]=g,t[10]=b,t[11]=S):S=t[11];let C;t[12]===n.fileLabel?C=t[13]:(C=(0,$.jsx)(`span`,{className:`truncate max-w-[200px]`,title:n.fileLabel,children:n.fileLabel}),t[12]=n.fileLabel,t[13]=C);let w;t[14]===Symbol.for(`react.memo_cache_sentinel`)?(w=(0,$.jsx)(`span`,{children:`•`}),t[14]=w):w=t[14];let T;t[15]!==n.endLine||t[16]!==n.startLine||t[17]!==s?(T=s(`inlineComment.range.lines`,{start:n.startLine,end:n.endLine}),t[15]=n.endLine,t[16]=n.startLine,t[17]=s,t[18]=T):T=t[18];let E;t[19]===T?E=t[20]:(E=(0,$.jsx)(`span`,{children:T}),t[19]=T,t[20]=E);let D;t[21]===n.side?D=t[22]:(D=n.side&&(0,$.jsxs)(`span`,{children:[`(`,n.side,`)`]}),t[21]=n.side,t[22]=D);let O;t[23]!==E||t[24]!==D||t[25]!==C?(O=(0,$.jsxs)(`div`,{className:`flex items-center gap-2 text-xs font-medium text-muted-foreground mb-1.5`,children:[C,w,E,D]}),t[23]=E,t[24]=D,t[25]=C,t[26]=O):O=t[26];let k=l||!h,A=!l&&h&&`line-clamp-3`,j;t[27]===A?j=t[28]:(j=J(`text-sm whitespace-pre-wrap break-words leading-relaxed`,A),t[27]=A,t[28]=j);let M;t[29]!==p||t[30]!==j?(M=(0,$.jsx)(`div`,{className:j,children:p}),t[29]=p,t[30]=j,t[31]=M):M=t[31];let N;t[32]!==h||t[33]!==l||t[34]!==s?(N=h&&(0,$.jsx)(gn,{asChild:!0,children:(0,$.jsx)(X,{variant:`ghost`,size:`sm`,className:`h-6 px-0 mt-1 text-xs text-muted-foreground hover:text-foreground w-full justify-start`,children:l?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Y,{name:`arrow-up-s`,className:`size-3 mr-1`}),s(`inlineComment.actions.showLess`)]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Y,{name:`arrow-down-s`,className:`size-3 mr-1`}),s(`inlineComment.actions.showMore`)]})})}),t[32]=h,t[33]=l,t[34]=s,t[35]=N):N=t[35];let P;t[36]===Symbol.for(`react.memo_cache_sentinel`)?(P=(0,$.jsx)(hn,{}),t[36]=P):P=t[36];let F;t[37]!==k||t[38]!==M||t[39]!==N?(F=(0,$.jsxs)(_n,{open:k,onOpenChange:u,children:[M,N,P]}),t[37]=k,t[38]=M,t[39]=N,t[40]=F):F=t[40];let I;t[41]!==O||t[42]!==F?(I=(0,$.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[O,F]}),t[41]=O,t[42]=F,t[43]=I):I=t[43];let te;t[44]===Symbol.for(`react.memo_cache_sentinel`)?(te=(0,$.jsx)(Ke,{asChild:!0,children:(0,$.jsx)(X,{variant:`ghost`,size:`icon`,className:`h-6 w-6 -mr-1 text-muted-foreground hover:text-foreground`,children:(0,$.jsx)(Y,{name:`more`,className:`size-4`})})}),t[44]=te):te=t[44];let ne;t[45]===Symbol.for(`react.memo_cache_sentinel`)?(ne=(0,$.jsx)(Y,{name:`edit`,className:`size-4 mr-2`}),t[45]=ne):ne=t[45];let L;t[46]===s?L=t[47]:(L=s(`inlineComment.actions.editComment`),t[46]=s,t[47]=L);let re;t[48]!==r||t[49]!==L?(re=(0,$.jsxs)(Je,{onClick:r,children:[ne,L]}),t[48]=r,t[49]=L,t[50]=re):re=t[50];let ie;t[51]===Symbol.for(`react.memo_cache_sentinel`)?(ie=(0,$.jsx)(Y,{name:`delete-bin`,className:`size-4 mr-2`}),t[51]=ie):ie=t[51];let R;t[52]===s?R=t[53]:(R=s(`inlineComment.actions.deleteComment`),t[52]=s,t[53]=R);let ae;t[54]!==i||t[55]!==R?(ae=(0,$.jsxs)(Je,{onClick:i,className:`text-destructive`,children:[ie,R]}),t[54]=i,t[55]=R,t[56]=ae):ae=t[56];let z;t[57]!==re||t[58]!==ae?(z=(0,$.jsxs)(Ve,{children:[te,(0,$.jsxs)(Ge,{align:`end`,children:[re,ae]})]}),t[57]=re,t[58]=ae,t[59]=z):z=t[59];let B;t[60]!==I||t[61]!==z?(B=(0,$.jsxs)(`div`,{className:`flex items-start justify-between gap-2 p-3`,children:[I,z]}),t[60]=I,t[61]=z,t[62]=B):B=t[62];let V;t[63]!==B||t[64]!==S?(V=(0,$.jsx)(ln,{render:S,children:B}),t[63]=B,t[64]=S,t[65]=V):V=t[65];let oe;t[66]===Symbol.for(`react.memo_cache_sentinel`)?(oe=(0,$.jsx)(Y,{name:`edit`,className:`size-4 mr-2`}),t[66]=oe):oe=t[66];let se;t[67]===s?se=t[68]:(se=s(`inlineComment.actions.editComment`),t[67]=s,t[68]=se);let H;t[69]!==r||t[70]!==se?(H=(0,$.jsxs)(pn,{onClick:r,children:[oe,se]}),t[69]=r,t[70]=se,t[71]=H):H=t[71];let U;t[72]===Symbol.for(`react.memo_cache_sentinel`)?(U=(0,$.jsx)(Y,{name:`delete-bin`,className:`size-4 mr-2`}),t[72]=U):U=t[72];let W;t[73]===s?W=t[74]:(W=s(`inlineComment.actions.deleteComment`),t[73]=s,t[74]=W);let G;t[75]!==i||t[76]!==W?(G=(0,$.jsxs)(pn,{onClick:i,className:`text-destructive focus:text-destructive`,children:[U,W]}),t[75]=i,t[76]=W,t[77]=G):G=t[77];let K;t[78]!==H||t[79]!==G?(K=(0,$.jsxs)(dn,{children:[H,G]}),t[78]=H,t[79]=G,t[80]=K):K=t[80];let ce;return t[81]!==d||t[82]!==V||t[83]!==K?(ce=(0,$.jsxs)(on,{open:d,onOpenChange:f,children:[V,K]}),t[81]=d,t[82]=V,t[83]=K,t[84]=ce):ce=t[84],ce}function Fn(e){let t=(0,Sn.c)(67),{initialText:n,onTextChange:r,onSave:i,onCancel:a,fileLabel:o,lineRange:s,isEditing:c,className:l,maxWidth:u,onAddToChat:d}=e,f=n===void 0?``:n,p=c!==void 0&&c,{t:m}=ee(),h=Pe()?.currentTheme,{isMobile:g}=Ye(),[_,v]=Q.useState(f),y=(0,Q.useRef)(null),b;t[0]===r?b=t[1]:(b=e=>{v(e),r?.(e)},t[0]=r,t[1]=b);let x=b,S=(0,Q.useRef)(s),C,w;t[2]===s?(C=t[3],w=t[4]):(C=()=>{s&&(S.current=s)},w=[s],t[2]=s,t[3]=C,t[4]=w),(0,Q.useEffect)(C,w);let T=Un,E=T(s),D,O;t[5]===g?(D=t[6],O=t[7]):(D=()=>{let e=y.current;if(!e)return;let t=e.closest(`.overlay-scrollbar-container`),n=t?.scrollTop??window.scrollY,r=t?.scrollLeft??window.scrollX;if(g){e.scrollIntoView({behavior:`auto`,block:`nearest`});try{e.focus({preventScroll:!0})}catch{e.focus()}return}try{e.focus({preventScroll:!0})}catch{e.focus()}let i=e.value.length;try{e.setSelectionRange(i,i)}catch{}requestAnimationFrame(()=>{t?(t.scrollTop=n,t.scrollLeft=r):window.scrollTo({top:n,left:r})})},O=[g],t[5]=g,t[6]=D,t[7]=O),(0,Q.useEffect)(D,O);let k;t[8]!==a||t[9]!==i||t[10]!==_?(k=e=>{(e.metaKey||e.ctrlKey)&&e.key===`Enter`?(e.preventDefault(),_.trim()&&i(_,T(S.current))):e.key===`Escape`&&(e.preventDefault(),a())},t[8]=a,t[9]=i,t[10]=_,t[11]=k):k=t[11];let A=k,j;t[12]!==i||t[13]!==_?(j=e=>{e.stopPropagation(),_.trim()&&i(_,T(S.current))},t[12]=i,t[13]=_,t[14]=j):j=t[14];let M=j,N;t[15]===l?N=t[16]:(N=J(`rounded-lg border shadow-none w-full max-w-[min(100%,calc(var(--oc-context-panel-width,100vw)-var(--oc-editor-gutter-width,0px)))] overflow-hidden animate-in fade-in zoom-in-95 duration-200`,l),t[15]=l,t[16]=N);let P=h?.colors?.surface?.elevated,F=h?.colors?.interactive?.border,I=u?`${Math.max(200,Math.floor(u))}px`:void 0,te;t[17]!==P||t[18]!==F||t[19]!==I?(te={backgroundColor:P,borderColor:F,maxWidth:I},t[17]=P,t[18]=F,t[19]=I,t[20]=te):te=t[20];let ne=Hn,L=Vn,re=(o||s)&&(0,$.jsxs)(`div`,{className:`flex items-center gap-2 text-xs font-medium text-muted-foreground mb-2`,children:[o&&(0,$.jsx)(`span`,{className:`truncate max-w-[200px]`,children:o}),o&&s&&(0,$.jsx)(`span`,{children:`•`}),E&&(0,$.jsx)(`span`,{children:m(`inlineComment.range.lines`,{start:E.start,end:E.end})})]}),ie;t[21]===x?ie=t[22]:(ie=e=>x(e.target.value),t[21]=x,t[22]=ie);let R;t[23]!==g||t[24]!==m?(R=m(g?`inlineComment.input.placeholderShort`:`inlineComment.input.placeholder`),t[23]=g,t[24]=m,t[25]=R):R=t[25];let ae;t[26]!==A||t[27]!==ie||t[28]!==R||t[29]!==_?(ae=(0,$.jsx)(Oe,{simple:!0,ref:y,value:_,onChange:ie,onKeyDown:A,placeholder:R,outerClassName:`rounded-[var(--radius-xl)] bg-[var(--surface-subtle)] ring-1 ring-inset ring-border/60 focus-within:ring-2 focus-within:ring-[var(--interactive-focus-ring)]`,className:`min-h-[80px] px-3 py-2.5 text-sm resize-y`}),t[26]=A,t[27]=ie,t[28]=R,t[29]=_,t[30]=ae):ae=t[30];let z;t[31]!==E||t[32]!==d||t[33]!==m?(z=E&&d?(0,$.jsxs)(X,{variant:`outline`,size:`sm`,onClick:()=>d(E),onPointerDown:Bn,className:`mr-auto h-8 gap-1.5`,children:[(0,$.jsx)(Y,{name:`add`,className:`size-4`}),m(`chat.textSelection.actions.addToChat`),(0,$.jsx)(tt,{shortcut:`⌘+I`})]}):null,t[31]=E,t[32]=d,t[33]=m,t[34]=z):z=t[34];let B;t[35]===m?B=t[36]:(B=m(`inlineComment.actions.cancel`),t[35]=m,t[36]=B);let V;t[37]!==a||t[38]!==B?(V=(0,$.jsx)(X,{variant:`ghost`,size:`sm`,onClick:a,onPointerDown:zn,onTouchStart:Rn,className:`h-8 text-muted-foreground hover:text-foreground`,children:B}),t[37]=a,t[38]=B,t[39]=V):V=t[39];let oe;t[40]===_?oe=t[41]:(oe=_.trim(),t[40]=_,t[41]=oe);let se=!oe,H=h?.colors?.status?.success,U=h?.colors?.status?.successForeground,W;t[42]!==H||t[43]!==U?(W={backgroundColor:H,color:U},t[42]=H,t[43]=U,t[44]=W):W=t[44];let G;t[45]!==p||t[46]!==m?(G=m(p?`inlineComment.actions.save`:`inlineComment.actions.comment`),t[45]=p,t[46]=m,t[47]=G):G=t[47];let K;t[48]!==M||t[49]!==se||t[50]!==W||t[51]!==G?(K=(0,$.jsx)(X,{size:`sm`,onClick:M,onPointerDown:Ln,onTouchStart:In,disabled:se,className:`h-8 min-w-[80px]`,style:W,children:G}),t[48]=M,t[49]=se,t[50]=W,t[51]=G,t[52]=K):K=t[52];let ce;t[53]!==z||t[54]!==V||t[55]!==K?(ce=(0,$.jsxs)(`div`,{className:`flex items-center justify-end gap-2 mt-3`,children:[z,V,K]}),t[53]=z,t[54]=V,t[55]=K,t[56]=ce):ce=t[56];let le;t[57]!==re||t[58]!==ae||t[59]!==ce?(le=(0,$.jsxs)(`div`,{className:`p-3`,children:[re,ae,ce]}),t[57]=re,t[58]=ae,t[59]=ce,t[60]=le):le=t[60];let q;return t[61]!==N||t[62]!==te||t[63]!==ne||t[64]!==L||t[65]!==le?(q=(0,$.jsx)(`div`,{className:N,style:te,"data-comment-input":`true`,onPointerDown:ne,onTouchStart:L,children:le}),t[61]=N,t[62]=te,t[63]=ne,t[64]=L,t[65]=le,t[66]=q):q=t[66],q}function In(e){return e.stopPropagation()}function Ln(e){return e.stopPropagation()}function Rn(e){return e.stopPropagation()}function zn(e){return e.stopPropagation()}function Bn(e){return e.stopPropagation()}function Vn(e){return e.stopPropagation()}function Hn(e){return e.stopPropagation()}function Un(e){if(!e)return;let t=Math.min(e.start,e.end),n=Math.max(e.start,e.end);return{...e,start:t,end:n}}var Wn=e=>{let t=Math.min(e.startLine,e.endLine),n=Math.max(e.startLine,e.endLine);return{...e,startLine:t,endLine:n}},Gn=e=>{let t=Math.min(e.start,e.end),n=Math.max(e.start,e.end);return{...e,start:t,end:n}};function Kn(e){let t=(0,Sn.c)(40),{t:n}=ee(),{source:r,fileLabel:i,language:a,getCodeForRange:o,toStoreRange:s,fromDraftRange:c}=e,l=ue(Qn),u=ue(Zn),d=lt(Xn),f=lt(Yn),p=lt(Jn),m=lt(qn),[h,g]=Q.useState(null),[_,v]=Q.useState(``),[y,b]=Q.useState(null),x=l??(u?`draft`:null),S;bb0:{if(!x||!i){let e;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(e=[],t[0]=e):e=t[0],S=e;break bb0}let e;t[1]!==m||t[2]!==x?(e=m[x]??[],t[1]=m,t[2]=x,t[3]=e):e=t[3];let n=e,a;if(t[4]!==i||t[5]!==n||t[6]!==r){let e;t[8]!==i||t[9]!==r?(e=e=>e.source===r&&e.fileLabel===i,t[8]=i,t[9]=r,t[10]=e):e=t[10],a=n.filter(e),t[4]=i,t[5]=n,t[6]=r,t[7]=a}else a=t[7];S=a}let C=S,w;t[11]===Symbol.for(`react.memo_cache_sentinel`)?(w=()=>{g(null),v(``),b(null)},t[11]=w):w=t[11];let T=w,E;t[12]===Symbol.for(`react.memo_cache_sentinel`)?(E=()=>{T()},t[12]=E):E=t[12];let D=E,O;t[13]===c?O=t[14]:(O=e=>{let t=Gn(c(e));g(t),v(e.text),b(e.id)},t[13]=c,t[14]=O);let k=O,A;t[15]!==y||t[16]!==p?(A=e=>{p(e.sessionKey,e.id),y===e.id&&T()},t[15]=y,t[16]=p,t[17]=A):A=t[17];let j=A,M;t[18]!==d||t[19]!==y||t[20]!==i||t[21]!==o||t[22]!==a||t[23]!==h||t[24]!==x||t[25]!==r||t[26]!==n||t[27]!==s||t[28]!==f?(M=(e,t)=>{let c=t??h,l=e.trim();if(!c||!l||!i)return;if(!x){G.error(n(`inlineComment.toast.selectSessionToSave`));return}let u=Gn(c),p=Wn(s(u)),m=o(u);y?f(x,y,{fileLabel:i,startLine:p.startLine,endLine:p.endLine,side:p.side,code:m,language:a,text:l}):d({sessionKey:x,source:r,fileLabel:i,startLine:p.startLine,endLine:p.endLine,side:p.side,code:m,language:a,text:l}),T()},t[18]=d,t[19]=y,t[20]=i,t[21]=o,t[22]=a,t[23]=h,t[24]=x,t[25]=r,t[26]=n,t[27]=s,t[28]=f,t[29]=M):M=t[29];let N=M,P;return t[30]!==_||t[31]!==j||t[32]!==C||t[33]!==y||t[34]!==c||t[35]!==N||t[36]!==h||t[37]!==x||t[38]!==k?(P={sessionKey:x,drafts:C,selection:h,setSelection:g,commentText:_,setCommentText:v,editingDraftId:y,setEditingDraftId:b,reset:T,cancel:D,startEdit:k,deleteDraft:j,saveComment:N,fromDraftRange:c},t[30]=_,t[31]=j,t[32]=C,t[33]=y,t[34]=c,t[35]=N,t[36]=h,t[37]=x,t[38]=k,t[39]=P):P=t[39],P}function qn(e){return e.drafts}function Jn(e){return e.removeDraft}function Yn(e){return e.updateDraft}function Xn(e){return e.addDraft}function Zn(e){return e.newSessionDraft?.open}function Qn(e){return e.currentSessionId}function $n(e){let{drafts:t,editingDraftId:n,commentText:r,onTextChange:i,selection:a,isDragging:o,fileLabel:s,newWidgetId:c,mapDraftToRange:l,onSave:u,onCancel:d,onEdit:f,onDelete:p,onAddToChat:m}=e,h=[];for(let e of t){let t=l(e);if(e.id===n){h.push({afterLine:t.end,id:`edit-${e.id}`,content:(0,$.jsx)(Fn,{initialText:r,onTextChange:i,fileLabel:s,lineRange:t,isEditing:!0,onSave:u,onCancel:d,onAddToChat:m},`edit-${e.id}`)});continue}h.push({afterLine:t.end,id:`card-${e.id}`,content:(0,$.jsx)(Pn,{draft:e,onEdit:()=>f(e),onDelete:()=>p(e)},`card-${e.id}`)})}if(a&&!n&&!o){let e={...a,start:Math.min(a.start,a.end),end:Math.max(a.start,a.end)};h.push({afterLine:e.end,id:c,content:(0,$.jsx)(Fn,{initialText:r,onTextChange:i,fileLabel:s,lineRange:e,isEditing:!1,onSave:u,onCancel:d,onAddToChat:m},c)})}return h}var er=e=>{if(e.type===`new`){let t=Math.min(e.selection.start,e.selection.end),n=Math.max(e.selection.start,e.selection.end);return`new-comment-${e.selection.side??`additions`}-${t}-${n}`}return`draft-${e.draft.id}`},tr=e=>{let{drafts:t,editingDraftId:n,selection:r}=e,i=[];for(let e of t){if(!Number.isFinite(e.endLine))continue;let t=Math.max(1,Math.floor(e.endLine)),r=e.side===`original`?`deletions`:`additions`;i.push({lineNumber:t,side:r,metadata:{type:e.id===n?`edit`:`saved`,draft:e}})}return r&&!n&&i.push({lineNumber:Math.max(r.start,r.end),side:r.side??`additions`,metadata:{type:`new`,selection:r}}),i};function nr(e){let t=e.trim();if(!t)return null;if(/^-?\d+(\.\d+)?$/.test(t)){let e=Number.parseFloat(t);return Number.isFinite(e)?e:null}if(t.endsWith(`px`)){let e=Number.parseFloat(t.slice(0,-2));return Number.isFinite(e)?e:null}return null}function rr(e){if(!(!e||e<=0))return Math.max(200,Math.floor(e))}function ir(e){let{diffRootRef:t,drafts:n,selection:r,editingDraftId:i,commentText:a,onTextChange:o,fileLabel:s,onSave:c,onCancel:l,onEdit:u,onDelete:d,onAddToChat:f}=e,[p,m]=Q.useState(0),[h,g]=Q.useState(null),_=Q.useMemo(()=>!r||i?null:er({type:`new`,selection:r}),[i,r]),v=Q.useMemo(()=>{let e=n.map(e=>er({type:e.id===i?`edit`:`saved`,draft:e}));return _&&e.push(_),e},[n,i,_]),y=Q.useCallback(e=>{let n=t.current;if(!n)return null;let r=n.querySelector(`diffs-container`);if(!(r instanceof HTMLElement))return null;let i=r.querySelector(`[data-annotation-id="${e}"]`);if(i instanceof HTMLElement)return i;let a=r.shadowRoot;return a?a.querySelector(`[data-annotation-id="${e}"]`):null},[t]);Q.useEffect(()=>{if(v.length===0)return;let e=!1,t=0,n=()=>{e||v.every(e=>!!y(e))||t>=12||(t+=1,requestAnimationFrame(()=>{e||(m(e=>e+1),n())}))};return n(),()=>{e=!0}},[v,y]),Q.useEffect(()=>{let e=t.current;if(!e)return;let n=()=>{let t=nr(getComputedStyle(e).getPropertyValue(`--oc-context-panel-width`)),n=e.getBoundingClientRect(),r=t??n.width;g(r>0?r:null)};n();let r=new ResizeObserver(()=>{n()});return r.observe(e),window.addEventListener(`resize`,n),()=>{r.disconnect(),window.removeEventListener(`resize`,n)}},[t]);let b=Q.useCallback(e=>{let n=t.current?.getBoundingClientRect(),r=e.closest(`[data-annotation-content]`),i=r instanceof HTMLElement?r.getBoundingClientRect():e.getBoundingClientRect(),a=[i.width];n&&a.push(n.right-i.left);let o=a.filter(e=>Number.isFinite(e)&&e>0);return o.length>0?rr(Math.min(...o)):rr(h)},[t,h]);return(0,$.jsxs)($.Fragment,{children:[n.map(e=>{let t=er({type:e.id===i?`edit`:`saved`,draft:e}),n=y(t);if(!n)return null;let r=b(n);return e.id===i?(0,Cn.createPortal)((0,$.jsx)(Fn,{initialText:a,onTextChange:o,fileLabel:s,lineRange:{start:e.startLine,end:e.endLine,side:e.side===`original`?`deletions`:`additions`},isEditing:!0,onSave:c,onCancel:l,onAddToChat:f,maxWidth:r}),n,`draft-edit-${e.id}`):(0,Cn.createPortal)((0,$.jsx)(Pn,{draft:e,onEdit:()=>u(e),onDelete:()=>d(e),maxWidth:r}),n,`draft-card-${e.id}`)}),r&&!i&&_&&(()=>{let e=y(_);if(!e)return null;let t=b(e);return(0,Cn.createPortal)((0,$.jsx)(Fn,{initialText:a,onTextChange:o,fileLabel:s,lineRange:r,isEditing:!1,onSave:c,onCancel:l,onAddToChat:f,maxWidth:t}),e,_)})()]})}function ar(e){let t=(0,Sn.c)(16),{position:n,onAddToChat:r,onDismiss:i}=e,{t:a}=ee(),o=Q.useRef(null),s,c;t[0]===i?(s=t[1],c=t[2]):(s=()=>{if(!i)return;let e=e=>{o.current&&e.target instanceof Node&&o.current.contains(e.target)||i()};return window.addEventListener(`scroll`,e,{capture:!0,passive:!0}),()=>{window.removeEventListener(`scroll`,e,!0)}},c=[i],t[0]=i,t[1]=s,t[2]=c),Q.useEffect(s,c);let l;t[3]!==n.x||t[4]!==n.y?(l={left:n.x,top:n.y},t[3]=n.x,t[4]=n.y,t[5]=l):l=t[5];let u;t[6]===Symbol.for(`react.memo_cache_sentinel`)?(u=(0,$.jsx)(Y,{name:`add`,className:`size-4`}),t[6]=u):u=t[6];let d;t[7]===a?d=t[8]:(d=a(`chat.textSelection.actions.addToChat`),t[7]=a,t[8]=d);let f;t[9]===Symbol.for(`react.memo_cache_sentinel`)?(f=(0,$.jsx)(tt,{shortcut:`⌘+I`}),t[9]=f):f=t[9];let p;t[10]!==r||t[11]!==d?(p=(0,$.jsxs)(X,{variant:`ghost`,size:`sm`,className:`h-7 gap-1.5 px-2`,onClick:r,children:[u,d,f]}),t[10]=r,t[11]=d,t[12]=p):p=t[12];let m;return t[13]!==l||t[14]!==p?(m=(0,Cn.createPortal)((0,$.jsx)(`div`,{ref:o,"data-code-selection-action":`true`,className:`fixed z-[100] -translate-y-full rounded-lg border border-[var(--interactive-border)] bg-[var(--surface-elevated)] p-1 shadow-lg`,style:l,onPointerDown:or,children:p}),document.body),t[13]=l,t[14]=p,t[15]=m):m=t[15],m}function or(e){return e.preventDefault()}var sr=`[data-code-selection-action]`;function cr(e){return e instanceof Element&&!!e.closest(sr)}function lr(e,t=[]){return cr(e)?!0:t.some(e=>e instanceof Element&&e.matches(`[data-column-number]`))}function ur(e,t){return e&&!!t?.trim()}function dr(e,t,n,r){let i=r.side===`deletions`,a=Math.min(r.start,r.end),o=Math.max(r.start,r.end);if(!n){let n=(i?e:t).split(`
|
|
4
4
|
`),r=Math.max(1,a),s=Math.min(n.length,o);return r>s?``:n.slice(r-1,s).join(`
|
|
5
5
|
`)}let s=i?n.deletionLines:n.additionLines,c=[];for(let e=a;e<=o;e+=1){let t=n.isPartial?fr(n,e,i):e-1;if(t===null||t<0||t>=s.length)continue;let r=s[t]??``;c.push(r.endsWith(`
|
|
@@ -142,7 +142,7 @@ import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{C as t,E as n,I as r,K
|
|
|
142
142
|
`),n=null;for(let e of t){let t=e.match(/^@@\s*-\d+(?:,\d+)?\s+\+(\d+)(?:,\d+)?\s*@@/);if(t){let e=Number.parseInt(t[1]??``,10);n=Number.isFinite(e)&&e>=1?e:null;continue}if(n!==null){if(e.startsWith(` `)){n+=1;continue}if(e.startsWith(`+`))return n;if(e.startsWith(`-`))return Math.max(1,n)}}return null},Gr=e=>{let t=[],n=new Set;for(let r of e){let e=r.path.trim(),i=r.patch;if(!e||!i.trim()||n.has(e))continue;n.add(e);let a=0,o=0;for(let e of i.split(`
|
|
143
143
|
`))e.startsWith(`+++`)||e.startsWith(`---`)||(e.startsWith(`+`)&&(a+=1),e.startsWith(`-`)&&(o+=1));let s=/^---\s+\/dev\/null(?:\s|$)/m.test(i)?`added`:/^\+\+\+\s+\/dev\/null(?:\s|$)/m.test(i)?`deleted`:`modified`;t.push({file:e,patch:i,status:s,additions:a,deletions:o})}return t},Kr=e=>`${e.scope}:${e.navigationRequestKey??``}:${(e.targetFilePath??``).trim()}:${e.targetLine??``}`,qr=(e,t,n)=>n&&e!==t,Jr=e=>`/api/openchamber/sessions/${encodeURIComponent(e)}/changes`,Yr=e=>e.trim(),Xr=e=>e===404||e===405||e===501,Zr=e=>{if(!e||typeof e!=`object`||Array.isArray(e))return!1;let t=e.diff;return!!t&&typeof t==`object`&&!Array.isArray(t)},Qr=(e,t)=>{if(!Array.isArray(e))return null;for(let n of e)if(n&&typeof n==`object`&&!Array.isArray(n)&&n.file===t)return n;return null},$r=async(e,t)=>{let n={messageID:e.messageID,directory:e.directory};return typeof e.file==`string`&&e.file.length>0&&(n.file=e.file),_(Jr(e.sessionID),{method:`GET`,headers:{Accept:`application/json`,"x-opencode-directory":e.directory},query:n,signal:t})},ei=async(e,t)=>{if(t.aborted)throw new DOMException(`Aborted`,`AbortError`);return D.getSessionDiff({sessionID:e.sessionID,directory:e.directory,messageID:e.messageID},{signal:t})},ti=(e,t=n())=>m.sessionTurnChanges.file(e.directory,e.sessionID,e.messageID,e.file,e.diffCount,t),ni=(e,t=n())=>({queryKey:ti(e,t),queryFn:async({signal:t})=>{let n=await $r(e,t);if(n.ok){let e=await n.json().catch(()=>null);if(Zr(e))return e}else if(!Xr(n.status))throw Error(`Session turn change file request failed (${n.status})`);let r=Qr(await ei(e,t),e.file);if(!r)throw Error(`change file not found`);return{diff:r}},staleTime:0,gcTime:6e4,retry:!1}),ri=(e,t)=>{let r=(0,Sn.c)(10),i;r[0]===t?i=r[1]:(i=t===void 0?{}:t,r[0]=t,r[1]=i);let a=i,o,s,c;if(r[2]!==e||r[3]!==a){let t=n();o=!!e&&!!e?.sessionID?.trim()&&!!e?.directory?.trim()&&!!e?.messageID?.trim()&&!!e?.file?.trim()&&a.enabled!==!1;let i=e??{sessionID:``,directory:``,messageID:``,file:``};c=j,s=ni({...i,directory:Yr(i.directory),file:i.file},t),r[2]=e,r[3]=a,r[4]=o,r[5]=s,r[6]=c}else o=r[4],s=r[5],c=r[6];let l;return r[7]!==o||r[8]!==s?(l={...s,enabled:o},r[7]=o,r[8]=s,r[9]=l):l=r[9],c(l)},ii=1100,ai=15e3,oi=500,si=300,ci=1e6,li=3,ui=e=>e<=6?e:e<=12?6:e<=25?4:2,di=Q.memo(()=>{let e=(0,Sn.c)(4),{t}=ee(),n;e[0]===t?n=e[1]:(n=t(`diffView.binary.unavailable`),e[0]=t,e[1]=n);let r;return e[2]===n?r=e[3]:(r=(0,$.jsx)(`div`,{className:`rounded-lg border border-border/60 bg-background px-3 py-2`,children:(0,$.jsx)(`div`,{className:`typography-meta text-muted-foreground`,children:n})}),e[2]=n,e[3]=r),r}),fi={"?":{code:`?`,color:`var(--status-info)`,descriptionKey:`diffView.change.untracked`},A:{code:`A`,color:`var(--status-success)`,descriptionKey:`diffView.change.new`},D:{code:`D`,color:`var(--status-error)`,descriptionKey:`diffView.change.deleted`},R:{code:`R`,color:`var(--status-info)`,descriptionKey:`diffView.change.renamed`},C:{code:`C`,color:`var(--status-info)`,descriptionKey:`diffView.change.copied`},M:{code:`M`,color:`var(--status-warning)`,descriptionKey:`diffView.change.modified`}},pi=fi.M,mi=e=>{let t=e.index?.trim(),n=e.working_dir?.trim();return t&&t!==`?`?t.charAt(0):n?n.charAt(0):t?.charAt(0)||n?.charAt(0)||`M`},hi=e=>fi[mi(e)]??pi,gi=e=>{let{index:t,working_dir:n}=e;return t===`A`||n===`A`||t===`?`||n===`?`},_i=e=>{let t=e.index?.trim();return!!(t&&t!==`?`)},vi=e=>!!e.working_dir?.trim()||e.index===`?`,yi=(e,t)=>Qe(e,t),bi=e=>(e||``).replace(/\\/g,`/`).replace(/\/+$/,``),xi=(e,t)=>{let n=e.split(`
|
|
144
144
|
`),r=t.split(`
|
|
145
|
-
`),i=Math.min(n.length,r.length);for(let e=0;e<i;e+=1)if(n[e]!==r[e])return e+1;return r.length>n.length?n.length+1:n.length>r.length?Math.max(1,r.length):1},Si=e=>/^Binary files .+ differ$/m.test(e)||/^GIT binary patch$/m.test(e),Ci=e=>Array.isArray(e)?e.filter(e=>!e||typeof e!=`object`?!1:typeof e.file==`string`):[],wi=e=>e===`added`?`A`:e===`deleted`?`D`:`M`,Ti=e=>e.isBinary||typeof e.patch==`string`&&e.patch.length>0||e.fileDiff?!0:e.original.length>0||e.modified.length>0,Ei=(e,t,n)=>Si(t)?{original:``,modified:``,isBinary:!0,patch:t,contextMode:n}:{original:``,modified:``,patch:t,fileDiff:zr(e,t),contextMode:n},Di=(e,t,n)=>{let r=e??0,i=t??0;return!r&&!i?null:(0,$.jsxs)(`span`,{className:J(`typography-code flex items-center gap-1 whitespace-nowrap`,n?.shrink?`min-w-0 overflow-hidden`:`flex-shrink-0`,n?.className),children:[r?(0,$.jsxs)(`span`,{style:{color:`var(--status-success)`},children:[`+`,r]}):null,i?(0,$.jsxs)(`span`,{style:{color:`var(--status-error)`},children:[`-`,i]}):null]})},Oi=Q.memo(e=>{let t=(0,Sn.c)(53),{scope:n,workingCount:r,stagedCount:i,turnCount:a,onScopeChange:o}=e,{t:s}=ee(),[c,l]=Q.useState(!1),u=n===`staged`?i:n===`turn`?a:r,d;t[0]!==n||t[1]!==s?(d=s(n===`staged`?`diffView.scope.staged`:n===`turn`?`diffView.scope.lastTurn`:`diffView.scope.changed`),t[0]=n,t[1]=s,t[2]=d):d=t[2];let f=d,p;t[3]===s?p=t[4]:(p=s(`diffView.scope.selectorAria`),t[3]=s,t[4]=p);let m;t[5]===u?m=t[6]:(m=(0,$.jsxs)(`span`,{className:`diff-toolbar__scope-count`,children:[`: `,u]}),t[5]=u,t[6]=m);let h;t[7]!==f||t[8]!==m?(h=(0,$.jsxs)(`span`,{className:`whitespace-nowrap`,children:[f,m]}),t[7]=f,t[8]=m,t[9]=h):h=t[9];let g;t[10]===Symbol.for(`react.memo_cache_sentinel`)?(g=(0,$.jsx)(Y,{name:`arrow-down-s`,className:`size-4 flex-shrink-0 opacity-60`}),t[10]=g):g=t[10];let _;t[11]!==p||t[12]!==h?(_=(0,$.jsx)(Ke,{asChild:!0,children:(0,$.jsxs)(`button`,{type:`button`,className:`flex h-7 flex-shrink-0 items-center gap-1.5 rounded-md px-2 typography-code font-semibold text-foreground outline-none hover:bg-interactive-hover focus-visible:ring-2 focus-visible:ring-ring`,"aria-label":p,children:[h,g]})}),t[11]=p,t[12]=h,t[13]=_):_=t[13];let v;t[14]===o?v=t[15]:(v=e=>{(e===`working`||e===`staged`||e===`turn`)&&(o?.(e),l(!1))},t[14]=o,t[15]=v);let y;t[16]===s?y=t[17]:(y=s(`diffView.scope.changed`),t[16]=s,t[17]=y);let b;t[18]===y?b=t[19]:(b=(0,$.jsx)(`span`,{children:y}),t[18]=y,t[19]=b);let x;t[20]===r?x=t[21]:(x=(0,$.jsx)(`span`,{className:`typography-meta text-muted-foreground`,children:r}),t[20]=r,t[21]=x);let S;t[22]!==x||t[23]!==b?(S=(0,$.jsx)(ze,{value:`working`,children:(0,$.jsxs)(`span`,{className:`flex min-w-0 flex-1 items-center justify-between gap-3`,children:[b,x]})}),t[22]=x,t[23]=b,t[24]=S):S=t[24];let C;t[25]===s?C=t[26]:(C=s(`diffView.scope.staged`),t[25]=s,t[26]=C);let w;t[27]===C?w=t[28]:(w=(0,$.jsx)(`span`,{children:C}),t[27]=C,t[28]=w);let T;t[29]===i?T=t[30]:(T=(0,$.jsx)(`span`,{className:`typography-meta text-muted-foreground`,children:i}),t[29]=i,t[30]=T);let E;t[31]!==w||t[32]!==T?(E=(0,$.jsx)(ze,{value:`staged`,children:(0,$.jsxs)(`span`,{className:`flex min-w-0 flex-1 items-center justify-between gap-3`,children:[w,T]})}),t[31]=w,t[32]=T,t[33]=E):E=t[33];let D;t[34]===s?D=t[35]:(D=s(`diffView.scope.lastTurn`),t[34]=s,t[35]=D);let O;t[36]===D?O=t[37]:(O=(0,$.jsx)(`span`,{children:D}),t[36]=D,t[37]=O);let k;t[38]===a?k=t[39]:(k=(0,$.jsx)(`span`,{className:`typography-meta text-muted-foreground`,children:a}),t[38]=a,t[39]=k);let A;t[40]!==O||t[41]!==k?(A=(0,$.jsx)(ze,{value:`turn`,children:(0,$.jsxs)(`span`,{className:`flex min-w-0 flex-1 items-center justify-between gap-3`,children:[O,k]})}),t[40]=O,t[41]=k,t[42]=A):A=t[42];let j;t[43]!==n||t[44]!==S||t[45]!==E||t[46]!==A||t[47]!==v?(j=(0,$.jsx)(Ge,{align:`start`,className:`w-40`,children:(0,$.jsxs)(qe,{value:n,onValueChange:v,children:[S,E,A]})}),t[43]=n,t[44]=S,t[45]=E,t[46]=A,t[47]=v,t[48]=j):j=t[48];let M;return t[49]!==c||t[50]!==j||t[51]!==_?(M=(0,$.jsxs)(Ve,{open:c,onOpenChange:l,children:[_,j]}),t[49]=c,t[50]=j,t[51]=_,t[52]=M):M=t[52],M}),ki=Q.memo(e=>{let t=(0,Sn.c)(11),{changedFiles:n,selectedFile:r,onSelectFile:i}=e,{t:a}=ee();if(n.length===0)return null;let o;if(t[0]!==n||t[1]!==i||t[2]!==r||t[3]!==a){let e;t[5]!==i||t[6]!==r||t[7]!==a?(e=e=>{let t=hi(e),n=r===e.path;return(0,$.jsx)(`li`,{children:(0,$.jsxs)(`button`,{type:`button`,onClick:()=>i(e.path),className:J(`flex w-full items-center gap-1.5 rounded-md px-2 py-1 text-left transition-colors`,n?`bg-interactive-selection text-interactive-selection-foreground`:`text-muted-foreground hover:bg-interactive-hover hover:text-foreground`),children:[(0,$.jsx)(St,{filePath:e.path,className:`size-3 flex-shrink-0`}),(0,$.jsx)(`span`,{className:`typography-code font-semibold w-3.5 text-center uppercase`,style:{color:t.color},title:a(t.descriptionKey),"aria-label":a(t.descriptionKey),children:t.code}),(0,$.jsx)(ot,{path:e.path,className:`min-w-0 flex-1 typography-code`,dirClassName:n?`text-interactive-selection-foreground`:`text-muted-foreground`,nameClassName:n?`text-interactive-selection-foreground`:`text-foreground`}),Di(e.insertions,e.deletions)]})},e.path)},t[5]=i,t[6]=r,t[7]=a,t[8]=e):e=t[8],o=n.map(e),t[0]=n,t[1]=i,t[2]=r,t[3]=a,t[4]=o}else o=t[4];let s;return t[9]===o?s=t[10]:(s=(0,$.jsx)(Ee,{outerClassName:`flex-1 min-h-0`,className:`px-2 py-2`,children:(0,$.jsx)(`ul`,{className:`flex flex-col gap-1`,children:o})}),t[9]=o,t[10]=s),s}),Ai=Q.memo(e=>{let t=(0,Sn.c)(20),{filePath:n,diff:r,renderSideBySide:i}=e,{t:a}=ee(),o=r.original.length>0,s=r.modified.length>0,c=i?`flex flex-row gap-6 items-start justify-center`:`flex flex-col gap-4 items-center`,l=i?`flex flex-col items-center gap-2 flex-1 min-w-0`:`flex flex-col items-center gap-2`,u;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(u={contain:`layout`},t[0]=u):u=t[0];let d;t[1]!==r.original||t[2]!==n||t[3]!==o||t[4]!==l||t[5]!==i||t[6]!==a?(d=o&&(0,$.jsxs)(`div`,{className:l,children:[(0,$.jsx)(`span`,{className:`typography-meta text-muted-foreground font-medium`,children:a(`diffView.image.original`)}),(0,$.jsx)(`img`,{src:r.original,alt:a(`diffView.image.originalAlt`,{path:n}),className:i?`max-w-full max-h-[70vh] object-contain`:`max-w-full object-contain`,style:{imageRendering:`auto`}})]}),t[1]=r.original,t[2]=n,t[3]=o,t[4]=l,t[5]=i,t[6]=a,t[7]=d):d=t[7];let f;t[8]!==r.modified||t[9]!==n||t[10]!==s||t[11]!==o||t[12]!==l||t[13]!==i||t[14]!==a?(f=s&&(0,$.jsxs)(`div`,{className:l,children:[(0,$.jsx)(`span`,{className:`typography-meta text-muted-foreground font-medium`,children:a(o?`diffView.image.modified`:`diffView.image.new`)}),(0,$.jsx)(`img`,{src:r.modified,alt:a(`diffView.image.modifiedAlt`,{path:n}),className:i?`max-w-full max-h-[70vh] object-contain`:`max-w-full object-contain`,style:{imageRendering:`auto`}})]}),t[8]=r.modified,t[9]=n,t[10]=s,t[11]=o,t[12]=l,t[13]=i,t[14]=a,t[15]=f):f=t[15];let p;return t[16]!==c||t[17]!==d||t[18]!==f?(p=(0,$.jsx)(`div`,{className:`w-full overflow-auto p-4`,style:u,children:(0,$.jsxs)(`div`,{className:c,children:[d,f]})}),t[16]=c,t[17]=d,t[18]=f,t[19]=p):p=t[19],p}),ji=Q.memo(e=>{let t=(0,Sn.c)(17),{filePath:n,diff:r,renderSideBySide:i,wrapLines:a,focusLine:o}=e,s;t[0]===n?s=t[1]:(s=Vt(n)||`text`,t[0]=n,t[1]=s);let c=s;if(r.isBinary){let e;return t[2]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,$.jsx)(di,{}),t[2]=e):e=t[2],e}if(zt(n)){let e;return t[3]!==r||t[4]!==n||t[5]!==i?(e=(0,$.jsx)(Ai,{filePath:n,diff:r,renderSideBySide:i}),t[3]=r,t[4]=n,t[5]=i,t[6]=e):e=t[6],e}let l;t[7]===Symbol.for(`react.memo_cache_sentinel`)?(l={contain:`layout`},t[7]=l):l=t[7];let u;return t[8]!==r.fileDiff||t[9]!==r.modified||t[10]!==r.original||t[11]!==n||t[12]!==o||t[13]!==c||t[14]!==i||t[15]!==a?(u=(0,$.jsx)(`div`,{className:`w-full`,style:l,children:(0,$.jsx)(Or,{original:r.original,modified:r.modified,fileDiff:r.fileDiff,language:c,fileName:n,renderSideBySide:i,wrapLines:a,focusLine:o,layout:`inline`,enableSelectionActions:!0})}),t[8]=r.fileDiff,t[9]=r.modified,t[10]=r.original,t[11]=n,t[12]=o,t[13]=c,t[14]=i,t[15]=a,t[16]=u):u=t[16],u}),Mi=Q.memo(e=>{let t=(0,Sn.c)(7),{filePath:n,staged:r,busyAction:i,disabled:a,onAction:o}=e,{t:s}=ee(),c;return t[0]!==i||t[1]!==a||t[2]!==n||t[3]!==o||t[4]!==r||t[5]!==s?(c=(0,$.jsx)(`div`,{className:`flex items-center gap-0.5 rounded-full border border-[var(--interactive-border)]/45 bg-[var(--surface-background)]/95 px-1 py-0.5 shadow-lg backdrop-blur-md`,children:r?(0,$.jsx)(Ni,{label:s(`gitView.changes.unstageFileAria`,{path:n}),icon:`arrow-go-back`,loading:i===`unstage`,disabled:a,onClick:()=>o(`unstage`)}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Ni,{label:s(`gitView.changes.revertFileAria`,{path:n}),icon:`arrow-go-back`,loading:i===`discard`,disabled:a,tone:`failure`,onClick:()=>o(`discard`)}),(0,$.jsx)(Ni,{label:s(`gitView.changes.stageFileAria`,{path:n}),icon:`add`,loading:i===`stage`,disabled:a,tone:`success`,onClick:()=>o(`stage`)})]})}),t[0]=i,t[1]=a,t[2]=n,t[3]=o,t[4]=r,t[5]=s,t[6]=c):c=t[6],c}),Ni=e=>{let t=(0,Sn.c)(14),{label:n,icon:r,loading:i,disabled:a,tone:o,onClick:s}=e,c=o===`failure`&&`text-[var(--status-error)] hover:text-[var(--status-error)]`,l=o===`success`&&`text-[var(--status-success)] hover:text-[var(--status-success)]`,u;t[0]!==c||t[1]!==l?(u=J(`h-6 w-6 rounded-none bg-transparent p-0 text-muted-foreground opacity-70 hover:bg-transparent hover:text-foreground hover:opacity-100`,c,l),t[0]=c,t[1]=l,t[2]=u):u=t[2];let d;t[3]===s?d=t[4]:(d=e=>{e.stopPropagation(),s()},t[3]=s,t[4]=d);let f;t[5]!==r||t[6]!==i?(f=i?(0,$.jsx)(Y,{name:`loader-4`,className:`size-3.5 animate-spin`}):(0,$.jsx)(Y,{name:r,className:r===`add`?`size-4`:`size-3.5`}),t[5]=r,t[6]=i,t[7]=f):f=t[7];let p;return t[8]!==a||t[9]!==n||t[10]!==u||t[11]!==d||t[12]!==f?(p=(0,$.jsx)(X,{variant:`ghost`,size:`sm`,className:u,disabled:a,title:n,"aria-label":n,onClick:d,children:f}),t[8]=a,t[9]=n,t[10]=u,t[11]=d,t[12]=f,t[13]=p):p=t[13],p},Pi=Q.memo(({directory:e,file:t,layout:n,wrapLines:r,isSelected:i,isExpanded:a,isMounted:o,onSelect:s,onExpandedChange:c,registerSectionRef:l,showOpenInEditorAction:u=!1,isOpeningInEditor:d=!1,onOpenInEditor:f,onOpenFile:p,staged:m=!1,loadFullFiles:h=!1,initialDiffData:g=null,focusLine:_=null,showFileActions:v=!0,disableGitFetch:y=!1,turnChangesRequest:b=null,loadTurnChangeFile:x=!1})=>{let{t:S}=ee(),{git:C}=Tt(),w=Ot(Q.useCallback(n=>n.directories.get(e)?.diffCache.get(t.path)??null,[e,t.path])),T=Ot(e=>e.setDiff),E=Ot(e=>e.fetchStatus),[D,O]=Q.useState(0),[k,A]=Q.useState(null),[j,M]=Q.useState(!1),[N,P]=Q.useState(null),[F,I]=Q.useState(!1),[te,ne]=Q.useState(null),[L,re]=Q.useState(null),ie=Q.useRef(null),R=Q.useRef(null),ae=Q.useMemo(()=>hi(t),[t]),z=n===`side-by-side`,B=h?`full`:`patch`,V=`${t.index}:${t.working_dir}:${t.insertions}:${t.deletions}`,oe=ri({sessionID:b?.sessionID??``,directory:b?.directory??``,messageID:b?.messageID??``,diffCount:b?.diffCount,file:t.path},{enabled:x&&!!b&&a&&o}),se=Q.useMemo(()=>{let e=oe.data?.diff;return e?typeof e.patch==`string`&&e.patch.length>0?Ei(t.path,e.patch,`patch`):typeof e.before==`string`&&e.before.length>0||typeof e.after==`string`&&e.after.length>0?{original:e.before??``,modified:e.after??``,contextMode:`full`}:null:null},[t.path,oe.data]),H=Q.useMemo(()=>{if(g)return g;if(se)return se;if(m)return L;if(te)return te;if(!w)return null;let e={original:w.original,modified:w.modified,isBinary:w.isBinary,contextMode:`full`};return Ti(e)?e:null},[w,g,te,m,L,se]),U=oe.error instanceof Error?oe.error.message:oe.error?String(oe.error):null,W=H?null:U??k,K=x&&oe.isPending||j,ce=H?.contextMode===B,le=Q.useCallback(e=>{R.current=e,l(t.path,e)},[t.path,l]),q=Q.useCallback(e=>{c(t.path,e)},[t.path,c]),ue=Q.useCallback(()=>{s(t.path)},[t.path,s]);Q.useEffect(()=>{if(!a||!o)return;if(y){ie.current=null,M(!1);return}if(!e||g){ie.current=null,M(!1);return}let n=`${e}::${t.path}::${m?`staged`:`unstaged`}::${V}::${B}::${D}`;if(ie.current===n)return;let r=!!(H&&ce);ie.current=n,A(null),r||M(!0);let i=!1,s=h?ci:li,c=zt(t.path)||h?C.getGitFileDiff(e,{path:t.path,staged:m}):C.getGitDiff(e,{path:t.path,staged:m,contextLines:s}),l=ai,u=new Promise((e,t)=>{setTimeout(()=>t(Error(`Timed out after ${l}ms`)),l)});return Promise.race([c,u]).then(n=>{if(!i){if(`diff`in n){let e=Ei(t.path,n.diff,B);m?re(e):ne(e)}else{let r={original:n.original??``,modified:n.modified??``,isBinary:n.isBinary,contextMode:`full`};m?re(r):(ne(r),T(e,t.path,r))}M(!1)}}).catch(e=>{if(i)return;let t=e instanceof Error?e.message:String(e);A(t),M(!1)}),()=>{i=!0,ie.current===n&&(ie.current=null)}},[B,H,ce,D,e,y,t.path,V,C,g,a,o,h,T,m]);let de=Q.useCallback(()=>{q(!a),ue()},[q,ue,a]),fe=Q.useCallback(async n=>{if(!(!e||N!==null)){P(n);try{n===`stage`?await C.stageGitFile(e,t.path):n===`unstage`?await C.unstageGitFile(e,t.path):await C.revertGitFile(e,t.path,{scope:`working`}),O(e=>e+1),await E(e,C)}catch(e){let t=n===`unstage`?`gitView.toast.unstageFileFailed`:n===`stage`?`gitView.toast.stageFileFailed`:`gitView.toast.revertFailed`;G.error(e instanceof Error?e.message:S(t))}finally{P(e=>e===n?null:e)}}},[e,E,t.path,N,C,S]);return(0,$.jsxs)(`div`,{ref:le,className:`scroll-mt-9 border-b border-[var(--interactive-border)]/40 last:border-b-0`,children:[(0,$.jsx)(`div`,{className:`sticky top-0 z-30 border-b border-[var(--interactive-border)]/35 bg-[var(--surface-elevated)]/90 backdrop-blur-md supports-[backdrop-filter]:bg-[var(--surface-elevated)]/80`,children:(0,$.jsxs)(`div`,{role:`button`,tabIndex:0,onClick:de,onKeyDown:e=>{e.target===e.currentTarget&&(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),de())},className:J(`cursor-pointer`,`group/header relative grid min-h-8 w-full min-w-0 grid-cols-[minmax(0,1fr)_auto] items-center gap-1.5 overflow-hidden px-2 py-1`,`bg-transparent`,`text-muted-foreground hover:text-foreground`,i?`bg-[var(--interactive-selection)]/35`:null),children:[(0,$.jsx)(`div`,{className:`absolute inset-0 pointer-events-none group-hover/header:bg-[var(--interactive-hover)]/50`}),(0,$.jsxs)(`div`,{className:`relative flex min-w-0 flex-1 items-center gap-1.5`,children:[(0,$.jsx)(`span`,{className:`flex size-4 items-center justify-center opacity-70 group-hover/header:opacity-100`,children:a?(0,$.jsx)(Y,{name:`arrow-down-s`,className:`size-3.5`}):(0,$.jsx)(Y,{name:`arrow-right-s`,className:`size-3.5`})}),(0,$.jsx)(`span`,{className:`typography-code font-semibold leading-none w-3.5 text-center uppercase`,style:{color:ae.color},title:S(ae.descriptionKey),"aria-label":S(ae.descriptionKey),children:ae.code}),(0,$.jsx)(`span`,{className:`min-w-0 flex-1 overflow-hidden typography-code`,title:t.path,children:(0,$.jsxs)(`span`,{className:`flex min-w-0 items-center gap-1.5`,children:[(0,$.jsx)(St,{filePath:t.path,className:`size-3 flex-shrink-0 align-middle`}),(0,$.jsx)(ot,{path:t.path,className:`min-w-0 flex-1 typography-code`})]})})]}),(0,$.jsxs)(`div`,{className:`relative flex shrink-0 items-center justify-self-end gap-1.5`,children:[Di(t.insertions,t.deletions),u&&f?(0,$.jsx)(X,{variant:`ghost`,size:`sm`,className:`h-5 w-5 p-0 opacity-70 hover:opacity-100`,title:S(`diffView.actions.openFileInEditorAtChange`),onClick:e=>{e.stopPropagation(),f(t.path,H)},disabled:d,children:d?(0,$.jsx)(Y,{name:`loader-4`,className:`size-3.5 animate-spin`}):(0,$.jsx)(Y,{name:`edit`,className:`size-3.5`})}):null,p?(0,$.jsx)(X,{variant:`ghost`,size:`sm`,className:`h-5 w-5 p-0 opacity-70 hover:opacity-100`,title:S(`diffView.actions.openFilePreview`),"aria-label":S(`diffView.actions.openFilePreview`),onClick:e=>{e.stopPropagation(),p(t.path)},children:(0,$.jsx)(Y,{name:`eye`,className:`size-3.5`})}):null]})]})}),a&&(0,$.jsxs)(`div`,{className:`relative bg-background overflow-hidden`,children:[!o&&!W?(0,$.jsx)(`div`,{className:`h-40 border border-border/40 bg-background/40`}):null,W?(0,$.jsxs)(`div`,{className:`flex flex-col items-center gap-2 px-4 py-8 text-sm text-muted-foreground`,children:[(0,$.jsx)(`div`,{className:`typography-ui-label font-semibold text-foreground`,children:S(`diffView.state.failedToLoadDiff`)}),(0,$.jsx)(`div`,{className:`typography-meta text-muted-foreground max-w-[32rem] text-center`,children:W}),(0,$.jsx)(`button`,{type:`button`,className:`typography-ui-label text-primary hover:underline`,onClick:()=>{if(x){oe.refetch();return}O(e=>e+1)},children:S(`diffView.actions.retry`)})]}):null,o&&K&&!H&&!W?(0,$.jsxs)(`div`,{className:`flex items-center justify-center gap-2 px-4 py-8 text-sm text-muted-foreground`,children:[(0,$.jsx)(Y,{name:`loader-4`,className:`size-4 animate-spin`}),S(`diffView.state.loadingDiff`)]}):null,o&&H&&!F&&t.insertions+t.deletions>oi?(0,$.jsxs)(`div`,{className:`flex flex-col items-center gap-2 px-4 py-8 text-sm text-muted-foreground`,children:[(0,$.jsx)(`div`,{className:`typography-ui-label font-semibold text-foreground`,children:S(`diffView.state.largeDiff`,{count:t.insertions+t.deletions})}),(0,$.jsx)(`div`,{className:`typography-meta text-muted-foreground`,children:S(`diffView.state.largeDiffDescription`)}),(0,$.jsx)(`button`,{type:`button`,className:`typography-ui-label text-primary hover:underline`,onClick:()=>I(!0),children:S(`diffView.actions.renderAnyway`)})]}):null,o&&H&&(F||t.insertions+t.deletions<=oi)?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(ji,{filePath:t.path,diff:H,renderSideBySide:z,wrapLines:r,focusLine:_}),v?(0,$.jsx)(`div`,{className:`pointer-events-none absolute bottom-3 right-3 z-20`,children:(0,$.jsx)(`div`,{className:`pointer-events-auto`,children:(0,$.jsx)(Mi,{filePath:t.path,staged:m,busyAction:N,disabled:N!==null,onAction:fe})})}):null]}):null]})]})}),Fi=({hideStackedFileSidebar:e=!1,stackedDefaultCollapsedAll:t=!1,pinSelectedFileHeaderToTopOnNavigate:n=!1,showOpenInEditorAction:r=!1,diffScope:i=`all`,turnMessageId:a=null,sessionId:o=null,directory:s=null,onDiffScopeChange:u,targetFilePath:d=null,targetLine:f=null,toolPatches:p=null,flushContent:m=!1,singleFileView:h=!1,preloadFullFiles:g=!1,navigationRequestKey:_})=>{let{t:v}=ee(),{git:y,files:b}=Tt(),x=Ht(),S=typeof s==`string`&&s.trim()?s.trim():x,{screenWidth:C,isMobile:w}=Ye(),T=At(S??null),E=jt(S??null),D=kt(S??null),O=Ot(e=>e.setActiveDirectory),k=Ot(e=>e.ensureStatus),A=Ot(e=>e.fetchStatus),j=Ot(e=>e.setDiff),[M,N]=Q.useState(null),[F,I]=Q.useState(!1),[te,ne]=Q.useState(null),[L,re]=Q.useState(null),[R,ae]=Q.useState(()=>new Set),[z,B]=Q.useState(()=>new Set),[V,oe]=Q.useState(g),[se,H]=Q.useState(0),[W,K]=Q.useState(!1),[ce,le]=Q.useState(!1),[q,de]=Q.useState(i);Q.useEffect(()=>{de(i)},[i]);let fe=c(e=>e.pendingDiffFile),pe=c(e=>e.pendingDiffStaged),he=c(e=>e.pendingDiffScope),ge=c(e=>e.pendingDiffLine),_e=c(e=>e.setPendingDiffFile),ve=c(e=>e.diffLayoutPreference),ye=c(e=>e.diffFileLayout),be=c(e=>e.setDiffFileLayout),xe=c(e=>e.diffWrapLines),Se=c(e=>e.setDiffWrapLines),Ce=c(e=>e.openContextFileAtLine),we=c(e=>e.openContextFile),Te=rt(),De=ue(e=>e.currentSessionId),Oe=typeof o==`string`&&o.trim()?o.trim():De,ke=me(Oe??``,S??void 0),Ne=xe,Pe=q===`staged`||q!==`working`&&null,Fe=Pe??F,Ie=w||C<=768,Le=!!Oe&&q!==`turn`&&!Ie&&!l(),Re=!e&&!Ie&&C>=1024,ze=Q.useRef(null),Be=Q.useRef(new Map),Ve=Q.useRef(null),He=Q.useRef(null),Ue=Q.useRef(!1),We=Q.useRef(null),Ge=Q.useRef(null),Ke=Q.useRef(null),qe=Q.useRef(null),Je=Q.useCallback(()=>{Ve.current=null,Ue.current=!1,re(null),He.current!==null&&(window.cancelAnimationFrame(He.current),He.current=null)},[]),Xe=Q.useCallback(e=>{ae(t=>{if(t.has(e))return t;let n=new Set(t);return n.add(e),n})},[]),Ze=Q.useMemo(()=>{let e=ke.length-1;if(a&&(e=ke.findIndex(e=>e.id===a),e<0))return{messageID:null,count:0,hasDiffs:!1,thinDiffs:[]};for(let t=e;t>=0;--t){let e=ke[t];if(e.role!==`user`)continue;let n=Ci(e.summary?.diffs),r=typeof e.summary?.diffCount==`number`&&Number.isFinite(e.summary.diffCount)?Math.max(0,Math.trunc(e.summary.diffCount)):n.length;return{messageID:typeof e.id==`string`&&e.id?e.id:null,count:r,hasDiffs:e.summary?.hasDiffs===!0||r>0||n.length>0,thinDiffs:n}}return{messageID:null,count:0,hasDiffs:!1,thinDiffs:[]}},[ke,a]),Qe=Q.useMemo(()=>Gr(p??[]),[p]),$e=Qe.length>0,et=Q.useMemo(()=>!Oe||!S||!Ze.messageID?null:{sessionID:Oe,directory:S,messageID:Ze.messageID,diffCount:Ze.count},[S,Oe,Ze.count,Ze.messageID]),tt=Q.useMemo(()=>$e?Qe:Ze.thinDiffs,[Qe,Ze.thinDiffs,$e]),nt=Q.useMemo(()=>{let e=new Map;for(let t of tt)if(t.file){if(typeof t.patch==`string`&&t.patch.length>0){e.set(t.file,Ei(t.file,t.patch,`patch`));continue}(typeof t.before==`string`&&t.before.length>0||typeof t.after==`string`&&t.after.length>0)&&e.set(t.file,{original:t.before??``,modified:t.after??``,contextMode:`full`})}return e},[tt]),at=Q.useMemo(()=>{if(q===`turn`)return tt.map(e=>({path:e.file??``,index:``,working_dir:wi(e.status),insertions:e.additions??0,deletions:e.deletions??0,isNew:e.status===`added`})).filter(e=>e.path).sort((e,t)=>e.path.localeCompare(t.path));if(!E?.files)return[];let e=E.diffStats??{},t=q===`staged`?_i:q===`working`?vi:()=>!0;return E.files.filter(t).map(t=>({...t,insertions:e[t.path]?.insertions??0,deletions:e[t.path]?.deletions??0,isNew:gi(t)})).sort((e,t)=>e.path.localeCompare(t.path))},[q,tt,E]),ot=Q.useMemo(()=>E?.files?E.files.filter(vi).length:0,[E]),st=Q.useMemo(()=>E?.files?E.files.filter(_i).length:0,[E]),ct=$e?tt.length:Ze.count,lt=Q.useMemo(()=>at.map(e=>e.path).join(`\0`),[at]),ut=Q.useMemo(()=>{if(!h)return at;let e=d?.trim()||M;return e?at.filter(t=>t.path===e):[]},[at,M,h,d]);Q.useEffect(()=>{let e=lt?lt.split(`\0`):[],n=new Set(e),r=`${S??``}:${q}:${a??``}:${t?`collapsed`:`default`}`,i=p!==null&&Ke.current!==p,o=Ge.current!==r||i;Ge.current=r,Ke.current=p,ae(r=>{if(o){let n=t||q===`turn`&&!$e?0:ui(e.length);return new Set(e.slice(0,n))}let i=!1,a=new Set;for(let e of r){if(!n.has(e)){i=!0;continue}a.add(e)}return i?a:r}),B(e=>{if(o)return new Set;let t=!1,r=new Set;for(let i of e){if(!n.has(i)){t=!0;continue}r.add(i)}return t?r:e})},[q,lt,S,t,p,a,$e]);let Z=Q.useCallback(()=>{We.current=null;let e=ze.current;if(!e)return;let t=e.getBoundingClientRect(),n=t.top-si,r=t.bottom+si,i={};for(let[e,t]of Be.current){if(!t||!R.has(e))continue;let a=t.getBoundingClientRect();a.bottom<n||a.top>r||(i[e]=!0)}B(e=>{let t=!1,n=new Set(e);for(let e of Object.keys(i))n.has(e)||(n.add(e),t=!0);return t?n:e})},[R]),dt=Q.useCallback(()=>{typeof window>`u`||We.current===null&&(We.current=window.requestAnimationFrame(Z))},[Z]);Q.useEffect(()=>{let e=ze.current;if(e)return dt(),e.addEventListener(`scroll`,dt,{passive:!0}),window.addEventListener(`resize`,dt),()=>{e.removeEventListener(`scroll`,dt),window.removeEventListener(`resize`,dt),We.current!==null&&(window.cancelAnimationFrame(We.current),We.current=null)}},[at,R,dt]);let ft=Q.useCallback(e=>{let t=ye[e.path];if(t)return t;if(ve===`inline`)return`inline`;if(ve===`side-by-side`)return`side-by-side`;let n=C<ii;return e.isNew||n?`inline`:`side-by-side`},[ye,ve,C]),pt=Q.useMemo(()=>ut.length===0?null:ut.every(e=>ft(e)===`side-by-side`)?`side-by-side`:`inline`,[ft,ut]);Q.useEffect(()=>{S&&(O(S),k(S,y))},[S,O,k,y]),Q.useEffect(()=>{if(S)return U.onGitRefreshHint(e=>{bi(e.directory)===bi(S)&&A(S,y)})},[S,A,y]),Q.useEffect(()=>{q!==`all`&&!he||fe&&(he&&de(he),N(fe),I(he===`staged`||!he&&pe),ne(ge),_e(null),Ue.current=!0,Ve.current=fe,Xe(fe),H(e=>e+1))},[q,Xe,fe,ge,he,pe,_e]),Q.useEffect(()=>{if(q===`all`)return;let e=d?.trim();if(!e)return;Xe(e),N(e),I(q===`staged`),ne(f);let t=Kr({scope:q,navigationRequestKey:_,targetFilePath:e,targetLine:f}),n=at.some(t=>t.path===e);qr(qe.current,t,n)&&(qe.current=t,Ue.current=!0,Ve.current=e,H(e=>e+1))},[q,at,Xe,_,d,f]),Q.useEffect(()=>{M&&(at.some(e=>e.path===M)||(N(null),I(!1)))},[at,M]);let mt=Q.useCallback((e,t)=>{let n=Be.current;t?n.set(e,t):n.delete(e),dt()},[dt]),ht=Q.useCallback((e,t)=>{Je(),ae(n=>{if(t===n.has(e))return n;let r=new Set(n);return t?r.add(e):r.delete(e),r}),t||B(t=>{if(!t.has(e))return t;let n=new Set(t);return n.delete(e),n}),dt()},[Je,dt]),gt=Q.useCallback(()=>{Je(),ae(e=>e.size>0?new Set:new Set(at.map(e=>e.path))),B(new Set),dt()},[Je,at,dt]),_t=Q.useCallback(async e=>{if(!De)return;let t=ue.getState().getDirectoryForSession(De)||S||``;if(!t){G.error(v(`diffView.reviewDialog.toast.noSessionDirectory`));return}le(!0);try{await ie({originalSessionID:De,directory:t,providerID:e.providerID,modelID:e.modelID,agent:e.agent||void 0,variant:e.variant||void 0,generateHandoff:e.generateHandoff,returnAfterHandoffRequest:e.generateHandoff,autoReview:e.autoReview}),K(!1)}catch(e){console.error(`[review-flow] failed to start review flow`,e),G.error(e instanceof Error?e.message:v(`diffView.reviewDialog.toast.startFailed`))}finally{le(!1)}},[De,S,v]),vt=Q.useCallback(e=>{let t=Be.current.get(e),n=ze.current;if(!t||!n)return!1;let r=n.getBoundingClientRect(),i=t.getBoundingClientRect().top-r.top,a=Math.max(0,n.scrollHeight-n.clientHeight);return n.scrollTop=Math.min(a,Math.max(0,n.scrollTop+i)),!0},[]);Q.useEffect(()=>{if(!Ve.current)return;let e=0,t=!1,r=()=>{t||(t=!0,Ve.current=null,Ue.current=!1,re(null),He.current!==null&&(window.cancelAnimationFrame(He.current),He.current=null))},i=()=>{if(t){He.current=null;return}let a=Ve.current;if(!a){r(),He.current=null;return}if(!vt(a)){e+=1,e<20?He.current=window.requestAnimationFrame(i):(r(),He.current=null);return}n&&Ue.current&&re(a),r()};return He.current=window.requestAnimationFrame(i),()=>{t=!0,He.current!==null&&(window.cancelAnimationFrame(He.current),He.current=null)}},[n,se,vt]);let yt=Q.useCallback(e=>{},[]),bt=Q.useCallback(e=>{Je(),N(e),I(!1),Ue.current=!0,Ve.current=e,Xe(e),H(e=>e+1),vt(e)},[Je,Xe,vt]),xt=Q.useCallback(e=>{let t=e===`side-by-side`?`side-by-side`:`inline`;ut.forEach(e=>{be(e.path,t)})},[be,ut]),[St,Ct]=Q.useState(null),wt=Q.useCallback(async(e,t)=>{if(!(!S||!e)){Ct(e);try{let n=null;if(t?.patch&&!t.isBinary&&!zt(e)?n=Wr(t.patch):t&&t.contextMode===`full`&&!t.isBinary&&!zt(e)&&(n=xi(t.original,t.modified)),n===null)try{n=Wr((await y.getGitDiff(S,{path:e,staged:Fe,contextLines:3})).diff)}catch{n=null}let r=t;if(n===null||!r){let t=await y.getGitFileDiff(S,{path:e,staged:Fe});r={original:t.original??``,modified:t.modified??``,isBinary:t.isBinary},Fe||j(S,e,r)}let i=n??(r.isBinary||zt(e)?1:xi(r.original,r.modified)),a=yi(S,e),o=await Pr(b,a);if(!o.ok){G.error(Fr(o.reason));return}Ce(S,a,i,1)}finally{Ct(t=>t===e?null:t)}}},[Fe,S,b,y,Ce,j]),Et=P(e=>{if(!S||!e)return;let t=yi(S,e);if(Te){Te.openFile({path:t});return}Pr(b,t).then(e=>{if(!e.ok){G.error(Fr(e.reason));return}we(S,t)})});return(0,$.jsxs)(`div`,{className:`flex h-full flex-col overflow-hidden bg-background`,children:[h?null:(0,$.jsxs)(`div`,{className:`@container/diff-toolbar flex min-w-0 items-center gap-1.5 px-2 py-1.5 bg-background`,children:[!w&&(q===`working`||q===`staged`||q===`turn`?(0,$.jsx)(Oi,{scope:q,workingCount:ot,stagedCount:st,turnCount:ct,onScopeChange:e=>{de(e),u?.(e)}}):(0,$.jsx)(`div`,{className:`flex items-center gap-1 rounded-md px-2 py-1 text-muted-foreground shrink-0`,children:(0,$.jsx)(`span`,{className:`typography-code font-semibold text-foreground`,children:D&&!E?v(`diffView.state.loadingChanges`):ut.length===1?v(`diffView.summary.changedFilesSingle`,{count:ut.length}):v(`diffView.summary.changedFilesPlural`,{count:ut.length})})})),!h&&at.length>0&&(q!==`turn`||$e)&&(0,$.jsxs)(X,{variant:`ghost`,size:`sm`,onClick:gt,className:J(`diff-toolbar__expand-button h-7 flex-shrink-0 gap-1 px-1.5 text-muted-foreground hover:text-foreground`,`ml-auto`),title:R.size>0?v(`diffView.actions.collapseAll`):v(`diffView.actions.expandAll`),children:[(0,$.jsx)(Y,{name:`expand-up-down`,className:`size-4`}),(0,$.jsx)(`span`,{className:`diff-toolbar__expand-label typography-code`,children:R.size>0?v(`diffView.actions.collapseAll`):v(`diffView.actions.expandAll`)})]}),at.length>0&&Le&&(0,$.jsxs)(X,{variant:`default`,size:`sm`,onClick:()=>K(!0),disabled:ce,className:`diff-toolbar__review-button h-7 flex-shrink-0 gap-1.5 px-2`,"aria-label":v(`diffView.actions.reviewAria`),children:[ce?(0,$.jsx)(Y,{name:`loader-4`,className:`size-4 animate-spin`}):(0,$.jsx)(Y,{name:`search-eye`,className:`size-4`}),(0,$.jsx)(`span`,{className:`diff-toolbar__review-label typography-code`,children:v(`diffView.actions.review`)})]}),at.length>0&&(0,$.jsxs)(Me,{children:[(0,$.jsx)(Ae,{asChild:!0,children:(0,$.jsx)(X,{variant:`ghost`,size:`sm`,onClick:()=>oe(e=>!e),"aria-pressed":V,"aria-label":v(V?`diffView.actions.disableFullFiles`:`diffView.actions.loadFullFiles`),className:J(`h-7 w-7 flex-shrink-0 p-0 text-muted-foreground hover:text-foreground`,V&&`bg-interactive-selection text-interactive-selection-foreground`),children:(0,$.jsx)(Y,{name:`file-download`,className:`size-4`})})}),(0,$.jsx)(je,{children:(0,$.jsx)(`p`,{children:v(V?`diffView.actions.disableFullFiles`:`diffView.actions.loadFullFiles`)})})]}),at.length>0&&(0,$.jsx)(X,{variant:`ghost`,size:`sm`,onClick:()=>Se(!xe),className:J(`h-5 w-5 p-0 transition-opacity`,Ne?`text-foreground opacity-100`:`text-muted-foreground opacity-60 hover:opacity-100`),title:v(Ne?`diffView.actions.disableLineWrap`:`diffView.actions.enableLineWrap`),children:(0,$.jsx)(Y,{name:`text-wrap`,className:`size-4`})}),pt&&(0,$.jsx)(Gt,{mode:pt===`side-by-side`?`side-by-side`:`unified`,onModeChange:xt})]}),(0,$.jsx)(it,{open:W,onOpenChange:K,projectDirectory:S??null,submitting:ce,onConfirm:_t}),S?q!==`turn`&&D&&!E?(0,$.jsxs)(`div`,{className:`flex flex-1 items-center justify-center gap-2 text-sm text-muted-foreground`,children:[(0,$.jsx)(Y,{name:`loader-4`,className:`size-4 animate-spin`}),v(`diffView.state.loadingRepositoryStatus`)]}):q!==`turn`&&T===!1?(0,$.jsx)(`div`,{className:`flex flex-1 items-center justify-center text-sm text-muted-foreground`,children:v(`diffView.state.notGitRepository`)}):ut.length===0?(0,$.jsx)(`div`,{className:`flex flex-1 items-center justify-center text-sm text-muted-foreground`,children:v(q===`turn`?`diffView.state.noLastTurnChanges`:`diffView.state.cleanWorkingTree`)}):(()=>{if(!S)return null;let e=e=>Pe===null?F&&e===M:Pe;return(0,$.jsxs)(`div`,{className:J(`flex min-w-0 flex-1 min-h-0 h-full`,m?`gap-0`:`gap-3 px-3 pb-3 pt-2`),children:[Re&&(0,$.jsxs)(`section`,{className:`hidden lg:flex w-72 flex-col rounded-xl border border-border/60 bg-background/70 overflow-hidden`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between px-3 py-1.5 border-b border-border/40`,children:[(0,$.jsx)(`span`,{className:`typography-code font-semibold text-foreground`,children:v(`diffView.section.files`)}),(0,$.jsx)(`span`,{className:`typography-code text-muted-foreground`,children:at.length})]}),(0,$.jsx)(ki,{changedFiles:at,selectedFile:null,onSelectFile:bt})]}),(0,$.jsx)(`div`,{className:`relative flex-1 min-w-0 min-h-0 h-full`,children:(0,$.jsx)(Ee,{ref:ze,outerClassName:`min-h-0 h-full`,className:`[overflow-anchor:none] pb-16 pwa-overlay-scroll`,disableHorizontal:!0,observeMutations:!1,preventOverscroll:!0,"data-diff-virtual-root":!0,children:(0,$.jsx)(`div`,{className:`flex flex-col [overflow-anchor:none]`,"data-diff-virtual-content":!0,children:ut.map(t=>(0,$.jsx)(Pi,{directory:S,file:t,layout:ft(t),wrapLines:Ne,isSelected:!1,isExpanded:R.has(t.path),isMounted:z.has(t.path)||t.path===L||h&&ut.length===1,onSelect:yt,onExpandedChange:ht,registerSectionRef:mt,showOpenInEditorAction:r&&q!==`turn`,isOpeningInEditor:St===t.path,onOpenInEditor:(e,t)=>{wt(e,t)},onOpenFile:Et,staged:e(t.path),loadFullFiles:V,initialDiffData:q===`turn`?nt.get(t.path)??null:null,focusLine:t.path===(d?.trim()||M)?f??te:null,showFileActions:q!==`turn`,disableGitFetch:q===`turn`,turnChangesRequest:et,loadTurnChangeFile:q===`turn`&&!$e},t.path))})})})]})})():(0,$.jsx)(`div`,{className:`flex flex-1 items-center justify-center text-sm text-muted-foreground`,children:v(`diffView.state.selectSessionDirectory`)})]})},Ii=(e,t)=>{if(!t)return null;let n=Number.parseInt(e.trim(),10);return!Number.isFinite(n)||n<1?null:Math.min(n,t.state.doc.lines)},Li=(e,t)=>{let n=e.state.doc.lineAt(t.main.head);return{lineNumber:n.number,character:t.main.head-n.from+1,selection:t}},Ri=(e,t,n)=>{let r=e.state.doc.line(t),i=Math.max(1,Math.min(n,r.length+1)),a=r.from+i-1;e.dispatch({selection:N.cursor(a),effects:M.scrollIntoView(a,{y:`center`})})};function zi({open:e,onOpenChange:t,view:n,variant:r=`overlay`}){let{t:i}=ee(),[a,o]=Q.useState(``),s=Q.useRef(null),c=Q.useRef(!1),l=Q.useRef(null),u=Q.useRef(null),d=Q.useMemo(()=>Ii(a,n),[a,n]);Q.useEffect(()=>{!e||!n||(c.current=!1,s.current=Li(n,n.state.selection),o(``))},[e,n]),Q.useEffect(()=>{e&&window.requestAnimationFrame(()=>{u.current?.focus(),u.current?.select()})},[e]),Q.useEffect(()=>{if(!(!e||!n||!s.current)){if(d===null){let{selection:e}=s.current;n.dispatch({selection:e,effects:M.scrollIntoView(e.main.from,{y:`center`})});return}Ri(n,d,s.current.character)}},[d,e,n]);let f=Q.useCallback(()=>{if(!n||c.current||!s.current)return;let{selection:e}=s.current;n.dispatch({selection:e,effects:M.scrollIntoView(e.main.from,{y:`center`})})},[n]),p=Q.useCallback(e=>{e||f(),t(e)},[t,f]),m=Q.useCallback(()=>{!n||d===null||!s.current||(c.current=!0,Ri(n,d,s.current.character),t(!1),n.focus())},[d,t,n]);Q.useEffect(()=>{if(!e)return;let t=e=>{let t=l.current,n=e.target;!t||!(n instanceof Node)||t.contains(n)||p(!1)},n=e=>{e.key===`Escape`&&(e.preventDefault(),p(!1))};return document.addEventListener(`pointerdown`,t,!0),document.addEventListener(`keydown`,n,!0),()=>{document.removeEventListener(`pointerdown`,t,!0),document.removeEventListener(`keydown`,n,!0)}},[p,e,r]);let h=Q.useMemo(()=>{if(!n)return i(`goToLineDialog.helper.editorUnavailable`);if(d===null){let e=s.current??Li(n,n.state.selection);return i(`goToLineDialog.helper.currentLineRange`,{current:e.lineNumber,max:n.state.doc.lines})}return i(`goToLineDialog.helper.goToLine`,{line:d})},[d,i,n]);return r===`inline`?e?(0,$.jsxs)(`div`,{ref:l,className:`ml-1 flex h-6 items-center gap-1`,children:[(0,$.jsx)(ke,{ref:u,type:`number`,min:1,step:1,inputMode:`numeric`,value:a,onChange:e=>o(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),m())},placeholder:i(`goToLineDialog.field.linePlaceholderShort`),className:`h-6 w-20 rounded-md border-border/70 bg-transparent px-2 typography-meta`}),(0,$.jsx)(X,{variant:`outline`,size:`xs`,onClick:m,disabled:!n||d===null,className:`h-6 px-2`,children:i(`goToLineDialog.actions.go`)})]}):null:(0,$.jsx)(`div`,{ref:l,className:J(`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`,e?`pointer-events-auto translate-y-0 opacity-100`:`pointer-events-none -translate-y-1 opacity-0`),children:(0,$.jsxs)(`div`,{className:`min-w-0`,children:[(0,$.jsx)(ke,{ref:u,type:`number`,min:1,step:1,inputMode:`numeric`,value:a,onChange:e=>o(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),m())},placeholder:i(`goToLineDialog.field.linePlaceholder`),className:`h-8 w-full rounded-md border-border/70 bg-background/60 typography-ui-label`}),(0,$.jsx)(`div`,{className:`mt-2 rounded-md bg-primary/15 px-3 py-1.5 typography-ui-label text-foreground/95`,children:h})]})})}var Bi=(e,t)=>{let n=Ze(t,e);return!n||n===`.`||n===t?0:n.split(`/`).filter(Boolean).length},Vi=(e,t,n=10)=>{let r=$e(e);if(!r||n<1)return[];let i=new Set,a=[];for(let e of Object.values(t))if(e)for(let t of e){if(t.type!==`directory`)continue;let e=$e(t.path);if(!e||i.has(e))continue;let o=Bi(r,e);o<1||o>n||(i.add(e),a.push(e))}return a},Hi=e=>e.some(e=>!!$e(e)),Ui=(e,t)=>{let n=new Set(t.map(e=>$e(e)).filter(Boolean));return e.filter(e=>!n.has(e))},Wi=(e,t,n)=>t.length===0?e.length===0:Ui(e,t).length>0?!1:t.every(e=>n.has($e(e))),Gi=[{id:`finder`,label:`Finder`,appName:`Finder`},{id:`terminal`,label:`Terminal`,appName:`Terminal`},{id:`iterm2`,label:`iTerm2`,appName:`iTerm`},{id:`ghostty`,label:`Ghostty`,appName:`Ghostty`},{id:`vscode`,label:`VS Code`,appName:`Visual Studio Code`},{id:`vscode-insiders`,label:`VS Code Insiders`,appName:`Visual Studio Code - Insiders`},{id:`intellij`,label:`IntelliJ`,appName:`IntelliJ IDEA`},{id:`visual-studio`,label:`Visual Studio`,appName:`Visual Studio`},{id:`cursor`,label:`Cursor`,appName:`Cursor`},{id:`android-studio`,label:`Android Studio`,appName:`Android Studio`},{id:`pycharm`,label:`PyCharm`,appName:`PyCharm`},{id:`xcode`,label:`Xcode`,appName:`Xcode`},{id:`sublime-text`,label:`Sublime`,appName:`Sublime Text`},{id:`webstorm`,label:`WebStorm`,appName:`WebStorm`},{id:`rider`,label:`Rider`,appName:`Rider`},{id:`zed`,label:`Zed`,appName:`Zed`},{id:`phpstorm`,label:`PhpStorm`,appName:`PhpStorm`},{id:`eclipse`,label:`Eclipse`,appName:`Eclipse`},{id:`windsurf`,label:`Windsurf`,appName:`Windsurf`},{id:`vscodium`,label:`VSCodium`,appName:`VSCodium`},{id:`rustrover`,label:`RustRover`,appName:`RustRover`},{id:`kiro`,label:`Kiro`,appName:`Kiro`},{id:`antigravity`,label:`Antigravity`,appName:`Antigravity`},{id:`trae`,label:`Trae`,appName:`Trae`}],Ki=`finder`,qi=new Set([`finder`,`terminal`]),Ji=e=>typeof window<`u`&&window.__OPENCHAMBER_PLATFORM__===`win32`&&e.id===`finder`?{...e,label:`Explorer`,appName:`File Explorer`}:e,Yi=e=>{if(!e)return null;let t=Gi.find(t=>t.id===e)??null;return t?Ji(t):null},Xi=()=>Gi.filter(e=>qi.has(e.id)).map(e=>({...Ji(e)})),Zi=()=>{if(typeof window>`u`)return Ki;let e=window.localStorage.getItem(`openInAppId`);return e&&Yi(e)?e:Ki},Qi=!1,$i=!1,ea=!1,ta=0,na=null,ra=()=>{na&&=(clearTimeout(na),null)},ia=S()((e,t)=>({selectedAppId:Zi(),availableApps:Xi(),hasLoadedApps:!1,isCacheStale:!1,isScanning:!1,initialize:()=>{if(Qi||typeof window>`u`)return;Qi=!0;let n=(t,n=!0)=>{if(!Array.isArray(t)||t.length===0){e({availableApps:Xi(),hasLoadedApps:n});return}let r=new Set(t.map(e=>e.name)),i=new Map(t.map(e=>[e.name,e.iconDataUrl??void 0]));e({availableApps:Gi.filter(e=>r.has(e.appName)||qi.has(e.id)).map(e=>({...Ji(e),iconDataUrl:i.get(e.appName)})),hasLoadedApps:!0})},r=async i=>{if(!f()||!p()||$i||t().hasLoadedApps&&!i)return;let a=Gi.map(e=>e.appName);ra(),i&&e({hasLoadedApps:!1}),$i=!0,ea=!1,e({isScanning:!0});try{let{apps:t,success:o,hasCache:s,isCacheStale:c}=await d(a,i),l=o&&!s&&t.length===0&&ta<3;if(e({isCacheStale:s?c:!1}),n(t,o?!l:!1),o){if(l){let e=[800,1600,3200][ta]??3200;ta+=1,ea=!0,na=setTimeout(()=>{r()},e);return}ta=0,ea=!1;return}if(ta<3){let e=[1e3,3e3,7e3][ta]??7e3;ta+=1,ea=!0,na=setTimeout(()=>{r()},e)}}finally{$i=!1,ea||e({isScanning:!1})}};r(),window.addEventListener(`openchamber:settings-synced`,t=>{let n=t.detail,r=n&&typeof n.openInAppId==`string`&&n.openInAppId.length>0&&Yi(n.openInAppId)?n.openInAppId:null;r&&(window.localStorage.setItem(`openInAppId`,r),e({selectedAppId:r}))}),window.addEventListener(`openchamber:app-ready`,()=>{r()}),window.addEventListener(`openchamber:installed-apps-updated`,t=>{let r=t.detail;Array.isArray(r)&&(ta=3,ea=!1,e({isScanning:!1,isCacheStale:!1}),n(r))}),window.__openchamberAppReady&&r(),window.setTimeout(()=>{t().hasLoadedApps||r()},5e3)},loadInstalledApps:async n=>{if(Qi||t().initialize(),!f()||!p()||$i||t().hasLoadedApps&&!n)return;let r=Gi.map(e=>e.appName);ra(),n&&e({hasLoadedApps:!1}),$i=!0,ea=!1,e({isScanning:!0});try{let{apps:t,hasCache:i,isCacheStale:a}=await d(r,n),o=new Set(t.map(e=>e.name)),s=new Map(t.map(e=>[e.name,e.iconDataUrl??void 0])),c=Gi.filter(e=>o.has(e.appName)||qi.has(e.id)).map(e=>({...e,iconDataUrl:s.get(e.appName)}));e({availableApps:c.length>0?c:Xi(),hasLoadedApps:c.length>0,isCacheStale:i?a:!1})}finally{$i=!1,ea||e({isScanning:!1})}},selectApp:async t=>{Yi(t)&&(e({selectedAppId:t}),typeof window<`u`&&window.localStorage.setItem(`openInAppId`,t),await y({openInAppId:t}))}})),aa=Ft(()=>O(()=>import(`./ToolOutputDialog-nSZ8-Kjx.js`),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45]))),oa=e=>{let t=la(e);if(!t)return``;if(t===`/`||/^[A-Za-z]:\/$/.test(t))return t;let n=t.lastIndexOf(`/`);if(n<0)return t;if(n===0)return`/`;let r=t.slice(0,n);return/^[A-Za-z]:$/.test(r)?`${r}/`:r},sa=e=>{let t=(0,Sn.c)(8),{label:n,iconDataUrl:r}=e,[i,a]=Q.useState(!1),o;t[0]===n?o=t[1]:(o=n.trim().slice(0,1).toUpperCase()||`?`,t[0]=n,t[1]=o);let s=o;if(r&&!i){let e;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(e=()=>a(!0),t[2]=e):e=t[2];let n;return t[3]===r?n=t[4]:(n=(0,$.jsx)(`img`,{src:r,alt:``,className:`size-4 rounded-sm`,onError:e}),t[3]=r,t[4]=n),n}let c;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(c=J(`size-4 rounded-sm flex items-center justify-center`,`bg-[var(--surface-muted)] text-[9px] font-medium text-muted-foreground`),t[5]=c):c=t[5];let l;return t[6]===s?l=t[7]:(l=(0,$.jsx)(`span`,{className:c,children:s}),t[6]=s,t[7]=l),l},ca=e=>e.slice().sort((e,t)=>e.type===t.type?e.name.localeCompare(t.name):e.type===`directory`?-1:1),la=e=>{if(!e)return``;let t=e.replace(/\\/g,`/`),n=t.startsWith(`//`),r=t.replace(/\/+/g,`/`);n&&!r.startsWith(`//`)&&(r=`/${r}`);let i=r===`/`,a=/^[A-Za-z]:\/$/.test(r);return!i&&!a&&(r=r.replace(/\/+$/,``)),r},ua=e=>e.startsWith(`/`)||e.startsWith(`//`)||/^[A-Za-z]:\//.test(e),da=e=>/^[A-Za-z]:\//.test(e)?e.toLowerCase():e,fa=(e,t)=>{let n=la(t),r=la(e);if(!n||!r)return!1;let i=da(n),a=da(r);return a===i||a.startsWith(`${i}/`)},pa=(e,t)=>{let n=la(t),r=la(e);if(!fa(r,n))return[];let i=r.slice(n.length).replace(/^\//,``).split(`/`),a=[],o=n;for(let e=0;e<i.length-1;e++)o=o?`${o}/${i[e]}`:i[e],a.push(o);return a},ma=(e,t)=>{if(!t)return``;let n=la(t);if(!e||!fa(n,e))return n;let r=n.slice(e.length);return r.startsWith(`/`)?r.slice(1):r},ha=new Set([`node_modules`]),ga=e=>{let t=(0,Sn.c)(3),{status:n}=e,r;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(r={open:`var(--status-info)`,modified:`var(--status-warning)`,"git-modified":`var(--status-warning)`,"git-added":`var(--status-success)`,"git-deleted":`var(--status-error)`},t[0]=r):r=t[0];let i=r[n],a;return t[1]===i?a=t[2]:(a=(0,$.jsx)(`span`,{className:`size-2 rounded-full`,style:{backgroundColor:i}}),t[1]=i,t[2]=a),a},_a=e=>{let t=(0,Sn.c)(11),{name:n}=e,r=Q.useRef(null),i=Q.useRef(null),[a,o]=Q.useState(!1),s;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(s=()=>{let e=r.current,t=i.current;if(!e||!t)return;let n=()=>{o(t.scrollWidth>e.clientWidth+1)};n();let a=new ResizeObserver(n);return a.observe(e),a.observe(t),()=>{a.disconnect()}},t[0]=s):s=t[0];let c;t[1]===n?c=t[2]:(c=[n],t[1]=n,t[2]=c),Q.useLayoutEffect(s,c);let l;t[3]===n?l=t[4]:(l=(0,$.jsx)(`span`,{ref:i,"aria-hidden":`true`,className:`invisible absolute whitespace-nowrap`,children:n}),t[3]=n,t[4]=l);let u;t[5]!==n||t[6]!==a?(u=a?(0,$.jsxs)(`span`,{className:`open-file-name-marquee-track`,children:[(0,$.jsx)(`span`,{className:`open-file-name-marquee-item`,children:n}),(0,$.jsx)(`span`,{className:`open-file-name-marquee-item`,"aria-hidden":`true`,children:n})]}):(0,$.jsx)(`span`,{className:`block min-w-0 truncate`,children:n}),t[5]=n,t[6]=a,t[7]=u):u=t[7];let d;return t[8]!==l||t[9]!==u?(d=(0,$.jsxs)(`span`,{ref:r,className:`relative block min-w-0 flex-1 overflow-hidden whitespace-nowrap`,children:[l,u]}),t[8]=l,t[9]=u,t[10]=d):d=t[10],d},va=e=>ha.has(e),ya=e=>{let t=la(e);return t===`node_modules`||t.endsWith(`/node_modules`)||t.includes(`/node_modules/`)},ba=e=>{let t=(e instanceof Error?e.message:String(e??``)).toLowerCase();return t.includes(`is a directory`)||t.includes(`eisdir`)},xa=e=>{let t=(e instanceof Error?e.message:String(e??``)).toLowerCase();return t.includes(`file not found`)||t.includes(`enoent`)||t.includes(`no such file`)||t.includes(`does not exist`)},Sa=2e5,Ca=`openchamber:files:auto-save-enabled`,wa=e=>{let t=0,n=0;for(let r=0;r<e.length;r+=1)e.charCodeAt(r)===10&&(r>0&&e.charCodeAt(r-1)===13?t+=1:n+=1);return t>n?`\r
|
|
145
|
+
`),i=Math.min(n.length,r.length);for(let e=0;e<i;e+=1)if(n[e]!==r[e])return e+1;return r.length>n.length?n.length+1:n.length>r.length?Math.max(1,r.length):1},Si=e=>/^Binary files .+ differ$/m.test(e)||/^GIT binary patch$/m.test(e),Ci=e=>Array.isArray(e)?e.filter(e=>!e||typeof e!=`object`?!1:typeof e.file==`string`):[],wi=e=>e===`added`?`A`:e===`deleted`?`D`:`M`,Ti=e=>e.isBinary||typeof e.patch==`string`&&e.patch.length>0||e.fileDiff?!0:e.original.length>0||e.modified.length>0,Ei=(e,t,n)=>Si(t)?{original:``,modified:``,isBinary:!0,patch:t,contextMode:n}:{original:``,modified:``,patch:t,fileDiff:zr(e,t),contextMode:n},Di=(e,t,n)=>{let r=e??0,i=t??0;return!r&&!i?null:(0,$.jsxs)(`span`,{className:J(`typography-code flex items-center gap-1 whitespace-nowrap`,n?.shrink?`min-w-0 overflow-hidden`:`flex-shrink-0`,n?.className),children:[r?(0,$.jsxs)(`span`,{style:{color:`var(--status-success)`},children:[`+`,r]}):null,i?(0,$.jsxs)(`span`,{style:{color:`var(--status-error)`},children:[`-`,i]}):null]})},Oi=Q.memo(e=>{let t=(0,Sn.c)(53),{scope:n,workingCount:r,stagedCount:i,turnCount:a,onScopeChange:o}=e,{t:s}=ee(),[c,l]=Q.useState(!1),u=n===`staged`?i:n===`turn`?a:r,d;t[0]!==n||t[1]!==s?(d=s(n===`staged`?`diffView.scope.staged`:n===`turn`?`diffView.scope.lastTurn`:`diffView.scope.changed`),t[0]=n,t[1]=s,t[2]=d):d=t[2];let f=d,p;t[3]===s?p=t[4]:(p=s(`diffView.scope.selectorAria`),t[3]=s,t[4]=p);let m;t[5]===u?m=t[6]:(m=(0,$.jsxs)(`span`,{className:`diff-toolbar__scope-count`,children:[`: `,u]}),t[5]=u,t[6]=m);let h;t[7]!==f||t[8]!==m?(h=(0,$.jsxs)(`span`,{className:`whitespace-nowrap`,children:[f,m]}),t[7]=f,t[8]=m,t[9]=h):h=t[9];let g;t[10]===Symbol.for(`react.memo_cache_sentinel`)?(g=(0,$.jsx)(Y,{name:`arrow-down-s`,className:`size-4 flex-shrink-0 opacity-60`}),t[10]=g):g=t[10];let _;t[11]!==p||t[12]!==h?(_=(0,$.jsx)(Ke,{asChild:!0,children:(0,$.jsxs)(`button`,{type:`button`,className:`flex h-7 flex-shrink-0 items-center gap-1.5 rounded-md px-2 typography-code font-semibold text-foreground outline-none hover:bg-interactive-hover focus-visible:ring-2 focus-visible:ring-ring`,"aria-label":p,children:[h,g]})}),t[11]=p,t[12]=h,t[13]=_):_=t[13];let v;t[14]===o?v=t[15]:(v=e=>{(e===`working`||e===`staged`||e===`turn`)&&(o?.(e),l(!1))},t[14]=o,t[15]=v);let y;t[16]===s?y=t[17]:(y=s(`diffView.scope.changed`),t[16]=s,t[17]=y);let b;t[18]===y?b=t[19]:(b=(0,$.jsx)(`span`,{children:y}),t[18]=y,t[19]=b);let x;t[20]===r?x=t[21]:(x=(0,$.jsx)(`span`,{className:`typography-meta text-muted-foreground`,children:r}),t[20]=r,t[21]=x);let S;t[22]!==x||t[23]!==b?(S=(0,$.jsx)(ze,{value:`working`,children:(0,$.jsxs)(`span`,{className:`flex min-w-0 flex-1 items-center justify-between gap-3`,children:[b,x]})}),t[22]=x,t[23]=b,t[24]=S):S=t[24];let C;t[25]===s?C=t[26]:(C=s(`diffView.scope.staged`),t[25]=s,t[26]=C);let w;t[27]===C?w=t[28]:(w=(0,$.jsx)(`span`,{children:C}),t[27]=C,t[28]=w);let T;t[29]===i?T=t[30]:(T=(0,$.jsx)(`span`,{className:`typography-meta text-muted-foreground`,children:i}),t[29]=i,t[30]=T);let E;t[31]!==w||t[32]!==T?(E=(0,$.jsx)(ze,{value:`staged`,children:(0,$.jsxs)(`span`,{className:`flex min-w-0 flex-1 items-center justify-between gap-3`,children:[w,T]})}),t[31]=w,t[32]=T,t[33]=E):E=t[33];let D;t[34]===s?D=t[35]:(D=s(`diffView.scope.lastTurn`),t[34]=s,t[35]=D);let O;t[36]===D?O=t[37]:(O=(0,$.jsx)(`span`,{children:D}),t[36]=D,t[37]=O);let k;t[38]===a?k=t[39]:(k=(0,$.jsx)(`span`,{className:`typography-meta text-muted-foreground`,children:a}),t[38]=a,t[39]=k);let A;t[40]!==O||t[41]!==k?(A=(0,$.jsx)(ze,{value:`turn`,children:(0,$.jsxs)(`span`,{className:`flex min-w-0 flex-1 items-center justify-between gap-3`,children:[O,k]})}),t[40]=O,t[41]=k,t[42]=A):A=t[42];let j;t[43]!==n||t[44]!==S||t[45]!==E||t[46]!==A||t[47]!==v?(j=(0,$.jsx)(Ge,{align:`start`,className:`w-40`,children:(0,$.jsxs)(qe,{value:n,onValueChange:v,children:[S,E,A]})}),t[43]=n,t[44]=S,t[45]=E,t[46]=A,t[47]=v,t[48]=j):j=t[48];let M;return t[49]!==c||t[50]!==j||t[51]!==_?(M=(0,$.jsxs)(Ve,{open:c,onOpenChange:l,children:[_,j]}),t[49]=c,t[50]=j,t[51]=_,t[52]=M):M=t[52],M}),ki=Q.memo(e=>{let t=(0,Sn.c)(11),{changedFiles:n,selectedFile:r,onSelectFile:i}=e,{t:a}=ee();if(n.length===0)return null;let o;if(t[0]!==n||t[1]!==i||t[2]!==r||t[3]!==a){let e;t[5]!==i||t[6]!==r||t[7]!==a?(e=e=>{let t=hi(e),n=r===e.path;return(0,$.jsx)(`li`,{children:(0,$.jsxs)(`button`,{type:`button`,onClick:()=>i(e.path),className:J(`flex w-full items-center gap-1.5 rounded-md px-2 py-1 text-left transition-colors`,n?`bg-interactive-selection text-interactive-selection-foreground`:`text-muted-foreground hover:bg-interactive-hover hover:text-foreground`),children:[(0,$.jsx)(St,{filePath:e.path,className:`size-3 flex-shrink-0`}),(0,$.jsx)(`span`,{className:`typography-code font-semibold w-3.5 text-center uppercase`,style:{color:t.color},title:a(t.descriptionKey),"aria-label":a(t.descriptionKey),children:t.code}),(0,$.jsx)(ot,{path:e.path,className:`min-w-0 flex-1 typography-code`,dirClassName:n?`text-interactive-selection-foreground`:`text-muted-foreground`,nameClassName:n?`text-interactive-selection-foreground`:`text-foreground`}),Di(e.insertions,e.deletions)]})},e.path)},t[5]=i,t[6]=r,t[7]=a,t[8]=e):e=t[8],o=n.map(e),t[0]=n,t[1]=i,t[2]=r,t[3]=a,t[4]=o}else o=t[4];let s;return t[9]===o?s=t[10]:(s=(0,$.jsx)(Ee,{outerClassName:`flex-1 min-h-0`,className:`px-2 py-2`,children:(0,$.jsx)(`ul`,{className:`flex flex-col gap-1`,children:o})}),t[9]=o,t[10]=s),s}),Ai=Q.memo(e=>{let t=(0,Sn.c)(20),{filePath:n,diff:r,renderSideBySide:i}=e,{t:a}=ee(),o=r.original.length>0,s=r.modified.length>0,c=i?`flex flex-row gap-6 items-start justify-center`:`flex flex-col gap-4 items-center`,l=i?`flex flex-col items-center gap-2 flex-1 min-w-0`:`flex flex-col items-center gap-2`,u;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(u={contain:`layout`},t[0]=u):u=t[0];let d;t[1]!==r.original||t[2]!==n||t[3]!==o||t[4]!==l||t[5]!==i||t[6]!==a?(d=o&&(0,$.jsxs)(`div`,{className:l,children:[(0,$.jsx)(`span`,{className:`typography-meta text-muted-foreground font-medium`,children:a(`diffView.image.original`)}),(0,$.jsx)(`img`,{src:r.original,alt:a(`diffView.image.originalAlt`,{path:n}),className:i?`max-w-full max-h-[70vh] object-contain`:`max-w-full object-contain`,style:{imageRendering:`auto`}})]}),t[1]=r.original,t[2]=n,t[3]=o,t[4]=l,t[5]=i,t[6]=a,t[7]=d):d=t[7];let f;t[8]!==r.modified||t[9]!==n||t[10]!==s||t[11]!==o||t[12]!==l||t[13]!==i||t[14]!==a?(f=s&&(0,$.jsxs)(`div`,{className:l,children:[(0,$.jsx)(`span`,{className:`typography-meta text-muted-foreground font-medium`,children:a(o?`diffView.image.modified`:`diffView.image.new`)}),(0,$.jsx)(`img`,{src:r.modified,alt:a(`diffView.image.modifiedAlt`,{path:n}),className:i?`max-w-full max-h-[70vh] object-contain`:`max-w-full object-contain`,style:{imageRendering:`auto`}})]}),t[8]=r.modified,t[9]=n,t[10]=s,t[11]=o,t[12]=l,t[13]=i,t[14]=a,t[15]=f):f=t[15];let p;return t[16]!==c||t[17]!==d||t[18]!==f?(p=(0,$.jsx)(`div`,{className:`w-full overflow-auto p-4`,style:u,children:(0,$.jsxs)(`div`,{className:c,children:[d,f]})}),t[16]=c,t[17]=d,t[18]=f,t[19]=p):p=t[19],p}),ji=Q.memo(e=>{let t=(0,Sn.c)(17),{filePath:n,diff:r,renderSideBySide:i,wrapLines:a,focusLine:o}=e,s;t[0]===n?s=t[1]:(s=Bt(n)||`text`,t[0]=n,t[1]=s);let c=s;if(r.isBinary){let e;return t[2]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,$.jsx)(di,{}),t[2]=e):e=t[2],e}if(Rt(n)){let e;return t[3]!==r||t[4]!==n||t[5]!==i?(e=(0,$.jsx)(Ai,{filePath:n,diff:r,renderSideBySide:i}),t[3]=r,t[4]=n,t[5]=i,t[6]=e):e=t[6],e}let l;t[7]===Symbol.for(`react.memo_cache_sentinel`)?(l={contain:`layout`},t[7]=l):l=t[7];let u;return t[8]!==r.fileDiff||t[9]!==r.modified||t[10]!==r.original||t[11]!==n||t[12]!==o||t[13]!==c||t[14]!==i||t[15]!==a?(u=(0,$.jsx)(`div`,{className:`w-full`,style:l,children:(0,$.jsx)(Or,{original:r.original,modified:r.modified,fileDiff:r.fileDiff,language:c,fileName:n,renderSideBySide:i,wrapLines:a,focusLine:o,layout:`inline`,enableSelectionActions:!0})}),t[8]=r.fileDiff,t[9]=r.modified,t[10]=r.original,t[11]=n,t[12]=o,t[13]=c,t[14]=i,t[15]=a,t[16]=u):u=t[16],u}),Mi=Q.memo(e=>{let t=(0,Sn.c)(7),{filePath:n,staged:r,busyAction:i,disabled:a,onAction:o}=e,{t:s}=ee(),c;return t[0]!==i||t[1]!==a||t[2]!==n||t[3]!==o||t[4]!==r||t[5]!==s?(c=(0,$.jsx)(`div`,{className:`flex items-center gap-0.5 rounded-full border border-[var(--interactive-border)]/45 bg-[var(--surface-background)]/95 px-1 py-0.5 shadow-lg backdrop-blur-md`,children:r?(0,$.jsx)(Ni,{label:s(`gitView.changes.unstageFileAria`,{path:n}),icon:`arrow-go-back`,loading:i===`unstage`,disabled:a,onClick:()=>o(`unstage`)}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Ni,{label:s(`gitView.changes.revertFileAria`,{path:n}),icon:`arrow-go-back`,loading:i===`discard`,disabled:a,tone:`failure`,onClick:()=>o(`discard`)}),(0,$.jsx)(Ni,{label:s(`gitView.changes.stageFileAria`,{path:n}),icon:`add`,loading:i===`stage`,disabled:a,tone:`success`,onClick:()=>o(`stage`)})]})}),t[0]=i,t[1]=a,t[2]=n,t[3]=o,t[4]=r,t[5]=s,t[6]=c):c=t[6],c}),Ni=e=>{let t=(0,Sn.c)(14),{label:n,icon:r,loading:i,disabled:a,tone:o,onClick:s}=e,c=o===`failure`&&`text-[var(--status-error)] hover:text-[var(--status-error)]`,l=o===`success`&&`text-[var(--status-success)] hover:text-[var(--status-success)]`,u;t[0]!==c||t[1]!==l?(u=J(`h-6 w-6 rounded-none bg-transparent p-0 text-muted-foreground opacity-70 hover:bg-transparent hover:text-foreground hover:opacity-100`,c,l),t[0]=c,t[1]=l,t[2]=u):u=t[2];let d;t[3]===s?d=t[4]:(d=e=>{e.stopPropagation(),s()},t[3]=s,t[4]=d);let f;t[5]!==r||t[6]!==i?(f=i?(0,$.jsx)(Y,{name:`loader-4`,className:`size-3.5 animate-spin`}):(0,$.jsx)(Y,{name:r,className:r===`add`?`size-4`:`size-3.5`}),t[5]=r,t[6]=i,t[7]=f):f=t[7];let p;return t[8]!==a||t[9]!==n||t[10]!==u||t[11]!==d||t[12]!==f?(p=(0,$.jsx)(X,{variant:`ghost`,size:`sm`,className:u,disabled:a,title:n,"aria-label":n,onClick:d,children:f}),t[8]=a,t[9]=n,t[10]=u,t[11]=d,t[12]=f,t[13]=p):p=t[13],p},Pi=Q.memo(({directory:e,file:t,layout:n,wrapLines:r,isSelected:i,isExpanded:a,isMounted:o,onSelect:s,onExpandedChange:c,registerSectionRef:l,showOpenInEditorAction:u=!1,isOpeningInEditor:d=!1,onOpenInEditor:f,onOpenFile:p,staged:m=!1,loadFullFiles:h=!1,initialDiffData:g=null,focusLine:_=null,showFileActions:v=!0,disableGitFetch:y=!1,turnChangesRequest:b=null,loadTurnChangeFile:x=!1})=>{let{t:S}=ee(),{git:C}=Tt(),w=Ot(Q.useCallback(n=>n.directories.get(e)?.diffCache.get(t.path)??null,[e,t.path])),T=Ot(e=>e.setDiff),E=Ot(e=>e.fetchStatus),[D,O]=Q.useState(0),[k,A]=Q.useState(null),[j,M]=Q.useState(!1),[N,P]=Q.useState(null),[F,I]=Q.useState(!1),[te,ne]=Q.useState(null),[L,re]=Q.useState(null),ie=Q.useRef(null),R=Q.useRef(null),ae=Q.useMemo(()=>hi(t),[t]),z=n===`side-by-side`,B=h?`full`:`patch`,V=`${t.index}:${t.working_dir}:${t.insertions}:${t.deletions}`,oe=ri({sessionID:b?.sessionID??``,directory:b?.directory??``,messageID:b?.messageID??``,diffCount:b?.diffCount,file:t.path},{enabled:x&&!!b&&a&&o}),se=Q.useMemo(()=>{let e=oe.data?.diff;return e?typeof e.patch==`string`&&e.patch.length>0?Ei(t.path,e.patch,`patch`):typeof e.before==`string`&&e.before.length>0||typeof e.after==`string`&&e.after.length>0?{original:e.before??``,modified:e.after??``,contextMode:`full`}:null:null},[t.path,oe.data]),H=Q.useMemo(()=>{if(g)return g;if(se)return se;if(m)return L;if(te)return te;if(!w)return null;let e={original:w.original,modified:w.modified,isBinary:w.isBinary,contextMode:`full`};return Ti(e)?e:null},[w,g,te,m,L,se]),U=oe.error instanceof Error?oe.error.message:oe.error?String(oe.error):null,W=H?null:U??k,K=x&&oe.isPending||j,ce=H?.contextMode===B,le=Q.useCallback(e=>{R.current=e,l(t.path,e)},[t.path,l]),q=Q.useCallback(e=>{c(t.path,e)},[t.path,c]),ue=Q.useCallback(()=>{s(t.path)},[t.path,s]);Q.useEffect(()=>{if(!a||!o)return;if(y){ie.current=null,M(!1);return}if(!e||g){ie.current=null,M(!1);return}let n=`${e}::${t.path}::${m?`staged`:`unstaged`}::${V}::${B}::${D}`;if(ie.current===n)return;let r=!!(H&&ce);ie.current=n,A(null),r||M(!0);let i=!1,s=h?ci:li,c=Rt(t.path)||h?C.getGitFileDiff(e,{path:t.path,staged:m}):C.getGitDiff(e,{path:t.path,staged:m,contextLines:s}),l=ai,u=new Promise((e,t)=>{setTimeout(()=>t(Error(`Timed out after ${l}ms`)),l)});return Promise.race([c,u]).then(n=>{if(!i){if(`diff`in n){let e=Ei(t.path,n.diff,B);m?re(e):ne(e)}else{let r={original:n.original??``,modified:n.modified??``,isBinary:n.isBinary,contextMode:`full`};m?re(r):(ne(r),T(e,t.path,r))}M(!1)}}).catch(e=>{if(i)return;let t=e instanceof Error?e.message:String(e);A(t),M(!1)}),()=>{i=!0,ie.current===n&&(ie.current=null)}},[B,H,ce,D,e,y,t.path,V,C,g,a,o,h,T,m]);let de=Q.useCallback(()=>{q(!a),ue()},[q,ue,a]),fe=Q.useCallback(async n=>{if(!(!e||N!==null)){P(n);try{n===`stage`?await C.stageGitFile(e,t.path):n===`unstage`?await C.unstageGitFile(e,t.path):await C.revertGitFile(e,t.path,{scope:`working`}),O(e=>e+1),await E(e,C)}catch(e){let t=n===`unstage`?`gitView.toast.unstageFileFailed`:n===`stage`?`gitView.toast.stageFileFailed`:`gitView.toast.revertFailed`;G.error(e instanceof Error?e.message:S(t))}finally{P(e=>e===n?null:e)}}},[e,E,t.path,N,C,S]);return(0,$.jsxs)(`div`,{ref:le,className:`scroll-mt-9 border-b border-[var(--interactive-border)]/40 last:border-b-0`,children:[(0,$.jsx)(`div`,{className:`sticky top-0 z-30 border-b border-[var(--interactive-border)]/35 bg-[var(--surface-elevated)]/90 backdrop-blur-md supports-[backdrop-filter]:bg-[var(--surface-elevated)]/80`,children:(0,$.jsxs)(`div`,{role:`button`,tabIndex:0,onClick:de,onKeyDown:e=>{e.target===e.currentTarget&&(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),de())},className:J(`cursor-pointer`,`group/header relative grid min-h-8 w-full min-w-0 grid-cols-[minmax(0,1fr)_auto] items-center gap-1.5 overflow-hidden px-2 py-1`,`bg-transparent`,`text-muted-foreground hover:text-foreground`,i?`bg-[var(--interactive-selection)]/35`:null),children:[(0,$.jsx)(`div`,{className:`absolute inset-0 pointer-events-none group-hover/header:bg-[var(--interactive-hover)]/50`}),(0,$.jsxs)(`div`,{className:`relative flex min-w-0 flex-1 items-center gap-1.5`,children:[(0,$.jsx)(`span`,{className:`flex size-4 items-center justify-center opacity-70 group-hover/header:opacity-100`,children:a?(0,$.jsx)(Y,{name:`arrow-down-s`,className:`size-3.5`}):(0,$.jsx)(Y,{name:`arrow-right-s`,className:`size-3.5`})}),(0,$.jsx)(`span`,{className:`typography-code font-semibold leading-none w-3.5 text-center uppercase`,style:{color:ae.color},title:S(ae.descriptionKey),"aria-label":S(ae.descriptionKey),children:ae.code}),(0,$.jsx)(`span`,{className:`min-w-0 flex-1 overflow-hidden typography-code`,title:t.path,children:(0,$.jsxs)(`span`,{className:`flex min-w-0 items-center gap-1.5`,children:[(0,$.jsx)(St,{filePath:t.path,className:`size-3 flex-shrink-0 align-middle`}),(0,$.jsx)(ot,{path:t.path,className:`min-w-0 flex-1 typography-code`})]})})]}),(0,$.jsxs)(`div`,{className:`relative flex shrink-0 items-center justify-self-end gap-1.5`,children:[Di(t.insertions,t.deletions),u&&f?(0,$.jsx)(X,{variant:`ghost`,size:`sm`,className:`h-5 w-5 p-0 opacity-70 hover:opacity-100`,title:S(`diffView.actions.openFileInEditorAtChange`),onClick:e=>{e.stopPropagation(),f(t.path,H)},disabled:d,children:d?(0,$.jsx)(Y,{name:`loader-4`,className:`size-3.5 animate-spin`}):(0,$.jsx)(Y,{name:`edit`,className:`size-3.5`})}):null,p?(0,$.jsx)(X,{variant:`ghost`,size:`sm`,className:`h-5 w-5 p-0 opacity-70 hover:opacity-100`,title:S(`diffView.actions.openFilePreview`),"aria-label":S(`diffView.actions.openFilePreview`),onClick:e=>{e.stopPropagation(),p(t.path)},children:(0,$.jsx)(Y,{name:`eye`,className:`size-3.5`})}):null]})]})}),a&&(0,$.jsxs)(`div`,{className:`relative bg-background overflow-hidden`,children:[!o&&!W?(0,$.jsx)(`div`,{className:`h-40 border border-border/40 bg-background/40`}):null,W?(0,$.jsxs)(`div`,{className:`flex flex-col items-center gap-2 px-4 py-8 text-sm text-muted-foreground`,children:[(0,$.jsx)(`div`,{className:`typography-ui-label font-semibold text-foreground`,children:S(`diffView.state.failedToLoadDiff`)}),(0,$.jsx)(`div`,{className:`typography-meta text-muted-foreground max-w-[32rem] text-center`,children:W}),(0,$.jsx)(`button`,{type:`button`,className:`typography-ui-label text-primary hover:underline`,onClick:()=>{if(x){oe.refetch();return}O(e=>e+1)},children:S(`diffView.actions.retry`)})]}):null,o&&K&&!H&&!W?(0,$.jsxs)(`div`,{className:`flex items-center justify-center gap-2 px-4 py-8 text-sm text-muted-foreground`,children:[(0,$.jsx)(Y,{name:`loader-4`,className:`size-4 animate-spin`}),S(`diffView.state.loadingDiff`)]}):null,o&&H&&!F&&t.insertions+t.deletions>oi?(0,$.jsxs)(`div`,{className:`flex flex-col items-center gap-2 px-4 py-8 text-sm text-muted-foreground`,children:[(0,$.jsx)(`div`,{className:`typography-ui-label font-semibold text-foreground`,children:S(`diffView.state.largeDiff`,{count:t.insertions+t.deletions})}),(0,$.jsx)(`div`,{className:`typography-meta text-muted-foreground`,children:S(`diffView.state.largeDiffDescription`)}),(0,$.jsx)(`button`,{type:`button`,className:`typography-ui-label text-primary hover:underline`,onClick:()=>I(!0),children:S(`diffView.actions.renderAnyway`)})]}):null,o&&H&&(F||t.insertions+t.deletions<=oi)?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(ji,{filePath:t.path,diff:H,renderSideBySide:z,wrapLines:r,focusLine:_}),v?(0,$.jsx)(`div`,{className:`pointer-events-none absolute bottom-3 right-3 z-20`,children:(0,$.jsx)(`div`,{className:`pointer-events-auto`,children:(0,$.jsx)(Mi,{filePath:t.path,staged:m,busyAction:N,disabled:N!==null,onAction:fe})})}):null]}):null]})]})}),Fi=({hideStackedFileSidebar:e=!1,stackedDefaultCollapsedAll:t=!1,pinSelectedFileHeaderToTopOnNavigate:n=!1,showOpenInEditorAction:r=!1,diffScope:i=`all`,turnMessageId:a=null,sessionId:o=null,directory:s=null,onDiffScopeChange:u,targetFilePath:d=null,targetLine:f=null,toolPatches:p=null,flushContent:m=!1,singleFileView:h=!1,preloadFullFiles:g=!1,navigationRequestKey:_})=>{let{t:v}=ee(),{git:y,files:b}=Tt(),x=Ht(),S=typeof s==`string`&&s.trim()?s.trim():x,{screenWidth:C,isMobile:w}=Ye(),T=At(S??null),E=jt(S??null),D=kt(S??null),O=Ot(e=>e.setActiveDirectory),k=Ot(e=>e.ensureStatus),A=Ot(e=>e.fetchStatus),j=Ot(e=>e.setDiff),[M,N]=Q.useState(null),[F,I]=Q.useState(!1),[te,ne]=Q.useState(null),[L,re]=Q.useState(null),[R,ae]=Q.useState(()=>new Set),[z,B]=Q.useState(()=>new Set),[V,oe]=Q.useState(g),[se,H]=Q.useState(0),[W,K]=Q.useState(!1),[ce,le]=Q.useState(!1),[q,de]=Q.useState(i);Q.useEffect(()=>{de(i)},[i]);let fe=c(e=>e.pendingDiffFile),pe=c(e=>e.pendingDiffStaged),he=c(e=>e.pendingDiffScope),ge=c(e=>e.pendingDiffLine),_e=c(e=>e.setPendingDiffFile),ve=c(e=>e.diffLayoutPreference),ye=c(e=>e.diffFileLayout),be=c(e=>e.setDiffFileLayout),xe=c(e=>e.diffWrapLines),Se=c(e=>e.setDiffWrapLines),Ce=c(e=>e.openContextFileAtLine),we=c(e=>e.openContextFile),Te=rt(),De=ue(e=>e.currentSessionId),Oe=typeof o==`string`&&o.trim()?o.trim():De,ke=me(Oe??``,S??void 0),Ne=xe,Pe=q===`staged`||q!==`working`&&null,Fe=Pe??F,Ie=w||C<=768,Le=!!Oe&&q!==`turn`&&!Ie&&!l(),Re=!e&&!Ie&&C>=1024,ze=Q.useRef(null),Be=Q.useRef(new Map),Ve=Q.useRef(null),He=Q.useRef(null),Ue=Q.useRef(!1),We=Q.useRef(null),Ge=Q.useRef(null),Ke=Q.useRef(null),qe=Q.useRef(null),Je=Q.useCallback(()=>{Ve.current=null,Ue.current=!1,re(null),He.current!==null&&(window.cancelAnimationFrame(He.current),He.current=null)},[]),Xe=Q.useCallback(e=>{ae(t=>{if(t.has(e))return t;let n=new Set(t);return n.add(e),n})},[]),Ze=Q.useMemo(()=>{let e=ke.length-1;if(a&&(e=ke.findIndex(e=>e.id===a),e<0))return{messageID:null,count:0,hasDiffs:!1,thinDiffs:[]};for(let t=e;t>=0;--t){let e=ke[t];if(e.role!==`user`)continue;let n=Ci(e.summary?.diffs),r=typeof e.summary?.diffCount==`number`&&Number.isFinite(e.summary.diffCount)?Math.max(0,Math.trunc(e.summary.diffCount)):n.length;return{messageID:typeof e.id==`string`&&e.id?e.id:null,count:r,hasDiffs:e.summary?.hasDiffs===!0||r>0||n.length>0,thinDiffs:n}}return{messageID:null,count:0,hasDiffs:!1,thinDiffs:[]}},[ke,a]),Qe=Q.useMemo(()=>Gr(p??[]),[p]),$e=Qe.length>0,et=Q.useMemo(()=>!Oe||!S||!Ze.messageID?null:{sessionID:Oe,directory:S,messageID:Ze.messageID,diffCount:Ze.count},[S,Oe,Ze.count,Ze.messageID]),tt=Q.useMemo(()=>$e?Qe:Ze.thinDiffs,[Qe,Ze.thinDiffs,$e]),nt=Q.useMemo(()=>{let e=new Map;for(let t of tt)if(t.file){if(typeof t.patch==`string`&&t.patch.length>0){e.set(t.file,Ei(t.file,t.patch,`patch`));continue}(typeof t.before==`string`&&t.before.length>0||typeof t.after==`string`&&t.after.length>0)&&e.set(t.file,{original:t.before??``,modified:t.after??``,contextMode:`full`})}return e},[tt]),at=Q.useMemo(()=>{if(q===`turn`)return tt.map(e=>({path:e.file??``,index:``,working_dir:wi(e.status),insertions:e.additions??0,deletions:e.deletions??0,isNew:e.status===`added`})).filter(e=>e.path).sort((e,t)=>e.path.localeCompare(t.path));if(!E?.files)return[];let e=E.diffStats??{},t=q===`staged`?_i:q===`working`?vi:()=>!0;return E.files.filter(t).map(t=>({...t,insertions:e[t.path]?.insertions??0,deletions:e[t.path]?.deletions??0,isNew:gi(t)})).sort((e,t)=>e.path.localeCompare(t.path))},[q,tt,E]),ot=Q.useMemo(()=>E?.files?E.files.filter(vi).length:0,[E]),st=Q.useMemo(()=>E?.files?E.files.filter(_i).length:0,[E]),ct=$e?tt.length:Ze.count,lt=Q.useMemo(()=>at.map(e=>e.path).join(`\0`),[at]),ut=Q.useMemo(()=>{if(!h)return at;let e=d?.trim()||M;return e?at.filter(t=>t.path===e):[]},[at,M,h,d]);Q.useEffect(()=>{let e=lt?lt.split(`\0`):[],n=new Set(e),r=`${S??``}:${q}:${a??``}:${t?`collapsed`:`default`}`,i=p!==null&&Ke.current!==p,o=Ge.current!==r||i;Ge.current=r,Ke.current=p,ae(r=>{if(o){let n=t||q===`turn`&&!$e?0:ui(e.length);return new Set(e.slice(0,n))}let i=!1,a=new Set;for(let e of r){if(!n.has(e)){i=!0;continue}a.add(e)}return i?a:r}),B(e=>{if(o)return new Set;let t=!1,r=new Set;for(let i of e){if(!n.has(i)){t=!0;continue}r.add(i)}return t?r:e})},[q,lt,S,t,p,a,$e]);let Z=Q.useCallback(()=>{We.current=null;let e=ze.current;if(!e)return;let t=e.getBoundingClientRect(),n=t.top-si,r=t.bottom+si,i={};for(let[e,t]of Be.current){if(!t||!R.has(e))continue;let a=t.getBoundingClientRect();a.bottom<n||a.top>r||(i[e]=!0)}B(e=>{let t=!1,n=new Set(e);for(let e of Object.keys(i))n.has(e)||(n.add(e),t=!0);return t?n:e})},[R]),dt=Q.useCallback(()=>{typeof window>`u`||We.current===null&&(We.current=window.requestAnimationFrame(Z))},[Z]);Q.useEffect(()=>{let e=ze.current;if(e)return dt(),e.addEventListener(`scroll`,dt,{passive:!0}),window.addEventListener(`resize`,dt),()=>{e.removeEventListener(`scroll`,dt),window.removeEventListener(`resize`,dt),We.current!==null&&(window.cancelAnimationFrame(We.current),We.current=null)}},[at,R,dt]);let ft=Q.useCallback(e=>{let t=ye[e.path];if(t)return t;if(ve===`inline`)return`inline`;if(ve===`side-by-side`)return`side-by-side`;let n=C<ii;return e.isNew||n?`inline`:`side-by-side`},[ye,ve,C]),pt=Q.useMemo(()=>ut.length===0?null:ut.every(e=>ft(e)===`side-by-side`)?`side-by-side`:`inline`,[ft,ut]);Q.useEffect(()=>{S&&(O(S),k(S,y))},[S,O,k,y]),Q.useEffect(()=>{if(S)return U.onGitRefreshHint(e=>{bi(e.directory)===bi(S)&&A(S,y)})},[S,A,y]),Q.useEffect(()=>{q!==`all`&&!he||fe&&(he&&de(he),N(fe),I(he===`staged`||!he&&pe),ne(ge),_e(null),Ue.current=!0,Ve.current=fe,Xe(fe),H(e=>e+1))},[q,Xe,fe,ge,he,pe,_e]),Q.useEffect(()=>{if(q===`all`)return;let e=d?.trim();if(!e)return;Xe(e),N(e),I(q===`staged`),ne(f);let t=Kr({scope:q,navigationRequestKey:_,targetFilePath:e,targetLine:f}),n=at.some(t=>t.path===e);qr(qe.current,t,n)&&(qe.current=t,Ue.current=!0,Ve.current=e,H(e=>e+1))},[q,at,Xe,_,d,f]),Q.useEffect(()=>{M&&(at.some(e=>e.path===M)||(N(null),I(!1)))},[at,M]);let mt=Q.useCallback((e,t)=>{let n=Be.current;t?n.set(e,t):n.delete(e),dt()},[dt]),ht=Q.useCallback((e,t)=>{Je(),ae(n=>{if(t===n.has(e))return n;let r=new Set(n);return t?r.add(e):r.delete(e),r}),t||B(t=>{if(!t.has(e))return t;let n=new Set(t);return n.delete(e),n}),dt()},[Je,dt]),gt=Q.useCallback(()=>{Je(),ae(e=>e.size>0?new Set:new Set(at.map(e=>e.path))),B(new Set),dt()},[Je,at,dt]),_t=Q.useCallback(async e=>{if(!De)return;let t=ue.getState().getDirectoryForSession(De)||S||``;if(!t){G.error(v(`diffView.reviewDialog.toast.noSessionDirectory`));return}le(!0);try{await ie({originalSessionID:De,directory:t,providerID:e.providerID,modelID:e.modelID,agent:e.agent||void 0,variant:e.variant||void 0,generateHandoff:e.generateHandoff,returnAfterHandoffRequest:e.generateHandoff,autoReview:e.autoReview}),K(!1)}catch(e){console.error(`[review-flow] failed to start review flow`,e),G.error(e instanceof Error?e.message:v(`diffView.reviewDialog.toast.startFailed`))}finally{le(!1)}},[De,S,v]),vt=Q.useCallback(e=>{let t=Be.current.get(e),n=ze.current;if(!t||!n)return!1;let r=n.getBoundingClientRect(),i=t.getBoundingClientRect().top-r.top,a=Math.max(0,n.scrollHeight-n.clientHeight);return n.scrollTop=Math.min(a,Math.max(0,n.scrollTop+i)),!0},[]);Q.useEffect(()=>{if(!Ve.current)return;let e=0,t=!1,r=()=>{t||(t=!0,Ve.current=null,Ue.current=!1,re(null),He.current!==null&&(window.cancelAnimationFrame(He.current),He.current=null))},i=()=>{if(t){He.current=null;return}let a=Ve.current;if(!a){r(),He.current=null;return}if(!vt(a)){e+=1,e<20?He.current=window.requestAnimationFrame(i):(r(),He.current=null);return}n&&Ue.current&&re(a),r()};return He.current=window.requestAnimationFrame(i),()=>{t=!0,He.current!==null&&(window.cancelAnimationFrame(He.current),He.current=null)}},[n,se,vt]);let yt=Q.useCallback(e=>{},[]),bt=Q.useCallback(e=>{Je(),N(e),I(!1),Ue.current=!0,Ve.current=e,Xe(e),H(e=>e+1),vt(e)},[Je,Xe,vt]),xt=Q.useCallback(e=>{let t=e===`side-by-side`?`side-by-side`:`inline`;ut.forEach(e=>{be(e.path,t)})},[be,ut]),[St,Ct]=Q.useState(null),wt=Q.useCallback(async(e,t)=>{if(!(!S||!e)){Ct(e);try{let n=null;if(t?.patch&&!t.isBinary&&!Rt(e)?n=Wr(t.patch):t&&t.contextMode===`full`&&!t.isBinary&&!Rt(e)&&(n=xi(t.original,t.modified)),n===null)try{n=Wr((await y.getGitDiff(S,{path:e,staged:Fe,contextLines:3})).diff)}catch{n=null}let r=t;if(n===null||!r){let t=await y.getGitFileDiff(S,{path:e,staged:Fe});r={original:t.original??``,modified:t.modified??``,isBinary:t.isBinary},Fe||j(S,e,r)}let i=n??(r.isBinary||Rt(e)?1:xi(r.original,r.modified)),a=yi(S,e),o=await Pr(b,a);if(!o.ok){G.error(Fr(o.reason));return}Ce(S,a,i,1)}finally{Ct(t=>t===e?null:t)}}},[Fe,S,b,y,Ce,j]),Et=P(e=>{if(!S||!e)return;let t=yi(S,e);if(Te){Te.openFile({path:t});return}Pr(b,t).then(e=>{if(!e.ok){G.error(Fr(e.reason));return}we(S,t)})});return(0,$.jsxs)(`div`,{className:`flex h-full flex-col overflow-hidden bg-background`,children:[h?null:(0,$.jsxs)(`div`,{className:`@container/diff-toolbar flex min-w-0 items-center gap-1.5 px-2 py-1.5 bg-background`,children:[!w&&(q===`working`||q===`staged`||q===`turn`?(0,$.jsx)(Oi,{scope:q,workingCount:ot,stagedCount:st,turnCount:ct,onScopeChange:e=>{de(e),u?.(e)}}):(0,$.jsx)(`div`,{className:`flex items-center gap-1 rounded-md px-2 py-1 text-muted-foreground shrink-0`,children:(0,$.jsx)(`span`,{className:`typography-code font-semibold text-foreground`,children:D&&!E?v(`diffView.state.loadingChanges`):ut.length===1?v(`diffView.summary.changedFilesSingle`,{count:ut.length}):v(`diffView.summary.changedFilesPlural`,{count:ut.length})})})),!h&&at.length>0&&(q!==`turn`||$e)&&(0,$.jsxs)(X,{variant:`ghost`,size:`sm`,onClick:gt,className:J(`diff-toolbar__expand-button h-7 flex-shrink-0 gap-1 px-1.5 text-muted-foreground hover:text-foreground`,`ml-auto`),title:R.size>0?v(`diffView.actions.collapseAll`):v(`diffView.actions.expandAll`),children:[(0,$.jsx)(Y,{name:`expand-up-down`,className:`size-4`}),(0,$.jsx)(`span`,{className:`diff-toolbar__expand-label typography-code`,children:R.size>0?v(`diffView.actions.collapseAll`):v(`diffView.actions.expandAll`)})]}),at.length>0&&Le&&(0,$.jsxs)(X,{variant:`default`,size:`sm`,onClick:()=>K(!0),disabled:ce,className:`diff-toolbar__review-button h-7 flex-shrink-0 gap-1.5 px-2`,"aria-label":v(`diffView.actions.reviewAria`),children:[ce?(0,$.jsx)(Y,{name:`loader-4`,className:`size-4 animate-spin`}):(0,$.jsx)(Y,{name:`search-eye`,className:`size-4`}),(0,$.jsx)(`span`,{className:`diff-toolbar__review-label typography-code`,children:v(`diffView.actions.review`)})]}),at.length>0&&(0,$.jsxs)(Me,{children:[(0,$.jsx)(Ae,{asChild:!0,children:(0,$.jsx)(X,{variant:`ghost`,size:`sm`,onClick:()=>oe(e=>!e),"aria-pressed":V,"aria-label":v(V?`diffView.actions.disableFullFiles`:`diffView.actions.loadFullFiles`),className:J(`h-7 w-7 flex-shrink-0 p-0 text-muted-foreground hover:text-foreground`,V&&`bg-interactive-selection text-interactive-selection-foreground`),children:(0,$.jsx)(Y,{name:`file-download`,className:`size-4`})})}),(0,$.jsx)(je,{children:(0,$.jsx)(`p`,{children:v(V?`diffView.actions.disableFullFiles`:`diffView.actions.loadFullFiles`)})})]}),at.length>0&&(0,$.jsx)(X,{variant:`ghost`,size:`sm`,onClick:()=>Se(!xe),className:J(`h-5 w-5 p-0 transition-opacity`,Ne?`text-foreground opacity-100`:`text-muted-foreground opacity-60 hover:opacity-100`),title:v(Ne?`diffView.actions.disableLineWrap`:`diffView.actions.enableLineWrap`),children:(0,$.jsx)(Y,{name:`text-wrap`,className:`size-4`})}),pt&&(0,$.jsx)(Gt,{mode:pt===`side-by-side`?`side-by-side`:`unified`,onModeChange:xt})]}),(0,$.jsx)(it,{open:W,onOpenChange:K,projectDirectory:S??null,submitting:ce,onConfirm:_t}),S?q!==`turn`&&D&&!E?(0,$.jsxs)(`div`,{className:`flex flex-1 items-center justify-center gap-2 text-sm text-muted-foreground`,children:[(0,$.jsx)(Y,{name:`loader-4`,className:`size-4 animate-spin`}),v(`diffView.state.loadingRepositoryStatus`)]}):q!==`turn`&&T===!1?(0,$.jsx)(`div`,{className:`flex flex-1 items-center justify-center text-sm text-muted-foreground`,children:v(`diffView.state.notGitRepository`)}):ut.length===0?(0,$.jsx)(`div`,{className:`flex flex-1 items-center justify-center text-sm text-muted-foreground`,children:v(q===`turn`?`diffView.state.noLastTurnChanges`:`diffView.state.cleanWorkingTree`)}):(()=>{if(!S)return null;let e=e=>Pe===null?F&&e===M:Pe;return(0,$.jsxs)(`div`,{className:J(`flex min-w-0 flex-1 min-h-0 h-full`,m?`gap-0`:`gap-3 px-3 pb-3 pt-2`),children:[Re&&(0,$.jsxs)(`section`,{className:`hidden lg:flex w-72 flex-col rounded-xl border border-border/60 bg-background/70 overflow-hidden`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between px-3 py-1.5 border-b border-border/40`,children:[(0,$.jsx)(`span`,{className:`typography-code font-semibold text-foreground`,children:v(`diffView.section.files`)}),(0,$.jsx)(`span`,{className:`typography-code text-muted-foreground`,children:at.length})]}),(0,$.jsx)(ki,{changedFiles:at,selectedFile:null,onSelectFile:bt})]}),(0,$.jsx)(`div`,{className:`relative flex-1 min-w-0 min-h-0 h-full`,children:(0,$.jsx)(Ee,{ref:ze,outerClassName:`min-h-0 h-full`,className:`[overflow-anchor:none] pb-16 pwa-overlay-scroll`,disableHorizontal:!0,observeMutations:!1,preventOverscroll:!0,"data-diff-virtual-root":!0,children:(0,$.jsx)(`div`,{className:`flex flex-col [overflow-anchor:none]`,"data-diff-virtual-content":!0,children:ut.map(t=>(0,$.jsx)(Pi,{directory:S,file:t,layout:ft(t),wrapLines:Ne,isSelected:!1,isExpanded:R.has(t.path),isMounted:z.has(t.path)||t.path===L||h&&ut.length===1,onSelect:yt,onExpandedChange:ht,registerSectionRef:mt,showOpenInEditorAction:r&&q!==`turn`,isOpeningInEditor:St===t.path,onOpenInEditor:(e,t)=>{wt(e,t)},onOpenFile:Et,staged:e(t.path),loadFullFiles:V,initialDiffData:q===`turn`?nt.get(t.path)??null:null,focusLine:t.path===(d?.trim()||M)?f??te:null,showFileActions:q!==`turn`,disableGitFetch:q===`turn`,turnChangesRequest:et,loadTurnChangeFile:q===`turn`&&!$e},t.path))})})})]})})():(0,$.jsx)(`div`,{className:`flex flex-1 items-center justify-center text-sm text-muted-foreground`,children:v(`diffView.state.selectSessionDirectory`)})]})},Ii=(e,t)=>{if(!t)return null;let n=Number.parseInt(e.trim(),10);return!Number.isFinite(n)||n<1?null:Math.min(n,t.state.doc.lines)},Li=(e,t)=>{let n=e.state.doc.lineAt(t.main.head);return{lineNumber:n.number,character:t.main.head-n.from+1,selection:t}},Ri=(e,t,n)=>{let r=e.state.doc.line(t),i=Math.max(1,Math.min(n,r.length+1)),a=r.from+i-1;e.dispatch({selection:N.cursor(a),effects:M.scrollIntoView(a,{y:`center`})})};function zi({open:e,onOpenChange:t,view:n,variant:r=`overlay`}){let{t:i}=ee(),[a,o]=Q.useState(``),s=Q.useRef(null),c=Q.useRef(!1),l=Q.useRef(null),u=Q.useRef(null),d=Q.useMemo(()=>Ii(a,n),[a,n]);Q.useEffect(()=>{!e||!n||(c.current=!1,s.current=Li(n,n.state.selection),o(``))},[e,n]),Q.useEffect(()=>{e&&window.requestAnimationFrame(()=>{u.current?.focus(),u.current?.select()})},[e]),Q.useEffect(()=>{if(!(!e||!n||!s.current)){if(d===null){let{selection:e}=s.current;n.dispatch({selection:e,effects:M.scrollIntoView(e.main.from,{y:`center`})});return}Ri(n,d,s.current.character)}},[d,e,n]);let f=Q.useCallback(()=>{if(!n||c.current||!s.current)return;let{selection:e}=s.current;n.dispatch({selection:e,effects:M.scrollIntoView(e.main.from,{y:`center`})})},[n]),p=Q.useCallback(e=>{e||f(),t(e)},[t,f]),m=Q.useCallback(()=>{!n||d===null||!s.current||(c.current=!0,Ri(n,d,s.current.character),t(!1),n.focus())},[d,t,n]);Q.useEffect(()=>{if(!e)return;let t=e=>{let t=l.current,n=e.target;!t||!(n instanceof Node)||t.contains(n)||p(!1)},n=e=>{e.key===`Escape`&&(e.preventDefault(),p(!1))};return document.addEventListener(`pointerdown`,t,!0),document.addEventListener(`keydown`,n,!0),()=>{document.removeEventListener(`pointerdown`,t,!0),document.removeEventListener(`keydown`,n,!0)}},[p,e,r]);let h=Q.useMemo(()=>{if(!n)return i(`goToLineDialog.helper.editorUnavailable`);if(d===null){let e=s.current??Li(n,n.state.selection);return i(`goToLineDialog.helper.currentLineRange`,{current:e.lineNumber,max:n.state.doc.lines})}return i(`goToLineDialog.helper.goToLine`,{line:d})},[d,i,n]);return r===`inline`?e?(0,$.jsxs)(`div`,{ref:l,className:`ml-1 flex h-6 items-center gap-1`,children:[(0,$.jsx)(ke,{ref:u,type:`number`,min:1,step:1,inputMode:`numeric`,value:a,onChange:e=>o(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),m())},placeholder:i(`goToLineDialog.field.linePlaceholderShort`),className:`h-6 w-20 rounded-md border-border/70 bg-transparent px-2 typography-meta`}),(0,$.jsx)(X,{variant:`outline`,size:`xs`,onClick:m,disabled:!n||d===null,className:`h-6 px-2`,children:i(`goToLineDialog.actions.go`)})]}):null:(0,$.jsx)(`div`,{ref:l,className:J(`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`,e?`pointer-events-auto translate-y-0 opacity-100`:`pointer-events-none -translate-y-1 opacity-0`),children:(0,$.jsxs)(`div`,{className:`min-w-0`,children:[(0,$.jsx)(ke,{ref:u,type:`number`,min:1,step:1,inputMode:`numeric`,value:a,onChange:e=>o(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),m())},placeholder:i(`goToLineDialog.field.linePlaceholder`),className:`h-8 w-full rounded-md border-border/70 bg-background/60 typography-ui-label`}),(0,$.jsx)(`div`,{className:`mt-2 rounded-md bg-primary/15 px-3 py-1.5 typography-ui-label text-foreground/95`,children:h})]})})}var Bi=(e,t)=>{let n=Ze(t,e);return!n||n===`.`||n===t?0:n.split(`/`).filter(Boolean).length},Vi=(e,t,n=10)=>{let r=$e(e);if(!r||n<1)return[];let i=new Set,a=[];for(let e of Object.values(t))if(e)for(let t of e){if(t.type!==`directory`)continue;let e=$e(t.path);if(!e||i.has(e))continue;let o=Bi(r,e);o<1||o>n||(i.add(e),a.push(e))}return a},Hi=e=>e.some(e=>!!$e(e)),Ui=(e,t)=>{let n=new Set(t.map(e=>$e(e)).filter(Boolean));return e.filter(e=>!n.has(e))},Wi=(e,t,n)=>t.length===0?e.length===0:Ui(e,t).length>0?!1:t.every(e=>n.has($e(e))),Gi=[{id:`finder`,label:`Finder`,appName:`Finder`},{id:`terminal`,label:`Terminal`,appName:`Terminal`},{id:`iterm2`,label:`iTerm2`,appName:`iTerm`},{id:`ghostty`,label:`Ghostty`,appName:`Ghostty`},{id:`vscode`,label:`VS Code`,appName:`Visual Studio Code`},{id:`vscode-insiders`,label:`VS Code Insiders`,appName:`Visual Studio Code - Insiders`},{id:`intellij`,label:`IntelliJ`,appName:`IntelliJ IDEA`},{id:`visual-studio`,label:`Visual Studio`,appName:`Visual Studio`},{id:`cursor`,label:`Cursor`,appName:`Cursor`},{id:`android-studio`,label:`Android Studio`,appName:`Android Studio`},{id:`pycharm`,label:`PyCharm`,appName:`PyCharm`},{id:`xcode`,label:`Xcode`,appName:`Xcode`},{id:`sublime-text`,label:`Sublime`,appName:`Sublime Text`},{id:`webstorm`,label:`WebStorm`,appName:`WebStorm`},{id:`rider`,label:`Rider`,appName:`Rider`},{id:`zed`,label:`Zed`,appName:`Zed`},{id:`phpstorm`,label:`PhpStorm`,appName:`PhpStorm`},{id:`eclipse`,label:`Eclipse`,appName:`Eclipse`},{id:`windsurf`,label:`Windsurf`,appName:`Windsurf`},{id:`vscodium`,label:`VSCodium`,appName:`VSCodium`},{id:`rustrover`,label:`RustRover`,appName:`RustRover`},{id:`kiro`,label:`Kiro`,appName:`Kiro`},{id:`antigravity`,label:`Antigravity`,appName:`Antigravity`},{id:`trae`,label:`Trae`,appName:`Trae`}],Ki=`finder`,qi=new Set([`finder`,`terminal`]),Ji=e=>typeof window<`u`&&window.__OPENCHAMBER_PLATFORM__===`win32`&&e.id===`finder`?{...e,label:`Explorer`,appName:`File Explorer`}:e,Yi=e=>{if(!e)return null;let t=Gi.find(t=>t.id===e)??null;return t?Ji(t):null},Xi=()=>Gi.filter(e=>qi.has(e.id)).map(e=>({...Ji(e)})),Zi=()=>{if(typeof window>`u`)return Ki;let e=window.localStorage.getItem(`openInAppId`);return e&&Yi(e)?e:Ki},Qi=!1,$i=!1,ea=!1,ta=0,na=null,ra=()=>{na&&=(clearTimeout(na),null)},ia=S()((e,t)=>({selectedAppId:Zi(),availableApps:Xi(),hasLoadedApps:!1,isCacheStale:!1,isScanning:!1,initialize:()=>{if(Qi||typeof window>`u`)return;Qi=!0;let n=(t,n=!0)=>{if(!Array.isArray(t)||t.length===0){e({availableApps:Xi(),hasLoadedApps:n});return}let r=new Set(t.map(e=>e.name)),i=new Map(t.map(e=>[e.name,e.iconDataUrl??void 0]));e({availableApps:Gi.filter(e=>r.has(e.appName)||qi.has(e.id)).map(e=>({...Ji(e),iconDataUrl:i.get(e.appName)})),hasLoadedApps:!0})},r=async i=>{if(!f()||!p()||$i||t().hasLoadedApps&&!i)return;let a=Gi.map(e=>e.appName);ra(),i&&e({hasLoadedApps:!1}),$i=!0,ea=!1,e({isScanning:!0});try{let{apps:t,success:o,hasCache:s,isCacheStale:c}=await d(a,i),l=o&&!s&&t.length===0&&ta<3;if(e({isCacheStale:s?c:!1}),n(t,o?!l:!1),o){if(l){let e=[800,1600,3200][ta]??3200;ta+=1,ea=!0,na=setTimeout(()=>{r()},e);return}ta=0,ea=!1;return}if(ta<3){let e=[1e3,3e3,7e3][ta]??7e3;ta+=1,ea=!0,na=setTimeout(()=>{r()},e)}}finally{$i=!1,ea||e({isScanning:!1})}};r(),window.addEventListener(`openchamber:settings-synced`,t=>{let n=t.detail,r=n&&typeof n.openInAppId==`string`&&n.openInAppId.length>0&&Yi(n.openInAppId)?n.openInAppId:null;r&&(window.localStorage.setItem(`openInAppId`,r),e({selectedAppId:r}))}),window.addEventListener(`openchamber:app-ready`,()=>{r()}),window.addEventListener(`openchamber:installed-apps-updated`,t=>{let r=t.detail;Array.isArray(r)&&(ta=3,ea=!1,e({isScanning:!1,isCacheStale:!1}),n(r))}),window.__openchamberAppReady&&r(),window.setTimeout(()=>{t().hasLoadedApps||r()},5e3)},loadInstalledApps:async n=>{if(Qi||t().initialize(),!f()||!p()||$i||t().hasLoadedApps&&!n)return;let r=Gi.map(e=>e.appName);ra(),n&&e({hasLoadedApps:!1}),$i=!0,ea=!1,e({isScanning:!0});try{let{apps:t,hasCache:i,isCacheStale:a}=await d(r,n),o=new Set(t.map(e=>e.name)),s=new Map(t.map(e=>[e.name,e.iconDataUrl??void 0])),c=Gi.filter(e=>o.has(e.appName)||qi.has(e.id)).map(e=>({...e,iconDataUrl:s.get(e.appName)}));e({availableApps:c.length>0?c:Xi(),hasLoadedApps:c.length>0,isCacheStale:i?a:!1})}finally{$i=!1,ea||e({isScanning:!1})}},selectApp:async t=>{Yi(t)&&(e({selectedAppId:t}),typeof window<`u`&&window.localStorage.setItem(`openInAppId`,t),await y({openInAppId:t}))}})),aa=Ft(()=>O(()=>import(`./ToolOutputDialog-GNBM3JdP.js`),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45]))),oa=e=>{let t=la(e);if(!t)return``;if(t===`/`||/^[A-Za-z]:\/$/.test(t))return t;let n=t.lastIndexOf(`/`);if(n<0)return t;if(n===0)return`/`;let r=t.slice(0,n);return/^[A-Za-z]:$/.test(r)?`${r}/`:r},sa=e=>{let t=(0,Sn.c)(8),{label:n,iconDataUrl:r}=e,[i,a]=Q.useState(!1),o;t[0]===n?o=t[1]:(o=n.trim().slice(0,1).toUpperCase()||`?`,t[0]=n,t[1]=o);let s=o;if(r&&!i){let e;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(e=()=>a(!0),t[2]=e):e=t[2];let n;return t[3]===r?n=t[4]:(n=(0,$.jsx)(`img`,{src:r,alt:``,className:`size-4 rounded-sm`,onError:e}),t[3]=r,t[4]=n),n}let c;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(c=J(`size-4 rounded-sm flex items-center justify-center`,`bg-[var(--surface-muted)] text-[9px] font-medium text-muted-foreground`),t[5]=c):c=t[5];let l;return t[6]===s?l=t[7]:(l=(0,$.jsx)(`span`,{className:c,children:s}),t[6]=s,t[7]=l),l},ca=e=>e.slice().sort((e,t)=>e.type===t.type?e.name.localeCompare(t.name):e.type===`directory`?-1:1),la=e=>{if(!e)return``;let t=e.replace(/\\/g,`/`),n=t.startsWith(`//`),r=t.replace(/\/+/g,`/`);n&&!r.startsWith(`//`)&&(r=`/${r}`);let i=r===`/`,a=/^[A-Za-z]:\/$/.test(r);return!i&&!a&&(r=r.replace(/\/+$/,``)),r},ua=e=>e.startsWith(`/`)||e.startsWith(`//`)||/^[A-Za-z]:\//.test(e),da=e=>/^[A-Za-z]:\//.test(e)?e.toLowerCase():e,fa=(e,t)=>{let n=la(t),r=la(e);if(!n||!r)return!1;let i=da(n),a=da(r);return a===i||a.startsWith(`${i}/`)},pa=(e,t)=>{let n=la(t),r=la(e);if(!fa(r,n))return[];let i=r.slice(n.length).replace(/^\//,``).split(`/`),a=[],o=n;for(let e=0;e<i.length-1;e++)o=o?`${o}/${i[e]}`:i[e],a.push(o);return a},ma=(e,t)=>{if(!t)return``;let n=la(t);if(!e||!fa(n,e))return n;let r=n.slice(e.length);return r.startsWith(`/`)?r.slice(1):r},ha=new Set([`node_modules`]),ga=e=>{let t=(0,Sn.c)(3),{status:n}=e,r;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(r={open:`var(--status-info)`,modified:`var(--status-warning)`,"git-modified":`var(--status-warning)`,"git-added":`var(--status-success)`,"git-deleted":`var(--status-error)`},t[0]=r):r=t[0];let i=r[n],a;return t[1]===i?a=t[2]:(a=(0,$.jsx)(`span`,{className:`size-2 rounded-full`,style:{backgroundColor:i}}),t[1]=i,t[2]=a),a},_a=e=>{let t=(0,Sn.c)(11),{name:n}=e,r=Q.useRef(null),i=Q.useRef(null),[a,o]=Q.useState(!1),s;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(s=()=>{let e=r.current,t=i.current;if(!e||!t)return;let n=()=>{o(t.scrollWidth>e.clientWidth+1)};n();let a=new ResizeObserver(n);return a.observe(e),a.observe(t),()=>{a.disconnect()}},t[0]=s):s=t[0];let c;t[1]===n?c=t[2]:(c=[n],t[1]=n,t[2]=c),Q.useLayoutEffect(s,c);let l;t[3]===n?l=t[4]:(l=(0,$.jsx)(`span`,{ref:i,"aria-hidden":`true`,className:`invisible absolute whitespace-nowrap`,children:n}),t[3]=n,t[4]=l);let u;t[5]!==n||t[6]!==a?(u=a?(0,$.jsxs)(`span`,{className:`open-file-name-marquee-track`,children:[(0,$.jsx)(`span`,{className:`open-file-name-marquee-item`,children:n}),(0,$.jsx)(`span`,{className:`open-file-name-marquee-item`,"aria-hidden":`true`,children:n})]}):(0,$.jsx)(`span`,{className:`block min-w-0 truncate`,children:n}),t[5]=n,t[6]=a,t[7]=u):u=t[7];let d;return t[8]!==l||t[9]!==u?(d=(0,$.jsxs)(`span`,{ref:r,className:`relative block min-w-0 flex-1 overflow-hidden whitespace-nowrap`,children:[l,u]}),t[8]=l,t[9]=u,t[10]=d):d=t[10],d},va=e=>ha.has(e),ya=e=>{let t=la(e);return t===`node_modules`||t.endsWith(`/node_modules`)||t.includes(`/node_modules/`)},ba=e=>{let t=(e instanceof Error?e.message:String(e??``)).toLowerCase();return t.includes(`is a directory`)||t.includes(`eisdir`)},xa=e=>{let t=(e instanceof Error?e.message:String(e??``)).toLowerCase();return t.includes(`file not found`)||t.includes(`enoent`)||t.includes(`no such file`)||t.includes(`does not exist`)},Sa=2e5,Ca=`openchamber:files:auto-save-enabled`,wa=e=>{let t=0,n=0;for(let r=0;r<e.length;r+=1)e.charCodeAt(r)===10&&(r>0&&e.charCodeAt(r-1)===13?t+=1:n+=1);return t>n?`\r
|
|
146
146
|
`:`
|
|
147
147
|
`},Ta=e=>e.replace(/\r\n/g,`
|
|
148
148
|
`).replace(/\r/g,`
|
|
@@ -151,9 +151,9 @@ import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{C as t,E as n,I as r,K
|
|
|
151
151
|
`):n},Da=()=>{if(typeof window>`u`)return!0;try{return window.localStorage.getItem(Ca)!==`false`}catch{return!0}},Oa=(e,t)=>(0,$.jsx)(St,{filePath:e,extension:t}),ka=e=>{if(!e)return!1;let t=e.toLowerCase().split(`.`).pop();return t===`md`||t===`markdown`},Aa=e=>{if(!e)return!1;let t=e.toLowerCase().split(`.`).pop();return t===`html`||t===`htm`},ja=e=>{let t=(0,Sn.c)(83),{node:n,root:r,isExpanded:i,isActive:a,isMobile:o,alwaysShowActions:s,status:c,badge:l,permissions:u,downloadFile:d,contextMenuPath:f,setContextMenuPath:p,rightClickMenuPath:m,setRightClickMenuPath:h,onSelect:g,onToggle:_,onRevealPath:v,onOpenDialog:y}=e,{t:b}=ee(),x=n.type===`directory`,{canRename:S,canCreateFile:C,canCreateFolder:w,canDelete:T,canReveal:E}=u,D;t[0]!==C||t[1]!==w||t[2]!==T||t[3]!==S||t[4]!==E||t[5]!==n.path||t[6]!==h?(D=e=>{!S&&!C&&!w&&!T&&!E||(e?.preventDefault(),h(n.path))},t[0]=C,t[1]=w,t[2]=T,t[3]=S,t[4]=E,t[5]=n.path,t[6]=h,t[7]=D):D=t[7];let O=D,k;t[8]!==x||t[9]!==n||t[10]!==g||t[11]!==_?(k=()=>{x?_(n.path):g(n)},t[8]=x,t[9]=n,t[10]=g,t[11]=_,t[12]=k):k=t[12];let A=k,j;t[13]!==n.path||t[14]!==p||t[15]!==h?(j=e=>{e.stopPropagation(),h(null),p(n.path)},t[13]=n.path,t[14]=p,t[15]=h,t[16]=j):j=t[16];let M=j,N;t[17]!==C||t[18]!==w||t[19]!==T||t[20]!==S||t[21]!==E||t[22]!==d||t[23]!==x||t[24]!==n||t[25]!==y||t[26]!==v||t[27]!==r||t[28]!==b?(N=e=>{let{Item:t,Separator:i}=e;return(0,$.jsxs)($.Fragment,{children:[S&&(0,$.jsxs)(t,{onClick:e=>{e.stopPropagation(),y(`rename`,n)},children:[(0,$.jsx)(Y,{name:`edit`,className:`mr-2 size-4`}),` `,b(`sidebarFilesTree.menu.rename`)]}),(0,$.jsxs)(t,{onClick:e=>{e.stopPropagation(),te(n.path).then(e=>{e.ok||G.error(b(`sidebarFilesTree.toast.copyFailed`))})},children:[(0,$.jsx)(Y,{name:`file-copy`,className:`mr-2 size-4`}),` `,b(`sidebarFilesTree.menu.copyPath`)]}),(0,$.jsxs)(t,{onClick:e=>{e.stopPropagation();let t=ma(r,n.path)||n.path;te(t).then(e=>{if(e.ok){G.success(b(`filesView.toast.relativePathCopied`));return}G.error(b(`sidebarFilesTree.toast.copyFailed`))})},children:[(0,$.jsx)(Y,{name:`file-copy-2`,className:`mr-2 size-4`}),` `,b(`filesView.tree.menu.copyRelativePath`)]}),!x&&d&&(0,$.jsxs)(t,{onClick:e=>{e.stopPropagation(),d(n.path).catch(e=>{console.error(`Download failed:`,e),G.error(b(`sidebarFilesTree.toast.operationFailed`))})},children:[(0,$.jsx)(Y,{name:`download`,className:`mr-2 size-4`}),` `,b(`sidebarFilesTree.menu.save`)]}),E&&(0,$.jsxs)(t,{onClick:e=>{e.stopPropagation(),v(n.path)},children:[(0,$.jsx)(Y,{name:`folder-received`,className:`mr-2 size-4`}),` `,b(Ce())]}),x&&(C||w)&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(i,{}),C&&(0,$.jsxs)(t,{onClick:e=>{e.stopPropagation(),y(`createFile`,n)},children:[(0,$.jsx)(Y,{name:`file-add`,className:`mr-2 size-4`}),` `,b(`sidebarFilesTree.menu.newFile`)]}),w&&(0,$.jsxs)(t,{onClick:e=>{e.stopPropagation(),y(`createFolder`,n)},children:[(0,$.jsx)(Y,{name:`folder-add`,className:`mr-2 size-4`}),` `,b(`sidebarFilesTree.menu.newFolder`)]})]}),T&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(i,{}),(0,$.jsxs)(t,{onClick:e=>{e.stopPropagation(),y(`delete`,n)},className:`text-destructive focus:text-destructive`,children:[(0,$.jsx)(Y,{name:`delete-bin`,className:`mr-2 size-4`}),` `,b(`sidebarFilesTree.menu.delete`)]})]})]})},t[17]=C,t[18]=w,t[19]=T,t[20]=S,t[21]=E,t[22]=d,t[23]=x,t[24]=n,t[25]=y,t[26]=v,t[27]=r,t[28]=b,t[29]=N):N=t[29];let P=N,F=m===n.path,I;t[30]!==n.path||t[31]!==h?(I=e=>h(e?n.path:null),t[30]=n.path,t[31]=h,t[32]=I):I=t[32];let ne=o?void 0:O,L;t[33]===ne?L=t[34]:(L=(0,$.jsx)(`div`,{className:`group relative flex items-center`,onContextMenu:ne}),t[33]=ne,t[34]=L);let re=o?void 0:O,ie=a?`bg-interactive-selection/70`:`hover:bg-interactive-hover/40`,R;t[35]===ie?R=t[36]:(R=J(`flex w-full items-center gap-1.5 rounded-md px-2 py-1 text-left text-foreground transition-colors pr-8 select-none`,ie),t[35]=ie,t[36]=R);let ae;t[37]!==x||t[38]!==i||t[39]!==n.extension||t[40]!==n.path?(ae=x?i?(0,$.jsx)(Y,{name:`folder-open-fill`,className:`size-4 flex-shrink-0 text-muted-foreground`}):(0,$.jsx)(Y,{name:`folder-3-fill`,className:`size-4 flex-shrink-0 text-muted-foreground`}):Oa(n.path,n.extension),t[37]=x,t[38]=i,t[39]=n.extension,t[40]=n.path,t[41]=ae):ae=t[41];let z;t[42]!==n.name||t[43]!==n.path?(z=(0,$.jsx)(`span`,{className:`min-w-0 flex-1 truncate typography-meta`,title:n.path,children:n.name}),t[42]=n.name,t[43]=n.path,t[44]=z):z=t[44];let B;t[45]!==x||t[46]!==c?(B=!x&&c&&(0,$.jsx)(ga,{status:c}),t[45]=x,t[46]=c,t[47]=B):B=t[47];let V;t[48]!==l||t[49]!==x?(V=x&&l&&(0,$.jsxs)(`span`,{className:`text-xs flex items-center gap-1 ml-auto mr-1`,children:[l.modified>0&&(0,$.jsxs)(`span`,{className:`text-[var(--status-warning)]`,children:[`M`,l.modified]}),l.added>0&&(0,$.jsxs)(`span`,{className:`text-[var(--status-success)]`,children:[`+`,l.added]})]}),t[48]=l,t[49]=x,t[50]=V):V=t[50];let oe;t[51]!==A||t[52]!==R||t[53]!==ae||t[54]!==z||t[55]!==B||t[56]!==V||t[57]!==re?(oe=(0,$.jsxs)(`button`,{type:`button`,onClick:A,onContextMenu:re,className:R,children:[ae,z,B,V]}),t[51]=A,t[52]=R,t[53]=ae,t[54]=z,t[55]=B,t[56]=V,t[57]=re,t[58]=oe):oe=t[58];let se;t[59]!==s||t[60]!==C||t[61]!==w||t[62]!==T||t[63]!==S||t[64]!==E||t[65]!==f||t[66]!==M||t[67]!==o||t[68]!==n.path||t[69]!==P||t[70]!==p?(se=(S||C||w||T||E)&&(0,$.jsx)(`div`,{className:J(`absolute right-1 top-1/2 -translate-y-1/2`,s?`opacity-100`:`opacity-0 focus-within:opacity-100 group-hover:opacity-100`),children:(0,$.jsxs)(Ve,{open:f===n.path,onOpenChange:e=>p(e?n.path:null),children:[(0,$.jsx)(Ke,{asChild:!0,children:(0,$.jsx)(X,{variant:`ghost`,size:`icon`,className:`size-6`,onClick:M,children:(0,$.jsx)(Y,{name:`more-2-fill`,className:`size-4`})})}),(0,$.jsx)(Ge,{align:`end`,side:`bottom`,onCloseAutoFocus:()=>p(null),children:P({Item:Je,Separator:Ie})})]})}),t[59]=s,t[60]=C,t[61]=w,t[62]=T,t[63]=S,t[64]=E,t[65]=f,t[66]=M,t[67]=o,t[68]=n.path,t[69]=P,t[70]=p,t[71]=se):se=t[71];let H;t[72]!==oe||t[73]!==se||t[74]!==L?(H=(0,$.jsxs)(ln,{render:L,children:[oe,se]}),t[72]=oe,t[73]=se,t[74]=L,t[75]=H):H=t[75];let U;t[76]===P?U=t[77]:(U=(0,$.jsx)(dn,{className:`min-w-[180px]`,children:P({Item:pn,Separator:sn})}),t[76]=P,t[77]=U);let W;return t[78]!==H||t[79]!==U||t[80]!==F||t[81]!==I?(W=(0,$.jsxs)(on,{open:F,onOpenChange:I,children:[H,U]}),t[78]=H,t[79]=U,t[80]=F,t[81]=I,t[82]=W):W=t[82],W},Ma=e=>{let t=(0,Sn.c)(83),{activeDialog:n,dialogData:r,dialogInputValue:i,onDialogInputChange:a,isDialogSubmitting:o,onDialogSubmit:s,onClose:c,inputRef:l}=e,{t:u}=ee(),d=!!n,f;t[0]===c?f=t[1]:(f=e=>!e&&c(),t[0]=c,t[1]=f);let p;t[2]!==n||t[3]!==u?(p=n===`createFile`&&u(`filesView.dialog.createFile.title`),t[2]=n,t[3]=u,t[4]=p):p=t[4];let m;t[5]!==n||t[6]!==u?(m=n===`createFolder`&&u(`filesView.dialog.createFolder.title`),t[5]=n,t[6]=u,t[7]=m):m=t[7];let h;t[8]!==n||t[9]!==u?(h=n===`rename`&&u(`filesView.dialog.rename.title`),t[8]=n,t[9]=u,t[10]=h):h=t[10];let g;t[11]!==n||t[12]!==u?(g=n===`delete`&&u(`filesView.dialog.delete.title`),t[11]=n,t[12]=u,t[13]=g):g=t[13];let _;t[14]!==p||t[15]!==m||t[16]!==h||t[17]!==g?(_=(0,$.jsxs)(be,{children:[p,m,h,g]}),t[14]=p,t[15]=m,t[16]=h,t[17]=g,t[18]=_):_=t[18];let v;t[19]!==n||t[20]!==r?.path||t[21]!==u?(v=n===`createFile`&&u(`filesView.dialog.createFile.description`,{path:r?.path??u(`filesView.dialog.rootFallback`)}),t[19]=n,t[20]=r?.path,t[21]=u,t[22]=v):v=t[22];let y;t[23]!==n||t[24]!==r?.path||t[25]!==u?(y=n===`createFolder`&&u(`filesView.dialog.createFolder.description`,{path:r?.path??u(`filesView.dialog.rootFallback`)}),t[23]=n,t[24]=r?.path,t[25]=u,t[26]=y):y=t[26];let b;t[27]!==n||t[28]!==r?.name||t[29]!==u?(b=n===`rename`&&u(`filesView.dialog.rename.description`,{name:r?.name??``}),t[27]=n,t[28]=r?.name,t[29]=u,t[30]=b):b=t[30];let x;t[31]!==n||t[32]!==r?.name||t[33]!==u?(x=n===`delete`&&u(`filesView.dialog.delete.description`,{name:r?.name??``}),t[31]=n,t[32]=r?.name,t[33]=u,t[34]=x):x=t[34];let S;t[35]!==b||t[36]!==x||t[37]!==v||t[38]!==y?(S=(0,$.jsxs)(xe,{children:[v,y,b,x]}),t[35]=b,t[36]=x,t[37]=v,t[38]=y,t[39]=S):S=t[39];let C;t[40]!==S||t[41]!==_?(C=(0,$.jsxs)(_e,{children:[_,S]}),t[40]=S,t[41]=_,t[42]=C):C=t[42];let w;t[43]!==n||t[44]!==i||t[45]!==l||t[46]!==a||t[47]!==s||t[48]!==u?(w=n!==`delete`&&(0,$.jsx)(`div`,{className:`py-4`,children:(0,$.jsx)(ke,{value:i,onChange:e=>a(e.target.value),placeholder:u(n===`rename`?`filesView.dialog.rename.placeholder`:`filesView.dialog.namePlaceholder`),onKeyDown:e=>{e.key===`Enter`&&s()},ref:l})}),t[43]=n,t[44]=i,t[45]=l,t[46]=a,t[47]=s,t[48]=u,t[49]=w):w=t[49];let T;t[50]===u?T=t[51]:(T=u(`filesView.dialog.cancel`),t[50]=u,t[51]=T);let E;t[52]!==o||t[53]!==c||t[54]!==T?(E=(0,$.jsx)(X,{variant:`outline`,onClick:c,disabled:o,children:T}),t[52]=o,t[53]=c,t[54]=T,t[55]=E):E=t[55];let D=n===`delete`?`destructive`:`default`,O;t[56]===s?O=t[57]:(O=()=>void s(),t[56]=s,t[57]=O);let k;t[58]!==n||t[59]!==i||t[60]!==o?(k=o||n!==`delete`&&!i.trim(),t[58]=n,t[59]=i,t[60]=o,t[61]=k):k=t[61];let A;t[62]!==n||t[63]!==o||t[64]!==u?(A=o?(0,$.jsx)(Y,{name:`loader-4`,className:`size-4 animate-spin`}):u(n===`delete`?`filesView.dialog.delete.confirm`:`filesView.dialog.confirm`),t[62]=n,t[63]=o,t[64]=u,t[65]=A):A=t[65];let j;t[66]!==D||t[67]!==O||t[68]!==k||t[69]!==A?(j=(0,$.jsx)(X,{variant:D,onClick:O,disabled:k,children:A}),t[66]=D,t[67]=O,t[68]=k,t[69]=A,t[70]=j):j=t[70];let M;t[71]!==E||t[72]!==j?(M=(0,$.jsxs)(ve,{children:[E,j]}),t[71]=E,t[72]=j,t[73]=M):M=t[73];let N;t[74]!==l||t[75]!==C||t[76]!==w||t[77]!==M?(N=(0,$.jsxs)(ye,{initialFocus:l,children:[C,w,M]}),t[74]=l,t[75]=C,t[76]=w,t[77]=M,t[78]=N):N=t[78];let P;return t[79]!==d||t[80]!==f||t[81]!==N?(P=(0,$.jsx)(Se,{open:d,onOpenChange:f,children:N}),t[79]=d,t[80]=f,t[81]=N,t[82]=P):P=t[82],P},Na=(e,t,n)=>e&&!!t&&n===t,Pa=(e,n,a)=>{let o=(0,Sn.c)(8),[c,l]=Q.useState(``),[u,d]=Q.useState(0),f,p;o[0]!==e||o[1]!==a||o[2]!==n?(f=()=>{if(!e){l(``);return}let o=!1;l(``);let c=t(),u=r(c);s(c).then(t=>{o||!t||(l(e),n(null))}).catch(t=>{o||(n(t instanceof Error?t.message:a),l(e))});let f=i(()=>{o||(l(e),d(Ia),n(null))});return()=>{o=!0,u(),f()}},p=[e,n,a],o[0]=e,o[1]=a,o[2]=n,o[3]=f,o[4]=p):(f=o[3],p=o[4]),Q.useEffect(f,p);let m;return o[5]!==u||o[6]!==c?(m={readyKey:c,nonce:u},o[5]=u,o[6]=c,o[7]=m):m=o[7],m},Fa=({mode:e=`full`,isActive:t=!0})=>{let{t:n}=ee(),{files:r,runtime:i}=Tt(),{currentTheme:o,availableThemes:s,lightThemeId:l,darkThemeId:d}=Ne(),{isMobile:f,isTablet:p,screenWidth:m}=Ye(),v=f||p,y=g(),S=u(),C=Ht()??``,w=la(C.trim()),T=f||e!==`editor-only`,O=e===`editor-only`&&!f,k=E(e=>e.searchFiles),A=jt(C),[j,N]=Q.useState(``),P=Dt(j,200),F=Q.useRef(null),[I,ne]=Q.useState(!1),[L,ie]=Q.useState(!0),[R,ae]=Q.useState(!1),[z,B]=Q.useState(!1),[V,oe]=Q.useState(!1),[se,H]=Q.useState({open:!1,title:``,content:``}),U=Q.useRef(null),W=Q.useRef(0),K=Q.useCallback(e=>{W.current=Math.max(0,W.current+(e?1:-1))},[]),ce=Q.useCallback(e=>e instanceof Element&&e.closest(`[data-slot="dropdown-menu-content"], [data-slot="dropdown-menu-item"]`)!==null,[]);Q.useEffect(()=>{if(!V)return;let e=e=>{W.current>0||ce(e.target)||U.current&&!U.current.contains(e.target)&&oe(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[ce,V]);let[le,q]=Q.useState(`edit`),[ue,de]=Q.useState(`edit`),[pe,me]=Q.useState(`edit`),[he,ge]=Q.useState(`preview`),[Ce,De]=Q.useState(0),Oe=Q.useRef({}),Pe=Q.useRef({}),Ie=Q.useRef({}),Le=Q.useRef({}),ze=Q.useMemo(()=>s.find(e=>e.metadata.id===l)??et(!1),[s,l]),Ue=Q.useMemo(()=>s.find(e=>e.metadata.id===d)??et(!0),[s,d]);Q.useEffect(()=>{Pt(ze),Pt(Ue)},[ze,Ue]);let qe=Q.useMemo(()=>[],[]),Xe=Et(e=>w?e.byRoot[w]?.openPaths??qe:qe),Ze=Et(e=>w?e.byRoot[w]?.selectedPath??null:null),Qe=Et(e=>w?e.byRoot[w]?.expandedPaths??qe:qe),$e=Et(e=>e.addOpenPath),nt=Et(e=>e.removeOpenPath),rt=Et(e=>e.removeOpenPathsByPrefix),it=Et(e=>e.removeExpandedPathsByPrefix),at=Et(e=>e.setSelectedPath),ot=Et(e=>e.toggleExpandedPath),st=Et(e=>e.expandPaths),ct=Q.useCallback(e=>{let t=la(e),n=t.split(`/`),r=n[n.length-1]||t;return{name:r,path:t,type:`file`,extension:r.includes(`.`)?r.split(`.`).pop()?.toLowerCase():void 0}},[]),lt=Q.useMemo(()=>Xe.map(ct),[Xe,ct]),ut=Q.useMemo(()=>{if(Ze){let e=da(Ze);if(Xe.some(t=>da(t)===e))return Ze}return Xe[0]??null},[Xe,Ze]),Z=Q.useMemo(()=>ut?ct(ut):null,[ut,ct]),dt=Z?.path??``;Q.useEffect(()=>{if(!w||!Ze)return;let e=da(Ze);Xe.some(t=>da(t)===e)||at(w,Xe[0]??null)},[Xe,w,Ze,at]);let ft=!!(w&&dt&&!fa(dt,w)),pt=ft?Ut(dt):void 0,mt=Q.useMemo(()=>({allowOutsideWorkspace:e===`editor-only`&&ft,outsideFileGrant:pt,directory:w||void 0}),[e,ft,pt,w]),gt=Q.useRef(null),[_t,vt]=Q.useState({left:!1,right:!1}),yt=Q.useCallback(()=>{let e=gt.current;e&&vt({left:e.scrollLeft>2,right:e.scrollLeft+e.clientWidth<e.scrollWidth-2})},[]),bt=Q.useRef(yt);bt.current=yt,Q.useEffect(()=>{let e=gt.current;if(!e)return;let t=()=>bt.current();t(),e.addEventListener(`scroll`,t,{passive:!0});let n=new ResizeObserver(t);return n.observe(e),()=>{e.removeEventListener(`scroll`,t),n.disconnect()}},[lt.length]);let[xt,Ct]=Q.useState({}),[wt,Ot]=Q.useState({}),kt=Q.useRef(new Set),At=Q.useRef(new Set),Ft=Q.useRef(!1),It=Q.useRef(new Map),Wt=Q.useRef(0),[Gt,Kt]=Q.useState([]),[Jt,Yt]=Q.useState(!1),[Xt,Zt]=Q.useState(``),{isPlaying:Qt,play:$t,stop:en}=ht(),[tn,nn]=Q.useState(!1),[rn,an]=Q.useState(null),[on,sn]=Q.useState(``),ln=Q.useRef(``),[dn,pn]=Q.useState(null),[hn,gn]=Q.useState(``),[_n,yn]=Q.useState(!1),[bn,xn]=Q.useState(`
|
|
152
152
|
`),Sn=Q.useRef(null),Cn=Q.useRef(null),wn=Q.useRef(null),Tn=Q.useRef(``),En=Q.useRef(``),Dn=Q.useRef(null),On=Q.useRef(null),kn=Q.useRef(null),An=Q.useRef(0),[jn,Mn]=Q.useState(`idle`),[Nn,Pn]=Q.useState(!1),[Fn,In]=Q.useState(Da),[Ln,Rn]=Q.useState(!1),zn=Q.useRef(null),Bn=Q.useRef(null),Vn=Q.useRef(null),Hn=Q.useRef(!1),Un=Q.useRef(null),Wn=Q.useRef(null),qn=Q.useRef(null),Jn=Q.useRef(null),[Yn,Xn]=Q.useState(0),Zn=Q.useRef(null),Qn=Q.useRef({key:``,attempts:0});Q.useEffect(()=>()=>{Zn.current!==null&&typeof window<`u`&&(window.cancelAnimationFrame(Zn.current),Zn.current=null)},[]);let[er,tr]=Q.useState(null),[nr,rr]=Q.useState(null),[ir,or]=Q.useState(``),[sr,cr]=Q.useState(!1),[lr,ur]=Q.useState(null),[dr,fr]=Q.useState(null),[pr,mr]=Q.useState(!1),[hr,gr]=Q.useState(!1),[_r,vr]=Q.useState(!1),[yr,br]=Q.useState(!1),[xr,Sr]=Q.useState(null),Cr=re(e=>e.addCodeSelectionAttachment),wr=re(e=>e.setPendingInputText),Tr=!!r.writeFile,Er=!!r.createDirectory,Dr=!!r.rename,Or=!!r.delete,kr=!!r.revealPath,Ar=ia(e=>e.availableApps),jr=ia(e=>e.isCacheStale),Mr=ia(e=>e.initialize),Nr=ia(e=>e.loadInstalledApps);Q.useEffect(()=>{Mr()},[Mr]);let Pr=Q.useCallback(e=>{r.revealPath&&r.revealPath(e).catch(()=>{G.error(n(`sidebarFilesTree.toast.revealFailed`))})},[r,n]),Fr=Q.useCallback(async e=>{if(!Z?.path||await b(Z.path,e.id,e.appName)||await h(Z.path,e.appName))return;let t=oa(Z.path)||w;t&&await h(t,e.appName)||G.error(n(`filesView.toast.openInAppFailed`,{app:e.appName}))},[w,Z?.path,n]),Ir=Q.useCallback((e,t)=>{tr(e),rr(t),or(e===`rename`&&t.name||``),cr(!1)},[]),[Lr,Rr]=Q.useState(null),zr=Q.useRef(!1),Br=Q.useRef(null),[Vr,Hr]=Q.useState(!1),Ur=c(e=>e.setMainTabGuard),Wr=c(e=>e.pendingFileNavigation),Gr=c(e=>e.setPendingFileNavigation),Kr=c(e=>e.pendingFileFocusPath),qr=c(e=>e.setPendingFileFocusPath),Jr=c(e=>e.shortcutOverrides),Yr=c(e=>e.fileEditorKeymap),Xr=fe(e=>e.settingsDefaultFileViewerPreview),Zr=fe(e=>e.showMessageTTSButtons),Qr=c(e=>e.expandedEditorToolbar);Q.useEffect(()=>{let e=()=>{zr.current=!1,Br.current=null,Hr(!1)};return document.addEventListener(`mouseup`,e),()=>document.removeEventListener(`mouseup`,e)},[]),Q.useEffect(()=>()=>{Un.current!==null&&window.clearTimeout(Un.current),Wn.current!==null&&window.clearTimeout(Wn.current)},[]);let $r=Q.useCallback((e,t)=>{let n=e.split(`
|
|
153
153
|
`),r=Math.max(1,t.start),i=Math.min(n.length,t.end);return r>i?``:n.slice(r-1,i).join(`
|
|
154
|
-
`)},[]),{drafts:ei,commentText:ti,setCommentText:ni,editingDraftId:ri,setSelection:ii,saveComment:ai,cancel:oi,reset:si,startEdit:ci,deleteDraft:li}=Kn({source:`file`,fileLabel:Z?.path??null,language:Z?.path&&Vt(Z.path)||`text`,getCodeForRange:e=>$r(Xt,Gn(e)),toStoreRange:e=>({startLine:e.start,endLine:e.end}),fromDraftRange:e=>({start:e.startLine,end:e.endLine})});Q.useEffect(()=>{Rr(null),si(),Ur(null),gn(``),yn(!1)},[Z?.path,si,Ur]),Q.useEffect(()=>{ii(Lr)},[Lr,ii]),Q.useEffect(()=>{if(!Lr&&!ri)return;let e=e=>{let t=e.target;t.closest(`[data-comment-input="true"]`)||t.closest(`[data-comment-card="true"]`)||t.closest(`.cm-gutterElement`)||t.closest(`[data-sonner-toast]`)||t.closest(`[data-sonner-toaster]`)||ti.trim()||(Rr(null),oi())},t=setTimeout(()=>{document.addEventListener(`click`,e)},100);return()=>{clearTimeout(t),document.removeEventListener(`click`,e)}},[oi,ti,ri,Lr]);let ui=Q.useCallback((e,t)=>{let n=t??Lr??void 0;t&&Rr(t),ai(e,n),Rr(null)},[Lr,ai]),di=Q.useCallback((e,t)=>{let n=[];for(let r of t){if(!(r&&typeof r.name==`string`&&r.name.length>0)||!y&&r.name.startsWith(`.`)||!S&&va(r.name))continue;let t=r.name,i=la(r.path||``),a=i?ua(i)?i:la(`${e}/${i}`):la(`${e}/${t}`),o=r.isDirectory?`directory`:`file`,s=o===`file`&&t.includes(`.`)?t.split(`.`).pop()?.toLowerCase():void 0;n.push({name:t,path:a,type:o,extension:s})}return ca(n)},[S,y]),fi=Q.useCallback(async e=>{let t=la(e.trim());if(!t||kt.current.has(t)||At.current.has(t))return;At.current=new Set(At.current),At.current.add(t);let n=Wt.current+1;Wt.current=n,It.current=new Map(It.current),It.current.set(t,n);let i=()=>It.current.get(t)===n;await(r.listDirectory?r.listDirectory(t).then(e=>e.entries.map(e=>({name:e.name,path:e.path,isDirectory:e.isDirectory}))):D.listLocalDirectory(t).then(e=>e.map(e=>({name:e.name,path:e.path,isDirectory:e.isDirectory})))).then(e=>{if(!i())return;let n=di(t,e);kt.current=new Set(kt.current),kt.current.add(t),Ot(e=>{if(!e[t])return e;let n={...e};return delete n[t],n}),Ct(e=>({...e,[t]:n}))}).catch(e=>{if(!i())return;let n=e instanceof Error?e.message:String(e??``);if(n===`Directory not found`&&w&&t!==w){it(w,t),Ot(e=>{if(!e[t])return e;let n={...e};return delete n[t],n});return}console.error(`Failed to load files directory:`,e),Ot(e=>({...e,[t]:n}))}).finally(()=>{i()&&(It.current=new Map(It.current),It.current.delete(t),At.current=new Set(At.current),At.current.delete(t))})},[r,di,it,w]),pi=Q.useCallback(async()=>{w&&(kt.current=new Set,At.current=new Set,It.current=new Map,Ot({}),Ct(e=>Object.keys(e).length===0?e:{}),await fi(w))},[fi,w]),mi=Q.useCallback(async e=>{if(!e){await pi();return}let t=la(e);kt.current=new Set(kt.current),kt.current.delete(t),At.current=new Set(At.current),At.current.delete(t),await fi(t)},[fi,pi]),hi=Q.useRef(``),gi=Q.useRef(``);Q.useEffect(()=>{if(!w)return;let e=`${w}|h${y?`1`:`0`}|g${S?`1`:`0`}`,t=hi.current!==w,n=gi.current!==e;!t&&!n||(t&&(hi.current=w,Zt(``),an(null),sn(``),pn(null),ne(!1)),n&&(gi.current=e,Ft.current=!1,kt.current=new Set,At.current=new Set,It.current=new Map,Ot({}),Ct(e=>Object.keys(e).length===0?e:{}),fi(w)))},[fi,w,S,y]),Q.useEffect(()=>{if(!r.listDirectory)return;let e=()=>{if(!document.hidden&&Qe.length>0)for(let e of Qe)mi(e)};return document.addEventListener(`visibilitychange`,e),()=>document.removeEventListener(`visibilitychange`,e)},[Qe,r.listDirectory,mi]),Q.useEffect(()=>{if(!w||Qe.length===0)return;let e=Qe.map(e=>la(e)).filter(e=>!!e&&e!==w&&e.startsWith(`${w}/`)&&!kt.current.has(e)&&!At.current.has(e)).sort((e,t)=>e.split(`/`).length-t.split(`/`).length);if(e.length===0)return;let t=!1;return(async()=>{for(let n=0;n<e.length&&!t;n+=3){let t=e.slice(n,n+3);await Promise.all(t.map(e=>fi(e)))}})(),()=>{t=!0}},[Qe,fi,w]);let _i=Q.useCallback(async e=>{if(e?.preventDefault(),!nr||!er)return;cr(!0);let t=()=>{tr(null)},i=e=>{G.error(e)},a=()=>{cr(!1)};if(er===`createFile`){if(!ir.trim()){i(n(`sidebarFilesTree.toast.filenameRequired`)),a();return}if(!r.writeFile){i(n(`sidebarFilesTree.toast.writeNotSupported`)),a();return}let e=nr.path,o=la(`${e?`${e}/`:``}${ir.trim()}`);await r.writeFile(o,``).then(async r=>{r.success&&(G.success(n(`sidebarFilesTree.toast.fileCreated`)),await mi(e)),t()}).catch(()=>i(n(`sidebarFilesTree.toast.operationFailed`))).finally(a);return}if(er===`createFolder`){if(!ir.trim()){i(n(`sidebarFilesTree.toast.folderNameRequired`)),a();return}let e=nr.path,o=la(`${e?`${e}/`:``}${ir.trim()}`);await r.createDirectory(o).then(async r=>{r.success&&(G.success(n(`sidebarFilesTree.toast.folderCreated`)),await mi(e)),t()}).catch(()=>i(n(`sidebarFilesTree.toast.operationFailed`))).finally(a);return}if(er===`rename`){if(!ir.trim()){i(n(`sidebarFilesTree.toast.nameRequired`)),a();return}if(!r.rename){i(n(`sidebarFilesTree.toast.renameNotSupported`)),a();return}let e=nr.path,o=e.split(`/`).slice(0,-1).join(`/`),s=la(`${o?`${o}/`:``}${ir.trim()}`);await r.rename(e,s).then(async r=>{r.success&&(G.success(n(`sidebarFilesTree.toast.renamedSuccessfully`)),await mi(o),w&&rt(w,e),(Z?.path===e||Z?.path.startsWith(`${e}/`))&&(w&&at(w,null),Zt(``),an(null),sn(``),pn(null),f&&ne(!1))),t()}).catch(()=>i(n(`sidebarFilesTree.toast.operationFailed`))).finally(a);return}if(er===`delete`){if(!r.delete){i(n(`sidebarFilesTree.toast.deleteNotSupported`)),a();return}let e=nr.path,o=e.split(`/`).slice(0,-1).join(`/`);await r.delete(e).then(async r=>{r.success&&(G.success(n(`sidebarFilesTree.toast.deletedSuccessfully`)),await mi(o),w&&rt(w,e),(Z?.path===e||Z?.path.startsWith(`${e}/`))&&(w&&at(w,null),Zt(``),an(null),sn(``),pn(null),f&&ne(!1))),t()}).catch(()=>i(n(`sidebarFilesTree.toast.operationFailed`))).finally(a);return}a()},[er,nr,ir,r,mi,f,rt,w,Z?.path,at,n]);Q.useEffect(()=>{if(!C){Kt([]),Yt(!1);return}let e=P.trim();if(!e){Kt([]),Yt(!1);return}let t=!1;return Yt(!0),k(C,e,150,{includeHidden:y,respectGitignore:!S,type:`file`}).then(e=>{if(t)return;let n=e.filter(e=>S||!ya(e.path)).map(e=>({name:e.name,path:la(e.path),type:`file`,extension:e.extension,relativePath:e.relativePath}));Kt(n)}).catch(()=>{t||Kt([])}).finally(()=>{t||Yt(!1)}),()=>{t=!0}},[C,P,k,y,S]);let vi=Q.useCallback(async(e,t)=>{if(r.readFile)return(await r.readFile(e,{...t??{},directory:w||void 0})).content??``;let i=new URLSearchParams({path:e});t?.allowOutsideWorkspace&&i.set(`allowOutsideWorkspace`,`true`),t?.outsideFileGrant&&i.set(`outsideFileGrant`,t.outsideFileGrant),t?.optional&&i.set(`optional`,`true`),w&&i.set(`directory`,w);let a=await _(`/api/fs/read?${i.toString()}`,{cache:t?.optional?`no-store`:`default`});if(!a.ok){let e=await a.json().catch(()=>({error:a.statusText}));throw Error(e.error||n(`filesView.error.readFileFailed`))}return a.text()},[r,w,n]),yi=Q.useCallback(async(e,t)=>{if(r.statFile){let n=await r.statFile(e,{...t??{},directory:w||void 0});return{path:n.path,size:n.size,mtimeMs:n.mtimeMs}}return null},[r,w]);Q.useEffect(()=>{if(!w||!r.statFile||Xe.length===0)return;let e=!1,t=[...Xe];return Promise.all(t.map(async t=>{try{let n=await r.statFile?.(t,{directory:w||void 0});!e&&n&&!n.isFile&&rt(w,t)}catch(n){!e&&xa(n)&&rt(w,t)}})),()=>{e=!0}},[r,Xe,rt,w]);let bi=Q.useMemo(()=>Xt.length>Sa?`${Xt.slice(0,Sa)}\n\n… truncated …`:Xt,[Xt]),xi=hn!==bi,Si=Q.useCallback(async()=>{if(!Z||!r.writeFile)return G.error(n(`filesView.toast.savingNotSupported`)),!1;if(!xi)return!0;if(hn===``&&Xt!==``&&dn!==Z.path)return console.warn(`[saveDraft] refusing to save empty draft for "${Z.path}" (${Xt.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;yn(!0);try{let e=Ea(hn,bn);return(await r.writeFile(Z.path,e))?.success?(Zt(hn),Z?.path&&Bt(Z.path)&&(Tn.current=hn,En.current=hn),yi(Z.path).then(e=>{e&&(kn.current=e)}).catch(()=>{}),!0):(G.error(n(`filesView.toast.writeFileFailed`)),!1)}catch(e){return G.error(e instanceof Error?e.message:n(`filesView.toast.saveFailed`)),!1}finally{yn(!1)}},[hn,Xt,r,xi,bn,dn,yi,Z,n]);Q.useEffect(()=>{if(!xi){Ur(null);return}let e=e=>Hn.current?(Hn.current=!1,!0):(Rn(!0),Bn.current=e,!1);return Ur(e),()=>{c.getState().mainTabGuard===e&&Ur(null)}},[xi,Ur]),Q.useEffect(()=>{try{window.localStorage.setItem(Ca,Fn?`true`:`false`)}catch{}},[Fn]),Q.useEffect(()=>{Fn||(Mn(`idle`),Cn.current&&=(clearTimeout(Cn.current),null))},[Fn]);let Ci=1500;Q.useEffect(()=>{let e=!!(Z&&r.writeFile);if(!(!Fn||!xi||!e||_n))return Cn.current=setTimeout(()=>{Si().then(e=>{e&&(Mn(`saved`),setTimeout(()=>Mn(`idle`),2e3))})},Ci),()=>{Cn.current&&=(clearTimeout(Cn.current),null)}},[Fn,hn,xi,Z,r.writeFile,_n,Si]),Q.useEffect(()=>{Mn(`idle`)},[Z?.path]),Q.useEffect(()=>{let e=e=>{Te(e)&&(e.key.toLowerCase()===`s`?(e.preventDefault(),Cn.current&&=(clearTimeout(Cn.current),null),_n||Si().then(e=>{e&&(Mn(`saved`),setTimeout(()=>Mn(`idle`),2e3))})):e.key.toLowerCase()===`f`&&(e.preventDefault(),B(!0)))};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[_n,Si]);let wi=Q.useCallback(async t=>{let r=An.current+1;An.current=r;let a=()=>{if(!w)return!1;let e=Et.getState().byRoot[w],n=e?.selectedPath??e?.openPaths[0]??null;return An.current===r&&n===t.path};an(null),sn(``),pn(null);let o=zt(t.path),s=t.path.toLowerCase().endsWith(`.svg`),c=Rt(t.path);if(f&&ne(!0),i.isDesktop&&o&&!s){Zt(``),gn(``),nn(!0);return}if(!i.isDesktop&&o&&!s){Zt(``),gn(``),pn(t.path),nn(!1);return}if(c){Zt(``),gn(``),pn(t.path),nn(!1);return}nn(!0);let l=Ut(t.path),u={allowOutsideWorkspace:e===`editor-only`&&!!w&&!fa(t.path,w),outsideFileGrant:l};await vi(t.path,u).then(e=>{if(!a())return;let n=Ta(e);xn(wa(e)),Zt(n),Tn.current=n,En.current=n,gn(n.length>Sa?`${n.slice(0,Sa)}\n\n… truncated …`:n),pn(t.path),yi(t.path,u).then(e=>{e&&a()&&(kn.current=e)}).catch(()=>{})}).catch(e=>{if(a()){if(ba(e)){if(nn(!1),w&&at(w,null),an(null),Zt(``),gn(``),pn(null),kn.current=null,j.trim().length>0&&N(``),f&&ne(!1),w){let e=[...pa(t.path,w),t.path];e.length>0&&st(w,e);for(let t of e)kt.current.has(t)||fi(t)}return}if(xa(e)){w&&rt(w,t.path),Zt(``),gn(``),an(null),kn.current=null,f&&ne(!1);return}Zt(``),gn(``),an(e instanceof Error?e.message:n(`filesView.error.readFileFailed`)),kn.current=null}}).finally(()=>{a()&&nn(!1)})},[st,f,fi,e,vi,yi,rt,w,i.isDesktop,j,at,n]),Ti=Q.useCallback(async(e,t)=>{if(!w)return;let n=pa(e,w),r=t?[...n,e]:n;r.length>0&&st(w,r);let i=r.map(e=>{if(!kt.current.has(e))return fi(e)}).filter(Boolean);await Promise.all(i)},[st,fi,w]),Ei=Q.useCallback((e,t)=>{let n=t.findIndex(t=>t.path===e);return n===-1||t.length<=1?null:t[n+1]??t[n-1]??null},[]),Di=Q.useCallback(async e=>{if(Hn.current)Hn.current=!1;else if(xi){Rn(!0),zn.current=e;return}w&&(at(w,e.path),$e(w,e.path),Ti(e.path,!1)),an(null),sn(``),Zt(``),Tn.current=``,En.current=``,gn(``),pn(null),f&&ne(!0)},[$e,Ti,xi,f,w,at]);Q.useEffect(()=>{Z?.path&&Ti(Z.path,!1)},[Ti,Z?.path]),Q.useEffect(()=>{if(!Z){An.current+=1,nn(!1);return}dn!==Z.path&&wi(Z)},[wi,dn,Z]);let Oi=Q.useRef(xi);Oi.current=xi,Q.useEffect(()=>{let e=Z?.path??``;if(!Na(t,e,dn))return;let n=!1,r=window.setInterval(()=>{document.hidden||yi(e,mt).then(t=>{if(n||!t)return;let r=kn.current;if(!r||r.path!==e){kn.current=t;return}let i=t.mtimeMs!==void 0&&r.mtimeMs!==void 0&&t.mtimeMs!==r.mtimeMs,a=t.size!==r.size;!i&&!a||Oi.current||(kn.current=t,pn(null))}).catch(()=>{})},2e3);return()=>{n=!0,window.clearInterval(r)}},[t,dn,yi,Z?.path,mt]);let ki=Q.useCallback(()=>{let e=zn.current,t=Bn.current,n=Vn.current;if(zn.current=null,Bn.current=null,Vn.current=null,Hn.current=!0,Rn(!1),gn(bi),n){w&&nt(w,n),Z?.path===n&&(e?Di(e):(w&&at(w,null),Zt(``),an(null),sn(``),pn(null),f&&ne(!1)));return}if(e){Di(e);return}t&&(Ur(null),c.getState().setActiveMainTab(t))},[bi,Di,f,nt,w,Z?.path,Ur,at]),Ai=Q.useCallback(async()=>{let e=zn.current,t=Bn.current,n=Vn.current;if(!await Si()){Hn.current=!1;return}if(zn.current=null,Bn.current=null,Vn.current=null,Hn.current=!0,Rn(!1),n){w&&nt(w,n),Z?.path===n&&(e?await Di(e):(w&&at(w,null),Zt(``),an(null),sn(``),pn(null),f&&ne(!1)));return}if(e){await Di(e);return}t&&(Ur(null),c.getState().setActiveMainTab(t))},[Di,f,nt,w,Si,Z?.path,Ur,at]),ji=Q.useCallback(e=>{let t=Z?.path===e,n=Ei(e,lt);if(t&&xi){Rn(!0),zn.current=n,Vn.current=e;return}if(w&&nt(w,e),t){if(n){Di(n);return}w&&at(w,null),Zt(``),an(null),sn(``),pn(null),f&&ne(!1)}},[Ei,Di,xi,f,lt,nt,w,Z?.path,at]),Mi=Q.useCallback(e=>{if(Xe.includes(e))return`open`;if(A?.files){let t=e.startsWith(w+`/`)?e.slice(w.length+1):e,n=A.files.find(e=>e.path===t);if(n){if(n.index===`A`||n.working_dir===`?`)return`git-added`;if(n.index===`D`)return`git-deleted`;if(n.index===`M`||n.working_dir===`M`)return`git-modified`}}return null},[Xe,A,w]),Ni=Q.useCallback(e=>{if(!A?.files)return null;let t=e.startsWith(w+`/`)?e.slice(w.length+1):e,n=t?`${t}/`:``,r=0,i=0;for(let e of A.files)e.path.startsWith(n)&&((e.index===`M`||e.working_dir===`M`)&&r++,(e.index===`A`||e.working_dir===`?`)&&i++);return r+i>0?{modified:r,added:i}:null},[A,w]),Pi=Q.useCallback(async e=>{let t=la(e);w&&(ot(w,t),kt.current.has(t)||await fi(t))},[fi,w,ot]),Fi=Q.useMemo(()=>w?Vi(w,xt):[],[xt,w]),Ii=Q.useMemo(()=>new Set(Qe.map(e=>la(e))),[Qe]),Li=Hi(Qe),Ri=Q.useCallback(()=>{if(w){if(Li){Ft.current=!1,it(w,w);return}Ft.current=!0,st(w,Fi)}},[Li,Fi,st,it,w]);Q.useEffect(()=>{if(!w||!Ft.current)return;let e=Ui(Fi,Qe);if(e.length>0){st(w,e);return}let t=new Set([...kt.current,...Object.keys(wt)]);Wi(Fi,Qe,t)&&(Ft.current=!1)},[Fi,st,Qe,wt,w]);let Bi=Q.useMemo(()=>({canRename:Dr,canCreateFile:Tr,canCreateFolder:Er,canDelete:Or,canReveal:kr}),[Dr,Tr,Er,Or,kr]);function Gi(e,t){let i=xt[e]??[];return i.map((e,a)=>{let o=e.type===`directory`,s=o&&Ii.has(la(e.path)),c=Z?.path===e.path,l=a===i.length-1;return(0,$.jsxs)(`li`,{className:`relative`,children:[t>0&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`span`,{className:`absolute top-3.5 left-[-12px] w-3 h-px bg-border/40`}),l&&(0,$.jsx)(`span`,{className:`absolute top-3.5 bottom-0 left-[-13px] w-[2px] bg-background`})]}),(0,$.jsx)(ja,{node:e,root:w,isExpanded:s,isActive:c,isMobile:f,alwaysShowActions:v,status:o?void 0:Mi(e.path),badge:o?Ni(e.path):void 0,permissions:Bi,downloadFile:r.downloadFile,contextMenuPath:lr,setContextMenuPath:ur,rightClickMenuPath:dr,setRightClickMenuPath:fr,onSelect:Di,onToggle:Pi,onRevealPath:Pr,onOpenDialog:Ir}),o&&s&&(0,$.jsxs)(`ul`,{className:`flex flex-col gap-1 ml-3 pl-3 border-l border-border/40 relative`,children:[wt[e.path]?(0,$.jsxs)(`li`,{className:`flex items-center gap-2 px-2 py-1 typography-meta text-muted-foreground`,children:[(0,$.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-[var(--status-error)]`,title:wt[e.path],children:wt[e.path]}),(0,$.jsxs)(X,{variant:`ghost`,size:`xs`,className:`h-6 gap-1`,onClick:()=>void mi(e.path),children:[(0,$.jsx)(Y,{name:`refresh`,className:`size-3.5`}),n(`filesView.tree.actions.refreshTitle`)]})]}):null,Gi(e.path,t+1)]})]},e.path)})}let Ki=!!(Z?.path&&zt(Z.path)),qi=!!(Z?.path&&Z.path.toLowerCase().endsWith(`.svg`)),Ji=!!(Z?.path&&Rt(Z.path)),Yi=Q.useMemo(()=>la(Wr?.path??``),[Wr?.path]),Xi=!!(Wr&&Yi&&dt&&dt===Yi&&!tn&&!rn&&!Ki&&!Ji),Zi=Q.useMemo(()=>ma(w,dt),[dt,w]),Qi=Q.useCallback(e=>{let t=!e.state.selection.main.empty;if(br(e=>e===t?e:t),!t){Sr(null);return}let n=e.state.selection.main,r=e.state.doc.lineAt(n.from).from,i=e.coordsAtPos(r);i&&Sr({x:Math.min(window.innerWidth-240,Math.max(8,i.left)),y:Math.max(8,i.top-8)})},[]),$i=Q.useCallback(()=>{let e=qn.current,t=e?.state.selection.main;if(!e||!t||t.empty||!Z)return;let n=e.state.sliceDoc(t.from,t.to),r=e.state.doc.lineAt(t.from).number,i=e.state.doc.lineAt(Math.max(t.from,t.to-1)).number,a=r===i?`${r}`:`${r}-${i}`,o=`${Z.name}:${a}`;Cr(Z.path,o,n),wr(x(o),`append-inline`),Sr(null),c.getState().setActiveMainTab(`chat`)},[Cr,Z,wr]),ea=Q.useCallback(e=>{if(!Z)return;let t=Math.min(e.start,e.end),n=Math.max(e.start,e.end),r=hn.split(`
|
|
154
|
+
`)},[]),{drafts:ei,commentText:ti,setCommentText:ni,editingDraftId:ri,setSelection:ii,saveComment:ai,cancel:oi,reset:si,startEdit:ci,deleteDraft:li}=Kn({source:`file`,fileLabel:Z?.path??null,language:Z?.path&&Bt(Z.path)||`text`,getCodeForRange:e=>$r(Xt,Gn(e)),toStoreRange:e=>({startLine:e.start,endLine:e.end}),fromDraftRange:e=>({start:e.startLine,end:e.endLine})});Q.useEffect(()=>{Rr(null),si(),Ur(null),gn(``),yn(!1)},[Z?.path,si,Ur]),Q.useEffect(()=>{ii(Lr)},[Lr,ii]),Q.useEffect(()=>{if(!Lr&&!ri)return;let e=e=>{let t=e.target;t.closest(`[data-comment-input="true"]`)||t.closest(`[data-comment-card="true"]`)||t.closest(`.cm-gutterElement`)||t.closest(`[data-sonner-toast]`)||t.closest(`[data-sonner-toaster]`)||ti.trim()||(Rr(null),oi())},t=setTimeout(()=>{document.addEventListener(`click`,e)},100);return()=>{clearTimeout(t),document.removeEventListener(`click`,e)}},[oi,ti,ri,Lr]);let ui=Q.useCallback((e,t)=>{let n=t??Lr??void 0;t&&Rr(t),ai(e,n),Rr(null)},[Lr,ai]),di=Q.useCallback((e,t)=>{let n=[];for(let r of t){if(!(r&&typeof r.name==`string`&&r.name.length>0)||!y&&r.name.startsWith(`.`)||!S&&va(r.name))continue;let t=r.name,i=la(r.path||``),a=i?ua(i)?i:la(`${e}/${i}`):la(`${e}/${t}`),o=r.isDirectory?`directory`:`file`,s=o===`file`&&t.includes(`.`)?t.split(`.`).pop()?.toLowerCase():void 0;n.push({name:t,path:a,type:o,extension:s})}return ca(n)},[S,y]),fi=Q.useCallback(async e=>{let t=la(e.trim());if(!t||kt.current.has(t)||At.current.has(t))return;At.current=new Set(At.current),At.current.add(t);let n=Wt.current+1;Wt.current=n,It.current=new Map(It.current),It.current.set(t,n);let i=()=>It.current.get(t)===n;await(r.listDirectory?r.listDirectory(t).then(e=>e.entries.map(e=>({name:e.name,path:e.path,isDirectory:e.isDirectory}))):D.listLocalDirectory(t).then(e=>e.map(e=>({name:e.name,path:e.path,isDirectory:e.isDirectory})))).then(e=>{if(!i())return;let n=di(t,e);kt.current=new Set(kt.current),kt.current.add(t),Ot(e=>{if(!e[t])return e;let n={...e};return delete n[t],n}),Ct(e=>({...e,[t]:n}))}).catch(e=>{if(!i())return;let n=e instanceof Error?e.message:String(e??``);if(n===`Directory not found`&&w&&t!==w){it(w,t),Ot(e=>{if(!e[t])return e;let n={...e};return delete n[t],n});return}console.error(`Failed to load files directory:`,e),Ot(e=>({...e,[t]:n}))}).finally(()=>{i()&&(It.current=new Map(It.current),It.current.delete(t),At.current=new Set(At.current),At.current.delete(t))})},[r,di,it,w]),pi=Q.useCallback(async()=>{w&&(kt.current=new Set,At.current=new Set,It.current=new Map,Ot({}),Ct(e=>Object.keys(e).length===0?e:{}),await fi(w))},[fi,w]),mi=Q.useCallback(async e=>{if(!e){await pi();return}let t=la(e);kt.current=new Set(kt.current),kt.current.delete(t),At.current=new Set(At.current),At.current.delete(t),await fi(t)},[fi,pi]),hi=Q.useRef(``),gi=Q.useRef(``);Q.useEffect(()=>{if(!w)return;let e=`${w}|h${y?`1`:`0`}|g${S?`1`:`0`}`,t=hi.current!==w,n=gi.current!==e;!t&&!n||(t&&(hi.current=w,Zt(``),an(null),sn(``),pn(null),ne(!1)),n&&(gi.current=e,Ft.current=!1,kt.current=new Set,At.current=new Set,It.current=new Map,Ot({}),Ct(e=>Object.keys(e).length===0?e:{}),fi(w)))},[fi,w,S,y]),Q.useEffect(()=>{if(!r.listDirectory)return;let e=()=>{if(!document.hidden&&Qe.length>0)for(let e of Qe)mi(e)};return document.addEventListener(`visibilitychange`,e),()=>document.removeEventListener(`visibilitychange`,e)},[Qe,r.listDirectory,mi]),Q.useEffect(()=>{if(!w||Qe.length===0)return;let e=Qe.map(e=>la(e)).filter(e=>!!e&&e!==w&&e.startsWith(`${w}/`)&&!kt.current.has(e)&&!At.current.has(e)).sort((e,t)=>e.split(`/`).length-t.split(`/`).length);if(e.length===0)return;let t=!1;return(async()=>{for(let n=0;n<e.length&&!t;n+=3){let t=e.slice(n,n+3);await Promise.all(t.map(e=>fi(e)))}})(),()=>{t=!0}},[Qe,fi,w]);let _i=Q.useCallback(async e=>{if(e?.preventDefault(),!nr||!er)return;cr(!0);let t=()=>{tr(null)},i=e=>{G.error(e)},a=()=>{cr(!1)};if(er===`createFile`){if(!ir.trim()){i(n(`sidebarFilesTree.toast.filenameRequired`)),a();return}if(!r.writeFile){i(n(`sidebarFilesTree.toast.writeNotSupported`)),a();return}let e=nr.path,o=la(`${e?`${e}/`:``}${ir.trim()}`);await r.writeFile(o,``).then(async r=>{r.success&&(G.success(n(`sidebarFilesTree.toast.fileCreated`)),await mi(e)),t()}).catch(()=>i(n(`sidebarFilesTree.toast.operationFailed`))).finally(a);return}if(er===`createFolder`){if(!ir.trim()){i(n(`sidebarFilesTree.toast.folderNameRequired`)),a();return}let e=nr.path,o=la(`${e?`${e}/`:``}${ir.trim()}`);await r.createDirectory(o).then(async r=>{r.success&&(G.success(n(`sidebarFilesTree.toast.folderCreated`)),await mi(e)),t()}).catch(()=>i(n(`sidebarFilesTree.toast.operationFailed`))).finally(a);return}if(er===`rename`){if(!ir.trim()){i(n(`sidebarFilesTree.toast.nameRequired`)),a();return}if(!r.rename){i(n(`sidebarFilesTree.toast.renameNotSupported`)),a();return}let e=nr.path,o=e.split(`/`).slice(0,-1).join(`/`),s=la(`${o?`${o}/`:``}${ir.trim()}`);await r.rename(e,s).then(async r=>{r.success&&(G.success(n(`sidebarFilesTree.toast.renamedSuccessfully`)),await mi(o),w&&rt(w,e),(Z?.path===e||Z?.path.startsWith(`${e}/`))&&(w&&at(w,null),Zt(``),an(null),sn(``),pn(null),f&&ne(!1))),t()}).catch(()=>i(n(`sidebarFilesTree.toast.operationFailed`))).finally(a);return}if(er===`delete`){if(!r.delete){i(n(`sidebarFilesTree.toast.deleteNotSupported`)),a();return}let e=nr.path,o=e.split(`/`).slice(0,-1).join(`/`);await r.delete(e).then(async r=>{r.success&&(G.success(n(`sidebarFilesTree.toast.deletedSuccessfully`)),await mi(o),w&&rt(w,e),(Z?.path===e||Z?.path.startsWith(`${e}/`))&&(w&&at(w,null),Zt(``),an(null),sn(``),pn(null),f&&ne(!1))),t()}).catch(()=>i(n(`sidebarFilesTree.toast.operationFailed`))).finally(a);return}a()},[er,nr,ir,r,mi,f,rt,w,Z?.path,at,n]);Q.useEffect(()=>{if(!C){Kt([]),Yt(!1);return}let e=P.trim();if(!e){Kt([]),Yt(!1);return}let t=!1;return Yt(!0),k(C,e,150,{includeHidden:y,respectGitignore:!S,type:`file`}).then(e=>{if(t)return;let n=e.filter(e=>S||!ya(e.path)).map(e=>({name:e.name,path:la(e.path),type:`file`,extension:e.extension,relativePath:e.relativePath}));Kt(n)}).catch(()=>{t||Kt([])}).finally(()=>{t||Yt(!1)}),()=>{t=!0}},[C,P,k,y,S]);let vi=Q.useCallback(async(e,t)=>{if(r.readFile)return(await r.readFile(e,{...t??{},directory:w||void 0})).content??``;let i=new URLSearchParams({path:e});t?.allowOutsideWorkspace&&i.set(`allowOutsideWorkspace`,`true`),t?.outsideFileGrant&&i.set(`outsideFileGrant`,t.outsideFileGrant),t?.optional&&i.set(`optional`,`true`),w&&i.set(`directory`,w);let a=await _(`/api/fs/read?${i.toString()}`,{cache:t?.optional?`no-store`:`default`});if(!a.ok){let e=await a.json().catch(()=>({error:a.statusText}));throw Error(e.error||n(`filesView.error.readFileFailed`))}return a.text()},[r,w,n]),yi=Q.useCallback(async(e,t)=>{if(r.statFile){let n=await r.statFile(e,{...t??{},directory:w||void 0});return{path:n.path,size:n.size,mtimeMs:n.mtimeMs}}return null},[r,w]);Q.useEffect(()=>{if(!w||!r.statFile||Xe.length===0)return;let e=!1,t=[...Xe];return Promise.all(t.map(async t=>{try{let n=await r.statFile?.(t,{directory:w||void 0});!e&&n&&!n.isFile&&rt(w,t)}catch(n){!e&&xa(n)&&rt(w,t)}})),()=>{e=!0}},[r,Xe,rt,w]);let bi=Q.useMemo(()=>Xt.length>Sa?`${Xt.slice(0,Sa)}\n\n… truncated …`:Xt,[Xt]),xi=hn!==bi,Si=Q.useCallback(async()=>{if(!Z||!r.writeFile)return G.error(n(`filesView.toast.savingNotSupported`)),!1;if(!xi)return!0;if(hn===``&&Xt!==``&&dn!==Z.path)return console.warn(`[saveDraft] refusing to save empty draft for "${Z.path}" (${Xt.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;yn(!0);try{let e=Ea(hn,bn);return(await r.writeFile(Z.path,e))?.success?(Zt(hn),Z?.path&&zt(Z.path)&&(Tn.current=hn,En.current=hn),yi(Z.path).then(e=>{e&&(kn.current=e)}).catch(()=>{}),!0):(G.error(n(`filesView.toast.writeFileFailed`)),!1)}catch(e){return G.error(e instanceof Error?e.message:n(`filesView.toast.saveFailed`)),!1}finally{yn(!1)}},[hn,Xt,r,xi,bn,dn,yi,Z,n]);Q.useEffect(()=>{if(!xi){Ur(null);return}let e=e=>Hn.current?(Hn.current=!1,!0):(Rn(!0),Bn.current=e,!1);return Ur(e),()=>{c.getState().mainTabGuard===e&&Ur(null)}},[xi,Ur]),Q.useEffect(()=>{try{window.localStorage.setItem(Ca,Fn?`true`:`false`)}catch{}},[Fn]),Q.useEffect(()=>{Fn||(Mn(`idle`),Cn.current&&=(clearTimeout(Cn.current),null))},[Fn]);let Ci=1500;Q.useEffect(()=>{let e=!!(Z&&r.writeFile);if(!(!Fn||!xi||!e||_n))return Cn.current=setTimeout(()=>{Si().then(e=>{e&&(Mn(`saved`),setTimeout(()=>Mn(`idle`),2e3))})},Ci),()=>{Cn.current&&=(clearTimeout(Cn.current),null)}},[Fn,hn,xi,Z,r.writeFile,_n,Si]),Q.useEffect(()=>{Mn(`idle`)},[Z?.path]),Q.useEffect(()=>{let e=e=>{Te(e)&&(e.key.toLowerCase()===`s`?(e.preventDefault(),Cn.current&&=(clearTimeout(Cn.current),null),_n||Si().then(e=>{e&&(Mn(`saved`),setTimeout(()=>Mn(`idle`),2e3))})):e.key.toLowerCase()===`f`&&(e.preventDefault(),B(!0)))};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[_n,Si]);let wi=Q.useCallback(async t=>{let r=An.current+1;An.current=r;let a=()=>{if(!w)return!1;let e=Et.getState().byRoot[w],n=e?.selectedPath??e?.openPaths[0]??null;return An.current===r&&n===t.path};an(null),sn(``),pn(null);let o=Rt(t.path),s=t.path.toLowerCase().endsWith(`.svg`),c=Lt(t.path);if(f&&ne(!0),i.isDesktop&&o&&!s){Zt(``),gn(``),nn(!0);return}if(!i.isDesktop&&o&&!s){Zt(``),gn(``),pn(t.path),nn(!1);return}if(c){Zt(``),gn(``),pn(t.path),nn(!1);return}nn(!0);let l=Ut(t.path),u={allowOutsideWorkspace:e===`editor-only`&&!!w&&!fa(t.path,w),outsideFileGrant:l};await vi(t.path,u).then(e=>{if(!a())return;let n=Ta(e);xn(wa(e)),Zt(n),Tn.current=n,En.current=n,gn(n.length>Sa?`${n.slice(0,Sa)}\n\n… truncated …`:n),pn(t.path),yi(t.path,u).then(e=>{e&&a()&&(kn.current=e)}).catch(()=>{})}).catch(e=>{if(a()){if(ba(e)){if(nn(!1),w&&at(w,null),an(null),Zt(``),gn(``),pn(null),kn.current=null,j.trim().length>0&&N(``),f&&ne(!1),w){let e=[...pa(t.path,w),t.path];e.length>0&&st(w,e);for(let t of e)kt.current.has(t)||fi(t)}return}if(xa(e)){w&&rt(w,t.path),Zt(``),gn(``),an(null),kn.current=null,f&&ne(!1);return}Zt(``),gn(``),an(e instanceof Error?e.message:n(`filesView.error.readFileFailed`)),kn.current=null}}).finally(()=>{a()&&nn(!1)})},[st,f,fi,e,vi,yi,rt,w,i.isDesktop,j,at,n]),Ti=Q.useCallback(async(e,t)=>{if(!w)return;let n=pa(e,w),r=t?[...n,e]:n;r.length>0&&st(w,r);let i=r.map(e=>{if(!kt.current.has(e))return fi(e)}).filter(Boolean);await Promise.all(i)},[st,fi,w]),Ei=Q.useCallback((e,t)=>{let n=t.findIndex(t=>t.path===e);return n===-1||t.length<=1?null:t[n+1]??t[n-1]??null},[]),Di=Q.useCallback(async e=>{if(Hn.current)Hn.current=!1;else if(xi){Rn(!0),zn.current=e;return}w&&(at(w,e.path),$e(w,e.path),Ti(e.path,!1)),an(null),sn(``),Zt(``),Tn.current=``,En.current=``,gn(``),pn(null),f&&ne(!0)},[$e,Ti,xi,f,w,at]);Q.useEffect(()=>{Z?.path&&Ti(Z.path,!1)},[Ti,Z?.path]),Q.useEffect(()=>{if(!Z){An.current+=1,nn(!1);return}dn!==Z.path&&wi(Z)},[wi,dn,Z]);let Oi=Q.useRef(xi);Oi.current=xi,Q.useEffect(()=>{let e=Z?.path??``;if(!Na(t,e,dn))return;let n=!1,r=window.setInterval(()=>{document.hidden||yi(e,mt).then(t=>{if(n||!t)return;let r=kn.current;if(!r||r.path!==e){kn.current=t;return}let i=t.mtimeMs!==void 0&&r.mtimeMs!==void 0&&t.mtimeMs!==r.mtimeMs,a=t.size!==r.size;!i&&!a||Oi.current||(kn.current=t,pn(null))}).catch(()=>{})},2e3);return()=>{n=!0,window.clearInterval(r)}},[t,dn,yi,Z?.path,mt]);let ki=Q.useCallback(()=>{let e=zn.current,t=Bn.current,n=Vn.current;if(zn.current=null,Bn.current=null,Vn.current=null,Hn.current=!0,Rn(!1),gn(bi),n){w&&nt(w,n),Z?.path===n&&(e?Di(e):(w&&at(w,null),Zt(``),an(null),sn(``),pn(null),f&&ne(!1)));return}if(e){Di(e);return}t&&(Ur(null),c.getState().setActiveMainTab(t))},[bi,Di,f,nt,w,Z?.path,Ur,at]),Ai=Q.useCallback(async()=>{let e=zn.current,t=Bn.current,n=Vn.current;if(!await Si()){Hn.current=!1;return}if(zn.current=null,Bn.current=null,Vn.current=null,Hn.current=!0,Rn(!1),n){w&&nt(w,n),Z?.path===n&&(e?await Di(e):(w&&at(w,null),Zt(``),an(null),sn(``),pn(null),f&&ne(!1)));return}if(e){await Di(e);return}t&&(Ur(null),c.getState().setActiveMainTab(t))},[Di,f,nt,w,Si,Z?.path,Ur,at]),ji=Q.useCallback(e=>{let t=Z?.path===e,n=Ei(e,lt);if(t&&xi){Rn(!0),zn.current=n,Vn.current=e;return}if(w&&nt(w,e),t){if(n){Di(n);return}w&&at(w,null),Zt(``),an(null),sn(``),pn(null),f&&ne(!1)}},[Ei,Di,xi,f,lt,nt,w,Z?.path,at]),Mi=Q.useCallback(e=>{if(Xe.includes(e))return`open`;if(A?.files){let t=e.startsWith(w+`/`)?e.slice(w.length+1):e,n=A.files.find(e=>e.path===t);if(n){if(n.index===`A`||n.working_dir===`?`)return`git-added`;if(n.index===`D`)return`git-deleted`;if(n.index===`M`||n.working_dir===`M`)return`git-modified`}}return null},[Xe,A,w]),Ni=Q.useCallback(e=>{if(!A?.files)return null;let t=e.startsWith(w+`/`)?e.slice(w.length+1):e,n=t?`${t}/`:``,r=0,i=0;for(let e of A.files)e.path.startsWith(n)&&((e.index===`M`||e.working_dir===`M`)&&r++,(e.index===`A`||e.working_dir===`?`)&&i++);return r+i>0?{modified:r,added:i}:null},[A,w]),Pi=Q.useCallback(async e=>{let t=la(e);w&&(ot(w,t),kt.current.has(t)||await fi(t))},[fi,w,ot]),Fi=Q.useMemo(()=>w?Vi(w,xt):[],[xt,w]),Ii=Q.useMemo(()=>new Set(Qe.map(e=>la(e))),[Qe]),Li=Hi(Qe),Ri=Q.useCallback(()=>{if(w){if(Li){Ft.current=!1,it(w,w);return}Ft.current=!0,st(w,Fi)}},[Li,Fi,st,it,w]);Q.useEffect(()=>{if(!w||!Ft.current)return;let e=Ui(Fi,Qe);if(e.length>0){st(w,e);return}let t=new Set([...kt.current,...Object.keys(wt)]);Wi(Fi,Qe,t)&&(Ft.current=!1)},[Fi,st,Qe,wt,w]);let Bi=Q.useMemo(()=>({canRename:Dr,canCreateFile:Tr,canCreateFolder:Er,canDelete:Or,canReveal:kr}),[Dr,Tr,Er,Or,kr]);function Gi(e,t){let i=xt[e]??[];return i.map((e,a)=>{let o=e.type===`directory`,s=o&&Ii.has(la(e.path)),c=Z?.path===e.path,l=a===i.length-1;return(0,$.jsxs)(`li`,{className:`relative`,children:[t>0&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`span`,{className:`absolute top-3.5 left-[-12px] w-3 h-px bg-border/40`}),l&&(0,$.jsx)(`span`,{className:`absolute top-3.5 bottom-0 left-[-13px] w-[2px] bg-background`})]}),(0,$.jsx)(ja,{node:e,root:w,isExpanded:s,isActive:c,isMobile:f,alwaysShowActions:v,status:o?void 0:Mi(e.path),badge:o?Ni(e.path):void 0,permissions:Bi,downloadFile:r.downloadFile,contextMenuPath:lr,setContextMenuPath:ur,rightClickMenuPath:dr,setRightClickMenuPath:fr,onSelect:Di,onToggle:Pi,onRevealPath:Pr,onOpenDialog:Ir}),o&&s&&(0,$.jsxs)(`ul`,{className:`flex flex-col gap-1 ml-3 pl-3 border-l border-border/40 relative`,children:[wt[e.path]?(0,$.jsxs)(`li`,{className:`flex items-center gap-2 px-2 py-1 typography-meta text-muted-foreground`,children:[(0,$.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-[var(--status-error)]`,title:wt[e.path],children:wt[e.path]}),(0,$.jsxs)(X,{variant:`ghost`,size:`xs`,className:`h-6 gap-1`,onClick:()=>void mi(e.path),children:[(0,$.jsx)(Y,{name:`refresh`,className:`size-3.5`}),n(`filesView.tree.actions.refreshTitle`)]})]}):null,Gi(e.path,t+1)]})]},e.path)})}let Ki=!!(Z?.path&&Rt(Z.path)),qi=!!(Z?.path&&Z.path.toLowerCase().endsWith(`.svg`)),Ji=!!(Z?.path&&Lt(Z.path)),Yi=Q.useMemo(()=>la(Wr?.path??``),[Wr?.path]),Xi=!!(Wr&&Yi&&dt&&dt===Yi&&!tn&&!rn&&!Ki&&!Ji),Zi=Q.useMemo(()=>ma(w,dt),[dt,w]),Qi=Q.useCallback(e=>{let t=!e.state.selection.main.empty;if(br(e=>e===t?e:t),!t){Sr(null);return}let n=e.state.selection.main,r=e.state.doc.lineAt(n.from).from,i=e.coordsAtPos(r);i&&Sr({x:Math.min(window.innerWidth-240,Math.max(8,i.left)),y:Math.max(8,i.top-8)})},[]),$i=Q.useCallback(()=>{let e=qn.current,t=e?.state.selection.main;if(!e||!t||t.empty||!Z)return;let n=e.state.sliceDoc(t.from,t.to),r=e.state.doc.lineAt(t.from).number,i=e.state.doc.lineAt(Math.max(t.from,t.to-1)).number,a=r===i?`${r}`:`${r}-${i}`,o=`${Z.name}:${a}`;Cr(Z.path,o,n),wr(x(o),`append-inline`),Sr(null),c.getState().setActiveMainTab(`chat`)},[Cr,Z,wr]),ea=Q.useCallback(e=>{if(!Z)return;let t=Math.min(e.start,e.end),n=Math.max(e.start,e.end),r=hn.split(`
|
|
155
155
|
`).slice(t-1,n).join(`
|
|
156
|
-
`);if(!r)return;let i=t===n?`${t}`:`${t}-${n}`,a=`${Z.name}:${i}`;Cr(Z.path,a,r),wr(x(a),`append-inline`),c.getState().setActiveMainTab(`chat`)},[Cr,hn,Z,wr]),ta=!!(Z&&(!Ki||qi)&&!Ji&&Xt.length>0),na=!!(Z&&Zi.length>0),ra=!!(Z&&!ft&&!Ki&&!Ji&&r.writeFile&&Xt.length<=Sa),ha=!!(Z?.path&&ka(Z.path)),ga=!!(Z?.path&&Aa(Z.path)),Fa=!!(Z?.path&&Bt(Z.path)),Ia=!!(Z&&!Ki&&!Ji),La=Ia&&!ha&&!Fa&&!(ga&&pe===`preview`),Ra=ha&&ue===`edit`||ga&&pe===`edit`||!ha&&!ga&&le===`edit`,za=Q.useMemo(()=>dt?We(dt):null,[dt]),[Ba,Va]=Q.useState(null);Q.useEffect(()=>{let e=!1,t=Z?.path;if(!t||za){Va(null);return}return Va(null),He(t).then(t=>{e||Va(t)}),()=>{e=!0}},[Z?.path,za]),Q.useEffect(()=>{!ra&&le===`edit`&&q(`view`)},[ra,le]);let Ha=`openchamber:files:md-viewer-mode`,Ua=`openchamber:files:html-viewer-mode`;Q.useEffect(()=>{let e=Z?.path;if(!e)return;q(Oe.current[e]??`edit`);let t=Xr?`preview`:`edit`;try{let e=localStorage.getItem(Ha);(e===`preview`||e===`edit`)&&(t=e)}catch{}de(Pe.current[e]??t);let n=Xr?`preview`:`edit`;try{let e=localStorage.getItem(Ua);(e===`preview`||e===`edit`)&&(n=e)}catch{}me(Ie.current[e]??n),ge(Le.current[e]??(Xr?`preview`:`edit`))},[Z?.path,Xr]);let Wa=Q.useCallback(e=>{let t=Z?.path;t&&(Oe.current[t]=e),q(e)},[Z?.path]),Ga=Q.useCallback(e=>{let t=Z?.path;t&&(Pe.current[t]=e),de(e);try{localStorage.setItem(Ha,e)}catch{}},[Z?.path]),Ka=Q.useCallback(()=>ue,[ue]),qa=Q.useCallback(e=>{let t=Z?.path;t&&(Ie.current[t]=e),me(e);try{localStorage.setItem(Ua,e)}catch{}},[Z?.path]),Ja=Q.useCallback(e=>{let t=Z?.path;if(t&&(Le.current[t]=e),wn.current&&=(clearTimeout(wn.current),null),Dn.current!==null&&(cancelAnimationFrame(Dn.current),Dn.current=null),e===`edit`)gn(Tn.current||Xt),ge(e);else{Tn.current=hn;let e=t;ge(`edit`),Dn.current=requestAnimationFrame(()=>{Dn.current=requestAnimationFrame(()=>{Dn.current=null,!(w&&e&&Et.getState().byRoot[w]?.selectedPath!==e)&&(De(e=>e+1),ge(`preview`))})});return}},[hn,Xt,w,Z?.path]),Ya=Q.useCallback(async(e,t)=>{if(!r.writeFile||t===En.current)return!1;if(!(await r.writeFile(e,t))?.success)return G.error(n(`filesView.toast.writeFileFailed`)),!1;Tn.current=t,En.current=t,gn(t);let i=await yi(e,mt).catch(()=>null);return i&&(kn.current=i),!0},[r,yi,mt,n]);Q.useEffect(()=>()=>{wn.current&&=(clearTimeout(wn.current),null),Dn.current!==null&&(cancelAnimationFrame(Dn.current),Dn.current=null)},[he,Z?.path]);let Xa=Q.useCallback(e=>{if(Tn.current=e,!Z?.path||he!==`preview`||!r.writeFile)return;wn.current&&clearTimeout(wn.current);let t=Z.path;wn.current=setTimeout(()=>{wn.current=null,Ya(t,e).then(e=>{e&&(Pn(!0),setTimeout(()=>Pn(!1),1500))}).catch(e=>{G.error(e instanceof Error?e.message:n(`filesView.toast.saveFailed`))})},Ci)},[he,r.writeFile,Ya,Z?.path,n]),Za=Q.useMemo(()=>Fa&&(Tn.current||hn)||Xt,[hn,Xt,Fa]),Qa=Q.useCallback(()=>pe,[pe]);Q.useEffect(()=>{let e=e=>{let t=e?`preview`:`edit`;for(let e of Xe)Oe.current[e]=`edit`,ka(e)&&(Pe.current[e]=t),Aa(e)&&(Ie.current[e]=t),Bt(e)&&(Le.current[e]=t);q(`edit`),de(t),me(t),ge(t);try{localStorage.setItem(Ha,t),localStorage.setItem(Ua,t)}catch{}},t=t=>{let n=!!t.detail?.enabled;e(n)};return window.addEventListener(`openchamber:file-viewer-preview-mode-changed`,t),()=>{window.removeEventListener(`openchamber:file-viewer-preview-mode-changed`,t)}},[Xe]),Q.useEffect(()=>{if(!Wr||!w)return;let e=()=>{typeof window>`u`||Zn.current===null&&(Zn.current=window.requestAnimationFrame(()=>{Zn.current=null,Xn(e=>e+1)}))},t=(e,t)=>{if(e.state.doc.length!==t.length)return!1;if(t.length===0)return!0;let n=Math.min(128,t.length);if(e.state.sliceDoc(0,n)!==t.slice(0,n))return!1;let r=Math.max(0,t.length-n);return e.state.sliceDoc(r,t.length)===t.slice(r)},n=la(Wr.path);if(!n){Gr(null),Qn.current={key:``,attempts:0};return}let r=`${n}:${Wr.line}:${Wr.column??1}`;if(Qn.current.key!==r&&(Qn.current={key:r,attempts:0}),Z?.path!==n){if(Ln)return;Di(ct(n));return}if(tn||dn!==n)return;if(rn||Ki||Ji){Gr(null),Qn.current={key:``,attempts:0};return}if(!ra)return;if(le!==`edit`){q(`edit`);return}let i=qn.current;if(!i){e();return}if(!t(i,hn)){e();return}let a=Math.max(1,Math.min(Wr.line,i.state.doc.lines)),o=i.state.doc.line(a),s=Math.max(1,Wr.column||1),c=Math.max(0,o.to-o.from),l=Math.min(c,s-1),u=o.from+l;if(i.state.selection.main.head!==u||Qn.current.attempts===0){Qn.current.attempts+=1,i.dispatch({selection:{anchor:u},effects:M.scrollIntoView(u,{y:`center`})}),i.focus(),e();return}typeof window<`u`&&window.requestAnimationFrame(()=>{let e=qn.current;e&&(e.dispatch({selection:{anchor:u},effects:M.scrollIntoView(u,{y:`center`})}),e.focus())}),Gr(null),Qn.current={key:``,attempts:0}},[ra,Ln,hn,Yn,rn,tn,Ki,Ji,dn,Di,Wr,w,Z?.path,Gr,le,ct]),Q.useEffect(()=>{if(!Kr||!w)return;let e=la(Kr);if(!e){qr(null);return}if(Z?.path!==e){if(Ln)return;Di(ct(e));return}if(!(tn||dn!==e||rn||Ki||Ji)){if(ra&&le===`edit`){let e=qn.current;if(!e)return;e.focus()}qr(null)}},[ra,Ln,rn,tn,Di,Ki,Ji,dn,Kr,w,Z?.path,qr,le,ct]);let $a=Q.useCallback(e=>{if(!f||!e||!e.hasFocus||typeof window>`u`)return;let t=window.visualViewport;if(!t)return;let n=document.documentElement.clientHeight||window.innerHeight;if(Math.max(0,n-(t.offsetTop+t.height))<=0)return;let r=e.state.selection.main.head,i=e.coordsAtPos(r);if(!i)return;let a=Math.round(t.offsetTop+t.height),o=i.bottom+20-a;o<=0||(e.scrollDOM.scrollTop+=o)},[f]);Q.useEffect(()=>{if(!f||typeof window>`u`)return;let e=()=>{window.requestAnimationFrame(()=>{$a(qn.current)})},t=window.visualViewport;return t?.addEventListener(`resize`,e),t?.addEventListener(`scroll`,e,{passive:!0}),document.addEventListener(`selectionchange`,e),()=>{t?.removeEventListener(`resize`,e),t?.removeEventListener(`scroll`,e),document.removeEventListener(`selectionchange`,e)}},[f,$a]),Q.useEffect(()=>{if(le!==`edit`||f)return;let e=Re(`open_go_to_line`,Jr),t=t=>{let n=t.target;if(n?.closest(`[role="dialog"]`))return;let r=!!n?.closest(`.cm-editor`);if(!(n?.closest(`input, textarea, [contenteditable="true"], [role="textbox"]`)&&!r||!document.activeElement?.closest(`.cm-editor`))){if(Fe(t,e)){t.preventDefault(),vr(!0);return}if(t.metaKey&&!t.ctrlKey&&!t.altKey&&!t.shiftKey&&t.key.toLowerCase()===`i`){let e=qn.current?.state.selection.main;e&&!e.empty&&(t.preventDefault(),$i())}}};return window.addEventListener(`keydown`,t),()=>window.removeEventListener(`keydown`,t)},[$i,f,Jr,le]);let eo=c(e=>e.editorFontSize),to=Q.useMemo(()=>{if(!Z?.path)return[un(o,{fontSize:eo})];let e=Vt(Z.path),t=[un(o,e?{syntaxColors:!1,fontSize:eo}:{fontSize:eo})],n=za??Ba;return n&&t.push(n),e&&t.push(mn({language:e,themeName:o.metadata.id,theme:Nt(o)})),L&&t.push(M.lineWrapping),t.push(M.updateListener.of(e=>{(e.selectionSet||e.docChanged)&&Qi(e.view)})),f&&t.push(M.updateListener.of(e=>{e.view.hasFocus&&(e.selectionSet||e.focusChanged||e.viewportChanged||e.geometryChanged)&&window.requestAnimationFrame(()=>{$a(e.view)})})),t},[o,Z?.path,za,Ba,L,f,$a,eo,Qi]),no=Q.useMemo(()=>({light:ze.metadata.id,dark:Ue.metadata.id}),[ze.metadata.id,Ue.metadata.id]),ro=Z?.path&&Ki&&!i.isDesktop&&!qi?`${Z.path}|${mt.allowOutsideWorkspace?`outside`:`workspace`}|${mt.outsideFileGrant??``}`:``,io=Z?.path&&Ji?`${Z.path}|${mt.allowOutsideWorkspace?`outside`:`workspace`}|${mt.outsideFileGrant??``}`:``,ao=Z?.path&&ga&&pe===`preview`&&!i.isVSCode?Z.path:``,oo=n(`filesView.error.readFileFailed`),{readyKey:so,nonce:co}=Pa(ro,an,oo),{readyKey:lo,nonce:uo}=Pa(ao,an,oo),{readyKey:fo,nonce:po}=Pa(io,an,oo),mo=!!(ro&&so!==ro),ho=!!(ao&&lo!==ao),go=!!(io&&fo!==io),_o=Z?.path&&Ki?i.isDesktop?qi?`data:${Lt(Z.path)};utf8,${encodeURIComponent(Xt)}`:on:qi?`data:${Lt(Z.path)};utf8,${encodeURIComponent(Xt)}`:so===ro?a().authenticatedAsset(`/api/fs/raw`,{path:Z.path,allowOutsideWorkspace:mt.allowOutsideWorkspace?`true`:void 0,outsideFileGrant:mt.outsideFileGrant,directory:w||void 0}):``:``,vo=Q.useCallback(()=>{if(!Z?.path||!Ki)return;let e=qi?_o:Z.path||_o;if(!e)return;let t=Z.name||Z.path;H({open:!0,title:t,content:``,metadata:{tool:`image-preview`,filename:t,mime:Lt(Z.path)},image:{url:e,mimeType:Lt(Z.path),filename:t}})},[_o,Ki,qi,Z?.name,Z?.path]),yo=Q.useCallback(e=>{H(t=>t.open===e?t:{...t,open:e})},[]),bo=Q.useCallback((e,t)=>{let r=e.name||n(`filesView.editor.imageAltFallback`);return(0,$.jsx)(`div`,{className:J(`flex items-center justify-center`,t?.fullHeight?`h-full p-4`:`h-full p-3`),children:(0,$.jsx)(`button`,{type:`button`,className:`max-h-full max-w-full cursor-zoom-in rounded-md border-0 bg-transparent p-0 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary`,onClick:vo,"aria-label":r,disabled:!_o,children:(0,$.jsx)(`img`,{src:_o,alt:r,className:J(`object-contain rounded-md border border-border/30 bg-primary/10`,t?.fullHeight?`max-h-full max-w-full`:`max-h-[70vh] max-w-full`),draggable:!1},co)})})},[co,_o,vo,n]),xo=Z?.path&&Ji&&fo===io?a().authenticatedAsset(`/api/fs/raw`,{path:Z.path,allowOutsideWorkspace:mt.allowOutsideWorkspace?`true`:void 0,outsideFileGrant:mt.outsideFileGrant,directory:w||void 0}):``,So=Q.useCallback(e=>(0,$.jsx)(`div`,{className:`h-full overflow-hidden bg-[var(--surface-background)]`,children:(0,$.jsx)(`iframe`,{src:xo,className:`h-full w-full border-0`,title:e.name},po)}),[xo,po]);Q.useEffect(()=>{let e=!1;return(async()=>{if(!i.isDesktop||!Z?.path||!Ki||qi){ln.current&&=(URL.revokeObjectURL(ln.current),``),sn(``);return}an(null),ln.current&&=(URL.revokeObjectURL(ln.current),``),await(r.readFileBinary?r.readFileBinary(Z.path,mt).then(e=>e.dataUrl):(async()=>{let t=await _(`/api/fs/raw`,{query:{path:Z.path,allowOutsideWorkspace:mt.allowOutsideWorkspace?`true`:void 0,outsideFileGrant:mt.outsideFileGrant,directory:w||void 0}});if(!t.ok)throw Error(n(`filesView.error.readFileFailed`));let r=await t.blob(),i=URL.createObjectURL(r);return e?(URL.revokeObjectURL(i),``):(ln.current=i,i)})()).then(t=>{e||(sn(t),pn(Z.path))}).catch(t=>{ln.current&&=(URL.revokeObjectURL(ln.current),``),e||(sn(``),an(t instanceof Error?t.message:n(`filesView.error.readFileFailed`)),pn(null))}).finally(()=>{e||nn(!1)})})(),()=>{e=!0}},[r,Ki,qi,w,i.isDesktop,Z?.path,mt,n]),Q.useEffect(()=>()=>{ln.current&&=(URL.revokeObjectURL(ln.current),``)},[]);let Co=Q.useCallback(()=>tr(null),[]),wo=Q.useMemo(()=>$n({drafts:ei,editingDraftId:ri,commentText:ti,onTextChange:ni,selection:Lr,isDragging:Vr,fileLabel:Z?.path??``,newWidgetId:`files-new-comment-input`,mapDraftToRange:e=>({start:e.startLine,end:e.endLine}),onSave:ui,onCancel:()=>{Rr(null),oi()},onEdit:e=>{ci(e),Rr({start:e.startLine,end:e.endLine})},onDelete:li,onAddToChat:ea}),[ea,oi,ti,li,ri,ei,ui,Vr,Lr,Z?.path,ni,ci]),To=Q.useCallback((e,t)=>(0,$.jsx)(`div`,{className:`h-full`,children:(0,$.jsx)(qt,{file:{name:e.name,contents:t,lang:Vt(e.path)||void 0},options:{disableFileHeader:!0,overflow:L?`wrap`:`scroll`,theme:no,themeType:o.metadata.variant===`dark`?`dark`:`light`},className:`block h-full w-full`,style:{height:`100%`}})}),[o.metadata.variant,no,L]),Eo=({exitFullscreenOnly:t=!1,layout:i=`floating`}={})=>{if(!Z)return null;let a=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`,o=(e,t)=>(0,$.jsxs)(Me,{children:[(0,$.jsx)(Ae,{asChild:!0,children:(0,$.jsx)(`span`,{className:`inline-flex`,children:t})}),(0,$.jsx)(je,{side:`bottom`,sideOffset:6,children:e})]});return(0,$.jsxs)(`div`,{className:a,children:[ra&&Ra&&(0,$.jsxs)($.Fragment,{children:[_n?(0,$.jsxs)(`span`,{className:`flex items-center gap-1 px-1 text-muted-foreground typography-meta`,children:[(0,$.jsx)(Y,{name:`loader-4`,className:`size-3.5 animate-spin`}),n(`filesView.editor.saving`)]}):Fn&&jn===`saved`&&!xi?(0,$.jsxs)(`span`,{className:`flex items-center gap-1 px-1 text-[color:var(--status-success)] typography-meta`,children:[(0,$.jsx)(Y,{name:`check`,className:`size-3.5`}),n(`filesView.editor.saved`)]}):xi?o(n(Fn?`filesView.editor.saveNowTitle`:`filesView.editor.saveNowManualTitle`,{shortcut:`${we()}+S`}),(0,$.jsx)(X,{variant:`ghost`,size:`sm`,onClick:()=>void Si(),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:n(Fn?`filesView.editor.saveNowTitle`:`filesView.editor.saveNowManualTitle`,{shortcut:`${we()}+S`}),"aria-label":n(`filesView.editor.saveAria`,{shortcut:`${we()}+S`}),children:(0,$.jsx)(Y,{name:`save-3`,className:`size-4`})})):null,o(n(Fn?`filesView.editor.autoSaveOn`:`filesView.editor.manualSave`),(0,$.jsx)(X,{variant:`ghost`,size:`sm`,onClick:()=>In(e=>!e),className:J(`size-6 p-0 transition-opacity hover:bg-transparent focus-visible:bg-transparent active:bg-transparent`,Fn?`text-foreground opacity-100`:`text-muted-foreground opacity-65 hover:opacity-100`),title:n(Fn?`filesView.editor.autoSaveOn`:`filesView.editor.manualSave`),"aria-label":n(Fn?`filesView.editor.autoSaveOn`:`filesView.editor.manualSave`),children:Fn?(0,$.jsx)(Y,{name:`file-check-fill`,className:`size-4`}):(0,$.jsx)(Y,{name:`file-check`,className:`size-4`})}))]}),Ia&&yr?o(`${n(`chat.textSelection.title.addToCurrentChat`)} (⌘I)`,(0,$.jsxs)(X,{variant:`ghost`,size:`sm`,onClick:$i,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:`${n(`chat.textSelection.title.addToCurrentChat`)} (⌘I)`,"aria-label":`${n(`chat.textSelection.title.addToCurrentChat`)} (⌘I)`,children:[(0,$.jsx)(Y,{name:`chat-new`,className:`size-4`}),(0,$.jsx)(`span`,{children:n(`chat.textSelection.actions.addToChat`)}),(0,$.jsx)(tt,{shortcut:`⌘+I`})]})):null,(0,$.jsxs)(Ve,{onOpenChange:K,children:[(0,$.jsxs)(Me,{children:[(0,$.jsx)(Ae,{asChild:!0,children:(0,$.jsx)(`span`,{className:`inline-flex`,children:(0,$.jsx)(Ke,{asChild:!0,children:(0,$.jsx)(X,{variant:`ghost`,size:`sm`,className:`size-6 p-0 text-foreground opacity-100 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent`,title:n(`filesView.editor.openInDesktopApp`),"aria-label":n(`filesView.editor.openInDesktopApp`),children:(0,$.jsx)(Y,{name:`file-transfer`,className:`size-4`})})})})}),(0,$.jsx)(je,{side:`bottom`,sideOffset:6,children:n(`filesView.editor.openInDesktopApp`)})]}),(0,$.jsxs)(Ge,{align:`end`,className:`w-56 max-h-[70vh] overflow-y-auto`,children:[Ar.map(e=>(0,$.jsxs)(Je,{className:`flex items-center gap-2`,onClick:()=>void Fr(e),children:[(0,$.jsx)(sa,{label:e.label,iconDataUrl:e.iconDataUrl}),(0,$.jsx)(`span`,{className:`typography-ui-label text-foreground`,children:e.label})]},e.id)),jr?(0,$.jsxs)(Je,{className:`flex items-center gap-2`,onClick:()=>void Nr(!0),children:[(0,$.jsx)(Y,{name:`refresh`,className:`size-4`}),(0,$.jsx)(`span`,{className:`typography-ui-label text-foreground`,children:n(`filesView.editor.refreshApps`)})]}):null]})]}),!Ki&&!Ji&&(0,$.jsxs)($.Fragment,{children:[o(n(L?`filesView.editor.disableLineWrap`:`filesView.editor.enableLineWrap`),(0,$.jsx)(X,{variant:`ghost`,size:`sm`,onClick:()=>ie(!L),className:J(`size-6 p-0 transition-opacity hover:bg-transparent focus-visible:bg-transparent active:bg-transparent`,L?`text-foreground opacity-100`:`text-muted-foreground opacity-65 hover:opacity-100`),title:n(L?`filesView.editor.disableLineWrap`:`filesView.editor.enableLineWrap`),children:(0,$.jsx)(Y,{name:`text-wrap`,className:`size-4`})})),le===`edit`&&(0,$.jsxs)($.Fragment,{children:[o(n(`filesView.editor.findInFile`),(0,$.jsx)(X,{variant:`ghost`,size:`sm`,onClick:e=>{B(!z),e.currentTarget.blur()},className:`size-6 p-0 text-foreground opacity-100 transition-opacity hover:bg-transparent focus-visible:bg-transparent active:bg-transparent`,title:n(`filesView.editor.findInFile`),children:(0,$.jsx)(Y,{name:`search`,className:`size-4`})})),o(n(`filesView.editor.goToLine`),(0,$.jsx)(X,{variant:`ghost`,size:`sm`,onClick:e=>{vr(e=>!e),e.currentTarget.blur()},className:`size-6 p-0 text-foreground opacity-100 transition-opacity hover:bg-transparent focus-visible:bg-transparent active:bg-transparent`,title:n(`filesView.editor.goToLine`),children:(0,$.jsx)(Y,{name:`menu-fold-2`,className:`size-4`})})),(0,$.jsx)(zi,{open:_r,onOpenChange:vr,view:qn.current,variant:`inline`})]})]}),La&&ra&&!ga&&(0,$.jsx)(fn,{currentMode:le===`view`?`preview`:`edit`,onToggle:()=>{Wa(le===`view`?`edit`:`view`)}}),ha&&o(n(Ka()===`preview`?`filesView.editor.switchToEditMode`:`filesView.editor.switchToPreviewMode`),(0,$.jsx)(X,{variant:`ghost`,size:`sm`,onClick:()=>Ga(Ka()===`preview`?`edit`:`preview`),className:J(`size-6 p-0 transition-colors hover:bg-[var(--interactive-hover)] focus-visible:bg-[var(--interactive-hover)] active:bg-[var(--interactive-hover)]`,Ka()===`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:n(Ka()===`preview`?`filesView.editor.switchToEditMode`:`filesView.editor.switchToPreviewMode`),"aria-label":n(Ka()===`preview`?`filesView.editor.switchToEditMode`:`filesView.editor.switchToPreviewMode`),children:(0,$.jsx)(Y,{name:Ka()===`preview`?`eye`:`eye-off`,className:`size-4`})})),Aa(Z?.path??``)&&(0,$.jsx)(fn,{currentMode:Qa(),onToggle:()=>{qa(Qa()===`preview`?`edit`:`preview`)}}),ha&&Ka()===`preview`&&Zr&&(0,$.jsxs)(Me,{children:[(0,$.jsx)(Ae,{asChild:!0,children:(0,$.jsx)(X,{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":n(Qt?`filesView.tts.stopSpeaking`:`filesView.tts.readAloud`),onClick:()=>{Qt?en():Xt.trim()&&$t(Xt)},children:Qt?(0,$.jsx)(Y,{name:`stop`,className:`size-4 text-[color:var(--status-success)]`}):(0,$.jsx)(Y,{name:`volume-up`,className:`size-4`})})}),(0,$.jsx)(je,{sideOffset:8,children:n(Qt?`filesView.tts.stopSpeaking`:`filesView.tts.readAloud`)})]}),Fa&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(fn,{currentMode:he,onToggle:()=>Ja(he===`preview`?`edit`:`preview`)}),he===`preview`&&(0,$.jsx)(X,{variant:`ghost`,size:`sm`,onClick:async()=>{let e=On.current?.getXml();if(wn.current&&=(clearTimeout(wn.current),null),Z?.path&&e){if(!await Ya(Z.path,e))return;Pn(!0),setTimeout(()=>Pn(!1),1500)}},className:`size-6 p-0 text-foreground hover:bg-transparent focus-visible:bg-transparent active:bg-transparent`,title:n(`filesView.diagram.saveDiagram`),children:Nn?(0,$.jsx)(Y,{name:`check`,className:`size-4 text-[color:var(--status-success)]`}):(0,$.jsx)(Y,{name:`save-3`,className:`size-4`})})]}),ta&&o(n(`filesView.editor.copyFileContents`),(0,$.jsx)(X,{variant:`ghost`,size:`sm`,onClick:async()=>{(await te(Xt)).ok?(mr(!0),Un.current!==null&&window.clearTimeout(Un.current),Un.current=window.setTimeout(()=>{mr(!1)},1200)):G.error(n(`filesView.toast.copyFailed`))},className:`size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent`,title:n(`filesView.editor.copyFileContents`),"aria-label":n(`filesView.editor.copyFileContents`),children:pr?(0,$.jsx)(Y,{name:`check`,className:`size-4 text-[color:var(--status-success)]`}):(0,$.jsx)(Y,{name:`clipboard`,className:`size-4`})})),na&&o(n(`filesView.editor.copyFilePathTitle`,{path:Zi}),(0,$.jsx)(X,{variant:`ghost`,size:`sm`,onClick:async()=>{(await te(Zi)).ok?(gr(!0),Wn.current!==null&&window.clearTimeout(Wn.current),Wn.current=window.setTimeout(()=>{gr(!1)},1200)):G.error(n(`filesView.toast.copyFailed`))},className:`size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent`,title:n(`filesView.editor.copyFilePathTitle`,{path:Zi}),"aria-label":n(`filesView.editor.copyFilePathTitle`,{path:Zi}),children:hr?(0,$.jsx)(Y,{name:`check`,className:`size-4 text-[color:var(--status-success)]`}):(0,$.jsx)(Y,{name:`file-copy-2`,className:`size-4`})})),r.downloadFile&&o(n(`filesView.editor.saveFile`),(0,$.jsx)(X,{variant:`ghost`,size:`sm`,onClick:()=>{let e=r.downloadFile;e&&e(Z.path).catch(e=>{console.error(`Download failed:`,e),G.error(n(`sidebarFilesTree.toast.operationFailed`))})},className:`size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent`,title:n(`filesView.editor.saveFile`),"aria-label":n(`filesView.editor.saveFile`),children:(0,$.jsx)(Y,{name:`download`,className:`size-4`})})),t?o(n(`filesView.editor.exitFullscreen`),(0,$.jsx)(X,{variant:`ghost`,size:`sm`,onClick:()=>ae(!1),className:`size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent`,title:n(`filesView.editor.exitFullscreen`),"aria-label":n(`filesView.editor.exitFullscreen`),children:(0,$.jsx)(Y,{name:`fullscreen-exit`,className:`size-4`})})):!f&&e===`full`&&o(n(R?`filesView.editor.exitFullscreen`:`filesView.editor.fullscreen`),(0,$.jsx)(X,{variant:`ghost`,size:`sm`,onClick:()=>ae(!R),className:`size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent`,title:n(R?`filesView.editor.exitFullscreen`:`filesView.editor.fullscreen`),"aria-label":n(R?`filesView.editor.exitFullscreen`:`filesView.editor.fullscreen`),children:R?(0,$.jsx)(Y,{name:`fullscreen-exit`,className:`size-4`}):(0,$.jsx)(Y,{name:`fullscreen`,className:`size-4`})}))]})},Do=(0,$.jsxs)(`div`,{className:`relative flex h-full min-h-0 min-w-0 w-full flex-col overflow-hidden`,children:[(0,$.jsx)(Se,{open:Ln,onOpenChange:e=>{e||Rn(!0)},children:(0,$.jsxs)(ye,{showCloseButton:!1,className:`max-w-md`,children:[(0,$.jsxs)(_e,{children:[(0,$.jsx)(be,{children:n(`filesView.unsaved.title`)}),(0,$.jsx)(xe,{children:n(`filesView.unsaved.description`)})]}),(0,$.jsxs)(ve,{children:[(0,$.jsx)(X,{variant:`outline`,onClick:()=>void Ai(),disabled:_n,className:`border-[var(--status-success-border)] bg-[var(--status-success-background)] text-[var(--status-success)] hover:bg-[rgb(var(--status-success)/0.2)]`,children:n(`filesView.unsaved.saveChanges`)}),(0,$.jsx)(X,{variant:`destructive`,onClick:ki,children:n(`filesView.unsaved.discard`)})]})]})}),(0,$.jsxs)(`div`,{className:J(`flex flex-col flex-shrink-0`,T&&`border-b border-border/40`),children:[T?(0,$.jsxs)(`div`,{className:`flex min-w-0 items-center px-3 py-1.5`,children:[f&&I&&(0,$.jsx)(`button`,{type:`button`,onClick:()=>ne(!1),"aria-label":n(`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:(0,$.jsx)(Y,{name:`arrow-left-s`,className:`size-5`})}),f?Z?(0,$.jsxs)(Ve,{children:[(0,$.jsx)(Ke,{asChild:!0,children:(0,$.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":n(`filesView.editor.openFilesAria`),children:[(0,$.jsx)(St,{filePath:Z.path,extension:Z.extension,className:`size-3.5 flex-shrink-0`}),(0,$.jsx)(_a,{name:Z.name}),(0,$.jsx)(Y,{name:`arrow-down-s`,className:`size-4 flex-shrink-0 text-muted-foreground`})]})}),(0,$.jsx)(Ge,{align:`start`,className:`w-[min(24rem,calc(100vw-2rem))] max-w-[calc(100vw-2rem)]`,children:lt.map(e=>{let t=Z?.path===e.path;return(0,$.jsxs)(Je,{onSelect:n=>{if(n.target.closest(`[data-close-open-file]`)){n.preventDefault();return}t||Di(e)},className:J(`flex min-w-0 items-center justify-between gap-2 overflow-hidden`,t&&`bg-[var(--interactive-selection)] text-[var(--interactive-selection-foreground)]`),children:[(0,$.jsxs)(`span`,{className:`flex min-w-0 flex-1 items-center gap-2 overflow-hidden`,children:[(0,$.jsx)(St,{filePath:e.path,extension:e.extension,className:`size-3.5 flex-shrink-0`}),(0,$.jsx)(_a,{name:e.name})]}),(0,$.jsx)(`button`,{type:`button`,"data-close-open-file":!0,onPointerDown:e=>{e.preventDefault(),e.stopPropagation()},onClick:t=>{t.preventDefault(),t.stopPropagation(),ji(e.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":n(`filesView.editor.closeFileAria`,{name:e.name}),children:(0,$.jsx)(Y,{name:`close`,className:`size-3.5`})})]},e.path)})})]}):(0,$.jsx)(`div`,{className:`typography-ui-label font-medium truncate`,children:n(`filesView.editor.selectFile`)}):lt.length>0?(0,$.jsxs)(`div`,{className:`relative min-w-0 flex-1`,children:[_t.left&&(0,$.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`}),_t.right&&(0,$.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`}),(0,$.jsx)(`div`,{ref:gt,className:`flex min-w-0 items-center gap-1 overflow-x-auto scrollbar-none`,style:{scrollbarWidth:`none`,msOverflowStyle:`none`},children:lt.map(e=>{let t=Z?.path===e.path;return(0,$.jsxs)(`div`,{title:ma(w,e.path),className:J(`group inline-flex items-center gap-1 rounded-md border px-2 py-1 typography-ui-label transition-colors whitespace-nowrap`,t?`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:[(0,$.jsx)(St,{filePath:e.path,extension:e.extension,className:`size-3.5 flex-shrink-0`}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>{t||Di(e)},className:`max-w-[12rem] truncate text-left`,children:e.name}),(0,$.jsx)(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),ji(e.path)},className:J(`rounded-sm p-0.5 text-[var(--surface-muted-foreground)] hover:text-[var(--surface-foreground)]`,!t&&!v&&`opacity-0 group-hover:opacity-100`),"aria-label":n(`filesView.editor.closeFileAria`,{name:e.name}),children:(0,$.jsx)(Y,{name:`close`,className:`size-3.5`})})]},e.path)})})]}):(0,$.jsx)(`div`,{className:`typography-ui-label font-medium truncate`,children:n(`filesView.editor.selectFile`)})]}):null,Qr&&!f&&Z?(0,$.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:[Zi?(0,$.jsx)(`span`,{className:`min-w-0 flex-1 truncate typography-meta text-muted-foreground`,title:Zi,children:Zi}):null,(0,$.jsx)(`div`,{className:`ml-auto min-w-0 shrink-0 overflow-x-auto`,children:Eo({layout:`docked`})})]}):null]}),(0,$.jsxs)(`div`,{className:`flex-1 min-h-0 min-w-0 relative`,children:[Z&&!z&&!(Qr&&!f)&&(0,$.jsx)(`div`,{ref:U,className:`absolute right-3 top-3 z-30`,onMouseLeave:()=>{W.current>0||oe(!1)},children:V?Eo():(0,$.jsxs)(`div`,{className:`flex items-center gap-1`,children:[ha?(0,$.jsxs)(Me,{children:[(0,$.jsx)(Ae,{asChild:!0,children:(0,$.jsx)(`span`,{className:`inline-flex`,children:(0,$.jsx)(X,{variant:`ghost`,size:`sm`,onClick:()=>Ga(Ka()===`preview`?`edit`:`preview`),className:J(`size-8 rounded-lg border border-[var(--interactive-border)] bg-[var(--surface-elevated)] p-0 shadow-sm transition-colors`,Ka()===`preview`?`bg-[var(--interactive-selection)] text-[var(--interactive-selection-foreground)] hover:bg-[var(--interactive-selection)]`:`text-muted-foreground hover:text-foreground`),"aria-label":n(Ka()===`preview`?`filesView.editor.switchToEditMode`:`filesView.editor.switchToPreviewMode`),title:n(Ka()===`preview`?`filesView.editor.switchToEditMode`:`filesView.editor.switchToPreviewMode`),children:(0,$.jsx)(Y,{name:Ka()===`preview`?`eye`:`eye-off`,className:`size-4`})})})}),(0,$.jsx)(je,{side:`bottom`,sideOffset:6,children:n(Ka()===`preview`?`filesView.editor.switchToEditMode`:`filesView.editor.switchToPreviewMode`)})]}):null,(0,$.jsxs)(Me,{children:[(0,$.jsx)(Ae,{asChild:!0,children:(0,$.jsx)(`span`,{className:`inline-flex`,onMouseEnter:()=>oe(!0),children:(0,$.jsx)(X,{variant:`ghost`,size:`sm`,onClick:()=>oe(!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":n(`filesView.editor.showControlsAria`),title:n(`filesView.editor.controlsTitle`),children:(0,$.jsx)(Y,{name:`more-2-fill`,className:`size-4`})})})}),(0,$.jsx)(je,{side:`bottom`,sideOffset:6,children:n(`filesView.editor.controlsTitle`)})]})]})}),(0,$.jsx)(Ee,{outerClassName:`h-full min-w-0`,className:`h-full min-w-0`,children:Z?tn||mo||go?O?(0,$.jsx)(`div`,{className:`p-3`}):(0,$.jsxs)(`div`,{className:`p-3 flex items-center gap-2 typography-ui text-muted-foreground`,children:[(0,$.jsx)(Y,{name:`loader-4`,className:`size-4 animate-spin`}),n(`filesView.state.loading`)]}):rn?(0,$.jsx)(`div`,{className:`p-3 typography-ui text-[color:var(--status-error)]`,children:rn}):Ki&&Z?bo(Z):Ji?So(Z):Z&&Fa&&he===`preview`?(0,$.jsx)(`div`,{className:`h-full overflow-hidden`,style:{minHeight:`400px`},children:(0,$.jsx)(vn,{ref:On,xml:Za,onChange:Xa},`${Z.path}:${Ce}`)}):Z&&ha&&Ka()===`preview`?(0,$.jsxs)(`div`,{className:`h-full overflow-auto p-3`,children:[Xt.length>512e3&&(0,$.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:n(`filesView.warning.largeFilePreviewLimited`,{sizeKb:Math.round(Xt.length/1024)})}),(0,$.jsx)(Be,{fallback:(0,$.jsxs)(`div`,{className:`rounded-md border border-destructive/20 bg-destructive/10 px-3 py-2`,children:[(0,$.jsx)(`div`,{className:`mb-1 font-medium text-destructive`,children:n(`filesView.error.previewUnavailable`)}),(0,$.jsx)(`div`,{className:`text-sm text-muted-foreground`,children:n(`filesView.error.switchToEditMode`)})]}),children:(0,$.jsx)(Mt,{content:Xt,className:`typography-markdown-body`,stripFrontmatter:!0,enableFileReferences:!1})})]}):Z&&ga&&pe===`preview`?ho?(0,$.jsx)(`div`,{className:`flex h-full items-center justify-center text-muted-foreground typography-ui-label`,children:n(`common.loading`)}):(0,$.jsx)(`div`,{className:`h-full overflow-hidden`,children:(0,$.jsx)(`iframe`,{src:!i.isVSCode&&lo===ao?(()=>{let e=Z.path.split(`/`).map(e=>encodeURIComponent(e)).join(`/`);return a().authenticatedAsset(`/api/fs/serve${e.startsWith(`/`)?e:`/${e}`}`)})():void 0,srcDoc:i.isVSCode?(()=>{let e=Z.path.substring(0,Z.path.lastIndexOf(`/`)+1);return e?Xt.replace(/<head([^>]*)>/i,`<head$1><base href="${e}">`):Xt})():void 0,className:`w-full h-full border-none`,sandbox:`allow-scripts allow-same-origin allow-forms`,title:n(`filesView.editor.htmlPreviewTitle`)},uo)}):Z&&La&&le===`view`?To(Z,hn):(0,$.jsxs)(`div`,{className:J(`relative h-full`,Xi&&`overflow-hidden`),ref:Jn,children:[(0,$.jsx)(`div`,{className:J(`h-full`,Xi&&`invisible`),children:(0,$.jsx)(cn,{value:hn,onChange:gn,readOnly:!ra,vimMode:Yr===`vim`,extensions:to,className:`h-full`,blockWidgets:wo,onViewReady:e=>{qn.current=e,Qi(e),Xn(e=>e+1),window.requestAnimationFrame(()=>{$a(e)})},onViewDestroy:()=>{qn.current&&=null,br(!1),Sr(null),Xn(e=>e+1)},enableSearch:!0,searchOpen:z,onSearchOpenChange:B,highlightLines:Lr?{start:Math.min(Lr.start,Lr.end),end:Math.max(Lr.start,Lr.end)}:void 0,lineNumbersConfig:{domEventHandlers:{mousedown:(e,t,n)=>{if(!(n instanceof MouseEvent)||n.button!==0)return!1;n.preventDefault();let r=e.state.doc.lineAt(t.from).number;if(Lr&&!n.shiftKey&&Math.min(Lr.start,Lr.end)===r&&Math.max(Lr.start,Lr.end)===r)return Rr(null),oi(),zr.current=!1,Br.current=null,Hr(!1),!0;if(f&&Lr&&!n.shiftKey){let e=Math.min(Lr.start,Lr.end,r),t=Math.max(Lr.start,Lr.end,r);return Rr({start:e,end:t}),zr.current=!1,Br.current=null,Hr(!1),!0}if(zr.current=!0,Br.current=r,Hr(!0),Lr&&n.shiftKey){let e=Math.min(Lr.start,r),t=Math.max(Lr.end,r);Rr({start:e,end:t})}else Rr({start:r,end:r});return!0},mouseover:(e,t,n)=>{if(!(n instanceof MouseEvent)||n.buttons!==1||!zr.current||Br.current===null)return!1;let r=e.state.doc.lineAt(t.from).number,i=Math.min(Br.current,r),a=Math.max(Br.current,r);return Rr({start:i,end:a}),Hr(!0),!1},mouseup:()=>(zr.current=!1,Br.current=null,Hr(!1),!1)}}})}),Xi&&(0,$.jsx)(`div`,{className:`pointer-events-none absolute inset-0 flex items-center justify-center bg-background`,children:(0,$.jsxs)(`div`,{className:`flex items-center gap-2 typography-ui text-muted-foreground`,children:[(0,$.jsx)(Y,{name:`loader-4`,className:`size-4 animate-spin`}),n(`filesView.state.openingFileAtChange`)]})})]}):(0,$.jsx)(`div`,{className:`p-3 typography-ui text-muted-foreground`,children:n(`filesView.editor.pickFileFromTree`)})})]})]}),Oo=!!(w&&xt[w]),ko=w?wt[w]:null,Ao=(0,$.jsxs)(`section`,{className:J(`flex min-h-0 flex-col overflow-hidden`,f?`h-full w-full bg-background`:`h-full rounded-xl border border-border/60 bg-background/70`),children:[(0,$.jsx)(`div`,{className:J(`flex flex-col gap-2 py-2`,f?`px-3`:`px-2`),children:(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsxs)(`div`,{className:`relative flex-1 min-w-0`,children:[(0,$.jsx)(Y,{name:`search`,className:`pointer-events-none absolute left-2 top-2 size-4 text-muted-foreground`}),(0,$.jsx)(ke,{ref:F,value:j,onChange:e=>N(e.target.value),placeholder:n(`filesView.tree.search.placeholder`),className:`h-8 pl-8 pr-8 typography-meta`}),j.trim().length>0&&(0,$.jsx)(`button`,{type:`button`,"aria-label":n(`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:()=>{N(``),F.current?.focus()},children:(0,$.jsx)(Y,{name:`close`,className:`size-4`})})]}),(0,$.jsxs)(Me,{children:[(0,$.jsx)(Ae,{asChild:!0,children:(0,$.jsx)(`span`,{className:`inline-flex flex-shrink-0`,children:(0,$.jsx)(X,{variant:`ghost`,size:`sm`,onClick:()=>Ir(`createFile`,{path:C,type:`directory`}),className:`size-8 p-0 flex-shrink-0`,title:n(`filesView.tree.actions.newFileTitle`),"aria-label":n(`filesView.tree.actions.newFileTitle`),children:(0,$.jsx)(Y,{name:`file-add`,className:`size-4`})})})}),(0,$.jsx)(je,{side:`bottom`,sideOffset:6,children:n(`filesView.tree.actions.newFileTitle`)})]}),(0,$.jsxs)(Me,{children:[(0,$.jsx)(Ae,{asChild:!0,children:(0,$.jsx)(`span`,{className:`inline-flex flex-shrink-0`,children:(0,$.jsx)(X,{variant:`ghost`,size:`sm`,onClick:()=>Ir(`createFolder`,{path:C,type:`directory`}),className:`size-8 p-0 flex-shrink-0`,title:n(`filesView.tree.actions.newFolderTitle`),"aria-label":n(`filesView.tree.actions.newFolderTitle`),children:(0,$.jsx)(Y,{name:`folder-add`,className:`size-4`})})})}),(0,$.jsx)(je,{side:`bottom`,sideOffset:6,children:n(`filesView.tree.actions.newFolderTitle`)})]}),(0,$.jsxs)(Me,{children:[(0,$.jsx)(Ae,{asChild:!0,children:(0,$.jsx)(`span`,{className:`inline-flex flex-shrink-0`,children:(0,$.jsx)(X,{variant:`ghost`,size:`sm`,onClick:()=>void pi(),className:`size-8 p-0 flex-shrink-0`,title:n(`filesView.tree.actions.refreshTitle`),"aria-label":n(`filesView.tree.actions.refreshTitle`),children:(0,$.jsx)(Y,{name:`refresh`,className:`size-4`})})})}),(0,$.jsx)(je,{side:`bottom`,sideOffset:6,children:n(`filesView.tree.actions.refreshTitle`)})]}),(0,$.jsxs)(Me,{children:[(0,$.jsx)(Ae,{asChild:!0,children:(0,$.jsx)(X,{variant:`ghost`,size:`sm`,onClick:Ri,disabled:Fi.length===0&&Qe.length===0,className:`size-8 flex-shrink-0 p-0`,title:n(Li?`sidebarFilesTree.actions.collapseAllTitle`:`sidebarFilesTree.actions.expandAllTitle`),"aria-label":n(Li?`sidebarFilesTree.actions.collapseAllTitle`:`sidebarFilesTree.actions.expandAllTitle`),children:(0,$.jsx)(Y,{name:Li?`contract-up-down`:`expand-up-down`,className:`size-4`})})}),(0,$.jsx)(je,{side:`bottom`,sideOffset:6,children:n(Li?`sidebarFilesTree.actions.collapseAllTitle`:`sidebarFilesTree.actions.expandAllTitle`)})]})]})}),(0,$.jsx)(Ee,{outerClassName:`flex-1 min-h-0`,className:J(`py-2`,f?`px-3`:`px-2`),children:(0,$.jsx)(`ul`,{className:`flex flex-col`,children:Jt?(0,$.jsxs)(`li`,{className:`flex items-center gap-1.5 px-2 py-1 typography-meta text-muted-foreground`,children:[(0,$.jsx)(Y,{name:`loader-4`,className:`size-4 animate-spin`}),n(`filesView.tree.search.searching`)]}):Gt.length>0?Gt.map(e=>{let t=Z?.path===e.path;return(0,$.jsx)(`li`,{children:(0,$.jsxs)(`button`,{type:`button`,onClick:()=>void Di(e),className:J(`flex w-full items-center gap-1.5 rounded-md px-2 py-1 text-left text-foreground transition-colors`,t?`bg-interactive-selection/70`:`hover:bg-interactive-hover/40`),children:[Oa(e.path,e.extension),(0,$.jsx)(`span`,{className:`min-w-0 flex-1 truncate typography-meta`,style:{direction:`rtl`,textAlign:`left`},title:e.path,children:e.relativePath??e.path})]})},e.path)}):ko?(0,$.jsxs)(`li`,{className:`flex flex-col gap-2 px-2 py-1 typography-meta text-muted-foreground`,children:[(0,$.jsx)(`span`,{className:`text-[var(--status-error)]`,children:ko}),(0,$.jsxs)(X,{variant:`outline`,size:`xs`,className:`w-fit gap-1.5`,onClick:()=>void pi(),children:[(0,$.jsx)(Y,{name:`refresh`,className:`size-3.5`}),n(`filesView.tree.actions.refreshTitle`)]})]}):Oo?Gi(w,0):(0,$.jsx)(`li`,{className:`px-2 py-1 typography-meta text-muted-foreground`,children:n(`filesView.state.loading`)})})})]}),jo=e===`full`&&R&&Z&&(0,$.jsx)(`div`,{className:`absolute inset-0 z-50 flex flex-col bg-background`,children:(0,$.jsxs)(`div`,{className:`flex-1 min-h-0 min-w-0 relative`,children:[(0,$.jsx)(`div`,{className:`absolute right-4 top-4 z-30`,children:Eo({exitFullscreenOnly:!0})}),(0,$.jsx)(Ee,{outerClassName:`h-full min-w-0`,className:`h-full min-w-0`,children:tn||mo||go?O?(0,$.jsx)(`div`,{className:`p-4`}):(0,$.jsxs)(`div`,{className:`p-4 flex items-center gap-2 typography-ui text-muted-foreground`,children:[(0,$.jsx)(Y,{name:`loader-4`,className:`size-4 animate-spin`}),`Loading…`]}):rn?(0,$.jsx)(`div`,{className:`p-4 typography-ui text-[color:var(--status-error)]`,children:rn}):Ki?bo(Z,{fullHeight:!0}):Ji?So(Z):ha&&Ka()===`preview`?(0,$.jsxs)(`div`,{className:`h-full overflow-auto p-4`,children:[Xt.length>512e3&&(0,$.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:n(`filesView.warning.largeFilePreviewLimited`,{sizeKb:Math.round(Xt.length/1024)})}),(0,$.jsx)(Be,{fallback:(0,$.jsxs)(`div`,{className:`rounded-md border border-destructive/20 bg-destructive/10 px-3 py-2`,children:[(0,$.jsx)(`div`,{className:`mb-1 font-medium text-destructive`,children:n(`filesView.error.previewUnavailable`)}),(0,$.jsx)(`div`,{className:`text-sm text-muted-foreground`,children:n(`filesView.error.switchToEditMode`)})]}),children:(0,$.jsx)(Mt,{content:Xt,className:`typography-markdown-body`,stripFrontmatter:!0,enableFileReferences:!1})})]}):La&&le===`view`?To(Z,hn):(0,$.jsxs)(`div`,{className:J(`relative h-full`,Xi&&`overflow-hidden`),children:[(0,$.jsx)(`div`,{className:J(`h-full`,Xi&&`invisible`),children:(0,$.jsx)(cn,{value:hn,onChange:gn,readOnly:!ra,vimMode:Yr===`vim`,extensions:to,className:`h-full`,onViewReady:e=>{qn.current=e,Qi(e),window.requestAnimationFrame(()=>{$a(e)})},onViewDestroy:()=>{qn.current&&=null,br(!1),Sr(null)}})}),Xi&&(0,$.jsx)(`div`,{className:`pointer-events-none absolute inset-0 flex items-center justify-center bg-background`,children:(0,$.jsxs)(`div`,{className:`flex items-center gap-2 typography-ui text-muted-foreground`,children:[(0,$.jsx)(Y,{name:`loader-4`,className:`size-4 animate-spin`}),n(`filesView.state.openingFileAtChange`)]})})]})})]})});return(0,$.jsxs)(`div`,{className:`flex h-full min-h-0 overflow-hidden bg-background relative`,children:[(0,$.jsx)(Ma,{activeDialog:er,dialogData:nr,dialogInputValue:ir,onDialogInputChange:or,isDialogSubmitting:sr,onDialogSubmit:_i,onClose:Co,inputRef:Sn}),jo,xr?(0,$.jsx)(ar,{position:xr,onDismiss:()=>Sr(null),onAddToChat:$i}):null,se.open?(0,$.jsx)(Q.Suspense,{fallback:null,children:(0,$.jsx)(aa,{popup:se,onOpenChange:yo,isMobile:f})}):null,f?I?Do:Ao:e===`editor-only`?(0,$.jsx)(`div`,{className:`flex flex-1 min-h-0 min-w-0 overflow-hidden`,children:(0,$.jsx)(`div`,{className:`flex-1 min-h-0 min-w-0 overflow-hidden bg-background`,children:Do})}):(0,$.jsxs)(`div`,{className:`flex flex-1 min-h-0 min-w-0 gap-3 px-3 pb-3 pt-2`,children:[m>=700&&(0,$.jsx)(`div`,{className:`w-72 flex-shrink-0 min-h-0 overflow-hidden`,children:Ao}),(0,$.jsx)(`div`,{className:`flex-1 min-h-0 min-w-0 overflow-hidden rounded-xl border border-border/60 bg-background`,children:Do})]})]})};function Ia(e){return e+1}var La=e=>e,Ra=e=>{let t=La(e).type;return typeof t==`string`?t:``},za=e=>{let t=La(e).tool;return typeof t==`string`?t:``},Ba=e=>{let t=La(e).text;return typeof t==`string`?t:``},Va=e=>{let t=Ra(e);return t===`tool`?za(e).trim().toLowerCase()||`tool`:t||`unknown`},Ha=e=>{if(e.length===0)return``;let t=[];for(let n of e){let e=Va(n);t.includes(e)||t.push(e)}return t.join(` + `)},Ua=e=>e.replace(/\s+/g,` `).trim(),Wa=e=>{for(let t of e)if(Ra(t)===`text`){let e=Ua(Ba(t));if(e.length===0)continue;return e}let t=e.filter(e=>Ra(e)!==`text`).length;return t===0?``:`${t} attachment${t===1?``:`s`}`},Ga=(e,t,n)=>`${n(e)} / ${n(t)}`,Ka=(e,t,n,r)=>{let i=Ga(e,t,n);return typeof r==`string`&&r.trim().length>0?`${i} · ${r.trim()}`:i},qa=e=>{if(e===`12h`)return!0;if(e===`24h`)return!1},Ja=(e,t)=>{if(!e||!Number.isFinite(e))return`-`;let n=qa(t);return new Date(e).toLocaleString(void 0,{month:`numeric`,day:`numeric`,hour:n===!1?`2-digit`:`numeric`,minute:`2-digit`,...n===void 0?{}:{hour12:n}})},Ya={input:0,output:0,reasoning:0,cacheRead:0,cacheWrite:0,total:0},Xa={user:0,assistant:0,tool:0,other:0},Za=e=>typeof e!=`number`||!Number.isFinite(e)||e<0?0:e,Qa=e=>{let t=e.info.tokens,n=t===void 0?e.parts.find(e=>e.tokens!==void 0)?.tokens:t;if(typeof n==`number`)return{...Ya,total:Za(n)};if(!n||typeof n!=`object`)return Ya;let r=n,i=Za(r.input),a=Za(r.output),o=Za(r.reasoning),s=Za(r.cache?.read),c=Za(r.cache?.write);return{input:i,output:a,reasoning:o,cacheRead:s,cacheWrite:c,total:i+a+o+s+c}},$a=(...e)=>{for(let t of e)if(typeof t==`string`&&t.trim().length>0)return t;return``},eo=e=>typeof e==`string`?e.length:typeof e==`number`||typeof e==`boolean`?String(e).length:Array.isArray(e)?e.reduce((e,t)=>e+eo(t),0):e&&typeof e==`object`?Object.values(e).reduce((e,t)=>e+eo(t),0):0,to=(e,t)=>{let n=e,r=typeof n.type==`string`?n.type:``;if(r===`reasoning`)return{...Xa,assistant:eo(n.text)+eo(n.content)};let i=$a(n.text,n.content,n.value,n.source?.value,n.source?.text?.value);return r===`tool`||t===`tool`?{user:0,assistant:0,tool:eo(n.input)+eo(n.output)+eo(n.error)+eo(n.call?.input)+eo(n.call?.output)+eo(n.call?.error)+eo(n.raw)+Math.round(eo(n.metadata)*.25)+Math.round(eo(n.state)*.1),other:0}:t===`user`?{user:i.length,assistant:0,tool:0,other:0}:t===`assistant`?{user:0,assistant:i.length,tool:0,other:0}:{user:0,assistant:0,tool:0,other:i.length}},no=(e,t)=>({user:e.user+t.user,assistant:e.assistant+t.assistant,tool:e.tool+t.tool,other:e.other+t.other}),ro=e=>{let t=ft(e.info);return t.isUser?`user`:t.role===`assistant`?`assistant`:t.role===`tool`?`tool`:`other`},io=(e,t)=>{if(e.length===0)return{...Xa};let n=e.reduce((e,t)=>{let n=ro(t),r={...Xa};for(let e of t.parts)r=no(r,to(e,n));return no(e,r)},{...Xa});return n.user+=t.length,{user:Math.ceil(n.user/4),assistant:Math.ceil(n.assistant/4),tool:Math.ceil(n.tool/4),other:Math.ceil(n.other/4)}},ao=e=>e.toLocaleString(I()),oo=e=>!Number.isFinite(e)||e<=0?new Intl.NumberFormat(I(),{style:`currency`,currency:`USD`,minimumFractionDigits:2,maximumFractionDigits:2}).format(0):new Intl.NumberFormat(I(),{style:`currency`,currency:`USD`,minimumFractionDigits:e<.01?4:2,maximumFractionDigits:e<.01?4:2}).format(e),so=(e,t)=>!e||!Number.isFinite(e)?`-`:Ue(e,t,{month:`short`,day:`numeric`,year:`numeric`,hour:`numeric`,minute:`2-digit`}),co=(e,t,n)=>{let r=e.find(e=>e.id===t),i=r?.models?.find(e=>e.id===n);return{providerName:r?.name||t||`-`,modelName:i?.name||n||`-`,contextLimit:typeof i?.limit?.context==`number`?i.limit.context:null}},lo=()=>{let e=(0,Sn.c)(259),{t}=ee(),n=c(uo),r=c(fo),i;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(i={},e[0]=i):i=e[0];let[a,o]=Q.useState(i),[s,l]=Q.useState(null),u=Q.useRef(null),d=ue(po),f=W(),p=se(d??``),m=fe(mo),h;e[1]===Symbol.for(`react.memo_cache_sentinel`)?(h=()=>{u.current!==null&&(window.clearTimeout(u.current),u.current=null),o(ho),l(null)},e[1]=h):h=e[1];let g;e[2]===d?g=e[3]:(g=[d],e[2]=d,e[3]=g),Q.useEffect(h,g);let _,v;e[4]===Symbol.for(`react.memo_cache_sentinel`)?(_=()=>()=>{u.current!==null&&(window.clearTimeout(u.current),u.current=null)},v=[],e[4]=_,e[5]=v):(_=e[4],v=e[5]),Q.useEffect(_,v);let y;e[6]===Symbol.for(`react.memo_cache_sentinel`)?(y=async(e,t)=>{(await te(t)).ok?(l(e),u.current!==null&&window.clearTimeout(u.current),u.current=window.setTimeout(()=>{l(t=>t===e?null:t),u.current=null},2e3)):l(null)},e[6]=y):y=e[6];let b=y,x;e[7]!==d||e[8]!==f?(x=d?f.find(e=>e.id===d)??null:null,e[7]=d,e[8]=f,e[9]=x):x=e[9];let S=x,C,w,T,E,D,O,k,A;if(e[10]!==m||e[11]!==p){C=p.filter(go);let t;e[20]===p?t=e[21]:(t=p.filter(_o),e[20]=p,e[21]=t),A=t;let n=null;for(let e=C.length-1;e>=0;--e){let t=C[e];if(Qa(t).total>0){n=t;break}}O=n?Qa(n):Ya,w=nt({input:O.input,cache:{read:O.cacheRead,write:O.cacheWrite}}),k=C.reduce(vo,0);let r=0,i=0;for(let e of C){let t=Qa(e),n=e.info.time?.created??null,a=e.info.time?.completed??null,o=xt(n,a,e.parts);if(o===null)continue;let s=t.output+t.reasoning;s<=0||(r+=s,i+=o)}let a=i>0&&r>0?r/(i/1e3):null,o;e[22]===a?o=e[23]:(o=a===null?null:_t(a),e[22]=a,e[23]=o),E=o;let s=n?mt({createdAt:n.info.time?.created??null,completedAt:n.info.time?.completed??null,outputTokens:O.output,reasoningTokens:O.reasoning,parts:n.parts}):null;T=s===null?null:_t(s);let c=n?.info??null;D=co(m,c?.providerID||``,c?.modelID||``),e[10]=m,e[11]=p,e[12]=C,e[13]=w,e[14]=T,e[15]=E,e[16]=D,e[17]=O,e[18]=k,e[19]=A}else C=e[12],w=e[13],T=e[14],E=e[15],D=e[16],O=e[17],k=e[18],A=e[19];let j=D,M=j.contextLimit,N=M&&M>0?Math.min(999,O.total/M*100):0,P;e[24]===p?P=e[25]:(P=io(p,[...p].reverse().find(yo)?.info?.system||``),e[24]=p,e[25]=P);let F=P,I=F.user,ne=F.assistant,L=F.tool,re=Math.max(0,O.input-I-ne-L),ie=I+ne+L+re,R=p[0]?.info?.time?.created,ae=p.length>0?p[p.length-1]?.info?.time?.created:null,z;e[26]!==S?.title||e[27]!==t?(z=S?.title||t(`contextSidebar.session.untitled`),e[26]=S?.title,e[27]=t,e[28]=z):z=e[28];let B=S?.time?.created??R??null,V=ae??S?.time?.created??null,oe=E&&E.length>0?E:null,H=T&&T.length>0?T:null,U;e[29]!==ne||e[30]!==re||e[31]!==L||e[32]!==I?(U={user:I,assistant:ne,tool:L,other:re},e[29]=ne,e[30]=re,e[31]=L,e[32]=I,e[33]=U):U=e[33];let G;e[34]!==C.length||e[35]!==ie||e[36]!==w||e[37]!==M||e[38]!==j||e[39]!==p.length||e[40]!==B||e[41]!==V||e[42]!==oe||e[43]!==H||e[44]!==U||e[45]!==z||e[46]!==O||e[47]!==k||e[48]!==N||e[49]!==A.length?(G={sessionTitle:z,messagesCount:p.length,userMessagesCount:A.length,assistantMessagesCount:C.length,createdAt:B,lastActivityAt:V,providerModel:j,tokenBreakdown:O,usagePercent:N,cacheHitRate:w,totalAssistantCost:k,sessionTpsLabel:oe,lastAssistantTpsLabel:H,contextLimit:M,breakdown:U,breakdownTotal:ie},e[34]=C.length,e[35]=ie,e[36]=w,e[37]=M,e[38]=j,e[39]=p.length,e[40]=B,e[41]=V,e[42]=oe,e[43]=H,e[44]=U,e[45]=z,e[46]=O,e[47]=k,e[48]=N,e[49]=A.length,e[50]=G):G=e[50];let K=G;if(!d){let n;e[51]===t?n=e[52]:(n=t(`contextSidebar.empty.openSession`),e[51]=t,e[52]=n);let r;return e[53]===n?r=e[54]:(r=(0,$.jsx)(`div`,{className:`flex h-full items-center justify-center p-6 text-center typography-ui-label text-muted-foreground`,children:n}),e[53]=n,e[54]=r),r}let ce;e[55]===t?ce=e[56]:(ce=t(`contextSidebar.breakdown.user`),e[55]=t,e[56]=ce);let le;e[57]!==ce||e[58]!==K.breakdown.user?(le={key:`user`,label:ce,value:K.breakdown.user,color:`var(--status-success)`},e[57]=ce,e[58]=K.breakdown.user,e[59]=le):le=e[59];let q;e[60]===t?q=e[61]:(q=t(`contextSidebar.breakdown.assistant`),e[60]=t,e[61]=q);let de;e[62]!==q||e[63]!==K.breakdown.assistant?(de={key:`assistant`,label:q,value:K.breakdown.assistant,color:`var(--primary-base)`},e[62]=q,e[63]=K.breakdown.assistant,e[64]=de):de=e[64];let pe;e[65]===t?pe=e[66]:(pe=t(`contextSidebar.breakdown.toolCalls`),e[65]=t,e[66]=pe);let me;e[67]!==pe||e[68]!==K.breakdown.tool?(me={key:`tool`,label:pe,value:K.breakdown.tool,color:`var(--status-warning)`},e[67]=pe,e[68]=K.breakdown.tool,e[69]=me):me=e[69];let he;e[70]===t?he=e[71]:(he=t(`contextSidebar.breakdown.other`),e[70]=t,e[71]=he);let ge;e[72]!==he||e[73]!==K.breakdown.other?(ge={key:`other`,label:he,value:K.breakdown.other,color:`var(--surface-muted-foreground)`},e[72]=he,e[73]=K.breakdown.other,e[74]=ge):ge=e[74];let _e;e[75]!==le||e[76]!==de||e[77]!==me||e[78]!==ge?(_e=[le,de,me,ge],e[75]=le,e[76]=de,e[77]=me,e[78]=ge,e[79]=_e):_e=e[79];let ve=_e,ye;e[80]===K.sessionTitle?ye=e[81]:(ye=(0,$.jsx)(`h2`,{className:`typography-ui-header font-semibold text-foreground truncate`,children:K.sessionTitle}),e[80]=K.sessionTitle,e[81]=ye);let be;e[82]!==K.providerModel.modelName||e[83]!==K.providerModel.providerName?(be=(0,$.jsxs)(`span`,{children:[K.providerModel.providerName,` / `,K.providerModel.modelName]}),e[82]=K.providerModel.modelName,e[83]=K.providerModel.providerName,e[84]=be):be=e[84];let xe;e[85]!==n||e[86]!==K.createdAt?(xe=K.createdAt&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`span`,{children:`·`}),(0,$.jsx)(`span`,{children:so(K.createdAt,n)})]}),e[85]=n,e[86]=K.createdAt,e[87]=xe):xe=e[87];let Se;e[88]!==be||e[89]!==xe?(Se=(0,$.jsxs)(`div`,{className:`mt-1 flex flex-wrap items-center gap-x-2 gap-y-0.5 typography-micro text-muted-foreground/70`,children:[be,xe]}),e[88]=be,e[89]=xe,e[90]=Se):Se=e[90];let Ce;e[91]!==ye||e[92]!==Se?(Ce=(0,$.jsxs)(`div`,{className:`mb-6`,children:[ye,Se]}),e[91]=ye,e[92]=Se,e[93]=Ce):Ce=e[93];let we;e[94]===t?we=e[95]:(we=t(`contextSidebar.section.context`),e[94]=t,e[95]=we);let Te;e[96]===we?Te=e[97]:(Te=(0,$.jsx)(`span`,{className:`typography-micro text-muted-foreground`,children:we}),e[96]=we,e[97]=Te);let X;e[98]===K.tokenBreakdown.total?X=e[99]:(X=ao(K.tokenBreakdown.total),e[98]=K.tokenBreakdown.total,e[99]=X);let Ee;e[100]===K.contextLimit?Ee=e[101]:(Ee=K.contextLimit?` / ${ao(K.contextLimit)}`:``,e[100]=K.contextLimit,e[101]=Ee);let De;e[102]!==X||e[103]!==Ee?(De=(0,$.jsxs)(`span`,{className:`typography-micro tabular-nums text-muted-foreground/70`,children:[X,Ee]}),e[102]=X,e[103]=Ee,e[104]=De):De=e[104];let Oe;e[105]!==Te||e[106]!==De?(Oe=(0,$.jsxs)(`div`,{className:`flex items-baseline justify-between`,children:[Te,De]}),e[105]=Te,e[106]=De,e[107]=Oe):Oe=e[107];let ke;e[108]===K.usagePercent?ke=e[109]:(ke=K.usagePercent>0&&(0,$.jsx)(`div`,{className:`rounded-full transition-all duration-300`,style:{width:`${Math.max(.5,K.usagePercent)}%`,backgroundColor:K.usagePercent>80?`var(--status-warning)`:`var(--primary-base)`}}),e[108]=K.usagePercent,e[109]=ke);let Ae;e[110]===ke?Ae=e[111]:(Ae=(0,$.jsx)(`div`,{className:`mt-2.5 flex h-1 w-full overflow-hidden rounded-full bg-[var(--surface-subtle)]`,children:ke}),e[110]=ke,e[111]=Ae);let je;e[112]!==t||e[113]!==K.usagePercent?(je=t(`contextSidebar.context.percentUsed`,{percent:K.usagePercent.toFixed(1)}),e[112]=t,e[113]=K.usagePercent,e[114]=je):je=e[114];let Me;e[115]===je?Me=e[116]:(Me=(0,$.jsx)(`div`,{className:`mt-1.5 typography-micro font-medium tabular-nums text-foreground/80`,children:je}),e[115]=je,e[116]=Me);let Ne;e[117]!==Oe||e[118]!==Ae||e[119]!==Me?(Ne=(0,$.jsxs)(`div`,{className:`mb-5 rounded-lg bg-[var(--surface-elevated)]/70 px-4 py-3.5`,children:[Oe,Ae,Me]}),e[117]=Oe,e[118]=Ae,e[119]=Me,e[120]=Ne):Ne=e[120];let Pe;e[121]===t?Pe=e[122]:(Pe=t(`contextSidebar.stats.messages`),e[121]=t,e[122]=Pe);let Fe;e[123]===K.messagesCount?Fe=e[124]:(Fe=ao(K.messagesCount),e[123]=K.messagesCount,e[124]=Fe);let Ie;e[125]!==Pe||e[126]!==Fe?(Ie={label:Pe,value:Fe},e[125]=Pe,e[126]=Fe,e[127]=Ie):Ie=e[127];let Le;e[128]===t?Le=e[129]:(Le=t(`contextSidebar.stats.user`),e[128]=t,e[129]=Le);let Re;e[130]===K.userMessagesCount?Re=e[131]:(Re=ao(K.userMessagesCount),e[130]=K.userMessagesCount,e[131]=Re);let ze;e[132]!==Le||e[133]!==Re?(ze={label:Le,value:Re},e[132]=Le,e[133]=Re,e[134]=ze):ze=e[134];let Be;e[135]===t?Be=e[136]:(Be=t(`contextSidebar.stats.assistant`),e[135]=t,e[136]=Be);let Ve;e[137]===K.assistantMessagesCount?Ve=e[138]:(Ve=ao(K.assistantMessagesCount),e[137]=K.assistantMessagesCount,e[138]=Ve);let He;e[139]!==Be||e[140]!==Ve?(He={label:Be,value:Ve},e[139]=Be,e[140]=Ve,e[141]=He):He=e[141];let Ue;e[142]!==Ie||e[143]!==ze||e[144]!==He?(Ue=[Ie,ze,He],e[142]=Ie,e[143]=ze,e[144]=He,e[145]=Ue):Ue=e[145];let We=Ue,Ge;e[146]===We?Ge=e[147]:(Ge=(0,$.jsx)(`div`,{className:`grid grid-cols-3 gap-2`,children:We.map(bo)}),e[146]=We,e[147]=Ge);let Ke=r?`grid-cols-2`:`grid-cols-1`,qe;e[148]===Ke?qe=e[149]:(qe=J(`grid gap-2`,Ke),e[148]=Ke,e[149]=qe);let Je;e[150]===t?Je=e[151]:(Je=t(`contextSidebar.stats.cost`),e[150]=t,e[151]=Je);let Ye;e[152]===Je?Ye=e[153]:(Ye=(0,$.jsx)(`div`,{className:`typography-micro text-muted-foreground/70`,children:Je}),e[152]=Je,e[153]=Ye);let Xe;e[154]===K.totalAssistantCost?Xe=e[155]:(Xe=oo(K.totalAssistantCost),e[154]=K.totalAssistantCost,e[155]=Xe);let Ze;e[156]===Xe?Ze=e[157]:(Ze=(0,$.jsx)(`div`,{className:`mt-0.5 typography-ui-label tabular-nums text-foreground`,children:Xe}),e[156]=Xe,e[157]=Ze);let Qe;e[158]!==Ye||e[159]!==Ze?(Qe=(0,$.jsxs)(`div`,{className:`rounded-lg bg-[var(--surface-elevated)]/70 px-3 py-2.5`,children:[Ye,Ze]}),e[158]=Ye,e[159]=Ze,e[160]=Qe):Qe=e[160];let $e;e[161]!==r||e[162]!==t||e[163]!==K.sessionTpsLabel?($e=r?(0,$.jsxs)(`div`,{className:`rounded-lg bg-[var(--surface-elevated)]/70 px-3 py-2.5`,children:[(0,$.jsx)(`div`,{className:`typography-micro text-muted-foreground/70`,children:t(`contextSidebar.stats.sessionTps`)}),(0,$.jsx)(`div`,{className:`mt-0.5 typography-ui-label tabular-nums text-foreground`,children:K.sessionTpsLabel??`—`})]}):null,e[161]=r,e[162]=t,e[163]=K.sessionTpsLabel,e[164]=$e):$e=e[164];let et;e[165]!==qe||e[166]!==Qe||e[167]!==$e?(et=(0,$.jsxs)(`div`,{className:qe,children:[Qe,$e]}),e[165]=qe,e[166]=Qe,e[167]=$e,e[168]=et):et=e[168];let tt;e[169]!==Ge||e[170]!==et?(tt=(0,$.jsxs)(`div`,{className:`mb-5 space-y-2`,children:[Ge,et]}),e[169]=Ge,e[170]=et,e[171]=tt):tt=e[171];let rt;e[172]===t?rt=e[173]:(rt=t(`contextSidebar.section.lastAssistantMessage`),e[172]=t,e[173]=rt);let it;e[174]===rt?it=e[175]:(it=(0,$.jsx)(`div`,{className:`typography-micro text-muted-foreground mb-2.5`,children:rt}),e[174]=rt,e[175]=it);let at;e[176]===t?at=e[177]:(at=t(`contextSidebar.tokens.input`),e[176]=t,e[177]=at);let ot;e[178]!==at||e[179]!==K.tokenBreakdown.input?(ot={label:at,value:K.tokenBreakdown.input,format:`count`},e[178]=at,e[179]=K.tokenBreakdown.input,e[180]=ot):ot=e[180];let st;e[181]===t?st=e[182]:(st=t(`contextSidebar.tokens.output`),e[181]=t,e[182]=st);let ct;e[183]!==st||e[184]!==K.tokenBreakdown.output?(ct={label:st,value:K.tokenBreakdown.output,format:`count`},e[183]=st,e[184]=K.tokenBreakdown.output,e[185]=ct):ct=e[185];let lt;e[186]===t?lt=e[187]:(lt=t(`contextSidebar.tokens.reasoning`),e[186]=t,e[187]=lt);let ut;e[188]!==lt||e[189]!==K.tokenBreakdown.reasoning?(ut={label:lt,value:K.tokenBreakdown.reasoning,format:`count`},e[188]=lt,e[189]=K.tokenBreakdown.reasoning,e[190]=ut):ut=e[190];let Z;e[191]===t?Z=e[192]:(Z=t(`contextSidebar.tokens.cacheRead`),e[191]=t,e[192]=Z);let dt;e[193]!==Z||e[194]!==K.tokenBreakdown.cacheRead?(dt={label:Z,value:K.tokenBreakdown.cacheRead,format:`count`},e[193]=Z,e[194]=K.tokenBreakdown.cacheRead,e[195]=dt):dt=e[195];let pt;e[196]===t?pt=e[197]:(pt=t(`contextSidebar.tokens.cacheWrite`),e[196]=t,e[197]=pt);let ht;e[198]!==pt||e[199]!==K.tokenBreakdown.cacheWrite?(ht={label:pt,value:K.tokenBreakdown.cacheWrite,format:`count`},e[198]=pt,e[199]=K.tokenBreakdown.cacheWrite,e[200]=ht):ht=e[200];let gt;e[201]===t?gt=e[202]:(gt=t(`contextSidebar.tokens.cacheHit`),e[201]=t,e[202]=gt);let vt=K.cacheHitRate.hasInput?K.cacheHitRate.percent:null,yt;e[203]!==gt||e[204]!==vt?(yt={label:gt,value:vt,format:`percent`},e[203]=gt,e[204]=vt,e[205]=yt):yt=e[205];let bt;e[206]!==r||e[207]!==t||e[208]!==K.lastAssistantTpsLabel?(bt=r?[{label:t(`contextSidebar.tokens.tps`),value:K.lastAssistantTpsLabel,format:`text`}]:[],e[206]=r,e[207]=t,e[208]=K.lastAssistantTpsLabel,e[209]=bt):bt=e[209];let St;e[210]!==ot||e[211]!==ct||e[212]!==ut||e[213]!==dt||e[214]!==ht||e[215]!==yt||e[216]!==bt?(St=(0,$.jsx)(`div`,{className:`grid grid-cols-3 gap-x-4 gap-y-2.5`,children:[ot,ct,ut,dt,ht,yt,...bt].map(xo)}),e[210]=ot,e[211]=ct,e[212]=ut,e[213]=dt,e[214]=ht,e[215]=yt,e[216]=bt,e[217]=St):St=e[217];let Ct;e[218]!==it||e[219]!==St?(Ct=(0,$.jsxs)(`div`,{className:`mb-5 rounded-lg bg-[var(--surface-elevated)]/70 px-4 py-3.5`,children:[it,St]}),e[218]=it,e[219]=St,e[220]=Ct):Ct=e[220];let wt;e[221]!==ve||e[222]!==K.breakdownTotal?(wt=(0,$.jsx)(`div`,{className:`flex h-1 w-full overflow-hidden rounded-full bg-[var(--surface-subtle)]`,children:ve.map(e=>e.value<=0||K.breakdownTotal<=0?null:(0,$.jsx)(`div`,{style:{width:`${e.value/K.breakdownTotal*100}%`,backgroundColor:e.color}},e.key))}),e[221]=ve,e[222]=K.breakdownTotal,e[223]=wt):wt=e[223];let Tt;e[224]!==ve||e[225]!==K.breakdownTotal?(Tt=(0,$.jsx)(`div`,{className:`mt-2 flex flex-wrap items-center gap-x-4 gap-y-1`,children:ve.map(e=>{let t=K.breakdownTotal>0?e.value/K.breakdownTotal*100:0;return(0,$.jsxs)(`div`,{className:`inline-flex items-center gap-1.5`,children:[(0,$.jsx)(`span`,{className:`h-1.5 w-1.5 rounded-full`,style:{backgroundColor:e.color}}),(0,$.jsxs)(`span`,{className:`typography-micro text-muted-foreground/70`,children:[e.label,` `,(0,$.jsxs)(`span`,{className:`tabular-nums`,children:[t.toFixed(0),`%`]})]})]},e.key)})}),e[224]=ve,e[225]=K.breakdownTotal,e[226]=Tt):Tt=e[226];let Et;e[227]!==wt||e[228]!==Tt?(Et=(0,$.jsxs)(`div`,{className:`mb-6`,children:[wt,Tt]}),e[227]=wt,e[228]=Tt,e[229]=Et):Et=e[229];let Dt;e[230]===t?Dt=e[231]:(Dt=t(`contextSidebar.section.rawMessages`),e[230]=t,e[231]=Dt);let Ot;e[232]===Dt?Ot=e[233]:(Ot=(0,$.jsx)(`div`,{className:`typography-micro text-muted-foreground`,children:Dt}),e[232]=Dt,e[233]=Ot);let kt;if(e[234]!==s||e[235]!==a||e[236]!==p||e[237]!==r||e[238]!==t||e[239]!==n){let i;e[241]!==s||e[242]!==a||e[243]!==r||e[244]!==t||e[245]!==n?(i=e=>{let i=ft(e.info).role,c=i===`assistant`,l=i===`user`,u=a[e.info.id]===!0,d=s===e.info.id,f=e.info.time?.created??null,p=e.info.time?.completed??null,m=Ha(e.parts),h=c?Qa({info:e.info,parts:e.parts}):null,g=l?Wa(e.parts):``,_=Ja(f,n),v=m||`—`,y=(()=>{if(!r||!c||!h)return null;let t=mt({createdAt:f,completedAt:p,outputTokens:h.output,reasoningTokens:h.reasoning,parts:e.parts});if(t===null)return null;let n=_t(t);return n.length>0?n:null})(),x=h?Ka(h.input,h.output,ao,y):``,S=i||`unknown`,C=m?`${S}: ${m}`:S,w=u?JSON.stringify({info:e.info,parts:e.parts},null,2):``;return(0,$.jsxs)(`div`,{className:`overflow-hidden rounded-lg bg-[var(--surface-elevated)]/70`,children:[(0,$.jsx)(`button`,{type:`button`,className:`w-full cursor-pointer px-3 py-1.5 text-left hover:bg-[var(--interactive-hover)]`,"aria-expanded":u,onClick:()=>{o(t=>({...t,[e.info.id]:t[e.info.id]!==!0}))},children:(0,$.jsxs)(`div`,{className:`grid items-center gap-x-2 whitespace-nowrap typography-micro`,style:{gridTemplateColumns:c?`minmax(0, 1fr) minmax(7.5rem, max-content) max-content`:`minmax(0, 1fr) max-content`},children:[l?(0,$.jsxs)(`span`,{className:`min-w-0 truncate text-muted-foreground`,children:[(0,$.jsx)(`span`,{className:`typography-ui-label text-foreground`,children:`user:`}),` `,g]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`span`,{className:`min-w-0 truncate text-muted-foreground`,children:c?v:C}),c&&(0,$.jsx)(`span`,{className:`text-right text-muted-foreground tabular-nums`,children:x})]}),(0,$.jsx)(`span`,{className:`text-right text-muted-foreground`,children:_})]})}),u&&(0,$.jsx)(`div`,{className:`border-t border-[var(--surface-subtle)] p-0`,children:(0,$.jsxs)(`div`,{className:`group relative max-h-[26rem] w-full overflow-auto bg-[var(--surface-background)]`,children:[(0,$.jsx)(`div`,{className:`absolute top-1 right-2 z-10 opacity-0 transition-opacity group-hover:opacity-100`,children:(0,$.jsx)(`button`,{type:`button`,className:`rounded p-1 text-muted-foreground transition-colors hover:bg-interactive-hover/60 hover:text-foreground`,onClick:t=>{t.stopPropagation(),b(e.info.id,w)},"aria-label":t(d?`contextSidebar.actions.copied`:`contextSidebar.actions.copyJson`),title:t(d?`contextSidebar.actions.copied`:`contextSidebar.actions.copy`),children:d?(0,$.jsx)(Y,{name:`check`,className:`size-3.5`}):(0,$.jsx)(Y,{name:`file-copy`,className:`size-3.5`})})}),(0,$.jsx)(Wt,{language:`json`,code:w,style:{margin:0,padding:`0.75rem`,background:`transparent`,fontSize:`var(--text-micro)`,lineHeight:`1.35`},wrap:!0})]})})]},e.info.id)},e[241]=s,e[242]=a,e[243]=r,e[244]=t,e[245]=n,e[246]=i):i=e[246],kt=[...p].reverse().map(i),e[234]=s,e[235]=a,e[236]=p,e[237]=r,e[238]=t,e[239]=n,e[240]=kt}else kt=e[240];let At;e[247]===kt?At=e[248]:(At=(0,$.jsx)(`div`,{className:`mt-2.5 space-y-1`,children:kt}),e[247]=kt,e[248]=At);let jt;e[249]!==Ot||e[250]!==At?(jt=(0,$.jsxs)(`div`,{children:[Ot,At]}),e[249]=Ot,e[250]=At,e[251]=jt):jt=e[251];let Mt;return e[252]!==Ce||e[253]!==Ne||e[254]!==tt||e[255]!==Ct||e[256]!==Et||e[257]!==jt?(Mt=(0,$.jsx)(`div`,{className:`h-full overflow-y-auto bg-background`,children:(0,$.jsxs)(`div`,{className:`mx-auto w-full max-w-[52rem] px-5 py-6`,children:[Ce,Ne,tt,Ct,Et,jt]})}),e[252]=Ce,e[253]=Ne,e[254]=tt,e[255]=Ct,e[256]=Et,e[257]=jt,e[258]=Mt):Mt=e[258],Mt};function uo(e){return e.timeFormatPreference}function fo(e){return e.showAssistantTps}function po(e){return e.currentSessionId}function mo(e){return e.providers}function ho(e){return Object.keys(e).length>0?{}:e}function go(e){return ft(e.info).role===`assistant`}function _o(e){return ft(e.info).isUser}function vo(e,t){return e+Za(t.info.cost)}function yo(e){return ft(e.info).isUser&&typeof e.info.system==`string`}function bo(e){return(0,$.jsxs)(`div`,{className:`rounded-lg bg-[var(--surface-elevated)]/70 px-3 py-2.5`,children:[(0,$.jsx)(`div`,{className:`typography-micro text-muted-foreground/70`,children:e.label}),(0,$.jsx)(`div`,{className:`mt-0.5 typography-ui-label tabular-nums text-foreground`,children:e.value})]},e.label)}function xo(e){return(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`div`,{className:`typography-micro text-muted-foreground/70`,children:e.label}),(0,$.jsx)(`div`,{className:`mt-0.5 typography-ui-label tabular-nums text-foreground`,children:e.format===`text`?typeof e.value==`string`&&e.value.length>0?e.value:`—`:e.value!==null&&e.value!==void 0?e.format===`percent`?`${Number(e.value).toFixed(1)}%`:ao(Number(e.value)):`—`})]},e.label)}var So=e=>{let t=e.trim().replace(/\\/g,`/`);if(!t)return``;let n=t.startsWith(`//`),r=t.replace(/\/+$/g,``).replace(/\/+/g,`/`);return n&&!r.startsWith(`//`)?`/${r}`:r||(t.startsWith(`/`)?`/`:``)},Co=()=>`react-surface`,wo=(e,t)=>JSON.stringify([So(e),t]),To=(e,t,n,r)=>JSON.stringify([e,t,So(n),r]),Eo=(e,t,n)=>n?t:e===t?e:null,Do=(e,t)=>e.sessionId===t.sessionId&&So(e.directory)===So(t.directory),Oo=(e,t)=>So(e)===So(t),ko=e=>({anchor:e,current:e,stack:[]}),Ao=(e,t)=>e??ko(t),jo=(e,t)=>e?.current.sessionId??t,Mo=(e,t)=>Do(e.current,t)?e:{...e,current:t,stack:[...e.stack,e.current]},No=e=>{let t=e.stack[e.stack.length-1];return t?{...e,current:t,stack:e.stack.slice(0,-1)}:e},Po=(e,t,n)=>!Oo(e.anchor.directory,t.directory)||!Oo(e.current.directory,t.directory)||n(t.sessionId,t.directory)===!1?{status:`rejected-cross-directory`,state:e}:{status:`navigated`,state:Mo(e,t)},Fo=(e,t,n)=>{let r=e[t];if(!r)return{accepted:!1,navigationBySurfaceId:e};let i=Po(r,n,()=>!0);return i.status===`navigated`?{accepted:!0,navigationBySurfaceId:i.state===r?e:{...e,[t]:i.state}}:{accepted:!1,navigationBySurfaceId:e}},Io=(e,t)=>{let n=!1,r={};for(let[i,a]of Object.entries(e)){if(!t.has(i)){n=!0;continue}r[i]=a}return n?r:e},Lo=e=>e.directoryMatches?e.error?e.messageCount>0?`partial-error`:`fatal-error`:!e.renderable&&e.requested?`cold-loading`:e.messageCount===0?e.working?`working-empty`:`authoritative-empty`:`transcript`:`directory-mismatch`,Ro=e=>e===`retry`,zo=e=>e.active&&e.visible&&e.messageCount<=0,Bo=e=>e?`load-more`:`ensure`,Vo=e=>e.kind===`has-more`,Ho=(e,t)=>`${e}\n${t}`,Uo=(e,t,n,r)=>r&&!e.has(Ho(t,n)),Wo=(e,t)=>({scrollHeight:e,scrollTop:t}),Go=(e,t)=>Math.max(0,e.scrollTop+Math.max(0,t-e.scrollHeight)),Ko=(e,t)=>e&&!t,qo=e=>e,Jo=e=>!e,Yo=e=>!Ko(e.hasMore,e.isLoading)||!Jo(e.historyVirtualized)?null:Wo(e.scrollHeight,e.scrollTop),Xo=(e,t,n)=>!!(e&&e.token===t&&e.viewportKey===n),Zo=33554432,Qo=e=>Math.min(Zo,262144+Math.max(0,Math.ceil(e))*64*1024),$o=e=>Math.min(Zo,Math.max(0,Math.round(Number.isFinite(e)?e:0))),es=e=>{let t=Object.values(e.mountedViews),n=t.length,r=t.reduce((e,t)=>e+t.estimatedBytes,0),i=new Set,a=t.filter(t=>t.viewKey!==e.activeViewKey).sort((e,t)=>e.lastAccessed-t.lastAccessed);for(let e of a){if(n<=3&&r<=33554432)break;i.add(e.viewKey),--n,r-=e.estimatedBytes}if(i.size===0)return e;let o={...e.mountedViews};return i.forEach(e=>delete o[e]),{...e,mountedViews:o}},ts=(e,t)=>{if(t.type===`close-tab`){let n=Object.values(e.mountedViews).filter(e=>e.tabId===t.tabId);if(!e.tabs[t.tabId]&&n.length===0)return e;let r={...e.tabs},i={...e.mountedViews};return delete r[t.tabId],n.forEach(e=>delete i[e.viewKey]),{activeViewKey:n.some(t=>t.viewKey===e.activeViewKey)?null:e.activeViewKey,tabs:r,mountedViews:i}}if(t.type===`activate`){if(t.viewKey===e.activeViewKey)return e;let n=t.viewKey?e.mountedViews[t.viewKey]:void 0;if(t.viewKey&&!n)return e;if(!n)return{...e,activeViewKey:null};let r=n.lastAccessed===t.now?e.mountedViews:{...e.mountedViews,[n.viewKey]:{...n,lastAccessed:t.now}};return es({...e,activeViewKey:t.viewKey,mountedViews:r})}if(t.type===`estimate`){let n=e.mountedViews[t.viewKey],r=$o(t.estimatedBytes);return!n||n.estimatedBytes===r?e:es({...e,mountedViews:{...e.mountedViews,[n.viewKey]:{...n,estimatedBytes:r}}})}let n=e.tabs[t.tab.tabId],r=e.mountedViews[t.view.viewKey],i=n&&n.sessionId===t.tab.sessionId&&n.directory===t.tab.directory&&n.title===t.tab.title,a=r&&r.tabId===t.view.tabId&&r.surfaceId===t.view.surfaceId&&r.lastAccessed===t.now;return i&&a&&e.activeViewKey===t.view.viewKey?e:es({...e,activeViewKey:t.view.viewKey,tabs:i?e.tabs:{...e.tabs,[t.tab.tabId]:t.tab},mountedViews:{...e.mountedViews,[t.view.viewKey]:{...t.view,estimatedBytes:r?.estimatedBytes??Qo(0),lastAccessed:t.now}}})},ns={overflowAnchor:`none`,overscrollBehavior:`contain`,overscrollBehaviorY:`contain`},rs={scrollbar:`chat`,scrollShadow:`true`,orientation:`vertical`},is=e=>{let t=(0,Sn.c)(17),{state:n,error:r,onRetry:i}=e,{t:a}=ee();if(n===`cold-loading`||n===`working-empty`){let e;return t[0]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,$.jsx)(`div`,{className:`flex h-full items-center justify-center text-sm text-muted-foreground`,children:(0,$.jsx)(Y,{name:`loader-4`,className:`size-4 animate-spin`})}),t[0]=e):e=t[0],e}if(n===`fatal-error`||n===`directory-mismatch`){let e;t[1]!==r||t[2]!==a?(e=r||a(`chat.emptyState.opencodeUnreachable`),t[1]=r,t[2]=a,t[3]=e):e=t[3];let o;t[4]===e?o=t[5]:(o=(0,$.jsx)(`div`,{className:`text-center`,children:e}),t[4]=e,t[5]=o);let s;t[6]!==i||t[7]!==n||t[8]!==a?(s=n===`fatal-error`?(0,$.jsx)(X,{type:`button`,variant:`secondary`,size:`sm`,onClick:i,children:a(`chat.history.retry`)}):null,t[6]=i,t[7]=n,t[8]=a,t[9]=s):s=t[9];let c;return t[10]!==o||t[11]!==s?(c=(0,$.jsxs)(`div`,{className:`flex h-full flex-col items-center justify-center gap-3 px-6 text-sm text-muted-foreground`,children:[o,s]}),t[10]=o,t[11]=s,t[12]=c):c=t[12],c}let o;t[13]===a?o=t[14]:(o=a(`chat.timeline.empty.session`),t[13]=a,t[14]=o);let s;return t[15]===o?s=t[16]:(s=(0,$.jsx)(`div`,{className:`flex h-full items-center justify-center px-6 text-center text-sm text-muted-foreground`,children:o}),t[15]=o,t[16]=s),s},as=e=>{let t=(0,Sn.c)(193),{surfaceId:n,sessionId:r,directory:i,active:a,canNavigateBack:s,onNavigateSession:c,onNavigateBack:l,onEstimateBytes:u,syncDirectory:d}=e,{t:f}=ee(),p=ct(),m,h,g;t[0]!==i||t[1]!==r||t[2]!==n?(h=o(),m=So(i),g=To(h,n,m,r),t[0]=i,t[1]=r,t[2]=n,t[3]=m,t[4]=h,t[5]=g):(m=t[3],h=t[4],g=t[5]);let _=g,v=Q.useRef(null),y=Q.useRef(null),b=Q.useRef(0),[x,S]=Q.useState(null),C;t[6]===Symbol.for(`react.memo_cache_sentinel`)?(C=new Set,t[6]=C):C=t[6];let w=Q.useRef(C),T=he(r,d),E=se(r,d),D=fe(ss),O;t[7]===E?O=t[8]:(O=vt(E),t[7]=E,t[8]=O);let k=O,j;bb0:{if(!k.modelId){let e;t[9]===f?e=t[10]:(e=f(`common.unavailable`),t[9]=f,t[10]=e),j=e;break bb0}let e;if(t[11]!==k.modelId||t[12]!==k.providerId||t[13]!==D){let n;t[15]===k.providerId?n=t[16]:(n=e=>e.id===k.providerId,t[15]=k.providerId,t[16]=n);let r=D.find(n);e=r?.models.some(e=>e.id===k.modelId)&&B(r,k.modelId)||k.modelId,t[11]=k.modelId,t[12]=k.providerId,t[13]=D,t[14]=e}else e=t[14];j=e}let M=j,N=H(r,d),F=pe(r,d).renderable,I;t[17]===r?I=t[18]:(I=e=>!!e.session.find(e=>e.id===r)?.parentID,t[17]=r,t[18]=I);let te=V(I,d),[ne,L]=Q.useState(null),re,ie;t[19]!==te||t[20]!==_?(re=()=>{L(e=>Eo(e,_,te))},ie=[te,_],t[19]=te,t[20]=_,t[21]=re,t[22]=ie):(re=t[21],ie=t[22]),Q.useLayoutEffect(re,ie);let R=te||ne===_,z=le(r,d),oe;t[23]===r?oe=t[24]:(oe=e=>e.streamingMessageIds.get(r)??null,t[23]=r,t[24]=oe);let U=ae(oe),W;t[25]===U?W=t[26]:(W=e=>U?e.messageStreamStates.get(U)?.phase??null:null,t[25]=U,t[26]=W);let q=ae(W),ue=N?.type===`busy`||N?.type===`retry`,me=gt(cs),[ge,_e]=Q.useState(!1),[ve,ye]=Q.useState(!1),[be,xe]=Q.useState(0),Se=a&&!me,Ce;t[27]!==r||t[28]!==ue||t[29]!==T||t[30]!==Se||t[31]!==_?(Ce={enabled:Se,currentSessionId:r,viewportKey:_,sessionMessageCount:T,sessionIsWorking:ue,isMobile:!1},t[27]=r,t[28]=ue,t[29]=T,t[30]=Se,t[31]=_,t[32]=Ce):Ce=t[32];let{scrollRef:we,notifyContentChange:Te,getAnimationHandlers:J,goToBottom:Ee,restoreSnapshot:Oe,showScrollButton:ke}=Z(Ce),Ae;t[33]===Symbol.for(`react.memo_cache_sentinel`)?(Ae=()=>{_e(!1),ye(!1)},t[33]=Ae):Ae=t[33];let je;t[34]===r?je=t[35]:(je=[r],t[34]=r,t[35]=je),Q.useEffect(Ae,je);let Me;t[36]===Symbol.for(`react.memo_cache_sentinel`)?(Me=(e,t)=>{e&&ye(!1),t!==void 0&&_e(t)},t[36]=Me):Me=t[36];let Ne=P(Me),Pe;t[37]===Ee?Pe=t[38]:(Pe=e=>{let t=e===void 0?`instant`:e;ye(!1),v.current?.scrollToBottom(),Ee(t)},t[37]=Ee,t[38]=Pe);let Fe=P(Pe),Ie;t[39]===Symbol.for(`react.memo_cache_sentinel`)?(Ie=()=>{ye(!0)},t[39]=Ie):Ie=t[39];let Le=P(Ie),Re;t[40]!==Le||t[41]!==me||t[42]!==we?(Re={scrollRef:we,enabled:me,onUpwardIntent:Le},t[40]=Le,t[41]=me,t[42]=we,t[43]=Re):Re=t[43],bt(Re);let ze;t[44]!==r||t[45]!==p?(ze=e=>{p.ensureSessionRenderable(r,Ro(e))},t[44]=r,t[45]=p,t[46]=ze):ze=t[46];let Be=P(ze),Ve,He;t[47]!==a||t[48]!==Be?(Ve=()=>{a&&Be(`active`)},He=[a,Be],t[47]=a,t[48]=Be,t[49]=Ve,t[50]=He):(Ve=t[49],He=t[50]),Q.useEffect(Ve,He);let Ue,We;t[51]!==a||t[52]!==Be||t[53]!==T?(Ue=()=>{if(typeof window>`u`)return;let e=()=>{let e=document.visibilityState!==`hidden`&&document.hasFocus();zo({active:a,visible:e,messageCount:T})&&Be(`retry`)};return window.addEventListener(`focus`,e),document.addEventListener(`visibilitychange`,e),()=>{window.removeEventListener(`focus`,e),document.removeEventListener(`visibilitychange`,e)}},We=[a,Be,T],t[51]=a,t[52]=Be,t[53]=T,t[54]=Ue,t[55]=We):(Ue=t[54],We=t[55]),Q.useEffect(Ue,We);let Ge,Ke;t[56]!==u||t[57]!==T||t[58]!==_?(Ge=()=>{u?.(_,Qo(T))},Ke=[u,T,_],t[56]=u,t[57]=T,t[58]=_,t[59]=Ge,t[60]=Ke):(Ge=t[59],Ke=t[60]),Q.useEffect(Ge,Ke);let qe,Je;t[61]!==F||t[62]!==Oe||t[63]!==r||t[64]!==_?(qe=()=>{if(!Uo(w.current,r,_,F))return;let e=Ho(r,_);w.current.add(e),Oe()},Je=[F,Oe,r,_],t[61]=F,t[62]=Oe,t[63]=r,t[64]=_,t[65]=qe,t[66]=Je):(qe=t[65],Je=t[66]),Q.useEffect(qe,Je);let Ye;t[67]===Symbol.for(`react.memo_cache_sentinel`)?(Ye=()=>{y.current=null,S(null)},t[67]=Ye):Ye=t[67];let Ze;t[68]===_?Ze=t[69]:(Ze=[_],t[68]=_,t[69]=Ze),Q.useLayoutEffect(Ye,Ze);let Qe;t[70]!==x||t[71]!==we||t[72]!==_?(Qe=()=>{let e=y.current,t=we.current;if(Xo(e,x,_)){if(!t||!Jo(!!v.current?.isHistoryVirtualized())){y.current=null;return}t.scrollTop=Go(e.anchor,t.scrollHeight),y.current=null}},t[70]=x,t[71]=we,t[72]=_,t[73]=Qe):Qe=t[73];let $e;t[74]!==x||t[75]!==we||t[76]!==E||t[77]!==_?($e=[x,we,E,_],t[74]=x,t[75]=we,t[76]=E,t[77]=_,t[78]=$e):$e=t[78],Q.useLayoutEffect(Qe,$e);let et;t[79]===m?et=t[80]:(et={directory:m},t[79]=m,t[80]=et);let tt=et,nt=ce(r,d).boundary,rt;t[81]===nt?rt=t[82]:(rt=Vo(nt),t[81]=nt,t[82]=rt);let it=rt,ot;t[83]!==z?.status||t[84]!==tt||t[85]!==r||t[86]!==p?(ot=z?.status===`loading`||p.isLoading(r,tt),t[83]=z?.status,t[84]=tt,t[85]=r,t[86]=p,t[87]=ot):ot=t[87];let lt=ot,ft;t[88]!==m||t[89]!==h||t[90]!==r?(ft=[`context-panel-load-older`,h,m,r],t[88]=m,t[89]=h,t[90]=r,t[91]=ft):ft=t[91];let pt;t[92]!==nt||t[93]!==r||t[94]!==d?(pt=async()=>{nt.kind===`unknown`&&await de(d,r),await K(d,r)},t[92]=nt,t[93]=r,t[94]=d,t[95]=pt):pt=t[95];let mt;t[96]!==ft||t[97]!==pt?(mt={mutationKey:ft,mutationFn:pt},t[96]=ft,t[97]=pt,t[98]=mt):mt=t[98];let ht=A(mt),_t=ht.isPending,yt;t[99]!==lt||t[100]!==it||t[101]!==_t||t[102]!==me||t[103]!==ht||t[104]!==we||t[105]!==f||t[106]!==_?(yt=()=>{if(!Ko(it,_t||lt)||ht.isPending)return;me&&xe(ls);let e=b.current+1;b.current=e;let t=we.current,n=t?Yo({hasMore:it,isLoading:_t,historyVirtualized:!!v.current?.isHistoryVirtualized(),scrollHeight:t.scrollHeight,scrollTop:t.scrollTop}):null;y.current=n?{token:e,viewportKey:_,anchor:n}:null,ht.mutateAsync().then(()=>{S(e)},()=>{S(e),G.error(f(`chat.history.loadOlderFailed`))})},t[99]=lt,t[100]=it,t[101]=_t,t[102]=me,t[103]=ht,t[104]=we,t[105]=f,t[106]=_,t[107]=yt):yt=t[107];let xt=P(yt),St=z?.status===`error`?z.error:void 0,Tt;t[108]!==a||t[109]!==F||t[110]!==ue||t[111]!==E.length||t[112]!==St?(Tt=Lo({directoryMatches:!0,requested:a,renderable:F,messageCount:E.length,working:ue,error:St}),t[108]=a,t[109]=F,t[110]=ue,t[111]=E.length,t[112]=St,t[113]=Tt):Tt=t[113];let Et=Tt,Dt;t[114]!==a||t[115]!==m||t[116]!==c||t[117]!==r||t[118]!==n?(Dt={kind:`panel`,surfaceId:n,sessionId:r,directory:m,active:a,capabilities:st,navigateSession:c},t[114]=a,t[115]=m,t[116]=c,t[117]=r,t[118]=n,t[119]=Dt):Dt=t[119];let Ot=Dt,kt;t[120]!==Be||t[121]!==it||t[122]!==xt?(kt=()=>{if(Bo(it)===`load-more`){xt();return}Be(`retry`)},t[120]=Be,t[121]=it,t[122]=xt,t[123]=kt):kt=t[123];let At=P(kt),jt;t[124]!==z?.error||t[125]!==At||t[126]!==f||t[127]!==Et?(jt=Et===`partial-error`?(0,$.jsxs)(`div`,{className:`flex items-center justify-center gap-2 px-3 py-2 text-sm text-[var(--status-error-foreground)]`,children:[(0,$.jsx)(`span`,{className:`truncate`,children:z?.error}),(0,$.jsx)(X,{type:`button`,variant:`secondary`,size:`xs`,onClick:At,children:f(`chat.history.retry`)})]}):null,t[124]=z?.error,t[125]=At,t[126]=f,t[127]=Et,t[128]=jt):jt=t[128];let Mt=jt,Nt;t[129]!==it||t[130]!==_t||t[131]!==xt||t[132]!==f?(Nt=qo(it)?(0,$.jsx)(`div`,{className:`flex justify-center pt-3 pb-1`,children:(0,$.jsxs)(X,{type:`button`,variant:`secondary`,size:`sm`,onClick:xt,disabled:_t,children:[_t?(0,$.jsx)(Y,{name:`loader-4`,className:`size-4 animate-spin`}):null,f(`chat.history.loadOlder`)]})}):null,t[129]=it,t[130]=_t,t[131]=xt,t[132]=f,t[133]=Nt):Nt=t[133];let Pt=Nt,Ft;t[134]===Symbol.for(`react.memo_cache_sentinel`)?(Ft=(0,$.jsx)(`div`,{className:`flex-shrink-0`,style:{height:Ct},"aria-hidden":`true`}),t[134]=Ft):Ft=t[134];let It=Ft,Lt;t[135]===Fe?Lt=t[136]:(Lt=()=>Fe(`instant`),t[135]=Fe,t[136]=Lt);let Rt=!ve,zt;t[137]!==me||t[138]!==Pt||t[139]!==Mt?(zt=me?(0,$.jsxs)($.Fragment,{children:[Mt,Pt]}):void 0,t[137]=me,t[138]=Pt,t[139]=Mt,t[140]=zt):zt=t[140];let Bt=me?It:void 0,Vt;t[141]!==q||t[142]!==J||t[143]!==Ne||t[144]!==_t||t[145]!==Te||t[146]!==we||t[147]!==r||t[148]!==ue||t[149]!==E||t[150]!==U||t[151]!==d||t[152]!==Lt||t[153]!==Rt||t[154]!==zt||t[155]!==Bt||t[156]!==be||t[157]!==_?(Vt=(0,$.jsx)(dt,{ref:v,sessionKey:r,virtualizerKey:_,messages:E,sessionIsWorking:ue,activeStreamingMessageId:U,activeStreamingPhase:q,onMessageContentChange:Te,getAnimationHandlers:J,isLoadingOlder:_t,scrollToBottom:Lt,scrollRef:we,directory:d,enableSendPark:!1,timelineScrollClassName:`absolute inset-0 z-0 chat-scroll overlay-scrollbar-target`,timelineScrollStyle:ns,timelineScrollDataset:rs,timelineFollowEnabled:Rt,timelineHistoryAnchorToken:be,timelineOnIsAtEndChange:Ne,headerSlot:zt,footerSlot:Bt}),t[141]=q,t[142]=J,t[143]=Ne,t[144]=_t,t[145]=Te,t[146]=we,t[147]=r,t[148]=ue,t[149]=E,t[150]=U,t[151]=d,t[152]=Lt,t[153]=Rt,t[154]=zt,t[155]=Bt,t[156]=be,t[157]=_,t[158]=Vt):Vt=t[158];let Ht=Vt,Ut=me?ge:ke,Wt;t[159]===Fe?Wt=t[160]:(Wt=()=>Fe(`smooth`),t[159]=Fe,t[160]=Wt);let Gt;t[161]!==Ut||t[162]!==Wt?(Gt=(0,$.jsx)(at,{visible:Ut,onClick:Wt}),t[161]=Ut,t[162]=Wt,t[163]=Gt):Gt=t[163];let Kt=Gt,qt;t[164]!==s||t[165]!==l||t[166]!==f?(qt=s?(0,$.jsxs)(X,{type:`button`,variant:`outline`,size:`xs`,onClick:l,className:`absolute left-3 top-3 z-20 !font-normal bg-[var(--surface-background)]/95`,"aria-label":f(`chat.container.returnToParent.aria`),title:f(`chat.container.returnToParent.title`),children:[(0,$.jsx)(Y,{name:`arrow-left`,className:`h-4 w-4`}),f(`chat.container.returnToParent.label`)]}):null,t[164]=s,t[165]=l,t[166]=f,t[167]=qt):qt=t[167];let Jt;t[168]!==Be||t[169]!==me||t[170]!==Pt||t[171]!==Mt||t[172]!==z?.error||t[173]!==we||t[174]!==Kt||t[175]!==Ht||t[176]!==Et?(Jt=(0,$.jsx)(`div`,{className:`relative min-h-0 flex-1`,children:Et===`cold-loading`||Et===`working-empty`||Et===`authoritative-empty`||Et===`fatal-error`?(0,$.jsx)(is,{state:Et,error:z?.error,onRetry:()=>Be(`retry`)}):me?(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`absolute inset-0`,children:[Ht,(0,$.jsx)(Xe,{containerRef:we,userIntentOnly:!0,observeMutations:!1})]}),Kt]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(De,{ref:we,className:`absolute inset-0 overflow-y-auto overflow-x-hidden chat-scroll overlay-scrollbar-target`,observeMutations:!1,"data-scroll-shadow":`true`,"data-scrollbar":`chat`,children:(0,$.jsxs)(`div`,{className:`relative min-h-full`,children:[Mt,Pt,Ht,It]})}),Kt]})}),t[168]=Be,t[169]=me,t[170]=Pt,t[171]=Mt,t[172]=z?.error,t[173]=we,t[174]=Kt,t[175]=Ht,t[176]=Et,t[177]=Jt):Jt=t[177];let Yt;t[178]!==k.agentName||t[179]!==k.modelId||t[180]!==k.providerId||t[181]!==M||t[182]!==R?(Yt=R?(0,$.jsx)(ut,{agentName:k.agentName,providerId:k.providerId,modelId:k.modelId,modelName:M}):null,t[178]=k.agentName,t[179]=k.modelId,t[180]=k.providerId,t[181]=M,t[182]=R,t[183]=Yt):Yt=t[183];let Xt;t[184]!==r||t[185]!==n||t[186]!==qt||t[187]!==Jt||t[188]!==Yt?(Xt=(0,$.jsxs)(`div`,{className:`relative flex h-full min-h-0 flex-col bg-background`,"data-context-session-surface":`true`,"data-session-id":r,"data-surface-id":n,children:[qt,Jt,Yt]}),t[184]=r,t[185]=n,t[186]=qt,t[187]=Jt,t[188]=Yt,t[189]=Xt):Xt=t[189];let Zt;return t[190]!==Ot||t[191]!==Xt?(Zt=(0,$.jsx)(wt.Provider,{value:Ot,children:Xt}),t[190]=Ot,t[191]=Xt,t[192]=Zt):Zt=t[192],Zt},os=e=>{let t=(0,Sn.c)(22),n=oe(),{t:r}=ee(),i;t[0]===e.directory?i=t[1]:(i=So(e.directory),t[0]=e.directory,t[1]=i);let a=i,o=a===So(n),s;t[2]!==a||t[3]!==e.active||t[4]!==e.onNavigateSession||t[5]!==e.sessionId||t[6]!==e.surfaceId?(s={kind:`panel`,surfaceId:e.surfaceId,sessionId:e.sessionId,directory:a,active:e.active,capabilities:st,navigateSession:e.onNavigateSession},t[2]=a,t[3]=e.active,t[4]=e.onNavigateSession,t[5]=e.sessionId,t[6]=e.surfaceId,t[7]=s):s=t[7];let c=s;if(!o){let n=e.sessionId,i=e.surfaceId,a;t[8]===r?a=t[9]:(a=r(`chat.emptyState.opencodeUnreachable`),t[8]=r,t[9]=a);let o;t[10]===a?o=t[11]:(o=(0,$.jsx)(is,{state:`directory-mismatch`,onRetry:us,error:a}),t[10]=a,t[11]=o);let s;t[12]!==e.sessionId||t[13]!==e.surfaceId||t[14]!==o?(s=(0,$.jsx)(`div`,{className:`h-full`,"data-context-session-surface":`true`,"data-session-id":n,"data-surface-id":i,children:o}),t[12]=e.sessionId,t[13]=e.surfaceId,t[14]=o,t[15]=s):s=t[15];let l;return t[16]!==c||t[17]!==s?(l=(0,$.jsx)(wt.Provider,{value:c,children:s}),t[16]=c,t[17]=s,t[18]=l):l=t[18],l}let l;return t[19]!==e||t[20]!==n?(l=(0,$.jsx)(as,{...e,syncDirectory:n}),t[19]=e,t[20]=n,t[21]=l):l=t[21],l};function ss(e){return e.providers}function cs(e){return e.legendTimelineEnabled}function ls(e){return e+1}function us(){}var ds=e=>{if(!e||typeof e!=`object`)return!1;let t=e;return typeof t.x==`number`&&typeof t.y==`number`},fs=e=>!e||typeof e!=`object`?!1:Object.values(e).every(e=>typeof e==`string`),ps=e=>{if(!e||typeof e!=`object`)return!1;let t=e,n=t.bounds;return typeof t.tag==`string`&&typeof t.text==`string`&&typeof t.selector==`string`&&typeof t.path==`string`&&!!n&&typeof n?.x==`number`&&typeof n?.y==`number`&&typeof n?.width==`number`&&typeof n?.height==`number`&&ds(t.center)&&fs(t.attributes)&&fs(t.computedStyle)&&Array.isArray(t.ancestry)},ms=({pageUrl:e,viewport:t,devicePixelRatio:n,target:r,screenshotAttached:i,intro:a})=>{let o=r.text.trim(),s=Object.entries(r.attributes).map(([e,t])=>`${e}="${t}"`).join(` `),c=r.computedStyle,l=r.bounds,u=r.center,d=a.replace(/[.:]+$/g,``),f=r.ancestry.map(e=>e.selectorPart).join(` > `);return[`${d}:`,`Page: ${e||`preview`}`,`Viewport: ${t.width}x${t.height}, DPR ${n}`,`Screenshot: ${i?`attached`:`not attached`}`,`Element: ${r.tag}`,o?`Text: ${o}`:null,`- Selector: ${r.selector}`,`- Path: ${r.path}`,f?`- Ancestry: ${f}`:null,s?`- Attributes: ${s}`:null,`- Bounds: x=${Math.round(l.x)}, y=${Math.round(l.y)}, width=${Math.round(l.width)}, height=${Math.round(l.height)}`,`- Center: x=${Math.round(u.x)}, y=${Math.round(u.y)}`,`Styles: display=${c.display}; position=${c.position}; font=${c.fontWeight} ${c.fontSize} / ${c.lineHeight} ${c.fontFamily}; color=${c.color}; background=${c.backgroundColor}; z-index=${c.zIndex}`].filter(e=>typeof e==`string`).join(`
|
|
156
|
+
`);if(!r)return;let i=t===n?`${t}`:`${t}-${n}`,a=`${Z.name}:${i}`;Cr(Z.path,a,r),wr(x(a),`append-inline`),c.getState().setActiveMainTab(`chat`)},[Cr,hn,Z,wr]),ta=!!(Z&&(!Ki||qi)&&!Ji&&Xt.length>0),na=!!(Z&&Zi.length>0),ra=!!(Z&&!ft&&!Ki&&!Ji&&r.writeFile&&Xt.length<=Sa),ha=!!(Z?.path&&ka(Z.path)),ga=!!(Z?.path&&Aa(Z.path)),Fa=!!(Z?.path&&zt(Z.path)),Ia=!!(Z&&!Ki&&!Ji),La=Ia&&!ha&&!Fa&&!(ga&&pe===`preview`),Ra=ha&&ue===`edit`||ga&&pe===`edit`||!ha&&!ga&&le===`edit`,za=Q.useMemo(()=>dt?We(dt):null,[dt]),[Ba,Va]=Q.useState(null);Q.useEffect(()=>{let e=!1,t=Z?.path;if(!t||za){Va(null);return}return Va(null),He(t).then(t=>{e||Va(t)}),()=>{e=!0}},[Z?.path,za]),Q.useEffect(()=>{!ra&&le===`edit`&&q(`view`)},[ra,le]);let Ha=`openchamber:files:md-viewer-mode`,Ua=`openchamber:files:html-viewer-mode`;Q.useEffect(()=>{let e=Z?.path;if(!e)return;q(Oe.current[e]??`edit`);let t=Xr?`preview`:`edit`;try{let e=localStorage.getItem(Ha);(e===`preview`||e===`edit`)&&(t=e)}catch{}de(Pe.current[e]??t);let n=Xr?`preview`:`edit`;try{let e=localStorage.getItem(Ua);(e===`preview`||e===`edit`)&&(n=e)}catch{}me(Ie.current[e]??n),ge(Le.current[e]??(Xr?`preview`:`edit`))},[Z?.path,Xr]);let Wa=Q.useCallback(e=>{let t=Z?.path;t&&(Oe.current[t]=e),q(e)},[Z?.path]),Ga=Q.useCallback(e=>{let t=Z?.path;t&&(Pe.current[t]=e),de(e);try{localStorage.setItem(Ha,e)}catch{}},[Z?.path]),Ka=Q.useCallback(()=>ue,[ue]),qa=Q.useCallback(e=>{let t=Z?.path;t&&(Ie.current[t]=e),me(e);try{localStorage.setItem(Ua,e)}catch{}},[Z?.path]),Ja=Q.useCallback(e=>{let t=Z?.path;if(t&&(Le.current[t]=e),wn.current&&=(clearTimeout(wn.current),null),Dn.current!==null&&(cancelAnimationFrame(Dn.current),Dn.current=null),e===`edit`)gn(Tn.current||Xt),ge(e);else{Tn.current=hn;let e=t;ge(`edit`),Dn.current=requestAnimationFrame(()=>{Dn.current=requestAnimationFrame(()=>{Dn.current=null,!(w&&e&&Et.getState().byRoot[w]?.selectedPath!==e)&&(De(e=>e+1),ge(`preview`))})});return}},[hn,Xt,w,Z?.path]),Ya=Q.useCallback(async(e,t)=>{if(!r.writeFile||t===En.current)return!1;if(!(await r.writeFile(e,t))?.success)return G.error(n(`filesView.toast.writeFileFailed`)),!1;Tn.current=t,En.current=t,gn(t);let i=await yi(e,mt).catch(()=>null);return i&&(kn.current=i),!0},[r,yi,mt,n]);Q.useEffect(()=>()=>{wn.current&&=(clearTimeout(wn.current),null),Dn.current!==null&&(cancelAnimationFrame(Dn.current),Dn.current=null)},[he,Z?.path]);let Xa=Q.useCallback(e=>{if(Tn.current=e,!Z?.path||he!==`preview`||!r.writeFile)return;wn.current&&clearTimeout(wn.current);let t=Z.path;wn.current=setTimeout(()=>{wn.current=null,Ya(t,e).then(e=>{e&&(Pn(!0),setTimeout(()=>Pn(!1),1500))}).catch(e=>{G.error(e instanceof Error?e.message:n(`filesView.toast.saveFailed`))})},Ci)},[he,r.writeFile,Ya,Z?.path,n]),Za=Q.useMemo(()=>Fa&&(Tn.current||hn)||Xt,[hn,Xt,Fa]),Qa=Q.useCallback(()=>pe,[pe]);Q.useEffect(()=>{let e=e=>{let t=e?`preview`:`edit`;for(let e of Xe)Oe.current[e]=`edit`,ka(e)&&(Pe.current[e]=t),Aa(e)&&(Ie.current[e]=t),zt(e)&&(Le.current[e]=t);q(`edit`),de(t),me(t),ge(t);try{localStorage.setItem(Ha,t),localStorage.setItem(Ua,t)}catch{}},t=t=>{let n=!!t.detail?.enabled;e(n)};return window.addEventListener(`openchamber:file-viewer-preview-mode-changed`,t),()=>{window.removeEventListener(`openchamber:file-viewer-preview-mode-changed`,t)}},[Xe]),Q.useEffect(()=>{if(!Wr||!w)return;let e=()=>{typeof window>`u`||Zn.current===null&&(Zn.current=window.requestAnimationFrame(()=>{Zn.current=null,Xn(e=>e+1)}))},t=(e,t)=>{if(e.state.doc.length!==t.length)return!1;if(t.length===0)return!0;let n=Math.min(128,t.length);if(e.state.sliceDoc(0,n)!==t.slice(0,n))return!1;let r=Math.max(0,t.length-n);return e.state.sliceDoc(r,t.length)===t.slice(r)},n=la(Wr.path);if(!n){Gr(null),Qn.current={key:``,attempts:0};return}let r=`${n}:${Wr.line}:${Wr.column??1}`;if(Qn.current.key!==r&&(Qn.current={key:r,attempts:0}),Z?.path!==n){if(Ln)return;Di(ct(n));return}if(tn||dn!==n)return;if(rn||Ki||Ji){Gr(null),Qn.current={key:``,attempts:0};return}if(!ra)return;if(le!==`edit`){q(`edit`);return}let i=qn.current;if(!i){e();return}if(!t(i,hn)){e();return}let a=Math.max(1,Math.min(Wr.line,i.state.doc.lines)),o=i.state.doc.line(a),s=Math.max(1,Wr.column||1),c=Math.max(0,o.to-o.from),l=Math.min(c,s-1),u=o.from+l;if(i.state.selection.main.head!==u||Qn.current.attempts===0){Qn.current.attempts+=1,i.dispatch({selection:{anchor:u},effects:M.scrollIntoView(u,{y:`center`})}),i.focus(),e();return}typeof window<`u`&&window.requestAnimationFrame(()=>{let e=qn.current;e&&(e.dispatch({selection:{anchor:u},effects:M.scrollIntoView(u,{y:`center`})}),e.focus())}),Gr(null),Qn.current={key:``,attempts:0}},[ra,Ln,hn,Yn,rn,tn,Ki,Ji,dn,Di,Wr,w,Z?.path,Gr,le,ct]),Q.useEffect(()=>{if(!Kr||!w)return;let e=la(Kr);if(!e){qr(null);return}if(Z?.path!==e){if(Ln)return;Di(ct(e));return}if(!(tn||dn!==e||rn||Ki||Ji)){if(ra&&le===`edit`){let e=qn.current;if(!e)return;e.focus()}qr(null)}},[ra,Ln,rn,tn,Di,Ki,Ji,dn,Kr,w,Z?.path,qr,le,ct]);let $a=Q.useCallback(e=>{if(!f||!e||!e.hasFocus||typeof window>`u`)return;let t=window.visualViewport;if(!t)return;let n=document.documentElement.clientHeight||window.innerHeight;if(Math.max(0,n-(t.offsetTop+t.height))<=0)return;let r=e.state.selection.main.head,i=e.coordsAtPos(r);if(!i)return;let a=Math.round(t.offsetTop+t.height),o=i.bottom+20-a;o<=0||(e.scrollDOM.scrollTop+=o)},[f]);Q.useEffect(()=>{if(!f||typeof window>`u`)return;let e=()=>{window.requestAnimationFrame(()=>{$a(qn.current)})},t=window.visualViewport;return t?.addEventListener(`resize`,e),t?.addEventListener(`scroll`,e,{passive:!0}),document.addEventListener(`selectionchange`,e),()=>{t?.removeEventListener(`resize`,e),t?.removeEventListener(`scroll`,e),document.removeEventListener(`selectionchange`,e)}},[f,$a]),Q.useEffect(()=>{if(le!==`edit`||f)return;let e=Re(`open_go_to_line`,Jr),t=t=>{let n=t.target;if(n?.closest(`[role="dialog"]`))return;let r=!!n?.closest(`.cm-editor`);if(!(n?.closest(`input, textarea, [contenteditable="true"], [role="textbox"]`)&&!r||!document.activeElement?.closest(`.cm-editor`))){if(Fe(t,e)){t.preventDefault(),vr(!0);return}if(t.metaKey&&!t.ctrlKey&&!t.altKey&&!t.shiftKey&&t.key.toLowerCase()===`i`){let e=qn.current?.state.selection.main;e&&!e.empty&&(t.preventDefault(),$i())}}};return window.addEventListener(`keydown`,t),()=>window.removeEventListener(`keydown`,t)},[$i,f,Jr,le]);let eo=c(e=>e.editorFontSize),to=Q.useMemo(()=>{if(!Z?.path)return[un(o,{fontSize:eo})];let e=Bt(Z.path),t=[un(o,e?{syntaxColors:!1,fontSize:eo}:{fontSize:eo})],n=za??Ba;return n&&t.push(n),e&&t.push(mn({language:e,themeName:o.metadata.id,theme:Nt(o)})),L&&t.push(M.lineWrapping),t.push(M.updateListener.of(e=>{(e.selectionSet||e.docChanged)&&Qi(e.view)})),f&&t.push(M.updateListener.of(e=>{e.view.hasFocus&&(e.selectionSet||e.focusChanged||e.viewportChanged||e.geometryChanged)&&window.requestAnimationFrame(()=>{$a(e.view)})})),t},[o,Z?.path,za,Ba,L,f,$a,eo,Qi]),no=Q.useMemo(()=>({light:ze.metadata.id,dark:Ue.metadata.id}),[ze.metadata.id,Ue.metadata.id]),ro=Z?.path&&Ki&&!i.isDesktop&&!qi?`${Z.path}|${mt.allowOutsideWorkspace?`outside`:`workspace`}|${mt.outsideFileGrant??``}`:``,io=Z?.path&&Ji?`${Z.path}|${mt.allowOutsideWorkspace?`outside`:`workspace`}|${mt.outsideFileGrant??``}`:``,ao=Z?.path&&ga&&pe===`preview`&&!i.isVSCode?Z.path:``,oo=n(`filesView.error.readFileFailed`),{readyKey:so,nonce:co}=Pa(ro,an,oo),{readyKey:lo,nonce:uo}=Pa(ao,an,oo),{readyKey:fo,nonce:po}=Pa(io,an,oo),mo=!!(ro&&so!==ro),ho=!!(ao&&lo!==ao),go=!!(io&&fo!==io),_o=Z?.path&&Ki?i.isDesktop?qi?`data:${Vt(Z.path)};utf8,${encodeURIComponent(Xt)}`:on:qi?`data:${Vt(Z.path)};utf8,${encodeURIComponent(Xt)}`:so===ro?a().authenticatedAsset(`/api/fs/raw`,{path:Z.path,allowOutsideWorkspace:mt.allowOutsideWorkspace?`true`:void 0,outsideFileGrant:mt.outsideFileGrant,directory:w||void 0}):``:``,vo=Q.useCallback(()=>{if(!Z?.path||!Ki)return;let e=qi?_o:Z.path||_o;if(!e)return;let t=Z.name||Z.path;H({open:!0,title:t,content:``,metadata:{tool:`image-preview`,filename:t,mime:Vt(Z.path)},image:{url:e,mimeType:Vt(Z.path),filename:t}})},[_o,Ki,qi,Z?.name,Z?.path]),yo=Q.useCallback(e=>{H(t=>t.open===e?t:{...t,open:e})},[]),bo=Q.useCallback((e,t)=>{let r=e.name||n(`filesView.editor.imageAltFallback`);return(0,$.jsx)(`div`,{className:J(`flex items-center justify-center`,t?.fullHeight?`h-full p-4`:`h-full p-3`),children:(0,$.jsx)(`button`,{type:`button`,className:`max-h-full max-w-full cursor-zoom-in rounded-md border-0 bg-transparent p-0 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary`,onClick:vo,"aria-label":r,disabled:!_o,children:(0,$.jsx)(`img`,{src:_o,alt:r,className:J(`object-contain rounded-md border border-border/30 bg-primary/10`,t?.fullHeight?`max-h-full max-w-full`:`max-h-[70vh] max-w-full`),draggable:!1},co)})})},[co,_o,vo,n]),xo=Z?.path&&Ji&&fo===io?a().authenticatedAsset(`/api/fs/raw`,{path:Z.path,allowOutsideWorkspace:mt.allowOutsideWorkspace?`true`:void 0,outsideFileGrant:mt.outsideFileGrant,directory:w||void 0}):``,So=Q.useCallback(e=>(0,$.jsx)(`div`,{className:`h-full overflow-hidden bg-[var(--surface-background)]`,children:(0,$.jsx)(`iframe`,{src:xo,className:`h-full w-full border-0`,title:e.name},po)}),[xo,po]);Q.useEffect(()=>{let e=!1;return(async()=>{if(!i.isDesktop||!Z?.path||!Ki||qi){ln.current&&=(URL.revokeObjectURL(ln.current),``),sn(``);return}an(null),ln.current&&=(URL.revokeObjectURL(ln.current),``),await(r.readFileBinary?r.readFileBinary(Z.path,mt).then(e=>e.dataUrl):(async()=>{let t=await _(`/api/fs/raw`,{query:{path:Z.path,allowOutsideWorkspace:mt.allowOutsideWorkspace?`true`:void 0,outsideFileGrant:mt.outsideFileGrant,directory:w||void 0}});if(!t.ok)throw Error(n(`filesView.error.readFileFailed`));let r=await t.blob(),i=URL.createObjectURL(r);return e?(URL.revokeObjectURL(i),``):(ln.current=i,i)})()).then(t=>{e||(sn(t),pn(Z.path))}).catch(t=>{ln.current&&=(URL.revokeObjectURL(ln.current),``),e||(sn(``),an(t instanceof Error?t.message:n(`filesView.error.readFileFailed`)),pn(null))}).finally(()=>{e||nn(!1)})})(),()=>{e=!0}},[r,Ki,qi,w,i.isDesktop,Z?.path,mt,n]),Q.useEffect(()=>()=>{ln.current&&=(URL.revokeObjectURL(ln.current),``)},[]);let Co=Q.useCallback(()=>tr(null),[]),wo=Q.useMemo(()=>$n({drafts:ei,editingDraftId:ri,commentText:ti,onTextChange:ni,selection:Lr,isDragging:Vr,fileLabel:Z?.path??``,newWidgetId:`files-new-comment-input`,mapDraftToRange:e=>({start:e.startLine,end:e.endLine}),onSave:ui,onCancel:()=>{Rr(null),oi()},onEdit:e=>{ci(e),Rr({start:e.startLine,end:e.endLine})},onDelete:li,onAddToChat:ea}),[ea,oi,ti,li,ri,ei,ui,Vr,Lr,Z?.path,ni,ci]),To=Q.useCallback((e,t)=>(0,$.jsx)(`div`,{className:`h-full`,children:(0,$.jsx)(qt,{file:{name:e.name,contents:t,lang:Bt(e.path)||void 0},options:{disableFileHeader:!0,overflow:L?`wrap`:`scroll`,theme:no,themeType:o.metadata.variant===`dark`?`dark`:`light`},className:`block h-full w-full`,style:{height:`100%`}})}),[o.metadata.variant,no,L]),Eo=({exitFullscreenOnly:t=!1,layout:i=`floating`}={})=>{if(!Z)return null;let a=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`,o=(e,t)=>(0,$.jsxs)(Me,{children:[(0,$.jsx)(Ae,{asChild:!0,children:(0,$.jsx)(`span`,{className:`inline-flex`,children:t})}),(0,$.jsx)(je,{side:`bottom`,sideOffset:6,children:e})]});return(0,$.jsxs)(`div`,{className:a,children:[ra&&Ra&&(0,$.jsxs)($.Fragment,{children:[_n?(0,$.jsxs)(`span`,{className:`flex items-center gap-1 px-1 text-muted-foreground typography-meta`,children:[(0,$.jsx)(Y,{name:`loader-4`,className:`size-3.5 animate-spin`}),n(`filesView.editor.saving`)]}):Fn&&jn===`saved`&&!xi?(0,$.jsxs)(`span`,{className:`flex items-center gap-1 px-1 text-[color:var(--status-success)] typography-meta`,children:[(0,$.jsx)(Y,{name:`check`,className:`size-3.5`}),n(`filesView.editor.saved`)]}):xi?o(n(Fn?`filesView.editor.saveNowTitle`:`filesView.editor.saveNowManualTitle`,{shortcut:`${we()}+S`}),(0,$.jsx)(X,{variant:`ghost`,size:`sm`,onClick:()=>void Si(),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:n(Fn?`filesView.editor.saveNowTitle`:`filesView.editor.saveNowManualTitle`,{shortcut:`${we()}+S`}),"aria-label":n(`filesView.editor.saveAria`,{shortcut:`${we()}+S`}),children:(0,$.jsx)(Y,{name:`save-3`,className:`size-4`})})):null,o(n(Fn?`filesView.editor.autoSaveOn`:`filesView.editor.manualSave`),(0,$.jsx)(X,{variant:`ghost`,size:`sm`,onClick:()=>In(e=>!e),className:J(`size-6 p-0 transition-opacity hover:bg-transparent focus-visible:bg-transparent active:bg-transparent`,Fn?`text-foreground opacity-100`:`text-muted-foreground opacity-65 hover:opacity-100`),title:n(Fn?`filesView.editor.autoSaveOn`:`filesView.editor.manualSave`),"aria-label":n(Fn?`filesView.editor.autoSaveOn`:`filesView.editor.manualSave`),children:Fn?(0,$.jsx)(Y,{name:`file-check-fill`,className:`size-4`}):(0,$.jsx)(Y,{name:`file-check`,className:`size-4`})}))]}),Ia&&yr?o(`${n(`chat.textSelection.title.addToCurrentChat`)} (⌘I)`,(0,$.jsxs)(X,{variant:`ghost`,size:`sm`,onClick:$i,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:`${n(`chat.textSelection.title.addToCurrentChat`)} (⌘I)`,"aria-label":`${n(`chat.textSelection.title.addToCurrentChat`)} (⌘I)`,children:[(0,$.jsx)(Y,{name:`chat-new`,className:`size-4`}),(0,$.jsx)(`span`,{children:n(`chat.textSelection.actions.addToChat`)}),(0,$.jsx)(tt,{shortcut:`⌘+I`})]})):null,(0,$.jsxs)(Ve,{onOpenChange:K,children:[(0,$.jsxs)(Me,{children:[(0,$.jsx)(Ae,{asChild:!0,children:(0,$.jsx)(`span`,{className:`inline-flex`,children:(0,$.jsx)(Ke,{asChild:!0,children:(0,$.jsx)(X,{variant:`ghost`,size:`sm`,className:`size-6 p-0 text-foreground opacity-100 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent`,title:n(`filesView.editor.openInDesktopApp`),"aria-label":n(`filesView.editor.openInDesktopApp`),children:(0,$.jsx)(Y,{name:`file-transfer`,className:`size-4`})})})})}),(0,$.jsx)(je,{side:`bottom`,sideOffset:6,children:n(`filesView.editor.openInDesktopApp`)})]}),(0,$.jsxs)(Ge,{align:`end`,className:`w-56 max-h-[70vh] overflow-y-auto`,children:[Ar.map(e=>(0,$.jsxs)(Je,{className:`flex items-center gap-2`,onClick:()=>void Fr(e),children:[(0,$.jsx)(sa,{label:e.label,iconDataUrl:e.iconDataUrl}),(0,$.jsx)(`span`,{className:`typography-ui-label text-foreground`,children:e.label})]},e.id)),jr?(0,$.jsxs)(Je,{className:`flex items-center gap-2`,onClick:()=>void Nr(!0),children:[(0,$.jsx)(Y,{name:`refresh`,className:`size-4`}),(0,$.jsx)(`span`,{className:`typography-ui-label text-foreground`,children:n(`filesView.editor.refreshApps`)})]}):null]})]}),!Ki&&!Ji&&(0,$.jsxs)($.Fragment,{children:[o(n(L?`filesView.editor.disableLineWrap`:`filesView.editor.enableLineWrap`),(0,$.jsx)(X,{variant:`ghost`,size:`sm`,onClick:()=>ie(!L),className:J(`size-6 p-0 transition-opacity hover:bg-transparent focus-visible:bg-transparent active:bg-transparent`,L?`text-foreground opacity-100`:`text-muted-foreground opacity-65 hover:opacity-100`),title:n(L?`filesView.editor.disableLineWrap`:`filesView.editor.enableLineWrap`),children:(0,$.jsx)(Y,{name:`text-wrap`,className:`size-4`})})),le===`edit`&&(0,$.jsxs)($.Fragment,{children:[o(n(`filesView.editor.findInFile`),(0,$.jsx)(X,{variant:`ghost`,size:`sm`,onClick:e=>{B(!z),e.currentTarget.blur()},className:`size-6 p-0 text-foreground opacity-100 transition-opacity hover:bg-transparent focus-visible:bg-transparent active:bg-transparent`,title:n(`filesView.editor.findInFile`),children:(0,$.jsx)(Y,{name:`search`,className:`size-4`})})),o(n(`filesView.editor.goToLine`),(0,$.jsx)(X,{variant:`ghost`,size:`sm`,onClick:e=>{vr(e=>!e),e.currentTarget.blur()},className:`size-6 p-0 text-foreground opacity-100 transition-opacity hover:bg-transparent focus-visible:bg-transparent active:bg-transparent`,title:n(`filesView.editor.goToLine`),children:(0,$.jsx)(Y,{name:`menu-fold-2`,className:`size-4`})})),(0,$.jsx)(zi,{open:_r,onOpenChange:vr,view:qn.current,variant:`inline`})]})]}),La&&ra&&!ga&&(0,$.jsx)(fn,{currentMode:le===`view`?`preview`:`edit`,onToggle:()=>{Wa(le===`view`?`edit`:`view`)}}),ha&&o(n(Ka()===`preview`?`filesView.editor.switchToEditMode`:`filesView.editor.switchToPreviewMode`),(0,$.jsx)(X,{variant:`ghost`,size:`sm`,onClick:()=>Ga(Ka()===`preview`?`edit`:`preview`),className:J(`size-6 p-0 transition-colors hover:bg-[var(--interactive-hover)] focus-visible:bg-[var(--interactive-hover)] active:bg-[var(--interactive-hover)]`,Ka()===`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:n(Ka()===`preview`?`filesView.editor.switchToEditMode`:`filesView.editor.switchToPreviewMode`),"aria-label":n(Ka()===`preview`?`filesView.editor.switchToEditMode`:`filesView.editor.switchToPreviewMode`),children:(0,$.jsx)(Y,{name:Ka()===`preview`?`eye`:`eye-off`,className:`size-4`})})),Aa(Z?.path??``)&&(0,$.jsx)(fn,{currentMode:Qa(),onToggle:()=>{qa(Qa()===`preview`?`edit`:`preview`)}}),ha&&Ka()===`preview`&&Zr&&(0,$.jsxs)(Me,{children:[(0,$.jsx)(Ae,{asChild:!0,children:(0,$.jsx)(X,{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":n(Qt?`filesView.tts.stopSpeaking`:`filesView.tts.readAloud`),onClick:()=>{Qt?en():Xt.trim()&&$t(Xt)},children:Qt?(0,$.jsx)(Y,{name:`stop`,className:`size-4 text-[color:var(--status-success)]`}):(0,$.jsx)(Y,{name:`volume-up`,className:`size-4`})})}),(0,$.jsx)(je,{sideOffset:8,children:n(Qt?`filesView.tts.stopSpeaking`:`filesView.tts.readAloud`)})]}),Fa&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(fn,{currentMode:he,onToggle:()=>Ja(he===`preview`?`edit`:`preview`)}),he===`preview`&&(0,$.jsx)(X,{variant:`ghost`,size:`sm`,onClick:async()=>{let e=On.current?.getXml();if(wn.current&&=(clearTimeout(wn.current),null),Z?.path&&e){if(!await Ya(Z.path,e))return;Pn(!0),setTimeout(()=>Pn(!1),1500)}},className:`size-6 p-0 text-foreground hover:bg-transparent focus-visible:bg-transparent active:bg-transparent`,title:n(`filesView.diagram.saveDiagram`),children:Nn?(0,$.jsx)(Y,{name:`check`,className:`size-4 text-[color:var(--status-success)]`}):(0,$.jsx)(Y,{name:`save-3`,className:`size-4`})})]}),ta&&o(n(`filesView.editor.copyFileContents`),(0,$.jsx)(X,{variant:`ghost`,size:`sm`,onClick:async()=>{(await te(Xt)).ok?(mr(!0),Un.current!==null&&window.clearTimeout(Un.current),Un.current=window.setTimeout(()=>{mr(!1)},1200)):G.error(n(`filesView.toast.copyFailed`))},className:`size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent`,title:n(`filesView.editor.copyFileContents`),"aria-label":n(`filesView.editor.copyFileContents`),children:pr?(0,$.jsx)(Y,{name:`check`,className:`size-4 text-[color:var(--status-success)]`}):(0,$.jsx)(Y,{name:`clipboard`,className:`size-4`})})),na&&o(n(`filesView.editor.copyFilePathTitle`,{path:Zi}),(0,$.jsx)(X,{variant:`ghost`,size:`sm`,onClick:async()=>{(await te(Zi)).ok?(gr(!0),Wn.current!==null&&window.clearTimeout(Wn.current),Wn.current=window.setTimeout(()=>{gr(!1)},1200)):G.error(n(`filesView.toast.copyFailed`))},className:`size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent`,title:n(`filesView.editor.copyFilePathTitle`,{path:Zi}),"aria-label":n(`filesView.editor.copyFilePathTitle`,{path:Zi}),children:hr?(0,$.jsx)(Y,{name:`check`,className:`size-4 text-[color:var(--status-success)]`}):(0,$.jsx)(Y,{name:`file-copy-2`,className:`size-4`})})),r.downloadFile&&o(n(`filesView.editor.saveFile`),(0,$.jsx)(X,{variant:`ghost`,size:`sm`,onClick:()=>{let e=r.downloadFile;e&&e(Z.path).catch(e=>{console.error(`Download failed:`,e),G.error(n(`sidebarFilesTree.toast.operationFailed`))})},className:`size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent`,title:n(`filesView.editor.saveFile`),"aria-label":n(`filesView.editor.saveFile`),children:(0,$.jsx)(Y,{name:`download`,className:`size-4`})})),t?o(n(`filesView.editor.exitFullscreen`),(0,$.jsx)(X,{variant:`ghost`,size:`sm`,onClick:()=>ae(!1),className:`size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent`,title:n(`filesView.editor.exitFullscreen`),"aria-label":n(`filesView.editor.exitFullscreen`),children:(0,$.jsx)(Y,{name:`fullscreen-exit`,className:`size-4`})})):!f&&e===`full`&&o(n(R?`filesView.editor.exitFullscreen`:`filesView.editor.fullscreen`),(0,$.jsx)(X,{variant:`ghost`,size:`sm`,onClick:()=>ae(!R),className:`size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent`,title:n(R?`filesView.editor.exitFullscreen`:`filesView.editor.fullscreen`),"aria-label":n(R?`filesView.editor.exitFullscreen`:`filesView.editor.fullscreen`),children:R?(0,$.jsx)(Y,{name:`fullscreen-exit`,className:`size-4`}):(0,$.jsx)(Y,{name:`fullscreen`,className:`size-4`})}))]})},Do=(0,$.jsxs)(`div`,{className:`relative flex h-full min-h-0 min-w-0 w-full flex-col overflow-hidden`,children:[(0,$.jsx)(Se,{open:Ln,onOpenChange:e=>{e||Rn(!0)},children:(0,$.jsxs)(ye,{showCloseButton:!1,className:`max-w-md`,children:[(0,$.jsxs)(_e,{children:[(0,$.jsx)(be,{children:n(`filesView.unsaved.title`)}),(0,$.jsx)(xe,{children:n(`filesView.unsaved.description`)})]}),(0,$.jsxs)(ve,{children:[(0,$.jsx)(X,{variant:`outline`,onClick:()=>void Ai(),disabled:_n,className:`border-[var(--status-success-border)] bg-[var(--status-success-background)] text-[var(--status-success)] hover:bg-[rgb(var(--status-success)/0.2)]`,children:n(`filesView.unsaved.saveChanges`)}),(0,$.jsx)(X,{variant:`destructive`,onClick:ki,children:n(`filesView.unsaved.discard`)})]})]})}),(0,$.jsxs)(`div`,{className:J(`flex flex-col flex-shrink-0`,T&&`border-b border-border/40`),children:[T?(0,$.jsxs)(`div`,{className:`flex min-w-0 items-center px-3 py-1.5`,children:[f&&I&&(0,$.jsx)(`button`,{type:`button`,onClick:()=>ne(!1),"aria-label":n(`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:(0,$.jsx)(Y,{name:`arrow-left-s`,className:`size-5`})}),f?Z?(0,$.jsxs)(Ve,{children:[(0,$.jsx)(Ke,{asChild:!0,children:(0,$.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":n(`filesView.editor.openFilesAria`),children:[(0,$.jsx)(St,{filePath:Z.path,extension:Z.extension,className:`size-3.5 flex-shrink-0`}),(0,$.jsx)(_a,{name:Z.name}),(0,$.jsx)(Y,{name:`arrow-down-s`,className:`size-4 flex-shrink-0 text-muted-foreground`})]})}),(0,$.jsx)(Ge,{align:`start`,className:`w-[min(24rem,calc(100vw-2rem))] max-w-[calc(100vw-2rem)]`,children:lt.map(e=>{let t=Z?.path===e.path;return(0,$.jsxs)(Je,{onSelect:n=>{if(n.target.closest(`[data-close-open-file]`)){n.preventDefault();return}t||Di(e)},className:J(`flex min-w-0 items-center justify-between gap-2 overflow-hidden`,t&&`bg-[var(--interactive-selection)] text-[var(--interactive-selection-foreground)]`),children:[(0,$.jsxs)(`span`,{className:`flex min-w-0 flex-1 items-center gap-2 overflow-hidden`,children:[(0,$.jsx)(St,{filePath:e.path,extension:e.extension,className:`size-3.5 flex-shrink-0`}),(0,$.jsx)(_a,{name:e.name})]}),(0,$.jsx)(`button`,{type:`button`,"data-close-open-file":!0,onPointerDown:e=>{e.preventDefault(),e.stopPropagation()},onClick:t=>{t.preventDefault(),t.stopPropagation(),ji(e.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":n(`filesView.editor.closeFileAria`,{name:e.name}),children:(0,$.jsx)(Y,{name:`close`,className:`size-3.5`})})]},e.path)})})]}):(0,$.jsx)(`div`,{className:`typography-ui-label font-medium truncate`,children:n(`filesView.editor.selectFile`)}):lt.length>0?(0,$.jsxs)(`div`,{className:`relative min-w-0 flex-1`,children:[_t.left&&(0,$.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`}),_t.right&&(0,$.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`}),(0,$.jsx)(`div`,{ref:gt,className:`flex min-w-0 items-center gap-1 overflow-x-auto scrollbar-none`,style:{scrollbarWidth:`none`,msOverflowStyle:`none`},children:lt.map(e=>{let t=Z?.path===e.path;return(0,$.jsxs)(`div`,{title:ma(w,e.path),className:J(`group inline-flex items-center gap-1 rounded-md border px-2 py-1 typography-ui-label transition-colors whitespace-nowrap`,t?`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:[(0,$.jsx)(St,{filePath:e.path,extension:e.extension,className:`size-3.5 flex-shrink-0`}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>{t||Di(e)},className:`max-w-[12rem] truncate text-left`,children:e.name}),(0,$.jsx)(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),ji(e.path)},className:J(`rounded-sm p-0.5 text-[var(--surface-muted-foreground)] hover:text-[var(--surface-foreground)]`,!t&&!v&&`opacity-0 group-hover:opacity-100`),"aria-label":n(`filesView.editor.closeFileAria`,{name:e.name}),children:(0,$.jsx)(Y,{name:`close`,className:`size-3.5`})})]},e.path)})})]}):(0,$.jsx)(`div`,{className:`typography-ui-label font-medium truncate`,children:n(`filesView.editor.selectFile`)})]}):null,Qr&&!f&&Z?(0,$.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:[Zi?(0,$.jsx)(`span`,{className:`min-w-0 flex-1 truncate typography-meta text-muted-foreground`,title:Zi,children:Zi}):null,(0,$.jsx)(`div`,{className:`ml-auto min-w-0 shrink-0 overflow-x-auto`,children:Eo({layout:`docked`})})]}):null]}),(0,$.jsxs)(`div`,{className:`flex-1 min-h-0 min-w-0 relative`,children:[Z&&!z&&!(Qr&&!f)&&(0,$.jsx)(`div`,{ref:U,className:`absolute right-3 top-3 z-30`,onMouseLeave:()=>{W.current>0||oe(!1)},children:V?Eo():(0,$.jsxs)(`div`,{className:`flex items-center gap-1`,children:[ha?(0,$.jsxs)(Me,{children:[(0,$.jsx)(Ae,{asChild:!0,children:(0,$.jsx)(`span`,{className:`inline-flex`,children:(0,$.jsx)(X,{variant:`ghost`,size:`sm`,onClick:()=>Ga(Ka()===`preview`?`edit`:`preview`),className:J(`size-8 rounded-lg border border-[var(--interactive-border)] bg-[var(--surface-elevated)] p-0 shadow-sm transition-colors`,Ka()===`preview`?`bg-[var(--interactive-selection)] text-[var(--interactive-selection-foreground)] hover:bg-[var(--interactive-selection)]`:`text-muted-foreground hover:text-foreground`),"aria-label":n(Ka()===`preview`?`filesView.editor.switchToEditMode`:`filesView.editor.switchToPreviewMode`),title:n(Ka()===`preview`?`filesView.editor.switchToEditMode`:`filesView.editor.switchToPreviewMode`),children:(0,$.jsx)(Y,{name:Ka()===`preview`?`eye`:`eye-off`,className:`size-4`})})})}),(0,$.jsx)(je,{side:`bottom`,sideOffset:6,children:n(Ka()===`preview`?`filesView.editor.switchToEditMode`:`filesView.editor.switchToPreviewMode`)})]}):null,(0,$.jsxs)(Me,{children:[(0,$.jsx)(Ae,{asChild:!0,children:(0,$.jsx)(`span`,{className:`inline-flex`,onMouseEnter:()=>oe(!0),children:(0,$.jsx)(X,{variant:`ghost`,size:`sm`,onClick:()=>oe(!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":n(`filesView.editor.showControlsAria`),title:n(`filesView.editor.controlsTitle`),children:(0,$.jsx)(Y,{name:`more-2-fill`,className:`size-4`})})})}),(0,$.jsx)(je,{side:`bottom`,sideOffset:6,children:n(`filesView.editor.controlsTitle`)})]})]})}),(0,$.jsx)(Ee,{outerClassName:`h-full min-w-0`,className:`h-full min-w-0`,children:Z?tn||mo||go?O?(0,$.jsx)(`div`,{className:`p-3`}):(0,$.jsxs)(`div`,{className:`p-3 flex items-center gap-2 typography-ui text-muted-foreground`,children:[(0,$.jsx)(Y,{name:`loader-4`,className:`size-4 animate-spin`}),n(`filesView.state.loading`)]}):rn?(0,$.jsx)(`div`,{className:`p-3 typography-ui text-[color:var(--status-error)]`,children:rn}):Ki&&Z?bo(Z):Ji?So(Z):Z&&Fa&&he===`preview`?(0,$.jsx)(`div`,{className:`h-full overflow-hidden`,style:{minHeight:`400px`},children:(0,$.jsx)(vn,{ref:On,xml:Za,onChange:Xa},`${Z.path}:${Ce}`)}):Z&&ha&&Ka()===`preview`?(0,$.jsxs)(`div`,{className:`h-full overflow-auto p-3`,children:[Xt.length>512e3&&(0,$.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:n(`filesView.warning.largeFilePreviewLimited`,{sizeKb:Math.round(Xt.length/1024)})}),(0,$.jsx)(Be,{fallback:(0,$.jsxs)(`div`,{className:`rounded-md border border-destructive/20 bg-destructive/10 px-3 py-2`,children:[(0,$.jsx)(`div`,{className:`mb-1 font-medium text-destructive`,children:n(`filesView.error.previewUnavailable`)}),(0,$.jsx)(`div`,{className:`text-sm text-muted-foreground`,children:n(`filesView.error.switchToEditMode`)})]}),children:(0,$.jsx)(Mt,{content:Xt,className:`typography-markdown-body`,stripFrontmatter:!0,enableFileReferences:!1})})]}):Z&&ga&&pe===`preview`?ho?(0,$.jsx)(`div`,{className:`flex h-full items-center justify-center text-muted-foreground typography-ui-label`,children:n(`common.loading`)}):(0,$.jsx)(`div`,{className:`h-full overflow-hidden`,children:(0,$.jsx)(`iframe`,{src:!i.isVSCode&&lo===ao?(()=>{let e=Z.path.split(`/`).map(e=>encodeURIComponent(e)).join(`/`);return a().authenticatedAsset(`/api/fs/serve${e.startsWith(`/`)?e:`/${e}`}`)})():void 0,srcDoc:i.isVSCode?(()=>{let e=Z.path.substring(0,Z.path.lastIndexOf(`/`)+1);return e?Xt.replace(/<head([^>]*)>/i,`<head$1><base href="${e}">`):Xt})():void 0,className:`w-full h-full border-none`,sandbox:`allow-scripts allow-same-origin allow-forms`,title:n(`filesView.editor.htmlPreviewTitle`)},uo)}):Z&&La&&le===`view`?To(Z,hn):(0,$.jsxs)(`div`,{className:J(`relative h-full`,Xi&&`overflow-hidden`),ref:Jn,children:[(0,$.jsx)(`div`,{className:J(`h-full`,Xi&&`invisible`),children:(0,$.jsx)(cn,{value:hn,onChange:gn,readOnly:!ra,vimMode:Yr===`vim`,extensions:to,className:`h-full`,blockWidgets:wo,onViewReady:e=>{qn.current=e,Qi(e),Xn(e=>e+1),window.requestAnimationFrame(()=>{$a(e)})},onViewDestroy:()=>{qn.current&&=null,br(!1),Sr(null),Xn(e=>e+1)},enableSearch:!0,searchOpen:z,onSearchOpenChange:B,highlightLines:Lr?{start:Math.min(Lr.start,Lr.end),end:Math.max(Lr.start,Lr.end)}:void 0,lineNumbersConfig:{domEventHandlers:{mousedown:(e,t,n)=>{if(!(n instanceof MouseEvent)||n.button!==0)return!1;n.preventDefault();let r=e.state.doc.lineAt(t.from).number;if(Lr&&!n.shiftKey&&Math.min(Lr.start,Lr.end)===r&&Math.max(Lr.start,Lr.end)===r)return Rr(null),oi(),zr.current=!1,Br.current=null,Hr(!1),!0;if(f&&Lr&&!n.shiftKey){let e=Math.min(Lr.start,Lr.end,r),t=Math.max(Lr.start,Lr.end,r);return Rr({start:e,end:t}),zr.current=!1,Br.current=null,Hr(!1),!0}if(zr.current=!0,Br.current=r,Hr(!0),Lr&&n.shiftKey){let e=Math.min(Lr.start,r),t=Math.max(Lr.end,r);Rr({start:e,end:t})}else Rr({start:r,end:r});return!0},mouseover:(e,t,n)=>{if(!(n instanceof MouseEvent)||n.buttons!==1||!zr.current||Br.current===null)return!1;let r=e.state.doc.lineAt(t.from).number,i=Math.min(Br.current,r),a=Math.max(Br.current,r);return Rr({start:i,end:a}),Hr(!0),!1},mouseup:()=>(zr.current=!1,Br.current=null,Hr(!1),!1)}}})}),Xi&&(0,$.jsx)(`div`,{className:`pointer-events-none absolute inset-0 flex items-center justify-center bg-background`,children:(0,$.jsxs)(`div`,{className:`flex items-center gap-2 typography-ui text-muted-foreground`,children:[(0,$.jsx)(Y,{name:`loader-4`,className:`size-4 animate-spin`}),n(`filesView.state.openingFileAtChange`)]})})]}):(0,$.jsx)(`div`,{className:`p-3 typography-ui text-muted-foreground`,children:n(`filesView.editor.pickFileFromTree`)})})]})]}),Oo=!!(w&&xt[w]),ko=w?wt[w]:null,Ao=(0,$.jsxs)(`section`,{className:J(`flex min-h-0 flex-col overflow-hidden`,f?`h-full w-full bg-background`:`h-full rounded-xl border border-border/60 bg-background/70`),children:[(0,$.jsx)(`div`,{className:J(`flex flex-col gap-2 py-2`,f?`px-3`:`px-2`),children:(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsxs)(`div`,{className:`relative flex-1 min-w-0`,children:[(0,$.jsx)(Y,{name:`search`,className:`pointer-events-none absolute left-2 top-2 size-4 text-muted-foreground`}),(0,$.jsx)(ke,{ref:F,value:j,onChange:e=>N(e.target.value),placeholder:n(`filesView.tree.search.placeholder`),className:`h-8 pl-8 pr-8 typography-meta`}),j.trim().length>0&&(0,$.jsx)(`button`,{type:`button`,"aria-label":n(`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:()=>{N(``),F.current?.focus()},children:(0,$.jsx)(Y,{name:`close`,className:`size-4`})})]}),(0,$.jsxs)(Me,{children:[(0,$.jsx)(Ae,{asChild:!0,children:(0,$.jsx)(`span`,{className:`inline-flex flex-shrink-0`,children:(0,$.jsx)(X,{variant:`ghost`,size:`sm`,onClick:()=>Ir(`createFile`,{path:C,type:`directory`}),className:`size-8 p-0 flex-shrink-0`,title:n(`filesView.tree.actions.newFileTitle`),"aria-label":n(`filesView.tree.actions.newFileTitle`),children:(0,$.jsx)(Y,{name:`file-add`,className:`size-4`})})})}),(0,$.jsx)(je,{side:`bottom`,sideOffset:6,children:n(`filesView.tree.actions.newFileTitle`)})]}),(0,$.jsxs)(Me,{children:[(0,$.jsx)(Ae,{asChild:!0,children:(0,$.jsx)(`span`,{className:`inline-flex flex-shrink-0`,children:(0,$.jsx)(X,{variant:`ghost`,size:`sm`,onClick:()=>Ir(`createFolder`,{path:C,type:`directory`}),className:`size-8 p-0 flex-shrink-0`,title:n(`filesView.tree.actions.newFolderTitle`),"aria-label":n(`filesView.tree.actions.newFolderTitle`),children:(0,$.jsx)(Y,{name:`folder-add`,className:`size-4`})})})}),(0,$.jsx)(je,{side:`bottom`,sideOffset:6,children:n(`filesView.tree.actions.newFolderTitle`)})]}),(0,$.jsxs)(Me,{children:[(0,$.jsx)(Ae,{asChild:!0,children:(0,$.jsx)(`span`,{className:`inline-flex flex-shrink-0`,children:(0,$.jsx)(X,{variant:`ghost`,size:`sm`,onClick:()=>void pi(),className:`size-8 p-0 flex-shrink-0`,title:n(`filesView.tree.actions.refreshTitle`),"aria-label":n(`filesView.tree.actions.refreshTitle`),children:(0,$.jsx)(Y,{name:`refresh`,className:`size-4`})})})}),(0,$.jsx)(je,{side:`bottom`,sideOffset:6,children:n(`filesView.tree.actions.refreshTitle`)})]}),(0,$.jsxs)(Me,{children:[(0,$.jsx)(Ae,{asChild:!0,children:(0,$.jsx)(X,{variant:`ghost`,size:`sm`,onClick:Ri,disabled:Fi.length===0&&Qe.length===0,className:`size-8 flex-shrink-0 p-0`,title:n(Li?`sidebarFilesTree.actions.collapseAllTitle`:`sidebarFilesTree.actions.expandAllTitle`),"aria-label":n(Li?`sidebarFilesTree.actions.collapseAllTitle`:`sidebarFilesTree.actions.expandAllTitle`),children:(0,$.jsx)(Y,{name:Li?`contract-up-down`:`expand-up-down`,className:`size-4`})})}),(0,$.jsx)(je,{side:`bottom`,sideOffset:6,children:n(Li?`sidebarFilesTree.actions.collapseAllTitle`:`sidebarFilesTree.actions.expandAllTitle`)})]})]})}),(0,$.jsx)(Ee,{outerClassName:`flex-1 min-h-0`,className:J(`py-2`,f?`px-3`:`px-2`),children:(0,$.jsx)(`ul`,{className:`flex flex-col`,children:Jt?(0,$.jsxs)(`li`,{className:`flex items-center gap-1.5 px-2 py-1 typography-meta text-muted-foreground`,children:[(0,$.jsx)(Y,{name:`loader-4`,className:`size-4 animate-spin`}),n(`filesView.tree.search.searching`)]}):Gt.length>0?Gt.map(e=>{let t=Z?.path===e.path;return(0,$.jsx)(`li`,{children:(0,$.jsxs)(`button`,{type:`button`,onClick:()=>void Di(e),className:J(`flex w-full items-center gap-1.5 rounded-md px-2 py-1 text-left text-foreground transition-colors`,t?`bg-interactive-selection/70`:`hover:bg-interactive-hover/40`),children:[Oa(e.path,e.extension),(0,$.jsx)(`span`,{className:`min-w-0 flex-1 truncate typography-meta`,style:{direction:`rtl`,textAlign:`left`},title:e.path,children:e.relativePath??e.path})]})},e.path)}):ko?(0,$.jsxs)(`li`,{className:`flex flex-col gap-2 px-2 py-1 typography-meta text-muted-foreground`,children:[(0,$.jsx)(`span`,{className:`text-[var(--status-error)]`,children:ko}),(0,$.jsxs)(X,{variant:`outline`,size:`xs`,className:`w-fit gap-1.5`,onClick:()=>void pi(),children:[(0,$.jsx)(Y,{name:`refresh`,className:`size-3.5`}),n(`filesView.tree.actions.refreshTitle`)]})]}):Oo?Gi(w,0):(0,$.jsx)(`li`,{className:`px-2 py-1 typography-meta text-muted-foreground`,children:n(`filesView.state.loading`)})})})]}),jo=e===`full`&&R&&Z&&(0,$.jsx)(`div`,{className:`absolute inset-0 z-50 flex flex-col bg-background`,children:(0,$.jsxs)(`div`,{className:`flex-1 min-h-0 min-w-0 relative`,children:[(0,$.jsx)(`div`,{className:`absolute right-4 top-4 z-30`,children:Eo({exitFullscreenOnly:!0})}),(0,$.jsx)(Ee,{outerClassName:`h-full min-w-0`,className:`h-full min-w-0`,children:tn||mo||go?O?(0,$.jsx)(`div`,{className:`p-4`}):(0,$.jsxs)(`div`,{className:`p-4 flex items-center gap-2 typography-ui text-muted-foreground`,children:[(0,$.jsx)(Y,{name:`loader-4`,className:`size-4 animate-spin`}),`Loading…`]}):rn?(0,$.jsx)(`div`,{className:`p-4 typography-ui text-[color:var(--status-error)]`,children:rn}):Ki?bo(Z,{fullHeight:!0}):Ji?So(Z):ha&&Ka()===`preview`?(0,$.jsxs)(`div`,{className:`h-full overflow-auto p-4`,children:[Xt.length>512e3&&(0,$.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:n(`filesView.warning.largeFilePreviewLimited`,{sizeKb:Math.round(Xt.length/1024)})}),(0,$.jsx)(Be,{fallback:(0,$.jsxs)(`div`,{className:`rounded-md border border-destructive/20 bg-destructive/10 px-3 py-2`,children:[(0,$.jsx)(`div`,{className:`mb-1 font-medium text-destructive`,children:n(`filesView.error.previewUnavailable`)}),(0,$.jsx)(`div`,{className:`text-sm text-muted-foreground`,children:n(`filesView.error.switchToEditMode`)})]}),children:(0,$.jsx)(Mt,{content:Xt,className:`typography-markdown-body`,stripFrontmatter:!0,enableFileReferences:!1})})]}):La&&le===`view`?To(Z,hn):(0,$.jsxs)(`div`,{className:J(`relative h-full`,Xi&&`overflow-hidden`),children:[(0,$.jsx)(`div`,{className:J(`h-full`,Xi&&`invisible`),children:(0,$.jsx)(cn,{value:hn,onChange:gn,readOnly:!ra,vimMode:Yr===`vim`,extensions:to,className:`h-full`,onViewReady:e=>{qn.current=e,Qi(e),window.requestAnimationFrame(()=>{$a(e)})},onViewDestroy:()=>{qn.current&&=null,br(!1),Sr(null)}})}),Xi&&(0,$.jsx)(`div`,{className:`pointer-events-none absolute inset-0 flex items-center justify-center bg-background`,children:(0,$.jsxs)(`div`,{className:`flex items-center gap-2 typography-ui text-muted-foreground`,children:[(0,$.jsx)(Y,{name:`loader-4`,className:`size-4 animate-spin`}),n(`filesView.state.openingFileAtChange`)]})})]})})]})});return(0,$.jsxs)(`div`,{className:`flex h-full min-h-0 overflow-hidden bg-background relative`,children:[(0,$.jsx)(Ma,{activeDialog:er,dialogData:nr,dialogInputValue:ir,onDialogInputChange:or,isDialogSubmitting:sr,onDialogSubmit:_i,onClose:Co,inputRef:Sn}),jo,xr?(0,$.jsx)(ar,{position:xr,onDismiss:()=>Sr(null),onAddToChat:$i}):null,se.open?(0,$.jsx)(Q.Suspense,{fallback:null,children:(0,$.jsx)(aa,{popup:se,onOpenChange:yo,isMobile:f})}):null,f?I?Do:Ao:e===`editor-only`?(0,$.jsx)(`div`,{className:`flex flex-1 min-h-0 min-w-0 overflow-hidden`,children:(0,$.jsx)(`div`,{className:`flex-1 min-h-0 min-w-0 overflow-hidden bg-background`,children:Do})}):(0,$.jsxs)(`div`,{className:`flex flex-1 min-h-0 min-w-0 gap-3 px-3 pb-3 pt-2`,children:[m>=700&&(0,$.jsx)(`div`,{className:`w-72 flex-shrink-0 min-h-0 overflow-hidden`,children:Ao}),(0,$.jsx)(`div`,{className:`flex-1 min-h-0 min-w-0 overflow-hidden rounded-xl border border-border/60 bg-background`,children:Do})]})]})};function Ia(e){return e+1}var La=e=>e,Ra=e=>{let t=La(e).type;return typeof t==`string`?t:``},za=e=>{let t=La(e).tool;return typeof t==`string`?t:``},Ba=e=>{let t=La(e).text;return typeof t==`string`?t:``},Va=e=>{let t=Ra(e);return t===`tool`?za(e).trim().toLowerCase()||`tool`:t||`unknown`},Ha=e=>{if(e.length===0)return``;let t=[];for(let n of e){let e=Va(n);t.includes(e)||t.push(e)}return t.join(` + `)},Ua=e=>e.replace(/\s+/g,` `).trim(),Wa=e=>{for(let t of e)if(Ra(t)===`text`){let e=Ua(Ba(t));if(e.length===0)continue;return e}let t=e.filter(e=>Ra(e)!==`text`).length;return t===0?``:`${t} attachment${t===1?``:`s`}`},Ga=(e,t,n)=>`${n(e)} / ${n(t)}`,Ka=(e,t,n,r)=>{let i=Ga(e,t,n);return typeof r==`string`&&r.trim().length>0?`${i} · ${r.trim()}`:i},qa=e=>{if(e===`12h`)return!0;if(e===`24h`)return!1},Ja=(e,t)=>{if(!e||!Number.isFinite(e))return`-`;let n=qa(t);return new Date(e).toLocaleString(void 0,{month:`numeric`,day:`numeric`,hour:n===!1?`2-digit`:`numeric`,minute:`2-digit`,...n===void 0?{}:{hour12:n}})},Ya={input:0,output:0,reasoning:0,cacheRead:0,cacheWrite:0,total:0},Xa={user:0,assistant:0,tool:0,other:0},Za=e=>typeof e!=`number`||!Number.isFinite(e)||e<0?0:e,Qa=e=>{let t=e.info.tokens,n=t===void 0?e.parts.find(e=>e.tokens!==void 0)?.tokens:t;if(typeof n==`number`)return{...Ya,total:Za(n)};if(!n||typeof n!=`object`)return Ya;let r=n,i=Za(r.input),a=Za(r.output),o=Za(r.reasoning),s=Za(r.cache?.read),c=Za(r.cache?.write);return{input:i,output:a,reasoning:o,cacheRead:s,cacheWrite:c,total:i+a+o+s+c}},$a=(...e)=>{for(let t of e)if(typeof t==`string`&&t.trim().length>0)return t;return``},eo=e=>typeof e==`string`?e.length:typeof e==`number`||typeof e==`boolean`?String(e).length:Array.isArray(e)?e.reduce((e,t)=>e+eo(t),0):e&&typeof e==`object`?Object.values(e).reduce((e,t)=>e+eo(t),0):0,to=(e,t)=>{let n=e,r=typeof n.type==`string`?n.type:``;if(r===`reasoning`)return{...Xa,assistant:eo(n.text)+eo(n.content)};let i=$a(n.text,n.content,n.value,n.source?.value,n.source?.text?.value);return r===`tool`||t===`tool`?{user:0,assistant:0,tool:eo(n.input)+eo(n.output)+eo(n.error)+eo(n.call?.input)+eo(n.call?.output)+eo(n.call?.error)+eo(n.raw)+Math.round(eo(n.metadata)*.25)+Math.round(eo(n.state)*.1),other:0}:t===`user`?{user:i.length,assistant:0,tool:0,other:0}:t===`assistant`?{user:0,assistant:i.length,tool:0,other:0}:{user:0,assistant:0,tool:0,other:i.length}},no=(e,t)=>({user:e.user+t.user,assistant:e.assistant+t.assistant,tool:e.tool+t.tool,other:e.other+t.other}),ro=e=>{let t=ft(e.info);return t.isUser?`user`:t.role===`assistant`?`assistant`:t.role===`tool`?`tool`:`other`},io=(e,t)=>{if(e.length===0)return{...Xa};let n=e.reduce((e,t)=>{let n=ro(t),r={...Xa};for(let e of t.parts)r=no(r,to(e,n));return no(e,r)},{...Xa});return n.user+=t.length,{user:Math.ceil(n.user/4),assistant:Math.ceil(n.assistant/4),tool:Math.ceil(n.tool/4),other:Math.ceil(n.other/4)}},ao=e=>e.toLocaleString(I()),oo=e=>!Number.isFinite(e)||e<=0?new Intl.NumberFormat(I(),{style:`currency`,currency:`USD`,minimumFractionDigits:2,maximumFractionDigits:2}).format(0):new Intl.NumberFormat(I(),{style:`currency`,currency:`USD`,minimumFractionDigits:e<.01?4:2,maximumFractionDigits:e<.01?4:2}).format(e),so=(e,t)=>!e||!Number.isFinite(e)?`-`:Ue(e,t,{month:`short`,day:`numeric`,year:`numeric`,hour:`numeric`,minute:`2-digit`}),co=(e,t,n)=>{let r=e.find(e=>e.id===t),i=r?.models?.find(e=>e.id===n);return{providerName:r?.name||t||`-`,modelName:i?.name||n||`-`,contextLimit:typeof i?.limit?.context==`number`?i.limit.context:null}},lo=()=>{let e=(0,Sn.c)(259),{t}=ee(),n=c(uo),r=c(fo),i;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(i={},e[0]=i):i=e[0];let[a,o]=Q.useState(i),[s,l]=Q.useState(null),u=Q.useRef(null),d=ue(po),f=W(),p=se(d??``),m=fe(mo),h;e[1]===Symbol.for(`react.memo_cache_sentinel`)?(h=()=>{u.current!==null&&(window.clearTimeout(u.current),u.current=null),o(ho),l(null)},e[1]=h):h=e[1];let g;e[2]===d?g=e[3]:(g=[d],e[2]=d,e[3]=g),Q.useEffect(h,g);let _,v;e[4]===Symbol.for(`react.memo_cache_sentinel`)?(_=()=>()=>{u.current!==null&&(window.clearTimeout(u.current),u.current=null)},v=[],e[4]=_,e[5]=v):(_=e[4],v=e[5]),Q.useEffect(_,v);let y;e[6]===Symbol.for(`react.memo_cache_sentinel`)?(y=async(e,t)=>{(await te(t)).ok?(l(e),u.current!==null&&window.clearTimeout(u.current),u.current=window.setTimeout(()=>{l(t=>t===e?null:t),u.current=null},2e3)):l(null)},e[6]=y):y=e[6];let b=y,x;e[7]!==d||e[8]!==f?(x=d?f.find(e=>e.id===d)??null:null,e[7]=d,e[8]=f,e[9]=x):x=e[9];let S=x,C,w,T,E,D,O,k,A;if(e[10]!==m||e[11]!==p){C=p.filter(go);let t;e[20]===p?t=e[21]:(t=p.filter(_o),e[20]=p,e[21]=t),A=t;let n=null;for(let e=C.length-1;e>=0;--e){let t=C[e];if(Qa(t).total>0){n=t;break}}O=n?Qa(n):Ya,w=nt({input:O.input,cache:{read:O.cacheRead,write:O.cacheWrite}}),k=C.reduce(vo,0);let r=0,i=0;for(let e of C){let t=Qa(e),n=e.info.time?.created??null,a=e.info.time?.completed??null,o=xt(n,a,e.parts);if(o===null)continue;let s=t.output+t.reasoning;s<=0||(r+=s,i+=o)}let a=i>0&&r>0?r/(i/1e3):null,o;e[22]===a?o=e[23]:(o=a===null?null:_t(a),e[22]=a,e[23]=o),E=o;let s=n?mt({createdAt:n.info.time?.created??null,completedAt:n.info.time?.completed??null,outputTokens:O.output,reasoningTokens:O.reasoning,parts:n.parts}):null;T=s===null?null:_t(s);let c=n?.info??null;D=co(m,c?.providerID||``,c?.modelID||``),e[10]=m,e[11]=p,e[12]=C,e[13]=w,e[14]=T,e[15]=E,e[16]=D,e[17]=O,e[18]=k,e[19]=A}else C=e[12],w=e[13],T=e[14],E=e[15],D=e[16],O=e[17],k=e[18],A=e[19];let j=D,M=j.contextLimit,N=M&&M>0?Math.min(999,O.total/M*100):0,P;e[24]===p?P=e[25]:(P=io(p,[...p].reverse().find(yo)?.info?.system||``),e[24]=p,e[25]=P);let F=P,I=F.user,ne=F.assistant,L=F.tool,re=Math.max(0,O.input-I-ne-L),ie=I+ne+L+re,R=p[0]?.info?.time?.created,ae=p.length>0?p[p.length-1]?.info?.time?.created:null,z;e[26]!==S?.title||e[27]!==t?(z=S?.title||t(`contextSidebar.session.untitled`),e[26]=S?.title,e[27]=t,e[28]=z):z=e[28];let B=S?.time?.created??R??null,V=ae??S?.time?.created??null,oe=E&&E.length>0?E:null,H=T&&T.length>0?T:null,U;e[29]!==ne||e[30]!==re||e[31]!==L||e[32]!==I?(U={user:I,assistant:ne,tool:L,other:re},e[29]=ne,e[30]=re,e[31]=L,e[32]=I,e[33]=U):U=e[33];let G;e[34]!==C.length||e[35]!==ie||e[36]!==w||e[37]!==M||e[38]!==j||e[39]!==p.length||e[40]!==B||e[41]!==V||e[42]!==oe||e[43]!==H||e[44]!==U||e[45]!==z||e[46]!==O||e[47]!==k||e[48]!==N||e[49]!==A.length?(G={sessionTitle:z,messagesCount:p.length,userMessagesCount:A.length,assistantMessagesCount:C.length,createdAt:B,lastActivityAt:V,providerModel:j,tokenBreakdown:O,usagePercent:N,cacheHitRate:w,totalAssistantCost:k,sessionTpsLabel:oe,lastAssistantTpsLabel:H,contextLimit:M,breakdown:U,breakdownTotal:ie},e[34]=C.length,e[35]=ie,e[36]=w,e[37]=M,e[38]=j,e[39]=p.length,e[40]=B,e[41]=V,e[42]=oe,e[43]=H,e[44]=U,e[45]=z,e[46]=O,e[47]=k,e[48]=N,e[49]=A.length,e[50]=G):G=e[50];let K=G;if(!d){let n;e[51]===t?n=e[52]:(n=t(`contextSidebar.empty.openSession`),e[51]=t,e[52]=n);let r;return e[53]===n?r=e[54]:(r=(0,$.jsx)(`div`,{className:`flex h-full items-center justify-center p-6 text-center typography-ui-label text-muted-foreground`,children:n}),e[53]=n,e[54]=r),r}let ce;e[55]===t?ce=e[56]:(ce=t(`contextSidebar.breakdown.user`),e[55]=t,e[56]=ce);let le;e[57]!==ce||e[58]!==K.breakdown.user?(le={key:`user`,label:ce,value:K.breakdown.user,color:`var(--status-success)`},e[57]=ce,e[58]=K.breakdown.user,e[59]=le):le=e[59];let q;e[60]===t?q=e[61]:(q=t(`contextSidebar.breakdown.assistant`),e[60]=t,e[61]=q);let de;e[62]!==q||e[63]!==K.breakdown.assistant?(de={key:`assistant`,label:q,value:K.breakdown.assistant,color:`var(--primary-base)`},e[62]=q,e[63]=K.breakdown.assistant,e[64]=de):de=e[64];let pe;e[65]===t?pe=e[66]:(pe=t(`contextSidebar.breakdown.toolCalls`),e[65]=t,e[66]=pe);let me;e[67]!==pe||e[68]!==K.breakdown.tool?(me={key:`tool`,label:pe,value:K.breakdown.tool,color:`var(--status-warning)`},e[67]=pe,e[68]=K.breakdown.tool,e[69]=me):me=e[69];let he;e[70]===t?he=e[71]:(he=t(`contextSidebar.breakdown.other`),e[70]=t,e[71]=he);let ge;e[72]!==he||e[73]!==K.breakdown.other?(ge={key:`other`,label:he,value:K.breakdown.other,color:`var(--surface-muted-foreground)`},e[72]=he,e[73]=K.breakdown.other,e[74]=ge):ge=e[74];let _e;e[75]!==le||e[76]!==de||e[77]!==me||e[78]!==ge?(_e=[le,de,me,ge],e[75]=le,e[76]=de,e[77]=me,e[78]=ge,e[79]=_e):_e=e[79];let ve=_e,ye;e[80]===K.sessionTitle?ye=e[81]:(ye=(0,$.jsx)(`h2`,{className:`typography-ui-header font-semibold text-foreground truncate`,children:K.sessionTitle}),e[80]=K.sessionTitle,e[81]=ye);let be;e[82]!==K.providerModel.modelName||e[83]!==K.providerModel.providerName?(be=(0,$.jsxs)(`span`,{children:[K.providerModel.providerName,` / `,K.providerModel.modelName]}),e[82]=K.providerModel.modelName,e[83]=K.providerModel.providerName,e[84]=be):be=e[84];let xe;e[85]!==n||e[86]!==K.createdAt?(xe=K.createdAt&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`span`,{children:`·`}),(0,$.jsx)(`span`,{children:so(K.createdAt,n)})]}),e[85]=n,e[86]=K.createdAt,e[87]=xe):xe=e[87];let Se;e[88]!==be||e[89]!==xe?(Se=(0,$.jsxs)(`div`,{className:`mt-1 flex flex-wrap items-center gap-x-2 gap-y-0.5 typography-micro text-muted-foreground/70`,children:[be,xe]}),e[88]=be,e[89]=xe,e[90]=Se):Se=e[90];let Ce;e[91]!==ye||e[92]!==Se?(Ce=(0,$.jsxs)(`div`,{className:`mb-6`,children:[ye,Se]}),e[91]=ye,e[92]=Se,e[93]=Ce):Ce=e[93];let we;e[94]===t?we=e[95]:(we=t(`contextSidebar.section.context`),e[94]=t,e[95]=we);let Te;e[96]===we?Te=e[97]:(Te=(0,$.jsx)(`span`,{className:`typography-micro text-muted-foreground`,children:we}),e[96]=we,e[97]=Te);let X;e[98]===K.tokenBreakdown.total?X=e[99]:(X=ao(K.tokenBreakdown.total),e[98]=K.tokenBreakdown.total,e[99]=X);let Ee;e[100]===K.contextLimit?Ee=e[101]:(Ee=K.contextLimit?` / ${ao(K.contextLimit)}`:``,e[100]=K.contextLimit,e[101]=Ee);let De;e[102]!==X||e[103]!==Ee?(De=(0,$.jsxs)(`span`,{className:`typography-micro tabular-nums text-muted-foreground/70`,children:[X,Ee]}),e[102]=X,e[103]=Ee,e[104]=De):De=e[104];let Oe;e[105]!==Te||e[106]!==De?(Oe=(0,$.jsxs)(`div`,{className:`flex items-baseline justify-between`,children:[Te,De]}),e[105]=Te,e[106]=De,e[107]=Oe):Oe=e[107];let ke;e[108]===K.usagePercent?ke=e[109]:(ke=K.usagePercent>0&&(0,$.jsx)(`div`,{className:`rounded-full transition-all duration-300`,style:{width:`${Math.max(.5,K.usagePercent)}%`,backgroundColor:K.usagePercent>80?`var(--status-warning)`:`var(--primary-base)`}}),e[108]=K.usagePercent,e[109]=ke);let Ae;e[110]===ke?Ae=e[111]:(Ae=(0,$.jsx)(`div`,{className:`mt-2.5 flex h-1 w-full overflow-hidden rounded-full bg-[var(--surface-subtle)]`,children:ke}),e[110]=ke,e[111]=Ae);let je;e[112]!==t||e[113]!==K.usagePercent?(je=t(`contextSidebar.context.percentUsed`,{percent:K.usagePercent.toFixed(1)}),e[112]=t,e[113]=K.usagePercent,e[114]=je):je=e[114];let Me;e[115]===je?Me=e[116]:(Me=(0,$.jsx)(`div`,{className:`mt-1.5 typography-micro font-medium tabular-nums text-foreground/80`,children:je}),e[115]=je,e[116]=Me);let Ne;e[117]!==Oe||e[118]!==Ae||e[119]!==Me?(Ne=(0,$.jsxs)(`div`,{className:`mb-5 rounded-lg bg-[var(--surface-elevated)]/70 px-4 py-3.5`,children:[Oe,Ae,Me]}),e[117]=Oe,e[118]=Ae,e[119]=Me,e[120]=Ne):Ne=e[120];let Pe;e[121]===t?Pe=e[122]:(Pe=t(`contextSidebar.stats.messages`),e[121]=t,e[122]=Pe);let Fe;e[123]===K.messagesCount?Fe=e[124]:(Fe=ao(K.messagesCount),e[123]=K.messagesCount,e[124]=Fe);let Ie;e[125]!==Pe||e[126]!==Fe?(Ie={label:Pe,value:Fe},e[125]=Pe,e[126]=Fe,e[127]=Ie):Ie=e[127];let Le;e[128]===t?Le=e[129]:(Le=t(`contextSidebar.stats.user`),e[128]=t,e[129]=Le);let Re;e[130]===K.userMessagesCount?Re=e[131]:(Re=ao(K.userMessagesCount),e[130]=K.userMessagesCount,e[131]=Re);let ze;e[132]!==Le||e[133]!==Re?(ze={label:Le,value:Re},e[132]=Le,e[133]=Re,e[134]=ze):ze=e[134];let Be;e[135]===t?Be=e[136]:(Be=t(`contextSidebar.stats.assistant`),e[135]=t,e[136]=Be);let Ve;e[137]===K.assistantMessagesCount?Ve=e[138]:(Ve=ao(K.assistantMessagesCount),e[137]=K.assistantMessagesCount,e[138]=Ve);let He;e[139]!==Be||e[140]!==Ve?(He={label:Be,value:Ve},e[139]=Be,e[140]=Ve,e[141]=He):He=e[141];let Ue;e[142]!==Ie||e[143]!==ze||e[144]!==He?(Ue=[Ie,ze,He],e[142]=Ie,e[143]=ze,e[144]=He,e[145]=Ue):Ue=e[145];let We=Ue,Ge;e[146]===We?Ge=e[147]:(Ge=(0,$.jsx)(`div`,{className:`grid grid-cols-3 gap-2`,children:We.map(bo)}),e[146]=We,e[147]=Ge);let Ke=r?`grid-cols-2`:`grid-cols-1`,qe;e[148]===Ke?qe=e[149]:(qe=J(`grid gap-2`,Ke),e[148]=Ke,e[149]=qe);let Je;e[150]===t?Je=e[151]:(Je=t(`contextSidebar.stats.cost`),e[150]=t,e[151]=Je);let Ye;e[152]===Je?Ye=e[153]:(Ye=(0,$.jsx)(`div`,{className:`typography-micro text-muted-foreground/70`,children:Je}),e[152]=Je,e[153]=Ye);let Xe;e[154]===K.totalAssistantCost?Xe=e[155]:(Xe=oo(K.totalAssistantCost),e[154]=K.totalAssistantCost,e[155]=Xe);let Ze;e[156]===Xe?Ze=e[157]:(Ze=(0,$.jsx)(`div`,{className:`mt-0.5 typography-ui-label tabular-nums text-foreground`,children:Xe}),e[156]=Xe,e[157]=Ze);let Qe;e[158]!==Ye||e[159]!==Ze?(Qe=(0,$.jsxs)(`div`,{className:`rounded-lg bg-[var(--surface-elevated)]/70 px-3 py-2.5`,children:[Ye,Ze]}),e[158]=Ye,e[159]=Ze,e[160]=Qe):Qe=e[160];let $e;e[161]!==r||e[162]!==t||e[163]!==K.sessionTpsLabel?($e=r?(0,$.jsxs)(`div`,{className:`rounded-lg bg-[var(--surface-elevated)]/70 px-3 py-2.5`,children:[(0,$.jsx)(`div`,{className:`typography-micro text-muted-foreground/70`,children:t(`contextSidebar.stats.sessionTps`)}),(0,$.jsx)(`div`,{className:`mt-0.5 typography-ui-label tabular-nums text-foreground`,children:K.sessionTpsLabel??`—`})]}):null,e[161]=r,e[162]=t,e[163]=K.sessionTpsLabel,e[164]=$e):$e=e[164];let et;e[165]!==qe||e[166]!==Qe||e[167]!==$e?(et=(0,$.jsxs)(`div`,{className:qe,children:[Qe,$e]}),e[165]=qe,e[166]=Qe,e[167]=$e,e[168]=et):et=e[168];let tt;e[169]!==Ge||e[170]!==et?(tt=(0,$.jsxs)(`div`,{className:`mb-5 space-y-2`,children:[Ge,et]}),e[169]=Ge,e[170]=et,e[171]=tt):tt=e[171];let rt;e[172]===t?rt=e[173]:(rt=t(`contextSidebar.section.lastAssistantMessage`),e[172]=t,e[173]=rt);let it;e[174]===rt?it=e[175]:(it=(0,$.jsx)(`div`,{className:`typography-micro text-muted-foreground mb-2.5`,children:rt}),e[174]=rt,e[175]=it);let at;e[176]===t?at=e[177]:(at=t(`contextSidebar.tokens.input`),e[176]=t,e[177]=at);let ot;e[178]!==at||e[179]!==K.tokenBreakdown.input?(ot={label:at,value:K.tokenBreakdown.input,format:`count`},e[178]=at,e[179]=K.tokenBreakdown.input,e[180]=ot):ot=e[180];let st;e[181]===t?st=e[182]:(st=t(`contextSidebar.tokens.output`),e[181]=t,e[182]=st);let ct;e[183]!==st||e[184]!==K.tokenBreakdown.output?(ct={label:st,value:K.tokenBreakdown.output,format:`count`},e[183]=st,e[184]=K.tokenBreakdown.output,e[185]=ct):ct=e[185];let lt;e[186]===t?lt=e[187]:(lt=t(`contextSidebar.tokens.reasoning`),e[186]=t,e[187]=lt);let ut;e[188]!==lt||e[189]!==K.tokenBreakdown.reasoning?(ut={label:lt,value:K.tokenBreakdown.reasoning,format:`count`},e[188]=lt,e[189]=K.tokenBreakdown.reasoning,e[190]=ut):ut=e[190];let Z;e[191]===t?Z=e[192]:(Z=t(`contextSidebar.tokens.cacheRead`),e[191]=t,e[192]=Z);let dt;e[193]!==Z||e[194]!==K.tokenBreakdown.cacheRead?(dt={label:Z,value:K.tokenBreakdown.cacheRead,format:`count`},e[193]=Z,e[194]=K.tokenBreakdown.cacheRead,e[195]=dt):dt=e[195];let pt;e[196]===t?pt=e[197]:(pt=t(`contextSidebar.tokens.cacheWrite`),e[196]=t,e[197]=pt);let ht;e[198]!==pt||e[199]!==K.tokenBreakdown.cacheWrite?(ht={label:pt,value:K.tokenBreakdown.cacheWrite,format:`count`},e[198]=pt,e[199]=K.tokenBreakdown.cacheWrite,e[200]=ht):ht=e[200];let gt;e[201]===t?gt=e[202]:(gt=t(`contextSidebar.tokens.cacheHit`),e[201]=t,e[202]=gt);let vt=K.cacheHitRate.hasInput?K.cacheHitRate.percent:null,yt;e[203]!==gt||e[204]!==vt?(yt={label:gt,value:vt,format:`percent`},e[203]=gt,e[204]=vt,e[205]=yt):yt=e[205];let bt;e[206]!==r||e[207]!==t||e[208]!==K.lastAssistantTpsLabel?(bt=r?[{label:t(`contextSidebar.tokens.tps`),value:K.lastAssistantTpsLabel,format:`text`}]:[],e[206]=r,e[207]=t,e[208]=K.lastAssistantTpsLabel,e[209]=bt):bt=e[209];let St;e[210]!==ot||e[211]!==ct||e[212]!==ut||e[213]!==dt||e[214]!==ht||e[215]!==yt||e[216]!==bt?(St=(0,$.jsx)(`div`,{className:`grid grid-cols-3 gap-x-4 gap-y-2.5`,children:[ot,ct,ut,dt,ht,yt,...bt].map(xo)}),e[210]=ot,e[211]=ct,e[212]=ut,e[213]=dt,e[214]=ht,e[215]=yt,e[216]=bt,e[217]=St):St=e[217];let Ct;e[218]!==it||e[219]!==St?(Ct=(0,$.jsxs)(`div`,{className:`mb-5 rounded-lg bg-[var(--surface-elevated)]/70 px-4 py-3.5`,children:[it,St]}),e[218]=it,e[219]=St,e[220]=Ct):Ct=e[220];let wt;e[221]!==ve||e[222]!==K.breakdownTotal?(wt=(0,$.jsx)(`div`,{className:`flex h-1 w-full overflow-hidden rounded-full bg-[var(--surface-subtle)]`,children:ve.map(e=>e.value<=0||K.breakdownTotal<=0?null:(0,$.jsx)(`div`,{style:{width:`${e.value/K.breakdownTotal*100}%`,backgroundColor:e.color}},e.key))}),e[221]=ve,e[222]=K.breakdownTotal,e[223]=wt):wt=e[223];let Tt;e[224]!==ve||e[225]!==K.breakdownTotal?(Tt=(0,$.jsx)(`div`,{className:`mt-2 flex flex-wrap items-center gap-x-4 gap-y-1`,children:ve.map(e=>{let t=K.breakdownTotal>0?e.value/K.breakdownTotal*100:0;return(0,$.jsxs)(`div`,{className:`inline-flex items-center gap-1.5`,children:[(0,$.jsx)(`span`,{className:`h-1.5 w-1.5 rounded-full`,style:{backgroundColor:e.color}}),(0,$.jsxs)(`span`,{className:`typography-micro text-muted-foreground/70`,children:[e.label,` `,(0,$.jsxs)(`span`,{className:`tabular-nums`,children:[t.toFixed(0),`%`]})]})]},e.key)})}),e[224]=ve,e[225]=K.breakdownTotal,e[226]=Tt):Tt=e[226];let Et;e[227]!==wt||e[228]!==Tt?(Et=(0,$.jsxs)(`div`,{className:`mb-6`,children:[wt,Tt]}),e[227]=wt,e[228]=Tt,e[229]=Et):Et=e[229];let Dt;e[230]===t?Dt=e[231]:(Dt=t(`contextSidebar.section.rawMessages`),e[230]=t,e[231]=Dt);let Ot;e[232]===Dt?Ot=e[233]:(Ot=(0,$.jsx)(`div`,{className:`typography-micro text-muted-foreground`,children:Dt}),e[232]=Dt,e[233]=Ot);let kt;if(e[234]!==s||e[235]!==a||e[236]!==p||e[237]!==r||e[238]!==t||e[239]!==n){let i;e[241]!==s||e[242]!==a||e[243]!==r||e[244]!==t||e[245]!==n?(i=e=>{let i=ft(e.info).role,c=i===`assistant`,l=i===`user`,u=a[e.info.id]===!0,d=s===e.info.id,f=e.info.time?.created??null,p=e.info.time?.completed??null,m=Ha(e.parts),h=c?Qa({info:e.info,parts:e.parts}):null,g=l?Wa(e.parts):``,_=Ja(f,n),v=m||`—`,y=(()=>{if(!r||!c||!h)return null;let t=mt({createdAt:f,completedAt:p,outputTokens:h.output,reasoningTokens:h.reasoning,parts:e.parts});if(t===null)return null;let n=_t(t);return n.length>0?n:null})(),x=h?Ka(h.input,h.output,ao,y):``,S=i||`unknown`,C=m?`${S}: ${m}`:S,w=u?JSON.stringify({info:e.info,parts:e.parts},null,2):``;return(0,$.jsxs)(`div`,{className:`overflow-hidden rounded-lg bg-[var(--surface-elevated)]/70`,children:[(0,$.jsx)(`button`,{type:`button`,className:`w-full cursor-pointer px-3 py-1.5 text-left hover:bg-[var(--interactive-hover)]`,"aria-expanded":u,onClick:()=>{o(t=>({...t,[e.info.id]:t[e.info.id]!==!0}))},children:(0,$.jsxs)(`div`,{className:`grid items-center gap-x-2 whitespace-nowrap typography-micro`,style:{gridTemplateColumns:c?`minmax(0, 1fr) minmax(7.5rem, max-content) max-content`:`minmax(0, 1fr) max-content`},children:[l?(0,$.jsxs)(`span`,{className:`min-w-0 truncate text-muted-foreground`,children:[(0,$.jsx)(`span`,{className:`typography-ui-label text-foreground`,children:`user:`}),` `,g]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`span`,{className:`min-w-0 truncate text-muted-foreground`,children:c?v:C}),c&&(0,$.jsx)(`span`,{className:`text-right text-muted-foreground tabular-nums`,children:x})]}),(0,$.jsx)(`span`,{className:`text-right text-muted-foreground`,children:_})]})}),u&&(0,$.jsx)(`div`,{className:`border-t border-[var(--surface-subtle)] p-0`,children:(0,$.jsxs)(`div`,{className:`group relative max-h-[26rem] w-full overflow-auto bg-[var(--surface-background)]`,children:[(0,$.jsx)(`div`,{className:`absolute top-1 right-2 z-10 opacity-0 transition-opacity group-hover:opacity-100`,children:(0,$.jsx)(`button`,{type:`button`,className:`rounded p-1 text-muted-foreground transition-colors hover:bg-interactive-hover/60 hover:text-foreground`,onClick:t=>{t.stopPropagation(),b(e.info.id,w)},"aria-label":t(d?`contextSidebar.actions.copied`:`contextSidebar.actions.copyJson`),title:t(d?`contextSidebar.actions.copied`:`contextSidebar.actions.copy`),children:d?(0,$.jsx)(Y,{name:`check`,className:`size-3.5`}):(0,$.jsx)(Y,{name:`file-copy`,className:`size-3.5`})})}),(0,$.jsx)(Wt,{language:`json`,code:w,style:{margin:0,padding:`0.75rem`,background:`transparent`,fontSize:`var(--text-micro)`,lineHeight:`1.35`},wrap:!0})]})})]},e.info.id)},e[241]=s,e[242]=a,e[243]=r,e[244]=t,e[245]=n,e[246]=i):i=e[246],kt=[...p].reverse().map(i),e[234]=s,e[235]=a,e[236]=p,e[237]=r,e[238]=t,e[239]=n,e[240]=kt}else kt=e[240];let At;e[247]===kt?At=e[248]:(At=(0,$.jsx)(`div`,{className:`mt-2.5 space-y-1`,children:kt}),e[247]=kt,e[248]=At);let jt;e[249]!==Ot||e[250]!==At?(jt=(0,$.jsxs)(`div`,{children:[Ot,At]}),e[249]=Ot,e[250]=At,e[251]=jt):jt=e[251];let Mt;return e[252]!==Ce||e[253]!==Ne||e[254]!==tt||e[255]!==Ct||e[256]!==Et||e[257]!==jt?(Mt=(0,$.jsx)(`div`,{className:`h-full overflow-y-auto bg-background`,children:(0,$.jsxs)(`div`,{className:`mx-auto w-full max-w-[52rem] px-5 py-6`,children:[Ce,Ne,tt,Ct,Et,jt]})}),e[252]=Ce,e[253]=Ne,e[254]=tt,e[255]=Ct,e[256]=Et,e[257]=jt,e[258]=Mt):Mt=e[258],Mt};function uo(e){return e.timeFormatPreference}function fo(e){return e.showAssistantTps}function po(e){return e.currentSessionId}function mo(e){return e.providers}function ho(e){return Object.keys(e).length>0?{}:e}function go(e){return ft(e.info).role===`assistant`}function _o(e){return ft(e.info).isUser}function vo(e,t){return e+Za(t.info.cost)}function yo(e){return ft(e.info).isUser&&typeof e.info.system==`string`}function bo(e){return(0,$.jsxs)(`div`,{className:`rounded-lg bg-[var(--surface-elevated)]/70 px-3 py-2.5`,children:[(0,$.jsx)(`div`,{className:`typography-micro text-muted-foreground/70`,children:e.label}),(0,$.jsx)(`div`,{className:`mt-0.5 typography-ui-label tabular-nums text-foreground`,children:e.value})]},e.label)}function xo(e){return(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`div`,{className:`typography-micro text-muted-foreground/70`,children:e.label}),(0,$.jsx)(`div`,{className:`mt-0.5 typography-ui-label tabular-nums text-foreground`,children:e.format===`text`?typeof e.value==`string`&&e.value.length>0?e.value:`—`:e.value!==null&&e.value!==void 0?e.format===`percent`?`${Number(e.value).toFixed(1)}%`:ao(Number(e.value)):`—`})]},e.label)}var So=e=>{let t=e.trim().replace(/\\/g,`/`);if(!t)return``;let n=t.startsWith(`//`),r=t.replace(/\/+$/g,``).replace(/\/+/g,`/`);return n&&!r.startsWith(`//`)?`/${r}`:r||(t.startsWith(`/`)?`/`:``)},Co=()=>`react-surface`,wo=(e,t)=>JSON.stringify([So(e),t]),To=(e,t,n,r)=>JSON.stringify([e,t,So(n),r]),Eo=(e,t,n)=>n?t:e===t?e:null,Do=(e,t)=>e.sessionId===t.sessionId&&So(e.directory)===So(t.directory),Oo=(e,t)=>So(e)===So(t),ko=e=>({anchor:e,current:e,stack:[]}),Ao=(e,t)=>e??ko(t),jo=(e,t)=>e?.current.sessionId??t,Mo=(e,t)=>Do(e.current,t)?e:{...e,current:t,stack:[...e.stack,e.current]},No=e=>{let t=e.stack[e.stack.length-1];return t?{...e,current:t,stack:e.stack.slice(0,-1)}:e},Po=(e,t,n)=>!Oo(e.anchor.directory,t.directory)||!Oo(e.current.directory,t.directory)||n(t.sessionId,t.directory)===!1?{status:`rejected-cross-directory`,state:e}:{status:`navigated`,state:Mo(e,t)},Fo=(e,t,n)=>{let r=e[t];if(!r)return{accepted:!1,navigationBySurfaceId:e};let i=Po(r,n,()=>!0);return i.status===`navigated`?{accepted:!0,navigationBySurfaceId:i.state===r?e:{...e,[t]:i.state}}:{accepted:!1,navigationBySurfaceId:e}},Io=(e,t)=>{let n=!1,r={};for(let[i,a]of Object.entries(e)){if(!t.has(i)){n=!0;continue}r[i]=a}return n?r:e},Lo=e=>e.directoryMatches?e.error?e.messageCount>0?`partial-error`:`fatal-error`:!e.renderable&&e.requested?`cold-loading`:e.messageCount===0?e.working?`working-empty`:`authoritative-empty`:`transcript`:`directory-mismatch`,Ro=e=>e===`retry`,zo=e=>e.active&&e.visible&&e.messageCount<=0,Bo=e=>e?`load-more`:`ensure`,Vo=e=>e.kind===`has-more`,Ho=(e,t)=>`${e}\n${t}`,Uo=(e,t,n,r)=>r&&!e.has(Ho(t,n)),Wo=(e,t)=>({scrollHeight:e,scrollTop:t}),Go=(e,t)=>Math.max(0,e.scrollTop+Math.max(0,t-e.scrollHeight)),Ko=(e,t)=>e&&!t,qo=e=>e,Jo=e=>!e,Yo=e=>!Ko(e.hasMore,e.isLoading)||!Jo(e.historyVirtualized)?null:Wo(e.scrollHeight,e.scrollTop),Xo=(e,t,n)=>!!(e&&e.token===t&&e.viewportKey===n),Zo=33554432,Qo=e=>Math.min(Zo,262144+Math.max(0,Math.ceil(e))*64*1024),$o=e=>Math.min(Zo,Math.max(0,Math.round(Number.isFinite(e)?e:0))),es=e=>{let t=Object.values(e.mountedViews),n=t.length,r=t.reduce((e,t)=>e+t.estimatedBytes,0),i=new Set,a=t.filter(t=>t.viewKey!==e.activeViewKey).sort((e,t)=>e.lastAccessed-t.lastAccessed);for(let e of a){if(n<=3&&r<=33554432)break;i.add(e.viewKey),--n,r-=e.estimatedBytes}if(i.size===0)return e;let o={...e.mountedViews};return i.forEach(e=>delete o[e]),{...e,mountedViews:o}},ts=(e,t)=>{if(t.type===`close-tab`){let n=Object.values(e.mountedViews).filter(e=>e.tabId===t.tabId);if(!e.tabs[t.tabId]&&n.length===0)return e;let r={...e.tabs},i={...e.mountedViews};return delete r[t.tabId],n.forEach(e=>delete i[e.viewKey]),{activeViewKey:n.some(t=>t.viewKey===e.activeViewKey)?null:e.activeViewKey,tabs:r,mountedViews:i}}if(t.type===`activate`){if(t.viewKey===e.activeViewKey)return e;let n=t.viewKey?e.mountedViews[t.viewKey]:void 0;if(t.viewKey&&!n)return e;if(!n)return{...e,activeViewKey:null};let r=n.lastAccessed===t.now?e.mountedViews:{...e.mountedViews,[n.viewKey]:{...n,lastAccessed:t.now}};return es({...e,activeViewKey:t.viewKey,mountedViews:r})}if(t.type===`estimate`){let n=e.mountedViews[t.viewKey],r=$o(t.estimatedBytes);return!n||n.estimatedBytes===r?e:es({...e,mountedViews:{...e.mountedViews,[n.viewKey]:{...n,estimatedBytes:r}}})}let n=e.tabs[t.tab.tabId],r=e.mountedViews[t.view.viewKey],i=n&&n.sessionId===t.tab.sessionId&&n.directory===t.tab.directory&&n.title===t.tab.title,a=r&&r.tabId===t.view.tabId&&r.surfaceId===t.view.surfaceId&&r.lastAccessed===t.now;return i&&a&&e.activeViewKey===t.view.viewKey?e:es({...e,activeViewKey:t.view.viewKey,tabs:i?e.tabs:{...e.tabs,[t.tab.tabId]:t.tab},mountedViews:{...e.mountedViews,[t.view.viewKey]:{...t.view,estimatedBytes:r?.estimatedBytes??Qo(0),lastAccessed:t.now}}})},ns={overflowAnchor:`none`,overscrollBehavior:`contain`,overscrollBehaviorY:`contain`},rs={scrollbar:`chat`,scrollShadow:`true`,orientation:`vertical`},is=e=>{let t=(0,Sn.c)(17),{state:n,error:r,onRetry:i}=e,{t:a}=ee();if(n===`cold-loading`||n===`working-empty`){let e;return t[0]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,$.jsx)(`div`,{className:`flex h-full items-center justify-center text-sm text-muted-foreground`,children:(0,$.jsx)(Y,{name:`loader-4`,className:`size-4 animate-spin`})}),t[0]=e):e=t[0],e}if(n===`fatal-error`||n===`directory-mismatch`){let e;t[1]!==r||t[2]!==a?(e=r||a(`chat.emptyState.opencodeUnreachable`),t[1]=r,t[2]=a,t[3]=e):e=t[3];let o;t[4]===e?o=t[5]:(o=(0,$.jsx)(`div`,{className:`text-center`,children:e}),t[4]=e,t[5]=o);let s;t[6]!==i||t[7]!==n||t[8]!==a?(s=n===`fatal-error`?(0,$.jsx)(X,{type:`button`,variant:`secondary`,size:`sm`,onClick:i,children:a(`chat.history.retry`)}):null,t[6]=i,t[7]=n,t[8]=a,t[9]=s):s=t[9];let c;return t[10]!==o||t[11]!==s?(c=(0,$.jsxs)(`div`,{className:`flex h-full flex-col items-center justify-center gap-3 px-6 text-sm text-muted-foreground`,children:[o,s]}),t[10]=o,t[11]=s,t[12]=c):c=t[12],c}let o;t[13]===a?o=t[14]:(o=a(`chat.timeline.empty.session`),t[13]=a,t[14]=o);let s;return t[15]===o?s=t[16]:(s=(0,$.jsx)(`div`,{className:`flex h-full items-center justify-center px-6 text-center text-sm text-muted-foreground`,children:o}),t[15]=o,t[16]=s),s},as=e=>{let t=(0,Sn.c)(193),{surfaceId:n,sessionId:r,directory:i,active:a,canNavigateBack:s,onNavigateSession:c,onNavigateBack:l,onEstimateBytes:u,syncDirectory:d}=e,{t:f}=ee(),p=ct(),m,h,g;t[0]!==i||t[1]!==r||t[2]!==n?(h=o(),m=So(i),g=To(h,n,m,r),t[0]=i,t[1]=r,t[2]=n,t[3]=m,t[4]=h,t[5]=g):(m=t[3],h=t[4],g=t[5]);let _=g,v=Q.useRef(null),y=Q.useRef(null),b=Q.useRef(0),[x,S]=Q.useState(null),C;t[6]===Symbol.for(`react.memo_cache_sentinel`)?(C=new Set,t[6]=C):C=t[6];let w=Q.useRef(C),T=he(r,d),E=se(r,d),D=fe(ss),O;t[7]===E?O=t[8]:(O=vt(E),t[7]=E,t[8]=O);let k=O,j;bb0:{if(!k.modelId){let e;t[9]===f?e=t[10]:(e=f(`common.unavailable`),t[9]=f,t[10]=e),j=e;break bb0}let e;if(t[11]!==k.modelId||t[12]!==k.providerId||t[13]!==D){let n;t[15]===k.providerId?n=t[16]:(n=e=>e.id===k.providerId,t[15]=k.providerId,t[16]=n);let r=D.find(n);e=r?.models.some(e=>e.id===k.modelId)&&B(r,k.modelId)||k.modelId,t[11]=k.modelId,t[12]=k.providerId,t[13]=D,t[14]=e}else e=t[14];j=e}let M=j,N=H(r,d),F=pe(r,d).renderable,I;t[17]===r?I=t[18]:(I=e=>!!e.session.find(e=>e.id===r)?.parentID,t[17]=r,t[18]=I);let te=V(I,d),[ne,L]=Q.useState(null),re,ie;t[19]!==te||t[20]!==_?(re=()=>{L(e=>Eo(e,_,te))},ie=[te,_],t[19]=te,t[20]=_,t[21]=re,t[22]=ie):(re=t[21],ie=t[22]),Q.useLayoutEffect(re,ie);let R=te||ne===_,z=le(r,d),oe;t[23]===r?oe=t[24]:(oe=e=>e.streamingMessageIds.get(r)??null,t[23]=r,t[24]=oe);let U=ae(oe),W;t[25]===U?W=t[26]:(W=e=>U?e.messageStreamStates.get(U)?.phase??null:null,t[25]=U,t[26]=W);let q=ae(W),ue=N?.type===`busy`||N?.type===`retry`,me=gt(cs),[ge,_e]=Q.useState(!1),[ve,ye]=Q.useState(!1),[be,xe]=Q.useState(0),Se=a&&!me,Ce;t[27]!==r||t[28]!==ue||t[29]!==T||t[30]!==Se||t[31]!==_?(Ce={enabled:Se,currentSessionId:r,viewportKey:_,sessionMessageCount:T,sessionIsWorking:ue,isMobile:!1},t[27]=r,t[28]=ue,t[29]=T,t[30]=Se,t[31]=_,t[32]=Ce):Ce=t[32];let{scrollRef:we,notifyContentChange:Te,getAnimationHandlers:J,goToBottom:Ee,restoreSnapshot:Oe,showScrollButton:ke}=Z(Ce),Ae;t[33]===Symbol.for(`react.memo_cache_sentinel`)?(Ae=()=>{_e(!1),ye(!1)},t[33]=Ae):Ae=t[33];let je;t[34]===r?je=t[35]:(je=[r],t[34]=r,t[35]=je),Q.useEffect(Ae,je);let Me;t[36]===Symbol.for(`react.memo_cache_sentinel`)?(Me=(e,t)=>{e&&ye(!1),t!==void 0&&_e(t)},t[36]=Me):Me=t[36];let Ne=P(Me),Pe;t[37]===Ee?Pe=t[38]:(Pe=e=>{let t=e===void 0?`instant`:e;ye(!1),v.current?.scrollToBottom(),Ee(t)},t[37]=Ee,t[38]=Pe);let Fe=P(Pe),Ie;t[39]===Symbol.for(`react.memo_cache_sentinel`)?(Ie=()=>{ye(!0)},t[39]=Ie):Ie=t[39];let Le=P(Ie),Re;t[40]!==Le||t[41]!==me||t[42]!==we?(Re={scrollRef:we,enabled:me,onUpwardIntent:Le},t[40]=Le,t[41]=me,t[42]=we,t[43]=Re):Re=t[43],bt(Re);let ze;t[44]!==r||t[45]!==p?(ze=e=>{p.ensureSessionRenderable(r,Ro(e))},t[44]=r,t[45]=p,t[46]=ze):ze=t[46];let Be=P(ze),Ve,He;t[47]!==a||t[48]!==Be?(Ve=()=>{a&&Be(`active`)},He=[a,Be],t[47]=a,t[48]=Be,t[49]=Ve,t[50]=He):(Ve=t[49],He=t[50]),Q.useEffect(Ve,He);let Ue,We;t[51]!==a||t[52]!==Be||t[53]!==T?(Ue=()=>{if(typeof window>`u`)return;let e=()=>{let e=document.visibilityState!==`hidden`&&document.hasFocus();zo({active:a,visible:e,messageCount:T})&&Be(`retry`)};return window.addEventListener(`focus`,e),document.addEventListener(`visibilitychange`,e),()=>{window.removeEventListener(`focus`,e),document.removeEventListener(`visibilitychange`,e)}},We=[a,Be,T],t[51]=a,t[52]=Be,t[53]=T,t[54]=Ue,t[55]=We):(Ue=t[54],We=t[55]),Q.useEffect(Ue,We);let Ge,Ke;t[56]!==u||t[57]!==T||t[58]!==_?(Ge=()=>{u?.(_,Qo(T))},Ke=[u,T,_],t[56]=u,t[57]=T,t[58]=_,t[59]=Ge,t[60]=Ke):(Ge=t[59],Ke=t[60]),Q.useEffect(Ge,Ke);let qe,Je;t[61]!==F||t[62]!==Oe||t[63]!==r||t[64]!==_?(qe=()=>{if(!Uo(w.current,r,_,F))return;let e=Ho(r,_);w.current.add(e),Oe()},Je=[F,Oe,r,_],t[61]=F,t[62]=Oe,t[63]=r,t[64]=_,t[65]=qe,t[66]=Je):(qe=t[65],Je=t[66]),Q.useEffect(qe,Je);let Ye;t[67]===Symbol.for(`react.memo_cache_sentinel`)?(Ye=()=>{y.current=null,S(null)},t[67]=Ye):Ye=t[67];let Ze;t[68]===_?Ze=t[69]:(Ze=[_],t[68]=_,t[69]=Ze),Q.useLayoutEffect(Ye,Ze);let Qe;t[70]!==x||t[71]!==we||t[72]!==_?(Qe=()=>{let e=y.current,t=we.current;if(Xo(e,x,_)){if(!t||!Jo(!!v.current?.isHistoryVirtualized())){y.current=null;return}t.scrollTop=Go(e.anchor,t.scrollHeight),y.current=null}},t[70]=x,t[71]=we,t[72]=_,t[73]=Qe):Qe=t[73];let $e;t[74]!==x||t[75]!==we||t[76]!==E||t[77]!==_?($e=[x,we,E,_],t[74]=x,t[75]=we,t[76]=E,t[77]=_,t[78]=$e):$e=t[78],Q.useLayoutEffect(Qe,$e);let et;t[79]===m?et=t[80]:(et={directory:m},t[79]=m,t[80]=et);let tt=et,nt=ce(r,d).boundary,rt;t[81]===nt?rt=t[82]:(rt=Vo(nt),t[81]=nt,t[82]=rt);let it=rt,ot;t[83]!==z?.status||t[84]!==tt||t[85]!==r||t[86]!==p?(ot=z?.status===`loading`||p.isLoading(r,tt),t[83]=z?.status,t[84]=tt,t[85]=r,t[86]=p,t[87]=ot):ot=t[87];let lt=ot,ft;t[88]!==m||t[89]!==h||t[90]!==r?(ft=[`context-panel-load-older`,h,m,r],t[88]=m,t[89]=h,t[90]=r,t[91]=ft):ft=t[91];let pt;t[92]!==nt||t[93]!==r||t[94]!==d?(pt=async()=>{nt.kind===`unknown`&&await de(d,r),await K(d,r)},t[92]=nt,t[93]=r,t[94]=d,t[95]=pt):pt=t[95];let mt;t[96]!==ft||t[97]!==pt?(mt={mutationKey:ft,mutationFn:pt},t[96]=ft,t[97]=pt,t[98]=mt):mt=t[98];let ht=A(mt),_t=ht.isPending,yt;t[99]!==lt||t[100]!==it||t[101]!==_t||t[102]!==me||t[103]!==ht||t[104]!==we||t[105]!==f||t[106]!==_?(yt=()=>{if(!Ko(it,_t||lt)||ht.isPending)return;me&&xe(ls);let e=b.current+1;b.current=e;let t=we.current,n=t?Yo({hasMore:it,isLoading:_t,historyVirtualized:!!v.current?.isHistoryVirtualized(),scrollHeight:t.scrollHeight,scrollTop:t.scrollTop}):null;y.current=n?{token:e,viewportKey:_,anchor:n}:null,ht.mutateAsync().then(()=>{S(e)},()=>{S(e),G.error(f(`chat.history.loadOlderFailed`))})},t[99]=lt,t[100]=it,t[101]=_t,t[102]=me,t[103]=ht,t[104]=we,t[105]=f,t[106]=_,t[107]=yt):yt=t[107];let xt=P(yt),St=z?.status===`error`?z.error:void 0,Tt;t[108]!==a||t[109]!==F||t[110]!==ue||t[111]!==E.length||t[112]!==St?(Tt=Lo({directoryMatches:!0,requested:a,renderable:F,messageCount:E.length,working:ue,error:St}),t[108]=a,t[109]=F,t[110]=ue,t[111]=E.length,t[112]=St,t[113]=Tt):Tt=t[113];let Et=Tt,Dt;t[114]!==a||t[115]!==m||t[116]!==c||t[117]!==r||t[118]!==n?(Dt={kind:`panel`,surfaceId:n,sessionId:r,directory:m,active:a,capabilities:st,navigateSession:c},t[114]=a,t[115]=m,t[116]=c,t[117]=r,t[118]=n,t[119]=Dt):Dt=t[119];let Ot=Dt,kt;t[120]!==Be||t[121]!==it||t[122]!==xt?(kt=()=>{if(Bo(it)===`load-more`){xt();return}Be(`retry`)},t[120]=Be,t[121]=it,t[122]=xt,t[123]=kt):kt=t[123];let At=P(kt),jt;t[124]!==z?.error||t[125]!==At||t[126]!==f||t[127]!==Et?(jt=Et===`partial-error`?(0,$.jsxs)(`div`,{className:`flex items-center justify-center gap-2 px-3 py-2 text-sm text-[var(--status-error-foreground)]`,children:[(0,$.jsx)(`span`,{className:`truncate`,children:z?.error}),(0,$.jsx)(X,{type:`button`,variant:`secondary`,size:`xs`,onClick:At,children:f(`chat.history.retry`)})]}):null,t[124]=z?.error,t[125]=At,t[126]=f,t[127]=Et,t[128]=jt):jt=t[128];let Mt=jt,Nt;t[129]!==it||t[130]!==_t||t[131]!==xt||t[132]!==f?(Nt=qo(it)?(0,$.jsx)(`div`,{className:`flex justify-center pt-3 pb-1`,children:(0,$.jsxs)(X,{type:`button`,variant:`secondary`,size:`sm`,onClick:xt,disabled:_t,children:[_t?(0,$.jsx)(Y,{name:`loader-4`,className:`size-4 animate-spin`}):null,f(`chat.history.loadOlder`)]})}):null,t[129]=it,t[130]=_t,t[131]=xt,t[132]=f,t[133]=Nt):Nt=t[133];let Pt=Nt,Ft;t[134]===Symbol.for(`react.memo_cache_sentinel`)?(Ft=(0,$.jsx)(`div`,{className:`flex-shrink-0`,style:{height:Ct},"aria-hidden":`true`}),t[134]=Ft):Ft=t[134];let It=Ft,Lt;t[135]===Fe?Lt=t[136]:(Lt=()=>Fe(`instant`),t[135]=Fe,t[136]=Lt);let Rt=!ve,zt;t[137]!==me||t[138]!==Pt||t[139]!==Mt?(zt=me?(0,$.jsxs)($.Fragment,{children:[Mt,Pt]}):void 0,t[137]=me,t[138]=Pt,t[139]=Mt,t[140]=zt):zt=t[140];let Bt=me?It:void 0,Vt;t[141]!==q||t[142]!==J||t[143]!==Ne||t[144]!==_t||t[145]!==Te||t[146]!==we||t[147]!==r||t[148]!==ue||t[149]!==E||t[150]!==U||t[151]!==d||t[152]!==Lt||t[153]!==Rt||t[154]!==zt||t[155]!==Bt||t[156]!==be||t[157]!==_?(Vt=(0,$.jsx)(dt,{ref:v,sessionKey:r,virtualizerKey:_,messages:E,sessionIsWorking:ue,activeStreamingMessageId:U,activeStreamingPhase:q,onMessageContentChange:Te,getAnimationHandlers:J,isLoadingOlder:_t,scrollToBottom:Lt,scrollRef:we,directory:d,enableSendPark:!1,timelineScrollClassName:`absolute inset-0 z-0 chat-scroll overlay-scrollbar-target`,timelineScrollStyle:ns,timelineScrollDataset:rs,timelineFollowEnabled:Rt,timelineHistoryAnchorToken:be,timelineOnIsAtEndChange:Ne,headerSlot:zt,footerSlot:Bt}),t[141]=q,t[142]=J,t[143]=Ne,t[144]=_t,t[145]=Te,t[146]=we,t[147]=r,t[148]=ue,t[149]=E,t[150]=U,t[151]=d,t[152]=Lt,t[153]=Rt,t[154]=zt,t[155]=Bt,t[156]=be,t[157]=_,t[158]=Vt):Vt=t[158];let Ht=Vt,Ut=me?ge:ke,Wt;t[159]===Fe?Wt=t[160]:(Wt=()=>Fe(`smooth`),t[159]=Fe,t[160]=Wt);let Gt;t[161]!==Ut||t[162]!==Wt?(Gt=(0,$.jsx)(at,{visible:Ut,onClick:Wt}),t[161]=Ut,t[162]=Wt,t[163]=Gt):Gt=t[163];let Kt=Gt,qt;t[164]!==s||t[165]!==l||t[166]!==f?(qt=s?(0,$.jsxs)(X,{type:`button`,variant:`outline`,size:`xs`,onClick:l,className:`absolute left-3 top-3 z-20 !font-normal bg-[var(--surface-background)]/95`,"aria-label":f(`chat.container.returnToParent.aria`),title:f(`chat.container.returnToParent.title`),children:[(0,$.jsx)(Y,{name:`arrow-left`,className:`h-4 w-4`}),f(`chat.container.returnToParent.label`)]}):null,t[164]=s,t[165]=l,t[166]=f,t[167]=qt):qt=t[167];let Jt;t[168]!==Be||t[169]!==me||t[170]!==Pt||t[171]!==Mt||t[172]!==z?.error||t[173]!==we||t[174]!==Kt||t[175]!==Ht||t[176]!==Et?(Jt=(0,$.jsx)(`div`,{className:`relative min-h-0 flex-1`,children:Et===`cold-loading`||Et===`working-empty`||Et===`authoritative-empty`||Et===`fatal-error`?(0,$.jsx)(is,{state:Et,error:z?.error,onRetry:()=>Be(`retry`)}):me?(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`absolute inset-0`,children:[Ht,(0,$.jsx)(Xe,{containerRef:we,userIntentOnly:!0,observeMutations:!1})]}),Kt]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(De,{ref:we,className:`absolute inset-0 overflow-y-auto overflow-x-hidden chat-scroll overlay-scrollbar-target`,observeMutations:!1,"data-scroll-shadow":`true`,"data-scrollbar":`chat`,children:(0,$.jsxs)(`div`,{className:`relative min-h-full`,children:[Mt,Pt,Ht,It]})}),Kt]})}),t[168]=Be,t[169]=me,t[170]=Pt,t[171]=Mt,t[172]=z?.error,t[173]=we,t[174]=Kt,t[175]=Ht,t[176]=Et,t[177]=Jt):Jt=t[177];let Yt;t[178]!==k.agentName||t[179]!==k.modelId||t[180]!==k.providerId||t[181]!==M||t[182]!==R?(Yt=R?(0,$.jsx)(ut,{agentName:k.agentName,providerId:k.providerId,modelId:k.modelId,modelName:M}):null,t[178]=k.agentName,t[179]=k.modelId,t[180]=k.providerId,t[181]=M,t[182]=R,t[183]=Yt):Yt=t[183];let Xt;t[184]!==r||t[185]!==n||t[186]!==qt||t[187]!==Jt||t[188]!==Yt?(Xt=(0,$.jsxs)(`div`,{className:`relative flex h-full min-h-0 flex-col bg-background`,"data-context-session-surface":`true`,"data-session-id":r,"data-surface-id":n,children:[qt,Jt,Yt]}),t[184]=r,t[185]=n,t[186]=qt,t[187]=Jt,t[188]=Yt,t[189]=Xt):Xt=t[189];let Zt;return t[190]!==Ot||t[191]!==Xt?(Zt=(0,$.jsx)(wt.Provider,{value:Ot,children:Xt}),t[190]=Ot,t[191]=Xt,t[192]=Zt):Zt=t[192],Zt},os=e=>{let t=(0,Sn.c)(22),n=oe(),{t:r}=ee(),i;t[0]===e.directory?i=t[1]:(i=So(e.directory),t[0]=e.directory,t[1]=i);let a=i,o=a===So(n),s;t[2]!==a||t[3]!==e.active||t[4]!==e.onNavigateSession||t[5]!==e.sessionId||t[6]!==e.surfaceId?(s={kind:`panel`,surfaceId:e.surfaceId,sessionId:e.sessionId,directory:a,active:e.active,capabilities:st,navigateSession:e.onNavigateSession},t[2]=a,t[3]=e.active,t[4]=e.onNavigateSession,t[5]=e.sessionId,t[6]=e.surfaceId,t[7]=s):s=t[7];let c=s;if(!o){let n=e.sessionId,i=e.surfaceId,a;t[8]===r?a=t[9]:(a=r(`chat.emptyState.opencodeUnreachable`),t[8]=r,t[9]=a);let o;t[10]===a?o=t[11]:(o=(0,$.jsx)(is,{state:`directory-mismatch`,onRetry:us,error:a}),t[10]=a,t[11]=o);let s;t[12]!==e.sessionId||t[13]!==e.surfaceId||t[14]!==o?(s=(0,$.jsx)(`div`,{className:`h-full`,"data-context-session-surface":`true`,"data-session-id":n,"data-surface-id":i,children:o}),t[12]=e.sessionId,t[13]=e.surfaceId,t[14]=o,t[15]=s):s=t[15];let l;return t[16]!==c||t[17]!==s?(l=(0,$.jsx)(wt.Provider,{value:c,children:s}),t[16]=c,t[17]=s,t[18]=l):l=t[18],l}let l;return t[19]!==e||t[20]!==n?(l=(0,$.jsx)(as,{...e,syncDirectory:n}),t[19]=e,t[20]=n,t[21]=l):l=t[21],l};function ss(e){return e.providers}function cs(e){return e.legendTimelineEnabled}function ls(e){return e+1}function us(){}var ds=e=>{if(!e||typeof e!=`object`)return!1;let t=e;return typeof t.x==`number`&&typeof t.y==`number`},fs=e=>!e||typeof e!=`object`?!1:Object.values(e).every(e=>typeof e==`string`),ps=e=>{if(!e||typeof e!=`object`)return!1;let t=e,n=t.bounds;return typeof t.tag==`string`&&typeof t.text==`string`&&typeof t.selector==`string`&&typeof t.path==`string`&&!!n&&typeof n?.x==`number`&&typeof n?.y==`number`&&typeof n?.width==`number`&&typeof n?.height==`number`&&ds(t.center)&&fs(t.attributes)&&fs(t.computedStyle)&&Array.isArray(t.ancestry)},ms=({pageUrl:e,viewport:t,devicePixelRatio:n,target:r,screenshotAttached:i,intro:a})=>{let o=r.text.trim(),s=Object.entries(r.attributes).map(([e,t])=>`${e}="${t}"`).join(` `),c=r.computedStyle,l=r.bounds,u=r.center,d=a.replace(/[.:]+$/g,``),f=r.ancestry.map(e=>e.selectorPart).join(` > `);return[`${d}:`,`Page: ${e||`preview`}`,`Viewport: ${t.width}x${t.height}, DPR ${n}`,`Screenshot: ${i?`attached`:`not attached`}`,`Element: ${r.tag}`,o?`Text: ${o}`:null,`- Selector: ${r.selector}`,`- Path: ${r.path}`,f?`- Ancestry: ${f}`:null,s?`- Attributes: ${s}`:null,`- Bounds: x=${Math.round(l.x)}, y=${Math.round(l.y)}, width=${Math.round(l.width)}, height=${Math.round(l.height)}`,`- Center: x=${Math.round(u.x)}, y=${Math.round(u.y)}`,`Styles: display=${c.display}; position=${c.position}; font=${c.fontWeight} ${c.fontSize} / ${c.lineHeight} ${c.fontFamily}; color=${c.color}; background=${c.backgroundColor}; z-index=${c.zIndex}`].filter(e=>typeof e==`string`).join(`
|
|
157
157
|
`)},hs=async(e,t)=>{if(typeof window<`u`)try{let n=e.getBoundingClientRect(),r=await v(`desktop_capture_page_rect`,{x:n.left,y:n.top,width:n.width,height:n.height});if(!r)throw Error(`Desktop screenshot capture is not available`);let i=new Image;await new Promise((e,t)=>{i.onload=()=>e(),i.onerror=()=>t(Error(`Failed to load desktop preview screenshot`)),i.src=`data:${r.mime};base64,${r.base64}`});let a=Math.max(1,i.naturalWidth||r.width||Math.floor(n.width)),o=Math.max(1,i.naturalHeight||r.height||Math.floor(n.height)),s=Math.min(1,1200/a),c=document.createElement(`canvas`);c.width=Math.floor(a*s),c.height=Math.floor(o*s);let l=c.getContext(`2d`);if(!l)return null;l.scale(s,s),l.drawImage(i,0,0,a,o);let u=a/Math.max(1,n.width),d=o/Math.max(1,n.height);l.fillStyle=`rgba(37, 99, 235, 0.28)`,l.strokeStyle=`rgb(37, 99, 235)`,l.lineWidth=Math.max(2,2*u),l.fillRect(t.bounds.x*u,t.bounds.y*d,t.bounds.width*u,t.bounds.height*d),l.strokeRect(t.bounds.x*u,t.bounds.y*d,t.bounds.width*u,t.bounds.height*d);let f=await new Promise(e=>c.toBlob(e,`image/jpeg`,.82));return f?new File([f],`preview-annotation-${Date.now()}.jpg`,{type:`image/jpeg`}):null}catch(e){return console.warn(`[preview] failed to capture annotation screenshot:`,e),null}return await Ks(e,t)},gs=async(e,t,n,r,i,a)=>{if(!e)return null;try{let o=new Image;await new Promise((t,n)=>{o.onload=()=>t(),o.onerror=()=>n(Error(`Failed to load desktop browser screenshot`)),o.src=`data:image/jpeg;base64,${e}`});let s=Math.max(1,o.naturalWidth||t),c=Math.max(1,o.naturalHeight||n),l=Math.min(1,1200/s),u=document.createElement(`canvas`);u.width=Math.floor(s*l),u.height=Math.floor(c*l);let d=u.getContext(`2d`);if(!d)return null;d.scale(l,l),d.drawImage(o,0,0,s,c);let f=s/Math.max(1,r||s),p=c/Math.max(1,i||c);d.fillStyle=`rgba(37, 99, 235, 0.14)`,d.strokeStyle=`rgb(37, 99, 235)`,d.lineWidth=Math.max(2,2*f),d.fillRect(a.bounds.x*f,a.bounds.y*p,a.bounds.width*f,a.bounds.height*p),d.strokeRect(a.bounds.x*f,a.bounds.y*p,a.bounds.width*f,a.bounds.height*p);let m=await new Promise(e=>u.toBlob(e,`image/jpeg`,.82));return m?new File([m],`browser-annotation-${Date.now()}.jpg`,{type:`image/jpeg`}):null}catch{return null}},_s=`data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAwMCAO+/p9sAAAAASUVORK5CYII=`,vs=new Map,ys=new Map,bs=3e4,xs=e=>{let t=vs.get(e);return t?t.expiresAt-Date.now()<=bs?(vs.delete(e),null):t:null},Ss=e=>{try{return new URL(e).origin}catch{return e}};function Cs(e){let t=e.defaultView??window;try{let n=e.body?t.getComputedStyle(e.body).backgroundColor:``;if(n&&n!==`rgba(0, 0, 0, 0)`&&n!==`transparent`)return n;let r=t.getComputedStyle(e.documentElement).backgroundColor;if(r&&r!==`rgba(0, 0, 0, 0)`&&r!==`transparent`)return r}catch{}return`#ffffff`}var ws=e=>new Promise((t,n)=>{let r=new FileReader;r.onloadend=()=>t(typeof r.result==`string`?r.result:_s),r.onerror=()=>n(r.error??Error(`Failed to read image blob`)),r.readAsDataURL(e)}),Ts=async(e,t=.82)=>{let n=await new Promise(n=>e.toBlob(n,`image/jpeg`,t));return n&&(await ws(n)).split(`,`,2)[1]||``},Es=()=>{try{return!!window.__previewCaptureDebug}catch{return!1}},Ds=(...e)=>{Es()&&[...e]},Os=(e,t=8)=>{let n=[];try{let r=e.querySelectorAll(`*`);for(let e of r){let r=e.scrollTop||0,i=e.scrollLeft||0;if(r<=0&&i<=0)continue;let a=e.tagName.toLowerCase(),o=e.id?`#${e.id}`:``,s=typeof e.className==`string`&&e.className?`.${e.className.trim().split(/\s+/).slice(0,2).join(`.`)}`:``;if(n.push({selector:`${a}${o}${s}`,scrollTop:r,scrollLeft:i,clientWidth:e.clientWidth,clientHeight:e.clientHeight,scrollWidth:e.scrollWidth,scrollHeight:e.scrollHeight}),n.length>=t)break}}catch{}return n},ks=`data-oc-fixed-pin`,As=(e,t,n)=>{if(t<=0&&n<=0)return()=>{};let r=e.defaultView;if(!r)return()=>{};let i=[],a=[];try{for(let o of e.querySelectorAll(`*`)){if(r.getComputedStyle(o).position!==`fixed`)continue;let e=o.getBoundingClientRect();if(!(e.width>0&&e.height>0))continue;o.setAttribute(ks,JSON.stringify({top:e.top+n,left:e.left+t,width:e.width,height:e.height})),i.push(o);let s=o.tagName.toLowerCase(),c=typeof o.className==`string`&&o.className?`.${o.className.trim().split(/\s+/).slice(0,2).join(`.`)}`:``;a.push({selector:`${s}${c}`,top:Math.round(e.top),left:Math.round(e.left),width:Math.round(e.width),height:Math.round(e.height)})}}catch{}return Ds(`tagged fixed elements`,a),()=>{for(let e of i)try{e.removeAttribute(ks)}catch{}}},js={name:`oc-fixed-pin`,afterClone(e){let t=e?.clone;if(!(!t||typeof t.querySelectorAll!=`function`))for(let e of t.querySelectorAll(`[${ks}]`)){let t;try{t=JSON.parse(e.getAttribute(ks)||``)}catch{continue}e.style.setProperty(`position`,`absolute`,`important`),e.style.setProperty(`top`,`${t.top}px`,`important`),e.style.setProperty(`left`,`${t.left}px`,`important`),e.style.setProperty(`right`,`auto`,`important`),e.style.setProperty(`bottom`,`auto`,`important`),e.style.setProperty(`width`,`${t.width}px`,`important`),e.style.setProperty(`height`,`${t.height}px`,`important`),e.removeAttribute(ks)}}},Ms=`data-oc-scroll-pin`,Ns=e=>{let t=[],n=Os(e,64);try{let n=e.documentElement,r=e.body;for(let i of e.querySelectorAll(`*`)){let e=i.scrollTop||0,a=i.scrollLeft||0;if(e<=0&&a<=0)continue;let o=i!==n&&i!==r;o&&i.setAttribute(Ms,JSON.stringify({top:e,left:a})),t.push({el:i,top:e,left:a,tagged:o})}}catch{}return{reapply:()=>{for(let e of t)try{e.el.scrollHeight,e.el.scrollTop!==e.top&&(e.el.scrollTop=e.top),e.el.scrollLeft!==e.left&&(e.el.scrollLeft=e.left)}catch{}},cleanup:()=>{for(let e of t)if(e.tagged)try{e.el.removeAttribute(Ms)}catch{}},snapshot:n}},Ps={name:`oc-nested-scroll`,afterClone(e){let t=e?.clone;if(!t||typeof t.querySelectorAll!=`function`)return;let n=t.ownerDocument;if(n)for(let e of t.querySelectorAll(`[${Ms}]`)){let t;try{t=JSON.parse(e.getAttribute(Ms)||``)}catch{e.removeAttribute(Ms);continue}let r=`translate(${-t.left}px, ${-t.top}px)`,i=e.children.length===1&&e.firstElementChild instanceof HTMLElement&&e.firstElementChild.style.willChange===`transform`?e.firstElementChild:null;if(i)i.style.transform=r;else{e.style.overflow=`hidden`;let t=n.createElement(`div`);for(t.style.transform=r,t.style.willChange=`transform`,t.style.display=`inline-block`,t.style.width=`100%`;e.firstChild;)t.appendChild(e.firstChild);e.appendChild(t)}e.removeAttribute(Ms)}}},Fs=async(e,t)=>{try{let n=await fetch(e,{credentials:t});return n.ok?await ws(await n.blob()):null}catch{return null}},Is=async e=>{if(e.protocol!==`http:`&&e.protocol!==`https:`)return``;let t=e.origin,n=xs(t);if(n)return`${n.proxyBasePath}${e.pathname}${e.search}${e.hash}`;let r=ys.get(t),i=r??(async()=>{try{let n=await _(`/api/preview/targets`,{method:`POST`,headers:{"Content-Type":`application/json`},credentials:`include`,body:JSON.stringify({url:e.toString(),allowExternal:!0})});if(!n.ok)return vs.delete(t),null;let r=await n.json(),i=typeof r.proxyBasePath==`string`?r.proxyBasePath:``,a=typeof r.expiresAt==`number`?r.expiresAt:0;if(!i)return vs.delete(t),null;let o={proxyBasePath:i,expiresAt:a};return vs.set(t,o),o}catch{return vs.delete(t),null}finally{ys.delete(t)}})();r||ys.set(t,i);let a=await i;return a?`${a.proxyBasePath}${e.pathname}${e.search}${e.hash}`:``},Ls=async(e,t)=>{if(!e||e.startsWith(`data:`))return e;try{let n=new URL(e,t.baseURI);if(n.origin===window.location.origin||n.protocol!==`http:`&&n.protocol!==`https:`)return await Fs(n.toString(),`include`)??_s;let r=await Is(n);return(r?await Fs(r,`include`):null)||(await Fs(n.toString(),`omit`)??_s)}catch{return _s}},Rs=async(e,t)=>{if(!e||e===`none`||!e.includes(`url(`))return e;let n=Array.from(e.matchAll(/url\((['"]?)(.*?)\1\)/g)),r=e;for(let e of n){let n=e[2]||``;if(!n||n.startsWith(`data:`))continue;let i=await Ls(n,t);r=r.replace(e[0],`url("${i}")`)}return r},zs=e=>e.complete?Promise.resolve():new Promise(t=>{e.addEventListener(`load`,()=>t(),{once:!0}),e.addEventListener(`error`,()=>t(),{once:!0})}),Bs=e=>{let t=e.style.cssText;return()=>{e.style.cssText=t}},Vs=e=>{let t=Number.parseFloat(e.lineHeight);if(Number.isFinite(t)&&t>0)return t;let n=Number.parseFloat(e.fontSize);return Number.isFinite(n)&&n>0?n*1.2:16},Hs=(e,t,n)=>{let r=[],i=e.defaultView??window,a=Array.from(e.querySelectorAll(`button, a, summary, label, [role="button"], [role="link"], [role="menuitem"], [role="tab"], nav *, header *`));for(let e of a){let a=e.textContent?.replace(/\s+/g,` `).trim()??``;if(!a||!a.includes(` `))continue;let o=e.getBoundingClientRect();if(o.width<=0||o.height<=0||o.right<0||o.bottom<0||o.left>t||o.top>n)continue;let s=i.getComputedStyle(e);if(s.display===`none`||s.visibility===`hidden`||Number(s.opacity)===0)continue;let c=s.getPropertyValue(`text-wrap`),l=s.getPropertyValue(`text-wrap-mode`),u=s.whiteSpace.includes(`nowrap`)||c===`nowrap`||l===`nowrap`,d=o.height<=Vs(s)*1.7;!u&&(!d||o.width>t*.72)||(r.push(Bs(e)),e.style.whiteSpace=`nowrap`,e.style.overflowWrap=`normal`,e.style.wordBreak=`normal`,e.style.setProperty(`text-wrap`,`nowrap`),e.style.setProperty(`text-wrap-mode`,`nowrap`))}return()=>{for(let e=r.length-1;e>=0;--e)r[e]?.()}},Us=(e,t,n,r)=>{let i=[],a=e.defaultView??window,o=a.scrollX||e.documentElement.scrollLeft||e.body?.scrollLeft||0,s=a.scrollY||e.documentElement.scrollTop||e.body?.scrollTop||0,c=Array.from(e.querySelectorAll(`*`)).filter(e=>{let r=a.getComputedStyle(e);if(r.position!==`fixed`||r.display===`none`||r.visibility===`hidden`||Number(r.opacity)===0)return!1;let i=e.getBoundingClientRect();return i.width>0&&i.height>0&&i.right>=0&&i.bottom>=0&&i.left<=t&&i.top<=n}).filter((e,t,n)=>!n.some((n,r)=>r<t&&n.contains(e)));for(let e of c){let t=e.getBoundingClientRect(),n=a.getComputedStyle(e),c=Math.ceil(t.width)+8,l=Math.ceil(t.height)+2;r?.add(e),i.push(Bs(e)),e.style.position=`absolute`,e.style.top=`${t.top+s}px`,e.style.left=`${t.left+o}px`,e.style.right=`auto`,e.style.bottom=`auto`,e.style.width=`${c}px`,e.style.minWidth=`${c}px`,e.style.height=`${l}px`,e.style.minHeight=`${l}px`,e.style.margin=`0`,e.style.boxSizing=`border-box`,e.style.transform=`none`,n.zIndex!==`auto`&&(e.style.zIndex=n.zIndex)}return()=>{for(let e=i.length-1;e>=0;--e)i[e]?.()}},Ws=async(e,t,n,r={})=>{let i=[],a=e.defaultView??window,o=r=>{if(r===e.documentElement||r===e.body)return!0;try{let e=r.getBoundingClientRect();return e.width>0&&e.height>0&&e.right>=0&&e.bottom>=0&&e.left<=t&&e.top<=n}catch{return!1}};if(r.applyLayoutWorkarounds){let r=new WeakSet;i.push(Us(e,t,n,r)),i.push(Hs(e,t,n))}let s=new Map;for(let t of Array.from(e.images))s.set(t,t.currentSrc||t.src||t.getAttribute(`src`)||``);let c=Array.from(e.querySelectorAll(`picture`));for(let e of c){let t=Array.from(e.querySelectorAll(`source`));if(t.length===0)continue;let n=t.map(e=>({source:e,srcset:e.getAttribute(`srcset`),sizes:e.getAttribute(`sizes`)}));i.push(()=>{for(let e of n)e.srcset===null?e.source.removeAttribute(`srcset`):e.source.setAttribute(`srcset`,e.srcset),e.sizes===null?e.source.removeAttribute(`sizes`):e.source.setAttribute(`sizes`,e.sizes)});for(let e of t)e.removeAttribute(`srcset`),e.removeAttribute(`sizes`)}let l=Array.from(e.images).filter(e=>o(e));await Promise.all(l.map(async t=>{let n=s.get(t)||t.currentSrc||t.src||t.getAttribute(`src`)||``;if(!n)return;await zs(t);let r=await Ls(n,e),a={src:t.getAttribute(`src`),srcset:t.getAttribute(`srcset`),sizes:t.getAttribute(`sizes`)};i.push(()=>{a.src===null?t.removeAttribute(`src`):t.setAttribute(`src`,a.src),a.srcset===null?t.removeAttribute(`srcset`):t.setAttribute(`srcset`,a.srcset),a.sizes===null?t.removeAttribute(`sizes`):t.setAttribute(`sizes`,a.sizes)}),t.removeAttribute(`srcset`),t.removeAttribute(`sizes`),t.setAttribute(`src`,r||_s),await zs(t)}));let u=Array.from(e.querySelectorAll(`*`)).filter(o);return await Promise.all(u.map(async t=>{let n=a.getComputedStyle(t).backgroundImage;if(!n||n===`none`||!n.includes(`url(`))return;let r=await Rs(n,e);if(r===n)return;let o=t.style.backgroundImage;i.push(()=>{t.style.backgroundImage=o}),t.style.backgroundImage=r})),()=>{for(let e=i.length-1;e>=0;--e)try{i[e]?.()}catch{}}};async function Gs(e,t){try{let n=e.contentWindow,r=e.contentDocument??n?.document,i=r?.documentElement;if(!n||!r||!i)return null;let a=e.getBoundingClientRect(),o=Math.max(1,Math.ceil(n.innerWidth||e.clientWidth||a.width)),s=Math.max(1,Math.ceil(n.innerHeight||e.clientHeight||a.height)),c=r.body,l=r.scrollingElement instanceof HTMLElement?r.scrollingElement:null,u=n.scrollX||0,d=n.scrollY||0,f=n.pageXOffset||0,p=n.pageYOffset||0,m=n.visualViewport?.pageLeft||n.visualViewport?.offsetLeft||0,h=n.visualViewport?.pageTop||n.visualViewport?.offsetTop||0,g=i.scrollLeft||0,_=i.scrollTop||0,v=c?.scrollLeft||0,y=c?.scrollTop||0,b=l?.scrollLeft||0,x=l?.scrollTop||0,S=Math.max(u,f,m,g,v,b),C=Math.max(d,p,h,_,y,x);Ds(`scroll sources`,{windowScrollX:u,windowScrollY:d,pageScrollX:f,pageScrollY:p,visualViewportScrollX:m,visualViewportScrollY:h,rootScrollX:g,rootScrollY:_,bodyScrollX:v,bodyScrollY:y,scrollingElementScrollX:b,scrollingElementScrollY:x,scrollingElementTag:l?.tagName?.toLowerCase()??null,resolvedScrollX:S,resolvedScrollY:C,nestedScrolledElements:Os(r)});let w=Math.max(o,i.scrollWidth||0,c?.scrollWidth||0,Math.ceil(i.getBoundingClientRect().width||0)),T=Math.max(s,i.scrollHeight||0,c?.scrollHeight||0,Math.ceil(i.getBoundingClientRect().height||0)),E=Math.min(2,Math.max(1,window.devicePixelRatio||1)),D=i.style.scrollBehavior,O=c?.style.scrollBehavior??``;i.style.scrollBehavior=`auto`,c&&(c.style.scrollBehavior=`auto`);let k=Ns(r);Ds(`nested scroll snapshot`,k.snapshot);let A=()=>{},j=()=>{};try{await r.fonts?.ready.catch(()=>void 0),A=await Ws(r,o,s,{applyLayoutWorkarounds:!1}),n.scrollTo(S,C),j=As(r,S,C),k.reapply();let e={backgroundColor:Cs(r),cache:`disabled`,dpr:E,embedFonts:!0,fast:!1,height:T,outerShadows:!0,outerTransforms:!0,placeholders:!0,plugins:[js,Ps],quality:.82,width:w},a=await(await yn(i,e)).toCanvas();if(!a.width||!a.height)return null;let c=a.width/Math.max(1,w),l=a.height/Math.max(1,T),u=Math.min(a.width,Math.max(1,Math.round(o*c))),d=Math.min(a.height,Math.max(1,Math.round(s*l))),f=Math.max(0,a.width-u),p=Math.max(0,a.height-d),m=Math.min(f,Math.max(0,Math.round(S*c))),h=Math.min(p,Math.max(0,Math.round(C*l)));Ds(`capture geometry`,{viewportWidth:o,viewportHeight:s,captureWidth:w,captureHeight:T,canvasWidth:a.width,canvasHeight:a.height,xScale:c,yScale:l,sourceX:m,sourceY:h,sourceWidth:u,sourceHeight:d});let g=r.createElement(`canvas`);g.width=u,g.height=d;let _=g.getContext(`2d`);if(!_)return null;_.drawImage(a,m,h,u,d,0,0,u,d);let v=await Ts(g,.82);return v?await gs(v,o,s,o,s,t):null}finally{j(),k.cleanup(),A(),n.scrollTo(S,C),k.reapply(),i.style.scrollBehavior=D,c&&(c.style.scrollBehavior=O)}}catch(e){return console.warn(`[preview] failed to capture iframe DOM screenshot with snapDOM:`,e),null}}async function Ks(e,t){let n=await Gs(e,t);if(n)return n;try{let n=e.contentWindow,r=e.contentDocument??n?.document,i=r?.documentElement;if(!n||!r||!i)return null;let a=e.getBoundingClientRect(),o=Math.max(1,Math.ceil(n.innerWidth||e.clientWidth||a.width)),s=Math.max(1,Math.ceil(n.innerHeight||e.clientHeight||a.height)),c=n.scrollX||r.documentElement.scrollLeft||r.body?.scrollLeft||0,l=n.scrollY||r.documentElement.scrollTop||r.body?.scrollTop||0,u=r.body,d=Math.max(s,i.scrollHeight||0,u?.scrollHeight||0),f=Math.min(2,Math.max(1,window.devicePixelRatio||1)),p=i.style.scrollBehavior,m=u?.style.scrollBehavior??``;i.style.scrollBehavior=`auto`,u&&(u.style.scrollBehavior=`auto`);let h=``,g=()=>{};try{await r.fonts?.ready.catch(()=>void 0),g=await Ws(r,o,s,{applyLayoutWorkarounds:!0}),n.scrollTo(c,l);let e=await xn(i).catch(()=>``);h=await bn(i,{quality:.82,pixelRatio:f,width:o,height:s,backgroundColor:Cs(r),imagePlaceholder:_s,fontEmbedCSS:e||void 0,style:{transform:`translate(${-c}px, ${-l}px)`,transformOrigin:`top left`,minWidth:`${o}px`,minHeight:`${d}px`},cacheBust:!0})}finally{g(),n.scrollTo(c,l),i.style.scrollBehavior=p,u&&(u.style.scrollBehavior=m)}let _=h.split(`,`,2)[1]||``;return _?await gs(_,o,s,o,s,t):null}catch(e){return console.warn(`[preview] failed to capture iframe DOM screenshot:`,e),null}}var qs=380,Js=1400,Ys=600,Xs=24,Zs=new Map,Qs=200,$s=(e,t)=>t===`all`?!0:t===`errors`?e.level===`error`||e.level===`runtime`||e.level===`resource`:t===`warnings`?e.level===`warn`:e.level===`log`||e.level===`info`||e.level===`debug`,ec=e=>{if(!e)return``;let t=e.replace(/\\/g,`/`),n=t.startsWith(`//`),r=t.replace(/\/+$/g,``);return r=r.replace(/\/+/g,`/`),n&&!r.startsWith(`//`)&&(r=`/${r}`),r===``?t.startsWith(`/`)?`/`:``:r},tc=e=>Number.isFinite(e)?Math.min(Js,Math.max(qs,Math.round(e))):Ys,nc=e=>{let t=e?.parentElement?.clientWidth;return!t||t<=0?null:t},rc=(e,t)=>{let n=tc(e),r=nc(t);return r===null?n:Math.min(n,Math.max(1,r))},ic=(e,t)=>{if(!e)return``;let n=e.replace(/\\/g,`/`),r=t.replace(/\\/g,`/`).replace(/\/+$/,``);return r&&n.startsWith(r+`/`)?n.slice(r.length+1):n},ac=(e,t)=>t(e===`chat`?`contextPanel.mode.chat`:e===`file`?`contextPanel.mode.files`:e===`diff`||e===`file-diff`?`contextPanel.mode.diff`:e===`preview`?`contextPanel.mode.preview`:e===`browser`?`contextPanel.mode.browser`:`contextPanel.mode.context`),oc=e=>{if(!e)return null;let t=e.replace(/\\/g,`/`).trim();if(!t)return null;let n=t.split(`/`).filter(Boolean);return n.length===0?t:n[n.length-1]||null},sc=(e,t,n)=>{if(e.mode===`chat`){let r=lc(e.dedupeKey);if(r){let e=t.get(r)?.trim();if(e)return e}return e.sessionTitleFallback?.trim()||n(`contextPanel.mode.chat`)}if(e.label)return e.label;if(e.mode===`file`)return oc(e.targetPath)||n(`contextPanel.mode.files`);if(e.mode===`preview`){let t=e.targetPath;if(t)try{let e=new URL(t);return e.host||e.hostname||n(`contextPanel.mode.preview`)}catch{}return n(`contextPanel.mode.preview`)}return e.mode===`diff`?n(`contextPanel.mode.diff`):e.mode===`file-diff`?oc(e.targetPath)||n(`contextPanel.mode.diff`):ac(e.mode,n)},cc=e=>{if(e.mode===`file`)return e.targetPath?(0,$.jsx)(St,{filePath:e.targetPath,className:`h-3.5 w-3.5`}):void 0;if(e.mode===`diff`||e.mode===`file-diff`)return(0,$.jsx)(Y,{name:`arrow-left-right`,className:`h-3.5 w-3.5`});if(e.mode===`context`)return(0,$.jsx)(Y,{name:`file-list-2`,className:`h-3.5 w-3.5`});if(e.mode===`chat`)return(0,$.jsx)(Y,{name:`chat-thread`,className:`h-3.5 w-3.5`});if(e.mode===`preview`)return(0,$.jsx)(Y,{name:`global`,className:`h-3.5 w-3.5 text-[var(--status-info)]`});if(e.mode===`browser`)return(0,$.jsx)(Y,{name:`global`,className:`h-3.5 w-3.5`})},lc=e=>!e||!e.startsWith(`session:`)?null:e.slice(8).trim()||null,uc=(e,t)=>{if(e.size!==t.size)return!1;for(let[n,r]of e)if(t.get(n)!==r)return!1;return!0},dc=(e,t)=>{if(t.length===0)return Zs;let n=new Set(t),r=new Map;for(let t of e){if(!n.has(t.id))continue;let e=t.title?.trim();e&&r.set(t.id,e)}return r.size===0?Zs:r},fc=(e,t)=>{let n=z(e),r=Q.useRef(Zs),i=Q.useRef(t);return i.current=t,Q.useSyncExternalStore(n.subscribe,Q.useCallback(()=>{let e=dc(n.getState().session,i.current);return uc(r.current,e)?r.current:(r.current=e,e)},[n]),()=>Zs)},pc=`new Promise((resolve) => {
|
|
158
158
|
const existing = document.getElementById('__openchamber_desktop_browser_overlay');
|
|
159
159
|
if (existing) existing.remove();
|