@bigduu/lotus-next 2026.10.32 → 2026.11.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/asset-manifest.json +137 -133
- package/dist/assets/{AgentService-Cq8E6qgL.js → AgentService-BcSV4V6G.js} +2 -2
- package/dist/assets/{BrowserPane-Uhp3ve04.js → BrowserPane-Qpdtlb6C.js} +1 -1
- package/dist/assets/{CommandPalette-DZuHQOKu.js → CommandPalette-FYYof7PJ.js} +1 -1
- package/dist/assets/{ConversationClearDialogContent-Dz_KhgM2.js → ConversationClearDialogContent-DapZ3K4B.js} +1 -1
- package/dist/assets/{ErrorBoundary-CHIy5vq_.js → ErrorBoundary-Cd8Mqhm-.js} +1 -1
- package/dist/assets/ErrorBoundary-DrkdmL6R.js +1 -0
- package/dist/assets/{ExternalLinkDialog-BZfVZnBd.js → ExternalLinkDialog-DxecTv9b.js} +1 -1
- package/dist/assets/{JianduProjectMemories-DeRiyJXQ.js → JianduProjectMemories-BSU_YgtD.js} +1 -1
- package/dist/assets/{Markdown-BfHCf8-S.js → Markdown-sn8uDNJU.js} +2 -2
- package/dist/assets/MermaidChart-CK128dqg.js +1 -0
- package/dist/assets/{NewChatWorktreeControl-D0T1NyvS.js → NewChatWorktreeControl-BVvX1tE3.js} +1 -1
- package/dist/assets/{ProjectWorkBoard-BppPrBYK.js → ProjectWorkBoard-BDerd2KC.js} +1 -1
- package/dist/assets/{RightWorkbench-Cd1XrFXL.js → RightWorkbench-ClTIc5yT.js} +1 -1
- package/dist/assets/{RightWorkbenchSurface-CBJc97Ts.js → RightWorkbenchSurface-5chVm3Q5.js} +1 -1
- package/dist/assets/Root-Cbi1Q37c.js +112 -0
- package/dist/assets/{RunDiagnosticsDialogContent-BuGC65ol.js → RunDiagnosticsDialogContent-C83miiCb.js} +1 -1
- package/dist/assets/Settings-6l99-5Ca.js +9 -0
- package/dist/assets/SidebarProjectDrag-B8jeZZwD.js +1 -0
- package/dist/assets/{StreamdownMarkdown-74wGCpxb.js → StreamdownMarkdown-BYrL8Htd.js} +2 -2
- package/dist/assets/{StreamdownMermaid-nnJlHSls.js → StreamdownMermaid-BqMCspWP.js} +1 -1
- package/dist/assets/StreamdownMermaid-CK128dqg.js +1 -0
- package/dist/assets/{SupervisorManagedSessions-VbVRjD5Z.js → SupervisorManagedSessions-DDL1goCC.js} +1 -1
- package/dist/assets/{SupervisorProjectScopeDialog-DUlnfIv1.js → SupervisorProjectScopeDialog-BRpx_B7f.js} +1 -1
- package/dist/assets/{TicketWorkPanel-Ervlq3kg.js → TicketWorkPanel-CoPV3q8A.js} +1 -1
- package/dist/assets/{WorkflowRunsContent-Dn_wa8kY.js → WorkflowRunsContent-lUfm3WNf.js} +1 -1
- package/dist/assets/appStore-DJRgb7nl.js +14 -0
- package/dist/assets/{command-DV03FsGg.js → command-CKwm5a6S.js} +3 -3
- package/dist/assets/en-US-CsZdRXMR.js +5 -0
- package/dist/assets/{index-CGBGoEKA.js → index-BziNk-bd.js} +3 -3
- package/dist/assets/managedSessions-CNlNA0Gf.js +1 -0
- package/dist/assets/managedSessions-Df_XdXaQ.js +2 -0
- package/dist/assets/{renderPdf-DeetBKqh.js → renderPdf-Cug6wuGM.js} +1 -1
- package/dist/assets/{responsive-dialog-ZHgo4VEm.js → responsive-dialog-ChvCU7Pw.js} +1 -1
- package/dist/assets/{runDiagnostic-CjBJ7eom.js → runDiagnostic-DBibDMFH.js} +1 -1
- package/dist/assets/{runDiagnostic-_B6jaLEK.js → runDiagnostic-DJ_i4o1q.js} +1 -1
- package/dist/assets/{state-wt1OcEQE.js → state-BgzWNmJm.js} +1 -1
- package/dist/assets/{ticketWorkLabels-CBire2Lh.js → ticketWorkLabels-tosshWRq.js} +1 -1
- package/dist/assets/{ui-Bh_Lw5Ur.js → ui-DQy0lUHc.js} +1 -1
- package/dist/assets/{useBrowserSession-FocPZCP6.js → useBrowserSession-DTq2injR.js} +1 -1
- package/dist/assets/{useWorkflowCatalog-B7if__Fq.js → useWorkflowCatalog-B3e4h1Zh.js} +1 -1
- package/dist/assets/zh-CN-M8nOhM1r.js +5 -0
- package/dist/bundle-ownership.json +56 -53
- package/dist/index.html +1 -1
- package/dist/lotus-next-manifest.json +106 -106
- package/package.json +1 -1
- package/dist/assets/ErrorBoundary-IGN8nbc_.js +0 -1
- package/dist/assets/MermaidChart-B9agFKWW.js +0 -1
- package/dist/assets/Root-BcbYdCLh.js +0 -112
- package/dist/assets/Settings-g8dWj_nl.js +0 -9
- package/dist/assets/SidebarProjectDrag-D8MDge8c.js +0 -1
- package/dist/assets/StreamdownMermaid-B9agFKWW.js +0 -1
- package/dist/assets/appStore-CtWsUc9q.js +0 -13
- package/dist/assets/en-US-DDbOhD2J.js +0 -5
- package/dist/assets/managedSessions-B02qzAls.js +0 -2
- package/dist/assets/managedSessions-CsCr49nE.js +0 -1
- package/dist/assets/zh-CN-DWR3SgZg.js +0 -5
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./SupervisorManagedSessions-DDL1goCC.js","./rolldown-runtime-QTnfLwEv.js","./vendor-react-CCIEwYL0.js","./ui-DQy0lUHc.js","./preload-helper-DYl5dUZ5.js","./refresh-cw-DHR8UyeF.js","./createLucideIcon-5m7IB1Aa.js","./api-dae15_RX.js","./runtimeConfig-DNyol2mX.js","./button-Cfb4l-V4.js","./bundle-mjs-B_AA55HL.js","./dist-F2p7j0vG.js","./utils-DqNhCx4L.js","./dialog-CfOua_Le.js","./x-CH9nNoJJ.js","./motion-A2StR0Mh.js","./dist-DF6JjXE-.js","./client-IKYlOoXY.js","./project-EohCp9v3.js","./SupervisorProjectScopeDialog-BRpx_B7f.js","./managedSessions-Df_XdXaQ.js","./AgentService-BcSV4V6G.js","./managedSessions-CNlNA0Gf.js","./CommandPalette-FYYof7PJ.js","./commandFocusReturn-DRzRqGCt.js","./plus-Do3us3O5.js","./search-DcePmjfr.js","./Settings-6l99-5Ca.js","./command-CKwm5a6S.js","./ErrorBoundary-Cd8Mqhm-.js","./responsive-dialog-ChvCU7Pw.js","./popover-NRuw3aPJ.js","./dist-gWmr0ziz.js","./loader-circle-B9fKDSy8.js","./input-DWysC80E.js","./dist-D8rsXFxT.js","./dist-DCRuquMi.js","./select-D2Yn2_yL.js","./dist-fTqKuvxa.js","./copy-DmHig_f7.js","./external-link-zzXjsZJY.js","./clipboard-CyQ_pZV9.js","./react-BqtYw2Yd.js","./appStore-DJRgb7nl.js","./themeStore-iULXkh0N.js","./textarea-BKzYyWL5.js","./tabs-CZ73j2Ke.js","./jianduMemoryApi-o1cxvito.js","./Settings-CmyQkAqB.css","./runDiagnostic-DJ_i4o1q.js","./runDiagnostic-DBibDMFH.js","./ProjectWorkBoard-BDerd2KC.js","./ownerAccessContext-DnfKhLRV.js","./ticketWorkLabels-tosshWRq.js","./ProjectWorkBoard-DV8jiE36.css","./SidebarProjectDrag-B8jeZZwD.js","./workbenchSensors-t4FKs4U1.js","./projectSidebarPreferences-CMJ99W-X.js","./renderPdf-Cug6wuGM.js","./vendor-mermaid-D-p0xABq.js","./vendor-markdown-CfSBref-.js","./lib-CFLxRXs3.js","./typeof-B5XbjTb1.js","./html2canvas-BzlCjWQf.js","./unsupportedIterableToArray-7m2_meZB.js","./strictConfig-C66PYHjm.js","./StreamdownMarkdown-BYrL8Htd.js","./vendor-streamdown-LREut7gy.js","./vendor-streamdown-CXvuy5h3.css","./FileOperationsService-XcscMou0.js","./ExternalLinkDialog-DxecTv9b.js","./earth-CjVWVKTC.js","./dropdown-menu-CL18d3V3.js","./markdownTheme-DZ_SWMdl.js","./StreamdownMarkdown-BRtZQ3tC.css","./Markdown-sn8uDNJU.js","./TicketWorkPanel-CoPV3q8A.js","./state-BgzWNmJm.js","./WorkflowRunsContent-lUfm3WNf.js","./useWorkflowCatalog-B3e4h1Zh.js","./RunDiagnosticsDialogContent-C83miiCb.js","./runDiagnosticId-Chp3mq_m.js","./NewChatWorktreeControl-BVvX1tE3.js","./composerStyles-t36ulToF.js","./BrowserPane-Qpdtlb6C.js","./arrow-left-wQDuPz_E.js","./useBrowserSession-DTq2injR.js","./RightWorkbench-ClTIc5yT.js","./RightWorkbenchSurface-5chVm3Q5.js"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{r as e,t}from"./rolldown-runtime-QTnfLwEv.js";import{i as n,r,t as i}from"./vendor-react-CCIEwYL0.js";import{i as a}from"./runtimeConfig-DNyol2mX.js";import{t as o}from"./preload-helper-DYl5dUZ5.js";import{a as s,c,d as l,i as u,n as d,r as f,s as p,t as m,u as h}from"./ui-DQy0lUHc.js";import{C as g,D as _,E as v,O as y,S as b,T as x,_ as S,a as C,b as w,c as T,i as E,n as D,t as O,u as k,w as A,x as j,y as M}from"./command-CKwm5a6S.js";import{t as N}from"./createLucideIcon-5m7IB1Aa.js";import{a as P,i as F,r as I,t as ee}from"./popover-NRuw3aPJ.js";import{t as L}from"./loader-circle-B9fKDSy8.js";import{t as te}from"./arrow-left-wQDuPz_E.js";import{i as R,t as ne}from"./useBrowserSession-DTq2injR.js";import{a as re,i as ie,o as ae,r as oe,t as se}from"./RightWorkbenchSurface-5chVm3Q5.js";import{n as ce,r as le,t as ue}from"./ErrorBoundary-Cd8Mqhm-.js";import{n as de,t as fe}from"./input-DWysC80E.js";import{c as pe,d as me,l as he,s as ge,u as _e}from"./dist-gWmr0ziz.js";import{i as ve}from"./dist-D8rsXFxT.js";import{a as ye,i as be,n as xe,r as Se,s as Ce,t as we}from"./select-D2Yn2_yL.js";import{c as Te,l as Ee,n as z,o as De,r as B,s as Oe,t as ke,u as V}from"./dropdown-menu-CL18d3V3.js";import{t as Ae}from"./copy-DmHig_f7.js";import{a as je,i as Me,n as Ne,r as Pe,t as Fe}from"./composerStyles-t36ulToF.js";import{n as Ie,r as Le,t as Re}from"./commandFocusReturn-DRzRqGCt.js";import{t as ze}from"./plus-Do3us3O5.js";import{t as Be}from"./refresh-cw-DHR8UyeF.js";import{t as Ve}from"./search-DcePmjfr.js";import{t as He}from"./x-CH9nNoJJ.js";import{t as Ue}from"./clipboard-CyQ_pZV9.js";import{t as We}from"./react-BqtYw2Yd.js";import{B as Ge,C as Ke,F as qe,H as Je,I as Ye,L as Xe,M as Ze,N as Qe,P as $e,R as et,S as tt,T as nt,U as rt,V as it,_ as at,a as ot,b as st,c as ct,i as H,j as lt,k as ut,m as dt,n as ft,o as pt,r as mt,s as ht,t as gt,u as _t,w as vt,x as yt,y as bt,z as xt}from"./appStore-DJRgb7nl.js";import{a as St,c as Ct,i as U,n as wt,o as Tt,r as Et,s as Dt,t as Ot}from"./api-dae15_RX.js";import{a as kt,c as At,d as jt,g as Mt,h as Nt,i as Pt,l as Ft,m as It,o as Lt,p as Rt,r as zt,u as Bt}from"./AgentService-BcSV4V6G.js";import{r as Vt,t as Ht}from"./project-EohCp9v3.js";import{t as W}from"./button-Cfb4l-V4.js";import{t as G}from"./utils-DqNhCx4L.js";import{n as Ut}from"./motion-A2StR0Mh.js";import{a as Wt,r as Gt,s as Kt}from"./dist-DF6JjXE-.js";import{a as qt,i as Jt,n as Yt,o as Xt,r as Zt,s as Qt,t as $t}from"./dialog-CfOua_Le.js";import{r as en,t as tn}from"./FileOperationsService-XcscMou0.js";import{n as nn,r as rn}from"./ExternalLinkDialog-DxecTv9b.js";import{i as an,n as on,r as sn,t as cn}from"./responsive-dialog-ChvCU7Pw.js";import{i as ln,o as un,r as dn,t as fn}from"./themeStore-iULXkh0N.js";import{a as pn,i as mn,r as hn,t as gn}from"./useWorkflowCatalog-B3e4h1Zh.js";import{a as _n,c as vn,d as yn,f as bn,h as xn,i as Sn,l as Cn,m as wn,n as Tn,o as En,p as Dn,r as On,s as kn,u as An}from"./projectSidebarPreferences-CMJ99W-X.js";import{t as jn}from"./SupervisorProjectScopeDialog-BRpx_B7f.js";import{t as Mn}from"./textarea-BKzYyWL5.js";import{a as Nn,c as Pn,i as Fn,o as In,r as Ln,s as Rn,t as zn}from"./state-BgzWNmJm.js";import{t as Bn}from"./ownerAccessContext-DnfKhLRV.js";import{t as Vn}from"./ticketWorkLabels-tosshWRq.js";import{t as Hn}from"./runDiagnosticId-Chp3mq_m.js";var Un=N(`chart-column`,[[`path`,{d:`M3 3v16a2 2 0 0 0 2 2h16`,key:`c24i48`}],[`path`,{d:`M18 17V9`,key:`2bz60n`}],[`path`,{d:`M13 17V5`,key:`1frdt8`}],[`path`,{d:`M8 17v-3`,key:`17ska0`}]]),Wn=N(`circle-check`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`m9 12 2 2 4-4`,key:`dzmm74`}]]),Gn=N(`circle-minus`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M8 12h8`,key:`1wcyev`}]]),Kn=N(`circle-pause`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`line`,{x1:`10`,x2:`10`,y1:`15`,y2:`9`,key:`c1nkhi`}],[`line`,{x1:`14`,x2:`14`,y1:`15`,y2:`9`,key:`h65svq`}]]),qn=N(`circle-question-mark`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M9.09 9a3 3 0 0 1 5.83 1c0 2-3 3-3 3`,key:`1u773s`}],[`path`,{d:`M12 17h.01`,key:`p32p05`}]]),Jn=N(`circle-x`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`m15 9-6 6`,key:`1uzhvr`}],[`path`,{d:`m9 9 6 6`,key:`z0biqf`}]]),Yn=N(`columns-2`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M12 3v18`,key:`108xh3`}]]),Xn=N(`ellipsis`,[[`circle`,{cx:`12`,cy:`12`,r:`1`,key:`41hilf`}],[`circle`,{cx:`19`,cy:`12`,r:`1`,key:`1wjl8i`}],[`circle`,{cx:`5`,cy:`12`,r:`1`,key:`1pcz8c`}]]),Zn=N(`panel-left-close`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M9 3v18`,key:`fh3hqa`}],[`path`,{d:`m16 15-3-3 3-3`,key:`14y99z`}]]),Qn=N(`rows-3`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M21 9H3`,key:`1338ky`}],[`path`,{d:`M21 15H3`,key:`9uk58r`}]]),$n=N(`sparkles`,[[`path`,{d:`M11.017 2.814a1 1 0 0 1 1.966 0l1.051 5.558a2 2 0 0 0 1.594 1.594l5.558 1.051a1 1 0 0 1 0 1.966l-5.558 1.051a2 2 0 0 0-1.594 1.594l-1.051 5.558a1 1 0 0 1-1.966 0l-1.051-5.558a2 2 0 0 0-1.594-1.594l-5.558-1.051a1 1 0 0 1 0-1.966l5.558-1.051a2 2 0 0 0 1.594-1.594z`,key:`1s2grr`}],[`path`,{d:`M20 2v4`,key:`1rf3ol`}],[`path`,{d:`M22 4h-4`,key:`gwowj6`}],[`circle`,{cx:`4`,cy:`20`,r:`2`,key:`6kqj1y`}]]),er=N(`square-pen`,[[`path`,{d:`M12 3H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7`,key:`1m0v6g`}],[`path`,{d:`M18.375 2.625a1 1 0 0 1 3 3l-9.013 9.014a2 2 0 0 1-.853.505l-2.873.84a.5.5 0 0 1-.62-.62l.84-2.873a2 2 0 0 1 .506-.852z`,key:`ohrbg2`}]]),tr=N(`text-wrap`,[[`path`,{d:`m16 16-3 3 3 3`,key:`117b85`}],[`path`,{d:`M3 12h14.5a1 1 0 0 1 0 7H13`,key:`18xa6z`}],[`path`,{d:`M3 19h6`,key:`1ygdsz`}],[`path`,{d:`M3 5h18`,key:`1u36vt`}]]),nr=N(`archive-restore`,[[`rect`,{width:`20`,height:`5`,x:`2`,y:`3`,rx:`1`,key:`1wp1u1`}],[`path`,{d:`M4 8v11a2 2 0 0 0 2 2h2`,key:`tvwodi`}],[`path`,{d:`M20 8v11a2 2 0 0 1-2 2h-2`,key:`1gkqxj`}],[`path`,{d:`m9 15 3-3 3 3`,key:`1pd0qc`}],[`path`,{d:`M12 12v9`,key:`192myk`}]]),rr=N(`archive`,[[`rect`,{width:`20`,height:`5`,x:`2`,y:`3`,rx:`1`,key:`1wp1u1`}],[`path`,{d:`M4 8v11a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8`,key:`1s80jp`}],[`path`,{d:`M10 12h4`,key:`a56b0p`}]]),ir=N(`arrow-up`,[[`path`,{d:`m5 12 7-7 7 7`,key:`hav0vg`}],[`path`,{d:`M12 19V5`,key:`x0mq9r`}]]),ar=N(`book-text`,[[`path`,{d:`M4 19.5v-15A2.5 2.5 0 0 1 6.5 2H19a1 1 0 0 1 1 1v18a1 1 0 0 1-1 1H6.5a1 1 0 0 1 0-5H20`,key:`k3hazp`}],[`path`,{d:`M8 11h8`,key:`vwpz6n`}],[`path`,{d:`M8 7h6`,key:`1f0q6e`}]]),or=N(`brain`,[[`path`,{d:`M12 18V5`,key:`adv99a`}],[`path`,{d:`M15 13a4.17 4.17 0 0 1-3-4 4.17 4.17 0 0 1-3 4`,key:`1e3is1`}],[`path`,{d:`M17.598 6.5A3 3 0 1 0 12 5a3 3 0 1 0-5.598 1.5`,key:`1gqd8o`}],[`path`,{d:`M17.997 5.125a4 4 0 0 1 2.526 5.77`,key:`iwvgf7`}],[`path`,{d:`M18 18a4 4 0 0 0 2-7.464`,key:`efp6ie`}],[`path`,{d:`M19.967 17.483A4 4 0 1 1 12 18a4 4 0 1 1-7.967-.517`,key:`1gq6am`}],[`path`,{d:`M6 18a4 4 0 0 1-2-7.464`,key:`k1g0md`}],[`path`,{d:`M6.003 5.125a4 4 0 0 0-2.526 5.77`,key:`q97ue3`}]]),sr=N(`calendar-days`,[[`path`,{d:`M8 2v4`,key:`1cmpym`}],[`path`,{d:`M16 2v4`,key:`4m81vk`}],[`rect`,{width:`18`,height:`18`,x:`3`,y:`4`,rx:`2`,key:`1hopcy`}],[`path`,{d:`M3 10h18`,key:`8toen8`}],[`path`,{d:`M8 14h.01`,key:`6423bh`}],[`path`,{d:`M12 14h.01`,key:`1etili`}],[`path`,{d:`M16 14h.01`,key:`1gbofw`}],[`path`,{d:`M8 18h.01`,key:`lrp35t`}],[`path`,{d:`M12 18h.01`,key:`mhygvu`}],[`path`,{d:`M16 18h.01`,key:`kzsmim`}]]),cr=N(`chevron-left`,[[`path`,{d:`m15 18-6-6 6-6`,key:`1wnfg3`}]]),lr=N(`circle-dot`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`circle`,{cx:`12`,cy:`12`,r:`1`,key:`41hilf`}]]),ur=N(`circle-off`,[[`path`,{d:`m2 2 20 20`,key:`1ooewy`}],[`path`,{d:`M8.35 2.69A10 10 0 0 1 21.3 15.65`,key:`1pfsoa`}],[`path`,{d:`M19.08 19.08A10 10 0 1 1 4.92 4.92`,key:`1ablyi`}]]),dr=N(`circle-slash`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`line`,{x1:`9`,x2:`15`,y1:`15`,y2:`9`,key:`1dfufj`}]]),fr=N(`clock-3`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M12 6v6h4`,key:`135r8i`}]]),pr=N(`clock`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M12 6v6l4 2`,key:`mmk7yg`}]]),mr=N(`code`,[[`path`,{d:`m16 18 6-6-6-6`,key:`eg8j8`}],[`path`,{d:`m8 6-6 6 6 6`,key:`ppft3o`}]]),hr=N(`cog`,[[`path`,{d:`M11 10.27 7 3.34`,key:`16pf9h`}],[`path`,{d:`m11 13.73-4 6.93`,key:`794ttg`}],[`path`,{d:`M12 22v-2`,key:`1osdcq`}],[`path`,{d:`M12 2v2`,key:`tus03m`}],[`path`,{d:`M14 12h8`,key:`4f43i9`}],[`path`,{d:`m17 20.66-1-1.73`,key:`eq3orb`}],[`path`,{d:`m17 3.34-1 1.73`,key:`2wel8s`}],[`path`,{d:`M2 12h2`,key:`1t8f8n`}],[`path`,{d:`m20.66 17-1.73-1`,key:`sg0v6f`}],[`path`,{d:`m20.66 7-1.73 1`,key:`1ow05n`}],[`path`,{d:`m3.34 17 1.73-1`,key:`nuk764`}],[`path`,{d:`m3.34 7 1.73 1`,key:`1ulond`}],[`circle`,{cx:`12`,cy:`12`,r:`2`,key:`1c9p78`}],[`circle`,{cx:`12`,cy:`12`,r:`8`,key:`46899m`}]]),gr=N(`container`,[[`path`,{d:`M22 7.7c0-.6-.4-1.2-.8-1.5l-6.3-3.9a1.72 1.72 0 0 0-1.7 0l-10.3 6c-.5.2-.9.8-.9 1.4v6.6c0 .5.4 1.2.8 1.5l6.3 3.9a1.72 1.72 0 0 0 1.7 0l10.3-6c.5-.3.9-1 .9-1.5Z`,key:`1t2lqe`}],[`path`,{d:`M10 21.9V14L2.1 9.1`,key:`o7czzq`}],[`path`,{d:`m10 14 11.9-6.9`,key:`zm5e20`}],[`path`,{d:`M14 19.8v-8.1`,key:`159ecu`}],[`path`,{d:`M18 17.5V9.4`,key:`11uown`}]]),_r=N(`file-down`,[[`path`,{d:`M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z`,key:`1oefj6`}],[`path`,{d:`M14 2v5a1 1 0 0 0 1 1h5`,key:`wfsgrz`}],[`path`,{d:`M12 18v-6`,key:`17g6i2`}],[`path`,{d:`m9 15 3 3 3-3`,key:`1npd3o`}]]),vr=N(`file-search`,[[`path`,{d:`M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z`,key:`1oefj6`}],[`path`,{d:`M14 2v5a1 1 0 0 0 1 1h5`,key:`wfsgrz`}],[`circle`,{cx:`11.5`,cy:`14.5`,r:`2.5`,key:`1bq0ko`}],[`path`,{d:`M13.3 16.3 15 18`,key:`2quom7`}]]),yr=N(`file`,[[`path`,{d:`M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z`,key:`1oefj6`}],[`path`,{d:`M14 2v5a1 1 0 0 0 1 1h5`,key:`wfsgrz`}]]),br=N(`folder-closed`,[[`path`,{d:`M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z`,key:`1kt360`}],[`path`,{d:`M2 10h20`,key:`1ir3d8`}]]),xr=N(`folder-kanban`,[[`path`,{d:`M4 20h16a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.93a2 2 0 0 1-1.66-.9l-.82-1.2A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13c0 1.1.9 2 2 2Z`,key:`1fr9dc`}],[`path`,{d:`M8 10v4`,key:`tgpxqk`}],[`path`,{d:`M12 10v2`,key:`hh53o1`}],[`path`,{d:`M16 10v6`,key:`1d6xys`}]]),Sr=N(`folder-open`,[[`path`,{d:`m6 14 1.5-2.9A2 2 0 0 1 9.24 10H20a2 2 0 0 1 1.94 2.5l-1.54 6a2 2 0 0 1-1.95 1.5H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h3.9a2 2 0 0 1 1.69.9l.81 1.2a2 2 0 0 0 1.67.9H18a2 2 0 0 1 2 2v2`,key:`usdka0`}]]),Cr=N(`folder-plus`,[[`path`,{d:`M12 10v6`,key:`1bos4e`}],[`path`,{d:`M9 13h6`,key:`1uhe8q`}],[`path`,{d:`M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z`,key:`1kt360`}]]),wr=N(`folder`,[[`path`,{d:`M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z`,key:`1kt360`}]]),Tr=N(`git-compare`,[[`circle`,{cx:`18`,cy:`18`,r:`3`,key:`1xkwt0`}],[`circle`,{cx:`6`,cy:`6`,r:`3`,key:`1lh9wr`}],[`path`,{d:`M13 6h3a2 2 0 0 1 2 2v7`,key:`1yeb86`}],[`path`,{d:`M11 18H8a2 2 0 0 1-2-2V9`,key:`19pyzm`}]]),Er=N(`git-fork`,[[`circle`,{cx:`12`,cy:`18`,r:`3`,key:`1mpf1b`}],[`circle`,{cx:`6`,cy:`6`,r:`3`,key:`1lh9wr`}],[`circle`,{cx:`18`,cy:`6`,r:`3`,key:`1h7g24`}],[`path`,{d:`M18 9v2c0 .6-.4 1-1 1H7c-.6 0-1-.4-1-1V9`,key:`1uq4wg`}],[`path`,{d:`M12 12v3`,key:`158kv8`}]]),Dr=N(`git-merge`,[[`circle`,{cx:`18`,cy:`18`,r:`3`,key:`1xkwt0`}],[`circle`,{cx:`6`,cy:`6`,r:`3`,key:`1lh9wr`}],[`path`,{d:`M6 21V9a9 9 0 0 0 9 9`,key:`7kw0sc`}]]),Or=N(`image`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,ry:`2`,key:`1m3agn`}],[`circle`,{cx:`9`,cy:`9`,r:`2`,key:`af1f0g`}],[`path`,{d:`m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21`,key:`1xmnt7`}]]),kr=N(`info`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M12 16v-4`,key:`1dtifu`}],[`path`,{d:`M12 8h.01`,key:`e9boi3`}]]),Ar=N(`list-filter`,[[`path`,{d:`M2 5h20`,key:`1fs1ex`}],[`path`,{d:`M6 12h12`,key:`8npq4p`}],[`path`,{d:`M9 19h6`,key:`456am0`}]]),jr=N(`list`,[[`path`,{d:`M3 5h.01`,key:`18ugdj`}],[`path`,{d:`M3 12h.01`,key:`nlz23k`}],[`path`,{d:`M3 19h.01`,key:`noohij`}],[`path`,{d:`M8 5h13`,key:`1pao27`}],[`path`,{d:`M8 12h13`,key:`1za7za`}],[`path`,{d:`M8 19h13`,key:`m83p4d`}]]),Mr=N(`menu`,[[`path`,{d:`M4 5h16`,key:`1tepv9`}],[`path`,{d:`M4 12h16`,key:`1lakjw`}],[`path`,{d:`M4 19h16`,key:`1djgab`}]]),Nr=N(`message-circle`,[[`path`,{d:`M2.992 16.342a2 2 0 0 1 .094 1.167l-1.065 3.29a1 1 0 0 0 1.236 1.168l3.413-.998a2 2 0 0 1 1.099.092 10 10 0 1 0-4.777-4.719`,key:`1sd12s`}]]),Pr=N(`message-square-plus`,[[`path`,{d:`M22 17a2 2 0 0 1-2 2H6.828a2 2 0 0 0-1.414.586l-2.202 2.202A.71.71 0 0 1 2 21.286V5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2z`,key:`18887p`}],[`path`,{d:`M12 8v6`,key:`1ib9pf`}],[`path`,{d:`M9 11h6`,key:`1fldmi`}]]),Fr=N(`panel-right-open`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M15 3v18`,key:`14nvp0`}],[`path`,{d:`m10 15-3-3 3-3`,key:`1pgupc`}]]),Ir=N(`paperclip`,[[`path`,{d:`m16 6-8.414 8.586a2 2 0 0 0 2.829 2.829l8.414-8.586a4 4 0 1 0-5.657-5.657l-8.379 8.551a6 6 0 1 0 8.485 8.485l8.379-8.551`,key:`1miecu`}]]),Lr=N(`pin-off`,[[`path`,{d:`M12 17v5`,key:`bb1du9`}],[`path`,{d:`M15 9.34V7a1 1 0 0 1 1-1 2 2 0 0 0 0-4H7.89`,key:`znwnzq`}],[`path`,{d:`m2 2 20 20`,key:`1ooewy`}],[`path`,{d:`M9 9v1.76a2 2 0 0 1-1.11 1.79l-1.78.9A2 2 0 0 0 5 15.24V16a1 1 0 0 0 1 1h11`,key:`c9qhm2`}]]),Rr=N(`pin`,[[`path`,{d:`M12 17v5`,key:`bb1du9`}],[`path`,{d:`M9 10.76a2 2 0 0 1-1.11 1.79l-1.78.9A2 2 0 0 0 5 15.24V16a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1v-.76a2 2 0 0 0-1.11-1.79l-1.78-.9A2 2 0 0 1 15 10.76V7a1 1 0 0 1 1-1 2 2 0 0 0 0-4H8a2 2 0 0 0 0 4 1 1 0 0 1 1 1z`,key:`1nkz8b`}]]),zr=N(`shield-alert`,[[`path`,{d:`M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z`,key:`oel41y`}],[`path`,{d:`M12 8v4`,key:`1got3b`}],[`path`,{d:`M12 16h.01`,key:`1drbdi`}]]),Br=N(`square`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}]]),Vr=N(`terminal`,[[`path`,{d:`M12 19h8`,key:`baeox8`}],[`path`,{d:`m4 17 6-6-6-6`,key:`1yngyt`}]]),Hr=N(`wifi-off`,[[`path`,{d:`M12 20h.01`,key:`zekei9`}],[`path`,{d:`M8.5 16.429a5 5 0 0 1 7 0`,key:`1bycff`}],[`path`,{d:`M5 12.859a10 10 0 0 1 5.17-2.69`,key:`1dl1wf`}],[`path`,{d:`M19 12.859a10 10 0 0 0-2.007-1.523`,key:`4k23kn`}],[`path`,{d:`M2 8.82a15 15 0 0 1 4.177-2.643`,key:`1grhjp`}],[`path`,{d:`M22 8.82a15 15 0 0 0-11.288-3.764`,key:`z3jwby`}],[`path`,{d:`m2 2 20 20`,key:`1ooewy`}]]),Ur=N(`wrench`,[[`path`,{d:`M14.7 6.3a1 1 0 0 0 0 1.4l1.6 1.6a1 1 0 0 0 1.4 0l3.106-3.105c.32-.322.863-.22.983.218a6 6 0 0 1-8.259 7.057l-7.91 7.91a1 1 0 0 1-2.999-3l7.91-7.91a6 6 0 0 1 7.057-8.259c.438.12.54.662.219.984z`,key:`1ngwbx`}]]),K=e(n(),1),Wr=e=>Symbol.iterator in e,Gr=e=>`entries`in e,Kr=(e,t)=>{let n=e instanceof Map?e:new Map(e.entries()),r=t instanceof Map?t:new Map(t.entries());if(n.size!==r.size)return!1;for(let[e,t]of n)if(!r.has(e)||!Object.is(t,r.get(e)))return!1;return!0},qr=(e,t)=>{let n=e[Symbol.iterator](),r=t[Symbol.iterator](),i=n.next(),a=r.next();for(;!i.done&&!a.done;){if(!Object.is(i.value,a.value))return!1;i=n.next(),a=r.next()}return!!i.done&&!!a.done};function Jr(e,t){return Object.is(e,t)?!0:typeof e!=`object`||!e||typeof t!=`object`||!t||Object.getPrototypeOf(e)!==Object.getPrototypeOf(t)?!1:Wr(e)&&Wr(t)?Gr(e)&&Gr(t)?Kr(e,t):qr(e,t):Kr({entries:()=>Object.entries(e)},{entries:()=>Object.entries(t)})}function Yr(e){let t=K.useRef(void 0);return n=>{let r=e(n);return Jr(t.current,r)?t.current:t.current=r}}var Xr=e=>typeof e==`object`&&!!e&&!Array.isArray(e),Zr=e=>typeof e==`string`?e:void 0,Qr=e=>typeof e==`number`&&Number.isFinite(e)?e:void 0,$r=e=>typeof e==`boolean`?e:void 0,ei=e=>{if(!e)return null;let t=e.trim();if(!t.startsWith(`{`)||!t.endsWith(`}`))return null;try{let e=JSON.parse(t);if(!Xr(e))return null;let n=Zr(e.file_path),r=Zr(e.operation),i=e.diff;if(!n||!r||!Xr(i))return null;let a=Zr(i.unified);if(!a)return null;let o=e.checkpoint,s=Xr(o)?{created:$r(o.created)??!1,id:Zr(o.id),path:Zr(o.path),size_bytes:Qr(o.size_bytes),reason:Zr(o.reason)}:void 0;return{operation:r,message:Zr(e.message),file_path:n,workspace:Zr(e.workspace),checkpoint:s,diff:{unified:a,old_line_count:Qr(i.old_line_count),new_line_count:Qr(i.new_line_count),added_lines:Qr(i.added_lines),removed_lines:Qr(i.removed_lines),truncated:$r(i.truncated)}}}catch{return null}},ti=e=>e.startsWith(`-`)&&!e.startsWith(`---`),ni=e=>e.startsWith(`+`)&&!e.startsWith(`+++`),ri=e=>{let t=e.split(`
|
|
3
|
+
`),n=[],r=0;for(;r<t.length;){let e=t[r]??``;if(e.startsWith(`--- `)||e.startsWith(`+++ `)){n.push({kind:`meta`,text:e}),r+=1;continue}if(e.startsWith(`@@`)){n.push({kind:`hunk`,text:e}),r+=1;continue}if(ti(e)){let e=[];for(;r<t.length&&ti(t[r]??``);)e.push(t[r]??``),r+=1;let i=[];for(;r<t.length&&ni(t[r]??``);)i.push(t[r]??``),r+=1;i.length>0?(e.forEach(e=>n.push({kind:`modified_remove`,text:e})),i.forEach(e=>n.push({kind:`modified_add`,text:e}))):e.forEach(e=>n.push({kind:`remove`,text:e}));continue}if(ni(e)){n.push({kind:`add`,text:e}),r+=1;continue}n.push({kind:`context`,text:e}),r+=1}return n},ii=e=>{let t=e.match(/^@@ -(\d+)(?:,\d+)? \+(\d+)(?:,\d+)? @@/);return t?{oldStart:Number.parseInt(t[1],10),newStart:Number.parseInt(t[2],10)}:null},ai=e=>{if(!e)return``;let t=e[0];return t===`+`||t===`-`||t===` `?e.slice(1):e},oi=e=>e==null?null:e+1,si=e=>{let t=e.split(`
|
|
4
|
+
`),n=[],r=null,i=null,a=0;for(;a<t.length;){let e=t[a]??``;if(e.startsWith(`--- `)||e.startsWith(`+++ `)){n.push({kind:`meta`,text:e}),a+=1;continue}if(e.startsWith(`@@`)){let t=ii(e);t&&(r=t.oldStart,i=t.newStart),n.push({kind:`hunk`,text:e}),a+=1;continue}if(ti(e)){let e=[];for(;a<t.length&&ti(t[a]??``);)e.push(t[a]??``),a+=1;let o=[];for(;a<t.length&&ni(t[a]??``);)o.push(t[a]??``),a+=1;if(o.length>0){let t=Math.max(e.length,o.length);for(let a=0;a<t;a+=1){let t=e[a],s=o[a];if(t&&s){n.push({kind:`modified`,oldLineNumber:r??void 0,newLineNumber:i??void 0,oldText:ai(t),newText:ai(s)}),r=oi(r),i=oi(i);continue}if(t){n.push({kind:`remove`,oldLineNumber:r??void 0,oldText:ai(t)}),r=oi(r);continue}s&&(n.push({kind:`add`,newLineNumber:i??void 0,newText:ai(s)}),i=oi(i))}}else e.forEach(e=>{n.push({kind:`remove`,oldLineNumber:r??void 0,oldText:ai(e)}),r=oi(r)});continue}if(ni(e)){n.push({kind:`add`,newLineNumber:i??void 0,newText:ai(e)}),i=oi(i),a+=1;continue}let o=ai(e);n.push({kind:`context`,oldLineNumber:r??void 0,newLineNumber:i??void 0,oldText:o,newText:o}),r=oi(r),i=oi(i),a+=1}return n},ci=e=>{let t=0,n=0;for(let r of e.split(`
|
|
5
|
+
`)){if(ni(r)){t+=1;continue}ti(r)&&(n+=1)}return{added:t,removed:n}},li=e=>{let t=ci(e.diff.unified);return{added:e.diff.added_lines??t.added,removed:e.diff.removed_lines??t.removed}};function ui(e){let t=[];for(let n of e){if(n.type!==`tool_result`)continue;let e=n,r=e.result?.result;if(typeof r!=`string`)continue;let i=ei(r);i&&t.push({id:n.id,toolCallId:e.toolCallId,payload:i})}return t}function di(e){let t=[];for(let n of e)if(n.kind===`tools`)for(let e of n.calls??[]){let n=ei(e.output);n&&t.push({id:`live:${e.toolCallId}`,toolCallId:e.toolCallId,payload:n})}return t}function fi(e,t){let n=new Set(e.flatMap(e=>e.toolCallId?[e.toolCallId]:[]));return[...e,...t.filter(e=>!e.toolCallId||!n.has(e.toolCallId))]}var pi=e=>e.replace(/\\/g,`/`).replace(/^\/private\/tmp(?=\/|$)/,`/tmp`).replace(/^\/private\/var(?=\/|$)/,`/var`),mi=e=>e.startsWith(`/`)||/^[a-zA-Z]:\//.test(e);function hi(e,t,n){let r=pi(e);if(mi(r))return r;let i=pi(t||n||``).replace(/\/$/,``);return i?`${i}/${r.replace(/^\.\//,``)}`:r}function gi(e,t){let n=new Map;return e.forEach((e,r)=>{let i=hi(e.payload.file_path,e.payload.workspace,t),a=li(e.payload),o=n.get(i);if(o){o.changes.push(e),o.addedLines+=a.added,o.removedLines+=a.removed,o.truncated||=e.payload.diff.truncated===!0,o.lastChangeIndex=r;return}n.set(i,{id:`file:${i}`,filePath:i,changes:[e],addedLines:a.added,removedLines:a.removed,truncated:e.payload.diff.truncated===!0,lastChangeIndex:r})}),Array.from(n.values()).sort((e,t)=>e.lastChangeIndex-t.lastChangeIndex).map(({lastChangeIndex:e,...t})=>t)}function _i(e){return e.reduce((e,t)=>({fileCount:e.fileCount+1,editCount:e.editCount+t.changes.length,addedLines:e.addedLines+t.addedLines,removedLines:e.removedLines+t.removedLines}),{fileCount:0,editCount:0,addedLines:0,removedLines:0})}function vi(e=!0){let t=(0,K.useRef)(null),[n,r]=(0,K.useState)(0);return(0,K.useEffect)(()=>{if(!e)return;let n=t.current;if(!n)return;let i=()=>{let e=Math.round(n.getBoundingClientRect().width);r(t=>t===e?t:e)};if(i(),typeof ResizeObserver>`u`)return window.addEventListener(`resize`,i),()=>window.removeEventListener(`resize`,i);let a=null,o=new ResizeObserver(()=>{a===null&&(a=window.requestAnimationFrame(()=>{a=null,i()}))});return o.observe(n),()=>{o.disconnect(),a!==null&&window.cancelAnimationFrame(a)}},[e]),[t,n]}var yi=e=>pi(e).replace(/\/$/,``);function bi(e,t,n){let r=yi(e);if(t===`full`)return r;if(t===`basename`)return r.split(`/`).filter(Boolean).pop()||r;let i=n?yi(n):``;return i&&r.startsWith(`${i}/`)?r.slice(i.length+1):r}var q=i(),xi=720,Si={add:`bg-green-500/10 text-green-700 dark:text-green-400`,modified_add:`bg-green-500/10 text-green-700 dark:text-green-400`,remove:`bg-red-500/10 text-red-700 dark:text-red-400`,modified_remove:`bg-red-500/10 text-red-700 dark:text-red-400`,hunk:`bg-muted/70 text-muted-foreground`,meta:`text-muted-foreground`,gap:`text-muted-foreground/50`},Ci={add:`bg-green-500/10 text-green-700 dark:text-green-400`,remove:`bg-red-500/10 text-red-700 dark:text-red-400`};function wi(e){return e.startsWith(`--- `)||e.startsWith(`+++ `)}function Ti({payload:e,showHeader:t=!0,viewMode:n,wrapLines:r,scrollMode:i=`contained`,allowSplit:a}){u();let[o,s]=vi(a===void 0),[c,l]=(0,K.useState)(`unified`),[d,p]=(0,K.useState)(!1),m=e.diff?.unified??``,h=(0,K.useMemo)(()=>li(e),[e]),g=a??s>=xi,_=(n??c)===`split`&&g?`split`:`unified`,v=r??d,y=(0,K.useMemo)(()=>ri(m).filter(e=>!wi(e.text)),[m]),b=(0,K.useMemo)(()=>_===`split`?si(m).filter(e=>e.kind!==`meta`||!wi(e.text??``)):[],[_,m]);if(!m.trim())return null;let x=e.file_path?.split(/[\\/]/).filter(Boolean).pop()||e.file_path,S=i===`contained`?`max-h-72 overflow-auto`:`overflow-x-auto`,C=v?`whitespace-pre-wrap break-words`:void 0;return(0,q.jsxs)(`div`,{ref:o,className:G(t&&`overflow-hidden rounded-md border bg-background/50`),children:[t?(0,q.jsxs)(`div`,{className:`flex items-center gap-2 border-b bg-muted/40 px-2.5 py-1.5`,children:[(0,q.jsx)(re,{className:`size-3.5 shrink-0 text-muted-foreground`}),(0,q.jsx)(`span`,{className:`min-w-0 flex-1 truncate font-mono text-[11px]`,title:e.file_path,children:x}),(0,q.jsxs)(`span`,{className:`shrink-0 text-[11px]`,children:[(0,q.jsxs)(`span`,{className:`text-green-600 dark:text-green-400`,children:[`+`,h.added]}),` `,(0,q.jsxs)(`span`,{className:`text-red-600 dark:text-red-400`,children:[`−`,h.removed]})]}),e.diff?.truncated?(0,q.jsx)(`span`,{className:`shrink-0 rounded bg-muted px-1 text-[10px] text-muted-foreground`,children:f(`truncated_4fb9aa6e`)}):null,(0,q.jsx)(`button`,{type:`button`,onClick:()=>p(e=>!e),className:G(`shrink-0 rounded p-0.5 text-muted-foreground hover:bg-accent hover:text-foreground`,v&&`bg-accent text-foreground`),title:f(v?`no_wrapping_5e4313a9`:`wrap_lines_b096842c`),"aria-label":f(v?`no_wrapping_5e4313a9`:`wrap_lines_b096842c`),"aria-pressed":v,children:(0,q.jsx)(tr,{className:`size-3.5`})}),g?(0,q.jsx)(`button`,{type:`button`,onClick:()=>l(e=>e===`split`?`unified`:`split`),className:`shrink-0 rounded p-0.5 text-muted-foreground hover:bg-accent hover:text-foreground`,title:f(_===`split`?`unified_view_ed58c78e`:`side_by_side_view_0b210103`),"aria-label":f(_===`split`?`unified_view_ed58c78e`:`side_by_side_view_0b210103`),children:_===`split`?(0,q.jsx)(Qn,{className:`size-3.5`}):(0,q.jsx)(Yn,{className:`size-3.5`})}):null]}):null,_===`split`?(0,q.jsx)(`div`,{className:G(S,`font-mono text-xs leading-relaxed`),children:(0,q.jsx)(`table`,{className:`w-full border-collapse`,style:{minWidth:`42rem`},children:(0,q.jsx)(`tbody`,{children:b.map((e,t)=>{if(e.kind===`meta`||e.kind===`hunk`)return(0,q.jsx)(`tr`,{children:(0,q.jsx)(`td`,{colSpan:4,className:G(`px-2 py-0.5`,Si[e.kind]),children:e.text})},t);let n=e.kind===`remove`||e.kind===`modified`?Ci.remove:void 0,r=e.kind===`add`||e.kind===`modified`?Ci.add:void 0;return(0,q.jsxs)(`tr`,{className:`align-top`,children:[(0,q.jsx)(`td`,{className:`w-8 select-none border-r px-1 text-right text-muted-foreground/60`,children:e.oldLineNumber??``}),(0,q.jsx)(`td`,{className:G(`w-1/2 px-2`,C,n),style:v?void 0:{whiteSpace:`pre`},children:e.kind===`add`?``:e.oldText??e.text??``}),(0,q.jsx)(`td`,{className:`w-8 select-none border-x px-1 text-right text-muted-foreground/60`,children:e.newLineNumber??``}),(0,q.jsx)(`td`,{className:G(`w-1/2 px-2`,C,r),style:v?void 0:{whiteSpace:`pre`},children:e.kind===`remove`?``:e.newText??e.text??``})]},t)})})})}):(0,q.jsx)(`div`,{role:`table`,"aria-label":f(`unified_diff_3046b5d4`,{v0:x}),className:G(S,`font-mono text-xs leading-relaxed`),children:y.map((e,t)=>(0,q.jsx)(`div`,{role:`row`,className:G(`px-2.5`,C,Si[e.kind]),style:v?void 0:{minWidth:`max-content`,whiteSpace:`pre`},children:e.text||` `},t))})]})}var Ei=720,Di={comfortable:{details:`rounded-lg border bg-background/50`,summary:`sticky top-0 z-20 flex cursor-pointer select-none items-center gap-2 bg-card px-3 py-2.5 text-sm hover:bg-accent [&::-webkit-details-marker]:hidden`,icon:`size-4 shrink-0 text-muted-foreground`,stats:`shrink-0 text-xs`,body:`border-t`},compact:{details:`rounded-md border bg-background/50`,summary:`flex cursor-pointer select-none items-center gap-1.5 px-2 py-1.5 text-xs hover:bg-accent/50 [&::-webkit-details-marker]:hidden`,icon:`size-3.5 shrink-0 text-muted-foreground`,stats:`shrink-0 text-[11px]`,body:`border-t`}},Oi={get apply_patch(){return f(`modify_37090f45`)},get create(){return f(`create_cde2cd07`)},get create_file(){return f(`create_cde2cd07`)},get delete(){return f(`delete_2f9daa82`)},get delete_file(){return f(`delete_2f9daa82`)},get edit(){return f(`modify_37090f45`)},get patch(){return f(`modify_37090f45`)},get update(){return f(`modify_37090f45`)},get write(){return f(`write_5c783c46`)},get write_file(){return f(`write_5c783c46`)}};function ki(e){return Oi[e.toLowerCase()]??e}function Ai({group:e,workspace:t,pathMode:n=`full`,density:r=`comfortable`,defaultOpen:i=!1,scrollIntoViewOnMount:a=!1}){u();let[o,s]=(0,K.useState)(i),[c,l]=(0,K.useState)(`unified`),[d,p]=(0,K.useState)(!1),[m,h]=vi(),g=Di[r],_=bi(e.filePath,n,t),v=h>=Ei;return(0,K.useEffect)(()=>{!v&&c===`split`&&l(`unified`)},[v,c]),(0,K.useEffect)(()=>{if(!i||!a)return;let e=window.requestAnimationFrame(()=>{m.current?.scrollIntoView({block:`start`})});return()=>window.cancelAnimationFrame(e)},[m,i,a]),(0,q.jsxs)(`details`,{ref:m,open:o,onToggle:e=>s(e.currentTarget.open),className:g.details,children:[(0,q.jsxs)(`summary`,{className:g.summary,style:r===`comfortable`?{borderTopLeftRadius:`var(--radius)`,borderTopRightRadius:`var(--radius)`}:void 0,children:[(0,q.jsx)(re,{className:g.icon}),(0,q.jsx)(`span`,{className:`min-w-0 flex-1 truncate font-mono`,title:e.filePath,children:_}),e.changes.length>1?(0,q.jsx)(`span`,{className:`shrink-0 rounded bg-muted px-1.5 py-0.5 text-[10px] text-muted-foreground`,children:f(`count_changes`,{count:e.changes.length})}):null,e.truncated?(0,q.jsx)(`span`,{className:`shrink-0 rounded bg-muted px-1.5 py-0.5 text-[10px] text-muted-foreground`,children:f(`truncated_4fb9aa6e`)}):null,(0,q.jsxs)(`span`,{className:g.stats,children:[(0,q.jsxs)(`span`,{className:`text-green-600 dark:text-green-400`,children:[`+`,e.addedLines]}),` `,(0,q.jsxs)(`span`,{className:`text-red-600 dark:text-red-400`,children:[`−`,e.removedLines]})]})]}),o?(0,q.jsxs)(`div`,{className:g.body,children:[(0,q.jsxs)(`div`,{className:G(`flex items-center gap-1 border-b bg-card px-2 py-1.5`,r===`comfortable`&&`sticky z-10`),style:r===`comfortable`?{top:41}:void 0,children:[(0,q.jsxs)(W,{type:`button`,size:`sm`,variant:c===`unified`?`secondary`:`ghost`,className:`h-7 px-2 text-xs`,onClick:()=>l(`unified`),"aria-pressed":c===`unified`,children:[(0,q.jsx)(Qn,{className:`size-3.5`}),f(`unified_a1108b48`)]}),(0,q.jsxs)(W,{type:`button`,size:`sm`,variant:c===`split`?`secondary`:`ghost`,className:`h-7 px-2 text-xs`,onClick:()=>l(`split`),disabled:!v,title:f(v?`side_by_side_872790ee`:`expand_the_panel_to_compare_side_by_side_e4c4ced4`),"aria-pressed":c===`split`,children:[(0,q.jsx)(Yn,{className:`size-3.5`}),f(`compare_e182fb40`)]}),(0,q.jsx)(`div`,{className:`flex-1`}),(0,q.jsxs)(W,{type:`button`,size:`sm`,variant:d?`secondary`:`ghost`,className:`h-7 px-2 text-xs`,onClick:()=>p(e=>!e),"aria-pressed":d,children:[(0,q.jsx)(tr,{className:`size-3.5`}),f(`wrap_bd609a8e`)]})]}),(0,q.jsx)(`div`,{className:`divide-y`,children:e.changes.map((t,n)=>(0,q.jsxs)(`section`,{"aria-label":f(`change_1d9f6496`,{v0:_,v1:n+1}),children:[e.changes.length>1?(0,q.jsxs)(`div`,{className:`flex items-center gap-2 bg-muted/30 px-2.5 py-1 text-[10px] text-muted-foreground`,children:[(0,q.jsxs)(`span`,{children:[f(`modify_37090f45`),` `,n+1,` / `,e.changes.length]}),(0,q.jsx)(`span`,{"aria-hidden":`true`,children:`·`}),(0,q.jsx)(`span`,{children:ki(t.payload.operation)})]}):null,(0,q.jsx)(`div`,{children:(0,q.jsx)(Ti,{payload:t.payload,showHeader:!1,viewMode:c,wrapLines:d,scrollMode:`document`,allowSplit:v})})]},t.id))})]}):null]})}var ji={comfortable:`space-y-3`,compact:`space-y-1.5`};function Mi({groups:e,workspace:t,pathMode:n=`full`,density:r=`comfortable`,defaultOpen:i=!1,variant:a=`disclosure`,onSelect:o,scrollToGroupId:s}){return u(),a===`summary`?(0,q.jsx)(`div`,{className:`space-y-0.5`,children:e.map(e=>{let r=bi(e.filePath,n,t);return(0,q.jsxs)(`button`,{type:`button`,className:`flex w-full items-center gap-1.5 rounded px-1 py-1 text-left text-xs hover:bg-accent`,onClick:()=>o?.(e),title:f(`view_in_review_93af0688`,{v0:r}),children:[(0,q.jsx)(re,{className:`size-3.5 shrink-0 text-muted-foreground`}),(0,q.jsx)(`span`,{className:`min-w-0 flex-1 truncate font-mono`,title:e.filePath,children:r}),e.changes.length>1?(0,q.jsx)(`span`,{className:`shrink-0 text-[10px] text-muted-foreground`,children:f(`count_changes`,{count:e.changes.length})}):null,(0,q.jsxs)(`span`,{className:`shrink-0 text-[11px]`,children:[(0,q.jsxs)(`span`,{className:`text-green-600 dark:text-green-400`,children:[`+`,e.addedLines]}),` `,(0,q.jsxs)(`span`,{className:`text-red-600 dark:text-red-400`,children:[`−`,e.removedLines]})]})]},e.id)})}):(0,q.jsx)(`div`,{className:ji[r],children:e.map((a,o)=>(0,q.jsx)(Ai,{group:a,workspace:t,pathMode:n,density:r,defaultOpen:typeof i==`function`?i(o,e.length):i,scrollIntoViewOnMount:a.id===s},a.id))})}var Ni=`application/vnd.bamboo.actor-snapshot.v2+json, application/json;q=0.9`;function Pi(e){if(typeof e!=`string`)return null;let t=/^at1-([0-9a-f]{64})-([1-9][0-9]*)$/.exec(e);if(!t)return null;let n=Number(t[2]);return Number.isSafeInteger(n)&&n>0?{scope:t[1],revision:n}:null}function Fi(e,t){let n=Pi(e),r=Pi(t);return n!==null&&r!==null&&n.scope===r.scope&&n.revision>=r.revision}var Ii=(e,t)=>{let n=Date.parse(e)-Date.parse(t);if(n!==0)return n;let r=e=>/\.(\d{1,9})(?:Z|[+-])/.exec(e)?.[1].padEnd(9,`0`)??`000000000`;return r(e).localeCompare(r(t))},Li=(e,t)=>e?e.state===`stopped`&&t?.state!==`stopped`||e.state===`stop_unconfirmed`&&(!t||e.reason===`execution_stop_unconfirmed`&&t.state!==`stopped`&&(t.state!==`stop_unconfirmed`||t.reason!==e.reason)||e.reason===`lease_expired_without_stop`&&t.state===`running`&&(!e.lease_expires_at||!t.lease_expires_at||Ii(t.lease_expires_at,e.lease_expires_at)<=0))?!0:!t||t.state!==e.state||t.reason!==e.reason?!1:e.observed_at!==null&&t.observed_at!==null&&Ii(t.observed_at,e.observed_at)<0||e.lease_expires_at!==null&&t.lease_expires_at!==null&&Ii(t.lease_expires_at,e.lease_expires_at)<0:!1;function Ri(e,t){if(e.root_actor_id!==t.root_actor_id||e.subtree_actor_id!==t.subtree_actor_id)return!1;if(e.stream_cursor!==null&&!Fi(t.stream_cursor,e.stream_cursor))return!0;let n=new Map(e.nodes.map(e=>[e.actor_id,e]));for(let e of t.nodes){let t=n.get(e.actor_id);if(!t)continue;if(e.revision.session_metadata_version<t.revision.session_metadata_version)return!0;let r=t.revision.actor_directory_revision,i=e.revision.actor_directory_revision;if(r!==null&&i!==null&&i<r||t.activation&&e.activation&&e.activation.attempt<t.activation.attempt||t.activation&&e.activation&&t.activation.activation_id===e.activation.activation_id&&t.activation.attempt===e.activation.attempt&&([`succeeded`,`failed`,`cancelled`].includes(t.activation.status)&&e.activation.status!==t.activation.status||Li(t.local_task,e.local_task))||r!==null&&i===r&&t.activation&&e.activation&&e.activation.attempt===t.activation.attempt&&e.activation.activation_id!==t.activation.activation_id)return!0}return!1}var zi=class extends Error{constructor(){super(f(`the_agent_structure_response_is_invalid_or_unsupported__d3bdb4ac`))}},Bi=()=>{throw new zi},Vi=new TextEncoder,Hi=e=>{if(typeof e!=`string`)return!1;if(e.length===32)return/^[0-9a-f]{32}$/i.test(e);let t=e.length===38&&e.startsWith(`{`)&&e.endsWith(`}`)?e.slice(1,-1):e.length===45&&e.startsWith(`urn:uuid:`)?e.slice(9):e;return t.length===36&&/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(t)},Ui=e=>Number.isSafeInteger(e)&&e>=0,Wi=(e,t)=>typeof e==`string`&&[...e].length<=t&&![...e].some(e=>{let t=e.codePointAt(0);return t<32||t>=127&&t<=159||t>=55296&&t<=57343||t>=8234&&t<=8238||t>=8294&&t<=8297}),Gi=e=>{if(typeof e!=`string`)return!1;let t=/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(?:\.\d{1,9})?(?:Z|[+-](\d{2}):(\d{2}))$/.exec(e);if(!t||t[0]!==e||!Number.isFinite(Date.parse(e)))return!1;let[n,r,i,a,o,s]=t.slice(1,7).map(Number),c=Number(t[7]??0),l=Number(t[8]??0),u=[31,n%4==0&&(n%100!=0||n%400==0)?29:28,31,30,31,30,31,31,30,31,30,31];return r>=1&&r<=12&&i>=1&&i<=u[r-1]&&a<24&&o<60&&s<60&&c<24&&l<60},Ki=e=>Wi(e,256)&&e.length>0&&e.trim()===e&&Vi.encode(e).length<=256&&!e.includes(`..`)&&!/[\\/]/.test(e),qi=(e,t)=>t.includes(e),Ji=(e,t)=>{if(!e||typeof e!=`object`||Array.isArray(e))return Bi();let n=e;return Object.keys(n).length!==t.length||t.some(e=>!Object.hasOwn(n,e))?Bi():n};function Yi(e,t,n=t){if(!Ki(t)||!Ki(n))return Bi();let r=e&&typeof e==`object`&&`schema_version`in e?e.schema_version:null,i=Ji(e,[`schema_version`,`root_actor_id`,`subtree_actor_id`,`snapshot_id`,`stream_cursor`,`nodes`,...r===2?[`refresh_after_ms`]:[]]);if(r!==1&&r!==2||i.root_actor_id!==t||i.subtree_actor_id!==n||typeof i.snapshot_id!=`string`||i.snapshot_id.length!==68||!RegExp(`^as${r}-[0-9a-f]{64}$`).test(i.snapshot_id)||i.stream_cursor!==null&&!Pi(i.stream_cursor)||!Array.isArray(i.nodes)||i.nodes.length===0||i.nodes.length>256||r===2&&i.refresh_after_ms!==null&&(!Ui(i.refresh_after_ms)||i.refresh_after_ms<1e3||i.refresh_after_ms>2147483647))return Bi();let a=[],o=new Map;for(let e of i.nodes){let n=Ji(e,[`actor_id`,`parent_actor_id`,`root_actor_id`,`depth`,`title`,`role`,`logical_state`,`placement_class`,`revision`,`activation`,...r===2?[`local_task`]:[]]);if(!Ki(n.actor_id)||o.has(n.actor_id)||n.root_actor_id!==t||n.parent_actor_id!==null&&!Ki(n.parent_actor_id)||!Ui(n.depth)||n.depth>4294967295||!Wi(n.title,160)||!qi(n.role,[`root`,`child`])||n.logical_state!==null&&!qi(n.logical_state,[`cold`,`active`,`failed`,`retired`])||n.placement_class!==null&&!qi(n.placement_class,[`local`,`docker`,`ssh`,`remote`,`schedulable`]))return Bi();let i=Ji(n.revision,[`session_metadata_version`,`actor_directory_revision`]);if(!Ui(i.session_metadata_version)||i.actor_directory_revision!==null&&(!Ui(i.actor_directory_revision)||i.actor_directory_revision===0))return Bi();let s=null;if(n.activation!==null){let e=Ji(n.activation,[`activation_id`,`attempt`,`status`]);if(!Hi(e.activation_id)||!Ui(e.attempt)||e.attempt===0||!qi(e.status,[`reserved`,`running`,`succeeded`,`failed`,`cancelled`]))return Bi();s={activation_id:e.activation_id,attempt:e.attempt,status:e.status}}if(i.actor_directory_revision===null&&(n.logical_state!==null||s!==null||n.placement_class!==null)||n.logical_state===null&&i.actor_directory_revision!==null||s===null&&n.placement_class!==null)return Bi();let c=null;if(r===2&&n.local_task!==null){let e=Ji(n.local_task,[`state`,`reason`,`observed_at`,`lease_expires_at`]);if(n.role!==`child`||n.placement_class!==null&&n.placement_class!==`local`||s===null||!qi(e.state,[`running`,`stopped`,`stop_unconfirmed`])||(e.state===`stop_unconfirmed`?!qi(e.reason,[`execution_stop_unconfirmed`,`lease_expired_without_stop`]):e.reason!==null)||e.observed_at!==null&&!Gi(e.observed_at)||e.lease_expires_at!==null&&!Gi(e.lease_expires_at))return Bi();c={state:e.state,reason:e.reason,observed_at:e.observed_at,lease_expires_at:e.lease_expires_at}}let l={actor_id:n.actor_id,parent_actor_id:n.parent_actor_id,root_actor_id:t,depth:n.depth,title:n.title,role:n.role,...r===2?{local_task:c}:{},logical_state:n.logical_state,placement_class:n.placement_class,revision:{session_metadata_version:i.session_metadata_version,actor_directory_revision:i.actor_directory_revision},activation:s};a.push(l),o.set(l.actor_id,l)}let s=o.get(n);if(!s||(n===t?s.parent_actor_id!==null||s.depth!==0||s.role!==`root`:s.parent_actor_id===null||o.has(s.parent_actor_id)||s.depth===0||s.role!==`child`))return Bi();let c=new Map;for(let e of a){if(e.actor_id===n)continue;let t=e.parent_actor_id===null?void 0:o.get(e.parent_actor_id);if(!t||e.role!==`child`||e.depth!==t.depth+1)return Bi();let r=c.get(t.actor_id)??[];r.push(e.actor_id),c.set(t.actor_id,r)}let l=new Set,u=[n];for(let e=0;e<u.length;e+=1){if(l.has(u[e]))return Bi();l.add(u[e]),u.push(...c.get(u[e])??[])}return l.size===a.length?{schema_version:r,...r===2?{refresh_after_ms:i.refresh_after_ms}:{},root_actor_id:t,subtree_actor_id:n,snapshot_id:i.snapshot_id,stream_cursor:i.stream_cursor,nodes:a}:Bi()}async function Xi(e,t=e,n){if(!Ki(e)||!Ki(t))return Bi();let r=new URLSearchParams({subtree_id:t}),i=await Ot.fetchRaw(`actors/${encodeURIComponent(e)}/snapshot?${r}`,{signal:n,cache:`no-store`,headers:{Accept:Ni}}),a=i.body?.getReader();if(!a)return Bi();let o=[],s=0;try{let e=i.headers.get(`content-type`)?.split(`;`,1)[0].trim().toLowerCase();if(e!==`application/json`&&e!==`application/vnd.bamboo.actor-snapshot.v2+json`)return Bi();for(;;){let e=await a.read();if(e.done)break;if(s+=e.value.byteLength,s>262144)return Bi();o.push(e.value)}}finally{await a.cancel().catch(()=>void 0),a.releaseLock()}let c=new Uint8Array(s),l=0;for(let e of o)c.set(e,l),l+=e.byteLength;let u;try{u=JSON.parse(new TextDecoder(`utf-8`,{fatal:!0}).decode(c))}catch{return Bi()}return Yi(u,e,t)}var Zi=(e,t)=>e.actorId===t.actorId&&e.parentActorId===t.parentActorId&&e.depth===t.depth&&e.title===t.title&&e.role===t.role&&e.lifecycle===t.lifecycle&&e.placement===t.placement&&e.placementUnavailableReason===t.placementUnavailableReason&&e.health===t.health&&e.localTaskDiagnostic===t.localTaskDiagnostic&&e.queuedCount===t.queuedCount&&e.waitingForCount===t.waitingForCount&&e.pendingRequestCount===t.pendingRequestCount,Qi=e=>{if(e.logical_state===`retired`||e.logical_state===`failed`||e.logical_state===null)return e.logical_state??`unknown`;if(e.logical_state===`active`){if(e.local_task&&e.local_task.state!==`running`)return`unknown`;if(e.activation?.status===`reserved`)return`queued`;if(e.activation?.status===`running`)return`running`}if(e.logical_state===`cold`){if(e.activation?.status===`succeeded`)return`completed`;if(e.activation?.status===`cancelled`)return`cancelled`}return e.logical_state};function $i(e,t=!1,n){let r=n?.rootActorId===e.subtree_actor_id?n:void 0,i=Object.create(null),a=Object.create(null),o=Object.create(null);for(let t of e.nodes){let e={actorId:t.actor_id,parentActorId:t.parent_actor_id,depth:t.depth,title:t.title,role:t.role===`root`?f(`root_agent_9cfcb9f9`):f(`sub_agent_acd37b4c`),lifecycle:Qi(t),placement:t.placement_class??`unknown`,placementUnavailableReason:t.placement_class===null?t.local_task?`native_task`:t.activation===null?`no_activation`:`not_reported`:null,health:t.local_task&&t.local_task.state!==`running`?`unknown`:null,localTaskDiagnostic:t.local_task&&t.local_task.state!==`running`?t.local_task.state:null,queuedCount:null,waitingForCount:null,pendingRequestCount:null},n=r?.byId[t.actor_id];i[t.actor_id]=n&&Zi(n,e)?n:e,o[t.actor_id]=[]}for(let t of e.nodes)t.actor_id!==e.subtree_actor_id&&t.parent_actor_id!==null&&o[t.parent_actor_id].push(t.actor_id);for(let[e,t]of Object.entries(o)){let n=r?.childrenById[e];a[e]=n&&n.length===t.length&&n.every((e,n)=>e===t[n])?n:t}return r&&r.needsSnapshot===t&&Object.keys(r.byId).length===e.nodes.length&&e.nodes.every(e=>r.byId[e.actor_id]===i[e.actor_id]&&r.childrenById[e.actor_id]===a[e.actor_id])?r:{rootActorId:e.subtree_actor_id,byId:i,childrenById:a,needsSnapshot:t}}function ea(e){if(Ct(e)){if(e.status===401||e.status===403)return f(`this_connection_cannot_read_agent_structure_check_bambo_2abedc8d`);if(e.status===404||e.status===501)return f(`this_bamboo_version_does_not_provide_agent_structure_ch_ae23a7fe`);if(e.status===409)return f(`agent_structure_or_permissions_are_changing_and_cannot__bc1899b0`);if(e.status===413)return f(`agent_structure_exceeds_the_current_read_limit_and_cann_a53518ef`)}return f(`agent_structure_cannot_be_confirmed_right_now_reload_st_2ba610a7`)}function ta(e){return Ct(e)?e.status===409||e.status>=500&&e.status!==501:e instanceof U||e instanceof Tt}function na(e,t,n=null,r=null){u();let[i,a]=(0,K.useState)({rootId:null,snapshot:null,loading:!1,error:null,gapReason:null,gapActorId:null}),o=(0,K.useRef)(0),s=(0,K.useRef)(null),c=(0,K.useRef)(null),l=(0,K.useRef)(0),d=(0,K.useRef)(null),f=(0,K.useRef)(null),p=(0,K.useRef)(null),m=(0,K.useRef)(!1),h=(0,K.useRef)(null),g=(0,K.useRef)(null),_=(0,K.useRef)(void 0),v=(0,K.useRef)({rootId:null,count:null}),y=(0,K.useRef)({rootId:e,active:t,interestedActorId:n});y.current={rootId:e,active:t,interestedActorId:n};let b=(0,K.useRef)(()=>{}),x=(0,K.useCallback)(async()=>{let e=y.current;if(!e.rootId||!e.active)return;let t=e.rootId,n=++o.current;c.current!==null&&(clearTimeout(c.current),c.current=null),s.current?.abort();let r=new AbortController;s.current=r,a(e=>({rootId:t,snapshot:e.rootId===t?e.snapshot:null,loading:!0,error:null,gapReason:e.rootId===t?e.gapReason:null,gapActorId:e.rootId===t?e.gapActorId:null}));try{let e=await Xi(t,t,r.signal);if(r.signal.aborted||o.current!==n||y.current.rootId!==t||!y.current.active)return;if(h.current&&Ri(h.current,e)){a(e=>e.rootId===t?{...e,loading:!1,error:null,gapReason:`snapshot_regression`,gapActorId:null}:e);return}h.current=e,l.current=0,_.current!==void 0&&Fi(e.stream_cursor,_.current)&&(_.current=void 0),a(()=>({rootId:t,snapshot:e,loading:!1,error:null,gapReason:g.current?.reason??(_.current===void 0?null:`transport_gap`),gapActorId:g.current?.actorId??null}))}catch(e){if(r.signal.aborted||o.current!==n||y.current.rootId!==t||!y.current.active)return;if(h.current&&_.current!==void 0&&ta(e)){a(n=>n.rootId===t?{...n,loading:!1,error:ea(e),gapReason:g.current?.reason??`transport_gap`,gapActorId:g.current?.actorId??null}:n);let n=Math.min(500*2**Math.min(l.current,6),3e4);l.current+=1,c.current=setTimeout(()=>{c.current=null,y.current.rootId===t&&y.current.active&&b.current()},n);return}h.current=null,a(n=>({rootId:t,snapshot:null,loading:!1,error:ea(e),gapReason:n.rootId===t?n.gapReason:null,gapActorId:n.rootId===t?n.gapActorId:null}))}finally{s.current===r&&(s.current=null,m.current&&(m.current=!1,b.current()))}},[]),S=(0,K.useCallback)(()=>{let{rootId:e}=y.current,t=p.current!==null;p.current=e,!t&&queueMicrotask(()=>{let e=p.current;if(p.current=null,!(!e||y.current.rootId!==e||!y.current.active)){if(s.current){m.current=!0;return}x()}})},[x]);b.current=S;let C=(0,K.useCallback)(()=>{++o.current,c.current!==null&&(clearTimeout(c.current),c.current=null),l.current=0,d.current!==null&&(clearTimeout(d.current),d.current=null),f.current=null,s.current?.abort(),s.current=null,p.current=null,m.current=!1,h.current=null,g.current=null,_.current=void 0},[]);(0,K.useEffect)(()=>(t&&e&&x(),C),[e,t,x,C]),(0,K.useEffect)(()=>{let n=v.current;v.current={rootId:e,count:r},t&&e&&n.rootId===e&&n.count!==null&&r!==null&&n.count!==r&&x()},[e,t,r,x]),(0,K.useEffect)(()=>{d.current!==null&&(clearTimeout(d.current),d.current=null);let n=i.snapshot;if(!t||!e||i.rootId!==e||n?.schema_version!==2)return;let r=n.refresh_after_ms,a=performance.now(),o=n.nodes.filter(e=>e.local_task!==null&&e.local_task!==void 0).sort((e,t)=>e.actor_id.localeCompare(t.actor_id)),s=JSON.stringify(o.map(e=>[e.actor_id,e.activation,e.local_task])),c=f.current,l=c?.key===s?c:{key:s,due:1/0,consumed:!1};if(f.current=l,!(r==null||l.consumed||!o.some(e=>e.local_task?.state===`running`)))return l.due=Math.min(l.due,a+r),d.current=setTimeout(()=>{d.current=null,!(y.current.rootId!==e||!y.current.active)&&(l.consumed=!0,S())},Math.max(0,l.due-performance.now())),()=>{d.current!==null&&(clearTimeout(d.current),d.current=null)}},[t,e,i.rootId,i.snapshot,S]);let w=t&&!!e&&i.rootId===e&&i.snapshot?.root_actor_id===e&&i.snapshot.subtree_actor_id===e,T=w?i.snapshot?.stream_cursor??null:null;(0,K.useEffect)(()=>{if(!w||!e)return;let t=!0,n=(n,r)=>{if(!t||y.current.rootId!==e||!y.current.active||!r&&Fi(h.current?.stream_cursor??null,n))return;let i=_.current,o=!r&&s.current!==null&&i!==void 0&&Fi(i,n);i===void 0?_.current=n:i===null||n===null?_.current=null:Fi(n,i)?_.current=n:Fi(i,n)||(_.current=null),r&&a(t=>t.rootId===e?{...t,gapReason:g.current?.reason??`transport_gap`,gapActorId:g.current?.actorId??null}:t),o||S()},r=Bt(e,T,{onControl:e=>n(e.cursor,e.reason===`gap`||e.reason===`unavailable`),onGap:()=>n(h.current?.stream_cursor??null,!0)});return()=>{t=!1,r.close()}},[w,e,T,S]);let E=t&&!!e&&!!n&&i.rootId===e&&h.current===i.snapshot&&i.snapshot?.root_actor_id===e&&i.snapshot.subtree_actor_id===e&&i.snapshot.nodes.some(t=>t.actor_id===n&&t.root_actor_id===e);return(0,K.useEffect)(()=>{if(!E||!e||!n)return;let t=!0,r=r=>{!t||y.current.rootId!==e||y.current.interestedActorId!==n||!y.current.active||(g.current={reason:r,actorId:n},a(t=>t.rootId===e?{...t,gapReason:r,gapActorId:n}:t),S())},i=Ft(n,{onEvent:i=>{if(!t||y.current.rootId!==e||y.current.interestedActorId!==n||!y.current.active)return;let a=h.current,o=a?.nodes.find(e=>e.actor_id===n);if(i.root_actor_id!==e||i.actor_id!==n||i.parent_actor_id!==o?.parent_actor_id||a?.root_actor_id!==e||o?.root_actor_id!==e){r(`scope_mismatch`);return}if(!(o.activation&&i.attempt<o.activation.attempt)){if(!o.activation||o.activation.activation_id!==i.activation_id||o.activation.attempt!==i.attempt){r(`activation_mismatch`);return}S()}},onControl:i=>{!t||y.current.rootId!==e||y.current.interestedActorId!==n||!y.current.active||(i.reason===`gap`?r(`transport_gap`):S())},onGap:()=>r(`transport_gap`)});return()=>{t=!1,i.close()}},[E,e,n,S]),{...i.rootId===e?i:{rootId:e,snapshot:null,loading:t&&e!==null,error:null,gapReason:null,gapActorId:null},refresh:x}}var ra=e(r(),1);function ia(e){return typeof e==`object`?e.key:e}function aa(e,t){let n=e.length;return new Proxy(e,{get(e,r,i){if(typeof r==`string`){let i=r.charCodeAt(0);if(i>=48&&i<=57){let i=+r;if(Number.isInteger(i)&&i>=0&&i<n){let n=e[i];if(typeof n!=`object`){let r=t[i*2];n=e[i]={index:i,key:n,start:r,size:t[i*2+1],end:r+t[i*2+1],lane:0}}return n}}if(r===`length`)return n}return Reflect.get(e,r,i)}})}function oa(e,t,n){let r=n.initialDeps??[],i,a=!0;function o(){let o=e();return o.length!==r.length||o.some((e,t)=>r[t]!==e)?(r=o,i=t(...o),n?.onChange&&!(a&&n.skipInitialOnChange)&&n.onChange(i),a=!1,i):i}return o.updateDeps=e=>{r=e},o}function sa(e,t){if(e===void 0)throw Error(`Unexpected undefined${t?`: ${t}`:``}`);return e}var ca=(e,t)=>Math.abs(e-t)<1.01,la=(e,t,n)=>{let r;return Object.assign(function(...i){e.clearTimeout(r),r=e.setTimeout(()=>t.apply(this,i),n)},{cancel:()=>{e.clearTimeout(r)}})},ua,da=()=>{if(ua!==void 0)return ua;if(typeof navigator>`u`)return ua=!1;if(/iP(hone|od|ad)/.test(navigator.userAgent))return ua=!0;let e=navigator.maxTouchPoints;return ua=navigator.platform===`MacIntel`&&e!==void 0&&e>0},fa=e=>{let{offsetWidth:t,offsetHeight:n}=e;return{width:t,height:n}},pa=e=>e,ma=e=>{let t=Math.max(e.startIndex-e.overscan,0),n=Math.min(e.endIndex+e.overscan,e.count-1)-t+1,r=Array(n);for(let e=0;e<n;e++)r[e]=t+e;return r},ha=(e,t)=>{let n=e.scrollElement;if(!n)return;let r=e.targetWindow;if(!r)return;let i=e=>{let{width:n,height:r}=e;t({width:Math.round(n),height:Math.round(r)})};if(i(fa(n)),!r.ResizeObserver)return()=>{};let a=new r.ResizeObserver(t=>{let r=()=>{let e=t[0];if(e?.borderBoxSize){let t=e.borderBoxSize[0];if(t){i({width:t.inlineSize,height:t.blockSize});return}}i(fa(n))};e.options.useAnimationFrameWithResizeObserver?requestAnimationFrame(r):r()});return a.observe(n,{box:`border-box`}),()=>{a.unobserve(n)}},ga={passive:!0},_a=typeof window>`u`?!0:`onscrollend`in window,va=(e,t,n)=>{let r=e.scrollElement;if(!r)return;let i=e.targetWindow;if(!i)return;let a=e.options.useScrollendEvent&&_a,o=0,s=a?null:la(i,()=>t(n(r),!1),e.options.isScrollingResetDelay),c=e=>()=>{o=n(r),s?.(),t(o,e)},l=c(!0),u=c(!1);return r.addEventListener(`scroll`,l,ga),a&&r.addEventListener(`scrollend`,u,ga),()=>{r.removeEventListener(`scroll`,l),a&&r.removeEventListener(`scrollend`,u),s?.cancel()}},ya=(e,t)=>va(e,t,t=>{let{horizontal:n,isRtl:r}=e.options;return n?t.scrollLeft*(r&&-1||1):t.scrollTop}),ba=(e,t,n)=>{if(n.options.useCachedMeasurements){let t=n.indexFromElement(e),r=n.options.getItemKey(t);return n.itemSizeCache.get(r)??n.options.estimateSize(t)}if(t?.borderBoxSize){let e=t.borderBoxSize[0];if(e)return Math.round(e[n.options.horizontal?`inlineSize`:`blockSize`])}if(!t){let t=n.indexFromElement(e),r=n.options.getItemKey(t),i=n.itemSizeCache.get(r);if(i!==void 0)return i}return e[n.options.horizontal?`offsetWidth`:`offsetHeight`]},xa=(e,{adjustments:t=0,behavior:n},r)=>{var i,a;(a=(i=r.scrollElement)?.scrollTo)==null||a.call(i,{[r.options.horizontal?`left`:`top`]:e+t,behavior:n})};function Sa(e,t,n,r){if(t===0)return!1;let i=r(0),a=new Set,o=0;for(;o<e;){let e=n(o);if(e===i)break;a.add(e),o++}let s=e-o;if(s===0||s>=t)return!1;for(let e=0;e<s;e++)if(r(e)!==n(o+e))return!1;for(let e=s;e<t;e++)if(a.has(r(e)))return!1;return!0}var Ca=class{constructor(e){this.unsubs=[],this.scrollElement=null,this.targetWindow=null,this.isScrolling=!1,this.scrollState=null,this.measurementsCache=[],this._singleLaneMeasurements=null,this.itemSizeCache=new Map,this.itemSizeCacheVersion=0,this.laneAssignments=new Map,this.pendingMin=null,this.prevLanes=void 0,this.lanesChangedFlag=!1,this.lanesSettling=!1,this.pendingScrollAnchor=null,this.scrollRect=null,this.scrollOffset=null,this.scrollDirection=null,this.scrollAdjustments=0,this._iosDeferredAdjustment=0,this._iosTouching=!1,this._iosJustTouchEnded=!1,this._iosTouchEndTimerId=null,this._intendedScrollOffset=null,this._clampedAdjustment=null,this.elementsCache=new Map,this.now=()=>{var e;return((e=this.targetWindow?.performance)?.now)?.call(e)??Date.now()},this.observer=(()=>{let e=null,t=()=>e||(!this.targetWindow||!this.targetWindow.ResizeObserver?null:e=new this.targetWindow.ResizeObserver(e=>{e.forEach(e=>{let t=()=>{let t=e.target,n=this.indexFromElement(t);if(!t.isConnected){this.observer.unobserve(t);for(let[e,n]of this.elementsCache)if(n===t){this.elementsCache.delete(e);break}return}this.isIndexInRange(n)&&this.shouldMeasureDuringScroll(n)&&this.resizeItem(n,this.options.measureElement(t,e,this))};this.options.useAnimationFrameWithResizeObserver?requestAnimationFrame(t):t()})}));return{disconnect:()=>{var n;(n=t())==null||n.disconnect(),e=null},observe:e=>t()?.observe(e,{box:`border-box`}),unobserve:e=>t()?.unobserve(e)}})(),this.range=null,this.setOptions=e=>{let t={debug:!1,initialOffset:0,overscan:1,paddingStart:0,paddingEnd:0,scrollPaddingStart:0,scrollPaddingEnd:0,horizontal:!1,getItemKey:pa,rangeExtractor:ma,onChange:()=>{},measureElement:ba,initialRect:{width:0,height:0},scrollMargin:0,gap:0,indexAttribute:`data-index`,initialMeasurementsCache:[],lanes:1,anchorTo:`start`,followOnAppend:!1,scrollEndThreshold:1,isScrollingResetDelay:150,enabled:!0,isRtl:!1,useScrollendEvent:!1,useAnimationFrameWithResizeObserver:!1,laneAssignmentMode:`estimate`,useCachedMeasurements:!1};for(let n in e){let r=e[n];r!==void 0&&(t[n]=r)}let n=this.options,r=null,i=null,a=!1;if(n!==void 0&&n.enabled&&t.enabled&&t.anchorTo===`end`&&this.scrollElement!==null){let e=n.count,o=t.count,s=this.getMeasurements(),c=this._singleLaneMeasurements?.items??s,l=e=>ia(c[e]),u=e>0?l(0):null,d=e>0?l(e-1):null;if(o!==e||e>0&&o>0&&(t.getItemKey(0)!==u||t.getItemKey(o-1)!==d)){a=!0;let c=e>0?this.getVirtualItemForOffset(this.getScrollOffset())??s[0]:null;c&&(r=[c.key,this.getScrollOffset()-c.start]);let u=t.followOnAppend===!0?`auto`:t.followOnAppend||null;u&&o>0&&this.isAtEnd(n.scrollEndThreshold)&&(e===0||t.getItemKey(o-1)!==d)&&(o>e||Sa(e,o,l,t.getItemKey))&&(i=u)}}this.options=t,a&&(this.pendingMin=0,this.itemSizeCacheVersion++);let o=!1,s=0;if(r&&this.scrollOffset!==null){let[e,t]=r,n=this.getMeasurements(),{count:a,getItemKey:c}=this.options,l=0;for(;l<a&&c(l)!==e;)l++;if(l<a){let e=n[l];if(e){let n=Math.max(0,e.start+t);!i&&n!==this.scrollOffset&&(s=n-this.scrollOffset,this.scrollOffset=n,o=!0)}}}(o||i)&&(this.pendingScrollAnchor=[o?r[0]:null,o?r[1]:0,i,s])},this.notify=e=>{var t,n;(n=(t=this.options).onChange)==null||n.call(t,this,e)},this.maybeNotify=oa(()=>(this.calculateRange(),[this.isScrolling,this.range?this.range.startIndex:null,this.range?this.range.endIndex:null]),e=>{this.notify(e)},{key:!1,debug:()=>this.options.debug,initialDeps:[this.isScrolling,this.range?this.range.startIndex:null,this.range?this.range.endIndex:null]}),this.cleanup=()=>{this.unsubs.filter(Boolean).forEach(e=>e()),this.unsubs=[],this.observer.disconnect(),this.rafId!=null&&this.targetWindow&&(this.targetWindow.cancelAnimationFrame(this.rafId),this.rafId=null),this.scrollState=null,this.isScrolling=!1,this.scrollDirection=null,this._iosDeferredAdjustment=0,this._iosTouching=!1,this._iosJustTouchEnded=!1,this._clampedAdjustment=null,this.scrollElement=null,this.targetWindow=null},this._didMount=()=>()=>{this.cleanup()},this._willUpdate=()=>{let e=this.options.enabled?this.options.getScrollElement():null;if(this.scrollElement!==e){if(this.cleanup(),!e){this.maybeNotify();return}if(this.scrollElement=e,this.scrollElement&&`ownerDocument`in this.scrollElement?this.targetWindow=this.scrollElement.ownerDocument.defaultView:this.targetWindow=this.scrollElement?.window??null,this.elementsCache.forEach(e=>{this.observer.observe(e)}),this.unsubs.push(this.options.observeElementRect(this,e=>{this.scrollRect=e,this.maybeNotify()})),this.unsubs.push(this.options.observeElementOffset(this,(e,t)=>{if(t&&this._intendedScrollOffset===null&&e===this.scrollOffset)return;this._intendedScrollOffset!==null&&Math.abs(e-this._intendedScrollOffset)<1.5&&(e=this._intendedScrollOffset),this._intendedScrollOffset=null,this._clampedAdjustment!==null&&Math.abs(e-this._clampedAdjustment.maxAtWrite)>=1.5&&(this._clampedAdjustment=null),this.scrollAdjustments=0;let n=this.getScrollOffset();this.scrollDirection=t?n===e?this.scrollDirection:n<e?`forward`:`backward`:null,this.scrollOffset=e,this.isScrolling=t,this._flushIosDeferredIfReady(),this.scrollState&&this.scheduleScrollReconcile(),this.maybeNotify()})),`addEventListener`in this.scrollElement){let e=this.scrollElement,t=()=>{this._iosTouching=!0,this._iosJustTouchEnded=!1,this._iosTouchEndTimerId!==null&&this.targetWindow!=null&&(this.targetWindow.clearTimeout(this._iosTouchEndTimerId),this._iosTouchEndTimerId=null)},n=()=>{this._iosTouching=!1,!(!da()||this.targetWindow==null)&&(this._iosJustTouchEnded=!0,this._iosTouchEndTimerId=this.targetWindow.setTimeout(()=>{this._iosJustTouchEnded=!1,this._iosTouchEndTimerId=null,this._flushIosDeferredIfReady()},150))};e.addEventListener(`touchstart`,t,ga),e.addEventListener(`touchend`,n,ga),this.unsubs.push(()=>{e.removeEventListener(`touchstart`,t),e.removeEventListener(`touchend`,n),this._iosTouchEndTimerId!==null&&this.targetWindow!=null&&(this.targetWindow.clearTimeout(this._iosTouchEndTimerId),this._iosTouchEndTimerId=null)})}this._scrollToOffset(this.getScrollOffset(),{adjustments:void 0,behavior:void 0})}let t=this.pendingScrollAnchor;if(this.pendingScrollAnchor=null,t&&this.scrollElement&&this.options.enabled){let[e,n,r,i]=t;e!==null&&!r&&(da()&&(this.isScrolling||this._iosTouching||this._iosJustTouchEnded)?i!==0&&(this._iosDeferredAdjustment+=i):this.scrollState?.behavior===`smooth`&&!ca(this.getScrollOffset()-i,this.scrollState.lastTargetOffset)||this._scrollToOffset(this.getScrollOffset(),{adjustments:void 0,behavior:void 0})),r&&this.scrollToEnd({behavior:r})}this._retryClampedAdjustment()},this._retryClampedAdjustment=()=>{if(this._clampedAdjustment===null||!this.scrollElement||!this.options.enabled)return;let{target:e,maxAtWrite:t}=this._clampedAdjustment,n=this.getMaxScrollOffset();n>t+.5&&(this._clampedAdjustment=e>n+.5?{target:e,maxAtWrite:n}:null,this._scrollToOffset(e,{adjustments:void 0,behavior:void 0}))},this._flushIosDeferredIfReady=()=>{if(this._iosDeferredAdjustment===0||this.isScrolling||this._iosTouching||this._iosJustTouchEnded)return;let e=this.getScrollOffset(),t=this.getMaxScrollOffset();if(e<0||e>t)return;if(this._iosDeferredAdjustment<0&&e>=t-1){this._iosDeferredAdjustment=0;return}let n=this._iosDeferredAdjustment;this._iosDeferredAdjustment=0,this._scrollToOffset(e,{adjustments:this.scrollAdjustments+=n,behavior:void 0})},this.rafId=null,this.getSize=()=>this.options.enabled?(this.scrollRect=this.scrollRect??this.options.initialRect,this.scrollRect[this.options.horizontal?`width`:`height`]):(this.scrollRect=null,0),this.getScrollOffset=()=>this.options.enabled?(this.scrollOffset=this.scrollOffset??(typeof this.options.initialOffset==`function`?this.options.initialOffset():this.options.initialOffset),this.scrollOffset):(this.scrollOffset=null,0),this.getMeasurementOptions=oa(()=>[this.options.count,this.options.paddingStart,this.options.scrollMargin,this.options.getItemKey,this.options.enabled,this.options.lanes,this.options.laneAssignmentMode,this.options.gap],(e,t,n,r,i,a,o,s)=>(this.prevLanes!==void 0&&this.prevLanes!==a&&(this.lanesChangedFlag=!0),this.prevLanes=a,this.pendingMin=null,{count:e,paddingStart:t,scrollMargin:n,getItemKey:r,enabled:i,lanes:a,laneAssignmentMode:o,gap:s}),{key:!1}),this.isIndexInRange=e=>e>=0&&e<this.options.count,this.getMeasurements=oa(()=>[this.getMeasurementOptions(),this.itemSizeCacheVersion],({count:e,paddingStart:t,scrollMargin:n,getItemKey:r,enabled:i,lanes:a,laneAssignmentMode:o,gap:s},c)=>{let l=this.itemSizeCache;if(!i)return this.measurementsCache=[],this._singleLaneMeasurements=null,this.itemSizeCache.clear(),this.laneAssignments.clear(),[];if(this.laneAssignments.size>e)for(let t of this.laneAssignments.keys())t>=e&&this.laneAssignments.delete(t);this.lanesChangedFlag&&(this.lanesChangedFlag=!1,this.lanesSettling=!0,this.measurementsCache=[],this._singleLaneMeasurements=null,this.itemSizeCache.clear(),this.laneAssignments.clear(),this.pendingMin=null),this.measurementsCache.length===0&&!this.lanesSettling&&(this.measurementsCache=this.options.initialMeasurementsCache,this.measurementsCache.forEach(e=>{this.itemSizeCache.set(e.key,e.size)}));let u=this.lanesSettling?0:this.pendingMin??0;if(this.pendingMin=null,this.lanesSettling&&this.measurementsCache.length===e&&(this.lanesSettling=!1),a===1){let i=e*2,a=this._singleLaneMeasurements?.flat;if(!a||a.length<i){let e=new Float64Array(i);a&&u>0&&e.set(a.subarray(0,u*2)),a=e}let o=u===0?Array(e):this._singleLaneMeasurements.items.slice(),c;if(u===0)c=t+n;else{let e=u-1;c=a[e*2]+a[e*2+1]+s}for(let t=u;t<e;t++){let e=r(t);o[t]=e;let n=l.get(e),i=typeof n==`number`?n:this.options.estimateSize(t);a[t*2]=c,a[t*2+1]=i,c+=i+s}this._singleLaneMeasurements={flat:a,items:o};let d=aa(o,a);return this.measurementsCache=d,d}let d=this.measurementsCache.slice(0,u),f=Array(a).fill(void 0),p=new Float64Array(a),m=0;for(let e=0;e<u;e++){let t=d[e];t&&(f[t.lane]===void 0&&m++,f[t.lane]=e,p[t.lane]=t.end)}for(let i=u;i<e;i++){let e=r(i),c=this.laneAssignments.get(i),u,h,g=o===`estimate`||l.has(e);if(c!==void 0&&this.options.lanes>1){u=c;let e=f[u],r=e===void 0?void 0:d[e];h=r?r.end+s:t+n}else if(m===a){let e=0,t=p[0],n=f[0];for(let r=1;r<a;r++){let i=p[r];(i<t||i===t&&f[r]<n)&&(e=r,t=i,n=f[r])}u=e,h=t+s,g&&this.laneAssignments.set(i,u)}else u=i%this.options.lanes,h=t+n,g&&this.laneAssignments.set(i,u);let _=l.get(e),v=typeof _==`number`?_:this.options.estimateSize(i),y=h+v;d[i]={index:i,start:h,size:v,end:y,key:e,lane:u},f[u]===void 0&&m++,f[u]=i,p[u]=y}return this.measurementsCache=d,d},{key:!1,debug:()=>this.options.debug}),this.calculateRange=oa(()=>[this.getMeasurements(),this.getSize(),this.getScrollOffset(),this.options.lanes],(e,t,n,r)=>e.length===0||t===0?(this.range=null,null):(this.range=Ea(e,t,n,r,r===1&&this._singleLaneMeasurements!==null?this._singleLaneMeasurements.flat:null),this.range),{key:!1,debug:()=>this.options.debug}),this.getVirtualIndexes=oa(()=>{let e=null,t=null,n=this.calculateRange();return n&&(e=n.startIndex,t=n.endIndex),this.maybeNotify.updateDeps([this.isScrolling,e,t]),[this.options.rangeExtractor,this.options.overscan,this.options.count,e,t]},(e,t,n,r,i)=>r===null||i===null?[]:e({startIndex:r,endIndex:i,overscan:t,count:n}),{key:!1,debug:()=>this.options.debug}),this.indexFromElement=e=>{let t=this.options.indexAttribute,n=e.getAttribute(t);return n?parseInt(n,10):(console.warn(`Missing attribute name '${t}={index}' on measured element.`),-1)},this.shouldMeasureDuringScroll=e=>{if(!this.scrollState||this.scrollState.behavior!==`smooth`)return!0;let t=this.scrollState.index??this.getVirtualItemForOffset(this.scrollState.lastTargetOffset)?.index;if(t!==void 0&&this.range){let n=Math.max(this.options.overscan,Math.ceil((this.range.endIndex-this.range.startIndex)/2)),r=Math.max(0,t-n),i=Math.min(this.options.count-1,t+n);return e>=r&&e<=i}return!0},this.measureElement=e=>{if(!e){this.elementsCache.forEach((e,t)=>{e.isConnected||(this.observer.unobserve(e),this.elementsCache.delete(t))});return}let t=this.indexFromElement(e);if(!this.isIndexInRange(t))return;let n=this.options.getItemKey(t),r=this.elementsCache.get(n);r!==e&&(r&&this.observer.unobserve(r),this.observer.observe(e),this.elementsCache.set(n,e)),(!this.isScrolling||this.scrollState)&&this.shouldMeasureDuringScroll(t)&&this.resizeItem(t,this.options.measureElement(e,void 0,this))},this.resizeItem=(e,t)=>{if(!this.isIndexInRange(e))return;let n,r,i,a=this._singleLaneMeasurements?.flat;if(this.options.lanes===1&&a!=null)i=this.options.getItemKey(e),r=a[e*2],n=a[e*2+1];else{let t=this.measurementsCache[e];if(!t)return;i=t.key,r=t.start,n=t.size}let o=this.itemSizeCache.get(i)??n,s=t-o;if(s!==0){let a=this.options.anchorTo===`end`&&this.scrollState?.behavior!==`smooth`&&this.getVirtualDistanceFromEnd()<=this.options.scrollEndThreshold,c=a?this.getTotalSize():0,l=this.getScrollOffset()+this.scrollAdjustments,u=this.itemSizeCache.has(i)?r+o<=l&&this.scrollDirection!==`backward`:r<l,d=this.scrollState?.behavior!==`smooth`&&(this.shouldAdjustScrollPositionOnItemSizeChange===void 0?u:this.shouldAdjustScrollPositionOnItemSizeChange(this.measurementsCache[e]??{index:e,key:i,start:r,size:n,end:r+n,lane:0},s,this));(this.pendingMin===null||e<this.pendingMin)&&(this.pendingMin=e),this.itemSizeCache.set(i,t),this.itemSizeCacheVersion++;let f=!1;a?f=this.applyScrollAdjustment(this.getTotalSize()-c):d&&(f=this.applyScrollAdjustment(s)),this.notify(f),this._retryClampedAdjustment()}},this.getVirtualItems=oa(()=>[this.getVirtualIndexes(),this.getMeasurements()],(e,t)=>{let n=[];for(let r=0,i=e.length;r<i;r++){let i=t[e[r]];n.push(i)}return n},{key:!1,debug:()=>this.options.debug}),this.getVirtualItemForOffset=e=>{let t=this.getMeasurements();if(t.length===0)return;let n=this._singleLaneMeasurements?.flat,r=this.options.lanes===1&&n!=null;return sa(t[wa(0,t.length-1,r?e=>n[e*2]:e=>sa(t[e]).start,e)])},this.getMaxScrollOffset=()=>{if(!this.scrollElement)return 0;if(`scrollHeight`in this.scrollElement)return this.options.horizontal?this.scrollElement.scrollWidth-this.scrollElement.clientWidth:this.scrollElement.scrollHeight-this.scrollElement.clientHeight;{let e=this.scrollElement.document.documentElement;return this.options.horizontal?e.scrollWidth-this.scrollElement.innerWidth:e.scrollHeight-this.scrollElement.innerHeight}},this.getVirtualDistanceFromEnd=()=>Math.max(this.getTotalSize()-this.getSize()-this.getScrollOffset(),0),this.getDistanceFromEnd=()=>Math.max(this.getMaxScrollOffset()-this.getScrollOffset(),0),this.isAtEnd=(e=this.options.scrollEndThreshold)=>this.getDistanceFromEnd()<=e,this.getOffsetForAlignment=(e,t,n=0)=>{if(!this.scrollElement)return 0;let r=this.getSize(),i=this.getScrollOffset();t===`auto`&&(t=e>=i+r?`end`:`start`),t===`center`?e+=(n-r)/2:t===`end`&&(e-=r);let a=this.getMaxScrollOffset();return Math.max(Math.min(a,e),0)},this.getOffsetForIndex=(e,t=`auto`)=>{e=Math.max(0,Math.min(e,this.options.count-1));let n=this.getSize(),r=this.getScrollOffset(),i=this.measurementsCache[e];if(!i)return;if(t===`auto`)if(i.end>=r+n-this.options.scrollPaddingEnd)t=`end`;else if(i.start<=r+this.options.scrollPaddingStart)t=`start`;else return[r,t];if(t===`end`&&e===this.options.count-1)return[this.getMaxScrollOffset(),t];let a=t===`end`?i.end+this.options.scrollPaddingEnd:i.start-this.options.scrollPaddingStart;return[this.getOffsetForAlignment(a,t,i.size),t]},this.scrollToOffset=(e,{align:t=`start`,behavior:n=`auto`}={})=>{this._iosDeferredAdjustment=0;let r=this.getOffsetForAlignment(e,t),i=this.now();this.scrollState={index:null,align:t,behavior:n,startedAt:i,lastTargetOffset:r,stableFrames:0},this._scrollToOffset(r,{adjustments:void 0,behavior:n}),this.scheduleScrollReconcile()},this.scrollToIndex=(e,{align:t=`auto`,behavior:n=`auto`}={})=>{this._iosDeferredAdjustment=0,e=Math.max(0,Math.min(e,this.options.count-1));let r=this.getOffsetForIndex(e,t);if(!r)return;let[i,a]=r,o=this.now();this.scrollState={index:e,align:a,behavior:n,startedAt:o,lastTargetOffset:i,stableFrames:0},this._scrollToOffset(i,{adjustments:void 0,behavior:n}),this.scheduleScrollReconcile()},this.scrollBy=(e,{behavior:t=`auto`}={})=>{let n=this.getScrollOffset()+e,r=this.now();this.scrollState={index:null,align:`start`,behavior:t,startedAt:r,lastTargetOffset:n,stableFrames:0},this._scrollToOffset(n,{adjustments:void 0,behavior:t}),this.scheduleScrollReconcile()},this.scrollToEnd=({behavior:e=`auto`}={})=>{if(this.options.count>0){this.scrollToIndex(this.options.count-1,{align:`end`,behavior:e});return}this.scrollToOffset(Math.max(this.getTotalSize()-this.getSize(),0),{behavior:e})},this.getTotalSize=()=>{let e=this.getMeasurements(),t;if(e.length===0)t=this.options.paddingStart;else if(this.options.lanes===1){let n=e.length-1,r=this._singleLaneMeasurements?.flat;t=r==null?e[n]?.end??0:r[n*2]+r[n*2+1]}else{let n=Array(this.options.lanes).fill(null),r=e.length-1;for(;r>=0&&n.some(e=>e===null);){let t=e[r];n[t.lane]===null&&(n[t.lane]=t.end),r--}t=Math.max(...n.filter(e=>e!==null))}return Math.max(t-this.options.scrollMargin+this.options.paddingEnd,0)},this.takeSnapshot=()=>{let e=[];if(this.itemSizeCache.size===0)return e;let t=this.getMeasurements();for(let n of t)n&&this.itemSizeCache.has(n.key)&&e.push({index:n.index,key:n.key,start:n.start,size:n.size,end:n.end,lane:n.lane});return e},this._scrollToOffset=(e,{adjustments:t,behavior:n})=>{this._intendedScrollOffset=e+(t??0),this.options.scrollToFn(e,{behavior:n,adjustments:t},this)},this.measure=()=>{this.pendingMin=null,this.itemSizeCache.clear(),this.laneAssignments.clear(),this.itemSizeCacheVersion++,this.notify(!1)},this.setOptions(e)}applyScrollAdjustment(e,t){if(e===0)return!1;if(da()&&(this.isScrolling||this._iosTouching||this._iosJustTouchEnded))return this._iosDeferredAdjustment+=e,!1;{let n=this.getScrollOffset()+this.scrollAdjustments+e,r=this.scrollElement,i=r!==null&&(`scrollHeight`in r||`document`in r)?this.getMaxScrollOffset():null;return this._clampedAdjustment=i!==null&&n>i+.5?{target:n,maxAtWrite:i}:null,this._scrollToOffset(this.getScrollOffset(),{adjustments:this.scrollAdjustments+=e,behavior:t}),this.scrollOffset!==null&&(this.scrollOffset+=this.scrollAdjustments,this.scrollOffset<0&&(this.scrollOffset=0),this.scrollAdjustments=0),!0}}scheduleScrollReconcile(){if(!this.targetWindow){this.scrollState=null;return}this.rafId??=this.targetWindow.requestAnimationFrame(()=>{this.rafId=null,this.reconcileScroll()})}reconcileScroll(){if(!this.scrollState||!this.scrollElement)return;if(this.now()-this.scrollState.startedAt>5e3){this.scrollState=null;return}let e=this.scrollState.index==null?void 0:this.getOffsetForIndex(this.scrollState.index,this.scrollState.align),t=e?e[0]:this.scrollState.lastTargetOffset,n=t!==this.scrollState.lastTargetOffset;if(!n&&ca(t,this.getScrollOffset())){if(this.scrollState.stableFrames++,this.scrollState.stableFrames>=1){this.getScrollOffset()!==t&&this._scrollToOffset(t,{adjustments:void 0,behavior:`auto`}),this.scrollState=null;return}}else if(this.scrollState.stableFrames=0,n){let e=this.getSize()||600,n=Math.abs(t-this.getScrollOffset()),r=this.scrollState.behavior===`smooth`&&n>e;this.scrollState.lastTargetOffset=t,r||(this.scrollState.behavior=`auto`),this._scrollToOffset(t,{adjustments:void 0,behavior:r?`smooth`:`auto`})}this.scheduleScrollReconcile()}},wa=(e,t,n,r)=>{for(;e<=t;){let i=(e+t)/2|0,a=n(i);if(a<r)e=i+1;else if(a>r)t=i-1;else return i}return e>0?e-1:0};function Ta(e,t,n){let r=0;for(;r<=t;){let i=(r+t)/2|0,a=e[i*2];if(a<n)r=i+1;else if(a>n)t=i-1;else return i}return r>0?r-1:0}function Ea(e,t,n,r,i){let a=e.length-1;if(e.length<=r)return{startIndex:0,endIndex:a};if(r===1&&i!==null){let e=Ta(i,a,n),r=e,o=n+t;for(;r<a&&i[r*2]+i[r*2+1]<o;)r++;return{startIndex:e,endIndex:r}}let o=wa(0,a,t=>e[t].start,n),s=o;if(r===1)for(;s<a&&e[s].end<n+t;)s++;else if(r>1){let i=Array(r).fill(0);for(;s<a&&i.some(e=>e<n+t);){let t=e[s];i[t.lane]=t.end,s++}let c=Array(r).fill(n+t);for(;o>=0&&c.some(e=>e>=n);){let t=e[o];c[t.lane]=t.start,o--}o=Math.max(0,o-o%r),s=Math.min(a,s+(r-1-s%r))}return{startIndex:o,endIndex:s}}var Da=typeof document<`u`?K.useLayoutEffect:K.useEffect;function Oa({useFlushSync:e=!0,directDomUpdates:t=!1,directDomUpdatesMode:n=`transform`,...r}){let i=K.useReducer(e=>e+1,0)[1],a=K.useRef({enabled:t,mode:n,container:null,lastSize:null,lastPositions:new WeakMap,prevRange:null});a.current.enabled=t,a.current.mode=n;let o=K.useRef(!1),s=e=>{let t=a.current;if(!t.enabled||!t.container)return;let n=e.getTotalSize();if(n!==t.lastSize){t.lastSize=n;let r=e.options.horizontal?`width`:`height`;t.container.style[r]=`${n}px`}},c=e=>{let t=a.current;if(!t.enabled||!t.container)return;s(e);let n=!!e.options.horizontal,r=t.mode===`transform`,i=n?`left`:`top`,o=e.options.scrollMargin,c=e.getVirtualItems();for(let a of c){let s=a.start-o,c=e.elementsCache.get(a.key);c&&t.lastPositions.get(c)!==s&&(t.lastPositions.set(c,s),r?c.style.transform=n?`translate3d(${s}px, 0, 0)`:`translate3d(0, ${s}px, 0)`:c.style[i]=`${s}px`)}},l={...r,onChange:(t,n)=>{var s;let l=a.current,u=!0;if(l.enabled){c(t);let e=t.range,n=l.prevRange;u=!n||n.isScrolling!==t.isScrolling||n.startIndex!==e?.startIndex||n.endIndex!==e?.endIndex,u&&(l.prevRange=e?{startIndex:e.startIndex,endIndex:e.endIndex,isScrolling:t.isScrolling}:null)}u&&(e&&n&&!o.current?(0,ra.flushSync)(i):i()),(s=r.onChange)==null||s.call(r,t,n)}},[u]=K.useState(()=>{let e=new Ca(l),t=e.measureElement;return e.measureElement=e=>{o.current=!0;try{t(e)}finally{o.current=!1}},Object.assign(e,{containerRef:t=>{let n=a.current;if(n.container=t,n.lastSize=null,t&&n.enabled){let r=e.getTotalSize();n.lastSize=r;let i=e.options.horizontal?`width`:`height`;t.style[i]=`${r}px`}}})});return u.setOptions(l),Da(()=>u._didMount(),[]),Da(()=>(s(u),u._willUpdate())),Da(()=>{c(u)}),u}function ka(e){return Oa({observeElementRect:ha,observeElementOffset:ya,scrollToFn:xa,...e})}var Aa=64,ja={width:320,height:320},Ma={get active(){return f(`activity_f98dfe0b`)},get unknown(){return f(`lifecycle_unknown_2217e6e4`)},get cold(){return f(`not_started_e6fc5eb8`)},get queued(){return f(`queued_d6f766f2`)},get running(){return f(`running_1f0eb99b`)},get suspended(){return f(`paused_eb0c326b`)},get completed(){return f(`completed_f28461bb`)},get failed(){return f(`failed_28384d7a`)},get cancelled(){return f(`cancelled_a37778f1`)},get retired(){return f(`exited_899df7e2`)},get lost(){return f(`unreachable_8deefc6c`)}},Na={get docker(){return f(`container_6d23f04b`)},ssh:`SSH`,get schedulable(){return f(`pending_scheduling_d8eb0fb8`)},get local(){return f(`local_8a94c4a1`)},get remote(){return f(`remote_edca84b9`)},get container(){return f(`container_6d23f04b`)},get scheduled(){return f(`pending_scheduling_d8eb0fb8`)},get unknown(){return f(`actor_placement_not_reported`)}},Pa={get healthy(){return f(`healthy_296de0e3`)},get waiting(){return f(`waiting_26c8cfcb`)},get stalled(){return f(`stalled_97daa1e1`)},get failed(){return f(`unhealthy_428fb8bf`)},get orphaned(){return f(`orphaned_a1d6c892`)},get blocked_needs_input(){return f(`waiting_for_input_6569c6e6`)},get lost(){return f(`disconnected_481cf3ad`)},get unknown(){return f(`unknown_state_93e474c6`)}},Fa={active:{Icon:lr,cls:`text-primary`},unknown:{Icon:dr,cls:`text-muted-foreground`},cold:{Icon:ur,cls:`text-muted-foreground`},queued:{Icon:fr,cls:`text-amber-500`},running:{Icon:L,cls:`text-primary`,spin:!0},suspended:{Icon:Kn,cls:`text-muted-foreground`},completed:{Icon:Wn,cls:`text-emerald-500`},failed:{Icon:Jn,cls:`text-destructive`},cancelled:{Icon:Gn,cls:`text-muted-foreground`},retired:{Icon:Gn,cls:`text-muted-foreground`},lost:{Icon:P,cls:`text-destructive`}},Ia=new Set([`active`,`cold`,`unknown`]);function La(e){let t=new Set,n=(r,i)=>{if(!i.add(r))return!1;let a=!1;for(let t of e.childrenById[r]??[])e.byId[t]&&n(t,i)&&(a=!0);return e.byId[r]?.lifecycle===`running`&&(a=!0),a&&t.add(r),a};return e.byId[e.rootActorId]&&n(e.rootActorId,new Set),t}function Ra(e,t){if(!e.byId[e.rootActorId])return[];let n=[],r=new Set,i=[{actorId:e.rootActorId,parentActorId:null,position:1,siblingCount:1}];for(;i.length>0;){let a=i.pop();if(r.has(a.actorId))continue;let o=e.byId[a.actorId];if(!o)continue;r.add(a.actorId);let s=e.childrenById[a.actorId]??[];if(n.push({node:o,parentActorId:a.parentActorId,position:a.position,siblingCount:a.siblingCount,hasChildren:s.length>0}),t.has(a.actorId))for(let e=s.length-1;e>=0;--e)i.push({actorId:s[e],parentActorId:a.actorId,position:e+1,siblingCount:s.length})}return n}function za(e,t){return ha(e,e=>t({width:e.width||ja.width,height:e.height||ja.height}))}function Ba({topology:e,selectedActorId:t,onSelectActor:n,unreadActorIds:r,error:i,onRetry:a,className:o}){u();let s=(0,K.useId)(),c=(0,K.useRef)(null),[l,d]=(0,K.useState)(()=>new Set([e.rootActorId])),[p,m]=(0,K.useState)(t??e.rootActorId),h=(0,K.useRef)(t);h.current=t;let g=(0,K.useRef)(null),_=(0,K.useMemo)(()=>Ra(e,l),[e,l]),v=(0,K.useMemo)(()=>La(e),[e]),y=(0,K.useRef)(_);y.current=_;let b=(0,K.useCallback)(e=>y.current[e]?.node.actorId??e,[]),x=_.findIndex(e=>e.node.actorId===p),S=x<0?0:x,C=(0,K.useCallback)(e=>{let t=ma(e);return _.length===0||t.includes(S)?t:[...t,S].sort((e,t)=>e-t)},[_.length,S]),w=ka({count:_.length,getScrollElement:()=>c.current,getItemKey:b,estimateSize:()=>Aa,overscan:4,initialRect:ja,observeElementRect:za,rangeExtractor:C}),T=w.getVirtualItems();(0,K.useEffect)(()=>{d(new Set([e.rootActorId])),m(h.current??e.rootActorId)},[e.rootActorId]),(0,K.useEffect)(()=>{if(g.current===t)return;if(!t){g.current=null;return}let n=e.byId[t];n&&(g.current=t,m(t),d(t=>{let r=new Set(t),i=n.parentActorId;for(;i;)r.add(i),i=e.byId[i]?.parentActorId??null;return r.size===t.size?t:r}))},[t,e.byId]);let E=(0,K.useCallback)(e=>{d(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),D=e=>{let t=_[e];t&&(m(t.node.actorId),w.scrollToIndex(e,{align:`auto`}))};return(0,q.jsxs)(`div`,{className:G(`flex min-h-0 min-w-0 flex-col`,o),"data-actor-tree":!0,children:[(0,q.jsxs)(`div`,{className:`flex items-center justify-between gap-2 px-3 py-2 text-sm font-medium`,children:[(0,q.jsx)(`span`,{children:f(`agent_structure_4cf93237`)}),e.needsSnapshot?(0,q.jsx)(`span`,{role:`status`,className:`text-xs font-normal text-muted-foreground`,children:f(`syncing_954ec984`)}):null]}),i?(0,q.jsxs)(`div`,{role:`alert`,className:`flex items-center gap-2 px-3 py-2 text-xs text-destructive`,children:[(0,q.jsx)(`span`,{className:`min-w-0 flex-1 break-words`,children:i}),a?(0,q.jsxs)(W,{size:`sm`,variant:`outline`,onClick:a,children:[(0,q.jsx)(Be,{}),f(`retry_b8784c8d`)]}):null]}):null,_.length===0?(0,q.jsx)(`p`,{className:`px-3 py-4 text-sm text-muted-foreground`,children:e.needsSnapshot?f(`loading_agent_structure_53ba2f19`):f(i?`agent_structure_is_not_confirmed_yet_eeda2d8c`:`no_agents_to_display_ea1f7e8b`)}):(0,q.jsx)(`div`,{ref:c,role:`tree`,"aria-label":f(`agent_session_structure_0bfa0e40`),"aria-activedescendant":`${s}-actor-${S}`,tabIndex:0,onKeyDown:e=>{if(_.length===0)return;let t=_[S];if(t){switch(e.key){case`ArrowDown`:D(Math.min(_.length-1,S+1));break;case`ArrowUp`:D(Math.max(0,S-1));break;case`Home`:D(0);break;case`End`:D(_.length-1);break;case`ArrowRight`:t.hasChildren&&!l.has(t.node.actorId)?E(t.node.actorId):t.hasChildren&&D(S+1);break;case`ArrowLeft`:t.hasChildren&&l.has(t.node.actorId)?E(t.node.actorId):t.parentActorId&&D(_.findIndex(e=>e.node.actorId===t.parentActorId));break;case`Enter`:case` `:n(t.node.actorId);break;default:return}e.preventDefault()}},className:`min-h-0 max-h-80 overflow-y-auto outline-none focus-visible:ring-2 focus-visible:ring-ring`,"data-actor-tree-scroll":!0,children:(0,q.jsx)(`div`,{className:`relative w-full`,style:{height:w.getTotalSize()},"data-actor-tree-virtual":!0,children:T.map(e=>{let i=_[e.index];if(!i)return null;let{node:a}=i,o=l.has(a.actorId),u=t===a.actorId,d=r?.has(a.actorId)??!1,p=[a.queuedCount!==null&&a.queuedCount>0?f(`queued_0d272e30`,{v0:a.queuedCount}):null,a.waitingForCount!==null&&a.waitingForCount>0?f(`waiting_23f9a84a`,{v0:a.waitingForCount}):null,a.pendingRequestCount!==null&&a.pendingRequestCount>0?f(`requests_25082fa5`,{v0:a.pendingRequestCount}):null].filter(e=>e!==null),h=a.lifecycle===`unknown`&&a.localTaskDiagnostic?f(a.localTaskDiagnostic===`stop_unconfirmed`?`native_task_stop_unconfirmed`:`native_task_stopped_outcome_unconfirmed`):Ma[a.lifecycle],g=a.localTaskDiagnostic===`stop_unconfirmed`&&a.lifecycle!==`unknown`?f(`native_task_stop_unconfirmed`):null,y=a.placement===`unknown`?f(a.placementUnavailableReason===`no_activation`?`actor_placement_no_activation`:a.placementUnavailableReason===`native_task`?`actor_placement_native_task`:`actor_placement_missing`):void 0,b=a.health===null?f(`health_unknown_d7b6f7ae`):Pa[a.health],x=Ia.has(a.lifecycle)&&v.has(a.actorId),C=x?Fa.running:Fa[a.lifecycle],w=x?Ma.running:h;return(0,q.jsxs)(`div`,{id:`${s}-actor-${e.index}`,role:`treeitem`,tabIndex:-1,"aria-level":a.depth+1,"aria-posinset":i.position,"aria-setsize":i.siblingCount,"aria-expanded":i.hasChildren?o:void 0,"aria-selected":u,"aria-label":[a.title||f(`unnamed_agent_1ff6bc72`),a.role||f(`agent_5e84ea61`),h,g,Na[a.placement],b,...p,d?f(`has_unread_messages`):null].filter(Boolean).join(f(`list_separator`)),"aria-description":y,"data-actor-id":a.actorId,className:G(`absolute left-0 top-0 flex h-16 w-full cursor-pointer items-center gap-2 overflow-hidden border-b px-2 text-left text-sm hover:bg-accent/50`,u&&`bg-muted/30`,!u&&S===e.index&&`bg-primary/5`),style:{transform:`translateY(${e.start}px)`,paddingLeft:Math.min(a.depth,8)*16+8},onClick:e=>{e.target.closest(`[data-actor-toggle]`)?E(a.actorId):n(a.actorId),m(a.actorId),c.current?.focus()},children:[(0,q.jsx)(`span`,{"data-actor-toggle":!0,"aria-hidden":`true`,className:`flex size-5 shrink-0 items-center justify-center`,children:i.hasChildren?o?(0,q.jsx)(me,{className:`size-4`}):(0,q.jsx)(ve,{className:`size-4`}):null}),(0,q.jsx)(`span`,{"data-actor-status":a.lifecycle,"data-inherits-running":x?`true`:void 0,"aria-hidden":`true`,title:w,className:G(`flex size-3.5 shrink-0 items-center justify-center`,C.cls),children:(0,q.jsx)(C.Icon,{className:G(`size-3.5`,C.spin&&`animate-spin`)})}),(0,q.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,q.jsxs)(`span`,{className:`flex min-w-0 items-center gap-1`,children:[(0,q.jsx)(`span`,{className:`truncate font-medium`,children:a.title||f(`unnamed_agent_1ff6bc72`)}),d?(0,q.jsx)(`span`,{className:`size-1.5 shrink-0 rounded-full bg-primary`,"aria-hidden":`true`}):null]}),(0,q.jsxs)(`span`,{className:`block truncate text-xs text-muted-foreground`,children:[a.role||f(`agent_5e84ea61`),` · `,h,g?` · ${g}`:``,` · `,(0,q.jsx)(`span`,{"data-actor-placement":!0,title:y,children:Na[a.placement]}),` · `,b,p.length?` · ${p.join(` · `)}`:``]})]})]},e.key)})})})]})}function Va({rootId:e,active:t,selectedActorId:n,descendantCountHint:r=null,onSelectActor:i}){u();let a=na(e,t,n,r),o=(0,K.useRef)(void 0),s=(0,K.useMemo)(()=>a.snapshot?$i(a.snapshot,a.loading,o.current):{rootActorId:e??``,byId:Object.create(null),childrenById:Object.create(null),needsSnapshot:a.loading},[a.snapshot,a.loading,e]);return(0,K.useEffect)(()=>{o.current=s},[s]),(0,q.jsxs)(`section`,{className:`rounded-lg border`,"data-actor-snapshot-panel":!0,"aria-busy":a.loading,children:[(0,q.jsxs)(`div`,{className:`flex items-center justify-between gap-2 px-3 py-2 text-xs text-muted-foreground`,children:[(0,q.jsx)(`span`,{children:f(`saved_agent_state_health_and_queue_information_unavaila_f82ce646`)}),e?(0,q.jsx)(W,{size:`sm`,variant:`ghost`,disabled:a.loading,onClick:()=>{a.refresh()},"aria-label":f(`refresh_agent_structure_277bb85d`),children:(0,q.jsx)(Be,{})}):null]}),a.gapReason?(0,q.jsx)(`p`,{role:`status`,"data-actor-gap":a.gapReason,"data-actor-gap-origin":a.gapActorId??void 0,className:`px-3 pb-2 text-xs text-muted-foreground [overflow-wrap:anywhere]`,children:a.gapReason===`snapshot_regression`?f(`an_older_agent_structure_was_returned_the_last_confirme_15ec0d29`):a.gapActorId?f(`actor_event_gap_origin`,{actorId:a.gapActorId}):f(`there_is_a_gap_in_agent_events_state_was_reloaded_but_e_0c545fcb`)}):null,e?(0,q.jsx)(Ba,{topology:s,selectedActorId:n,onSelectActor:i,error:a.error,onRetry:()=>{a.refresh()}}):(0,q.jsx)(`p`,{className:`px-3 py-4 text-sm text-muted-foreground`,children:f(`select_a_root_session_to_load_agent_structure_abe1ec98`)})]})}var Ha=()=>o(()=>import(`./SupervisorManagedSessions-DDL1goCC.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]),import.meta.url),Ua=e=>(0,K.lazy)(async()=>({default:(await e()).SupervisorManagedSessionsPanel}));function Wa({loadPanel:e=Ha,...t}){u();let[n,r]=(0,K.useState)(()=>Ua(e));return(0,q.jsx)(ue,{name:`Supervisor sessions`,fallback:(t,n)=>(0,q.jsxs)(`div`,{role:`alert`,className:`text-sm`,children:[(0,q.jsx)(`p`,{children:f(`supervisor_sessions_unavailable`)}),(0,q.jsx)(`button`,{type:`button`,className:`mt-2 underline`,onClick:()=>{r(Ua(e)),n()},children:f(`retry_b8784c8d`)})]}),children:(0,q.jsx)(K.Suspense,{fallback:(0,q.jsx)(`p`,{role:`status`,className:`text-xs text-muted-foreground`,children:f(`supervisor_sessions_loading`)}),children:(0,q.jsx)(n,{...t})})})}var Ga=`bamboo-default-supervisor`;function Ka(e){return e.id===`bamboo-default-supervisor`&&!e.parentSessionId&&e.kind!==`child`}function qa({sessionId:e,goldConfig:t,goalState:n}){u();let[r,i]=(0,K.useState)(!1),[a,o]=(0,K.useState)(``),[s,c]=(0,K.useState)(!1),[l,d]=(0,K.useState)(!1),[p,m]=(0,K.useState)(!1),[h,g]=(0,K.useState)(``),_=t?.goal,v=(t?.recovery?.max_attempts??0)>0?t.recovery:{max_attempts:3,max_elapsed_seconds:900};return(0,q.jsxs)(`section`,{className:`rounded-lg border p-3`,children:[(0,q.jsxs)(`div`,{className:`mb-2 flex items-center justify-between`,children:[(0,q.jsx)(`span`,{className:`text-xs font-medium text-muted-foreground`,children:f(`target_57060c88`)}),r?null:(0,q.jsx)(`button`,{onClick:()=>{o(_??``),c(t?.auto_continue_enabled??!1),d((t?.recovery?.max_attempts??0)>0),g(``),i(!0)},className:`text-xs text-primary hover:underline`,children:f(_?`edit_05183656`:`goal_set_action`)})]}),(0,q.jsxs)(`p`,{className:`mb-2 text-xs text-muted-foreground`,children:[f(`chat_commands_a9207e15`),(0,q.jsx)(`code`,{children:f(`goal_goal_text_4fe4dd06`)}),f(`set_and_pursue_270d1beb`),(0,q.jsx)(`code`,{children:`/goal off`}),f(`pause_bfaa6e86`),(0,q.jsx)(`code`,{children:`/goal clear`}),f(`clear_531ffd78`)]}),r?(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(`textarea`,{value:a,onChange:e=>o(e.target.value),autoFocus:!0,placeholder:f(`describe_the_goal_for_this_session_668b351d`),className:`min-h-16 w-full resize-y rounded-md border bg-background px-2.5 py-1.5 text-sm outline-none focus-visible:ring-2 focus-visible:ring-ring`}),(0,q.jsxs)(`label`,{className:`mt-2 flex items-center gap-2 text-xs`,children:[(0,q.jsx)(`input`,{type:`checkbox`,checked:s,onChange:e=>c(e.target.checked)}),f(`continue_pursuing_the_goal_automatically_9a0d0cd4`)]}),(0,q.jsxs)(`label`,{className:`mt-2 flex items-center gap-2 text-xs`,children:[(0,q.jsx)(`input`,{type:`checkbox`,checked:l,disabled:!s,onChange:e=>d(e.target.checked)}),f(`attempt_recovery_after_an_output_timeout_227c0054`)]}),s&&l&&(0,q.jsxs)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:[f(`extra_attempts_per_goal_at_most_71934320`),` `,Math.min(v.max_attempts,10),` `,f(`attempts_recovery_window_123ea7f2`),` `,Math.min(v.max_elapsed_seconds,3600)/60,` `,f(`minutes_stopping_ends_the_wait_4accfbf3`)]}),h&&(0,q.jsx)(`p`,{role:`alert`,className:`mt-1 text-xs text-destructive`,children:h}),(0,q.jsxs)(`div`,{className:`mt-1.5 flex justify-end gap-2`,children:[(0,q.jsx)(W,{size:`sm`,variant:`secondary`,disabled:p,onClick:()=>i(!1),children:f(`cancel_2cd0f3be`)}),(0,q.jsx)(W,{size:`sm`,disabled:p,onClick:async()=>{if(p)return;let n=a.trim();m(!0),g(``);try{await zt.patchSession(e,{gold_config:{...t??{enabled:!0},enabled:!0,goal:n||null,auto_continue_enabled:s,recovery:l&&s?v:{max_attempts:0,max_elapsed_seconds:0}}}),i(!1),await H.getState().loadChatHistory(e)}catch{g(f(`could_not_save_goal_please_try_again_46d0ad3b`))}finally{m(!1)}},children:f(`save_a3030bf8`)})]})]}):_?(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(`p`,{className:`text-sm leading-relaxed`,children:_}),n?.status?(0,q.jsxs)(`div`,{className:`mt-1.5 text-xs text-muted-foreground`,children:[f(`status_ed1eb79b`),n.status]}):null]}):(0,q.jsx)(`p`,{className:`text-xs leading-relaxed text-muted-foreground`,children:f(`no_goal_set_set_one_for_the_agent_to_pursue_and_check_f_221f6826`)})]})}var Ja={pending:{icon:`○`,cls:`text-muted-foreground`},in_progress:{icon:`◐`,cls:`text-primary`},completed:{icon:`✓`,cls:`text-emerald-500`},skipped:{icon:`–`,cls:`text-muted-foreground`},failed:{icon:`✗`,cls:`text-destructive`}};function Ya({label:e,value:t}){return u(),(0,q.jsxs)(`div`,{className:`flex items-center justify-between gap-3 py-0.5 text-sm`,children:[(0,q.jsx)(`span`,{className:`text-muted-foreground`,children:e}),(0,q.jsx)(`span`,{className:`truncate font-medium`,children:t})]})}var Xa=e=>`${yt(e)} tokens`;function Za({usage:e}){u();let t=e?.prefixCache,n=t?tt(t):void 0,r=typeof n==`number`?`${n.toFixed(1).replace(/\.0$/,``)}%`:null,i=t?.cacheReadInputTokens??e?.cacheReadInputTokens,a=!!(t?.retainedFromPreviousRound||e?.cacheReadInputTokensRetained);return(0,q.jsxs)(`div`,{"data-prefix-cache-details":!0,children:[(0,q.jsx)(`div`,{className:`mb-1 text-xs text-muted-foreground`,children:`Prefix Cache`}),t&&r?(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(Ya,{label:f(`hit_rate_da9e37af`),value:r}),(0,q.jsx)(Ya,{label:f(`cache_reads_1ded6559`),value:Xa(t.cacheReadInputTokens)}),(0,q.jsx)(Ya,{label:f(`new_input_56164cf0`),value:Xa(t.inputTokens)}),(0,q.jsx)(Ya,{label:f(`cache_creation_92797c69`),value:Xa(t.cacheCreationInputTokens)}),(0,q.jsx)(Ya,{label:f(`provider_input_cbf1d1f1`),value:Xa(Ke(t))}),(0,q.jsx)(Ya,{label:f(`data_status_bbd51f73`),value:f(a?`previous_completed_round_836ba413`:`latest_completed_round_fe872c8f`)}),(0,q.jsx)(`p`,{className:`mt-1.5 text-[11px] leading-relaxed text-muted-foreground`,children:f(`hit_rate_cache_reads_new_input_cache_creation_cache_rea_ae5ec6f5`)})]}):typeof i==`number`&&i>0?(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(Ya,{label:f(`cache_reads_1ded6559`),value:Xa(i)}),(0,q.jsx)(Ya,{label:f(`provider_input_cbf1d1f1`),value:f(`waiting_for_complete_data_a333ea86`)}),(0,q.jsx)(Ya,{label:f(`hit_rate_da9e37af`),value:f(`waiting_for_exact_data_42730723`)}),(0,q.jsx)(Ya,{label:f(`data_status_bbd51f73`),value:f(a?`previous_valid_value_84e70723`:`latest_compatible_data_a6b924c0`)}),(0,q.jsx)(`p`,{className:`mt-1.5 text-[11px] leading-relaxed text-muted-foreground`,children:f(`hit_rate_requires_provider_input_from_the_same_round_th_3f9518c8`)})]}):(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(Ya,{label:f(`hit_rate_da9e37af`),value:f(`no_data_yet_497c8569`)}),(0,q.jsx)(`p`,{className:`mt-1.5 text-[11px] leading-relaxed text-muted-foreground`,children:f(`shown_after_a_model_call_reports_provider_usage_709de1e3`)})]})]})}function Qa({usage:e}){return u(),(0,q.jsxs)(`div`,{"data-context-usage-details":!0,children:[(0,q.jsx)(`div`,{className:`mb-1 text-xs text-muted-foreground`,children:f(`context_estimate_11f23d14`)}),(0,q.jsx)(Ya,{label:f(`estimated_total_58f48562`),value:Xa(e.totalTokens)}),(0,q.jsx)(Ya,{label:f(`system_prompt_0894b78b`),value:Xa(e.systemTokens)}),(0,q.jsx)(Ya,{label:f(`session_window_7b78e572`),value:Xa(e.windowTokens)}),e.summaryTokens>0?(0,q.jsx)(Ya,{label:f(`summary_21c04b2e`),value:Xa(e.summaryTokens)}):null,(e.thinkingTokens??0)>0?(0,q.jsx)(Ya,{label:f(`reasoning_132411ba`),value:Xa(e.thinkingTokens)}):null,e.maxContextTokens?(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(Ya,{label:f(`context_window_bb074b86`),value:Xa(e.maxContextTokens)}),(0,q.jsx)(Ya,{label:f(`context_occupancy_ba08613d`),value:`${Math.min(100,e.totalTokens/e.maxContextTokens*100).toFixed(1).replace(/\.0$/,``)}%`}),(0,q.jsx)(`div`,{className:`mt-2 h-1.5 w-full overflow-hidden rounded-full bg-muted`,children:(0,q.jsx)(`div`,{className:`h-full rounded-full bg-primary`,style:{width:`${Math.min(100,Math.round(e.totalTokens/e.maxContextTokens*100))}%`}})})]}):null]})}function $a({sessionId:e,open:t,onClose:n,workspace:r,onEditWorkspace:i,onOpenReview:a,onCopySessionId:s,onSelectActor:c=()=>{},selectedActorId:l,docked:d=!1,width:p,embedded:m=!1}){u();let h=H(t=>e?mt(e)(t):ft(t)),g=H(t=>{let n=e?mt(e)(t):ft(t),r=n?.kind===`root`?n.id:n?.rootSessionId;return r?mt(r)(t)?.subagentCount??null:null}),_=H(t=>e?t.tokenUsages[e]:void 0),v=H(t=>e?t.taskLists[e]:void 0),y=H(t=>e?t.evaluationStates[e]:void 0),b=H(e=>e.loadTaskList),[x,S]=(0,K.useState)(!1),C=(0,K.useRef)(0);(0,K.useEffect)(()=>{S(!1)},[e]),(0,K.useEffect)(()=>()=>{++C.current},[t,e]);let w=H(Yr(t=>e?mt(e)(t)?.messages??[]:[])),T=(0,K.useMemo)(()=>ui(w),[w]),E=(0,K.useMemo)(()=>gi(T,r??void 0),[T,r]),D=(0,K.useMemo)(()=>_i(E),[E]),O=nt(e=>e.getProviderDisplayLabel);if((0,K.useEffect)(()=>{t&&e&&b(e)},[t,e,b]),!t)return null;let k=h?.config,A=k?.model_ref?.model||k?.model||`—`,j=k?.model_ref?.provider,M=j?O(j):null,N=k?.goalState,P=_??k?.tokenUsage,F=h?.kind===`root`?h.id:h?.rootSessionId??null,I=(0,q.jsxs)(q.Fragment,{children:[m?null:(0,q.jsxs)(`div`,{className:`flex items-center justify-between border-b px-4 py-3`,children:[(0,q.jsx)(`span`,{className:`text-sm font-semibold`,children:f(`inspector_fc48a7f2`)}),(0,q.jsx)(W,{size:`icon`,variant:`ghost`,onClick:n,children:(0,q.jsx)(He,{})})]}),(0,q.jsxs)(`div`,{className:`min-h-0 flex-1 space-y-4 overflow-y-auto p-4`,children:[h&&Ka(h)?(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(Wa,{active:t,onSelectSession:async(e,t,n)=>{let r=++C.current,i=H.getState(),a=i.currentSessionId,s=i.chats.find(t=>t.id===e),c=t&&i.chats.find(e=>e.id===t.target.root_session_id),l=i.executionBySession,u=t?[...new Set([e,t.target.root_session_id])]:[],d=e=>JSON.stringify(u.map(t=>{let n=e.chats.find(e=>e.id===t);return n?[n.createdAtExact,n.kind,n.rootSessionId,n.parentSessionId,n.config.projectId]:null})),f=d(i),p=t?i.chats.filter(e=>e.kind===`child`&&e.rootSessionId===t.target.root_session_id):[],m=e=>JSON.stringify(t?e.chats.filter(e=>e.kind===`child`&&e.rootSessionId===t.target.root_session_id).map(e=>[e.id,e.createdAtExact,e.parentSessionId,e.config.projectId]).sort((e,t)=>String(e[0]).localeCompare(String(t[0]))):[]),h=m(i),g=i.getSessionNavigationRevision(),_=!1,v=!1,y=t?H.subscribe(e=>{d(e)!==f&&(_=!0),m(e)!==h&&(v=!0)}):void 0;try{let i=()=>!_&&C.current===r&&H.getState().currentSessionId===a&&H.getState().getSessionNavigationRevision()===g&&(!n||n()),u,d;if(t){if(t.target.session_id!==e)return!1;let n=t,{managedSessionsClient:r,revalidateManagedSelection:a}=await o(async()=>{let{managedSessionsClient:e,revalidateManagedSelection:t}=await import(`./managedSessions-CNlNA0Gf.js`);return{managedSessionsClient:e,revalidateManagedSelection:t}},__vite__mapDeps([22,20,4,7,8,21,3,1,2,17,18]),import.meta.url);if(u=()=>a(n,i),d=()=>r.readBoundHistory(n),!i()||!await u())return!1}let f,m=s?.config.projectId??null,h=n=>{if(!t)return!1;let r=t.target;return n.id===e&&n.created_at===r.created_at&&n.kind===r.kind&&n.root_session_id===r.root_session_id&&(n.parent_session_id??null)===r.parent_session_id&&(n.project_id??null)===r.project_id};if(t){let n=t.target;if(s&&(s.createdAt!==Date.parse(n.created_at)||s.createdAtExact!==n.created_at||s.kind!==n.kind||s.rootSessionId!==n.root_session_id||(s.parentSessionId??null)!==n.parent_session_id))return!1;let r=s&&(n.kind===`root`?s:H.getState().chats.find(e=>e.id===n.root_session_id)),a=r&&H.getState().chats.filter(e=>e.kind===`child`&&e.rootSessionId===r.id).length,o=r?.kind===`root`&&a!==(r.subagentCount??0);if(!s||m!==n.project_id||o){let t=await zt.getSession(e);if(!i()||!h(t.session)||(f=await H.getState().stageSessionForNavigation(t.session)??void 0,!i()||!f))return!1}}else if(!await H.getState().restoreSession(e)||!i())return!1;let y=()=>{if(!t)return!0;let n=t.target,r=H.getState(),i=r.chats.find(t=>t.id===e);if(f&&(i!==s||v||p.some(e=>r.chats.find(t=>t.id===e.id)!==e)||f.some(e=>{let t=r.chats.find(t=>t.id===e.id);return t&&(t.createdAtExact!==e.created_at||t.kind!==e.kind||t.rootSessionId!==e.root_session_id||(t.parentSessionId??null)!==(e.parent_session_id??null))||r.executionBySession[e.id]!==l[e.id]})))return!1;let a=f?.find(t=>t.id===e),o=f?.find(e=>e.id===n.root_session_id),u=o&&H.getState().chats.find(e=>e.id===o.id);return o&&(u!==c||u&&(u.kind!==`root`||u.createdAtExact!==o.created_at))?!1:i?i.createdAt===Date.parse(n.created_at)&&i.createdAtExact===n.created_at&&i.kind===n.kind&&i.rootSessionId===n.root_session_id&&(i.parentSessionId??null)===n.parent_session_id&&((i.config.projectId??null)===n.project_id||!!s&&!!a&&(i.config.projectId??null)===m&&h(a)):!!a&&h(a)};if(!y())return!1;try{await H.getState().loadChatHistory(e,{throwOnError:!0,...f?{stagedSessions:f}:{},...u?{readHistory:d,managedSelection:t,beforeApply:async()=>i()&&y()&&!!await u?.(),canApply:()=>i()&&y(),selectOnApply:!0}:{}})}catch(e){if(e instanceof DOMException&&e.name===`AbortError`)return!1;throw e}return t?!0:!i()||!y()?!1:(H.getState().selectSession(e),!0)}finally{y?.()}}}),(0,q.jsxs)(`details`,{className:`rounded-lg border p-3`,open:x,onToggle:e=>S(e.currentTarget.open),"data-testid":`supervisor-auxiliary-agents`,children:[(0,q.jsx)(`summary`,{className:`cursor-pointer text-xs font-medium text-muted-foreground`,children:f(`supervisor_sessions_auxiliary`)}),(0,q.jsx)(`div`,{className:`mt-3`,children:(0,q.jsx)(Va,{rootId:F,active:t&&x,selectedActorId:l??e,descendantCountHint:g,onSelectActor:c})})]})]}):(0,q.jsx)(Va,{rootId:F,active:t,selectedActorId:l??e,descendantCountHint:g,onSelectActor:c}),(0,q.jsxs)(`section`,{className:`rounded-lg border p-3`,children:[(0,q.jsxs)(`div`,{className:`mb-2 flex items-center justify-between`,children:[(0,q.jsx)(`span`,{className:`text-xs font-medium text-muted-foreground`,children:f(`working_directory_3db7b06b`)}),i?(0,q.jsx)(`button`,{onClick:i,className:`text-xs text-primary hover:underline`,children:f(e?`change_6b01fce4`:`select_c11330b8`)}):null]}),(0,q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,q.jsx)(je,{className:`size-4 shrink-0 text-muted-foreground`}),(0,q.jsx)(`span`,{className:`min-w-0 flex-1 truncate font-mono text-xs`,title:r||void 0,children:r||f(`default_directory_4ff28651`)})]}),e?(0,q.jsx)(`p`,{className:`mt-1.5 text-[11px] text-muted-foreground`,children:f(`set_when_the_session_is_created_changes_apply_to_new_se_33699fd8`)}):null]}),e?(0,q.jsx)(qa,{sessionId:e,goldConfig:k?.goldConfig,goalState:N},e):null,(0,q.jsxs)(`section`,{className:`rounded-lg border p-3`,children:[(0,q.jsx)(`div`,{className:`mb-2 text-xs font-medium text-muted-foreground`,children:f(`task_list_a4ea7d95`)}),y?.isEvaluating?(0,q.jsxs)(`p`,{className:`mb-2 flex items-center gap-1.5 text-xs text-primary`,children:[(0,q.jsx)(`span`,{className:`size-1.5 animate-pulse rounded-full bg-primary`}),f(`evaluating_task_progress_602a2eb0`)]}):y?.reasoning?(0,q.jsx)(`p`,{className:`mb-2 rounded bg-muted/60 px-2 py-1.5 text-[11px] leading-relaxed text-muted-foreground`,children:y.reasoning}):null,!v||v.items.length===0?(0,q.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:f(`no_tasks_yet_da968898`)}):(0,q.jsx)(`ul`,{className:`space-y-1.5`,children:v.items.map(e=>{let t=Ja[e.status]??Ja.pending;return(0,q.jsxs)(`li`,{className:`flex gap-2 text-sm`,children:[(0,q.jsx)(`span`,{className:G(`mt-0.5 shrink-0`,t.cls),children:t.icon}),(0,q.jsx)(`span`,{className:G(`leading-relaxed`,e.status===`completed`&&`text-muted-foreground line-through`),children:e.description})]},e.id)})})]}),E.length>0?(0,q.jsxs)(`section`,{className:`rounded-lg border p-3`,children:[(0,q.jsxs)(`div`,{className:`mb-1.5 flex items-center justify-between gap-2`,children:[(0,q.jsx)(`span`,{className:`text-xs font-medium text-muted-foreground`,children:f(`file_changes_4d016b2f`)}),a?(0,q.jsxs)(`button`,{type:`button`,onClick:()=>a(),className:`flex items-center gap-0.5 text-xs text-primary hover:underline`,children:[`Review`,(0,q.jsx)(R,{className:`size-3`})]}):null]}),(0,q.jsxs)(`div`,{className:`mb-1.5 flex items-center justify-between gap-2 text-[11px] text-muted-foreground`,children:[(0,q.jsxs)(`span`,{children:[f(`count_files`,{count:D.fileCount}),` · `,f(`count_changes`,{count:D.editCount})]}),(0,q.jsxs)(`span`,{className:`shrink-0`,children:[(0,q.jsxs)(`span`,{className:`text-green-600 dark:text-green-400`,children:[`+`,D.addedLines]}),` `,(0,q.jsxs)(`span`,{className:`text-red-600 dark:text-red-400`,children:[`−`,D.removedLines]})]})]}),(0,q.jsx)(Mi,{groups:E,workspace:r??void 0,pathMode:`basename`,density:`compact`,variant:`summary`,onSelect:e=>a?.(e.filePath)})]}):null,(0,q.jsxs)(`details`,{className:`rounded-lg border p-3`,children:[(0,q.jsx)(`summary`,{className:`cursor-pointer select-none text-xs font-medium text-muted-foreground`,children:f(`advanced_details_d305be8b`)}),(0,q.jsxs)(`div`,{className:`mt-3 space-y-3`,children:[(0,q.jsxs)(`div`,{children:[(0,q.jsx)(`div`,{className:`mb-1 text-xs text-muted-foreground`,children:f(`config_148d195e`)}),e?(0,q.jsxs)(`div`,{className:`flex items-start justify-between gap-3 py-0.5 text-sm`,children:[(0,q.jsx)(`span`,{className:`shrink-0 text-muted-foreground`,children:f(`session_id_a76bd2d8`)}),(0,q.jsxs)(`div`,{className:`flex min-w-0 items-start gap-1`,children:[(0,q.jsx)(`code`,{className:`break-all text-right font-mono text-xs`,style:{userSelect:`text`},title:e,children:e}),(0,q.jsx)(`button`,{type:`button`,"aria-label":f(`copy_session_id_7df96a6b`),title:f(`copy_session_id_7df96a6b`),onClick:()=>s(e),className:`shrink-0 rounded p-0.5 text-muted-foreground hover:bg-accent hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring`,children:(0,q.jsx)(Ae,{className:`size-3.5`})})]})]}):null,(0,q.jsx)(Ya,{label:f(`model_c98e118e`),value:A}),M?(0,q.jsx)(Ya,{label:f(`provider_9e218722`),value:M}):null,k?.reasoningEffort?(0,q.jsx)(Ya,{label:f(`reasoning_level_c8c14507`),value:k.reasoningEffort}):null]}),P?(0,q.jsx)(Qa,{usage:P}):null,(0,q.jsx)(Za,{usage:P})]})]})]})]});return m?(0,q.jsx)(`div`,{className:`flex min-h-0 min-w-0 flex-1 flex-col`,children:I}):d?(0,q.jsx)(`aside`,{className:`flex shrink-0 flex-col border-l bg-card`,style:{width:p??384,maxWidth:`38vw`},children:I}):(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(`button`,{className:`fixed inset-0 z-40 bg-black/50`,"aria-label":f(`close_inspector_ac416b66`),onClick:n}),(0,q.jsx)(`aside`,{className:G(`fixed z-50 flex flex-col bg-card`,`inset-x-0 bottom-0 max-h-[90dvh] rounded-t-2xl border-t`,`md:inset-y-0 md:right-0 md:left-auto md:w-96 md:max-h-none md:rounded-none md:border-l md:border-t-0`),style:{paddingBottom:`env(safe-area-inset-bottom)`},children:I})]})}var eo=(0,K.lazy)(()=>o(()=>import(`./CommandPalette-FYYof7PJ.js`).then(e=>({default:e.CommandPalette})),__vite__mapDeps([23,1,2,3,4,6,24,25,26,11,12,10,15,16,13,14]),import.meta.url));function to({onClose:e,getReturnFocusTarget:t}){let n=s(),r=(0,K.useRef)(document.activeElement instanceof HTMLElement?document.activeElement:null);return(0,q.jsx)($t,{open:!0,onOpenChange:t=>{t||e()},children:(0,q.jsx)(Wt,{className:`fixed inset-0 z-[130] flex items-start justify-center bg-black/50 p-4 pt-[12vh]`,children:(0,q.jsxs)(Gt,{"data-command-palette":``,"aria-describedby":void 0,className:`w-full max-w-lg overflow-hidden rounded-2xl border bg-popover shadow-2xl`,onEscapeKeyDown:e=>{Ie(e)&&e.preventDefault()},onCloseAutoFocus:e=>{e.preventDefault(),queueMicrotask(()=>{document.querySelector(`[data-command-palette]`)||Re(t?t():r.current)})},children:[(0,q.jsx)(Kt,{className:`sr-only`,children:n(`search_sessions_or_actions_b2a0f9e8`)}),(0,q.jsx)(`p`,{role:`status`,className:`px-3 py-6 text-center text-sm text-muted-foreground`,children:n(`loading_4927a53b`)})]})})})}function no(e){return e.open?(0,q.jsx)(K.Suspense,{fallback:(0,q.jsx)(to,{...e}),children:(0,q.jsx)(eo,{...e})}):null}function ro(){return u(),(0,q.jsx)(`div`,{role:`status`,"aria-live":`polite`,className:`flex min-h-0 flex-1 items-center justify-center p-6 text-sm text-muted-foreground`,children:f(`loading_settings_69ede7ee`)})}function io({onClose:e}){return u(),(0,q.jsxs)(`div`,{role:`alert`,className:`flex min-h-0 flex-1 flex-col items-center justify-center p-6 text-center`,children:[(0,q.jsx)(`div`,{className:`text-base font-semibold`,children:f(`could_not_load_settings_05a4babd`)}),(0,q.jsx)(`p`,{className:`mt-2 max-w-sm text-sm leading-relaxed text-muted-foreground`,children:f(`settings_code_could_not_be_loaded_chat_is_still_availab_05bc021f`)}),(0,q.jsx)(W,{className:`mt-4`,onClick:e,children:f(`back_to_chat_5b8ac6b1`)})]})}var ao=()=>o(()=>import(`./Settings-6l99-5Ca.js`),__vite__mapDeps([27,1,2,8,4,3,28,6,29,9,10,11,12,7,30,14,15,16,31,32,33,34,35,36,37,38,39,40,25,5,26,41,42,43,21,18,44,45,46,47,48]),import.meta.url);function oo({open:e,onClose:t,loadSettings:n=ao}){u();let[r,i]=(0,K.useState)(`general`),a=(0,K.useId)(),o=(0,K.useRef)(null),[s]=(0,K.useState)(()=>(0,K.lazy)(async()=>({default:(await n()).SettingsContent})));return(0,K.useEffect)(()=>{e&&o.current?.focus({preventScroll:!0})},[e]),e?(0,q.jsxs)(`main`,{"data-slot":`settings-page`,"aria-labelledby":a,className:`motion-page-enter animate-in fade-in-0 slide-in-from-bottom-2 flex h-full min-h-0 w-full flex-1 flex-col bg-background`,style:{animationDuration:`var(--motion-normal)`,animationTimingFunction:`var(--motion-ease)`},onKeyDown:e=>{if(e.key!==`Escape`||e.defaultPrevented||e.nativeEvent.isComposing)return;let n=e.target;n instanceof Element&&n.closest(`[role="dialog"], [role="alertdialog"], [role="combobox"], [role="listbox"], [role="menu"], [data-slot="popover-content"], [data-slot="dropdown-menu-content"], select`)||(e.preventDefault(),t())},children:[(0,q.jsxs)(`header`,{className:`flex shrink-0 items-center gap-4 border-b p-4 sm:px-6`,style:{borderBottomColor:`color-mix(in oklab, var(--border) 70%, transparent)`},children:[(0,q.jsxs)(W,{variant:`ghost`,size:`sm`,onClick:t,children:[(0,q.jsx)(te,{"aria-hidden":`true`}),f(`back_to_chat_5b8ac6b1`)]}),(0,q.jsx)(`div`,{className:`h-5 w-px bg-border`,"aria-hidden":`true`}),(0,q.jsx)(`h1`,{ref:o,id:a,tabIndex:-1,className:`text-base font-semibold tracking-tight outline-none sm:text-lg`,children:f(`system_settings_68ea5dd4`)})]}),(0,q.jsx)(ue,{name:`Settings`,fallback:(0,q.jsx)(io,{onClose:t}),children:(0,q.jsx)(K.Suspense,{fallback:(0,q.jsx)(ro,{}),children:(0,q.jsx)(s,{tab:r,onTabChange:i})})})]}):null}function so({className:e,...t}){return(0,q.jsxs)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,viewBox:`0 0 32 32`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.6`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,focusable:`false`,className:G(`size-8 shrink-0 text-primary`,e),...t,children:[(0,q.jsx)(`path`,{d:`M10.5 21c-2.4 1.7-5.7.7-7-1.8-1.5-2.8-.3-5.9 2.3-7.2-.4-3 1.8-5.6 4.8-5.3a5.8 5.8 0 0 1 10.8 0c3-.3 5.2 2.3 4.8 5.3 2.6 1.3 3.8 4.4 2.3 7.2-1.3 2.5-4.6 3.5-7 1.8`}),(0,q.jsx)(`path`,{d:`M16 6.5c-2.6 2.7-2.6 5.2 0 7.5 2.6-2.3 2.6-4.8 0-7.5ZM7.5 12.5c.3 4.3 2.6 6.3 6.4 5.5-.6-3.7-2.8-5.5-6.4-5.5ZM24.5 12.5c-.3 4.3-2.6 6.3-6.4 5.5.6-3.7 2.8-5.5 6.4-5.5Z`}),(0,q.jsx)(`path`,{d:`M16 14v8c0 3.2-2.2 5.7-5.5 6.5M16 22c0 3.2 2.2 5.7 5.5 6.5M11 15.5l5 6 5-6M6 29.5c6.7-2 13.3-2 20 0`})]})}var co=`bodhi_onboarded_v1`;function lo(){u();let[e,t]=(0,K.useState)(()=>{try{return localStorage.getItem(co)===`1`}catch{return!0}});return e?null:(0,q.jsx)(cn,{open:!0,children:(0,q.jsxs)(on,{dismissable:!1,showCloseButton:!1,className:`p-6 text-center sm:max-w-sm`,children:[(0,q.jsx)(so,{className:`mx-auto mb-3 size-12`}),(0,q.jsx)(an,{className:`text-lg`,children:f(`welcome_to_bodhi_094c7fae`)}),(0,q.jsxs)(`p`,{className:`mt-2 text-sm leading-relaxed text-muted-foreground`,children:[f(`an_ai_assistant_for_mobile_use_the_top_left_menu_to_swi_cf369af5`),` `,(0,q.jsx)(`code`,{children:`/`}),f(`to_choose_skills_paste_or_select_images_and_use_the_top_acab9973`)]}),(0,q.jsx)(W,{className:`mt-5 w-full`,onClick:()=>{try{localStorage.setItem(co,`1`)}catch{}t(!0)},children:f(`get_started_715ee9dc`)})]})})}var uo=new class{cache=null;options;constructor(e={}){this.options={maxRecentWorkspaces:e.maxRecentWorkspaces??10,cacheTimeoutMs:e.cacheTimeoutMs??300*1e3,requestTimeoutMs:e.requestTimeoutMs??1e4}}async validatePath(e){return Ot.post(`workspace/validate`,{path:e})}async getRecent(){if(this.isCacheValid())return this.cache.recentWorkspaces;try{let e=await Ot.get(`workspace/recent`,{signal:AbortSignal.timeout(this.options.requestTimeoutMs)});return this.cache={recentWorkspaces:e,timestamp:Date.now()},e}catch(e){if(console.error(`Failed to get recent workspaces:`,e),this.cache?.recentWorkspaces)return this.cache.recentWorkspaces;throw e}}async addRecent(e,t){await Ot.post(`workspace/recent`,{path:e,metadata:t}),this.invalidateCache()}async removeRecent(e){let t=(await this.getRecent()).filter(t=>t.path!==e);this.cache={recentWorkspaces:t,timestamp:Date.now()}}async clearRecent(){this.cache=null}async getPathSuggestions(){return Ot.get(`workspace/suggestions`)}async browseFolder(e){return Ot.post(`workspace/browse-folder`,{path:e})}async getCombinedSuggestions(){let[e,t]=await Promise.all([this.getPathSuggestions().catch(()=>({suggestions:[]})),this.getRecent().catch(()=>[])]),n=[...e.suggestions.map(e=>({path:e.path,is_valid:!0,workspace_name:e.name})),...t];return this.deduplicateByPath(n).sort((e,n)=>{let r=t.findIndex(t=>t.path===e.path),i=t.findIndex(e=>e.path===n.path);return r!==-1&&i!==-1?r-i:r===-1?i===-1?(e.workspace_name||``).localeCompare(n.workspace_name||``):1:-1})}async healthCheck(){let e=Date.now();try{await Ot.get(`workspace/recent`,{signal:AbortSignal.timeout(2e3)});let t=this.cache?.recentWorkspaces||await this.getRecent();return{available:!0,cacheValid:this.isCacheValid(),recentCount:t.length,latency:Date.now()-e}}catch(e){return{available:!1,cacheValid:this.isCacheValid(),recentCount:this.cache?.recentWorkspaces?.length||0,error:e instanceof Error?e.message:`Unknown error`}}}validateWorkspacePath=this.validatePath.bind(this);getRecentWorkspaces=this.getRecent.bind(this);addRecentWorkspace=this.addRecent.bind(this);removeRecentWorkspace=this.removeRecent.bind(this);clearRecentWorkspaces=this.clearRecent.bind(this);getWorkspaceSuggestions=this.getCombinedSuggestions.bind(this);getHealthStatus=this.healthCheck.bind(this);async listWorkspaceFiles(e,t){return Ot.post(`workspace/files`,{path:e,max_depth:t?.max_depth??3,max_entries:t?.max_entries??500,include_hidden:t?.include_hidden??!1})}isCacheValid(){return this.cache?!(Date.now()-this.cache.timestamp>this.options.cacheTimeoutMs):!1}invalidateCache(){this.cache=null}deduplicateByPath(e){let t=new Set;return e.filter(e=>t.has(e.path)?!1:(t.add(e.path),!0))}};function fo({open:e,current:t,locked:n,onClose:r,onSelect:i}){u();let[a,o]=(0,K.useState)([]),[s,c]=(0,K.useState)(!0),[l,d]=(0,K.useState)(``),[p,m]=(0,K.useState)(!1),[h,g]=(0,K.useState)(null),[_,v]=(0,K.useState)([]);if((0,K.useEffect)(()=>{e&&(c(!0),uo.getCombinedSuggestions().then(o).catch(()=>{}).finally(()=>c(!1)))},[e]),(0,K.useEffect)(()=>{if(!e||!l.startsWith(`/`)){v([]);return}let t=l.lastIndexOf(`/`),n=t<=0?`/`:l.slice(0,t),r=l.slice(t+1).toLowerCase(),i=setTimeout(()=>{uo.browseFolder(n).then(e=>v(e.folders.filter(e=>e.name.toLowerCase().startsWith(r)).slice(0,500))).catch(()=>v([]))},180);return()=>clearTimeout(i)},[e,l]),!e)return null;let b=e=>{i(e),r()},x=async()=>{let e=l.trim();if(e.length>1&&(e=e.replace(/\/+$/,``)),e){m(!0),g(null);try{let t=await uo.validatePath(e);t.is_valid?(await uo.addRecent(e).catch(()=>{}),b(e)):g(t.error_message||f(`invalid_path_1f83ecf9`))}catch{g(f(`validation_failed_a096c117`))}finally{m(!1)}}};return(0,q.jsx)(cn,{open:!0,onOpenChange:e=>{e||r()},children:(0,q.jsxs)(on,{showCloseButton:!1,className:`p-0 sm:max-w-lg`,children:[(0,q.jsxs)(`div`,{className:`flex items-center justify-between border-b px-4 py-3`,children:[(0,q.jsx)(an,{children:f(`select_working_directory_18240aa3`)}),(0,q.jsx)(W,{size:`icon`,variant:`ghost`,onClick:r,children:(0,q.jsx)(He,{})})]}),(0,q.jsxs)(`div`,{className:`min-h-0 flex-1 space-y-3 overflow-y-auto p-4`,children:[n?(0,q.jsx)(`p`,{className:`rounded-md bg-muted/50 px-2.5 py-2 text-xs text-muted-foreground`,children:(0,q.jsx)(y,{i18nKey:`ui.workspace_locked_notice`,components:{strong:(0,q.jsx)(`strong`,{})}})}):null,(0,q.jsxs)(`div`,{className:`flex gap-2`,children:[(0,q.jsx)(fe,{className:`flex-1`,placeholder:f(`absolute_path_e_g_home_you_project_52ea40f9`),value:l,autoFocus:!0,onChange:e=>d(e.target.value),onKeyDown:e=>{e.key===`Enter`&&x()}}),(0,q.jsx)(W,{size:`sm`,onClick:x,disabled:!l.trim()||p,children:p?(0,q.jsx)(L,{className:`size-4 animate-spin`}):f(`use_cdfd0b34`)})]}),_.length>0?(0,q.jsx)(`ul`,{className:`-mt-1 max-h-80 overflow-y-auto rounded-md border bg-background`,children:_.map(e=>(0,q.jsx)(`li`,{children:(0,q.jsxs)(`button`,{onClick:()=>d(e.path+`/`),className:`flex w-full items-center gap-2 px-2.5 py-1.5 text-left text-sm hover:bg-accent`,children:[(0,q.jsx)(wr,{className:`size-3.5 shrink-0 text-muted-foreground`}),(0,q.jsx)(`span`,{className:`truncate`,children:e.name}),(0,q.jsx)(`span`,{className:`ml-auto truncate text-xs text-muted-foreground`,children:e.path})]})},e.path))}):null,h?(0,q.jsx)(`p`,{className:`text-xs text-destructive`,children:h}):null,t?(0,q.jsx)(`button`,{onClick:()=>b(null),className:`text-xs text-muted-foreground underline-offset-2 hover:text-foreground hover:underline`,children:f(`clear_use_default_directory_5619a464`)}):null,(0,q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,q.jsx)(`div`,{className:`text-xs font-medium text-muted-foreground`,children:f(`recent_suggested_035f05c6`)}),s?(0,q.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:f(`loading_4927a53b`)}):a.length===0?(0,q.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:f(`none_yet_b336a174`)}):(0,q.jsx)(`ul`,{className:`space-y-1`,children:a.map(e=>(0,q.jsx)(`li`,{children:(0,q.jsxs)(`button`,{onClick:()=>b(e.path),className:G(`flex w-full items-center gap-2 rounded-md px-2.5 py-2 text-left hover:bg-accent`,t===e.path&&`bg-accent`),children:[(0,q.jsx)(wr,{className:`size-4 shrink-0 text-muted-foreground`}),(0,q.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,q.jsx)(`div`,{className:`truncate text-sm`,children:e.workspace_name||e.path.split(`/`).pop()||e.path}),(0,q.jsx)(`div`,{className:`truncate text-xs text-muted-foreground`,children:e.path})]}),t===e.path?(0,q.jsx)(de,{className:`size-4 shrink-0 text-primary`}):null]})},e.path))})]})]})]})})}var po=class{samples=[];reset(){this.samples=[]}record(e,t=performance.now()){if(!e||!Number.isFinite(t))return;let n=this.samples.at(-1)?.at;n!==void 0&&(t<n||t-n>2e3)&&this.reset();let r=0;for(let t of e)r+=/[\u1100-\u11ff\u2e80-\u9fff\uac00-\ud7af\uf900-\ufaff\uff00-\uffef]/u.test(t)?.75:.25;let i=this.samples.at(-1);i&&t-i.at<50?i.tokens+=r:this.samples.push({at:t,tokens:r}),this.prune(t)}rate(e=performance.now()){this.prune(e);let t=this.samples[0],n=this.samples.at(-1);if(!t||!n||e<n.at||e-n.at>1500)return null;let r=n.at-t.at;return r<600?null:this.samples.slice(1).reduce((e,t)=>e+t.tokens,0)*1e3/r}prune(e){this.samples=this.samples.filter(t=>e-t.at<=5e3)}};function mo(e,t){let n=(0,K.useRef)(new po),[r,i]=(0,K.useState)(null),a=(0,K.useCallback)(e=>n.current.record(e),[]),o=(0,K.useCallback)(()=>{n.current.reset(),i(null)},[]);return(0,K.useEffect)(()=>{if(!t||!e)return;let r=window.setInterval(()=>{let t=n.current.rate();i(n=>n?.sessionId===e&&n.rate===t?n:{sessionId:e,rate:t})},500);return()=>window.clearInterval(r)},[t,e]),{record:a,reset:o,rate:t&&r&&r.sessionId===e?r.rate:null}}var ho=e=>typeof e==`object`&&e&&!Array.isArray(e)?e:null,go=e=>typeof e==`number`&&Number.isInteger(e)&&e>=0&&e<=4294967295;function _o(e){let t=ho(e);if(!t||t.session_version!==null&&!go(t.session_version)||!go(t.current_session_version)||typeof t.status!=`string`||![`compatible`,`legacy_compatible`,`conflict`].includes(t.status)||t.history_readable!==!0||typeof t.execution_allowed!=`boolean`||t.status===`conflict`===t.execution_allowed||!Array.isArray(t.conflicts))return null;let n=[];for(let e of t.conflicts){let t=ho(e);if(!t||typeof t.code!=`string`||!t.code||typeof t.message!=`string`)return null;n.push({code:t.code,message:t.message})}return{session_version:t.session_version,current_session_version:t.current_session_version,status:t.status,history_readable:!0,execution_allowed:t.execution_allowed,conflicts:n}}var vo={report:null,observed:!1,legacy:!1,loading:!1,readError:!1},yo=new Map,bo=new Map,xo=new Set,So=0,Co=e=>e?yo.get(e)??vo:vo,wo=e=>!!e&&yo.get(e)?.report?.status===`conflict`;function To(e){return xo.add(e),()=>{xo.delete(e)}}function Eo(e,t){yo.set(e,t);for(let e of xo)e()}function Do(e){let t=++So;return bo.set(e,t),Eo(e,{...Co(e),loading:!0,readError:!1}),t}function Oo(e,t,n){if(bo.get(e)!==t)return!1;let r=ho(ho(n)?.session);if(r?.id!==e)return ko(e,t),!1;let i=Co(e),a=_o(r.execution_compatibility),o=r.execution_compatibility!=null&&!a;return Eo(e,{report:a??(i.report?.status===`conflict`?i.report:null),observed:!0,legacy:!a&&r.session_version==null,loading:!1,readError:o}),!o}function ko(e,t){bo.get(e)===t&&Eo(e,{...Co(e),loading:!1,readError:!0})}function Ao(e,t){if(!e||!Ct(t)||t.status!==409)return!1;try{let n=ho(JSON.parse(t.body??`null`)),r=ho(n?.error);if(n?.session_id!==e||r?.code!==`session_execution_incompatible`)return!1;let i=_o(n.compatibility);return i?.status===`conflict`?(bo.set(e,++So),Eo(e,{report:i,observed:!0,legacy:!1,loading:!1,readError:!1}),!0):!1}catch{return!1}}function jo(e){let t=(0,K.useSyncExternalStore)(To,()=>Co(e),()=>Co(null)),n=(0,K.useCallback)(async()=>{if(!e)return;let t=Do(e);try{Oo(e,t,await zt.getSession(e))}catch{ko(e,t)}},[e]);return(0,K.useEffect)(()=>{if(n(),e)return At(()=>{n()})},[n,e]),{...t,blocked:t.report?.status===`conflict`,refresh:n}}var Mo=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i,No=(e,t)=>encodeURIComponent(JSON.stringify([e,t])),Po=(e,t)=>`lotus-next.continuous-retry.guard.v1.${No(e,t)}`,Fo=(e,t)=>`lotus-next.continuous-retry.tab.v1.${No(e,t)}`,Io=`{"version":1,"requiresExactStop":true}`;function Lo(e){try{let t=JSON.parse(e);if(typeof t!=`object`||!t)return null;let n=t;return n.version!==1||typeof n.operationId!=`string`||!Mo.test(n.operationId)?null:n.state===`pending`?n.origin===void 0?{version:1,operationId:n.operationId,state:`pending`}:n.origin===`ordinary`||n.origin===`continuous`?{version:1,operationId:n.operationId,state:`pending`,origin:n.origin}:null:n.state===`started_unidentified`&&n.origin===`ordinary`&&n.runId===void 0?{version:1,operationId:n.operationId,state:`started_unidentified`,origin:`ordinary`}:n.state===`confirmed`&&It(n.runId)?n.origin===void 0?{version:1,operationId:n.operationId,state:`confirmed`,runId:n.runId}:n.origin===`ordinary`||n.origin===`continuous`?{version:1,operationId:n.operationId,state:`confirmed`,runId:n.runId,origin:n.origin}:null:null}catch{return null}}var Ro=new Map,zo=64,Bo=5*6e4,Vo=null,Ho=(e,t)=>JSON.stringify([e,t]);function Uo(e){for(let[t,n]of Ro)(e<n.createdAt||e-n.createdAt>=Bo)&&Ro.delete(t)}function Wo(){Vo!==null&&clearTimeout(Vo),Vo=null;let e=Date.now();if(Uo(e),Ro.size===0)return;let t=1/0;for(let e of Ro.values())t=Math.min(t,e.createdAt+Bo);try{Vo=setTimeout(()=>{Vo=null,Wo()},Math.max(0,t-e)),Vo.unref?.()}catch{Ro.clear()}}function Go(e){for(let[t,n]of Ro)n.tabKey===e&&Ro.delete(t);Wo()}function Ko(e,t){if(e.tabKey.length>4096||e.pendingRaw.length>1024)return;let n=Date.now();if(!Number.isFinite(n))return;Uo(n);let r=Ho(e.tabKey,e.operationId),i=Ro.get(r);for(i?(i.pendingRaw!==e.pendingRaw||i.confirmedRaw!==t)&&(i.conflicting=!0):Ro.set(r,{tabKey:e.tabKey,pendingRaw:e.pendingRaw,confirmedRaw:t,createdAt:n,conflicting:!1});Ro.size>zo;)Ro.delete(Ro.keys().next().value);Wo()}function qo(e,t,n){Uo(Date.now());let r=Ho(e,t),i=Ro.get(r);return Ro.delete(r),Wo(),i&&!i.conflicting&&i.pendingRaw===n?i.confirmedRaw:null}function Jo(e,t,n){try{let r=sessionStorage.getItem(e.tabKey);if(r!==e.pendingRaw){let i=r===null?null:Lo(r);return t.origin===`ordinary`&&i?.state===`pending`&&i.operationId!==t.operationId&&Ko(e,n),!1}sessionStorage.setItem(e.tabKey,n);let i=sessionStorage.getItem(e.tabKey)===n;return i&&Go(e.tabKey),i}catch{return!1}}function Yo(e,t){try{let n=sessionStorage.getItem(Fo(e,t));if(n===null)return{kind:`clear`,raw:null};let r=Lo(n);return r?r.state===`pending`?{kind:`pending`,raw:n,operationId:r.operationId,origin:r.origin??`unknown`}:r.state===`started_unidentified`?{kind:`started_unidentified`,raw:n,operationId:r.operationId,origin:`ordinary`}:{kind:`confirmed`,raw:n,operationId:r.operationId,origin:r.origin??`unknown`,runId:r.runId}:{kind:`ambiguous`}}catch{return{kind:`unavailable`}}}function Xo(e,t){try{let n=localStorage.getItem(Po(e,t));return n===null?`clear`:n===Io?`guarded`:`ambiguous`}catch{return`unavailable`}}function Zo(e,t){let n=Yo(e,t);if(n.kind===`confirmed`)return{kind:`confirmed`,runId:n.runId};if(n.kind===`started_unidentified`)return{kind:`ambiguous`};if(n.kind===`pending`||n.kind===`ambiguous`||n.kind===`unavailable`)return{kind:n.kind};let r=Xo(e,t);return r===`clear`?{kind:`clear`}:r===`ambiguous`||r===`unavailable`?{kind:r}:{kind:`ambiguous`}}function Qo(e,t){if(Xo(e,t)!==`guarded`)return null;let n=Yo(e,t);return n.kind!==`pending`&&n.kind!==`confirmed`&&n.kind!==`started_unidentified`||n.origin!==`ordinary`||Xo(e,t)!==`guarded`?null:{operationId:n.operationId,started:n.kind!==`pending`,runId:n.kind===`confirmed`?n.runId:null}}function $o(e,t){let n=Yo(e,t),r=Xo(e,t);if(n.kind!==`clear`&&n.kind!==`confirmed`&&n.kind!==`started_unidentified`&&!(n.kind===`pending`&&n.origin===`ordinary`)||r!==`clear`&&r!==`guarded`)return null;let i=null;try{let a=crypto.randomUUID(),o=Fo(e,t),s=Po(e,t);if(!Mo.test(a)||n.raw!==null&&Lo(n.raw)?.operationId===a)return null;let c=JSON.stringify({version:1,operationId:a,state:`pending`,origin:`continuous`});return i={tabKey:o,pendingRaw:c,priorTabRaw:n.raw,operationId:a},sessionStorage.getItem(o)!==n.raw||(r===`clear`&&localStorage.setItem(s,Io),localStorage.getItem(s)!==Io)?null:(sessionStorage.setItem(o,c),sessionStorage.getItem(o)===c?i:(es(i),null))}catch{return i&&es(i),null}}function es(e){try{return sessionStorage.getItem(e.tabKey)===e.pendingRaw?(e.priorTabRaw===null?sessionStorage.removeItem(e.tabKey):sessionStorage.setItem(e.tabKey,e.priorTabRaw),sessionStorage.getItem(e.tabKey)===e.priorTabRaw):!1}catch{return!1}}function ts(e){if(!es(e))return!1;let t=e.priorTabRaw,n=t===null?null:Lo(t);if(!n||n.state!==`pending`||n.origin!==`ordinary`||t===null)return!0;let r=qo(e.tabKey,n.operationId,t);if(r===null)return!0;try{if(sessionStorage.getItem(e.tabKey)!==t)return!0;sessionStorage.setItem(e.tabKey,r),sessionStorage.getItem(e.tabKey)===r&&Go(e.tabKey)}catch{}return!0}function ns(e,t){if(!It(t))return!1;let n=Lo(e.pendingRaw);return!n||n.state!==`pending`||n.operationId!==e.operationId?!1:Jo(e,n,JSON.stringify({version:1,operationId:e.operationId,state:`confirmed`,runId:t,...n.origin?{origin:n.origin}:{}}))}function rs(e){let t=Lo(e.pendingRaw);return!t||t.state!==`pending`||t.origin!==`ordinary`||t.operationId!==e.operationId?!1:Jo(e,t,JSON.stringify({version:1,operationId:e.operationId,state:`started_unidentified`,origin:`ordinary`}))}function is(e){let t=`lotus-next.continuous-retry.probe.${Date.now()}.${Math.random().toString(36).slice(2)}`,n=`probe`,r=!1;try{return e.getItem(t)!==null||(r=!0,e.setItem(t,n),e.getItem(t)!==n)?!1:(e.removeItem(t),r=!1,e.getItem(t)===null)}catch{return!1}finally{if(r)try{e.getItem(t)===n&&e.removeItem(t)}catch{}}}function as(e,t,n){let r={kind:`unavailable`},i=Yo(e,t),a=Xo(e,t);if(i.kind===`ambiguous`||i.kind===`unavailable`||a===`ambiguous`||a===`unavailable`)return r;let o=null;try{if(a===`clear`&&i.kind===`clear`&&!n?.ensureGuard)return Xo(e,t)===`clear`&&sessionStorage.getItem(Fo(e,t))===null?{kind:`unguarded`}:r;if(!is(localStorage)||!is(sessionStorage)||Xo(e,t)!==a||sessionStorage.getItem(Fo(e,t))!==i.raw||a===`clear`&&(localStorage.setItem(Po(e,t),Io),Xo(e,t)!==`guarded`))return r;let s=crypto.randomUUID(),c=Fo(e,t);if(!Mo.test(s)||i.raw!==null&&Lo(i.raw)?.operationId===s)return r;let l=JSON.stringify({version:1,operationId:s,state:`pending`,origin:`ordinary`});return o={tabKey:c,pendingRaw:l,priorTabRaw:i.raw,operationId:s},sessionStorage.setItem(c,l),sessionStorage.getItem(c)===l?{kind:`reserved`,reservation:o}:(es(o),r)}catch{return o&&es(o),r}}var ss=(e,t)=>e===t||e.startsWith(`${t}:`);function cs(e){return e?.status===`running`?{status:`completed`,awaitingUsage:!0}:e??{status:`unconfirmed`}}function ls(e,t){return typeof t==`string`?t===`started`?{status:`running`}:t===`completed`?cs(e):ss(t,`cancelled`)||ss(t,`canceled`)?{status:`cancelled`}:ss(t,`failed_candidate_plan`)?{status:`failed`,reason:`candidate_plan`}:ss(t,`failed_postcondition`)?{status:`failed`,reason:`postcondition`}:ss(t,`failed`)||t.startsWith(`failed_`)?{status:`failed`,reason:`other`}:ss(t,`deferred_tool_protocol`)?{status:`deferred`,reason:`tool_protocol`}:ss(t,`deferred`)||t.startsWith(`deferred_`)?{status:`deferred`,reason:`other`}:ss(t,`skipped_no_background_model`)?{status:`skipped`,reason:`no_model`}:ss(t,`skipped`)||t.startsWith(`skipped_`)?{status:`skipped`,reason:`other`}:e:e}function us(e){return e?.status===`completed`&&e.awaitingUsage?{status:`completed`,awaitingUsage:!1}:e}function ds(e,t=!1){return e?.status===`running`?{status:t?`cancelled`:`unconfirmed`}:e}var fs=`lotus.sidebar.session-order.v1`,ps=4e3,ms={version:1,ranks:{},activity:{}},hs=ms,gs=e=>!!e&&typeof e==`object`&&!Array.isArray(e),_s=e=>typeof e==`string`&&!!e.trim()&&e.length<=256,vs=e=>typeof e==`number`&&Number.isFinite(e),ys=e=>{if(!gs(e))return{};let t=Object.entries(e).filter(e=>_s(e[0])&&vs(e[1]));return Object.fromEntries(t.slice(0,ps))};function bs(e){let t=Object.entries(e);return t.length<=ps?e:Object.fromEntries(t.sort((e,t)=>t[1]-e[1]).slice(0,ps))}function xs(e){try{let t=JSON.parse(e??`null`);return!gs(t)||t.version!==1?ms:{version:1,ranks:ys(t.ranks),activity:ys(t.activity)}}catch{return ms}}function Ss(){try{return typeof localStorage>`u`?ms:xs(localStorage.getItem(fs))}catch{return ms}}function Cs(e){try{if(typeof localStorage>`u`)return;localStorage.setItem(fs,JSON.stringify(e))}catch{}}var ws=Ss(),Ts=new Set;function Es(e){if(e===ws)return ws;let t={version:1,ranks:bs(e.ranks),activity:bs(e.activity)};ws=t,Cs(t);for(let e of Ts)e();return t}function Ds(e){return Ts.add(e),Ts.size===1&&typeof window<`u`&&window.addEventListener(`storage`,Os),()=>{Ts.delete(e),!Ts.size&&typeof window<`u`&&window.removeEventListener(`storage`,Os)}}function Os(e){if(e.key!==`lotus.sidebar.session-order.v1`&&e.key!==null)return;let t=Ss();if(t!==ws){ws=t;for(let e of Ts)e()}}var ks=()=>ws;function As(){return(0,K.useSyncExternalStore)(Ds,()=>ws,()=>ms)}var js=e=>{let t=0;for(let n of Object.values(e.ranks))n>t&&(t=n);return t+1};function Ms(e,t=Date.now()){if(!_s(e))return ws;let n=ws.activity[e]??0;return t<n?ws:Es({version:1,activity:{...ws.activity,[e]:Math.max(t,n)},ranks:{...ws.ranks,[e]:js(ws)}})}function Ns(e,t,n,r,i=!1){if(!_s(n)||n===r)return e;let a=t.filter(e=>e!==n),o=r===null?-1:a.indexOf(r);if(r!==null&&o<0)return e;let s=r===null?a.length:o+ +!!i,c=0;for(let t of Object.values(e.ranks))t>c&&(c=t);c+=a.length+1;let l={...e.ranks};a.forEach((e,t)=>{l[e]=c-1-t});let u=s>0?l[a[s-1]]:void 0,d=s<a.length?l[a[s]]:void 0;return l[n]=u!==void 0&&d!==void 0?(u+d)/2:u===void 0?d===void 0?c:d+.5:u-.5,{...e,ranks:l}}function Ps(e){return Es(e)}function Fs(e,t){return[...t].sort((t,n)=>{let r=e.ranks[t]??-1/0,i=e.ranks[n]??-1/0;return r===i?(e.activity[n]??0)-(e.activity[t]??0):r>i?-1:1})}function Is(e,t=ms){let n=vs(e.createdAt)?e.createdAt:0;return Math.max(n,t.activity[e.id]??0)}function Ls(e,t,n=ms){let r=n.ranks[e.id]??-1/0,i=n.ranks[t.id]??-1/0;return r===i?Is(t,n)-Is(e,n):r>i?-1:1}var Rs=[`development`,`debugging`,`analysis`,`documentation`,`operations`],zs={get development(){return f(`development_9ec42862`)},get debugging(){return f(`troubleshooting_0793d14f`)},get analysis(){return f(`analysis_2af437d3`)},get documentation(){return f(`documentation_2687ccdb`)},get operations(){return f(`operations_2805edf2`)}},Bs=[`For this session, operate in code review mode.`,`Review code changes with emphasis on correctness, regressions, security, maintainability, tests, and rollout risk.`,`Prefer concise findings with severity, rationale, and actionable fixes.`,`Ask for missing scope or repository context before making strong assumptions.`].join(` `),Vs=[`For this session, operate in bug investigation mode.`,`Help diagnose issues by analyzing code, logs, stack traces, and runtime behavior.`,`Trace root causes methodically, suggest targeted fixes, and flag related risks.`,`Ask for reproduction steps or error messages if not provided.`].join(` `),Hs=[`For this session, operate in feature implementation mode.`,`Help plan and implement new features step by step, following existing code conventions.`,`Consider edge cases, testing strategies, and backward compatibility.`,`Propose an implementation plan before writing code when scope is large.`].join(` `),Us=[`For this session, operate in architecture analysis mode.`,`Analyze the repository structure, key abstractions, data flow, and module boundaries.`,`Identify architectural patterns, coupling hotspots, and potential improvements.`,`Use diagrams to illustrate relationships when helpful.`].join(` `),Ws=[`For this session, operate in error explanation mode.`,`Help users understand error messages, stack traces, and unexpected behavior.`,`Explain the root cause clearly, suggest fixes, and provide prevention tips.`,`Keep explanations accessible even for less experienced developers.`].join(` `),Gs=[`For this session, operate in file comparison mode.`,`Compare the given files or code sections, highlighting key differences and their implications.`,`Focus on functional changes, potential regressions, and design trade-offs.`].join(` `),Ks=[`For this session, operate in refactoring advisor mode.`,`Suggest targeted refactoring improvements for readability, maintainability, and performance.`,`Respect existing code style, propose incremental changes, and explain the rationale.`,`Flag any risks introduced by the refactoring.`].join(` `),qs=[`For this session, operate in release notes generation mode.`,`Generate clear, well-structured release notes from git history and code changes.`,`Categorize changes (features, fixes, improvements, breaking changes).`,`Write for both technical and non-technical readers.`].join(` `),Js=[`For this session, operate in work summary mode.`,`Help summarize recent work activity for standups, weeklies, or status reports.`,`Pull key accomplishments, blockers, and next steps from session history or code changes.`,`Keep output concise and actionable.`].join(` `),Ys=[`For this session, operate in documentation writer mode.`,`Help create or improve technical documentation from code and project context.`,`Follow good documentation practices: clear structure, examples, and consistent terminology.`,`Produce Markdown-formatted output by default.`].join(` `),Xs=[`For this session, operate in scheduled task setup mode.`,`Help the user create a recurring scheduled task in Bamboo.`,`Clarify the task goal, frequency, workspace, and expected output before proceeding.`,`Guide the user through configuration and confirm before saving.`].join(` `),Zs=[`For this session, operate in session review mode.`,`Help inspect and analyze past session history for patterns, insights, or issues.`,`Summarize key decisions, outcomes, and areas that may need follow-up.`].join(` `),Qs=[`For this session, operate in context diagnostics mode.`,`Help analyze token usage, prompt bloat, context growth, truncation, and compression behavior.`,`Quantify likely causes when possible and recommend concrete, prioritized fixes.`,`Keep the output practical for engineers improving prompt and session efficiency.`].join(` `),$s=[{id:`blank`,icon:`plus`,get title(){return f(`blank_session_b3d1db15`)},get description(){return f(`start_from_scratch_with_the_default_assistant_and_an_em_6ccce42b`)},prefill:``,category:`development`},{id:`codeReview`,icon:`code`,get title(){return f(`code_review_fd5dc005`)},get description(){return f(`start_a_review_session_with_editable_review_instruction_88b1cc9f`)},prefill:`Review the relevant code changes in this workspace or repository. Start with the overall scope, then list risks, notable diffs, and the most important fixes.`,taskPrompt:Bs,category:`development`},{id:`implementFeature`,icon:`wrench`,get title(){return f(`implement_a_feature_1ddbacbb`)},get description(){return f(`plan_and_implement_a_feature_step_by_step_following_exi_13d8115d`)},prefill:`Help me implement a new feature in this workspace. Start by understanding the codebase structure, then propose an implementation plan before writing code.`,taskPrompt:Hs,category:`development`},{id:`refactor`,icon:`gitCompare`,get title(){return f(`refactoring_advice_2b476822`)},get description(){return f(`get_focused_advice_on_code_quality_and_maintainability_651b3684`)},prefill:`Suggest refactoring improvements for the code in this workspace. Focus on readability, maintainability, and performance. Propose incremental changes with clear rationale.`,taskPrompt:Ks,category:`development`},{id:`bugInvestigation`,icon:`bug`,get title(){return f(`investigate_a_bug_af57765b`)},get description(){return f(`find_the_root_cause_using_code_logs_and_runtime_behavio_7ce9e8b4`)},prefill:`Help me investigate a bug. I'll describe the symptoms and share relevant code or logs. Trace the root cause and suggest targeted fixes.`,taskPrompt:Vs,category:`debugging`},{id:`explainError`,icon:`helpCircle`,get title(){return f(`explain_an_error_28d73930`)},get description(){return f(`understand_an_error_message_or_stack_trace_dcea6ce4`)},prefill:`Help me understand the following error. Explain the root cause, suggest fixes, and share prevention tips.`,taskPrompt:Ws,category:`debugging`},{id:`tokenUsage`,icon:`barChart`,get title(){return f(`token_usage_diagnostics_2c9aeec8`)},get description(){return f(`diagnose_context_growth_truncation_risks_and_token_budg_fb7d69ae`)},prefill:`Help me investigate token usage, context growth, and truncation risk for this session or workflow. Summarize the likely drivers and recommend concrete next fixes.`,taskPrompt:Qs,category:`debugging`},{id:`architectureReview`,icon:`network`,get title(){return f(`explore_repository_architecture_362772ad`)},get description(){return f(`analyze_repository_structure_modules_and_architecture_p_c4144c28`)},prefill:`Analyze the architecture of this repository. Map the key modules, data flow, abstractions, and dependency patterns. Identify strengths and potential improvements.`,taskPrompt:Us,category:`analysis`},{id:`compareFiles`,icon:`fileSearch`,get title(){return f(`compare_files_ab62da9c`)},get description(){return f(`compare_files_or_code_snippets_to_understand_difference_4f4b61db`)},prefill:`Compare the following files or code sections. Highlight key differences, their implications, and any potential risks.`,taskPrompt:Gs,category:`analysis`},{id:`releaseNotes`,icon:`fileText`,get title(){return f(`generate_release_notes_3f4a4bc9`)},get description(){return f(`create_structured_release_notes_from_git_history_and_co_4ce6bd0b`)},prefill:`Generate release notes for the latest changes in this workspace. Categorize into features, fixes, improvements, and breaking changes.`,taskPrompt:qs,category:`documentation`},{id:`summarizeWork`,icon:`bookOpen`,get title(){return f(`summarize_work_0aefa71c`)},get description(){return f(`prepare_a_work_summary_for_a_stand_up_or_weekly_update_139cd09f`)},prefill:`Help me summarize my recent work for a status update. Pull key accomplishments, blockers, and next steps.`,taskPrompt:Js,category:`documentation`},{id:`writeDocs`,icon:`fileText`,get title(){return f(`write_documentation_af1b8189`)},get description(){return f(`create_or_improve_technical_documentation_using_project_9f5371fb`)},prefill:`Help me write technical documentation for this project. Analyze the code and produce clear, well-structured Markdown documentation.`,taskPrompt:Ys,category:`documentation`},{id:`createSchedule`,icon:`clock`,get title(){return f(`create_a_scheduled_task_edd706c3`)},get description(){return f(`set_up_a_recurring_task_to_run_automatically_on_a_sched_9ec9d769`)},prefill:`Help me set up a recurring scheduled task. I'll describe what I want it to do, and you guide me through the configuration.`,taskPrompt:Xs,category:`operations`},{id:`sessionReview`,icon:`search`,get title(){return f(`review_session_history_e0929a0e`)},get description(){return f(`inspect_past_sessions_for_patterns_and_follow_up_items_ea45ad91`)},prefill:`Help me review my recent session history. Summarize key decisions, outcomes, and areas that need follow-up.`,taskPrompt:Zs,category:`operations`}],ec=null,tc=0,nc=e=>{if(e===null){ec=null;return}tc+=1,ec=Object.freeze({prompt:e,revision:tc})},rc=()=>ec,ic=e=>ec?.revision!==e.revision||ec.prompt!==e.prompt?!1:(ec=null,!0),ac=e=>`lotus-next.root-mode-transition.v1.${e}`,oc=e=>`lotus-next.root-mode-operation.v2.${encodeURIComponent(e)}.`,sc=`lotus-next:root-mode-transition-changed`;function cc(e,t){return t===null||t===ac(e)||t.startsWith(oc(e))}function lc(e){if(typeof e!=`object`||!e)return!1;let t=e;return t.version===2&&typeof t.operationId==`string`&&/^[0-9]+:[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/.test(t.operationId)&&Number.isSafeInteger(t.expectedEpoch)&&(t.expectedEpoch??-1)>=0&&t.operationId.startsWith(`${t.expectedEpoch}:`)&&typeof t.birthToken==`string`&&t.birthToken.length>0&&typeof t.enabled==`boolean`}function uc(e){try{if(localStorage.getItem(ac(e))!==null)return{kind:`legacy`};let t=oc(e),n=[],r=Object.keys(localStorage).filter(e=>e.startsWith(t));for(let e of r){let r=localStorage.getItem(e);if(r===null)continue;let i;try{i=JSON.parse(r)}catch{return{kind:`invalid`}}if(!lc(i)||e!==`${t}${i.operationId}`)return{kind:`invalid`};n.push(i)}return n.length?{kind:`pending`,operations:n}:{kind:`clear`}}catch{return{kind:`storage-unavailable`}}}function dc(e){let t=uc(e);return t.kind===`clear`?`clear`:t.kind===`storage-unavailable`?`storage-unavailable`:`uncertain`}function fc(e){window.dispatchEvent(new CustomEvent(sc,{detail:e}))}function pc(e,t,n,r){if(uc(e).kind!==`clear`||!Number.isSafeInteger(t)||t<0||!n)return null;try{let i=`${t}:${crypto.randomUUID()}`,a={version:2,operationId:i,expectedEpoch:t,birthToken:n,enabled:r},o=`${oc(e)}${i}`,s=JSON.stringify(a);return localStorage.setItem(o,s),localStorage.getItem(o)===s?(fc(e),a):null}catch{return null}}function mc(e,t){try{let n=`${oc(e)}${t.operationId}`,r=localStorage.getItem(n);return r===null?!0:r!==JSON.stringify(t)||(localStorage.removeItem(n),localStorage.getItem(n)!==null)?!1:(fc(e),!0)}catch{return!1}}function hc(e){return(0,K.useSyncExternalStore)((0,K.useCallback)(t=>{if(!e)return()=>{};let n=n=>{n.detail===e&&t()},r=n=>{cc(e,n.key)&&t()};return window.addEventListener(sc,n),window.addEventListener(`storage`,r),()=>{window.removeEventListener(sc,n),window.removeEventListener(`storage`,r)}},[e]),(0,K.useCallback)(()=>e?dc(e):`clear`,[e]),()=>`clear`)}var gc=e=>JSON.stringify([e.interaction_kind,e.tool_call_id,e.interaction_kind===`permission`?e.permission_request.request_generation:null,e.interaction_kind===`permission`?e.permission_request.policy_revision:null]),_c=(e,t)=>e.sessionId===t.sessionId&&e.epoch===t.epoch,vc=e=>{if(!Ct(e)||e.status!==400&&e.status!==409||!e.body)return null;try{let t=JSON.parse(e.body).error?.code;return t===`session_project_running_conflict`?e.status===409?t:null:t===`root_orchestration_incompatible_mode`||t===`root_orchestration_requires_root`?t:null}catch{return null}},yc=(e,t)=>{if(!Ct(e)||e.status!==409||!e.body)return!1;try{let n=JSON.parse(e.body);if(!n||typeof n!=`object`||Array.isArray(n)||Object.hasOwn(n,`run_id`))return!1;let r=n;return r.session_id!==t||!r.error||typeof r.error!=`object`||Array.isArray(r.error)?!1:r.error.code===`retry_resume_not_prepared`}catch{return!1}},bc=e=>{if(e!=null)return typeof e==`string`?e.trim()||void 0:Dt(e).trim()||void 0},xc=new Map,Sc=async(e,t)=>{let n=H.getState();n.markCancel(e),n.updateSession(e,{isRunning:!1},{skipBackendPatch:!0});let r=zt.stopGeneration(e);return t?.(),await r,`legacy`},Cc=async(e,t,n)=>{if(!await Mt())throw Error(`Exact Stop capability unavailable`);let r=zt.stopGeneration(e,t);return n?.(),await r,`exact`},wc=e=>{let t=null;return n=>{if(t)return t;let r=e(n);return t=r,r.catch(()=>{t===r&&(t=null)}),r}},Tc=[],Ec=(e,t,n=new Set)=>{let r=new Map,i=new Set(n);for(let n of t)n.acknowledgedMessageId!==null&&e.some(e=>e.role===`user`&&e.id===n.acknowledgedMessageId)&&(r.set(n.operationId,n.acknowledgedMessageId),i.add(n.acknowledgedMessageId));for(let n of t){if(n.acknowledgedMessageId!==null)continue;let t=e.find(e=>e.role===`user`&&!i.has(e.id)&&!n.baselineMessageIds.has(e.id)&&`content`in e&&e.content.trim()===n.text);t&&(r.set(n.operationId,t.id),i.add(t.id))}return r},Dc=(e,t,n)=>{let r=(t?e.find(e=>e.id===t):void 0)?.content?.trim(),i=n?.trim();if(!i)return r||void 0;let a=(e.find(e=>e.isDefault)?.content??e[0]?.content)?.trim(),o=r||a;return o?`${o}\n\n## Task Mode\n${i}`:i},Oc=[];function kc(e,t){u();let n=e!==void 0,r=H(Yr(e=>e.chats)),i=H(e=>e.currentSessionId),a=H(e=>e.sessionIndexRevision),s=n?e:i,c=jo(s),l=H(mt(s)),d=H(Yr(e=>mt(s)(e)?.messages??[])),p=(0,K.useSyncExternalStore)(it,$e,$e);(0,K.useEffect)(()=>{for(let e of new Set(p.map(e=>e.sessionId))){let t=r.find(t=>t.id===e);t&&et(e,t.messages)}},[r,p,d]);let m=H(e=>e.selectedModel),h=nt(e=>e.providerSnapshot),g=h?.defaults?.chat?.model,_=h?.defaults?.chat,v=l?.config?.model_ref,y=v?.model||l?.config?.model||``,b=(0,K.useMemo)(()=>s?void 0:lt(h,m),[s,h,m]),x=s?y||g||``:b?.model||``,C=(0,K.useMemo)(()=>{if(!s)return b;if(v?.provider?.trim()&&v.model?.trim())return{provider:v.provider,model:v.model};if(!y&&_?.provider?.trim()&&g)return{provider:_.provider,model:g}},[g,_,s,b,y,v]),w=nt(e=>e.providerSnapshot?.defaults?.chat?.reasoning_effort),E=s&&v?.provider||C?.provider,D=nt(e=>bt(e.providerSnapshot,E)),O=nt(e=>E?e.getProviderType(E):void 0),A=H(e=>e.inputStates[s??``]?.reasoningEffort),j=s?l?.config?.reasoningEffort??v?.reasoning_effort??D:A===`auto`?void 0:A??w,[M,N]=(0,K.useState)(!1),[P,F]=(0,K.useState)(null),[I,ee]=(0,K.useState)(null),[L,te]=(0,K.useState)(null),[R,ne]=(0,K.useState)(()=>({entries:new Map,claimed:new Map})),[re,ie]=(0,K.useState)(!1),{rate:ae,record:oe,reset:se}=mo(s,(re||l?.isRunning===!0)&&L===s),[ce,le]=(0,K.useState)(!1),[ue,de]=(0,K.useState)(()=>new Map),[fe,pe]=(0,K.useState)(null),[me,he]=(0,K.useState)(null),ge=(0,K.useRef)(null),_e=jo(fe?.childSessionId??null),ve=(0,K.useRef)(null),ye=(0,K.useRef)(!1),be=(0,K.useRef)(0),xe=(0,K.useRef)(null),Se=(0,K.useRef)(new Map),[Ce,we]=(0,K.useState)(null),Te=(0,K.useRef)(new Map),Ee=(0,K.useRef)(new Map),z=(0,K.useRef)(null),De=(0,K.useRef)(null),B=(0,K.useRef)(new Set),Oe=(0,K.useRef)(null),ke=(0,K.useRef)(null),V=(0,K.useRef)({sessionId:s,epoch:0});V.current.sessionId!==s&&(V.current={sessionId:s,epoch:V.current.epoch+1});let[Ae,je]=(0,K.useState)(()=>({scope:V.current,question:null,loading:!1,submitting:!1,unavailable:!1,error:null,retry:null,recordedKey:null})),Me=(0,K.useRef)(Ae),Ne=(0,K.useRef)(0),Pe=(0,K.useRef)(null),Fe=_c(Ae.scope,V.current)?Ae:null,Ie=Fe?.question??null,Le=(0,K.useCallback)(e=>{let t=e(Me.current);Me.current=t,je(t)},[]),Re=(0,K.useCallback)(e=>ye.current&&_c(e,V.current),[]),ze=(0,K.useCallback)(async(e=V.current,t=!1)=>{if(!e.sessionId||!Re(e))return`stale`;let n=++Ne.current;Le(e=>({...e,loading:!0}));try{let r=await zt.getPendingQuestion(e.sessionId);if(!Re(e)||Ne.current!==n)return`stale`;let i=r.has_pending_question?r:null;return Le(n=>{let r=n.question?gc(n.question):n.recordedKey,a=!!i&&(gc(i)!==r||n.retry&&i.interaction_kind===`permission`&&!i.permission_request.allowed_decisions.includes(n.retry.decision));a&&(Pe.current=null);let o=a?null:n.retry,s=a?null:n.recordedKey,c=Pe.current,l=c?.awaitingResponse&&_c(c.scope,e)&&n.question&&gc(n.question)===c.key;return{scope:e,question:i??(o||l?n.question:null),loading:!1,submitting:a?!1:n.submitting,unavailable:!1,retry:o,recordedKey:s,error:t||o||s?n.error:null}}),i?`pending`:`absent`}catch{return!Re(e)||Ne.current!==n?`stale`:(Le(e=>({...e,loading:!1,unavailable:!0,error:e.recordedKey?f(`your_decision_was_recorded_but_subsequent_state_cannot__624ad0a2`):e.retry?f(`the_previous_submission_is_unconfirmed_and_the_current__c5a7efbd`):f(`the_confirmation_request_cannot_be_read_right_now_refre_05a4bdbe`)})),`unavailable`)}},[Re,Le]),Be=(0,K.useRef)(null),Ve=(0,K.useRef)(``),He=(0,K.useRef)(null),[Ue,We]=(0,K.useState)(null),Ke=(0,K.useRef)(``),Je=(0,K.useRef)(null),Ze=(0,K.useRef)({}),[tt,at]=(0,K.useState)([]),ot=(0,K.useRef)([]),st=(0,K.useRef)(null),ct=(0,K.useRef)(new Map),[ut,dt]=(0,K.useState)(null),ft=(0,K.useRef)(null),[pt,yt]=(0,K.useState)(null),St=(0,K.useRef)(null),U=(0,K.useRef)(null),Tt=(0,K.useRef)(null),Et=(0,K.useCallback)(()=>{let e=U.current;if(!e)return;let{lease:t,...n}=e,r=H.getState().chats.find(e=>e.id===n.sessionId);r&&et(n.sessionId,r.messages),xt(t),U.current=null,Tt.current===t&&(Tt.current=null)},[]),Dt=U.current,kt=(0,K.useMemo)(()=>p.filter(e=>e.sessionId===s),[p,s]),At=(0,K.useMemo)(()=>rt(d,kt),[d,kt]),jt=L===s&&Dt?.lease.valid?Dt.handoffId:void 0,Pt=!!jt&&kt.some(e=>e.handoffId===jt),Ft=!!jt&&At.remaining.some(e=>e.handoffId===jt),Lt=(0,K.useMemo)(()=>jt&&Ft?At.messages.filter(e=>e.id!==`completed-answer-handoff-${jt}`):At.messages,[jt,Ft,At]),Rt=Dt?.sessionId===s&&(Dt.lease.confirmed||Pt&&!Ft),Bt=Tt.current?.runId,Vt=!Dt&&L===s&&Bt&&p.some(e=>e.sessionId===s&&e.runId===Bt&&e.text.startsWith(P??``)),Ht=Tt.current?.valid!==!1,W=L===s&&!Rt&&!Vt&&Ht?P:null,G=L===s&&Ht?Ue:null,Ut=(0,K.useMemo)(()=>{if(L!==s||!Ht)return Oc;if(I!==null)return tt;let e=Oe.current,t=e===null?-1:Lt.findIndex(t=>t.role===`user`&&t.id===e),n=t<0?-1:Lt.findIndex((e,n)=>n>t&&e.role===`user`),r=t<0?[]:Lt.slice(t+1,n<0?void 0:n),i=new Set(r.flatMap(e=>`type`in e&&e.type===`tool_result`&&!B.current.has(e.id)?[e.toolCallId]:[])),a=!1,o=tt.flatMap(e=>{if(e.kind!==`tools`)return[e];let t=e.calls.filter(e=>!i.has(e.toolCallId));return a||=t.length!==e.calls.length,t.length?[{...e,calls:t}]:[]});return a?o:tt},[Ht,tt,Lt,s,I,L]),Wt=L===s&&Ht?ut:null,Gt=pt?.sessionId===s?pt.value:null,Kt=L===s&&Ht?I:null,qt=(0,K.useMemo)(()=>[...R.entries.values()].filter(e=>e.sid===s),[R.entries,s]),Jt=(0,K.useMemo)(()=>Ec(Lt,qt,R.claimed.get(s??``)),[Lt,R.claimed,qt,s]),Yt=(0,K.useMemo)(()=>qt.filter(e=>!Jt.has(e.operationId)).map(({operationId:e,text:t,images:n})=>({operationId:e,text:t,images:n})),[Jt,qt]),Xt=Yt.at(-1)??null,Zt=Xt?.text??null,Qt=Xt?.images??Tc,$t=ue.get(s??null)??null,en=(0,K.useCallback)((e,t)=>{let n=Ee.current.get(e);(n===void 0||t>n)&&Ee.current.set(e,t)},[]),tn=(0,K.useCallback)(e=>{let t=Ee.current.get(e.sessionId);if(t!==void 0&&t>e.operationId)return!1;let n=Te.current.get(e.sessionId);if(n&&n.operationId>e.operationId)return!1;let r=new Map(Te.current);return r.set(e.sessionId,e),Te.current=r,ye.current&&de(r),!0},[]),nn=(0,K.useCallback)((e,t)=>{let n=Te.current.get(e);if(!n||t!==void 0&&n.operationId!==t)return!1;let r=new Map(Te.current);return r.delete(e),Te.current=r,ye.current&&de(r),!0},[]),rn=(0,K.useCallback)(e=>Te.current.get(e)??null,[]),an=(0,K.useCallback)(e=>{if(!ye.current)return;let t=xe.current?.phase===`submitting`?xe.current.originSessionId:null;ne(n=>{let r=n.entries.get(e);if(!r)return n;let i=mt(r.sid)(H.getState())?.messages??[],a=[...n.entries.values()].filter(e=>e.sid===r.sid),o=Ec(i,a,n.claimed.get(r.sid)).get(e);if(!o)return n;let s=new Map(n.entries),c=new Map(n.claimed);return s.delete(e),a.length>1||t===r.sid?c.set(r.sid,new Set([...c.get(r.sid)??[],o])):c.delete(r.sid),{entries:s,claimed:c}})},[]);(0,K.useEffect)(()=>{for(let e of Jt.keys())an(e)},[an,Jt]);let on=(0,K.useCallback)(e=>{ft.current!==e&&(ft.current=e,dt(e))},[]),sn=(0,K.useCallback)(e=>{St.current=e,yt(e)},[]),cn=(0,K.useCallback)(()=>{st.current??=requestAnimationFrame(()=>{st.current=null,at(ot.current.map(e=>e.kind===`tools`?{...e,calls:e.calls.map(e=>({...e}))}:e))})},[]),ln=(0,K.useCallback)(()=>{let e=Ve.current,t=Ke.current;!e.trim()&&!t.trim()||(ot.current.push({kind:`text`,text:e,reasoning:t.trim()?t:null}),Ve.current=``,Ke.current=``,He.current!=null&&(cancelAnimationFrame(He.current),He.current=null),Je.current!=null&&(cancelAnimationFrame(Je.current),Je.current=null),F(``),We(null))},[]),un=(0,K.useCallback)(e=>{on(null),oe(e),Ve.current+=e,He.current??=requestAnimationFrame(()=>{He.current=null,F(Ve.current)})},[on,oe]),dn=(0,K.useCallback)(e=>{oe(e),Ke.current+=e,Je.current??=requestAnimationFrame(()=>{Je.current=null,We(Ke.current)})},[oe]),fn=(0,K.useCallback)((e,t,n=!1)=>{if(t!==void 0&&z.current!==t)return;let r=n?ot.current.flatMap(e=>{if(e.kind!==`tools`)return[];let t=e.calls.filter(e=>e.status!==`running`).map(e=>({...e}));return t.length?[{...e,calls:t}]:[]}):Oc,i=St.current;if(i&&i.operationId===z.current){let e=ds(i.value);e!==i.value&&sn({...i,value:e})}He.current!=null&&(cancelAnimationFrame(He.current),He.current=null),Je.current!=null&&(cancelAnimationFrame(Je.current),Je.current=null),st.current!=null&&(cancelAnimationFrame(st.current),st.current=null),Ve.current=``,Ke.current=``,ot.current=r,ct.current.clear(),we(e=>e?.status===`enabled`||e?.status===`requesting`||e?.status===`already_running`?null:e),z.current=null,at(r),on(null),F(e),We(null),e===null?(Tt.current&&xt(Tt.current),Tt.current=null,U.current=null,ee(null),r.length||te(null)):ee(`finalizing`)},[on,sn]);(0,K.useEffect)(()=>{let e=Tt.current;if(e&&!e.valid&&e.sessionId===s){ve.current?.abort(),fn(null);return}let t=U.current;!t||t.sessionId!==s||z.current===null&&(t.lease.valid&&!t.lease.confirmed||fn(null))},[d,p,s,fn]),(0,K.useEffect)(()=>{L!==s||I!==null||z.current!==null||Ut===tt||(ot.current=Ut,at(Ut),Ut.length||te(null))},[Ut,tt,s,I,L]);let pn=`lotus_next_last_session`;(0,K.useEffect)(()=>{if(n){N(!0);return}let e=null;try{e=localStorage.getItem(pn)}catch{}(async()=>{try{await gt()}catch{}try{if(e){let t=H.getState();(t.chats.some(t=>t.id===e)||await t.restoreSession(e))&&(H.getState().selectSession(e),H.getState().loadChatHistory(e))}}catch{}})().finally(()=>{N(!0)})},[n]),(0,K.useEffect)(()=>{if(!(!M||n||!i))try{localStorage.setItem(pn,i)}catch{}},[M,i,n]);let hn=n||M;(0,K.useEffect)(()=>{!s||!hn||H.getState().loadSubagentSessions(s,{force:!0}).catch(()=>{})},[hn,a,s]);let gn=(0,K.useCallback)(e=>{V.current.sessionId!==e&&(ve.current?.abort(),Et(),fn(null)),H.getState().selectSession(e),H.getState().loadChatHistory(e)},[Et,fn]),_n=(0,K.useCallback)((e,t,n)=>{let r=wt(),i=xc.get(e),a;return a={sessionId:e,operationId:t,stop:wc(async t=>{let o=await Nt(),s=Qo(r,e);if(!s||s.operationId!==n||!s.started)throw Error(`Execution identity unavailable`);if(o===`unsupported`){if(xc.get(e)!==i&&xc.get(e)!==a)throw Error(`Legacy Stop no longer owns this session`);return Sc(e,t)}if(o!==`supported`||!It(s.runId))throw Error(`Exact Stop identity unavailable`);return Cc(e,s.runId,t)})},a},[]),vn=(0,K.useCallback)((e,t,n)=>{let r=wt(),i=as(r,e,{ensureGuard:!0});i.kind===`unavailable`&&ye.current&&V.current.sessionId===e&&we({sessionId:e,operationId:t,status:`identity_unsaved`});let a=n(),o={sessionId:e,operationId:t,stop:wc(async t=>{let n=await a;if(n?.session_id!==e||n.status!==`started`)throw Error(`Execution did not start`);let s=await Nt();if(s===`unsupported`){let a=Qo(r,e),s=i.kind===`reserved`?a?.operationId===i.reservation.operationId&&a.started:Zo(r,e).kind===`clear`;if(n.run_id!=null&&!It(n.run_id)||!s||xc.get(e)!==o)throw Error(`Legacy Stop no longer owns this session`);return Sc(e,t)}if(s!==`supported`||!It(n.run_id))throw Error(`Exact Stop identity unavailable`);return Cc(e,n.run_id,t)})};return xc.set(e,o),Se.current.set(e,o),i.kind===`reserved`&&a.then(n=>{if(n?.session_id===e){if(n.status===`started`)(!(n.run_id==null?rs(i.reservation):ns(i.reservation,n.run_id))||!It(n.run_id))&&xc.get(e)===o&&Se.current.get(e)===o&&ye.current&&V.current.sessionId===e&&we({sessionId:e,operationId:t,status:`identity_unsaved`});else if((n.status===`already_running`||n.status===`completed`||n.status===`error`||n.status===`cancelled`)&&ts(i.reservation)&&xc.get(e)===o&&Se.current.get(e)===o){let n=Qo(r,e);if(n?.started){let r=_n(e,t,n.operationId);xc.set(e,r),Se.current.set(e,r)}}}},()=>{}),a},[_n]),yn=(0,K.useCallback)((e,t)=>{let n=wt(),r=xc.get(e);return{sessionId:e,operationId:t,stop:wc(async t=>{if(await Nt()!==`unsupported`||xc.get(e)!==r||Zo(n,e).kind!==`clear`)throw Error(`Execution identity unavailable`);return Sc(e,t)})}},[]),bn=(0,K.useCallback)(async(e,t)=>{if(!t?.resume&&wo(e))throw Error(f(`session_compatibility_execution_blocked`));let n=t?.operationId??be.current+1,r=wt(),i=!t?.resume&&t?.upstreamRetry?$o(r,e):null;if(!t?.resume&&t?.upstreamRetry&&!i)throw we({sessionId:e,operationId:n,status:`identity_unavailable`}),Error(f(`upstream_retry_identity_unavailable`));if(be.current=Math.max(be.current,n),t?.resume&&!Se.current.has(e)){let t=xc.get(e),i=Qo(r,e),a=Zo(r,e),o=i?.started?_n(e,n,i.operationId):a.kind===`confirmed`?{sessionId:e,operationId:n,stop:wc(t=>Cc(e,a.runId,t))}:null,s=t??o;s?Se.current.set(e,s):a.kind===`clear`&&Se.current.set(e,yn(e,n))}Et(),Tt.current&&xt(Tt.current);let a=Qe(e);Tt.current=a,en(e,n),we(null),z.current=n;let s=H.getState().chats.find(t=>t.id===e)?.messages??[];De.current=s.findLast(e=>e.role!==`system`)?.id??null,B.current=new Set(s.flatMap(e=>`type`in e&&e.type===`tool_result`?[e.id]:[])),Oe.current=t?.acknowledgedMessageId??null;let c=()=>z.current===n&&a.valid,l={settlement:null,pendingRead:null};ve.current?.abort(),sn(null),U.current=null,te(e),ee(`streaming`),se(),Ve.current=``,Ke.current=``,Ze.current={},ot.current=[],ct.current.clear(),at(Oc),on(null),F(``),We(null);let u=new AbortController;ve.current=u;let d={operationId:n,sessionId:e};ke.current=d,Be.current=e;let p=()=>c()&&!u.signal.aborted&&ye.current&&!l.settlement,m=(t,r)=>{if(!p())return;let i=St.current,a=i?.sessionId===e&&i.operationId===n?i:null;if(r!==void 0&&a?.value.status===`running`&&a.phase!==r)return;let o=a?.value??null,s=t(o);return s!==o&&sn(s?{sessionId:e,operationId:n,phase:r??a?.phase??``,value:s}:null),{previous:o,next:s}},h=!1,g=null,_,v=()=>clearTimeout(_);if(u.signal.addEventListener(`abort`,v,{once:!0}),!t?.resume){let r=Object.prototype.hasOwnProperty.call(t??{},`reasoningEffort`)?t?.reasoningEffort??void 0:j;if(dc(e)!==`clear`)throw i&&es(i),Error(f(`the_root_permission_change_is_unconfirmed_your_message__64f12563`));let o=t?.modelSelection?.model??x,s=t?.modelSelection?t.modelSelection.modelRef:C,l=null,d,m,_=t?.upstreamRetry?zt.execute(e,o||void 0,r,void 0,s,t.upstreamRetry):vn(e,n,()=>t?.liveBootstrapResume?zt.execute(e,o||void 0,r,void 0,s,void 0,!0):zt.execute(e,o||void 0,r,void 0,s));t?.upstreamRetry&&(we({sessionId:e,operationId:n,status:`requesting`}),l={sessionId:e,operationId:n,stop:wc(t=>_.then(async n=>{if(n?.session_id!==e||n.status!==`started`||!It(n.run_id))throw Error(`Execution did not start with a valid identity`);return Cc(e,n.run_id,t)}))},d=xc.get(e),m=Se.current.get(e),xc.set(e,l),Se.current.set(e,l)),_.then(r=>{h=!0,p()&&r?.session_id===e&&r.run_id?.trim()&&(g=r.run_id,a.runId=r.run_id);let o=!!i&&r?.session_id===e&&r.status===`started`&&ns(i,r.run_id);i&&r?.session_id===e&&(r.status===`already_running`||r.status===`completed`||r.status===`error`||r.status===`cancelled`)&&ts(i),l&&xc.get(e)===l&&p()&&we(t=>t?.operationId!==n||t.sessionId!==e||t.status!==`requesting`?t:r?.session_id===e&&r.status===`already_running`?{...t,status:`already_running`}:r?.session_id===e&&(r.status===`completed`||r.status===`error`||r.status===`cancelled`)?{...t,status:`not_started`}:o?{...t,status:`enabled`}:{...t,status:`identity_unsaved`}),l&&p()&&r?.session_id===e&&(r.status===`completed`||r.status===`error`||r.status===`cancelled`)&&(tn({kind:`generation-failed`,operationId:n,sessionId:e,pendingOperationId:t?.pendingOperationId,message:f(`upstream_retry_not_started`)}),fn(null,n),u.abort())}).catch(r=>{let a=!!i&&yc(r,e);if(a&&i&&l){let t=ts(i),r=xc.get(e)===l,a=Se.current.get(e)===l;t&&r&&a&&ye.current&&V.current.sessionId===e&&we(t=>t?.sessionId===e&&t.operationId===n?{...t,status:`not_started`}:t),t&&r&&(i.priorTabRaw!==null&&d?xc.set(e,d):xc.delete(e)),t&&a&&(i.priorTabRaw!==null&&m?Se.current.set(e,m):Se.current.delete(e))}c()&&(Ao(e,r),tn({kind:`generation-failed`,operationId:n,sessionId:e,pendingOperationId:t?.pendingOperationId,message:a?f(`upstream_retry_not_started`):bc(r)}),fn(null,n),u.abort())})}let y=(r=!1)=>{!c()||l.settlement||(m(ds),ee(`finalizing`),l.settlement=(async()=>{He.current!=null&&(cancelAnimationFrame(He.current),He.current=null);let i=Ve.current;i&&F(i);let o=H.getState().chats.find(t=>t.id===e)?.messages??[];if(i.trim()&&a.valid){let r=s.find(e=>e.id===De.current),c={sessionId:e,operationId:n,handoffId:Xe(),runId:g,text:i,baselineMessageId:De.current,baselineMessageText:r?.role===`assistant`&&r.type===`text`?r.content:null,excludedCanonicalIds:new Set(a.excludedCanonicalIds),acknowledgedMessageId:t?.acknowledgedMessageId??null,baselineMessageIds:new Set(s.map(e=>e.id)),anchorSeen:t?.acknowledgedMessageId!=null&&o.some(e=>e.role===`user`&&e.id===t.acknowledgedMessageId)},l={...c,lease:a};U.current=l;let u=Ge(a,c);u&&(l.handoffId=u)}if(!r)try{await H.getState().loadChatHistory(e,{mode:`monotonic`,waitForAssistant:!0,retries:8,retryDelayMs:150})}catch(e){console.warn(`[useChat] terminal history hydration failed`,e)}if(!c())return;if(!a.valid){fn(null,n);return}t?.pendingOperationId!==void 0&&an(t.pendingOperationId);let l=H.getState().chats.find(t=>t.id===e)?.messages??[];if(et(e,l),!i.trim()||a.confirmed){fn(null,n);return}let u=U.current;u&&(u.anchorSeen||=t?.acknowledgedMessageId!=null&&l.some(e=>e.role===`user`&&e.id===t.acknowledgedMessageId),a.handoff=u),fn(i,n)})())},b=(r=!1,i,a)=>{!c()||l.settlement||(m(ds),tn({...a?{diagnostic:a}:{},kind:`generation-failed`,operationId:n,sessionId:e,pendingOperationId:t?.pendingOperationId,message:bc(i)}),l.settlement=(async()=>{let i=r;if(!r)try{await H.getState().loadChatHistory(e,{throwOnError:!0}),i=!0}catch(e){console.warn(`[useChat] failed-generation history hydration failed`,e)}c()&&(i&&t?.pendingOperationId!==void 0&&an(t.pendingOperationId),fn(null,n,!i),u.abort())})())},S=(r=!1)=>{!c()||l.settlement||(m(e=>ds(e,!0)),l.settlement=(async()=>{let i=r;if(!r)try{await H.getState().loadChatHistory(e),i=!0}catch(e){console.warn(`[useChat] cancelled-generation history hydration failed`,e)}c()&&(i&&t?.pendingOperationId!==void 0&&an(t.pendingOperationId),fn(null,n))})())},w=!1,T=!0,E=()=>c()&&T&&!u.signal.aborted&&!l.settlement,D=async()=>{if(!E())return;let t=5e3;try{if(!h)return;let{session:n}=await zt.getSession(e);if(!E())return;if(n.id!==e||n.is_running||n.has_pending_question||n.last_run_status===`suspended`&&n.has_pending_question!==!1){w=!1;return}if(!w){w=!0,t=2e3;return}if(await H.getState().refreshChatsNow(),!E())return;if(H.getState().chats.find(t=>t.id===e)?.isRunning){w=!1;return}if(n.last_run_status===`suspended`){let t=V.current;if(t.sessionId!==e||await ze(t)!==`absent`||!E())return}let r=!1;try{await H.getState().loadChatHistory(e,{mode:`monotonic`,throwOnError:!0}),r=!0}catch(e){console.warn(`[useChat] owned-stream history reconciliation failed`,e)}if(!E())return;let i=Me.current;if(H.getState().chats.find(t=>t.id===e)?.isRunning||i.scope.sessionId===e&&i.question){w=!1;return}if(!r&&n.last_run_status!==`error`)return;let a=H.getState().chats.find(t=>t.id===e)?.messages?.findLast(e=>e.role!==`system`),s=Ve.current.trim(),c=s&&a?.role===`assistant`&&a.type===`text`&&a.id!==De.current&&a.content.trim()===s;if(n.last_run_status===`cancelled`)S(!0);else if(n.last_run_status===`suspended`||n.last_run_status===`completed`&&c)y(!0);else{let t=n.last_run_diagnostic==null?null:await o(()=>import(`./runDiagnostic-DJ_i4o1q.js`),__vite__mapDeps([49,50]),import.meta.url).catch(()=>null),i=bc(n.last_run_error),a=t&&i?t.decodeRunDiagnostic(n.last_run_diagnostic,e,i):null;b(r,n.last_run_error,a)}u.abort()}catch(e){w=!1,console.warn(`[useChat] owned-stream status reconciliation failed`,e)}finally{E()&&(_=setTimeout(()=>{D()},t))}};if(t?.resume||(_=setTimeout(()=>{D()},5e3)),await zt.subscribeToEvents(e,{onToken:e=>{p()&&un(e)},onReasoningToken:e=>{p()&&dn(e)},onToolStart:(e,t,n)=>{if(!p()||!e||ct.current.has(e))return;ln();let r={toolCallId:e,toolName:t,args:n,output:``,status:`running`};ct.current.set(e,r);let i=ot.current[ot.current.length-1];i&&i.kind===`tools`?i.calls.push(r):ot.current.push({kind:`tools`,calls:[r]}),on(f(`running_29ee24a4`,{v0:t})),cn()},onToolToken:(e,t)=>{if(!p())return;let n=ct.current.get(e);!n||n.status!==`running`||(n.output+=t,cn())},onToolComplete:(e,t)=>{if(!p()||!t)return;let n=ct.current.get(e);!n||n.status!==`running`||(n.status=t.success===!1?`error`:`completed`,typeof t.result==`string`&&(n.output=t.result),n.images=t.images,on(null),cn())},onToolError:(e,t)=>{if(!p())return;let n=ct.current.get(e);!n||n.status!==`running`||(n.status=`error`,n.error=t,on(null),cn())},onTaskListUpdated:e=>{e.session_id&&H.getState().setTaskList(e.session_id,e)},onTaskListItemProgress:e=>{if(!e.session_id)return;let t=H.getState();t.taskLists[e.session_id]?t.updateTaskListDelta(e.session_id,e):t.loadTaskList(e.session_id)},onTaskEvaluationStarted:e=>{H.getState().setEvaluationState(e,{isEvaluating:!0,reasoning:null,timestamp:Date.now()})},onTaskEvaluationCompleted:(e,t,n)=>{H.getState().setEvaluationState(e,{isEvaluating:!1,reasoning:t>0?n:null,timestamp:Date.now()})},onTokenBudgetUpdated:t=>{if(!p())return;let n=vt(t);if(!n)return;let r=H.getState();r.updateTokenUsage(e,n),r.setTruncationInfo(e,t.truncation_occurred,t.segments_removed),m(us)},onContextCompressionStatus:(e,t)=>{let n=m(e=>ls(e,t),e);n?.next?.status===`running`?on(f(`compressing_context_57b37811`)):n?.previous?.status===`running`&&on(null)},onContextSummarized:()=>{m(cs)?.previous?.status===`running`&&on(null)},onSubAgentStarted:(e,t,n)=>{H.getState().applyChildProgress(e,t,{title:n,status:`running`})},onSubAgentEvent:(e,t,n)=>{let r=n,i={};r.type===`token`&&r.content?(Ze.current[t]=(Ze.current[t]||``)+r.content,i.outputPreview=Ze.current[t].slice(-400)):r.type===`tool_start`&&r.tool_name&&(i.outputPreview=f(`calling_ace05fd8`,{v0:r.tool_name})),i.outputPreview!==void 0&&H.getState().applyChildProgress(e,t,i)},onSubAgentCompleted:(e,t,n,r)=>{H.getState().applyChildProgress(e,t,{status:r?`error`:n||`completed`,error:r||void 0})},onBashCompleted:(e,t,n,r)=>{H.getState().setBashCompleted(e,r,n)},onNotification:e=>{let t=e;_t(t.title??``,t.body??``)},onNeedClarification:()=>{let t=V.current;!c()||t.sessionId!==e||!Re(t)||(l.pendingRead=(async()=>{await ze(t)!==`absent`||!Re(t)||await ze(t)===`absent`&&Re(t)&&!Me.current.question&&Le(e=>({...e,error:e.error??f(`the_confirmation_request_is_not_ready_please_refresh_3093bf30`)}))})())},onMessageAppended:t=>{t===e&&H.getState().loadChatHistory(e,{mode:`monotonic`})},onChildApprovalRequested:(e,t,n)=>pe({childSessionId:e,requestId:t,toolName:n.toolName,permission:n.permission,resource:n.resource}),onSessionHistoryCommitted:t=>{t===e&&H.getState().loadChatHistory(e,{mode:`monotonic`})},onComplete:()=>{y()},onError:(e,t)=>{b(!1,e,t)},onCancelled:()=>{S()}},u).finally(()=>{T=!1,v(),u.signal.removeEventListener(`abort`,v),ke.current===d&&(ke.current=null,Be.current=null)}),l.settlement)await l.settlement;else if(c()){if(l.pendingRead&&await l.pendingRead,!c())return;let r=Me.current;if(r.scope.sessionId===e&&Re(r.scope)&&r.question){try{await H.getState().loadChatHistory(e),t?.pendingOperationId!==void 0&&an(t.pendingOperationId)}catch{}fn(null,n);return}let i=()=>H.getState().chats.find(t=>t.id===e)?.lastRunStatus;try{await H.getState().refreshChatsNow()}catch(e){console.warn(`[useChat] terminal-control summary reconciliation failed`,e)}if(!c())return;let o=i();if(o===`completed`)y();else if(o===`error`)b();else if(o===`cancelled`)S();else if(o===`suspended`){try{await ze(V.current),await H.getState().loadChatHistory(e),t?.pendingOperationId!==void 0&&an(t.pendingOperationId)}catch{}fn(null,n);return}else{let r=Ve.current,l=!1;try{await H.getState().loadChatHistory(e,{mode:`monotonic`,throwOnError:!0,waitForAssistant:!!r.trim(),retries:r.trim()?8:0,retryDelayMs:150}),l=!0}catch(e){console.warn(`[useChat] terminal-control history reconciliation failed`,e)}if(!c())return;let u=H.getState().chats.find(t=>t.id===e)?.messages??[];et(e,u);let d=s.find(e=>e.id===De.current),f={sessionId:e,operationId:n,text:r,baselineMessageId:De.current,baselineMessageText:d?.role===`assistant`&&d.type===`text`?d.content:null,baselineMessageIds:new Set(s.map(e=>e.id)),excludedCanonicalIds:new Set(a.excludedCanonicalIds),acknowledgedMessageId:t?.acknowledgedMessageId??null,anchorSeen:!1};if(r.trim()&&rt(u,[f]).remaining.length===0)y(l);else{try{await H.getState().refreshChatsNow()}catch(e){console.warn(`[useChat] terminal-control final summary reconciliation failed`,e)}if(!c())return;o=i(),o===`completed`?y(l):o===`cancelled`?S(l):b(l)}}l.settlement&&await l.settlement}},[x,C,j,vn,yn,_n,ln,un,se,dn,on,sn,cn,fn,Et,an,tn,en,Re,ze,Le]);(0,K.useEffect)(()=>(ye.current=!0,()=>{ye.current=!1,Et(),Tt.current&&xt(Tt.current),Tt.current=null,z.current=null,ke.current=null,Be.current=null,ve.current?.abort()}),[Et]);let xn=l?.isRunning??!1,Sn=l?.lastRunStatus===`suspended`,Cn=H(e=>s?ht(s)(e):!1);(0,K.useEffect)(()=>{!s||!Cn||Sn&&!xn||xe.current||Be.current!==s&&bn(s,{resume:!0})},[s,Cn,Sn,xn,re,bn]),(0,K.useEffect)(()=>{if(!s||xn||Be.current!==s||re)return;let e=setTimeout(()=>{Be.current===s&&(H.getState().chats.find(e=>e.id===s)?.isRunning||(ve.current?.abort(),H.getState().loadChatHistory(s).then(()=>fn(null))))},2e3);return()=>clearTimeout(e)},[s,xn,re,fn]);let[wn,Tn,En,Dn]=H(Yr(e=>{let t=s?e.executionBySession[s]:void 0;return[t?.interaction.pendingQuestion??null,t?.backend.hasPendingQuestion??null,t?.backend.hasPendingQuestion||Sn?t?.backend??null:null,t?.backend.lastRunStatus??null]}));(0,K.useEffect)(()=>{let e=V.current;_c(Me.current.scope,e)||(Pe.current=null,Le(()=>({scope:e,question:null,loading:!1,submitting:!1,unavailable:!1,error:null,retry:null,recordedKey:null}))),s&&ze(e)},[s,wn,Tn,En,Dn,Sn,ze,Le]),(0,K.useEffect)(()=>{if(n)return;let e=()=>{if(document.visibilityState!==`visible`)return;let e=H.getState();e.refreshChatsNow();let t=e.currentSessionId;t&&e.reconcileOpenSession(t,`visibility_regain`)};return document.addEventListener(`visibilitychange`,e),()=>document.removeEventListener(`visibilitychange`,e)},[n]);let On=(0,K.useCallback)(async(e,t)=>{if(xe.current||wo(e)||dc(e)!==`clear`||t?.expectedFailureOperationId!==void 0&&rn(e)?.operationId!==t.expectedFailureOperationId)return!1;let n={id:be.current+1,phase:`preparing`,originSessionId:e,originNavigationEpoch:V.current.epoch,acknowledgedSessionId:e,pendingOperationId:t?.pendingOperationId};be.current=n.id,en(e,n.id),xe.current=n,ye.current&&(ie(!0),le(!0));let r=!1,i=!1,a=()=>{xe.current?.id===n.id&&(xe.current=null,i=!0,ye.current&&(le(!1),ie(!1)))};try{if(await t?.prepare?.(),xe.current?.id!==n.id||t?.upstreamRetry&&(!ye.current||V.current.sessionId!==n.originSessionId||V.current.epoch!==n.originNavigationEpoch||t.expectedFailureOperationId!==void 0&&rn(e)?.operationId!==t.expectedFailureOperationId)||dc(e)!==`clear`||wo(e))return!1;if(t?.expectedFailureOperationId!==void 0&&rn(e)?.operationId!==t.expectedFailureOperationId?console.warn(`[useChat] retry failure ownership changed after preparation`):nn(e,t?.expectedFailureOperationId),n.phase=`generating`,!(ye.current&&V.current.sessionId===n.originSessionId&&V.current.epoch===n.originNavigationEpoch)){a();try{await vn(e,n.id,()=>zt.execute(e,x||void 0,j,void 0,C));try{await H.getState().loadChatHistory(e),n.pendingOperationId!==void 0&&an(n.pendingOperationId)}catch(e){console.warn(`[useChat] detached rerun history hydration failed`,e)}return!0}catch(t){return Ao(e,t),console.warn(`[useChat] detached rerun start failed`,t),tn({kind:`generation-failed`,operationId:n.id,sessionId:e,pendingOperationId:n.pendingOperationId,message:bc(t)}),!1}}ye.current&&le(!1);let i=bn(e,{upstreamRetry:t?.upstreamRetry,operationId:n.id,pendingOperationId:n.pendingOperationId});return r=!0,H.getState().loadChatHistory(e).then(()=>{n.pendingOperationId!==void 0&&an(n.pendingOperationId)}).catch(e=>console.warn(`[useChat] rerun history hydration failed`,e)),await i,!0}catch(i){return Ao(e,i),console.error(`[useChat] rerun failed`,i),t?.upstreamRetry&&!r&&ye.current&&we({sessionId:e,operationId:n.id,status:`unavailable`}),(r||!t?.preserveFailureOnPrepareError)&&tn({kind:`generation-failed`,operationId:n.id,sessionId:e,pendingOperationId:n.pendingOperationId,message:bc(i)}),fn(null,n.id),!1}finally{!i&&xe.current?.id===n.id&&(xe.current=null,ye.current&&(le(!1),ie(!1)))}},[an,nn,x,C,rn,en,tn,j,bn,vn,fn]),kn=(0,K.useCallback)(async()=>{s&&await On(s,{prepare:async()=>{let e=await zt.truncateSessionMessages(s,{mode:`after_last_user`}).catch(()=>null);if(e?.success&&e.session_id===s){let e=H.getState().chats.find(e=>e.id===s)?.messages??[];Ye(s,{messages:e,targetId:e.findLast(e=>e.role===`user`)?.id??null})}}})},[s,On]),An=(0,K.useCallback)(async(e,t)=>{let n=t?.upstreamRetry,r=async e=>{if(n){if(!await Mt())throw Error(f(`upstream_retry_unavailable`))}else await zt.truncateSessionMessages(e,{mode:`error_retry`})},i=rn(s??null),a=e??(i?.kind===`generation-failed`?i:void 0);if(a){if(rn(a.sessionId)?.operationId!==a.operationId)return;await On(a.sessionId,{upstreamRetry:n,expectedFailureOperationId:a.operationId,pendingOperationId:a.pendingOperationId,preserveFailureOnPrepareError:!0,prepare:()=>r(a.sessionId)});return}!s||l?.lastRunStatus!==`error`||await On(s,{upstreamRetry:n,preserveFailureOnPrepareError:!0,prepare:()=>r(s)})},[l?.lastRunStatus,rn,On,s]),jn=(0,K.useCallback)(async(e,t)=>{let n=t.trim();!s||!n||await On(s,{prepare:async()=>{await zt.patchSessionMessage(s,e,{content:n}).catch(()=>{});let t=await zt.restoreSessionState(s,{target_message_id:e,restore_files:!1}).catch(()=>null);t?.success&&t.session_id===s&&t.target_message_id===e&&Ye(s,{messages:H.getState().chats.find(e=>e.id===s)?.messages??[],targetId:e})}})},[s,On]),Mn=(0,K.useCallback)(async(e,r)=>{if(r?.isOriginCurrent&&!r.isOriginCurrent()||wo(s))return{kind:`blocked`};let i=e.trim();if(!i&&!r?.images?.length)return{kind:`ignored`};let a=r?.images?.map(e=>({...e}))??[];if(xe.current)return{kind:`busy`};let o=s,c=nt.getState(),l=o?C:lt(c.providerSnapshot,H.getState().selectedModel),u=o?x:l?.model||``;if(!o&&!l)return{kind:`blocked`};let d=o?O:l?c.getProviderType(l.provider):void 0;if(o&&dc(o)!==`clear`||o&&typeof r?.rootOrchestrationOnly==`boolean`||o&&r?.thinkingMode!==void 0)return{kind:`blocked`};let p=o?void 0:r?.thinkingMode;if(p!==void 0&&(p!==`standard`&&p!==`ultra`||r?.rootOrchestrationOnly!==void 0&&r.rootOrchestrationOnly!==(p===`ultra`)))return{kind:`blocked`};let m=o?j:r?.reasoningSelection===`auto`?void 0:r?.reasoningSelection??j,h={id:be.current+1,phase:`submitting`,originSessionId:o,originNavigationEpoch:V.current.epoch},g=new Set((mt(o??null)(H.getState())?.messages??[]).map(e=>e.id));be.current=h.id,en(o,h.id),xe.current=h,ye.current&&(ie(!0),le(!0)),nn(o);let _=o?null:r?.templatePrompt??null,v,y=null;try{let e=T(d).trim(),t;if(!o){let e=H.getState();t=Dc(e.systemPrompts,e.lastSelectedPromptId,_?.prompt)}let n=await zt.sendMessage({message:i,session_id:o??void 0,model:u,model_ref:l,reasoning_effort:o?void 0:m,enhance_prompt:e||void 0,copilot_conclusion_with_options_enhancement_enabled:d===`copilot`&&k(),system_prompt:t,selected_skill_ids:r?.skillIds?.length?r.skillIds:void 0,...r?.workflowSelection?{workflow_selection:r.workflowSelection}:{},root_orchestration_only:o?void 0:p===void 0?r?.rootOrchestrationOnly:p===`ultra`,thinking_mode:o?void 0:p??(r?.rootOrchestrationOnly===void 0?void 0:r.rootOrchestrationOnly?`ultra`:`standard`),images:a.length?a:void 0,workspace_path:!o&&r?.workspacePath?r.workspacePath:void 0,project_id:!o&&r?.projectId?r.projectId:void 0,permission_mode:!o&&r?.permissionMode?r.permissionMode:void 0});if(v=typeof n?.session_id==`string`?n.session_id.trim():``,!v||o&&v!==o)throw Error(`The chat submission response did not acknowledge the expected session.`);y=typeof n.message_id==`string`&&n.message_id.trim()?n.message_id.trim():null,S(u)}catch(e){console.error(`[useChat] message submission was not acknowledged`,e);let t=Ao(o,e),n=vc(e);if(xe.current?.id===h.id&&(xe.current=null),ye.current&&(le(!1),ie(!1),ne(e=>{if(!o||!e.claimed.has(o)||[...e.entries.values()].some(e=>e.sid===o))return e;let t=new Map(e.claimed);return t.delete(o),{...e,claimed:t}}),t||tn({kind:`submission-unconfirmed`,operationId:h.id,sessionId:o,message:bc(e),...n?{rejectionCode:n,rootModeSelectionSubmitted:n!==`session_project_running_conflict`&&typeof r?.rootOrchestrationOnly==`boolean`}:{}})),t)return{kind:`blocked`};let i=r?.workflowSelection?mn(e):null;return{kind:`unconfirmed`,operationId:h.id,...n?{rejectionCode:n}:{},...i?{workflowError:i}:{}}}h.phase=`generating`,h.acknowledgedSessionId=v,h.pendingOperationId=h.id,en(v,h.id),Ms(v),_&&ic(_),ye.current&&(i||a.length)&&ne(e=>({...e,entries:new Map(e.entries).set(h.id,{operationId:h.id,sid:v,text:i,images:a.map((e,t)=>({id:`pending-${h.id}-${t}`,name:e.name??`image`,size:e.size??0,type:e.type||`image/png`,base64:e.base64,url:e.base64.startsWith(`data:`)?e.base64:`data:${e.type||`image/png`};base64,${e.base64}`})),acknowledgedMessageId:y,baselineMessageIds:g})}));let b=!1;return ye.current&&V.current.sessionId===h.originSessionId&&V.current.epoch===h.originNavigationEpoch&&(r?.isOriginCurrent?.()??!0)?(le(!1),v!==o&&(n?t&&(t(v),b=!0):(H.getState().selectSession(v),b=!0)),bn(v,{operationId:h.id,pendingOperationId:h.pendingOperationId,acknowledgedMessageId:y,liveBootstrapResume:r?.liveBootstrapResume,reasoningEffort:m??null,modelSelection:{model:u,modelRef:l}}).catch(e=>{console.error(`[useChat] acknowledged generation failed`,e),tn({kind:`generation-failed`,operationId:h.id,sessionId:v,pendingOperationId:h.pendingOperationId,message:bc(e)}),fn(null,h.id)}).finally(()=>{xe.current?.id===h.id&&(xe.current=null),ye.current&&ie(!1)}),(async()=>{v!==o&&await H.getState().refreshChatsNow().catch(e=>console.warn(`[useChat] acknowledged session refresh failed`,e)),await H.getState().loadChatHistory(v,{mode:`monotonic`}),an(h.id)})().catch(e=>{console.warn(`[useChat] acknowledged message hydration failed`,e)})):(ye.current&&(le(!1),ie(!1)),xe.current?.id===h.id&&(xe.current=null),wo(v)?tn({kind:`generation-failed`,operationId:h.id,sessionId:v,message:f(`session_compatibility_execution_blocked`)}):dc(v)===`clear`?vn(v,h.id,()=>r?.liveBootstrapResume?zt.execute(v,u||void 0,m,void 0,l,void 0,!0):zt.execute(v,u||void 0,m,void 0,l)).catch(e=>{Ao(v,e),console.warn(`[useChat] detached generation start failed`,e),tn({kind:`generation-failed`,operationId:h.id,sessionId:v,message:bc(e)})}):tn({kind:`generation-failed`,operationId:h.id,sessionId:v,message:f(`the_root_permission_change_is_unconfirmed_your_message__64f12563`)}),v!==o&&H.getState().refreshChatsNow().catch(e=>console.warn(`[useChat] detached session refresh failed`,e))),{kind:`accepted`,operationId:h.id,sessionId:v,navigated:b}},[s,n,t,x,C,O,j,bn,fn,an,nn,en,tn,vn]),Nn=(0,K.useCallback)(()=>{let e=xe.current;if(e?.phase===`submitting`||e?.phase===`preparing`)return;let t=e?.acknowledgedSessionId??s,n=e?.pendingOperationId,r=e?.id??z.current??void 0,i=t?Se.current.get(t)??xc.get(t):void 0,a=t?Zo(wt(),t):{kind:`clear`},o=t?Qo(wt(),t):null;if(!i&&t&&o?.started&&(i=_n(t,r??0,o.operationId)),!i&&t&&a.kind===`confirmed`){let e=t,n=a.runId;i={sessionId:e,operationId:r??0,stop:wc(t=>Cc(e,n,t))},xc.set(e,i)}if(!i&&t&&a.kind!==`clear`){we({sessionId:t,operationId:r??0,status:`identity_unavailable`});return}!i&&t&&(i=yn(t,r??0));let c=i;c&&Se.current.set(c.sessionId,c);let l=()=>!!c&&Se.current.get(c.sessionId)===c;c&&we({sessionId:c.sessionId,operationId:c.operationId,status:`stopping`});let u=ve.current,d=c?c.stop(()=>u?.abort()):t?zt.stopGeneration(t):null;if(c&&d&&d.then(()=>{ye.current&&V.current.sessionId===c.sessionId&&l()&&we({sessionId:c.sessionId,operationId:c.operationId,status:`stop_requested`})},()=>{ye.current&&V.current.sessionId===c.sessionId&&l()&&we({sessionId:c.sessionId,operationId:c.operationId,status:`stop_unconfirmed`})}),t&&!c){let e=H.getState();e.markCancel(t),e.updateSession(t,{isRunning:!1},{skipBackendPatch:!0})}let f=St.current;if(f?.sessionId===t&&f.operationId===r){let e=ds(f.value);e!==f.value&&sn({...f,value:e})}c&&d?d.catch(()=>u?.abort()):u?.abort(),fn(null,r),!(!t||!d)&&(async()=>{await d.then(e=>e??`legacy`,()=>null)!==`legacy`&&await H.getState().refreshChatsNow().catch(()=>{});try{await H.getState().loadChatHistory(t),n!==void 0&&an(n)}catch(e){console.warn(`[useChat] stopped-generation history hydration failed`,e)}})()},[an,s,fn,sn,yn,_n]),Pn=(0,K.useCallback)(()=>{V.current.sessionId!==null&&(ve.current?.abort(),Et(),fn(null)),H.getState().selectSession(null)},[Et,fn]),Fn=(0,K.useCallback)(async e=>{s&&(await zt.deleteSessionMessage(s,e).then(()=>!0,()=>!1)&&qe(s,e),await H.getState().loadChatHistory(s))},[s]),In=(0,K.useCallback)(async e=>{if(s&&dc(s)===`clear`)try{let r=await Ot.post(`sessions/${encodeURIComponent(s)}/fork`,{up_to_message_id:e}),i=r?.session?.id??r?.session?.session_id;return i?(await H.getState().refreshChatsNow(),n?t?.(i):H.getState().selectSession(i),await H.getState().loadChatHistory(i),i):void 0}catch{return}},[s,n,t]),Ln=(0,K.useCallback)(async(e,t,n,r=!1)=>{let i=Me.current,{scope:a,question:o}=i;if(!a.sessionId||wo(a.sessionId)||!Re(a)||!o||Pe.current||i.loading||i.submitting)return;let s=gc(o);if(!t||!_c(t,a)||n!==s||i.recordedKey===s||!r&&(i.unavailable||i.retry)||r&&!i.retry)return;let c=null;if(o.interaction_kind===`permission`){let t=o.permission_request;if(r){let e=i.retry;if(e.request_id!==t.request_id||e.request_generation!==t.request_generation||e.expected_policy_revision!==t.policy_revision||!t.allowed_decisions.includes(e.decision))return;c=e}else{if(e!==`allow_once`&&e!==`deny_once`||!t.allowed_decisions.includes(e))return;c={request_id:t.request_id,request_generation:t.request_generation,expected_policy_revision:t.policy_revision,decision:e}}}else if(!e.trim()||!o.allow_custom&&!o.options.includes(e))return;let l={scope:a,key:s,awaitingResponse:!0};Pe.current=l;let u=()=>Pe.current===l&&Re(a)&&Me.current.question!==null&&gc(Me.current.question)===s;Le(e=>({...e,submitting:!0,error:null}));try{let t,n;if(c){let e=await zt.submitPermissionDecision(a.sessionId,c);t=e.autoResumeStatus,n=e.continuationConfirmed}else{let r=await Ot.post(`respond/${encodeURIComponent(a.sessionId)}`,{response:e,expected_tool_call_id:o.tool_call_id});if(r?.success!==!0)throw Error(`Unconfirmed clarification response`);t=r.auto_resume_status,n=[`started`,`already_running`,`completed`].includes(t??``)}if(l.awaitingResponse=!1,!u()||(++Ne.current,Le(e=>({...e,question:null,retry:null,recordedKey:s,unavailable:!1,loading:!1,error:n?null:f(`your_response_was_recorded_but_task_continuation_is_unc_844b0635`)})),await ze(a,!n),!Re(a)||Pe.current!==l))return;H.getState().loadChatHistory(a.sessionId).catch(()=>{}),n&&(t===`started`||t===`already_running`)&&!Me.current.question&&Be.current!==a.sessionId&&bn(a.sessionId,{resume:!0})}catch(e){if(Ao(a.sessionId,e),l.awaitingResponse=!1,!u())return;let t=Ct(e)&&e.status>=400&&e.status<500;Le(e=>({...e,retry:t?null:c,unavailable:t,error:f(t?`the_request_or_permissions_have_changed_confirm_again_u_a1ebae48`:c?`submission_is_unconfirmed_refresh_or_retry_the_last_sub_f3127c94`:`the_response_result_is_unconfirmed_refresh_the_current__2c1a59fd`)})),await ze(a,!0)}finally{Pe.current===l&&(Pe.current=null,Re(a)&&Le(e=>({...e,submitting:!1})))}},[Re,ze,bn,Le]),Rn=Fe?.scope,zn=Ie?gc(Ie):null,Bn=(0,K.useCallback)(e=>Ln(e,Rn,zn),[Ln,Rn,zn]),Vn=(0,K.useCallback)(()=>Ln(``,Rn,zn,!0),[Ln,Rn,zn]),Hn=(0,K.useCallback)(()=>ze(),[ze]),Un=(0,K.useCallback)(async e=>{let t=fe;if(!(!t||wo(t.childSessionId)||ge.current)){ge.current=t,he({request:t,submitting:!0,error:null});try{if((await zt.respondToChildApproval(t.childSessionId,t.requestId,e)).delivered!==!0)throw Error(`Unconfirmed Child approval delivery`);pe(e=>e===t?null:e)}catch(e){let n=Ao(t.childSessionId,e),r=Ct(e)&&e.status>=400&&e.status<500;he({request:t,submitting:!1,error:f(n||r?`the_request_or_permissions_have_changed_confirm_again_u_a1ebae48`:`submission_is_unconfirmed_refresh_or_retry_the_last_sub_f3127c94`)})}finally{ge.current===t&&(ge.current=null),he(e=>e?.request===t?{...e,submitting:!1}:e)}}},[fe]);return{booted:n?!0:M,chats:r,currentSessionId:s,currentChat:l,messages:Lt,streaming:W,streamPhase:Kt,streamingReasoning:G,liveSegments:Ut,streamStatus:Wt,contextCompression:Gt,outputRate:ae,upstreamRetryStatus:Ce?.sessionId===s?Ce.status:null,pendingUserText:Zt,pendingUserImages:Qt,pendingUserMessages:Yt,executionCompatibility:c,sending:re,submissionPending:ce,select:gn,send:Mn,stop:Nn,newChat:Pn,deleteMessage:Fn,fork:In,regenerate:kn,retry:An,editMessage:jn,sendFailure:$t,pendingQuestion:Ie,questionLoading:Fe?.loading??!1,questionSubmitting:Fe?.submitting??!1,questionUnavailable:(Fe?.unavailable??!1)||!!Ie&&Fe?.recordedKey===gc(Ie),questionError:Fe?.error??null,questionCanRetry:!!Fe?.retry,refreshQuestion:Hn,retryQuestion:Vn,pendingApproval:fe,approvalSubmitting:me?.submitting??!1,approvalError:me?.request===fe?me?.error??null:null,approvalCompatibility:_e,answerQuestion:Bn,respondApproval:Un}}var Ac=class extends Error{};async function jc(e){await H.getState().ensureProject(e,{force:!0}).catch(()=>{}),await H.getState().ensureProject(e,{force:!0});let t=H.getState().projects[e];if(!t||dt(t)<t.revision)throw Error(`Project snapshot is unavailable`)}async function Mc(e,t){let n=()=>{let n=H.getState().projects[e];return!!n?.sidebar&&dt(n)>=t.revision};if(!n()){try{await jc(e)}catch{throw new Ac}if(!n())throw new Ac}}var Nc=new Set;async function Pc(e,t,n){if(Nc.has(e))return`busy`;Nc.add(e);let r=!1;try{let i=H.getState(),a=i.projects[e];if(!a||a.sidebar===void 0)return`unavailable`;if(a.sidebar===null&&Object.hasOwn(t.projects,e)){if(r=!0,a=await i.updateProject(e,dt(a),{import_sidebar:wn(t.projects[e])}),!a.sidebar)return`unavailable`;await Mc(e,a),On(e,t.projects[e]),r=!1}if(a=H.getState().projects[e],!a||a.sidebar===void 0)return`unavailable`;let o=bn({[e]:a},t),s=n(o);if(s===o)return null;let c=await H.getState().updateProject(e,dt(a),{sidebar:wn(s.projects[e])});return c.sidebar?(await Mc(e,c),null):`unavailable`}catch(t){if(t instanceof Ac)return`saved-refresh-failed`;if(Ct(t)&&(t.status===412||r&&t.status===409))try{return await jc(e),`conflict`}catch{return`refresh-failed`}return`save-failed`}finally{Nc.delete(e)}}async function Fc(e,t,n,r){let i=i=>{let a=_n(i,e).sessionSections[t];return(a===void 0?n===null:a===n)?i:Dn(i,e,t,n,r??void 0)};for(let t=0;;t+=1){let n=await Pc(e,Cn(),i);if(n!==`busy`)return n===null;if(t>=40)return!1;await new Promise(e=>setTimeout(e,250))}}function Ic(e){let t=s(),[n]=(0,K.useState)(Cn),r=(0,K.useRef)(new Set),[i,a]=(0,K.useState)(new Set),[o,c]=(0,K.useState)({}),l=(0,K.useMemo)(()=>bn(e,n),[e,n]),u=(0,K.useCallback)(e=>{switch(e){case`unavailable`:return t(`sidebar_sections_unavailable`);case`saved-refresh-failed`:return t(`sidebar_sections_saved_refresh_failed`);case`conflict`:return t(`sidebar_sections_conflict`);case`refresh-failed`:return t(`sidebar_sections_refresh_failed`);default:return t(`sidebar_sections_save_failed`)}},[t]),d=(0,K.useCallback)(async(e,t)=>{if(Nc.has(e))return!1;a(t=>new Set(t).add(e)),c(t=>{let n={...t};return delete n[e],n});let r=await Pc(e,n,t);return a(t=>{if(!Nc.has(e)){let n=new Set(t);return n.delete(e),n}return t}),r&&c(t=>({...t,[e]:u(r)})),r===null},[n,u]),f=(0,K.useCallback)(async(e,t,n,r)=>d(e,i=>Dn(i,e,t,n,r??void 0)),[d]);return(0,K.useEffect)(()=>{for(let t of Object.values(e))t.sidebar!==null||!Object.hasOwn(n.projects,t.id)||r.current.has(t.id)||(r.current.add(t.id),d(t.id,e=>e))},[e,n,d]),{preferences:l,update:d,assignSessionToSection:f,busy:i,errors:o}}function Lc({scope:e,state:t,savedId:n,selectionVersion:r,activateTab:i,save:a}){let o=(0,K.useRef)(null);(0,K.useEffect)(()=>{o.current?.scope!==e&&(o.current={scope:e,version:r.current,status:`pending`});let s=o.current;if(t&&(s.version!==r.current&&(s.status=`complete`),s.status!==`activating`)){if(s.status===`pending`&&n&&n!==t.active_tab_id&&t.tabs?.some(e=>e.tab_id===n)){if(t.pending_dialog||s.attemptedState===t)return;s.status=`activating`,s.attemptedState=t,i(n).then(e=>{o.current!==s||s.version!==r.current||(s.status=e?`complete`:`pending`,e&&a(e.active_tab_id??null))});return}s.status=`complete`,a(t.active_tab_id??null)}},[e,t,n,r,i,a])}var Rc=[`work`,`inspector`,`review`,`session`],zc=()=>({open:!1,tab:null,tools:[],order:[],secondSid:null,reviewTarget:null,browserActiveId:null,browserPresent:!1}),Bc=e=>typeof e==`string`&&e.length>0&&e.length<=4096;function Vc(e,t){if(!t)return null;let n=new URL(e);return`lotus-next.workbench.v1:${encodeURIComponent(n.origin+n.pathname)}:${encodeURIComponent(t)}`}function Hc(e){let t=zc();if(!e)return t;try{let n=JSON.parse(localStorage.getItem(e)??`null`);if(!n||n.version!==1||!n.state||typeof n.state!=`object`)return t;let r=n.state,i=Array.isArray(r.tools)?[...new Set(r.tools.filter(e=>Rc.includes(e)))]:[];return{open:r.open===!0,tab:r.tab===`browser`||i.includes(r.tab)?r.tab:null,tools:i,order:Array.isArray(r.order)?[...new Set(r.order.filter(e=>Bc(e)&&(e.startsWith(`browser:`)||Rc.some(t=>e===`tool:${t}`))))].slice(0,200):[],secondSid:Bc(r.secondSid)?r.secondSid:null,reviewTarget:Bc(r.reviewTarget)?r.reviewTarget:null,browserActiveId:Bc(r.browserActiveId)?r.browserActiveId:null,browserPresent:r.browserPresent===!0}}catch{return t}}function Uc(e){let t=Vc(wt(),e),n=(0,K.useRef)(new Map),[r,i]=(0,K.useState)(()=>({key:t,state:Hc(t)})),a=r;r.key!==t&&(a={key:t,state:n.current.get(t)??Hc(t)},i(a)),(0,K.useEffect)(()=>{if(n.current.delete(t),!(!r.key||r.key!==t))try{localStorage.setItem(r.key,JSON.stringify({version:1,state:r.state}))}catch{}},[t,r]);let o=(0,K.useCallback)((e,n)=>{i(r=>{if(r.key!==t)return r;let i=typeof n==`function`?n(r.state[e]):n;return Object.is(i,r.state[e])?r:{key:t,state:{...r.state,[e]:i}}})},[t]);return{state:a.state,setField:o,scope:t,openToolForSession:(e,r)=>{let o=Vc(wt(),e),s=o===t?a.state:n.current.get(o)??Hc(o),c={...s,open:!0,tab:r,tools:s.tools.includes(r)?s.tools:[...s.tools,r]};if(o===t)i(e=>e.key===t?{key:t,state:{...e.state,open:!0,tab:r,tools:e.state.tools.includes(r)?e.state.tools:[...e.state.tools,r]}}:e);else if(n.current.set(o,c),o)try{localStorage.setItem(o,JSON.stringify({version:1,state:c}))}catch{}}}}var Wc=(e,t,n)=>Math.min(n,Math.max(t,e));function Gc(e,t,n){let{min:r,max:i}=n,[a,o]=(0,K.useState)(()=>{try{let t=localStorage.getItem(e),n=t?Number(t):NaN;if(Number.isFinite(n)&&n>0)return n}catch{}return t});return{width:Wc(a,r,i),setWidth:(0,K.useCallback)(t=>{if(!Number.isFinite(t)||t<=0)return;let n=Wc(t,r,i);o(n);try{localStorage.setItem(e,String(n))}catch{}},[e,r,i])}}function Kc(e,t){let n=t>0?2:1;return Math.max(360,e-t-360-n)}function qc(e){let[t,n]=(0,K.useState)(()=>window.innerWidth);(0,K.useEffect)(()=>{let e=()=>n(window.innerWidth);return window.addEventListener(`resize`,e),e(),()=>window.removeEventListener(`resize`,e)},[]);let r=Kc(t,e);return{...Gc(`lotus_next_inspector_w`,520,{min:360,max:r}),maxWidth:r,viewportWidth:t}}function Jc(e){return(typeof e==`number`||typeof e==`string`)&&e!==``}function Yc(e){let t=(0,K.useId)();return Jc(e)?`${e}`:t}var Xc=typeof window<`u`?K.useLayoutEffect:K.useEffect;function Zc(e){let t=(0,K.useRef)(e);return Xc(()=>{t.current=e},[e]),(0,K.useCallback)((...e)=>t.current?.(...e),[t])}function Qc(...e){return Zc(t=>{e.forEach(e=>{if(e)switch(typeof e){case`function`:e(t);break;case`object`:e.current=t;break}})})}function $c(e,t){let n=e?.[`data-testid`];return Jc(n)?`${n}`:Jc(t)?`${t}`:void 0}function el(e,t){return t?e*2+1:e+1}function tl(e,t){return t?e*2-1:e}function nl(e,t,n){let r=el(e,n);return t===void 0?`${r} / -1`:`${r} / span ${tl(t,n)}`}function rl(e){return`${e*2} / span 1`}function il({crossCount:e,crossSpan:t,crossStart:n,hasGutters:r}){let i=t===void 0?e:n+t;if(n===0&&i===e)return`1 / -1`;let a=el(n,r),o=el(i-1,r)+1;return r&&(n>0&&a--,i<e&&o++),`${a} / ${o}`}function al(e,t){return Number.isInteger(e)&&e>=1&&e<t}function ol(e,t=`Assertion error`){if(!e)throw Error(t)}var sl=(0,K.createContext)(null);function cl(){let e=(0,K.useContext)(sl);return ol(e,`Grid Context not found; did you render a Cell or Gridline outside of a Grid?`),e}function ll({children:e,className:t,column:n,columnSpan:r=1,elementRef:i,id:a,row:o,rowSpan:s=1,style:c,...l}){let u=Yc(a),{gutters:d,registerCell:f}=cl(),p=(0,K.useRef)(null),m=Qc(p,i);return Xc(()=>{let e=p.current;if(e!==null)return f({column:n,columnSpan:r,element:e,id:u,row:o,rowSpan:s})},[n,r,u,f,o,s]),(0,q.jsx)(`div`,{...l,className:t,"data-cell":!0,"data-testid":$c(l,a),id:u,ref:m,style:{overflow:`auto`,...c,minHeight:0,minWidth:0,gridColumn:nl(n,r,d.column),gridRow:nl(o,s,d.row)},children:e})}ll.displayName=`Cell`;var ul;function dl(){return ul===void 0&&(ul=typeof matchMedia==`function`?!!matchMedia(`(pointer:coarse)`).matches:!1),ul}function fl({expandHitTargets:e,axis:t,rect:n}){let r=e?dl()?t.resizeTargetMinimumSize.coarse:t.resizeTargetMinimumSize.fine:0;if(n.width<r){let e=r-n.width;n=new DOMRect(n.x-e/2,n.y,n.width+e,n.height)}if(n.height<r){let e=r-n.height;n=new DOMRect(n.x,n.y-e/2,n.width,n.height+e)}return n}function pl({axis:e,cells:t,index:n,rect:r}){let i=[r];for(let r of t){let t=e===`column`?r.column:r.row,a=e===`column`?r.columnSpan:r.rowSpan;if(t>=n||t+a<=n)continue;let o=r.element.getBoundingClientRect(),s=e===`column`?o.top:o.left,c=e===`column`?o.bottom:o.right;c<=s||(i=i.flatMap(t=>{let n=e===`column`?t.top:t.left,r=e===`column`?t.bottom:t.right;if(s>=r||c<=n)return[t];let i=[],a=(n,r)=>{i.push(e===`column`?new DOMRect(t.x,n,t.width,r-n):new DOMRect(n,t.y,r-n,t.height))};return n<s&&a(n,s),r>c&&a(c,r),i}))}return i}function ml({axis:e,cells:t,crossTrackCount:n,expandHitTargets:r,resizeAxis:i,axisSize:a,includeDisabled:o,separatorPlacements:s}){let{items:c,separators:l}=i,u=c.length,d=-1,f=-1,p=0;if(c.forEach((e,t)=>{e.constraintProps.disabled||(p++,d===-1&&(d=t),f=t)}),!o&&p<2)return[];let m=e=>o||e>d&&e<=f,h=[],g=(e,t,n)=>({axis:i,axisSize:a,items:[c[e-1],c[e]],rect:t,separator:n}),_=(n,r)=>{let i;for(let a of t){let t=e===`column`?a.row:a.column,o=e===`column`?a.rowSpan:a.columnSpan;if(r===`start`?t===n:t+o-1===n){let t=a.element.getBoundingClientRect();if(r===`start`){let n=e===`column`?t.top:t.left;i=i===void 0?n:Math.min(i,n)}else{let n=e===`column`?t.bottom:t.right;i=i===void 0?n:Math.max(i,n)}}}return i},v=new Set;for(let a of l){let c=s.get(a);if(!c||c.index<1||c.index>=u||(v.add(c.index),!o&&(a.disabled||a.element.hasAttribute(`aria-disabled`)))||!m(c.index))continue;let l=a.element.getBoundingClientRect(),{crossSpan:d,crossStart:f}=c,p=d===void 0?n:f+d,y=e===`column`?l.top:l.left,b=e===`column`?l.bottom:l.right;if(f>0){let e=_(f-1,`end`);e!==void 0&&e<y&&(y=e)}if(p<n){let e=_(p,`start`);e!==void 0&&e>b&&(b=e)}l=e===`column`?new DOMRect(l.x,y,l.width,b-y):new DOMRect(y,l.y,b-y,l.height),l=fl({expandHitTargets:r,axis:i,rect:l}),o?h.push(g(c.index,l,a)):pl({axis:e,cells:t,index:c.index,rect:l}).forEach(e=>{h.push(g(c.index,e,a))})}let y=(n,a)=>{pl({axis:e,cells:t,index:n,rect:fl({expandHitTargets:r,axis:i,rect:a})}).forEach(e=>{h.push(g(n,e))})},b=Array.from({length:n},()=>Array(u));for(let r of t){let[t,i,a,o]=e===`column`?[r.column,r.columnSpan,r.row,r.rowSpan]:[r.row,r.rowSpan,r.column,r.columnSpan];for(let e=Math.max(0,a);e<Math.min(n,a+o);e++)for(let n=Math.max(0,t);n<Math.min(u,t+i);n++)b[e][n]??=r}let x=new Map,S=t=>{let n=x.get(t);if(!n){let r=t.element.getBoundingClientRect();n=e===`column`?{crossEnd:r.bottom,crossStart:r.top,end:r.right,start:r.left}:{crossEnd:r.right,crossStart:r.left,end:r.bottom,start:r.top},x.set(t,n)}return n},C=({crossEnd:t,crossStart:n,end:r,start:i})=>e===`column`?new DOMRect(i,n,r-i,t-n):new DOMRect(n,i,t-n,r-i);for(let e=1;e<u;e++){if(v.has(e)||!m(e))continue;let t;for(let r=0;r<n;r++){let n=b[r][e-1],i=b[r][e],a;if((n||i)&&n!==i){let e=n?S(n):void 0,t=i?S(i):void 0,r=e?.end??t.start,o=t?.start??e.end,s=Math.max(e?.crossStart??-1/0,t?.crossStart??-1/0),c=Math.min(e?.crossEnd??1/0,t?.crossEnd??1/0);a={crossEnd:Math.max(s,c),crossStart:s,end:Math.max(r,o),start:Math.min(r,o)}}a?t=t?{crossEnd:Math.max(t.crossEnd,a.crossEnd),crossStart:Math.min(t.crossStart,a.crossStart),end:Math.max(t.end,a.end),start:Math.min(t.start,a.start)}:a:t&&=(y(e,C(t)),void 0)}t&&y(e,C(t))}return h}function hl(e){let t=parseFloat(e??``);return Number.isFinite(t)?t:0}function gl({axis:e,element:t,gutterSizes:n,hasGutters:r,layout:i,trackIds:a}){let o=a.length,s=r?o*2-1:o,c=t.ownerDocument.defaultView?.getComputedStyle(t),l=e===`column`?c?.gridTemplateColumns:c?.gridTemplateRows;if(l){let e=l.trim().split(/\s+/);if(e.length===s&&e.every(e=>/^-?[\d.]+px$/.test(e))){let t=a.map((t,n)=>hl(e[r?n*2:n]));return{availableSize:t.reduce((e,t)=>e+t,0),trackSizes:t}}}let u=e===`column`?t.offsetWidth:t.offsetHeight,d=e===`column`?hl(c?.paddingLeft)+hl(c?.paddingRight)+hl(c?.borderLeftWidth)+hl(c?.borderRightWidth):hl(c?.paddingTop)+hl(c?.paddingBottom)+hl(c?.borderTopWidth)+hl(c?.borderBottomWidth),f=hl(e===`column`?c?.columnGap:c?.rowGap),p=n.reduce((e,t)=>e+t,0),m=Math.max(0,u-d-f*Math.max(0,s-1)-p);return{availableSize:m,trackSizes:a.map(e=>i&&i[e]!==void 0?i[e]/100*m:m/o)}}function _l(e){switch(typeof e){case`number`:return[e,`px`];case`string`:{let t=parseFloat(e);return e.endsWith(`%`)?[t,`%`]:e.endsWith(`px`)?[t,`px`]:e.endsWith(`rem`)?[t,`rem`]:e.endsWith(`em`)?[t,`em`]:e.endsWith(`vh`)?[t,`vh`]:e.endsWith(`vw`)?[t,`vw`]:[t,`%`]}}}var vl=class{#e={};addListener(e,t){let n=this.#e[e];return n===void 0?this.#e[e]=[t]:n.includes(t)||n.push(t),()=>{this.removeListener(e,t)}}emit(e,t){let n=this.#e[e];if(n!==void 0){if(n.length===1){n[0].call(null,t);return}let e,r=Array.from(n);for(let n=0;n<r.length;n++){let i=r[n];try{i.call(null,t)}catch(t){e??={error:t}}}if(e)throw e.error}}removeAllListeners(){this.#e={}}removeListener(e,t){let n=this.#e[e];if(n!==void 0){let e=n.indexOf(t);e>=0&&n.splice(e,1)}}},yl={cursorFlags:0,state:`inactive`},bl=new vl;function xl(){return yl}function Sl(e){return bl.addListener(`change`,e)}function Cl(e,t=[],n,r=!1){let i=yl,a={...yl};a.cursorFlags=e,a.state===`active`&&(a.didPointerMove||=r,a.previews=t,n&&(a.previewLayoutMap=n)),yl=a,bl.emit(`change`,{prev:i,next:a})}function wl(e){let t=yl;yl=e,t.state===`active`&&e.state!==`active`&&t.didPointerMove&&t.hitRegions.forEach(({separator:e})=>{e&&e.element.ownerDocument.activeElement===e.element&&e.element.blur()}),bl.emit(`change`,{prev:t,next:e})}function Tl(e){yl.state!==`active`||!yl.previews.some(t=>t.separator===e)||wl({...yl,previews:yl.previews.map(t=>t.separator===e?{...t}:t)})}function El(e){if(yl.state===`inactive`)return;let t=yl.hitRegions.filter(t=>t.axis!==e),n=yl.state===`active`&&yl.previews.some(t=>t.axis===e);if(!(t.length===yl.hitRegions.length&&!n))if(t.length===0)wl({cursorFlags:0,state:`inactive`});else if(yl.state===`active`){let n=new Map(yl.initialLayoutMap),r=new Map(yl.previewLayoutMap);n.delete(e),r.delete(e),wl({...yl,cursorFlags:0,hitRegions:t,initialLayoutMap:n,previewLayoutMap:r,previews:yl.previews.filter(t=>t.axis!==e)})}else wl({...yl,hitRegions:t})}var Dl=e=>e,Ol=()=>{},kl=1,Al=2,jl=4,Ml=8,Nl=3,Pl=12,Fl;function Il(){return Fl===void 0&&(Fl=!1,typeof window<`u`&&(window.navigator.userAgent.includes(`Chrome`)||window.navigator.userAgent.includes(`Firefox`))&&(Fl=!0)),Fl}function Ll({cursorFlags:e,axes:t,state:n}){let r=0,i=0;switch(n){case`active`:case`hover`:t.forEach(e=>{if(!e.mutableState.disableCursor)switch(e.orientation){case`horizontal`:r++;break;case`vertical`:i++;break}})}if(!(r===0&&i===0)){switch(n){case`active`:if(e&&Il()){let t=(e&kl)!==0,n=(e&Al)!==0,r=(e&jl)!==0,i=(e&Ml)!==0;if(t)return r?`se-resize`:i?`ne-resize`:`e-resize`;if(n)return r?`sw-resize`:i?`nw-resize`:`w-resize`;if(r)return`s-resize`;if(i)return`n-resize`}break}return Il()?r>0&&i>0?`move`:r>0?`ew-resize`:`ns-resize`:r>0&&i>0?`grab`:r>0?`col-resize`:`row-resize`}}var Rl=new WeakMap;function zl(e){if(!e.defaultView||!e.adoptedStyleSheets)return;let{prevStyle:t,styleSheet:n}=Rl.get(e)??{};n===void 0&&(n=new e.defaultView.CSSStyleSheet,e.adoptedStyleSheets&&(Object.isExtensible(e.adoptedStyleSheets)?e.adoptedStyleSheets.push(n):e.adoptedStyleSheets=[...e.adoptedStyleSheets,n]));let r=xl();switch(r.state!==`inactive`&&r.ownerDocument!==e&&(r={cursorFlags:0,state:`inactive`}),r.state){case`active`:case`hover`:{let e=Ll({cursorFlags:r.cursorFlags,axes:r.hitRegions.map(e=>e.axis),state:r.state}),i=`*, *:hover {cursor: ${e} !important; }`;if(t===i)return;t=i,e?n.cssRules.length===0?n.insertRule(i):n.replaceSync(i):n.cssRules.length===1&&n.deleteRule(0);break}case`inactive`:t=void 0,n.cssRules.length===1&&n.deleteRule(0);break}Rl.set(e,{prevStyle:t,styleSheet:n})}function Bl(e){return e.state===`inactive`?void 0:e.ownerDocument}function Vl({next:e,prev:t}){let n=Bl(t),r=Bl(e);n&&n!==r&&zl(n),r&&zl(r)}function Hl({axis:e}){let{layoutStrategy:t,orientation:n,items:r}=e;return t?t.calculateAvailableSize():r.reduce((e,t)=>(e+=n===`horizontal`?t.element.offsetWidth:t.element.offsetHeight,e),0)}function Ul(e,t){let n=e.compareDocumentPosition(t);return n&Node.DOCUMENT_POSITION_DISCONNECTED?0:n&Node.DOCUMENT_POSITION_FOLLOWING?-1:n&Node.DOCUMENT_POSITION_PRECEDING?1:0}function Wl(e,t){return Array.from(t).sort((t,n)=>{let r=e===`horizontal`?Gl(t,n):Kl(t,n);return r===0?Ul(t.element,n.element):r})}function Gl(e,t){let n=e.element.offsetLeft-t.element.offsetLeft;return n===0?e.element.offsetWidth-t.element.offsetWidth:n}function Kl(e,t){let n=e.element.offsetTop-t.element.offsetTop;return n===0?e.element.offsetHeight-t.element.offsetHeight:n}function ql(e){return typeof e==`object`&&!!e&&`nodeType`in e&&e.nodeType===Node.ELEMENT_NODE}function Jl(e,t){return{x:e.x>=t.left&&e.x<=t.right?0:Math.min(Math.abs(e.x-t.left),Math.abs(e.x-t.right)),y:e.y>=t.top&&e.y<=t.bottom?0:Math.min(Math.abs(e.y-t.top),Math.abs(e.y-t.bottom))}}function Yl({orientation:e,rects:t,targetRect:n}){let r={x:n.x+n.width/2,y:n.y+n.height/2},i,a=Number.MAX_VALUE;for(let n of t){let{x:t,y:o}=Jl(r,n),s=e===`horizontal`?t:o;s<a&&(a=s,i=n)}return ol(i,`No rect found`),i}function Xl({expandHitTargets:e=!0,axis:t,includeDisabled:n=!1}){if(t.layoutStrategy)return t.layoutStrategy.calculateHitRegions({expandHitTargets:e,axis:t,includeDisabled:n});let{element:r,orientation:i,items:a,separators:o}=t,s=Wl(i,Array.from(r.children).filter(ql).filter(e=>!e.hasAttribute(`data-resize-preview`)).map(e=>({element:e}))).map(({element:e})=>e),c=[],l=!1,u=!1,d=-1,f,p=-1,m=0,h,g=[];{let e=-1;for(let t of s)t.hasAttribute(`data-panel`)&&(e++,t.hasAttribute(`data-disabled`)||(m++,d===-1&&(d=e),p=e))}if(n||m>1){let r=-1;for(let m of s)if(m.hasAttribute(`data-panel`)){r++;let o=a.find(e=>e.element===m);if(o){if(h){let a=h.element.getBoundingClientRect(),s=m.getBoundingClientRect(),_;if(u){let e=i===`horizontal`?new DOMRect(a.right,a.top,0,a.height):new DOMRect(a.left,a.bottom,a.width,0),t=i===`horizontal`?new DOMRect(s.left,s.top,0,s.height):new DOMRect(s.left,s.top,s.width,0);switch(g.length){case 0:_=[e,t];break;case 1:{let n=g[0];_=[n,Yl({orientation:i,rects:[a,s],targetRect:n.element.getBoundingClientRect()})===a?t:e];break}default:_=g;break}}else _=g.length?g:[i===`horizontal`?new DOMRect(a.right,s.top,s.left-a.right,s.height):new DOMRect(s.left,a.bottom,s.width,s.top-a.bottom)];for(let i of _){let a=fl({expandHitTargets:e,axis:t,rect:`width`in i?i:i.element.getBoundingClientRect()});(n||!l&&!(r<=d||r>p))&&(f??=Hl({axis:t}),c.push({axis:t,axisSize:f,items:[h,o],separator:`width`in i?void 0:i,rect:a})),l=!1}}u=!1,h=o,g=[]}}else if(m.hasAttribute(`data-separator`)){m.ariaDisabled!==null&&(l=!0);let e=o.find(e=>e.element===m);e?g.push(e):(h=void 0,g=[])}else u=!0}return c}function Zl(e,t){let n=getComputedStyle(e);return t*parseFloat(n.fontSize)}function Ql(e,t){let n=getComputedStyle(e.ownerDocument.documentElement);return t*parseFloat(n.fontSize)}function $l(e){return e/100*window.innerHeight}function eu(e){return e/100*window.innerWidth}function tu({axisSize:e,itemElement:t,styleProp:n}){let r,[i,a]=_l(n);switch(a){case`%`:r=i/100*e;break;case`px`:r=i;break;case`rem`:r=Ql(t,i);break;case`em`:r=Zl(t,i);break;case`vh`:r=$l(i);break;case`vw`:r=eu(i);break}return r}function nu(e){return parseFloat(e.toFixed(3))}function ru(e,t=Hl({axis:e})){let{items:n}=e;return t===0?n.map(e=>({groupResizeBehavior:e.constraintProps.groupResizeBehavior,collapsedSize:0,collapsible:e.constraintProps.collapsible===!0,defaultSize:void 0,disabled:e.constraintProps.disabled,minSize:0,maxSize:100,itemId:e.id})):n.map(e=>{let{element:n,constraintProps:r}=e,i=0;r.collapsedSize!==void 0&&(i=nu(tu({axisSize:t,itemElement:n,styleProp:r.collapsedSize})/t*100));let a;r.collapsedThreshold!==void 0&&(a=nu(tu({axisSize:t,itemElement:n,styleProp:r.collapsedThreshold})/t*100));let o;r.defaultSize!==void 0&&(o=nu(tu({axisSize:t,itemElement:n,styleProp:r.defaultSize})/t*100));let s=0;r.minSize!==void 0&&(s=nu(tu({axisSize:t,itemElement:n,styleProp:r.minSize})/t*100));let c=100;return r.maxSize!==void 0&&(c=nu(tu({axisSize:t,itemElement:n,styleProp:r.maxSize})/t*100)),{groupResizeBehavior:r.groupResizeBehavior,collapsedSize:i,collapsedThreshold:a,collapsible:r.collapsible===!0,defaultSize:o,disabled:r.disabled,minSize:s,maxSize:c,itemId:e.id}})}var iu=new Map,au=new vl,ou=0,su=[],cu;function lu(){ou++}function uu(){for(let e=0;e<su.length;e++)try{au.emit(`axisChange`,su[e])}catch(e){cu??={error:e}}su.length=0}function du(){if(ou===1&&uu(),ou--,ou===0&&cu){let{error:e}=cu;throw cu=void 0,e}}function fu(e){iu=new Map(iu),iu.delete(e)}function pu(e,t){for(let[t]of iu)if(t.id===e)return t}function mu(e,t){for(let[t,n]of iu)if(t.id===e)return n;if(t)throw Error(`Could not find data for Group with id ${e}`)}function hu(){return iu}function gu(e,t){return au.addListener(`axisChange`,n=>{n.axis.id===e&&t(n)})}function _u(e,t,n){let r=iu.get(e);iu=new Map(iu),iu.set(e,t);let i={axis:e,isUserInteraction:n?.isUserInteraction===!0,prev:r,next:t};ou>0?su.push(i):au.emit(`axisChange`,i)}function vu(e,{pointerId:t,pointerType:n}){return t===e.pointerId||n===`pen`&&e.pointerType===`pen`}function yu(e,t,n={}){return e.ownerDocument===t&&(n.pointerId===void 0||vu(e,n))}function bu(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n]!=t[n])return!1;return!0}function xu(e,t,n=0){return Math.abs(nu(e)-nu(t))<=n}function Su(e,t){return xu(e,t)?0:e>t?1:-1}function Cu({overrideDisabledItems:e,itemConstraints:t,prevSize:n,size:r}){let{collapsedSize:i=0,collapsedThreshold:a,collapsible:o,disabled:s,maxSize:c=100,minSize:l=0}=t;if(s&&!e)return n;if(Su(r,l)<0)if(o){let e=a??(l-i)/2,t=Su(n,i)<=0,o=t?i+e:l-e,s=Su(r,o);r=Su(r,i)<=0||s<0||a!==void 0&&t&&s===0?i:l}else r=l;return r=Math.min(c,r),r=nu(r),r}function wu({delta:e,initialLayout:t,itemConstraints:n,pivotIndices:r,prevLayout:i,trigger:a}){if(xu(e,0))return t;let o=a===`imperative-api`,s=n.map(({itemId:e})=>t[e]),c=n.map(({itemId:e})=>i[e]),l=[...s],[u,d]=r;ol(u!=null,`Invalid first pivot index`),ol(d!=null,`Invalid second pivot index`);let f=0;switch(a){case`keyboard`:{let t=e<0?d:u,r=n[t];ol(r,`Panel constraints not found for index ${t}`);let{collapsedSize:i=0,collapsible:a,minSize:o=0}=r;if(a){let n=s[t];if(ol(n!=null,`Previous layout not found for panel index ${t}`),xu(n,i)){let t=o-n;Su(t,Math.abs(e))>0&&(e=e<0?0-t:t)}}}{let t=e<0?u:d,r=n[t];ol(r,`No panel constraints found for index ${t}`);let{collapsedSize:i=0,collapsible:a,minSize:o=0}=r;if(a){let n=s[t];if(ol(n!=null,`Previous layout not found for panel index ${t}`),xu(n,o)){let t=n-i;Su(t,Math.abs(e))>0&&(e=e<0?0-t:t)}}}break;default:{let t=e<0?d:u,r=n[t];ol(r,`Panel constraints not found for index ${t}`);let i=s[t],{collapsedSize:a,collapsedThreshold:o,collapsible:c,minSize:l}=r;if(c&&Su(i,l)<0){let t=l-a,n=o??t/2;if(Su(i+Math.abs(e),l)<0){let r=Su(Math.abs(e),n);e=r>0||r===0&&o===void 0&&e<0?e<0?-t:t:0}}break}}{let t=e<0?1:-1,r=e<0?d:u,i=0;for(;;){let e=s[r];ol(e!=null,`Previous layout not found for panel index ${r}`);let a=Cu({overrideDisabledItems:o,itemConstraints:n[r],prevSize:e,size:100})-e;if(i+=a,r+=t,r<0||r>=n.length)break}let a=Math.min(Math.abs(e),Math.abs(i));e=e<0?0-a:a}{let t=e<0?u:d;for(;t>=0&&t<n.length;){let r=Math.abs(e)-Math.abs(f),i=s[t];ol(i!=null,`Previous layout not found for panel index ${t}`);let a=i-r,c=Cu({overrideDisabledItems:o,itemConstraints:n[t],prevSize:i,size:a});if(!xu(i,c)&&(f+=i-c,l[t]=c,f.toFixed(3).localeCompare(Math.abs(e).toFixed(3),void 0,{numeric:!0})>=0))break;e<0?t--:t++}}if(bu(c,l))return i;{let t=e<0?d:u,r=s[t];ol(r!=null,`Previous layout not found for panel index ${t}`);let i=r+f,a=Cu({overrideDisabledItems:o,itemConstraints:n[t],prevSize:r,size:i});if(l[t]=a,!xu(a,i)){let t=i-a,r=e<0?d:u;for(;r>=0&&r<n.length;){let i=l[r];ol(i!=null,`Previous layout not found for panel index ${r}`);let a=i+t,s=Cu({overrideDisabledItems:o,itemConstraints:n[r],prevSize:i,size:a});if(xu(i,s)||(t-=s-i,l[r]=s),xu(t,0))break;e>0?r--:r++}}}return xu(Object.values(l).reduce((e,t)=>t+e,0),100,.1)?l.reduce((e,t,r)=>(e[n[r].itemId]=t,e),{}):i}function Tu(e,t){if(Object.keys(e).length!==Object.keys(t).length)return!1;for(let n in e)if(t[n]===void 0||Su(e[n],t[n])!==0)return!1;return!0}function Eu(e){lu();try{Du(e)}finally{du()}}function Du({commit:e,event:t,hitRegions:n,initialLayoutMap:r,mountedAxes:i,pointerDownAtPoint:a,prevCursorFlags:o}){let s=0,c=xl(),l=c.state===`active`?c.previews:[],u=new Map(c.state===`active`?c.previewLayoutMap:void 0);n.forEach(n=>{let{axis:o,axisSize:c}=n,{orientation:d,items:f}=o;if(e&&o.resizePreviewMode!==`separator`)return;let{disableCursor:p}=o.mutableState,m=0;m=a?d===`horizontal`?(t.clientX-a.x)/c*100:(t.clientY-a.y)/c*100:d===`horizontal`?t.clientX<0?-100:100:t.clientY<0?-100:100;let h=r.get(o),g=i.get(o);if(!h||!g)return;let{defaultLayoutDeferred:_,derivedItemConstraints:v,axisSize:y,layout:b,separatorToItems:x}=g;if(v&&b&&x){let t=o.resizePreviewMode===`separator`?u.get(o)??b:b,r=wu({delta:m,initialLayout:h,itemConstraints:v,pivotIndices:n.items.map(e=>f.indexOf(e)),prevLayout:t,trigger:`mouse-or-touch`});if(o.resizePreviewMode===`separator`&&!e&&!Tu(r,t)){u.set(o,r);let e=0,t=f.map(t=>(e+=r[t.id]-h[t.id],c/100*e));l=l.map(e=>{if(e.axis!==o)return e;let n=t[e.itemIndex];return n===e.offset?e:{...e,offset:n}})}if(Tu(r,t)&&m!==0&&!p)switch(d){case`horizontal`:s|=m<0?kl:Al;break;case`vertical`:s|=m<0?jl:Ml;break}(o.resizePreviewMode!==`separator`||e)&&!Tu(r,b)&&_u(n.axis,{defaultLayoutDeferred:_,derivedItemConstraints:v,axisSize:y,layout:r,requestedAxisSize:y,requestedLayout:r,separatorToItems:x})}});let d=0;t.movementX===0?d|=o&Nl:d|=s&Nl,t.movementY===0?d|=o&Pl:d|=s&Pl;let f=c.state===`active`&&(t.clientX!==c.pointerDownAtPoint.x||t.clientY!==c.pointerDownAtPoint.y);Cl(d,l,u,f)}function Ou(e,t){let n=xl();if(n.state!==`active`||!yu(n,e,t))return;let r=hu();lu();try{Eu({commit:!0,event:t,hitRegions:n.hitRegions,initialLayoutMap:n.initialLayoutMap,mountedAxes:r,pointerDownAtPoint:n.pointerDownAtPoint,prevCursorFlags:n.cursorFlags}),uu(),wl({cursorFlags:0,state:`inactive`}),n.hitRegions.length>0&&(t.preventDefault?.(),n.hitRegions.forEach(e=>{if(!r.has(e.axis))return;let t=mu(e.axis.id,!0);_u(e.axis,t,{isUserInteraction:!0})}))}finally{du()}}function ku(e){if(e.defaultPrevented)return;let{clientX:t,clientY:n,movementX:r,movementY:i}=e;Ou(e.currentTarget,{clientX:t,clientY:n,movementX:r,movementY:i})}function Au(e,t,n){let r,i={x:1/0,y:1/0};for(let a of t){let t=Jl(n,a.rect);switch(e){case`horizontal`:(t.x<i.x||t.x===i.x&&t.y<=i.y)&&(r=a,i=t);break;case`vertical`:(t.y<i.y||t.y===i.y&&t.x<=i.x)&&(r=a,i=t);break}}return r?{distance:i,hitRegion:r}:void 0}function ju(e){return typeof e==`object`&&!!e&&`nodeType`in e&&e.nodeType===Node.DOCUMENT_FRAGMENT_NODE}function Mu(e,t){if(e===t)throw Error(`Cannot compare node with itself`);let n={a:Ru(e),b:Ru(t)},r;for(;n.a.at(-1)===n.b.at(-1);)r=n.a.pop(),n.b.pop();ol(r,`Stacking order can only be calculated for elements with a common ancestor`);let i={a:Lu(Iu(n.a)),b:Lu(Iu(n.b))};if(i.a===i.b){let e=r.childNodes,t={a:n.a.at(-1),b:n.b.at(-1)},i=e.length;for(;i--;){let n=e[i];if(n===t.a)return 1;if(n===t.b)return-1}}return Math.sign(i.a-i.b)}var Nu=/\b(?:position|zIndex|opacity|transform|webkitTransform|mixBlendMode|filter|webkitFilter|isolation)\b/;function Pu(e){let t=getComputedStyle(zu(e)??e).display;return t===`flex`||t===`inline-flex`}function Fu(e){let t=getComputedStyle(e);return!!(t.position===`fixed`||t.zIndex!==`auto`&&(t.position!==`static`||Pu(e))||+t.opacity<1||`transform`in t&&t.transform!==`none`||`webkitTransform`in t&&t.webkitTransform!==`none`||`mixBlendMode`in t&&t.mixBlendMode!==`normal`||`filter`in t&&t.filter!==`none`||`webkitFilter`in t&&t.webkitFilter!==`none`||`isolation`in t&&t.isolation===`isolate`||Nu.test(t.willChange)||t.webkitOverflowScrolling===`touch`)}function Iu(e){let t=e.length;for(;t--;){let n=e[t];if(ol(n,`Missing node`),Fu(n))return n}return null}function Lu(e){return e&&Number(getComputedStyle(e).zIndex)||0}function Ru(e){let t=[];for(;e;)t.push(e),e=zu(e);return t}function zu(e){let{parentNode:t}=e;return ju(t)?t.host:t}function Bu(e,t){return e.x<t.x+t.width&&e.x+e.width>t.x&&e.y<t.y+t.height&&e.y+e.height>t.y}function Vu(e){try{return e.matches(`:modal`)}catch{return!1}}function Hu({axisElement:e,hitRegion:t,pointerEventTarget:n}){if(ql(n)){let t=n.closest(`dialog`);if(t&&!t.contains(e)&&Vu(t))return!1}if(!ql(n)||n.contains(e)||e.contains(n)||!n.isConnected||!e.isConnected)return!0;if(Mu(n,e)>0){let r=n;for(;r;){if(r.contains(e))return!0;if(Bu(r.getBoundingClientRect(),t))return!1;r=r.parentElement}}return!0}function Uu(e,t,n){let r=[];return t.forEach((t,i)=>{if(i.disabled||i.element.ownerDocument!==n)return;let a=Xl({axis:i}),o=Au(i.orientation,a,{x:e.clientX,y:e.clientY});o&&o.distance.x<=0&&o.distance.y<=0&&Hu({axisElement:i.element,hitRegion:o.hitRegion.rect,pointerEventTarget:e.target})&&r.push(o.hitRegion)}),r}function Wu(e){let t=0,n=0,r={};for(let i of e)if(i.defaultSize!==void 0){t++;let e=nu(i.defaultSize);n+=e,r[i.itemId]=e}else r[i.itemId]=void 0;let i=e.length-t;if(i!==0){let t=nu((100-n)/i);for(let n of e)n.defaultSize===void 0&&(r[n.itemId]=t)}return r}function Gu(e,t){let n=e.map(e=>e.id),r=Object.keys(t);if(n.length!==r.length)return!1;for(let e of n)if(!r.includes(e))return!1;return!0}function Ku({axis:e,itemConstraints:t}){let n=e.items.map(({id:e})=>e).join(`,`),r=e.mutableState.defaultLayout;return e.mutableState.layouts[n]??(r&&Gu(e.items,r)?r:Wu(t))}function qu(e,t){if(Object.keys(e).length!==Object.keys(t).length)return!1;for(let n in e)if(e[n]!==t[n])return!1;return!0}function Ju(e,t){return e.length===t.length?e.every((e,n)=>qu(e,t[n])):!1}function Yu({layout:e,itemConstraints:t}){let n=t.map(({itemId:t})=>e[t]),r=[...n],i=r.reduce((e,t)=>e+t,0);if(Object.keys(e).length!==t.length)throw Error(`Invalid ${t.length} panel layout: ${Object.values(e).map(e=>`${e}%`).join(`, `)}`);if(!xu(i,100)&&r.length>0)for(let e=0;e<t.length;e++){let t=r[e];ol(t!=null,`No layout data found for index ${e}`),r[e]=100/i*t}let a=0;for(let e=0;e<t.length;e++){let i=n[e];ol(i!=null,`No layout data found for index ${e}`);let o=r[e];ol(o!=null,`No layout data found for index ${e}`);let s=Cu({overrideDisabledItems:!0,itemConstraints:t[e],prevSize:i,size:o});o!=s&&(a+=o-s,r[e]=s)}if(!xu(a,0))for(let e=0;e<t.length;e++){let n=r[e];ol(n!=null,`No layout data found for index ${e}`);let i=n+a,o=Cu({overrideDisabledItems:!0,itemConstraints:t[e],prevSize:n,size:i});if(n!==o&&(a-=o-n,r[e]=o,xu(a,0)))break}return r.reduce((e,n,r)=>(e[t[r].itemId]=n,e),{})}function Xu({itemIds:e,layout:t}){return Yu({layout:t,itemConstraints:e.map(e=>({collapsedSize:0,collapsible:!1,defaultSize:void 0,disabled:void 0,itemId:e,maxSize:100,minSize:0}))})}function Zu({axis:e,nextAxisSize:t,prevAxisSize:n,prevLayout:r}){if(n<=0||t<=0||n===t)return r;let i=0,a=0,o=!1,s=new Map,c=[];for(let l of e.items){let e=r[l.id]??0;switch(l.constraintProps.groupResizeBehavior){case`preserve-pixel-size`:{o=!0;let r=nu(e/100*n/t*100);s.set(l.id,r),i+=r;break}default:c.push(l.id),a+=e;break}}if(!o||c.length===0)return r;let l=100-i,u={...r};if(s.forEach((e,t)=>{u[t]=e}),a>0)for(let e of c)u[e]=nu((r[e]??0)/a*l);else{let e=nu(l/c.length);for(let t of c)u[t]=e}return u}function Qu({axis:e,axisState:t}){let n=Hl({axis:e});if(n===0)return;let r=ru(e,n),i=t.requestedAxisSize,a=t.requestedLayout;t.defaultLayoutDeferred&&(i=n,a=Xu({itemIds:e.items.map(({id:e})=>e),layout:Ku({axis:e,itemConstraints:r})}));let o=Yu({layout:Zu({axis:e,nextAxisSize:n,prevAxisSize:i,prevLayout:a}),itemConstraints:r});return{changed:t.defaultLayoutDeferred||!Tu(t.layout,o)||!Ju(t.derivedItemConstraints,r)||t.axisSize!==n,state:{defaultLayoutDeferred:!1,derivedItemConstraints:r,axisSize:n,layout:o,requestedAxisSize:i,requestedLayout:a,separatorToItems:t.separatorToItems}}}function $u({axisId:e,itemId:t}){let n=()=>{let t=hu();for(let[n,r]of t)if(n.id===e)return{axis:n,...r};throw Error(`Group ${e} not found`)},r=()=>{let e=n().derivedItemConstraints.find(e=>e.itemId===t);if(e!==void 0)return e;throw Error(`Panel constraints not found for Panel ${t}`)},i=()=>{let{axis:e,...r}=n(),i=Qu({axis:e,axisState:r}),a=i?.state??r,o=a.derivedItemConstraints.find(e=>e.itemId===t);if(o===void 0)throw Error(`Panel constraints not found for Panel ${t}`);let s=a.layout[t];if(s===void 0)throw Error(`Layout not found for Panel ${t}`);return{axis:e,changed:i?.changed===!0,itemConstraints:o,itemSize:s,state:a}},a=()=>{let e=n().axis.items.find(e=>e.id===t);if(e!==void 0)return e;throw Error(`Layout not found for Panel ${t}`)},o=()=>{let e=n().layout[t];if(e!==void 0)return e;throw Error(`Layout not found for Panel ${t}`)},s=({nextSize:e,items:n,prevLayout:r,derivedItemConstraints:i})=>{let a=r[t],o=n.findIndex(e=>e.id===t),s=o===0,c=o===n.length-1;if(c&&e<a&&(s||n.slice(0,o).every((e,t)=>{let n=i[t];return n?.collapsible&&xu(n.collapsedSize,r[n.itemId])}))){let e=n.slice(0,o).reduce((e,t)=>e+r[t.id],0);return{...r,[t]:nu(100-e)}}return wu({delta:c?a-e:e-a,initialLayout:r,itemConstraints:i,pivotIndices:c?[o-1,o]:[o,o+1],prevLayout:r,trigger:`imperative-api`})},c=(e,{axis:t,changed:n,itemSize:r,state:i})=>{if(e===r)return;let{derivedItemConstraints:a,axisSize:o,layout:c}=i,l=Yu({layout:s({nextSize:e,items:t.items,prevLayout:c,derivedItemConstraints:a}),itemConstraints:a});(n||!Tu(c,l))&&_u(t,{...i,layout:l,requestedAxisSize:o,requestedLayout:l})};return{collapse:()=>{let e=i(),{collapsible:t,collapsedSize:n}=e.itemConstraints,{mutableValues:r}=a(),o=e.itemSize;t&&o!==n&&(r.expandToSize=o,c(n,e))},expand:()=>{let e=i(),{collapsible:t,collapsedSize:n,minSize:r}=e.itemConstraints,{mutableValues:o}=a(),s=e.itemSize;if(t&&s===n){let t=o.expandToSize??r;t===0&&(t=1),c(t,e)}},getSize:()=>{let{axis:e}=n(),r=o(),{element:i}=a();return{asPercentage:r,inPixels:e.layoutStrategy?e.layoutStrategy.getItemSizeInPixels(t):e.orientation===`horizontal`?i.offsetWidth:i.offsetHeight}},isCollapsed:()=>{let{collapsible:e,collapsedSize:t}=r(),n=o();return e&&xu(t,n)},resize:e=>{let t=i(),{axisSize:n}=t.state,{element:r}=a();c(nu(tu({axisSize:n,itemElement:r,styleProp:e})/n*100),t)}}}function ed(e){e.defaultPrevented||Uu(e,hu(),e.currentTarget).forEach(t=>{if(t.separator&&!t.separator.disableDoubleClick){let n=t.items.find(e=>e.constraintProps.defaultSize!==void 0);if(n){let r=n.constraintProps.defaultSize,i=$u({axisId:t.axis.id,itemId:n.id});i&&r!==void 0&&(i.resize(r),e.preventDefault())}}})}function td(e){let t=hu();for(let[n]of t)if(n.separators.some(t=>t.element===e))return n;throw Error(`Could not find parent Group for separator element`)}function nd({axisId:e}){let t=()=>{let t=hu();for(let[n,r]of t)if(n.id===e)return{axis:n,...r};throw Error(`Could not find Group with id "${e}"`)};return{getLayout(){let{defaultLayoutDeferred:e,layout:n}=t();return e?{}:n},setLayout(e){let{axis:n,...r}=t(),i=Qu({axis:n,axisState:r}),a=i?.state??r,{defaultLayoutDeferred:o,derivedItemConstraints:s,axisSize:c,layout:l}=a,u=Yu({layout:e,itemConstraints:s});return o?l:((i?.changed||!Tu(l,u))&&_u(n,{...a,layout:u,requestedAxisSize:c,requestedLayout:u}),u)}}}function rd(e,t){let n=td(e),r=mu(n.id,!0),i=n.separators.find(t=>t.element===e);ol(i,`Matching separator not found`);let a=r.separatorToItems.get(i);ol(a,`Matching panels not found`);let o=a.map(e=>n.items.indexOf(e)),s=nd({axisId:n.id}).getLayout(),c=Yu({layout:wu({delta:t,initialLayout:s,itemConstraints:r.derivedItemConstraints,pivotIndices:o,prevLayout:s,trigger:`keyboard`}),itemConstraints:r.derivedItemConstraints});Tu(s,c)||_u(n,{defaultLayoutDeferred:r.defaultLayoutDeferred,derivedItemConstraints:r.derivedItemConstraints,axisSize:r.axisSize,layout:c,requestedAxisSize:r.axisSize,requestedLayout:c,separatorToItems:r.separatorToItems},{isUserInteraction:!0})}function id(e){return e.separators.filter(e=>!e.disabled)}function ad(e){if(e.defaultPrevented)return;let t=e.currentTarget,n=td(t);if(!(n.disabled||n.separators.find(e=>e.element===t)?.disabled))switch(e.key){case`ArrowDown`:e.preventDefault(),n.orientation===`vertical`&&rd(t,5);break;case`ArrowLeft`:e.preventDefault(),n.orientation===`horizontal`&&rd(t,-5);break;case`ArrowRight`:e.preventDefault(),n.orientation===`horizontal`&&rd(t,5);break;case`ArrowUp`:e.preventDefault(),n.orientation===`vertical`&&rd(t,-5);break;case`End`:e.preventDefault(),rd(t,100);break;case`Enter`:{e.preventDefault();let{derivedItemConstraints:r,layout:i,separatorToItems:a}=mu(n.id,!0),o=n.separators.find(e=>e.element===t);ol(o,`Matching separator not found`);let s=a.get(o);ol(s,`Matching panels not found`);let c=s[0],l=r.find(e=>e.itemId===c.id);if(ol(l,`Panel metadata not found`),l.collapsible){let e=i[c.id];rd(t,(l.collapsedSize===e?n.mutableState.expandedItemSizes[c.id]??l.minSize:l.collapsedSize)-e)}break}case`F6`:{e.preventDefault();let t=id(n).map(e=>e.element),r=t.findIndex(t=>t===e.currentTarget);ol(r!==-1,`Index not found`),t[e.shiftKey?r>0?r-1:t.length-1:r+1<t.length?r+1:0].focus({preventScroll:!0});break}case`Home`:e.preventDefault(),rd(t,-100);break}}function od(e,t){let n=xl();if(n.state!==`active`||!yu(n,e,t))return!1;let r=hu();lu();try{n.previewLayoutMap.forEach((e,t)=>{let n=r.get(t);t.resizePreviewMode===`separator`&&n&&!Tu(e,n.layout)&&_u(t,{...n,layout:e,requestedAxisSize:n.axisSize,requestedLayout:e})}),uu(),wl({cursorFlags:0,state:`inactive`}),n.hitRegions.forEach(e=>{if(!r.has(e.axis))return;let t=mu(e.axis.id,!0);_u(e.axis,t,{isUserInteraction:!0})})}finally{du()}return!0}function sd(e){let t=xl();if(t.state!==`active`)return;let n=t.hitRegions.flatMap(({separator:e})=>e?[e.element]:[]);!n.some(t=>t===e.target)||n.some(t=>t.hasPointerCapture?.(e.pointerId))||od(e.currentTarget,e)}function cd(e){od(e.currentTarget,e)}function ld(e,t){let{element:n,orientation:r,items:i}=e,a=n.getBoundingClientRect(),o=r===`horizontal`;return Xl({expandHitTargets:!1,axis:e,includeDisabled:!0}).map(({items:r,rect:s,separator:c},l)=>{let u=i.indexOf(r[0]),d=o?s.left+s.width/2:s.top+s.height/2;return{active:t.some(t=>t.axis!==e||t.items[0]!==r[0]?!1:c||t.separator?t.separator===c:xu(d,o?t.rect.left+t.rect.width/2:t.rect.top+t.rect.height/2)),axis:e,key:c?`separator-${c.id}`:`panel-${r[0].id}-${l}`,offset:0,itemIndex:u,rect:new DOMRect((o&&!c?d:s.left)-a.left-n.clientLeft+n.scrollLeft,(!o&&!c?d:s.top)-a.top-n.clientTop+n.scrollTop,o&&!c?0:s.width,!o&&!c?0:s.height),separator:c}})}function ud(e){if(e.defaultPrevented||e.pointerType===`mouse`&&e.button>0)return;let t=xl();if(t.state===`active`){vu(t,e)&&od(t.ownerDocument,t);return}let n=hu(),r=Uu(e,n,e.currentTarget);if(r.length===0)return;let i=new Map,a=!1;r.forEach(e=>{e.separator&&(a||(a=!0,e.separator.element.focus({focusVisible:!1,preventScroll:!0})));let t=n.get(e.axis);t&&i.set(e.axis,t.layout)});let o=Array.from(i.keys()).flatMap(e=>e.resizePreviewMode===`separator`?ld(e,r):[]);wl({cursorFlags:0,didPointerMove:!1,hitRegions:r,initialLayoutMap:i,ownerDocument:e.currentTarget,pointerDownAtPoint:{x:e.clientX,y:e.clientY},pointerId:e.pointerId,pointerType:e.pointerType,previewLayoutMap:new Map(i),previews:o,state:`active`}),e.preventDefault()}function dd(e){let t=e.currentTarget,n=hu(),r=xl();switch(r.state){case`active`:if(!yu(r,t,e))return;Eu({commit:!1,event:e,hitRegions:r.hitRegions,initialLayoutMap:r.initialLayoutMap,mountedAxes:n,prevCursorFlags:r.cursorFlags})}}function fd(e){if(e.defaultPrevented)return;let t=e.currentTarget,n=xl(),r=hu();switch(n.state){case`active`:if(!yu(n,t,e))return;if(e.buttons===0){od(t,e);return}for(let t of n.hitRegions)if(t.separator){let{element:n}=t.separator;n.isConnected&&!n.hasPointerCapture?.(e.pointerId)&&n.setPointerCapture?.(e.pointerId)}Eu({commit:!1,event:e,hitRegions:n.hitRegions,initialLayoutMap:n.initialLayoutMap,mountedAxes:r,pointerDownAtPoint:n.pointerDownAtPoint,prevCursorFlags:n.cursorFlags});break;default:{let i=Uu(e,r,t);i.length===0?n.state!==`inactive`&&wl({cursorFlags:0,state:`inactive`}):wl({cursorFlags:0,hitRegions:i,ownerDocument:t,state:`hover`});break}}}function pd(e){if(e.relatedTarget instanceof HTMLIFrameElement){let t=xl();switch(t.state){case`hover`:t.ownerDocument===e.currentTarget&&wl({cursorFlags:0,state:`inactive`})}}}function md(e){e.defaultPrevented||e.pointerType===`mouse`&&e.button>0||Ou(e.currentTarget,e)}function hd(e){e.target===e.currentTarget&&od(e.currentTarget.document)}function gd(e){od(e.currentTarget.document)}function _d(e,t,n){if(!n[0])return;let r=e.items.find(e=>e.element===t);if(!r||!r.onResize)return;let i=Hl({axis:e}),a=e.orientation===`horizontal`?r.element.offsetWidth:r.element.offsetHeight,o=r.mutableValues.prevSize,s={asPercentage:nu(a/i*100),inPixels:a};r.mutableValues.prevSize=s,r.onResize(s,r.id,o)}var vd=new Map,yd=!1;function bd(e){let t=!0;ol(e.element.ownerDocument.defaultView,`Cannot register an unmounted Group`);let n=e.element.ownerDocument.defaultView.ResizeObserver,r=new Set,i=new Set,a=new n(n=>{let r;lu();try{for(let i of n){let{borderBoxSize:n,target:a}=i;if(a===e.element){if(t){let t=mu(e.id);if(!t)break;let n=Qu({axis:e,axisState:t});if(!n)break;if(!n.changed)continue;_u(e,n.state)}}else try{_d(e,a,n)}catch(e){r??={error:e}}}}finally{du()}if(r)throw r.error});a.observe(e.element),e.items.forEach(e=>{ol(!r.has(e.id),`Panel ids must be unique; id "${e.id}" was used more than once`),r.add(e.id),e.onResize&&a.observe(e.element)});let o=Hl({axis:e}),s=ru(e,o),c=Ku({axis:e,itemConstraints:s}),l=Yu({layout:c,itemConstraints:s}),u=e.element.ownerDocument,d=u.defaultView;vd.set(u,(vd.get(u)??0)+1);let f=new Map;return Xl({axis:e,includeDisabled:!0}).forEach(e=>{e.separator&&f.set(e.separator,e.items)}),_u(e,{defaultLayoutDeferred:o===0,derivedItemConstraints:s,axisSize:o,layout:l,requestedAxisSize:o,requestedLayout:Xu({itemIds:e.items.map(({id:e})=>e),layout:c}),separatorToItems:f}),e.separators.forEach(e=>{ol(!i.has(e.id),`Separator ids must be unique; id "${e.id}" was used more than once`),i.add(e.id),e.element.addEventListener(`keydown`,ad)}),yd||(yd=!0,Sl(Vl)),vd.get(u)===1&&(u.addEventListener(`contextmenu`,ku,!0),u.addEventListener(`dblclick`,ed,!0),u.addEventListener(`lostpointercapture`,sd,!0),u.addEventListener(`pointercancel`,cd,!0),u.addEventListener(`pointerdown`,ud,!0),u.addEventListener(`pointerleave`,dd),u.addEventListener(`pointermove`,fd),u.addEventListener(`pointerout`,pd),u.addEventListener(`pointerup`,md,!0),d?.addEventListener(`blur`,hd),d?.addEventListener(`pagehide`,gd)),function(){t=!1,vd.set(u,Math.max(0,(vd.get(u)??0)-1)),fu(e),El(e),e.separators.forEach(e=>{e.element.removeEventListener(`keydown`,ad)}),vd.get(u)||(u.removeEventListener(`contextmenu`,ku,!0),u.removeEventListener(`dblclick`,ed,!0),u.removeEventListener(`lostpointercapture`,sd,!0),u.removeEventListener(`pointercancel`,cd,!0),u.removeEventListener(`pointerdown`,ud,!0),u.removeEventListener(`pointerleave`,dd),u.removeEventListener(`pointermove`,fd),u.removeEventListener(`pointerout`,pd),u.removeEventListener(`pointerup`,md,!0),d?.removeEventListener(`blur`,hd),d?.removeEventListener(`pagehide`,gd)),a.disconnect()}}function xd({derivedItemConstraints:e,axis:t,layout:n,prevLayout:r,requestedLayout:i}){let a=t.items.map(({id:e})=>e).join(`,`);t.mutableState.layouts[a]=i,r&&e.forEach(e=>{if(e.collapsible){let i=xu(e.collapsedSize,n[e.itemId]),a=xu(e.collapsedSize,r[e.itemId]);i&&!a&&(t.mutableState.expandedItemSizes[e.itemId]=r[e.itemId])}})}function Sd(){let[e,t]=(0,K.useState)({});return[e,(0,K.useCallback)(()=>t({}),[])]}function Cd(e){let t=(0,K.useRef)({...e});return Xc(()=>{for(let n in e)t.current[n]=e[n]},[e]),t.current}var wd=(0,K.createContext)(null);function Td({layout:e,itemConstraints:t,itemId:n,itemIndex:r}){let i,a,o=e[n],s=t.find(e=>e.itemId===n);if(s){let c=s.maxSize,l=s.collapsible?s.collapsedSize:s.minSize,u=[r,r+1];a=Yu({layout:wu({delta:l-o,initialLayout:e,itemConstraints:t,pivotIndices:u,prevLayout:e}),itemConstraints:t})[n],i=Yu({layout:wu({delta:c-o,initialLayout:e,itemConstraints:t,pivotIndices:u,prevLayout:e}),itemConstraints:t})[n]}return{valueControls:n,valueMax:i,valueMin:a,valueNow:o}}function Ed({attributes:e,axisId:t,axisOrientation:n,children:r,className:i,"data-testid":a,disableCursor:o,disabled:s,disableDoubleClick:c,elementRef:l,id:u,isSharedHitRegion:d,preview:f,registerSeparator:p,requiredStyle:m,style:h,styleDefaults:g,tabIndex:_=0,updateSeparatorProps:v}){let y=Cd({disabled:s,disableDoubleClick:c,children:r,className:i,preview:f,style:h}),[b,x]=(0,K.useState)({}),[S,C]=(0,K.useState)(`inactive`),[w,T]=(0,K.useState)(!1),E=(0,K.useRef)(null),D=(0,K.useRef)(null),O=Qc(E,l),k=n===`horizontal`?`vertical`:`horizontal`;Xc(()=>{let e=E.current;if(e!==null){let n={disabled:y.disabled,disableDoubleClick:y.disableDoubleClick,element:e,id:u,get children(){return y.children},get className(){return y.className},get preview(){return y.preview},get style(){return y.style}};D.current=n;let r=p(n),i=Sl(e=>{C(e.next.state!==`inactive`&&e.next.hitRegions.some(e=>e.separator===n||(d?.(e)??!1))?e.next.state:`inactive`)}),a=gu(t,e=>{let{derivedItemConstraints:t,layout:r,separatorToItems:i}=e.next,a=i.get(n);if(a){let n=a[0],i=t.findIndex(e=>e.itemId===n.id),{layoutStrategy:o}=e.axis;x({...Td({layout:r,itemConstraints:t,itemId:n.id,itemIndex:i}),...o?.getItemAriaControls&&{valueControls:o.getItemAriaControls(n.id)}})}});return()=>{D.current=null,i(),a(),r()}}},[t,u,d,p,y]),Xc(()=>{let e=D.current;e&&Tl(e)},[f]),(0,K.useEffect)(()=>{v(u,{disabled:s,disableDoubleClick:c})},[s,c,u,v]);let A;s&&!o&&(A=`not-allowed`);let j;if(s)j=`disabled`;else switch(S){case`active`:j=`active`;break;default:j=w?`focus`:S}return(0,q.jsx)(`div`,{...e,"aria-controls":b.valueControls,"aria-disabled":s||void 0,"aria-orientation":k,"aria-valuemax":b.valueMax,"aria-valuemin":b.valueMin,"aria-valuenow":b.valueNow,children:r,className:i,"data-separator":j,"data-testid":a,id:u,onBlur:()=>T(!1),onFocus:()=>T(!0),ref:O,role:`separator`,style:{...g,cursor:A,...h,...m,touchAction:`none`},tabIndex:s?void 0:_})}function Dd({axis:e,children:t,className:n,crossSpan:r,crossStart:i,disabled:a,elementRef:o,index:s,style:c}){let l=Yc(void 0),{getDisableCursor:u,getResizeAxisId:d,gutters:f,registerSeparator:p,separatorPlacements:m,trackCounts:h,updateSeparatorProps:g}=cl(),_=d(e),v=e===`column`?`row`:`column`,y=h[v],b=!!a||!al(s,h[e]),x=!0;for(let t of m.values())if(t.axis===e&&t.index===s&&!t.disabled&&t.crossStart<i){x=!1;break}let S=(0,K.useCallback)(e=>e.axis.id===_&&e.axis.items.indexOf(e.items[1])===s,[_,s]),C=(0,K.useCallback)(t=>p({axis:e,crossSpan:r,crossStart:i,disabled:!!a,index:s},t),[e,r,i,a,s,p]),w=rl(s),T=il({crossCount:y,crossSpan:r,crossStart:i,hasGutters:f[v]});return(0,q.jsx)(Ed,{axisId:_,axisOrientation:e===`column`?`horizontal`:`vertical`,className:n,disableCursor:u(),disabled:b,disableDoubleClick:void 0,elementRef:o,id:l,isSharedHitRegion:S,registerSeparator:C,requiredStyle:{gridColumn:e===`column`?w:T,gridRow:e===`row`?w:T},style:c,tabIndex:x?0:-1,updateSeparatorProps:g,children:t})}function Od(e){let{children:t,className:n,disabled:r,elementRef:i,style:a}=e;return e.type===`column`?(0,q.jsx)(Dd,{axis:`column`,className:n,crossSpan:e.rowSpan,crossStart:e.row??0,disabled:r,elementRef:i,index:e.column,style:a,children:t}):(0,q.jsx)(Dd,{axis:`row`,className:n,crossSpan:e.columnSpan,crossStart:e.column??0,disabled:r,elementRef:i,index:e.row,style:a,children:t})}Od.displayName=`Gridline`;var kd=[`column`,`row`],Ad={columns:{},rows:{}};function jd({children:e,className:t,columns:n,defaultLayout:r,disableCursor:i,disabled:a,elementRef:o,gridRef:s,id:c,onLayoutChange:l,onLayoutChanged:u,resizeTargetMinimumSize:d={coarse:20,fine:10},rows:f,style:p,...m}){let h=Yc(c),g=(0,K.useCallback)(e=>e===`column`?`${h}:columns`:`${h}:rows`,[h]),_=Md(n,`columns`),v=Md(f,`rows`),y=e=>e===`column`?_:v,b=(0,K.useRef)({onLayoutChange:Ad,onLayoutChanged:Ad}),x=Zc(e=>{Id(b.current.onLayoutChange,e)||(b.current.onLayoutChange=e,l?.(e))}),S=Zc((e,t,n)=>{Id(b.current.onLayoutChanged,e)||(b.current.onLayoutChanged=e,u?.(e,{isUserInteraction:t,requestedLayout:n}))}),C=(0,K.useRef)(null),w=Qc(C,o),[T,E]=Sd(),D=(0,K.useRef)({cells:[],column:{expandedItemSizes:{},layouts:{}},loggedErrors:new Set,row:{expandedItemSizes:{},layouts:{}},separators:new Map}),O={column:!1,row:!1};for(let e of D.current.separators.values())O[e.axis]=!0;Nd(e,O);let k=Cd({defaultLayout:r,disableCursor:i,resizeTargetMinimumSize:d}),A=Zc(()=>!!k.disableCursor),j=(0,K.useCallback)(e=>{let t=D.current;return t.cells=[...t.cells,e],E(),()=>{t.cells=t.cells.filter(t=>t!==e),E()}},[E]),M=(0,K.useCallback)((e,t)=>{let n=D.current;return n.separators=new Map(n.separators),n.separators.set(t,e),E(),()=>{n.separators=new Map(n.separators),n.separators.delete(t),E()}},[E]),N=(0,K.useCallback)((e,{disabled:t,disableDoubleClick:n})=>{for(let r of D.current.separators.keys())r.id===e&&(r.disabled=t,r.disableDoubleClick=n)},[]),P=D.current.separators,F=(0,K.useMemo)(()=>({getDisableCursor:A,getResizeAxisId:g,gutters:{column:O.column,row:O.row},id:h,registerCell:j,registerSeparator:M,separatorPlacements:P,trackCounts:{column:_.length,row:v.length},updateSeparatorProps:N}),[_.length,A,g,O.column,O.row,h,j,M,v.length,P,N]),I=(0,K.useRef)([]);Xc(()=>{let e=C.current;if(e===null)return;let t=D.current,n=Fd({cells:t.cells,separatorPlacements:t.separators,trackCounts:{column:_.length,row:v.length}});n.forEach(e=>{t.loggedErrors.has(e)||console.error(e)}),t.loggedErrors=new Set(n);let r=e=>Array.from(t.separators.entries()).filter(([,t])=>t.axis===e).sort(([,e],[,t])=>e.index-t.index).map(([e])=>e),i=kd.map(n=>{let i=n===`column`?_:v,o=n===`column`?v:_,s=i.map(e=>e.id),c=g(n),l=r(n),u=l.length>0,d=i.map(({id:t,...n},r)=>({element:e,id:s[r],idIsStable:!0,mutableValues:{expandToSize:void 0,prevSize:void 0},onResize:void 0,constraintProps:n})),f=()=>{let r=[];if(u){for(let[e,a]of t.separators)if(a.axis===n&&al(a.index,i.length)){let t=e.element.getBoundingClientRect();r[a.index]=Math.max(r[a.index]??0,n===`column`?t.width:t.height)}}return gl({axis:n,element:e,gutterSizes:r.filter(e=>e!==void 0),hasGutters:u,layout:mu(c)?.layout,trackIds:s})},p,m=k.defaultLayout?.[n===`column`?`columns`:`rows`];if(m!==void 0&&Object.keys(m).length===s.length){p={};for(let e of s){let t=m[e];t!==void 0&&(p[e]=t)}}return{disabled:!!a,element:e,id:c,layoutStrategy:{getItemAriaControls:e=>{let r=s.indexOf(e);return t.cells.filter(e=>{let t=n===`column`?e.column:e.row,i=n===`column`?e.columnSpan:e.rowSpan;return t<=r&&r<t+i}).map(e=>e.element.id).filter(Boolean).join(` `)||void 0},calculateAvailableSize:()=>f().availableSize,calculateHitRegions:({expandHitTargets:e,axis:r,includeDisabled:i})=>ml({axis:n,cells:t.cells,crossTrackCount:o.length,expandHitTargets:e,resizeAxis:r,axisSize:f().availableSize,includeDisabled:i,separatorPlacements:t.separators}),getItemSizeInPixels:e=>f().trackSizes[s.indexOf(e)]??0},mutableState:{defaultLayout:p,disableCursor:!!k.disableCursor,expandedItemSizes:t[n].expandedItemSizes,layouts:t[n].layouts},orientation:n===`column`?`horizontal`:`vertical`,items:d,resizePreviewMode:`panel`,get resizeTargetMinimumSize(){return k.resizeTargetMinimumSize},separators:l}});I.current=i;let o=i.map(e=>bd(e)),s=()=>{let[e,t]=i.map(e=>mu(e.id));if(!(!e||!t||e.defaultLayoutDeferred||t.defaultLayoutDeferred))return{layout:{columns:e.layout,rows:t.layout},requestedLayout:{columns:e.requestedLayout,rows:t.requestedLayout}}};{let e=s();if(e)try{try{x(e.layout)}finally{S(e.layout,!1,e.requestedLayout)}}catch(e){throw I.current=[],o.forEach(e=>e()),e}}let c=i.map(e=>gu(e.id,t=>{let{defaultLayoutDeferred:n,derivedItemConstraints:r,layout:a,requestedLayout:o}=t.next;if(n||r.length===0)return;xd({derivedItemConstraints:r,axis:e,layout:a,prevLayout:t.prev?.layout,requestedLayout:o});let c=s();if(c){let e=xl(),n=e.state!==`active`||!e.hitRegions.some(e=>i.includes(e.axis));try{x(c.layout)}finally{n&&S(c.layout,t.isUserInteraction,c.requestedLayout)}}}));return()=>{I.current=[],o.forEach(e=>e()),c.forEach(e=>e())}},[_,a,g,h,S,x,v,T,k]),(0,K.useEffect)(()=>{I.current.forEach(e=>{e.mutableState.defaultLayout=r?.[e.orientation===`horizontal`?`columns`:`rows`],e.mutableState.disableCursor=!!i})}),(0,K.useImperativeHandle)(s,()=>{let e=()=>{let[e,t]=kd.map(g);return!pu(e)||!pu(t)?{columns:{},rows:{}}:{columns:nd({axisId:e}).getLayout(),rows:nd({axisId:t}).getLayout()}},t=e=>e.map(e=>`"${e}"`).join(`, `),n=(e,n)=>{let r=g(e),i=()=>{let i=pu(r);return ol(i,`Grid "${h}" has not been mounted`),ol(i.items.some(e=>e.id===n),`Grid "${h}" no longer contains a ${e} with id "${n}"; ${e} ids are ${t(i.items.map(e=>e.id))}`),$u({axisId:r,itemId:n})};return{collapse:()=>i().collapse(),expand:()=>i().expand(),getSize:()=>i().getSize(),isCollapsed:()=>i().isCollapsed(),resize:e=>i().resize(e)}};return{getLayout:e,getTrackById:(e,r)=>{let i=e===`column`?_:v,a=`${r}`;return ol(i.some(e=>e.id===a),`Grid "${h}" does not contain a ${e} with id "${a}"; ${e} ids are ${t(i.map(e=>e.id))}`),n(e,a)},getTrackByIndex:(e,t)=>{let r=e===`column`?_:v,i=Number.isInteger(t)?r[t]:void 0;return ol(i,`Grid "${h}" does not contain a ${e} at index ${t}; it has ${r.length} ${e}s`),n(e,i.id)},setLayout:t=>(kd.forEach(e=>{let n=t[e===`column`?`columns`:`rows`],r=g(e);n&&pu(r)&&nd({axisId:r}).setLayout(n)}),e())}},[_,g,h,v]);let ee=()=>kd.map(e=>{let t=mu(g(e)),n=y(e);return(t&&!t.defaultLayoutDeferred?n.map(e=>`minmax(0, ${t.layout[e.id]??1}fr)`):Pd(n,r?.[e===`column`?`columns`:`rows`])).join(O[e]?` auto `:` `)}).join(`|`),[L,te]=(0,K.useSyncExternalStore)((0,K.useCallback)(e=>{let t=kd.map(t=>gu(g(t),e));return()=>t.forEach(e=>e())},[g]),ee,ee).split(`|`);return(0,q.jsx)(sl.Provider,{value:F,children:(0,q.jsx)(`div`,{...m,className:t,"data-grid":!0,"data-testid":$c(m,c),id:h,ref:w,style:{height:`100%`,width:`100%`,overflow:`hidden`,...p,display:`grid`,gridTemplateColumns:L,gridTemplateRows:te,touchAction:`none`},children:(0,q.jsx)(wd.Provider,{value:null,children:e})})})}jd.displayName=`Grid`;function Md(e,t){let n=JSON.stringify(e);return(0,K.useMemo)(()=>{let r=typeof e==`number`?Array.from({length:e},(e,t)=>({id:`${t}`})):e.map((e,t)=>({...e,id:`${e.id??t}`}));return ol(r.length>0,`Grid must have at least one track; "${t}" is ${n}`),r},[n])}function Nd(e,t){K.Children.forEach(e,e=>{if((0,K.isValidElement)(e))if(e.type===Od){let{type:n}=e.props;n===`column`?t.column=!0:n===`row`&&(t.row=!0)}else typeof e.type==`symbol`&&e.props!==null&&typeof e.props==`object`&&`children`in e.props&&Nd(e.props.children,t)})}function Pd(e,t){if(t)return e.map(e=>`minmax(0, ${t[e.id]??1}fr)`);let n=e.map(e=>e.defaultSize===void 0?void 0:_l(e.defaultSize)),r=100,i=0;return n.forEach(e=>{e===void 0?i++:e[1]===`%`&&(r-=e[0])}),n.map(e=>{if(e===void 0)return`minmax(0, ${Math.max(0,r)/Math.max(1,i)}fr)`;let[t,n]=e;return n===`%`?`minmax(0, ${t}fr)`:`${t}${n}`})}function Fd({cells:e,separatorPlacements:t,trackCounts:n}){let r=[];for(let t of e)kd.forEach(e=>{let[i,a]=e===`column`?[t.column,t.columnSpan]:[t.row,t.rowSpan],o=n[e];(!Number.isInteger(i)||!Number.isInteger(a)||i<0||a<1||i+a>o)&&r.push(`Invalid Cell ${e} placement (${e}: ${i}, ${e}Span: ${a}); Grid has ${o} ${e}s`)});let i=({axis:e,crossSpan:t,crossStart:n,disabled:r,index:i})=>{let a=e===`column`?`row`:`column`,o=`type="${e}" ${e}={${i}}`;return(n!==0||t!==void 0)&&(o+=` ${a}={${n}}`),t!==void 0&&(o+=` ${a}Span={${t}}`),r&&(o+=` disabled`),`<Gridline ${o} />`},a=Array.from(t.values()).filter(e=>{let{axis:t,crossSpan:i,crossStart:a,index:o}=e,s=t===`column`?`row`:`column`,c=n[t],l=n[s],u=!0;return al(o,c)||(r.push(`Invalid ${t} Gridline ${t} (${o}); must be between 1 and ${c-1}`),u=!1),!Number.isInteger(a)||a<0||a>=l?(r.push(`Invalid ${t} Gridline ${s} (${a}); must be between 0 and ${l-1}`),u=!1):i!==void 0&&(!Number.isInteger(i)||i<1||a+i>l)&&(r.push(`Invalid ${t} Gridline ${s}Span (${i}); Grid has ${l} ${s}s`),u=!1),u}),o=e=>{let t=n[e.axis===`column`?`row`:`column`];return[e.crossStart,e.crossSpan===void 0?t:e.crossStart+e.crossSpan]};return a.forEach((t,n)=>{let{axis:s,index:c}=t,[l,u]=o(t);for(let n of e){let[e,a,o,d]=s===`column`?[n.column,n.columnSpan,n.row,n.rowSpan]:[n.row,n.rowSpan,n.column,n.columnSpan];if(e<c&&c<e+a&&o<u&&l<o+d){let n=s===`column`?`row`:`column`;r.push(`${i(t)} overlaps a Cell that spans across it (${s}: ${e}, ${s}Span: ${a}, ${n}: ${o}, ${n}Span: ${d}); use the ${n} and ${n}Span props to render gridlines beside the Cell instead`)}}for(let e of a.slice(n+1))if(e.axis===s&&e.index===c){let[n,a]=o(e);n<u&&l<a&&r.push(`${i(t)} overlaps ${i(e)}`)}}),r}function Id(e,t){return Tu(e.columns,t.columns)&&Tu(e.rows,t.rows)}function Ld(e){for(let t=1;t<e.length;t++)if(Ul(e[t-1],e[t])>0)return!1;return!0}function Rd({separator:e}){let{element:t}=e,n=(0,K.useRef)(null);return Xc(()=>{let e=t.cloneNode(!0),r=[t,...t.querySelectorAll(`*`)],i=[e,...e.querySelectorAll(`*`)],a=t.ownerDocument.defaultView;return r.forEach((e,t)=>{let n=i[t];if(n instanceof a.HTMLElement||n instanceof a.SVGElement){let t=a.getComputedStyle(e);for(let e=0;e<t.length;e++){let r=t.item(e);n.style.setProperty(r,t.getPropertyValue(r))}}n.removeAttribute(`data-testid`),n.removeAttribute(`id`)}),Object.assign(e.style,{boxSizing:`border-box`,height:`100%`,margin:`0`,position:`static`,transform:`none`,width:`100%`}),n.current.appendChild(e),()=>e.remove()},[t]),(0,q.jsx)(`div`,{ref:n,style:{height:`100%`,opacity:.65,pointerEvents:`none`,width:`100%`}})}function zd(){let e=(0,K.useContext)(wd);return ol(e,`Group Context not found; did you render a Panel or Separator outside of a Group?`),e}function Bd(e){let{registerOverlay:t}=zd(),n=(0,K.useRef)(e);qu(n.current,e)||(n.current=e);let r=n.current;return Xc(()=>t(r),[t,r]),null}Bd.displayName=`SeparatorOverlay`;function Vd({active:e,orientation:t,style:n,...r}){let i;switch(t){case`horizontal`:i={height:`100%`,minWidth:`1px`};break;case`vertical`:i={minHeight:`1px`,width:`100%`};break}return(0,q.jsx)(`div`,{...r,"data-separator-overlay":e?`active`:`inactive`,style:{...i,...n,flexShrink:0,pointerEvents:`none`}})}function Hd({overlay:e,preview:t}){let{axis:n,offset:r,rect:i,separator:a}=t,o=n.orientation===`horizontal`,s=a?.preview,c=e;return(0,K.isValidElement)(s)&&s.type===Bd&&(c=s.props,s=void 0),s??(c?s=(0,q.jsx)(Vd,{...c,active:t.active,orientation:n.orientation}):a&&(s=(0,q.jsx)(Rd,{separator:a}))),(0,q.jsx)(`div`,{"aria-hidden":`true`,"data-resize-preview":!0,inert:!0,style:{height:i.height,left:i.left,pointerEvents:`none`,position:`absolute`,top:i.top,transform:o?`translateX(${r}px)`:`translateY(${r}px)`,width:i.width},children:s})}function Ud(e){return Array.from(e).sort(Ul)}function Wd(e,t){let n=(0,K.useRef)({getLayout:()=>({}),setLayout:Dl});(0,K.useImperativeHandle)(t,()=>n.current,[]),Xc(()=>{Object.assign(n.current,nd({axisId:e}))})}function Gd({groupId:e,resizePreviewMode:t}){let[n,r]=(0,K.useState)([]),i=(0,K.useRef)(n);return Xc(()=>{let n=n=>{let a=pu(e),o=t===`separator`&&n.state===`active`?n.previews.filter(e=>e.axis===a&&(e.active||!xu(e.offset,0))):[],s=i.current;s.length===o.length&&o.every((e,t)=>e===s[t])||(i.current=o,r(o))};if(t!==`separator`){n(xl());return}let a=Sl(({next:e})=>n(e));return n(xl()),a},[e,t]),n}function Kd({children:e,className:t,defaultLayout:n,disableCursor:r,disabled:i,elementRef:a,groupRef:o,id:s,onLayoutChange:c,onLayoutChanged:l,orientation:u=`horizontal`,resizePreviewMode:d=`panel`,resizeTargetMinimumSize:f={coarse:20,fine:10},style:p,...m}){let h=(0,K.useRef)({onLayoutChange:{},onLayoutChanged:{}}),g=Zc(e=>{Tu(h.current.onLayoutChange,e)||(h.current.onLayoutChange=e,c?.(e))}),_=Zc((e,t,n)=>{Tu(h.current.onLayoutChanged,e)||(h.current.onLayoutChanged=e,l?.(e,{isUserInteraction:t,requestedLayout:n}))}),v=Yc(s),[y,b]=(0,K.useState)(),x=Gd({groupId:v,resizePreviewMode:d}),S=(0,K.useRef)(null),[C,w]=Sd(),T=(0,K.useRef)([]),E=(0,K.useRef)({lastExpandedPanelSizes:{},layouts:{},panels:[],separators:[]}),D=Qc(S,a);Wd(v,o);let O=Zc((e,t)=>{let r=mu(e);if(r)return{flexGrow:r.layout[t]??1};if(n?.[t])return{flexGrow:n?.[t]}}),k=Cd({defaultLayout:n,disableCursor:r,resizeTargetMinimumSize:f}),A=(0,K.useMemo)(()=>({get disableCursor(){return!!k.disableCursor},getPanelStyles:O,id:v,orientation:u,registerPanel:e=>{let t=E.current;return t.panels=Wl(u,[...t.panels,e]),w(),()=>{t.panels=t.panels.filter(t=>t!==e),w()}},registerOverlay:e=>(b(e),()=>{b(void 0)}),registerSeparator:e=>{let t=E.current;return t.separators=Wl(u,[...t.separators,e]),w(),()=>{t.separators=t.separators.filter(t=>t!==e),w()}},updatePanelProps:(e,{disabled:t})=>{let n=E.current.panels.find(t=>t.id===e);if(!n||n.constraintProps.disabled===t)return;n.constraintProps.disabled=t;let r=pu(v),i=mu(v);r&&i&&_u(r,{...i,derivedItemConstraints:ru(r)})},updateSeparatorProps:(e,{disabled:t,disableDoubleClick:n})=>{let r=E.current.separators.find(t=>t.id===e);r&&(r.disabled=t,r.disableDoubleClick=n)}}),[O,v,w,u,k]),j=(0,K.useRef)(null);return Xc(()=>{let e=S.current;if(e===null)return;let t=E.current;t.panels=Wl(u,t.panels),t.separators=Wl(u,t.separators),T.current=Ud([...t.panels.map(({element:e})=>e),...t.separators.map(({element:e})=>e)]);let n;if(k.defaultLayout!==void 0&&Object.keys(k.defaultLayout).length===t.panels.length){n={};for(let e of t.panels){let t=k.defaultLayout[e.id];t!==void 0&&(n[e.id]=t)}}let r={disabled:!!i,element:e,id:v,mutableState:{defaultLayout:n,disableCursor:!!k.disableCursor,expandedItemSizes:E.current.lastExpandedPanelSizes,layouts:E.current.layouts},orientation:u,items:t.panels,resizePreviewMode:d,get resizeTargetMinimumSize(){return k.resizeTargetMinimumSize},separators:t.separators};j.current=r;let a=bd(r),{defaultLayoutDeferred:o,derivedItemConstraints:s,layout:c,requestedLayout:l}=mu(r.id,!0);if(!o&&s.length>0)try{try{g(c)}finally{_(c,!1,l)}}catch(e){throw j.current=null,a(),e}let f=gu(v,e=>{let{defaultLayoutDeferred:t,derivedItemConstraints:n,layout:i,requestedLayout:a}=e.next;if(t||n.length===0)return;xd({derivedItemConstraints:n,axis:r,layout:i,prevLayout:e.prev?.layout,requestedLayout:a});let o=xl(),s=o.state!==`active`||!o.hitRegions.some(e=>e.axis===r);try{g(i)}finally{s&&_(i,e.isUserInteraction,a)}});return()=>{j.current=null,a(),f()}},[i,v,_,g,u,C,d,k]),Xc(()=>{Ld(T.current)||w()}),(0,K.useEffect)(()=>{let e=j.current;e&&(e.mutableState.defaultLayout=n,e.mutableState.disableCursor=!!r)}),(0,q.jsx)(wd.Provider,{value:A,children:(0,q.jsxs)(`div`,{...m,className:t,"data-group":!0,"data-testid":$c(m,s),id:v,ref:D,style:{height:`100%`,width:`100%`,overflow:`hidden`,position:d===`separator`?`relative`:void 0,...p,display:`flex`,flexDirection:u===`horizontal`?`row`:`column`,flexWrap:`nowrap`,touchAction:u===`horizontal`?`pan-y`:`pan-x`},children:[e,x.map(e=>(0,q.jsx)(Hd,{overlay:y,preview:e},e.key))]})})}Kd.displayName=`Group`;function qd(){return(0,K.useRef)(null)}function Jd(e,t){let{id:n}=zd(),r=(0,K.useRef)({collapse:Ol,expand:Ol,getSize:()=>({asPercentage:0,inPixels:0}),isCollapsed:()=>!1,resize:Ol});(0,K.useImperativeHandle)(t,()=>r.current,[]),Xc(()=>{Object.assign(r.current,$u({axisId:n,itemId:e}))})}function Yd({children:e,className:t,collapsedSize:n=`0%`,collapsedThreshold:r,collapsible:i=!1,defaultSize:a,disabled:o,elementRef:s,groupResizeBehavior:c=`preserve-relative-size`,id:l,maxSize:u=`100%`,minSize:d=`0%`,onResize:f,panelRef:p,style:m,...h}){let g=Jc(l),_=Yc(l),v=Cd({disabled:o}),y=(0,K.useRef)(null),b=Qc(y,s),{getPanelStyles:x,id:S,orientation:C,registerPanel:w,updatePanelProps:T}=zd(),E=f!==null,D=Zc((e,t,n)=>{f?.(e,l,n)});Xc(()=>{let e=y.current;if(e!==null)return w({element:e,id:_,idIsStable:g,mutableValues:{expandToSize:void 0,prevSize:void 0},onResize:E?D:void 0,constraintProps:{groupResizeBehavior:c,collapsedSize:n,collapsedThreshold:r,collapsible:i,defaultSize:a,disabled:v.disabled,maxSize:u,minSize:d}})},[c,n,r,i,a,E,_,g,u,d,D,w,v]),(0,K.useEffect)(()=>{T(_,{disabled:o})},[o,_,T]),Jd(_,p);let O=()=>{let e=x(S,_);if(e)return JSON.stringify(e)},k=(0,K.useSyncExternalStore)(e=>gu(S,e),O,O),A;return A=k?JSON.parse(k):a===void 0?{flexGrow:1}:{flexGrow:void 0,flexShrink:void 0,flexBasis:a},(0,q.jsx)(`div`,{...h,"data-disabled":o||void 0,"data-panel":!0,"data-testid":$c(h,l),id:_,ref:b,style:{...Xd,display:`flex`,flexBasis:0,flexShrink:1,overflow:`visible`,...A},children:(0,q.jsx)(`div`,{className:t,style:{maxHeight:`100%`,maxWidth:`100%`,flexGrow:1,overflow:`auto`,...m,touchAction:C===`horizontal`?`pan-y`:`pan-x`},children:e})})}Yd.displayName=`Panel`;var Xd={minHeight:0,maxHeight:`100%`,height:`auto`,minWidth:0,maxWidth:`100%`,width:`auto`,border:`none`,borderWidth:0,padding:0,margin:0},Zd={flexBasis:`auto`},Qd={flexGrow:0,flexShrink:0};function $d({children:e,className:t,disabled:n,disableDoubleClick:r,elementRef:i,id:a,preview:o,style:s,...c}){let l=Yc(a),{disableCursor:u,id:d,orientation:f,registerSeparator:p,updateSeparatorProps:m}=zd();return(0,q.jsx)(Ed,{attributes:c,axisId:d,axisOrientation:f,className:t,"data-testid":$c(c,a),disableCursor:u,disabled:n,disableDoubleClick:r,elementRef:i,id:l,preview:o,registerSeparator:p,requiredStyle:Qd,style:s,styleDefaults:Zd,updateSeparatorProps:m,children:e})}$d.displayName=`Separator`;function ef(e){let[t,n]=(0,K.useState)(()=>typeof window<`u`?window.matchMedia(e).matches:!1);return(0,K.useEffect)(()=>{if(typeof window>`u`)return;let t=window.matchMedia(e);n(t.matches);let r=e=>{n(e.matches)};return t.addEventListener?t.addEventListener(`change`,r):t.addListener(r),()=>{t.removeEventListener?t.removeEventListener(`change`,r):t.removeListener(r)}},[e]),t}function tf(){return ef(`(max-width: 768px)`)}function nf(){return ef(`(min-width: 1280px)`)}function rf({className:e,...t}){return(0,q.jsxs)($d,{disableDoubleClick:!0,...t,className:G(`group relative z-30 w-px cursor-col-resize bg-border outline-none focus-visible:bg-primary focus-visible:ring-2 focus-visible:ring-ring`,e),children:[(0,q.jsx)(`span`,{className:`absolute inset-y-0 -left-1.5 -right-1.5`}),(0,q.jsx)(`span`,{className:`absolute inset-y-0 -left-px -right-px bg-primary opacity-0 transition-opacity group-hover:opacity-100 group-active:opacity-100`})]})}function af({sidebar:e,children:t,workbench:n,sidebarCollapsed:r,workbenchDocked:i,sidebarWidth:a,workbenchWidth:o,workbenchMaxWidth:s,viewportWidth:c,suspended:l,scopeKey:d}){u();let p=ef(`(min-width: 768px)`)&&!r,m=qd(),h=(0,K.useRef)(null),g=(0,K.useRef)(null),_=(0,K.useCallback)(e=>{h.current===e&&(h.current=null,m.current?.setLayout(e.layout))},[m]),v=(0,K.useCallback)(()=>{let e=h.current;!e||e.pointerId===null||e.cancelled||(e.cancelled=!0,g.current?.dispatchEvent(new PointerEvent(`pointercancel`,{bubbles:!0,pointerId:e.pointerId})),_(e))},[_]);(0,K.useEffect)(()=>{let e=e=>{let t=h.current;!t||t.pointerId!==e.pointerId||t.cancelled||e.type===`lostpointercapture`&&(!(e.target instanceof HTMLElement)||e.target.dataset.resizePanel!==t.side)||(t.cancelled=!0)},t=e=>{let t=h.current;t?.cancelled&&t.pointerId===e.pointerId&&_(t)},n=e=>{e.target===window&&v()},r=e=>{e.key===`Escape`&&h.current?.pointerId!=null&&(e.preventDefault(),v())},i=e=>{h.current?.pointerId===e.pointerId&&(h.current=null)};return window.addEventListener(`pointercancel`,e,!0),window.addEventListener(`pointercancel`,t),window.addEventListener(`lostpointercapture`,e,!0),window.addEventListener(`lostpointercapture`,t),window.addEventListener(`blur`,n,!0),window.addEventListener(`pagehide`,v,!0),window.addEventListener(`keydown`,r,!0),window.addEventListener(`pointerup`,i),()=>{h.current=null,window.removeEventListener(`pointercancel`,e,!0),window.removeEventListener(`pointercancel`,t),window.removeEventListener(`lostpointercapture`,e,!0),window.removeEventListener(`lostpointercapture`,t),window.removeEventListener(`blur`,n,!0),window.removeEventListener(`pagehide`,v,!0),window.removeEventListener(`keydown`,r,!0),window.removeEventListener(`pointerup`,i)}},[v,_]),(0,K.useLayoutEffect)(()=>{if(v(),l)return;let e=!0;return queueMicrotask(()=>{if(!e)return;let t=g.current?g.current.getBoundingClientRect().width-Number(p)-Number(i):0;if(t<=0)return;let n=p?a.width/t*100:0,r=i?o.width/t*100:0;m.current?.setLayout({"sidebar-panel":n,"chat-panel":100-n-r,"workbench-panel":r})}),()=>{e=!1}},[v,p,i,a.width,o.width,s,c,l,d,m]);let y=(e,t)=>{if(l||!(e instanceof HTMLElement))return!1;let n=e.closest(`[data-resize-panel]`)?.dataset.resizePanel,r=m.current?.getLayout();return!n||!r?!1:(h.current={side:n,pointerId:t,layout:r,cancelled:!1},!0)};return(0,q.jsxs)(Kd,{id:`chat-panels`,groupRef:m,elementRef:g,className:`min-h-0 min-w-0 flex-1 touch-auto!`,disabled:l,resizeTargetMinimumSize:{fine:12,coarse:28},onLayoutChanged:(e,t)=>{let n=h.current,r=g.current;if(!t.isUserInteraction||!n||n.cancelled||l||!r)return;let i=[...r.children].filter(e=>e.hasAttribute(`data-separator`)),s=r.getBoundingClientRect().width-i.reduce((e,t)=>e+t.getBoundingClientRect().width,0),c=Math.round(e[`${n.side}-panel`]/100*s*1e3)/1e3,u=n.side===`sidebar`?a:o;h.current=null,c&&u.setWidth(c)},onPointerDownCapture:e=>{e.pointerType===`mouse`&&e.button!==0||h.current?.pointerId!=null&&h.current.pointerId!==e.pointerId||y(e.target,e.pointerId)||y(document.activeElement,e.pointerId)},onKeyDownCapture:e=>{[`ArrowLeft`,`ArrowRight`,`Home`,`End`].includes(e.key)&&y(e.target,null)},children:[(0,q.jsx)(Yd,{id:`sidebar-panel`,minSize:p?220:0,maxSize:p?420:0,defaultSize:p?a.width:0,style:{overflow:`visible`},className:`flex min-h-0 min-w-0 touch-auto!`,children:e}),p?(0,q.jsx)(rf,{id:`sidebar-resize`,"data-resize-panel":`sidebar`,"aria-label":f(`resize_sidebar`),disabled:l}):null,(0,q.jsx)(Yd,{id:`chat-panel`,minSize:p?360:0,className:`flex min-h-0 min-w-0 touch-auto!`,style:{overflow:`hidden`},children:t}),i?(0,q.jsx)(rf,{id:`workbench-resize`,"data-resize-panel":`workbench`,"aria-label":f(`resize_workbench`),disabled:l}):null,(0,q.jsx)(Yd,{id:`workbench-panel`,minSize:i?360:0,maxSize:i?s:0,defaultSize:i?o.width:0,style:{overflow:`visible`},className:`flex min-h-0 min-w-0 touch-auto!`,children:n})]})}var of=`lotus-next.session-read.v1`,sf={};function cf(e){let t=Date.parse(e.lastActivityAt??``),n=e.messageCount??e.messages?.length??0;return{at:Number.isFinite(t)?t:0,count:Number.isFinite(n)?Math.max(0,n):0}}function lf(e){try{let t=JSON.parse(e??`null`);return!t||typeof t!=`object`||Array.isArray(t)?{}:Object.fromEntries(Object.entries(t).filter(([e,t])=>e&&t&&[t.at,t.count,t.readAt].every(e=>typeof e==`number`&&Number.isFinite(e)&&e>=0)).sort((e,t)=>t[1].readAt-e[1].readAt).slice(0,2e3))}catch{return{}}}function uf(e,t){let n=cf(e);if(n.count===0)return!1;let r=Object.hasOwn(t,e.id)?t[e.id]:void 0;return!r||n.count>r.count||n.at>r.at}function df(e,t,n=Date.now()){let r=cf(t),i=Object.hasOwn(e,t.id)?e[t.id]:void 0;if(i&&i.at>=r.at&&i.count>=r.count)return e;let a={at:Math.max(r.at,i?.at??0),count:Math.max(r.count,i?.count??0),readAt:n};return Object.fromEntries(Object.entries({...e,[t.id]:a}).sort((e,t)=>t[1].readAt-e[1].readAt).slice(0,2e3))}function ff(){try{return lf(localStorage.getItem(of))}catch{return{}}}var pf=ff(),mf=new Set;function hf(e){if(e!==pf){pf=e;for(let e of mf)e()}}function gf(e){(e.key===of||e.key===null)&&hf(ff())}function _f(e){return mf.add(e),mf.size===1&&window.addEventListener(`storage`,gf),()=>{mf.delete(e),mf.size||window.removeEventListener(`storage`,gf)}}function vf(){return(0,K.useSyncExternalStore)(_f,()=>pf,()=>sf)}function yf(e){(0,K.useEffect)(()=>{if(!e)return;let t=()=>{if(document.visibilityState===`hidden`)return;let t=df(pf,e);if(t!==pf){hf(t);try{localStorage.setItem(of,JSON.stringify(t))}catch{}}};return t(),document.addEventListener(`visibilitychange`,t),()=>document.removeEventListener(`visibilitychange`,t)},[e])}function bf(e=!1){let[t,n]=(0,K.useState)(!1),r=(0,K.useRef)(null),i=t=>{if(e||!t.currentTarget.contains(t.target))return;let i=t.target;i.closest(`input, textarea, [contenteditable="true"], [role="menu"]`)||(t.preventDefault(),t.stopPropagation(),r.current=i.closest(`button:not(:disabled), [tabindex]`)??t.currentTarget.querySelector(`button:not(:disabled), [tabindex]`),n(!0))};return{open:t,onOpenChange:n,rowProps:{onContextMenu:e=>i(e),onKeyDown:e=>{(e.key===`ContextMenu`||e.shiftKey&&e.key===`F10`)&&i(e)}},onCloseAutoFocus:e=>{r.current?.isConnected&&(e.preventDefault(),r.current.focus()),r.current=null}}}var xf=(0,K.lazy)(async()=>({default:(await o(async()=>{let{SupervisorManagedSessionsDialog:e}=await import(`./SupervisorManagedSessions-DDL1goCC.js`);return{SupervisorManagedSessionsDialog:e}},__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21]),import.meta.url)).SupervisorManagedSessionsDialog}));function Sf({chat:e,active:t,unread:n,busy:r,running:i,disabled:a,onSelect:o,onRename:c}){let l=s(),u=bf(a),d=(0,K.useId)(),f=(0,K.useId)(),p=(0,K.useId)(),m=(0,K.useId)(),[h,g]=(0,K.useState)(!1),[_,v]=(0,K.useState)(!1),[y,b]=(0,K.useState)(!1),[x,S]=(0,K.useState)(!1),C=(0,K.useRef)(null),[w,T]=(0,K.useState)(``),[E,O]=(0,K.useState)(!1),[k,A]=(0,K.useState)(!1),M=e?.title?.trim()||`Supervisor`,N=i??e?.isRunning===!0,F=!!e&&!N&&e.lastRunStatus===`error`,I=F?e.lastRunError?.trim()||l(`session_last_run_failed_hint`):null,ee=async()=>{let t=w.trim();if(!(!e||!t||E)){if(t===M){g(!1);return}O(!0),A(!1);try{await c(e.id,t),g(!1)}catch{A(!0)}finally{O(!1)}}};return(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)($t,{open:h,onOpenChange:e=>{E||g(e)},children:(0,q.jsxs)(`div`,{className:`mb-2`,children:[(0,q.jsxs)(`div`,{...u.rowProps,className:G(`flex select-none items-center rounded-md`,t&&`bg-sidebar-accent`),children:[(0,q.jsxs)(W,{variant:`ghost`,"aria-current":t?`page`:void 0,"aria-describedby":F?`${d} ${f} ${p}`:`${d} ${f}`,"aria-busy":r||void 0,disabled:a,className:G(`min-w-0 flex-1 justify-start gap-2`,n&&`font-semibold`),onClick:o,children:[(0,q.jsx)(lr,{className:`size-4 shrink-0`,"aria-hidden":`true`}),(0,q.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-left`,title:M,children:M}),N?(0,q.jsx)(`span`,{"data-session-running":``,"aria-hidden":`true`,className:`size-1.5 shrink-0 animate-pulse rounded-full bg-primary`}):F?(0,q.jsx)(`span`,{title:I??void 0,"data-session-run-failure":``,"aria-hidden":`true`,className:`shrink-0`,children:(0,q.jsx)(P,{className:`size-3.5 text-destructive`})}):n?(0,q.jsx)(`span`,{"aria-hidden":`true`,className:`size-1.5 shrink-0 rounded-full bg-primary`}):null,(0,q.jsx)(`span`,{id:f,className:`sr-only`,children:N?l(`running_1f0eb99b`):n?l(`unread_messages_519491f4`):``}),F?(0,q.jsx)(`span`,{id:p,className:`sr-only`,children:l(`session_last_run_failed_hint`)}):null]}),(0,q.jsx)(Qt,{asChild:!0,children:(0,q.jsx)(W,{variant:`ghost`,size:`icon`,className:`mr-1 size-8 shrink-0 text-muted-foreground`,"aria-label":l(`supervisor_rename`),title:l(`supervisor_rename`),disabled:!e||a,onClick:()=>{T(M),A(!1)},children:(0,q.jsx)(j,{className:`size-3.5`,"aria-hidden":`true`})})}),(0,q.jsxs)(ke,{open:u.open,onOpenChange:u.onOpenChange,children:[(0,q.jsx)(V,{ref:C,"aria-label":l(`session_actions_e6f6d875`),disabled:a,className:`mr-1 rounded p-1 text-muted-foreground outline-none hover:bg-accent focus-visible:ring-2 focus-visible:ring-ring`,children:(0,q.jsx)(Xn,{className:`size-4`})}),(0,q.jsxs)(z,{align:`end`,onCloseAutoFocus:h||_||y||x?e=>e.preventDefault():u.onCloseAutoFocus,children:[(0,q.jsxs)(B,{disabled:!e,onSelect:()=>{T(M),A(!1),g(!0)},children:[(0,q.jsx)(j,{}),l(`supervisor_rename`)]}),(0,q.jsx)(B,{onSelect:()=>b(!0),children:l(`supervisor_sessions_manage`)}),(0,q.jsx)(B,{onSelect:()=>v(!0),children:l(`supervisor_scope_title`)}),(0,q.jsxs)(B,{variant:`destructive`,disabled:!e,onSelect:()=>S(!0),children:[(0,q.jsx)(ce,{}),l(`conversation_clear_action`)]})]})]})]}),(0,q.jsx)(`p`,{id:d,className:`px-3 pb-1 text-xs leading-relaxed text-muted-foreground`,children:l(`supervisor_entry_description`)}),(0,q.jsx)(Yt,{showCloseButton:!E,children:(0,q.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),ee()},className:`grid gap-4`,children:[(0,q.jsxs)(qt,{children:[(0,q.jsx)(Xt,{children:l(`supervisor_rename`)}),(0,q.jsx)(Zt,{children:l(`supervisor_rename_description`)})]}),(0,q.jsx)(`label`,{htmlFor:m,className:`text-sm font-medium`,children:l(`supervisor_name`)}),(0,q.jsx)(fe,{id:m,value:w,disabled:E,onChange:e=>T(e.target.value),onFocus:e=>e.target.select()}),k?(0,q.jsx)(`p`,{role:`alert`,className:`text-sm text-destructive`,children:l(`could_not_save_please_try_again_f42a1238`)}):null,(0,q.jsxs)(Jt,{children:[(0,q.jsx)(W,{type:`button`,variant:`outline`,disabled:E,onClick:()=>g(!1),children:l(`cancel_2cd0f3be`)}),(0,q.jsx)(W,{type:`submit`,disabled:E||!w.trim(),children:l(`save_a3030bf8`)})]})]})})]})}),y?(0,q.jsx)(ue,{name:`Supervisor sessions`,fallback:()=>(0,q.jsx)($t,{open:!0,onOpenChange:b,children:(0,q.jsx)(Yt,{onCloseAutoFocus:e=>{e.preventDefault(),C.current?.focus()},children:(0,q.jsxs)(qt,{children:[(0,q.jsx)(Xt,{children:l(`supervisor_sessions_title`)}),(0,q.jsx)(Zt,{children:l(`supervisor_sessions_unavailable`)})]})})}),children:(0,q.jsx)(K.Suspense,{fallback:(0,q.jsx)($t,{open:!0,onOpenChange:b,children:(0,q.jsx)(Yt,{onCloseAutoFocus:e=>{e.preventDefault(),C.current?.focus()},children:(0,q.jsxs)(qt,{children:[(0,q.jsx)(Xt,{children:l(`supervisor_sessions_title`)}),(0,q.jsx)(Zt,{children:l(`supervisor_sessions_loading`)})]})})}),children:(0,q.jsx)(xf,{open:!0,onOpenChange:b,returnFocus:()=>C.current?.focus()})})}):null,_?(0,q.jsx)(jn,{open:!0,onOpenChange:v,returnFocus:()=>C.current?.focus()}):null,x&&e?(0,q.jsx)(D,{sessionId:e.id,title:M,onClose:()=>{S(!1),C.current?.focus()}}):null]})}function Cf({merge:e,running:t}){let n=e.state===`merged`,r=e.state===`in_progress`,i=n?`text-primary`:r?`text-amber-500`:`text-muted-foreground`,a=f(`worktree_state_${e.state}`,e.baseRef?{base:e.baseRef}:void 0);return(0,q.jsxs)(`span`,{role:`img`,"aria-label":a,title:a,"data-worktree-state":e.state,className:`relative flex size-4 shrink-0 items-center justify-center ${i}`,children:[n?(0,q.jsx)(Dr,{className:`size-3`,"aria-hidden":`true`}):(0,q.jsx)(Me,{className:`size-3`,"aria-hidden":`true`}),r?(0,q.jsx)(`span`,{"aria-hidden":`true`,className:`absolute right-0 top-0 size-1 rounded-full bg-amber-500${t?` animate-pulse`:``}`}):null]})}function wf({chat:e,active:t,unread:n=!1,running:r,onSelect:i,onRename:a,onDelete:o,onTogglePin:s,onCopySessionId:c,projectId:l,sections:d=[],sectionId:p=null,onMoveToSection:m,dragHandle:h,mergeState:g}){u();let _=bf(),v=(0,K.useRef)(null),y=(0,K.useRef)(!1),b=(0,K.useRef)(!1),[x,S]=(0,K.useState)(!1),[C,w]=(0,K.useState)(!1),[T,E]=(0,K.useState)(e.title??``),O=(0,K.useRef)(null),k=(0,K.useId)(),A=r??e.isRunning===!0,N=(0,K.useId)(),F=!A&&e.lastRunStatus===`error`,I=F?e.lastRunError?.trim()||f(`session_last_run_failed_hint`):null,ee=[n?k:null,F?N:null].filter(Boolean).join(` `)||void 0;(0,K.useEffect)(()=>{x&&(E(e.title??``),requestAnimationFrame(()=>{O.current?.focus(),O.current?.select()}))},[x,e.title]);let L=()=>{let t=T.trim();S(!1),t&&t!==(e.title??``)&&a(t)};return x?(0,q.jsx)(`div`,{className:`mb-0.5 px-2 py-1`,children:(0,q.jsx)(`input`,{ref:O,value:T,onChange:e=>E(e.target.value),onKeyDown:e=>{e.key===`Enter`&&L(),e.key===`Escape`&&S(!1)},onBlur:L,className:`w-full rounded-md border bg-background px-2 py-1.5 text-sm outline-none focus-visible:ring-2 focus-visible:ring-ring`})}):(0,q.jsxs)(q.Fragment,{children:[(0,q.jsxs)(`div`,{..._.rowProps,"data-sidebar-session":e.id,"data-session-project":l,draggable:!0,onPointerDownCapture:e=>{y.current=!1,b.current=e.target instanceof Element&&!!e.target.closest(`[data-sidebar-drag-handle]`)},onDragStart:t=>{if(b.current){t.preventDefault();return}y.current=!0,t.dataTransfer.setData(Tn,JSON.stringify({projectId:l??null,sessionId:e.id})),t.dataTransfer.effectAllowed=`copyMove`},style:t?{boxShadow:`inset 0 0 0 1px var(--border)`}:void 0,className:G(`group/row relative mb-0.5 flex select-none items-center rounded-md feedback-motion switch-feedback hover:bg-sidebar-accent`,t&&`bg-sidebar-accent`),children:[(0,q.jsxs)(`button`,{type:`button`,"aria-current":t?`page`:void 0,onClick:e=>{if(y.current&&e.detail!==0){e.preventDefault();return}i()},"aria-describedby":ee,className:G(`flex min-w-0 flex-1 items-center gap-2 py-2 pl-2 pr-1 text-left text-sm rounded-md outline-none focus-visible:ring-2 focus-visible:ring-ring`,(t||n)&&`font-medium`),children:[(0,q.jsx)(`span`,{title:I??void 0,"data-session-run-failure":F?``:void 0,className:`flex size-3.5 shrink-0 items-center justify-center`,children:A?(0,q.jsx)(`span`,{"data-session-running":``,role:`img`,"aria-label":f(`running_1f0eb99b`),title:f(`running_1f0eb99b`),className:`size-1.5 animate-pulse rounded-full bg-primary`}):F?(0,q.jsx)(P,{"aria-hidden":`true`,className:`size-3.5 text-destructive`}):n?(0,q.jsx)(`span`,{"aria-hidden":`true`,title:f(`new_messages_ce3b9bb1`),className:`size-1.5 rounded-full bg-primary`}):null}),(0,q.jsx)(`span`,{className:`truncate`,children:e.title||f(`new_session_c57c30bc`)})]}),g?(0,q.jsx)(`span`,{className:g.state===`merged`||g.state===`in_progress`?void 0:`opacity-0 group-hover:opacity-100 group-focus-within:opacity-100 transition-opacity`,children:(0,q.jsx)(Cf,{merge:g,running:A})}):null,h,n&&(0,q.jsx)(`span`,{id:k,className:`sr-only`,children:f(`unread_messages_519491f4`)}),F&&(0,q.jsx)(`span`,{id:N,className:`sr-only`,children:f(`session_last_run_failed_hint`)}),(0,q.jsxs)(ke,{open:_.open,onOpenChange:_.onOpenChange,children:[(0,q.jsx)(V,{ref:v,"aria-label":f(`session_actions_e6f6d875`),style:t?{opacity:1}:void 0,className:G(`mr-1 shrink-0 rounded p-1 text-muted-foreground outline-none feedback-motion transition-opacity hover:bg-accent focus-visible:ring-2 focus-visible:ring-ring hover:text-foreground`,`opacity-100 data-[state=open]:opacity-100 focus-within:opacity-100 md:opacity-0 md:group-hover/row:opacity-100 md:group-focus-within/row:opacity-100`),children:(0,q.jsx)(Xn,{className:`size-4`})}),(0,q.jsxs)(z,{onCloseAutoFocus:C?e=>e.preventDefault():_.onCloseAutoFocus,align:`end`,className:`min-w-32 rounded-xl`,children:[l&&m?(0,q.jsxs)(Oe,{children:[(0,q.jsxs)(Ee,{className:`gap-2 rounded-lg px-2.5 py-1.5`,children:[(0,q.jsx)(jr,{className:`size-3.5`}),f(`sidebar_move_to_section`)]}),(0,q.jsxs)(Te,{"aria-label":f(`sidebar_section_select_target`),children:[d.map(e=>(0,q.jsxs)(B,{onClick:()=>m(e.id),disabled:e.id===p,children:[e.id===p?(0,q.jsx)(de,{}):(0,q.jsx)(jr,{}),e.name]},e.id)),(0,q.jsxs)(B,{onClick:()=>m(null),disabled:p===null,children:[p===null?(0,q.jsx)(de,{}):(0,q.jsx)(jr,{}),f(`sidebar_no_section`)]})]})]}):null,(0,q.jsx)(B,{onClick:s,className:`gap-2 rounded-lg px-2.5 py-1.5`,children:e.pinned?(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(Lr,{className:`size-3.5`}),f(`unpin_c92179b7`)]}):(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(Rr,{className:`size-3.5`}),f(`pin_173f88d2`)]})}),(0,q.jsxs)(B,{onClick:()=>S(!0),className:`gap-2 rounded-lg px-2.5 py-1.5`,children:[(0,q.jsx)(j,{className:`size-3.5`}),f(`rename_0d0cbac2`)]}),(0,q.jsxs)(B,{onClick:()=>{zt.regenerateSessionTitle(e.id).catch(()=>{})},className:`gap-2 rounded-lg px-2.5 py-1.5`,children:[(0,q.jsx)($n,{className:`size-3.5`}),f(`generate_title_with_ai_f327dbdd`)]}),(0,q.jsxs)(B,{onClick:c,className:`gap-2 rounded-lg px-2.5 py-1.5`,children:[(0,q.jsx)(Ae,{className:`size-3.5`}),f(`copy_session_id_7df96a6b`)]}),(0,q.jsxs)(B,{variant:`destructive`,onSelect:()=>w(!0),className:`gap-2 rounded-lg px-2.5 py-1.5`,children:[(0,q.jsx)(ce,{className:`size-3.5`}),f(`conversation_clear_action`)]}),(0,q.jsxs)(B,{variant:`destructive`,onClick:o,className:`gap-2 rounded-lg px-2.5 py-1.5`,children:[(0,q.jsx)(M,{className:`size-3.5`}),f(`delete_2f9daa82`)]})]})]})]}),C?(0,q.jsx)(D,{sessionId:e.id,title:e.title||e.id,onClose:()=>{w(!1),v.current?.focus()}}):null]})}function Tf({projectName:e,busy:t,error:n,onClose:r,onConfirm:i}){return u(),(0,q.jsx)(cn,{open:e!==null,onOpenChange:e=>{!e&&!t&&r()},children:(0,q.jsxs)(on,{className:`gap-0 p-0 sm:max-w-sm`,dismissable:!t,children:[(0,q.jsxs)(`div`,{className:`p-4 pb-2`,children:[(0,q.jsx)(an,{children:e?f(`remove_bdb7b58b`,{v0:e}):f(`remove_project_6277bb2a`)}),(0,q.jsx)(sn,{className:`mt-2 leading-relaxed`,children:f(`the_project_will_be_removed_from_new_session_choices_ex_d355c682`)}),n?(0,q.jsx)(`p`,{className:`mt-2 text-xs text-destructive`,children:n}):null]}),(0,q.jsxs)(`div`,{className:`flex justify-end gap-2 p-4 pt-2`,children:[(0,q.jsx)(W,{variant:`secondary`,disabled:t,onClick:r,children:f(`cancel_2cd0f3be`)}),(0,q.jsxs)(W,{variant:`destructive`,disabled:t,onClick:i,children:[t?(0,q.jsx)(L,{className:`size-4 animate-spin`}):null,f(`remove_project_84663136`)]})]})]})})}var Ef=e=>{let t=e.trim();return t===`/`?t:t.replace(/\/+$/,``)},Df=(e,t)=>Ct(e)?e.status===409||e.status===412?f(`the_project_was_changed_by_another_operation_close_this_c06150ff`):e.status===404?f(`the_project_does_not_exist_or_has_been_removed_6a68f3ee`):e.message||t:e instanceof Error?e.message:t,Of=async()=>{if(!en())return null;let e=await tn.pickDirectory();return e?Ef(e):null};function kf({projectId:e,onClose:t}){u();let n=H(t=>e?t.projects[e]:void 0),r=H(e=>e.ensureProject),i=H(e=>e.updateProject),a=H(e=>e.bindWorkspace),o=H(e=>e.unbindWorkspace),s=H(e=>e.archiveProject),c=H(e=>e.unarchiveProject),[l,d]=(0,K.useState)(``),[p,m]=(0,K.useState)(``),[h,g]=(0,K.useState)([]),[_,v]=(0,K.useState)(``),[y,b]=(0,K.useState)(!1),[x,S]=(0,K.useState)(!1),[C,w]=(0,K.useState)(null),[T,E]=(0,K.useState)(!1);(0,K.useEffect)(()=>{if(!e)return;let t=!1;return b(!0),w(null),v(``),r(e).then(()=>{if(t)return;let n=H.getState().projects[e];if(!n)throw Error(f(`project_does_not_exist_b2667460`));d(n.name),m(n.project_path??``),g(n.workspace_bindings)}).catch(e=>{t||w(Df(e,f(`could_not_load_project_10e9dd1f`)))}).finally(()=>{t||b(!1)}),()=>{t=!0}},[r,e]);let D=(0,K.useMemo)(()=>new Set([Ef(p),...h.map(e=>Ef(e.path))]),[h,p]);if(!e||!n)return null;let O=(e=_)=>{let t=Ef(e);!t||D.has(t)||(g(e=>[...e,{path:t}]),v(``))},k=async e=>{try{let t=await Of();if(!t)return;e===`primary`?m(t):O(t)}catch(e){w(Df(e,f(`could_not_open_the_folder_picker_645d74e6`)))}},A=async()=>{let n=l.trim(),r=Ef(p),s=h.map(e=>({...e,path:Ef(e.path)})).filter((e,t,n)=>!!e.path&&e.path!==r&&n.findIndex(t=>t.path===e.path)===t);if(!n){w(f(`enter_a_project_name_0fb3237e`));return}if(!r){w(f(`select_the_project_s_primary_directory_5c187cfd`));return}S(!0),w(null);try{let c=[r,...s.map(e=>e.path)],l=(await Promise.all(c.map(e=>uo.validatePath(e)))).find(e=>!e.is_valid);if(l)throw Error(l.error_message||f(`invalid_source_directory_80ab8f9e`));let u=H.getState().projects[e];if(!u)throw Error(f(`project_does_not_exist_b2667460`));let d={};n!==u.name&&(d.name=n),r!==u.project_path&&(d.project_path=r),Object.keys(d).length>0&&(u=await i(u.id,u.revision,d));let p=new Set(s.map(e=>e.path));for(let e of[...u.workspace_bindings])p.has(e.path)||(u=await o(u.id,u.revision,e.path));let m=new Set(u.workspace_bindings.map(e=>e.path));for(let e of s)m.has(e.path)||(u=await a(u.id,u.revision,e),m.add(e.path));t()}catch(e){w(Df(e,f(`could_not_save_project_a052bb9e`)))}finally{S(!1)}},j=async()=>{S(!0),w(null);try{let n=H.getState().projects[e];if(!n)throw Error(f(`project_does_not_exist_b2667460`));n.status===`archived`?await c(n.id,n.revision):await s(n.id,n.revision),E(!1),t()}catch(e){w(Df(e,n.status===`archived`?f(`could_not_restore_project_4f2a985d`):f(`could_not_remove_project_1086e674`)))}finally{S(!1)}};return(0,q.jsx)(cn,{open:!0,onOpenChange:e=>{e||x||(T?E(!1):t())},children:(0,q.jsx)(on,{className:`gap-0 p-0 ${T?`sm:max-w-sm`:`sm:max-w-xl`}`,dismissable:!x,children:T?(0,q.jsxs)(q.Fragment,{children:[(0,q.jsxs)(`div`,{className:`p-4 pb-2`,children:[(0,q.jsx)(an,{children:f(`remove_bdb7b58b`,{v0:n.name})}),(0,q.jsx)(sn,{className:`mt-2 leading-relaxed`,children:f(`the_project_will_be_removed_from_new_session_choices_ex_d355c682`)}),C?(0,q.jsx)(`p`,{className:`mt-2 text-xs text-destructive`,children:C}):null]}),(0,q.jsxs)(`div`,{className:`flex justify-end gap-2 p-4 pt-2`,children:[(0,q.jsx)(W,{variant:`secondary`,disabled:x,onClick:()=>E(!1),children:f(`cancel_2cd0f3be`)}),(0,q.jsxs)(W,{variant:`destructive`,disabled:x,onClick:()=>void j(),children:[x?(0,q.jsx)(L,{className:`size-4 animate-spin`}):null,f(`remove_project_84663136`)]})]})]}):(0,q.jsxs)(q.Fragment,{children:[(0,q.jsxs)(`div`,{className:`border-b p-4`,children:[(0,q.jsx)(an,{children:f(`edit_project_577feeef`)}),(0,q.jsx)(sn,{className:`mt-1`,children:f(`bamboo_persists_names_and_source_directories_in_its_pro_20919dcd`)})]}),(0,q.jsxs)(`div`,{className:`min-h-0 flex-1 space-y-4 overflow-y-auto p-4`,children:[y?(0,q.jsxs)(`div`,{className:`flex items-center gap-2 py-8 text-sm text-muted-foreground`,children:[(0,q.jsx)(L,{className:`size-4 animate-spin`}),f(`loading_project_6d8a4e84`)]}):(0,q.jsxs)(q.Fragment,{children:[(0,q.jsxs)(`div`,{className:`grid gap-1.5`,children:[(0,q.jsx)(`label`,{htmlFor:`edit-project-name`,className:`text-sm font-medium`,children:f(`project_name_867698fb`)}),(0,q.jsx)(fe,{id:`edit-project-name`,value:l,onChange:e=>d(e.target.value),autoFocus:!0})]}),(0,q.jsxs)(`div`,{className:`space-y-2`,children:[(0,q.jsxs)(`div`,{children:[(0,q.jsx)(`div`,{className:`text-sm font-medium`,children:f(`source_directories_28af332c`)}),(0,q.jsx)(`p`,{className:`mt-0.5 text-xs text-muted-foreground`,children:f(`the_primary_directory_is_the_default_workspace_for_new__2518446f`)})]}),(0,q.jsxs)(`div`,{className:`overflow-hidden rounded-lg border`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-2 border-b px-3 py-2.5`,children:[(0,q.jsx)(wr,{className:`size-4 shrink-0 text-muted-foreground`}),(0,q.jsx)(fe,{"aria-label":f(`primary_project_directory_0852e851`),className:`h-8 min-w-0 flex-1 border-0 bg-transparent shadow-none focus-visible:ring-0`,value:p,onChange:e=>m(e.target.value),placeholder:f(`absolute_path_to_primary_directory_ab8e5c38`)}),(0,q.jsx)(`span`,{className:`shrink-0 text-[11px] text-muted-foreground`,children:f(`primary_5ccd91f4`)}),en()?(0,q.jsx)(W,{type:`button`,size:`icon`,variant:`ghost`,className:`size-8`,"aria-label":f(`select_primary_project_directory_30a25dc5`),onClick:()=>void k(`primary`),children:(0,q.jsx)(Sr,{className:`size-3.5`})}):null]}),h.map(e=>(0,q.jsxs)(`div`,{className:`flex items-center gap-2 border-b px-3 py-2.5 last:border-0`,children:[(0,q.jsx)(wr,{className:`size-4 shrink-0 text-muted-foreground`}),(0,q.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-sm`,title:e.path,children:e.path}),(0,q.jsx)(W,{type:`button`,size:`icon`,variant:`ghost`,className:`size-8 text-muted-foreground hover:text-destructive`,"aria-label":f(`remove_source_directory_c14882d9`,{v0:e.path}),onClick:()=>g(t=>t.filter(t=>t.path!==e.path)),children:(0,q.jsx)(M,{className:`size-3.5`})})]},e.path)),(0,q.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-2.5`,children:[(0,q.jsx)(Cr,{className:`size-4 shrink-0 text-muted-foreground`}),(0,q.jsx)(fe,{"aria-label":f(`add_source_directory_398c49c7`),className:`h-8 min-w-0 flex-1 border-0 bg-transparent shadow-none focus-visible:ring-0`,value:_,onChange:e=>v(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),O())},placeholder:f(`add_an_absolute_folder_path_0a395954`)}),en()?(0,q.jsx)(W,{type:`button`,size:`icon`,variant:`ghost`,className:`size-8`,"aria-label":f(`select_source_directory_to_add_4b3ae33c`),onClick:()=>void k(`binding`),children:(0,q.jsx)(Sr,{className:`size-3.5`})}):null,(0,q.jsx)(W,{type:`button`,size:`sm`,variant:`ghost`,disabled:!_.trim(),onClick:()=>O(),children:f(`add_7a8a11ea`)})]})]})]})]}),C?(0,q.jsx)(`p`,{role:`alert`,className:`rounded-md bg-destructive/10 px-3 py-2 text-xs text-destructive`,children:C}):null]}),(0,q.jsxs)(`div`,{className:`flex items-center justify-between gap-3 border-t px-4 py-3`,children:[n.status===`archived`?(0,q.jsx)(W,{variant:`outline`,disabled:x||y,onClick:()=>void j(),children:f(`restore_project_52a1d56b`)}):(0,q.jsx)(W,{variant:`ghost`,className:`text-destructive hover:text-destructive`,disabled:x||y,onClick:()=>{w(null),E(!0)},children:f(`remove_local_project_e951cbd0`)}),(0,q.jsxs)(`div`,{className:`ml-auto flex gap-2`,children:[(0,q.jsx)(W,{variant:`secondary`,disabled:x,onClick:t,children:f(`cancel_2cd0f3be`)}),(0,q.jsxs)(W,{disabled:x||y||!l.trim()||!p.trim(),onClick:()=>void A(),children:[x?(0,q.jsx)(L,{className:`size-4 animate-spin`}):null,f(`save_a3030bf8`)]})]})]})]})})})}function Af({children:e,sectionName:t,onNewSession:n,onManageSections:r}){let i=s(),a=bf(),o=!!t&&!!n;return(0,q.jsxs)(`div`,{...a.rowProps,className:`flex select-none items-center`,children:[e,o?(0,q.jsx)(`button`,{type:`button`,"aria-label":i(`sidebar_section_new_session`,{v0:t}),className:`shrink-0 rounded p-1 text-muted-foreground outline-none hover:bg-accent hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring`,onClick:n,children:(0,q.jsx)(er,{className:`size-3.5`})}):null,(0,q.jsxs)(ke,{open:a.open,onOpenChange:a.onOpenChange,children:[(0,q.jsx)(V,{"aria-label":i(`sidebar_manage_sections`),className:`shrink-0 rounded p-1 text-muted-foreground outline-none hover:bg-accent focus-visible:ring-2 focus-visible:ring-ring`,children:(0,q.jsx)(Xn,{className:`size-3.5`})}),(0,q.jsxs)(z,{align:`end`,onCloseAutoFocus:a.onCloseAutoFocus,children:[o?(0,q.jsxs)(B,{onSelect:n,children:[(0,q.jsx)(Pr,{}),i(`sidebar_section_new_session`,{v0:t})]}):null,(0,q.jsxs)(B,{onSelect:r,children:[(0,q.jsx)(jr,{}),i(`sidebar_manage_sections`)]})]})]})]})}var jf=()=>o(()=>import(`./ProjectWorkBoard-BDerd2KC.js`),__vite__mapDeps([51,1,2,3,4,7,8,9,10,11,12,52,53,54]),import.meta.url),Mf=e=>(0,K.lazy)(async()=>({default:(await e()).ProjectWorkBoard}));function Nf({project:e,onClose:t,metadataError:n,controls:r,onOpenSession:i,loadBoard:a=jf}){u();let[o,s]=(0,K.useState)(()=>Mf(a));return(0,q.jsx)(cn,{open:!!e,onOpenChange:e=>{e||t()},children:(0,q.jsxs)(on,{style:{maxWidth:`64rem`},"aria-describedby":void 0,children:[(0,q.jsxs)(`div`,{className:`border-b p-4 pr-12`,children:[(0,q.jsxs)(an,{children:[f(`project_work_title`),e?` · ${e.name}`:``]}),(0,q.jsx)(sn,{className:`sr-only`,children:f(`project_work_readonly`)})]}),n?(0,q.jsx)(`p`,{role:`alert`,className:`px-4 pt-3 text-sm text-destructive`,children:n}):null,e?(0,q.jsx)(ue,{name:`ProjectWorkBoard`,fallback:(e,t)=>(0,q.jsxs)(`div`,{role:`alert`,className:`p-4 text-sm`,children:[(0,q.jsx)(`p`,{children:f(`work_load_failed`)}),(0,q.jsx)(W,{className:`mt-2`,variant:`outline`,onClick:()=>{s(Mf(a)),t()},children:f(`retry_b8784c8d`)})]}),children:(0,q.jsx)(K.Suspense,{fallback:(0,q.jsx)(`p`,{role:`status`,"aria-live":`polite`,className:`p-4 text-sm text-muted-foreground`,"data-testid":`project-work-loading`,children:f(`project_work_loading`)}),children:(0,q.jsx)(o,{project:e,controls:r,onOpenSession:i},e.id)})},e.id):null]})})}function Pf({project:e,label:t,sessionCount:n,expanded:r,contentId:i,disabled:a,pinned:o,onToggleExpanded:s,onNewChat:c,onEdit:l,onWork:d,onTogglePin:p,onCreateSection:m,onManageSections:h,onReveal:g,onArchive:_}){u();let v=bf();return e?(0,q.jsxs)(`div`,{...v.rowProps,className:`flex select-none items-center rounded-md px-1 pb-1 pt-2 feedback-motion transition-colors hover:bg-sidebar-accent`,children:[(0,q.jsxs)(`button`,{type:`button`,"aria-expanded":r,"aria-controls":i,disabled:a,className:`flex min-w-0 flex-1 items-center gap-1 rounded px-1 py-1 text-left text-xs font-medium text-muted-foreground outline-none hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-default`,onClick:s,children:[(0,q.jsx)(ve,{"aria-hidden":`true`,className:G(`size-3 shrink-0 feedback-motion transition-transform`,r&&`rotate-90`)}),(0,q.jsx)(br,{"aria-hidden":`true`,className:`size-3.5 shrink-0`}),(0,q.jsx)(`span`,{className:`truncate`,children:t}),o?(0,q.jsx)(Rr,{"aria-label":f(`pinned_fb47db5e`),className:`size-3 shrink-0`}):null,(0,q.jsx)(`span`,{className:`ml-auto whitespace-nowrap font-normal`,children:n})]}),(0,q.jsxs)(`div`,{className:`flex shrink-0 items-center`,children:[(0,q.jsx)(`button`,{type:`button`,"aria-label":f(`new_session_in_1e893198`,{v0:e.name}),disabled:e.status===`archived`,className:`rounded p-1 text-muted-foreground outline-none hover:bg-accent hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-default`,onClick:c,children:(0,q.jsx)(er,{className:`size-3.5`})}),(0,q.jsxs)(ke,{open:v.open,onOpenChange:v.onOpenChange,children:[(0,q.jsx)(V,{"aria-label":f(`project_actions_4bc7fa27`,{v0:e.name}),className:`rounded p-1 text-muted-foreground outline-none hover:bg-accent hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring data-[state=open]:bg-accent`,children:(0,q.jsx)(Xn,{className:`size-3.5`})}),(0,q.jsxs)(z,{onCloseAutoFocus:v.onCloseAutoFocus,align:`start`,side:`right`,className:`min-w-48 rounded-xl`,children:[(0,q.jsxs)(B,{disabled:e.status===`archived`,onClick:c,children:[(0,q.jsx)(Pr,{}),f(`new_session_58e21b87`)]}),d?(0,q.jsxs)(B,{onClick:d,children:[(0,q.jsx)(jr,{}),f(`project_work_title`)]}):null,(0,q.jsxs)(B,{onClick:p,children:[o?(0,q.jsx)(Lr,{}):(0,q.jsx)(Rr,{}),` `,f(o?`unpin_c92179b7`:`pin_173f88d2`)]}),(0,q.jsxs)(B,{onClick:m,children:[(0,q.jsx)(ze,{}),f(`sidebar_create_section`)]}),(0,q.jsxs)(B,{onClick:h,children:[(0,q.jsx)(jr,{}),f(`sidebar_manage_sections`)]}),(0,q.jsxs)(B,{disabled:e.status===`archived`,onClick:l,children:[(0,q.jsx)(j,{}),f(`edit_project_577feeef`)]}),(0,q.jsx)(De,{}),(0,q.jsxs)(B,{disabled:!e.project_path,onClick:g,children:[(0,q.jsx)(Sr,{}),f(`show_in_file_manager_1280364b`)]}),(0,q.jsx)(De,{}),(0,q.jsxs)(B,{variant:e.status===`archived`?`default`:`destructive`,onClick:_,children:[e.status===`archived`?(0,q.jsx)(nr,{}):(0,q.jsx)(rr,{}),e.status===`archived`?f(`restore_project_52a1d56b`):f(`remove_local_project_e951cbd0`)]})]})]})]})]}):(0,q.jsxs)(`button`,{type:`button`,"aria-expanded":r,"aria-controls":i,disabled:a,className:`flex select-none w-full items-center gap-1 rounded-md px-2 pb-1 pt-3 text-left text-xs font-medium text-muted-foreground outline-none hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-default`,onClick:s,children:[(0,q.jsx)(ve,{"aria-hidden":`true`,className:G(`size-3 shrink-0 feedback-motion transition-transform`,r&&`rotate-90`)}),(0,q.jsx)(`span`,{className:`truncate`,children:t}),(0,q.jsx)(`span`,{className:`ml-auto whitespace-nowrap pl-2 font-normal`,children:f(`project_sessions`,{count:n})})]})}function Ff({projectId:e,existingSections:t,mode:n=`create`,busy:r=!1,unavailable:i=!1,saveError:a,onCreate:o,onRemove:s,onClose:c}){u();let l=H(t=>e?t.projects[e]:void 0),[d,p]=(0,K.useState)(``),[m,h]=(0,K.useState)(null);if(!e||!l)return null;let g=async()=>{if(r||i)return;let e=d.trim();if(!e||[...e].length>80||Array.from(e).some(e=>{let t=e.codePointAt(0);return t<32||t===127})){h(f(`sidebar_section_invalid_name`));return}if(t.some(t=>t.name.toLocaleLowerCase()===e.toLocaleLowerCase())){h(f(`sidebar_section_duplicate`));return}await o(e)&&(p(``),h(null),n===`create`&&c())};return(0,q.jsx)(cn,{open:!0,onOpenChange:e=>{!e&&!r&&c()},children:(0,q.jsxs)(on,{className:`gap-0 p-0 sm:max-w-sm`,"aria-busy":r,children:[(0,q.jsxs)(`div`,{className:`p-4 pb-2`,children:[(0,q.jsxs)(an,{children:[f(n===`create`?`sidebar_create_section`:`sidebar_manage_sections`),` · `,l.name]}),(0,q.jsx)(sn,{className:`mt-2 leading-relaxed`,children:f(`sidebar_section_server_hint`)})]}),(0,q.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),g()},className:`grid gap-1.5 p-4`,children:[(0,q.jsx)(`label`,{htmlFor:`project-section-name`,className:`text-sm font-medium`,children:f(`sidebar_section_name`)}),(0,q.jsxs)(`div`,{className:`flex gap-2`,children:[(0,q.jsx)(fe,{id:`project-section-name`,value:d,disabled:r||i,onChange:e=>{p(e.target.value),h(null)},autoFocus:!0,"aria-invalid":!!m,"aria-describedby":m?`project-section-error`:void 0}),(0,q.jsx)(W,{type:`submit`,disabled:!d.trim()||r||i,children:f(`create_cde2cd07`)})]}),m?(0,q.jsx)(`p`,{id:`project-section-error`,role:`alert`,className:`text-xs text-destructive`,children:m}):null,i||a?(0,q.jsx)(`p`,{role:`alert`,className:`text-xs text-destructive`,children:i?f(`sidebar_sections_unavailable`):a}):null]}),n===`manage`&&t.length>0?(0,q.jsxs)(`div`,{className:`grid gap-2 border-t p-4`,children:[(0,q.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:f(`sidebar_section_remove_hint`)}),t.map(e=>(0,q.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[(0,q.jsx)(`span`,{className:`flex-1 truncate text-sm`,children:e.name}),(0,q.jsx)(W,{size:`icon`,variant:`ghost`,disabled:r||i,"aria-label":`${f(`sidebar_section_remove`)} ${e.name}`,onClick:()=>{s(e.id)},children:(0,q.jsx)(M,{className:`size-4`})})]},e.id))]}):null,(0,q.jsx)(`div`,{className:`flex justify-end p-4 pt-2`,children:(0,q.jsx)(W,{variant:`secondary`,disabled:r,onClick:c,children:f(`cancel_2cd0f3be`)})})]})})}var If=e=>`${e.getFullYear()}-${String(e.getMonth()+1).padStart(2,`0`)}-${String(e.getDate()).padStart(2,`0`)}`;function Lf(e,t){let n=new Date(e),r=new Date(t.getFullYear(),t.getMonth(),t.getDate()-1);return If(n)===If(t)?f(`today_d5f5a7a0`):If(n)===If(r)?f(`yesterday_0c184871`):new Intl.DateTimeFormat(m(),{...n.getFullYear()===t.getFullYear()?{}:{year:`numeric`},month:`long`,day:`numeric`}).format(n)}var Rf=(e,t)=>[...e].sort((e,n)=>Ls(e,n,t)),zf=e=>e.chats.reduce((e,t)=>Math.max(e,typeof t.createdAt==`number`?t.createdAt:0),0);function Bf(e,t,n=hs){let r=Rf(e.filter(e=>e.pinned),n),i=Rf(e.filter(e=>!e.pinned),n),a=new Map;for(let e of i){let r=Is(e,n),i=If(new Date(r)),o=a.get(i);o?o.chats.push(e):a.set(i,{key:i,label:Lf(r,t),chats:[e]})}let o=[];return r.length&&o.push({key:`__pinned`,label:f(`pinned_section`),chats:r}),o.push(...[...a.values()].sort((e,t)=>t.key.localeCompare(e.key))),o}function Vf(e,t,n=hs){let r=Rf(e.filter(e=>e.pinned),n),i=Rf(e.filter(e=>!e.pinned),n),a=new Map;for(let e of i){let n=e.config?.projectId?.trim(),r=n||`__no_project__`,i=a.get(r);i?i.chats.push(e):a.set(r,{key:r,label:t(n||null),chats:[e]})}let o=[];r.length&&o.push({key:`__pinned`,label:f(`pinned_section`),chats:r});let s=[...a.values()].filter(e=>e.key!==Ht);s.sort((e,t)=>zf(t)-zf(e)),o.push(...s);let c=a.get(Ht);return c&&o.push(c),o}var Hf=e=>e.replace(/\/+$/,``);async function Uf(e){let t=new Map,n=await Promise.all([...new Set(e)].filter(Boolean).map(e=>Ot.get(`projects/${encodeURIComponent(e)}/worktrees/merge-state`).catch(()=>null)));for(let e of n)if(e)for(let n of e.repositories)for(let e of n.worktrees){let r=e.state;t.set(Hf(e.path),{state:r===`merged`||r===`in_progress`||r===`primary`?r:`unknown`,baseRef:n.base_ref})}return t}var Wf=(e,t)=>t?e.get(Hf(t)):void 0;function Gf(e,t){let[n,r]=(0,K.useState)(()=>new Map),i=e.join(`\0`);return(0,K.useEffect)(()=>{if(!Rt(`worktree_merge_state`))return;let e=!0,t=(i?i.split(`\0`):[]).filter(Boolean);if(t.length)return Uf(t).then(t=>{e&&r(t)}),()=>{e=!1}},[i,t]),n}var Kf=(0,K.lazy)(()=>o(()=>import(`./SidebarProjectDrag-B8jeZZwD.js`),__vite__mapDeps([55,1,2,3,4,56,6,43,41,42,7,8,21,18,57]),import.meta.url)),qf=({target:e,disabled:t,...n})=>(0,q.jsx)(`div`,{...n}),Jf=`lotus.sidebar.grouping-mode.v1`,Yf=7,Xf=(e,t)=>JSON.stringify([e,t]),Zf=()=>{try{return typeof localStorage>`u`?`date`:localStorage.getItem(Jf)===`project`?`project`:`date`}catch{return`date`}};function Qf({open:e,onClose:t,collapsed:n,onToggleCollapse:r,width:i,chats:a,booted:o,currentSessionId:c,onNewChat:l,onSelect:u,onOpenExistingSession:d,onRename:f,onDelete:p,onTogglePin:m,onCopySessionId:h,onOpenSettings:g,onOpenProjectManager:_,onOpenWorktrees:v}){let y=s(),[b,x]=(0,K.useState)(``),[S,C]=(0,K.useState)(Zf),[w,T]=(0,K.useState)(vn),[E,D]=(0,K.useState)(`create`),[O,k]=(0,K.useState)(null),[A,j]=(0,K.useState)(null),[M,N]=(0,K.useState)(null),[P,F]=(0,K.useState)(null),[I,ee]=(0,K.useState)(!1),[L,te]=(0,K.useState)(null),R=H(e=>e.projects),ne=As(),{preferences:re,update:ie,busy:ae,errors:oe}=Ic(R),se=vf(),ce=H(e=>e.backgroundBash),le=H(e=>e.executionBySession),ue=(0,K.useId)(),de=(0,K.useRef)(!1),[pe,he]=(0,K.useState)(!1),[ge,_e]=(0,K.useState)(null),ye=async()=>{if(!de.current){de.current=!0,he(!0),_e(null);try{await u(Ga),t()}catch(e){_e(Dt(e))}finally{de.current=!1,he(!1)}}},be=b.trim().toLowerCase(),xe=e=>ct(e,le[e.id],ce),Se=e=>{C(e);try{localStorage.setItem(Jf,e)}catch{}},Ce=a.find(Ka),we=c===Ga,Te=!!Ce&&uf(Ce,se),Ee=(0,K.useMemo)(()=>a.filter(e=>!e.parentSessionId&&!Ka(e)),[a]),z=(0,K.useMemo)(()=>{let e=new Map;for(let t of Ee){let n=t.config?.projectId?.trim()||`__no_project__`;e.set(n,(e.get(n)??0)+1)}return e},[Ee]),De=Gf(Ee.map(e=>e.config?.projectId?.trim()).filter(e=>!!e),Ee.map(e=>e.id).join(`,`)),B=(0,K.useMemo)(()=>{if(S===`project`){let e=Vf(Ee,e=>{if(!e)return y(`unassigned_52496e5a`);let t=R[e];return t?t.status===`archived`?y(`archived_01a84e81`,{v0:t.name}):t.name:y(`unknown_project_9714067d`)},ne),t=e.find(e=>e.key===`__pinned`),n=e.filter(e=>e.key!==`__pinned`),r=new Set(n.map(e=>e.key));for(let e of Object.values(R))e.status!==`active`||r.has(e.id)||n.push({key:e.id,label:e.name,chats:[]});return n.sort((e,t)=>{let n=w.has(e.key);return n===w.has(t.key)?0:n?-1:1}),t?[t,...n]:n}return Bf(Ee,new Date,ne)},[S,w,R,Ee,ne,y]),Oe=S===`project`,ke=(Oe?[]:B.filter(e=>e.key!==`__pinned`)).slice(5),V=B.find(e=>e.chats.some(e=>e.id===c)),Ae=Oe&&V?R[V.key]:void 0,je=Ae&&c?kn(re,Ae.id,c,Ae.section):null,Ne=Ae?Xf(Ae.id,je):null,Pe=Ne??V?.key,Fe=Ae&&V?V.chats.filter(e=>kn(re,Ae.id,e.id,Ae.section)===je):V?.chats??[],Ie=ke.some(e=>e.key===V?.key),Le=JSON.stringify([c??null,V?.key,Ne,Ie]),[Re,Be]=(0,K.useState)(()=>({activePath:Le,olderExpanded:Ie,closedDates:new Set,closedSections:new Set,expandedProjectGroups:new Set(Oe&&Pe&&Fe.findIndex(e=>e.id===c)>=Yf?[Pe]:[])}));if(Re.activePath!==Le){let e=new Set(Re.closedDates);V&&e.delete(V.key);let t=new Set(Re.closedSections);Ne&&t.delete(Ne);let n=new Set(Re.expandedProjectGroups);Pe&&Fe.findIndex(e=>e.id===c)>=Yf&&n.add(Pe),Be({activePath:Le,olderExpanded:Re.olderExpanded||Ie,closedDates:e,closedSections:t,expandedProjectGroups:n})}let Ue=be?B.map(e=>({...e,chats:e.chats.filter(e=>(e.title||``).toLowerCase().includes(be))})).filter(e=>e.chats.length>0):Oe?B:B.filter(e=>e.key===`__pinned`||!ke.includes(e)),We=ke.reduce((e,t)=>e+t.chats.length,0),Ge=P?R[P]:void 0,Ke=e=>{T(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),xn(n),n})},qe=async e=>{let t=H.getState().projects[e];if(!(!t||I)){ee(!0),te(null);try{await H.getState().unarchiveProject(t.id,t.revision)}catch(e){te(e instanceof Error?e.message:y(`could_not_restore_project_4f2a985d`))}finally{ee(!1)}}},Je=(e,t,n,r)=>{if(Ee.find(e=>e.id===t)?.config?.projectId?.trim()!==e||!R[e]||R[e].status!==`active`||kn(re,e,t,R[e].section)===n)return Promise.resolve(!1);let i=!1;return ie(e,a=>{if(r&&!Ye(r))return a;let o=Dn(a,e,t,n,R[e]?.section);return i=o!==a,o}).then(t=>!t||!i?!1:(Be(t=>{let r=new Set(t.closedDates);r.delete(e);let i=Xf(e,n),a=new Set(t.closedSections);a.delete(i);let o=new Set(t.expandedProjectGroups);return o.add(i),{...t,closedDates:r,closedSections:a,expandedProjectGroups:o}}),!0))},Ye=e=>{let t=H.getState().projects[e.projectId];return!!t&&t.status===`active`&&t.sidebar!==void 0&&t.revision===e.revision&&dt(t)===e.revision&&!ae.has(t.id)},Xe=(e,t)=>{let n=R[e],r=B.find(t=>t.key===e);return!n||!r?[]:r.chats.filter(e=>kn(re,n.id,e.id,n.section)===t).map(e=>e.id)},Ze=(e,t,n)=>{let r=Ee.find(t=>t.id===e.id),i=R[t.projectId];if(!r||!i||i.status!==`active`||!t.sessionId)return Promise.resolve(!1);let a=t.sessionId,o=t.sectionId;if(r.config?.projectId?.trim()!==i.id||a===e.id)return Promise.resolve(!1);let s=Xe(i.id,o);if(!s.includes(a))return Promise.resolve(!1);let c=()=>{let t=ks();return Ns(t,Fs(t,s),e.id,a,n)};return kn(re,i.id,e.id,i.section)===o?(Ps(c()),Promise.resolve(!0)):Je(i.id,e.id,o,e).then(e=>(e&&Ps(c()),e))},Qe=(e,t,n=!1)=>!Ye(e)||e.projectId!==t.projectId?Promise.resolve(!1):t.sessionId?Ze(e,t,n):Je(e.projectId,e.id,t.sectionId,e),$e=(e,t,n)=>{!Ye(e)||e.projectId!==t.projectId||ie(e.projectId,r=>Ye(e)?yn(r,e.projectId,e.id,t.sectionId,n):r)},et=(e,n)=>{let r=e.config?.projectId?.trim(),i=r?R[r]:void 0;return(0,q.jsx)(wf,{chat:e,active:e.id===c,running:xe(e),unread:e.id!==c&&uf(e,se),projectId:i?.id,mergeState:Wf(De,e.config?.workspacePath),dragHandle:n&&i&&i.status===`active`&&i.sidebar!==void 0&&!be?(0,q.jsx)(n.Handle,{source:{kind:`session`,projectId:i.id,id:e.id},label:`${y(`sidebar_session_drag_hint`)} · ${e.title||y(`new_session_c57c30bc`)}`,disabled:ae.has(i.id)}):void 0,sections:i?En(re,i.id,i.section):void 0,sectionId:i?kn(re,i.id,e.id,i.section):void 0,onMoveToSection:i&&i.sidebar!==void 0&&!ae.has(i.id)?t=>Je(i.id,e.id,t):void 0,onSelect:()=>{u(e.id),t()},onRename:t=>f(e.id,t),onDelete:()=>p(e),onTogglePin:()=>m(e),onCopySessionId:()=>h(e.id)},e.id)},tt=(e,t,n,r)=>{let i=Oe&&!be&&e.key!==`__pinned`&&e.chats.length>Yf,a=Re.expandedProjectGroups.has(n),o=i&&!a?e.chats.slice(0,Yf):e.chats;return(0,q.jsxs)(q.Fragment,{children:[t?o.map(e=>et(e,r)):null,t&&i?(0,q.jsxs)(`button`,{type:`button`,className:`flex select-none w-full items-center gap-1 rounded-md px-2 py-1.5 text-left text-xs text-muted-foreground outline-none hover:bg-sidebar-accent hover:text-foreground`,onClick:()=>Be(e=>{let t=new Set(e.expandedProjectGroups);return t.has(n)?t.delete(n):t.add(n),{...e,expandedProjectGroups:t}}),children:[a?(0,q.jsx)(me,{"aria-hidden":`true`,className:`size-3 shrink-0`}):(0,q.jsx)(ve,{"aria-hidden":`true`,className:`size-3 shrink-0`}),(0,q.jsx)(`span`,{children:a?y(`collapse_afd4b783`):`${y(`expand_00bd3960`)} ${y(`count_items`,{count:e.chats.length-Yf})}`})]}):null]})},nt=(e,n)=>{let r=R[e.key],i=En(re,r.id,r.section),a=r.status!==`active`||r.sidebar===void 0||ae.has(r.id)||!!be;if(!i.length){let t=Xf(r.id,null);return(0,q.jsx)(n?.Target??qf,{target:{projectId:r.id,sectionId:null},disabled:a,"data-project-section":``,"data-section-id":`none`,"data-section-project":r.id,"aria-disabled":r.status!==`active`||r.sidebar===void 0||ae.has(r.id),style:{marginInlineStart:12},className:`mb-1 rounded-md feedback-motion switch-feedback`,children:tt(e,!0,t,n)})}return[...i,{id:null,name:y(`sidebar_no_section`)}].map(i=>{let o=Xf(r.id,i.id),s={...e,chats:e.chats.filter(e=>kn(re,r.id,e.id,r.section)===i.id)};if(be&&!s.chats.length)return null;let c=!!be||!Re.closedSections.has(o),u=`${ue}-section-${encodeURIComponent(o)}`;return(0,q.jsxs)(n?.Target??qf,{target:{projectId:r.id,sectionId:i.id},disabled:a,"data-project-section":i.name,"data-section-id":i.id??`none`,"data-section-project":r.id,"aria-disabled":r.status!==`active`||r.sidebar===void 0||ae.has(r.id),style:{marginInlineStart:12},className:`mb-1 rounded-md feedback-motion switch-feedback`,children:[(0,q.jsxs)(Af,{sectionName:i.name,onNewSession:r.status===`active`&&!a?()=>{l(r.id,i.id),t()}:void 0,onManageSections:()=>{D(`manage`),N(r.id)},children:[(0,q.jsxs)(`button`,{type:`button`,"aria-expanded":c,"aria-controls":u,disabled:!!be,className:`flex min-w-0 flex-1 select-none items-center gap-1 rounded-md px-2 py-1.5 text-left text-xs font-medium text-muted-foreground outline-none hover:text-foreground disabled:cursor-default`,"data-sidebar-section-header":!0,onClick:()=>Be(e=>{let t=new Set(e.closedSections);return t.has(o)?t.delete(o):t.add(o),{...e,closedSections:t}}),children:[(0,q.jsx)(ve,{"aria-hidden":`true`,className:G(`size-3 shrink-0 feedback-motion transition-transform`,c&&`rotate-90`)}),(0,q.jsx)(`span`,{className:`truncate`,children:i.name}),(0,q.jsx)(`span`,{className:`ml-auto whitespace-nowrap pl-2 font-normal`,children:y(`project_sessions`,{count:s.chats.length})})]}),n&&i.id&&i.id!==`legacy`?(0,q.jsx)(n.Handle,{source:{kind:`section`,projectId:r.id,id:i.id},label:`${y(`sidebar_section_drag_hint`)} · ${i.name}`,disabled:a}):null]}),(0,q.jsxs)(`div`,{id:u,hidden:!c,children:[tt(s,c,o,n),c&&!s.chats.length?(0,q.jsx)(`p`,{className:`px-2 py-2 text-xs text-muted-foreground`,children:y(`sidebar_section_empty`)}):null]})]},o)})},rt=(e,n)=>{let r=e.key===`__pinned`,i=r||!!be||!Re.closedDates.has(e.key),a=`${ue}-${e.key}`,o=Oe?R[e.key]:void 0,s=()=>Be(t=>{let n=new Set(t.closedDates);return n.has(e.key)?n.delete(e.key):n.add(e.key),{...t,closedDates:n}}),c=n?.Target??qf;return(0,q.jsxs)(`div`,{"data-sidebar-project":o?.id,"aria-busy":o?ae.has(o.id):void 0,className:`mb-1`,children:[r?(0,q.jsx)(`div`,{className:`px-2 pt-3 pb-1 text-xs font-medium text-muted-foreground`,children:e.label}):o?(0,q.jsx)(c,{target:{projectId:o.id,sectionId:null},disabled:o.status!==`active`||o.sidebar===void 0||ae.has(o.id)||!!be,"data-project-drop":o.id,title:y(`sidebar_project_drop_hint`),className:`rounded-md feedback-motion switch-feedback`,children:(0,q.jsx)(Pf,{project:o,label:e.label,sessionCount:z.get(e.key)??e.chats.length,expanded:i,contentId:a,disabled:!!be,pinned:w.has(o.id),onToggleExpanded:s,onNewChat:()=>{l(o.id),t()},onWork:()=>{te(null),k(o.id),H.getState().ensureProject(o.id).catch(e=>{te(Dt(e))})},onEdit:()=>{te(null),j(o.id)},onTogglePin:()=>Ke(o.id),onCreateSection:()=>{te(null),D(`create`),N(o.id)},onManageSections:()=>{D(`manage`),N(o.id)},onReveal:()=>{te(null),rn(o.project_path??``).catch(e=>{te(e instanceof Error?e.message:y(`could_not_open_project_directory_b25cc8f5`))})},onArchive:()=>{o.status===`archived`?qe(o.id):(te(null),F(o.id))}})}):(0,q.jsxs)(`button`,{type:`button`,"aria-expanded":i,"aria-controls":a,disabled:!!be,className:`flex select-none w-full items-center gap-1 rounded-md px-2 pt-3 pb-1 text-left text-xs font-medium text-muted-foreground outline-none hover:text-foreground disabled:cursor-default`,onClick:s,children:[(0,q.jsx)(ve,{"aria-hidden":`true`,className:G(`size-3 shrink-0 feedback-motion transition-transform`,i&&`rotate-90`)}),(0,q.jsx)(`span`,{children:e.label}),(0,q.jsx)(`span`,{className:`ml-auto whitespace-nowrap pl-2 font-normal`,children:y(`project_sessions`,{count:e.chats.length})})]}),(0,q.jsx)(`div`,{id:a,hidden:!i,children:o?i?nt(e,n):null:tt(e,i,e.key,n)})]},e.key)};return(0,q.jsxs)(q.Fragment,{children:[e&&(0,q.jsx)(`button`,{className:`fixed inset-0 z-40 bg-black/50 md:hidden`,"aria-label":`Close menu`,onClick:t}),(0,q.jsxs)(`aside`,{style:{"--sidebar-w":typeof i==`number`?`${i}px`:i,color:`var(--sidebar-foreground)`},className:G(`fixed inset-y-0 left-0 z-50 flex w-[84%] max-w-xs flex-col bg-sidebar transition-transform md:static md:w-[var(--sidebar-w)] md:max-w-none md:translate-x-0`,e?`translate-x-0`:`-translate-x-full`,n&&`md:hidden`),children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-2 px-4 py-3`,children:[(0,q.jsx)(so,{className:`size-6`}),(0,q.jsx)(`span`,{className:`flex-1 text-sm font-semibold dark:font-medium`,children:`Bodhi`}),(0,q.jsx)(W,{size:`icon`,variant:`ghost`,className:`hidden size-8 text-muted-foreground md:inline-flex`,"aria-label":y(`collapse_sidebar_bb0b6e36`),onClick:r,children:(0,q.jsx)(Zn,{className:`size-4`})})]}),(0,q.jsxs)(`div`,{className:`px-2 pb-2`,children:[(0,q.jsx)(Sf,{chat:Ce,active:we,unread:Te,busy:pe,running:!!Ce&&xe(Ce),disabled:!o||pe,onSelect:()=>void ye(),onRename:f}),ge?(0,q.jsx)(`p`,{role:`alert`,className:`px-2 pb-2 text-sm text-destructive`,children:ge}):null,(0,q.jsxs)(W,{variant:`ghost`,className:`w-full justify-start gap-2`,onClick:()=>{l(Oe&&V?.key&&V.key!==`__pinned`&&V.key!==`__no_project__`?V.key:null),t()},children:[(0,q.jsx)(ze,{className:`size-4`}),y(`new_session_58e21b87`)]}),(0,q.jsxs)(W,{variant:`ghost`,className:`w-full justify-start gap-2`,onClick:()=>{_(),t()},children:[(0,q.jsx)(br,{className:`size-4`}),y(`manage_projects_302f96cf`)]})]}),(0,q.jsx)(`div`,{className:`px-3 pb-2`,children:(0,q.jsxs)(`div`,{className:`relative`,children:[(0,q.jsx)(Ve,{className:`pointer-events-none absolute left-2.5 top-1/2 size-3.5 -translate-y-1/2 text-muted-foreground`}),(0,q.jsx)(fe,{value:b,onChange:e=>x(e.target.value),placeholder:y(`search_sessions_feb95554`),className:`border-transparent bg-transparent py-1.5 pl-8 pr-7 shadow-none`}),b?(0,q.jsx)(`button`,{onClick:()=>x(``),"aria-label":y(`clear_bce23772`),className:`absolute right-1.5 top-1/2 -translate-y-1/2 rounded p-0.5 text-muted-foreground hover:text-foreground`,children:(0,q.jsx)(He,{className:`size-3.5`})}):null]})}),(0,q.jsxs)(`div`,{className:`flex items-center gap-2 px-3`,children:[(0,q.jsxs)(`span`,{className:`relative min-w-0 flex-1 text-xs font-medium text-muted-foreground`,children:[(0,q.jsx)(`span`,{className:ae.size?`invisible`:void 0,children:y(Oe?`project_79f326be`:`recent_997a5e6e`)}),ae.size?(0,q.jsx)(`span`,{role:`status`,className:`absolute inset-x-0 top-0 truncate`,children:y(`sidebar_sections_saving`)}):null]}),(0,q.jsxs)(W,{size:`sm`,variant:`ghost`,className:`text-muted-foreground`,"aria-label":y(Oe?`switch_to_recent_view_fce00dbe`:`switch_to_project_view_43561b9a`),onClick:()=>Se(Oe?`date`:`project`),children:[Oe?(0,q.jsx)(sr,{className:`size-4`}):(0,q.jsx)(br,{className:`size-4`}),y(Oe?`recent_997a5e6e`:`project_79f326be`)]})]}),(0,q.jsxs)(`div`,{className:`min-h-0 flex-1 overflow-y-auto px-2 pb-3`,children:[Oe&&Object.values(R).some(e=>e.sidebar===void 0&&En(re,e.id,e.section).length)?(0,q.jsx)(`p`,{role:`status`,className:`px-3 py-2 text-xs text-muted-foreground`,children:y(`sidebar_sections_unavailable`)}):null,Object.entries(oe).filter(([e])=>R[e]&&e!==M).map(([e,t])=>(0,q.jsxs)(`p`,{role:`alert`,className:`px-3 py-2 text-xs text-destructive`,children:[R[e].name,` · `,t]},e)),L?(0,q.jsx)(`button`,{type:`button`,className:`mb-2 w-full rounded-md bg-destructive/10 px-2 py-1.5 text-left text-xs text-destructive`,onClick:()=>te(null),children:L}):null,Ee.length===0&&(0,q.jsx)(`p`,{className:`px-2 py-4 text-xs text-muted-foreground`,children:y(o?`no_sessions_yet_69e71f03`:`loading_4927a53b`)}),Oe?(0,q.jsx)(K.Suspense,{fallback:(0,q.jsx)(`div`,{inert:!0,"aria-busy":`true`,children:Ue.map(e=>rt(e))}),children:(0,q.jsx)(Kf,{projects:R,chats:Ee,preferences:re,busy:ae,scopeKey:JSON.stringify([c,be,e,n,A,M,P,I]),onMoveSession:Qe,onMoveSection:$e,children:e=>Ue.map(t=>rt(t,e))})}):Ue.map(e=>rt(e)),!be&&ke.length>0?(0,q.jsxs)(`div`,{className:`mb-1`,children:[(0,q.jsxs)(`button`,{type:`button`,"aria-expanded":Re.olderExpanded,"aria-controls":`${ue}-older`,className:`mt-2 flex select-none w-full items-center gap-1 rounded-md px-2 py-2 text-left text-xs font-medium text-muted-foreground outline-none hover:bg-sidebar-accent hover:text-foreground`,onClick:()=>Be(e=>({...e,olderExpanded:!e.olderExpanded})),children:[(0,q.jsx)(ve,{"aria-hidden":`true`,className:G(`size-3 shrink-0 feedback-motion transition-transform`,Re.olderExpanded&&`rotate-90`)}),(0,q.jsx)(`span`,{children:y(`earlier_c56a5bb6`)}),(0,q.jsxs)(`span`,{className:`ml-auto whitespace-nowrap pl-2 font-normal`,children:[y(`count_days`,{count:ke.length}),` · `,y(`project_sessions`,{count:We})]})]}),(0,q.jsx)(`div`,{id:`${ue}-older`,hidden:!Re.olderExpanded,children:Re.olderExpanded?ke.map(e=>rt(e)):null})]}):null]}),(0,q.jsxs)(`div`,{className:`p-2`,children:[v&&(0,q.jsxs)(W,{variant:`ghost`,className:`w-full justify-start gap-2`,onClick:()=>{v(),t()},children:[(0,q.jsx)(Me,{className:`size-4`}),y(`worktrees_title`)]}),(0,q.jsxs)(W,{variant:`ghost`,className:`w-full justify-start gap-2`,onClick:()=>{g(),t()},children:[(0,q.jsx)(hr,{className:`size-4`}),y(`system_settings_68ea5dd4`)]})]})]}),(0,q.jsx)(Nf,{metadataError:L,project:O?R[O]??null:null,onClose:()=>k(null),onOpenSession:d?async(e,n)=>{let r=await d(e,n);return r&&(k(null),t()),r}:void 0}),(0,q.jsx)(kf,{projectId:A,onClose:()=>j(null)}),(0,q.jsx)(Ff,{projectId:M,existingSections:M?En(re,M,R[M]?.section):[],mode:E,busy:!!M&&ae.has(M),saveError:M?oe[M]:null,unavailable:!!M&&R[M]?.sidebar===void 0,onCreate:e=>{let t=`section:${crypto.randomUUID()}`;return M?ie(M,n=>Sn(n,M,e,R[M]?.section,t)):Promise.resolve(!1)},onRemove:e=>M?ie(M,t=>An(t,M,e,R[M]?.section)):Promise.resolve(!1),onClose:()=>N(null)},M??`closed`),(0,q.jsx)(Tf,{projectName:Ge?.name??null,busy:I,error:Ge?L:null,onClose:()=>{I||(F(null),te(null))},onConfirm:()=>{!Ge||I||(ee(!0),te(null),H.getState().archiveProject(Ge.id,Ge.revision).then(()=>{F(null)}).catch(e=>{te(e instanceof Error?e.message:y(`could_not_remove_project_1086e674`))}).finally(()=>{ee(!1)}))}})]})}async function $f(e,t,n){if(!await t()||!n.isCurrent())return!1;let r=await n.restore(e);if(!n.isCurrent())return!1;if(!r)throw n.notFound();return n.select(e),!0}function ep({open:e,onClose:t,onOpen:n,onSession:r}){let i=s(),a=H(e=>e.projects),[o,c]=(0,K.useState)(``),[l,u]=(0,K.useState)(null),[d,f]=(0,K.useState)(null),[p,m]=(0,K.useState)(``),[h,g]=(0,K.useState)(``),[_,v]=(0,K.useState)(``),[y,b]=(0,K.useState)(``),[x,S]=(0,K.useState)(``),[C,w]=(0,K.useState)(``),[T,E]=(0,K.useState)(!1),D=(0,K.useRef)(!1),[O,k]=(0,K.useState)(!1),[A,j]=(0,K.useState)(null),[M,N]=(0,K.useState)(null),P=Object.values(a).filter(e=>e.status===`active`),F=P.some(e=>e.id===o)?o:P[0]?.id||``;(0,K.useEffect)(()=>{if(!e)return;let t=!1;return k(!0),j(null),N(null),f(null),u(null),Promise.all([Pe.preferences(),F?Pe.list(F):Promise.resolve(null)]).then(([e,n])=>{t||(u(e),m(e.default_root??``),g(e.project_roots?.[F]??``),f(n),v(n?.repositories.find(e=>!e.error)?.path??``),b(n?.default_root??``))}).catch(e=>{t||j(Dt(e))}).finally(()=>{t||k(!1)}),()=>{t=!0}},[e,F]);let I=async e=>{if(!D.current){D.current=!0,E(!0),j(null);try{await e()}catch(e){j(Dt(e))}finally{D.current=!1,E(!1)}}},ee=async()=>{if(!F)return;let e=await Pe.list(F);f(e),v(t=>e.repositories.some(e=>!e.error&&e.path===t)?t:e.repositories.find(e=>!e.error)?.path??``)},L=e=>I(async()=>{let t=e?h:p,n=await Pe.saveRoot(t.trim()?t:null,e);u(n),m(n.default_root??``),g(n.project_roots?.[F]??``),b(n.project_roots?.[F]??n.default_root??``),await ee()}),te=e=>I(async()=>{if(e.project_owned!==!0){let t=await Vt.getProject(F);t.project_path!==e.path&&!(t.workspace_bindings??[]).some(t=>t.path===e.path)&&await H.getState().bindWorkspace(t.id,t.revision,{path:e.path})}n(F,e.path)});return e?(0,q.jsx)(cn,{open:!0,onOpenChange:e=>{!e&&!T&&t()},children:(0,q.jsxs)(on,{className:`gap-3 p-4`,style:{maxWidth:`56rem`},dismissable:!T,"aria-describedby":`worktrees-description`,children:[(0,q.jsxs)(an,{className:`flex items-center gap-2`,children:[(0,q.jsx)(Me,{className:`size-5`}),i(`worktrees_title`)]}),(0,q.jsx)(`p`,{id:`worktrees-description`,className:`text-sm text-muted-foreground`,children:i(`worktrees_description`)}),A&&(0,q.jsx)(`p`,{role:`alert`,className:`break-words text-sm text-destructive`,children:A}),M&&(0,q.jsx)(`p`,{role:`status`,className:`break-all text-sm`,children:i(`worktrees_created`,{path:M})}),(0,q.jsxs)(`div`,{className:`min-h-0 space-y-4 overflow-y-auto pr-1`,style:{maxHeight:`70dvh`},children:[(0,q.jsxs)(`section`,{className:`space-y-2 rounded-md border p-3`,children:[(0,q.jsx)(`label`,{htmlFor:`worktree-global-root`,className:`text-sm font-medium`,children:i(`worktrees_global_root`)}),(0,q.jsxs)(`div`,{className:`flex gap-2`,children:[(0,q.jsx)(fe,{id:`worktree-global-root`,value:p,disabled:O||T||!l,onChange:e=>m(e.target.value),placeholder:`/Volumes/External/worktree`}),(0,q.jsx)(W,{variant:`outline`,disabled:O||T||!l,onClick:()=>void L(),children:i(`save_a3030bf8`)})]}),(0,q.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:i(`worktrees_root_hint`)})]}),(0,q.jsxs)(`section`,{className:`space-y-3`,children:[(0,q.jsx)(`label`,{htmlFor:`worktree-project`,className:`text-sm font-medium`,children:i(`worktrees_project`)}),(0,q.jsxs)(`select`,{id:`worktree-project`,className:`h-9 w-full rounded-md border bg-background px-2 text-sm`,value:F,disabled:O||T,onChange:e=>{N(null),c(e.target.value)},children:[!P.length&&(0,q.jsx)(`option`,{value:``,children:i(`worktrees_no_projects`)}),P.map(e=>(0,q.jsx)(`option`,{value:e.id,children:e.name},e.id))]}),F&&(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(`label`,{htmlFor:`worktree-project-root`,className:`text-sm`,children:i(`worktrees_project_root`)}),(0,q.jsxs)(`div`,{className:`flex gap-2`,children:[(0,q.jsx)(fe,{id:`worktree-project-root`,value:h,disabled:O||T||!l,onChange:e=>g(e.target.value),placeholder:i(`worktrees_use_global`)}),(0,q.jsx)(W,{variant:`outline`,disabled:O||T||!l,onClick:()=>void L(F),children:i(`save_a3030bf8`)})]})]})]}),O&&(0,q.jsx)(`p`,{role:`status`,children:i(`loading_4927a53b`)}),d&&(0,q.jsxs)(q.Fragment,{children:[(0,q.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,q.jsx)(`h3`,{className:`text-sm font-medium`,children:i(`worktrees_repositories`)}),(0,q.jsxs)(W,{variant:`ghost`,size:`sm`,disabled:T,onClick:()=>void I(ee),children:[(0,q.jsx)(Be,{className:`size-4`}),i(`worktrees_refresh`)]})]}),!d.repositories.length&&(0,q.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:i(`worktrees_no_repositories`)}),d.repositories.map(e=>(0,q.jsxs)(`section`,{className:`space-y-2 rounded-md border p-3`,children:[(0,q.jsx)(`h4`,{className:`break-all text-xs text-muted-foreground`,children:e.path}),e.error&&(0,q.jsx)(`p`,{role:`alert`,className:`break-words text-sm text-destructive`,children:e.error}),e.warnings?.map(e=>(0,q.jsx)(`p`,{role:`status`,className:`break-words text-sm text-muted-foreground`,children:e},e)),e.worktrees.map(e=>(0,q.jsxs)(`article`,{"aria-label":e.path,className:`space-y-2 border-t pt-2 text-sm`,children:[(0,q.jsxs)(`div`,{className:`flex items-start justify-between gap-2`,children:[(0,q.jsxs)(`div`,{className:`min-w-0`,children:[(0,q.jsx)(`div`,{className:`font-medium`,children:e.branch??i(`worktrees_detached`)}),(0,q.jsx)(`div`,{className:`break-all text-xs text-muted-foreground`,children:e.path})]}),(0,q.jsx)(W,{size:`sm`,variant:`outline`,disabled:T||e.prunable||e.path_encoding===`escaped`||e.openable===!1,onClick:()=>void te(e),children:i(`worktrees_open`)})]}),(0,q.jsxs)(`div`,{className:`flex flex-wrap gap-x-3 gap-y-1 text-xs text-muted-foreground`,children:[(0,q.jsx)(`span`,{children:e.dirty===null?i(`worktrees_unknown`):e.dirty?i(`worktrees_dirty`):i(`worktrees_clean`)}),(0,q.jsx)(`span`,{children:e.occupied?i(`worktrees_occupied`):i(`worktrees_idle`)}),e.locked&&(0,q.jsx)(`span`,{children:i(`worktrees_locked`)}),e.prunable&&(0,q.jsx)(`span`,{children:i(`worktrees_unavailable`)})]}),e.error&&(0,q.jsx)(`p`,{role:`alert`,className:`break-words text-xs text-destructive`,children:e.error}),(0,q.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:e.sessions.length?e.sessions.map(e=>(0,q.jsxs)(W,{variant:`ghost`,size:`sm`,disabled:T,onClick:()=>r(e.id),children:[e.title||e.id,e.active?` · ${i(`worktrees_active_session`)}`:``]},e.id)):(0,q.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:i(`worktrees_no_sessions`)})})]},e.path))]},e.path)),(0,q.jsxs)(`form`,{className:`space-y-3 rounded-md border p-3`,onSubmit:e=>{e.preventDefault(),I(async()=>{N((await Pe.create(F,{repository:_,root:y,name:x.trim(),branch:C.trim()})).path),S(``),w(``),await ee()})},children:[(0,q.jsx)(`h3`,{className:`text-sm font-medium`,children:i(`worktrees_create`)}),(0,q.jsx)(`label`,{htmlFor:`worktree-repository`,className:`text-xs`,children:i(`worktrees_repository`)}),(0,q.jsx)(`select`,{id:`worktree-repository`,className:`h-9 w-full rounded-md border bg-background px-2 text-sm`,value:_,disabled:T,onChange:e=>v(e.target.value),children:d.repositories.filter(e=>!e.error).map(e=>(0,q.jsx)(`option`,{value:e.path,children:e.path},e.path))}),(0,q.jsx)(`label`,{htmlFor:`worktree-root`,className:`text-xs`,children:i(`worktrees_create_root`)}),(0,q.jsx)(fe,{id:`worktree-root`,required:!0,value:y,disabled:T,onChange:e=>b(e.target.value)}),(0,q.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,q.jsxs)(`div`,{className:`space-y-1`,children:[(0,q.jsx)(`label`,{htmlFor:`worktree-name`,className:`text-xs`,children:i(`worktrees_folder`)}),(0,q.jsx)(fe,{id:`worktree-name`,required:!0,pattern:`[A-Za-z0-9_-]{1,80}`,value:x,disabled:T,onChange:e=>S(e.target.value)})]}),(0,q.jsxs)(`div`,{className:`space-y-1`,children:[(0,q.jsx)(`label`,{htmlFor:`worktree-branch`,className:`text-xs`,children:i(`worktrees_branch`)}),(0,q.jsx)(fe,{id:`worktree-branch`,required:!0,value:C,disabled:T,onChange:e=>w(e.target.value)})]})]}),(0,q.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:i(`worktrees_target`,{path:`${y.replace(/\/$/,``)}/${x}`})}),(0,q.jsx)(W,{type:`submit`,disabled:T||!_||!y.trim()||!x.trim()||!C.trim(),children:i(`worktrees_create`)})]})]})]})]})}):null}var tp=(e,t)=>Ct(e)?e.status===409?f(`conflict_the_project_was_just_changed_please_try_again_39427e75`):e.status===404?f(`the_project_does_not_exist_or_has_been_deleted_e99cf9dc`):e.message||t:e instanceof Error?e.message:t;function np({onCreated:e}){u();let t=H(e=>e.createProject),[n,r]=(0,K.useState)(``),[i,a]=(0,K.useState)(``),[o,s]=(0,K.useState)(!1),[c,l]=(0,K.useState)(null),d=async()=>{let c=n.trim(),u=i.trim().replace(/\/+$/,``);if(!(!c||!u||o)){s(!0),l(null);try{let n=await uo.validatePath(u);if(!n.is_valid){l(n.error_message||f(`invalid_path_1f83ecf9`));return}e(await t({name:c,project_path:u})),r(``),a(``)}catch(e){l(tp(e,f(`could_not_create_7e6a71ef`)))}finally{s(!1)}}};return(0,q.jsxs)(`div`,{className:`space-y-2 rounded-md border p-3`,children:[(0,q.jsx)(`div`,{className:`text-xs font-medium text-muted-foreground`,children:f(`new_project_0e1a7040`)}),(0,q.jsxs)(`div`,{className:`grid gap-2`,children:[(0,q.jsxs)(`div`,{className:`grid gap-1`,children:[(0,q.jsx)(`label`,{htmlFor:`project-name`,className:`text-xs`,children:f(`name_d44e9b3d`)}),(0,q.jsx)(fe,{id:`project-name`,className:`h-8`,placeholder:f(`e_g_zenith_60cf008b`),value:n,onChange:e=>r(e.target.value)})]}),(0,q.jsxs)(`div`,{className:`grid gap-1`,children:[(0,q.jsx)(`label`,{htmlFor:`project-path`,className:`text-xs`,children:f(`primary_directory_absolute_path_35a7dd77`)}),(0,q.jsx)(fe,{id:`project-path`,className:`h-8`,placeholder:`/Users/you/project`,value:i,onChange:e=>a(e.target.value),onKeyDown:e=>{e.key===`Enter`&&d()}})]})]}),c?(0,q.jsx)(`p`,{className:`text-xs text-destructive`,children:c}):null,(0,q.jsxs)(W,{size:`sm`,className:`w-full`,onClick:d,disabled:!n.trim()||!i.trim()||o,children:[o?(0,q.jsx)(L,{className:`size-4 animate-spin`}):(0,q.jsx)(ze,{className:`size-4`}),` `,f(`create_cde2cd07`)]})]})}function rp({open:e,onClose:t}){u();let{projects:n,projectsLoading:r,projectsError:i,activeProjectId:a,setActiveProjectId:o,archiveProject:s,unarchiveProject:c,bindWorkspace:l,loadProjects:d}=H(Yr(e=>({projects:e.projects,projectsLoading:e.projectsLoading,projectsError:e.projectsError,activeProjectId:e.activeProjectId,setActiveProjectId:e.setActiveProjectId,archiveProject:e.archiveProject,unarchiveProject:e.unarchiveProject,bindWorkspace:e.bindWorkspace,loadProjects:e.loadProjects}))),[p,m]=(0,K.useState)(null),[h,g]=(0,K.useState)(null),[_,v]=(0,K.useState)(null),[y,b]=(0,K.useState)(``);(0,K.useEffect)(()=>{e&&(g(null),H.getState().loadProjects().catch(()=>{}))},[e,d]);let x=(0,K.useMemo)(()=>Object.values(n).sort((e,t)=>e.status===t.status?t.updated_at.localeCompare(e.updated_at):e.status===`active`?-1:1),[n]);if(!e)return null;let S=async(e,t)=>{if(!p){m(e),g(null);try{await t()}catch(e){g(tp(e,f(`operation_failed_0c3b4cf7`)))}finally{m(null)}}},C=async e=>{let t=y.trim().replace(/\/+$/,``);!t||p||await S(e.id,async()=>{let n=await uo.validatePath(t);if(!n.is_valid)throw Error(n.error_message||f(`invalid_path_1f83ecf9`));await l(e.id,e.revision,{path:t}),v(null),b(``)})};return(0,q.jsx)(cn,{open:!0,onOpenChange:e=>{e||t()},children:(0,q.jsxs)(on,{showCloseButton:!1,className:`p-0 sm:max-w-2xl`,children:[(0,q.jsxs)(`div`,{className:`flex items-center justify-between border-b px-4 py-3`,children:[(0,q.jsx)(an,{children:f(`manage_projects_302f96cf`)}),(0,q.jsx)(W,{size:`icon`,variant:`ghost`,onClick:t,children:(0,q.jsx)(He,{})})]}),(0,q.jsxs)(`div`,{className:`min-h-0 flex-1 space-y-3 overflow-y-auto p-4`,children:[i?(0,q.jsx)(`p`,{className:`rounded-md bg-destructive/10 px-2.5 py-2 text-xs text-destructive`,children:i}):null,h?(0,q.jsx)(`p`,{className:`rounded-md bg-destructive/10 px-2.5 py-2 text-xs text-destructive`,children:h}):null,(0,q.jsx)(np,{onCreated:()=>g(null)}),r&&x.length===0?(0,q.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:f(`loading_4927a53b`)}):x.length===0?(0,q.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:f(`no_projects_yet_4550442e`)}):(0,q.jsx)(`ul`,{className:`space-y-2`,children:x.map(e=>{let t=e.status===`archived`,n=a===e.id;return(0,q.jsxs)(`li`,{className:G(`rounded-md border p-3`,t&&`opacity-60`),children:[(0,q.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,q.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,q.jsx)(`span`,{className:`truncate text-sm font-medium`,children:e.name}),t?(0,q.jsx)(`span`,{className:`rounded bg-muted px-1.5 py-0.5 text-[10px] text-muted-foreground`,children:f(`archived_82395d42`)}):null]}),(0,q.jsx)(`div`,{className:`truncate text-xs text-muted-foreground`,title:e.project_path??void 0,children:e.project_path||f(`no_primary_directory_configured_095fa19f`)}),e.workspace_bindings.length>0?(0,q.jsx)(`div`,{className:`mt-1 space-y-0.5`,children:e.workspace_bindings.map(e=>(0,q.jsxs)(`div`,{className:`truncate text-[11px] text-muted-foreground`,children:[`+ `,e.path]},e.path))}):null]}),p===e.id?(0,q.jsx)(L,{className:`size-4 shrink-0 animate-spin text-muted-foreground`}):n?(0,q.jsx)(de,{className:`size-4 shrink-0 text-primary`}):null]}),(0,q.jsxs)(`div`,{className:`mt-2 flex flex-wrap items-center gap-1.5`,children:[t?null:(0,q.jsx)(W,{size:`sm`,variant:`outline`,className:`h-7 px-2 text-xs`,disabled:n||!!p,onClick:()=>o(e.id),children:f(n?`current_default_f50585ee`:`set_as_default_35721109`)}),t?null:(0,q.jsxs)(W,{size:`sm`,variant:`ghost`,className:`h-7 px-2 text-xs`,disabled:!!p,onClick:()=>{v(_===e.id?null:e.id),b(``)},children:[(0,q.jsx)(Cr,{className:`size-3.5`}),f(`attach_directory_66c84cb7`)]}),(0,q.jsx)(W,{size:`sm`,variant:`ghost`,className:`h-7 px-2 text-xs`,disabled:!!p,onClick:()=>S(e.id,()=>t?c(e.id,e.revision):s(e.id,e.revision)),children:t?(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(nr,{className:`size-3.5`}),f(`restore_e0534b8a`)]}):(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(rr,{className:`size-3.5`}),f(`archive_5292ab1a`)]})})]}),_===e.id?(0,q.jsxs)(`div`,{className:`mt-2 flex gap-2`,children:[(0,q.jsx)(fe,{className:`h-8 flex-1`,placeholder:f(`absolute_working_directory_path_b1c49808`),value:y,autoFocus:!0,onChange:e=>b(e.target.value),onKeyDown:t=>{t.key===`Enter`&&C(e)}}),(0,q.jsx)(W,{size:`sm`,className:`h-8`,onClick:()=>void C(e),disabled:!y.trim()||!!p,children:f(`attach_3dd97f4d`)})]}):null]},e.id)})})]})]})})}function ip({pending:e,onCancel:t,onConfirm:n}){return u(),(0,q.jsx)(cn,{open:!!e,onOpenChange:e=>{e||t()},children:(0,q.jsxs)(on,{showCloseButton:!1,className:`p-5`,children:[(0,q.jsx)(an,{children:f(`delete_session_d51250d1`)}),(0,q.jsx)(`p`,{className:`mt-2 text-sm leading-relaxed text-muted-foreground`,children:f(`delete_session_description`,{title:e?.title??``})}),(0,q.jsxs)(`div`,{className:`mt-5 flex justify-end gap-2`,children:[(0,q.jsx)(W,{variant:`secondary`,onClick:t,children:f(`cancel_2cd0f3be`)}),(0,q.jsx)(W,{variant:`destructive`,onClick:()=>{e&&n(e.id)},children:f(`delete_2f9daa82`)})]})]})})}function ap({offer:e,disabled:t,stopDisabled:n=!1,refreshDisabled:r=!1,onConfirm:i,onStop:a,onRefresh:o}){if(u(),!e)return null;let s=e.status===`waiting`?f(`live_retry_waiting`,{seconds:e.secondsRemaining}):e.status===`confirming`?f(`live_retry_confirming`):e.status===`continued`?f(`live_retry_continued`):e.status===`expired`?f(`live_retry_expired`):e.status===`unavailable`?f(`live_retry_unavailable`):e.status===`unconfirmed`?f(`live_retry_unconfirmed`):e.status===`identity_unavailable`?f(`live_retry_identity_unavailable`):e.status===`stopping`?f(`live_retry_stopping`):e.status===`stop_requested`?f(`upstream_retry_stop_requested`):f(`upstream_retry_stop_unconfirmed`),c=[`waiting`,`confirming`,`continued`,`unconfirmed`].includes(e.status),l=[`stop_unconfirmed`,`identity_unavailable`].includes(e.status);return(0,q.jsxs)(`div`,{role:`status`,"aria-live":`polite`,className:`mx-4 mb-2 text-xs text-muted-foreground`,children:[(0,q.jsx)(`p`,{children:s}),e.status===`waiting`||c||l?(0,q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[e.status===`waiting`?(0,q.jsx)(W,{size:`sm`,variant:`outline`,disabled:t,onClick:i,children:f(`upstream_retry_until_stopped`)}):null,c?(0,q.jsx)(W,{size:`sm`,variant:`outline`,disabled:n,onClick:a,children:f(`stop_generation_9ad0aac3`)}):null,l?(0,q.jsx)(W,{size:`sm`,variant:`outline`,disabled:r,onClick:o,children:f(`live_retry_refresh`)}):null]}):null]})}var op=/^Moved command `([^`]+)` to background monitoring\./;function sp(e,t){if(e&&typeof e==`object`&&e.runtime_kind===`background_exec_wait`){let t=e.exec_session_id;return{runtimeKind:`background_exec_wait`,execSessionId:typeof t==`string`&&t?t:void 0}}let n=t??``;if(!n)return null;let r=n.match(op);return r?{runtimeKind:`background_exec_wait`,execSessionId:r[1]}:null}function cp(e){let t=e[e.length-1];return t?t.metadata?.runtime_kind===`background_exec_wait`?!0:typeof t.content==`string`&&!!t.content.match(op):!1}async function lp(){let e;try{e=await Ot.get(`execute/defaults`,{cache:`no-store`})}catch{return null}if(!e||typeof e!=`object`||Array.isArray(e))return null;let t=e;if(!t.upstream_retry||typeof t.upstream_retry!=`object`||Array.isArray(t.upstream_retry)||!t.live_bootstrap_resume||typeof t.live_bootstrap_resume!=`object`||Array.isArray(t.live_bootstrap_resume))return null;let n=t.upstream_retry,r=t.live_bootstrap_resume;return!Array.isArray(n.supported_modes)||!n.supported_modes.every(e=>typeof e==`string`)||!n.supported_modes.includes(`until_cancelled`)||r.protocol_version!==1||r.waiting_endpoint!==`execute/{session_id}/retry`||r.continue_run_header!==`Bamboo-Run-Id`||r.initial_opt_in_field!==`live_bootstrap_resume`||!Number.isSafeInteger(r.offer_timeout_ms)||r.offer_timeout_ms<=0?null:{offerTimeoutMs:r.offer_timeout_ms}}async function up(e,t){let n=await Ot.get(`execute/${encodeURIComponent(e)}/retry`,{cache:`no-store`});if(!n||typeof n!=`object`||Array.isArray(n))throw Error(`Invalid retry offer`);let r=n;if(r.session_id!==e)throw Error(`Retry offer belongs to another session`);if(r.status===`unavailable`&&r.run_id===void 0)return{kind:`unavailable`};if(r.status!==`retry_waiting`||!It(r.run_id)||!Number.isSafeInteger(r.expires_in_ms)||r.expires_in_ms<0||r.expires_in_ms>t||typeof r.confirming!=`boolean`)throw Error(`Invalid retry offer`);return{kind:`waiting`,runId:r.run_id,expiresInMs:r.expires_in_ms,confirming:r.confirming}}async function dp(e,t){if(!It(t))throw Error(`Invalid retry run identity`);let n=await Ot.postOnce(`execute/${encodeURIComponent(e)}`,{upstream_retry:{mode:`until_cancelled`}},{headers:{"Bamboo-Run-Id":t}});if(!n||typeof n!=`object`||Array.isArray(n))throw Error(`Invalid retry confirmation`);let r=n;if(r.session_id!==e||r.run_id!==t||r.status!==`retry_continuing`)throw Error(`Retry confirmation did not match the selected run`)}function fp(e,t){if(!Ct(e)||e.status!==409||!e.body)return!1;try{let n=JSON.parse(e.body);if(!n||typeof n!=`object`||Array.isArray(n)||Object.hasOwn(n,`run_id`))return!1;let r=n;return r.session_id===t&&!!r.error&&typeof r.error==`object`&&!Array.isArray(r.error)&&r.error.code===`retry_resume_not_prepared`}catch{return!1}}var pp=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i,mp=e=>`lotus-next.live-bootstrap-confirm.v1.${encodeURIComponent(JSON.stringify([wt(),e]))}`;function hp(e){try{let t=JSON.parse(e);if(!t||typeof t!=`object`||Array.isArray(t))return null;let n=t;return n.version===1&&It(n.runId)&&typeof n.operationId==`string`&&pp.test(n.operationId)&&(n.state===`pending`||n.state===`accepted`)?n:null}catch{return null}}function gp(e,t){try{let n=sessionStorage.getItem(mp(e));if(n===null)return`clear`;let r=hp(n);return r?r.runId===t?r.state:`clear`:`unavailable`}catch{return`unavailable`}}function _p(e,t){if(!It(t))return null;try{let n=mp(e),r=sessionStorage.getItem(n),i=r===null?null:hp(r);if(r!==null&&(!i||i.runId===t))return null;let a=crypto.randomUUID();if(!pp.test(a))return null;let o=JSON.stringify({version:1,runId:t,operationId:a,state:`pending`});return sessionStorage.getItem(n)===r?(sessionStorage.setItem(n,o),sessionStorage.getItem(n)===o?{key:n,pending:o}:null):null}catch{return null}}function vp(e,t){try{if(sessionStorage.getItem(e.key)!==e.pending)return!1;if(t===`unknown`)return!0;if(t===`refused`)sessionStorage.removeItem(e.key);else{let t=hp(e.pending);if(!t)return!1;sessionStorage.setItem(e.key,JSON.stringify({...t,state:`accepted`}))}return!0}catch{return!1}}var yp=5e3;function bp(e,t,n){let[r,i]=(0,K.useState)(null),[a,o]=(0,K.useState)(null),s=(0,K.useRef)(null),c=(0,K.useRef)(null),l=(0,K.useRef)(null),u=(0,K.useRef)(null),d=(0,K.useRef)(null),f=(0,K.useRef)(!1),p=(0,K.useRef)({sessionId:e,running:t,root:n,epoch:0});(p.current.sessionId!==e||p.current.running!==t||p.current.root!==n)&&(p.current={sessionId:e,running:t,root:n,epoch:p.current.epoch+1},l.current=null,u.current=null,d.current=null);let m=(0,K.useCallback)(e=>{s.current=e,o(e)},[]),h=(0,K.useCallback)((e,t,n,r)=>{let i=Zo(e,t.sessionId);if(i.kind===`confirmed`&&i.runId!==t.runId){m(null);return}if(i.kind!==`confirmed`){m({...t,status:`identity_unavailable`,secondsRemaining:0});return}m({...t,status:n,...r===void 0?{}:{secondsRemaining:r}})},[m]),g=wt(),_=n&&r?.scope===g;(0,K.useEffect)(()=>(f.current=!0,()=>{f.current=!1,l.current=null,u.current=null}),[]),(0,K.useEffect)(()=>{let r=s.current;r&&(!n||r.sessionId!==e||!t&&r.status!==`expired`)&&m(null)},[e,t,n,m]);let v=(0,K.useCallback)(e=>{let t={scope:e,promise:lp()};return c.current=t,t.promise.then(n=>{c.current===t&&(c.current=null,f.current&&p.current.root&&e===wt()&&i(n?{scope:e,value:n}:null))}),t},[]);(0,K.useEffect)(()=>{if(!n){c.current=null,i(null);return}let e=v(wt());return()=>{c.current===e&&(c.current=null)}},[n,v]);let y=(0,K.useCallback)(()=>{let e=p.current,t=wt();if(!f.current||!n||!e.root)return!1;if(r?.scope===t)return!0;let i=c.current,a=i?.scope===t?i:v(t);return new Promise(n=>{let r=!1,i=e=>{r||(r=!0,clearTimeout(o),n(e))},o=setTimeout(()=>i(!1),750);a.promise.then(n=>i(!!n&&f.current&&p.current.epoch===e.epoch&&p.current.root&&t===wt()),()=>i(!1))})},[r,n,v]);(0,K.useEffect)(()=>{if(!e||!t||!n||!r||r.scope!==wt())return;let i=!0,a,o=p.current.epoch,c=async()=>{let t=performance.now();try{let n=await up(e,r.value.offerTimeoutMs);if(!i||p.current.epoch!==o||r.scope!==wt())return;let a=s.current;if(n.kind===`unavailable`)a?.sessionId===e&&![`continued`,`unconfirmed`,`stopping`,`stop_requested`,`stop_unconfirmed`].includes(a.status)&&m({...a,status:performance.now()>=a.deadline?`expired`:`unavailable`,secondsRemaining:0});else if(d.current!==JSON.stringify([e,n.runId])){l.current?.epoch===o&&l.current.runId!==n.runId&&(l.current=null),u.current?.epoch===o&&u.current.runId!==n.runId&&(u.current=null);let i=t+n.expiresInMs,s=a?.sessionId===e&&a.runId===n.runId?Math.min(a.deadline,i):i,c=Math.max(0,Math.ceil((s-performance.now())/1e3)),d=Zo(r.scope,e),f=gp(e,n.runId),p=c===0?`expired`:f===`pending`?`unconfirmed`:f===`accepted`?`continued`:f===`unavailable`||d.kind!==`confirmed`||d.runId!==n.runId?`identity_unavailable`:n.confirming?`confirming`:`waiting`;l.current?.epoch===o&&l.current.runId===n.runId||m({sessionId:e,runId:n.runId,status:p,secondsRemaining:c,deadline:s})}}catch{i&&p.current.epoch===o&&s.current?.sessionId===e&&s.current.status===`waiting`&&m({...s.current,status:`unavailable`})}i&&p.current.epoch===o&&(a=setTimeout(c,yp))};return c(),()=>{i=!1,a&&clearTimeout(a)}},[r,n,t,e,m]);let b=a?.sessionId,x=a?.runId,S=a?.status;(0,K.useEffect)(()=>{if(S!==`waiting`||b!==e)return;let t=setInterval(()=>{let t=s.current;if(!t||t.sessionId!==e||t.runId!==x||t.status!==`waiting`)return;let n=Math.max(0,Math.ceil((t.deadline-performance.now())/1e3));n!==t.secondsRemaining&&m({...t,secondsRemaining:n,status:n===0?`expired`:`waiting`})},1e3);return()=>clearInterval(t)},[b,x,S,e,m]);let C=(0,K.useCallback)(async()=>{let e=s.current,t=p.current;if(!e||e.status!==`waiting`||e.sessionId!==t.sessionId||!t.running||!t.root||!r||r.scope!==wt()||l.current)return;let n={epoch:t.epoch,runId:e.runId};l.current=n,m({...e,status:`confirming`});let i=()=>f.current&&p.current.epoch===n.epoch&&l.current===n&&s.current?.sessionId===e.sessionId&&s.current.runId===n.runId&&r.scope===wt(),a=(t,n)=>{i()&&h(r.scope,e,t,n)};try{let t=await lp();if(!i())return;if(!t){a(`unavailable`);return}let n=performance.now(),o=await up(e.sessionId,t.offerTimeoutMs);if(!i())return;let s=Zo(r.scope,e.sessionId);if(o.kind!==`waiting`||o.runId!==e.runId||o.confirming||o.expiresInMs<=0||performance.now()>=Math.min(e.deadline,n+o.expiresInMs)||s.kind!==`confirmed`||s.runId!==e.runId){a(performance.now()>=e.deadline?`expired`:`unavailable`,0);return}let c=_p(e.sessionId,e.runId);if(!c){a(`unconfirmed`);return}try{await dp(e.sessionId,e.runId),vp(c,`accepted`),a(`continued`)}catch(t){let n=fp(t,e.sessionId);vp(c,n?`refused`:`unknown`),a(n?`unavailable`:`unconfirmed`)}}catch{a(`unavailable`)}finally{l.current===n&&(l.current=null)}},[r,h,m]),w=(0,K.useCallback)(()=>{l.current=null,u.current=null;let e=s.current;!e||e.sessionId!==p.current.sessionId||(d.current=JSON.stringify([e.sessionId,e.runId]),m({...e,status:`stopping`}))},[m]),T=(0,K.useCallback)(async()=>{let e=s.current,t=p.current;if(!e||e.sessionId!==t.sessionId||!t.running||!t.root||[`stopping`,`stop_requested`,`identity_unavailable`,`expired`,`unavailable`].includes(e.status))return;let n=Zo(wt(),e.sessionId);if(n.kind!==`confirmed`||n.runId!==e.runId){m({...e,status:`identity_unavailable`});return}let r=wt();w();let i={epoch:t.epoch,runId:e.runId};u.current=i;let a=()=>f.current&&p.current.epoch===i.epoch&&u.current===i&&s.current?.sessionId===e.sessionId&&r===wt(),o=()=>a()&&s.current?.runId===i.runId,c=t=>{o()&&h(r,e,t)},l=async()=>{let t=await lp();if(!t||!a())return!1;let n=await up(e.sessionId,t.offerTimeoutMs);if(!a()||n.kind!==`waiting`)return!1;let o=Zo(r,e.sessionId);if(o.kind!==`confirmed`||o.runId!==n.runId)return!1;let s={epoch:i.epoch,runId:n.runId};u.current=s,d.current=JSON.stringify([e.sessionId,n.runId]);try{return await zt.stopGeneration(e.sessionId,n.runId),u.current===s&&h(r,{...e,runId:n.runId},`stop_requested`),u.current===s&&(u.current=null),!0}catch{return u.current===s&&(h(r,{...e,runId:n.runId},`stop_unconfirmed`),u.current=null),!0}};try{let t=await lp();if(!o())return;let n=Zo(r,e.sessionId);if(!t||n.kind!==`confirmed`||n.runId!==e.runId){try{if(await l())return}catch{}c(`stop_unconfirmed`);return}await zt.stopGeneration(e.sessionId,e.runId),c(`stop_requested`)}catch{try{if(await l())return}catch{}c(`stop_unconfirmed`)}finally{u.current===i&&(u.current=null)}},[w,h,m]),E=(0,K.useCallback)(async()=>{let e=s.current,t=p.current;if(!e||e.sessionId!==t.sessionId||!t.root)return;let n=wt(),r=t.epoch,i=()=>f.current&&p.current.epoch===r&&n===wt();try{let t=await lp();if(!t||!i())return;let r=performance.now(),a=await up(e.sessionId,t.offerTimeoutMs);if(!i())return;if(a.kind===`unavailable`){m(null);return}if(l.current||u.current||d.current===JSON.stringify([e.sessionId,a.runId])&&s.current?.status!==`stop_unconfirmed`)return;d.current=null;let o=r+a.expiresInMs,c=Math.max(0,Math.ceil((o-performance.now())/1e3)),f=Zo(n,e.sessionId),p=gp(e.sessionId,a.runId),h=c===0?`expired`:p===`pending`?`unconfirmed`:p===`accepted`?`continued`:p===`unavailable`||f.kind!==`confirmed`||f.runId!==a.runId?`identity_unavailable`:a.confirming?`confirming`:`waiting`;m({sessionId:e.sessionId,runId:a.runId,status:h,secondsRemaining:c,deadline:o})}catch{}},[m]);return{canPrepare:!!_,prepareInitial:y,offer:n&&a?.sessionId===e?a:null,confirm:C,stop:T,refresh:E,cancelForStop:w}}function xp(e){try{let t=JSON.parse(e.getData(Tn));return!t||typeof t!=`object`||!(`sessionId`in t)||!(`projectId`in t)||typeof t.sessionId!=`string`||!t.sessionId.trim()||t.projectId!==null&&(typeof t.projectId!=`string`||!t.projectId.trim())?null:{sessionId:t.sessionId,projectId:t.projectId}}catch{return null}}function Sp(e,t){let[n,r]=(0,K.useState)(!1);(0,K.useEffect)(()=>{let e=()=>r(!1);return window.addEventListener(`dragend`,e),window.addEventListener(`drop`,e),()=>{window.removeEventListener(`dragend`,e),window.removeEventListener(`drop`,e)}},[]);let i=e=>e.dataTransfer.types.includes(`application/x-lotus-sidebar-session`)&&!e.dataTransfer.types.includes(`Files`);return{active:n,handlers:{onDragOverCapture:e=>{i(e)&&(e.preventDefault(),e.stopPropagation(),e.dataTransfer.dropEffect=`copy`,r(!0))},onDragLeaveCapture:e=>{(!(e.relatedTarget instanceof Node)||!e.currentTarget.contains(e.relatedTarget))&&r(!1)},onDropCapture:n=>{if(r(!1),!i(n))return;n.preventDefault(),n.stopPropagation();let a=xp(n.dataTransfer);if(!a)return;let o=e.find(e=>e.id===a.sessionId);!o||o.parentSessionId||o.kind&&o.kind!==`root`||(o.config?.projectId?.trim()||null)===a.projectId&&t(o.id)}}}}function Cp({title:e,description:t,actions:n,disabled:r=!1,children:i,footer:a}){let o=(0,K.useRef)(null);return(0,q.jsx)(cn,{open:!0,children:(0,q.jsxs)(on,{ref:o,dismissable:!1,showCloseButton:!1,className:`overflow-y-auto p-5 sm:pb-5`,"data-approval-presentation":!0,onOpenAutoFocus:e=>{e.preventDefault(),o.current?.focus()},onKeyDownCapture:e=>{e.key===`Enter`&&(e.repeat||e.nativeEvent.isComposing)&&(e.preventDefault(),e.stopPropagation())},children:[(0,q.jsx)(an,{children:e}),(0,q.jsx)(sn,{className:`mt-2 whitespace-pre-wrap break-words text-sm leading-relaxed text-foreground`,children:t}),i,(0,q.jsx)(`div`,{className:`mt-4 flex flex-col gap-2`,children:n.map(e=>(0,q.jsx)(W,{variant:`secondary`,className:`h-auto justify-start whitespace-normal py-2 text-left`,disabled:r,onClick:e.onSelect,children:e.label},e.id))}),a]})})}function wp({q:e,onAnswer:t,loading:n=!1,submitting:r=!1,unavailable:i=!1,error:a=null,canRetry:o=!1,onRefresh:s,onRetry:c}){u();let l=e.interaction_kind===`permission`?e.permission_request:null,d=JSON.stringify([e.interaction_kind,e.tool_call_id,l?.request_generation]),[p,m]=(0,K.useState)({identity:d,text:``}),h=p.identity===d?p.text:``,g=n||r||i||o,_=l?[{value:`allow_once`,label:f(`allow_once_390dd1fc`)},{value:`deny_once`,label:f(`deny_once_29b8bbf3`)}].filter(e=>l.allowed_decisions.includes(e.value)):e.options.map(e=>({value:e,label:e})),v=(0,q.jsxs)(q.Fragment,{children:[r||n?(0,q.jsx)(`p`,{role:`status`,className:`mt-3 text-sm text-muted-foreground`,children:f(r?`submitting_26ef00b7`:`refreshing_71659de8`)}):null,a?(0,q.jsx)(`p`,{role:`alert`,className:`mt-3 text-sm text-destructive`,children:a}):null,l&&_.length===0?(0,q.jsx)(`p`,{className:`mt-3 text-sm text-muted-foreground`,children:f(`no_action_choices_are_available_for_this_request_refres_7be8bf22`)}):null,(0,q.jsxs)(`div`,{className:`mt-3 flex gap-2`,children:[(0,q.jsx)(W,{variant:`outline`,disabled:n||r,onClick:s,children:f(`refresh_request_0ab317cc`)}),o?(0,q.jsx)(W,{variant:`secondary`,disabled:n||r,onClick:c,children:f(`retry_last_submission_2970e28a`)}):null]})]});return l?(0,q.jsx)(Cp,{title:f(`action_approval_required_3bd71c54`),description:e.question,disabled:g,actions:_.map(e=>({id:e.value,label:e.label,onSelect:()=>t(e.value)})),footer:v},JSON.stringify([l.session_id,l.request_id,l.request_generation,l.policy_revision])):(0,q.jsx)(cn,{open:!0,children:(0,q.jsxs)(on,{dismissable:!1,showCloseButton:!1,className:`p-5`,children:[(0,q.jsx)(an,{children:f(`your_confirmation_is_needed_383ebd59`)}),(0,q.jsx)(sn,{className:`mt-2 whitespace-pre-wrap text-sm leading-relaxed text-foreground`,children:e.question}),(0,q.jsx)(`div`,{className:`mt-4 flex flex-col gap-2`,children:_.map(e=>(0,q.jsx)(W,{variant:`secondary`,className:`h-auto justify-start whitespace-normal py-2 text-left`,disabled:g,onClick:()=>t(e.value),children:e.label},e.value))}),e.allow_custom?(0,q.jsxs)(`div`,{className:`mt-3`,children:[(0,q.jsx)(Mn,{value:h,disabled:g,onChange:e=>m({identity:d,text:e.target.value}),placeholder:f(`or_type_a_custom_response_ba17604e`),rows:2,className:`rounded-lg border px-3 py-2`}),(0,q.jsx)(W,{className:`mt-2 w-full`,disabled:g||!h.trim(),onClick:()=>t(h.trim()),children:f(`submit_answer_0c1762dd`)})]}):null,v]})})}function Tp({a:e,onRespond:t,submitting:n=!1,error:r=null}){return u(),(0,q.jsx)(Cp,{title:f(`subagent_approval_request_4321e83b`),description:f(`a_subagent_requests_approval_for_an_operation_940aa95b`),disabled:n,footer:(0,q.jsxs)(q.Fragment,{children:[n?(0,q.jsx)(`p`,{role:`status`,className:`mt-3 text-sm text-muted-foreground`,children:f(`submitting_26ef00b7`)}):null,r?(0,q.jsx)(`p`,{role:`alert`,className:`mt-3 text-sm text-destructive`,children:r}):null]}),actions:[{id:`deny`,label:f(`deny_136de7a8`),onSelect:()=>t(!1)},{id:`approve`,label:f(`approve_8cbe697b`),onSelect:()=>t(!0)}],children:(0,q.jsxs)(`div`,{className:`mt-3 space-y-1 rounded-lg border p-3 text-sm`,children:[e.toolName?(0,q.jsxs)(`div`,{children:[(0,q.jsx)(`span`,{className:`text-muted-foreground`,children:f(`tool_3e990ad5`)}),` `,e.toolName]}):null,e.permission?(0,q.jsxs)(`div`,{children:[(0,q.jsx)(`span`,{className:`text-muted-foreground`,children:f(`permission_5ab9623e`)}),` `,e.permission]}):null,e.resource?(0,q.jsxs)(`div`,{className:`break-all`,children:[(0,q.jsx)(`span`,{className:`text-muted-foreground`,children:f(`resource_05e94286`)}),` `,e.resource]}):null]})},JSON.stringify([e.childSessionId,e.requestId]))}function Ep(e){return e===`user`?f(`user_0d0e1a86`):e===`assistant`?f(`assistant_e5ce5f6d`):e===`system`?f(`system_5b50d7c4`):e}function Dp(e){return`content`in e&&typeof e.content==`string`?e.content:``}function Op(e,t){let n=[`# ${t}`,``];for(let t of e){let e=Dp(t);e&&n.push(`## ${Ep(t.role)}`,``,e,``)}return n.join(`
|
|
6
|
+
`)}function kp(e,t){let n=Op(e,t||`chat`),r=new Blob([n],{type:`text/markdown;charset=utf-8`}),i=URL.createObjectURL(r),a=document.createElement(`a`);a.href=i,a.download=`${t||`chat`}.md`,a.click(),URL.revokeObjectURL(i)}function Ap(){let e=document.createElement(`div`);e.style.position=`fixed`,e.style.inset=`0`,e.style.zIndex=`2147483647`,e.style.background=`rgba(0,0,0,0.35)`,e.style.display=`flex`,e.style.alignItems=`center`,e.style.justifyContent=`center`,e.style.fontFamily=`system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif`,e.style.fontSize=`14px`;let t=document.createElement(`div`);t.style.background=`#fff`,t.style.color=`#111`,t.style.border=`1px solid rgba(0,0,0,0.12)`,t.style.borderRadius=`10px`,t.style.padding=`12px 16px`,t.style.maxWidth=`80vw`,t.style.boxShadow=`0 8px 24px rgba(0,0,0,0.12)`,t.textContent=f(`exporting_pdf_9bdbbc51`),e.appendChild(t),document.body.appendChild(e);let n=!1,r=()=>{n||(n=!0,e.remove())};return{remove:r,fail(n){t.textContent=n,t.style.color=`#dc2626`,e.style.cursor=`pointer`,e.addEventListener(`click`,r),window.setTimeout(r,6e3)}}}async function jp(e,t){if(typeof document>`u`)return;let n=Ap();try{let{renderConversationPdf:r}=await o(async()=>{let{renderConversationPdf:e}=await import(`./renderPdf-Cug6wuGM.js`);return{renderConversationPdf:e}},__vite__mapDeps([58,1,2,4,59,60,61,62,63,3,44,42,64,65]),import.meta.url);await r(Op(e,t||`chat`),t||`chat`),n.remove()}catch(e){console.error(`PDF export failed:`,e),n.fail(f(`could_not_export_pdf_0c1eb07c`,{v0:e instanceof Error?e.message:String(e)}))}}function Mp(e){let[t,n]=(0,K.useState)(null),[r,i]=(0,K.useState)(null),a=(0,K.useRef)(!0),o=(0,K.useRef)(0),s=(0,K.useRef)(0),c=(0,K.useRef)(!1),[l,u]=(0,K.useState)(!0),d=(0,K.useCallback)(()=>{if(!t||!a.current)return;let e=Math.max(0,t.scrollHeight-t.clientHeight);t.scrollTop!==e&&t.scrollTo({top:e,behavior:`instant`}),o.current=t.scrollTop,u(!0)},[t]),f=()=>{if(t){if(t.scrollHeight-t.scrollTop-t.clientHeight<=2)a.current=!0;else if(t.scrollTop<o.current-1&&(c.current||Date.now()<s.current))a.current=!1;else if(a.current){d();return}o.current=t.scrollTop,u(a.current)}},p=()=>{a.current=!0,s.current=0,c.current=!1,d()};return(0,K.useLayoutEffect)(()=>{if(a.current=!0,s.current=0,c.current=!1,u(!0),d(),!t||!r)return;let e=new ResizeObserver(d);e.observe(r),e.observe(t);let n=e=>{if(!e.defaultPrevented){for(let n=e.target instanceof Element?e.target:null;n&&n!==t;n=n.parentElement)if(n.scrollTop>0&&/^(auto|scroll)$/.test(getComputedStyle(n).overflowY))return;s.current=Date.now()+500,t.scrollTop>0&&(a.current=!1,u(!1))}},i=e=>{e.deltaY<0&&n(e)},o=e=>{let n=t.getBoundingClientRect().right;e.button===0&&e.target===t&&e.clientX>=n-16&&e.clientX<=n&&(c.current=!0)},l=()=>{c.current&&(s.current=Date.now()+500),c.current=!1},f=null,p=e=>{f=e.touches[0]?.clientY??null},m=e=>{let t=e.touches[0]?.clientY??null;t!==null&&f!==null&&t>f&&n(e),f=t},h=e=>{e.target instanceof Element&&e.target.closest(`input, textarea, select, [contenteditable=true]`)||([`ArrowUp`,`PageUp`,`Home`].includes(e.key)||e.key===` `&&e.shiftKey)&&n(e)};t.addEventListener(`wheel`,i,{passive:!0}),t.addEventListener(`pointerdown`,o,{passive:!0}),t.addEventListener(`touchstart`,p,{passive:!0}),t.addEventListener(`touchmove`,m,{passive:!0}),t.addEventListener(`keydown`,h);let g=t.ownerDocument.defaultView;return g?.addEventListener(`pointerup`,l),g?.addEventListener(`pointercancel`,l),()=>{e.disconnect(),t.removeEventListener(`wheel`,i),t.removeEventListener(`pointerdown`,o),t.removeEventListener(`touchstart`,p),t.removeEventListener(`touchmove`,m),t.removeEventListener(`keydown`,h),g?.removeEventListener(`pointerup`,l),g?.removeEventListener(`pointercancel`,l)}},[t,r,e,d]),{scrollRef:n,contentRef:i,atBottom:l,handleScroll:f,scrollToBottom:p,pinToBottom:p}}function Np(e){return Number.isSafeInteger(e)&&e>=0}function Pp(e,t){return!e||!Np(e.root_tool_authority_revision)||e.operation_id!==t.operationId||e.expected_epoch!==t.expectedEpoch?!1:e.status===`fenced_by_successor`?Np(e.current_epoch)&&e.current_epoch>t.expectedEpoch&&typeof e.current_enabled==`boolean`&&Pt(e.current_thinking_mode)&&e.current_thinking_mode===`ultra`===e.current_enabled:[`committed`,`fenced`,`rejected_incompatible`].includes(e.status)&&e.operation_id===t.operationId&&e.expected_epoch===t.expectedEpoch&&e.resulting_epoch===t.expectedEpoch+1&&typeof e.enabled_at_completion==`boolean`&&Pt(e.thinking_mode_at_completion)&&e.thinking_mode_at_completion===`ultra`===e.enabled_at_completion&&(e.status!==`committed`||e.enabled_at_completion===t.enabled)}function Fp(e){if(!Ct(e)||e.status!==412||!e.body)return!1;try{return JSON.parse(e.body).error?.code===`root_mode_birth_mismatch`}catch{return!1}}var Ip=e=>{switch(e){case`committed`:return null;case`rejected_incompatible`:return f(`bamboo_rejected_this_root_mode_change_the_current_mode__5b0f50d4`);case`fenced`:return f(`the_change_request_was_safely_canceled_the_current_mode_45bd934b`);case`fenced_by_successor`:return f(`another_operation_updated_root_mode_the_current_mode_wa_e0dd0ad0`)}};function Lp(e,t){u();let n=hc(e),r=e?uc(e):{kind:`clear`},i=n!==`clear`,[a,o]=(0,K.useState)(!1),[s,c]=(0,K.useState)(null),[l,d]=(0,K.useState)(null),[p,m]=(0,K.useState)(null),h=(0,K.useRef)(0),g=(0,K.useRef)(new Map),_=(0,K.useRef)(e);_.current=e;let v=(0,K.useCallback)(async(e,t=null,n=0)=>{let r=++h.current;c(t=>({sessionId:e,kind:t?.sessionId===e?t.kind:null,authority:t?.sessionId===e?t.authority:null,loading:!0,error:null}));try{let i=await zt.getSession(e);if(h.current!==r||_.current!==e)return null;let a=i.session;if(a.kind===`child`)return c({sessionId:e,kind:`child`,authority:null,loading:!1,error:null}),null;if(a.id!==e||a.kind!==`root`||typeof a.root_orchestration_only!=`boolean`||!Pt(a.thinking_mode)||a.thinking_mode===`ultra`!==a.root_orchestration_only||a.reasoning_effort!=null&&!st(a.reasoning_effort)||!Np(a.root_mode_transition_epoch)||typeof a.root_mode_birth_token!=`string`||!/^[0-9a-f]{64}$/i.test(a.root_mode_birth_token))return c({sessionId:e,kind:a.kind??null,authority:null,loading:!1,error:f(`thinking_mode_could_not_be_confirmed_bamboo_did_not_ret_ba55db0f`)}),null;let o={sessionId:e,enabled:a.root_orchestration_only,thinkingMode:a.thinking_mode,ordinaryEffort:a.reasoning_effort??null,epoch:a.root_mode_transition_epoch,birthToken:a.root_mode_birth_token,isRunning:a.is_running===!0};return o.epoch<n?(c({sessionId:e,kind:`root`,authority:null,loading:!1,error:f(`current_state_predates_the_confirmed_mode_change_reload_07a3df79`)}),null):(c({sessionId:e,kind:`root`,authority:o,loading:!1,error:t}),H.setState(t=>({chats:t.chats.map(t=>t.id===e?{...t,config:{...t.config,reasoningEffort:o.ordinaryEffort}}:t)})),o)}catch(t){return h.current!==r||_.current!==e||c({sessionId:e,kind:null,authority:null,loading:!1,error:f(`could_not_read_root_mode_a54a59bf`,{v0:Dt(t)})}),null}},[]),y=(0,K.useCallback)(e=>{let t=g.current.get(e);if(t)return t;let n=(async()=>{let t=uc(e),n=new Map;if(t.kind!==`pending`)return{outcomes:n,authority:null};m(e),d(null);let r=null,i=null,a=0;for(let o of t.operations)try{let t=await zt.recoverRootMode(e,o);if(!Pp(t,o))throw Error(f(`bamboo_did_not_return_terminal_state_evidence_matching__e7c81005`));if(!mc(e,o))throw Error(f(`could_not_clear_the_local_safety_marker_88e9a7a3`));n.set(o.operationId,t.status),a=Math.max(a,t.status===`fenced_by_successor`?t.current_epoch:t.resulting_epoch),r=Ip(t.status)}catch(t){Fp(t)&&mc(e,o)?(n.set(o.operationId,`birth_mismatch`),r=f(`session_identity_changed_the_current_root_mode_was_relo_1fc1b49a`)):i=f(`could_not_confirm_root_mode_change_retry_recovery_1fff2314`,{v0:Dt(t)})}return _.current===e&&(m(null),d(i?{sessionId:e,message:i}:null)),{outcomes:n,authority:uc(e).kind===`clear`&&_.current===e?await v(e,r,a):null}})().finally(()=>{g.current.delete(e)});return g.current.set(e,n),n},[v]);(0,K.useEffect)(()=>{if(!e||t===`child`){h.current+=1,c(null),d(null),e||o(!1);return}return uc(e).kind===`pending`?y(e):v(e),()=>{h.current+=1}},[e,t,v,y]),(0,K.useEffect)(()=>{if(!e||t===`child`)return;let n=t=>{cc(e,t.key)&&uc(e).kind===`clear`&&v(e)};return window.addEventListener(`storage`,n),()=>window.removeEventListener(`storage`,n)},[e,t,v]);let b=s?.sessionId===e?s:null,x=!!(e&&(t===`child`||b?.kind===`child`)),S=b?.authority??null,C=i||b?.loading?null:S?.enabled??null,w=e?C:a,T=!!(e&&!x&&(!b||b.loading)),E=async t=>{if(!e)return o(t),{status:`unchanged`,authority:null};if(x||i||T||!S||p===e||uc(e).kind!==`clear`)return{status:`unconfirmed`,authority:null};let n=e,r=pc(n,S.epoch,S.birthToken,t);if(!r)return d({sessionId:n,message:f(`could_not_save_the_root_mode_safety_marker_the_change_w_4c40ae2b`)}),{status:`unconfirmed`,authority:null};++h.current,d(null);try{let e=await zt.selectRootMode(n,r);if(!Pp(e,r))throw Error(f(`bamboo_did_not_return_terminal_state_evidence_matching__e7c81005`));if(!mc(n,r))throw Error(f(`could_not_clear_the_local_safety_marker_88e9a7a3`));if(_.current===n&&uc(n).kind===`clear`){let t=e.status===`fenced_by_successor`?e.current_epoch:e.resulting_epoch;return{status:e.status,authority:await v(n,Ip(e.status),t)}}}catch(e){if(Fp(e)&&mc(n,r))return{status:`birth_mismatch`,authority:_.current===n?await v(n,f(`session_identity_changed_the_current_root_mode_was_relo_1fc1b49a`)):null};{let e=await y(n);return{status:e.outcomes.get(r.operationId)??`unconfirmed`,authority:e.authority}}}return{status:`unconfirmed`,authority:null}},D=()=>!e||x?Promise.resolve():uc(e).kind===`pending`?y(e).then(e=>e.authority):v(e),O=r.kind===`legacy`?f(`the_legacy_chat_mode_change_has_no_recoverable_request__b94e28d9`):r.kind===`invalid`?f(`the_local_root_mode_request_record_is_invalid_and_canno_6ef1c36c`):r.kind===`storage-unavailable`?f(`could_not_read_local_root_permission_safety_state_retry_0f33322f`):p===e?f(`confirming_the_terminal_state_of_the_root_mode_change_s_ae6d8992`):l?.sessionId===e?l.message:f(`the_root_mode_change_is_unconfirmed_sending_is_temporar_94ddc690`);return{child:x,unsafe:i,selected:w,confirmed:C,loading:T,authority:S,isRoot:!e||!x&&(t===`root`||b?.kind===`root`),recovering:p===e,recoverable:r.kind===`pending`,errorIsPendingNotice:i&&r.kind===`pending`&&l?.sessionId!==e,error:i?O:l?.sessionId===e?l.message:b?.error??null,change:E,refresh:v,retry:D,requestValue:e?void 0:a}}var Rp=new Set,zp=new Map,Bp=new Set,Vp=e=>(Bp.add(e),()=>{Bp.delete(e)}),Hp=()=>{for(let e of Bp)e()};function Up({sessionId:e,draftKey:t,ordinarySelection:n,root:r,disabled:i}){u();let a=e?`session:${e}`:`draft:${t}`,o=(0,K.useRef)({key:a,epoch:0});o.current.key!==a&&(o.current={key:a,epoch:o.current.epoch+1});let s=(0,K.useRef)(!0);(0,K.useEffect)(()=>(s.current=!0,()=>{s.current=!1,o.current.epoch+=1}),[]);let[c,l]=(0,K.useState)(null),d=H(e=>e.inputStates[t]?.thinkingMode??e.getInputState(t).thinkingMode??`standard`),p=e?r.selected:d===`ultra`,m=e?p===null?null:p?`ultra`:`standard`:d,h=e&&!r.child&&r.authority?r.authority.ordinaryEffort??`auto`:n,g=!!(e&&!r.child&&(r.loading||r.unsafe||r.confirmed===null)),_=(0,K.useSyncExternalStore)(Vp,()=>Rp.has(a),()=>!1),v=(0,K.useSyncExternalStore)(Vp,()=>zp.get(a)??0,()=>0),y=(0,K.useRef)({key:a,revision:v});y.current.key!==a&&(y.current={key:a,revision:v});let b=!!(e&&!r.child&&y.current.revision!==v),{child:x,refresh:S}=r;(0,K.useEffect)(()=>{y.current.revision!==v&&(y.current.revision=v,l(null),!(!e||x)&&S(e))},[v,e,a,x,S]);let C=i||_||g||b||!!r.authority?.isRunning,w=c?.key===a&&c.epoch===o.current.epoch?c.message:null,T=async n=>{if(C||Rp.has(a)||n===`ultra`&&!r.isRoot)return;let i=o.current.epoch,c=()=>s.current&&o.current.key===a&&o.current.epoch===i,u=e=>{c()&&l({key:a,epoch:i,message:e})};if(l(null),!e){let e=H.getState();if(!e.setInputThinkingMode(t,n===`ultra`?`ultra`:`standard`)){u(f(`could_not_save_the_draft_s_thinking_mode_check_browser__14cd9961`));return}n!==`ultra`&&e.setInputReasoningEffort(t,n);return}Rp.add(a),Hp();let d=!1,p=r.authority?.birthToken,m=r.authority?.thinkingMode===`ultra`;try{if(!r.child){let t=await r.change(n===`ultra`);if(!c())return;let i=t.authority;if(!i||i.birthToken!==p||i.sessionId!==e||t.status!==`committed`&&t.status!==`unchanged`||i.thinkingMode!==(n===`ultra`?`ultra`:`standard`)){u({fenced:f(`this_change_was_canceled_select_again_using_the_current_40e0d507`),rejected_incompatible:f(`the_selected_mode_is_incompatible_with_the_current_plan_2c3c36dd`),fenced_by_successor:f(`another_operation_updated_thinking_mode_select_again_us_6cf74dff`),birth_mismatch:f(`session_identity_changed_select_a_thinking_mode_using_t_fec23538`)}[t.status]??f(`the_change_result_is_unconfirmed_recover_or_reload_the__7f8a5ea7`));return}if(n===`ultra`)return;if(d=m,i.isRunning)throw Error(f(`the_session_is_running_wait_for_it_to_finish_before_sel_d3b71735`))}if(n===`ultra`||(await H.getState().changeSessionReasoningEffort(e,n===`auto`?null:n),!c()||r.child))return;let t=await r.refresh(e);if(!c())return;(!t||t.birthToken!==p||t.thinkingMode!==`standard`||(t.ordinaryEffort??`auto`)!==n)&&u(f(`the_standard_reasoning_level_is_unconfirmed_actual_mode_a1eda4b7`))}catch(t){if(!c())return;let n=r.child?null:await r.refresh(e);u(f(`your_draft_is_preserved_select_again_or_reload_server_s_f14be63a`,{v0:d&&n?.thinkingMode===`standard`?f(`standard_unconfirmed_after_ultra`):f(`standard_unconfirmed`),v1:Dt(t)}))}finally{Rp.delete(a);let e=(zp.get(a)??0)+1;zp.set(a,e),c()&&(y.current.revision=e),Hp()}},E=async()=>{if(Rp.has(a))return;let e=o.current.epoch;await r.retry(),s.current&&o.current.key===a&&o.current.epoch===e&&l(null)};return{...r,selected:b?null:p,thinkingMode:b?null:m,ordinaryValue:h,busy:_,blocked:g||b,controlDisabled:C,choose:T,retry:E,error:w??(_&&r.errorIsPendingNotice?null:r.error),requestValue:e?void 0:d===`ultra`}}function Wp(e,t,n,r,i,a=[]){if(!e)return{};let o=t.filter(t=>t.parentSessionId===e).sort((e,t)=>e.createdAt-t.createdAt||e.id.localeCompare(t.id)),s=r?.nodes.filter(t=>t.parent_actor_id===e&&t.role===`child`)??[],c=new Map(o.map(e=>[e.id,e])),l=new Map(s.map(e=>[e.actor_id,e])),u=new Set([...o.map(e=>e.id),...Object.keys(n).sort(),...s.map(e=>e.actor_id).sort()]),d=[...a.filter(e=>u.has(e)),...[...u].filter(e=>!a.includes(e))];return Object.fromEntries(d.map(e=>{let t=c.get(e),r=l.get(e),a=i&&r?Qi(r):`unknown`;return[e,{title:r?.title||t?.title||n[e]?.title||t?.subagentType||void 0,status:a===`cold`?`idle`:a===`active`?`unknown`:a,placement:t?.placement}]}))}function Gp(e,t,n,r){let i=e?.id??null,a=e?.rootSessionId||i,o=!!e?.subagentCount||Object.keys(n).length>0||t.some(e=>e.parentSessionId===i),s=na(a,r&&o,null,e?.subagentCount??null),{refresh:c}=s,l=JSON.stringify(Object.entries(n).map(([e,t])=>[e,t.status]).sort(([e],[t])=>(e??``).localeCompare(t??``))),u=(0,K.useRef)({parentId:i,lifecycleHint:l});(0,K.useEffect)(()=>{let e=u.current;u.current={parentId:i,lifecycleHint:l},r&&o&&e.parentId===i&&e.lifecycleHint!==l&&c()},[i,l,r,o,c]);let d=!!s.snapshot&&s.snapshot.root_actor_id===a&&!s.error&&!s.gapReason,p=(0,K.useRef)({parentId:null,ids:[]}),m=(0,K.useMemo)(()=>Wp(i,t,n,s.snapshot,d,p.current.parentId===i?p.current.ids:[]),[i,t,n,s.snapshot,d]);return(0,K.useEffect)(()=>{p.current={parentId:i,ids:Object.keys(m)}},[i,m]),{agents:m,refresh:c,error:s.error||(s.gapReason?f(`agent_structure_cannot_be_confirmed_right_now_reload_st_2ba610a7`):null)}}function Kp(e){switch(e){case`ssh`:return w;case`docker`:return gr;default:return g}}function qp({placement:e,compact:t,className:n}){if(u(),!e||!e.host)return null;let{kind:r,host:i}=e,a=r!==`local`,o=Kp(r);return(0,q.jsxs)(Ce,{variant:`outline`,title:f(`running_on_caee1687`,{v0:r,v1:i}),className:G(`max-w-full gap-1 font-normal text-muted-foreground`,a&&`border-transparent bg-blue-500/15 text-blue-600 dark:text-blue-400`,n),children:[(0,q.jsx)(o,{}),t?null:(0,q.jsx)(`span`,{className:`opacity-65`,children:f(`machine_ece969c3`)}),(0,q.jsx)(`span`,{className:`truncate`,children:`${r} · ${i}`})]})}function Jp({items:e}){return u(),e.length===0?null:(0,q.jsxs)(ke,{children:[(0,q.jsx)(V,{"aria-label":f(`more_38844b13`),className:`inline-flex size-9 items-center justify-center rounded-md text-muted-foreground transition-colors outline-none hover:bg-accent hover:text-foreground`,children:(0,q.jsx)(Xn,{className:`size-5`})}),(0,q.jsx)(z,{align:`end`,className:`min-w-44 rounded-2xl`,children:e.map((e,t)=>(0,q.jsxs)(B,{onClick:e.onClick,className:`gap-2.5 rounded-xl px-3 py-2`,children:[e.icon,(0,q.jsx)(`span`,{children:e.label})]},t))})]})}function Yp({icon:e,label:t,detail:n,trailing:r,onClick:i,ariaLabel:a}){u();let o=(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(`span`,{className:`text-muted-foreground`,children:e}),(0,q.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,q.jsx)(`span`,{className:`block truncate text-sm font-medium`,children:t}),n?(0,q.jsx)(`span`,{className:`block truncate text-xs text-muted-foreground`,title:n,children:n}):null]}),r]});return i?(0,q.jsx)(`button`,{type:`button`,"aria-label":a,className:`flex w-full items-center gap-3 rounded-lg px-3 py-2 text-left transition-colors hover:bg-accent focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring`,onClick:i,children:o}):(0,q.jsx)(`div`,{className:`flex items-center gap-3 px-3 py-2`,children:o})}function Xp({open:e,controlsId:t,onToggle:n}){return u(),(0,q.jsx)(W,{size:`icon`,variant:`ghost`,"aria-label":f(e?`collapse_environment_4c6b8293`:`open_environment_052cba79`),"aria-expanded":e,"aria-controls":t,onClick:n,children:(0,q.jsx)(Ar,{})})}function Zp({open:e,onToggle:t}){return u(),(0,q.jsx)(W,{size:`icon`,variant:`ghost`,"aria-label":f(e?`collapse_side_panel_e7d2fdd8`:`open_side_panel_732ea38b`),"aria-expanded":e,"aria-controls":`right-workbench`,onClick:t,children:(0,q.jsx)(Fr,{})})}function Qp({id:e,workspace:t,projectName:n,workflowControl:r,placement:i,changedFiles:a,addedLines:o,removedLines:s,sources:c,onOpenReview:l,onPreviewImage:d}){u();let p=t?t.split(/[\\/]/).filter(Boolean).at(-1)??t:f(`no_workspace_set_ed50070e`),m=i?i.kind===`local`?`Local`:i.kind:f(`execution_location_unconfirmed_64b94db6`);return(0,q.jsxs)(`section`,{id:e,"aria-label":`Environment`,"data-environment-card":!0,className:`rounded-2xl border bg-popover p-2 text-popover-foreground shadow-lg`,style:{width:`20rem`,maxWidth:`100%`},children:[(0,q.jsx)(`div`,{className:`px-3 pb-2 pt-1 text-sm font-semibold`,children:`Environment`}),(0,q.jsx)(Yp,{icon:(0,q.jsx)(re,{className:`size-4`}),label:`Changes`,detail:f(`changed_files_b757f839`,{v0:a,count:a}),trailing:(0,q.jsxs)(`span`,{className:`flex shrink-0 items-center gap-1 text-xs tabular-nums`,children:[(0,q.jsxs)(`span`,{className:`text-green-600 dark:text-green-400`,children:[`+`,o]}),(0,q.jsxs)(`span`,{className:`text-red-600 dark:text-red-400`,children:[`−`,s]}),(0,q.jsx)(ve,{className:`size-4 text-muted-foreground`})]}),onClick:l}),(0,q.jsx)(Yp,{icon:(0,q.jsx)(g,{className:`size-4`}),label:m,detail:i?.host}),(0,q.jsx)(Yp,{icon:(0,q.jsx)(je,{className:`size-4`}),label:p,detail:t}),n?(0,q.jsx)(Yp,{icon:(0,q.jsx)(xr,{className:`size-4`}),label:n,detail:`Project`}):null,r,(0,q.jsx)(`div`,{className:`my-2 border-t`,style:{marginInline:`0.5rem`}}),(0,q.jsxs)(`div`,{className:`flex items-center justify-between px-3 pb-1 text-sm text-muted-foreground`,children:[(0,q.jsx)(`span`,{children:`Sources`}),(0,q.jsx)(`span`,{className:`text-xs tabular-nums`,children:c.length})]}),c.length>0?(0,q.jsx)(`div`,{className:`space-y-0.5`,children:c.slice(0,5).map(e=>{let t=e.kind===`image`?e.previewUrl:void 0;return(0,q.jsx)(Yp,{icon:t?(0,q.jsx)(`img`,{src:t,alt:``,className:`size-8 rounded-md border object-cover`}):e.kind===`image`?(0,q.jsx)(Or,{className:`size-4`}):(0,q.jsx)(yr,{className:`size-4`}),label:e.name,trailing:t?(0,q.jsx)(ve,{className:`size-4 text-muted-foreground`}):void 0,onClick:t?()=>d(t):void 0,ariaLabel:t?f(`preview_2078e163`,{v0:e.name}):void 0},e.id)})}):(0,q.jsx)(`div`,{className:`px-3 py-2 text-xs text-muted-foreground`,children:f(`this_session_has_no_source_files_yet_b1b2a050`)})]})}function $p({title:e,hasSession:t,overflowItems:n,onOpenSidebar:r,environment:i,sidePaneOpen:a,onToggleSidePane:o,sidebarCollapsed:s,supervisorControl:c}){u();let l=H(Yr(e=>e.currentSessionId?e.chats.find(t=>t.id===e.currentSessionId)?.placement??null:null));return(0,q.jsxs)(`header`,{className:`flex items-center gap-2 px-4 py-2.5`,children:[(0,q.jsx)(W,{size:`icon`,variant:`ghost`,className:G(`md:hidden`,s&&`md:inline-flex`),"aria-label":f(`menu_4ce4cafd`),onClick:r,children:(0,q.jsx)(Mr,{})}),(0,q.jsx)(`span`,{className:`flex-1 truncate text-sm font-medium`,children:e}),l&&l.kind!==`local`?(0,q.jsx)(qp,{placement:l,compact:!0,className:`max-w-36 shrink-0`}):null,(0,q.jsx)(Jp,{items:n}),c,t?(0,q.jsxs)(q.Fragment,{children:[i,(0,q.jsx)(Zp,{open:a,onToggle:o})]}):null]})}var em=`button-interaction outline-none focus-visible:ring-2`,tm={plus:(0,q.jsx)(ze,{className:`size-4`}),code:(0,q.jsx)(mr,{className:`size-4`}),wrench:(0,q.jsx)(Ur,{className:`size-4`}),gitCompare:(0,q.jsx)(Tr,{className:`size-4`}),bug:(0,q.jsx)(le,{className:`size-4`}),helpCircle:(0,q.jsx)(qn,{className:`size-4`}),barChart:(0,q.jsx)(Un,{className:`size-4`}),network:(0,q.jsx)(b,{className:`size-4`}),fileSearch:(0,q.jsx)(vr,{className:`size-4`}),fileText:(0,q.jsx)(x,{className:`size-4`}),bookOpen:(0,q.jsx)(_,{className:`size-4`}),clock:(0,q.jsx)(pr,{className:`size-4`}),search:(0,q.jsx)(Ve,{className:`size-4`})};function nm(e){if(!e)return``;let t=typeof e==`number`?e:Date.parse(e);if(!Number.isFinite(t))return``;let n=Date.now()-t;if(n<6e4)return f(`just_now_de6785d9`);let r=new Intl.RelativeTimeFormat(m(),{numeric:`always`});return n<36e5?r.format(-Math.floor(n/6e4),`minute`):n<864e5?r.format(-Math.floor(n/36e5),`hour`):r.format(-Math.floor(n/864e5),`day`)}function rm({chat:e,onOpen:t}){return u(),(0,q.jsxs)(`button`,{onClick:t,className:G(em,`flex w-full items-center gap-2 rounded-lg px-2.5 py-2 text-left text-sm hover:bg-accent`),children:[e.isRunning?(0,q.jsx)(L,{className:`size-3.5 shrink-0 animate-spin text-primary`}):e.pinned?(0,q.jsx)(Rr,{className:`size-3.5 shrink-0 text-muted-foreground`}):(0,q.jsx)(Le,{className:`size-3.5 shrink-0 text-muted-foreground`}),(0,q.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:e.title||f(`new_session_c57c30bc`)}),(0,q.jsx)(`span`,{className:`shrink-0 text-[11px] text-muted-foreground`,children:nm(e.lastActivityAt??e.updatedAt)})]})}function im({chats:e,onOpenSession:t,onPickTemplate:n,onDescribeTask:r}){u();let[i,a]=(0,K.useState)(``),o=(0,K.useRef)(null),s=()=>{a(``),o.current?.focus()},c=(0,K.useMemo)(()=>e.filter(e=>e.isRunning).slice(0,5),[e]),l=(0,K.useMemo)(()=>e.filter(e=>e.pinned&&!e.isRunning).slice(0,5),[e]),d=(0,K.useMemo)(()=>e.filter(e=>!e.isRunning&&!e.pinned&&!e.parentSessionId).slice(0,5),[e]),p=i.trim().toLowerCase(),m=p?$s.filter(e=>e.title.toLowerCase().includes(p)||e.description.toLowerCase().includes(p)):$s,h=Rs.map(e=>({cat:e,items:m.filter(t=>t.category===e)})).filter(e=>e.items.length>0),g=e=>{nc(e.taskPrompt??null),n(e.prefill)},_=[{label:f(`running_1f0eb99b`),items:c},{label:f(`pinned_section`),items:l},{label:f(`recent_997a5e6e`),items:d}].filter(e=>e.items.length>0);return(0,q.jsx)(`div`,{"data-testid":`home-dashboard`,className:`min-h-0 flex-1 overflow-y-auto`,children:(0,q.jsxs)(`div`,{className:`mx-auto w-full max-w-6xl px-4 py-6`,children:[(0,q.jsxs)(`div`,{className:`mb-5 flex items-center gap-3`,children:[(0,q.jsx)(so,{className:`size-9`}),(0,q.jsxs)(`div`,{children:[(0,q.jsx)(`h1`,{className:`text-base font-semibold`,children:f(`start_a_new_task_625aa91a`)}),(0,q.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:f(`choose_a_template_or_type_below_6a05a677`)})]})]}),_.length>0?(0,q.jsx)(`div`,{className:`mb-5 grid gap-3 sm:grid-cols-2`,children:_.map(e=>(0,q.jsxs)(`section`,{className:`rounded-lg border p-2`,children:[(0,q.jsx)(`div`,{className:`mb-1 px-1 text-xs font-medium text-muted-foreground`,children:e.label}),e.items.map(e=>(0,q.jsx)(rm,{chat:e,onOpen:()=>t(e.id)},e.id))]},e.label))}):null,(0,q.jsx)(`div`,{className:`mb-3`,children:(0,q.jsx)(fe,{ref:o,"aria-label":f(`search_templates_28062b4d`),onKeyDown:e=>{e.key===`Escape`&&i&&!e.nativeEvent.isComposing&&e.nativeEvent.keyCode!==229&&(e.preventDefault(),e.stopPropagation(),s())},value:i,onChange:e=>a(e.target.value),placeholder:f(`search_templates_28062b4d`),className:`h-9`})}),h.map(({cat:e,items:t})=>(0,q.jsxs)(`section`,{className:`mb-4`,children:[(0,q.jsx)(`div`,{className:`mb-1.5 text-xs font-medium text-muted-foreground`,children:zs[e]}),(0,q.jsx)(`div`,{className:`grid gap-2 sm:grid-cols-2`,children:t.map(e=>(0,q.jsxs)(`button`,{onClick:()=>g(e),className:G(em,`flex items-start gap-2.5 rounded-xl border p-3 text-left hover:bg-accent`),children:[(0,q.jsx)(`span`,{"aria-hidden":!0,className:`flex size-8 shrink-0 items-center justify-center rounded-lg bg-accent text-primary`,children:tm[e.icon]??tm.plus}),(0,q.jsxs)(`span`,{className:`min-w-0`,children:[(0,q.jsx)(`span`,{className:`block text-sm font-medium`,children:e.title}),(0,q.jsx)(`span`,{className:`mt-0.5 line-clamp-2 block text-xs leading-relaxed text-muted-foreground`,children:e.description})]})]},e.id))})]},e)),h.length===0?(0,q.jsxs)(`div`,{role:`status`,className:G(Ut,`surface-fade rounded-xl border bg-card px-4 py-8 text-center`),children:[(0,q.jsx)(Ve,{className:`mx-auto mb-3 size-5 text-primary`,"aria-hidden":!0}),(0,q.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:f(`no_matching_templates_0f5e1c5f`)}),(0,q.jsxs)(`div`,{className:`mt-4 flex flex-wrap justify-center gap-2`,children:[(0,q.jsx)(W,{type:`button`,variant:`outline`,size:`sm`,onClick:s,children:f(`clear_search_b6f00afa`)}),(0,q.jsx)(W,{type:`button`,size:`sm`,onClick:r,children:f(`home_describe_task`)})]})]}):null]})})}function am({expanded:e,triggerRef:t,className:n,children:r,...i}){let a=(0,K.useRef)(null),o=(0,K.useRef)(e);return(0,K.useLayoutEffect)(()=>{let n=a.current;n&&(o.current&&!e&&n.contains(n.ownerDocument.activeElement)&&t.current?.focus({preventScroll:!0}),n.toggleAttribute(`inert`,!e),n.setAttribute(`aria-hidden`,String(!e)),o.current=e)},[e,t]),(0,q.jsx)(`div`,{...i,ref:a,"data-disclosure-panel":!0,"data-state":e?`open`:`closed`,className:G(`disclosure-panel`,n),children:(0,q.jsx)(`div`,{className:`disclosure-panel-clip`,children:r})})}function om({confirmed:e,sequence:t,fallback:n=Ae,className:r}){return e?(0,q.jsx)(de,{"aria-hidden":`true`,className:`confirmation-icon ${r??``}`,"data-copy-confirmation":`true`},t):(0,q.jsx)(n,{"aria-hidden":`true`,className:r})}var sm={status:`idle`,sequence:0};function cm(e,t){let[n,r]=(0,K.useState)(sm),i=(0,K.useRef)({active:!1,generation:0,request:0,sequence:0,text:e,sourceId:t}),a=(0,K.useRef)(null),o=(0,K.useCallback)(()=>{a.current!==null&&clearTimeout(a.current),a.current=null},[]);(0,K.useLayoutEffect)(()=>{let n=i.current;return n.active=!0,n.generation+=1,n.text=e,n.sourceId=t,r(sm),()=>{n.active=!1,n.generation+=1,o()}},[e,t,o]);let s=(0,K.useCallback)(async()=>{let n=i.current;if(!n.active||n.text!==e||n.sourceId!==t)return;let s=n.generation,c=++n.request,l=()=>n.active&&n.generation===s&&n.request===c;r(e=>e.status===`error`?sm:e);try{await Ue(e)}catch{if(!l())return;o(),r({status:`error`,sequence:n.sequence});return}if(!l())return;o();let u=++n.sequence;r({status:`copied`,sequence:u}),a.current=setTimeout(()=>{n.active&&n.generation===s&&n.sequence===u&&(a.current=null,r(sm))},2500)},[e,t,o]);return{...n,copy:s}}var lm=(0,K.lazy)(()=>o(()=>import(`./StreamdownMarkdown-BYrL8Htd.js`).then(e=>({default:e.StreamdownMarkdown})),__vite__mapDeps([66,1,2,4,60,61,67,10,68,3,12,69,8,70,71,6,32,11,15,72,35,36,39,40,41,9,13,14,16,73,74]),import.meta.url));function um({children:e,isStreaming:t,onPreviewImage:n}){return(0,q.jsx)(K.Suspense,{fallback:(0,q.jsx)(`div`,{"aria-busy":t||void 0,className:`whitespace-pre-wrap text-base font-normal leading-7 text-foreground [overflow-wrap:anywhere]`,"data-assistant-markdown-fallback":`true`,style:{WebkitFontSmoothing:`auto`},children:e}),children:(0,q.jsx)(lm,{isStreaming:t,onPreviewImage:n,children:e})})}var dm=(0,K.lazy)(()=>o(()=>import(`./Markdown-sn8uDNJU.js`).then(e=>({default:e.Markdown})),__vite__mapDeps([75,1,2,4,60,61,12,10,73]),import.meta.url));function fm({children:e}){return(0,q.jsx)(K.Suspense,{fallback:(0,q.jsx)(`div`,{className:`whitespace-pre-wrap text-sm leading-relaxed`,children:e}),children:(0,q.jsx)(dm,{children:e})})}function pm({name:e,body:t}){u();let[n,r]=(0,K.useState)(!1);return(0,q.jsxs)(`div`,{className:`my-1.5`,children:[(0,q.jsxs)(`button`,{type:`button`,onClick:()=>r(e=>!e),className:`inline-flex max-w-full items-center gap-1.5 rounded-full bg-muted/60 px-2.5 py-1 text-xs text-muted-foreground transition-colors hover:bg-muted`,children:[(0,q.jsx)(A,{className:`size-3 shrink-0`}),(0,q.jsxs)(`span`,{className:`truncate`,children:[f(`built_in_tool_508add77`),` `,e]}),(0,q.jsx)(ve,{className:G(`size-3 shrink-0 transition-transform`,n&&`rotate-90`)})]}),n?(0,q.jsx)(`div`,{className:`mt-1.5 overflow-x-auto rounded-lg border bg-card/50 p-2.5 text-xs`,children:(0,q.jsx)(fm,{children:t})}):null]})}var mm=/(?:\*\*)?\s*🌐?\s*(?:Z\.ai\s+)?Built-in Tool[::]\s*([A-Za-z0-9_]+)\s*(?:\*\*)?[\s\S]*?\*\*Output:\*\*[\s\S]*?(?=\n\n|$)/,hm=/(?:\*\*\s*🌐?\s*(?:Z\.ai\s+)?|🌐\s*(?:Z\.ai\s+)?|Z\.ai\s+)Built-in Tool[::]\s*([A-Za-z0-9_]+)\s*(?:\*\*)?/,gm=/(?:^|\n)(?:\*\*\s*🌐?\s*(?:Z\.ai\s+)?|🌐\s*(?:Z\.ai\s+)?|Z\.ai\s+)([^\n]*)/g;function _m(e){gm.lastIndex=0;for(let t of e.matchAll(gm)){let n=t[1].trim().replace(/\*\*\s*$/,``).trimEnd().replace(`:`,`:`).toLowerCase(),r=`built-in tool:`.startsWith(n),i=/^built-in tool:\s*[a-z0-9_]*$/i.test(n);if(!r&&!i)continue;let a=(t.index??0)+ +!!t[0].startsWith(`
|
|
7
|
+
`),o=e.slice(a).match(hm);return{index:a,name:o?.index===0?o[1]:void 0}}return null}function vm({children:e,isStreaming:t=!1,onPreviewImage:n}){u();let r=e,i=r.match(mm);if(!i||i.index===void 0){let e=t?_m(r):null;if(e){let t=r.slice(0,e.index).trimEnd(),i=e.name?f(`built_in_tool_is_running_aa5c6389`,{v0:e.name}):f(`starting_built_in_tool_4b6a8d81`);return(0,q.jsxs)(q.Fragment,{children:[t?(0,q.jsx)(um,{isStreaming:!1,onPreviewImage:n,children:t}):null,(0,q.jsx)(`div`,{"aria-label":i,className:`my-1.5 inline-flex max-w-full items-center rounded-full bg-muted/60 px-2.5 py-1 text-xs text-muted-foreground`,"data-provider-tool-state":`streaming`,role:`status`,children:(0,q.jsx)(`span`,{className:`truncate`,children:e.name?f(`built_in_tool_b3950b4c`,{v0:e.name}):f(`built_in_tool_starting_d9a432a6`)})})]})}return(0,q.jsx)(um,{isStreaming:t,onPreviewImage:n,children:r})}let a=r.slice(0,i.index).trimEnd(),o=r.slice(i.index+i[0].length).replace(/^\n+/,``);return(0,q.jsxs)(q.Fragment,{children:[a?(0,q.jsx)(um,{isStreaming:!1,onPreviewImage:n,children:a}):null,(0,q.jsx)(pm,{name:i[1],body:i[0].trim()}),o?(0,q.jsx)(vm,{isStreaming:t,onPreviewImage:n,children:o}):null]})}function ym({text:e,active:t=!1,spaced:n=!1}){u();let[r,i]=(0,K.useState)(!1),a=(0,K.useId)(),o=(0,K.useRef)(null);return(0,q.jsxs)(`div`,{className:G(n&&`mb-1.5`),children:[(0,q.jsxs)(`button`,{ref:o,type:`button`,"aria-expanded":r,"aria-controls":a,"data-reasoning-toggle":!0,onClick:()=>i(e=>!e),className:`reasoning-toggle inline-flex items-center gap-1.5 rounded-sm text-xs text-muted-foreground transition-colors hover:text-foreground`,children:[(0,q.jsx)(or,{className:G(`reasoning-brain size-3.5 shrink-0`,t&&`animate-pulse`)}),(0,q.jsx)(`span`,{children:f(t?`thinking_64088d8c`:`reasoning_a62acb18`)}),(0,q.jsx)(ve,{className:G(`reasoning-chevron size-3.5 transition-transform duration-(--motion-normal) ease-(--motion-ease)`,r&&`rotate-90`)})]}),(0,q.jsx)(am,{expanded:r,triggerRef:o,children:(0,q.jsx)(`div`,{id:a,tabIndex:r?0:-1,role:`region`,"aria-label":f(t?`live_reasoning_b8c0edb7`:`reasoning_a62acb18`),className:G(`mt-1 max-h-32 overflow-y-auto overscroll-contain whitespace-pre-wrap border-l-2 border-border pl-2.5 text-xs leading-relaxed text-muted-foreground [overflow-wrap:anywhere]`,!n&&`mb-1.5`),children:e})})]})}var bm=e=>typeof e==`object`&&!!e&&!Array.isArray(e);function xm(e,t,n){let r=e.trim().split(/__|::|\./).at(-1)?.toLowerCase().replace(/[_-]/g,``);if(!(r===`sessionmessage`||r===`subagent`&&(t?.action===`send_message`||t?.intent===`chat`&&typeof t.target==`string`&&t.target.trim())))return null;let i=t?.interrupt_running===!0||t?.mode===`after_round`?f(`message_action_interject`):f(`message_action_send`);if(n?.isError)return{label:i,status:f(`message_delivery_failed`)};if(!n)return{label:i,status:f(`message_delivery_pending`)};let a;try{a=JSON.parse(n.text)}catch{}switch(bm(a)?a.observed_status??a.status:void 0){case`pending`:return{label:i,status:f(`message_delivery_pending`)};case`queued`:case`message_queued`:return{label:i,status:f(`message_delivery_queued`)};case`activation_pending`:return{label:i,status:f(`message_delivery_activation_pending`)};case`activation_retry_required`:return{label:i,status:f(`message_delivery_retry`)};case`message_delivered_live`:return{label:i,status:f(`message_delivery_live`)};case`delivered`:return{label:i,status:f(`message_delivery_delivered`)};case`steering`:return{label:i,status:f(`message_delivery_steering`)};default:return{label:i,status:f(`message_delivery_unconfirmed`)}}}var Sm=/^image\/(?:png|jpeg|gif|webp)$/i,Cm=3495254*4,wm=/^[A-Za-z0-9+/]+={0,2}$/;function Tm(e){let t=e.url||(e.base64&&Sm.test(e.type)?`data:${e.type};base64,${e.base64}`:``);if(!t)return null;try{let e=new URL(t,window.location.href),n=/\/sessions\/([^/]+)\/attachments\/([^/]+)$/.exec(e.pathname);if(n&&e.href===Ot.resolveUrl(`sessions/${n[1]}/attachments/${n[2]}`))return t}catch{}let n=/^data:(image\/(?:png|jpeg|gif|webp));base64,([A-Za-z0-9+/=]+)$/i.exec(t);if(!n)return null;let r=n[2];return r.length>Cm||r.length%4!=0||!wm.test(r)?null:t}function Em(e){let t=e.trim().toLowerCase().split(/__|::|\./).at(-1)??``;return/^(?:view_?image|open_?image|image_?view)$/.test(t)}function Dm(e){let t;try{t=JSON.parse(e)}catch{return null}if(t&&typeof t==`object`&&typeof t.bash_id==`string`&&t.status===`running`&&typeof t.command==`string`&&t.command.length>0){let e=t;return{bashId:e.bash_id,command:e.command}}return null}var Om=16*1024,km=512*1024,Am=()=>f(`waiting_for_your_approval_0dc00a8d`),jm=new Set([`environment`,`env`,`cwd`,`import_shell`,`path_env`]),Mm=[`command`,`cmd`,`query`,`file_path`,`path`,`pattern`,`url`,`content`,`message`,`text`,`prompt`,`description`,`action`],Nm=(e,t=72)=>{let n=e.replace(/\s+/g,` `).trim();return n.length>t?`${n.slice(0,t-1)}…`:n},Pm=e=>{let t=e.replace(/\\/g,`/`).replace(/\/+$/,``);return Nm(t.split(`/`).filter(Boolean).slice(-2).join(`/`)||t)},Fm=(e,t)=>{for(let n of t){let t=e?.[n];if(typeof t==`string`&&t.trim())return t}},Im=e=>typeof e==`object`&&!!e&&!Array.isArray(e),Lm=e=>e.trim().toLowerCase().split(/__|::|\./).at(-1),Rm=e=>Lm(e)===`browser`,zm=e=>Lm(e)===`browser_eval`,Bm=e=>Im(e)?e.kind===`role`?typeof e.role==`string`&&e.role.trim().length>0:e.kind===`label`||e.kind===`text`?typeof e.value==`string`&&e.value.trim().length>0:!1:!1;function Vm(e,t){let n=Rm(e),r=zm(e);if(r)return{browserTool:n,browserEvalTool:r,focusedBrowserInput:!1,browserSelectOption:!1};if(!Im(t))return{browserTool:n,browserEvalTool:r,focusedBrowserInput:n,browserSelectOption:!1};if(!n)return{params:t,browserTool:n,browserEvalTool:r,focusedBrowserInput:!1,browserSelectOption:!1};let i=``;try{if(`raw`in t)return{browserTool:n,browserEvalTool:r,focusedBrowserInput:!0,browserSelectOption:!1};if(i=typeof t.action==`string`?t.action.trim().toLowerCase():``,i===`set_file_input`)return{browserTool:n,browserEvalTool:r,focusedBrowserInput:!1,browserSelectOption:!1,browserFileInput:!0};if(i===`dialog_respond`)return{browserTool:n,browserEvalTool:r,focusedBrowserInput:!1,browserSelectOption:!1,browserDialogResponse:!0};if(i===`download`)return{browserTool:n,browserEvalTool:r,focusedBrowserInput:!1,browserSelectOption:!1,browserDownload:!0};if(i===`select_option`)return{browserTool:n,browserEvalTool:r,focusedBrowserInput:!1,browserSelectOption:!0};if(JSON.stringify(t).length>Om)return{browserTool:n,browserEvalTool:r,focusedBrowserInput:!0,browserSelectOption:!1}}catch{return{browserTool:n,browserEvalTool:r,focusedBrowserInput:!0,browserSelectOption:!1}}let a=typeof t.selector==`string`&&t.selector.trim().length>0,o=i===`type`||i===`key`||i===`press`&&!a&&!Bm(t.target);return o?{params:{action:i},browserTool:n,browserEvalTool:r,focusedBrowserInput:o,browserSelectOption:!1}:i?{params:t,browserTool:n,browserEvalTool:r,focusedBrowserInput:!1,browserSelectOption:!1}:{browserTool:n,browserEvalTool:r,focusedBrowserInput:!0,browserSelectOption:!1}}function Hm(e){if(e.length>Om*4)return{parsedRecord:!1};try{let t=JSON.parse(e);return Im(t)?t.pending_dialog==null?{parsedRecord:!0}:Im(t.pending_dialog)?{parsedRecord:!0,dialogStatus:t.pending_dialog.status===`expired`?`expired`:`pending`}:{parsedRecord:!1,dialogStatus:`unknown`}:{parsedRecord:!1}}catch{return{parsedRecord:!1}}}function Um(e,t){return Im(e)&&(e.status===`awaiting_permission_approval`||`permission_request`in e)?Am():t?f(`web_download_failed_37881d0e`):Im(e)&&typeof e.data_base64==`string`&&typeof e.filename==`string`&&typeof e.sha256==`string`&&Number.isSafeInteger(e.byte_count)?f(`web_download_completed_f9dd3004`):``}function Wm(e,t){if(!t)return e.browserDownload&&e.result?.isError?f(`web_download_failed_37881d0e`):``;if(e.browserDialogResponse||e.browserDialogStatus){if(t.length>Om*4)return e.result?.isError?f(`web_dialog_action_failed_496f20bd`):f(`web_dialog_state_unconfirmed_511c7de0`);let n;try{n=JSON.parse(t)}catch{return e.result?.isError?f(`web_dialog_action_failed_496f20bd`):f(`web_dialog_state_unconfirmed_511c7de0`)}return Im(n)&&(n.status===`awaiting_permission_approval`||`permission_request`in n)?Am():e.result?.isError?f(`web_dialog_action_failed_496f20bd`):!Im(n)||e.browserDialogStatus===`unknown`?f(`web_dialog_state_unconfirmed_511c7de0`):e.browserDialogStatus===`expired`?f(`web_dialog_expired_33cf66ef`):e.browserDialogStatus===`pending`?f(`web_dialog_awaiting_response_9f92f02b`):f(`web_dialog_answered_2de9a678`)}let n=t.includes(`awaiting_permission_approval`)||t.includes(`permission_request`);if((e.browserTool||e.browserEvalTool||n)&&t.length>Om){if(e.browserDownload){if(t.length>km)return e.result?.isError?f(`web_download_failed_37881d0e`):``;try{return Um(JSON.parse(t),!!e.result?.isError)}catch{return e.result?.isError?f(`web_download_failed_37881d0e`):``}}if(e.browserSelectOption&&t.length<=Om*4)try{let n=JSON.parse(t);if(Im(n))return n.status===`awaiting_permission_approval`||`permission_request`in n?Am():e.result?.isError?f(`web_option_selection_failed_54027654`):f(`web_options_selected_9d95e309`)}catch{}return``}let r;try{r=JSON.parse(t)}catch{return e.browserDownload&&e.result?.isError?f(`web_download_failed_37881d0e`):e.browserTool||e.browserEvalTool||n?``:t}return Im(r)&&(r.status===`awaiting_permission_approval`||`permission_request`in r)?Am():e.browserTool&&!e.browserFileInput&&Im(r)&&[`data_base64`,`filename`,`byte_count`,`sha256`].some(e=>e in r)?Um(r,!!e.result?.isError):e.browserEvalTool?e.result?.isError?f(`web_script_execution_failed_742c4b84`):f(`web_script_executed_ede4f7a6`):e.focusedBrowserInput?e.result?.isError?f(`browser_input_failed_0a04106d`):f(`browser_input_completed_f26de380`):e.browserSelectOption?e.result?.isError?f(`web_option_selection_failed_54027654`):f(`web_options_selected_9d95e309`):e.browserFileInput?e.result?.isError?f(`web_file_selection_failed_ddd93cab`):f(`web_files_selected_beb60ad8`):e.browserDownload?Um(r,!!e.result?.isError):e.browserTool&&!Im(r)?``:t}var Gm=e=>e.replace(/^.*__/,``).replace(/^.*\./,``).replace(/[_-]+/g,` `).replace(/([a-z0-9])([A-Z])/g,`$1 $2`).trim()||f(`tool_calls_a8ca3c13`);function Km(e){let t=xm(e.toolName,e.params,e.result);if(t)return{label:t.label,detail:t.status,icon:Le};if(e.browserEvalTool)return{label:f(`execute_web_script_f9a5ccf3`),icon:A};if(e.browserDialogResponse)return{label:f(`respond_to_web_dialog_e0f2f248`),icon:A};if(e.browserDialogStatus)return{label:f(`view_web_dialog_b07d2b63`),icon:A};if(e.browserSelectOption)return{label:f(`select_web_options_4ddab1c1`),icon:A};if(e.browserFileInput)return{label:f(`set_web_files_a87e70ca`),icon:A};if(e.browserDownload)return{label:f(`download_web_file_68532ddc`),icon:A};let n=e.toolName.toLowerCase().replace(/[^a-z0-9]+/g,``),r=Fm(e.params,[`file_path`,`path`]),i=Fm(e.params,[`command`,`cmd`]),a=Fm(e.params,[`query`,`pattern`]);if(/bashoutput|shelloutput|writestdin/.test(n))return{label:f(`read_command_output_dd7e06ae`),icon:Vr};if(/bashinput|shellinput/.test(n))return{label:f(`send_command_input_8fc6194d`),icon:Vr};if(/killshell|stopcommand|terminateprocess/.test(n))return{label:f(`stop_command_b116ef12`),icon:Vr};if(/bash|execcommand|runshell|terminal/.test(n))return{label:f(`run_command_e53f35dc`),icon:Vr,detail:i?Nm(i):void 0,multipleLabel:e=>f(`run_commands_272cb4c2`,{v0:e,count:e})};if(/viewimage|openimage|imageview/.test(n))return{label:f(`view_image_a9769c63`),icon:Or,detail:r?Pm(r):void 0,multipleLabel:e=>f(`view_images_45758edd`,{v0:e,count:e})};if(/imagegen|generateimage/.test(n))return{label:f(`generate_image_71c9cf3d`),icon:Or};if(n===`edit`||n===`write`||/applypatch|editfile|writefile|notebookedit/.test(n))return{label:/notebook/.test(n)?f(`edit_notebook_3ee5f852`):f(`edit_file_60ed2653`),icon:j,detail:r?Pm(r):void 0,multipleLabel:e=>f(`edit_files_ff5ac699`,{v0:e,count:e})};if(/glob|findfiles|listfiles/.test(n))return{label:f(`find_files_51fdfeaa`),icon:Ve,detail:a?Nm(a):void 0,multipleLabel:e=>f(`run_file_searches_a6744ab4`,{v0:e,count:e})};if(/grep|codesearch|searchcode|rgsearch/.test(n))return{label:f(`search_code_562834f5`),icon:Ve,detail:a?Nm(a):void 0,multipleLabel:e=>f(`run_code_searches_9cb50811`,{v0:e,count:e})};if(n===`read`||/readfile|openfile/.test(n))return{label:f(`read_file_407dd16f`),icon:x,detail:r?Pm(r):void 0,multipleLabel:e=>f(`read_files_77738f3e`,{v0:e,count:e})};if(/webfetch|fetchurl|openurl/.test(n)){let t=Fm(e.params,[`url`]);return{label:f(`fetch_page_943f1f86`),icon:A,detail:t?Nm(t):void 0}}if(/websearch|searchweb/.test(n))return{label:f(`search_web_01aeaf3f`),icon:A,detail:a?Nm(a):void 0};if(/sleep|wait/.test(n))return{label:f(`wait_251bc40e`),icon:Ur};if(n===`task`||/subagent|spawnagent|delegatetask/.test(n)){let t=Fm(e.params,[`description`,`prompt`]);return{label:f(`delegate_task_5161967c`),icon:Ur,detail:t?Nm(t):void 0}}return n===`plan`||/updateplan/.test(n)?{label:f(`update_plan_c9388382`),icon:Ur}:/getfileinfo|filestat/.test(n)?{label:f(`view_file_information_a5d09268`),icon:x,detail:r?Pm(r):void 0}:/skill/.test(n)?{label:f(`load_skill_11ff0491`),icon:Ur}:/memory/.test(n)?{label:f(`query_memory_6c9164f7`),icon:Ur}:/project/.test(n)?{label:f(`manage_projects_302f96cf`),icon:Ur}:{label:Gm(e.toolName),icon:Ur}}function qm(e){if(e.length===0)return{label:f(`tool_calls_a8ca3c13`),icon:Ur};let t=e.map(Km),n=Array.from(new Set(t.map(e=>e.label)));if(n.length===1){let n=t[0];return{...n,label:e.length>1&&n.multipleLabel?n.multipleLabel(e.length):n.label,detail:e.length===1?n.detail:void 0}}return{label:n.length<=3?d(n):f(`and_operations_89a77073`,{v0:d(n.slice(0,2)),v1:e.length}),icon:t[0].icon}}function Jm(e){if(!e)return{rest:[]};let t=Mm.find(t=>typeof e[t]==`string`&&e[t]),n=t?String(e[t]):void 0,r=[];for(let[n,i]of Object.entries(e)){if(n===t||jm.has(n)||i==null||i===``||i===!1)continue;let e=typeof i==`string`?i:JSON.stringify(i);r.push([n,e])}return{primary:n,rest:r}}function Ym(e){let t=e.trim();if(t.startsWith(`{`)||t.startsWith(`[`))try{let e=JSON.parse(t);if(e&&typeof e==`object`&&!Array.isArray(e))for(let t of jm)delete e[t];return JSON.stringify(e,null,2)}catch{}return e}function Xm(e){let t=[],n=new Map;for(let r of e){let e=r.type;if(e===`tool_call`){let e=r.toolCalls??[];for(let n of e)t.push({id:n.toolCallId,toolName:n.toolName,...Vm(n.toolName,n.parameters)})}else if(e===`tool_result`){let e=r;e.toolCallId&&n.set(e.toolCallId,{text:typeof e.result?.result==`string`?e.result.result:``,isError:!!e.isError,images:e.images})}}return t.map(e=>{let t=n.get(e.id),r=e.browserTool&&t?Hm(t.text):void 0,i=r?.dialogStatus,a=e.browserTool&&t&&!r?.parsedRecord,o={...e,browserDialogStatus:i,result:t},s=t&&{isError:t.isError,text:Wm(o,t.text)},c=s?Dm(s.text):null;return{id:e.id,toolName:e.toolName,params:i||a?void 0:e.params,focusedBrowserInput:e.focusedBrowserInput,browserSelectOption:e.browserSelectOption,browserFileInput:e.browserFileInput,browserDialogResponse:e.browserDialogResponse,browserDialogStatus:i,browserDownload:e.browserDownload,browserTool:e.browserTool,browserEvalTool:e.browserEvalTool,result:s,images:Em(e.toolName)?t?.images:void 0,background:c??void 0}})}function Zm({bashId:e}){u();let t=ot(e);if(!t)return(0,q.jsxs)(Ce,{variant:`warning`,children:[(0,q.jsx)(L,{className:`size-3 animate-spin`}),c.t(`chat.tools.runningInBackground`)]});let{status:n,exitCode:r}=t,i=r==null?``:` · exit ${r}`;return n===`completed`&&(r===0||r==null)?(0,q.jsxs)(Ce,{variant:`success`,children:[c.t(`chat.tools.backgroundCompleted`),i]}):n===`killed`?(0,q.jsx)(Ce,{variant:`secondary`,children:c.t(`chat.tools.backgroundKilled`)}):(0,q.jsxs)(Ce,{variant:`destructive`,children:[c.t(`chat.tools.backgroundFailed`),i]})}var Qm=`flex min-w-0 flex-wrap items-center gap-1.5 rounded-sm py-1 text-sm text-muted-foreground`;function $m({e,presentation:t,running:n,open:r}){let i=t.icon;return(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(i,{className:`size-3.5 shrink-0`}),(0,q.jsx)(`span`,{className:`min-w-0 break-words [overflow-wrap:anywhere]`,children:t.label}),t.detail?(0,q.jsx)(`span`,{title:t.detail,className:`min-w-0 break-words text-xs opacity-70 [overflow-wrap:anywhere]`,children:t.detail}):null,e.result?.isError?(0,q.jsx)(`span`,{className:`shrink-0 text-destructive`,children:f(`errors_01ad2bc5`)}):null,e.background?(0,q.jsx)(Zm,{bashId:e.background.bashId}):null,n&&!xm(e.toolName,e.params,e.result)?(0,q.jsx)(`span`,{className:`shrink-0`,children:f(`running_14d9f2d8`)}):null,r===void 0?null:(0,q.jsx)(ve,{className:G(`size-3 shrink-0 transition-transform`,r&&`rotate-90`)})]})}function eh({e,running:t,expanded:n=!1,onPreviewImage:r}){u();let[i,a]=(0,K.useState)(n),o=n||i,{primary:s,rest:c}=Jm(e.params),l=Km(e),d=o&&e.result?.text?ei(e.result.text):null,p=o&&e.result?.text?Ym(e.result.text):``,m=o?e.images?.map(Tm).filter(e=>!!e):void 0,h=o?(0,q.jsxs)(`div`,{"data-tool-call-entry-detail":!0,className:`mt-1 border-l border-border pl-4 text-[11px]`,children:[l.label===e.toolName?null:(0,q.jsx)(`div`,{className:`break-all text-muted-foreground opacity-70`,children:e.toolName}),m?.length?(0,q.jsx)(`div`,{className:`mt-1.5 flex flex-wrap gap-1.5`,children:m.map((e,t)=>(0,q.jsx)(`button`,{type:`button`,"aria-label":f(`preview_tool_image_344014b6`,{v0:t+1}),className:`cursor-zoom-in`,onClick:()=>r?.(e),children:(0,q.jsx)(`img`,{src:e,alt:f(`tool_image_7b8fcc11`,{v0:t+1}),className:`max-h-48 max-w-full rounded-xl object-contain`})},t))}):null,s?(0,q.jsx)(`div`,{className:`mt-1 max-h-64 overflow-auto whitespace-pre-wrap break-words font-mono text-foreground [overflow-wrap:anywhere]`,children:s}):null,c.length>0?(0,q.jsx)(`div`,{className:`mt-1 flex flex-wrap gap-x-3 gap-y-0.5 text-muted-foreground`,children:c.map(([e,t])=>(0,q.jsxs)(`span`,{className:`min-w-0 whitespace-pre-wrap break-words [overflow-wrap:anywhere]`,children:[(0,q.jsxs)(`span`,{className:`opacity-60`,children:[e,`:`]}),` `,t]},e))}):null,d?(0,q.jsx)(`div`,{className:`mt-1.5`,children:(0,q.jsx)(Ti,{payload:d})}):p?(0,q.jsx)(`pre`,{className:`mt-1.5 max-h-44 overflow-auto whitespace-pre-wrap break-all text-muted-foreground`,children:p}):null]}):null;return(0,q.jsx)(`div`,{"data-tool-call-entry":!0,className:`min-w-0`,children:n?(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(`div`,{"data-tool-call-entry-heading":!0,className:Qm,children:(0,q.jsx)($m,{e,presentation:l,running:t})}),h]}):(0,q.jsxs)(`details`,{open:o,children:[(0,q.jsx)(`summary`,{"data-tool-call-entry-toggle":!0,"aria-expanded":o,onClick:e=>{e.preventDefault(),a(!o)},className:G(Qm,`cursor-pointer list-none hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring [&::-webkit-details-marker]:hidden`),children:(0,q.jsx)($m,{e,presentation:l,running:t,open:o})}),h]})})}function th({items:e,presentation:t=`group`,singleExpanded:n=!1,active:r,runningCallIds:i,open:a,onOpenChange:o,onPreviewImage:s}){u();let[c,l]=(0,K.useState)(!1),f=a??c,p=e=>{a===void 0&&l(e),o?.(e)},m=Xm(e),h=e=>i?i.has(e.id):!!(r&&!e.result);if(t===`preview`){let e=m.findLast(h)??m.at(-1);if(!e)return null;let t=e.focusedBrowserInput||e.browserEvalTool||e.browserSelectOption||e.browserFileInput||e.browserDialogResponse||e.browserDialogStatus||e.browserDownload||e.result?.text===Am()?e.result?.text:void 0;return(0,q.jsx)(`div`,{className:`flex justify-start`,children:(0,q.jsxs)(`div`,{"data-tool-call-preview":!0,className:G(`w-full max-w-[85%] px-3.5`,Qm),children:[(0,q.jsx)($m,{e,presentation:Km(e),running:h(e)}),t?(0,q.jsx)(`span`,{className:`min-w-0 truncate text-xs`,children:t}):null]})})}if(t===`process`)return m.length===0?null:(0,q.jsx)(`div`,{className:`flex justify-start`,children:(0,q.jsx)(`div`,{"data-tool-call-panel":!0,className:`w-full max-w-[85%] space-y-1 px-3.5 text-xs`,children:m.map(e=>(0,q.jsx)(eh,{e,running:h(e),expanded:n&&m.length===1,onPreviewImage:s},e.id))})});let g=Array.from(new Set(m.map(e=>e.toolName).filter(Boolean))),_=qm(m),v=r?L:_.icon;return(0,q.jsx)(`div`,{className:`flex justify-start`,children:(0,q.jsxs)(`div`,{className:`w-full max-w-[85%] px-3.5`,children:[(0,q.jsxs)(`button`,{type:`button`,onClick:()=>p(!f),"aria-expanded":f,"data-tool-call-toggle":!0,title:d(g)||void 0,className:`inline-flex max-w-full flex-wrap items-center gap-1.5 rounded-sm py-1 text-xs text-muted-foreground transition-colors hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring`,children:[(0,q.jsx)(v,{className:G(`size-3.5 shrink-0`,r&&`animate-spin`)}),(0,q.jsx)(`span`,{className:`min-w-0 break-words [overflow-wrap:anywhere]`,children:_.label}),_.detail?(0,q.jsx)(`span`,{title:_.detail,className:`min-w-0 break-words text-[11px] text-muted-foreground opacity-70 [overflow-wrap:anywhere]`,children:_.detail}):null,(0,q.jsx)(ve,{className:G(`size-3 shrink-0 transition-transform`,f&&`rotate-90`)})]}),f?(0,q.jsx)(`div`,{"data-tool-call-panel":!0,className:`mt-1.5 space-y-1 border-l border-border pl-4 text-xs`,children:m.map(e=>(0,q.jsx)(eh,{e,running:h(e),onPreviewImage:s},e.id))}):null]})})}function nh(e){return typeof e.animate==`function`&&document.body.dataset.vdiSafe!==`true`&&!window.matchMedia?.(`(prefers-reduced-motion: reduce)`).matches}function rh(e,t){let n=getComputedStyle(e),r=n.getPropertyValue(t).trim(),i=Number.parseFloat(r)*(r.endsWith(`ms`)?1:1e3);return{duration:Number.isFinite(i)?i:t===`--motion-fast`?140:220,easing:n.getPropertyValue(`--motion-ease`).trim()||`cubic-bezier(0.2, 0.8, 0.2, 1)`}}function ih({preview:e,expanded:t}){let n=!t&&e?.running?e:void 0,r=(0,K.useRef)(void 0),[i,a]=(0,K.useState)(),o=i?.key,s=(0,K.useRef)(null),c=(0,K.useRef)(null);return(0,K.useLayoutEffect)(()=>{let i=r.current;r.current=n,t?a(void 0):i&&i.key!==n?.key&&a({...i,content:e?.snapshot?.(i.key)??(e?.key===i.key?e.content:i.content)})},[n,t,e]),(0,K.useLayoutEffect)(()=>{let e=s.current;if(!e||!nh(e))return;let t=e.animate([{opacity:0,transform:`translateY(4px)`},{opacity:1,transform:`translateY(0)`}],rh(e,`--motion-fast`));return()=>t.cancel()},[n?.key]),(0,K.useLayoutEffect)(()=>{let e=c.current;if(!e||!o)return;let t=()=>a(e=>e?.key===o?void 0:e);if(!nh(e)){t();return}let n=`${e.getBoundingClientRect().height}px`,r=e.animate([{height:n,opacity:1,transform:`translateY(0) scale(1)`,offset:0},{height:n,opacity:1,transform:`translateY(0) scale(1)`,offset:.35},{height:`0px`,opacity:0,transform:`translateY(-12px) scale(0.98)`}],{...rh(e,`--motion-normal`),fill:`forwards`});return r.finished.then(t,()=>{}),()=>r.cancel()},[o]),(0,q.jsxs)(`div`,{className:`-mx-3.5`,children:[i?(0,q.jsx)(`div`,{ref:c,"data-process-handoff":!0,"aria-hidden":`true`,style:{overflow:`hidden`,transformOrigin:`top left`},children:i.content}):null,n?(0,q.jsx)(`div`,{ref:s,"data-process-current":!0,children:n.content},n.key):null]})}function ah(e,t=72){if(!e||t<1)return``;let n=e.slice(-2048).replace(/^[\uDC00-\uDFFF]/u,``).replace(/\r\n?/g,`
|
|
8
|
+
`).replace(/^[ \t]*(?:`{3,}|~{3,})[^\n]*$/gm,``).replace(/^[ \t]*[-_*]{3,}[ \t]*$/gm,``).replace(/^[ \t]*(?:#{1,6}[ \t]+|>[ \t]*|[-+*][ \t]+|\d+[.)][ \t]+)+/gm,``).replace(/^[ \t]*\[[ xX]\][ \t]+/gm,``).replace(/!?\[([^\]\n]*)\]\([^)\n]*\)/g,`$1`).replace(/\[([^\]\n]+)\]\[[^\]\n]*\]/g,`$1`).replace(/<(https?:\/\/[^>]+)>/g,`$1`).replace(/`+|\*\*|__|~~/g,``).replace(/(^|[^\p{L}\p{N}])[*_]|[*_]($|[^\p{L}\p{N}])/gu,`$1$2`).split(/(?<=[。!?!?])[ \t]*|(?<=\.)[ \t]+|\n+/u).map(e=>e.replace(/\s+/g,` `).trim()).filter(Boolean).at(-1)??``,r=Array.from(n);return r.length>t?`${r.slice(0,t-1).join(``)}…`:n}function oh({children:e,reasoning:t,toolCallCount:n=0,active:r=!1,thinking:i=!1,status:a,label:o,hasDetails:s=!0,preview:c,open:l,onOpenChange:d,onToggle:p}){u();let[m,h]=(0,K.useState)(!1),g=(0,K.useId)(),_=(0,K.useRef)(null),v=l??m,y=o??f(r&&i?`thinking_64088d8c`:`process_activity`),b=ah(t),x=n>0?f(`process_tool_count`,{count:n}):``,S=ah(a??void 0)||x,C=r&&i&&!b&&!a?.trim()?y:r&&!i?S||b||y:b||S||y,w=()=>{let e=!v;l===void 0&&h(e),d?.(e),p?.(e)},T=(0,q.jsxs)(q.Fragment,{children:[s?(0,q.jsx)(ve,{className:`process-activity-icon size-3.5`,"aria-hidden":`true`}):null,s&&C!==y?(0,q.jsx)(`span`,{className:`process-activity-label`,children:y}):null,(0,q.jsx)(`span`,{"data-process-brief":!0,"data-process-shimmer":r&&i||void 0,className:`process-activity-brief${r&&i?` process-activity-shimmer`:``}`,children:C}),x&&C!==x?(0,q.jsx)(`span`,{className:`process-activity-count`,children:x}):null]});return(0,q.jsxs)(`div`,{"data-process-activity":!0,className:`process-activity`,children:[s?(0,q.jsx)(`button`,{ref:_,type:`button`,"data-process-toggle":!0,"aria-label":y,"aria-expanded":v,"aria-controls":g,className:`process-activity-toggle rounded-sm text-xs`,onClick:w,children:T}):(0,q.jsx)(`div`,{"data-process-status":!0,role:`status`,className:`process-activity-toggle rounded-sm text-xs`,style:{cursor:`default`},children:T}),(0,q.jsx)(ih,{preview:c?{...c,running:r&&c.running}:void 0,expanded:v}),s?(0,q.jsx)(am,{id:g,"data-process-content":!0,role:`region`,"aria-label":y,expanded:v,triggerRef:_,className:`process-activity-content`,children:(0,q.jsx)(`div`,{className:`process-activity-content-body`,children:e})}):null]})}function sh({notice:e}){return u(),(0,q.jsxs)(`div`,{"data-runtime-notice":e.runtimeKind,className:`border border-border/60 bg-muted/30 text-muted-foreground flex items-start gap-2.5 rounded-lg px-3 py-2.5 text-sm`,children:[(0,q.jsx)(Vr,{className:`mt-0.5 size-4 shrink-0`,"aria-hidden":`true`}),(0,q.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,q.jsx)(`div`,{className:`font-medium text-foreground`,children:f(`runtime_notice_background_exec_title_1b8a7ef0`)}),(0,q.jsx)(`div`,{className:`mt-0.5`,children:f(`runtime_notice_background_exec_body_c90c9f52`)}),e.execSessionId?(0,q.jsx)(`div`,{className:`mt-1 font-mono text-xs break-all opacity-70`,children:f(`runtime_notice_background_exec_handle_0f9a6d34`,{v0:e.execSessionId})}):null]})]})}function ch({className:e}){return u(),(0,q.jsxs)(`div`,{className:G(`text-muted-foreground flex items-center gap-2 text-sm`,e),children:[(0,q.jsx)(L,{className:`size-4 animate-spin`,"aria-hidden":`true`}),f(`runtime_notice_background_exec_running_93d0e2c1`)]})}var lh=e=>typeof e==`string`&&e.toLowerCase().replace(/[_-]/g,``)===`subagent`,uh=new Set([`intent`,`target`,`role`,`message`,`reply_to`]),dh=e=>e==null||e===``;function fh(e){if(!e||typeof e!=`object`||Array.isArray(e))return null;let t=e;return t.action===`create`?`child_session_id`:Object.keys(t).some(e=>!uh.has(e))||t.intent!==void 0&&t.intent!==`chat`||!dh(t.target)||!dh(t.reply_to)||!dh(t.role)&&typeof t.role!=`string`||typeof t.message!=`string`||!t.message.trim()?null:`actor_id`}function ph(e,t){let n=new Map,r=new Map;for(let i of e)for(let e of i.messages){if(!(`type`in e))continue;if(e.role===`assistant`&&e.type===`tool_call`)for(let t of e.toolCalls){let e=lh(t.toolName)?fh(t.parameters):null;e&&!n.has(t.toolCallId)&&n.set(t.toolCallId,{key:i.key,field:e})}if(e.type!==`tool_result`||e.isError)continue;let a=n.get(e.toolCallId);if(!(!a||typeof e.result?.result!=`string`||e.result.result.length>65536))try{let n=JSON.parse(e.result.result);if(!n||typeof n!=`object`||Array.isArray(n))continue;let i=n,o=i[a.field];typeof o==`string`&&i.reused!==!0&&Object.hasOwn(t,o)&&!r.has(o)&&r.set(o,a.key)}catch{}}let i=new Map;for(let[e,n]of r){let r=i.get(n)??{};r[e]=t[e],i.set(n,r)}return{byOrigin:i,unplaced:Object.fromEntries(Object.entries(t).filter(([e])=>!r.has(e)))}}function mh(e){switch(e.status?.toLowerCase()){case`running`:return`running`;case`completed`:case`succeeded`:case`done`:return`done`;case`error`:case`failed`:return`error`;case`cancelled`:return`cancelled`;case`queued`:case`reserved`:return`queued`;case`idle`:case`cold`:case`created`:return`idle`;case`retired`:return`retired`;default:return`unknown`}}var hh={get running(){return f(`running_1f0eb99b`)},get done(){return f(`done_c0b3fbff`)},get error(){return f(`failed_28384d7a`)},get cancelled(){return f(`workflow_run_status_cancelled`)},get queued(){return f(`workflow_run_status_queued`)},get idle(){return f(`idle_dae661d1`)},get retired(){return f(`exited_899df7e2`)},get unknown(){return f(`plugin_connection_unknown`)}};function gh({child:e,childId:t,onOpen:n,expanded:r,onExpandedChange:i}){u();let[a,o]=(0,K.useState)(!1),s=r??a,c=(0,K.useId)(),l=mh(e),d=e.error||e.outputPreview,p=e.placement??null;return(0,q.jsxs)(`article`,{"data-subagent-id":t,"data-subagent-status":l,"data-expansion-key":`subagent-${t}`,className:G(`w-full overflow-hidden rounded-lg border text-left transition-colors`,l===`running`?`border-primary/40 bg-primary/5`:`bg-muted/30`),children:[(0,q.jsxs)(`button`,{type:`button`,"data-subagent-toggle":!0,"aria-expanded":s,"aria-controls":c,onClick:()=>i?i(!s):o(!s),className:`flex w-full items-center gap-2 rounded-lg px-3 py-2 text-left hover:bg-accent/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring`,children:[l===`running`?(0,q.jsx)(L,{className:`size-3.5 shrink-0 animate-spin text-primary`}):l===`error`?(0,q.jsx)(P,{className:`size-3.5 shrink-0 text-destructive`}):l===`done`?(0,q.jsx)(de,{className:`size-3.5 shrink-0 text-emerald-500`}):(0,q.jsx)(P,{className:`size-3.5 shrink-0 text-muted-foreground`}),(0,q.jsx)(ae,{className:`size-3.5 shrink-0 text-muted-foreground`}),(0,q.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-sm font-medium`,children:e.title||f(`sub_agent_acd37b4c`)}),(0,q.jsx)(qp,{placement:p,compact:!0,className:`max-w-32 shrink-0`}),(0,q.jsxs)(`span`,{className:`shrink-0 text-xs text-muted-foreground`,children:[hh[l],typeof e.roundCount==`number`?f(`rounds_6ff24cb5`,{v0:e.roundCount,count:e.roundCount}):``]}),(0,q.jsx)(ve,{"aria-hidden":`true`,className:G(`size-4 shrink-0 text-muted-foreground transition-transform`,s&&`rotate-90`)})]}),(0,q.jsxs)(`div`,{id:c,"data-subagent-details":!0,hidden:!s,className:`space-y-2 border-t px-3 py-2`,children:[d?(0,q.jsx)(`div`,{className:G(`whitespace-pre-wrap text-xs leading-relaxed [overflow-wrap:anywhere]`,l===`error`?`text-destructive`:`text-muted-foreground`),children:d}):null,n?(0,q.jsx)(`button`,{type:`button`,onClick:n,className:`text-xs underline focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring`,children:f(`subagent_open_conversation`,{title:e.title||f(`sub_agent_acd37b4c`)})}):null]})]})}function _h({agents:e,onOpen:t,originUnconfirmed:n=!1,expandedIds:r,onExpandedChange:i}){u();let a=Object.entries(e);return a.length===0?null:(0,q.jsx)(`div`,{className:`flex justify-start`,"data-subagent-group":!0,children:(0,q.jsxs)(`div`,{className:`ml-1 w-full max-w-[85%] space-y-1.5 border-l-2 border-border/60 pl-3`,children:[(0,q.jsxs)(`div`,{className:`text-xs font-medium text-muted-foreground`,children:[f(`subagents_76d97a95`),a.length,`)`]}),n?(0,q.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:f(`subagent_origin_unknown`)}):null,a.map(([e,n])=>(0,q.jsx)(gh,{childId:e,child:n,onOpen:t?()=>t(e):void 0,expanded:r?.has(e),onExpandedChange:i?t=>i(e,t):void 0},e))]})})}function vh(e){let t=[];for(let n of e.calls)t.push({id:`live-call-${n.toolCallId}`,role:`assistant`,type:`tool_call`,toolCalls:[{toolCallId:n.toolCallId,toolName:n.toolName,parameters:n.args??{}}],createdAt:``}),(n.output||n.images?.length||n.status!==`running`)&&t.push({id:`live-res-${n.toolCallId}`,role:`tool`,type:`tool_result`,toolCallId:n.toolCallId,toolName:n.toolName,isError:n.status===`error`,result:{tool_name:n.toolName,display_preference:`Default`,result:n.status===`error`&&n.error||n.output},images:n.images?.map((e,t)=>({id:`${n.toolCallId}-image-${t}`,base64:e.data,type:e.mime_type,name:f(`tool_image_7b8fcc11`,{v0:t+1}),size:0})),createdAt:``});return t}function yh(e){return`content`in e&&typeof e.content==`string`?e.content:`displayText`in e&&typeof e.displayText==`string`?e.displayText:``}function bh(e){let t=e.type;return t===`tool_call`||t===`tool_result`}function xh(e){let t=e.metadata?.reasoning;return typeof t==`string`?t:``}var Sh=8,Ch={width:1024,height:720};function wh(e,t){return ha(e,e=>t({width:e.width||Ch.width,height:e.height||Ch.height}))}function Th(e,t,n){let r=ba(e,t,n);return r>0?r:n.options.estimateSize(n.indexFromElement(e))}var Eh=`min-w-0 overflow-hidden rounded-2xl px-3.5 py-2 [overflow-wrap:anywhere]`,Dh=`flex-1 bg-transparent text-base font-normal leading-7 text-foreground`;function Oh(e,t,n){let r=e.at(-1),i=r?.kind===`process`?r:{kind:`process`,key:`activity-${t}`,parts:[]};i!==r&&e.push(i);let a=i.parts.at(-1);return a?.kind===`tools`&&n.kind===`tools`?(a.items.push(...n.items),n.runningCallIds&&(a.runningCallIds=new Set([...a.runningCallIds??[],...n.runningCallIds]))):i.parts.push(n),i}function kh(e){let t=[];for(let n of e)if(n.role!==`system`)if(bh(n))Oh(t,n.id,{kind:`tools`,items:[n]});else{let e=n.role===`assistant`?xh(n):``;e.trim()&&Oh(t,n.id,{kind:`reasoning`,text:e,createdAt:n.createdAt});let r=n.images;(yh(n).trim()||r?.length)&&t.push({kind:`msg`,m:n})}return t}function Ah(e,t,n,r,i){let a=[],o=0,s=(e,t,n=!1)=>{t?.trim()&&Oh(a,`live-${o}`,{kind:`reasoning`,text:t}),e.trim()&&a.push({kind:`msg`,streaming:n,m:{id:`live-body-${o++}`,role:`assistant`,type:`text`,content:e,createdAt:``}})};for(let t of e)t.kind===`text`?s(t.text,t.reasoning):t.calls.length&&Oh(a,`live-${o}`,{kind:`tools`,items:vh(t),runningCallIds:new Set(t.calls.filter(e=>e.status===`running`).map(e=>e.toolCallId))});if(s(t??``,n,r),r&&(!t?.trim()||i)){let e=a.at(-1),n=e?.kind===`process`?e:{kind:`process`,key:`activity-live-${o}`,parts:[]};n!==e&&a.push(n),n.active=!0;let r=n.parts.some(e=>e.kind===`tools`&&e.runningCallIds?.size);n.thinking=!t?.trim()&&!r&&!i?.trim(),n.status=i}return a}function jh(e,t=`first`){let n=e.kind===`msg`?[e.m.createdAt]:e.parts.flatMap(e=>e.kind===`tools`?e.items.map(e=>e.createdAt):[e.createdAt]),r=t===`first`?n:[...n].reverse();for(let e of r){let t=Date.parse(String(e||``));if(Number.isFinite(t))return t}return null}function Mh(e){if(!Number.isFinite(e)||e<=0)return null;let t=Math.max(1,Math.round(e/1e3)),n=Math.floor(t/3600),r=Math.floor(t%3600/60),i=t%60;return n>0?f(`h_69c6dc51`,{v0:n,v1:r>0?f(`m_977a465a`,{v0:r,v1:``}):``}):r>0?f(`m_977a465a`,{v0:r,v1:i>0?f(`s_6366b823`,{v0:i}):``}):f(`s_6366b823`,{v0:i})}function Nh(e){if(e.kind!==`msg`||e.m.role!==`assistant`)return!1;let t=e.m.images;return!!(yh(e.m).trim()||t?.length)}function Ph(e,t){let n=new Set,r=null;for(let t=0;t<e.length;t+=1){let i=e[t];if(i.kind===`msg`&&i.m.role===`user`){r!==null&&n.add(r),r=null;continue}i.kind!==`collapsedTurn`&&Nh(i)&&(r=t)}return t&&r!==null&&n.add(r),n}function Fh(e,t){let n=[],r=0,i=e=>e.kind===`msg`&&e.m.role===`user`;for(let t=0;t<=e.length;t+=1){if(t<e.length&&!i(e[t]))continue;let a=null;for(let n=t-1;n>r;--n){if(Nh(e[n])){a=n;break}if(e[n].kind===`process`)break}n.push({start:r,end:t,summary:a}),r=t}let a=new Set,o=[];for(let r=0;r<n.length;r+=1){let{start:i,end:s,summary:c}=n[r];if(c==null||c!==s-1||!t&&r===n.length-1)continue;let l=[];for(let e=i+1;e<c;e+=1)l.push(e);if(!l.length||!l.some(t=>e[t].kind===`process`))continue;let u=l.flatMap(t=>{let n=e[t];return n.kind===`msg`?[n.m.createdAt]:n.parts.flatMap(e=>e.kind===`tools`?e.items.map(e=>e.createdAt):[e.createdAt])}),d=u.map(e=>Date.parse(String(e||``))).find(Number.isFinite),f=[...u].reverse().map(e=>Date.parse(String(e||``))).find(Number.isFinite);for(let e of l)a.add(e);o.push({kind:`collapsedTurn`,key:`collapsed-turn-${e[c].kind===`msg`?e[c].m.id:i}`,finalId:e[c].kind===`msg`?e[c].m.id:``,items:l.map(t=>e[t]),indexes:l,toolCalls:Ih(e.slice(i+1,c)),startedAt:d??null,finishedAt:f??null})}if(!o.length)return e;let s=[];for(let t=0;t<e.length;t+=1){let n=o.find(e=>e.indexes[0]===t);if(n){s.push(n),t=n.indexes[n.indexes.length-1];continue}a.has(t)||s.push(e[t])}return s}function Ih(e){let t=new Set;for(let n of e)if(n.kind===`process`)for(let e of n.parts.flatMap(e=>e.kind===`tools`?e.items:[]))for(let n of e.toolCalls??[])n.toolCallId&&t.add(n.toolCallId);return t.size}function Lh(e,t){return e.kind===`msg`?`message-${e.m.id}`:e.key||`activity-${t}`}function Rh(e){return e.map((e,t)=>e.kind===`collapsedTurn`?{key:e.key,item:e,itemIndex:t}:{key:Lh(e,t),item:e,itemIndex:t})}function zh(e,t,n,r){return e?e.item.kind===`collapsedTurn`?r?96+e.item.items.length*40:24:e.item.kind===`process`?t?96+e.item.parts.length*(n?160:40):36:e.item.m.role===`user`?112:220:120}function Bh(e,t,n){if(e.has(t)===n)return e;let r=new Set(e);return n?r.add(t):r.delete(t),r}function Vh(e,t,n){for(let r of e)t.has(r)||n.add(r);for(let r of t)e.has(r)||n.add(r)}function Hh(e,t){typeof e==`function`?e(t):e&&(e.current=t)}var Uh=`items-center justify-center rounded-md text-muted-foreground transition-colors hover:bg-accent hover:text-foreground disabled:pointer-events-none disabled:opacity-50`,Wh={width:28,height:28};function Gh({messageId:e,text:t,isUser:n,sending:r,forking:i,onEdit:a,executionBlocked:o,onRegenerate:s,onFork:l,onDelete:d}){u();let p=cm(t,e),m=p.status===`copied`,h=()=>void p.copy();return(0,q.jsxs)(`div`,{"data-message-actions":e,"data-copy-state":p.status,className:G(`relative flex shrink-0 items-center gap-0.5 opacity-100 transition-opacity focus-within:opacity-100 group-hover:opacity-100`,p.status===`idle`&&`md:opacity-0`),children:[(0,q.jsx)(`span`,{role:`status`,className:`sr-only`,children:m?(0,q.jsx)(`span`,{children:f(`copied_8f6f8d97`)},p.sequence):null}),p.status===`error`?(0,q.jsx)(`span`,{role:`alert`,className:`absolute bottom-full end-0 z-10 mb-1 w-max max-w-48 rounded-md bg-popover px-2 py-1 text-xs text-popover-foreground shadow-sm`,children:String(c.t(`components.markdown.copyFailed`))}):null,(0,q.jsx)(`button`,{type:`button`,onClick:h,className:`${Uh} hidden md:inline-flex`,style:Wh,"aria-label":f(`copy_63d90d97`),title:f(m?`copied_8f6f8d97`:`copy_63d90d97`),children:(0,q.jsx)(om,{confirmed:m,sequence:p.sequence,className:`size-3.5`})}),(0,q.jsx)(`button`,{type:`button`,onClick:l,disabled:i,className:`${Uh} hidden md:inline-flex`,style:Wh,"aria-label":f(`fork_from_here_28321cb9`),title:f(`fork_into_a_new_session_from_here_53c2881c`),children:(0,q.jsx)(Er,{className:`size-3.5`})}),(0,q.jsxs)(ke,{children:[(0,q.jsx)(V,{asChild:!0,children:(0,q.jsxs)(`button`,{type:`button`,className:`${Uh} inline-flex`,style:Wh,"aria-label":f(`more_message_actions_cecaef80`),title:f(`more_message_actions_cecaef80`),children:[(0,q.jsx)(Xn,{className:`hidden size-3.5 md:block`}),(0,q.jsx)(om,{confirmed:m,sequence:p.sequence,fallback:Xn,className:`size-3.5 md:hidden`})]})}),(0,q.jsxs)(z,{side:`bottom`,align:n?`end`:`start`,className:`rounded-xl`,style:{minWidth:`10rem`},children:[(0,q.jsxs)(B,{className:`md:hidden`,onClick:h,children:[(0,q.jsx)(Ae,{}),f(`copy_63d90d97`)]}),(0,q.jsxs)(B,{className:`md:hidden`,disabled:i,onClick:l,children:[(0,q.jsx)(Er,{}),f(`fork_from_here_28321cb9`)]}),(0,q.jsx)(De,{className:`md:hidden`}),n?(0,q.jsxs)(B,{disabled:o,onClick:a,children:[(0,q.jsx)(j,{}),f(`edit_and_resend_f857c444`)]}):(0,q.jsxs)(B,{disabled:r||o,onClick:s,children:[(0,q.jsx)(ce,{}),f(`regenerate_3221a042`)]}),(0,q.jsx)(De,{}),(0,q.jsxs)(B,{variant:`destructive`,onClick:d,children:[(0,q.jsx)(M,{}),f(`delete_2f9daa82`)]})]})]})]})}function Kh({scrollRef:e,contentRef:t,onScroll:n,messages:r,mergedSubAgents:i,subAgentError:a,onRefreshSubAgents:o,sending:s,latestRunFinished:c,streaming:l,streamingActive:d,streamingReasoning:p,liveSegments:m,streamStatus:h,backgroundExecWaiting:g=!1,pendingUserText:_,pendingUserImages:v=[],pendingUserMessages:y,contentShiftX:b=0,readOnly:x=!1,executionBlocked:S=!1,forking:C,onSelectSubAgent:w,onPreviewImage:T,onRegenerate:E,onFork:D,onDelete:O,onEditMessage:k}){u();let[A,j]=(0,K.useState)(null),M=y??(_?.trim()||v.length?[{operationId:0,text:_??``,images:v}]:[]),N=M.length>0,P=(0,K.useMemo)(()=>kh(r),[r]),F=(0,K.useMemo)(()=>Ah(m,l,p,s||d,h),[m,s,h,l,d,p]),I=(0,K.useMemo)(()=>Fh(P,!(s||F.length>0)),[P,s,F.length]),ee=(0,K.useMemo)(()=>Ph(I,!s),[I,s]),L=(0,K.useMemo)(()=>Rh(I),[I]),[te,R]=(0,K.useState)(()=>new Set),[ne,re]=(0,K.useState)(()=>new Set),[ie,ae]=(0,K.useState)(()=>new Set),[oe,se]=(0,K.useState)(()=>new Set),ce=(0,K.useRef)(L),le=(0,K.useRef)(te),ue=(0,K.useRef)(ne),de=(0,K.useRef)(ie);ce.current=L,le.current=te,ue.current=ne,de.current=ie;let fe=(0,K.useRef)(null),pe=(0,K.useCallback)(t=>{fe.current=t,Hh(e,t)},[e]),me=(0,K.useCallback)(()=>fe.current,[]),he=(0,K.useCallback)(e=>ce.current[e]?.key??e,[]),ge=(0,K.useCallback)(e=>{let t=ce.current[e];return zh(t,!!(t&&le.current.has(t.key)),t?.item.kind===`process`&&t.item.parts.some(e=>e.kind===`tools`&&ue.current.has(`tools-${e.items[0]?.id}`)),!!(t&&de.current.has(t.key)))},[]),_e=ka({count:L.length,getScrollElement:me,getItemKey:he,estimateSize:ge,gap:Sh,overscan:6,initialRect:Ch,observeElementRect:wh,measureElement:Th,useAnimationFrameWithResizeObserver:!0}),ye=(0,K.useRef)({openProcessKeys:te,openToolKeys:ne,openSubAgentIds:oe,openTurnKeys:ie}),be=(0,K.useRef)(L.map(e=>e.key));(0,K.useLayoutEffect)(()=>{let e=be.current;if(be.current=L.map(e=>e.key),!(e.length!==L.length||e.some((e,t)=>e!==L[t]?.key)))return;let t=fe.current?.querySelectorAll(`[data-history-entry-key]`);for(let e of t??[]){let t=_e.indexFromElement(e);t<0||_e.resizeItem(t,e.offsetHeight||ge(t))}},[ge,L,_e]),(0,K.useLayoutEffect)(()=>{let e=ye.current;ye.current={openProcessKeys:te,openToolKeys:ne,openSubAgentIds:oe,openTurnKeys:ie};let t=new Set;Vh(e.openProcessKeys,te,t),Vh(e.openToolKeys,ne,t),Vh(e.openTurnKeys,ie,t);let n=new Set;Vh(e.openSubAgentIds,oe,n);for(let e of n)t.add(`subagent-${e}`);if(t.size===0)return;let r=fe.current?.querySelectorAll(`[data-history-entry-key]`);for(let e of r??[]){if(!(e.dataset.historyEntryKey&&t.has(e.dataset.historyEntryKey)||[...e.querySelectorAll(`[data-expansion-key]`)].some(e=>t.has(e.dataset.expansionKey??``))))continue;let n=_e.indexFromElement(e);_e.resizeItem(n,e.offsetHeight||ge(n))}},[ge,te,ne,oe,ie,_e]);let xe=(0,K.useCallback)((e,t)=>{R(n=>Bh(n,e,t))},[]),Se=(0,K.useCallback)((e,t)=>{re(n=>Bh(n,e,t))},[]),Ce=(0,K.useCallback)((e,t)=>{ae(n=>Bh(n,e,t))},[]),we=(0,K.useCallback)((e,t)=>{se(n=>Bh(n,e,t))},[]),Te=(0,K.useRef)(new Map),Ee=e=>{let t=Te.current.get(e);return t||(t={current:null},Te.current.set(e,t)),t},z=(0,K.useMemo)(()=>ph([...P,...F].flatMap(e=>e.kind===`process`?[{key:e.key,messages:e.parts.flatMap(e=>e.kind===`tools`?e.items:[])}]:[]),i),[P,F,i]),De=e=>e?.length?(0,q.jsx)(`div`,{className:`mb-1.5 flex flex-wrap gap-1.5`,children:e.map((e,t)=>{let n=e.url||`data:${e.type||`image/png`};base64,${e.base64}`;return(0,q.jsx)(`img`,{src:n,alt:``,className:`max-h-48 cursor-zoom-in rounded-xl transition-opacity hover:opacity-90`,onClick:()=>T(n)},t)})}):null,B=(e,t,n)=>{if(e.kind===`collapsedTurn`){let t=ie.has(e.key),n=e.startedAt!=null&&e.finishedAt!=null?Mh(e.finishedAt-e.startedAt):null,r=n?e.toolCalls>0?f(`turn_collapse_processed_with_tools`,{v0:n,count:e.toolCalls}):f(`processed_db5f0926`,{v0:n}):e.toolCalls>0?f(`process_tool_count`,{count:e.toolCalls}):f(`process_activity`),i=`turn-content-${e.key}`;return(0,q.jsxs)(`div`,{"data-turn-collapse":e.key,"data-expansion-key":e.key,children:[(0,q.jsxs)(`button`,{type:`button`,"data-turn-toggle":!0,ref:Ee(e.key),"aria-expanded":t,"aria-controls":i,"aria-label":r,className:`flex w-full items-center gap-3 py-1 text-xs text-muted-foreground`,onClick:()=>Ce(e.key,!t),children:[(0,q.jsx)(`span`,{className:`h-px flex-1 bg-border`,"aria-hidden":`true`}),(0,q.jsx)(`span`,{className:`whitespace-nowrap`,"data-turn-brief":!0,children:r}),(0,q.jsx)(ve,{className:`size-3 shrink-0 ${t?`rotate-90`:``}`,"aria-hidden":`true`}),(0,q.jsx)(`span`,{className:`h-px flex-1 bg-border`,"aria-hidden":`true`})]}),(0,q.jsx)(am,{id:i,expanded:t,triggerRef:Ee(e.key),className:`turn-collapse-content`,children:(0,q.jsx)(`div`,{className:`flex flex-col gap-2 pt-1`,children:e.items.map((t,n)=>(0,q.jsx)(K.Fragment,{children:B(t,-1)},Lh(t,e.indexes[n])))})})]},e.key)}if(e.kind===`process`){let t=n?.live?e.active:e===P.at(-1)&&s&&!N&&!c&&F.length===0,r=e.parts.findLast(e=>e.kind===`reasoning`),i=e.parts.findLast(e=>e.kind===`tools`&&e.runningCallIds?.size)??e.parts.findLast(e=>e.kind===`tools`),a=i?.kind===`tools`?i:void 0,o=a?.items.flatMap(e=>`type`in e&&e.type===`tool_call`?e.toolCalls.map(e=>e.toolCallId):[]),l=o?.findLast(e=>a?.runningCallIds?.has(e))??o?.at(-1),u=a&&l?{key:l,running:!!a.runningCallIds?.size,content:(0,q.jsx)(th,{items:a.items,presentation:`preview`,active:!!(t&&a.runningCallIds?.size),runningCallIds:a.runningCallIds??new Set}),snapshot:n=>{let r=e.parts.flatMap(e=>e.kind===`tools`?e.items.flatMap(e=>{if(`type`in e&&e.type===`tool_call`){let t=e.toolCalls.filter(e=>e.toolCallId===n);return t.length?[{...e,toolCalls:t}]:[]}return`toolCallId`in e&&e.toolCallId===n?[e]:[]}):[]),i=new Set(e.parts.flatMap(e=>e.kind===`tools`?[...e.runningCallIds??[]]:[]));return(0,q.jsx)(th,{items:r,presentation:`preview`,active:!!(t&&i.has(n)),runningCallIds:i})}}:void 0,d=jh(e),p=jh(e,`last`),m=!n?.live&&!t&&Ih([e])&&d!=null&&p!=null?Mh(p-d):null,h=(0,q.jsx)(`div`,{"data-expansion-key":e.key,children:(0,q.jsx)(oh,{reasoning:r?.kind===`reasoning`?r.text:void 0,toolCallCount:Ih([e]),label:m?f(`processed_db5f0926`,{v0:m}):void 0,active:t,thinking:e.thinking,status:u?.running?void 0:e.status,hasDetails:e.parts.length>0,preview:u,open:te.has(e.key),onOpenChange:t=>xe(e.key,t),children:(0,q.jsx)(`div`,{className:`-mx-3.5 flex flex-col gap-2`,children:e.parts.map((n,r)=>{if(n.kind===`reasoning`)return(0,q.jsx)(`div`,{className:`px-3.5`,children:(0,q.jsx)(ym,{text:n.text})},`reasoning-${r}`);let i=`tools-${n.items[0]?.id}`;return(0,q.jsx)(`div`,{"data-expansion-key":i,children:(0,q.jsx)(th,{items:n.items,presentation:`process`,singleExpanded:Ih([e])===1,active:n.runningCallIds===void 0?!!(t&&r===e.parts.length-1):n.runningCallIds.size>0,runningCallIds:n.runningCallIds,open:ne.has(i),onOpenChange:e=>Se(i,e),onPreviewImage:T})},i)})})})}),g=z.byOrigin.get(e.key);return g?(0,q.jsxs)(K.Fragment,{children:[h,(0,q.jsx)(_h,{agents:g,onOpen:w,expandedIds:oe,onExpandedChange:we})]},e.key):h}let r=e.m,i=yh(r),a=r.images,o=r.role===`user`,l=o?null:sp(r.metadata,i),u=!x&&!n?.live&&!Je(r)&&(o||ee.has(t));if(!i.trim()&&!a?.length)return null;if(o&&A?.id===r.id)return(0,q.jsx)(`div`,{className:`flex flex-col items-end`,children:(0,q.jsxs)(`div`,{className:`w-full max-w-[85%]`,children:[(0,q.jsx)(Mn,{value:A.text,onChange:e=>j({id:r.id,text:e.target.value}),onKeyDown:e=>{e.key===`Escape`&&j(null),!S&&e.key===`Enter`&&(e.metaKey||e.ctrlKey)&&(k(r.id,A.text),j(null))},autoFocus:!0,className:`min-h-16 bg-card`}),(0,q.jsxs)(`div`,{className:`mt-1.5 flex justify-end gap-2`,children:[(0,q.jsx)(W,{size:`sm`,variant:`secondary`,onClick:()=>j(null),children:f(`cancel_2cd0f3be`)}),(0,q.jsx)(W,{size:`sm`,disabled:S,onClick:()=>{k(r.id,A.text),j(null)},children:f(`save_and_resend_b45cc57a`)})]})]})},r.id);let d=u?(0,q.jsx)(Gh,{messageId:r.id,text:i,isUser:o,sending:s,forking:C,onEdit:()=>j({id:r.id,text:i}),onRegenerate:E,executionBlocked:S,onFork:()=>D(r.id),onDelete:()=>O(r.id)}):null;return(0,q.jsxs)(`div`,{"data-message-row":r.id,className:G(`group flex w-full items-end gap-1.5`,o?`justify-end`:`justify-start`),children:[o?d:null,(0,q.jsxs)(`div`,{"data-message-role":o?`user`:`assistant`,className:G(Eh,o?`user-message-surface max-w-[85%] whitespace-pre-wrap text-base leading-7`:Dh),children:[De(a),o?(0,q.jsxs)(q.Fragment,{children:[r.role===`user`&&`inReplyTo`in r&&r.inReplyTo?(0,q.jsxs)(`div`,{className:`mb-1 text-xs`,"data-testid":`message-request-reference`,children:[f(`ticket_referenced_request__7209ca36`),r.inReplyTo]}):null,i]}):l?(0,q.jsx)(sh,{notice:l}):i.trim()?(0,q.jsx)(vm,{isStreaming:!!e.streaming,onPreviewImage:T,children:i}):null]}),o?null:d]},r.id)},Oe=e=>B(e.item,e.itemIndex),ke=_e.getVirtualItems();return(0,q.jsx)(`div`,{ref:pe,onScroll:n,className:`min-h-0 min-w-0 flex-1 overflow-y-auto px-3`,children:(0,q.jsxs)(`div`,{ref:t,"data-message-list-content":!0,className:`relative mx-auto flex min-w-0 w-full max-w-full flex-col gap-2 py-4`,style:{transform:`translateX(${b}px)`,transition:`transform var(--motion-normal) var(--motion-ease)`},children:[a?(0,q.jsxs)(`div`,{role:`status`,className:`text-xs text-muted-foreground`,"data-subagent-error":!0,children:[a,o?(0,q.jsx)(W,{variant:`ghost`,size:`sm`,onClick:o,children:f(`subagent_refresh`)}):null]}):null,(0,q.jsx)(_h,{agents:z.unplaced,originUnconfirmed:!0,onOpen:w,expandedIds:oe,onExpandedChange:we}),r.length===0&&!l&&!N&&m.length===0&&(0,q.jsxs)(`div`,{className:`flex flex-col items-center gap-2 py-20 text-center`,children:[(0,q.jsx)(so,{className:`size-10 text-primary`}),(0,q.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:f(`start_a_new_conversation_bab6ab18`)})]}),L.length>0?(0,q.jsx)(`div`,{"data-virtual-history":!0,className:`relative w-full`,style:{height:_e.getTotalSize()},children:ke.map(e=>{let t=L[e.index];return t?(0,q.jsx)(`div`,{ref:_e.measureElement,"data-history-entry-key":t.key,"data-index":e.index,className:G(`absolute left-0 top-0 w-full`,e.index>0&&t.item.kind===`msg`&&t.item.m.role===`user`&&`pt-2`),style:{transform:`translateY(${e.start}px)`},children:Oe(t)},e.key):null})}):null,M.map(e=>(0,q.jsx)(`div`,{className:`mt-2 flex justify-end`,children:(0,q.jsxs)(`div`,{"data-pending-user-message":!0,"data-pending-operation":e.operationId,"data-message-role":`user`,className:`user-message-surface max-w-[85%] overflow-hidden whitespace-pre-wrap rounded-2xl px-3.5 py-2 text-base leading-7 [overflow-wrap:anywhere]`,children:[De(e.images),e.text]})},e.operationId)),F.map((e,t)=>(0,q.jsx)(K.Fragment,{children:B(e,t,{live:!0})},Lh(e,t))),!l&&g?(0,q.jsx)(ch,{className:`px-1 py-1`}):null]})})}var qh=e=>`sessions/${encodeURIComponent(e)}/guidance`,Jh={imageUrl:(e,t)=>Ot.resolveUrl(`sessions/${encodeURIComponent(e)}/attachments/${encodeURIComponent(t)}`),list:e=>Ot.get(qh(e)),send:(e,t,n,r=`after_round`,i=[])=>Ot.post(qh(e),{id:t,text:n,mode:r,images:i}),cancel:(e,t)=>Ot.delete(`${qh(e)}/${encodeURIComponent(t)}`)},Yh=e=>`lotus-next.guidance-submission.${e}`,Xh=e=>`lotus-next.guidance-mode.${e}`;function Zh(e){try{let t=JSON.parse(sessionStorage.getItem(Yh(e))??`null`);if(typeof t?.id==`string`&&typeof t?.fingerprint==`string`)return t}catch{}return null}function Qh(e){try{if(e&&sessionStorage.getItem(Xh(e))===`after_run`)return`after_run`}catch{}return`after_round`}function $h(e,t){u();let[n,r]=(0,K.useState)(null),[i,a]=(0,K.useState)(null),[o,s]=(0,K.useState)(null),[c,l]=(0,K.useState)({sessionId:e,mode:Qh(e)}),[d,p]=(0,K.useState)(e&&Zh(e)?e:null),m=(0,K.useRef)(!1),h=(0,K.useRef)(e);h.current=e;let g=(0,K.useRef)(!0),_=(0,K.useRef)(0),v=(0,K.useRef)(new Map),y=c.sessionId===e?c.mode:Qh(e),b=t=>{l({sessionId:e,mode:t});try{e&&sessionStorage.setItem(Xh(e),t)}catch{}},x=async e=>{let t=++_.current,n=await Jh.list(e);g.current&&h.current===e&&t===_.current&&r({sessionId:e,messages:n.messages})},S=()=>{++_.current};return(0,K.useEffect)(()=>(g.current=!0,()=>{g.current=!1}),[]),(0,K.useEffect)(()=>{if(!e)return;let n=!1,r,i=async()=>{try{await x(e)}catch{}n||(r=setTimeout(()=>void i(),t?1500:5e3))};return i(),()=>{n=!0,clearTimeout(r),S()}},[e,t]),{mode:y,setMode:b,send:async(t,n=[])=>{if(!e||!t.trim()&&!n.length)return{kind:`ignored`};if(dc(e)!==`clear`||wo(e))return{kind:`blocked`};if(m.current)return{kind:`busy`};m.current=!0;let r=e;s(r),a(null);let i=null,o=null;try{let e=new TextEncoder().encode(JSON.stringify({text:t,images:n,mode:y})),a=Array.from(new Uint8Array(await crypto.subtle.digest(`SHA-256`,e)),e=>e.toString(16).padStart(2,`0`)).join(``),s=v.current.get(r)??Zh(r),c=s?.fingerprint===a?s:{id:crypto.randomUUID(),fingerprint:a};c!==s&&(i=c.id,o=s),v.current.set(r,c);try{sessionStorage.setItem(Yh(r),JSON.stringify(c))}catch{}if(dc(r)!==`clear`||wo(r)){if(c!==s){s?v.current.set(r,s):v.current.delete(r);try{s?sessionStorage.setItem(Yh(r),JSON.stringify(s)):sessionStorage.removeItem(Yh(r))}catch{}}return{kind:`blocked`}}if((await Jh.send(r,c.id,t,y,n)).id!==c.id)throw Error(`Queue acknowledgement identity mismatch`);v.current.delete(r);try{sessionStorage.removeItem(Yh(r))}catch{}if(g.current&&h.current===r){p(null);try{await x(r)}catch{}}return{kind:`accepted`,operationId:0,sessionId:r,navigated:!1}}catch(e){if(Ao(r,e)){if(i!==null){v.current.get(r)?.id===i&&(o?v.current.set(r,o):v.current.delete(r));try{Zh(r)?.id===i&&(o?sessionStorage.setItem(Yh(r),JSON.stringify(o)):sessionStorage.removeItem(Yh(r)))}catch{}}return{kind:`blocked`}}return g.current&&h.current===r&&(p(r),a({sessionId:r,text:f(`sending_could_not_be_confirmed_text_and_images_are_pres_65db5d72`)})),{kind:`unconfirmed`,operationId:0}}finally{m.current=!1,g.current&&s(null)}},cancel:async t=>{if(!e||m.current)return;let n=e;m.current=!0,s(n),a(null);try{await Jh.cancel(n,t),++_.current,g.current&&h.current===n&&r(e=>e?.sessionId===n?{...e,messages:e.messages.filter(e=>e.id!==t)}:e)}catch{g.current&&h.current===n&&a({sessionId:n,text:f(`could_not_withdraw_the_message_may_already_be_applying_f01042f1`)})}finally{m.current=!1,g.current&&s(null)}},pending:n?.sessionId===e?n.messages:[],error:i?.sessionId===e?i.text:null,busy:o!==null&&o===e,hasUnconfirmed:!!e&&(d===e||v.current.has(e)||!!Zh(e))}}var eg=e=>`lotus-next.ticket-decision.${encodeURIComponent(e)}.`,tg=(e,t)=>eg(e)+encodeURIComponent(t);function ng(e){let t={};for(let n of Object.keys(sessionStorage).filter(t=>t.startsWith(eg(e)))){let r=sessionStorage.getItem(n);if(!r||r.length>32768)throw Error(f(`ticket_request_receipts_could_not_be_verified_answer_4dfb4150`));let i=JSON.parse(r),a=e=>typeof e==`string`&&e.trim().length>0&&e.length<=512,o=e=>Number.isSafeInteger(e)&&e>=1;if(!i||typeof i!=`object`||Array.isArray(i)||!a(i.operation_id)||i.binding?.supervisor_session_id!==e||!a(i.binding?.scope_id)||!o(i.binding?.binding_revision)||!a(i.target?.request_id)||n!==tg(e,i.target.request_id)||!a(i.target?.work_id)||!(i.target?.assignment_id===null||a(i.target?.assignment_id))||!o(i.target?.generation)||!o(i.target?.contract_revision)||!o(i.target?.prompt_revision)||!Number.isSafeInteger(i.expected_seq)||i.expected_seq<0||!o(i.expected_epoch)||!(i.decision?.kind===`question`&&typeof i.decision.answer==`string`&&i.decision.answer.trim().length>0||i.decision?.kind===`approval`&&a(i.decision.fingerprint)&&typeof i.decision.approve==`boolean`))throw Error(f(`ticket_request_receipts_could_not_be_verified_answer_4dfb4150`));t[i.target.request_id]=i}return t}function rg(e,t){let n=JSON.stringify(t);if(n.length>32768)throw Error(f(`ticket_the_request_receipt_exceeds_the_storage_limit_34b4aced`));if(sessionStorage.setItem(tg(e,t.target.request_id),n),sessionStorage.getItem(tg(e,t.target.request_id))!==n)throw Error(f(`ticket_the_request_receipt_was_not_saved_nothing_was_bf0abec3`))}function ig(e,t){let n=tg(e,t.target.request_id);sessionStorage.getItem(n)===JSON.stringify(t)&&sessionStorage.removeItem(n)}var ag=new Set,og=new Set,sg=e=>(og.add(e),()=>{og.delete(e)}),cg=()=>{for(let e of og)e()};async function lg(e){let t=await Fn.respond(e);if(!t||t.operation_id!==e.operation_id||!Number.isSafeInteger(t.committed_seq)||t.committed_seq<=e.expected_seq)throw Error(f(`ticket_the_decision_receipt_is_not_confirmed_retry_t_42a54511`))}function ug(e,t=``,n=!1,r=!1){u();let i=(0,K.useContext)(Bn),[a,o]=(0,K.useState)({kind:`loading`}),[s,c]=(0,K.useState)(!1),l=(0,K.useSyncExternalStore)(sg,()=>!!e&&ag.has(e),()=>!1),[d,p]=(0,K.useState)(null),[m,h]=(0,K.useState)(-1),[g,_]=(0,K.useState)(null),[v,y]=(0,K.useState)(null),[b,x]=(0,K.useState)(null),[S,C]=(0,K.useState)(!1),w=(0,K.useRef)(!1),[T,E]=(0,K.useState)(null),[D,O]=(0,K.useState)({}),[k,A]=(0,K.useState)({}),j=(0,K.useRef)(null),M=(0,K.useRef)(e),N=(0,K.useRef)(i),P=(0,K.useRef)(0),F=(0,K.useRef)({key:t,blocked:n,deferRead:r}),I=(0,K.useRef)(new Set);(M.current!==e||N.current!==i||F.current.key!==t||F.current.blocked!==n||F.current.deferRead!==r)&&(P.current+=1),M.current=e,N.current=i,F.current={key:t,blocked:n,deferRead:r};let ee=(0,K.useRef)(async()=>{});(0,K.useEffect)(()=>{j.current=null,w.current=!1,_(null),C(!1),E(null),y(null),O({}),A({});let t=P.current;if(p(null),h(-1),x(null),o({kind:`loading`}),c(!1),I.current.clear(),ee.current=async()=>{},!e||!i){h(t),E(e??null),o({kind:i?`unbound`:`forbidden`});return}if(r)return;try{A(ng(e))}catch(e){x(Dt(e))}let n=new AbortController,a,s=!1,l=async(r=!0,i=!1)=>{if(!(s||n.signal.aborted||P.current!==t||ag.has(e)&&!i)){s=!0,c(!0);try{if(!r&&j.current)try{let r=await Fn.changes(j.current.current.snapshot.seq,n.signal);if(r.snapshot.seq===j.current.current.snapshot.seq&&r.snapshot.authority_epoch===j.current.current.snapshot.authority_epoch){let r=await Fn.scope(e,n.signal);if(n.signal.aborted||P.current!==t)return;if(!r){j.current=null,w.current=!0,_(null),C(!0),E(e),y(null),o({kind:`unbound`}),h(t);return}let i=j.current.current;if(r.binding.scope_id===i.scope.binding.scope_id&&r.binding.binding_revision===i.scope.binding.binding_revision&&r.overview.snapshot.commit===i.snapshot.commit&&r.overview.snapshot.seq===i.snapshot.seq&&r.overview.snapshot.authority_epoch===i.snapshot.authority_epoch){j.current={...j.current,current:{...i,scope:r}},w.current=!0,_(j.current),C(!0),E(e),y(null),o({kind:`ready`}),h(t);return}}}catch(e){if(!Ct(e)||![409,410].includes(e.status))throw e}let i=await Fn.load(e,n.signal);if(n.signal.aborted||P.current!==t)return;j.current=i?zn(j.current,i):null,A(ng(e)),w.current=!0,_(j.current),C(!0),E(e),y(null),o({kind:i?`ready`:`unbound`}),h(t)}catch(r){if(!n.signal.aborted&&P.current===t){h(t);let n=Pn(r);w.current=!1,C(!1),o(n),y(Dt(r)),(r instanceof Nn||n.kind===`forbidden`)&&(j.current=null,_(null)),r instanceof Nn&&E(e)}}finally{s=!1,!n.signal.aborted&&P.current===t&&c(!1)}}};ee.current=e=>l(!0,e);let u=async()=>{document.hidden||await l(!1),n.signal.aborted||(a=setTimeout(()=>void u(),2500))},d=()=>{l()};return window.addEventListener(`online`,d),window.addEventListener(`focus`,d),u(),()=>{n.abort(),clearTimeout(a),window.removeEventListener(`online`,d),window.removeEventListener(`focus`,d)}},[e,i,t,n,r]);let L=(0,K.useCallback)(async(t,a)=>{let o=e,s=P.current;if(m!==s||n||r||!i||!j.current||j.current.current.scope.binding.supervisor_session_id!==o||!w.current||!j.current.current.complete||!j.current.current.scope.mutation_enabled||j.current.current.scope.health!==`writable`||I.current.has(t.id))return!1;let c;try{c=ng(o)[t.id]}catch(e){return x(Dt(e)),!1}if(c&&JSON.stringify(c.decision)!==JSON.stringify(a))return x(f(`ticket_the_previous_send_is_not_confirmed_confirm_th_1c3020b9`)),!1;let l;try{l=c??Ln(j.current,t,a,crypto.randomUUID()),rg(o,l)}catch(e){return x(Dt(e)),!1}I.current.add(t.id),x(null),O(e=>({...e,[t.id]:!0}));try{try{await lg(l)}catch(e){if(c||a.kind!==`question`||!Ct(e)||e.status!==409||e.message!==`revision_conflict`||(await ee.current(),M.current!==o||P.current!==s||!j.current||!w.current||!j.current.current.complete||!j.current.current.scope.mutation_enabled||j.current.current.scope.health!==`writable`||j.current.current.scope.binding.supervisor_session_id!==o||j.current.current.scope.binding.scope_id!==l.binding.scope_id||j.current.current.scope.binding.binding_revision!==l.binding.binding_revision||j.current.current.snapshot.seq<=l.expected_seq))throw e;try{l=Ln(j.current,t,a,crypto.randomUUID())}catch{throw e}rg(o,l),await lg(l)}return ig(o,l),M.current!==o||P.current!==s?!1:(A(e=>{let n={...e};return delete n[t.id],n}),await ee.current(),!0)}catch(e){let n=!!c||!Ct(e)||e.status>=500;return n||ig(o,l),M.current!==o||P.current!==s||(n?(A(e=>({...e,[t.id]:l})),x(f(`ticket_the_send_outcome_is_not_confirmed_retrying_wi_25b2c47f`))):(A(e=>{let n={...e};return delete n[t.id],n}),x(e.message===`revision_conflict`?f(`ticket_work_has_changed_check_the_current_question_a_d216c46f`):Dt(e)),await ee.current())),!1}finally{M.current===o&&P.current===s&&(I.current.delete(t.id),O(e=>({...e,[t.id]:!1})))}},[e,i,m,n,r]),te=(0,K.useCallback)(async()=>{let t=a.initialization,c=P.current,l=e;if(!i||!l||n||r||m!==c||!t||s||ag.has(l))return!1;ag.add(l),cg(),p(null);let u=()=>M.current===l&&N.current&&P.current===c,d=!1,g;try{try{if(await Fn.initialize(t),!u())return!1;d=!0}catch(e){if(!u())return!1;if(Ct(e)&&[401,403].includes(e.status)){j.current=null,w.current=!1,_(null),C(!1);let t=In(e,l);return o(t??Pn(e)),h(c),y(null),p(t?.detail??Dt(e)),!1}let t=Rn(e);Ct(e)&&e.status===409&&t&&(g=Dt(e)),p(f(t===`scope_requires_recovery`?`supervisor_work_recovery_guidance`:t===`scope_binding_mismatch`?`supervisor_work_binding_guidance`:t===`ticket_mutation_disabled`?`supervisor_work_disabled_guidance`:t===`supervisor_mode_required`?`supervisor_work_mode_guidance`:t===`supervisor_identity_mismatch`?`supervisor_work_identity_guidance`:t===`scope_io_error`?`supervisor_work_storage_guidance`:t===`initialization_conflict`?`supervisor_work_initialization_conflict`:`supervisor_work_initialization_unconfirmed`)+` `+Dt(e))}if(!u()||(await ee.current(!0),!u()))return!1;let e=j.current?.current.scope.binding,n=w.current&&e?.supervisor_session_id===t.supervisor_session_id&&e.scope_id===`supervisor/`+t.incarnation_id&&e.binding_revision===t.binding_revision;return g&&w.current&&j.current&&p(f(`supervisor_work_initialization_conflict`)+` `+g),d&&!n&&p(f(`supervisor_work_initialization_unconfirmed`)),d&&n}finally{ag.delete(l),cg()}},[e,i,a,s,m,n,r]),R=m===P.current;return{state:i&&R&&g?.current.scope.binding.supervisor_session_id===e?g:null,availability:i?R?a:{kind:`loading`}:{kind:`forbidden`},refreshing:s,initializing:l,initializationError:R?d:null,canInitialize:i&&R&&!n&&!r&&!!a.initialization&&!l&&!s,initialize:te,canRefresh:i&&!!e&&!r&&!l,error:b??(d?d+(v?` `+v:``):v),connected:i&&R&&S,negotiated:!e||!i||R&&T===e,busy:D,uncertain:k,respond:L,refresh:()=>ee.current(),canSendIngress:i&&R&&!n&&!r&&S&&g!==null&&g.current.scope.binding.supervisor_session_id===e&&g.current.scope.health===`writable`&&g.current.scope.mutation_enabled===!0&&g.current.scope.capabilities?.semantic_messages_v1===!0,canRespond:i&&R&&!n&&!r&&S&&g!==null&&g.current.scope.binding.supervisor_session_id===e&&g.current.complete&&g.current.scope.health===`writable`&&g.current.scope.mutation_enabled===!0}}var dg=e=>`lotus-next.ticket-human.${e}`,fg=new Set,pg=new Set,mg=()=>{for(let e of pg)e()};function hg(e){let t=sessionStorage.getItem(dg(e));if(t===null)return;let n=JSON.parse(t);if(typeof n?.id!=`string`||n.id.length===0||n.id.length>128||typeof n.fingerprint!=`string`||!/^[a-f0-9]{64}$/.test(n.fingerprint)||n.fingerprint_version!==void 0&&n.fingerprint_version!==2||n.phase!==void 0&&n.phase!==`activation`||n.references!==void 0&&(typeof n.references!=`object`||n.references===null||Object.entries(n.references).some(([e,t])=>![`thread_id`,`in_reply_to`,`correlation_id`].includes(e)||typeof t!=`string`||t.length===0||t.length>128)))throw Error(f(`ticket_the_original_message_receipt_could_not_be_rea_0d475435`));return n}function gg(e){return Array.isArray(e)?e.map(gg):typeof e==`object`&&e?Object.fromEntries(Object.entries(e).sort(([e],[t])=>e<t?-1:+(e>t)).map(([e,t])=>[e,gg(t)])):e}function _g(e){u();let t=(0,K.useRef)(0),n=(0,K.useRef)({sessionId:e});n.current.sessionId!==e&&(n.current={sessionId:e});let[r,i]=(0,K.useState)(!1),[a,o]=(0,K.useState)(null),[s,c]=(0,K.useState)(null),l=(e,t)=>n.current===e&&e.sessionId===t,d=(e,t,n)=>{l(e,t)&&o(n)},p=e=>{if(n.current.sessionId===e)try{let t=hg(e)?.phase===`activation`;c(t?e:null),o(t?f(`ticket_message_saved_but_start_is_not_confirmed_you__c27c17c7`):null)}catch(e){o(Dt(e))}};(0,K.useEffect)(()=>{let e=()=>i(!!n.current.sessionId&&fg.has(n.current.sessionId));return pg.add(e),e(),()=>{pg.delete(e)}},[e]),(0,K.useEffect)(()=>{if(c(null),o(null),e)try{hg(e)?.phase===`activation`&&(c(e),o(f(`ticket_message_saved_but_start_is_not_confirmed_you__c27c17c7`)))}catch(e){o(Dt(e))}},[e]);let m=e=>{if(!e)return!1;try{return sessionStorage.getItem(dg(e))!==null}catch{return!1}},h=e=>{if(e)try{return hg(e)?.references}catch{return}},g=(e,t)=>{let n=hg(e);return n&&n.id!==t?!1:(n&&sessionStorage.removeItem(dg(e)),p(e),!0)},_=async(e,t,n)=>{if(wo(e))return p(e),d(n,e,f(`session_compatibility_execution_blocked`)),!1;if(dc(e)!==`clear`)return p(e),d(n,e,f(`ticket_message_saved_but_the_root_mode_change_is_not_12907d7e`)),!1;try{let n=await zt.execute(e);if(n.session_id!==e||![`started`,`already_running`,`completed`].includes(n.status))throw Error(f(`ticket_message_saved_the_run_has_not_started__383c6c1b`));if(!g(e,t.id))throw Error(f(`ticket_the_message_receipt_has_changed_refresh_and_c_5517657b`));return H.getState().loadChatHistory(e).catch(()=>{}),!0}catch(t){let r=Ao(e,t);return p(e),d(n,e,f(r?`session_compatibility_execution_blocked`:`ticket_message_saved_but_start_is_not_confirmed_you__c27c17c7`)),!1}};return{send:async e=>{let r=e.session_id;if(!r)return{kind:`blocked`};if(fg.has(r))return{kind:`busy`};if(dc(r)!==`clear`||wo(r))return{kind:`blocked`};let i=n.current,a=++t.current,o=!1,s;fg.add(r),mg(),d(i,r,null);try{let t=hg(r);if(o=!!t,t?.phase===`activation`)return p(r),d(i,r,f(`ticket_message_saved_confirm_the_start_first_to_avoi_d9f0157f`)),{kind:`blocked`};if(t?.references&&Object.entries(t.references).some(([t,n])=>e[t]!==void 0&&e[t]!==n))return d(i,r,f(`ticket_the_previous_message_is_not_confirmed_keep_th_18bb3408`)),{kind:`blocked`};let n=t?.references?{...e,...t.references}:e,c=new TextEncoder().encode(JSON.stringify(t&&t.fingerprint_version===void 0?n:gg(n))),l=Array.from(new Uint8Array(await crypto.subtle.digest(`SHA-256`,c)),e=>e.toString(16).padStart(2,`0`)).join(``);if(t&&t.fingerprint!==l)return d(i,r,f(`ticket_the_previous_message_is_not_confirmed_retry_w_26be7bc7`)),{kind:`blocked`};if(dc(r)!==`clear`||wo(r))return{kind:`blocked`};let u=t??{fingerprint:l,fingerprint_version:2,id:crypto.randomUUID(),references:{...e.thread_id?{thread_id:e.thread_id}:{},...e.in_reply_to?{in_reply_to:e.in_reply_to}:{},...e.correlation_id?{correlation_id:e.correlation_id}:{}}};s=u.id,sessionStorage.setItem(dg(r),JSON.stringify(u));let m=await Ot.postOnce(`chat`,{...n,message_id:u.id,correlation_id:n.correlation_id??u.id});if(m.session_id!==r||m.message_id!==u.id||!Number.isSafeInteger(m.ingress_seq)||(m.ingress_seq??0)<1)throw Error(f(`ticket_no_persistence_confirmation_was_received_for__9144eecb`));if(hg(r)?.id!==u.id)throw Error(f(`ticket_the_message_receipt_has_changed_refresh_and_c_5517657b`));let h={...u,phase:`activation`};return sessionStorage.setItem(dg(r),JSON.stringify(h)),p(r),await _(r,h,i),{kind:`accepted`,operationId:a,sessionId:r,navigated:!1}}catch(e){let t=Ao(r,e);if(!o&&s&&Ct(e)&&e.status>=400&&e.status<500)try{g(r,s)}catch{}return t?{kind:`blocked`}:(d(i,r,Dt(e)+f(`ticket__draft_preserved_retrying_will_use_the_same_m_0c9ddb59`)),{kind:`unconfirmed`,operationId:a})}finally{fg.delete(r),mg()}},busy:r,error:a,executePending:s,hasPending:m,references:h,retryExecute:async()=>{let e=s;if(!e||fg.has(e)||wo(e))return!1;let t=n.current;fg.add(e),mg();try{let n=hg(e);return n?.phase===`activation`?await _(e,n,t):(p(e),!1)}catch(n){return d(t,e,Dt(n)),!1}finally{fg.delete(e),mg()}}}}function vg({availability:e,refreshing:t,canRefresh:n,onRefresh:r,canInitialize:i=!1,initializing:a=!1,initializationError:o,onInitialize:s}){u();let c=e.kind,l={loading:`supervisor_work_loading`,ready:`supervisor_work_tab`,disabled:`supervisor_work_disabled`,uninitialized:`supervisor_work_uninitialized`,unbound:`supervisor_work_unbound`,unsupported:`supervisor_work_unsupported`,forbidden:`supervisor_work_forbidden`,error:`supervisor_work_error`},d={disabled:`supervisor_work_disabled_guidance`,uninitialized:`supervisor_work_uninitialized_guidance`,unbound:`supervisor_work_unbound_guidance`,unsupported:`supervisor_work_unsupported_guidance`,forbidden:`supervisor_work_forbidden_guidance`,error:`supervisor_work_error_guidance`},p={supervisor_mode_required:[`supervisor_work_mode_required`,`supervisor_work_mode_guidance`],supervisor_identity_mismatch:[`supervisor_work_identity_mismatch`,`supervisor_work_identity_guidance`],scope_binding_mismatch:[`supervisor_work_binding_mismatch`,`supervisor_work_binding_guidance`],scope_requires_recovery:[`supervisor_work_requires_recovery`,`supervisor_work_recovery_guidance`],scope_io_error:[`supervisor_work_storage_error`,`supervisor_work_storage_guidance`],scope_uninitialized:[`supervisor_work_uninitialized`,e.initialization?`supervisor_work_initialize_guidance`:`supervisor_work_uninitialized_waiting`]},m=e.reasonCode&&e.reasonCode in p?p[e.reasonCode]:void 0,h=!!e.initialization&&!!s;return(0,q.jsxs)(`section`,{"data-testid":`ticket-work-availability`,className:`space-y-3 p-4 text-sm`,children:[(0,q.jsx)(`p`,{role:c===`error`||c===`forbidden`?`alert`:`status`,className:`font-medium`,children:f(m?.[0]??l[c])}),c!==`loading`&&c!==`ready`?(0,q.jsx)(`p`,{className:`text-muted-foreground`,children:f(m?.[1]??d[c])}):null,o?(0,q.jsx)(`p`,{role:`alert`,className:`text-destructive`,children:o}):null,h?(0,q.jsx)(`button`,{type:`button`,disabled:!i||a||t,onClick:s,className:`rounded-md border px-3 py-1.5 disabled:opacity-50`,children:f(a?`supervisor_work_initializing`:`supervisor_work_initialize`)}):null,e.detail?(0,q.jsxs)(`details`,{className:`text-xs text-muted-foreground`,children:[(0,q.jsx)(`summary`,{className:`cursor-pointer`,children:f(`supervisor_work_service_detail`)}),(0,q.jsx)(`p`,{className:`mt-2 whitespace-pre-wrap break-words`,children:e.detail})]}):null,c===`loading`?null:(0,q.jsx)(`button`,{type:`button`,disabled:t||a||!n,onClick:r,className:`rounded-md border px-3 py-1.5 disabled:opacity-50`,children:f(t?`supervisor_work_loading`:`supervisor_work_retry`)})]})}var yg=()=>o(()=>import(`./TicketWorkPanel-CoPV3q8A.js`),__vite__mapDeps([76,1,2,3,4,77,7,8,53]),import.meta.url),bg=e=>(0,K.lazy)(async()=>({default:(await e()).TicketWorkPanel}));function xg({loadPanel:e=yg,...t}){u();let[n,r]=(0,K.useState)(()=>bg(e));return(0,q.jsx)(ue,{name:`Work`,fallback:(t,n)=>(0,q.jsxs)(`div`,{role:`alert`,className:`p-4 text-sm`,children:[(0,q.jsx)(`p`,{children:f(`work_load_failed`)}),(0,q.jsx)(`button`,{type:`button`,className:`mt-2 underline`,onClick:()=>{r(bg(e)),n()},children:f(`retry_b8784c8d`)})]}),children:(0,q.jsx)(K.Suspense,{fallback:(0,q.jsx)(`div`,{role:`status`,"aria-live":`polite`,className:`p-4 text-sm text-muted-foreground`,"data-testid":`ticket-work-loading`,children:f(`loading_4927a53b`)}),children:(0,q.jsx)(n,{...t})})})}function Sg({controller:e,running:t,onSelectWork:n}){let r=s(),[i,a]=(0,K.useState)(!1),o=(0,K.useRef)(!1),c=e.state;if(!c||!n)return null;let l=c.current.scope.overview.data,u=l.open_questions+l.open_approvals+l.needs_acceptance,d=Object.values(c.works).filter(e=>e.ticket.kind===`work`&&!e.ticket.archived).sort((e,t)=>t.ticket.updated_seq-e.ticket.updated_seq),f=d.flatMap(e=>e.submissions.filter(t=>!t.stale&&(t.id===e.ticket.accepted_submission||t.id===e.ticket.current_submission)).flatMap(t=>t.artifacts.map((n,r)=>({work:e.ticket,artifact:n,submissionId:t.id,number:r+1})))),p=e=>{o.current=!0,a(!1),n(e)};return(0,q.jsxs)(ee,{open:i,onOpenChange:e=>{e&&(o.current=!1),a(e)},children:[(0,q.jsx)(F,{asChild:!0,children:(0,q.jsxs)(W,{type:`button`,size:`icon`,variant:`ghost`,className:`relative shrink-0`,"data-testid":`ticket-work-status`,"aria-label":r(`supervisor_overview_open`)+` · `+r(`ticket_work_count`,{count:l.work_count})+` · `+r(`supervisor_work_attention`,{count:u}),children:[(0,q.jsx)(lr,{"aria-hidden":`true`}),(0,q.jsxs)(`span`,{className:`sr-only`,children:[r(`ticket_work_count`,{count:l.work_count}),` · `,r(`supervisor_work_attention`,{count:u})]}),u>0?(0,q.jsx)(`span`,{"aria-hidden":`true`,style:{right:-4,top:-4,minWidth:16},className:`absolute rounded-full bg-primary px-1 text-xs leading-4 text-primary-foreground`,children:u>99?`99+`:u}):null]})}),(0,q.jsxs)(I,{align:`end`,side:`bottom`,sideOffset:10,collisionPadding:12,"aria-label":r(`supervisor_overview_open`),"data-testid":`supervisor-overview`,style:{maxHeight:`min(32rem, var(--radix-popover-content-available-height))`,width:`min(22rem, calc(100vw - 1.5rem))`},className:`overflow-y-auto rounded-2xl p-4 shadow-lg`,onCloseAutoFocus:e=>{o.current&&=(e.preventDefault(),!1)},children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,q.jsx)(`div`,{className:`flex size-10 shrink-0 items-center justify-center rounded-2xl bg-primary/10 text-primary`,children:(0,q.jsx)(lr,{className:`size-6`,"aria-hidden":`true`})}),(0,q.jsxs)(`div`,{className:`min-w-0`,children:[(0,q.jsx)(`strong`,{className:`text-sm`,children:`Supervisor`}),(0,q.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e.connected?e.error?r(`supervisor_work_status_attention`):t||(l.states.active??0)>0?r(`supervisor_overview_running`):r(`supervisor_overview_idle`):r(`supervisor_work_connection_attention`)})]})]}),(0,q.jsxs)(`div`,{className:`mt-3 flex flex-wrap gap-2 text-xs text-muted-foreground`,children:[(0,q.jsx)(`span`,{children:r(`ticket_work_count`,{count:l.work_count})}),u>0?(0,q.jsx)(`span`,{className:`rounded-full bg-primary/10 px-2 text-primary`,children:r(`supervisor_work_attention`,{count:u})}):null]}),c.current.complete?null:(0,q.jsx)(`p`,{role:`status`,className:`mt-2 text-xs text-muted-foreground`,children:r(`ticket_only_some_work_is_shown_other_work_may_still__ee267ea7`)}),e.connected?null:(0,q.jsx)(`p`,{role:`status`,className:`mt-2 text-xs text-muted-foreground`,children:r(`ticket_the_connection_is_not_confirmed_answers_and_a_aaac8c0d`)}),e.error?(0,q.jsx)(`p`,{role:`alert`,className:`mt-2 break-words text-xs text-destructive`,children:r(`supervisor_work_status_attention`)}):null,(0,q.jsx)(`h2`,{className:`mb-1 mt-5 text-xs font-medium text-muted-foreground`,children:r(`supervisor_overview_recent`)}),d.length?d.slice(0,5).map(({ticket:e})=>(0,q.jsxs)(`button`,{type:`button`,onClick:()=>p(e.id),className:`flex w-full items-center gap-2 rounded-lg px-2 py-2 text-left text-sm hover:bg-muted focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring`,children:[(0,q.jsx)(Nr,{className:`size-4 shrink-0 text-muted-foreground`,"aria-hidden":`true`}),(0,q.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,title:e.contract.title,children:e.contract.title}),(0,q.jsx)(`span`,{className:`shrink-0 text-xs text-muted-foreground`,children:Vn[e.state]})]},e.id)):(0,q.jsx)(`p`,{className:`px-2 py-2 text-xs text-muted-foreground`,children:r(c.current.complete&&e.connected?`supervisor_overview_empty`:`supervisor_overview_pending`)}),(0,q.jsx)(`h2`,{className:`mb-1 mt-4 text-xs font-medium text-muted-foreground`,children:r(`supervisor_overview_outputs`)}),f.length?f.slice(0,3).map(({work:e,artifact:t,submissionId:n,number:i})=>(0,q.jsxs)(`button`,{type:`button`,onClick:()=>p(e.id),className:`flex w-full items-center gap-2 rounded-lg px-2 py-2 text-left text-sm hover:bg-muted focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring`,children:[(0,q.jsx)(x,{className:`size-4 shrink-0 text-muted-foreground`,"aria-hidden":`true`}),(0,q.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,title:e.contract.title,children:e.contract.title}),(0,q.jsx)(`span`,{className:`shrink-0 text-xs text-muted-foreground`,children:r(`ticket_artifact_label`,{number:i})})]},e.id+n+t.sha256+i)):(0,q.jsx)(`p`,{className:`px-2 py-2 text-xs text-muted-foreground`,children:r(c.current.complete&&e.connected?`supervisor_overview_no_outputs`:`supervisor_overview_pending`)}),(0,q.jsxs)(`button`,{type:`button`,onClick:()=>p(null),className:`mt-4 flex w-full items-center justify-center gap-2 rounded-xl border px-3 py-2 text-sm hover:bg-muted focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring`,children:[r(`supervisor_overview_all`),(0,q.jsx)(ve,{className:`size-4`,"aria-hidden":`true`})]})]})]})}function Cg({sessionId:e,messages:t,busy:n,onCancel:r,onPreview:i}){return u(),t.length?(0,q.jsxs)(`details`,{"aria-label":f(`message_queue_9dc5a845`),className:`group mx-auto mb-2 w-full max-w-6xl rounded-lg border bg-card text-xs`,children:[(0,q.jsxs)(`summary`,{"aria-label":f(`queued_messages_daa57141`,{v0:t.length,count:t.length}),className:`cursor-pointer whitespace-nowrap rounded px-3 py-2 tabular-nums text-muted-foreground hover:bg-accent`,children:[f(`queued_f9e719c6`),` `,t.length]}),(0,q.jsx)(`div`,{className:`max-h-[min(12rem,25dvh)] overflow-y-auto overscroll-contain border-t px-3 py-1`,children:t.map(t=>(0,q.jsxs)(`div`,{className:`flex items-start gap-2 border-b py-2 last:border-0`,children:[(0,q.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,q.jsx)(`div`,{className:`mb-1 whitespace-pre-wrap break-words text-muted-foreground`,children:t.mode===`after_run`?f(`message_queue_after_run`):f(`message_queue_interject`)}),t.text&&(0,q.jsx)(`div`,{className:`whitespace-pre-wrap break-words [overflow-wrap:anywhere]`,children:t.text}),!!t.images?.length&&(0,q.jsx)(`div`,{className:`mt-1 flex flex-wrap gap-1`,children:t.images.map((t,n)=>{let r=Jh.imageUrl(e,t);return(0,q.jsx)(`button`,{onClick:()=>i(r),"aria-label":f(`view_queued_image_81c3b7ba`,{v0:n+1}),children:(0,q.jsx)(`img`,{src:r,alt:f(`queued_image_009dcc09`,{v0:n+1}),className:`size-12 rounded border object-cover`})},`${t}-${n}`)})})]}),(0,q.jsx)(W,{className:`shrink-0`,size:`sm`,variant:`ghost`,disabled:n,onClick:()=>r(t.id),children:f(`withdraw_6b581989`)})]},t.id))})]}):null}var wg=Object.defineProperty,Tg=(e,t)=>{let n={};for(var r in e)wg(n,r,{get:e[r],enumerable:!0});return t||wg(n,Symbol.toStringTag,{value:`Module`}),n};function Eg(e){this.content=e}Eg.prototype={constructor:Eg,find:function(e){for(var t=0;t<this.content.length;t+=2)if(this.content[t]===e)return t;return-1},get:function(e){var t=this.find(e);return t==-1?void 0:this.content[t+1]},update:function(e,t,n){var r=n&&n!=e?this.remove(n):this,i=r.find(e),a=r.content.slice();return i==-1?a.push(n||e,t):(a[i+1]=t,n&&(a[i]=n)),new Eg(a)},remove:function(e){var t=this.find(e);if(t==-1)return this;var n=this.content.slice();return n.splice(t,2),new Eg(n)},addToStart:function(e,t){return new Eg([e,t].concat(this.remove(e).content))},addToEnd:function(e,t){var n=this.remove(e).content.slice();return n.push(e,t),new Eg(n)},addBefore:function(e,t,n){var r=this.remove(t),i=r.content.slice(),a=r.find(e);return i.splice(a==-1?i.length:a,0,t,n),new Eg(i)},forEach:function(e){for(var t=0;t<this.content.length;t+=2)e(this.content[t],this.content[t+1])},prepend:function(e){return e=Eg.from(e),e.size?new Eg(e.content.concat(this.subtract(e).content)):this},append:function(e){return e=Eg.from(e),e.size?new Eg(this.subtract(e).content.concat(e.content)):this},subtract:function(e){var t=this;e=Eg.from(e);for(var n=0;n<e.content.length;n+=2)t=t.remove(e.content[n]);return t},toObject:function(){var e={};return this.forEach(function(t,n){e[t]=n}),e},get size(){return this.content.length>>1}},Eg.from=function(e){if(e instanceof Eg)return e;var t=[];if(e)for(var n in e)t.push(n,e[n]);return new Eg(t)};function Dg(e,t,n){for(let r=0;;r++){if(r==e.childCount||r==t.childCount)return e.childCount==t.childCount?null:n;let i=e.child(r),a=t.child(r);if(i==a){n+=i.nodeSize;continue}if(!i.sameMarkup(a))return n;if(i.isText&&i.text!=a.text){let e=i.text,t=a.text,r=0;for(;e[r]==t[r];r++)n++;return r&&r<e.length&&r<t.length&&Ag(e.charCodeAt(r-1))&&kg(e.charCodeAt(r))&&n--,n}if(i.content.size||a.content.size){let e=Dg(i.content,a.content,n+1);if(e!=null)return e}n+=i.nodeSize}}function Og(e,t,n,r){for(let i=e.childCount,a=t.childCount;;){if(i==0||a==0)return i==a?null:{a:n,b:r};let o=e.child(--i),s=t.child(--a),c=o.nodeSize;if(o==s){n-=c,r-=c;continue}if(!o.sameMarkup(s))return{a:n,b:r};if(o.isText&&o.text!=s.text){let e=o.text,t=s.text,i=e.length,a=t.length;for(;i>0&&a>0&&e[i-1]==t[a-1];)i--,a--,n--,r--;return i&&a&&i<e.length&&Ag(e.charCodeAt(i-1))&&kg(e.charCodeAt(i))&&(n++,r++),{a:n,b:r}}if(o.content.size||s.content.size){let e=Og(o.content,s.content,n-1,r-1);if(e)return e}n-=c,r-=c}}function kg(e){return e>=56320&&e<57344}function Ag(e){return e>=55296&&e<56320}var J=class e{constructor(e,t){if(this.content=e,this.size=t||0,t==null)for(let t=0;t<e.length;t++)this.size+=e[t].nodeSize}nodesBetween(e,t,n,r=0,i){for(let a=0,o=0;o<t;a++){let s=this.content[a],c=o+s.nodeSize;if(c>e&&n(s,r+o,i||null,a)!==!1&&s.content.size){let i=o+1;s.nodesBetween(Math.max(0,e-i),Math.min(s.content.size,t-i),n,r+i)}o=c}}descendants(e){this.nodesBetween(0,this.size,e)}textBetween(e,t,n,r){let i=``,a=!0;return this.nodesBetween(e,t,(o,s)=>{let c=o.isText?o.text.slice(Math.max(e,s)-s,t-s):o.isLeaf?r?typeof r==`function`?r(o):r:o.type.spec.leafText?o.type.spec.leafText(o):``:``;o.isBlock&&(o.isLeaf&&c||o.isTextblock)&&n&&(a?a=!1:i+=n),i+=c},0),i}append(t){if(!t.size)return this;if(!this.size)return t;let n=this.lastChild,r=t.firstChild,i=this.content.slice(),a=0;for(n.isText&&n.sameMarkup(r)&&(i[i.length-1]=n.withText(n.text+r.text),a=1);a<t.content.length;a++)i.push(t.content[a]);return new e(i,this.size+t.size)}cut(t,n=this.size){if(t==0&&n==this.size)return this;let r=[],i=0;if(n>t)for(let e=0,a=0;a<n;e++){let o=this.content[e],s=a+o.nodeSize;s>t&&((a<t||s>n)&&(o=o.isText?o.cut(Math.max(0,t-a),Math.min(o.text.length,n-a)):o.cut(Math.max(0,t-a-1),Math.min(o.content.size,n-a-1))),r.push(o),i+=o.nodeSize),a=s}return new e(r,i)}cutByIndex(t,n){return t==n?e.empty:t==0&&n==this.content.length?this:new e(this.content.slice(t,n))}replaceChild(t,n){let r=this.content[t];if(r==n)return this;let i=this.content.slice(),a=this.size+n.nodeSize-r.nodeSize;return i[t]=n,new e(i,a)}addToStart(t){return new e([t].concat(this.content),this.size+t.nodeSize)}addToEnd(t){return new e(this.content.concat(t),this.size+t.nodeSize)}eq(e){if(this.content.length!=e.content.length)return!1;for(let t=0;t<this.content.length;t++)if(!this.content[t].eq(e.content[t]))return!1;return!0}get firstChild(){return this.content.length?this.content[0]:null}get lastChild(){return this.content.length?this.content[this.content.length-1]:null}get childCount(){return this.content.length}child(e){let t=this.content[e];if(!t)throw RangeError(`Index `+e+` out of range for `+this);return t}maybeChild(e){return this.content[e]||null}forEach(e){for(let t=0,n=0;t<this.content.length;t++){let r=this.content[t];e(r,n,t),n+=r.nodeSize}}findDiffStart(e,t=0){return Dg(this,e,t)}findDiffEnd(e,t=this.size,n=e.size){return Og(this,e,t,n)}findIndex(e){if(e==0)return Mg(0,e);if(e==this.size)return Mg(this.content.length,e);if(e>this.size||e<0)throw RangeError(`Position ${e} outside of fragment (${this})`);for(let t=0,n=0;;t++){let r=this.child(t),i=n+r.nodeSize;if(i>=e)return i==e?Mg(t+1,i):Mg(t,n);n=i}}toString(){return`<`+this.toStringInner()+`>`}toStringInner(){return this.content.join(`, `)}toJSON(){return this.content.length?this.content.map(e=>e.toJSON()):null}static fromJSON(t,n){if(!n)return e.empty;if(!Array.isArray(n))throw RangeError(`Invalid input for Fragment.fromJSON`);return e.fromArray(n.map(t.nodeFromJSON))}static fromArray(t){if(!t.length)return e.empty;let n,r=0;for(let e=0;e<t.length;e++){let i=t[e];r+=i.nodeSize,e&&i.isText&&t[e-1].sameMarkup(i)?(n||=t.slice(0,e),n[n.length-1]=i.withText(n[n.length-1].text+i.text)):n&&n.push(i)}return new e(n||t,r)}static from(t){if(!t)return e.empty;if(t instanceof e)return t;if(Array.isArray(t))return this.fromArray(t);if(t.attrs)return new e([t],t.nodeSize);throw RangeError(`Can not convert `+t+` to a Fragment`+(t.nodesBetween?` (looks like multiple versions of prosemirror-model were loaded)`:``))}};J.empty=new J([],0);var jg={index:0,offset:0};function Mg(e,t){return jg.index=e,jg.offset=t,jg}function Ng(e,t){if(e===t)return!0;if(!(e&&typeof e==`object`)||!(t&&typeof t==`object`))return!1;let n=Array.isArray(e);if(Array.isArray(t)!=n)return!1;if(n){if(e.length!=t.length)return!1;for(let n=0;n<e.length;n++)if(!Ng(e[n],t[n]))return!1}else{for(let n in e)if(!(n in t)||!Ng(e[n],t[n]))return!1;for(let n in t)if(!(n in e))return!1}return!0}var Pg=class e{constructor(e,t){this.type=e,this.attrs=t}addToSet(e){let t,n=!1;for(let r=0;r<e.length;r++){let i=e[r];if(this.eq(i))return e;if(this.type.excludes(i.type))t||=e.slice(0,r);else if(i.type.excludes(this.type))return e;else!n&&i.type.rank>this.type.rank&&(t||=e.slice(0,r),t.push(this),n=!0),t&&t.push(i)}return t||=e.slice(),n||t.push(this),t}removeFromSet(e){for(let t=0;t<e.length;t++)if(this.eq(e[t]))return e.slice(0,t).concat(e.slice(t+1));return e}isInSet(e){for(let t=0;t<e.length;t++)if(this.eq(e[t]))return!0;return!1}eq(e){return this==e||this.type==e.type&&Ng(this.attrs,e.attrs)}toJSON(){let e={type:this.type.name};for(let t in this.attrs){e.attrs=this.attrs;break}return e}static fromJSON(e,t){if(!t)throw RangeError(`Invalid input for Mark.fromJSON`);let n=e.marks[t.type];if(!n)throw RangeError(`There is no mark type ${t.type} in this schema`);return n.create(t.attrs)}static sameSet(e,t){if(e==t)return!0;if(e.length!=t.length)return!1;for(let n=0;n<e.length;n++)if(!e[n].eq(t[n]))return!1;return!0}static setFrom(t){if(!t||Array.isArray(t)&&t.length==0)return e.none;if(t instanceof e)return[t];let n=t.slice();return n.sort((e,t)=>e.type.rank-t.type.rank),n}};Pg.none=[];var Fg=class extends Error{},Y=class e{constructor(e,t,n){this.content=e,this.openStart=t,this.openEnd=n}get size(){return this.content.size-this.openStart-this.openEnd}insertAt(t,n){let r=Lg(this.content,t+this.openStart,n,this.openStart+1,this.openEnd+1);return r&&new e(r,this.openStart,this.openEnd)}removeBetween(t,n){return new e(Ig(this.content,t+this.openStart,n+this.openStart),this.openStart,this.openEnd)}eq(e){return this.content.eq(e.content)&&this.openStart==e.openStart&&this.openEnd==e.openEnd}toString(){return this.content+`(`+this.openStart+`,`+this.openEnd+`)`}toJSON(){if(!this.content.size)return null;let e={content:this.content.toJSON()};return this.openStart>0&&(e.openStart=this.openStart),this.openEnd>0&&(e.openEnd=this.openEnd),e}static fromJSON(t,n){if(!n)return e.empty;let r=n.openStart||0,i=n.openEnd||0;if(typeof r!=`number`||typeof i!=`number`)throw RangeError(`Invalid input for Slice.fromJSON`);return new e(J.fromJSON(t,n.content),r,i)}static maxOpen(t,n=!0){let r=0,i=0;for(let e=t.firstChild;e&&!e.isLeaf&&(n||!e.type.spec.isolating);e=e.firstChild)r++;for(let e=t.lastChild;e&&!e.isLeaf&&(n||!e.type.spec.isolating);e=e.lastChild)i++;return new e(t,r,i)}};Y.empty=new Y(J.empty,0,0);function Ig(e,t,n){let{index:r,offset:i}=e.findIndex(t),a=e.maybeChild(r),{index:o,offset:s}=e.findIndex(n);if(i==t||a.isText){if(s!=n&&!e.child(o).isText)throw RangeError(`Removing non-flat range`);return e.cut(0,t).append(e.cut(n))}if(r!=o)throw RangeError(`Removing non-flat range`);return e.replaceChild(r,a.copy(Ig(a.content,t-i-1,n-i-1)))}function Lg(e,t,n,r,i,a){let{index:o,offset:s}=e.findIndex(t),c=e.maybeChild(o);if(s==t||c.isText)return a&&r<=0&&i<=0&&!a.canReplace(o,o,n)?null:e.cut(0,t).append(n).append(e.cut(t));let l=Lg(c.content,t-s-1,n,o==0?r-1:0,o==e.childCount-1?i-1:0,c);return l&&e.replaceChild(o,c.copy(l))}function Rg(e,t,n){if(n.openStart>e.depth)throw new Fg(`Inserted content deeper than insertion position`);if(e.depth-n.openStart!=t.depth-n.openEnd)throw new Fg(`Inconsistent open depths`);return zg(e,t,n,0)}function zg(e,t,n,r){let i=e.index(r),a=e.node(r);if(i==t.index(r)&&r<e.depth-n.openStart){let o=zg(e,t,n,r+1);return a.copy(a.content.replaceChild(i,o))}else if(!n.content.size)return Wg(a,Kg(e,t,r));else if(!n.openStart&&!n.openEnd&&e.depth==r&&t.depth==r){let r=e.parent,i=r.content;return Wg(r,i.cut(0,e.parentOffset).append(n.content).append(i.cut(t.parentOffset)))}else{let{start:i,end:o}=qg(n,e);return Wg(a,Gg(e,i,o,t,r))}}function Bg(e,t){if(!t.type.compatibleContent(e.type))throw new Fg(`Cannot join `+t.type.name+` onto `+e.type.name)}function Vg(e,t,n){let r=e.node(n);return Bg(r,t.node(n)),r}function Hg(e,t){let n=t.length-1;n>=0&&e.isText&&e.sameMarkup(t[n])?t[n]=e.withText(t[n].text+e.text):t.push(e)}function Ug(e,t,n,r){let i=(t||e).node(n),a=0,o=t?t.index(n):i.childCount;e&&(a=e.index(n),e.depth>n?a++:e.textOffset&&(Hg(e.nodeAfter,r),a++));for(let e=a;e<o;e++)Hg(i.child(e),r);t&&t.depth==n&&t.textOffset&&Hg(t.nodeBefore,r)}function Wg(e,t){if(!e.type.validContent(t))throw new Fg(`Invalid content for node `+e.type.name);return e.copy(t)}function Gg(e,t,n,r,i){let a=e.depth>i&&Vg(e,t,i+1),o=r.depth>i&&Vg(n,r,i+1),s=[];return Ug(null,e,i,s),a&&o&&t.index(i)==n.index(i)?(Bg(a,o),Hg(Wg(a,Gg(e,t,n,r,i+1)),s)):(a&&Hg(Wg(a,Kg(e,t,i+1)),s),Ug(t,n,i,s),o&&Hg(Wg(o,Kg(n,r,i+1)),s)),Ug(r,null,i,s),new J(s)}function Kg(e,t,n){let r=[];return Ug(null,e,n,r),e.depth>n&&Hg(Wg(Vg(e,t,n+1),Kg(e,t,n+1)),r),Ug(t,null,n,r),new J(r)}function qg(e,t){let n=t.depth-e.openStart,r=t.node(n).copy(e.content);for(let e=n-1;e>=0;e--)r=t.node(e).copy(J.from(r));return{start:r.resolveNoCache(e.openStart+n),end:r.resolveNoCache(r.content.size-e.openEnd-n)}}var Jg=class e{constructor(e,t,n){this.pos=e,this.path=t,this.parentOffset=n,this.depth=t.length/3-1}resolveDepth(e){return e==null?this.depth:e<0?this.depth+e:e}get parent(){return this.node(this.depth)}get doc(){return this.node(0)}node(e){return this.path[this.resolveDepth(e)*3]}index(e){return this.path[this.resolveDepth(e)*3+1]}indexAfter(e){return e=this.resolveDepth(e),this.index(e)+(e==this.depth&&!this.textOffset?0:1)}start(e){return e=this.resolveDepth(e),e==0?0:this.path[e*3-1]+1}end(e){return e=this.resolveDepth(e),this.start(e)+this.node(e).content.size}before(e){if(e=this.resolveDepth(e),!e)throw RangeError(`There is no position before the top-level node`);return e==this.depth+1?this.pos:this.path[e*3-1]}after(e){if(e=this.resolveDepth(e),!e)throw RangeError(`There is no position after the top-level node`);return e==this.depth+1?this.pos:this.path[e*3-1]+this.path[e*3].nodeSize}get textOffset(){return this.pos-this.path[this.path.length-1]}get nodeAfter(){let e=this.parent,t=this.index(this.depth);if(t==e.childCount)return null;let n=this.pos-this.path[this.path.length-1],r=e.child(t);return n?e.child(t).cut(n):r}get nodeBefore(){let e=this.index(this.depth),t=this.pos-this.path[this.path.length-1];return t?this.parent.child(e).cut(0,t):e==0?null:this.parent.child(e-1)}posAtIndex(e,t){t=this.resolveDepth(t);let n=this.path[t*3],r=t==0?0:this.path[t*3-1]+1;for(let t=0;t<e;t++)r+=n.child(t).nodeSize;return r}marks(){let e=this.parent,t=this.index();if(e.content.size==0)return Pg.none;if(this.textOffset)return e.child(t).marks;let n=e.maybeChild(t-1),r=e.maybeChild(t);if(!n){let e=n;n=r,r=e}let i=n.marks;for(var a=0;a<i.length;a++)i[a].type.spec.inclusive===!1&&(!r||!i[a].isInSet(r.marks))&&(i=i[a--].removeFromSet(i));return i}marksAcross(e){let t=this.parent.maybeChild(this.index());if(!t||!t.isInline)return null;let n=t.marks,r=e.parent.maybeChild(e.index());for(var i=0;i<n.length;i++)n[i].type.spec.inclusive===!1&&(!r||!n[i].isInSet(r.marks))&&(n=n[i--].removeFromSet(n));return n}sharedDepth(e){for(let t=this.depth;t>0;t--)if(this.start(t)<=e&&this.end(t)>=e)return t;return 0}blockRange(e=this,t){if(e.pos<this.pos)return e.blockRange(this);for(let n=this.depth-(this.parent.inlineContent||this.pos==e.pos?1:0);n>=0;n--)if(e.pos<=this.end(n)&&(!t||t(this.node(n))))return new Qg(this,e,n);return null}sameParent(e){return this.pos-this.parentOffset==e.pos-e.parentOffset}max(e){return e.pos>this.pos?e:this}min(e){return e.pos<this.pos?e:this}toString(){let e=``;for(let t=1;t<=this.depth;t++)e+=(e?`/`:``)+this.node(t).type.name+`_`+this.index(t-1);return e+`:`+this.parentOffset}static resolve(t,n){if(!(n>=0&&n<=t.content.size))throw RangeError(`Position `+n+` out of range`);let r=[],i=0,a=n;for(let e=t;;){let{index:t,offset:n}=e.content.findIndex(a),o=a-n;if(r.push(e,t,i+n),!o||(e=e.child(t),e.isText))break;a=o-1,i+=n+1}return new e(n,r,a)}static resolveCached(t,n){let r=Zg.get(t);if(r)for(let e=0;e<r.elts.length;e++){let t=r.elts[e];if(t.pos==n)return t}else Zg.set(t,r=new Yg);let i=r.elts[r.i]=e.resolve(t,n);return r.i=(r.i+1)%Xg,i}},Yg=class{constructor(){this.elts=[],this.i=0}},Xg=12,Zg=new WeakMap,Qg=class{constructor(e,t,n){this.$from=e,this.$to=t,this.depth=n}get start(){return this.$from.before(this.depth+1)}get end(){return this.$to.after(this.depth+1)}get parent(){return this.$from.node(this.depth)}get startIndex(){return this.$from.index(this.depth)}get endIndex(){return this.$to.indexAfter(this.depth)}},$g=Object.create(null),e_=class e{constructor(e,t,n,r=Pg.none){this.type=e,this.attrs=t,this.marks=r,this.content=n||J.empty}get children(){return this.content.content}get nodeSize(){return this.isLeaf?1:2+this.content.size}get childCount(){return this.content.childCount}child(e){return this.content.child(e)}maybeChild(e){return this.content.maybeChild(e)}forEach(e){this.content.forEach(e)}nodesBetween(e,t,n,r=0){this.content.nodesBetween(e,t,n,r,this)}descendants(e){this.nodesBetween(0,this.content.size,e)}get textContent(){return this.isLeaf&&this.type.spec.leafText?this.type.spec.leafText(this):this.textBetween(0,this.content.size,``)}textBetween(e,t,n,r){return this.content.textBetween(e,t,n,r)}get firstChild(){return this.content.firstChild}get lastChild(){return this.content.lastChild}eq(e){return this==e||this.sameMarkup(e)&&this.content.eq(e.content)}sameMarkup(e){return this.hasMarkup(e.type,e.attrs,e.marks)}hasMarkup(e,t,n){return this.type==e&&Ng(this.attrs,t||e.defaultAttrs||$g)&&Pg.sameSet(this.marks,n||Pg.none)}copy(t=null){return t==this.content?this:new e(this.type,this.attrs,t,this.marks)}mark(t){return t==this.marks?this:new e(this.type,this.attrs,this.content,t)}cut(e,t=this.content.size){return e==0&&t==this.content.size?this:this.copy(this.content.cut(e,t))}slice(e,t=this.content.size,n=!1){if(e==t)return Y.empty;let r=this.resolve(e),i=this.resolve(t),a=n?0:r.sharedDepth(t),o=r.start(a);return new Y(r.node(a).content.cut(r.pos-o,i.pos-o),r.depth-a,i.depth-a)}replace(e,t,n){return Rg(this.resolve(e),this.resolve(t),n)}nodeAt(e){for(let t=this;;){let{index:n,offset:r}=t.content.findIndex(e);if(t=t.maybeChild(n),!t)return null;if(r==e||t.isText)return t;e-=r+1}}childAfter(e){let{index:t,offset:n}=this.content.findIndex(e);return{node:this.content.maybeChild(t),index:t,offset:n}}childBefore(e){if(e==0)return{node:null,index:0,offset:0};let{index:t,offset:n}=this.content.findIndex(e);if(n<e)return{node:this.content.child(t),index:t,offset:n};let r=this.content.child(t-1);return{node:r,index:t-1,offset:n-r.nodeSize}}resolve(e){return Jg.resolveCached(this,e)}resolveNoCache(e){return Jg.resolve(this,e)}rangeHasMark(e,t,n){let r=!1;return t>e&&this.nodesBetween(e,t,e=>(n.isInSet(e.marks)&&(r=!0),!r)),r}get isBlock(){return this.type.isBlock}get isTextblock(){return this.type.isTextblock}get inlineContent(){return this.type.inlineContent}get isInline(){return this.type.isInline}get isText(){return this.type.isText}get isLeaf(){return this.type.isLeaf}get isAtom(){return this.type.isAtom}toString(){if(this.type.spec.toDebugString)return this.type.spec.toDebugString(this);let e=this.type.name;return this.content.size&&(e+=`(`+this.content.toStringInner()+`)`),n_(this.marks,e)}contentMatchAt(e){let t=this.type.contentMatch.matchFragment(this.content,0,e);if(!t)throw Error(`Called contentMatchAt on a node with invalid content`);return t}canReplace(e,t,n=J.empty,r=0,i=n.childCount){let a=this.contentMatchAt(e).matchFragment(n,r,i),o=a&&a.matchFragment(this.content,t);if(!o||!o.validEnd)return!1;for(let e=r;e<i;e++)if(!this.type.allowsMarks(n.child(e).marks))return!1;return!0}canReplaceWith(e,t,n,r){if(r&&!this.type.allowsMarks(r))return!1;let i=this.contentMatchAt(e).matchType(n),a=i&&i.matchFragment(this.content,t);return a?a.validEnd:!1}canAppend(e){return e.content.size?this.canReplace(this.childCount,this.childCount,e.content):this.type.compatibleContent(e.type)}check(){this.type.checkContent(this.content),r_(this.type.attrs,this.attrs,`node`,this.type.name);let e=Pg.none;for(let t=0;t<this.marks.length;t++){let n=this.marks[t];r_(n.type.attrs,n.attrs,`mark`,n.type.name),e=n.addToSet(e)}if(!Pg.sameSet(e,this.marks))throw RangeError(`Invalid collection of marks for node ${this.type.name}: ${this.marks.map(e=>e.type.name)}`);this.content.forEach(e=>e.check())}toJSON(){let e={type:this.type.name};for(let t in this.attrs){e.attrs=this.attrs;break}return this.content.size&&(e.content=this.content.toJSON()),this.marks.length&&(e.marks=this.marks.map(e=>e.toJSON())),e}static fromJSON(e,t){if(!t)throw RangeError(`Invalid input for Node.fromJSON`);let n;if(t.marks){if(!Array.isArray(t.marks))throw RangeError(`Invalid mark data for Node.fromJSON`);n=t.marks.map(e.markFromJSON)}if(t.type==`text`){if(typeof t.text!=`string`)throw RangeError(`Invalid text node in JSON`);return e.text(t.text,n)}let r=J.fromJSON(e,t.content);return e.nodeType(t.type).create(t.attrs,r,n)}};e_.prototype.text=void 0;var t_=class e extends e_{constructor(e,t,n,r){if(super(e,t,null,r),!n)throw RangeError(`Empty text nodes are not allowed`);this.text=n}toString(){return this.type.spec.toDebugString?this.type.spec.toDebugString(this):n_(this.marks,JSON.stringify(this.text))}get textContent(){return this.text}textBetween(e,t){return this.text.slice(e,t)}get nodeSize(){return this.text.length}mark(t){return t==this.marks?this:new e(this.type,this.attrs,this.text,t)}withText(t){return t==this.text?this:new e(this.type,this.attrs,t,this.marks)}cut(e=0,t=this.text.length){return e==0&&t==this.text.length?this:this.withText(this.text.slice(e,t))}eq(e){return this.sameMarkup(e)&&this.text==e.text}toJSON(){let e=super.toJSON();return e.text=this.text,e}};function n_(e,t){for(let n=e.length-1;n>=0;n--)t=e[n].type.name+`(`+t+`)`;return t}function r_(e,t,n,r){for(let i in t)if(!(i in e))throw RangeError(`Unsupported attribute ${i} for ${n} of type ${r}`);for(let n in e)e[n].validate&&e[n].validate(t[n])}var i_=class e{constructor(e){this.validEnd=e,this.next=[],this.wrapCache=[]}static parse(t,n){let r=new a_(t,n);if(r.next==null)return e.empty;let i=o_(r);r.next&&r.err(`Unexpected trailing text`);let a=g_(p_(i));return __(a,r),a}matchType(e){for(let t=0;t<this.next.length;t++)if(this.next[t].type==e)return this.next[t].next;return null}matchFragment(e,t=0,n=e.childCount){let r=this;for(let i=t;r&&i<n;i++)r=r.matchType(e.child(i).type);return r}get inlineContent(){return this.next.length!=0&&this.next[0].type.isInline}get defaultType(){for(let e=0;e<this.next.length;e++){let{type:t}=this.next[e];if(!(t.isText||t.hasRequiredAttrs()))return t}return null}compatible(e){for(let t=0;t<this.next.length;t++)for(let n=0;n<e.next.length;n++)if(this.next[t].type==e.next[n].type)return!0;return!1}fillBefore(e,t=!1,n=0){let r=[this];function i(a,o){let s=a.matchFragment(e,n);if(s&&(!t||s.validEnd))return J.from(o.map(e=>e.createAndFill()));for(let e=0;e<a.next.length;e++){let{type:t,next:n}=a.next[e];if(!(t.isText||t.hasRequiredAttrs())&&r.indexOf(n)==-1){r.push(n);let e=i(n,o.concat(t));if(e)return e}}return null}return i(this,[])}findWrapping(e){for(let t=0;t<this.wrapCache.length;t+=2)if(this.wrapCache[t]==e)return this.wrapCache[t+1];let t=this.computeWrapping(e);return this.wrapCache.push(e,t),t}computeWrapping(e){let t=Object.create(null),n=[{match:this,type:null,via:null}];for(;n.length;){let r=n.shift(),i=r.match;if(i.matchType(e)){let e=[];for(let t=r;t.type;t=t.via)e.push(t.type);return e.reverse()}for(let e=0;e<i.next.length;e++){let{type:a,next:o}=i.next[e];!a.isLeaf&&!a.hasRequiredAttrs()&&!(a.name in t)&&(!r.type||o.validEnd)&&(n.push({match:a.contentMatch,type:a,via:r}),t[a.name]=!0)}}return null}get edgeCount(){return this.next.length}edge(e){if(e>=this.next.length)throw RangeError(`There's no ${e}th edge in this content match`);return this.next[e]}toString(){let e=[];function t(n){e.push(n);for(let r=0;r<n.next.length;r++)e.indexOf(n.next[r].next)==-1&&t(n.next[r].next)}return t(this),e.map((t,n)=>{let r=n+(t.validEnd?`*`:` `)+` `;for(let n=0;n<t.next.length;n++)r+=(n?`, `:``)+t.next[n].type.name+`->`+e.indexOf(t.next[n].next);return r}).join(`
|
|
9
|
+
`)}};i_.empty=new i_(!0);var a_=class{constructor(e,t){this.string=e,this.nodeTypes=t,this.inline=null,this.pos=0,this.tokens=e.split(/\s*(?=\b|\W|$)/),this.tokens[this.tokens.length-1]==``&&this.tokens.pop(),this.tokens[0]==``&&this.tokens.shift()}get next(){return this.tokens[this.pos]}eat(e){return this.next==e&&(this.pos++||!0)}err(e){throw SyntaxError(e+` (in content expression '`+this.string+`')`)}};function o_(e){let t=[];do t.push(s_(e));while(e.eat(`|`));return t.length==1?t[0]:{type:`choice`,exprs:t}}function s_(e){let t=[];do t.push(c_(e));while(e.next&&e.next!=`)`&&e.next!=`|`);return t.length==1?t[0]:{type:`seq`,exprs:t}}function c_(e){let t=f_(e);for(;;)if(e.eat(`+`))t={type:`plus`,expr:t};else if(e.eat(`*`))t={type:`star`,expr:t};else if(e.eat(`?`))t={type:`opt`,expr:t};else if(e.eat(`{`))t=u_(e,t);else break;return t}function l_(e){/\D/.test(e.next)&&e.err(`Expected number, got '`+e.next+`'`);let t=Number(e.next);return e.pos++,t}function u_(e,t){let n=l_(e),r=n;return e.eat(`,`)&&(r=e.next==`}`?-1:l_(e)),e.eat(`}`)||e.err(`Unclosed braced range`),{type:`range`,min:n,max:r,expr:t}}function d_(e,t){let n=e.nodeTypes,r=n[t];if(r)return[r];let i=[];for(let e in n){let r=n[e];r.isInGroup(t)&&i.push(r)}return i.length==0&&e.err(`No node type or group '`+t+`' found`),i}function f_(e){if(e.eat(`(`)){let t=o_(e);return e.eat(`)`)||e.err(`Missing closing paren`),t}else if(/\W/.test(e.next))e.err(`Unexpected token '`+e.next+`'`);else{let t=d_(e,e.next).map(t=>(e.inline==null?e.inline=t.isInline:e.inline!=t.isInline&&e.err(`Mixing inline and block content`),{type:`name`,value:t}));return e.pos++,t.length==1?t[0]:{type:`choice`,exprs:t}}}function p_(e){let t=[[]];return i(a(e,0),n()),t;function n(){return t.push([])-1}function r(e,n,r){let i={term:r,to:n};return t[e].push(i),i}function i(e,t){e.forEach(e=>e.to=t)}function a(e,t){if(e.type==`choice`)return e.exprs.reduce((e,n)=>e.concat(a(n,t)),[]);if(e.type==`seq`)for(let r=0;;r++){let o=a(e.exprs[r],t);if(r==e.exprs.length-1)return o;i(o,t=n())}else if(e.type==`star`){let o=n();return r(t,o),i(a(e.expr,o),o),[r(o)]}else if(e.type==`plus`){let o=n();return i(a(e.expr,t),o),i(a(e.expr,o),o),[r(o)]}else if(e.type==`opt`)return[r(t)].concat(a(e.expr,t));else if(e.type==`range`){let o=t;for(let t=0;t<e.min;t++){let t=n();i(a(e.expr,o),t),o=t}if(e.max==-1)i(a(e.expr,o),o);else for(let t=e.min;t<e.max;t++){let t=n();r(o,t),i(a(e.expr,o),t),o=t}return[r(o)]}else if(e.type==`name`)return[r(t,void 0,e.value)];else throw Error(`Unknown expr type`)}}function m_(e,t){return t-e}function h_(e,t){let n=[];return r(t),n.sort(m_);function r(t){let i=e[t];if(i.length==1&&!i[0].term)return r(i[0].to);n.push(t);for(let e=0;e<i.length;e++){let{term:t,to:a}=i[e];!t&&n.indexOf(a)==-1&&r(a)}}}function g_(e){let t=Object.create(null);return n(h_(e,0));function n(r){let i=[];r.forEach(t=>{e[t].forEach(({term:t,to:n})=>{if(!t)return;let r;for(let e=0;e<i.length;e++)i[e][0]==t&&(r=i[e][1]);h_(e,n).forEach(e=>{r||i.push([t,r=[]]),r.indexOf(e)==-1&&r.push(e)})})});let a=t[r.join(`,`)]=new i_(r.indexOf(e.length-1)>-1);for(let e=0;e<i.length;e++){let r=i[e][1].sort(m_);a.next.push({type:i[e][0],next:t[r.join(`,`)]||n(r)})}return a}}function __(e,t){for(let n=0,r=[e];n<r.length;n++){let e=r[n],i=!e.validEnd,a=[];for(let t=0;t<e.next.length;t++){let{type:n,next:o}=e.next[t];a.push(n.name),i&&!(n.isText||n.hasRequiredAttrs())&&(i=!1),r.indexOf(o)==-1&&r.push(o)}i&&t.err(`Only non-generatable nodes (`+a.join(`, `)+`) in a required position (see https://prosemirror.net/docs/guide/#generatable)`)}}function v_(e){let t=Object.create(null);for(let n in e){let r=e[n];if(!r.hasDefault)return null;t[n]=r.default}return t}function y_(e,t){let n=Object.create(null);for(let r in e){let i=e[r],a=t&&t[r];if(a===void 0)if(i.hasDefault)a=i.default;else throw RangeError(`No value supplied for attribute `+r);else i.validate&&i.validate(a);n[r]=a}return n}function b_(e,t){let n=Object.create(null);if(t)for(let r in t)n[r]=new C_(e,r,t[r]);return n}var x_=class e{constructor(e,t,n){this.name=e,this.schema=t,this.spec=n,this.markSet=null,this.groups=n.group?n.group.split(` `):[],this.attrs=b_(e,n.attrs),this.defaultAttrs=v_(this.attrs),this.contentMatch=null,this.inlineContent=null,this.isBlock=!(n.inline||e==`text`),this.isText=e==`text`}get isInline(){return!this.isBlock}get isTextblock(){return this.isBlock&&this.inlineContent}get isLeaf(){return this.contentMatch==i_.empty}get isAtom(){return this.isLeaf||!!this.spec.atom}isInGroup(e){return this.groups.indexOf(e)>-1}get whitespace(){return this.spec.whitespace||(this.spec.code?`pre`:`normal`)}hasRequiredAttrs(){for(let e in this.attrs)if(this.attrs[e].isRequired)return!0;return!1}compatibleContent(e){return this==e||this.contentMatch.compatible(e.contentMatch)}computeAttrs(e){return!e&&this.defaultAttrs?this.defaultAttrs:y_(this.attrs,e)}create(e=null,t,n){if(this.isText)throw Error(`NodeType.create can't construct text nodes`);return new e_(this,this.computeAttrs(e),J.from(t),Pg.setFrom(n))}createChecked(e=null,t,n){return t=J.from(t),this.checkContent(t),new e_(this,this.computeAttrs(e),t,Pg.setFrom(n))}createAndFill(e=null,t,n){if(e=this.computeAttrs(e),t=J.from(t),t.size){let e=this.contentMatch.fillBefore(t);if(!e)return null;t=e.append(t)}let r=this.contentMatch.matchFragment(t),i=r&&r.fillBefore(J.empty,!0);return i?new e_(this,e,t.append(i),Pg.setFrom(n)):null}validContent(e){let t=this.contentMatch.matchFragment(e);if(!t||!t.validEnd)return!1;for(let t=0;t<e.childCount;t++)if(!this.allowsMarks(e.child(t).marks))return!1;return!0}checkContent(e){if(!this.validContent(e))throw RangeError(`Invalid content for node ${this.name}: ${e.toString().slice(0,50)}`)}checkAttrs(e){}allowsMarkType(e){return this.markSet==null||this.markSet.indexOf(e)>-1}allowsMarks(e){if(this.markSet==null)return!0;for(let t=0;t<e.length;t++)if(!this.allowsMarkType(e[t].type))return!1;return!0}allowedMarks(e){if(this.markSet==null)return e;let t;for(let n=0;n<e.length;n++)this.allowsMarkType(e[n].type)?t&&t.push(e[n]):t||=e.slice(0,n);return t?t.length?t:Pg.none:e}static compile(t,n){let r=Object.create(null);t.forEach((t,i)=>r[t]=new e(t,n,i));let i=n.spec.topNode||`doc`;if(!r[i])throw RangeError(`Schema is missing its top node type ('`+i+`')`);if(!r.text)throw RangeError(`Every schema needs a 'text' type`);for(let e in r.text.attrs)throw RangeError(`The text node type should not have attributes`);return r}};function S_(e,t,n){let r=n.split(`|`);return n=>{let i=n===null?`null`:typeof n;if(r.indexOf(i)<0)throw RangeError(`Expected value of type ${r} for attribute ${t} on type ${e}, got ${i}`)}}var C_=class{constructor(e,t,n){this.hasDefault=Object.prototype.hasOwnProperty.call(n,`default`),this.default=n.default,this.validate=typeof n.validate==`string`?S_(e,t,n.validate):n.validate}get isRequired(){return!this.hasDefault}},w_=class e{constructor(e,t,n,r){this.name=e,this.rank=t,this.schema=n,this.spec=r,this.attrs=b_(e,r.attrs),this.excluded=null;let i=v_(this.attrs);this.instance=i?new Pg(this,i):null}create(e=null){return!e&&this.instance?this.instance:new Pg(this,y_(this.attrs,e))}static compile(t,n){let r=Object.create(null),i=0;return t.forEach((t,a)=>r[t]=new e(t,i++,n,a)),r}removeFromSet(e){for(var t=0;t<e.length;t++)e[t].type==this&&(e=e.slice(0,t).concat(e.slice(t+1)),t--);return e}isInSet(e){for(let t=0;t<e.length;t++)if(e[t].type==this)return e[t]}excludes(e){return this.excluded.indexOf(e)>-1}},T_=class{constructor(e){this.linebreakReplacement=null,this.cached=Object.create(null);let t=this.spec={};for(let n in e)t[n]=e[n];t.nodes=Eg.from(e.nodes),t.marks=Eg.from(e.marks||{}),this.nodes=x_.compile(this.spec.nodes,this),this.marks=w_.compile(this.spec.marks,this);let n=Object.create(null);for(let e in this.nodes){if(e in this.marks)throw RangeError(e+` can not be both a node and a mark`);let t=this.nodes[e],r=t.spec.content||``,i=t.spec.marks;if(t.contentMatch=n[r]||(n[r]=i_.parse(r,this.nodes)),t.inlineContent=t.contentMatch.inlineContent,t.spec.linebreakReplacement){if(this.linebreakReplacement)throw RangeError(`Multiple linebreak nodes defined`);if(!t.isInline||!t.isLeaf)throw RangeError(`Linebreak replacement nodes must be inline leaf nodes`);this.linebreakReplacement=t}t.markSet=i==`_`?null:i?E_(this,i.split(` `)):i==``||!t.inlineContent?[]:null}for(let e in this.marks){let t=this.marks[e],n=t.spec.excludes;t.excluded=n==null?[t]:n==``?[]:E_(this,n.split(` `))}this.nodeFromJSON=e=>e_.fromJSON(this,e),this.markFromJSON=e=>Pg.fromJSON(this,e),this.topNodeType=this.nodes[this.spec.topNode||`doc`],this.cached.wrappings=Object.create(null)}node(e,t=null,n,r){if(typeof e==`string`)e=this.nodeType(e);else if(!(e instanceof x_))throw RangeError(`Invalid node type: `+e);else if(e.schema!=this)throw RangeError(`Node type from different schema used (`+e.name+`)`);return e.createChecked(t,n,r)}text(e,t){let n=this.nodes.text;return new t_(n,n.defaultAttrs,e,Pg.setFrom(t))}mark(e,t){return typeof e==`string`&&(e=this.marks[e]),e.create(t)}nodeType(e){let t=this.nodes[e];if(!t)throw RangeError(`Unknown node type: `+e);return t}};function E_(e,t){let n=[];for(let r=0;r<t.length;r++){let i=t[r],a=e.marks[i],o=a;if(a)n.push(a);else for(let t in e.marks){let r=e.marks[t];(i==`_`||r.spec.group&&r.spec.group.split(` `).indexOf(i)>-1)&&n.push(o=r)}if(!o)throw SyntaxError(`Unknown mark type: '`+t[r]+`'`)}return n}function D_(e){return e.tag!=null}function O_(e){return e.style!=null}var k_=class e{constructor(e,t){this.schema=e,this.rules=t,this.tags=[],this.styles=[];let n=this.matchedStyles=[];t.forEach(e=>{if(D_(e))this.tags.push(e);else if(O_(e)){let t=/[^=]*/.exec(e.style)[0];n.indexOf(t)<0&&n.push(t),this.styles.push(e)}}),this.normalizeLists=!this.tags.some(t=>{if(!/^(ul|ol)\b/.test(t.tag)||!t.node)return!1;let n=e.nodes[t.node];return n.contentMatch.matchType(n)})}parse(e,t={}){let n=new R_(this,t,!1);return n.addAll(e,Pg.none,t.from,t.to),n.finish()}parseSlice(e,t={}){let n=new R_(this,t,!0);return n.addAll(e,Pg.none,t.from,t.to),Y.maxOpen(n.finish())}matchTag(e,t,n){for(let r=n?this.tags.indexOf(n)+1:0;r<this.tags.length;r++){let n=this.tags[r];if(B_(e,n.tag)&&(n.namespace===void 0||e.namespaceURI==n.namespace)&&(!n.context||t.matchesContext(n.context))){if(n.getAttrs){let t=n.getAttrs(e);if(t===!1)continue;n.attrs=t||void 0}return n}}}matchStyle(e,t,n,r){for(let i=r?this.styles.indexOf(r)+1:0;i<this.styles.length;i++){let r=this.styles[i],a=r.style;if(!(a.indexOf(e)!=0||r.context&&!n.matchesContext(r.context)||a.length>e.length&&(a.charCodeAt(e.length)!=61||a.slice(e.length+1)!=t))){if(r.getAttrs){let e=r.getAttrs(t);if(e===!1)continue;r.attrs=e||void 0}return r}}}static schemaRules(e){let t=[];function n(e){let n=e.priority==null?50:e.priority,r=0;for(;r<t.length;r++){let e=t[r];if((e.priority==null?50:e.priority)<n)break}t.splice(r,0,e)}for(let t in e.marks){let r=e.marks[t].spec.parseDOM;r&&r.forEach(e=>{n(e=V_(e)),e.mark||e.ignore||e.clearMark||(e.mark=t)})}for(let t in e.nodes){let r=e.nodes[t].spec.parseDOM;r&&r.forEach(e=>{n(e=V_(e)),e.node||e.ignore||e.mark||(e.node=t)})}return t}static fromSchema(t){return t.cached.domParser||(t.cached.domParser=new e(t,e.schemaRules(t)))}},A_={address:!0,article:!0,aside:!0,blockquote:!0,body:!0,canvas:!0,dd:!0,div:!0,dl:!0,fieldset:!0,figcaption:!0,figure:!0,footer:!0,form:!0,h1:!0,h2:!0,h3:!0,h4:!0,h5:!0,h6:!0,header:!0,hgroup:!0,hr:!0,li:!0,noscript:!0,ol:!0,output:!0,p:!0,pre:!0,section:!0,table:!0,tfoot:!0,ul:!0},j_={head:!0,noscript:!0,object:!0,script:!0,style:!0,title:!0},M_={ol:!0,ul:!0},N_=1,P_=2,F_=4;function I_(e,t,n){return t==null?e&&e.whitespace==`pre`?3:n&-5:(t?N_:0)|(t===`full`?P_:0)}var L_=class{constructor(e,t,n,r,i,a){this.type=e,this.attrs=t,this.marks=n,this.solid=r,this.options=a,this.content=[],this.activeMarks=Pg.none,this.match=i||(a&F_?null:e.contentMatch)}findWrapping(e){if(!this.match){if(!this.type)return[];let t=this.type.contentMatch.fillBefore(J.from(e));if(t)this.match=this.type.contentMatch.matchFragment(t);else{let t=this.type.contentMatch,n;return(n=t.findWrapping(e.type))?(this.match=t,n):null}}return this.match.findWrapping(e.type)}finish(e){if(!(this.options&N_)){let e=this.content[this.content.length-1],t;if(e&&e.isText&&(t=/[ \t\r\n\u000c]+$/.exec(e.text))){let n=e;e.text.length==t[0].length?this.content.pop():this.content[this.content.length-1]=n.withText(n.text.slice(0,n.text.length-t[0].length))}}let t=J.from(this.content);return!e&&this.match&&(t=t.append(this.match.fillBefore(J.empty,!0))),this.type?this.type.create(this.attrs,t,this.marks):t}inlineContext(e){return this.type?this.type.inlineContent:this.content.length?this.content[0].isInline:e.parentNode&&!A_.hasOwnProperty(e.parentNode.nodeName.toLowerCase())}},R_=class{constructor(e,t,n){this.parser=e,this.options=t,this.isOpen=n,this.open=0,this.localPreserveWS=!1;let r=t.topNode,i,a=I_(null,t.preserveWhitespace,0)|(n?F_:0);i=r?new L_(r.type,r.attrs,Pg.none,!0,t.topMatch||r.type.contentMatch,a):n?new L_(null,null,Pg.none,!0,null,a):new L_(e.schema.topNodeType,null,Pg.none,!0,null,a),this.nodes=[i],this.find=t.findPositions,this.needsBlock=!1}get top(){return this.nodes[this.open]}addDOM(e,t){e.nodeType==3?this.addTextNode(e,t):e.nodeType==1&&this.addElement(e,t)}addTextNode(e,t){let n=e.nodeValue,r=this.top,i=r.options&P_?`full`:this.localPreserveWS||(r.options&N_)>0,{schema:a}=this.parser;if(i===`full`||r.inlineContext(e)||/[^ \t\r\n\u000c]/.test(n)){if(!i){if(n=n.replace(/[ \t\r\n\u000c]+/g,` `),/^[ \t\r\n\u000c]/.test(n)&&this.open==this.nodes.length-1){let t=r.content[r.content.length-1],i=e.previousSibling;(!t||i&&i.nodeName==`BR`||t.isText&&/[ \t\r\n\u000c]$/.test(t.text))&&(n=n.slice(1))}}else if(i===`full`)n=n.replace(/\r\n?/g,`
|
|
10
|
+
`);else if(a.linebreakReplacement&&/[\r\n]/.test(n)&&this.top.findWrapping(a.linebreakReplacement.create())){let e=n.split(/\r?\n|\r/);for(let n=0;n<e.length;n++)n&&this.insertNode(a.linebreakReplacement.create(),t,!0),e[n]&&this.insertNode(a.text(e[n]),t,!/\S/.test(e[n]));n=``}else n=n.replace(/\r?\n|\r/g,` `);n&&this.insertNode(a.text(n),t,!/\S/.test(n)),this.findInText(e)}else this.findInside(e)}addElement(e,t,n){let r=this.localPreserveWS,i=this.top;(e.tagName==`PRE`||/pre/.test(e.style&&e.style.whiteSpace))&&(this.localPreserveWS=!0);let a=e.nodeName.toLowerCase(),o;M_.hasOwnProperty(a)&&this.parser.normalizeLists&&z_(e);let s=this.options.ruleFromNode&&this.options.ruleFromNode(e)||(o=this.parser.matchTag(e,this,n));out:if(s?s.ignore:j_.hasOwnProperty(a))this.findInside(e),this.ignoreFallback(e,t);else if(!s||s.skip||s.closeParent){s&&s.closeParent?this.open=Math.max(0,this.open-1):s&&s.skip.nodeType&&(e=s.skip);let n,r=this.needsBlock;if(A_.hasOwnProperty(a))i.content.length&&i.content[0].isInline&&this.open&&(this.open--,i=this.top),n=!0,i.type||(this.needsBlock=!0);else if(!e.firstChild){this.leafFallback(e,t);break out}let o=s&&s.skip?t:this.readStyles(e,t);o&&this.addAll(e,o),n&&this.sync(i),this.needsBlock=r}else{let n=this.readStyles(e,t);n&&this.addElementByRule(e,s,n,s.consuming===!1?o:void 0)}this.localPreserveWS=r}leafFallback(e,t){e.nodeName==`BR`&&this.top.type&&this.top.type.inlineContent&&this.addTextNode(e.ownerDocument.createTextNode(`
|
|
11
|
+
`),t)}ignoreFallback(e,t){e.nodeName==`BR`&&(!this.top.type||!this.top.type.inlineContent)&&this.findPlace(this.parser.schema.text(`-`),t,!0)}readStyles(e,t){let n=e.style;if(n&&n.length)for(let e=0;e<this.parser.matchedStyles.length;e++){let r=this.parser.matchedStyles[e],i=n.getPropertyValue(r);if(i)for(let e;;){let n=this.parser.matchStyle(r,i,this,e);if(!n)break;if(n.ignore)return null;if(t=n.clearMark?t.filter(e=>!n.clearMark(e)):t.concat(this.parser.schema.marks[n.mark].create(n.attrs)),n.consuming===!1)e=n;else break}}return t}addElementByRule(e,t,n,r){let i,a;if(t.node)if(a=this.parser.schema.nodes[t.node],a.isLeaf)this.insertNode(a.create(t.attrs),n,e.nodeName==`BR`)||this.leafFallback(e,n);else{let e=this.enter(a,t.attrs||null,n,t.preserveWhitespace);e&&(i=!0,n=e)}else{let e=this.parser.schema.marks[t.mark];n=n.concat(e.create(t.attrs))}let o=this.top;if(a&&a.isLeaf)this.findInside(e);else if(r)this.addElement(e,n,r);else if(t.getContent)this.findInside(e),t.getContent(e,this.parser.schema).forEach(e=>this.insertNode(e,n,!1));else{let r=e;typeof t.contentElement==`string`?r=e.querySelector(t.contentElement):typeof t.contentElement==`function`?r=t.contentElement(e):t.contentElement&&(r=t.contentElement),this.findAround(e,r,!0),this.addAll(r,n),this.findAround(e,r,!1)}i&&this.sync(o)&&this.open--}addAll(e,t,n,r){let i=n||0;for(let a=n?e.childNodes[n]:e.firstChild,o=r==null?null:e.childNodes[r];a!=o;a=a.nextSibling,++i)this.findAtPoint(e,i),this.addDOM(a,t);this.findAtPoint(e,i)}findPlace(e,t,n){let r,i;for(let t=this.open,a=0;t>=0;t--){let o=this.nodes[t],s=o.findWrapping(e);if(s&&(!r||r.length>s.length+a)&&(r=s,i=o,!s.length))break;if(o.solid){if(n)break;a+=2}}if(!r)return null;this.sync(i);for(let e=0;e<r.length;e++)t=this.enterInner(r[e],null,t,!1);return t}insertNode(e,t,n){if(e.isInline&&this.needsBlock&&!this.top.type){let e=this.textblockFromContext();e&&(t=this.enterInner(e,null,t))}let r=this.findPlace(e,t,n);if(r){this.closeExtra();let t=this.top;t.match&&=t.match.matchType(e.type);let n=Pg.none;for(let i of r.concat(e.marks))(t.type?t.type.allowsMarkType(i.type):H_(i.type,e.type))&&(n=i.addToSet(n));return t.content.push(e.mark(n)),!0}return!1}enter(e,t,n,r){let i=this.findPlace(e.create(t),n,!1);return i&&=this.enterInner(e,t,n,!0,r),i}enterInner(e,t,n,r=!1,i){this.closeExtra();let a=this.top;a.match=a.match&&a.match.matchType(e);let o=I_(e,i,a.options);a.options&F_&&a.content.length==0&&(o|=F_);let s=Pg.none;return n=n.filter(t=>(a.type?a.type.allowsMarkType(t.type):H_(t.type,e))?(s=t.addToSet(s),!1):!0),this.nodes.push(new L_(e,t,s,r,null,o)),this.open++,n}closeExtra(e=!1){let t=this.nodes.length-1;if(t>this.open){for(;t>this.open;t--)this.nodes[t-1].content.push(this.nodes[t].finish(e));this.nodes.length=this.open+1}}finish(){return this.open=0,this.closeExtra(this.isOpen),this.nodes[0].finish(!!(this.isOpen||this.options.topOpen))}sync(e){for(let t=this.open;t>=0;t--)if(this.nodes[t]==e)return this.open=t,!0;else this.localPreserveWS&&(this.nodes[t].options|=N_);return!1}get currentPos(){this.closeExtra();let e=0;for(let t=this.open;t>=0;t--){let n=this.nodes[t].content;for(let t=n.length-1;t>=0;t--)e+=n[t].nodeSize;t&&e++}return e}findAtPoint(e,t){if(this.find)for(let n=0;n<this.find.length;n++)this.find[n].node==e&&this.find[n].offset==t&&(this.find[n].pos=this.currentPos)}findInside(e){if(this.find)for(let t=0;t<this.find.length;t++)this.find[t].pos==null&&e.nodeType==1&&e.contains(this.find[t].node)&&(this.find[t].pos=this.currentPos)}findAround(e,t,n){if(e!=t&&this.find)for(let r=0;r<this.find.length;r++)this.find[r].pos==null&&e.nodeType==1&&e.contains(this.find[r].node)&&t.compareDocumentPosition(this.find[r].node)&(n?2:4)&&(this.find[r].pos=this.currentPos)}findInText(e){if(this.find)for(let t=0;t<this.find.length;t++)this.find[t].node==e&&(this.find[t].pos=this.currentPos-(e.nodeValue.length-this.find[t].offset))}matchesContext(e){if(e.indexOf(`|`)>-1)return e.split(/\s*\|\s*/).some(this.matchesContext,this);let t=e.split(`/`),n=this.options.context,r=!this.isOpen&&(!n||n.parent.type==this.nodes[0].type),i=-(n?n.depth+1:0)+ +!r,a=(e,o)=>{for(;e>=0;e--){let s=t[e];if(s==``){if(e==t.length-1||e==0)continue;for(;o>=i;o--)if(a(e-1,o))return!0;return!1}else{let e=o>0||o==0&&r?this.nodes[o].type:n&&o>=i?n.node(o-i).type:null;if(!e||e.name!=s&&!e.isInGroup(s))return!1;o--}}return!0};return a(t.length-1,this.open)}textblockFromContext(){let e=this.options.context;if(e)for(let t=e.depth;t>=0;t--){let n=e.node(t).contentMatchAt(e.indexAfter(t)).defaultType;if(n&&n.isTextblock&&n.defaultAttrs)return n}for(let e in this.parser.schema.nodes){let t=this.parser.schema.nodes[e];if(t.isTextblock&&t.defaultAttrs)return t}}};function z_(e){for(let t=e.firstChild,n=null;t;t=t.nextSibling){let e=t.nodeType==1?t.nodeName.toLowerCase():null;e&&M_.hasOwnProperty(e)&&n?(n.appendChild(t),t=n):e==`li`?n=t:e&&(n=null)}}function B_(e,t){return(e.matches||e.msMatchesSelector||e.webkitMatchesSelector||e.mozMatchesSelector).call(e,t)}function V_(e){let t={};for(let n in e)t[n]=e[n];return t}function H_(e,t){let n=t.schema.nodes;for(let r in n){let i=n[r];if(!i.allowsMarkType(e))continue;let a=[],o=e=>{a.push(e);for(let n=0;n<e.edgeCount;n++){let{type:r,next:i}=e.edge(n);if(r==t||a.indexOf(i)<0&&o(i))return!0}};if(o(i.contentMatch))return!0}}var U_=class e{constructor(e,t){this.nodes=e,this.marks=t}serializeFragment(e,t={},n){n||=G_(t).createDocumentFragment();let r=n,i=[];return e.forEach(e=>{if(i.length||e.marks.length){let n=0,a=0;for(;n<i.length&&a<e.marks.length;){let t=e.marks[a];if(!this.marks[t.type.name]){a++;continue}if(!t.eq(i[n][0])||t.type.spec.spanning===!1)break;n++,a++}for(;n<i.length;)r=i.pop()[1];for(;a<e.marks.length;){let n=e.marks[a++],o=this.serializeMark(n,e.isInline,t);o&&(i.push([n,r]),r.appendChild(o.dom),r=o.contentDOM||o.dom)}}r.appendChild(this.serializeNodeInner(e,t))}),n}serializeNodeInner(e,t){if(e.isText)return G_(t).createTextNode(e.text);let{dom:n,contentDOM:r}=Y_(G_(t),this.nodes[e.type.name](e),null,e.attrs);if(r){if(e.isLeaf)throw RangeError(`Content hole not allowed in a leaf node spec`);this.serializeFragment(e.content,t,r)}return n}serializeNode(e,t={}){let n=this.serializeNodeInner(e,t);for(let r=e.marks.length-1;r>=0;r--){let i=this.serializeMark(e.marks[r],e.isInline,t);i&&((i.contentDOM||i.dom).appendChild(n),n=i.dom)}return n}serializeMark(e,t,n={}){let r=this.marks[e.type.name];return r&&Y_(G_(n),r(e,t),null,e.attrs)}static renderSpec(e,t,n=null,r){return typeof t==`string`?{dom:e.createTextNode(t)}:Y_(e,t,n,r)}static fromSchema(t){return t.cached.domSerializer||(t.cached.domSerializer=new e(this.nodesFromSchema(t),this.marksFromSchema(t)))}static nodesFromSchema(e){let t=W_(e.nodes);return t.text||=e=>e.text,t}static marksFromSchema(e){return W_(e.marks)}};function W_(e){let t={};for(let n in e){let r=e[n].spec.toDOM;r&&(t[n]=r)}return t}function G_(e){return e.document||window.document}var K_=new WeakMap;function q_(e){let t=K_.get(e);return t===void 0&&K_.set(e,t=J_(e)),t}function J_(e){let t=null;function n(e){if(e&&typeof e==`object`)if(Array.isArray(e))if(typeof e[0]==`string`)t||=[],t.push(e);else for(let t=0;t<e.length;t++)n(e[t]);else for(let t in e)n(e[t])}return n(e),t}function Y_(e,t,n,r){if(t.nodeType==1)return{dom:t};if(t.dom&&t.dom.nodeType==1)return t;let i=t[0],a;if(typeof i!=`string`)throw RangeError(`Invalid array passed to renderSpec`);if(r&&(a=q_(r))&&a.indexOf(t)>-1)throw RangeError(`Using an array from an attribute object as a DOM spec. This may be an attempted cross site scripting attack.`);let o=i.indexOf(` `);o>0&&(n=i.slice(0,o),i=i.slice(o+1));let s,c=n?e.createElementNS(n,i):e.createElement(i),l=t[1],u=1;if(l&&typeof l==`object`&&l.nodeType==null&&!Array.isArray(l)){u=2;for(let e in l)if(l[e]!=null){let t=e.indexOf(` `);t>0?c.setAttributeNS(e.slice(0,t),e.slice(t+1),l[e]):e==`style`&&c.style?c.style.cssText=l[e]:c.setAttribute(e,l[e])}}for(let i=u;i<t.length;i++){let a=t[i];if(a===0){if(i<t.length-1||i>u)throw RangeError(`Content hole must be the only child of its parent node`);return{dom:c,contentDOM:c}}else if(typeof a==`string`)c.appendChild(e.createTextNode(a));else{let{dom:t,contentDOM:i}=Y_(e,a,n,r);if(c.appendChild(t),i){if(s)throw RangeError(`Multiple content holes`);s=i}}}return{dom:c,contentDOM:s}}var X_=65535,Z_=2**16;function Q_(e,t){return e+t*Z_}function $_(e){return e&X_}function ev(e){return(e-(e&X_))/Z_}var tv=1,nv=2,rv=4,iv=8,av=class{constructor(e,t,n){this.pos=e,this.delInfo=t,this.recover=n}get deleted(){return(this.delInfo&iv)>0}get deletedBefore(){return(this.delInfo&5)>0}get deletedAfter(){return(this.delInfo&6)>0}get deletedAcross(){return(this.delInfo&rv)>0}},ov=class e{constructor(t,n=!1){if(this.ranges=t,this.inverted=n,!t.length&&e.empty)return e.empty}recover(e){let t=0,n=$_(e);if(!this.inverted)for(let e=0;e<n;e++)t+=this.ranges[e*3+2]-this.ranges[e*3+1];return this.ranges[n*3]+t+ev(e)}mapResult(e,t=1){return this._map(e,t,!1)}map(e,t=1){return this._map(e,t,!0)}_map(e,t,n){let r=0,i=this.inverted?2:1,a=this.inverted?1:2;for(let o=0;o<this.ranges.length;o+=3){let s=this.ranges[o]-(this.inverted?r:0);if(s>e)break;let c=this.ranges[o+i],l=this.ranges[o+a],u=s+c;if(e<=u){let i=c?e==s?-1:e==u?1:t:t,a=s+r+(i<0?0:l);if(n)return a;let d=e==(t<0?s:u)?null:Q_(o/3,e-s),f=0;return c&&(f|=e==s?nv:e==u?tv:rv,(t<0?e!=s:e!=u)&&(f|=iv)),new av(a,f,d)}r+=l-c}return n?e+r:new av(e+r,0,null)}touches(e,t){let n=0,r=$_(t),i=this.inverted?2:1,a=this.inverted?1:2;for(let t=0;t<this.ranges.length;t+=3){let o=this.ranges[t]-(this.inverted?n:0);if(o>e)break;let s=this.ranges[t+i];if(e<=o+s&&t==r*3)return!0;n+=this.ranges[t+a]-s}return!1}forEach(e){let t=this.inverted?2:1,n=this.inverted?1:2;for(let r=0,i=0;r<this.ranges.length;r+=3){let a=this.ranges[r],o=a-(this.inverted?i:0),s=a+(this.inverted?0:i),c=this.ranges[r+t],l=this.ranges[r+n];e(o,o+c,s,s+l),i+=l-c}}invert(){return new e(this.ranges,!this.inverted)}toString(){return(this.inverted?`-`:``)+JSON.stringify(this.ranges)}static offset(t){return t==0?e.empty:new e(t<0?[0,-t,0]:[0,0,t])}};ov.empty=new ov([]);var sv=class e{constructor(e,t,n=0,r=e?e.length:0){this.mirror=t,this.from=n,this.to=r,this._maps=e||[],this.ownData=!(e||t)}get maps(){return this._maps}slice(t=0,n=this.maps.length){return new e(this._maps,this.mirror,t,n)}appendMap(e,t){this.ownData||=(this._maps=this._maps.slice(),this.mirror=this.mirror&&this.mirror.slice(),!0),this.to=this._maps.push(e),t!=null&&this.setMirror(this._maps.length-1,t)}appendMapping(e){for(let t=0,n=this._maps.length;t<e._maps.length;t++){let r=e.getMirror(t);this.appendMap(e._maps[t],r!=null&&r<t?n+r:void 0)}}getMirror(e){if(this.mirror){for(let t=0;t<this.mirror.length;t++)if(this.mirror[t]==e)return this.mirror[t+(t%2?-1:1)]}}setMirror(e,t){this.mirror||=[],this.mirror.push(e,t)}appendMappingInverted(e){for(let t=e.maps.length-1,n=this._maps.length+e._maps.length;t>=0;t--){let r=e.getMirror(t);this.appendMap(e._maps[t].invert(),r!=null&&r>t?n-r-1:void 0)}}invert(){let t=new e;return t.appendMappingInverted(this),t}map(e,t=1){if(this.mirror)return this._map(e,t,!0);for(let n=this.from;n<this.to;n++)e=this._maps[n].map(e,t);return e}mapResult(e,t=1){return this._map(e,t,!1)}_map(e,t,n){let r=0;for(let n=this.from;n<this.to;n++){let i=this._maps[n].mapResult(e,t);if(i.recover!=null){let t=this.getMirror(n);if(t!=null&&t>n&&t<this.to){n=t,e=this._maps[t].recover(i.recover);continue}}r|=i.delInfo,e=i.pos}return n?e:new av(e,r,null)}},cv=Object.create(null),lv=class{getMap(){return ov.empty}merge(e){return null}static fromJSON(e,t){if(!t||!t.stepType)throw RangeError(`Invalid input for Step.fromJSON`);let n=cv[t.stepType];if(!n)throw RangeError(`No step type ${t.stepType} defined`);return n.fromJSON(e,t)}static jsonID(e,t){if(e in cv)throw RangeError(`Duplicate use of step JSON ID `+e);return cv[e]=t,t.prototype.jsonID=e,t}},uv=class e{constructor(e,t){this.doc=e,this.failed=t}static ok(t){return new e(t,null)}static fail(t){return new e(null,t)}static fromReplace(t,n,r,i){try{return e.ok(t.replace(n,r,i))}catch(t){if(t instanceof Fg)return e.fail(t.message);throw t}}};function dv(e,t,n){let r=[];for(let i=0;i<e.childCount;i++){let a=e.child(i);a.content.size&&(a=a.copy(dv(a.content,t,a))),a.isInline&&(a=t(a,n,i)),r.push(a)}return J.fromArray(r)}var fv=class e extends lv{constructor(e,t,n){super(),this.from=e,this.to=t,this.mark=n}apply(e){let t=e.slice(this.from,this.to),n=e.resolve(this.from),r=n.node(n.sharedDepth(this.to)),i=new Y(dv(t.content,(e,t)=>!e.isAtom||!t.type.allowsMarkType(this.mark.type)?e:e.mark(this.mark.addToSet(e.marks)),r),t.openStart,t.openEnd);return uv.fromReplace(e,this.from,this.to,i)}invert(){return new pv(this.from,this.to,this.mark)}map(t){let n=t.mapResult(this.from,1),r=t.mapResult(this.to,-1);return n.deleted&&r.deleted||n.pos>=r.pos?null:new e(n.pos,r.pos,this.mark)}merge(t){return t instanceof e&&t.mark.eq(this.mark)&&this.from<=t.to&&this.to>=t.from?new e(Math.min(this.from,t.from),Math.max(this.to,t.to),this.mark):null}toJSON(){return{stepType:`addMark`,mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(t,n){if(typeof n.from!=`number`||typeof n.to!=`number`)throw RangeError(`Invalid input for AddMarkStep.fromJSON`);return new e(n.from,n.to,t.markFromJSON(n.mark))}};lv.jsonID(`addMark`,fv);var pv=class e extends lv{constructor(e,t,n){super(),this.from=e,this.to=t,this.mark=n}apply(e){let t=e.slice(this.from,this.to),n=new Y(dv(t.content,e=>e.mark(this.mark.removeFromSet(e.marks)),e),t.openStart,t.openEnd);return uv.fromReplace(e,this.from,this.to,n)}invert(){return new fv(this.from,this.to,this.mark)}map(t){let n=t.mapResult(this.from,1),r=t.mapResult(this.to,-1);return n.deleted&&r.deleted||n.pos>=r.pos?null:new e(n.pos,r.pos,this.mark)}merge(t){return t instanceof e&&t.mark.eq(this.mark)&&this.from<=t.to&&this.to>=t.from?new e(Math.min(this.from,t.from),Math.max(this.to,t.to),this.mark):null}toJSON(){return{stepType:`removeMark`,mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(t,n){if(typeof n.from!=`number`||typeof n.to!=`number`)throw RangeError(`Invalid input for RemoveMarkStep.fromJSON`);return new e(n.from,n.to,t.markFromJSON(n.mark))}};lv.jsonID(`removeMark`,pv);var mv=class e extends lv{constructor(e,t){super(),this.pos=e,this.mark=t}apply(e){let t=e.nodeAt(this.pos);if(!t)return uv.fail(`No node at mark step's position`);let n=t.type.create(t.attrs,null,this.mark.addToSet(t.marks));return uv.fromReplace(e,this.pos,this.pos+1,new Y(J.from(n),0,+!t.isLeaf))}invert(t){let n=t.nodeAt(this.pos);if(n){let t=this.mark.addToSet(n.marks);if(t.length==n.marks.length){for(let r=0;r<n.marks.length;r++)if(!n.marks[r].isInSet(t))return new e(this.pos,n.marks[r]);return new e(this.pos,this.mark)}}return new hv(this.pos,this.mark)}map(t){let n=t.mapResult(this.pos,1);return n.deletedAfter?null:new e(n.pos,this.mark)}toJSON(){return{stepType:`addNodeMark`,pos:this.pos,mark:this.mark.toJSON()}}static fromJSON(t,n){if(typeof n.pos!=`number`)throw RangeError(`Invalid input for AddNodeMarkStep.fromJSON`);return new e(n.pos,t.markFromJSON(n.mark))}};lv.jsonID(`addNodeMark`,mv);var hv=class e extends lv{constructor(e,t){super(),this.pos=e,this.mark=t}apply(e){let t=e.nodeAt(this.pos);if(!t)return uv.fail(`No node at mark step's position`);let n=t.type.create(t.attrs,null,this.mark.removeFromSet(t.marks));return uv.fromReplace(e,this.pos,this.pos+1,new Y(J.from(n),0,+!t.isLeaf))}invert(e){let t=e.nodeAt(this.pos);return!t||!this.mark.isInSet(t.marks)?this:new mv(this.pos,this.mark)}map(t){let n=t.mapResult(this.pos,1);return n.deletedAfter?null:new e(n.pos,this.mark)}toJSON(){return{stepType:`removeNodeMark`,pos:this.pos,mark:this.mark.toJSON()}}static fromJSON(t,n){if(typeof n.pos!=`number`)throw RangeError(`Invalid input for RemoveNodeMarkStep.fromJSON`);return new e(n.pos,t.markFromJSON(n.mark))}};lv.jsonID(`removeNodeMark`,hv);var gv=class e extends lv{constructor(e,t,n,r=!1){super(),this.from=e,this.to=t,this.slice=n,this.structure=r}apply(e){return this.structure&&vv(e,this.from,this.to)?uv.fail(`Structure replace would overwrite content`):uv.fromReplace(e,this.from,this.to,this.slice)}getMap(){return new ov([this.from,this.to-this.from,this.slice.size])}invert(t){return new e(this.from,this.from+this.slice.size,t.slice(this.from,this.to))}map(t){let n=t.mapResult(this.to,-1),r=this.from==this.to&&e.MAP_BIAS<0?n:t.mapResult(this.from,1);return r.deletedAcross&&n.deletedAcross?null:new e(r.pos,Math.max(r.pos,n.pos),this.slice,this.structure)}merge(t){if(!(t instanceof e)||t.structure||this.structure)return null;if(this.from+this.slice.size==t.from&&!this.slice.openEnd&&!t.slice.openStart){let n=this.slice.size+t.slice.size==0?Y.empty:new Y(this.slice.content.append(t.slice.content),this.slice.openStart,t.slice.openEnd);return new e(this.from,this.to+(t.to-t.from),n,this.structure)}else if(t.to==this.from&&!this.slice.openStart&&!t.slice.openEnd){let n=this.slice.size+t.slice.size==0?Y.empty:new Y(t.slice.content.append(this.slice.content),t.slice.openStart,this.slice.openEnd);return new e(t.from,this.to,n,this.structure)}else return null}toJSON(){let e={stepType:`replace`,from:this.from,to:this.to};return this.slice.size&&(e.slice=this.slice.toJSON()),this.structure&&(e.structure=!0),e}static fromJSON(t,n){if(typeof n.from!=`number`||typeof n.to!=`number`)throw RangeError(`Invalid input for ReplaceStep.fromJSON`);return new e(n.from,n.to,Y.fromJSON(t,n.slice),!!n.structure)}};gv.MAP_BIAS=1,lv.jsonID(`replace`,gv);var _v=class e extends lv{constructor(e,t,n,r,i,a,o=!1){super(),this.from=e,this.to=t,this.gapFrom=n,this.gapTo=r,this.slice=i,this.insert=a,this.structure=o}apply(e){if(this.structure&&(vv(e,this.from,this.gapFrom)||vv(e,this.gapTo,this.to)))return uv.fail(`Structure gap-replace would overwrite content`);let t=e.slice(this.gapFrom,this.gapTo);if(t.openStart||t.openEnd)return uv.fail(`Gap is not a flat range`);let n=this.slice.insertAt(this.insert,t.content);return n?uv.fromReplace(e,this.from,this.to,n):uv.fail(`Content does not fit in gap`)}getMap(){return new ov([this.from,this.gapFrom-this.from,this.insert,this.gapTo,this.to-this.gapTo,this.slice.size-this.insert])}invert(t){let n=this.gapTo-this.gapFrom;return new e(this.from,this.from+this.slice.size+n,this.from+this.insert,this.from+this.insert+n,t.slice(this.from,this.to).removeBetween(this.gapFrom-this.from,this.gapTo-this.from),this.gapFrom-this.from,this.structure)}map(t){let n=t.mapResult(this.from,1),r=t.mapResult(this.to,-1),i=this.from==this.gapFrom?n.pos:t.map(this.gapFrom,-1),a=this.to==this.gapTo?r.pos:t.map(this.gapTo,1);return n.deletedAcross&&r.deletedAcross||i<n.pos||a>r.pos?null:new e(n.pos,r.pos,i,a,this.slice,this.insert,this.structure)}toJSON(){let e={stepType:`replaceAround`,from:this.from,to:this.to,gapFrom:this.gapFrom,gapTo:this.gapTo,insert:this.insert};return this.slice.size&&(e.slice=this.slice.toJSON()),this.structure&&(e.structure=!0),e}static fromJSON(t,n){if(typeof n.from!=`number`||typeof n.to!=`number`||typeof n.gapFrom!=`number`||typeof n.gapTo!=`number`||typeof n.insert!=`number`)throw RangeError(`Invalid input for ReplaceAroundStep.fromJSON`);return new e(n.from,n.to,n.gapFrom,n.gapTo,Y.fromJSON(t,n.slice),n.insert,!!n.structure)}};lv.jsonID(`replaceAround`,_v);function vv(e,t,n){let r=e.resolve(t),i=n-t,a=r.depth;for(;i>0&&a>0&&r.indexAfter(a)==r.node(a).childCount;)a--,i--;if(i>0){let e=r.node(a).maybeChild(r.indexAfter(a));for(;i>0;){if(!e||e.isLeaf)return!0;e=e.firstChild,i--}}return!1}function yv(e,t,n,r){let i=[],a=[],o,s;e.doc.nodesBetween(t,n,(e,c,l)=>{if(!e.isInline)return;let u=e.marks;if(!r.isInSet(u)&&l.type.allowsMarkType(r.type)){let l=Math.max(c,t),d=Math.min(c+e.nodeSize,n),f=r.addToSet(u);for(let e=0;e<u.length;e++)u[e].isInSet(f)||(o&&o.to==l&&o.mark.eq(u[e])?o.to=d:i.push(o=new pv(l,d,u[e])));s&&s.to==l?s.to=d:a.push(s=new fv(l,d,r))}}),i.forEach(t=>e.step(t)),a.forEach(t=>e.step(t))}function bv(e,t,n,r){let i=[],a=0;e.doc.nodesBetween(t,n,(e,o)=>{if(!e.isInline)return;a++;let s=null;if(r instanceof w_){let t=e.marks,n;for(;n=r.isInSet(t);)(s||=[]).push(n),t=n.removeFromSet(t)}else r?r.isInSet(e.marks)&&(s=[r]):s=e.marks;if(s&&s.length){let r=Math.min(o+e.nodeSize,n);for(let e=0;e<s.length;e++){let n=s[e],c;for(let e=0;e<i.length;e++){let t=i[e];t.step==a-1&&n.eq(i[e].style)&&(c=t)}c?(c.to=r,c.step=a):i.push({style:n,from:Math.max(o,t),to:r,step:a})}}}),i.forEach(t=>e.step(new pv(t.from,t.to,t.style)))}function xv(e,t,n,r=n.contentMatch,i=!0){let a=e.doc.nodeAt(t),o=[],s=t+1;for(let t=0;t<a.childCount;t++){let c=a.child(t),l=s+c.nodeSize,u=r.matchType(c.type);if(!u)o.push(new gv(s,l,Y.empty));else{r=u;for(let t=0;t<c.marks.length;t++)n.allowsMarkType(c.marks[t].type)||e.step(new pv(s,l,c.marks[t]));if(i&&c.isText&&n.whitespace!=`pre`){let e,t=/\r?\n|\r/g,r;for(;e=t.exec(c.text);)r||=new Y(J.from(n.schema.text(` `,n.allowedMarks(c.marks))),0,0),o.push(new gv(s+e.index,s+e.index+e[0].length,r))}}s=l}if(!r.validEnd){let t=r.fillBefore(J.empty,!0);e.replace(s,s,new Y(t,0,0))}for(let t=o.length-1;t>=0;t--)e.step(o[t])}function Sv(e,t,n){return(t==0||e.canReplace(t,e.childCount))&&(n==e.childCount||e.canReplace(0,n))}function Cv(e){let t=e.parent.content.cutByIndex(e.startIndex,e.endIndex);for(let n=e.depth,r=0,i=0;;--n){let a=e.$from.node(n),o=e.$from.index(n)+r,s=e.$to.indexAfter(n)-i;if(n<e.depth&&a.canReplace(o,s,t))return n;if(n==0||a.type.spec.isolating||!Sv(a,o,s))break;o&&(r=1),s<a.childCount&&(i=1)}return null}function wv(e,t,n){let{$from:r,$to:i,depth:a}=t,o=r.before(a+1),s=i.after(a+1),c=o,l=s,u=J.empty,d=0;for(let e=a,t=!1;e>n;e--)t||r.index(e)>0?(t=!0,u=J.from(r.node(e).copy(u)),d++):c--;let f=J.empty,p=0;for(let e=a,t=!1;e>n;e--)t||i.after(e+1)<i.end(e)?(t=!0,f=J.from(i.node(e).copy(f)),p++):l++;e.step(new _v(c,l,o,s,new Y(u.append(f),d,p),u.size-d,!0))}function Tv(e,t,n=null,r=e){let i=Dv(e,t),a=i&&Ov(r,t);return a?i.map(Ev).concat({type:t,attrs:n}).concat(a.map(Ev)):null}function Ev(e){return{type:e,attrs:null}}function Dv(e,t){let{parent:n,startIndex:r,endIndex:i}=e,a=n.contentMatchAt(r).findWrapping(t);if(!a)return null;let o=a.length?a[0]:t;return n.canReplaceWith(r,i,o)?a:null}function Ov(e,t){let{parent:n,startIndex:r,endIndex:i}=e,a=n.child(r),o=t.contentMatch.findWrapping(a.type);if(!o)return null;let s=(o.length?o[o.length-1]:t).contentMatch;for(let e=r;s&&e<i;e++)s=s.matchType(n.child(e).type);return!s||!s.validEnd?null:o}function kv(e,t,n){let r=J.empty;for(let e=n.length-1;e>=0;e--){if(r.size){let t=n[e].type.contentMatch.matchFragment(r);if(!t||!t.validEnd)throw RangeError(`Wrapper type given to Transform.wrap does not form valid content of its parent wrapper`)}r=J.from(n[e].type.create(n[e].attrs,r))}let i=t.start,a=t.end;e.step(new _v(i,a,i,a,new Y(r,0,0),n.length,!0))}function Av(e,t,n,r,i){if(!r.isTextblock)throw RangeError(`Type given to setBlockType should be a textblock`);let a=e.steps.length;e.doc.nodesBetween(t,n,(t,n)=>{let o=typeof i==`function`?i(t):i;if(t.isTextblock&&!t.hasMarkup(r,o)&&Nv(e.doc,e.mapping.slice(a).map(n),r)){let i=null;if(r.schema.linebreakReplacement){let e=r.whitespace==`pre`,t=!!r.contentMatch.matchType(r.schema.linebreakReplacement);e&&!t?i=!1:!e&&t&&(i=!0)}i===!1&&Mv(e,t,n,a),xv(e,e.mapping.slice(a).map(n,1),r,void 0,i===null);let s=e.mapping.slice(a),c=s.map(n,1),l=s.map(n+t.nodeSize,1);return e.step(new _v(c,l,c+1,l-1,new Y(J.from(r.create(o,null,t.marks)),0,0),1,!0)),i===!0&&jv(e,t,n,a),!1}})}function jv(e,t,n,r){t.forEach((i,a)=>{if(i.isText){let o,s=/\r?\n|\r/g;for(;o=s.exec(i.text);){let i=e.mapping.slice(r).map(n+1+a+o.index);e.replaceWith(i,i+1,t.type.schema.linebreakReplacement.create())}}})}function Mv(e,t,n,r){t.forEach((i,a)=>{if(i.type==i.type.schema.linebreakReplacement){let i=e.mapping.slice(r).map(n+1+a);e.replaceWith(i,i+1,t.type.schema.text(`
|
|
12
|
+
`))}})}function Nv(e,t,n){let r=e.resolve(t),i=r.index();return r.parent.canReplaceWith(i,i+1,n)}function Pv(e,t,n,r,i){let a=e.doc.nodeAt(t);if(!a)throw RangeError(`No node at given position`);n||=a.type;let o=n.create(r,null,i||a.marks);if(a.isLeaf)return e.replaceWith(t,t+a.nodeSize,o);if(!n.validContent(a.content))throw RangeError(`Invalid content for node type `+n.name);e.step(new _v(t,t+a.nodeSize,t+1,t+a.nodeSize-1,new Y(J.from(o),0,0),1,!0))}function Fv(e,t,n=1,r){let i=e.resolve(t),a=i.depth-n,o=r&&r[r.length-1]||i.parent;if(a<0||i.parent.type.spec.isolating||!i.parent.canReplace(i.index(),i.parent.childCount)||!o.type.validContent(i.parent.content.cutByIndex(i.index(),i.parent.childCount)))return!1;for(let e=i.depth-1,t=n-2;e>a;e--,t--){let n=i.node(e),a=i.index(e);if(n.type.spec.isolating)return!1;let o=n.content.cutByIndex(a,n.childCount),s=r&&r[t+1];s&&(o=o.replaceChild(0,s.type.create(s.attrs)));let c=r&&r[t]||n;if(!n.canReplace(a+1,n.childCount)||!c.type.validContent(o))return!1}let s=i.indexAfter(a),c=r&&r[0];return i.node(a).canReplaceWith(s,s,c?c.type:i.node(a+1).type)}function Iv(e,t,n=1,r){let i=e.doc.resolve(t),a=J.empty,o=J.empty;for(let e=i.depth,t=i.depth-n,s=n-1;e>t;e--,s--){a=J.from(i.node(e).copy(a));let t=r&&r[s];o=J.from(t?t.type.create(t.attrs,o):i.node(e).copy(o))}e.step(new gv(t,t,new Y(a.append(o),n,n),!0))}function Lv(e,t){let n=e.resolve(t),r=n.index();return zv(n.nodeBefore,n.nodeAfter)&&n.parent.canReplace(r,r+1)}function Rv(e,t){t.content.size||e.type.compatibleContent(t.type);let n=e.contentMatchAt(e.childCount),{linebreakReplacement:r}=e.type.schema;for(let i=0;i<t.childCount;i++){let a=t.child(i),o=a.type==r?e.type.schema.nodes.text:a.type;if(n=n.matchType(o),!n||!e.type.allowsMarks(a.marks))return!1}return n.validEnd}function zv(e,t){return!!(e&&t&&!e.isLeaf&&Rv(e,t))}function Bv(e,t,n=-1){let r=e.resolve(t);for(let e=r.depth;;e--){let i,a,o=r.index(e);if(e==r.depth?(i=r.nodeBefore,a=r.nodeAfter):n>0?(i=r.node(e+1),o++,a=r.node(e).maybeChild(o)):(i=r.node(e).maybeChild(o-1),a=r.node(e+1)),i&&!i.isTextblock&&zv(i,a)&&r.node(e).canReplace(o,o+1))return t;if(e==0)break;t=n<0?r.before(e):r.after(e)}}function Vv(e,t,n){let r=null,{linebreakReplacement:i}=e.doc.type.schema,a=e.doc.resolve(t-n),o=a.node().type;if(i&&o.inlineContent){let e=o.whitespace==`pre`,t=!!o.contentMatch.matchType(i);e&&!t?r=!1:!e&&t&&(r=!0)}let s=e.steps.length;if(r===!1){let r=e.doc.resolve(t+n);Mv(e,r.node(),r.before(),s)}o.inlineContent&&xv(e,t+n-1,o,a.node().contentMatchAt(a.index()),r==null);let c=e.mapping.slice(s),l=c.map(t-n);if(e.step(new gv(l,c.map(t+n,-1),Y.empty,!0)),r===!0){let t=e.doc.resolve(l);jv(e,t.node(),t.before(),e.steps.length)}return e}function Hv(e,t,n){let r=e.resolve(t);if(r.parent.canReplaceWith(r.index(),r.index(),n))return t;if(r.parentOffset==0)for(let e=r.depth-1;e>=0;e--){let t=r.index(e);if(r.node(e).canReplaceWith(t,t,n))return r.before(e+1);if(t>0)return null}if(r.parentOffset==r.parent.content.size)for(let e=r.depth-1;e>=0;e--){let t=r.indexAfter(e);if(r.node(e).canReplaceWith(t,t,n))return r.after(e+1);if(t<r.node(e).childCount)return null}return null}function Uv(e,t,n){let r=e.resolve(t);if(!n.content.size)return t;let i=n.content;for(let e=0;e<n.openStart;e++)i=i.firstChild.content;for(let e=1;e<=(n.openStart==0&&n.size?2:1);e++)for(let t=r.depth;t>=0;t--){let n=t==r.depth?0:r.pos<=(r.start(t+1)+r.end(t+1))/2?-1:1,a=r.index(t)+ +(n>0),o=r.node(t),s=!1;if(e==1)s=o.canReplace(a,a,i);else{let e=o.contentMatchAt(a).findWrapping(i.firstChild.type);s=e&&o.canReplaceWith(a,a,e[0])}if(s)return n==0?r.pos:n<0?r.before(t+1):r.after(t+1)}return null}function Wv(e,t,n=t,r=Y.empty){if(t==n&&!r.size)return null;let i=e.resolve(t),a=e.resolve(n);return Gv(i,a,r)?new gv(t,n,r):new Kv(i,a,r).fit()}function Gv(e,t,n){return!n.openStart&&!n.openEnd&&e.start()==t.start()&&e.parent.canReplace(e.index(),t.index(),n.content)}var Kv=class{constructor(e,t,n){this.$from=e,this.$to=t,this.unplaced=n,this.frontier=[],this.placed=J.empty;for(let t=0;t<=e.depth;t++){let n=e.node(t);this.frontier.push({type:n.type,match:n.contentMatchAt(e.indexAfter(t))})}for(let t=e.depth;t>0;t--)this.placed=J.from(e.node(t).copy(this.placed))}get depth(){return this.frontier.length-1}fit(){for(;this.unplaced.size;){let e=this.findFittable();e?this.placeNodes(e):this.openMore()||this.dropNode()}let e=this.mustMoveInline(),t=this.placed.size-this.depth-this.$from.depth,n=this.$from,r=this.close(e<0?this.$to:n.doc.resolve(e));if(!r)return null;let i=this.placed,a=n.depth,o=r.depth;for(;a&&o&&i.childCount==1;)i=i.firstChild.content,a--,o--;let s=new Y(i,a,o);return e>-1?new _v(n.pos,e,this.$to.pos,this.$to.end(),s,t):s.size||n.pos!=this.$to.pos?new gv(n.pos,r.pos,s):null}findFittable(){let e=this.unplaced.openStart;for(let t=this.unplaced.content,n=0,r=this.unplaced.openEnd;n<e;n++){let i=t.firstChild;if(t.childCount>1&&(r=0),i.type.spec.isolating&&r<=n){e=n;break}t=i.content}for(let t=1;t<=2;t++)for(let n=t==1?e:this.unplaced.openStart;n>=0;n--){let e,r=null;n?(r=Yv(this.unplaced.content,n-1).firstChild,e=r.content):e=this.unplaced.content;let i=e.firstChild;for(let e=this.depth;e>=0;e--){let{type:a,match:o}=this.frontier[e],s,c=null;if(t==1&&(i?o.matchType(i.type)||(c=o.fillBefore(J.from(i),!1)):r&&a.compatibleContent(r.type)))return{sliceDepth:n,frontierDepth:e,parent:r,inject:c};if(t==2&&i&&(s=o.findWrapping(i.type)))return{sliceDepth:n,frontierDepth:e,parent:r,wrap:s};if(r&&o.matchType(r.type))break}}}openMore(){let{content:e,openStart:t,openEnd:n}=this.unplaced;return ey(e,-1)<=t?!1:(this.unplaced.size>1&&ey(e,1)>n&&n++,this.unplaced=new Y(e,t+1,n),!0)}dropNode(){let{content:e,openStart:t,openEnd:n}=this.unplaced,r=Yv(e,t);if(r.childCount<=1&&t>0){let i=e.size-t<=t+r.size;this.unplaced=new Y(qv(e,t-1,1),t-1,i?t-1:n)}else this.unplaced=new Y(qv(e,t,1),t,n)}placeNodes({sliceDepth:e,frontierDepth:t,parent:n,inject:r,wrap:i}){for(;this.depth>t;)this.closeFrontierNode();if(i)for(let e=0;e<i.length;e++)this.openFrontierNode(i[e]);let a=this.unplaced,o=n?n.content:a.content,s=a.openStart-e,c=0,l=[],{match:u,type:d}=this.frontier[t];if(r){for(let e=0;e<r.childCount;e++)l.push(r.child(e));u=u.matchFragment(r)}let f=o.size+e-(a.content.size-a.openEnd);for(;c<o.childCount;){let e=o.child(c),t=u.matchType(e.type);if(!t)break;c++,(c>1||s==0||e.content.size)&&(u=t,l.push(Xv(e.mark(d.allowedMarks(e.marks)),c==1?s:0,c==o.childCount?f:-1)))}let p=c==o.childCount;p||(f=-1),this.placed=Jv(this.placed,t,J.from(l)),this.frontier[t].match=u,p&&f<0&&n&&n.type==this.frontier[this.depth].type&&this.frontier.length>1&&this.closeFrontierNode();for(let e=0,t=o;e<f;e++){let e=t.lastChild;this.frontier.push({type:e.type,match:e.contentMatchAt(e.childCount)}),t=e.content}this.unplaced=p?e==0?Y.empty:new Y(qv(a.content,e-1,1),e-1,f<0?a.openEnd:e-1):new Y(qv(a.content,e,c),a.openStart,a.openEnd)}mustMoveInline(){if(!this.$to.parent.isTextblock)return-1;let e=this.frontier[this.depth],t;if(!e.type.isTextblock||!Zv(this.$to,this.$to.depth,e.type,e.match,!1)||this.$to.depth==this.depth&&(t=this.findCloseLevel(this.$to))&&t.depth==this.depth)return-1;let{depth:n}=this.$to,r=this.$to.after(n);for(;n>1&&r==this.$to.end(--n);)++r;return r}findCloseLevel(e){scan:for(let t=Math.min(this.depth,e.depth);t>=0;t--){let{match:n,type:r}=this.frontier[t],i=t<e.depth&&e.end(t+1)==e.pos+(e.depth-(t+1)),a=Zv(e,t,r,n,i);if(a){for(let n=t-1;n>=0;n--){let{match:t,type:r}=this.frontier[n],i=Zv(e,n,r,t,!0);if(!i||i.childCount)continue scan}return{depth:t,fit:a,move:i?e.doc.resolve(e.after(t+1)):e}}}}close(e){let t=this.findCloseLevel(e);if(!t)return null;for(;this.depth>t.depth;)this.closeFrontierNode();t.fit.childCount&&(this.placed=Jv(this.placed,t.depth,t.fit)),e=t.move;for(let n=t.depth+1;n<=e.depth;n++){let t=e.node(n),r=t.type.contentMatch.fillBefore(t.content,!0,e.index(n));this.openFrontierNode(t.type,t.attrs,r)}return e}openFrontierNode(e,t=null,n){let r=this.frontier[this.depth];r.match=r.match.matchType(e),this.placed=Jv(this.placed,this.depth,J.from(e.create(t,n))),this.frontier.push({type:e,match:e.contentMatch})}closeFrontierNode(){let e=this.frontier.pop().match.fillBefore(J.empty,!0);e.childCount&&(this.placed=Jv(this.placed,this.frontier.length,e))}};function qv(e,t,n){return t==0?e.cutByIndex(n,e.childCount):e.replaceChild(0,e.firstChild.copy(qv(e.firstChild.content,t-1,n)))}function Jv(e,t,n){return t==0?e.append(n):e.replaceChild(e.childCount-1,e.lastChild.copy(Jv(e.lastChild.content,t-1,n)))}function Yv(e,t){for(let n=0;n<t;n++)e=e.firstChild.content;return e}function Xv(e,t,n){if(t<=0)return e;let r=e.content;return t>1&&(r=r.replaceChild(0,Xv(r.firstChild,t-1,r.childCount==1?n-1:0))),t>0&&(r=e.type.contentMatch.fillBefore(r).append(r),n<=0&&(r=r.append(e.type.contentMatch.matchFragment(r).fillBefore(J.empty,!0)))),e.copy(r)}function Zv(e,t,n,r,i){let a=e.node(t),o=i?e.indexAfter(t):e.index(t);if(o==a.childCount&&!n.compatibleContent(a.type))return null;let s=r.fillBefore(a.content,!0,o);return s&&!Qv(n,a.content,o)?s:null}function Qv(e,t,n){for(let r=n;r<t.childCount;r++)if(!e.allowsMarks(t.child(r).marks))return!0;return!1}function $v(e){return e.spec.defining||e.spec.definingForContent}function ey(e,t){for(let n=0;;n++){let r=t<0?e.firstChild:e.lastChild;if(!r||r.isAtom)return n;e=r.content}}function ty(e,t,n,r){if(!r.size)return e.deleteRange(t,n);let i=e.doc.resolve(t),a=e.doc.resolve(n);if(Gv(i,a,r))return e.step(new gv(t,n,r));let o=ay(i,a);o[o.length-1]==0&&o.pop();let s=-(i.depth+1);o.unshift(s);for(let e=i.depth,t=i.pos-1;e>0;e--,t--){let n=i.node(e).type.spec;if(n.defining||n.definingAsContext||n.isolating)break;o.indexOf(e)>-1?s=e:i.before(e)==t&&o.splice(1,0,-e)}let c=o.indexOf(s),l=[],u=r.openStart;for(let e=r.content,t=0;;t++){let n=e.firstChild;if(l.push(n),t==r.openStart)break;e=n.content}for(let e=u-1;e>=0;e--){let t=l[e],n=$v(t.type);if(n&&!t.sameMarkup(i.node(Math.abs(s)-1)))u=e;else if(n||!t.type.isTextblock)break}for(let t=r.openStart;t>=0;t--){let s=(t+u+1)%(r.openStart+1),d=l[s];if(d)for(let t=0;t<o.length;t++){let l=o[(t+c)%o.length],u=!0;l<0&&(u=!1,l=-l);let f=i.node(l-1),p=i.index(l-1);if(f.canReplaceWith(p,p,d.type,d.marks))return e.replace(i.before(l),u?a.after(l):n,new Y(ny(r.content,0,r.openStart,s),s,r.openEnd))}}let d=e.steps.length;for(let s=o.length-1;s>=0&&(e.replace(t,n,r),!(e.steps.length>d));s--){let e=o[s];e<0||(t=i.before(e),n=a.after(e))}}function ny(e,t,n,r,i){if(t<n){let i=e.firstChild;e=e.replaceChild(0,i.copy(ny(i.content,t+1,n,r,i)))}if(t>r){let t=i.contentMatchAt(0),n=t.fillBefore(e).append(e);e=n.append(t.matchFragment(n).fillBefore(J.empty,!0))}return e}function ry(e,t,n,r){if(!r.isInline&&t==n&&e.doc.resolve(t).parent.content.size){let i=Hv(e.doc,t,r.type);i!=null&&(t=n=i)}e.replaceRange(t,n,new Y(J.from(r),0,0))}function iy(e,t,n){let r=e.doc.resolve(t),i=e.doc.resolve(n);if(r.parent.isTextblock&&i.parent.isTextblock&&r.start()!=i.start()&&r.parentOffset==0&&i.parentOffset==0){let a=r.sharedDepth(n),o=!1;for(let e=r.depth;e>a;e--)r.node(e).type.spec.isolating&&(o=!0);for(let e=i.depth;e>a;e--)i.node(e).type.spec.isolating&&(o=!0);if(!o){for(let e=r.depth;e>0&&t==r.start(e);e--)t=r.before(e);for(let e=i.depth;e>0&&n==i.start(e);e--)n=i.before(e);r=e.doc.resolve(t),i=e.doc.resolve(n)}}let a=ay(r,i);for(let t=0;t<a.length;t++){let n=a[t],o=t==a.length-1;if(o&&n==0||r.node(n).type.contentMatch.validEnd)return e.delete(r.start(n),i.end(n));if(n>0&&(o||r.node(n-1).canReplace(r.index(n-1),i.indexAfter(n-1))))return e.delete(r.before(n),i.after(n))}for(let a=1;a<=r.depth&&a<=i.depth;a++)if(t-r.start(a)==r.depth-a&&n>r.end(a)&&i.end(a)-n!=i.depth-a&&r.start(a-1)==i.start(a-1)&&r.node(a-1).canReplace(r.index(a-1),i.index(a-1)))return e.delete(r.before(a),n);e.delete(t,n)}function ay(e,t){let n=[],r=Math.min(e.depth,t.depth);for(let i=r;i>=0;i--){let r=e.start(i);if(r<e.pos-(e.depth-i)||t.end(i)>t.pos+(t.depth-i)||e.node(i).type.spec.isolating||t.node(i).type.spec.isolating)break;(r==t.start(i)||i==e.depth&&i==t.depth&&e.parent.inlineContent&&t.parent.inlineContent&&i&&t.start(i-1)==r-1)&&n.push(i)}return n}var oy=class e extends lv{constructor(e,t,n){super(),this.pos=e,this.attr=t,this.value=n}apply(e){let t=e.nodeAt(this.pos);if(!t)return uv.fail(`No node at attribute step's position`);let n=Object.create(null);for(let e in t.attrs)n[e]=t.attrs[e];n[this.attr]=this.value;let r=t.type.create(n,null,t.marks);return uv.fromReplace(e,this.pos,this.pos+1,new Y(J.from(r),0,+!t.isLeaf))}getMap(){return ov.empty}invert(t){return new e(this.pos,this.attr,t.nodeAt(this.pos).attrs[this.attr])}map(t){let n=t.mapResult(this.pos,1);return n.deletedAfter?null:new e(n.pos,this.attr,this.value)}toJSON(){return{stepType:`attr`,pos:this.pos,attr:this.attr,value:this.value}}static fromJSON(t,n){if(typeof n.pos!=`number`||typeof n.attr!=`string`)throw RangeError(`Invalid input for AttrStep.fromJSON`);return new e(n.pos,n.attr,n.value)}};lv.jsonID(`attr`,oy);var sy=class e extends lv{constructor(e,t){super(),this.attr=e,this.value=t}apply(e){let t=Object.create(null);for(let n in e.attrs)t[n]=e.attrs[n];t[this.attr]=this.value;let n=e.type.create(t,e.content,e.marks);return uv.ok(n)}getMap(){return ov.empty}invert(t){return new e(this.attr,t.attrs[this.attr])}map(e){return this}toJSON(){return{stepType:`docAttr`,attr:this.attr,value:this.value}}static fromJSON(t,n){if(typeof n.attr!=`string`)throw RangeError(`Invalid input for DocAttrStep.fromJSON`);return new e(n.attr,n.value)}};lv.jsonID(`docAttr`,sy);var cy=class extends Error{};cy=function e(t){let n=Error.call(this,t);return n.__proto__=e.prototype,n},cy.prototype=Object.create(Error.prototype),cy.prototype.constructor=cy,cy.prototype.name=`TransformError`;var ly=class{constructor(e){this.doc=e,this.steps=[],this.docs=[],this.mapping=new sv}get before(){return this.docs.length?this.docs[0]:this.doc}step(e){let t=this.maybeStep(e);if(t.failed)throw new cy(t.failed);return this}maybeStep(e){let t=e.apply(this.doc);return t.failed||this.addStep(e,t.doc),t}get docChanged(){return this.steps.length>0}changedRange(){let e=1e9,t=-1e9;for(let n=0;n<this.mapping.maps.length;n++){let r=this.mapping.maps[n];n&&(e=r.map(e,1),t=r.map(t,-1)),r.forEach((n,r,i,a)=>{e=Math.min(e,i),t=Math.max(t,a)})}return e==1e9?null:{from:e,to:t}}addStep(e,t){this.docs.push(this.doc),this.steps.push(e),this.mapping.appendMap(e.getMap()),this.doc=t}replace(e,t=e,n=Y.empty){let r=Wv(this.doc,e,t,n);return r&&this.step(r),this}replaceWith(e,t,n){return this.replace(e,t,new Y(J.from(n),0,0))}delete(e,t){return this.replace(e,t,Y.empty)}insert(e,t){return this.replaceWith(e,e,t)}replaceRange(e,t,n){return ty(this,e,t,n),this}replaceRangeWith(e,t,n){return ry(this,e,t,n),this}deleteRange(e,t){return iy(this,e,t),this}lift(e,t){return wv(this,e,t),this}join(e,t=1){return Vv(this,e,t),this}wrap(e,t){return kv(this,e,t),this}setBlockType(e,t=e,n,r=null){return Av(this,e,t,n,r),this}setNodeMarkup(e,t,n=null,r){return Pv(this,e,t,n,r),this}setNodeAttribute(e,t,n){return this.step(new oy(e,t,n)),this}setDocAttribute(e,t){return this.step(new sy(e,t)),this}addNodeMark(e,t){return this.step(new mv(e,t)),this}removeNodeMark(e,t){let n=this.doc.nodeAt(e);if(!n)throw RangeError(`No node at position `+e);if(t instanceof Pg)t.isInSet(n.marks)&&this.step(new hv(e,t));else{let r=n.marks,i,a=[];for(;i=t.isInSet(r);)a.push(new hv(e,i)),r=i.removeFromSet(r);for(let e=a.length-1;e>=0;e--)this.step(a[e])}return this}split(e,t=1,n){return Iv(this,e,t,n),this}addMark(e,t,n){return yv(this,e,t,n),this}removeMark(e,t,n){return bv(this,e,t,n),this}clearIncompatible(e,t,n){return xv(this,e,t,n),this}},uy=Object.create(null),dy=class{constructor(e,t,n){this.$anchor=e,this.$head=t,this.ranges=n||[new fy(e.min(t),e.max(t))]}get anchor(){return this.$anchor.pos}get head(){return this.$head.pos}get from(){return this.$from.pos}get to(){return this.$to.pos}get $from(){return this.ranges[0].$from}get $to(){return this.ranges[0].$to}get empty(){let e=this.ranges;for(let t=0;t<e.length;t++)if(e[t].$from.pos!=e[t].$to.pos)return!1;return!0}content(){return this.$from.doc.slice(this.from,this.to,!0)}replace(e,t=Y.empty){let n=t.content.lastChild,r=null;for(let e=0;e<t.openEnd;e++)r=n,n=n.lastChild;let i=e.steps.length,a=this.ranges;for(let o=0;o<a.length;o++){let{$from:s,$to:c}=a[o],l=e.mapping.slice(i);e.replaceRange(l.map(s.pos),l.map(c.pos),o?Y.empty:t),o==0&&xy(e,i,(n?n.isInline:r&&r.isTextblock)?-1:1)}}replaceWith(e,t){let n=e.steps.length,r=this.ranges;for(let i=0;i<r.length;i++){let{$from:a,$to:o}=r[i],s=e.mapping.slice(n),c=s.map(a.pos),l=s.map(o.pos);i?e.deleteRange(c,l):(e.replaceRangeWith(c,l,t),xy(e,n,t.isInline?-1:1))}}static findFrom(e,t,n=!1){let r=e.parent.inlineContent?new hy(e):by(e.node(0),e.parent,e.pos,e.index(),t,n);if(r)return r;for(let r=e.depth-1;r>=0;r--){let i=t<0?by(e.node(0),e.node(r),e.before(r+1),e.index(r),t,n):by(e.node(0),e.node(r),e.after(r+1),e.index(r)+1,t,n);if(i)return i}return null}static near(e,t=1){return this.findFrom(e,t)||this.findFrom(e,-t)||new vy(e.node(0))}static atStart(e){return by(e,e,0,0,1)||new vy(e)}static atEnd(e){return by(e,e,e.content.size,e.childCount,-1)||new vy(e)}static fromJSON(e,t){if(!t||!t.type)throw RangeError(`Invalid input for Selection.fromJSON`);let n=uy[t.type];if(!n)throw RangeError(`No selection type ${t.type} defined`);return n.fromJSON(e,t)}static jsonID(e,t){if(e in uy)throw RangeError(`Duplicate use of selection JSON ID `+e);return uy[e]=t,t.prototype.jsonID=e,t}getBookmark(){return hy.between(this.$anchor,this.$head).getBookmark()}};dy.prototype.visible=!0;var fy=class{constructor(e,t){this.$from=e,this.$to=t}},py=!1;function my(e){!py&&!e.parent.inlineContent&&(py=!0,console.warn(`TextSelection endpoint not pointing into a node with inline content (`+e.parent.type.name+`)`))}var hy=class e extends dy{constructor(e,t=e){my(e),my(t),super(e,t)}get $cursor(){return this.$anchor.pos==this.$head.pos?this.$head:null}map(t,n){let r=t.resolve(n.map(this.head));if(!r.parent.inlineContent)return dy.near(r);let i=t.resolve(n.map(this.anchor));return new e(i.parent.inlineContent?i:r,r)}replace(e,t=Y.empty){if(super.replace(e,t),t==Y.empty){let t=this.$from.marksAcross(this.$to);t&&e.ensureMarks(t)}}eq(t){return t instanceof e&&t.anchor==this.anchor&&t.head==this.head}getBookmark(){return new gy(this.anchor,this.head)}toJSON(){return{type:`text`,anchor:this.anchor,head:this.head}}static fromJSON(t,n){if(typeof n.anchor!=`number`||typeof n.head!=`number`)throw RangeError(`Invalid input for TextSelection.fromJSON`);return new e(t.resolve(n.anchor),t.resolve(n.head))}static create(e,t,n=t){let r=e.resolve(t);return new this(r,n==t?r:e.resolve(n))}static between(t,n,r){let i=t.pos-n.pos;if((!r||i)&&(r=i>=0?1:-1),!n.parent.inlineContent){let e=dy.findFrom(n,r,!0)||dy.findFrom(n,-r,!0);if(e)n=e.$head;else return dy.near(n,r)}return t.parent.inlineContent||(i==0?t=n:(t=(dy.findFrom(t,-r,!0)||dy.findFrom(t,r,!0)).$anchor,t.pos<n.pos!=i<0&&(t=n))),new e(t,n)}};dy.jsonID(`text`,hy);var gy=class e{constructor(e,t){this.anchor=e,this.head=t}map(t){return new e(t.map(this.anchor),t.map(this.head))}resolve(e){return hy.between(e.resolve(this.anchor),e.resolve(this.head))}},X=class e extends dy{constructor(e){let t=e.nodeAfter,n=e.node(0).resolve(e.pos+t.nodeSize);super(e,n),this.node=t}map(t,n){let{deleted:r,pos:i}=n.mapResult(this.anchor),a=t.resolve(i);return r?dy.near(a):new e(a)}content(){return new Y(J.from(this.node),0,0)}eq(t){return t instanceof e&&t.anchor==this.anchor}toJSON(){return{type:`node`,anchor:this.anchor}}getBookmark(){return new _y(this.anchor)}static fromJSON(t,n){if(typeof n.anchor!=`number`)throw RangeError(`Invalid input for NodeSelection.fromJSON`);return new e(t.resolve(n.anchor))}static create(t,n){return new e(t.resolve(n))}static isSelectable(e){return!e.isText&&e.type.spec.selectable!==!1}};X.prototype.visible=!1,dy.jsonID(`node`,X);var _y=class e{constructor(e){this.anchor=e}map(t){let{deleted:n,pos:r}=t.mapResult(this.anchor);return n?new gy(r,r):new e(r)}resolve(e){let t=e.resolve(this.anchor),n=t.nodeAfter;return n&&X.isSelectable(n)?new X(t):dy.near(t)}},vy=class e extends dy{constructor(e){super(e.resolve(0),e.resolve(e.content.size))}replace(e,t=Y.empty){if(t==Y.empty){e.delete(0,e.doc.content.size);let t=dy.atStart(e.doc);t.eq(e.selection)||e.setSelection(t)}else super.replace(e,t)}toJSON(){return{type:`all`}}static fromJSON(t){return new e(t)}map(t){return new e(t)}eq(t){return t instanceof e}getBookmark(){return yy}};dy.jsonID(`all`,vy);var yy={map(){return this},resolve(e){return new vy(e)}};function by(e,t,n,r,i,a=!1){if(t.inlineContent)return hy.create(e,n);for(let o=r-(i>0?0:1);i>0?o<t.childCount:o>=0;o+=i){let r=t.child(o);if(!r.isAtom){let t=by(e,r,n+i,i<0?r.childCount:0,i,a);if(t)return t}else if(!a&&X.isSelectable(r))return X.create(e,n-(i<0?r.nodeSize:0));n+=r.nodeSize*i}return null}function xy(e,t,n){let r=e.steps.length-1;if(r<t)return;let i=e.steps[r];if(!(i instanceof gv||i instanceof _v))return;let a=e.mapping.maps[r],o;a.forEach((e,t,n,r)=>{o??=r}),e.setSelection(dy.near(e.doc.resolve(o),n))}var Sy=1,Cy=2,wy=4,Ty=class extends ly{constructor(e){super(e.doc),this.curSelectionFor=0,this.updated=0,this.meta=Object.create(null),this.time=Date.now(),this.curSelection=e.selection,this.storedMarks=e.storedMarks}get selection(){return this.curSelectionFor<this.steps.length&&(this.curSelection=this.curSelection.map(this.doc,this.mapping.slice(this.curSelectionFor)),this.curSelectionFor=this.steps.length),this.curSelection}setSelection(e){if(e.$from.doc!=this.doc)throw RangeError(`Selection passed to setSelection must point at the current document`);return this.curSelection=e,this.curSelectionFor=this.steps.length,this.updated=(this.updated|Sy)&-3,this.storedMarks=null,this}get selectionSet(){return(this.updated&Sy)>0}setStoredMarks(e){return this.storedMarks=e,this.updated|=Cy,this}ensureMarks(e){return Pg.sameSet(this.storedMarks||this.selection.$from.marks(),e)||this.setStoredMarks(e),this}addStoredMark(e){return this.ensureMarks(e.addToSet(this.storedMarks||this.selection.$head.marks()))}removeStoredMark(e){return this.ensureMarks(e.removeFromSet(this.storedMarks||this.selection.$head.marks()))}get storedMarksSet(){return(this.updated&Cy)>0}addStep(e,t){super.addStep(e,t),this.updated&=-3,this.storedMarks=null}setTime(e){return this.time=e,this}replaceSelection(e){return this.selection.replace(this,e),this}replaceSelectionWith(e,t=!0){let n=this.selection;return t&&(e=e.mark(this.storedMarks||(n.empty?n.$from.marks():n.$from.marksAcross(n.$to)||Pg.none))),n.replaceWith(this,e),this}deleteSelection(){return this.selection.replace(this),this}insertText(e,t,n){let r=this.doc.type.schema;if(t==null)return e?this.replaceSelectionWith(r.text(e),!0):this.deleteSelection();{if(n??=t,!e)return this.deleteRange(t,n);let i=this.storedMarks;if(!i){let e=this.doc.resolve(t);i=n==t?e.marks():e.marksAcross(this.doc.resolve(n))}return this.replaceRangeWith(t,n,r.text(e,i)),!this.selection.empty&&this.selection.to==t+e.length&&this.setSelection(dy.near(this.selection.$to)),this}}setMeta(e,t){return this.meta[typeof e==`string`?e:e.key]=t,this}getMeta(e){return this.meta[typeof e==`string`?e:e.key]}get isGeneric(){for(let e in this.meta)return!1;return!0}scrollIntoView(){return this.updated|=wy,this}get scrolledIntoView(){return(this.updated&wy)>0}};function Ey(e,t){return!t||!e?e:e.bind(t)}var Dy=class{constructor(e,t,n){this.name=e,this.init=Ey(t.init,n),this.apply=Ey(t.apply,n)}},Oy=[new Dy(`doc`,{init(e){return e.doc||e.schema.topNodeType.createAndFill()},apply(e){return e.doc}}),new Dy(`selection`,{init(e,t){return e.selection||dy.atStart(t.doc)},apply(e){return e.selection}}),new Dy(`storedMarks`,{init(e){return e.storedMarks||null},apply(e,t,n,r){return r.selection.$cursor?e.storedMarks:null}}),new Dy(`scrollToSelection`,{init(){return 0},apply(e,t){return e.scrolledIntoView?t+1:t}})],ky=class{constructor(e,t){this.schema=e,this.plugins=[],this.pluginsByKey=Object.create(null),this.fields=Oy.slice(),t&&t.forEach(e=>{if(this.pluginsByKey[e.key])throw RangeError(`Adding different instances of a keyed plugin (`+e.key+`)`);this.plugins.push(e),this.pluginsByKey[e.key]=e,e.spec.state&&this.fields.push(new Dy(e.key,e.spec.state,e))})}},Ay=class e{constructor(e){this.config=e}get schema(){return this.config.schema}get plugins(){return this.config.plugins}apply(e){return this.applyTransaction(e).state}filterTransaction(e,t=-1){for(let n=0;n<this.config.plugins.length;n++)if(n!=t){let t=this.config.plugins[n];if(t.spec.filterTransaction&&!t.spec.filterTransaction.call(t,e,this))return!1}return!0}applyTransaction(e){if(!this.filterTransaction(e))return{state:this,transactions:[]};let t=[e],n=this.applyInner(e),r=null;for(;;){let i=!1;for(let a=0;a<this.config.plugins.length;a++){let o=this.config.plugins[a];if(o.spec.appendTransaction){let s=r?r[a].n:0,c=r?r[a].state:this,l=s<t.length&&o.spec.appendTransaction.call(o,s?t.slice(s):t,c,n);if(l&&n.filterTransaction(l,a)){if(l.setMeta(`appendedTransaction`,e),!r){r=[];for(let e=0;e<this.config.plugins.length;e++)r.push(e<a?{state:n,n:t.length}:{state:this,n:0})}t.push(l),n=n.applyInner(l),i=!0}r&&(r[a]={state:n,n:t.length})}}if(!i)return{state:n,transactions:t}}}applyInner(t){if(!t.before.eq(this.doc))throw RangeError(`Applying a mismatched transaction`);let n=new e(this.config),r=this.config.fields;for(let e=0;e<r.length;e++){let i=r[e];n[i.name]=i.apply(t,this[i.name],this,n)}return n}get tr(){return new Ty(this)}static create(t){let n=new ky(t.doc?t.doc.type.schema:t.schema,t.plugins),r=new e(n);for(let e=0;e<n.fields.length;e++)r[n.fields[e].name]=n.fields[e].init(t,r);return r}reconfigure(t){let n=new ky(this.schema,t.plugins),r=n.fields,i=new e(n);for(let e=0;e<r.length;e++){let n=r[e].name;i[n]=this.hasOwnProperty(n)?this[n]:r[e].init(t,i)}return i}toJSON(e){let t={doc:this.doc.toJSON(),selection:this.selection.toJSON()};if(this.storedMarks&&(t.storedMarks=this.storedMarks.map(e=>e.toJSON())),e&&typeof e==`object`)for(let n in e){if(n==`doc`||n==`selection`)throw RangeError("The JSON fields `doc` and `selection` are reserved");let r=e[n],i=r.spec.state;i&&i.toJSON&&(t[n]=i.toJSON.call(r,this[r.key]))}return t}static fromJSON(t,n,r){if(!n)throw RangeError(`Invalid input for EditorState.fromJSON`);if(!t.schema)throw RangeError(`Required config field 'schema' missing`);let i=new ky(t.schema,t.plugins),a=new e(i);return i.fields.forEach(e=>{if(e.name==`doc`)a.doc=e_.fromJSON(t.schema,n.doc);else if(e.name==`selection`)a.selection=dy.fromJSON(a.doc,n.selection);else if(e.name==`storedMarks`)n.storedMarks&&(a.storedMarks=n.storedMarks.map(t.schema.markFromJSON));else{if(r)for(let i in r){let o=r[i],s=o.spec.state;if(o.key==e.name&&s&&s.fromJSON&&Object.prototype.hasOwnProperty.call(n,i)){a[e.name]=s.fromJSON.call(o,t,n[i],a);return}}a[e.name]=e.init(t,a)}}),a}};function jy(e,t,n){for(let r in e){let i=e[r];i instanceof Function?i=i.bind(t):r==`handleDOMEvents`&&(i=jy(i,t,{})),n[r]=i}return n}var My=class{constructor(e){this.spec=e,this.props={},e.props&&jy(e.props,this,this.props),this.key=e.key?e.key.key:Py(`plugin`)}getState(e){return e[this.key]}},Ny=Object.create(null);function Py(e){return e in Ny?e+`$`+ ++Ny[e]:(Ny[e]=0,e+`$`)}var Fy=class{constructor(e=`key`){this.key=Py(e)}get(e){return e.config.pluginsByKey[this.key]}getState(e){return e[this.key]}},Iy=(e,t)=>e.selection.empty?!1:(t&&t(e.tr.deleteSelection().scrollIntoView()),!0);function Ly(e,t){let{$cursor:n}=e.selection;return!n||(t?!t.endOfTextblock(`backward`,e):n.parentOffset>0)?null:n}var Ry=(e,t,n)=>{let r=Ly(e,n);if(!r)return!1;let i=Wy(r);if(!i){let n=r.blockRange(),i=n&&Cv(n);return i==null?!1:(t&&t(e.tr.lift(n,i).scrollIntoView()),!0)}let a=i.nodeBefore;if(cb(e,i,t,-1))return!0;if(r.parent.content.size==0&&(Hy(a,`end`)||X.isSelectable(a)))for(let n=r.depth;;n--){let o=Wv(e.doc,r.before(n),r.after(n),Y.empty);if(o&&o.slice.size<o.to-o.from){if(t){let n=e.tr.step(o);n.setSelection(Hy(a,`end`)?dy.findFrom(n.doc.resolve(n.mapping.map(i.pos,-1)),-1):X.create(n.doc,i.pos-a.nodeSize)),t(n.scrollIntoView())}return!0}if(n==1||r.node(n-1).childCount>1)break}return a.isAtom&&i.depth==r.depth-1?(t&&t(e.tr.delete(i.pos-a.nodeSize,i.pos).scrollIntoView()),!0):!1},zy=(e,t,n)=>{let r=Ly(e,n);if(!r)return!1;let i=Wy(r);return i?Vy(e,i,t):!1},By=(e,t,n)=>{let r=Gy(e,n);if(!r)return!1;let i=Jy(r);return i?Vy(e,i,t):!1};function Vy(e,t,n){let r=t.nodeBefore,i=t.pos-1;for(;!r.isTextblock;i--){if(r.type.spec.isolating)return!1;let e=r.lastChild;if(!e)return!1;r=e}let a=t.nodeAfter,o=t.pos+1;for(;!a.isTextblock;o++){if(a.type.spec.isolating)return!1;let e=a.firstChild;if(!e)return!1;a=e}let s=Wv(e.doc,i,o,Y.empty);if(!s||s.from!=i||s instanceof gv&&s.slice.size>=o-i)return!1;if(n){let t=e.tr.step(s);t.setSelection(hy.create(t.doc,i)),n(t.scrollIntoView())}return!0}function Hy(e,t,n=!1){for(let r=e;r;r=t==`start`?r.firstChild:r.lastChild){if(r.isTextblock)return!0;if(n&&r.childCount!=1)return!1}return!1}var Uy=(e,t,n)=>{let{$head:r,empty:i}=e.selection,a=r;if(!i)return!1;if(r.parent.isTextblock){if(n?!n.endOfTextblock(`backward`,e):r.parentOffset>0)return!1;a=Wy(r)}let o=a&&a.nodeBefore;return!o||!X.isSelectable(o)?!1:(t&&t(e.tr.setSelection(X.create(e.doc,a.pos-o.nodeSize)).scrollIntoView()),!0)};function Wy(e){if(!e.parent.type.spec.isolating)for(let t=e.depth-1;t>=0;t--){if(e.index(t)>0)return e.doc.resolve(e.before(t+1));if(e.node(t).type.spec.isolating)break}return null}function Gy(e,t){let{$cursor:n}=e.selection;return!n||(t?!t.endOfTextblock(`forward`,e):n.parentOffset<n.parent.content.size)?null:n}var Ky=(e,t,n)=>{let r=Gy(e,n);if(!r)return!1;let i=Jy(r);if(!i)return!1;let a=i.nodeAfter;if(cb(e,i,t,1))return!0;if(r.parent.content.size==0&&(Hy(a,`start`)||X.isSelectable(a))){let n=Wv(e.doc,r.before(),r.after(),Y.empty);if(n&&n.slice.size<n.to-n.from){if(t){let r=e.tr.step(n);r.setSelection(Hy(a,`start`)?dy.findFrom(r.doc.resolve(r.mapping.map(i.pos)),1):X.create(r.doc,r.mapping.map(i.pos))),t(r.scrollIntoView())}return!0}}return a.isAtom&&i.depth==r.depth-1?(t&&t(e.tr.delete(i.pos,i.pos+a.nodeSize).scrollIntoView()),!0):!1},qy=(e,t,n)=>{let{$head:r,empty:i}=e.selection,a=r;if(!i)return!1;if(r.parent.isTextblock){if(n?!n.endOfTextblock(`forward`,e):r.parentOffset<r.parent.content.size)return!1;a=Jy(r)}let o=a&&a.nodeAfter;return!o||!X.isSelectable(o)?!1:(t&&t(e.tr.setSelection(X.create(e.doc,a.pos)).scrollIntoView()),!0)};function Jy(e){if(!e.parent.type.spec.isolating)for(let t=e.depth-1;t>=0;t--){let n=e.node(t);if(e.index(t)+1<n.childCount)return e.doc.resolve(e.after(t+1));if(n.type.spec.isolating)break}return null}var Yy=(e,t)=>{let n=e.selection,r=n instanceof X,i;if(r){if(n.node.isTextblock||!Lv(e.doc,n.from))return!1;i=n.from}else if(i=Bv(e.doc,n.from,-1),i==null)return!1;if(t){let n=e.tr.join(i);r&&n.setSelection(X.create(n.doc,i-e.doc.resolve(i).nodeBefore.nodeSize)),t(n.scrollIntoView())}return!0},Xy=(e,t)=>{let n=e.selection,r;if(n instanceof X){if(n.node.isTextblock||!Lv(e.doc,n.to))return!1;r=n.to}else if(r=Bv(e.doc,n.to,1),r==null)return!1;return t&&t(e.tr.join(r).scrollIntoView()),!0},Zy=(e,t)=>{let{$from:n,$to:r}=e.selection,i=n.blockRange(r),a=i&&Cv(i);return a==null?!1:(t&&t(e.tr.lift(i,a).scrollIntoView()),!0)},Qy=(e,t)=>{let{$head:n,$anchor:r}=e.selection;return!n.parent.type.spec.code||!n.sameParent(r)?!1:(t&&t(e.tr.insertText(`
|
|
13
|
+
`).scrollIntoView()),!0)};function $y(e){for(let t=0;t<e.edgeCount;t++){let{type:n}=e.edge(t);if(n.isTextblock&&!n.hasRequiredAttrs())return n}return null}var eb=(e,t)=>{let{$head:n,$anchor:r}=e.selection;if(!n.parent.type.spec.code||!n.sameParent(r))return!1;let i=n.node(-1),a=n.indexAfter(-1),o=$y(i.contentMatchAt(a));if(!o||!i.canReplaceWith(a,a,o))return!1;if(t){let r=n.after(),i=e.tr.replaceWith(r,r,o.createAndFill());i.setSelection(dy.near(i.doc.resolve(r),1)),t(i.scrollIntoView())}return!0},tb=(e,t)=>{let n=e.selection,{$from:r,$to:i}=n;if(n instanceof vy||r.parent.inlineContent||i.parent.inlineContent)return!1;let a=$y(i.parent.contentMatchAt(i.indexAfter()));if(!a||!a.isTextblock)return!1;if(t){let n=(!r.parentOffset&&i.index()<i.parent.childCount?r:i).pos,o=e.tr.insert(n,a.createAndFill());o.setSelection(hy.create(o.doc,n+1)),t(o.scrollIntoView())}return!0},nb=(e,t)=>{let{$cursor:n}=e.selection;if(!n||n.parent.content.size)return!1;if(n.depth>1&&n.after()!=n.end(-1)){let r=n.before();if(Fv(e.doc,r))return t&&t(e.tr.split(r).scrollIntoView()),!0}let r=n.blockRange(),i=r&&Cv(r);return i==null?!1:(t&&t(e.tr.lift(r,i).scrollIntoView()),!0)};function rb(e){return(t,n)=>{if(t.selection instanceof X&&t.selection.node.isBlock){let{$from:e}=t.selection;return!e.parentOffset||!Fv(t.doc,e.pos)?!1:(n&&n(t.tr.split(e.pos).scrollIntoView()),!0)}if(!t.selection.$from.depth)return!1;let r=t.tr;!t.selection.empty&&(t.selection instanceof hy||t.selection instanceof vy)&&r.deleteSelection();let{$from:i}=r.selection,a=r.steps.length,o=[],s,c,l=!1,u=!1;for(let t=i.depth;;t--)if(i.node(t).isBlock){l=i.end(t)==i.pos+(i.depth-t),u=i.start(t)==i.pos-(i.depth-t),c=$y(i.node(t-1).contentMatchAt(i.indexAfter(t-1)));let n=e&&e(i.parent,l,i);o.unshift(n||(l&&c?{type:c}:null)),s=t;break}else{if(t==1)return!1;o.unshift(null)}let d=i.pos,f=Fv(r.doc,d,o.length,o);if(f||=(o[0]=c?{type:c}:null,Fv(r.doc,d,o.length,o)),!f)return!1;if(r.split(d,o.length,o),!l&&u&&i.node(s).type!=c){let e=r.mapping.slice(a),t=e.map(i.before(s)),n=r.doc.resolve(t);c&&i.node(s-1).canReplaceWith(n.index(),n.index()+1,c)&&r.setNodeMarkup(e.map(i.before(s)),c)}return n&&n(r.scrollIntoView()),!0}}var ib=rb(),ab=(e,t)=>{let{$from:n,to:r}=e.selection,i,a=n.sharedDepth(r);return a==0?!1:(i=n.before(a),t&&t(e.tr.setSelection(X.create(e.doc,i))),!0)},ob=(e,t)=>(t&&t(e.tr.setSelection(new vy(e.doc))),!0);function sb(e,t,n){let r=t.nodeBefore,i=t.nodeAfter,a=t.index();return!r||!i||!r.type.compatibleContent(i.type)?!1:!r.content.size&&t.parent.canReplace(a-1,a)?(n&&n(e.tr.delete(t.pos-r.nodeSize,t.pos).scrollIntoView()),!0):!t.parent.canReplace(a,a+1)||!(i.isTextblock||Lv(e.doc,t.pos))?!1:(n&&n(e.tr.join(t.pos).scrollIntoView()),!0)}function cb(e,t,n,r){let i=t.nodeBefore,a=t.nodeAfter,o,s,c=i.type.spec.isolating||a.type.spec.isolating;if(!c&&sb(e,t,n))return!0;let l=!c&&t.parent.canReplace(t.index(),t.index()+1);if(l&&(o=(s=i.contentMatchAt(i.childCount)).findWrapping(a.type))&&s.matchType(o[0]||a.type).validEnd){if(n){let r=t.pos+a.nodeSize,s=J.empty;for(let e=o.length-1;e>=0;e--)s=J.from(o[e].create(null,s));s=J.from(i.copy(s));let c=e.tr.step(new _v(t.pos-1,r,t.pos,r,new Y(s,1,0),o.length,!0)),l=c.doc.resolve(r+2*o.length);l.nodeAfter&&l.nodeAfter.type==i.type&&Lv(c.doc,l.pos)&&c.join(l.pos),n(c.scrollIntoView())}return!0}let u=a.type.spec.isolating||r>0&&c?null:dy.findFrom(t,1),d=u&&u.$from.blockRange(u.$to),f=d&&Cv(d);if(f!=null&&f>=t.depth)return n&&n(e.tr.lift(d,f).scrollIntoView()),!0;if(l&&Hy(a,`start`,!0)&&Hy(i,`end`)){let r=i,o=[];for(;o.push(r),!r.isTextblock;)r=r.lastChild;let s=a,c=1;for(;!s.isTextblock;s=s.firstChild)c++;if(r.canReplace(r.childCount,r.childCount,s.content)){if(n){let r=J.empty;for(let e=o.length-1;e>=0;e--)r=J.from(o[e].copy(r));n(e.tr.step(new _v(t.pos-o.length,t.pos+a.nodeSize,t.pos+c,t.pos+a.nodeSize-c,new Y(r,o.length,0),0,!0)).scrollIntoView())}return!0}}return!1}function lb(e){return function(t,n){let r=t.selection,i=e<0?r.$from:r.$to,a=i.depth;for(;i.node(a).isInline;){if(!a)return!1;a--}return i.node(a).isTextblock?(n&&n(t.tr.setSelection(hy.create(t.doc,e<0?i.start(a):i.end(a)))),!0):!1}}var ub=lb(-1),db=lb(1);function fb(e,t=null){return function(n,r){let{$from:i,$to:a}=n.selection,o=i.blockRange(a),s=o&&Tv(o,e,t);return s?(r&&r(n.tr.wrap(o,s).scrollIntoView()),!0):!1}}function pb(e,t=null){return function(n,r){let i=!1;for(let r=0;r<n.selection.ranges.length&&!i;r++){let{$from:{pos:a},$to:{pos:o}}=n.selection.ranges[r];n.doc.nodesBetween(a,o,(r,a)=>{if(i)return!1;if(!(!r.isTextblock||r.hasMarkup(e,t)))if(r.type==e)i=!0;else{let t=n.doc.resolve(a),r=t.index();i=t.parent.canReplaceWith(r,r+1,e)}})}if(!i)return!1;if(r){let i=n.tr;for(let r=0;r<n.selection.ranges.length;r++){let{$from:{pos:a},$to:{pos:o}}=n.selection.ranges[r];i.setBlockType(a,o,e,t)}r(i.scrollIntoView())}return!0}}function mb(...e){return function(t,n,r){for(let i=0;i<e.length;i++)if(e[i](t,n,r))return!0;return!1}}var hb=mb(Iy,Ry,Uy),gb=mb(Iy,Ky,qy),_b={Enter:mb(Qy,tb,nb,ib),"Mod-Enter":eb,Backspace:hb,"Mod-Backspace":hb,"Shift-Backspace":hb,Delete:gb,"Mod-Delete":gb,"Mod-a":ob},vb={"Ctrl-h":_b.Backspace,"Alt-Backspace":_b[`Mod-Backspace`],"Ctrl-d":_b.Delete,"Ctrl-Alt-Backspace":_b[`Mod-Delete`],"Alt-Delete":_b[`Mod-Delete`],"Alt-d":_b[`Mod-Delete`],"Ctrl-a":ub,"Ctrl-e":db};for(let e in _b)vb[e]=_b[e];typeof navigator<`u`?/Mac|iP(hone|[oa]d)/.test(navigator.platform):typeof os<`u`&&os.platform&&os.platform();function yb(e,t=null){return function(n,r){let{$from:i,$to:a}=n.selection,o=i.blockRange(a);if(!o)return!1;let s=r?n.tr:null;return bb(s,o,e,t)?(r&&r(s.scrollIntoView()),!0):!1}}function bb(e,t,n,r=null){let i=!1,a=t,o=t.$from.doc;if(t.depth>=2&&t.$from.node(t.depth-1).type.compatibleContent(n)&&t.startIndex==0){if(t.$from.index(t.depth-1)==0)return!1;let e=o.resolve(t.start-2);a=new Qg(e,e,t.depth),t.endIndex<t.parent.childCount&&(t=new Qg(t.$from,o.resolve(t.$to.end(t.depth)),t.depth)),i=!0}let s=Tv(a,n,r,t);return s?(e&&xb(e,t,s,i,n),!0):!1}function xb(e,t,n,r,i){let a=J.empty;for(let e=n.length-1;e>=0;e--)a=J.from(n[e].type.create(n[e].attrs,a));e.step(new _v(t.start-(r?2:0),t.end,t.start,t.end,new Y(a,0,0),n.length,!0));let o=0;for(let e=0;e<n.length;e++)n[e].type==i&&(o=e+1);let s=n.length-o,c=t.start+n.length-(r?2:0),l=t.parent;for(let n=t.startIndex,r=t.endIndex,i=!0;n<r;n++,i=!1)!i&&Fv(e.doc,c,s)&&(e.split(c,s),c+=2*s),c+=l.child(n).nodeSize;return e}function Sb(e){return function(t,n){let{$from:r,$to:i}=t.selection,a=r.blockRange(i,t=>t.childCount>0&&t.firstChild.type==e);return a?n?r.node(a.depth-1).type==e?Cb(t,n,e,a):wb(t,n,a):!0:!1}}function Cb(e,t,n,r){let i=e.tr,a=r.end,o=r.$to.end(r.depth);a<o&&(i.step(new _v(a-1,o,a,o,new Y(J.from(n.create(null,r.parent.copy())),1,0),1,!0)),r=new Qg(i.doc.resolve(r.$from.pos),i.doc.resolve(o),r.depth));let s=Cv(r);if(s==null)return!1;i.lift(r,s);let c=i.doc.resolve(i.mapping.map(a,-1)-1);return Lv(i.doc,c.pos)&&c.nodeBefore.type==c.nodeAfter.type&&i.join(c.pos),t(i.scrollIntoView()),!0}function wb(e,t,n){let r=e.tr,i=n.parent;for(let e=n.end,t=n.endIndex-1,a=n.startIndex;t>a;t--)e-=i.child(t).nodeSize,r.delete(e-1,e+1);let a=r.doc.resolve(n.start),o=a.nodeAfter;if(r.mapping.map(n.end)!=n.start+a.nodeAfter.nodeSize)return!1;let s=n.startIndex==0,c=n.endIndex==i.childCount,l=a.node(-1),u=a.index(-1);if(!l.canReplace(u+ +!s,u+1,o.content.append(c?J.empty:J.from(i))))return!1;let d=a.pos,f=d+o.nodeSize;return r.step(new _v(d-+!!s,f+ +!!c,d+1,f-1,new Y((s?J.empty:J.from(i.copy(J.empty))).append(c?J.empty:J.from(i.copy(J.empty))),+!s,+!c),+!s)),t(r.scrollIntoView()),!0}function Tb(e){return function(t,n){let{$from:r,$to:i}=t.selection,a=r.blockRange(i,t=>t.childCount>0&&t.firstChild.type==e);if(!a)return!1;let o=a.startIndex;if(o==0)return!1;let s=a.parent,c=s.child(o-1);if(c.type!=e)return!1;if(n){let r=c.lastChild&&c.lastChild.type==s.type,i=J.from(r?e.create():null),o=new Y(J.from(e.create(null,J.from(s.type.create(null,i)))),r?3:1,0),l=a.start,u=a.end;n(t.tr.step(new _v(l-(r?3:1),u,l,u,o,1,!0)).scrollIntoView())}return!0}}var Eb=function(e){for(var t=0;;t++)if(e=e.previousSibling,!e)return t},Db=function(e){let t=e.assignedSlot||e.parentNode;return t&&t.nodeType==11?t.host:t},Ob=null,kb=function(e,t,n){let r=Ob||=document.createRange();return r.setEnd(e,n??e.nodeValue.length),r.setStart(e,t||0),r},Ab=function(){Ob=null},jb=function(e,t,n,r){return n&&(Nb(e,t,n,r,-1)||Nb(e,t,n,r,1))},Mb=/^(img|br|input|textarea|hr)$/i;function Nb(e,t,n,r,i){for(;;){if(e==n&&t==r)return!0;if(t==(i<0?0:Pb(e))){let n=e.parentNode;if(!n||!Z(n)||Bb(e)||Mb.test(e.nodeName)||e.contentEditable==`false`)return!1;t=Eb(e)+(i<0?0:1),e=n}else if(Z(e)){let n=e.childNodes[t+(i<0?-1:0)];if(Z(n)&&n.contentEditable==`false`)if(n.pmViewDesc?.ignoreForSelection)t+=i;else return!1;else e=n,t=i<0?Pb(e):0}else return!1}}function Pb(e){return e.nodeType==3?e.nodeValue.length:e.childNodes.length}function Z(e){return e.nodeType==1}function Fb(e){return e.nodeType==3}function Ib(e,t){return t?e.contains(Z(t)?t:t.parentNode):!1}function Lb(e,t){for(;;){if(Fb(e)&&t)return e;if(Z(e)&&t>0){if(e.contentEditable==`false`)return null;e=e.childNodes[t-1],t=Pb(e)}else if(e.parentNode&&!Bb(e))t=Eb(e),e=e.parentNode;else return null}}function Rb(e,t){for(;;){if(Fb(e)&&t<e.nodeValue.length)return e;if(Z(e)&&t<e.childNodes.length){if(e.contentEditable==`false`)return null;e=e.childNodes[t],t=0}else if(e.parentNode&&!Bb(e))t=Eb(e)+1,e=e.parentNode;else return null}}function zb(e,t,n){for(let r=t==0,i=t==Pb(e);r||i;){if(e==n)return!0;let t=Eb(e);if(e=e.parentNode,!e)return!1;r&&=t==0,i&&=t==Pb(e)}}function Bb(e){let t;for(let n=e;n&&!(t=n.pmViewDesc);n=n.parentNode);return t&&t.node&&t.node.isBlock&&(t.dom==e||t.contentDOM==e)}var Vb=function(e){return e.focusNode&&jb(e.focusNode,e.focusOffset,e.anchorNode,e.anchorOffset)};function Hb(e,t){let n=document.createEvent(`Event`);return n.initEvent(`keydown`,!0,!0),n.keyCode=e,n.key=n.code=t,n}function Ub(e){let t=e.activeElement;for(;t&&t.shadowRoot;)t=t.shadowRoot.activeElement;return t}function Wb(e,t,n){if(e.caretPositionFromPoint)try{let r=e.caretPositionFromPoint(t,n);if(r)return{node:r.offsetNode,offset:Math.min(Pb(r.offsetNode),r.offset)}}catch{}if(e.caretRangeFromPoint){let r=e.caretRangeFromPoint(t,n);if(r)return{node:r.startContainer,offset:Math.min(Pb(r.startContainer),r.startOffset)}}}var Gb=typeof navigator<`u`?navigator:null,Kb=typeof document<`u`?document:null,qb=Gb&&Gb.userAgent||``,Jb=/Edge\/(\d+)/.exec(qb),Yb=/MSIE \d/.exec(qb),Xb=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(qb),Zb=!!(Yb||Xb||Jb),Qb=Yb?document.documentMode:Xb?+Xb[1]:Jb?+Jb[1]:0,$b=!Zb&&/gecko\/(\d+)/i.test(qb);$b&&+(/Firefox\/(\d+)/.exec(qb)||[0,0])[1];var ex=!Zb&&/Chrome\/(\d+)/.exec(qb),tx=!!ex,nx=ex?+ex[1]:0,rx=!Zb&&!!Gb&&/Apple Computer/.test(Gb.vendor),ix=rx&&(/Mobile\/\w+/.test(qb)||!!Gb&&Gb.maxTouchPoints>2),ax=ix||(Gb?/Mac/.test(Gb.platform):!1),ox=Gb?/Win/.test(Gb.platform):!1,sx=/Android \d/.test(qb),cx=!!Kb&&`webkitFontSmoothing`in Kb.documentElement.style,lx=cx?+(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent)||[0,0])[1]:0;function ux(e){let t=e.defaultView&&e.defaultView.visualViewport;return t?{left:0,right:t.width,top:0,bottom:t.height}:{left:0,right:e.documentElement.clientWidth,top:0,bottom:e.documentElement.clientHeight}}function dx(e,t){return typeof e==`number`?e:e[t]}function fx(e){let t=e.getBoundingClientRect(),n=t.width/e.offsetWidth||1,r=t.height/e.offsetHeight||1;return{left:t.left,right:t.left+e.clientWidth*n,top:t.top,bottom:t.top+e.clientHeight*r}}function px(e,t,n){if(!Ox(t)&&t.left==0)return;let r=e.someProp(`scrollThreshold`)||0,i=e.someProp(`scrollMargin`)||5,a=e.dom.ownerDocument;for(let o=n||e.dom;o;){if(!Z(o)){o=Db(o);continue}let e=o==a.body,n=e?ux(a):fx(o),s=0,c=0;if(t.top<n.top+dx(r,`top`)?c=-(n.top-t.top+dx(i,`top`)):t.bottom>n.bottom-dx(r,`bottom`)&&(c=t.bottom-t.top>n.bottom-n.top?t.top+dx(i,`top`)-n.top:t.bottom-n.bottom+dx(i,`bottom`)),t.left<n.left+dx(r,`left`)?s=-(n.left-t.left+dx(i,`left`)):t.right>n.right-dx(r,`right`)&&(s=t.right-n.right+dx(i,`right`)),s||c)if(e)a.defaultView.scrollBy(s,c);else{let e=o.scrollLeft,n=o.scrollTop;c&&(o.scrollTop+=c),s&&(o.scrollLeft+=s);let r=o.scrollLeft-e,i=o.scrollTop-n;t={left:t.left-r,top:t.top-i,right:t.right-r,bottom:t.bottom-i}}let l=e?`fixed`:getComputedStyle(o).position;if(/^(fixed|sticky)$/.test(l))break;o=l==`absolute`?o.offsetParent:Db(o)}}function mx(e){let t=e.dom.getBoundingClientRect(),n=Math.max(0,t.top),r,i;for(let a=(t.left+t.right)/2,o=n+1;o<Math.min(innerHeight,t.bottom);o+=5){let t=e.root.elementFromPoint(a,o);if(!t||t==e.dom||!e.dom.contains(t))continue;let s=t.getBoundingClientRect();if(s.top>=n-20){r=t,i=s.top;break}}return{refDOM:r,refTop:i,stack:hx(e.dom)}}function hx(e){let t=[],n=e.ownerDocument;for(let r=e;r&&(t.push({dom:r,top:r.scrollTop,left:r.scrollLeft}),e!=n);r=Db(r));return t}function gx({refDOM:e,refTop:t,stack:n}){let r=e?e.getBoundingClientRect().top:0;_x(n,r==0?0:r-t)}function _x(e,t){for(let n=0;n<e.length;n++){let{dom:r,top:i,left:a}=e[n];r.scrollTop!=i+t&&(r.scrollTop=i+t),r.scrollLeft!=a&&(r.scrollLeft=a)}}var vx=null;function yx(e){if(e.setActive)return e.setActive();if(vx)return e.focus(vx);let t=hx(e);e.focus(vx==null?{get preventScroll(){return vx={preventScroll:!0},!0}}:void 0),vx||(vx=!1,_x(t,0))}function bx(e,t){let n,r=2e8,i,a=0,o=t.top,s=t.top,c,l;for(let u=e.firstChild,d=0;u;u=u.nextSibling,d++){let e;if(Z(u))e=u.getClientRects();else if(Fb(u))e=kb(u).getClientRects();else continue;for(let f=0;f<e.length;f++){let p=e[f];if(p.top<=o&&p.bottom>=s){o=Math.max(p.bottom,o),s=Math.min(p.top,s);let e=p.left>t.left?p.left-t.left:p.right<t.left?t.left-p.right:0;if(e<r){n=u,r=e,i=e&&Fb(n)?{left:p.right<t.left?p.right:p.left,top:t.top}:t,Z(u)&&e&&(a=d+ +(t.left>=(p.left+p.right)/2));continue}}else p.top>t.top&&!c&&p.left<=t.left&&p.right>=t.left&&(c=u,l={left:Math.max(p.left,Math.min(p.right,t.left)),top:p.top});!n&&(t.left>=p.right&&t.top>=p.top||t.left>=p.left&&t.top>=p.bottom)&&(a=d+1)}}return!n&&c&&(n=c,i=l,r=0),n&&Fb(n)?xx(n,i):!n||r?{node:e,offset:a}:bx(n,i)}function xx(e,t){let n=e.nodeValue.length,r=document.createRange(),i;for(let a=0;a<n;a++){r.setEnd(e,a+1),r.setStart(e,a);let n=kx(r,1);if(n.top!=n.bottom&&Sx(t,n)){i={node:e,offset:a+ +(t.left>=(n.left+n.right)/2)};break}}return r.detach(),i||{node:e,offset:0}}function Sx(e,t){return e.left>=t.left-1&&e.left<=t.right+1&&e.top>=t.top-1&&e.top<=t.bottom+1}function Cx(e,t){let n=e.parentNode;return n&&/^li$/i.test(n.nodeName)&&t.left<e.getBoundingClientRect().left?n:e}function wx(e,t,n){let{node:r,offset:i}=bx(t,n),a=-1;if(Z(r)&&!r.firstChild){let e=r.getBoundingClientRect();a=e.left!=e.right&&n.left>(e.left+e.right)/2?1:-1}return e.docView.posFromDOM(r,i,a)}function Tx(e,t,n,r){let i=-1;for(let n=t,a=!1;n!=e.dom;){let t=e.docView.nearestDesc(n,!0),o;if(!t)return null;if(Z(t.dom)&&(t.node.isBlock&&t.parent||!t.contentDOM)&&((o=t.dom.getBoundingClientRect()).width||o.height)&&(t.node.isBlock&&t.parent&&!/^T(R|BODY|HEAD|FOOT)$/.test(t.dom.nodeName)&&(!a&&o.left>r.left||o.top>r.top?i=t.posBefore:(!a&&o.right<r.left||o.bottom<r.top)&&(i=t.posAfter),a=!0),!t.contentDOM&&i<0&&!t.node.isText))return(t.node.isBlock?r.top<(o.top+o.bottom)/2:r.left<(o.left+o.right)/2)?t.posBefore:t.posAfter;n=t.dom.parentNode}return i>-1?i:e.docView.posFromDOM(t,n,-1)}function Ex(e,t,n){let r=e.childNodes.length;if(r&&n.top<n.bottom)for(let i=Math.max(0,Math.min(r-1,Math.floor(r*(t.top-n.top)/(n.bottom-n.top))-2)),a=i;;){let n=e.childNodes[a];if(Z(n)){let e=n.getClientRects();for(let r=0;r<e.length;r++){let i=e[r];if(Sx(t,i))return Ex(n,t,i)}}if((a=(a+1)%r)==i)break}return e}function Dx(e,t){let n=e.dom.ownerDocument,r,i=0,a=Wb(n,t.left,t.top);a&&({node:r,offset:i}=a);let o=(e.root.elementFromPoint?e.root:n).elementFromPoint(t.left,t.top),s;if(!o||!e.dom.contains(o)){let n=e.dom.getBoundingClientRect();if(!Sx(t,n)||(o=Ex(e.dom,t,n),!o))return null}if(rx)for(let e=o;r&&e;e=Db(e))e.draggable&&(r=void 0);if(o=Cx(o,t),r){if($b&&Z(r)&&(i=Math.min(i,r.childNodes.length),i<r.childNodes.length)){let e=r.childNodes[i],n;e.nodeName==`IMG`&&(n=e.getBoundingClientRect()).right<=t.left&&n.bottom>t.top&&i++}let n;cx&&i&&Z(r)&&Z(n=r.childNodes[i-1])&&n.contentEditable==`false`&&n.getBoundingClientRect().top>=t.top&&i--,r==e.dom&&i==r.childNodes.length-1&&Z(r.lastChild)&&t.top>r.lastChild.getBoundingClientRect().bottom?s=e.state.doc.content.size:(i==0||!Z(r)||r.childNodes[i-1].nodeName!=`BR`)&&(s=Tx(e,r,i,t))}s??=wx(e,o,t);let c=e.docView.nearestDesc(o,!0);return{pos:s,inside:c?c.posAtStart-c.border:-1}}function Ox(e){return e.top<e.bottom||e.left<e.right}function kx(e,t){let n=e.getClientRects();if(n.length){let e=n[t<0?0:n.length-1];if(Ox(e))return e}return Array.prototype.find.call(n,Ox)||e.getBoundingClientRect()}var Ax=/[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac]/;function jx(e,t,n){let{node:r,offset:i,atom:a}=e.docView.domFromPos(t,n<0?-1:1),o=cx||$b;if(Fb(r))if(o&&(Ax.test(r.nodeValue)||(n<0?!i:i==r.nodeValue.length))){let e=kx(kb(r,i,i),n);if($b&&i&&/\s/.test(r.nodeValue[i-1])&&i<r.nodeValue.length){let t=kx(kb(r,i-1,i-1),-1);if(t.top==e.top){let n=kx(kb(r,i,i+1),-1);if(n.top!=e.top)return Mx(n,n.left<t.left)}}return e}else{let e=i,t=i,a=n<0?1:-1;return n<0&&!i?(t++,a=-1):n>=0&&i==r.nodeValue.length?(e--,a=1):n<0?e--:t++,Mx(kx(kb(r,e,t),a),a<0)}if(!e.state.doc.resolve(t-(a||0)).parent.inlineContent){if(a==null&&i&&(n<0||i==Pb(r))){let e=r.childNodes[i-1];if(Z(e))return Nx(e.getBoundingClientRect(),!1)}if(a==null&&i<Pb(r)){let e=r.childNodes[i];if(Z(e))return Nx(e.getBoundingClientRect(),!0)}return Nx(r.getBoundingClientRect(),n>=0)}if(a==null&&i&&(n<0||i==Pb(r))){let e=r.childNodes[i-1],t=Fb(e)?kb(e,Pb(e)-+!o):Z(e)&&(e.nodeName!=`BR`||!e.nextSibling)?e:null;if(t)return Mx(kx(t,1),!1)}if(a==null&&i<Pb(r)){let e=r.childNodes[i];for(;e.pmViewDesc&&e.pmViewDesc.ignoreForCoords;)e=e.nextSibling;let t=e?Fb(e)?kb(e,0,+!o):Z(e)?e:null:null;if(t)return Mx(kx(t,-1),!0)}return Mx(kx(Fb(r)?kb(r):r,-n),n>=0)}function Mx(e,t){if(e.width==0)return e;let n=t?e.left:e.right;return{top:e.top,bottom:e.bottom,left:n,right:n}}function Nx(e,t){if(e.height==0)return e;let n=t?e.top:e.bottom;return{top:n,bottom:n,left:e.left,right:e.right}}function Px(e,t,n){let r=e.state,i=e.root.activeElement;r!=t&&e.updateState(t),i!=e.dom&&e.focus();try{return n()}finally{r!=t&&e.updateState(r),i!=e.dom&&i&&i.focus()}}function Fx(e,t,n){let r=t.selection,i=n==`up`?r.$from:r.$to;return Px(e,t,()=>{let{node:t}=e.docView.domFromPos(i.pos,n==`up`?-1:1);for(;;){let n=e.docView.nearestDesc(t,!0);if(!n)break;if(n.node.isBlock){t=n.contentDOM||n.dom;break}t=n.dom.parentNode}let r=jx(e,i.pos,1);for(let e=t.firstChild;e;e=e.nextSibling){let t;if(Z(e))t=e.getClientRects();else if(Fb(e))t=kb(e,0,e.nodeValue.length).getClientRects();else continue;for(let e=0;e<t.length;e++){let i=t[e];if(i.bottom>i.top+1&&(n==`up`?r.top-i.top>(i.bottom-r.top)*2:i.bottom-r.bottom>(r.bottom-i.top)*2))return!1}}return!0})}var Ix=/[\u0590-\u08ac]/;function Lx(e,t,n){let{$head:r}=t.selection;if(!r.parent.isTextblock)return!1;let i=r.parentOffset,a=!i,o=i==r.parent.content.size,s=e.domSelection();return s?!Ix.test(r.parent.textContent)||!s.modify?n==`left`||n==`backward`?a:o:Px(e,t,()=>{let{focusNode:t,focusOffset:i,anchorNode:a,anchorOffset:o}=e.domSelectionRange(),c=s.caretBidiLevel;s.modify(`move`,n,`character`);let l=r.depth?e.docView.domAfterPos(r.before()):e.dom,{focusNode:u,focusOffset:d}=e.domSelectionRange(),f=u&&!Ib(l,u)||t==u&&i==d;try{s.collapse(a,o),t&&(t!=a||i!=o)&&s.extend&&s.extend(t,i)}catch{}return c!=null&&(s.caretBidiLevel=c),f}):r.pos==r.start()||r.pos==r.end()}var Rx=null,zx=null,Bx=!1;function Vx(e,t,n){return Rx==t&&zx==n?Bx:(Rx=t,zx=n,Bx=n==`up`||n==`down`?Fx(e,t,n):Lx(e,t,n))}var Hx=0,Ux=1,Wx=2,Gx=3,Kx=class{constructor(e,t,n,r){this.parent=e,this.children=t,this.dom=n,this.contentDOM=r,this.dirty=Hx,n.pmViewDesc=this}matchesWidget(e){return!1}matchesMark(e){return!1}matchesNode(e,t,n){return!1}matchesHack(e){return!1}parseRule(e){return null}stopEvent(e){return!1}get size(){let e=0;for(let t=0;t<this.children.length;t++)e+=this.children[t].size;return e}get border(){return 0}destroy(){this.parent=void 0,this.dom.pmViewDesc==this&&(this.dom.pmViewDesc=void 0);for(let e=0;e<this.children.length;e++)this.children[e].destroy()}posBeforeChild(e){for(let t=0,n=this.posAtStart;;t++){let r=this.children[t];if(r==e)return n;n+=r.size}}get posBefore(){return this.parent.posBeforeChild(this)}get posAtStart(){return this.parent?this.parent.posBeforeChild(this)+this.border:0}get posAfter(){return this.posBefore+this.size}get posAtEnd(){return this.posAtStart+this.size-2*this.border}localPosFromDOM(e,t,n){if(this.contentDOM&&Ib(this.contentDOM,e))if(n<0){let n,r;if(e==this.contentDOM)n=e.childNodes[t-1];else{for(;e.parentNode!=this.contentDOM;)e=e.parentNode;n=e.previousSibling}for(;n&&!((r=n.pmViewDesc)&&r.parent==this);)n=n.previousSibling;return n?this.posBeforeChild(r)+r.size:this.posAtStart}else{let n,r;if(e==this.contentDOM)n=e.childNodes[t];else{for(;e.parentNode!=this.contentDOM;)e=e.parentNode;n=e.nextSibling}for(;n&&!((r=n.pmViewDesc)&&r.parent==this);)n=n.nextSibling;return n?this.posBeforeChild(r):this.posAtEnd}let r;if(e==this.dom&&this.contentDOM)r=t>Eb(this.contentDOM);else if(this.contentDOM&&this.contentDOM!=this.dom&&this.dom.contains(this.contentDOM))r=!!(e.compareDocumentPosition(this.contentDOM)&4);else if(this.dom.firstChild){if(t==0)for(let t=e;;t=t.parentNode){if(t==this.dom){r=!1;break}if(t.previousSibling)break}if(r==null&&t==e.childNodes.length)for(let t=e;;t=t.parentNode){if(t==this.dom){r=!0;break}if(t.nextSibling)break}}return r??n>0?this.posAtEnd:this.posAtStart}nearestDesc(e,t=!1){for(let n=!0,r=e;r;r=r.parentNode){let i=this.getDesc(r),a;if(i&&(!t||i.node))if(n&&(a=i.nodeDOM)&&!(Z(a)?Ib(a,e):a==e))n=!1;else return i}}getDesc(e){let t=e.pmViewDesc;for(let e=t;e;e=e.parent)if(e==this)return t}posFromDOM(e,t,n){for(let r=e;r;r=r.parentNode){let i=this.getDesc(r);if(i)return i.localPosFromDOM(e,t,n)}return-1}descAt(e){for(let t=0,n=0;t<this.children.length;t++){let r=this.children[t],i=n+r.size;if(n==e&&i!=n){for(;!r.border&&r.children.length;)for(let e=0;e<r.children.length;e++){let t=r.children[e];if(t.size){r=t;break}}return r}if(e<i)return r.descAt(e-n-r.border);n=i}}domFromPos(e,t){if(!this.contentDOM)return{node:this.dom,offset:0,atom:e+1};let n=0,r=0;for(let t=0;n<this.children.length;n++){let i=this.children[n],a=t+i.size;if(a>e){r=e-t;break}t=a}if(r)return this.children[n].domFromPos(r-this.children[n].border,t);for(;n>0;n--){let e=this.children[n-1];if(e.size||!(e instanceof $x||e instanceof qx&&e.side>=0))break}if(t<=0){let e,r=!0;for(;e=n?this.children[n-1]:null,!(!e||e.dom.parentNode==this.contentDOM);n--,r=!1);return e&&t&&r&&!e.border&&!e.domAtom?e.domFromPos(e.size,t):{node:this.contentDOM,offset:e?Eb(e.dom)+1:0}}else{let e,r=!0;for(;e=n<this.children.length?this.children[n]:null,!(!e||e.dom.parentNode==this.contentDOM);n++,r=!1);return e&&r&&!e.border&&!e.domAtom?e.domFromPos(0,t):{node:this.contentDOM,offset:e?Eb(e.dom):this.contentDOM.childNodes.length}}}parseRange(e,t,n=0){if(this.children.length==0)return{node:this.contentDOM,from:e,to:t,fromOffset:0,toOffset:this.contentDOM.childNodes.length};let r=-1,i=-1;for(let a=n,o=0;;o++){let n=this.children[o],s=a+n.size;if(r==-1&&e<=s){let i=a+n.border;if(e>=i&&t<=s-n.border&&n.node&&n.contentDOM&&this.contentDOM.contains(n.contentDOM))return n.parseRange(e,t,i);e=a;for(let t=o;t>0;t--){let n=this.children[t-1];if(n.size&&n.dom.parentNode==this.contentDOM&&!n.emptyChildAt(1)){r=Eb(n.dom)+1;break}e-=n.size}r==-1&&(r=0)}if(r>-1&&(s>t||o==this.children.length-1)){t=s;for(let e=o+1;e<this.children.length;e++){let n=this.children[e];if(n.size&&n.dom.parentNode==this.contentDOM&&!n.emptyChildAt(-1)){i=Eb(n.dom);break}t+=n.size}i==-1&&(i=this.contentDOM.childNodes.length);break}a=s}return{node:this.contentDOM,from:e,to:t,fromOffset:r,toOffset:i}}emptyChildAt(e){if(this.border||!this.contentDOM||!this.children.length)return!1;let t=this.children[e<0?0:this.children.length-1];return t.size==0||t.emptyChildAt(e)}domAfterPos(e){let{node:t,offset:n}=this.domFromPos(e,0);if(!Z(t)||n==t.childNodes.length)throw RangeError(`No node after pos `+e);return t.childNodes[n]}setSelection(e,t,n,r=!1){let i=Math.min(e,t),a=Math.max(e,t);for(let o=0,s=0;o<this.children.length;o++){let c=this.children[o],l=s+c.size;if(i>s&&a<l)return c.setSelection(e-s-c.border,t-s-c.border,n,r);s=l}let o=this.domFromPos(e,e?-1:1),s=t==e?o:this.domFromPos(t,t?-1:1),c=n.root.getSelection(),l=n.domSelectionRange(),u=!1;if(($b||rx)&&e==t){let{node:e,offset:t}=o;if(Fb(e)){if(u=!!(t&&e.nodeValue[t-1]==`
|
|
14
|
+
`),u&&t==e.nodeValue.length)for(let t=e,n;t;t=t.parentNode){if(n=t.nextSibling){n.nodeName==`BR`&&(o=s={node:n.parentNode,offset:Eb(n)+1});break}let e=t.pmViewDesc;if(e&&e.node&&e.node.isBlock)break}}else{let n=e.childNodes[t-1];u=n&&(n.nodeName==`BR`||n.contentEditable==`false`)}}if($b&&l.focusNode&&l.focusNode!=s.node&&Z(l.focusNode)){let e=l.focusNode.childNodes[l.focusOffset];e&&e.contentEditable==`false`&&(r=!0)}if(!(r||u&&rx)&&jb(o.node,o.offset,l.anchorNode,l.anchorOffset)&&jb(s.node,s.offset,l.focusNode,l.focusOffset))return;let d=!1;if((c.extend||e==t)&&!(u&&$b)){c.collapse(o.node,o.offset);try{e!=t&&c.extend(s.node,s.offset),d=!0}catch{}}if(!d){if(e>t){let e=o;o=s,s=e}let n=document.createRange();n.setEnd(s.node,s.offset),n.setStart(o.node,o.offset),c.removeAllRanges(),c.addRange(n)}}ignoreMutation(e){return!this.contentDOM&&e.type!=`selection`}get contentLost(){return this.contentDOM&&this.contentDOM!=this.dom&&!this.dom.contains(this.contentDOM)}markDirty(e,t){for(let n=0,r=0;r<this.children.length;r++){let i=this.children[r],a=n+i.size;if(n==a?e<=a&&t>=n:e<a&&t>n){let r=n+i.border,o=a-i.border;if(e>=r&&t<=o){this.dirty=e==n||t==a?Wx:Ux,e==r&&t==o&&(i.contentLost||i.dom.parentNode!=this.contentDOM)?i.dirty=Gx:i.markDirty(e-r,t-r);return}else i.dirty=i.dom==i.contentDOM&&i.dom.parentNode==this.contentDOM&&!i.children.length?Wx:Gx}n=a}this.dirty=Wx}markParentsDirty(){let e=1;for(let t=this.parent;t;t=t.parent,e++){let n=e==1?Wx:Ux;t.dirty<n&&(t.dirty=n)}}get domAtom(){return!1}get ignoreForCoords(){return!1}get ignoreForSelection(){return!1}isText(e){return!1}},qx=class extends Kx{constructor(e,t,n,r){let i,a=t.type.toDOM;if(typeof a==`function`&&(a=a(n,()=>{if(!i)return r;if(i.parent)return i.parent.posBeforeChild(i)})),!t.type.spec.raw){let e=Z(a)?a:document.createElement(`span`);e!=a&&e.appendChild(a),e.hasAttribute(`contenteditable`)||(e.contentEditable=`false`),e.classList.add(`ProseMirror-widget`)}super(e,[],a,null),this.widget=t,this.widget=t,i=this}matchesWidget(e){return this.dirty==Hx&&e.type.eq(this.widget.type)}parseRule(){return{ignore:!0}}stopEvent(e){let t=this.widget.spec.stopEvent;return t?t(e):!1}ignoreMutation(e){return e.type!=`selection`||this.widget.spec.ignoreSelection}destroy(){this.widget.type.destroy(this.dom),super.destroy()}get domAtom(){return!0}get ignoreForSelection(){return!!this.widget.type.spec.relaxedSide}get side(){return this.widget.type.side}},Jx=class extends Kx{constructor(e,t,n,r){super(e,[],t,null),this.textDOM=n,this.text=r}get size(){return this.text.length}localPosFromDOM(e,t){return e==this.textDOM?this.posAtStart+t:this.posAtStart+(t?this.size:0)}domFromPos(e){return{node:this.textDOM,offset:e}}ignoreMutation(e){return e.type===`characterData`&&e.target.nodeValue==e.oldValue}},Yx=class e extends Kx{constructor(e,t,n,r,i){super(e,[],n,r),this.mark=t,this.spec=i}static create(t,n,r,i){let a=i.nodeViews[n.type.name],o=a&&a(n,i,r);return(!o||!o.dom)&&(o=U_.renderSpec(document,n.type.spec.toDOM(n,r),null,n.attrs)),new e(t,n,o.dom,o.contentDOM||o.dom,o)}parseRule(){return this.dirty&Gx||this.mark.type.spec.reparseInView?null:{mark:this.mark.type.name,attrs:this.mark.attrs,contentElement:this.contentDOM}}matchesMark(e){return this.dirty!=Gx&&this.mark.eq(e)}markDirty(e,t){if(super.markDirty(e,t),this.dirty!=Hx){let e=this.parent;for(;!e.node;)e=e.parent;e.dirty<this.dirty&&(e.dirty=this.dirty),this.dirty=Hx}}slice(t,n,r){let i=e.create(this.parent,this.mark,!0,r),a=this.children,o=this.size;n<o&&(a=gS(a,n,o,r)),t>0&&(a=gS(a,0,t,r));for(let e=0;e<a.length;e++)a[e].parent=i;return i.children=a,i}ignoreMutation(e){return this.spec.ignoreMutation?this.spec.ignoreMutation(e):super.ignoreMutation(e)}destroy(){this.spec.destroy&&this.spec.destroy(),super.destroy()}},Xx=class e extends Kx{constructor(e,t,n,r,i,a,o){super(e,[],i,a),this.node=t,this.outerDeco=n,this.innerDeco=r,this.nodeDOM=o}static create(t,n,r,i,a,o){let s=a.nodeViews[n.type.name],c,l=s&&s(n,a,()=>{if(!c)return o;if(c.parent)return c.parent.posBeforeChild(c)},r,i),u=l&&l.dom,d=l&&l.contentDOM;if(n.isText){if(!u)u=document.createTextNode(n.text);else if(!Fb(u))throw RangeError(`Text must be rendered as a DOM text node`)}else if(!u){let e=U_.renderSpec(document,n.type.spec.toDOM(n),null,n.attrs);({dom:u,contentDOM:d}=e)}!d&&!n.isText&&u.nodeName!=`BR`&&(u.hasAttribute(`contenteditable`)||(u.contentEditable=`false`),n.type.spec.draggable&&(u.draggable=!0));let f=u;return u=sS(u,r,n),l?c=new eS(t,n,r,i,u,d||null,f,l):n.isText?new Qx(t,n,r,i,u,f):new e(t,n,r,i,u,d||null,f)}parseRule(e){if(this.node.type.spec.reparseInView)return null;let t={node:this.node.type.name,attrs:this.node.attrs};if(this.node.type.whitespace==`pre`&&(t.preserveWhitespace=`full`),!this.contentDOM)t.getContent=()=>this.node.content;else if(!this.contentLost)t.contentElement=this.contentDOM;else{for(let e=this.children.length-1;e>=0;e--){let n=this.children[e];if(this.dom.contains(n.dom.parentNode)){t.contentElement=n.dom.parentNode;break}}if(!t.contentElement){let n=e&&e.find(t=>Z(t)&&e.indexOf(t.parentNode)<0&&this.dom.contains(t));n?t.contentElement=n:t.getContent=()=>J.empty}}return t}matchesNode(e,t,n){return this.dirty==Hx&&e.eq(this.node)&&cS(t,this.outerDeco)&&n.eq(this.innerDeco)}get size(){return this.node.nodeSize}get border(){return+!this.node.isLeaf}updateChildren(e,t){let n=this.node.inlineContent,r=t,i=e.composing?this.localCompositionInfo(e,t):null,a=i&&i.pos>-1?i:null,o=i&&i.pos<0,s=new uS(this,a&&a.node,e),c=this.node.inlineContent,l=c&&this.node.isBlock;pS(this.node,this.innerDeco,(t,i,a)=>{t.spec.marks?s.syncToMarks(t.spec.marks,n,e,i):t.type.side>=0&&!a&&s.syncToMarks(i==this.node.childCount?Pg.none:this.node.child(i).marks,n,e,i),s.placeWidget(t,e,r)},(t,a,u,d)=>{s.syncToMarks(t.marks,n,e,d),l&&t.isAtom&&!t.isText&&s.addHackNode(`IMG`,s.top);let f;s.findNodeMatch(t,a,u,d)||o&&e.state.selection.from>r&&e.state.selection.to<r+t.nodeSize&&(f=s.findIndexWithChild(i.node))>-1&&s.updateNodeAt(t,a,u,f,e)||s.updateNextNode(t,a,u,e,d,r)||s.addNode(t,a,u,e,r),r+=t.nodeSize,c&&(l=t.isAtom&&!t.isText)}),s.syncToMarks([],n,e,0),this.node.isTextblock&&s.addTextblockHacks(),s.destroyRest(),(s.changed||this.dirty==Wx)&&(a&&this.protectLocalComposition(e,a),tS(this.contentDOM,this.children,e),ix&&mS(this.dom))}localCompositionInfo(e,t){let{from:n,to:r}=e.state.selection;if(!(e.state.selection instanceof hy)||n<t||r>t+this.node.content.size)return null;let i=e.input.compositionNode;if(!i||!this.dom.contains(i.parentNode))return null;if(this.node.inlineContent){let e=i.nodeValue,a=hS(this.node.content,e,n-t,r-t);return a<0?null:{node:i,pos:a,text:e}}else return{node:i,pos:-1,text:``}}protectLocalComposition(e,{node:t,pos:n,text:r}){if(this.getDesc(t))return;let i=t;for(;i.parentNode!=this.contentDOM;i=i.parentNode){for(;i.previousSibling;)i.parentNode.removeChild(i.previousSibling);for(;i.nextSibling;)i.parentNode.removeChild(i.nextSibling);i.pmViewDesc&&=void 0}let a=new Jx(this,i,t,r);e.input.compositionNodes.push(a),this.children=gS(this.children,n,n+r.length,e,a)}update(e,t,n,r){return this.dirty==Gx||!e.sameMarkup(this.node)?!1:(this.updateInner(e,t,n,r),!0)}updateInner(e,t,n,r){this.updateOuterDeco(t),this.node=e,this.innerDeco=n,this.contentDOM&&this.updateChildren(r,this.posAtStart),this.dirty=Hx}updateOuterDeco(e){if(cS(e,this.outerDeco))return;let t=!Z(this.nodeDOM),n=this.dom;this.dom=aS(this.dom,this.nodeDOM,iS(this.outerDeco,this.node,t),iS(e,this.node,t)),this.dom!=n&&(n.pmViewDesc=void 0,this.dom.pmViewDesc=this),this.outerDeco=e}selectNode(){Z(this.nodeDOM)&&(this.nodeDOM.classList.add(`ProseMirror-selectednode`),(this.contentDOM||!this.node.type.spec.draggable)&&(this.nodeDOM.draggable=!0))}deselectNode(){Z(this.nodeDOM)&&(this.nodeDOM.classList.remove(`ProseMirror-selectednode`),(this.contentDOM||!this.node.type.spec.draggable)&&this.nodeDOM.removeAttribute(`draggable`))}get domAtom(){return this.node.isAtom}};function Zx(e,t,n,r,i){sS(r,t,e);let a=new Xx(void 0,e,t,n,r,r,r);return a.contentDOM&&a.updateChildren(i,0),a}var Qx=class e extends Xx{constructor(e,t,n,r,i,a){super(e,t,n,r,i,null,a)}parseRule(){let e=this.nodeDOM.parentNode;for(;e&&e!=this.dom&&!e.pmIsDeco;)e=e.parentNode;return{skip:e||!0}}update(e,t,n,r){return this.dirty==Gx||this.dirty!=Hx&&!this.inParent()||!e.sameMarkup(this.node)?!1:(this.updateOuterDeco(t),(this.dirty!=Hx||e.text!=this.node.text)&&e.text!=this.nodeDOM.nodeValue&&(this.nodeDOM.nodeValue=e.text,r.trackWrites==this.nodeDOM&&(r.trackWrites=null)),this.node=e,this.dirty=Hx,!0)}inParent(){let e=this.parent.contentDOM;for(let t=this.nodeDOM;t;t=t.parentNode)if(t==e)return!0;return!1}domFromPos(e){return{node:this.nodeDOM,offset:e}}localPosFromDOM(e,t,n){return e==this.nodeDOM?this.posAtStart+Math.min(t,this.node.text.length):super.localPosFromDOM(e,t,n)}ignoreMutation(e){return e.type!=`characterData`&&e.type!=`selection`}slice(t,n,r){let i=this.node.cut(t,n),a=document.createTextNode(i.text);return new e(this.parent,i,this.outerDeco,this.innerDeco,a,a)}markDirty(e,t){super.markDirty(e,t),this.dom!=this.nodeDOM&&(e==0||t==this.nodeDOM.nodeValue.length)&&(this.dirty=Gx)}get domAtom(){return!1}isText(e){return this.node.text==e}},$x=class extends Kx{parseRule(){return{ignore:!0}}matchesHack(e){return this.dirty==Hx&&this.dom.nodeName==e}get domAtom(){return!0}get ignoreForCoords(){return this.dom.nodeName==`IMG`}},eS=class extends Xx{constructor(e,t,n,r,i,a,o,s){super(e,t,n,r,i,a,o),this.spec=s}update(e,t,n,r){if(this.dirty==Gx)return!1;if(this.spec.update&&(this.node.type==e.type||this.spec.multiType)){let i=this.spec.update(e,t,n);return i&&this.updateInner(e,t,n,r),i}else if(!this.contentDOM&&!e.isLeaf)return!1;else return super.update(e,t,n,r)}selectNode(){this.spec.selectNode?this.spec.selectNode():super.selectNode()}deselectNode(){this.spec.deselectNode?this.spec.deselectNode():super.deselectNode()}setSelection(e,t,n,r){this.spec.setSelection?this.spec.setSelection(e,t,n.root):super.setSelection(e,t,n,r)}destroy(){this.spec.destroy&&this.spec.destroy(),super.destroy()}stopEvent(e){return this.spec.stopEvent?this.spec.stopEvent(e):!1}ignoreMutation(e){return this.spec.ignoreMutation?this.spec.ignoreMutation(e):super.ignoreMutation(e)}};function tS(e,t,n){let r=e.firstChild,i=!1;for(let a=0;a<t.length;a++){let o=t[a],s=o.dom;if(s.parentNode==e){for(;s!=r;)r=lS(r),i=!0;r=r.nextSibling}else i=!0,e.insertBefore(s,r);if(o instanceof Yx){let t=r?r.previousSibling:e.lastChild;tS(o.contentDOM,o.children,n),r=t?t.nextSibling:e.firstChild}}for(;r;)r=lS(r),i=!0;i&&n.trackWrites==e&&(n.trackWrites=null)}var nS=function(e){e&&(this.nodeName=e)};nS.prototype=Object.create(null);var rS=[new nS];function iS(e,t,n){if(e.length==0)return rS;let r=n?rS[0]:new nS,i=[r];for(let a=0;a<e.length;a++){let o=e[a].type.attrs;if(o){o.nodeName&&i.push(r=new nS(o.nodeName));for(let e in o){let a=o[e];a!=null&&(n&&i.length==1&&i.push(r=new nS(t.isInline?`span`:`div`)),e==`class`?r.class=(r.class?r.class+` `:``)+a:e==`style`?r.style=(r.style?r.style+`;`:``)+a:e!=`nodeName`&&(r[e]=a))}}}return i}function aS(e,t,n,r){if(n==rS&&r==rS)return t;let i=t;for(let t=0;t<r.length;t++){let a=r[t],o=n[t];if(t){let t;o&&o.nodeName==a.nodeName&&i!=e&&(t=i.parentNode)&&t.nodeName.toLowerCase()==a.nodeName?i=t:(t=document.createElement(a.nodeName),t.pmIsDeco=!0,t.appendChild(i),o=rS[0],i=t)}oS(i,o||rS[0],a)}return i}function oS(e,t,n){for(let r in t)r!=`class`&&r!=`style`&&r!=`nodeName`&&!(r in n)&&e.removeAttribute(r);for(let r in n)r!=`class`&&r!=`style`&&r!=`nodeName`&&n[r]!=t[r]&&e.setAttribute(r,n[r]);if(t.class!=n.class){let r=t.class?t.class.split(` `).filter(Boolean):[],i=n.class?n.class.split(` `).filter(Boolean):[];for(let t=0;t<r.length;t++)i.indexOf(r[t])==-1&&e.classList.remove(r[t]);for(let t=0;t<i.length;t++)r.indexOf(i[t])==-1&&e.classList.add(i[t]);e.classList.length==0&&e.removeAttribute(`class`)}if(t.style!=n.style){if(t.style){let n=/\s*([\w\-\xa1-\uffff]+)\s*:(?:"(?:\\.|[^"])*"|'(?:\\.|[^'])*'|\(.*?\)|[^;])*/g,r;for(;r=n.exec(t.style);)e.style.removeProperty(r[1])}n.style&&(e.style.cssText+=n.style)}}function sS(e,t,n){return aS(e,e,rS,iS(t,n,!Z(e)))}function cS(e,t){if(e.length!=t.length)return!1;for(let n=0;n<e.length;n++)if(!e[n].type.eq(t[n].type))return!1;return!0}function lS(e){let t=e.nextSibling;return e.parentNode.removeChild(e),t}var uS=class{constructor(e,t,n){this.lock=t,this.view=n,this.index=0,this.stack=[],this.changed=!1,this.top=e,this.preMatch=dS(e.node.content,e)}destroyBetween(e,t){if(e!=t){for(let n=e;n<t;n++)this.top.children[n].destroy();this.top.children.splice(e,t-e),this.changed=!0}}destroyRest(){this.destroyBetween(this.index,this.top.children.length)}syncToMarks(e,t,n,r){let i=0,a=this.stack.length>>1,o=Math.min(a,e.length);for(;i<o&&(i==a-1?this.top:this.stack[i+1<<1]).matchesMark(e[i])&&e[i].type.spec.spanning!==!1;)i++;for(;i<a;)this.destroyRest(),this.top.dirty=Hx,this.index=this.stack.pop(),this.top=this.stack.pop(),a--;for(;a<e.length;){this.stack.push(this.top,this.index+1);let i=-1,o=this.top.children.length;r<this.preMatch.index&&(o=Math.min(this.index+3,o));for(let t=this.index;t<o;t++){let n=this.top.children[t];if(n.matchesMark(e[a])&&!this.isLocked(n.dom)){i=t;break}}if(i<0&&this.index<this.top.children.length){let t=this.top.children[this.index];t instanceof Yx&&t.dirty!=Gx&&t.mark.type==e[a].type&&t.spec.update&&!this.isLocked(t.dom)&&t.spec.update(e[a])&&(t.mark=e[a],i=this.index,this.changed=!0)}if(i>-1)i>this.index&&(this.changed=!0,this.destroyBetween(this.index,i)),this.top=this.top.children[this.index];else{let r=Yx.create(this.top,e[a],t,n);this.top.children.splice(this.index,0,r),this.top=r,this.changed=!0}this.index=0,a++}}findNodeMatch(e,t,n,r){let i=-1,a;if(r>=this.preMatch.index&&(a=this.preMatch.matches[r-this.preMatch.index]).parent==this.top&&a.matchesNode(e,t,n))i=this.top.children.indexOf(a,this.index);else for(let r=this.index,a=Math.min(this.top.children.length,r+5);r<a;r++){let a=this.top.children[r];if(a.matchesNode(e,t,n)&&!this.preMatch.matched.has(a)){i=r;break}}return i<0?!1:(this.destroyBetween(this.index,i),this.index++,!0)}updateNodeAt(e,t,n,r,i){let a=this.top.children[r];return a.dirty==Gx&&a.dom==a.contentDOM&&(a.dirty=Wx),a.update(e,t,n,i)?(this.destroyBetween(this.index,r),this.index++,!0):!1}findIndexWithChild(e){for(;;){let t=e.parentNode;if(!t)return-1;if(t==this.top.contentDOM){let t=e.pmViewDesc;if(t){for(let e=this.index;e<this.top.children.length;e++)if(this.top.children[e]==t)return e}return-1}e=t}}updateNextNode(e,t,n,r,i,a){for(let o=this.index;o<this.top.children.length;o++){let s=this.top.children[o];if(s instanceof Xx){let c=this.preMatch.matched.get(s);if(c!=null&&c!=i)return!1;let l=s.dom,u,d=this.isLocked(l)&&!(e.isText&&s.node&&s.node.isText&&s.nodeDOM.nodeValue==e.text&&s.dirty!=Gx&&cS(t,s.outerDeco));if(!d&&s.update(e,t,n,r))return this.destroyBetween(this.index,o),s.dom!=l&&(this.changed=!0),this.index++,!0;if(!d&&(u=this.recreateWrapper(s,e,t,n,r,a)))return this.destroyBetween(this.index,o),this.top.children[this.index]=u,u.contentDOM&&(u.dirty=Wx,u.updateChildren(r,a+1),u.dirty=Hx),this.changed=!0,this.index++,!0;break}}return!1}recreateWrapper(e,t,n,r,i,a){if(e.dirty||t.isAtom||!e.children.length||!e.node.content.eq(t.content)||!cS(n,e.outerDeco)||!r.eq(e.innerDeco))return null;let o=Xx.create(this.top,t,n,r,i,a);if(o.contentDOM){o.children=e.children,e.children=[];for(let e of o.children)e.parent=o}return e.destroy(),o}addNode(e,t,n,r,i){let a=Xx.create(this.top,e,t,n,r,i);a.contentDOM&&a.updateChildren(r,i+1),this.top.children.splice(this.index++,0,a),this.changed=!0}placeWidget(e,t,n){let r=this.index<this.top.children.length?this.top.children[this.index]:null;if(r&&r.matchesWidget(e)&&(e==r.widget||!r.widget.type.toDOM.parentNode))this.index++;else{let r=new qx(this.top,e,t,n);this.top.children.splice(this.index++,0,r),this.changed=!0}}addTextblockHacks(){let e=this.top.children[this.index-1],t=this.top;for(;e instanceof Yx;)t=e,e=t.children[t.children.length-1];(!e||!(e instanceof Qx)||/\n$/.test(e.node.text)||this.view.requiresGeckoHackNode&&/\s$/.test(e.node.text))&&((rx||tx)&&e&&e.dom.contentEditable==`false`&&this.addHackNode(`IMG`,t),this.addHackNode(`BR`,this.top))}addHackNode(e,t){if(t==this.top&&this.index<t.children.length&&t.children[this.index].matchesHack(e))this.index++;else{let n=document.createElement(e);e==`IMG`&&(n.className=`ProseMirror-separator`,n.alt=``),e==`BR`&&(n.className=`ProseMirror-trailingBreak`);let r=new $x(this.top,[],n,null);t==this.top?t.children.splice(this.index++,0,r):t.children.push(r),this.changed=!0}}isLocked(e){return this.lock&&(e==this.lock||Z(e)&&e.contains(this.lock.parentNode))}};function dS(e,t){let n=t,r=n.children.length,i=e.childCount,a=new Map,o=[];outer:for(;i>0;){let s;for(;;)if(r){let e=n.children[r-1];if(e instanceof Yx)n=e,r=e.children.length;else{s=e,r--;break}}else if(n==t)break outer;else r=n.parent.children.indexOf(n),n=n.parent;let c=s.node;if(c){if(c!=e.child(i-1))break;--i,a.set(s,i),o.push(s)}}return{index:i,matched:a,matches:o.reverse()}}function fS(e,t){return e.type.side-t.type.side}function pS(e,t,n,r){let i=t.locals(e),a=0;if(i.length==0){for(let n=0;n<e.childCount;n++){let o=e.child(n);r(o,i,t.forChild(a,o),n),a+=o.nodeSize}return}let o=0,s=[],c=null;for(let l=0;;){let u,d;for(;o<i.length&&i[o].to==a;){let e=i[o++];e.widget&&(u?(d||=[u]).push(e):u=e)}if(u)if(d){d.sort(fS);for(let e=0;e<d.length;e++)n(d[e],l,!!c)}else n(u,l,!!c);let f,p;if(c)p=-1,f=c,c=null;else if(l<e.childCount)p=l,f=e.child(l++);else break;for(let e=0;e<s.length;e++)s[e].to<=a&&s.splice(e--,1);for(;o<i.length&&i[o].from<=a&&i[o].to>a;)s.push(i[o++]);let m=a+f.nodeSize;if(f.isText){let e=m;o<i.length&&i[o].from<e&&(e=i[o].from);for(let t=0;t<s.length;t++)s[t].to<e&&(e=s[t].to);e<m&&(c=f.cut(e-a),f=f.cut(0,e-a),m=e,p=-1)}else for(;o<i.length&&i[o].to<m;)o++;let h=f.isInline&&!f.isLeaf?s.filter(e=>!e.inline):s.slice();r(f,h,t.forChild(a,f),p),a=m}}function mS(e){if(e.nodeName==`UL`||e.nodeName==`OL`){let t=e.style.cssText;e.style.cssText=t+`; list-style: square !important`,window.getComputedStyle(e).listStyle,e.style.cssText=t}}function hS(e,t,n,r){for(let i=0,a=0;i<e.childCount&&a<=r;){let o=e.child(i++),s=a;if(a+=o.nodeSize,!o.isText)continue;let c=o.text;for(;i<e.childCount;){let t=e.child(i++);if(a+=t.nodeSize,!t.isText)break;c+=t.text}if(a>=n){if(a>=r&&c.slice(r-t.length-s,r-s)==t)return r-t.length;let e=s<r?c.lastIndexOf(t,r-s-1):-1;if(e>=0&&e+t.length+s>=n)return s+e;if(n==r&&c.length>=r+t.length-s&&c.slice(r-s,r-s+t.length)==t)return r}}return-1}function gS(e,t,n,r,i){let a=[];for(let o=0,s=0;o<e.length;o++){let c=e[o],l=s,u=s+=c.size;l>=n||u<=t?a.push(c):(l<t&&a.push(c.slice(0,t-l,r)),i&&=(a.push(i),void 0),u>n&&a.push(c.slice(n-l,c.size,r)))}return a}function _S(e,t=null){let n=e.domSelectionRange(),r=e.state.doc;if(!n.focusNode)return null;let i=e.docView.nearestDesc(n.focusNode),a=i&&i.size==0,o=e.docView.posFromDOM(n.focusNode,n.focusOffset,1);if(o<0)return null;let s=r.resolve(o),c,l;if(Vb(n)){for(c=o;i&&!i.node;)i=i.parent;if(i&&i.node.isAtom&&X.isSelectable(i.node)&&i.parent&&!(i.node.isInline&&zb(n.focusNode,n.focusOffset,i.dom))){let e=i.posBefore;l=new X(o==e?s:r.resolve(e))}else if($b&&t==`key`&&o>e.state.selection.to&&Z(n.focusNode)&&n.focusOffset==n.focusNode.childNodes.length&&i&&i.posAtStart>e.state.selection.to)for(let e=n.focusNode;;e=e.parentNode){if(getComputedStyle(e).overflow!=`visible`){l=dy.findFrom(r.resolve(i.posAtStart),1);break}if(e==i.dom||e.nextSibling||!e.parentNode||!Z(e.parentNode))break}}else{if(n instanceof e.dom.ownerDocument.defaultView.Selection&&n.rangeCount>1){let t=o,i=o;for(let r=0;r<n.rangeCount;r++){let a=n.getRangeAt(r);t=Math.min(t,e.docView.posFromDOM(a.startContainer,a.startOffset,1)),i=Math.max(i,e.docView.posFromDOM(a.endContainer,a.endOffset,-1))}if(t<0)return null;[c,o]=i==e.state.selection.anchor?[i,t]:[t,i],s=r.resolve(o)}else c=e.docView.posFromDOM(n.anchorNode,n.anchorOffset,1);if(c<0)return null}let u=r.resolve(c);if(!l){let n=t==`pointer`||e.state.selection.head<s.pos&&!a?1:-1;l=OS(e,u,s,n)}return l}function vS(e){return e.editable?e.hasFocus():AS(e)&&document.activeElement&&document.activeElement.contains(e.dom)}function yS(e,t=!1){let n=e.state.selection;if(ES(e,n),!vS(e))return;let r=e.input.mouseDown;if(!t&&tx&&r){let t=e.domSelectionRange(),n=e.domObserver.currentSelection;if(t.anchorNode&&n.anchorNode&&jb(t.anchorNode,t.anchorOffset,n.anchorNode,n.anchorOffset)&&r.delaySelUpdate()){e.domObserver.setCurSelection();return}}if(e.domObserver.disconnectSelection(),e.cursorWrapper)TS(e);else{let{anchor:r,head:i}=n,a,o;bS&&!(n instanceof hy)&&(n.$from.parent.inlineContent||(a=xS(e,n.from)),!n.empty&&!n.$from.parent.inlineContent&&(o=xS(e,n.to))),e.docView.setSelection(r,i,e,t),bS&&(a&&CS(a),o&&CS(o)),n.visible?e.dom.classList.remove(`ProseMirror-hideselection`):(e.dom.classList.add(`ProseMirror-hideselection`),`onselectionchange`in document&&wS(e))}e.domObserver.setCurSelection(),e.domObserver.connectSelection()}var bS=rx||tx&&nx<63;function xS(e,t){let{node:n,offset:r}=e.docView.domFromPos(t,0),i=r<n.childNodes.length?n.childNodes[r]:null,a=r?n.childNodes[r-1]:null;if(rx&&i&&i.contentEditable==`false`)return SS(i);if((!i||i.contentEditable==`false`)&&(!a||a.contentEditable==`false`)){if(i)return SS(i);if(a)return SS(a)}}function SS(e){return e.contentEditable=`true`,rx&&e.draggable&&(e.draggable=!1,e.wasDraggable=!0),e}function CS(e){e.contentEditable=`false`,e.wasDraggable&&=(e.draggable=!0,null)}function wS(e){let t=e.dom.ownerDocument;t.removeEventListener(`selectionchange`,e.input.hideSelectionGuard);let n=e.domSelectionRange(),r=n.anchorNode,i=n.anchorOffset;t.addEventListener(`selectionchange`,e.input.hideSelectionGuard=()=>{(n.anchorNode!=r||n.anchorOffset!=i)&&(t.removeEventListener(`selectionchange`,e.input.hideSelectionGuard),setTimeout(()=>{(!vS(e)||e.state.selection.visible)&&e.dom.classList.remove(`ProseMirror-hideselection`)},20))})}function TS(e){let t=e.domSelection();if(!t)return;let n=e.cursorWrapper.dom,r=n.nodeName==`IMG`;r?t.collapse(n.parentNode,Eb(n)+1):t.collapse(n,0),!r&&!e.state.selection.visible&&Zb&&Qb<=11&&(n.disabled=!0,n.disabled=!1)}function ES(e,t){if(t instanceof X){let n=e.docView.descAt(t.from);n!=e.lastSelectedViewDesc&&(DS(e),n&&n.selectNode(),e.lastSelectedViewDesc=n)}else DS(e)}function DS(e){e.lastSelectedViewDesc&&=(e.lastSelectedViewDesc.parent&&e.lastSelectedViewDesc.deselectNode(),void 0)}function OS(e,t,n,r){return e.someProp(`createSelectionBetween`,r=>r(e,t,n))||hy.between(t,n,r)}function kS(e){return e.editable&&!e.hasFocus()?!1:AS(e)}function AS(e){let t=e.domSelectionRange();if(!t.anchorNode)return!1;try{return Ib(e.dom,t.anchorNode)&&(e.editable||Ib(e.dom,t.focusNode))}catch{return!1}}function jS(e){let t=e.docView.domFromPos(e.state.selection.anchor,0),n=e.domSelectionRange();return jb(t.node,t.offset,n.anchorNode,n.anchorOffset)}function MS(e,t){let{$anchor:n,$head:r}=e.selection,i=t>0?n.max(r):n.min(r),a=i.parent.inlineContent?i.depth?e.doc.resolve(t>0?i.after():i.before()):null:i;return a&&dy.findFrom(a,t)}function NS(e,t){return e.dispatch(e.state.tr.setSelection(t).scrollIntoView()),!0}function PS(e,t,n){let r=e.state.selection;if(r instanceof hy){if(n.indexOf(`s`)>-1){let{$head:n}=r,i=n.textOffset?null:t<0?n.nodeBefore:n.nodeAfter;if(!i||i.isText||!i.isLeaf)return!1;let a=e.state.doc.resolve(n.pos+i.nodeSize*(t<0?-1:1));return NS(e,new hy(r.$anchor,a))}else if(!r.empty)return!1;else if(e.endOfTextblock(t>0?`forward`:`backward`)){let n=MS(e.state,t);return n&&n instanceof X?NS(e,n):!1}else if(!(ax&&n.indexOf(`m`)>-1)){let n=r.$head,i=n.textOffset?null:t<0?n.nodeBefore:n.nodeAfter,a;if(!i||i.isText)return!1;let o=t<0?n.pos-i.nodeSize:n.pos;return i.isAtom||(a=e.docView.descAt(o))&&!a.contentDOM?X.isSelectable(i)?NS(e,new X(t<0?e.state.doc.resolve(n.pos-i.nodeSize):n)):NS(e,new hy(e.state.doc.resolve(t<0?o:o+i.nodeSize))):!1}}else if(r instanceof X&&r.node.isInline)return NS(e,new hy(t>0?r.$to:r.$from));else{let n=MS(e.state,t);return n?NS(e,n):!1}}function FS(e,t){let n=e.pmViewDesc;return n?n.size==0&&(t<0||e.nextSibling||e.nodeName!=`BR`):Z(e)&&e.contentEditable==`false`}function IS(e,t){return t<0?LS(e):RS(e)}function LS(e){let t=e.domSelectionRange(),n=t.focusNode,r=t.focusOffset;if(!n)return;let i,a,o=!1;for($b&&Z(n)&&r<Pb(n)&&FS(n.childNodes[r],-1)&&(o=!0);;)if(r>0){if(!Z(n))break;let e=n.childNodes[r-1];if(FS(e,-1))i=n,a=--r;else if(Fb(e))n=e,r=n.nodeValue.length;else break}else if(zS(n))break;else{let t=n.previousSibling;for(;t&&FS(t,-1);)i=n.parentNode,a=Eb(t),t=t.previousSibling;if(t)n=t,r=Pb(n);else{if(n=n.parentNode,n==e.dom)break;r=0}}o?HS(e,n,r):i&&HS(e,i,a)}function RS(e){let t=e.domSelectionRange(),n=t.focusNode,r=t.focusOffset;if(!n)return;let i=Pb(n),a,o;for(;;)if(r<i){if(!Z(n))break;let e=n.childNodes[r];if(FS(e,1))a=n,o=++r;else break}else if(zS(n))break;else{let t=n.nextSibling;for(;t&&FS(t,1);)a=t.parentNode,o=Eb(t)+1,t=t.nextSibling;if(t)n=t,r=0,i=Pb(n);else{if(n=n.parentNode,n==e.dom)break;r=i=0}}a&&HS(e,a,o)}function zS(e){let t=e.pmViewDesc;return t&&t.node&&t.node.isBlock}function BS(e,t){for(;e&&t==e.childNodes.length&&!Bb(e);)t=Eb(e)+1,e=e.parentNode;for(;e&&t<e.childNodes.length;){let n=e.childNodes[t];if(Fb(n))return n;if(Z(n)&&n.contentEditable==`false`)break;e=n,t=0}}function VS(e,t){for(;e&&!t&&!Bb(e);)t=Eb(e),e=e.parentNode;for(;e&&t;){let n=e.childNodes[t-1];if(Fb(n))return n;if(Z(n)&&n.contentEditable==`false`)break;e=n,t=e.childNodes.length}}function HS(e,t,n){if(!Fb(t)){let e,r;(r=BS(t,n))?(t=r,n=0):(e=VS(t,n))&&(t=e,n=e.nodeValue.length)}let r=e.domSelection();if(!r)return;if(Vb(r)){let e=document.createRange();e.setEnd(t,n),e.setStart(t,n),r.removeAllRanges(),r.addRange(e)}else r.extend&&r.extend(t,n);e.domObserver.setCurSelection();let{state:i}=e;setTimeout(()=>{e.state==i&&yS(e)},50)}function US(e,t){let n=e.state.doc.resolve(t);if(!(tx||ox)&&n.parent.inlineContent){let r=e.coordsAtPos(t);if(t>n.start()){let n=e.coordsAtPos(t-1),i=(n.top+n.bottom)/2;if(i>r.top&&i<r.bottom&&Math.abs(n.left-r.left)>1)return n.left<r.left?`ltr`:`rtl`}if(t<n.end()){let n=e.coordsAtPos(t+1),i=(n.top+n.bottom)/2;if(i>r.top&&i<r.bottom&&Math.abs(n.left-r.left)>1)return n.left>r.left?`ltr`:`rtl`}}return getComputedStyle(e.dom).direction==`rtl`?`rtl`:`ltr`}function WS(e,t,n){let r=e.state.selection;if(r instanceof hy&&!r.empty||n.indexOf(`s`)>-1||ax&&n.indexOf(`m`)>-1)return!1;let{$from:i,$to:a}=r;if(!i.parent.inlineContent||e.endOfTextblock(t<0?`up`:`down`)){let n=MS(e.state,t);if(n&&n instanceof X)return NS(e,n)}if(!i.parent.inlineContent){let n=t<0?i:a,o=r instanceof vy?dy.near(n,t):dy.findFrom(n,t);return o?NS(e,o):!1}return!1}function GS(e,t){if(!(e.state.selection instanceof hy))return!0;let{$head:n,$anchor:r,empty:i}=e.state.selection;if(!n.sameParent(r))return!0;if(!i)return!1;if(e.endOfTextblock(t>0?`forward`:`backward`))return!0;let a=!n.textOffset&&(t<0?n.nodeBefore:n.nodeAfter);if(a&&!a.isText){let r=e.state.tr;return t<0?r.delete(n.pos-a.nodeSize,n.pos):r.delete(n.pos,n.pos+a.nodeSize),e.dispatch(r),!0}return!1}function KS(e,t,n){e.domObserver.stop(),t.contentEditable=n,e.domObserver.start()}function qS(e){if(!rx||e.state.selection.$head.parentOffset>0)return!1;let{focusNode:t,focusOffset:n}=e.domSelectionRange();if(t&&Z(t)&&n==0&&t.firstChild&&Z(t.firstChild)&&t.firstChild.contentEditable==`false`){let n=t.firstChild;KS(e,n,`true`),setTimeout(()=>KS(e,n,`false`),20)}return!1}function JS(e){let t=``;return e.ctrlKey&&(t+=`c`),e.metaKey&&(t+=`m`),e.altKey&&(t+=`a`),e.shiftKey&&(t+=`s`),t}function YS(e,t){let n=t.keyCode,r=JS(t);if(n==8||ax&&n==72&&r==`c`)return GS(e,-1)||IS(e,-1);if(n==46&&!t.shiftKey||ax&&n==68&&r==`c`)return GS(e,1)||IS(e,1);if(n==13||n==27)return!0;if(n==37||ax&&n==66&&r==`c`){let t=n==37?US(e,e.state.selection.from)==`ltr`?-1:1:-1;return PS(e,t,r)||IS(e,t)}else if(n==39||ax&&n==70&&r==`c`){let t=n==39?US(e,e.state.selection.from)==`ltr`?1:-1:1;return PS(e,t,r)||IS(e,t)}else if(n==38||ax&&n==80&&r==`c`)return WS(e,-1,r)||IS(e,-1);else if(n==40||ax&&n==78&&r==`c`)return qS(e)||WS(e,1,r)||IS(e,1);else if(r==(ax?`m`:`c`)&&(n==66||n==73||n==89||n==90))return!0;return!1}function XS(e,t){e.someProp(`transformCopied`,n=>{t=n(t,e)});let n=[],{content:r,openStart:i,openEnd:a}=t;for(;i>1&&a>1&&r.childCount==1&&r.firstChild.childCount==1;){i--,a--;let e=r.firstChild;n.push(e.type.name,e.attrs==e.type.defaultAttrs?null:e.attrs),r=e.content}let o=e.someProp(`clipboardSerializer`)||U_.fromSchema(e.state.schema),s=oC(),c=s.createElement(`div`);c.appendChild(o.serializeFragment(r,{document:s}));let l=c.firstChild,u,d=0;for(;l&&Z(l)&&(u=aC[l.nodeName.toLowerCase()]);){for(let e=u.length-1;e>=0;e--){let t=s.createElement(u[e]);for(;c.firstChild;)t.appendChild(c.firstChild);c.appendChild(t),d++}l=c.firstChild}return l&&Z(l)&&l.setAttribute(`data-pm-slice`,`${i} ${a}${d?` -${d}`:``} ${JSON.stringify(n)}`),{dom:c,text:e.someProp(`clipboardTextSerializer`,n=>n(t,e))||t.content.textBetween(0,t.content.size,`
|
|
15
|
+
|
|
16
|
+
`),slice:t}}function ZS(e,t,n,r,i){let a=i.parent.type.spec.code,o,s;if(!n&&!t)return null;let c=!!t&&(r||a||!n);if(c){if(e.someProp(`transformPastedText`,n=>{t=n(t,a||r,e)}),a)return s=new Y(J.from(e.state.schema.text(t.replace(/\r\n?/g,`
|
|
17
|
+
`))),0,0),e.someProp(`transformPasted`,t=>{s=t(s,e,!0)}),s;let n=e.someProp(`clipboardTextParser`,n=>n(t,i,r,e));if(n)s=n;else{let n=i.marks(),{schema:r}=e.state,a=U_.fromSchema(r);o=document.createElement(`div`),t.split(/(?:\r\n?|\n)+/).forEach(e=>{let t=o.appendChild(document.createElement(`p`));e&&t.appendChild(a.serializeNode(r.text(e,n)))})}}else e.someProp(`transformPastedHTML`,t=>{n=t(n,e)}),o=lC(n),cx&&uC(o);let l=o&&o.querySelector(`[data-pm-slice]`),u=l&&/^(\d+) (\d+)(?: -(\d+))? (.*)/.exec(l.getAttribute(`data-pm-slice`)||``);if(u&&u[3])for(let e=+u[3];e>0;e--){let e=o.firstChild;for(;e&&!Z(e);)e=e.nextSibling;if(!e)break;o=e}if(s||=(e.someProp(`clipboardParser`)||e.someProp(`domParser`)||k_.fromSchema(e.state.schema)).parseSlice(o,{preserveWhitespace:!!(c||u),context:i,ruleFromNode(e){return e.nodeName==`BR`&&!e.nextSibling&&e.parentNode&&!QS.test(e.parentNode.nodeName)?{ignore:!0}:null}}),u)s=dC(iC(s,+u[1],+u[2]),u[4]);else if(s=Y.maxOpen($S(s.content,i),!0),s.openStart||s.openEnd){let e=0,t=0;for(let t=s.content.firstChild;e<s.openStart&&!t.type.spec.isolating;e++,t=t.firstChild);for(let e=s.content.lastChild;t<s.openEnd&&!e.type.spec.isolating;t++,e=e.lastChild);s=iC(s,e,t)}return e.someProp(`transformPasted`,t=>{s=t(s,e,c)}),s}var QS=/^(a|abbr|acronym|b|cite|code|del|em|i|ins|kbd|label|output|q|ruby|s|samp|span|strong|sub|sup|time|u|tt|var)$/i;function $S(e,t){if(e.childCount<2)return e;for(let n=t.depth;n>=0;n--){let r=t.node(n).contentMatchAt(t.index(n)),i,a=[];if(e.forEach(e=>{if(!a)return;let t=r.findWrapping(e.type),n;if(!t)return a=null;if(n=a.length&&i.length&&tC(t,i,e,a[a.length-1],0))a[a.length-1]=n;else{a.length&&(a[a.length-1]=nC(a[a.length-1],i.length));let n=eC(e,t);a.push(n),r=r.matchType(n.type),i=t}}),a)return J.from(a)}return e}function eC(e,t,n=0){for(let r=t.length-1;r>=n;r--)e=t[r].create(null,J.from(e));return e}function tC(e,t,n,r,i){if(i<e.length&&i<t.length&&e[i]==t[i]){let a=tC(e,t,n,r.lastChild,i+1);if(a)return r.copy(r.content.replaceChild(r.childCount-1,a));if(r.contentMatchAt(r.childCount).matchType(i==e.length-1?n.type:e[i+1]))return r.copy(r.content.append(J.from(eC(n,e,i+1))))}}function nC(e,t){if(t==0)return e;let n=e.content.replaceChild(e.childCount-1,nC(e.lastChild,t-1)),r=e.contentMatchAt(e.childCount).fillBefore(J.empty,!0);return e.copy(n.append(r))}function rC(e,t,n,r,i,a){let o=t<0?e.firstChild:e.lastChild,s=o.content;return e.childCount>1&&(a=0),i<r-1&&(s=rC(s,t,n,r,i+1,a)),i>=n&&(s=t<0?o.contentMatchAt(0).fillBefore(s,a<=i).append(s):s.append(o.contentMatchAt(o.childCount).fillBefore(J.empty,!0))),e.replaceChild(t<0?0:e.childCount-1,o.copy(s))}function iC(e,t,n){return t<e.openStart&&(e=new Y(rC(e.content,-1,t,e.openStart,0,e.openEnd),t,e.openEnd)),n<e.openEnd&&(e=new Y(rC(e.content,1,n,e.openEnd,0,0),e.openStart,n)),e}var aC={thead:[`table`],tbody:[`table`],tfoot:[`table`],caption:[`table`],colgroup:[`table`],col:[`table`,`colgroup`],tr:[`table`,`tbody`],td:[`table`,`tbody`,`tr`],th:[`table`,`tbody`,`tr`]};function oC(){return document.implementation.createHTMLDocument(`title`)}var sC=null;function cC(e){let t=window.trustedTypes;if(!t)return e;if(!sC){if(sC=t.defaultPolicy)try{return sC.createHTML(e)}catch{}sC=t.createPolicy(`ProseMirrorClipboard`,{createHTML:e=>e})}return sC.createHTML(e)}function lC(e){let t=/^(\s*<meta [^>]*>)*/.exec(e);t&&(e=e.slice(t[0].length));let n=oC(),r=n.body,i=/<([a-z][^>\s]+)/i.exec(e),a;if((a=i&&aC[i[1].toLowerCase()])&&(e=a.map(e=>`<`+e+`>`).join(``)+e+a.map(e=>`</`+e+`>`).reverse().join(``)),r.innerHTML=cC(e),a)for(let e=0;e<a.length;e++)r=r.querySelector(a[e])||r;for(let e=0;e<n.styleSheets.length;e++){let t=n.styleSheets[e];for(let e=0;e<t.rules.length;e++){let n=t.rules[e];if(n instanceof CSSStyleRule){let e=r.querySelectorAll(n.selectorText);for(let t=0;t<e.length;t++)e[t].style.cssText+=n.style.cssText}}}return r}function uC(e){let t=e.querySelectorAll(tx?`span:not([class]):not([style])`:`span.Apple-converted-space`);for(let n=0;n<t.length;n++){let r=t[n];r.childNodes.length==1&&r.textContent==`\xA0`&&r.parentNode&&r.parentNode.replaceChild(e.ownerDocument.createTextNode(` `),r)}}function dC(e,t){if(!e.size)return e;let n=e.content.firstChild.type.schema,r;try{r=JSON.parse(t)}catch{return e}let{content:i,openStart:a,openEnd:o}=e;for(let e=r.length-2;e>=0;e-=2){let t=n.nodes[r[e]];if(!t||t.hasRequiredAttrs())break;try{i=J.from(t.create(r[e+1],i))}catch{break}a++,o++}return new Y(i,a,o)}var fC={},pC={},mC={touchstart:!0,touchmove:!0},hC=class{constructor(){this.shiftKey=!1,this.mouseDown=null,this.lastKeyCode=null,this.lastKeyCodeTime=0,this.lastClick={time:0,x:0,y:0,type:``,button:0},this.lastSelectionOrigin=null,this.lastSelectionTime=0,this.lastIOSEnter=0,this.lastIOSEnterFallbackTimeout=-1,this.lastFocus=0,this.lastTouch=0,this.lastChromeDelete=0,this.composing=!1,this.compositionNode=null,this.composingTimeout=-1,this.compositionNodes=[],this.compositionEndedAt=-2e8,this.compositionID=1,this.badSafariComposition=!1,this.compositionPendingChanges=0,this.domChangeCount=0,this.eventHandlers=Object.create(null),this.hideSelectionGuard=null}};function gC(e){for(let t in fC){let n=fC[t];e.dom.addEventListener(t,e.input.eventHandlers[t]=t=>{xC(e,t)&&!bC(e,t)&&(e.editable||!(t.type in pC))&&n(e,t)},mC[t]?{passive:!0}:void 0)}rx&&e.dom.addEventListener(`input`,()=>null),yC(e)}function _C(e,t){e.input.lastSelectionOrigin=t,e.input.lastSelectionTime=Date.now()}function vC(e){e.input.mouseDown&&e.input.mouseDown.done(),e.domObserver.stop();for(let t in e.input.eventHandlers)e.dom.removeEventListener(t,e.input.eventHandlers[t]);clearTimeout(e.input.composingTimeout),clearTimeout(e.input.lastIOSEnterFallbackTimeout)}function yC(e){e.someProp(`handleDOMEvents`,t=>{for(let n in t)e.input.eventHandlers[n]||e.dom.addEventListener(n,e.input.eventHandlers[n]=t=>bC(e,t))})}function bC(e,t){return e.someProp(`handleDOMEvents`,n=>{let r=n[t.type];return r?r(e,t)||t.defaultPrevented:!1})}function xC(e,t){if(!t.bubbles)return!0;if(t.defaultPrevented)return!1;for(let n=t.target;n!=e.dom;n=n.parentNode)if(!n||n.nodeType==11||n.pmViewDesc&&n.pmViewDesc.stopEvent(t))return!1;return!0}function SC(e,t){!bC(e,t)&&fC[t.type]&&(e.editable||!(t.type in pC))&&fC[t.type](e,t)}pC.keydown=(e,t)=>{let n=t;if(e.input.shiftKey=n.keyCode==16||n.shiftKey,!zC(e)&&(e.input.lastKeyCode=n.keyCode,e.input.lastKeyCodeTime=Date.now(),!(sx&&tx&&n.keyCode==13)))if(n.keyCode!=229&&e.domObserver.forceFlush(),ix&&n.keyCode==13&&!n.ctrlKey&&!n.altKey&&!n.metaKey){let t=Date.now();e.input.lastIOSEnter=t,e.input.lastIOSEnterFallbackTimeout=setTimeout(()=>{e.input.lastIOSEnter==t&&(e.someProp(`handleKeyDown`,t=>t(e,Hb(13,`Enter`))),e.input.lastIOSEnter=0)},200)}else e.someProp(`handleKeyDown`,t=>t(e,n))||YS(e,n)?n.preventDefault():_C(e,`key`)},pC.keyup=(e,t)=>{t.keyCode==16&&(e.input.shiftKey=!1)},pC.keypress=(e,t)=>{let n=t;if(zC(e)||!n.charCode||n.ctrlKey&&!n.altKey||ax&&n.metaKey)return;if(e.someProp(`handleKeyPress`,t=>t(e,n))){n.preventDefault();return}let r=e.state.selection;if(!(r instanceof hy)||!r.$from.sameParent(r.$to)){let t=String.fromCharCode(n.charCode),i=()=>e.state.tr.insertText(t).scrollIntoView();!/[\r\n]/.test(t)&&!e.someProp(`handleTextInput`,n=>n(e,r.$from.pos,r.$to.pos,t,i))&&e.dispatch(i()),n.preventDefault()}};function CC(e){return{left:e.clientX,top:e.clientY}}function wC(e,t){let n=t.x-e.clientX,r=t.y-e.clientY;return n*n+r*r<100}function TC(e,t,n,r,i){if(r==-1)return!1;let a=e.state.doc.resolve(r);for(let r=a.depth+1;r>0;r--)if(e.someProp(t,t=>r>a.depth?t(e,n,a.nodeAfter,a.before(r),i,!0):t(e,n,a.node(r),a.before(r),i,!1)))return!0;return!1}function EC(e,t,n){if(e.focused||e.focus(),e.state.selection.eq(t))return;let r=e.state.tr.setSelection(t);r.setMeta(`pointer`,!0),e.dispatch(r)}function DC(e,t){if(t==-1)return!1;let n=e.state.doc.resolve(t),r=n.nodeAfter;return r&&r.isAtom&&X.isSelectable(r)?(EC(e,new X(n)),!0):!1}function OC(e,t){if(t==-1)return!1;let n=e.state.selection,r,i;n instanceof X&&(r=n.node);let a=e.state.doc.resolve(t);for(let e=a.depth+1;e>0;e--){let t=e>a.depth?a.nodeAfter:a.node(e);if(X.isSelectable(t)){i=r&&n.$from.depth>0&&e>=n.$from.depth&&a.before(n.$from.depth+1)==n.$from.pos?a.before(n.$from.depth):a.before(e);break}}return i==null?!1:(EC(e,X.create(e.state.doc,i)),!0)}function kC(e,t,n,r,i){return TC(e,`handleClickOn`,t,n,r)||e.someProp(`handleClick`,n=>n(e,t,r))||(i?OC(e,n):DC(e,n))}function AC(e,t,n,r){return TC(e,`handleDoubleClickOn`,t,n,r)||e.someProp(`handleDoubleClick`,n=>n(e,t,r))}function jC(e,t,n,r){return TC(e,`handleTripleClickOn`,t,n,r)||e.someProp(`handleTripleClick`,n=>n(e,t,r))||MC(e,n,r)}function MC(e,t,n){if(n.button!=0)return!1;let r=NC(e,t,!0),i=e.state.doc;return r?(EC(e,r),r instanceof hy&&i.eq(e.state.doc)&&(e.input.mouseDown=new RC(e,r)),!0):!1}function NC(e,t,n){let r=e.state.doc;if(t==-1)return r.inlineContent?hy.create(r,0,r.content.size):null;let i=r.resolve(t);for(let e=i.depth+1;e>0;e--){let t=e>i.depth?i.nodeAfter:i.node(e),a=i.before(e);if(t.inlineContent)return hy.create(r,a+1,a+1+t.content.size);if(n&&X.isSelectable(t))return X.create(r,a)}return null}function PC(e){return GC(e)}var FC=ax?`metaKey`:`ctrlKey`;fC.mousedown=(e,t)=>{let n=t;e.input.shiftKey=n.shiftKey;let r=PC(e),i=Date.now(),a=`singleClick`;i-e.input.lastClick.time<500&&wC(n,e.input.lastClick)&&!n[FC]&&e.input.lastClick.button==n.button&&(e.input.lastClick.type==`singleClick`?a=`doubleClick`:e.input.lastClick.type==`doubleClick`&&(a=`tripleClick`)),e.input.lastClick={time:i,x:n.clientX,y:n.clientY,type:a,button:n.button},e.input.mouseDown&&e.input.mouseDown.done();let o=e.posAtCoords(CC(n));o&&(a==`singleClick`?e.input.mouseDown=new LC(e,o,n,!!r):(a==`doubleClick`?AC:jC)(e,o.pos,o.inside,n)?n.preventDefault():_C(e,`pointer`))};var IC=class{constructor(e){this.view=e,this.mightDrag=null,e.root.addEventListener(`mouseup`,this.up=this.up.bind(this)),e.root.addEventListener(`mousemove`,this.move=this.move.bind(this))}up(e){this.done()}move(e){e.buttons==0&&this.done()}done(){this.view.root.removeEventListener(`mouseup`,this.up),this.view.root.removeEventListener(`mousemove`,this.move),this.view.input.mouseDown==this&&(this.view.input.mouseDown=null)}delaySelUpdate(){return!1}},LC=class extends IC{constructor(e,t,n,r){super(e),this.pos=t,this.event=n,this.flushed=r,this.delayedSelectionSync=!1,this.startDoc=e.state.doc,this.selectNode=!!n[FC],this.allowDefault=n.shiftKey;let i,a;if(t.inside>-1)i=e.state.doc.nodeAt(t.inside),a=t.inside;else{let n=e.state.doc.resolve(t.pos);i=n.parent,a=n.depth?n.before():0}let o=r?null:n.target,s=o?e.docView.nearestDesc(o,!0):null;this.target=s&&Z(s.nodeDOM)?s.nodeDOM:null;let{selection:c}=e.state;n.button==0&&(i.type.spec.draggable&&i.type.spec.selectable!==!1||c instanceof X&&c.from<=a&&c.to>a)&&(this.mightDrag={node:i,pos:a,addAttr:!!(this.target&&!this.target.draggable),setUneditable:!!(this.target&&$b&&!this.target.hasAttribute(`contentEditable`))}),this.target&&this.mightDrag&&(this.mightDrag.addAttr||this.mightDrag.setUneditable)&&(this.view.domObserver.stop(),this.mightDrag.addAttr&&(this.target.draggable=!0),this.mightDrag.setUneditable&&setTimeout(()=>{this.view.input.mouseDown==this&&this.target.setAttribute(`contentEditable`,`false`)},20),this.view.domObserver.start()),_C(e,`pointer`)}done(){super.done(),this.mightDrag&&this.target&&(this.view.domObserver.stop(),this.mightDrag.addAttr&&this.target.removeAttribute(`draggable`),this.mightDrag.setUneditable&&this.target.removeAttribute(`contentEditable`),this.view.domObserver.start()),this.delayedSelectionSync&&setTimeout(()=>{this.view.isDestroyed||yS(this.view)})}up(e){if(this.done(),!this.view.dom.contains(e.target))return;let t=this.pos;this.view.state.doc!=this.startDoc&&(t=this.view.posAtCoords(CC(e))),this.updateAllowDefault(e),this.allowDefault||!t?_C(this.view,`pointer`):kC(this.view,t.pos,t.inside,e,this.selectNode)?e.preventDefault():e.button==0&&(this.flushed||rx&&this.mightDrag&&!this.mightDrag.node.isAtom||tx&&!this.view.state.selection.visible&&Math.min(Math.abs(t.pos-this.view.state.selection.from),Math.abs(t.pos-this.view.state.selection.to))<=2)?(EC(this.view,dy.near(this.view.state.doc.resolve(t.pos))),e.preventDefault()):_C(this.view,`pointer`)}move(e){this.updateAllowDefault(e),_C(this.view,`pointer`),super.move(e)}updateAllowDefault(e){!this.allowDefault&&(Math.abs(this.event.x-e.clientX)>4||Math.abs(this.event.y-e.clientY)>4)&&(this.allowDefault=!0)}delaySelUpdate(){return this.allowDefault?(this.delayedSelectionSync=!0,!0):!1}},RC=class extends IC{constructor(e,t){super(e),this.startSelection=t,this.startDoc=e.state.doc}move(e){if(e.buttons==0||this.view.isDestroyed||!this.view.state.doc.eq(this.startDoc)){this.done();return}e.preventDefault(),_C(this.view,`pointer`);let t=this.view.posAtCoords(CC(e)),n=t&&NC(this.view,t.inside,!1);if(!n)return;let{doc:r}=this.view.state,i=this.startSelection,[a,o]=n.from<i.from?[i.to,n.from]:[i.from,n.to];EC(this.view,hy.create(r,a,o))}};fC.touchstart=e=>{e.input.lastTouch=Date.now(),PC(e),_C(e,`pointer`)},fC.touchmove=e=>{e.input.lastTouch=Date.now(),_C(e,`pointer`)},fC.contextmenu=e=>PC(e);function zC(e,t){return e.composing?!0:rx&&Math.abs(Date.now()-e.input.compositionEndedAt)<500?(e.input.compositionEndedAt=-2e8,!0):!1}var BC=sx?5e3:-1;pC.compositionstart=pC.compositionupdate=e=>{if(!e.composing){e.domObserver.flush();let{state:t}=e,n=t.selection.$to;if(t.selection instanceof hy&&t.selection.empty&&(t.storedMarks||!n.textOffset&&n.parentOffset&&n.nodeBefore.marks.some(e=>e.type.spec.inclusive===!1)||tx&&ox&&VC(e)))e.markCursor=e.state.storedMarks||n.marks(),GC(e,!0),e.markCursor=null;else if(GC(e,!t.selection.empty),$b&&t.selection.empty&&n.parentOffset&&!n.textOffset&&n.nodeBefore.marks.length){let t=e.domSelectionRange();for(let n=t.focusNode,r=t.focusOffset;n&&Z(n)&&r!=0;){let t=r<0?n.lastChild:n.childNodes[r-1];if(!t)break;if(Fb(t)){let n=e.domSelection();n&&n.collapse(t,t.nodeValue.length);break}else n=t,r=-1}}e.input.composing=!0}HC(e,BC)};function VC(e){let{focusNode:t,focusOffset:n}=e.domSelectionRange();if(!t||!Z(t)||n>=t.childNodes.length)return!1;let r=t.childNodes[n];return Z(r)&&r.contentEditable==`false`}pC.compositionend=(e,t)=>{e.composing&&(e.input.composing=!1,e.input.compositionEndedAt=Date.now(),e.input.compositionPendingChanges=e.domObserver.pendingRecords().length?e.input.compositionID:0,e.input.compositionNode=null,e.input.badSafariComposition?e.domObserver.forceFlush():e.input.compositionPendingChanges&&Promise.resolve().then(()=>e.domObserver.flush()),e.input.compositionID++,HC(e,20))};function HC(e,t){clearTimeout(e.input.composingTimeout),t>-1&&(e.input.composingTimeout=setTimeout(()=>GC(e),t))}function UC(e){for(e.composing&&(e.input.composing=!1,e.input.compositionEndedAt=Date.now());e.input.compositionNodes.length>0;)e.input.compositionNodes.pop().markParentsDirty()}function WC(e){let t=e.domSelectionRange();if(!t.focusNode)return null;let n=Lb(t.focusNode,t.focusOffset),r=Rb(t.focusNode,t.focusOffset);if(n&&r&&n!=r){let t=r.pmViewDesc,i=e.domObserver.lastChangedTextNode;if(n==i||r==i)return i;if(!t||!t.isText(r.nodeValue))return r;if(e.input.compositionNode==r){let e=n.pmViewDesc;if(!(!e||!e.isText(n.nodeValue)))return r}}return n||r}function GC(e,t=!1){if(!(sx&&e.domObserver.flushingSoon>=0)){if(e.domObserver.forceFlush(),UC(e),t||e.docView&&e.docView.dirty){let n=_S(e),r=e.state.selection;return n&&!n.eq(r)?e.dispatch(e.state.tr.setSelection(n)):(e.markCursor||t)&&!r.$from.node(r.$from.sharedDepth(r.to)).inlineContent?e.dispatch(e.state.tr.deleteSelection()):e.updateState(e.state),!0}return!1}}function KC(e,t){if(!e.dom.parentNode)return;let n=e.dom.parentNode.appendChild(document.createElement(`div`));n.appendChild(t),n.style.cssText=`position: fixed; left: -10000px; top: 10px`;let r=getSelection(),i=document.createRange();i.selectNodeContents(t),e.dom.blur(),r.removeAllRanges(),r.addRange(i),setTimeout(()=>{n.parentNode&&n.parentNode.removeChild(n),e.focus()},50)}var qC=Zb&&Qb<15||ix&&lx<604;fC.copy=pC.cut=(e,t)=>{let n=t,r=e.state.selection,i=n.type==`cut`;if(r.empty)return;let a=qC?null:n.clipboardData,{dom:o,text:s}=XS(e,r.content());a?(n.preventDefault(),a.clearData(),a.setData(`text/html`,o.innerHTML),a.setData(`text/plain`,s)):KC(e,o),i&&e.dispatch(e.state.tr.deleteSelection().scrollIntoView().setMeta(`uiEvent`,`cut`))};function JC(e){return e.openStart==0&&e.openEnd==0&&e.content.childCount==1?e.content.firstChild:null}function YC(e,t){if(!e.dom.parentNode)return;let n=e.input.shiftKey||e.state.selection.$from.parent.type.spec.code,r=e.dom.parentNode.appendChild(document.createElement(n?`textarea`:`div`));n||(r.contentEditable=`true`),r.style.cssText=`position: fixed; left: -10000px; top: 10px`,r.focus();let i=e.input.shiftKey&&e.input.lastKeyCode!=45;setTimeout(()=>{e.focus(),r.parentNode&&r.parentNode.removeChild(r),n?XC(e,r.value,null,i,t):XC(e,r.textContent,r.innerHTML,i,t)},50)}function XC(e,t,n,r,i){let a=ZS(e,t,n,r,e.state.selection.$from);if(e.someProp(`handlePaste`,t=>t(e,i,a||Y.empty)))return!0;if(!a)return!1;let o=JC(a),s=o?e.state.tr.replaceSelectionWith(o,r):e.state.tr.replaceSelection(a);return e.dispatch(s.scrollIntoView().setMeta(`paste`,!0).setMeta(`uiEvent`,`paste`)),!0}function ZC(e){let t=e.getData(`text/plain`)||e.getData(`Text`);if(t)return t;let n=e.getData(`text/uri-list`);return n?n.replace(/\r?\n/g,` `):``}pC.paste=(e,t)=>{let n=t;if(e.composing&&!sx)return;let r=qC?null:n.clipboardData,i=e.input.shiftKey&&e.input.lastKeyCode!=45;r&&XC(e,ZC(r),r.getData(`text/html`),i,n)?n.preventDefault():YC(e,n)};var QC=class{constructor(e,t,n){this.slice=e,this.move=t,this.node=n}},$C=ax?`altKey`:`ctrlKey`;function ew(e,t){let n;return e.someProp(`dragCopies`,e=>{n||=e(t)}),n==null?!t[$C]:!n}fC.dragstart=(e,t)=>{let n=t,r=e.input.mouseDown;if(r&&r.done(),!n.dataTransfer)return;let i=e.state.selection,a=i.empty?null:e.posAtCoords(CC(n)),o;if(!(a&&a.pos>=i.from&&a.pos<=(i instanceof X?i.to-1:i.to))){if(r&&r.mightDrag)o=X.create(e.state.doc,r.mightDrag.pos);else if(n.target&&Z(n.target)){let t=e.docView.nearestDesc(n.target,!0);t&&t.node.type.spec.draggable&&t!=e.docView&&(o=X.create(e.state.doc,t.posBefore))}}let{dom:s,text:c,slice:l}=XS(e,(o||e.state.selection).content());(!n.dataTransfer.files.length||!tx||nx>120)&&n.dataTransfer.clearData(),n.dataTransfer.setData(qC?`Text`:`text/html`,s.innerHTML),n.dataTransfer.effectAllowed=`copyMove`,qC||n.dataTransfer.setData(`text/plain`,c),e.dragging=new QC(l,ew(e,n),o)},fC.dragend=e=>{let t=e.dragging;window.setTimeout(()=>{e.dragging==t&&(e.dragging=null)},50)},pC.dragover=pC.dragenter=(e,t)=>t.preventDefault(),pC.drop=(e,t)=>{try{tw(e,t,e.dragging)}finally{e.dragging=null}};function tw(e,t,n){if(!t.dataTransfer)return;let r=e.posAtCoords(CC(t));if(!r)return;let i=e.state.doc.resolve(r.pos),a=n&&n.slice;a?e.someProp(`transformPasted`,t=>{a=t(a,e,!1)}):a=ZS(e,ZC(t.dataTransfer),qC?null:t.dataTransfer.getData(`text/html`),!1,i);let o=!!(n&&ew(e,t));if(e.someProp(`handleDrop`,n=>n(e,t,a||Y.empty,o))){t.preventDefault();return}if(!a)return;t.preventDefault();let s=a?Uv(e.state.doc,i.pos,a):i.pos;s??=i.pos;let c=e.state.tr;if(o){let{node:e}=n;e?e.replace(c):c.deleteSelection()}let l=c.mapping.map(s),u=a.openStart==0&&a.openEnd==0&&a.content.childCount==1,d=c.doc;if(u?c.replaceRangeWith(l,l,a.content.firstChild):c.replaceRange(l,l,a),c.doc.eq(d))return;let f=c.doc.resolve(l);if(u&&X.isSelectable(a.content.firstChild)&&f.nodeAfter&&f.nodeAfter.sameMarkup(a.content.firstChild))c.setSelection(new X(f));else{let t=c.mapping.map(s);c.mapping.maps[c.mapping.maps.length-1].forEach((e,n,r,i)=>t=i),c.setSelection(OS(e,f,c.doc.resolve(t)))}e.focus(),e.dispatch(c.setMeta(`uiEvent`,`drop`))}fC.focus=e=>{e.input.lastFocus=Date.now(),e.focused||(e.domObserver.stop(),e.dom.classList.add(`ProseMirror-focused`),e.domObserver.start(),e.focused=!0,setTimeout(()=>{e.docView&&e.hasFocus()&&!e.domObserver.currentSelection.eq(e.domSelectionRange())&&yS(e)},20))},fC.blur=(e,t)=>{let n=t;e.focused&&=(e.domObserver.stop(),e.dom.classList.remove(`ProseMirror-focused`),e.domObserver.start(),n.relatedTarget&&e.dom.contains(n.relatedTarget)&&e.domObserver.currentSelection.clear(),!1)},fC.beforeinput=(e,t)=>{if(sx&&t.inputType==`deleteContentBackward`){e.domObserver.flushSoon();let{domChangeCount:t}=e.input;setTimeout(()=>{if(e.input.domChangeCount!=t||(e.dom.blur(),e.focus(),e.someProp(`handleKeyDown`,t=>t(e,Hb(8,`Backspace`)))))return;let{$cursor:n}=e.state.selection;n&&n.pos>0&&e.dispatch(e.state.tr.delete(n.pos-1,n.pos).scrollIntoView())},50)}};for(let e in pC)fC[e]=pC[e];function nw(e,t){if(e==t)return!0;for(let n in e)if(e[n]!==t[n])return!1;for(let n in t)if(!(n in e))return!1;return!0}var rw=class e{constructor(e,t){this.toDOM=e,this.spec=t||cw,this.side=this.spec.side||0}map(e,t,n,r){let{pos:i,deleted:a}=e.mapResult(t.from+r,this.side<0?-1:1);return a?null:new ow(i-n,i-n,this)}valid(){return!0}eq(t){return this==t||t instanceof e&&(this.spec.key&&this.spec.key==t.spec.key||this.toDOM==t.toDOM&&nw(this.spec,t.spec))}destroy(e){this.spec.destroy&&this.spec.destroy(e)}},iw=class e{constructor(e,t){this.attrs=e,this.spec=t||cw}map(e,t,n,r){let i=e.map(t.from+r,this.spec.inclusiveStart?-1:1)-n,a=e.map(t.to+r,this.spec.inclusiveEnd?1:-1)-n;return i>=a?null:new ow(i,a,this)}valid(e,t){return t.from<t.to}eq(t){return this==t||t instanceof e&&nw(this.attrs,t.attrs)&&nw(this.spec,t.spec)}static is(t){return t.type instanceof e}destroy(){}},aw=class e{constructor(e,t){this.attrs=e,this.spec=t||cw}map(e,t,n,r){let i=e.mapResult(t.from+r,1);if(i.deleted)return null;let a=e.mapResult(t.to+r,-1);return a.deleted||a.pos<=i.pos?null:new ow(i.pos-n,a.pos-n,this)}valid(e,t){let{index:n,offset:r}=e.content.findIndex(t.from),i;return r==t.from&&!(i=e.child(n)).isText&&r+i.nodeSize==t.to}eq(t){return this==t||t instanceof e&&nw(this.attrs,t.attrs)&&nw(this.spec,t.spec)}destroy(){}},ow=class e{constructor(e,t,n){this.from=e,this.to=t,this.type=n}copy(t,n){return new e(t,n,this.type)}eq(e,t=0){return this.type.eq(e.type)&&this.from+t==e.from&&this.to+t==e.to}map(e,t,n){return this.type.map(e,this,t,n)}static widget(t,n,r){return new e(t,t,new rw(n,r))}static inline(t,n,r,i){return new e(t,n,new iw(r,i))}static node(t,n,r,i){return new e(t,n,new aw(r,i))}get spec(){return this.type.spec}get inline(){return this.type instanceof iw}get widget(){return this.type instanceof rw}},sw=[],cw={},lw=class e{constructor(e,t){this.local=e.length?e:sw,this.children=t.length?t:sw}static create(e,t){return t.length?_w(t,e,0,cw):uw}find(e,t,n){let r=[];return this.findInner(e??0,t??1e9,r,0,n),r}findInner(e,t,n,r,i){for(let a=0;a<this.local.length;a++){let o=this.local[a];o.from<=t&&o.to>=e&&(!i||i(o.spec))&&n.push(o.copy(o.from+r,o.to+r))}for(let a=0;a<this.children.length;a+=3)if(this.children[a]<t&&this.children[a+1]>e){let o=this.children[a]+1;this.children[a+2].findInner(e-o,t-o,n,r+o,i)}}map(e,t,n){return this==uw||e.maps.length==0?this:this.mapInner(e,t,0,0,n||cw)}mapInner(t,n,r,i,a){let o;for(let e=0;e<this.local.length;e++){let s=this.local[e].map(t,r,i);s&&s.type.valid(n,s)?(o||=[]).push(s):a.onRemove&&a.onRemove(this.local[e].spec)}return this.children.length?fw(this.children,o||[],t,n,r,i,a):o?new e(o.sort(vw),sw):uw}add(t,n){return n.length?this==uw?e.create(t,n):this.addInner(t,n,0):this}addInner(t,n,r){let i,a=0;t.forEach((e,t)=>{let o=t+r,s;if(s=hw(n,e,o)){for(i||=this.children.slice();a<i.length&&i[a]<t;)a+=3;i[a]==t?i[a+2]=i[a+2].addInner(e,s,o+1):i.splice(a,0,t,t+e.nodeSize,_w(s,e,o+1,cw)),a+=3}});let o=pw(a?gw(n):n,-r);for(let e=0;e<o.length;e++)o[e].type.valid(t,o[e])||o.splice(e--,1);return new e(o.length?this.local.concat(o).sort(vw):this.local,i||this.children)}remove(e){return e.length==0||this==uw?this:this.removeInner(e,0)}removeInner(t,n){let r=this.children,i=this.local;for(let e=0;e<r.length;e+=3){let i,a=r[e]+n,o=r[e+1]+n;for(let e=0,n;e<t.length;e++)(n=t[e])&&n.from>a&&n.to<o&&(t[e]=null,(i||=[]).push(n));if(!i)continue;r==this.children&&(r=this.children.slice());let s=r[e+2].removeInner(i,a+1);s==uw?(r.splice(e,3),e-=3):r[e+2]=s}if(i.length){for(let e=0,r;e<t.length;e++)if(r=t[e])for(let e=0;e<i.length;e++)i[e].eq(r,n)&&(i==this.local&&(i=this.local.slice()),i.splice(e--,1))}return r==this.children&&i==this.local?this:i.length||r.length?new e(i,r):uw}forChild(t,n){if(this==uw)return this;if(n.isLeaf)return e.empty;let r,i;for(let e=0;e<this.children.length;e+=3)if(this.children[e]>=t){this.children[e]==t&&(r=this.children[e+2]);break}let a=t+1,o=a+n.content.size;for(let e=0;e<this.local.length;e++){let t=this.local[e];if(t.from<o&&t.to>a&&t.type instanceof iw){let e=Math.max(a,t.from)-a,n=Math.min(o,t.to)-a;e<n&&(i||=[]).push(t.copy(e,n))}}if(i){let t=new e(i.sort(vw),sw);return r?new dw([t,r]):t}return r||uw}eq(t){if(this==t)return!0;if(!(t instanceof e)||this.local.length!=t.local.length||this.children.length!=t.children.length)return!1;for(let e=0;e<this.local.length;e++)if(!this.local[e].eq(t.local[e]))return!1;for(let e=0;e<this.children.length;e+=3)if(this.children[e]!=t.children[e]||this.children[e+1]!=t.children[e+1]||!this.children[e+2].eq(t.children[e+2]))return!1;return!0}locals(e){return yw(this.localsInner(e))}localsInner(e){if(this==uw)return sw;if(e.inlineContent||!this.local.some(iw.is))return this.local;let t=[];for(let e=0;e<this.local.length;e++)this.local[e].type instanceof iw||t.push(this.local[e]);return t}forEachSet(e){e(this)}};lw.empty=new lw([],[]),lw.removeOverlap=yw;var uw=lw.empty,dw=class e{constructor(e){this.members=e}map(t,n){let r=this.members.map(e=>e.map(t,n,cw));return e.from(r)}forChild(t,n){if(n.isLeaf)return lw.empty;let r=[];for(let i=0;i<this.members.length;i++){let a=this.members[i].forChild(t,n);a!=uw&&(a instanceof e?r=r.concat(a.members):r.push(a))}return e.from(r)}eq(t){if(!(t instanceof e)||t.members.length!=this.members.length)return!1;for(let e=0;e<this.members.length;e++)if(!this.members[e].eq(t.members[e]))return!1;return!0}locals(e){let t,n=!0;for(let r=0;r<this.members.length;r++){let i=this.members[r].localsInner(e);if(i.length)if(!t)t=i;else{n&&=(t=t.slice(),!1);for(let e=0;e<i.length;e++)t.push(i[e])}}return t?yw(n?t:t.sort(vw)):sw}static from(t){switch(t.length){case 0:return uw;case 1:return t[0];default:return new e(t.every(e=>e instanceof lw)?t:t.reduce((e,t)=>e.concat(t instanceof lw?t:t.members),[]))}}forEachSet(e){for(let t=0;t<this.members.length;t++)this.members[t].forEachSet(e)}};function fw(e,t,n,r,i,a,o){let s=e.slice();for(let e=0,t=a;e<n.maps.length;e++){let r=0;n.maps[e].forEach((e,n,i,a)=>{let o=a-i-(n-e);for(let i=0;i<s.length;i+=3){let a=s[i+1];if(a<0||e>a+t-r)continue;let c=s[i]+t-r;n>=c?s[i+1]=e<=c?-2:-1:e>=t&&o&&(s[i]+=o,s[i+1]+=o)}r+=o}),t=n.maps[e].map(t,-1)}let c=!1;for(let t=0;t<s.length;t+=3)if(s[t+1]<0){if(s[t+1]==-2){c=!0,s[t+1]=-1;continue}let l=n.map(e[t]+a),u=l-i;if(u<0||u>=r.content.size){c=!0;continue}let d=n.map(e[t+1]+a,-1)-i,{index:f,offset:p}=r.content.findIndex(u),m=r.maybeChild(f);if(m&&p==u&&p+m.nodeSize==d){let r=s[t+2].mapInner(n,m,l+1,e[t]+a+1,o);r==uw?(s[t+1]=-2,c=!0):(s[t]=u,s[t+1]=d,s[t+2]=r)}else c=!0}if(c){let c=_w(mw(s,e,t,n,i,a,o),r,0,o);t=c.local;for(let e=0;e<s.length;e+=3)s[e+1]<0&&(s.splice(e,3),e-=3);for(let e=0,t=0;e<c.children.length;e+=3){let n=c.children[e];for(;t<s.length&&s[t]<n;)t+=3;s.splice(t,0,c.children[e],c.children[e+1],c.children[e+2])}}return new lw(t.sort(vw),s)}function pw(e,t){if(!t||!e.length)return e;let n=[];for(let r=0;r<e.length;r++){let i=e[r];n.push(new ow(i.from+t,i.to+t,i.type))}return n}function mw(e,t,n,r,i,a,o){function s(e,t){for(let a=0;a<e.local.length;a++){let s=e.local[a].map(r,i,t);s?n.push(s):o.onRemove&&o.onRemove(e.local[a].spec)}for(let n=0;n<e.children.length;n+=3)s(e.children[n+2],e.children[n]+t+1)}for(let n=0;n<e.length;n+=3)e[n+1]==-1&&s(e[n+2],t[n]+a+1);return n}function hw(e,t,n){if(t.isLeaf)return null;let r=n+t.nodeSize,i=null;for(let t=0,a;t<e.length;t++)(a=e[t])&&a.from>n&&a.to<r&&((i||=[]).push(a),e[t]=null);return i}function gw(e){let t=[];for(let n=0;n<e.length;n++)e[n]!=null&&t.push(e[n]);return t}function _w(e,t,n,r){let i=[],a=!1;t.forEach((t,o)=>{let s=hw(e,t,o+n);if(s){a=!0;let e=_w(s,t,n+o+1,r);e!=uw&&i.push(o,o+t.nodeSize,e)}});let o=pw(a?gw(e):e,-n).sort(vw);for(let e=0;e<o.length;e++)o[e].type.valid(t,o[e])||(r.onRemove&&r.onRemove(o[e].spec),o.splice(e--,1));return o.length||i.length?new lw(o,i):uw}function vw(e,t){return e.from-t.from||e.to-t.to}function yw(e){let t=e;for(let n=0;n<t.length-1;n++){let r=t[n];if(r.from!=r.to)for(let i=n+1;i<t.length;i++){let a=t[i];if(a.from==r.from){a.to!=r.to&&(t==e&&(t=e.slice()),t[i]=a.copy(a.from,r.to),bw(t,i+1,a.copy(r.to,a.to)));continue}else{a.from<r.to&&(t==e&&(t=e.slice()),t[n]=r.copy(r.from,a.from),bw(t,i,r.copy(a.from,r.to)));break}}}return t}function bw(e,t,n){for(;t<e.length&&vw(n,e[t])>0;)t++;e.splice(t,0,n)}function xw(e){let t=[];return e.someProp(`decorations`,n=>{let r=n(e.state);r&&r!=uw&&t.push(r)}),e.cursorWrapper&&t.push(lw.create(e.state.doc,[e.cursorWrapper.deco])),dw.from(t)}var Sw={childList:!0,characterData:!0,characterDataOldValue:!0,attributes:!0,attributeOldValue:!0,subtree:!0},Cw=Zb&&Qb<=11,ww=class{constructor(){this.anchorNode=null,this.anchorOffset=0,this.focusNode=null,this.focusOffset=0}set(e){this.anchorNode=e.anchorNode,this.anchorOffset=e.anchorOffset,this.focusNode=e.focusNode,this.focusOffset=e.focusOffset}clear(){this.anchorNode=this.focusNode=null}eq(e){return e.anchorNode==this.anchorNode&&e.anchorOffset==this.anchorOffset&&e.focusNode==this.focusNode&&e.focusOffset==this.focusOffset}},Tw=class{constructor(e,t){this.view=e,this.handleDOMChange=t,this.queue=[],this.flushingSoon=-1,this.observer=null,this.currentSelection=new ww,this.onCharData=null,this.suppressingSelectionUpdates=!1,this.lastChangedTextNode=null,this.observer=window.MutationObserver&&new window.MutationObserver(t=>{for(let e=0;e<t.length;e++)this.queue.push(t[e]);Zb&&Qb<=11&&t.some(e=>e.type==`childList`&&e.removedNodes.length||e.type==`characterData`&&e.oldValue.length>e.target.nodeValue.length)?this.flushSoon():rx&&e.composing&&t.some(e=>e.type==`childList`&&e.target.nodeName==`TR`)?(e.input.badSafariComposition=!0,this.flushSoon()):this.flush()}),Cw&&(this.onCharData=e=>{this.queue.push({target:e.target,type:`characterData`,oldValue:e.prevValue}),this.flushSoon()}),this.onSelectionChange=this.onSelectionChange.bind(this)}flushSoon(){this.flushingSoon<0&&(this.flushingSoon=window.setTimeout(()=>{this.flushingSoon=-1,this.flush()},20))}forceFlush(){this.flushingSoon>-1&&(window.clearTimeout(this.flushingSoon),this.flushingSoon=-1,this.flush())}start(){this.observer&&(this.observer.takeRecords(),this.observer.observe(this.view.dom,Sw)),this.onCharData&&this.view.dom.addEventListener(`DOMCharacterDataModified`,this.onCharData),this.connectSelection()}stop(){if(this.observer){let e=this.observer.takeRecords();if(e.length){for(let t=0;t<e.length;t++)this.queue.push(e[t]);window.setTimeout(()=>this.flush(),20)}this.observer.disconnect()}this.onCharData&&this.view.dom.removeEventListener(`DOMCharacterDataModified`,this.onCharData),this.disconnectSelection()}connectSelection(){this.view.dom.ownerDocument.addEventListener(`selectionchange`,this.onSelectionChange)}disconnectSelection(){this.view.dom.ownerDocument.removeEventListener(`selectionchange`,this.onSelectionChange)}suppressSelectionUpdates(){this.suppressingSelectionUpdates=!0,setTimeout(()=>this.suppressingSelectionUpdates=!1,50)}onSelectionChange(){if(kS(this.view)){if(this.suppressingSelectionUpdates)return yS(this.view);if(Zb&&Qb<=11&&!this.view.state.selection.empty){let e=this.view.domSelectionRange();if(e.focusNode&&jb(e.focusNode,e.focusOffset,e.anchorNode,e.anchorOffset))return this.flushSoon()}this.flush()}}setCurSelection(){this.currentSelection.set(this.view.domSelectionRange())}ignoreSelectionChange(e){if(!e.focusNode)return!0;let t=new Set,n;for(let n=e.focusNode;n;n=Db(n))t.add(n);for(let r=e.anchorNode;r;r=Db(r))if(t.has(r)){n=r;break}let r=n&&this.view.docView.nearestDesc(n);if(r&&r.ignoreMutation({type:`selection`,target:Fb(n)?n.parentNode:n}))return this.setCurSelection(),!0}pendingRecords(){if(this.observer)for(let e of this.observer.takeRecords())this.queue.push(e);return this.queue}flush(){let{view:e}=this;if(!e.docView||this.flushingSoon>-1)return;let t=this.pendingRecords();t.length&&(this.queue=[]);let n=e.domSelectionRange(),r=!this.suppressingSelectionUpdates&&!this.currentSelection.eq(n)&&kS(e)&&!this.ignoreSelectionChange(n),i=-1,a=-1,o=!1,s=[];if(e.editable)for(let e=0;e<t.length;e++){let n=this.registerMutation(t[e],s);n&&(i=i<0?n.from:Math.min(n.from,i),a=a<0?n.to:Math.max(n.to,a),n.typeOver&&(o=!0))}if(s.some(e=>e.nodeName==`BR`)&&(e.input.lastKeyCode==8||e.input.lastKeyCode==46||tx&&(e.composing||e.input.compositionEndedAt>Date.now()-50)&&t.some(e=>e.type==`childList`&&e.removedNodes.length))){for(let e of s)if(e.nodeName==`BR`&&e.parentNode){let t=e.nextSibling;for(;t&&Z(t);){if(t.contentEditable==`false`){e.parentNode.removeChild(e);break}t=t.firstChild}}}else if($b&&s.length){let t=s.filter(e=>e.nodeName==`BR`);if(t.length==2){let[e,n]=t;e.parentNode&&e.parentNode.parentNode==n.parentNode?n.remove():e.remove()}else{let{focusNode:n}=this.currentSelection;for(let r of t){let t=r.parentNode;t&&t.nodeName==`LI`&&(!n||jw(e,n)!=t)&&r.remove()}}}let c=null;i<0&&r&&e.input.lastFocus>Date.now()-200&&Math.max(e.input.lastTouch,e.input.lastClick.time)<Date.now()-300&&Vb(n)&&(c=_S(e))&&c.eq(dy.near(e.state.doc.resolve(0),1))?(e.input.lastFocus=0,yS(e),this.currentSelection.set(n),e.scrollToSelection()):(i>-1||r)&&(i>-1&&(e.docView.markDirty(i,a),Ow(e)),e.input.badSafariComposition&&(e.input.badSafariComposition=!1,Mw(e,s)),this.handleDOMChange(i,a,o,s),e.docView&&e.docView.dirty?e.updateState(e.state):this.currentSelection.eq(n)||yS(e),this.currentSelection.set(n))}registerMutation(e,t){if(t.indexOf(e.target)>-1)return null;let n=this.view.docView.nearestDesc(e.target);if(e.type==`attributes`&&(n==this.view.docView||e.attributeName==`contenteditable`||e.attributeName==`style`&&!e.oldValue&&!e.target.getAttribute(`style`))||!n||n.ignoreMutation(e))return null;if(e.type==`childList`){for(let n=0;n<e.addedNodes.length;n++){let r=e.addedNodes[n];t.push(r),Fb(r)&&(this.lastChangedTextNode=r)}if(n.contentDOM&&n.contentDOM!=n.dom&&!n.contentDOM.contains(e.target))return{from:n.posBefore,to:n.posAfter};let r=e.previousSibling,i=e.nextSibling;if(Zb&&Qb<=11&&e.addedNodes.length)for(let t=0;t<e.addedNodes.length;t++){let{previousSibling:n,nextSibling:a}=e.addedNodes[t];(!n||Array.prototype.indexOf.call(e.addedNodes,n)<0)&&(r=n),(!a||Array.prototype.indexOf.call(e.addedNodes,a)<0)&&(i=a)}let a=r&&r.parentNode==e.target?Eb(r)+1:0,o=n.localPosFromDOM(e.target,a,-1),s=i&&i.parentNode==e.target?Eb(i):e.target.childNodes.length;return{from:o,to:n.localPosFromDOM(e.target,s,1)}}else if(e.type==`attributes`)return{from:n.posAtStart-n.border,to:n.posAtEnd+n.border};else return this.lastChangedTextNode=e.target,{from:n.posAtStart,to:n.posAtEnd,typeOver:e.target.nodeValue==e.oldValue}}},Ew=new WeakMap,Dw=!1;function Ow(e){if(!Ew.has(e)&&(Ew.set(e,null),[`normal`,`nowrap`,`pre-line`].indexOf(getComputedStyle(e.dom).whiteSpace)!==-1)){if(e.requiresGeckoHackNode=$b,Dw)return;console.warn(`ProseMirror expects the CSS white-space property to be set, preferably to 'pre-wrap'. It is recommended to load style/prosemirror.css from the prosemirror-view package.`),Dw=!0}}function kw(e,t){let n=t.startContainer,r=t.startOffset,i=t.endContainer,a=t.endOffset,o=e.domAtPos(e.state.selection.anchor);return jb(o.node,o.offset,i,a)&&([n,r,i,a]=[i,a,n,r]),{anchorNode:n,anchorOffset:r,focusNode:i,focusOffset:a}}function Aw(e,t){if(t.getComposedRanges){let n=t.getComposedRanges(e.root)[0];if(n)return kw(e,n)}let n;function r(e){e.preventDefault(),e.stopImmediatePropagation(),n=e.getTargetRanges()[0]}return e.dom.addEventListener(`beforeinput`,r,!0),document.execCommand(`indent`),e.dom.removeEventListener(`beforeinput`,r,!0),n?kw(e,n):null}function jw(e,t){for(let n=t.parentNode;n&&n!=e.dom;n=n.parentNode){let t=e.docView.nearestDesc(n,!0);if(t&&t.node.isBlock)return n}return null}function Mw(e,t){let{focusNode:n,focusOffset:r}=e.domSelectionRange();for(let i of t)if(i.parentNode?.nodeName==`TR`){let t=i.nextSibling;for(;t&&t.nodeName!=`TD`&&t.nodeName!=`TH`;)t=t.nextSibling;if(t){let a=t;for(;;){let e=a.firstChild;if(!e||!Z(e)||e.contentEditable==`false`||/^(BR|IMG)$/.test(e.nodeName))break;a=e}a.insertBefore(i,a.firstChild),n==i&&e.domSelection().collapse(i,r)}else i.parentNode.removeChild(i)}}function Nw(e,t,n,r){let{node:i,fromOffset:a,toOffset:o,from:s,to:c}=e.docView.parseRange(t,n),l=e.domSelectionRange(),u,d=l.anchorNode;if(d&&Ib(e.dom,d)&&(u=[{node:d,offset:l.anchorOffset}],Vb(l)||u.push({node:l.focusNode,offset:l.focusOffset})),tx&&e.input.lastKeyCode===8)for(let e=o;e>a;e--){let t=i.childNodes[e-1],n=t.pmViewDesc;if(t.nodeName==`BR`&&!n){o=e;break}if(!n||n.size)break}let f=e.state.doc,p=e.someProp(`domParser`)||k_.fromSchema(e.state.schema),m=f.resolve(s),h=null,g=p.parse(i,{topNode:m.parent,topMatch:m.parent.contentMatchAt(m.index()),topOpen:!0,from:a,to:o,preserveWhitespace:m.parent.type.whitespace==`pre`?`full`:!0,findPositions:u,ruleFromNode:Pw(r),context:m});if(u&&u[0].pos!=null){let e=u[0].pos,t=u[1]&&u[1].pos;t??=e,h={anchor:e+s,head:t+s}}return{doc:g,sel:h,from:s,to:c}}var Pw=e=>t=>{let n=t.pmViewDesc;if(n)return n.parseRule(e);if(t.nodeName==`BR`&&t.parentNode){if(rx&&/^(ul|ol)$/i.test(t.parentNode.nodeName)){let e=document.createElement(`div`);return e.appendChild(document.createElement(`li`)),{skip:e}}else if(t.parentNode.lastChild==t||rx&&/^(tr|table)$/i.test(t.parentNode.nodeName))return{ignore:!0}}else if(t.nodeName==`IMG`&&t.getAttribute(`mark-placeholder`))return{ignore:!0};return null},Fw=/^(a|abbr|acronym|b|bd[io]|big|br|button|cite|code|data(list)?|del|dfn|em|i|img|ins|kbd|label|map|mark|meter|output|q|ruby|s|samp|small|span|strong|su[bp]|time|u|tt|var)$/i;function Iw(e,t,n,r,i){let a=e.input.compositionPendingChanges||(e.composing?e.input.compositionID:0);if(e.input.compositionPendingChanges=0,t<0){let t=e.input.lastSelectionTime>Date.now()-50?e.input.lastSelectionOrigin:null,n=_S(e,t);if(n&&!e.state.selection.eq(n)){if(tx&&sx&&e.input.lastKeyCode===13&&Date.now()-100<e.input.lastKeyCodeTime&&e.someProp(`handleKeyDown`,t=>t(e,Hb(13,`Enter`))))return;let r=e.state.tr.setSelection(n);t==`pointer`?r.setMeta(`pointer`,!0):t==`key`&&r.scrollIntoView(),a&&r.setMeta(`composition`,a),e.dispatch(r)}return}let o=e.state.doc.resolve(t),s=o.sharedDepth(n);t=o.before(s+1),n=e.state.doc.resolve(n).after(s+1);let c=e.state.selection,l=Nw(e,t,n,i),u=e.state.doc,d=u.slice(l.from,l.to),f,p;e.input.lastKeyCode===8&&Date.now()-100<e.input.lastKeyCodeTime?(f=e.state.selection.to,p=`end`):(f=e.state.selection.from,p=`start`),e.input.lastKeyCode=null;let m=Hw(d.content,l.doc.content,l.from,f,p);if(m&&e.input.domChangeCount++,(ix&&e.input.lastIOSEnter>Date.now()-225||sx)&&i.some(e=>Z(e)&&!Fw.test(e.nodeName))&&(!m||m.endA>=m.endB)&&e.someProp(`handleKeyDown`,t=>t(e,Hb(13,`Enter`)))){e.input.lastIOSEnter=0;return}if(!m)if(r&&c instanceof hy&&!c.empty&&c.$head.sameParent(c.$anchor)&&!e.composing&&!(l.sel&&l.sel.anchor!=l.sel.head))m={start:c.from,endA:c.to,endB:c.to};else{if(l.sel){let t=Lw(e,e.state.doc,l.sel);if(t&&!t.eq(e.state.selection)){let n=e.state.tr.setSelection(t);a&&n.setMeta(`composition`,a),e.dispatch(n)}}return}e.state.selection.from<e.state.selection.to&&m.start==m.endB&&e.state.selection instanceof hy&&(m.start>e.state.selection.from&&m.start<=e.state.selection.from+2&&e.state.selection.from>=l.from?m.start=e.state.selection.from:m.endA<e.state.selection.to&&m.endA>=e.state.selection.to-2&&e.state.selection.to<=l.to&&(m.endB+=e.state.selection.to-m.endA,m.endA=e.state.selection.to)),Zb&&Qb<=11&&m.endB==m.start+1&&m.endA==m.start&&m.start>l.from&&l.doc.textBetween(m.start-l.from-1,m.start-l.from+1)==` \xA0`&&(m.start--,m.endA--,m.endB--);let h=l.doc.resolveNoCache(m.start-l.from),g=l.doc.resolveNoCache(m.endB-l.from),_=u.resolve(m.start),v=h.sameParent(g)&&h.parent.inlineContent&&_.end()>=m.endA;if((ix&&e.input.lastIOSEnter>Date.now()-225&&(!v||i.some(e=>e.nodeName==`DIV`||e.nodeName==`P`))||!v&&Bw(l.doc,h.pos,g.pos))&&e.someProp(`handleKeyDown`,t=>t(e,Hb(13,`Enter`)))){e.input.lastIOSEnter=0;return}if(e.state.selection.anchor>m.start&&zw(u,m.start,m.endA,h,g)&&e.someProp(`handleKeyDown`,t=>t(e,Hb(8,`Backspace`)))){sx&&tx&&e.domObserver.suppressSelectionUpdates();return}tx&&m.endB==m.start&&(e.input.lastChromeDelete=Date.now()),sx&&!v&&h.start()!=g.start()&&g.parentOffset==0&&h.depth==g.depth&&l.sel&&l.sel.anchor==l.sel.head&&l.sel.head==m.endA&&(m.endB-=2,g=l.doc.resolveNoCache(m.endB-l.from),setTimeout(()=>{e.someProp(`handleKeyDown`,function(t){return t(e,Hb(13,`Enter`))})},20));let y=m.start,b=m.endA,x=t=>{let n=t||e.state.tr.replace(y,b,l.doc.slice(m.start-l.from,m.endB-l.from));if(l.sel){let t=Lw(e,n.doc,l.sel);t&&!(tx&&e.composing&&t.empty&&(m.start!=m.endB||e.input.lastChromeDelete<Date.now()-100)&&(t.head==y||t.head==n.mapping.map(b)-1)||Zb&&t.empty&&t.head==y)&&n.setSelection(t)}return a&&n.setMeta(`composition`,a),n.scrollIntoView()},S;if(v)if(h.pos==g.pos){Zb&&Qb<=11&&h.parentOffset==0&&(e.domObserver.suppressSelectionUpdates(),setTimeout(()=>yS(e),20));let t=x(e.state.tr.delete(y,b)),n=u.resolve(m.start).marksAcross(u.resolve(m.endA));n&&t.ensureMarks(n),e.dispatch(t)}else if(m.endA==m.endB&&(S=Rw(h.parent.content.cut(h.parentOffset,g.parentOffset),_.parent.content.cut(_.parentOffset,m.endA-_.start())))){let t=x(e.state.tr);S.type==`add`?t.addMark(y,b,S.mark):t.removeMark(y,b,S.mark),e.dispatch(t)}else if(h.parent.child(h.index()).isText&&h.index()==g.index()-+!g.textOffset){let t=h.parent.textBetween(h.parentOffset,g.parentOffset),n=()=>x(e.state.tr.insertText(t,y,b));e.someProp(`handleTextInput`,r=>r(e,y,b,t,n))||e.dispatch(n())}else e.dispatch(x());else e.dispatch(x())}function Lw(e,t,n){return Math.max(n.anchor,n.head)>t.content.size?null:OS(e,t.resolve(n.anchor),t.resolve(n.head))}function Rw(e,t){let n=e.firstChild.marks,r=t.firstChild.marks,i=n,a=r,o,s,c;for(let e=0;e<r.length;e++)i=r[e].removeFromSet(i);for(let e=0;e<n.length;e++)a=n[e].removeFromSet(a);if(i.length==1&&a.length==0)s=i[0],o=`add`,c=e=>e.mark(s.addToSet(e.marks));else if(i.length==0&&a.length==1)s=a[0],o=`remove`,c=e=>e.mark(s.removeFromSet(e.marks));else return null;let l=[];for(let e=0;e<t.childCount;e++)l.push(c(t.child(e)));if(J.from(l).eq(e))return{mark:s,type:o}}function zw(e,t,n,r,i){if(n-t<=i.pos-r.pos||Vw(r,!0,!1)<i.pos)return!1;let a=e.resolve(t);if(!r.parent.isTextblock){let e=a.nodeAfter;return e!=null&&n==t+e.nodeSize}if(a.parentOffset<a.parent.content.size||!a.parent.isTextblock)return!1;let o=e.resolve(Vw(a,!0,!0));return!o.parent.isTextblock||o.pos>n||Vw(o,!0,!1)<n?!1:r.parent.content.cut(r.parentOffset).eq(o.parent.content)}function Bw(e,t,n){let r=0,i=0;return e.nodesBetween(t,n,(e,a)=>{e.isTextblock&&a>=t&&a<n?r++:(e.isText?/\S/.test(e.text.slice(Math.max(0,t-a),Math.min(e.nodeSize,n-a))):e.isLeaf)&&i++}),i==0&&r==1}function Vw(e,t,n){let r=e.depth,i=t?e.end():e.pos;for(;r>0&&(t||e.indexAfter(r)==e.node(r).childCount);)r--,i++,t=!1;if(n){let t=e.node(r).maybeChild(e.indexAfter(r));for(;t&&!t.isLeaf;)t=t.firstChild,i++}return i}function Hw(e,t,n,r,i){let a=e.findDiffStart(t,n),o=n+e.size,s=n+t.size;if(a==null)return null;let{a:c,b:l}=e.findDiffEnd(t,o,s);if(i==`end`){let e=Math.max(0,a-Math.min(c,l));r-=c+e-a}if(c<a&&o<s){let e=r<=a&&r>=c?a-r:0;a-=e,l=a+(l-c),c=a}else if(l<a){let e=r<=a&&r>=l?a-r:0;a-=e,c=a+(c-l),l=a}return{start:a,endA:c,endB:l}}var Uw=class{constructor(e,t){this._root=null,this.focused=!1,this.trackWrites=null,this.mounted=!1,this.markCursor=null,this.cursorWrapper=null,this.lastSelectedViewDesc=void 0,this.input=new hC,this.prevDirectPlugins=[],this.pluginViews=[],this.requiresGeckoHackNode=!1,this.dragging=null,this._props=t,this.state=t.state,this.directPlugins=t.plugins||[],this.directPlugins.forEach(Xw),this.dispatch=this.dispatch.bind(this),this.dom=e&&e.mount||document.createElement(`div`),e&&(e.appendChild?e.appendChild(this.dom):typeof e==`function`?e(this.dom):e.mount&&(this.mounted=!0)),this.editable=Kw(this),Gw(this),this.nodeViews=Jw(this),this.docView=Zx(this.state.doc,Ww(this),xw(this),this.dom,this),this.domObserver=new Tw(this,(e,t,n,r)=>Iw(this,e,t,n,r)),this.domObserver.start(),gC(this),this.updatePluginViews()}get composing(){return this.input.composing}get props(){if(this._props.state!=this.state){let e=this._props;this._props={};for(let t in e)this._props[t]=e[t];this._props.state=this.state}return this._props}update(e){e.handleDOMEvents!=this._props.handleDOMEvents&&yC(this);let t=this._props;this._props=e,e.plugins&&(e.plugins.forEach(Xw),this.directPlugins=e.plugins),this.updateStateInner(e.state,t)}setProps(e){let t={};for(let e in this._props)t[e]=this._props[e];t.state=this.state;for(let n in e)t[n]=e[n];this.update(t)}updateState(e){this.updateStateInner(e,this._props)}updateStateInner(e,t){let n=this.state,r=!1,i=!1;e.storedMarks&&this.composing&&(UC(this),i=!0),this.state=e;let a=n.plugins!=e.plugins||this._props.plugins!=t.plugins;if(a||this._props.plugins!=t.plugins||this._props.nodeViews!=t.nodeViews){let e=Jw(this);Yw(e,this.nodeViews)&&(this.nodeViews=e,r=!0)}(a||t.handleDOMEvents!=this._props.handleDOMEvents)&&yC(this),this.editable=Kw(this),Gw(this);let o=xw(this),s=Ww(this),c=n.plugins!=e.plugins&&!n.doc.eq(e.doc)?`reset`:e.scrollToSelection>n.scrollToSelection?`to selection`:`preserve`,l=r||!this.docView.matchesNode(e.doc,s,o);(l||!e.selection.eq(n.selection))&&(i=!0);let u=c==`preserve`&&i&&this.dom.style.overflowAnchor==null&&mx(this);if(i){this.domObserver.stop();let t=l&&(Zb||tx)&&!this.composing&&!n.selection.empty&&!e.selection.empty&&qw(n.selection,e.selection);if(l){let n=tx?this.trackWrites=this.domSelectionRange().focusNode:null;this.composing&&(this.input.compositionNode=WC(this)),(r||!this.docView.update(e.doc,s,o,this))&&(this.docView.updateOuterDeco(s),this.docView.destroy(),this.docView=Zx(e.doc,s,o,this.dom,this)),n&&(!this.trackWrites||!this.dom.contains(this.trackWrites))&&(t=!0)}let i=this.input.mouseDown;t||!(i&&this.domObserver.currentSelection.eq(this.domSelectionRange())&&jS(this)&&i.delaySelUpdate())?yS(this,t):(ES(this,e.selection),this.domObserver.setCurSelection()),this.domObserver.start()}this.updatePluginViews(n),this.dragging?.node&&!n.doc.eq(e.doc)&&this.updateDraggedNode(this.dragging,n),c==`reset`?this.dom.scrollTop=0:c==`to selection`?this.scrollToSelection():u&&gx(u)}scrollToSelection(){let e=this.domSelectionRange().focusNode;if(!(!e||!Ib(this.dom,e))&&!this.someProp(`handleScrollToSelection`,e=>e(this)))if(this.state.selection instanceof X){let t=this.docView.domAfterPos(this.state.selection.from);Z(t)&&px(this,t.getBoundingClientRect(),e)}else px(this,this.coordsAtPos(this.state.selection.head,1),e)}destroyPluginViews(){let e;for(;e=this.pluginViews.pop();)e.destroy&&e.destroy()}updatePluginViews(e){if(!e||e.plugins!=this.state.plugins||this.directPlugins!=this.prevDirectPlugins){this.prevDirectPlugins=this.directPlugins,this.destroyPluginViews();for(let e=0;e<this.directPlugins.length;e++){let t=this.directPlugins[e];t.spec.view&&this.pluginViews.push(t.spec.view(this))}for(let e=0;e<this.state.plugins.length;e++){let t=this.state.plugins[e];t.spec.view&&this.pluginViews.push(t.spec.view(this))}}else for(let t=0;t<this.pluginViews.length;t++){let n=this.pluginViews[t];n.update&&n.update(this,e)}}updateDraggedNode(e,t){let n=e.node,r=-1;if(n.from<this.state.doc.content.size&&this.state.doc.nodeAt(n.from)==n.node)r=n.from;else{let e=n.from+(this.state.doc.content.size-t.doc.content.size);(e>0&&e<this.state.doc.content.size&&this.state.doc.nodeAt(e))==n.node&&(r=e)}this.dragging=new QC(e.slice,e.move,r<0?void 0:X.create(this.state.doc,r))}someProp(e,t){let n=this._props&&this._props[e],r;if(n!=null&&(r=t?t(n):n))return r;for(let n=0;n<this.directPlugins.length;n++){let i=this.directPlugins[n].props[e];if(i!=null&&(r=t?t(i):i))return r}let i=this.state.plugins;if(i)for(let n=0;n<i.length;n++){let a=i[n].props[e];if(a!=null&&(r=t?t(a):a))return r}}hasFocus(){if(Zb){let e=this.root.activeElement;if(e==this.dom)return!0;if(!e||!this.dom.contains(e))return!1;for(;e&&this.dom!=e&&this.dom.contains(e);){if(e.contentEditable==`false`)return!1;e=e.parentElement}return!0}return this.root.activeElement==this.dom}focus(){this.domObserver.stop(),this.editable&&yx(this.dom),yS(this),this.domObserver.start()}get root(){let e=this._root;if(e==null){for(let e=this.dom.parentNode;e;e=e.parentNode)if(e.nodeType==9||e.nodeType==11&&e.host)return e.getSelection||(Object.getPrototypeOf(e).getSelection=()=>e.ownerDocument.getSelection()),this._root=e}return e||document}updateRoot(){this._root=null}posAtCoords(e){return Dx(this,e)}coordsAtPos(e,t=1){return jx(this,e,t)}domAtPos(e,t=0){return this.docView.domFromPos(e,t)}nodeDOM(e){let t=this.docView.descAt(e);return t?t.nodeDOM:null}posAtDOM(e,t,n=-1){let r=this.docView.posFromDOM(e,t,n);if(r==null)throw RangeError(`DOM position not inside the editor`);return r}endOfTextblock(e,t){return Vx(this,t||this.state,e)}pasteHTML(e,t){return XC(this,``,e,!1,t||new ClipboardEvent(`paste`))}pasteText(e,t){return XC(this,e,null,!0,t||new ClipboardEvent(`paste`))}serializeForClipboard(e){return XS(this,e)}destroy(){this.docView&&(vC(this),this.destroyPluginViews(),this.mounted?(this.docView.update(this.state.doc,[],xw(this),this),this.dom.textContent=``):this.dom.parentNode&&this.dom.parentNode.removeChild(this.dom),this.docView.destroy(),this.docView=null,Ab())}get isDestroyed(){return this.docView==null}dispatchEvent(e){return SC(this,e)}domSelectionRange(){let e=this.dom.isConnected!==!1&&this.domSelection();return e?rx&&this.root.nodeType===11&&Ub(this.dom.ownerDocument)==this.dom&&Aw(this,e)||e:{focusNode:null,focusOffset:0,anchorNode:null,anchorOffset:0}}domSelection(){return this.root.getSelection()}};Uw.prototype.dispatch=function(e){let t=this._props.dispatchTransaction;t?t.call(this,e):this.updateState(this.state.apply(e))};function Ww(e){let t=Object.create(null);return t.class=`ProseMirror`,t.contenteditable=String(e.editable),e.someProp(`attributes`,n=>{if(typeof n==`function`&&(n=n(e.state)),n)for(let e in n)e==`class`?t.class+=` `+n[e]:e==`style`?t.style=(t.style?t.style+`;`:``)+n[e]:!t[e]&&e!=`contenteditable`&&e!=`nodeName`&&(t[e]=String(n[e]))}),t.translate||=`no`,[ow.node(0,e.state.doc.content.size,t)]}function Gw(e){if(e.markCursor){let t=document.createElement(`img`);t.className=`ProseMirror-separator`,t.setAttribute(`mark-placeholder`,`true`),t.setAttribute(`alt`,``),e.cursorWrapper={dom:t,deco:ow.widget(e.state.selection.from,t,{raw:!0,marks:e.markCursor})}}else e.cursorWrapper=null}function Kw(e){return!e.someProp(`editable`,t=>t(e.state)===!1)}function qw(e,t){let n=Math.min(e.$anchor.sharedDepth(e.head),t.$anchor.sharedDepth(t.head));return e.$anchor.start(n)!=t.$anchor.start(n)}function Jw(e){let t=Object.create(null);function n(e){for(let n in e)Object.prototype.hasOwnProperty.call(t,n)||(t[n]=e[n])}return e.someProp(`nodeViews`,n),e.someProp(`markViews`,n),t}function Yw(e,t){let n=0,r=0;for(let r in e){if(e[r]!=t[r])return!0;n++}for(let e in t)r++;return n!=r}function Xw(e){if(e.spec.state||e.spec.filterTransaction||e.spec.appendTransaction)throw RangeError(`Plugins passed directly to the view must not have a state component`)}for(var Zw={8:`Backspace`,9:`Tab`,10:`Enter`,12:`NumLock`,13:`Enter`,16:`Shift`,17:`Control`,18:`Alt`,20:`CapsLock`,27:`Escape`,32:` `,33:`PageUp`,34:`PageDown`,35:`End`,36:`Home`,37:`ArrowLeft`,38:`ArrowUp`,39:`ArrowRight`,40:`ArrowDown`,44:`PrintScreen`,45:`Insert`,46:`Delete`,59:`;`,61:`=`,91:`Meta`,92:`Meta`,106:`*`,107:`+`,108:`,`,109:`-`,110:`.`,111:`/`,144:`NumLock`,145:`ScrollLock`,160:`Shift`,161:`Shift`,162:`Control`,163:`Control`,164:`Alt`,165:`Alt`,173:`-`,186:`;`,187:`=`,188:`,`,189:`-`,190:`.`,191:`/`,192:"`",219:`[`,220:`\\`,221:`]`,222:`'`},Qw={48:`)`,49:`!`,50:`@`,51:`#`,52:`$`,53:`%`,54:`^`,55:`&`,56:`*`,57:`(`,59:`:`,61:`+`,173:`_`,186:`:`,187:`+`,188:`<`,189:`_`,190:`>`,191:`?`,192:`~`,219:`{`,220:`|`,221:`}`,222:`"`},$w=typeof navigator<`u`&&/Mac/.test(navigator.platform),eT=typeof navigator<`u`&&/MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent),tT=0;tT<10;tT++)Zw[48+tT]=Zw[96+tT]=String(tT);for(var tT=1;tT<=24;tT++)Zw[tT+111]=`F`+tT;for(var tT=65;tT<=90;tT++)Zw[tT]=String.fromCharCode(tT+32),Qw[tT]=String.fromCharCode(tT);for(var nT in Zw)Qw.hasOwnProperty(nT)||(Qw[nT]=Zw[nT]);function rT(e){var t=!($w&&e.metaKey&&e.shiftKey&&!e.ctrlKey&&!e.altKey||eT&&e.shiftKey&&e.key&&e.key.length==1||e.key==`Unidentified`)&&e.key||(e.shiftKey?Qw:Zw)[e.keyCode]||e.key||`Unidentified`;return t==`Esc`&&(t=`Escape`),t==`Del`&&(t=`Delete`),t==`Left`&&(t=`ArrowLeft`),t==`Up`&&(t=`ArrowUp`),t==`Right`&&(t=`ArrowRight`),t==`Down`&&(t=`ArrowDown`),t}var iT=typeof navigator<`u`&&/Mac|iP(hone|[oa]d)/.test(navigator.platform),aT=typeof navigator<`u`&&/Win/.test(navigator.platform);function oT(e){let t=e.split(/-(?!$)/),n=t[t.length-1];n==`Space`&&(n=` `);let r,i,a,o;for(let e=0;e<t.length-1;e++){let n=t[e];if(/^(cmd|meta|m)$/i.test(n))o=!0;else if(/^a(lt)?$/i.test(n))r=!0;else if(/^(c|ctrl|control)$/i.test(n))i=!0;else if(/^s(hift)?$/i.test(n))a=!0;else if(/^mod$/i.test(n))iT?o=!0:i=!0;else throw Error(`Unrecognized modifier name: `+n)}return r&&(n=`Alt-`+n),i&&(n=`Ctrl-`+n),o&&(n=`Meta-`+n),a&&(n=`Shift-`+n),n}function sT(e){let t=Object.create(null);for(let n in e)t[oT(n)]=e[n];return t}function cT(e,t,n=!0){return t.altKey&&(e=`Alt-`+e),t.ctrlKey&&(e=`Ctrl-`+e),t.metaKey&&(e=`Meta-`+e),n&&t.shiftKey&&(e=`Shift-`+e),e}function lT(e){return new My({props:{handleKeyDown:uT(e)}})}function uT(e){let t=sT(e);return function(e,n){let r=rT(n),i,a=t[cT(r,n)];if(a&&a(e.state,e.dispatch,e))return!0;if(r.length==1&&r!=` `){if(n.shiftKey){let i=t[cT(r,n,!1)];if(i&&i(e.state,e.dispatch,e))return!0}if((n.altKey||n.metaKey||n.ctrlKey)&&!(aT&&n.ctrlKey&&n.altKey)&&(i=Zw[n.keyCode])&&i!=r){let r=t[cT(i,n)];if(r&&r(e.state,e.dispatch,e))return!0}}return!1}}var dT=200,fT=function(){};fT.prototype.append=function(e){return e.length?(e=fT.from(e),!this.length&&e||e.length<dT&&this.leafAppend(e)||this.length<dT&&e.leafPrepend(this)||this.appendInner(e)):this},fT.prototype.prepend=function(e){return e.length?fT.from(e).append(this):this},fT.prototype.appendInner=function(e){return new mT(this,e)},fT.prototype.slice=function(e,t){return e===void 0&&(e=0),t===void 0&&(t=this.length),e>=t?fT.empty:this.sliceInner(Math.max(0,e),Math.min(this.length,t))},fT.prototype.get=function(e){if(!(e<0||e>=this.length))return this.getInner(e)},fT.prototype.forEach=function(e,t,n){t===void 0&&(t=0),n===void 0&&(n=this.length),t<=n?this.forEachInner(e,t,n,0):this.forEachInvertedInner(e,t,n,0)},fT.prototype.map=function(e,t,n){t===void 0&&(t=0),n===void 0&&(n=this.length);var r=[];return this.forEach(function(t,n){return r.push(e(t,n))},t,n),r},fT.from=function(e){return e instanceof fT?e:e&&e.length?new pT(e):fT.empty};var pT=function(e){function t(t){e.call(this),this.values=t}e&&(t.__proto__=e),t.prototype=Object.create(e&&e.prototype),t.prototype.constructor=t;var n={length:{configurable:!0},depth:{configurable:!0}};return t.prototype.flatten=function(){return this.values},t.prototype.sliceInner=function(e,n){return e==0&&n==this.length?this:new t(this.values.slice(e,n))},t.prototype.getInner=function(e){return this.values[e]},t.prototype.forEachInner=function(e,t,n,r){for(var i=t;i<n;i++)if(e(this.values[i],r+i)===!1)return!1},t.prototype.forEachInvertedInner=function(e,t,n,r){for(var i=t-1;i>=n;i--)if(e(this.values[i],r+i)===!1)return!1},t.prototype.leafAppend=function(e){if(this.length+e.length<=dT)return new t(this.values.concat(e.flatten()))},t.prototype.leafPrepend=function(e){if(this.length+e.length<=dT)return new t(e.flatten().concat(this.values))},n.length.get=function(){return this.values.length},n.depth.get=function(){return 0},Object.defineProperties(t.prototype,n),t}(fT);fT.empty=new pT([]);var mT=function(e){function t(t,n){e.call(this),this.left=t,this.right=n,this.length=t.length+n.length,this.depth=Math.max(t.depth,n.depth)+1}return e&&(t.__proto__=e),t.prototype=Object.create(e&&e.prototype),t.prototype.constructor=t,t.prototype.flatten=function(){return this.left.flatten().concat(this.right.flatten())},t.prototype.getInner=function(e){return e<this.left.length?this.left.get(e):this.right.get(e-this.left.length)},t.prototype.forEachInner=function(e,t,n,r){var i=this.left.length;if(t<i&&this.left.forEachInner(e,t,Math.min(n,i),r)===!1||n>i&&this.right.forEachInner(e,Math.max(t-i,0),Math.min(this.length,n)-i,r+i)===!1)return!1},t.prototype.forEachInvertedInner=function(e,t,n,r){var i=this.left.length;if(t>i&&this.right.forEachInvertedInner(e,t-i,Math.max(n,i)-i,r+i)===!1||n<i&&this.left.forEachInvertedInner(e,Math.min(t,i),n,r)===!1)return!1},t.prototype.sliceInner=function(e,t){if(e==0&&t==this.length)return this;var n=this.left.length;return t<=n?this.left.slice(e,t):e>=n?this.right.slice(e-n,t-n):this.left.slice(e,n).append(this.right.slice(0,t-n))},t.prototype.leafAppend=function(e){var n=this.right.leafAppend(e);if(n)return new t(this.left,n)},t.prototype.leafPrepend=function(e){var n=this.left.leafPrepend(e);if(n)return new t(n,this.right)},t.prototype.appendInner=function(e){return this.left.depth>=Math.max(this.right.depth,e.depth)+1?new t(this.left,new t(this.right,e)):new t(this,e)},t}(fT),hT=500,gT=class e{constructor(e,t){this.items=e,this.eventCount=t}popEvent(t,n){if(this.eventCount==0)return null;let r=this.items.length;for(;;r--)if(this.items.get(r-1).selection){--r;break}let i,a;n&&(i=this.remapping(r,this.items.length),a=i.maps.length);let o=t.tr,s,c,l=[],u=[];return this.items.forEach((t,n)=>{if(!t.step){i||(i=this.remapping(r,n+1),a=i.maps.length),a--,u.push(t);return}if(i){u.push(new vT(t.map));let e=t.step.map(i.slice(a)),n;e&&o.maybeStep(e).doc&&(n=o.mapping.maps[o.mapping.maps.length-1],l.push(new vT(n,void 0,void 0,l.length+u.length))),a--,n&&i.appendMap(n,a)}else o.maybeStep(t.step);if(t.selection)return s=i?t.selection.map(i.slice(a)):t.selection,c=new e(this.items.slice(0,r).append(u.reverse().concat(l)),this.eventCount-1),!1},this.items.length,0),{remaining:c,transform:o,selection:s}}addTransform(t,n,r,i){let a=[],o=this.eventCount,s=this.items,c=!i&&s.length?s.get(s.length-1):null;for(let e=0;e<t.steps.length;e++){let r=t.steps[e].invert(t.docs[e]),l=new vT(t.mapping.maps[e],r,n),u;(u=c&&c.merge(l))&&(l=u,e?a.pop():s=s.slice(0,s.length-1)),a.push(l),n&&=(o++,void 0),i||(c=l)}let l=o-r.depth;return l>bT&&(s=_T(s,l),o-=l),new e(s.append(a),o)}remapping(e,t){let n=new sv;return this.items.forEach((t,r)=>{let i=t.mirrorOffset!=null&&r-t.mirrorOffset>=e?n.maps.length-t.mirrorOffset:void 0;n.appendMap(t.map,i)},e,t),n}addMaps(t){return this.eventCount==0?this:new e(this.items.append(t.map(e=>new vT(e))),this.eventCount)}rebased(t,n){if(!this.eventCount)return this;n=Math.min(this.items.length,n);let r=[],i=this.items.length-n,a=t.mapping,o=t.steps.length,s=this.eventCount;this.items.forEach(e=>{e.selection&&s--},i);let c=n;this.items.forEach(e=>{let n=a.getMirror(--c);if(n==null)return;o=Math.min(o,n);let i=a.maps[n];if(e.step){let o=t.steps[n].invert(t.docs[n]),l=e.selection&&e.selection.map(a.slice(c+1,n));l&&s++,r.push(new vT(i,o,l))}else r.push(new vT(i))},i);let l=[];for(let e=n;e<o;e++)l.push(new vT(a.maps[e]));let u=new e(this.items.slice(0,i).append(l).append(r),s);return u.emptyItemCount()>hT&&(u=u.compress(this.items.length-r.length)),u}emptyItemCount(){let e=0;return this.items.forEach(t=>{t.step||e++}),e}compress(t=this.items.length){let n=this.remapping(0,t),r=n.maps.length,i=[],a=0;return this.items.forEach((e,o)=>{if(o>=t)i.push(e),e.selection&&a++;else if(e.step){let t=e.step.map(n.slice(r)),o=t&&t.getMap();if(r--,o&&n.appendMap(o,r),t){let s=e.selection&&e.selection.map(n.slice(r));s&&a++;let c=new vT(o.invert(),t,s),l,u=i.length-1;(l=i.length&&i[u].merge(c))?i[u]=l:i.push(c)}}else e.map&&r--},this.items.length,0),new e(fT.from(i.reverse()),a)}};gT.empty=new gT(fT.empty,0);function _T(e,t){let n;return e.forEach((e,r)=>{if(e.selection&&t--==0)return n=r,!1}),e.slice(n)}var vT=class e{constructor(e,t,n,r){this.map=e,this.step=t,this.selection=n,this.mirrorOffset=r}merge(t){if(this.step&&t.step&&!t.selection){let n=t.step.merge(this.step);if(n)return new e(n.getMap().invert(),n,this.selection)}}},yT=class{constructor(e,t,n,r,i){this.done=e,this.undone=t,this.prevRanges=n,this.prevTime=r,this.prevComposition=i}},bT=20;function xT(e,t,n,r){let i=n.getMeta(AT),a;if(i)return i.historyState;n.getMeta(jT)&&(e=new yT(e.done,e.undone,null,0,-1));let o=n.getMeta(`appendedTransaction`);if(n.steps.length==0)return e;if(o&&o.getMeta(AT))return o.getMeta(AT).redo?new yT(e.done.addTransform(n,void 0,r,OT(t)),e.undone,CT(n.mapping.maps),e.prevTime,e.prevComposition):new yT(e.done,e.undone.addTransform(n,void 0,r,OT(t)),null,e.prevTime,e.prevComposition);if(n.getMeta(`addToHistory`)!==!1&&!(o&&o.getMeta(`addToHistory`)===!1)){let i=n.getMeta(`composition`),a=e.prevTime==0||!o&&e.prevComposition!=i&&(e.prevTime<(n.time||0)-r.newGroupDelay||!ST(n,e.prevRanges)),s=o?wT(e.prevRanges,n.mapping):CT(n.mapping.maps);return new yT(e.done.addTransform(n,a?t.selection.getBookmark():void 0,r,OT(t)),gT.empty,s,n.time,i??e.prevComposition)}else if(a=n.getMeta(`rebased`))return new yT(e.done.rebased(n,a),e.undone.rebased(n,a),wT(e.prevRanges,n.mapping),e.prevTime,e.prevComposition);else return new yT(e.done.addMaps(n.mapping.maps),e.undone.addMaps(n.mapping.maps),wT(e.prevRanges,n.mapping),e.prevTime,e.prevComposition)}function ST(e,t){if(!t)return!1;if(!e.docChanged)return!0;let n=!1;return e.mapping.maps[0].forEach((e,r)=>{for(let i=0;i<t.length;i+=2)e<=t[i+1]&&r>=t[i]&&(n=!0)}),n}function CT(e){let t=[];for(let n=e.length-1;n>=0&&t.length==0;n--)e[n].forEach((e,n,r,i)=>t.push(r,i));return t}function wT(e,t){if(!e)return null;let n=[];for(let r=0;r<e.length;r+=2){let i=t.map(e[r],1),a=t.map(e[r+1],-1);i<=a&&n.push(i,a)}return n}function TT(e,t,n){let r=OT(t),i=AT.get(t).spec.config,a=(n?e.undone:e.done).popEvent(t,r);if(!a)return null;let o=a.selection.resolve(a.transform.doc),s=(n?e.done:e.undone).addTransform(a.transform,t.selection.getBookmark(),i,r),c=new yT(n?s:a.remaining,n?a.remaining:s,null,0,-1);return a.transform.setSelection(o).setMeta(AT,{redo:n,historyState:c})}var ET=!1,DT=null;function OT(e){let t=e.plugins;if(DT!=t){ET=!1,DT=t;for(let e=0;e<t.length;e++)if(t[e].spec.historyPreserveItems){ET=!0;break}}return ET}function kT(e){return e.setMeta(jT,!0)}var AT=new Fy(`history`),jT=new Fy(`closeHistory`);function MT(e={}){return e={depth:e.depth||100,newGroupDelay:e.newGroupDelay||500},new My({key:AT,state:{init(){return new yT(gT.empty,gT.empty,null,0,-1)},apply(t,n,r){return xT(n,r,t,e)}},config:e,props:{handleDOMEvents:{beforeinput(e,t){let n=t.inputType,r=n==`historyUndo`?PT:n==`historyRedo`?FT:null;return!r||!e.editable?!1:(t.preventDefault(),r(e.state,e.dispatch))}}}})}function NT(e,t){return(n,r)=>{let i=AT.getState(n);if(!i||(e?i.undone:i.done).eventCount==0)return!1;if(r){let a=TT(i,n,e);a&&r(t?a.scrollIntoView():a)}return!0}}var PT=NT(!1,!0),FT=NT(!0,!0);function IT(e){return e.getMeta(AT)!=null}function LT(e){let{state:t,transaction:n}=e,{selection:r}=n,{doc:i}=n,{storedMarks:a}=n;return{...t,apply:t.apply.bind(t),applyTransaction:t.applyTransaction.bind(t),plugins:t.plugins,schema:t.schema,reconfigure:t.reconfigure.bind(t),toJSON:t.toJSON.bind(t),get storedMarks(){return a},get selection(){return r},get doc(){return i},get tr(){return r=n.selection,i=n.doc,a=n.storedMarks,n}}}var RT=class e{constructor(e){this.editor=e.editor,this.rawCommands=this.editor.extensionManager.commands,this.customState=e.state}get hasCustomState(){return!!this.customState}get state(){return this.customState||this.editor.state}get commands(){let{rawCommands:e,editor:t,state:n}=this,{view:r}=t,{tr:i}=n,a=this.buildProps(i);return Object.fromEntries(Object.entries(e).map(([e,t])=>[e,(...e)=>{let n=t(...e)(a);return!i.getMeta(`preventDispatch`)&&!this.hasCustomState&&r.dispatch(i),n}]))}get chain(){return()=>this.createChain()}get can(){return()=>this.createCan()}createChain(e,t=!0){let{rawCommands:n,editor:r,state:i}=this,{view:a}=r,o=[],s=!!e,c=e||i.tr,l=()=>(!s&&t&&!c.getMeta(`preventDispatch`)&&!this.hasCustomState&&a.dispatch(c),o.every(e=>e===!0)),u={...Object.fromEntries(Object.entries(n).map(([e,n])=>[e,(...e)=>{let r=this.buildProps(c,t),i=n(...e)(r);return o.push(i),u}])),run:l};return u}static createFakeChain(){let e=new Proxy({},{get:(t,n)=>{if(n!==`then`)return n===`run`?()=>!1:()=>e}});return e}createCan(e){let{rawCommands:t,state:n}=this,r=e||n.tr,i=this.buildProps(r,!1);return{...Object.fromEntries(Object.entries(t).map(([e,t])=>[e,(...e)=>t(...e)({...i,dispatch:void 0})])),chain:()=>this.createChain(r,!1)}}static createFallbackCan(){let t=e.createFakeChain();return new Proxy({chain:()=>t},{get:(e,t)=>{if(t!==`then`)return t===`chain`?e.chain:()=>!1}})}buildProps(e,t=!0){let{rawCommands:n,editor:r,state:i}=this,{view:a}=r,o={tr:e,editor:r,view:a,state:LT({state:i,transaction:e}),dispatch:t?()=>void 0:void 0,chain:()=>this.createChain(e,t),can:()=>this.createCan(e),get commands(){return Object.fromEntries(Object.entries(n).map(([e,t])=>[e,(...e)=>t(...e)(o)]))}};return o}},zT=()=>({editor:e,view:t})=>(requestAnimationFrame(()=>{if(!e.isDestroyed){var n;t.dom.blur(),(n=window)==null||(n=n.getSelection())==null||n.removeAllRanges()}}),!0),BT=(e=!0)=>({commands:t})=>t.setContent(``,{emitUpdate:e}),VT=()=>({state:e,tr:t,dispatch:n})=>{let{selection:r}=t,{ranges:i}=r;return n&&i.forEach(({$from:n,$to:r})=>{e.doc.nodesBetween(n.pos,r.pos,(e,n)=>{if(e.type.isText)return;let{doc:r,mapping:i}=t,a=r.resolve(i.map(n)),o=r.resolve(i.map(n+e.nodeSize)),s=a.blockRange(o);if(!s)return;let c=Cv(s);if(e.type.isTextblock){let{defaultType:e}=a.parent.contentMatchAt(a.index());t.setNodeMarkup(s.start,e)}(c||c===0)&&t.lift(s,c)})}),!0},HT=e=>t=>e(t),UT=()=>({state:e,dispatch:t})=>tb(e,t),WT=(e,t)=>({editor:n,tr:r})=>{let{state:i}=n,a=i.doc.slice(e.from,e.to);r.deleteRange(e.from,e.to);let o=r.mapping.map(t);return r.insert(o,a.content),r.setSelection(new hy(r.doc.resolve(Math.max(o-1,0)))),!0},GT=()=>({tr:e,dispatch:t})=>{let{selection:n}=e,r=n.$anchor.node();if(r.content.size>0)return!1;let i=e.selection.$anchor;for(let n=i.depth;n>0;--n)if(i.node(n).type===r.type){if(t){let t=i.before(n),r=i.after(n);e.delete(t,r).scrollIntoView()}return!0}return!1};function KT(e,t){if(typeof e==`string`){if(!t.nodes[e])throw Error(`There is no node type named '${e}'. Maybe you forgot to add the extension?`);return t.nodes[e]}return e}var qT=e=>({tr:t,state:n,dispatch:r})=>{let i=KT(e,n.schema),a=t.selection.$anchor;for(let e=a.depth;e>0;--e)if(a.node(e).type===i){if(r){let n=a.before(e),r=a.after(e);t.delete(n,r).scrollIntoView()}return!0}return!1},JT=e=>({tr:t,dispatch:n})=>{let{from:r,to:i}=e;return n&&t.delete(r,i),!0},YT=e=>e.content?/^text(\*|\+)/.test(e.content):!1,XT=(e,t,n)=>{if(!e.parent.isInline||n===`left`&&e.pos>e.start()||n===`right`&&e.pos<e.end())return e.pos;let r=t.nodes[e.parent.type.name].spec;return YT(r)?n===`left`?e.start()-1:e.end()+1:e.pos},ZT=(e,t,n)=>({from:XT(e,n,`left`),to:XT(t,n,`right`)}),QT=()=>({state:e,dispatch:t})=>{if(e.selection.empty)return!1;if(t){let n=e.tr,{ranges:r}=e.selection,i=n.steps.length;r.forEach(t=>{let r=n.mapping.slice(i),{from:a,to:o}=ZT(n.doc.resolve(r.map(t.$from.pos)),n.doc.resolve(r.map(t.$to.pos)),e.schema);n.deleteRange(a,o)}),n.selection.empty||n.setSelection(hy.near(n.doc.resolve(n.selection.from))),n.scrollIntoView(),t(n)}return!0},$T=()=>({commands:e})=>e.keyboardShortcut(`Enter`),eE=()=>({state:e,dispatch:t})=>eb(e,t);function tE(e){return Object.prototype.toString.call(e)===`[object RegExp]`}function nE(e,t,n={strict:!0}){let r=Object.keys(t);return r.length?r.every(r=>n.strict?t[r]===e[r]:tE(t[r])?t[r].test(e[r]):t[r]===e[r]):!0}function rE(e,t,n={}){return e.find(e=>e.type===t&&nE(Object.fromEntries(Object.keys(n).map(t=>[t,e.attrs[t]])),n))}function iE(e,t,n={}){return!!rE(e,t,n)}function aE(e,t,n){if(!e||!t)return;let r=e.parent.childAfter(e.parentOffset);if((!r.node||!r.node.marks.some(e=>e.type===t))&&(r=e.parent.childBefore(e.parentOffset)),!r.node||!r.node.marks.some(e=>e.type===t))return;if(!n){let e=r.node.marks.find(e=>e.type===t);e&&(n=e.attrs)}if(!rE([...r.node.marks],t,n))return;let i=r.index,a=e.start()+r.offset,o=i+1,s=a+r.node.nodeSize;for(;i>0&&iE([...e.parent.child(i-1).marks],t,n);)--i,a-=e.parent.child(i).nodeSize;for(;o<e.parent.childCount&&iE([...e.parent.child(o).marks],t,n);)s+=e.parent.child(o).nodeSize,o+=1;return{from:a,to:s}}function oE(e,t){if(typeof e==`string`){if(!t.marks[e])throw Error(`There is no mark type named '${e}'. Maybe you forgot to add the extension?`);return t.marks[e]}return e}var sE=(e,t)=>({tr:n,state:r,dispatch:i})=>{let a=oE(e,r.schema),{doc:o,selection:s}=n,{$from:c,from:l,to:u}=s;if(i){let e=aE(c,a,t);if(e&&e.from<=l&&e.to>=u){let t=hy.create(o,e.from,e.to);n.setSelection(t)}}return!0},cE=e=>t=>{let n=typeof e==`function`?e(t):e;for(let e=0;e<n.length;e+=1)if(n[e](t))return!0;return!1};function lE(e){return e instanceof hy}function uE(e=0,t=0,n=0){return Math.min(Math.max(e,t),n)}function dE(e,t=null){if(!t)return null;let n=dy.atStart(e),r=dy.atEnd(e);if(t===`start`||t===!0)return n;if(t===`end`)return r;let i=n.from,a=r.to;return t===`all`?hy.create(e,uE(0,i,a),uE(e.content.size,i,a)):hy.create(e,uE(t,i,a),uE(t,i,a))}function fE(){return[`Android`].includes(navigator.platform)||/android/i.test(navigator.userAgent)}function pE(){return[`iPad Simulator`,`iPhone Simulator`,`iPod Simulator`,`iPad`,`iPhone`,`iPod`].includes(navigator.platform)||navigator.userAgent.includes(`Mac`)&&`ontouchend`in document}function mE(){return typeof navigator<`u`?/^((?!chrome|android).)*safari/i.test(navigator.userAgent):!1}var hE=(e=null,t={})=>({editor:n,view:r,tr:i,dispatch:a})=>{t={scrollIntoView:!0,...t};let o=()=>{(pE()||fE())&&r.dom.focus(),mE()&&!pE()&&!fE()&&r.dom.focus({preventScroll:!0}),requestAnimationFrame(()=>{n.isDestroyed||(r.focus(),t?.scrollIntoView&&n.commands.scrollIntoView())})};try{if(r.hasFocus()&&e===null||e===!1)return!0}catch{return!1}if(a&&e===null&&!lE(n.state.selection))return o(),!0;let s=dE(i.doc,e)||n.state.selection,c=n.state.selection.eq(s);return a&&(c||i.setSelection(s),c&&i.storedMarks&&i.setStoredMarks(i.storedMarks),o()),!0},gE=(e,t)=>n=>e.every((e,r)=>t(e,{...n,index:r})),_E=(e,t)=>({tr:n,commands:r})=>r.insertContentAt({from:n.selection.from,to:n.selection.to},e,t),vE=e=>{let t=e.childNodes;for(let n=t.length-1;n>=0;--n){let r=t[n];r.nodeType===3&&r.nodeValue&&/^(\n\s\s|\n)$/.test(r.nodeValue)?e.removeChild(r):r.nodeType===1&&vE(r)}return e};function yE(e){if(typeof window>`u`)throw Error(`[tiptap error]: there is no window object available, so this function cannot be used`);let t=`<body>${e}</body>`,n=new window.DOMParser().parseFromString(t,`text/html`).body;return vE(n)}function bE(e){return typeof e?.nodesBetween==`function`}function xE(e,t,n){if(bE(e))return e;let r=typeof e==`object`&&!!e;n={slice:!0,parseOptions:{},...n};let i=typeof e==`string`;if(r)try{if(Array.isArray(e)&&e.length>0)return J.fromArray(e.map(e=>t.nodeFromJSON(e)));let r=t.nodeFromJSON(e);return n.errorOnInvalidContent&&r.check(),r}catch(r){if(n.errorOnInvalidContent)throw Error(`[tiptap error]: Invalid JSON content`,{cause:r});return console.warn(`[tiptap warn]: Invalid content.`,`Passed value:`,e,`Error:`,r),xE(``,t,n)}if(i){if(n.errorOnInvalidContent){let r=!1,i=``,a=new T_({topNode:t.spec.topNode,marks:t.spec.marks,nodes:t.spec.nodes.append({__tiptap__private__unknown__catch__all__node:{content:`inline*`,group:`block`,parseDOM:[{tag:`*`,getAttrs:e=>(r=!0,i=typeof e==`string`?e:e.outerHTML,null)}]}})});if(n.slice?k_.fromSchema(a).parseSlice(yE(e),n.parseOptions):k_.fromSchema(a).parse(yE(e),n.parseOptions),n.errorOnInvalidContent&&r)throw Error(`[tiptap error]: Invalid HTML content`,{cause:Error(`Invalid element found: ${i}`)})}let r=k_.fromSchema(t);return n.slice?r.parseSlice(yE(e),n.parseOptions).content:r.parse(yE(e),n.parseOptions)}return xE(``,t,n)}function SE(e){return!(`type`in e)}function CE(e,t,n){let r=e.steps.length-1;if(r<t)return;let i=e.steps[r];if(!(i instanceof gv||i instanceof _v))return;let a=e.mapping.maps[r],o=0;a.forEach((e,t,n,r)=>{o===0&&(o=r)}),e.setSelection(dy.near(e.doc.resolve(o),n))}var wE=(e,t,n)=>({tr:r,dispatch:i,editor:a})=>{if(i){n={parseOptions:a.options.parseOptions,updateSelection:!0,applyInputRules:!1,applyPasteRules:!1,...n};let i,o=e=>{a.emit(`contentError`,{editor:a,error:e,disableCollaboration:()=>{`collaboration`in a.storage&&typeof a.storage.collaboration==`object`&&a.storage.collaboration&&(a.storage.collaboration.isDisabled=!0)}})},s={preserveWhitespace:`full`,...n.parseOptions};if(!n.errorOnInvalidContent&&!a.options.enableContentCheck&&a.options.emitContentError)try{xE(t,a.schema,{parseOptions:s,errorOnInvalidContent:!0})}catch(e){o(e)}try{i=xE(t,a.schema,{parseOptions:s,errorOnInvalidContent:n.errorOnInvalidContent??a.options.enableContentCheck})}catch(e){return o(e),!1}let{from:c,to:l}=typeof e==`number`?{from:e,to:e}:{from:e.from,to:e.to},u=!0,d=!0,f=SE(i)?i.content:[i];if(f.forEach(e=>{e.check(),u=u?e.isText&&e.marks.length===0:!1,d=d?e.isBlock:!1}),c===l&&d){let{parent:e}=r.doc.resolve(c);e.isTextblock&&!e.type.spec.code&&!e.childCount&&(--c,l+=1)}let p;if(u)p=Array.isArray(t)?t.map(e=>e.text||``).join(``):bE(t)?f.map(e=>e.text??``).join(``):typeof t==`object`&&t&&t.text?t.text:t,r.insertText(p,c,l);else{p=J.from(f);let e=r.doc.resolve(c),t=e.node(),n=e.parentOffset===0,i=t.isText||t.isTextblock,a=t.content.size>0;n&&i&&a&&d&&(c=Math.max(0,c-1)),r.replaceWith(c,l,f)}n.updateSelection&&CE(r,r.steps.length-1,-1),n.applyInputRules&&r.setMeta(`applyInputRules`,{from:c,text:p}),n.applyPasteRules&&r.setMeta(`applyPasteRules`,{from:c,text:p})}return!0};function TE(e){for(let t=0;t<e.edgeCount;t+=1){let{type:n}=e.edge(t);if(n.isTextblock&&!n.hasRequiredAttrs())return n}return null}var EE=(e={})=>({tr:t,dispatch:n,editor:r})=>{let{pos:i,attrs:a,content:o,updateSelection:s=!0}=e,c;c=typeof i==`number`?t.doc.resolve(i):i||t.selection.$from;let l=TE(c.parent.contentMatchAt(c.index()));if(!l)return!1;let u=Object.keys(l.spec.attrs||{}),d=a?Object.fromEntries(Object.entries(a).filter(([e])=>u.includes(e))):{},f;if(o){let e=xE(o,r.schema);f=l.createAndFill(d,e)}else f=l.createAndFill(d);return f?(n&&(t.insert(c.pos,f),s&&CE(t,t.steps.length-1,-1)),!0):!1},DE=()=>({state:e,dispatch:t})=>Yy(e,t),OE=()=>({state:e,dispatch:t})=>Xy(e,t),kE=()=>({state:e,dispatch:t})=>Ry(e,t),AE=()=>({state:e,dispatch:t})=>Ky(e,t),jE=(e,t)=>{let n=e.resolve(t),r=n.nodeBefore,i=n.nodeAfter;return!r||!i?!1:!r.type.spec.isolating&&!i.type.spec.isolating},ME=()=>({state:e,dispatch:t,tr:n})=>{try{let r=Bv(e.doc,e.selection.$from.pos,-1);return r==null||!jE(e.doc,r)?!1:(n.join(r,2),t&&t(n),!0)}catch{return!1}},NE=()=>({state:e,dispatch:t,tr:n})=>{try{let r=Bv(e.doc,e.selection.$from.pos,1);return r==null||!jE(e.doc,r)?!1:(n.join(r,2),t&&t(n),!0)}catch{return!1}},PE=()=>({state:e,dispatch:t})=>zy(e,t),FE=()=>({state:e,dispatch:t})=>By(e,t);function IE(){return typeof navigator<`u`?/Mac/.test(navigator.platform):!1}function LE(e){let t=e.split(/-(?!$)/),n=t[t.length-1];n===`Space`&&(n=` `);let r,i,a,o;for(let e=0;e<t.length-1;e+=1){let n=t[e];if(/^(cmd|meta|m)$/i.test(n))o=!0;else if(/^a(lt)?$/i.test(n))r=!0;else if(/^(c|ctrl|control)$/i.test(n))i=!0;else if(/^s(hift)?$/i.test(n))a=!0;else if(/^mod$/i.test(n))pE()||IE()?o=!0:i=!0;else throw Error(`Unrecognized modifier name: ${n}`)}return r&&(n=`Alt-${n}`),i&&(n=`Ctrl-${n}`),o&&(n=`Meta-${n}`),a&&(n=`Shift-${n}`),n}var RE=e=>({editor:t,view:n,tr:r,dispatch:i})=>{let a=LE(e).split(/-(?!$)/),o=a.find(e=>![`Alt`,`Ctrl`,`Meta`,`Shift`].includes(e)),s=new KeyboardEvent(`keydown`,{key:o===`Space`?` `:o,altKey:a.includes(`Alt`),ctrlKey:a.includes(`Ctrl`),metaKey:a.includes(`Meta`),shiftKey:a.includes(`Shift`),bubbles:!0,cancelable:!0});return t.captureTransaction(()=>{n.someProp(`handleKeyDown`,e=>e(n,s))})?.steps.forEach(e=>{let t=e.map(r.mapping);t&&i&&r.maybeStep(t)}),!0};function zE(e,t,n={}){let{from:r,to:i,empty:a}=e.selection,o=t?KT(t,e.schema):null,s=[];e.doc.nodesBetween(r,i,(e,t)=>{if(e.isText)return;let n=Math.max(r,t),a=Math.min(i,t+e.nodeSize);s.push({node:e,from:n,to:a})});let c=i-r,l=s.filter(e=>o?o.name===e.node.type.name:!0).filter(e=>nE(e.node.attrs,n,{strict:!1}));return a?!!l.length:l.reduce((e,t)=>e+t.to-t.from,0)>=c}var BE=(e,t={})=>({state:n,dispatch:r})=>zE(n,KT(e,n.schema),t)?Zy(n,r):!1,VE=()=>({state:e,dispatch:t})=>nb(e,t),HE=e=>({state:t,dispatch:n})=>Sb(KT(e,t.schema))(t,n),UE=()=>({state:e,dispatch:t})=>Qy(e,t);function WE(e,t){return t.nodes[e]?`node`:t.marks[e]?`mark`:null}function GE(e,t){let n=typeof t==`string`?[t]:t;return Object.keys(e).reduce((t,r)=>(n.includes(r)||(t[r]=e[r]),t),{})}var KE=(e,t)=>({tr:n,state:r,dispatch:i})=>{let a=null,o=null,s=WE(typeof e==`string`?e:e.name,r.schema);if(!s)return!1;s===`node`&&(a=KT(e,r.schema)),s===`mark`&&(o=oE(e,r.schema));let c=!1;return n.selection.ranges.forEach(e=>{r.doc.nodesBetween(e.$from.pos,e.$to.pos,(e,r)=>{a&&a===e.type&&(c=!0,i&&n.setNodeMarkup(r,void 0,GE(e.attrs,t))),o&&e.marks.length&&e.marks.forEach(a=>{o===a.type&&(c=!0,i&&n.addMark(r,r+e.nodeSize,o.create(GE(a.attrs,t))))})})}),c},qE=()=>({tr:e,dispatch:t})=>(t&&e.scrollIntoView(),!0),JE=()=>({tr:e,dispatch:t})=>{if(t){let t=new vy(e.doc);e.setSelection(t)}return!0},YE=()=>({state:e,dispatch:t})=>Uy(e,t),XE=()=>({state:e,dispatch:t})=>qy(e,t),ZE=()=>({state:e,dispatch:t})=>ab(e,t),QE=()=>({state:e,dispatch:t})=>db(e,t),$E=()=>({state:e,dispatch:t})=>ub(e,t);function eD(e,t,n={},r={}){return xE(e,t,{slice:!1,parseOptions:n,errorOnInvalidContent:r.errorOnInvalidContent})}var tD=(e,{errorOnInvalidContent:t,emitUpdate:n=!0,parseOptions:r={}}={})=>({editor:i,tr:a,dispatch:o,commands:s})=>{let{doc:c}=a;if(r.preserveWhitespace!==`full`){let s=eD(e,i.schema,r,{errorOnInvalidContent:t??i.options.enableContentCheck});if(o){let e=SE(s)?s.content:[s];a.replaceWith(0,c.content.size,e).setMeta(`preventUpdate`,!n)}return!0}return o&&a.setMeta(`preventUpdate`,!n),s.insertContentAt({from:0,to:c.content.size},e,{parseOptions:r,errorOnInvalidContent:t??i.options.enableContentCheck})};function nD(e,t){let n=oE(t,e.schema),{from:r,to:i,empty:a}=e.selection,o=[];a?(e.storedMarks&&o.push(...e.storedMarks),o.push(...e.selection.$head.marks())):e.doc.nodesBetween(r,i,e=>{o.push(...e.marks)});let s=o.find(e=>e.type.name===n.name);return s?{...s.attrs}:{}}function rD(e,t){let n=new ly(e);return t.forEach(e=>{e.steps.forEach(e=>{n.step(e)})}),n}function iD(e,t,n){let r=[];return e.nodesBetween(t.from,t.to,(e,t)=>{n(e)&&r.push({node:e,pos:t})}),r}function aD(e,t){for(let n=e.depth;n>0;--n){let r=e.node(n);if(t(r))return{pos:n>0?e.before(n):0,start:e.start(n),depth:n,node:r}}}function oD(e){return t=>aD(t.$from,e)}function Q(e,t,n){return e.config[t]===void 0&&e.parent?Q(e.parent,t,n):typeof e.config[t]==`function`?e.config[t].bind({...n,parent:e.parent?Q(e.parent,t,n):null}):e.config[t]}function sD(e){return e.map(e=>{let t=Q(e,`addExtensions`,{name:e.name,options:e.options,storage:e.storage});return t?[e,...sD(t())]:e}).flat(10)}function cD(e,t){let n=U_.fromSchema(t).serializeFragment(e),r=document.implementation.createHTMLDocument().createElement(`div`);return r.appendChild(n),r.innerHTML}function lD(e){return typeof e==`function`}function uD(e,t=void 0,...n){return lD(e)?t?e.bind(t)(...n):e(...n):e}function dD(e={}){return Object.keys(e).length===0&&e.constructor===Object}function fD(e){return{baseExtensions:e.filter(e=>e.type===`extension`),nodeExtensions:e.filter(e=>e.type===`node`),markExtensions:e.filter(e=>e.type===`mark`)}}function pD(e){let t=[],{nodeExtensions:n,markExtensions:r}=fD(e),i=[...n,...r],a={default:null,validate:void 0,rendered:!0,renderHTML:null,parseHTML:null,keepOnSplit:!0,isRequired:!1},o=n.filter(e=>e.name!==`text`).map(e=>e.name),s=r.map(e=>e.name),c=[...o,...s];return e.forEach(e=>{let n=Q(e,`addGlobalAttributes`,{name:e.name,options:e.options,storage:e.storage,extensions:i});n&&n().forEach(e=>{let n;n=Array.isArray(e.types)?e.types:e.types===`*`?c:e.types===`nodes`?o:e.types===`marks`?s:[],n.forEach(n=>{Object.entries(e.attributes).forEach(([e,r])=>{t.push({type:n,name:e,attribute:{...a,...r}})})})})}),i.forEach(e=>{let n=Q(e,`addAttributes`,{name:e.name,options:e.options,storage:e.storage});if(!n)return;let r=n();Object.entries(r).forEach(([n,r])=>{let i={...a,...r};typeof i?.default==`function`&&(i.default=i.default()),i?.isRequired&&i?.default===void 0&&delete i.default,t.push({type:e.name,name:n,attribute:i})})}),t}function mD(e){let t=[],n=``,r=!1,i=!1,a=0,o=e.length;for(let s=0;s<o;s+=1){let o=e[s];if(o===`'`&&!i){r=!r,n+=o;continue}if(o===`"`&&!r){i=!i,n+=o;continue}if(!r&&!i){if(o===`(`){a+=1,n+=o;continue}if(o===`)`&&a>0){--a,n+=o;continue}if(o===`;`&&a===0){t.push(n),n=``;continue}}n+=o}return n&&t.push(n),t}function hD(e){let t=[],n=mD(e||``),r=n.length;for(let e=0;e<r;e+=1){let r=n[e],i=r.indexOf(`:`);if(i===-1)continue;let a=r.slice(0,i).trim(),o=r.slice(i+1).trim();a&&o&&t.push([a,o])}return t}function gD(...e){return e.filter(e=>!!e).reduce((e,t)=>{let n={...e};return Object.entries(t).forEach(([e,t])=>{if(e===`__proto__`){Object.defineProperty(n,e,{configurable:!0,enumerable:!0,value:t,writable:!0});return}if(!n[e]){n[e]=t;return}if(e===`class`){let r=t?String(t).split(` `):[],i=n[e]?n[e].split(` `):[],a=r.filter(e=>!i.includes(e));n[e]=[...i,...a].join(` `)}else if(e===`style`){let r=new Map([...hD(n[e]),...hD(t)]);n[e]=Array.from(r.entries()).map(([e,t])=>`${e}: ${t}`).join(`; `)}else n[e]=t}),n},{})}function _D(e,t){return t.filter(t=>t.type===e.type.name).filter(e=>e.attribute.rendered).map(t=>t.attribute.renderHTML?t.attribute.renderHTML(e.attrs)||{}:{[t.name]:e.attrs[t.name]}).reduce((e,t)=>gD(e,t),{})}function vD(e){return typeof e==`string`?e.match(/^[+-]?(?:\d*\.)?\d+$/)?Number(e):e===`true`?!0:e===`false`?!1:e:e}function yD(e,t){return`style`in e?e:{...e,getAttrs:n=>{let r=e.getAttrs?e.getAttrs(n):e.attrs;if(r===!1)return!1;let i=t.reduce((e,t)=>{let r=t.attribute.parseHTML?t.attribute.parseHTML(n):vD(n.getAttribute(t.name));return r==null?e:{...e,[t.name]:r}},{});return{...r,...i}}}}function bD(e){return Object.fromEntries(Object.entries(e).filter(([e,t])=>e===`attrs`&&dD(t)?!1:t!=null))}function xD(e){var t,n;let r={};return!(!(e==null||(t=e.attribute)==null)&&t.isRequired)&&`default`in(e?.attribute||{})&&(r.default=e.attribute.default),(e==null||(n=e.attribute)==null?void 0:n.validate)!==void 0&&(r.validate=e.attribute.validate),[e.name,r]}function SD(e,t){let n=pD(e),{nodeExtensions:r,markExtensions:i}=fD(e);return new T_({topNode:r.find(e=>Q(e,`topNode`))?.name,nodes:Object.fromEntries(r.map(r=>{let i=n.filter(e=>e.type===r.name),a={name:r.name,options:r.options,storage:r.storage,editor:t},o=bD({...e.reduce((e,t)=>{let n=Q(t,`extendNodeSchema`,a);return{...e,...n?n(r):{}}},{}),content:uD(Q(r,`content`,a)),marks:uD(Q(r,`marks`,a)),group:uD(Q(r,`group`,a)),inline:uD(Q(r,`inline`,a)),atom:uD(Q(r,`atom`,a)),selectable:uD(Q(r,`selectable`,a)),draggable:uD(Q(r,`draggable`,a)),code:uD(Q(r,`code`,a)),whitespace:uD(Q(r,`whitespace`,a)),linebreakReplacement:uD(Q(r,`linebreakReplacement`,a)),defining:uD(Q(r,`defining`,a)),isolating:uD(Q(r,`isolating`,a)),attrs:Object.fromEntries(i.map(xD))}),s=uD(Q(r,`parseHTML`,a));s&&(o.parseDOM=s.map(e=>yD(e,i)));let c=Q(r,`renderHTML`,a);c&&(o.toDOM=e=>c({node:e,HTMLAttributes:_D(e,i)}));let l=Q(r,`renderText`,a);return l&&(o.toText=l),[r.name,o]})),marks:Object.fromEntries(i.map(r=>{let i=n.filter(e=>e.type===r.name),a={name:r.name,options:r.options,storage:r.storage,editor:t},o=bD({...e.reduce((e,t)=>{let n=Q(t,`extendMarkSchema`,a);return{...e,...n?n(r):{}}},{}),inclusive:uD(Q(r,`inclusive`,a)),excludes:uD(Q(r,`excludes`,a)),group:uD(Q(r,`group`,a)),spanning:uD(Q(r,`spanning`,a)),code:uD(Q(r,`code`,a)),attrs:Object.fromEntries(i.map(xD))}),s=uD(Q(r,`parseHTML`,a));s&&(o.parseDOM=s.map(e=>yD(e,i)));let c=Q(r,`renderHTML`,a);return c&&(o.toDOM=e=>c({mark:e,HTMLAttributes:_D(e,i)})),[r.name,o]}))})}function CD(e){let t=e.filter((t,n)=>e.indexOf(t)!==n);return Array.from(new Set(t))}function wD(e){return e.sort((e,t)=>{let n=Q(e,`priority`)||100,r=Q(t,`priority`)||100;return n>r?-1:+(n<r)})}function TD(e){let t=wD(sD(e)),n=CD(t.map(e=>e.name));return n.length&&console.warn(`[tiptap warn]: Duplicate extension names found: [${n.map(e=>`'${e}'`).join(`, `)}]. This can lead to issues.`),t}function ED(e,t,n){let{from:r,to:i}=t,{blockSeparator:a=`
|
|
18
|
+
|
|
19
|
+
`,textSerializers:o={}}=n||{},s=``;return e.nodesBetween(r,i,(e,n,c,l)=>{e.isBlock&&n>r&&(s+=a);let u=o?.[e.type.name];if(u)return c&&(s+=u({node:e,pos:n,parent:c,index:l,range:t})),!1;if(e.isText){var d;s+=e==null||(d=e.text)==null?void 0:d.slice(Math.max(r,n)-n,i-n)}}),s}function DD(e,t){return ED(e,{from:0,to:e.content.size},t)}function OD(e){return Object.fromEntries(Object.entries(e.nodes).filter(([,e])=>e.spec.toText).map(([e,t])=>[e,t.spec.toText]))}function kD(e,t){let n=KT(t,e.schema),{from:r,to:i}=e.selection,a=[];e.doc.nodesBetween(r,i,e=>{a.push(e)});let o=a.reverse().find(e=>e.type.name===n.name);return o?{...o.attrs}:{}}function AD(e,t){let n=WE(typeof t==`string`?t:t.name,e.schema);return n===`node`?kD(e,t):n===`mark`?nD(e,t):{}}function jD(e,t=JSON.stringify){let n={};return e.filter(e=>{let r=t(e);return Object.prototype.hasOwnProperty.call(n,r)?!1:n[r]=!0})}function MD(e){let t=jD(e);return t.length===1?t:t.filter((e,n)=>!t.filter((e,t)=>t!==n).some(t=>e.oldRange.from>=t.oldRange.from&&e.oldRange.to<=t.oldRange.to&&e.newRange.from>=t.newRange.from&&e.newRange.to<=t.newRange.to))}function ND(e){let{mapping:t,steps:n}=e,r=[];return t.maps.forEach((e,i)=>{let a=[];if(e.ranges.length)e.forEach((e,t)=>{a.push({from:e,to:t})});else{let{from:e,to:t}=n[i];if(e===void 0||t===void 0)return;a.push({from:e,to:t})}a.forEach(({from:e,to:n})=>{let a=t.slice(i).map(e,-1),o=t.slice(i).map(n),s=t.invert().map(a,-1),c=t.invert().map(o);r.push({oldRange:{from:s,to:c},newRange:{from:a,to:o}})})}),MD(r)}function PD(e,t,n){let r=[];return e===t?n.resolve(e).marks().forEach(t=>{let i=aE(n.resolve(e),t.type);i&&r.push({mark:t,...i})}):n.nodesBetween(e,t,(e,t)=>{!e||e?.nodeSize===void 0||r.push(...e.marks.map(n=>({from:t,to:t+e.nodeSize,mark:n})))}),r}function FD(e,t){return t.nodes[e]||t.marks[e]||null}function ID(e,t,n){return Object.fromEntries(Object.entries(n).filter(([n])=>{let r=e.find(e=>e.type===t&&e.name===n);return r?r.attribute.keepOnSplit:!1}))}var LD=(e,t=500)=>{let n=``,r=e.parentOffset;return e.parent.nodesBetween(Math.max(0,r-t),r,(e,t,i,a)=>{var o;let s=(o=e.type.spec).toText?.call(o,{node:e,pos:t,parent:i,index:a})||e.textContent||`%leaf%`;n+=e.isAtom&&!e.isText?s:s.slice(0,Math.max(0,r-t))}),n};function RD(e,t,n={}){let{empty:r,ranges:i}=e.selection,a=t?oE(t,e.schema):null;if(r)return!!(e.storedMarks||e.selection.$from.marks()).filter(e=>a?a.name===e.type.name:!0).find(e=>nE(e.attrs,n,{strict:!1}));let o=0,s=[];if(i.forEach(({$from:t,$to:n})=>{let r=t.pos,i=n.pos;e.doc.nodesBetween(r,i,(e,t)=>{if(a&&e.inlineContent&&!e.type.allowsMarkType(a))return!1;if(!e.isText&&!e.marks.length)return;let n=Math.max(r,t),c=Math.min(i,t+e.nodeSize),l=c-n;o+=l,s.push(...e.marks.map(e=>({mark:e,from:n,to:c})))})}),o===0)return!1;let c=s.filter(e=>a?a.name===e.mark.type.name:!0).filter(e=>nE(e.mark.attrs,n,{strict:!1})).reduce((e,t)=>e+t.to-t.from,0),l=s.filter(e=>a?e.mark.type!==a&&e.mark.type.excludes(a):!0).reduce((e,t)=>e+t.to-t.from,0);return(c>0?c+l:c)>=o}function zD(e,t,n={}){if(!t)return zE(e,null,n)||RD(e,null,n);let r=WE(t,e.schema);return r===`node`?zE(e,t,n):r===`mark`?RD(e,t,n):!1}function BD(e,t){return Array.isArray(t)?t.some(t=>(typeof t==`string`?t:t.name)===e.name):t}function VD(e,t){let{nodeExtensions:n}=fD(t),r=n.find(t=>t.name===e);if(!r)return!1;let i=uD(Q(r,`group`,{name:r.name,options:r.options,storage:r.storage}));return typeof i==`string`?i.split(` `).includes(`list`):!1}function HD(e,{checkChildren:t=!0,ignoreWhitespace:n=!1}={}){if(n){if(e.type.name===`hardBreak`)return!0;if(e.isText)return!/\S/.test(e.text??``)}if(e.isText)return!e.text;if(e.isAtom||e.isLeaf)return!1;if(e.content.childCount===0)return!0;if(t){let r=!0;return e.content.forEach(e=>{r!==!1&&(HD(e,{ignoreWhitespace:n,checkChildren:t})||(r=!1))}),r}return!1}var UD=class e{constructor(e){this.position=e}static fromJSON(t){return new e(t.position)}toJSON(){return{position:this.position}}};function WD(e,t){let n=t.mapping.mapResult(e.position);return{position:new UD(n.pos),mapResult:n}}function GD(e){return new UD(e)}function KD(e,t,n){let{selection:r}=t,i=null;if(lE(r)&&(i=r.$cursor),i){let t=e.storedMarks??i.marks();return i.parent.type.allowsMarkType(n)&&(!!n.isInSet(t)||!t.some(e=>e.type.excludes(n)))}let{ranges:a}=r;return a.some(({$from:t,$to:r})=>{let i=t.depth===0?e.doc.inlineContent&&e.doc.type.allowsMarkType(n):!1;return e.doc.nodesBetween(t.pos,r.pos,(e,t,r)=>{if(i)return!1;if(e.isInline){let t=!r||r.type.allowsMarkType(n),a=!!n.isInSet(e.marks)||!e.marks.some(e=>e.type.excludes(n));i=t&&a}return!i}),i})}var qD=(e,t={})=>({tr:n,state:r,dispatch:i})=>{let{selection:a}=n,{empty:o,ranges:s}=a,c=oE(e,r.schema);if(i)if(o){let e=nD(r,c);n.addStoredMark(c.create({...e,...t}))}else s.forEach(e=>{let i=e.$from.pos,a=e.$to.pos;r.doc.nodesBetween(i,a,(e,r)=>{let o=Math.max(r,i),s=Math.min(r+e.nodeSize,a);e.marks.find(e=>e.type===c)?e.marks.forEach(e=>{c===e.type&&n.addMark(o,s,c.create({...e.attrs,...t}))}):n.addMark(o,s,c.create(t))})});return KD(r,n,c)},JD=(e,t)=>({tr:n})=>(n.setMeta(e,t),!0),YD=(e,t={})=>({state:n,dispatch:r,chain:i})=>{let a=KT(e,n.schema),o;return n.selection.$anchor.sameParent(n.selection.$head)&&(o=n.selection.$anchor.parent.attrs),a.isTextblock?i().command(({commands:e})=>pb(a,{...o,...t})(n)?!0:e.clearNodes()).command(({state:e})=>pb(a,{...o,...t})(e,r)).run():(console.warn(`[tiptap warn]: Currently "setNode()" only supports text block nodes.`),!1)},XD=e=>({tr:t,dispatch:n})=>{if(n){let{doc:n}=t,r=uE(e,0,n.content.size),i=X.create(n,r);t.setSelection(i)}return!0},ZD=(e,t)=>({tr:n,state:r,dispatch:i})=>{let{selection:a}=r,o,s;return typeof t==`number`?(o=t,s=t):t&&`from`in t&&`to`in t?(o=t.from,s=t.to):(o=a.from,s=a.to),i&&n.doc.nodesBetween(o,s,(t,r)=>{t.isText||n.setNodeMarkup(r,void 0,{...t.attrs,dir:e})}),!0},QD=e=>({tr:t,dispatch:n})=>{if(n){let{doc:n}=t,{from:r,to:i}=typeof e==`number`?{from:e,to:e}:e,a=hy.atStart(n).from,o=hy.atEnd(n).to,s=uE(r,a,o),c=uE(i,a,o),l=hy.create(n,s,c);t.setSelection(l)}return!0},$D=e=>({state:t,dispatch:n})=>Tb(KT(e,t.schema))(t,n);function eO(e,t){let n=e.storedMarks||e.selection.$to.parentOffset&&e.selection.$from.marks();if(n){let r=n.filter(e=>t?.includes(e.type.name));e.tr.ensureMarks(r)}}var tO=({keepMarks:e=!0}={})=>({tr:t,state:n,dispatch:r,editor:i})=>{let{selection:a,doc:o}=t,{$from:s,$to:c}=a,l=i.extensionManager.attributes,u=ID(l,s.node().type.name,s.node().attrs);if(a instanceof X&&a.node.isBlock)return!s.parentOffset||!Fv(o,s.pos)?!1:(r&&(e&&eO(n,i.extensionManager.splittableMarks),t.split(s.pos).scrollIntoView()),!0);if(!s.parent.isBlock)return!1;let d=c.parentOffset===c.parent.content.size,f=s.depth===0?void 0:TE(s.node(-1).contentMatchAt(s.indexAfter(-1))),p=d&&f?[{type:f,attrs:u}]:void 0,m=a instanceof hy&&!a.empty?Ay.create({doc:t.doc,selection:a}).tr.deleteSelection():null,h=m?m.doc:t.doc,g=m?m.mapping.map(s.pos):s.pos,_=Fv(h,g,1,p);if(!p&&!_&&Fv(h,g,1,f?[{type:f}]:void 0)&&(_=!0,p=f?[{type:f,attrs:u}]:void 0),r){if(_){let e=t.steps.length;if(a instanceof hy&&t.deleteSelection(),t.split(t.mapping.slice(e).map(s.pos),1,p),f&&!d&&!s.parentOffset&&s.parent.type!==f){let n=t.mapping.slice(e).map(s.before()),r=t.doc.resolve(n);s.node(-1).canReplaceWith(r.index(),r.index()+1,f)&&t.setNodeMarkup(t.mapping.slice(e).map(s.before()),f)}}e&&eO(n,i.extensionManager.splittableMarks),t.scrollIntoView()}return _},nO=(e,t={})=>({tr:n,state:r,dispatch:i,editor:a})=>{let o=KT(e,r.schema),{$from:s,$to:c}=r.selection,l=r.selection.node;if(l&&l.isBlock||s.depth<2||!s.sameParent(c))return!1;let u=s.node(-1);if(u.type!==o)return!1;let d=a.extensionManager.attributes;if(s.parent.content.size===0&&s.node(-1).childCount===s.indexAfter(-1)){if(s.depth===2||s.node(-3).type!==o||s.index(-2)!==s.node(-2).childCount-1)return!1;if(i){let e=J.empty,r=s.index(-1)?1:s.index(-2)?2:3;for(let t=s.depth-r;t>=s.depth-3;--t)e=J.from(s.node(t).copy(e));let i=s.indexAfter(-1)<s.node(-2).childCount?1:s.indexAfter(-2)<s.node(-3).childCount?2:3,a={...ID(d,s.node().type.name,s.node().attrs),...t},c=o.contentMatch.defaultType?.createAndFill(a)||void 0;e=e.append(J.from(o.createAndFill(null,c)||void 0));let l=s.before(s.depth-(r-1));n.replace(l,s.after(-i),new Y(e,4-r,0));let u=-1;n.doc.nodesBetween(l,n.doc.content.size,(e,t)=>{if(u>-1)return!1;e.isTextblock&&e.content.size===0&&(u=t+1)}),u>-1&&n.setSelection(hy.near(n.doc.resolve(u))),n.scrollIntoView()}return!0}let f=c.pos===s.end()?u.contentMatchAt(0).defaultType:null,p={...ID(d,u.type.name,u.attrs),...t},m={...ID(d,s.node().type.name,s.node().attrs),...t},h=s.parentOffset===0&&s.index(-1)===0,g=s.before(-1);n.delete(s.pos,c.pos);let _=h?u.attrs:p,v=f?[{type:o,attrs:_},{type:f,attrs:m}]:[{type:o,attrs:_}];if(!Fv(n.doc,s.pos,2))return!1;if(i){let{selection:e,storedMarks:t}=r,{splittableMarks:o}=a.extensionManager,c=t||e.$to.parentOffset&&e.$from.marks();if(n.split(s.pos,2,v).scrollIntoView(),h&&n.setNodeMarkup(g,void 0,p),!c||!i)return!0;let l=c.filter(e=>o.includes(e.type.name));n.ensureMarks(l)}return!0};function rO(e){return!e||e===`1`?null:e}function iO(e,t){return rO(e)===rO(t)}var aO=(e,t)=>{let n=oD(e=>e.type===t)(e.selection);if(!n)return!0;let r=e.doc.resolve(Math.max(0,n.pos-1)).before(n.depth);if(r===void 0)return!0;let i=e.doc.nodeAt(r);return!(n.node.type===i?.type&&Lv(e.doc,n.pos))||!iO(n.node.attrs.type,i?.attrs.type)||e.join(n.pos),!0},oO=(e,t)=>{let n=oD(e=>e.type===t)(e.selection);if(!n)return!0;let r=e.doc.resolve(n.start).after(n.depth);if(r===void 0)return!0;let i=e.doc.nodeAt(r);return!(n.node.type===i?.type&&Lv(e.doc,r))||!iO(n.node.attrs.type,i?.attrs.type)||e.join(r),!0};function sO(e){let t=e.doc,n=t.firstChild;if(!n)return null;let r=t.resolve(1),i=t.resolve(n.nodeSize-1);return hy.between(r,i)}var cO=(e,t,n,r={})=>({editor:i,tr:a,state:o,dispatch:s,chain:c,commands:l,can:u})=>{let{extensions:d,splittableMarks:f}=i.extensionManager,p=KT(e,o.schema),m=KT(t,o.schema),{selection:h,storedMarks:g}=o,{$from:_,$to:v}=h,y=_.blockRange(v),b=g||h.$to.parentOffset&&h.$from.marks();if(!y)return!1;let x=oD(e=>VD(e.type.name,d))(h),S=h.from===0&&h.to===o.doc.content.size,C=o.doc.content.content,w=C.length===1?C[0]:null,T=S&&w&&VD(w.type.name,d)?{node:w,pos:0,depth:0}:null,E=x??T,D=!!x&&y.depth>=1&&y.depth-x.depth<=1,O=!!T;if((D||O)&&E){if(E.node.type===p)return S&&O?c().command(({tr:e,dispatch:t})=>{let n=sO(e);return n?(e.setSelection(n),t&&t(e),!0):!1}).liftListItem(m).run():l.liftListItem(m);if(VD(E.node.type.name,d)&&p.validContent(E.node.content))return c().command(()=>(a.setNodeMarkup(E.pos,p),!0)).command(()=>aO(a,p)).command(()=>oO(a,p)).run()}return!n||!b||!s?c().command(()=>u().wrapInList(p,r)?!0:l.clearNodes()).wrapInList(p,r).command(()=>aO(a,p)).command(()=>oO(a,p)).run():c().command(()=>{let e=u().wrapInList(p,r),t=b.filter(e=>f.includes(e.type.name));return a.ensureMarks(t),e?!0:l.clearNodes()}).wrapInList(p,r).command(()=>aO(a,p)).command(()=>oO(a,p)).run()},lO=(e,t={},n={})=>({state:r,commands:i})=>{let{extendEmptyMarkRange:a=!1}=n,o=oE(e,r.schema);return RD(r,o,t)?i.unsetMark(o,{extendEmptyMarkRange:a}):i.setMark(o,t)},uO=(e,t,n={})=>({state:r,commands:i})=>{let a=KT(e,r.schema),o=KT(t,r.schema),s=zE(r,a,n),c;return r.selection.$anchor.sameParent(r.selection.$head)&&(c=r.selection.$anchor.parent.attrs),s?i.setNode(o,c):i.setNode(a,{...c,...n})},dO=(e,t={})=>({state:n,commands:r})=>{let i=KT(e,n.schema);return zE(n,i,t)?r.lift(i):r.wrapIn(i,t)},fO=()=>({state:e,dispatch:t})=>{let n=e.plugins;for(let r=0;r<n.length;r+=1){let i=n[r],a;if(i.spec.isInputRules&&(a=i.getState(e))){if(t){let t=e.tr,n=a.transform;for(let e=n.steps.length-1;e>=0;--e)t.step(n.steps[e].invert(n.docs[e]));if(a.text){let n=t.doc.resolve(a.from).marks();t.replaceWith(a.from,a.to,e.schema.text(a.text,n))}else t.delete(a.from,a.to)}return!0}}return!1},pO=(e={})=>({tr:t,dispatch:n,editor:r})=>{let{ignoreClearable:i=!1}=e,{selection:a}=t,{empty:o,ranges:s}=a;if(o)return!0;let{nonClearableMarks:c}=r.extensionManager;if(n){let e=Object.values(r.schema.marks).filter(e=>i||!c.includes(e.name));s.forEach(n=>{for(let r of e)t.removeMark(n.$from.pos,n.$to.pos,r)})}return!0},mO=(e,t={})=>({tr:n,state:r,dispatch:i})=>{let{extendEmptyMarkRange:a=!1}=t,{selection:o}=n,s=oE(e,r.schema),{$from:c,empty:l,ranges:u}=o;if(!i)return!0;if(l&&a){let{from:e,to:t}=o,r=aE(c,s,c.marks().find(e=>e.type===s)?.attrs);r&&(e=r.from,t=r.to),n.removeMark(e,t,s)}else u.forEach(e=>{n.removeMark(e.$from.pos,e.$to.pos,s)});return n.removeStoredMark(s),!0},hO=e=>({tr:t,state:n,dispatch:r})=>{let{selection:i}=n,a,o;return typeof e==`number`?(a=e,o=e):e&&`from`in e&&`to`in e?(a=e.from,o=e.to):(a=i.from,o=i.to),r&&t.doc.nodesBetween(a,o,(e,n)=>{if(e.isText)return;let r={...e.attrs};delete r.dir,t.setNodeMarkup(n,void 0,r)}),!0},gO=(e,t={})=>({tr:n,state:r,dispatch:i})=>{let a=null,o=null,s=WE(typeof e==`string`?e:e.name,r.schema);if(!s)return!1;s===`node`&&(a=KT(e,r.schema)),s===`mark`&&(o=oE(e,r.schema));let c=!1;return n.selection.ranges.forEach(e=>{let s=e.$from.pos,l=e.$to.pos,u,d,f,p;n.selection.empty?r.doc.nodesBetween(s,l,(e,t)=>{a&&a===e.type&&(c=!0,f=Math.max(t,s),p=Math.min(t+e.nodeSize,l),u=t,d=e)}):r.doc.nodesBetween(s,l,(e,r)=>{r<s&&a&&a===e.type&&(c=!0,f=Math.max(r,s),p=Math.min(r+e.nodeSize,l),u=r,d=e),r>=s&&r<=l&&(a&&a===e.type&&(c=!0,i&&n.setNodeMarkup(r,void 0,{...e.attrs,...t})),o&&e.marks.length&&e.marks.forEach(a=>{if(o===a.type&&(c=!0,i)){let i=Math.max(r,s),c=Math.min(r+e.nodeSize,l);n.addMark(i,c,o.create({...a.attrs,...t}))}}))}),d&&(u!==void 0&&i&&n.setNodeMarkup(u,void 0,{...d.attrs,...t}),o&&d.marks.length&&d.marks.forEach(e=>{o===e.type&&i&&n.addMark(f,p,o.create({...e.attrs,...t}))}))}),c},_O=new Fy(`__tiptap_decorations__`),vO=e=>({tr:t,dispatch:n})=>(n&&t.setMeta(_O,{type:`force`,name:e}),!0),yO=(e,t={})=>({state:n,dispatch:r})=>fb(KT(e,n.schema),t)(n,r),bO=(e,t={})=>({state:n,dispatch:r})=>yb(KT(e,n.schema),t)(n,r),xO=Tg({blur:()=>zT,clearContent:()=>BT,clearNodes:()=>VT,command:()=>HT,createParagraphNear:()=>UT,cut:()=>WT,deleteCurrentNode:()=>GT,deleteNode:()=>qT,deleteRange:()=>JT,deleteSelection:()=>QT,enter:()=>$T,exitCode:()=>eE,extendMarkRange:()=>sE,first:()=>cE,focus:()=>hE,forEach:()=>gE,insertContent:()=>_E,insertContentAt:()=>wE,insertDefaultBlock:()=>EE,joinBackward:()=>kE,joinDown:()=>OE,joinForward:()=>AE,joinItemBackward:()=>ME,joinItemForward:()=>NE,joinTextblockBackward:()=>PE,joinTextblockForward:()=>FE,joinUp:()=>DE,keyboardShortcut:()=>RE,lift:()=>BE,liftEmptyBlock:()=>VE,liftListItem:()=>HE,newlineInCode:()=>UE,resetAttributes:()=>KE,scrollIntoView:()=>qE,selectAll:()=>JE,selectNodeBackward:()=>YE,selectNodeForward:()=>XE,selectParentNode:()=>ZE,selectTextblockEnd:()=>QE,selectTextblockStart:()=>$E,setContent:()=>tD,setMark:()=>qD,setMeta:()=>JD,setNode:()=>YD,setNodeSelection:()=>XD,setTextDirection:()=>ZD,setTextSelection:()=>QD,sinkListItem:()=>$D,splitBlock:()=>tO,splitListItem:()=>nO,toggleList:()=>cO,toggleMark:()=>lO,toggleNode:()=>uO,toggleWrap:()=>dO,undoInputRule:()=>fO,unsetAllMarks:()=>pO,unsetMark:()=>mO,unsetTextDirection:()=>hO,updateAttributes:()=>gO,updateDecorations:()=>vO,wrapIn:()=>yO,wrapInList:()=>bO}),SO=new WeakMap;function CO(e,t){SO.set(e,(SO.get(e)??0)+1);try{return t()}finally{let t=(SO.get(e)??1)-1;t>0?SO.set(e,t):SO.delete(e)}}function wO(e){return SO.has(e)}var TO=class{constructor(){this.callbacks={}}on(e,t){return this.callbacks[e]||(this.callbacks[e]=[]),this.callbacks[e].push(t),this}emit(e,...t){let n=this.callbacks[e];return n&&n.forEach(e=>e.apply(this,t)),this}off(e,t){let n=this.callbacks[e];return n&&(t?this.callbacks[e]=n.filter(e=>e!==t):delete this.callbacks[e]),this}once(e,t){let n=(...r)=>{this.off(e,n),t.apply(this,r)};return this.on(e,n)}removeAllListeners(){this.callbacks={}}},EO=typeof process<`u`&&!1;function DO(e){return e.kind===`widget`}function OO(e,t){let n=[],r=new Set;for(let i of e)i.kind===`widget`&&DO(i)&&r.add(i.key),n.push(i.toPMDecoration(t));return{decorations:n,widgetKeys:r}}function kO(e,t,n){let{decorations:r,widgetKeys:i}=OO(t,n);return{set:lw.create(e,r),widgetKeys:i}}function AO({position:e,from:t,to:n,docSize:r}){return e<t?!1:e<n?!0:e===n&&n===r}function jO({decorations:e,from:t,to:n,docSize:r,extensionName:i,warnedExtensions:a}){return e.filter(e=>AO({position:e.anchor,from:t,to:n,docSize:r})?!0:(e.anchor===n||a.has(i)||(a.add(i),console.warn(`[tiptap warn]: Extension "${i}" returned a decoration outside the requested range [${t}, ${n}). It was ignored.`)),!1))}function MO(e){let t=e.spec?.key;return typeof t==`string`?t:void 0}function NO(e){let t=new Map,n=new Map;for(let r of e.find()){let e=MO(r);if(!e)continue;let i=r.spec.extensionName??`unknown`,a=t.get(e)??new Set;a.add(i),t.set(e,a),n.set(e,(n.get(e)??0)+1)}return Array.from(t,([e,t])=>({key:e,extensions:t})).filter(({key:e})=>(n.get(e)??0)>1)}function PO(e){return e.jsonID===`attr`}function FO(e){let t=!1;if(e.getMap().forEach(()=>{t=!0}),t||PO(e))return!0;let n=e;return typeof n.from==`number`&&typeof n.to==`number`}function IO(e,t){let n=null,r=0,i=0;for(let a=0;a<e.childCount&&!(i>t.to);a+=1){let o=i+e.child(a).nodeSize;o>=t.from&&(n===null&&(n=i),r=o),i=o}return n===null?null:{from:n,to:r}}function LO(e,t){if(e.steps.some(e=>!FO(e)))return{type:`full`};let n=ND(e).map(({newRange:e})=>e);e.steps.forEach((t,r)=>{if(!PO(t))return;let i=e.mapping.slice(r);n.push({from:i.map(t.pos,-1),to:i.map(t.pos+1)})});let r=[];for(let e of n){let n=IO(t,e);n&&r.push(n)}r.sort((e,t)=>e.from-t.from);let i=[];for(let e of r){let t=i[i.length-1];t&&e.from<=t.to?t.to=Math.max(t.to,e.to):i.push({...e})}return{type:`ranges`,ranges:i}}function RO(e,t,n,r){return e.map(t,n,{onRemove:e=>{let t=e?.key;typeof t==`string`&&r.delete(t)}})}function zO(e,t,n){let r=t.decorationSetsByExtension[e]??lw.empty,i=new Set(t.widgetKeysByExtension[e]??[]);return{set:RO(r,n.mapping,n.doc,i),widgetKeys:i}}function BO(e,t){let n=Object.values(t).flatMap(e=>e.find());return lw.create(e,n)}function VO(e){let t=new Set;for(let n of Object.values(e))for(let e of n)t.add(e);return t}function HO(e,t){switch(t.update??`document`){case`document`:if(t.createInRange)throw Error(`[tiptap error]: Extension "${e}" provides createInRange() but does not use the "changedRanges" decoration update strategy.`);return;case`changedRanges`:if(!t.createInRange)throw Error(`[tiptap error]: Extension "${e}" uses the "changedRanges" decoration update strategy but does not provide createInRange().`);return;case`manual`:if(t.createInRange)throw Error(`[tiptap error]: Extension "${e}" uses the "manual" decoration update strategy, which is not compatible with createInRange(). createInRange() requires the "changedRanges" strategy.`);if(t.shouldUpdate)throw Error(`[tiptap error]: Extension "${e}" cannot combine the "manual" decoration update strategy with shouldUpdate().`);return;default:throw Error(`[tiptap error]: Extension "${e}" uses an unknown decoration update strategy. Expected "document", "changedRanges", or "manual".`)}}function UO(e,t,n){return n?!0:e.update===`manual`?!1:e.shouldUpdate?e.shouldUpdate(t):t.tr.docChanged}var WO=new Set,GO=class{constructor(e){this.warnedWidgetKeys=new Set,this.warnedOutOfRangeExtensions=new Set,this.handleBeforeTransaction=({nextState:e})=>{let t=_O.getState(e);t&&this.warnDuplicateWidgetKeys(t)},this.editor=e.editor,this.entries=this.resolveEntries(e.entries),this.entries.forEach(({name:e,spec:t})=>HO(e,t)),this.plugin=this.entries.length>0?this.createPlugin():null,this.editor.on(`beforeTransaction`,this.handleBeforeTransaction)}destroy(){this.editor.off(`beforeTransaction`,this.handleBeforeTransaction)}liveWidgetKeys(){return _O.getState(this.editor.state)?.widgetKeys??WO}get mountedView(){return this.editor.isDestroyed?null:this.editor.view}resolveEntries(e){let t=[];for(let{name:n,addDecorations:r}of e){let e=r();e&&t.push({name:n,spec:e})}return t}createPlugin(){let{editor:e,entries:t}=this;return new My({key:_O,state:{init:(e,n)=>{let r={},i={};for(let{name:e,spec:a}of t){let{set:t,widgetKeys:o}=this.buildFullSet(e,a,n);r[e]=t,i[e]=o}let a={decorationSetsByExtension:r,widgetKeysByExtension:i,mergedDecorationSet:this.buildMergedSet(n.doc,r),widgetKeys:VO(i)};return this.warnDuplicateWidgetKeys(a),a},apply:(n,r,i,a)=>{let o=n.getMeta(_O),s=o?.type===`force`&&!o.name,c=o?.type===`force`?o.name:void 0,l={},u={},d=new Set;return CO(e,()=>{for(let{name:o,spec:f}of t){let t=s||c===o;if(!UO(f,{editor:e,tr:n,oldState:i,newState:a},t)){let e=zO(o,r,n);l[o]=e.set,u[o]=e.widgetKeys}else if(f.update===`changedRanges`&&n.docChanged&&!t){let e=this.applyChangedRangesRecompute(o,f,r,n,a);l[o]=e.set,u[o]=e.widgetKeys,d.add(o)}else{let{set:e,widgetKeys:t}=this.buildFullSet(o,f,a);l[o]=e,u[o]=t,d.add(o)}}}),d.size===0&&!n.docChanged?r:{decorationSetsByExtension:l,widgetKeysByExtension:u,mergedDecorationSet:this.mergeAfterApply({entries:t,previous:r,tr:n,decorationSetsByExtension:l,recomputedNames:d}),widgetKeys:VO(u)}}},props:{decorations(e){return _O.getState(e)?.mergedDecorationSet??lw.empty}}})}applyChangedRangesRecompute(e,t,n,r,i){let a=LO(r,i.doc);return a.type===`full`?this.buildFullSet(e,t,i):this.rebuildRanges(e,t,n,r,i,a.ranges)}rebuildRanges(e,t,n,r,i,a){let o=n.decorationSetsByExtension[e]??lw.empty,s=new Set(n.widgetKeysByExtension[e]??[]),c=RO(o,r.mapping,r.doc,s),l=i.doc.content.size;for(let{from:n,to:r}of a){let a=c.find(n,r).filter(e=>AO({position:e.from,from:n,to:r,docSize:l}));for(let e of a){let t=MO(e);t&&s.delete(t)}c=c.remove(a);let{decorations:o,widgetKeys:u}=OO(jO({decorations:this.runCreate(e,`createInRange`,()=>t.createInRange({editor:this.editor,state:i,view:this.mountedView,from:n,to:r})),from:n,to:r,docSize:l,extensionName:e,warnedExtensions:this.warnedOutOfRangeExtensions}),e);c=c.add(i.doc,o);for(let e of u)s.add(e)}return{set:c,widgetKeys:s}}buildFullSet(e,t,n){let r=this.runCreate(e,`create`,()=>t.create({editor:this.editor,state:n,view:this.mountedView}));return kO(n.doc,r,e)}runCreate(e,t,n){try{return n()}catch(n){return console.error(`[tiptap error]: Extension "${e}" threw in \`addDecorations().${t}()\`. Its decorations were dropped for this update.`,n),[]}}warnDuplicateWidgetKeys(e){if(!EO)return;if(e.widgetKeys.size===0){this.warnedWidgetKeys.clear();return}let t=NO(e.mergedDecorationSet),n=new Set(t.map(({key:e})=>e));for(let{key:e,extensions:n}of t){if(this.warnedWidgetKeys.has(e))continue;let t=Array.from(n).map(e=>`"${e}"`).join(`, `);console.warn(`[tiptap warn]: Duplicate widget decoration key "${e}" in extension${n.size===1?``:`s`} ${t}. Widget decoration keys must be globally unique, otherwise ProseMirror misplaces the widget DOM. Use a stable, unique key (e.g. \`comment-\${id}\`).`)}this.warnedWidgetKeys=n}buildMergedSet(e,t){let n=Object.keys(t);return n.length===1?t[n[0]]:BO(e,t)}mergeAfterApply({entries:e,previous:t,tr:n,decorationSetsByExtension:r,recomputedNames:i}){return e.length===1?r[e[0].name]:i.size===0?t.mergedDecorationSet.map(n.mapping,n.doc):BO(n.doc,r)}};function KO(e,t,n){let r=document.querySelector(`style[data-tiptap-style${n?`-${n}`:``}]`);if(r!==null)return r;let i=document.createElement(`style`);return t&&i.setAttribute(`nonce`,t),i.setAttribute(`data-tiptap-style${n?`-${n}`:``}`,``),i.innerHTML=e,document.getElementsByTagName(`head`)[0].appendChild(i),i}function qO(e){return e.replace(/[-/\\^$*+?.()|[\]{}]/g,`\\$&`)}function JO(e){return typeof e==`number`}function YO(e){return Object.prototype.toString.call(e).slice(8,-1)}function XO(e){return YO(e)===`Object`?e.constructor===Object&&Object.getPrototypeOf(e)===Object.prototype:!1}function ZO(e){return/\s/.test(e)}function QO(e){return/^[a-zA-Z]$/.test(e)}function $O(e){return/^\w$/.test(e)}function ek(e,t){for(;t<e.length&&ZO(e[t]);)t+=1;return t}function tk(e,t){for(;t<e.length&&!ZO(e[t]);)t+=1;return t}function nk(e,t,n){for(;t<e.length&&($O(e[t])||n&&e[t]===`-`);)t+=1;return t}function rk(e,t){let n=e[t],r=t+1,i=nk(e,r,!0);return i===r?{nextIndex:tk(e,i)}:{token:{type:n===`.`?`class`:`id`,name:e.slice(r,i)},nextIndex:tk(e,i)}}function ik(e,t){let n=e.indexOf(e[t],t+1);return{nextIndex:tk(e,n===-1?t:n+1)}}function ak(e,t,n,r){let i=r?ek(e,n):n;if(e[i]!==`=`)return;i=r?ek(e,i+1):i+1;let a=e[i];if(a!==`"`&&a!==`'`)return;let o=e.indexOf(a,i+1);if(o!==-1)return{token:{type:`keyValue`,name:t,value:e.slice(i+1,o)},nextIndex:tk(e,o+1)}}function ok(e,t,n){let r=n===`pandoc`,i=nk(e,t+1,r),a=e.slice(t,i),o=ak(e,a,i,r);if(o)return o;let s=i===e.length||ZO(e[i]);return{token:r&&s?{type:`boolean`,name:a}:void 0,nextIndex:n===`shortcode`?tk(e,i):i}}function sk(e,t,n){let r=e[t];return n===`pandoc`&&(r===`.`||r===`#`)?rk(e,t):r===`"`||r===`'`?ik(e,t):(n===`pandoc`?QO(r):$O(r))?ok(e,t,n):{nextIndex:tk(e,t)}}function ck(e,t){let n=[],r=0;for(;r<e.length&&(r=ek(e,r),!(r>=e.length));){let i=sk(e,r,t);i.token&&n.push(i.token),r=i.nextIndex}return n}function lk(e){let t={};return ck(e,`shortcode`).forEach(e=>{e.type===`keyValue`&&(t[e.name]=e.value)}),t}function uk(e){return Object.entries(e).filter(([,e])=>e!=null).map(([e,t])=>`${e}="${t}"`).join(` `)}function dk(e){let{nodeName:t,name:n,getContent:r,parseAttributes:i=lk,serializeAttributes:a=uk,defaultAttributes:o={},selfClosing:s=!1,allowedAttributes:c}=e,l=n||t,u=e=>{if(!c)return e;let t={};return c.forEach(n=>{let r=typeof n==`string`?n:n.name,i=typeof n==`string`?void 0:n.skipIfDefault;if(r in e){let n=e[r];if(i!==void 0&&n===i)return;t[r]=n}}),t},d=l.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`);return{parseMarkdown:(e,n)=>{let i={...o,...e.attributes};if(s)return n.createNode(t,i);let a=r?r(e):e.content||``;return a?n.createNode(t,i,[n.createTextNode(a)]):n.createNode(t,i,[])},markdownTokenizer:{name:t,level:`inline`,start(e){let t=RegExp(s?`\\[${d}\\s*[^\\]]*\\]`:`\\[${d}\\s*[^\\]]*\\][\\s\\S]*?\\[\\/${d}\\]`),n=e.match(t)?.index;return n===void 0?-1:n},tokenize(e,n,r){let a=RegExp(s?`^\\[${d}\\s*([^\\]]*)\\]`:`^\\[${d}\\s*([^\\]]*)\\]([\\s\\S]*?)\\[\\/${d}\\]`),o=e.match(a);if(!o)return;let c=``,l=``;if(s){let[,e]=o;l=e}else{let[,e,t]=o;l=e,c=t||``}let u=i(l.trim());return{type:t,raw:o[0],content:c.trim(),attributes:u}}},renderMarkdown:e=>{let t=``;r?t=r(e):e.content&&e.content.length>0&&(t=e.content.filter(e=>e.type===`text`).map(e=>e.text).join(``));let n=a(u(e.attrs||{})),i=n?` ${n}`:``;return s?`[${l}${i}]`:`[${l}${i}]${t}[/${l}]`}}}function fk(e,t){let n={...e};return XO(e)&&XO(t)&&Object.keys(t).forEach(r=>{XO(t[r])&&XO(e[r])?n[r]=fk(e[r],t[r]):n[r]=t[r]}),n}function pk(e,t,n={}){let{state:r}=t,{doc:i,tr:a}=r,o=e;i.descendants((t,r)=>{let i=a.mapping.map(r),s=a.mapping.map(r)+t.nodeSize,c=null;if(t.marks.forEach(e=>{if(e!==o)return!1;c=e}),!c)return;let l=!1;if(Object.keys(n).forEach(e=>{n[e]!==c.attrs[e]&&(l=!0)}),l){let t=e.type.create({...e.attrs,...n});a.removeMark(i,s,e.type),a.addMark(i,s,t)}}),a.docChanged&&t.view.dispatch(a)}var mk=class{constructor(e){this.find=e.find,this.handler=e.handler,this.undoable=e.undoable??!0}},hk=(e,t)=>{if(tE(t))return t.exec(e);let n=t(e);if(!n)return null;let r=[n.text];return r.index=n.index,r.input=e,r.data=n.data,n.replaceWith&&(n.text.includes(n.replaceWith)||console.warn(`[tiptap warn]: "inputRuleMatch.replaceWith" must be part of "inputRuleMatch.text".`),r.push(n.replaceWith)),r};function gk(e){let{editor:t,from:n,to:r,text:i,insertText:a}=e;if(!a)return{inputTransaction:null,tr:t.view.state.tr};let o=t.view.state.tr.insertText(i,n,r);return{inputTransaction:o,tr:Ay.create({doc:o.doc,selection:o.selection,storedMarks:o.storedMarks}).tr}}function _k(e){let{editor:t,from:n,to:r,text:i,rule:a,match:o,plugin:s,insertText:c}=e,{view:l}=t,{inputTransaction:u,tr:d}=gk({editor:t,from:n,to:r,text:i,insertText:c}),f=u?n+i.length:r,p=LT({state:l.state,transaction:d}),m={from:n-(o[0].length-i.length),to:f},{commands:h,chain:g,can:_}=new RT({editor:t,state:p});return a.handler({state:p,range:m,match:o,commands:h,chain:g,can:_})===null||!d.steps.length?!1:u&&(l.dispatch(u),!l.state.doc.eq(u.doc))?!0:(kT(d),d.setMeta(`inputRule`,!0),a.undoable&&d.setMeta(s,{transform:d,from:n,to:f,text:i}),l.dispatch(d),!0)}function vk(e,t,n){let r=t[0].length-n.length;if(r<=0)return!0;let i=e.parentOffset-r;return i>=0&&e.parent.textBetween(i,e.parentOffset)===t[0].slice(0,r)}function yk(e){let{editor:t,from:n,to:r,text:i,rules:a,plugin:o,insertText:s}=e,{view:c}=t;if(c.composing)return!1;let l=c.state.doc.resolve(n);if(l.parent.type.spec.code||(l.nodeBefore||l.nodeAfter)?.marks.find(e=>e.type.spec.code))return!1;let u=LD(l)+i;for(let e of a){let a=hk(u,e.find);if(!(!a||!vk(l,a,i))&&_k({editor:t,from:n,to:r,text:i,rule:e,match:a,plugin:o,insertText:s}))return!0}return!1}function bk(e){let{editor:t,rules:n}=e,r=new My({state:{init(){return null},apply(e,i,a){let o=e.getMeta(r);if(o)return o;let s=e.getMeta(`applyInputRules`);return s&&setTimeout(()=>{let{text:e}=s;e=typeof e==`string`?e:cD(J.from(e),a.schema);let{from:i}=s;yk({editor:t,from:i,to:i+e.length,text:e,rules:n,plugin:r})}),e.selectionSet||e.docChanged?null:i}},props:{handleTextInput(e,i,a,o){return yk({editor:t,from:i,to:a,text:o,rules:n,plugin:r,insertText:!0})},handleDOMEvents:{compositionend:e=>(setTimeout(()=>{let{$cursor:i}=e.state.selection;i&&yk({editor:t,from:i.pos,to:i.pos,text:``,rules:n,plugin:r})}),!1)},handleKeyDown(e,i){if(i.key!==`Enter`)return!1;let{$cursor:a}=e.state.selection;return a?yk({editor:t,from:a.pos,to:a.pos,text:`
|
|
20
|
+
`,rules:n,plugin:r}):!1}},isInputRules:!0});return r}var xk=class{constructor(e={}){this.type=`extendable`,this.parent=null,this.child=null,this.name=``,this.config={name:this.name},this.config={...this.config,...e},this.name=this.config.name}get options(){return{...uD(Q(this,`addOptions`,{name:this.name}))}}get storage(){return{...uD(Q(this,`addStorage`,{name:this.name,options:this.options}))}}configure(e={}){let t=this.extend({...this.config,addOptions:()=>fk(this.options,e)});return t.name=this.name,t.parent=this.parent,this.child=null,t}extend(e={}){let t=new this.constructor({...this.config,...e});return t.parent=this,this.child=t,t.name=`name`in e?e.name:t.parent.name,t}},Sk=class e extends xk{constructor(...e){super(...e),this.type=`mark`}static create(t={}){return new e(typeof t==`function`?t():t)}static handleExit({editor:e,mark:t}){let{tr:n}=e.state,r=e.state.selection.$from;if(r.pos===r.end()){let i=r.marks();if(!i.find(e=>e?.type.name===t.name))return!1;let a=i.find(e=>e?.type.name===t.name);return a&&n.removeStoredMark(a),n.insertText(` `,r.pos),e.view.dispatch(n),!0}return!1}configure(e){return super.configure(e)}extend(e){let t=typeof e==`function`?e():e;return super.extend(t)}},Ck=class{constructor(e){this.find=e.find,this.handler=e.handler}},wk=(e,t,n)=>{if(tE(t))return[...e.matchAll(t)];let r=t(e,n);return r?r.map(t=>{let n=[t.text];return n.index=t.index,n.input=e,n.data=t.data,t.replaceWith&&(t.text.includes(t.replaceWith)||console.warn(`[tiptap warn]: "pasteRuleMatch.replaceWith" must be part of "pasteRuleMatch.text".`),n.push(t.replaceWith)),n}):[]};function Tk(e){let{editor:t,state:n,from:r,to:i,rule:a,pasteEvent:o,dropEvent:s}=e,{commands:c,chain:l,can:u}=new RT({editor:t,state:n}),d=[];return n.doc.nodesBetween(r,i,(e,t)=>{var f;if(!((f=e.type)==null||(f=f.spec)==null)&&f.code||!(e.isText||e.isTextblock||e.isInline))return;let p=e.content?.size??e.nodeSize??0,m=Math.max(r,t),h=Math.min(i,t+p);m>=h||wk(e.isText?e.text||``:e.textBetween(m-t,h-t,void 0,``),a.find,o).forEach(e=>{if(e.index===void 0)return;let t=m+e.index+1,r=t+e[0].length,i={from:n.tr.mapping.map(t),to:n.tr.mapping.map(r)},f=a.handler({state:n,range:i,match:e,commands:c,chain:l,can:u,pasteEvent:o,dropEvent:s});d.push(f)})}),d.every(e=>e!==null)}var Ek=null,Dk=e=>{var t;let n=new ClipboardEvent(`paste`,{clipboardData:new DataTransfer});return(t=n.clipboardData)==null||t.setData(`text/html`,e),n};function Ok(e){let{editor:t,rules:n}=e,r=null,i=!1,a=!1,o=typeof ClipboardEvent<`u`?new ClipboardEvent(`paste`):null,s;try{s=typeof DragEvent<`u`?new DragEvent(`drop`):null}catch{s=null}let c=({state:e,from:n,to:r,rule:i,pasteEvt:a})=>{let c=e.tr;if(!(!Tk({editor:t,state:LT({state:e,transaction:c}),from:Math.max(n-1,0),to:r.b-1,rule:i,pasteEvent:a,dropEvent:s})||!c.steps.length)){try{s=typeof DragEvent<`u`?new DragEvent(`drop`):null}catch{s=null}return o=typeof ClipboardEvent<`u`?new ClipboardEvent(`paste`):null,c}};return t.on(`destroy`,()=>{Ek===t&&(Ek=null)}),n.map(e=>new My({view(e){let n=n=>{r=e.dom.parentElement?.contains(n.target)?e.dom.parentElement:null,r&&(Ek=t)},i=()=>{Ek&&=null};return window.addEventListener(`dragstart`,n),window.addEventListener(`dragend`,i),{destroy(){window.removeEventListener(`dragstart`,n),window.removeEventListener(`dragend`,i)}}},props:{handleDOMEvents:{drop:(e,t)=>{if(a=r===e.dom.parentElement,s=t,!a){let e=Ek;e?.isEditable&&setTimeout(()=>{if(e.isDestroyed)return;let t=e.state.selection;t&&e.commands.deleteRange({from:t.from,to:t.to})},10)}return!1},paste:(e,t)=>{let n=t.clipboardData?.getData(`text/html`);return o=t,i=!!n?.includes(`data-pm-slice`),!1}}},appendTransaction:(t,n,r)=>{let s=t[0],l=s.getMeta(`uiEvent`)===`paste`&&!i,u=s.getMeta(`uiEvent`)===`drop`&&!a,d=s.getMeta(`applyPasteRules`),f=!!d;if(!l&&!u&&!f)return;if(f){let{text:t}=d;t=typeof t==`string`?t:cD(J.from(t),r.schema);let{from:n}=d,i=n+t.length,a=Dk(t);return c({rule:e,state:r,from:n,to:{b:i},pasteEvt:a})}let p=n.doc.content.findDiffStart(r.doc.content),m=n.doc.content.findDiffEnd(r.doc.content);if(!(!JO(p)||!m||p===m.b))return c({rule:e,state:r,from:p,to:m,pasteEvt:o})}}))}var kk=class{constructor(e,t){this.splittableMarks=[],this.nonClearableMarks=[],this.decorationManager=null,this.editor=t,this.baseExtensions=e,this.extensions=TD(e),this.schema=SD(this.extensions,t),this.setupExtensions()}get commands(){return this.extensions.reduce((e,t)=>{let n=Q(t,`addCommands`,{name:t.name,options:t.options,storage:this.editor.extensionStorage[t.name],editor:this.editor,type:FD(t.name,this.schema)});return n?{...e,...n()}:e},{})}get plugins(){let{editor:e}=this,t=wD([...this.extensions].reverse()).flatMap(t=>{let n={name:t.name,options:t.options,storage:this.editor.extensionStorage[t.name],editor:e,type:FD(t.name,this.schema)},r=[],i=Q(t,`addKeyboardShortcuts`,n),a={};if(t.type===`mark`&&Q(t,`exitable`,n)&&(a.ArrowRight=()=>Sk.handleExit({editor:e,mark:t})),i){let t=Object.fromEntries(Object.entries(i()).map(([t,n])=>[t,()=>n({editor:e})]));a={...a,...t}}let o=lT(a);r.push(o);let s=Q(t,`addInputRules`,n);if(BD(t,e.options.enableInputRules)&&s){let t=s();if(t&&t.length){let n=bk({editor:e,rules:t}),i=Array.isArray(n)?n:[n];r.push(...i)}}let c=Q(t,`addPasteRules`,n);if(BD(t,e.options.enablePasteRules)&&c){let t=c();if(t&&t.length){let n=Ok({editor:e,rules:t});r.push(...n)}}let l=Q(t,`addProseMirrorPlugins`,n);if(l){let e=l();r.push(...e)}return r}),n=this.createDecorationPlugin();return n&&t.push(n),t}createDecorationPlugin(){var e;let{editor:t}=this;(e=this.decorationManager)==null||e.destroy();let n=[];return this.extensions.forEach(e=>{let r=Q(e,`addDecorations`,{name:e.name,options:e.options,storage:this.editor.extensionStorage[e.name],editor:t,type:FD(e.name,this.schema)});r&&n.push({name:e.name,addDecorations:r})}),this.decorationManager=new GO({editor:t,entries:n}),this.decorationManager.plugin}get attributes(){return pD(this.extensions)}get nodeViews(){let{editor:e}=this,{nodeExtensions:t}=fD(this.extensions);return Object.fromEntries(t.filter(e=>!!Q(e,`addNodeView`)).map(t=>{let n=this.attributes.filter(e=>e.type===t.name),r=Q(t,`addNodeView`,{name:t.name,options:t.options,storage:this.editor.extensionStorage[t.name],editor:e,type:KT(t.name,this.schema)});if(!r)return[];let i=r();return i?[t.name,(r,a,o,s,c)=>i({node:r,view:a,getPos:o,decorations:s,innerDecorations:c,editor:e,extension:t,HTMLAttributes:_D(r,n)})]:[]}))}dispatchTransaction(e){let{editor:t}=this;return wD([...this.extensions].reverse()).reduceRight((e,n)=>{let r={name:n.name,options:n.options,storage:this.editor.extensionStorage[n.name],editor:t,type:FD(n.name,this.schema)},i=Q(n,`dispatchTransaction`,r);return i?t=>{i.call(r,{transaction:t,next:e})}:e},e)}transformPastedHTML(e){let{editor:t}=this;return wD([...this.extensions]).reduce((e,n)=>{let r={name:n.name,options:n.options,storage:this.editor.extensionStorage[n.name],editor:t,type:FD(n.name,this.schema)},i=Q(n,`transformPastedHTML`,r);return i?(t,n)=>{let a=e(t,n);return i.call(r,a)}:e},e||(e=>e))}get markViews(){let{editor:e}=this,{markExtensions:t}=fD(this.extensions);return Object.fromEntries(t.filter(e=>!!Q(e,`addMarkView`)).map(t=>{let n=this.attributes.filter(e=>e.type===t.name),r=Q(t,`addMarkView`,{name:t.name,options:t.options,storage:this.editor.extensionStorage[t.name],editor:e,type:oE(t.name,this.schema)});return r?[t.name,(i,a,o)=>{let s=_D(i,n);return r()({mark:i,view:a,inline:o,editor:e,extension:t,HTMLAttributes:s,updateAttributes:t=>{pk(i,e,t)}})}]:[]}))}destroy(){var e;(e=this.decorationManager)==null||e.destroy(),this.extensions.forEach(e=>{let t=e;for(;t.parent;){let e=t.parent;e.child===t&&(e.child=null),t=e}}),this.extensions=[],this.baseExtensions=[],this.decorationManager=null,this.schema=null,this.editor=null}setupExtensions(){let e=this.extensions;this.editor.extensionStorage=Object.fromEntries(e.map(e=>[e.name,e.storage])),e.forEach(e=>{let t={name:e.name,options:e.options,storage:this.editor.extensionStorage[e.name],editor:this.editor,type:FD(e.name,this.schema)};e.type===`mark`&&((uD(Q(e,`keepOnSplit`,t))??!0)&&this.splittableMarks.push(e.name),(uD(Q(e,`clearable`,t))??!0)||this.nonClearableMarks.push(e.name));let n=Q(e,`onBeforeCreate`,t),r=Q(e,`onCreate`,t),i=Q(e,`onUpdate`,t),a=Q(e,`onSelectionUpdate`,t),o=Q(e,`onTransaction`,t),s=Q(e,`onFocus`,t),c=Q(e,`onBlur`,t),l=Q(e,`onDestroy`,t);n&&this.editor.on(`beforeCreate`,n),r&&this.editor.on(`create`,r),i&&this.editor.on(`update`,i),a&&this.editor.on(`selectionUpdate`,a),o&&this.editor.on(`transaction`,o),s&&this.editor.on(`focus`,s),c&&this.editor.on(`blur`,c),l&&this.editor.on(`destroy`,l)})}};kk.resolve=TD,kk.sort=wD,kk.flatten=sD;var Ak=class e extends xk{constructor(...e){super(...e),this.type=`extension`}static create(t={}){return new e(typeof t==`function`?t():t)}configure(e){return super.configure(e)}extend(e){let t=typeof e==`function`?e():e;return super.extend(t)}},jk=Ak.create({name:`clipboardTextSerializer`,addOptions(){return{blockSeparator:void 0}},addProseMirrorPlugins(){return[new My({key:new Fy(`clipboardTextSerializer`),props:{clipboardTextSerializer:()=>{let{editor:e}=this,{state:t,schema:n}=e,{doc:r,selection:i}=t,a=OD(n),{blockSeparator:o}=this.options,s={...o===void 0?{}:{blockSeparator:o},textSerializers:a};return[...i.ranges].sort((e,t)=>e.$from.pos-t.$from.pos).map(({$from:e,$to:t})=>ED(r,{from:e.pos,to:t.pos},s)).join(o??`
|
|
21
|
+
|
|
22
|
+
`)}}})]}}),Mk=Ak.create({name:`commands`,addCommands(){return{...xO}}}),Nk=Ak.create({name:`delete`,onUpdate({transaction:e,appendedTransactions:t}){var n;let r=()=>{var n,r;if(((n=this.editor.options.coreExtensionOptions)==null||(n=n.delete)==null||(r=n.filterTransaction)==null?void 0:r.call(n,e))??e.getMeta(`y-sync$`))return;let i=rD(e.before,[e,...t]);ND(i).forEach(t=>{i.mapping.mapResult(t.oldRange.from).deletedAfter&&i.mapping.mapResult(t.oldRange.to).deletedBefore&&i.before.nodesBetween(t.oldRange.from,t.oldRange.to,(n,r)=>{let a=r+n.nodeSize-2,o=t.oldRange.from<=r&&a<=t.oldRange.to;this.editor.emit(`delete`,{type:`node`,node:n,from:r,to:a,newFrom:i.mapping.map(r),newTo:i.mapping.map(a),deletedRange:t.oldRange,newRange:t.newRange,partial:!o,editor:this.editor,transaction:e,combinedTransform:i})})});let a=i.mapping;i.steps.forEach((t,n)=>{if(t instanceof pv){let r=a.slice(n).map(t.from,-1),o=a.slice(n).map(t.to),s=a.invert().map(r,-1),c=a.invert().map(o),l=r>0?i.doc.nodeAt(r-1)?.marks.some(e=>e.eq(t.mark)):!1,u=i.doc.nodeAt(o)?.marks.some(e=>e.eq(t.mark));this.editor.emit(`delete`,{type:`mark`,mark:t.mark,from:t.from,to:t.to,deletedRange:{from:s,to:c},newRange:{from:r,to:o},partial:!!(u||l),editor:this.editor,transaction:e,combinedTransform:i})}})};((n=this.editor.options.coreExtensionOptions)==null||(n=n.delete)==null?void 0:n.async)??!0?setTimeout(r,0):r()}}),Pk=Ak.create({name:`drop`,addProseMirrorPlugins(){return[new My({key:new Fy(`tiptapDrop`),props:{handleDrop:(e,t,n,r)=>{this.editor.emit(`drop`,{editor:this.editor,event:t,slice:n,moved:r})}}})]}}),Fk=Ak.create({name:`editable`,addProseMirrorPlugins(){return[new My({key:new Fy(`editable`),props:{editable:()=>this.editor.options.editable}})]}}),Ik=new Fy(`focusEvents`),Lk=Ak.create({name:`focusEvents`,addProseMirrorPlugins(){let{editor:e}=this;return[new My({key:Ik,props:{handleDOMEvents:{focus:(t,n)=>{e.isFocused=!0;let r=e.state.tr.setMeta(`focus`,{event:n}).setMeta(`addToHistory`,!1);return t.dispatch(r),!1},blur:(t,n)=>{e.isFocused=!1;let r=e.state.tr.setMeta(`blur`,{event:n}).setMeta(`addToHistory`,!1);return t.dispatch(r),!1}}}})]}}),Rk=Ak.create({name:`keymap`,addKeyboardShortcuts(){let e=()=>this.editor.commands.first(({commands:e})=>[()=>e.undoInputRule(),()=>e.command(({tr:t})=>{let{selection:n,doc:r}=t,{empty:i,$anchor:a}=n,{pos:o,parent:s}=a,c=a.parent.isTextblock&&o>0?t.doc.resolve(o-1):a,l=c.parent.type.spec.isolating,u=a.pos-a.parentOffset,d=l&&c.parent.childCount===1?u===a.pos:dy.atStart(r).from===o;return!i||!s.type.isTextblock||s.textContent.length||!d||d&&a.parent.type.name===`paragraph`?!1:e.clearNodes()}),()=>e.deleteSelection(),()=>e.joinBackward(),()=>e.selectNodeBackward()]),t=()=>this.editor.commands.first(({commands:e})=>[()=>e.deleteSelection(),()=>e.deleteCurrentNode(),()=>e.joinForward(),()=>e.selectNodeForward()]),n={Enter:()=>this.editor.commands.first(({commands:e})=>[()=>e.newlineInCode(),()=>e.createParagraphNear(),()=>e.liftEmptyBlock(),()=>e.splitBlock()]),"Mod-Enter":()=>this.editor.commands.exitCode(),Backspace:e,"Mod-Backspace":e,"Shift-Backspace":e,Delete:t,"Mod-Delete":t,"Mod-a":()=>this.editor.commands.selectAll()},r={...n},i={...n,"Ctrl-h":e,"Alt-Backspace":e,"Ctrl-d":t,"Ctrl-Alt-Backspace":t,"Alt-Delete":t,"Alt-d":t,"Ctrl-a":()=>this.editor.commands.selectTextblockStart(),"Ctrl-e":()=>this.editor.commands.selectTextblockEnd()};return pE()||IE()?i:r},addProseMirrorPlugins(){return[new My({key:new Fy(`clearDocument`),appendTransaction:(e,t,n)=>{if(e.some(e=>e.getMeta(`composition`)))return;let r=e.some(e=>e.docChanged)&&!t.doc.eq(n.doc),i=e.some(e=>e.getMeta(`preventClearDocument`));if(!r||i)return;let{empty:a,from:o,to:s}=t.selection,c=dy.atStart(t.doc).from,l=dy.atEnd(t.doc).to;if(a||!(o===c&&s===l)||!HD(n.doc))return;let u=n.tr,d=LT({state:n,transaction:u}),{commands:f}=new RT({editor:this.editor,state:d});if(f.clearNodes(),u.steps.length)return u}})]}}),zk=Ak.create({name:`paste`,addProseMirrorPlugins(){return[new My({key:new Fy(`tiptapPaste`),props:{handlePaste:(e,t,n)=>{this.editor.emit(`paste`,{editor:this.editor,event:t,slice:n})}}})]}}),Bk=Ak.create({name:`tabindex`,addOptions(){return{value:void 0}},addProseMirrorPlugins(){return[new My({key:new Fy(`tabindex`),props:{attributes:()=>!this.editor.isEditable&&this.options.value===void 0?{}:{tabindex:this.options.value??`0`}}})]}}),Vk=Ak.create({name:`textDirection`,addOptions(){return{direction:void 0}},addGlobalAttributes(){if(!this.options.direction)return[];let{nodeExtensions:e}=fD(this.extensions);return[{types:e.filter(e=>e.name!==`text`).map(e=>e.name),attributes:{dir:{default:this.options.direction,parseHTML:e=>{let t=e.getAttribute(`dir`);return t&&(t===`ltr`||t===`rtl`||t===`auto`)?t:this.options.direction},renderHTML:e=>e.dir?{dir:e.dir}:{}}}}]},addProseMirrorPlugins(){return[new My({key:new Fy(`textDirection`),props:{attributes:()=>{let e=this.options.direction;return e?{dir:e}:{}}}})]}}),Hk=!1;function Uk(e){if(Hk)return;Hk=!0;let t;try{t=gv.fromJSON(e,{from:0,to:0}).slice.content}catch{return}t instanceof J||console.warn(`[tiptap warn]: prosemirror-model is loaded more than once. Wrapping and splitting nodes will fail. Deduplicate it in your lock file, or alias it to a single copy in your bundler.`)}var Wk=class e{get name(){return this.node.type.name}constructor(e,t,n=!1,r=null){this.currentNode=null,this.actualDepth=null,this.isBlock=n,this.resolvedPos=e,this.editor=t,this.currentNode=r}get node(){return this.currentNode||this.resolvedPos.node()}get element(){return this.editor.view.domAtPos(this.pos).node}get depth(){return this.actualDepth??this.resolvedPos.depth}get pos(){return this.resolvedPos.pos}get content(){return this.node.content}set content(e){let t=this.from,n=this.to;if(this.isBlock){if(this.content.size===0){console.error(`You can’t set content on a block node. Tried to set content on ${this.name} at ${this.pos}`);return}t=this.from+1,n=this.to-1}this.editor.commands.insertContentAt({from:t,to:n},e)}get attributes(){return this.node.attrs}get textContent(){return this.node.textContent}get size(){return this.node.nodeSize}get from(){return this.isBlock?this.pos:this.resolvedPos.start(this.resolvedPos.depth)}get range(){return{from:this.from,to:this.to}}get to(){return this.isBlock?this.pos+this.size:this.resolvedPos.end(this.resolvedPos.depth)+ +!this.node.isText}get parent(){if(this.depth===0)return null;let t=this.resolvedPos.start(this.resolvedPos.depth-1);return new e(this.resolvedPos.doc.resolve(t),this.editor)}get before(){let t=this.resolvedPos.doc.resolve(this.from-(this.isBlock?1:2));return t.depth!==this.depth&&(t=this.resolvedPos.doc.resolve(this.from-3)),new e(t,this.editor)}get after(){let t=this.resolvedPos.doc.resolve(this.to+(this.isBlock?2:1));return t.depth!==this.depth&&(t=this.resolvedPos.doc.resolve(this.to+3)),new e(t,this.editor)}get children(){let t=[];return this.node.content.forEach((n,r)=>{let i=n.isBlock&&!n.isTextblock,a=n.isAtom&&!n.isText,o=n.isInline,s=this.pos+r+ +!a;if(s<0||s>this.resolvedPos.doc.nodeSize-2)return;let c=this.resolvedPos.doc.resolve(s);if(!i&&!o&&c.depth<=this.depth)return;let l=new e(c,this.editor,i,i||o?n:null);i&&(l.actualDepth=this.depth+1),t.push(l)}),t}get firstChild(){return this.children[0]||null}get lastChild(){let e=this.children;return e[e.length-1]||null}closest(e,t={}){let n=null,r=this.parent;for(;r&&!n;){if(r.node.type.name===e)if(Object.keys(t).length>0){let e=r.node.attrs,n=Object.keys(t);for(let r=0;r<n.length;r+=1){let i=n[r];if(e[i]!==t[i])break}}else n=r;r=r.parent}return n}querySelector(e,t={}){return this.querySelectorAll(e,t,!0)[0]||null}querySelectorAll(e,t={},n=!1){let r=[];if(!this.children||this.children.length===0)return r;let i=Object.keys(t);return this.children.forEach(a=>{n&&r.length>0||(a.node.type.name===e&&i.every(e=>t[e]===a.node.attrs[e])&&r.push(a),!(n&&r.length>0)&&(r=r.concat(a.querySelectorAll(e,t,n))))}),r}setAttribute(e){let{tr:t}=this.editor.state;t.setNodeMarkup(this.from,void 0,{...this.node.attrs,...e}),this.editor.view.dispatch(t)}},Gk=`.ProseMirror {
|
|
23
|
+
position: relative;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
.ProseMirror {
|
|
27
|
+
word-wrap: break-word;
|
|
28
|
+
white-space: pre-wrap;
|
|
29
|
+
white-space: break-spaces;
|
|
30
|
+
-webkit-font-variant-ligatures: none;
|
|
31
|
+
font-variant-ligatures: none;
|
|
32
|
+
font-feature-settings: "liga" 0; /* the above doesn't seem to work in Edge */
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
.ProseMirror [contenteditable="false"] {
|
|
36
|
+
white-space: normal;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
.ProseMirror [contenteditable="false"] [contenteditable="true"] {
|
|
40
|
+
white-space: pre-wrap;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
.ProseMirror pre {
|
|
44
|
+
white-space: pre-wrap;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
img.ProseMirror-separator {
|
|
48
|
+
display: inline !important;
|
|
49
|
+
border: none !important;
|
|
50
|
+
margin: 0 !important;
|
|
51
|
+
width: 0 !important;
|
|
52
|
+
height: 0 !important;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
.ProseMirror-gapcursor {
|
|
56
|
+
display: none;
|
|
57
|
+
pointer-events: none;
|
|
58
|
+
position: absolute;
|
|
59
|
+
margin: 0;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
.ProseMirror-gapcursor:after {
|
|
63
|
+
content: "";
|
|
64
|
+
display: block;
|
|
65
|
+
position: absolute;
|
|
66
|
+
top: -2px;
|
|
67
|
+
width: 20px;
|
|
68
|
+
border-top: 1px solid black;
|
|
69
|
+
animation: ProseMirror-cursor-blink 1.1s steps(2, start) infinite;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
@keyframes ProseMirror-cursor-blink {
|
|
73
|
+
to {
|
|
74
|
+
visibility: hidden;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
.ProseMirror-hideselection *::selection {
|
|
79
|
+
background: transparent;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
.ProseMirror-hideselection *::-moz-selection {
|
|
83
|
+
background: transparent;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
.ProseMirror-hideselection * {
|
|
87
|
+
caret-color: transparent;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
.ProseMirror-focused .ProseMirror-gapcursor {
|
|
91
|
+
display: block;
|
|
92
|
+
}`,Kk=class extends TO{constructor(e={}){super(),this.css=null,this.className=`tiptap`,this.editorView=null,this.isFocused=!1,this.destroyed=!1,this.isInitialized=!1,this.extensionStorage={},this.instanceId=Math.random().toString(36).slice(2,9),this.hasWarnedStaleDecorationRead=!1,this.options={element:typeof document<`u`?document.createElement(`div`):null,content:``,injectCSS:!0,injectNonce:void 0,extensions:[],autofocus:!1,editable:!0,textDirection:void 0,editorProps:{},parseOptions:{},coreExtensionOptions:{},enableInputRules:!0,enablePasteRules:!0,enableCoreExtensions:!0,enableContentCheck:!1,emitContentError:!1,onBeforeCreate:()=>null,onCreate:()=>null,onMount:()=>null,onUnmount:()=>null,onUpdate:()=>null,onSelectionUpdate:()=>null,onTransaction:()=>null,onFocus:()=>null,onBlur:()=>null,onDestroy:()=>null,onContentError:({error:e})=>{throw e},onPaste:()=>null,onDrop:()=>null,onDelete:()=>null,enableExtensionDispatchTransaction:!0},this.isCapturingTransaction=!1,this.capturedTransaction=null,this.utils={getUpdatedPosition:WD,createMappablePosition:GD},this.setOptions(e),this.createExtensionManager(),this.createCommandManager(),this.createSchema(),this.on(`beforeCreate`,this.options.onBeforeCreate),this.emit(`beforeCreate`,{editor:this}),this.on(`mount`,this.options.onMount),this.on(`unmount`,this.options.onUnmount),this.on(`contentError`,this.options.onContentError),this.on(`create`,this.options.onCreate),this.on(`update`,this.options.onUpdate),this.on(`selectionUpdate`,this.options.onSelectionUpdate),this.on(`transaction`,this.options.onTransaction),this.on(`focus`,this.options.onFocus),this.on(`blur`,this.options.onBlur),this.on(`destroy`,this.options.onDestroy),this.on(`drop`,({event:e,slice:t,moved:n})=>this.options.onDrop(e,t,n)),this.on(`paste`,({event:e,slice:t})=>this.options.onPaste(e,t)),this.on(`delete`,this.options.onDelete);let t=this.createDoc();if(!this.editorState){let e=dE(t,this.options.autofocus);this.editorState=Ay.create({doc:t,schema:this.schema,selection:e||void 0})}Uk(this.schema),this.options.element&&this.mount(this.options.element)}mount(e){if(typeof document>`u`)throw Error(`[tiptap error]: The editor cannot be mounted because there is no 'document' defined in this environment.`);this.createView(e),this.emit(`mount`,{editor:this}),this.css&&!document.head.contains(this.css)&&document.head.appendChild(this.css),window.setTimeout(()=>{this.isDestroyed||(this.options.autofocus!==!1&&this.options.autofocus!==null&&this.commands.focus(this.options.autofocus),this.emit(`create`,{editor:this}),this.isInitialized=!0)},0)}unmount(){if(this.editorView){this.editorState=this.editorView.state;let e=this.editorView.dom;e?.editor&&delete e.editor,this.editorView.destroy()}if(this.editorView=null,this.isInitialized=!1,this.css&&!document.querySelectorAll(`.${this.className}`).length)try{typeof this.css.remove==`function`?this.css.remove():this.css.parentNode&&this.css.parentNode.removeChild(this.css)}catch(e){console.warn(`Failed to remove CSS element:`,e)}this.css=null,this.emit(`unmount`,{editor:this})}get storage(){return this.extensionStorage}get commands(){return this.commandManager.commands}chain(){return this.commandManager?this.commandManager.chain():RT.createFakeChain()}can(){return this.commandManager?this.commandManager.can():RT.createFallbackCan()}injectCSS(){this.options.injectCSS&&typeof document<`u`&&(this.css=KO(Gk,this.options.injectNonce))}setOptions(e={}){this.options={...this.options,...e},!(!this.editorView||!this.state||this.isDestroyed)&&(this.options.editorProps&&this.view.setProps({...this.options.editorProps,attributes:this.getEditorViewAttributes()}),this.view.updateState(this.state))}setEditable(e,t=!0){this.setOptions({editable:e}),t&&this.emit(`update`,{editor:this,transaction:this.state.tr,appendedTransactions:[]})}get isEditable(){return this.options.editable&&this.view&&this.view.editable}get view(){return this.editorView?this.editorView:new Proxy({state:this.editorState,updateState:e=>{this.editorState=e},dispatch:e=>{this.dispatchTransaction(e)},composing:!1,dragging:null,editable:!0,isDestroyed:!1},{get:(e,t)=>{if(this.editorView)return this.editorView[t];if(t===`state`)return this.editorState;if(t in e)return Reflect.get(e,t);throw Error(`[tiptap error]: The editor view is not available. Cannot access view['${t}']. The editor may not be mounted yet.`)}})}get state(){return EO&&!this.hasWarnedStaleDecorationRead&&wO(this)&&(this.hasWarnedStaleDecorationRead=!0,console.warn("[tiptap warn]: `editor.state` was read while decoration `create()` was running. It returns the pre-transaction document. Use the `state` argument passed to `create()` instead. Helpers like `editor.isActive()` read `editor.state` too, so pass `state` to their standalone versions instead of calling them on the editor.")),this.editorView&&(this.editorState=this.view.state),this.editorState}registerPlugin(e,t){let n=lD(t)?t(e,[...this.state.plugins]):[...this.state.plugins,e],r=this.state.reconfigure({plugins:n});return this.view.updateState(r),r}unregisterPlugin(e){if(this.isDestroyed)return;let t=this.state.plugins,n=t;if([].concat(e).forEach(e=>{let t=typeof e==`string`?`${e}$`:e.key;n=n.filter(e=>!e.key.startsWith(t))}),t.length===n.length)return;let r=this.state.reconfigure({plugins:n});return this.view.updateState(r),r}createExtensionManager(){var e,t;let n=[...this.options.enableCoreExtensions?[Fk,jk.configure({blockSeparator:(e=this.options.coreExtensionOptions)==null||(e=e.clipboardTextSerializer)==null?void 0:e.blockSeparator}),Mk,Lk,Rk,Bk.configure({value:(t=this.options.coreExtensionOptions)==null||(t=t.tabindex)==null?void 0:t.value}),Pk,zk,Nk,Vk.configure({direction:this.options.textDirection})].filter(e=>typeof this.options.enableCoreExtensions==`object`?this.options.enableCoreExtensions[e.name]!==!1:!0):[],...this.options.extensions].filter(e=>[`extension`,`node`,`mark`].includes(e?.type));this.extensionManager=new kk(n,this)}createCommandManager(){this.commandManager=new RT({editor:this})}createSchema(){this.schema=this.extensionManager.schema}createDoc(){let e;try{e=eD(this.options.content,this.schema,this.options.parseOptions,{errorOnInvalidContent:this.options.enableContentCheck})}catch(e){if(!(e instanceof Error)||![`[tiptap error]: Invalid JSON content`,`[tiptap error]: Invalid HTML content`].includes(e.message))throw e;let t=eD(this.options.content,this.schema,this.options.parseOptions,{errorOnInvalidContent:!1});return this.editorState=Ay.create({doc:t,schema:this.schema,selection:dE(t,this.options.autofocus)||void 0}),this.emit(`contentError`,{editor:this,error:e,disableCollaboration:()=>{`collaboration`in this.storage&&typeof this.storage.collaboration==`object`&&this.storage.collaboration&&(this.storage.collaboration.isDisabled=!0),this.options.extensions=this.options.extensions.filter(e=>e.name!==`collaboration`),this.createExtensionManager()}}),this.editorState.doc}return e}getEditorViewAttributes(){let e=this.options.editorProps?.attributes;return lD(e)?t=>({role:`textbox`,...e(t)}):{role:`textbox`,...e}}createView(e){let{editorProps:t,enableExtensionDispatchTransaction:n}=this.options,r=t.dispatchTransaction||this.dispatchTransaction.bind(this),i=n?this.extensionManager.dispatchTransaction(r):r,a=t.transformPastedHTML,o=this.extensionManager.transformPastedHTML(a);this.editorView=new Uw(e,{...t,attributes:this.getEditorViewAttributes(),dispatchTransaction:i,transformPastedHTML:o,state:this.editorState,markViews:this.extensionManager.markViews,nodeViews:this.extensionManager.nodeViews});let s=this.state.reconfigure({plugins:this.extensionManager.plugins});this.view.updateState(s),this.prependClass(),this.injectCSS();let c=this.view.dom;c.editor=this}createNodeViews(){this.view.isDestroyed||this.view.setProps({markViews:this.extensionManager.markViews,nodeViews:this.extensionManager.nodeViews})}prependClass(){this.view.dom.className=`${this.className} ${this.view.dom.className}`}captureTransaction(e){this.isCapturingTransaction=!0,e(),this.isCapturingTransaction=!1;let t=this.capturedTransaction;return this.capturedTransaction=null,t}dispatchTransaction(e){if(this.view.isDestroyed)return;if(this.isCapturingTransaction){if(!this.capturedTransaction){this.capturedTransaction=e;return}e.steps.forEach(e=>this.capturedTransaction?.step(e));return}let{state:t,transactions:n}=this.state.applyTransaction(e),r=!this.state.selection.eq(t.selection),i=n.includes(e),a=this.state;if(this.emit(`beforeTransaction`,{editor:this,transaction:e,nextState:t}),!i)return;this.view.updateState(t),this.emit(`transaction`,{editor:this,transaction:e,appendedTransactions:n.slice(1)}),r&&this.emit(`selectionUpdate`,{editor:this,transaction:e});let o=n.findLast(e=>e.getMeta(`focus`)||e.getMeta(`blur`)),s=o?.getMeta(`focus`),c=o?.getMeta(`blur`);s&&this.emit(`focus`,{editor:this,event:s.event,transaction:o}),c&&this.emit(`blur`,{editor:this,event:c.event,transaction:o}),!(e.getMeta(`preventUpdate`)||!n.some(e=>e.docChanged)||a.doc.eq(t.doc))&&this.emit(`update`,{editor:this,transaction:e,appendedTransactions:n.slice(1)})}getAttributes(e){return AD(this.state,e)}isActive(e,t){let n=typeof e==`string`?e:null,r=typeof e==`string`?t:e;return zD(this.state,n,r)}getJSON(){return this.state.doc.toJSON()}getHTML(){return cD(this.state.doc.content,this.schema)}getText(e){let{blockSeparator:t=`
|
|
93
|
+
|
|
94
|
+
`,textSerializers:n={}}=e||{};return DD(this.state.doc,{blockSeparator:t,textSerializers:{...OD(this.schema),...n}})}get isEmpty(){return HD(this.state.doc)}destroy(){this.destroyed||(this.destroyed=!0,this.emit(`destroy`),this.unmount(),this.removeAllListeners(),this.extensionManager.destroy(),this.extensionManager=null,this.schema=null,this.commandManager=null,this.extensionStorage={})}get isDestroyed(){return this.editorView?.isDestroyed??!0}$node(e,t){return this.$doc?.querySelector(e,t)||null}$nodes(e,t){return this.$doc?.querySelectorAll(e,t)||null}$pos(e){let t=this.state.doc.resolve(e),n=e>0&&t.nodeAfter&&!t.nodeAfter.isText&&t.nodeAfter.isAtom?t.nodeAfter:null;return new Wk(t,this,!1,n)}get $doc(){return this.$pos(0)}};function qk(e){return new mk({find:e.find,handler:({state:t,range:n,match:r})=>{let i=uD(e.getAttributes,void 0,r);if(i===!1||i===null)return null;let{tr:a}=t,o=r[r.length-1],s=r[0];if(o){let r=s.search(/\S/),c=n.from+s.indexOf(o),l=c+o.length;if(PD(n.from,n.to,t.doc).filter(t=>t.mark.type.excluded.find(n=>n===e.type&&n!==t.mark.type)).filter(e=>e.to>c).length)return null;l<n.to&&a.delete(l,n.to),c>n.from&&a.delete(n.from+r,c);let u=n.from+r+o.length;a.addMark(n.from+r,u,e.type.create(i||{})),a.removeStoredMark(e.type)}},undoable:e.undoable})}var Jk=class e extends xk{constructor(...e){super(...e),this.type=`node`}static create(t={}){return new e(typeof t==`function`?t():t)}configure(e){return super.configure(e)}extend(e){let t=typeof e==`function`?e():e;return super.extend(t)}};function Yk(e){return new Ck({find:e.find,handler:({state:t,range:n,match:r,pasteEvent:i})=>{let a=uD(e.getAttributes,void 0,r,i);if(a===!1||a===null)return null;let{tr:o}=t,s=r[r.length-1],c=r[0],l=n.to;if(s){let i=c.search(/\S/),u=n.from+c.indexOf(s),d=u+s.length;if(PD(n.from,n.to,t.doc).filter(t=>t.mark.type.excluded.find(n=>n===e.type&&n!==t.mark.type)).filter(e=>e.to>u).length)return null;d<n.to&&o.delete(d,n.to),u>n.from&&o.delete(n.from+i,u),l=n.from+i+s.length,o.addMark(n.from+i,l,e.type.create(a||{})),r.index!==void 0&&r.input!==void 0&&r.index+r[0].length>=r.input.length||o.removeStoredMark(e.type)}}})}var Xk=l(),{getOwnPropertyNames:Zk,getOwnPropertySymbols:Qk}=Object,{hasOwnProperty:$k}=Object.prototype;function eA(e,t){return function(n,r,i){return e(n,r,i)&&t(n,r,i)}}function tA(e){return function(t,n,r){if(!t||!n||typeof t!=`object`||typeof n!=`object`)return e(t,n,r);let{cache:i}=r,a=i.get(t),o=i.get(n);if(a&&o)return a===n&&o===t;i.set(t,n),i.set(n,t);let s=e(t,n,r);return i.delete(t),i.delete(n),s}}function nA(e){return e?.[Symbol.toStringTag]}function rA(e){return Zk(e).concat(Qk(e))}var iA=Object.hasOwn||((e,t)=>$k.call(e,t));function aA(e,t){return e===t||!e&&!t&&e!==e&&t!==t}var oA=`__v`,sA=`__o`,cA=`_owner`,lA=typeof Float16Array<`u`,{getOwnPropertyDescriptor:uA,keys:dA}=Object;function fA(e,t){return e.byteLength===t.byteLength&&TA(new Uint8Array(e),new Uint8Array(t))}function pA(e,t,n){let r=e.length;if(t.length!==r)return!1;for(;r-->0;)if(!n.equals(e[r],t[r],r,r,e,t,n))return!1;return!0}function mA(e,t){return e.byteLength===t.byteLength&&TA(new Uint8Array(e.buffer,e.byteOffset,e.byteLength),new Uint8Array(t.buffer,t.byteOffset,t.byteLength))}function hA(e,t){return aA(e.getTime(),t.getTime())}function gA(e,t,n){return e.name===t.name&&e.message===t.message&&e.stack===t.stack&&n.equals(e.cause,t.cause,`cause`,`cause`,e,t,n)}function _A(e,t){return e===t}function vA(e,t,n){let r=e.size;if(r!==t.size)return!1;if(!r)return!0;let i=Array(r),a=e.entries(),o,s,c=0;for(;(o=a.next())&&!o.done;){let r=t.entries(),a=!1,l=0;for(;(s=r.next())&&!s.done;){if(i[l]){l++;continue}let r=o.value,u=s.value;if(n.equals(r[0],u[0],c,l,e,t,n)&&n.equals(r[1],u[1],r[0],u[0],e,t,n)){a=i[l]=!0;break}l++}if(!a)return!1;c++}return!0}var yA=aA;function bA(e,t,n){let r=dA(e),i=r.length;if(dA(t).length!==i)return!1;for(;i-->0;)if(!kA(e,t,n,r[i]))return!1;return!0}function xA(e,t,n){let r=rA(e),i=r.length;if(rA(t).length!==i)return!1;let a,o,s;for(;i-->0;)if(a=r[i],!kA(e,t,n,a)||(o=uA(e,a),s=uA(t,a),(o||s)&&(!o||!s||o.configurable!==s.configurable||o.enumerable!==s.enumerable||o.writable!==s.writable)))return!1;return!0}function SA(e,t){return aA(e.valueOf(),t.valueOf())}function CA(e,t){return e.source===t.source&&e.flags===t.flags}function wA(e,t,n){let r=e.size;if(r!==t.size)return!1;if(!r)return!0;let i=Array(r),a=e.values(),o,s;for(;(o=a.next())&&!o.done;){let r=t.values(),a=!1,c=0;for(;(s=r.next())&&!s.done;){if(!i[c]&&n.equals(o.value,s.value,o.value,s.value,e,t,n)){a=i[c]=!0;break}c++}if(!a)return!1}return!0}function TA(e,t){let n=e.length;if(t.length!==n||e.byteOffset!==t.byteOffset)return!1;if(e instanceof Float64Array||e instanceof Float32Array||lA&&e instanceof Float16Array){for(;n-->0;)if(e[n]!==t[n]&&(e[n]===e[n]||t[n]===t[n]))return!1;return!0}for(;n-->0;)if(e[n]!==t[n])return!1;return!0}function EA(e,t){return e.href===t.href?!0:e.protocol===t.protocol&&e.username===t.username&&e.password===t.password&&e.host===t.host&&e.pathname===t.pathname&&e.hash===t.hash&&DA(e.searchParams,t.searchParams)}function DA(e,t){let n=e.toString(),r=t.toString();return n===r||OA(n)===OA(r)}function OA(e){return e.split(`&`).sort().join(`&`)}function kA(e,t,n,r){return(r===cA||r===sA||r===oA)&&(e.$$typeof||t.$$typeof)?!0:iA(t,r)&&n.equals(e[r],t[r],r,r,e,t,n)}var AA=`[object ArrayBuffer]`,jA=`[object Arguments]`,MA=`[object Boolean]`,NA=`[object DataView]`,PA=`[object Date]`,FA=`[object Error]`,IA=`[object Map]`,LA=`[object Number]`,RA=`[object Object]`,zA=`[object RegExp]`,BA=`[object Set]`,VA=`[object String]`,HA={"[object Int8Array]":!0,"[object Uint8Array]":!0,"[object Uint8ClampedArray]":!0,"[object Int16Array]":!0,"[object Uint16Array]":!0,"[object Int32Array]":!0,"[object Uint32Array]":!0,"[object Float16Array]":!0,"[object Float32Array]":!0,"[object Float64Array]":!0,"[object BigInt64Array]":!0,"[object BigUint64Array]":!0},UA=`[object URL]`,WA=Object.prototype.toString;function GA({areArrayBuffersEqual:e,areArraysEqual:t,areDataViewsEqual:n,areDatesEqual:r,areErrorsEqual:i,areFunctionsEqual:a,areMapsEqual:o,areNumbersEqual:s,areObjectsEqual:c,arePrimitiveWrappersEqual:l,areRegExpsEqual:u,areSetsEqual:d,areTypedArraysEqual:f,areUrlsEqual:p,unknownTagComparators:m}){return function(h,g,_){if(h===g)return!0;if(h==null||g==null)return!1;let v=typeof h;if(v!==typeof g)return!1;if(v!==`object`)return v===`number`?s(h,g,_):v===`function`?a(h,g,_):!1;let y=h.constructor;if(y!==g.constructor)return!1;if(y===Object)return c(h,g,_);if(Array.isArray(h))return t(h,g,_);if(y===Date)return r(h,g,_);if(y===RegExp)return u(h,g,_);if(y===Map)return o(h,g,_);if(y===Set)return d(h,g,_);if(y==null)return c(h,g,_);let b=WA.call(h);if(b===PA)return r(h,g,_);if(b===zA)return u(h,g,_);if(b===IA)return o(h,g,_);if(b===BA)return d(h,g,_);if(b===RA)return typeof h.then!=`function`&&typeof g.then!=`function`&&c(h,g,_);if(b===UA)return p(h,g,_);if(b===FA)return i(h,g,_);if(b===jA)return c(h,g,_);if(HA[b])return f(h,g,_);if(b===AA)return e(h,g,_);if(b===NA)return n(h,g,_);if(b===MA||b===LA||b===VA)return l(h,g,_);if(m){let e=m[b];if(!e){let t=nA(h);t&&(e=m[t])}if(e)return e(h,g,_)}return!1}}function KA({circular:e,createCustomConfig:t,strict:n}){let r={areArrayBuffersEqual:fA,areArraysEqual:n?xA:pA,areDataViewsEqual:mA,areDatesEqual:hA,areErrorsEqual:n?eA(gA,xA):eA(gA,bA),areFunctionsEqual:_A,areMapsEqual:n?eA(vA,xA):vA,areNumbersEqual:yA,areObjectsEqual:n?xA:bA,arePrimitiveWrappersEqual:SA,areRegExpsEqual:CA,areSetsEqual:n?eA(wA,xA):wA,areTypedArraysEqual:n?eA(TA,xA):TA,areUrlsEqual:EA,unknownTagComparators:void 0};if(t&&(r=Object.assign({},r,t(r))),e){let e=tA(r.areArraysEqual),t=tA(r.areErrorsEqual),n=tA(r.areMapsEqual),i=tA(r.areObjectsEqual),a=tA(r.areSetsEqual);r=Object.assign({},r,{areArraysEqual:e,areErrorsEqual:t,areMapsEqual:n,areObjectsEqual:i,areSetsEqual:a})}return r}function qA(e){return function(t,n,r,i,a,o,s){return e(t,n,s)}}function JA({circular:e,comparator:t,createState:n,equals:r,strict:i}){if(n)return function(a,o){let{cache:s=e?new WeakMap:void 0,meta:c}=n();return t(a,o,{cache:s,equals:r,meta:c,strict:i})};if(e)return function(e,n){return t(e,n,{cache:new WeakMap,equals:r,meta:void 0,strict:i})};let a={cache:void 0,equals:r,meta:void 0,strict:i};return function(e,n){return t(e,n,a)}}var YA=XA();XA({strict:!0}),XA({circular:!0}),XA({circular:!0,strict:!0}),XA({createInternalComparator:()=>aA}),XA({strict:!0,createInternalComparator:()=>aA}),XA({circular:!0,createInternalComparator:()=>aA}),XA({circular:!0,createInternalComparator:()=>aA,strict:!0});function XA(e={}){let{circular:t=!1,createInternalComparator:n,createState:r,strict:i=!1}=e,a=GA(KA(e));return JA({circular:t,comparator:a,createState:r,equals:n?n(a):qA(a),strict:i})}var ZA=t((e=>{var t=n(),r=l();function i(e,t){return e===t&&(e!==0||1/e==1/t)||e!==e&&t!==t}var a=typeof Object.is==`function`?Object.is:i,o=r.useSyncExternalStore,s=t.useRef,c=t.useEffect,u=t.useMemo,d=t.useDebugValue;e.useSyncExternalStoreWithSelector=function(e,t,n,r,i){var l=s(null);if(l.current===null){var f={hasValue:!1,value:null};l.current=f}else f=l.current;l=u(function(){function e(e){if(!o){if(o=!0,s=e,e=r(e),i!==void 0&&f.hasValue){var t=f.value;if(i(t,e))return c=t}return c=e}if(t=c,a(s,e))return t;var n=r(e);return i!==void 0&&i(t,n)?(s=e,t):(s=e,c=n)}var o=!1,s,c,l=n===void 0?null:n;return[function(){return e(t())},l===null?void 0:function(){return e(l())}]},[t,n,r,i]);var p=o(e,l[0],l[1]);return c(function(){f.hasValue=!0,f.value=p},[p]),d(p),p}})),QA=t(((e,t)=>{t.exports=ZA()}))();function $A(e,t){if(e.isDestroyed||t.defaultPrevented||!t.cancelable||!e.isEditable||t.inputType!==`insertParagraph`&&t.inputType!==`insertLineBreak`||!pE()&&!fE())return;let n=e.view,r=n.root,i=(r.getSelection?.call(r)??n.dom.ownerDocument.getSelection())?.anchorNode,a=(i?.nodeType===1?i:i?.parentElement)?.closest(`[data-node-view-content-react]`);if(!a||!n.dom.contains(a))return;let o=n.input.lastKeyCode;o===13&&(n.input.lastKeyCode=null),n.domObserver.forceFlush(),n.domObserver.flush();let s=new KeyboardEvent(`keydown`,{key:`Enter`,code:`Enter`,keyCode:13,shiftKey:t.inputType===`insertLineBreak`,bubbles:!0,cancelable:!0});n.someProp(`handleKeyDown`,e=>e(n,s))?(t.preventDefault(),n.input.lastIOSEnter=0,clearTimeout(n.input.lastIOSEnterFallbackTimeout)):o===13&&(n.input.lastKeyCode=o)}var ej=new Fy(`reactMobileEnter`),tj=(...e)=>t=>{e.forEach(e=>{typeof e==`function`?e(t):e&&(e.current=t)})},nj=({contentComponent:e})=>{let t=(0,Xk.useSyncExternalStore)(e.subscribe,e.getSnapshot,e.getServerSnapshot);return(0,q.jsx)(q.Fragment,{children:Object.values(t)})};function rj(){let e=new Set,t={},n=!1,r=()=>{n||!e.size||(n=!0,queueMicrotask(()=>{n=!1,e.forEach(e=>e())}))};return{subscribe(t){return e.add(t),()=>{e.delete(t)}},getSnapshot(){return t},getServerSnapshot(){return t},setRenderer(e,n){t={...t,[e]:ra.createPortal(n.reactElement,n.element,e)},r()},removeRenderer(e){let n={...t};delete n[e],t=n,r()}}}var ij=class extends K.Component{constructor(e){super(e),this.editorContentRef=K.createRef()}componentDidMount(){this.init()}componentDidUpdate(){this.init()}init(){let e=this.props.editor;if(e&&!e.isDestroyed&&e.view.dom?.parentNode){if(e.contentComponent)return;let t=this.editorContentRef.current;t.append(...e.view.dom.parentNode.childNodes),e.setOptions({element:t}),e.contentComponent=rj(),e.createNodeViews(),e.registerPlugin(new My({key:ej,props:{handleDOMEvents:{beforeinput:(t,n)=>$A(e,n)}}})),e.isEditorContentInitialized=!0,this.forceUpdate()}}componentWillUnmount(){let e=this.props.editor;if(e){e.isEditorContentInitialized=!1,e.isDestroyed||(e.unregisterPlugin(ej),e.view.setProps({nodeViews:{}})),e.contentComponent=null;try{if(!e.view.dom?.parentNode)return;let t=document.createElement(`div`);t.append(...e.view.dom.parentNode.childNodes),e.setOptions({element:t})}catch{}}}render(){let{editor:e,innerRef:t,...n}=this.props;return(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(`div`,{ref:tj(t,this.editorContentRef),...n}),e?.contentComponent&&(0,q.jsx)(nj,{contentComponent:e.contentComponent})]})}},aj=(0,K.forwardRef)((e,t)=>{let n=K.useMemo(()=>Math.floor(Math.random()*4294967295).toString(),[e.editor]);return K.createElement(ij,{key:n,innerRef:t,...e})}),oj=K.memo(aj),sj=typeof window<`u`?K.useLayoutEffect:K.useEffect,cj=class{constructor(e){this.transactionNumber=0,this.lastTransactionNumber=0,this.subscribers=new Set,this.editor=e,this.lastSnapshot={editor:e,transactionNumber:0},this.getSnapshot=this.getSnapshot.bind(this),this.getServerSnapshot=this.getServerSnapshot.bind(this),this.watch=this.watch.bind(this),this.subscribe=this.subscribe.bind(this)}getSnapshot(){return this.transactionNumber===this.lastTransactionNumber?this.lastSnapshot:(this.lastTransactionNumber=this.transactionNumber,this.lastSnapshot={editor:this.editor,transactionNumber:this.transactionNumber},this.lastSnapshot)}getServerSnapshot(){return{editor:null,transactionNumber:0}}subscribe(e){return this.subscribers.add(e),()=>{this.subscribers.delete(e)}}watch(e){if(this.editor=e,this.editor){let e,t=t=>{t?.transaction!==void 0&&t.transaction===e||(e=t?.transaction,this.transactionNumber+=1,this.subscribers.forEach(e=>e()))},n=this.editor;return n.on(`transaction`,t),n.on(`update`,t),()=>{n.off(`transaction`,t),n.off(`update`,t)}}}};function lj(e){let[t]=(0,K.useState)(()=>new cj(e.editor)),n=(0,QA.useSyncExternalStoreWithSelector)(t.subscribe,t.getSnapshot,t.getServerSnapshot,e.selector,e.equalityFn??YA);return sj(()=>t.watch(e.editor),[e.editor,t]),(0,K.useDebugValue)(n),n}var uj=typeof window>`u`,dj=uj||!!(typeof window<`u`&&window.next),fj=class e{constructor(e){this.editor=null,this.subscriptions=new Set,this.isComponentMounted=!1,this.previousDeps=null,this.instanceId=``,this.options=e,this.subscriptions=new Set,this.setEditor(this.getInitialEditor()),this.scheduleDestroy(),this.getEditor=this.getEditor.bind(this),this.getServerSnapshot=this.getServerSnapshot.bind(this),this.subscribe=this.subscribe.bind(this),this.refreshEditorInstance=this.refreshEditorInstance.bind(this),this.scheduleDestroy=this.scheduleDestroy.bind(this),this.onRender=this.onRender.bind(this),this.createEditor=this.createEditor.bind(this)}setEditor(e){this.editor=e,this.instanceId=Math.random().toString(36).slice(2,9),this.subscriptions.forEach(e=>e())}getInitialEditor(){let e=this.options.current.immediatelyRender,t=e??!0;return(uj||dj&&e===void 0)&&(t=!1),t?this.createEditor():null}createEditor(){return new Kk({...this.options.current,onBeforeCreate:(...e)=>{var t;return(t=this.options.current).onBeforeCreate?.call(t,...e)},onBlur:(...e)=>{var t;return(t=this.options.current).onBlur?.call(t,...e)},onCreate:(...e)=>{var t;return(t=this.options.current).onCreate?.call(t,...e)},onDestroy:(...e)=>{var t;return(t=this.options.current).onDestroy?.call(t,...e)},onFocus:(...e)=>{var t;return(t=this.options.current).onFocus?.call(t,...e)},onSelectionUpdate:(...e)=>{var t;return(t=this.options.current).onSelectionUpdate?.call(t,...e)},onTransaction:(...e)=>{var t;return(t=this.options.current).onTransaction?.call(t,...e)},onUpdate:(...e)=>{var t;return(t=this.options.current).onUpdate?.call(t,...e)},onContentError:(...e)=>{var t;return(t=this.options.current).onContentError?.call(t,...e)},onDrop:(...e)=>{var t;return(t=this.options.current).onDrop?.call(t,...e)},onPaste:(...e)=>{var t;return(t=this.options.current).onPaste?.call(t,...e)},onDelete:(...e)=>{var t;return(t=this.options.current).onDelete?.call(t,...e)},onMount:(...e)=>{var t;return(t=this.options.current).onMount?.call(t,...e)},onUnmount:(...e)=>{var t;return(t=this.options.current).onUnmount?.call(t,...e)}})}getEditor(){return this.editor}getServerSnapshot(){return null}subscribe(e){return this.subscriptions.add(e),()=>{this.subscriptions.delete(e)}}static compareOptions(e,t){return Object.keys(e).every(n=>[`onCreate`,`onBeforeCreate`,`onDestroy`,`onUpdate`,`onTransaction`,`onFocus`,`onBlur`,`onSelectionUpdate`,`onContentError`,`onDrop`,`onPaste`].includes(n)?!0:n===`extensions`&&e.extensions&&t.extensions?e.extensions.length===t.extensions.length?e.extensions.every((e,n)=>e===t.extensions?.[n]):!1:e[n]===t[n])}onRender(t){return()=>(this.isComponentMounted=!0,clearTimeout(this.scheduledDestructionTimeout),this.editor&&!this.editor.isDestroyed&&t.length===0?e.compareOptions(this.options.current,this.editor.options)||this.editor.setOptions({...this.options.current,editable:this.editor.isEditable}):this.refreshEditorInstance(t),()=>{this.isComponentMounted=!1,this.scheduleDestroy()})}refreshEditorInstance(e){if(this.editor&&!this.editor.isDestroyed){if(this.previousDeps===null){this.previousDeps=e;return}if(this.previousDeps.length===e.length&&this.previousDeps.every((t,n)=>t===e[n]))return}this.editor&&!this.editor.isDestroyed&&this.editor.destroy(),this.setEditor(this.createEditor()),this.previousDeps=e}scheduleDestroy(){let e=this.instanceId,t=this.editor;this.scheduledDestructionTimeout=setTimeout(()=>{if(this.isComponentMounted&&this.instanceId===e){t&&t.setOptions(this.options.current);return}t&&!t.isDestroyed&&(t.destroy(),this.instanceId===e&&this.setEditor(null))},1)}};function pj(e={},t=[]){let n=(0,K.useRef)(e);n.current=e;let[r]=(0,K.useState)(()=>new fj(n)),i=(0,Xk.useSyncExternalStore)(r.subscribe,r.getEditor,r.getServerSnapshot);return(0,K.useDebugValue)(i),(0,K.useEffect)(r.onRender(t)),lj({editor:i,selector:({transactionNumber:t})=>e.shouldRerenderOnTransaction===!1||e.shouldRerenderOnTransaction===void 0?null:e.immediatelyRender&&t===0?0:t+1}),i}var mj=(0,K.createContext)({editor:null});mj.Consumer;var hj=(0,K.createContext)({onDragStart:()=>{},nodeViewContentChildren:void 0,nodeViewContentRef:()=>{}}),gj=()=>(0,K.useContext)(hj);K.forwardRef((e,t)=>{let{onDragStart:n}=gj();return(0,q.jsx)(e.as||`div`,{...e,ref:t,"data-node-view-wrapper":``,onDragStart:n,style:{whiteSpace:`normal`,...e.style}})}),K.createContext({markViewContentRef:()=>{}});var _j=(0,K.createContext)({get editor(){throw Error(`useTiptap must be used within a <Tiptap> provider`)}});_j.displayName=`TiptapContext`;var vj=()=>(0,K.useContext)(_j);function yj({children:e,...t}){let n=`editor`in t?t.editor:t.instance;if(!n)throw Error("Tiptap: An editor instance is required. Pass a non-null `editor` prop.");let r=(0,K.useMemo)(()=>({editor:n}),[n]),i=(0,K.useMemo)(()=>({editor:n}),[n]);return(0,q.jsx)(mj.Provider,{value:i,children:(0,q.jsx)(_j.Provider,{value:r,children:e})})}yj.displayName=`Tiptap`;function bj({...e}){let{editor:t}=vj();return(0,q.jsx)(oj,{editor:t,...e})}bj.displayName=`Tiptap.Content`,Object.assign(yj,{Content:bj});var xj=Jk.create({name:`doc`,topNode:!0,content:`block+`,renderMarkdown:(e,t)=>e.content?t.renderChildren(e.content,`
|
|
95
|
+
|
|
96
|
+
`):``}),Sj=` `,Cj=`\xA0`,wj=Jk.create({name:`paragraph`,priority:1e3,addOptions(){return{HTMLAttributes:{}}},group:`block`,content:`inline*`,parseHTML(){return[{tag:`p`}]},renderHTML({HTMLAttributes:e}){return[`p`,gD(this.options.HTMLAttributes,e),0]},parseMarkdown:(e,t)=>{let n=e.tokens||[];if(n.length===1&&n[0].type===`image`)return t.parseChildren([n[0]]);let r=t.parseInline(n);return n.length===1&&n[0].type===`text`&&(n[0].raw===Sj||n[0].text===Sj||n[0].raw===Cj||n[0].text===Cj)&&r.length===1&&r[0].type===`text`&&(r[0].text===Sj||r[0].text===Cj)?t.createNode(`paragraph`,void 0,[]):t.createNode(`paragraph`,void 0,r)},renderMarkdown:(e,t,n)=>{if(!e)return``;let r=Array.isArray(e.content)?e.content:[];if(r.length===0){var i,a;let e=Array.isArray(n==null||(i=n.previousNode)==null?void 0:i.content)?n.previousNode.content:[];return(n==null||(a=n.previousNode)==null?void 0:a.type)===`paragraph`&&e.length===0?Sj:``}return t.renderChildren(r)},addCommands(){return{setParagraph:()=>({commands:e})=>e.setNode(this.name)}},addKeyboardShortcuts(){return{"Mod-Alt-0":()=>this.editor.commands.setParagraph()}}}),Tj=Jk.create({name:`text`,group:`inline`,parseMarkdown:e=>({type:`text`,text:e.text||``}),renderMarkdown:e=>e.text||``}),Ej=Jk.create({name:`hardBreak`,markdownTokenName:`br`,addOptions(){return{keepMarks:!0,HTMLAttributes:{}}},inline:!0,group:`inline`,selectable:!1,linebreakReplacement:!0,parseHTML(){return[{tag:`br`}]},renderHTML({HTMLAttributes:e}){return[`br`,gD(this.options.HTMLAttributes,e)]},renderText(){return`
|
|
97
|
+
`},renderMarkdown:()=>`
|
|
98
|
+
`,parseMarkdown:()=>({type:`hardBreak`}),addCommands(){return{setHardBreak:()=>({commands:e,chain:t,state:n,editor:r})=>e.first([()=>e.exitCode(),()=>e.command(()=>{let{selection:e,storedMarks:i}=n;if(e.$from.parent.type.spec.isolating)return!1;let{keepMarks:a}=this.options,{splittableMarks:o}=r.extensionManager,s=i||e.$to.parentOffset&&e.$from.marks();return t().insertContent({type:this.name}).command(({tr:e,dispatch:t})=>{if(t&&s&&a){let t=s.filter(e=>o.includes(e.type.name));e.ensureMarks(t)}return!0}).scrollIntoView().run()})])}},addKeyboardShortcuts(){return{"Mod-Enter":()=>this.editor.commands.setHardBreak(),"Shift-Enter":()=>this.editor.commands.setHardBreak()}}});function Dj(e){let{char:t,allowSpaces:n,allowToIncludeChar:r,allowedPrefixes:i,startOfLine:a,$position:o}=e,s=n&&!r,c=qO(t),l=RegExp(`\\s${c}$`),u=a?`^`:``,d=r?``:c,f=RegExp(s?`${u}${c}.*?(?=\\s${d}|$)`:`${u}(?:^)?${c}[^\\s${d}]*`,`gm`),p=o.nodeBefore?.isText&&o.nodeBefore.text;if(!p)return null;let m=o.pos-p.length,h=Array.from(p.matchAll(f)).pop();if(!h||h.input===void 0||h.index===void 0)return null;let g=h.input.slice(Math.max(0,h.index-1),h.index),_=RegExp(`^[${i?.join(``)}\0]?$`).test(g);if(i!==null&&!_)return null;let v=m+h.index,y=v+h[0].length;return s&&l.test(p.slice(y-1,y+1))&&(h[0]+=` `,y+=1),v<o.pos&&y>=o.pos?{range:{from:v,to:y},query:h[0].slice(t.length),text:h[0]}:null}function Oj(e){return e.docChanged?e.steps.some(e=>{let t=e.slice;if(!t?.content)return!1;let n=t.content.textBetween(0,t.content.size,`
|
|
99
|
+
`);return/\s/.test(n)}):!1}function kj(e){return()=>{let t=e.state.selection.$anchor.pos,{top:n,right:r,bottom:i,left:a}=e.view.coordsAtPos(t);try{return new DOMRect(a,n,r-a,i-n)}catch{return null}}}function Aj(e,t,n,r){return n?()=>{let n=r.getState(e.state)?.decorationId;return t.dom.querySelector(`[data-decoration-id="${n}"]`)?.getBoundingClientRect()||null}:kj(e)}function jj({match:e,dismissedRange:t,state:n,transaction:r,editor:i,shouldResetDismissed:a,effectiveAllowSpaces:o}){return a?.({editor:i,state:n,range:t,match:e,transaction:r,allowSpaces:o})?!1:o?e.range.from===t.from:e.range.from===t.from&&!Oj(r)}function Mj({view:e,pluginKeyRef:t}){let n=e.state.tr.setMeta(t,{exit:!0});e.dispatch(n)}function Nj({pluginKey:e,decorationTag:t,decorationClass:n,decorationContent:r,decorationEmptyClass:i,renderer:a,dispatchExit:o}){return{handleKeyDown(t,n){var r;let i=e.getState(t.state);if(!i.active)return!1;if(n.key===`Escape`||n.key===`Esc`){var s;return a==null||(s=a.onKeyDown)==null||s.call(a,{view:t,event:n,range:i.range}),o(t),!0}return(a==null||(r=a.onKeyDown)==null?void 0:r.call(a,{view:t,event:n,range:i.range}))||!1},decorations(a){let{active:o,range:s,decorationId:c,query:l}=e.getState(a);if(!o)return null;let u=!l?.length,d=[n];return u&&d.push(i),lw.create(a.doc,[ow.inline(s.from,s.to,{nodeName:t,class:d.join(` `),"data-decoration-id":c||void 0,"data-decoration-content":r})])}}}function Pj({editor:e,char:t,effectiveAllowSpaces:n,allowToIncludeChar:r,allowedPrefixes:i,startOfLine:a,findSuggestionMatch:o,allow:s,shouldShow:c,shouldKeepDismissed:l,pluginKey:u}){return{init(){return{active:!1,range:{from:0,to:0},query:null,text:null,composing:!1,dismissedRange:null}},apply(d,f,p,m){let{isEditable:h}=e,{composing:g}=e.view,{selection:_}=d,{empty:v,from:y}=_,b={...f},x=d.getMeta(u);if(x&&x.exit)return b.active=!1,b.decorationId=null,b.range={from:0,to:0},b.query=null,b.text=null,b.dismissedRange=f.active?{...f.range}:f.dismissedRange,b;if(b.composing=g,d.docChanged&&b.dismissedRange!==null&&(b.dismissedRange={from:d.mapping.map(b.dismissedRange.from),to:d.mapping.map(b.dismissedRange.to)}),h&&(v||e.view.composing)){(y<f.range.from||y>f.range.to)&&!g&&!f.composing&&(b.active=!1);let u=o({char:t,allowSpaces:n,allowToIncludeChar:r,allowedPrefixes:i,startOfLine:a,$position:_.$from}),p=`id_${Math.floor(Math.random()*4294967295)}`;u&&s({editor:e,state:m,range:u.range,isActive:f.active})&&(!c||c({editor:e,range:u.range,query:u.query,text:u.text,transaction:d}))?(b.dismissedRange!==null&&!l({match:u,dismissedRange:b.dismissedRange,state:m,transaction:d})&&(b.dismissedRange=null),b.dismissedRange===null?(b.active=!0,b.decorationId=f.decorationId||p,b.range=u.range,b.query=u.query,b.text=u.text):b.active=!1):(u||(b.dismissedRange=null),b.active=!1)}else b.active=!1;return b.active||(b.decorationId=null,b.range={from:0,to:0},b.query=null,b.text=null),b}}}function Fj({editor:e,items:t}){let n=null,r=null,i=null,a=()=>{r!==null&&(clearTimeout(r),r=null),i?.(),i=null},o=e=>new Promise(t=>{i=t,r=setTimeout(()=>{r=null;let e=i;i=null,e?.()},e)}),s=()=>{n?.abort(),a(),n=null};return{abort:s,fetch:async(r,i)=>{s(),n=new AbortController;let a=n;if(i>0&&await o(i),n!==a||a.signal.aborted)return{status:`aborted`};try{let i=await t({editor:e,query:r,signal:a.signal});return n!==a||a.signal.aborted?{status:`aborted`}:{status:`resolved`,items:i}}catch{return n!==a||a.signal.aborted?{status:`aborted`}:{status:`error`}}}}}function Ij({placement:e,offset:t,flip:n,floatingUi:r}){var i;let a=[_e({mainAxis:t.mainAxis??4,crossAxis:t.crossAxis??0})];return n&&a.push(he()),!(r==null||(i=r.middleware)==null)&&i.length&&a.push(...r.middleware),{placement:e,strategy:r?.strategy??`absolute`,middleware:a}}function Lj(e){if(e instanceof HTMLElement)return e;if(typeof e==`string`)try{let t=document.querySelector(e);if(t)return t}catch{return document.body}return document.body}function Rj({getReferenceRect:e,contextElement:t,config:n,container:r,dismissOnOutsideClick:i,dismiss:a}){return(o,s={})=>{let c={getBoundingClientRect:()=>e()??new DOMRect,contextElement:t},l=!1,u=!o.isConnected;u&&Lj(r).appendChild(o),s.onPosition||(o.style.visibility=`hidden`,o.style.width=`max-content`);let d=ge(c,o,()=>{pe(c,o,{placement:n.placement,strategy:n.strategy,middleware:n.middleware}).then(({x:e,y:t,placement:n,strategy:r})=>{if(s.onPosition){s.onPosition({x:e,y:t,placement:n,strategy:r});return}Object.assign(o.style,{position:r,left:`${e}px`,top:`${t}px`}),l||(l=!0,o.style.visibility=``)})},s.autoUpdate),f;return i&&(f=e=>{let n=e.target;!(n instanceof Node)||o.contains(n)||t.contains(n)||a()},document.addEventListener(`pointerdown`,f,!0)),()=>{d(),f&&document.removeEventListener(`pointerdown`,f,!0),u&&o.remove()}}}function zj({editor:e,pluginKey:t,items:n,renderer:r,minQueryLength:i,debounce:a,initialItems:o,placement:s,offset:c,container:l,flip:u,floatingUi:d,dismissOnOutsideClick:f,command:p,clientRectFor:m,dispatchExit:h}){let g,_=Fj({editor:e,items:n}),v=Ij({placement:s,offset:c,flip:u,floatingUi:d});function y(e,t){switch(e){case`started`:var n;r==null||(n=r.onStart)==null||n.call(r,t);break;case`updated`:var i;r==null||(i=r.onUpdate)==null||i.call(r,t);break;case`stopped`:var a;r==null||(a=r.onExit)==null||a.call(r,t)}}return{update:async(n,d)=>{let b=t.getState(d),x=t.getState(n.state);if(!b||!x)return;let S=null,C=b.query!==x.query,w=b.text!==x.text,T=b.range.from!==x.range.from||b.range.to!==x.range.to,E=C||w||T;if(!b.active&&x.active)S=`started`;else if(b.active&&!x.active)S=`stopped`;else if(x.active&&E)S=`updated`;else return;let D=S===`stopped`?b:x,O=n.dom.querySelector(`[data-decoration-id="${D.decorationId}"]`),k=m(n,O),A=i===0||(D.query?D.query.length>=i:!1),j=(S===`started`||S===`updated`)&&A;if(g={editor:e,range:D.range,query:D.query||``,text:D.text||``,items:o??[],command:t=>p({editor:e,range:D.range,props:t}),decorationNode:O,clientRect:k,loading:j,placement:s,offset:{mainAxis:c.mainAxis??4,crossAxis:c.crossAxis??0},container:l,flip:u,floatingUi:v,mount:Rj({getReferenceRect:k,contextElement:n.dom,config:v,container:l,dismissOnOutsideClick:f,dismiss:()=>h(e.view)})},S===`started`){var M;r==null||(M=r.onBeforeStart)==null||M.call(r,g)}if(S===`updated`){var N;r==null||(N=r.onBeforeUpdate)==null||N.call(r,g)}if(S===`started`&&y(S,g),S===`started`||S===`updated`)if(!j)_.abort(),g={...g,items:o??[],loading:!1};else{g={...g,items:o??[],loading:!0},S=`updated`,y(S,g);let e=await _.fetch(D.query||``,a);if(e.status===`aborted`)return;if(!t.getState(n.state)?.active){_.abort();return}g=e.status===`resolved`?{...g,items:e.items,loading:!1}:{...g,loading:!1}}if(S===`stopped`){_.abort(),y(S,g),g=void 0;return}S===`updated`&&y(S,g)},destroy:()=>{var e;_.abort(),g&&(r==null||(e=r.onExit)==null||e.call(r,g))}}}var Bj=new Fy(`suggestion`);function Vj({pluginKey:e=Bj,editor:t,char:n=`@`,allowSpaces:r=!1,allowToIncludeChar:i=!1,allowedPrefixes:a=[` `],startOfLine:o=!1,decorationTag:s=`span`,decorationClass:c=`suggestion`,decorationContent:l=``,decorationEmptyClass:u=`is-empty`,command:d=()=>null,items:f=()=>[],minQueryLength:p=0,debounce:m=0,initialItems:h,placement:g=`bottom-start`,offset:_={},container:v,flip:y=!0,floatingUi:b,dismissOnOutsideClick:x=!0,render:S=()=>({}),allow:C=()=>!0,findSuggestionMatch:w=Dj,shouldShow:T,shouldResetDismissed:E}){let D=S?.(),O=r&&!i,k=(n,r)=>Aj(t,n,r,e);function A(e){return jj({...e,editor:t,shouldResetDismissed:E,effectiveAllowSpaces:O})}let j=t=>Mj({view:t,pluginKeyRef:e});return new My({key:e,view:()=>zj({editor:t,pluginKey:e,items:f,renderer:D,minQueryLength:p,debounce:m,initialItems:h,placement:g,offset:_,container:v,flip:y,floatingUi:b,dismissOnOutsideClick:x,command:d,clientRectFor:k,dispatchExit:j}),state:Pj({editor:t,char:n,effectiveAllowSpaces:O,allowToIncludeChar:i,allowedPrefixes:a,startOfLine:o,findSuggestionMatch:w,allow:C,shouldShow:T,shouldKeepDismissed:A,pluginKey:e}),props:Nj({pluginKey:e,decorationTag:s,decorationClass:c,decorationContent:l,decorationEmptyClass:u,renderer:D,dispatchExit:j})})}function Hj(e,t=Bj){let n=e.state.tr.setMeta(t,{exit:!0});e.dispatch(n)}function Uj({editor:e,overrideSuggestionOptions:t,extensionName:n,char:r=`@`}){return{editor:e,char:r,pluginKey:new Fy,command:({editor:e,range:t,props:i})=>{var a,o;let s=e.view.state.selection.$to.nodeAfter;!(s==null||(a=s.text)==null)&&a.startsWith(` `)&&(t.to+=1),e.chain().focus().insertContentAt(t,[{type:n,attrs:{...i,mentionSuggestionChar:r}},{type:`text`,text:` `}]).run(),(o=e.view.dom.ownerDocument.defaultView)==null||(o=o.getSelection())==null||o.collapseToEnd()},allow:({state:e,range:t})=>{let r=e.doc.resolve(t.from),i=e.schema.nodes[n];return!!r.parent.type.contentMatch.matchType(i)},...t}}function Wj(e){return(e.options.suggestions.length?e.options.suggestions:[e.options.suggestion]).map(t=>Uj({editor:e.editor,overrideSuggestionOptions:t,extensionName:e.name,char:t.char}))}function Gj(e,t){let n=Wj(e);return n.find(e=>e.char===t)||(n.length?n[0]:null)}var Kj=Jk.create({name:`mention`,priority:101,addOptions(){return{HTMLAttributes:{},renderText({node:e,suggestion:t}){return`${t?.char??`@`}${e.attrs.label??e.attrs.id}`},deleteTriggerWithBackspace:!1,renderHTML({options:e,node:t,suggestion:n}){return[`span`,gD(this.HTMLAttributes,e.HTMLAttributes),`${n?.char??`@`}${t.attrs.label??t.attrs.id}`]},suggestions:[],suggestion:{}}},group:`inline`,inline:!0,selectable:!1,atom:!0,addAttributes(){return{id:{default:null,parseHTML:e=>e.getAttribute(`data-id`),renderHTML:e=>e.id?{"data-id":e.id}:{}},label:{default:null,parseHTML:e=>e.getAttribute(`data-label`),renderHTML:e=>e.label?{"data-label":e.label}:{}},mentionSuggestionChar:{default:`@`,parseHTML:e=>e.getAttribute(`data-mention-suggestion-char`),renderHTML:e=>({"data-mention-suggestion-char":e.mentionSuggestionChar})}}},parseHTML(){return[{tag:`span[data-type="${this.name}"]`}]},renderHTML({node:e,HTMLAttributes:t}){let n=Gj(this,e.attrs.mentionSuggestionChar);if(this.options.renderLabel!==void 0)return console.warn(`renderLabel is deprecated use renderText and renderHTML instead`),[`span`,gD({"data-type":this.name},this.options.HTMLAttributes,t),this.options.renderLabel({options:this.options,node:e,suggestion:n})];let r={...this.options};r.HTMLAttributes=gD({"data-type":this.name},this.options.HTMLAttributes,t);let i=this.options.renderHTML({options:r,node:e,suggestion:n});return typeof i==`string`?[`span`,gD({"data-type":this.name},this.options.HTMLAttributes,t),i]:i},...dk({nodeName:`mention`,name:`@`,selfClosing:!0,allowedAttributes:[`id`,`label`,{name:`mentionSuggestionChar`,skipIfDefault:`@`}],parseAttributes:e=>{let t={},n=/(?:^|\s)(\w+)=(?:"([^"]*)"|'([^']*)')/g,r=n.exec(e);for(;r!==null;){let[,i,a,o]=r;t[i===`char`?`mentionSuggestionChar`:i]=a??o,r=n.exec(e)}return t},serializeAttributes:e=>Object.entries(e).filter(([,e])=>e!=null).map(([e,t])=>`${e===`mentionSuggestionChar`?`char`:e}="${t}"`).join(` `)}),renderText({node:e}){let t={options:this.options,node:e,suggestion:Gj(this,e.attrs.mentionSuggestionChar)};return this.options.renderLabel===void 0?this.options.renderText(t):(console.warn(`renderLabel is deprecated use renderText and renderHTML instead`),this.options.renderLabel(t))},addKeyboardShortcuts(){return{Backspace:()=>this.editor.commands.command(({tr:e,state:t})=>{let n=!1,{selection:r}=t,{empty:i,anchor:a}=r;if(!i)return!1;let o=new e_,s=0;return t.doc.nodesBetween(a-1,a,(e,t)=>{if(e.type.name===this.name)return n=!0,o=e,s=t,!1}),n&&e.insertText(this.options.deleteTriggerWithBackspace?``:o.attrs.mentionSuggestionChar,s,s+o.nodeSize),n})}},addProseMirrorPlugins(){return Wj(this).map(Vj)}}),qj=`aaa1rp3bb0ott3vie4c1le2ogado5udhabi7c0ademy5centure6ountant0s9o1tor4d0s1ult4e0g1ro2tna4f0l1rica5g0akhan5ency5i0g1rbus3force5tel5kdn3l0ibaba4pay4lfinanz6state5y2sace3tom5m0azon4ericanexpress7family11x2fam3ica3sterdam8nalytics7droid5quan4z2o0l2partments8p0le4q0uarelle8r0ab1mco4chi3my2pa2t0e3s0da2ia2sociates9t0hleta5torney7u0ction5di0ble3o3spost5thor3o0s4w0s2x0a2z0ure5ba0by2idu3namex4d1k2r0celona5laycard4s5efoot5gains6seball5ketball8uhaus5yern5b0c1t1va3cg1n2d1e0ats2uty4er2rlin4st0buy5t2f1g1h0arti5i0ble3d1ke2ng0o3o1z2j1lack0friday9ockbuster8g1omberg7ue3m0s1w2n0pparibas9o0ats3ehringer8fa2m1nd2o0k0ing5sch2tik2on4t1utique6x2r0adesco6idgestone9oadway5ker3ther5ussels7s1t1uild0ers6siness6y1zz3v1w1y1z0h3ca0b1fe2l0l1vinklein9m0era3p2non3petown5ital0one8r0avan4ds2e0er0s4s2sa1e1h1ino4t0ering5holic7ba1n1re3c1d1enter4o1rn3f0a1d2g1h0anel2nel4rity4se2t2eap3intai5ristmas6ome4urch5i0priani6rcle4sco3tadel4i0c2y3k1l0aims4eaning6ick2nic1que6othing5ud3ub0med6m1n1o0ach3des3ffee4llege4ogne5m0mbank4unity6pany2re3uter5sec4ndos3struction8ulting7tact3ractors9oking4l1p2rsica5untry4pon0s4rses6pa2r0edit0card4union9icket5own3s1uise0s6u0isinella9v1w1x1y0mru3ou3z2dad1nce3ta1e1ing3sun4y2clk3ds2e0al0er2s3gree4livery5l1oitte5ta3mocrat6ntal2ist5si0gn4v2hl2iamonds6et2gital5rect0ory7scount3ver5h2y2j1k1m1np2o0cs1tor4g1mains5t1wnload7rive4tv2ubai3pont4rban5vag2r2z2earth3t2c0o2deka3u0cation8e1g1mail3erck5nergy4gineer0ing9terprises10pson4quipment8r0icsson6ni3s0q1tate5t1u0rovision8s2vents5xchange6pert3osed4ress5traspace10fage2il1rwinds6th3mily4n0s2rm0ers5shion4t3edex3edback6rrari3ero6i0delity5o2lm2nal1nce1ial7re0stone6mdale6sh0ing5t0ness6j1k1lickr3ghts4r2orist4wers5y2m1o0o0d1tball6rd1ex2sale4um3undation8x2r0ee1senius7l1ogans4ntier7tr2ujitsu5n0d2rniture7tbol5yi3ga0l0lery3o1up4me0s3p1rden4y2b0iz3d0n2e0a1nt0ing5orge5f1g0ee3h1i0ft0s3ves2ing5l0ass3e1obal2o4m0ail3bh2o1x2n1odaddy5ld0point6f2odyear5g0le4p1t1v2p1q1r0ainger5phics5tis4een3ipe3ocery4up4s1t1u0cci3ge2ide2tars5ru3w1y2hair2mburg5ngout5us3bo2dfc0bank7ealth0care8lp1sinki6re1mes5iphop4samitsu7tachi5v2k0t2m1n1ockey4ldings5iday5medepot5goods5s0ense7nda3rse3spital5t0ing5t0els3mail5use3w2r1sbc3t1u0ghes5yatt3undai7ibm2cbc2e1u2d1e0ee3fm2kano4l1m0amat4db2mo0bilien9n0c1dustries8finiti5o2g1k1stitute6urance4e4t0ernational10uit4vestments10o1piranga7q1r0ish4s0maili5t0anbul7t0au2v3jaguar4va3cb2e0ep2tzt3welry6io2ll2m0p2nj2o0bs1urg4t1y2p0morgan6rs3uegos4niper7kaufen5ddi3e0rryhotels6properties14fh2g1h1i0a1ds2m1ndle4tchen5wi3m1n1oeln3matsu5sher5p0mg2n2r0d1ed3uokgroup8w1y0oto4z2la0caixa5mborghini8er3nd0rover6xess5salle5t0ino3robe5w0yer5b1c1ds2ease3clerc5frak4gal2o2xus4gbt3i0dl2fe0insurance9style7ghting6ke2lly3mited4o2ncoln4k2ve1ing5k1lc1p2oan0s3cker3us3l1ndon4tte1o3ve3pl0financial11r1s1t0d0a3u0ndbeck6xe1ury5v1y2ma0drid4if1son4keup4n0agement7go3p1rket0ing3s4riott5shalls7ttel5ba2c0kinsey7d1e0d0ia3et2lbourne7me1orial6n0u2rck0msd7g1h1iami3crosoft7l1ni1t2t0subishi9k1l0b1s2m0a2n1o0bi0le4da2e1i1m1nash3ey2ster5rmon3tgage6scow4to0rcycles9v0ie4p1q1r1s0d2t0n1r2u0seum3ic4v1w1x1y1z2na0b1goya4me2vy3ba2c1e0c1t0bank4flix4work5ustar5w0s2xt0direct7us4f0l2g0o2hk2i0co2ke1on3nja3ssan1y5l1o0kia3rton4w0ruz3tv4p1r0a1w2tt2u1yc2z2obi1server7ffice5kinawa6layan0group9lo3m0ega4ne1g1l0ine5oo2pen3racle3nge4g0anic5igins6saka4tsuka4t2vh3pa0ge2nasonic7ris2s1tners4s1y3y2ccw3e0t2f0izer5g1h0armacy6d1ilips5one2to0graphy6s4ysio5ics1tet2ures6d1n0g1k2oneer5zza4k1l0ace2y0station9umbing5s3m1n0c2ohl2ker3litie5rn2st3r0axi3ess3ime3o0d0uctions8f1gressive8mo2perties3y5tection8u0dential9s1t1ub2w0c2y2qa1pon3uebec3st5racing4dio4e0ad1lestate6tor2y4cipes5d0umbrella9hab3ise0n3t2liance6n0t0als5pair3ort3ublican8st0aurant8view0s5xroth6ich0ardli6oh3l1o1p2o0cks3deo3gers4om3s0vp3u0gby3hr2n2w0e2yukyu6sa0arland6fe0ty4kura4le1on3msclub4ung5ndvik0coromant12ofi4p1rl2s1ve2xo3b0i1s2c0b1haeffler7midt4olarships8ol3ule3warz5ience5ot3d1e0arch3t2cure1ity6ek2lect4ner3rvices6ven3w1x0y3fr2g1h0angrila6rp3ell3ia1ksha5oes2p0ping5uji3w3i0lk2na1gles5te3j1k0i0n2y0pe4l0ing4m0art3ile4n0cf3o0ccer3ial4ftbank4ware6hu2lar2utions7ng1y2y2pa0ce3ort2t3r0l2s1t0ada2ples4r1tebank4farm7c0group6ockholm6rage3e3ream4udio2y3yle4u0cks3pplies3y2ort5rf1gery5zuki5v1watch4iss4x1y0dney4stems6z2tab1ipei4lk2obao4rget4tamotors6r2too4x0i3c0i2d0k2eam2ch0nology8l1masek5nnis4va3f1g1h0d1eater2re6iaa2ckets5enda4ps2res2ol4j0maxx4x2k0maxx5l1m0all4n1o0day3kyo3ols3p1ray3shiba5tal3urs3wn2yota3s3r0ade1ing4ining5vel0ers0insurance16ust3v2t1ube2i1nes3shu4v0s2w1z2ua1bank3s2g1k1nicom3versity8o2ol2ps2s1y1z2va0cations7na1guard7c1e0gas3ntures6risign5mögensberater2ung14sicherung10t2g1i0ajes4deo3g1king4llas4n1p1rgin4sa1ion4va1o3laanderen9n1odka3lvo3te1ing3o2yage5u2wales2mart4ter4ng0gou5tch0es6eather0channel12bcam3er2site5d0ding5ibo2r3f1hoswho6ien2ki2lliamhill9n0dows4e1ners6me2oodside6rk0s2ld3w2s1tc1f3xbox3erox4ihuan4n2xx2yz3yachts4hoo3maxun5ndex5e1odobashi7ga2kohama6u0tube6t1un3za0ppos4ra3ero3ip2m1one3uerich6w2`,Jj=`ελ1υ2бг1ел3дети4ею2католик6ом3мкд2он1сква6онлайн5рг3рус2ф2сайт3рб3укр3қаз3հայ3ישראל5קום3ابوظبي5رامكو5لاردن4بحرين5جزائر5سعودية6عليان5مغرب5مارات5یران5بارت2زار4يتك3ھارت5تونس4سودان3رية5شبكة4عراق2ب2مان4فلسطين6قطر3كاثوليك6وم3مصر2ليسيا5وريتانيا7قع4همراه5پاکستان7ڀارت4कॉम3नेट3भारत0म्3ोत5संगठन5বাংলা5ভারত2ৰত4ਭਾਰਤ4ભારત4ଭାରତ4இந்தியா6லங்கை6சிங்கப்பூர்11భారత్5ಭಾರತ4ഭാരതം5ලංකා4คอม3ไทย3ລາວ3გე2みんな3アマゾン4クラウド4グーグル4コム2ストア3セール3ファッション6ポイント4世界2中信1国1國1文网3亚马逊3企业2佛山2信息2健康2八卦2公司1益2台湾1灣2商城1店1标2嘉里0大酒店5在线2大拿2天主教3娱乐2家電2广东2微博2慈善2我爱你3手机2招聘2政务1府2新加坡2闻2时尚2書籍2机构2淡马锡3游戏2澳門2点看2移动2组织机构4网址1店1站1络2联通2谷歌2购物2通販2集团2電訊盈科4飞利浦3食品2餐厅2香格里拉3港2닷넷1컴2삼성2한국2`,Yj=`numeric`,Xj=`ascii`,Zj=`alpha`,Qj=`asciinumeric`,$j=`alphanumeric`,eM=`domain`,tM=`emoji`,nM=`scheme`,rM=`slashscheme`,iM=`whitespace`;function aM(e,t){return e in t||(t[e]=[]),t[e]}function oM(e,t,n){t[Yj]&&(t[Qj]=!0,t[$j]=!0),t[Xj]&&(t[Qj]=!0,t[Zj]=!0),t[Qj]&&(t[$j]=!0),t[Zj]&&(t[$j]=!0),t[$j]&&(t[eM]=!0),t[tM]&&(t[eM]=!0);for(let r in t){let t=aM(r,n);t.indexOf(e)<0&&t.push(e)}}function sM(e,t){let n={};for(let r in t)t[r].indexOf(e)>=0&&(n[r]=!0);return n}function cM(e=null){this.j={},this.jr=[],this.jd=null,this.t=e}cM.groups={},cM.prototype={accepts(){return!!this.t},go(e){let t=this,n=t.j[e];if(n)return n;for(let n=0;n<t.jr.length;n++){let r=t.jr[n][0],i=t.jr[n][1];if(i&&r.test(e))return i}return t.jd},has(e,t=!1){return t?e in this.j:!!this.go(e)},ta(e,t,n,r){for(let i=0;i<e.length;i++)this.tt(e[i],t,n,r)},tr(e,t,n,r){r||=cM.groups;let i;return t&&t.j?i=t:(i=new cM(t),n&&r&&oM(t,n,r)),this.jr.push([e,i]),i},ts(e,t,n,r){let i=this,a=e.length;if(!a)return i;for(let t=0;t<a-1;t++)i=i.tt(e[t]);return i.tt(e[a-1],t,n,r)},tt(e,t,n,r){r||=cM.groups;let i=this;if(t&&t.j)return i.j[e]=t,t;let a=t,o,s=i.go(e);return s?(o=new cM,Object.assign(o.j,s.j),o.jr.push.apply(o.jr,s.jr),o.jd=s.jd,o.t=s.t):o=new cM,a&&(r&&(o.t&&typeof o.t==`string`?oM(a,Object.assign(sM(o.t,r),n),r):n&&oM(a,n,r)),o.t=a),i.j[e]=o,o}};var lM=(e,t,n,r,i)=>e.ta(t,n,r,i),uM=(e,t,n,r,i)=>e.tr(t,n,r,i),dM=(e,t,n,r,i)=>e.ts(t,n,r,i),$=(e,t,n,r,i)=>e.tt(t,n,r,i),fM=`WORD`,pM=`UWORD`,mM=`ASCIINUMERICAL`,hM=`ALPHANUMERICAL`,gM=`LOCALHOST`,_M=`TLD`,vM=`UTLD`,yM=`SCHEME`,bM=`SLASH_SCHEME`,xM=`NUM`,SM=`WS`,CM=`NL`,wM=`OPENBRACE`,TM=`CLOSEBRACE`,EM=`OPENBRACKET`,DM=`CLOSEBRACKET`,OM=`OPENPAREN`,kM=`CLOSEPAREN`,AM=`OPENANGLEBRACKET`,jM=`CLOSEANGLEBRACKET`,MM=`FULLWIDTHLEFTPAREN`,NM=`FULLWIDTHRIGHTPAREN`,PM=`LEFTCORNERBRACKET`,FM=`RIGHTCORNERBRACKET`,IM=`LEFTWHITECORNERBRACKET`,LM=`RIGHTWHITECORNERBRACKET`,RM=`FULLWIDTHLESSTHAN`,zM=`FULLWIDTHGREATERTHAN`,BM=`AMPERSAND`,VM=`APOSTROPHE`,HM=`ASTERISK`,UM=`AT`,WM=`BACKSLASH`,GM=`BACKTICK`,KM=`CARET`,qM=`COLON`,JM=`COMMA`,YM=`DOLLAR`,XM=`DOT`,ZM=`EQUALS`,QM=`EXCLAMATION`,$M=`HYPHEN`,eN=`PERCENT`,tN=`PIPE`,nN=`PLUS`,rN=`POUND`,iN=`QUERY`,aN=`QUOTE`,oN=`FULLWIDTHMIDDLEDOT`,sN=`SEMI`,cN=`SLASH`,lN=`TILDE`,uN=`UNDERSCORE`,dN=`EMOJI`,fN=`SYM`,pN=Object.freeze({__proto__:null,ALPHANUMERICAL:hM,AMPERSAND:BM,APOSTROPHE:VM,ASCIINUMERICAL:mM,ASTERISK:HM,AT:UM,BACKSLASH:WM,BACKTICK:GM,CARET:KM,CLOSEANGLEBRACKET:jM,CLOSEBRACE:TM,CLOSEBRACKET:DM,CLOSEPAREN:kM,COLON:qM,COMMA:JM,DOLLAR:YM,DOT:XM,EMOJI:dN,EQUALS:ZM,EXCLAMATION:QM,FULLWIDTHGREATERTHAN:zM,FULLWIDTHLEFTPAREN:MM,FULLWIDTHLESSTHAN:RM,FULLWIDTHMIDDLEDOT:oN,FULLWIDTHRIGHTPAREN:NM,HYPHEN:$M,LEFTCORNERBRACKET:PM,LEFTWHITECORNERBRACKET:IM,LOCALHOST:gM,NL:CM,NUM:xM,OPENANGLEBRACKET:AM,OPENBRACE:wM,OPENBRACKET:EM,OPENPAREN:OM,PERCENT:eN,PIPE:tN,PLUS:nN,POUND:rN,QUERY:iN,QUOTE:aN,RIGHTCORNERBRACKET:FM,RIGHTWHITECORNERBRACKET:LM,SCHEME:yM,SEMI:sN,SLASH:cN,SLASH_SCHEME:bM,SYM:fN,TILDE:lN,TLD:_M,UNDERSCORE:uN,UTLD:vM,UWORD:pM,WORD:fM,WS:SM}),mN=/[a-z]/,hN=/\p{L}/u,gN=/\p{Emoji}/u,_N=/\d/,vN=/\s/,yN=`\r`,bN=`
|
|
100
|
+
`,xN=`️`,SN=``,CN=``,wN=null,TN=null;function EN(e=[]){let t={};cM.groups=t;let n=new cM;wN??=AN(qj),TN??=AN(Jj),$(n,`'`,VM),$(n,`{`,wM),$(n,`}`,TM),$(n,`[`,EM),$(n,`]`,DM),$(n,`(`,OM),$(n,`)`,kM),$(n,`<`,AM),$(n,`>`,jM),$(n,`(`,MM),$(n,`)`,NM),$(n,`「`,PM),$(n,`」`,FM),$(n,`『`,IM),$(n,`』`,LM),$(n,`<`,RM),$(n,`>`,zM),$(n,`&`,BM),$(n,`*`,HM),$(n,`@`,UM),$(n,"`",GM),$(n,`^`,KM),$(n,`:`,qM),$(n,`,`,JM),$(n,`$`,YM),$(n,`.`,XM),$(n,`=`,ZM),$(n,`!`,QM),$(n,`-`,$M),$(n,`%`,eN),$(n,`|`,tN),$(n,`+`,nN),$(n,`#`,rN),$(n,`?`,iN),$(n,`"`,aN),$(n,`/`,cN),$(n,`;`,sN),$(n,`~`,lN),$(n,`_`,uN),$(n,`\\`,WM),$(n,`・`,oN);let r=uM(n,_N,xM,{[Yj]:!0});uM(r,_N,r);let i=uM(r,mN,mM,{[Qj]:!0}),a=uM(r,hN,hM,{[$j]:!0}),o=uM(n,mN,fM,{[Xj]:!0});uM(o,_N,i),uM(o,mN,o),uM(i,_N,i),uM(i,mN,i);let s=uM(n,hN,pM,{[Zj]:!0});uM(s,mN),uM(s,_N,a),uM(s,hN,s),uM(a,_N,a),uM(a,mN),uM(a,hN,a);let c=$(n,bN,CM,{[iM]:!0}),l=$(n,yN,SM,{[iM]:!0}),u=uM(n,vN,SM,{[iM]:!0});$(n,CN,u),$(l,bN,c),$(l,CN,u),uM(l,vN,u),$(u,yN),$(u,bN),uM(u,vN,u),$(u,CN,u);let d=uM(n,gN,dN,{[tM]:!0});$(d,`#`),uM(d,gN,d),$(d,xN,d);let f=$(d,SN);$(f,`#`),uM(f,gN,d);let p=[[mN,o],[_N,i]],m=[[mN,null],[hN,s],[_N,a]];for(let e=0;e<wN.length;e++)kN(n,wN[e],_M,fM,p);for(let e=0;e<TN.length;e++)kN(n,TN[e],vM,pM,m);oM(_M,{tld:!0,ascii:!0},t),oM(vM,{utld:!0,alpha:!0},t),kN(n,`file`,yM,fM,p),kN(n,`mailto`,yM,fM,p),kN(n,`http`,bM,fM,p),kN(n,`https`,bM,fM,p),kN(n,`ftp`,bM,fM,p),kN(n,`ftps`,bM,fM,p),oM(yM,{scheme:!0,ascii:!0},t),oM(bM,{slashscheme:!0,ascii:!0},t),e=e.sort((e,t)=>e[0]>t[0]?1:-1);for(let t=0;t<e.length;t++){let r=e[t][0],i=e[t][1]?{[nM]:!0}:{[rM]:!0};r.indexOf(`-`)>=0?i[eM]=!0:mN.test(r)?_N.test(r)?i[Qj]=!0:i[Xj]=!0:i[Yj]=!0,dM(n,r,r,i)}return dM(n,`localhost`,gM,{ascii:!0}),n.jd=new cM(fN),{start:n,tokens:Object.assign({groups:t},pN)}}function DN(e,t){let n=ON(t.replace(/[A-Z]/g,e=>e.toLowerCase())),r=n.length,i=[],a=0,o=0;for(;o<r;){let s=e,c=null,l=0,u=null,d=-1,f=-1;for(;o<r&&(c=s.go(n[o]));)s=c,s.accepts()?(d=0,f=0,u=s):d>=0&&(d+=n[o].length,f++),l+=n[o].length,a+=n[o].length,o++;a-=d,o-=f,l-=d,i.push({t:u.t,v:t.slice(a-l,a),s:a-l,e:a})}return i}function ON(e){let t=[],n=e.length,r=0;for(;r<n;){let i=e.charCodeAt(r),a,o=i<55296||i>56319||r+1===n||(a=e.charCodeAt(r+1))<56320||a>57343?e[r]:e.slice(r,r+2);t.push(o),r+=o.length}return t}function kN(e,t,n,r,i){let a,o=t.length;for(let n=0;n<o-1;n++){let o=t[n];e.j[o]?a=e.j[o]:(a=new cM(r),a.jr=i.slice(),e.j[o]=a),e=a}return a=new cM(n),a.jr=i.slice(),e.j[t[o-1]]=a,a}function AN(e){let t=[],n=[],r=0;for(;r<e.length;){let i=0;for(;`0123456789`.indexOf(e[r+i])>=0;)i++;if(i>0){t.push(n.join(``));for(let t=parseInt(e.substring(r,r+i),10);t>0;t--)n.pop();r+=i}else n.push(e[r]),r++}return t}var jN={defaultProtocol:`http`,events:null,format:NN,formatHref:NN,nl2br:!1,tagName:`a`,target:null,rel:null,validate:!0,truncate:1/0,className:null,attributes:null,ignoreTags:[],render:null};function MN(e,t=null){let n=Object.assign({},jN);e&&(n=Object.assign(n,e instanceof MN?e.o:e));let r=n.ignoreTags,i=[];for(let e=0;e<r.length;e++)i.push(r[e].toUpperCase());this.o=n,t&&(this.defaultRender=t),this.ignoreTags=i}MN.prototype={o:jN,ignoreTags:[],defaultRender(e){return e},check(e){return this.get(`validate`,e.toString(),e)},get(e,t,n){let r=t!=null,i=this.o[e];return i&&(typeof i==`object`?(i=n.t in i?i[n.t]:jN[e],typeof i==`function`&&r&&(i=i(t,n))):typeof i==`function`&&r&&(i=i(t,n.t,n)),i)},getObj(e,t,n){let r=this.o[e];return typeof r==`function`&&t!=null&&(r=r(t,n.t,n)),r},render(e){let t=e.render(this);return(this.get(`render`,null,e)||this.defaultRender)(t,e.t,e)}};function NN(e){return e}function PN(e,t){this.t=`token`,this.v=e,this.tk=t}PN.prototype={isLink:!1,toString(){return this.v},toHref(e){return this.toString()},toFormattedString(e){let t=this.toString(),n=e.get(`truncate`,t,this),r=e.get(`format`,t,this);return n&&r.length>n?r.substring(0,n)+`…`:r},toFormattedHref(e){return e.get(`formatHref`,this.toHref(e.get(`defaultProtocol`)),this)},startIndex(){return this.tk[0].s},endIndex(){return this.tk[this.tk.length-1].e},toObject(e=jN.defaultProtocol){return{type:this.t,value:this.toString(),isLink:this.isLink,href:this.toHref(e),start:this.startIndex(),end:this.endIndex()}},toFormattedObject(e){return{type:this.t,value:this.toFormattedString(e),isLink:this.isLink,href:this.toFormattedHref(e),start:this.startIndex(),end:this.endIndex()}},validate(e){return e.get(`validate`,this.toString(),this)},render(e){let t=this,n=this.toHref(e.get(`defaultProtocol`)),r=e.get(`formatHref`,n,this),i=e.get(`tagName`,n,t),a=this.toFormattedString(e),o={},s=e.get(`className`,n,t),c=e.get(`target`,n,t),l=e.get(`rel`,n,t),u=e.getObj(`attributes`,n,t),d=e.getObj(`events`,n,t);return o.href=r,s&&(o.class=s),c&&(o.target=c),l&&(o.rel=l),u&&Object.assign(o,u),{tagName:i,attributes:o,content:a,eventListeners:d}}};function FN(e,t){class n extends PN{constructor(t,n){super(t,n),this.t=e}}for(let e in t)n.prototype[e]=t[e];return n.t=e,n}var IN=FN(`email`,{isLink:!0,toHref(){return`mailto:`+this.toString()}}),LN=FN(`text`),RN=FN(`nl`),zN=FN(`url`,{isLink:!0,toHref(e=jN.defaultProtocol){return this.hasProtocol()?this.v:`${e}://${this.v}`},hasProtocol(){let e=this.tk;return e.length>=2&&e[0].t!==gM&&e[1].t===qM}}),BN=e=>new cM(e);function VN({groups:e}){let t=e.domain.concat([BM,HM,UM,WM,GM,KM,YM,ZM,$M,xM,eN,tN,nN,rN,cN,fN,lN,uN]),n=[VM,qM,JM,XM,QM,eN,iN,aN,sN,AM,jM,wM,TM,DM,EM,OM,kM,MM,NM,PM,FM,IM,LM,RM,zM],r=[BM,VM,HM,WM,GM,KM,YM,ZM,$M,wM,TM,eN,tN,nN,rN,iN,cN,fN,lN,uN],i=BN(),a=$(i,lN);lM(a,r,a),lM(a,e.domain,a);let o=BN(),s=BN(),c=BN();lM(i,e.domain,o),lM(i,e.scheme,s),lM(i,e.slashscheme,c),lM(o,r,a),lM(o,e.domain,o);let l=$(o,UM);$(a,UM,l),$(s,UM,l),$(c,UM,l);let u=$(a,XM);lM(u,r,a),lM(u,e.domain,a);let d=BN();lM(l,e.domain,d),lM(d,e.domain,d);let f=$(d,XM);lM(f,e.domain,d);let p=BN(IN);lM(f,e.tld,p),lM(f,e.utld,p),$(l,gM,p);let m=$(d,$M);$(m,$M,m),lM(m,e.domain,d),lM(p,e.domain,d),$(p,XM,f),$(p,$M,m);let h=$(o,$M),g=$(o,XM);$(h,$M,h),lM(h,e.domain,o),lM(g,r,a),lM(g,e.domain,o);let _=BN(zN);lM(g,e.tld,_),lM(g,e.utld,_),lM(_,e.domain,o),lM(_,r,a),$(_,XM,g),$(_,$M,h),$(_,UM,l);let v=$(_,qM),y=BN(zN);lM(v,e.numeric,y);let b=BN(zN),x=BN();lM(b,t,b),lM(b,n,x),lM(x,t,b),lM(x,n,x),$(_,cN,b),$(y,cN,b);let S=$(s,qM),C=$($($(c,qM),cN),cN);lM(s,e.domain,o),$(s,XM,g),$(s,$M,h),lM(c,e.domain,o),$(c,XM,g),$(c,$M,h),lM(S,e.domain,b),$(S,cN,b),$(S,iN,b),lM(C,e.domain,b),lM(C,t,b),$(C,cN,b);let w=[[wM,TM],[EM,DM],[OM,kM],[AM,jM],[MM,NM],[PM,FM],[IM,LM],[RM,zM]];for(let e=0;e<w.length;e++){let[r,i]=w[e],a=$(b,r);$(x,r,a);let o=BN(zN);lM(a,t,o);let s=BN();lM(a,n,s),$(a,i,b),lM(o,t,o),lM(o,n,s),lM(s,t,o),lM(s,n,s),$(o,i,b),$(s,i,b)}return $(i,gM,_),$(i,CM,RN),{start:i,tokens:pN}}function HN(e,t,n){let r=n.length,i=0,a=[],o=[];for(;i<r;){let s=e,c=null,l=null,u=0,d=null,f=-1;for(;i<r&&!(c=s.go(n[i].t));)o.push(n[i++]);for(;i<r&&(l=c||s.go(n[i].t));)c=null,s=l,s.accepts()?(f=0,d=s):f>=0&&f++,i++,u++;if(f<0)i-=u,i<r&&(o.push(n[i]),i++);else{o.length>0&&(a.push(UN(LN,t,o)),o=[]),i-=f,u-=f;let e=d.t,r=n.slice(i-u,i);a.push(UN(e,t,r))}}return o.length>0&&a.push(UN(LN,t,o)),a}function UN(e,t,n){let r=n[0].s,i=n[n.length-1].e;return new e(t.slice(r,i),n)}var WN=typeof console<`u`&&console&&console.warn||(()=>{}),GN=`until manual call of linkify.init(). Register all schemes and plugins before invoking linkify the first time.`,KN={scanner:null,parser:null,tokenQueue:[],pluginQueue:[],customSchemes:[],initialized:!1};function qN(){return cM.groups={},KN.scanner=null,KN.parser=null,KN.tokenQueue=[],KN.pluginQueue=[],KN.customSchemes=[],KN.initialized=!1,KN}function JN(e,t=!1){if(KN.initialized&&WN(`linkifyjs: already initialized - will not register custom scheme "${e}" ${GN}`),!/^[0-9a-z]+(-[0-9a-z]+)*$/.test(e))throw Error(`linkifyjs: incorrect scheme format.
|
|
101
|
+
1. Must only contain digits, lowercase ASCII letters or "-"
|
|
102
|
+
2. Cannot start or end with "-"
|
|
103
|
+
3. "-" cannot repeat`);KN.customSchemes.push([e,t])}function YN(){KN.scanner=EN(KN.customSchemes);for(let e=0;e<KN.tokenQueue.length;e++)KN.tokenQueue[e][1]({scanner:KN.scanner});KN.parser=VN(KN.scanner.tokens);for(let e=0;e<KN.pluginQueue.length;e++)KN.pluginQueue[e][1]({scanner:KN.scanner,parser:KN.parser});return KN.initialized=!0,KN}function XN(e){return KN.initialized||YN(),HN(KN.parser.start,e,DN(KN.scanner.start,e))}XN.scan=DN;function ZN(e,t=null,n=null){if(t&&typeof t==`object`){if(n)throw Error(`linkifyjs: Invalid link type ${t}; must be a string`);n=t,t=null}let r=new MN(n),i=XN(e),a=[];for(let e=0;e<i.length;e++){let n=i[e];n.isLink&&(!t||n.t===t)&&r.check(n)&&a.push(n.toFormattedObject(r))}return a}var QN=`[\0- \xA0 -\u2029 ]`,$N=new RegExp(QN),eP=RegExp(`${QN}$`),tP=RegExp(`${QN}+$`),nP=new RegExp(QN,`g`);function rP(e,t,n){let r=e.doc.resolve(t.to);if(!r.nodeBefore?.isText)return;let i=e.doc.textBetween(t.from,t.to,``,``).match(tP)?.[0];if(!i)return;let a=t.to-i.length,o=PD(a,t.to,e.doc).filter(e=>e.mark.type===n);if(!o.length)return;let{nodeAfter:s}=r;if(s&&o.some(e=>e.mark.isInSet(s.marks)))return;let c=e.storedMarks;e.removeMark(a,t.to,n),e.setStoredMarks(c),e.selection.empty&&e.selection.from===t.to&&e.removeStoredMark(n)}function iP(e){return e.length===1?e[0].isLink:e.length===3&&e[1].isLink?[`()`,`[]`].includes(e[0].value+e[2].value):!1}function aP(e){return new My({key:new Fy(`autolink`),appendTransaction:(t,n,r)=>{let i=t.some(e=>e.docChanged)&&!n.doc.eq(r.doc),a=t.some(e=>e.getMeta(`preventAutolink`));if(!i||a)return;let{tr:o}=r,s=rD(n.doc,[...t]);if(!t.some(IT)){let t=[];s.steps.forEach((e,n)=>{if(!(e instanceof gv)||!e.slice.size)return;let r=s.mapping.slice(n+1),i=r.map(e.from,1),a=r.map(e.from+e.slice.size,-1);i<a&&t.push({from:i,to:a})}),t.sort((e,t)=>t.to-e.to),t.forEach(t=>rP(o,t,e.type))}if(ND(s).forEach(({newRange:t})=>{let n=iD(r.doc,t,e=>e.isTextblock),i,a;if(n.length>1)i=n[0],a=r.doc.textBetween(i.pos,i.pos+i.node.nodeSize,void 0,` `);else if(n.length){let e=r.doc.textBetween(t.from,t.to,` `,` `);if(!eP.test(e))return;i=n[0],a=r.doc.textBetween(i.pos,t.to,void 0,` `)}if(i&&a){let t=a.split($N).filter(Boolean);if(t.length<=0)return!1;let n=t[t.length-1],s=i.pos+a.lastIndexOf(n);if(!n)return!1;let c=XN(n).map(t=>t.toObject(e.defaultProtocol));if(!iP(c))return!1;c.filter(e=>e.isLink).map(e=>({...e,from:s+e.start+1,to:s+e.end+1})).filter(e=>r.schema.marks.code?!r.doc.rangeHasMark(e.from,e.to,r.schema.marks.code):!0).filter(t=>e.validate(t.value)).filter(t=>e.shouldAutoLink(t.value)).forEach(t=>{PD(t.from,t.to,r.doc).some(t=>t.mark.type===e.type)||o.addMark(t.from,t.to,e.type.create({href:t.href}))})}}),o.steps.length)return o}})}function oP(e){return new My({key:new Fy(`handleClickLink`),props:{handleClick:(t,n,r)=>{if(r.button!==0||!t.editable)return!1;let i=null;if(r.target instanceof HTMLAnchorElement)i=r.target;else{let t=r.target;if(!t)return!1;let n=e.editor.view.dom;i=t.closest(`a`),i&&!n.contains(i)&&(i=null)}if(!i)return!1;let a=!1;if(e.enableClickSelection&&(a=e.editor.commands.extendMarkRange(e.type.name)),e.openOnClick){let n=AD(t.state,e.type.name),r=i.href??n.href,o=i.target??n.target;r&&(window.open(r,o),a=!0)}return a}}})}var sP=/\[([^[\]]+)\]\(((?:[^\s()]|\([^\s()]*\))+)(?:\s+(?:(["'])(.*?)\3|“(.*?)”|‘(.*?)’))?\)$/,cP=/\[([^[\]]+)\]\(((?:[^\s()]|\([^\s()]*\))+)(?:\s+(?:(["'])(.*?)\3|“(.*?)”|‘(.*?)’))?\)/g;function lP(e,t){let n=0;for(let r=t-1;r>=0&&e[r]===`\\`;--r)n+=1;return n%2==1}function uP(e,t){let n=0,r=0;for(;r<t;){if(e[r]!=="`"){r+=1;continue}if(n===0&&lP(e,r)){r+=1;continue}let i=0;for(;r<t&&e[r]==="`";)i+=1,r+=1;n===0?n=i:i===n&&(n=0)}return n>0}function dP(e,t,n){let[,r,i]=t;return(t.index?e[t.index-1]:void 0)===`!`||lP(e,t.index??0)||uP(e,t.index??0)?!1:!!r.trim()&&n(i)}function fP(e){let[t,n,r,,i,a,o]=e,s=i??a??o;return{index:e.index??0,text:t,replaceWith:n,data:{href:r,title:s||null,markdown:!0}}}function pP(e,t){return e.index<t.index+t.text.length&&t.index<e.index+e.text.length}function mP(e){return{href:e.data?.href,title:e.data?.title??null}}function hP(e){let t=qk({find:t=>{let n=sP.exec(t);return!n||!dP(t,n,e.isAllowedHref)?null:fP(n)},type:e.type,getAttributes:mP});return new mk({find:t.find,handler:e=>{let n=t.handler(e);return n!==null&&e.state.tr.steps.length&&e.state.tr.setMeta(`preventAutolink`,!0),n}})}function gP(e){let t=Yk({find:t=>{let n=[];for(let r of t.matchAll(cP))dP(t,r,e.isAllowedHref)&&n.push(fP(r));let r=(e.findPlainUrls?.call(e,t)??[]).filter(e=>!n.some(t=>pP(t,e)));return[...n,...r]},type:e.type,getAttributes:mP});return new Ck({find:t.find,handler:e=>{let n=t.handler(e);return n!==null&&e.state.tr.steps.length&&e.match.data?.markdown&&e.state.tr.setMeta(`preventAutolink`,!0),n}})}function _P(e){return new My({key:new Fy(`handlePasteLink`),props:{handlePaste:(t,n,r)=>{let{shouldAutoLink:i}=e,{state:a}=t,{selection:o}=a,{empty:s}=o;if(s)return!1;let c=``;r.content.forEach(e=>{c+=e.textContent});let l=ZN(c,{defaultProtocol:e.defaultProtocol}).find(e=>e.isLink&&e.value===c);return!c||!l||i!==void 0&&!i(l.value)?!1:e.editor.commands.setMark(e.type,{href:l.href})}}})}function vP(e,t){let n=[`http`,`https`,`ftp`,`ftps`,`mailto`,`tel`,`callto`,`sms`,`cid`,`xmpp`];return t&&t.forEach(e=>{let t=typeof e==`string`?e:e.scheme;t&&n.push(t)}),!e||e.replace(nP,``).match(RegExp(`^(?:(?:${n.map(e=>e.replace(/[-/\\^$*+?.()|[\]{}]/g,`\\$&`)).join(`|`)}):|[^a-z]|[a-z0-9+.\\-]+(?:[^a-z+.\\-:]|$))`,`i`))}var yP=Sk.create({name:`link`,priority:1e3,keepOnSplit:!1,exitable:!0,onCreate(){this.options.validate&&!this.options.shouldAutoLink&&(this.options.shouldAutoLink=this.options.validate,console.warn("The `validate` option is deprecated. Rename to the `shouldAutoLink` option instead.")),this.options.protocols.forEach(e=>{if(typeof e==`string`){JN(e);return}JN(e.scheme,e.optionalSlashes)})},onDestroy(){qN()},inclusive(){return this.options.autolink},addOptions(){return{openOnClick:!0,enableClickSelection:!1,linkOnPaste:!0,markdownLinks:!1,autolink:!0,protocols:[],defaultProtocol:`http`,HTMLAttributes:{target:`_blank`,rel:`noopener noreferrer nofollow`,class:null},isAllowedUri:(e,t)=>!!vP(e,t.protocols),validate:e=>!!e,shouldAutoLink:e=>{let t=/^[a-z][a-z0-9+.-]*:\/\//i.test(e),n=/^[a-z][a-z0-9+.-]*:/i.test(e);if(t||n&&!e.includes(`@`))return!0;let r=(e.includes(`@`)?e.split(`@`).pop():e).split(/[/?#:]/)[0];return!(/^\d{1,3}(\.\d{1,3}){3}$/.test(r)||!/\./.test(r))}}},addAttributes(){return{href:{default:null,parseHTML(e){return e.getAttribute(`href`)}},target:{default:this.options.HTMLAttributes.target??null},rel:{default:this.options.HTMLAttributes.rel??null},class:{default:this.options.HTMLAttributes.class??null},title:{default:null}}},parseHTML(){return[{tag:`a[href]`,getAttrs:e=>{let t=e.getAttribute(`href`);return!t||!this.options.isAllowedUri(t,{defaultValidate:e=>!!vP(e,this.options.protocols),protocols:this.options.protocols,defaultProtocol:this.options.defaultProtocol})?!1:null}}]},renderHTML({HTMLAttributes:e}){return this.options.isAllowedUri(e.href,{defaultValidate:e=>!!vP(e,this.options.protocols),protocols:this.options.protocols,defaultProtocol:this.options.defaultProtocol})?[`a`,gD(this.options.HTMLAttributes,e),0]:[`a`,gD(this.options.HTMLAttributes,{...e,href:``}),0]},markdownTokenName:`link`,parseMarkdown:(e,t)=>t.applyMark(`link`,t.parseInline(e.tokens||[]),{href:e.href,title:e.title||null}),renderMarkdown:(e,t)=>{let n=e.attrs?.href??``,r=e.attrs?.title??``,i=t.renderChildren(e);return r?`[${i}](${n} "${r}")`:`[${i}](${n})`},addCommands(){return{setLink:e=>({chain:t})=>{let{href:n}=e;return this.options.isAllowedUri(n,{defaultValidate:e=>!!vP(e,this.options.protocols),protocols:this.options.protocols,defaultProtocol:this.options.defaultProtocol})?t().setMark(this.name,e).setMeta(`preventAutolink`,!0).run():!1},toggleLink:e=>({chain:t})=>{let{href:n}=e||{};return n&&!this.options.isAllowedUri(n,{defaultValidate:e=>!!vP(e,this.options.protocols),protocols:this.options.protocols,defaultProtocol:this.options.defaultProtocol})?!1:t().toggleMark(this.name,e,{extendEmptyMarkRange:!0}).setMeta(`preventAutolink`,!0).run()},unsetLink:()=>({chain:e})=>e().unsetMark(this.name,{extendEmptyMarkRange:!0}).setMeta(`preventAutolink`,!0).run()}},addInputRules(){return this.options.markdownLinks?[hP({type:this.type,isAllowedHref:e=>this.options.isAllowedUri(e,{defaultValidate:e=>!!vP(e,this.options.protocols),protocols:this.options.protocols,defaultProtocol:this.options.defaultProtocol})})]:[]},addPasteRules(){let e=e=>{let t=[];if(e){let{protocols:n,defaultProtocol:r}=this.options;ZN(e).filter(e=>e.isLink&&this.options.isAllowedUri(e.value,{defaultValidate:e=>!!vP(e,n),protocols:n,defaultProtocol:r})).forEach(e=>{this.options.shouldAutoLink(e.value)&&t.push({text:e.value,data:{href:e.href},index:e.start})})}return t};return this.options.markdownLinks?[gP({type:this.type,isAllowedHref:e=>this.options.isAllowedUri(e,{defaultValidate:e=>!!vP(e,this.options.protocols),protocols:this.options.protocols,defaultProtocol:this.options.defaultProtocol}),findPlainUrls:e})]:[Yk({find:e,type:this.type,getAttributes:e=>({href:e.data?.href})})]},addProseMirrorPlugins(){let e=[],{protocols:t,defaultProtocol:n}=this.options;return this.options.autolink&&e.push(aP({type:this.type,defaultProtocol:this.options.defaultProtocol,validate:e=>this.options.isAllowedUri(e,{defaultValidate:e=>!!vP(e,t),protocols:t,defaultProtocol:n}),shouldAutoLink:this.options.shouldAutoLink})),e.push(oP({type:this.type,editor:this.editor,openOnClick:this.options.openOnClick===`whenNotEditable`?!0:this.options.openOnClick,enableClickSelection:this.options.enableClickSelection})),this.options.linkOnPaste&&e.push(_P({editor:this.editor,defaultProtocol:this.options.defaultProtocol,type:this.type,shouldAutoLink:this.options.shouldAutoLink})),e}}),bP=`placeholder`,xP=new Fy(`tiptap__placeholder`);function SP(e){let{editor:t,placeholder:n,dataAttribute:r,pos:i,node:a,isEmptyDoc:o,hasAnchor:s,classes:{emptyNode:c,emptyEditor:l}}=e,u=[c];return o&&u.push(l),ow.node(i,i+a.nodeSize,{class:u.join(` `),[r]:typeof n==`function`?n({editor:t,node:a,pos:i,hasAnchor:s}):n})}function CP(e,t){return typeof e==`function`?e(t):e}function wP({editor:e,options:t,dataAttribute:n,doc:r,selection:i,from:a,to:o}){let{anchor:s}=i,c=[],l=e.isEmpty;return r.nodesBetween(a,o,(r,i)=>{let a=s>=i&&s<=i+r.nodeSize,o=!r.isLeaf&&HD(r);return r.type.isTextblock&&(a||!t.showOnlyCurrent)&&o&&c.push(SP({editor:e,isEmptyDoc:l,dataAttribute:n,hasAnchor:a,placeholder:t.placeholder,classes:{emptyEditor:t.emptyEditorClass,emptyNode:CP(t.emptyNodeClass,{editor:e,node:r,pos:i,hasAnchor:a})},node:r,pos:i})),t.includeChildren}),c}function TP({editor:e,options:t,dataAttribute:n,doc:r,selection:i}){if(!(e.isEditable||!t.showOnlyWhenEditable))return null;let{anchor:a}=i,o=[],s=e.isEmpty;if(t.showOnlyCurrent&&!t.includeChildren){let i=r.resolve(a),c=i.depth>0?i.node(1):i.nodeAfter,l=i.depth>0?i.before(1):a;if(c&&c.type.isTextblock&&HD(c)){let r=a>=l&&a<=l+c.nodeSize;o.push(SP({editor:e,isEmptyDoc:s,dataAttribute:n,hasAnchor:r,placeholder:t.placeholder,classes:{emptyEditor:t.emptyEditorClass,emptyNode:CP(t.emptyNodeClass,{editor:e,node:c,pos:l,hasAnchor:r})},node:c,pos:l}))}}else o.push(...wP({editor:e,options:t,dataAttribute:n,doc:r,selection:i,from:0,to:r.content.size}));return lw.create(r,o)}function EP(e,t){let n=e.resolve(t);if(n.depth===0){let e=n.nodeAfter??n.nodeBefore;if(!e)return{from:t,to:t};let r=n.nodeAfter?t:t-e.nodeSize;return{from:r,to:r+e.nodeSize}}let r=n.before(1);return{from:r,to:r+n.node(1).nodeSize}}function DP(e,t){return{from:Math.max(0,t.from-1),to:Math.min(e.content.size,t.to-1)}}function OP(e,t,n){let r=[];return e.forEach((e,i)=>{let a=i,o=a+e.nodeSize,s=a+1,c=o+1;s<n&&c>t&&r.push({from:a,to:o})}),r}function kP(e){if(e.length===0)return[];let t=[...e].sort((e,t)=>e.from-t.from),n=[{...t[0]}];for(let e=1;e<t.length;e+=1){let r=n[n.length-1],i=t[e];i.from<=r.to?r.to=Math.max(r.to,i.to):n.push({...i})}return n}function AP(e,t){let n=OP(e,t.from,t.to);return n.push(DP(e,EP(e,t.from))),t.to>t.from?n.push(DP(e,EP(e,Math.min(t.to,e.content.size+1)-1))):t.from<e.content.size+1&&n.push(DP(e,EP(e,Math.min(t.from+1,e.content.size)))),n}function jP(e,t,n){let r=[];if(e.docChanged){let t=ND(e);for(let e of t)r.push(...AP(n.doc,e.newRange))}return e.selectionSet&&(r.push(DP(n.doc,EP(n.doc,e.mapping.map(t.selection.anchor)))),r.push(DP(n.doc,EP(n.doc,n.selection.anchor)))),kP(r)}function MP(e,t,n){let r=Math.max(0,Math.min(e,n.content.size));return{from:r,to:Math.max(r,Math.min(t,n.content.size))}}function NP({decorations:e,ranges:t,editor:n,options:r,dataAttribute:i,doc:a,selection:o}){let s=e;for(let e of t){let{from:t,to:c}=MP(e.from,e.to,a),l=s.find(t,c).filter(e=>e.from>=t&&e.to<=c);l.length&&(s=s.remove(l));let u=wP({editor:n,options:r,dataAttribute:i,doc:a,selection:o,from:t,to:c});u.length&&(s=s.add(a,u))}return s}function PP({editor:e,options:t,dataAttribute:n}){return{init(r,i){return TP({editor:e,options:t,dataAttribute:n,doc:i.doc,selection:i.selection})??lw.empty},apply(r,i,a,o){return!r.docChanged&&!r.selectionSet?i:NP({decorations:i.map(r.mapping,r.doc),ranges:jP(r,a,o),editor:e,options:t,dataAttribute:n,doc:o.doc,selection:o.selection})}}}function FP(e){return e.replace(/\s+/g,`-`).replace(/[^a-zA-Z0-9-]/g,``).replace(/^[0-9-]+/,``).replace(/^-+/,``).toLowerCase()}function IP({editor:e,options:t}){let n=t.dataAttribute?`data-${FP(t.dataAttribute)}`:`data-${bP}`,r=t.showOnlyCurrent&&!t.includeChildren;return new My({key:xP,...r?{}:{state:PP({editor:e,options:t,dataAttribute:n})},props:{decorations:r?({doc:r,selection:i})=>TP({editor:e,options:t,dataAttribute:n,doc:r,selection:i}):n=>t.showOnlyWhenEditable&&!e.isEditable?lw.empty:xP.getState(n)??lw.empty}})}var LP=Ak.create({name:`placeholder`,addOptions(){return{emptyEditorClass:`is-editor-empty`,emptyNodeClass:`is-empty`,dataAttribute:bP,placeholder:`Write something …`,showOnlyWhenEditable:!0,showOnlyCurrent:!0,includeChildren:!1}},addProseMirrorPlugins(){return[IP({editor:this.editor,options:this.options})]}}),RP=Ak.create({name:`undoRedo`,addOptions(){return{depth:100,newGroupDelay:500}},addCommands(){return{undo:()=>({state:e,dispatch:t})=>PT(e,t),redo:()=>({state:e,dispatch:t})=>FT(e,t)}},addProseMirrorPlugins(){return[MT(this.options)]},addKeyboardShortcuts(){return{"Mod-z":()=>this.editor.commands.undo(),"Shift-Mod-z":()=>this.editor.commands.redo(),"Mod-y":()=>this.editor.commands.redo(),"Mod-я":()=>this.editor.commands.undo(),"Shift-Mod-я":()=>this.editor.commands.redo()}}});function zP(e){if(!/^https?:\/\//i.test(e)||Array.from(e).some(e=>e.charCodeAt(0)<=32||e.charCodeAt(0)===127))return!1;try{let t=new URL(e);return(t.protocol===`http:`||t.protocol===`https:`)&&!!t.hostname}catch{return!1}}function BP(e){return{type:`doc`,content:e.replace(/\r\n?/g,`
|
|
104
|
+
`).split(`
|
|
105
|
+
`).map(e=>{let t=[],n=0;for(let r of ZN(e,`url`))zP(r.value)&&(r.start>n&&t.push({type:`text`,text:e.slice(n,r.start)}),t.push({type:`text`,text:r.value,marks:[{type:`link`,attrs:{href:r.value}}]}),n=r.end);return n<e.length&&t.push({type:`text`,text:e.slice(n)}),{type:`paragraph`,content:t}})}}function VP(e){return e.textBetween(0,`type`in e?e.content.size:e.size,`
|
|
106
|
+
`,e=>e.type.name===`mention`?`@${e.attrs.id}`:e.type.name===`hardBreak`?`
|
|
107
|
+
`:``)}function HP(e,t){return new Y(t.nodeFromJSON(BP(e)).content,1,1)}var UP=new Fy(`composer-files`);function WP(e){let t=[];return e.state.doc.descendants((e,n)=>{e.type.name===`mention`&&t.push([n,e.attrs.id])}),JSON.stringify(t)}function GP(e){let t=(0,K.useRef)(e);t.current=e;let n=e.value.replace(/\r\n?/g,`
|
|
108
|
+
`),r=(0,K.useRef)({text:n,references:`[]`}),i=(0,K.useRef)(null),[a]=(0,K.useState)(()=>({extensions:[xj,wj,Tj,Ej,RP,LP.configure({placeholder:()=>t.current.placeholder}),yP.configure({autolink:!0,openOnClick:!1,linkOnPaste:!1,isAllowedUri:(e,t)=>t.defaultValidate(e)&&zP(e),shouldAutoLink:zP,HTMLAttributes:{class:`text-primary underline decoration-primary/60 underline-offset-2`,tabindex:`-1`}}),Kj.configure({deleteTriggerWithBackspace:!0,renderText:({node:e})=>`@${e.attrs.id}`,HTMLAttributes:{class:`rounded bg-primary/15 px-1 text-primary [overflow-wrap:anywhere]`},suggestion:{pluginKey:UP,char:`@`,allowedPrefixes:[` `,`
|
|
109
|
+
`,`(`],allow:({state:e,range:n})=>t.current.mentionsEnabled&&!!e.doc.resolve(n.from).parent.type.contentMatch.matchType(e.schema.nodes.mention),items:()=>[],shouldResetDismissed:({transaction:e})=>e.docChanged,render:()=>{let e=e=>{t.current.onSuggestionChange({query:e.query,pick:t=>e.command({id:t,label:t}),dismiss:()=>{e.editor.isDestroyed||Hj(e.editor.view,UP)}})};return{onStart:e,onUpdate:e,onExit:()=>t.current.onSuggestionChange(null)}}}})],content:BP(e.value),editorProps:{attributes:{id:e.id,role:`textbox`,"aria-multiline":`true`,"data-composer-editor":``,class:`composer-editor min-h-11 max-h-40 w-full min-w-0 overflow-y-auto overflow-x-hidden rounded-md bg-transparent px-2 py-2 text-base outline-none whitespace-pre-wrap [overflow-wrap:anywhere] [&_p]:m-0`},clipboardTextSerializer:e=>VP(e.content),handleKeyDown:(e,n)=>n.defaultPrevented||n.isComposing||n.keyCode===229||e.composing?!1:n.key===`Enter`?(n.shiftKey?i.current?.commands.setHardBreak():t.current.onSubmit(),!0):!1,handlePaste:(e,n)=>{let r=n.clipboardData;if(!r)return!1;let i=Array.from(r.files);if(i.length)t.current.onAddFiles(i);else{let t=r.getData(`text/plain`);t&&e.dispatch(e.state.tr.replaceSelection(HP(t,e.state.schema)).scrollIntoView())}return n.preventDefault(),!0},handleDrop:(e,t)=>{if(e.dragging||t.dataTransfer?.files.length)return!1;let n=t.dataTransfer?.getData(`text/plain`);if(n){let r=e.posAtCoords({left:t.clientX,top:t.clientY})?.pos??e.state.selection.from,i=e.state.tr.replaceRange(r,r,HP(n,e.state.schema));i.setSelection(hy.near(i.doc.resolve(i.mapping.map(r)))),e.dispatch(i.scrollIntoView()),e.focus()}return t.preventDefault(),!0},handleDOMEvents:{keydown:(e,t)=>t.isComposing||t.keyCode===229||e.composing||e.dom.dataset.composing===`true`?!0:t.key===`Enter`&&t.shiftKey&&fE()&&/Chrome\//.test(navigator.userAgent)?(t.preventDefault(),i.current?.commands.setHardBreak(),!0):!1,compositionstart:e=>(e.dom.dataset.composing=`true`,!1),compositionend:e=>(requestAnimationFrame(()=>{delete e.dom.dataset.composing}),!1),drop:(e,t)=>t.dataTransfer?.files.length?(t.preventDefault(),!0):!1,click:(e,t)=>(t.target instanceof Element&&t.target.closest(`a`)&&t.preventDefault(),!1),auxclick:(e,t)=>(t.target instanceof Element&&t.target.closest(`a`)&&t.preventDefault(),!1)}},onUpdate:({editor:e})=>{let n=VP(e.state.doc),i=WP(e);n===r.current.text&&i===r.current.references||(r.current={text:n,references:i},t.current.onChange(n))}})),o=pj(a);return i.current=o,(0,K.useEffect)(()=>{o&&!o.isDestroyed&&Hj(o.view,UP)},[o,e.mentionScope]),(0,K.useLayoutEffect)(()=>{let t=e.focusSnapshot;if(!o||o.isDestroyed||!t)return;let n=t.current;if(n){if(n.text===VP(o.state.doc)){let e=e=>{let t=o.state.doc.content.size-1,n=e;return o.state.doc.forEach((e,r)=>{if(n<0)return;let i=VP(e).length;n<=i?(t=r+1+n,n=-1):n-=i+1}),t};o.commands.setTextSelection({from:e(n.from),to:e(n.to)})}else o.commands.setTextSelection(o.state.doc.content.size-1);o.view.focus(),t.current=null}return()=>{if(o.isDestroyed)return;let{doc:e,selection:n}=o.state;t.current=o.view.hasFocus()?{text:VP(e),from:VP(e.cut(0,n.from)).length,to:VP(e.cut(0,n.to)).length}:null}},[o,e.focusSnapshot]),(0,K.useImperativeHandle)(e.inputRef,()=>({focus:()=>{o&&!o.isDestroyed&&o.view.focus()}}),[o]),(0,K.useEffect)(()=>{!o||o.isDestroyed||(VP(o.state.doc)!==n&&o.commands.setContent(BP(n),{emitUpdate:!1}),r.current={text:n,references:WP(o)})},[o,n]),(0,K.useEffect)(()=>{if(!o||o.isDestroyed)return;let t=o.view.dom;t.setAttribute(`aria-label`,e.label),t.setAttribute(`aria-busy`,String(e.busy)),t.setAttribute(`title`,e.title),t.setAttribute(`data-placeholder`,e.placeholder),o.view.dispatch(o.state.tr),e.mentionsEnabled||Hj(o.view,UP)},[o,e.label,e.busy,e.title,e.placeholder,e.mentionsEnabled]),(0,q.jsx)(oj,{editor:o,className:`contents`})}function KP(e,t,n,r){let[i,a]=(0,K.useState)(0),o=(0,K.useRef)(e);o.current=e;let s=(0,K.useRef)(t);s.current=t;let c=(0,K.useRef)(n);c.current=n;let l=(0,K.useRef)(i);return l.current=i,(0,K.useEffect)(()=>{i>=e&&a(e>0?e-1:0)},[e,i]),(0,K.useEffect)(()=>{let e=e=>{if(e.isComposing||e.keyCode===229)return;let t=document.getElementById(r);if(!(!(e.target instanceof Node)||!t?.contains(e.target)||t.dataset.composing===`true`)){if(e.key===`Escape`){e.preventDefault(),e.stopPropagation(),c.current?.();return}o.current!==0&&(e.key===`ArrowDown`?(e.preventDefault(),e.stopPropagation(),a(e=>(e+1)%o.current)):e.key===`ArrowUp`?(e.preventDefault(),e.stopPropagation(),a(e=>(e-1+o.current)%o.current)):e.key===`Enter`&&!e.metaKey&&!e.ctrlKey&&!e.shiftKey||e.key===`Tab`&&!e.shiftKey?(e.preventDefault(),e.stopPropagation(),s.current(l.current)):e.key===`Escape`&&(e.preventDefault(),e.stopPropagation(),c.current?.()))}};return window.addEventListener(`keydown`,e,!0),()=>window.removeEventListener(`keydown`,e,!0)},[r]),i}function qP({skills:e,workflows:t,query:n,onPick:r,onPickWorkflow:i,onPickGoal:a,onPickCatalog:o,onDismiss:s,inputId:c,catalogState:l,onPickCatalogEntry:d,catalogDisabled:p=!1}){u();let m=n.trim().toLowerCase(),h=(e,t)=>!m||e.toLowerCase().includes(m)||t.toLowerCase().includes(m),g=o&&(!m||h(f(`catalog_workflows_b3caa7b0`),f(`choose_an_executable_workflow_from_the_bamboo_catalog_b7020d54`))||`workflow`.includes(m))?[{kind:`catalog`,id:`builtin-catalog`,name:f(`catalog_workflows_b3caa7b0`),description:f(`open_the_workflow_catalog_to_choose_a_workflow_and_argu_4359980e`)}]:[],_=[...a&&h(`goal`,f(`set_session_goal_98fa0b0f`))?[{kind:`goal`,id:`builtin-goal`,name:`goal`,description:f(`goal_goal_text_send_goal_alone_to_open_settings_b45f54c8`)}]:[],...e.filter(e=>h(e.name,e.description)).map(e=>({kind:`skill`,id:`skill-${e.id}`,name:e.name,description:e.description,skill:e})),...t.filter(e=>h(e.display_name||e.name,e.description)).map(e=>({kind:`workflow`,id:`workflow-${e.id}`,name:e.display_name||e.name,description:e.description,command:e}))].slice(0,g.length?7:8),v=(l?.catalog?.entries??[]).filter(e=>!m||h(e.name,e.description)||e.id.toLowerCase().includes(m)||e.source.includes(m)).map(e=>({kind:`typed`,id:`catalog:${e.source}:${e.id}:${e.revision}`,name:e.name,description:e.description,entry:e}));_.push(...v,...g);let y=e=>e.kind===`typed`?pn(e.entry)||(p?f(`workflow_selection_is_currently_unavailable_94a186a4`):null):null,b=_.filter(e=>!y(e)),x=e=>{y(e)||(e.kind===`typed`?d?.(e.entry):e.kind===`skill`?r(e.skill):e.kind===`workflow`?i(e.command):e.kind===`catalog`?o?.():a?.())},S=KP(b.length,e=>{let t=b[e];t&&x(t)},s,c),C=(0,K.useRef)(null);return(0,K.useEffect)(()=>{C.current?.scrollIntoView({block:`nearest`})},[S]),_.length===0&&!l?null:(0,q.jsxs)(`div`,{className:`mx-auto mb-2 w-full max-w-6xl overflow-hidden rounded-xl border bg-popover shadow-lg`,children:[(0,q.jsx)(`div`,{className:`border-b px-3 py-1.5 text-xs text-muted-foreground`,children:f(`commands_skills_workflows_1abfc720`)}),(0,q.jsxs)(`div`,{className:`max-h-64 overflow-y-auto p-1`,children:[_.map((e,t)=>(0,q.jsxs)(`div`,{children:[(t===0||_[t-1].kind!==e.kind)&&(0,q.jsx)(`div`,{className:`px-3 pb-1 pt-2 text-[10px] text-muted-foreground`,children:e.kind===`typed`?f(`catalog_workflow_this_message_4bad8776`):e.kind===`workflow`?f(`text_expansion_workflow_8362c042`):e.kind===`skill`?f(`skills_99aea2f9`):e.kind===`goal`?f(`command_6ee4a9a8`):f(`catalog_management_8dd26df6`)}),(0,q.jsxs)(`button`,{ref:b[S]?.id===e.id?C:void 0,disabled:!!y(e),onClick:()=>x(e),className:G(`flex w-full flex-col gap-0.5 rounded-lg px-3 py-2 text-left transition-colors hover:bg-accent`,b[S]?.id===e.id&&`bg-accent`,`disabled:opacity-50`),children:[(0,q.jsxs)(`span`,{className:`flex items-center gap-1.5 text-sm font-medium`,children:[`/`,e.name,(0,q.jsx)(`span`,{className:G(`rounded-full px-1.5 py-0 text-[10px] font-normal`,e.kind===`workflow`?`bg-primary/15 text-primary`:`bg-muted text-muted-foreground`),children:e.kind===`typed`?`${e.entry.source} · r${e.entry.revision}`:e.kind===`goal`?f(`command_6ee4a9a8`):e.kind===`catalog`?f(`catalog_selection_a07f95c4`):e.kind===`workflow`?f(`text_expansion_96adb387`):f(`skills_99aea2f9`)})]}),y(e)||e.description?(0,q.jsx)(`span`,{className:`line-clamp-1 text-xs text-muted-foreground`,children:y(e)||e.description}):null]})]},e.id)),!_.length&&!l?.loading&&!l?.error&&(0,q.jsx)(`p`,{className:`px-3 py-2 text-xs text-muted-foreground`,children:f(`no_matching_commands_or_workflows_bfef441f`)}),l?.loading&&(0,q.jsx)(`p`,{role:`status`,className:`px-3 py-2 text-xs text-muted-foreground`,children:f(`loading_workflow_catalog_59214f82`)}),l?.error&&(0,q.jsxs)(`p`,{role:`alert`,className:`px-3 py-2 text-xs text-destructive`,children:[f(`could_not_load_catalog_a2342d5f`),l.error]})]})]})}function JP({files:e,query:t,onPick:n,onDismiss:r,inputId:i}){u();let a=t.trim().toLowerCase(),o=e.filter(e=>!e.is_directory&&(!a||e.path.toLowerCase().includes(a))).slice(0,8),s=KP(o.length,e=>{let t=o[e];t&&n(t)},r,i),c=(0,K.useRef)(null);return(0,K.useEffect)(()=>{c.current?.scrollIntoView({block:`nearest`})},[s]),(0,K.useEffect)(()=>{let e=document.getElementById(i);if(!(!e||o.length===0))return e.setAttribute(`aria-controls`,`${i}-files`),e.setAttribute(`aria-expanded`,`true`),e.setAttribute(`aria-autocomplete`,`list`),e.setAttribute(`aria-activedescendant`,`${i}-file-${s}`),()=>{for(let t of[`aria-controls`,`aria-expanded`,`aria-autocomplete`,`aria-activedescendant`])e.removeAttribute(t)}},[i,s,o.length]),o.length===0?null:(0,q.jsxs)(`div`,{className:`mx-auto mb-2 w-full max-w-6xl overflow-hidden rounded-xl border bg-popover shadow-lg`,children:[(0,q.jsx)(`div`,{className:`border-b px-3 py-1.5 text-xs text-muted-foreground`,children:f(`workspace_files_c0c1e416`)}),(0,q.jsx)(`div`,{role:`listbox`,id:`${i}-files`,"aria-label":f(`workspace_files_c0c1e416`),className:`max-h-64 overflow-y-auto p-1`,children:o.map((e,t)=>(0,q.jsx)(`button`,{role:`option`,id:`${i}-file-${t}`,"aria-selected":t===s,tabIndex:-1,onMouseDown:e=>e.preventDefault(),ref:t===s?c:void 0,onClick:()=>n(e),className:G(`block w-full truncate rounded-lg px-3 py-1.5 text-left text-sm transition-colors hover:bg-accent`,t===s&&`bg-accent`),children:e.path},e.path))})]})}function YP(){u();let e=H(Yr(e=>e.systemPrompts)),t=H(e=>e.lastSelectedPromptId),n=H(e=>e.setLastSelectedPromptId);if(e.length===0)return null;let r=e.find(e=>e.id===t)??e.find(e=>e.isDefault)??e[0];return(0,q.jsxs)(ke,{children:[(0,q.jsx)(V,{asChild:!0,children:(0,q.jsxs)(`button`,{className:Fe,title:f(`system_prompt_b9068145`,{v0:r.name}),children:[(0,q.jsx)(ar,{className:`size-4 shrink-0`}),(0,q.jsx)(`span`,{className:`truncate`,children:r.name}),(0,q.jsx)(me,{className:`size-3 shrink-0 opacity-60`})]})}),(0,q.jsx)(z,{align:`start`,children:e.map(e=>(0,q.jsxs)(B,{onClick:()=>n(e.id),children:[r?.id===e.id?(0,q.jsx)(de,{className:`size-3.5`}):(0,q.jsx)(`span`,{className:`size-3.5`}),(0,q.jsx)(`span`,{className:`truncate`,children:e.name})]},e.id))})]})}function XP({selectedProjectId:e,onSelect:t}){u();let n=H(Yr(e=>e.projects));if(H(e=>e.projectsAvailable)===!1)return null;let r=Object.values(n).filter(e=>e.status===`active`&&e.project_path_status===`configured`).sort((e,t)=>t.updated_at.localeCompare(e.updated_at)),i=e?n[e]:void 0;return(0,q.jsxs)(ke,{children:[(0,q.jsx)(V,{asChild:!0,children:(0,q.jsxs)(`button`,{className:Fe,title:i?f(`project_690aa0ce`,{v0:i.name}):f(`select_project_682279bf`),children:[(0,q.jsx)(br,{className:`size-4 shrink-0`}),(0,q.jsx)(`span`,{className:`truncate`,children:i?i.name:f(`select_project_682279bf`)}),(0,q.jsx)(me,{className:`size-3 shrink-0 opacity-60`})]})}),(0,q.jsxs)(z,{align:`start`,children:[(0,q.jsxs)(B,{onClick:()=>t(null),children:[i?(0,q.jsx)(`span`,{className:`size-3.5`}):(0,q.jsx)(de,{className:`size-3.5`}),f(`no_project_4fdaa950`)]}),r.map(e=>(0,q.jsxs)(B,{onClick:()=>t(e.id),children:[i?.id===e.id?(0,q.jsx)(de,{className:`size-3.5`}):(0,q.jsx)(`span`,{className:`size-3.5`}),(0,q.jsx)(`span`,{className:`truncate`,children:e.name})]},e.id))]})]})}function ZP({draft:e,draftKey:t,contentShiftX:n=0,outputRate:r,onDraftChange:i,onSubmit:a,executionBlocked:o=!1,onStop:s,sending:c,queueMode:l,onQueueModeChange:d,sendWhileRunning:p=!1,queueControls:h,permissionControl:g,workspaceControl:_,runtimeControls:v,workflowControl:y,workflowUndoControl:b,catalogState:x,onPickCatalogEntry:S,catalogDisabled:C,submissionPending:w,inputRef:T,attachments:E,onAddFiles:D,onRemoveAttachment:O,onPreviewImage:k,selectedSkill:A,onClearSkill:j,onPickSkill:M,skills:N,workflows:P,selectedWorkflow:te,onClearWorkflow:R,onPickWorkflow:ne,onPickCatalog:re,onOpenCatalog:ie,onPickGoal:ae,slashQuery:oe,onMentionQueryChange:se,displayWorkspace:ce,showProjectWorkspace:le=!1,workspaceFiles:ue,hasSession:de,onOpenWorkspacePicker:fe,selectedProjectId:pe,onSelectProject:he,onDismissMenus:ge}){u();let _e=(0,K.useId)(),[ve,ye]=vi(),be=ye>0&&ye<600,xe=(0,K.useRef)(be);xe.current=be;let[Se,Ce]=(0,K.useState)(!1),we=(0,K.useRef)(!1);(0,K.useEffect)(()=>{Ce(!1)},[be,t]);let Te=(0,K.useRef)(null),Ee=(0,K.useRef)(null),[z,De]=(0,K.useState)(null),B=z?.query??null;(0,K.useEffect)(()=>se(B),[B,se]),(0,K.useEffect)(()=>De(null),[t,ce]);let Oe=c&&!!d,ke=!c||Oe||p,V=!!e.trim()||E.length>0||!!te,Ae=e=>{Se&&(we.current=!0,Ce(!1)),e()},Me=(0,q.jsxs)(`div`,{className:`flex min-w-0 max-w-full flex-wrap items-center gap-1`,"data-composer-secondary-controls":!0,children:[(0,q.jsx)(W,{size:`icon`,variant:`ghost`,className:Ne,"aria-label":f(`add_images_9f0d4e46`),onClick:()=>Ee.current?.click(),children:(0,q.jsx)(Ir,{className:`size-4`})}),re&&(0,q.jsx)(W,{size:`icon`,variant:`ghost`,className:`size-8 shrink-0 text-muted-foreground`,"aria-label":f(`open_workflow_catalog_1bd98d37`),title:f(`catalog_workflow_this_message_4bad8776`),onClick:()=>Ae(ie??re),children:(0,q.jsx)(ar,{className:`size-4`})}),de?null:(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(XP,{selectedProjectId:pe,onSelect:he}),_,(0,q.jsxs)(`button`,{onClick:()=>Ae(fe),className:pe&&!le?`hidden`:Fe,title:ce||f(`default_working_directory_3d80c40d`),children:[(0,q.jsx)(je,{className:`size-4 shrink-0`}),(0,q.jsx)(`span`,{className:`truncate`,children:ce?ce.split(`/`).filter(Boolean).pop()||ce:f(`select_working_directory_18240aa3`)}),(0,q.jsx)(me,{className:`size-3 shrink-0 opacity-60`})]}),(0,q.jsx)(YP,{})]})]});return(0,q.jsx)(`div`,{className:`min-w-0 shrink-0 px-3 py-3`,children:(0,q.jsxs)(`div`,{ref:ve,"data-composer-column":!0,"data-composer-compact":be,className:`relative mx-auto min-w-0 w-full max-w-full`,style:{transform:`translateX(${n}px)`,transition:`transform var(--motion-normal) var(--motion-ease)`},children:[h,oe!==null&&(0,q.jsx)(qP,{inputId:_e,catalogState:x,onPickCatalogEntry:S,catalogDisabled:C,skills:N,workflows:P,query:oe,onPick:M,onPickWorkflow:ne,onPickCatalog:re,onPickGoal:ae,onDismiss:ge}),oe===null&&z&&ce?(0,q.jsx)(JP,{inputId:_e,files:ue,query:z.query,onPick:e=>z.pick(e.path),onDismiss:()=>z.dismiss()}):null,A&&(0,q.jsx)(`div`,{className:`mx-auto mb-2 flex w-full max-w-full`,children:(0,q.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded-full bg-primary/15 px-2.5 py-1 text-xs font-medium text-primary`,children:[`/`,A.name,(0,q.jsx)(`button`,{onClick:j,"aria-label":f(`remove_skill_1324d3de`),className:`opacity-70 hover:opacity-100`,children:(0,q.jsx)(He,{className:`size-3`})})]})}),te&&(0,q.jsx)(`div`,{className:`mx-auto mb-2 flex w-full max-w-full`,children:(0,q.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded-full bg-primary/15 px-2.5 py-1 text-xs font-medium text-primary`,children:[f(`text_expansion_6768e498`),te.name,(0,q.jsx)(`button`,{onClick:R,"aria-label":f(`remove_workflow_c1c0133d`),className:`opacity-70 hover:opacity-100`,children:(0,q.jsx)(He,{className:`size-3`})})]})}),E.length>0&&(0,q.jsx)(`div`,{className:`mx-auto mb-2 flex w-full max-w-full flex-wrap gap-2`,children:E.map(e=>(0,q.jsxs)(`div`,{className:`relative size-24 overflow-hidden rounded-2xl border`,children:[(0,q.jsx)(`img`,{src:e.url,alt:e.name,className:`size-full cursor-zoom-in object-cover transition-opacity hover:opacity-90`,onClick:()=>k(e.url)}),(0,q.jsx)(`button`,{onClick:()=>O(e.id),className:`absolute right-1 top-1 rounded-full bg-black/60 p-1 text-white transition-colors hover:bg-black/80`,"aria-label":f(`remove_image_86d72aab`),children:(0,q.jsx)(He,{className:`size-3.5`})})]},e.id))}),(0,q.jsx)(`input`,{ref:Ee,type:`file`,accept:`image/*`,multiple:!0,hidden:!0,onChange:e=>{e.target.files&&D(e.target.files),e.target.value=``}}),(0,q.jsx)(`div`,{className:`relative mx-auto min-w-0 w-full max-w-full`,children:(0,q.jsxs)(`div`,{"data-composer-surface":!0,className:`rounded-2xl border border-transparent bg-card p-1.5`,style:{borderRadius:`1.5rem`},children:[y,b,(0,q.jsx)(`div`,{className:`relative`,children:(0,q.jsx)(GP,{id:_e,inputRef:T,focusSnapshot:Te,value:e,label:f(`messages_4da199fa`),busy:w,onChange:i,onAddFiles:D,onSubmit:()=>{!o&&!w&&V&&ke&&a()},mentionScope:ce,mentionsEnabled:oe===null&&!!ce,onSuggestionChange:De,title:f(`enter_to_send_shift_enter_for_a_new_line_b6153e81`),placeholder:f(Oe?`type_a_message_to_add_to_the_queue_38c6f67b`:`send_a_message_ae2f86f0`)},t)}),(0,q.jsxs)(`div`,{"data-composer-toolbar":!0,className:`flex flex-wrap items-center gap-1`,children:[(0,q.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-center gap-1`,style:{flex:be?`1 0 100%`:`1 1 auto`},children:[g,be?(0,q.jsxs)(ee,{open:Se,onOpenChange:Ce,children:[(0,q.jsx)(F,{asChild:!0,children:(0,q.jsx)(W,{size:`icon`,variant:`ghost`,className:Ne,"aria-label":f(`more_38844b13`),title:f(`more_38844b13`),children:(0,q.jsx)(Xn,{className:`size-4`})})}),(0,q.jsx)(I,{side:`top`,align:`start`,"aria-label":f(`more_38844b13`),style:{maxWidth:`calc(100vw - 24px)`},onCloseAutoFocus:e=>{we.current?(we.current=!1,e.preventDefault()):xe.current||(e.preventDefault(),ve.current?.querySelector(`[data-composer-editor]`)?.focus())},children:Me})]}):Me,typeof r==`number`&&(0,q.jsx)(`span`,{"data-output-rate":!0,className:`ml-auto min-w-0 text-xs tabular-nums text-muted-foreground`,style:{maxWidth:112,overflow:`hidden`,textOverflow:`ellipsis`,whiteSpace:`nowrap`},title:f(`estimated_from_streamed_text_not_used_for_billing_1de5fc8d`),children:f(`output_rate`,{rate:r.toLocaleString(m(),{minimumFractionDigits:1,maximumFractionDigits:1})})})]}),(0,q.jsxs)(`div`,{className:`ml-auto flex max-w-full flex-wrap items-center justify-end gap-1`,children:[Oe?(0,q.jsxs)(`div`,{className:`relative h-8 shrink-0`,style:{width:be?32:96},children:[(0,q.jsx)(fr,{"aria-hidden":`true`,className:`pointer-events-none absolute left-2 top-2 size-4 text-muted-foreground`,style:{display:be?void 0:`none`}}),(0,q.jsxs)(`select`,{"aria-label":f(`send_timing_22388dde`),value:l??`after_round`,disabled:w,onChange:e=>d?.(e.target.value),title:f(l===`after_run`?`send_when_the_run_finishes_1525b79a`:`send_after_the_current_tool_call_before_the_next_model__ce3a9c75`),className:`h-full w-full rounded-md border-0 bg-transparent text-sm text-muted-foreground`,style:{appearance:be?`none`:`auto`,color:be?`transparent`:void 0},children:[(0,q.jsx)(`option`,{className:`text-foreground`,value:`after_round`,children:f(`after_tool_call_252b019e`)}),(0,q.jsx)(`option`,{className:`text-foreground`,value:`after_run`,children:f(`after_run_81638e07`)})]})]}):null,v,w?(0,q.jsx)(W,{size:`icon`,disabled:!0,"aria-label":f(`sending_2d88d503`),className:`size-8 rounded-full`,children:(0,q.jsx)(L,{className:`animate-spin`})}):ke?(0,q.jsx)(W,{size:`icon`,onClick:a,disabled:!V||o,className:`size-8 rounded-full`,"aria-label":f(Oe?`add_to_queue_bc3b684c`:`send_message_00881483`),title:f(Oe?`add_to_queue_bc3b684c`:`send_message_00881483`),children:(0,q.jsx)(ir,{})}):null,c&&(!w||Oe)?(0,q.jsx)(W,{size:`icon`,onClick:s,className:`size-8 rounded-full`,"aria-label":f(`stop_generation_9ad0aac3`),children:(0,q.jsx)(Br,{fill:`currentColor`})}):null]})]})]})})]})})}function QP({notice:e,onDismiss:t,onRestoreFocus:n}){let r=(0,K.useRef)(null),i=(0,K.useRef)(null),[a,o]=(0,K.useState)(!1),[s,c]=(0,K.useState)(!1),[l,u]=(0,K.useState)(!1),d=(0,K.useRef)(5e3),p=(0,K.useRef)(t);p.current=t,(0,K.useEffect)(()=>{if(e.kind===`error`||a||s||l)return;let t=Date.now(),n=setTimeout(()=>p.current(),d.current);return()=>{clearTimeout(n),d.current=Math.max(0,d.current-(Date.now()-t))}},[e.kind,a,s,l]);let m=e.message.length>160?`${e.message.slice(0,160)}…`:e.message,h=[m===e.message?null:e.message,e.details===e.message?null:e.details].filter(Boolean).join(`
|
|
110
|
+
|
|
111
|
+
`);return(0,q.jsxs)(`div`,{ref:r,className:G(Ut,`surface-fade pointer-events-auto flex min-w-0 max-w-md items-start gap-2 rounded-2xl border bg-card px-4 py-3 text-sm font-medium text-foreground shadow-lg`),style:{"--tw-enter-translate-y":`8px`,width:`100%`,maxHeight:`calc(100dvh - 8rem)`,overflowY:`auto`},onMouseEnter:()=>o(!0),onMouseLeave:()=>o(!1),onFocusCapture:e=>{if(!e.currentTarget.contains(e.relatedTarget)){let t=e.relatedTarget;i.current=t instanceof HTMLElement&&t!==document.body?t:null}c(!0)},onBlurCapture:e=>{e.currentTarget.contains(e.relatedTarget)||c(!1)},children:[(0,q.jsx)(kr,{className:G(`mt-0.5 size-4 shrink-0`,e.kind===`error`?`text-destructive`:`text-primary`),"aria-hidden":!0}),(0,q.jsxs)(`div`,{className:`min-w-0 flex-1`,style:{overflowWrap:`anywhere`},children:[(0,q.jsxs)(`div`,{role:e.kind===`error`?`alert`:`status`,"aria-atomic":`true`,children:[e.kind===`error`&&(0,q.jsx)(`strong`,{className:`block text-destructive`,children:f(`operation_failed_0c3b4cf7`)}),m]}),h&&(0,q.jsxs)(`details`,{className:`mt-2`,onToggle:e=>u(e.currentTarget.open),children:[(0,q.jsx)(`summary`,{className:`cursor-pointer rounded outline-none focus-visible:ring-2`,children:f(l?`hide_details_2e1b7da4`:`show_details_448d5d38`)}),(0,q.jsx)(`div`,{className:`mt-2 overflow-auto whitespace-pre-wrap text-xs text-muted-foreground`,style:{maxHeight:`min(40vh, 20rem)`},children:h})]})]}),(0,q.jsx)(W,{variant:`ghost`,size:`icon`,className:`size-6 shrink-0`,"aria-label":f(`close_3fd47edc`),onClick:()=>{let e=r.current?.contains(document.activeElement);if(t(),!e)return;let a=i.current;a?.isConnected&&!a.matches(`:disabled, [aria-disabled=true]`)&&!a.closest(`[hidden], [inert], [aria-hidden=true]`)&&(a.focus({preventScroll:!0}),document.activeElement===a)||n?.()},children:(0,q.jsx)(He,{className:`size-4`})})]})}function $P({forking:e,toast:t,onDismiss:n,onRestoreFocus:r}){return u(),!e&&!t?null:(0,q.jsx)(`div`,{className:`pointer-events-none fixed inset-x-0 bottom-28 z-[110] flex justify-center px-4`,children:e?(0,q.jsxs)(`div`,{role:`status`,"aria-atomic":`true`,className:`flex items-center gap-2 rounded-2xl border bg-card px-4 py-3 text-sm shadow-lg`,children:[(0,q.jsx)(L,{className:`size-4 animate-spin text-primary`,"aria-hidden":!0}),f(`forking_bed88cb0`)]}):t&&(0,q.jsx)(QP,{notice:t,onDismiss:n,onRestoreFocus:r},t.id)})}function eF({src:e,onClose:t}){return u(),e?(0,q.jsxs)(`div`,{className:`fixed inset-0 z-[100] flex items-center justify-center bg-black/85 p-4 sm:p-8`,onClick:t,children:[(0,q.jsx)(`img`,{src:e,alt:``,className:`max-h-full max-w-full rounded-xl object-contain shadow-2xl`,onClick:e=>e.stopPropagation()}),(0,q.jsx)(`button`,{onClick:t,className:`absolute right-4 top-4 rounded-full bg-white/15 p-2 text-white backdrop-blur transition-colors hover:bg-white/25`,"aria-label":f(`close_preview_1eb05d31`),children:(0,q.jsx)(He,{className:`size-5`})})]}):null}function tF({totalTokens:e,maxContextTokens:t,cacheReadInputTokens:n,cacheReadInputTokensRetained:r,prefixCache:i,onClick:a}){if(u(),!t)return null;let o=Math.min(100,Math.round(e/t*100)),s=i?tt(i):void 0,c=typeof s==`number`?Math.round(s):void 0,l=i?.cacheReadInputTokens??n,d=!!(i?.retainedFromPreviousRound||r),p=typeof c==`number`?`${c}%`:typeof l==`number`?`--`:null,h=2*Math.PI*7,g=o>85?`text-destructive`:o>65?`text-amber-500`:`text-primary`,_=f(`context_tokens_34cb163e`,{v0:e.toLocaleString(m()),v1:t.toLocaleString(m()),v2:o}),v=f(d?`previous_completed_round_836ba413`:`latest_completed_round_fe872c8f`),y=typeof c==`number`&&i?f(`prefix_cache_detail`,{pct:c,read:i.cacheReadInputTokens.toLocaleString(m()),input:Ke(i).toLocaleString(m()),status:v}):typeof l==`number`&&l>0?f(`prefix_cache_read_tokens_the_backend_does_not_provide_a_6d8df76f`,{v0:l.toLocaleString(m()),v1:v}):null;return(0,q.jsxs)(`button`,{onClick:a,className:`flex h-8 shrink-0 items-center gap-1.5 rounded-md px-2 text-muted-foreground hover:bg-accent hover:text-foreground`,title:y?f(`context_cache_detail`,{context:_,cache:y}):_,"aria-label":p===null?f(`context_usage_06d7b2e3`):f(`context_usage_cache_0cd3733a`,{v0:p}),children:[(0,q.jsxs)(`svg`,{width:`16`,height:`16`,viewBox:`0 0 18 18`,className:`-rotate-90`,"aria-hidden":!0,children:[(0,q.jsx)(`circle`,{cx:`9`,cy:`9`,r:`7`,fill:`none`,strokeWidth:`2.5`,className:`stroke-muted`}),(0,q.jsx)(`circle`,{cx:`9`,cy:`9`,r:`7`,fill:`none`,strokeWidth:`2.5`,strokeLinecap:`round`,strokeDasharray:h,strokeDashoffset:h*(1-o/100),className:G(`stroke-current transition-all`,g)})]}),(0,q.jsxs)(`span`,{className:`hidden text-sm tabular-nums sm:inline`,children:[o,`%`]}),p===null?null:(0,q.jsxs)(`span`,{"data-prefix-cache":!0,className:`hidden text-xs tabular-nums text-muted-foreground sm:inline-flex`,children:[`Cache `,p]})]})}function nF(e){switch(e?.status){case`running`:return f(`context_compression_notice_running`);case`completed`:return e.awaitingUsage===!0?f(`context_compression_notice_completed_waiting`):e.awaitingUsage===!1?f(`context_compression_notice_completed`):null;case`failed`:switch(e.reason){case`candidate_plan`:return f(`context_compression_notice_failed_candidate`);case`postcondition`:return f(`context_compression_notice_failed_postcondition`);case`other`:return f(`context_compression_notice_failed`);default:return null}case`deferred`:switch(e.reason){case`tool_protocol`:return f(`context_compression_notice_deferred_tool`);case`other`:return f(`context_compression_notice_deferred`);default:return null}case`skipped`:switch(e.reason){case`no_model`:return f(`context_compression_notice_skipped_no_model`);case`other`:return f(`context_compression_notice_skipped`);default:return null}case`cancelled`:return f(`context_compression_notice_cancelled`);case`unconfirmed`:return f(`context_compression_notice_unconfirmed`);default:return null}}function rF({feedback:e}){u();let t=nF(e);return t?(0,q.jsxs)(`div`,{role:`status`,"aria-live":`polite`,"aria-atomic":`true`,className:`flex min-w-0 items-start gap-2 rounded-md border bg-muted/40 px-3 py-2 text-xs text-muted-foreground`,"data-testid":`context-compression-notice`,children:[e?.status===`running`?(0,q.jsx)(L,{"aria-hidden":`true`,className:`mt-0.5 size-3.5 shrink-0 motion-safe:animate-spin`}):null,(0,q.jsx)(`span`,{className:`min-w-0 break-words`,children:t})]}):null}var iF=[{top:`22%`,animationDuration:`1.6s`,animationDelay:`-0.4s`,"--meteor-rest":`-25%`},{top:`48%`,animationDuration:`2.7s`,animationDelay:`-1.8s`,"--meteor-rest":`8%`},{top:`76%`,animationDuration:`2.1s`,animationDelay:`-0.9s`,"--meteor-rest":`30%`}],aF=[`auto`,`none`,`low`,`medium`,`high`,`xhigh`,`max`],oF=()=>({auto:f(`auto_7eb336e4`),none:f(`reasoning_none`),low:f(`low_aa9e366f`),medium:f(`medium_a567bdaa`),high:f(`high_b1c27820`),xhigh:f(`extra_high_392d0dce`),max:f(`max_9730c15f`),ultra:f(`ultra_orchestration_5857fcd7`)}),sF={auto:`var(--muted-foreground)`,none:`var(--muted-foreground)`,low:`#5294ed`,medium:`#428cff`,high:`#3b82f6`,xhigh:`#818cf8`,max:`#a78bfa`,ultra:`#bd8bfa`};function cF({models:e,model:t,onModelChange:n,modelDisabled:r=!1,value:i,onChange:a,disabled:o=!1,allowUltra:s=!1,thinkingMode:c,menuPlacement:l=`up`,menuAlign:d=`right`}){u();let p=(0,K.useId)(),[m,h]=(0,K.useState)(!1),[g,_]=(0,K.useState)(`effort`),[v,y]=(0,K.useState)(``),[b,x]=(0,K.useState)(null),S=(0,K.useRef)(null),C=(0,K.useRef)(null),w=(0,K.useRef)(null),T=(0,K.useRef)(!1),E=(0,K.useRef)(!1),D=s?[...aF,`ultra`]:aF,O=s&&c===`ultra`?`ultra`:i,k=s&&c===null,A=o||k,j=r||e.length===0,M=A&&j,N=D.indexOf(O),P=A?N:b??N,L=D[P],te=oF(),R=k?f(`unconfirmed_c098e854`):te[O],ne=sF[L],re=v.trim().toLowerCase(),ie=re?e.filter(e=>e.toLowerCase().includes(re)):e;(0,K.useEffect)(()=>{m&&(g===`models`?S.current?.focus():A?w.current?.focus():C.current?.focus())},[m,g,A]);let ae=e=>{e&&M||(h(e),e||(_(`effort`),y(``),x(null),T.current=!1,E.current=!1))},oe=e=>{x(null),T.current=!1,E.current=!1;let t=D[e];!A&&t&&(t!==O||k)&&a(t)};return(0,q.jsxs)(ee,{open:m&&!M,onOpenChange:ae,children:[(0,q.jsx)(F,{asChild:!0,children:(0,q.jsxs)(`button`,{type:`button`,"data-testid":`model-effort-picker`,"aria-label":f(`model_and_reasoning_effort`),"aria-describedby":`${p}-model ${p}-effort`,title:`${t||f(`select_a_model_1afed6a8`)} · ${R}`,disabled:M,className:G(`model-effort-trigger`,Fe),children:[(0,q.jsx)(`span`,{id:`${p}-model`,className:`min-w-0 truncate text-left`,children:t||f(`select_a_model_1afed6a8`)}),(0,q.jsx)(`span`,{id:`${p}-effort`,className:`effort-trigger-label shrink-0 truncate`,children:R}),(0,q.jsx)(me,{className:`size-3 shrink-0 text-muted-foreground`,"aria-hidden":!0})]})}),(0,q.jsx)(I,{side:l===`up`?`top`:`bottom`,align:d===`right`?`end`:`start`,className:`model-effort-panel w-64 max-w-[calc(100vw-1.5rem)] rounded-2xl p-2.5 shadow-xl`,onOpenAutoFocus:e=>{e.preventDefault(),A?w.current?.focus():C.current?.focus()},children:g===`effort`?(0,q.jsxs)(q.Fragment,{children:[(0,q.jsxs)(`div`,{className:`grid grid-cols-[2rem_1fr_2rem] items-center gap-2`,children:[O===`ultra`?(0,q.jsx)($n,{className:`mx-auto size-4`,style:{color:ne},"aria-hidden":!0}):(0,q.jsx)(`span`,{"aria-hidden":!0}),(0,q.jsxs)(`div`,{className:`min-w-0 text-center`,children:[(0,q.jsx)(`p`,{className:`truncate text-sm font-semibold`,style:{color:ne},"aria-live":`polite`,title:k?R:te[L],children:k?R:te[L]}),(0,q.jsxs)(`button`,{ref:w,type:`button`,"data-testid":`model-picker-model`,disabled:j,title:t||f(`select_a_model_1afed6a8`),onClick:()=>{j||(_(`models`),x(null))},className:`mx-auto flex min-h-8 max-w-full items-center gap-0.5 rounded-md px-1 py-0.5 text-xs text-muted-foreground outline-none hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50`,children:[(0,q.jsx)(`span`,{className:`truncate`,children:t||f(`select_a_model_1afed6a8`)}),(0,q.jsx)(ve,{className:`size-3 shrink-0`,"aria-hidden":!0})]})]}),(0,q.jsx)(`button`,{type:`button`,"aria-label":f(`restore_auto_reasoning`),title:f(`restore_auto_reasoning`),disabled:A||O===`auto`,onClick:()=>{!A&&O!==`auto`&&a(`auto`)},className:`flex size-8 items-center justify-center rounded-full text-muted-foreground outline-none hover:bg-accent hover:text-foreground disabled:cursor-not-allowed disabled:opacity-40`,children:(0,q.jsx)(ce,{className:`size-4`,"aria-hidden":!0})})]}),(0,q.jsxs)(`div`,{className:G(`effort-slider mt-3`,L===`ultra`&&`effort-slider-ultra`,A&&`opacity-40`),style:{"--effort-accent":ne,"--effort-progress":P/(D.length-1)},children:[(0,q.jsx)(`div`,{className:`effort-slider-fill`,"aria-hidden":!0,children:L===`ultra`&&(0,q.jsx)(`span`,{className:`effort-meteors pointer-events-none absolute inset-0 overflow-hidden rounded-full`,children:iF.map(e=>(0,q.jsx)(`i`,{className:`absolute h-0.5 w-full opacity-70`,style:{...e,transform:`translateX(var(--meteor-rest))`,background:`linear-gradient(90deg, #fff, transparent) center / 26px 2px no-repeat`}},e.top))})}),(0,q.jsx)(`div`,{className:`effort-slider-ticks`,"aria-hidden":!0,children:D.map(e=>(0,q.jsx)(`span`,{},e))}),(0,q.jsx)(`input`,{ref:C,type:`range`,min:0,max:D.length-1,step:1,value:P,"aria-label":f(`reasoning_level_c8c14507`),"aria-valuetext":k?R:te[L],disabled:A,onPointerDown:()=>{T.current=!0},onChange:e=>{if(A)return;let t=Number(e.currentTarget.value);T.current||E.current?x(t):oe(t)},onPointerUp:e=>oe(Number(e.currentTarget.value)),onPointerCancel:()=>{T.current=!1,x(null)},onKeyDown:e=>{[`ArrowLeft`,`ArrowRight`,`ArrowUp`,`ArrowDown`,`Home`,`End`,`PageUp`,`PageDown`].includes(e.key)&&(E.current=!0)},onKeyUp:e=>{[`ArrowLeft`,`ArrowRight`,`ArrowUp`,`ArrowDown`,`Home`,`End`,`PageUp`,`PageDown`].includes(e.key)&&oe(Number(e.currentTarget.value))},onBlur:()=>{E.current=!1,T.current||x(null)}})]})]}):(0,q.jsxs)(q.Fragment,{children:[(0,q.jsxs)(`div`,{className:`mb-2 flex items-center gap-1 text-sm text-muted-foreground`,children:[(0,q.jsx)(`button`,{type:`button`,"aria-label":f(`back_2d1d8c1e`),onClick:()=>{_(`effort`),y(``)},className:`flex size-7 items-center justify-center rounded-full outline-none hover:bg-accent`,children:(0,q.jsx)(cr,{className:`size-4`,"aria-hidden":!0})}),(0,q.jsx)(`span`,{children:f(`select_a_model_1afed6a8`)})]}),(0,q.jsxs)(`div`,{className:`relative mb-2`,children:[(0,q.jsx)(Ve,{className:`pointer-events-none absolute left-2.5 top-1/2 size-3.5 -translate-y-1/2 text-muted-foreground`,"aria-hidden":!0}),(0,q.jsx)(fe,{ref:S,type:`text`,role:`searchbox`,"aria-label":f(`search_models_93a8734c`),placeholder:f(`search_models_8ec7b052`),value:v,onChange:e=>y(e.currentTarget.value),className:`model-effort-search h-8 pl-8 pr-8 text-xs`}),v?(0,q.jsx)(`button`,{type:`button`,"aria-label":f(`clear_model_search_ff2b5895`),onClick:()=>{y(``),S.current?.focus()},className:`absolute right-1 top-1/2 flex size-6 -translate-y-1/2 items-center justify-center rounded-md text-muted-foreground hover:bg-accent`,children:(0,q.jsx)(He,{className:`size-3.5`,"aria-hidden":!0})}):null]}),(0,q.jsxs)(`div`,{className:`max-h-60 overflow-y-auto`,"aria-label":f(`model_list_ea4bf042`),children:[ie.map(e=>(0,q.jsxs)(`button`,{type:`button`,"data-model-option":``,"aria-pressed":e===t,title:e,disabled:j,onClick:()=>{j||(n(e),ae(!1))},className:`flex w-full items-center gap-2 rounded-xl px-3 py-2 text-left text-sm outline-none hover:bg-accent focus-visible:bg-accent disabled:cursor-not-allowed disabled:opacity-50`,children:[(0,q.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:e}),(0,q.jsx)(de,{className:G(`size-4 shrink-0 text-primary`,e!==t&&`opacity-0`),"aria-hidden":!0})]},e)),ie.length===0?(0,q.jsx)(`p`,{role:`status`,className:`px-3 py-6 text-center text-xs text-muted-foreground`,children:f(`no_matching_models_4b5e0ae1`)}):null]})]})})]})}var lF=We((e,t)=>({mode:`default`,loaded:!1,setMode:t=>e({mode:t}),refresh:async()=>{try{let t=kt((await Ze.getDefaultSessionPermissionMode()).mode);t&&e({mode:t,loaded:!0})}catch{t().loaded||e({loaded:!0})}}})),uF=G(Fe,`border-0 bg-transparent shadow-none dark:bg-transparent dark:hover:bg-accent [&>svg:last-child]:size-3`);function dF(){return(0,q.jsxs)(xe,{side:`top`,align:`start`,children:[(0,q.jsx)(Se,{value:`default`,children:`Default`}),(0,q.jsx)(Se,{value:`bypass`,children:`Bypass`}),(0,q.jsx)(Se,{value:`auto`,children:`Auto`})]})}function fF(e){return(0,q.jsx)(pF,{...e},e.sessionId)}function pF({sessionId:e,title:t,compact:n=!1}){let{t:r}=h(),i=(0,K.useId)(),a=H(t=>t.chats.some(t=>t.id===e)),o=H(t=>t.chats.find(t=>t.id===e)?.config.permissionMode),s=H(t=>t.chats.find(t=>t.id===e)?.config.permissionModeEtag),c=H(t=>t.permissionModeRequests[e]),l=H(e=>e.refreshSessionPermissionMode),u=H(e=>e.changeSessionPermissionMode),d=!c,[f,p]=(0,K.useState)(null),m=(0,K.useRef)(null),g=(0,K.useRef)(null);(0,K.useEffect)(()=>{a&&d&&l(e)},[e,l,d,a]);let _=!!(kt(o)&&Lt(s)!==null),v=c?.status===`ready`&&_,y=c?.status===`saving`,b=_&&(v||y),x=a&&!c||c?.status===`loading`||y,S=a?c?.status===`unsupported`?r(`chat.permissionMode.unavailable`):r(x?`chat.permissionMode.loading`:`chat.permissionMode.unconfirmed`):r(`chat.permissionMode.unconfirmed`),C=r(b?`chat.permissionMode.help.${o}`:`chat.permissionMode.readRequired`),w=c?.error?r(`chat.permissionMode.errors.${c.error}`):null;return(0,q.jsxs)(`section`,{className:G(n?`flex min-w-0 max-w-full flex-wrap items-center gap-1`:`shrink-0 border-b px-3 py-2`),"aria-label":r(`chat.permissionMode.section`),"data-variant":n?`composer`:`bar`,title:n?[C,w].filter(Boolean).join(` `):void 0,children:[(0,q.jsxs)(`div`,{className:G(`flex flex-wrap items-center`,n?`gap-1`:`gap-x-3 gap-y-1.5`),children:[(0,q.jsx)(`label`,{htmlFor:i,className:n?`sr-only`:`text-xs font-medium`,children:r(`chat.permissionMode.label`)}),(0,q.jsxs)(we,{disabled:!v,value:b?o:``,onValueChange:t=>{let n=kt(t);!v||!s||!n||n===o||(n===`auto`?p({etag:s}):u(e,n,s))},children:[(0,q.jsxs)(be,{ref:m,id:i,"aria-label":r(`chat.permissionMode.label`),"aria-describedby":`${i}-help${c?.error?` ${i}-error`:``}`,size:n?`sm`:`default`,className:G(n?uF:`max-w-full bg-background`,`disabled:opacity-70`,b&&o===`auto`&&(n?`text-amber-700 dark:text-amber-400`:`border-amber-500 text-amber-700 dark:text-amber-400`)),children:[n?(0,q.jsx)(zr,{className:G(`size-4 shrink-0`,b&&o===`auto`?`text-amber-500`:`text-muted-foreground`),"aria-hidden":!0}):null,(0,q.jsx)(ye,{placeholder:S})]}),(0,q.jsx)(dF,{})]}),(0,q.jsx)(`span`,{role:`status`,className:n?`sr-only`:`text-xs text-muted-foreground`,children:y?r(`chat.permissionMode.saving`):x?r(`chat.permissionMode.loading`):null}),c?.error?(0,q.jsx)(W,{size:`sm`,variant:`ghost`,className:n?`h-7 px-1.5 text-xs`:void 0,disabled:x,onClick:()=>void l(e),children:r(`chat.permissionMode.refresh`)}):null]}),(0,q.jsx)(`p`,{id:`${i}-help`,className:n?`sr-only`:`mt-1.5 text-xs leading-relaxed text-muted-foreground`,children:C}),c?.error?(0,q.jsx)(`p`,{id:`${i}-error`,role:`alert`,className:n?`basis-full max-w-sm break-words text-xs leading-relaxed text-destructive`:`mt-1 text-xs leading-relaxed text-destructive`,children:w}):null,(0,q.jsx)($t,{open:!!(f&&f.etag===s),onOpenChange:e=>{e||p(null)},children:(0,q.jsxs)(Yt,{onOpenAutoFocus:e=>{e.preventDefault(),g.current?.focus()},onCloseAutoFocus:e=>{e.preventDefault(),m.current?.focus()},children:[(0,q.jsxs)(qt,{children:[(0,q.jsxs)(Xt,{className:`flex items-center gap-2`,children:[(0,q.jsx)(zr,{className:`size-5 shrink-0 text-amber-500`}),r(`chat.permissionMode.confirmTitle`)]}),(0,q.jsx)(Zt,{className:`break-words`,children:r(`chat.permissionMode.confirmDescription`,{title:t})})]}),v?null:(0,q.jsx)(`p`,{role:`alert`,className:`text-sm text-destructive`,children:r(`chat.permissionMode.readRequired`)}),(0,q.jsxs)(Jt,{children:[(0,q.jsx)(W,{ref:g,variant:`outline`,onClick:()=>p(null),children:r(`chat.permissionMode.cancel`)}),(0,q.jsx)(W,{variant:`destructive`,disabled:!v,onClick:()=>{let t=f?.etag;!v||!t||t!==s||(p(null),u(e,`auto`,t))},children:r(`chat.permissionMode.confirm`)})]})]})})]})}function mF(){let{t:e}=h(),t=lF(e=>e.mode),n=lF(e=>e.setMode),r=lF(e=>e.refresh);return(0,K.useEffect)(()=>{r()},[r]),(0,q.jsxs)(`div`,{className:`flex min-w-0 items-center`,"data-permission-scope":`new-session`,title:e(`chat.permissionMode.help.${t}`),children:[(0,q.jsx)(`span`,{className:`sr-only`,children:e(`chat.permissionMode.label`)}),(0,q.jsxs)(we,{value:t,onValueChange:e=>{let t=kt(e);t&&n(t)},children:[(0,q.jsxs)(be,{"aria-label":e(`chat.permissionMode.label`),size:`sm`,className:G(uF,t===`auto`&&`text-amber-700 dark:text-amber-400`),children:[(0,q.jsx)(zr,{className:G(`size-4 shrink-0`,t===`auto`?`text-amber-500`:`text-muted-foreground`),"aria-hidden":!0}),(0,q.jsx)(ye,{})]}),(0,q.jsx)(dF,{})]})]})}function hF({sessionId:e,child:t,unsafe:n,selected:r,confirmed:i,loading:a,pending:o,recovering:s,recoverable:c,error:l,conflict:d,onRetry:p}){if(u(),t)return null;let m=f(n&&o&&!l&&!d?`waiting_for_server_confirmation_71efb37a`:n?s?`recovering_permission_result_7a4a9813`:`permission_result_unknown_37e663a7`:t?`only_root_can_configure_this_33c9ea08`:a?`reading_server_state_14b7f241`:e&&r===null?`state_unavailable_a9dcef67`:o?`waiting_for_server_confirmation_71efb37a`:e?e&&typeof r==`boolean`&&typeof i==`boolean`&&r!==i?r?`pending_enable_currently_off_b175d612`:`pending_disable_currently_on_8e846da7`:i?`server_confirmed_ultra_orchestration_25a54375`:`server_confirmed_standard_mode_fb0ea60d`:r?`use_ultra_orchestration_for_the_next_session_7f755f23`:`use_standard_mode_for_the_next_session_b08ea9c5`);return(0,q.jsxs)(`div`,{className:l||d?`flex min-w-0 max-w-full flex-wrap items-center gap-1.5 text-xs`:`sr-only`,"aria-busy":a||o||s,children:[(0,q.jsx)(`span`,{role:`status`,"aria-live":`polite`,className:`sr-only`,children:m}),l||d?(0,q.jsxs)(`span`,{role:`alert`,className:`basis-full text-destructive`,children:[d||l,c&&!t?(0,q.jsx)(`button`,{type:`button`,className:`ml-1 underline`,disabled:s||o,onClick:p,children:f(`recover_mode_change_ca1cc75a`)}):l&&!t&&!n?(0,q.jsx)(`button`,{type:`button`,className:`ml-1 underline`,disabled:o,onClick:p,children:f(`reload_state_df7392cc`)}):null]}):null]})}function gF({sessionId:e,selected:t,onChange:n,onRemove:r,open:i,onOpenChange:a,catalogState:o,disabled:s,error:c,onArgsFocus:l,onReturnFocus:d,variant:p=`composer`}){u();let[m,h]=(0,K.useState)(``),g=(0,K.useId)(),_=(0,K.useRef)(!1),{catalog:v,loading:y,error:b,refresh:x}=o,S=null;if(t)try{hn(t)}catch(e){S=Dt(e)}let C=m.trim().toLowerCase(),w=v?.entries.filter(e=>!C||[e.name,e.id,e.description,e.source].some(e=>e.toLowerCase().includes(C)))??[],T=p===`environment`;return(0,q.jsxs)(ee,{open:i,onOpenChange:e=>{h(``),a(e)},children:[(0,q.jsxs)(`div`,{className:T?`px-1`:`flex min-w-0 flex-wrap items-center gap-1 pt-1`,"data-workflow-chip":T?void 0:``,children:[(0,q.jsx)(F,{asChild:!0,children:(0,q.jsxs)(`button`,{type:`button`,"aria-label":t?f(`edit_catalog_workflow_for_this_message_c2caaa3d`,{v0:t.entry.name}):f(`choose_a_catalog_workflow_for_this_message_9594a231`),className:T?`flex w-full items-center gap-2 rounded-xl px-2 py-2 text-left hover:bg-accent`:G(Fe,`bg-primary/15 text-primary`),children:[(0,q.jsx)(ar,{className:T?`size-3.5 shrink-0`:`size-4 shrink-0`}),(0,q.jsxs)(`span`,{className:`min-w-0 flex-1 truncate`,children:[t?t.entry.name:f(`choose_catalog_workflow_cf058476`),T&&(0,q.jsx)(`span`,{className:`mt-0.5 block text-xs text-muted-foreground`,children:f(`catalog_workflow_this_message_4bad8776`)})]}),!T&&(0,q.jsx)(`span`,{className:`shrink-0 text-xs opacity-70`,children:f(`this_message_12a8838f`)}),(0,q.jsx)(me,{className:`size-3 shrink-0 opacity-60`})]})}),!T&&t&&(0,q.jsx)(`button`,{type:`button`,"aria-label":f(`remove_catalog_workflow_2388a457`),disabled:s,onClick:r,className:`rounded-full p-1 text-muted-foreground hover:bg-accent disabled:opacity-50`,children:(0,q.jsx)(He,{className:`size-3.5`})}),!T&&(c||S)&&(0,q.jsx)(`p`,{role:`alert`,className:`basis-full break-words text-xs text-destructive`,children:c||S})]}),i&&(0,q.jsxs)(I,{side:T?`left`:`top`,align:`start`,"aria-labelledby":g,className:`space-y-3 overflow-y-auto rounded-xl p-3 text-xs`,style:{width:`calc(var(--spacing) * 80)`,maxHeight:`min(32rem, var(--radix-popover-content-available-height))`,maxWidth:`calc(100vw - 1.5rem)`},onOpenAutoFocus:()=>{_.current=!1},onInteractOutside:()=>{_.current=!0},onCloseAutoFocus:e=>{d&&!T&&!_.current&&(e.preventDefault(),d())},onFocusCapture:l,children:[(0,q.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,q.jsx)(`h3`,{id:g,className:`font-medium`,children:f(`catalog_workflow_this_message_4bad8776`)}),(0,q.jsx)(`button`,{type:`button`,"aria-label":f(`close_workflow_catalog_c435e8e5`),onClick:()=>a(!1),children:(0,q.jsx)(He,{className:`size-4`})})]}),(0,q.jsx)(`p`,{className:`text-muted-foreground`,children:f(`the_selected_workflow_runs_with_this_message_and_does_n_9786f97e`)}),!e&&(0,q.jsx)(`p`,{className:`text-muted-foreground`,children:f(`new_sessions_show_general_workflows_only_open_a_project_a0386a25`)}),t&&(0,q.jsxs)(`div`,{className:`space-y-2 rounded-lg border bg-muted/30 p-2`,"data-workflow-selection":!0,children:[(0,q.jsxs)(`div`,{className:`flex min-w-0 items-start gap-2`,children:[(0,q.jsxs)(`span`,{className:`min-w-0 flex-1 break-words`,children:[t.entry.name,` · `,t.entry.source,` · r`,t.entry.revision]}),(0,q.jsx)(`button`,{type:`button`,"aria-label":f(`remove_selected_catalog_workflow_6b64a0d2`),disabled:s,onClick:r,children:(0,q.jsx)(He,{className:`size-3.5`})})]}),(0,q.jsx)(`p`,{className:`break-words text-muted-foreground`,children:t.entry.description}),(0,q.jsxs)(`label`,{className:`block space-y-1`,children:[(0,q.jsx)(`span`,{children:f(`workflow_arguments_json_7cca8c51`)}),(0,q.jsx)(Mn,{"aria-label":f(`workflow_arguments_json_7cca8c51`),value:t.argsText,disabled:s,onFocus:l,onChange:e=>n({...t,argsText:e.target.value}),rows:2,className:`max-h-40 border text-xs`})]}),(0,q.jsxs)(`details`,{className:`text-muted-foreground`,children:[(0,q.jsx)(`summary`,{children:f(`view_argument_schema_f39ae9e6`)}),(0,q.jsx)(`pre`,{className:`whitespace-pre-wrap break-words`,children:JSON.stringify(t.entry.argument_schema,null,2)})]}),S&&(0,q.jsx)(`p`,{role:`alert`,children:S})]}),c&&(0,q.jsx)(`p`,{role:`alert`,className:`break-words text-destructive`,children:c}),(0,q.jsxs)(`div`,{className:`flex gap-2`,children:[(0,q.jsx)(fe,{"aria-label":f(`search_catalog_workflows_0d8bffd7`),placeholder:f(`search_catalog_workflows_d2735d7b`),value:m,onChange:e=>h(e.target.value),className:`h-8 text-xs`}),(0,q.jsx)(W,{type:`button`,size:`sm`,variant:`outline`,disabled:y,onClick:x,children:f(`refresh_aee88743`)})]}),y&&(0,q.jsx)(`p`,{role:`status`,children:f(`loading_workflow_catalog_59214f82`)}),b&&(0,q.jsxs)(`p`,{role:`alert`,children:[f(`could_not_load_catalog_a2342d5f`),b]}),!y&&!b&&(0,q.jsxs)(`div`,{className:`max-h-60 space-y-1 overflow-y-auto`,"aria-label":f(`workflows_in_catalog_0f32be5f`),children:[w.map(e=>{let t=pn(e);return(0,q.jsxs)(`button`,{type:`button`,disabled:s||!!t,onClick:()=>{s||t||(n({entry:e,argsText:`{}`}),a(!1))},className:`block w-full rounded-lg px-2 py-2 text-left hover:bg-accent disabled:opacity-50`,children:[(0,q.jsxs)(`span`,{className:`block font-medium`,children:[e.name,` `,(0,q.jsxs)(`span`,{className:`font-normal text-muted-foreground`,children:[e.source,` · r`,e.revision]})]}),(0,q.jsx)(`span`,{className:`block text-muted-foreground`,children:t||e.description})]},`${e.kind}:${e.id}:${e.source}:${e.revision}`)}),!w.length&&(0,q.jsx)(`p`,{className:`py-2 text-muted-foreground`,children:f(C?`no_matching_catalog_workflows_de80e22d`:`no_workflows_in_catalog_yet_3aa5c7a8`)})]})]})]})}var _F=()=>o(()=>import(`./WorkflowRunsContent-lUfm3WNf.js`),__vite__mapDeps([78,1,2,3,4,7,8,9,10,11,12,79,45]),import.meta.url);function vF({sessionId:e,sessionTitle:t,onClose:n,loadContent:r=_F}){u();let[i]=(0,K.useState)(()=>(0,K.lazy)(r));return(0,q.jsx)(cn,{open:!0,onOpenChange:e=>{e||n()},children:(0,q.jsxs)(on,{className:`sm:max-w-2xl`,children:[(0,q.jsxs)(`div`,{className:`shrink-0 border-b px-5 py-4 pr-12`,children:[(0,q.jsx)(an,{children:f(`workflow_run_title`)}),(0,q.jsx)(sn,{className:`mt-2 break-words`,children:t})]}),(0,q.jsx)(ue,{name:`WorkflowRuns`,fallback:(0,q.jsx)(`p`,{role:`alert`,className:`px-5 py-4 text-sm text-destructive`,children:f(`this_section_could_not_render_try_again_or_reload_the_p_e644d5da`)}),children:(0,q.jsx)(K.Suspense,{fallback:(0,q.jsx)(`p`,{role:`status`,"aria-live":`polite`,className:`px-5 py-4 text-sm text-muted-foreground`,children:f(`workflow_run_loading`)}),children:(0,q.jsx)(i,{sessionId:e})})},e)]})})}function yF(e){return e?/Native canonical Session Source scope changed/i.test(e)?{title:f(`session_source_changed`),action:f(`session_source_changed_action`)}:/\blast_http_status=429\b|\bHTTP\s+429\b/i.test(e)?{title:f(`model_service_rate_limited_8b54cf50`),action:f(`the_provider_or_proxy_returned_429_wait_for_the_rate_li_b76133d9`)}:/\bStream timed out:\s*phase=bootstrap\b/i.test(e)?{title:f(`model_service_connection_timed_out_ecde837c`),action:f(`the_model_response_could_not_be_established_check_the_p_c6ee27c5`)}:null:null}var bF=()=>o(()=>import(`./RunDiagnosticsDialogContent-C83miiCb.js`),__vite__mapDeps([80,1,2,8,3,4,21,7,9,10,11,12,30,14,6,15,16,81,50]),import.meta.url);function xF({onClose:e,failed:t=!1}){let n=s();return(0,q.jsx)(cn,{open:!0,onOpenChange:t=>{t||e()},children:(0,q.jsxs)(on,{className:`gap-3 p-4 sm:pb-4`,children:[(0,q.jsx)(an,{children:n(`run_diagnostics_title`)}),(0,q.jsx)(sn,{children:n(t?`run_diagnostics_load_failed`:`loading_4927a53b`)}),(0,q.jsx)(W,{size:`sm`,variant:`secondary`,onClick:e,children:n(`cancel_2cd0f3be`)})]})})}function SF({subject:e,loadDialog:t=bF}){let n=s(),r=(0,K.useRef)(e),i=(0,K.useRef)(!0),a=(0,K.useRef)(null);r.current=e,(0,K.useEffect)(()=>(i.current=!0,()=>{i.current=!1,a.current=null}),[]);let o=()=>(0,K.lazy)(async()=>({default:(await t()).RunDiagnosticsDialogContent})),[c,l]=(0,K.useState)(o),[u,d]=(0,K.useState)(null),f=()=>{a.current=null,d(null)};return(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(W,{size:`sm`,variant:`outline`,onClick:()=>{let t={subject:e};a.current=t,l(o),d(t)},children:n(`run_diagnostics_open`)}),u&&u.subject===e?(0,q.jsx)(ue,{name:`Run diagnostics`,fallback:()=>(0,q.jsx)(xF,{failed:!0,onClose:f}),children:(0,q.jsx)(K.Suspense,{fallback:(0,q.jsx)(xF,{onClose:f}),children:(0,q.jsx)(c,{subject:u.subject,isCurrent:()=>i.current&&u!==null&&a.current===u&&r.current===u.subject,onClose:f})})}):null]})}var CF=e=>typeof e==`object`&&e&&!Array.isArray(e)?e:null,wF=e=>typeof e==`number`&&Number.isSafeInteger(e)&&e>=0,TF=e=>wF(e)&&e<=4294967295,EF=e=>e===null||TF(e),DF=e=>typeof e==`string`&&/^[a-f0-9]{64}$/.test(e),OF=e=>typeof e==`string`&&/^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/.test(e),kF=DF,AF=()=>{throw Error(`invalid_session_version_migration_response`)};function jF(e){let t=CF(e);return!t||!OF(t.operation_id)||!kF(t.birth_token)||!EF(t.expected_session_version)||!wF(t.expected_metadata_version)||!DF(t.expected_snapshot_sha256)?AF():{operation_id:t.operation_id,birth_token:t.birth_token,expected_session_version:t.expected_session_version,expected_metadata_version:t.expected_metadata_version,expected_snapshot_sha256:t.expected_snapshot_sha256}}function MF(e,t){let n=CF(e);if(!n||n.session_id!==t||!kF(n.birth_token)||!EF(n.session_version)||!TF(n.current_session_version)||!wF(n.metadata_version)||!DF(n.snapshot_sha256)||typeof n.eligible!=`boolean`||!Array.isArray(n.blockers)||n.blockers.length>32)return AF();let r=n.blockers.map(e=>{let t=CF(e);return!t||typeof t.code!=`string`||!t.code||typeof t.message!=`string`?AF():{code:t.code,message:t.message}});if(n.eligible&&r.length)return AF();let i=n.pending_operation==null?void 0:jF(n.pending_operation);return i&&i.birth_token!==n.birth_token?AF():{session_id:t,birth_token:n.birth_token,session_version:n.session_version,current_session_version:n.current_session_version,metadata_version:n.metadata_version,snapshot_sha256:n.snapshot_sha256,eligible:n.eligible,blockers:r,...i?{pending_operation:i}:{}}}function NF(e,t=!1){let n=t?e.pending_operation:e.eligible?{operation_id:crypto.randomUUID(),birth_token:e.birth_token,expected_session_version:e.session_version,expected_metadata_version:e.metadata_version,expected_snapshot_sha256:e.snapshot_sha256}:null;return n?Object.freeze({sessionId:e.session_id,targetVersion:e.current_session_version,request:Object.freeze(jF(n))}):AF()}function PF(e,t){let n=CF(e);return!n||n.status!==`committed`||n.session_id!==t.sessionId||n.operation_id!==t.request.operation_id||n.source_version!==t.request.expected_session_version||n.target_version!==t.targetVersion||n.before_sha256!==t.request.expected_snapshot_sha256||!DF(n.after_sha256)||n.birth_token!==t.request.birth_token?AF():{status:`committed`,session_id:t.sessionId,operation_id:t.request.operation_id,source_version:t.request.expected_session_version,target_version:t.targetVersion,before_sha256:n.before_sha256,after_sha256:n.after_sha256,birth_token:t.request.birth_token}}var FF=e=>`sessions/`+encodeURIComponent(e)+`/version-migration`,IF={async assess(e){return MF(await Ot.get(FF(e),{cache:`no-store`}),e)},async migrate(e){return PF(await Ot.postOnce(FF(e.sessionId),e.request),e)}},LF={assessment:null,reading:!1,submitting:!1,phase:`idle`,problem:null};function RF(e,t,n=!0,r=n){let[i,a]=(0,K.useState)(LF),o=(0,K.useRef)({sessionId:e,enabled:t});o.current={sessionId:e,enabled:t};let s=(0,K.useRef)(0),c=(0,K.useRef)(null),l=(0,K.useRef)(null),u=(0,K.useCallback)((e,t)=>o.current.enabled&&o.current.sessionId===e&&s.current===t,[]),d=(0,K.useCallback)(()=>{++s.current},[]),f=(0,K.useCallback)(async(e,t)=>{a(e=>({...e,reading:!0,problem:null}));try{let n=await IF.assess(e);if(!u(e,t))return;!l.current&&n.pending_operation&&(l.current=NF(n,!0)),a(e=>({...e,assessment:n,reading:!1}))}catch(n){if(!u(e,t))return;a(e=>({...e,reading:!1,problem:Ct(n)&&(n.status===404||n.status===501)?`unsupported`:`unavailable`}))}},[u]);(0,K.useEffect)(()=>(++s.current,l.current=null,c.current=null,a(LF),d),[e,t,d]),(0,K.useEffect)(()=>{t&&e&&r&&!c.current&&f(e,++s.current)},[e,t,r,f]);let p=(0,K.useCallback)(async()=>{!e||!t||c.current||await f(e,++s.current)},[e,t,f]),m=(0,K.useCallback)(async()=>{if(!e||!t||c.current||i.reading||i.phase===`committed`)return;let r=l.current;if(!r){if(!n||!i.assessment?.eligible)return;r=NF(i.assessment),l.current=r}if(r.sessionId!==e)return;let o=s.current,d=Symbol();c.current=d,a(e=>({...e,submitting:!0,problem:null}));let p=!1;try{let t=await IF.migrate(r);if(p=!0,!u(e,o))return;let n=Do(e),i=!1;try{let a=await zt.getSession(e),o=_o(a.session.execution_compatibility);if(a.session.id!==e||!o)throw Error(`migration_readback_unconfirmed`);if(!Oo(e,n,a))throw Error(`migration_readback_superseded`);if(i=!0,!o.execution_allowed||o.session_version!==t.target_version)throw Error(`migration_readback_unconfirmed`);let s=a.session.root_mode_birth_token;if(s==null){let n=await IF.assess(e);if(n.session_version!==t.target_version)throw Error(`migration_version_changed`);s=n.birth_token}if(s!==r.request.birth_token)throw Error(`migration_lifetime_changed`);if(!Oo(e,n,a))throw Error(`migration_readback_superseded`)}catch(t){throw i||ko(e,n),t}if(!u(e,o))return;l.current=null,a(e=>({...e,phase:`committed`,problem:null}))}catch(t){if(!u(e,o))return;let n=!p&&Ct(t)&&[400,401,403,404,409,412].includes(t.status);n&&(l.current=null),a(e=>({...e,phase:n?`error`:`unconfirmed`,problem:n?`rejected`:null})),n&&await f(e,o)}finally{c.current===d&&(c.current=null),u(e,o)&&a(e=>({...e,submitting:!1}))}},[e,t,n,i.assessment,i.reading,i.phase,u,f]);return{...i,canStart:n&&i.assessment?.eligible===!0,canRecover:l.current!==null,refresh:p,migrate:m}}function zF({sessionId:e,enabled:t,allowNewMigration:n=!0,autoAssess:r=n,hideIdle:i=!1,className:a=``}){u();let o=RF(e,t,n,r);if(!t||o.problem===`unsupported`)return null;let s=o.reading||o.submitting||o.canRecover||o.phase===`unconfirmed`||o.phase===`error`||o.problem!==null;if(i&&(o.phase===`committed`||!s))return null;let c=o.assessment?.blockers.filter(e=>e.code!==`already_current`)??[];return(0,q.jsx)(`div`,{className:`mt-2 space-y-1 text-xs ${a}`,"data-testid":`session-version-migration`,children:o.phase===`committed`?(0,q.jsx)(`p`,{role:`status`,children:f(`session_migration_completed`)}):(0,q.jsxs)(q.Fragment,{children:[o.canStart?(0,q.jsx)(`p`,{className:`text-muted-foreground`,children:f(`session_migration_preserves_context`)}):null,o.phase===`unconfirmed`?(0,q.jsx)(`p`,{role:`status`,children:f(`session_migration_unconfirmed`)}):null,o.problem||o.phase===`error`?(0,q.jsx)(`p`,{role:`status`,children:f(o.phase===`error`?`session_migration_rejected`:`session_migration_read_error`)}):null,c.length?(0,q.jsxs)(`details`,{children:[(0,q.jsx)(`summary`,{children:f(`session_migration_blocked`)}),(0,q.jsx)(`ul`,{className:`mt-1 space-y-1`,children:c.map((e,t)=>(0,q.jsx)(`li`,{children:e.message},e.code+t))})]}):null,(0,q.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[o.canStart||o.canRecover?(0,q.jsx)(W,{size:`sm`,variant:`outline`,disabled:o.reading||o.submitting,onClick:()=>void o.migrate(),children:f(o.submitting?`session_migration_in_progress`:o.canRecover?`session_migration_confirm_result`:`session_migration_action`)}):null,(0,q.jsx)(W,{size:`sm`,variant:`ghost`,disabled:o.reading||o.submitting,onClick:()=>void o.refresh(),children:f(`session_migration_refresh`)})]})]})})}var BF={unsupported_session_version:`session_compatibility_version_conflict`,session_version_mismatch:`session_compatibility_observation_conflict`,unsupported_runtime_state_version:`session_compatibility_runtime_conflict`,unsupported_model_context_version:`session_compatibility_context_conflict`};function VF({state:e,sessionId:t}){if(u(),!e)return null;let n=e.report,r=e.blocked||e.readError||e.observed&&n?.status===`legacy_compatible`,i=e.observed&&!e.loading&&!e.readError&&!e.blocked&&n?.status===`legacy_compatible`&&n.execution_allowed;return(0,q.jsxs)(q.Fragment,{children:[r?(0,q.jsxs)(`section`,{className:`border-b px-3 py-2 text-sm`,"aria-label":f(`session_compatibility_label`),"data-session-execution-blocked":e.blocked,children:[(0,q.jsx)(`p`,{role:e.blocked?`alert`:`status`,className:e.blocked?`font-medium text-destructive`:`text-muted-foreground`,children:f(e.blocked?`session_compatibility_execution_blocked`:n?.status===`legacy_compatible`?`session_compatibility_legacy_compatible`:e.legacy?`session_compatibility_legacy_unassessed`:`session_compatibility_unassessed`)}),n?(0,q.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:f(`session_compatibility_versions`,{session:n.session_version??f(`session_compatibility_unmarked`),current:n.current_session_version})}):null,e.blocked?(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(`p`,{className:`mt-1 text-xs`,children:f(`session_compatibility_recovery`)}),n?.conflicts.map((e,t)=>(0,q.jsxs)(`div`,{className:`mt-1 text-xs`,children:[(0,q.jsx)(`p`,{children:f(BF[e.code]??`session_compatibility_other_conflict`)}),(0,q.jsxs)(`details`,{children:[(0,q.jsx)(`summary`,{children:f(`session_compatibility_diagnostic`)}),(0,q.jsxs)(`p`,{className:`break-words`,children:[e.code,`: `,e.message]})]})]},`${e.code}-${t}`))]}):null,e.readError?(0,q.jsx)(`p`,{role:`status`,className:`mt-1 text-xs`,children:f(`session_compatibility_read_error`)}):null,(0,q.jsx)(W,{size:`sm`,variant:`ghost`,disabled:e.loading,onClick:()=>void e.refresh(),children:f(`session_compatibility_refresh`)})]}):null,t?(0,q.jsx)(zF,{sessionId:t,enabled:!0,autoAssess:i,allowNewMigration:i,hideIdle:!r,className:`mx-4 mb-2`},t):null]})}var HF=class extends Error{kind;constructor(e,t){super(e,t),this.kind=e,this.name=`NewChatWorktreePreparationError`}};function UF(e,t){return e.project_path===t||(e.workspace_bindings??[]).some(e=>e.path===t)}var WF=class{projectId;changed;dependencies;selection=null;path=null;busy=!1;uncertain=!1;error=null;constructor(e,t,n={getProject:e=>Vt.getProject(e),create:(e,t)=>Pe.create(e,t),bindWorkspace:(e,t,n)=>H.getState().bindWorkspace(e,t,n)}){this.projectId=e,this.changed=t,this.dependencies=n}get locked(){return this.busy||this.path!==null||this.uncertain}select(e){this.locked||(this.selection=e?Object.freeze({...e}):null,this.error=null,this.changed())}async prepare(e){if(this.busy)throw new HF(`failed`);if(this.uncertain)throw this.error??new HF(`uncertain`);let t=this.selection;if(!this.projectId?.trim()||!t||[t.repository,t.root,t.name,t.branch].some(e=>typeof e!=`string`||!e.trim())||!/^[A-Za-z0-9_-]{1,80}$/.test(t.name)||!/^(?:\/|[A-Za-z]:[\\/]|\\\\[^\\]+\\[^\\]+)/.test(t.root)||[`\0`,`\r`,`
|
|
112
|
+
`].some(e=>t.root.includes(e))||t.branch===`HEAD`||t.branch.startsWith(`-`))throw this.error=new HF(`invalid`),this.changed(),this.error;let n=()=>{if(!e())throw new HF(`context-changed`)};this.busy=!0,this.error=null,this.changed();try{n();let e=await this.dependencies.getProject(this.projectId);if(n(),e.id!==this.projectId||e.status!==`active`)throw new HF(`invalid`);if(!this.path){try{let e=await this.dependencies.create(this.projectId,{...t});if(typeof e?.path!=`string`||!e.path.trim())throw new HF(`uncertain`);this.path=e.path,this.changed()}catch(e){throw this.uncertain=!0,new HF(`uncertain`,{cause:e})}n(),e=await this.dependencies.getProject(this.projectId),n()}if(e.id!==this.projectId||e.status!==`active`)throw new HF(`invalid`);if(!UF(e,this.path)&&(e=await this.dependencies.bindWorkspace(this.projectId,e.revision,{path:this.path}),e.id!==this.projectId||!UF(e,this.path)))throw new HF(`failed`);return n(),this.path}catch(e){throw this.error=e instanceof HF?e:new HF(`failed`,{cause:e}),this.error}finally{this.busy=!1,this.changed()}}},GF=(0,K.lazy)(()=>o(()=>import(`./NewChatWorktreeControl-BVvX1tE3.js`).then(e=>({default:e.NewChatWorktreeControl})),__vite__mapDeps([82,1,2,3,4,31,6,32,11,15,12,10,33,34,83,7,8,5,9]),import.meta.url));function KF(e){if(!e)return null;switch(e.kind){case`invalid`:return f(`chat_worktree_invalid_config`);case`uncertain`:return f(`chat_worktree_uncertain`);case`context-changed`:return f(`chat_worktree_context_changed`);default:return f(`chat_worktree_prepare_failed`)}}var qF=332,JF=1484;function YF(e){return new Promise((t,n)=>{let r=new FileReader;r.onload=()=>{let n=String(r.result),i=n.includes(`,`)?n.slice(n.indexOf(`,`)+1):n;t({id:`${e.name}-${e.size}-${n.length}`,base64:i,name:e.name,type:e.type,size:e.size,url:n})},r.onerror=()=>n(r.error),r.readAsDataURL(e)})}function XF({chat:e,pickedWorkspace:t,worktreePath:n,pendingProjectId:r,onNewSessionInProjectSection:i,newChatEpoch:a=0,getNavigationVersion:o,onSelectProject:s,onOpenWorkspacePicker:c,onOpenInspector:l,onOpenReview:d,workPanelTarget:p,onOpenWork:m,onWorkReference:h,sidePaneOpen:g,onToggleSidePane:_,splitOpen:y,onToggleSplit:b,onSelectSubAgent:x,onOpenSidebar:S,sidebarCollapsed:C,secondary:w,pageVisible:T=!0}){u();let E=!!w?.historyRead&&w.historyRead.status!==`ready`,{chats:k,currentSessionId:A,currentChat:j,messages:M,streaming:N,streamPhase:P,streamingReasoning:F,liveSegments:I,streamStatus:ee,contextCompression:L,outputRate:te,pendingUserText:R,pendingUserImages:ne=[],pendingUserMessages:re,sending:ie,submissionPending:ae,select:oe,send:se,stop:le,deleteMessage:ue,fork:de,regenerate:fe,editMessage:pe,retry:he,sendFailure:ge,pendingQuestion:_e,questionLoading:ve,questionSubmitting:Ce,questionUnavailable:Te,questionError:Ee,questionCanRetry:z,refreshQuestion:De,retryQuestion:B,pendingApproval:Oe,answerQuestion:ke,respondApproval:V}=e,Ae=e.executionCompatibility?.blocked===!0,je=j?.lastRunStatus===`suspended`&&j?.isRunning!==!0&&cp((j?.messages??[]).map(e=>({metadata:e.metadata,content:`content`in e?e.content:void 0}))),Me=j?.isRunning===!0||ie&&N!==null||je,Ne=H(e=>A?e.managedHistoryBindings?.[A]?.status===`stale`:!1),Pe=ge?.sessionId===A?ge:null,Fe=!Pe&&!Me&&j?.lastRunStatus===`error`?j.lastRunError?.trim()||f(`generation_failed_the_server_provided_no_error_details_d70c7744`):null,Ie=Pe?.kind===`generation-failed`||Fe!==null,Le=Pe?.message?.trim()||(Ie&&j?.lastRunStatus===`error`?j.lastRunError?.trim()||Fe:null),Re=Ie?yF(Le):null,ze=(0,K.useMemo)(()=>({sessionId:A,localOperationId:Pe?.operationId??null,failureKind:Pe?.kind??`generation-failed`,diagnosticId:Hn(Le),errorBinding:Le,liveDiagnostic:Pe?.kind===`generation-failed`?Pe.diagnostic:null}),[A,Pe,Le]),Be=$h(A,Me),Ve=Lp(A,j?.kind),Ue=bp(A,Me,Ve.isRoot),We=()=>{Ue.cancelForStop(),le()},Ge=`${Ve.authority?.birthToken??``}:${Ve.authority?.epoch??``}:${Ve.authority?.enabled??``}`,Ke=Ve.loading&&!Ve.authority&&!Ve.unsafe,qe=ug(A,Ge,Ve.unsafe,Ke),Je=_g(A),Ye=qe.state?.current.scope,Xe=Je.hasPending(A),Ze=qe.negotiated===!1||Xe||Ye?.capabilities?.semantic_messages_v1===!0&&Ye.mutation_enabled===!0&&Ye.binding.supervisor_session_id===A,[Qe,$e]=(0,K.useState)(null),[et,tt]=(0,K.useState)(null),rt=(0,K.useMemo)(()=>({currentSessionId:A}),[A]),[it,at]=(0,K.useState)(null),ot=(0,K.useCallback)(()=>{if(!it||it.scope!==rt||T===!1)return;let e=p?.querySelector(`[data-testid="ticket-work-overview"]`);if(!e)return;let t=document.activeElement;(!t?.matches(`input, textarea, [contenteditable="true"]`)||p?.contains(t))&&e.focus(),at(null)},[it,rt,p,T]),st=e=>{tt(e),m?.(),at({scope:rt})};(0,K.useEffect)(()=>{if(!it)return;if(it.scope!==rt||T===!1){at(null);return}let e=()=>at(null);document.addEventListener(`pointerdown`,e,!0),document.addEventListener(`keydown`,e,!0);let t=requestAnimationFrame(ot);return()=>{cancelAnimationFrame(t),document.removeEventListener(`pointerdown`,e,!0),document.removeEventListener(`keydown`,e,!0)}},[it,rt,p,T,Ye?.binding.supervisor_session_id,ot]);let ct=Je.references(A),dt=Xe&&ct?.in_reply_to?{work_id:ct.thread_id??ct.in_reply_to,id:ct.in_reply_to}:Qe;(0,K.useEffect)(()=>{at(null),$e(null),tt(null)},[A]);let ft=ef(`(min-width: 768px)`),[mt,ht]=vi(),gt=ht>=JF;yf(T&&(!w||ft)?j:null);let[_t,vt]=(0,K.useState)(`auto`),yt=(0,K.useId)();(0,K.useEffect)(()=>{vt(`auto`)},[A]);let bt=_t===`open`||_t===`auto`&>,xt=!w&&bt&&!(g??!1),St=xt&>?qF:0,Ct=H(e=>A?e.tokenUsages[A]:void 0)??j?.config?.tokenUsage,U=A??(w?`__new_chat_pane2__`:``),wt=H(e=>e.inputStates[U]?.content??``),Tt=(0,K.useRef)(null),Et=(0,K.useRef)(!1),[Ot,kt]=(0,K.useState)(!1),At=(0,K.useRef)(!0);(0,K.useEffect)(()=>(At.current=!0,()=>{At.current=!1}),[]);let jt=(0,K.useRef)(U);jt.current=U;let Mt=e=>{let t=H.getState(),n=t.inputStates[U]?.content??``;t.setInputContent(U,typeof e==`function`?e(n):e)},Nt=Sp(w?.chats??k,w?.onPickSession??oe),[Pt,Ft]=(0,K.useState)(!1),[It,Lt]=(0,K.useState)(!1),Rt=(0,K.useRef)(!1),[Bt,Vt]=(0,K.useState)(null),[Ht,G]=(0,K.useState)([]),[Ut,Wt]=(0,K.useState)(null),[Gt,Kt]=(0,K.useState)(null),[qt,Jt]=(0,K.useState)(null),[Yt,Xt]=(0,K.useState)(null),[Zt,Qt]=(0,K.useState)(null),[$t,en]=(0,K.useState)(null);(0,K.useEffect)(()=>{en(null)},[A]);let[tn,nn]=(0,K.useState)([]),rn=(0,K.useRef)(0),an=(0,K.useRef)(0),on=(0,K.useRef)(0),sn=e=>{rn.current+=1,nn(e)},cn=e=>{an.current+=1,Vt(e)},ln=e=>{on.current+=1,e||en(null),Wt(e),Xt(null),e&&(Kt(null),Qt(null))},un=e=>{on.current+=1,Kt(e),Qt(null),Xt(null),e||Jt(null),e&&(Wt(null),cn(null))};(0,K.useEffect)(()=>{on.current+=1,Kt(null),Qt(null),Jt(null),Xt(null)},[A]);let[dn,fn]=(0,K.useState)(null),[mn,_n]=(0,K.useState)(null),[vn,yn]=(0,K.useState)(!1),bn=(0,K.useMemo)(()=>({sessionId:A}),[A]),xn=(0,K.useRef)(bn);xn.current=bn,(0,K.useEffect)(()=>{_n(null),yn(!1)},[A]);let Sn=(0,K.useRef)(0),Cn=(e,t=`info`,n)=>{xn.current===bn&&_n({id:++Sn.current,message:e,kind:t,details:n})},{scrollRef:wn,contentRef:Tn,atBottom:En,handleScroll:Dn,scrollToBottom:On,pinToBottom:kn}=Mp(A),An=async e=>{let t=Array.from(e).filter(e=>e.type.startsWith(`image/`));if(t.length===0)return;let n=await Promise.all(t.map(YF));sn(e=>[...e,...n])},jn=H(Yr(e=>e.skills)),Mn=Gp(j,k,H(Yr(e=>pt(A)(e))),T&&(!w||ft)),Nn=Mn.agents,Pn=nt(e=>e.providerSnapshot),Fn=nt(e=>e.providerStatus),In=j?.config?.model_ref?.provider??Pn?.defaults?.chat.provider??Pn?.default_provider_instance_id,Ln=Pn?.instances.find(e=>e.id===In),Rn=(0,K.useMemo)(()=>Fn===`ready`&&Ln?.enabled?ut(Ln,Pn?.defaults):[],[Fn,Ln,Pn?.defaults]),zn=H(e=>e.selectedModel),Bn=H(e=>e.setSelectedModel),Vn=H(e=>e.changeSessionModel),Un=nt(e=>e.providerSnapshot?.defaults?.chat?.model),Wn=nt(e=>e.providerSnapshot?.defaults?.chat?.reasoning_effort),Gn=H(e=>e.inputStates[U]?.reasoningEffort),Kn=A?j?.config?.reasoningEffort??j?.config?.model_ref?.reasoning_effort??`auto`:Gn??Wn??`auto`,qn=H(e=>e.clearInputReasoningEffort),Jn=Up({sessionId:A,draftKey:U,ordinarySelection:Kn,root:Ve,disabled:ae||Me||Be.busy||Be.hasUnconfirmed}),Xn=()=>Jn.busy||Jn.blocked||!!(A&&dc(A)!==`clear`),Zn=Bt&&Jn.selected===!0&&!Jn.child?f(`the_selected_skill_is_incompatible_with_ultra_orchestra_fd2e7fa6`):null,Qn=A?j?.config?.model_ref?.model||j?.config?.model||Un||``:lt(Pn,zn)?.model||``,[$n,er]=(0,K.useState)(!1),tr=$n||Me||ae||Be.busy||Be.hasUnconfirmed,nr=async e=>{if(!(tr||e===Qn)){if(!A){Bn(e);return}er(!0);try{await Vn(A,e)}catch(e){jt.current===A&&Cn(f(`could_not_save_the_model_please_try_again_631991a6`),`error`,Dt(e))}finally{er(!1)}}},[rr,ir]=(0,K.useState)(!1),or=(0,K.useRef)({key:U,text:wt});(0,K.useEffect)(()=>{let e=or.current.key!==U||or.current.text!==wt;or.current={key:U,text:wt},e&&rr&&ir(!1)},[wt,U,rr]);let sr=!rr&&wt.startsWith(`/`)?wt.slice(1):null,lr=gn(A,sr!==null||qt!==null),[ur,dr]=(0,K.useState)(!1),[fr,pr]=(0,K.useState)(null),mr=ae||Me||Be.hasUnconfirmed||Jn.unsafe;(0,K.useEffect)(()=>{qt===`environment`&&!xt&&Jt(`composer`)},[qt,xt]);let hr=e=>{ir(!0),Jt(e)},gr=()=>{if(!Gt||mr)return;let e=Gt;un(null),Xt({draft:e,revision:on.current}),Tt.current?.focus()},[vr,yr]=(0,K.useState)(null),br=j?.config?.workspacePath,xr=H(e=>r?e.projects[r]?.project_path:void 0),[,Sr]=(0,K.useState)(0),Cr=(0,K.useRef)({epoch:a,entries:new Map});Cr.current.epoch!==a&&(Cr.current={epoch:a,entries:new Map});let wr=JSON.stringify([r??null,t,n??null]),Tr=Cr.current.entries.get(wr);Tr||(Tr=new WF(r??null,()=>{At.current&&Sr(e=>e+1)}),Cr.current.entries.set(wr,Tr));let Er=(0,K.useMemo)(()=>({currentSessionId:A,pendingProjectId:r,pickedWorkspace:t,worktreePath:n,selectedProjectPath:xr,newChatEpoch:a}),[A,r,t,n,xr,a]),Dr=(0,K.useRef)(Er);Dr.current=Er;let Or=(0,K.useRef)(se);Or.current=se;let kr=A?null:Tr.path??n,Ar=br??kr??xr??t,jr=H(e=>{let t=j?.config?.projectId;return t?e.projects[t]?.name:void 0}),Mr=(0,K.useMemo)(()=>ui(M),[M]),Nr=(0,K.useMemo)(()=>di(I),[I]),Pr=(0,K.useMemo)(()=>fi(Mr,Nr),[Mr,Nr]),Ir=(0,K.useMemo)(()=>{let e=new Set,t=0,n=0;for(let r of Pr){e.add(r.payload.file_path);let i=li(r.payload);t+=i.added,n+=i.removed}return{changedFiles:e.size,addedLines:t,removedLines:n}},[Pr]),Lr=(0,K.useMemo)(()=>{let e=new Map,t=t=>{let n=t.split(/[\\/]/).filter(Boolean).at(-1)??t;e.set(`file:${t}`,{id:`file:${t}`,name:n,kind:`file`})};for(let n of M){if(`images`in n)for(let t of n.images??[]){let n=t.url??(t.base64?t.base64.startsWith(`data:`)?t.base64:`data:${t.type||`image/png`};base64,${t.base64}`:void 0);e.set(`image:${t.id}`,{id:`image:${t.id}`,name:t.name,kind:`image`,previewUrl:n})}if(`type`in n&&n.type===`file_reference`)for(let e of n.paths)t(e)}for(let t of tn)e.set(`draft:${t.id}`,{id:`draft:${t.id}`,name:t.name,kind:`image`,previewUrl:t.url});return[...e.values()]},[tn,M]),[Rr,zr]=(0,K.useState)([]),Br=(0,K.useRef)(null);(0,K.useEffect)(()=>{Br.current=null,zr([])},[Ar]);let Vr=vr!==null;(0,K.useEffect)(()=>{if(!Vr||!Ar||Br.current===Ar)return;let e=!1,t=Ar;return uo.listWorkspaceFiles(t).then(n=>{e||(Br.current=t,zr(n))}).catch(()=>{e||zr([])}),()=>{e=!0}},[Vr,Ar]);let Hr=(0,K.useRef)(!1);(0,K.useEffect)(()=>{sr===null||Hr.current||(Hr.current=!0,O.listCommands().then(e=>G((e.commands??[]).filter(e=>e.type===`workflow`))).catch(()=>{}))},[sr]);let Ur=()=>{if(Et.current||Ae||wo(A)||E||ae||$n||Be.busy||Je.busy||Jn.busy||Rt.current)return;if(Ze&&!qe.canSendIngress){Cn(f(`ticket_the_ticket_connection_or_write_permission_is__c3da124f`),`error`);return}if(Xn()){en(f(`the_root_permission_change_is_unconfirmed_sending_and_e_a75a6b4f`));return}let e=H.getState(),n=e.inputStates[U],a=n?.content??``,s=!Ut&&!Gt&&!Bt&&tn.length===0?/^\/goal(?:\s+([\s\S]*))?$/i.exec(a.trim()):null;if(s&&!Xe&&(A||!s[1]?.trim())){if(!A){Cn(f(`open_a_session_before_setting_a_goal_83867da8`));return}let t=n?.contentRevision??0;if(!s[1]?.trim()){l(),e.setInputContentIfRevision(U,t,``);return}let r=A;if(dc(r)!==`clear`){en(f(`the_root_permission_change_is_unconfirmed_sending_and_e_a75a6b4f`));return}Rt.current=!0,Lt(!0),zt.sendMessage({message:a.trim(),session_id:r,model:j?.config?.model??``}).then(async e=>{if(e.session_id!==r||!e.goal_command)throw Error(`Goal command was not acknowledged`);if(Ms(r),H.getState().setInputContentIfRevision(U,t,``),jt.current===U){let t=e.goal_command.action;Cn(f(t===`off`?`goal_paused_c6289896`:t===`clear`?`goal_cleared_0cfc707e`:t===`on_no_prompt`?`set_a_goal_first_cc87f18f`:t===`status`?`goal_settings_opened_63de7dc7`:`goal_set_724a547c`)),(t===`status`||t===`on_no_prompt`)&&l()}try{await H.getState().loadChatHistory(r)}catch{}if(e.goal_command.should_execute){if(dc(r)!==`clear`){jt.current===U&&Cn(f(`root_permissions_are_unconfirmed_the_goal_was_saved_but_bd40481a`),`error`);return}if(wo(r))return;try{await zt.execute(r,j?.config?.model)}catch(e){Ao(r,e),jt.current===U&&Cn(f(`goal_saved_send_a_message_to_continue_ba844fbc`),`error`,Dt(e))}}}).catch(e=>{Ao(r,e),jt.current===U&&Cn(f(`could_not_save_the_goal_your_command_is_preserved_pleas_ac375306`),`error`,Dt(e))}).finally(()=>{Rt.current=!1,Lt(!1)});return}if(!a.trim()&&tn.length===0&&!Ut)return;let c=null;if(Gt){if(Me||Be.hasUnconfirmed){Qt(f(`wait_for_the_current_run_to_finish_before_sending_the_s_8a1c6253`));return}try{c=hn(Gt)}catch(e){Qt(Dt(e));return}}if(Ut&&!Jn.child&&(Jn.selected===!0||A&&Jn.selected===null)){en(f(`the_selected_text_workflow_is_incompatible_with_ultra_o_b46c71ea`));return}if(en(null),Qt(null),(Me||Be.hasUnconfirmed)&&Bt){Cn(f(`remove_the_selected_skill_before_queueing_the_message_e38f6811`));return}let u=Object.freeze({draftKey:U,draftRevision:n?.contentRevision??0,attachmentRevision:rn.current,skillRevision:an.current,workflowRevision:on.current,text:a,attachments:Object.freeze(tn.map(e=>Object.freeze({...e}))),selectedSkill:Bt?Object.freeze({...Bt,tool_refs:[...Bt.tool_refs]}):null,selectedWorkflow:Ut?Object.freeze({...Ut}):null,typedWorkflow:c?Object.freeze(c):null,workspacePath:kr??xr??t,projectId:r??null,templatePrompt:!A&&!w?rc():null,permissionMode:A?null:lF.getState().mode,rootOrchestrationOnly:!A&&n?.thinkingMode!==void 0?n.thinkingMode===`ultra`:Jn.requestValue,thinkingMode:A?void 0:n?.thinkingMode,thinkingModeRevision:A?void 0:n?.thinkingModeRevision,reasoningSelection:A?void 0:Gn}),d=u.selectedWorkflow?`${u.selectedWorkflow.content}${a.trim()?`\n\n${a.trim()}`:``}`:a,p=u.attachments.map(e=>({base64:e.base64,name:e.name,size:e.size,type:e.type}));if(Ze&&(u.selectedSkill||u.selectedWorkflow||u.typedWorkflow)){Cn(f(`ticket_enter_ticket_instructions_directly_in_the_mes_2bddd839`));return}let m=Qe,h=!A&&!w&&Tr.selection!==null,g=o?.(),_=()=>At.current&&Dr.current===Er&&Or.current===se&&(!!w||H.getState().currentSessionId===A)&&o?.()===g,v=e=>{let t=t=>se(d,{skillIds:u.selectedSkill?[u.selectedSkill.id]:void 0,...u.typedWorkflow?{workflowSelection:u.typedWorkflow}:{},images:p.length?p:void 0,workspacePath:e,projectId:u.projectId,templatePrompt:u.templatePrompt,permissionMode:u.permissionMode??void 0,rootOrchestrationOnly:u.rootOrchestrationOnly,thinkingMode:u.thinkingMode,reasoningSelection:u.reasoningSelection,...h?{isOriginCurrent:_}:{},...t?{liveBootstrapResume:!0}:{}}),n=Ue.prepareInitial();return typeof n==`boolean`?t(n):n.then(e=>_()?t(e):{kind:`blocked`})};Et.current=!0,(Ze&&A?Je.send({session_id:A,message:d,model:Qn,model_ref:j?.config.model_ref??void 0,images:p.length?p:void 0,...m?{thread_id:m.work_id,in_reply_to:m.id}:{}}):A&&(Me||Be.hasUnconfirmed)?Be.send(d,p):h?(async()=>{kt(!0);try{let e=await Tr.prepare(_);if(!_())throw new HF(`context-changed`);return await v(e)}catch(e){return _()&&Cn(KF(e instanceof HF?e:null)??f(`chat_worktree_prepare_failed`),`error`),{kind:`blocked`}}finally{At.current&&kt(!1)}})():v(u.workspacePath)).then(e=>{if(h&&e.kind!==`accepted`&&!_())return;if(A&&!Jn.child&&!Me&&!Be.hasUnconfirmed&&e.kind!==`busy`&&e.kind!==`ignored`&&e.kind!==`blocked`&&Jn.refresh(A),e.kind===`unconfirmed`){e.workflowError&&jt.current===u.draftKey&&Qt(f(`your_draft_and_selection_are_preserved_a3485200`,{v0:{root_orchestration_incompatible_mode:f(`the_selected_workflow_is_incompatible_with_ultra_orches_de35fdd7`),workflow_revision_missing:f(`the_selected_workflow_is_no_longer_available_refresh_th_7bd9ac1f`),workflow_revision_mismatch:f(`the_selected_workflow_revision_has_changed_refresh_the__bcef1f66`),workflow_source_mismatch:f(`the_selected_workflow_source_has_changed_refresh_the_ca_8af8563c`),workflow_manual_only:f(`this_workflow_cannot_be_selected_explicitly_select_anot_78f7dbdc`),workflow_selection_invalid:f(`the_workflow_or_arguments_do_not_match_the_current_defi_0bb6277d`),workflow_snapshot_unavailable:f(`bamboo_cannot_preserve_the_selected_workflow_definition_43555a20`),workflow_snapshot_too_large:f(`the_workflow_definition_exceeds_bamboo_s_snapshot_budge_0dc8f7de`),workflow_context_invalid:f(`bamboo_cannot_prepare_the_workflow_context_check_the_ar_83c4fc3e`)}[e.workflowError.code]??f(`workflow_not_accepted`),v1:e.workflowError.code,v2:e.workflowError.message})),jt.current===u.draftKey&&Tt.current?.focus();return}if(e.kind!==`accepted`||h&&(!At.current||o?.()!==g||!e.navigated&&!_()))return;m&&$e(e=>e?.id===m.id?null:e),!A&&u.projectId&&i&&i(e.sessionId);let t=H.getState();if(!t.setInputContentIfRevision(u.draftKey,u.draftRevision,``)&&e.navigated&&u.draftKey!==e.sessionId){let t=H.getState(),n=t.inputStates[u.draftKey]?.contentRevision??0;t.moveInputContentIfRevision(u.draftKey,n,e.sessionId)}e.navigated&&u.draftKey!==e.sessionId&&(u.thinkingModeRevision!==void 0&&t.clearInputThinkingModeIfRevision(u.draftKey,u.thinkingModeRevision),H.getState().inputStates[u.draftKey]?.reasoningEffort===u.reasoningSelection&&qn(u.draftKey)),rn.current===u.attachmentRevision&&nn([]),an.current===u.skillRevision&&Vt(null),on.current===u.workflowRevision&&(Wt(null),Kt(null),Xt(null),Jt(null))}).catch(e=>{console.error(`[ChatPane] submission coordinator failed`,e),jt.current===u.draftKey&&Tt.current?.focus()}).finally(()=>{Et.current=!1}),kn()},Wr=e=>{un(null),cn(e),Mt(``)},Gr=e=>{let t=++on.current;Mt(``),O.getWorkflowCommand(e.name).then(n=>{on.current===t&&ln({name:e.display_name||e.name,content:n.content})}).catch(n=>{on.current===t&&Cn(f(`could_not_load_workflow_ed648068`,{v0:e.name}),`error`,Dt(n))})},Kr=e=>{if(Xn()){en(f(`the_root_permission_change_is_unconfirmed_forking_is_un_ca51f044`));return}let t=jt.current;yn(!0),de(e).then(e=>{xn.current===bn&&yn(!1),e?xn.current===bn?Cn(f(`forked_into_a_new_session_from_here_b0abc6b8`)):jt.current===e&&_n(e=>e??{id:++Sn.current,kind:`info`,message:f(`forked_into_a_new_session_from_here_b0abc6b8`)}):jt.current===t&&Cn(f(`could_not_fork_this_backend_does_not_support_session_fo_006caf5c`),`error`)}).catch(e=>{xn.current===bn&&yn(!1),Cn(f(`operation_failed_0c3b4cf7`),`error`,Dt(e))})},qr=e=>{e()},Jr=x??w?.onPickSession??oe,Xr=[...A?[{label:f(`conversation_clear_action`),icon:(0,q.jsx)(ce,{className:`size-4`}),onClick:()=>pr({id:A,title:j?.title||A})}]:[],...A?[{label:f(`workflow_run_title`),icon:(0,q.jsx)(ar,{className:`size-4`}),onClick:()=>dr(!0)}]:[],...A&&M.length>0?[{label:f(`export_as_markdown_ac8b027c`),icon:(0,q.jsx)(v,{className:`size-4`}),onClick:()=>kp(M,j?.title||`chat`)},{label:f(`export_as_pdf_e42c8735`),icon:(0,q.jsx)(_r,{className:`size-4`}),onClick:()=>void jp(M,j?.title||`chat`)}]:[],{label:f(y?`close_side_by_side_comparison_2b7637f6`:`compare_side_by_side_a17b7763`),icon:(0,q.jsx)(Yn,{className:`size-4`}),onClick:()=>qr(b)}],Zr=e=>(0,q.jsx)(gF,{sessionId:A,variant:e,selected:Gt,onChange:un,onRemove:gr,open:qt===e,onOpenChange:t=>{t?hr(e):(Jt(null),ir(!0))},catalogState:lr,onArgsFocus:()=>ir(!0),onReturnFocus:()=>Tt.current?.focus(),disabled:mr,error:Zt},`${A??`new`}:${e}`),Qr=!w&&A?(0,q.jsx)(Qp,{id:yt,workspace:Ar,projectName:jr,workflowControl:Zr(`environment`),placement:j?.placement,changedFiles:Ir.changedFiles,addedLines:Ir.addedLines,removedLines:Ir.removedLines,sources:Lr,onOpenReview:()=>qr(d??l),onPreviewImage:fn}):null;return(0,q.jsxs)(q.Fragment,{children:[(0,q.jsxs)(`div`,{className:`relative flex min-w-0 flex-1 flex-col`,"data-session-drop-target":w?`secondary`:`main`,...Nt.handlers,onDragOver:e=>{e.dataTransfer.types.includes(`Files`)&&(e.preventDefault(),Ft(!0))},onDragLeave:e=>{e.currentTarget===e.target&&Ft(!1)},onDrop:e=>{e.preventDefault(),Ft(!1),e.dataTransfer.files.length&&An(e.dataTransfer.files)},children:[Pt||Nt.active?(0,q.jsx)(`div`,{className:`pointer-events-none absolute inset-0 z-[60] m-3 flex items-center justify-center rounded-2xl border-2 border-dashed border-primary bg-primary/10 text-sm font-medium text-primary`,children:f(Nt.active?`drop_to_open_session`:`drop_to_add_images_6ccb05f2`)}):null,w?(0,q.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2 border-b px-3 py-2`,children:[(0,q.jsxs)(we,{value:w.sessionId??void 0,onValueChange:e=>w.onPickSession(e||null),children:[(0,q.jsx)(be,{size:`sm`,className:`min-w-0 flex-1`,children:(0,q.jsx)(ye,{placeholder:f(`select_a_session_to_compare_74d69a72`)})}),(0,q.jsx)(xe,{children:w.chats.filter(e=>!e.parentSessionId||e.id===w.sessionId).map(e=>(0,q.jsx)(Se,{value:e.id,children:e.title||f(`new_session_c57c30bc`)},e.id))})]}),A?(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(W,{size:`icon`,variant:`ghost`,"aria-label":f(`workflow_run_title`),onClick:()=>dr(!0),children:(0,q.jsx)(ar,{className:`size-4`})}),(0,q.jsx)(W,{size:`icon`,variant:`ghost`,"aria-label":f(`inspector_fc48a7f2`),onClick:()=>qr(l),children:(0,q.jsx)(Fr,{})})]}):null,w.hideClose?null:(0,q.jsx)(W,{size:`icon`,variant:`ghost`,"aria-label":f(`close_pane_1cd5deec`),onClick:w.onClose,children:(0,q.jsx)(He,{})})]}):(0,q.jsx)($p,{title:j?.title||`Bodhi`,hasSession:!!A,overflowItems:Xr,onOpenSidebar:S,environment:(0,q.jsx)(Xp,{open:xt,controlsId:yt,onToggle:()=>vt(bt?`closed`:`open`)}),sidePaneOpen:g??!1,onToggleSidePane:()=>qr(_??l),sidebarCollapsed:C,supervisorControl:j&&Ka(j)&&Ye?.binding.supervisor_session_id===A?(0,q.jsx)(Sg,{controller:qe,running:Me,onSelectWork:m?st:void 0}):null}),(0,q.jsxs)(`div`,{ref:mt,"data-chat-layout":!0,className:`relative flex min-h-0 min-w-0 flex-1`,children:[(0,q.jsxs)(`div`,{"data-chat-body":!0,className:`relative flex min-w-0 flex-1 flex-col`,style:{paddingInlineEnd:St,transition:`padding-inline-end 200ms ease-out`},"data-session-drop-target":w?`secondary`:`main`,...Nt.handlers,children:[(0,q.jsx)(VF,{state:e.executionCompatibility,sessionId:A}),Oe&&e.approvalCompatibility?.blocked?(0,q.jsxs)(`section`,{"aria-label":f(`subagent_approval_request_4321e83b`),children:[(0,q.jsx)(`p`,{className:`px-3 pt-2 text-sm font-medium`,children:f(`subagent_approval_request_4321e83b`)}),(0,q.jsx)(VF,{state:e.approvalCompatibility})]}):null,j?.planMode?(0,q.jsxs)(`div`,{className:`border-b bg-primary/10 px-3 py-1.5 text-center text-xs font-medium text-primary`,children:[f(`plan_mode_7cbb85b7`),` `,j.planMode.status?` · ${j.planMode.status}`:``]}):null,j?.parentSessionId?(0,q.jsxs)(`button`,{onClick:()=>w?w.onPickSession(j.parentSessionId):oe(j.parentSessionId),className:`flex w-full items-center gap-1.5 border-b bg-muted/40 px-3 py-1.5 text-xs font-medium text-muted-foreground hover:text-foreground`,children:[(0,q.jsx)(cr,{className:`size-3.5`}),f(`subagent_back_to_parent_session_5f5fc758`)]}):null,E?(0,q.jsxs)(`div`,{role:w?.historyRead?.status===`error`?`alert`:`status`,className:`flex min-h-0 flex-1 flex-col items-center justify-center gap-3 px-6 text-center text-sm text-muted-foreground`,children:[(0,q.jsx)(`p`,{children:f(w?.historyRead?.status===`error`?`this_session_cannot_be_loaded_right_now_please_try_agai_502f5a61`:`loading_side_by_side_session_f5d66e68`)}),w?.historyRead?.status===`error`?(0,q.jsx)(W,{variant:`outline`,size:`sm`,onClick:w.historyRead.retry,children:f(`retry_b8784c8d`)}):null,Me?(0,q.jsx)(W,{variant:`outline`,size:`sm`,onClick:We,children:f(`stop_generation_9ad0aac3`)}):null]}):!A&&!w&&!ie&&!R&&ne.length===0&&!re?.length?(0,q.jsx)(im,{chats:k,onOpenSession:oe,onPickTemplate:e=>Mt(e),onDescribeTask:()=>Tt.current?.focus()}):(0,q.jsx)(Kh,{scrollRef:wn,contentRef:Tn,onScroll:Dn,messages:M,mergedSubAgents:Nn,subAgentError:Mn.error,onRefreshSubAgents:()=>{Mn.refresh()},sending:Me,latestRunFinished:!Me&&P===null&&j?.lastRunStatus===`completed`,streaming:N,streamingActive:P===`streaming`,streamingReasoning:F,liveSegments:I,streamStatus:ee,backgroundExecWaiting:je,pendingUserText:R,pendingUserImages:ne,pendingUserMessages:re,forking:vn,executionBlocked:Ae,onSelectSubAgent:e=>{Jr(e)},onPreviewImage:fn,onRegenerate:()=>{if(!Ae){if(Xn()){en(f(`the_root_permission_change_is_unconfirmed_regeneration__134c0a98`));return}if($n){Cn(f(`saving_model_please_wait_04e35c5e`));return}fe()}},onFork:Kr,onDelete:e=>void ue(e),onEditMessage:(e,t)=>{if(!Ae){if(Xn()){en(f(`the_root_permission_change_is_unconfirmed_editing_and_r_45b99ff9`));return}if($n){Cn(f(`saving_model_please_wait_04e35c5e`));return}pe(e,t)}}},A??`new-session`),Ne&&(0,q.jsx)(`div`,{role:`alert`,className:`mx-4 mb-2 text-xs text-destructive`,children:f(`supervisor_managed_history_stale`)}),Pe||Fe?(0,q.jsxs)(`div`,{role:`alert`,"aria-live":`assertive`,className:`mx-auto mb-1 flex w-[calc(100%-1.5rem)] max-w-full flex-wrap items-center justify-between gap-2 rounded-lg border border-destructive/40 bg-destructive/10 px-3 py-2 text-sm`,children:[(0,q.jsxs)(`div`,{className:`min-w-0 flex-1 text-destructive`,children:[(0,q.jsx)(`p`,{className:`font-medium`,children:Pe?.kind===`submission-unconfirmed`?Pe.rejectionCode?Pe.rootModeSelectionSubmitted?f(`bamboo_rejected_the_mode_change_your_content_is_preserv_3445f2fc`):f(`bamboo_rejected_the_request_your_content_is_preserved_74a6cc8c`):f(`sending_is_unconfirmed_your_content_is_preserved_4f66238c`):Jn.unsafe&&Ie?f(`message_saved_but_execution_is_stopped_for_this_session_bacf408a`):Re?.title??f(`message_sent_but_generation_was_interrupted_62a4d83d`)}),Jn.unsafe&&Ie?(0,q.jsx)(`p`,{className:`mt-1 text-xs`,children:f(`the_root_permission_change_is_unconfirmed_your_message__fd9a5b04`)}):Pe?.kind===`submission-unconfirmed`&&Pe.rejectionCode===`session_project_running_conflict`?(0,q.jsx)(`p`,{className:`mt-1 text-xs`,children:f(`session_source_conflict_action`)}):Re?(0,q.jsx)(`p`,{className:`mt-1 text-xs`,children:Re.action}):null,Le&&Pe?.kind===`submission-unconfirmed`?(0,q.jsx)(`p`,{className:`mt-1 break-words text-xs`,children:Le}):Le?(0,q.jsxs)(`details`,{className:`mt-1 text-xs`,children:[(0,q.jsx)(`summary`,{children:f(`technical_details_c26fb419`)}),(0,q.jsx)(`p`,{className:`mt-1 break-words`,children:Le})]}):null]}),Me?null:(0,q.jsx)(SF,{subject:ze},j?.updatedAt),Jn.unsafe?null:Ie?(0,q.jsxs)(W,{size:`sm`,variant:`secondary`,disabled:ie||$n||Ae,onClick:()=>{if(Xn()){en(f(`the_root_permission_change_is_unconfirmed_generation_re_bdcf3a6c`));return}Pe?.kind===`generation-failed`?he(Pe):he()},children:[(0,q.jsx)(ce,{className:`size-3.5`}),f(`retry_generation_37960b38`)]}):(0,q.jsx)(W,{size:`sm`,variant:`secondary`,onClick:()=>Tt.current?.focus(),children:f(`continue_editing_fd4b9e3b`)})]}):null,(0,q.jsx)(ap,{offer:Ue.offer,disabled:Ae||Jn.unsafe||$n,onConfirm:()=>{Xn()||Ue.confirm()},onStop:()=>void Ue.stop(),onRefresh:()=>{Xn()||Ue.refresh()}}),e.upstreamRetryStatus?(0,q.jsx)(`p`,{role:`status`,className:`mx-4 mb-2 text-xs text-muted-foreground`,children:f(e.upstreamRetryStatus===`requesting`?`upstream_retry_requesting`:e.upstreamRetryStatus===`already_running`?`upstream_retry_already_running`:e.upstreamRetryStatus===`enabled`?`upstream_retry_enabled`:e.upstreamRetryStatus===`stopping`?`upstream_retry_stopping`:e.upstreamRetryStatus===`stop_requested`?`upstream_retry_stop_requested`:e.upstreamRetryStatus===`not_started`?`upstream_retry_not_started`:e.upstreamRetryStatus===`unavailable`?`upstream_retry_unavailable`:e.upstreamRetryStatus===`identity_unsaved`?`upstream_retry_identity_unsaved`:e.upstreamRetryStatus===`identity_unavailable`?`upstream_retry_identity_unavailable`:`upstream_retry_stop_unconfirmed`)}):null,Be.error&&(0,q.jsx)(`div`,{role:`alert`,className:`mx-auto mb-1 w-[calc(100%-1.5rem)] max-w-full rounded-lg border border-destructive/40 px-3 py-2 text-xs text-destructive`,children:Be.error}),p?(0,ra.createPortal)(Ye?.binding.supervisor_session_id===A?(0,q.jsx)(xg,{onReady:ot,controller:qe,selectedWorkId:et,onShowAll:()=>st(null),onReference:qe.canSendIngress&&Ye.capabilities?.message_references_v1===!0&&!Xe?e=>{$e(e),h?.(),requestAnimationFrame(()=>Tt.current?.focus())}:void 0},A):(0,q.jsx)(vg,{availability:qe.availability,refreshing:qe.refreshing,canRefresh:qe.canRefresh,onRefresh:()=>void qe.refresh(),canInitialize:qe.canInitialize,initializing:qe.initializing,initializationError:qe.initializationError,onInitialize:()=>void qe.initialize()}),p):null,Ze&&dt?(0,q.jsxs)(`div`,{className:`mx-4 mb-2 flex items-center gap-2 text-xs`,"data-testid":`ticket-reference`,children:[(0,q.jsx)(`span`,{children:f(`ticket_reference`,{title:qe.state?.works[dt.work_id]?.ticket.contract.title??f(`supervisor_work_tab`)})}),(0,q.jsx)(`button`,{type:`button`,className:`underline`,disabled:Xe,onClick:()=>$e(null),children:f(`ticket_clear_reference_b2e538a2`)})]}):null,Ze&&(Je.error||Xe)?(0,q.jsxs)(`div`,{role:`alert`,className:`mx-4 mb-2 text-xs text-destructive`,children:[Je.error??f(`ticket_the_previous_message_is_not_confirmed_retry_w_7369504e`),Je.executePending===A?(0,q.jsx)(`button`,{type:`button`,className:`ml-2 underline`,onClick:()=>void Je.retryExecute(),children:f(`ticket_retry_start_47d5cd3e`)}):null]}):null,(0,q.jsxs)(`div`,{"data-composer-region":!0,className:`relative shrink-0`,children:[!En&&(0,q.jsx)(`div`,{"data-scroll-to-bottom-anchor":!0,className:`pointer-events-none absolute inset-x-0 top-0 z-20 mx-auto flex max-w-full -translate-y-1/2 justify-center px-3`,children:(0,q.jsx)(`button`,{onClick:On,"aria-label":f(`scroll_to_bottom_2b05ff67`),className:`pointer-events-auto rounded-full border bg-card p-2 text-muted-foreground shadow-lg transition-colors hover:bg-accent hover:text-foreground`,children:(0,q.jsx)(me,{className:`size-5`})})}),(0,q.jsxs)(`div`,{className:`shrink-0`,hidden:E,inert:E,"data-history-composer-blocked":E,children:[(0,q.jsx)(rF,{feedback:L}),(0,q.jsx)(ZP,{draft:wt,draftKey:U,outputRate:te,onDraftChange:Mt,executionBlocked:Ae,onSubmit:Ur,onStop:We,sending:Me,queueMode:Be.mode,onQueueModeChange:A&&!ae&&!Ze?Be.setMode:void 0,sendWhileRunning:Ze,queueControls:A&&!Ze?(0,q.jsx)(Cg,{sessionId:A,messages:Be.pending,busy:Be.busy,onCancel:e=>void Be.cancel(e),onPreview:fn},A):null,workspaceControl:!A&&!w?(0,q.jsxs)(K.Suspense,{fallback:null,children:[(0,q.jsx)(GF,{projectId:r??null,workspacePath:n??xr??t,value:Tr.selection,onChange:e=>Tr.select(e),disabled:Tr.locked||ae||Ot,preparedPath:Tr.path,error:KF(Tr.error)}),Ot?(0,q.jsx)(`span`,{role:`status`,className:`px-2 text-xs text-muted-foreground`,children:f(`chat_worktree_preparing`)}):null]}):null,workflowControl:qt===`composer`||Gt||Zt?Zr(`composer`):null,catalogState:lr,catalogDisabled:mr,onPickCatalogEntry:e=>{if(mr||pn(e))return;let t={entry:e,argsText:`{}`},n=!1;try{hn(t)}catch{n=!0}un(t),Mt(``),ir(!0),Jt(n?`composer`:null),Tt.current?.focus()},workflowUndoControl:Yt&&Yt.revision===on.current?(0,q.jsxs)(`div`,{className:`px-2 pt-1 text-xs text-muted-foreground`,children:[f(`catalog_workflow_removed_81a37c5b`)+` `,(0,q.jsx)(`button`,{type:`button`,className:`text-primary hover:underline`,disabled:mr,onClick:()=>{!mr&&Yt.revision===on.current&&un(Yt.draft)},children:f(`undo_removal_2016190c`)})]}):null,permissionControl:(0,q.jsxs)(q.Fragment,{children:[A?(0,q.jsx)(fF,{sessionId:A,title:j?.title||A,compact:!0}):(0,q.jsx)(mF,{}),(0,q.jsx)(hF,{sessionId:A,child:Jn.child,unsafe:Jn.unsafe,selected:Jn.selected,confirmed:Jn.confirmed,loading:Jn.loading,pending:ae||Jn.busy,recovering:Jn.recovering,recoverable:Jn.recoverable,error:Jn.error,conflict:$t??Zn,onRetry:()=>{Jn.retry()}}),Jn.child&&Jn.error?(0,q.jsx)(`span`,{role:`alert`,className:`basis-full text-destructive`,children:Jn.error}):null]}),runtimeControls:(0,q.jsxs)(q.Fragment,{children:[Ct?(0,q.jsx)(tF,{totalTokens:Ct.totalTokens,maxContextTokens:Ct.maxContextTokens,cacheReadInputTokens:Ct.cacheReadInputTokens,cacheReadInputTokensRetained:Ct.cacheReadInputTokensRetained,prefixCache:Ct.prefixCache,onClick:()=>qr(l)}):null,(0,q.jsx)(cF,{models:Rn,model:Qn,onModelChange:e=>void nr(e),modelDisabled:tr,value:Jn.ordinaryValue,allowUltra:Jn.isRoot,thinkingMode:Jn.thinkingMode,onChange:e=>{en(null),Jn.choose(e)},disabled:Jn.controlDisabled||Je.busy,menuPlacement:`up`,menuAlign:`right`})]}),submissionPending:ae||Ot||It||Be.busy||Je.busy||$n||Jn.busy,inputRef:Tt,attachments:tn,onAddFiles:e=>void An(e),onRemoveAttachment:e=>sn(t=>t.filter(t=>t.id!==e)),onPreviewImage:fn,selectedSkill:Bt,onClearSkill:()=>cn(null),onPickSkill:Wr,skills:jn,workflows:Ht,selectedWorkflow:Ut,onClearWorkflow:()=>ln(null),onPickWorkflow:Gr,onOpenCatalog:()=>hr(`composer`),onPickCatalog:()=>{hr(`composer`),sr!==null&&Mt(``)},onPickGoal:A?()=>{qr(l),Mt(``),ir(!0)}:void 0,slashQuery:sr,onMentionQueryChange:yr,displayWorkspace:Ar,showProjectWorkspace:!!kr,workspaceFiles:Rr,hasSession:!!A,onOpenWorkspacePicker:c,selectedProjectId:r??null,onSelectProject:e=>s?.(e),onDismissMenus:()=>ir(!0)})]})]})]}),Qr?(0,q.jsx)(`div`,{"data-environment-floating":!0,"data-state":xt?`open`:`closed`,"aria-hidden":!xt,className:`absolute right-3 top-3 z-30 max-h-[calc(100%-1.5rem)] max-w-[calc(100%-1.5rem)] overflow-y-auto rounded-2xl`,style:{opacity:+!!xt,transform:xt?`translateX(0) scale(1)`:`translateX(0.75rem) scale(0.98)`,transformOrigin:`top right`,visibility:xt?`visible`:`hidden`,pointerEvents:xt?`auto`:`none`,transition:`opacity 200ms ease-out, transform 200ms ease-out, visibility 200ms ease-out`},children:Qr}):null]})]}),(0,q.jsx)($P,{forking:vn,toast:mn,onDismiss:()=>_n(null),onRestoreFocus:()=>{T!==!1&&!E&&Tt.current?.focus()}}),fr?(0,q.jsx)(D,{sessionId:fr.id,title:fr.title,onClose:()=>pr(null)},fr.id):null,ur&&A&&T!==!1?(0,q.jsx)(vF,{sessionId:A,sessionTitle:j?.title||A,onClose:()=>dr(!1)},A):null,(0,q.jsx)(eF,{src:dn,onClose:()=>fn(null)}),!_e&&Ee?(0,q.jsxs)(`div`,{role:`alert`,className:`mx-4 mb-3 flex items-center gap-3 rounded-lg border p-3 text-sm`,children:[(0,q.jsx)(`span`,{children:Ee}),(0,q.jsx)(`button`,{type:`button`,className:`shrink-0 underline`,disabled:ve||Ce,onClick:()=>void De(),children:f(ve?`refreshing_71659de8`:`refresh_request_0ab317cc`)})]}):null,Oe&&!e.approvalCompatibility?.blocked?(0,q.jsx)(Tp,{a:Oe,onRespond:e=>void V(e),submitting:e.approvalSubmitting,error:e.approvalError}):!Ae&&_e?(0,q.jsx)(wp,{q:_e,onAnswer:e=>void ke(e),loading:ve,submitting:Ce,unavailable:Te,error:Ee,canRetry:z,onRefresh:()=>void De(),onRetry:()=>void B()}):null]})}var ZF=()=>({history:[],committedReplay:[],live:[],liveVersion:null,terminal:null,commitPending:!1,needsReconcile:!1,reconcileRevision:0}),QF=new TextEncoder,$F=(e,t)=>e.length===t.length&&e.every((e,n)=>e===t[n]),eI=(e,t,n)=>{let r=QF.encode(e),i=QF.encode(n);return t>r.length?null:t===r.length?e+n:$F(r.slice(t,t+i.length),i)?e:null},tI=(e,t)=>{let n=[...e],r=new Map(n.map((e,t)=>[e.id,t]));for(let e of t){let t=r.get(e.id);t===void 0?(r.set(e.id,n.length),n.push(e)):n[t]=e}return n},nI=(e,t,n)=>{if(!n)return t;let r=[...e],i=new Map(r.map((e,t)=>[e.id,t]));for(let e of t){let t=i.get(e.id);t===void 0?(i.set(e.id,r.length),r.push(e)):r[t]=e}return r},rI=(e,t,n=e.reconcileRevision)=>{let r=n===e.reconcileRevision,i=r&&e.commitPending;return{...e,history:nI(e.history,t.messages,t.is_delta),committedReplay:i?[]:e.committedReplay,commitPending:i?!1:e.commitPending,needsReconcile:r?!1:e.needsReconcile}},iI=(e,t)=>{if(t.type===`snapshot`)return t.history_committed?{...e,committedReplay:tI(e.committedReplay,e.live),live:[],liveVersion:t.version,terminal:t.terminal??e.terminal,commitPending:!0,needsReconcile:!0,reconcileRevision:e.reconcileRevision+1}:{...e,live:t.messages,liveVersion:t.version,terminal:t.terminal??null,needsReconcile:!0,reconcileRevision:e.reconcileRevision+1};if(e.liveVersion!==null&&t.version<=e.liveVersion)return e;if(t.type===`started`){let n=e.live.some(e=>e.id===t.message_id);return{...e,live:n?e.live:[...e.live,{id:t.message_id,content:``,created_at:t.created_at}],liveVersion:t.version,terminal:null,needsReconcile:!0,reconcileRevision:e.reconcileRevision+1}}if(t.type===`discarded`)return{...e,history:e.history.filter(e=>e.id!==t.message_id),committedReplay:e.committedReplay.filter(e=>e.id!==t.message_id),live:e.live.filter(e=>e.id!==t.message_id),liveVersion:t.version};let n=e.live.findIndex(e=>e.id===t.message_id),r=n>=0?e.live[n]:null,i=eI(r?.content??``,t.offset,t.content);if(i===null)return{...e,liveVersion:t.version,needsReconcile:!0,reconcileRevision:e.reconcileRevision+1};let a={id:t.message_id,content:i,created_at:r?.created_at??t.created_at},o=[...e.live];return n>=0?o[n]=a:o.push(a),{...e,live:o,liveVersion:t.version}},aI=e=>({...e,needsReconcile:!0,reconcileRevision:e.reconcileRevision+1}),oI=(e,t)=>t.type===`gap`?{...e,needsReconcile:!0,reconcileRevision:e.reconcileRevision+1}:t.type===`terminal`?{...e,terminal:t.reason}:{...e,committedReplay:tI(e.committedReplay,e.live),live:[],liveVersion:Math.max(e.liveVersion??0,t.version),commitPending:!0,needsReconcile:!0,reconcileRevision:e.reconcileRevision+1},sI=(e,t)=>t?!e||t.startsWith(e)?t:e.startsWith(t)?e:t:e,cI=e=>{let t=tI(e.committedReplay,e.live),n=new Map(t.map(e=>[e.id,e])),r=new Set,i=e.history.map(e=>{r.add(e.id);let t=n.get(e.id),i=t?sI(e.content,t.content):e.content;return e.role===`user`?{id:e.id,role:`user`,content:i,createdAt:e.created_at}:{id:e.id,role:`assistant`,type:`text`,content:i,createdAt:e.created_at}});for(let e of t)r.has(e.id)||!e.content||i.push({id:e.id,role:`assistant`,type:`text`,content:e.content,createdAt:e.created_at});return i},lI=e=>({sessionId:e,transcript:ZF(),loading:e!==null,error:null,truncated:!1});function uI(e){u();let[t,n]=(0,K.useState)(()=>lI(e)),r=(0,K.useRef)(()=>{});(0,K.useEffect)(()=>{let t=lI(e),i=t,a=!0,o=!1,s=!1,c=0,l=e=>{i=e,a&&n(e)},u=e=>{let t=e(i.transcript);return l({...i,transcript:t}),t};if(l(t),!e)return r.current=()=>{},()=>{a=!1};let d=async()=>{if(!a)return;if(o){s=!0;return}o=!0,s=!1;let t=++c,n=i.transcript.reconcileRevision;try{let r=await zt.getMessageHistory(e);if(!a||t!==c)return;let o=rI(i.transcript,r,n);l({...i,transcript:o,loading:!1,error:null,truncated:r.truncated})}catch{if(!a||t!==c)return;l({...i,loading:!1,error:f(`subagent_messages_cannot_be_loaded_right_now_try_again__3a4bddca`)});return}finally{t===c&&(o=!1)}a&&(s||i.transcript.needsReconcile)&&(s=!1,d())},p=e=>{let t=i.transcript.reconcileRevision;u(e).reconcileRevision!==t&&d()},m=jt(e,{onEvent:e=>{p(t=>iI(t,e))},onControl:e=>{p(t=>oI(t,e))}}),h=At(()=>{p(aI)});return r.current=()=>{a&&(l({...i,loading:i.transcript.history.length===0,error:null}),u(aI),d())},d(),()=>{a=!1,c+=1,r.current=()=>{},h(),m.close()}},[e]);let i=t.sessionId===e?t:lI(e),a=(0,K.useCallback)(()=>r.current(),[]),o=(0,K.useMemo)(()=>cI(i.transcript),[i.transcript]),s=i.transcript.terminal===null&&i.transcript.live.some(e=>e.content.length>0);return{messages:o,loading:i.loading,error:i.error,truncated:i.truncated,streaming:s,retry:a}}var dI=()=>{};function fI({sessionId:e,chats:t,onPickSession:n}){u();let r=uI(e),i=t.find(t=>t.id===e&&t.kind===`child`)?.rootSessionId??null,a=na(i,!!i&&!!e,e),{scrollRef:o,contentRef:s,atBottom:c,handleScroll:l,scrollToBottom:d}=Mp(e),p=e?r.loading&&r.messages.length===0?(0,q.jsxs)(`div`,{className:`flex min-h-0 flex-1 items-center justify-center gap-2 text-sm text-muted-foreground`,"aria-label":f(`loading_subagent_messages_c313f76d`),children:[(0,q.jsx)(L,{className:`size-4 animate-spin`}),f(`loading_messages_bade7d59`)]}):r.error&&r.messages.length===0?(0,q.jsxs)(`div`,{role:`alert`,className:`flex min-h-0 flex-1 flex-col items-center justify-center gap-3 px-6 text-center text-sm text-destructive`,children:[(0,q.jsx)(`p`,{children:r.error}),(0,q.jsxs)(W,{size:`sm`,variant:`outline`,onClick:r.retry,children:[(0,q.jsx)(Be,{}),f(`retry_b8784c8d`)]})]}):r.messages.length===0?(0,q.jsx)(`div`,{className:`flex min-h-0 flex-1 items-center justify-center px-6 text-center text-sm text-muted-foreground`,children:f(`this_subagent_has_no_messages_to_display_yet_540b699c`)}):(0,q.jsxs)(`div`,{className:`relative flex min-h-0 flex-1 flex-col`,children:[r.error?(0,q.jsxs)(`div`,{role:`alert`,className:`mx-4 mt-2 flex items-center justify-between gap-2 rounded-lg border border-destructive/40 px-3 py-2 text-xs text-destructive`,children:[(0,q.jsx)(`span`,{children:r.error}),(0,q.jsx)(W,{size:`sm`,variant:`ghost`,onClick:r.retry,children:f(`retry_b8784c8d`)})]}):null,r.truncated?(0,q.jsx)(`div`,{role:`status`,className:`mx-4 mt-2 rounded-lg border px-3 py-2 text-xs text-muted-foreground`,children:f(`earlier_subagent_messages_are_omitted_only_recent_messa_103a24b5`)}):null,(0,q.jsx)(Kh,{scrollRef:o,contentRef:s,onScroll:l,messages:r.messages,mergedSubAgents:{},sending:r.streaming,latestRunFinished:!r.streaming,streaming:null,streamingActive:!1,streamingReasoning:null,liveSegments:[],streamStatus:null,pendingUserText:null,readOnly:!0,forking:!1,onSelectSubAgent:dI,onPreviewImage:dI,onRegenerate:dI,onFork:dI,onDelete:dI,onEditMessage:dI}),c?null:(0,q.jsx)(W,{size:`icon`,variant:`outline`,"aria-label":f(`scroll_to_bottom_2b05ff67`),className:`absolute bottom-4 left-1/2 z-20 -translate-x-1/2 rounded-full shadow-lg`,onClick:d,children:(0,q.jsx)(me,{})})]}):(0,q.jsx)(`div`,{className:`flex min-h-0 flex-1 items-center justify-center px-6 text-center text-sm text-muted-foreground`,children:f(`select_a_subagent_to_load_its_message_history_d73b4879`)});return(0,q.jsxs)(`div`,{className:`flex min-h-0 min-w-0 flex-1 flex-col`,"data-subagent-transcript-pane":!0,children:[(0,q.jsx)(`div`,{className:`flex shrink-0 items-center border-b px-3 py-2`,children:(0,q.jsxs)(we,{value:e??void 0,onValueChange:e=>n(e||null),children:[(0,q.jsx)(be,{size:`sm`,className:`min-w-0 flex-1`,children:(0,q.jsx)(ye,{placeholder:f(`select_subagent_aceda583`)})}),(0,q.jsx)(xe,{children:t.filter(t=>!t.parentSessionId||t.id===e).map(e=>(0,q.jsx)(Se,{value:e.id,children:e.title||f(`new_session_c57c30bc`)},e.id))})]})}),a.gapReason?(0,q.jsx)(`p`,{role:`status`,"data-actor-gap":a.gapReason,className:`border-b px-3 py-2 text-xs text-muted-foreground`,children:f(`there_is_a_gap_in_subagent_events_state_was_reloaded_bu_463a89f1`)}):null,p]})}function pI({sessionId:e,chats:t,onPickSession:n,onSessionCreated:r,onClose:i,onOpenInspector:a,onOpenReview:o,active:s=!0,pageVisible:c=!0}){u();let[l,d]=(0,K.useState)({sessionId:null,status:`ready`}),[f,p]=(0,K.useState)(0),m=kc(e,r),h=e?l.sessionId===e?l.status:`loading`:`ready`;return(0,K.useEffect)(()=>{if(!e)return;let t=new AbortController;return d({sessionId:e,status:`loading`}),H.getState().loadChatHistory(e,{throwOnError:!0,signal:t.signal}).then(()=>{t.signal.aborted||d({sessionId:e,status:`ready`})}).catch(()=>{t.signal.aborted||d({sessionId:e,status:`error`})}),()=>t.abort()},[e,f]),(0,q.jsx)(`div`,{className:`relative flex min-h-0 flex-1`,children:(0,q.jsx)(XF,{chat:m,pageVisible:c&&s,secondary:{sessionId:e,chats:t,onPickSession:t=>{t===e&&h===`error`?p(e=>e+1):n(t)},onClose:i,hideClose:!0,historyRead:{status:h,retry:()=>{h===`error`&&p(e=>e+1)}}},pickedWorkspace:null,onOpenWorkspacePicker:()=>{},onOpenInspector:a,onOpenReview:o,splitOpen:!0,onToggleSplit:i,onSelectSubAgent:n,onOpenSidebar:()=>{},sidebarCollapsed:!1})})}function mI(e){u();let[t,n]=(0,K.useState)(null),r=Sp(e.chats,e.onPickSession),i=e.chats.find(t=>t.id===e.sessionId);return!e.sessionId||!i?.parentSessionId&&(i?.kind===`root`||!i&&t===e.sessionId)?(0,q.jsx)(pI,{...e,onSessionCreated:t=>{n(t),e.onPickSession(t)}}):e.active===!1?null:(0,q.jsxs)(`div`,{className:`relative flex min-h-0 flex-1`,"data-session-drop-target":`secondary`,...r.handlers,children:[r.active?(0,q.jsx)(`div`,{className:`pointer-events-none absolute inset-0 z-[60] m-3 flex items-center justify-center rounded-2xl border-2 border-dashed border-primary bg-primary/10 text-sm font-medium text-primary`,children:f(`drop_to_open_session`)}):null,(0,q.jsx)(fI,{sessionId:e.sessionId,chats:e.chats,onPickSession:e.onPickSession})]})}var hI=3e3;function gI(){u();let e=H(e=>e.agentAvailability),[t,n]=(0,K.useState)(!1);return(0,K.useEffect)(()=>{if(e===!1){let e=window.setTimeout(()=>n(!0),hI);return()=>window.clearTimeout(e)}n(!1)},[e]),(0,q.jsx)(`div`,{role:`status`,"aria-live":`polite`,className:`pointer-events-none fixed inset-x-0 top-0 z-[140]`,children:t?(0,q.jsxs)(`div`,{className:`flex items-center justify-center gap-2 bg-destructive px-3 py-1.5 pt-[max(0.375rem,env(safe-area-inset-top))] text-xs font-medium text-white`,children:[(0,q.jsx)(Hr,{className:`size-3.5 shrink-0`}),(0,q.jsx)(`span`,{children:f(`connection_lost_reconnecting_7ea3f97f`)})]}):null})}function _I({sessionId:e,liveSegments:t=[],workspace:n,targetFilePath:r}){u();let i=H(Yr(t=>e?mt(e)(t)?.messages??[]:[])),a=(0,K.useMemo)(()=>fi(ui(i),di(t)),[t,i]),o=(0,K.useMemo)(()=>gi(a,n??void 0),[a,n]),s=(0,K.useMemo)(()=>_i(o),[o]);return e?o.length===0?(0,q.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col items-center justify-center gap-2 p-8 text-center text-sm text-muted-foreground`,children:[(0,q.jsx)(re,{className:`size-6 opacity-60`}),(0,q.jsx)(`p`,{children:f(`this_session_has_no_file_changes_to_review_yet_062e5342`)})]}):(0,q.jsxs)(`div`,{className:`min-h-0 flex-1 overflow-y-auto p-4`,children:[(0,q.jsxs)(`div`,{className:`mb-3 flex items-center gap-2 text-sm font-medium`,children:[(0,q.jsx)(re,{className:`size-4 text-muted-foreground`}),(0,q.jsx)(`span`,{children:f(`file_changes_4d016b2f`)}),(0,q.jsxs)(`span`,{className:`text-xs font-normal text-muted-foreground`,children:[f(`count_files`,{count:s.fileCount}),` · `,f(`count_changes`,{count:s.editCount})]}),(0,q.jsxs)(`span`,{className:`ml-auto shrink-0 text-xs font-normal`,children:[(0,q.jsxs)(`span`,{className:`text-green-600 dark:text-green-400`,children:[`+`,s.addedLines]}),` `,(0,q.jsxs)(`span`,{className:`text-red-600 dark:text-red-400`,children:[`−`,s.removedLines]})]})]}),(0,q.jsx)(Mi,{groups:o,workspace:n??void 0,pathMode:`relative`,density:`comfortable`,defaultOpen:(e,t)=>r?o[e]?.filePath===r:e===t-1,scrollToGroupId:r?`file:${r}`:null},r??`latest`)]}):(0,q.jsx)(`div`,{className:`flex min-h-0 flex-1 items-center justify-center p-8 text-center text-sm text-muted-foreground`,children:f(`open_a_session_to_view_changes_7de76304`)})}var vI=()=>o(()=>import(`./BrowserPane-Qpdtlb6C.js`),__vite__mapDeps([84,1,2,3,4,6,71,33,85,86,7,8,40,5,14,9,10,11,12,69]),import.meta.url),yI=e=>(0,K.lazy)(async()=>({default:(await e()).BrowserPaneView}));function bI({loadView:e=vI,...t}){u();let[n,r]=(0,K.useState)(()=>yI(e)),[i,a]=(0,K.useState)(0);return(0,q.jsx)(ue,{name:`Browser view`,fallback:()=>(0,q.jsxs)(`div`,{role:`alert`,className:`space-y-3 p-3 text-sm`,children:[(0,q.jsx)(`p`,{children:f(`browser_view_load_failed`)}),(0,q.jsx)(W,{variant:`outline`,onClick:()=>{r(()=>yI(e)),a(e=>e+1)},children:f(`retry_b8784c8d`)})]}),children:(0,q.jsx)(K.Suspense,{fallback:(0,q.jsx)(`p`,{role:`status`,className:`p-3 text-sm`,children:f(`loading_4927a53b`)}),children:(0,q.jsx)(n,{...t})})},i)}function xI(e,t){return t===!0||/\b(?:iPhone|iPod)\b|\bAndroid\b.*\bMobile\b/i.test(e)}function SI(){if(typeof navigator>`u`)return!1;let e=navigator.userAgentData?.mobile;return xI(navigator.userAgent,e)}function CI(e,t,n,r){let i=r??e?.closest(`[data-workbench-tab-handle]`)?.dataset.workbenchTabHandle;return()=>n()===t?i?[...document.querySelectorAll(`#right-workbench [data-workbench-tab-handle]`)].find(e=>e.dataset.workbenchTabHandle===i&&!e.closest(`[inert]`))??null:e:null}var wI=(0,K.lazy)(()=>o(()=>import(`./RightWorkbench-ClTIc5yT.js`).then(e=>({default:e.RightWorkbenchContent})),__vite__mapDeps([87,1,2,3,4,6,71,85,88,12,10,15,11,32,72,35,36,56,25,14,9,38,46]),import.meta.url));function TI(){u();let e=kc(),{booted:t,chats:n,currentSessionId:r,currentChat:i,select:a,newChat:o}=e,s=(0,K.useRef)(0),[c,l]=(0,K.useState)(0),d=(0,K.useCallback)(()=>s.current,[]),p=(0,K.useCallback)(e=>{s.current+=1,te(!1),a(e)},[a]),m=(0,K.useCallback)(()=>{s.current+=1,l(e=>e+1),te(!1),o()},[o]),{state:h,setField:g,scope:_,openToolForSession:v}=Uc(r),y=(0,K.useRef)(_);y.current=_;let b=(0,K.useCallback)(()=>y.current,[]),{secondSid:x,open:S,tab:w,tools:T,reviewTarget:D}=h,O=e=>g(`secondSid`,e),k=e=>g(`open`,e),A=(0,K.useCallback)(e=>g(`tab`,e),[g]),j=e=>g(`tools`,e),M=e=>g(`reviewTarget`,e),N=e=>O(e);(0,K.useEffect)(()=>{if(!x)return;let e=H.getState();e.chats.some(e=>e.id===x)||e.restoreSession(x).catch(()=>!1)},[x,_]);let[P,F]=(0,K.useState)(!1),[I,ee]=(0,K.useState)(!1),[L,te]=(0,K.useState)(!1),R=(0,K.useRef)(null),re=(0,K.useRef)(()=>null);(0,K.useEffect)(()=>{let e=e=>{(e.metaKey||e.ctrlKey)&&(e.key===`k`||e.key===`K`)&&(e.preventDefault(),L||(re.current=CI(document.activeElement instanceof HTMLElement?document.activeElement:null,b(),b,R.current?.getSourceId())),te(e=>!e))};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[L,b]);let ae=(0,K.useRef)(0),[ce,le]=(0,K.useState)(null),ue=!!i&&Ka(i),de=T.filter(e=>e!==`work`||ue),[fe,pe]=(0,K.useState)(!1),[me,he]=(0,K.useState)(``),[ge,_e]=(0,K.useState)(!1),ve=(0,K.useRef)(null),[ye,be]=(0,K.useState)(null),[xe,Se]=(0,K.useState)(null),Ce=(0,K.useRef)(null),we=tf(),Te=nf(),Ee=!we&&!SI(),z=ne(r,Ee&&S&&(w===`browser`||h.browserPresent||ye===r)),{readySessionId:De,state:B,openUrlInNewTab:Oe,hasPendingDialog:ke,activateTab:V}=z,Ae=De===r?B?.tabs:null,je=!Ee&&w===`browser`||!ue&&w===`work`?null:w;(0,K.useEffect)(()=>{De!==r||!B?.tabs||(g(`order`,e=>{let t=ie(T,B.tabs,e);return t.length===e.length&&t.every((t,n)=>t===e[n])?e:t}),g(`browserPresent`,B.tabs.length>0))},[T,B?.tabs,De,r,g]);let Me=(0,K.useCallback)(e=>g(`browserActiveId`,e),[g]);Lc({scope:_,state:De===r?B:null,savedId:h.browserActiveId,selectionVersion:ae,activateTab:V,save:Me}),(0,K.useEffect)(()=>{ve.current?.sessionId!==r&&(pe(!1),he(``),_e(!1))},[r]),(0,K.useEffect)(()=>{Ee&&S&&w===`browser`&&be(r)},[Ee,r,S,w]),(0,K.useEffect)(()=>{if(xe){if(xe.sessionId!==r){Se(null),Ce.current=null;return}if(!(De!==r||!B||z.busy||z.loading||z.entryOpening)){if(B.pending_dialog){pe(!1);return}Ce.current!==xe&&(Ce.current=xe,Oe(xe.url).then(e=>{Ce.current===xe&&(Ce.current=null,e?(Se(e=>e===xe?null:e),pe(!1)):ke()||Se(e=>e===xe?null:e))}))}}},[xe,r,De,B,z.busy,z.loading,z.entryOpening,Oe,ke]),(0,K.useEffect)(()=>{if(!fe||De!==r||!B)return;let e=ve.current;e?.sessionId!==r||!e.initialStateMissing||(e.initialStateMissing=!1,(B.tabs?B.tabs.length>0:B.url&&B.url!==`about:blank`)&&!ge&&!xe&&pe(!1))},[fe,De,r,B,ge,xe]),(0,K.useEffect)(()=>{De!==r||!B?.tabs||(B.tabs.length>0?S&&w===null&&T.length===0&&A(`browser`):w===`browser`&&!fe&&!xe&&A(T.at(-1)??null))},[De,r,B?.tabs,S,w,T,fe,xe,A]);let Ne=Gc(`lotus_next_sidebar_w`,288,{min:220,max:420}),Pe=qc(I?0:Ne.width),[Fe,Ie]=(0,K.useState)(!1),Le=(0,K.useRef)(null),Re=(0,K.useRef)(()=>null),ze=()=>{Fe||(Re.current=L?re.current:CI(document.activeElement instanceof HTMLElement?document.activeElement:null,b(),b,R.current?.getSourceId())),F(!1),te(!1),Ie(!0)},Be=()=>{Ie(!1),requestAnimationFrame(()=>{let e=Re.current();e?.isConnected&&e.getClientRects().length>0?e.focus():Le.current?.querySelector(`textarea`)?.focus()})},[Ve,He]=(0,K.useState)(null),[We,Ge]=(0,K.useState)(null),[Ke,qe]=(0,K.useState)(!1),[Je,Ye]=(0,K.useState)(null),[Xe,Ze]=(0,K.useState)(null),[Qe,$e]=(0,K.useState)(!1),[et,tt]=(0,K.useState)(!1),[nt,rt]=(0,K.useState)(null),[it,at]=(0,K.useState)(null);(0,K.useEffect)(()=>{if(!it)return;let e=setTimeout(()=>at(null),2500);return()=>clearTimeout(e)},[it]);let ot=async e=>{try{await Ue(e),at({message:f(`session_id_copied_3afb54a6`),failed:!1})}catch{at({message:f(`could_not_copy_session_id_3db157e7`),failed:!0})}};(0,K.useEffect)(()=>{H.getState().loadProjects().catch(()=>{})},[]);let st=fn(e=>e.themeMode),ct=fn(e=>e.userMessageColorPreset),lt=fn(e=>e.customUserMessageColor),ut=fn(e=>e.globalAccentPreset),dt=fn(e=>e.customGlobalAccentColor);(0,K.useEffect)(()=>{document.documentElement.classList.toggle(`dark`,st===`dark`)},[st]),(0,K.useEffect)(()=>{let e=un(st,ct,lt);document.documentElement.style.setProperty(`--user-message-background`,e.background),document.documentElement.style.setProperty(`--user-message-foreground`,e.foreground)},[st,ct,lt]),(0,K.useEffect)(()=>{dn(ln(st,ut,dt))},[st,ut,dt]),(0,K.useEffect)(()=>{let e=()=>{let e=E()?`true`:`false`;document.body.setAttribute(`data-vdi-safe`,e),document.getElementById(`root`)?.setAttribute(`data-vdi-safe`,e)};return e(),C(e)},[]);let ft=H(e=>e.loadSkills),pt=H(e=>e.persistSessionTitle),mt=H(e=>e.deleteSession),ht=H(e=>e.pinSession),gt=H(e=>e.unpinSession);(0,K.useEffect)(()=>{ft()},[ft]);let _t=i?.config?.workspacePath,vt=_t??We,yt=n.find(e=>e.id===x),bt=ie(de,Ae,h.order),xt=e=>{let t=bt.indexOf(e),n=bt.filter(t=>t!==e);return n[t]??n[t-1]??null},St=e=>{g(`order`,t=>t.filter(t=>t!==e))},Ct=(e,t=B?.active_tab_id)=>{if(ae.current+=1,e?.startsWith(`tool:`))A(e.slice(5));else if(e?.startsWith(`browser:`)){let n=e.slice(8);A(`browser`),pe(!1),n!==t&&z.activateTab(n)}else A(null)},U=(e,t=!0)=>{ae.current+=1,e===`browser`?(t&&r&&z.requestEntryOpen(r),be(r),De===r&&B!==null&&B.tabs===void 0&&B.url&&B.url!==`about:blank`?pe(!1):(ve.current={sessionId:r,initialStateMissing:De!==r||!B},he(``),_e(!1),pe(!0))):j(t=>t.includes(e)?t:[...t,e]),A(e),k(!0)},wt=e=>{ae.current+=1;let t=`tool:${e}`,n=xt(t);j(t=>t.filter(t=>t!==e)),St(t),w===e&&Ct(n)},Tt=e=>{ae.current+=1;let t=`browser:${e}`,n=xt(t),r=w===`browser`&&B?.active_tab_id===e&&!fe,i=ae.current;z.closeTab(e).then(e=>{e&&(St(t),r&&ae.current===i&&Ct(n,e.active_tab_id))})},Et=e=>{!r||!Ee||(Se({sessionId:r,url:e}),De===r&&B?.pending_dialog?(pe(!1),A(`browser`),k(!0)):U(`browser`))},Dt=e=>{M(e??null),U(`review`)},Ot=()=>{k(e=>!e)},kt=()=>{if(S&&w===`session`){k(!1);return}U(`session`)},At=e=>{N(e),U(`session`)};return(0,q.jsx)(nn,{onOpenInApp:Ee&&r?Et:void 0,children:(0,q.jsxs)(`div`,{className:`relative flex h-full min-h-0 flex-col bg-background text-foreground`,children:[(0,q.jsxs)(`div`,{ref:Le,"data-slot":`chat-shell`,inert:Fe,"aria-hidden":Fe||void 0,className:`relative h-full min-h-0 overflow-hidden ${Fe?`hidden`:`flex`}`,children:[(0,q.jsx)(gI,{}),(0,q.jsx)(af,{sidebarCollapsed:I,workbenchDocked:Te&&S,sidebarWidth:Ne,workbenchWidth:Pe,workbenchMaxWidth:Pe.maxWidth,viewportWidth:Pe.viewportWidth,suspended:Fe||L,scopeKey:_,sidebar:(0,q.jsx)(Qf,{open:P,onClose:()=>F(!1),collapsed:I,onToggleCollapse:()=>ee(e=>!e),width:`100%`,chats:n,booted:t,currentSessionId:r,onNewChat:(e,t)=>{rt(null),Ye(e??null),Ze(e&&t!==void 0?{projectId:e,sectionId:t}:null),e&&Ge(null),m()},onSelect:async e=>{let t=++s.current,n=H.getState().currentSessionId;if(e===`bamboo-default-supervisor`){if(await zt.ensureDefaultSupervisor(),!await H.getState().restoreSession(e))throw Error(f(`workflow_run_not_found`));if(t!==s.current||n!==H.getState().currentSessionId)return}Te&&e===`bamboo-default-supervisor`&&v(e,`work`),p(e)},onOpenExistingSession:async(e,t)=>{let n=++s.current,r=H.getState().currentSessionId;return $f(e,t,{isCurrent:()=>n===s.current&&r===H.getState().currentSessionId,restore:e=>H.getState().restoreSession(e),select:p,notFound:()=>Error(f(`workflow_run_not_found`))})},onRename:(e,t)=>pt(e,t),onDelete:e=>He({id:e.id,title:e.title||f(`new_session_c57c30bc`)}),onTogglePin:e=>e.pinned?gt(e.id):ht(e.id),onCopySessionId:ot,onOpenSettings:ze,onOpenProjectManager:()=>$e(!0),onOpenWorktrees:()=>tt(!0)}),workbench:(0,q.jsx)(se,{tabDragRef:R,interactionSuspended:L,focusScopeKey:_,getCurrentFocusScope:b,visible:S,pageVisible:!Fe,docked:Te,width:`100%`,onClose:()=>k(!1),children:S||ue&&T.includes(`work`)?(0,q.jsx)(K.Suspense,{fallback:null,children:(0,q.jsx)(wI,{visible:S,activeTab:je,openToolTabs:de,workEnabled:ue,work:(0,q.jsx)(`div`,{ref:le,className:`min-h-0 flex-1 overflow-y-auto`}),tabOrder:h.order,onTabReorder:e=>{ae.current+=1,g(`order`,t=>oe(t,e))},onToolClose:wt,browserEnabled:Ee,browserSessionAvailable:!!r,browserEntryOpen:fe,browserTabs:Ae,activeBrowserTabId:z.readySessionId===r?z.state?.active_tab_id:null,browserBusy:z.busy||!!z.state?.pending_dialog,onBrowserActivate:e=>{ae.current+=1,A(`browser`),pe(!1),e!==z.state?.active_tab_id&&z.activateTab(e)},onBrowserClose:Tt,onTabChange:e=>{if(e===null){ae.current+=1,A(null),pe(!1);return}e===`review`&&M(null),U(e)},onClose:()=>k(!1),sessionTitle:yt?.title,inspector:(0,q.jsx)($a,{embedded:!0,sessionId:r,open:S&&je===`inspector`,onClose:()=>k(!1),workspace:vt,onEditWorkspace:()=>qe(!0),onOpenReview:Dt,onCopySessionId:ot,selectedActorId:x??r??null,onSelectActor:e=>{e===(i?.kind===`root`?r:i?.rootSessionId)?(N(null),v(e,`inspector`),p(e)):At(e)}}),review:(0,q.jsx)(_I,{sessionId:r,liveSegments:e.liveSegments,workspace:vt,targetFilePath:D}),browser:Ee?(0,q.jsx)(bI,{sessionId:r,active:S&&w===`browser`,newTabEntry:fe,entryDraft:me,onEntryDraftChange:e=>{he(e),_e(!0)},onNewTabOpened:()=>{pe(!1),he(``)},browser:{...z,openDefault:e=>(e===r&&z.profilePhase===`closed`&&U(`browser`,!1),z.openDefault(e)),openClean:e=>(e===r&&z.profilePhase===`closed`&&U(`browser`,!1),z.openClean(e)),openProfile:(e,t)=>(e===r&&z.profilePhase===`closed`&&U(`browser`,!1),z.openProfile(e,t))}},r??`no-session`):null,session:(0,q.jsx)(mI,{sessionId:x,pageVisible:!Fe,active:S&&je===`session`,chats:n,onPickSession:N,onClose:()=>k(!1),onOpenInspector:()=>A(`inspector`),onOpenReview:()=>A(`review`)})})}):null}),children:(0,q.jsx)(XF,{chat:{...e,select:p,newChat:m},pageVisible:!Fe,pickedWorkspace:We,worktreePath:nt?.projectId===Je?nt.path:null,pendingProjectId:Je,newChatEpoch:c,getNavigationVersion:d,onNewSessionInProjectSection:Xe&&Xe.projectId===Je?e=>{let t=Xe;Ze(e=>e===t?null:e);let n=H.getState().projects[t.projectId];!n||n.status!==`active`||n.sidebar===void 0||Fc(t.projectId,e,t.sectionId,n.section).then(e=>{e||at({message:f(`sidebar_section_assign_failed`),failed:!0})}).catch(()=>at({message:f(`sidebar_section_assign_failed`),failed:!0}))}:void 0,onSelectProject:e=>{s.current+=1,Ye(e),Ze(null),rt(null),e&&Ge(null)},onOpenWorkspacePicker:()=>qe(!0),onOpenInspector:()=>U(`inspector`),onOpenReview:()=>Dt(),workPanelTarget:ue?ce:null,onOpenWork:ue?()=>U(`work`):void 0,onWorkReference:()=>{Te||k(!1)},sidePaneOpen:S,onToggleSidePane:Ot,splitOpen:S&&w===`session`,onToggleSplit:kt,onSelectSubAgent:At,onOpenSidebar:()=>{F(!0),ee(!1)},sidebarCollapsed:I})}),(0,q.jsx)(lo,{}),(0,q.jsx)(fo,{open:Ke,current:vt,locked:!!_t,onClose:()=>qe(!1),onSelect:e=>{s.current+=1,Ge(e),rt(null),e&&(Ye(null),Ze(null))}}),(0,q.jsx)(ep,{open:et,onClose:()=>tt(!1),onOpen:(e,t)=>{m(),Ye(e),Ze(null),Ge(t),rt({projectId:e,path:t}),tt(!1)},onSession:e=>{p(e),tt(!1)}}),(0,q.jsx)(rp,{open:Qe,onClose:()=>$e(!1)}),(0,q.jsx)(ip,{pending:Ve,onCancel:()=>He(null),onConfirm:e=>{mt(e),He(null)}}),it?(0,q.jsx)(`div`,{role:it.failed?`alert`:`status`,className:`pointer-events-none fixed inset-x-0 bottom-28 z-[110] flex justify-center px-4`,children:(0,q.jsx)(`span`,{className:`rounded-full border bg-card px-4 py-2 text-sm font-medium text-foreground shadow-xl`,children:it.message})}):null]}),(0,q.jsx)(oo,{open:Fe,onClose:Be}),(0,q.jsx)(no,{getReturnFocusTarget:re.current,open:L,onClose:()=>te(!1),chats:n,onSelect:e=>{Ie(!1),p(e),F(!1)},onNewChat:()=>{Ie(!1),m()},onSettings:ze})]})})}var EI=e=>{switch(e.kind){case`rejected`:return f(`incorrect_password_please_try_again_9380cc84`);case`rate-limited`:return f(`too_many_attempts_please_try_again_later_4cc53caf`);case`unavailable`:return f(`password_verification_is_temporarily_unavailable_please_2001e8cc`);case`contract-error`:return f(`the_backend_password_api_is_incompatible_upgrade_the_ba_d923cbab`)}};function DI({verifyPassword:e,onVerified:t}){u();let[n,r]=(0,K.useState)(``),[i,a]=(0,K.useState)(null),[o,s]=(0,K.useState)(!1),c=(0,K.useRef)(null);(0,K.useEffect)(()=>()=>{c.current?.abort(),c.current=null},[]);let l=async r=>{if(r.preventDefault(),!n||o)return;c.current?.abort();let i=new AbortController;c.current=i,s(!0),a(null);try{let r=await e(n,i.signal);if(i.signal.aborted||c.current!==i)return;r.kind===`verified`?t():a(EI(r))}catch{!i.signal.aborted&&c.current===i&&a(f(`password_verification_is_temporarily_unavailable_please_2001e8cc`))}finally{!i.signal.aborted&&c.current===i&&(c.current=null,s(!1))}};return(0,q.jsx)(`div`,{className:`flex h-full items-center justify-center bg-background p-6`,children:(0,q.jsxs)(`form`,{className:`w-full max-w-sm rounded-2xl border bg-card p-6 shadow-lg`,onSubmit:e=>void l(e),children:[(0,q.jsx)(`h1`,{className:`text-xl font-semibold`,children:f(`enter_access_password_c0052de1`)}),(0,q.jsx)(`p`,{className:`mt-1 text-sm text-muted-foreground`,children:f(`password_verification_is_required_before_entering_the_a_13035473`)}),(0,q.jsx)(`label`,{className:`mt-5 block text-sm font-medium`,htmlFor:`access-password`,children:f(`access_password_f4f712d5`)}),(0,q.jsx)(fe,{id:`access-password`,type:`password`,value:n,onChange:e=>r(e.target.value),placeholder:f(`please_enter_the_access_password_38433a0a`),autoComplete:`current-password`,autoFocus:!0,className:`mt-1.5 h-auto rounded-lg py-2 !text-base`}),i?(0,q.jsx)(`p`,{className:`mt-2 text-sm text-destructive`,role:`alert`,children:i}):null,(0,q.jsx)(W,{type:`submit`,disabled:!n||o,className:`mt-4 w-full`,children:f(o?`verifying_7f2d0739`:`verify_and_continue_64ded447`)})]})})}var OI=`bootstrap`,kI=`bamboo/access/verify`,AI=1,jI=`bamboo`,MI=`bamboo.agent`,NI=`/api/v1`,PI=1,FI=`bamboo.v2`,II=`/v2/stream`,LI=2,RI=`bamboo.v2`,zI=`/api/v1/bamboo/access/verify`,BI=`/v2/pair`,VI=4294967295,HI=[`auth.ws_hello_ack.v1`,`realtime.account_feed.v1`,`realtime.agent_events.v1`,`realtime.application_heartbeat.v1`,`realtime.feed_cursor.v1`,`realtime.feed_reset.v1`,`realtime.stop_control.v1`],UI=`auth.password_cookie.v1`,WI=`auth.device_bearer.v1`,GI=e=>typeof e==`object`&&!!e&&!Array.isArray(e),KI=e=>typeof e==`string`&&e.length>0,qI=e=>Number.isInteger(e)&&e>=0&&e<=VI,JI=e=>e===`open`||e===`credential_required`||e===`repair_required`,YI=e=>e===`local_bypass`||e===`authenticated`||e===`unauthenticated`;function XI(e){if(e.aborted)throw new St(e.reason)}function ZI(e){if(!GI(e))return{ok:!1,reason:`document-shape`};let t=e.server,n=e.api,r=e.realtime,i=e.auth,a=e.capabilities;if(typeof e.schema_version!=`number`||!GI(t)||!GI(n)||!GI(r)||!GI(i)||!Array.isArray(a)||!KI(t.product)||!KI(t.version)||!KI(n.name)||!KI(n.canonical_base_path)||typeof n.min_version!=`number`||typeof n.max_version!=`number`||!KI(r.name)||!KI(r.path)||typeof r.min_version!=`number`||typeof r.max_version!=`number`||!Array.isArray(r.subprotocols)||typeof i.password_enabled!=`boolean`||typeof i.device_auth_enabled!=`boolean`||!KI(i.verify_path)||!KI(i.pair_path))return{ok:!1,reason:`document-shape`};if(!JI(i.policy)||!YI(i.request_state))return{ok:!1,reason:`auth-enum`};if(!a.every(KI))return{ok:!1,reason:`document-shape`};let o=[];for(let e of r.subprotocols){if(!GI(e)||!KI(e.name)||!KI(e.encoding))return{ok:!1,reason:`document-shape`};o.push({name:e.name,encoding:e.encoding})}return{ok:!0,document:{schema_version:e.schema_version,server:{product:t.product,version:t.version},api:{name:n.name,canonical_base_path:n.canonical_base_path,min_version:n.min_version,max_version:n.max_version},realtime:{name:r.name,path:r.path,min_version:r.min_version,max_version:r.max_version,subprotocols:o},capabilities:[...a],auth:{policy:i.policy,request_state:i.request_state,password_enabled:i.password_enabled,device_auth_enabled:i.device_auth_enabled,verify_path:i.verify_path,pair_path:i.pair_path}}}}function QI(e){if(![e.schema_version,e.api.min_version,e.api.max_version,e.realtime.min_version,e.realtime.max_version].every(qI)||e.api.min_version>e.api.max_version||e.realtime.min_version>e.realtime.max_version)return`invalid-range`;if(new Set(e.capabilities).size!==e.capabilities.length)return`duplicate-capability`;let t=e.realtime.subprotocols.map(({name:e})=>e);if(new Set(t).size!==t.length)return`duplicate-subprotocol`;let{policy:n,request_state:r,password_enabled:i,device_auth_enabled:a}=e.auth;return n===`open`&&(r===`authenticated`||i||a)||n===`credential_required`&&!i&&!a||n===`repair_required`&&r===`authenticated`?`invalid-auth-combination`:null}function $I(e,t,n){return e<=n&&n<=t}function eL(e,t){let n=ZI(e);if(!n.ok)return{kind:`invalid`,reason:n.reason};let r=n.document,i=QI(r);if(i)return{kind:`invalid`,reason:i};if(r.schema_version!==AI)return{kind:`incompatible`,reason:`schema-version`};if(r.server.product!==jI)return{kind:`incompatible`,reason:`server-product`};if(r.api.name!==MI||r.api.canonical_base_path!==NI||!$I(r.api.min_version,r.api.max_version,PI))return{kind:`incompatible`,reason:`api-contract`};if(r.realtime.name!==FI||r.realtime.path!==II||!$I(r.realtime.min_version,r.realtime.max_version,LI)||!r.realtime.subprotocols.some(({name:e,encoding:t})=>e===RI&&t===`json`))return{kind:`incompatible`,reason:`realtime-contract`};let a=new Set(r.capabilities);if(HI.some(e=>!a.has(e)))return{kind:`incompatible`,reason:`missing-capability`};if(r.auth.password_enabled&&(!a.has(UI)||r.auth.verify_path!==zI))return{kind:`incompatible`,reason:`password-contract`};if(r.auth.device_auth_enabled&&(!a.has(WI)||r.auth.pair_path!==BI))return{kind:`incompatible`,reason:`device-contract`};let o=()=>(t?.(r.auth.request_state),{kind:`ready`});return r.auth.policy===`repair_required`?{kind:`repair`}:r.auth.request_state===`local_bypass`||r.auth.policy===`open`?o():r.auth.password_enabled?r.auth.request_state===`authenticated`?o():{kind:`auth-required`}:{kind:`auth-unsupported`,mechanism:`device`}}function tL(e){if(!e)return!1;let t=e.split(`;`,1)[0]?.trim().toLowerCase();return t===`application/json`||!!(t?.startsWith(`application/`)&&t.endsWith(`+json`))}function nL(e,t){if(e instanceof St)throw e;if(e instanceof Tt)return{kind:`unavailable`,reason:`timeout`};if(t.aborted)throw new St(t.reason??e);return e instanceof U?{kind:`unavailable`,reason:`network`}:e instanceof Et?e.status===404?{kind:`missing`}:e.status===408||e.status===429||e.status>=500&&e.status<=599?{kind:`unavailable`,reason:`http-status`,status:e.status}:{kind:`incompatible`,reason:`http-status`,status:e.status}:{kind:`unavailable`,reason:`network`}}async function rL(e,t){XI(e);let n;try{n=await Ot.fetchRaw(OI,{method:`GET`,signal:e,cache:`no-store`})}catch(t){return nL(t,e)}if(XI(e),!tL(n.headers.get(`content-type`))){let e=n.body?.cancel();return e&&e.catch(()=>void 0),{kind:`invalid`,reason:`content-type`}}let r;try{r=await n.json()}catch(t){return t instanceof St||t instanceof Tt||t instanceof U||e.aborted?nL(t,e):{kind:`invalid`,reason:`malformed-json`}}return XI(e),eL(r,t)}function iL(e,t){if(e instanceof St)throw e;if(e instanceof Tt)return{kind:`unavailable`,reason:`timeout`};if(t.aborted)throw new St(t.reason??e);return e instanceof U?{kind:`unavailable`,reason:`network`}:e instanceof Et?e.status===401?{kind:`rejected`}:e.status===429?{kind:`rate-limited`}:e.status>=500&&e.status<=599?{kind:`unavailable`,reason:`http-status`,status:e.status}:{kind:`contract-error`,reason:`http-status`,status:e.status}:{kind:`contract-error`,reason:`invalid-response`}}async function aL(e,t){XI(t);let n;try{n=await Ot.post(kI,{password:e},{signal:t})}catch(e){return iL(e,t)}return XI(t),!GI(n)||n.success!==!0||Object.keys(n).length!==1||!Object.hasOwn(n,`success`)?{kind:`contract-error`,reason:`invalid-response`}:{kind:`verified`}}var oL=[250,500],sL=6e4,cL=2e3,lL=e=>Math.min(250*2**Math.min(e,3),cL),uL=(e,t)=>new Promise(n=>{if(t.aborted){n(!1);return}let r=e=>{clearTimeout(a),t.removeEventListener(`abort`,i),n(e)},i=()=>r(!1),a=setTimeout(()=>r(!0),e);t.addEventListener(`abort`,i,{once:!0})}),dL=e=>{switch(e.kind){case`missing`:return{title:f(`backend_bootstrap_contract_missing_e730cff1`),description:f(`this_backend_does_not_provide_the_canonical_bootstrap_r_978e5022`)};case`invalid`:return{title:f(`invalid_backend_bootstrap_response_a55ab584`),description:f(`backend_startup_information_could_not_be_parsed_safely__0be87b82`)};case`incompatible`:return{title:f(`incompatible_backend_protocol_260abc98`),description:f(`this_backend_does_not_meet_the_http_v1_and_v2_stream_co_7566de39`)};case`auth-unsupported`:return{title:f(`unsupported_authentication_method_5c205826`),description:f(`this_deployment_accepts_only_device_credentials_this_lo_347b881c`)};case`repair`:return{title:f(`backend_access_configuration_needs_repair_47913701`),description:f(`bamboo_has_isolated_access_control_for_safety_repair_or_e922553b`)};case`unavailable`:case`internal-failure`:return{title:f(`backend_temporarily_unavailable_42868eee`),description:f(`bamboo_is_temporarily_unavailable_check_that_the_servic_f2489632`)}}};function fL(){u();let e=a(),[t,n]=(0,K.useState)({kind:`loading`}),r=(0,K.useRef)(0),i=(0,K.useRef)(null),o=(0,K.useCallback)(()=>{i.current?.controller.abort();let e={generation:r.current+1,controller:new AbortController,startedAt:Date.now()};return r.current=e.generation,i.current=e,e},[]),s=(0,K.useCallback)(e=>!e.controller.signal.aborted&&i.current?.generation===e.generation&&i.current.controller===e.controller,[]),c=(0,K.useCallback)(async(e,t)=>{try{let r=await at.getInstance().getSetupStatus();if(!s(e))return;if(!r.is_complete){n({kind:`setup`,ownerAccess:t,message:r.message||f(`initial_app_setup_is_not_complete__38590db7`)});return}}catch{if(!s(e))return}s(e)&&n({kind:`app`,ownerAccess:t})},[s]),l=(0,K.useCallback)(async t=>{for(let r=0;;r+=1){let i,a=!1;try{i=await rL(t.controller.signal,e=>{a=e===`local_bypass`||e===`authenticated`})}catch{if(!s(t))return;n({kind:`internal-failure`});return}if(!s(t))return;if(i.kind===`unavailable`){let a=e.host.capabilities.sidecarBackend,o=sL-(Date.now()-t.startedAt),c=a?Math.min(lL(r),o):oL[r];if(c===void 0||c<=0){n(i);return}if(!await uL(c,t.controller.signal)||!s(t))return;continue}if(i.kind===`ready`){await c(t,a);return}n(i);return}},[s,c,e.host.capabilities.sidecarBackend]),d=(0,K.useCallback)(()=>{let e=o();n({kind:`loading`}),l(e)},[o,l]),p=(0,K.useCallback)(()=>{let e=t.kind===`setup`&&t.ownerAccess,r=o();n({kind:`loading`}),(async()=>{await at.getInstance().markSetupComplete().catch(()=>void 0),s(r)&&await c(r,e)})()},[o,s,c,t]);if((0,K.useEffect)(()=>(d(),()=>{r.current+=1,i.current?.controller.abort(),i.current=null}),[d]),t.kind===`loading`){let t=e.host.capabilities.sidecarBackend;return(0,q.jsx)(`div`,{className:`flex h-full items-center justify-center bg-background p-6`,children:(0,q.jsxs)(`div`,{role:`status`,"aria-live":`polite`,className:`w-full max-w-sm rounded-2xl border bg-card p-6 text-center shadow-lg`,children:[(0,q.jsx)(`div`,{className:`mx-auto flex size-12 items-center justify-center rounded-full bg-primary/10`,children:(0,q.jsx)(L,{"aria-hidden":`true`,className:`size-6 animate-spin text-primary motion-reduce:animate-none`})}),(0,q.jsx)(`h1`,{className:`mt-4 text-xl font-semibold`,children:f(t?`starting_bodhi_41498861`:`connecting_to_bamboo_a1d9b183`)}),(0,q.jsx)(`p`,{className:`mt-2 text-sm leading-relaxed text-muted-foreground`,children:f(t?`waiting_for_the_local_bamboo_engine__da692f8f`:`checking_backend_service_status__e695ea14`)}),(0,q.jsx)(`p`,{className:`mt-2 text-xs text-muted-foreground`,children:f(t?`first_launch_or_complex_configuration_may_take_a_while__cd1be987`:`please_wait__043bd055`)})]})})}if(t.kind===`setup`)return(0,q.jsx)(`div`,{className:`flex h-full items-center justify-center bg-background p-6`,children:(0,q.jsxs)(`div`,{className:`w-full max-w-sm rounded-2xl border bg-card p-6 text-center shadow-lg`,children:[(0,q.jsx)(`h1`,{className:`text-xl font-semibold`,children:f(`initial_setup_8a18eafe`)}),(0,q.jsx)(`p`,{className:`mt-2 text-sm leading-relaxed text-muted-foreground`,children:t.message}),(0,q.jsx)(`p`,{className:`mt-2 text-xs text-muted-foreground`,children:f(`configure_your_provider_and_api_key_in_the_backend_or_d_93002bfd`)}),(0,q.jsx)(W,{className:`mt-5 w-full`,onClick:p,children:f(`setup_complete_continue_0e3dd041`)})]})});if(t.kind===`auth-required`)return(0,q.jsx)(DI,{verifyPassword:aL,onVerified:d});if(t.kind===`app`)return(0,q.jsx)(Bn,{value:t.ownerAccess,children:(0,q.jsx)(TI,{})});let m=dL(t);return(0,q.jsx)(`div`,{className:`flex h-full items-center justify-center bg-background p-6`,children:(0,q.jsxs)(`div`,{className:`w-full max-w-sm rounded-2xl border bg-card p-6 text-center shadow-lg`,children:[(0,q.jsx)(`h1`,{className:`text-xl font-semibold`,children:m.title}),(0,q.jsx)(`p`,{className:`mt-2 text-sm leading-relaxed text-muted-foreground`,children:m.description}),(0,q.jsxs)(`p`,{className:`mt-3 break-all font-mono text-xs text-muted-foreground`,children:[e.endpointSource,` · v`,e.artifact.version,e.artifact.revision?`@${e.artifact.revision}`:``]}),(0,q.jsx)(W,{className:`mt-5 w-full`,onClick:d,children:f(`retry_b8784c8d`)})]})})}await p;export{fL as default};
|