@openchambery/web 1.19.2-beta.1 → 1.19.2-beta.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/{AgentAvatar-DgGHpQoD.js → AgentAvatar-HJ-RYWko.js} +1 -1
- package/dist/assets/AssistantView-DlCqeHRI.js +1 -0
- package/dist/assets/{ChatContainer-CM43Pxln.js → ChatContainer-BkLmQfq7.js} +39 -39
- package/dist/assets/ContextPanel-BQMC2oCJ.js +285 -0
- package/dist/assets/DiagramView-vGsDg-yO.js +1 -0
- package/dist/assets/{FadeInOnReveal-BpIMrqet.js → FadeInOnReveal-Cy3sf2M5.js} +1 -1
- package/dist/assets/{Icon-Bs6GJIoO.js → Icon-BLWVqBee.js} +1 -1
- package/dist/assets/{MarkdownRendererImpl-Cmm9i5Vj.js → MarkdownRendererImpl-Bzu4V7LA.js} +1 -1
- package/dist/assets/{MobileDetailNavigation-nITHp7W3.js → MobileDetailNavigation-D8fXCuG1.js} +1 -1
- package/dist/assets/{MobileShareBridge-C_QaKaB6.js → MobileShareBridge-Ds-e8QJQ.js} +2 -2
- package/dist/assets/MobileSurface-vlEqR4CT.js +2 -0
- package/dist/assets/{MultiRunWindow-B1ALyR36.js → MultiRunWindow-BFTiVVgw.js} +1 -1
- package/dist/assets/{OnboardingScreen-n85WAcBc.js → OnboardingScreen-yNfhXL7h.js} +1 -1
- package/dist/assets/{OverlayScrollbar-VZKKu-cu.js → OverlayScrollbar-GQgJusKL.js} +1 -1
- package/dist/assets/{SettingsView-BW8d_8pw.js → SettingsView-Dl0oHuoW.js} +6 -6
- package/dist/assets/{SettingsWindow-7SmQV5GW.js → SettingsWindow-C_TY0Td5.js} +1 -1
- package/dist/assets/{TerminalView-C7EFF7ZS.js → TerminalView-c6NtOWOG.js} +1 -1
- package/dist/assets/{ToolOutputDialog-Cba_60bU.js → ToolOutputDialog-CyVjUPDv.js} +2 -2
- package/dist/assets/{appThemeRegistry-Co5dwWx_.js → appThemeRegistry-BmNfsTDj.js} +2 -2
- package/dist/assets/{button-BkTMa7Qj.js → button-CeCkEpvn.js} +1 -1
- package/dist/assets/{clipboard-BL4PvBYZ.js → clipboard-2rQvL28z.js} +1 -1
- package/dist/assets/{collapsible-CVL-5iEB.js → collapsible-B-aagADh.js} +1 -1
- package/dist/assets/{desktopHosts-Dzx3McaD.js → desktopHosts-BrrYPqKq.js} +1 -1
- package/dist/assets/{desktopRelayRestore-B9S0Rp5s.js → desktopRelayRestore-DR60DATT.js} +1 -1
- package/dist/assets/diagram-Cxma_IKI.js +1 -0
- package/dist/assets/{dialog-CD0j-atu.js → dialog-DnzdtCcc.js} +1 -1
- package/dist/assets/es-BOiTSQ5G.js +15 -0
- package/dist/assets/fileQueries-BJKLdYos.js +1 -0
- package/dist/assets/fr-C5pZX4Yb.js +13 -0
- package/dist/assets/{gitApi-DaTTo7St.js → gitApi-Dz8NtzVn.js} +3 -3
- package/dist/assets/{input-Ca2tUhgN.js → input-CyG05w-V.js} +1 -1
- package/dist/assets/insertionBoundaries-1tfYYfQc.js +4 -0
- package/dist/assets/ja-80U-a23j.js +15 -0
- package/dist/assets/ko-tcJcPnGS.js +15 -0
- package/dist/assets/main-BBfAXAy9.js +29 -0
- package/dist/assets/{main-IyYkGXkX.js → main-i9SC8giI.js} +2 -2
- package/dist/assets/{markdown-worker-9Sn2jsDp.js → markdown-worker-DqO-GnVj.js} +1 -1
- package/dist/assets/{markdownTheme-DidS-jC5.js → markdownTheme-H7_7lbuh.js} +1 -1
- package/dist/assets/{miniChat-CAAQzm9R.js → miniChat-Cldq5qFL.js} +2 -2
- package/dist/assets/mobile-yEDsvHcp.js +2 -0
- package/dist/assets/multirun-fLDKu-UT.js +4 -0
- package/dist/assets/{persistence-aCOlo6ew.js → persistence-DE9RnVcA.js} +2 -2
- package/dist/assets/pl-CIRIRP8a.js +15 -0
- package/dist/assets/{platform-ulFAVx1H.js → platform-MjT8iqKB.js} +1 -1
- package/dist/assets/{projectMeta-B0YA9FxC.js → projectMeta-D7X-A53_.js} +2 -2
- package/dist/assets/pt-BR-yXSOtWjW.js +15 -0
- package/dist/assets/radio-Yq-d8wdL.js +1 -0
- package/dist/assets/renderElectronMiniChatApp-D2oO2jcX.js +2 -0
- package/dist/assets/renderMobileApp-CsWmUiF2.js +23 -0
- package/dist/assets/{runtimeConfig-BJ3S27Ah.js → runtimeConfig-DWavskLj.js} +1 -1
- package/dist/assets/runtimeEndpointReset-BpPowLWZ.js +4 -0
- package/dist/assets/{shikiHighlight-_cgskSv2.js → shikiHighlight-DtIFquMl.js} +1 -1
- package/dist/assets/{sortable-tabs-strip-Bl26ebY_.js → sortable-tabs-strip-CmUWXOHX.js} +1 -1
- package/dist/assets/src-BM9HiQZr.css +2 -0
- package/dist/assets/store-NWfuTiFD.js +15 -0
- package/dist/assets/{terminalApi-HsIEks5U.js → terminalApi-Bnx0KvaV.js} +1 -1
- package/dist/assets/{tooltip-GC3dg3gO.js → tooltip-B__x-HDJ.js} +1 -1
- package/dist/assets/uk-Do9LnhN3.js +15 -0
- package/dist/assets/{url-BQHM4bC4.js → url-CTuw7Rjf.js} +1 -1
- package/dist/assets/{useAppFontEffects-B_a7MLYy.js → useAppFontEffects-a1rqNBb6.js} +5 -5
- package/dist/assets/{useAssistantUIStore-DxZsjSPQ.js → useAssistantUIStore-D2K7ksGj.js} +1 -1
- package/dist/assets/{useDesktopWindowControlsLayout-D-74BaI3.js → useDesktopWindowControlsLayout-DuV7h2ks.js} +1 -1
- package/dist/assets/{useEffectiveDirectory-DWwrRiBF.js → useEffectiveDirectory-BD6DpFta.js} +1 -1
- package/dist/assets/{useFontPreferences-DaFspdDd.js → useFontPreferences-CWZnNRjz.js} +1 -1
- package/dist/assets/{useMobileNavigationStore-7LBI6idi.js → useMobileNavigationStore-COadjMlM.js} +12 -75
- package/dist/assets/{useSessionAutoCleanup-Buvg8rem.js → useSessionAutoCleanup-BXaR4Y1z.js} +1 -1
- package/dist/assets/{useUIStore-Wyu09VUF.js → useUIStore-DOxLVeGb.js} +1 -1
- package/dist/assets/{useWorkerHighlightedLines-BdlVg3Sj.js → useWorkerHighlightedLines-CDuEzJVC.js} +1 -1
- package/dist/assets/{utils-CJdWZupK.js → utils-C2R0YoC5.js} +1 -1
- package/dist/assets/zh-CN-BAZNUvn0.js +15 -0
- package/dist/assets/zh-TW-BQsPCZWH.js +15 -0
- package/dist/index.html +9 -9
- package/dist/mini-chat.html +9 -9
- package/dist/mobile.html +9 -9
- package/package.json +1 -1
- package/server/index.js +0 -5
- package/dist/assets/AssistantView-DGqRio2e.js +0 -1
- package/dist/assets/ContextPanel-Bp3ZKAJE.js +0 -288
- package/dist/assets/DiagramView-BH5YxFAL.js +0 -1
- package/dist/assets/MobileSurface-CjpCviv6.js +0 -2
- package/dist/assets/es-C-RVtNF4.js +0 -15
- package/dist/assets/fileQueries-_VUJM8AE.js +0 -1
- package/dist/assets/fr-C6VZ9yt-.js +0 -13
- package/dist/assets/insertionBoundaries-BoIHXczc.js +0 -4
- package/dist/assets/ja-BdksT20v.js +0 -15
- package/dist/assets/ko-CvsczTmf.js +0 -15
- package/dist/assets/main-WVLfE2Df.js +0 -29
- package/dist/assets/mobile-BiCmfs5Y.js +0 -2
- package/dist/assets/multirun-DPXG-TWE.js +0 -4
- package/dist/assets/pl-C84UGmMr.js +0 -15
- package/dist/assets/pt-BR-DISmT3zF.js +0 -15
- package/dist/assets/radio-CUea8K8R.js +0 -1
- package/dist/assets/renderElectronMiniChatApp-CGA16ZyN.js +0 -2
- package/dist/assets/renderMobileApp-D9fgFt6E.js +0 -23
- package/dist/assets/runtimeEndpointReset-C9pWVmjf.js +0 -4
- package/dist/assets/src-BwToVDxi.css +0 -2
- package/dist/assets/store-Dge7C5E4.js +0 -15
- package/dist/assets/uk-Ba5HBTQU.js +0 -15
- package/dist/assets/zh-CN-BZYwBvs-.js +0 -15
- package/dist/assets/zh-TW-BsJuPsIi.js +0 -15
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/ToolOutputDialog-CyVjUPDv.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-2rQvL28z.js","assets/store-NWfuTiFD.js","assets/vendor-aparajita-capacitor-secure-storage-CjQdwfjS.js","assets/dialog-DnzdtCcc.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-BmNfsTDj.js","assets/platform-MjT8iqKB.js","assets/vendor-opencode-sdk-C07HQypa.js","assets/useMobileNavigationStore-COadjMlM.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-DqO-GnVj.js","assets/useEffectiveDirectory-BD6DpFta.js","assets/useWorkerHighlightedLines-CDuEzJVC.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-2rQvL28z.js";import{i as ne,t as L}from"./store-NWfuTiFD.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-COadjMlM.js";import{a as _e,i as ve,n as ye,o as be,r as xe,t as Se}from"./dialog-DnzdtCcc.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-D7X-A53_.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-Yq-d8wdL.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-BkLmQfq7.js";import{n as Tt}from"./useRuntimeAPIs-DSLXJybW.js";import{M as Et,N as Dt,b as Ot,g as kt,x as At,y as jt}from"./insertionBoundaries-1tfYYfQc.js";import{i as Mt,n as Nt,t as Pt,u as Ft}from"./appThemeRegistry-BmNfsTDj.js";import{a as It}from"./url-CTuw7Rjf.js";import{f as Lt,g as Rt,h as zt,m as Bt,p as Vt}from"./markdown-worker-DqO-GnVj.js";import{n as Ht}from"./useEffectiveDirectory-BD6DpFta.js";import{o as Ut}from"./FadeInOnReveal-Cy3sf2M5.js";import{g as Wt,n as Gt}from"./useWorkerHighlightedLines-CDuEzJVC.js";import{t as Kt}from"./sortable-tabs-strip-CmUWXOHX.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-DtIFquMl.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
|
+
`).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
|
+
`),r=Math.max(1,a),s=Math.min(n.length,o);return r>s?``:n.slice(r-1,s).join(`
|
|
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(`
|
|
6
|
+
`)?r.slice(0,-1):r)}return c.join(`
|
|
7
|
+
`)}function fr(e,t,n){for(let r of e.hunks)if(n){if(t>=r.deletionStart&&t<r.deletionStart+r.deletionCount)return r.deletionLineIndex+(t-r.deletionStart)}else if(t>=r.additionStart&&t<r.additionStart+r.additionCount)return r.additionLineIndex+(t-r.additionStart);return null}var pr=5e5,mr=`
|
|
8
|
+
:host {
|
|
9
|
+
font-family: var(--font-mono);
|
|
10
|
+
font-size: var(--text-code);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
pre, [data-code] {
|
|
14
|
+
font-family: var(--font-mono);
|
|
15
|
+
font-size: var(--text-code);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/* Mobile touch selection support */
|
|
19
|
+
[data-line-number] {
|
|
20
|
+
touch-action: manipulation;
|
|
21
|
+
-webkit-tap-highlight-color: transparent;
|
|
22
|
+
cursor: pointer;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/* Ensure interactive line numbers work on touch */
|
|
26
|
+
pre[data-interactive-line-numbers] [data-line-number] {
|
|
27
|
+
touch-action: manipulation;
|
|
28
|
+
}
|
|
29
|
+
`,hr=`
|
|
30
|
+
${mr}
|
|
31
|
+
|
|
32
|
+
:host {
|
|
33
|
+
--diffs-bg-separator-override: var(--surface-elevated);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
[data-diff-header],
|
|
37
|
+
[data-diff] {
|
|
38
|
+
[data-separator] {
|
|
39
|
+
height: 24px !important;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
[data-separator="line-info-basic"] {
|
|
44
|
+
height: 24px !important;
|
|
45
|
+
background: var(--diffs-bg) !important;
|
|
46
|
+
position: relative;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
[data-diff-type="single"] [data-gutter],
|
|
50
|
+
[data-diff-type="split"] [data-deletions] [data-gutter] {
|
|
51
|
+
[data-separator-wrapper] {
|
|
52
|
+
position: absolute;
|
|
53
|
+
left: 100%;
|
|
54
|
+
display: flex;
|
|
55
|
+
align-items: center;
|
|
56
|
+
gap: unset;
|
|
57
|
+
width: max-content;
|
|
58
|
+
background: transparent;
|
|
59
|
+
color: var(--diffs-fg-number);
|
|
60
|
+
font-family: var(--diffs-header-font-family, var(--font-sans));
|
|
61
|
+
font-size: 0.75rem;
|
|
62
|
+
line-height: 1;
|
|
63
|
+
margin-left: calc(-2ch - 2px);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
[data-separator-wrapper][data-separator-multi-button] {
|
|
67
|
+
margin-left: calc(-3ch - 2px);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
[data-expand-button],
|
|
71
|
+
[data-separator-content] {
|
|
72
|
+
display: block;
|
|
73
|
+
align-self: unset;
|
|
74
|
+
min-width: unset;
|
|
75
|
+
min-height: unset;
|
|
76
|
+
padding: 0;
|
|
77
|
+
flex-shrink: 0;
|
|
78
|
+
grid-column: unset;
|
|
79
|
+
border: none;
|
|
80
|
+
width: auto;
|
|
81
|
+
height: auto;
|
|
82
|
+
background-color: transparent;
|
|
83
|
+
color: inherit;
|
|
84
|
+
font: inherit;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
[data-expand-button]:not([data-expand-all-button]) {
|
|
88
|
+
&[data-expand-down]::before {
|
|
89
|
+
content: '\\2191';
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
&[data-expand-up]::before {
|
|
93
|
+
content: '\\2193';
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
&[data-expand-both]::before {
|
|
97
|
+
content: '\\2195';
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
svg {
|
|
101
|
+
display: none;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
[data-separator-content] {
|
|
106
|
+
background: transparent;
|
|
107
|
+
margin-left: calc(2px + 1ch);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
[data-expand-all-button] {
|
|
111
|
+
position: relative;
|
|
112
|
+
margin-left: 14px;
|
|
113
|
+
text-transform: lowercase;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
[data-expand-all-button]::before {
|
|
117
|
+
content: '';
|
|
118
|
+
display: block;
|
|
119
|
+
position: absolute;
|
|
120
|
+
top: 50%;
|
|
121
|
+
left: -8px;
|
|
122
|
+
margin-top: -1px;
|
|
123
|
+
width: 3px;
|
|
124
|
+
height: 3px;
|
|
125
|
+
border-radius: 2px;
|
|
126
|
+
background-color: var(--diffs-fg-number);
|
|
127
|
+
pointer-events: none;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
[data-separator-content]:hover,
|
|
131
|
+
[data-expand-button]:hover,
|
|
132
|
+
[data-expand-all-button]:hover {
|
|
133
|
+
color: var(--diffs-fg);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
[data-expand-all-button]:hover {
|
|
137
|
+
text-decoration: underline;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
`;function gr(e){let t=2166136261;for(let n=0;n<e.length;n+=1)t^=e.charCodeAt(n),t=t+((t<<1)+(t<<4)+(t<<7)+(t<<8)+(t<<24))>>>0;return t.toString(16)}function _r(e){let t=e.length>400?`${e.slice(0,200)}${e.slice(-200)}`:e;return`${e.length}:${gr(t)}`}var vr=(e,t)=>e===t?!0:!e||!t?!1:e.start===t.start&&e.end===t.end&&e.side===t.side,yr=e=>e===`auto`||e===`scroll`||e===`overlay`,br=e=>{let t=e?.parentElement??null;for(;t;){if(yr(window.getComputedStyle(t).overflowY))return t;t=t.parentElement}return null},xr=(e,t)=>{if(!e||!t||typeof window>`u`)return()=>{};let n=br(e);if(!n)return()=>{};let r=t.getBoundingClientRect().height;if(!r)return()=>{};let i=e.getBoundingClientRect().top-n.getBoundingClientRect().top,a=t.style.minHeight;t.style.minHeight=`${Math.ceil(r)}px`;let o=!1;return()=>{if(o)return;o=!0,t.style.minHeight=a;let r=e.getBoundingClientRect().top-n.getBoundingClientRect().top-i;r&&(n.scrollTop+=r)}},Sr=(e,t,n={})=>{if(typeof window>`u`)return()=>{};let r=null,i=null,a=!1,o=()=>{a||(i?.disconnect(),i=null,r=window.requestAnimationFrame(()=>{r=window.requestAnimationFrame(()=>{a||t()})}))},s=()=>e.querySelector(`diffs-container`)?.shadowRoot??void 0,c=(e=s())=>!!e?.querySelector(`[data-line]`);return!n.awaitRender&&c()?o():typeof MutationObserver<`u`?(i=new MutationObserver(()=>{let e=s();if(e){if(c(e)){o();return}i?.disconnect(),i=new MutationObserver(()=>{c(e)&&o()}),i.observe(e,{childList:!0,subtree:!0})}}),i.observe(e,{childList:!0,subtree:!0})):r=window.requestAnimationFrame(o),()=>{a=!0,i?.disconnect(),r!==null&&window.cancelAnimationFrame(r)}},Cr=new WeakMap,wr={lineHeight:24,hunkSeparatorHeight:24,spacing:0};function Tr(e){let t=e.closest(`[data-diff-virtual-root]`);if(t instanceof HTMLElement){let e=t.querySelector(`[data-diff-virtual-content]`);return{key:t,root:t,content:e instanceof HTMLElement?e:void 0}}return{key:document,root:document,content:void 0}}function Er(e){if(typeof document>`u`)return null;let t=Tr(e),n=Cr.get(t.key);if(!n){let e=new en;e.setup(t.root,t.content),n={virtualizer:e,refs:0},Cr.set(t.key,n)}n.refs+=1;let r=!1;return{virtualizer:n.virtualizer,root:t.root,release:()=>{if(r)return;r=!0;let e=Cr.get(t.key);e&&(--e.refs,!(e.refs>0)&&(e.virtualizer.cleanUp(),Cr.delete(t.key)))}}}var Dr=(e,t,n)=>{if(typeof window>`u`)return()=>{};let r=[],i=()=>{try{e.rerender()}catch{}let r=t?.root;r instanceof HTMLElement?r.dispatchEvent(new Event(`scroll`,{bubbles:!1})):document.dispatchEvent(new Event(`scroll`,{bubbles:!1})),window.dispatchEvent(new Event(`resize`)),n()};return r.push(window.requestAnimationFrame(i)),r.push(window.requestAnimationFrame(()=>{r.push(window.requestAnimationFrame(i))})),()=>{for(let e of r)window.cancelAnimationFrame(e)}},Or=({original:e,modified:t,fileDiff:n,language:r,fileName:i,renderSideBySide:a,wrapLines:o,layout:s=`fill`,enableComments:l=!0,enableSelectionActions:u=!0,focusLine:d=null})=>{let f=Pe(),p=f?.currentTheme.metadata.variant===`dark`,m=f?.availableThemes.find(e=>e.metadata.id===f.lightThemeId)??et(!1),h=f?.availableThemes.find(e=>e.metadata.id===f.darkThemeId)??et(!0),{isMobile:g}=Ye(),_=re(e=>e.addCodeSelectionAttachment),v=re(e=>e.setPendingInputText),[y,b]=Q.useState(null),{drafts:S,selection:C,setSelection:w,commentText:T,setCommentText:E,editingDraftId:D,saveComment:O,cancel:k,startEdit:A,deleteDraft:j}=Kn({source:`diff`,fileLabel:i||`unknown`,language:r,getCodeForRange:r=>dr(e,t,n,r),toStoreRange:e=>({startLine:e.start,endLine:e.end,side:e.side===`deletions`?`original`:`modified`}),fromDraftRange:e=>({start:e.startLine,end:e.endLine,side:e.side===`original`?`deletions`:`additions`})}),M=(0,Q.useRef)(null),N=(0,Q.useRef)(null),P=(0,Q.useRef)(``),ee=(0,Q.useRef)(!1),F=(0,Q.useRef)(null),I=(0,Q.useRef)(!1);(0,Q.useEffect)(()=>{M.current=C},[C]),(0,Q.useEffect)(()=>{N.current=D},[D]),(0,Q.useEffect)(()=>{P.current=T},[T]);let te=(0,Q.useCallback)(e=>{if(!l||ee.current)return;let t=M.current;if(!(!e&&t&&P.current.trim())){if(g&&t&&e&&e.side===t.side){let n=Math.min(t.start,e.start),r=Math.max(t.end,e.end);w({...e,start:n,end:r})}else w(e);e||b(null),e&&(N.current||E(``))}},[l,g,E,w]),ne=(0,Q.useCallback)(()=>{k()},[k]),L=(0,Q.useCallback)(e=>{let t=document.createElement(`div`);t.style.position=`relative`;let n=er(e.metadata);return t.dataset.annotationId=n,t.dataset.annotationSide=e.side,t.dataset.annotationLine=String(e.lineNumber),t},[]),ie=(0,Q.useCallback)((e,t)=>{O(e,t??C??void 0)},[O,C]),R=(0,Q.useCallback)(r=>{if(!i)return;let a=Math.min(r.start,r.end),o=Math.max(r.start,r.end),s=a===o?`${a}`:`${a}-${o}`,l=dr(e,t,n,r);if(!l)return;let u=`${i.replace(/\\/g,`/`).split(`/`).pop()||i}:${s}`;_(i,u,l),v(x(u),`append-inline`),c.getState().setActiveMainTab(`chat`)},[_,n,i,t,e,v]);(0,Q.useEffect)(()=>{if(!u)return;let e=e=>{if(!e.metaKey||e.ctrlKey||e.altKey||e.shiftKey||e.key.toLowerCase()!==`i`)return;let t=y?.range??M.current;t&&(e.preventDefault(),R(t))};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[u,R,y]),(0,Q.useEffect)(()=>{b(null)},[i,n,e,t]),(0,Q.useEffect)(()=>{if(!u)return;let e=e=>{let t=e.composedPath(),n=lr(e.target,t),r=t.some(e=>e instanceof ShadowRoot||e instanceof Element&&e.localName===`diffs-container`);I.current=r&&!n,n||b(null)};return document.addEventListener(`pointerdown`,e,!0),()=>document.removeEventListener(`pointerdown`,e,!0)},[u]);let ae=(0,Q.useCallback)(e=>{w(e);let t=H.current;if(t)try{ee.current=!0,t.setSelectedLines(e),F.current=e}catch{}finally{ee.current=!1}},[w]),z=(0,Q.useCallback)(e=>{let t=e.closest(`[data-line-type]`)?.getAttribute(`data-line-type`)??e.getAttribute(`data-line-type`);if(t===`change-deletion`)return`deletions`;if(t===`change-addition`)return`additions`;let n=e.getAttribute(`data-column-side`)??e.getAttribute(`data-side`)??e.closest(`[data-column-side]`)?.getAttribute(`data-column-side`);if(n===`deletions`||n===`left`||n===`original`)return`deletions`;if(n===`additions`||n===`right`||n===`modified`)return`additions`;let r=e.closest(`[data-line-type]`);if(r instanceof HTMLElement){let t=r.getBoundingClientRect(),n=e.getBoundingClientRect(),i=t.left+t.width/2;return n.left+n.width/2<i?`deletions`:`additions`}return`additions`},[]);Pt(m),Pt(h);let B=`${m.metadata.id}:${h.metadata.id}:${p?`dark`:`light`}`,V=(0,Q.useMemo)(()=>{if(n){let e=n.deletionLines.reduce((e,t)=>e+t.length,0),t=n.additionLines.reduce((e,t)=>e+t.length,0);return Math.max(e,t)>pr}return Math.max(e.length,t.length)>pr},[n,t.length,e.length]),oe=(0,Q.useRef)(null),se=(0,Q.useRef)(null),H=(0,Q.useRef)(null),U=(0,Q.useRef)(null),W=(0,Q.useRef)(null),G=(0,Q.useRef)(null),K=(0,Q.useRef)(void 0),ce=(0,Q.useRef)(void 0),le=(0,Q.useRef)(void 0),q=(0,Q.useRef)(void 0),ue=(0,Q.useRef)(null),[,de]=Q.useReducer(e=>e+1,0),fe=Nn(V?`unified`:a?`split`:`unified`),pe=(0,Q.useMemo)(()=>Nt(m),[m]),me=(0,Q.useMemo)(()=>Nt(h),[h]);Q.useLayoutEffect(()=>{let e=oe.current;if(!e)return;let t=e.querySelector(`diffs-container`);if(!t)return;let n=p?me:pe,r=(e,t)=>e.colors?.[t],i=r(pe,`terminal.ansiGreen`),a=r(pe,`terminal.ansiRed`),o=r(pe,`terminal.ansiBlue`),s=r(me,`terminal.ansiGreen`),c=r(me,`terminal.ansiRed`),l=r(me,`terminal.ansiBlue`);t.style.setProperty(`--shiki-light`,pe.fg),t.style.setProperty(`--shiki-light-bg`,pe.bg),i&&t.style.setProperty(`--shiki-light-addition-color`,i),a&&t.style.setProperty(`--shiki-light-deletion-color`,a),o&&t.style.setProperty(`--shiki-light-modified-color`,o),t.style.setProperty(`--shiki-dark`,me.fg),t.style.setProperty(`--shiki-dark-bg`,me.bg),s&&t.style.setProperty(`--shiki-dark-addition-color`,s),c&&t.style.setProperty(`--shiki-dark-deletion-color`,c),l&&t.style.setProperty(`--shiki-dark-modified-color`,l),t.style.setProperty(`--diffs-bg`,n.bg),t.style.setProperty(`--diffs-fg`,n.fg);let u=p?s:i,d=p?c:a,f=p?l:o;u&&t.style.setProperty(`--diffs-addition-color-override`,u),d&&t.style.setProperty(`--diffs-deletion-color-override`,d),f&&t.style.setProperty(`--diffs-modified-color-override`,f);let m=t.shadowRoot?.querySelector(`pre`);m&&(m.style.setProperty(`--shiki-light`,pe.fg),m.style.setProperty(`--shiki-light-bg`,pe.bg),i&&m.style.setProperty(`--shiki-light-addition-color`,i),a&&m.style.setProperty(`--shiki-light-deletion-color`,a),o&&m.style.setProperty(`--shiki-light-modified-color`,o),m.style.setProperty(`--shiki-dark`,me.fg),m.style.setProperty(`--shiki-dark-bg`,me.bg),s&&m.style.setProperty(`--shiki-dark-addition-color`,s),c&&m.style.setProperty(`--shiki-dark-deletion-color`,c),l&&m.style.setProperty(`--shiki-dark-modified-color`,l),m.style.setProperty(`--diffs-bg`,n.bg),m.style.setProperty(`--diffs-fg`,n.fg),u&&m.style.setProperty(`--diffs-addition-color-override`,u),d&&m.style.setProperty(`--diffs-deletion-color-override`,d),f&&m.style.setProperty(`--diffs-modified-color-override`,f))},[me,B,p,pe]);let he=(0,Q.useMemo)(()=>({theme:{dark:h.metadata.id,light:m.metadata.id},themeType:p?`dark`:`light`,diffStyle:a?`split`:`unified`,diffIndicators:`none`,hunkSeparators:`line-info-basic`,lineDiffType:`none`,maxLineDiffLength:V?0:1e3,maxLineLengthForHighlighting:V?1:1e3,tokenizeMaxLineLength:V?1:1e3,collapsedContextThreshold:0,expansionLineCount:20,overflow:o?`wrap`:`scroll`,disableFileHeader:!0,enableLineSelection:l,enableHoverUtility:!1,onLineSelected:l?te:void 0,unsafeCSS:hr,renderAnnotation:l?L:void 0}),[h.metadata.id,l,p,V,m.metadata.id,a,o,te,L]),ge=(0,Q.useMemo)(()=>l?tr({drafts:S,editingDraftId:D,selection:C}):[],[D,l,S,C]),_e=(0,Q.useRef)(ge);if((0,Q.useEffect)(()=>{_e.current=ge},[ge]),(0,Q.useEffect)(()=>{let e=se.current;return()=>{H.current?.cleanUp(),H.current=null,U.current?.release(),U.current=null,W.current=null,G.current=null,K.current=void 0,ce.current=void 0,le.current=void 0,q.current=void 0,e&&(e.innerHTML=``)}},[]),(0,Q.useEffect)(()=>{if(typeof window>`u`)return;let a=se.current,o=oe.current;if(!a||!fe)return;let s=xr(o,a),c=U.current;c||(c=Er(a),U.current=c),U.current=c;let l=c?.virtualizer??null,u=n?void 0:{name:i||``,contents:e,lang:r,cacheKey:`old:${B}:${i}:${_r(e)}`},f=n?void 0:{name:i||``,contents:t,lang:r,cacheKey:`new:${B}:${i}:${_r(t)}`},p=n?ce.current!==n:ce.current!==void 0||!u||!f||!le.current||!q.current||!Qt(le.current,u)||!Qt(q.current,f),m=H.current,h=!!(m&&(W.current!==l||G.current!==fe||l&&(K.current!==he.hunkSeparators||p)));h&&(m?.cleanUp(),H.current=null,a.innerHTML=``);let g=H.current,_=!h&&m?!Xt(m.options,he):!1;if(g?g.setOptions(he):(g=c?new nn(he,c.virtualizer,wr,fe):new Jt(he,fe),H.current=g,F.current=null),W.current=l,G.current=fe,K.current=l?he.hunkSeparators:void 0,ce.current=n,le.current=u,q.current=f,n)g.render({fileDiff:n,forceRender:_,lineAnnotations:_e.current,containerWrapper:a});else{if(!u||!f)return;g.render({oldFile:u,newFile:f,forceRender:_,lineAnnotations:_e.current,containerWrapper:a})}let v=Sr(a,()=>{if(s(),Dr(g,c,de),!d||ue.current===d)return;let e=(a.querySelector(`diffs-container`)?.shadowRoot)?.querySelector(`[data-line="${d}"]:not([data-line-type="change-deletion"])`);e instanceof HTMLElement&&(e.scrollIntoView({block:`center`}),ue.current=d)},{awaitRender:p&&!h});return()=>{v(),s()}},[B,n,i,d,r,t,he,e,fe]),(0,Q.useEffect)(()=>{let e=H.current;if(e){try{e.setLineAnnotations(ge)}catch(t){console.error(`Failed to apply diff line annotations`,t);try{e.setLineAnnotations([])}catch{}}requestAnimationFrame(()=>{if(H.current===e){try{e.rerender()}catch{}de()}})}},[ge]),(0,Q.useEffect)(()=>{let e=H.current;if(!e||C!==null)return;let t=F.current;if(!vr(C,t))try{ee.current=!0,e.setSelectedLines(C),F.current=C}catch{}finally{ee.current=!1}},[C]),(0,Q.useEffect)(()=>{if(!l)return;let e=se.current;if(!e)return;let t=null,n=()=>{},r=()=>{let i=e.querySelector(`diffs-container`)?.shadowRoot;if(!i){t=requestAnimationFrame(r);return}let a=e=>{if(!(e instanceof MouseEvent)||e.button!==0||!(e.target instanceof Element))return;let t=e.target.closest(`[data-column-number]`);if(!(t instanceof HTMLElement))return;let n=t.getAttribute(`data-column-number`),r=n?parseInt(n,10):NaN;if(Number.isNaN(r))return;let a=z(t);if(te({start:r,end:r,side:a}),u){let e=t.getBoundingClientRect(),n=t.closest(`[data-line-type]`)?.getAttribute(`data-line-type`),o=Array.from(i.querySelectorAll(`[data-line="${r}"]`)).find(e=>!n||e.getAttribute(`data-line-type`)===n);b({range:{start:r,end:r,side:a},x:Math.min(window.innerWidth-240,Math.max(8,o?.getBoundingClientRect().left??e.right+12)),y:e.top-8})}e.preventDefault(),e.stopPropagation()},o=(e,t)=>{let n=(e instanceof Element?e:e.parentElement)?.closest(`[data-line]`);if(!(n instanceof HTMLElement))return null;let r=Number.parseInt(n.getAttribute(`data-line`)??``,10);if(Number.isFinite(r))return{lineNumber:r,side:z(n),lineStartX:n.getBoundingClientRect().left};let i=Array.from(n.querySelectorAll(`[data-column-number]`));if(i.length===0)return null;let a=i.reduce((e,n)=>{let r=Math.abs(e.getBoundingClientRect().right-t);return Math.abs(n.getBoundingClientRect().right-t)<r?n:e}),o=Number.parseInt(a.getAttribute(`data-column-number`)??``,10);return Number.isFinite(o)?{lineNumber:o,side:z(a),lineStartX:a.getBoundingClientRect().right+12}:null},s=()=>{if(!u)return;let e=I.current;I.current=!1,e&&window.requestAnimationFrame(()=>{let e=i.getSelection?.(),t=e?.rangeCount?e:window.getSelection();if(!t)return;let n=t.getComposedRanges?.({shadowRoots:[i]})[0],r=document.createRange();if(n)r.setStart(n.startContainer,n.startOffset),r.setEnd(n.endContainer,n.endOffset);else if(t.rangeCount>0){let e=t.getRangeAt(0);r.setStart(e.startContainer,e.startOffset),r.setEnd(e.endContainer,e.endOffset)}else return;if(!ur(!0,r.toString()))return;let a=r.getBoundingClientRect(),s=o(r.startContainer,a.left),c=o(r.endContainer,a.right);!s||!c||s.side!==c.side||b({range:{start:s.lineNumber,end:c.lineNumber,side:s.side},x:Math.min(window.innerWidth-240,Math.max(8,s.lineStartX)),y:Math.max(8,a.top-8)})})};i.addEventListener(`click`,a,!0),i.addEventListener(`pointerup`,s),window.addEventListener(`pointerup`,s,!0),n=()=>{i.removeEventListener(`click`,a,!0),i.removeEventListener(`pointerup`,s),window.removeEventListener(`pointerup`,s,!0)}};return r(),()=>{t!==null&&cancelAnimationFrame(t),n()}},[B,l,u,i,te,z]),(0,Q.useEffect)(()=>{let e=se.current;if(!e)return;let t=null,n=null,r=setTimeout(()=>{let r=e.querySelector(`diffs-container`);if(!(r instanceof HTMLElement))return;let i=r.shadowRoot;t=new MutationObserver(()=>{n&&cancelAnimationFrame(n),n=requestAnimationFrame(()=>{de(),n=null})}),t.observe(r,{childList:!0,subtree:!0}),i&&t.observe(i,{childList:!0,subtree:!0})},100);return()=>{clearTimeout(r),n&&cancelAnimationFrame(n),t?.disconnect()}},[B,i]),typeof window>`u`)return null;let ve=l?(0,$.jsx)(ir,{diffRootRef:oe,drafts:S,selection:C,editingDraftId:D,commentText:T,onTextChange:E,fileLabel:i?.split(`/`).pop()??``,onSave:ie,onCancel:ne,onEdit:e=>{ae({start:e.startLine,end:e.endLine,side:e.side===`original`?`deletions`:`additions`}),A(e)},onDelete:j,onAddToChat:u?R:void 0}):null,ye=u&&y?(0,$.jsx)(ar,{position:y,onDismiss:()=>b(null),onAddToChat:()=>{R(y.range),b(null),window.getSelection()?.removeAllRanges()}}):null;return s===`fill`?(0,$.jsx)(`div`,{className:J(`flex flex-col relative`,`size-full`),"data-diff-virtual-root":!0,children:(0,$.jsxs)(`div`,{className:`flex-1 relative min-h-0`,children:[(0,$.jsx)(Ee,{outerClassName:`pierre-diff-wrapper size-full`,disableHorizontal:!1,fillContainer:!0,"data-diff-virtual-content":!0,children:(0,$.jsx)(`div`,{ref:oe,className:`size-full relative`,children:(0,$.jsx)(`div`,{ref:se,className:`size-full`})})}),ve,ye]})}):(0,$.jsxs)(`div`,{className:J(`relative`,`w-full`),children:[(0,$.jsx)(`div`,{ref:oe,className:`pierre-diff-wrapper w-full overflow-x-auto overflow-y-visible relative`,children:(0,$.jsx)(`div`,{ref:se,className:`w-full`})}),ve,ye]})},kr=5e3,Ar=(e,t)=>{if(!e)return 1;let n=1;for(let r=0;r<e.length;r+=1)if(e.charCodeAt(r)===10&&(n+=1,n>t))return n;return n},jr=(e,t)=>L(ne.getState().dictionary,e,t),Mr=e=>{let t=(e instanceof Error?e.message:String(e??``)).toLowerCase();return t.includes(`file not found`)||t.includes(`not found`)||t.includes(`enoent`)||t.includes(`no such file`)||t.includes(`does not exist`)?`missing`:`unreadable`},Nr=async(e,t)=>{if(e.readFile){let n=await e.readFile(t,{optional:!0});if(typeof n.exists!=`boolean`)throw Error(`Optional file read requires an existence response header`);return{content:n.content??``,exists:n.exists}}let n=new URLSearchParams({path:t,optional:`true`}),r=await _(`/api/fs/read?${n.toString()}`,{cache:`no-store`});if(!r.ok){let e=await r.json().catch(()=>({error:r.statusText}));throw Error(e.error||`Failed to read file`)}let i=r.headers.get(`x-openchamber-file-exists`);if(i!==`true`&&i!==`false`)throw Error(`Optional file read requires an existence response header`);return{content:await r.text(),exists:i===`true`}},Pr=async(e,t)=>{try{let{content:n,exists:r}=await Nr(e,t);return r?Ar(n,5e3)>5e3?{ok:!1,reason:`too-large`}:{ok:!0}:{ok:!1,reason:`missing`}}catch(e){return{ok:!1,reason:Mr(e)}}},Fr=e=>e===`too-large`?jr(`contextFileOpen.failure.tooLarge`,{count:kr.toLocaleString(I())}):jr(e===`missing`?`contextFileOpen.failure.missing`:`contextFileOpen.failure.unreadable`),Ir=64,Lr=3,Rr=new Map,zr=(e,t,n=Lr)=>{let r=`${e}\0${n}\0${t}`,i=Rr.get(r);if(i)return Rr.delete(r),Rr.set(r,i),i;let a=Vr(t),o=a?Yt($t(t,n),{oldFile:{name:e,contents:a.before},newFile:{name:e,contents:a.after}})??Ur(e):an(Br(e,t))[0]?.files[0]??Ur(e);for(Rr.set(r,o);Rr.size>Ir;){let e=Rr.keys().next().value;if(!e)break;Rr.delete(e)}return o},Br=(e,t)=>!t.trim()||t.startsWith(`diff --git `)||/^--- [^\n]*\r?\n\+\+\+ /m.test(t)?t:`Index: ${e}\n===================================================================\n--- ${e}\t\n+++ ${e}\t\n${t}`,Vr=e=>{if(!e.startsWith(`diff --git `)&&!/^--- [^\n]*\t?\r?\n\+\+\+ [^\n]*\t?(?:\r?\n|$)/m.test(e))return;let t=[...e.matchAll(/^@@\s+-(\d+)(?:,\d+)?\s+\+(\d+)(?:,\d+)?\s+@@[^\n]*(?:\r?\n|$)/gm)];if(t.length!==1)return;let n=t[0],r=Number.parseInt(n[1]??``,10),i=Number.parseInt(n[2]??``,10);if(r>1||i>1||!Number.isFinite(r)||!Number.isFinite(i))return;let a=(n.index??0)+n[0].length,o=e.slice(a),s=[],c=[],l;for(let e of o.split(/\r?\n/)){if(e.startsWith(`diff --git `)||e.startsWith(`@@ `))break;if(e.startsWith(`\\`)){if(l===`-`||l===` `){let e=s.at(-1);e&&(e.newline=!1)}if(l===`+`||l===` `){let e=c.at(-1);e&&(e.newline=!1)}continue}if(e.startsWith(`-`)){s.push({text:e.slice(1),newline:!0}),l=`-`;continue}if(e.startsWith(`+`)){c.push({text:e.slice(1),newline:!0}),l=`+`;continue}e.startsWith(` `)&&(s.push({text:e.slice(1),newline:!0}),c.push({text:e.slice(1),newline:!0}),l=` `)}return{before:Hr(s),after:Hr(c)}},Hr=e=>e.map(e=>e.text+(e.newline?`
|
|
141
|
+
`:``)).join(``),Ur=e=>Zt({name:e,contents:``},{name:e,contents:``}),Wr=e=>{if(!e)return null;let t=e.split(`
|
|
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
|
+
`))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
|
+
`),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-CyVjUPDv.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
|
+
`:`
|
|
147
|
+
`},Ta=e=>e.replace(/\r\n/g,`
|
|
148
|
+
`).replace(/\r/g,`
|
|
149
|
+
`),Ea=(e,t)=>{let n=Ta(e);return t===`\r
|
|
150
|
+
`?n.replace(/\n/g,`\r
|
|
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=Et(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=Dt(e=>w?e.byRoot[w]?.openPaths??qe:qe),Ze=Dt(e=>w?e.byRoot[w]?.selectedPath??null:null),Qe=Dt(e=>w?e.byRoot[w]?.expandedPaths??qe:qe),$e=Dt(e=>e.addOpenPath),nt=Dt(e=>e.removeOpenPath),rt=Dt(e=>e.removeOpenPathsByPrefix),it=Dt(e=>e.removeExpandedPathsByPrefix),at=Dt(e=>e.setSelectedPath),ot=Dt(e=>e.toggleExpandedPath),st=Dt(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
|
+
`),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
|
+
`),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=Dt.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(`
|
|
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&&Dt.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(`
|
|
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
|
+
const existing = document.getElementById('__openchamber_desktop_browser_overlay');
|
|
159
|
+
if (existing) existing.remove();
|
|
160
|
+
if (typeof window.__openchamberDesktopBrowserCancelInspect === 'function') {
|
|
161
|
+
try { window.__openchamberDesktopBrowserCancelInspect(); } catch { /* webview not ready */ }
|
|
162
|
+
}
|
|
163
|
+
const overlay = document.createElement('div');
|
|
164
|
+
overlay.id = '__openchamber_desktop_browser_overlay';
|
|
165
|
+
overlay.style.cssText = 'position:fixed;z-index:2147483647;pointer-events:none;border:2px solid #60a5fa;background:rgba(96,165,250,.24);border-radius:3px;display:none;box-sizing:border-box;';
|
|
166
|
+
document.documentElement.appendChild(overlay);
|
|
167
|
+
const cssEscape = (value) => {
|
|
168
|
+
try { return CSS.escape(value); } catch { return String(value).replace(/[^a-zA-Z0-9_-]/g, '\\\\$&'); }
|
|
169
|
+
};
|
|
170
|
+
const selectorPart = (element) => {
|
|
171
|
+
const tag = element.tagName.toLowerCase();
|
|
172
|
+
if (element.id) return tag + '#' + cssEscape(element.id);
|
|
173
|
+
const className = String(element.className || '').trim().split(/\\s+/).filter(Boolean).slice(0, 3).map((part) => '.' + cssEscape(part)).join('');
|
|
174
|
+
return tag + className;
|
|
175
|
+
};
|
|
176
|
+
const metadata = (element) => {
|
|
177
|
+
const rect = element.getBoundingClientRect();
|
|
178
|
+
const style = getComputedStyle(element);
|
|
179
|
+
const ancestry = [];
|
|
180
|
+
let current = element;
|
|
181
|
+
while (current && current.nodeType === Node.ELEMENT_NODE && ancestry.length < 8) {
|
|
182
|
+
ancestry.unshift({ tag: current.tagName.toLowerCase(), id: current.id || undefined, className: typeof current.className === 'string' ? current.className : undefined, selectorPart: selectorPart(current) });
|
|
183
|
+
current = current.parentElement;
|
|
184
|
+
}
|
|
185
|
+
const attrs = {};
|
|
186
|
+
for (const attr of Array.from(element.attributes || []).slice(0, 16)) attrs[attr.name] = attr.value.slice(0, 300);
|
|
187
|
+
const path = ancestry.map((entry) => entry.selectorPart).join(' > ');
|
|
188
|
+
return {
|
|
189
|
+
frame: 'top',
|
|
190
|
+
tag: element.tagName.toLowerCase(),
|
|
191
|
+
text: String(element.innerText || element.textContent || '').replace(/\\s+/g, ' ').trim().slice(0, 500),
|
|
192
|
+
selector: element.id ? '#' + cssEscape(element.id) : path,
|
|
193
|
+
path,
|
|
194
|
+
bounds: { x: rect.x, y: rect.y, width: rect.width, height: rect.height },
|
|
195
|
+
center: { x: rect.x + rect.width / 2, y: rect.y + rect.height / 2 },
|
|
196
|
+
attributes: attrs,
|
|
197
|
+
computedStyle: { display: style.display, position: style.position, fontWeight: style.fontWeight, fontSize: style.fontSize, lineHeight: style.lineHeight, fontFamily: style.fontFamily, color: style.color, backgroundColor: style.backgroundColor, zIndex: style.zIndex },
|
|
198
|
+
ancestry,
|
|
199
|
+
};
|
|
200
|
+
};
|
|
201
|
+
const move = (event) => {
|
|
202
|
+
const element = document.elementFromPoint(event.clientX, event.clientY);
|
|
203
|
+
if (!element || element === overlay || element === document.documentElement || element === document.body) return;
|
|
204
|
+
const rect = element.getBoundingClientRect();
|
|
205
|
+
overlay.style.display = 'block';
|
|
206
|
+
overlay.style.left = rect.left + 'px';
|
|
207
|
+
overlay.style.top = rect.top + 'px';
|
|
208
|
+
overlay.style.width = rect.width + 'px';
|
|
209
|
+
overlay.style.height = rect.height + 'px';
|
|
210
|
+
};
|
|
211
|
+
const cleanup = () => {
|
|
212
|
+
window.removeEventListener('mousemove', move, true);
|
|
213
|
+
window.removeEventListener('click', click, true);
|
|
214
|
+
window.removeEventListener('keydown', keydown, true);
|
|
215
|
+
if (window.__openchamberDesktopBrowserCancelInspect === cancel) {
|
|
216
|
+
delete window.__openchamberDesktopBrowserCancelInspect;
|
|
217
|
+
}
|
|
218
|
+
};
|
|
219
|
+
const cancel = () => {
|
|
220
|
+
cleanup();
|
|
221
|
+
overlay.remove();
|
|
222
|
+
resolve(null);
|
|
223
|
+
};
|
|
224
|
+
const click = (event) => {
|
|
225
|
+
event.preventDefault();
|
|
226
|
+
event.stopPropagation();
|
|
227
|
+
const element = document.elementFromPoint(event.clientX, event.clientY);
|
|
228
|
+
const result = element ? metadata(element) : null;
|
|
229
|
+
cleanup();
|
|
230
|
+
overlay.remove();
|
|
231
|
+
resolve(result);
|
|
232
|
+
};
|
|
233
|
+
const keydown = (event) => {
|
|
234
|
+
if (event.key !== 'Escape') return;
|
|
235
|
+
cancel();
|
|
236
|
+
};
|
|
237
|
+
window.__openchamberDesktopBrowserCancelInspect = cancel;
|
|
238
|
+
window.addEventListener('mousemove', move, true);
|
|
239
|
+
window.addEventListener('click', click, true);
|
|
240
|
+
window.addEventListener('keydown', keydown, true);
|
|
241
|
+
});`,mc=`(() => {
|
|
242
|
+
if (typeof window.__openchamberDesktopBrowserCancelInspect === 'function') {
|
|
243
|
+
window.__openchamberDesktopBrowserCancelInspect();
|
|
244
|
+
return;
|
|
245
|
+
}
|
|
246
|
+
const overlay = document.getElementById('__openchamber_desktop_browser_overlay');
|
|
247
|
+
if (overlay) overlay.remove();
|
|
248
|
+
})()`,hc=`(() => {
|
|
249
|
+
if (window.__openchamberSameWebviewNavigationInstalled) return;
|
|
250
|
+
window.__openchamberSameWebviewNavigationInstalled = true;
|
|
251
|
+
|
|
252
|
+
const navigate = (rawUrl) => {
|
|
253
|
+
if (typeof rawUrl !== 'string' || rawUrl.length === 0) return false;
|
|
254
|
+
try {
|
|
255
|
+
const url = new URL(rawUrl, window.location.href);
|
|
256
|
+
if (url.protocol !== 'http:' && url.protocol !== 'https:') return false;
|
|
257
|
+
window.location.assign(url.href);
|
|
258
|
+
return true;
|
|
259
|
+
} catch (_error) {
|
|
260
|
+
return false;
|
|
261
|
+
}
|
|
262
|
+
};
|
|
263
|
+
|
|
264
|
+
const originalOpen = window.open.bind(window);
|
|
265
|
+
window.open = (url, target, features) => {
|
|
266
|
+
if (navigate(url)) return null;
|
|
267
|
+
return originalOpen(url, target, features);
|
|
268
|
+
};
|
|
269
|
+
|
|
270
|
+
document.addEventListener('click', (event) => {
|
|
271
|
+
if (event.defaultPrevented) return;
|
|
272
|
+
const target = event.target;
|
|
273
|
+
if (!(target instanceof Element)) return;
|
|
274
|
+
const anchor = target.closest('a[target="_blank"][href]');
|
|
275
|
+
if (!(anchor instanceof HTMLAnchorElement)) return;
|
|
276
|
+
if (!navigate(anchor.href)) return;
|
|
277
|
+
event.preventDefault();
|
|
278
|
+
event.stopPropagation();
|
|
279
|
+
}, true);
|
|
280
|
+
})()`,gc=e=>{let t=e.trim();if(!t)return`about:blank`;try{let e=new URL(t.includes(`://`)?t:`https://${t}`);return e.protocol!==`http:`&&e.protocol!==`https:`?`about:blank`:e.toString()}catch{return`about:blank`}},_c=async(e,t)=>{let n=e.contentWindow;if(!n)throw Error(`Iframe window is not available`);let r=n.eval.call(n,t);return await Promise.resolve(r)},vc=(e,t)=>e.length<=t?e:`${e.slice(0,t-3)}...`,yc=e=>{if(typeof window>`u`)return``;try{return new URL(e||window.location.href,window.location.href).origin}catch{return window.location.origin}},bc=(e,t,n)=>{let r=yc(t);e.postMessage(n,r)},xc=e=>{if(!e)return e;try{let t=new URL(e);return t.searchParams.delete(`oc_preview_token`),t.searchParams.delete(`oc_client_token`),t.searchParams.delete(`oc_url_token`),t.toString()}catch{return e}},Sc=e=>{if(!e)return e;try{let t=new URL(e);return t.searchParams.delete(`ocPreview`),t.searchParams.delete(`oc_preview_token`),t.searchParams.delete(`oc_client_token`),t.searchParams.delete(`oc_url_token`),t.toString()}catch{return e}},Cc=({rawUrl:e,onNavigate:n})=>{let{t:r}=ee(),{currentTheme:i}=Ne(),[o,c]=Q.useReducer(e=>e+1,0),[l,u]=Q.useReducer(e=>e+1,0),[d,f]=Q.useState({status:`idle`}),[p,m]=Q.useState(``),h=Q.useRef(null),g=Q.useRef(1),[v,y]=Q.useState(!1),[b,x]=Q.useState(!1),[S,C]=Q.useState(`all`),[w,T]=Q.useState([]),[E,D]=Q.useState(!1),[O,k]=Q.useState(null),A=ue(e=>e.currentSessionId),j=ue(e=>e.newSessionDraft?.open),M=lt(e=>e.addDraft),N=re(e=>e.addAttachedFile),P=null;try{P=e?new URL(e):null}catch{P=null}let F=P?P.hostname===`localhost`||P.hostname===`127.0.0.1`||P.hostname===`::1`||P.hostname===`[::1]`||P.hostname===`0.0.0.0`:!1,I=P?P.hostname===`0.0.0.0`?new URL(P.toString().replace(`0.0.0.0`,`127.0.0.1`)):P:null,ne=I?I.toString():``,L=ne?`${t()||`same-origin`}|${ne}`:``,ie=i.metadata.variant;Q.useEffect(()=>{if(!ne||!F){f({status:`idle`});return}let e=xs(L);if(e?.previewToken){f({status:`ready`,proxyBasePath:e.proxyBasePath,previewToken:e.previewToken,expiresAt:e.expiresAt});return}e&&vs.delete(L);let t=!1;return f({status:`loading`}),(async()=>{try{let e=await _(`/api/preview/targets`,{method:`POST`,headers:{"Content-Type":`application/json`},credentials:`include`,body:JSON.stringify({url:ne})});if(!e.ok){vs.delete(L);let n=await e.json().catch(()=>({})),r=typeof n?.error==`string`?n.error:`HTTP ${e.status}`;t||f({status:`error`,message:r});return}let n=await e.json(),i=typeof n.proxyBasePath==`string`?n.proxyBasePath:``,a=typeof n.previewToken==`string`?n.previewToken:``,o=typeof n.expiresAt==`number`?n.expiresAt:0;if(!i||!a){vs.delete(L),t||f({status:`error`,message:r(`contextPanel.preview.proxyError`)});return}vs.set(L,{proxyBasePath:i,previewToken:a,expiresAt:o}),t||f({status:`ready`,proxyBasePath:i,previewToken:a,expiresAt:o})}catch(e){if(vs.delete(L),!t){let t=e instanceof Error?e.message:String(e);f({status:`error`,message:t})}}})(),()=>{t=!0}},[F,L,l,r,ne]);let R=I&&(I.protocol===`http:`||I.protocol===`https:`)?I.toString():``,ae=F&&d.status===`ready`?`${d.proxyBasePath}|${d.previewToken||``}|${o}`:``;Q.useEffect(()=>{if(!ae){m(``);return}let e=!1;return m(``),s(t()).then(t=>{!e&&t&&m(ae)}).catch(()=>{}),()=>{e=!0}},[ae]);let z=F&&d.status===`ready`&&I&&p===ae?(()=>{let e=I.pathname||`/`,t=new URLSearchParams(I.search);t.delete(`oc_url_token`),t.delete(`oc_client_token`),t.set(`ocPreview`,String(o)),t.set(`oc_preview_token`,d.previewToken||``);let n=t.toString(),r=I.hash||``;return a().authenticatedAsset(`${d.proxyBasePath}${e}${n?`?${n}`:``}${r}`)})():``,B=F?z:R,V=F?xc(z):R,oe=F&&(d.status===`loading`||d.status===`idle`||p!==ae),se=F&&d.status===`error`,H=Q.useCallback(t=>{let n=A??(j?`draft`:null);if(!n){G.error(r(`contextPanel.preview.inspect.attachNoSession`));return}let i=e||B||``,a=typeof window<`u`?{width:window.innerWidth,height:window.innerHeight}:{width:0,height:0},o=typeof window<`u`?window.devicePixelRatio:1;(async()=>{let e=!1;try{let n=h.current,r=n?await hs(n,t):null;r&&(await N(r),e=!0)}catch{e=!1}M({sessionKey:n,source:`preview-annotation`,fileLabel:i||`preview`,startLine:1,endLine:1,code:ms({pageUrl:i,viewport:a,devicePixelRatio:o,target:t,screenshotAttached:e,intro:r(`contextPanel.preview.inspect.attachAnnotation`)}),language:`markdown`,text:``}),G.success(r(`contextPanel.preview.inspect.attached`))})()},[N,M,A,B,j,e,r]);Q.useEffect(()=>{y(!1),T([]),x(!1),C(`all`),D(!1),k(null),g.current=1},[B]),Q.useEffect(()=>{let e=h.current?.contentWindow;!v||!e||bc(e,z,{source:`openchamber-preview-parent`,version:1,type:`set-inspect-mode`,enabled:E})},[v,E,z]),Q.useEffect(()=>{let e=h.current?.contentWindow;!v||!e||bc(e,z,{source:`openchamber-preview-parent`,version:1,type:`set-color-scheme`,scheme:ie})},[v,ie,z]),Q.useEffect(()=>{if(!E||typeof window>`u`)return;let e=e=>{e.key===`Escape`&&(e.preventDefault(),e.stopImmediatePropagation(),D(!1))};return window.addEventListener(`keydown`,e,!0),()=>window.removeEventListener(`keydown`,e,!0)},[E]),Q.useEffect(()=>{if(!F||typeof window>`u`)return;let e=e=>{if(typeof e==`string`)return e;if(e==null)return``;try{return JSON.stringify(e)}catch{return String(e)}},t=e=>{let t=g.current;g.current+=1,T(n=>{let r=[...n,{...e,id:t}];return r.length>Qs?r.slice(r.length-Qs):r})},i=i=>{if(i.source!==h.current?.contentWindow)return;let a=i.data;if(!(!a||a.source!==`openchamber-preview-bridge`||a.version!==1)){if(a.type===`ready`){y(!0);return}if(a.type===`console`){let n=a.level===`error`||a.level===`warn`||a.level===`info`||a.level===`debug`?a.level:`log`,r=Array.isArray(a.args)?a.args.map(e).filter(Boolean):[];t({level:n,message:r.join(` `),ts:typeof a.ts==`number`?a.ts:Date.now()});return}if(a.type===`runtime-error`){let n=e(a.filename),i=typeof a.line==`number`?a.line:null,o=typeof a.column==`number`?a.column:null,s=n?`${n}${i===null?``:`:${i}${o===null?``:`:${o}`}`}`:``,c=e(a.stack);t({level:`runtime`,message:e(a.message)||r(`contextPanel.preview.console.runtimeError`),details:[s,c].filter(Boolean).join(`
|
|
281
|
+
`),ts:typeof a.ts==`number`?a.ts:Date.now()});return}if(a.type===`resource-error`){let n=e(a.tag)||`resource`,r=e(a.url);t({level:`resource`,message:r?`${n}: ${r}`:n,details:e(a.outerHTML),ts:typeof a.ts==`number`?a.ts:Date.now()});return}if(a.type===`hover`){k(ps(a.target)?a.target:null);return}if(a.type===`select`&&ps(a.target)){k(a.target),D(!1),H(a.target);return}if(a.type===`navigate-preview`){let e=typeof a.url==`string`?a.url:``,t=a.navigation===`external`?`external`:`proxy`;if(e&&t===`external`){It(e);return}e&&n(e)}}};return window.addEventListener(`message`,i),()=>{window.removeEventListener(`message`,i)}},[H,F,n,r]);let U=w.filter(e=>e.level===`error`||e.level===`runtime`||e.level===`resource`).length,W=w.filter(e=>$s(e,S)),K=Q.useCallback(()=>{let t=[`Preview URL: ${e||B||``}`,`Events: ${w.length}`,``].join(`
|
|
282
|
+
`),n=w.map(e=>{let t=new Date(e.ts).toISOString(),n=e.details?`\n${e.details}`:``;return`[${t}] [${e.level}] ${e.message}${n}`}).join(`
|
|
283
|
+
`);te(`${t}${n}`).then(e=>{e.ok?G.success(r(`contextPanel.preview.console.copied`)):G.error(r(`contextPanel.preview.console.copyFailed`))})},[w,B,e,r]),ce=Q.useCallback(()=>{let t=A??(j?`draft`:null);if(!t){G.error(r(`contextPanel.preview.console.attachNoSession`));return}let n=[`Preview URL: ${e||B||``}`,`Events: ${w.length}`,``].join(`
|
|
284
|
+
`),i=w.map(e=>{let t=new Date(e.ts).toISOString(),n=e.details?`\n${e.details}`:``;return`[${t}] [${e.level}] ${e.message}${n}`}).join(`
|
|
285
|
+
`);M({sessionKey:t,source:`preview-console`,fileLabel:e||B||`preview`,startLine:1,endLine:Math.max(1,w.length),code:`${n}${i}`,language:`text`,text:r(`contextPanel.preview.console.attachAnnotation`)}),G.success(r(`contextPanel.preview.console.attached`))},[M,w,A,B,j,e,r]),[le,q]=Q.useState(`unknown`),de=Q.useRef(0),fe=Q.useRef(0);Q.useEffect(()=>{if(!z){q(`unknown`),de.current=0,fe.current=0;return}let e=!1;return de.current||(de.current=Date.now(),fe.current=0),q(`unknown`),(async()=>{let t=await(async()=>{try{return await _(z,{method:`GET`,credentials:`include`,cache:`no-store`,redirect:`manual`})}catch{return null}})();if(e)return;if(!t){q(`unreachable`);return}if(t.status===403||t.status===404){vs.delete(L),f({status:`loading`}),u();return}if(t.status!==502){q(`reachable`);return}let n=de.current||Date.now();if(Date.now()-n<15e3){q(`starting`),fe.current+=1;let t=fe.current,n=Math.min(2e3,250*2**Math.min(4,t));setTimeout(()=>{e||c()},n).unref?.();return}q(`unreachable`)})(),()=>{e=!0}},[L,z,o]);let pe=F&&d.status===`ready`&&(le===`unknown`||le===`starting`),me=F&&d.status===`ready`&&le===`unreachable`,he=Q.useCallback(e=>{if(!F||d.status!==`ready`||typeof window>`u`)return;let t=e.currentTarget.contentWindow;if(t)try{let e=t.location,n=yc(z);if(e.origin!==n||e.pathname.startsWith(d.proxyBasePath))return;let r=`${d.proxyBasePath}${e.pathname}${e.search}${e.hash}`;t.location.replace(r)}catch{}},[F,z,d]);return(0,$.jsxs)(`div`,{className:`absolute inset-0 flex flex-col`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-1 border-b border-border/40 bg-[var(--surface-background)] px-2 py-1`,children:[(0,$.jsx)(`div`,{className:`min-w-0 flex-1 truncate typography-micro text-muted-foreground`,title:V||e,children:V||e||r(`contextPanel.preview.empty`)}),(0,$.jsx)(X,{type:`button`,size:`sm`,variant:`ghost`,className:`h-7 w-7 p-0`,onClick:()=>c(),title:r(`contextPanel.preview.actions.reload`),"aria-label":r(`contextPanel.preview.actions.reload`),disabled:!B,children:(0,$.jsx)(Y,{name:`refresh`,className:`h-3.5 w-3.5`})}),(0,$.jsx)(X,{type:`button`,size:`sm`,variant:`ghost`,className:`h-7 w-7 p-0`,onClick:()=>{R&&It(R)},title:r(`contextPanel.preview.actions.openExternal`),"aria-label":r(`contextPanel.preview.actions.openExternal`),disabled:!R,children:(0,$.jsx)(Y,{name:`external-link`,className:`h-3.5 w-3.5`})}),F?(0,$.jsx)(X,{type:`button`,size:`sm`,variant:E?`secondary`:`ghost`,className:`h-7 gap-1 px-2`,onClick:()=>D(e=>!e),title:r(`contextPanel.preview.inspect.toggle`),"aria-label":r(`contextPanel.preview.inspect.toggle`),disabled:!v,children:(0,$.jsx)(Y,{name:`cursor`,className:`h-3.5 w-3.5`})}):null,F?(0,$.jsxs)(X,{type:`button`,size:`sm`,variant:b?`secondary`:`ghost`,className:`h-7 gap-1 px-2`,onClick:()=>x(e=>!e),title:r(v?`contextPanel.preview.console.open`:`contextPanel.preview.console.waiting`),"aria-label":r(v?`contextPanel.preview.console.open`:`contextPanel.preview.console.waiting`),disabled:!v&&w.length===0,children:[(0,$.jsx)(Y,{name:`terminal-box`,className:`h-3.5 w-3.5`}),U>0?(0,$.jsx)(`span`,{className:`typography-micro text-status-error`,children:U}):null]}):null]}),(0,$.jsxs)(`div`,{className:`relative min-h-0 flex-1 bg-background`,children:[pe?(0,$.jsxs)(`div`,{className:`flex h-full flex-col items-center justify-center gap-3 px-6 text-center text-sm text-muted-foreground`,children:[(0,$.jsx)(`div`,{children:r(`contextPanel.preview.startingServer`)}),(0,$.jsx)(`div`,{className:`text-xs opacity-70`,children:r(`contextPanel.preview.startingServerHint`)})]}):me?(0,$.jsxs)(`div`,{className:`flex h-full flex-col items-center justify-center gap-3 px-6 text-center text-sm text-muted-foreground`,children:[(0,$.jsx)(`div`,{children:r(`contextPanel.preview.upstreamUnreachable`)}),(0,$.jsx)(`div`,{className:`text-xs opacity-70`,children:r(`contextPanel.preview.upstreamUnreachableHint`)}),(0,$.jsx)(X,{type:`button`,size:`sm`,variant:`outline`,onClick:()=>c(),children:r(`contextPanel.preview.actions.retry`)})]}):B&&(!F||le===`reachable`)?(0,$.jsxs)(`div`,{className:`relative h-full w-full`,children:[(0,$.jsx)(`iframe`,{ref:h,src:B,title:r(`contextPanel.preview.iframeTitle`),className:`h-full w-full border-0`,style:{colorScheme:ie},onLoad:he,sandbox:F?`allow-scripts allow-same-origin allow-forms allow-popups allow-downloads`:`allow-scripts allow-forms`},`${B}:${o}`),E&&O?(0,$.jsx)(`div`,{className:`pointer-events-none absolute rounded-sm border-2 border-[var(--interactive-focus-ring)] bg-[var(--interactive-focus-ring)]/35`,style:{left:O.bounds.x,top:O.bounds.y,width:O.bounds.width,height:O.bounds.height},children:(0,$.jsxs)(`div`,{className:`absolute -top-6 left-0 max-w-64 truncate rounded bg-[var(--surface-elevated)] px-2 py-0.5 typography-micro text-foreground shadow`,children:[O.tag,O.text?` · ${O.text}`:``]})}):null]}):oe?(0,$.jsx)(`div`,{className:`flex h-full items-center justify-center px-6 text-sm text-muted-foreground`,children:r(`contextPanel.preview.loading`)}):se?(0,$.jsxs)(`div`,{className:`flex h-full flex-col items-center justify-center gap-2 px-6 text-sm text-muted-foreground`,children:[(0,$.jsx)(`div`,{children:r(`contextPanel.preview.proxyError`)}),d.status===`error`?(0,$.jsx)(`div`,{className:`text-center text-xs opacity-70`,children:d.message}):null]}):(0,$.jsx)(`div`,{className:`flex h-full items-center justify-center px-6 text-sm text-muted-foreground`,children:r(`contextPanel.preview.invalidUrl`)}),b?(0,$.jsxs)(`div`,{className:`absolute inset-x-3 bottom-3 z-10 max-h-[45%] overflow-hidden rounded-xl border border-border/70 bg-[var(--surface-elevated)] shadow-lg`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between border-b border-border/50 px-3 py-2`,children:[(0,$.jsx)(`div`,{className:`typography-ui-label text-foreground`,children:r(`contextPanel.preview.console.title`)}),(0,$.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,$.jsx)(X,{type:`button`,size:`xs`,variant:`ghost`,onClick:ce,disabled:w.length===0,children:r(`contextPanel.preview.console.attach`)}),(0,$.jsx)(X,{type:`button`,size:`xs`,variant:`ghost`,onClick:K,disabled:w.length===0,children:r(`contextPanel.preview.console.copy`)}),(0,$.jsx)(X,{type:`button`,size:`xs`,variant:`ghost`,onClick:()=>T([]),disabled:w.length===0,children:r(`contextPanel.preview.console.clear`)})]})]}),(0,$.jsx)(`div`,{className:`flex items-center gap-1 border-b border-border/30 px-3 py-1.5`,children:[`all`,`errors`,`warnings`,`logs`].map(e=>(0,$.jsx)(X,{type:`button`,size:`xs`,variant:S===e?`secondary`:`ghost`,onClick:()=>C(e),children:r(e===`all`?`contextPanel.preview.console.filter.all`:e===`errors`?`contextPanel.preview.console.filter.errors`:e===`warnings`?`contextPanel.preview.console.filter.warnings`:`contextPanel.preview.console.filter.logs`)},e))}),(0,$.jsx)(`div`,{className:`max-h-64 overflow-auto p-2 typography-code text-xs`,children:w.length===0?(0,$.jsx)(`div`,{className:`px-2 py-3 text-muted-foreground`,children:r(`contextPanel.preview.console.empty`)}):W.length===0?(0,$.jsx)(`div`,{className:`px-2 py-3 text-muted-foreground`,children:r(`contextPanel.preview.console.noFilteredEvents`)}):W.map(e=>(0,$.jsx)(`div`,{className:`border-b border-border/30 px-2 py-1 last:border-b-0`,children:(0,$.jsxs)(`div`,{className:`flex gap-2`,children:[(0,$.jsx)(`span`,{className:J(`shrink-0 uppercase`,e.level===`error`||e.level===`runtime`||e.level===`resource`?`text-status-error`:e.level===`warn`?`text-status-warning`:`text-muted-foreground`),children:e.level}),(0,$.jsx)(`span`,{className:`min-w-0 break-words text-foreground`,children:e.message})]})},e.id))})]}):null]})]})},wc=()=>typeof window<`u`&&!!window.__OPENCHAMBER_ELECTRON__,Tc=({initialUrl:e,directory:n,tabID:r})=>{let{t:i}=ee(),o=Q.useRef(null),l=c(e=>e.setContextPanelTabTargetPath),u=gc(e),d=u===`about:blank`?``:u,[f,p]=Q.useState(d),[m,h]=Q.useState(d),[g,v]=Q.useState(d),[y,b]=Q.useState(()=>d?[d]:[]),[x,S]=Q.useState(()=>d?0:-1),[C,w]=Q.useReducer(e=>e+1,0),[T,E]=Q.useState(!!d),[D,O]=Q.useState(!1),[k,A]=Q.useState(null),[j,M]=Q.useState({status:`idle`}),[N,P]=Q.useState(``),F=ue(e=>e.currentSessionId),I=ue(e=>e.newSessionDraft?.open),te=lt(e=>e.addDraft),ne=re(e=>e.addAttachedFile),L=Q.useCallback(e=>{!e||e===`about:blank`||!n||!r||l(n,r,e)},[n,r,l]),ie=Q.useCallback((e,t)=>{let n=gc(e),r=n===`about:blank`?``:n;h(r),p(r),t?.inFrame?E(!1):(v(r),E(!!r)),L(r),b(e=>{if(!r)return S(-1),[];if(t?.replaceHistory)return e;let n=x>=0?e.slice(0,x+1):[];if(n[n.length-1]===r)return S(n.length-1),n;let i=[...n,r];return S(i.length-1),i})},[x,L]),R=Q.useCallback(e=>{let t=y[e];t&&(S(e),h(t),v(t),p(t),E(!0),L(t))},[y,L]),ae=Q.useCallback(()=>{if(m){E(!0);try{o.current?.contentWindow?.location.reload()}catch{w()}}},[m]);Q.useEffect(()=>{if(!g){M({status:`idle`});return}let e=Ss(g),t=xs(e);if(t?.previewToken){M({status:`ready`,proxyBasePath:t.proxyBasePath,previewToken:t.previewToken,expiresAt:t.expiresAt});return}t&&vs.delete(e);let n=!1;return M({status:`loading`}),E(!0),(async()=>{try{let t=await _(`/api/preview/targets`,{method:`POST`,headers:{"Content-Type":`application/json`},credentials:`include`,body:JSON.stringify({url:g,allowExternal:!0})});if(!t.ok){let e=await t.json().catch(()=>({})),r=typeof e?.error==`string`?e.error:`HTTP ${t.status}`;n||M({status:`error`,message:r});return}let r=await t.json(),a=typeof r.proxyBasePath==`string`?r.proxyBasePath:``,o=typeof r.previewToken==`string`?r.previewToken:``,s=typeof r.expiresAt==`number`?r.expiresAt:0;if(!a||!o){n||M({status:`error`,message:i(`contextPanel.preview.proxyError`)});return}vs.set(e,{proxyBasePath:a,previewToken:o,expiresAt:s}),n||M({status:`ready`,proxyBasePath:a,previewToken:o,expiresAt:s})}catch(e){if(!n){let t=e instanceof Error?e.message:String(e);M({status:`error`,message:t})}}})(),()=>{n=!0}},[g,i]);let z=g&&j.status===`ready`?`${j.proxyBasePath}|${j.previewToken||``}|${C}`:``;Q.useEffect(()=>{if(!z){P(``);return}let e=!1;return P(``),s(t()).then(t=>{!e&&t&&P(z)}).catch(()=>{}),()=>{e=!0}},[z]);let B=Q.useMemo(()=>{if(N!==z||!g||j.status!==`ready`)return``;try{let e=new URL(g),t=e.pathname||`/`,n=new URLSearchParams(e.search);n.delete(`oc_url_token`),n.delete(`oc_client_token`),n.set(`ocPreview`,String(C)),n.set(`oc_preview_token`,j.previewToken||``);let r=n.toString();return a().authenticatedAsset(`${j.proxyBasePath}${t}${r?`?${r}`:``}${e.hash}`)}catch{return``}},[g,j,z,C,N]),V=B||(j.status===`error`?g:``),oe=Q.useCallback(e=>{if(!e||!g||j.status!==`ready`)return``;try{let t=new URL(e,window.location.origin),n=j.proxyBasePath.endsWith(`/`)?j.proxyBasePath.slice(0,-1):j.proxyBasePath;if(t.origin!==window.location.origin||!t.pathname.startsWith(n))return``;let r=t.pathname.slice(n.length)||`/`,i=new URL(g).origin;return Sc(new URL(`${r}${t.search}${t.hash}`,i).toString())}catch{return``}},[g,j]),se=Q.useCallback(e=>{if(!e||!g||j.status!==`ready`)return``;try{let t=new URL(e,window.location.origin),n=new URL(g).origin;if(t.origin!==window.location.origin||n===window.location.origin)return``;let r=j.proxyBasePath.endsWith(`/`)?j.proxyBasePath.slice(0,-1):j.proxyBasePath;return t.pathname.startsWith(r)?``:Sc(new URL(`${t.pathname}${t.search}${t.hash}`,n).toString())}catch{return``}},[g,j]),H=Q.useCallback(e=>{let t=o.current?.contentWindow;t&&t.postMessage({source:`openchamber-preview-parent`,version:1,type:`set-inspect-mode`,enabled:e},window.location.origin)},[]),U=Q.useCallback(async e=>{let t=F??(I?`draft`:null);if(!t){G.error(i(`contextPanel.preview.inspect.attachNoSession`));return}let n=o.current,r=n?.contentWindow,a=n?.getBoundingClientRect(),s={width:Number.isFinite(r?.innerWidth)?r?.innerWidth??a?.width??0:a?.width??0,height:Number.isFinite(r?.innerHeight)?r?.innerHeight??a?.height??0:a?.height??0},c=n?await hs(n,e):null,l=!!c;c&&await ne(c),te({sessionKey:t,source:`preview-annotation`,fileLabel:m||`browser`,startLine:1,endLine:1,code:ms({pageUrl:m,viewport:s,devicePixelRatio:window.devicePixelRatio||1,target:e,screenshotAttached:l,intro:i(l?`contextPanel.preview.inspect.attachAnnotationWithScreenshot`:`contextPanel.preview.inspect.attachAnnotation`)}),language:`markdown`,text:``}),G.success(i(`contextPanel.preview.inspect.attached`))},[ne,te,F,m,I,i]),W=Q.useCallback(()=>{let e=o.current;A(null),H(!1),e&&_c(e,mc).catch(()=>{})},[H]);Q.useEffect(()=>{if(!D)return;let e=e=>{e.key===`Escape`&&(e.preventDefault(),e.stopImmediatePropagation(),O(!1),W())};return window.addEventListener(`keydown`,e,!0),()=>window.removeEventListener(`keydown`,e,!0)},[W,D]),Q.useEffect(()=>()=>W(),[W]),Q.useEffect(()=>{let e=e=>{if(e.source!==o.current?.contentWindow)return;let t=e.data;if(!(!t||t.source!==`openchamber-preview-bridge`||t.version!==1)){if(t.type===`ready`){let e=typeof t.url==`string`?t.url:``,n=oe(e);n&&n!==m&&ie(n,{inFrame:!0});return}if(t.type===`hover`){A(ps(t.target)?t.target:null);return}if(t.type===`select`&&ps(t.target)){A(null),O(!1),H(!1),U(t.target);return}if(t.type===`navigate-preview`){let e=typeof t.url==`string`?t.url:``,n=se(e);if(n){ie(n);return}e&&ie(e)}}};return window.addEventListener(`message`,e),()=>window.removeEventListener(`message`,e)},[ie,U,m,oe,se,H]);let K=Q.useCallback(()=>{let e=o.current;if(!(!e||!m)){if(D){O(!1),W();return}if(B){A(null),O(!0),H(!0);return}O(!0),(async()=>{try{let t=await _c(e,pc);if(O(!1),!t||!ps(t))return;await U(t)}catch{O(!1),G.error(i(`contextPanel.browser.inspectUnavailable`))}})()}},[U,W,m,D,H,B,i]),ce=Q.useCallback(()=>{try{let e=o.current?.contentWindow?.location.href||``,t=se(e);if(t){ie(t,{inFrame:!0});return}}catch{}E(!1),D&&B&&H(!0)},[ie,se,D,H,B]);return(0,$.jsxs)(`div`,{className:`absolute inset-0 flex flex-col bg-background`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-1 border-b border-border/40 bg-[var(--surface-background)] px-2 py-1`,children:[(0,$.jsx)(X,{type:`button`,variant:`ghost`,size:`sm`,className:`h-7 w-7 p-0`,disabled:x<=0,onClick:()=>R(x-1),children:(0,$.jsx)(Y,{name:`arrow-left`,className:`h-3.5 w-3.5`})}),(0,$.jsx)(X,{type:`button`,variant:`ghost`,size:`sm`,className:`h-7 w-7 p-0`,disabled:x<0||x>=y.length-1,onClick:()=>R(x+1),children:(0,$.jsx)(Y,{name:`arrow-right`,className:`h-3.5 w-3.5`})}),(0,$.jsx)(X,{type:`button`,variant:`ghost`,size:`sm`,className:`h-7 w-7 p-0`,disabled:!m,onClick:ae,children:(0,$.jsx)(Y,{name:`refresh`,className:`h-3.5 w-3.5`})}),(0,$.jsx)(`form`,{className:`min-w-0 flex-1`,onSubmit:e=>{e.preventDefault(),ie(f)},children:(0,$.jsx)(`input`,{value:f,onChange:e=>p(e.target.value),className:`h-7 w-full rounded-md border border-border/50 bg-[var(--surface-elevated)] px-2 typography-micro text-foreground outline-none focus:border-[var(--interactive-focus-ring)]`,"aria-label":i(`contextPanel.browser.addressAria`)})}),(0,$.jsx)(X,{type:`button`,variant:D?`secondary`:`ghost`,size:`sm`,className:`h-7 w-7 p-0`,disabled:!m,onClick:K,title:i(`contextPanel.preview.inspect.toggle`),"aria-label":i(`contextPanel.preview.inspect.toggle`),children:(0,$.jsx)(Y,{name:`cursor`,className:`h-3.5 w-3.5`})}),(0,$.jsx)(X,{type:`button`,variant:`ghost`,size:`sm`,className:`h-7 w-7 p-0`,disabled:!m,onClick:()=>void It(m),children:(0,$.jsx)(Y,{name:`external-link`,className:`h-3.5 w-3.5`})})]}),(0,$.jsxs)(`div`,{className:`relative min-h-0 flex-1 bg-background`,children:[V?(0,$.jsxs)(`div`,{className:`absolute inset-0`,children:[(0,$.jsx)(`iframe`,{ref:o,src:V,title:i(`contextPanel.browser.empty`),className:`absolute inset-0 h-full w-full border-0 bg-background`,allow:`clipboard-read; clipboard-write; fullscreen`,allowFullScreen:!0,onLoad:ce},`${r}:${C}`),D&&k?(0,$.jsx)(`div`,{className:`pointer-events-none absolute rounded-sm border-2 border-[var(--interactive-focus-ring)] bg-[var(--interactive-focus-ring)]/35`,style:{left:k.bounds.x,top:k.bounds.y,width:k.bounds.width,height:k.bounds.height},children:(0,$.jsxs)(`div`,{className:`absolute -top-6 left-0 max-w-64 truncate rounded bg-[var(--surface-elevated)] px-2 py-0.5 typography-micro text-foreground shadow`,children:[k.tag,k.text?` · ${k.text}`:``]})}):null]}):(0,$.jsxs)(`div`,{className:`absolute inset-0 flex flex-col items-center justify-center gap-6 bg-background p-6 text-center`,children:[(0,$.jsx)(Le,{width:140,height:140,className:`opacity-20`}),(0,$.jsx)(`span`,{className:`typography-ui-header text-muted-foreground`,children:i(`contextPanel.browser.empty`)}),(0,$.jsx)(`span`,{className:`max-w-sm typography-micro text-muted-foreground`,children:i(`contextPanel.browser.emptyHint`)}),(0,$.jsx)(`span`,{className:`max-w-md typography-micro leading-relaxed text-status-warning/70`,children:i(`contextPanel.browser.trustNotice`)})]}),T?(0,$.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center bg-background/70 typography-micro text-muted-foreground`,children:i(`common.loading`)}):null]})]})},Ec=({initialUrl:e,directory:t,tabID:n})=>{let{t:r}=ee(),i=Q.useRef(null),a=c(e=>e.setContextPanelTabTargetPath),o=gc(e),s=o===`about:blank`?``:o,l=Q.useRef(gc(e)),[u,d]=Q.useState(s),[f,p]=Q.useState(s),[m,h]=Q.useState(!1),[g,_]=Q.useState(!0),v=Q.useRef(null),y=g,b=Q.useCallback(e=>{!e||e===`about:blank`||!t||!n||a(t,n,e)},[t,n,a]),x=ue(e=>e.currentSessionId),S=ue(e=>e.newSessionDraft?.open),C=lt(e=>e.addDraft),w=re(e=>e.addAttachedFile);Q.useEffect(()=>{let e=i.current;if(!e)return;let t=()=>{try{let t=e.getURL();t&&t!==`about:blank`&&(p(t),d(t),b(t))}catch{}},n=e=>{let t=e.detail;typeof t?.url==`string`&&t.url&&(p(t.url),d(t.url),b(t.url))},r=()=>{v.current&&clearTimeout(v.current),v.current=setTimeout(()=>_(!0),200)},a=()=>{v.current&&clearTimeout(v.current),_(!1),t()},o=e=>{let t=e.detail;if(t?.disposition===`new-window`||t?.disposition===`foreground-tab`||t?.disposition===`background-tab`){e.preventDefault();let n=i.current;typeof n?.loadURL==`function`&&t.url&&n.loadURL(t.url)}},s=()=>{try{e.executeJavaScript?.(hc,!0).catch(()=>{})}catch{}};e.addEventListener(`did-navigate`,n),e.addEventListener(`did-navigate-in-page`,n),e.addEventListener(`did-start-loading`,r),e.addEventListener(`did-stop-loading`,a),e.addEventListener(`new-window`,o),e.addEventListener(`dom-ready`,s);try{e.isLoading()||(_(!1),t())}catch{}return s(),()=>{v.current&&clearTimeout(v.current),e.removeEventListener(`did-navigate`,n),e.removeEventListener(`did-navigate-in-page`,n),e.removeEventListener(`did-start-loading`,r),e.removeEventListener(`did-stop-loading`,a),e.removeEventListener(`new-window`,o),e.removeEventListener(`dom-ready`,s)}},[b]),Q.useEffect(()=>{let e=setTimeout(()=>_(!1),3e4);return()=>clearTimeout(e)},[]),Q.useEffect(()=>{if(!m)return;let e=e=>{if(e.key!==`Escape`)return;e.preventDefault(),e.stopImmediatePropagation(),h(!1);let t=i.current;try{t?.executeJavaScript?.(mc).catch(()=>{})}catch{}};return window.addEventListener(`keydown`,e,!0),()=>window.removeEventListener(`keydown`,e,!0)},[m]),Q.useEffect(()=>{let e=i.current;return()=>{try{let r=e?.getURL?.();r&&r!==`about:blank`&&a(t,n,r)}catch{}try{e?.executeJavaScript?.(mc).catch(()=>{})}catch{}}},[t,n,a]);let T=Q.useCallback(e=>{let t=i.current;if(typeof t?.loadURL!=`function`)return;let n=gc(e);try{t.loadURL(n)}catch{}},[]),E=Q.useCallback(()=>{let e=i.current;if(e){if(m){h(!1);try{e.executeJavaScript?.(mc).catch(()=>{})}catch{}return}h(!0),e.executeJavaScript?.(pc,!0).then(async t=>{if(h(!1),!t||!ps(t))return;let n=x??(S?`draft`:null);if(!n){G.error(r(`contextPanel.preview.inspect.attachNoSession`));return}let i=typeof e.getWebContentsId==`function`?e.getWebContentsId():null;if(i==null)return;let a=await F(`desktop_browser_capture_page`,{webContentsId:i}),o=await e.executeJavaScript?.(`({ width: window.innerWidth, height: window.innerHeight })`,!0).catch(()=>null),s=Number.isFinite(o?.width)?o.width:a.width,c=Number.isFinite(o?.height)?o.height:a.height,l=await gs(a.base64,a.width,a.height,s,c,t),u=!!l;l&&await w(l),C({sessionKey:n,source:`preview-annotation`,fileLabel:f||`browser`,startLine:1,endLine:1,code:ms({pageUrl:f,viewport:{width:s,height:c},devicePixelRatio:window.devicePixelRatio||1,target:t,screenshotAttached:u,intro:r(`contextPanel.preview.inspect.attachAnnotationWithScreenshot`)}),language:`markdown`,text:``}),G.success(r(`contextPanel.preview.inspect.attached`))}).catch(()=>h(!1))}},[w,C,x,f,m,S,r]);return(0,$.jsxs)(`div`,{className:`absolute inset-0 flex flex-col bg-background`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-1 border-b border-border/40 bg-[var(--surface-background)] px-2 py-1`,children:[(0,$.jsx)(X,{type:`button`,variant:`ghost`,size:`sm`,className:`h-7 w-7 p-0`,onClick:()=>{try{i.current?.goBack?.()}catch{}},children:(0,$.jsx)(Y,{name:`arrow-left`,className:`h-3.5 w-3.5`})}),(0,$.jsx)(X,{type:`button`,variant:`ghost`,size:`sm`,className:`h-7 w-7 p-0`,onClick:()=>{try{i.current?.goForward?.()}catch{}},children:(0,$.jsx)(Y,{name:`arrow-right`,className:`h-3.5 w-3.5`})}),(0,$.jsx)(X,{type:`button`,variant:`ghost`,size:`sm`,className:`h-7 w-7 p-0`,onClick:()=>{try{i.current?.reload?.()}catch{}},children:(0,$.jsx)(Y,{name:`refresh`,className:`h-3.5 w-3.5`})}),(0,$.jsx)(`form`,{className:`min-w-0 flex-1`,onSubmit:e=>{e.preventDefault(),T(u)},children:(0,$.jsx)(`input`,{value:u,onChange:e=>d(e.target.value),className:`h-7 w-full rounded-md border border-border/50 bg-[var(--surface-elevated)] px-2 typography-micro text-foreground outline-none focus:border-[var(--interactive-focus-ring)]`,"aria-label":r(`contextPanel.browser.addressAria`)})}),(0,$.jsx)(X,{type:`button`,variant:m?`secondary`:`ghost`,size:`sm`,className:`h-7 w-7 p-0`,onClick:E,title:r(`contextPanel.preview.inspect.toggle`),"aria-label":r(`contextPanel.preview.inspect.toggle`),children:(0,$.jsx)(Y,{name:`cursor`,className:`h-3.5 w-3.5`})}),(0,$.jsx)(X,{type:`button`,variant:`ghost`,size:`sm`,className:`h-7 w-7 p-0`,onClick:()=>void It(f),children:(0,$.jsx)(Y,{name:`external-link`,className:`h-3.5 w-3.5`})})]}),(0,$.jsxs)(`div`,{className:`relative min-h-0 flex-1 bg-background`,children:[(0,$.jsx)(`webview`,{ref:i,src:l.current,partition:`persist:openchamber-browser`,allowpopups:!0,style:{width:`100%`,height:`100%`,border:`none`}}),(!f||f===`about:blank`)&&!g?(0,$.jsxs)(`div`,{className:`absolute inset-0 flex flex-col items-center justify-center gap-6 bg-background p-6 text-center`,children:[(0,$.jsx)(Le,{width:140,height:140,className:`opacity-20`}),(0,$.jsx)(`span`,{className:`typography-ui-header text-muted-foreground`,children:r(`contextPanel.browser.empty`)})]}):null,y?(0,$.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center bg-background/70 typography-micro text-muted-foreground`,children:r(`common.loading`)}):null]})]})},Dc=({directory:e})=>{let{t}=ee(),n=Ht()??``,r=e?.trim()||n,i=Q.useMemo(()=>ec(r),[r]),a=c(e=>i?e.contextPanelByDirectory[i]:void 0),s=c(e=>i?e.contextToolDiffByDirectory[i]:void 0),l=c(e=>e.closeContextPanel),u=c(e=>e.closeContextPanelTab),d=c(e=>e.openContextPanelTab),f=c(e=>e.toggleContextPanelExpanded),p=c(e=>e.setContextPanelWidth),m=c(e=>e.setActiveContextPanelTab),h=c(e=>e.reorderContextPanelTabs),g=Dt(e=>e.setSelectedPath),_=c(e=>e.openContextPreview),v=c(e=>e.allowPromptingSubagentSessions),{themeMode:y,setThemeMode:b,lightThemeId:x,darkThemeId:S,currentTheme:C}=Ne(),w=Q.useMemo(()=>a?.tabs??[],[a?.tabs]),T=w.find(e=>e.id===a?.activeTabId)??w[w.length-1]??null,E=!!(a?.isOpen&&T),D=!!(E&&a?.expanded),O=tc(a?.width??Ys),k=Q.useMemo(()=>{let e=[];for(let t of w){if(t.mode!==`chat`)continue;let n=lc(t.dedupeKey);n&&!e.includes(n)&&e.push(n)}return e},[w]),A=fc(i||void 0,k),[j,M]=Q.useState(!1),[N,P]=Q.useState(!1),F=Q.useRef(0),I=Q.useRef(O),te=Q.useRef(null),ne=Q.useRef(null),L=Q.useRef(null),re=Q.useRef(new Map),ie=Q.useRef(new Map),ae=Q.useRef(!1),z=Q.useRef(E),B=Q.useRef(null),[V,oe]=Q.useState({}),se=Q.useRef(V);se.current=V;let[H,U]=Q.useReducer(ts,{activeViewKey:null,tabs:{},mountedViews:{}}),W=Co(),G=o(),K=Q.useCallback(e=>{let t=se.current,n=e(t);return n!==t&&(se.current=n,oe(n),!0)},[]),ce=Q.useCallback(e=>{if(!i)return;U({type:`close-tab`,tabId:e});let t=wo(i,e);K(e=>{if(!e[t])return e;let n={...e};return delete n[t],n}),u(i,e)},[u,K,i]),le=Q.useCallback(()=>{P(!0),B.current!==null&&window.cancelAnimationFrame(B.current),B.current=window.requestAnimationFrame(()=>{B.current=null,P(!1)})},[]);Q.useEffect(()=>()=>{B.current!==null&&window.cancelAnimationFrame(B.current)},[]),Q.useLayoutEffect(()=>{let e=z.current;if(z.current=E,!E){P(!1);return}e||le()},[E,le]),Q.useEffect(()=>{if(!E||ae.current){ae.current=E;return}let e=window.requestAnimationFrame(()=>{L.current?.focus({preventScroll:!0})});return ae.current=!0,()=>window.cancelAnimationFrame(e)},[E]);let ue=Q.useCallback(e=>{let t=L.current;t&&t.style.setProperty(`--oc-context-panel-width`,`${rc(e,t)}px`)},[]),de=Q.useCallback(e=>{if(!(!E||D||!i)){try{e.currentTarget.setPointerCapture(e.pointerId)}catch{}ne.current=e.pointerId,M(!0),F.current=e.clientX,I.current=O,te.current=O,ue(O),e.preventDefault()}},[ue,i,D,E,O]),fe=Q.useCallback(e=>{if(!j||ne.current!==e.pointerId)return;let t=F.current-e.clientX,n=rc(I.current+t,L.current);te.current!==n&&(te.current=n,ue(n))},[ue,j]),pe=Q.useCallback(e=>{if(ne.current!==e.pointerId||!i)return;try{e.currentTarget.releasePointerCapture(e.pointerId)}catch{}let t=rc(te.current??O,L.current);le(),ue(t),te.current=t,p(i,t),M(!1),ne.current=null},[ue,i,p,le,O]);Q.useEffect(()=>{j||(te.current=null)},[j]);let me=Q.useCallback(()=>{i&&l(i)},[l,i]),he=Q.useCallback(()=>{i&&f(i)},[i,f]),_e=Q.useCallback(e=>{if((e.metaKey||e.ctrlKey)&&e.key.toLowerCase()===`w`&&T&&i){e.preventDefault(),e.stopPropagation(),ce(T.id);return}e.key===`Escape`&&(e.preventDefault(),e.stopPropagation(),me())},[T,ce,i,me]);Q.useEffect(()=>{if(!(!i||!T)&&T.mode===`file`&&T.targetPath){g(i,T.targetPath,{allowOutsideRoot:!0});return}},[T,i,g]);let ve=T?.mode===`chat`?T.id:null,ye=jo(ve?V[wo(i,ve)]:void 0,ve?lc(T?.dedupeKey):null);Q.useEffect(()=>{if(!E||!i||!ye){ge(``,null);return}return ge(i,ye),()=>{ge(``,null)}},[ye,i,E]),Q.useEffect(()=>{if(!E||!i||!ye||typeof window>`u`)return;let e=()=>{if(document.visibilityState===`hidden`||!document.hasFocus()){R(i,ye,!1);return}q(ye),R(i,ye,!0)};e();let t=window.setInterval(e,1e4);return window.addEventListener(`focus`,e),window.addEventListener(`blur`,e),document.addEventListener(`visibilitychange`,e),()=>{window.clearInterval(t),window.removeEventListener(`focus`,e),window.removeEventListener(`blur`,e),document.removeEventListener(`visibilitychange`,e),R(i,ye,!1)}},[ye,i,E]);let be=Q.useCallback((e,t,n)=>yt(ie.current,e,t,i||null,n,{mode:y,lightThemeId:x,darkThemeId:S,currentTheme:C}),[C,S,i,x,y]);Q.useEffect(()=>{let e=new Set(w.map(e=>e.id));for(let t of ie.current.keys())e.has(t)||ie.current.delete(t)},[w]);let xe=Q.useCallback(e=>{!i||T?.mode!==`diff`&&T?.mode!==`file-diff`||d(i,{mode:T.mode,targetPath:T.targetPath,stagedDiff:e===`staged`,diffScope:e})},[T,i,d]),Se=Q.useCallback(()=>{if(typeof window>`u`)return;let e={themeMode:y,lightThemeId:x,darkThemeId:S,currentTheme:C};for(let t of re.current.values()){let n=t.contentWindow;if(!n)continue;let r=n.__openchamberApplyThemeSync;if(typeof r==`function`)try{r(e);continue}catch{}n.postMessage({type:`openchamber:theme-sync`,payload:e},window.location.origin)}},[C,S,x,y]),Ce=Q.useCallback(()=>{if(typeof window>`u`)return;let e={allowPromptingSubagentSessions:v};for(let t of re.current.values()){let n=t.contentWindow;if(!n)continue;let r=n.__openchamberApplyChatSettingsSync;if(typeof r==`function`)try{r(e);continue}catch{}n.postMessage({type:`openchamber:chat-settings-sync`,payload:e},window.location.origin)}},[v]),we=Q.useCallback(()=>{if(!(typeof window>`u`))for(let[e,t]of re.current.entries()){let n=t.contentWindow;if(!n)continue;let r={visible:ve===e},i=n.__openchamberSetEmbeddedVisibility;if(typeof i==`function`)try{i(r);continue}catch{}n.postMessage({type:pt,payload:r},window.location.origin)}},[ve]);Q.useEffect(()=>{if(typeof window>`u`)return;let e=e=>{if(e.origin!==window.location.origin||!Array.from(re.current.values()).some(t=>t.contentWindow===e.source))return;let t=e.data;if(t?.type===`openchamber:close-embedded-session-chat`){let t=Array.from(re.current.entries()).find(([,t])=>t.contentWindow===e.source);t&&i&&ce(t[0]);return}if(t?.type===`openchamber:chat-settings-request`){Ce();return}if(t?.type===`openchamber:embedded-visibility-request`){we();return}if(t?.type!==`openchamber:cycle-theme-request`)return;let n=[`light`,`dark`,`system`],r=(n.indexOf(y)+1)%n.length;b(n[r])};return window.addEventListener(`message`,e),()=>window.removeEventListener(`message`,e)},[ce,i,Ce,we,b,y]),Q.useLayoutEffect(()=>{w.some(e=>e.mode===`chat`)&&(Se(),Ce(),we())},[S,x,Ce,we,Se,w,y]);let Te=Q.useMemo(()=>w.map(e=>{let n=sc(e,A,t),i=vc(n,Xs),a=ic(e.targetPath,r);return{id:e.id,label:i,icon:cc(e),title:a?`${n}: ${a}`:n,closeLabel:t(`contextPanel.tab.closeTabAria`,{label:i})}}),[r,A,t,w]),Ee=T?.mode===`context`?(0,$.jsx)(lo,{}):T?.mode===`preview`?(0,$.jsx)(Cc,{rawUrl:T.targetPath??``,onNavigate:e=>_(r,e)}):(0,$.jsxs)(`div`,{className:`flex h-full flex-col items-center justify-center gap-3 p-6 text-center`,children:[(0,$.jsx)(Y,{name:`global`,className:`h-12 w-12 text-muted-foreground/50`}),(0,$.jsx)(`div`,{className:`typography-ui-header text-foreground`,children:t(`contextPanel.preview.title`)}),(0,$.jsx)(`div`,{className:`max-w-sm typography-micro text-muted-foreground`,children:t(`contextPanel.preview.description`)})]}),De=Q.useMemo(()=>w.filter(e=>e.mode===`chat`),[w]),Oe=Q.useMemo(()=>w.filter(e=>e.mode===`browser`),[w]),ke=Q.useMemo(()=>w.filter(e=>e.mode===`diff`||e.mode===`file-diff`),[w]),Ae=wc()?Ec:Tc,je=Q.useMemo(()=>w.some(e=>e.mode===`file`),[w]),Me=T?.mode===`file`,Pe=Me?T?.fileNotice??null:null;Q.useEffect(()=>{let e=new Set(De.map(e=>wo(i,e.id)));K(t=>{let n=!1,r={};for(let e of De){let a=lc(e.dedupeKey);if(!a)continue;let o=wo(i,e.id),s=t[o];r[o]=s??ko({sessionId:a,directory:i}),n||=!s}let a=Io(t,e);return n||=a!==t,n?{...a,...r}:t});for(let t of Object.keys(H.tabs))(!e.has(wo(i,t))||H.tabs[t]?.directory!==i)&&U({type:`close-tab`,tabId:t})},[De,K,i,H.tabs]);let Fe=ve?wo(i,ve):null,Ie=ve?lc(T?.dedupeKey):null,Le=Fe&&Ie?Ao(V[Fe],{sessionId:Ie,directory:i}):void 0,Re=Le&&Fe?To(G,Fe,Le.current.directory,Le.current.sessionId):null;Q.useLayoutEffect(()=>{if(W!==`react-surface`||!E||!ve||!Le||!Fe||!Re){W===`react-surface`&&U({type:`activate`,viewKey:null,now:Date.now()});return}K(e=>e[Fe]?e:{...e,[Fe]:Le}),U({type:`touch`,tab:{tabId:ve,sessionId:Le.anchor.sessionId,directory:Le.anchor.directory},view:{tabId:ve,surfaceId:Fe,sessionId:Le.current.sessionId,directory:Le.current.directory,viewKey:Re},now:Date.now()})},[Le,Fe,ve,Re,W,K,E]);let ze=Q.useCallback((e,t,n)=>{let r=wo(i,e),a=!1;return K(e=>{let i=Fo(e,r,{sessionId:t,directory:n});return a=i.accepted,i.navigationBySurfaceId}),a},[K,i]),Be=Q.useCallback(e=>{let t=wo(i,e);K(e=>{let n=e[t];if(!n)return e;let r=No(n);return r===n?e:{...e,[t]:r}})},[K,i]),Ve=(0,$.jsxs)(`header`,{className:`flex h-10 items-stretch border-b border-transparent`,children:[(0,$.jsx)(Kt,{items:Te,activeId:T?.id??null,onSelect:e=>{i&&m(i,e)},onClose:e=>{ce(e)},onReorder:(e,t)=>{i&&h(i,e,t)},layoutMode:`scrollable`,variant:`default`}),(0,$.jsxs)(`div`,{className:`flex items-center gap-1 px-1.5`,children:[(0,$.jsx)(X,{type:`button`,variant:`ghost`,size:`sm`,onClick:he,className:`h-7 w-7 p-0`,title:t(D?`contextPanel.actions.collapsePanel`:`contextPanel.actions.expandPanel`),"aria-label":t(D?`contextPanel.actions.collapsePanel`:`contextPanel.actions.expandPanel`),children:D?(0,$.jsx)(Y,{name:`fullscreen-exit`,className:`h-3.5 w-3.5`}):(0,$.jsx)(Y,{name:`fullscreen`,className:`h-3.5 w-3.5`})}),(0,$.jsx)(X,{type:`button`,variant:`ghost`,size:`sm`,onClick:me,className:`h-7 w-7 p-0`,title:t(`contextPanel.actions.closePanel`),"aria-label":t(`contextPanel.actions.closePanel`),children:(0,$.jsx)(Y,{name:`close`,className:`h-3.5 w-3.5`})})]})]}),He=E?D?{"--oc-context-panel-width":`100%`,width:`100%`,minWidth:`100%`,maxWidth:`100%`}:{width:`min(var(--oc-context-panel-width), 100%)`,minWidth:`min(${qs}px, 100%)`,maxWidth:`100%`,"--oc-context-panel-width":`${j?te.current??O:O}px`}:{"--oc-context-panel-width":`${j?te.current??O:O}px`,width:0,minWidth:0,maxWidth:0,opacity:0,overflow:`hidden`,visibility:`hidden`};return(0,$.jsxs)(`aside`,{ref:L,"data-context-panel":`true`,tabIndex:-1,inert:!E||void 0,className:J(`flex min-h-0 flex-col overflow-hidden bg-background`,!D&&`oc-layout-divider-l`,D?`absolute inset-0 z-20 min-w-0`:`relative h-full flex-shrink-0`,!E&&`pointer-events-none`,j||!E||N?`transition-none`:`transition-[width] duration-200 ease-in-out`),onKeyDownCapture:_e,style:He,children:[!D&&(0,$.jsx)(`div`,{className:J(`absolute left-0 top-0 z-50 h-full w-[3px] cursor-col-resize transition-colors hover:bg-[var(--interactive-border)]/80`,j&&`bg-[var(--interactive-border)]`),onPointerDown:de,onPointerMove:fe,onPointerUp:pe,onPointerCancel:pe,role:`separator`,"aria-orientation":`vertical`,"aria-label":t(`contextPanel.actions.resizePanelAria`)}),Ve,Pe===`turn-diff-outside-workspace`?(0,$.jsx)(`div`,{className:`shrink-0 border-b border-status-info/20 bg-status-info/10 px-3 py-2 typography-meta text-status-info`,children:t(`contextPanel.file.notice.turnDiffOutsideWorkspace`)}):null,(0,$.jsxs)(`div`,{className:J(`relative min-h-0 flex-1 overflow-hidden`,j&&`pointer-events-none`),children:[je?(0,$.jsx)(`div`,{className:J(`absolute inset-0`,Me?`block`:`hidden`),children:(0,$.jsx)(Fa,{mode:`editor-only`,isActive:E&&Me})}):null,W===`legacy-iframe`&&De.map(e=>{let n=lc(e.dedupeKey);if(!n)return null;let r=be(e.id,n,e.readOnly);return r?(0,$.jsx)(`iframe`,{ref:t=>{if(!t){re.current.delete(e.id);return}re.current.set(e.id,t)},src:r,title:t(`contextPanel.iframe.sessionChatTitle`,{sessionID:n}),className:J(`absolute inset-0 h-full w-full border-0 bg-background`,ve===e.id?`block`:`hidden`),onLoad:()=>{Se(),Ce(),we()}},e.id):null}),W===`react-surface`?Object.values(H.mountedViews).map(e=>{let t=V[wo(i,e.tabId)],n=E&&ve===e.tabId&&Re===e.viewKey;return(0,$.jsx)(Q.Activity,{name:`context-panel-session-${e.sessionId}`,mode:n?`visible`:`hidden`,children:(0,$.jsx)(os,{surfaceId:e.surfaceId,sessionId:e.sessionId,directory:e.directory,active:n,canNavigateBack:n&&!!t?.stack.length,onNavigateSession:(t,n)=>ze(e.tabId,t,n),onNavigateBack:()=>Be(e.tabId),onEstimateBytes:(e,t)=>U({type:`estimate`,viewKey:e,estimatedBytes:t})})},e.viewKey)}):null,Oe.map(e=>(0,$.jsx)(`div`,{className:J(`absolute inset-0`,T?.id!==e.id&&`hidden`),children:(0,$.jsx)(Ae,{initialUrl:e.targetPath??``,directory:i,tabID:e.id})},e.id)),ke.map(e=>{let t=e.mode===`diff`&&s?.targetPath===e.targetPath&&s.turnMessageId===e.diffTurnMessageId?s.patches:null;return(0,$.jsx)(`div`,{className:J(`absolute inset-0`,T?.id!==e.id&&`hidden`),children:(0,$.jsx)(Fi,{hideStackedFileSidebar:!0,stackedDefaultCollapsedAll:!t,pinSelectedFileHeaderToTopOnNavigate:!0,showOpenInEditorAction:!0,diffScope:e.diffScope??(e.stagedDiff?`staged`:`working`),turnMessageId:e.diffTurnMessageId,sessionId:e.diffSessionId,directory:i,onDiffScopeChange:xe,targetFilePath:e.targetPath,targetLine:e.diffTargetLine??null,toolPatches:t,navigationRequestKey:e.touchedAt,flushContent:!0,singleFileView:e.mode===`file-diff`,preloadFullFiles:e.mode===`file-diff`})},e.id)}),T?.mode!==`chat`&&!Me&&T?.mode!==`browser`&&T?.mode!==`diff`&&T?.mode!==`file-diff`?Ee:null]})]})};export{Gi as a,Wi as c,Fr as d,Pr as f,Mn as h,Ki as i,Hi as l,Or as m,Fa as n,Vi as o,mr as p,ia as r,Ui as s,Dc as t,Fi as u};
|