@openchambery/web 1.19.1 → 1.19.2-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/dist/assets/{AssistantView-H6shoxl5.js → AssistantView-DGqRio2e.js} +1 -1
  2. package/dist/assets/{ChatContainer-Daa5W1sk.js → ChatContainer-CM43Pxln.js} +6 -6
  3. package/dist/assets/ContextPanel-Bp3ZKAJE.js +288 -0
  4. package/dist/assets/{DiagramView-BfyN-k_0.js → DiagramView-BH5YxFAL.js} +1 -1
  5. package/dist/assets/{MarkdownRendererImpl-DNhuoybt.js → MarkdownRendererImpl-Cmm9i5Vj.js} +1 -1
  6. package/dist/assets/{MobileDetailNavigation-B21nwHVB.js → MobileDetailNavigation-nITHp7W3.js} +1 -1
  7. package/dist/assets/{MobileShareBridge-CVuIIOkq.js → MobileShareBridge-C_QaKaB6.js} +1 -1
  8. package/dist/assets/MobileSurface-CjpCviv6.js +2 -0
  9. package/dist/assets/{MultiRunWindow-BHa95dXi.js → MultiRunWindow-B1ALyR36.js} +1 -1
  10. package/dist/assets/{SettingsView-TLcvwH03.js → SettingsView-BW8d_8pw.js} +1 -1
  11. package/dist/assets/{SettingsWindow-BUIQkiO2.js → SettingsWindow-7SmQV5GW.js} +1 -1
  12. package/dist/assets/{TerminalView-BIk-diLF.js → TerminalView-C7EFF7ZS.js} +1 -1
  13. package/dist/assets/{ToolOutputDialog-ClZXQ2ee.js → ToolOutputDialog-Cba_60bU.js} +1 -1
  14. package/dist/assets/appThemeRegistry-Co5dwWx_.js +2 -0
  15. package/dist/assets/{gitApi-G6u4mIJa.js → gitApi-DaTTo7St.js} +1 -1
  16. package/dist/assets/{insertionBoundaries-lo4zrlFI.js → insertionBoundaries-BoIHXczc.js} +1 -1
  17. package/dist/assets/{main-8r9WN9j6.js → main-IyYkGXkX.js} +2 -2
  18. package/dist/assets/{main-tsB0yCVi.js → main-WVLfE2Df.js} +5 -5
  19. package/dist/assets/{miniChat-B4rTOWDV.js → miniChat-CAAQzm9R.js} +2 -2
  20. package/dist/assets/{mobile-Dd71U7If.js → mobile-BiCmfs5Y.js} +2 -2
  21. package/dist/assets/{multirun-DYvDqrOC.js → multirun-DPXG-TWE.js} +1 -1
  22. package/dist/assets/{projectMeta-B6E8Feg8.js → projectMeta-B0YA9FxC.js} +1 -1
  23. package/dist/assets/{radio-DswLr47h.js → radio-CUea8K8R.js} +1 -1
  24. package/dist/assets/{renderElectronMiniChatApp-Dz39AM3_.js → renderElectronMiniChatApp-CGA16ZyN.js} +2 -2
  25. package/dist/assets/{renderMobileApp-DHc-J2Fc.js → renderMobileApp-D9fgFt6E.js} +4 -4
  26. package/dist/assets/{runtimeConfig-Cf_G38k8.js → runtimeConfig-BJ3S27Ah.js} +1 -1
  27. package/dist/assets/runtimeEndpointReset-C9pWVmjf.js +4 -0
  28. package/dist/assets/{shikiHighlight-BzV876r7.js → shikiHighlight-_cgskSv2.js} +1 -1
  29. package/dist/assets/{useAppFontEffects-Cgp7KwNF.js → useAppFontEffects-B_a7MLYy.js} +5 -5
  30. package/dist/assets/{useDesktopWindowControlsLayout-DPffJ02b.js → useDesktopWindowControlsLayout-D-74BaI3.js} +1 -1
  31. package/dist/assets/{useEffectiveDirectory-DSrxWL-k.js → useEffectiveDirectory-DWwrRiBF.js} +1 -1
  32. package/dist/assets/{useMobileNavigationStore-B-eF_OVT.js → useMobileNavigationStore-7LBI6idi.js} +1 -1
  33. package/dist/assets/{useSessionAutoCleanup-0GyoJ4_9.js → useSessionAutoCleanup-Buvg8rem.js} +1 -1
  34. package/dist/assets/{useWorkerHighlightedLines-CcNKZE-g.js → useWorkerHighlightedLines-BdlVg3Sj.js} +1 -1
  35. package/dist/index.html +2 -2
  36. package/dist/mini-chat.html +2 -2
  37. package/dist/mobile.html +2 -2
  38. package/package.json +1 -1
  39. package/server/index.js +4 -0
  40. package/server/lib/scheduled-tasks/DOCUMENTATION.md +25 -2
  41. package/server/lib/scheduled-tasks/runtime.js +234 -3
  42. package/server/lib/scheduled-tasks/runtime.test.js +221 -0
  43. package/dist/assets/ContextPanel-BTUao9L2.js +0 -288
  44. package/dist/assets/MobileSurface-BJ9fqB5L.js +0 -2
  45. package/dist/assets/appThemeRegistry-CyE8QPIG.js +0 -2
  46. package/dist/assets/runtimeEndpointReset-51jb_Bfy.js +0 -4
