@openchambery/web 1.19.0-beta.9 → 1.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/AgentAvatar-DgGHpQoD.js +1 -0
- package/dist/assets/AssistantView-WZ8qXOm6.js +1 -0
- package/dist/assets/{ChatContainer-Dvicpi3T.js → ChatContainer-CPOlhHJn.js} +41 -43
- package/dist/assets/ContextPanel-ClzJl6RQ.js +288 -0
- package/dist/assets/{DiagramView-Ct9M_fMh.js → DiagramView-BFE0XxUH.js} +1 -1
- package/dist/assets/{FadeInOnReveal-By2F9vcI.js → FadeInOnReveal-BpIMrqet.js} +1 -1
- package/dist/assets/{Icon-DpjYnXxn.js → Icon-Bs6GJIoO.js} +1 -1
- package/dist/assets/{MarkdownRendererImpl-CTTZH1DE.js → MarkdownRendererImpl-BisXjTdJ.js} +1 -1
- package/dist/assets/{MobileDetailNavigation-BMQiOv_u.js → MobileDetailNavigation-DRiFdQXq.js} +1 -1
- package/dist/assets/{MobileShareBridge-D5J6Qnvn.js → MobileShareBridge-D-kwfbug.js} +2 -2
- package/dist/assets/MobileSurface-NsB1sKld.js +2 -0
- package/dist/assets/{MultiRunWindow-Bw_vmN_V.js → MultiRunWindow-C_Tbyfco.js} +1 -1
- package/dist/assets/{OnboardingScreen-BKmuT7AL.js → OnboardingScreen-n85WAcBc.js} +1 -1
- package/dist/assets/OverlayScrollbar-VZKKu-cu.js +2 -0
- package/dist/assets/{SettingsView-BcFNPdSl.js → SettingsView-BOrARuHr.js} +10 -10
- package/dist/assets/{SettingsWindow-5QE3UEs3.js → SettingsWindow-BmegFGj-.js} +1 -1
- package/dist/assets/{TerminalView-DyW2LZuM.js → TerminalView-BcFMX_mg.js} +1 -1
- package/dist/assets/{ToolOutputDialog-CZPvZV_w.js → ToolOutputDialog-DN2IYmqU.js} +4 -4
- package/dist/assets/appThemeRegistry-7v5TIiNK.js +2 -0
- package/dist/assets/{button-C7OXr4ae.js → button-BkTMa7Qj.js} +1 -1
- package/dist/assets/{clipboard-DWuULPzo.js → clipboard-BL4PvBYZ.js} +1 -1
- package/dist/assets/{collapsible-DaEya6b6.js → collapsible-CVL-5iEB.js} +1 -1
- package/dist/assets/{desktopHosts-Txp4xOVQ.js → desktopHosts-Dzx3McaD.js} +1 -1
- package/dist/assets/{desktopRelayRestore-C_FSEHKM.js → desktopRelayRestore-B9S0Rp5s.js} +1 -1
- package/dist/assets/dialog-CD0j-atu.js +1 -0
- package/dist/assets/{es-BX0Vm3Ac.js → es-C-RVtNF4.js} +2 -2
- package/dist/assets/{fileQueries-B_fTkH6s.js → fileQueries-_VUJM8AE.js} +1 -1
- package/dist/assets/{fr-CuPzXTYx.js → fr-C6VZ9yt-.js} +4 -4
- package/dist/assets/{gitApi-DAUlmpqX.js → gitApi-CxPLKmZ2.js} +3 -3
- package/dist/assets/{input-BzYA603C.js → input-Ca2tUhgN.js} +1 -1
- package/dist/assets/insertionBoundaries-2Mzsx_VV.js +4 -0
- package/dist/assets/{ja-DGtzjrFO.js → ja-BdksT20v.js} +3 -3
- package/dist/assets/{ko-DZ9Di0je.js → ko-CvsczTmf.js} +3 -3
- package/dist/assets/main-C1IdVCQf.js +29 -0
- package/dist/assets/{main-IaZbd8eq.js → main-dGakBRsd.js} +2 -2
- package/dist/assets/{markdown-worker-W06-MhF5.js → markdown-worker-9Sn2jsDp.js} +1 -1
- package/dist/assets/{markdownTheme-B89dbj3N.js → markdownTheme-DidS-jC5.js} +1 -1
- package/dist/assets/{miniChat-Byg-MsGQ.js → miniChat-C8rpOcNP.js} +2 -2
- package/dist/assets/mobile-Dm22ebC9.js +2 -0
- package/dist/assets/multirun-ColPhFw1.js +4 -0
- package/dist/assets/{persistence-6sclr7B6.js → persistence-aCOlo6ew.js} +2 -2
- package/dist/assets/pl-C84UGmMr.js +15 -0
- package/dist/assets/platform-ulFAVx1H.js +2 -0
- package/dist/assets/projectMeta-CKI_msIR.js +3 -0
- package/dist/assets/{pt-BR-Brf4RMsw.js → pt-BR-DISmT3zF.js} +2 -2
- package/dist/assets/radio-DKNOd1MW.js +1 -0
- package/dist/assets/renderElectronMiniChatApp-B8ly-dZn.js +2 -0
- package/dist/assets/renderMobileApp-OAlYU54b.js +23 -0
- package/dist/assets/{runtimeConfig-CMLxQH75.js → runtimeConfig-QFdp6Itq.js} +1 -1
- package/dist/assets/runtimeEndpointReset-MzR_-tYR.js +4 -0
- package/dist/assets/{shikiHighlight-g-Djz_ic.js → shikiHighlight-C7KkxQ9i.js} +1 -1
- package/dist/assets/{sortable-tabs-strip-nLsPC06f.js → sortable-tabs-strip-Bl26ebY_.js} +1 -1
- package/dist/assets/src-BwToVDxi.css +2 -0
- package/dist/assets/{store-DQY8Fkb0.js → store-Dge7C5E4.js} +4 -4
- package/dist/assets/{terminalApi-BpPeXWIu.js → terminalApi-HsIEks5U.js} +1 -1
- package/dist/assets/{tooltip-D_orJMYd.js → tooltip-GC3dg3gO.js} +1 -1
- package/dist/assets/{uk-C-wmaPTi.js → uk-Ba5HBTQU.js} +2 -2
- package/dist/assets/{url-BsaBG5-1.js → url-BQHM4bC4.js} +1 -1
- package/dist/assets/{useAppFontEffects-DcZfHbUS.js → useAppFontEffects-D0FmY4C_.js} +5 -5
- package/dist/assets/{useAssistantUIStore-BHsHXCKE.js → useAssistantUIStore-DxZsjSPQ.js} +1 -1
- package/dist/assets/{useDesktopWindowControlsLayout-FEUxMDnk.js → useDesktopWindowControlsLayout-Ce9FSwxa.js} +1 -1
- package/dist/assets/useEffectiveDirectory-C5CrdVlr.js +1 -0
- package/dist/assets/{useFontPreferences-ckzpXQaJ.js → useFontPreferences-DaFspdDd.js} +1 -1
- package/dist/assets/useMobileNavigationStore-jKG6OU5F.js +475 -0
- package/dist/assets/useSessionAutoCleanup-C6GD9W2z.js +1 -0
- package/dist/assets/{useUIStore-DzwCfRqr.js → useUIStore-Wyu09VUF.js} +1 -1
- package/dist/assets/{useWorkerHighlightedLines-D6-XaqdP.js → useWorkerHighlightedLines-mc9J5erB.js} +1 -1
- package/dist/assets/{utils-B1EK5zKa.js → utils-CJdWZupK.js} +1 -1
- package/dist/assets/{zh-CN-DueRrIql.js → zh-CN-BZYwBvs-.js} +2 -2
- package/dist/assets/zh-TW-BsJuPsIi.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 +3 -2
- package/server/index.js +12 -15
- package/server/lib/config-sync/DOCUMENTATION.md +6 -7
- package/server/lib/config-sync/engine.js +0 -8
- package/server/lib/config-sync/index.js +0 -7
- package/server/lib/config-sync/receiver.js +0 -35
- package/server/lib/config-sync/routes.js +8 -41
- package/server/lib/config-sync/routes.test.js +1 -38
- package/server/lib/notifications/APNS.md +53 -38
- package/server/lib/notifications/DOCUMENTATION.md +5 -4
- package/server/lib/notifications/apns-runtime.js +235 -71
- package/server/lib/notifications/apns-runtime.test.js +447 -0
- package/server/lib/notifications/apns-titles.js +212 -0
- package/server/lib/notifications/apns-titles.test.js +55 -0
- package/server/lib/notifications/routes.js +2 -1
- package/server/lib/notifications/runtime.js +5 -13
- package/server/lib/opencode/openchamber-routes.js +1 -7
- package/server/lib/opencode/settings-helpers.js +0 -3
- package/server/lib/opencode/shutdown-runtime.js +0 -2
- package/server/lib/relay/DOCUMENTATION.md +2 -2
- package/server/lib/relay/service.js +45 -3
- package/server/lib/relay/service.test.js +117 -0
- package/server/lib/relay/signing-key.js +1 -1
- package/server/lib/session-goal/DOCUMENTATION.md +3 -3
- package/server/lib/session-goal/runtime.js +3 -3
- package/server/lib/session-title/DOCUMENTATION.md +1 -2
- package/dist/assets/AgentAvatar-DDcjamcJ.js +0 -1
- package/dist/assets/AssistantView-BipKB0Xu.js +0 -1
- package/dist/assets/ContextPanel-DxaTJbBJ.js +0 -288
- package/dist/assets/MobileSurface-Bob51m6v.js +0 -2
- package/dist/assets/OverlayScrollbar-Ch3J6ASR.js +0 -2
- package/dist/assets/appThemeRegistry-Ds7o-iDC.js +0 -2
- package/dist/assets/dialog-DPS0W9eS.js +0 -1
- package/dist/assets/insertionBoundaries-DN03Ffgf.js +0 -1
- package/dist/assets/main-rv0Iw_-o.js +0 -29
- package/dist/assets/mobile-eAdQk_4x.js +0 -2
- package/dist/assets/multirun-lZV5lnAU.js +0 -4
- package/dist/assets/pl-BuCO3qb1.js +0 -15
- package/dist/assets/platform-CbeLpKPk.js +0 -2
- package/dist/assets/projectMeta-2o-eC3Cz.js +0 -3
- package/dist/assets/radio-CHY-FZIg.js +0 -1
- package/dist/assets/renderElectronMiniChatApp-DuK-UF8v.js +0 -2
- package/dist/assets/renderMobileApp-B-UiIevb.js +0 -23
- package/dist/assets/runtimeEndpointReset-5XhUYqlE.js +0 -4
- package/dist/assets/src-RGaBtbGz.css +0 -2
- package/dist/assets/useEffectiveDirectory-BmTAJUVK.js +0 -1
- package/dist/assets/useMobileNavigationStore-DkUlpkW4.js +0 -475
- package/dist/assets/useSessionAutoCleanup-CQmXCiFr.js +0 -1
- package/dist/assets/zh-TW-6875X80V.js +0 -15
- package/server/lib/config-sync/credential-auth.js +0 -39
- package/server/lib/session-assist/DOCUMENTATION.md +0 -62
- package/server/lib/session-assist/runtime.js +0 -376
- package/server/lib/session-assist/runtime.test.js +0 -114
|
@@ -1,288 +0,0 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/ToolOutputDialog-CZPvZV_w.js","assets/rolldown-runtime-C0FnF6B9.js","assets/useUIStore-DzwCfRqr.js","assets/vendor-zustand-B4dlGEM2.js","assets/vendor-base-ui-CnHfUmDN.js","assets/persistence-6sclr7B6.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-DWuULPzo.js","assets/store-DQY8Fkb0.js","assets/vendor-aparajita-capacitor-secure-storage-CjQdwfjS.js","assets/utils-B1EK5zKa.js","assets/vendor-class-variance-authority-BLUaYARZ.js","assets/vendor-tailwind-merge-BicNWLTg.js","assets/Icon-DpjYnXxn.js","assets/dialog-DPS0W9eS.js","assets/button-C7OXr4ae.js","assets/useThemeSystem-DMzWVJaW.js","assets/markdownTheme-B89dbj3N.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-Ds7o-iDC.js","assets/platform-CbeLpKPk.js","assets/vendor-opencode-sdk-C07HQypa.js","assets/markdown-worker-W06-MhF5.js","assets/useEffectiveDirectory-BmTAJUVK.js","assets/useMobileNavigationStore-DkUlpkW4.js","assets/vendor-tanstack-react-query-D7pys_c9.js","assets/vendor-sonner-DVzioF3d.js","assets/useAssistantUIStore-BHsHXCKE.js","assets/vendor-fuse.js-DB5wDJbI.js","assets/useWorkerHighlightedLines-D6-XaqdP.js","assets/tooltip-D_orJMYd.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-DzwCfRqr.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,xn as S}from"./persistence-6sclr7B6.js";import{a as C}from"./vendor-zustand-B4dlGEM2.js";import{nt as w,rt as T,tt as E}from"./vendor-base-ui-CnHfUmDN.js";import{Ct as D,Mt as O,Nt as k}from"./platform-CbeLpKPk.js";import{o as A}from"./vendor-aparajita-capacitor-secure-storage-CjQdwfjS.js";import{n as j}from"./vendor-react-DLPElpoQ.js";import{l as M,n as ee,s as N}from"./vendor-tanstack-react-query-D7pys_c9.js";import{W as P,ct as F}from"./vendor-codemirror-autocomplete-DHomsvW7.js";import{n as I}from"./vendor-reactuses-core-DDoDDyM9.js";import{n as te,o as L,r as R,t as ne}from"./clipboard-DWuULPzo.js";import{i as z,t as re}from"./store-DQY8Fkb0.js";import{$a as B,$t as V,Cn as H,Eo as ie,Et as ae,Fo as oe,Ga as U,Lt as se,On as W,Pr as ce,Qi as le,Rt as G,Ut as K,Vn as ue,Wt as de,Xa as fe,ao as pe,ba as me,br as q,cn as he,en as ge,fn as _e,l as ve,mn as ye,nn as be,oa as xe,oi as Se,pn as Ce,rn as we,tn as Te,ya as Ee}from"./useMobileNavigationStore-DkUlpkW4.js";import{a as De,i as Oe,o as ke,t as J}from"./utils-B1EK5zKa.js";import{n as Y}from"./Icon-DpjYnXxn.js";import{a as Ae,i as je,n as Me,o as Ne,r as Pe,t as Fe}from"./dialog-DPS0W9eS.js";import{t as X}from"./button-C7OXr4ae.js";import{A as Ie,N as Le,j as Re,o as ze}from"./projectMeta-2o-eC3Cz.js";import{t as Be}from"./input-BzYA603C.js";import{i as Ve,n as He,t as Ue}from"./tooltip-D_orJMYd.js";import{n as We,t as Ge}from"./useThemeSystem-DMzWVJaW.js";import{$ as Ke,B as qe,D as Je,M as Ye,N as Xe,O as Ze,P as Qe,W as $e,c as et,h as tt,it as nt,j as rt,k as it,n as at,p as ot,s as st}from"./radio-CHY-FZIg.js";import{i as ct}from"./OverlayScrollbar-Ch3J6ASR.js";import{f as Z,g as lt,h as ut,x as dt}from"./markdownTheme-B89dbj3N.js";import{F as ft,G as pt,H as mt,I as ht,J as gt,K as _t,N as vt,O as yt,Q as bt,W as xt,a as St,c as Ct,d as wt,et as Tt,h as Et,j as Dt,k as Ot,l as kt,m as At,n as jt,p as Mt,q as Nt,s as Pt,u as Ft,z as It}from"./ChatContainer-Dvicpi3T.js";import{n as Lt}from"./useRuntimeAPIs-DSLXJybW.js";import{i as Rt,n as zt,t as Bt,u as Vt}from"./appThemeRegistry-Ds7o-iDC.js";import{a as Ht}from"./url-BsaBG5-1.js";import{f as Ut,g as Wt,h as Gt,m as Kt,p as qt}from"./markdown-worker-W06-MhF5.js";import{n as Jt}from"./useEffectiveDirectory-BmTAJUVK.js";import{o as Yt}from"./FadeInOnReveal-By2F9vcI.js";import{M as Xt,N as Zt,b as Qt,g as $t,x as en,y as tn}from"./insertionBoundaries-DN03Ffgf.js";import{g as nn,n as rn}from"./useWorkerHighlightedLines-D6-XaqdP.js";import{t as an}from"./sortable-tabs-strip-nLsPC06f.js";import{a as on,c as sn,d as cn,f as ln,l as un,m as dn,n as fn,o as pn,p as mn,s as hn,t as gn,u as _n}from"./vendor-pierre-diffs-BenIz2TM.js";import{a as vn,c as yn,i as bn,l as xn,n as Sn,o as Cn,r as wn,s as Tn,t as En}from"./shikiHighlight-g-Djz_ic.js";import{n as Dn,r as On,t as kn}from"./collapsible-DaEya6b6.js";import{n as An,s as jn,t as Mn}from"./fileQueries-B_fTkH6s.js";import{t as Nn}from"./vendor-zumer-snapdom-yq9vlCKr.js";import{n as Pn,t as Fn}from"./vendor-html-to-image-BDMm2v6d.js";var Q=e(T(),1),In=j(),$=w(),Ln=e(E(),1);function Rn(){return new Worker(gn,{type:`module`})}var zn=[`typescript`,`javascript`,`tsx`,`jsx`,`json`,`markdown`],Bn={unified:{poolSize:1,totalASTLRUCacheSize:24,lineDiffType:`none`},split:{poolSize:2,totalASTLRUCacheSize:56,lineDiffType:`word-alt`}},Vn,Hn,Un=e=>{let t=Bn[e],n=new mn({workerFactory:Rn,poolSize:t.poolSize,totalASTLRUCacheSize:t.totalASTLRUCacheSize},{theme:{light:`pierre-light`,dark:`pierre-dark`},langs:zn,lineDiffType:t.lineDiffType,preferredHighlighter:`shiki-wasm`});return n.initialize(),n},Wn=e=>{if(!(typeof window>`u`))return e===`split`?(Hn??=Un(`split`),Hn):(Vn??=Un(`unified`),Vn)},Gn=e=>{let t=(0,In.c)(7),{children:n,renderTheme:r}=e,i=qn(`unified`),a=qn(`split`),o,s;t[0]!==r||t[1]!==a||t[2]!==i?(o=()=>{i&&i.setRenderOptions({theme:r,lineDiffType:Bn.unified.lineDiffType}),a&&a.setRenderOptions({theme:r,lineDiffType:Bn.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},Kn=e=>{let t=(0,In.c)(11),{children:n}=e,r=Ge(),i,a;if(t[0]!==r?.availableThemes||t[1]!==r?.darkThemeId||t[2]!==r?.lightThemeId){let e=dt(!1),n=dt(!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,Bt(a),Bt(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)(Gn,{renderTheme:s,children:n}),t[8]=n,t[9]=s,t[10]=c):c=t[10],c},qn=e=>{let t=(0,In.c)(2),n=e===void 0?`unified`:e,r;return t[0]===n?r=t[1]:(r=Wn(n),t[0]=n,t[1]=r),r};function Jn(e){let t=(0,In.c)(85),{draft:n,onEdit:r,onDelete:i,className:a,maxWidth:o}=e,{t:s}=te(),c=Ge()?.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 ee;t[32]!==h||t[33]!==l||t[34]!==s?(ee=h&&(0,$.jsx)(On,{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]=ee):ee=t[35];let N;t[36]===Symbol.for(`react.memo_cache_sentinel`)?(N=(0,$.jsx)(Dn,{}),t[36]=N):N=t[36];let P;t[37]!==k||t[38]!==M||t[39]!==ee?(P=(0,$.jsxs)(kn,{open:k,onOpenChange:u,children:[M,ee,N]}),t[37]=k,t[38]=M,t[39]=ee,t[40]=P):P=t[40];let F;t[41]!==O||t[42]!==P?(F=(0,$.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[O,P]}),t[41]=O,t[42]=P,t[43]=F):F=t[43];let I;t[44]===Symbol.for(`react.memo_cache_sentinel`)?(I=(0,$.jsx)(Qe,{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]=I):I=t[44];let L;t[45]===Symbol.for(`react.memo_cache_sentinel`)?(L=(0,$.jsx)(Y,{name:`edit`,className:`size-4 mr-2`}),t[45]=L):L=t[45];let R;t[46]===s?R=t[47]:(R=s(`inlineComment.actions.editComment`),t[46]=s,t[47]=R);let ne;t[48]!==r||t[49]!==R?(ne=(0,$.jsxs)(it,{onClick:r,children:[L,R]}),t[48]=r,t[49]=R,t[50]=ne):ne=t[50];let z;t[51]===Symbol.for(`react.memo_cache_sentinel`)?(z=(0,$.jsx)(Y,{name:`delete-bin`,className:`size-4 mr-2`}),t[51]=z):z=t[51];let re;t[52]===s?re=t[53]:(re=s(`inlineComment.actions.deleteComment`),t[52]=s,t[53]=re);let B;t[54]!==i||t[55]!==re?(B=(0,$.jsxs)(it,{onClick:i,className:`text-destructive`,children:[z,re]}),t[54]=i,t[55]=re,t[56]=B):B=t[56];let V;t[57]!==ne||t[58]!==B?(V=(0,$.jsxs)(Je,{children:[I,(0,$.jsxs)(Ze,{align:`end`,children:[ne,B]})]}),t[57]=ne,t[58]=B,t[59]=V):V=t[59];let H;t[60]!==F||t[61]!==V?(H=(0,$.jsxs)(`div`,{className:`flex items-start justify-between gap-2 p-3`,children:[F,V]}),t[60]=F,t[61]=V,t[62]=H):H=t[62];let ie;t[63]!==H||t[64]!==S?(ie=(0,$.jsx)(xn,{render:S,children:H}),t[63]=H,t[64]=S,t[65]=ie):ie=t[65];let ae;t[66]===Symbol.for(`react.memo_cache_sentinel`)?(ae=(0,$.jsx)(Y,{name:`edit`,className:`size-4 mr-2`}),t[66]=ae):ae=t[66];let oe;t[67]===s?oe=t[68]:(oe=s(`inlineComment.actions.editComment`),t[67]=s,t[68]=oe);let U;t[69]!==r||t[70]!==oe?(U=(0,$.jsxs)(Tn,{onClick:r,children:[ae,oe]}),t[69]=r,t[70]=oe,t[71]=U):U=t[71];let se;t[72]===Symbol.for(`react.memo_cache_sentinel`)?(se=(0,$.jsx)(Y,{name:`delete-bin`,className:`size-4 mr-2`}),t[72]=se):se=t[72];let W;t[73]===s?W=t[74]:(W=s(`inlineComment.actions.deleteComment`),t[73]=s,t[74]=W);let ce;t[75]!==i||t[76]!==W?(ce=(0,$.jsxs)(Tn,{onClick:i,className:`text-destructive focus:text-destructive`,children:[se,W]}),t[75]=i,t[76]=W,t[77]=ce):ce=t[77];let le;t[78]!==U||t[79]!==ce?(le=(0,$.jsxs)(Cn,{children:[U,ce]}),t[78]=U,t[79]=ce,t[80]=le):le=t[80];let G;return t[81]!==d||t[82]!==ie||t[83]!==le?(G=(0,$.jsxs)(vn,{open:d,onOpenChange:f,children:[ie,le]}),t[81]=d,t[82]=ie,t[83]=le,t[84]=G):G=t[84],G}function Yn(e){let t=(0,In.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}=te(),h=Ge()?.currentTheme,{isMobile:g}=ct(),[_,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=rr,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,ee;t[15]===l?ee=t[16]:(ee=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]=ee);let N=h?.colors?.surface?.elevated,P=h?.colors?.interactive?.border,F=u?`${Math.max(200,Math.floor(u))}px`:void 0,I;t[17]!==N||t[18]!==P||t[19]!==F?(I={backgroundColor:N,borderColor:P,maxWidth:F},t[17]=N,t[18]=P,t[19]=F,t[20]=I):I=t[20];let L=nr,R=tr,ne=(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})})]}),z;t[21]===x?z=t[22]:(z=e=>x(e.target.value),t[21]=x,t[22]=z);let re;t[23]!==g||t[24]!==m?(re=m(g?`inlineComment.input.placeholderShort`:`inlineComment.input.placeholder`),t[23]=g,t[24]=m,t[25]=re):re=t[25];let B;t[26]!==A||t[27]!==z||t[28]!==re||t[29]!==_?(B=(0,$.jsx)(ze,{simple:!0,ref:y,value:_,onChange:z,onKeyDown:A,placeholder:re,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]=z,t[28]=re,t[29]=_,t[30]=B):B=t[30];let V;t[31]!==E||t[32]!==d||t[33]!==m?(V=E&&d?(0,$.jsxs)(X,{variant:`outline`,size:`sm`,onClick:()=>d(E),onPointerDown:er,className:`mr-auto h-8 gap-1.5`,children:[(0,$.jsx)(Y,{name:`add`,className:`size-4`}),m(`chat.textSelection.actions.addToChat`),(0,$.jsx)(mt,{shortcut:`⌘+I`})]}):null,t[31]=E,t[32]=d,t[33]=m,t[34]=V):V=t[34];let H;t[35]===m?H=t[36]:(H=m(`inlineComment.actions.cancel`),t[35]=m,t[36]=H);let ie;t[37]!==a||t[38]!==H?(ie=(0,$.jsx)(X,{variant:`ghost`,size:`sm`,onClick:a,onPointerDown:$n,onTouchStart:Qn,className:`h-8 text-muted-foreground hover:text-foreground`,children:H}),t[37]=a,t[38]=H,t[39]=ie):ie=t[39];let ae;t[40]===_?ae=t[41]:(ae=_.trim(),t[40]=_,t[41]=ae);let oe=!ae,U=h?.colors?.status?.success,se=h?.colors?.status?.successForeground,W;t[42]!==U||t[43]!==se?(W={backgroundColor:U,color:se},t[42]=U,t[43]=se,t[44]=W):W=t[44];let ce;t[45]!==p||t[46]!==m?(ce=m(p?`inlineComment.actions.save`:`inlineComment.actions.comment`),t[45]=p,t[46]=m,t[47]=ce):ce=t[47];let le;t[48]!==M||t[49]!==oe||t[50]!==W||t[51]!==ce?(le=(0,$.jsx)(X,{size:`sm`,onClick:M,onPointerDown:Zn,onTouchStart:Xn,disabled:oe,className:`h-8 min-w-[80px]`,style:W,children:ce}),t[48]=M,t[49]=oe,t[50]=W,t[51]=ce,t[52]=le):le=t[52];let G;t[53]!==V||t[54]!==ie||t[55]!==le?(G=(0,$.jsxs)(`div`,{className:`flex items-center justify-end gap-2 mt-3`,children:[V,ie,le]}),t[53]=V,t[54]=ie,t[55]=le,t[56]=G):G=t[56];let K;t[57]!==ne||t[58]!==B||t[59]!==G?(K=(0,$.jsxs)(`div`,{className:`p-3`,children:[ne,B,G]}),t[57]=ne,t[58]=B,t[59]=G,t[60]=K):K=t[60];let ue;return t[61]!==ee||t[62]!==I||t[63]!==L||t[64]!==R||t[65]!==K?(ue=(0,$.jsx)(`div`,{className:ee,style:I,"data-comment-input":`true`,onPointerDown:L,onTouchStart:R,children:K}),t[61]=ee,t[62]=I,t[63]=L,t[64]=R,t[65]=K,t[66]=ue):ue=t[66],ue}function Xn(e){return e.stopPropagation()}function Zn(e){return e.stopPropagation()}function Qn(e){return e.stopPropagation()}function $n(e){return e.stopPropagation()}function er(e){return e.stopPropagation()}function tr(e){return e.stopPropagation()}function nr(e){return e.stopPropagation()}function rr(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 ir=e=>{let t=Math.min(e.startLine,e.endLine),n=Math.max(e.startLine,e.endLine);return{...e,startLine:t,endLine:n}},ar=e=>{let t=Math.min(e.start,e.end),n=Math.max(e.start,e.end);return{...e,start:t,end:n}};function or(e){let t=(0,In.c)(40),{t:n}=te(),{source:r,fileLabel:i,language:a,getCodeForRange:o,toStoreRange:s,fromDraftRange:c}=e,l=ve(fr),u=ve(dr),d=Nt(ur),f=Nt(lr),p=Nt(cr),m=Nt(sr),[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=ar(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){q.error(n(`inlineComment.toast.selectSessionToSave`));return}let u=ar(c),p=ir(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 ee=M,N;return t[30]!==_||t[31]!==j||t[32]!==C||t[33]!==y||t[34]!==c||t[35]!==ee||t[36]!==h||t[37]!==x||t[38]!==k?(N={sessionKey:x,drafts:C,selection:h,setSelection:g,commentText:_,setCommentText:v,editingDraftId:y,setEditingDraftId:b,reset:T,cancel:D,startEdit:k,deleteDraft:j,saveComment:ee,fromDraftRange:c},t[30]=_,t[31]=j,t[32]=C,t[33]=y,t[34]=c,t[35]=ee,t[36]=h,t[37]=x,t[38]=k,t[39]=N):N=t[39],N}function sr(e){return e.drafts}function cr(e){return e.removeDraft}function lr(e){return e.updateDraft}function ur(e){return e.addDraft}function dr(e){return e.newSessionDraft?.open}function fr(e){return e.currentSessionId}function pr(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)(Yn,{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)(Jn,{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)(Yn,{initialText:r,onTextChange:i,fileLabel:s,lineRange:e,isEditing:!1,onSave:u,onCancel:d,onAddToChat:m},c)})}return h}var mr=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}`},hr=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 gr(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 _r(e){if(!(!e||e<=0))return Math.max(200,Math.floor(e))}function vr(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:mr({type:`new`,selection:r}),[i,r]),v=Q.useMemo(()=>{let e=n.map(e=>mr({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=gr(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?_r(Math.min(...o)):_r(h)},[t,h]);return(0,$.jsxs)($.Fragment,{children:[n.map(e=>{let t=mr({type:e.id===i?`edit`:`saved`,draft:e}),n=y(t);if(!n)return null;let r=b(n);return e.id===i?(0,Ln.createPortal)((0,$.jsx)(Yn,{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,Ln.createPortal)((0,$.jsx)(Jn,{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,Ln.createPortal)((0,$.jsx)(Yn,{initialText:a,onTextChange:o,fileLabel:s,lineRange:r,isEditing:!1,onSave:c,onCancel:l,onAddToChat:f,maxWidth:t}),e,_)})()]})}function yr(e){let t=(0,In.c)(16),{position:n,onAddToChat:r,onDismiss:i}=e,{t:a}=te(),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)(mt,{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,Ln.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:br,children:p}),document.body),t[13]=l,t[14]=p,t[15]=m):m=t[15],m}function br(e){return e.preventDefault()}var xr=`[data-code-selection-action]`;function Sr(e){return e instanceof Element&&!!e.closest(xr)}function Cr(e,t=[]){return Sr(e)?!0:t.some(e=>e instanceof Element&&e.matches(`[data-column-number]`))}function wr(e,t){return e&&!!t?.trim()}function Tr(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?Er(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 Er(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 Dr=5e5,Or=`
|
|
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
|
-
`,kr=`
|
|
30
|
-
${Or}
|
|
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 Ar(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 jr(e){let t=e.length>400?`${e.slice(0,200)}${e.slice(-200)}`:e;return`${e.length}:${Ar(t)}`}var Mr=(e,t)=>e===t?!0:!e||!t?!1:e.start===t.start&&e.end===t.end&&e.side===t.side,Nr=e=>e===`auto`||e===`scroll`||e===`overlay`,Pr=e=>{let t=e?.parentElement??null;for(;t;){if(Nr(window.getComputedStyle(t).overflowY))return t;t=t.parentElement}return null},Fr=(e,t)=>{if(!e||!t||typeof window>`u`)return()=>{};let n=Pr(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)}},Ir=(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)}},Lr=new WeakMap,Rr={lineHeight:24,hunkSeparatorHeight:24,spacing:0};function zr(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 Br(e){if(typeof document>`u`)return null;let t=zr(e),n=Lr.get(t.key);if(!n){let e=new pn;e.setup(t.root,t.content),n={virtualizer:e,refs:0},Lr.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=Lr.get(t.key);e&&(--e.refs,!(e.refs>0)&&(e.virtualizer.cleanUp(),Lr.delete(t.key)))}}}var Vr=(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)}},Hr=({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=Ge(),p=f?.currentTheme.metadata.variant===`dark`,m=f?.availableThemes.find(e=>e.metadata.id===f.lightThemeId)??dt(!1),h=f?.availableThemes.find(e=>e.metadata.id===f.darkThemeId)??dt(!0),{isMobile:g}=ct(),_=oe(e=>e.addCodeSelectionAttachment),v=oe(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}=or({source:`diff`,fileLabel:i||`unknown`,language:r,getCodeForRange:r=>Tr(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),ee=(0,Q.useRef)(null),N=(0,Q.useRef)(``),P=(0,Q.useRef)(!1),F=(0,Q.useRef)(null),I=(0,Q.useRef)(!1);(0,Q.useEffect)(()=>{M.current=C},[C]),(0,Q.useEffect)(()=>{ee.current=D},[D]),(0,Q.useEffect)(()=>{N.current=T},[T]);let te=(0,Q.useCallback)(e=>{if(!l||P.current)return;let t=M.current;if(!(!e&&t&&N.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&&(ee.current||E(``))}},[l,g,E,w]),L=(0,Q.useCallback)(()=>{k()},[k]),R=(0,Q.useCallback)(e=>{let t=document.createElement(`div`);t.style.position=`relative`;let n=mr(e.metadata);return t.dataset.annotationId=n,t.dataset.annotationSide=e.side,t.dataset.annotationLine=String(e.lineNumber),t},[]),ne=(0,Q.useCallback)((e,t)=>{O(e,t??C??void 0)},[O,C]),z=(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=Tr(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(),z(t))};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[u,z,y]),(0,Q.useEffect)(()=>{b(null)},[i,n,e,t]),(0,Q.useEffect)(()=>{if(!u)return;let e=e=>{let t=e.composedPath(),n=Cr(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 re=(0,Q.useCallback)(e=>{w(e);let t=U.current;if(t)try{P.current=!0,t.setSelectedLines(e),F.current=e}catch{}finally{P.current=!1}},[w]),B=(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`},[]);Bt(m),Bt(h);let V=`${m.metadata.id}:${h.metadata.id}:${p?`dark`:`light`}`,H=(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)>Dr}return Math.max(e.length,t.length)>Dr},[n,t.length,e.length]),ie=(0,Q.useRef)(null),ae=(0,Q.useRef)(null),U=(0,Q.useRef)(null),se=(0,Q.useRef)(null),W=(0,Q.useRef)(null),ce=(0,Q.useRef)(null),le=(0,Q.useRef)(void 0),G=(0,Q.useRef)(void 0),K=(0,Q.useRef)(void 0),ue=(0,Q.useRef)(void 0),de=(0,Q.useRef)(null),[,fe]=Q.useReducer(e=>e+1,0),pe=qn(H?`unified`:a?`split`:`unified`),me=(0,Q.useMemo)(()=>zt(m),[m]),q=(0,Q.useMemo)(()=>zt(h),[h]);Q.useLayoutEffect(()=>{let e=ie.current;if(!e)return;let t=e.querySelector(`diffs-container`);if(!t)return;let n=p?q:me,r=(e,t)=>e.colors?.[t],i=r(me,`terminal.ansiGreen`),a=r(me,`terminal.ansiRed`),o=r(me,`terminal.ansiBlue`),s=r(q,`terminal.ansiGreen`),c=r(q,`terminal.ansiRed`),l=r(q,`terminal.ansiBlue`);t.style.setProperty(`--shiki-light`,me.fg),t.style.setProperty(`--shiki-light-bg`,me.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`,q.fg),t.style.setProperty(`--shiki-dark-bg`,q.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`,me.fg),m.style.setProperty(`--shiki-light-bg`,me.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`,q.fg),m.style.setProperty(`--shiki-dark-bg`,q.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))},[q,V,p,me]);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:H?0:1e3,maxLineLengthForHighlighting:H?1:1e3,tokenizeMaxLineLength:H?1:1e3,collapsedContextThreshold:0,expansionLineCount:20,overflow:o?`wrap`:`scroll`,disableFileHeader:!0,enableLineSelection:l,enableHoverUtility:!1,onLineSelected:l?te:void 0,unsafeCSS:kr,renderAnnotation:l?R:void 0}),[h.metadata.id,l,p,H,m.metadata.id,a,o,te,R]),ge=(0,Q.useMemo)(()=>l?hr({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=ae.current;return()=>{U.current?.cleanUp(),U.current=null,se.current?.release(),se.current=null,W.current=null,ce.current=null,le.current=void 0,G.current=void 0,K.current=void 0,ue.current=void 0,e&&(e.innerHTML=``)}},[]),(0,Q.useEffect)(()=>{if(typeof window>`u`)return;let a=ae.current,o=ie.current;if(!a||!pe)return;let s=Fr(o,a),c=se.current;c||(c=Br(a),se.current=c),se.current=c;let l=c?.virtualizer??null,u=n?void 0:{name:i||``,contents:e,lang:r,cacheKey:`old:${V}:${i}:${jr(e)}`},f=n?void 0:{name:i||``,contents:t,lang:r,cacheKey:`new:${V}:${i}:${jr(t)}`},p=n?G.current!==n:G.current!==void 0||!u||!f||!K.current||!ue.current||!dn(K.current,u)||!dn(ue.current,f),m=U.current,h=!!(m&&(W.current!==l||ce.current!==pe||l&&(le.current!==he.hunkSeparators||p)));h&&(m?.cleanUp(),U.current=null,a.innerHTML=``);let g=U.current,_=!h&&m?!ln(m.options,he):!1;if(g?g.setOptions(he):(g=c?new hn(he,c.virtualizer,Rr,pe):new sn(he,pe),U.current=g,F.current=null),W.current=l,ce.current=pe,le.current=l?he.hunkSeparators:void 0,G.current=n,K.current=u,ue.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=Ir(a,()=>{if(s(),Vr(g,c,fe),!d||de.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`}),de.current=d)},{awaitRender:p&&!h});return()=>{v(),s()}},[V,n,i,d,r,t,he,e,pe]),(0,Q.useEffect)(()=>{let e=U.current;if(e){try{e.setLineAnnotations(ge)}catch(t){console.error(`Failed to apply diff line annotations`,t);try{e.setLineAnnotations([])}catch{}}requestAnimationFrame(()=>{if(U.current===e){try{e.rerender()}catch{}fe()}})}},[ge]),(0,Q.useEffect)(()=>{let e=U.current;if(!e||C!==null)return;let t=F.current;if(!Mr(C,t))try{P.current=!0,e.setSelectedLines(C),F.current=C}catch{}finally{P.current=!1}},[C]),(0,Q.useEffect)(()=>{if(!l)return;let e=ae.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=B(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:B(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:B(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(!wr(!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()}},[V,l,u,i,te,B]),(0,Q.useEffect)(()=>{let e=ae.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(()=>{fe(),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()}},[V,i]),typeof window>`u`)return null;let ve=l?(0,$.jsx)(vr,{diffRootRef:ie,drafts:S,selection:C,editingDraftId:D,commentText:T,onTextChange:E,fileLabel:i?.split(`/`).pop()??``,onSave:ne,onCancel:L,onEdit:e=>{re({start:e.startLine,end:e.endLine,side:e.side===`original`?`deletions`:`additions`}),A(e)},onDelete:j,onAddToChat:u?z:void 0}):null,ye=u&&y?(0,$.jsx)(yr,{position:y,onDismiss:()=>b(null),onAddToChat:()=>{z(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)(Ie,{outerClassName:`pierre-diff-wrapper size-full`,disableHorizontal:!1,fillContainer:!0,"data-diff-virtual-content":!0,children:(0,$.jsx)(`div`,{ref:ie,className:`size-full relative`,children:(0,$.jsx)(`div`,{ref:ae,className:`size-full`})})}),ve,ye]})}):(0,$.jsxs)(`div`,{className:J(`relative`,`w-full`),children:[(0,$.jsx)(`div`,{ref:ie,className:`pierre-diff-wrapper w-full overflow-x-auto overflow-y-visible relative`,children:(0,$.jsx)(`div`,{ref:ae,className:`w-full`})}),ve,ye]})},Ur=5e3,Wr=(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},Gr=(e,t)=>re(z.getState().dictionary,e,t),Kr=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`},qr=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`}},Jr=async(e,t)=>{try{let{content:n,exists:r}=await qr(e,t);return r?Wr(n,5e3)>5e3?{ok:!1,reason:`too-large`}:{ok:!0}:{ok:!1,reason:`missing`}}catch(e){return{ok:!1,reason:Kr(e)}}},Yr=e=>e===`too-large`?Gr(`contextFileOpen.failure.tooLarge`,{count:Ur.toLocaleString(R())}):Gr(e===`missing`?`contextFileOpen.failure.missing`:`contextFileOpen.failure.unreadable`),Xr=64,Zr=3,Qr=new Map,$r=(e,t,n=Zr)=>{let r=`${e}\0${n}\0${t}`,i=Qr.get(r);if(i)return Qr.delete(r),Qr.set(r,i),i;let a=ti(t),o=a?cn(fn(t,n),{oldFile:{name:e,contents:a.before},newFile:{name:e,contents:a.after}})??ri(e):_n(ei(e,t))[0]?.files[0]??ri(e);for(Qr.set(r,o);Qr.size>Xr;){let e=Qr.keys().next().value;if(!e)break;Qr.delete(e)}return o},ei=(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}`,ti=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:ni(s),after:ni(c)}},ni=e=>e.map(e=>e.text+(e.newline?`
|
|
141
|
-
`:``)).join(``),ri=e=>un({name:e,contents:``},{name:e,contents:``}),ii=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},ai=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},oi=e=>`${e.scope}:${e.navigationRequestKey??``}:${(e.targetFilePath??``).trim()}:${e.targetLine??``}`,si=(e,t,n)=>n&&e!==t,ci=e=>`/api/openchamber/sessions/${encodeURIComponent(e)}/changes`,li=e=>e.trim(),ui=e=>e===404||e===405||e===501,di=e=>{if(!e||typeof e!=`object`||Array.isArray(e))return!1;let t=e.diff;return!!t&&typeof t==`object`&&!Array.isArray(t)},fi=(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},pi=async(e,t)=>{let n={messageID:e.messageID,directory:e.directory};return typeof e.file==`string`&&e.file.length>0&&(n.file=e.file),_(ci(e.sessionID),{method:`GET`,headers:{Accept:`application/json`,"x-opencode-directory":e.directory},query:n,signal:t})},mi=async(e,t)=>{if(t.aborted)throw new DOMException(`Aborted`,`AbortError`);return k.getSessionDiff({sessionID:e.sessionID,directory:e.directory,messageID:e.messageID},{signal:t})},hi=(e,t=n())=>m.sessionTurnChanges.file(e.directory,e.sessionID,e.messageID,e.file,e.diffCount,t),gi=(e,t=n())=>({queryKey:hi(e,t),queryFn:async({signal:t})=>{let n=await pi(e,t);if(n.ok){let e=await n.json().catch(()=>null);if(di(e))return e}else if(!ui(n.status))throw Error(`Session turn change file request failed (${n.status})`);let r=fi(await mi(e,t),e.file);if(!r)throw Error(`change file not found`);return{diff:r}},staleTime:0,gcTime:6e4,retry:!1}),_i=(e,t)=>{let r=(0,In.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=N,s=gi({...i,directory:li(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)},vi=1100,yi=15e3,bi=500,xi=300,Si=1e6,Ci=3,wi=e=>e<=6?e:e<=12?6:e<=25?4:2,Ti=Q.memo(()=>{let e=(0,In.c)(4),{t}=te(),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}),Ei={"?":{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`}},Di=Ei.M,Oi=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`},ki=e=>Ei[Oi(e)]??Di,Ai=e=>{let{index:t,working_dir:n}=e;return t===`A`||n===`A`||t===`?`||n===`?`},ji=e=>{let t=e.index?.trim();return!!(t&&t!==`?`)},Mi=e=>!!e.working_dir?.trim()||e.index===`?`,Ni=(e,t)=>lt(e,t),Pi=e=>(e||``).replace(/\\/g,`/`).replace(/\/+$/,``),Fi=(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},Ii=e=>/^Binary files .+ differ$/m.test(e)||/^GIT binary patch$/m.test(e),Li=e=>Array.isArray(e)?e.filter(e=>!e||typeof e!=`object`?!1:typeof e.file==`string`):[],Ri=e=>e===`added`?`A`:e===`deleted`?`D`:`M`,zi=e=>e.isBinary||typeof e.patch==`string`&&e.patch.length>0||e.fileDiff?!0:e.original.length>0||e.modified.length>0,Bi=(e,t,n)=>Ii(t)?{original:``,modified:``,isBinary:!0,patch:t,contextMode:n}:{original:``,modified:``,patch:t,fileDiff:$r(e,t),contextMode:n},Vi=(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]})},Hi=Q.memo(e=>{let t=(0,In.c)(53),{scope:n,workingCount:r,stagedCount:i,turnCount:a,onScopeChange:o}=e,{t:s}=te(),[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)(Qe,{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)(Ye,{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)(Ye,{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)(Ye,{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)(Ze,{align:`start`,className:`w-40`,children:(0,$.jsxs)(rt,{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)(Je,{open:c,onOpenChange:l,children:[_,j]}),t[49]=c,t[50]=j,t[51]=_,t[52]=M):M=t[52],M}),Ui=Q.memo(e=>{let t=(0,In.c)(11),{changedFiles:n,selectedFile:r,onSelectFile:i}=e,{t:a}=te();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=ki(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)(xt,{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)(`span`,{className:`min-w-0 flex-1 truncate typography-code`,style:{direction:`rtl`,textAlign:`left`,unicodeBidi:`plaintext`},title:e.path,children:e.path}),Vi(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)(Ie,{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}),Wi=Q.memo(e=>{let t=(0,In.c)(20),{filePath:n,diff:r,renderSideBySide:i}=e,{t:a}=te(),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}),Gi=Q.memo(e=>{let t=(0,In.c)(17),{filePath:n,diff:r,renderSideBySide:i,wrapLines:a,focusLine:o}=e,s;t[0]===n?s=t[1]:(s=qt(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)(Ti,{}),t[2]=e):e=t[2],e}if(Gt(n)){let e;return t[3]!==r||t[4]!==n||t[5]!==i?(e=(0,$.jsx)(Wi,{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)(Hr,{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}),Ki=Q.memo(e=>{let t=(0,In.c)(7),{filePath:n,staged:r,busyAction:i,disabled:a,onAction:o}=e,{t:s}=te(),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)(qi,{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)(qi,{label:s(`gitView.changes.revertFileAria`,{path:n}),icon:`arrow-go-back`,loading:i===`discard`,disabled:a,tone:`failure`,onClick:()=>o(`discard`)}),(0,$.jsx)(qi,{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}),qi=e=>{let t=(0,In.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},Ji=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}=te(),{git:C}=Lt(),w=Qt(Q.useCallback(n=>n.directories.get(e)?.diffCache.get(t.path)??null,[e,t.path])),T=Qt(e=>e.setDiff),E=Qt(e=>e.fetchStatus),[D,O]=Q.useState(0),[k,A]=Q.useState(null),[j,M]=Q.useState(!1),[ee,N]=Q.useState(null),[P,F]=Q.useState(!1),[I,L]=Q.useState(null),[R,ne]=Q.useState(null),z=Q.useRef(null),re=Q.useRef(null),B=Q.useMemo(()=>ki(t),[t]),V=n===`side-by-side`,H=h?`full`:`patch`,ie=`${t.index}:${t.working_dir}:${t.insertions}:${t.deletions}`,ae=_i({sessionID:b?.sessionID??``,directory:b?.directory??``,messageID:b?.messageID??``,diffCount:b?.diffCount,file:t.path},{enabled:x&&!!b&&a&&o}),oe=Q.useMemo(()=>{let e=ae.data?.diff;return e?typeof e.patch==`string`&&e.patch.length>0?Bi(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,ae.data]),U=Q.useMemo(()=>{if(g)return g;if(oe)return oe;if(m)return R;if(I)return I;if(!w)return null;let e={original:w.original,modified:w.modified,isBinary:w.isBinary,contextMode:`full`};return zi(e)?e:null},[w,g,I,m,R,oe]),se=ae.error instanceof Error?ae.error.message:ae.error?String(ae.error):null,W=U?null:se??k,ce=x&&ae.isPending||j,le=U?.contextMode===H,G=Q.useCallback(e=>{re.current=e,l(t.path,e)},[t.path,l]),K=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){z.current=null,M(!1);return}if(!e||g){z.current=null,M(!1);return}let n=`${e}::${t.path}::${m?`staged`:`unstaged`}::${ie}::${H}::${D}`;if(z.current===n)return;let r=!!(U&&le);z.current=n,A(null),r||M(!0);let i=!1,s=h?Si:Ci,c=Gt(t.path)||h?C.getGitFileDiff(e,{path:t.path,staged:m}):C.getGitDiff(e,{path:t.path,staged:m,contextLines:s}),l=yi,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=Bi(t.path,n.diff,H);m?ne(e):L(e)}else{let r={original:n.original??``,modified:n.modified??``,isBinary:n.isBinary,contextMode:`full`};m?ne(r):(L(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,z.current===n&&(z.current=null)}},[H,U,le,D,e,y,t.path,ie,C,g,a,o,h,T,m]);let de=Q.useCallback(()=>{K(!a),ue()},[K,ue,a]),fe=Q.useCallback(async n=>{if(!(!e||ee!==null)){N(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`;q.error(e instanceof Error?e.message:S(t))}finally{N(e=>e===n?null:e)}}},[e,E,t.path,ee,C,S]);return(0,$.jsxs)(`div`,{ref:G,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:B.color},title:S(B.descriptionKey),"aria-label":S(B.descriptionKey),children:B.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)(xt,{filePath:t.path,className:`size-3 flex-shrink-0 align-middle`}),(()=>{let e=t.path.lastIndexOf(`/`);if(e===-1)return(0,$.jsx)(`span`,{className:`block min-w-0 truncate typography-code text-foreground`,style:{direction:`rtl`,textAlign:`left`,unicodeBidi:`plaintext`},children:t.path});let n=t.path.slice(0,e),r=t.path.slice(e+1);return(0,$.jsxs)(`span`,{className:`flex min-w-0 items-baseline overflow-hidden`,children:[(0,$.jsx)(`span`,{className:`min-w-0 truncate typography-code text-muted-foreground`,style:{direction:`rtl`,textAlign:`left`,unicodeBidi:`plaintext`},children:n}),(0,$.jsxs)(`span`,{className:`flex-shrink-0 typography-code`,children:[(0,$.jsx)(`span`,{className:`text-muted-foreground`,children:`/`}),(0,$.jsx)(`span`,{className:`text-foreground`,children:r})]})]})})()]})})]}),(0,$.jsxs)(`div`,{className:`relative flex shrink-0 items-center justify-self-end gap-1.5`,children:[Vi(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,U)},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){ae.refetch();return}O(e=>e+1)},children:S(`diffView.actions.retry`)})]}):null,o&&ce&&!U&&!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&&U&&!P&&t.insertions+t.deletions>bi?(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:()=>F(!0),children:S(`diffView.actions.renderAnyway`)})]}):null,o&&U&&(P||t.insertions+t.deletions<=bi)?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Gi,{filePath:t.path,diff:U,renderSideBySide:V,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)(Ki,{filePath:t.path,staged:m,busyAction:ee,disabled:ee!==null,onAction:fe})})}):null]}):null]})]})}),Yi=({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}=te(),{git:y,files:b}=Lt(),x=Jt(),S=typeof s==`string`&&s.trim()?s.trim():x,{screenWidth:C,isMobile:w}=ct(),T=en(S??null),E=tn(S??null),D=$t(S??null),O=Qt(e=>e.setActiveDirectory),k=Qt(e=>e.ensureStatus),A=Qt(e=>e.fetchStatus),j=Qt(e=>e.setDiff),[M,ee]=Q.useState(null),[N,P]=Q.useState(!1),[F,L]=Q.useState(null),[R,ne]=Q.useState(null),[z,re]=Q.useState(()=>new Set),[B,V]=Q.useState(()=>new Set),[H,ie]=Q.useState(g),[ae,oe]=Q.useState(0),[U,se]=Q.useState(!1),[W,le]=Q.useState(!1),[G,K]=Q.useState(i);Q.useEffect(()=>{K(i)},[i]);let ue=c(e=>e.pendingDiffFile),de=c(e=>e.pendingDiffStaged),fe=c(e=>e.pendingDiffScope),pe=c(e=>e.pendingDiffLine),me=c(e=>e.setPendingDiffFile),he=c(e=>e.diffLayoutPreference),ge=c(e=>e.diffFileLayout),_e=c(e=>e.setDiffFileLayout),ye=c(e=>e.diffWrapLines),be=c(e=>e.setDiffWrapLines),xe=c(e=>e.openContextFileAtLine),Ce=c(e=>e.openContextFile),Te=vt(),Ee=ve(e=>e.currentSessionId),De=typeof o==`string`&&o.trim()?o.trim():Ee,Oe=we(De??``,S??void 0),ke=ye,Ae=G===`staged`||G!==`working`&&null,je=Ae??N,Me=w||C<=768,Ne=!!De&&G!==`turn`&&!Me&&!l(),Pe=!e&&!Me&&C>=1024,Fe=Q.useRef(null),Le=Q.useRef(new Map),Re=Q.useRef(null),ze=Q.useRef(null),Be=Q.useRef(!1),We=Q.useRef(null),Ge=Q.useRef(null),Ke=Q.useRef(null),qe=Q.useRef(null),Je=Q.useCallback(()=>{Re.current=null,Be.current=!1,ne(null),ze.current!==null&&(window.cancelAnimationFrame(ze.current),ze.current=null)},[]),Ye=Q.useCallback(e=>{re(t=>{if(t.has(e))return t;let n=new Set(t);return n.add(e),n})},[]),Xe=Q.useMemo(()=>{let e=Oe.length-1;if(a&&(e=Oe.findIndex(e=>e.id===a),e<0))return{messageID:null,count:0,hasDiffs:!1,thinDiffs:[]};for(let t=e;t>=0;--t){let e=Oe[t];if(e.role!==`user`)continue;let n=Li(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:[]}},[Oe,a]),Ze=Q.useMemo(()=>ai(p??[]),[p]),Qe=Ze.length>0,$e=Q.useMemo(()=>!De||!S||!Xe.messageID?null:{sessionID:De,directory:S,messageID:Xe.messageID,diffCount:Xe.count},[S,De,Xe.count,Xe.messageID]),et=Q.useMemo(()=>Qe?Ze:Xe.thinDiffs,[Ze,Xe.thinDiffs,Qe]),tt=Q.useMemo(()=>{let e=new Map;for(let t of et)if(t.file){if(typeof t.patch==`string`&&t.patch.length>0){e.set(t.file,Bi(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},[et]),nt=Q.useMemo(()=>{if(G===`turn`)return et.map(e=>({path:e.file??``,index:``,working_dir:Ri(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=G===`staged`?ji:G===`working`?Mi:()=>!0;return E.files.filter(t).map(t=>({...t,insertions:e[t.path]?.insertions??0,deletions:e[t.path]?.deletions??0,isNew:Ai(t)})).sort((e,t)=>e.path.localeCompare(t.path))},[G,et,E]),rt=Q.useMemo(()=>E?.files?E.files.filter(Mi).length:0,[E]),it=Q.useMemo(()=>E?.files?E.files.filter(ji).length:0,[E]),at=Qe?et.length:Xe.count,ot=Q.useMemo(()=>nt.map(e=>e.path).join(`\0`),[nt]),st=Q.useMemo(()=>{if(!h)return nt;let e=d?.trim()||M;return e?nt.filter(t=>t.path===e):[]},[nt,M,h,d]);Q.useEffect(()=>{let e=ot?ot.split(`\0`):[],n=new Set(e),r=`${S??``}:${G}:${a??``}:${t?`collapsed`:`default`}`,i=p!==null&&Ke.current!==p,o=Ge.current!==r||i;Ge.current=r,Ke.current=p,re(r=>{if(o){let n=t||G===`turn`&&!Qe?0:wi(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}),V(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})},[G,ot,S,t,p,a,Qe]);let Z=Q.useCallback(()=>{We.current=null;let e=Fe.current;if(!e)return;let t=e.getBoundingClientRect(),n=t.top-xi,r=t.bottom+xi,i={};for(let[e,t]of Le.current){if(!t||!z.has(e))continue;let a=t.getBoundingClientRect();a.bottom<n||a.top>r||(i[e]=!0)}V(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})},[z]),lt=Q.useCallback(()=>{typeof window>`u`||We.current===null&&(We.current=window.requestAnimationFrame(Z))},[Z]);Q.useEffect(()=>{let e=Fe.current;if(e)return lt(),e.addEventListener(`scroll`,lt,{passive:!0}),window.addEventListener(`resize`,lt),()=>{e.removeEventListener(`scroll`,lt),window.removeEventListener(`resize`,lt),We.current!==null&&(window.cancelAnimationFrame(We.current),We.current=null)}},[nt,z,lt]);let ut=Q.useCallback(e=>{let t=ge[e.path];if(t)return t;if(he===`inline`)return`inline`;if(he===`side-by-side`)return`side-by-side`;let n=C<vi;return e.isNew||n?`inline`:`side-by-side`},[ge,he,C]),dt=Q.useMemo(()=>st.length===0?null:st.every(e=>ut(e)===`side-by-side`)?`side-by-side`:`inline`,[ut,st]);Q.useEffect(()=>{S&&(O(S),k(S,y))},[S,O,k,y]),Q.useEffect(()=>{if(S)return Se.onGitRefreshHint(e=>{Pi(e.directory)===Pi(S)&&A(S,y)})},[S,A,y]),Q.useEffect(()=>{G!==`all`&&!fe||ue&&(fe&&K(fe),ee(ue),P(fe===`staged`||!fe&&de),L(pe),me(null),Be.current=!0,Re.current=ue,Ye(ue),oe(e=>e+1))},[G,Ye,ue,pe,fe,de,me]),Q.useEffect(()=>{if(G===`all`)return;let e=d?.trim();if(!e)return;Ye(e),ee(e),P(G===`staged`),L(f);let t=oi({scope:G,navigationRequestKey:_,targetFilePath:e,targetLine:f}),n=nt.some(t=>t.path===e);si(qe.current,t,n)&&(qe.current=t,Be.current=!0,Re.current=e,oe(e=>e+1))},[G,nt,Ye,_,d,f]),Q.useEffect(()=>{M&&(nt.some(e=>e.path===M)||(ee(null),P(!1)))},[nt,M]);let ft=Q.useCallback((e,t)=>{let n=Le.current;t?n.set(e,t):n.delete(e),lt()},[lt]),mt=Q.useCallback((e,t)=>{Je(),re(n=>{if(t===n.has(e))return n;let r=new Set(n);return t?r.add(e):r.delete(e),r}),t||V(t=>{if(!t.has(e))return t;let n=new Set(t);return n.delete(e),n}),lt()},[Je,lt]),ht=Q.useCallback(()=>{Je(),re(e=>e.size>0?new Set:new Set(nt.map(e=>e.path))),V(new Set),lt()},[Je,nt,lt]),gt=Q.useCallback(async e=>{if(!Ee)return;let t=ve.getState().getDirectoryForSession(Ee)||S||``;if(!t){q.error(v(`diffView.reviewDialog.toast.noSessionDirectory`));return}le(!0);try{await ce({originalSessionID:Ee,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}),se(!1)}catch(e){console.error(`[review-flow] failed to start review flow`,e),q.error(e instanceof Error?e.message:v(`diffView.reviewDialog.toast.startFailed`))}finally{le(!1)}},[Ee,S,v]),_t=Q.useCallback(e=>{let t=Le.current.get(e),n=Fe.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(!Re.current)return;let e=0,t=!1,r=()=>{t||(t=!0,Re.current=null,Be.current=!1,ne(null),ze.current!==null&&(window.cancelAnimationFrame(ze.current),ze.current=null))},i=()=>{if(t){ze.current=null;return}let a=Re.current;if(!a){r(),ze.current=null;return}if(!_t(a)){e+=1,e<20?ze.current=window.requestAnimationFrame(i):(r(),ze.current=null);return}n&&Be.current&&ne(a),r()};return ze.current=window.requestAnimationFrame(i),()=>{t=!0,ze.current!==null&&(window.cancelAnimationFrame(ze.current),ze.current=null)}},[n,ae,_t]);let yt=Q.useCallback(e=>{},[]),bt=Q.useCallback(e=>{Je(),ee(e),P(!1),Be.current=!0,Re.current=e,Ye(e),oe(e=>e+1),_t(e)},[Je,Ye,_t]),xt=Q.useCallback(e=>{let t=e===`side-by-side`?`side-by-side`:`inline`;st.forEach(e=>{_e(e.path,t)})},[_e,st]),[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&&!Gt(e)?n=ii(t.patch):t&&t.contextMode===`full`&&!t.isBinary&&!Gt(e)&&(n=Fi(t.original,t.modified)),n===null)try{n=ii((await y.getGitDiff(S,{path:e,staged:je,contextLines:3})).diff)}catch{n=null}let r=t;if(n===null||!r){let t=await y.getGitFileDiff(S,{path:e,staged:je});r={original:t.original??``,modified:t.modified??``,isBinary:t.isBinary},je||j(S,e,r)}let i=n??(r.isBinary||Gt(e)?1:Fi(r.original,r.modified)),a=Ni(S,e),o=await Jr(b,a);if(!o.ok){q.error(Yr(o.reason));return}xe(S,a,i,1)}finally{Ct(t=>t===e?null:t)}}},[je,S,b,y,xe,j]),Tt=I(e=>{if(!S||!e)return;let t=Ni(S,e);if(Te){Te.openFile({path:t});return}Jr(b,t).then(e=>{if(!e.ok){q.error(Yr(e.reason));return}Ce(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&&(G===`working`||G===`staged`||G===`turn`?(0,$.jsx)(Hi,{scope:G,workingCount:rt,stagedCount:it,turnCount:at,onScopeChange:e=>{K(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`):st.length===1?v(`diffView.summary.changedFilesSingle`,{count:st.length}):v(`diffView.summary.changedFilesPlural`,{count:st.length})})})),!h&&nt.length>0&&(G!==`turn`||Qe)&&(0,$.jsxs)(X,{variant:`ghost`,size:`sm`,onClick:ht,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:z.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:z.size>0?v(`diffView.actions.collapseAll`):v(`diffView.actions.expandAll`)})]}),nt.length>0&&Ne&&(0,$.jsxs)(X,{variant:`default`,size:`sm`,onClick:()=>se(!0),disabled:W,className:`diff-toolbar__review-button h-7 flex-shrink-0 gap-1.5 px-2`,"aria-label":v(`diffView.actions.reviewAria`),children:[W?(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`)})]}),nt.length>0&&(0,$.jsxs)(Ue,{children:[(0,$.jsx)(Ve,{asChild:!0,children:(0,$.jsx)(X,{variant:`ghost`,size:`sm`,onClick:()=>ie(e=>!e),"aria-pressed":H,"aria-label":v(H?`diffView.actions.disableFullFiles`:`diffView.actions.loadFullFiles`),className:J(`h-7 w-7 flex-shrink-0 p-0 text-muted-foreground hover:text-foreground`,H&&`bg-interactive-selection text-interactive-selection-foreground`),children:(0,$.jsx)(Y,{name:`file-download`,className:`size-4`})})}),(0,$.jsx)(He,{children:(0,$.jsx)(`p`,{children:v(H?`diffView.actions.disableFullFiles`:`diffView.actions.loadFullFiles`)})})]}),nt.length>0&&(0,$.jsx)(X,{variant:`ghost`,size:`sm`,onClick:()=>be(!ye),className:J(`h-5 w-5 p-0 transition-opacity`,ke?`text-foreground opacity-100`:`text-muted-foreground opacity-60 hover:opacity-100`),title:v(ke?`diffView.actions.disableLineWrap`:`diffView.actions.enableLineWrap`),children:(0,$.jsx)(Y,{name:`text-wrap`,className:`size-4`})}),dt&&(0,$.jsx)(rn,{mode:dt===`side-by-side`?`side-by-side`:`unified`,onModeChange:xt})]}),(0,$.jsx)(pt,{open:U,onOpenChange:se,projectDirectory:S??null,submitting:W,onConfirm:gt}),S?G!==`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`)]}):G!==`turn`&&T===!1?(0,$.jsx)(`div`,{className:`flex flex-1 items-center justify-center text-sm text-muted-foreground`,children:v(`diffView.state.notGitRepository`)}):st.length===0?(0,$.jsx)(`div`,{className:`flex flex-1 items-center justify-center text-sm text-muted-foreground`,children:v(G===`turn`?`diffView.state.noLastTurnChanges`:`diffView.state.cleanWorkingTree`)}):(()=>{if(!S)return null;let e=e=>Ae===null?N&&e===M:Ae;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:[Pe&&(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:nt.length})]}),(0,$.jsx)(Ui,{changedFiles:nt,selectedFile:null,onSelectFile:bt})]}),(0,$.jsx)(`div`,{className:`relative flex-1 min-w-0 min-h-0 h-full`,children:(0,$.jsx)(Ie,{ref:Fe,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:st.map(t=>(0,$.jsx)(Ji,{directory:S,file:t,layout:ut(t),wrapLines:ke,isSelected:!1,isExpanded:z.has(t.path),isMounted:B.has(t.path)||t.path===R,onSelect:yt,onExpandedChange:mt,registerSectionRef:ft,showOpenInEditorAction:r&&G!==`turn`,isOpeningInEditor:St===t.path,onOpenInEditor:(e,t)=>{wt(e,t)},onOpenFile:Tt,staged:e(t.path),loadFullFiles:H,initialDiffData:G===`turn`?tt.get(t.path)??null:null,focusLine:t.path===(d?.trim()||M)?f??F:null,showFileActions:G!==`turn`,disableGitFetch:G===`turn`,turnChangesRequest:$e,loadTurnChangeFile:G===`turn`&&!Qe},t.path))})})})]})})():(0,$.jsx)(`div`,{className:`flex flex-1 items-center justify-center text-sm text-muted-foreground`,children:v(`diffView.state.selectSessionDirectory`)})]})},Xi=(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)},Zi=(e,t)=>{let n=e.state.doc.lineAt(t.main.head);return{lineNumber:n.number,character:t.main.head-n.from+1,selection:t}},Qi=(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:F.cursor(a),effects:P.scrollIntoView(a,{y:`center`})})};function $i({open:e,onOpenChange:t,view:n,variant:r=`overlay`}){let{t:i}=te(),[a,o]=Q.useState(``),s=Q.useRef(null),c=Q.useRef(!1),l=Q.useRef(null),u=Q.useRef(null),d=Q.useMemo(()=>Xi(a,n),[a,n]);Q.useEffect(()=>{!e||!n||(c.current=!1,s.current=Zi(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:P.scrollIntoView(e.main.from,{y:`center`})});return}Qi(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:P.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,Qi(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??Zi(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)(Be,{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)(Be,{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 ea=(e,t)=>{let n=Z(t,e);return!n||n===`.`||n===t?0:n.split(`/`).filter(Boolean).length},ta=(e,t,n=10)=>{let r=ut(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=ut(t.path);if(!e||i.has(e))continue;let o=ea(r,e);o<1||o>n||(i.add(e),a.push(e))}return a},na=e=>e.some(e=>!!ut(e)),ra=(e,t)=>{let n=new Set(t.map(e=>ut(e)).filter(Boolean));return e.filter(e=>!n.has(e))},ia=(e,t,n)=>t.length===0?e.length===0:ra(e,t).length>0?!1:t.every(e=>n.has(ut(e))),aa=[{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`}],oa=`finder`,sa=new Set([`finder`,`terminal`]),ca=e=>typeof window<`u`&&window.__OPENCHAMBER_PLATFORM__===`win32`&&e.id===`finder`?{...e,label:`Explorer`,appName:`File Explorer`}:e,la=e=>{if(!e)return null;let t=aa.find(t=>t.id===e)??null;return t?ca(t):null},ua=()=>aa.filter(e=>sa.has(e.id)).map(e=>({...ca(e)})),da=()=>{if(typeof window>`u`)return oa;let e=window.localStorage.getItem(`openInAppId`);return e&&la(e)?e:oa},fa=!1,pa=!1,ma=!1,ha=0,ga=null,_a=()=>{ga&&=(clearTimeout(ga),null)},va=C()((e,t)=>({selectedAppId:da(),availableApps:ua(),hasLoadedApps:!1,isCacheStale:!1,isScanning:!1,initialize:()=>{if(fa||typeof window>`u`)return;fa=!0;let n=(t,n=!0)=>{if(!Array.isArray(t)||t.length===0){e({availableApps:ua(),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:aa.filter(e=>r.has(e.appName)||sa.has(e.id)).map(e=>({...ca(e),iconDataUrl:i.get(e.appName)})),hasLoadedApps:!0})},r=async i=>{if(!f()||!p()||pa||t().hasLoadedApps&&!i)return;let a=aa.map(e=>e.appName);_a(),i&&e({hasLoadedApps:!1}),pa=!0,ma=!1,e({isScanning:!0});try{let{apps:t,success:o,hasCache:s,isCacheStale:c}=await d(a,i),l=o&&!s&&t.length===0&&ha<3;if(e({isCacheStale:s?c:!1}),n(t,o?!l:!1),o){if(l){let e=[800,1600,3200][ha]??3200;ha+=1,ma=!0,ga=setTimeout(()=>{r()},e);return}ha=0,ma=!1;return}if(ha<3){let e=[1e3,3e3,7e3][ha]??7e3;ha+=1,ma=!0,ga=setTimeout(()=>{r()},e)}}finally{pa=!1,ma||e({isScanning:!1})}};r(),window.addEventListener(`openchamber:settings-synced`,t=>{let n=t.detail,r=n&&typeof n.openInAppId==`string`&&n.openInAppId.length>0&&la(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)&&(ha=3,ma=!1,e({isScanning:!1,isCacheStale:!1}),n(r))}),window.__openchamberAppReady&&r(),window.setTimeout(()=>{t().hasLoadedApps||r()},5e3)},loadInstalledApps:async n=>{if(fa||t().initialize(),!f()||!p()||pa||t().hasLoadedApps&&!n)return;let r=aa.map(e=>e.appName);_a(),n&&e({hasLoadedApps:!1}),pa=!0,ma=!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=aa.filter(e=>o.has(e.appName)||sa.has(e.id)).map(e=>({...e,iconDataUrl:s.get(e.appName)}));e({availableApps:c.length>0?c:ua(),hasLoadedApps:c.length>0,isCacheStale:i?a:!1})}finally{pa=!1,ma||e({isScanning:!1})}},selectApp:async t=>{la(t)&&(e({selectedAppId:t}),typeof window<`u`&&window.localStorage.setItem(`openInAppId`,t),await y({openInAppId:t}))}})),ya=Vt(()=>A(()=>import(`./ToolOutputDialog-CZPvZV_w.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]))),ba=e=>{let t=Ca(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},xa=e=>{let t=(0,In.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},Sa=e=>e.slice().sort((e,t)=>e.type===t.type?e.name.localeCompare(t.name):e.type===`directory`?-1:1),Ca=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},wa=e=>e.startsWith(`/`)||e.startsWith(`//`)||/^[A-Za-z]:\//.test(e),Ta=e=>/^[A-Za-z]:\//.test(e)?e.toLowerCase():e,Ea=(e,t)=>{let n=Ca(t),r=Ca(e);if(!n||!r)return!1;let i=Ta(n),a=Ta(r);return a===i||a.startsWith(`${i}/`)},Da=(e,t)=>{let n=Ca(t),r=Ca(e);if(!Ea(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},Oa=(e,t)=>{if(!t)return``;let n=Ca(t);if(!e||!Ea(n,e))return n;let r=n.slice(e.length);return r.startsWith(`/`)?r.slice(1):r},ka=new Set([`node_modules`]),Aa=e=>{let t=(0,In.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},ja=e=>{let t=(0,In.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},Ma=e=>ka.has(e),Na=e=>{let t=Ca(e);return t===`node_modules`||t.endsWith(`/node_modules`)||t.includes(`/node_modules/`)},Pa=e=>{let t=(e instanceof Error?e.message:String(e??``)).toLowerCase();return t.includes(`is a directory`)||t.includes(`eisdir`)},Fa=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`)},Ia=2e5,La=`openchamber:files:auto-save-enabled`,Ra=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
|
-
`},za=e=>e.replace(/\r\n/g,`
|
|
148
|
-
`).replace(/\r/g,`
|
|
149
|
-
`),Ba=(e,t)=>{let n=za(e);return t===`\r
|
|
150
|
-
`?n.replace(/\n/g,`\r
|
|
151
|
-
`):n},Va=()=>{if(typeof window>`u`)return!0;try{return window.localStorage.getItem(La)!==`false`}catch{return!0}},Ha=(e,t)=>(0,$.jsx)(xt,{filePath:e,extension:t}),Ua=e=>{if(!e)return!1;let t=e.toLowerCase().split(`.`).pop();return t===`md`||t===`markdown`},Wa=e=>{if(!e)return!1;let t=e.toLowerCase().split(`.`).pop();return t===`html`||t===`htm`},Ga=e=>{let t=(0,In.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}=te(),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,ee;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?(ee=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(),ne(n.path).then(e=>{e.ok||q.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=Oa(r,n.path)||n.path;ne(t).then(e=>{if(e.ok){q.success(b(`filesView.toast.relativePathCopied`));return}q.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),q.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(De())]}),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]=ee):ee=t[29];let N=ee,P=m===n.path,F;t[30]!==n.path||t[31]!==h?(F=e=>h(e?n.path:null),t[30]=n.path,t[31]=h,t[32]=F):F=t[32];let I=o?void 0:O,L;t[33]===I?L=t[34]:(L=(0,$.jsx)(`div`,{className:`group relative flex items-center`,onContextMenu:I}),t[33]=I,t[34]=L);let R=o?void 0:O,z=a?`bg-interactive-selection/70`:`hover:bg-interactive-hover/40`,re;t[35]===z?re=t[36]:(re=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`,z),t[35]=z,t[36]=re);let B;t[37]!==x||t[38]!==i||t[39]!==n.extension||t[40]!==n.path?(B=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`}):Ha(n.path,n.extension),t[37]=x,t[38]=i,t[39]=n.extension,t[40]=n.path,t[41]=B):B=t[41];let V;t[42]!==n.name||t[43]!==n.path?(V=(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]=V):V=t[44];let H;t[45]!==x||t[46]!==c?(H=!x&&c&&(0,$.jsx)(Aa,{status:c}),t[45]=x,t[46]=c,t[47]=H):H=t[47];let ie;t[48]!==l||t[49]!==x?(ie=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]=ie):ie=t[50];let ae;t[51]!==A||t[52]!==re||t[53]!==B||t[54]!==V||t[55]!==H||t[56]!==ie||t[57]!==R?(ae=(0,$.jsxs)(`button`,{type:`button`,onClick:A,onContextMenu:R,className:re,children:[B,V,H,ie]}),t[51]=A,t[52]=re,t[53]=B,t[54]=V,t[55]=H,t[56]=ie,t[57]=R,t[58]=ae):ae=t[58];let oe;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]!==N||t[70]!==p?(oe=(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)(Je,{open:f===n.path,onOpenChange:e=>p(e?n.path:null),children:[(0,$.jsx)(Qe,{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)(Ze,{align:`end`,side:`bottom`,onCloseAutoFocus:()=>p(null),children:N({Item:it,Separator:Xe})})]})}),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]=N,t[70]=p,t[71]=oe):oe=t[71];let U;t[72]!==ae||t[73]!==oe||t[74]!==L?(U=(0,$.jsxs)(xn,{render:L,children:[ae,oe]}),t[72]=ae,t[73]=oe,t[74]=L,t[75]=U):U=t[75];let se;t[76]===N?se=t[77]:(se=(0,$.jsx)(Cn,{className:`min-w-[180px]`,children:N({Item:Tn,Separator:yn})}),t[76]=N,t[77]=se);let W;return t[78]!==U||t[79]!==se||t[80]!==P||t[81]!==F?(W=(0,$.jsxs)(vn,{open:P,onOpenChange:F,children:[U,se]}),t[78]=U,t[79]=se,t[80]=P,t[81]=F,t[82]=W):W=t[82],W},Ka=e=>{let t=(0,In.c)(83),{activeDialog:n,dialogData:r,dialogInputValue:i,onDialogInputChange:a,isDialogSubmitting:o,onDialogSubmit:s,onClose:c,inputRef:l}=e,{t:u}=te(),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)(Ne,{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)(Pe,{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)(Ae,{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)(Be,{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)(je,{children:[E,j]}),t[71]=E,t[72]=j,t[73]=M):M=t[73];let ee;t[74]!==l||t[75]!==C||t[76]!==w||t[77]!==M?(ee=(0,$.jsxs)(Me,{initialFocus:l,children:[C,w,M]}),t[74]=l,t[75]=C,t[76]=w,t[77]=M,t[78]=ee):ee=t[78];let N;return t[79]!==d||t[80]!==f||t[81]!==ee?(N=(0,$.jsx)(Fe,{open:d,onOpenChange:f,children:ee}),t[79]=d,t[80]=f,t[81]=ee,t[82]=N):N=t[82],N},qa=(e,t,n)=>e&&!!t&&n===t,Ja=(e,n,a)=>{let o=(0,In.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(Xa),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},Ya=({mode:e=`full`,isActive:t=!0})=>{let{t:n}=te(),{files:r,runtime:i}=Lt(),{currentTheme:o,availableThemes:s,lightThemeId:l,darkThemeId:d}=We(),{isMobile:f,isTablet:p,screenWidth:m}=ct(),v=f||p,y=g(),S=u(),C=Jt()??``,w=Ca(C.trim()),T=f||e!==`editor-only`,E=e===`editor-only`&&!f,D=O(e=>e.searchFiles),A=tn(C),[j,M]=Q.useState(``),ee=Xt(j,200),N=Q.useRef(null),[F,I]=Q.useState(!1),[L,R]=Q.useState(!0),[z,re]=Q.useState(!1),[B,V]=Q.useState(!1),[H,ie]=Q.useState(!1),[ae,U]=Q.useState({open:!1,title:``,content:``}),se=Q.useRef(null),W=Q.useRef(0),ce=Q.useCallback(e=>{W.current=Math.max(0,W.current+(e?1:-1))},[]),le=Q.useCallback(e=>e instanceof Element&&e.closest(`[data-slot="dropdown-menu-content"], [data-slot="dropdown-menu-item"]`)!==null,[]);Q.useEffect(()=>{if(!H)return;let e=e=>{W.current>0||le(e.target)||se.current&&!se.current.contains(e.target)&&ie(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[le,H]);let[G,K]=Q.useState(`edit`),[ue,de]=Q.useState(`edit`),[fe,pe]=Q.useState(`edit`),[me,he]=Q.useState(`preview`),[ge,_e]=Q.useState(0),ve=Q.useRef({}),ye=Q.useRef({}),be=Q.useRef({}),Se=Q.useRef({}),Ce=Q.useMemo(()=>s.find(e=>e.metadata.id===l)??dt(!1),[s,l]),we=Q.useMemo(()=>s.find(e=>e.metadata.id===d)??dt(!0),[s,d]);Q.useEffect(()=>{Bt(Ce),Bt(we)},[Ce,we]);let Te=Q.useMemo(()=>[],[]),Ee=Zt(e=>w?e.byRoot[w]?.openPaths??Te:Te),De=Zt(e=>w?e.byRoot[w]?.selectedPath??null:null),Le=Zt(e=>w?e.byRoot[w]?.expandedPaths??Te:Te),Re=Zt(e=>e.addOpenPath),ze=Zt(e=>e.removeOpenPath),Ge=Zt(e=>e.removeOpenPathsByPrefix),Ye=Zt(e=>e.removeExpandedPathsByPrefix),Xe=Zt(e=>e.setSelectedPath),tt=Zt(e=>e.toggleExpandedPath),nt=Zt(e=>e.expandPaths),rt=Q.useCallback(e=>{let t=Ca(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}},[]),at=Q.useMemo(()=>Ee.map(rt),[Ee,rt]),ot=Q.useMemo(()=>{if(De){let e=Ta(De);if(Ee.some(t=>Ta(t)===e))return De}return Ee[0]??null},[Ee,De]),Z=Q.useMemo(()=>ot?rt(ot):null,[ot,rt]),lt=Z?.path??``;Q.useEffect(()=>{if(!w||!De)return;let e=Ta(De);Ee.some(t=>Ta(t)===e)||Xe(w,Ee[0]??null)},[Ee,w,De,Xe]);let ut=!!(w&<&&!Ea(lt,w)),ft=ut?Yt(lt):void 0,pt=Q.useMemo(()=>({allowOutsideWorkspace:e===`editor-only`&&ut,outsideFileGrant:ft,directory:w||void 0}),[e,ut,ft,w]),ht=Q.useRef(null),[gt,_t]=Q.useState({left:!1,right:!1}),vt=Q.useCallback(()=>{let e=ht.current;e&&_t({left:e.scrollLeft>2,right:e.scrollLeft+e.clientWidth<e.scrollWidth-2})},[]),yt=Q.useRef(vt);yt.current=vt,Q.useEffect(()=>{let e=ht.current;if(!e)return;let t=()=>yt.current();t(),e.addEventListener(`scroll`,t,{passive:!0});let n=new ResizeObserver(t);return n.observe(e),()=>{e.removeEventListener(`scroll`,t),n.disconnect()}},[at.length]);let[bt,St]=Q.useState({}),[Ct,wt]=Q.useState({}),Tt=Q.useRef(new Set),Et=Q.useRef(new Set),Dt=Q.useRef(!1),Ot=Q.useRef(new Map),kt=Q.useRef(0),[At,jt]=Q.useState([]),[Nt,Pt]=Q.useState(!1),[Ft,It]=Q.useState(``),{isPlaying:Vt,play:Ht,stop:Qt}=Mt(),[$t,en]=Q.useState(!1),[nn,rn]=Q.useState(null),[an,sn]=Q.useState(``),cn=Q.useRef(``),[ln,un]=Q.useState(null),[dn,fn]=Q.useState(``),[pn,mn]=Q.useState(!1),[hn,gn]=Q.useState(`
|
|
152
|
-
`),_n=Q.useRef(null),vn=Q.useRef(null),yn=Q.useRef(null),xn=Q.useRef(``),Cn=Q.useRef(``),Tn=Q.useRef(null),Dn=Q.useRef(null),On=Q.useRef(null),kn=Q.useRef(0),[An,Mn]=Q.useState(`idle`),[Nn,Pn]=Q.useState(!1),[Fn,In]=Q.useState(Va),[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),Gn=Q.useRef(null),Kn=Q.useRef(null),[qn,Jn]=Q.useState(0),Yn=Q.useRef(null),Xn=Q.useRef({key:``,attempts:0});Q.useEffect(()=>()=>{Yn.current!==null&&typeof window<`u`&&(window.cancelAnimationFrame(Yn.current),Yn.current=null)},[]);let[Zn,Qn]=Q.useState(null),[$n,er]=Q.useState(null),[tr,nr]=Q.useState(``),[rr,ir]=Q.useState(!1),[sr,cr]=Q.useState(null),[lr,ur]=Q.useState(null),[dr,fr]=Q.useState(!1),[mr,hr]=Q.useState(!1),[gr,_r]=Q.useState(!1),[vr,br]=Q.useState(!1),[xr,Sr]=Q.useState(null),Cr=oe(e=>e.addCodeSelectionAttachment),wr=oe(e=>e.setPendingInputText),Tr=!!r.writeFile,Er=!!r.createDirectory,Dr=!!r.rename,Or=!!r.delete,kr=!!r.revealPath,Ar=va(e=>e.availableApps),jr=va(e=>e.isCacheStale),Mr=va(e=>e.initialize),Nr=va(e=>e.loadInstalledApps);Q.useEffect(()=>{Mr()},[Mr]);let Pr=Q.useCallback(e=>{r.revealPath&&r.revealPath(e).catch(()=>{q.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=ba(Z.path)||w;t&&await h(t,e.appName)||q.error(n(`filesView.toast.openInAppFailed`,{app:e.appName}))},[w,Z?.path,n]),Ir=Q.useCallback((e,t)=>{Qn(e),er(t),nr(e===`rename`&&t.name||``),ir(!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=xe(e=>e.settingsDefaultFileViewerPreview),Zr=xe(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}=or({source:`file`,fileLabel:Z?.path??null,language:Z?.path&&qt(Z.path)||`text`,getCodeForRange:e=>$r(Ft,ar(e)),toStoreRange:e=>({startLine:e.start,endLine:e.end}),fromDraftRange:e=>({start:e.startLine,end:e.endLine})});Q.useEffect(()=>{Rr(null),si(),Ur(null),fn(``),mn(!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&&Ma(r.name))continue;let t=r.name,i=Ca(r.path||``),a=i?wa(i)?i:Ca(`${e}/${i}`):Ca(`${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 Sa(n)},[S,y]),fi=Q.useCallback(async e=>{let t=Ca(e.trim());if(!t||Tt.current.has(t)||Et.current.has(t))return;Et.current=new Set(Et.current),Et.current.add(t);let n=kt.current+1;kt.current=n,Ot.current=new Map(Ot.current),Ot.current.set(t,n);let i=()=>Ot.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}))):k.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);Tt.current=new Set(Tt.current),Tt.current.add(t),wt(e=>{if(!e[t])return e;let n={...e};return delete n[t],n}),St(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){Ye(w,t),wt(e=>{if(!e[t])return e;let n={...e};return delete n[t],n});return}console.error(`Failed to load files directory:`,e),wt(e=>({...e,[t]:n}))}).finally(()=>{i()&&(Ot.current=new Map(Ot.current),Ot.current.delete(t),Et.current=new Set(Et.current),Et.current.delete(t))})},[r,di,Ye,w]),pi=Q.useCallback(async()=>{w&&(Tt.current=new Set,Et.current=new Set,Ot.current=new Map,wt({}),St(e=>Object.keys(e).length===0?e:{}),await fi(w))},[fi,w]),mi=Q.useCallback(async e=>{if(!e){await pi();return}let t=Ca(e);Tt.current=new Set(Tt.current),Tt.current.delete(t),Et.current=new Set(Et.current),Et.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,It(``),rn(null),sn(``),un(null),I(!1)),n&&(gi.current=e,Dt.current=!1,Tt.current=new Set,Et.current=new Set,Ot.current=new Map,wt({}),St(e=>Object.keys(e).length===0?e:{}),fi(w)))},[fi,w,S,y]),Q.useEffect(()=>{if(!r.listDirectory)return;let e=()=>{if(!document.hidden&&Le.length>0)for(let e of Le)mi(e)};return document.addEventListener(`visibilitychange`,e),()=>document.removeEventListener(`visibilitychange`,e)},[Le,r.listDirectory,mi]),Q.useEffect(()=>{if(!w||Le.length===0)return;let e=Le.map(e=>Ca(e)).filter(e=>!!e&&e!==w&&e.startsWith(`${w}/`)&&!Tt.current.has(e)&&!Et.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}},[Le,fi,w]);let _i=Q.useCallback(async e=>{if(e?.preventDefault(),!$n||!Zn)return;ir(!0);let t=()=>{Qn(null)},i=e=>{q.error(e)},a=()=>{ir(!1)};if(Zn===`createFile`){if(!tr.trim()){i(n(`sidebarFilesTree.toast.filenameRequired`)),a();return}if(!r.writeFile){i(n(`sidebarFilesTree.toast.writeNotSupported`)),a();return}let e=$n.path,o=Ca(`${e?`${e}/`:``}${tr.trim()}`);await r.writeFile(o,``).then(async r=>{r.success&&(q.success(n(`sidebarFilesTree.toast.fileCreated`)),await mi(e)),t()}).catch(()=>i(n(`sidebarFilesTree.toast.operationFailed`))).finally(a);return}if(Zn===`createFolder`){if(!tr.trim()){i(n(`sidebarFilesTree.toast.folderNameRequired`)),a();return}let e=$n.path,o=Ca(`${e?`${e}/`:``}${tr.trim()}`);await r.createDirectory(o).then(async r=>{r.success&&(q.success(n(`sidebarFilesTree.toast.folderCreated`)),await mi(e)),t()}).catch(()=>i(n(`sidebarFilesTree.toast.operationFailed`))).finally(a);return}if(Zn===`rename`){if(!tr.trim()){i(n(`sidebarFilesTree.toast.nameRequired`)),a();return}if(!r.rename){i(n(`sidebarFilesTree.toast.renameNotSupported`)),a();return}let e=$n.path,o=e.split(`/`).slice(0,-1).join(`/`),s=Ca(`${o?`${o}/`:``}${tr.trim()}`);await r.rename(e,s).then(async r=>{r.success&&(q.success(n(`sidebarFilesTree.toast.renamedSuccessfully`)),await mi(o),w&&Ge(w,e),(Z?.path===e||Z?.path.startsWith(`${e}/`))&&(w&&Xe(w,null),It(``),rn(null),sn(``),un(null),f&&I(!1))),t()}).catch(()=>i(n(`sidebarFilesTree.toast.operationFailed`))).finally(a);return}if(Zn===`delete`){if(!r.delete){i(n(`sidebarFilesTree.toast.deleteNotSupported`)),a();return}let e=$n.path,o=e.split(`/`).slice(0,-1).join(`/`);await r.delete(e).then(async r=>{r.success&&(q.success(n(`sidebarFilesTree.toast.deletedSuccessfully`)),await mi(o),w&&Ge(w,e),(Z?.path===e||Z?.path.startsWith(`${e}/`))&&(w&&Xe(w,null),It(``),rn(null),sn(``),un(null),f&&I(!1))),t()}).catch(()=>i(n(`sidebarFilesTree.toast.operationFailed`))).finally(a);return}a()},[Zn,$n,tr,r,mi,f,Ge,w,Z?.path,Xe,n]);Q.useEffect(()=>{if(!C){jt([]),Pt(!1);return}let e=ee.trim();if(!e){jt([]),Pt(!1);return}let t=!1;return Pt(!0),D(C,e,150,{includeHidden:y,respectGitignore:!S,type:`file`}).then(e=>{if(t)return;let n=e.filter(e=>S||!Na(e.path)).map(e=>({name:e.name,path:Ca(e.path),type:`file`,extension:e.extension,relativePath:e.relativePath}));jt(n)}).catch(()=>{t||jt([])}).finally(()=>{t||Pt(!1)}),()=>{t=!0}},[C,ee,D,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||Ee.length===0)return;let e=!1,t=[...Ee];return Promise.all(t.map(async t=>{try{let n=await r.statFile?.(t,{directory:w||void 0});!e&&n&&!n.isFile&&Ge(w,t)}catch(n){!e&&Fa(n)&&Ge(w,t)}})),()=>{e=!0}},[r,Ee,Ge,w]);let bi=Q.useMemo(()=>Ft.length>Ia?`${Ft.slice(0,Ia)}\n\n… truncated …`:Ft,[Ft]),xi=dn!==bi,Si=Q.useCallback(async()=>{if(!Z||!r.writeFile)return q.error(n(`filesView.toast.savingNotSupported`)),!1;if(!xi)return!0;if(dn===``&&Ft!==``&&ln!==Z.path)return console.warn(`[saveDraft] refusing to save empty draft for "${Z.path}" (${Ft.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;mn(!0);try{let e=Ba(dn,hn);return(await r.writeFile(Z.path,e))?.success?(It(dn),Z?.path&&Kt(Z.path)&&(xn.current=dn,Cn.current=dn),yi(Z.path).then(e=>{e&&(On.current=e)}).catch(()=>{}),!0):(q.error(n(`filesView.toast.writeFileFailed`)),!1)}catch(e){return q.error(e instanceof Error?e.message:n(`filesView.toast.saveFailed`)),!1}finally{mn(!1)}},[dn,Ft,r,xi,hn,ln,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(La,Fn?`true`:`false`)}catch{}},[Fn]),Q.useEffect(()=>{Fn||(Mn(`idle`),vn.current&&=(clearTimeout(vn.current),null))},[Fn]);let Ci=1500;Q.useEffect(()=>{let e=!!(Z&&r.writeFile);if(!(!Fn||!xi||!e||pn))return vn.current=setTimeout(()=>{Si().then(e=>{e&&(Mn(`saved`),setTimeout(()=>Mn(`idle`),2e3))})},Ci),()=>{vn.current&&=(clearTimeout(vn.current),null)}},[Fn,dn,xi,Z,r.writeFile,pn,Si]),Q.useEffect(()=>{Mn(`idle`)},[Z?.path]),Q.useEffect(()=>{let e=e=>{ke(e)&&(e.key.toLowerCase()===`s`?(e.preventDefault(),vn.current&&=(clearTimeout(vn.current),null),pn||Si().then(e=>{e&&(Mn(`saved`),setTimeout(()=>Mn(`idle`),2e3))})):e.key.toLowerCase()===`f`&&(e.preventDefault(),V(!0)))};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[pn,Si]);let wi=Q.useCallback(async t=>{let r=kn.current+1;kn.current=r;let a=()=>{if(!w)return!1;let e=Zt.getState().byRoot[w],n=e?.selectedPath??e?.openPaths[0]??null;return kn.current===r&&n===t.path};rn(null),sn(``),un(null);let o=Gt(t.path),s=t.path.toLowerCase().endsWith(`.svg`),c=Wt(t.path);if(f&&I(!0),i.isDesktop&&o&&!s){It(``),fn(``),en(!0);return}if(!i.isDesktop&&o&&!s){It(``),fn(``),un(t.path),en(!1);return}if(c){It(``),fn(``),un(t.path),en(!1);return}en(!0);let l=Yt(t.path),u={allowOutsideWorkspace:e===`editor-only`&&!!w&&!Ea(t.path,w),outsideFileGrant:l};await vi(t.path,u).then(e=>{if(!a())return;let n=za(e);gn(Ra(e)),It(n),xn.current=n,Cn.current=n,fn(n.length>Ia?`${n.slice(0,Ia)}\n\n… truncated …`:n),un(t.path),yi(t.path,u).then(e=>{e&&a()&&(On.current=e)}).catch(()=>{})}).catch(e=>{if(a()){if(Pa(e)){if(en(!1),w&&Xe(w,null),rn(null),It(``),fn(``),un(null),On.current=null,j.trim().length>0&&M(``),f&&I(!1),w){let e=[...Da(t.path,w),t.path];e.length>0&&nt(w,e);for(let t of e)Tt.current.has(t)||fi(t)}return}if(Fa(e)){w&&Ge(w,t.path),It(``),fn(``),rn(null),On.current=null,f&&I(!1);return}It(``),fn(``),rn(e instanceof Error?e.message:n(`filesView.error.readFileFailed`)),On.current=null}}).finally(()=>{a()&&en(!1)})},[nt,f,fi,e,vi,yi,Ge,w,i.isDesktop,j,Xe,n]),Ti=Q.useCallback(async(e,t)=>{if(!w)return;let n=Da(e,w),r=t?[...n,e]:n;r.length>0&&nt(w,r);let i=r.map(e=>{if(!Tt.current.has(e))return fi(e)}).filter(Boolean);await Promise.all(i)},[nt,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&&(Xe(w,e.path),Re(w,e.path),Ti(e.path,!1)),rn(null),sn(``),It(``),xn.current=``,Cn.current=``,fn(``),un(null),f&&I(!0)},[Re,Ti,xi,f,w,Xe]);Q.useEffect(()=>{Z?.path&&Ti(Z.path,!1)},[Ti,Z?.path]),Q.useEffect(()=>{if(!Z){kn.current+=1,en(!1);return}ln!==Z.path&&wi(Z)},[wi,ln,Z]);let Oi=Q.useRef(xi);Oi.current=xi,Q.useEffect(()=>{let e=Z?.path??``;if(!qa(t,e,ln))return;let n=!1,r=window.setInterval(()=>{document.hidden||yi(e,pt).then(t=>{if(n||!t)return;let r=On.current;if(!r||r.path!==e){On.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||(On.current=t,un(null))}).catch(()=>{})},2e3);return()=>{n=!0,window.clearInterval(r)}},[t,ln,yi,Z?.path,pt]);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),fn(bi),n){w&&ze(w,n),Z?.path===n&&(e?Di(e):(w&&Xe(w,null),It(``),rn(null),sn(``),un(null),f&&I(!1)));return}if(e){Di(e);return}t&&(Ur(null),c.getState().setActiveMainTab(t))},[bi,Di,f,ze,w,Z?.path,Ur,Xe]),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&&ze(w,n),Z?.path===n&&(e?await Di(e):(w&&Xe(w,null),It(``),rn(null),sn(``),un(null),f&&I(!1)));return}if(e){await Di(e);return}t&&(Ur(null),c.getState().setActiveMainTab(t))},[Di,f,ze,w,Si,Z?.path,Ur,Xe]),ji=Q.useCallback(e=>{let t=Z?.path===e,n=Ei(e,at);if(t&&xi){Rn(!0),zn.current=n,Vn.current=e;return}if(w&&ze(w,e),t){if(n){Di(n);return}w&&Xe(w,null),It(``),rn(null),sn(``),un(null),f&&I(!1)}},[Ei,Di,xi,f,at,ze,w,Z?.path,Xe]),Mi=Q.useCallback(e=>{if(Ee.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},[Ee,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=Ca(e);w&&(tt(w,t),Tt.current.has(t)||await fi(t))},[fi,w,tt]),Fi=Q.useMemo(()=>w?ta(w,bt):[],[bt,w]),Ii=Q.useMemo(()=>new Set(Le.map(e=>Ca(e))),[Le]),Li=na(Le),Ri=Q.useCallback(()=>{if(w){if(Li){Dt.current=!1,Ye(w,w);return}Dt.current=!0,nt(w,Fi)}},[Li,Fi,nt,Ye,w]);Q.useEffect(()=>{if(!w||!Dt.current)return;let e=ra(Fi,Le);if(e.length>0){nt(w,e);return}let t=new Set([...Tt.current,...Object.keys(Ct)]);ia(Fi,Le,t)&&(Dt.current=!1)},[Fi,nt,Le,Ct,w]);let zi=Q.useMemo(()=>({canRename:Dr,canCreateFile:Tr,canCreateFolder:Er,canDelete:Or,canReveal:kr}),[Dr,Tr,Er,Or,kr]);function Bi(e,t){let i=bt[e]??[];return i.map((e,a)=>{let o=e.type===`directory`,s=o&&Ii.has(Ca(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)(Ga,{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:zi,downloadFile:r.downloadFile,contextMenuPath:sr,setContextMenuPath:cr,rightClickMenuPath:lr,setRightClickMenuPath:ur,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:[Ct[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:Ct[e.path],children:Ct[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,Bi(e.path,t+1)]})]},e.path)})}let Vi=!!(Z?.path&&Gt(Z.path)),Hi=!!(Z?.path&&Z.path.toLowerCase().endsWith(`.svg`)),Ui=!!(Z?.path&&Wt(Z.path)),Wi=Q.useMemo(()=>Ca(Wr?.path??``),[Wr?.path]),Gi=!!(Wr&&Wi&<&<===Wi&&!$t&&!nn&&!Vi&&!Ui),Ki=Q.useMemo(()=>Oa(w,lt),[lt,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)})},[]),Ji=Q.useCallback(()=>{let e=Gn.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]),Yi=Q.useCallback(e=>{if(!Z)return;let t=Math.min(e.start,e.end),n=Math.max(e.start,e.end),r=dn.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,dn,Z,wr]),Xi=!!(Z&&(!Vi||Hi)&&!Ui&&Ft.length>0),Zi=!!(Z&&Ki.length>0),Qi=!!(Z&&!ut&&!Vi&&!Ui&&r.writeFile&&Ft.length<=Ia),ea=!!(Z?.path&&Ua(Z.path)),aa=!!(Z?.path&&Wa(Z.path)),oa=!!(Z?.path&&Kt(Z.path)),sa=!!(Z&&!Vi&&!Ui),ca=sa&&!ea&&!oa&&!(aa&&fe===`preview`),la=ea&&ue===`edit`||aa&&fe===`edit`||!ea&&!aa&&G===`edit`,ua=Q.useMemo(()=>lt?st(lt):null,[lt]),[da,fa]=Q.useState(null);Q.useEffect(()=>{let e=!1,t=Z?.path;if(!t||ua){fa(null);return}return fa(null),et(t).then(t=>{e||fa(t)}),()=>{e=!0}},[Z?.path,ua]),Q.useEffect(()=>{!Qi&&G===`edit`&&K(`view`)},[Qi,G]);let pa=`openchamber:files:md-viewer-mode`,ma=`openchamber:files:html-viewer-mode`;Q.useEffect(()=>{let e=Z?.path;if(!e)return;K(ve.current[e]??`edit`);let t=Xr?`preview`:`edit`;try{let e=localStorage.getItem(pa);(e===`preview`||e===`edit`)&&(t=e)}catch{}de(ye.current[e]??t);let n=Xr?`preview`:`edit`;try{let e=localStorage.getItem(ma);(e===`preview`||e===`edit`)&&(n=e)}catch{}pe(be.current[e]??n),he(Se.current[e]??(Xr?`preview`:`edit`))},[Z?.path,Xr]);let ha=Q.useCallback(e=>{let t=Z?.path;t&&(ve.current[t]=e),K(e)},[Z?.path]),ga=Q.useCallback(e=>{let t=Z?.path;t&&(ye.current[t]=e),de(e);try{localStorage.setItem(pa,e)}catch{}},[Z?.path]),_a=Q.useCallback(()=>ue,[ue]),ka=Q.useCallback(e=>{let t=Z?.path;t&&(be.current[t]=e),pe(e);try{localStorage.setItem(ma,e)}catch{}},[Z?.path]),Aa=Q.useCallback(e=>{let t=Z?.path;if(t&&(Se.current[t]=e),yn.current&&=(clearTimeout(yn.current),null),Tn.current!==null&&(cancelAnimationFrame(Tn.current),Tn.current=null),e===`edit`)fn(xn.current||Ft),he(e);else{xn.current=dn;let e=t;he(`edit`),Tn.current=requestAnimationFrame(()=>{Tn.current=requestAnimationFrame(()=>{Tn.current=null,!(w&&e&&Zt.getState().byRoot[w]?.selectedPath!==e)&&(_e(e=>e+1),he(`preview`))})});return}},[dn,Ft,w,Z?.path]),Ya=Q.useCallback(async(e,t)=>{if(!r.writeFile||t===Cn.current)return!1;if(!(await r.writeFile(e,t))?.success)return q.error(n(`filesView.toast.writeFileFailed`)),!1;xn.current=t,Cn.current=t,fn(t);let i=await yi(e,pt).catch(()=>null);return i&&(On.current=i),!0},[r,yi,pt,n]);Q.useEffect(()=>()=>{yn.current&&=(clearTimeout(yn.current),null),Tn.current!==null&&(cancelAnimationFrame(Tn.current),Tn.current=null)},[me,Z?.path]);let Xa=Q.useCallback(e=>{if(xn.current=e,!Z?.path||me!==`preview`||!r.writeFile)return;yn.current&&clearTimeout(yn.current);let t=Z.path;yn.current=setTimeout(()=>{yn.current=null,Ya(t,e).then(e=>{e&&(Pn(!0),setTimeout(()=>Pn(!1),1500))}).catch(e=>{q.error(e instanceof Error?e.message:n(`filesView.toast.saveFailed`))})},Ci)},[me,r.writeFile,Ya,Z?.path,n]),Za=Q.useMemo(()=>oa&&(xn.current||dn)||Ft,[dn,Ft,oa]),Qa=Q.useCallback(()=>fe,[fe]);Q.useEffect(()=>{let e=e=>{let t=e?`preview`:`edit`;for(let e of Ee)ve.current[e]=`edit`,Ua(e)&&(ye.current[e]=t),Wa(e)&&(be.current[e]=t),Kt(e)&&(Se.current[e]=t);K(`edit`),de(t),pe(t),he(t);try{localStorage.setItem(pa,t),localStorage.setItem(ma,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)}},[Ee]),Q.useEffect(()=>{if(!Wr||!w)return;let e=()=>{typeof window>`u`||Yn.current===null&&(Yn.current=window.requestAnimationFrame(()=>{Yn.current=null,Jn(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=Ca(Wr.path);if(!n){Gr(null),Xn.current={key:``,attempts:0};return}let r=`${n}:${Wr.line}:${Wr.column??1}`;if(Xn.current.key!==r&&(Xn.current={key:r,attempts:0}),Z?.path!==n){if(Ln)return;Di(rt(n));return}if($t||ln!==n)return;if(nn||Vi||Ui){Gr(null),Xn.current={key:``,attempts:0};return}if(!Qi)return;if(G!==`edit`){K(`edit`);return}let i=Gn.current;if(!i){e();return}if(!t(i,dn)){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||Xn.current.attempts===0){Xn.current.attempts+=1,i.dispatch({selection:{anchor:u},effects:P.scrollIntoView(u,{y:`center`})}),i.focus(),e();return}typeof window<`u`&&window.requestAnimationFrame(()=>{let e=Gn.current;e&&(e.dispatch({selection:{anchor:u},effects:P.scrollIntoView(u,{y:`center`})}),e.focus())}),Gr(null),Xn.current={key:``,attempts:0}},[Qi,Ln,dn,qn,nn,$t,Vi,Ui,ln,Di,Wr,w,Z?.path,Gr,G,rt]),Q.useEffect(()=>{if(!Kr||!w)return;let e=Ca(Kr);if(!e){qr(null);return}if(Z?.path!==e){if(Ln)return;Di(rt(e));return}if(!($t||ln!==e||nn||Vi||Ui)){if(Qi&&G===`edit`){let e=Gn.current;if(!e)return;e.focus()}qr(null)}},[Qi,Ln,nn,$t,Di,Vi,Ui,ln,Kr,w,Z?.path,qr,G,rt]);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(Gn.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(G!==`edit`||f)return;let e=$e(`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(qe(t,e)){t.preventDefault(),_r(!0);return}if(t.metaKey&&!t.ctrlKey&&!t.altKey&&!t.shiftKey&&t.key.toLowerCase()===`i`){let e=Gn.current?.state.selection.main;e&&!e.empty&&(t.preventDefault(),Ji())}}};return window.addEventListener(`keydown`,t),()=>window.removeEventListener(`keydown`,t)},[Ji,f,Jr,G]);let eo=c(e=>e.editorFontSize),to=Q.useMemo(()=>{if(!Z?.path)return[Sn(o,{fontSize:eo})];let e=qt(Z.path),t=[Sn(o,e?{syntaxColors:!1,fontSize:eo}:{fontSize:eo})],n=ua??da;return n&&t.push(n),e&&t.push(En({language:e,themeName:o.metadata.id,theme:zt(o)})),L&&t.push(P.lineWrapping),t.push(P.updateListener.of(e=>{(e.selectionSet||e.docChanged)&&qi(e.view)})),f&&t.push(P.updateListener.of(e=>{e.view.hasFocus&&(e.selectionSet||e.focusChanged||e.viewportChanged||e.geometryChanged)&&window.requestAnimationFrame(()=>{$a(e.view)})})),t},[o,Z?.path,ua,da,L,f,$a,eo,qi]),no=Q.useMemo(()=>({light:Ce.metadata.id,dark:we.metadata.id}),[Ce.metadata.id,we.metadata.id]),ro=Z?.path&&Vi&&!i.isDesktop&&!Hi?`${Z.path}|${pt.allowOutsideWorkspace?`outside`:`workspace`}|${pt.outsideFileGrant??``}`:``,io=Z?.path&&Ui?`${Z.path}|${pt.allowOutsideWorkspace?`outside`:`workspace`}|${pt.outsideFileGrant??``}`:``,ao=Z?.path&&aa&&fe===`preview`&&!i.isVSCode?Z.path:``,oo=n(`filesView.error.readFileFailed`),{readyKey:so,nonce:co}=Ja(ro,rn,oo),{readyKey:lo,nonce:uo}=Ja(ao,rn,oo),{readyKey:fo,nonce:po}=Ja(io,rn,oo),mo=!!(ro&&so!==ro),ho=!!(ao&&lo!==ao),go=!!(io&&fo!==io),_o=Z?.path&&Vi?i.isDesktop?Hi?`data:${Ut(Z.path)};utf8,${encodeURIComponent(Ft)}`:an:Hi?`data:${Ut(Z.path)};utf8,${encodeURIComponent(Ft)}`:so===ro?a().authenticatedAsset(`/api/fs/raw`,{path:Z.path,allowOutsideWorkspace:pt.allowOutsideWorkspace?`true`:void 0,outsideFileGrant:pt.outsideFileGrant,directory:w||void 0}):``:``,vo=Q.useCallback(()=>{if(!Z?.path||!Vi)return;let e=Hi?_o:Z.path||_o;if(!e)return;let t=Z.name||Z.path;U({open:!0,title:t,content:``,metadata:{tool:`image-preview`,filename:t,mime:Ut(Z.path)},image:{url:e,mimeType:Ut(Z.path),filename:t}})},[_o,Vi,Hi,Z?.name,Z?.path]),yo=Q.useCallback(e=>{U(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&&Ui&&fo===io?a().authenticatedAsset(`/api/fs/raw`,{path:Z.path,allowOutsideWorkspace:pt.allowOutsideWorkspace?`true`:void 0,outsideFileGrant:pt.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||!Vi||Hi){cn.current&&=(URL.revokeObjectURL(cn.current),``),sn(``);return}rn(null),cn.current&&=(URL.revokeObjectURL(cn.current),``),await(r.readFileBinary?r.readFileBinary(Z.path,pt).then(e=>e.dataUrl):(async()=>{let t=await _(`/api/fs/raw`,{query:{path:Z.path,allowOutsideWorkspace:pt.allowOutsideWorkspace?`true`:void 0,outsideFileGrant:pt.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),``):(cn.current=i,i)})()).then(t=>{e||(sn(t),un(Z.path))}).catch(t=>{cn.current&&=(URL.revokeObjectURL(cn.current),``),e||(sn(``),rn(t instanceof Error?t.message:n(`filesView.error.readFileFailed`)),un(null))}).finally(()=>{e||en(!1)})})(),()=>{e=!0}},[r,Vi,Hi,w,i.isDesktop,Z?.path,pt,n]),Q.useEffect(()=>()=>{cn.current&&=(URL.revokeObjectURL(cn.current),``)},[]);let Co=Q.useCallback(()=>Qn(null),[]),wo=Q.useMemo(()=>pr({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:Yi}),[Yi,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)(on,{file:{name:e.name,contents:t,lang:qt(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)(Ue,{children:[(0,$.jsx)(Ve,{asChild:!0,children:(0,$.jsx)(`span`,{className:`inline-flex`,children:t})}),(0,$.jsx)(He,{side:`bottom`,sideOffset:6,children:e})]});return(0,$.jsxs)(`div`,{className:a,children:[Qi&&la&&(0,$.jsxs)($.Fragment,{children:[pn?(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&&An===`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:`${Oe()}+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:`${Oe()}+S`}),"aria-label":n(`filesView.editor.saveAria`,{shortcut:`${Oe()}+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`})}))]}),sa&&vr?o(`${n(`chat.textSelection.title.addToCurrentChat`)} (⌘I)`,(0,$.jsxs)(X,{variant:`ghost`,size:`sm`,onClick:Ji,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)(mt,{shortcut:`⌘+I`})]})):null,(0,$.jsxs)(Je,{onOpenChange:ce,children:[(0,$.jsxs)(Ue,{children:[(0,$.jsx)(Ve,{asChild:!0,children:(0,$.jsx)(`span`,{className:`inline-flex`,children:(0,$.jsx)(Qe,{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)(He,{side:`bottom`,sideOffset:6,children:n(`filesView.editor.openInDesktopApp`)})]}),(0,$.jsxs)(Ze,{align:`end`,className:`w-56 max-h-[70vh] overflow-y-auto`,children:[Ar.map(e=>(0,$.jsxs)(it,{className:`flex items-center gap-2`,onClick:()=>void Fr(e),children:[(0,$.jsx)(xa,{label:e.label,iconDataUrl:e.iconDataUrl}),(0,$.jsx)(`span`,{className:`typography-ui-label text-foreground`,children:e.label})]},e.id)),jr?(0,$.jsxs)(it,{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]})]}),!Vi&&!Ui&&(0,$.jsxs)($.Fragment,{children:[o(n(L?`filesView.editor.disableLineWrap`:`filesView.editor.enableLineWrap`),(0,$.jsx)(X,{variant:`ghost`,size:`sm`,onClick:()=>R(!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`})})),G===`edit`&&(0,$.jsxs)($.Fragment,{children:[o(n(`filesView.editor.findInFile`),(0,$.jsx)(X,{variant:`ghost`,size:`sm`,onClick:e=>{V(!B),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=>{_r(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)($i,{open:gr,onOpenChange:_r,view:Gn.current,variant:`inline`})]})]}),ca&&Qi&&!aa&&(0,$.jsx)(wn,{currentMode:G===`view`?`preview`:`edit`,onToggle:()=>{ha(G===`view`?`edit`:`view`)}}),ea&&o(n(_a()===`preview`?`filesView.editor.switchToEditMode`:`filesView.editor.switchToPreviewMode`),(0,$.jsx)(X,{variant:`ghost`,size:`sm`,onClick:()=>ga(_a()===`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)]`,_a()===`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(_a()===`preview`?`filesView.editor.switchToEditMode`:`filesView.editor.switchToPreviewMode`),"aria-label":n(_a()===`preview`?`filesView.editor.switchToEditMode`:`filesView.editor.switchToPreviewMode`),children:(0,$.jsx)(Y,{name:_a()===`preview`?`eye`:`eye-off`,className:`size-4`})})),Wa(Z?.path??``)&&(0,$.jsx)(wn,{currentMode:Qa(),onToggle:()=>{ka(Qa()===`preview`?`edit`:`preview`)}}),ea&&_a()===`preview`&&Zr&&(0,$.jsxs)(Ue,{children:[(0,$.jsx)(Ve,{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(Vt?`filesView.tts.stopSpeaking`:`filesView.tts.readAloud`),onClick:()=>{Vt?Qt():Ft.trim()&&Ht(Ft)},children:Vt?(0,$.jsx)(Y,{name:`stop`,className:`size-4 text-[color:var(--status-success)]`}):(0,$.jsx)(Y,{name:`volume-up`,className:`size-4`})})}),(0,$.jsx)(He,{sideOffset:8,children:n(Vt?`filesView.tts.stopSpeaking`:`filesView.tts.readAloud`)})]}),oa&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(wn,{currentMode:me,onToggle:()=>Aa(me===`preview`?`edit`:`preview`)}),me===`preview`&&(0,$.jsx)(X,{variant:`ghost`,size:`sm`,onClick:async()=>{let e=Dn.current?.getXml();if(yn.current&&=(clearTimeout(yn.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`})})]}),Xi&&o(n(`filesView.editor.copyFileContents`),(0,$.jsx)(X,{variant:`ghost`,size:`sm`,onClick:async()=>{(await ne(Ft)).ok?(fr(!0),Un.current!==null&&window.clearTimeout(Un.current),Un.current=window.setTimeout(()=>{fr(!1)},1200)):q.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:dr?(0,$.jsx)(Y,{name:`check`,className:`size-4 text-[color:var(--status-success)]`}):(0,$.jsx)(Y,{name:`clipboard`,className:`size-4`})})),Zi&&o(n(`filesView.editor.copyFilePathTitle`,{path:Ki}),(0,$.jsx)(X,{variant:`ghost`,size:`sm`,onClick:async()=>{(await ne(Ki)).ok?(hr(!0),Wn.current!==null&&window.clearTimeout(Wn.current),Wn.current=window.setTimeout(()=>{hr(!1)},1200)):q.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:Ki}),"aria-label":n(`filesView.editor.copyFilePathTitle`,{path:Ki}),children:mr?(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),q.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:()=>re(!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(z?`filesView.editor.exitFullscreen`:`filesView.editor.fullscreen`),(0,$.jsx)(X,{variant:`ghost`,size:`sm`,onClick:()=>re(!z),className:`size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent`,title:n(z?`filesView.editor.exitFullscreen`:`filesView.editor.fullscreen`),"aria-label":n(z?`filesView.editor.exitFullscreen`:`filesView.editor.fullscreen`),children:z?(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)(Fe,{open:Ln,onOpenChange:e=>{e||Rn(!0)},children:(0,$.jsxs)(Me,{showCloseButton:!1,className:`max-w-md`,children:[(0,$.jsxs)(Ae,{children:[(0,$.jsx)(Ne,{children:n(`filesView.unsaved.title`)}),(0,$.jsx)(Pe,{children:n(`filesView.unsaved.description`)})]}),(0,$.jsxs)(je,{children:[(0,$.jsx)(X,{variant:`outline`,onClick:()=>void Ai(),disabled:pn,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&&F&&(0,$.jsx)(`button`,{type:`button`,onClick:()=>I(!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)(Je,{children:[(0,$.jsx)(Qe,{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)(xt,{filePath:Z.path,extension:Z.extension,className:`size-3.5 flex-shrink-0`}),(0,$.jsx)(ja,{name:Z.name}),(0,$.jsx)(Y,{name:`arrow-down-s`,className:`size-4 flex-shrink-0 text-muted-foreground`})]})}),(0,$.jsx)(Ze,{align:`start`,className:`w-[min(24rem,calc(100vw-2rem))] max-w-[calc(100vw-2rem)]`,children:at.map(e=>{let t=Z?.path===e.path;return(0,$.jsxs)(it,{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)(xt,{filePath:e.path,extension:e.extension,className:`size-3.5 flex-shrink-0`}),(0,$.jsx)(ja,{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`)}):at.length>0?(0,$.jsxs)(`div`,{className:`relative min-w-0 flex-1`,children:[gt.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`}),gt.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:ht,className:`flex min-w-0 items-center gap-1 overflow-x-auto scrollbar-none`,style:{scrollbarWidth:`none`,msOverflowStyle:`none`},children:at.map(e=>{let t=Z?.path===e.path;return(0,$.jsxs)(`div`,{title:Oa(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)(xt,{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:[Ki?(0,$.jsx)(`span`,{className:`min-w-0 flex-1 truncate typography-meta text-muted-foreground`,title:Ki,children:Ki}):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&&!B&&!(Qr&&!f)&&(0,$.jsx)(`div`,{ref:se,className:`absolute right-3 top-3 z-30`,onMouseLeave:()=>{W.current>0||ie(!1)},children:H?Eo():(0,$.jsxs)(`div`,{className:`flex items-center gap-1`,children:[ea?(0,$.jsxs)(Ue,{children:[(0,$.jsx)(Ve,{asChild:!0,children:(0,$.jsx)(`span`,{className:`inline-flex`,children:(0,$.jsx)(X,{variant:`ghost`,size:`sm`,onClick:()=>ga(_a()===`preview`?`edit`:`preview`),className:J(`size-8 rounded-lg border border-[var(--interactive-border)] bg-[var(--surface-elevated)] p-0 shadow-sm transition-colors`,_a()===`preview`?`bg-[var(--interactive-selection)] text-[var(--interactive-selection-foreground)] hover:bg-[var(--interactive-selection)]`:`text-muted-foreground hover:text-foreground`),"aria-label":n(_a()===`preview`?`filesView.editor.switchToEditMode`:`filesView.editor.switchToPreviewMode`),title:n(_a()===`preview`?`filesView.editor.switchToEditMode`:`filesView.editor.switchToPreviewMode`),children:(0,$.jsx)(Y,{name:_a()===`preview`?`eye`:`eye-off`,className:`size-4`})})})}),(0,$.jsx)(He,{side:`bottom`,sideOffset:6,children:n(_a()===`preview`?`filesView.editor.switchToEditMode`:`filesView.editor.switchToPreviewMode`)})]}):null,(0,$.jsxs)(Ue,{children:[(0,$.jsx)(Ve,{asChild:!0,children:(0,$.jsx)(`span`,{className:`inline-flex`,onMouseEnter:()=>ie(!0),children:(0,$.jsx)(X,{variant:`ghost`,size:`sm`,onClick:()=>ie(!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)(He,{side:`bottom`,sideOffset:6,children:n(`filesView.editor.controlsTitle`)})]})]})}),(0,$.jsx)(Ie,{outerClassName:`h-full min-w-0`,className:`h-full min-w-0`,children:Z?$t||mo||go?E?(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`)]}):nn?(0,$.jsx)(`div`,{className:`p-3 typography-ui text-[color:var(--status-error)]`,children:nn}):Vi&&Z?bo(Z):Ui?So(Z):Z&&oa&&me===`preview`?(0,$.jsx)(`div`,{className:`h-full overflow-hidden`,style:{minHeight:`400px`},children:(0,$.jsx)(jn,{ref:Dn,xml:Za,onChange:Xa},`${Z.path}:${ge}`)}):Z&&ea&&_a()===`preview`?(0,$.jsxs)(`div`,{className:`h-full overflow-auto p-3`,children:[Ft.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(Ft.length/1024)})}),(0,$.jsx)(Ke,{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)(Rt,{content:Ft,className:`typography-markdown-body`,stripFrontmatter:!0,enableFileReferences:!1})})]}):Z&&aa&&fe===`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?Ft.replace(/<head([^>]*)>/i,`<head$1><base href="${e}">`):Ft})():void 0,className:`w-full h-full border-none`,sandbox:`allow-scripts allow-same-origin allow-forms`,title:n(`filesView.editor.htmlPreviewTitle`)},uo)}):Z&&ca&&G===`view`?To(Z,dn):(0,$.jsxs)(`div`,{className:J(`relative h-full`,Gi&&`overflow-hidden`),ref:Kn,children:[(0,$.jsx)(`div`,{className:J(`h-full`,Gi&&`invisible`),children:(0,$.jsx)(bn,{value:dn,onChange:fn,readOnly:!Qi,vimMode:Yr===`vim`,extensions:to,className:`h-full`,blockWidgets:wo,onViewReady:e=>{Gn.current=e,qi(e),Jn(e=>e+1),window.requestAnimationFrame(()=>{$a(e)})},onViewDestroy:()=>{Gn.current&&=null,br(!1),Sr(null),Jn(e=>e+1)},enableSearch:!0,searchOpen:B,onSearchOpenChange:V,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)}}})}),Gi&&(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&&bt[w]),ko=w?Ct[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)(Be,{ref:N,value:j,onChange:e=>M(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:()=>{M(``),N.current?.focus()},children:(0,$.jsx)(Y,{name:`close`,className:`size-4`})})]}),(0,$.jsxs)(Ue,{children:[(0,$.jsx)(Ve,{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)(He,{side:`bottom`,sideOffset:6,children:n(`filesView.tree.actions.newFileTitle`)})]}),(0,$.jsxs)(Ue,{children:[(0,$.jsx)(Ve,{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)(He,{side:`bottom`,sideOffset:6,children:n(`filesView.tree.actions.newFolderTitle`)})]}),(0,$.jsxs)(Ue,{children:[(0,$.jsx)(Ve,{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)(He,{side:`bottom`,sideOffset:6,children:n(`filesView.tree.actions.refreshTitle`)})]}),(0,$.jsxs)(Ue,{children:[(0,$.jsx)(Ve,{asChild:!0,children:(0,$.jsx)(X,{variant:`ghost`,size:`sm`,onClick:Ri,disabled:Fi.length===0&&Le.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)(He,{side:`bottom`,sideOffset:6,children:n(Li?`sidebarFilesTree.actions.collapseAllTitle`:`sidebarFilesTree.actions.expandAllTitle`)})]})]})}),(0,$.jsx)(Ie,{outerClassName:`flex-1 min-h-0`,className:J(`py-2`,f?`px-3`:`px-2`),children:(0,$.jsx)(`ul`,{className:`flex flex-col`,children:Nt?(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`)]}):At.length>0?At.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:[Ha(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?Bi(w,0):(0,$.jsx)(`li`,{className:`px-2 py-1 typography-meta text-muted-foreground`,children:n(`filesView.state.loading`)})})})]}),jo=e===`full`&&z&&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)(Ie,{outerClassName:`h-full min-w-0`,className:`h-full min-w-0`,children:$t||mo||go?E?(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…`]}):nn?(0,$.jsx)(`div`,{className:`p-4 typography-ui text-[color:var(--status-error)]`,children:nn}):Vi?bo(Z,{fullHeight:!0}):Ui?So(Z):ea&&_a()===`preview`?(0,$.jsxs)(`div`,{className:`h-full overflow-auto p-4`,children:[Ft.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(Ft.length/1024)})}),(0,$.jsx)(Ke,{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)(Rt,{content:Ft,className:`typography-markdown-body`,stripFrontmatter:!0,enableFileReferences:!1})})]}):ca&&G===`view`?To(Z,dn):(0,$.jsxs)(`div`,{className:J(`relative h-full`,Gi&&`overflow-hidden`),children:[(0,$.jsx)(`div`,{className:J(`h-full`,Gi&&`invisible`),children:(0,$.jsx)(bn,{value:dn,onChange:fn,readOnly:!Qi,vimMode:Yr===`vim`,extensions:to,className:`h-full`,onViewReady:e=>{Gn.current=e,qi(e),window.requestAnimationFrame(()=>{$a(e)})},onViewDestroy:()=>{Gn.current&&=null,br(!1),Sr(null)}})}),Gi&&(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)(Ka,{activeDialog:Zn,dialogData:$n,dialogInputValue:tr,onDialogInputChange:nr,isDialogSubmitting:rr,onDialogSubmit:_i,onClose:Co,inputRef:_n}),jo,xr?(0,$.jsx)(yr,{position:xr,onDismiss:()=>Sr(null),onAddToChat:Ji}):null,ae.open?(0,$.jsx)(Q.Suspense,{fallback:null,children:(0,$.jsx)(ya,{popup:ae,onOpenChange:yo,isMobile:f})}):null,f?F?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 Xa(e){return e+1}var Za=e=>({providerID:e.providerID,modelID:e.modelID,variant:e.variant,agent:e.agent});function Qa(e){let t=(0,In.c)(131),{t:n}=te(),{open:r,onOpenChange:i,target:a,projectDirectory:o,submitting:s,allowRunAsGoal:c,onConfirm:u}=e,d=s!==void 0&&s,f=c!==void 0&&c,p;t[0]===f?p=t[1]:(p=f&&!l(),t[0]=f,t[1]=p);let m=p,h=xe(lo),g=xe(co),_=pe(so),v=xe(oo),y=xe(ao),b=xe(io),x=xe(ro),S=xe(no),C;t[2]!==S||t[3]!==b||t[4]!==y||t[5]!==x?(C=()=>Za({providerID:y,modelID:b,variant:x,agent:S}),t[2]=S,t[3]=b,t[4]=y,t[5]=x,t[6]=C):C=t[6];let[w,T]=Q.useState(C),E,D;t[7]!==_||t[8]!==g||t[9]!==h||t[10]!==r||t[11]!==o?(E=()=>{r&&(h({directory:o,source:`todoSendDialog`}),g({directory:o}),_())},D=[r,h,g,_,o],t[7]=_,t[8]=g,t[9]=h,t[10]=r,t[11]=o,t[12]=E,t[13]=D):(E=t[12],D=t[13]),Q.useEffect(E,D);let O,k;t[14]!==S||t[15]!==b||t[16]!==y||t[17]!==x||t[18]!==r?(O=()=>{r&&T(Za({providerID:y,modelID:b,variant:x,agent:S}))},k=[r,y,b,x,S],t[14]=S,t[15]=b,t[16]=y,t[17]=x,t[18]=r,t[19]=O,t[20]=k):(O=t[19],k=t[20]),Q.useEffect(O,k);let A,j;t[21]!==w.modelID||t[22]!==w.providerID||t[23]!==r||t[24]!==v?(A=()=>{if(!r||v.length===0)return;let e=v.find(e=>e.id===w.providerID)??v[0],t=Array.isArray(e?.models)?e.models:[],n=t.some(e=>e.id===w.modelID),i=t[0]?.id??``;e?.id===w.providerID&&n||T(t=>({...t,providerID:e?.id??``,modelID:n?t.modelID:i,variant:``}))},j=[r,v,w.providerID,w.modelID],t[21]=w.modelID,t[22]=w.providerID,t[23]=r,t[24]=v,t[25]=A,t[26]=j):(A=t[25],j=t[26]),Q.useEffect(A,j);let M=to,ee;if(t[27]!==w.modelID||t[28]!==w.providerID||t[29]!==v){let e;t[31]===w.providerID?e=t[32]:(e=e=>e.id===w.providerID,t[31]=w.providerID,t[32]=e),ee=v.find(e)?.models?.find(e=>e.id===w.modelID),t[27]=w.modelID,t[28]=w.providerID,t[29]=v,t[30]=ee}else ee=t[30];let N=ee,P;t[33]===N?P=t[34]:(P=N?.variants?Object.keys(N.variants):[],t[33]=N,t[34]=P);let F=P,I=F.length>0,L,R;t[35]!==w.variant||t[36]!==I?(L=()=>{I||!w.variant||T(eo)},R=[I,w.variant],t[35]=w.variant,t[36]=I,t[37]=L,t[38]=R):(L=t[37],R=t[38]),Q.useEffect(L,R);let ne;t[39]!==w.modelID||t[40]!==w.providerID?(ne=w.providerID.trim().length>0&&w.modelID.trim().length>0,t[39]=w.modelID,t[40]=w.providerID,t[41]=ne):ne=t[41];let z=ne,re;t[42]!==z||t[43]!==w||t[44]!==u||t[45]!==d?(re=()=>{!z||d||u(w)},t[42]=z,t[43]=w,t[44]=u,t[45]=d,t[46]=re):re=t[46];let B=re,V,H;t[47]!==B||t[48]!==r?(V=()=>{if(!r)return;let e=e=>{(e.metaKey||e.ctrlKey)&&e.key===`Enter`&&(e.preventDefault(),B())};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},H=[r,B],t[47]=B,t[48]=r,t[49]=V,t[50]=H):(V=t[49],H=t[50]),Q.useEffect(V,H);let ie;t[51]!==n||t[52]!==a?(ie=n(a===`worktree`?`rightSidebar.contextNotesTodo.sendDialog.title.newWorktree`:`rightSidebar.contextNotesTodo.sendDialog.title.newSession`),t[51]=n,t[52]=a,t[53]=ie):ie=t[53];let ae=ie,oe;t[54]!==i||t[55]!==d?(oe=e=>{d||i(e)},t[54]=i,t[55]=d,t[56]=oe):oe=t[56];let U;t[57]===ae?U=t[58]:(U=(0,$.jsx)(Ae,{children:(0,$.jsx)(Ne,{children:ae})}),t[57]=ae,t[58]=U);let se;t[59]===n?se=t[60]:(se=n(`chat.modelControls.model`),t[59]=n,t[60]=se);let W;t[61]===se?W=t[62]:(W=(0,$.jsx)(`span`,{className:`typography-meta font-medium text-muted-foreground`,children:se}),t[61]=se,t[62]=W);let ce;t[63]===Symbol.for(`react.memo_cache_sentinel`)?(ce=(e,t)=>{T(n=>({...n,providerID:e,modelID:t,variant:``}))},t[63]=ce):ce=t[63];let le;t[64]!==w.modelID||t[65]!==w.providerID?(le=(0,$.jsx)(ot,{providerId:w.providerID,modelId:w.modelID,className:`max-w-[320px] justify-between`,dropdownPortalToBody:!0,onChange:ce}),t[64]=w.modelID,t[65]=w.providerID,t[66]=le):le=t[66];let G;t[67]!==W||t[68]!==le?(G=(0,$.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-1.5`,children:[W,le]}),t[67]=W,t[68]=le,t[69]=G):G=t[69];let K;t[70]===n?K=t[71]:(K=n(`sessions.scheduledTasks.editor.thinkingLevel.label`),t[70]=n,t[71]=K);let ue;t[72]===K?ue=t[73]:(ue=(0,$.jsx)(`span`,{className:`typography-meta font-medium text-muted-foreground`,children:K}),t[72]=K,t[73]=ue);let de=!I,fe;t[74]===Symbol.for(`react.memo_cache_sentinel`)?(fe=e=>T(t=>({...t,variant:e})),t[74]=fe):fe=t[74];let me;t[75]!==w.variant||t[76]!==de||t[77]!==F?(me=(0,$.jsx)(_t,{value:w.variant,options:F,disabled:de,onChange:fe}),t[75]=w.variant,t[76]=de,t[77]=F,t[78]=me):me=t[78];let q;t[79]!==ue||t[80]!==me?(q=(0,$.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[ue,me]}),t[79]=ue,t[80]=me,t[81]=q):q=t[81];let he;t[82]===n?he=t[83]:(he=n(`sessions.scheduledTasks.editor.agent.label`),t[82]=n,t[83]=he);let ge;t[84]===he?ge=t[85]:(ge=(0,$.jsx)(`span`,{className:`typography-meta font-medium text-muted-foreground`,children:he}),t[84]=he,t[85]=ge);let _e;t[86]===Symbol.for(`react.memo_cache_sentinel`)?(_e=e=>T(t=>({...t,agent:e})),t[86]=_e):_e=t[86];let ve;t[87]===w.agent?ve=t[88]:(ve=(0,$.jsx)(tt,{agentName:w.agent,filter:M,dropdownPortalToBody:!0,onChange:_e}),t[87]=w.agent,t[88]=ve);let ye;t[89]!==ge||t[90]!==ve?(ye=(0,$.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[ge,ve]}),t[89]=ge,t[90]=ve,t[91]=ye):ye=t[91];let be;t[92]!==G||t[93]!==q||t[94]!==ye?(be=(0,$.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[G,q,ye]}),t[92]=G,t[93]=q,t[94]=ye,t[95]=be):be=t[95];let Se=`flex items-center gap-3 ${m?`justify-between`:`justify-end`}`,Ce;t[96]!==w.runAsGoal||t[97]!==m||t[98]!==d||t[99]!==n?(Ce=m?(0,$.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[(0,$.jsx)(Le,{checked:w.runAsGoal===!0,onChange:e=>T(t=>({...t,runAsGoal:e})),disabled:d,ariaLabel:n(`sessions.scheduledTasks.editor.goal.aria`)}),(0,$.jsx)(`button`,{type:`button`,className:`truncate typography-ui-label text-muted-foreground transition-colors hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50`,disabled:d,onClick:()=>T($a),children:n(`sessions.scheduledTasks.editor.goal.label`)})]}):null,t[96]=w.runAsGoal,t[97]=m,t[98]=d,t[99]=n,t[100]=Ce):Ce=t[100];let we;t[101]===i?we=t[102]:(we=()=>i(!1),t[101]=i,t[102]=we);let Te;t[103]===n?Te=t[104]:(Te=n(`rightSidebar.contextNotesTodo.sendDialog.actions.cancel`),t[103]=n,t[104]=Te);let Ee;t[105]!==d||t[106]!==we||t[107]!==Te?(Ee=(0,$.jsx)(X,{variant:`ghost`,size:`sm`,onClick:we,disabled:d,children:Te}),t[105]=d,t[106]=we,t[107]=Te,t[108]=Ee):Ee=t[108];let De=!z||d,Oe;t[109]!==d||t[110]!==n?(Oe=n(d?`rightSidebar.contextNotesTodo.sendDialog.actions.sending`:`rightSidebar.contextNotesTodo.sendDialog.actions.send`),t[109]=d,t[110]=n,t[111]=Oe):Oe=t[111];let ke;t[112]!==B||t[113]!==De||t[114]!==Oe?(ke=(0,$.jsx)(X,{size:`sm`,onClick:B,disabled:De,children:Oe}),t[112]=B,t[113]=De,t[114]=Oe,t[115]=ke):ke=t[115];let J;t[116]!==Ee||t[117]!==ke?(J=(0,$.jsxs)(`div`,{className:`flex items-center justify-end gap-2`,children:[Ee,ke]}),t[116]=Ee,t[117]=ke,t[118]=J):J=t[118];let Y;t[119]!==Se||t[120]!==Ce||t[121]!==J?(Y=(0,$.jsxs)(`div`,{className:Se,children:[Ce,J]}),t[119]=Se,t[120]=Ce,t[121]=J,t[122]=Y):Y=t[122];let je;t[123]!==U||t[124]!==be||t[125]!==Y?(je=(0,$.jsxs)(Me,{className:`max-w-md overflow-visible`,children:[U,be,Y]}),t[123]=U,t[124]=be,t[125]=Y,t[126]=je):je=t[126];let Pe;return t[127]!==r||t[128]!==oe||t[129]!==je?(Pe=(0,$.jsx)(Fe,{open:r,onOpenChange:oe,children:je}),t[127]=r,t[128]=oe,t[129]=je,t[130]=Pe):Pe=t[130],Pe}function $a(e){return{...e,runAsGoal:e.runAsGoal!==!0}}function eo(e){return{...e,variant:``}}function to(e){return fe(e.mode)}function no(e){return e.currentAgentName||``}function ro(e){return e.currentVariant||``}function io(e){return e.currentModelId}function ao(e){return e.currentProviderId}function oo(e){return e.providers}function so(e){return e.loadAgents}function co(e){return e.loadAgents}function lo(e){return e.loadProviders}var uo=(e,t)=>e.mode===`target`?`target`:t===e.repoPath?`repo`:`home`,fo=e=>({optional:!0,...e?{directory:e}:{}}),po=async(e,t,n)=>{if(e?.readFile){let r=await e.readFile(t,fo(n));if(typeof r.exists!=`boolean`)throw Error(`Plan file read returned an invalid exists contract`);return r.exists?r.content:null}let r=await _(`/api/fs/read`,{query:{path:t,optional:!0},cache:`no-store`,headers:n?{"x-opencode-directory":n}:void 0});if(!r.ok)throw Error(`Failed to read plan file (${r.status})`);let i=r.headers.get(`x-openchamber-file-exists`);if(i===`true`)return r.text();if(i===`false`)return null;throw Error(`Plan file read returned an invalid exists contract`)},mo=(e,t,r=n())=>{let i=e?.readFile?e:S()?.files;return{queryKey:m.plans.resolved(t.mode,t.sessionId,t.scopeDirectory,t.targetPath,t.repoPath,t.homePath,r),queryFn:async()=>{if(t.mode===`target`){if(!t.targetPath)throw Error(`A target plan path is required`);let e=await po(i,t.targetPath,t.scopeDirectory);return e===null?{kind:`missing`,candidates:[t.targetPath]}:{kind:`resolved`,source:`target`,path:t.targetPath,content:e}}if(!t.repoPath||!t.homePath)throw Error(`Session plan candidates are required`);let e=await po(i,t.repoPath,t.scopeDirectory);if(e!==null)return{kind:`resolved`,source:`repo`,path:t.repoPath,content:e};let n=await po(i,t.homePath,t.scopeDirectory);return n===null?{kind:`missing`,candidates:[t.repoPath,t.homePath]}:{kind:`resolved`,source:`home`,path:t.homePath,content:n}}}},ho=(e,t)=>{let r=(0,In.c)(9),i;r[0]===t?i=r[1]:(i=t===void 0?{}:t,r[0]=t,r[1]=i);let a=i,{files:o}=Lt(),s,c;if(r[2]!==o||r[3]!==e){let t=n();c=N,s=mo(o,e,t),r[2]=o,r[3]=e,r[4]=s,r[5]=c}else s=r[4],c=r[5];let l;return r[6]!==a||r[7]!==s?(l={...s,...a},r[6]=a,r[7]=s,r[8]=l):l=r[8],c(l)},go=(e,t,n,r)=>e.identity===t?e.content===e.baseContent&&!r?{...e,path:n?.path??null,content:n?.content??``,baseContent:n?.content??``}:e:{identity:t,path:n?.path??null,content:n?.content??``,baseContent:n?.content??``},_o=e=>({persisted:e,desired:e,desiredRevision:0,nextAttemptToken:1,inFlight:null,failed:null}),vo=(e,t)=>e.desired===t?e:{...e,desired:t,desiredRevision:e.desiredRevision+1,failed:null},yo=e=>e.desired===e.persisted&&e.inFlight===null&&e.failed===null,bo=(e,t,n)=>({identity:e,path:t,content:n.desired,baseContent:n.persisted}),xo=e=>{if(e.inFlight||e.desired===e.persisted||e.failed?.revision===e.desiredRevision)return[e,null];let t={content:e.desired,revision:e.desiredRevision,token:e.nextAttemptToken};return[{...e,inFlight:t,nextAttemptToken:t.token+1},t]},So=(e,t)=>e.inFlight?.token===t.token?{...e,persisted:t.content,inFlight:null,failed:e.failed&&e.failed.revision>t.revision?e.failed:null}:e,Co=(e,t,n)=>e.inFlight?.token===t.token?{...e,inFlight:null,failed:{revision:t.revision,error:n}}:e,wo=e=>({...e,failed:null}),To=(e,t)=>e===t,Eo=(e,t,n)=>To(t,n)?xo(e):[e,null],Do=e=>e.desired!==e.persisted||e.inFlight!==null,Oo=(e,t,n=32)=>{let r=[];for(let[i,a]of e){if(e.size<=n)return r;i!==t&&yo(a)&&(e.delete(i),r.push(i))}return r},ko=(e,t,n)=>{let r=e.get(t);r&&e.set(t,So(r,n))},Ao=(e,t,n,r)=>{let i=e.get(t);i&&e.set(t,Co(i,n,r))},jo=(e,t)=>e&&t.path===null&&t.content===t.baseContent,Mo=(e,t)=>e&&t!==null,No=e=>{if(!e)return``;let t=e.replace(/\\/g,`/`);return t===`/`?`/`:t.replace(/\/+$/,``)},Po=(e,t)=>{let n=No(e),r=t.replace(/\\/g,`/`).replace(/^\/+/,``).replace(/\/+$/,``);return!n||n===`/`?`/${r}`:`${n}/${r}`},Fo=(e,t,n)=>Po(Po(Po(e,`.opencode`),`plans`),`${t}-${n}.md`),Io=(e,t)=>`~/.opencode/plans/${e}-${t}.md`,Lo=(e,t)=>{let n=e.trim();return n.startsWith(`~`)?n===`~`?t||n:(n.startsWith(`~/`)||n.startsWith(`~\\`))&&t?`${t}${n.slice(1)}`:n:n},Ro=(e,t)=>{let n=No(t.currentDirectory),r=No(t.homeDirectory),i=No(e);return n&&i.startsWith(n+`/`)?i.slice(n.length+1):r&&i===r?`~`:r&&i.startsWith(r+`/`)?`~${i.slice(r.length)}`:i},zo=(e,t,n)=>{let r=No(e.trim());if(!r)return null;let i=n?t.find(e=>e.id===n)??null:null;if(i?.path){let e=No(i.path);if(r===e||r.startsWith(`${e}/`))return{id:i.id,path:i.path}}let a=t.filter(e=>{let t=No(e.path);return r===t||r.startsWith(`${t}/`)}).sort((e,t)=>No(t.path).length-No(e.path).length)[0];return a?{id:a.id,path:a.path}:null},Bo=({targetPath:e=null})=>{let{t}=te(),r=ve(e=>e.currentSessionId),i=ve(e=>e.createSession),a=ve(e=>e.initializeNewOpenChamberSession),o=ve(e=>e.sendMessage),s=ve(e=>e.setCurrentSession),l=Ce(),u=D(e=>e.homeDirectory),d=At(e=>e.planModeEnabled),f=ie(e=>e.projects),p=ie(e=>e.activeProjectId),h=Qt(e=>e.directories),g=Jt()??``,v=c(e=>e.setActiveMainTab),y=c(e=>e.setSessionSwitcherOpen),b=Lt(),x=M(),{isMobile:S}=ct(),{currentTheme:C}=We(),w=Q.useMemo(()=>r?l.find(e=>e.id===r)??null:null,[r,l]),T=Q.useMemo(()=>No((typeof w?.directory==`string`?w.directory:``)||``),[w?.directory]),E=Q.useMemo(()=>No(g||T),[g,T]),O=Q.useMemo(()=>zo(E,f,p),[p,E,f]),k=Q.useMemo(()=>O?h.get(O.path)?.isGitRepo===!0:!1,[O,h]),[A,j]=Q.useState(null),[ee,N]=Q.useState(!1),[F,I]=Q.useState(null),L=Q.useMemo(()=>!F||!T||!u?F:Ro(F,{currentDirectory:T,homeDirectory:u}),[F,T,u]),[R,z]=Q.useState(``),[re,B]=Q.useState(``),{isPlaying:V,play:H,stop:oe}=Mt(),se=xe(e=>e.showMessageTTSButtons),[W,ce]=Q.useState(null),[G,K]=Q.useState(0),de=Q.useMemo(()=>L&&L.split(`/`).pop()||t(`planView.file.defaultName`),[L,t]),fe=Q.useMemo(()=>R.trim()&&ue(R).title||t(`planView.title.default`),[R,t]),pe=Q.useMemo(()=>fe.trim()||t(`planView.title.default`),[fe,t]),[me,q]=Q.useState(!1),[he,ge]=Q.useState(`edit`),_e=Q.useRef(null),ye=Q.useRef(!0),be=Q.useRef(new Map),Se=Q.useRef(new Map),we=Q.useRef(new Map),Te=Q.useRef(new Map),Ee=Q.useRef(()=>{}),De=Q.useRef(null),[Oe,ke]=Q.useState(null),J=Q.useRef(null),Ae=Q.useRef(null);Q.useEffect(()=>{ye.current=!0;let e=Se.current,t=Te.current,n=be.current;return()=>{ye.current=!1;for(let t of e.values())window.clearTimeout(t);e.clear();for(let[e,r]of t){let t=n.get(e);t&&Do(t)&&Ee.current(r)}}},[]);let je=`openchamber:plan:md-viewer-mode`;Q.useEffect(()=>{try{let e=localStorage.getItem(je);if(!e)return;let t=JSON.parse(e);(t===`preview`||t===`edit`)&&ge(t)}catch{}},[]);let Me=Q.useCallback(e=>{ge(e);try{localStorage.setItem(je,JSON.stringify(e))}catch{}},[]),Ne=Q.useRef(!1),Pe=Q.useRef(null),[Fe,Le]=Q.useState(!1);Q.useEffect(()=>{let e=()=>{Ne.current=!1,Pe.current=null,Le(!1)};return document.addEventListener(`mouseup`,e),()=>document.removeEventListener(`mouseup`,e)},[]);let Re=Q.useCallback((e,t)=>{let n=e.split(`
|
|
157
|
-
`),r=Math.max(1,t.start),i=Math.min(n.length,t.end);return r>i?``:n.slice(r-1,i).join(`
|
|
158
|
-
`)},[]),{drafts:ze,commentText:Be,setCommentText:Ge,editingDraftId:qe,setSelection:Ye,saveComment:Xe,cancel:$e,reset:et,startEdit:tt,deleteDraft:nt}=or({source:`plan`,fileLabel:de,language:F&&qt(F)||`markdown`,getCodeForRange:e=>Re(R,ar(e)),toStoreRange:e=>({startLine:e.start,endLine:e.end}),fromDraftRange:e=>({start:e.startLine,end:e.endLine})});Q.useEffect(()=>{ke(null),et()},[R,et]),Q.useEffect(()=>{Ye(Oe)},[Oe,Ye]);let rt=Q.useCallback(()=>{ke(null),$e()},[$e]),at=Q.useCallback((e,t)=>{t&&ke(t),Xe(e,t??Oe??void 0),ke(null)},[Oe,Xe]);Q.useEffect(()=>{if(!Oe)return;let e=e=>{let t=e.target;t.closest(`[data-comment-card="true"]`)||t.closest(`[data-comment-input="true"]`)||t.closest(`.oc-block-widget`)||t.closest(`.cm-gutterElement`)||t.closest(`[data-sonner-toast]`)||t.closest(`[data-sonner-toaster]`)||Be.trim()||(ke(null),$e())},t=window.setTimeout(()=>{document.addEventListener(`click`,e)},100);return()=>{window.clearTimeout(t),document.removeEventListener(`click`,e)}},[$e,Be,qe,S,Oe]);let ot=c(e=>e.editorFontSize),Z=Q.useMemo(()=>{let e=F?qt(F):null,t=!!e&&e!==`markdown`,n=[Sn(C,t?{syntaxColors:!1,fontSize:ot}:{fontSize:ot})],r=st(F||`plan.md`);return r&&n.push(r),t&&e&&n.push(En({language:e,themeName:C.metadata.id,theme:zt(C)})),n.push(P.lineWrapping),n},[C,F,ot]),lt=Q.useMemo(()=>({mode:e?`target`:`session`,sessionId:r,scopeDirectory:T||null,targetPath:e||null,repoPath:!e&&w?.slug&&w?.time?.created&&T?Fo(T,w.time.created,w.slug):null,homePath:!e&&w?.slug&&w?.time?.created?Lo(Io(w.time.created,w.slug),u||null):null}),[r,u,w?.slug,w?.time?.created,T,e]),ut=!!(e||d&<.repoPath&<.homePath),dt=ho(lt,{enabled:ut}),ft=n(),pt=Q.useRef(ft);pt.current=ft;let mt=Q.useMemo(()=>m.plans.resolved(lt.mode,lt.sessionId,lt.scopeDirectory,lt.targetPath,lt.repoPath,lt.homePath,ft),[lt.homePath,lt.mode,lt.repoPath,lt.scopeDirectory,lt.sessionId,lt.targetPath,ft]),ht=Q.useMemo(()=>JSON.stringify(mt),[mt]),gt=ut&&dt.isPending,_t=ut&&dt.isError&&dt.data===void 0,vt=jo(ut&&dt.data?.kind===`missing`,{path:F,content:R,baseContent:re}),bt=dt.data?.kind===`missing`?dt.data.candidates:null;Q.useEffect(()=>{if(!ut){De.current=null,I(null),z(``),B(``),ce(null);return}let e=ut&&dt.data?.kind===`resolved`?{path:dt.data.path,content:dt.data.content}:null,t=De.current,n=be.current.get(ht),r=go({identity:De.current,path:F,content:R,baseContent:re},ht,e,(n?.inFlight??null)!==null),i=De.current!==ht;if(i&&n&&!yo(n)){let t=Te.current.get(ht)?.path??null;r=bo(ht,e?.path??t,n)}if(i&&t){let e=Se.current.get(t);e!==void 0&&(window.clearTimeout(e),Se.current.delete(t));let n=be.current.get(t),r=Te.current.get(t);n&&r&&Do(n)&&Ee.current(r)}De.current=ht,(i||r.path!==F||r.content!==R||r.baseContent!==re)&&(I(r.path),z(r.content),B(r.baseContent),i&&ce(be.current.get(ht)?.failed?.error??null)),(!n||yo(n))&&be.current.set(ht,_o(r.baseContent));for(let e of Oo(be.current,ht))Te.current.delete(e)},[re,R,ht,ut,dt.data,F]);let xt=Q.useCallback(e=>{if(we.current.has(e.identity))return;let n=(async()=>{for(;;){let n=be.current.get(e.identity);if(!n)return;let[r,i]=Eo(n,e.transport,pt.current);if(be.current.set(e.identity,r),!i)return;try{await e.write(i.content),await e.commit(i.content),ko(be.current,e.identity,i);for(let e of Oo(be.current,De.current))Te.current.delete(e);ye.current&&De.current===e.identity&&(B(i.content),ce(null))}catch(n){let r=n instanceof Error?n.message:t(`planView.error.saveFailed`);Ao(be.current,e.identity,i,r);let a=be.current.get(e.identity),o=a?.failed?.revision;ye.current&&De.current===e.identity&&a&&o!==void 0&&o===a.desiredRevision&&ce(r)}}})().finally(()=>{we.current.delete(e.identity)});we.current.set(e.identity,n)},[t]);Ee.current=xt,Q.useEffect(()=>{let e=Se.current,n=be.current.get(ht)??_o(R);be.current.set(ht,vo(n,R));for(let e of Oo(be.current,ht))Te.current.delete(e);if(!Mo(ut,F)||!F){ye.current&&De.current===ht&&ce(null);return}let r=e.get(ht);r!==void 0&&window.clearTimeout(r);let i=b.files?.writeFile,a={identity:ht,transport:ft,path:F,scopeDirectory:lt.scopeDirectory,planKey:mt,planInput:lt,write:async e=>{if(i){if(!(await i(F,e))?.success)throw Error(t(`planView.error.writeFailed`));return}let n=await _(`/api/fs/write`,{method:`POST`,headers:{"Content-Type":`application/json`,...lt.scopeDirectory?{"x-opencode-directory":lt.scopeDirectory}:{}},body:JSON.stringify({path:F,content:e})});if(!n.ok)throw Error(t(`planView.error.writePlanFileFailed`,{status:n.status}))},commit:async e=>{let t={scopeDirectory:lt.scopeDirectory,path:F,options:{optional:!0,...lt.scopeDirectory?{directory:lt.scopeDirectory}:{}}};await x.cancelQueries({queryKey:Mn(t,ft),exact:!0}),await x.cancelQueries({queryKey:mt,exact:!0}),An(x,t,ft,e),x.setQueryData(mt,()=>({kind:`resolved`,source:uo(lt,F),path:F,content:e}))}};Te.current.set(ht,a);let o=window.setTimeout(()=>{e.delete(ht),xt(a)},350);return e.set(ht,o),()=>{window.clearTimeout(o),e.get(ht)===o&&e.delete(ht)}},[R,ht,xt,ut,lt,mt,dt.data?.kind,x,F,b.files,G,t,ft]),Q.useEffect(()=>()=>{_e.current!==null&&window.clearTimeout(_e.current)},[]);let St=Q.useCallback(()=>{v(`chat`),y(!1)},[v,y]),Ct=Q.useCallback(async e=>{if(!O||!A)return;let t=await le(A.action===`improve`?`plan.improve.visible`:`plan.implement.visible`,{plan_title:pe}),n=[{synthetic:!0,text:await le(A.action===`improve`?`plan.improve.instructions`:`plan.implement.instructions`,{plan_title:pe,plan_path:F??``})}];N(!0);try{St();let r=null,c=O.path;if(A.target===`worktree`){if(!k)return;let e=await yt(O.path,Ot());if(!e?.id)return;r=e.id,c=e.path}else{let e=await i(void 0,O.path,null);if(!e?.id)return;r=e.id,c=e.directory??O.path,a(e.id,xe.getState().agents??[])}if(!r)return;let l=U.getState();l.saveSessionModelSelection(r,e.providerID,e.modelID),e.agent.trim()&&(l.saveSessionAgentSelection(r,e.agent),l.saveAgentModelForSession(r,e.agent,e.providerID,e.modelID),l.saveAgentModelVariantForSession(r,e.agent,e.providerID,e.modelID,e.variant||void 0)),s(r,c);let u=e.runAsGoal===!0?[`Implement the plan "${pe}" end-to-end${F?` (plan file: ${F})`:``}.`,`Re-read that file for full details — it is the source of truth.`,``,R].join(`
|
|
159
|
-
`):null;ae.getState().setArmed(e.runAsGoal===!0,u),await o(t,e.providerID,e.modelID,e.agent.trim()||void 0,void 0,void 0,n,e.variant||void 0),j(null)}finally{N(!1)}},[k,R,i,O,a,A,F,St,o,pe,s]),wt=Q.useMemo(()=>pr({drafts:ze,editingDraftId:qe,commentText:Be,onTextChange:Ge,selection:Oe,isDragging:Fe,fileLabel:de,newWidgetId:`plan-new-comment-input`,mapDraftToRange:e=>({start:e.startLine,end:e.endLine}),onSave:at,onCancel:rt,onEdit:e=>{tt(e),ke({start:e.startLine,end:e.endLine})},onDelete:nt}),[Be,nt,qe,rt,at,Fe,Oe,ze,de,Ge,tt]);return(0,$.jsxs)(`div`,{className:`relative flex h-full min-h-0 min-w-0 w-full flex-col overflow-hidden bg-background`,children:[(0,$.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2 border-b border-border/40 px-3 py-1.5 flex-shrink-0`,children:[(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,$.jsx)(`div`,{className:`typography-ui-label font-medium truncate`,children:fe}),W?(0,$.jsx)(X,{variant:`link`,size:`xs`,className:`h-auto p-0 typography-micro text-[color:var(--status-error)]`,title:W,onClick:()=>{let e=be.current.get(ht);e&&(be.current.set(ht,wo(e)),ce(null),K(e=>e+1))},children:t(`planView.error.saveFailed`)}):null]}),F?(0,$.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,$.jsxs)(Je,{children:[(0,$.jsxs)(Ue,{children:[(0,$.jsx)(Ve,{asChild:!0,children:(0,$.jsx)(Qe,{asChild:!0,children:(0,$.jsx)(X,{variant:`ghost`,size:`sm`,className:`h-5 w-5 p-0`,"aria-label":t(`planView.actions.improvePlanAria`),disabled:!R.trim(),children:(0,$.jsx)(Y,{name:`loop-right-ai`,className:`size-4`})})})}),(0,$.jsx)(He,{sideOffset:8,children:t(`planView.actions.improve`)})]}),(0,$.jsxs)(Ze,{align:`end`,children:[(0,$.jsx)(it,{onClick:()=>j({action:`improve`,target:`session`}),children:t(`planView.actions.sendToNewSession`)}),(0,$.jsx)(it,{onClick:()=>j({action:`improve`,target:`worktree`}),disabled:!k,children:t(`planView.actions.sendToNewWorktreeSession`)})]})]}),(0,$.jsxs)(Je,{children:[(0,$.jsxs)(Ue,{children:[(0,$.jsx)(Ve,{asChild:!0,children:(0,$.jsx)(Qe,{asChild:!0,children:(0,$.jsx)(X,{variant:`ghost`,size:`sm`,className:`h-5 w-5 p-0`,"aria-label":t(`planView.actions.implementPlanAria`),disabled:!R.trim(),children:(0,$.jsx)(Y,{name:`code-ai`,className:`size-4`})})})}),(0,$.jsx)(He,{sideOffset:8,children:t(`planView.actions.implement`)})]}),(0,$.jsxs)(Ze,{align:`end`,children:[(0,$.jsx)(it,{onClick:()=>j({action:`implement`,target:`session`}),children:t(`planView.actions.sendToNewSession`)}),(0,$.jsx)(it,{onClick:()=>j({action:`implement`,target:`worktree`}),disabled:!k,children:t(`planView.actions.sendToNewWorktreeSession`)})]})]}),(0,$.jsx)(wn,{currentMode:he,onToggle:()=>Me(he===`preview`?`edit`:`preview`)}),he===`preview`&&se&&(0,$.jsxs)(Ue,{children:[(0,$.jsx)(Ve,{asChild:!0,children:(0,$.jsx)(X,{variant:`ghost`,size:`sm`,className:`h-5 w-5 p-0`,"aria-label":t(V?`planView.tts.stopSpeaking`:`planView.tts.readAloud`),onClick:()=>{V?oe():R.trim()&&H(R)},children:V?(0,$.jsx)(Y,{name:`stop`,className:`h-4 w-4 text-[color:var(--status-success)]`}):(0,$.jsx)(Y,{name:`volume-up`,className:`h-4 w-4`})})}),(0,$.jsx)(He,{sideOffset:8,children:t(V?`planView.tts.stopSpeaking`:`planView.tts.readAloud`)})]}),(0,$.jsx)(X,{variant:`ghost`,size:`sm`,onClick:async()=>{(await ne(R)).ok&&(q(!0),_e.current!==null&&window.clearTimeout(_e.current),_e.current=window.setTimeout(()=>{q(!1)},1200))},className:`h-5 w-5 p-0`,title:t(`planView.actions.copyPlanContents`),"aria-label":t(`planView.actions.copyPlanContents`),children:me?(0,$.jsx)(Y,{name:`check`,className:`h-4 w-4 text-[color:var(--status-success)]`}):(0,$.jsx)(Y,{name:`clipboard`,className:`h-4 w-4`})})]}):null]}),(0,$.jsx)(Qa,{open:A!==null,onOpenChange:e=>{!e&&!ee&&j(null)},target:A?.target??`session`,projectDirectory:O?.path??null,submitting:ee,allowRunAsGoal:!0,onConfirm:Ct}),(0,$.jsx)(`div`,{className:`flex-1 min-h-0 min-w-0 relative`,children:(0,$.jsx)(Ie,{outerClassName:`h-full min-w-0`,className:`h-full min-w-0`,children:gt?(0,$.jsx)(`div`,{className:`p-3 typography-ui text-muted-foreground`,children:t(`planView.state.loading`)}):_t?(0,$.jsx)(`div`,{className:`p-3 typography-ui text-destructive`,children:dt.error instanceof Error?dt.error.message:t(`planView.error.saveFailed`)}):vt&&bt?(0,$.jsx)(`div`,{className:`p-3 typography-ui text-muted-foreground`,children:bt.join(`, `)}):(0,$.jsx)(`div`,{className:`relative h-full`,children:(0,$.jsx)(`div`,{className:`h-full`,children:he===`preview`?(0,$.jsx)(`div`,{className:`h-full overflow-auto p-3`,children:(0,$.jsx)(Ke,{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:t(`planView.error.previewUnavailable`)}),(0,$.jsx)(`div`,{className:`text-sm text-muted-foreground`,children:t(`planView.error.switchToEditMode`)})]}),children:(0,$.jsx)(Rt,{content:R,className:`typography-markdown-body`,enableFileReferences:!1})})}):(0,$.jsx)(`div`,{className:`relative h-full`,ref:Ae,children:(0,$.jsx)(bn,{value:R,onChange:z,readOnly:!1,className:`h-full`,extensions:Z,onViewReady:e=>{J.current=e},onViewDestroy:()=>{J.current=null},blockWidgets:wt,highlightLines:Oe?{start:Math.min(Oe.start,Oe.end),end:Math.max(Oe.start,Oe.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(Oe&&!n.shiftKey&&Math.min(Oe.start,Oe.end)===r&&Math.max(Oe.start,Oe.end)===r)return ke(null),$e(),Ne.current=!1,Pe.current=null,Le(!1),!0;if(S&&Oe&&!n.shiftKey){let e=Math.min(Oe.start,Oe.end,r),t=Math.max(Oe.start,Oe.end,r);return ke({start:e,end:t}),Ne.current=!1,Pe.current=null,Le(!1),!0}if(Ne.current=!0,Pe.current=r,Le(!0),Oe&&n.shiftKey){let e=Math.min(Oe.start,r),t=Math.max(Oe.end,r);ke({start:e,end:t})}else ke({start:r,end:r});return!0},mouseover:(e,t,n)=>{if(!(n instanceof MouseEvent)||n.buttons!==1||!Ne.current||Pe.current===null)return!1;let r=e.state.doc.lineAt(t.from).number,i=Math.min(Pe.current,r),a=Math.max(Pe.current,r);return ke({start:i,end:a}),Le(!0),!1},mouseup:()=>(Ne.current=!1,Pe.current=null,Le(!1),!1)}}})})})})})})]})},Vo=e=>e,Ho=e=>{let t=Vo(e).type;return typeof t==`string`?t:``},Uo=e=>{let t=Vo(e).tool;return typeof t==`string`?t:``},Wo=e=>{let t=Vo(e).text;return typeof t==`string`?t:``},Go=e=>{let t=Ho(e);return t===`tool`?Uo(e).trim().toLowerCase()||`tool`:t||`unknown`},Ko=e=>{if(e.length===0)return``;let t=[];for(let n of e){let e=Go(n);t.includes(e)||t.push(e)}return t.join(` + `)},qo=e=>e.replace(/\s+/g,` `).trim(),Jo=e=>{for(let t of e)if(Ho(t)===`text`){let e=qo(Wo(t));if(e.length===0)continue;return e}let t=e.filter(e=>Ho(e)!==`text`).length;return t===0?``:`${t} attachment${t===1?``:`s`}`},Yo=(e,t,n)=>`${n(e)} / ${n(t)}`,Xo=(e,t,n,r)=>{let i=Yo(e,t,n);return typeof r==`string`&&r.trim().length>0?`${i} · ${r.trim()}`:i},Zo=e=>{if(e===`12h`)return!0;if(e===`24h`)return!1},Qo=(e,t)=>{if(!e||!Number.isFinite(e))return`-`;let n=Zo(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}})},$o={input:0,output:0,reasoning:0,cacheRead:0,cacheWrite:0,total:0},es={user:0,assistant:0,tool:0,other:0},ts=e=>typeof e!=`number`||!Number.isFinite(e)||e<0?0:e,ns=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{...$o,total:ts(n)};if(!n||typeof n!=`object`)return $o;let r=n,i=ts(r.input),a=ts(r.output),o=ts(r.reasoning),s=ts(r.cache?.read),c=ts(r.cache?.write);return{input:i,output:a,reasoning:o,cacheRead:s,cacheWrite:c,total:i+a+o+s+c}},rs=(...e)=>{for(let t of e)if(typeof t==`string`&&t.trim().length>0)return t;return``},is=e=>typeof e==`string`?e.length:typeof e==`number`||typeof e==`boolean`?String(e).length:Array.isArray(e)?e.reduce((e,t)=>e+is(t),0):e&&typeof e==`object`?Object.values(e).reduce((e,t)=>e+is(t),0):0,as=(e,t)=>{let n=e,r=typeof n.type==`string`?n.type:``;if(r===`reasoning`)return{...es,assistant:is(n.text)+is(n.content)};let i=rs(n.text,n.content,n.value,n.source?.value,n.source?.text?.value);return r===`tool`||t===`tool`?{user:0,assistant:0,tool:is(n.input)+is(n.output)+is(n.error)+is(n.call?.input)+is(n.call?.output)+is(n.call?.error)+is(n.raw)+Math.round(is(n.metadata)*.25)+Math.round(is(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}},os=(e,t)=>({user:e.user+t.user,assistant:e.assistant+t.assistant,tool:e.tool+t.tool,other:e.other+t.other}),ss=e=>{let t=Ct(e.info);return t.isUser?`user`:t.role===`assistant`?`assistant`:t.role===`tool`?`tool`:`other`},cs=(e,t)=>{if(e.length===0)return{...es};let n=e.reduce((e,t)=>{let n=ss(t),r={...es};for(let e of t.parts)r=os(r,as(e,n));return os(e,r)},{...es});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)}},ls=e=>e.toLocaleString(R()),us=e=>!Number.isFinite(e)||e<=0?new Intl.NumberFormat(R(),{style:`currency`,currency:`USD`,minimumFractionDigits:2,maximumFractionDigits:2}).format(0):new Intl.NumberFormat(R(),{style:`currency`,currency:`USD`,minimumFractionDigits:e<.01?4:2,maximumFractionDigits:e<.01?4:2}).format(e),ds=(e,t)=>!e||!Number.isFinite(e)?`-`:at(e,t,{month:`short`,day:`numeric`,year:`numeric`,hour:`numeric`,minute:`2-digit`}),fs=(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}},ps=()=>{let e=(0,In.c)(259),{t}=te(),n=c(ms),r=c(hs),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=ve(gs),f=Ce(),p=be(d??``),m=xe(_s),h;e[1]===Symbol.for(`react.memo_cache_sentinel`)?(h=()=>{u.current!==null&&(window.clearTimeout(u.current),u.current=null),o(vs),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 ne(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(ys);let t;e[20]===p?t=e[21]:(t=p.filter(bs),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(ns(t).total>0){n=t;break}}O=n?ns(n):$o,w=It({input:O.input,cache:{read:O.cacheRead,write:O.cacheWrite}}),k=C.reduce(xs,0);let r=0,i=0;for(let e of C){let t=ns(e),n=e.info.time?.created??null,a=e.info.time?.completed??null,o=Ft(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:wt(a),e[22]=a,e[23]=o),E=o;let s=n?kt({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:wt(s);let c=n?.info??null;D=fs(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,ee=M&&M>0?Math.min(999,O.total/M*100):0,N;e[24]===p?N=e[25]:(N=cs(p,[...p].reverse().find(Ss)?.info?.system||``),e[24]=p,e[25]=N);let P=N,F=P.user,I=P.assistant,L=P.tool,R=Math.max(0,O.input-F-I-L),z=F+I+L+R,re=p[0]?.info?.time?.created,B=p.length>0?p[p.length-1]?.info?.time?.created:null,V;e[26]!==S?.title||e[27]!==t?(V=S?.title||t(`contextSidebar.session.untitled`),e[26]=S?.title,e[27]=t,e[28]=V):V=e[28];let H=S?.time?.created??re??null,ie=B??S?.time?.created??null,ae=E&&E.length>0?E:null,oe=T&&T.length>0?T:null,U;e[29]!==I||e[30]!==R||e[31]!==L||e[32]!==F?(U={user:F,assistant:I,tool:L,other:R},e[29]=I,e[30]=R,e[31]=L,e[32]=F,e[33]=U):U=e[33];let se;e[34]!==C.length||e[35]!==z||e[36]!==w||e[37]!==M||e[38]!==j||e[39]!==p.length||e[40]!==H||e[41]!==ie||e[42]!==ae||e[43]!==oe||e[44]!==U||e[45]!==V||e[46]!==O||e[47]!==k||e[48]!==ee||e[49]!==A.length?(se={sessionTitle:V,messagesCount:p.length,userMessagesCount:A.length,assistantMessagesCount:C.length,createdAt:H,lastActivityAt:ie,providerModel:j,tokenBreakdown:O,usagePercent:ee,cacheHitRate:w,totalAssistantCost:k,sessionTpsLabel:ae,lastAssistantTpsLabel:oe,contextLimit:M,breakdown:U,breakdownTotal:z},e[34]=C.length,e[35]=z,e[36]=w,e[37]=M,e[38]=j,e[39]=p.length,e[40]=H,e[41]=ie,e[42]=ae,e[43]=oe,e[44]=U,e[45]=V,e[46]=O,e[47]=k,e[48]=ee,e[49]=A.length,e[50]=se):se=e[50];let W=se;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]!==W.breakdown.user?(le={key:`user`,label:ce,value:W.breakdown.user,color:`var(--status-success)`},e[57]=ce,e[58]=W.breakdown.user,e[59]=le):le=e[59];let G;e[60]===t?G=e[61]:(G=t(`contextSidebar.breakdown.assistant`),e[60]=t,e[61]=G);let K;e[62]!==G||e[63]!==W.breakdown.assistant?(K={key:`assistant`,label:G,value:W.breakdown.assistant,color:`var(--primary-base)`},e[62]=G,e[63]=W.breakdown.assistant,e[64]=K):K=e[64];let ue;e[65]===t?ue=e[66]:(ue=t(`contextSidebar.breakdown.toolCalls`),e[65]=t,e[66]=ue);let de;e[67]!==ue||e[68]!==W.breakdown.tool?(de={key:`tool`,label:ue,value:W.breakdown.tool,color:`var(--status-warning)`},e[67]=ue,e[68]=W.breakdown.tool,e[69]=de):de=e[69];let fe;e[70]===t?fe=e[71]:(fe=t(`contextSidebar.breakdown.other`),e[70]=t,e[71]=fe);let pe;e[72]!==fe||e[73]!==W.breakdown.other?(pe={key:`other`,label:fe,value:W.breakdown.other,color:`var(--surface-muted-foreground)`},e[72]=fe,e[73]=W.breakdown.other,e[74]=pe):pe=e[74];let me;e[75]!==le||e[76]!==K||e[77]!==de||e[78]!==pe?(me=[le,K,de,pe],e[75]=le,e[76]=K,e[77]=de,e[78]=pe,e[79]=me):me=e[79];let q=me,he;e[80]===W.sessionTitle?he=e[81]:(he=(0,$.jsx)(`h2`,{className:`typography-ui-header font-semibold text-foreground truncate`,children:W.sessionTitle}),e[80]=W.sessionTitle,e[81]=he);let ge;e[82]!==W.providerModel.modelName||e[83]!==W.providerModel.providerName?(ge=(0,$.jsxs)(`span`,{children:[W.providerModel.providerName,` / `,W.providerModel.modelName]}),e[82]=W.providerModel.modelName,e[83]=W.providerModel.providerName,e[84]=ge):ge=e[84];let _e;e[85]!==n||e[86]!==W.createdAt?(_e=W.createdAt&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`span`,{children:`·`}),(0,$.jsx)(`span`,{children:ds(W.createdAt,n)})]}),e[85]=n,e[86]=W.createdAt,e[87]=_e):_e=e[87];let ye;e[88]!==ge||e[89]!==_e?(ye=(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:[ge,_e]}),e[88]=ge,e[89]=_e,e[90]=ye):ye=e[90];let Se;e[91]!==he||e[92]!==ye?(Se=(0,$.jsxs)(`div`,{className:`mb-6`,children:[he,ye]}),e[91]=he,e[92]=ye,e[93]=Se):Se=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 Ee;e[98]===W.tokenBreakdown.total?Ee=e[99]:(Ee=ls(W.tokenBreakdown.total),e[98]=W.tokenBreakdown.total,e[99]=Ee);let De;e[100]===W.contextLimit?De=e[101]:(De=W.contextLimit?` / ${ls(W.contextLimit)}`:``,e[100]=W.contextLimit,e[101]=De);let Oe;e[102]!==Ee||e[103]!==De?(Oe=(0,$.jsxs)(`span`,{className:`typography-micro tabular-nums text-muted-foreground/70`,children:[Ee,De]}),e[102]=Ee,e[103]=De,e[104]=Oe):Oe=e[104];let ke;e[105]!==Te||e[106]!==Oe?(ke=(0,$.jsxs)(`div`,{className:`flex items-baseline justify-between`,children:[Te,Oe]}),e[105]=Te,e[106]=Oe,e[107]=ke):ke=e[107];let Ae;e[108]===W.usagePercent?Ae=e[109]:(Ae=W.usagePercent>0&&(0,$.jsx)(`div`,{className:`rounded-full transition-all duration-300`,style:{width:`${Math.max(.5,W.usagePercent)}%`,backgroundColor:W.usagePercent>80?`var(--status-warning)`:`var(--primary-base)`}}),e[108]=W.usagePercent,e[109]=Ae);let je;e[110]===Ae?je=e[111]:(je=(0,$.jsx)(`div`,{className:`mt-2.5 flex h-1 w-full overflow-hidden rounded-full bg-[var(--surface-subtle)]`,children:Ae}),e[110]=Ae,e[111]=je);let Me;e[112]!==t||e[113]!==W.usagePercent?(Me=t(`contextSidebar.context.percentUsed`,{percent:W.usagePercent.toFixed(1)}),e[112]=t,e[113]=W.usagePercent,e[114]=Me):Me=e[114];let Ne;e[115]===Me?Ne=e[116]:(Ne=(0,$.jsx)(`div`,{className:`mt-1.5 typography-micro font-medium tabular-nums text-foreground/80`,children:Me}),e[115]=Me,e[116]=Ne);let Pe;e[117]!==ke||e[118]!==je||e[119]!==Ne?(Pe=(0,$.jsxs)(`div`,{className:`mb-5 rounded-lg bg-[var(--surface-elevated)]/70 px-4 py-3.5`,children:[ke,je,Ne]}),e[117]=ke,e[118]=je,e[119]=Ne,e[120]=Pe):Pe=e[120];let Fe;e[121]===t?Fe=e[122]:(Fe=t(`contextSidebar.stats.messages`),e[121]=t,e[122]=Fe);let X;e[123]===W.messagesCount?X=e[124]:(X=ls(W.messagesCount),e[123]=W.messagesCount,e[124]=X);let Ie;e[125]!==Fe||e[126]!==X?(Ie={label:Fe,value:X},e[125]=Fe,e[126]=X,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]===W.userMessagesCount?Re=e[131]:(Re=ls(W.userMessagesCount),e[130]=W.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]===W.assistantMessagesCount?Ve=e[138]:(Ve=ls(W.assistantMessagesCount),e[137]=W.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(Cs)}),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]===W.totalAssistantCost?Xe=e[155]:(Xe=us(W.totalAssistantCost),e[154]=W.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]!==W.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:W.sessionTpsLabel??`—`})]}):null,e[161]=r,e[162]=t,e[163]=W.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 nt;e[172]===t?nt=e[173]:(nt=t(`contextSidebar.section.lastAssistantMessage`),e[172]=t,e[173]=nt);let rt;e[174]===nt?rt=e[175]:(rt=(0,$.jsx)(`div`,{className:`typography-micro text-muted-foreground mb-2.5`,children:nt}),e[174]=nt,e[175]=rt);let it;e[176]===t?it=e[177]:(it=t(`contextSidebar.tokens.input`),e[176]=t,e[177]=it);let at;e[178]!==it||e[179]!==W.tokenBreakdown.input?(at={label:it,value:W.tokenBreakdown.input,format:`count`},e[178]=it,e[179]=W.tokenBreakdown.input,e[180]=at):at=e[180];let ot;e[181]===t?ot=e[182]:(ot=t(`contextSidebar.tokens.output`),e[181]=t,e[182]=ot);let st;e[183]!==ot||e[184]!==W.tokenBreakdown.output?(st={label:ot,value:W.tokenBreakdown.output,format:`count`},e[183]=ot,e[184]=W.tokenBreakdown.output,e[185]=st):st=e[185];let ct;e[186]===t?ct=e[187]:(ct=t(`contextSidebar.tokens.reasoning`),e[186]=t,e[187]=ct);let Z;e[188]!==ct||e[189]!==W.tokenBreakdown.reasoning?(Z={label:ct,value:W.tokenBreakdown.reasoning,format:`count`},e[188]=ct,e[189]=W.tokenBreakdown.reasoning,e[190]=Z):Z=e[190];let lt;e[191]===t?lt=e[192]:(lt=t(`contextSidebar.tokens.cacheRead`),e[191]=t,e[192]=lt);let ut;e[193]!==lt||e[194]!==W.tokenBreakdown.cacheRead?(ut={label:lt,value:W.tokenBreakdown.cacheRead,format:`count`},e[193]=lt,e[194]=W.tokenBreakdown.cacheRead,e[195]=ut):ut=e[195];let dt;e[196]===t?dt=e[197]:(dt=t(`contextSidebar.tokens.cacheWrite`),e[196]=t,e[197]=dt);let ft;e[198]!==dt||e[199]!==W.tokenBreakdown.cacheWrite?(ft={label:dt,value:W.tokenBreakdown.cacheWrite,format:`count`},e[198]=dt,e[199]=W.tokenBreakdown.cacheWrite,e[200]=ft):ft=e[200];let pt;e[201]===t?pt=e[202]:(pt=t(`contextSidebar.tokens.cacheHit`),e[201]=t,e[202]=pt);let mt=W.cacheHitRate.hasInput?W.cacheHitRate.percent:null,ht;e[203]!==pt||e[204]!==mt?(ht={label:pt,value:mt,format:`percent`},e[203]=pt,e[204]=mt,e[205]=ht):ht=e[205];let gt;e[206]!==r||e[207]!==t||e[208]!==W.lastAssistantTpsLabel?(gt=r?[{label:t(`contextSidebar.tokens.tps`),value:W.lastAssistantTpsLabel,format:`text`}]:[],e[206]=r,e[207]=t,e[208]=W.lastAssistantTpsLabel,e[209]=gt):gt=e[209];let _t;e[210]!==at||e[211]!==st||e[212]!==Z||e[213]!==ut||e[214]!==ft||e[215]!==ht||e[216]!==gt?(_t=(0,$.jsx)(`div`,{className:`grid grid-cols-3 gap-x-4 gap-y-2.5`,children:[at,st,Z,ut,ft,ht,...gt].map(ws)}),e[210]=at,e[211]=st,e[212]=Z,e[213]=ut,e[214]=ft,e[215]=ht,e[216]=gt,e[217]=_t):_t=e[217];let vt;e[218]!==rt||e[219]!==_t?(vt=(0,$.jsxs)(`div`,{className:`mb-5 rounded-lg bg-[var(--surface-elevated)]/70 px-4 py-3.5`,children:[rt,_t]}),e[218]=rt,e[219]=_t,e[220]=vt):vt=e[220];let yt;e[221]!==q||e[222]!==W.breakdownTotal?(yt=(0,$.jsx)(`div`,{className:`flex h-1 w-full overflow-hidden rounded-full bg-[var(--surface-subtle)]`,children:q.map(e=>e.value<=0||W.breakdownTotal<=0?null:(0,$.jsx)(`div`,{style:{width:`${e.value/W.breakdownTotal*100}%`,backgroundColor:e.color}},e.key))}),e[221]=q,e[222]=W.breakdownTotal,e[223]=yt):yt=e[223];let bt;e[224]!==q||e[225]!==W.breakdownTotal?(bt=(0,$.jsx)(`div`,{className:`mt-2 flex flex-wrap items-center gap-x-4 gap-y-1`,children:q.map(e=>{let t=W.breakdownTotal>0?e.value/W.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]=q,e[225]=W.breakdownTotal,e[226]=bt):bt=e[226];let xt;e[227]!==yt||e[228]!==bt?(xt=(0,$.jsxs)(`div`,{className:`mb-6`,children:[yt,bt]}),e[227]=yt,e[228]=bt,e[229]=xt):xt=e[229];let St;e[230]===t?St=e[231]:(St=t(`contextSidebar.section.rawMessages`),e[230]=t,e[231]=St);let Tt;e[232]===St?Tt=e[233]:(Tt=(0,$.jsx)(`div`,{className:`typography-micro text-muted-foreground`,children:St}),e[232]=St,e[233]=Tt);let Et;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=Ct(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=Ko(e.parts),h=c?ns({info:e.info,parts:e.parts}):null,g=l?Jo(e.parts):``,_=Qo(f,n),v=m||`—`,y=(()=>{if(!r||!c||!h)return null;let t=kt({createdAt:f,completedAt:p,outputTokens:h.output,reasoningTokens:h.reasoning,parts:e.parts});if(t===null)return null;let n=wt(t);return n.length>0?n:null})(),x=h?Xo(h.input,h.output,ls,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)(nn,{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],Et=[...p].reverse().map(i),e[234]=s,e[235]=a,e[236]=p,e[237]=r,e[238]=t,e[239]=n,e[240]=Et}else Et=e[240];let Dt;e[247]===Et?Dt=e[248]:(Dt=(0,$.jsx)(`div`,{className:`mt-2.5 space-y-1`,children:Et}),e[247]=Et,e[248]=Dt);let Ot;e[249]!==Tt||e[250]!==Dt?(Ot=(0,$.jsxs)(`div`,{children:[Tt,Dt]}),e[249]=Tt,e[250]=Dt,e[251]=Ot):Ot=e[251];let At;return e[252]!==Se||e[253]!==Pe||e[254]!==tt||e[255]!==vt||e[256]!==xt||e[257]!==Ot?(At=(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:[Se,Pe,tt,vt,xt,Ot]})}),e[252]=Se,e[253]=Pe,e[254]=tt,e[255]=vt,e[256]=xt,e[257]=Ot,e[258]=At):At=e[258],At};function ms(e){return e.timeFormatPreference}function hs(e){return e.showAssistantTps}function gs(e){return e.currentSessionId}function _s(e){return e.providers}function vs(e){return Object.keys(e).length>0?{}:e}function ys(e){return Ct(e.info).role===`assistant`}function bs(e){return Ct(e.info).isUser}function xs(e,t){return e+ts(t.info.cost)}function Ss(e){return Ct(e.info).isUser&&typeof e.info.system==`string`}function Cs(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 ws(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)}%`:ls(Number(e.value)):`—`})]},e.label)}var Ts=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(`/`)?`/`:``)},Es=()=>`react-surface`,Ds=(e,t)=>JSON.stringify([Ts(e),t]),Os=(e,t,n,r)=>JSON.stringify([e,t,Ts(n),r]),ks=(e,t,n)=>n?t:e===t?e:null,As=(e,t)=>e.sessionId===t.sessionId&&Ts(e.directory)===Ts(t.directory),js=(e,t)=>Ts(e)===Ts(t),Ms=e=>({anchor:e,current:e,stack:[]}),Ns=(e,t)=>e??Ms(t),Ps=(e,t)=>e?.current.sessionId??t,Fs=(e,t)=>As(e.current,t)?e:{...e,current:t,stack:[...e.stack,e.current]},Is=e=>{let t=e.stack[e.stack.length-1];return t?{...e,current:t,stack:e.stack.slice(0,-1)}:e},Ls=(e,t,n)=>!js(e.anchor.directory,t.directory)||!js(e.current.directory,t.directory)||n(t.sessionId,t.directory)===!1?{status:`rejected-cross-directory`,state:e}:{status:`navigated`,state:Fs(e,t)},Rs=(e,t,n)=>{let r=e[t];if(!r)return{accepted:!1,navigationBySurfaceId:e};let i=Ls(r,n,()=>!0);return i.status===`navigated`?{accepted:!0,navigationBySurfaceId:i.state===r?e:{...e,[t]:i.state}}:{accepted:!1,navigationBySurfaceId:e}},zs=(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},Bs=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`,Vs=e=>e===`retry`,Hs=e=>e.active&&e.visible&&e.messageCount<=0,Us=e=>e?`load-more`:`ensure`,Ws=e=>e.kind===`has-more`,Gs=(e,t)=>`${e}\n${t}`,Ks=(e,t,n,r)=>r&&!e.has(Gs(t,n)),qs=(e,t)=>({scrollHeight:e,scrollTop:t}),Js=(e,t)=>Math.max(0,e.scrollTop+Math.max(0,t-e.scrollHeight)),Ys=(e,t)=>e&&!t,Xs=e=>e,Zs=e=>!e,Qs=e=>!Ys(e.hasMore,e.isLoading)||!Zs(e.historyVirtualized)?null:qs(e.scrollHeight,e.scrollTop),$s=(e,t,n)=>!!(e&&e.token===t&&e.viewportKey===n),ec=33554432,tc=e=>Math.min(ec,262144+Math.max(0,Math.ceil(e))*64*1024),nc=e=>Math.min(ec,Math.max(0,Math.round(Number.isFinite(e)?e:0))),rc=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}},ic=(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 rc({...e,activeViewKey:t.viewKey,mountedViews:r})}if(t.type===`estimate`){let n=e.mountedViews[t.viewKey],r=nc(t.estimatedBytes);return!n||n.estimatedBytes===r?e:rc({...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:rc({...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??tc(0),lastAccessed:t.now}}})},ac=e=>{let t=(0,In.c)(17),{state:n,error:r,onRetry:i}=e,{t:a}=te();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},oc=e=>{let t=(0,In.c)(151),{surfaceId:n,sessionId:r,directory:i,active:a,canNavigateBack:s,onNavigateSession:c,onNavigateBack:l,onEstimateBytes:u,syncDirectory:d}=e,{t:f}=te(),p=gt(),m,h,g;t[0]!==i||t[1]!==r||t[2]!==n?(h=o(),m=Ts(i),g=Os(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=ge(r,d),E=be(r,d),D=xe(cc),O;t[7]===E?O=t[8]:(O=jt(E),t[7]=E,t[8]=O);let k=O,A;bb0:{if(!k.modelId){let e;t[9]===f?e=t[10]:(e=f(`common.unavailable`),t[9]=f,t[10]=e),A=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];A=e}let j=A,M=he(r,d),N=V(r,d).renderable,P;t[17]===r?P=t[18]:(P=e=>!!e.session.find(e=>e.id===r)?.parentID,t[17]=r,t[18]=P);let F=de(P,d),[L,R]=Q.useState(null),ne,z;t[19]!==F||t[20]!==_?(ne=()=>{R(e=>ks(e,_,F))},z=[F,_],t[19]=F,t[20]=_,t[21]=ne,t[22]=z):(ne=t[21],z=t[22]),Q.useLayoutEffect(ne,z);let re=F||L===_,ie=Te(r,d),ae;t[23]===r?ae=t[24]:(ae=e=>e.streamingMessageIds.get(r)??null,t[23]=r,t[24]=ae);let oe=H(ae),U;t[25]===oe?U=t[26]:(U=e=>oe?e.messageStreamStates.get(oe)?.phase??null:null,t[25]=oe,t[26]=U);let se=H(U),W=M?.type===`busy`||M?.type===`retry`,ce;t[27]!==r||t[28]!==W||t[29]!==T||t[30]!==_?(ce={currentSessionId:r,viewportKey:_,sessionMessageCount:T,sessionIsWorking:W,isMobile:!1},t[27]=r,t[28]=W,t[29]=T,t[30]=_,t[31]=ce):ce=t[31];let{scrollRef:le,notifyContentChange:G,getAnimationHandlers:K,goToBottom:ue,restoreSnapshot:fe,showScrollButton:pe}=St(ce),ve;t[32]!==r||t[33]!==p?(ve=e=>{p.ensureSessionRenderable(r,Vs(e))},t[32]=r,t[33]=p,t[34]=ve):ve=t[34];let ye=I(ve),Se,Ce;t[35]!==a||t[36]!==ye?(Se=()=>{a&&ye(`active`)},Ce=[a,ye],t[35]=a,t[36]=ye,t[37]=Se,t[38]=Ce):(Se=t[37],Ce=t[38]),Q.useEffect(Se,Ce);let we,De;t[39]!==a||t[40]!==ye||t[41]!==T?(we=()=>{if(typeof window>`u`)return;let e=()=>{let e=document.visibilityState!==`hidden`&&document.hasFocus();Hs({active:a,visible:e,messageCount:T})&&ye(`retry`)};return window.addEventListener(`focus`,e),document.addEventListener(`visibilitychange`,e),()=>{window.removeEventListener(`focus`,e),document.removeEventListener(`visibilitychange`,e)}},De=[a,ye,T],t[39]=a,t[40]=ye,t[41]=T,t[42]=we,t[43]=De):(we=t[42],De=t[43]),Q.useEffect(we,De);let Oe,ke;t[44]!==u||t[45]!==T||t[46]!==_?(Oe=()=>{u?.(_,tc(T))},ke=[u,T,_],t[44]=u,t[45]=T,t[46]=_,t[47]=Oe,t[48]=ke):(Oe=t[47],ke=t[48]),Q.useEffect(Oe,ke);let J,Ae;t[49]!==N||t[50]!==fe||t[51]!==r||t[52]!==_?(J=()=>{if(!Ks(w.current,r,_,N))return;let e=Gs(r,_);w.current.add(e),fe()},Ae=[N,fe,r,_],t[49]=N,t[50]=fe,t[51]=r,t[52]=_,t[53]=J,t[54]=Ae):(J=t[53],Ae=t[54]),Q.useEffect(J,Ae);let je;t[55]===Symbol.for(`react.memo_cache_sentinel`)?(je=()=>{y.current=null,S(null)},t[55]=je):je=t[55];let Me;t[56]===_?Me=t[57]:(Me=[_],t[56]=_,t[57]=Me),Q.useLayoutEffect(je,Me);let Ne;t[58]!==x||t[59]!==le||t[60]!==_?(Ne=()=>{let e=y.current,t=le.current;if($s(e,x,_)){if(!t||!Zs(!!v.current?.isHistoryVirtualized())){y.current=null;return}t.scrollTop=Js(e.anchor,t.scrollHeight),y.current=null}},t[58]=x,t[59]=le,t[60]=_,t[61]=Ne):Ne=t[61];let Pe;t[62]!==x||t[63]!==le||t[64]!==E||t[65]!==_?(Pe=[x,le,E,_],t[62]=x,t[63]=le,t[64]=E,t[65]=_,t[66]=Pe):Pe=t[66],Q.useLayoutEffect(Ne,Pe);let Fe;t[67]===m?Fe=t[68]:(Fe={directory:m},t[67]=m,t[68]=Fe);let Ie=Fe,Le=_e(r,d).boundary,ze;t[69]===Le?ze=t[70]:(ze=Ws(Le),t[69]=Le,t[70]=ze);let Be=ze,Ve;t[71]!==ie?.status||t[72]!==Ie||t[73]!==r||t[74]!==p?(Ve=ie?.status===`loading`||p.isLoading(r,Ie),t[71]=ie?.status,t[72]=Ie,t[73]=r,t[74]=p,t[75]=Ve):Ve=t[75];let He=Ve,Ue;t[76]!==m||t[77]!==h||t[78]!==r?(Ue=[`context-panel-load-older`,h,m,r],t[76]=m,t[77]=h,t[78]=r,t[79]=Ue):Ue=t[79];let We;t[80]!==Le||t[81]!==r||t[82]!==d?(We=async()=>{Le.kind===`unknown`&&await Ee(d,r),await me(d,r)},t[80]=Le,t[81]=r,t[82]=d,t[83]=We):We=t[83];let Ge;t[84]!==Ue||t[85]!==We?(Ge={mutationKey:Ue,mutationFn:We},t[84]=Ue,t[85]=We,t[86]=Ge):Ge=t[86];let Ke=ee(Ge),qe=Ke.isPending,Je;t[87]!==He||t[88]!==Be||t[89]!==qe||t[90]!==Ke||t[91]!==le||t[92]!==f||t[93]!==_?(Je=()=>{if(!Ys(Be,qe||He)||Ke.isPending)return;let e=b.current+1;b.current=e;let t=le.current,n=t?Qs({hasMore:Be,isLoading:qe,historyVirtualized:!!v.current?.isHistoryVirtualized(),scrollHeight:t.scrollHeight,scrollTop:t.scrollTop}):null;y.current=n?{token:e,viewportKey:_,anchor:n}:null,Ke.mutateAsync().then(()=>{S(e)},()=>{S(e),q.error(f(`chat.history.loadOlderFailed`))})},t[87]=He,t[88]=Be,t[89]=qe,t[90]=Ke,t[91]=le,t[92]=f,t[93]=_,t[94]=Je):Je=t[94];let Ye=I(Je),Xe=ie?.status===`error`?ie.error:void 0,Ze;t[95]!==a||t[96]!==N||t[97]!==W||t[98]!==E.length||t[99]!==Xe?(Ze=Bs({directoryMatches:!0,requested:a,renderable:N,messageCount:E.length,working:W,error:Xe}),t[95]=a,t[96]=N,t[97]=W,t[98]=E.length,t[99]=Xe,t[100]=Ze):Ze=t[100];let Qe=Ze,$e;t[101]!==a||t[102]!==m||t[103]!==c||t[104]!==r||t[105]!==n?($e={kind:`panel`,surfaceId:n,sessionId:r,directory:m,active:a,capabilities:ft,navigateSession:c},t[101]=a,t[102]=m,t[103]=c,t[104]=r,t[105]=n,t[106]=$e):$e=t[106];let et=$e,tt;t[107]!==ye||t[108]!==Be||t[109]!==Ye?(tt=()=>{if(Us(Be)===`load-more`){Ye();return}ye(`retry`)},t[107]=ye,t[108]=Be,t[109]=Ye,t[110]=tt):tt=t[110];let nt=I(tt),rt;t[111]!==s||t[112]!==l||t[113]!==f?(rt=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[111]=s,t[112]=l,t[113]=f,t[114]=rt):rt=t[114];let it;t[115]!==se||t[116]!==ye||t[117]!==K||t[118]!==ue||t[119]!==Be||t[120]!==qe||t[121]!==Ye||t[122]!==G||t[123]!==ie?.error||t[124]!==nt||t[125]!==le||t[126]!==r||t[127]!==W||t[128]!==E||t[129]!==pe||t[130]!==oe||t[131]!==d||t[132]!==f||t[133]!==Qe||t[134]!==_?(it=(0,$.jsx)(`div`,{className:`relative min-h-0 flex-1`,children:Qe===`cold-loading`||Qe===`working-empty`||Qe===`authoritative-empty`||Qe===`fatal-error`?(0,$.jsx)(ac,{state:Qe,error:ie?.error,onRetry:()=>ye(`retry`)}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Re,{ref:le,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:[Qe===`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:ie?.error}),(0,$.jsx)(X,{type:`button`,variant:`secondary`,size:`xs`,onClick:nt,children:f(`chat.history.retry`)})]}):null,Xs(Be)?(0,$.jsx)(`div`,{className:`flex justify-center pt-3 pb-1`,children:(0,$.jsxs)(X,{type:`button`,variant:`secondary`,size:`sm`,onClick:Ye,disabled:qe,children:[qe?(0,$.jsx)(Y,{name:`loader-4`,className:`size-4 animate-spin`}):null,f(`chat.history.loadOlder`)]})}):null,(0,$.jsx)(Pt,{ref:v,sessionKey:r,virtualizerKey:_,messages:E,sessionIsWorking:W,activeStreamingMessageId:oe,activeStreamingPhase:se,onMessageContentChange:G,getAnimationHandlers:K,isLoadingOlder:qe,scrollToBottom:()=>ue(`instant`),scrollRef:le,directory:d}),(0,$.jsx)(`div`,{className:`h-12`,"aria-hidden":`true`})]})}),(0,$.jsx)(Dt,{visible:pe,onClick:()=>ue(`smooth`)})]})}),t[115]=se,t[116]=ye,t[117]=K,t[118]=ue,t[119]=Be,t[120]=qe,t[121]=Ye,t[122]=G,t[123]=ie?.error,t[124]=nt,t[125]=le,t[126]=r,t[127]=W,t[128]=E,t[129]=pe,t[130]=oe,t[131]=d,t[132]=f,t[133]=Qe,t[134]=_,t[135]=it):it=t[135];let at;t[136]!==k.agentName||t[137]!==k.modelId||t[138]!==k.providerId||t[139]!==j||t[140]!==re?(at=re?(0,$.jsx)(Et,{agentName:k.agentName,providerId:k.providerId,modelId:k.modelId,modelName:j}):null,t[136]=k.agentName,t[137]=k.modelId,t[138]=k.providerId,t[139]=j,t[140]=re,t[141]=at):at=t[141];let ot;t[142]!==r||t[143]!==n||t[144]!==rt||t[145]!==it||t[146]!==at?(ot=(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:[rt,it,at]}),t[142]=r,t[143]=n,t[144]=rt,t[145]=it,t[146]=at,t[147]=ot):ot=t[147];let st;return t[148]!==et||t[149]!==ot?(st=(0,$.jsx)(ht.Provider,{value:et,children:ot}),t[148]=et,t[149]=ot,t[150]=st):st=t[150],st},sc=e=>{let t=(0,In.c)(22),n=ye(),{t:r}=te(),i;t[0]===e.directory?i=t[1]:(i=Ts(e.directory),t[0]=e.directory,t[1]=i);let a=i,o=a===Ts(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:ft,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)(ac,{state:`directory-mismatch`,onRetry:lc,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)(ht.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)(oc,{...e,syncDirectory:n}),t[19]=e,t[20]=n,t[21]=l):l=t[21],l};function cc(e){return e.providers}function lc(){}var uc=e=>{if(!e||typeof e!=`object`)return!1;let t=e;return typeof t.x==`number`&&typeof t.y==`number`},dc=e=>!e||typeof e!=`object`?!1:Object.values(e).every(e=>typeof e==`string`),fc=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`&&uc(t.center)&&dc(t.attributes)&&dc(t.computedStyle)&&Array.isArray(t.ancestry)},pc=({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(`
|
|
160
|
-
`)},mc=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 Gc(e,t)},hc=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}},gc=`data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAwMCAO+/p9sAAAAASUVORK5CYII=`,_c=new Map,vc=new Map,yc=3e4,bc=e=>{let t=_c.get(e);return t?t.expiresAt-Date.now()<=yc?(_c.delete(e),null):t:null},xc=e=>{try{return new URL(e).origin}catch{return e}};function Sc(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 Cc=e=>new Promise((t,n)=>{let r=new FileReader;r.onloadend=()=>t(typeof r.result==`string`?r.result:gc),r.onerror=()=>n(r.error??Error(`Failed to read image blob`)),r.readAsDataURL(e)}),wc=async(e,t=.82)=>{let n=await new Promise(n=>e.toBlob(n,`image/jpeg`,t));return n&&(await Cc(n)).split(`,`,2)[1]||``},Tc=()=>{try{return!!window.__previewCaptureDebug}catch{return!1}},Ec=(...e)=>{Tc()&&[...e]},Dc=(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},Oc=`data-oc-fixed-pin`,kc=(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(Oc,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 Ec(`tagged fixed elements`,a),()=>{for(let e of i)try{e.removeAttribute(Oc)}catch{}}},Ac={name:`oc-fixed-pin`,afterClone(e){let t=e?.clone;if(!(!t||typeof t.querySelectorAll!=`function`))for(let e of t.querySelectorAll(`[${Oc}]`)){let t;try{t=JSON.parse(e.getAttribute(Oc)||``)}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(Oc)}}},jc=`data-oc-scroll-pin`,Mc=e=>{let t=[],n=Dc(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(jc,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(jc)}catch{}},snapshot:n}},Nc={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(`[${jc}]`)){let t;try{t=JSON.parse(e.getAttribute(jc)||``)}catch{e.removeAttribute(jc);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(jc)}}},Pc=async(e,t)=>{try{let n=await fetch(e,{credentials:t});return n.ok?await Cc(await n.blob()):null}catch{return null}},Fc=async e=>{if(e.protocol!==`http:`&&e.protocol!==`https:`)return``;let t=e.origin,n=bc(t);if(n)return`${n.proxyBasePath}${e.pathname}${e.search}${e.hash}`;let r=vc.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 _c.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 _c.delete(t),null;let o={proxyBasePath:i,expiresAt:a};return _c.set(t,o),o}catch{return _c.delete(t),null}finally{vc.delete(t)}})();r||vc.set(t,i);let a=await i;return a?`${a.proxyBasePath}${e.pathname}${e.search}${e.hash}`:``},Ic=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 Pc(n.toString(),`include`)??gc;let r=await Fc(n);return(r?await Pc(r,`include`):null)||(await Pc(n.toString(),`omit`)??gc)}catch{return gc}},Lc=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 Ic(n,t);r=r.replace(e[0],`url("${i}")`)}return r},Rc=e=>e.complete?Promise.resolve():new Promise(t=>{e.addEventListener(`load`,()=>t(),{once:!0}),e.addEventListener(`error`,()=>t(),{once:!0})}),zc=e=>{let t=e.style.cssText;return()=>{e.style.cssText=t}},Bc=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},Vc=(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<=Bc(s)*1.7;!u&&(!d||o.width>t*.72)||(r.push(zc(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]?.()}},Hc=(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(zc(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]?.()}},Uc=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(Hc(e,t,n,r)),i.push(Vc(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 Rc(t);let r=await Ic(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||gc),await Rc(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 Lc(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 Wc(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);Ec(`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:Dc(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=Mc(r);Ec(`nested scroll snapshot`,k.snapshot);let A=()=>{},j=()=>{};try{await r.fonts?.ready.catch(()=>void 0),A=await Uc(r,o,s,{applyLayoutWorkarounds:!1}),n.scrollTo(S,C),j=kc(r,S,C),k.reapply();let e={backgroundColor:Sc(r),cache:`disabled`,dpr:E,embedFonts:!0,fast:!1,height:T,outerShadows:!0,outerTransforms:!0,placeholders:!0,plugins:[Ac,Nc],quality:.82,width:w},a=await(await Nn(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)));Ec(`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 wc(g,.82);return v?await hc(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 Gc(e,t){let n=await Wc(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 Uc(r,o,s,{applyLayoutWorkarounds:!0}),n.scrollTo(c,l);let e=await Fn(i).catch(()=>``);h=await Pn(i,{quality:.82,pixelRatio:f,width:o,height:s,backgroundColor:Sc(r),imagePlaceholder:gc,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 hc(_,o,s,o,s,t):null}catch(e){return console.warn(`[preview] failed to capture iframe DOM screenshot:`,e),null}}var Kc=380,qc=1400,Jc=600,Yc=24,Xc=new Map,Zc=200,Qc=(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`,$c=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},el=e=>Number.isFinite(e)?Math.min(qc,Math.max(Kc,Math.round(e))):Jc,tl=e=>{let t=e?.parentElement?.clientWidth;return!t||t<=0?null:t},nl=(e,t)=>{let n=el(e),r=tl(t);return r===null?n:Math.min(n,Math.max(1,r))},rl=(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},il=(e,t)=>t(e===`chat`?`contextPanel.mode.chat`:e===`file`?`contextPanel.mode.files`:e===`diff`||e===`file-diff`?`contextPanel.mode.diff`:e===`plan`?`contextPanel.mode.plan`:e===`preview`?`contextPanel.mode.preview`:e===`browser`?`contextPanel.mode.browser`:`contextPanel.mode.context`),al=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},ol=(e,t,n)=>{if(e.mode===`chat`){let r=cl(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 al(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`?al(e.targetPath)||n(`contextPanel.mode.diff`):il(e.mode,n)},sl=e=>{if(e.mode===`file`)return e.targetPath?(0,$.jsx)(xt,{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===`plan`)return(0,$.jsx)(Y,{name:`file-text`,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`})},cl=e=>!e||!e.startsWith(`session:`)?null:e.slice(8).trim()||null,ll=(e,t)=>{if(e.size!==t.size)return!1;for(let[n,r]of e)if(t.get(n)!==r)return!1;return!0},ul=(e,t)=>{if(t.length===0)return Xc;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?Xc:r},dl=(e,t)=>{let n=K(e),r=Q.useRef(Xc),i=Q.useRef(t);return i.current=t,Q.useSyncExternalStore(n.subscribe,Q.useCallback(()=>{let e=ul(n.getState().session,i.current);return ll(r.current,e)?r.current:(r.current=e,e)},[n]),()=>Xc)},fl=`new Promise((resolve) => {
|
|
161
|
-
const existing = document.getElementById('__openchamber_desktop_browser_overlay');
|
|
162
|
-
if (existing) existing.remove();
|
|
163
|
-
if (typeof window.__openchamberDesktopBrowserCancelInspect === 'function') {
|
|
164
|
-
try { window.__openchamberDesktopBrowserCancelInspect(); } catch { /* webview not ready */ }
|
|
165
|
-
}
|
|
166
|
-
const overlay = document.createElement('div');
|
|
167
|
-
overlay.id = '__openchamber_desktop_browser_overlay';
|
|
168
|
-
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;';
|
|
169
|
-
document.documentElement.appendChild(overlay);
|
|
170
|
-
const cssEscape = (value) => {
|
|
171
|
-
try { return CSS.escape(value); } catch { return String(value).replace(/[^a-zA-Z0-9_-]/g, '\\\\$&'); }
|
|
172
|
-
};
|
|
173
|
-
const selectorPart = (element) => {
|
|
174
|
-
const tag = element.tagName.toLowerCase();
|
|
175
|
-
if (element.id) return tag + '#' + cssEscape(element.id);
|
|
176
|
-
const className = String(element.className || '').trim().split(/\\s+/).filter(Boolean).slice(0, 3).map((part) => '.' + cssEscape(part)).join('');
|
|
177
|
-
return tag + className;
|
|
178
|
-
};
|
|
179
|
-
const metadata = (element) => {
|
|
180
|
-
const rect = element.getBoundingClientRect();
|
|
181
|
-
const style = getComputedStyle(element);
|
|
182
|
-
const ancestry = [];
|
|
183
|
-
let current = element;
|
|
184
|
-
while (current && current.nodeType === Node.ELEMENT_NODE && ancestry.length < 8) {
|
|
185
|
-
ancestry.unshift({ tag: current.tagName.toLowerCase(), id: current.id || undefined, className: typeof current.className === 'string' ? current.className : undefined, selectorPart: selectorPart(current) });
|
|
186
|
-
current = current.parentElement;
|
|
187
|
-
}
|
|
188
|
-
const attrs = {};
|
|
189
|
-
for (const attr of Array.from(element.attributes || []).slice(0, 16)) attrs[attr.name] = attr.value.slice(0, 300);
|
|
190
|
-
const path = ancestry.map((entry) => entry.selectorPart).join(' > ');
|
|
191
|
-
return {
|
|
192
|
-
frame: 'top',
|
|
193
|
-
tag: element.tagName.toLowerCase(),
|
|
194
|
-
text: String(element.innerText || element.textContent || '').replace(/\\s+/g, ' ').trim().slice(0, 500),
|
|
195
|
-
selector: element.id ? '#' + cssEscape(element.id) : path,
|
|
196
|
-
path,
|
|
197
|
-
bounds: { x: rect.x, y: rect.y, width: rect.width, height: rect.height },
|
|
198
|
-
center: { x: rect.x + rect.width / 2, y: rect.y + rect.height / 2 },
|
|
199
|
-
attributes: attrs,
|
|
200
|
-
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 },
|
|
201
|
-
ancestry,
|
|
202
|
-
};
|
|
203
|
-
};
|
|
204
|
-
const move = (event) => {
|
|
205
|
-
const element = document.elementFromPoint(event.clientX, event.clientY);
|
|
206
|
-
if (!element || element === overlay || element === document.documentElement || element === document.body) return;
|
|
207
|
-
const rect = element.getBoundingClientRect();
|
|
208
|
-
overlay.style.display = 'block';
|
|
209
|
-
overlay.style.left = rect.left + 'px';
|
|
210
|
-
overlay.style.top = rect.top + 'px';
|
|
211
|
-
overlay.style.width = rect.width + 'px';
|
|
212
|
-
overlay.style.height = rect.height + 'px';
|
|
213
|
-
};
|
|
214
|
-
const cleanup = () => {
|
|
215
|
-
window.removeEventListener('mousemove', move, true);
|
|
216
|
-
window.removeEventListener('click', click, true);
|
|
217
|
-
window.removeEventListener('keydown', keydown, true);
|
|
218
|
-
if (window.__openchamberDesktopBrowserCancelInspect === cancel) {
|
|
219
|
-
delete window.__openchamberDesktopBrowserCancelInspect;
|
|
220
|
-
}
|
|
221
|
-
};
|
|
222
|
-
const cancel = () => {
|
|
223
|
-
cleanup();
|
|
224
|
-
overlay.remove();
|
|
225
|
-
resolve(null);
|
|
226
|
-
};
|
|
227
|
-
const click = (event) => {
|
|
228
|
-
event.preventDefault();
|
|
229
|
-
event.stopPropagation();
|
|
230
|
-
const element = document.elementFromPoint(event.clientX, event.clientY);
|
|
231
|
-
const result = element ? metadata(element) : null;
|
|
232
|
-
cleanup();
|
|
233
|
-
overlay.remove();
|
|
234
|
-
resolve(result);
|
|
235
|
-
};
|
|
236
|
-
const keydown = (event) => {
|
|
237
|
-
if (event.key !== 'Escape') return;
|
|
238
|
-
cancel();
|
|
239
|
-
};
|
|
240
|
-
window.__openchamberDesktopBrowserCancelInspect = cancel;
|
|
241
|
-
window.addEventListener('mousemove', move, true);
|
|
242
|
-
window.addEventListener('click', click, true);
|
|
243
|
-
window.addEventListener('keydown', keydown, true);
|
|
244
|
-
});`,pl=`(() => {
|
|
245
|
-
if (typeof window.__openchamberDesktopBrowserCancelInspect === 'function') {
|
|
246
|
-
window.__openchamberDesktopBrowserCancelInspect();
|
|
247
|
-
return;
|
|
248
|
-
}
|
|
249
|
-
const overlay = document.getElementById('__openchamber_desktop_browser_overlay');
|
|
250
|
-
if (overlay) overlay.remove();
|
|
251
|
-
})()`,ml=`(() => {
|
|
252
|
-
if (window.__openchamberSameWebviewNavigationInstalled) return;
|
|
253
|
-
window.__openchamberSameWebviewNavigationInstalled = true;
|
|
254
|
-
|
|
255
|
-
const navigate = (rawUrl) => {
|
|
256
|
-
if (typeof rawUrl !== 'string' || rawUrl.length === 0) return false;
|
|
257
|
-
try {
|
|
258
|
-
const url = new URL(rawUrl, window.location.href);
|
|
259
|
-
if (url.protocol !== 'http:' && url.protocol !== 'https:') return false;
|
|
260
|
-
window.location.assign(url.href);
|
|
261
|
-
return true;
|
|
262
|
-
} catch (_error) {
|
|
263
|
-
return false;
|
|
264
|
-
}
|
|
265
|
-
};
|
|
266
|
-
|
|
267
|
-
const originalOpen = window.open.bind(window);
|
|
268
|
-
window.open = (url, target, features) => {
|
|
269
|
-
if (navigate(url)) return null;
|
|
270
|
-
return originalOpen(url, target, features);
|
|
271
|
-
};
|
|
272
|
-
|
|
273
|
-
document.addEventListener('click', (event) => {
|
|
274
|
-
if (event.defaultPrevented) return;
|
|
275
|
-
const target = event.target;
|
|
276
|
-
if (!(target instanceof Element)) return;
|
|
277
|
-
const anchor = target.closest('a[target="_blank"][href]');
|
|
278
|
-
if (!(anchor instanceof HTMLAnchorElement)) return;
|
|
279
|
-
if (!navigate(anchor.href)) return;
|
|
280
|
-
event.preventDefault();
|
|
281
|
-
event.stopPropagation();
|
|
282
|
-
}, true);
|
|
283
|
-
})()`,hl=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`}},gl=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)},_l=(e,t)=>e.length<=t?e:`${e.slice(0,t-3)}...`,vl=e=>{if(typeof window>`u`)return``;try{return new URL(e||window.location.href,window.location.href).origin}catch{return window.location.origin}},yl=(e,t,n)=>{let r=vl(t);e.postMessage(n,r)},bl=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}},xl=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}},Sl=({rawUrl:e,onNavigate:n})=>{let{t:r}=te(),{currentTheme:i}=We(),[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=ve(e=>e.currentSessionId),j=ve(e=>e.newSessionDraft?.open),M=Nt(e=>e.addDraft),ee=oe(e=>e.addAttachedFile),N=null;try{N=e?new URL(e):null}catch{N=null}let P=N?N.hostname===`localhost`||N.hostname===`127.0.0.1`||N.hostname===`::1`||N.hostname===`[::1]`||N.hostname===`0.0.0.0`:!1,F=N?N.hostname===`0.0.0.0`?new URL(N.toString().replace(`0.0.0.0`,`127.0.0.1`)):N:null,I=F?F.toString():``,L=I?`${t()||`same-origin`}|${I}`:``,R=i.metadata.variant;Q.useEffect(()=>{if(!I||!P){f({status:`idle`});return}let e=bc(L);if(e?.previewToken){f({status:`ready`,proxyBasePath:e.proxyBasePath,previewToken:e.previewToken,expiresAt:e.expiresAt});return}e&&_c.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:I})});if(!e.ok){_c.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){_c.delete(L),t||f({status:`error`,message:r(`contextPanel.preview.proxyError`)});return}_c.set(L,{proxyBasePath:i,previewToken:a,expiresAt:o}),t||f({status:`ready`,proxyBasePath:i,previewToken:a,expiresAt:o})}catch(e){if(_c.delete(L),!t){let t=e instanceof Error?e.message:String(e);f({status:`error`,message:t})}}})(),()=>{t=!0}},[P,L,l,r,I]);let z=F&&(F.protocol===`http:`||F.protocol===`https:`)?F.toString():``,re=P&&d.status===`ready`?`${d.proxyBasePath}|${d.previewToken||``}|${o}`:``;Q.useEffect(()=>{if(!re){m(``);return}let e=!1;return m(``),s(t()).then(t=>{!e&&t&&m(re)}).catch(()=>{}),()=>{e=!0}},[re]);let B=P&&d.status===`ready`&&F&&p===re?(()=>{let e=F.pathname||`/`,t=new URLSearchParams(F.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=F.hash||``;return a().authenticatedAsset(`${d.proxyBasePath}${e}${n?`?${n}`:``}${r}`)})():``,V=P?B:z,H=P?bl(B):z,ie=P&&(d.status===`loading`||d.status===`idle`||p!==re),ae=P&&d.status===`error`,U=Q.useCallback(t=>{let n=A??(j?`draft`:null);if(!n){q.error(r(`contextPanel.preview.inspect.attachNoSession`));return}let i=e||V||``,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 mc(n,t):null;r&&(await ee(r),e=!0)}catch{e=!1}M({sessionKey:n,source:`preview-annotation`,fileLabel:i||`preview`,startLine:1,endLine:1,code:pc({pageUrl:i,viewport:a,devicePixelRatio:o,target:t,screenshotAttached:e,intro:r(`contextPanel.preview.inspect.attachAnnotation`)}),language:`markdown`,text:``}),q.success(r(`contextPanel.preview.inspect.attached`))})()},[ee,M,A,V,j,e,r]);Q.useEffect(()=>{y(!1),T([]),x(!1),C(`all`),D(!1),k(null),g.current=1},[V]),Q.useEffect(()=>{let e=h.current?.contentWindow;!v||!e||yl(e,B,{source:`openchamber-preview-parent`,version:1,type:`set-inspect-mode`,enabled:E})},[v,E,B]),Q.useEffect(()=>{let e=h.current?.contentWindow;!v||!e||yl(e,B,{source:`openchamber-preview-parent`,version:1,type:`set-color-scheme`,scheme:R})},[v,R,B]),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(!P||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>Zc?r.slice(r.length-Zc):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(`
|
|
284
|
-
`),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(fc(a.target)?a.target:null);return}if(a.type===`select`&&fc(a.target)){k(a.target),D(!1),U(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`){Ht(e);return}e&&n(e)}}};return window.addEventListener(`message`,i),()=>{window.removeEventListener(`message`,i)}},[U,P,n,r]);let se=w.filter(e=>e.level===`error`||e.level===`runtime`||e.level===`resource`).length,W=w.filter(e=>Qc(e,S)),ce=Q.useCallback(()=>{let t=[`Preview URL: ${e||V||``}`,`Events: ${w.length}`,``].join(`
|
|
285
|
-
`),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(`
|
|
286
|
-
`);ne(`${t}${n}`).then(e=>{e.ok?q.success(r(`contextPanel.preview.console.copied`)):q.error(r(`contextPanel.preview.console.copyFailed`))})},[w,V,e,r]),le=Q.useCallback(()=>{let t=A??(j?`draft`:null);if(!t){q.error(r(`contextPanel.preview.console.attachNoSession`));return}let n=[`Preview URL: ${e||V||``}`,`Events: ${w.length}`,``].join(`
|
|
287
|
-
`),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(`
|
|
288
|
-
`);M({sessionKey:t,source:`preview-console`,fileLabel:e||V||`preview`,startLine:1,endLine:Math.max(1,w.length),code:`${n}${i}`,language:`text`,text:r(`contextPanel.preview.console.attachAnnotation`)}),q.success(r(`contextPanel.preview.console.attached`))},[M,w,A,V,j,e,r]),[G,K]=Q.useState(`unknown`),ue=Q.useRef(0),de=Q.useRef(0);Q.useEffect(()=>{if(!B){K(`unknown`),ue.current=0,de.current=0;return}let e=!1;return ue.current||(ue.current=Date.now(),de.current=0),K(`unknown`),(async()=>{let t=await(async()=>{try{return await _(B,{method:`GET`,credentials:`include`,cache:`no-store`,redirect:`manual`})}catch{return null}})();if(e)return;if(!t){K(`unreachable`);return}if(t.status===403||t.status===404){_c.delete(L),f({status:`loading`}),u();return}if(t.status!==502){K(`reachable`);return}let n=ue.current||Date.now();if(Date.now()-n<15e3){K(`starting`),de.current+=1;let t=de.current,n=Math.min(2e3,250*2**Math.min(4,t));setTimeout(()=>{e||c()},n).unref?.();return}K(`unreachable`)})(),()=>{e=!0}},[L,B,o]);let fe=P&&d.status===`ready`&&(G===`unknown`||G===`starting`),pe=P&&d.status===`ready`&&G===`unreachable`,me=Q.useCallback(e=>{if(!P||d.status!==`ready`||typeof window>`u`)return;let t=e.currentTarget.contentWindow;if(t)try{let e=t.location,n=vl(B);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{}},[P,B,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:H||e,children:H||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:!V,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:()=>{z&&Ht(z)},title:r(`contextPanel.preview.actions.openExternal`),"aria-label":r(`contextPanel.preview.actions.openExternal`),disabled:!z,children:(0,$.jsx)(Y,{name:`external-link`,className:`h-3.5 w-3.5`})}),P?(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,P?(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`}),se>0?(0,$.jsx)(`span`,{className:`typography-micro text-status-error`,children:se}):null]}):null]}),(0,$.jsxs)(`div`,{className:`relative min-h-0 flex-1 bg-background`,children:[fe?(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`)})]}):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.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`)})]}):V&&(!P||G===`reachable`)?(0,$.jsxs)(`div`,{className:`relative h-full w-full`,children:[(0,$.jsx)(`iframe`,{ref:h,src:V,title:r(`contextPanel.preview.iframeTitle`),className:`h-full w-full border-0`,style:{colorScheme:R},onLoad:me,sandbox:P?`allow-scripts allow-same-origin allow-forms allow-popups allow-downloads`:`allow-scripts allow-forms`},`${V}:${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]}):ie?(0,$.jsx)(`div`,{className:`flex h-full items-center justify-center px-6 text-sm text-muted-foreground`,children:r(`contextPanel.preview.loading`)}):ae?(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:le,disabled:w.length===0,children:r(`contextPanel.preview.console.attach`)}),(0,$.jsx)(X,{type:`button`,size:`xs`,variant:`ghost`,onClick:ce,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]})]})},Cl=()=>typeof window<`u`&&!!window.__OPENCHAMBER_ELECTRON__,wl=({initialUrl:e,directory:n,tabID:r})=>{let{t:i}=te(),o=Q.useRef(null),l=c(e=>e.setContextPanelTabTargetPath),u=hl(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`}),[ee,N]=Q.useState(``),P=ve(e=>e.currentSessionId),F=ve(e=>e.newSessionDraft?.open),I=Nt(e=>e.addDraft),L=oe(e=>e.addAttachedFile),R=Q.useCallback(e=>{!e||e===`about:blank`||!n||!r||l(n,r,e)},[n,r,l]),ne=Q.useCallback((e,t)=>{let n=hl(e),r=n===`about:blank`?``:n;h(r),p(r),t?.inFrame?E(!1):(v(r),E(!!r)),R(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,R]),z=Q.useCallback(e=>{let t=y[e];t&&(S(e),h(t),v(t),p(t),E(!0),R(t))},[y,R]),re=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=xc(g),t=bc(e);if(t?.previewToken){M({status:`ready`,proxyBasePath:t.proxyBasePath,previewToken:t.previewToken,expiresAt:t.expiresAt});return}t&&_c.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}_c.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 B=g&&j.status===`ready`?`${j.proxyBasePath}|${j.previewToken||``}|${C}`:``;Q.useEffect(()=>{if(!B){N(``);return}let e=!1;return N(``),s(t()).then(t=>{!e&&t&&N(B)}).catch(()=>{}),()=>{e=!0}},[B]);let V=Q.useMemo(()=>{if(ee!==B||!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,B,C,ee]),H=V||(j.status===`error`?g:``),ie=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 xl(new URL(`${r}${t.search}${t.hash}`,i).toString())}catch{return``}},[g,j]),ae=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)?``:xl(new URL(`${t.pathname}${t.search}${t.hash}`,n).toString())}catch{return``}},[g,j]),U=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)},[]),se=Q.useCallback(async e=>{let t=P??(F?`draft`:null);if(!t){q.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 mc(n,e):null,l=!!c;c&&await L(c),I({sessionKey:t,source:`preview-annotation`,fileLabel:m||`browser`,startLine:1,endLine:1,code:pc({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:``}),q.success(i(`contextPanel.preview.inspect.attached`))},[L,I,P,m,F,i]),W=Q.useCallback(()=>{let e=o.current;A(null),U(!1),e&&gl(e,pl).catch(()=>{})},[U]);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=ie(e);n&&n!==m&&ne(n,{inFrame:!0});return}if(t.type===`hover`){A(fc(t.target)?t.target:null);return}if(t.type===`select`&&fc(t.target)){A(null),O(!1),U(!1),se(t.target);return}if(t.type===`navigate-preview`){let e=typeof t.url==`string`?t.url:``,n=ae(e);if(n){ne(n);return}e&&ne(e)}}};return window.addEventListener(`message`,e),()=>window.removeEventListener(`message`,e)},[ne,se,m,ie,ae,U]);let ce=Q.useCallback(()=>{let e=o.current;if(!(!e||!m)){if(D){O(!1),W();return}if(V){A(null),O(!0),U(!0);return}O(!0),(async()=>{try{let t=await gl(e,fl);if(O(!1),!t||!fc(t))return;await se(t)}catch{O(!1),q.error(i(`contextPanel.browser.inspectUnavailable`))}})()}},[se,W,m,D,U,V,i]),le=Q.useCallback(()=>{try{let e=o.current?.contentWindow?.location.href||``,t=ae(e);if(t){ne(t,{inFrame:!0});return}}catch{}E(!1),D&&V&&U(!0)},[ne,ae,D,U,V]);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:()=>z(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:()=>z(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:re,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(),ne(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:ce,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 Ht(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:[H?(0,$.jsxs)(`div`,{className:`absolute inset-0`,children:[(0,$.jsx)(`iframe`,{ref:o,src:H,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:le},`${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)(nt,{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]})]})},Tl=({initialUrl:e,directory:t,tabID:n})=>{let{t:r}=te(),i=Q.useRef(null),a=c(e=>e.setContextPanelTabTargetPath),o=hl(e),s=o===`about:blank`?``:o,l=Q.useRef(hl(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=ve(e=>e.currentSessionId),S=ve(e=>e.newSessionDraft?.open),C=Nt(e=>e.addDraft),w=oe(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?.(ml,!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?.(pl).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?.(pl).catch(()=>{})}catch{}}},[t,n,a]);let T=Q.useCallback(e=>{let t=i.current;if(typeof t?.loadURL!=`function`)return;let n=hl(e);try{t.loadURL(n)}catch{}},[]),E=Q.useCallback(()=>{let e=i.current;if(e){if(m){h(!1);try{e.executeJavaScript?.(pl).catch(()=>{})}catch{}return}h(!0),e.executeJavaScript?.(fl,!0).then(async t=>{if(h(!1),!t||!fc(t))return;let n=x??(S?`draft`:null);if(!n){q.error(r(`contextPanel.preview.inspect.attachNoSession`));return}let i=typeof e.getWebContentsId==`function`?e.getWebContentsId():null;if(i==null)return;let a=await L(`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 hc(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:pc({pageUrl:f,viewport:{width:s,height:c},devicePixelRatio:window.devicePixelRatio||1,target:t,screenshotAttached:u,intro:r(`contextPanel.preview.inspect.attachAnnotationWithScreenshot`)}),language:`markdown`,text:``}),q.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 Ht(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)(nt,{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]})]})},El=({directory:e})=>{let{t}=te(),n=Jt()??``,r=e?.trim()||n,i=Q.useMemo(()=>$c(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=Zt(e=>e.setSelectedPath),_=c(e=>e.openContextPreview),v=c(e=>e.allowPromptingSubagentSessions),{themeMode:y,setThemeMode:b,lightThemeId:x,darkThemeId:S,currentTheme:C}=We(),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=el(a?.width??Jc),k=Q.useMemo(()=>{let e=[];for(let t of w){if(t.mode!==`chat`)continue;let n=cl(t.dedupeKey);n&&!e.includes(n)&&e.push(n)}return e},[w]),A=dl(i||void 0,k),[j,M]=Q.useState(!1),[ee,N]=Q.useState(!1),P=Q.useRef(0),F=Q.useRef(O),I=Q.useRef(null),L=Q.useRef(null),R=Q.useRef(null),ne=Q.useRef(new Map),z=Q.useRef(new Map),re=Q.useRef(!1),B=Q.useRef(E),V=Q.useRef(null),[H,ie]=Q.useState({}),ae=Q.useRef(H);ae.current=H;let[oe,U]=Q.useReducer(ic,{activeViewKey:null,tabs:{},mountedViews:{}}),ce=Es(),le=o(),K=Q.useCallback(e=>{let t=ae.current,n=e(t);return n!==t&&(ae.current=n,ie(n),!0)},[]),ue=Q.useCallback(e=>{if(!i)return;U({type:`close-tab`,tabId:e});let t=Ds(i,e);K(e=>{if(!e[t])return e;let n={...e};return delete n[t],n}),u(i,e)},[u,K,i]),de=Q.useCallback(()=>{N(!0),V.current!==null&&window.cancelAnimationFrame(V.current),V.current=window.requestAnimationFrame(()=>{V.current=null,N(!1)})},[]);Q.useEffect(()=>()=>{V.current!==null&&window.cancelAnimationFrame(V.current)},[]),Q.useLayoutEffect(()=>{let e=B.current;if(B.current=E,!E){N(!1);return}e||de()},[E,de]),Q.useEffect(()=>{if(!E||re.current){re.current=E;return}let e=window.requestAnimationFrame(()=>{R.current?.focus({preventScroll:!0})});return re.current=!0,()=>window.cancelAnimationFrame(e)},[E]);let fe=Q.useCallback(e=>{let t=R.current;t&&t.style.setProperty(`--oc-context-panel-width`,`${nl(e,t)}px`)},[]),pe=Q.useCallback(e=>{if(!(!E||D||!i)){try{e.currentTarget.setPointerCapture(e.pointerId)}catch{}L.current=e.pointerId,M(!0),P.current=e.clientX,F.current=O,I.current=O,fe(O),e.preventDefault()}},[fe,i,D,E,O]),me=Q.useCallback(e=>{if(!j||L.current!==e.pointerId)return;let t=P.current-e.clientX,n=nl(F.current+t,R.current);I.current!==n&&(I.current=n,fe(n))},[fe,j]),q=Q.useCallback(e=>{if(L.current!==e.pointerId||!i)return;try{e.currentTarget.releasePointerCapture(e.pointerId)}catch{}let t=nl(I.current??O,R.current);de(),fe(t),I.current=t,p(i,t),M(!1),L.current=null},[fe,i,p,de,O]);Q.useEffect(()=>{j||(I.current=null)},[j]);let he=Q.useCallback(()=>{i&&l(i)},[l,i]),ge=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(),ue(T.id);return}e.key===`Escape`&&(e.preventDefault(),e.stopPropagation(),he())},[T,ue,i,he]);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=Ps(ve?H[Ds(i,ve)]:void 0,ve?cl(T?.dedupeKey):null);Q.useEffect(()=>{if(!E||!i||!ye){se(``,null);return}return se(i,ye),()=>{se(``,null)}},[ye,i,E]),Q.useEffect(()=>{if(!E||!i||!ye||typeof window>`u`)return;let e=()=>{if(document.visibilityState===`hidden`||!document.hasFocus()){G(i,ye,!1);return}W(ye),G(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),G(i,ye,!1)}},[ye,i,E]);let be=Q.useCallback((e,t,n)=>Tt(z.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 z.current.keys())e.has(t)||z.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 ne.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 ne.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 ne.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:bt,payload:r},window.location.origin)}},[ve]);Q.useEffect(()=>{if(typeof window>`u`)return;let e=e=>{if(e.origin!==window.location.origin||!Array.from(ne.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(ne.current.entries()).find(([,t])=>t.contentWindow===e.source);t&&i&&ue(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)},[ue,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=ol(e,A,t),i=_l(n,Yc),a=rl(e.targetPath,r);return{id:e.id,label:i,icon:sl(e),title:a?`${n}: ${a}`:n,closeLabel:t(`contextPanel.tab.closeTabAria`,{label:i})}}),[r,A,t,w]),Ee=T?.mode===`context`?(0,$.jsx)(ps,{}):T?.mode===`plan`?(0,$.jsx)(Bo,{targetPath:T.targetPath}):T?.mode===`preview`?(0,$.jsx)(Sl,{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=Cl()?Tl:wl,je=Q.useMemo(()=>w.some(e=>e.mode===`file`),[w]),Me=T?.mode===`file`,Ne=Me?T?.fileNotice??null:null;Q.useEffect(()=>{let e=new Set(De.map(e=>Ds(i,e.id)));K(t=>{let n=!1,r={};for(let e of De){let a=cl(e.dedupeKey);if(!a)continue;let o=Ds(i,e.id),s=t[o];r[o]=s??Ms({sessionId:a,directory:i}),n||=!s}let a=zs(t,e);return n||=a!==t,n?{...a,...r}:t});for(let t of Object.keys(oe.tabs))(!e.has(Ds(i,t))||oe.tabs[t]?.directory!==i)&&U({type:`close-tab`,tabId:t})},[De,K,i,oe.tabs]);let Pe=ve?Ds(i,ve):null,Fe=ve?cl(T?.dedupeKey):null,Ie=Pe&&Fe?Ns(H[Pe],{sessionId:Fe,directory:i}):void 0,Le=Ie&&Pe?Os(le,Pe,Ie.current.directory,Ie.current.sessionId):null;Q.useLayoutEffect(()=>{if(ce!==`react-surface`||!E||!ve||!Ie||!Pe||!Le){ce===`react-surface`&&U({type:`activate`,viewKey:null,now:Date.now()});return}K(e=>e[Pe]?e:{...e,[Pe]:Ie}),U({type:`touch`,tab:{tabId:ve,sessionId:Ie.anchor.sessionId,directory:Ie.anchor.directory},view:{tabId:ve,surfaceId:Pe,sessionId:Ie.current.sessionId,directory:Ie.current.directory,viewKey:Le},now:Date.now()})},[Ie,Pe,ve,Le,ce,K,E]);let Re=Q.useCallback((e,t,n)=>{let r=Ds(i,e),a=!1;return K(e=>{let i=Rs(e,r,{sessionId:t,directory:n});return a=i.accepted,i.navigationBySurfaceId}),a},[K,i]),ze=Q.useCallback(e=>{let t=Ds(i,e);K(e=>{let n=e[t];if(!n)return e;let r=Is(n);return r===n?e:{...e,[t]:r}})},[K,i]),Be=(0,$.jsxs)(`header`,{className:`flex h-10 items-stretch border-b border-transparent`,children:[(0,$.jsx)(an,{items:Te,activeId:T?.id??null,onSelect:e=>{i&&m(i,e)},onClose:e=>{ue(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:ge,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:he,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`})})]})]}),Ve=E?D?{"--oc-context-panel-width":`100%`,width:`100%`,minWidth:`100%`,maxWidth:`100%`}:{width:`min(var(--oc-context-panel-width), 100%)`,minWidth:`min(${Kc}px, 100%)`,maxWidth:`100%`,"--oc-context-panel-width":`${j?I.current??O:O}px`}:{"--oc-context-panel-width":`${j?I.current??O:O}px`,width:0,minWidth:0,maxWidth:0,opacity:0,overflow:`hidden`,visibility:`hidden`};return(0,$.jsxs)(`aside`,{ref:R,"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||ee?`transition-none`:`transition-[width] duration-200 ease-in-out`),onKeyDownCapture:_e,style:Ve,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:pe,onPointerMove:me,onPointerUp:q,onPointerCancel:q,role:`separator`,"aria-orientation":`vertical`,"aria-label":t(`contextPanel.actions.resizePanelAria`)}),Be,Ne===`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)(Ya,{mode:`editor-only`,isActive:E&&Me})}):null,ce===`legacy-iframe`&&De.map(e=>{let n=cl(e.dedupeKey);if(!n)return null;let r=be(e.id,n,e.readOnly);return r?(0,$.jsx)(`iframe`,{ref:t=>{if(!t){ne.current.delete(e.id);return}ne.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}),ce===`react-surface`?Object.values(oe.mountedViews).map(e=>{let t=H[Ds(i,e.tabId)],n=E&&ve===e.tabId&&Le===e.viewKey;return(0,$.jsx)(Q.Activity,{name:`context-panel-session-${e.sessionId}`,mode:n?`visible`:`hidden`,children:(0,$.jsx)(sc,{surfaceId:e.surfaceId,sessionId:e.sessionId,directory:e.directory,active:n,canNavigateBack:n&&!!t?.stack.length,onNavigateSession:(t,n)=>Re(e.tabId,t,n),onNavigateBack:()=>ze(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)(Yi,{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{Kn as _,va as a,ta as c,na as d,Yi as f,Hr as g,Or as h,Ya as i,ra as l,Jr as m,Bo as n,oa as o,Yr as p,Qa as r,aa as s,El as t,ia as u};
|