@pi-chamber/web 0.8.1 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/cli.js +5 -2
- package/bin/cli.test.js +44 -0
- package/bin/lib/DOCUMENTATION.md +5 -5
- package/bin/lib/cli-args.js +19 -4
- package/bin/lib/commands-lifecycle.js +14 -0
- package/bin/lib/commands-logs.js +2 -1
- package/bin/lib/commands-serve.js +166 -2
- package/bin/lib/commands-tunnel.js +21 -0
- package/bin/lib/commands-update.js +97 -33
- package/bin/lib/commands-update.test.js +96 -1
- package/dist/assets/{DiagramEditor-D_3eJVSw.js → DiagramEditor-CcbnMl1H.js} +1 -1
- package/dist/assets/{DiagramView-pGYm0-DR.js → DiagramView-DTW5jwK3.js} +1 -1
- package/dist/assets/DiffView-CZyHHAOB.js +18 -0
- package/dist/assets/FilesView-BJYLFR3H.js +6 -0
- package/dist/assets/GitView-Cg_5UU7E.js +8 -0
- package/dist/assets/{JsonTreeView-CpgqCk9_.js → JsonTreeView-GTdKGEdy.js} +1 -1
- package/dist/assets/{MarkdownRendererImpl-fI6n3kqT.js → MarkdownRendererImpl-WqBwxlso.js} +1 -1
- package/dist/assets/{PatchDiff-BRloGXPs.js → PatchDiff-BRi23N1l.js} +1 -1
- package/dist/assets/{SessionSwitcherContent-BQc-vW4s.js → SessionSwitcherContent-7VAU5pwZ.js} +1 -1
- package/dist/assets/{SessionSwitcherDropdown-v_8TaIZm.js → SessionSwitcherDropdown-BslRtccE.js} +2 -2
- package/dist/assets/{SessionUnreadDot-A7vSfll2.js → SessionUnreadDot-1nV0Z2ZA.js} +1 -1
- package/dist/assets/SettingsView-UIaAyjTo.js +2 -0
- package/dist/assets/{SettingsWindow-D7UDhYd4.js → SettingsWindow-D4jZHl8X.js} +1 -1
- package/dist/assets/{ToolOutputDialog-wpU0ylYS.js → ToolOutputDialog-BoeJONiR.js} +1 -1
- package/dist/assets/{ToolPartDiffPreview-BvoQK5Gm.js → ToolPartDiffPreview-9FLv2fWD.js} +1 -1
- package/dist/assets/{VirtualizedFileDiff-DdPbLdh7.js → VirtualizedFileDiff-ywmPBXAG.js} +4 -4
- package/dist/assets/{collapsible-BO6FIjvn.js → collapsible-6mCYf7Ky.js} +1 -1
- package/dist/assets/{computeVirtualFileMetrics-DMvXzUJh.js → computeVirtualFileMetrics-3H6mg13G.js} +1 -1
- package/dist/assets/{contextFileOpenGuard-BwXQVjtS.js → contextFileOpenGuard-CKyf-TZ7.js} +1 -1
- package/dist/assets/gitStatusPredicates-UsytDMy_.js +134 -0
- package/dist/assets/index-C8NYcA8-.css +1 -0
- package/dist/assets/{index-C3SyF-cA.js → index-D1IaU-Q7.js} +1 -1
- package/dist/assets/index-yWgKW2Fx.js +8 -0
- package/dist/assets/{isDiffPlainText-BboRbmcm.js → isDiffPlainText-DPCilEx_.js} +1 -1
- package/dist/assets/{isFilePlainText-BpTnLRyI.js → isFilePlainText-XdCAgm8R.js} +1 -1
- package/dist/assets/main-DcAMXRSi.js +135 -0
- package/dist/assets/{main-xLwCWLu-.js → main-DhvLreEl.js} +2 -2
- package/dist/assets/{markdownCore-CmFv4H-w.js → markdownCore-BF0Dqwm4.js} +1 -1
- package/dist/assets/{miniChat-Vwo4K1IK.js → miniChat-DsCx0dsW.js} +2 -2
- package/dist/assets/{mobile-BRaxtEoC.js → mobile-C-IN49xX.js} +2 -2
- package/dist/assets/{renderElectronMiniChatApp-DM4rRUUz.js → renderElectronMiniChatApp-C13HXGZL.js} +2 -2
- package/dist/assets/renderMobileApp-xCdVzvyf.js +11 -0
- package/dist/assets/runtimeEndpointReset-CT3WShpj.js +54 -0
- package/dist/assets/{runtimeSurface-SmPSdfop.js → runtimeSurface-C_3mcJ01.js} +1 -1
- package/dist/assets/{useAppFontEffects-Bg-8jtrQ.js → useAppFontEffects-BgK55NDM.js} +105 -105
- package/dist/assets/{useFilesViewSearch-GLcYNIUV.js → useFilesViewSearch-CWx24PZg.js} +1 -1
- package/dist/assets/{usePushVisibilityBeacon-VSYBfNoY.js → usePushVisibilityBeacon-swMQLm-i.js} +1 -1
- package/dist/assets/{useSwitcherItems-BkEt9K-N.js → useSwitcherItems-CrS-F6DY.js} +1 -1
- package/dist/assets/{vendor-codemirror-language-data-B5cJDWBR.js → vendor-codemirror-language-data-BzeePAPn.js} +2 -2
- package/dist/assets/{vendor-dnd-kit-core-CP8ck10N.js → vendor-dnd-kit-core-C9qcAm_1.js} +1 -1
- package/dist/assets/{vendor-dnd-kit-sortable-B-Icjoj4.js → vendor-dnd-kit-sortable-D8ozj8M-.js} +1 -1
- package/dist/assets/vendor-xterm-addon-fit-DX4qG4td.js +1 -0
- package/dist/assets/vendor-xterm-xterm-CrXqRur4.js +16 -0
- package/dist/assets/vendor-xterm-xterm-DDGTF8rc.css +1 -0
- package/dist/assets/{web-components-0H9kvZwn.js → web-components-DAkBDXRk.js} +3 -3
- package/dist/index.html +4 -4
- package/dist/mini-chat.html +3 -3
- package/dist/mobile.html +3 -3
- package/package.json +1 -2
- package/server/lib/pi/routes.test.js +39 -0
- package/server/lib/pi/session-daemon/DOCUMENTATION.md +1 -1
- package/server/lib/pi/session-daemon/extension-bridge.js +14 -11
- package/server/lib/pi/session-daemon/prompt-operations.test.js +73 -6
- package/server/lib/pi/session-daemon/session-daemon.js +163 -21
- package/server/lib/relay/host-client.test.js +3 -1
- package/server/lib/stt/DOCUMENTATION.md +1 -1
- package/server/lib/terminal/DOCUMENTATION.md +2 -2
- package/server/lib/ui-auth/DOCUMENTATION.md +1 -1
- package/server/lib/ui-auth/ui-auth.js +23 -26
- package/server/lib/ui-auth/ui-auth.test.js +27 -0
- package/dist/assets/DiffView-BApPTLGp.js +0 -18
- package/dist/assets/FilesView-CiPpuGiF.js +0 -6
- package/dist/assets/GitView-uW3w_LlQ.js +0 -8
- package/dist/assets/SettingsView-CphlZvfd.js +0 -2
- package/dist/assets/gitStatusPredicates-CgNk6M2_.js +0 -134
- package/dist/assets/index-BebQicw3.css +0 -1
- package/dist/assets/index-Bkz23mZq.js +0 -8
- package/dist/assets/main-CMOAwZnJ.js +0 -135
- package/dist/assets/renderMobileApp-DWWewNhc.js +0 -11
- package/dist/assets/runtimeEndpointReset-BF60eHSx.js +0 -54
- package/dist/assets/vendor-ghostty-web-CrxinGGH.js +0 -13
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/DiffView-CZyHHAOB.js","assets/vendor-react-B5Z1Mdn3.js","assets/vendor-scheduler-7OC5HNn7.js","assets/index-yWgKW2Fx.js","assets/vendor-zustand-GVb4H8HE.js","assets/vendor-clsx-B-dksMZM.js","assets/vendor-tailwind-merge-CPcsbTWB.js","assets/vendor-fuse.js-Dw8P0qyA.js","assets/index-C8NYcA8-.css","assets/useAppFontEffects-BgK55NDM.js","assets/vendor-base-ui-vkqQ2P9o.js","assets/vendor-floating-ui-utils-BzXdqYpP.js","assets/vendor-floating-ui-react-dom-BZOGXAGe.js","assets/vendor-floating-ui-dom-WyXykhNi.js","assets/vendor-floating-ui-core-CXmKXOXc.js","assets/vendor-use-sync-external-store-D0AXkdQC.js","assets/vendor-simplewebauthn-browser-VDA66rT_.js","assets/vendor-sonner-BDtm25td.js","assets/vendor-codemirror-view-Ct4T37Ue.js","assets/vendor-codemirror-state-CNWM3Q8V.js","assets/vendor-marijn-find-cluster-break-DXwl3gUT.js","assets/vendor-style-mod-NZ5MEPvj.js","assets/vendor-w3c-keyname-Vcq4gwWv.js","assets/vendor-crelt-C8TCjufn.js","assets/vendor-vite-runtime-DD1OZmLC.js","assets/vendor-class-variance-authority-5VPnzWs2.js","assets/runtimeSurface-C_3mcJ01.js","assets/vendor-dnd-kit-core-C9qcAm_1.js","assets/vendor-dnd-kit-utilities-DTY1C6ST.js","assets/vendor-dnd-kit-accessibility-DZKKhs9S.js","assets/vendor-dnd-kit-sortable-D8ozj8M-.js","assets/vendor-cmdk-zXx6sGnS.js","assets/vendor-radix-ui-react-dialog-D2yhEu2p.js","assets/vendor-radix-ui-primitive-Dc_FVRD7.js","assets/vendor-radix-ui-react-compose-refs-8xy6TJML.js","assets/vendor-radix-ui-react-context-CFsX-AUC.js","assets/vendor-radix-ui-react-id-D2kS9K1j.js","assets/vendor-radix-ui-react-use-layout-effect-C8Yrsaph.js","assets/vendor-radix-ui-react-use-controllable-state-LiqmKSXO.js","assets/vendor-radix-ui-react-dismissable-layer-DrorBNg9.js","assets/vendor-radix-ui-react-primitive-DkH8dMOR.js","assets/vendor-radix-ui-react-slot-BIDFZX0-.js","assets/vendor-radix-ui-react-use-callback-ref-BwDcSoGV.js","assets/vendor-radix-ui-react-use-escape-keydown-DTkqjenV.js","assets/vendor-radix-ui-react-focus-scope-D2BkImwt.js","assets/vendor-radix-ui-react-portal-YgCRIyi7.js","assets/vendor-radix-ui-react-presence-D432pCMB.js","assets/vendor-radix-ui-react-focus-guards-BfdFmL7c.js","assets/vendor-react-remove-scroll-vR1dy1aP.js","assets/vendor-tslib-De9GV7Vy.js","assets/vendor-react-remove-scroll-bar-CSAHp1YF.js","assets/vendor-react-style-singleton-Ctw6HnYx.js","assets/vendor-get-nonce-C-Z93AgS.js","assets/vendor-use-sidecar-Vv4V8Nd1.js","assets/vendor-use-callback-ref-CVVuCyLj.js","assets/vendor-aria-hidden-DvXkyWUv.js","assets/vendor-codemirror-language-BByA_dGF.js","assets/vendor-lezer-common-B3-cUCR_.js","assets/vendor-lezer-highlight-CDMHUZ74.js","assets/vendor-codemirror-lang-javascript-DuOEwJ3f.js","assets/vendor-lezer-javascript-D7Tj24ot.js","assets/vendor-lezer-lr-bhwg1HMg.js","assets/vendor-codemirror-autocomplete-wd6iRebq.js","assets/vendor-codemirror-lang-json-CZ07HmNC.js","assets/vendor-lezer-json-Iaex0UN-.js","assets/vendor-codemirror-lang-css-djiuoTi8.js","assets/vendor-lezer-css-C5xB6jxd.js","assets/vendor-codemirror-lang-html-CKHqhW5R.js","assets/vendor-lezer-html-C0I1p52t.js","assets/vendor-codemirror-lang-markdown-DtcZDGqe.js","assets/vendor-lezer-markdown-C6g-d6P3.js","assets/vendor-codemirror-language-data-BzeePAPn.js","assets/vendor-codemirror-lang-python-DzzokVau.js","assets/vendor-lezer-python-CvuFxeZl.js","assets/vendor-codemirror-commands-DYppkHEk.js","assets/vendor-tanstack-react-virtual-2skouoFw.js","assets/vendor-tanstack-virtual-core-Dubg10g5.js","assets/vendor-framer-motion-CfplGuM0.js","assets/vendor-motion-dom-DhJ-sYS5.js","assets/vendor-motion-utils-CKEGc_YG.js","assets/gitStatusPredicates-UsytDMy_.js","assets/web-components-DAkBDXRk.js","assets/computeVirtualFileMetrics-3H6mg13G.js","assets/vendor-shiki-Bbf2GEcE.js","assets/vendor-shikijs-core-CGM_jqPK.js","assets/vendor-shikijs-types-CPSbSeK6.js","assets/vendor-shikijs-vscode-textmate-BgLrS_2D.js","assets/vendor-hast-util-to-html-BKBhbTDb.js","assets/vendor-html-void-elements-CkdplsNl.js","assets/vendor-property-information-rJCbAzvX.js","assets/vendor-zwitch-C2o2j-tx.js","assets/vendor-stringify-entities-CsH1VEn9.js","assets/vendor-character-entities-legacy-BpoLgcEt.js","assets/vendor-character-entities-html4-D7taRCQ7.js","assets/vendor-ccount-c2V3InAJ.js","assets/vendor-comma-separated-tokens-D8TqSuIK.js","assets/vendor-space-separated-tokens-DD3iYX1K.js","assets/vendor-hast-util-whitespace-D4Wp6AEg.js","assets/vendor-shikijs-engine-oniguruma-DPWuIF1G.js","assets/themeResolver-yJ9XpNMI.js","assets/vendor-pierre-theming-Dgp7B_O4.js","assets/vendor-shikijs-engine-javascript-Cme4830A.js","assets/vendor-oniguruma-to-es-DLBnFDCE.js","assets/vendor-oniguruma-parser-C0D4_9rT.js","assets/vendor-regex-BBWcyTkg.js","assets/vendor-regex-utilities-2BQyy0xI.js","assets/vendor-regex-recursion-JU4mF-dD.js","assets/vendor-shikijs-transformers-CZWsLLKm.js","assets/VirtualizedFileDiff-ywmPBXAG.js","assets/isDiffPlainText-DPCilEx_.js","assets/vendor-diff-C3JhlQdm.js","assets/runtimeEndpointReset-CT3WShpj.js","assets/SessionUnreadDot-1nV0Z2ZA.js","assets/vendor-xterm-xterm-CrXqRur4.js","assets/vendor-xterm-xterm-DDGTF8rc.css","assets/permissionStore-iKN1K2_x.js","assets/runtimeEndpointReset-BV3KOtdA.css","assets/appThemeRegistry-gegrE2dq.js","assets/registerCustomTheme-DmolaWWZ.js","assets/contextFileOpenGuard-CKyf-TZ7.js","assets/FilesView-BJYLFR3H.js","assets/DiagramEditor-CcbnMl1H.js","assets/vendor-react-drawio-BYDptOsj.js","assets/useFilesViewSearch-CWx24PZg.js","assets/JsonTreeView-GTdKGEdy.js","assets/Virtualizer-BSHVMKgK.js","assets/isFilePlainText-XdCAgm8R.js","assets/vendor-codemirror-search-BV44140v.js","assets/vendor-replit-codemirror-vim-CGHHNQxC.js","assets/GitView-Cg_5UU7E.js","assets/collapsible-6mCYf7Ky.js","assets/DiagramView-DTW5jwK3.js","assets/SettingsView-UIaAyjTo.js","assets/vendor-qrcode-B0KNSajT.js","assets/vendor-dijkstrajs-COg3n3zL.js","assets/SettingsWindow-D4jZHl8X.js"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{R as r,j as e,r as Ce,e as Fn}from"./vendor-react-B5Z1Mdn3.js";import"./vendor-katex-CNckGUMB.js";import{u as ee,c as ce,r as tt,j as en,J as Bn,H as tn,U as nn,w as zn,G as Un,O as Hn,a5 as Re,P as Vn,Q as Kn,L as Te,M as Xn,a6 as qn,a7 as Gn,a8 as Et,a9 as Ve,f as Yn,d as Jn,l as Qn,b as Zn,A as er,aa as rn,m as sn,ab as tr,ac as nr,ad as rr,a4 as sr,s as or,p as on,o as ar}from"./index-yWgKW2Fx.js";import{_ as Ee}from"./vendor-vite-runtime-DD1OZmLC.js";import{o as ir,C as lr,a as cr,b as dr,c as ur,d as hr,T as an,B as pr,E as fr,G as mr,p as gr,z as xr,x as wr,y as yr,H as Tt,r as _t,A as Dt,S as At,q as br,v as vr,w as jr,F as Sr,W as Cr}from"./runtimeEndpointReset-CT3WShpj.js";import{b6 as st,I as q,$ as Ne,bS as ot,k as Se,t as je,bT as kr,U as ge,ay as nt,bx as ln,b3 as mt,D as Nr,E as Oe,F as $e,a as Pr,G as We,b as Rr,af as gt,bm as Er,bn as Tr,j as xt,aD as Ge,b8 as cn,bg as Mt,aq as _r,aS as wt,aT as yt,bi as bt,bj as vt,bk as jt,bl as Dr,aP as Ar,br as Mr,N as Ir,ba as dn,L as Ie,bU as Ke,bV as un,bW as hn,aV as Lr,bX as ht,bY as Or,bZ as De,b7 as pn,b_ as $r,b$ as St,c0 as Wr,Q as fn,Y as Fr,c1 as Br,c2 as zr,c3 as It,u as Ur,d as Hr,e as Vr,c4 as Kr,c as Lt,s as Xr,r as at,bb as qr,c5 as Gr,f as Yr,c6 as Jr,c7 as Qr,c8 as Zr,c9 as es,ca as Ue,cb as He,cc as ts,a1 as ns,a0 as rs,a3 as ss,_ as os,bP as as,a2 as is,a4 as ls,a5 as cs,a8 as ds,a9 as us}from"./useAppFontEffects-BgK55NDM.js";import{v as mn,g as gn}from"./contextFileOpenGuard-CKyf-TZ7.js";import{g as xn,l as hs,e as ps,f as fs,h as ms,u as gs}from"./useFilesViewSearch-CWx24PZg.js";import{c as wn,d as pt,P as xs,D as yn,e as bn,f as ws,T as ys,M as bs}from"./vendor-dnd-kit-core-C9qcAm_1.js";import{S as vn,h as vs,u as jn,a as js,v as Ss}from"./vendor-dnd-kit-sortable-D8ozj8M-.js";import{C as Sn}from"./vendor-dnd-kit-utilities-DTY1C6ST.js";import{g as Cn}from"./SessionUnreadDot-1nV0Z2ZA.js";import{u as Ot,a as Ye,m as $t}from"./vendor-framer-motion-CfplGuM0.js";import"./vendor-scheduler-7OC5HNn7.js";import"./vendor-zustand-GVb4H8HE.js";import"./vendor-clsx-B-dksMZM.js";import"./vendor-tailwind-merge-CPcsbTWB.js";import"./vendor-fuse.js-Dw8P0qyA.js";import"./vendor-base-ui-vkqQ2P9o.js";import"./vendor-floating-ui-utils-BzXdqYpP.js";import"./vendor-floating-ui-react-dom-BZOGXAGe.js";import"./vendor-floating-ui-dom-WyXykhNi.js";import"./vendor-floating-ui-core-CXmKXOXc.js";import"./vendor-use-sync-external-store-D0AXkdQC.js";import"./vendor-tanstack-react-virtual-2skouoFw.js";import"./vendor-tanstack-virtual-core-Dubg10g5.js";import"./vendor-xterm-xterm-CrXqRur4.js";import"./permissionStore-iKN1K2_x.js";import"./vendor-simplewebauthn-browser-VDA66rT_.js";import"./vendor-sonner-BDtm25td.js";import"./vendor-codemirror-view-Ct4T37Ue.js";import"./vendor-codemirror-state-CNWM3Q8V.js";import"./vendor-marijn-find-cluster-break-DXwl3gUT.js";import"./vendor-style-mod-NZ5MEPvj.js";import"./vendor-w3c-keyname-Vcq4gwWv.js";import"./vendor-crelt-C8TCjufn.js";import"./vendor-class-variance-authority-5VPnzWs2.js";import"./runtimeSurface-C_3mcJ01.js";import"./vendor-cmdk-zXx6sGnS.js";import"./vendor-radix-ui-react-dialog-D2yhEu2p.js";import"./vendor-radix-ui-primitive-Dc_FVRD7.js";import"./vendor-radix-ui-react-compose-refs-8xy6TJML.js";import"./vendor-radix-ui-react-context-CFsX-AUC.js";import"./vendor-radix-ui-react-id-D2kS9K1j.js";import"./vendor-radix-ui-react-use-layout-effect-C8Yrsaph.js";import"./vendor-radix-ui-react-use-controllable-state-LiqmKSXO.js";import"./vendor-radix-ui-react-dismissable-layer-DrorBNg9.js";import"./vendor-radix-ui-react-primitive-DkH8dMOR.js";import"./vendor-radix-ui-react-slot-BIDFZX0-.js";import"./vendor-radix-ui-react-use-callback-ref-BwDcSoGV.js";import"./vendor-radix-ui-react-use-escape-keydown-DTkqjenV.js";import"./vendor-radix-ui-react-focus-scope-D2BkImwt.js";import"./vendor-radix-ui-react-portal-YgCRIyi7.js";import"./vendor-radix-ui-react-presence-D432pCMB.js";import"./vendor-radix-ui-react-focus-guards-BfdFmL7c.js";import"./vendor-react-remove-scroll-vR1dy1aP.js";import"./vendor-tslib-De9GV7Vy.js";import"./vendor-react-remove-scroll-bar-CSAHp1YF.js";import"./vendor-react-style-singleton-Ctw6HnYx.js";import"./vendor-get-nonce-C-Z93AgS.js";import"./vendor-use-sidecar-Vv4V8Nd1.js";import"./vendor-use-callback-ref-CVVuCyLj.js";import"./vendor-aria-hidden-DvXkyWUv.js";import"./vendor-codemirror-language-BByA_dGF.js";import"./vendor-lezer-common-B3-cUCR_.js";import"./vendor-lezer-highlight-CDMHUZ74.js";import"./vendor-codemirror-lang-javascript-DuOEwJ3f.js";import"./vendor-lezer-javascript-D7Tj24ot.js";import"./vendor-lezer-lr-bhwg1HMg.js";import"./vendor-codemirror-autocomplete-wd6iRebq.js";import"./vendor-codemirror-lang-json-CZ07HmNC.js";import"./vendor-lezer-json-Iaex0UN-.js";import"./vendor-codemirror-lang-css-djiuoTi8.js";import"./vendor-lezer-css-C5xB6jxd.js";import"./vendor-codemirror-lang-html-CKHqhW5R.js";import"./vendor-lezer-html-C0I1p52t.js";import"./vendor-codemirror-lang-markdown-DtcZDGqe.js";import"./vendor-lezer-markdown-C6g-d6P3.js";import"./vendor-codemirror-language-data-BzeePAPn.js";import"./vendor-codemirror-lang-python-DzzokVau.js";import"./vendor-lezer-python-CvuFxeZl.js";import"./vendor-codemirror-commands-DYppkHEk.js";import"./vendor-dnd-kit-accessibility-DZKKhs9S.js";import"./vendor-motion-dom-DhJ-sYS5.js";import"./vendor-motion-utils-CKEGc_YG.js";const Cs=280,Wt=4,ks=({transform:t})=>({...t,y:0}),Ns=({id:t,children:n,className:s})=>{const{attributes:a,listeners:o,setNodeRef:m,transform:w,transition:u,isDragging:p}=jn({id:t});return e.jsx("div",{ref:m,"data-sortable-tab-id":t,style:{transform:Sn.Transform.toString(w),transition:u},className:ce("h-full rounded-md",s,p&&"opacity-50"),...a,...o,children:n})},Ps=({id:t,children:n,className:s})=>e.jsx("div",{className:ce("h-full",s),"data-sortable-tab-id":t,children:n}),Rs=({items:t,activeId:n,onSelect:s,onClose:a,onReorder:o,layoutMode:m="scrollable",variant:w="default",activePillInsetClassName:u,activePillButtonClassName:p,inactiveTabsIconOnly:g=!1,animateActivePill:v,activePillLowercase:f=!0,nonCompositedIndicator:l=!1,className:T})=>{const c=ee(k=>k.isMobile),{isTablet:S}=st(),j=c||S,P=r.useRef(null),[R,O]=r.useState({left:!1,right:!1}),te=r.useMemo(()=>t.map(k=>k.id),[t]),F=m==="scrollable",re=w==="default",z=w==="active-pill",b=z||w==="animated",G=re,H=b||G,$=z&&F,V=b,ne=v??b,E=typeof o=="function",Q=E?Ns:Ps,C=r.useRef(new Map),[M,U]=r.useState(null),[L,K]=r.useState(!1),[se,he]=r.useState(null),ue=r.useRef(!1),be=r.useRef(0),fe=r.useRef(n),xe=r.useRef(null),pe=r.useMemo(()=>{if(!H||!se||!n||se===n)return 0;const k=t.findIndex(ie=>ie.id===se),Y=t.findIndex(ie=>ie.id===n);return k<0||Y<0?0:k>Y?Wt:-Wt},[n,t,se,H]),I=wn(pt(xs,{activationConstraint:{distance:8}})),W=r.useCallback((k,Y)=>!k||!Y?k===Y:Math.abs(k.left-Y.left)<.5&&Math.abs(k.top-Y.top)<.5&&Math.abs(k.width-Y.width)<.5&&Math.abs(k.height-Y.height)<.5,[]),x=r.useCallback((k,Y)=>{if(Y){C.current.set(k,Y);return}C.current.delete(k)},[]),A=r.useCallback(()=>{if(!H||!n){U(J=>J===null?J:null);return}const k=P.current,Y=C.current.get(n);if(!k||!Y){U(J=>J===null?J:null);return}let ie=0,_=0,oe=Y;for(;oe&&oe!==k;)ie+=oe.offsetLeft,_+=oe.offsetTop,oe=oe.offsetParent;const ae={left:ie,top:_,width:Y.offsetWidth,height:Y.offsetHeight};U(J=>W(J,ae)?J:ae)},[n,W,H]),X=r.useCallback(()=>{if(!F){O({left:!1,right:!1});return}const k=P.current;if(!k){O({left:!1,right:!1});return}O({left:k.scrollLeft>2,right:k.scrollLeft+k.clientWidth<k.scrollWidth-2})},[F]);r.useEffect(()=>{if(!F){O({left:!1,right:!1});return}const k=P.current;if(!k)return;X(),k.addEventListener("scroll",X,{passive:!0});const Y=new ResizeObserver(X);return Y.observe(k),()=>{k.removeEventListener("scroll",X),Y.disconnect()}},[F,t.length,X]),r.useEffect(()=>{if(!H){U(null);return}A();const k=P.current;if(!k)return;const Y=new ResizeObserver(()=>{performance.now()-be.current>Cs&&K(!1),A()});if(Y.observe(k),n){const ie=C.current.get(n);ie&&Y.observe(ie)}return()=>{Y.disconnect()}},[n,t.length,A,H]),r.useLayoutEffect(()=>{A()});const de=te.join("\0");r.useLayoutEffect(()=>{if(!H){ue.current=!1,K(!1);return}const k=xe.current!==de;if(xe.current=de,!ue.current){ue.current=!0,fe.current=n;return}const Y=fe.current!==n;if(fe.current=n,!Y||k){K(!1);return}be.current=performance.now(),K(!0)},[n,de,H]),r.useEffect(()=>{if(!F||!n)return;const k=P.current;if(!k)return;const Y=window.requestAnimationFrame(()=>{const ie=typeof window.CSS?.escape=="function"?window.CSS.escape(n):n.replace(/"/g,'\\"'),_=k.querySelector(`[data-sortable-tab-id="${ie}"]`);_&&(_.scrollIntoView({block:"nearest",inline:"nearest"}),X())});return()=>{window.cancelAnimationFrame(Y)}},[n,F,t.length,X]);const me=r.useCallback(k=>{if(!o)return;const{active:Y,over:ie}=k;!ie||Y.id===ie.id||o(String(Y.id),String(ie.id))},[o]),we=e.jsxs("div",{className:ce("relative flex h-full min-w-0 flex-1",T),children:[F&&R.left?e.jsx("div",{className:ce("pointer-events-none absolute inset-y-0 left-0 z-20 bg-gradient-to-r to-transparent",b?"w-8 from-[var(--surface-background)]":"w-6 from-background")}):null,F&&R.right?e.jsx("div",{className:ce("pointer-events-none absolute inset-y-0 right-0 z-20 bg-gradient-to-l to-transparent",b?"w-8 from-[var(--surface-background)]":"w-6 from-background")}):null,e.jsxs("div",{ref:P,className:ce("relative flex h-full min-w-0 flex-1",b?"items-center overflow-x-hidden overflow-y-hidden":"items-stretch",b&&"@container/pill-tabs",b&&"pill-tabs__track",b&&(u??"gap-0.5 py-0.5"),G&&"items-center overflow-y-hidden",V&&"rounded-[10px] [corner-shape:squircle] supports-[corner-shape:squircle]:rounded-[50px] bg-[color-mix(in_srgb,var(--foreground)_4%,transparent)] p-0.5 gap-0.5",F?"overflow-x-auto scrollbar-none":"overflow-x-hidden"),style:F?{scrollbarWidth:"none",msOverflowStyle:"none"}:void 0,role:"tablist","aria-label":"Tabs",children:[b&&M?e.jsx("div",{className:ce("pointer-events-none absolute left-0 top-0 z-0 rounded-[9px] [corner-shape:squircle] supports-[corner-shape:squircle]:rounded-[50px] bg-[var(--surface-elevated)]","border border-[color-mix(in_srgb,var(--foreground)_7%,transparent)]","shadow-[0_1px_2px_color-mix(in_srgb,var(--foreground)_10%,transparent),0_2px_6px_color-mix(in_srgb,var(--foreground)_6%,transparent)]",ne&&L&&(l?"pill-tabs__indicator--is-animated-layout":"pill-tabs__indicator--is-animated")),style:l?{left:`${M.left+pe}px`,top:`${M.top}px`,width:`${M.width}px`,height:`${M.height}px`}:{transform:`translate3d(${M.left+pe}px, ${M.top}px, 0)`,width:`${M.width}px`,height:`${M.height}px`}}):null,G&&M?e.jsx("div",{className:ce("pointer-events-none absolute left-0 -bottom-px z-10 h-[3px] rounded-t-[2px] bg-[var(--primary-base)]",L&&"underline-tabs__indicator--is-animated"),style:{transform:`translate3d(${M.left+pe}px, 0, 0)`,width:`${M.width}px`},"aria-hidden":!0}):null,t.map(k=>{const Y=k.id===n,ie=g&&b&&!Y&&!!k.icon,_=!ie,oe=!!k.icon,ae=g&&b&&Y&&!F&&!$,J=k.closable!==!1&&!!a,B=J&&!!k.icon,h=F||$?void 0:b?ae?"flex-none basis-auto":c?"flex-1 basis-0 min-w-0":"flex-1 basis-0 min-w-fit":"min-w-0 flex-1 basis-0",i=J?N=>{N.button===1&&(N.preventDefault(),N.stopPropagation(),a?.(k.id))}:void 0,D=J?N=>{N.button===1&&N.preventDefault()}:void 0,d=N=>oe?e.jsxs("span",{className:N,children:[e.jsx("span",{className:ce("flex items-center justify-center transition-opacity",B&&(j?"opacity-0":"group-hover:opacity-0")),children:k.icon}),B?e.jsx("span",{role:"button",tabIndex:-1,className:ce("absolute inset-0 z-20 flex !min-h-0 !min-w-0 items-center justify-center rounded-sm text-muted-foreground transition-opacity hover:text-foreground",j?"opacity-100":"opacity-0 group-hover:opacity-100"),onPointerDown:le=>le.stopPropagation(),onClick:le=>{le.stopPropagation(),a?.(k.id)},"aria-label":k.closeLabel??`Close ${k.label} tab`,title:k.closeLabel??`Close ${k.label} tab`,children:e.jsx(q,{name:"close",className:"h-3.5 w-3.5"})}):null]}):null;return e.jsx(Q,{id:k.id,className:h,children:e.jsxs("div",{ref:N=>x(k.id,N),onAuxClick:i,onMouseDown:D,className:ce("group flex h-full min-w-0 flex-nowrap items-center",F||$?"shrink-0":b?"w-full":"w-full min-w-0",b?"relative z-10 bg-transparent":Y?"relative z-10 bg-transparent text-foreground":"relative z-10 bg-transparent text-muted-foreground hover:text-foreground"),children:[e.jsx("button",{type:"button",role:"tab","aria-selected":Y,"aria-label":ie?k.title??k.label:void 0,onClick:()=>s(k.id),onPointerDown:H?()=>{K(!0),he(k.id)}:void 0,onPointerUp:H?()=>he(null):void 0,onPointerLeave:H?()=>he(null):void 0,onPointerCancel:H?()=>he(null):void 0,className:ce(b?"animated-tabs__button pill-tabs__button relative z-10 flex flex-1 min-w-0 flex-nowrap items-center justify-center rounded-[9px] [corner-shape:squircle] supports-[corner-shape:squircle]:rounded-[50px] text-sm font-medium transition-colors duration-150 !min-h-0":"flex h-full min-w-0 flex-nowrap items-center typography-micro",b&&f?"lowercase":null,b&&(ie?"gap-0":"gap-1.5"),b?$?"shrink-0 whitespace-nowrap px-3 text-center":F?"max-w-56 shrink-0 px-3 text-center":ie?"px-2 !min-w-0 text-center":ae?"shrink-0 whitespace-nowrap px-3 text-center":"px-3 text-center":F?"max-w-56 justify-start truncate px-3 text-left":"w-full justify-center truncate px-3 text-center",b?p??(z?c?"h-[38px]":"h-[31px]":"h-7"):null,b?Y?"text-foreground":"text-muted-foreground hover:text-foreground":null,b?"focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)] focus-visible:ring-offset-1 focus-visible:ring-offset-background":null),title:k.title??k.label,children:b?e.jsxs(e.Fragment,{children:[d("relative flex h-4 w-4 shrink-0 items-center justify-center"),_?e.jsx("span",{className:"animated-tabs__label truncate",children:k.label}):null]}):e.jsxs("span",{className:ce("flex min-w-0 flex-nowrap items-center gap-1.5",!F&&"justify-center"),children:[d(ce("relative flex h-4 w-4 shrink-0 items-center justify-center transition-colors duration-200 ease-out",Y?"text-[var(--primary-base)]":"text-muted-foreground")),e.jsx("span",{className:"truncate leading-[1.2]",children:k.label})]})}),J&&!B?e.jsx("button",{type:"button",onPointerDown:N=>{N.stopPropagation()},onClick:N=>{N.stopPropagation(),a?.(k.id)},className:ce("relative z-20 inline-flex !min-h-0 !min-w-0 items-center justify-center transition-opacity",b?"-ml-2.5 mr-1 h-[88%] w-5 self-center !aspect-auto rounded-md":"aspect-square h-[65%] min-h-4 max-h-5 rounded-sm mr-1",b?Y?"text-muted-foreground hover:bg-transparent hover:text-foreground":"text-muted-foreground opacity-0 hover:bg-transparent hover:text-foreground group-hover:opacity-100":Y?"text-muted-foreground hover:bg-interactive-hover/60 hover:text-foreground":"text-muted-foreground opacity-0 hover:bg-interactive-hover/80 hover:text-foreground group-hover:opacity-100"),"aria-label":k.closeLabel??`Close ${k.label} tab`,title:k.closeLabel??`Close ${k.label} tab`,children:e.jsx(q,{name:"close",className:"h-3 w-3"})}):null]})},k.id)})]})]});return E?e.jsxs(yn,{sensors:I,collisionDetection:bn,onDragEnd:me,modifiers:[ks],children:[e.jsx(vn,{items:te,strategy:vs,children:we}),e.jsx(ws,{dropAnimation:null})]}):we},Ft=280,Bt=280,zt=500,Es=({isOpen:t,isMobile:n,children:s,className:a,topBar:o})=>{const m=ee(y=>y.sidebarWidth),w=ee(y=>y.setSidebarWidth),[u,p]=r.useState(!1),g=r.useRef(0),v=r.useRef(m||Ft),f=r.useRef(null),l=r.useRef(null),T=r.useRef(null),c=r.useCallback(y=>Math.min(zt,Math.max(Bt,y)),[]),S=r.useCallback(y=>{const b=T.current;b&&(b.style.width=`${y}px`,b.style.minWidth=`${y}px`,b.style.maxWidth=`${y}px`,b.style.setProperty("--oc-left-sidebar-width",`${y}px`))},[]);r.useEffect(()=>{n&&u&&p(!1)},[n,u]),r.useEffect(()=>{u||(f.current=null,l.current=null)},[u]);const j=ir(t);if(n)return null;const P=Math.min(zt,Math.max(Bt,m||Ft)),R=j.layoutVisible?P:0,O=y=>{if(t){try{y.currentTarget.setPointerCapture(y.pointerId)}catch{}l.current=y.pointerId,p(!0),g.current=y.clientX,v.current=R,f.current=R,S(R),y.preventDefault()}},te=y=>{if(n||!u||l.current!==y.pointerId)return;const b=y.clientX-g.current,G=c(v.current+b);f.current!==G&&(f.current=G,S(G))},F=y=>{if(l.current!==y.pointerId||n)return;try{y.currentTarget.releasePointerCapture(y.pointerId)}catch{}const b=c(f.current??R);l.current=null,f.current=null,p(!1),w(b)},re=u?f.current??R:R,z=u?re:R;return e.jsxs("aside",{ref:T,className:ce("relative flex h-full overflow-hidden motion-reduce:transition-none","bg-sidebar",a),style:{width:`${z}px`,minWidth:`${z}px`,maxWidth:`${z}px`,"--oc-left-sidebar-width":`${u?re:P}px`,overflowX:"clip",transform:u||j.slidIn?"translateX(0)":"translateX(-100%)",transition:u?"none":j.transition},"aria-hidden":!t||z===0,children:[t&&e.jsx("div",{className:"pointer-events-none absolute inset-0 z-30 shadow-[inset_-2px_0_10px_-2px_rgb(0_0_0_/_0.06)]","aria-hidden":"true"}),t&&e.jsx("div",{className:ce("absolute right-0 top-0 z-20 h-full w-[3px] cursor-col-resize hover:bg-[var(--interactive-border)]/80 transition-colors",u&&"bg-[var(--interactive-border)]"),onPointerDown:O,onPointerMove:te,onPointerUp:F,onPointerCancel:F,role:"separator","aria-orientation":"vertical","aria-label":"Resize left panel"}),e.jsxs("div",{className:ce("relative z-10 flex h-full shrink-0 flex-col",u&&"pointer-events-none",!t&&"pointer-events-none select-none"),style:{width:"var(--oc-left-sidebar-width)",overflowX:"hidden"},"aria-hidden":!t,children:[o,e.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto",children:e.jsx(Ne,{children:s})})]})]})},Ts=t=>{if(!t||typeof t!="object")return!1;const n=t;return typeof n.x=="number"&&typeof n.y=="number"},Ut=t=>!t||typeof t!="object"?!1:Object.values(t).every(n=>typeof n=="string"),Be=t=>{if(!t||typeof t!="object")return!1;const n=t,s=n.bounds;return typeof n.tag=="string"&&typeof n.text=="string"&&typeof n.selector=="string"&&typeof n.path=="string"&&!!s&&typeof s?.x=="number"&&typeof s?.y=="number"&&typeof s?.width=="number"&&typeof s?.height=="number"&&Ts(n.center)&&Ut(n.attributes)&&Ut(n.computedStyle)&&Array.isArray(n.ancestry)},Ct=({pageUrl:t,viewport:n,devicePixelRatio:s,target:a,screenshotAttached:o,intro:m})=>{const w=a.text.trim(),u=Object.entries(a.attributes).map(([T,c])=>`${T}="${c}"`).join(" "),p=a.computedStyle,g=a.bounds,v=a.center,f=m.replace(/[.:]+$/g,""),l=a.ancestry.map(T=>T.selectorPart).join(" > ");return[`${f}:`,`Page: ${t||"preview"}`,`Viewport: ${n.width}x${n.height}, DPR ${s}`,`Screenshot: ${o?"attached":"not attached"}`,`Element: ${a.tag}`,w?`Text: ${w}`:null,`- Selector: ${a.selector}`,`- Path: ${a.path}`,l?`- Ancestry: ${l}`:null,u?`- Attributes: ${u}`:null,`- Bounds: x=${Math.round(g.x)}, y=${Math.round(g.y)}, width=${Math.round(g.width)}, height=${Math.round(g.height)}`,`- Center: x=${Math.round(v.x)}, y=${Math.round(v.y)}`,`Styles: display=${p.display}; position=${p.position}; font=${p.fontWeight} ${p.fontSize} / ${p.lineHeight} ${p.fontFamily}; color=${p.color}; background=${p.backgroundColor}; z-index=${p.zIndex}`].filter(T=>typeof T=="string").join(`
|
|
3
|
+
`)},Pe=new Map,_s=3e4,kt=t=>{const n=Pe.get(t);return n?n.expiresAt-Date.now()<=_s?(Pe.delete(t),null):n:null},Ds=t=>{try{return new URL(t).origin}catch{return t}},ze="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAwMCAO+/p9sAAAAASUVORK5CYII=",it=new Map;function kn(t){const n="#ffffff",s=t.defaultView??window;try{const a=t.body?s.getComputedStyle(t.body).backgroundColor:"";if(a&&a!=="rgba(0, 0, 0, 0)"&&a!=="transparent")return a;const o=s.getComputedStyle(t.documentElement).backgroundColor;if(o&&o!=="rgba(0, 0, 0, 0)"&&o!=="transparent")return o}catch{}return n}const Nn=t=>new Promise((n,s)=>{const a=new FileReader;a.onloadend=()=>n(typeof a.result=="string"?a.result:ze),a.onerror=()=>s(a.error??new Error("Failed to read image blob")),a.readAsDataURL(t)}),As=async(t,n=.82)=>{const s=await new Promise(a=>t.toBlob(a,"image/jpeg",n));return s&&(await Nn(s)).split(",",2)[1]||""},lt=async(t,n)=>{try{const s=await fetch(t,{credentials:n});return s.ok?await Nn(await s.blob()):null}catch{return null}},Ms=async t=>{if(t.protocol!=="http:"&&t.protocol!=="https:")return"";const n=t.origin,s=kt(n);if(s)return`${s.proxyBasePath}${t.pathname}${t.search}${t.hash}`;const a=it.get(n),o=a??(async()=>{try{const w=await tt("/api/preview/targets",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({url:t.toString(),allowExternal:!0})});if(!w.ok)return Pe.delete(n),null;const u=await w.json(),p=typeof u.proxyBasePath=="string"?u.proxyBasePath:"",g=typeof u.expiresAt=="number"?u.expiresAt:0;if(!p)return Pe.delete(n),null;const v={proxyBasePath:p,expiresAt:g};return Pe.set(n,v),v}catch{return Pe.delete(n),null}finally{it.delete(n)}})();a||it.set(n,o);const m=await o;return m?`${m.proxyBasePath}${t.pathname}${t.search}${t.hash}`:""},Pn=async(t,n)=>{if(!t||t.startsWith("data:"))return t;try{const s=new URL(t,n.baseURI);if(s.origin===window.location.origin||s.protocol!=="http:"&&s.protocol!=="https:")return await lt(s.toString(),"include")??ze;const a=await Ms(s),o=a?await lt(a,"include"):null;return o||(await lt(s.toString(),"omit")??ze)}catch{return ze}},Is=async(t,n)=>{if(!t||t==="none"||!t.includes("url("))return t;const s=Array.from(t.matchAll(/url\((['"]?)(.*?)\1\)/g));let a=t;for(const o of s){const m=o[2]||"";if(!m||m.startsWith("data:"))continue;const w=await Pn(m,n);a=a.replace(o[0],`url("${w}")`)}return a},Ht=t=>t.complete?Promise.resolve():new Promise(n=>{t.addEventListener("load",()=>n(),{once:!0}),t.addEventListener("error",()=>n(),{once:!0})}),Rn=t=>{const n=t.style.cssText;return()=>{t.style.cssText=n}},Ls=t=>{const n=Number.parseFloat(t.lineHeight);if(Number.isFinite(n)&&n>0)return n;const s=Number.parseFloat(t.fontSize);return Number.isFinite(s)&&s>0?s*1.2:16},Os=(t,n,s)=>{const a=[],o=t.defaultView??window,w=Array.from(t.querySelectorAll('button, a, summary, label, [role="button"], [role="link"], [role="menuitem"], [role="tab"], nav *, header *'));for(const u of w){const p=u.textContent?.replace(/\s+/g," ").trim()??"";if(!p||!p.includes(" "))continue;const g=u.getBoundingClientRect();if(g.width<=0||g.height<=0||g.right<0||g.bottom<0||g.left>n||g.top>s)continue;const v=o.getComputedStyle(u);if(v.display==="none"||v.visibility==="hidden"||Number(v.opacity)===0)continue;const f=v.getPropertyValue("text-wrap"),l=v.getPropertyValue("text-wrap-mode"),T=v.whiteSpace.includes("nowrap")||f==="nowrap"||l==="nowrap",c=g.height<=Ls(v)*1.7;!T&&(!c||g.width>n*.72)||(a.push(Rn(u)),u.style.whiteSpace="nowrap",u.style.overflowWrap="normal",u.style.wordBreak="normal",u.style.setProperty("text-wrap","nowrap"),u.style.setProperty("text-wrap-mode","nowrap"))}return()=>{for(let u=a.length-1;u>=0;u-=1)a[u]?.()}},$s=(t,n,s,a)=>{const o=[],m=t.defaultView??window,w=m.scrollX||t.documentElement.scrollLeft||t.body?.scrollLeft||0,u=m.scrollY||t.documentElement.scrollTop||t.body?.scrollTop||0,p=Array.from(t.querySelectorAll("*")).filter(g=>{const v=m.getComputedStyle(g);if(v.position!=="fixed"||v.display==="none"||v.visibility==="hidden"||Number(v.opacity)===0)return!1;const f=g.getBoundingClientRect();return f.width>0&&f.height>0&&f.right>=0&&f.bottom>=0&&f.left<=n&&f.top<=s}).filter((g,v,f)=>!f.some((l,T)=>T<v&&l.contains(g)));for(const g of p){const v=g.getBoundingClientRect(),f=m.getComputedStyle(g),l=Math.ceil(v.width)+8,T=Math.ceil(v.height)+2;a?.add(g),o.push(Rn(g)),g.style.position="absolute",g.style.top=`${v.top+u}px`,g.style.left=`${v.left+w}px`,g.style.right="auto",g.style.bottom="auto",g.style.width=`${l}px`,g.style.minWidth=`${l}px`,g.style.height=`${T}px`,g.style.minHeight=`${T}px`,g.style.margin="0",g.style.boxSizing="border-box",g.style.transform="none",f.zIndex!=="auto"&&(g.style.zIndex=f.zIndex)}return()=>{for(let g=o.length-1;g>=0;g-=1)o[g]?.()}},En=async(t,n,s,a={})=>{const o=[],m=t.defaultView??window,w=f=>{if(f===t.documentElement||f===t.body)return!0;try{const l=f.getBoundingClientRect();return l.width>0&&l.height>0&&l.right>=0&&l.bottom>=0&&l.left<=n&&l.top<=s}catch{return!1}};if(a.applyLayoutWorkarounds){const f=new WeakSet;o.push($s(t,n,s,f)),o.push(Os(t,n,s))}const u=new Map;for(const f of Array.from(t.images))u.set(f,f.currentSrc||f.src||f.getAttribute("src")||"");const p=Array.from(t.querySelectorAll("picture"));for(const f of p){const l=Array.from(f.querySelectorAll("source"));if(l.length===0)continue;const T=l.map(c=>({source:c,srcset:c.getAttribute("srcset"),sizes:c.getAttribute("sizes")}));o.push(()=>{for(const c of T)c.srcset===null?c.source.removeAttribute("srcset"):c.source.setAttribute("srcset",c.srcset),c.sizes===null?c.source.removeAttribute("sizes"):c.source.setAttribute("sizes",c.sizes)});for(const c of l)c.removeAttribute("srcset"),c.removeAttribute("sizes")}const g=Array.from(t.images).filter(f=>w(f));await Promise.all(g.map(async f=>{const l=u.get(f)||f.currentSrc||f.src||f.getAttribute("src")||"";if(!l)return;await Ht(f);const T=await Pn(l,t),c={src:f.getAttribute("src"),srcset:f.getAttribute("srcset"),sizes:f.getAttribute("sizes")};o.push(()=>{c.src===null?f.removeAttribute("src"):f.setAttribute("src",c.src),c.srcset===null?f.removeAttribute("srcset"):f.setAttribute("srcset",c.srcset),c.sizes===null?f.removeAttribute("sizes"):f.setAttribute("sizes",c.sizes)}),f.removeAttribute("srcset"),f.removeAttribute("sizes"),f.setAttribute("src",T||ze),await Ht(f)}));const v=Array.from(t.querySelectorAll("*")).filter(w);return await Promise.all(v.map(async f=>{const l=m.getComputedStyle(f).backgroundImage;if(!l||l==="none"||!l.includes("url("))return;const T=await Is(l,t);if(T===l)return;const c=f.style.backgroundImage;o.push(()=>{f.style.backgroundImage=c}),f.style.backgroundImage=T})),()=>{for(let f=o.length-1;f>=0;f-=1)try{o[f]?.()}catch{}}},Ws=()=>{try{return!!window.__previewCaptureDebug}catch{return!1}},Qe=(...t)=>{Ws()&&console.info("[preview-capture]",...t)},Tn=(t,n=8)=>{const s=[];try{const a=t.querySelectorAll("*");for(const o of a){const m=o.scrollTop||0,w=o.scrollLeft||0;if(m<=0&&w<=0)continue;const u=o.tagName.toLowerCase(),p=o.id?`#${o.id}`:"",g=typeof o.className=="string"&&o.className?`.${o.className.trim().split(/\s+/).slice(0,2).join(".")}`:"";if(s.push({selector:`${u}${p}${g}`,scrollTop:m,scrollLeft:w,clientWidth:o.clientWidth,clientHeight:o.clientHeight,scrollWidth:o.scrollWidth,scrollHeight:o.scrollHeight}),s.length>=n)break}}catch{}return s},Xe="data-oc-fixed-pin",Fs=(t,n,s)=>{if(n<=0&&s<=0)return()=>{};const a=t.defaultView;if(!a)return()=>{};const o=[],m=[];try{for(const w of t.querySelectorAll("*")){if(a.getComputedStyle(w).position!=="fixed")continue;const u=w.getBoundingClientRect();if(!(u.width>0&&u.height>0))continue;w.setAttribute(Xe,JSON.stringify({top:u.top+s,left:u.left+n,width:u.width,height:u.height})),o.push(w);const p=w.tagName.toLowerCase(),g=typeof w.className=="string"&&w.className?`.${w.className.trim().split(/\s+/).slice(0,2).join(".")}`:"";m.push({selector:`${p}${g}`,top:Math.round(u.top),left:Math.round(u.left),width:Math.round(u.width),height:Math.round(u.height)})}}catch{}return Qe("tagged fixed elements",m),()=>{for(const w of o)try{w.removeAttribute(Xe)}catch{}}},Bs={name:"oc-fixed-pin",afterClone(t){const n=t?.clone;if(!(!n||typeof n.querySelectorAll!="function"))for(const s of n.querySelectorAll(`[${Xe}]`)){let a;try{a=JSON.parse(s.getAttribute(Xe)||"")}catch{continue}s.style.setProperty("position","absolute","important"),s.style.setProperty("top",`${a.top}px`,"important"),s.style.setProperty("left",`${a.left}px`,"important"),s.style.setProperty("right","auto","important"),s.style.setProperty("bottom","auto","important"),s.style.setProperty("width",`${a.width}px`,"important"),s.style.setProperty("height",`${a.height}px`,"important"),s.removeAttribute(Xe)}}},Fe="data-oc-scroll-pin",zs=t=>{const n=[],s=Tn(t,64);try{const m=t.documentElement,w=t.body;for(const u of t.querySelectorAll("*")){const p=u.scrollTop||0,g=u.scrollLeft||0;if(p<=0&&g<=0)continue;const v=u!==m&&u!==w;v&&u.setAttribute(Fe,JSON.stringify({top:p,left:g})),n.push({el:u,top:p,left:g,tagged:v})}}catch{}return{reapply:()=>{for(const m of n)try{m.el.scrollHeight,m.el.scrollTop!==m.top&&(m.el.scrollTop=m.top),m.el.scrollLeft!==m.left&&(m.el.scrollLeft=m.left)}catch{}},cleanup:()=>{for(const m of n)if(m.tagged)try{m.el.removeAttribute(Fe)}catch{}},snapshot:s}},Us={name:"oc-nested-scroll",afterClone(t){const n=t?.clone;if(!n||typeof n.querySelectorAll!="function")return;const s=n.ownerDocument;if(s)for(const a of n.querySelectorAll(`[${Fe}]`)){let o;try{o=JSON.parse(a.getAttribute(Fe)||"")}catch{a.removeAttribute(Fe);continue}const m=`translate(${-o.left}px, ${-o.top}px)`,w=a.children.length===1&&a.firstElementChild instanceof HTMLElement&&a.firstElementChild.style.willChange==="transform"?a.firstElementChild:null;if(w)w.style.transform=m;else{a.style.overflow="hidden";const u=s.createElement("div");for(u.style.transform=m,u.style.willChange="transform",u.style.display="inline-block",u.style.width="100%";a.firstChild;)u.appendChild(a.firstChild);a.appendChild(u)}a.removeAttribute(Fe)}}},_n=async(t,n)=>{if(typeof window<"u")try{const s=t.getBoundingClientRect(),a=await en("desktop_capture_page_rect",{x:s.left,y:s.top,width:s.width,height:s.height});if(!a)throw new Error("Desktop screenshot capture is not available");const o=new Image;await new Promise((c,S)=>{o.onload=()=>c(),o.onerror=()=>S(new Error("Failed to load desktop preview screenshot")),o.src=`data:${a.mime};base64,${a.base64}`});const m=Math.max(1,o.naturalWidth||a.width||Math.floor(s.width)),w=Math.max(1,o.naturalHeight||a.height||Math.floor(s.height)),p=Math.min(1,1200/m),g=document.createElement("canvas");g.width=Math.floor(m*p),g.height=Math.floor(w*p);const v=g.getContext("2d");if(!v)return null;v.scale(p,p),v.drawImage(o,0,0,m,w);const f=m/Math.max(1,s.width),l=w/Math.max(1,s.height);v.fillStyle="rgba(37, 99, 235, 0.28)",v.strokeStyle="rgb(37, 99, 235)",v.lineWidth=Math.max(2,2*f),v.fillRect(n.bounds.x*f,n.bounds.y*l,n.bounds.width*f,n.bounds.height*l),v.strokeRect(n.bounds.x*f,n.bounds.y*l,n.bounds.width*f,n.bounds.height*l);const T=await new Promise(c=>g.toBlob(c,"image/jpeg",.82));return T?new File([T],`preview-annotation-${Date.now()}.jpg`,{type:"image/jpeg"}):null}catch(s){return console.warn("[preview] failed to capture annotation screenshot:",s),null}return await Vs(t,n)},Nt=async(t,n,s,a,o,m)=>{if(!t)return null;try{const w=new Image;await new Promise((j,P)=>{w.onload=()=>j(),w.onerror=()=>P(new Error("Failed to load desktop browser screenshot")),w.src=`data:image/jpeg;base64,${t}`});const u=Math.max(1,w.naturalWidth||n),p=Math.max(1,w.naturalHeight||s),v=Math.min(1,1200/u),f=document.createElement("canvas");f.width=Math.floor(u*v),f.height=Math.floor(p*v);const l=f.getContext("2d");if(!l)return null;l.scale(v,v),l.drawImage(w,0,0,u,p);const T=u/Math.max(1,a||u),c=p/Math.max(1,o||p);l.fillStyle="rgba(37, 99, 235, 0.14)",l.strokeStyle="rgb(37, 99, 235)",l.lineWidth=Math.max(2,2*T),l.fillRect(m.bounds.x*T,m.bounds.y*c,m.bounds.width*T,m.bounds.height*c),l.strokeRect(m.bounds.x*T,m.bounds.y*c,m.bounds.width*T,m.bounds.height*c);const S=await new Promise(j=>f.toBlob(j,"image/jpeg",.82));return S?new File([S],`browser-annotation-${Date.now()}.jpg`,{type:"image/jpeg"}):null}catch{return null}};async function Hs(t,n){try{const s=t.contentWindow,a=t.contentDocument??s?.document,o=a?.documentElement;if(!s||!a||!o)return null;const m=t.getBoundingClientRect(),w=Math.max(1,Math.ceil(s.innerWidth||t.clientWidth||m.width)),u=Math.max(1,Math.ceil(s.innerHeight||t.clientHeight||m.height)),p=a.body,g=a.scrollingElement instanceof HTMLElement?a.scrollingElement:null,v=s.scrollX||0,f=s.scrollY||0,l=s.pageXOffset||0,T=s.pageYOffset||0,c=s.visualViewport?.pageLeft||s.visualViewport?.offsetLeft||0,S=s.visualViewport?.pageTop||s.visualViewport?.offsetTop||0,j=o.scrollLeft||0,P=o.scrollTop||0,R=p?.scrollLeft||0,O=p?.scrollTop||0,te=g?.scrollLeft||0,F=g?.scrollTop||0,re=Math.max(v,l,c,j,R,te),z=Math.max(f,T,S,P,O,F);Qe("scroll sources",{windowScrollX:v,windowScrollY:f,pageScrollX:l,pageScrollY:T,visualViewportScrollX:c,visualViewportScrollY:S,rootScrollX:j,rootScrollY:P,bodyScrollX:R,bodyScrollY:O,scrollingElementScrollX:te,scrollingElementScrollY:F,scrollingElementTag:g?.tagName?.toLowerCase()??null,resolvedScrollX:re,resolvedScrollY:z,nestedScrolledElements:Tn(a)});const y=Math.max(w,o.scrollWidth||0,p?.scrollWidth||0,Math.ceil(o.getBoundingClientRect().width||0)),b=Math.max(u,o.scrollHeight||0,p?.scrollHeight||0,Math.ceil(o.getBoundingClientRect().height||0)),G=Math.min(2,Math.max(1,window.devicePixelRatio||1)),H=o.style.scrollBehavior,$=p?.style.scrollBehavior??"";o.style.scrollBehavior="auto",p&&(p.style.scrollBehavior="auto");const V=zs(a);Qe("nested scroll snapshot",V.snapshot);let ne=()=>{},E=()=>{};try{await a.fonts?.ready.catch(()=>{}),ne=await En(a,w,u,{applyLayoutWorkarounds:!1}),s.scrollTo(re,z),E=Fs(a,re,z),V.reapply();const{snapdom:Q}=await Ee(async()=>{const{snapdom:x}=await import("./vendor-zumer-snapdom-Btyu_Xi2.js");return{snapdom:x}},[]),C={backgroundColor:kn(a),cache:"disabled",dpr:G,embedFonts:!0,fast:!1,height:b,outerShadows:!0,outerTransforms:!0,placeholders:!0,plugins:[Bs,Us],quality:.82,width:y},U=await(await Q(o,C)).toCanvas();if(!U.width||!U.height)return null;const L=U.width/Math.max(1,y),K=U.height/Math.max(1,b),se=Math.min(U.width,Math.max(1,Math.round(w*L))),he=Math.min(U.height,Math.max(1,Math.round(u*K))),ue=Math.max(0,U.width-se),be=Math.max(0,U.height-he),fe=Math.min(ue,Math.max(0,Math.round(re*L))),xe=Math.min(be,Math.max(0,Math.round(z*K)));Qe("capture geometry",{viewportWidth:w,viewportHeight:u,captureWidth:y,captureHeight:b,canvasWidth:U.width,canvasHeight:U.height,xScale:L,yScale:K,sourceX:fe,sourceY:xe,sourceWidth:se,sourceHeight:he});const pe=a.createElement("canvas");pe.width=se,pe.height=he;const I=pe.getContext("2d");if(!I)return null;I.drawImage(U,fe,xe,se,he,0,0,se,he);const W=await As(pe,.82);return W?await Nt(W,w,u,w,u,n):null}finally{E(),V.cleanup(),ne(),s.scrollTo(re,z),V.reapply(),o.style.scrollBehavior=H,p&&(p.style.scrollBehavior=$)}}catch(s){return console.warn("[preview] failed to capture iframe DOM screenshot with snapDOM:",s),null}}async function Vs(t,n){const s=await Hs(t,n);if(s)return s;try{const a=t.contentWindow,o=t.contentDocument??a?.document,m=o?.documentElement;if(!a||!o||!m)return null;const w=t.getBoundingClientRect(),u=Math.max(1,Math.ceil(a.innerWidth||t.clientWidth||w.width)),p=Math.max(1,Math.ceil(a.innerHeight||t.clientHeight||w.height)),g=a.scrollX||o.documentElement.scrollLeft||o.body?.scrollLeft||0,v=a.scrollY||o.documentElement.scrollTop||o.body?.scrollTop||0,f=o.body,l=Math.max(p,m.scrollHeight||0,f?.scrollHeight||0),T=Math.min(2,Math.max(1,window.devicePixelRatio||1)),c=m.style.scrollBehavior,S=f?.style.scrollBehavior??"";m.style.scrollBehavior="auto",f&&(f.style.scrollBehavior="auto");let j="",P=()=>{};try{await o.fonts?.ready.catch(()=>{}),P=await En(o,u,p,{applyLayoutWorkarounds:!0}),a.scrollTo(g,v);const{getFontEmbedCSS:O,toJpeg:te}=await Ee(async()=>{const{getFontEmbedCSS:re,toJpeg:z}=await import("./vendor-html-to-image-BeoRn2gJ.js");return{getFontEmbedCSS:re,toJpeg:z}},[]),F=await O(m).catch(()=>"");j=await te(m,{quality:.82,pixelRatio:T,width:u,height:p,backgroundColor:kn(o),imagePlaceholder:ze,fontEmbedCSS:F||void 0,style:{transform:`translate(${-g}px, ${-v}px)`,transformOrigin:"top left",minWidth:`${u}px`,minHeight:`${l}px`},cacheBust:!0})}finally{P(),a.scrollTo(g,v),m.style.scrollBehavior=c,f&&(f.style.scrollBehavior=S)}const R=j.split(",",2)[1]||"";return R?await Nt(R,u,p,u,p,n):null}catch(a){return console.warn("[preview] failed to capture iframe DOM screenshot:",a),null}}const Vt=200,Ks=(t,n)=>n==="all"?!0:n==="errors"?t.level==="error"||t.level==="runtime"||t.level==="resource":n==="warnings"?t.level==="warn":t.level==="log"||t.level==="info"||t.level==="debug",rt=t=>{const n=ot.getState();n.setPendingSyntheticParts([...n.pendingSyntheticParts??[],{text:t,synthetic:!0}])},Dn=async t=>{const n=await t.json().catch(()=>({}));if(!t.ok)return{ok:!1,message:typeof n.error=="string"?n.error:`HTTP ${t.status}`};const s=typeof n.proxyBasePath=="string"?n.proxyBasePath:"",a=typeof n.previewToken=="string"?n.previewToken:"";return!s||!a?{ok:!1,message:"Could not start preview proxy."}:{ok:!0,target:{proxyBasePath:s,previewToken:a,expiresAt:typeof n.expiresAt=="number"?n.expiresAt:0}}},An=t=>{if(typeof window>"u")return"";try{return new URL(t||window.location.href,window.location.href).origin}catch{return window.location.origin}},Kt=(t,n,s)=>{t.postMessage(s,An(n))},Xs=t=>{if(!t)return t;try{const n=new URL(t);return n.searchParams.delete("oc_preview_token"),n.searchParams.delete("oc_client_token"),n.searchParams.delete("oc_url_token"),n.toString()}catch{return t}},Xt=t=>{if(!t)return t;try{const n=new URL(t);return n.searchParams.delete("ocPreview"),n.searchParams.delete("oc_preview_token"),n.searchParams.delete("oc_client_token"),n.searchParams.delete("oc_url_token"),n.toString()}catch{return t}};function Mn(t){const[n,s]=r.useState("");return r.useEffect(()=>{if(!t){s("");return}let a=!1;return s(""),Bn(tn()).then(o=>{!a&&o&&s(t)}).catch(()=>{}),()=>{a=!0}},[t]),n}const In=`new Promise((resolve) => {
|
|
4
|
+
const existing = document.getElementById('__pichamber_desktop_browser_overlay');
|
|
5
|
+
if (existing) existing.remove();
|
|
6
|
+
if (typeof window.__pichamberDesktopBrowserCancelInspect === 'function') {
|
|
7
|
+
try { window.__pichamberDesktopBrowserCancelInspect(); } catch { /* webview not ready */ }
|
|
8
|
+
}
|
|
9
|
+
const overlay = document.createElement('div');
|
|
10
|
+
overlay.id = '__pichamber_desktop_browser_overlay';
|
|
11
|
+
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;';
|
|
12
|
+
document.documentElement.appendChild(overlay);
|
|
13
|
+
const cssEscape = (value) => {
|
|
14
|
+
try { return CSS.escape(value); } catch { return String(value).replace(/[^a-zA-Z0-9_-]/g, '\\\\$&'); }
|
|
15
|
+
};
|
|
16
|
+
const selectorPart = (element) => {
|
|
17
|
+
const tag = element.tagName.toLowerCase();
|
|
18
|
+
if (element.id) return tag + '#' + cssEscape(element.id);
|
|
19
|
+
const className = String(element.className || '').trim().split(/\\s+/).filter(Boolean).slice(0, 3).map((part) => '.' + cssEscape(part)).join('');
|
|
20
|
+
return tag + className;
|
|
21
|
+
};
|
|
22
|
+
const metadata = (element) => {
|
|
23
|
+
const rect = element.getBoundingClientRect();
|
|
24
|
+
const style = getComputedStyle(element);
|
|
25
|
+
const ancestry = [];
|
|
26
|
+
let current = element;
|
|
27
|
+
while (current && current.nodeType === Node.ELEMENT_NODE && ancestry.length < 8) {
|
|
28
|
+
ancestry.unshift({ tag: current.tagName.toLowerCase(), id: current.id || undefined, className: typeof current.className === 'string' ? current.className : undefined, selectorPart: selectorPart(current) });
|
|
29
|
+
current = current.parentElement;
|
|
30
|
+
}
|
|
31
|
+
const attrs = {};
|
|
32
|
+
for (const attr of Array.from(element.attributes || []).slice(0, 16)) attrs[attr.name] = attr.value.slice(0, 300);
|
|
33
|
+
const path = ancestry.map((entry) => entry.selectorPart).join(' > ');
|
|
34
|
+
return {
|
|
35
|
+
frame: 'top',
|
|
36
|
+
tag: element.tagName.toLowerCase(),
|
|
37
|
+
text: String(element.innerText || element.textContent || '').replace(/\\s+/g, ' ').trim().slice(0, 500),
|
|
38
|
+
selector: element.id ? '#' + cssEscape(element.id) : path,
|
|
39
|
+
path,
|
|
40
|
+
bounds: { x: rect.x, y: rect.y, width: rect.width, height: rect.height },
|
|
41
|
+
center: { x: rect.x + rect.width / 2, y: rect.y + rect.height / 2 },
|
|
42
|
+
attributes: attrs,
|
|
43
|
+
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 },
|
|
44
|
+
ancestry,
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
const move = (event) => {
|
|
48
|
+
const element = document.elementFromPoint(event.clientX, event.clientY);
|
|
49
|
+
if (!element || element === overlay || element === document.documentElement || element === document.body) return;
|
|
50
|
+
const rect = element.getBoundingClientRect();
|
|
51
|
+
overlay.style.display = 'block';
|
|
52
|
+
overlay.style.left = rect.left + 'px';
|
|
53
|
+
overlay.style.top = rect.top + 'px';
|
|
54
|
+
overlay.style.width = rect.width + 'px';
|
|
55
|
+
overlay.style.height = rect.height + 'px';
|
|
56
|
+
};
|
|
57
|
+
const cleanup = () => {
|
|
58
|
+
window.removeEventListener('mousemove', move, true);
|
|
59
|
+
window.removeEventListener('click', click, true);
|
|
60
|
+
window.removeEventListener('keydown', keydown, true);
|
|
61
|
+
if (window.__pichamberDesktopBrowserCancelInspect === cancel) {
|
|
62
|
+
delete window.__pichamberDesktopBrowserCancelInspect;
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
const cancel = () => {
|
|
66
|
+
cleanup();
|
|
67
|
+
overlay.remove();
|
|
68
|
+
resolve(null);
|
|
69
|
+
};
|
|
70
|
+
const click = (event) => {
|
|
71
|
+
event.preventDefault();
|
|
72
|
+
event.stopPropagation();
|
|
73
|
+
const element = document.elementFromPoint(event.clientX, event.clientY);
|
|
74
|
+
const result = element ? metadata(element) : null;
|
|
75
|
+
cleanup();
|
|
76
|
+
overlay.remove();
|
|
77
|
+
resolve(result);
|
|
78
|
+
};
|
|
79
|
+
const keydown = (event) => {
|
|
80
|
+
if (event.key !== 'Escape') return;
|
|
81
|
+
cancel();
|
|
82
|
+
};
|
|
83
|
+
window.__pichamberDesktopBrowserCancelInspect = cancel;
|
|
84
|
+
window.addEventListener('mousemove', move, true);
|
|
85
|
+
window.addEventListener('click', click, true);
|
|
86
|
+
window.addEventListener('keydown', keydown, true);
|
|
87
|
+
});`,Ze=`(() => {
|
|
88
|
+
if (typeof window.__pichamberDesktopBrowserCancelInspect === 'function') {
|
|
89
|
+
window.__pichamberDesktopBrowserCancelInspect();
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
const overlay = document.getElementById('__pichamber_desktop_browser_overlay');
|
|
93
|
+
if (overlay) overlay.remove();
|
|
94
|
+
})()`,qs=`(() => {
|
|
95
|
+
if (window.__pichamberSameWebviewNavigationInstalled) return;
|
|
96
|
+
window.__pichamberSameWebviewNavigationInstalled = true;
|
|
97
|
+
|
|
98
|
+
const navigate = (rawUrl) => {
|
|
99
|
+
if (typeof rawUrl !== 'string' || rawUrl.length === 0) return false;
|
|
100
|
+
try {
|
|
101
|
+
const url = new URL(rawUrl, window.location.href);
|
|
102
|
+
if (url.protocol !== 'http:' && url.protocol !== 'https:') return false;
|
|
103
|
+
window.location.assign(url.href);
|
|
104
|
+
return true;
|
|
105
|
+
} catch (_error) {
|
|
106
|
+
return false;
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
const originalOpen = window.open.bind(window);
|
|
111
|
+
window.open = (url, target, features) => {
|
|
112
|
+
if (navigate(url)) return null;
|
|
113
|
+
return originalOpen(url, target, features);
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
document.addEventListener('click', (event) => {
|
|
117
|
+
if (event.defaultPrevented) return;
|
|
118
|
+
const target = event.target;
|
|
119
|
+
if (!(target instanceof Element)) return;
|
|
120
|
+
const anchor = target.closest('a[target="_blank"][href]');
|
|
121
|
+
if (!(anchor instanceof HTMLAnchorElement)) return;
|
|
122
|
+
if (!navigate(anchor.href)) return;
|
|
123
|
+
event.preventDefault();
|
|
124
|
+
event.stopPropagation();
|
|
125
|
+
}, true);
|
|
126
|
+
})()`,qe=t=>{const n=t.trim();if(!n)return"about:blank";try{const s=new URL(n.includes("://")?n:`https://${n}`);return s.protocol!=="http:"&&s.protocol!=="https:"?"about:blank":s.toString()}catch{return"about:blank"}},qt=async(t,n)=>{const s=t.contentWindow;if(!s)throw new Error("Iframe window is not available");const o=s.eval.call(s,n);return await Promise.resolve(o)},Gs=()=>typeof window<"u"&&!!window.__PICHAMBER_ELECTRON__,Ys=({initialUrl:t,directory:n,tabID:s})=>{const a=r.useRef(null),o=ee(I=>I.setContextPanelTabTargetPath),m=qe(t),w=m!=="about:blank"?m:"",[u,p]=r.useState(w),[g,v]=r.useState(w),[f,l]=r.useState(w),[T,c]=r.useState(()=>w?[w]:[]),[S,j]=r.useState(()=>w?0:-1),[P,R]=r.useReducer(I=>I+1,0),[O,te]=r.useState(!!w),[F,re]=r.useState(!1),[z,y]=r.useState(null),[b,G]=r.useState({status:"idle"}),H=Se(I=>I.currentSessionId),$=Se(I=>I.newSessionDraft?.open),V=ot(I=>I.addAttachedFile),ne=r.useCallback(I=>{!I||I==="about:blank"||!n||!s||o(n,s,I)},[n,s,o]),E=r.useCallback((I,W)=>{const x=qe(I),A=x!=="about:blank"?x:"";v(A),p(A),W?.inFrame?te(!1):(l(A),te(!!A)),ne(A),c(X=>{if(!A)return j(-1),[];if(W?.replaceHistory)return X;const de=S>=0?X.slice(0,S+1):[];if(de[de.length-1]===A)return j(de.length-1),de;const we=[...de,A];return j(we.length-1),we})},[S,ne]),Q=r.useCallback(I=>{const W=T[I];W&&(j(I),v(W),l(W),p(W),te(!0),ne(W))},[T,ne]),C=r.useCallback(()=>{if(g){te(!0);try{a.current?.contentWindow?.location.reload()}catch{R()}}},[g]);r.useEffect(()=>{if(!f){G({status:"idle"});return}const I=Ds(f),W=kt(I);if(W?.previewToken){G({status:"ready",proxyBasePath:W.proxyBasePath,previewToken:W.previewToken,expiresAt:W.expiresAt});return}W&&Pe.delete(I);let x=!1;return G({status:"loading"}),te(!0),(async()=>{try{const A=await tt("/api/preview/targets",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({url:f,allowExternal:!0})}),X=await Dn(A);if(!X.ok){x||G({status:"error",message:X.message});return}Pe.set(I,X.target),x||G({status:"ready",...X.target})}catch(A){if(!x){const X=A instanceof Error?A.message:String(A);G({status:"error",message:X})}}})(),()=>{x=!0}},[f]);const M=f&&b.status==="ready"?`${b.proxyBasePath}|${b.previewToken||""}|${P}`:"",U=Mn(M),L=r.useMemo(()=>{if(U!==M||!f||b.status!=="ready")return"";try{const I=new URL(f),W=I.pathname||"/",x=new URLSearchParams(I.search);x.delete("oc_url_token"),x.delete("oc_client_token"),x.set("ocPreview",String(P)),x.set("oc_preview_token",b.previewToken||"");const A=x.toString();return nn().authenticatedAsset(`${b.proxyBasePath}${W}${A?`?${A}`:""}${I.hash}`)}catch{return""}},[f,b,M,P,U]),K=L||(b.status==="error"?f:""),se=r.useCallback(I=>{if(!I||!f||b.status!=="ready")return"";try{const W=new URL(I,window.location.origin),x=b.proxyBasePath.endsWith("/")?b.proxyBasePath.slice(0,-1):b.proxyBasePath;if(W.origin!==window.location.origin||!W.pathname.startsWith(x))return"";const A=W.pathname.slice(x.length)||"/",X=new URL(f).origin;return Xt(new URL(`${A}${W.search}${W.hash}`,X).toString())}catch{return""}},[f,b]),he=r.useCallback(I=>{if(!I||!f||b.status!=="ready")return"";try{const W=new URL(I,window.location.origin),x=new URL(f).origin;if(W.origin!==window.location.origin||x===window.location.origin)return"";const A=b.proxyBasePath.endsWith("/")?b.proxyBasePath.slice(0,-1):b.proxyBasePath;return W.pathname.startsWith(A)?"":Xt(new URL(`${W.pathname}${W.search}${W.hash}`,x).toString())}catch{return""}},[f,b]),ue=r.useCallback(I=>{const W=a.current?.contentWindow;W&&W.postMessage({source:"pichamber-preview-parent",version:1,type:"set-inspect-mode",enabled:I},window.location.origin)},[]),be=r.useCallback(async I=>{if(!(H??($?"draft":null))){je.error("Open a chat session before attaching preview annotations");return}const x=a.current,A=x?.contentWindow,X=x?.getBoundingClientRect(),de={width:Number.isFinite(A?.innerWidth)?A?.innerWidth??X?.width??0:X?.width??0,height:Number.isFinite(A?.innerHeight)?A?.innerHeight??X?.height??0:X?.height??0},me=x?await _n(x,I):null,we=!!me;me&&await V(me),rt(Ct({pageUrl:g,viewport:de,devicePixelRatio:window.devicePixelRatio||1,target:I,screenshotAttached:we,intro:we?"This is a selected DOM element from the in-app preview. A screenshot of the visible preview area with the selected element highlighted is attached.":"This is a selected DOM element from the in-app preview."})),je.success("Preview annotation attached to chat")},[V,H,g,$]),fe=r.useCallback(()=>{const I=a.current;y(null),ue(!1),I&&qt(I,Ze).catch(()=>{})},[ue]);r.useEffect(()=>{if(!F)return;const I=W=>{W.key==="Escape"&&(W.preventDefault(),W.stopImmediatePropagation(),re(!1),fe())};return window.addEventListener("keydown",I,!0),()=>window.removeEventListener("keydown",I,!0)},[fe,F]),r.useEffect(()=>()=>fe(),[fe]),r.useEffect(()=>{const I=W=>{if(W.source!==a.current?.contentWindow)return;const x=W.data;if(!(!x||x.source!=="pichamber-preview-bridge"||x.version!==1)){if(x.type==="ready"){const A=typeof x.url=="string"?x.url:"",X=se(A);X&&X!==g&&E(X,{inFrame:!0});return}if(x.type==="hover"){y(Be(x.target)?x.target:null);return}if(x.type==="select"&&Be(x.target)){y(null),re(!1),ue(!1),be(x.target);return}if(x.type==="navigate-preview"){const A=typeof x.url=="string"?x.url:"",X=he(A);if(X){E(X);return}A&&E(A)}}};return window.addEventListener("message",I),()=>window.removeEventListener("message",I)},[E,be,g,se,he,ue]);const xe=r.useCallback(()=>{const I=a.current;if(!(!I||!g)){if(F){re(!1),fe();return}if(L){y(null),re(!0),ue(!0);return}re(!0),(async()=>{try{const W=await qt(I,In);if(re(!1),!W||!Be(W))return;await be(W)}catch{re(!1),je.error("This page cannot be inspected from the browser panel.")}})()}},[be,fe,g,F,ue,L]),pe=r.useCallback(()=>{try{const I=a.current?.contentWindow?.location.href||"",W=he(I);if(W){E(W,{inFrame:!0});return}}catch{}te(!1),F&&L&&ue(!0)},[E,he,F,ue,L]);return e.jsxs("div",{className:"absolute inset-0 flex flex-col bg-background",children:[e.jsxs("div",{className:"flex items-center gap-1 border-b border-border bg-[var(--surface-background)] px-2 py-1",children:[e.jsx(ge,{type:"button",variant:"ghost",size:"sm",className:"h-7 w-7 p-0",disabled:S<=0,onClick:()=>Q(S-1),children:e.jsx(q,{name:"arrow-left",className:"h-3.5 w-3.5"})}),e.jsx(ge,{type:"button",variant:"ghost",size:"sm",className:"h-7 w-7 p-0",disabled:S<0||S>=T.length-1,onClick:()=>Q(S+1),children:e.jsx(q,{name:"arrow-right",className:"h-3.5 w-3.5"})}),e.jsx(ge,{type:"button",variant:"ghost",size:"sm",className:"h-7 w-7 p-0",disabled:!g,onClick:C,children:e.jsx(q,{name:"refresh",className:"h-3.5 w-3.5"})}),e.jsx("form",{className:"min-w-0 flex-1",onSubmit:I=>{I.preventDefault(),E(u)},children:e.jsx("input",{value:u,onChange:I=>p(I.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":"Browser address"})}),e.jsx(ge,{type:"button",variant:F?"secondary":"ghost",size:"sm",className:"h-7 w-7 p-0",disabled:!g,onClick:xe,title:"Inspect preview element","aria-label":"Inspect preview element",children:e.jsx(q,{name:"cursor",className:"h-3.5 w-3.5"})}),e.jsx(ge,{type:"button",variant:"ghost",size:"sm",className:"h-7 w-7 p-0",disabled:!g,onClick:()=>{nt(g)},children:e.jsx(q,{name:"external-link",className:"h-3.5 w-3.5"})})]}),e.jsxs("div",{className:"relative min-h-0 flex-1 bg-background",children:[K?e.jsxs("div",{className:"absolute inset-0",children:[e.jsx("iframe",{ref:a,src:K,title:"Web browser",className:"absolute inset-0 h-full w-full border-0 bg-background",allow:"clipboard-read; clipboard-write; fullscreen",allowFullScreen:!0,onLoad:pe},`${s}:${P}`),F&&z?e.jsx("div",{className:"pointer-events-none absolute rounded-sm border-2 border-[var(--interactive-focus-ring)] bg-[var(--interactive-focus-ring)]/35",style:{left:z.bounds.x,top:z.bounds.y,width:z.bounds.width,height:z.bounds.height},children:e.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:[z.tag,z.text?` · ${z.text}`:""]})}):null]}):e.jsxs("div",{className:"absolute inset-0 flex flex-col items-center justify-center gap-6 bg-background p-6 text-center",children:[e.jsx(ln,{width:140,height:140,className:"opacity-20"}),e.jsx("span",{className:"typography-ui-header text-muted-foreground",children:"Web browser"}),e.jsx("span",{className:"max-w-sm typography-micro text-muted-foreground",children:"Enter an address above to start browsing the web"}),e.jsx("span",{className:"max-w-md typography-micro leading-relaxed text-status-warning/70",children:"Pages opened here run with full access to PiChamber — needed for inspect and screenshots. Only open sites you trust: a malicious page could read your data or act on your behalf."})]}),O?e.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-background/70 typography-micro text-muted-foreground",children:"Loading..."}):null]})]})},Js=({initialUrl:t,directory:n,tabID:s})=>{const a=r.useRef(null),o=ee(y=>y.setContextPanelTabTargetPath),m=qe(t),w=m!=="about:blank"?m:"",u=r.useRef(qe(t)),[p,g]=r.useState(w),[v,f]=r.useState(w),[l,T]=r.useState(!1),[c,S]=r.useState(!0),j=r.useRef(null),P=c,R=r.useCallback(y=>{!y||y==="about:blank"||!n||!s||o(n,s,y)},[n,s,o]),O=Se(y=>y.currentSessionId),te=Se(y=>y.newSessionDraft?.open),F=ot(y=>y.addAttachedFile);r.useEffect(()=>{const y=a.current;if(!y)return;const b=()=>{try{const E=y.getURL();E&&E!=="about:blank"&&(f(E),g(E),R(E))}catch{}},G=E=>{const Q=E.detail;typeof Q?.url=="string"&&Q.url&&(f(Q.url),g(Q.url),R(Q.url))},H=()=>{j.current&&clearTimeout(j.current),j.current=setTimeout(()=>S(!0),200)},$=()=>{j.current&&clearTimeout(j.current),S(!1),b()},V=E=>{const Q=E.detail;if(Q?.disposition==="new-window"||Q?.disposition==="foreground-tab"||Q?.disposition==="background-tab"){E.preventDefault();const C=a.current;typeof C?.loadURL=="function"&&Q.url&&C.loadURL(Q.url)}},ne=()=>{try{y.executeJavaScript?.(qs,!0).catch(()=>{})}catch{}};y.addEventListener("did-navigate",G),y.addEventListener("did-navigate-in-page",G),y.addEventListener("did-start-loading",H),y.addEventListener("did-stop-loading",$),y.addEventListener("new-window",V),y.addEventListener("dom-ready",ne);try{y.isLoading()||(S(!1),b())}catch{}return ne(),()=>{j.current&&clearTimeout(j.current),y.removeEventListener("did-navigate",G),y.removeEventListener("did-navigate-in-page",G),y.removeEventListener("did-start-loading",H),y.removeEventListener("did-stop-loading",$),y.removeEventListener("new-window",V),y.removeEventListener("dom-ready",ne)}},[R]),r.useEffect(()=>{const y=setTimeout(()=>S(!1),3e4);return()=>clearTimeout(y)},[]),r.useEffect(()=>{if(!l)return;const y=b=>{if(b.key!=="Escape")return;b.preventDefault(),b.stopImmediatePropagation(),T(!1);const G=a.current;try{G?.executeJavaScript?.(Ze).catch(()=>{})}catch{}};return window.addEventListener("keydown",y,!0),()=>window.removeEventListener("keydown",y,!0)},[l]),r.useEffect(()=>{const y=a.current;return()=>{try{const b=y?.getURL?.();b&&b!=="about:blank"&&o(n,s,b)}catch{}try{y?.executeJavaScript?.(Ze).catch(()=>{})}catch{}}},[n,s,o]);const re=r.useCallback(y=>{const b=a.current;if(typeof b?.loadURL!="function")return;const G=qe(y);try{b.loadURL(G)}catch{}},[]),z=r.useCallback(()=>{const y=a.current;if(y){if(l){T(!1);try{y.executeJavaScript?.(Ze).catch(()=>{})}catch{}return}T(!0),y.executeJavaScript?.(In,!0).then(async b=>{if(T(!1),!b||!Be(b))return;if(!(O??(te?"draft":null))){je.error("Open a chat session before attaching preview annotations");return}const H=typeof y.getWebContentsId=="function"?y.getWebContentsId():null;if(H==null)return;const $=await kr("desktop_browser_capture_page",{webContentsId:H}),V=await y.executeJavaScript?.("({ width: window.innerWidth, height: window.innerHeight })",!0).catch(()=>null),ne=Number.isFinite(V?.width)?V.width:$.width,E=Number.isFinite(V?.height)?V.height:$.height,Q=await Nt($.base64,$.width,$.height,ne,E,b),C=!!Q;Q&&await F(Q),rt(Ct({pageUrl:v,viewport:{width:ne,height:E},devicePixelRatio:window.devicePixelRatio||1,target:b,screenshotAttached:C,intro:"This is a selected DOM element from the in-app preview. A screenshot of the visible preview area with the selected element highlighted is attached."})),je.success("Preview annotation attached to chat")}).catch(()=>T(!1))}},[F,O,v,l,te]);return e.jsxs("div",{className:"absolute inset-0 flex flex-col bg-background",children:[e.jsxs("div",{className:"flex items-center gap-1 border-b border-border bg-[var(--surface-background)] px-2 py-1",children:[e.jsx(ge,{type:"button",variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:()=>{try{a.current?.goBack?.()}catch{}},children:e.jsx(q,{name:"arrow-left",className:"h-3.5 w-3.5"})}),e.jsx(ge,{type:"button",variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:()=>{try{a.current?.goForward?.()}catch{}},children:e.jsx(q,{name:"arrow-right",className:"h-3.5 w-3.5"})}),e.jsx(ge,{type:"button",variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:()=>{try{a.current?.reload?.()}catch{}},children:e.jsx(q,{name:"refresh",className:"h-3.5 w-3.5"})}),e.jsx("form",{className:"min-w-0 flex-1",onSubmit:y=>{y.preventDefault(),re(p)},children:e.jsx("input",{value:p,onChange:y=>g(y.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":"Browser address"})}),e.jsx(ge,{type:"button",variant:l?"secondary":"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:z,title:"Inspect preview element","aria-label":"Inspect preview element",children:e.jsx(q,{name:"cursor",className:"h-3.5 w-3.5"})}),e.jsx(ge,{type:"button",variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:()=>{nt(v)},children:e.jsx(q,{name:"external-link",className:"h-3.5 w-3.5"})})]}),e.jsxs("div",{className:"relative min-h-0 flex-1 bg-background",children:[e.jsx("webview",{ref:a,src:u.current,partition:"persist:pichamber-browser",allowpopups:!0,style:{width:"100%",height:"100%",border:"none"}}),(!v||v==="about:blank")&&!c?e.jsxs("div",{className:"absolute inset-0 flex flex-col items-center justify-center gap-6 bg-background p-6 text-center",children:[e.jsx(ln,{width:140,height:140,className:"opacity-20"}),e.jsx("span",{className:"typography-ui-header text-muted-foreground",children:"Web browser"})]}):null,P?e.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-background/70 typography-micro text-muted-foreground",children:"Loading..."}):null]})]})},Qs=t=>{const n=Gs()?Js:Ys;return e.jsx(n,{...t})},Zs=8,_e=new Map,Pt=t=>JSON.stringify([zn(),t]),Gt=t=>{const n=Pt(t),s=_e.get(n);return s?(s.touchedAt=Date.now(),_e.delete(n),_e.set(n,s),s):null},ct=t=>{const n=Pt(t),s=_e.get(n);if(s)return s.touchedAt=Date.now(),s;if(_e.size>=Zs){const o=_e.keys().next().value;o!==void 0&&_e.delete(o)}const a={childrenByDir:{},loadErrorsByDir:{},loadedDirs:new Set,touchedAt:Date.now()};return _e.set(n,a),a},eo=t=>{_e.delete(Pt(t))},Ln=(t,n)=>e.jsx(mt,{filePath:t,extension:n}),to=({status:t})=>{const n={open:"var(--status-info)",modified:"var(--status-warning)","git-modified":"var(--status-warning)","git-added":"var(--status-success)","git-deleted":"var(--status-error)"}[t];return e.jsx("span",{className:"h-2 w-2 rounded-full",style:{backgroundColor:n}})},no=({node:t,root:n,isExpanded:s,isActive:a,isBrowserClient:o,status:m,badge:w,permissions:u,downloadFile:p,onSelect:g,onToggle:v,onRevealPath:f,onOpenDialog:l})=>{const T=t.type==="directory",{canRename:c,canCreateFile:S,canCreateFolder:j,canDelete:P,canReveal:R}=u,O=!T&&!!p,te=R&&!o,F=c||S||j||P||O||te,[re,z]=r.useState(!1),[y,b]=r.useState(!1),G=r.useCallback(E=>{F&&(E?.preventDefault(),b(!0))},[F]),H=r.useCallback(()=>{T?v(t.path):g(t)},[T,t,g,v]),$=r.useCallback(E=>{E.stopPropagation(),b(!1),z(!0)},[]),V=({Item:E,Separator:Q})=>e.jsxs(e.Fragment,{children:[c&&e.jsxs(E,{onClick:C=>{C.stopPropagation(),l("rename",t)},children:[e.jsx(q,{name:"edit",className:"mr-2 h-4 w-4"})," ","Rename"]}),e.jsxs(E,{onClick:C=>{C.stopPropagation(),gt(t.path).then(M=>{if(M.ok){je.success("Path copied");return}je.error("Copy failed")})},children:[e.jsx(q,{name:"file-copy",className:"mr-2 h-4 w-4"})," ","Copy Path"]}),!T&&p&&e.jsxs(E,{onClick:C=>{C.stopPropagation(),p(t.path).catch(M=>{console.error("Download failed:",M),je.error("Operation failed")})},children:[e.jsx(q,{name:"download",className:"mr-2 h-4 w-4"})," ",o?"Download":"Save"]}),te&&e.jsxs(E,{onClick:C=>{C.stopPropagation(),f(t.path)},children:[e.jsx(q,{name:"folder-received",className:"mr-2 h-4 w-4"})," ",Un()]}),T&&(S||j)&&e.jsxs(e.Fragment,{children:[e.jsx(Q,{}),S&&e.jsxs(E,{onClick:C=>{C.stopPropagation(),l("createFile",t)},children:[e.jsx(q,{name:"file-add",className:"mr-2 h-4 w-4"})," ","New File"]}),j&&e.jsxs(E,{onClick:C=>{C.stopPropagation(),l("createFolder",t)},children:[e.jsx(q,{name:"folder-add",className:"mr-2 h-4 w-4"})," ","New Folder"]})]}),P&&e.jsxs(e.Fragment,{children:[e.jsx(Q,{}),e.jsxs(E,{onClick:C=>{C.stopPropagation(),l("delete",t)},className:"text-destructive focus:text-destructive",children:[e.jsx(q,{name:"delete-bin",className:"mr-2 h-4 w-4"})," ","Delete"]})]})]}),ne=r.useCallback(E=>{const Q=xn(n,t.path);Q&&(E.dataTransfer.setData("application/x-pichamber-file-path",Q),E.dataTransfer.effectAllowed="copy")},[t.path,n]);return e.jsxs(lr,{open:y,onOpenChange:b,children:[e.jsxs(cr,{render:e.jsx("div",{className:"group relative flex items-center",onContextMenu:G}),children:[e.jsxs("button",{type:"button",onClick:H,onContextMenu:G,draggable:!0,onDragStart:ne,className:ce("flex w-full items-center gap-1.5 rounded-md px-2 py-1 text-left text-foreground transition-colors pr-8 select-none",a?"bg-interactive-selection/70":"hover:bg-interactive-hover/40","cursor-grab active:cursor-grabbing"),children:[T?s?e.jsx(q,{name:"folder-open",className:"h-4 w-4 flex-shrink-0 text-muted-foreground"}):e.jsx(q,{name:"folder-3",className:"h-4 w-4 flex-shrink-0 text-muted-foreground"}):Ln(t.path,t.extension),e.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta",title:t.path,children:t.name}),!T&&m&&e.jsx(to,{status:m}),T&&w&&e.jsxs("span",{className:"text-xs flex items-center gap-1 ml-auto mr-1",children:[w.modified>0&&e.jsxs("span",{className:"text-[var(--status-warning)]",children:["M",w.modified]}),w.added>0&&e.jsxs("span",{className:"text-[var(--status-success)]",children:["+",w.added]})]})]}),F&&e.jsx("div",{className:"absolute right-1 top-1/2 -translate-y-1/2 opacity-0 focus-within:opacity-100 group-hover:opacity-100",children:e.jsxs(Nr,{open:re,onOpenChange:z,children:[e.jsxs(Oe,{children:[e.jsx($e,{asChild:!0,children:e.jsx("span",{className:"inline-flex",children:e.jsx(Pr,{asChild:!0,children:e.jsx(ge,{variant:"ghost",size:"icon",className:"h-6 w-6",onClick:$,title:"File menu","aria-label":"File menu",children:e.jsx(q,{name:"more-2-fill",className:"h-4 w-4"})})})})}),e.jsx(We,{side:"bottom",sideOffset:6,children:"File menu"})]}),e.jsx(Rr,{align:"end",side:"bottom",onCloseAutoFocus:()=>z(!1),children:V({Item:Er,Separator:Tr})})]})})]}),e.jsx(dr,{className:"min-w-[180px]",children:V({Item:ur,Separator:hr})})]})},ro=(t,n)=>t.node===n.node&&t.root===n.root&&t.isExpanded===n.isExpanded&&t.isActive===n.isActive&&t.isBrowserClient===n.isBrowserClient&&t.status===n.status&&t.badge===n.badge&&t.permissions===n.permissions&&t.downloadFile===n.downloadFile&&t.onSelect===n.onSelect&&t.onToggle===n.onToggle&&t.onRevealPath===n.onRevealPath&&t.onOpenDialog===n.onOpenDialog,so=r.memo(no,ro),oo=()=>{const{files:t,runtime:n}=xt(),s=Hn(n.platform),a=Ge()??"",o=Re(a.trim()),m=Vn(),w=Kn(),u=ee(i=>i.openContextFile),p=cn(a),[g,v]=r.useState(""),f=r.useRef(null),{results:l,searching:T}=hs({directory:a,query:g,chrome:"desktop",showHidden:m,showGitignored:w}),[c,S]=r.useState({}),[j,P]=r.useState({}),R=r.useRef(new Set),O=r.useRef(new Set),te=r.useRef(null);r.useEffect(()=>{if(!o){S({}),P({}),R.current=new Set;return}const i=Gt(o);i?(S({...i.childrenByDir}),P({...i.loadErrorsByDir}),R.current=new Set(i.loadedDirs)):(S({}),P({}),R.current=new Set)},[o]),r.useEffect(()=>{if(!o)return;const i=ct(o);i.childrenByDir=c},[o,c]),r.useEffect(()=>{if(!o)return;const i=ct(o);i.loadErrorsByDir=j},[o,j]),r.useEffect(()=>{if(!o)return;const i=ct(o);i.loadedDirs=new Set(R.current)},[o,c,j]),r.useEffect(()=>()=>{if(!o)return;const i=Gt(o);i&&i.loadedDirs.size===0&&Object.keys(i.childrenByDir).length===0&&eo(o)},[o]);const F=r.useMemo(()=>[],[]),re=r.useMemo(()=>[],[]),z=Te(i=>o?i.byRoot[o]?.expandedPaths??F:F),y=Te(i=>o?i.byRoot[o]?.selectedPath??null:null),b=Te(i=>i.setSelectedPath),G=Te(i=>i.addOpenPath),H=Te(i=>i.removeOpenPathsByPrefix),$=Te(i=>i.toggleExpandedPath),V=Te(i=>i.collapseAllExpandedPaths),ne=ee(i=>o?i.contextPanelByDirectory[o]?.tabs??re:re),E=r.useMemo(()=>new Set(ne.map(i=>i.mode==="file"?i.targetPath:null).filter(i=>typeof i=="string"&&i.length>0).map(i=>Re(i))),[ne]),Q=r.useCallback(i=>{t.revealPath&&t.revealPath(i).catch(()=>{je.error("Failed to reveal path")})},[t]),C=r.useCallback((i,D)=>{const d=D.filter(N=>N&&typeof N.name=="string"&&N.name.length>0).filter(N=>m||!N.name.startsWith(".")).filter(N=>w||!ps(N.name)).map(N=>{const le=N.name,Z=Re(N.path||""),ye=Z?fs(Z)?Z:Re(`${i}/${Z}`):Re(`${i}/${le}`),ve=N.isDirectory?"directory":"file",Le=ve==="file"&&le.includes(".")?le.split(".").pop()?.toLowerCase():void 0;return{name:le,path:ye,type:ve,extension:Le}});return ms(d)},[w,m]),M=r.useCallback(async(i,D)=>{const d=Re(i.trim());if(!d||R.current.has(d)||O.current.has(d))return;O.current=new Set(O.current),O.current.add(d);const N=t.listDirectory?t.listDirectory(d).then(le=>le.entries.map(Z=>({name:Z.name,path:Z.path,isDirectory:Z.isDirectory}))):Xn(d).then(le=>le.map(Z=>({name:Z.name,path:Z.path,isDirectory:Z.isDirectory})));try{const le=await N;if(D?.())return;const Z=C(d,le);R.current=new Set(R.current),R.current.add(d),P(ye=>{if(!ye[d])return ye;const ve={...ye};return delete ve[d],ve}),S(ye=>({...ye,[d]:Z}))}catch(le){if(D?.())return;const Z=le instanceof Error?le.message:String(le??"");console.error("Failed to load sidebar directory:",le),P(ye=>({...ye,[d]:Z}))}finally{O.current=new Set(O.current),O.current.delete(d)}},[t,C]),U=r.useCallback(async()=>{if(!o)return;te.current?.abort();const i=new AbortController;te.current=i;try{const d=(Te.getState().byRoot[o]?.expandedPaths??[]).map(Z=>Re(Z)).filter(Z=>!!Z&&Z!==o&&Z.startsWith(`${o}/`)),N=[o,...d];R.current=new Set(R.current);for(const Z of N)R.current.delete(Z);P(Z=>{if(Object.keys(Z).length===0)return Z;const ye={...Z};let ve=!1;for(const Le of N)Le in ye&&(delete ye[Le],ve=!0);return ve?ye:Z});const le=()=>i.signal.aborted;await M(o,le);for(let Z=0;Z<d.length&&!i.signal.aborted;Z+=3){const ye=d.slice(Z,Z+3);await Promise.all(ye.map(ve=>M(ve,le)))}}catch(D){if(i.signal.aborted)return;console.error("Failed to refresh sidebar tree:",D)}finally{te.current===i&&(te.current=null)}},[M,o]),L=r.useCallback(async i=>{if(!i){await U();return}const D=Re(i);R.current=new Set(R.current),R.current.delete(D),O.current=new Set(O.current),O.current.delete(D),await M(D)},[M,U]),K=r.useCallback(()=>{o&&b(o,null)},[o,b]),{operation:se,target:he,inputValue:ue,setInputValue:be,submitting:fe,inputRef:xe,open:pe,close:I,submit:W,capabilities:{canCreateFile:x,canCreateFolder:A,canRename:X,canDelete:de}}=gs({files:t,root:o,selectedPath:y??"",refreshDirectory:L,removeOpenPathsByPrefix:H,clearSelectedPath:K}),me=!!t.revealPath,we=r.useMemo(()=>({canRename:X,canCreateFile:x,canCreateFolder:A,canDelete:de,canReveal:me}),[X,x,A,de,me]);r.useEffect(()=>{o&&(te.current?.abort(),R.current=new Set,O.current=new Set,P({}),S(i=>Object.keys(i).length===0?i:{}),M(o))},[M,o,m,w]),r.useEffect(()=>{if(!o||z.length===0)return;const i=z.map(N=>Re(N)).filter(N=>!!N&&N!==o&&N.startsWith(`${o}/`)&&!R.current.has(N)&&!O.current.has(N)).sort((N,le)=>N.split("/").length-le.split("/").length);if(i.length===0)return;let D=!1;const d=()=>D;return(async()=>{for(let N=0;N<i.length&&!D;N+=3){const le=i.slice(N,N+3);await Promise.all(le.map(Z=>M(Z,d)))}})(),()=>{D=!0}},[z,M,o]);const k=r.useMemo(()=>{const i=new Map;if(!p?.files)return i;for(const D of p.files)D.index==="A"||D.working_dir==="?"?i.set(D.path,"git-added"):D.index==="D"?i.set(D.path,"git-deleted"):(D.index==="M"||D.working_dir==="M")&&i.set(D.path,"git-modified");return i},[p]),Y=r.useMemo(()=>{const i=new Map;if(!p?.files||!o)return i;for(const D of p.files){const d=D.index==="M"||D.working_dir==="M",N=D.index==="A"||D.working_dir==="?";if(!d&&!N)continue;const le=D.path.split("/");if(le.length<=1)continue;let Z=o;for(let ye=0;ye<le.length-1;ye++){Z=`${Z}/${le[ye]}`;let ve=i.get(Z);ve||(ve={modified:0,added:0},i.set(Z,ve)),d&&ve.modified++,N&&ve.added++}}return i},[p,o]),ie=r.useCallback(i=>{if(E.has(i))return"open";if(k.size===0)return null;const D=i.startsWith(o+"/")?i.slice(o.length+1):i;return k.get(D)??null},[E,k,o]),_=r.useCallback(i=>{if(Y.size===0)return null;const D=Y.get(i);return D&&D.modified+D.added>0?D:null},[Y]),oe=r.useCallback(async i=>{if(!o)return;const D=await mn(t,i.path,{directory:o});if(!D.ok){je.error(gn(D.reason));return}b(o,i.path),G(o,i.path),u(o,i.path)},[G,t,u,o,b]),ae=r.useCallback(async i=>{const D=Re(i);o&&($(o,D),R.current.has(D)||await M(D))},[M,o,$]);function J(i,D){const d=c[i]??[];return d.map((N,le)=>{const Z=N.type==="directory",ye=Z&&z.includes(N.path),ve=y===N.path,Le=le===d.length-1;return e.jsxs("li",{className:"relative",children:[D>0&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"absolute top-3.5 left-[-12px] w-3 h-px bg-border/40"}),Le&&e.jsx("span",{className:"absolute top-3.5 bottom-0 left-[-13px] w-[2px] bg-sidebar/50"})]}),e.jsx(so,{node:N,root:o,isExpanded:ye,isActive:ve,isBrowserClient:s,status:Z?void 0:ie(N.path),badge:Z?_(N.path):void 0,permissions:we,downloadFile:t.downloadFile,onSelect:oe,onToggle:ae,onRevealPath:Q,onOpenDialog:pe}),Z&&ye&&e.jsxs("ul",{className:"flex flex-col gap-1 ml-3 pl-3 border-l border-border/40 relative",children:[j[N.path]?e.jsxs("li",{className:"flex items-center gap-2 px-2 py-1 typography-meta text-muted-foreground",children:[e.jsx("span",{className:"min-w-0 flex-1 truncate text-[var(--status-error)]",title:j[N.path],children:j[N.path]}),e.jsxs(ge,{variant:"ghost",size:"xs",className:"h-6 gap-1",onClick:()=>{L(N.path)},children:[e.jsx(q,{name:"refresh",className:"h-3.5 w-3.5"}),"Refresh"]})]}):null,J(N.path,D+1)]})]},N.path)})}const B=!!(o&&c[o]),h=o?j[o]:null;return e.jsxs("section",{className:"flex h-full min-h-0 flex-col overflow-hidden",children:[e.jsxs("div",{className:"flex flex-col gap-2 border-b border-border/40 px-3 py-2",children:[e.jsxs("div",{className:"flex items-center justify-end gap-2",children:[x&&e.jsxs(Oe,{children:[e.jsx($e,{asChild:!0,children:e.jsx("span",{className:"inline-flex flex-shrink-0",children:e.jsx(ge,{variant:"ghost",size:"sm",onClick:()=>pe("createFile",{path:a,type:"directory"}),className:"h-8 w-8 p-0 flex-shrink-0",title:"New File","aria-label":"New File",children:e.jsx(q,{name:"file-add",className:"h-4 w-4"})})})}),e.jsx(We,{side:"bottom",sideOffset:6,children:"New File"})]}),A&&e.jsxs(Oe,{children:[e.jsx($e,{asChild:!0,children:e.jsx("span",{className:"inline-flex flex-shrink-0",children:e.jsx(ge,{variant:"ghost",size:"sm",onClick:()=>pe("createFolder",{path:a,type:"directory"}),className:"h-8 w-8 p-0 flex-shrink-0",title:"New Folder","aria-label":"New Folder",children:e.jsx(q,{name:"folder-add",className:"h-4 w-4"})})})}),e.jsx(We,{side:"bottom",sideOffset:6,children:"New Folder"})]}),e.jsxs(Oe,{children:[e.jsx($e,{asChild:!0,children:e.jsx("span",{className:"inline-flex flex-shrink-0",children:e.jsx(ge,{variant:"ghost",size:"sm",onClick:()=>{U()},className:"h-8 w-8 p-0 flex-shrink-0",title:"Refresh","aria-label":"Refresh",children:e.jsx(q,{name:"refresh",className:"h-4 w-4"})})})}),e.jsx(We,{side:"bottom",sideOffset:6,children:"Refresh"})]}),e.jsxs(Oe,{children:[e.jsx($e,{asChild:!0,children:e.jsx("span",{className:"inline-flex flex-shrink-0",children:e.jsx(ge,{variant:"ghost",size:"sm",onClick:()=>{o&&V(o)},className:"h-8 w-8 p-0 flex-shrink-0",title:"Collapse all folders","aria-label":"Collapse all folders",children:e.jsx(q,{name:"collapse-vertical",className:"h-4 w-4"})})})}),e.jsx(We,{side:"bottom",sideOffset:6,children:"Collapse all folders"})]})]}),e.jsxs("div",{className:"relative min-w-0",children:[e.jsx(q,{name:"search",className:"pointer-events-none absolute left-2 top-2 h-4 w-4 text-muted-foreground"}),e.jsx(Mt,{ref:f,value:g,onChange:i=>v(i.target.value),placeholder:"Search files...",className:"h-8 pl-8 pr-8 typography-meta"}),g.trim().length>0?e.jsx("button",{type:"button","aria-label":"Clear search",className:"absolute right-2 top-2 inline-flex h-4 w-4 items-center justify-center text-muted-foreground hover:text-foreground",onClick:()=>{v(""),f.current?.focus()},children:e.jsx(q,{name:"close",className:"h-4 w-4"})}):null]})]}),e.jsx(_r,{outerClassName:"flex-1 min-h-0",className:"p-2",children:e.jsx("ul",{className:"flex flex-col",children:T?e.jsxs("li",{className:"flex items-center gap-1.5 px-2 py-1 typography-meta text-muted-foreground",children:[e.jsx(q,{name:"loader-4",className:"h-4 w-4 animate-spin"}),"Searching..."]}):l.length>0?l.map(i=>{const D=y===i.path;return e.jsx("li",{children:e.jsxs("button",{type:"button",onClick:()=>oe(i),draggable:!0,onDragStart:d=>{const N=i.relativePath||xn(o??"",i.path);!N||N==="."||(d.dataTransfer.setData("application/x-pichamber-file-path",N),d.dataTransfer.effectAllowed="copy")},className:ce("flex w-full items-center gap-1.5 rounded-md px-2 py-1 text-left text-foreground transition-colors cursor-grab active:cursor-grabbing",D?"bg-interactive-selection/70":"hover:bg-interactive-hover/40"),title:i.path,children:[Ln(i.path,i.extension),e.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta",style:{direction:"rtl",textAlign:"left"},children:i.relativePath??i.path})]})},i.path)}):h?e.jsxs("li",{className:"flex flex-col gap-2 px-2 py-1 typography-meta text-muted-foreground",children:[e.jsx("span",{children:h}),e.jsxs(ge,{variant:"outline",size:"xs",className:"w-fit gap-1.5",onClick:()=>{U()},children:[e.jsx(q,{name:"refresh",className:"h-3.5 w-3.5"}),"Refresh"]})]}):B&&o?J(o,0):e.jsx("li",{className:"px-2 py-1 typography-meta text-muted-foreground",children:"Loading..."})})}),e.jsx(wt,{open:!!se,onOpenChange:i=>!i&&I(),children:e.jsxs(yt,{children:[e.jsxs(bt,{children:[e.jsxs(vt,{children:[se==="createFile"&&"Create File",se==="createFolder"&&"Create Folder",se==="rename"&&"Rename",se==="delete"&&"Delete"]}),e.jsxs(jt,{children:[se==="createFile"&&`Create a new file in ${he?.path??"root"}`,se==="createFolder"&&`Create a new folder in ${he?.path??"root"}`,se==="rename"&&`Rename ${he?.name??""}`,se==="delete"&&`Are you sure you want to delete ${he?.name??""}? This action cannot be undone.`]})]}),se!=="delete"&&e.jsx("div",{className:"py-4",children:e.jsx(Mt,{ref:xe,value:ue,onChange:i=>be(i.target.value),placeholder:se==="rename"?"New name":"Name",onKeyDown:i=>{i.key==="Enter"&&W()},autoFocus:!0})}),e.jsxs(Dr,{children:[e.jsx(ge,{variant:"outline",onClick:I,disabled:fe,children:"Cancel"}),e.jsx(ge,{variant:se==="delete"?"destructive":"default",onClick:()=>{W()},disabled:fe||se!=="delete"&&!ue.trim(),children:fe?e.jsx(q,{name:"loader-4",className:"size-4 animate-spin"}):se==="delete"?"Delete":"Confirm"})]})]})})]})},ao=200,io=480,lo=({visible:t})=>{const n=ee(j=>j.contextEditorTreeWidth),s=ee(j=>j.setContextEditorTreeWidth),[a,o]=r.useState(!1),m=r.useRef(0),w=r.useRef(n),u=r.useRef(null),p=r.useRef(null),g=r.useRef(null),v=r.useCallback(j=>Math.min(io,Math.max(ao,Math.round(j))),[]),f=r.useCallback(j=>{const P=g.current;P&&(P.style.width=`${j}px`,P.style.setProperty("--oc-editor-tree-width",`${j}px`))},[]),l=j=>{if(t){try{j.currentTarget.setPointerCapture(j.pointerId)}catch{}p.current=j.pointerId,o(!0),m.current=j.clientX,w.current=n,u.current=n,j.preventDefault()}},T=j=>{if(!a||p.current!==j.pointerId)return;const P=m.current-j.clientX,R=v(w.current+P);u.current!==R&&(u.current=R,f(R))},c=j=>{if(p.current!==j.pointerId)return;try{j.currentTarget.releasePointerCapture(j.pointerId)}catch{}const P=v(u.current??n);p.current=null,u.current=null,o(!1),s(P)},S=t?n:0;return e.jsxs("div",{ref:g,className:ce("relative h-full flex-shrink-0 overflow-hidden border-l border-border bg-background will-change-[width] motion-reduce:transition-none",!t&&"border-l-0"),style:{width:`${a?u.current??S:S}px`,"--oc-editor-tree-width":`${a?u.current??n:n}px`,overflowX:"clip",transitionProperty:a?"none":"width",transitionDuration:"200ms",transitionTimingFunction:"cubic-bezier(0.22, 1, 0.36, 1)"},"aria-hidden":!t,children:[t&&e.jsx("div",{className:ce("absolute left-0 top-0 z-20 h-full w-[3px] cursor-col-resize transition-colors hover:bg-[var(--interactive-border)]/80",a&&"bg-[var(--interactive-border)]"),onPointerDown:l,onPointerMove:T,onPointerUp:c,onPointerCancel:c,role:"separator","aria-orientation":"vertical","aria-label":"Resize context panel"}),e.jsx("div",{className:ce("relative z-10 h-full shrink-0 transition-opacity duration-200 ease-[cubic-bezier(0.22,1,0.36,1)] motion-reduce:transition-none",a&&"pointer-events-none",!t&&"pointer-events-none select-none opacity-0"),style:{width:"var(--oc-editor-tree-width)"},"aria-hidden":!t,children:e.jsx(oo,{})})]})},co="x-pichamber-preview-target-error",uo=t=>{const n=t.get(co);return n==="missing"||n==="expired"||n==="invalid-token"?n:null},ho=(t,n)=>uo(t)?n?"stop-retrying":"retry-registration":"none",po=({rawUrl:t,onNavigate:n})=>{const{currentTheme:s}=Ar(),[a,o]=r.useReducer(_=>_+1,0),[m,w]=r.useReducer(_=>_+1,0),[u,p]=r.useState({status:"idle"}),g=r.useRef(null),v=r.useRef(1),[f,l]=r.useState(!1),[T,c]=r.useState(!1),[S,j]=r.useState("all"),[P,R]=r.useState([]),[O,te]=r.useState(!1),[F,re]=r.useState(null),z=Se(_=>_.currentSessionId),y=Se(_=>_.newSessionDraft?.open),b=Ge(),G=ot(_=>_.addAttachedFile);let H=null;try{H=t?new URL(t):null}catch{H=null}const $=H?H.hostname==="localhost"||H.hostname==="127.0.0.1"||H.hostname==="::1"||H.hostname==="[::1]"||H.hostname==="0.0.0.0":!1,V=H?H.hostname==="0.0.0.0"?new URL(H.toString().replace("0.0.0.0","127.0.0.1")):H:null,ne=V?V.toString():"",E=ne?`${tn()||"same-origin"}|${ne}`:"",Q=s.metadata.variant;r.useEffect(()=>{if(!ne||!$){p({status:"idle"});return}const _=kt(E);if(_?.previewToken){p({status:"ready",proxyBasePath:_.proxyBasePath,previewToken:_.previewToken,expiresAt:_.expiresAt});return}_&&Pe.delete(E);let oe=!1;return p({status:"loading"}),(async()=>{try{const ae=await tt("/api/preview/targets",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({url:ne})}),J=await Dn(ae);if(!J.ok){Pe.delete(E),oe||p({status:"error",message:J.message});return}Pe.set(E,J.target),oe||p({status:"ready",...J.target})}catch(ae){if(Pe.delete(E),!oe){const J=ae instanceof Error?ae.message:String(ae);p({status:"error",message:J})}}})(),()=>{oe=!0}},[$,E,m,ne]);const C=V&&(V.protocol==="http:"||V.protocol==="https:")?V.toString():"",M=$&&u.status==="ready"?`${u.proxyBasePath}|${u.previewToken||""}|${a}`:"",U=Mn(M),L=$&&u.status==="ready"&&V&&U===M?(()=>{const _=V.pathname||"/",oe=new URLSearchParams(V.search);oe.delete("oc_url_token"),oe.delete("oc_client_token"),oe.set("ocPreview",String(a)),oe.set("oc_preview_token",u.previewToken||"");const ae=oe.toString(),J=V.hash||"";return nn().authenticatedAsset(`${u.proxyBasePath}${_}${ae?`?${ae}`:""}${J}`)})():"",K=$?L:C,se=$?Xs(L):C,he=$&&(u.status==="loading"||u.status==="idle"||U!==M),ue=$&&u.status==="error",be=r.useCallback(_=>{if(!(z??(y?"draft":null))||!b){je.error("Open a chat session before attaching preview annotations");return}const ae=t||K||"",J=typeof window<"u"?{width:window.innerWidth,height:window.innerHeight}:{width:0,height:0},B=typeof window<"u"?window.devicePixelRatio:1;(async()=>{let h=!1;try{const i=g.current,D=i?await _n(i,_):null;D&&(await G(D),h=!0)}catch{h=!1}rt(Ct({pageUrl:ae,viewport:J,devicePixelRatio:B,target:_,screenshotAttached:h,intro:"This is a selected DOM element from the in-app preview."})),je.success("Preview annotation attached to chat")})()},[G,z,b,K,y,t]);r.useEffect(()=>{l(!1),R([]),c(!1),j("all"),te(!1),re(null),v.current=1},[K]),r.useEffect(()=>{const _=g.current?.contentWindow;!f||!_||Kt(_,L,{source:"pichamber-preview-parent",version:1,type:"set-inspect-mode",enabled:O})},[f,O,L]),r.useEffect(()=>{const _=g.current?.contentWindow;!f||!_||Kt(_,L,{source:"pichamber-preview-parent",version:1,type:"set-color-scheme",scheme:Q})},[f,Q,L]),r.useEffect(()=>{if(!O||typeof window>"u")return;const _=oe=>{oe.key==="Escape"&&(oe.preventDefault(),oe.stopImmediatePropagation(),te(!1))};return window.addEventListener("keydown",_,!0),()=>window.removeEventListener("keydown",_,!0)},[O]),r.useEffect(()=>{if(!$||typeof window>"u")return;const _=J=>{if(typeof J=="string")return J;if(J==null)return"";try{return JSON.stringify(J)}catch{return String(J)}},oe=J=>{const B=v.current;v.current+=1,R(h=>{const i=[...h,{...J,id:B}];return i.length>Vt?i.slice(i.length-Vt):i})},ae=J=>{if(J.source!==g.current?.contentWindow)return;const B=J.data;if(!(!B||B.source!=="pichamber-preview-bridge"||B.version!==1)){if(B.type==="ready"){l(!0);return}if(B.type==="console"){const h=B.level==="error"||B.level==="warn"||B.level==="info"||B.level==="debug"?B.level:"log",i=Array.isArray(B.args)?B.args.map(_).filter(Boolean):[];oe({level:h,message:i.join(" "),ts:typeof B.ts=="number"?B.ts:Date.now()});return}if(B.type==="runtime-error"){const h=_(B.filename),i=typeof B.line=="number"?B.line:null,D=typeof B.column=="number"?B.column:null,d=h?`${h}${i!==null?`:${i}${D!==null?`:${D}`:""}`:""}`:"",N=_(B.stack);oe({level:"runtime",message:_(B.message)||"Runtime error",details:[d,N].filter(Boolean).join(`
|
|
127
|
+
`),ts:typeof B.ts=="number"?B.ts:Date.now()});return}if(B.type==="resource-error"){const h=_(B.tag)||"resource",i=_(B.url);oe({level:"resource",message:i?`${h}: ${i}`:h,details:_(B.outerHTML),ts:typeof B.ts=="number"?B.ts:Date.now()});return}if(B.type==="hover"){re(Be(B.target)?B.target:null);return}if(B.type==="select"&&Be(B.target)){re(B.target),te(!1),be(B.target);return}if(B.type==="navigate-preview"){const h=typeof B.url=="string"?B.url:"",i=B.navigation==="external"?"external":"proxy";if(h&&i==="external"){nt(h);return}h&&n(h)}}};return window.addEventListener("message",ae),()=>{window.removeEventListener("message",ae)}},[be,$,n]);const fe=P.filter(_=>_.level==="error"||_.level==="runtime"||_.level==="resource").length,xe=P.filter(_=>Ks(_,S)),pe=r.useCallback(()=>{const _=[`Preview URL: ${t||K||""}`,`Events: ${P.length}`,""].join(`
|
|
128
|
+
`),oe=P.map(ae=>{const J=new Date(ae.ts).toISOString(),B=ae.details?`
|
|
129
|
+
${ae.details}`:"";return`[${J}] [${ae.level}] ${ae.message}${B}`}).join(`
|
|
130
|
+
`);gt(`${_}${oe}`).then(ae=>{ae.ok?je.success("Preview console copied"):je.error("Failed to copy preview console")})},[P,K,t]),I=r.useCallback(()=>{if(!(z??(y?"draft":null))||!b){je.error("Open a chat session before attaching preview logs");return}const oe=[`Preview URL: ${t||K||""}`,`Events: ${P.length}`,""].join(`
|
|
131
|
+
`),ae=P.map(J=>{const B=new Date(J.ts).toISOString(),h=J.details?`
|
|
132
|
+
${J.details}`:"";return`[${B}] [${J.level}] ${J.message}${h}`}).join(`
|
|
133
|
+
`);rt(`These are browser console logs from the dev server running for this project.
|
|
134
|
+
|
|
135
|
+
${oe}${ae}`),je.success("Preview console attached to chat")},[P,z,b,K,y,t]),[W,x]=r.useState("unknown"),A=r.useRef(0),X=r.useRef(0),de=r.useRef(""),me=r.useRef(""),we=15e3;r.useEffect(()=>{if(!L){x("unknown"),de.current="",A.current=0,X.current=0;return}let _=!1,oe=null;de.current!==E&&(de.current=E,A.current=Date.now(),X.current=0);const ae=J=>{oe=setTimeout(()=>{_||o()},J)};return x("unknown"),(async()=>{const B=await(async()=>{try{return await tt(L,{method:"GET",credentials:"include",cache:"no-store",redirect:"manual"})}catch{return null}})();if(_)return;if(!B){x("unreachable"),ae(5e3);return}const h=ho(B.headers,me.current===E);if(h!=="none"){if(Pe.delete(E),h==="retry-registration")me.current=E,p({status:"loading"}),w();else{const d=await B.json().catch(()=>({}));if(_)return;const N=typeof d?.error=="string"?d.error:`HTTP ${B.status}`;p({status:"error",message:N})}return}if(B.status!==502){me.current="",x("reachable");return}const i=A.current||Date.now();if(Date.now()-i<we){x("starting"),X.current+=1;const d=X.current,N=Math.min(2e3,250*Math.pow(2,Math.min(4,d)));ae(N);return}x("unreachable"),ae(5e3)})(),()=>{_=!0,oe&&clearTimeout(oe)}},[E,L,a]);const k=$&&u.status==="ready"&&(W==="unknown"||W==="starting"),Y=$&&u.status==="ready"&&W==="unreachable",ie=r.useCallback(_=>{if(!$||u.status!=="ready"||typeof window>"u")return;const oe=_.currentTarget.contentWindow;if(oe)try{const ae=oe.location,J=An(L);if(ae.origin!==J||ae.pathname.startsWith(u.proxyBasePath))return;const B=`${u.proxyBasePath}${ae.pathname}${ae.search}${ae.hash}`;oe.location.replace(B)}catch{}},[$,L,u]);return e.jsxs("div",{className:"absolute inset-0 flex flex-col",children:[e.jsxs("div",{className:"flex items-center gap-1 border-b border-border bg-[var(--surface-background)] px-2 py-1",children:[e.jsx("div",{className:"min-w-0 flex-1 truncate typography-micro text-muted-foreground",title:se||t,children:se||t||"No preview URL"}),e.jsx(ge,{type:"button",size:"sm",variant:"ghost",className:"h-7 w-7 p-0",onClick:()=>o(),title:"Reload preview","aria-label":"Reload preview",disabled:!K,children:e.jsx(q,{name:"refresh",className:"h-3.5 w-3.5"})}),e.jsx(ge,{type:"button",size:"sm",variant:"ghost",className:"h-7 w-7 p-0",onClick:()=>{C&&nt(C)},title:"Open in browser","aria-label":"Open in browser",disabled:!C,children:e.jsx(q,{name:"external-link",className:"h-3.5 w-3.5"})}),$?e.jsx(ge,{type:"button",size:"sm",variant:O?"secondary":"ghost",className:"h-7 gap-1 px-2",onClick:()=>te(_=>!_),title:"Inspect preview element","aria-label":"Inspect preview element",disabled:!f,children:e.jsx(q,{name:"cursor",className:"h-3.5 w-3.5"})}):null,$?e.jsxs(ge,{type:"button",size:"sm",variant:T?"secondary":"ghost",className:"h-7 gap-1 px-2",onClick:()=>c(_=>!_),title:f?"Open preview console":"Waiting for preview console","aria-label":f?"Open preview console":"Waiting for preview console",disabled:!f&&P.length===0,children:[e.jsx(q,{name:"terminal-box",className:"h-3.5 w-3.5"}),fe>0?e.jsx("span",{className:"typography-micro text-status-error",children:fe}):null]}):null]}),e.jsxs("div",{className:"relative min-h-0 flex-1 bg-background",children:[k?e.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-3 px-6 text-center text-sm text-muted-foreground",children:[e.jsx("div",{children:"Starting dev server..."}),e.jsx("div",{className:"text-xs opacity-70",children:"Waiting for the server to accept connections."})]}):Y?e.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-3 px-6 text-center text-sm text-muted-foreground",children:[e.jsx("div",{children:"Dev server is not responding."}),e.jsx("div",{className:"text-xs opacity-70",children:"Make sure your dev server is still running, then retry."}),e.jsx(ge,{type:"button",size:"sm",variant:"outline",onClick:()=>o(),children:"Retry"})]}):K&&(!$||W==="reachable")?e.jsxs("div",{className:"relative h-full w-full",children:[e.jsx("iframe",{ref:g,src:K,title:"Preview",className:"h-full w-full border-0",style:{colorScheme:Q},onLoad:ie,sandbox:$?"allow-scripts allow-same-origin allow-forms allow-popups allow-downloads":"allow-scripts allow-forms"},`${K}:${a}`),O&&F?e.jsx("div",{className:"pointer-events-none absolute rounded-sm border-2 border-[var(--interactive-focus-ring)] bg-[var(--interactive-focus-ring)]/35",style:{left:F.bounds.x,top:F.bounds.y,width:F.bounds.width,height:F.bounds.height},children:e.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:[F.tag,F.text?` · ${F.text}`:""]})}):null]}):he?e.jsx("div",{className:"flex h-full items-center justify-center px-6 text-sm text-muted-foreground",children:"Connecting preview proxy..."}):ue?e.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-2 px-6 text-sm text-muted-foreground",children:[e.jsx("div",{children:"Could not start preview proxy."}),u.status==="error"?e.jsx("div",{className:"text-center text-xs opacity-70",children:u.message}):null]}):e.jsx("div",{className:"flex h-full items-center justify-center px-6 text-sm text-muted-foreground",children:"Preview needs a valid http(s) URL."}),T?e.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:[e.jsxs("div",{className:"flex items-center justify-between border-b border-border/50 px-3 py-2",children:[e.jsx("div",{className:"typography-ui-label text-foreground",children:"Preview console"}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(ge,{type:"button",size:"xs",variant:"ghost",onClick:I,disabled:P.length===0,children:"Attach"}),e.jsx(ge,{type:"button",size:"xs",variant:"ghost",onClick:pe,disabled:P.length===0,children:"Copy"}),e.jsx(ge,{type:"button",size:"xs",variant:"ghost",onClick:()=>R([]),disabled:P.length===0,children:"Clear"})]})]}),e.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.jsx(ge,{type:"button",size:"xs",variant:S===_?"secondary":"ghost",onClick:()=>j(_),children:_==="all"?"All":_==="errors"?"Errors":_==="warnings"?"Warnings":"Logs"},_))}),e.jsx("div",{className:"max-h-64 overflow-auto p-2 typography-code text-xs",children:P.length===0?e.jsx("div",{className:"px-2 py-3 text-muted-foreground",children:"No preview console events yet."}):xe.length===0?e.jsx("div",{className:"px-2 py-3 text-muted-foreground",children:"No events match this filter."}):xe.map(_=>e.jsx("div",{className:"border-b border-border/30 px-2 py-1 last:border-b-0",children:e.jsxs("div",{className:"flex gap-2",children:[e.jsx("span",{className:ce("shrink-0 uppercase",_.level==="error"||_.level==="runtime"||_.level==="resource"?"text-status-error":_.level==="warn"?"text-status-warning":"text-muted-foreground"),children:_.level}),e.jsx("span",{className:"min-w-0 break-words text-foreground",children:_.message})]})},_.id))})]}):null]})]})},Rt=t=>t,ft=t=>{const n=Rt(t).type;return typeof n=="string"?n:""},fo=t=>{const n=Rt(t).tool;return typeof n=="string"?n:""},mo=t=>{const n=Rt(t).text;return typeof n=="string"?n:""},go=t=>{const n=ft(t);return n==="tool"?fo(t).trim().toLowerCase()||"tool":n||"unknown"},xo=t=>{if(t.length===0)return"";const n=[];for(const s of t){const a=go(s);n.includes(a)||n.push(a)}return n.join(" + ")},wo=t=>t.replace(/\s+/g," ").trim(),yo=t=>{for(const s of t)if(ft(s)==="text"){const a=wo(mo(s));if(a.length===0)continue;return a}const n=t.filter(s=>ft(s)!=="text").length;return n===0?"":`${n} attachment${n===1?"":"s"}`},bo=(t,n,s)=>`${s(t)} / ${s(n)}`,vo=t=>{if(t==="12h")return!0;if(t==="24h")return!1},jo=(t,n)=>{if(!t||!Number.isFinite(t))return"-";const s=vo(n);return new Date(t).toLocaleString(void 0,{month:"numeric",day:"numeric",hour:s===!1?"2-digit":"numeric",minute:"2-digit",...s===void 0?{}:{hour12:s}})},So={input:0,output:0,reasoning:0,cacheRead:0,cacheWrite:0,total:0},et={user:0,assistant:0,tool:0,other:0},Co=t=>typeof t!="number"||!Number.isFinite(t)||t<0?0:t,dt=t=>ht(t),ko=(...t)=>{for(const n of t)if(typeof n=="string"&&n.trim().length>0)return n;return""},ke=t=>typeof t=="string"?t.length:typeof t=="number"||typeof t=="boolean"?String(t).length:Array.isArray(t)?t.reduce((n,s)=>n+ke(s),0):t&&typeof t=="object"?Object.values(t).reduce((n,s)=>n+ke(s),0):0,No=(t,n)=>{const s=t,a=typeof s.type=="string"?s.type:"";if(a==="reasoning")return{...et,assistant:ke(s.text)+ke(s.content)};const o=ko(s.text,s.content,s.value,s.source?.value,s.source?.text?.value);return a==="tool"||n==="tool"?{user:0,assistant:0,tool:ke(s.input)+ke(s.output)+ke(s.error)+ke(s.call?.input)+ke(s.call?.output)+ke(s.call?.error)+ke(s.raw)+Math.round(ke(s.metadata)*.25)+Math.round(ke(s.state)*.1),other:0}:n==="user"?{user:o.length,assistant:0,tool:0,other:0}:n==="assistant"?{user:0,assistant:o.length,tool:0,other:0}:{user:0,assistant:0,tool:0,other:o.length}},Yt=(t,n)=>({user:t.user+n.user,assistant:t.assistant+n.assistant,tool:t.tool+n.tool,other:t.other+n.other}),Po=t=>{const n=Ke(t.info);return n.isUser?"user":n.role==="assistant"?"assistant":n.role==="tool"?"tool":"other"},Ro=(t,n)=>{if(t.length===0)return{...et};const s=t.reduce((a,o)=>{const m=Po(o);let w={...et};for(const u of o.parts)w=Yt(w,No(u,m));return Yt(a,w)},{...et});return s.user+=n.length,{user:Math.ceil(s.user/4),assistant:Math.ceil(s.assistant/4),tool:Math.ceil(s.tool/4),other:Math.ceil(s.other/4)}},Ae=t=>t.toLocaleString("en-US"),Eo=t=>!Number.isFinite(t)||t<=0?new Intl.NumberFormat("en-US",{style:"currency",currency:"USD",minimumFractionDigits:2,maximumFractionDigits:2}).format(0):new Intl.NumberFormat("en-US",{style:"currency",currency:"USD",minimumFractionDigits:t<.01?4:2,maximumFractionDigits:t<.01?4:2}).format(t),To=(t,n)=>!t||!Number.isFinite(t)?"-":Or(t,n,{month:"short",day:"numeric",year:"numeric",hour:"numeric",minute:"2-digit"}),_o=(t,n,s)=>{const a=t.find(m=>m.id===n),o=a?.models?.find(m=>m.id===s);return{providerName:a?.name||n||"-",modelName:o?.name||s||"-",contextLimit:typeof o?.limit?.context=="number"?o.limit.context:null}},Do=()=>{const t=ee(c=>c.timeFormatPreference),[n,s]=r.useState({}),{value:a,show:o,clear:m}=Mr(null,2e3),w=Se(c=>c.currentSessionId),u=Se(c=>c.currentSessionDirectory),p=Ir(),g=dn(w??""),v=Ie(c=>c.providers);r.useEffect(()=>{s(c=>Object.keys(c).length>0?{}:c),m()},[m,u,w]);const f=r.useCallback(async(c,S)=>{(await gt(S)).ok?o(c):m()},[m,o]),l=r.useMemo(()=>{const c=w?p.find(L=>L.id===w)??null:null,S=g.filter(L=>Ke(L.info).role==="assistant"),j=g.filter(L=>Ke(L.info).isUser);let P=null;for(let L=S.length-1;L>=0;L-=1){const K=S[L];if(dt(K).total>0){P=K;break}}const R=P?dt(P):So,O=P?.info?.usage,te=un({input:R.input,cache:{read:R.cacheRead,write:R.cacheWrite}}),F=S.reduce((L,K)=>{const se=Co(K.info.cost);return L+se},0),re=P?.info?.model??null,z=_o(v,re?.providerID||"",re?.modelID||""),y=z.contextLimit,b=O?hn(O):R.total,G=y&&y>0?Math.min(999,b/y*100):0,H=[...g].reverse().find(L=>Ke(L.info).isUser&&typeof L.info.system=="string")?.info?.system||"",$=Ro(g,H),V=$.user,ne=$.assistant,E=$.tool,Q=O?0:Math.max(0,R.input-V-ne-E),C=V+ne+E+Q,M=g[0]?.info?.time?.created,U=g.length>0?g[g.length-1]?.info?.time?.created:null;return{sessionTitle:Cn(c),messagesCount:g.length,userMessagesCount:j.length,assistantMessagesCount:S.length,createdAt:c?.time?.created??M??null,lastActivityAt:U??c?.time?.created??null,providerModel:z,tokenBreakdown:R,usagePercent:G,cacheHitRate:te,totalAssistantCost:F,contextLimit:y,contextWindowTokens:b,hasUsage:O!==void 0,breakdown:{user:V,assistant:ne,tool:E,other:Q},breakdownTotal:C}},[w,v,g,p]);if(!w)return e.jsx("div",{className:"flex h-full items-center justify-center p-6 text-center typography-ui-label text-muted-foreground",children:"Open a session to inspect context."});const T=[{key:"user",label:"User",value:l.breakdown.user,color:"var(--status-success)"},{key:"assistant",label:"Assistant",value:l.breakdown.assistant,color:"var(--primary-base)"},{key:"tool",label:"Tool Calls",value:l.breakdown.tool,color:"var(--status-warning)"},...l.hasUsage?[]:[{key:"other",label:"Other",value:l.breakdown.other,color:"var(--surface-muted-foreground)"}]];return e.jsx("div",{className:"h-full overflow-y-auto bg-background",children:e.jsxs("div",{className:"mx-auto w-full max-w-[52rem] px-5 py-6",children:[e.jsxs("div",{className:"mb-6",children:[e.jsx("h2",{className:"typography-ui-header font-semibold text-foreground truncate",children:l.sessionTitle}),e.jsxs("div",{className:"mt-1 flex flex-wrap items-center gap-x-2 gap-y-0.5 typography-micro text-muted-foreground/70",children:[e.jsxs("span",{children:[l.providerModel.providerName," / ",l.providerModel.modelName]}),l.createdAt&&e.jsxs(e.Fragment,{children:[e.jsx("span",{children:"·"}),e.jsx("span",{children:To(l.createdAt,t)})]})]})]}),e.jsxs("div",{className:"mb-5 rounded-lg bg-[var(--surface-elevated)]/70 px-4 py-3.5",children:[e.jsxs("div",{className:"flex items-baseline justify-between",children:[e.jsx("span",{className:"typography-micro text-muted-foreground",children:"Context"}),e.jsxs("span",{className:"typography-micro tabular-nums text-muted-foreground/70",children:[Ae(l.contextWindowTokens),l.contextLimit?` / ${Ae(l.contextLimit)}`:""]})]}),e.jsx("div",{className:"mt-2.5 flex h-1 w-full overflow-hidden rounded-full bg-[var(--surface-subtle)]",children:l.usagePercent>0&&e.jsx("div",{className:"rounded-full transition-all duration-300",style:{width:`${Math.max(.5,l.usagePercent)}%`,backgroundColor:l.usagePercent>80?"var(--status-warning)":"var(--primary-base)"}})}),e.jsx("div",{className:"mt-1.5 typography-micro font-medium tabular-nums text-foreground/80",children:`${l.usagePercent.toFixed(1)}% used`})]}),e.jsx("div",{className:"mb-5 grid grid-cols-2 gap-2",children:[{label:"Messages",value:Ae(l.messagesCount)},{label:"User",value:Ae(l.userMessagesCount)},{label:"Assistant",value:Ae(l.assistantMessagesCount)},{label:"Cost",value:Eo(l.totalAssistantCost)}].map(c=>e.jsxs("div",{className:"rounded-lg bg-[var(--surface-elevated)]/70 px-3 py-2.5",children:[e.jsx("div",{className:"typography-micro text-muted-foreground/70",children:c.label}),e.jsx("div",{className:"mt-0.5 typography-ui-label tabular-nums text-foreground",children:c.value})]},c.label))}),e.jsxs("div",{className:"mb-5 rounded-lg bg-[var(--surface-elevated)]/70 px-4 py-3.5",children:[e.jsx("div",{className:"typography-micro text-muted-foreground mb-2.5",children:"Last Assistant Message"}),e.jsx("div",{className:"grid grid-cols-3 gap-x-4 gap-y-2.5",children:[{label:"Input",value:l.tokenBreakdown.input,format:"count"},{label:"Output",value:l.tokenBreakdown.output,format:"count"},{label:"Reasoning",value:l.tokenBreakdown.reasoning,format:"count"},{label:"Cache Read",value:l.tokenBreakdown.cacheRead,format:"count"},{label:"Cache Write",value:l.tokenBreakdown.cacheWrite,format:"count"},{label:"Cache Hit",value:l.cacheHitRate.hasInput?l.cacheHitRate.percent:null,format:"percent"}].map(c=>e.jsxs("div",{children:[e.jsx("div",{className:"typography-micro text-muted-foreground/70",children:c.label}),e.jsx("div",{className:"mt-0.5 typography-ui-label tabular-nums text-foreground",children:c.value!==null&&c.value!==void 0?c.format==="percent"?`${c.value.toFixed(1)}%`:Ae(c.value):"—"})]},c.label))})]}),e.jsxs("div",{className:"mb-6",children:[e.jsx("div",{className:"flex h-1 w-full overflow-hidden rounded-full bg-[var(--surface-subtle)]",children:T.map(c=>c.value<=0||l.breakdownTotal<=0?null:e.jsx("div",{style:{width:`${c.value/l.breakdownTotal*100}%`,backgroundColor:c.color}},c.key))}),e.jsx("div",{className:"mt-2 flex flex-wrap items-center gap-x-4 gap-y-1",children:T.map(c=>{const S=l.breakdownTotal>0?c.value/l.breakdownTotal*100:0;return e.jsxs("div",{className:"inline-flex items-center gap-1.5",children:[e.jsx("span",{className:"h-1.5 w-1.5 rounded-full",style:{backgroundColor:c.color}}),e.jsxs("span",{className:"typography-micro text-muted-foreground/70",children:[c.label," ",e.jsxs("span",{className:"tabular-nums",children:[S.toFixed(0),"%"]})]})]},c.key)})})]}),e.jsxs("div",{children:[e.jsx("div",{className:"typography-micro text-muted-foreground",children:"Raw Messages"}),e.jsx("div",{className:"mt-2.5 space-y-1",children:[...g].reverse().map(c=>{const j=Ke(c.info).role,P=j==="assistant",R=j==="user",O=n[c.info.id]===!0,te=a===c.info.id,F=c.info.time?.created??null,re=xo(c.parts),z=P?dt({info:c.info,parts:c.parts}):null,y=R?yo(c.parts):"",b=jo(F,t),G=re||"—",H=z?bo(z.input,z.output,Ae):"",$=j||"unknown",V=re?`${$}: ${re}`:$,ne=O?JSON.stringify({info:c.info,parts:c.parts},null,2):"";return e.jsxs("div",{className:"overflow-hidden rounded-lg bg-[var(--surface-elevated)]/70",children:[e.jsx("button",{type:"button",className:"w-full cursor-pointer px-3 py-1.5 text-left hover:bg-[var(--interactive-hover)]","aria-expanded":O,onClick:()=>{s(E=>({...E,[c.info.id]:E[c.info.id]!==!0}))},children:e.jsxs("div",{className:"grid items-center gap-x-2 whitespace-nowrap typography-micro",style:{gridTemplateColumns:P?"minmax(0, 1fr) 7.5rem max-content":"minmax(0, 1fr) max-content"},children:[R?e.jsxs("span",{className:"min-w-0 truncate text-muted-foreground",children:[e.jsx("span",{className:"typography-ui-label text-foreground",children:"user:"})," ",y]}):e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"min-w-0 truncate text-muted-foreground",children:P?G:V}),P&&e.jsx("span",{className:"text-right text-muted-foreground tabular-nums",children:H})]}),e.jsx("span",{className:"text-right text-muted-foreground",children:b})]})}),O&&e.jsx("div",{className:"border-t border-[var(--surface-subtle)] p-0",children:e.jsxs("div",{className:"group relative max-h-[26rem] w-full overflow-auto bg-[var(--surface-background)]",children:[e.jsx("div",{className:"absolute top-1 right-2 z-10 opacity-0 transition-opacity group-hover:opacity-100",children:e.jsx("button",{type:"button",className:"rounded p-1 text-muted-foreground transition-colors hover:bg-interactive-hover/60 hover:text-foreground",onClick:E=>{E.stopPropagation(),f(c.info.id,ne)},"aria-label":te?"Copied":"Copy JSON",title:te?"Copied":"Copy",children:te?e.jsx(q,{name:"check",className:"size-3.5"}):e.jsx(q,{name:"file-copy",className:"size-3.5"})})}),e.jsx(Lr,{language:"json",code:ne,style:{margin:0,padding:"0.75rem",background:"transparent",fontSize:"var(--text-micro)",lineHeight:"1.35"},wrap:!0})]})})]},c.info.id)})})]})]})})},Ao=De(()=>Ee(()=>import("./DiffView-CZyHHAOB.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,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119])).then(t=>({default:t.DiffView}))),Mo=De(()=>Ee(()=>import("./FilesView-BJYLFR3H.js"),__vite__mapDeps([120,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,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,117,118,99,100,84,85,86,87,88,89,90,91,92,93,94,95,96,97,121,122,111,112,113,114,115,116,123,124,81,82,83,98,101,102,103,104,105,106,107,125,126,127,128])).then(t=>({default:t.FilesView}))),Io=De(()=>Ee(()=>import("./GitView-Cg_5UU7E.js"),__vite__mapDeps([129,24,1,2,9,4,3,5,6,7,8,10,11,12,13,14,15,16,17,18,19,20,21,22,23,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,111,112,113,114,115,116,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,117,118,130])).then(t=>({default:t.GitView}))),Lo=380,Oo=1400,On=600,$o=100,Wo=24,Jt=t=>Number.isFinite(t)?Math.min(Oo,Math.max(Lo,Math.round(t))):On,Fo=t=>{const n=t?.parentElement?.clientWidth;return!n||n<=0?null:n},Bo=(t,n)=>{if(!t)return"";const s=t.replace(/\\/g,"/"),a=n.replace(/\\/g,"/").replace(/\/+$/,"");return a&&s.startsWith(a+"/")?s.slice(a.length+1):s},$n=(t,n=null)=>t==="file"?"Files":t==="diff"?"Changes":t==="preview"?"Preview":t==="browser"?"Browser":t==="git"?St(n).label:t==="terminal"?"Terminal":"Context",zo=t=>{if(!t)return null;const n=t.replace(/\\/g,"/").trim();if(!n)return null;const s=n.split("/").filter(Boolean);return s.length===0?n:s[s.length-1]||null},Uo=(t,n=null)=>{if(t.label)return t.label;if(t.mode==="file")return zo(t.targetPath)||"Files";if(t.mode==="preview"){const s=t.targetPath;if(s)try{const a=new URL(s);return a.host||a.hostname||"Preview"}catch{}return"Preview"}return t.mode==="diff"?"Changes":$n(t.mode,n)},Qt=(t,n=null)=>{if(t.mode==="file")return t.targetPath?e.jsx(mt,{filePath:t.targetPath,className:"h-3.5 w-3.5"}):void 0;if(t.mode==="diff")return e.jsx(pr,{className:"h-3.5 w-3.5"});if(t.mode==="git")return e.jsx(q,{name:St(n).icon,className:"h-3.5 w-3.5"});if(t.mode==="terminal")return e.jsx(q,{name:"terminal-box",className:"h-3.5 w-3.5"});if(t.mode==="context")return e.jsx(q,{name:"donut-chart-fill",className:"h-3.5 w-3.5"});if(t.mode==="preview")return e.jsx(q,{name:"global",className:"h-3.5 w-3.5 text-[var(--status-info)]"});if(t.mode==="browser")return e.jsx(q,{name:"global",className:"h-3.5 w-3.5"})},Ho=(t,n)=>t.length<=n?t:`${t.slice(0,n-3)}...`,Vo=()=>{const t=Ge()??"",n=r.useMemo(()=>Re(t),[t]),s=ee(d=>n?d.contextPanelByDirectory[n]:void 0),a=ee(d=>d.closeContextPanel),o=ee(d=>d.closeContextPanelTab),m=ee(d=>d.openContextPanelTab),w=ee(d=>d.toggleContextPanelExpanded),u=ee(d=>d.setContextPanelWidth),p=ee(d=>d.setActiveContextPanelTab),g=ee(d=>d.reorderContextPanelTabs),v=Te(d=>d.setSelectedPath),f=ee(d=>d.openContextPreview),l=ee(d=>d.contextEditorTreeVisible),T=ee(d=>d.toggleContextEditorTree),c=r.useMemo(()=>s?.tabs??[],[s?.tabs]),S=c.find(d=>d.id===s?.activeTabId)??c[c.length-1]??null,j=!!(s?.isOpen&&S),P=!!(j&&s?.expanded),[R,O]=r.useState(null),te=s?.width,F=Wr,re=R??(typeof window<"u"?window.innerWidth:On*2),z=Jt(te??Math.round(F*re)),y=pn(n||null),[b,G]=r.useState(!1),[H,$]=r.useState(null),[V,ne]=r.useState(null),[E,Q]=r.useState(null),C=r.useRef(0),M=r.useRef(z),U=r.useRef(null),L=r.useRef(null),K=r.useRef(null),se=r.useRef(!1);r.useLayoutEffect(()=>{const d=K.current?.parentElement;if(!d||typeof ResizeObserver>"u")return;const N=new ResizeObserver(()=>{O(d.clientWidth||null)});return N.observe(d),O(d.clientWidth||null),()=>N.disconnect()},[]),r.useEffect(()=>{if(!j||se.current){se.current=j;return}const d=window.requestAnimationFrame(()=>{K.current?.focus({preventScroll:!0})});return se.current=!0,()=>window.cancelAnimationFrame(d)},[j]);const he=r.useRef(null),ue=r.useRef(null),be=r.useCallback(()=>{ue.current=null;const d=K.current,N=U.current;!d||N===null||d.style.setProperty("--oc-context-panel-width",`${N}px`)},[]);r.useEffect(()=>()=>{ue.current!==null&&clearTimeout(ue.current)},[]);const fe=r.useCallback(d=>{const N=Jt(d),le=he.current;return le===null?N:Math.min(N,Math.max(1,le))},[]),xe=r.useCallback(d=>{!j||P||!n||(L.current=d.pointerId,G(!0),C.current=d.clientX,M.current=z,U.current=z,he.current=Fo(K.current),document.documentElement.style.cursor="col-resize",d.preventDefault())},[n,P,j,z]),pe=r.useCallback(()=>{const d=fe(U.current??z);U.current=null,he.current=null,ue.current!==null&&(clearTimeout(ue.current),ue.current=null),document.documentElement.style.cursor="",n&&u(n,d),G(!1),L.current=null},[fe,n,u,z]);r.useEffect(()=>{if(!b)return;const d=Z=>{if(L.current!==Z.pointerId)return;const ye=C.current-Z.clientX,ve=fe(M.current+ye);U.current!==ve&&(U.current=ve,ue.current===null&&(ue.current=setTimeout(be,$o)))},N=Z=>{L.current===Z.pointerId&&pe()},le=()=>{pe()};return window.addEventListener("pointermove",d),window.addEventListener("pointerup",N),window.addEventListener("pointercancel",N),window.addEventListener("blur",le),()=>{window.removeEventListener("pointermove",d),window.removeEventListener("pointerup",N),window.removeEventListener("pointercancel",N),window.removeEventListener("blur",le)}},[be,fe,pe,b]),r.useEffect(()=>{b||(U.current=null,document.documentElement.style.cursor="")},[b]);const I=r.useCallback(()=>{n&&a(n)},[a,n]),W=r.useCallback(()=>{n&&w(n)},[n,w]),x=r.useCallback(d=>{d.key==="Escape"&&($r(d.target)||(d.preventDefault(),d.stopPropagation(),I()))},[I]);r.useEffect(()=>{if(!(!n||!S)&&S.mode==="file"&&S.targetPath){v(n,S.targetPath,{allowOutsideRoot:!0});return}},[S,n,v]);const A=r.useCallback(d=>{!n||S?.mode!=="diff"||m(n,{mode:"diff",targetPath:S.targetPath,stagedDiff:d==="staged",diffScope:d})},[S,n,m]),X=S?.mode==="file"||S?.mode==="preview",de=r.useMemo(()=>S?c.filter(d=>d.mode===S.mode):[],[S,c]),me=r.useMemo(()=>de.map(d=>{const N=Uo(d,y),le=Ho(N,Wo),Z=Bo(d.targetPath,t);return{id:d.id,label:le,icon:Qt(d,y),title:Z?`${N}: ${Z}`:N,closeLabel:`Close ${le} tab`}}),[de,t,y]),we=S?.mode==="context"?e.jsx(Do,{}):S?.mode==="git"?e.jsx(r.Suspense,{fallback:null,children:e.jsx(Io,{isActive:j,gitHeaderSlot:S?.mode==="git"?V:null})}):S?.mode==="preview"?e.jsx(po,{rawUrl:S.targetPath??"",onNavigate:d=>f(t,d)}):e.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-3 p-6 text-center",children:[e.jsx(q,{name:"global",className:"h-12 w-12 text-muted-foreground/50"}),e.jsx("div",{className:"typography-ui-header text-foreground",children:"Preview"}),e.jsx("div",{className:"max-w-sm typography-micro text-muted-foreground",children:"Use Project Actions or a terminal Preview button to open a preview."})]}),k=r.useMemo(()=>c.filter(d=>d.mode==="browser"),[c]),Y=r.useMemo(()=>c.filter(d=>d.mode==="diff"),[c]),ie=r.useMemo(()=>c.some(d=>d.mode==="terminal"),[c]),_=r.useMemo(()=>c.some(d=>d.mode==="file"),[c]),oe=r.useMemo(()=>c.some(d=>d.mode==="file"&&d.targetPath),[c]),ae=S?.mode==="file",J=S?.mode==="terminal",B=S?.mode==="git",h=S?.mode==="diff",i=e.jsxs("header",{className:"flex h-10 items-stretch border-b border-border",children:[X?e.jsx(Rs,{items:me,activeId:S?.id??null,onSelect:d=>{n&&p(n,d)},onClose:d=>{n&&o(n,d)},onReorder:(d,N)=>{n&&g(n,d,N)},layoutMode:"scrollable",variant:"default"}):J?e.jsx("div",{ref:d=>{$(d)},className:"flex min-w-0 flex-1 items-center px-1"}):B?e.jsx("div",{ref:d=>{ne(d)},className:"flex min-w-0 flex-1 items-center overflow-hidden px-1"}):h?e.jsx("div",{ref:d=>{Q(d)},className:"flex min-w-0 flex-1 items-center overflow-hidden px-1"}):e.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-1.5 px-3",children:[S?Qt(S,y):null,e.jsx("span",{className:"truncate typography-ui-label text-foreground",children:S?$n(S.mode,y):null})]}),e.jsxs("div",{className:"flex items-center gap-1 px-1.5",children:[ae?e.jsx(ge,{type:"button",variant:"ghost",size:"sm",onClick:T,className:"h-7 w-7 p-0",title:"Toggle file tree","aria-label":"Toggle file tree","aria-pressed":l,children:e.jsx(q,{name:"layout-right",className:"h-3.5 w-3.5"})}):null,e.jsx(ge,{type:"button",variant:"ghost",size:"sm",onClick:W,className:"h-7 w-7 p-0",title:P?"Collapse panel":"Expand panel","aria-label":P?"Collapse panel":"Expand panel",children:P?e.jsx(q,{name:"fullscreen-exit",className:"h-3.5 w-3.5"}):e.jsx(q,{name:"fullscreen",className:"h-3.5 w-3.5"})}),e.jsx(ge,{type:"button",variant:"ghost",size:"sm",onClick:I,className:"h-7 w-7 p-0",title:"Close panel","aria-label":"Close panel",children:e.jsx(q,{name:"close",className:"h-3.5 w-3.5"})})]})]}),D=j?P?{"--oc-context-panel-width":R!==null?`${R}px`:"100%",width:R!==null?`${R}px`:"100%",maxWidth:"100%"}:{width:"min(var(--oc-context-panel-width), 100%)",maxWidth:"100%",overflowX:"clip","--oc-context-panel-width":`${z}px`}:{"--oc-context-panel-width":`${z}px`,width:0,maxWidth:"100%",overflowX:"clip"};return e.jsxs("aside",{ref:K,"data-context-panel":"true",tabIndex:-1,inert:!j||void 0,className:ce("flex min-h-0 flex-col overflow-hidden bg-background",P?"absolute inset-y-0 right-0 z-20 min-w-0":"relative h-full flex-shrink-0",!j&&"pointer-events-none","will-change-[width] motion-reduce:transition-none","transition-[width] duration-200 ease-[cubic-bezier(0.22,1,0.36,1)]"),onKeyDownCapture:x,style:D,children:[j&&!P&&e.jsx("div",{"aria-hidden":"true",className:"absolute left-0 top-0 z-40 h-full w-px bg-border"}),j&&e.jsx("div",{"aria-hidden":"true",className:"absolute right-0 top-0 z-40 h-full w-px bg-border"}),!P&&e.jsx("div",{className:ce("absolute left-0 top-0 z-50 h-full w-[3px] cursor-col-resize transition-colors hover:bg-[var(--interactive-border)]/80",b&&"bg-[var(--interactive-border)]"),onPointerDown:xe,role:"separator","aria-orientation":"vertical","aria-label":"Resize context panel"}),e.jsxs("div",{className:ce("relative z-10 flex h-full min-h-0 shrink-0 flex-col duration-200 ease-[cubic-bezier(0.22,1,0.36,1)] motion-reduce:transition-none","transition-[width,opacity]",!j&&"pointer-events-none select-none opacity-0"),style:{width:P?R!==null?`${R}px`:"100%":"var(--oc-context-panel-width)"},"aria-hidden":!j,children:[i,e.jsxs("div",{className:ce("relative min-h-0 flex-1 overflow-hidden",b&&"pointer-events-none"),children:[_?e.jsxs("div",{className:ce("absolute inset-0 flex",ae?"flex":"hidden"),children:[e.jsx("div",{className:"h-full min-w-0 flex-1",children:oe?e.jsx(r.Suspense,{fallback:null,children:e.jsx(Mo,{mode:"editor-only"})}):e.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-3 p-6 text-center",children:[e.jsx(q,{name:"file-code",className:"h-12 w-12 text-muted-foreground/50"}),e.jsx("div",{className:"typography-ui-header text-foreground",children:"No file open"}),e.jsx("div",{className:"max-w-sm typography-micro text-muted-foreground",children:"Pick a file from the tree to start editing."})]})}),e.jsx(lo,{visible:l})]}):null,k.map(d=>e.jsx("div",{className:ce("absolute inset-0",S?.id!==d.id&&"hidden"),children:e.jsx(Qs,{initialUrl:d.targetPath??"",directory:n,tabID:d.id})},d.id)),j?Y.filter(d=>S?.id===d.id).map(d=>e.jsx("div",{className:"absolute inset-0",children:e.jsx(r.Suspense,{fallback:null,children:e.jsx(Ao,{hideStackedFileSidebar:!0,stackedDefaultCollapsedAll:!0,pinSelectedFileHeaderToTopOnNavigate:!0,showOpenInEditorAction:!0,diffScope:d.diffScope??(d.stagedDiff?"staged":"working"),onDiffScopeChange:A,targetFilePath:d.targetPath,flushContent:!0,toolbarSlot:h?E:null})})},d.id)):null,ie?e.jsx("div",{className:ce("absolute inset-0",S?.mode==="terminal"?"block":"hidden"),children:e.jsx(an,{visible:j&&S?.mode==="terminal",terminalHeaderSlot:J?H:null})}):null,j&&!ae&&S?.mode!=="browser"&&S?.mode!=="diff"&&S?.mode!=="terminal"?we:null]})]})]})},Ko=150,Xo=500,qo=[],Me=t=>t>=1e6?`${(t/1e6).toFixed(1)}M`:t>=1e3?`${(t/1e3).toFixed(1)}K`:String(t),Je=(t,n)=>{if(!t||typeof t!="object")return;const s=t[n];return typeof s=="number"&&Number.isFinite(s)?s:void 0},Go=t=>t>99?"99+":String(t),Yo=t=>t>=90?"text-[var(--status-error)]":t>=75?"text-[var(--status-warning)]":"text-[var(--status-success)]",Jo=({surface:t,isActive:n,showActivityDot:s,label:a,description:o,badgeCount:m,badgeAriaLabel:w,badgeDescription:u,orderNumber:p,showOrderNumber:g,onSelect:v,chartPercentage:f,chartDetails:l})=>{const{attributes:T,listeners:c,setNodeRef:S,transform:j,transition:P,isDragging:R}=jn({id:t.id}),O=m!=null&&m>0?Go(m):null;return e.jsx("div",{ref:S,style:{transform:Sn.Translate.toString(j),transition:P},className:ce("relative",R&&"z-10 opacity-70"),children:e.jsxs(Oe,{delayDuration:Ko,children:[e.jsx($e,{asChild:!0,children:e.jsxs("button",{type:"button",...T,...c,onClick:()=>v(t),"aria-label":w??a,"aria-pressed":n,className:ce("flex h-9 w-9 touch-none select-none items-center justify-center rounded-md transition-colors",n?"text-primary":"text-muted-foreground hover:text-foreground"),children:[t.id==="context"&&typeof f=="number"?e.jsx(It,{percentage:f,className:"size-[18px] -rotate-90"}):e.jsx(q,{name:t.icon,className:"h-[18px] w-[18px]"}),g&&p!=null?e.jsx("span",{"aria-hidden":"true",className:"absolute right-0 top-0 flex h-4 min-w-4 items-center justify-center rounded-full bg-surface-muted px-1 text-[0.625rem] font-medium leading-none text-muted-foreground",children:p===10?"0":p}):O?e.jsx("span",{"aria-hidden":"true",className:"absolute -right-0.5 -top-0.5 flex h-4 min-w-4 items-center justify-center rounded-full px-1 text-[0.625rem] font-semibold leading-none",style:{backgroundColor:"var(--status-info-background)",color:"var(--status-info)"},children:O}):s?e.jsx("span",{"aria-hidden":"true",className:"absolute right-1 top-1 h-1.5 w-1.5 rounded-full bg-[var(--status-info)]"}):null]})}),e.jsx(We,{side:"left",sideOffset:8,className:t.id==="context"&&l?"p-0 border-0 bg-transparent shadow-none":void 0,children:t.id==="context"&&l?e.jsx("div",{className:"w-[300px] overflow-hidden rounded-lg border border-border/70 bg-[var(--surface-elevated)] p-2 shadow-[0_8px_24px_rgb(0_0_0_/_0.18)]",children:e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-3 rounded-xl px-2.5 py-2.5",children:[e.jsx("span",{className:"flex size-5 shrink-0 items-center justify-center text-muted-foreground",children:e.jsx(It,{percentage:l.percentage,className:"size-[18px] -rotate-90"})}),e.jsx("span",{className:"shrink-0 typography-ui-label text-muted-foreground",children:a}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-right typography-ui-label font-medium text-foreground",children:l.hasData?e.jsxs("span",{className:"inline-flex items-baseline gap-1.5 tabular-nums",children:[e.jsxs("span",{className:ce("font-semibold",Yo(l.percentage)),children:[l.percentage.toFixed(1),"%"]}),e.jsx("span",{className:"text-muted-foreground",children:`${Me(l.totalTokens)}/${Me(l.contextLimit)}`})]}):e.jsx("span",{className:"typography-micro text-muted-foreground",children:"No data yet"})})]}),l.hasData?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex justify-between rounded-xl px-2.5 py-1.5 typography-micro",children:[e.jsx("span",{className:"text-muted-foreground",children:"Used tokens"}),e.jsx("span",{className:"font-medium text-foreground tabular-nums",children:Me(l.totalTokens)})]}),e.jsxs("div",{className:"flex justify-between rounded-xl px-2.5 py-1.5 typography-micro",children:[e.jsx("span",{className:"text-muted-foreground",children:"Context limit"}),e.jsx("span",{className:"font-medium text-foreground tabular-nums",children:Me(l.contextLimit)})]}),e.jsxs("div",{className:"flex justify-between rounded-xl px-2.5 py-1.5 typography-micro",children:[e.jsx("span",{className:"text-muted-foreground",children:"Output limit"}),e.jsx("span",{className:"font-medium text-foreground tabular-nums",children:Me(l.outputLimit)})]}),typeof l.cacheRead=="number"&&typeof l.cacheWrite=="number"?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex justify-between rounded-xl px-2.5 py-1.5 typography-micro",children:[e.jsx("span",{className:"text-muted-foreground",children:"Cache read"}),e.jsx("span",{className:"font-medium text-foreground tabular-nums",children:Me(l.cacheRead)})]}),e.jsxs("div",{className:"flex justify-between rounded-xl px-2.5 py-1.5 typography-micro",children:[e.jsx("span",{className:"text-muted-foreground",children:"Cache write"}),e.jsx("span",{className:"font-medium text-foreground tabular-nums",children:Me(l.cacheWrite)})]})]}):null,typeof l.cacheHitPercent=="number"?e.jsxs("div",{className:"flex justify-between rounded-xl px-2.5 py-1.5 typography-micro",children:[e.jsx("span",{className:"text-muted-foreground",children:"Cache hit"}),e.jsx("span",{className:"font-medium text-foreground tabular-nums",children:`${l.cacheHitPercent.toFixed(1)}%`})]}):null]}):e.jsx("div",{className:"px-2.5 py-2 typography-micro text-muted-foreground",children:o})]})}):e.jsxs("div",{className:"flex flex-col gap-0.5",children:[e.jsx("span",{children:a}),e.jsx("span",{className:"typography-micro text-muted-foreground",children:o}),u?e.jsx("span",{className:"typography-micro text-muted-foreground",children:u}):null]})})]})})},Qo=()=>{const t=Ge(),n=t?qn(t):"",s=ee(x=>n?x.contextPanelByDirectory[n]:void 0),a=ee(x=>x.contextRailOrder),o=ee(x=>x.setContextRailOrder),m=ee(x=>x.openContextSurface),w=ee(x=>x.shortcutOverrides),{screenWidth:u}=st(),{git:p}=xt(),g=cn(n||null),v=pn(n||null),f=fn(x=>x.ensureStatus);r.useEffect(()=>{n&&f(n,p)},[n,f,p]);const l=r.useMemo(()=>Gn("switch_context_surface",w),[w]),[T,c]=r.useState(!1);r.useEffect(()=>{const x=new Set;let A=null,X=!1;const de=ie=>ie.length===1&&ie>="0"&&ie<="9",me=()=>{Et(l,x)?!X&&A===null&&(A=setTimeout(()=>c(!0),Xo)):(X=!1,A!==null&&(clearTimeout(A),A=null),c(!1))},we=ie=>{if(x.add(ie.key.toLowerCase()),de(ie.key)&&Et(l,x)){X=!0,A!==null&&(clearTimeout(A),A=null),c(!1);return}me()},k=ie=>{x.delete(ie.key.toLowerCase()),me()},Y=()=>{x.clear(),X=!1,A!==null&&(clearTimeout(A),A=null),c(!1)};return window.addEventListener("keydown",we,!0),window.addEventListener("keyup",k,!0),window.addEventListener("blur",Y),()=>{window.removeEventListener("keydown",we,!0),window.removeEventListener("keyup",k,!0),window.removeEventListener("blur",Y),A!==null&&clearTimeout(A)}},[l]);const S=wn(pt(bs,{activationConstraint:{distance:8}}),pt(ys,{activationConstraint:{delay:200,tolerance:6}})),j=s?.tabs??qo,P=j.find(x=>x.id===s?.activeTabId)??null,R=s?.isOpen?P?.mode??null:null,O=g?.files.length??0,te=Se(x=>x.currentSessionId),F=Se(x=>!!x.newSessionDraft?.open),re=Ie(x=>x.providers),z=Ie(x=>x.currentProviderId),y=Ie(x=>x.currentModelId),b=Ie(x=>x.getCurrentModel()),G=Ie(x=>x.getModelMetadata);Ie(x=>x.modelsMetadata.size);const H=Fr(r.useCallback(x=>te?x.sessionModelSelections.get(te)??null:null,[te])),$=dn(te??""),V=r.useMemo(()=>{for(let x=$.length-1;x>=0;x-=1){const A=$[x];if(A?.info.role==="assistant")try{if(ht(A).total>0)return A}catch{continue}}return null},[$]),E=r.useMemo(()=>{for(let x=$.length-1;x>=0;x-=1){const A=$[x]?.info;if(A.role!=="user")continue;const X=A.model,de=X?.providerID??X?.providerId,me=X?.modelID??X?.modelId;if(typeof de=="string"&&de.trim()&&typeof me=="string"&&me.trim())return{providerID:de,modelID:me}}return null},[$])??(()=>{const x=V?.info.model,A=x?.providerID??x?.providerId,X=x?.modelID??x?.modelId;return A&&X?{providerID:A,modelID:X}:null})()??(H?{providerID:H.providerId,modelID:H.modelId}:null)??(z&&y?{providerID:z,modelID:y}:null),C=(E?re.find(x=>x.id===E.providerID):void 0)?.models.find(x=>x.id===E?.modelID),M=E?G(E.providerID,E.modelID):void 0,U=Je(C?.limit,"context")??M?.limit?.context??Je(b?.limit,"context")??0,L=Je(C?.limit,"output")??M?.limit?.output??Je(b?.limit,"output")??0,K=V?(()=>{try{return ht(V)}catch{return null}})():null,se=V?.info?.usage,he=se?hn(se):K?.total??0,ue=!F&&he>0&&U>0?Math.min(he/U*100,999):0,be=ue,fe=K?un({input:K.input,cache:{read:K.cacheRead,write:K.cacheWrite}}):null,xe=fe?.hasInput?fe.percent:null,pe=r.useMemo(()=>{const x=!!V&&he>0&&U>0;return{percentage:ue,totalTokens:he,contextLimit:U,outputLimit:L,cacheRead:K?.cacheRead??null,cacheWrite:K?.cacheWrite??null,cacheHitPercent:xe,hasData:x}},[K,xe,U,V,L,ue,he]),I=r.useMemo(()=>Br({railOrder:a,tabs:j}),[a,u,j]),W=r.useCallback(x=>{const{active:A,over:X}=x;if(!X||A.id===X.id)return;const de=zr(ee.getState().contextRailOrder).map(k=>k.id),me=de.indexOf(A.id),we=de.indexOf(X.id);me===-1||we===-1||o(js(de,me,we))},[o]);return n?e.jsx("nav",{"aria-label":"Panel surfaces",className:"flex h-full w-11 flex-shrink-0 flex-col items-center gap-1 bg-background py-2",children:e.jsx(yn,{sensors:S,collisionDetection:bn,onDragEnd:W,children:e.jsx(vn,{items:I.map(x=>x.id),strategy:Ss,children:I.map((x,A)=>{const X=x.id==="git"?St(v):null,de=X?{...x,...X}:x,me=de.label,we=x.id==="git"&&v===!0?O:0,k=we>0?we:null,Y=x.id==="context";return e.jsx(Jo,{surface:de,isActive:R===x.mode,showActivityDot:!1,label:me,description:de.description,badgeCount:k,badgeAriaLabel:k!==null?k===1?`${me}, ${k} changed file`:`${me}, ${k} changed files`:null,badgeDescription:k!==null?k===1?`${k} changed file`:`${k} changed files`:null,chartPercentage:Y?be:void 0,chartDetails:Y?pe:void 0,orderNumber:A+1,showOrderNumber:T,onSelect:ie=>m(n,ie.mode)},x.id)})})})}):null},Zo=(t,n)=>!t||n.length===0?"":JSON.stringify([t,n]),ea=(t,n,s,a)=>!s||a!==s||t.length===0?[]:Ve(t,n,o=>o.name,{limit:10,threshold:.4}),ta=new Set,ut=t=>{if(!t)return"";const n=t.replace(/\\/g,"/"),s=n.startsWith("//");let a=n.replace(/\/+/g,"/");s&&!a.startsWith("//")&&(a=`/${a}`);const o=a==="/",m=/^[A-Za-z]:\/$/.test(a);return!o&&!m&&(a=a.replace(/\/+$/,"")),a},na=()=>{const t=ee(h=>h.isCommandPaletteOpen),n=ee(h=>h.setCommandPaletteOpen),s=ee(h=>h.setActiveMainTab),a=ee(h=>h.setSettingsDialogOpen),o=ee(h=>h.setSettingsPage),m=ee(h=>h.setSessionSwitcherOpen),w=ee(h=>h.toggleSidebar),u=ee(h=>h.openContextOverview),p=ee(h=>h.openContextSurface),g=ee(h=>h.openContextFile),v=ee(h=>h.shortcutOverrides),f=Se(h=>h.openNewSessionDraft),l=Se(h=>h.setCurrentSession),T=Ur({archived:!1}),c=Hr(r.useCallback(h=>t?h.ids:ta,[t])),S=Vr(r.useCallback(h=>t?h.rankById:Kr,[t])),j=Yn(h=>h.currentDirectory),P=Lt(h=>h.getActiveProject()),R=Lt(h=>h.projects),O=Ge(),te=Jn(h=>h.searchFiles),{files:F,git:re}=xt(),z=fn(h=>h.ensureStatus),{isMobile:y}=st(),b=r.useMemo(()=>O?ut(O):null,[O]),[G,H]=r.useState(""),V=Xr(G,200).trim(),ne=G.trim();r.useEffect(()=>{t&&H("")},[t]),r.useEffect(()=>{if(!t||!re)return;const h=setTimeout(()=>{const i=new Set;for(const D of T){const d=at(D);!d||i.has(d)||(i.add(d),z(d,re))}},0);return()=>clearTimeout(h)},[t,T,re,z]);const E=r.useCallback(()=>n(!1),[n]),Q=r.useCallback(h=>()=>{E(),h()},[E]),C=r.useMemo(()=>{const h=[{id:"new-session",title:"New Session",icon:e.jsx(q,{name:"add",className:"mr-2 h-4 w-4"}),shortcutId:"new_chat",searchText:"New Session",onSelect:Q(()=>{s("chat"),m(!1),f()})},{id:"add-project",title:"Add Project",icon:e.jsx(q,{name:"folder-add",className:"mr-2 h-4 w-4"}),searchText:"Add Project",onSelect:Q(()=>{qr.requestDirectoryDialog()})},{id:"toggle-sidebar",title:y?"Show Session Switcher":"Toggle Sidebar",icon:e.jsx(q,{name:"layout-left",className:"mr-2 h-4 w-4"}),shortcutId:"toggle_sidebar",searchText:y?"Show Session Switcher":"Toggle Sidebar",onSelect:Q(()=>{if(y){const{isSessionSwitcherOpen:i}=ee.getState();m(!i)}else w()})},{id:"toggle-terminal",title:"Toggle Terminal",icon:e.jsx(q,{name:"terminal-box",className:"mr-2 h-4 w-4"}),shortcutId:"toggle_terminal",searchText:"Toggle Terminal",onSelect:Q(()=>{j&&p(j,"terminal")})},{id:"context-usage",title:"Show Context Usage",icon:e.jsx(q,{name:"pie-chart",className:"mr-2 h-4 w-4"}),searchText:"Show Context Usage",onSelect:Q(()=>{j&&u(j)})},{id:"open-settings",title:"Open Settings...",icon:e.jsx(q,{name:"settings-3",className:"mr-2 h-4 w-4"}),shortcutId:"open_settings",searchText:"Open Settings...",onSelect:Q(()=>a(!0))}];return Qn()&&h.splice(1,0,{id:"new-mini-chat",title:"New Mini Chat Window",icon:e.jsx(q,{name:"window",className:"mr-2 h-4 w-4"}),shortcutId:"new_mini_chat",searchText:"New Mini Chat Window",onSelect:Q(()=>{en("desktop_open_draft_mini_chat_window",{directory:ut(j||P?.path||""),projectId:P?.id??null}).catch(i=>{console.warn("[command-palette] failed to open draft mini chat window",i)})})}),h},[Q,y,s,m,f,w,p,j,u,a,P?.id,P?.path]),M=r.useMemo(()=>{const h=Zn();return{isWeb:!h&&er(),isDesktop:h,isMobile:y}},[y]),U=r.useMemo(()=>fr.filter(h=>h.slug!=="home").filter(h=>h.isAvailable?h.isAvailable(M):!0).map(h=>{const i=mr(h.slug)??"settings-3",D=(h.keywords??[]).join(" ");return{id:`settings:${h.slug}`,title:h.title,icon:e.jsx(q,{name:i,className:"mr-2 h-4 w-4"}),searchText:`${h.title} ${h.group} ${D}`,onSelect:Q(()=>{o(h.slug),a(!0)})}}),[M,Q,o,a]),L=r.useMemo(()=>Gr(T,c,S),[T,c,S]),K=Yr(),se=r.useCallback((h,i)=>i&&K.get(i)?.trim()||null,[K]),[he,ue]=r.useState([]),[be,fe]=r.useState(""),xe=Zo(b,V);r.useEffect(()=>{if(!t){ue([]),fe("");return}if(!xe){ue([]),fe("");return}if(!b){ue([]),fe("");return}let h=!1;return te(b,V,10,{type:"file"}).then(i=>{h||(ue(i.map(D=>({path:ut(D.path),name:D.name,relativePath:D.relativePath}))),fe(xe))}).catch(()=>{h||(ue([]),fe(xe))}),()=>{h=!0}},[t,b,V,xe,te]);const pe=ne.length>0,I=r.useMemo(()=>pe?Ve(C,ne,h=>h.searchText,{limit:7,noFuzzy:!0}):C.map(h=>({item:h,score:0})),[C,ne,pe]),W=r.useMemo(()=>pe?Ve(U,ne,h=>h.searchText,{limit:7,noFuzzy:!0}):[],[U,ne,pe]),x=r.useMemo(()=>pe?Ve(L,ne,h=>h.title||"",{limit:7,threshold:.2}):L.slice(0,5).map(h=>({item:h,score:0})),[L,ne,pe]),A=r.useMemo(()=>t?ea(he,V,xe,be):[],[t,he,be,xe,V]),X=t&&xe.length>0&&be!==xe,de=r.useMemo(()=>{if(!pe)return[];const h=R.map(i=>({...i,displayName:i.label||i.path.split("/").pop()||i.path,searchText:`${i.label||""} ${i.path}`}));return Ve(h,ne,i=>i.searchText,{limit:7,threshold:.4})},[R,ne,pe]),me=I.map(h=>h.item),we=W.map(h=>h.item),k=x.map(h=>h.item),Y=pe?A.map(h=>h.item):[],ie=pe?de.map(h=>h.item):[],_=r.useMemo(()=>{if(!pe)return["commands","sessions"];const h=D=>D.length?D[0].score:1/0,i=[{key:"commands",score:h(I)},{key:"settings",score:h(W)},{key:"sessions",score:h(x)},{key:"files",score:h(A)},{key:"projects",score:h(de)}];return i.sort((D,d)=>D.score-d.score),i.map(D=>D.key)},[pe,I,W,x,A,de]),oe=r.useCallback(h=>{E(),l(h.id,at(h))},[E,l]),ae=r.useCallback(async h=>{if(!b)return;const i=await mn(F,h,{directory:b});if(!i.ok){je.error(gn(i.reason));return}g(b,h),E()},[b,F,g,E]),J=r.useCallback((h,i)=>{E(),f({selectedProjectId:h,directoryOverride:i})},[E,f]),B=r.useCallback(h=>rn(sn(h,v)),[v]);return e.jsxs(wt,{open:t,onOpenChange:n,children:[e.jsxs(bt,{className:"sr-only",children:[e.jsx(vt,{children:"Command Palette"}),e.jsx(jt,{children:"Search files, sessions, and commands."})]}),e.jsx(yt,{className:"overflow-hidden p-0",showCloseButton:!0,children:e.jsxs(Jr,{shouldFilter:!1,className:"[&_[cmdk-group-heading]]:text-muted-foreground [&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group]]:px-2 [&_[cmdk-group]:not([hidden])_~[cmdk-group]]:pt-0 [&_[cmdk-input-wrapper]_svg]:h-4 [&_[cmdk-input-wrapper]_svg]:w-4 [&_[cmdk-input]]:h-8 [&_[cmdk-item]]:px-2 [&_[cmdk-item]]:py-1.5 [&_[cmdk-item]_svg]:h-4 [&_[cmdk-item]_svg]:w-4 [&_[cmdk-item]]:typography-meta",children:[e.jsx(Qr,{value:G,onValueChange:H,placeholder:"Search files, sessions, commands..."}),e.jsxs(Zr,{children:[e.jsx(es,{children:"No results found."}),_.map(h=>h==="commands"&&me.length>0?e.jsx(Ue,{children:me.map(i=>e.jsxs(He,{value:i.id,onSelect:i.onSelect,children:[i.icon,e.jsx("span",{children:i.title}),i.shortcutId?e.jsx(ts,{children:B(i.shortcutId)}):null]},i.id))},"commands"):h==="settings"&&we.length>0?e.jsx(Ue,{children:we.map(i=>e.jsxs(He,{value:i.id,onSelect:i.onSelect,children:[i.icon,e.jsx("span",{children:i.title})]},i.id))},"settings"):h==="sessions"&&k.length>0?e.jsx(Ue,{children:k.map(i=>{const D=Cn(i),d=at(i),N=se(i.id,d);return e.jsxs(He,{value:`session:${i.id}`,onSelect:()=>oe(i),children:[e.jsx(q,{name:"chat-ai-3",className:"mr-2 h-4 w-4"}),e.jsx("span",{className:"truncate",children:D}),N?e.jsxs("span",{className:"ml-auto inline-flex items-center gap-1 text-muted-foreground typography-meta",children:[e.jsx(q,{name:"git-branch",className:"h-3 w-3"}),e.jsx("span",{className:"truncate max-w-[160px]",children:N})]}):null]},i.id)})},"sessions"):h==="files"&&Y.length>0?e.jsx(Ue,{children:Y.map(i=>{const D=tr(i.relativePath||i.name,{maxLength:80});return e.jsxs(He,{value:`file:${i.path}`,onSelect:()=>{ae(i.path)},children:[e.jsx(mt,{filePath:i.path,className:"mr-2 size-4 shrink-0"}),e.jsx("span",{className:"truncate","aria-label":i.relativePath,children:D})]},`file:${i.path}`)})},"files"):h==="projects"&&ie.length>0?e.jsx(Ue,{children:ie.map(i=>{const D=i.displayName;return e.jsxs(He,{value:`project:${i.id}`,onSelect:()=>J(i.id,i.path),children:[e.jsx(q,{name:"folder",className:"mr-2 h-4 w-4"}),e.jsx("span",{className:"truncate",children:D}),e.jsx("span",{className:"ml-auto inline-flex items-center text-muted-foreground typography-meta truncate max-w-[160px]",children:i.path})]},`project:${i.id}`)})},"projects"):null),X?e.jsx("div",{className:"px-3 py-2 typography-meta text-muted-foreground",children:"Searching files..."}):null]})]})})]})},ra=(t,n,s)=>rr(t)?rn(sn(t,s)):n,sa=()=>{const t=ee(m=>m.isHelpDialogOpen),n=ee(m=>m.setHelpDialogOpen),s=ee(m=>m.shortcutOverrides),a=nr(),o=[{categoryKey:"Navigation & Commands",items:[{id:"open_command_palette",descriptionKey:"Open Command Palette",icon:"command",keys:""},{id:"open_help",descriptionKey:"Show Keyboard Shortcuts (this dialog)",icon:"question",keys:""},{id:"toggle_sidebar",descriptionKey:"Toggle Session Sidebar",icon:"layout-left",keys:""},{id:"add_selection_to_chat",descriptionKey:"Add Selection to Chat",icon:"add",keys:""},{id:"open_model_selector",descriptionKey:"Open Model Selector",icon:"ai-generate-2",keys:""},{keys:["↑↓"],descriptionKey:"Navigate Models (in picker)",icon:"ai-generate-2"},{keys:["←→"],descriptionKey:"Adjust Thinking Mode (in picker, when supported)",icon:"brain-ai-3"},{id:"cycle_thinking_variant",descriptionKey:"Cycle thinking (global shortcut)",icon:"brain-ai-3",keys:""},{keys:[`Shift + Alt + ${a} + N`],descriptionKey:"New Window (desktop only)",icon:"window"}]},{categoryKey:"Session Management",items:[{id:"new_chat",descriptionKey:"Create New Session",icon:"add",keys:""},{id:"focus_input",descriptionKey:"Focus Chat Input",icon:"text",keys:""},{id:"cycle_session_folder",descriptionKey:"Cycle session folder",icon:"folder-open",keys:""},{id:"cycle_draft_folder",descriptionKey:"Cycle draft folder",icon:"folder-3",keys:""},{id:"open_timeline_dialog",descriptionKey:"Open conversation timeline",icon:"history",keys:""},{id:"abort_run",descriptionKey:"Abort active run (double press)",icon:"close-circle",keys:""}]},{categoryKey:"Panels",items:[{id:"open_right_sidebar",descriptionKey:"Open right sidebar",icon:"layout-right",keys:""},{id:"toggle_terminal",descriptionKey:"helpDialog.item.toggleTerminalDock",icon:"window",keys:""},{keys:[`${a} + 1...0`],descriptionKey:"Switch Context Panel Surface (number key)",icon:"layout-right"}]},{categoryKey:"Interface",items:[{id:"cycle_theme",descriptionKey:"Cycle Theme (Light → Dark → System)",icon:"palette",keys:""},{id:"toggle_services_menu",descriptionKey:"helpDialog.item.toggleServicesMenu",icon:"stack",keys:""},{id:"open_settings",descriptionKey:"Open Settings",icon:"settings-3",keys:""}]}];return e.jsx(wt,{open:t,onOpenChange:n,children:e.jsxs(yt,{className:"w-[92vw] max-w-[1120px] h-[84vh] max-h-[900px] flex flex-col overflow-hidden",children:[e.jsxs(bt,{children:[e.jsxs(vt,{className:"flex items-center gap-2",children:[e.jsx(q,{name:"command",className:"h-5 w-5"}),"Keyboard Shortcuts"]}),e.jsx(jt,{children:"Use these keyboard shortcuts to navigate PiChamber efficiently"})]}),e.jsx("div",{className:"flex-1 overflow-y-auto mt-3 pr-1",children:e.jsx("div",{className:"grid grid-cols-1 gap-6 md:grid-cols-2 md:gap-x-10",children:o.map(m=>e.jsxs("div",{className:"min-w-0 break-inside-avoid",children:[e.jsx("h3",{className:"typography-meta font-semibold text-muted-foreground uppercase tracking-wider mb-2",children:m.categoryKey}),e.jsx("div",{className:"space-y-1",children:m.items.map(w=>{const u=w.id?ra(w.id,Array.isArray(w.keys)?w.keys[0]:w.keys,s):Array.isArray(w.keys)?w.keys:w.keys.split(" / ");return e.jsxs("div",{className:"flex items-center justify-between py-1 px-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[w.icon&&e.jsx(q,{name:w.icon,className:"h-3.5 w-3.5 text-muted-foreground"}),e.jsx("span",{className:"typography-meta",children:w.descriptionKey})]}),e.jsx("div",{className:"flex items-center gap-1",children:(Array.isArray(u)?u:[u]).map((p,g)=>e.jsxs(r.Fragment,{children:[g>0&&e.jsx("span",{className:"typography-meta text-muted-foreground mx-1",children:"or"}),e.jsx("kbd",{className:"inline-flex items-center gap-1 px-1.5 py-0.5 typography-meta font-mono bg-muted rounded border border-border/20",children:p})]},`${p}-${g}`))})]},w.id||w.descriptionKey)})})]},m.categoryKey))})})]})})},oa=r.createContext(null),aa=({children:t,value:n})=>e.jsx(oa.Provider,{value:n,children:t}),Zt=De(()=>Ee(()=>import("./GitView-Cg_5UU7E.js"),__vite__mapDeps([129,24,1,2,9,4,3,5,6,7,8,10,11,12,13,14,15,16,17,18,19,20,21,22,23,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,111,112,113,114,115,116,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,117,118,130])).then(t=>({default:t.GitView}))),ia=De(()=>Ee(()=>import("./DiffView-CZyHHAOB.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,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119])).then(t=>({default:t.DiffView}))),la=De(()=>Ee(()=>import("./FilesView-BJYLFR3H.js"),__vite__mapDeps([120,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,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,117,118,99,100,84,85,86,87,88,89,90,91,92,93,94,95,96,97,121,122,111,112,113,114,115,116,123,124,81,82,83,98,101,102,103,104,105,106,107,125,126,127,128])).then(t=>({default:t.FilesView}))),ca=De(()=>Ee(()=>import("./DiagramView-DTW5jwK3.js"),__vite__mapDeps([131,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,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,121,122])).then(t=>({default:t.DiagramView}))),da=De(()=>Ee(()=>import("./SettingsView-UIaAyjTo.js").then(t=>t.a),__vite__mapDeps([132,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,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,111,112,113,114,115,116,133,134,130])).then(t=>({default:t.SettingsView}))),ua=De(()=>Ee(()=>import("./SettingsWindow-D4jZHl8X.js"),__vite__mapDeps([135,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,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,132,111,112,113,114,115,116,133,134,130])).then(t=>({default:t.SettingsWindow}))),ha=()=>{const t=ee(C=>C.isSidebarOpen),n=ee(C=>C.activeMainTab),s=ee(C=>C.setIsMobile),a=ee(C=>C.isSessionSwitcherOpen),o=ee(C=>C.isSettingsDialogOpen),m=ee(C=>C.setSettingsDialogOpen),[w,u]=r.useState(!1);r.useEffect(()=>{o&&u(!0)},[o]),r.useEffect(()=>{const C=()=>ee.getState().closeMainSurfaces(),M=Se.subscribe((L,K)=>{const se=!!L.currentSessionId&&L.currentSessionId!==K.currentSessionId,he=!!L.newSessionDraft?.open&&L.newSessionDraft!==K.newSessionDraft;(se||he)&&C()}),U=ee.subscribe((L,K)=>{L.activeMainTab!==K.activeMainTab&&C()});return()=>{M(),U()}},[]);const{isMobile:p}=st(),g=r.useRef(!1),[v,f]=r.useState(!1),[l,T]=r.useState(!1),[c,S]=r.useState(!1),[j,P]=r.useState(!1),R=r.useCallback(C=>{f(C),ee.getState().setSessionSwitcherOpen(C)},[]),O=r.useRef(typeof window>"u"?0:window.innerWidth),te=r.useRef(null),F=r.useRef(!1),re=r.useRef(!1),z=r.useRef(!1),y=r.useRef(null),b=r.useRef(null),G=Ot(-O.current),H=Ce.useRef(0),$=Ot(O.current),V=Ce.useRef(0);Ce.useEffect(()=>{p&&(H.current=window.innerWidth,V.current=window.innerWidth)},[p]),Ce.useEffect(()=>{if(!p)return;const C=()=>{const M=window.innerWidth;H.current=M,V.current=M,v||G.get()<-10&&G.set(-M),l||$.get()>10&&$.set(M)};return window.addEventListener("resize",C),window.addEventListener("orientationchange",C),()=>{window.removeEventListener("resize",C),window.removeEventListener("orientationchange",C)}},[p,G,$,v,l]),Ce.useEffect(()=>{if(!p){S(!1);return}v&&S(!0);const C=H.current||O.current||(typeof window<"u"?window.innerWidth:0),M=Ye(G,v?0:-C,{type:"spring",stiffness:400,damping:35,mass:.8});return y.current=M,()=>M.stop()},[v,p,G]),Ce.useEffect(()=>{if(!p){P(!1);return}l&&P(!0);const C=V.current||O.current||(typeof window<"u"?window.innerWidth:0),M=Ye($,l?0:C,{type:"spring",stiffness:400,damping:35,mass:.8});return b.current=M,()=>M.stop()},[p,l,$]),Ce.useEffect(()=>{if(p)return G.on("change",C=>{const M=H.current||O.current,U=v||C>-M+.5;S(L=>L===U?L:U)})},[p,G,v]),Ce.useEffect(()=>{if(p)return $.on("change",C=>{const M=V.current||O.current,U=l||C<M-.5;P(L=>L===U?L:U)})},[p,l,$]),Ce.useEffect(()=>{p&&!a&&v&&R(!1)},[a,p,v,R]),Ce.useEffect(()=>{if(!p){g.current=!1;return}g.current||(g.current=!0,R(!1),T(!1))},[p,R]),Ce.useEffect(()=>{if(!p||n!=="chat"||v||l||o)return;let C=!1,M;const U=L=>{M=window.setTimeout(()=>{if(C)return;const K=Se.getState(),se=ee.getState();if(!(se.activeMainTab!=="chat"||se.isSettingsDialogOpen||K.currentSessionId||K.newSessionDraft?.open)){if(K.isLoading){U(250);return}K.openNewSessionDraft({automatic:!0})}},L)};return U(500),()=>{C=!0,M!==void 0&&window.clearTimeout(M)}},[n,p,o,v,l]),Ce.useEffect(()=>{!p||!o||(R(!1),T(!1))},[p,o,R]),r.useEffect(()=>{ee.getState().isMobile!==p&&s(p)},[p,s]);const ne=r.useCallback(()=>{v&&R(!1),T(!l)},[v,l,R]);gr(te,{enabled:p,leftOpen:v,rightOpen:l,leftWidth:()=>H.current||O.current||(typeof window<"u"?window.innerWidth:0),rightWidth:()=>V.current||O.current||(typeof window<"u"?window.innerWidth:0),onLeftProgress:C=>{const M=H.current||O.current||(typeof window<"u"?window.innerWidth:0);G.set(M*(C-1))},onRightProgress:C=>{const M=V.current||O.current||(typeof window<"u"?window.innerWidth:0);$.set(M*(1-C))},onLeftOpen:()=>{l&&T(!1),R(!0)},onLeftClose:()=>R(!1),onRightOpen:()=>{v&&R(!1),T(!0)},onRightClose:()=>T(!1),onDragStart:C=>{F.current=!0,C==="left"?(re.current=v,y.current?.stop(),c||S(!0)):(z.current=l,b.current?.stop(),j||P(!0))},onDragEnd:(C,M)=>{if(F.current=!1,C==="left"&&typeof M=="boolean"){const U=re.current;if(M===U){const L=H.current||O.current||(typeof window<"u"?window.innerWidth:0),K=Ye(G,U?0:-L,{type:"spring",stiffness:400,damping:35,mass:.8});y.current=K}}if(C==="right"&&typeof M=="boolean"){const U=z.current;if(M===U){const L=V.current||O.current||(typeof window<"u"?window.innerWidth:0),K=Ye($,U?0:L,{type:"spring",stiffness:400,damping:35,mass:.8});b.current=K}}}});const E=r.useMemo(()=>{if(!p&&n!=="terminal"&&n!=="diagram"||p&&n==="git"&&(l||j))return null;switch(n){case"git":return e.jsx(r.Suspense,{fallback:null,children:e.jsx(Zt,{isActive:!0})});case"diff":return e.jsx(r.Suspense,{fallback:null,children:e.jsx(ia,{})});case"terminal":return e.jsx(an,{onCloseView:()=>ee.getState().setActiveMainTab("chat")});case"files":return e.jsx(r.Suspense,{fallback:null,children:e.jsx(la,{})});case"diagram":return e.jsx(r.Suspense,{fallback:null,children:e.jsx(ca,{})});default:return null}},[n,p,j,l]),Q=n==="chat";return e.jsxs(xr,{children:[e.jsx(wr,{}),e.jsxs("div",{"data-page-scroll-lock":"true",className:ce("main-content-safe-area",p?"flex h-[100dvh] flex-col":"relative flex h-[100dvh]","bg-background"),children:[e.jsx(na,{}),e.jsx(sa,{}),e.jsx(yr,{}),p?e.jsxs(aa,{value:{leftDrawerOpen:v,rightDrawerOpen:l,toggleLeftDrawer:()=>{const C=!v;l&&T(!1),R(C)},toggleRightDrawer:ne,leftDrawerX:G,rightDrawerX:$,leftDrawerWidth:H,rightDrawerWidth:V,setMobileLeftDrawerOpen:R,setRightSidebarOpen:T},children:[!o&&e.jsx(Tt,{onToggleLeftDrawer:()=>{const C=!v;l&&T(!1),R(C)},onToggleRightDrawer:()=>{ne()},leftDrawerOpen:v,rightDrawerOpen:l}),e.jsx("div",{"data-page-scroll-lock":"true",className:ce("flex flex-1 overflow-hidden relative",o&&"hidden"),children:e.jsxs("main",{ref:te,className:"w-full h-full overflow-hidden bg-background relative","data-page-scroll-lock":"true",style:{touchAction:"pan-x pan-y"},children:[e.jsx("div",{className:ce("absolute inset-0",!Q&&"invisible"),children:e.jsx(Ne,{children:e.jsx(_t,{active:Q&&!o})})}),E&&e.jsx("div",{className:"absolute inset-0",children:e.jsx(Ne,{children:E})}),e.jsx(Ne,{children:e.jsx(Dt,{})}),e.jsx($t.div,{className:ce("absolute inset-0 z-20 bg-sidebar",!c&&"pointer-events-none invisible"),"data-page-scroll-lock":"true",style:{x:G},"aria-hidden":!v,children:e.jsx(Ne,{children:e.jsx(At,{mobileVariant:!0,isVisible:c})})}),e.jsx($t.div,{className:ce("absolute inset-0 z-20 bg-sidebar",!j&&"pointer-events-none invisible"),"data-page-scroll-lock":"true",style:{x:$},"aria-hidden":!l,children:e.jsx(Ne,{children:l||j?e.jsx(r.Suspense,{fallback:null,children:e.jsx(Zt,{isActive:l})}):null})})]})}),o&&e.jsx("div",{className:"absolute inset-0 z-10 bg-background",style:{paddingTop:"var(--oc-safe-area-top, 0px)"},children:e.jsx(Ne,{children:e.jsx(r.Suspense,{fallback:null,children:e.jsx(da,{onClose:()=>m(!1)})})})})]}):e.jsxs(e.Fragment,{children:[e.jsx(br,{}),e.jsxs("div",{className:"flex flex-1 overflow-hidden","data-page-scroll-lock":"true",children:[e.jsx(Es,{isOpen:t,isMobile:p,children:e.jsx(At,{isVisible:t})}),e.jsxs("div",{className:"relative flex flex-1 min-w-0 flex-col overflow-hidden bg-background","data-page-scroll-lock":"true",children:[e.jsx(Tt,{}),e.jsxs("div",{className:"relative flex flex-1 min-h-0 overflow-hidden bg-background","data-page-scroll-lock":"true",children:[e.jsx("div",{className:"relative flex flex-1 min-w-0 flex-col overflow-hidden border-t border-border bg-background","data-page-scroll-lock":"true",children:e.jsx("div",{className:"flex flex-1 min-h-0 overflow-hidden","data-page-scroll-lock":"true",children:e.jsxs("div",{className:"relative flex flex-1 min-h-0 min-w-0 overflow-hidden","data-page-scroll-lock":"true","data-chat-area":"true",children:[e.jsxs("main",{className:"flex-1 overflow-hidden bg-background relative","data-page-scroll-lock":"true",children:[e.jsx("div",{className:ce("absolute inset-0",!Q&&"invisible"),children:e.jsx(Ne,{children:e.jsx(_t,{active:Q&&!o})})}),E&&e.jsx("div",{className:"absolute inset-0",children:e.jsx(Ne,{children:E})}),e.jsx(Ne,{children:e.jsx(Dt,{})})]}),e.jsx(Vo,{})]})})}),e.jsx("div",{className:"border-t border-border","data-page-scroll-lock":"true",children:e.jsx(Ne,{children:e.jsx(Qo,{})})})]})]})]}),w?e.jsx(r.Suspense,{fallback:null,children:e.jsx(ua,{open:o,onOpenChange:m})}):null]})]})]})},pa=()=>(os(),jr(),e.jsxs(Sr,{children:[e.jsx(as,{embeddedBackgroundWorkEnabled:!0}),e.jsx(is,{}),e.jsx(ha,{}),e.jsx(Cr,{}),e.jsx(ls,{}),e.jsx(cs,{})]}));function fa({apis:t}){const n=t??on(),[s,a]=r.useState(0);return r.useEffect(()=>sr(o=>{o.runtimeKey!==o.previousRuntimeKey&&(vr(o),a(m=>m+1))}),[]),r.useEffect(()=>{or()},[s]),r.useEffect(()=>{n&&ar(n)},[n]),n?e.jsx(Ne,{children:e.jsx("div",{className:"h-full w-full overflow-hidden bg-background text-foreground",children:e.jsx(ns,{apis:n,children:e.jsx(rs,{children:e.jsx(ss,{children:e.jsx(pa,{})})},s)})})}):e.jsx(Ne,{children:e.jsx("div",{className:"h-full w-full overflow-hidden bg-background text-foreground"})})}const Wn=document.getElementById("root");if(!Wn)throw new Error("Root element not found");Fn.createRoot(Wn).render(e.jsx(Ce.StrictMode,{children:e.jsx(ds,{children:e.jsx(us,{children:e.jsx(fa,{apis:on()??void 0})})})}));
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/renderMobileApp-
|
|
2
|
-
import{_ as a}from"./vendor-vite-runtime-DD1OZmLC.js";import{a as m,e as f}from"./index-
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/renderMobileApp-xCdVzvyf.js","assets/vendor-react-B5Z1Mdn3.js","assets/vendor-scheduler-7OC5HNn7.js","assets/vendor-katex-CNckGUMB.js","assets/vendor-katex-Cp579UoJ.css","assets/index-yWgKW2Fx.js","assets/vendor-zustand-GVb4H8HE.js","assets/vendor-clsx-B-dksMZM.js","assets/vendor-tailwind-merge-CPcsbTWB.js","assets/vendor-fuse.js-Dw8P0qyA.js","assets/index-C8NYcA8-.css","assets/usePushVisibilityBeacon-swMQLm-i.js","assets/useAppFontEffects-BgK55NDM.js","assets/vendor-base-ui-vkqQ2P9o.js","assets/vendor-floating-ui-utils-BzXdqYpP.js","assets/vendor-floating-ui-react-dom-BZOGXAGe.js","assets/vendor-floating-ui-dom-WyXykhNi.js","assets/vendor-floating-ui-core-CXmKXOXc.js","assets/vendor-use-sync-external-store-D0AXkdQC.js","assets/vendor-simplewebauthn-browser-VDA66rT_.js","assets/vendor-sonner-BDtm25td.js","assets/vendor-codemirror-view-Ct4T37Ue.js","assets/vendor-codemirror-state-CNWM3Q8V.js","assets/vendor-marijn-find-cluster-break-DXwl3gUT.js","assets/vendor-style-mod-NZ5MEPvj.js","assets/vendor-w3c-keyname-Vcq4gwWv.js","assets/vendor-crelt-C8TCjufn.js","assets/vendor-vite-runtime-DD1OZmLC.js","assets/vendor-class-variance-authority-5VPnzWs2.js","assets/runtimeSurface-C_3mcJ01.js","assets/vendor-dnd-kit-core-C9qcAm_1.js","assets/vendor-dnd-kit-utilities-DTY1C6ST.js","assets/vendor-dnd-kit-accessibility-DZKKhs9S.js","assets/vendor-dnd-kit-sortable-D8ozj8M-.js","assets/vendor-cmdk-zXx6sGnS.js","assets/vendor-radix-ui-react-dialog-D2yhEu2p.js","assets/vendor-radix-ui-primitive-Dc_FVRD7.js","assets/vendor-radix-ui-react-compose-refs-8xy6TJML.js","assets/vendor-radix-ui-react-context-CFsX-AUC.js","assets/vendor-radix-ui-react-id-D2kS9K1j.js","assets/vendor-radix-ui-react-use-layout-effect-C8Yrsaph.js","assets/vendor-radix-ui-react-use-controllable-state-LiqmKSXO.js","assets/vendor-radix-ui-react-dismissable-layer-DrorBNg9.js","assets/vendor-radix-ui-react-primitive-DkH8dMOR.js","assets/vendor-radix-ui-react-slot-BIDFZX0-.js","assets/vendor-radix-ui-react-use-callback-ref-BwDcSoGV.js","assets/vendor-radix-ui-react-use-escape-keydown-DTkqjenV.js","assets/vendor-radix-ui-react-focus-scope-D2BkImwt.js","assets/vendor-radix-ui-react-portal-YgCRIyi7.js","assets/vendor-radix-ui-react-presence-D432pCMB.js","assets/vendor-radix-ui-react-focus-guards-BfdFmL7c.js","assets/vendor-react-remove-scroll-vR1dy1aP.js","assets/vendor-tslib-De9GV7Vy.js","assets/vendor-react-remove-scroll-bar-CSAHp1YF.js","assets/vendor-react-style-singleton-Ctw6HnYx.js","assets/vendor-get-nonce-C-Z93AgS.js","assets/vendor-use-sidecar-Vv4V8Nd1.js","assets/vendor-use-callback-ref-CVVuCyLj.js","assets/vendor-aria-hidden-DvXkyWUv.js","assets/vendor-codemirror-language-BByA_dGF.js","assets/vendor-lezer-common-B3-cUCR_.js","assets/vendor-lezer-highlight-CDMHUZ74.js","assets/vendor-codemirror-lang-javascript-DuOEwJ3f.js","assets/vendor-lezer-javascript-D7Tj24ot.js","assets/vendor-lezer-lr-bhwg1HMg.js","assets/vendor-codemirror-autocomplete-wd6iRebq.js","assets/vendor-codemirror-lang-json-CZ07HmNC.js","assets/vendor-lezer-json-Iaex0UN-.js","assets/vendor-codemirror-lang-css-djiuoTi8.js","assets/vendor-lezer-css-C5xB6jxd.js","assets/vendor-codemirror-lang-html-CKHqhW5R.js","assets/vendor-lezer-html-C0I1p52t.js","assets/vendor-codemirror-lang-markdown-DtcZDGqe.js","assets/vendor-lezer-markdown-C6g-d6P3.js","assets/vendor-codemirror-language-data-BzeePAPn.js","assets/vendor-codemirror-lang-python-DzzokVau.js","assets/vendor-lezer-python-CvuFxeZl.js","assets/vendor-codemirror-commands-DYppkHEk.js","assets/vendor-tanstack-react-virtual-2skouoFw.js","assets/vendor-tanstack-virtual-core-Dubg10g5.js","assets/vendor-framer-motion-CfplGuM0.js","assets/vendor-motion-dom-DhJ-sYS5.js","assets/vendor-motion-utils-CKEGc_YG.js","assets/runtimeEndpointReset-CT3WShpj.js","assets/SessionUnreadDot-1nV0Z2ZA.js","assets/vendor-xterm-xterm-CrXqRur4.js","assets/vendor-xterm-xterm-DDGTF8rc.css","assets/permissionStore-iKN1K2_x.js","assets/runtimeEndpointReset-BV3KOtdA.css","assets/vendor-capacitor-core-B4EWRrHz.js","assets/vendor-aparajita-capacitor-secure-storage-5IShChL0.js","assets/SettingsView-UIaAyjTo.js","assets/vendor-qrcode-B0KNSajT.js","assets/vendor-dijkstrajs-COg3n3zL.js","assets/collapsible-6mCYf7Ky.js","assets/useSwitcherItems-CrS-F6DY.js","assets/main-DcAMXRSi.js","assets/contextFileOpenGuard-CKyf-TZ7.js","assets/useFilesViewSearch-CWx24PZg.js"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{_ as a}from"./vendor-vite-runtime-DD1OZmLC.js";import{a as m,e as f}from"./index-yWgKW2Fx.js";import{r as w}from"./runtimeSurface-C_3mcJ01.js";import"./vendor-katex-CNckGUMB.js";import"./vendor-zustand-GVb4H8HE.js";import"./vendor-react-B5Z1Mdn3.js";import"./vendor-scheduler-7OC5HNn7.js";import"./vendor-clsx-B-dksMZM.js";import"./vendor-tailwind-merge-CPcsbTWB.js";import"./vendor-fuse.js-Dw8P0qyA.js";function _(t={}){const{immediate:r=!1,onNeedRefresh:i,onOfflineReady:n,onRegistered:s,onRegisteredSW:c,onRegisterError:d}=t;let o,u;const l=async(e=!0)=>{await u};async function p(){if("serviceWorker"in navigator){if(o=await a(async()=>{const{Workbox:e}=await import("./vendor-workbox-window-BIl4cyR9.js");return{Workbox:e}},[]).then(({Workbox:e})=>new e("/sw.js",{scope:"/",type:"classic"})).catch(e=>{d?.(e)}),!o)return;o.addEventListener("activated",e=>{(e.isUpdate||e.isExternal)&&window.location.reload()}),o.addEventListener("installed",e=>{e.isUpdate||n?.()}),o.register({immediate:r}).then(e=>{c?c("/sw.js",e):s?.(e)}).catch(e=>{d?.(e)})}}return u=p(),l}const v=w(),g=()=>!(!("serviceWorker"in navigator)||!window.isSecureContext||window.location.protocol!=="http:"&&window.location.protocol!=="https:"||document.prerendering||String(document.visibilityState)==="prerender"),S=t=>{let r=!1;const i=()=>{r||g()&&(r=!0,t())},n=()=>{setTimeout(i,0)};document.readyState==="complete"?n():window.addEventListener("load",n,{once:!0}),(document.prerendering||String(document.visibilityState)==="prerender")&&document.addEventListener("visibilitychange",i,{once:!0})},E=()=>{S(()=>{try{_({onRegisterError(t){console.warn("[PWA] service worker registration skipped:",t)}})}catch(t){console.warn("[PWA] service worker registration skipped:",t)}})},R=async()=>{if(window.__PICHAMBER_RUNTIME_APIS__=m(),v==="mobile"){const{renderMobileApp:t}=await a(async()=>{const{renderMobileApp:r}=await import("./renderMobileApp-xCdVzvyf.js").then(i=>i.r);return{renderMobileApp:r}},__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,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95]));t();return}await f(),await a(()=>import("./main-DcAMXRSi.js"),__vite__mapDeps([96,1,2,3,4,5,6,7,8,9,10,27,83,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,84,85,86,87,88,97,98]))};R();E();
|