@@ -1,288 +0,0 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/ToolOutputDialog-ClZXQ2ee.js","assets/rolldown-runtime-C0FnF6B9.js","assets/useUIStore-Wyu09VUF.js","assets/vendor-zustand-B4dlGEM2.js","assets/vendor-base-ui-CnHfUmDN.js","assets/persistence-aCOlo6ew.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-BL4PvBYZ.js","assets/store-Dge7C5E4.js","assets/vendor-aparajita-capacitor-secure-storage-CjQdwfjS.js","assets/dialog-CD0j-atu.js","assets/utils-CJdWZupK.js","assets/vendor-class-variance-authority-BLUaYARZ.js","assets/vendor-tailwind-merge-BicNWLTg.js","assets/Icon-Bs6GJIoO.js","assets/button-BkTMa7Qj.js","assets/useThemeSystem-DMzWVJaW.js","assets/markdownTheme-DidS-jC5.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-CyE8QPIG.js","assets/platform-ulFAVx1H.js","assets/vendor-opencode-sdk-C07HQypa.js","assets/useMobileNavigationStore-B-eF_OVT.js","assets/vendor-tanstack-react-query-D7pys_c9.js","assets/vendor-sonner-DVzioF3d.js","assets/useAssistantUIStore-DxZsjSPQ.js","assets/vendor-fuse.js-DB5wDJbI.js","assets/markdown-worker-9Sn2jsDp.js","assets/useEffectiveDirectory-DSrxWL-k.js","assets/useWorkerHighlightedLines-CcNKZE-g.js","assets/tooltip-GC3dg3gO.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-Wyu09VUF.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-aCOlo6ew.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-ulFAVx1H.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 ne,r as L,t as re}from"./clipboard-BL4PvBYZ.js";import{i as R,t as ie}from"./store-Dge7C5E4.js";import{Bt as z,Cr as B,En as V,Gt as H,Kt as ae,Lo as oe,Lr as U,Oo as W,Ot as G,Qa as K,Sa as se,Wn as ce,_n as q,an as le,dn as ue,gn as de,hn as fe,in as pe,jn as me,l as he,la as ge,nn as _e,on as ve,qa as ye,rn as be,si as xe,so as Se,ta as Ce,to as we,xa as Te,zt as Ee}from"./useMobileNavigationStore-B-eF_OVT.js";import{a as De,i as Oe,n as ke,o as Ae,r as je,t as Me}from"./dialog-CD0j-atu.js";import{a as Ne,i as Pe,o as Fe,t as J}from"./utils-CJdWZupK.js";import{n as Y}from"./Icon-Bs6GJIoO.js";import{t as X}from"./button-BkTMa7Qj.js";import{A as Ie,J as Le,j as Re,o as ze}from"./projectMeta-B6E8Feg8.js";import{t as Be}from"./input-Ca2tUhgN.js";import{i as Ve,n as He,t as Ue}from"./tooltip-GC3dg3gO.js";import{n as We,t as Ge}from"./useThemeSystem-DMzWVJaW.js";import{A as Ke,C as qe,K as Je,P as Ye,S as Xe,V as Ze,_ as Qe,c as $e,h as et,n as tt,p as nt,s as rt,v as it,w as at,x as ot,y as st}from"./radio-DswLr47h.js";import{i as ct}from"./OverlayScrollbar-VZKKu-cu.js";import{f as Z,g as lt,h as ut,x as dt}from"./markdownTheme-DidS-jC5.js";import{G as ft,H as pt,I as mt,J as ht,N as gt,O as _t,P as vt,R as yt,X as bt,Y as xt,Z as St,a as Ct,c as wt,d as Tt,h as Et,k as Dt,l as Ot,m as kt,n as At,o as jt,p as Mt,q as Nt,rt as Pt,tt as Ft,u as It,z as Lt}from"./ChatContainer-Daa5W1sk.js";import{n as Rt}from"./useRuntimeAPIs-DSLXJybW.js";import{M as zt,N as Bt,b as Vt,g as Ht,x as Ut,y as Wt}from"./insertionBoundaries-lo4zrlFI.js";import{i as Gt,n as Kt,t as qt,u as Jt}from"./appThemeRegistry-CyE8QPIG.js";import{a as Yt}from"./url-BQHM4bC4.js";import{f as Xt,g as Zt,h as Qt,m as $t,p as en}from"./markdown-worker-9Sn2jsDp.js";import{n as tn}from"./useEffectiveDirectory-DSrxWL-k.js";import{o as nn}from"./FadeInOnReveal-BpIMrqet.js";import{g as rn,n as an}from"./useWorkerHighlightedLines-CcNKZE-g.js";import{t as on}from"./sortable-tabs-strip-Bl26ebY_.js";import{a as sn,c as cn,d as ln,f as un,l as dn,m as fn,n as pn,o as mn,p as hn,s as gn,t as _n,u as vn}from"./vendor-pierre-diffs-BenIz2TM.js";import{a as yn,c as bn,i as xn,l as Sn,n as Cn,o as wn,r as Tn,s as En,t as Dn}from"./shikiHighlight-BzV876r7.js";import{n as On,r as kn,t as An}from"./collapsible-CVL-5iEB.js";import{n as jn,s as Mn,t as Nn}from"./fileQueries-_VUJM8AE.js";import{t as Pn}from"./vendor-zumer-snapdom-yq9vlCKr.js";import{n as Fn,t as In}from"./vendor-html-to-image-BDMm2v6d.js";var Q=e(T(),1),Ln=j(),$=w(),Rn=e(E(),1);function zn(){return new Worker(_n,{type:`module`})}var Bn=[`typescript`,`javascript`,`tsx`,`jsx`,`json`,`markdown`],Vn={unified:{poolSize:1,totalASTLRUCacheSize:24,lineDiffType:`none`},split:{poolSize:2,totalASTLRUCacheSize:56,lineDiffType:`word-alt`}},Hn,Un,Wn=e=>{let t=Vn[e],n=new hn({workerFactory:zn,poolSize:t.poolSize,totalASTLRUCacheSize:t.totalASTLRUCacheSize},{theme:{light:`pierre-light`,dark:`pierre-dark`},langs:Bn,lineDiffType:t.lineDiffType,preferredHighlighter:`shiki-wasm`});return n.initialize(),n},Gn=e=>{if(!(typeof window>`u`))return e===`split`?(Un??=Wn(`split`),Un):(Hn??=Wn(`unified`),Hn)},Kn=e=>{let t=(0,Ln.c)(7),{children:n,renderTheme:r}=e,i=Jn(`unified`),a=Jn(`split`),o,s;t[0]!==r||t[1]!==a||t[2]!==i?(o=()=>{i&&i.setRenderOptions({theme:r,lineDiffType:Vn.unified.lineDiffType}),a&&a.setRenderOptions({theme:r,lineDiffType:Vn.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},qn=e=>{let t=(0,Ln.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,qt(a),qt(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)(Kn,{renderTheme:s,children:n}),t[8]=n,t[9]=s,t[10]=c):c=t[10],c},Jn=e=>{let t=(0,Ln.c)(2),n=e===void 0?`unified`:e,r;return t[0]===n?r=t[1]:(r=Gn(n),t[0]=n,t[1]=r),r};function Yn(e){let t=(0,Ln.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)(kn,{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)(On,{}),t[36]=N):N=t[36];let P;t[37]!==k||t[38]!==M||t[39]!==ee?(P=(0,$.jsxs)(An,{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)(at,{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 ne;t[45]===Symbol.for(`react.memo_cache_sentinel`)?(ne=(0,$.jsx)(Y,{name:`edit`,className:`size-4 mr-2`}),t[45]=ne):ne=t[45];let L;t[46]===s?L=t[47]:(L=s(`inlineComment.actions.editComment`),t[46]=s,t[47]=L);let re;t[48]!==r||t[49]!==L?(re=(0,$.jsxs)(st,{onClick:r,children:[ne,L]}),t[48]=r,t[49]=L,t[50]=re):re=t[50];let R;t[51]===Symbol.for(`react.memo_cache_sentinel`)?(R=(0,$.jsx)(Y,{name:`delete-bin`,className:`size-4 mr-2`}),t[51]=R):R=t[51];let ie;t[52]===s?ie=t[53]:(ie=s(`inlineComment.actions.deleteComment`),t[52]=s,t[53]=ie);let z;t[54]!==i||t[55]!==ie?(z=(0,$.jsxs)(st,{onClick:i,className:`text-destructive`,children:[R,ie]}),t[54]=i,t[55]=ie,t[56]=z):z=t[56];let B;t[57]!==re||t[58]!==z?(B=(0,$.jsxs)(Qe,{children:[I,(0,$.jsxs)(it,{align:`end`,children:[re,z]})]}),t[57]=re,t[58]=z,t[59]=B):B=t[59];let V;t[60]!==F||t[61]!==B?(V=(0,$.jsxs)(`div`,{className:`flex items-start justify-between gap-2 p-3`,children:[F,B]}),t[60]=F,t[61]=B,t[62]=V):V=t[62];let H;t[63]!==V||t[64]!==S?(H=(0,$.jsx)(Sn,{render:S,children:V}),t[63]=V,t[64]=S,t[65]=H):H=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)(En,{onClick:r,children:[ae,oe]}),t[69]=r,t[70]=oe,t[71]=U):U=t[71];let W;t[72]===Symbol.for(`react.memo_cache_sentinel`)?(W=(0,$.jsx)(Y,{name:`delete-bin`,className:`size-4 mr-2`}),t[72]=W):W=t[72];let G;t[73]===s?G=t[74]:(G=s(`inlineComment.actions.deleteComment`),t[73]=s,t[74]=G);let K;t[75]!==i||t[76]!==G?(K=(0,$.jsxs)(En,{onClick:i,className:`text-destructive focus:text-destructive`,children:[W,G]}),t[75]=i,t[76]=G,t[77]=K):K=t[77];let se;t[78]!==U||t[79]!==K?(se=(0,$.jsxs)(wn,{children:[U,K]}),t[78]=U,t[79]=K,t[80]=se):se=t[80];let ce;return t[81]!==d||t[82]!==H||t[83]!==se?(ce=(0,$.jsxs)(yn,{open:d,onOpenChange:f,children:[H,se]}),t[81]=d,t[82]=H,t[83]=se,t[84]=ce):ce=t[84],ce}function Xn(e){let t=(0,Ln.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=ir,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 ne=rr,L=nr,re=(o||s)&&(0,$.jsxs)(`div`,{className:`flex items-center gap-2 text-xs font-medium text-muted-foreground mb-2`,children:[o&&(0,$.jsx)(`span`,{className:`truncate max-w-[200px]`,children:o}),o&&s&&(0,$.jsx)(`span`,{children:`•`}),E&&(0,$.jsx)(`span`,{children:m(`inlineComment.range.lines`,{start:E.start,end:E.end})})]}),R;t[21]===x?R=t[22]:(R=e=>x(e.target.value),t[21]=x,t[22]=R);let ie;t[23]!==g||t[24]!==m?(ie=m(g?`inlineComment.input.placeholderShort`:`inlineComment.input.placeholder`),t[23]=g,t[24]=m,t[25]=ie):ie=t[25];let z;t[26]!==A||t[27]!==R||t[28]!==ie||t[29]!==_?(z=(0,$.jsx)(ze,{simple:!0,ref:y,value:_,onChange:R,onKeyDown:A,placeholder:ie,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]=R,t[28]=ie,t[29]=_,t[30]=z):z=t[30];let B;t[31]!==E||t[32]!==d||t[33]!==m?(B=E&&d?(0,$.jsxs)(X,{variant:`outline`,size:`sm`,onClick:()=>d(E),onPointerDown:tr,className:`mr-auto h-8 gap-1.5`,children:[(0,$.jsx)(Y,{name:`add`,className:`size-4`}),m(`chat.textSelection.actions.addToChat`),(0,$.jsx)(ft,{shortcut:`⌘+I`})]}):null,t[31]=E,t[32]=d,t[33]=m,t[34]=B):B=t[34];let V;t[35]===m?V=t[36]:(V=m(`inlineComment.actions.cancel`),t[35]=m,t[36]=V);let H;t[37]!==a||t[38]!==V?(H=(0,$.jsx)(X,{variant:`ghost`,size:`sm`,onClick:a,onPointerDown:er,onTouchStart:$n,className:`h-8 text-muted-foreground hover:text-foreground`,children:V}),t[37]=a,t[38]=V,t[39]=H):H=t[39];let ae;t[40]===_?ae=t[41]:(ae=_.trim(),t[40]=_,t[41]=ae);let oe=!ae,U=h?.colors?.status?.success,W=h?.colors?.status?.successForeground,G;t[42]!==U||t[43]!==W?(G={backgroundColor:U,color:W},t[42]=U,t[43]=W,t[44]=G):G=t[44];let K;t[45]!==p||t[46]!==m?(K=m(p?`inlineComment.actions.save`:`inlineComment.actions.comment`),t[45]=p,t[46]=m,t[47]=K):K=t[47];let se;t[48]!==M||t[49]!==oe||t[50]!==G||t[51]!==K?(se=(0,$.jsx)(X,{size:`sm`,onClick:M,onPointerDown:Qn,onTouchStart:Zn,disabled:oe,className:`h-8 min-w-[80px]`,style:G,children:K}),t[48]=M,t[49]=oe,t[50]=G,t[51]=K,t[52]=se):se=t[52];let ce;t[53]!==B||t[54]!==H||t[55]!==se?(ce=(0,$.jsxs)(`div`,{className:`flex items-center justify-end gap-2 mt-3`,children:[B,H,se]}),t[53]=B,t[54]=H,t[55]=se,t[56]=ce):ce=t[56];let q;t[57]!==re||t[58]!==z||t[59]!==ce?(q=(0,$.jsxs)(`div`,{className:`p-3`,children:[re,z,ce]}),t[57]=re,t[58]=z,t[59]=ce,t[60]=q):q=t[60];let le;return t[61]!==ee||t[62]!==I||t[63]!==ne||t[64]!==L||t[65]!==q?(le=(0,$.jsx)(`div`,{className:ee,style:I,"data-comment-input":`true`,onPointerDown:ne,onTouchStart:L,children:q}),t[61]=ee,t[62]=I,t[63]=ne,t[64]=L,t[65]=q,t[66]=le):le=t[66],le}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){return e.stopPropagation()}function ir(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 ar=e=>{let t=Math.min(e.startLine,e.endLine),n=Math.max(e.startLine,e.endLine);return{...e,startLine:t,endLine:n}},or=e=>{let t=Math.min(e.start,e.end),n=Math.max(e.start,e.end);return{...e,start:t,end:n}};function sr(e){let t=(0,Ln.c)(40),{t:n}=te(),{source:r,fileLabel:i,language:a,getCodeForRange:o,toStoreRange:s,fromDraftRange:c}=e,l=he(pr),u=he(fr),d=bt(dr),f=bt(ur),p=bt(lr),m=bt(cr),[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=or(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){B.error(n(`inlineComment.toast.selectSessionToSave`));return}let u=or(c),p=ar(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 cr(e){return e.drafts}function lr(e){return e.removeDraft}function ur(e){return e.updateDraft}function dr(e){return e.addDraft}function fr(e){return e.newSessionDraft?.open}function pr(e){return e.currentSessionId}function mr(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)(Xn,{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)(Yn,{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)(Xn,{initialText:r,onTextChange:i,fileLabel:s,lineRange:e,isEditing:!1,onSave:u,onCancel:d,onAddToChat:m},c)})}return h}var hr=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}`},gr=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 _r(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 vr(e){if(!(!e||e<=0))return Math.max(200,Math.floor(e))}function yr(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:hr({type:`new`,selection:r}),[i,r]),v=Q.useMemo(()=>{let e=n.map(e=>hr({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=_r(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?vr(Math.min(...o)):vr(h)},[t,h]);return(0,$.jsxs)($.Fragment,{children:[n.map(e=>{let t=hr({type:e.id===i?`edit`:`saved`,draft:e}),n=y(t);if(!n)return null;let r=b(n);return e.id===i?(0,Rn.createPortal)((0,$.jsx)(Xn,{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,Rn.createPortal)((0,$.jsx)(Yn,{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,Rn.createPortal)((0,$.jsx)(Xn,{initialText:a,onTextChange:o,fileLabel:s,lineRange:r,isEditing:!1,onSave:c,onCancel:l,onAddToChat:f,maxWidth:t}),e,_)})()]})}function br(e){let t=(0,Ln.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)(ft,{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,Rn.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:xr,children:p}),document.body),t[13]=l,t[14]=p,t[15]=m):m=t[15],m}function xr(e){return e.preventDefault()}var Sr=`[data-code-selection-action]`;function Cr(e){return e instanceof Element&&!!e.closest(Sr)}function wr(e,t=[]){return Cr(e)?!0:t.some(e=>e instanceof Element&&e.matches(`[data-column-number]`))}function Tr(e,t){return e&&!!t?.trim()}function Er(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?Dr(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 Dr(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 Or=5e5,kr=`
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
- `,Ar=`
30
- ${kr}
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 jr(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 Mr(e){let t=e.length>400?`${e.slice(0,200)}${e.slice(-200)}`:e;return`${e.length}:${jr(t)}`}var Nr=(e,t)=>e===t?!0:!e||!t?!1:e.start===t.start&&e.end===t.end&&e.side===t.side,Pr=e=>e===`auto`||e===`scroll`||e===`overlay`,Fr=e=>{let t=e?.parentElement??null;for(;t;){if(Pr(window.getComputedStyle(t).overflowY))return t;t=t.parentElement}return null},Ir=(e,t)=>{if(!e||!t||typeof window>`u`)return()=>{};let n=Fr(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)}},Lr=(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)}},Rr=new WeakMap,zr={lineHeight:24,hunkSeparatorHeight:24,spacing:0};function Br(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 Vr(e){if(typeof document>`u`)return null;let t=Br(e),n=Rr.get(t.key);if(!n){let e=new mn;e.setup(t.root,t.content),n={virtualizer:e,refs:0},Rr.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=Rr.get(t.key);e&&(--e.refs,!(e.refs>0)&&(e.virtualizer.cleanUp(),Rr.delete(t.key)))}}}var Hr=(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)}},Ur=({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}=sr({source:`diff`,fileLabel:i||`unknown`,language:r,getCodeForRange:r=>Er(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]),ne=(0,Q.useCallback)(()=>{k()},[k]),L=(0,Q.useCallback)(e=>{let t=document.createElement(`div`);t.style.position=`relative`;let n=hr(e.metadata);return t.dataset.annotationId=n,t.dataset.annotationSide=e.side,t.dataset.annotationLine=String(e.lineNumber),t},[]),re=(0,Q.useCallback)((e,t)=>{O(e,t??C??void 0)},[O,C]),R=(0,Q.useCallback)(r=>{if(!i)return;let a=Math.min(r.start,r.end),o=Math.max(r.start,r.end),s=a===o?`${a}`:`${a}-${o}`,l=Er(e,t,n,r);if(!l)return;let u=`${i.replace(/\\/g,`/`).split(`/`).pop()||i}:${s}`;_(i,u,l),v(x(u),`append-inline`),c.getState().setActiveMainTab(`chat`)},[_,n,i,t,e,v]);(0,Q.useEffect)(()=>{if(!u)return;let e=e=>{if(!e.metaKey||e.ctrlKey||e.altKey||e.shiftKey||e.key.toLowerCase()!==`i`)return;let t=y?.range??M.current;t&&(e.preventDefault(),R(t))};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[u,R,y]),(0,Q.useEffect)(()=>{b(null)},[i,n,e,t]),(0,Q.useEffect)(()=>{if(!u)return;let e=e=>{let t=e.composedPath(),n=wr(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 ie=(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]),z=(0,Q.useCallback)(e=>{let t=e.closest(`[data-line-type]`)?.getAttribute(`data-line-type`)??e.getAttribute(`data-line-type`);if(t===`change-deletion`)return`deletions`;if(t===`change-addition`)return`additions`;let n=e.getAttribute(`data-column-side`)??e.getAttribute(`data-side`)??e.closest(`[data-column-side]`)?.getAttribute(`data-column-side`);if(n===`deletions`||n===`left`||n===`original`)return`deletions`;if(n===`additions`||n===`right`||n===`modified`)return`additions`;let r=e.closest(`[data-line-type]`);if(r instanceof HTMLElement){let t=r.getBoundingClientRect(),n=e.getBoundingClientRect(),i=t.left+t.width/2;return n.left+n.width/2<i?`deletions`:`additions`}return`additions`},[]);qt(m),qt(h);let B=`${m.metadata.id}:${h.metadata.id}:${p?`dark`:`light`}`,V=(0,Q.useMemo)(()=>{if(n){let e=n.deletionLines.reduce((e,t)=>e+t.length,0),t=n.additionLines.reduce((e,t)=>e+t.length,0);return Math.max(e,t)>Or}return Math.max(e.length,t.length)>Or},[n,t.length,e.length]),H=(0,Q.useRef)(null),ae=(0,Q.useRef)(null),U=(0,Q.useRef)(null),W=(0,Q.useRef)(null),G=(0,Q.useRef)(null),K=(0,Q.useRef)(null),se=(0,Q.useRef)(void 0),ce=(0,Q.useRef)(void 0),q=(0,Q.useRef)(void 0),le=(0,Q.useRef)(void 0),ue=(0,Q.useRef)(null),[,de]=Q.useReducer(e=>e+1,0),fe=Jn(V?`unified`:a?`split`:`unified`),pe=(0,Q.useMemo)(()=>Kt(m),[m]),me=(0,Q.useMemo)(()=>Kt(h),[h]);Q.useLayoutEffect(()=>{let e=H.current;if(!e)return;let t=e.querySelector(`diffs-container`);if(!t)return;let n=p?me:pe,r=(e,t)=>e.colors?.[t],i=r(pe,`terminal.ansiGreen`),a=r(pe,`terminal.ansiRed`),o=r(pe,`terminal.ansiBlue`),s=r(me,`terminal.ansiGreen`),c=r(me,`terminal.ansiRed`),l=r(me,`terminal.ansiBlue`);t.style.setProperty(`--shiki-light`,pe.fg),t.style.setProperty(`--shiki-light-bg`,pe.bg),i&&t.style.setProperty(`--shiki-light-addition-color`,i),a&&t.style.setProperty(`--shiki-light-deletion-color`,a),o&&t.style.setProperty(`--shiki-light-modified-color`,o),t.style.setProperty(`--shiki-dark`,me.fg),t.style.setProperty(`--shiki-dark-bg`,me.bg),s&&t.style.setProperty(`--shiki-dark-addition-color`,s),c&&t.style.setProperty(`--shiki-dark-deletion-color`,c),l&&t.style.setProperty(`--shiki-dark-modified-color`,l),t.style.setProperty(`--diffs-bg`,n.bg),t.style.setProperty(`--diffs-fg`,n.fg);let u=p?s:i,d=p?c:a,f=p?l:o;u&&t.style.setProperty(`--diffs-addition-color-override`,u),d&&t.style.setProperty(`--diffs-deletion-color-override`,d),f&&t.style.setProperty(`--diffs-modified-color-override`,f);let m=t.shadowRoot?.querySelector(`pre`);m&&(m.style.setProperty(`--shiki-light`,pe.fg),m.style.setProperty(`--shiki-light-bg`,pe.bg),i&&m.style.setProperty(`--shiki-light-addition-color`,i),a&&m.style.setProperty(`--shiki-light-deletion-color`,a),o&&m.style.setProperty(`--shiki-light-modified-color`,o),m.style.setProperty(`--shiki-dark`,me.fg),m.style.setProperty(`--shiki-dark-bg`,me.bg),s&&m.style.setProperty(`--shiki-dark-addition-color`,s),c&&m.style.setProperty(`--shiki-dark-deletion-color`,c),l&&m.style.setProperty(`--shiki-dark-modified-color`,l),m.style.setProperty(`--diffs-bg`,n.bg),m.style.setProperty(`--diffs-fg`,n.fg),u&&m.style.setProperty(`--diffs-addition-color-override`,u),d&&m.style.setProperty(`--diffs-deletion-color-override`,d),f&&m.style.setProperty(`--diffs-modified-color-override`,f))},[me,B,p,pe]);let he=(0,Q.useMemo)(()=>({theme:{dark:h.metadata.id,light:m.metadata.id},themeType:p?`dark`:`light`,diffStyle:a?`split`:`unified`,diffIndicators:`none`,hunkSeparators:`line-info-basic`,lineDiffType:`none`,maxLineDiffLength:V?0:1e3,maxLineLengthForHighlighting:V?1:1e3,tokenizeMaxLineLength:V?1:1e3,collapsedContextThreshold:0,expansionLineCount:20,overflow:o?`wrap`:`scroll`,disableFileHeader:!0,enableLineSelection:l,enableHoverUtility:!1,onLineSelected:l?te:void 0,unsafeCSS:Ar,renderAnnotation:l?L:void 0}),[h.metadata.id,l,p,V,m.metadata.id,a,o,te,L]),ge=(0,Q.useMemo)(()=>l?gr({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,W.current?.release(),W.current=null,G.current=null,K.current=null,se.current=void 0,ce.current=void 0,q.current=void 0,le.current=void 0,e&&(e.innerHTML=``)}},[]),(0,Q.useEffect)(()=>{if(typeof window>`u`)return;let a=ae.current,o=H.current;if(!a||!fe)return;let s=Ir(o,a),c=W.current;c||(c=Vr(a),W.current=c),W.current=c;let l=c?.virtualizer??null,u=n?void 0:{name:i||``,contents:e,lang:r,cacheKey:`old:${B}:${i}:${Mr(e)}`},f=n?void 0:{name:i||``,contents:t,lang:r,cacheKey:`new:${B}:${i}:${Mr(t)}`},p=n?ce.current!==n:ce.current!==void 0||!u||!f||!q.current||!le.current||!fn(q.current,u)||!fn(le.current,f),m=U.current,h=!!(m&&(G.current!==l||K.current!==fe||l&&(se.current!==he.hunkSeparators||p)));h&&(m?.cleanUp(),U.current=null,a.innerHTML=``);let g=U.current,_=!h&&m?!un(m.options,he):!1;if(g?g.setOptions(he):(g=c?new gn(he,c.virtualizer,zr,fe):new cn(he,fe),U.current=g,F.current=null),G.current=l,K.current=fe,se.current=l?he.hunkSeparators:void 0,ce.current=n,q.current=u,le.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=Lr(a,()=>{if(s(),Hr(g,c,de),!d||ue.current===d)return;let e=(a.querySelector(`diffs-container`)?.shadowRoot)?.querySelector(`[data-line="${d}"]:not([data-line-type="change-deletion"])`);e instanceof HTMLElement&&(e.scrollIntoView({block:`center`}),ue.current=d)},{awaitRender:p&&!h});return()=>{v(),s()}},[B,n,i,d,r,t,he,e,fe]),(0,Q.useEffect)(()=>{let e=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{}de()}})}},[ge]),(0,Q.useEffect)(()=>{let e=U.current;if(!e||C!==null)return;let t=F.current;if(!Nr(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=z(t);if(te({start:r,end:r,side:a}),u){let e=t.getBoundingClientRect(),n=t.closest(`[data-line-type]`)?.getAttribute(`data-line-type`),o=Array.from(i.querySelectorAll(`[data-line="${r}"]`)).find(e=>!n||e.getAttribute(`data-line-type`)===n);b({range:{start:r,end:r,side:a},x:Math.min(window.innerWidth-240,Math.max(8,o?.getBoundingClientRect().left??e.right+12)),y:e.top-8})}e.preventDefault(),e.stopPropagation()},o=(e,t)=>{let n=(e instanceof Element?e:e.parentElement)?.closest(`[data-line]`);if(!(n instanceof HTMLElement))return null;let r=Number.parseInt(n.getAttribute(`data-line`)??``,10);if(Number.isFinite(r))return{lineNumber:r,side:z(n),lineStartX:n.getBoundingClientRect().left};let i=Array.from(n.querySelectorAll(`[data-column-number]`));if(i.length===0)return null;let a=i.reduce((e,n)=>{let r=Math.abs(e.getBoundingClientRect().right-t);return Math.abs(n.getBoundingClientRect().right-t)<r?n:e}),o=Number.parseInt(a.getAttribute(`data-column-number`)??``,10);return Number.isFinite(o)?{lineNumber:o,side:z(a),lineStartX:a.getBoundingClientRect().right+12}:null},s=()=>{if(!u)return;let e=I.current;I.current=!1,e&&window.requestAnimationFrame(()=>{let e=i.getSelection?.(),t=e?.rangeCount?e:window.getSelection();if(!t)return;let n=t.getComposedRanges?.({shadowRoots:[i]})[0],r=document.createRange();if(n)r.setStart(n.startContainer,n.startOffset),r.setEnd(n.endContainer,n.endOffset);else if(t.rangeCount>0){let e=t.getRangeAt(0);r.setStart(e.startContainer,e.startOffset),r.setEnd(e.endContainer,e.endOffset)}else return;if(!Tr(!0,r.toString()))return;let a=r.getBoundingClientRect(),s=o(r.startContainer,a.left),c=o(r.endContainer,a.right);!s||!c||s.side!==c.side||b({range:{start:s.lineNumber,end:c.lineNumber,side:s.side},x:Math.min(window.innerWidth-240,Math.max(8,s.lineStartX)),y:Math.max(8,a.top-8)})})};i.addEventListener(`click`,a,!0),i.addEventListener(`pointerup`,s),window.addEventListener(`pointerup`,s,!0),n=()=>{i.removeEventListener(`click`,a,!0),i.removeEventListener(`pointerup`,s),window.removeEventListener(`pointerup`,s,!0)}};return r(),()=>{t!==null&&cancelAnimationFrame(t),n()}},[B,l,u,i,te,z]),(0,Q.useEffect)(()=>{let e=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(()=>{de(),n=null})}),t.observe(r,{childList:!0,subtree:!0}),i&&t.observe(i,{childList:!0,subtree:!0})},100);return()=>{clearTimeout(r),n&&cancelAnimationFrame(n),t?.disconnect()}},[B,i]),typeof window>`u`)return null;let ve=l?(0,$.jsx)(yr,{diffRootRef:H,drafts:S,selection:C,editingDraftId:D,commentText:T,onTextChange:E,fileLabel:i?.split(`/`).pop()??``,onSave:re,onCancel:ne,onEdit:e=>{ie({start:e.startLine,end:e.endLine,side:e.side===`original`?`deletions`:`additions`}),A(e)},onDelete:j,onAddToChat:u?R:void 0}):null,ye=u&&y?(0,$.jsx)(br,{position:y,onDismiss:()=>b(null),onAddToChat:()=>{R(y.range),b(null),window.getSelection()?.removeAllRanges()}}):null;return s===`fill`?(0,$.jsx)(`div`,{className:J(`flex flex-col relative`,`size-full`),"data-diff-virtual-root":!0,children:(0,$.jsxs)(`div`,{className:`flex-1 relative min-h-0`,children:[(0,$.jsx)(Ie,{outerClassName:`pierre-diff-wrapper size-full`,disableHorizontal:!1,fillContainer:!0,"data-diff-virtual-content":!0,children:(0,$.jsx)(`div`,{ref:H,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:H,className:`pierre-diff-wrapper w-full overflow-x-auto overflow-y-visible relative`,children:(0,$.jsx)(`div`,{ref:ae,className:`w-full`})}),ve,ye]})},Wr=5e3,Gr=(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},Kr=(e,t)=>ie(R.getState().dictionary,e,t),qr=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`},Jr=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`}},Yr=async(e,t)=>{try{let{content:n,exists:r}=await Jr(e,t);return r?Gr(n,5e3)>5e3?{ok:!1,reason:`too-large`}:{ok:!0}:{ok:!1,reason:`missing`}}catch(e){return{ok:!1,reason:qr(e)}}},Xr=e=>e===`too-large`?Kr(`contextFileOpen.failure.tooLarge`,{count:Wr.toLocaleString(L())}):Kr(e===`missing`?`contextFileOpen.failure.missing`:`contextFileOpen.failure.unreadable`),Zr=64,Qr=3,$r=new Map,ei=(e,t,n=Qr)=>{let r=`${e}\0${n}\0${t}`,i=$r.get(r);if(i)return $r.delete(r),$r.set(r,i),i;let a=ni(t),o=a?ln(pn(t,n),{oldFile:{name:e,contents:a.before},newFile:{name:e,contents:a.after}})??ii(e):vn(ti(e,t))[0]?.files[0]??ii(e);for($r.set(r,o);$r.size>Zr;){let e=$r.keys().next().value;if(!e)break;$r.delete(e)}return o},ti=(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}`,ni=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:ri(s),after:ri(c)}},ri=e=>e.map(e=>e.text+(e.newline?`
141
- `:``)).join(``),ii=e=>dn({name:e,contents:``},{name:e,contents:``}),ai=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},oi=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},si=e=>`${e.scope}:${e.navigationRequestKey??``}:${(e.targetFilePath??``).trim()}:${e.targetLine??``}`,ci=(e,t,n)=>n&&e!==t,li=e=>`/api/openchamber/sessions/${encodeURIComponent(e)}/changes`,ui=e=>e.trim(),di=e=>e===404||e===405||e===501,fi=e=>{if(!e||typeof e!=`object`||Array.isArray(e))return!1;let t=e.diff;return!!t&&typeof t==`object`&&!Array.isArray(t)},pi=(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},mi=async(e,t)=>{let n={messageID:e.messageID,directory:e.directory};return typeof e.file==`string`&&e.file.length>0&&(n.file=e.file),_(li(e.sessionID),{method:`GET`,headers:{Accept:`application/json`,"x-opencode-directory":e.directory},query:n,signal:t})},hi=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})},gi=(e,t=n())=>m.sessionTurnChanges.file(e.directory,e.sessionID,e.messageID,e.file,e.diffCount,t),_i=(e,t=n())=>({queryKey:gi(e,t),queryFn:async({signal:t})=>{let n=await mi(e,t);if(n.ok){let e=await n.json().catch(()=>null);if(fi(e))return e}else if(!di(n.status))throw Error(`Session turn change file request failed (${n.status})`);let r=pi(await hi(e,t),e.file);if(!r)throw Error(`change file not found`);return{diff:r}},staleTime:0,gcTime:6e4,retry:!1}),vi=(e,t)=>{let r=(0,Ln.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=_i({...i,directory:ui(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)},yi=1100,bi=15e3,xi=500,Si=300,Ci=1e6,wi=3,Ti=e=>e<=6?e:e<=12?6:e<=25?4:2,Ei=Q.memo(()=>{let e=(0,Ln.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}),Di={"?":{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`}},Oi=Di.M,ki=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`},Ai=e=>Di[ki(e)]??Oi,ji=e=>{let{index:t,working_dir:n}=e;return t===`A`||n===`A`||t===`?`||n===`?`},Mi=e=>{let t=e.index?.trim();return!!(t&&t!==`?`)},Ni=e=>!!e.working_dir?.trim()||e.index===`?`,Pi=(e,t)=>lt(e,t),Fi=e=>(e||``).replace(/\\/g,`/`).replace(/\/+$/,``),Ii=(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},Li=e=>/^Binary files .+ differ$/m.test(e)||/^GIT binary patch$/m.test(e),Ri=e=>Array.isArray(e)?e.filter(e=>!e||typeof e!=`object`?!1:typeof e.file==`string`):[],zi=e=>e===`added`?`A`:e===`deleted`?`D`:`M`,Bi=e=>e.isBinary||typeof e.patch==`string`&&e.patch.length>0||e.fileDiff?!0:e.original.length>0||e.modified.length>0,Vi=(e,t,n)=>Li(t)?{original:``,modified:``,isBinary:!0,patch:t,contextMode:n}:{original:``,modified:``,patch:t,fileDiff:ei(e,t),contextMode:n},Hi=(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]})},Ui=Q.memo(e=>{let t=(0,Ln.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)(at,{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)(Xe,{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)(Xe,{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)(Xe,{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)(it,{align:`start`,className:`w-40`,children:(0,$.jsxs)(ot,{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)(Qe,{open:c,onOpenChange:l,children:[_,j]}),t[49]=c,t[50]=j,t[51]=_,t[52]=M):M=t[52],M}),Wi=Q.memo(e=>{let t=(0,Ln.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=Ai(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)(Nt,{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)(vt,{path:e.path,className:`min-w-0 flex-1 typography-code`,dirClassName:n?`text-interactive-selection-foreground`:`text-muted-foreground`,nameClassName:n?`text-interactive-selection-foreground`:`text-foreground`}),Hi(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}),Gi=Q.memo(e=>{let t=(0,Ln.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}),Ki=Q.memo(e=>{let t=(0,Ln.c)(17),{filePath:n,diff:r,renderSideBySide:i,wrapLines:a,focusLine:o}=e,s;t[0]===n?s=t[1]:(s=en(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)(Ei,{}),t[2]=e):e=t[2],e}if(Qt(n)){let e;return t[3]!==r||t[4]!==n||t[5]!==i?(e=(0,$.jsx)(Gi,{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)(Ur,{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}),qi=Q.memo(e=>{let t=(0,Ln.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)(Ji,{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)(Ji,{label:s(`gitView.changes.revertFileAria`,{path:n}),icon:`arrow-go-back`,loading:i===`discard`,disabled:a,tone:`failure`,onClick:()=>o(`discard`)}),(0,$.jsx)(Ji,{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}),Ji=e=>{let t=(0,Ln.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},Yi=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}=Rt(),w=Vt(Q.useCallback(n=>n.directories.get(e)?.diffCache.get(t.path)??null,[e,t.path])),T=Vt(e=>e.setDiff),E=Vt(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,ne]=Q.useState(null),[L,re]=Q.useState(null),R=Q.useRef(null),ie=Q.useRef(null),z=Q.useMemo(()=>Ai(t),[t]),V=n===`side-by-side`,H=h?`full`:`patch`,ae=`${t.index}:${t.working_dir}:${t.insertions}:${t.deletions}`,oe=vi({sessionID:b?.sessionID??``,directory:b?.directory??``,messageID:b?.messageID??``,diffCount:b?.diffCount,file:t.path},{enabled:x&&!!b&&a&&o}),U=Q.useMemo(()=>{let e=oe.data?.diff;return e?typeof e.patch==`string`&&e.patch.length>0?Vi(t.path,e.patch,`patch`):typeof e.before==`string`&&e.before.length>0||typeof e.after==`string`&&e.after.length>0?{original:e.before??``,modified:e.after??``,contextMode:`full`}:null:null},[t.path,oe.data]),W=Q.useMemo(()=>{if(g)return g;if(U)return U;if(m)return L;if(I)return I;if(!w)return null;let e={original:w.original,modified:w.modified,isBinary:w.isBinary,contextMode:`full`};return Bi(e)?e:null},[w,g,I,m,L,U]),G=oe.error instanceof Error?oe.error.message:oe.error?String(oe.error):null,K=W?null:G??k,se=x&&oe.isPending||j,ce=W?.contextMode===H,q=Q.useCallback(e=>{ie.current=e,l(t.path,e)},[t.path,l]),le=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){R.current=null,M(!1);return}if(!e||g){R.current=null,M(!1);return}let n=`${e}::${t.path}::${m?`staged`:`unstaged`}::${ae}::${H}::${D}`;if(R.current===n)return;let r=!!(W&&ce);R.current=n,A(null),r||M(!0);let i=!1,s=h?Ci:wi,c=Qt(t.path)||h?C.getGitFileDiff(e,{path:t.path,staged:m}):C.getGitDiff(e,{path:t.path,staged:m,contextLines:s}),l=bi,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=Vi(t.path,n.diff,H);m?re(e):ne(e)}else{let r={original:n.original??``,modified:n.modified??``,isBinary:n.isBinary,contextMode:`full`};m?re(r):(ne(r),T(e,t.path,r))}M(!1)}}).catch(e=>{if(i)return;let t=e instanceof Error?e.message:String(e);A(t),M(!1)}),()=>{i=!0,R.current===n&&(R.current=null)}},[H,W,ce,D,e,y,t.path,ae,C,g,a,o,h,T,m]);let de=Q.useCallback(()=>{le(!a),ue()},[le,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`;B.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:q,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:z.color},title:S(z.descriptionKey),"aria-label":S(z.descriptionKey),children:z.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)(Nt,{filePath:t.path,className:`size-3 flex-shrink-0 align-middle`}),(0,$.jsx)(vt,{path:t.path,className:`min-w-0 flex-1 typography-code`})]})})]}),(0,$.jsxs)(`div`,{className:`relative flex shrink-0 items-center justify-self-end gap-1.5`,children:[Hi(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,W)},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&&!K?(0,$.jsx)(`div`,{className:`h-40 border border-border/40 bg-background/40`}):null,K?(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:K}),(0,$.jsx)(`button`,{type:`button`,className:`typography-ui-label text-primary hover:underline`,onClick:()=>{if(x){oe.refetch();return}O(e=>e+1)},children:S(`diffView.actions.retry`)})]}):null,o&&se&&!W&&!K?(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&&W&&!P&&t.insertions+t.deletions>xi?(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&&W&&(P||t.insertions+t.deletions<=xi)?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Ki,{filePath:t.path,diff:W,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)(qi,{filePath:t.path,staged:m,busyAction:ee,disabled:ee!==null,onAction:fe})})}):null]}):null]})]})}),Xi=({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}=Rt(),x=tn(),S=typeof s==`string`&&s.trim()?s.trim():x,{screenWidth:C,isMobile:w}=ct(),T=Ut(S??null),E=Wt(S??null),D=Ht(S??null),O=Vt(e=>e.setActiveDirectory),k=Vt(e=>e.ensureStatus),A=Vt(e=>e.fetchStatus),j=Vt(e=>e.setDiff),[M,ee]=Q.useState(null),[N,P]=Q.useState(!1),[F,ne]=Q.useState(null),[L,re]=Q.useState(null),[R,ie]=Q.useState(()=>new Set),[z,V]=Q.useState(()=>new Set),[H,ae]=Q.useState(g),[oe,W]=Q.useState(0),[G,K]=Q.useState(!1),[se,ce]=Q.useState(!1),[q,le]=Q.useState(i);Q.useEffect(()=>{le(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),ge=c(e=>e.diffLayoutPreference),_e=c(e=>e.diffFileLayout),ye=c(e=>e.setDiffFileLayout),be=c(e=>e.diffWrapLines),Se=c(e=>e.setDiffWrapLines),Ce=c(e=>e.openContextFileAtLine),we=c(e=>e.openContextFile),Te=mt(),Ee=he(e=>e.currentSessionId),De=typeof o==`string`&&o.trim()?o.trim():Ee,Oe=ve(De??``,S??void 0),ke=be,Ae=q===`staged`||q!==`working`&&null,je=Ae??N,Me=w||C<=768,Ne=!!De&&q!==`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,re(null),ze.current!==null&&(window.cancelAnimationFrame(ze.current),ze.current=null)},[]),Ye=Q.useCallback(e=>{ie(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=Ri(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(()=>oi(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,Vi(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(q===`turn`)return et.map(e=>({path:e.file??``,index:``,working_dir:zi(e.status),insertions:e.additions??0,deletions:e.deletions??0,isNew:e.status===`added`})).filter(e=>e.path).sort((e,t)=>e.path.localeCompare(t.path));if(!E?.files)return[];let e=E.diffStats??{},t=q===`staged`?Mi:q===`working`?Ni:()=>!0;return E.files.filter(t).map(t=>({...t,insertions:e[t.path]?.insertions??0,deletions:e[t.path]?.deletions??0,isNew:ji(t)})).sort((e,t)=>e.path.localeCompare(t.path))},[q,et,E]),rt=Q.useMemo(()=>E?.files?E.files.filter(Ni).length:0,[E]),it=Q.useMemo(()=>E?.files?E.files.filter(Mi).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??``}:${q}:${a??``}:${t?`collapsed`:`default`}`,i=p!==null&&Ke.current!==p,o=Ge.current!==r||i;Ge.current=r,Ke.current=p,ie(r=>{if(o){let n=t||q===`turn`&&!Qe?0:Ti(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})},[q,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-Si,r=t.bottom+Si,i={};for(let[e,t]of Le.current){if(!t||!R.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})},[R]),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,R,lt]);let ut=Q.useCallback(e=>{let t=_e[e.path];if(t)return t;if(ge===`inline`)return`inline`;if(ge===`side-by-side`)return`side-by-side`;let n=C<yi;return e.isNew||n?`inline`:`side-by-side`},[_e,ge,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 xe.onGitRefreshHint(e=>{Fi(e.directory)===Fi(S)&&A(S,y)})},[S,A,y]),Q.useEffect(()=>{q!==`all`&&!fe||ue&&(fe&&le(fe),ee(ue),P(fe===`staged`||!fe&&de),ne(pe),me(null),Be.current=!0,Re.current=ue,Ye(ue),W(e=>e+1))},[q,Ye,ue,pe,fe,de,me]),Q.useEffect(()=>{if(q===`all`)return;let e=d?.trim();if(!e)return;Ye(e),ee(e),P(q===`staged`),ne(f);let t=si({scope:q,navigationRequestKey:_,targetFilePath:e,targetLine:f}),n=nt.some(t=>t.path===e);ci(qe.current,t,n)&&(qe.current=t,Be.current=!0,Re.current=e,W(e=>e+1))},[q,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]),pt=Q.useCallback((e,t)=>{Je(),ie(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]),gt=Q.useCallback(()=>{Je(),ie(e=>e.size>0?new Set:new Set(nt.map(e=>e.path))),V(new Set),lt()},[Je,nt,lt]),_t=Q.useCallback(async e=>{if(!Ee)return;let t=he.getState().getDirectoryForSession(Ee)||S||``;if(!t){B.error(v(`diffView.reviewDialog.toast.noSessionDirectory`));return}ce(!0);try{await U({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}),K(!1)}catch(e){console.error(`[review-flow] failed to start review flow`,e),B.error(e instanceof Error?e.message:v(`diffView.reviewDialog.toast.startFailed`))}finally{ce(!1)}},[Ee,S,v]),vt=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,re(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(!vt(a)){e+=1,e<20?ze.current=window.requestAnimationFrame(i):(r(),ze.current=null);return}n&&Be.current&&re(a),r()};return ze.current=window.requestAnimationFrame(i),()=>{t=!0,ze.current!==null&&(window.cancelAnimationFrame(ze.current),ze.current=null)}},[n,oe,vt]);let yt=Q.useCallback(e=>{},[]),bt=Q.useCallback(e=>{Je(),ee(e),P(!1),Be.current=!0,Re.current=e,Ye(e),W(e=>e+1),vt(e)},[Je,Ye,vt]),xt=Q.useCallback(e=>{let t=e===`side-by-side`?`side-by-side`:`inline`;st.forEach(e=>{ye(e.path,t)})},[ye,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&&!Qt(e)?n=ai(t.patch):t&&t.contextMode===`full`&&!t.isBinary&&!Qt(e)&&(n=Ii(t.original,t.modified)),n===null)try{n=ai((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||Qt(e)?1:Ii(r.original,r.modified)),a=Pi(S,e),o=await Yr(b,a);if(!o.ok){B.error(Xr(o.reason));return}Ce(S,a,i,1)}finally{Ct(t=>t===e?null:t)}}},[je,S,b,y,Ce,j]),Tt=I(e=>{if(!S||!e)return;let t=Pi(S,e);if(Te){Te.openFile({path:t});return}Yr(b,t).then(e=>{if(!e.ok){B.error(Xr(e.reason));return}we(S,t)})});return(0,$.jsxs)(`div`,{className:`flex h-full flex-col overflow-hidden bg-background`,children:[h?null:(0,$.jsxs)(`div`,{className:`@container/diff-toolbar flex min-w-0 items-center gap-1.5 px-2 py-1.5 bg-background`,children:[!w&&(q===`working`||q===`staged`||q===`turn`?(0,$.jsx)(Ui,{scope:q,workingCount:rt,stagedCount:it,turnCount:at,onScopeChange:e=>{le(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&&(q!==`turn`||Qe)&&(0,$.jsxs)(X,{variant:`ghost`,size:`sm`,onClick:gt,className:J(`diff-toolbar__expand-button h-7 flex-shrink-0 gap-1 px-1.5 text-muted-foreground hover:text-foreground`,`ml-auto`),title:R.size>0?v(`diffView.actions.collapseAll`):v(`diffView.actions.expandAll`),children:[(0,$.jsx)(Y,{name:`expand-up-down`,className:`size-4`}),(0,$.jsx)(`span`,{className:`diff-toolbar__expand-label typography-code`,children:R.size>0?v(`diffView.actions.collapseAll`):v(`diffView.actions.expandAll`)})]}),nt.length>0&&Ne&&(0,$.jsxs)(X,{variant:`default`,size:`sm`,onClick:()=>K(!0),disabled:se,className:`diff-toolbar__review-button h-7 flex-shrink-0 gap-1.5 px-2`,"aria-label":v(`diffView.actions.reviewAria`),children:[se?(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:()=>ae(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:()=>Se(!be),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)(an,{mode:dt===`side-by-side`?`side-by-side`:`unified`,onModeChange:xt})]}),(0,$.jsx)(ht,{open:G,onOpenChange:K,projectDirectory:S??null,submitting:se,onConfirm:_t}),S?q!==`turn`&&D&&!E?(0,$.jsxs)(`div`,{className:`flex flex-1 items-center justify-center gap-2 text-sm text-muted-foreground`,children:[(0,$.jsx)(Y,{name:`loader-4`,className:`size-4 animate-spin`}),v(`diffView.state.loadingRepositoryStatus`)]}):q!==`turn`&&T===!1?(0,$.jsx)(`div`,{className:`flex flex-1 items-center justify-center text-sm text-muted-foreground`,children:v(`diffView.state.notGitRepository`)}):st.length===0?(0,$.jsx)(`div`,{className:`flex flex-1 items-center justify-center text-sm text-muted-foreground`,children:v(q===`turn`?`diffView.state.noLastTurnChanges`:`diffView.state.cleanWorkingTree`)}):(()=>{if(!S)return null;let e=e=>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)(Wi,{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)(Yi,{directory:S,file:t,layout:ut(t),wrapLines:ke,isSelected:!1,isExpanded:R.has(t.path),isMounted:z.has(t.path)||t.path===L||h&&st.length===1,onSelect:yt,onExpandedChange:pt,registerSectionRef:ft,showOpenInEditorAction:r&&q!==`turn`,isOpeningInEditor:St===t.path,onOpenInEditor:(e,t)=>{wt(e,t)},onOpenFile:Tt,staged:e(t.path),loadFullFiles:H,initialDiffData:q===`turn`?tt.get(t.path)??null:null,focusLine:t.path===(d?.trim()||M)?f??F:null,showFileActions:q!==`turn`,disableGitFetch:q===`turn`,turnChangesRequest:$e,loadTurnChangeFile:q===`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`)})]})},Zi=(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)},Qi=(e,t)=>{let n=e.state.doc.lineAt(t.main.head);return{lineNumber:n.number,character:t.main.head-n.from+1,selection:t}},$i=(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 ea({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(()=>Zi(a,n),[a,n]);Q.useEffect(()=>{!e||!n||(c.current=!1,s.current=Qi(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}$i(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,$i(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??Qi(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 ta=(e,t)=>{let n=Z(t,e);return!n||n===`.`||n===t?0:n.split(`/`).filter(Boolean).length},na=(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=ta(r,e);o<1||o>n||(i.add(e),a.push(e))}return a},ra=e=>e.some(e=>!!ut(e)),ia=(e,t)=>{let n=new Set(t.map(e=>ut(e)).filter(Boolean));return e.filter(e=>!n.has(e))},aa=(e,t,n)=>t.length===0?e.length===0:ia(e,t).length>0?!1:t.every(e=>n.has(ut(e))),oa=[{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`}],sa=`finder`,ca=new Set([`finder`,`terminal`]),la=e=>typeof window<`u`&&window.__OPENCHAMBER_PLATFORM__===`win32`&&e.id===`finder`?{...e,label:`Explorer`,appName:`File Explorer`}:e,ua=e=>{if(!e)return null;let t=oa.find(t=>t.id===e)??null;return t?la(t):null},da=()=>oa.filter(e=>ca.has(e.id)).map(e=>({...la(e)})),fa=()=>{if(typeof window>`u`)return sa;let e=window.localStorage.getItem(`openInAppId`);return e&&ua(e)?e:sa},pa=!1,ma=!1,ha=!1,ga=0,_a=null,va=()=>{_a&&=(clearTimeout(_a),null)},ya=C()((e,t)=>({selectedAppId:fa(),availableApps:da(),hasLoadedApps:!1,isCacheStale:!1,isScanning:!1,initialize:()=>{if(pa||typeof window>`u`)return;pa=!0;let n=(t,n=!0)=>{if(!Array.isArray(t)||t.length===0){e({availableApps:da(),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:oa.filter(e=>r.has(e.appName)||ca.has(e.id)).map(e=>({...la(e),iconDataUrl:i.get(e.appName)})),hasLoadedApps:!0})},r=async i=>{if(!f()||!p()||ma||t().hasLoadedApps&&!i)return;let a=oa.map(e=>e.appName);va(),i&&e({hasLoadedApps:!1}),ma=!0,ha=!1,e({isScanning:!0});try{let{apps:t,success:o,hasCache:s,isCacheStale:c}=await d(a,i),l=o&&!s&&t.length===0&&ga<3;if(e({isCacheStale:s?c:!1}),n(t,o?!l:!1),o){if(l){let e=[800,1600,3200][ga]??3200;ga+=1,ha=!0,_a=setTimeout(()=>{r()},e);return}ga=0,ha=!1;return}if(ga<3){let e=[1e3,3e3,7e3][ga]??7e3;ga+=1,ha=!0,_a=setTimeout(()=>{r()},e)}}finally{ma=!1,ha||e({isScanning:!1})}};r(),window.addEventListener(`openchamber:settings-synced`,t=>{let n=t.detail,r=n&&typeof n.openInAppId==`string`&&n.openInAppId.length>0&&ua(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)&&(ga=3,ha=!1,e({isScanning:!1,isCacheStale:!1}),n(r))}),window.__openchamberAppReady&&r(),window.setTimeout(()=>{t().hasLoadedApps||r()},5e3)},loadInstalledApps:async n=>{if(pa||t().initialize(),!f()||!p()||ma||t().hasLoadedApps&&!n)return;let r=oa.map(e=>e.appName);va(),n&&e({hasLoadedApps:!1}),ma=!0,ha=!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=oa.filter(e=>o.has(e.appName)||ca.has(e.id)).map(e=>({...e,iconDataUrl:s.get(e.appName)}));e({availableApps:c.length>0?c:da(),hasLoadedApps:c.length>0,isCacheStale:i?a:!1})}finally{ma=!1,ha||e({isScanning:!1})}},selectApp:async t=>{ua(t)&&(e({selectedAppId:t}),typeof window<`u`&&window.localStorage.setItem(`openInAppId`,t),await y({openInAppId:t}))}})),ba=Jt(()=>A(()=>import(`./ToolOutputDialog-ClZXQ2ee.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]))),xa=e=>{let t=wa(e);if(!t)return``;if(t===`/`||/^[A-Za-z]:\/$/.test(t))return t;let n=t.lastIndexOf(`/`);if(n<0)return t;if(n===0)return`/`;let r=t.slice(0,n);return/^[A-Za-z]:$/.test(r)?`${r}/`:r},Sa=e=>{let t=(0,Ln.c)(8),{label:n,iconDataUrl:r}=e,[i,a]=Q.useState(!1),o;t[0]===n?o=t[1]:(o=n.trim().slice(0,1).toUpperCase()||`?`,t[0]=n,t[1]=o);let s=o;if(r&&!i){let e;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(e=()=>a(!0),t[2]=e):e=t[2];let n;return t[3]===r?n=t[4]:(n=(0,$.jsx)(`img`,{src:r,alt:``,className:`size-4 rounded-sm`,onError:e}),t[3]=r,t[4]=n),n}let c;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(c=J(`size-4 rounded-sm flex items-center justify-center`,`bg-[var(--surface-muted)] text-[9px] font-medium text-muted-foreground`),t[5]=c):c=t[5];let l;return t[6]===s?l=t[7]:(l=(0,$.jsx)(`span`,{className:c,children:s}),t[6]=s,t[7]=l),l},Ca=e=>e.slice().sort((e,t)=>e.type===t.type?e.name.localeCompare(t.name):e.type===`directory`?-1:1),wa=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},Ta=e=>e.startsWith(`/`)||e.startsWith(`//`)||/^[A-Za-z]:\//.test(e),Ea=e=>/^[A-Za-z]:\//.test(e)?e.toLowerCase():e,Da=(e,t)=>{let n=wa(t),r=wa(e);if(!n||!r)return!1;let i=Ea(n),a=Ea(r);return a===i||a.startsWith(`${i}/`)},Oa=(e,t)=>{let n=wa(t),r=wa(e);if(!Da(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},ka=(e,t)=>{if(!t)return``;let n=wa(t);if(!e||!Da(n,e))return n;let r=n.slice(e.length);return r.startsWith(`/`)?r.slice(1):r},Aa=new Set([`node_modules`]),ja=e=>{let t=(0,Ln.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},Ma=e=>{let t=(0,Ln.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},Na=e=>Aa.has(e),Pa=e=>{let t=wa(e);return t===`node_modules`||t.endsWith(`/node_modules`)||t.includes(`/node_modules/`)},Fa=e=>{let t=(e instanceof Error?e.message:String(e??``)).toLowerCase();return t.includes(`is a directory`)||t.includes(`eisdir`)},Ia=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`)},La=2e5,Ra=`openchamber:files:auto-save-enabled`,za=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
- `},Ba=e=>e.replace(/\r\n/g,`
148
- `).replace(/\r/g,`
149
- `),Va=(e,t)=>{let n=Ba(e);return t===`\r
150
- `?n.replace(/\n/g,`\r
151
- `):n},Ha=()=>{if(typeof window>`u`)return!0;try{return window.localStorage.getItem(Ra)!==`false`}catch{return!0}},Ua=(e,t)=>(0,$.jsx)(Nt,{filePath:e,extension:t}),Wa=e=>{if(!e)return!1;let t=e.toLowerCase().split(`.`).pop();return t===`md`||t===`markdown`},Ga=e=>{if(!e)return!1;let t=e.toLowerCase().split(`.`).pop();return t===`html`||t===`htm`},Ka=e=>{let t=(0,Ln.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(),re(n.path).then(e=>{e.ok||B.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=ka(r,n.path)||n.path;re(t).then(e=>{if(e.ok){B.success(b(`filesView.toast.relativePathCopied`));return}B.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),B.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(Ne())]}),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,ne;t[33]===I?ne=t[34]:(ne=(0,$.jsx)(`div`,{className:`group relative flex items-center`,onContextMenu:I}),t[33]=I,t[34]=ne);let L=o?void 0:O,R=a?`bg-interactive-selection/70`:`hover:bg-interactive-hover/40`,ie;t[35]===R?ie=t[36]:(ie=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`,R),t[35]=R,t[36]=ie);let z;t[37]!==x||t[38]!==i||t[39]!==n.extension||t[40]!==n.path?(z=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`}):Ua(n.path,n.extension),t[37]=x,t[38]=i,t[39]=n.extension,t[40]=n.path,t[41]=z):z=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)(ja,{status:c}),t[45]=x,t[46]=c,t[47]=H):H=t[47];let ae;t[48]!==l||t[49]!==x?(ae=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]=ae):ae=t[50];let oe;t[51]!==A||t[52]!==ie||t[53]!==z||t[54]!==V||t[55]!==H||t[56]!==ae||t[57]!==L?(oe=(0,$.jsxs)(`button`,{type:`button`,onClick:A,onContextMenu:L,className:ie,children:[z,V,H,ae]}),t[51]=A,t[52]=ie,t[53]=z,t[54]=V,t[55]=H,t[56]=ae,t[57]=L,t[58]=oe):oe=t[58];let U;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?(U=(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)(Qe,{open:f===n.path,onOpenChange:e=>p(e?n.path:null),children:[(0,$.jsx)(at,{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)(it,{align:`end`,side:`bottom`,onCloseAutoFocus:()=>p(null),children:N({Item:st,Separator:qe})})]})}),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]=U):U=t[71];let W;t[72]!==oe||t[73]!==U||t[74]!==ne?(W=(0,$.jsxs)(Sn,{render:ne,children:[oe,U]}),t[72]=oe,t[73]=U,t[74]=ne,t[75]=W):W=t[75];let G;t[76]===N?G=t[77]:(G=(0,$.jsx)(wn,{className:`min-w-[180px]`,children:N({Item:En,Separator:bn})}),t[76]=N,t[77]=G);let K;return t[78]!==W||t[79]!==G||t[80]!==P||t[81]!==F?(K=(0,$.jsxs)(yn,{open:P,onOpenChange:F,children:[W,G]}),t[78]=W,t[79]=G,t[80]=P,t[81]=F,t[82]=K):K=t[82],K},qa=e=>{let t=(0,Ln.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)(Ae,{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)(je,{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)(De,{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)(Oe,{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)(ke,{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)(Me,{open:d,onOpenChange:f,children:ee}),t[79]=d,t[80]=f,t[81]=ee,t[82]=N):N=t[82],N},Ja=(e,t,n)=>e&&!!t&&n===t,Ya=(e,n,a)=>{let o=(0,Ln.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(Za),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},Xa=({mode:e=`full`,isActive:t=!0})=>{let{t:n}=te(),{files:r,runtime:i}=Rt(),{currentTheme:o,availableThemes:s,lightThemeId:l,darkThemeId:d}=We(),{isMobile:f,isTablet:p,screenWidth:m}=ct(),v=f||p,y=g(),S=u(),C=tn()??``,w=wa(C.trim()),T=f||e!==`editor-only`,E=e===`editor-only`&&!f,D=O(e=>e.searchFiles),A=Wt(C),[j,M]=Q.useState(``),ee=zt(j,200),N=Q.useRef(null),[F,I]=Q.useState(!1),[ne,L]=Q.useState(!0),[R,ie]=Q.useState(!1),[z,V]=Q.useState(!1),[H,ae]=Q.useState(!1),[U,W]=Q.useState({open:!1,title:``,content:``}),G=Q.useRef(null),K=Q.useRef(0),se=Q.useCallback(e=>{K.current=Math.max(0,K.current+(e?1:-1))},[]),ce=Q.useCallback(e=>e instanceof Element&&e.closest(`[data-slot="dropdown-menu-content"], [data-slot="dropdown-menu-item"]`)!==null,[]);Q.useEffect(()=>{if(!H)return;let e=e=>{K.current>0||ce(e.target)||G.current&&!G.current.contains(e.target)&&ae(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[ce,H]);let[q,le]=Q.useState(`edit`),[ue,de]=Q.useState(`edit`),[fe,pe]=Q.useState(`edit`),[me,he]=Q.useState(`preview`),[_e,ve]=Q.useState(0),ye=Q.useRef({}),be=Q.useRef({}),xe=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(()=>{qt(Ce),qt(we)},[Ce,we]);let Te=Q.useMemo(()=>[],[]),Ee=Bt(e=>w?e.byRoot[w]?.openPaths??Te:Te),Ne=Bt(e=>w?e.byRoot[w]?.selectedPath??null:null),Le=Bt(e=>w?e.byRoot[w]?.expandedPaths??Te:Te),Re=Bt(e=>e.addOpenPath),ze=Bt(e=>e.removeOpenPath),Ge=Bt(e=>e.removeOpenPathsByPrefix),qe=Bt(e=>e.removeExpandedPathsByPrefix),Je=Bt(e=>e.setSelectedPath),Xe=Bt(e=>e.toggleExpandedPath),et=Bt(e=>e.expandPaths),tt=Q.useCallback(e=>{let t=wa(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}},[]),nt=Q.useMemo(()=>Ee.map(tt),[Ee,tt]),ot=Q.useMemo(()=>{if(Ne){let e=Ea(Ne);if(Ee.some(t=>Ea(t)===e))return Ne}return Ee[0]??null},[Ee,Ne]),Z=Q.useMemo(()=>ot?tt(ot):null,[ot,tt]),lt=Z?.path??``;Q.useEffect(()=>{if(!w||!Ne)return;let e=Ea(Ne);Ee.some(t=>Ea(t)===e)||Je(w,Ee[0]??null)},[Ee,w,Ne,Je]);let ut=!!(w&&lt&&!Da(lt,w)),pt=ut?nn(lt):void 0,mt=Q.useMemo(()=>({allowOutsideWorkspace:e===`editor-only`&&ut,outsideFileGrant:pt,directory:w||void 0}),[e,ut,pt,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()}},[nt.length]);let[bt,xt]=Q.useState({}),[St,Ct]=Q.useState({}),wt=Q.useRef(new Set),Tt=Q.useRef(new Set),Et=Q.useRef(!1),Dt=Q.useRef(new Map),Ot=Q.useRef(0),[kt,At]=Q.useState([]),[jt,Pt]=Q.useState(!1),[Ft,It]=Q.useState(``),{isPlaying:Lt,play:Vt,stop:Ht}=Mt(),[Ut,Jt]=Q.useState(!1),[Yt,rn]=Q.useState(null),[an,on]=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),bn=Q.useRef(``),Sn=Q.useRef(``),wn=Q.useRef(null),En=Q.useRef(null),On=Q.useRef(null),kn=Q.useRef(0),[An,jn]=Q.useState(`idle`),[Nn,Pn]=Q.useState(!1),[Fn,In]=Q.useState(Ha),[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),[ar,cr]=Q.useState(null),[lr,ur]=Q.useState(null),[dr,fr]=Q.useState(!1),[pr,hr]=Q.useState(!1),[gr,_r]=Q.useState(!1),[vr,yr]=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=ya(e=>e.availableApps),jr=ya(e=>e.isCacheStale),Mr=ya(e=>e.initialize),Nr=ya(e=>e.loadInstalledApps);Q.useEffect(()=>{Mr()},[Mr]);let Pr=Q.useCallback(e=>{r.revealPath&&r.revealPath(e).catch(()=>{B.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=xa(Z.path)||w;t&&await h(t,e.appName)||B.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=ge(e=>e.settingsDefaultFileViewerPreview),Zr=ge(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}=sr({source:`file`,fileLabel:Z?.path??null,language:Z?.path&&en(Z.path)||`text`,getCodeForRange:e=>$r(Ft,or(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&&Na(r.name))continue;let t=r.name,i=wa(r.path||``),a=i?Ta(i)?i:wa(`${e}/${i}`):wa(`${e}/${t}`),o=r.isDirectory?`directory`:`file`,s=o===`file`&&t.includes(`.`)?t.split(`.`).pop()?.toLowerCase():void 0;n.push({name:t,path:a,type:o,extension:s})}return Ca(n)},[S,y]),fi=Q.useCallback(async e=>{let t=wa(e.trim());if(!t||wt.current.has(t)||Tt.current.has(t))return;Tt.current=new Set(Tt.current),Tt.current.add(t);let n=Ot.current+1;Ot.current=n,Dt.current=new Map(Dt.current),Dt.current.set(t,n);let i=()=>Dt.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);wt.current=new Set(wt.current),wt.current.add(t),Ct(e=>{if(!e[t])return e;let n={...e};return delete n[t],n}),xt(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){qe(w,t),Ct(e=>{if(!e[t])return e;let n={...e};return delete n[t],n});return}console.error(`Failed to load files directory:`,e),Ct(e=>({...e,[t]:n}))}).finally(()=>{i()&&(Dt.current=new Map(Dt.current),Dt.current.delete(t),Tt.current=new Set(Tt.current),Tt.current.delete(t))})},[r,di,qe,w]),pi=Q.useCallback(async()=>{w&&(wt.current=new Set,Tt.current=new Set,Dt.current=new Map,Ct({}),xt(e=>Object.keys(e).length===0?e:{}),await fi(w))},[fi,w]),mi=Q.useCallback(async e=>{if(!e){await pi();return}let t=wa(e);wt.current=new Set(wt.current),wt.current.delete(t),Tt.current=new Set(Tt.current),Tt.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),on(``),un(null),I(!1)),n&&(gi.current=e,Et.current=!1,wt.current=new Set,Tt.current=new Set,Dt.current=new Map,Ct({}),xt(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=>wa(e)).filter(e=>!!e&&e!==w&&e.startsWith(`${w}/`)&&!wt.current.has(e)&&!Tt.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=>{B.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=wa(`${e?`${e}/`:``}${tr.trim()}`);await r.writeFile(o,``).then(async r=>{r.success&&(B.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=wa(`${e?`${e}/`:``}${tr.trim()}`);await r.createDirectory(o).then(async r=>{r.success&&(B.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=wa(`${o?`${o}/`:``}${tr.trim()}`);await r.rename(e,s).then(async r=>{r.success&&(B.success(n(`sidebarFilesTree.toast.renamedSuccessfully`)),await mi(o),w&&Ge(w,e),(Z?.path===e||Z?.path.startsWith(`${e}/`))&&(w&&Je(w,null),It(``),rn(null),on(``),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&&(B.success(n(`sidebarFilesTree.toast.deletedSuccessfully`)),await mi(o),w&&Ge(w,e),(Z?.path===e||Z?.path.startsWith(`${e}/`))&&(w&&Je(w,null),It(``),rn(null),on(``),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,Je,n]);Q.useEffect(()=>{if(!C){At([]),Pt(!1);return}let e=ee.trim();if(!e){At([]),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||!Pa(e.path)).map(e=>({name:e.name,path:wa(e.path),type:`file`,extension:e.extension,relativePath:e.relativePath}));At(n)}).catch(()=>{t||At([])}).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&&Ia(n)&&Ge(w,t)}})),()=>{e=!0}},[r,Ee,Ge,w]);let bi=Q.useMemo(()=>Ft.length>La?`${Ft.slice(0,La)}\n\n… truncated …`:Ft,[Ft]),xi=dn!==bi,Si=Q.useCallback(async()=>{if(!Z||!r.writeFile)return B.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=Va(dn,hn);return(await r.writeFile(Z.path,e))?.success?(It(dn),Z?.path&&$t(Z.path)&&(bn.current=dn,Sn.current=dn),yi(Z.path).then(e=>{e&&(On.current=e)}).catch(()=>{}),!0):(B.error(n(`filesView.toast.writeFileFailed`)),!1)}catch(e){return B.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(Ra,Fn?`true`:`false`)}catch{}},[Fn]),Q.useEffect(()=>{Fn||(jn(`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&&(jn(`saved`),setTimeout(()=>jn(`idle`),2e3))})},Ci),()=>{vn.current&&=(clearTimeout(vn.current),null)}},[Fn,dn,xi,Z,r.writeFile,pn,Si]),Q.useEffect(()=>{jn(`idle`)},[Z?.path]),Q.useEffect(()=>{let e=e=>{Fe(e)&&(e.key.toLowerCase()===`s`?(e.preventDefault(),vn.current&&=(clearTimeout(vn.current),null),pn||Si().then(e=>{e&&(jn(`saved`),setTimeout(()=>jn(`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=Bt.getState().byRoot[w],n=e?.selectedPath??e?.openPaths[0]??null;return kn.current===r&&n===t.path};rn(null),on(``),un(null);let o=Qt(t.path),s=t.path.toLowerCase().endsWith(`.svg`),c=Zt(t.path);if(f&&I(!0),i.isDesktop&&o&&!s){It(``),fn(``),Jt(!0);return}if(!i.isDesktop&&o&&!s){It(``),fn(``),un(t.path),Jt(!1);return}if(c){It(``),fn(``),un(t.path),Jt(!1);return}Jt(!0);let l=nn(t.path),u={allowOutsideWorkspace:e===`editor-only`&&!!w&&!Da(t.path,w),outsideFileGrant:l};await vi(t.path,u).then(e=>{if(!a())return;let n=Ba(e);gn(za(e)),It(n),bn.current=n,Sn.current=n,fn(n.length>La?`${n.slice(0,La)}\n\n… truncated …`:n),un(t.path),yi(t.path,u).then(e=>{e&&a()&&(On.current=e)}).catch(()=>{})}).catch(e=>{if(a()){if(Fa(e)){if(Jt(!1),w&&Je(w,null),rn(null),It(``),fn(``),un(null),On.current=null,j.trim().length>0&&M(``),f&&I(!1),w){let e=[...Oa(t.path,w),t.path];e.length>0&&et(w,e);for(let t of e)wt.current.has(t)||fi(t)}return}if(Ia(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()&&Jt(!1)})},[et,f,fi,e,vi,yi,Ge,w,i.isDesktop,j,Je,n]),Ti=Q.useCallback(async(e,t)=>{if(!w)return;let n=Oa(e,w),r=t?[...n,e]:n;r.length>0&&et(w,r);let i=r.map(e=>{if(!wt.current.has(e))return fi(e)}).filter(Boolean);await Promise.all(i)},[et,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&&(Je(w,e.path),Re(w,e.path),Ti(e.path,!1)),rn(null),on(``),It(``),bn.current=``,Sn.current=``,fn(``),un(null),f&&I(!0)},[Re,Ti,xi,f,w,Je]);Q.useEffect(()=>{Z?.path&&Ti(Z.path,!1)},[Ti,Z?.path]),Q.useEffect(()=>{if(!Z){kn.current+=1,Jt(!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(!Ja(t,e,ln))return;let n=!1,r=window.setInterval(()=>{document.hidden||yi(e,mt).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,mt]);let ki=Q.useCallback(()=>{let e=zn.current,t=Bn.current,n=Vn.current;if(zn.current=null,Bn.current=null,Vn.current=null,Hn.current=!0,Rn(!1),fn(bi),n){w&&ze(w,n),Z?.path===n&&(e?Di(e):(w&&Je(w,null),It(``),rn(null),on(``),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,Je]),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&&Je(w,null),It(``),rn(null),on(``),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,Je]),ji=Q.useCallback(e=>{let t=Z?.path===e,n=Ei(e,nt);if(t&&xi){Rn(!0),zn.current=n,Vn.current=e;return}if(w&&ze(w,e),t){if(n){Di(n);return}w&&Je(w,null),It(``),rn(null),on(``),un(null),f&&I(!1)}},[Ei,Di,xi,f,nt,ze,w,Z?.path,Je]),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=wa(e);w&&(Xe(w,t),wt.current.has(t)||await fi(t))},[fi,w,Xe]),Fi=Q.useMemo(()=>w?na(w,bt):[],[bt,w]),Ii=Q.useMemo(()=>new Set(Le.map(e=>wa(e))),[Le]),Li=ra(Le),Ri=Q.useCallback(()=>{if(w){if(Li){Et.current=!1,qe(w,w);return}Et.current=!0,et(w,Fi)}},[Li,Fi,et,qe,w]);Q.useEffect(()=>{if(!w||!Et.current)return;let e=ia(Fi,Le);if(e.length>0){et(w,e);return}let t=new Set([...wt.current,...Object.keys(St)]);aa(Fi,Le,t)&&(Et.current=!1)},[Fi,et,Le,St,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(wa(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)(Ka,{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:ar,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:[St[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:St[e.path],children:St[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&&Qt(Z.path)),Hi=!!(Z?.path&&Z.path.toLowerCase().endsWith(`.svg`)),Ui=!!(Z?.path&&Zt(Z.path)),Wi=Q.useMemo(()=>wa(Wr?.path??``),[Wr?.path]),Gi=!!(Wr&&Wi&&lt&&lt===Wi&&!Ut&&!Yt&&!Vi&&!Ui),Ki=Q.useMemo(()=>ka(w,lt),[lt,w]),qi=Q.useCallback(e=>{let t=!e.state.selection.main.empty;if(yr(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<=La),$i=!!(Z?.path&&Wa(Z.path)),ta=!!(Z?.path&&Ga(Z.path)),oa=!!(Z?.path&&$t(Z.path)),sa=!!(Z&&!Vi&&!Ui),ca=sa&&!$i&&!oa&&!(ta&&fe===`preview`),la=$i&&ue===`edit`||ta&&fe===`edit`||!$i&&!ta&&q===`edit`,ua=Q.useMemo(()=>lt?rt(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),$e(t).then(t=>{e||fa(t)}),()=>{e=!0}},[Z?.path,ua]),Q.useEffect(()=>{!Qi&&q===`edit`&&le(`view`)},[Qi,q]);let pa=`openchamber:files:md-viewer-mode`,ma=`openchamber:files:html-viewer-mode`;Q.useEffect(()=>{let e=Z?.path;if(!e)return;le(ye.current[e]??`edit`);let t=Xr?`preview`:`edit`;try{let e=localStorage.getItem(pa);(e===`preview`||e===`edit`)&&(t=e)}catch{}de(be.current[e]??t);let n=Xr?`preview`:`edit`;try{let e=localStorage.getItem(ma);(e===`preview`||e===`edit`)&&(n=e)}catch{}pe(xe.current[e]??n),he(Se.current[e]??(Xr?`preview`:`edit`))},[Z?.path,Xr]);let ha=Q.useCallback(e=>{let t=Z?.path;t&&(ye.current[t]=e),le(e)},[Z?.path]),ga=Q.useCallback(e=>{let t=Z?.path;t&&(be.current[t]=e),de(e);try{localStorage.setItem(pa,e)}catch{}},[Z?.path]),_a=Q.useCallback(()=>ue,[ue]),va=Q.useCallback(e=>{let t=Z?.path;t&&(xe.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),wn.current!==null&&(cancelAnimationFrame(wn.current),wn.current=null),e===`edit`)fn(bn.current||Ft),he(e);else{bn.current=dn;let e=t;he(`edit`),wn.current=requestAnimationFrame(()=>{wn.current=requestAnimationFrame(()=>{wn.current=null,!(w&&e&&Bt.getState().byRoot[w]?.selectedPath!==e)&&(ve(e=>e+1),he(`preview`))})});return}},[dn,Ft,w,Z?.path]),ja=Q.useCallback(async(e,t)=>{if(!r.writeFile||t===Sn.current)return!1;if(!(await r.writeFile(e,t))?.success)return B.error(n(`filesView.toast.writeFileFailed`)),!1;bn.current=t,Sn.current=t,fn(t);let i=await yi(e,mt).catch(()=>null);return i&&(On.current=i),!0},[r,yi,mt,n]);Q.useEffect(()=>()=>{yn.current&&=(clearTimeout(yn.current),null),wn.current!==null&&(cancelAnimationFrame(wn.current),wn.current=null)},[me,Z?.path]);let Xa=Q.useCallback(e=>{if(bn.current=e,!Z?.path||me!==`preview`||!r.writeFile)return;yn.current&&clearTimeout(yn.current);let t=Z.path;yn.current=setTimeout(()=>{yn.current=null,ja(t,e).then(e=>{e&&(Pn(!0),setTimeout(()=>Pn(!1),1500))}).catch(e=>{B.error(e instanceof Error?e.message:n(`filesView.toast.saveFailed`))})},Ci)},[me,r.writeFile,ja,Z?.path,n]),Za=Q.useMemo(()=>oa&&(bn.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)ye.current[e]=`edit`,Wa(e)&&(be.current[e]=t),Ga(e)&&(xe.current[e]=t),$t(e)&&(Se.current[e]=t);le(`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=wa(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(tt(n));return}if(Ut||ln!==n)return;if(Yt||Vi||Ui){Gr(null),Xn.current={key:``,attempts:0};return}if(!Qi)return;if(q!==`edit`){le(`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,Yt,Ut,Vi,Ui,ln,Di,Wr,w,Z?.path,Gr,q,tt]),Q.useEffect(()=>{if(!Kr||!w)return;let e=wa(Kr);if(!e){qr(null);return}if(Z?.path!==e){if(Ln)return;Di(tt(e));return}if(!(Ut||ln!==e||Yt||Vi||Ui)){if(Qi&&q===`edit`){let e=Gn.current;if(!e)return;e.focus()}qr(null)}},[Qi,Ln,Yt,Ut,Di,Vi,Ui,ln,Kr,w,Z?.path,qr,q,tt]);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(q!==`edit`||f)return;let e=Ye(`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(Ke(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,q]);let eo=c(e=>e.editorFontSize),to=Q.useMemo(()=>{if(!Z?.path)return[Cn(o,{fontSize:eo})];let e=en(Z.path),t=[Cn(o,e?{syntaxColors:!1,fontSize:eo}:{fontSize:eo})],n=ua??da;return n&&t.push(n),e&&t.push(Dn({language:e,themeName:o.metadata.id,theme:Kt(o)})),ne&&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,ne,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}|${mt.allowOutsideWorkspace?`outside`:`workspace`}|${mt.outsideFileGrant??``}`:``,io=Z?.path&&Ui?`${Z.path}|${mt.allowOutsideWorkspace?`outside`:`workspace`}|${mt.outsideFileGrant??``}`:``,ao=Z?.path&&ta&&fe===`preview`&&!i.isVSCode?Z.path:``,oo=n(`filesView.error.readFileFailed`),{readyKey:so,nonce:co}=Ya(ro,rn,oo),{readyKey:lo,nonce:uo}=Ya(ao,rn,oo),{readyKey:fo,nonce:po}=Ya(io,rn,oo),mo=!!(ro&&so!==ro),ho=!!(ao&&lo!==ao),go=!!(io&&fo!==io),_o=Z?.path&&Vi?i.isDesktop?Hi?`data:${Xt(Z.path)};utf8,${encodeURIComponent(Ft)}`:an:Hi?`data:${Xt(Z.path)};utf8,${encodeURIComponent(Ft)}`:so===ro?a().authenticatedAsset(`/api/fs/raw`,{path:Z.path,allowOutsideWorkspace:mt.allowOutsideWorkspace?`true`:void 0,outsideFileGrant:mt.outsideFileGrant,directory:w||void 0}):``:``,vo=Q.useCallback(()=>{if(!Z?.path||!Vi)return;let e=Hi?_o:Z.path||_o;if(!e)return;let t=Z.name||Z.path;W({open:!0,title:t,content:``,metadata:{tool:`image-preview`,filename:t,mime:Xt(Z.path)},image:{url:e,mimeType:Xt(Z.path),filename:t}})},[_o,Vi,Hi,Z?.name,Z?.path]),yo=Q.useCallback(e=>{W(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:mt.allowOutsideWorkspace?`true`:void 0,outsideFileGrant:mt.outsideFileGrant,directory:w||void 0}):``,So=Q.useCallback(e=>(0,$.jsx)(`div`,{className:`h-full overflow-hidden bg-[var(--surface-background)]`,children:(0,$.jsx)(`iframe`,{src:xo,className:`h-full w-full border-0`,title:e.name},po)}),[xo,po]);Q.useEffect(()=>{let e=!1;return(async()=>{if(!i.isDesktop||!Z?.path||!Vi||Hi){cn.current&&=(URL.revokeObjectURL(cn.current),``),on(``);return}rn(null),cn.current&&=(URL.revokeObjectURL(cn.current),``),await(r.readFileBinary?r.readFileBinary(Z.path,mt).then(e=>e.dataUrl):(async()=>{let t=await _(`/api/fs/raw`,{query:{path:Z.path,allowOutsideWorkspace:mt.allowOutsideWorkspace?`true`:void 0,outsideFileGrant:mt.outsideFileGrant,directory:w||void 0}});if(!t.ok)throw Error(n(`filesView.error.readFileFailed`));let r=await t.blob(),i=URL.createObjectURL(r);return e?(URL.revokeObjectURL(i),``):(cn.current=i,i)})()).then(t=>{e||(on(t),un(Z.path))}).catch(t=>{cn.current&&=(URL.revokeObjectURL(cn.current),``),e||(on(``),rn(t instanceof Error?t.message:n(`filesView.error.readFileFailed`)),un(null))}).finally(()=>{e||Jt(!1)})})(),()=>{e=!0}},[r,Vi,Hi,w,i.isDesktop,Z?.path,mt,n]),Q.useEffect(()=>()=>{cn.current&&=(URL.revokeObjectURL(cn.current),``)},[]);let Co=Q.useCallback(()=>Qn(null),[]),wo=Q.useMemo(()=>mr({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)(sn,{file:{name:e.name,contents:t,lang:en(e.path)||void 0},options:{disableFileHeader:!0,overflow:ne?`wrap`:`scroll`,theme:no,themeType:o.metadata.variant===`dark`?`dark`:`light`},className:`block h-full w-full`,style:{height:`100%`}})}),[o.metadata.variant,no,ne]),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:`${Pe()}+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:`${Pe()}+S`}),"aria-label":n(`filesView.editor.saveAria`,{shortcut:`${Pe()}+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)(ft,{shortcut:`⌘+I`})]})):null,(0,$.jsxs)(Qe,{onOpenChange:se,children:[(0,$.jsxs)(Ue,{children:[(0,$.jsx)(Ve,{asChild:!0,children:(0,$.jsx)(`span`,{className:`inline-flex`,children:(0,$.jsx)(at,{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)(it,{align:`end`,className:`w-56 max-h-[70vh] overflow-y-auto`,children:[Ar.map(e=>(0,$.jsxs)(st,{className:`flex items-center gap-2`,onClick:()=>void Fr(e),children:[(0,$.jsx)(Sa,{label:e.label,iconDataUrl:e.iconDataUrl}),(0,$.jsx)(`span`,{className:`typography-ui-label text-foreground`,children:e.label})]},e.id)),jr?(0,$.jsxs)(st,{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(ne?`filesView.editor.disableLineWrap`:`filesView.editor.enableLineWrap`),(0,$.jsx)(X,{variant:`ghost`,size:`sm`,onClick:()=>L(!ne),className:J(`size-6 p-0 transition-opacity hover:bg-transparent focus-visible:bg-transparent active:bg-transparent`,ne?`text-foreground opacity-100`:`text-muted-foreground opacity-65 hover:opacity-100`),title:n(ne?`filesView.editor.disableLineWrap`:`filesView.editor.enableLineWrap`),children:(0,$.jsx)(Y,{name:`text-wrap`,className:`size-4`})})),q===`edit`&&(0,$.jsxs)($.Fragment,{children:[o(n(`filesView.editor.findInFile`),(0,$.jsx)(X,{variant:`ghost`,size:`sm`,onClick:e=>{V(!z),e.currentTarget.blur()},className:`size-6 p-0 text-foreground opacity-100 transition-opacity hover:bg-transparent focus-visible:bg-transparent active:bg-transparent`,title:n(`filesView.editor.findInFile`),children:(0,$.jsx)(Y,{name:`search`,className:`size-4`})})),o(n(`filesView.editor.goToLine`),(0,$.jsx)(X,{variant:`ghost`,size:`sm`,onClick:e=>{_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)(ea,{open:gr,onOpenChange:_r,view:Gn.current,variant:`inline`})]})]}),ca&&Qi&&!ta&&(0,$.jsx)(Tn,{currentMode:q===`view`?`preview`:`edit`,onToggle:()=>{ha(q===`view`?`edit`:`view`)}}),$i&&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`})})),Ga(Z?.path??``)&&(0,$.jsx)(Tn,{currentMode:Qa(),onToggle:()=>{va(Qa()===`preview`?`edit`:`preview`)}}),$i&&_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(Lt?`filesView.tts.stopSpeaking`:`filesView.tts.readAloud`),onClick:()=>{Lt?Ht():Ft.trim()&&Vt(Ft)},children:Lt?(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(Lt?`filesView.tts.stopSpeaking`:`filesView.tts.readAloud`)})]}),oa&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Tn,{currentMode:me,onToggle:()=>Aa(me===`preview`?`edit`:`preview`)}),me===`preview`&&(0,$.jsx)(X,{variant:`ghost`,size:`sm`,onClick:async()=>{let e=En.current?.getXml();if(yn.current&&=(clearTimeout(yn.current),null),Z?.path&&e){if(!await ja(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 re(Ft)).ok?(fr(!0),Un.current!==null&&window.clearTimeout(Un.current),Un.current=window.setTimeout(()=>{fr(!1)},1200)):B.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 re(Ki)).ok?(hr(!0),Wn.current!==null&&window.clearTimeout(Wn.current),Wn.current=window.setTimeout(()=>{hr(!1)},1200)):B.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:pr?(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),B.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:()=>ie(!1),className:`size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent`,title:n(`filesView.editor.exitFullscreen`),"aria-label":n(`filesView.editor.exitFullscreen`),children:(0,$.jsx)(Y,{name:`fullscreen-exit`,className:`size-4`})})):!f&&e===`full`&&o(n(R?`filesView.editor.exitFullscreen`:`filesView.editor.fullscreen`),(0,$.jsx)(X,{variant:`ghost`,size:`sm`,onClick:()=>ie(!R),className:`size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent`,title:n(R?`filesView.editor.exitFullscreen`:`filesView.editor.fullscreen`),"aria-label":n(R?`filesView.editor.exitFullscreen`:`filesView.editor.fullscreen`),children:R?(0,$.jsx)(Y,{name:`fullscreen-exit`,className:`size-4`}):(0,$.jsx)(Y,{name:`fullscreen`,className:`size-4`})}))]})},Do=(0,$.jsxs)(`div`,{className:`relative flex h-full min-h-0 min-w-0 w-full flex-col overflow-hidden`,children:[(0,$.jsx)(Me,{open:Ln,onOpenChange:e=>{e||Rn(!0)},children:(0,$.jsxs)(ke,{showCloseButton:!1,className:`max-w-md`,children:[(0,$.jsxs)(De,{children:[(0,$.jsx)(Ae,{children:n(`filesView.unsaved.title`)}),(0,$.jsx)(je,{children:n(`filesView.unsaved.description`)})]}),(0,$.jsxs)(Oe,{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)(Qe,{children:[(0,$.jsx)(at,{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)(Nt,{filePath:Z.path,extension:Z.extension,className:`size-3.5 flex-shrink-0`}),(0,$.jsx)(Ma,{name:Z.name}),(0,$.jsx)(Y,{name:`arrow-down-s`,className:`size-4 flex-shrink-0 text-muted-foreground`})]})}),(0,$.jsx)(it,{align:`start`,className:`w-[min(24rem,calc(100vw-2rem))] max-w-[calc(100vw-2rem)]`,children:nt.map(e=>{let t=Z?.path===e.path;return(0,$.jsxs)(st,{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)(Nt,{filePath:e.path,extension:e.extension,className:`size-3.5 flex-shrink-0`}),(0,$.jsx)(Ma,{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`)}):nt.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:nt.map(e=>{let t=Z?.path===e.path;return(0,$.jsxs)(`div`,{title:ka(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)(Nt,{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&&!z&&!(Qr&&!f)&&(0,$.jsx)(`div`,{ref:G,className:`absolute right-3 top-3 z-30`,onMouseLeave:()=>{K.current>0||ae(!1)},children:H?Eo():(0,$.jsxs)(`div`,{className:`flex items-center gap-1`,children:[$i?(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:()=>ae(!0),children:(0,$.jsx)(X,{variant:`ghost`,size:`sm`,onClick:()=>ae(!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?Ut||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`)]}):Yt?(0,$.jsx)(`div`,{className:`p-3 typography-ui text-[color:var(--status-error)]`,children:Yt}):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)(Mn,{ref:En,xml:Za,onChange:Xa},`${Z.path}:${_e}`)}):Z&&$i&&_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)(Ze,{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)(Gt,{content:Ft,className:`typography-markdown-body`,stripFrontmatter:!0,enableFileReferences:!1})})]}):Z&&ta&&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&&q===`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)(xn,{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,yr(!1),Sr(null),Jn(e=>e+1)},enableSearch:!0,searchOpen:z,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?St[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:jt?(0,$.jsxs)(`li`,{className:`flex items-center gap-1.5 px-2 py-1 typography-meta text-muted-foreground`,children:[(0,$.jsx)(Y,{name:`loader-4`,className:`size-4 animate-spin`}),n(`filesView.tree.search.searching`)]}):kt.length>0?kt.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:[Ua(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`&&R&&Z&&(0,$.jsx)(`div`,{className:`absolute inset-0 z-50 flex flex-col bg-background`,children:(0,$.jsxs)(`div`,{className:`flex-1 min-h-0 min-w-0 relative`,children:[(0,$.jsx)(`div`,{className:`absolute right-4 top-4 z-30`,children:Eo({exitFullscreenOnly:!0})}),(0,$.jsx)(Ie,{outerClassName:`h-full min-w-0`,className:`h-full min-w-0`,children:Ut||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…`]}):Yt?(0,$.jsx)(`div`,{className:`p-4 typography-ui text-[color:var(--status-error)]`,children:Yt}):Vi?bo(Z,{fullHeight:!0}):Ui?So(Z):$i&&_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)(Ze,{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)(Gt,{content:Ft,className:`typography-markdown-body`,stripFrontmatter:!0,enableFileReferences:!1})})]}):ca&&q===`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)(xn,{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,yr(!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)(qa,{activeDialog:Zn,dialogData:$n,dialogInputValue:tr,onDialogInputChange:nr,isDialogSubmitting:rr,onDialogSubmit:_i,onClose:Co,inputRef:_n}),jo,xr?(0,$.jsx)(br,{position:xr,onDismiss:()=>Sr(null),onAddToChat:Ji}):null,U.open?(0,$.jsx)(Q.Suspense,{fallback:null,children:(0,$.jsx)(ba,{popup:U,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 Za(e){return e+1}var Qa=e=>({providerID:e.providerID,modelID:e.modelID,variant:e.variant,agent:e.agent});function $a(e){let t=(0,Ln.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=ge(uo),g=ge(lo),_=Se(co),v=ge(so),y=ge(oo),b=ge(ao),x=ge(io),S=ge(ro),C;t[2]!==S||t[3]!==b||t[4]!==y||t[5]!==x?(C=()=>Qa({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(Qa({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=no,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,ne,L;t[35]!==w.variant||t[36]!==I?(ne=()=>{I||!w.variant||T(to)},L=[I,w.variant],t[35]=w.variant,t[36]=I,t[37]=ne,t[38]=L):(ne=t[37],L=t[38]),Q.useEffect(ne,L);let re;t[39]!==w.modelID||t[40]!==w.providerID?(re=w.providerID.trim().length>0&&w.modelID.trim().length>0,t[39]=w.modelID,t[40]=w.providerID,t[41]=re):re=t[41];let R=re,ie;t[42]!==R||t[43]!==w||t[44]!==u||t[45]!==d?(ie=()=>{!R||d||u(w)},t[42]=R,t[43]=w,t[44]=u,t[45]=d,t[46]=ie):ie=t[46];let z=ie,B,V;t[47]!==z||t[48]!==r?(B=()=>{if(!r)return;let e=e=>{(e.metaKey||e.ctrlKey)&&e.key===`Enter`&&(e.preventDefault(),z())};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},V=[r,z],t[47]=z,t[48]=r,t[49]=B,t[50]=V):(B=t[49],V=t[50]),Q.useEffect(B,V);let H;t[51]!==n||t[52]!==a?(H=n(a===`worktree`?`rightSidebar.contextNotesTodo.sendDialog.title.newWorktree`:`rightSidebar.contextNotesTodo.sendDialog.title.newSession`),t[51]=n,t[52]=a,t[53]=H):H=t[53];let ae=H,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)(De,{children:(0,$.jsx)(Ae,{children:ae})}),t[57]=ae,t[58]=U);let W;t[59]===n?W=t[60]:(W=n(`chat.modelControls.model`),t[59]=n,t[60]=W);let G;t[61]===W?G=t[62]:(G=(0,$.jsx)(`span`,{className:`typography-meta font-medium text-muted-foreground`,children:W}),t[61]=W,t[62]=G);let K;t[63]===Symbol.for(`react.memo_cache_sentinel`)?(K=(e,t)=>{T(n=>({...n,providerID:e,modelID:t,variant:``}))},t[63]=K):K=t[63];let se;t[64]!==w.modelID||t[65]!==w.providerID?(se=(0,$.jsx)(nt,{providerId:w.providerID,modelId:w.modelID,className:`max-w-[320px] justify-between`,dropdownPortalToBody:!0,onChange:K}),t[64]=w.modelID,t[65]=w.providerID,t[66]=se):se=t[66];let ce;t[67]!==G||t[68]!==se?(ce=(0,$.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-1.5`,children:[G,se]}),t[67]=G,t[68]=se,t[69]=ce):ce=t[69];let q;t[70]===n?q=t[71]:(q=n(`sessions.scheduledTasks.editor.thinkingLevel.label`),t[70]=n,t[71]=q);let le;t[72]===q?le=t[73]:(le=(0,$.jsx)(`span`,{className:`typography-meta font-medium text-muted-foreground`,children:q}),t[72]=q,t[73]=le);let ue=!I,de;t[74]===Symbol.for(`react.memo_cache_sentinel`)?(de=e=>T(t=>({...t,variant:e})),t[74]=de):de=t[74];let fe;t[75]!==w.variant||t[76]!==ue||t[77]!==F?(fe=(0,$.jsx)(xt,{value:w.variant,options:F,disabled:ue,onChange:de}),t[75]=w.variant,t[76]=ue,t[77]=F,t[78]=fe):fe=t[78];let pe;t[79]!==le||t[80]!==fe?(pe=(0,$.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[le,fe]}),t[79]=le,t[80]=fe,t[81]=pe):pe=t[81];let me;t[82]===n?me=t[83]:(me=n(`sessions.scheduledTasks.editor.agent.label`),t[82]=n,t[83]=me);let he;t[84]===me?he=t[85]:(he=(0,$.jsx)(`span`,{className:`typography-meta font-medium text-muted-foreground`,children:me}),t[84]=me,t[85]=he);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)(et,{agentName:w.agent,filter:M,dropdownPortalToBody:!0,onChange:_e}),t[87]=w.agent,t[88]=ve);let ye;t[89]!==he||t[90]!==ve?(ye=(0,$.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[he,ve]}),t[89]=he,t[90]=ve,t[91]=ye):ye=t[91];let be;t[92]!==ce||t[93]!==pe||t[94]!==ye?(be=(0,$.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[ce,pe,ye]}),t[92]=ce,t[93]=pe,t[94]=ye,t[95]=be):be=t[95];let xe=`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(eo),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 Oe=!R||d,je;t[109]!==d||t[110]!==n?(je=n(d?`rightSidebar.contextNotesTodo.sendDialog.actions.sending`:`rightSidebar.contextNotesTodo.sendDialog.actions.send`),t[109]=d,t[110]=n,t[111]=je):je=t[111];let Ne;t[112]!==z||t[113]!==Oe||t[114]!==je?(Ne=(0,$.jsx)(X,{size:`sm`,onClick:z,disabled:Oe,children:je}),t[112]=z,t[113]=Oe,t[114]=je,t[115]=Ne):Ne=t[115];let Pe;t[116]!==Ee||t[117]!==Ne?(Pe=(0,$.jsxs)(`div`,{className:`flex items-center justify-end gap-2`,children:[Ee,Ne]}),t[116]=Ee,t[117]=Ne,t[118]=Pe):Pe=t[118];let Fe;t[119]!==xe||t[120]!==Ce||t[121]!==Pe?(Fe=(0,$.jsxs)(`div`,{className:xe,children:[Ce,Pe]}),t[119]=xe,t[120]=Ce,t[121]=Pe,t[122]=Fe):Fe=t[122];let J;t[123]!==U||t[124]!==be||t[125]!==Fe?(J=(0,$.jsxs)(ke,{className:`max-w-md overflow-visible`,children:[U,be,Fe]}),t[123]=U,t[124]=be,t[125]=Fe,t[126]=J):J=t[126];let Y;return t[127]!==r||t[128]!==oe||t[129]!==J?(Y=(0,$.jsx)(Me,{open:r,onOpenChange:oe,children:J}),t[127]=r,t[128]=oe,t[129]=J,t[130]=Y):Y=t[130],Y}function eo(e){return{...e,runAsGoal:e.runAsGoal!==!0}}function to(e){return{...e,variant:``}}function no(e){return K(e.mode)}function ro(e){return e.currentAgentName||``}function io(e){return e.currentVariant||``}function ao(e){return e.currentModelId}function oo(e){return e.currentProviderId}function so(e){return e.providers}function co(e){return e.loadAgents}function lo(e){return e.loadAgents}function uo(e){return e.loadProviders}var fo=(e,t)=>e.mode===`target`?`target`:t===e.repoPath?`repo`:`home`,po=e=>({optional:!0,...e?{directory:e}:{}}),mo=async(e,t,n)=>{if(e?.readFile){let r=await e.readFile(t,po(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`)},ho=(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 mo(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 mo(i,t.repoPath,t.scopeDirectory);if(e!==null)return{kind:`resolved`,source:`repo`,path:t.repoPath,content:e};let n=await mo(i,t.homePath,t.scopeDirectory);return n===null?{kind:`missing`,candidates:[t.repoPath,t.homePath]}:{kind:`resolved`,source:`home`,path:t.homePath,content:n}}}},go=(e,t)=>{let r=(0,Ln.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}=Rt(),s,c;if(r[2]!==o||r[3]!==e){let t=n();c=N,s=ho(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)},_o=(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??``},vo=e=>({persisted:e,desired:e,desiredRevision:0,nextAttemptToken:1,inFlight:null,failed:null}),yo=(e,t)=>e.desired===t?e:{...e,desired:t,desiredRevision:e.desiredRevision+1,failed:null},bo=e=>e.desired===e.persisted&&e.inFlight===null&&e.failed===null,xo=(e,t,n)=>({identity:e,path:t,content:n.desired,baseContent:n.persisted}),So=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]},Co=(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,wo=(e,t,n)=>e.inFlight?.token===t.token?{...e,inFlight:null,failed:{revision:t.revision,error:n}}:e,To=e=>({...e,failed:null}),Eo=(e,t)=>e===t,Do=(e,t,n)=>Eo(t,n)?So(e):[e,null],Oo=e=>e.desired!==e.persisted||e.inFlight!==null,ko=(e,t,n=32)=>{let r=[];for(let[i,a]of e){if(e.size<=n)return r;i!==t&&bo(a)&&(e.delete(i),r.push(i))}return r},Ao=(e,t,n)=>{let r=e.get(t);r&&e.set(t,Co(r,n))},jo=(e,t,n,r)=>{let i=e.get(t);i&&e.set(t,wo(i,n,r))},Mo=(e,t)=>e&&t.path===null&&t.content===t.baseContent,No=(e,t)=>e&&t!==null,Po=e=>{if(!e)return``;let t=e.replace(/\\/g,`/`);return t===`/`?`/`:t.replace(/\/+$/,``)},Fo=(e,t)=>{let n=Po(e),r=t.replace(/\\/g,`/`).replace(/^\/+/,``).replace(/\/+$/,``);return!n||n===`/`?`/${r}`:`${n}/${r}`},Io=(e,t,n)=>Fo(Fo(Fo(e,`.opencode`),`plans`),`${t}-${n}.md`),Lo=(e,t)=>`~/.opencode/plans/${e}-${t}.md`,Ro=(e,t)=>{let n=e.trim();return n.startsWith(`~`)?n===`~`?t||n:(n.startsWith(`~/`)||n.startsWith(`~\\`))&&t?`${t}${n.slice(1)}`:n:n},zo=(e,t)=>{let n=Po(t.currentDirectory),r=Po(t.homeDirectory),i=Po(e);return n&&i.startsWith(n+`/`)?i.slice(n.length+1):r&&i===r?`~`:r&&i.startsWith(r+`/`)?`~${i.slice(r.length)}`:i},Bo=(e,t,n)=>{let r=Po(e.trim());if(!r)return null;let i=n?t.find(e=>e.id===n)??null:null;if(i?.path){let e=Po(i.path);if(r===e||r.startsWith(`${e}/`))return{id:i.id,path:i.path}}let a=t.filter(e=>{let t=Po(e.path);return r===t||r.startsWith(`${t}/`)}).sort((e,t)=>Po(t.path).length-Po(e.path).length)[0];return a?{id:a.id,path:a.path}:null},Vo=({targetPath:e=null})=>{let{t}=te(),r=he(e=>e.currentSessionId),i=he(e=>e.createSession),a=he(e=>e.initializeNewOpenChamberSession),o=he(e=>e.sendMessage),s=he(e=>e.setCurrentSession),l=de(),u=D(e=>e.homeDirectory),d=kt(e=>e.planModeEnabled),f=W(e=>e.projects),p=W(e=>e.activeProjectId),h=Vt(e=>e.directories),g=tn()??``,v=c(e=>e.setActiveMainTab),y=c(e=>e.setSessionSwitcherOpen),b=Rt(),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(()=>Po((typeof w?.directory==`string`?w.directory:``)||``),[w?.directory]),E=Q.useMemo(()=>Po(g||T),[g,T]),O=Q.useMemo(()=>Bo(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),ne=Q.useMemo(()=>!F||!T||!u?F:zo(F,{currentDirectory:T,homeDirectory:u}),[F,T,u]),[L,R]=Q.useState(``),[ie,z]=Q.useState(``),{isPlaying:B,play:V,stop:H}=Mt(),ae=ge(e=>e.showMessageTTSButtons),[oe,U]=Q.useState(null),[K,se]=Q.useState(0),q=Q.useMemo(()=>ne&&ne.split(`/`).pop()||t(`planView.file.defaultName`),[ne,t]),le=Q.useMemo(()=>L.trim()&&ce(L).title||t(`planView.title.default`),[L,t]),ue=Q.useMemo(()=>le.trim()||t(`planView.title.default`),[le,t]),[fe,pe]=Q.useState(!1),[me,_e]=Q.useState(`edit`),ve=Q.useRef(null),be=Q.useRef(!0),xe=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),Ae=Q.useRef(null),je=Q.useRef(null);Q.useEffect(()=>{be.current=!0;let e=Se.current,t=Te.current,n=xe.current;return()=>{be.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&&Oo(t)&&Ee.current(r)}}},[]);let Me=`openchamber:plan:md-viewer-mode`;Q.useEffect(()=>{try{let e=localStorage.getItem(Me);if(!e)return;let t=JSON.parse(e);(t===`preview`||t===`edit`)&&_e(t)}catch{}},[]);let Ne=Q.useCallback(e=>{_e(e);try{localStorage.setItem(Me,JSON.stringify(e))}catch{}},[]),Pe=Q.useRef(!1),Fe=Q.useRef(null),[J,Le]=Q.useState(!1);Q.useEffect(()=>{let e=()=>{Pe.current=!1,Fe.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:Ke,setSelection:qe,saveComment:Je,cancel:Ye,reset:Xe,startEdit:$e,deleteDraft:et}=sr({source:`plan`,fileLabel:q,language:F&&en(F)||`markdown`,getCodeForRange:e=>Re(L,or(e)),toStoreRange:e=>({startLine:e.start,endLine:e.end}),fromDraftRange:e=>({start:e.startLine,end:e.endLine})});Q.useEffect(()=>{ke(null),Xe()},[L,Xe]),Q.useEffect(()=>{qe(Oe)},[Oe,qe]);let tt=Q.useCallback(()=>{ke(null),Ye()},[Ye]),nt=Q.useCallback((e,t)=>{t&&ke(t),Je(e,t??Oe??void 0),ke(null)},[Oe,Je]);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),Ye())},t=window.setTimeout(()=>{document.addEventListener(`click`,e)},100);return()=>{window.clearTimeout(t),document.removeEventListener(`click`,e)}},[Ye,Be,Ke,S,Oe]);let ot=c(e=>e.editorFontSize),Z=Q.useMemo(()=>{let e=F?en(F):null,t=!!e&&e!==`markdown`,n=[Cn(C,t?{syntaxColors:!1,fontSize:ot}:{fontSize:ot})],r=rt(F||`plan.md`);return r&&n.push(r),t&&e&&n.push(Dn({language:e,themeName:C.metadata.id,theme:Kt(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?Io(T,w.time.created,w.slug):null,homePath:!e&&w?.slug&&w?.time?.created?Ro(Lo(w.time.created,w.slug),u||null):null}),[r,u,w?.slug,w?.time?.created,T,e]),ut=!!(e||d&&lt.repoPath&&lt.homePath),dt=go(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,vt=ut&&dt.isError&&dt.data===void 0,yt=Mo(ut&&dt.data?.kind===`missing`,{path:F,content:L,baseContent:ie}),bt=dt.data?.kind===`missing`?dt.data.candidates:null;Q.useEffect(()=>{if(!ut){De.current=null,I(null),R(``),z(``),U(null);return}let e=ut&&dt.data?.kind===`resolved`?{path:dt.data.path,content:dt.data.content}:null,t=De.current,n=xe.current.get(ht),r=_o({identity:De.current,path:F,content:L,baseContent:ie},ht,e,(n?.inFlight??null)!==null),i=De.current!==ht;if(i&&n&&!bo(n)){let t=Te.current.get(ht)?.path??null;r=xo(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=xe.current.get(t),r=Te.current.get(t);n&&r&&Oo(n)&&Ee.current(r)}De.current=ht,(i||r.path!==F||r.content!==L||r.baseContent!==ie)&&(I(r.path),R(r.content),z(r.baseContent),i&&U(xe.current.get(ht)?.failed?.error??null)),(!n||bo(n))&&xe.current.set(ht,vo(r.baseContent));for(let e of ko(xe.current,ht))Te.current.delete(e)},[ie,L,ht,ut,dt.data,F]);let xt=Q.useCallback(e=>{if(we.current.has(e.identity))return;let n=(async()=>{for(;;){let n=xe.current.get(e.identity);if(!n)return;let[r,i]=Do(n,e.transport,pt.current);if(xe.current.set(e.identity,r),!i)return;try{await e.write(i.content),await e.commit(i.content),Ao(xe.current,e.identity,i);for(let e of ko(xe.current,De.current))Te.current.delete(e);be.current&&De.current===e.identity&&(z(i.content),U(null))}catch(n){let r=n instanceof Error?n.message:t(`planView.error.saveFailed`);jo(xe.current,e.identity,i,r);let a=xe.current.get(e.identity),o=a?.failed?.revision;be.current&&De.current===e.identity&&a&&o!==void 0&&o===a.desiredRevision&&U(r)}}})().finally(()=>{we.current.delete(e.identity)});we.current.set(e.identity,n)},[t]);Ee.current=xt,Q.useEffect(()=>{let e=Se.current,n=xe.current.get(ht)??vo(L);xe.current.set(ht,yo(n,L));for(let e of ko(xe.current,ht))Te.current.delete(e);if(!No(ut,F)||!F){be.current&&De.current===ht&&U(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:Nn(t,ft),exact:!0}),await x.cancelQueries({queryKey:mt,exact:!0}),jn(x,t,ft,e),x.setQueryData(mt,()=>({kind:`resolved`,source:fo(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)}},[L,ht,xt,ut,lt,mt,dt.data?.kind,x,F,b.files,K,t,ft]),Q.useEffect(()=>()=>{ve.current!==null&&window.clearTimeout(ve.current)},[]);let St=Q.useCallback(()=>{v(`chat`),y(!1)},[v,y]),Ct=Q.useCallback(async e=>{if(!O||!A)return;let t=await Ce(A.action===`improve`?`plan.improve.visible`:`plan.implement.visible`,{plan_title:ue}),n=[{synthetic:!0,text:await Ce(A.action===`improve`?`plan.improve.instructions`:`plan.implement.instructions`,{plan_title:ue,plan_path:F??``})}];N(!0);try{St();let r=null,c=O.path;if(A.target===`worktree`){if(!k)return;let e=await _t(O.path,Dt());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,ge.getState().agents??[])}if(!r)return;let l=ye.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 "${ue}" end-to-end${F?` (plan file: ${F})`:``}.`,`Re-read that file for full details — it is the source of truth.`,``,L].join(`
159
- `):null;G.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,L,i,O,a,A,F,St,o,ue,s]),wt=Q.useMemo(()=>mr({drafts:ze,editingDraftId:Ke,commentText:Be,onTextChange:Ge,selection:Oe,isDragging:J,fileLabel:q,newWidgetId:`plan-new-comment-input`,mapDraftToRange:e=>({start:e.startLine,end:e.endLine}),onSave:nt,onCancel:tt,onEdit:e=>{$e(e),ke({start:e.startLine,end:e.endLine})},onDelete:et}),[Be,et,Ke,tt,nt,J,Oe,ze,q,Ge,$e]);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:le}),oe?(0,$.jsx)(X,{variant:`link`,size:`xs`,className:`h-auto p-0 typography-micro text-[color:var(--status-error)]`,title:oe,onClick:()=>{let e=xe.current.get(ht);e&&(xe.current.set(ht,To(e)),U(null),se(e=>e+1))},children:t(`planView.error.saveFailed`)}):null]}),F?(0,$.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,$.jsxs)(Qe,{children:[(0,$.jsxs)(Ue,{children:[(0,$.jsx)(Ve,{asChild:!0,children:(0,$.jsx)(at,{asChild:!0,children:(0,$.jsx)(X,{variant:`ghost`,size:`sm`,className:`h-5 w-5 p-0`,"aria-label":t(`planView.actions.improvePlanAria`),disabled:!L.trim(),children:(0,$.jsx)(Y,{name:`loop-right-ai`,className:`size-4`})})})}),(0,$.jsx)(He,{sideOffset:8,children:t(`planView.actions.improve`)})]}),(0,$.jsxs)(it,{align:`end`,children:[(0,$.jsx)(st,{onClick:()=>j({action:`improve`,target:`session`}),children:t(`planView.actions.sendToNewSession`)}),(0,$.jsx)(st,{onClick:()=>j({action:`improve`,target:`worktree`}),disabled:!k,children:t(`planView.actions.sendToNewWorktreeSession`)})]})]}),(0,$.jsxs)(Qe,{children:[(0,$.jsxs)(Ue,{children:[(0,$.jsx)(Ve,{asChild:!0,children:(0,$.jsx)(at,{asChild:!0,children:(0,$.jsx)(X,{variant:`ghost`,size:`sm`,className:`h-5 w-5 p-0`,"aria-label":t(`planView.actions.implementPlanAria`),disabled:!L.trim(),children:(0,$.jsx)(Y,{name:`code-ai`,className:`size-4`})})})}),(0,$.jsx)(He,{sideOffset:8,children:t(`planView.actions.implement`)})]}),(0,$.jsxs)(it,{align:`end`,children:[(0,$.jsx)(st,{onClick:()=>j({action:`implement`,target:`session`}),children:t(`planView.actions.sendToNewSession`)}),(0,$.jsx)(st,{onClick:()=>j({action:`implement`,target:`worktree`}),disabled:!k,children:t(`planView.actions.sendToNewWorktreeSession`)})]})]}),(0,$.jsx)(Tn,{currentMode:me,onToggle:()=>Ne(me===`preview`?`edit`:`preview`)}),me===`preview`&&ae&&(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(B?`planView.tts.stopSpeaking`:`planView.tts.readAloud`),onClick:()=>{B?H():L.trim()&&V(L)},children:B?(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(B?`planView.tts.stopSpeaking`:`planView.tts.readAloud`)})]}),(0,$.jsx)(X,{variant:`ghost`,size:`sm`,onClick:async()=>{(await re(L)).ok&&(pe(!0),ve.current!==null&&window.clearTimeout(ve.current),ve.current=window.setTimeout(()=>{pe(!1)},1200))},className:`h-5 w-5 p-0`,title:t(`planView.actions.copyPlanContents`),"aria-label":t(`planView.actions.copyPlanContents`),children:fe?(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)($a,{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`)}):vt?(0,$.jsx)(`div`,{className:`p-3 typography-ui text-destructive`,children:dt.error instanceof Error?dt.error.message:t(`planView.error.saveFailed`)}):yt&&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:me===`preview`?(0,$.jsx)(`div`,{className:`h-full overflow-auto p-3`,children:(0,$.jsx)(Ze,{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)(Gt,{content:L,className:`typography-markdown-body`,enableFileReferences:!1})})}):(0,$.jsx)(`div`,{className:`relative h-full`,ref:je,children:(0,$.jsx)(xn,{value:L,onChange:R,readOnly:!1,className:`h-full`,extensions:Z,onViewReady:e=>{Ae.current=e},onViewDestroy:()=>{Ae.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),Ye(),Pe.current=!1,Fe.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}),Pe.current=!1,Fe.current=null,Le(!1),!0}if(Pe.current=!0,Fe.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||!Pe.current||Fe.current===null)return!1;let r=e.state.doc.lineAt(t.from).number,i=Math.min(Fe.current,r),a=Math.max(Fe.current,r);return ke({start:i,end:a}),Le(!0),!1},mouseup:()=>(Pe.current=!1,Fe.current=null,Le(!1),!1)}}})})})})})})]})},Ho=e=>e,Uo=e=>{let t=Ho(e).type;return typeof t==`string`?t:``},Wo=e=>{let t=Ho(e).tool;return typeof t==`string`?t:``},Go=e=>{let t=Ho(e).text;return typeof t==`string`?t:``},Ko=e=>{let t=Uo(e);return t===`tool`?Wo(e).trim().toLowerCase()||`tool`:t||`unknown`},qo=e=>{if(e.length===0)return``;let t=[];for(let n of e){let e=Ko(n);t.includes(e)||t.push(e)}return t.join(` + `)},Jo=e=>e.replace(/\s+/g,` `).trim(),Yo=e=>{for(let t of e)if(Uo(t)===`text`){let e=Jo(Go(t));if(e.length===0)continue;return e}let t=e.filter(e=>Uo(e)!==`text`).length;return t===0?``:`${t} attachment${t===1?``:`s`}`},Xo=(e,t,n)=>`${n(e)} / ${n(t)}`,Zo=(e,t,n,r)=>{let i=Xo(e,t,n);return typeof r==`string`&&r.trim().length>0?`${i} · ${r.trim()}`:i},Qo=e=>{if(e===`12h`)return!0;if(e===`24h`)return!1},$o=(e,t)=>{if(!e||!Number.isFinite(e))return`-`;let n=Qo(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}})},es={input:0,output:0,reasoning:0,cacheRead:0,cacheWrite:0,total:0},ts={user:0,assistant:0,tool:0,other:0},ns=e=>typeof e!=`number`||!Number.isFinite(e)||e<0?0:e,rs=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{...es,total:ns(n)};if(!n||typeof n!=`object`)return es;let r=n,i=ns(r.input),a=ns(r.output),o=ns(r.reasoning),s=ns(r.cache?.read),c=ns(r.cache?.write);return{input:i,output:a,reasoning:o,cacheRead:s,cacheWrite:c,total:i+a+o+s+c}},is=(...e)=>{for(let t of e)if(typeof t==`string`&&t.trim().length>0)return t;return``},as=e=>typeof e==`string`?e.length:typeof e==`number`||typeof e==`boolean`?String(e).length:Array.isArray(e)?e.reduce((e,t)=>e+as(t),0):e&&typeof e==`object`?Object.values(e).reduce((e,t)=>e+as(t),0):0,os=(e,t)=>{let n=e,r=typeof n.type==`string`?n.type:``;if(r===`reasoning`)return{...ts,assistant:as(n.text)+as(n.content)};let i=is(n.text,n.content,n.value,n.source?.value,n.source?.text?.value);return r===`tool`||t===`tool`?{user:0,assistant:0,tool:as(n.input)+as(n.output)+as(n.error)+as(n.call?.input)+as(n.call?.output)+as(n.call?.error)+as(n.raw)+Math.round(as(n.metadata)*.25)+Math.round(as(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}},ss=(e,t)=>({user:e.user+t.user,assistant:e.assistant+t.assistant,tool:e.tool+t.tool,other:e.other+t.other}),cs=e=>{let t=wt(e.info);return t.isUser?`user`:t.role===`assistant`?`assistant`:t.role===`tool`?`tool`:`other`},ls=(e,t)=>{if(e.length===0)return{...ts};let n=e.reduce((e,t)=>{let n=cs(t),r={...ts};for(let e of t.parts)r=ss(r,os(e,n));return ss(e,r)},{...ts});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)}},us=e=>e.toLocaleString(L()),ds=e=>!Number.isFinite(e)||e<=0?new Intl.NumberFormat(L(),{style:`currency`,currency:`USD`,minimumFractionDigits:2,maximumFractionDigits:2}).format(0):new Intl.NumberFormat(L(),{style:`currency`,currency:`USD`,minimumFractionDigits:e<.01?4:2,maximumFractionDigits:e<.01?4:2}).format(e),fs=(e,t)=>!e||!Number.isFinite(e)?`-`:tt(e,t,{month:`short`,day:`numeric`,year:`numeric`,hour:`numeric`,minute:`2-digit`}),ps=(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}},ms=()=>{let e=(0,Ln.c)(259),{t}=te(),n=c(hs),r=c(gs),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=he(_s),f=de(),p=le(d??``),m=ge(vs),h;e[1]===Symbol.for(`react.memo_cache_sentinel`)?(h=()=>{u.current!==null&&(window.clearTimeout(u.current),u.current=null),o(ys),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 re(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(bs);let t;e[20]===p?t=e[21]:(t=p.filter(xs),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(rs(t).total>0){n=t;break}}O=n?rs(n):es,w=pt({input:O.input,cache:{read:O.cacheRead,write:O.cacheWrite}}),k=C.reduce(Ss,0);let r=0,i=0;for(let e of C){let t=rs(e),n=e.info.time?.created??null,a=e.info.time?.completed??null,o=It(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:Tt(a),e[22]=a,e[23]=o),E=o;let s=n?Ot({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:Tt(s);let c=n?.info??null;D=ps(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=ls(p,[...p].reverse().find(Cs)?.info?.system||``),e[24]=p,e[25]=N);let P=N,F=P.user,I=P.assistant,ne=P.tool,L=Math.max(0,O.input-F-I-ne),R=F+I+ne+L,ie=p[0]?.info?.time?.created,z=p.length>0?p[p.length-1]?.info?.time?.created:null,B;e[26]!==S?.title||e[27]!==t?(B=S?.title||t(`contextSidebar.session.untitled`),e[26]=S?.title,e[27]=t,e[28]=B):B=e[28];let V=S?.time?.created??ie??null,H=z??S?.time?.created??null,ae=E&&E.length>0?E:null,oe=T&&T.length>0?T:null,U;e[29]!==I||e[30]!==L||e[31]!==ne||e[32]!==F?(U={user:F,assistant:I,tool:ne,other:L},e[29]=I,e[30]=L,e[31]=ne,e[32]=F,e[33]=U):U=e[33];let W;e[34]!==C.length||e[35]!==R||e[36]!==w||e[37]!==M||e[38]!==j||e[39]!==p.length||e[40]!==V||e[41]!==H||e[42]!==ae||e[43]!==oe||e[44]!==U||e[45]!==B||e[46]!==O||e[47]!==k||e[48]!==ee||e[49]!==A.length?(W={sessionTitle:B,messagesCount:p.length,userMessagesCount:A.length,assistantMessagesCount:C.length,createdAt:V,lastActivityAt:H,providerModel:j,tokenBreakdown:O,usagePercent:ee,cacheHitRate:w,totalAssistantCost:k,sessionTpsLabel:ae,lastAssistantTpsLabel:oe,contextLimit:M,breakdown:U,breakdownTotal:R},e[34]=C.length,e[35]=R,e[36]=w,e[37]=M,e[38]=j,e[39]=p.length,e[40]=V,e[41]=H,e[42]=ae,e[43]=oe,e[44]=U,e[45]=B,e[46]=O,e[47]=k,e[48]=ee,e[49]=A.length,e[50]=W):W=e[50];let G=W;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 K;e[55]===t?K=e[56]:(K=t(`contextSidebar.breakdown.user`),e[55]=t,e[56]=K);let se;e[57]!==K||e[58]!==G.breakdown.user?(se={key:`user`,label:K,value:G.breakdown.user,color:`var(--status-success)`},e[57]=K,e[58]=G.breakdown.user,e[59]=se):se=e[59];let ce;e[60]===t?ce=e[61]:(ce=t(`contextSidebar.breakdown.assistant`),e[60]=t,e[61]=ce);let q;e[62]!==ce||e[63]!==G.breakdown.assistant?(q={key:`assistant`,label:ce,value:G.breakdown.assistant,color:`var(--primary-base)`},e[62]=ce,e[63]=G.breakdown.assistant,e[64]=q):q=e[64];let ue;e[65]===t?ue=e[66]:(ue=t(`contextSidebar.breakdown.toolCalls`),e[65]=t,e[66]=ue);let fe;e[67]!==ue||e[68]!==G.breakdown.tool?(fe={key:`tool`,label:ue,value:G.breakdown.tool,color:`var(--status-warning)`},e[67]=ue,e[68]=G.breakdown.tool,e[69]=fe):fe=e[69];let pe;e[70]===t?pe=e[71]:(pe=t(`contextSidebar.breakdown.other`),e[70]=t,e[71]=pe);let me;e[72]!==pe||e[73]!==G.breakdown.other?(me={key:`other`,label:pe,value:G.breakdown.other,color:`var(--surface-muted-foreground)`},e[72]=pe,e[73]=G.breakdown.other,e[74]=me):me=e[74];let _e;e[75]!==se||e[76]!==q||e[77]!==fe||e[78]!==me?(_e=[se,q,fe,me],e[75]=se,e[76]=q,e[77]=fe,e[78]=me,e[79]=_e):_e=e[79];let ve=_e,ye;e[80]===G.sessionTitle?ye=e[81]:(ye=(0,$.jsx)(`h2`,{className:`typography-ui-header font-semibold text-foreground truncate`,children:G.sessionTitle}),e[80]=G.sessionTitle,e[81]=ye);let be;e[82]!==G.providerModel.modelName||e[83]!==G.providerModel.providerName?(be=(0,$.jsxs)(`span`,{children:[G.providerModel.providerName,` / `,G.providerModel.modelName]}),e[82]=G.providerModel.modelName,e[83]=G.providerModel.providerName,e[84]=be):be=e[84];let xe;e[85]!==n||e[86]!==G.createdAt?(xe=G.createdAt&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`span`,{children:`·`}),(0,$.jsx)(`span`,{children:fs(G.createdAt,n)})]}),e[85]=n,e[86]=G.createdAt,e[87]=xe):xe=e[87];let Se;e[88]!==be||e[89]!==xe?(Se=(0,$.jsxs)(`div`,{className:`mt-1 flex flex-wrap items-center gap-x-2 gap-y-0.5 typography-micro text-muted-foreground/70`,children:[be,xe]}),e[88]=be,e[89]=xe,e[90]=Se):Se=e[90];let Ce;e[91]!==ye||e[92]!==Se?(Ce=(0,$.jsxs)(`div`,{className:`mb-6`,children:[ye,Se]}),e[91]=ye,e[92]=Se,e[93]=Ce):Ce=e[93];let we;e[94]===t?we=e[95]:(we=t(`contextSidebar.section.context`),e[94]=t,e[95]=we);let Te;e[96]===we?Te=e[97]:(Te=(0,$.jsx)(`span`,{className:`typography-micro text-muted-foreground`,children:we}),e[96]=we,e[97]=Te);let Ee;e[98]===G.tokenBreakdown.total?Ee=e[99]:(Ee=us(G.tokenBreakdown.total),e[98]=G.tokenBreakdown.total,e[99]=Ee);let De;e[100]===G.contextLimit?De=e[101]:(De=G.contextLimit?` / ${us(G.contextLimit)}`:``,e[100]=G.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]===G.usagePercent?Ae=e[109]:(Ae=G.usagePercent>0&&(0,$.jsx)(`div`,{className:`rounded-full transition-all duration-300`,style:{width:`${Math.max(.5,G.usagePercent)}%`,backgroundColor:G.usagePercent>80?`var(--status-warning)`:`var(--primary-base)`}}),e[108]=G.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]!==G.usagePercent?(Me=t(`contextSidebar.context.percentUsed`,{percent:G.usagePercent.toFixed(1)}),e[112]=t,e[113]=G.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]===G.messagesCount?X=e[124]:(X=us(G.messagesCount),e[123]=G.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]===G.userMessagesCount?Re=e[131]:(Re=us(G.userMessagesCount),e[130]=G.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]===G.assistantMessagesCount?Ve=e[138]:(Ve=us(G.assistantMessagesCount),e[137]=G.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(ws)}),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]===G.totalAssistantCost?Xe=e[155]:(Xe=ds(G.totalAssistantCost),e[154]=G.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]!==G.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:G.sessionTpsLabel??`—`})]}):null,e[161]=r,e[162]=t,e[163]=G.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]!==G.tokenBreakdown.input?(at={label:it,value:G.tokenBreakdown.input,format:`count`},e[178]=it,e[179]=G.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]!==G.tokenBreakdown.output?(st={label:ot,value:G.tokenBreakdown.output,format:`count`},e[183]=ot,e[184]=G.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]!==G.tokenBreakdown.reasoning?(Z={label:ct,value:G.tokenBreakdown.reasoning,format:`count`},e[188]=ct,e[189]=G.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]!==G.tokenBreakdown.cacheRead?(ut={label:lt,value:G.tokenBreakdown.cacheRead,format:`count`},e[193]=lt,e[194]=G.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]!==G.tokenBreakdown.cacheWrite?(ft={label:dt,value:G.tokenBreakdown.cacheWrite,format:`count`},e[198]=dt,e[199]=G.tokenBreakdown.cacheWrite,e[200]=ft):ft=e[200];let mt;e[201]===t?mt=e[202]:(mt=t(`contextSidebar.tokens.cacheHit`),e[201]=t,e[202]=mt);let ht=G.cacheHitRate.hasInput?G.cacheHitRate.percent:null,gt;e[203]!==mt||e[204]!==ht?(gt={label:mt,value:ht,format:`percent`},e[203]=mt,e[204]=ht,e[205]=gt):gt=e[205];let _t;e[206]!==r||e[207]!==t||e[208]!==G.lastAssistantTpsLabel?(_t=r?[{label:t(`contextSidebar.tokens.tps`),value:G.lastAssistantTpsLabel,format:`text`}]:[],e[206]=r,e[207]=t,e[208]=G.lastAssistantTpsLabel,e[209]=_t):_t=e[209];let vt;e[210]!==at||e[211]!==st||e[212]!==Z||e[213]!==ut||e[214]!==ft||e[215]!==gt||e[216]!==_t?(vt=(0,$.jsx)(`div`,{className:`grid grid-cols-3 gap-x-4 gap-y-2.5`,children:[at,st,Z,ut,ft,gt,..._t].map(Ts)}),e[210]=at,e[211]=st,e[212]=Z,e[213]=ut,e[214]=ft,e[215]=gt,e[216]=_t,e[217]=vt):vt=e[217];let yt;e[218]!==rt||e[219]!==vt?(yt=(0,$.jsxs)(`div`,{className:`mb-5 rounded-lg bg-[var(--surface-elevated)]/70 px-4 py-3.5`,children:[rt,vt]}),e[218]=rt,e[219]=vt,e[220]=yt):yt=e[220];let bt;e[221]!==ve||e[222]!==G.breakdownTotal?(bt=(0,$.jsx)(`div`,{className:`flex h-1 w-full overflow-hidden rounded-full bg-[var(--surface-subtle)]`,children:ve.map(e=>e.value<=0||G.breakdownTotal<=0?null:(0,$.jsx)(`div`,{style:{width:`${e.value/G.breakdownTotal*100}%`,backgroundColor:e.color}},e.key))}),e[221]=ve,e[222]=G.breakdownTotal,e[223]=bt):bt=e[223];let xt;e[224]!==ve||e[225]!==G.breakdownTotal?(xt=(0,$.jsx)(`div`,{className:`mt-2 flex flex-wrap items-center gap-x-4 gap-y-1`,children:ve.map(e=>{let t=G.breakdownTotal>0?e.value/G.breakdownTotal*100:0;return(0,$.jsxs)(`div`,{className:`inline-flex items-center gap-1.5`,children:[(0,$.jsx)(`span`,{className:`h-1.5 w-1.5 rounded-full`,style:{backgroundColor:e.color}}),(0,$.jsxs)(`span`,{className:`typography-micro text-muted-foreground/70`,children:[e.label,` `,(0,$.jsxs)(`span`,{className:`tabular-nums`,children:[t.toFixed(0),`%`]})]})]},e.key)})}),e[224]=ve,e[225]=G.breakdownTotal,e[226]=xt):xt=e[226];let St;e[227]!==bt||e[228]!==xt?(St=(0,$.jsxs)(`div`,{className:`mb-6`,children:[bt,xt]}),e[227]=bt,e[228]=xt,e[229]=St):St=e[229];let Ct;e[230]===t?Ct=e[231]:(Ct=t(`contextSidebar.section.rawMessages`),e[230]=t,e[231]=Ct);let Et;e[232]===Ct?Et=e[233]:(Et=(0,$.jsx)(`div`,{className:`typography-micro text-muted-foreground`,children:Ct}),e[232]=Ct,e[233]=Et);let Dt;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=wt(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=qo(e.parts),h=c?rs({info:e.info,parts:e.parts}):null,g=l?Yo(e.parts):``,_=$o(f,n),v=m||`—`,y=(()=>{if(!r||!c||!h)return null;let t=Ot({createdAt:f,completedAt:p,outputTokens:h.output,reasoningTokens:h.reasoning,parts:e.parts});if(t===null)return null;let n=Tt(t);return n.length>0?n:null})(),x=h?Zo(h.input,h.output,us,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)(rn,{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],Dt=[...p].reverse().map(i),e[234]=s,e[235]=a,e[236]=p,e[237]=r,e[238]=t,e[239]=n,e[240]=Dt}else Dt=e[240];let kt;e[247]===Dt?kt=e[248]:(kt=(0,$.jsx)(`div`,{className:`mt-2.5 space-y-1`,children:Dt}),e[247]=Dt,e[248]=kt);let At;e[249]!==Et||e[250]!==kt?(At=(0,$.jsxs)(`div`,{children:[Et,kt]}),e[249]=Et,e[250]=kt,e[251]=At):At=e[251];let jt;return e[252]!==Ce||e[253]!==Pe||e[254]!==tt||e[255]!==yt||e[256]!==St||e[257]!==At?(jt=(0,$.jsx)(`div`,{className:`h-full overflow-y-auto bg-background`,children:(0,$.jsxs)(`div`,{className:`mx-auto w-full max-w-[52rem] px-5 py-6`,children:[Ce,Pe,tt,yt,St,At]})}),e[252]=Ce,e[253]=Pe,e[254]=tt,e[255]=yt,e[256]=St,e[257]=At,e[258]=jt):jt=e[258],jt};function hs(e){return e.timeFormatPreference}function gs(e){return e.showAssistantTps}function _s(e){return e.currentSessionId}function vs(e){return e.providers}function ys(e){return Object.keys(e).length>0?{}:e}function bs(e){return wt(e.info).role===`assistant`}function xs(e){return wt(e.info).isUser}function Ss(e,t){return e+ns(t.info.cost)}function Cs(e){return wt(e.info).isUser&&typeof e.info.system==`string`}function ws(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 Ts(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)}%`:us(Number(e.value)):`—`})]},e.label)}var Es=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(`/`)?`/`:``)},Ds=()=>`react-surface`,Os=(e,t)=>JSON.stringify([Es(e),t]),ks=(e,t,n,r)=>JSON.stringify([e,t,Es(n),r]),As=(e,t,n)=>n?t:e===t?e:null,js=(e,t)=>e.sessionId===t.sessionId&&Es(e.directory)===Es(t.directory),Ms=(e,t)=>Es(e)===Es(t),Ns=e=>({anchor:e,current:e,stack:[]}),Ps=(e,t)=>e??Ns(t),Fs=(e,t)=>e?.current.sessionId??t,Is=(e,t)=>js(e.current,t)?e:{...e,current:t,stack:[...e.stack,e.current]},Ls=e=>{let t=e.stack[e.stack.length-1];return t?{...e,current:t,stack:e.stack.slice(0,-1)}:e},Rs=(e,t,n)=>!Ms(e.anchor.directory,t.directory)||!Ms(e.current.directory,t.directory)||n(t.sessionId,t.directory)===!1?{status:`rejected-cross-directory`,state:e}:{status:`navigated`,state:Is(e,t)},zs=(e,t,n)=>{let r=e[t];if(!r)return{accepted:!1,navigationBySurfaceId:e};let i=Rs(r,n,()=>!0);return i.status===`navigated`?{accepted:!0,navigationBySurfaceId:i.state===r?e:{...e,[t]:i.state}}:{accepted:!1,navigationBySurfaceId:e}},Bs=(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},Vs=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`,Hs=e=>e===`retry`,Us=e=>e.active&&e.visible&&e.messageCount<=0,Ws=e=>e?`load-more`:`ensure`,Gs=e=>e.kind===`has-more`,Ks=(e,t)=>`${e}\n${t}`,qs=(e,t,n,r)=>r&&!e.has(Ks(t,n)),Js=(e,t)=>({scrollHeight:e,scrollTop:t}),Ys=(e,t)=>Math.max(0,e.scrollTop+Math.max(0,t-e.scrollHeight)),Xs=(e,t)=>e&&!t,Zs=e=>e,Qs=e=>!e,$s=e=>!Xs(e.hasMore,e.isLoading)||!Qs(e.historyVirtualized)?null:Js(e.scrollHeight,e.scrollTop),ec=(e,t,n)=>!!(e&&e.token===t&&e.viewportKey===n),tc=33554432,nc=e=>Math.min(tc,262144+Math.max(0,Math.ceil(e))*64*1024),rc=e=>Math.min(tc,Math.max(0,Math.round(Number.isFinite(e)?e:0))),ic=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}},ac=(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 ic({...e,activeViewKey:t.viewKey,mountedViews:r})}if(t.type===`estimate`){let n=e.mountedViews[t.viewKey],r=rc(t.estimatedBytes);return!n||n.estimatedBytes===r?e:ic({...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:ic({...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??nc(0),lastAccessed:t.now}}})},oc=e=>{let t=(0,Ln.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},sc=e=>{let t=(0,Ln.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=St(),m,h,g;t[0]!==i||t[1]!==r||t[2]!==n?(h=o(),m=Es(i),g=ks(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=be(r,d),E=le(r,d),D=ge(lc),O;t[7]===E?O=t[8]:(O=At(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)&&we(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=ue(r,d),N=_e(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=ae(P,d),[ne,L]=Q.useState(null),re,R;t[19]!==F||t[20]!==_?(re=()=>{L(e=>As(e,_,F))},R=[F,_],t[19]=F,t[20]=_,t[21]=re,t[22]=R):(re=t[21],R=t[22]),Q.useLayoutEffect(re,R);let ie=F||ne===_,z=pe(r,d),H;t[23]===r?H=t[24]:(H=e=>e.streamingMessageIds.get(r)??null,t[23]=r,t[24]=H);let oe=V(H),U;t[25]===oe?U=t[26]:(U=e=>oe?e.messageStreamStates.get(oe)?.phase??null:null,t[25]=oe,t[26]=U);let W=V(U),G=M?.type===`busy`||M?.type===`retry`,K;t[27]!==r||t[28]!==G||t[29]!==T||t[30]!==_?(K={currentSessionId:r,viewportKey:_,sessionMessageCount:T,sessionIsWorking:G,isMobile:!1},t[27]=r,t[28]=G,t[29]=T,t[30]=_,t[31]=K):K=t[31];let{scrollRef:ce,notifyContentChange:q,getAnimationHandlers:de,goToBottom:me,restoreSnapshot:he,showScrollButton:ve}=Ct(K),ye;t[32]!==r||t[33]!==p?(ye=e=>{p.ensureSessionRenderable(r,Hs(e))},t[32]=r,t[33]=p,t[34]=ye):ye=t[34];let xe=I(ye),Se,Ce;t[35]!==a||t[36]!==xe?(Se=()=>{a&&xe(`active`)},Ce=[a,xe],t[35]=a,t[36]=xe,t[37]=Se,t[38]=Ce):(Se=t[37],Ce=t[38]),Q.useEffect(Se,Ce);let Ee,De;t[39]!==a||t[40]!==xe||t[41]!==T?(Ee=()=>{if(typeof window>`u`)return;let e=()=>{let e=document.visibilityState!==`hidden`&&document.hasFocus();Us({active:a,visible:e,messageCount:T})&&xe(`retry`)};return window.addEventListener(`focus`,e),document.addEventListener(`visibilitychange`,e),()=>{window.removeEventListener(`focus`,e),document.removeEventListener(`visibilitychange`,e)}},De=[a,xe,T],t[39]=a,t[40]=xe,t[41]=T,t[42]=Ee,t[43]=De):(Ee=t[42],De=t[43]),Q.useEffect(Ee,De);let Oe,ke;t[44]!==u||t[45]!==T||t[46]!==_?(Oe=()=>{u?.(_,nc(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 Ae,je;t[49]!==N||t[50]!==he||t[51]!==r||t[52]!==_?(Ae=()=>{if(!qs(w.current,r,_,N))return;let e=Ks(r,_);w.current.add(e),he()},je=[N,he,r,_],t[49]=N,t[50]=he,t[51]=r,t[52]=_,t[53]=Ae,t[54]=je):(Ae=t[53],je=t[54]),Q.useEffect(Ae,je);let Me;t[55]===Symbol.for(`react.memo_cache_sentinel`)?(Me=()=>{y.current=null,S(null)},t[55]=Me):Me=t[55];let Ne;t[56]===_?Ne=t[57]:(Ne=[_],t[56]=_,t[57]=Ne),Q.useLayoutEffect(Me,Ne);let Pe;t[58]!==x||t[59]!==ce||t[60]!==_?(Pe=()=>{let e=y.current,t=ce.current;if(ec(e,x,_)){if(!t||!Qs(!!v.current?.isHistoryVirtualized())){y.current=null;return}t.scrollTop=Ys(e.anchor,t.scrollHeight),y.current=null}},t[58]=x,t[59]=ce,t[60]=_,t[61]=Pe):Pe=t[61];let Fe;t[62]!==x||t[63]!==ce||t[64]!==E||t[65]!==_?(Fe=[x,ce,E,_],t[62]=x,t[63]=ce,t[64]=E,t[65]=_,t[66]=Fe):Fe=t[66],Q.useLayoutEffect(Pe,Fe);let J;t[67]===m?J=t[68]:(J={directory:m},t[67]=m,t[68]=J);let Ie=J,Le=fe(r,d).boundary,ze;t[69]===Le?ze=t[70]:(ze=Gs(Le),t[69]=Le,t[70]=ze);let Be=ze,Ve;t[71]!==z?.status||t[72]!==Ie||t[73]!==r||t[74]!==p?(Ve=z?.status===`loading`||p.isLoading(r,Ie),t[71]=z?.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 Te(d,r),await se(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]!==ce||t[92]!==f||t[93]!==_?(Je=()=>{if(!Xs(Be,qe||He)||Ke.isPending)return;let e=b.current+1;b.current=e;let t=ce.current,n=t?$s({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),B.error(f(`chat.history.loadOlderFailed`))})},t[87]=He,t[88]=Be,t[89]=qe,t[90]=Ke,t[91]=ce,t[92]=f,t[93]=_,t[94]=Je):Je=t[94];let Ye=I(Je),Xe=z?.status===`error`?z.error:void 0,Ze;t[95]!==a||t[96]!==N||t[97]!==G||t[98]!==E.length||t[99]!==Xe?(Ze=Vs({directoryMatches:!0,requested:a,renderable:N,messageCount:E.length,working:G,error:Xe}),t[95]=a,t[96]=N,t[97]=G,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:yt,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]!==xe||t[108]!==Be||t[109]!==Ye?(tt=()=>{if(Ws(Be)===`load-more`){Ye();return}xe(`retry`)},t[107]=xe,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]!==W||t[116]!==xe||t[117]!==de||t[118]!==me||t[119]!==Be||t[120]!==qe||t[121]!==Ye||t[122]!==q||t[123]!==z?.error||t[124]!==nt||t[125]!==ce||t[126]!==r||t[127]!==G||t[128]!==E||t[129]!==ve||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)(oc,{state:Qe,error:z?.error,onRetry:()=>xe(`retry`)}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Re,{ref:ce,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:z?.error}),(0,$.jsx)(X,{type:`button`,variant:`secondary`,size:`xs`,onClick:nt,children:f(`chat.history.retry`)})]}):null,Zs(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)(jt,{ref:v,sessionKey:r,virtualizerKey:_,messages:E,sessionIsWorking:G,activeStreamingMessageId:oe,activeStreamingPhase:W,onMessageContentChange:q,getAnimationHandlers:de,isLoadingOlder:qe,scrollToBottom:()=>me(`instant`),scrollRef:ce,directory:d,enableSendPark:!1}),(0,$.jsx)(`div`,{className:`h-12`,"aria-hidden":`true`})]})}),(0,$.jsx)(gt,{visible:ve,onClick:()=>me(`smooth`)})]})}),t[115]=W,t[116]=xe,t[117]=de,t[118]=me,t[119]=Be,t[120]=qe,t[121]=Ye,t[122]=q,t[123]=z?.error,t[124]=nt,t[125]=ce,t[126]=r,t[127]=G,t[128]=E,t[129]=ve,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]!==ie?(at=ie?(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]=ie,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)(Lt.Provider,{value:et,children:ot}),t[148]=et,t[149]=ot,t[150]=st):st=t[150],st},cc=e=>{let t=(0,Ln.c)(22),n=q(),{t:r}=te(),i;t[0]===e.directory?i=t[1]:(i=Es(e.directory),t[0]=e.directory,t[1]=i);let a=i,o=a===Es(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:yt,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)(oc,{state:`directory-mismatch`,onRetry:uc,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)(Lt.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)(sc,{...e,syncDirectory:n}),t[19]=e,t[20]=n,t[21]=l):l=t[21],l};function lc(e){return e.providers}function uc(){}var dc=e=>{if(!e||typeof e!=`object`)return!1;let t=e;return typeof t.x==`number`&&typeof t.y==`number`},fc=e=>!e||typeof e!=`object`?!1:Object.values(e).every(e=>typeof e==`string`),pc=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`&&dc(t.center)&&fc(t.attributes)&&fc(t.computedStyle)&&Array.isArray(t.ancestry)},mc=({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
- `)},hc=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 Kc(e,t)},gc=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}},_c=`data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAwMCAO+/p9sAAAAASUVORK5CYII=`,vc=new Map,yc=new Map,bc=3e4,xc=e=>{let t=vc.get(e);return t?t.expiresAt-Date.now()<=bc?(vc.delete(e),null):t:null},Sc=e=>{try{return new URL(e).origin}catch{return e}};function Cc(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 wc=e=>new Promise((t,n)=>{let r=new FileReader;r.onloadend=()=>t(typeof r.result==`string`?r.result:_c),r.onerror=()=>n(r.error??Error(`Failed to read image blob`)),r.readAsDataURL(e)}),Tc=async(e,t=.82)=>{let n=await new Promise(n=>e.toBlob(n,`image/jpeg`,t));return n&&(await wc(n)).split(`,`,2)[1]||``},Ec=()=>{try{return!!window.__previewCaptureDebug}catch{return!1}},Dc=(...e)=>{Ec()&&[...e]},Oc=(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},kc=`data-oc-fixed-pin`,Ac=(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(kc,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 Dc(`tagged fixed elements`,a),()=>{for(let e of i)try{e.removeAttribute(kc)}catch{}}},jc={name:`oc-fixed-pin`,afterClone(e){let t=e?.clone;if(!(!t||typeof t.querySelectorAll!=`function`))for(let e of t.querySelectorAll(`[${kc}]`)){let t;try{t=JSON.parse(e.getAttribute(kc)||``)}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(kc)}}},Mc=`data-oc-scroll-pin`,Nc=e=>{let t=[],n=Oc(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(Mc,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(Mc)}catch{}},snapshot:n}},Pc={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(`[${Mc}]`)){let t;try{t=JSON.parse(e.getAttribute(Mc)||``)}catch{e.removeAttribute(Mc);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(Mc)}}},Fc=async(e,t)=>{try{let n=await fetch(e,{credentials:t});return n.ok?await wc(await n.blob()):null}catch{return null}},Ic=async e=>{if(e.protocol!==`http:`&&e.protocol!==`https:`)return``;let t=e.origin,n=xc(t);if(n)return`${n.proxyBasePath}${e.pathname}${e.search}${e.hash}`;let r=yc.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 vc.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 vc.delete(t),null;let o={proxyBasePath:i,expiresAt:a};return vc.set(t,o),o}catch{return vc.delete(t),null}finally{yc.delete(t)}})();r||yc.set(t,i);let a=await i;return a?`${a.proxyBasePath}${e.pathname}${e.search}${e.hash}`:``},Lc=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 Fc(n.toString(),`include`)??_c;let r=await Ic(n);return(r?await Fc(r,`include`):null)||(await Fc(n.toString(),`omit`)??_c)}catch{return _c}},Rc=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 Lc(n,t);r=r.replace(e[0],`url("${i}")`)}return r},zc=e=>e.complete?Promise.resolve():new Promise(t=>{e.addEventListener(`load`,()=>t(),{once:!0}),e.addEventListener(`error`,()=>t(),{once:!0})}),Bc=e=>{let t=e.style.cssText;return()=>{e.style.cssText=t}},Vc=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},Hc=(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<=Vc(s)*1.7;!u&&(!d||o.width>t*.72)||(r.push(Bc(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]?.()}},Uc=(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(Bc(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]?.()}},Wc=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(Uc(e,t,n,r)),i.push(Hc(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 zc(t);let r=await Lc(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||_c),await zc(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 Rc(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 Gc(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);Dc(`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:Oc(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=Nc(r);Dc(`nested scroll snapshot`,k.snapshot);let A=()=>{},j=()=>{};try{await r.fonts?.ready.catch(()=>void 0),A=await Wc(r,o,s,{applyLayoutWorkarounds:!1}),n.scrollTo(S,C),j=Ac(r,S,C),k.reapply();let e={backgroundColor:Cc(r),cache:`disabled`,dpr:E,embedFonts:!0,fast:!1,height:T,outerShadows:!0,outerTransforms:!0,placeholders:!0,plugins:[jc,Pc],quality:.82,width:w},a=await(await Pn(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)));Dc(`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 Tc(g,.82);return v?await gc(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 Kc(e,t){let n=await Gc(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 Wc(r,o,s,{applyLayoutWorkarounds:!0}),n.scrollTo(c,l);let e=await In(i).catch(()=>``);h=await Fn(i,{quality:.82,pixelRatio:f,width:o,height:s,backgroundColor:Cc(r),imagePlaceholder:_c,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 gc(_,o,s,o,s,t):null}catch(e){return console.warn(`[preview] failed to capture iframe DOM screenshot:`,e),null}}var qc=380,Jc=1400,Yc=600,Xc=24,Zc=new Map,Qc=200,$c=(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`,el=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},tl=e=>Number.isFinite(e)?Math.min(Jc,Math.max(qc,Math.round(e))):Yc,nl=e=>{let t=e?.parentElement?.clientWidth;return!t||t<=0?null:t},rl=(e,t)=>{let n=tl(e),r=nl(t);return r===null?n:Math.min(n,Math.max(1,r))},il=(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},al=(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`),ol=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},sl=(e,t,n)=>{if(e.mode===`chat`){let r=ll(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 ol(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`?ol(e.targetPath)||n(`contextPanel.mode.diff`):al(e.mode,n)},cl=e=>{if(e.mode===`file`)return e.targetPath?(0,$.jsx)(Nt,{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`})},ll=e=>!e||!e.startsWith(`session:`)?null:e.slice(8).trim()||null,ul=(e,t)=>{if(e.size!==t.size)return!1;for(let[n,r]of e)if(t.get(n)!==r)return!1;return!0},dl=(e,t)=>{if(t.length===0)return Zc;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?Zc:r},fl=(e,t)=>{let n=H(e),r=Q.useRef(Zc),i=Q.useRef(t);return i.current=t,Q.useSyncExternalStore(n.subscribe,Q.useCallback(()=>{let e=dl(n.getState().session,i.current);return ul(r.current,e)?r.current:(r.current=e,e)},[n]),()=>Zc)},pl=`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
- });`,ml=`(() => {
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
- })()`,hl=`(() => {
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
- })()`,gl=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`}},_l=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)},vl=(e,t)=>e.length<=t?e:`${e.slice(0,t-3)}...`,yl=e=>{if(typeof window>`u`)return``;try{return new URL(e||window.location.href,window.location.href).origin}catch{return window.location.origin}},bl=(e,t,n)=>{let r=yl(t);e.postMessage(n,r)},xl=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}},Sl=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}},Cl=({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=he(e=>e.currentSessionId),j=he(e=>e.newSessionDraft?.open),M=bt(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():``,ne=I?`${t()||`same-origin`}|${I}`:``,L=i.metadata.variant;Q.useEffect(()=>{if(!I||!P){f({status:`idle`});return}let e=xc(ne);if(e?.previewToken){f({status:`ready`,proxyBasePath:e.proxyBasePath,previewToken:e.previewToken,expiresAt:e.expiresAt});return}e&&vc.delete(ne);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){vc.delete(ne);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){vc.delete(ne),t||f({status:`error`,message:r(`contextPanel.preview.proxyError`)});return}vc.set(ne,{proxyBasePath:i,previewToken:a,expiresAt:o}),t||f({status:`ready`,proxyBasePath:i,previewToken:a,expiresAt:o})}catch(e){if(vc.delete(ne),!t){let t=e instanceof Error?e.message:String(e);f({status:`error`,message:t})}}})(),()=>{t=!0}},[P,ne,l,r,I]);let R=F&&(F.protocol===`http:`||F.protocol===`https:`)?F.toString():``,ie=P&&d.status===`ready`?`${d.proxyBasePath}|${d.previewToken||``}|${o}`:``;Q.useEffect(()=>{if(!ie){m(``);return}let e=!1;return m(``),s(t()).then(t=>{!e&&t&&m(ie)}).catch(()=>{}),()=>{e=!0}},[ie]);let z=P&&d.status===`ready`&&F&&p===ie?(()=>{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?z:R,H=P?xl(z):R,ae=P&&(d.status===`loading`||d.status===`idle`||p!==ie),U=P&&d.status===`error`,W=Q.useCallback(t=>{let n=A??(j?`draft`:null);if(!n){B.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 hc(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:mc({pageUrl:i,viewport:a,devicePixelRatio:o,target:t,screenshotAttached:e,intro:r(`contextPanel.preview.inspect.attachAnnotation`)}),language:`markdown`,text:``}),B.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||bl(e,z,{source:`openchamber-preview-parent`,version:1,type:`set-inspect-mode`,enabled:E})},[v,E,z]),Q.useEffect(()=>{let e=h.current?.contentWindow;!v||!e||bl(e,z,{source:`openchamber-preview-parent`,version:1,type:`set-color-scheme`,scheme:L})},[v,L,z]),Q.useEffect(()=>{if(!E||typeof window>`u`)return;let e=e=>{e.key===`Escape`&&(e.preventDefault(),e.stopImmediatePropagation(),D(!1))};return window.addEventListener(`keydown`,e,!0),()=>window.removeEventListener(`keydown`,e,!0)},[E]),Q.useEffect(()=>{if(!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>Qc?r.slice(r.length-Qc):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(pc(a.target)?a.target:null);return}if(a.type===`select`&&pc(a.target)){k(a.target),D(!1),W(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`){Yt(e);return}e&&n(e)}}};return window.addEventListener(`message`,i),()=>{window.removeEventListener(`message`,i)}},[W,P,n,r]);let G=w.filter(e=>e.level===`error`||e.level===`runtime`||e.level===`resource`).length,K=w.filter(e=>$c(e,S)),se=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
- `);re(`${t}${n}`).then(e=>{e.ok?B.success(r(`contextPanel.preview.console.copied`)):B.error(r(`contextPanel.preview.console.copyFailed`))})},[w,V,e,r]),ce=Q.useCallback(()=>{let t=A??(j?`draft`:null);if(!t){B.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`)}),B.success(r(`contextPanel.preview.console.attached`))},[M,w,A,V,j,e,r]),[q,le]=Q.useState(`unknown`),ue=Q.useRef(0),de=Q.useRef(0);Q.useEffect(()=>{if(!z){le(`unknown`),ue.current=0,de.current=0;return}let e=!1;return ue.current||(ue.current=Date.now(),de.current=0),le(`unknown`),(async()=>{let t=await(async()=>{try{return await _(z,{method:`GET`,credentials:`include`,cache:`no-store`,redirect:`manual`})}catch{return null}})();if(e)return;if(!t){le(`unreachable`);return}if(t.status===403||t.status===404){vc.delete(ne),f({status:`loading`}),u();return}if(t.status!==502){le(`reachable`);return}let n=ue.current||Date.now();if(Date.now()-n<15e3){le(`starting`),de.current+=1;let t=de.current,n=Math.min(2e3,250*2**Math.min(4,t));setTimeout(()=>{e||c()},n).unref?.();return}le(`unreachable`)})(),()=>{e=!0}},[ne,z,o]);let fe=P&&d.status===`ready`&&(q===`unknown`||q===`starting`),pe=P&&d.status===`ready`&&q===`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=yl(z);if(e.origin!==n||e.pathname.startsWith(d.proxyBasePath))return;let r=`${d.proxyBasePath}${e.pathname}${e.search}${e.hash}`;t.location.replace(r)}catch{}},[P,z,d]);return(0,$.jsxs)(`div`,{className:`absolute inset-0 flex flex-col`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-1 border-b border-border/40 bg-[var(--surface-background)] px-2 py-1`,children:[(0,$.jsx)(`div`,{className:`min-w-0 flex-1 truncate typography-micro text-muted-foreground`,title: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:()=>{R&&Yt(R)},title:r(`contextPanel.preview.actions.openExternal`),"aria-label":r(`contextPanel.preview.actions.openExternal`),disabled:!R,children:(0,$.jsx)(Y,{name:`external-link`,className:`h-3.5 w-3.5`})}),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`}),G>0?(0,$.jsx)(`span`,{className:`typography-micro text-status-error`,children:G}):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||q===`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:L},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]}):ae?(0,$.jsx)(`div`,{className:`flex h-full items-center justify-center px-6 text-sm text-muted-foreground`,children:r(`contextPanel.preview.loading`)}):U?(0,$.jsxs)(`div`,{className:`flex h-full flex-col items-center justify-center gap-2 px-6 text-sm text-muted-foreground`,children:[(0,$.jsx)(`div`,{children:r(`contextPanel.preview.proxyError`)}),d.status===`error`?(0,$.jsx)(`div`,{className:`text-center text-xs opacity-70`,children:d.message}):null]}):(0,$.jsx)(`div`,{className:`flex h-full items-center justify-center px-6 text-sm text-muted-foreground`,children:r(`contextPanel.preview.invalidUrl`)}),b?(0,$.jsxs)(`div`,{className:`absolute inset-x-3 bottom-3 z-10 max-h-[45%] overflow-hidden rounded-xl border border-border/70 bg-[var(--surface-elevated)] shadow-lg`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between border-b border-border/50 px-3 py-2`,children:[(0,$.jsx)(`div`,{className:`typography-ui-label text-foreground`,children:r(`contextPanel.preview.console.title`)}),(0,$.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,$.jsx)(X,{type:`button`,size:`xs`,variant:`ghost`,onClick:ce,disabled:w.length===0,children:r(`contextPanel.preview.console.attach`)}),(0,$.jsx)(X,{type:`button`,size:`xs`,variant:`ghost`,onClick:se,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`)}):K.length===0?(0,$.jsx)(`div`,{className:`px-2 py-3 text-muted-foreground`,children:r(`contextPanel.preview.console.noFilteredEvents`)}):K.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]})]})},wl=()=>typeof window<`u`&&!!window.__OPENCHAMBER_ELECTRON__,Tl=({initialUrl:e,directory:n,tabID:r})=>{let{t:i}=te(),o=Q.useRef(null),l=c(e=>e.setContextPanelTabTargetPath),u=gl(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=he(e=>e.currentSessionId),F=he(e=>e.newSessionDraft?.open),I=bt(e=>e.addDraft),ne=oe(e=>e.addAttachedFile),L=Q.useCallback(e=>{!e||e===`about:blank`||!n||!r||l(n,r,e)},[n,r,l]),re=Q.useCallback((e,t)=>{let n=gl(e),r=n===`about:blank`?``:n;h(r),p(r),t?.inFrame?E(!1):(v(r),E(!!r)),L(r),b(e=>{if(!r)return S(-1),[];if(t?.replaceHistory)return e;let n=x>=0?e.slice(0,x+1):[];if(n[n.length-1]===r)return S(n.length-1),n;let i=[...n,r];return S(i.length-1),i})},[x,L]),R=Q.useCallback(e=>{let t=y[e];t&&(S(e),h(t),v(t),p(t),E(!0),L(t))},[y,L]),ie=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=Sc(g),t=xc(e);if(t?.previewToken){M({status:`ready`,proxyBasePath:t.proxyBasePath,previewToken:t.previewToken,expiresAt:t.expiresAt});return}t&&vc.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}vc.set(e,{proxyBasePath:a,previewToken:o,expiresAt:s}),n||M({status:`ready`,proxyBasePath:a,previewToken:o,expiresAt:s})}catch(e){if(!n){let t=e instanceof Error?e.message:String(e);M({status:`error`,message:t})}}})(),()=>{n=!0}},[g,i]);let z=g&&j.status===`ready`?`${j.proxyBasePath}|${j.previewToken||``}|${C}`:``;Q.useEffect(()=>{if(!z){N(``);return}let e=!1;return N(``),s(t()).then(t=>{!e&&t&&N(z)}).catch(()=>{}),()=>{e=!0}},[z]);let V=Q.useMemo(()=>{if(ee!==z||!g||j.status!==`ready`)return``;try{let e=new URL(g),t=e.pathname||`/`,n=new URLSearchParams(e.search);n.delete(`oc_url_token`),n.delete(`oc_client_token`),n.set(`ocPreview`,String(C)),n.set(`oc_preview_token`,j.previewToken||``);let r=n.toString();return a().authenticatedAsset(`${j.proxyBasePath}${t}${r?`?${r}`:``}${e.hash}`)}catch{return``}},[g,j,z,C,ee]),H=V||(j.status===`error`?g:``),ae=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 Sl(new URL(`${r}${t.search}${t.hash}`,i).toString())}catch{return``}},[g,j]),U=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)?``:Sl(new URL(`${t.pathname}${t.search}${t.hash}`,n).toString())}catch{return``}},[g,j]),W=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)},[]),G=Q.useCallback(async e=>{let t=P??(F?`draft`:null);if(!t){B.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 hc(n,e):null,l=!!c;c&&await ne(c),I({sessionKey:t,source:`preview-annotation`,fileLabel:m||`browser`,startLine:1,endLine:1,code:mc({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:``}),B.success(i(`contextPanel.preview.inspect.attached`))},[ne,I,P,m,F,i]),K=Q.useCallback(()=>{let e=o.current;A(null),W(!1),e&&_l(e,ml).catch(()=>{})},[W]);Q.useEffect(()=>{if(!D)return;let e=e=>{e.key===`Escape`&&(e.preventDefault(),e.stopImmediatePropagation(),O(!1),K())};return window.addEventListener(`keydown`,e,!0),()=>window.removeEventListener(`keydown`,e,!0)},[K,D]),Q.useEffect(()=>()=>K(),[K]),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=ae(e);n&&n!==m&&re(n,{inFrame:!0});return}if(t.type===`hover`){A(pc(t.target)?t.target:null);return}if(t.type===`select`&&pc(t.target)){A(null),O(!1),W(!1),G(t.target);return}if(t.type===`navigate-preview`){let e=typeof t.url==`string`?t.url:``,n=U(e);if(n){re(n);return}e&&re(e)}}};return window.addEventListener(`message`,e),()=>window.removeEventListener(`message`,e)},[re,G,m,ae,U,W]);let se=Q.useCallback(()=>{let e=o.current;if(!(!e||!m)){if(D){O(!1),K();return}if(V){A(null),O(!0),W(!0);return}O(!0),(async()=>{try{let t=await _l(e,pl);if(O(!1),!t||!pc(t))return;await G(t)}catch{O(!1),B.error(i(`contextPanel.browser.inspectUnavailable`))}})()}},[G,K,m,D,W,V,i]),ce=Q.useCallback(()=>{try{let e=o.current?.contentWindow?.location.href||``,t=U(e);if(t){re(t,{inFrame:!0});return}}catch{}E(!1),D&&V&&W(!0)},[re,U,D,W,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:()=>R(x-1),children:(0,$.jsx)(Y,{name:`arrow-left`,className:`h-3.5 w-3.5`})}),(0,$.jsx)(X,{type:`button`,variant:`ghost`,size:`sm`,className:`h-7 w-7 p-0`,disabled:x<0||x>=y.length-1,onClick:()=>R(x+1),children:(0,$.jsx)(Y,{name:`arrow-right`,className:`h-3.5 w-3.5`})}),(0,$.jsx)(X,{type:`button`,variant:`ghost`,size:`sm`,className:`h-7 w-7 p-0`,disabled:!m,onClick:ie,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(),re(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:se,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 Yt(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:ce},`${r}:${C}`),D&&k?(0,$.jsx)(`div`,{className:`pointer-events-none absolute rounded-sm border-2 border-[var(--interactive-focus-ring)] bg-[var(--interactive-focus-ring)]/35`,style:{left:k.bounds.x,top:k.bounds.y,width:k.bounds.width,height:k.bounds.height},children:(0,$.jsxs)(`div`,{className:`absolute -top-6 left-0 max-w-64 truncate rounded bg-[var(--surface-elevated)] px-2 py-0.5 typography-micro text-foreground shadow`,children:[k.tag,k.text?` · ${k.text}`:``]})}):null]}):(0,$.jsxs)(`div`,{className:`absolute inset-0 flex flex-col items-center justify-center gap-6 bg-background p-6 text-center`,children:[(0,$.jsx)(Je,{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]})]})},El=({initialUrl:e,directory:t,tabID:n})=>{let{t:r}=te(),i=Q.useRef(null),a=c(e=>e.setContextPanelTabTargetPath),o=gl(e),s=o===`about:blank`?``:o,l=Q.useRef(gl(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=he(e=>e.currentSessionId),S=he(e=>e.newSessionDraft?.open),C=bt(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?.(hl,!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?.(ml).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?.(ml).catch(()=>{})}catch{}}},[t,n,a]);let T=Q.useCallback(e=>{let t=i.current;if(typeof t?.loadURL!=`function`)return;let n=gl(e);try{t.loadURL(n)}catch{}},[]),E=Q.useCallback(()=>{let e=i.current;if(e){if(m){h(!1);try{e.executeJavaScript?.(ml).catch(()=>{})}catch{}return}h(!0),e.executeJavaScript?.(pl,!0).then(async t=>{if(h(!1),!t||!pc(t))return;let n=x??(S?`draft`:null);if(!n){B.error(r(`contextPanel.preview.inspect.attachNoSession`));return}let i=typeof e.getWebContentsId==`function`?e.getWebContentsId():null;if(i==null)return;let a=await ne(`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 gc(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:mc({pageUrl:f,viewport:{width:s,height:c},devicePixelRatio:window.devicePixelRatio||1,target:t,screenshotAttached:u,intro:r(`contextPanel.preview.inspect.attachAnnotationWithScreenshot`)}),language:`markdown`,text:``}),B.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 Yt(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)(Je,{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]})]})},Dl=({directory:e})=>{let{t}=te(),n=tn()??``,r=e?.trim()||n,i=Q.useMemo(()=>el(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=Bt(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=tl(a?.width??Yc),k=Q.useMemo(()=>{let e=[];for(let t of w){if(t.mode!==`chat`)continue;let n=ll(t.dedupeKey);n&&!e.includes(n)&&e.push(n)}return e},[w]),A=fl(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),ne=Q.useRef(null),L=Q.useRef(null),re=Q.useRef(new Map),R=Q.useRef(new Map),ie=Q.useRef(!1),B=Q.useRef(E),V=Q.useRef(null),[H,ae]=Q.useState({}),oe=Q.useRef(H);oe.current=H;let[U,W]=Q.useReducer(ac,{activeViewKey:null,tabs:{},mountedViews:{}}),G=Ds(),K=o(),se=Q.useCallback(e=>{let t=oe.current,n=e(t);return n!==t&&(oe.current=n,ae(n),!0)},[]),ce=Q.useCallback(e=>{if(!i)return;W({type:`close-tab`,tabId:e});let t=Os(i,e);se(e=>{if(!e[t])return e;let n={...e};return delete n[t],n}),u(i,e)},[u,se,i]),q=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||q()},[E,q]),Q.useEffect(()=>{if(!E||ie.current){ie.current=E;return}let e=window.requestAnimationFrame(()=>{L.current?.focus({preventScroll:!0})});return ie.current=!0,()=>window.cancelAnimationFrame(e)},[E]);let le=Q.useCallback(e=>{let t=L.current;t&&t.style.setProperty(`--oc-context-panel-width`,`${rl(e,t)}px`)},[]),ue=Q.useCallback(e=>{if(!(!E||D||!i)){try{e.currentTarget.setPointerCapture(e.pointerId)}catch{}ne.current=e.pointerId,M(!0),P.current=e.clientX,F.current=O,I.current=O,le(O),e.preventDefault()}},[le,i,D,E,O]),de=Q.useCallback(e=>{if(!j||ne.current!==e.pointerId)return;let t=P.current-e.clientX,n=rl(F.current+t,L.current);I.current!==n&&(I.current=n,le(n))},[le,j]),fe=Q.useCallback(e=>{if(ne.current!==e.pointerId||!i)return;try{e.currentTarget.releasePointerCapture(e.pointerId)}catch{}let t=rl(I.current??O,L.current);q(),le(t),I.current=t,p(i,t),M(!1),ne.current=null},[le,i,p,q,O]);Q.useEffect(()=>{j||(I.current=null)},[j]);let pe=Q.useCallback(()=>{i&&l(i)},[l,i]),he=Q.useCallback(()=>{i&&f(i)},[i,f]),ge=Q.useCallback(e=>{if((e.metaKey||e.ctrlKey)&&e.key.toLowerCase()===`w`&&T&&i){e.preventDefault(),e.stopPropagation(),ce(T.id);return}e.key===`Escape`&&(e.preventDefault(),e.stopPropagation(),pe())},[T,ce,i,pe]);Q.useEffect(()=>{if(!(!i||!T)&&T.mode===`file`&&T.targetPath){g(i,T.targetPath,{allowOutsideRoot:!0});return}},[T,i,g]);let _e=T?.mode===`chat`?T.id:null,ve=Fs(_e?H[Os(i,_e)]:void 0,_e?ll(T?.dedupeKey):null);Q.useEffect(()=>{if(!E||!i||!ve){Ee(``,null);return}return Ee(i,ve),()=>{Ee(``,null)}},[ve,i,E]),Q.useEffect(()=>{if(!E||!i||!ve||typeof window>`u`)return;let e=()=>{if(document.visibilityState===`hidden`||!document.hasFocus()){z(i,ve,!1);return}me(ve),z(i,ve,!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),z(i,ve,!1)}},[ve,i,E]);let ye=Q.useCallback((e,t,n)=>Pt(R.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 R.current.keys())e.has(t)||R.current.delete(t)},[w]);let be=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]),xe=Q.useCallback(()=>{if(typeof window>`u`)return;let e={themeMode:y,lightThemeId:x,darkThemeId:S,currentTheme:C};for(let t of re.current.values()){let n=t.contentWindow;if(!n)continue;let r=n.__openchamberApplyThemeSync;if(typeof r==`function`)try{r(e);continue}catch{}n.postMessage({type:`openchamber:theme-sync`,payload:e},window.location.origin)}},[C,S,x,y]),Se=Q.useCallback(()=>{if(typeof window>`u`)return;let e={allowPromptingSubagentSessions:v};for(let t of re.current.values()){let n=t.contentWindow;if(!n)continue;let r=n.__openchamberApplyChatSettingsSync;if(typeof r==`function`)try{r(e);continue}catch{}n.postMessage({type:`openchamber:chat-settings-sync`,payload:e},window.location.origin)}},[v]),Ce=Q.useCallback(()=>{if(!(typeof window>`u`))for(let[e,t]of re.current.entries()){let n=t.contentWindow;if(!n)continue;let r={visible:_e===e},i=n.__openchamberSetEmbeddedVisibility;if(typeof i==`function`)try{i(r);continue}catch{}n.postMessage({type:Ft,payload:r},window.location.origin)}},[_e]);Q.useEffect(()=>{if(typeof window>`u`)return;let e=e=>{if(e.origin!==window.location.origin||!Array.from(re.current.values()).some(t=>t.contentWindow===e.source))return;let t=e.data;if(t?.type===`openchamber:close-embedded-session-chat`){let t=Array.from(re.current.entries()).find(([,t])=>t.contentWindow===e.source);t&&i&&ce(t[0]);return}if(t?.type===`openchamber:chat-settings-request`){Se();return}if(t?.type===`openchamber:embedded-visibility-request`){Ce();return}if(t?.type!==`openchamber:cycle-theme-request`)return;let n=[`light`,`dark`,`system`],r=(n.indexOf(y)+1)%n.length;b(n[r])};return window.addEventListener(`message`,e),()=>window.removeEventListener(`message`,e)},[ce,i,Se,Ce,b,y]),Q.useLayoutEffect(()=>{w.some(e=>e.mode===`chat`)&&(xe(),Se(),Ce())},[S,x,Se,Ce,xe,w,y]);let we=Q.useMemo(()=>w.map(e=>{let n=sl(e,A,t),i=vl(n,Xc),a=il(e.targetPath,r);return{id:e.id,label:i,icon:cl(e),title:a?`${n}: ${a}`:n,closeLabel:t(`contextPanel.tab.closeTabAria`,{label:i})}}),[r,A,t,w]),Te=T?.mode===`context`?(0,$.jsx)(ms,{}):T?.mode===`plan`?(0,$.jsx)(Vo,{targetPath:T.targetPath}):T?.mode===`preview`?(0,$.jsx)(Cl,{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=wl()?El:Tl,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=>Os(i,e.id)));se(t=>{let n=!1,r={};for(let e of De){let a=ll(e.dedupeKey);if(!a)continue;let o=Os(i,e.id),s=t[o];r[o]=s??Ns({sessionId:a,directory:i}),n||=!s}let a=Bs(t,e);return n||=a!==t,n?{...a,...r}:t});for(let t of Object.keys(U.tabs))(!e.has(Os(i,t))||U.tabs[t]?.directory!==i)&&W({type:`close-tab`,tabId:t})},[De,se,i,U.tabs]);let Pe=_e?Os(i,_e):null,Fe=_e?ll(T?.dedupeKey):null,Ie=Pe&&Fe?Ps(H[Pe],{sessionId:Fe,directory:i}):void 0,Le=Ie&&Pe?ks(K,Pe,Ie.current.directory,Ie.current.sessionId):null;Q.useLayoutEffect(()=>{if(G!==`react-surface`||!E||!_e||!Ie||!Pe||!Le){G===`react-surface`&&W({type:`activate`,viewKey:null,now:Date.now()});return}se(e=>e[Pe]?e:{...e,[Pe]:Ie}),W({type:`touch`,tab:{tabId:_e,sessionId:Ie.anchor.sessionId,directory:Ie.anchor.directory},view:{tabId:_e,surfaceId:Pe,sessionId:Ie.current.sessionId,directory:Ie.current.directory,viewKey:Le},now:Date.now()})},[Ie,Pe,_e,Le,G,se,E]);let Re=Q.useCallback((e,t,n)=>{let r=Os(i,e),a=!1;return se(e=>{let i=zs(e,r,{sessionId:t,directory:n});return a=i.accepted,i.navigationBySurfaceId}),a},[se,i]),ze=Q.useCallback(e=>{let t=Os(i,e);se(e=>{let n=e[t];if(!n)return e;let r=Ls(n);return r===n?e:{...e,[t]:r}})},[se,i]),Be=(0,$.jsxs)(`header`,{className:`flex h-10 items-stretch border-b border-transparent`,children:[(0,$.jsx)(on,{items:we,activeId:T?.id??null,onSelect:e=>{i&&m(i,e)},onClose:e=>{ce(e)},onReorder:(e,t)=>{i&&h(i,e,t)},layoutMode:`scrollable`,variant:`default`}),(0,$.jsxs)(`div`,{className:`flex items-center gap-1 px-1.5`,children:[(0,$.jsx)(X,{type:`button`,variant:`ghost`,size:`sm`,onClick:he,className:`h-7 w-7 p-0`,title:t(D?`contextPanel.actions.collapsePanel`:`contextPanel.actions.expandPanel`),"aria-label":t(D?`contextPanel.actions.collapsePanel`:`contextPanel.actions.expandPanel`),children:D?(0,$.jsx)(Y,{name:`fullscreen-exit`,className:`h-3.5 w-3.5`}):(0,$.jsx)(Y,{name:`fullscreen`,className:`h-3.5 w-3.5`})}),(0,$.jsx)(X,{type:`button`,variant:`ghost`,size:`sm`,onClick:pe,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(${qc}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:L,"data-context-panel":`true`,tabIndex:-1,inert:!E||void 0,className:J(`flex min-h-0 flex-col overflow-hidden bg-background`,!D&&`oc-layout-divider-l`,D?`absolute inset-0 z-20 min-w-0`:`relative h-full flex-shrink-0`,!E&&`pointer-events-none`,j||!E||ee?`transition-none`:`transition-[width] duration-200 ease-in-out`),onKeyDownCapture:ge,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:ue,onPointerMove:de,onPointerUp:fe,onPointerCancel:fe,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)(Xa,{mode:`editor-only`,isActive:E&&Me})}):null,G===`legacy-iframe`&&De.map(e=>{let n=ll(e.dedupeKey);if(!n)return null;let r=ye(e.id,n,e.readOnly);return r?(0,$.jsx)(`iframe`,{ref:t=>{if(!t){re.current.delete(e.id);return}re.current.set(e.id,t)},src:r,title:t(`contextPanel.iframe.sessionChatTitle`,{sessionID:n}),className:J(`absolute inset-0 h-full w-full border-0 bg-background`,_e===e.id?`block`:`hidden`),onLoad:()=>{xe(),Se(),Ce()}},e.id):null}),G===`react-surface`?Object.values(U.mountedViews).map(e=>{let t=H[Os(i,e.tabId)],n=E&&_e===e.tabId&&Le===e.viewKey;return(0,$.jsx)(Q.Activity,{name:`context-panel-session-${e.sessionId}`,mode:n?`visible`:`hidden`,children:(0,$.jsx)(cc,{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)=>W({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)(Xi,{hideStackedFileSidebar:!0,stackedDefaultCollapsedAll:!t,pinSelectedFileHeaderToTopOnNavigate:!0,showOpenInEditorAction:!0,diffScope:e.diffScope??(e.stagedDiff?`staged`:`working`),turnMessageId:e.diffTurnMessageId,sessionId:e.diffSessionId,directory:i,onDiffScopeChange:be,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`?Te:null]})]})};export{qn as _,ya as a,na as c,ra as d,Xi as f,Ur as g,kr as h,Xa as i,ia as l,Yr as m,Vo as n,sa as o,Xr as p,$a as r,oa as s,Dl as t,aa as u};