@cortex-agent/server 2026.10.27 → 2026.10.28

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.
@@ -121,7 +121,7 @@ The entry has been removed from ISSUES.md and handed to this session. Please inv
121
121
  * LICENSE.md file in the root directory of this source tree.
122
122
  *
123
123
  * @license MIT
124
- */function Lh(){return Lh=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)({}).hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},Lh.apply(null,arguments)}function xS(e){return e===void 0&&(e=""),new URLSearchParams(typeof e=="string"||Array.isArray(e)||e instanceof URLSearchParams?e:Object.keys(e).reduce((t,n)=>{let r=e[n];return t.concat(Array.isArray(r)?r.map(i=>[n,i]):[[n,r]])},[]))}function C0e(e,t){let n=xS(e);return t&&t.forEach((r,i)=>{n.has(i)||t.getAll(i).forEach(s=>{n.append(i,s)})}),n}const T0e="6";try{window.__reactRouterVersion=T0e}catch{}function E0e(e,t){return rW({basename:t==null?void 0:t.basename,future:Lh({},t==null?void 0:t.future,{v7_prependBasename:!0}),history:phe({window:t==null?void 0:t.window}),hydrationData:(t==null?void 0:t.hydrationData)||bW(),routes:e,mapRouteProperties:xW,dataStrategy:t==null?void 0:t.dataStrategy,patchRoutesOnNavigation:t==null?void 0:t.patchRoutesOnNavigation,window:t==null?void 0:t.window}).initialize()}function yW(e,t){return rW({basename:t==null?void 0:t.basename,future:Lh({},t==null?void 0:t.future,{v7_prependBasename:!0}),history:hhe({window:t==null?void 0:t.window}),hydrationData:(t==null?void 0:t.hydrationData)||bW(),routes:e,mapRouteProperties:xW,dataStrategy:t==null?void 0:t.dataStrategy,patchRoutesOnNavigation:t==null?void 0:t.patchRoutesOnNavigation,window:t==null?void 0:t.window}).initialize()}function bW(){var e;let t=(e=window)==null?void 0:e.__staticRouterHydrationData;return t&&t.errors&&(t=Lh({},t,{errors:R0e(t.errors)})),t}function R0e(e){if(!e)return null;let t=Object.entries(e),n={};for(let[r,i]of t)if(i&&i.__type==="RouteErrorResponse")n[r]=new e1(i.status,i.statusText,i.data,i.internal===!0);else if(i&&i.__type==="Error"){if(i.__subType){let s=window[i.__subType];if(typeof s=="function")try{let a=new s(i.message);a.stack="",n[r]=a}catch{}}if(n[r]==null){let s=new Error(i.message);s.stack="",n[r]=s}}else n[r]=i;return n}const M0e=f.createContext({isTransitioning:!1}),A0e=f.createContext(new Map),P0e="startTransition",yE=af[P0e],I0e="flushSync",bE=Ene[I0e];function L0e(e){yE?yE(e):e()}function ep(e){bE?bE(e):e()}class N0e{constructor(){this.status="pending",this.promise=new Promise((t,n)=>{this.resolve=r=>{this.status==="pending"&&(this.status="resolved",t(r))},this.reject=r=>{this.status==="pending"&&(this.status="rejected",n(r))}})}}function wW(e){let{fallbackElement:t,router:n,future:r}=e,[i,s]=f.useState(n.state),[a,l]=f.useState(),[c,u]=f.useState({isTransitioning:!1}),[d,p]=f.useState(),[h,m]=f.useState(),[v,g]=f.useState(),x=f.useRef(new Map),{v7_startTransition:y}=r||{},b=f.useCallback(A=>{y?L0e(A):A()},[y]),S=f.useCallback((A,P)=>{let{deletedFetchers:L,flushSync:F,viewTransitionOpts:B}=P;A.fetchers.forEach((V,Q)=>{V.data!==void 0&&x.current.set(Q,V.data)}),L.forEach(V=>x.current.delete(V));let K=n.window==null||n.window.document==null||typeof n.window.document.startViewTransition!="function";if(!B||K){F?ep(()=>s(A)):b(()=>s(A));return}if(F){ep(()=>{h&&(d&&d.resolve(),h.skipTransition()),u({isTransitioning:!0,flushSync:!0,currentLocation:B.currentLocation,nextLocation:B.nextLocation})});let V=n.window.document.startViewTransition(()=>{ep(()=>s(A))});V.finished.finally(()=>{ep(()=>{p(void 0),m(void 0),l(void 0),u({isTransitioning:!1})})}),ep(()=>m(V));return}h?(d&&d.resolve(),h.skipTransition(),g({state:A,currentLocation:B.currentLocation,nextLocation:B.nextLocation})):(l(A),u({isTransitioning:!0,flushSync:!1,currentLocation:B.currentLocation,nextLocation:B.nextLocation}))},[n.window,h,d,x,b]);f.useLayoutEffect(()=>n.subscribe(S),[n,S]),f.useEffect(()=>{c.isTransitioning&&!c.flushSync&&p(new N0e)},[c]),f.useEffect(()=>{if(d&&a&&n.window){let A=a,P=d.promise,L=n.window.document.startViewTransition(async()=>{b(()=>s(A)),await P});L.finished.finally(()=>{p(void 0),m(void 0),l(void 0),u({isTransitioning:!1})}),m(L)}},[b,a,d,n.window]),f.useEffect(()=>{d&&a&&i.location.key===a.location.key&&d.resolve()},[d,h,i.location,a]),f.useEffect(()=>{!c.isTransitioning&&v&&(l(v.state),u({isTransitioning:!0,flushSync:!1,currentLocation:v.currentLocation,nextLocation:v.nextLocation}),g(void 0))},[c.isTransitioning,v]),f.useEffect(()=>{},[]);let j=f.useMemo(()=>({createHref:n.createHref,encodeLocation:n.encodeLocation,go:A=>n.navigate(A),push:(A,P,L)=>n.navigate(A,{state:P,preventScrollReset:L==null?void 0:L.preventScrollReset}),replace:(A,P,L)=>n.navigate(A,{replace:!0,state:P,preventScrollReset:L==null?void 0:L.preventScrollReset})}),[n]),w=n.basename||"/",R=f.useMemo(()=>({router:n,navigator:j,static:!1,basename:w}),[n,j,w]),T=f.useMemo(()=>({v7_relativeSplatPath:n.future.v7_relativeSplatPath}),[n.future.v7_relativeSplatPath]);return f.useEffect(()=>k0e(r,n.future),[r,n.future]),f.createElement(f.Fragment,null,f.createElement(qx.Provider,{value:R},f.createElement(lW.Provider,{value:i},f.createElement(A0e.Provider,{value:x.current},f.createElement(M0e.Provider,{value:c},f.createElement(j0e,{basename:w,location:i.location,navigationType:i.historyAction,navigator:j,future:T},i.initialized||n.future.v7_partialHydration?f.createElement(D0e,{routes:n.routes,future:n.future,state:i}):t))))),null)}const D0e=f.memo(O0e);function O0e(e){let{routes:t,future:n,state:r}=e;return f0e(t,void 0,r,n)}var wE;(function(e){e.UseScrollRestoration="useScrollRestoration",e.UseSubmit="useSubmit",e.UseSubmitFetcher="useSubmitFetcher",e.UseFetcher="useFetcher",e.useViewTransitionState="useViewTransitionState"})(wE||(wE={}));var SE;(function(e){e.UseFetcher="useFetcher",e.UseFetchers="useFetchers",e.UseScrollRestoration="useScrollRestoration"})(SE||(SE={}));function F0e(e){let t=f.useRef(xS(e)),n=f.useRef(!1),r=_n(),i=f.useMemo(()=>C0e(r.search,n.current?null:t.current),[r.search]),s=qe(),a=f.useCallback((l,c)=>{const u=xS(typeof l=="function"?l(i):l);n.current=!0,s("?"+u,c)},[s,i]);return[i,a]}let SW=[];function _0e(e){SW=e}function z0e(e){return e.hash.startsWith("#/")?e.hash.slice(1).split(/[?#]/)[0]:e.pathname}function W0e(e){const t=e.join("/").replace(/\/{2,}/g,"/");return t.startsWith("/")?t:`/${t}`}function B0e(e,t=SW){const n=ia(t,e);if(!n)return null;const r=n.map(i=>i.route.path).filter(i=>!!i);return W0e(r).slice(0,80)}function $0e(){return typeof window>"u"?null:B0e(z0e(window.location))}const I0="1027-2309·66a9504",H0e=[/^Script error\.?$/i,/^ResizeObserver loop/i];function kW(e){return e instanceof Error?{name:e.name||"Error",message:e.message,stack:e.stack??""}:{name:`NonError:${e===null?"null":typeof e}`,message:String(e),stack:""}}function A6(e,t,n=""){const r=kW(t);return{kind:"crash",crashKind:e,errorName:r.name.slice(0,200),message:r.message.slice(0,2e3),stack:`${r.stack}${n}`.slice(0,2e4),route:$0e(),buildStamp:I0.slice(0,60),uptimeS:typeof performance>"u"?null:Math.round(performance.now()/1e3)}}function jW(e){return H0e.some(t=>t.test(e))}function kE(e){if(jW(e.message??""))return;const t=e.error??new Error(e.message||"Unknown error");fs.enqueue(A6("windowError",t))}function jE(e){const t=kW(e.reason);jW(t.message)||fs.enqueue(A6("unhandledRejection",e.reason))}function U0e(e=window){return e.addEventListener("error",kE),e.addEventListener("unhandledrejection",jE),()=>{e.removeEventListener("error",kE),e.removeEventListener("unhandledrejection",jE)}}function CW(e,t){const n=t?`
124
+ */function Lh(){return Lh=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)({}).hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},Lh.apply(null,arguments)}function xS(e){return e===void 0&&(e=""),new URLSearchParams(typeof e=="string"||Array.isArray(e)||e instanceof URLSearchParams?e:Object.keys(e).reduce((t,n)=>{let r=e[n];return t.concat(Array.isArray(r)?r.map(i=>[n,i]):[[n,r]])},[]))}function C0e(e,t){let n=xS(e);return t&&t.forEach((r,i)=>{n.has(i)||t.getAll(i).forEach(s=>{n.append(i,s)})}),n}const T0e="6";try{window.__reactRouterVersion=T0e}catch{}function E0e(e,t){return rW({basename:t==null?void 0:t.basename,future:Lh({},t==null?void 0:t.future,{v7_prependBasename:!0}),history:phe({window:t==null?void 0:t.window}),hydrationData:(t==null?void 0:t.hydrationData)||bW(),routes:e,mapRouteProperties:xW,dataStrategy:t==null?void 0:t.dataStrategy,patchRoutesOnNavigation:t==null?void 0:t.patchRoutesOnNavigation,window:t==null?void 0:t.window}).initialize()}function yW(e,t){return rW({basename:t==null?void 0:t.basename,future:Lh({},t==null?void 0:t.future,{v7_prependBasename:!0}),history:hhe({window:t==null?void 0:t.window}),hydrationData:(t==null?void 0:t.hydrationData)||bW(),routes:e,mapRouteProperties:xW,dataStrategy:t==null?void 0:t.dataStrategy,patchRoutesOnNavigation:t==null?void 0:t.patchRoutesOnNavigation,window:t==null?void 0:t.window}).initialize()}function bW(){var e;let t=(e=window)==null?void 0:e.__staticRouterHydrationData;return t&&t.errors&&(t=Lh({},t,{errors:R0e(t.errors)})),t}function R0e(e){if(!e)return null;let t=Object.entries(e),n={};for(let[r,i]of t)if(i&&i.__type==="RouteErrorResponse")n[r]=new e1(i.status,i.statusText,i.data,i.internal===!0);else if(i&&i.__type==="Error"){if(i.__subType){let s=window[i.__subType];if(typeof s=="function")try{let a=new s(i.message);a.stack="",n[r]=a}catch{}}if(n[r]==null){let s=new Error(i.message);s.stack="",n[r]=s}}else n[r]=i;return n}const M0e=f.createContext({isTransitioning:!1}),A0e=f.createContext(new Map),P0e="startTransition",yE=af[P0e],I0e="flushSync",bE=Ene[I0e];function L0e(e){yE?yE(e):e()}function ep(e){bE?bE(e):e()}class N0e{constructor(){this.status="pending",this.promise=new Promise((t,n)=>{this.resolve=r=>{this.status==="pending"&&(this.status="resolved",t(r))},this.reject=r=>{this.status==="pending"&&(this.status="rejected",n(r))}})}}function wW(e){let{fallbackElement:t,router:n,future:r}=e,[i,s]=f.useState(n.state),[a,l]=f.useState(),[c,u]=f.useState({isTransitioning:!1}),[d,p]=f.useState(),[h,m]=f.useState(),[v,g]=f.useState(),x=f.useRef(new Map),{v7_startTransition:y}=r||{},b=f.useCallback(A=>{y?L0e(A):A()},[y]),S=f.useCallback((A,P)=>{let{deletedFetchers:L,flushSync:F,viewTransitionOpts:B}=P;A.fetchers.forEach((V,Q)=>{V.data!==void 0&&x.current.set(Q,V.data)}),L.forEach(V=>x.current.delete(V));let K=n.window==null||n.window.document==null||typeof n.window.document.startViewTransition!="function";if(!B||K){F?ep(()=>s(A)):b(()=>s(A));return}if(F){ep(()=>{h&&(d&&d.resolve(),h.skipTransition()),u({isTransitioning:!0,flushSync:!0,currentLocation:B.currentLocation,nextLocation:B.nextLocation})});let V=n.window.document.startViewTransition(()=>{ep(()=>s(A))});V.finished.finally(()=>{ep(()=>{p(void 0),m(void 0),l(void 0),u({isTransitioning:!1})})}),ep(()=>m(V));return}h?(d&&d.resolve(),h.skipTransition(),g({state:A,currentLocation:B.currentLocation,nextLocation:B.nextLocation})):(l(A),u({isTransitioning:!0,flushSync:!1,currentLocation:B.currentLocation,nextLocation:B.nextLocation}))},[n.window,h,d,x,b]);f.useLayoutEffect(()=>n.subscribe(S),[n,S]),f.useEffect(()=>{c.isTransitioning&&!c.flushSync&&p(new N0e)},[c]),f.useEffect(()=>{if(d&&a&&n.window){let A=a,P=d.promise,L=n.window.document.startViewTransition(async()=>{b(()=>s(A)),await P});L.finished.finally(()=>{p(void 0),m(void 0),l(void 0),u({isTransitioning:!1})}),m(L)}},[b,a,d,n.window]),f.useEffect(()=>{d&&a&&i.location.key===a.location.key&&d.resolve()},[d,h,i.location,a]),f.useEffect(()=>{!c.isTransitioning&&v&&(l(v.state),u({isTransitioning:!0,flushSync:!1,currentLocation:v.currentLocation,nextLocation:v.nextLocation}),g(void 0))},[c.isTransitioning,v]),f.useEffect(()=>{},[]);let j=f.useMemo(()=>({createHref:n.createHref,encodeLocation:n.encodeLocation,go:A=>n.navigate(A),push:(A,P,L)=>n.navigate(A,{state:P,preventScrollReset:L==null?void 0:L.preventScrollReset}),replace:(A,P,L)=>n.navigate(A,{replace:!0,state:P,preventScrollReset:L==null?void 0:L.preventScrollReset})}),[n]),w=n.basename||"/",R=f.useMemo(()=>({router:n,navigator:j,static:!1,basename:w}),[n,j,w]),T=f.useMemo(()=>({v7_relativeSplatPath:n.future.v7_relativeSplatPath}),[n.future.v7_relativeSplatPath]);return f.useEffect(()=>k0e(r,n.future),[r,n.future]),f.createElement(f.Fragment,null,f.createElement(qx.Provider,{value:R},f.createElement(lW.Provider,{value:i},f.createElement(A0e.Provider,{value:x.current},f.createElement(M0e.Provider,{value:c},f.createElement(j0e,{basename:w,location:i.location,navigationType:i.historyAction,navigator:j,future:T},i.initialized||n.future.v7_partialHydration?f.createElement(D0e,{routes:n.routes,future:n.future,state:i}):t))))),null)}const D0e=f.memo(O0e);function O0e(e){let{routes:t,future:n,state:r}=e;return f0e(t,void 0,r,n)}var wE;(function(e){e.UseScrollRestoration="useScrollRestoration",e.UseSubmit="useSubmit",e.UseSubmitFetcher="useSubmitFetcher",e.UseFetcher="useFetcher",e.useViewTransitionState="useViewTransitionState"})(wE||(wE={}));var SE;(function(e){e.UseFetcher="useFetcher",e.UseFetchers="useFetchers",e.UseScrollRestoration="useScrollRestoration"})(SE||(SE={}));function F0e(e){let t=f.useRef(xS(e)),n=f.useRef(!1),r=_n(),i=f.useMemo(()=>C0e(r.search,n.current?null:t.current),[r.search]),s=qe(),a=f.useCallback((l,c)=>{const u=xS(typeof l=="function"?l(i):l);n.current=!0,s("?"+u,c)},[s,i]);return[i,a]}let SW=[];function _0e(e){SW=e}function z0e(e){return e.hash.startsWith("#/")?e.hash.slice(1).split(/[?#]/)[0]:e.pathname}function W0e(e){const t=e.join("/").replace(/\/{2,}/g,"/");return t.startsWith("/")?t:`/${t}`}function B0e(e,t=SW){const n=ia(t,e);if(!n)return null;const r=n.map(i=>i.route.path).filter(i=>!!i);return W0e(r).slice(0,80)}function $0e(){return typeof window>"u"?null:B0e(z0e(window.location))}const I0="1028-0011·b3440f0",H0e=[/^Script error\.?$/i,/^ResizeObserver loop/i];function kW(e){return e instanceof Error?{name:e.name||"Error",message:e.message,stack:e.stack??""}:{name:`NonError:${e===null?"null":typeof e}`,message:String(e),stack:""}}function A6(e,t,n=""){const r=kW(t);return{kind:"crash",crashKind:e,errorName:r.name.slice(0,200),message:r.message.slice(0,2e3),stack:`${r.stack}${n}`.slice(0,2e4),route:$0e(),buildStamp:I0.slice(0,60),uptimeS:typeof performance>"u"?null:Math.round(performance.now()/1e3)}}function jW(e){return H0e.some(t=>t.test(e))}function kE(e){if(jW(e.message??""))return;const t=e.error??new Error(e.message||"Unknown error");fs.enqueue(A6("windowError",t))}function jE(e){const t=kW(e.reason);jW(t.message)||fs.enqueue(A6("unhandledRejection",e.reason))}function U0e(e=window){return e.addEventListener("error",kE),e.addEventListener("unhandledrejection",jE),()=>{e.removeEventListener("error",kE),e.removeEventListener("unhandledrejection",jE)}}function CW(e,t){const n=t?`
125
125
  --- component stack ---${t}`:"";fs.enqueue(A6("renderError",e,n))}const V0e=6e4,q0e=5*6e4;function CE(){return typeof performance>"u"?null:Math.round(performance.now())}function K0e(){if(typeof performance>"u"||typeof performance.getEntriesByType!="function")return null;const e=performance.getEntriesByType("navigation")[0];return e&&e.responseStart>0?Math.round(e.responseStart):null}class G0e{constructor(t,n=K0e){Pe(this,"firstRenderMs",null);Pe(this,"sent",!1);Pe(this,"timer",null);this.enqueue=t,this.ttfb=n}markFirstRender(t=CE()){this.firstRenderMs!==null||this.sent||(this.firstRenderMs=t,this.timer=setTimeout(()=>this.send(null),V0e))}markInteractive(t=CE()){this.send(t)}send(t){this.sent||(this.sent=!0,this.timer!==null&&clearTimeout(this.timer),this.enqueue({kind:"load",ttfbMs:this.ttfb(),firstRenderMs:this.firstRenderMs,interactiveMs:t}))}}class Y0e{constructor(t,n=q0e){Pe(this,"count",0);Pe(this,"timer",null);this.enqueue=t,this.flushMs=n}record(){this.count+=1,this.timer===null&&(this.timer=setTimeout(()=>this.flush(),this.flushMs))}flush(){this.timer=null;const t=Math.min(this.count,1e3);this.count=0,t>0&&this.enqueue({kind:"sse_reconnect",count:t})}}const TW=e=>fs.enqueue(e),EW=new G0e(TW),Q0e=new Y0e(TW),X0e={minHeight:"100vh",display:"grid",placeItems:"center",padding:24,boxSizing:"border-box",background:"var(--proto-bg, Canvas)",color:"var(--proto-ink, CanvasText)",fontFamily:"inherit"},Z0e={fontSize:15,fontWeight:600,margin:0},J0e={fontSize:13,margin:"6px 0 14px",color:"var(--proto-muted, GrayText)"},eme={font:"inherit",fontSize:13,padding:"6px 14px",borderRadius:8,cursor:"pointer",border:"1px solid var(--proto-line-2, ButtonBorder)",background:"var(--proto-card, ButtonFace)",color:"inherit"};function RW({onReload:e=()=>window.location.reload()}){const t=Z();return o.jsx("div",{role:"alert","data-crash-fallback":!0,style:X0e,children:o.jsxs("div",{style:{textAlign:"center",maxWidth:360},children:[o.jsx("p",{style:Z0e,children:t.tmCrashTitle}),o.jsx("p",{style:J0e,children:t.tmCrashBody}),o.jsx("button",{type:"button",style:eme,onClick:e,children:t.tmCrashReload})]})})}function tme({children:e}){return f.useEffect(()=>EW.markFirstRender(),[]),o.jsx(o.Fragment,{children:e})}class nme extends f.Component{constructor(){super(...arguments);Pe(this,"state",{failed:!1})}static getDerivedStateFromError(){return{failed:!0}}componentDidCatch(n,r){CW(n,r.componentStack)}render(){return this.state.failed?o.jsx(RW,{}):o.jsx(tme,{children:this.props.children})}}function rme(){const e=gW();return f.useEffect(()=>{Fd(e)||CW(e,null)},[e]),o.jsx(RW,{})}function ime(e){return{errorElement:f.createElement(rme),...e}}function ome(e,t=bt()){const n=t?yW:E0e;return _0e(e),n(e.map(ime))}const sme=[{id:"sessions",path:"/m/sessions",home:"list"},{id:"project",path:"/m/project",home:"projects",parent:"sessions"},{id:"session",path:"/m/session/:sessionId",parent:"sessions"},{id:"plan",path:"/m/session/:sessionId/plan/:requestId",parent:"session"},{id:"approvals",path:"/m/approvals",parent:"project"},{id:"issues",path:"/m/issues",parent:"project"},{id:"notes",path:"/m/notes",parent:"project"},{id:"memory",path:"/m/memory",parent:"project"},{id:"memoryFile",path:"/m/memory/file",parent:"memory"},{id:"machines",path:"/m/machines",parent:"project"},{id:"settings",path:"/m/settings",parent:"project"},{id:"settingsAccounts",path:"/m/settings/accounts",parent:"settings"},{id:"settingsAppearance",path:"/m/settings/appearance",parent:"settings"},{id:"settingsPlatform",path:"/m/settings/platform",parent:"settings"},{id:"settingsModels",path:"/m/settings/models",parent:"settings"},{id:"settingsBudget",path:"/m/settings/budget",parent:"settings"},{id:"settingsMcp",path:"/m/settings/mcp",parent:"settings"},{id:"settingsNotifications",path:"/m/settings/notifications",parent:"settings"},{id:"settingsAdvanced",path:"/m/settings/advanced",parent:"settings"},{id:"settingsPrivacy",path:"/m/settings/privacy",parent:"settings"},{id:"settingsHooks",path:"/m/settings/hooks",parent:"settings"},{id:"settingsUsage",path:"/m/settings/usage",parent:"settings"},{id:"daemon",path:"/m/daemon",parent:"settings"}],P6=sme,I6=Object.fromEntries(P6.map(e=>[e.id,e]));function L6(e){return e.length>1?e.replace(/\/+$/,""):e}function N6(e){const t=L6(e);for(const n of P6){const r=hS({path:n.path,end:!0},t);if(r)return{route:n,params:r.params}}}function cc(e){return Jz(I6[e].path)}function ame(e){const t=N6(e),n=t==null?void 0:t.route.parent;if(!(!t||!n))return Jz(I6[n].path,t.params)}function Gx(e){var t;return((t=N6(e))==null?void 0:t.route.home)??null}function n1(e){return Gx(e)?I6.sessions.path:L6(e)}function lme(e,t){var n;if(t)switch(e.replace(/\/+$/,"")){case"/memory":return cc("memory");case"/overview":return cc("project");default:return cc("sessions")}switch((n=N6(e))==null?void 0:n.route.id){case"memory":case"memoryFile":return"/memory";case"project":return"/overview";default:return"/workbench"}}function TE({mobile:e,children:t}){const n=Hx(),r=_n();return n!==e?o.jsx(P0,{to:lme(r.pathname,n),replace:!0}):t}function MW(e){return e===""?1:e.split(`
126
126
  `).length}function cme(e){return[...e].length}function ume(e,t,n){return`${MW(e)} ${t} · ${cme(e)} ${n}`}const D6=20,O6=2,dme=D6+2*O6,yS=5*D6+2*O6;function fme(){return o.jsx("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:C.muted,strokeWidth:"1.5",children:o.jsx("path",{d:"M6 1h3v3M4 9H1V6M9 1 5.8 4.2M1 9l3.2-3.2"})})}function pme(){return o.jsx("svg",{width:"11",height:"11",viewBox:"0 0 10 10",fill:"none",stroke:C.muted,strokeWidth:"1.5",children:o.jsx("path",{d:"M9 1 5.8 4.2m0 0H8.6M5.8 4.2V1.4M1 9l3.2-3.2m0 0H1.4m2.8 0v2.8"})})}function AW({size:e=16,color:t="var(--ink-solid-fg)"}){return o.jsx("svg",{width:e,height:e,viewBox:"0 0 16 16",fill:"none",stroke:t,strokeWidth:"1.8",children:o.jsx("path",{d:"M8 13V3M3.5 7.5 8 3l4.5 4.5"})})}const PW={flex:"none",borderRadius:"50%",display:"flex",alignItems:"center",justifyContent:"center",boxSizing:"border-box",border:"none",padding:0};function IW({enabled:e,onSend:t,size:n=36}){const r=Z();return o.jsx("button",{type:"button","aria-label":r.cmSend,disabled:!e,onClick:t,style:{...PW,width:n,height:n,background:"var(--proto-gray)",opacity:e?1:.45,cursor:e?"pointer":"default"},children:o.jsx(AW,{size:14,color:C.ink})})}function LW({running:e,enabled:t,onSend:n,onStop:r,size:i=36}){const s=Z();return o.jsx("button",{type:"button","aria-label":e?s.stop:s.cmSend,disabled:!t,onClick:e?r:n,"data-armed":t?"true":"false",style:{...PW,width:i,height:i,background:t?C.inkSolid:"var(--proto-line-3)",cursor:t?"pointer":"default"},children:e?o.jsx("span",{style:{width:11,height:11,background:C.inkSolidFg,borderRadius:2.5}}):o.jsx(AW,{size:15})})}function hme(e,t,n){f.useEffect(()=>{const r=e.current;if(!r)return;r.style.height="auto";const i=r.scrollHeight;r.style.height=`${Math.min(i,yS)}px`,r.style.overflowY=i>yS?"auto":"hidden",n(i>dme+2)},[e,t,n])}const mme={position:"absolute",left:12,right:12,bottom:"calc(20px + env(safe-area-inset-bottom))",zIndex:4},gme="var(--shadow-chrome-rise), var(--shadow-chrome-float)";function vme(e,t){const n=e==="amber"?C.amber:e==="accent"||t?C.run:null;return{borderRadius:"var(--r-float)",background:C.glassRaised,backdropFilter:C.glassFilter,WebkitBackdropFilter:C.glassFilter,boxShadow:`${gme}, 0 0 0 1px ${n??"var(--proto-line)"}`,boxSizing:"border-box",padding:"12px 10px 10px 16px"}}function xme(e){return o.jsxs("div",{style:{position:"relative",display:"flex",alignItems:"center",padding:`0 ${e.showExpand?28:2}px 0 2px`},children:[o.jsx("textarea",{ref:e.textareaRef,rows:1,value:e.value,onChange:t=>{var n;return(n=e.onChange)==null?void 0:n.call(e,t.target.value)},onFocus:()=>e.onFocus(!0),onBlur:()=>e.onFocus(!1),placeholder:e.placeholder,style:{flex:1,minWidth:0,resize:"none",border:"none",outline:"none",background:"transparent",padding:`${O6}px 0`,margin:0,maxHeight:yS,fontSize:16,lineHeight:`${D6}px`,color:C.ink,fontFamily:"inherit",boxSizing:"border-box"}}),e.showExpand&&o.jsx(yme,{onClick:e.onExpand})]})}function yme({onClick:e}){const t=Z();return o.jsx("button",{type:"button","aria-label":t.cmExpand,onClick:e,style:{position:"absolute",top:1,right:0,width:22,height:22,borderRadius:"50%",background:"var(--m-gray)",border:"none",display:"flex",alignItems:"center",justifyContent:"center",cursor:"pointer"},children:o.jsx(fme,{})})}function bme(e){const t=e.running??!1;return o.jsxs("div",{"data-composer-toolbar":!0,style:{display:"flex",alignItems:"center",gap:6,marginTop:10},children:[e.leading,o.jsx("span",{style:{marginLeft:"auto",display:"flex",alignItems:"center",gap:6,minWidth:0,flex:"0 1 auto"},children:e.tools}),t&&o.jsx(IW,{enabled:e.sendEnabled??!0,onSend:e.onSend,size:32}),o.jsx(LW,{running:t,enabled:t?e.stopEnabled??!0:e.sendEnabled??!0,onSend:e.onSend,onStop:e.onStop,size:34})]})}function wme(e){return o.jsxs("div",{"data-composer-card":!0,style:vme(e.tone,e.focused),children:[o.jsx(xme,{...e}),o.jsx(bme,{...e})]})}function Sme(e){const t=f.useRef(null),[n,r]=f.useState(!1),[i,s]=f.useState(!1),[a,l]=f.useState(()=>MW(e.value??"")>1);hme(t,e.value,l);const c=i?o.jsx(Mme,{...e,value:e.value??"",onCollapse:()=>s(!1),onSend:()=>{var u;(u=e.onSend)==null||u.call(e),s(!1)},onCommandPick:()=>s(!1)}):null;return o.jsxs(o.Fragment,{children:[o.jsxs("div",{ref:e.shellRef,"data-composer-shell":!0,style:mme,children:[e.above,i?null:e.commandMenu,o.jsx(wme,{...e,focused:n,showExpand:a&&!i,textareaRef:t,onFocus:r,onExpand:()=>s(!0)})]}),c]})}const kme={position:"absolute",inset:0,zIndex:6,background:C.backdrop,padding:"8px 10px",paddingTop:"calc(8px + env(safe-area-inset-top))",paddingBottom:"calc(8px + env(safe-area-inset-bottom))",boxSizing:"border-box",display:"flex"},jme={flex:1,minWidth:0,position:"relative",display:"flex",flexDirection:"column",overflow:"hidden",border:`1.5px solid ${C.run}`,borderRadius:"var(--r-float)",background:C.card,boxShadow:"var(--shadow-panel)",boxSizing:"border-box"},Cme={flex:1,minHeight:0,resize:"none",border:"none",outline:"none",background:"transparent",padding:"14px 40px 8px 16px",margin:0,fontSize:16,lineHeight:"22px",color:C.ink,fontFamily:"inherit",boxSizing:"border-box"},EE={flex:"none",width:32,height:32,borderRadius:"50%",border:"none",padding:0,background:"var(--proto-gray)",display:"flex",alignItems:"center",justifyContent:"center",color:C.sub,cursor:"pointer"};function Tme({props:e,textareaRef:t}){const n=Z();return o.jsxs(o.Fragment,{children:[o.jsx("textarea",{ref:t,value:e.value,onChange:r=>{var i;return(i=e.onChange)==null?void 0:i.call(e,r.target.value)},placeholder:e.placeholder,style:Cme}),o.jsx("button",{type:"button","aria-label":n.cmCollapse,onClick:e.onCollapse,style:{position:"absolute",top:11,right:11,width:26,height:26,borderRadius:"50%",background:"var(--m-gray)",border:"none",display:"flex",alignItems:"center",justifyContent:"center",cursor:"pointer"},children:o.jsx(pme,{})})]})}function Eme({props:e,insertSlash:t}){const n=e.running??!1,r=Z();return o.jsxs("div",{style:{flex:"none",display:"flex",alignItems:"center",gap:10,padding:"8px 10px 8px 14px",borderTop:`1px solid ${C.divider}`},children:[o.jsx("button",{type:"button","aria-label":r.cmAttach,onClick:e.onPlus,style:EE,children:o.jsx(Ba,{})}),o.jsx("button",{type:"button","aria-label":r.chatSlashCommand,onClick:t,style:{...EE,font:`600 13px ${qn}`},children:"/"}),o.jsx("span",{style:{marginLeft:"auto",flex:"none",whiteSpace:"nowrap",fontSize:12,color:C.muted,fontVariantNumeric:"tabular-nums"},children:ume(e.value,e.lineUnit??r.chatLineUnit,e.charUnit??r.chatCharUnit)}),n&&o.jsx(IW,{enabled:e.sendEnabled??!0,onSend:e.onSend,size:32}),o.jsx(LW,{running:n,enabled:n?e.stopEnabled??!0:e.sendEnabled??!0,onSend:e.onSend,onStop:e.onStop,size:34})]})}function Rme(e){f.useEffect(()=>{const t=e.current;if(!t)return;t.focus();const n=t.value.length;t.setSelectionRange(n,n)},[e])}function Mme(e){const t=f.useRef(null);Rme(t);const n=()=>{var r;return(r=e.onChange)==null?void 0:r.call(e,e.value?`${e.value}/`:"/")};return o.jsx("div",{style:kme,children:o.jsxs("div",{style:jme,children:[o.jsx(Tme,{props:e,textareaRef:t}),e.commandMenu?o.jsx("div",{"data-fullscreen-command-menu":!0,onClick:e.onCommandPick,children:e.commandMenu}):null,o.jsx(Eme,{props:e,insertSlash:n})]})})}const Ame={},Pme={"--m-header-bg":C.glass,"--m-header-filter":C.glassFilter,"--m-header-edge":"0 1px 0 var(--proto-line)"};function Ime(e){const t=f.useRef(null),[n,r]=f.useState(0),[i,s]=f.useState(!1);return f.useLayoutEffect(()=>{const l=t.current;if(!e||!l)return;const c=()=>r(l.offsetHeight);if(c(),typeof ResizeObserver>"u")return;const u=new ResizeObserver(c);return u.observe(l),()=>u.disconnect()},[e]),{headerRef:t,clearance:n,scrolled:i,onScroll:l=>s(l.currentTarget.scrollTop>2)}}const Lme={height:"100%",minWidth:0,overflowWrap:"anywhere",position:"relative",display:"flex",flexDirection:"column",boxSizing:"border-box",background:"transparent"};function hl({header:e,footer:t,overlay:n,floatingHeader:r=!1,children:i,label:s,style:a}){const l=r&&e!=null,{headerRef:c,clearance:u,scrolled:d,onScroll:p}=Ime(l);return o.jsxs("div",{"data-screen-label":s,style:{...Lme,...l?{"--m-header-clearance":`${u}px`}:{},...a},children:[l?o.jsx("div",{ref:c,"data-floating-header":"true","data-scrolled":d?"true":"false",style:{position:"absolute",top:0,left:0,right:0,zIndex:5,pointerEvents:"none",...d?Pme:Ame},children:e}):e,o.jsx("div",{"data-m-scroller":"",onScroll:l?p:void 0,style:{flex:1,minHeight:0,overflow:"auto"},children:i}),t,n]})}const RE={fontSize:24,fontWeight:680,color:C.ink,letterSpacing:"-.01em",minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},Nme={display:"flex",alignItems:"center",gap:5,minWidth:0,minHeight:44,margin:0,padding:0,border:0,background:"transparent",color:"inherit",font:"inherit",cursor:"pointer"};function Dme({title:e,menu:t}){return t?o.jsxs("button",{type:"button","aria-label":`${t.label}: ${e}`,"aria-haspopup":"dialog",onClick:t.onOpen,style:Nme,children:[o.jsx("span",{style:RE,children:e}),o.jsx("svg",{width:14,height:14,viewBox:"0 0 10 10",fill:"none","aria-hidden":"true",style:{flex:"none",color:C.muted},children:o.jsx("path",{d:"M2.2 3.8 5 6.6l2.8-2.8",stroke:"currentColor",strokeWidth:1.5,strokeLinecap:"round",strokeLinejoin:"round"})})]}):o.jsx("span",{style:RE,children:e})}function Ome({text:e}){return o.jsx("span",{style:{fontSize:11,fontWeight:600,color:C.sub,background:"var(--proto-gray)",padding:"2px 7px",borderRadius:6,flex:"none"},children:e})}function Fme(e){return{flex:"none",pointerEvents:"auto",padding:`calc(6px + env(safe-area-inset-top)) ${jx}px ${e?12:6}px`,background:"var(--m-header-bg, transparent)",backdropFilter:"var(--m-header-filter, none)",WebkitBackdropFilter:"var(--m-header-filter, none)",boxShadow:"var(--m-header-edge, none)",transition:"background-color .2s, box-shadow .2s"}}function NW({title:e,titleMenu:t,leading:n,qn:r,trailing:i,below:s}){return o.jsxs("div",{"data-tab-header":"true",style:Fme(!!s),children:[o.jsxs("div",{style:{display:"flex",alignItems:"center",gap:9,minHeight:48,paddingLeft:14},children:[n,o.jsx(Dme,{title:e,menu:t}),r&&o.jsx(Ome,{text:r}),i&&o.jsx("div",{style:{marginLeft:"auto",display:"flex",alignItems:"center"},children:i})]}),s&&o.jsx("div",{style:{padding:"0 14px"},children:s})]})}function Ds({size:e=18}){return o.jsx("svg",{width:e,height:e,viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:1.8,strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:o.jsx("path",{d:"M10 3.5 5.5 8l4.5 4.5"})})}function L0({onBack:e,children:t,trailing:n}){const r=Z();return o.jsxs("div",{style:{flex:"none",display:"flex",alignItems:"center",flexWrap:"wrap",gap:8,padding:"8px 14px 10px",paddingTop:"calc(8px + env(safe-area-inset-top))"},children:[o.jsx("button",{type:"button","aria-label":r.back,onClick:e,style:{border:"none",background:"transparent",color:C.ink,padding:0,margin:"0 -6px 0 -10px",cursor:"pointer",flex:"none",minHeight:44,minWidth:44,display:"grid",placeItems:"center"},children:o.jsx(Ds,{})}),t,n&&o.jsx("div",{style:{marginLeft:"auto",minWidth:0,maxWidth:"100%",overflowWrap:"anywhere"},children:n})]})}function kf({children:e,gap:t=10,padding:n="12px 14px 0"}){return o.jsxs("div",{style:{padding:n,display:"flex",flexDirection:"column",gap:t},children:[o.jsx("div",{style:{height:"var(--m-header-clearance, 0px)",flex:"none",marginBottom:-t}}),e,o.jsx("div",{style:{height:"calc(20px + env(safe-area-inset-bottom))",flex:"none"}})]})}const _me={default:"transparent",blue:C.runBorder,amber:C.amberBorder,fail:C.failBorder},ME={background:"var(--m-float-bg)",boxShadow:"var(--m-float-ring), var(--m-float-shadow)"};function F6({tone:e="default",radius:t="var(--r-card)",padding:n="11px 13px",onClick:r,children:i,style:s}){return o.jsx("div",{onClick:r,style:{...ME,boxShadow:e==="default"?ME.boxShadow:"var(--m-float-shadow)",border:e==="default"?void 0:`1px solid ${_me[e]}`,borderRadius:t,padding:n,boxSizing:"border-box",minWidth:0,overflowWrap:"anywhere",cursor:r?"pointer":void 0,...s},children:i})}const zme={ink:{bg:C.inkSolid,fg:C.inkSolidFg},outline:{bg:"var(--material-control-bg)",fg:C.ink,line:"var(--proto-line-3)"},"danger-outline":{bg:"var(--material-control-bg)",fg:"var(--proto-danger)",line:"var(--proto-danger-bg)"}},Wme={padding:"0 8px",fontSize:15,borderRadius:"var(--r-control)",lineWidth:1},Bme={padding:"0 12px",fontSize:13,borderRadius:"var(--r-chip)",lineWidth:1};function pt({variant:e="outline",compact:t=!1,disabled:n,style:r,type:i="button",...s}){const a=zme[e],{lineWidth:l,...c}=t?Bme:Wme;return o.jsx("button",{type:i,disabled:n,style:{...c,height:44,display:"inline-flex",alignItems:"center",justifyContent:"center",gap:6,boxSizing:"border-box",background:a.bg,color:a.fg,border:a.line?`${l}px solid ${a.line}`:"none",boxShadow:a.line?"var(--material-control-shadow)":void 0,fontFamily:"inherit",fontWeight:600,cursor:n?"not-allowed":"pointer",opacity:n?.5:1,...r},...s})}function DW({title:e,meta:t,leading:n,sub:r,onExpand:i}){return o.jsxs(F6,{padding:"11px 14px",onClick:i,children:[o.jsxs("div",{style:{display:"flex",alignItems:"center",gap:7,overflow:"hidden"},children:[n,o.jsx("span",{style:{fontSize:13,fontWeight:600,color:C.body,flex:1,minWidth:0,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:e}),t&&o.jsx("span",{style:{fontSize:12,color:C.muted,flex:"none",...$e},children:t})]}),r&&o.jsx("div",{style:{fontSize:12,color:C.muted,marginTop:5,paddingLeft:2,...$e},children:r})]})}const $me={running:{bg:C.runBg,fg:C.run},waiting:{bg:C.amberBg,fg:C.amberInk},done:{bg:C.doneBg,fg:"color-mix(in srgb, var(--proto-success) 85%, var(--proto-ink))"},failed:{bg:C.failBg,fg:C.fail},cancelled:{bg:C.gray,fg:C.grayInk}};function OW({tone:e,children:t}){const n=$me[e];return o.jsx("span",{style:{fontSize:11,fontWeight:600,padding:"2px 8px",borderRadius:"var(--r-pill)",background:n.bg,color:n.fg,flex:"none",whiteSpace:"nowrap"},children:t})}function N0({color:e,size:t=6,style:n}){return o.jsx("span",{style:{width:t,height:t,borderRadius:"50%",background:e,flex:"none",display:"inline-block",...n}})}function Yx({children:e,style:t}){return o.jsx("div",{style:{fontSize:12,fontWeight:600,color:C.muted,padding:"0 14px 6px",...t},children:e})}function Xi({children:e,inset:t=14,style:n}){const r=f.Children.toArray(e).filter(f.isValidElement);return o.jsx("div",{"data-m-group":"",style:{minWidth:0,...n},children:r.map((i,s)=>o.jsxs(f.Fragment,{children:[s>0&&o.jsx("div",{"aria-hidden":"true",style:{height:1,marginLeft:t,background:"var(--proto-line)"}}),i]},i.key??s))})}function Hme({children:e}){return o.jsx("div",{style:{padding:"56px 24px",textAlign:"center",color:C.muted,fontSize:13},children:e})}const Ume={sameScreen:!0};function Vme(e,t){return e==="REPLACE"&&(t==null?void 0:t.sameScreen)===!0}function qme(e,t,n){return t?{animate:!1}:n?{animate:!0,dir:"back"}:e==="REPLACE"?{animate:!1}:{animate:!0,dir:e==="POP"?"back":"forward"}}function FW(e,t){return n1(e)===n1(t)}function l2(e){return Gx(e)!==null}function Kme(e,t,n){return t&&FW(t.key,n.key)?{current:t,retainedHome:null,returningToRetained:!0}:l2(e.key)&&!l2(n.key)?{current:n,retainedHome:e,returningToRetained:!1}:{current:n,retainedHome:l2(n.key)?null:t,returningToRetained:!1}}function Gme(e){return e==="forward"?{incoming:"animate-slide-in-right",outgoing:"animate-slide-out-left"}:{incoming:"animate-slide-in-left",outgoing:"animate-slide-out-right"}}function Yme(){return typeof window<"u"&&typeof window.matchMedia=="function"&&window.matchMedia("(prefers-reduced-motion: reduce)").matches}const _W={position:"absolute",inset:0,background:C.backdrop,zIndex:0},Qme={..._W,visibility:"hidden",pointerEvents:"none"};function Xme(e,t,n,r){const i=f.useRef(0),s=v=>({key:n1(v),element:r,id:`${i.current++}`}),[a,l]=f.useState(()=>s(e)),[c,u]=f.useState(null),[d,p]=f.useState(null),[h,m]=f.useState("forward");return f.useLayoutEffect(()=>{if(FW(e,a.key))return;if(Vme(t,n)){l({...a,key:n1(e),element:r});return}const v=s(e),g=Kme(a,c,v),x=qme(t,Yme(),g.returningToRetained);u(g.retainedHome),p(x.animate?a:null),x.animate&&m(x.dir),l(g.current)},[e]),{current:a,retainedHome:c,previous:d,dir:h,onSettled:()=>p(null)}}function c2({frame:e,role:t,className:n,hidden:r,onAnimationEnd:i}){return o.jsx("div",{"data-route-layer":t,"data-route-key":e.key,className:n,style:r?Qme:_W,"aria-hidden":t==="current"?void 0:!0,onAnimationEnd:i,children:e.element})}const u2=e=>e.id??e.key;function Zme({current:e,retainedHome:t,previous:n,dir:r,onSettled:i}){const s=Gme(r),a=t&&t.key!==(n==null?void 0:n.key)&&t.key!==e.key;return o.jsxs("div",{style:{position:"relative",height:"100%",overflow:"hidden"},children:[a&&o.jsx(c2,{frame:t,role:"retained",hidden:!0},u2(t)),n&&o.jsx(c2,{frame:n,role:"previous",className:s.outgoing},u2(n)),o.jsx(c2,{frame:e,role:"current",className:n?s.incoming:void 0,onAnimationEnd:n?i:void 0},u2(e))]})}function Jme(){const e=_n(),t=c0e(),n=dW(),r=Xme(e.pathname,t,e.state,n);return o.jsx(Zme,{...r})}function ege(e){return ame(e)??cc("sessions")}function tge(e,t,n=!1){if(t)return{kind:"history"};const r=Gx(e);return r==="list"?{kind:"exit"}:r==="projects"?{kind:"navigate",to:cc("sessions")}:n?{kind:"history"}:{kind:"navigate",to:ege(e)}}function zW(e,t){return e&&typeof(t==null?void 0:t.idx)=="number"&&t.idx>0}function Kt(e,t,n=(r=>(r=globalThis.history)==null?void 0:r.state)()??null){zW(!0,n)?e(-1):e(t,{replace:!0})}async function nge(e,t,n,r){const i=tge(e,t,n);if(!(!t&&r.canLeave&&!await r.canLeave())){if(i.kind==="history")return r.historyBack();if(i.kind==="exit")return void await r.exit();r.navigate(i.to,{replace:!0})}}function WW(e,t){t(cc(e?"project":"sessions"),{replace:!0})}function rge(e){return!e||typeof e!="object"?!1:Reflect.get(e,"canGoBack")===!0}async function ige(){await Ye("plugin:app|exit",{code:0})}const bS=new Set;async function oge(){for(const e of bS)if(!await e())return!1;return!0}function sge(e,t){const n=f.useRef({dirty:e,dialog:t});n.current={dirty:e,dialog:t};const r=f.useCallback(async()=>!n.current.dirty||T0(n.current.dialog),[]);return f.useEffect(()=>(bS.add(r),()=>{bS.delete(r)}),[r]),r}function age(){const e=window.history.state;return(e==null?void 0:e.__cortexOverlay)===!0}function lge(e,t){const n=f.useRef({pathname:e,navigate:t});n.current={pathname:e,navigate:t},f.useEffect(()=>ehe(r=>{if(Dde())return;const i=n.current,s=window.history.state,a=zW(rge(r),s);nge(i.pathname,age(),a,{historyBack:()=>window.history.back(),exit:ige,navigate:i.navigate,canLeave:oge}).catch(()=>{})}),[])}function cge(){const e=new Map,t=new Set,n=new Map,r=()=>{for(const i of[...t])i()};return{slot:i=>e.get(i),open:(i,s)=>{const a=e.get(i);a&&Object.is(a.payload,s)||(e.set(i,{payload:s}),r())},close:i=>{e.delete(i)&&r()},subscribe:i=>(t.add(i),()=>t.delete(i)),attachHost:i=>(n.set(i,(n.get(i)??0)+1),()=>{n.set(i,(n.get(i)??1)-1)})}}const uge={slot:()=>{},open:()=>{},close:()=>{},subscribe:()=>()=>{},attachHost:()=>()=>{}},BW=f.createContext(null);function dge({children:e}){const[t]=f.useState(cge);return o.jsx(BW.Provider,{value:t,children:e})}function Os(e,t={}){const n=t.requireProvider??!0;function r(){const s=f.useContext(BW);if(!s&&n)throw new Error(`modal "${e}" needs a <ModalRegistryProvider> above it`);return s??uge}function i(s){return f.useMemo(()=>({open:a=>s.open(e,a),close:()=>s.close(e)}),[s])}return{useModal(){const s=r(),a=i(s);f.useEffect(()=>s.attachHost(e),[s]);const l=f.useSyncExternalStore(s.subscribe,f.useCallback(()=>s.slot(e),[s]));return{isOpen:!!l,payload:l==null?void 0:l.payload,...a}},useModalActions(){return i(r())}}}function fge(e,t){var n;if(e.length>0){const r=[...e].sort((i,s)=>Date.parse(s.lastUsedAt||s.createdAt)-Date.parse(i.lastUsedAt||i.createdAt))[0];if(r!=null&&r.projectId)return r.projectId}return((n=t[0])==null?void 0:n.id)??null}function pge(e,t){return t?e.filter(n=>n.projectId===t):e}function Zi(e){const t=ve();return xe({...t.sessions.list.queryOptions({origin:e}),refetchOnMount:!1})}function Ga(e,t){const n=ve(),r=f.useCallback(i=>pge(i,e),[e]);return xe({...n.sessions.list.queryOptions({origin:t}),select:r,refetchOnMount:!1})}const $W=f.createContext(null);function hge({children:e}){const t=ve(),n=xe({...t.projects.list.queryOptions({}),refetchOnMount:!1}),r=Zi("direct");Zi("scheduled");const[i,s]=f.useState(null),[a,l]=f.useState([]),c=n.data??[],u=i??fge(r.data??[],c),d=r.isSuccess;f.useEffect(()=>{i===null&&d&&u&&s(u)},[i,d,u]);const p=f.useCallback(v=>s(v),[]),h=f.useCallback(v=>{l(g=>g.length===v.length&&g.every((x,y)=>x===v[y])?g:[...v])},[]),m=f.useMemo(()=>({currentProjectId:u,projects:c,projectOrder:a,setCurrentProject:p,setProjectOrder:h}),[u,c,a,p,h]);return o.jsx($W.Provider,{value:m,children:e})}function Wt(){const e=f.useContext($W);if(!e)throw new Error("useCurrentProject must be used within a CurrentProjectProvider");return e}const HW=f.createContext({canDock:!1,active:!1,activeKind:null,activeBoardId:null,activeAgentBrowserSession:null,openFile:()=>{},openWeb:()=>{},openBoard:()=>{},openAgentBrowser:()=>{}}),mge=HW.Provider;function Bo(){return f.useContext(HW)}function UW(e){kx(e),f.useEffect(()=>{const t=r=>{r.key==="Escape"&&e()};window.addEventListener("keydown",t);const n=document.body.style.overflow;return document.body.style.overflow="hidden",()=>{window.removeEventListener("keydown",t),document.body.style.overflow=n}},[e])}function gge(e,t){const n=t?t.indexOf(e):-1;return n<0?{items:[e],index:0}:{items:t,index:n}}function vge(e,t){if(!e)return null;const n=Math.min(Math.max(e.index+t,0),e.items.length-1);return n===e.index?e:{...e,index:n}}function VW(){const[e,t]=f.useState(null),n=Bo(),r=e?e.items[e.index]:null,i=f.useCallback((c,u)=>{if(n.active){n.openFile(c);return}t(gge(c,u))},[n]),s=f.useCallback(c=>t(u=>vge(u,c)),[]),a=f.useCallback(()=>t(null),[]),l=n.canDock?()=>{r&&n.openFile(r),t(null)}:void 0;return{item:r,index:(e==null?void 0:e.index)??0,count:(e==null?void 0:e.items.length)??0,open:i,step:s,close:a,pin:l}}const xge="/api/files/download",yge="/api/boards/asset",wS="board:";function bge(e,t){return`${wS}${encodeURIComponent(e)}/${t}`}function wge(e){if(!e.startsWith(wS))return null;const t=e.slice(wS.length),n=t.indexOf("/");return n<=0?null:{projectId:decodeURIComponent(t.slice(0,n)),relPath:t.slice(n+1)}}function qW(e,t,n="inline"){const r=new URLSearchParams({projectId:e,path:t,disposition:n});return`${ro()}${yge}?${r.toString()}`}function r1(e,t="attachment"){const n=wge(e);if(n)return qW(n.projectId,n.relPath,t);const r=new URLSearchParams({path:e,disposition:t});return`${ro()}${xge}?${r.toString()}`}async function Qx(e,t="inline",n){const r=await fetch(r1(e,t),{headers:Io(),signal:n});if(!r.ok)throw new Error(`HTTP ${r.status}`);const i=await r.blob();return URL.createObjectURL(i)}function i1(e){if(!e.ok&&e.reason==="failed")throw e.error}async function Sge(e,t){if(Pn()){const s=await Ye("plugin:cortex-download|download",{url:r1(e,"attachment"),fileName:t,token:Io()["x-cortex-token"]});return i1(s),s.ok?{}:null}const n=await fetch(r1(e,"attachment"),{headers:Io()});if(!n.ok)throw new Error(`HTTP ${n.status}`);const r=Array.from(new Uint8Array(await n.arrayBuffer())),i=await Ye("save_download",{name:t,bytes:r});return i1(i),i.ok?{savedPath:i.value}:null}function kge(e,t){const n=document.createElement("a");n.href=e,n.download=t,document.body.appendChild(n),n.click(),n.remove(),setTimeout(()=>URL.revokeObjectURL(e),1e4)}async function o1(e,t){const n=t??e.split("/").pop()??"download";if(bt()&&k6("invoke")){const i=await Sge(e,n);if(i)return i}const r=await Qx(e,"attachment");return kge(r,n),{}}async function jge(e){if(!bt())return;const t=await Ye("open_path",{path:e});i1(t)}async function KW(e){if(!bt())return;const t=await Ye("reveal_path",{path:e});i1(t)}const Cge=new Set(["localhost","127.0.0.1","[::1]"]);function Tge(){var e;if(!sr())return!1;try{return Cge.has(new URL(((e=ni())==null?void 0:e.serverUrl)??"").hostname)}catch{return!1}}function s1(e){return typeof e=="string"?e:e instanceof Error?e.message:String(e)}function GW(e){var n;const t=/^([A-Za-z][A-Za-z0-9_]*)(?::\s*([\s\S]*))?$/.exec(e.trim());return t?{code:t[1],detail:((n=t[2])==null?void 0:n.trim())||null}:null}function Xx(e,t){const n=s1(e),r=GW(n),i=r&&Object.hasOwn(t,r.code)?t[r.code]:void 0;return!r||!i?n:r.detail?`${i} (${r.detail})`:i}function Ege(e,t){return Xx(e,{download_dir_unavailable:t.downloadErrDir,download_dir_create_failed:t.downloadErrCreateDir,download_write_failed:t.downloadErrWrite})}function $c(){const e=pl(),t=Z();return f.useCallback((n,r)=>{(async()=>{if(Pn()){await o1(n,r).catch(()=>{});return}const i=r??n.split("/").pop()??n;try{const{savedPath:s}=await o1(n,r),a=s?[{label:t.wbFileOpenFile,onClick:()=>void jge(s)},{label:t.wbFileOpenFolder,onClick:()=>void KW(s)}]:void 0;e==null||e.toast({title:t.wbFileDownloadDone,description:s?t.wbFileSavedTo.replace("{path}",s):i,tone:"done",duration:a?1e4:void 0,actions:a})}catch(s){e==null||e.toast({title:t.wbFileDownloadFailed,description:Ege(s,t),tone:"failed"})}})()},[e,t])}function YW(e){const[t,n]=f.useState(e.url??null),[r,i]=f.useState(!1);return f.useEffect(()=>{if(e.url){n(e.url),i(!1);return}if(!e.path)return;let s=!0,a=null;return n(null),i(!1),Qx(e.path,"inline").then(l=>{s?(a=l,n(l)):URL.revokeObjectURL(l)}).catch(()=>{s&&i(!0)}),()=>{s=!1,a&&URL.revokeObjectURL(a)}},[e.path,e.url]),{src:t,failed:r}}const Rge=4;function Mge(){const e=t=>{t.stopPropagation(),t.preventDefault()};window.addEventListener("click",e,{capture:!0,once:!0}),setTimeout(()=>window.removeEventListener("click",e,{capture:!0}),0)}function Age(e,t){const n=t.clientX-e.startX,r=t.clientY-e.startY;return Math.hypot(n,r)>Rge&&(e.moved=!0),{x:e.tx+n,y:e.ty+r}}function Pge(e,t){let n=null;const r=l=>{n&&t.setTranslate(Age(n,l))},i=()=>{window.removeEventListener("mousemove",r),window.removeEventListener("mouseup",s);const l=(n==null?void 0:n.moved)??!1;return n&&t.onDragChange(!1),n=null,l};function s(){i()&&Mge()}const a=l=>{const c=t.getZoom();l.button!==0||c.scale<=1||!t.hasContent()||(l.preventDefault(),n={startX:l.clientX,startY:l.clientY,tx:c.x,ty:c.y,moved:!1},t.onDragChange(!0),window.addEventListener("mousemove",r),window.addEventListener("mouseup",s))};return e.addEventListener("mousedown",a),()=>{e.removeEventListener("mousedown",a),i()}}function Ige(e,t,n){const[r,i]=f.useState(!1),{getZoom:s,hasContent:a,setTranslate:l}=n;return f.useEffect(()=>{if(!(!e||!t))return Pge(e,{getZoom:s,hasContent:a,setTranslate:l,onDragChange:i})},[e,t,s,a,l]),r}const AE=.4,Lge=250,Nge=10,Dge=300,Oge=40,QW=(e,t)=>Math.hypot(t.x-e.x,t.y-e.y);function Fge(e,t){return t.t-e.t<=Lge&&QW(e,t)<=Nge}function _ge(e,t){return e!==null&&t.t-e.t<=Dge&&QW(e,t)<=Oge}function zge(e,t){return e==="transform"?!0:t.ctrlKey||t.metaKey}function PE(e,t,n,r){if(t<=1)return{scale:1,x:0,y:0};const i=t/e.scale;return{scale:t,x:e.x+(1-i)*(n.x-r.x),y:e.y+(1-i)*(n.y-r.y)}}function Wge(e,t,n,r,i,s){if(i<=1)return{scale:1,x:0,y:0};const a=i/e;return{scale:i,x:t.x+(r.x-n.x)+(n.x-s.x)*(1-a),y:t.y+(r.y-n.y)+(n.y-s.y)*(1-a)}}function _6(e={}){const{maxScale:t=5,mode:n="transform"}=e,[r,i]=f.useState({scale:1,x:0,y:0}),[s,a]=f.useState(null),l=f.useRef(null),c=f.useRef(r);c.current=r;const u=f.useRef(null),d=f.useRef(null),p=f.useRef(null),h=f.useCallback(A=>Math.min(t,Math.max(1,A)),[t]),m=f.useCallback(()=>{!s||n!=="css-zoom"||(u.current={ox:s.clientWidth/2,oy:s.clientHeight/2,scrollLeft:s.scrollLeft,scrollTop:s.scrollTop,prevScale:c.current.scale})},[s,n]),v=f.useCallback(()=>{m(),i(A=>({...A,scale:Math.min(t,A.scale+AE)}))},[t,m]),g=f.useCallback(()=>{m(),i(A=>{const P=Math.max(1,A.scale-AE);return P<=1?{scale:1,x:0,y:0}:{...A,scale:P}})},[m]),x=f.useCallback(()=>{m(),i({scale:1,x:0,y:0})},[m]),y=f.useCallback(A=>{a(A)},[]),b=f.useCallback(A=>{l.current=A},[]),S=f.useCallback(()=>c.current,[]),j=f.useCallback(()=>l.current!==null,[]),w=f.useCallback(A=>{i(P=>P.scale>1?{...P,...A}:P)},[]),R=Ige(s,n==="transform",{getZoom:S,hasContent:j,setTranslate:w});f.useLayoutEffect(()=>{if(!s||n!=="css-zoom"||!u.current)return;const{ox:A,oy:P,scrollLeft:L,scrollTop:F,prevScale:B}=u.current,K=r.scale;if(u.current=null,B===K)return;const V=K/B;s.scrollLeft=(L+A)*V-A,s.scrollTop=(F+P)*V-P},[r.scale,s,n]),f.useEffect(()=>{if(!s)return;const A=Y=>{var ne;if(!zge(n,Y))return;Y.preventDefault();const U=s.getBoundingClientRect();if(n==="css-zoom"){u.current={ox:Y.clientX-U.left,oy:Y.clientY-U.top,scrollLeft:s.scrollLeft,scrollTop:s.scrollTop,prevScale:c.current.scale},i(te=>{const se=1+(Y.deltaY<0?1:-1)*.12;return{...te,scale:h(te.scale*se)}});return}const ie=(ne=l.current)==null?void 0:ne.getBoundingClientRect(),de={x:(ie==null?void 0:ie.left)??U.left,y:(ie==null?void 0:ie.top)??U.top};i(te=>{const se=1+(Y.deltaY<0?1:-1)*.12,ke=h(te.scale*se);return PE(te,ke,{x:Y.clientX,y:Y.clientY},de)})},P=Y=>{var U;if(Y.touches.length===2){Y.preventDefault();const[ie,de]=[Y.touches[0],Y.touches[1]],ne=Math.hypot(de.clientX-ie.clientX,de.clientY-ie.clientY),te={x:(ie.clientX+de.clientX)/2,y:(ie.clientY+de.clientY)/2},H=c.current,se=(U=l.current)==null?void 0:U.getBoundingClientRect();d.current={initialDist:ne,initialScale:H.scale,initialMid:te,initialTranslate:{x:H.x,y:H.y},startTopLeft:{x:(se==null?void 0:se.left)??0,y:(se==null?void 0:se.top)??0}}}},L=Y=>{if(Y.touches.length===2&&d.current){Y.preventDefault();const[U,ie]=[Y.touches[0],Y.touches[1]],de=Math.hypot(ie.clientX-U.clientX,ie.clientY-U.clientY),ne={x:(U.clientX+ie.clientX)/2,y:(U.clientY+ie.clientY)/2},te=de/d.current.initialDist,H=h(d.current.initialScale*te);if(n==="css-zoom"){const se=s.getBoundingClientRect();u.current={ox:ne.x-se.left,oy:ne.y-se.top,scrollLeft:s.scrollLeft,scrollTop:s.scrollTop,prevScale:c.current.scale},i(ke=>({...ke,scale:H}))}else{const se=d.current;i(Wge(se.initialScale,se.initialTranslate,se.initialMid,ne,H,se.startTopLeft))}}},F=Y=>{Y.touches.length<2&&(d.current=null)};let B=null,K=null;const V=Y=>({t:Date.now(),x:Y.clientX,y:Y.clientY}),Q=Y=>{var ie;if(Y.touches.length!==1){K=null,B=null;return}const U=V(Y.touches[0]);if(K=U,_ge(B,U)){K=null,B=null,Y.preventDefault();const de=c.current;if(de.scale>1)n==="css-zoom"&&(u.current={ox:s.clientWidth/2,oy:s.clientHeight/2,scrollLeft:s.scrollLeft,scrollTop:s.scrollTop,prevScale:de.scale}),i({scale:1,x:0,y:0});else if(n==="css-zoom"){const ne=s.getBoundingClientRect();u.current={ox:Y.touches[0].clientX-ne.left,oy:Y.touches[0].clientY-ne.top,scrollLeft:s.scrollLeft,scrollTop:s.scrollTop,prevScale:de.scale},i({scale:2,x:0,y:0})}else{const ne=s.getBoundingClientRect(),te=(ie=l.current)==null?void 0:ie.getBoundingClientRect(),H={x:(te==null?void 0:te.left)??ne.left,y:(te==null?void 0:te.top)??ne.top};i(PE({scale:1,x:0,y:0},2,{x:Y.touches[0].clientX,y:Y.touches[0].clientY},H))}}},re=Y=>{if(K&&Y.touches.length===0&&Y.changedTouches.length===1){const U=V(Y.changedTouches[0]);B=Fge(K,U)?U:null}K=null},ue=Y=>{if(n!=="transform"||Y.touches.length!==1)return;const U=c.current;U.scale<=1||(p.current={startX:Y.touches[0].clientX,startY:Y.touches[0].clientY,startTranslateX:U.x,startTranslateY:U.y})},z=Y=>{const U=p.current;if(!U||Y.touches.length!==1)return;Y.preventDefault();const ie=U.startTranslateX+Y.touches[0].clientX-U.startX,de=U.startTranslateY+Y.touches[0].clientY-U.startY;i(ne=>ne.scale>1?{...ne,x:ie,y:de}:ne)},J=()=>{p.current=null},ee=()=>{d.current=null,p.current=null,K=null,B=null};return s.addEventListener("wheel",A,{passive:!1}),s.addEventListener("touchstart",P,{passive:!1}),s.addEventListener("touchstart",Q,{passive:!1}),s.addEventListener("touchstart",ue,{passive:!1}),s.addEventListener("touchmove",L,{passive:!1}),s.addEventListener("touchmove",z,{passive:!1}),s.addEventListener("touchend",F),s.addEventListener("touchend",J),s.addEventListener("touchend",re),s.addEventListener("touchcancel",ee),()=>{s.removeEventListener("wheel",A),s.removeEventListener("touchstart",P),s.removeEventListener("touchstart",Q),s.removeEventListener("touchstart",ue),s.removeEventListener("touchmove",L),s.removeEventListener("touchmove",z),s.removeEventListener("touchend",F),s.removeEventListener("touchend",J),s.removeEventListener("touchend",re),s.removeEventListener("touchcancel",ee)}},[s,h,n]);const T=n==="transform"?{transform:`translate(${r.x}px, ${r.y}px) scale(${r.scale})`,transformOrigin:"0 0",touchAction:"none",cursor:r.scale>1?R?"grabbing":"grab":void 0}:{transform:`scale(${r.scale})`,transformOrigin:"top left"};return{containerRef:y,contentRef:b,zoom:r,style:T,zoomIn:v,zoomOut:g,resetZoom:x,isZoomed:r.scale>1}}const Bge=60,$ge=1.5,Hge={ArrowLeft:-1,ArrowRight:1};function Uge(e,t){const n=t.x-e.x,r=t.y-e.y;return Math.abs(n)<Bge||Math.abs(n)<$ge*Math.abs(r)?0:n<0?1:-1}function Vge(e){return Hge[e]??0}const XW=e=>(e==null?void 0:e.tagName)==="VIDEO",IE=e=>({x:e.clientX,y:e.clientY});function qge(e,t){f.useEffect(()=>{if(!t)return;const n=r=>{const i=Vge(r.key);i===0||XW(r.target)||(r.preventDefault(),e(i))};return window.addEventListener("keydown",n),()=>window.removeEventListener("keydown",n)},[e,t])}function Kge(e,t){const n=f.useRef(null);return{onTouchStart:r=>{const i=r.touches.length===1&&!XW(r.target);n.current=t&&i?IE(r.touches[0]):null},onTouchEnd:r=>{const i=n.current;if(n.current=null,!i||r.touches.length!==0)return;const s=Uge(i,IE(r.changedTouches[0]));s!==0&&e(s)}}}function Gge(e,t,n){return qge(e,t),Kge(e,t&&!n)}const ZW=f.createContext({openMedia:()=>{}}),JW="'IBM Plex Mono',monospace",SS={maxWidth:"94vw",maxHeight:"84vh"},Gg={borderRadius:"var(--r-control)",background:"var(--media-control-bg)",color:"var(--ink-solid-fg)"},Yge={position:"fixed",inset:0,zIndex:4e3,background:"var(--media-backdrop)",display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",padding:"max(24px, env(safe-area-inset-top)) 16px max(24px, env(safe-area-inset-bottom))",boxSizing:"border-box",animation:"cxfade .18s ease both"},Nh=e=>e.stopPropagation();function Qge(){const e=$c();return t=>{if(t.path)e(t.path,t.name);else if(t.url){const n=document.createElement("a");n.href=t.url,n.download=t.name,document.body.appendChild(n),n.click(),n.remove()}}}function Xge({item:e,onClose:t,onPin:n}){const r=Z(),i=Qge();return o.jsxs("div",{onClick:Nh,style:{position:"absolute",top:"max(14px, env(safe-area-inset-top))",right:14,display:"flex",gap:10,zIndex:2},children:[n&&o.jsx(rt,{label:r.mediaPin,size:38,onClick:n,style:{...Gg,fontSize:15},children:"◧"}),o.jsx(rt,{label:r.cmDownload,size:38,onClick:()=>i(e),style:{...Gg,fontSize:16},children:"↓"}),o.jsx(rt,{label:r.cmClose,size:38,onClick:t,style:{...Gg,fontSize:18},children:"×"})]})}function Zge({item:e,src:t,failed:n,zoom:r}){const i=Z(),s={color:"var(--media-overlay-fg)",font:`500 12px ${JW}`};return n?o.jsx("div",{style:s,children:i.cmLoadFailed.replace("{name}",e.name)}):t?e.kind==="video"?o.jsx("video",{src:t,controls:!0,autoPlay:!0,playsInline:!0,style:{...SS,background:"var(--media-stage-bg)"}},t):o.jsx("div",{ref:r.contentRef,style:{...r.style,display:"inline-block"},children:o.jsx("img",{src:t,alt:e.name,draggable:!1,style:{...SS,objectFit:"contain",display:"block"}})}):o.jsx("div",{style:s,children:i.cmLoading})}function Jge({item:e,zoom:t,swipe:n}){const{src:r,failed:i}=YW(e);return o.jsx("div",{ref:t.containerRef,onClick:Nh,...n,style:{...SS,width:"94vw",height:"84vh",display:"flex",alignItems:"center",justifyContent:"center",overflow:"hidden"},children:o.jsx(Zge,{item:e,src:r,failed:i,zoom:t})})}function eve({index:e,count:t,onStep:n}){const r=Z(),i=s=>({...Gg,position:"absolute",top:"50%",[s]:14,transform:"translateY(-50%)",fontSize:22,zIndex:2});return o.jsxs(o.Fragment,{children:[e>0&&o.jsx(rt,{label:r.mediaPrevItem,size:38,onClick:s=>{Nh(s),n(-1)},style:i("left"),children:"‹"}),e<t-1&&o.jsx(rt,{label:r.mediaNextItem,size:38,onClick:s=>{Nh(s),n(1)},style:i("right"),children:"›"})]})}function tve({name:e,index:t,count:n}){return o.jsx("div",{onClick:Nh,style:{position:"absolute",bottom:"max(16px, env(safe-area-inset-bottom))",left:0,right:0,textAlign:"center",color:"var(--media-caption-fg)",font:`500 11px ${JW}`,padding:"0 20px",pointerEvents:"none"},children:n>1?`${t+1} / ${n} · ${e}`:e})}function nve({item:e,index:t,count:n,onStep:r,onClose:i,onPin:s}){const a=_6({mode:"transform",maxScale:8}),{isZoomed:l,resetZoom:c}=a;UW(i);const u=p=>{t+p<0||t+p>=n||(c(),r(p))},d=Gge(u,n>1,l);return o.jsxs("div",{className:"content-surface",role:"dialog","aria-modal":"true","aria-label":e.name,onClick:()=>{l?c():i()},style:Yge,children:[o.jsx(Xge,{item:e,onClose:i,onPin:s}),o.jsx(Jge,{item:e,zoom:a,swipe:d}),n>1&&o.jsx(eve,{index:t,count:n,onStep:u}),o.jsx(tve,{name:e.name,index:t,count:n})]})}function rve({children:e}){const{item:t,index:n,count:r,open:i,step:s,close:a,pin:l}=VW(),c=f.useMemo(()=>({openMedia:i}),[i]);return o.jsxs(ZW.Provider,{value:c,children:[e,t&&o.jsx(nve,{item:t,index:n,count:r,onStep:s,onClose:a,onPin:l})]})}function ml(){return f.useContext(ZW)}class pe extends Error{constructor(t,n){var r="KaTeX parse error: "+t,i,s,a=n&&n.loc;if(a&&a.start<=a.end){var l=a.lexer.input;i=a.start,s=a.end,i===l.length?r+=" at end of input: ":r+=" at position "+(i+1)+": ";var c=l.slice(i,s).replace(/[^]/g,"$&̲"),u;i>15?u="…"+l.slice(i-15,i):u=l.slice(0,i);var d;s+15<l.length?d=l.slice(s,s+15)+"…":d=l.slice(s),r+=u+c+d}super(r),this.name="ParseError",this.position=void 0,this.length=void 0,this.rawMessage=void 0,Object.setPrototypeOf(this,pe.prototype),this.position=i,i!=null&&s!=null&&(this.length=s-i),this.rawMessage=t}}var ive=/([A-Z])/g,ove=e=>e.replace(ive,"-$1").toLowerCase(),sve={"&":"&amp;",">":"&gt;","<":"&lt;",'"':"&quot;","'":"&#x27;"},ave=/[&><"']/g,rr=e=>String(e).replace(ave,t=>sve[t]),Yg=e=>e.type==="ordgroup"||e.type==="color"?e.body.length===1?Yg(e.body[0]):e:e.type==="font"?Yg(e.body):e,lve=new Set(["mathord","textord","atom"]),Fs=e=>lve.has(Yg(e).type),cve=e=>{var t=/^[\x00-\x20]*([^\\/#?]*?)(:|&#0*58|&#x0*3a|&colon)/i.exec(e);return t?t[2]!==":"||!/^[a-zA-Z][a-zA-Z0-9+\-.]*$/.test(t[1])?null:t[1].toLowerCase():"_relative"},kS={displayMode:{type:"boolean",description:"Render math in display mode, which puts the math in display style (so \\int and \\sum are large, for example), and centers the math on the page on its own line.",cli:"-d, --display-mode"},output:{type:{enum:["htmlAndMathml","html","mathml"]},description:"Determines the markup language of the output.",cli:"-F, --format <type>"},leqno:{type:"boolean",description:"Render display math in leqno style (left-justified tags)."},fleqn:{type:"boolean",description:"Render display math flush left."},throwOnError:{type:"boolean",default:!0,cli:"-t, --no-throw-on-error",cliDescription:"Render errors (in the color given by --error-color) instead of throwing a ParseError exception when encountering an error."},errorColor:{type:"string",default:"#cc0000",cli:"-c, --error-color <color>",cliDescription:"A color string given in the format 'rgb' or 'rrggbb' (no #). This option determines the color of errors rendered by the -t option.",cliProcessor:e=>"#"+e},macros:{type:"object",cli:"-m, --macro <def>",cliDescription:"Define custom macro of the form '\\foo:expansion' (use multiple -m arguments for multiple macros).",cliDefault:[],cliProcessor:(e,t)=>(t.push(e),t)},minRuleThickness:{type:"number",description:"Specifies a minimum thickness, in ems, for fraction lines, `\\sqrt` top lines, `{array}` vertical lines, `\\hline`, `\\hdashline`, `\\underline`, `\\overline`, and the borders of `\\fbox`, `\\boxed`, and `\\fcolorbox`.",processor:e=>Math.max(0,e),cli:"--min-rule-thickness <size>",cliProcessor:parseFloat},colorIsTextColor:{type:"boolean",description:"Makes \\color behave like LaTeX's 2-argument \\textcolor, instead of LaTeX's one-argument \\color mode change.",cli:"-b, --color-is-text-color"},strict:{type:[{enum:["warn","ignore","error"]},"boolean","function"],description:"Turn on strict / LaTeX faithfulness mode, which throws an error if the input uses features that are not supported by LaTeX.",cli:"-S, --strict",cliDefault:!1},trust:{type:["boolean","function"],description:"Trust the input, enabling all HTML features such as \\url.",cli:"-T, --trust"},maxSize:{type:"number",default:1/0,description:"If non-zero, all user-specified sizes, e.g. in \\rule{500em}{500em}, will be capped to maxSize ems. Otherwise, elements and spaces can be arbitrarily large",processor:e=>Math.max(0,e),cli:"-s, --max-size <n>",cliProcessor:parseInt},maxExpand:{type:"number",default:1e3,description:"Limit the number of macro expansions to the specified number, to prevent e.g. infinite macro loops. If set to Infinity, the macro expander will try to fully expand as in LaTeX.",processor:e=>Math.max(0,e),cli:"-e, --max-expand <n>",cliProcessor:e=>e==="Infinity"?1/0:parseInt(e)},globalGroup:{type:"boolean",cli:!1}};function uve(e){if(typeof e!="string")return e.enum[0];switch(e){case"boolean":return!1;case"string":return"";case"number":return 0;case"object":return{};default:throw new Error("Unexpected schema type; settings must declare an explicit default.")}}function dve(e){if(Object.prototype.hasOwnProperty.call(e,"default")&&e.default!==void 0)return e.default;var t=Array.isArray(e.type)?e.type[0]:e.type;return uve(t)}function fve(e,t,n,r){var i=Object.prototype.hasOwnProperty.call(n,t)?n[t]:void 0,s=Object.prototype.hasOwnProperty.call(r,"processor")?r.processor:void 0;e[t]=i!==void 0?s?s(i):i:dve(r)}class z6{constructor(t){t===void 0&&(t={}),this.displayMode=void 0,this.output=void 0,this.leqno=void 0,this.fleqn=void 0,this.throwOnError=void 0,this.errorColor=void 0,this.macros=void 0,this.minRuleThickness=void 0,this.colorIsTextColor=void 0,this.strict=void 0,this.trust=void 0,this.maxSize=void 0,this.maxExpand=void 0,this.globalGroup=void 0,t=t||{};for(var n of Object.keys(kS)){var r=kS[n];r&&fve(this,n,t,r)}}reportNonstrict(t,n,r){var i=this.strict;if(typeof i=="function"&&(i=i(t,n,r)),!(!i||i==="ignore")){if(i===!0||i==="error")throw new pe("LaTeX-incompatible input and strict mode is set to 'error': "+(n+" ["+t+"]"),r);i==="warn"?typeof console<"u"&&console.warn("LaTeX-incompatible input and strict mode is set to 'warn': "+(n+" ["+t+"]")):typeof console<"u"&&console.warn("LaTeX-incompatible input and strict mode is set to "+("unrecognized '"+i+"': "+n+" ["+t+"]"))}}useStrictBehavior(t,n,r){var i=this.strict;if(typeof i=="function")try{i=i(t,n,r)}catch{i="error"}return!i||i==="ignore"?!1:i===!0||i==="error"?!0:i==="warn"?(typeof console<"u"&&console.warn("LaTeX-incompatible input and strict mode is set to 'warn': "+(n+" ["+t+"]")),!1):(typeof console<"u"&&console.warn("LaTeX-incompatible input and strict mode is set to "+("unrecognized '"+i+"': "+n+" ["+t+"]")),!1)}isTrusted(t){if("url"in t&&t.url&&!t.protocol){var n=cve(t.url);if(n==null)return!1;t.protocol=n}var r=typeof this.trust=="function"?this.trust(t):this.trust;return!!r}}class Hs{constructor(t,n,r){this.id=void 0,this.size=void 0,this.cramped=void 0,this.id=t,this.size=n,this.cramped=r}sup(){return bo[pve[this.id]]}sub(){return bo[hve[this.id]]}fracNum(){return bo[mve[this.id]]}fracDen(){return bo[gve[this.id]]}cramp(){return bo[vve[this.id]]}text(){return bo[xve[this.id]]}isTight(){return this.size>=2}}var W6=0,a1=1,rd=2,ps=3,Dh=4,yi=5,_d=6,gr=7,bo=[new Hs(W6,0,!1),new Hs(a1,0,!0),new Hs(rd,1,!1),new Hs(ps,1,!0),new Hs(Dh,2,!1),new Hs(yi,2,!0),new Hs(_d,3,!1),new Hs(gr,3,!0)],pve=[Dh,yi,Dh,yi,_d,gr,_d,gr],hve=[yi,yi,yi,yi,gr,gr,gr,gr],mve=[rd,ps,Dh,yi,_d,gr,_d,gr],gve=[ps,ps,yi,yi,gr,gr,gr,gr],vve=[a1,a1,ps,ps,yi,yi,gr,gr],xve=[W6,a1,rd,ps,rd,ps,rd,ps],Xe={DISPLAY:bo[W6],TEXT:bo[rd],SCRIPT:bo[Dh],SCRIPTSCRIPT:bo[_d]},jS=[{name:"latin",blocks:[[256,591],[768,879]]},{name:"cyrillic",blocks:[[1024,1279]]},{name:"armenian",blocks:[[1328,1423]]},{name:"brahmic",blocks:[[2304,4255]]},{name:"georgian",blocks:[[4256,4351]]},{name:"cjk",blocks:[[12288,12543],[19968,40879],[65280,65376]]},{name:"hangul",blocks:[[44032,55215]]}];function yve(e){for(var t=0;t<jS.length;t++)for(var n=jS[t],r=0;r<n.blocks.length;r++){var i=n.blocks[r];if(e>=i[0]&&e<=i[1])return n.name}return null}var Qg=[];jS.forEach(e=>e.blocks.forEach(t=>Qg.push(...t)));function eB(e){for(var t=0;t<Qg.length;t+=2)if(e>=Qg[t]&&e<=Qg[t+1])return!0;return!1}var Cn=e=>e+" "+e,mu=80,bve=function(t,n){return"M95,"+(622+t+n)+`
127
127
  c-2.7,0,-7.17,-2.7,-13.5,-8c-5.8,-5.3,-9.5,-10,-9.5,-14
@@ -419,7 +419,7 @@ l0,-`+(n+144)+`c-2,-159.3,-10,-310.7,-24,-454c-53.3,-528,-210,-949.7,
419
419
  if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', watch);
420
420
  else watch();
421
421
  })();
422
- `.trim();function bye(e){if(!e)return null;const t=e.trim();return t&&!/[;{}<]/.test(t)?t:null}function wye(e,t){const n=bye(t);return[`:root{color-scheme:${e}}`,"html,body{margin:0;padding:0;background:transparent;",n?`color:${n};`:"","font:13px/1.55 -apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,'Helvetica Neue',Arial,sans-serif}"].join("")}const Sye=/<html[\s>]/i,kye=/<head[\s>]/i,jye=/<meta[^>]+http-equiv\s*=\s*["']?content-security-policy/i;function Cye(e,t={}){const n=t.theme??"light",r=typeof e=="string"?e:"",s='<meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">'+(jye.test(r)?"":`<meta http-equiv="Content-Security-Policy" content="${s$()}">`)+`<style>${wye(n,t.ink)}</style><script>${yye}<\/script>`;return Sye.test(r)?kye.test(r)?r.replace(/(<head[^>]*>)/i,`$1${s}`):r.replace(/(<html[^>]*>)/i,`$1<head>${s}</head>`):`<!DOCTYPE html><html><head>${s}</head><body>${r}</body></html>`}function Tye(e,t){const{enabled:n=!0}=t,[r,i]=f.useState(o$);return f.useEffect(()=>{if(!n)return;const s=a=>{const l=e.current;if(!l||a.source!==l.contentWindow)return;const c=xye(a.data);(c==null?void 0:c.type)==="height"&&i(c.value)};return window.addEventListener("message",s),()=>window.removeEventListener("message",s)},[e,n]),r}const E2={kind:"toolarge"};function Eye(e){const t=e.headers.get("content-length"),n=t===null?NaN:Number(t);return Number.isFinite(n)&&n>=0?n:null}function Rye(e,t){const n=new Uint8Array(t);let r=0;for(const i of e)n.set(i,r),r+=i.byteLength;return n}async function a$(e,t){var a;const n=Eye(e);if(n!==null&&n>t)return await((a=e.body)==null?void 0:a.cancel().catch(()=>{})),E2;if(!e.body){const l=new Uint8Array(await e.arrayBuffer());return l.byteLength>t?E2:{kind:"ok",bytes:l}}const r=e.body.getReader(),i=[];let s=0;for(;;){const{done:l,value:c}=await r.read();if(l)return{kind:"ok",bytes:Rye(i,s)};if(s+=c.byteLength,s>t)return await r.cancel().catch(()=>{}),E2;i.push(c)}}async function l$(e,t,n){var i;const r=await fetch(r1(e,"inline"),{headers:Io(),signal:n});if(!r.ok)throw await((i=r.body)==null?void 0:i.cancel().catch(()=>{})),new Error(`download failed: ${r.status}`);return a$(r,t)}function c$(e,t){const[n,r]=f.useState(null),[i,s]=f.useState("loading");return f.useEffect(()=>{const a=new AbortController;return s("loading"),r(null),l$(e,t,a.signal).then(l=>{if(!a.signal.aborted){if(l.kind==="toolarge"){s("toolarge");return}r(new TextDecoder().decode(l.bytes)),s("ok")}}).catch(()=>{a.signal.aborted||s("failed")}),()=>a.abort()},[e,t]),{text:n,state:i}}const Mye=2*1024*1024,Aye="'IBM Plex Mono',monospace";function uy({item:e,mode:t="expanded"}){const n=$x(),r=Z(),i=f.useRef(null),{text:s,state:a}=c$(e.path,Mye),{effectiveTheme:l,ink:c}=f.useMemo(()=>{if(typeof document>"u")return{effectiveTheme:"light",ink:void 0};const h=document.documentElement;return{effectiveTheme:h.getAttribute("data-theme")==="dark"?"dark":"light",ink:getComputedStyle(h).getPropertyValue("--proto-ink").trim()||void 0}},[n]),u=f.useMemo(()=>s===null?null:Cye(s,{theme:l,ink:c}),[s,l,c]),d=t==="inline",p=Tye(i,{enabled:d});return a!=="ok"||u===null?o.jsxs(Pye,{height:d?o$:void 0,children:[a==="loading"&&r.mediaViewLoading,a==="failed"&&r.cmLoadFailed.replace("{name}",e.name),a==="toolarge"&&r.mediaViewTooLarge]}):o.jsx("iframe",{ref:i,title:e.name,sandbox:i$,srcDoc:u,referrerPolicy:"no-referrer",loading:"lazy",style:{display:"block",width:"100%",height:d?p:"100%",border:0,background:"var(--proto-card)"}})}function Pye({children:e,height:t}){return o.jsx("div",{style:{display:"flex",alignItems:"center",justifyContent:"center",height:t??"100%",minHeight:88,padding:"20px",boxSizing:"border-box",color:"var(--proto-muted)",font:`500 11.5px ${Aye}`},children:e})}function u$(e,t){return t<=0||!Number.isFinite(e)?1:Math.min(Math.max(1,Math.floor(e)),t)}function Iye(e,t,n){if(e.length===0)return 1;const r=t+n/2;for(let i=0;i<e.length;i++){const s=e[i];if(r<s.top+s.height)return i+1}return e.length}function Lye(e,t){const n=parseInt(e,10);return Number.isFinite(n)?u$(n,t):null}const d$=1.5,sg={kind:"closed"};class Nye{constructor(t){Pe(this,"abort",new AbortController);Pe(this,"task",null);Pe(this,"doc",null);Pe(this,"wanted",new Set);Pe(this,"drawn",new Set);Pe(this,"running",null);Pe(this,"pumping",!1);Pe(this,"closed",!1);this.canvas=t}async open(t){try{const[n,r]=await Promise.all([t.fetchBytes(this.abort.signal),t.loadPdfjs()]);if(this.closed)return sg;if(n.kind==="toolarge")return{kind:"toolarge"};this.task=r.getDocument({data:n.bytes});const i=await this.task.promise;if(this.closed)return sg;const s=await i.getPage(1);if(this.closed)return sg;this.doc=i;const{width:a,height:l}=s.getViewport({scale:d$});return{kind:"ok",numPages:i.numPages,pageSize:{width:a,height:l}}}catch(n){if(this.closed)return sg;throw n}}show(t){this.closed||!this.doc||(this.wanted.add(t),this.pump())}hide(t){var n;this.wanted.delete(t),((n=this.running)==null?void 0:n.pageNumber)===t&&this.running.task.cancel(),this.drawn.delete(t)&&this.canvas.clear(t)}close(){var t,n;if(!this.closed){this.closed=!0,this.abort.abort(),this.wanted.clear(),(t=this.running)==null||t.task.cancel();for(const r of this.drawn)this.canvas.clear(r);this.drawn.clear(),(n=this.task)==null||n.destroy().catch(()=>{}),this.task=null,this.doc=null}}nextPage(){for(const t of this.wanted)if(!this.drawn.has(t))return t}async pump(){if(!this.pumping){this.pumping=!0;try{for(let t=this.nextPage();t!==void 0&&!this.closed;t=this.nextPage())await this.draw(t)}finally{this.pumping=!1}}}async draw(t){const n=this.doc;if(n){this.drawn.add(t);try{const r=await n.getPage(t);if(this.closed||!this.drawn.has(t))return;const i=this.canvas.draw(t,r);this.running={pageNumber:t,task:i},await i.promise}catch{}finally{this.running=null}}}}const Dye=2*1024*1024,Oye=50*1024*1024,id="'IBM Plex Mono',monospace";function Fye(e){return e.kind==="html"&&e.viewWidth==="full"?"96vw":e.kind==="html"&&e.viewWidth==="wide"?"min(1380px, 96vw)":"min(920px, 96vw)"}const f$=f.createContext({openDoc:()=>{}});function p$({item:e,source:t=!1}){const{text:n,state:r}=c$(e.path,Dye),i=Z();return r==="loading"?o.jsx(od,{children:i.cmLoading}):r==="failed"?o.jsx(od,{failed:!0,children:i.cmLoadFailed.replace("{name}",e.name)}):r==="toolarge"?o.jsx(od,{children:i.mediaTextTooLarge}):!t&&n$(e.name)?o.jsx("div",{style:{padding:"22px 26px",color:"var(--proto-ink)",fontSize:13.5,lineHeight:1.6},children:o.jsx(br,{text:n??""})}):o.jsx("pre",{style:{margin:0,padding:"20px 22px",font:`500 12px/1.6 ${id}`,color:"var(--proto-ink)",whiteSpace:"pre",overflowX:"auto"},children:n})}function h$({item:e,actions:t}){const n=Z(),r=f.useRef(null),i=f.useRef(null),s=f.useRef([]),[a,l]=f.useState("loading"),[c,u]=f.useState(0),[d,p]=f.useState(1),{containerRef:h,style:m,zoom:v,zoomIn:g,zoomOut:x,resetZoom:y}=_6({mode:"css-zoom",maxScale:5});f.useEffect(()=>{const w=i.current;if(!w)return;let R=!1,T=null;w.replaceChildren(),s.current=[],l("loading"),u(0),p(1);const A=[],P=new Nye(zye(A,Math.min(window.devicePixelRatio||1,2)));return P.open({fetchBytes:L=>l$(e.path,Oye,L),loadPdfjs:async()=>(await Wc(async()=>{const{getPdfjs:L}=await import("./pdf-worker-Hp15W1QJ.js");return{getPdfjs:L}},[])).getPdfjs()}).then(L=>{if(!(R||L.kind==="closed")){if(L.kind==="toolarge"){l("toolarge");return}for(let F=1;F<=L.numPages;F++){const B=_ye(L.pageSize);B.dataset.page=String(F),w.appendChild(B),A.push(B)}s.current=A,T=new IntersectionObserver(F=>{for(const B of F){const K=Number(B.target.dataset.page);B.isIntersecting?P.show(K):P.hide(K)}},{root:r.current,rootMargin:"100% 0px"});for(const F of A)T.observe(F);u(L.numPages),l("ok")}}).catch(()=>{R||l("failed")}),()=>{R=!0,T==null||T.disconnect(),P.close()}},[e.path]);const b=f.useCallback(()=>{const w=r.current;if(!w)return[];const R=w.getBoundingClientRect().top-w.scrollTop;return s.current.map(T=>({top:T.getBoundingClientRect().top-R,height:T.offsetHeight}))},[]),S=f.useCallback(()=>{const w=r.current;if(!w)return;const R=Iye(b(),w.scrollTop,w.clientHeight);p(T=>T===R?T:R)},[b]),j=f.useCallback(w=>{const R=r.current,T=s.current[u$(w,c)-1];if(!R||!T)return;const A=T.getBoundingClientRect().top-R.getBoundingClientRect().top+R.scrollTop;R.scrollTo({top:Math.max(0,A-12),behavior:"smooth"})},[c]);return o.jsxs("div",{className:"content-surface",style:{display:"flex",flexDirection:"column",width:"100%",height:"100%"},children:[(c>0&&a!=="failed"||t)&&o.jsx(Wye,{current:d,total:a==="failed"?0:c,onJump:j,scale:v.scale,onZoomIn:g,onZoomOut:x,onZoomReset:y,actions:t}),o.jsxs("div",{ref:w=>{r.current=w,h(w)},onScroll:S,style:{flex:1,minHeight:0,overflow:"auto",padding:"20px 16px",boxSizing:"border-box"},children:[a==="loading"&&o.jsx(od,{children:n.mediaPdfLoading}),a==="failed"&&o.jsx(od,{failed:!0,children:n.mediaPdfFailed.replace("{name}",e.name)}),a==="toolarge"&&o.jsx(od,{children:n.mediaTextTooLarge}),o.jsx("div",{ref:i,style:{...m,maxWidth:900,margin:"0 auto"}})]})]})}function _ye(e){const t=document.createElement("div");return t.style.margin="0 auto 12px",t.style.overflow="hidden",t.style.borderRadius="var(--r-control)",t.style.background="var(--media-paper-bg)",t.style.boxShadow="var(--media-paper-shadow)",m$(t,e),t}function m$(e,t){e.style.maxWidth=`${Math.floor(t.width)}px`,e.style.aspectRatio=`${t.width} / ${t.height}`}function zye(e,t){return{draw(n,r){const i=e[n-1],s=r.getViewport({scale:d$});m$(i,s);const a=document.createElement("canvas");return a.width=Math.floor(s.width*t),a.height=Math.floor(s.height*t),a.style.display="block",a.style.width="100%",a.style.height="100%",i.replaceChildren(a),r.render({canvas:a,viewport:s,transform:t===1?void 0:[t,0,0,t,0,0]})},clear(n){var i;const r=(i=e[n-1])==null?void 0:i.querySelector("canvas");r&&(r.width=0,r.height=0,r.remove())}}}function Wye({current:e,total:t,onJump:n,scale:r,onZoomIn:i,onZoomOut:s,onZoomReset:a,actions:l}){const c=Z(),[u,d]=f.useState(String(e));f.useEffect(()=>{d(String(e))},[e]);const p=()=>{const h=Lye(u,t);h===null?d(String(e)):n(h)};return o.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"center",gap:8,padding:"7px 10px",borderBottom:"1px solid var(--proto-line-2)",background:"var(--material-card-bg)",flex:"none"},children:[t>0&&o.jsx(rt,{label:c.mediaPrevPage,size:28,disabled:e<=1,onClick:()=>n(e-1),style:ql(e<=1),children:"↑"}),t>0&&o.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,font:`600 11.5px ${id}`,color:"var(--proto-ink)"},children:[o.jsx("input",{value:u,inputMode:"numeric","aria-label":c.mediaPageNumber,onChange:h=>d(h.target.value.replace(/[^0-9]/g,"")),onFocus:h=>h.currentTarget.select(),onKeyDown:h=>{h.key==="Enter"&&(p(),h.currentTarget.blur())},onBlur:p,style:{width:44,textAlign:"center",padding:"3px 4px",borderRadius:"var(--r-chip)",border:"1px solid var(--proto-line-2)",background:"var(--material-inset-bg)",color:"var(--proto-ink)",font:`600 11.5px ${id}`}}),o.jsxs("span",{style:{color:"var(--proto-muted)"},children:["/ ",t]})]}),t>0&&o.jsx(rt,{label:c.mediaNextPage,size:28,disabled:e>=t,onClick:()=>n(e+1),style:ql(e>=t),children:"↓"}),t>0&&o.jsxs("div",{style:{marginLeft:12,display:"flex",alignItems:"center",gap:4},children:[o.jsx(rt,{label:c.mViewZoomOut,size:28,disabled:r<=1,onClick:s,style:ql(r<=1),children:"−"}),o.jsxs(rt,{label:c.mediaZoomReset,size:28,onClick:a,style:{width:"auto",minWidth:36,padding:"0 4px",font:`600 11px ${id}`,userSelect:"none"},children:[Math.round(r*100),"%"]}),o.jsx(rt,{label:c.mViewZoomIn,size:28,disabled:r>=5,onClick:i,style:ql(r>=5),children:"+"})]}),l&&o.jsx("div",{style:{marginLeft:t>0?12:0,display:"flex",alignItems:"center",gap:4},children:l})]})}function ql(e=!1){return{border:"1px solid var(--proto-line-2)",borderRadius:"var(--r-control)",background:"var(--material-control-bg)",boxShadow:"var(--material-control-shadow)",fontSize:14,userSelect:"none",...e?{opacity:.4,color:"var(--proto-muted)"}:{}}}function od({children:e,failed:t}){return o.jsx("div",{style:{display:"flex",alignItems:"center",justifyContent:"center",padding:"48px 20px",color:t?"var(--proto-danger)":"var(--proto-muted)",font:`500 12px ${id}`},children:e})}function Bye({item:e,onClose:t,onPin:n}){const r=$c(),i=Z();return UW(t),o.jsx("div",{className:"content-surface",role:"dialog","aria-modal":"true","aria-label":e.name,onClick:t,style:{position:"fixed",inset:0,zIndex:4e3,background:"var(--media-backdrop-soft)",display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",padding:"max(24px, env(safe-area-inset-top)) 16px max(24px, env(safe-area-inset-bottom))",boxSizing:"border-box",animation:"cxfade .18s ease both"},children:o.jsxs("div",{onClick:s=>s.stopPropagation(),style:{width:Fye(e),height:"min(88vh, 100%)",background:"var(--material-overlay-bg)",backdropFilter:"var(--glass-filter)",WebkitBackdropFilter:"var(--glass-filter)",border:"1px solid var(--proto-line-2)",borderRadius:"var(--r-float)",display:"flex",flexDirection:"column",overflow:"hidden",boxShadow:"var(--material-overlay-shadow)"},children:[o.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10,padding:"10px 12px",borderBottom:"1px solid var(--proto-line-2)",flex:"none",background:"transparent"},children:[o.jsx("span",{style:{font:`600 11.5px ${id}`,color:"var(--proto-ink)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",flex:1},children:e.name}),n&&o.jsx(rt,{label:i.mediaPin,onClick:n,style:ql(),children:"◧"}),o.jsx(rt,{label:i.cmDownload,onClick:()=>r(e.path,e.name),style:ql(),children:"↓"}),o.jsx(rt,{label:i.cmClose,onClick:t,style:{...ql(),fontSize:16},children:"×"})]}),o.jsx("div",{style:{flex:1,minHeight:0,overflow:"auto",background:e.kind==="pdf"?"var(--proto-gray)":"var(--proto-card)"},children:e.kind==="pdf"?o.jsx(h$,{item:e}):e.kind==="html"?o.jsx(uy,{item:e,mode:"expanded"}):o.jsx(p$,{item:e})})]})})}function $ye({children:e}){const{item:t,open:n,close:r,pin:i}=VW(),s=f.useMemo(()=>({openDoc:n}),[n]);return o.jsxs(f$.Provider,{value:s,children:[e,t&&o.jsx(Bye,{item:t,onClose:r,onPin:i})]})}function Uc(){return f.useContext(f$)}const g$=["session.message","session.message.delivered","session.status","session.turn","session.context-usage","session.todos","session.context-compacted","session.interaction","session.decision","session.rewound","session.debug.updated","session.tool-images"],Hye=["session.message.delta"],v$=["system.notice"],Uye=["config.changed"],x$=["rate-limit.changed"],y$=["board.updated","session.board","board.style-updated"],Vye=[...g$,...v$,...Uye,...x$,...y$];function qye(e){if(e.type!=="config.changed"||!e.payload||typeof e.payload!="object")return!1;const t=e.payload.section;return t==="models"||t==="preferences"}function Kye(e){const t=e.payload;if(!t||typeof t!="object")return null;const n=t.sessionId;return typeof n=="string"&&n?n:null}function Gye(e,t,n){if(!t.includes(e.type))return!1;const r=n==null?void 0:n.sessionId;if(!r)return!0;const i=Kye(e);return i===null||i===r}function Yye(e,t){let n=0;for(const r of e)if(Gye(t,r.types,r.scope)){n++;try{r.fn(t)}catch{}}return n}function Qye(){return{hasConnected:!1,epoch:0,down:!1}}function SR(e,t){return t!=="pending"?e.hasConnected&&!e.down?{...e,down:!0}:e:e.hasConnected?e.down?{hasConnected:!0,epoch:e.epoch+1,down:!1}:e:{hasConnected:!0,epoch:e.epoch,down:!1}}const Xye=1e3,Zye=3e4;function b$(e){const t=Math.max(0,Math.floor(e));return Math.min(Zye,Xye*2**t)}const ij=f.createContext({register:()=>()=>{},connState:"connecting",hasConnected:!1,reconnectEpoch:0});function Jye({children:e}){const t=ci(),n=ve(),r=_e(),[i]=f.useState(()=>n.config.get.queryFilter({})),s=f.useRef(new Set),[a,l]=f.useState(()=>({state:"connecting",accum:Qye()})),[c,u]=f.useState(0),d=f.useRef(0),p=f.useRef(null),h=f.useRef(!1),m=f.useCallback(()=>{p.current!==null&&(clearTimeout(p.current),p.current=null)},[]);f.useEffect(()=>{let x=!1;const y=t.subscribe.subscribe({events:[...Vye]},{onConnectionStateChange:b=>{const S=b.state;S==="pending"&&(d.current=0,h.current=!1),l(j=>({state:S,accum:SR(j.accum,S)}))},onData:b=>{const S=b;!S||typeof S.type!="string"||(qye(S)&&r.invalidateQueries(i),Yye([...s.current],S))},onError:()=>{if(l(S=>({state:"idle",accum:SR(S.accum,"idle")})),h.current=!0,x||p.current!==null)return;const b=b$(d.current++);p.current=setTimeout(()=>{p.current=null,u(S=>S+1)},b)}});return()=>{x=!0,m(),y.unsubscribe()}},[t,i,r,c,m]),f.useEffect(()=>{if(typeof window>"u"||typeof document>"u")return;const x=()=>{h.current&&document.visibilityState!=="hidden"&&(m(),d.current=0,u(y=>y+1))};return window.addEventListener("online",x),document.addEventListener("visibilitychange",x),()=>{window.removeEventListener("online",x),document.removeEventListener("visibilitychange",x)}},[m]),f.useEffect(()=>{a.accum.hasConnected&&EW.markInteractive()},[a.accum.hasConnected]),f.useEffect(()=>{a.accum.epoch>0&&Q0e.record()},[a.accum.epoch]);const v=f.useCallback(x=>(s.current.add(x),()=>{s.current.delete(x)}),[]),g=f.useMemo(()=>({register:v,connState:a.state,hasConnected:a.accum.hasConnected,reconnectEpoch:a.accum.epoch}),[v,a]);return o.jsx(ij.Provider,{value:g,children:e})}function vl(e,t,n){const{register:r}=f.useContext(ij),i=f.useRef(t);i.current=t;const s=e.join(","),a=n==null?void 0:n.sessionId;f.useEffect(()=>r({types:s.split(","),scope:a?{sessionId:a}:void 0,fn:l=>i.current(l)}),[r,s,a])}function oj(){const{connState:e,hasConnected:t,reconnectEpoch:n}=f.useContext(ij);return{connState:e,hasConnected:t,reconnectEpoch:n}}function ebe(e,t){return e==="pending"?"connected":e==="connecting"?t?"reconnecting":"connecting":t?"disconnected":"connecting"}function w$(e){switch(e){case"connected":return{color:"var(--proto-success)"};case"connecting":case"reconnecting":return{color:"var(--proto-amber)"};case"disconnected":return{color:"var(--proto-danger)"}}}function sj(e){switch(e){case"connected":return"connConnected";case"connecting":return"connConnecting";case"reconnecting":return"connReconnecting";case"disconnected":return"connDisconnected"}}const S$=f.createContext("connecting");function tbe({children:e}){const{connState:t,hasConnected:n}=oj(),r=ebe(t,n);return o.jsx(S$.Provider,{value:r,children:e})}function O0(){return f.useContext(S$)}function nbe(e){return e.payload&&typeof e.payload=="object"?e.payload:{}}const rbe=["board.updated"];function ibe(){const e=ve(),t=_e();vl(y$,n=>{if(n.type==="board.style-updated"){t.invalidateQueries(e.boards.style.queryFilter());return}if(n.type==="session.board"){t.invalidateQueries(e.sessions.list.queryFilter());return}t.invalidateQueries(e.boards.list.queryFilter()),t.invalidateQueries(e.boards.get.queryFilter()),t.invalidateQueries(e.boards.decisions.queryFilter()),t.invalidateQueries(e.sessions.list.queryFilter()),t.invalidateQueries({...e.memory.file.queryFilter(),predicate:r=>{var s;const i=(s=r.queryKey[1])==null?void 0:s.input;return typeof(i==null?void 0:i.path)=="string"&&i.path.startsWith("boards/")}})})}function obe(){return ibe(),null}function sbe(e){vl(rbe,t=>{const n=nbe(t).boardId;typeof n=="string"&&e(n)})}function k$({children:e}){return o.jsxs(Jye,{children:[o.jsx(obe,{}),o.jsx(tbe,{children:o.jsx(hge,{children:o.jsx(dge,{children:o.jsx(rve,{children:o.jsx($ye,{children:e})})})})})]})}function Ti(e){return e.slice(0,8)}const kR=96;function j$(e){const t=(e??"").replace(/\s+/g," ").trim();return t.length<=kR?t:t.slice(0,kR-1).trimEnd()+"…"}function C$(e){const t=(e.sessionLabel??"").trim();return{id:e.id,level:"info",title:t||(e.L??so).notifNewMessage,meta:j$(e.text),ts:e.ts,sessionId:e.sessionId,projectId:e.projectId}}function abe(e){const t=(e.title??"").trim();return{id:e.id,level:e.level,title:t||(e.L??so).notifSystemNotice,meta:j$(e.text),ts:e.ts??new Date().toISOString(),sessionId:"",projectId:null}}function lbe(e){return e==="info"}const cbe=["session.message","session.status"];function ube({onMessage:e,onTurnEnd:t}){vl(cbe,n=>{if(n.type==="session.message"){const r=n.payload;if(!r||r.role!=="assistant")return;const i=(r.text??"").trim();if(!i||!r.sessionId)return;e({sessionId:r.sessionId,text:i,ts:r.ts??null});return}if(n.type==="session.status"){const r=n.payload;if(!r||!r.sessionId||r.running!==!1)return;t(r.sessionId)}})}function T$(e){vl(v$,t=>{if(t.type!=="system.notice")return;const n=t.payload,r=((n==null?void 0:n.text)??"").trim();r&&e({level:(n==null?void 0:n.level)??"info",text:r,title:(n==null?void 0:n.title)??null,ts:(n==null?void 0:n.ts)??null})})}function jR(e){const t=new Map;for(const n of e??[])t.set(n.sessionId,{label:n.label??Ti(n.sessionId),projectId:n.projectId,silent:!!n.teamLeadId,awaitingInput:!!n.awaitingInput});return t}function dbe(){const e=ve(),t=xe(e.sessions.list.queryOptions({origin:"direct"})),n=f.useMemo(()=>jR(t.data),[t.data]),r=f.useCallback(async()=>{const i=await t.refetch();return i.isError?null:jR(i.data)},[t.refetch]);return{map:n,refresh:r}}function fbe(){const e=f.useRef(!1);return f.useEffect(()=>(e.current=!0,()=>{e.current=!1}),[]),e}function pbe(e,t){const n=fbe(),r=f.useRef(e);return r.current=e,f.useCallback(i=>{(async()=>{try{if(t&&await t(i))return}catch{}n.current&&r.current(i)})()},[t,n])}function hbe(e,t,n,r,i,s){if(!e.has(i))return{consumed:!0,item:null};if(n(i))return e.delete(i),{consumed:!0,item:null};const a=t.get(i);if(!a)return{consumed:!1,item:null};const l=e.get(i);return e.delete(i),a.silent?{consumed:!0,item:null}:{consumed:!0,item:C$({id:r("dmn"),sessionId:i,sessionLabel:a.label,projectId:a.projectId,text:l.text,ts:l.ts,L:s})}}function mbe(e,t,n,r){const i=f.useRef(new Map),s=f.useRef(new Set),a=Z(),l=f.useCallback((d,p=e.map)=>{const h=hbe(i.current,p,t,n,d,a);return h.consumed?(s.current.delete(d),h.item&&r(h.item),!0):!1},[r,t,a,e.map,n]),c=f.useCallback(d=>{i.current.set(d.sessionId,{text:d.text,ts:d.ts??new Date().toISOString()})},[]),u=f.useCallback(d=>{!i.current.has(d)||l(d)||(s.current.add(d),e.refresh().then(p=>{!p||l(d,p)||(i.current.delete(d),s.current.delete(d))}).catch(()=>{}))},[l,e]);f.useEffect(()=>{s.current.forEach(d=>{l(d)})},[l]),ube({onMessage:c,onTurnEnd:u})}function gbe(e,t,n,r){const i=f.useRef(new Map),s=Z();f.useEffect(()=>{var l;const a=i.current;if(i.current=e,!Pn())for(const[c,u]of e)!u.awaitingInput||((l=a.get(c))==null?void 0:l.awaitingInput)!==!1||u.silent||t(c)||r({...C$({id:n("dmn"),sessionId:c,sessionLabel:u.label,projectId:u.projectId,text:s.notifAwaitingInput,ts:new Date().toISOString(),L:s}),level:"warning"})},[e,t,n,r,s])}function vbe(e,t){const n=Z(),r=f.useCallback(i=>{t(abe({id:e("sysn"),level:i.level,text:i.text,title:i.title??void 0,ts:i.ts??void 0,L:n}))},[t,n,e]);T$(r)}function aj({isSessionOpen:e,publish:t,externalDelivery:n}){const r=f.useRef(0),i=dbe(),s=pbe(t,n),a=f.useCallback(l=>`${l}-${r.current++}`,[]);mbe(i,e,a,s),gbe(i.map,e,a,s),vbe(a,s)}const E$="cortex.local.notifications.enabled",HS="cortex-local-notifications-change";let u1;function R$(){if(u1!==void 0)return u1;try{return localStorage.getItem(E$)!=="false"}catch{return!0}}function xbe(e){u1=e;try{localStorage.setItem(E$,String(e)),u1=void 0}catch{}window.dispatchEvent(new Event(HS))}function ybe(e){return window.addEventListener(HS,e),window.addEventListener("storage",e),()=>{window.removeEventListener(HS,e),window.removeEventListener("storage",e)}}function bbe(){return f.useSyncExternalStore(ybe,R$,()=>!0)}function lj(){return typeof document<"u"&&document.visibilityState==="visible"&&document.hasFocus()}const wbe=6e3;function Sbe(e){return`${e.sessionId}\0${e.meta}`}function cj(e,t){return{title:e.title,description:e.meta,level:e.level,ts:e.ts,duration:lbe(e.level)?wbe:1/0,dedupeKey:Sbe(e),onActivate:t}}function M$(){const e=ni();return()=>{const t=ni();return(t==null?void 0:t.serverUrl)===(e==null?void 0:e.serverUrl)&&(t==null?void 0:t.token)===(e==null?void 0:e.token)}}function Wh(){return bt()||!globalThis.isSecureContext||typeof Notification!="function"?"unsupported":Notification.permission}async function kbe(){if(Wh()==="unsupported")return"unsupported";try{return await Notification.requestPermission()}catch{return Wh()}}function jbe(e,t,n,r){return new Promise(i=>{const s=()=>{e.onclick=null,e.onclose=null,e.onshow=null,e.onerror=null,t.delete(e),i(!1)};t.set(e,s),e.onshow=()=>i(!0),e.onclose=s,e.onerror=()=>{s(),e.close()},e.onclick=()=>{r()&&(i(!0),window.focus(),Promise.resolve(n(r)).catch(()=>{}),e.close())}})}function Cbe(){const e=new Map;let t=!1;return{send:async(i,s)=>{if(t||Wh()!=="granted")return!1;const a=M$(),l=()=>!t&&a();try{return await jbe(new Notification(i.title,{body:i.body}),e,s,l)}catch{return!1}},dispose:()=>{t=!0,e.forEach((i,s)=>{i(),s.close()}),e.clear()}}}function A$(e){return{title:e.title,body:e.meta}}let uc=null,_l;const P$="cortex.mobile.notifications.permission-requested";let Xg=!1;function Tbe(){if(!Pn())return Xg;try{return Xg||localStorage.getItem(P$)==="true"}catch{return Xg}}function Ebe(){if(Xg=!0,!!Pn())try{localStorage.setItem(P$,"true")}catch{}}async function dy(){if(!bt())return!1;try{const{isPermissionGranted:e}=await Wc(async()=>{const{isPermissionGranted:t}=await import("./index-XBRXpnC5.js");return{isPermissionGranted:t}},[]);uc=await e()}catch{uc=!1}return uc}async function I$(){Ebe();try{const{requestPermission:e}=await Wc(async()=>{const{requestPermission:n}=await import("./index-XBRXpnC5.js");return{requestPermission:n}},[]),t=await e();return uc=t==="granted",t}catch{return uc=!1,"denied"}}async function Rbe(){return await dy()?!0:Tbe()||Pn()&&typeof document<"u"&&document.visibilityState!=="visible"?!1:await I$()==="granted"}async function L$(){return bt()?_l||(uc!==null?uc:(_l=Rbe().finally(()=>{_l=void 0}),_l)):!1}async function Mbe({userInitiated:e}){return bt()?_l&&await _l?"granted":I$():"denied"}async function N$(e,t){if(!bt())return!1;try{if(!await L$())return!1;if(Pn()){const r=await Ye("plugin:cortex-notifications|post",{...e,data:t});if(!Bc(r))return r.ok}const{sendNotification:n}=await Wc(async()=>{const{sendNotification:r}=await import("./index-XBRXpnC5.js");return{sendNotification:r}},[]);return n({...e,extra:t,autoCancel:!0}),!0}catch{return!1}}function Abe(e){if(!e||typeof e!="object")return;const t=Reflect.get(e,"notification"),n=t&&typeof t=="object"?Reflect.get(t,"extra")??Reflect.get(e,"extra"):Reflect.get(e,"extra");return n&&typeof n=="object"?n:void 0}async function Pbe(e,t){let n=(t==null?void 0:t.aborted)??!1,r=()=>{};const i=()=>{n=!0,t==null||t.removeEventListener("abort",i),r()};t==null||t.addEventListener("abort",i,{once:!0});try{const{onAction:s}=await Wc(async()=>{const{onAction:c}=await import("./index-XBRXpnC5.js");return{onAction:c}},[]);if(n)return i;const a=await s(c=>{n||Promise.resolve(e(Abe(c))).catch(()=>{})});let l=!1;r=()=>{l||(l=!0,a.unregister().catch(()=>{}))},n&&r()}catch{i()}return i}async function Ibe(e,t){if(!Pn()||t!=null&&t.aborted)return()=>{};try{return await Vx()?Jpe(r=>e({...r}),t):Pbe(e,t)}catch{return()=>{}}}async function Lbe(e,t,n){const r=await Ye("desktop_notifications_post",{...e,data:t,action:n});return r.ok?!0:r.reason==="failed"&&Bc(r)?N$(e,t):!1}async function Nbe(e,t,n){var r;if(n()){if(e.serverUrl!==((r=ni())==null?void 0:r.serverUrl)){await Ye("desktop_notifications_ack",{actionId:e.actionId});return}await t(e,n)&&n()&&await Ye("desktop_notifications_ack",{actionId:e.actionId})}}async function Dbe(e,t){if(!t())return;const n=await Ye("desktop_notifications_pending");if(!(!t()||Bc(n))){if(!n.ok)throw new Error("Unable to read pending desktop notification actions");for(const r of n.value.actions)await Nbe(r,e,t)}}const CR=[1e3,2e3,4e3];function Obe(e,t){let n=Promise.resolve(),r=0,i;const s=()=>{i!==void 0&&clearTimeout(i),i=void 0},a=()=>(n=n.then(async()=>{s(),await Dbe(e,t),r=0}).catch(()=>{!t()||r>=CR.length||(i=setTimeout(()=>{i=void 0,a()},CR[r++]))}),n);return{drain:a,resume:()=>{s(),r=0,a()},dispose:s}}async function Fbe(e,t){let n=(t==null?void 0:t.aborted)??!1,r=()=>{};const i=M$(),a=Obe(e,()=>!n&&i()),l=()=>{n=!0,a.dispose(),t==null||t.removeEventListener("abort",l),typeof window<"u"&&(window.removeEventListener("focus",a.resume),window.removeEventListener("online",a.resume)),r()};return n?l:(t==null||t.addEventListener("abort",l,{once:!0}),r=await wf("desktop-notification-action",a.resume),n?(r(),l):(typeof window<"u"&&(window.addEventListener("focus",a.resume),window.addEventListener("online",a.resume)),await a.drain(),l))}function _be(e){if(!e.trim()||e.length>512||/[\u0000-\u001f\u007f]/.test(e))return!1;try{return encodeURIComponent(e),!0}catch{return!1}}function zbe(e){const t=ci();return f.useCallback(async(n,r)=>{if(!r())return!1;if(!n.sessionId)return!0;const i=n.sessionId,s=_be(i)?await t.sessions.list.query({origin:"direct"}):[];return r()?(e(s.find(a=>a.sessionId===i)??null),!0):!1},[t,e])}function Wbe(e){const t=f.useRef(null);return f.useEffect(()=>{const n=new AbortController;let r=()=>{};return t.current=Cbe(),sr()&&Fbe(e,n.signal).then(i=>{n.signal.aborted?i():r=i}),()=>{var i;n.abort(),r(),(i=t.current)==null||i.dispose(),t.current=null}},[e]),t}function D$(e){const t=zbe(e),n=Wbe(t),r=Z().notificationOpenAction;return f.useCallback(async i=>{var l;if(!R$()||lj())return!1;const s=A$(i),a={sessionId:i.sessionId||void 0,projectId:i.projectId??void 0};return sr()?Lbe(s,a,r):((l=n.current)==null?void 0:l.send(s,async c=>{await t(a,c)}))??!1},[n,t,r])}const Bbe=/^\/m\/session\/([^/]+)$/;function uj(e){const t=Bbe.exec(e);if(!t)return null;try{return F0(decodeURIComponent(t[1]))??null}catch{return null}}function F0(e){if(!(typeof e!="string"||!e.trim()||e.length>512)&&!/[\u0000-\u001f\u007f]/.test(e))try{return encodeURIComponent(e),e}catch{return}}async function $be(e,t){const n=F0(e.sessionId);if(!n)return{path:"/m/sessions"};const r=`/m/session/${encodeURIComponent(n)}`,i=await t.sessions().catch(()=>null);if(!i)return{path:r};const s=i.find(a=>a.sessionId===n);return s?{path:r,projectId:s.projectId??void 0}:{path:"/m/sessions"}}async function Hbe(e,t){const n=F0(e.approvalId);if(!n)return{path:"/m/approvals"};const r=`/m/approvals?approvalId=${encodeURIComponent(n)}`,i=await t.approvals().catch(()=>null);if(!i)return{path:r};const s=i.find(a=>a.id===n);return s?{path:r,projectId:s.projectId??void 0}:{path:"/m/approvals"}}async function Ube(e,t){const n=e.kind??(e.sessionId?"session":"sessions");return n==="session"?$be(e,t):n==="approvals"?Hbe(e,t):{path:"/m/sessions"}}function Vbe({items:e,now:t=Date.now(),lang:n,onDismiss:r}){if(e.length===0)return null;const{visible:i}=U_(e);return o.jsx("div",{style:{position:"fixed",top:"calc(10px + env(safe-area-inset-top))",left:10,right:10,zIndex:1e3,display:"flex",flexDirection:"column",gap:8,pointerEvents:"none"},children:i.map(s=>o.jsx(qbe,{item:s,now:t,lang:n,onDismiss:r},s.id))})}function qbe({item:e,now:t,lang:n,onDismiss:r}){var l;const{onMouseEnter:i,onMouseLeave:s}=G_(e.id,e.duration,r),a=e.onActivate;return o.jsxs("div",{role:a?"button":"status",onTouchStart:i,onTouchEnd:s,onClick:a?()=>{a(),r(e.id)}:void 0,style:{pointerEvents:"auto",background:"var(--proto-card)",border:"1px solid var(--panel-translucent-border)",borderRadius:"var(--r-float)",boxShadow:"var(--material-overlay-shadow)",padding:"11px 13px",display:"flex",gap:10,alignItems:"center",cursor:a?"pointer":"default"},children:[o.jsx("div",{"aria-label":"Cortex",style:{width:36,height:36,borderRadius:"var(--r-chip)",background:"var(--brand-badge-bg)",border:"1px solid var(--brand-badge-border)",display:"flex",alignItems:"center",justifyContent:"center",flex:"none"},children:o.jsxs("svg",{width:25,height:25,viewBox:"0 0 64 64",fill:"none","aria-hidden":"true",children:[o.jsx("circle",{cx:33,cy:32,r:5,fill:"var(--brand-badge-core)"}),o.jsx("path",{d:"M42.29 23.64A12.5 12.5 0 1 0 42.29 40.36",stroke:"var(--brand-badge-arc)",strokeWidth:5,strokeLinecap:"round"}),o.jsx("path",{d:"M48.6 17.95A21 21 0 1 0 48.6 46.05",stroke:"var(--brand-badge-arc)",strokeWidth:5,strokeLinecap:"round"})]})}),o.jsxs("div",{style:{minWidth:0,flex:1},children:[o.jsx("div",{style:{fontSize:12.5,fontWeight:650,color:C.ink,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:e.title}),e.description?o.jsx("div",{style:{fontSize:11,color:C.sub,marginTop:1,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:e.description}):null,(l=e.actions)!=null&&l.length?o.jsx("div",{style:{display:"flex",gap:6,marginTop:6,flexWrap:"wrap"},children:e.actions.map((c,u)=>o.jsx("button",{type:"button","aria-label":c.altText??c.label,onClick:d=>{d.stopPropagation(),c.onClick(),r(e.id)},style:{border:"1px solid var(--panel-translucent-border)",borderRadius:"var(--r-chip)",background:"transparent",color:C.ink,fontSize:11,padding:"3px 8px"},children:c.label},u))}):null]}),o.jsx("span",{style:{fontSize:10,fontVariantNumeric:"tabular-nums",color:C.faint,flex:"none",alignSelf:"flex-start"},children:zr(e.ts,t,n)||zr(t,t,n)}),o.jsx("button",{type:"button","aria-label":cn(n).cmDismiss,onClick:c=>{c.stopPropagation(),r(e.id)},style:{border:"none",background:"transparent",color:C.faint,fontSize:12,cursor:"pointer",flex:"none",padding:"0 2px"},children:"✕"})]})}function O$(){const{dismiss:e}=Rt(),t=q_(),n=Qe();return o.jsx(Vbe,{items:t,lang:n,onDismiss:e})}function Kbe(){const e=qe(),{setCurrentProject:t}=Wt();return f.useCallback(n=>{n!=null&&n.projectId&&t(n.projectId),e(n?`/m/session/${encodeURIComponent(n.sessionId)}`:"/m/sessions")},[e,t])}function Gbe(){const{toast:e}=Rt(),t=Kbe(),n=f.useRef(_n().pathname);n.current=_n().pathname;const r=D$(t),i=f.useCallback(a=>lj()&&uj(n.current)===a,[]),s=f.useCallback(a=>{e(cj(a,a.sessionId?()=>t(a):void 0))},[t,e]);return aj({isSessionOpen:i,publish:s,externalDelivery:r}),o.jsx(O$,{})}let $d={status:null,supported:null,pending:!1,error:null};const US=new Set;let R2=Promise.resolve();const d1=()=>typeof document<"u"&&document.visibilityState==="visible",TR=()=>$d,Ybe=e=>(US.add(e),()=>{US.delete(e)});function dc(e){$d={...$d,...e},US.forEach(t=>t())}async function F$(e,t){const n=await Ye("mobile_notifications_configure",{enabled:e,locale:t,completionNotifications:!0});if(!n.ok)throw new Error("Native notification configuration failed");return n.value}function Qbe(){var e;return((e=$d.status)==null?void 0:e.completionNotifications)===!0&&$d.status.enabled}function VS(e){return R2=R2.then(e).catch(()=>{dc({error:"configure",pending:!1})}),R2}async function ER(e,t,n){if(!n()||!d1())return;const r=await Vx();if(!n())return;dc({status:r,supported:r!==null});const i=await(t?L$():dy());if(!r||!n()||!d1())return;if(r.enabled&&!i){dc({status:{...r,permissionGranted:!1}});return}const s=await F$(r.enabled,e);n()&&dc({status:s,error:null})}function Xbe(e){if(!Pn())return()=>{};let t=!0;const n=()=>{VS(()=>ER(e,!1,()=>t))};return VS(()=>ER(e,!0,()=>t)),document.addEventListener("visibilitychange",n),window.addEventListener("focus",n),()=>{t=!1,document.removeEventListener("visibilitychange",n),window.removeEventListener("focus",n)}}function Zbe(e){f.useEffect(()=>Xbe(e),[e])}function Jbe(){return f.useSyncExternalStore(Ybe,TR,TR)}function e2e(e,t){return!Pn()||$d.pending?Promise.resolve():(dc({pending:!0,error:null}),VS(async()=>{if(e&&(!d1()||!await dy()||!d1())){dc({pending:!1,error:"permission"});return}const n=await F$(e,t);dc({status:n,supported:!0,pending:!1,error:null})}))}function t2e(){const e=ci(),t=qe(),{setCurrentProject:n}=Wt();f.useEffect(()=>{const r=new AbortController;let i=()=>{};return Ibe(async s=>{if(!s||r.signal.aborted)return!1;const a=await Ube(s,{sessions:()=>e.sessions.list.query({origin:"direct"}),approvals:()=>e.approvals.list.query({status:"pending"})}),l=s.scope===void 0?null:await Vx();if(r.signal.aborted||s.scope!==void 0&&s.scope!==(l==null?void 0:l.scope))return!1;a.projectId&&n(a.projectId),t(a.path)},r.signal).then(s=>{r.signal.aborted?s():i=s}),()=>{r.abort(),i()}},[e,t,n])}function n2e(e){if(e.sessionId&&Qbe())return Promise.resolve(!0);const t=e.sessionId?{kind:"session",sessionId:e.sessionId,projectId:e.projectId??""}:{kind:"sessions"};return N$(A$(e),t)}function r2e(){const e=_n(),t=f.useRef(e.pathname);return t.current=e.pathname,f.useCallback(n=>document.visibilityState==="visible"&&uj(t.current)===n,[])}function i2e(){const e=uj(_n().pathname);f.useEffect(()=>{const t=()=>{J9(document.visibilityState==="visible"?e:null)};return t(),document.addEventListener("visibilitychange",t),()=>{document.removeEventListener("visibilitychange",t),J9(null)}},[e])}function o2e(){const e=qe(),{toast:t}=Rt(),{setCurrentProject:n}=Wt();Zbe(Qe()),t2e(),i2e();const r=f.useCallback((a,l)=>{if(!F0(a)){e("/m/sessions");return}l&&n(l),e(`/m/session/${encodeURIComponent(a)}`)},[e,n]),i=r2e(),s=f.useCallback(a=>{t(cj(a,()=>r(a.sessionId,a.projectId)))},[r,t]);return aj({isSessionOpen:i,publish:s,externalDelivery:n2e}),o.jsx(O$,{})}function s2e(){return Pn()?o.jsx(o2e,{}):o.jsx(Gbe,{})}const a2e="fixed inset-0 z-40 bg-state-ink/[0.44] [backdrop-filter:var(--material-scrim-filter)] [-webkit-backdrop-filter:var(--material-scrim-filter)] data-[state=open]:animate-fade-in data-[state=closed]:animate-fade-out motion-reduce:animate-none",l2e="fixed left-1/2 top-1/2 z-50 -translate-x-1/2 -translate-y-1/2 w-[420px] max-w-[calc(100vw-32px)] box-border rounded-[var(--r-float)] [background:var(--material-overlay-bg)] [backdrop-filter:var(--glass-filter)] [-webkit-backdrop-filter:var(--glass-filter)] p-5 pb-4 shadow-[shadow:var(--material-overlay-shadow)] focus:outline-none data-[state=open]:animate-zoom-in data-[state=closed]:animate-zoom-out motion-reduce:animate-none";function c2e(e){return o.jsxs("div",{className:"flex items-start gap-3",children:[o.jsx("div",{className:"flex h-9 w-9 flex-none items-center justify-center rounded-[var(--r-control)] bg-proto-accent-bg text-state-run",children:o.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 20 20",fill:"none",stroke:"currentColor",strokeWidth:"1.8",children:[o.jsx("path",{d:"M10 14V4M5.5 8.5 10 4l4.5 4.5"}),o.jsx("path",{d:"M3.5 16.5h13"})]})}),o.jsxs("div",{className:"min-w-0 flex-1",children:[o.jsx(mf,{className:"text-body font-semibold text-state-ink",children:e.title}),o.jsx("div",{className:"mt-1 break-words font-mono text-[11.5px] font-medium leading-relaxed text-proto-muted",children:e.summary})]})]})}function fy(e){return o.jsx(pf,{open:!0,onOpenChange:t=>{t||e.onDismiss()},children:o.jsxs(hf,{children:[o.jsx(wc,{className:a2e}),o.jsxs(Oc,{className:l2e,"aria-describedby":e.descriptionId,children:[o.jsx(c2e,{title:e.title,summary:e.summary}),o.jsx(bx,{id:e.descriptionId,className:"mb-4 mt-3 text-[12.5px] leading-[1.65] text-proto-muted",children:e.description}),e.children]})]})})}const M2="box-border flex h-9 items-center rounded-[var(--r-control)] border border-proto-line px-4 text-[12.5px] [background:var(--material-control-bg)] shadow-[shadow:var(--material-control-shadow)] font-semibold text-proto-muted transition-colors hover:bg-surface-canvas-alt disabled:opacity-60 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-proto-accent",u2e="box-border flex h-9 items-center rounded-[var(--r-control)] bg-state-ink px-4 text-[12.5px] font-semibold text-[var(--ink-solid-fg)] transition-opacity hover:opacity-90 disabled:opacity-60 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-proto-accent";function d2e(e){const t=e.available??"";return t?`Cortex ${t}`:"Cortex"}function f2e(e,t){switch(e){case"waiting":return t.updateWaiting;case"installing":return t.updateInstalling;case"restarting":return t.updateReconnecting;case"failed":return t.updateFailed;default:return t.updateNewAvailable}}function p2e(e,t){const n=e.available??t.updateNewVersion;switch(e.state){case"waiting":return t.updateWaitingHint;case"installing":return t.updateInstallingHint;case"restarting":return t.updateReconnectingHint;case"failed":return t.updateFailedHint;default:return t.updateConfirmVersion.replace("{version}",n)}}function h2e(e){const t=M();return e.status.state==="prompting"?o.jsxs("div",{className:"flex flex-wrap justify-end gap-2",children:[o.jsx("button",{type:"button",onClick:e.onSkip,disabled:e.busy,className:M2,children:t.updateSkipVersion}),o.jsx("button",{type:"button",onClick:e.onDismiss,className:M2,children:t.updateLater}),o.jsx("button",{type:"button",onClick:e.onApply,disabled:e.busy,className:u2e,children:e.busy?t.updateBusy:t.updateApply})]}):o.jsx("div",{className:"flex justify-end gap-2",children:o.jsx("button",{type:"button",onClick:e.onDismiss,className:M2,children:e.status.state==="failed"?t.updateClose:t.updateContinueBackground})})}function _$(e){const t=M();return o.jsxs(fy,{title:f2e(e.status.state,t),summary:d2e(e.status),descriptionId:"server-update-desc",description:p2e(e.status,t),onDismiss:e.onDismiss,children:[e.status.error?o.jsx("pre",{className:"mb-3 max-h-28 overflow-auto whitespace-pre-wrap break-all rounded-[var(--r-control)] bg-surface-canvas-alt p-2 font-mono text-[11.5px] leading-relaxed text-state-fail",children:e.status.error}):null,o.jsx(h2e,{...e})]})}function z$({onApply:e,onDismiss:t}){const n=M();return o.jsx(fy,{title:n.updateNewAvailable,summary:n.updateCheckUi,descriptionId:"browser-update-desc",description:n.updatePageHint,onDismiss:t,children:o.jsxs("div",{className:"flex flex-wrap justify-end gap-2",children:[o.jsx("button",{type:"button",className:"rounded-[var(--r-control)] border border-proto-line px-4 py-2 text-sm",onClick:t,children:n.updateLater}),o.jsx("button",{type:"button",className:"rounded-[var(--r-control)] bg-state-ink px-4 py-2 text-sm text-[var(--ink-solid-fg)]",onClick:e,children:n.updateRefreshPage})]})})}const m2e=1e4;function RR(e,t,n,r,i){return Array.from(e.querySelectorAll(t)).flatMap(s=>{try{const a=new URL(s.getAttribute(n)??"",r),l=new RegExp(`/assets/[^/]+-[A-Za-z0-9_-]{8,}\\.${i}$`);return a.origin!==r.origin||!l.test(a.pathname)?[]:[a.href]}catch{return[]}}).sort()}function W$(e,t){const n=new URL(t);if(!/^https?:$/.test(n.protocol)||e.title!=="Cortex"||!e.querySelector("#root")||e.querySelector('base, script[src*="/@vite/client"], script[src*="/src/"]'))return null;const r=RR(e,'script[type="module"][src]',"src",n,"js"),i=RR(e,'link[rel="stylesheet"][href]',"href",n,"css");return!r.length||!i.length?null:JSON.stringify([r,i])}async function g2e(e,t){var a;const n=await fetch(e,{cache:"no-store",credentials:"same-origin",redirect:"error",signal:t}),r=(a=n.headers.get("content-type"))==null?void 0:a.split(";")[0].trim();if(!n.ok||n.redirected||n.url!==e||r!=="text/html")throw new Error("invalid_page");const i=await n.text(),s=W$(new DOMParser().parseFromString(i,"text/html"),e);if(!s)throw new Error("invalid_entry");return s}async function v2e(){if(typeof document>"u")return{status:"skipped",reason:"unsupported_page"};const e=new URL(location.href);e.hash="";const t=W$(document,e.href);if(!t)return{status:"skipped",reason:"unsupported_page"};const n=new AbortController,r=setTimeout(()=>n.abort(),m2e);try{return await g2e(e.href,n.signal)===t?{status:"current"}:{status:"available",update:{kind:"browser-page"}}}catch{return{status:"error",reason:"check_failed"}}finally{clearTimeout(r)}}function x2e(){location.reload()}const qS=new Set;let KS=!1;function y2e(){KS=!0}function MR(){const e=KS;return KS=!1,e}function py(e){const t=e;return qS.add(t),()=>{qS.delete(t)}}function b2e(e){for(const t of qS)t(e)}const AR=["B","KB","MB","GB","TB"];function qi(e){return`$${e.toFixed(2)}`}function dj(e,t={}){const{fractionDigits:n=1,trimTrailingZeros:r=!1,maxUnit:i="TB"}=t,s=AR.indexOf(i),a=Math.abs(e);let l=0;for(;l<s&&a>=1024**(l+1);)l+=1;if(l===0)return`${e} B`;const c=(e/1024**l).toFixed(n);return`${r?String(Number(c)):c} ${AR[l]}`}const w2e="frontend-update-staged";function PR(e){return e.slice(0,8)}function S2e(e){const t=PR(e.version),n=e.fromVersion?PR(e.fromVersion):"";return n&&n!==t?`${n} → ${t}`:t}function B$(e){if(!e||e<=0)return null;const t=e>=1024*1024?1:0;return dj(e,{fractionDigits:t,maxUnit:"MB"})}function $$(e,t){const n=B$(e.size),r=[S2e(e)];return n&&r.push(n),r.push(t.updateDownloaded),r.join(" · ")}function fj(e){if(!e||typeof e!="object")return null;const t=e;return typeof t.version!="string"||!t.version?null:{version:t.version,fromVersion:typeof t.fromVersion=="string"&&t.fromVersion?t.fromVersion:void 0,size:typeof t.size=="number"?t.size:void 0}}async function k2e(e){return bt()?wf(w2e,t=>{const n=fj(t);n&&e(n)}):()=>{}}async function j2e(){if(!bt())return null;const e=await Ye("get_staged_update");return e.ok?fj(e.value):null}async function C2e(){bt()&&await Ye("apply_frontend_update")}const T2e="app-update-available";function GS(e){if(!e||typeof e!="object")return null;const t=e;if(typeof t.version!="string"||!t.version||typeof t.kind!="string"||!t.kind)return null;const n=t.apply==="silent"?"silent":"prompt",r={version:t.version,kind:t.kind,apply:n};return typeof t.releaseUrl=="string"&&t.releaseUrl&&(r.releaseUrl=t.releaseUrl),typeof t.notes=="string"&&t.notes&&(r.notes=t.notes),typeof t.size=="number"&&t.size>0&&(r.size=t.size),r}function E2e(e,t){return t.updateSilentNotice.replace("{version}",e.version)}function H$(e,t){const n=[`Cortex ${e.version}`],r=B$(e.size);return r&&n.push(r),n.push(t.updateDownloaded),n.join(" · ")}function U$(e,t){switch(e){case"appimage":return t.updateRestartInstall;case"nsis":return t.updateRunInstaller;case"apk":return t.updateInstall;case"dmg":case"deb":case"rpm":return t.updateOpenInstaller;default:return t.updateApply}}function V$(e,t){switch(e){case"appimage":return t.updateAppimageHint;case"nsis":return t.updateNsisHint;case"apk":return t.updateApkHint;case"dmg":return t.updateDmgHint;case"deb":case"rpm":return t.updatePackageHint;default:return t.updateInstallHint}}let q$=null;const YS=new Set;function Bh(e){q$=e;for(const t of YS)t()}function K$(e){return YS.add(e),()=>YS.delete(e)}function G$(){return q$}async function R2e(){if(!bt())return()=>{};const e=await wf(T2e,n=>{const r=GS(n);r&&Bh(r)}),t=await Ye("get_app_update");if(t.ok){const n=GS(t.value);n&&Bh(n)}return e}async function M2e(){if(!bt())return null;const e=await Ye("install_app_update");if(e.ok)return typeof e.value=="string"?e.value:null;if(e.reason==="failed"&&typeof e.error=="string"&&e.error)throw new Error(e.error);return null}async function A2e(){Bh(null),bt()&&await Ye("skip_app_update")}const f1=new Set;let oa=null;const QS=()=>oa!==null;function Y$(e){return f1.add(e),()=>{f1.delete(e)}}function A2(e){return{ui:{status:"error",reason:e},shell:{status:"error",reason:e}}}function P2e(e){if(!e||typeof e!="object")return null;const t=e;return!["available","current","skipped","error"].includes(t.status)||t.reason!==void 0&&typeof t.reason!="string"?null:t}function IR(e,t){const n=P2e(e);if(!n)return null;const r=n.update===void 0?void 0:t(n.update);return r===null||n.status==="available"&&!r||n.status==="current"&&r?null:{status:n.status,...r?{update:r}:{},...n.reason!==void 0?{reason:n.reason}:{}}}async function I2e(){var r,i;const e=await Ye("check_for_updates");if(Bc(e))return A2("unsupported_shell");if(!e.ok)return A2("check_failed");const t=IR((r=e.value)==null?void 0:r.ui,fj),n=IR((i=e.value)==null?void 0:i.shell,GS);return t&&n?{ui:t,shell:n}:A2("invalid_report")}async function Q$(){return bt()?I2e():{ui:await v2e()}}async function L2e(e){try{return await e()}catch{return{status:"error",reason:"check_failed"}}}function N2e(e){return Z$(async()=>({server:await L2e(e),...await Q$()}))}function X$(){return oa?oa.then(()=>X$()):Z$(Q$)}function Z$(e){if(oa)return oa;oa=e().then(t=>(b2e(t),t)).finally(()=>{oa=null;for(const t of f1)t()});for(const t of f1)t();return oa}const D2e={available:null,state:"idle"};function O2e(e){return e==="idle"?6e4:e==="waiting"?1e4:2e3}function F2e(e,t){return e.state==="idle"||e.auto&&e.state!=="failed"?!1:t!==(e.available??"")}function _2e(e){const t=ve(),n=_e();f.useEffect(()=>py(({server:r})=>{if(r){if(r.status==="available"&&r.update&&r.reason!=="auto_install"){e(null);const i=r.update.version;n.setQueryData(t.system.updateStatus.queryKey({}),s=>(s==null?void 0:s.state)==="waiting"||(s==null?void 0:s.state)==="installing"||(s==null?void 0:s.state)==="restarting"?s:{available:i,state:"prompting"})}n.invalidateQueries(t.system.updateStatus.queryFilter())}}),[t,n,e])}function z2e(){const e=ve(),t=xe({...e.system.updateStatus.queryOptions({}),refetchInterval:n=>{var r;return O2e(((r=n.state.data)==null?void 0:r.state)??"idle")},refetchIntervalInBackground:!0,retry:!0});return{status:t.data??D2e,hasStatus:t.data!==void 0}}function W2e(){const e=ve(),t=_e(),n=()=>t.invalidateQueries(e.system.updateStatus.queryFilter()),r=Se(e.system.applyUpdate.mutationOptions({onSuccess:u=>{u.accepted&&y2e(),t.setQueryData(e.system.updateStatus.queryKey({}),u.status)},onSettled:n})),i=Se(e.system.skipUpdate.mutationOptions({onSettled:n})),{mutate:s}=r,{mutate:a}=i,l=f.useCallback(()=>{s({})},[s]),c=f.useCallback(()=>{a({})},[a]);return{apply:l,skip:c,busy:r.isPending||i.isPending}}function B2e(){const{status:e,hasStatus:t}=z2e(),n=W2e(),[r,i]=f.useState(null);_2e(i);const s=f.useCallback(()=>{i(e.available??"")},[e.available]);return{status:e,hasStatus:t,visible:F2e(e,r),...n,dismiss:s}}const $2e=["button","checkbox","radio","submit","reset","file","range","color"];function H2e(e){return e?e.tagName==="TEXTAREA"?!0:e.tagName==="INPUT"?!$2e.includes(e.type):e.isContentEditable===!0:!1}function U2e(){return typeof document<"u"&&H2e(document.activeElement)}function pj(e){const[t,n]=f.useState(null);return f.useEffect(()=>{if(e===null){n(null);return}const r=()=>{U2e()||n(e)};if(r(),typeof document>"u")return;const i=()=>window.setTimeout(r,0);return document.addEventListener("focusout",i),()=>document.removeEventListener("focusout",i)},[e]),e===t?t:null}function V2e(){f.useEffect(()=>{let e=!1,t=()=>{};return R2e().then(n=>{e?n():t=n}),()=>{e=!0,t()}},[])}function q2e(e,t){const[n,r]=f.useState(!1),[i,s]=f.useState(null),a=f.useCallback(()=>{r(!0),s(null),M2e().then(l=>{r(!1),t(e),l!==null&&Bh(null)}).catch(l=>{r(!1),s(l.message)})},[t,e]);return{busy:n,error:i,install:a}}function K2e(){const e=f.useSyncExternalStore(K$,G$),[t,n]=f.useState(null),r=(e==null?void 0:e.version)===t?null:e,i=pj(r),s=q2e((e==null?void 0:e.version)??null,n);V2e(),f.useEffect(()=>py(({shell:c})=>{c!=null&&c.update&&(n(null),Bh(c.update))}),[]);const a=f.useCallback(()=>{A2e()},[]),l=f.useCallback(()=>{n((e==null?void 0:e.version)??null)},[e]);return{pending:e,update:i,...s,skip:a,dismiss:l}}function G2e(e){const[t,n]=f.useState(null);return f.useEffect(()=>{let r=!1,i=()=>{};const s=l=>{!r&&!e.current&&n(l)};k2e(s).then(l=>{r?l():i=l}),j2e().then(l=>{l&&s(l)});const a=py(({ui:l})=>{!bt()||!l.update||(e.current=!1,n(l.update))});return()=>{r=!0,i(),a()}},[e]),[t,n]}function Y2e(){const e=f.useRef(!1),[t,n]=G2e(e),r=pj(t),i=f.useCallback(()=>{C2e()},[]),s=f.useCallback(()=>{e.current=!0,n(null)},[n]);return{staged:r,apply:i,dismiss:s}}let J$=null;const XS=new Set,Q2e=()=>J$;function ZS(e){J$=e;for(const t of XS)t()}function X2e(e){return XS.add(e),()=>{XS.delete(e)}}const Z2e=()=>ZS(null);py(({ui:e})=>{var t;bt()||(e.status==="available"&&((t=e.update)==null?void 0:t.kind)==="browser-page"&&ZS(e.update),e.status==="current"&&ZS(null))});function J2e(){return{update:pj(f.useSyncExternalStore(X2e,Q2e)),dismiss:Z2e,apply:x2e}}function ewe(e,t=!0){const n=f.useRef(!1),r=O0();f.useEffect(()=>{if(["installing","restarting"].includes(e)||["reconnecting","disconnected"].includes(r)){n.current=!0;return}if(e==="failed"){n.current=!1,MR();return}t&&e==="idle"&&(MR()||n.current)&&(n.current=!1,X$())},[e,r,t])}function eH(){const e=B2e();ewe(e.status.state,e.hasStatus);const t=K2e(),n=Y2e(),r=J2e(),i=f.useSyncExternalStore(Y$,QS);return e.visible?{kind:"server",status:e.status,busy:e.busy,apply:e.apply,skip:e.skip,dismiss:e.dismiss}:i||["prompting","waiting","installing","restarting"].includes(e.status.state)?null:r.update?{kind:"page",apply:r.apply,dismiss:r.dismiss}:twe(t,n)}function twe(e,t){return e.update&&e.update.apply!=="silent"?{kind:"app",update:e.update,busy:e.busy,error:e.error,install:e.install,skip:e.skip,dismiss:e.dismiss}:(!e.pending||e.pending.apply==="silent")&&t.staged?{kind:"hot",update:t.staged,apply:t.apply,dismiss:t.dismiss}:null}const nwe={position:"fixed",inset:0,zIndex:60,background:"var(--overlay-scrim-strong)",display:"flex",alignItems:"center",justifyContent:"center",padding:"0 36px",boxSizing:"border-box"},rwe={width:"100%",background:"var(--material-overlay-bg)",borderRadius:"var(--r-float)",backdropFilter:"var(--glass-filter)",WebkitBackdropFilter:"var(--glass-filter)",boxShadow:"var(--material-overlay-shadow)",padding:"24px 20px 14px",boxSizing:"border-box",display:"flex",flexDirection:"column",alignItems:"center"},iwe={width:46,height:46,borderRadius:"var(--r-card)",background:"var(--proto-gray)",display:"flex",alignItems:"center",justifyContent:"center",marginBottom:14},owe={fontSize:17,fontWeight:650,color:"var(--proto-ink)"},swe={fontSize:12.5,color:"var(--proto-muted-3)",marginTop:6,fontVariantNumeric:"tabular-nums"},awe={fontSize:13,lineHeight:1.6,color:"var(--proto-muted)",textAlign:"center",margin:"10px 0 18px"};function lwe({title:e,summary:t}){return o.jsxs(o.Fragment,{children:[o.jsx("div",{style:iwe,children:o.jsxs("svg",{width:"20",height:"20",viewBox:"0 0 20 20",fill:"none",stroke:"var(--proto-ink-2)",strokeWidth:"1.8","aria-hidden":"true",children:[o.jsx("path",{d:"M10 14V4M5.5 8.5 10 4l4.5 4.5"}),o.jsx("path",{d:"M3.5 16.5h13"})]})}),o.jsx("div",{style:owe,children:e}),o.jsx("div",{style:swe,children:t})]})}function tH(e){return o.jsx("div",{role:"dialog","aria-modal":"true","aria-label":e.title,style:nwe,children:o.jsxs("div",{style:rwe,children:[o.jsx(lwe,{title:e.title,summary:e.summary}),o.jsx("div",{style:awe,children:e.description}),e.children]})})}const cwe={width:"100%",display:"flex",flexDirection:"column",gap:2},uwe={height:48,border:"none",borderRadius:"var(--r-control)",background:"var(--ink-solid-bg)",color:"var(--ink-solid-fg)",display:"flex",alignItems:"center",fontFamily:"var(--font-ui)",justifyContent:"center",fontSize:15,fontWeight:600,cursor:"pointer",width:"100%"},LR={height:44,border:"none",background:"transparent",display:"flex",alignItems:"center",justifyContent:"center",fontFamily:"var(--font-ui)",fontSize:14,fontWeight:600,color:"var(--proto-muted-2)",cursor:"pointer",flex:1};function dwe(e){const t=M();return o.jsxs("div",{style:cwe,children:[o.jsx("button",{type:"button",onClick:e.onInstall,disabled:e.busy,style:{...uwe,opacity:e.busy?.6:1},children:e.busy?t.updateBusy:U$(e.update.kind,t)}),o.jsxs("div",{style:{display:"flex",width:"100%"},children:[o.jsx("button",{type:"button",onClick:e.onSkip,style:LR,children:t.updateSkipVersion}),o.jsx("button",{type:"button",onClick:e.onDismiss,style:LR,children:t.updateLater})]})]})}function fwe(e){const t=M();return o.jsxs(tH,{title:t.updateReady,summary:H$(e.update,t),description:V$(e.update.kind,t),children:[e.error?o.jsx("div",{style:{fontSize:12,color:"var(--proto-danger)",marginBottom:10,textAlign:"center"},children:t.updateInstallFailed.replace("{error}",e.error)}):null,o.jsx(dwe,{...e})]})}const pwe={width:"100%",display:"flex",flexDirection:"column",gap:2},hwe={height:48,border:"none",borderRadius:"var(--r-control)",background:"var(--ink-solid-bg)",color:"var(--ink-solid-fg)",display:"flex",alignItems:"center",fontFamily:"var(--font-ui)",justifyContent:"center",fontSize:15,fontWeight:600,cursor:"pointer",width:"100%"},mwe={height:44,border:"none",background:"transparent",display:"flex",alignItems:"center",justifyContent:"center",fontFamily:"var(--font-ui)",fontSize:14,fontWeight:600,color:"var(--proto-muted-2)",cursor:"pointer",width:"100%"};function gwe(e){const t=M();return o.jsxs("div",{style:pwe,children:[o.jsx("button",{type:"button",onClick:e.onApply,style:hwe,children:t.updateExitApp}),o.jsx("button",{type:"button",onClick:e.onDismiss,style:mwe,children:t.updateIgnore})]})}function vwe(e){const t=M();return o.jsx(tH,{title:t.updateReady,summary:$$(e.update,t),description:t.updateHotHint,children:o.jsx(gwe,{onApply:e.onApply,onDismiss:e.onDismiss})})}function xwe(){const e=eH();return e?e.kind==="page"?o.jsx(z$,{onApply:e.apply,onDismiss:e.dismiss}):e.kind==="server"?o.jsx(_$,{status:e.status,busy:e.busy,onApply:e.apply,onSkip:e.skip,onDismiss:e.dismiss}):e.kind==="hot"?o.jsx(vwe,{update:e.update,onApply:e.apply,onDismiss:e.dismiss}):o.jsx(fwe,{update:e.update,busy:e.busy,error:e.error,onInstall:e.install,onSkip:e.skip,onDismiss:e.dismiss}):null}const NR="--cortex-vvh",DR="--cortex-vvt";function ywe(e,t){const n=()=>{e.setProperty(NR,`${t.height}px`),e.setProperty(DR,`${t.offsetTop}px`)};return n(),t.addEventListener("resize",n),t.addEventListener("scroll",n),()=>{t.removeEventListener("resize",n),t.removeEventListener("scroll",n),e.removeProperty(NR),e.removeProperty(DR)}}function bwe(){f.useEffect(()=>{const e=window.visualViewport;if(e)return ywe(document.documentElement.style,e)},[])}const wwe={position:"fixed",top:0,left:0,right:0,height:"var(--cortex-vvh, 100dvh)",transform:"translateY(var(--cortex-vvt, 0px))",display:"flex",flexDirection:"column",overflow:"hidden",background:"var(--app-backdrop)"};function Swe(){return o.jsx("div",{style:wwe,children:o.jsx(Lle,{children:o.jsx("div",{style:{flex:1,minHeight:0,overflow:"hidden"},children:o.jsx(Jme,{})})})})}function kwe({children:e}){return o.jsxs(k$,{children:[e,o.jsx(s2e,{}),o.jsx(xwe,{})]})}function jwe(){const e=_n(),t=qe();return bwe(),lge(e.pathname,t),o.jsx(kwe,{children:o.jsx(Swe,{})})}function ot(e){return JSON.stringify([e.backend,e.provider,e.model])}function Cc(e){return e.model.replace(/^claude-/,"").replace(/-\d{8}$/,"")}function Hd(e,t,n){const r=t==null?void 0:t.models.memory[ot(e)],i=n==null?void 0:n.routes.find(s=>s.backend===e.backend&&s.provider===e.provider);return{...e,thinking:(r==null?void 0:r.thinking)??null,mode:(r==null?void 0:r.mode)??(i==null?void 0:i.modes[0])??""}}function Cwe(e){return((e==null?void 0:e.routes)??[]).flatMap(t=>t.models.map(n=>({backend:t.backend,provider:t.provider,model:n})))}function nH(e,t){return e.toLowerCase().includes(t.trim().toLowerCase())}const rH=["interval","daily","weekly","once"],p1=["min","hr"],iH=[0,1,2,3,4,5,6],Twe={min:"schedUnitMin",hr:"schedUnitHr"};function h1(e,t){return t[Twe[e]]}function Ewe(e,t,n){var a;const r=((a=e==null?void 0:e.models)==null?void 0:a.favorites)??[],i=[...r,...((t==null?void 0:t.routes)??[]).flatMap(l=>l.models.map(c=>({backend:l.backend,provider:l.provider,model:c})))];return n&&i.push(n),[...new Map(i.map(l=>[ot(l),l]))].map(([l,c])=>({value:l,label:`${Cc(c)} · ${c.provider??c.backend}`,selection:n&&ot(n)===l?n:Hd(c,e,t),favorite:r.some(u=>ot(u)===l)}))}function Rwe(e,t){var i,s;if(!t)return[""];const n=e==null?void 0:e.routes.find(a=>a.backend===t.backend&&a.provider===t.provider),r=((i=n==null?void 0:n.modelThinking)==null?void 0:i[t.model])??((s=e==null?void 0:e.thinkingLevels)==null?void 0:s[t.backend])??[];return[...new Set(["",...r,t.thinking??""])]}function oH(e,t){const n=e.find(r=>r.value===t);return n!=null&&n.selection.mode?{selection:n.selection}:{}}function sH(e,t){return e.selection?{selection:{...e.selection,thinking:t||null}}:{}}function aH(e){return{type:"daily",message:"",selection:null,time:"09:00",dayOfWeek:1,intervalValue:30,intervalUnit:"min",delayValue:10,delayUnit:"min",projectId:e}}function Ef(e){return{time:e==="daily"||e==="weekly",interval:e==="interval",dayOfWeek:e==="weekly",delay:e==="once"}}function lH(e,t){const n=Ef(t),r=e==="edit";return{...n,delay:n.delay&&!r,type:!r,message:!0,selection:!0,projectId:!0}}const Mwe={intervalValue:"interval",intervalUnit:"interval",delayValue:"delay",delayUnit:"delay"};function Awe(e,t){const n=Mwe[t]??t;return e[n]??!1}function Pwe(e,t,n){const r=lH(t,e.type),i={};for(const s of Object.keys(n))Awe(r,s)&&Object.assign(i,{[s]:n[s]});return{...e,...i}}function $h(e,t){return t==="hr"?e*36e5:e*6e4}const Iwe=/^\d{2}:\d{2}$/;function Lwe(e){const t={type:e.type,message:e.message.trim()};return e.projectId&&(t.projectId=e.projectId),e.selection&&(t.selection=e.selection),e.type==="interval"&&(t.intervalMs=$h(e.intervalValue,e.intervalUnit)),(e.type==="daily"||e.type==="weekly")&&(t.time=e.time),e.type==="weekly"&&(t.dayOfWeek=e.dayOfWeek),e.type==="once"&&(t.delay=$h(e.delayValue,e.delayUnit)),t}function cH(e){const t=aH(e.projectId||null),n=e.intervalMs??0,r=n>0&&n%36e5===0;return{...t,type:e.type,message:e.message,selection:e.selection,time:e.time??t.time,dayOfWeek:e.dayOfWeek??t.dayOfWeek,intervalValue:n>0?r?n/36e5:Math.round(n/6e4):t.intervalValue,intervalUnit:r?"hr":"min"}}function Nwe(e,t){const n={scheduleId:e,message:t.message.trim()};return t.selection&&(n.selection=t.selection),t.projectId&&(n.projectId=t.projectId),t.type==="interval"&&(n.intervalMs=$h(t.intervalValue,t.intervalUnit)),(t.type==="daily"||t.type==="weekly")&&(n.time=t.time),t.type==="weekly"&&(n.dayOfWeek=t.dayOfWeek),n}function Dwe(e){return e.message.trim()?null:"message is required"}function Owe(e){return e.type==="interval"&&!(e.intervalValue>0)?"interval must be > 0":null}function Fwe(e){return(e.type==="daily"||e.type==="weekly")&&!Iwe.test(e.time)?"time must be HH:MM":null}function _we(e){const t=!(e.dayOfWeek>=0&&e.dayOfWeek<=6);return e.type==="weekly"&&t?"dayOfWeek must be 0..6":null}function zwe(e,t){return e.type==="once"&&t==="create"&&!(e.delayValue>0)?"delay must be > 0":null}function uH(e,t="create"){const r=[Dwe(e),Owe(e),Fwe(e),_we(e),zwe(e,t)].filter(i=>i!==null);return{ok:r.length===0,errors:r}}function Wwe(e,t){if(e.type==="interval")return new Date(t.getTime()+$h(e.intervalValue,e.intervalUnit));if(e.type==="once")return new Date(t.getTime()+$h(e.delayValue,e.delayUnit));const[n,r]=e.time.split(":").map(a=>parseInt(a,10)),i=new Date(t);if(i.setHours(n,r,0,0),e.type==="daily")return i.getTime()<=t.getTime()&&i.setDate(i.getDate()+1),i;let s=(e.dayOfWeek-t.getDay()+7)%7;return s===0&&i.getTime()<=t.getTime()&&(s=7),i.setDate(i.getDate()+s),i}function OR(e){return String(e).padStart(2,"0")}function hj(e,t){const n=Math.max(0,Math.round(e/6e4))*6e4;return n<864e5?zc(n,t):_c(n,t)}function FR(e){return new Date(e.getFullYear(),e.getMonth(),e.getDate()).getTime()}function Bwe(e,t,n){const r=cn(n),i=Math.round((FR(e)-FR(t))/864e5);return i<=0?r.timeToday:i===1?r.scTomorrow:G(r.timeMonthDay,{month:r.timeMonths.split(",")[e.getMonth()],day:e.getDate()})}function $we(e,t,n){const r=Wwe(e,t);return{day:Bwe(r,t,n),clock:`${OR(r.getHours())}:${OR(r.getMinutes())}`,delta:hj(r.getTime()-t.getTime(),n)}}const Hwe=["chatDaySun","chatDayMon","chatDayTue","chatDayWed","chatDayThu","chatDayFri","chatDaySat"],Uwe={daily:"chatCadenceDaily",weekly:"chatCadenceWeekly",interval:"chatCadenceInterval",once:"chatCadenceOnce"};function Hh(e,t){const n=cn(t),r=Uwe[e.type],i=r?n[r]:e.type;if(e.type==="daily")return e.time?`${i} ${e.time}`:i;if(e.type==="weekly"){const s=e.dayOfWeek!=null?Hwe[e.dayOfWeek]:void 0,a=s?n[s]:null;return!a||!e.time?i:G(n.chatCadenceWeeklyAt,{cadence:i,day:a,time:e.time})}if(e.type==="interval"&&e.intervalMs!=null&&e.intervalMs>0){const s=hj(e.intervalMs,t);return G(n.chatCadenceEvery,{span:s})}return i}function mj(e,t,n){if(!e)return null;const r=Date.parse(e);return Number.isNaN(r)?null:hj(r-t,n)}function Cs(e){const t=Date.parse(e.lastUsedAt||e.createdAt);return Number.isNaN(t)?0:t}function Uh(e){return[...e].sort((t,n)=>+!!n.unread-+!!t.unread||Cs(n)-Cs(t))}function _R(e){const t=new Date(e);return Math.floor(new Date(t.getFullYear(),t.getMonth(),t.getDate()).getTime()/864e5)}function zR(e){return e<10?"0"+e:""+e}function gj(e,t=Date.now()){const n=typeof t=="number"?t:t.getTime(),r=Cs(e),i=new Date(r),s=bf(i);return(_R(r)<_R(n)-1?(i.getFullYear()===new Date(n).getFullYear()?"":i.getFullYear()+"-")+zR(i.getMonth()+1)+"-"+zR(i.getDate())+" ":"")+s}function dH(e){const t=e.split(/[-_]/).filter(Boolean);return t.length>=2?(t[0][0]+t[1][0]).toUpperCase():t.length===1?t[0].slice(0,2).toUpperCase():"?"}function Vwe(e){const t=new Map;for(const n of e){if(n.origin!=="scheduled"||n.scheduleId==null)continue;const r=t.get(n.scheduleId)??[];r.push(n),t.set(n.scheduleId,r)}for(const n of t.values())n.sort((r,i)=>Cs(i)-Cs(r));return t}function WR(e){var r;if(e.latest)return Cs(e.latest);const t=(r=e.schedule)==null?void 0:r.lastRun,n=t?Date.parse(t):NaN;return Number.isNaN(n)?0:n}function JS(e,t){var i;const n=Vwe(t),r=[];for(const s of e){const a=n.get(s.id)??[];n.delete(s.id),r.push({scheduleId:s.id,schedule:s,title:s.message.trim()||(((i=a[0])==null?void 0:i.label)??(a[0]?Ti(a[0].sessionId):s.id)),kind:s.type==="once"?"once":"repeat",runs:a,latest:a[0]??null,unread:a.some(l=>l.unread)})}for(const[s,a]of n)r.push({scheduleId:s,schedule:null,title:a[0].label??Ti(a[0].sessionId),kind:a.length>1?"repeat":"once",runs:a,latest:a[0],unread:a.some(l=>l.unread)});return r.sort((s,a)=>WR(a)-WR(s))}function vj(e){const t=[...e].sort((r,i)=>Date.parse(r.createdAt)-Date.parse(i.createdAt)),n=new Map;return t.forEach((r,i)=>n.set(r.sessionId,i+1)),n}function fH(e){if(e.runs.length===0){if(!e.schedule)throw new Error(`Schedule row ${e.scheduleId} has neither a DTO nor a run`);return{type:"edit",schedule:e.schedule}}return e.kind==="once"?{type:"open",sessionId:e.runs[0].sessionId}:{type:"modal"}}function pH(e,t,n){var i;if((i=e.schedule)!=null&&i.paused)return{kind:"paused",cadence:Hh(e.schedule,n)};if(e.latest)return{kind:"run",stamp:gj(e.latest,t),cost:e.latest.costUsd!=null?qi(e.latest.costUsd):null};const r=e.schedule;return{kind:"pending",cadence:r?Hh(r,n):"",nextDelta:r?mj(r.nextRun,t,n):null}}function qwe(e,t,n,r){if(!e)return null;const i=vj(t).get(n);return i==null?null:G(r.chatRunTitle,{message:e.message,n:i})}function hH(e){return e.runs.filter(t=>t.unread).map(t=>t.sessionId)}function mH(e){return e.filter(t=>t.unread).length}const Kwe=["session.status","session.interaction","session.context-usage","session.context-compacted","session.todos"];function gH(){const e=ve(),t=_e();vl(Kwe,()=>{t.invalidateQueries(e.sessions.list.queryFilter())})}function Gwe(e){var r,i,s;const t=ve();return(s=(i=(r=xe(t.config.get.queryOptions({})).data)==null?void 0:r.settings)==null?void 0:i.find(a=>a.key===e))==null?void 0:s.value}function hy(){return Gwe("teamEnabled")===!0}function Ywe({projectId:e,count:t,expanded:n,onToggle:r,mobile:i,children:s}){const a=Z();return t===0?null:o.jsxs("section",{"data-starred-project":e,children:[o.jsxs("button",{type:"button","aria-label":a.chatStars,"aria-expanded":n,onClick:r,style:{display:"flex",alignItems:"center",gap:6,width:"100%",border:0,background:"transparent",color:"var(--proto-muted)",cursor:"pointer",minHeight:i?44:28,padding:i?"0 14px":"0 10px 0 28px",fontFamily:"inherit",fontSize:i?13:11.5},children:[o.jsx("span",{"aria-hidden":"true",children:n?"▾":"▸"}),o.jsx("span",{"aria-hidden":"true",children:"☆"}),o.jsx("span",{children:a.chatStars}),o.jsx("span",{style:{marginLeft:"auto"},children:t})]}),n&&s]})}function vH(e,t){return{starred:[...e,...t].filter(n=>n.starred===!0),direct:e.filter(n=>n.starred!==!0),scheduled:t.filter(n=>n.starred!==!0)}}const Qwe=3*60*60*1e3;function _0(e,t=Date.now()){if(!e.teamLeadId||e.running||e.awaitingInput||(e.waitingOnLead??0)>0||(e.waitingOn??0)>0)return!1;const n=Date.parse(e.lastUsedAt);return!Number.isNaN(n)&&t-n>Qwe}function xH(e,t=Date.now()){const n=Uh(e),r=i=>_0(i,t);return[...n.filter(i=>!r(i)),...n.filter(r)]}function xj(e,t=Date.now()){const n=new Set(e.map(l=>l.sessionId)),r=l=>l.teamLeadId&&l.teamLeadId!==l.sessionId&&n.has(l.teamLeadId)?l.teamLeadId:null,i=new Set(e.filter(l=>r(l)===null).map(l=>l.sessionId)),s=[],a=new Map;for(const l of e){const c=r(l);if(c===null||!i.has(c)){s.push(l);continue}const u=a.get(c);u?u.push(l):a.set(c,[l])}for(const[l,c]of a)a.set(l,xH(c,t));return{top:s,workers:a}}function Xwe(e,t,n=Date.now()){return xH(t.filter(r=>r.teamLeadId===e&&r.sessionId!==e),n)}const BR={lead:null,workers:[]};function Zwe(e,t,n){if(!e||!t)return BR;const r=t.teamLeadId&&t.teamLeadId!==t.sessionId?n.find(s=>s.sessionId===t.teamLeadId)??null:null,i=Xwe(t.sessionId,n);return r||i.length>0?{lead:r,workers:i}:BR}function Vh(e){return{running:!!e.running,awaitingInput:!!e.awaitingInput,waitingOn:(e.waitingOn??0)>0,unread:!!e.unread}}function yj(e){return{running:e.some(t=>t.running),awaitingInput:e.some(t=>t.awaitingInput),waitingOn:e.some(t=>t.waitingOn),unread:e.some(t=>t.unread)}}function ek(e,t,n,r){return G(t===1?e[n]:e[r],{n:t})}function Jwe(e,t=so){if(e.awaitingInput)return{kind:"awaiting",text:t.slAwaiting};if(e.running)return e.backgroundRunning?{kind:"background",text:t.slBackground}:{kind:"running",text:e.numTurns!=null?G(t.slRunningTurns,{n:e.numTurns}):t.slRunning};const n=e.waitingOn??0;return n>0?{kind:"waiting-external",text:ek(t,n,"slWaitingOne","slWaitingMany")}:{kind:"idle",text:t.slIdle}}function yH(e,t,n,r){return{id:e.sessionId,title:e.label||Ti(e.sessionId),time:zr(e.lastUsedAt||e.createdAt,t,n),unread:e.unread,status:Jwe(e,r)}}function e4e(e,t,n){const r=yj(t);return e.kind==="awaiting"?e:r.awaitingInput?{kind:"awaiting",text:n.slWorkerAwaiting}:e.kind==="running"||e.kind==="background"?e:r.running?{kind:"running",text:ek(n,t.filter(i=>i.running).length,"slWorkersRunningOne","slWorkersRunningMany")}:e.kind==="waiting-external"?e:r.waitingOn?{kind:"waiting-external",text:ek(n,t.filter(i=>i.waitingOn).length,"slWorkersWaitingOne","slWorkersWaitingMany")}:e}function t4e(e,t,n,r,i){const s=yH(e,n,r,i),a=t.filter(l=>!_0(l,n)).map(Vh);return a.length===0?s:{...s,unread:s.unread||yj(a).unread,status:e4e(s.status,a,i)}}const n4e={awaiting:"needsYou",running:"active",background:"active","waiting-external":"active",idle:"recent"};function r4e(e){const t={needsYou:[],active:[],recent:[]};for(const n of e)t[n4e[n.status.kind]].push(n);return["needsYou","active","recent"].filter(n=>t[n].length>0).map(n=>({key:n,rows:t[n]}))}function i4e(e,t,n,r,i=Date.now(),s="en",a=so,l=!1){if(e===null)return{rows:P2(t,i,s,a,l),starredRows:[],scheduleRows:JS(r,n)};const c=p=>p.projectId===e,u=vH(t.filter(c),n.filter(c)),d=[...u.starred,...u.direct];return{rows:P2(u.direct,i,s,a,l,d),starredRows:P2(u.starred,i,s,a,l,d),scheduleRows:JS(r.filter(p=>p.projectId===e),u.scheduled)}}function P2(e,t=Date.now(),n="en",r=so,i=!1,s=e){if(!i)return Uh(e).map(u=>yH(u,t,n,r));const{top:a,workers:l}=xj(s,t),c=new Set(a.map(u=>u.sessionId));return Uh(e.filter(u=>c.has(u.sessionId))).map(u=>t4e(u,l.get(u.sessionId)??[],t,n,r))}const o4e={connected:"var(--proto-success)",connecting:"var(--proto-amber)",reconnecting:"var(--proto-amber)",disconnected:C.muted};function bH({presence:e}){return o.jsxs("div",{"aria-hidden":"true",style:{position:"relative",width:26,height:26,flex:"none",display:"grid",placeItems:"center"},children:[o.jsxs("svg",{width:26,height:26,viewBox:"0 0 64 64",fill:"none","aria-hidden":"true",children:[o.jsx("circle",{cx:"33",cy:"32",r:"6",fill:"var(--proto-ink)"}),o.jsx("path",{d:"M42.29 23.64A12.5 12.5 0 1 0 42.29 40.36",stroke:"var(--proto-accent)",strokeWidth:6,strokeLinecap:"round"}),o.jsx("path",{d:"M48.6 17.95A21 21 0 1 0 48.6 46.05",stroke:"var(--proto-accent)",strokeWidth:6,strokeLinecap:"round"})]}),o.jsx("span",{style:{position:"absolute",right:-1,bottom:0,width:8,height:8,borderRadius:"50%",background:o4e[e],boxShadow:"0 0 0 2px var(--m-canvas)"}})]})}function s4e({presence:e,projects:t}){const n=Z(),r=t.needsYou,i=r>0?G(n.slProjectsNeedYou,{n:r}):n.projTitle;return o.jsxs("button",{type:"button","aria-label":i,"data-projects-button":"",onClick:t.onOpen,style:a4e,children:[o.jsx(bH,{presence:e}),r>0&&o.jsx("span",{"aria-hidden":"true","data-needs-you-count":"",style:l4e,children:r})]})}const a4e={position:"relative",minWidth:44,height:44,margin:"0 -4px 0 -9px",padding:"0 9px",flex:"none",border:0,background:"transparent",display:"flex",alignItems:"center",gap:4,cursor:"pointer",boxSizing:"border-box"},l4e={fontSize:13,fontWeight:650,color:"var(--proto-amber-fg)",...$e};function c4e({unread:e,onClick:t}){const n=Z();return o.jsxs("div",{style:{position:"relative",flex:"none"},children:[o.jsx("button",{type:"button","aria-label":n.schedSheetTitle,onClick:t,style:u4e,children:o.jsxs("svg",{width:19,height:19,viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:1.5,strokeLinecap:"round","aria-hidden":"true",children:[o.jsx("circle",{cx:"8",cy:"8",r:"5.5"}),o.jsx("path",{d:"M8 5v3l2 1.5"})]})}),e>0&&o.jsx("span",{"aria-label":G(n.slUnreadScheduled,{n:e}),style:d4e,children:e})]})}const u4e={width:44,height:44,borderRadius:"var(--r-control)",background:"transparent",border:0,color:"var(--proto-muted)",display:"grid",placeItems:"center",cursor:"pointer",padding:0},d4e={position:"absolute",top:5,right:4,color:"var(--proto-accent)",fontSize:11,fontWeight:650,...$e},f4e={running:{background:"var(--proto-accent)",boxShadow:"0 0 0 3px var(--proto-accent-bg)"},background:{background:"var(--proto-accent)",boxShadow:"0 0 0 3px var(--proto-accent-bg)"},awaiting:{background:"var(--proto-amber)"},"waiting-external":{border:`1.5px solid ${C.muted}`}},wH={whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"};function p4e({status:e}){return o.jsx("span",{"aria-hidden":"true",style:{width:12,flex:"none",display:"flex",justifyContent:"center",paddingTop:8},children:e.kind!=="idle"&&o.jsx("span",{"data-status-dot":e.kind,style:{width:7,height:7,borderRadius:"50%",boxSizing:"border-box",flex:"none",...f4e[e.kind]}})})}function h4e({status:e}){if(e.kind==="idle")return null;const t=e.kind==="awaiting"?"var(--proto-amber-fg)":C.muted;return o.jsx("div",{style:{marginTop:2,fontSize:14,color:t,...$e,...wH},children:e.text})}function m4e({row:e}){const t=Z();return o.jsxs("div",{style:{flex:"none",display:"flex",alignItems:"center",gap:6,paddingTop:3},children:[o.jsx("span",{style:{fontSize:13,color:C.faint,...$e},children:e.time}),e.unread&&o.jsx("span",{"aria-label":t.slUnread,style:{width:7,height:7,borderRadius:"50%",background:"var(--proto-accent)",flex:"none"}})]})}function $R({row:e,onOpen:t}){const n=e.unread||e.status.kind==="awaiting";return o.jsxs("div",{className:"m-press","data-session-id":e.id,onClick:()=>t(e.id),style:{display:"flex",alignItems:"flex-start",gap:12,minHeight:48,padding:"11px 14px",boxSizing:"border-box",borderRadius:"var(--r-control)",cursor:"pointer"},children:[o.jsx(p4e,{status:e.status}),o.jsxs("div",{style:{flex:1,minWidth:0},children:[o.jsx("div",{style:{fontSize:16,lineHeight:"22px",fontWeight:n?650:550,color:C.ink,...wH},children:e.title}),o.jsx(h4e,{status:e.status})]}),o.jsx(m4e,{row:e})]})}const g4e={position:"absolute",right:jx+10,bottom:Kle,height:50,padding:"0 20px 0 16px",border:0,borderRadius:"var(--r-pill)",background:C.inkSolid,color:C.inkSolidFg,display:"flex",alignItems:"center",gap:8,fontFamily:"var(--font-ui)",fontSize:15,fontWeight:600,cursor:"pointer",boxShadow:"var(--shadow-key-lift)"};function v4e({title:e,presence:t,project:n,projects:r,scheduled:i}){const s=n&&{label:n.switchLabel,onOpen:n.onSwitch};return o.jsx(NW,{title:(n==null?void 0:n.name)??e,titleMenu:s,leading:r?o.jsx(s4e,{presence:t,projects:r}):o.jsx(bH,{presence:t}),trailing:i&&o.jsx(c4e,{unread:i.unread,onClick:i.onOpen})})}const x4e={needsYou:"mSectionNeedsYou",active:"mSectionActive",recent:"mSectionRecent"};function y4e({rows:e,stars:t,empty:n,onOpen:r}){const i=Z();return o.jsxs(kf,{gap:0,padding:SF,children:[t&&o.jsx(Ywe,{projectId:t.projectId,count:t.rows.length,expanded:t.expanded,onToggle:t.onToggle,mobile:!0,children:t.rows.map(s=>o.jsx($R,{row:s,onOpen:r},s.id))}),e.length===0&&!(t!=null&&t.rows.length)&&o.jsx(Hme,{children:n}),r4e(e).map(s=>o.jsxs("section",{"data-session-section":s.key,children:[o.jsx(Yx,{style:{fontSize:13,padding:"14px 14px 2px"},children:i[x4e[s.key]]}),s.rows.map(a=>o.jsx($R,{row:a,onOpen:r},a.id))]},s.key)),o.jsx("div",{style:{height:72,flex:"none"}})]})}function b4e({rows:e,stars:t,presence:n,project:r,projects:i,newLabel:s,scheduled:a,onOpen:l,onNew:c}){const u=Z(),d=o.jsxs("button",{type:"button","aria-label":s,title:s,onClick:c,style:g4e,children:[o.jsx(Ba,{size:16,strokeWidth:2}),o.jsx("span",{"aria-hidden":"true",children:s})]});return o.jsx(hl,{label:"1a sessions",floatingHeader:!0,overlay:d,header:o.jsx(v4e,{title:u.sessions,presence:n,project:r,projects:i,scheduled:a}),children:o.jsx(y4e,{rows:e,stars:t,empty:u.slEmpty,onOpen:l})})}const w4e=800;function S4e(e,t){const n=ve(),r=_e(),i=Se(n.sessions.markRead.mutationOptions({onSuccess:()=>{r.invalidateQueries(n.sessions.list.queryFilter())}})),s=f.useRef(i.mutate);s.current=i.mutate;const a=f.useRef(null);f.useEffect(()=>{if(!e)return;const l=()=>{document.visibilityState==="visible"&&(a.current&&clearTimeout(a.current),a.current=setTimeout(()=>{s.current({sessionId:e})},w4e))};l();const c=()=>{document.visibilityState==="visible"&&l()};return document.addEventListener("visibilitychange",c),()=>{document.removeEventListener("visibilitychange",c),a.current&&clearTimeout(a.current)}},[e,t])}function SH(){const e=ve(),t=_e(),n=Se(e.sessions.markManyRead.mutationOptions({onSuccess:()=>{t.invalidateQueries(e.sessions.list.queryFilter())}}));return{markManyRead:r=>{r.length!==0&&n.mutate({sessionIds:r})},pending:n.isPending}}function k4e(e){return e instanceof Error?e:new Error(String(e))}async function j4e(e,t){if(e.mode==="edit"){if(!e.schedule)return!1;await t.update(e.schedule.id,e.form)}else await t.add(e.form);return!0}async function C4e(e,t){try{return!await j4e(e,t)||(await t.invalidate(),!t.isCurrent(e.generation))?!1:(t.success(e.mode),t.close(e.generation),!0)}catch(n){return t.isCurrent(e.generation)&&t.failure(e.mode,k4e(n)),!1}}function T4e(e){return e?e.mode==="edit"?{mode:"edit",form:cH(e.schedule),schedule:e.schedule,generation:0}:{mode:"create",form:aH(e.projectId),schedule:null,generation:0}:null}function E4e(e){const[t,n]=f.useState(()=>T4e(e)),[r,i]=f.useState(null),s=f.useRef(0),a=f.useRef(!0);f.useEffect(()=>(a.current=!0,()=>{a.current=!1}),[]);const l=f.useCallback(()=>++s.current,[]),c=f.useCallback(m=>a.current&&s.current===m,[]),u=f.useCallback(()=>{l(),n(null),i(null)},[l]),d=f.useCallback(m=>{s.current===m&&u()},[u]),p=f.useCallback(m=>{i(null),n({mode:"edit",form:cH(m),schedule:m,generation:l()})},[l]),h=f.useCallback(m=>{n(v=>v&&{...v,form:Pwe(v.form,v.mode,m)})},[]);return{state:t,error:r,setError:i,close:u,closeGeneration:d,isCurrent:c,openEdit:p,onChange:h}}function R4e(e){var l,c;const t=ve(),n=_e(),r=xe(t.config.get.queryOptions({})),i=xe(t.models.catalog.queryOptions({},{enabled:e!==null,refetchInterval:u=>{var d;return(d=u.state.data)!=null&&d.piPending?2500:!1}})),s=Se(t.schedules.add.mutationOptions({})),a=Se(t.schedules.update.mutationOptions({}));return{add:s,update:a,pending:s.isPending||a.isPending,defaultSelection:(c=(l=r.data)==null?void 0:l.models)==null?void 0:c.default,models:Ewe(r.data,i.data,(e==null?void 0:e.selection)??null),thinking:Rwe(i.data,(e==null?void 0:e.selection)??null),invalidate:()=>n.invalidateQueries(t.schedules.list.queryFilter())}}function M4e(e,t,n,r){return f.useCallback(async()=>!e||t.pending||!uH(e.form,e.mode).ok?!1:(n.setError(null),C4e(e,{add:i=>t.add.mutateAsync(Lwe(i)),update:(i,s)=>t.update.mutateAsync(Nwe(i,s)),invalidate:t.invalidate,isCurrent:n.isCurrent,success:i=>{var s,a;return i==="edit"?(s=r.onUpdated)==null?void 0:s.call(r):(a=r.onCreated)==null?void 0:a.call(r)},failure:(i,s)=>{var a;n.setError(s.message),(a=r.onError)==null||a.call(r,i,s)},close:n.closeGeneration})),[n.closeGeneration,n.isCurrent,n.setError,r,t,e])}function A4e(e){return(e==null?void 0:e.form)??null}function P4e(e){return(e==null?void 0:e.mode)??null}function I4e(e){return e??"create"}function L4e(e){return(e==null?void 0:e.type)??"daily"}function N4e(e,t){return e?uH(e,t).ok:!1}function D4e(e){const t=A4e(e),n=P4e(e),r=I4e(n);return{form:t,mode:n,editableFields:lH(r,L4e(t)),valid:N4e(t,r)}}function kH(e={},t){var a;const n=E4e(t),r=D4e(n.state),i=R4e(r.form);f.useEffect(()=>{var l;r.mode==="create"&&((l=r.form)==null?void 0:l.selection)===null&&i.defaultSelection&&n.onChange({selection:i.defaultSelection})},[r.mode,(a=r.form)==null?void 0:a.selection,i.defaultSelection,n.onChange]);const s=M4e(n.state,i,n,e);return{...r,modelOptions:i.models,thinkingOptions:i.thinking,pending:i.pending,error:n.error,openEdit:n.openEdit,close:n.close,onChange:n.onChange,submit:s}}function jH(){const e=M(),{toast:t}=Rt();return{onCreated:()=>t({title:e.scToastCreated,tone:"done"}),onUpdated:()=>t({title:e.scToastUpdated,tone:"done"}),onError:(n,r)=>t({title:n==="edit"?e.scToastUpdateFailed:e.scToastCreateFailed,description:r.message,tone:"failed"})}}const xl={display:"block",marginBottom:5,color:C.muted,fontSize:13,fontWeight:600},Ts={width:"100%",minWidth:0,minHeight:44,boxSizing:"border-box",border:`1px solid ${C.hairline}`,borderRadius:"var(--r-control)",padding:"8px 10px",background:"var(--material-inset-bg)",color:C.ink,fontSize:16,fontFamily:"inherit"},CH={display:"grid",gridTemplateColumns:"repeat(2, minmax(0, 1fr))",gap:8};function O4e({copy:e,mode:t,onBack:n}){return o.jsxs("div",{style:{display:"flex",alignItems:"center",gap:9,padding:"0 2px 12px"},children:[o.jsx("button",{type:"button","data-action":"sheet-back",onClick:n,"aria-label":e.back,style:{border:0,background:"transparent",color:C.ink,padding:0,margin:"0 -8px 0 -10px",cursor:"pointer",minWidth:44,minHeight:44,display:"grid",placeItems:"center"},children:o.jsx(Ds,{})}),o.jsx("span",{style:{fontSize:17,fontWeight:650,color:C.ink},children:t==="edit"?e.scEditSchedule:e.scNewSchedule})]})}function F4e({copy:e,form:t,editableFields:n,onChange:r}){const i={interval:e.scTypeInterval,daily:e.scTypeDaily,weekly:e.scTypeWeekly,once:e.scTypeOnce};return o.jsxs("div",{children:[o.jsx("span",{style:xl,children:e.scType}),o.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(4, 1fr)",border:`1px solid ${C.hairline}`,borderRadius:"var(--r-chip)",overflow:"hidden"},children:rH.map(s=>o.jsx(_4e,{type:s,form:t,disabled:!n.type,label:i[s],onChange:r},s))})]})}function _4e({type:e,form:t,disabled:n,label:r,onChange:i}){const s=t.type===e;return o.jsx("button",{type:"button",disabled:n,"aria-pressed":s,onClick:()=>i({type:e}),style:{border:0,borderRight:e==="once"?0:`1px solid ${C.hairline}`,padding:"8px 2px",minHeight:44,background:s?"var(--proto-gray)":"var(--material-control-bg)",boxShadow:"var(--material-control-shadow)",fontFamily:"var(--font-ui)",color:s?C.ink:C.muted,fontSize:13,fontWeight:s?600:400},children:r})}function z4e({copy:e,form:t,editableFields:n,onChange:r}){return Ef(t.type).time?o.jsxs("label",{children:[o.jsx("span",{style:xl,children:e.scTime}),o.jsx("input",{style:Ts,value:t.time,disabled:!n.time,onChange:i=>r({time:i.target.value})})]}):null}function W4e({copy:e,form:t,editableFields:n,onChange:r}){return Ef(t.type).interval?o.jsxs("div",{children:[o.jsx("span",{style:xl,children:e.scEvery}),o.jsxs("div",{style:CH,children:[o.jsx("input",{style:Ts,type:"number",min:1,value:t.intervalValue,disabled:!n.interval,onChange:i=>r({intervalValue:Number(i.target.value)})}),o.jsx(cl,{style:Ts,title:e.scEvery,value:t.intervalUnit,disabled:!n.interval,onValueChange:i=>r({intervalUnit:i}),options:p1.map(i=>({value:i,label:h1(i,e)}))})]})]}):null}function B4e({copy:e,form:t,editableFields:n,onChange:r}){return!Ef(t.type).delay||!n.delay?null:o.jsxs("div",{"data-schedule-delay":!0,children:[o.jsx("span",{style:xl,children:e.scIn}),o.jsxs("div",{style:CH,children:[o.jsx("input",{style:Ts,type:"number",min:1,value:t.delayValue,onChange:i=>r({delayValue:Number(i.target.value)})}),o.jsx(cl,{style:Ts,title:e.scIn,value:t.delayUnit,onValueChange:i=>r({delayUnit:i}),options:p1.map(i=>({value:i,label:h1(i,e)}))})]})]})}function $4e({copy:e,form:t,mode:n}){return n!=="edit"||t.type!=="once"?null:o.jsx("div",{"data-once-timing-note":!0,style:{border:`1px solid ${C.hairline}`,borderRadius:"var(--r-chip)",padding:10,color:C.muted,fontSize:11.5,lineHeight:1.5},children:e.scOnceTimingUnavailable})}function H4e({copy:e,form:t,editableFields:n,onChange:r}){if(!Ef(t.type).dayOfWeek)return null;const i=[e.scDaySun,e.scDayMon,e.scDayTue,e.scDayWed,e.scDayThu,e.scDayFri,e.scDaySat];return o.jsxs("label",{children:[o.jsx("span",{style:xl,children:e.scDay}),o.jsx(cl,{style:Ts,title:e.scDay,value:String(t.dayOfWeek),disabled:!n.dayOfWeek,onValueChange:s=>r({dayOfWeek:Number(s)}),options:iH.map(s=>({value:String(s),label:i[s]}))})]})}function U4e({copy:e,form:t,editableFields:n,modelOptions:r,onChange:i}){return o.jsxs("label",{children:[o.jsx("span",{style:xl,children:e.scModel}),o.jsx(cl,{style:Ts,title:e.scModel,"data-schedule-select":"model","aria-label":e.scModel,value:t.selection?ot(t.selection):"",disabled:!n.selection,onValueChange:s=>i(oH(r,s)),options:[{value:"",label:e.scChooseModel,disabled:!0},...r.map(s=>({value:s.value,label:`${s.favorite?"★ ":""}${s.label}`,disabled:!s.selection.mode}))]})]})}function V4e({copy:e,form:t,editableFields:n,thinkingOptions:r,onChange:i}){var s;return o.jsxs("label",{children:[o.jsx("span",{style:xl,children:e.scThinking}),o.jsx(cl,{style:Ts,title:e.scThinking,"data-schedule-select":"thinking","aria-label":e.scThinking,value:((s=t.selection)==null?void 0:s.thinking)??"",disabled:!n.selection||!t.selection,onValueChange:a=>i(sH(t,a)),options:r.map(a=>({value:a,label:a||e.scThinkingDefault}))})]})}function q4e({copy:e,form:t,editableFields:n,onChange:r}){return o.jsxs("label",{children:[o.jsx("span",{style:xl,children:e.scMessage}),o.jsx("textarea",{style:{...Ts,minHeight:82,resize:"vertical"},value:t.message,disabled:!n.message,onChange:i=>r({message:i.target.value})})]})}function K4e({copy:e,mode:t,valid:n,pending:r,error:i,onSubmit:s}){return o.jsxs(o.Fragment,{children:[i&&o.jsx("div",{role:"alert",style:{color:C.fail,fontSize:12.5},children:i}),o.jsx("button",{type:"button","data-action":"save-schedule",disabled:!n||r,onClick:s,style:{border:0,borderRadius:"var(--r-control)",height:44,background:C.inkSolid,color:C.inkSolidFg,fontFamily:"var(--font-ui)",fontSize:15,fontWeight:600,opacity:n&&!r?1:.45,cursor:n&&!r?"pointer":"default"},children:t==="edit"?e.scSaveSchedule:e.scCreateSchedule})]})}function G4e(e){return o.jsxs("div",{style:{display:"grid",gap:12},children:[o.jsx(F4e,{...e}),o.jsx(z4e,{...e}),o.jsx(W4e,{...e}),o.jsx(B4e,{...e}),o.jsx($4e,{...e}),o.jsx(H4e,{...e}),o.jsx(U4e,{...e}),o.jsx(V4e,{...e}),o.jsx(q4e,{...e}),o.jsx(K4e,{...e})]})}function Y4e(e){const t=M(),n={...e,copy:t};return o.jsxs("div",{"data-mobile-schedule-editor":!0,children:[o.jsx(O4e,{...n}),o.jsx(G4e,{...n})]})}function bj({size:e,color:t}){return o.jsxs("svg",{width:e,height:e,viewBox:"0 0 14 14",fill:"none",stroke:t,strokeWidth:1.6,style:{flex:"none"},children:[o.jsx("circle",{cx:"7",cy:"7",r:"5.6"}),o.jsx("path",{d:"M7 4v3.2l2.2 1.3"})]})}function Q4e({sub:e}){return e.kind!=="run"?null:o.jsxs(o.Fragment,{children:[e.stamp,e.cost&&o.jsxs(o.Fragment,{children:[" · ",e.cost]})]})}function X4e({sub:e,copy:t}){return e.kind!=="pending"?null:o.jsxs(o.Fragment,{children:[e.cadence,e.nextDelta&&o.jsxs(o.Fragment,{children:[" · ",G(t.schedNextIn,{d:e.nextDelta})]})]})}function Z4e({sub:e,copy:t}){return e.kind!=="paused"?null:o.jsxs(o.Fragment,{children:[e.cadence," · ",o.jsx("span",{style:{color:C.amberText},children:t.wbSchedPausedPill})]})}function J4e({row:e,copy:t,now:n}){const r=Qe(),i=pH(e,n,r);return o.jsxs("div",{style:{fontSize:12.5,color:C.muted,marginTop:2,...$e},children:[o.jsx(Q4e,{sub:i}),o.jsx(X4e,{sub:i,copy:t}),o.jsx(Z4e,{sub:i,copy:t})]})}function eSe({rows:e,copy:t}){return o.jsxs("div",{style:{display:"flex",alignItems:"center",gap:9,padding:"0 2px 10px"},children:[o.jsx(bj,{size:14,color:C.muted}),o.jsx("span",{style:{fontSize:17,fontWeight:650,color:C.ink},children:t.schedSheetTitle}),o.jsx("span",{style:{fontSize:13,color:C.muted,...$e},children:G(t.schedSheetCount,{n:e.length})})]})}function tSe(e){return{display:"flex",alignItems:"center",gap:9,padding:13,minHeight:44,boxSizing:"border-box",cursor:"pointer",borderBottom:e?"none":`1px solid ${C.divider}`}}function nSe({row:e,copy:t}){return o.jsxs(o.Fragment,{children:[o.jsx("span",{style:{fontSize:12.5,color:C.muted,flex:"none",...$e},children:e.kind==="repeat"?`×${e.runs.length}`:t.scTypeOnce}),e.unread&&o.jsx("span",{style:{width:7,height:7,borderRadius:"50%",background:C.run,flex:"none"}}),o.jsx("span",{style:{fontSize:13,color:C.muted,flex:"none"},children:"›"})]})}function rSe({row:e,copy:t,now:n,last:r,onRow:i}){return o.jsxs("div",{"data-schedule-row":e.scheduleId,onClick:()=>i(e),style:tSe(r),children:[o.jsx(bj,{size:13,color:C.muted}),o.jsx(iSe,{row:e,copy:t,now:n}),o.jsx(nSe,{row:e,copy:t})]})}function iSe({row:e,copy:t,now:n}){return o.jsxs("div",{style:{minWidth:0,flex:1},children:[o.jsx("div",{style:{fontSize:14,fontWeight:e.unread?600:400,color:e.unread?C.ink:"var(--proto-muted)",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:e.title}),o.jsx(J4e,{row:e,copy:t,now:n})]})}function oSe({rows:e,copy:t,now:n,onRow:r}){return o.jsx("div",{style:{background:"transparent",border:`1px solid ${C.hairline}`,borderRadius:"var(--r-card)",overflow:"hidden"},children:e.map((i,s)=>o.jsx(rSe,{row:i,copy:t,now:n,last:s===e.length-1,onRow:r},i.scheduleId))})}function sSe({rows:e,copy:t,now:n,onRow:r}){return o.jsxs(o.Fragment,{children:[o.jsx(eSe,{rows:e,copy:t}),o.jsx(oSe,{rows:e,copy:t,now:n,onRow:r})]})}function aSe(e,t,n,r){const i=e.schedule;if(!i)return null;const s=mj(i.nextRun,n,r),a=i.paused?` · ${t.wbSchedPausedPill}`:s?` · ${G(t.schedNextIn,{d:s})}`:"";return Hh(i,r)+a}function lSe({row:e,copy:t,now:n,onBack:r}){const i=Qe(),s=aSe(e,t,n,i);return o.jsxs("div",{style:{display:"flex",alignItems:"center",gap:9,padding:"0 2px 10px"},children:[o.jsx("span",{"data-action":"sheet-back",role:"button","aria-label":t.back,onClick:r,style:{color:C.ink,flex:"none",cursor:"pointer",minWidth:44,minHeight:44,margin:"0 -8px 0 -10px",display:"inline-flex",alignItems:"center",justifyContent:"center"},children:o.jsx(Ds,{})}),o.jsx(bj,{size:14,color:C.muted}),o.jsxs("div",{style:{minWidth:0},children:[o.jsx("div",{style:{fontSize:17,fontWeight:650,color:C.ink,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:e.title}),s&&o.jsx("div",{style:{fontSize:12.5,color:C.muted,marginTop:1,...$e},children:s})]})]})}function cSe({copy:e}){return o.jsxs("div",{style:{display:"grid",gridTemplateColumns:"64px 1fr 70px",gap:10,padding:"4px 15px 6px",fontSize:12,fontWeight:600,color:C.muted},children:[o.jsx("span",{children:e.schedColRun}),o.jsx("span",{children:e.schedColFired}),o.jsx("span",{style:{textAlign:"right"},children:e.schedColCost})]})}function uSe(e){return{display:"grid",gridTemplateColumns:"64px 1fr 70px",gap:10,padding:13,minHeight:44,boxSizing:"border-box",alignItems:"center",cursor:"pointer",borderTop:e?"none":`1px solid ${C.divider}`}}function dSe({run:e,ordinal:t}){return o.jsxs("span",{style:{fontSize:13,fontWeight:e.unread?600:400,...$e,color:e.unread?C.ink:"var(--proto-muted)",display:"flex",alignItems:"center",gap:6},children:["#",t,e.unread&&o.jsx("span",{style:{width:6,height:6,borderRadius:"50%",background:C.run}})]})}function fSe({cost:e}){return o.jsx("span",{style:{fontSize:13,color:C.muted,textAlign:"right",...$e},children:e!=null?qi(e):"—"})}function pSe({run:e,ordinal:t,first:n,now:r,onOpenRun:i}){return o.jsxs("div",{"data-run-row":e.sessionId,onClick:()=>i(e.sessionId),style:uSe(n),children:[o.jsx(dSe,{run:e,ordinal:t}),o.jsx("span",{style:{fontSize:13,color:"var(--proto-muted-2)",...$e},children:gj(e,r)}),o.jsx(fSe,{cost:e.costUsd})]})}function hSe({row:e,now:t,onOpenRun:n}){const r=vj(e.runs);return o.jsx("div",{style:{background:"transparent",border:`1px solid ${C.hairline}`,borderRadius:"var(--r-card)",overflow:"hidden",maxHeight:"46vh",overflowY:"auto"},children:e.runs.map((i,s)=>o.jsx(pSe,{run:i,ordinal:r.get(i.sessionId),first:s===0,now:t,onOpenRun:n},i.sessionId))})}function mSe({unreadIds:e,copy:t,pending:n,onMarkAllRead:r}){return o.jsx("button",{type:"button","data-action":"mark-all-read",disabled:n,onClick:()=>r(e),style:{marginLeft:"auto",border:0,background:"transparent",color:C.run,fontFamily:"var(--font-ui)",fontSize:13,fontWeight:600,cursor:n?"default":"pointer",opacity:n?.5:1,padding:0},children:G(t.schedMarkRead,{n:e.length})})}function gSe({row:e,copy:t,onEdit:n,onMarkAllRead:r,markAllPending:i=!1}){const s=hH(e);return o.jsxs("div",{style:{display:"flex",alignItems:"center",flexWrap:"wrap",padding:"10px 4px 0",gap:10},children:[o.jsx("span",{style:{fontSize:13,fontWeight:600,color:C.muted,...$e},children:G(t.schedAllRuns,{n:e.runs.length})}),n&&o.jsx("button",{type:"button","data-action":"edit-schedule",onClick:n,style:{border:0,background:"transparent",color:C.run,fontFamily:"var(--font-ui)",fontSize:13,fontWeight:600,cursor:"pointer"},children:t.scEditSchedule}),r&&s.length>0?o.jsx(mSe,{unreadIds:s,copy:t,pending:i,onMarkAllRead:r}):null]})}function vSe({row:e,copy:t,now:n,onBack:r,onOpenRun:i,onEdit:s,onMarkAllRead:a,markAllPending:l}){return o.jsxs(o.Fragment,{children:[o.jsx(lSe,{row:e,copy:t,now:n,onBack:r}),o.jsx(cSe,{copy:t}),o.jsx(hSe,{row:e,now:n,onOpenRun:i}),o.jsx(gSe,{row:e,copy:t,onEdit:s,onMarkAllRead:a,markAllPending:l})]})}function xSe(e){const[t,n]=f.useState({kind:"list"}),r=f.useCallback(()=>n(s=>s.kind==="editor"?(e.close(),s.returnTo):{kind:"list"}),[e.close]),i=f.useCallback((s,a)=>{e.openEdit(s),n({kind:"editor",returnTo:a})},[e.openEdit]);return{level:t,setLevel:n,back:r,openEditor:i}}function ySe(e,t,n){return f.useCallback(r=>{const i=fH(r);if(i.type==="modal"){t({kind:"runs",scheduleId:r.scheduleId});return}if(i.type==="open")return e(i.sessionId);n(i.schedule,{kind:"list"})},[e,n,t])}function bSe(e,t){return f.useCallback(()=>{e.submit().then(n=>{n&&t(r=>r.kind==="editor"?r.returnTo:{kind:"list"})})},[e.submit,t])}function wSe(e,t){return t.kind!=="runs"?null:e.find(n=>n.scheduleId===t.scheduleId)??null}function SSe({row:e,copy:t,now:n,back:r,onOpenSession:i,openEditor:s,onMarkAllRead:a,markAllPending:l}){const c=e.schedule?()=>s(e.schedule,{kind:"runs",scheduleId:e.scheduleId}):void 0;return o.jsx(vSe,{row:e,copy:t,now:n,onBack:r,onOpenRun:i,onEdit:c,onMarkAllRead:a,markAllPending:l})}function kSe(e,t,n,r){return e.kind!=="editor"||!t.form||!t.mode?null:o.jsx(Y4e,{form:t.form,mode:t.mode,editableFields:t.editableFields,modelOptions:t.modelOptions,thinkingOptions:t.thinkingOptions,valid:t.valid,pending:t.pending,error:t.error,onChange:t.onChange,onSubmit:n,onBack:r})}function jSe({rows:e,copy:t,editor:n,level:r,runsRow:i,now:s,back:a,onOpenSession:l,onRow:c,openEditor:u,submit:d,onMarkAllRead:p,markAllPending:h}){const m=kSe(r,n,d,a);return m||(i?o.jsx(SSe,{row:i,copy:t,now:s,back:a,onOpenSession:l,openEditor:u,onMarkAllRead:p,markAllPending:h}):o.jsx(sSe,{rows:e,copy:t,now:s,onRow:c}))}function CSe(e){const t=Z(),{rows:n,editor:r,onOpenSession:i,onClose:s}=e,a=xSe(r),l=wSe(n,a.level),c=ySe(i,a.setLevel,a.openEditor),u=bSe(r,a.setLevel),d=f.useCallback(()=>{r.close(),s()},[r.close,s]),p=a.level.kind==="list"?void 0:a.back;return o.jsx(Kn,{onClose:d,onBack:p,children:o.jsx(jSe,{...e,copy:t,level:a.level,runsRow:l,now:e.now??Date.now(),back:a.back,onRow:c,openEditor:a.openEditor,submit:u})})}function TSe(e){const t=SH(),n=kH(jH());return o.jsx(CSe,{...e,editor:n,onMarkAllRead:t.markManyRead,markAllPending:t.pending})}function ESe(e){try{const t=window.localStorage.getItem(e);if(!t)return new Set;const n=JSON.parse(t);return new Set(Array.isArray(n)?n.filter(r=>typeof r=="string"):[])}catch{return new Set}}function RSe(e,t){try{window.localStorage.setItem(e,JSON.stringify([...t]))}catch{}}function Zg(e){const[t,n]=f.useState(()=>ESe(e)),r=f.useCallback(l=>{n(c=>{const u=l(c);return u!==c&&RSe(e,u),u})},[e]),i=f.useCallback(l=>r(c=>{const u=new Set(c);return u.delete(l)||u.add(l),u}),[r]),s=f.useCallback(l=>r(c=>c.has(l)?c:new Set(c).add(l)),[r]),a=f.useCallback(l=>r(c=>{if(!c.has(l))return c;const u=new Set(c);return u.delete(l),u}),[r]);return f.useMemo(()=>({ids:t,toggle:i,add:s,remove:a}),[t,i,s,a])}const MSe="cortex.projectStarsCollapsed";function TH(){const{ids:e,toggle:t,remove:n}=Zg(MSe);return{collapsed:e,toggle:t,reveal:n}}const Kp=e=>e<10?`0${e}`:`${e}`,EH={running:"execStatusRunning",completed:"execStatusCompleted",failed:"execStatusFailed",cancelled:"execStatusCancelled",stale:"execStatusStale"};function RH(e){return Object.prototype.hasOwnProperty.call(EH,e)}function wj(e,t){return RH(e)?t[EH[e]]:e}const ASe={running:"●",completed:"✓",failed:"✕",cancelled:"✕",stale:"◦"};function PSe(e,t){return RH(e)?`${ASe[e]} ${wj(e,t)}`:e}function ISe(e){if(!e)return"";const t=new Date(e);return`${Kp(t.getUTCHours())}:${Kp(t.getUTCMinutes())}`}function LSe(e){const t=e.runtime.endedAt??e.runtime.updatedAt,n=new Date(t);return`${Kp(n.getUTCHours())}:${Kp(n.getUTCMinutes())}:${Kp(n.getUTCSeconds())}`}function NSe(e,t){const n=e.runtime.endedAt;return n?G(t.execFinishedAt,{time:ISe(n)}):wj("running",t)}function DSe(e){return e==="running"}function Sj(e){if(e.actions.some(n=>n.action==="approve"))return"approved";const t=e.actions[e.actions.length-1];return t?t.action==="explain"?"explained":"revised":"none"}function HR(e,t,n,r){const i=r.trim();return t==="revise"?i?e.revise.replace("{title}",n).replace("{text}",i):null:i?e.explain.replace("{title}",n).replace("{text}",i):e.explainBare.replace("{title}",n)}function or(e){return e.awaitingInput&&!e.teamLeadId?"you":e.running?"running":(e.waitingOn??0)>0?"waiting":"idle"}const UR={you:0,running:1,waiting:2,idle:3};function Tc(e){return e.workerName||e.label||Ti(e.sessionId)}function Ja(e,t=Date.now()){const n=i=>_0(i,t);return{active:[...e.filter(i=>!n(i))].sort((i,s)=>UR[or(i)]-UR[or(s)]),inactive:e.filter(n)}}function kj(e,t){const r=e.map(or).filter(i=>i==="running").length;return{workers:G(e.length===1?t.wbTeamCountOne:t.wbTeamCountMany,{n:e.length}),running:r>0?G(t.wbTeamRunningCount,{n:r}):null}}function jj(e,t){const n=kj(e,t);return[n.workers,n.running].filter(Boolean).join(" · ")}function Cj(e,t,n,r){const i=Date.parse(e.lastUsedAt),s=Number.isNaN(i)?null:_c(t-i,r);switch(or(e)){case"you":return n.wbTeamStatusYou;case"running":return s&&!e.backgroundRunning?G(n.wbTeamStatusRunningFor,{span:s}):n.wbTeamStatusRunning;case"waiting":return n.wbTeamStatusWaiting;case"idle":return s?G(n.wbTeamStatusIdleFor,{span:s}):n.wbTeamStatusIdle}}function OSe(e,t,n){const r=or(e);if(r==="you"||r==="waiting"||r==="running"&&e.backgroundRunning)return null;const i=Date.parse(e.lastUsedAt);return Number.isNaN(i)?null:_c(t-i,n)}function FSe(e,t){var n;return t||(or(e)==="running"&&((n=e.todos)!=null&&n.activeLabel)?e.todos.activeLabel:e.workerBrief?e.workerBrief:e.label&&e.label!==Tc(e)?e.label:null)}function _Se(e,t){var i,s,a,l;const n=(a=(s=(i=e==null?void 0:e.askUser)==null?void 0:i.questions[0])==null?void 0:s.question)==null?void 0:a.trim();if(n)return G(t.wbTeamAsks,{text:n});const r=(l=e==null?void 0:e.plan)==null?void 0:l.planContent.split(`
422
+ `.trim();function bye(e){if(!e)return null;const t=e.trim();return t&&!/[;{}<]/.test(t)?t:null}function wye(e,t){const n=bye(t);return[`:root{color-scheme:${e}}`,"html,body{margin:0;padding:0;background:transparent;",n?`color:${n};`:"","font:13px/1.55 -apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,'Helvetica Neue',Arial,sans-serif}"].join("")}const Sye=/<html[\s>]/i,kye=/<head[\s>]/i,jye=/<meta[^>]+http-equiv\s*=\s*["']?content-security-policy/i;function Cye(e,t={}){const n=t.theme??"light",r=typeof e=="string"?e:"",s='<meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">'+(jye.test(r)?"":`<meta http-equiv="Content-Security-Policy" content="${s$()}">`)+`<style>${wye(n,t.ink)}</style><script>${yye}<\/script>`;return Sye.test(r)?kye.test(r)?r.replace(/(<head[^>]*>)/i,`$1${s}`):r.replace(/(<html[^>]*>)/i,`$1<head>${s}</head>`):`<!DOCTYPE html><html><head>${s}</head><body>${r}</body></html>`}function Tye(e,t){const{enabled:n=!0}=t,[r,i]=f.useState(o$);return f.useEffect(()=>{if(!n)return;const s=a=>{const l=e.current;if(!l||a.source!==l.contentWindow)return;const c=xye(a.data);(c==null?void 0:c.type)==="height"&&i(c.value)};return window.addEventListener("message",s),()=>window.removeEventListener("message",s)},[e,n]),r}const E2={kind:"toolarge"};function Eye(e){const t=e.headers.get("content-length"),n=t===null?NaN:Number(t);return Number.isFinite(n)&&n>=0?n:null}function Rye(e,t){const n=new Uint8Array(t);let r=0;for(const i of e)n.set(i,r),r+=i.byteLength;return n}async function a$(e,t){var a;const n=Eye(e);if(n!==null&&n>t)return await((a=e.body)==null?void 0:a.cancel().catch(()=>{})),E2;if(!e.body){const l=new Uint8Array(await e.arrayBuffer());return l.byteLength>t?E2:{kind:"ok",bytes:l}}const r=e.body.getReader(),i=[];let s=0;for(;;){const{done:l,value:c}=await r.read();if(l)return{kind:"ok",bytes:Rye(i,s)};if(s+=c.byteLength,s>t)return await r.cancel().catch(()=>{}),E2;i.push(c)}}async function l$(e,t,n){var i;const r=await fetch(r1(e,"inline"),{headers:Io(),signal:n});if(!r.ok)throw await((i=r.body)==null?void 0:i.cancel().catch(()=>{})),new Error(`download failed: ${r.status}`);return a$(r,t)}function c$(e,t){const[n,r]=f.useState(null),[i,s]=f.useState("loading");return f.useEffect(()=>{const a=new AbortController;return s("loading"),r(null),l$(e,t,a.signal).then(l=>{if(!a.signal.aborted){if(l.kind==="toolarge"){s("toolarge");return}r(new TextDecoder().decode(l.bytes)),s("ok")}}).catch(()=>{a.signal.aborted||s("failed")}),()=>a.abort()},[e,t]),{text:n,state:i}}const Mye=2*1024*1024,Aye="'IBM Plex Mono',monospace";function uy({item:e,mode:t="expanded"}){const n=$x(),r=Z(),i=f.useRef(null),{text:s,state:a}=c$(e.path,Mye),{effectiveTheme:l,ink:c}=f.useMemo(()=>{if(typeof document>"u")return{effectiveTheme:"light",ink:void 0};const h=document.documentElement;return{effectiveTheme:h.getAttribute("data-theme")==="dark"?"dark":"light",ink:getComputedStyle(h).getPropertyValue("--proto-ink").trim()||void 0}},[n]),u=f.useMemo(()=>s===null?null:Cye(s,{theme:l,ink:c}),[s,l,c]),d=t==="inline",p=Tye(i,{enabled:d});return a!=="ok"||u===null?o.jsxs(Pye,{height:d?o$:void 0,children:[a==="loading"&&r.mediaViewLoading,a==="failed"&&r.cmLoadFailed.replace("{name}",e.name),a==="toolarge"&&r.mediaViewTooLarge]}):o.jsx("iframe",{ref:i,title:e.name,sandbox:i$,srcDoc:u,referrerPolicy:"no-referrer",loading:"lazy",style:{display:"block",width:"100%",height:d?p:"100%",border:0,background:"var(--proto-card)"}})}function Pye({children:e,height:t}){return o.jsx("div",{style:{display:"flex",alignItems:"center",justifyContent:"center",height:t??"100%",minHeight:88,padding:"20px",boxSizing:"border-box",color:"var(--proto-muted)",font:`500 11.5px ${Aye}`},children:e})}function u$(e,t){return t<=0||!Number.isFinite(e)?1:Math.min(Math.max(1,Math.floor(e)),t)}function Iye(e,t,n){if(e.length===0)return 1;const r=t+n/2;for(let i=0;i<e.length;i++){const s=e[i];if(r<s.top+s.height)return i+1}return e.length}function Lye(e,t){const n=parseInt(e,10);return Number.isFinite(n)?u$(n,t):null}const d$=1.5,sg={kind:"closed"};class Nye{constructor(t){Pe(this,"abort",new AbortController);Pe(this,"task",null);Pe(this,"doc",null);Pe(this,"wanted",new Set);Pe(this,"drawn",new Set);Pe(this,"running",null);Pe(this,"pumping",!1);Pe(this,"closed",!1);this.canvas=t}async open(t){try{const[n,r]=await Promise.all([t.fetchBytes(this.abort.signal),t.loadPdfjs()]);if(this.closed)return sg;if(n.kind==="toolarge")return{kind:"toolarge"};this.task=r.getDocument({data:n.bytes});const i=await this.task.promise;if(this.closed)return sg;const s=await i.getPage(1);if(this.closed)return sg;this.doc=i;const{width:a,height:l}=s.getViewport({scale:d$});return{kind:"ok",numPages:i.numPages,pageSize:{width:a,height:l}}}catch(n){if(this.closed)return sg;throw n}}show(t){this.closed||!this.doc||(this.wanted.add(t),this.pump())}hide(t){var n;this.wanted.delete(t),((n=this.running)==null?void 0:n.pageNumber)===t&&this.running.task.cancel(),this.drawn.delete(t)&&this.canvas.clear(t)}close(){var t,n;if(!this.closed){this.closed=!0,this.abort.abort(),this.wanted.clear(),(t=this.running)==null||t.task.cancel();for(const r of this.drawn)this.canvas.clear(r);this.drawn.clear(),(n=this.task)==null||n.destroy().catch(()=>{}),this.task=null,this.doc=null}}nextPage(){for(const t of this.wanted)if(!this.drawn.has(t))return t}async pump(){if(!this.pumping){this.pumping=!0;try{for(let t=this.nextPage();t!==void 0&&!this.closed;t=this.nextPage())await this.draw(t)}finally{this.pumping=!1}}}async draw(t){const n=this.doc;if(n){this.drawn.add(t);try{const r=await n.getPage(t);if(this.closed||!this.drawn.has(t))return;const i=this.canvas.draw(t,r);this.running={pageNumber:t,task:i},await i.promise}catch{}finally{this.running=null}}}}const Dye=2*1024*1024,Oye=50*1024*1024,id="'IBM Plex Mono',monospace";function Fye(e){return e.kind==="html"&&e.viewWidth==="full"?"96vw":e.kind==="html"&&e.viewWidth==="wide"?"min(1380px, 96vw)":"min(920px, 96vw)"}const f$=f.createContext({openDoc:()=>{}});function p$({item:e,source:t=!1}){const{text:n,state:r}=c$(e.path,Dye),i=Z();return r==="loading"?o.jsx(od,{children:i.cmLoading}):r==="failed"?o.jsx(od,{failed:!0,children:i.cmLoadFailed.replace("{name}",e.name)}):r==="toolarge"?o.jsx(od,{children:i.mediaTextTooLarge}):!t&&n$(e.name)?o.jsx("div",{style:{padding:"22px 26px",color:"var(--proto-ink)",fontSize:13.5,lineHeight:1.6},children:o.jsx(br,{text:n??""})}):o.jsx("pre",{style:{margin:0,padding:"20px 22px",font:`500 12px/1.6 ${id}`,color:"var(--proto-ink)",whiteSpace:"pre",overflowX:"auto"},children:n})}function h$({item:e,actions:t}){const n=Z(),r=f.useRef(null),i=f.useRef(null),s=f.useRef([]),[a,l]=f.useState("loading"),[c,u]=f.useState(0),[d,p]=f.useState(1),{containerRef:h,style:m,zoom:v,zoomIn:g,zoomOut:x,resetZoom:y}=_6({mode:"css-zoom",maxScale:5});f.useEffect(()=>{const w=i.current;if(!w)return;let R=!1,T=null;w.replaceChildren(),s.current=[],l("loading"),u(0),p(1);const A=[],P=new Nye(zye(A,Math.min(window.devicePixelRatio||1,2)));return P.open({fetchBytes:L=>l$(e.path,Oye,L),loadPdfjs:async()=>(await Wc(async()=>{const{getPdfjs:L}=await import("./pdf-worker-Hp15W1QJ.js");return{getPdfjs:L}},[])).getPdfjs()}).then(L=>{if(!(R||L.kind==="closed")){if(L.kind==="toolarge"){l("toolarge");return}for(let F=1;F<=L.numPages;F++){const B=_ye(L.pageSize);B.dataset.page=String(F),w.appendChild(B),A.push(B)}s.current=A,T=new IntersectionObserver(F=>{for(const B of F){const K=Number(B.target.dataset.page);B.isIntersecting?P.show(K):P.hide(K)}},{root:r.current,rootMargin:"100% 0px"});for(const F of A)T.observe(F);u(L.numPages),l("ok")}}).catch(()=>{R||l("failed")}),()=>{R=!0,T==null||T.disconnect(),P.close()}},[e.path]);const b=f.useCallback(()=>{const w=r.current;if(!w)return[];const R=w.getBoundingClientRect().top-w.scrollTop;return s.current.map(T=>({top:T.getBoundingClientRect().top-R,height:T.offsetHeight}))},[]),S=f.useCallback(()=>{const w=r.current;if(!w)return;const R=Iye(b(),w.scrollTop,w.clientHeight);p(T=>T===R?T:R)},[b]),j=f.useCallback(w=>{const R=r.current,T=s.current[u$(w,c)-1];if(!R||!T)return;const A=T.getBoundingClientRect().top-R.getBoundingClientRect().top+R.scrollTop;R.scrollTo({top:Math.max(0,A-12),behavior:"smooth"})},[c]);return o.jsxs("div",{className:"content-surface",style:{display:"flex",flexDirection:"column",width:"100%",height:"100%"},children:[(c>0&&a!=="failed"||t)&&o.jsx(Wye,{current:d,total:a==="failed"?0:c,onJump:j,scale:v.scale,onZoomIn:g,onZoomOut:x,onZoomReset:y,actions:t}),o.jsxs("div",{ref:w=>{r.current=w,h(w)},onScroll:S,style:{flex:1,minHeight:0,overflow:"auto",padding:"20px 16px",boxSizing:"border-box"},children:[a==="loading"&&o.jsx(od,{children:n.mediaPdfLoading}),a==="failed"&&o.jsx(od,{failed:!0,children:n.mediaPdfFailed.replace("{name}",e.name)}),a==="toolarge"&&o.jsx(od,{children:n.mediaTextTooLarge}),o.jsx("div",{ref:i,style:{...m,maxWidth:900,margin:"0 auto"}})]})]})}function _ye(e){const t=document.createElement("div");return t.style.margin="0 auto 12px",t.style.overflow="hidden",t.style.borderRadius="var(--r-control)",t.style.background="var(--media-paper-bg)",t.style.boxShadow="var(--media-paper-shadow)",m$(t,e),t}function m$(e,t){e.style.maxWidth=`${Math.floor(t.width)}px`,e.style.aspectRatio=`${t.width} / ${t.height}`}function zye(e,t){return{draw(n,r){const i=e[n-1],s=r.getViewport({scale:d$});m$(i,s);const a=document.createElement("canvas");return a.width=Math.floor(s.width*t),a.height=Math.floor(s.height*t),a.style.display="block",a.style.width="100%",a.style.height="100%",i.replaceChildren(a),r.render({canvas:a,viewport:s,transform:t===1?void 0:[t,0,0,t,0,0]})},clear(n){var i;const r=(i=e[n-1])==null?void 0:i.querySelector("canvas");r&&(r.width=0,r.height=0,r.remove())}}}function Wye({current:e,total:t,onJump:n,scale:r,onZoomIn:i,onZoomOut:s,onZoomReset:a,actions:l}){const c=Z(),[u,d]=f.useState(String(e));f.useEffect(()=>{d(String(e))},[e]);const p=()=>{const h=Lye(u,t);h===null?d(String(e)):n(h)};return o.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"center",gap:8,padding:"7px 10px",borderBottom:"1px solid var(--proto-line-2)",background:"var(--material-card-bg)",flex:"none"},children:[t>0&&o.jsx(rt,{label:c.mediaPrevPage,size:28,disabled:e<=1,onClick:()=>n(e-1),style:ql(e<=1),children:"↑"}),t>0&&o.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,font:`600 11.5px ${id}`,color:"var(--proto-ink)"},children:[o.jsx("input",{value:u,inputMode:"numeric","aria-label":c.mediaPageNumber,onChange:h=>d(h.target.value.replace(/[^0-9]/g,"")),onFocus:h=>h.currentTarget.select(),onKeyDown:h=>{h.key==="Enter"&&(p(),h.currentTarget.blur())},onBlur:p,style:{width:44,textAlign:"center",padding:"3px 4px",borderRadius:"var(--r-chip)",border:"1px solid var(--proto-line-2)",background:"var(--material-inset-bg)",color:"var(--proto-ink)",font:`600 11.5px ${id}`}}),o.jsxs("span",{style:{color:"var(--proto-muted)"},children:["/ ",t]})]}),t>0&&o.jsx(rt,{label:c.mediaNextPage,size:28,disabled:e>=t,onClick:()=>n(e+1),style:ql(e>=t),children:"↓"}),t>0&&o.jsxs("div",{style:{marginLeft:12,display:"flex",alignItems:"center",gap:4},children:[o.jsx(rt,{label:c.mViewZoomOut,size:28,disabled:r<=1,onClick:s,style:ql(r<=1),children:"−"}),o.jsxs(rt,{label:c.mediaZoomReset,size:28,onClick:a,style:{width:"auto",minWidth:36,padding:"0 4px",font:`600 11px ${id}`,userSelect:"none"},children:[Math.round(r*100),"%"]}),o.jsx(rt,{label:c.mViewZoomIn,size:28,disabled:r>=5,onClick:i,style:ql(r>=5),children:"+"})]}),l&&o.jsx("div",{style:{marginLeft:t>0?12:0,display:"flex",alignItems:"center",gap:4},children:l})]})}function ql(e=!1){return{border:"1px solid var(--proto-line-2)",borderRadius:"var(--r-control)",background:"var(--material-control-bg)",boxShadow:"var(--material-control-shadow)",fontSize:14,userSelect:"none",...e?{opacity:.4,color:"var(--proto-muted)"}:{}}}function od({children:e,failed:t}){return o.jsx("div",{style:{display:"flex",alignItems:"center",justifyContent:"center",padding:"48px 20px",color:t?"var(--proto-danger)":"var(--proto-muted)",font:`500 12px ${id}`},children:e})}function Bye({item:e,onClose:t,onPin:n}){const r=$c(),i=Z();return UW(t),o.jsx("div",{className:"content-surface",role:"dialog","aria-modal":"true","aria-label":e.name,onClick:t,style:{position:"fixed",inset:0,zIndex:4e3,background:"var(--media-backdrop-soft)",display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",padding:"max(24px, env(safe-area-inset-top)) 16px max(24px, env(safe-area-inset-bottom))",boxSizing:"border-box",animation:"cxfade .18s ease both"},children:o.jsxs("div",{onClick:s=>s.stopPropagation(),style:{width:Fye(e),height:"min(88vh, 100%)",background:"var(--material-overlay-bg)",backdropFilter:"var(--glass-filter)",WebkitBackdropFilter:"var(--glass-filter)",border:"1px solid var(--proto-line-2)",borderRadius:"var(--r-float)",display:"flex",flexDirection:"column",overflow:"hidden",boxShadow:"var(--material-overlay-shadow)"},children:[o.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10,padding:"10px 12px",borderBottom:"1px solid var(--proto-line-2)",flex:"none",background:"transparent"},children:[o.jsx("span",{style:{font:`600 11.5px ${id}`,color:"var(--proto-ink)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",flex:1},children:e.name}),n&&o.jsx(rt,{label:i.mediaPin,onClick:n,style:ql(),children:"◧"}),o.jsx(rt,{label:i.cmDownload,onClick:()=>r(e.path,e.name),style:ql(),children:"↓"}),o.jsx(rt,{label:i.cmClose,onClick:t,style:{...ql(),fontSize:16},children:"×"})]}),o.jsx("div",{style:{flex:1,minHeight:0,overflow:"auto",background:e.kind==="pdf"?"var(--proto-gray)":"var(--proto-card)"},children:e.kind==="pdf"?o.jsx(h$,{item:e}):e.kind==="html"?o.jsx(uy,{item:e,mode:"expanded"}):o.jsx(p$,{item:e})})]})})}function $ye({children:e}){const{item:t,open:n,close:r,pin:i}=VW(),s=f.useMemo(()=>({openDoc:n}),[n]);return o.jsxs(f$.Provider,{value:s,children:[e,t&&o.jsx(Bye,{item:t,onClose:r,onPin:i})]})}function Uc(){return f.useContext(f$)}const g$=["session.message","session.message.delivered","session.status","session.turn","session.context-usage","session.todos","session.context-compacted","session.interaction","session.decision","session.rewound","session.debug.updated","session.tool-images"],Hye=["session.message.delta"],v$=["system.notice"],Uye=["config.changed"],x$=["rate-limit.changed"],y$=["board.updated","session.board","board.style-updated"],Vye=[...g$,...v$,...Uye,...x$,...y$];function qye(e){if(e.type!=="config.changed"||!e.payload||typeof e.payload!="object")return!1;const t=e.payload.section;return t==="models"||t==="preferences"}function Kye(e){const t=e.payload;if(!t||typeof t!="object")return null;const n=t.sessionId;return typeof n=="string"&&n?n:null}function Gye(e,t,n){if(!t.includes(e.type))return!1;const r=n==null?void 0:n.sessionId;if(!r)return!0;const i=Kye(e);return i===null||i===r}function Yye(e,t){let n=0;for(const r of e)if(Gye(t,r.types,r.scope)){n++;try{r.fn(t)}catch{}}return n}function Qye(){return{hasConnected:!1,epoch:0,down:!1}}function SR(e,t){return t!=="pending"?e.hasConnected&&!e.down?{...e,down:!0}:e:e.hasConnected?e.down?{hasConnected:!0,epoch:e.epoch+1,down:!1}:e:{hasConnected:!0,epoch:e.epoch,down:!1}}const Xye=1e3,Zye=3e4;function b$(e){const t=Math.max(0,Math.floor(e));return Math.min(Zye,Xye*2**t)}const ij=f.createContext({register:()=>()=>{},connState:"connecting",hasConnected:!1,reconnectEpoch:0});function Jye({children:e}){const t=ci(),n=ve(),r=_e(),[i]=f.useState(()=>n.config.get.queryFilter({})),s=f.useRef(new Set),[a,l]=f.useState(()=>({state:"connecting",accum:Qye()})),[c,u]=f.useState(0),d=f.useRef(0),p=f.useRef(null),h=f.useRef(!1),m=f.useCallback(()=>{p.current!==null&&(clearTimeout(p.current),p.current=null)},[]);f.useEffect(()=>{let x=!1;const y=t.subscribe.subscribe({events:[...Vye]},{onConnectionStateChange:b=>{const S=b.state;S==="pending"&&(d.current=0,h.current=!1),l(j=>({state:S,accum:SR(j.accum,S)}))},onData:b=>{const S=b;!S||typeof S.type!="string"||(qye(S)&&r.invalidateQueries(i),Yye([...s.current],S))},onError:()=>{if(l(S=>({state:"idle",accum:SR(S.accum,"idle")})),h.current=!0,x||p.current!==null)return;const b=b$(d.current++);p.current=setTimeout(()=>{p.current=null,u(S=>S+1)},b)}});return()=>{x=!0,m(),y.unsubscribe()}},[t,i,r,c,m]),f.useEffect(()=>{if(typeof window>"u"||typeof document>"u")return;const x=()=>{h.current&&document.visibilityState!=="hidden"&&(m(),d.current=0,u(y=>y+1))};return window.addEventListener("online",x),document.addEventListener("visibilitychange",x),()=>{window.removeEventListener("online",x),document.removeEventListener("visibilitychange",x)}},[m]),f.useEffect(()=>{a.accum.hasConnected&&EW.markInteractive()},[a.accum.hasConnected]),f.useEffect(()=>{a.accum.epoch>0&&Q0e.record()},[a.accum.epoch]);const v=f.useCallback(x=>(s.current.add(x),()=>{s.current.delete(x)}),[]),g=f.useMemo(()=>({register:v,connState:a.state,hasConnected:a.accum.hasConnected,reconnectEpoch:a.accum.epoch}),[v,a]);return o.jsx(ij.Provider,{value:g,children:e})}function vl(e,t,n){const{register:r}=f.useContext(ij),i=f.useRef(t);i.current=t;const s=e.join(","),a=n==null?void 0:n.sessionId;f.useEffect(()=>r({types:s.split(","),scope:a?{sessionId:a}:void 0,fn:l=>i.current(l)}),[r,s,a])}function oj(){const{connState:e,hasConnected:t,reconnectEpoch:n}=f.useContext(ij);return{connState:e,hasConnected:t,reconnectEpoch:n}}function ebe(e,t){return e==="pending"?"connected":e==="connecting"?t?"reconnecting":"connecting":t?"disconnected":"connecting"}function w$(e){switch(e){case"connected":return{color:"var(--proto-success)"};case"connecting":case"reconnecting":return{color:"var(--proto-amber)"};case"disconnected":return{color:"var(--proto-danger)"}}}function sj(e){switch(e){case"connected":return"connConnected";case"connecting":return"connConnecting";case"reconnecting":return"connReconnecting";case"disconnected":return"connDisconnected"}}const S$=f.createContext("connecting");function tbe({children:e}){const{connState:t,hasConnected:n}=oj(),r=ebe(t,n);return o.jsx(S$.Provider,{value:r,children:e})}function O0(){return f.useContext(S$)}function nbe(e){return e.payload&&typeof e.payload=="object"?e.payload:{}}const rbe=["board.updated"];function ibe(){const e=ve(),t=_e();vl(y$,n=>{if(n.type==="board.style-updated"){t.invalidateQueries(e.boards.style.queryFilter());return}if(n.type==="session.board"){t.invalidateQueries(e.sessions.list.queryFilter());return}t.invalidateQueries(e.boards.list.queryFilter()),t.invalidateQueries(e.boards.get.queryFilter()),t.invalidateQueries(e.boards.decisions.queryFilter()),t.invalidateQueries(e.sessions.list.queryFilter()),t.invalidateQueries({...e.memory.file.queryFilter(),predicate:r=>{var s;const i=(s=r.queryKey[1])==null?void 0:s.input;return typeof(i==null?void 0:i.path)=="string"&&i.path.startsWith("boards/")}})})}function obe(){return ibe(),null}function sbe(e){vl(rbe,t=>{const n=nbe(t).boardId;typeof n=="string"&&e(n)})}function k$({children:e}){return o.jsxs(Jye,{children:[o.jsx(obe,{}),o.jsx(tbe,{children:o.jsx(hge,{children:o.jsx(dge,{children:o.jsx(rve,{children:o.jsx($ye,{children:e})})})})})]})}function Ti(e){return e.slice(0,8)}const kR=96;function j$(e){const t=(e??"").replace(/\s+/g," ").trim();return t.length<=kR?t:t.slice(0,kR-1).trimEnd()+"…"}function C$(e){const t=(e.sessionLabel??"").trim();return{id:e.id,level:"info",title:t||(e.L??so).notifNewMessage,meta:j$(e.text),ts:e.ts,sessionId:e.sessionId,projectId:e.projectId}}function abe(e){const t=(e.title??"").trim();return{id:e.id,level:e.level,title:t||(e.L??so).notifSystemNotice,meta:j$(e.text),ts:e.ts??new Date().toISOString(),sessionId:"",projectId:null}}function lbe(e){return e==="info"}const cbe=["session.message","session.status"];function ube({onMessage:e,onTurnEnd:t}){vl(cbe,n=>{if(n.type==="session.message"){const r=n.payload;if(!r||r.role!=="assistant")return;const i=(r.text??"").trim();if(!i||!r.sessionId)return;e({sessionId:r.sessionId,text:i,ts:r.ts??null});return}if(n.type==="session.status"){const r=n.payload;if(!r||!r.sessionId||r.running!==!1)return;t(r.sessionId)}})}function T$(e){vl(v$,t=>{if(t.type!=="system.notice")return;const n=t.payload,r=((n==null?void 0:n.text)??"").trim();r&&e({level:(n==null?void 0:n.level)??"info",text:r,title:(n==null?void 0:n.title)??null,ts:(n==null?void 0:n.ts)??null})})}function jR(e){const t=new Map;for(const n of e??[])t.set(n.sessionId,{label:n.label??Ti(n.sessionId),projectId:n.projectId,silent:!!n.teamLeadId,awaitingInput:!!n.awaitingInput});return t}function dbe(){const e=ve(),t=xe(e.sessions.list.queryOptions({origin:"direct"})),n=f.useMemo(()=>jR(t.data),[t.data]),r=f.useCallback(async()=>{const i=await t.refetch();return i.isError?null:jR(i.data)},[t.refetch]);return{map:n,refresh:r}}function fbe(){const e=f.useRef(!1);return f.useEffect(()=>(e.current=!0,()=>{e.current=!1}),[]),e}function pbe(e,t){const n=fbe(),r=f.useRef(e);return r.current=e,f.useCallback(i=>{(async()=>{try{if(t&&await t(i))return}catch{}n.current&&r.current(i)})()},[t,n])}function hbe(e,t,n,r,i,s){if(!e.has(i))return{consumed:!0,item:null};if(n(i))return e.delete(i),{consumed:!0,item:null};const a=t.get(i);if(!a)return{consumed:!1,item:null};const l=e.get(i);return e.delete(i),a.silent?{consumed:!0,item:null}:{consumed:!0,item:C$({id:r("dmn"),sessionId:i,sessionLabel:a.label,projectId:a.projectId,text:l.text,ts:l.ts,L:s})}}function mbe(e,t,n,r){const i=f.useRef(new Map),s=f.useRef(new Set),a=Z(),l=f.useCallback((d,p=e.map)=>{const h=hbe(i.current,p,t,n,d,a);return h.consumed?(s.current.delete(d),h.item&&r(h.item),!0):!1},[r,t,a,e.map,n]),c=f.useCallback(d=>{i.current.set(d.sessionId,{text:d.text,ts:d.ts??new Date().toISOString()})},[]),u=f.useCallback(d=>{!i.current.has(d)||l(d)||(s.current.add(d),e.refresh().then(p=>{!p||l(d,p)||(i.current.delete(d),s.current.delete(d))}).catch(()=>{}))},[l,e]);f.useEffect(()=>{s.current.forEach(d=>{l(d)})},[l]),ube({onMessage:c,onTurnEnd:u})}function gbe(e,t,n,r){const i=f.useRef(new Map),s=Z();f.useEffect(()=>{var l;const a=i.current;if(i.current=e,!Pn())for(const[c,u]of e)!u.awaitingInput||((l=a.get(c))==null?void 0:l.awaitingInput)!==!1||u.silent||t(c)||r({...C$({id:n("dmn"),sessionId:c,sessionLabel:u.label,projectId:u.projectId,text:s.notifAwaitingInput,ts:new Date().toISOString(),L:s}),level:"warning"})},[e,t,n,r,s])}function vbe(e,t){const n=Z(),r=f.useCallback(i=>{t(abe({id:e("sysn"),level:i.level,text:i.text,title:i.title??void 0,ts:i.ts??void 0,L:n}))},[t,n,e]);T$(r)}function aj({isSessionOpen:e,publish:t,externalDelivery:n}){const r=f.useRef(0),i=dbe(),s=pbe(t,n),a=f.useCallback(l=>`${l}-${r.current++}`,[]);mbe(i,e,a,s),gbe(i.map,e,a,s),vbe(a,s)}const E$="cortex.local.notifications.enabled",HS="cortex-local-notifications-change";let u1;function R$(){if(u1!==void 0)return u1;try{return localStorage.getItem(E$)!=="false"}catch{return!0}}function xbe(e){u1=e;try{localStorage.setItem(E$,String(e)),u1=void 0}catch{}window.dispatchEvent(new Event(HS))}function ybe(e){return window.addEventListener(HS,e),window.addEventListener("storage",e),()=>{window.removeEventListener(HS,e),window.removeEventListener("storage",e)}}function bbe(){return f.useSyncExternalStore(ybe,R$,()=>!0)}function lj(){return typeof document<"u"&&document.visibilityState==="visible"&&document.hasFocus()}const wbe=6e3;function Sbe(e){return`${e.sessionId}\0${e.meta}`}function cj(e,t){return{title:e.title,description:e.meta,level:e.level,ts:e.ts,duration:lbe(e.level)?wbe:1/0,dedupeKey:Sbe(e),onActivate:t}}function M$(){const e=ni();return()=>{const t=ni();return(t==null?void 0:t.serverUrl)===(e==null?void 0:e.serverUrl)&&(t==null?void 0:t.token)===(e==null?void 0:e.token)}}function Wh(){return bt()||!globalThis.isSecureContext||typeof Notification!="function"?"unsupported":Notification.permission}async function kbe(){if(Wh()==="unsupported")return"unsupported";try{return await Notification.requestPermission()}catch{return Wh()}}function jbe(e,t,n,r){return new Promise(i=>{const s=()=>{e.onclick=null,e.onclose=null,e.onshow=null,e.onerror=null,t.delete(e),i(!1)};t.set(e,s),e.onshow=()=>i(!0),e.onclose=s,e.onerror=()=>{s(),e.close()},e.onclick=()=>{r()&&(i(!0),window.focus(),Promise.resolve(n(r)).catch(()=>{}),e.close())}})}function Cbe(){const e=new Map;let t=!1;return{send:async(i,s)=>{if(t||Wh()!=="granted")return!1;const a=M$(),l=()=>!t&&a();try{return await jbe(new Notification(i.title,{body:i.body}),e,s,l)}catch{return!1}},dispose:()=>{t=!0,e.forEach((i,s)=>{i(),s.close()}),e.clear()}}}function A$(e){return{title:e.title,body:e.meta}}let uc=null,_l;const P$="cortex.mobile.notifications.permission-requested";let Xg=!1;function Tbe(){if(!Pn())return Xg;try{return Xg||localStorage.getItem(P$)==="true"}catch{return Xg}}function Ebe(){if(Xg=!0,!!Pn())try{localStorage.setItem(P$,"true")}catch{}}async function dy(){if(!bt())return!1;try{const{isPermissionGranted:e}=await Wc(async()=>{const{isPermissionGranted:t}=await import("./index-WCm6wwmM.js");return{isPermissionGranted:t}},[]);uc=await e()}catch{uc=!1}return uc}async function I$(){Ebe();try{const{requestPermission:e}=await Wc(async()=>{const{requestPermission:n}=await import("./index-WCm6wwmM.js");return{requestPermission:n}},[]),t=await e();return uc=t==="granted",t}catch{return uc=!1,"denied"}}async function Rbe(){return await dy()?!0:Tbe()||Pn()&&typeof document<"u"&&document.visibilityState!=="visible"?!1:await I$()==="granted"}async function L$(){return bt()?_l||(uc!==null?uc:(_l=Rbe().finally(()=>{_l=void 0}),_l)):!1}async function Mbe({userInitiated:e}){return bt()?_l&&await _l?"granted":I$():"denied"}async function N$(e,t){if(!bt())return!1;try{if(!await L$())return!1;if(Pn()){const r=await Ye("plugin:cortex-notifications|post",{...e,data:t});if(!Bc(r))return r.ok}const{sendNotification:n}=await Wc(async()=>{const{sendNotification:r}=await import("./index-WCm6wwmM.js");return{sendNotification:r}},[]);return n({...e,extra:t,autoCancel:!0}),!0}catch{return!1}}function Abe(e){if(!e||typeof e!="object")return;const t=Reflect.get(e,"notification"),n=t&&typeof t=="object"?Reflect.get(t,"extra")??Reflect.get(e,"extra"):Reflect.get(e,"extra");return n&&typeof n=="object"?n:void 0}async function Pbe(e,t){let n=(t==null?void 0:t.aborted)??!1,r=()=>{};const i=()=>{n=!0,t==null||t.removeEventListener("abort",i),r()};t==null||t.addEventListener("abort",i,{once:!0});try{const{onAction:s}=await Wc(async()=>{const{onAction:c}=await import("./index-WCm6wwmM.js");return{onAction:c}},[]);if(n)return i;const a=await s(c=>{n||Promise.resolve(e(Abe(c))).catch(()=>{})});let l=!1;r=()=>{l||(l=!0,a.unregister().catch(()=>{}))},n&&r()}catch{i()}return i}async function Ibe(e,t){if(!Pn()||t!=null&&t.aborted)return()=>{};try{return await Vx()?Jpe(r=>e({...r}),t):Pbe(e,t)}catch{return()=>{}}}async function Lbe(e,t,n){const r=await Ye("desktop_notifications_post",{...e,data:t,action:n});return r.ok?!0:r.reason==="failed"&&Bc(r)?N$(e,t):!1}async function Nbe(e,t,n){var r;if(n()){if(e.serverUrl!==((r=ni())==null?void 0:r.serverUrl)){await Ye("desktop_notifications_ack",{actionId:e.actionId});return}await t(e,n)&&n()&&await Ye("desktop_notifications_ack",{actionId:e.actionId})}}async function Dbe(e,t){if(!t())return;const n=await Ye("desktop_notifications_pending");if(!(!t()||Bc(n))){if(!n.ok)throw new Error("Unable to read pending desktop notification actions");for(const r of n.value.actions)await Nbe(r,e,t)}}const CR=[1e3,2e3,4e3];function Obe(e,t){let n=Promise.resolve(),r=0,i;const s=()=>{i!==void 0&&clearTimeout(i),i=void 0},a=()=>(n=n.then(async()=>{s(),await Dbe(e,t),r=0}).catch(()=>{!t()||r>=CR.length||(i=setTimeout(()=>{i=void 0,a()},CR[r++]))}),n);return{drain:a,resume:()=>{s(),r=0,a()},dispose:s}}async function Fbe(e,t){let n=(t==null?void 0:t.aborted)??!1,r=()=>{};const i=M$(),a=Obe(e,()=>!n&&i()),l=()=>{n=!0,a.dispose(),t==null||t.removeEventListener("abort",l),typeof window<"u"&&(window.removeEventListener("focus",a.resume),window.removeEventListener("online",a.resume)),r()};return n?l:(t==null||t.addEventListener("abort",l,{once:!0}),r=await wf("desktop-notification-action",a.resume),n?(r(),l):(typeof window<"u"&&(window.addEventListener("focus",a.resume),window.addEventListener("online",a.resume)),await a.drain(),l))}function _be(e){if(!e.trim()||e.length>512||/[\u0000-\u001f\u007f]/.test(e))return!1;try{return encodeURIComponent(e),!0}catch{return!1}}function zbe(e){const t=ci();return f.useCallback(async(n,r)=>{if(!r())return!1;if(!n.sessionId)return!0;const i=n.sessionId,s=_be(i)?await t.sessions.list.query({origin:"direct"}):[];return r()?(e(s.find(a=>a.sessionId===i)??null),!0):!1},[t,e])}function Wbe(e){const t=f.useRef(null);return f.useEffect(()=>{const n=new AbortController;let r=()=>{};return t.current=Cbe(),sr()&&Fbe(e,n.signal).then(i=>{n.signal.aborted?i():r=i}),()=>{var i;n.abort(),r(),(i=t.current)==null||i.dispose(),t.current=null}},[e]),t}function D$(e){const t=zbe(e),n=Wbe(t),r=Z().notificationOpenAction;return f.useCallback(async i=>{var l;if(!R$()||lj())return!1;const s=A$(i),a={sessionId:i.sessionId||void 0,projectId:i.projectId??void 0};return sr()?Lbe(s,a,r):((l=n.current)==null?void 0:l.send(s,async c=>{await t(a,c)}))??!1},[n,t,r])}const Bbe=/^\/m\/session\/([^/]+)$/;function uj(e){const t=Bbe.exec(e);if(!t)return null;try{return F0(decodeURIComponent(t[1]))??null}catch{return null}}function F0(e){if(!(typeof e!="string"||!e.trim()||e.length>512)&&!/[\u0000-\u001f\u007f]/.test(e))try{return encodeURIComponent(e),e}catch{return}}async function $be(e,t){const n=F0(e.sessionId);if(!n)return{path:"/m/sessions"};const r=`/m/session/${encodeURIComponent(n)}`,i=await t.sessions().catch(()=>null);if(!i)return{path:r};const s=i.find(a=>a.sessionId===n);return s?{path:r,projectId:s.projectId??void 0}:{path:"/m/sessions"}}async function Hbe(e,t){const n=F0(e.approvalId);if(!n)return{path:"/m/approvals"};const r=`/m/approvals?approvalId=${encodeURIComponent(n)}`,i=await t.approvals().catch(()=>null);if(!i)return{path:r};const s=i.find(a=>a.id===n);return s?{path:r,projectId:s.projectId??void 0}:{path:"/m/approvals"}}async function Ube(e,t){const n=e.kind??(e.sessionId?"session":"sessions");return n==="session"?$be(e,t):n==="approvals"?Hbe(e,t):{path:"/m/sessions"}}function Vbe({items:e,now:t=Date.now(),lang:n,onDismiss:r}){if(e.length===0)return null;const{visible:i}=U_(e);return o.jsx("div",{style:{position:"fixed",top:"calc(10px + env(safe-area-inset-top))",left:10,right:10,zIndex:1e3,display:"flex",flexDirection:"column",gap:8,pointerEvents:"none"},children:i.map(s=>o.jsx(qbe,{item:s,now:t,lang:n,onDismiss:r},s.id))})}function qbe({item:e,now:t,lang:n,onDismiss:r}){var l;const{onMouseEnter:i,onMouseLeave:s}=G_(e.id,e.duration,r),a=e.onActivate;return o.jsxs("div",{role:a?"button":"status",onTouchStart:i,onTouchEnd:s,onClick:a?()=>{a(),r(e.id)}:void 0,style:{pointerEvents:"auto",background:"var(--proto-card)",border:"1px solid var(--panel-translucent-border)",borderRadius:"var(--r-float)",boxShadow:"var(--material-overlay-shadow)",padding:"11px 13px",display:"flex",gap:10,alignItems:"center",cursor:a?"pointer":"default"},children:[o.jsx("div",{"aria-label":"Cortex",style:{width:36,height:36,borderRadius:"var(--r-chip)",background:"var(--brand-badge-bg)",border:"1px solid var(--brand-badge-border)",display:"flex",alignItems:"center",justifyContent:"center",flex:"none"},children:o.jsxs("svg",{width:25,height:25,viewBox:"0 0 64 64",fill:"none","aria-hidden":"true",children:[o.jsx("circle",{cx:33,cy:32,r:5,fill:"var(--brand-badge-core)"}),o.jsx("path",{d:"M42.29 23.64A12.5 12.5 0 1 0 42.29 40.36",stroke:"var(--brand-badge-arc)",strokeWidth:5,strokeLinecap:"round"}),o.jsx("path",{d:"M48.6 17.95A21 21 0 1 0 48.6 46.05",stroke:"var(--brand-badge-arc)",strokeWidth:5,strokeLinecap:"round"})]})}),o.jsxs("div",{style:{minWidth:0,flex:1},children:[o.jsx("div",{style:{fontSize:12.5,fontWeight:650,color:C.ink,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:e.title}),e.description?o.jsx("div",{style:{fontSize:11,color:C.sub,marginTop:1,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:e.description}):null,(l=e.actions)!=null&&l.length?o.jsx("div",{style:{display:"flex",gap:6,marginTop:6,flexWrap:"wrap"},children:e.actions.map((c,u)=>o.jsx("button",{type:"button","aria-label":c.altText??c.label,onClick:d=>{d.stopPropagation(),c.onClick(),r(e.id)},style:{border:"1px solid var(--panel-translucent-border)",borderRadius:"var(--r-chip)",background:"transparent",color:C.ink,fontSize:11,padding:"3px 8px"},children:c.label},u))}):null]}),o.jsx("span",{style:{fontSize:10,fontVariantNumeric:"tabular-nums",color:C.faint,flex:"none",alignSelf:"flex-start"},children:zr(e.ts,t,n)||zr(t,t,n)}),o.jsx("button",{type:"button","aria-label":cn(n).cmDismiss,onClick:c=>{c.stopPropagation(),r(e.id)},style:{border:"none",background:"transparent",color:C.faint,fontSize:12,cursor:"pointer",flex:"none",padding:"0 2px"},children:"✕"})]})}function O$(){const{dismiss:e}=Rt(),t=q_(),n=Qe();return o.jsx(Vbe,{items:t,lang:n,onDismiss:e})}function Kbe(){const e=qe(),{setCurrentProject:t}=Wt();return f.useCallback(n=>{n!=null&&n.projectId&&t(n.projectId),e(n?`/m/session/${encodeURIComponent(n.sessionId)}`:"/m/sessions")},[e,t])}function Gbe(){const{toast:e}=Rt(),t=Kbe(),n=f.useRef(_n().pathname);n.current=_n().pathname;const r=D$(t),i=f.useCallback(a=>lj()&&uj(n.current)===a,[]),s=f.useCallback(a=>{e(cj(a,a.sessionId?()=>t(a):void 0))},[t,e]);return aj({isSessionOpen:i,publish:s,externalDelivery:r}),o.jsx(O$,{})}let $d={status:null,supported:null,pending:!1,error:null};const US=new Set;let R2=Promise.resolve();const d1=()=>typeof document<"u"&&document.visibilityState==="visible",TR=()=>$d,Ybe=e=>(US.add(e),()=>{US.delete(e)});function dc(e){$d={...$d,...e},US.forEach(t=>t())}async function F$(e,t){const n=await Ye("mobile_notifications_configure",{enabled:e,locale:t,completionNotifications:!0});if(!n.ok)throw new Error("Native notification configuration failed");return n.value}function Qbe(){var e;return((e=$d.status)==null?void 0:e.completionNotifications)===!0&&$d.status.enabled}function VS(e){return R2=R2.then(e).catch(()=>{dc({error:"configure",pending:!1})}),R2}async function ER(e,t,n){if(!n()||!d1())return;const r=await Vx();if(!n())return;dc({status:r,supported:r!==null});const i=await(t?L$():dy());if(!r||!n()||!d1())return;if(r.enabled&&!i){dc({status:{...r,permissionGranted:!1}});return}const s=await F$(r.enabled,e);n()&&dc({status:s,error:null})}function Xbe(e){if(!Pn())return()=>{};let t=!0;const n=()=>{VS(()=>ER(e,!1,()=>t))};return VS(()=>ER(e,!0,()=>t)),document.addEventListener("visibilitychange",n),window.addEventListener("focus",n),()=>{t=!1,document.removeEventListener("visibilitychange",n),window.removeEventListener("focus",n)}}function Zbe(e){f.useEffect(()=>Xbe(e),[e])}function Jbe(){return f.useSyncExternalStore(Ybe,TR,TR)}function e2e(e,t){return!Pn()||$d.pending?Promise.resolve():(dc({pending:!0,error:null}),VS(async()=>{if(e&&(!d1()||!await dy()||!d1())){dc({pending:!1,error:"permission"});return}const n=await F$(e,t);dc({status:n,supported:!0,pending:!1,error:null})}))}function t2e(){const e=ci(),t=qe(),{setCurrentProject:n}=Wt();f.useEffect(()=>{const r=new AbortController;let i=()=>{};return Ibe(async s=>{if(!s||r.signal.aborted)return!1;const a=await Ube(s,{sessions:()=>e.sessions.list.query({origin:"direct"}),approvals:()=>e.approvals.list.query({status:"pending"})}),l=s.scope===void 0?null:await Vx();if(r.signal.aborted||s.scope!==void 0&&s.scope!==(l==null?void 0:l.scope))return!1;a.projectId&&n(a.projectId),t(a.path)},r.signal).then(s=>{r.signal.aborted?s():i=s}),()=>{r.abort(),i()}},[e,t,n])}function n2e(e){if(e.sessionId&&Qbe())return Promise.resolve(!0);const t=e.sessionId?{kind:"session",sessionId:e.sessionId,projectId:e.projectId??""}:{kind:"sessions"};return N$(A$(e),t)}function r2e(){const e=_n(),t=f.useRef(e.pathname);return t.current=e.pathname,f.useCallback(n=>document.visibilityState==="visible"&&uj(t.current)===n,[])}function i2e(){const e=uj(_n().pathname);f.useEffect(()=>{const t=()=>{J9(document.visibilityState==="visible"?e:null)};return t(),document.addEventListener("visibilitychange",t),()=>{document.removeEventListener("visibilitychange",t),J9(null)}},[e])}function o2e(){const e=qe(),{toast:t}=Rt(),{setCurrentProject:n}=Wt();Zbe(Qe()),t2e(),i2e();const r=f.useCallback((a,l)=>{if(!F0(a)){e("/m/sessions");return}l&&n(l),e(`/m/session/${encodeURIComponent(a)}`)},[e,n]),i=r2e(),s=f.useCallback(a=>{t(cj(a,()=>r(a.sessionId,a.projectId)))},[r,t]);return aj({isSessionOpen:i,publish:s,externalDelivery:n2e}),o.jsx(O$,{})}function s2e(){return Pn()?o.jsx(o2e,{}):o.jsx(Gbe,{})}const a2e="fixed inset-0 z-40 bg-state-ink/[0.44] [backdrop-filter:var(--material-scrim-filter)] [-webkit-backdrop-filter:var(--material-scrim-filter)] data-[state=open]:animate-fade-in data-[state=closed]:animate-fade-out motion-reduce:animate-none",l2e="fixed left-1/2 top-1/2 z-50 -translate-x-1/2 -translate-y-1/2 w-[420px] max-w-[calc(100vw-32px)] box-border rounded-[var(--r-float)] [background:var(--material-overlay-bg)] [backdrop-filter:var(--glass-filter)] [-webkit-backdrop-filter:var(--glass-filter)] p-5 pb-4 shadow-[shadow:var(--material-overlay-shadow)] focus:outline-none data-[state=open]:animate-zoom-in data-[state=closed]:animate-zoom-out motion-reduce:animate-none";function c2e(e){return o.jsxs("div",{className:"flex items-start gap-3",children:[o.jsx("div",{className:"flex h-9 w-9 flex-none items-center justify-center rounded-[var(--r-control)] bg-proto-accent-bg text-state-run",children:o.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 20 20",fill:"none",stroke:"currentColor",strokeWidth:"1.8",children:[o.jsx("path",{d:"M10 14V4M5.5 8.5 10 4l4.5 4.5"}),o.jsx("path",{d:"M3.5 16.5h13"})]})}),o.jsxs("div",{className:"min-w-0 flex-1",children:[o.jsx(mf,{className:"text-body font-semibold text-state-ink",children:e.title}),o.jsx("div",{className:"mt-1 break-words font-mono text-[11.5px] font-medium leading-relaxed text-proto-muted",children:e.summary})]})]})}function fy(e){return o.jsx(pf,{open:!0,onOpenChange:t=>{t||e.onDismiss()},children:o.jsxs(hf,{children:[o.jsx(wc,{className:a2e}),o.jsxs(Oc,{className:l2e,"aria-describedby":e.descriptionId,children:[o.jsx(c2e,{title:e.title,summary:e.summary}),o.jsx(bx,{id:e.descriptionId,className:"mb-4 mt-3 text-[12.5px] leading-[1.65] text-proto-muted",children:e.description}),e.children]})]})})}const M2="box-border flex h-9 items-center rounded-[var(--r-control)] border border-proto-line px-4 text-[12.5px] [background:var(--material-control-bg)] shadow-[shadow:var(--material-control-shadow)] font-semibold text-proto-muted transition-colors hover:bg-surface-canvas-alt disabled:opacity-60 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-proto-accent",u2e="box-border flex h-9 items-center rounded-[var(--r-control)] bg-state-ink px-4 text-[12.5px] font-semibold text-[var(--ink-solid-fg)] transition-opacity hover:opacity-90 disabled:opacity-60 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-proto-accent";function d2e(e){const t=e.available??"";return t?`Cortex ${t}`:"Cortex"}function f2e(e,t){switch(e){case"waiting":return t.updateWaiting;case"installing":return t.updateInstalling;case"restarting":return t.updateReconnecting;case"failed":return t.updateFailed;default:return t.updateNewAvailable}}function p2e(e,t){const n=e.available??t.updateNewVersion;switch(e.state){case"waiting":return t.updateWaitingHint;case"installing":return t.updateInstallingHint;case"restarting":return t.updateReconnectingHint;case"failed":return t.updateFailedHint;default:return t.updateConfirmVersion.replace("{version}",n)}}function h2e(e){const t=M();return e.status.state==="prompting"?o.jsxs("div",{className:"flex flex-wrap justify-end gap-2",children:[o.jsx("button",{type:"button",onClick:e.onSkip,disabled:e.busy,className:M2,children:t.updateSkipVersion}),o.jsx("button",{type:"button",onClick:e.onDismiss,className:M2,children:t.updateLater}),o.jsx("button",{type:"button",onClick:e.onApply,disabled:e.busy,className:u2e,children:e.busy?t.updateBusy:t.updateApply})]}):o.jsx("div",{className:"flex justify-end gap-2",children:o.jsx("button",{type:"button",onClick:e.onDismiss,className:M2,children:e.status.state==="failed"?t.updateClose:t.updateContinueBackground})})}function _$(e){const t=M();return o.jsxs(fy,{title:f2e(e.status.state,t),summary:d2e(e.status),descriptionId:"server-update-desc",description:p2e(e.status,t),onDismiss:e.onDismiss,children:[e.status.error?o.jsx("pre",{className:"mb-3 max-h-28 overflow-auto whitespace-pre-wrap break-all rounded-[var(--r-control)] bg-surface-canvas-alt p-2 font-mono text-[11.5px] leading-relaxed text-state-fail",children:e.status.error}):null,o.jsx(h2e,{...e})]})}function z$({onApply:e,onDismiss:t}){const n=M();return o.jsx(fy,{title:n.updateNewAvailable,summary:n.updateCheckUi,descriptionId:"browser-update-desc",description:n.updatePageHint,onDismiss:t,children:o.jsxs("div",{className:"flex flex-wrap justify-end gap-2",children:[o.jsx("button",{type:"button",className:"rounded-[var(--r-control)] border border-proto-line px-4 py-2 text-sm",onClick:t,children:n.updateLater}),o.jsx("button",{type:"button",className:"rounded-[var(--r-control)] bg-state-ink px-4 py-2 text-sm text-[var(--ink-solid-fg)]",onClick:e,children:n.updateRefreshPage})]})})}const m2e=1e4;function RR(e,t,n,r,i){return Array.from(e.querySelectorAll(t)).flatMap(s=>{try{const a=new URL(s.getAttribute(n)??"",r),l=new RegExp(`/assets/[^/]+-[A-Za-z0-9_-]{8,}\\.${i}$`);return a.origin!==r.origin||!l.test(a.pathname)?[]:[a.href]}catch{return[]}}).sort()}function W$(e,t){const n=new URL(t);if(!/^https?:$/.test(n.protocol)||e.title!=="Cortex"||!e.querySelector("#root")||e.querySelector('base, script[src*="/@vite/client"], script[src*="/src/"]'))return null;const r=RR(e,'script[type="module"][src]',"src",n,"js"),i=RR(e,'link[rel="stylesheet"][href]',"href",n,"css");return!r.length||!i.length?null:JSON.stringify([r,i])}async function g2e(e,t){var a;const n=await fetch(e,{cache:"no-store",credentials:"same-origin",redirect:"error",signal:t}),r=(a=n.headers.get("content-type"))==null?void 0:a.split(";")[0].trim();if(!n.ok||n.redirected||n.url!==e||r!=="text/html")throw new Error("invalid_page");const i=await n.text(),s=W$(new DOMParser().parseFromString(i,"text/html"),e);if(!s)throw new Error("invalid_entry");return s}async function v2e(){if(typeof document>"u")return{status:"skipped",reason:"unsupported_page"};const e=new URL(location.href);e.hash="";const t=W$(document,e.href);if(!t)return{status:"skipped",reason:"unsupported_page"};const n=new AbortController,r=setTimeout(()=>n.abort(),m2e);try{return await g2e(e.href,n.signal)===t?{status:"current"}:{status:"available",update:{kind:"browser-page"}}}catch{return{status:"error",reason:"check_failed"}}finally{clearTimeout(r)}}function x2e(){location.reload()}const qS=new Set;let KS=!1;function y2e(){KS=!0}function MR(){const e=KS;return KS=!1,e}function py(e){const t=e;return qS.add(t),()=>{qS.delete(t)}}function b2e(e){for(const t of qS)t(e)}const AR=["B","KB","MB","GB","TB"];function qi(e){return`$${e.toFixed(2)}`}function dj(e,t={}){const{fractionDigits:n=1,trimTrailingZeros:r=!1,maxUnit:i="TB"}=t,s=AR.indexOf(i),a=Math.abs(e);let l=0;for(;l<s&&a>=1024**(l+1);)l+=1;if(l===0)return`${e} B`;const c=(e/1024**l).toFixed(n);return`${r?String(Number(c)):c} ${AR[l]}`}const w2e="frontend-update-staged";function PR(e){return e.slice(0,8)}function S2e(e){const t=PR(e.version),n=e.fromVersion?PR(e.fromVersion):"";return n&&n!==t?`${n} → ${t}`:t}function B$(e){if(!e||e<=0)return null;const t=e>=1024*1024?1:0;return dj(e,{fractionDigits:t,maxUnit:"MB"})}function $$(e,t){const n=B$(e.size),r=[S2e(e)];return n&&r.push(n),r.push(t.updateDownloaded),r.join(" · ")}function fj(e){if(!e||typeof e!="object")return null;const t=e;return typeof t.version!="string"||!t.version?null:{version:t.version,fromVersion:typeof t.fromVersion=="string"&&t.fromVersion?t.fromVersion:void 0,size:typeof t.size=="number"?t.size:void 0}}async function k2e(e){return bt()?wf(w2e,t=>{const n=fj(t);n&&e(n)}):()=>{}}async function j2e(){if(!bt())return null;const e=await Ye("get_staged_update");return e.ok?fj(e.value):null}async function C2e(){bt()&&await Ye("apply_frontend_update")}const T2e="app-update-available";function GS(e){if(!e||typeof e!="object")return null;const t=e;if(typeof t.version!="string"||!t.version||typeof t.kind!="string"||!t.kind)return null;const n=t.apply==="silent"?"silent":"prompt",r={version:t.version,kind:t.kind,apply:n};return typeof t.releaseUrl=="string"&&t.releaseUrl&&(r.releaseUrl=t.releaseUrl),typeof t.notes=="string"&&t.notes&&(r.notes=t.notes),typeof t.size=="number"&&t.size>0&&(r.size=t.size),r}function E2e(e,t){return t.updateSilentNotice.replace("{version}",e.version)}function H$(e,t){const n=[`Cortex ${e.version}`],r=B$(e.size);return r&&n.push(r),n.push(t.updateDownloaded),n.join(" · ")}function U$(e,t){switch(e){case"appimage":return t.updateRestartInstall;case"nsis":return t.updateRunInstaller;case"apk":return t.updateInstall;case"dmg":case"deb":case"rpm":return t.updateOpenInstaller;default:return t.updateApply}}function V$(e,t){switch(e){case"appimage":return t.updateAppimageHint;case"nsis":return t.updateNsisHint;case"apk":return t.updateApkHint;case"dmg":return t.updateDmgHint;case"deb":case"rpm":return t.updatePackageHint;default:return t.updateInstallHint}}let q$=null;const YS=new Set;function Bh(e){q$=e;for(const t of YS)t()}function K$(e){return YS.add(e),()=>YS.delete(e)}function G$(){return q$}async function R2e(){if(!bt())return()=>{};const e=await wf(T2e,n=>{const r=GS(n);r&&Bh(r)}),t=await Ye("get_app_update");if(t.ok){const n=GS(t.value);n&&Bh(n)}return e}async function M2e(){if(!bt())return null;const e=await Ye("install_app_update");if(e.ok)return typeof e.value=="string"?e.value:null;if(e.reason==="failed"&&typeof e.error=="string"&&e.error)throw new Error(e.error);return null}async function A2e(){Bh(null),bt()&&await Ye("skip_app_update")}const f1=new Set;let oa=null;const QS=()=>oa!==null;function Y$(e){return f1.add(e),()=>{f1.delete(e)}}function A2(e){return{ui:{status:"error",reason:e},shell:{status:"error",reason:e}}}function P2e(e){if(!e||typeof e!="object")return null;const t=e;return!["available","current","skipped","error"].includes(t.status)||t.reason!==void 0&&typeof t.reason!="string"?null:t}function IR(e,t){const n=P2e(e);if(!n)return null;const r=n.update===void 0?void 0:t(n.update);return r===null||n.status==="available"&&!r||n.status==="current"&&r?null:{status:n.status,...r?{update:r}:{},...n.reason!==void 0?{reason:n.reason}:{}}}async function I2e(){var r,i;const e=await Ye("check_for_updates");if(Bc(e))return A2("unsupported_shell");if(!e.ok)return A2("check_failed");const t=IR((r=e.value)==null?void 0:r.ui,fj),n=IR((i=e.value)==null?void 0:i.shell,GS);return t&&n?{ui:t,shell:n}:A2("invalid_report")}async function Q$(){return bt()?I2e():{ui:await v2e()}}async function L2e(e){try{return await e()}catch{return{status:"error",reason:"check_failed"}}}function N2e(e){return Z$(async()=>({server:await L2e(e),...await Q$()}))}function X$(){return oa?oa.then(()=>X$()):Z$(Q$)}function Z$(e){if(oa)return oa;oa=e().then(t=>(b2e(t),t)).finally(()=>{oa=null;for(const t of f1)t()});for(const t of f1)t();return oa}const D2e={available:null,state:"idle"};function O2e(e){return e==="idle"?6e4:e==="waiting"?1e4:2e3}function F2e(e,t){return e.state==="idle"||e.auto&&e.state!=="failed"?!1:t!==(e.available??"")}function _2e(e){const t=ve(),n=_e();f.useEffect(()=>py(({server:r})=>{if(r){if(r.status==="available"&&r.update&&r.reason!=="auto_install"){e(null);const i=r.update.version;n.setQueryData(t.system.updateStatus.queryKey({}),s=>(s==null?void 0:s.state)==="waiting"||(s==null?void 0:s.state)==="installing"||(s==null?void 0:s.state)==="restarting"?s:{available:i,state:"prompting"})}n.invalidateQueries(t.system.updateStatus.queryFilter())}}),[t,n,e])}function z2e(){const e=ve(),t=xe({...e.system.updateStatus.queryOptions({}),refetchInterval:n=>{var r;return O2e(((r=n.state.data)==null?void 0:r.state)??"idle")},refetchIntervalInBackground:!0,retry:!0});return{status:t.data??D2e,hasStatus:t.data!==void 0}}function W2e(){const e=ve(),t=_e(),n=()=>t.invalidateQueries(e.system.updateStatus.queryFilter()),r=Se(e.system.applyUpdate.mutationOptions({onSuccess:u=>{u.accepted&&y2e(),t.setQueryData(e.system.updateStatus.queryKey({}),u.status)},onSettled:n})),i=Se(e.system.skipUpdate.mutationOptions({onSettled:n})),{mutate:s}=r,{mutate:a}=i,l=f.useCallback(()=>{s({})},[s]),c=f.useCallback(()=>{a({})},[a]);return{apply:l,skip:c,busy:r.isPending||i.isPending}}function B2e(){const{status:e,hasStatus:t}=z2e(),n=W2e(),[r,i]=f.useState(null);_2e(i);const s=f.useCallback(()=>{i(e.available??"")},[e.available]);return{status:e,hasStatus:t,visible:F2e(e,r),...n,dismiss:s}}const $2e=["button","checkbox","radio","submit","reset","file","range","color"];function H2e(e){return e?e.tagName==="TEXTAREA"?!0:e.tagName==="INPUT"?!$2e.includes(e.type):e.isContentEditable===!0:!1}function U2e(){return typeof document<"u"&&H2e(document.activeElement)}function pj(e){const[t,n]=f.useState(null);return f.useEffect(()=>{if(e===null){n(null);return}const r=()=>{U2e()||n(e)};if(r(),typeof document>"u")return;const i=()=>window.setTimeout(r,0);return document.addEventListener("focusout",i),()=>document.removeEventListener("focusout",i)},[e]),e===t?t:null}function V2e(){f.useEffect(()=>{let e=!1,t=()=>{};return R2e().then(n=>{e?n():t=n}),()=>{e=!0,t()}},[])}function q2e(e,t){const[n,r]=f.useState(!1),[i,s]=f.useState(null),a=f.useCallback(()=>{r(!0),s(null),M2e().then(l=>{r(!1),t(e),l!==null&&Bh(null)}).catch(l=>{r(!1),s(l.message)})},[t,e]);return{busy:n,error:i,install:a}}function K2e(){const e=f.useSyncExternalStore(K$,G$),[t,n]=f.useState(null),r=(e==null?void 0:e.version)===t?null:e,i=pj(r),s=q2e((e==null?void 0:e.version)??null,n);V2e(),f.useEffect(()=>py(({shell:c})=>{c!=null&&c.update&&(n(null),Bh(c.update))}),[]);const a=f.useCallback(()=>{A2e()},[]),l=f.useCallback(()=>{n((e==null?void 0:e.version)??null)},[e]);return{pending:e,update:i,...s,skip:a,dismiss:l}}function G2e(e){const[t,n]=f.useState(null);return f.useEffect(()=>{let r=!1,i=()=>{};const s=l=>{!r&&!e.current&&n(l)};k2e(s).then(l=>{r?l():i=l}),j2e().then(l=>{l&&s(l)});const a=py(({ui:l})=>{!bt()||!l.update||(e.current=!1,n(l.update))});return()=>{r=!0,i(),a()}},[e]),[t,n]}function Y2e(){const e=f.useRef(!1),[t,n]=G2e(e),r=pj(t),i=f.useCallback(()=>{C2e()},[]),s=f.useCallback(()=>{e.current=!0,n(null)},[n]);return{staged:r,apply:i,dismiss:s}}let J$=null;const XS=new Set,Q2e=()=>J$;function ZS(e){J$=e;for(const t of XS)t()}function X2e(e){return XS.add(e),()=>{XS.delete(e)}}const Z2e=()=>ZS(null);py(({ui:e})=>{var t;bt()||(e.status==="available"&&((t=e.update)==null?void 0:t.kind)==="browser-page"&&ZS(e.update),e.status==="current"&&ZS(null))});function J2e(){return{update:pj(f.useSyncExternalStore(X2e,Q2e)),dismiss:Z2e,apply:x2e}}function ewe(e,t=!0){const n=f.useRef(!1),r=O0();f.useEffect(()=>{if(["installing","restarting"].includes(e)||["reconnecting","disconnected"].includes(r)){n.current=!0;return}if(e==="failed"){n.current=!1,MR();return}t&&e==="idle"&&(MR()||n.current)&&(n.current=!1,X$())},[e,r,t])}function eH(){const e=B2e();ewe(e.status.state,e.hasStatus);const t=K2e(),n=Y2e(),r=J2e(),i=f.useSyncExternalStore(Y$,QS);return e.visible?{kind:"server",status:e.status,busy:e.busy,apply:e.apply,skip:e.skip,dismiss:e.dismiss}:i||["prompting","waiting","installing","restarting"].includes(e.status.state)?null:r.update?{kind:"page",apply:r.apply,dismiss:r.dismiss}:twe(t,n)}function twe(e,t){return e.update&&e.update.apply!=="silent"?{kind:"app",update:e.update,busy:e.busy,error:e.error,install:e.install,skip:e.skip,dismiss:e.dismiss}:(!e.pending||e.pending.apply==="silent")&&t.staged?{kind:"hot",update:t.staged,apply:t.apply,dismiss:t.dismiss}:null}const nwe={position:"fixed",inset:0,zIndex:60,background:"var(--overlay-scrim-strong)",display:"flex",alignItems:"center",justifyContent:"center",padding:"0 36px",boxSizing:"border-box"},rwe={width:"100%",background:"var(--material-overlay-bg)",borderRadius:"var(--r-float)",backdropFilter:"var(--glass-filter)",WebkitBackdropFilter:"var(--glass-filter)",boxShadow:"var(--material-overlay-shadow)",padding:"24px 20px 14px",boxSizing:"border-box",display:"flex",flexDirection:"column",alignItems:"center"},iwe={width:46,height:46,borderRadius:"var(--r-card)",background:"var(--proto-gray)",display:"flex",alignItems:"center",justifyContent:"center",marginBottom:14},owe={fontSize:17,fontWeight:650,color:"var(--proto-ink)"},swe={fontSize:12.5,color:"var(--proto-muted-3)",marginTop:6,fontVariantNumeric:"tabular-nums"},awe={fontSize:13,lineHeight:1.6,color:"var(--proto-muted)",textAlign:"center",margin:"10px 0 18px"};function lwe({title:e,summary:t}){return o.jsxs(o.Fragment,{children:[o.jsx("div",{style:iwe,children:o.jsxs("svg",{width:"20",height:"20",viewBox:"0 0 20 20",fill:"none",stroke:"var(--proto-ink-2)",strokeWidth:"1.8","aria-hidden":"true",children:[o.jsx("path",{d:"M10 14V4M5.5 8.5 10 4l4.5 4.5"}),o.jsx("path",{d:"M3.5 16.5h13"})]})}),o.jsx("div",{style:owe,children:e}),o.jsx("div",{style:swe,children:t})]})}function tH(e){return o.jsx("div",{role:"dialog","aria-modal":"true","aria-label":e.title,style:nwe,children:o.jsxs("div",{style:rwe,children:[o.jsx(lwe,{title:e.title,summary:e.summary}),o.jsx("div",{style:awe,children:e.description}),e.children]})})}const cwe={width:"100%",display:"flex",flexDirection:"column",gap:2},uwe={height:48,border:"none",borderRadius:"var(--r-control)",background:"var(--ink-solid-bg)",color:"var(--ink-solid-fg)",display:"flex",alignItems:"center",fontFamily:"var(--font-ui)",justifyContent:"center",fontSize:15,fontWeight:600,cursor:"pointer",width:"100%"},LR={height:44,border:"none",background:"transparent",display:"flex",alignItems:"center",justifyContent:"center",fontFamily:"var(--font-ui)",fontSize:14,fontWeight:600,color:"var(--proto-muted-2)",cursor:"pointer",flex:1};function dwe(e){const t=M();return o.jsxs("div",{style:cwe,children:[o.jsx("button",{type:"button",onClick:e.onInstall,disabled:e.busy,style:{...uwe,opacity:e.busy?.6:1},children:e.busy?t.updateBusy:U$(e.update.kind,t)}),o.jsxs("div",{style:{display:"flex",width:"100%"},children:[o.jsx("button",{type:"button",onClick:e.onSkip,style:LR,children:t.updateSkipVersion}),o.jsx("button",{type:"button",onClick:e.onDismiss,style:LR,children:t.updateLater})]})]})}function fwe(e){const t=M();return o.jsxs(tH,{title:t.updateReady,summary:H$(e.update,t),description:V$(e.update.kind,t),children:[e.error?o.jsx("div",{style:{fontSize:12,color:"var(--proto-danger)",marginBottom:10,textAlign:"center"},children:t.updateInstallFailed.replace("{error}",e.error)}):null,o.jsx(dwe,{...e})]})}const pwe={width:"100%",display:"flex",flexDirection:"column",gap:2},hwe={height:48,border:"none",borderRadius:"var(--r-control)",background:"var(--ink-solid-bg)",color:"var(--ink-solid-fg)",display:"flex",alignItems:"center",fontFamily:"var(--font-ui)",justifyContent:"center",fontSize:15,fontWeight:600,cursor:"pointer",width:"100%"},mwe={height:44,border:"none",background:"transparent",display:"flex",alignItems:"center",justifyContent:"center",fontFamily:"var(--font-ui)",fontSize:14,fontWeight:600,color:"var(--proto-muted-2)",cursor:"pointer",width:"100%"};function gwe(e){const t=M();return o.jsxs("div",{style:pwe,children:[o.jsx("button",{type:"button",onClick:e.onApply,style:hwe,children:t.updateExitApp}),o.jsx("button",{type:"button",onClick:e.onDismiss,style:mwe,children:t.updateIgnore})]})}function vwe(e){const t=M();return o.jsx(tH,{title:t.updateReady,summary:$$(e.update,t),description:t.updateHotHint,children:o.jsx(gwe,{onApply:e.onApply,onDismiss:e.onDismiss})})}function xwe(){const e=eH();return e?e.kind==="page"?o.jsx(z$,{onApply:e.apply,onDismiss:e.dismiss}):e.kind==="server"?o.jsx(_$,{status:e.status,busy:e.busy,onApply:e.apply,onSkip:e.skip,onDismiss:e.dismiss}):e.kind==="hot"?o.jsx(vwe,{update:e.update,onApply:e.apply,onDismiss:e.dismiss}):o.jsx(fwe,{update:e.update,busy:e.busy,error:e.error,onInstall:e.install,onSkip:e.skip,onDismiss:e.dismiss}):null}const NR="--cortex-vvh",DR="--cortex-vvt";function ywe(e,t){const n=()=>{e.setProperty(NR,`${t.height}px`),e.setProperty(DR,`${t.offsetTop}px`)};return n(),t.addEventListener("resize",n),t.addEventListener("scroll",n),()=>{t.removeEventListener("resize",n),t.removeEventListener("scroll",n),e.removeProperty(NR),e.removeProperty(DR)}}function bwe(){f.useEffect(()=>{const e=window.visualViewport;if(e)return ywe(document.documentElement.style,e)},[])}const wwe={position:"fixed",top:0,left:0,right:0,height:"var(--cortex-vvh, 100dvh)",transform:"translateY(var(--cortex-vvt, 0px))",display:"flex",flexDirection:"column",overflow:"hidden",background:"var(--app-backdrop)"};function Swe(){return o.jsx("div",{style:wwe,children:o.jsx(Lle,{children:o.jsx("div",{style:{flex:1,minHeight:0,overflow:"hidden"},children:o.jsx(Jme,{})})})})}function kwe({children:e}){return o.jsxs(k$,{children:[e,o.jsx(s2e,{}),o.jsx(xwe,{})]})}function jwe(){const e=_n(),t=qe();return bwe(),lge(e.pathname,t),o.jsx(kwe,{children:o.jsx(Swe,{})})}function ot(e){return JSON.stringify([e.backend,e.provider,e.model])}function Cc(e){return e.model.replace(/^claude-/,"").replace(/-\d{8}$/,"")}function Hd(e,t,n){const r=t==null?void 0:t.models.memory[ot(e)],i=n==null?void 0:n.routes.find(s=>s.backend===e.backend&&s.provider===e.provider);return{...e,thinking:(r==null?void 0:r.thinking)??null,mode:(r==null?void 0:r.mode)??(i==null?void 0:i.modes[0])??""}}function Cwe(e){return((e==null?void 0:e.routes)??[]).flatMap(t=>t.models.map(n=>({backend:t.backend,provider:t.provider,model:n})))}function nH(e,t){return e.toLowerCase().includes(t.trim().toLowerCase())}const rH=["interval","daily","weekly","once"],p1=["min","hr"],iH=[0,1,2,3,4,5,6],Twe={min:"schedUnitMin",hr:"schedUnitHr"};function h1(e,t){return t[Twe[e]]}function Ewe(e,t,n){var a;const r=((a=e==null?void 0:e.models)==null?void 0:a.favorites)??[],i=[...r,...((t==null?void 0:t.routes)??[]).flatMap(l=>l.models.map(c=>({backend:l.backend,provider:l.provider,model:c})))];return n&&i.push(n),[...new Map(i.map(l=>[ot(l),l]))].map(([l,c])=>({value:l,label:`${Cc(c)} · ${c.provider??c.backend}`,selection:n&&ot(n)===l?n:Hd(c,e,t),favorite:r.some(u=>ot(u)===l)}))}function Rwe(e,t){var i,s;if(!t)return[""];const n=e==null?void 0:e.routes.find(a=>a.backend===t.backend&&a.provider===t.provider),r=((i=n==null?void 0:n.modelThinking)==null?void 0:i[t.model])??((s=e==null?void 0:e.thinkingLevels)==null?void 0:s[t.backend])??[];return[...new Set(["",...r,t.thinking??""])]}function oH(e,t){const n=e.find(r=>r.value===t);return n!=null&&n.selection.mode?{selection:n.selection}:{}}function sH(e,t){return e.selection?{selection:{...e.selection,thinking:t||null}}:{}}function aH(e){return{type:"daily",message:"",selection:null,time:"09:00",dayOfWeek:1,intervalValue:30,intervalUnit:"min",delayValue:10,delayUnit:"min",projectId:e}}function Ef(e){return{time:e==="daily"||e==="weekly",interval:e==="interval",dayOfWeek:e==="weekly",delay:e==="once"}}function lH(e,t){const n=Ef(t),r=e==="edit";return{...n,delay:n.delay&&!r,type:!r,message:!0,selection:!0,projectId:!0}}const Mwe={intervalValue:"interval",intervalUnit:"interval",delayValue:"delay",delayUnit:"delay"};function Awe(e,t){const n=Mwe[t]??t;return e[n]??!1}function Pwe(e,t,n){const r=lH(t,e.type),i={};for(const s of Object.keys(n))Awe(r,s)&&Object.assign(i,{[s]:n[s]});return{...e,...i}}function $h(e,t){return t==="hr"?e*36e5:e*6e4}const Iwe=/^\d{2}:\d{2}$/;function Lwe(e){const t={type:e.type,message:e.message.trim()};return e.projectId&&(t.projectId=e.projectId),e.selection&&(t.selection=e.selection),e.type==="interval"&&(t.intervalMs=$h(e.intervalValue,e.intervalUnit)),(e.type==="daily"||e.type==="weekly")&&(t.time=e.time),e.type==="weekly"&&(t.dayOfWeek=e.dayOfWeek),e.type==="once"&&(t.delay=$h(e.delayValue,e.delayUnit)),t}function cH(e){const t=aH(e.projectId||null),n=e.intervalMs??0,r=n>0&&n%36e5===0;return{...t,type:e.type,message:e.message,selection:e.selection,time:e.time??t.time,dayOfWeek:e.dayOfWeek??t.dayOfWeek,intervalValue:n>0?r?n/36e5:Math.round(n/6e4):t.intervalValue,intervalUnit:r?"hr":"min"}}function Nwe(e,t){const n={scheduleId:e,message:t.message.trim()};return t.selection&&(n.selection=t.selection),t.projectId&&(n.projectId=t.projectId),t.type==="interval"&&(n.intervalMs=$h(t.intervalValue,t.intervalUnit)),(t.type==="daily"||t.type==="weekly")&&(n.time=t.time),t.type==="weekly"&&(n.dayOfWeek=t.dayOfWeek),n}function Dwe(e){return e.message.trim()?null:"message is required"}function Owe(e){return e.type==="interval"&&!(e.intervalValue>0)?"interval must be > 0":null}function Fwe(e){return(e.type==="daily"||e.type==="weekly")&&!Iwe.test(e.time)?"time must be HH:MM":null}function _we(e){const t=!(e.dayOfWeek>=0&&e.dayOfWeek<=6);return e.type==="weekly"&&t?"dayOfWeek must be 0..6":null}function zwe(e,t){return e.type==="once"&&t==="create"&&!(e.delayValue>0)?"delay must be > 0":null}function uH(e,t="create"){const r=[Dwe(e),Owe(e),Fwe(e),_we(e),zwe(e,t)].filter(i=>i!==null);return{ok:r.length===0,errors:r}}function Wwe(e,t){if(e.type==="interval")return new Date(t.getTime()+$h(e.intervalValue,e.intervalUnit));if(e.type==="once")return new Date(t.getTime()+$h(e.delayValue,e.delayUnit));const[n,r]=e.time.split(":").map(a=>parseInt(a,10)),i=new Date(t);if(i.setHours(n,r,0,0),e.type==="daily")return i.getTime()<=t.getTime()&&i.setDate(i.getDate()+1),i;let s=(e.dayOfWeek-t.getDay()+7)%7;return s===0&&i.getTime()<=t.getTime()&&(s=7),i.setDate(i.getDate()+s),i}function OR(e){return String(e).padStart(2,"0")}function hj(e,t){const n=Math.max(0,Math.round(e/6e4))*6e4;return n<864e5?zc(n,t):_c(n,t)}function FR(e){return new Date(e.getFullYear(),e.getMonth(),e.getDate()).getTime()}function Bwe(e,t,n){const r=cn(n),i=Math.round((FR(e)-FR(t))/864e5);return i<=0?r.timeToday:i===1?r.scTomorrow:G(r.timeMonthDay,{month:r.timeMonths.split(",")[e.getMonth()],day:e.getDate()})}function $we(e,t,n){const r=Wwe(e,t);return{day:Bwe(r,t,n),clock:`${OR(r.getHours())}:${OR(r.getMinutes())}`,delta:hj(r.getTime()-t.getTime(),n)}}const Hwe=["chatDaySun","chatDayMon","chatDayTue","chatDayWed","chatDayThu","chatDayFri","chatDaySat"],Uwe={daily:"chatCadenceDaily",weekly:"chatCadenceWeekly",interval:"chatCadenceInterval",once:"chatCadenceOnce"};function Hh(e,t){const n=cn(t),r=Uwe[e.type],i=r?n[r]:e.type;if(e.type==="daily")return e.time?`${i} ${e.time}`:i;if(e.type==="weekly"){const s=e.dayOfWeek!=null?Hwe[e.dayOfWeek]:void 0,a=s?n[s]:null;return!a||!e.time?i:G(n.chatCadenceWeeklyAt,{cadence:i,day:a,time:e.time})}if(e.type==="interval"&&e.intervalMs!=null&&e.intervalMs>0){const s=hj(e.intervalMs,t);return G(n.chatCadenceEvery,{span:s})}return i}function mj(e,t,n){if(!e)return null;const r=Date.parse(e);return Number.isNaN(r)?null:hj(r-t,n)}function Cs(e){const t=Date.parse(e.lastUsedAt||e.createdAt);return Number.isNaN(t)?0:t}function Uh(e){return[...e].sort((t,n)=>+!!n.unread-+!!t.unread||Cs(n)-Cs(t))}function _R(e){const t=new Date(e);return Math.floor(new Date(t.getFullYear(),t.getMonth(),t.getDate()).getTime()/864e5)}function zR(e){return e<10?"0"+e:""+e}function gj(e,t=Date.now()){const n=typeof t=="number"?t:t.getTime(),r=Cs(e),i=new Date(r),s=bf(i);return(_R(r)<_R(n)-1?(i.getFullYear()===new Date(n).getFullYear()?"":i.getFullYear()+"-")+zR(i.getMonth()+1)+"-"+zR(i.getDate())+" ":"")+s}function dH(e){const t=e.split(/[-_]/).filter(Boolean);return t.length>=2?(t[0][0]+t[1][0]).toUpperCase():t.length===1?t[0].slice(0,2).toUpperCase():"?"}function Vwe(e){const t=new Map;for(const n of e){if(n.origin!=="scheduled"||n.scheduleId==null)continue;const r=t.get(n.scheduleId)??[];r.push(n),t.set(n.scheduleId,r)}for(const n of t.values())n.sort((r,i)=>Cs(i)-Cs(r));return t}function WR(e){var r;if(e.latest)return Cs(e.latest);const t=(r=e.schedule)==null?void 0:r.lastRun,n=t?Date.parse(t):NaN;return Number.isNaN(n)?0:n}function JS(e,t){var i;const n=Vwe(t),r=[];for(const s of e){const a=n.get(s.id)??[];n.delete(s.id),r.push({scheduleId:s.id,schedule:s,title:s.message.trim()||(((i=a[0])==null?void 0:i.label)??(a[0]?Ti(a[0].sessionId):s.id)),kind:s.type==="once"?"once":"repeat",runs:a,latest:a[0]??null,unread:a.some(l=>l.unread)})}for(const[s,a]of n)r.push({scheduleId:s,schedule:null,title:a[0].label??Ti(a[0].sessionId),kind:a.length>1?"repeat":"once",runs:a,latest:a[0],unread:a.some(l=>l.unread)});return r.sort((s,a)=>WR(a)-WR(s))}function vj(e){const t=[...e].sort((r,i)=>Date.parse(r.createdAt)-Date.parse(i.createdAt)),n=new Map;return t.forEach((r,i)=>n.set(r.sessionId,i+1)),n}function fH(e){if(e.runs.length===0){if(!e.schedule)throw new Error(`Schedule row ${e.scheduleId} has neither a DTO nor a run`);return{type:"edit",schedule:e.schedule}}return e.kind==="once"?{type:"open",sessionId:e.runs[0].sessionId}:{type:"modal"}}function pH(e,t,n){var i;if((i=e.schedule)!=null&&i.paused)return{kind:"paused",cadence:Hh(e.schedule,n)};if(e.latest)return{kind:"run",stamp:gj(e.latest,t),cost:e.latest.costUsd!=null?qi(e.latest.costUsd):null};const r=e.schedule;return{kind:"pending",cadence:r?Hh(r,n):"",nextDelta:r?mj(r.nextRun,t,n):null}}function qwe(e,t,n,r){if(!e)return null;const i=vj(t).get(n);return i==null?null:G(r.chatRunTitle,{message:e.message,n:i})}function hH(e){return e.runs.filter(t=>t.unread).map(t=>t.sessionId)}function mH(e){return e.filter(t=>t.unread).length}const Kwe=["session.status","session.interaction","session.context-usage","session.context-compacted","session.todos"];function gH(){const e=ve(),t=_e();vl(Kwe,()=>{t.invalidateQueries(e.sessions.list.queryFilter())})}function Gwe(e){var r,i,s;const t=ve();return(s=(i=(r=xe(t.config.get.queryOptions({})).data)==null?void 0:r.settings)==null?void 0:i.find(a=>a.key===e))==null?void 0:s.value}function hy(){return Gwe("teamEnabled")===!0}function Ywe({projectId:e,count:t,expanded:n,onToggle:r,mobile:i,children:s}){const a=Z();return t===0?null:o.jsxs("section",{"data-starred-project":e,children:[o.jsxs("button",{type:"button","aria-label":a.chatStars,"aria-expanded":n,onClick:r,style:{display:"flex",alignItems:"center",gap:6,width:"100%",border:0,background:"transparent",color:"var(--proto-muted)",cursor:"pointer",minHeight:i?44:28,padding:i?"0 14px":"0 10px 0 28px",fontFamily:"inherit",fontSize:i?13:11.5},children:[o.jsx("span",{"aria-hidden":"true",children:n?"▾":"▸"}),o.jsx("span",{"aria-hidden":"true",children:"☆"}),o.jsx("span",{children:a.chatStars}),o.jsx("span",{style:{marginLeft:"auto"},children:t})]}),n&&s]})}function vH(e,t){return{starred:[...e,...t].filter(n=>n.starred===!0),direct:e.filter(n=>n.starred!==!0),scheduled:t.filter(n=>n.starred!==!0)}}const Qwe=3*60*60*1e3;function _0(e,t=Date.now()){if(!e.teamLeadId||e.running||e.awaitingInput||(e.waitingOnLead??0)>0||(e.waitingOn??0)>0)return!1;const n=Date.parse(e.lastUsedAt);return!Number.isNaN(n)&&t-n>Qwe}function xH(e,t=Date.now()){const n=Uh(e),r=i=>_0(i,t);return[...n.filter(i=>!r(i)),...n.filter(r)]}function xj(e,t=Date.now()){const n=new Set(e.map(l=>l.sessionId)),r=l=>l.teamLeadId&&l.teamLeadId!==l.sessionId&&n.has(l.teamLeadId)?l.teamLeadId:null,i=new Set(e.filter(l=>r(l)===null).map(l=>l.sessionId)),s=[],a=new Map;for(const l of e){const c=r(l);if(c===null||!i.has(c)){s.push(l);continue}const u=a.get(c);u?u.push(l):a.set(c,[l])}for(const[l,c]of a)a.set(l,xH(c,t));return{top:s,workers:a}}function Xwe(e,t,n=Date.now()){return xH(t.filter(r=>r.teamLeadId===e&&r.sessionId!==e),n)}const BR={lead:null,workers:[]};function Zwe(e,t,n){if(!e||!t)return BR;const r=t.teamLeadId&&t.teamLeadId!==t.sessionId?n.find(s=>s.sessionId===t.teamLeadId)??null:null,i=Xwe(t.sessionId,n);return r||i.length>0?{lead:r,workers:i}:BR}function Vh(e){return{running:!!e.running,awaitingInput:!!e.awaitingInput,waitingOn:(e.waitingOn??0)>0,unread:!!e.unread}}function yj(e){return{running:e.some(t=>t.running),awaitingInput:e.some(t=>t.awaitingInput),waitingOn:e.some(t=>t.waitingOn),unread:e.some(t=>t.unread)}}function ek(e,t,n,r){return G(t===1?e[n]:e[r],{n:t})}function Jwe(e,t=so){if(e.awaitingInput)return{kind:"awaiting",text:t.slAwaiting};if(e.running)return e.backgroundRunning?{kind:"background",text:t.slBackground}:{kind:"running",text:e.numTurns!=null?G(t.slRunningTurns,{n:e.numTurns}):t.slRunning};const n=e.waitingOn??0;return n>0?{kind:"waiting-external",text:ek(t,n,"slWaitingOne","slWaitingMany")}:{kind:"idle",text:t.slIdle}}function yH(e,t,n,r){return{id:e.sessionId,title:e.label||Ti(e.sessionId),time:zr(e.lastUsedAt||e.createdAt,t,n),unread:e.unread,status:Jwe(e,r)}}function e4e(e,t,n){const r=yj(t);return e.kind==="awaiting"?e:r.awaitingInput?{kind:"awaiting",text:n.slWorkerAwaiting}:e.kind==="running"||e.kind==="background"?e:r.running?{kind:"running",text:ek(n,t.filter(i=>i.running).length,"slWorkersRunningOne","slWorkersRunningMany")}:e.kind==="waiting-external"?e:r.waitingOn?{kind:"waiting-external",text:ek(n,t.filter(i=>i.waitingOn).length,"slWorkersWaitingOne","slWorkersWaitingMany")}:e}function t4e(e,t,n,r,i){const s=yH(e,n,r,i),a=t.filter(l=>!_0(l,n)).map(Vh);return a.length===0?s:{...s,unread:s.unread||yj(a).unread,status:e4e(s.status,a,i)}}const n4e={awaiting:"needsYou",running:"active",background:"active","waiting-external":"active",idle:"recent"};function r4e(e){const t={needsYou:[],active:[],recent:[]};for(const n of e)t[n4e[n.status.kind]].push(n);return["needsYou","active","recent"].filter(n=>t[n].length>0).map(n=>({key:n,rows:t[n]}))}function i4e(e,t,n,r,i=Date.now(),s="en",a=so,l=!1){if(e===null)return{rows:P2(t,i,s,a,l),starredRows:[],scheduleRows:JS(r,n)};const c=p=>p.projectId===e,u=vH(t.filter(c),n.filter(c)),d=[...u.starred,...u.direct];return{rows:P2(u.direct,i,s,a,l,d),starredRows:P2(u.starred,i,s,a,l,d),scheduleRows:JS(r.filter(p=>p.projectId===e),u.scheduled)}}function P2(e,t=Date.now(),n="en",r=so,i=!1,s=e){if(!i)return Uh(e).map(u=>yH(u,t,n,r));const{top:a,workers:l}=xj(s,t),c=new Set(a.map(u=>u.sessionId));return Uh(e.filter(u=>c.has(u.sessionId))).map(u=>t4e(u,l.get(u.sessionId)??[],t,n,r))}const o4e={connected:"var(--proto-success)",connecting:"var(--proto-amber)",reconnecting:"var(--proto-amber)",disconnected:C.muted};function bH({presence:e}){return o.jsxs("div",{"aria-hidden":"true",style:{position:"relative",width:26,height:26,flex:"none",display:"grid",placeItems:"center"},children:[o.jsxs("svg",{width:26,height:26,viewBox:"0 0 64 64",fill:"none","aria-hidden":"true",children:[o.jsx("circle",{cx:"33",cy:"32",r:"6",fill:"var(--proto-ink)"}),o.jsx("path",{d:"M42.29 23.64A12.5 12.5 0 1 0 42.29 40.36",stroke:"var(--proto-accent)",strokeWidth:6,strokeLinecap:"round"}),o.jsx("path",{d:"M48.6 17.95A21 21 0 1 0 48.6 46.05",stroke:"var(--proto-accent)",strokeWidth:6,strokeLinecap:"round"})]}),o.jsx("span",{style:{position:"absolute",right:-1,bottom:0,width:8,height:8,borderRadius:"50%",background:o4e[e],boxShadow:"0 0 0 2px var(--m-canvas)"}})]})}function s4e({presence:e,projects:t}){const n=Z(),r=t.needsYou,i=r>0?G(n.slProjectsNeedYou,{n:r}):n.projTitle;return o.jsxs("button",{type:"button","aria-label":i,"data-projects-button":"",onClick:t.onOpen,style:a4e,children:[o.jsx(bH,{presence:e}),r>0&&o.jsx("span",{"aria-hidden":"true","data-needs-you-count":"",style:l4e,children:r})]})}const a4e={position:"relative",minWidth:44,height:44,margin:"0 -4px 0 -9px",padding:"0 9px",flex:"none",border:0,background:"transparent",display:"flex",alignItems:"center",gap:4,cursor:"pointer",boxSizing:"border-box"},l4e={fontSize:13,fontWeight:650,color:"var(--proto-amber-fg)",...$e};function c4e({unread:e,onClick:t}){const n=Z();return o.jsxs("div",{style:{position:"relative",flex:"none"},children:[o.jsx("button",{type:"button","aria-label":n.schedSheetTitle,onClick:t,style:u4e,children:o.jsxs("svg",{width:19,height:19,viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:1.5,strokeLinecap:"round","aria-hidden":"true",children:[o.jsx("circle",{cx:"8",cy:"8",r:"5.5"}),o.jsx("path",{d:"M8 5v3l2 1.5"})]})}),e>0&&o.jsx("span",{"aria-label":G(n.slUnreadScheduled,{n:e}),style:d4e,children:e})]})}const u4e={width:44,height:44,borderRadius:"var(--r-control)",background:"transparent",border:0,color:"var(--proto-muted)",display:"grid",placeItems:"center",cursor:"pointer",padding:0},d4e={position:"absolute",top:5,right:4,color:"var(--proto-accent)",fontSize:11,fontWeight:650,...$e},f4e={running:{background:"var(--proto-accent)",boxShadow:"0 0 0 3px var(--proto-accent-bg)"},background:{background:"var(--proto-accent)",boxShadow:"0 0 0 3px var(--proto-accent-bg)"},awaiting:{background:"var(--proto-amber)"},"waiting-external":{border:`1.5px solid ${C.muted}`}},wH={whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"};function p4e({status:e}){return o.jsx("span",{"aria-hidden":"true",style:{width:12,flex:"none",display:"flex",justifyContent:"center",paddingTop:8},children:e.kind!=="idle"&&o.jsx("span",{"data-status-dot":e.kind,style:{width:7,height:7,borderRadius:"50%",boxSizing:"border-box",flex:"none",...f4e[e.kind]}})})}function h4e({status:e}){if(e.kind==="idle")return null;const t=e.kind==="awaiting"?"var(--proto-amber-fg)":C.muted;return o.jsx("div",{style:{marginTop:2,fontSize:14,color:t,...$e,...wH},children:e.text})}function m4e({row:e}){const t=Z();return o.jsxs("div",{style:{flex:"none",display:"flex",alignItems:"center",gap:6,paddingTop:3},children:[o.jsx("span",{style:{fontSize:13,color:C.faint,...$e},children:e.time}),e.unread&&o.jsx("span",{"aria-label":t.slUnread,style:{width:7,height:7,borderRadius:"50%",background:"var(--proto-accent)",flex:"none"}})]})}function $R({row:e,onOpen:t}){const n=e.unread||e.status.kind==="awaiting";return o.jsxs("div",{className:"m-press","data-session-id":e.id,onClick:()=>t(e.id),style:{display:"flex",alignItems:"flex-start",gap:12,minHeight:48,padding:"11px 14px",boxSizing:"border-box",borderRadius:"var(--r-control)",cursor:"pointer"},children:[o.jsx(p4e,{status:e.status}),o.jsxs("div",{style:{flex:1,minWidth:0},children:[o.jsx("div",{style:{fontSize:16,lineHeight:"22px",fontWeight:n?650:550,color:C.ink,...wH},children:e.title}),o.jsx(h4e,{status:e.status})]}),o.jsx(m4e,{row:e})]})}const g4e={position:"absolute",right:jx+10,bottom:Kle,height:50,padding:"0 20px 0 16px",border:0,borderRadius:"var(--r-pill)",background:C.inkSolid,color:C.inkSolidFg,display:"flex",alignItems:"center",gap:8,fontFamily:"var(--font-ui)",fontSize:15,fontWeight:600,cursor:"pointer",boxShadow:"var(--shadow-key-lift)"};function v4e({title:e,presence:t,project:n,projects:r,scheduled:i}){const s=n&&{label:n.switchLabel,onOpen:n.onSwitch};return o.jsx(NW,{title:(n==null?void 0:n.name)??e,titleMenu:s,leading:r?o.jsx(s4e,{presence:t,projects:r}):o.jsx(bH,{presence:t}),trailing:i&&o.jsx(c4e,{unread:i.unread,onClick:i.onOpen})})}const x4e={needsYou:"mSectionNeedsYou",active:"mSectionActive",recent:"mSectionRecent"};function y4e({rows:e,stars:t,empty:n,onOpen:r}){const i=Z();return o.jsxs(kf,{gap:0,padding:SF,children:[t&&o.jsx(Ywe,{projectId:t.projectId,count:t.rows.length,expanded:t.expanded,onToggle:t.onToggle,mobile:!0,children:t.rows.map(s=>o.jsx($R,{row:s,onOpen:r},s.id))}),e.length===0&&!(t!=null&&t.rows.length)&&o.jsx(Hme,{children:n}),r4e(e).map(s=>o.jsxs("section",{"data-session-section":s.key,children:[o.jsx(Yx,{style:{fontSize:13,padding:"14px 14px 2px"},children:i[x4e[s.key]]}),s.rows.map(a=>o.jsx($R,{row:a,onOpen:r},a.id))]},s.key)),o.jsx("div",{style:{height:72,flex:"none"}})]})}function b4e({rows:e,stars:t,presence:n,project:r,projects:i,newLabel:s,scheduled:a,onOpen:l,onNew:c}){const u=Z(),d=o.jsxs("button",{type:"button","aria-label":s,title:s,onClick:c,style:g4e,children:[o.jsx(Ba,{size:16,strokeWidth:2}),o.jsx("span",{"aria-hidden":"true",children:s})]});return o.jsx(hl,{label:"1a sessions",floatingHeader:!0,overlay:d,header:o.jsx(v4e,{title:u.sessions,presence:n,project:r,projects:i,scheduled:a}),children:o.jsx(y4e,{rows:e,stars:t,empty:u.slEmpty,onOpen:l})})}const w4e=800;function S4e(e,t){const n=ve(),r=_e(),i=Se(n.sessions.markRead.mutationOptions({onSuccess:()=>{r.invalidateQueries(n.sessions.list.queryFilter())}})),s=f.useRef(i.mutate);s.current=i.mutate;const a=f.useRef(null);f.useEffect(()=>{if(!e)return;const l=()=>{document.visibilityState==="visible"&&(a.current&&clearTimeout(a.current),a.current=setTimeout(()=>{s.current({sessionId:e})},w4e))};l();const c=()=>{document.visibilityState==="visible"&&l()};return document.addEventListener("visibilitychange",c),()=>{document.removeEventListener("visibilitychange",c),a.current&&clearTimeout(a.current)}},[e,t])}function SH(){const e=ve(),t=_e(),n=Se(e.sessions.markManyRead.mutationOptions({onSuccess:()=>{t.invalidateQueries(e.sessions.list.queryFilter())}}));return{markManyRead:r=>{r.length!==0&&n.mutate({sessionIds:r})},pending:n.isPending}}function k4e(e){return e instanceof Error?e:new Error(String(e))}async function j4e(e,t){if(e.mode==="edit"){if(!e.schedule)return!1;await t.update(e.schedule.id,e.form)}else await t.add(e.form);return!0}async function C4e(e,t){try{return!await j4e(e,t)||(await t.invalidate(),!t.isCurrent(e.generation))?!1:(t.success(e.mode),t.close(e.generation),!0)}catch(n){return t.isCurrent(e.generation)&&t.failure(e.mode,k4e(n)),!1}}function T4e(e){return e?e.mode==="edit"?{mode:"edit",form:cH(e.schedule),schedule:e.schedule,generation:0}:{mode:"create",form:aH(e.projectId),schedule:null,generation:0}:null}function E4e(e){const[t,n]=f.useState(()=>T4e(e)),[r,i]=f.useState(null),s=f.useRef(0),a=f.useRef(!0);f.useEffect(()=>(a.current=!0,()=>{a.current=!1}),[]);const l=f.useCallback(()=>++s.current,[]),c=f.useCallback(m=>a.current&&s.current===m,[]),u=f.useCallback(()=>{l(),n(null),i(null)},[l]),d=f.useCallback(m=>{s.current===m&&u()},[u]),p=f.useCallback(m=>{i(null),n({mode:"edit",form:cH(m),schedule:m,generation:l()})},[l]),h=f.useCallback(m=>{n(v=>v&&{...v,form:Pwe(v.form,v.mode,m)})},[]);return{state:t,error:r,setError:i,close:u,closeGeneration:d,isCurrent:c,openEdit:p,onChange:h}}function R4e(e){var l,c;const t=ve(),n=_e(),r=xe(t.config.get.queryOptions({})),i=xe(t.models.catalog.queryOptions({},{enabled:e!==null,refetchInterval:u=>{var d;return(d=u.state.data)!=null&&d.piPending?2500:!1}})),s=Se(t.schedules.add.mutationOptions({})),a=Se(t.schedules.update.mutationOptions({}));return{add:s,update:a,pending:s.isPending||a.isPending,defaultSelection:(c=(l=r.data)==null?void 0:l.models)==null?void 0:c.default,models:Ewe(r.data,i.data,(e==null?void 0:e.selection)??null),thinking:Rwe(i.data,(e==null?void 0:e.selection)??null),invalidate:()=>n.invalidateQueries(t.schedules.list.queryFilter())}}function M4e(e,t,n,r){return f.useCallback(async()=>!e||t.pending||!uH(e.form,e.mode).ok?!1:(n.setError(null),C4e(e,{add:i=>t.add.mutateAsync(Lwe(i)),update:(i,s)=>t.update.mutateAsync(Nwe(i,s)),invalidate:t.invalidate,isCurrent:n.isCurrent,success:i=>{var s,a;return i==="edit"?(s=r.onUpdated)==null?void 0:s.call(r):(a=r.onCreated)==null?void 0:a.call(r)},failure:(i,s)=>{var a;n.setError(s.message),(a=r.onError)==null||a.call(r,i,s)},close:n.closeGeneration})),[n.closeGeneration,n.isCurrent,n.setError,r,t,e])}function A4e(e){return(e==null?void 0:e.form)??null}function P4e(e){return(e==null?void 0:e.mode)??null}function I4e(e){return e??"create"}function L4e(e){return(e==null?void 0:e.type)??"daily"}function N4e(e,t){return e?uH(e,t).ok:!1}function D4e(e){const t=A4e(e),n=P4e(e),r=I4e(n);return{form:t,mode:n,editableFields:lH(r,L4e(t)),valid:N4e(t,r)}}function kH(e={},t){var a;const n=E4e(t),r=D4e(n.state),i=R4e(r.form);f.useEffect(()=>{var l;r.mode==="create"&&((l=r.form)==null?void 0:l.selection)===null&&i.defaultSelection&&n.onChange({selection:i.defaultSelection})},[r.mode,(a=r.form)==null?void 0:a.selection,i.defaultSelection,n.onChange]);const s=M4e(n.state,i,n,e);return{...r,modelOptions:i.models,thinkingOptions:i.thinking,pending:i.pending,error:n.error,openEdit:n.openEdit,close:n.close,onChange:n.onChange,submit:s}}function jH(){const e=M(),{toast:t}=Rt();return{onCreated:()=>t({title:e.scToastCreated,tone:"done"}),onUpdated:()=>t({title:e.scToastUpdated,tone:"done"}),onError:(n,r)=>t({title:n==="edit"?e.scToastUpdateFailed:e.scToastCreateFailed,description:r.message,tone:"failed"})}}const xl={display:"block",marginBottom:5,color:C.muted,fontSize:13,fontWeight:600},Ts={width:"100%",minWidth:0,minHeight:44,boxSizing:"border-box",border:`1px solid ${C.hairline}`,borderRadius:"var(--r-control)",padding:"8px 10px",background:"var(--material-inset-bg)",color:C.ink,fontSize:16,fontFamily:"inherit"},CH={display:"grid",gridTemplateColumns:"repeat(2, minmax(0, 1fr))",gap:8};function O4e({copy:e,mode:t,onBack:n}){return o.jsxs("div",{style:{display:"flex",alignItems:"center",gap:9,padding:"0 2px 12px"},children:[o.jsx("button",{type:"button","data-action":"sheet-back",onClick:n,"aria-label":e.back,style:{border:0,background:"transparent",color:C.ink,padding:0,margin:"0 -8px 0 -10px",cursor:"pointer",minWidth:44,minHeight:44,display:"grid",placeItems:"center"},children:o.jsx(Ds,{})}),o.jsx("span",{style:{fontSize:17,fontWeight:650,color:C.ink},children:t==="edit"?e.scEditSchedule:e.scNewSchedule})]})}function F4e({copy:e,form:t,editableFields:n,onChange:r}){const i={interval:e.scTypeInterval,daily:e.scTypeDaily,weekly:e.scTypeWeekly,once:e.scTypeOnce};return o.jsxs("div",{children:[o.jsx("span",{style:xl,children:e.scType}),o.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(4, 1fr)",border:`1px solid ${C.hairline}`,borderRadius:"var(--r-chip)",overflow:"hidden"},children:rH.map(s=>o.jsx(_4e,{type:s,form:t,disabled:!n.type,label:i[s],onChange:r},s))})]})}function _4e({type:e,form:t,disabled:n,label:r,onChange:i}){const s=t.type===e;return o.jsx("button",{type:"button",disabled:n,"aria-pressed":s,onClick:()=>i({type:e}),style:{border:0,borderRight:e==="once"?0:`1px solid ${C.hairline}`,padding:"8px 2px",minHeight:44,background:s?"var(--proto-gray)":"var(--material-control-bg)",boxShadow:"var(--material-control-shadow)",fontFamily:"var(--font-ui)",color:s?C.ink:C.muted,fontSize:13,fontWeight:s?600:400},children:r})}function z4e({copy:e,form:t,editableFields:n,onChange:r}){return Ef(t.type).time?o.jsxs("label",{children:[o.jsx("span",{style:xl,children:e.scTime}),o.jsx("input",{style:Ts,value:t.time,disabled:!n.time,onChange:i=>r({time:i.target.value})})]}):null}function W4e({copy:e,form:t,editableFields:n,onChange:r}){return Ef(t.type).interval?o.jsxs("div",{children:[o.jsx("span",{style:xl,children:e.scEvery}),o.jsxs("div",{style:CH,children:[o.jsx("input",{style:Ts,type:"number",min:1,value:t.intervalValue,disabled:!n.interval,onChange:i=>r({intervalValue:Number(i.target.value)})}),o.jsx(cl,{style:Ts,title:e.scEvery,value:t.intervalUnit,disabled:!n.interval,onValueChange:i=>r({intervalUnit:i}),options:p1.map(i=>({value:i,label:h1(i,e)}))})]})]}):null}function B4e({copy:e,form:t,editableFields:n,onChange:r}){return!Ef(t.type).delay||!n.delay?null:o.jsxs("div",{"data-schedule-delay":!0,children:[o.jsx("span",{style:xl,children:e.scIn}),o.jsxs("div",{style:CH,children:[o.jsx("input",{style:Ts,type:"number",min:1,value:t.delayValue,onChange:i=>r({delayValue:Number(i.target.value)})}),o.jsx(cl,{style:Ts,title:e.scIn,value:t.delayUnit,onValueChange:i=>r({delayUnit:i}),options:p1.map(i=>({value:i,label:h1(i,e)}))})]})]})}function $4e({copy:e,form:t,mode:n}){return n!=="edit"||t.type!=="once"?null:o.jsx("div",{"data-once-timing-note":!0,style:{border:`1px solid ${C.hairline}`,borderRadius:"var(--r-chip)",padding:10,color:C.muted,fontSize:11.5,lineHeight:1.5},children:e.scOnceTimingUnavailable})}function H4e({copy:e,form:t,editableFields:n,onChange:r}){if(!Ef(t.type).dayOfWeek)return null;const i=[e.scDaySun,e.scDayMon,e.scDayTue,e.scDayWed,e.scDayThu,e.scDayFri,e.scDaySat];return o.jsxs("label",{children:[o.jsx("span",{style:xl,children:e.scDay}),o.jsx(cl,{style:Ts,title:e.scDay,value:String(t.dayOfWeek),disabled:!n.dayOfWeek,onValueChange:s=>r({dayOfWeek:Number(s)}),options:iH.map(s=>({value:String(s),label:i[s]}))})]})}function U4e({copy:e,form:t,editableFields:n,modelOptions:r,onChange:i}){return o.jsxs("label",{children:[o.jsx("span",{style:xl,children:e.scModel}),o.jsx(cl,{style:Ts,title:e.scModel,"data-schedule-select":"model","aria-label":e.scModel,value:t.selection?ot(t.selection):"",disabled:!n.selection,onValueChange:s=>i(oH(r,s)),options:[{value:"",label:e.scChooseModel,disabled:!0},...r.map(s=>({value:s.value,label:`${s.favorite?"★ ":""}${s.label}`,disabled:!s.selection.mode}))]})]})}function V4e({copy:e,form:t,editableFields:n,thinkingOptions:r,onChange:i}){var s;return o.jsxs("label",{children:[o.jsx("span",{style:xl,children:e.scThinking}),o.jsx(cl,{style:Ts,title:e.scThinking,"data-schedule-select":"thinking","aria-label":e.scThinking,value:((s=t.selection)==null?void 0:s.thinking)??"",disabled:!n.selection||!t.selection,onValueChange:a=>i(sH(t,a)),options:r.map(a=>({value:a,label:a||e.scThinkingDefault}))})]})}function q4e({copy:e,form:t,editableFields:n,onChange:r}){return o.jsxs("label",{children:[o.jsx("span",{style:xl,children:e.scMessage}),o.jsx("textarea",{style:{...Ts,minHeight:82,resize:"vertical"},value:t.message,disabled:!n.message,onChange:i=>r({message:i.target.value})})]})}function K4e({copy:e,mode:t,valid:n,pending:r,error:i,onSubmit:s}){return o.jsxs(o.Fragment,{children:[i&&o.jsx("div",{role:"alert",style:{color:C.fail,fontSize:12.5},children:i}),o.jsx("button",{type:"button","data-action":"save-schedule",disabled:!n||r,onClick:s,style:{border:0,borderRadius:"var(--r-control)",height:44,background:C.inkSolid,color:C.inkSolidFg,fontFamily:"var(--font-ui)",fontSize:15,fontWeight:600,opacity:n&&!r?1:.45,cursor:n&&!r?"pointer":"default"},children:t==="edit"?e.scSaveSchedule:e.scCreateSchedule})]})}function G4e(e){return o.jsxs("div",{style:{display:"grid",gap:12},children:[o.jsx(F4e,{...e}),o.jsx(z4e,{...e}),o.jsx(W4e,{...e}),o.jsx(B4e,{...e}),o.jsx($4e,{...e}),o.jsx(H4e,{...e}),o.jsx(U4e,{...e}),o.jsx(V4e,{...e}),o.jsx(q4e,{...e}),o.jsx(K4e,{...e})]})}function Y4e(e){const t=M(),n={...e,copy:t};return o.jsxs("div",{"data-mobile-schedule-editor":!0,children:[o.jsx(O4e,{...n}),o.jsx(G4e,{...n})]})}function bj({size:e,color:t}){return o.jsxs("svg",{width:e,height:e,viewBox:"0 0 14 14",fill:"none",stroke:t,strokeWidth:1.6,style:{flex:"none"},children:[o.jsx("circle",{cx:"7",cy:"7",r:"5.6"}),o.jsx("path",{d:"M7 4v3.2l2.2 1.3"})]})}function Q4e({sub:e}){return e.kind!=="run"?null:o.jsxs(o.Fragment,{children:[e.stamp,e.cost&&o.jsxs(o.Fragment,{children:[" · ",e.cost]})]})}function X4e({sub:e,copy:t}){return e.kind!=="pending"?null:o.jsxs(o.Fragment,{children:[e.cadence,e.nextDelta&&o.jsxs(o.Fragment,{children:[" · ",G(t.schedNextIn,{d:e.nextDelta})]})]})}function Z4e({sub:e,copy:t}){return e.kind!=="paused"?null:o.jsxs(o.Fragment,{children:[e.cadence," · ",o.jsx("span",{style:{color:C.amberText},children:t.wbSchedPausedPill})]})}function J4e({row:e,copy:t,now:n}){const r=Qe(),i=pH(e,n,r);return o.jsxs("div",{style:{fontSize:12.5,color:C.muted,marginTop:2,...$e},children:[o.jsx(Q4e,{sub:i}),o.jsx(X4e,{sub:i,copy:t}),o.jsx(Z4e,{sub:i,copy:t})]})}function eSe({rows:e,copy:t}){return o.jsxs("div",{style:{display:"flex",alignItems:"center",gap:9,padding:"0 2px 10px"},children:[o.jsx(bj,{size:14,color:C.muted}),o.jsx("span",{style:{fontSize:17,fontWeight:650,color:C.ink},children:t.schedSheetTitle}),o.jsx("span",{style:{fontSize:13,color:C.muted,...$e},children:G(t.schedSheetCount,{n:e.length})})]})}function tSe(e){return{display:"flex",alignItems:"center",gap:9,padding:13,minHeight:44,boxSizing:"border-box",cursor:"pointer",borderBottom:e?"none":`1px solid ${C.divider}`}}function nSe({row:e,copy:t}){return o.jsxs(o.Fragment,{children:[o.jsx("span",{style:{fontSize:12.5,color:C.muted,flex:"none",...$e},children:e.kind==="repeat"?`×${e.runs.length}`:t.scTypeOnce}),e.unread&&o.jsx("span",{style:{width:7,height:7,borderRadius:"50%",background:C.run,flex:"none"}}),o.jsx("span",{style:{fontSize:13,color:C.muted,flex:"none"},children:"›"})]})}function rSe({row:e,copy:t,now:n,last:r,onRow:i}){return o.jsxs("div",{"data-schedule-row":e.scheduleId,onClick:()=>i(e),style:tSe(r),children:[o.jsx(bj,{size:13,color:C.muted}),o.jsx(iSe,{row:e,copy:t,now:n}),o.jsx(nSe,{row:e,copy:t})]})}function iSe({row:e,copy:t,now:n}){return o.jsxs("div",{style:{minWidth:0,flex:1},children:[o.jsx("div",{style:{fontSize:14,fontWeight:e.unread?600:400,color:e.unread?C.ink:"var(--proto-muted)",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:e.title}),o.jsx(J4e,{row:e,copy:t,now:n})]})}function oSe({rows:e,copy:t,now:n,onRow:r}){return o.jsx("div",{style:{background:"transparent",border:`1px solid ${C.hairline}`,borderRadius:"var(--r-card)",overflow:"hidden"},children:e.map((i,s)=>o.jsx(rSe,{row:i,copy:t,now:n,last:s===e.length-1,onRow:r},i.scheduleId))})}function sSe({rows:e,copy:t,now:n,onRow:r}){return o.jsxs(o.Fragment,{children:[o.jsx(eSe,{rows:e,copy:t}),o.jsx(oSe,{rows:e,copy:t,now:n,onRow:r})]})}function aSe(e,t,n,r){const i=e.schedule;if(!i)return null;const s=mj(i.nextRun,n,r),a=i.paused?` · ${t.wbSchedPausedPill}`:s?` · ${G(t.schedNextIn,{d:s})}`:"";return Hh(i,r)+a}function lSe({row:e,copy:t,now:n,onBack:r}){const i=Qe(),s=aSe(e,t,n,i);return o.jsxs("div",{style:{display:"flex",alignItems:"center",gap:9,padding:"0 2px 10px"},children:[o.jsx("span",{"data-action":"sheet-back",role:"button","aria-label":t.back,onClick:r,style:{color:C.ink,flex:"none",cursor:"pointer",minWidth:44,minHeight:44,margin:"0 -8px 0 -10px",display:"inline-flex",alignItems:"center",justifyContent:"center"},children:o.jsx(Ds,{})}),o.jsx(bj,{size:14,color:C.muted}),o.jsxs("div",{style:{minWidth:0},children:[o.jsx("div",{style:{fontSize:17,fontWeight:650,color:C.ink,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:e.title}),s&&o.jsx("div",{style:{fontSize:12.5,color:C.muted,marginTop:1,...$e},children:s})]})]})}function cSe({copy:e}){return o.jsxs("div",{style:{display:"grid",gridTemplateColumns:"64px 1fr 70px",gap:10,padding:"4px 15px 6px",fontSize:12,fontWeight:600,color:C.muted},children:[o.jsx("span",{children:e.schedColRun}),o.jsx("span",{children:e.schedColFired}),o.jsx("span",{style:{textAlign:"right"},children:e.schedColCost})]})}function uSe(e){return{display:"grid",gridTemplateColumns:"64px 1fr 70px",gap:10,padding:13,minHeight:44,boxSizing:"border-box",alignItems:"center",cursor:"pointer",borderTop:e?"none":`1px solid ${C.divider}`}}function dSe({run:e,ordinal:t}){return o.jsxs("span",{style:{fontSize:13,fontWeight:e.unread?600:400,...$e,color:e.unread?C.ink:"var(--proto-muted)",display:"flex",alignItems:"center",gap:6},children:["#",t,e.unread&&o.jsx("span",{style:{width:6,height:6,borderRadius:"50%",background:C.run}})]})}function fSe({cost:e}){return o.jsx("span",{style:{fontSize:13,color:C.muted,textAlign:"right",...$e},children:e!=null?qi(e):"—"})}function pSe({run:e,ordinal:t,first:n,now:r,onOpenRun:i}){return o.jsxs("div",{"data-run-row":e.sessionId,onClick:()=>i(e.sessionId),style:uSe(n),children:[o.jsx(dSe,{run:e,ordinal:t}),o.jsx("span",{style:{fontSize:13,color:"var(--proto-muted-2)",...$e},children:gj(e,r)}),o.jsx(fSe,{cost:e.costUsd})]})}function hSe({row:e,now:t,onOpenRun:n}){const r=vj(e.runs);return o.jsx("div",{style:{background:"transparent",border:`1px solid ${C.hairline}`,borderRadius:"var(--r-card)",overflow:"hidden",maxHeight:"46vh",overflowY:"auto"},children:e.runs.map((i,s)=>o.jsx(pSe,{run:i,ordinal:r.get(i.sessionId),first:s===0,now:t,onOpenRun:n},i.sessionId))})}function mSe({unreadIds:e,copy:t,pending:n,onMarkAllRead:r}){return o.jsx("button",{type:"button","data-action":"mark-all-read",disabled:n,onClick:()=>r(e),style:{marginLeft:"auto",border:0,background:"transparent",color:C.run,fontFamily:"var(--font-ui)",fontSize:13,fontWeight:600,cursor:n?"default":"pointer",opacity:n?.5:1,padding:0},children:G(t.schedMarkRead,{n:e.length})})}function gSe({row:e,copy:t,onEdit:n,onMarkAllRead:r,markAllPending:i=!1}){const s=hH(e);return o.jsxs("div",{style:{display:"flex",alignItems:"center",flexWrap:"wrap",padding:"10px 4px 0",gap:10},children:[o.jsx("span",{style:{fontSize:13,fontWeight:600,color:C.muted,...$e},children:G(t.schedAllRuns,{n:e.runs.length})}),n&&o.jsx("button",{type:"button","data-action":"edit-schedule",onClick:n,style:{border:0,background:"transparent",color:C.run,fontFamily:"var(--font-ui)",fontSize:13,fontWeight:600,cursor:"pointer"},children:t.scEditSchedule}),r&&s.length>0?o.jsx(mSe,{unreadIds:s,copy:t,pending:i,onMarkAllRead:r}):null]})}function vSe({row:e,copy:t,now:n,onBack:r,onOpenRun:i,onEdit:s,onMarkAllRead:a,markAllPending:l}){return o.jsxs(o.Fragment,{children:[o.jsx(lSe,{row:e,copy:t,now:n,onBack:r}),o.jsx(cSe,{copy:t}),o.jsx(hSe,{row:e,now:n,onOpenRun:i}),o.jsx(gSe,{row:e,copy:t,onEdit:s,onMarkAllRead:a,markAllPending:l})]})}function xSe(e){const[t,n]=f.useState({kind:"list"}),r=f.useCallback(()=>n(s=>s.kind==="editor"?(e.close(),s.returnTo):{kind:"list"}),[e.close]),i=f.useCallback((s,a)=>{e.openEdit(s),n({kind:"editor",returnTo:a})},[e.openEdit]);return{level:t,setLevel:n,back:r,openEditor:i}}function ySe(e,t,n){return f.useCallback(r=>{const i=fH(r);if(i.type==="modal"){t({kind:"runs",scheduleId:r.scheduleId});return}if(i.type==="open")return e(i.sessionId);n(i.schedule,{kind:"list"})},[e,n,t])}function bSe(e,t){return f.useCallback(()=>{e.submit().then(n=>{n&&t(r=>r.kind==="editor"?r.returnTo:{kind:"list"})})},[e.submit,t])}function wSe(e,t){return t.kind!=="runs"?null:e.find(n=>n.scheduleId===t.scheduleId)??null}function SSe({row:e,copy:t,now:n,back:r,onOpenSession:i,openEditor:s,onMarkAllRead:a,markAllPending:l}){const c=e.schedule?()=>s(e.schedule,{kind:"runs",scheduleId:e.scheduleId}):void 0;return o.jsx(vSe,{row:e,copy:t,now:n,onBack:r,onOpenRun:i,onEdit:c,onMarkAllRead:a,markAllPending:l})}function kSe(e,t,n,r){return e.kind!=="editor"||!t.form||!t.mode?null:o.jsx(Y4e,{form:t.form,mode:t.mode,editableFields:t.editableFields,modelOptions:t.modelOptions,thinkingOptions:t.thinkingOptions,valid:t.valid,pending:t.pending,error:t.error,onChange:t.onChange,onSubmit:n,onBack:r})}function jSe({rows:e,copy:t,editor:n,level:r,runsRow:i,now:s,back:a,onOpenSession:l,onRow:c,openEditor:u,submit:d,onMarkAllRead:p,markAllPending:h}){const m=kSe(r,n,d,a);return m||(i?o.jsx(SSe,{row:i,copy:t,now:s,back:a,onOpenSession:l,openEditor:u,onMarkAllRead:p,markAllPending:h}):o.jsx(sSe,{rows:e,copy:t,now:s,onRow:c}))}function CSe(e){const t=Z(),{rows:n,editor:r,onOpenSession:i,onClose:s}=e,a=xSe(r),l=wSe(n,a.level),c=ySe(i,a.setLevel,a.openEditor),u=bSe(r,a.setLevel),d=f.useCallback(()=>{r.close(),s()},[r.close,s]),p=a.level.kind==="list"?void 0:a.back;return o.jsx(Kn,{onClose:d,onBack:p,children:o.jsx(jSe,{...e,copy:t,level:a.level,runsRow:l,now:e.now??Date.now(),back:a.back,onRow:c,openEditor:a.openEditor,submit:u})})}function TSe(e){const t=SH(),n=kH(jH());return o.jsx(CSe,{...e,editor:n,onMarkAllRead:t.markManyRead,markAllPending:t.pending})}function ESe(e){try{const t=window.localStorage.getItem(e);if(!t)return new Set;const n=JSON.parse(t);return new Set(Array.isArray(n)?n.filter(r=>typeof r=="string"):[])}catch{return new Set}}function RSe(e,t){try{window.localStorage.setItem(e,JSON.stringify([...t]))}catch{}}function Zg(e){const[t,n]=f.useState(()=>ESe(e)),r=f.useCallback(l=>{n(c=>{const u=l(c);return u!==c&&RSe(e,u),u})},[e]),i=f.useCallback(l=>r(c=>{const u=new Set(c);return u.delete(l)||u.add(l),u}),[r]),s=f.useCallback(l=>r(c=>c.has(l)?c:new Set(c).add(l)),[r]),a=f.useCallback(l=>r(c=>{if(!c.has(l))return c;const u=new Set(c);return u.delete(l),u}),[r]);return f.useMemo(()=>({ids:t,toggle:i,add:s,remove:a}),[t,i,s,a])}const MSe="cortex.projectStarsCollapsed";function TH(){const{ids:e,toggle:t,remove:n}=Zg(MSe);return{collapsed:e,toggle:t,reveal:n}}const Kp=e=>e<10?`0${e}`:`${e}`,EH={running:"execStatusRunning",completed:"execStatusCompleted",failed:"execStatusFailed",cancelled:"execStatusCancelled",stale:"execStatusStale"};function RH(e){return Object.prototype.hasOwnProperty.call(EH,e)}function wj(e,t){return RH(e)?t[EH[e]]:e}const ASe={running:"●",completed:"✓",failed:"✕",cancelled:"✕",stale:"◦"};function PSe(e,t){return RH(e)?`${ASe[e]} ${wj(e,t)}`:e}function ISe(e){if(!e)return"";const t=new Date(e);return`${Kp(t.getUTCHours())}:${Kp(t.getUTCMinutes())}`}function LSe(e){const t=e.runtime.endedAt??e.runtime.updatedAt,n=new Date(t);return`${Kp(n.getUTCHours())}:${Kp(n.getUTCMinutes())}:${Kp(n.getUTCSeconds())}`}function NSe(e,t){const n=e.runtime.endedAt;return n?G(t.execFinishedAt,{time:ISe(n)}):wj("running",t)}function DSe(e){return e==="running"}function Sj(e){if(e.actions.some(n=>n.action==="approve"))return"approved";const t=e.actions[e.actions.length-1];return t?t.action==="explain"?"explained":"revised":"none"}function HR(e,t,n,r){const i=r.trim();return t==="revise"?i?e.revise.replace("{title}",n).replace("{text}",i):null:i?e.explain.replace("{title}",n).replace("{text}",i):e.explainBare.replace("{title}",n)}function or(e){return e.awaitingInput&&!e.teamLeadId?"you":e.running?"running":(e.waitingOn??0)>0?"waiting":"idle"}const UR={you:0,running:1,waiting:2,idle:3};function Tc(e){return e.workerName||e.label||Ti(e.sessionId)}function Ja(e,t=Date.now()){const n=i=>_0(i,t);return{active:[...e.filter(i=>!n(i))].sort((i,s)=>UR[or(i)]-UR[or(s)]),inactive:e.filter(n)}}function kj(e,t){const r=e.map(or).filter(i=>i==="running").length;return{workers:G(e.length===1?t.wbTeamCountOne:t.wbTeamCountMany,{n:e.length}),running:r>0?G(t.wbTeamRunningCount,{n:r}):null}}function jj(e,t){const n=kj(e,t);return[n.workers,n.running].filter(Boolean).join(" · ")}function Cj(e,t,n,r){const i=Date.parse(e.lastUsedAt),s=Number.isNaN(i)?null:_c(t-i,r);switch(or(e)){case"you":return n.wbTeamStatusYou;case"running":return s&&!e.backgroundRunning?G(n.wbTeamStatusRunningFor,{span:s}):n.wbTeamStatusRunning;case"waiting":return n.wbTeamStatusWaiting;case"idle":return s?G(n.wbTeamStatusIdleFor,{span:s}):n.wbTeamStatusIdle}}function OSe(e,t,n){const r=or(e);if(r==="you"||r==="waiting"||r==="running"&&e.backgroundRunning)return null;const i=Date.parse(e.lastUsedAt);return Number.isNaN(i)?null:_c(t-i,n)}function FSe(e,t){var n;return t||(or(e)==="running"&&((n=e.todos)!=null&&n.activeLabel)?e.todos.activeLabel:e.workerBrief?e.workerBrief:e.label&&e.label!==Tc(e)?e.label:null)}function _Se(e,t){var i,s,a,l;const n=(a=(s=(i=e==null?void 0:e.askUser)==null?void 0:i.questions[0])==null?void 0:s.question)==null?void 0:a.trim();if(n)return G(t.wbTeamAsks,{text:n});const r=(l=e==null?void 0:e.plan)==null?void 0:l.planContent.split(`
423
423
  `).map(c=>c.replace(/^#+\s*/,"").trim()).find(Boolean);return r?G(t.wbTeamPlan,{text:r}):null}function zSe(e,t,n=Date.now()){const r=t(e);return _0(e,n)?{...r,inactive:!0}:r}function MH(e,t,n,r){const i=yj(t),s=r&&n.length>0;return{...e,running:e.running||i.running,awaitingInput:e.awaitingInput||i.awaitingInput,waitingOn:e.waitingOn||i.waitingOn,unread:e.unread||!s&&i.unread,...n.length>0?{workers:n,workersExpanded:s}:{}}}function my(){return Object.create(null)}function AH(e){const t=my();for(const n of e)n.unread&&(t[n.projectId]=(t[n.projectId]??0)+1);return t}function PH(e){const t=my();for(const n of e)n.awaitingInput&&(t[n.projectId]=(t[n.projectId]??0)+1);return t}function IH(e,t){const n=e+t;return{count:n,tone:t>0?"action":n>0?"unread":null}}function LH(e){const t=my();for(const n of e){const r=Date.parse(n.lastUsedAt||n.createdAt);Number.isNaN(r)||(!(n.projectId in t)||r>t[n.projectId])&&(t[n.projectId]=r)}return t}function NH(e,t){const n=r=>typeof t[r]=="number"?t[r]:-1/0;return[...e].sort((r,i)=>{const s=n(r.id),a=n(i.id);return s===a?0:a-s})}function WSe(e){return e.length!==1||e<"1"||e>"9"?null:e.charCodeAt(0)-49}const DH="cortex.railSort",OH="cortex.railOrder";function BSe(e){return e==="activity"||e==="manual"}function $Se(){try{const e=window.localStorage.getItem(DH);return BSe(e)?e:"activity"}catch{return"activity"}}function HSe(e){try{window.localStorage.setItem(DH,e)}catch{}}function USe(){try{const e=window.localStorage.getItem(OH);if(!e)return[];const t=JSON.parse(e);return Array.isArray(t)?t.filter(n=>typeof n=="string"):[]}catch{return[]}}function VSe(e){try{window.localStorage.setItem(OH,JSON.stringify(e))}catch{}}function tk(e,t){const n=new Set(t),r=new Set,i=[];for(const a of e)n.has(a)&&!r.has(a)&&(r.add(a),i.push(a));let s=0;for(const a of t){const l=i.indexOf(a);if(l>=0){s=l+1;continue}i.splice(s,0,a),s+=1}return i}function qSe(e,t,n){const r=e.indexOf(t),i=e.indexOf(n);if(r<0||i<0||r===i)return[...e];const s=[...e];return s.splice(r,1),s.splice(i,0,t),s}function KSe(e,t,n,r){return e==="manual"||r?tk(n,t):[...t]}const VR=8;function qR(e){return e<10?"0"+e:String(e)}function GSe(e){const t=Cs(e);if(!t)return"";const n=new Date(t);return n.getFullYear()+"-"+qR(n.getMonth()+1)+"-"+qR(n.getDate())+" "+bf(n)}function gy(e){return e.label??Ti(e.sessionId)}function gu(e,t){return t?gy(e).toLowerCase().includes(t.toLowerCase()):!0}function I2(e){const t=new Map;for(const n of e){const r=t.get(n.projectId);r?r.push(n):t.set(n.projectId,[n])}return t}function nk(e,t,n){if(!e)return null;const r=t.find(i=>i.sessionId===e)??n.find(i=>i.sessionId===e);return(r==null?void 0:r.projectId)??null}function YSe(e){const{projects:t,directSessions:n,scheduledSessions:r,schedules:i,selectedSessionId:s,fallbackProjectId:a,expanded:l,schedulesExpanded:c,showAll:u,sort:d,manualOrder:p,dragged:h,now:m,lang:v}=e,g=V=>({sessionId:V.sessionId,projectId:V.projectId,title:gy(V),starred:V.starred,age:zr(Cs(V),m,v),stamp:GSe(V),...Vh(V),selected:V.sessionId===s}),x=e.filter.trim(),y=x.length>0,b=AH(n),S=PH(n),j=LH([...n,...r]),w=I2(n),R=I2(r),T=I2(i),A=NH(t,j).map(V=>V.id),P=KSe(d,A,p,h),L=new Map(t.map(V=>[V.id,V])),F=P.map(V=>L.get(V)).filter(V=>!!V),B=nk(s,n,r)??a,K=F.map(V=>{var be;const Q=vH(w.get(V.id)??[],R.get(V.id)??[]),re=Q.direct,ue=Q.starred.filter(Ue=>gu(Ue,x)),z=e.teamEnabled?xj(re,e.now):null,J=Ue=>(z==null?void 0:z.workers.get(Ue.sessionId))??[],ee=JS(T.get(V.id)??[],Q.scheduled),Y=IH(b[V.id]??0,S[V.id]??0),U=Y.count,ie=Q.starred.length===0&&re.length===0&&ee.length===0,de=y?re.filter(Ue=>gu(Ue,x)).length:re.length,ne=z?y?z.top.filter(Ue=>gu(Ue,x)||J(Ue).some(He=>gu(He,x))):z.top:y?re.filter(Ue=>gu(Ue,x)):re,te=Ue=>{var fn;const He=J(Ue);if(He.length===0)return g(Ue);const Dt=He.map($t=>zSe($t,g,e.now)),Xt=y?Dt.filter(($t,Zt)=>gu(He[Zt],x)):Dt,dn=y||!!((fn=e.expandedLeads)!=null&&fn.has(Ue.sessionId))||He.some($t=>$t.sessionId===s);return MH(g(Ue),Dt,Xt,dn)},H=Uh(ne),se=u.has(V.id),ke=y||se?H:H.slice(0,VR),le=j[V.id],De=U>0;return{id:V.id,current:V.id===B,expanded:y?de+ue.length>0:l.has(V.id),empty:ie,attention:U,attentionTone:Y.tone,idleAge:!De&&typeof le=="number"?zr(le,m,v):null,starredSessions:Uh(ue).map(g),starsExpanded:y||!((be=e.starsCollapsed)!=null&&be.has(V.id)),sessions:ke.map(te),hiddenSessions:Math.max(0,H.length-ke.length),showingAll:se&&!y&&H.length>VR,totalSessions:re.length,schedules:ee,schedulesExpanded:c.has(V.id),scheduleUnread:mH(ee),matchCount:y?de+ue.length:null}});return{projects:y?K.filter(V=>(V.matchCount??0)>0):K,currentProjectId:B}}function hr(e){return qi(e??0)}const QSe=5;function FH(e,t){if(t==null||t<=0)return null;const n=(e??0)/t*100;return Math.max(0,Math.min(100,n))}function XSe(e){return e==null||e<=0?"—":hr(e)}function ZSe(e){if(!e||e.length===0)return[];const t=e.reduce((r,i)=>Math.max(r,i.cost),0),n=e.length-1;return e.map((r,i)=>({pct:t>0?r.cost/t*100:0,date:r.date,cost:r.cost,isToday:i===n}))}function JSe(e){return!e||e.length===0?null:e.reduce((n,r)=>n+r.cost,0)/e.length}function eke(e){if(!e)return[];const t=Object.entries(e).map(([r,i])=>({label:r,cost:i.week})).filter(r=>r.cost>0).sort((r,i)=>i.cost-r.cost).slice(0,QSe),n=t.reduce((r,i)=>r+i.cost,0);return t.map(r=>({label:r.label,cost:r.cost,pct:n>0?r.cost/n*100:0}))}function tke(e){var t;return((t=e.selection)==null?void 0:t.model)??""}function nke(e,t,n,r){return e?Date.parse(e)-t<=0?r.ovNextDue:G(r.ovNextIn,{until:$_(e,t,n)}):"—"}function rke(e,t,n,r){const i=yf(e,t,n);return i?G(r.ovLastRun,{ago:i}):r.ovNeverRun}function ike(e,t){return typeof e.durationMs=="number"?e.durationMs:e.startedAt?Math.max(0,t-Date.parse(e.startedAt)):null}function oke(e){return e==null?"—":qi(e)}function ske(e,t){return e.sessionId?G(t.ovSummarySession,{id:Ti(e.sessionId)}):t.ovSummaryExec}function _H(e,t,n){const r=Date.parse(e);if(Number.isNaN(r))return"—";const i=Ih(r,new Date(t),n);return i===Ih(t,new Date(t),n)?bf(r):i}function ake(e,t){switch(e.status){case"running":return"running";case"completed":return(t==null?void 0:t.origin)==="scheduled"?"scheduled":"done";case"failed":return"failed";default:return"stopped"}}function lke(e,t,n,r,i){return e.map(s=>{const a=s.sessionId?t.get(s.sessionId):void 0,l=a!=null&&a.teamLeadId?i.ovTagWorker:(a==null?void 0:a.origin)==="scheduled"?i.wbSchedGroup:null;return{id:s.id,title:a?gy(a):ske(s,i),tag:l,mark:ake(s,a),statusWord:wj(s.status,i),duration:ike(s,n),cost:oke(s.cost),time:_H(s.startedAt,n,r)}})}function cke(e){return e.awaitingInput?"you":e.running?"running":e.waitingOn?"waiting":null}function uke(e,t){return e===1?t.ovWaitingOne:G(t.ovWaitingMany,{n:e})}function dke(e,t,n,r,i){var a;if(t==="you")return null;if(e.running)return((a=e.todos)==null?void 0:a.activeLabel)||e.workerBrief||(e.backgroundRunning?i.pillBackground:null);const s=Vh(e);return n.length>0&&!s[t==="running"?"running":"waitingOn"]?jj(Ja(n,r).active,i):s.waitingOn?uke(e.waitingOn??0,i):null}const KR={you:0,running:1,waiting:2};function fke(e,t,n=!1,r=Date.now()){const i=[...new Map(e.map(l=>[l.sessionId,l])).values()],s=n?xj(i.filter(l=>l.origin==="direct"&&l.starred!==!0),r):null,a=[];for(const l of i){const c=(s==null?void 0:s.workers.get(l.sessionId))??[],u=Vh(l),d=cke(c.length>0?MH(u,c.map(Vh),[],!1):u);d&&a.push({sessionId:l.sessionId,projectId:l.projectId,title:gy(l),state:d,doing:dke(l,d,c,r,t),at:Cs(l)})}return a.sort((l,c)=>KR[l.state]-KR[c.state]||c.at-l.at),{needsYou:a.filter(l=>l.state==="you"),inProgress:a.filter(l=>l.state!=="you")}}function pke(e,t,n,r){const i=t?yf(t,n,r):"";return[e,i].filter(Boolean).join(" · ")}function hke(e,t){const n=[];return e.forEach((r,i)=>{const s=(t[i]??[]).filter(l=>Sj(l.item)==="none");if(s.length===0)return;const a=s.reduce((l,c)=>c.ts>l?c.ts:l,s[0].ts);n.push({boardId:r.id,boardTitle:r.title,pending:s.length,latestTs:a})}),n.sort((r,i)=>i.latestTs.localeCompare(r.latestTs))}const mke={user:"ovTriggerChat",scheduled:"wbSchedGroup"};function GR(e,t){const n=mke[e];return n?t[n]:e}const YR={user:0,scheduled:1};function gke(e,t){let n=Object.keys(YR).length;return e.map(r=>YR[r.label]??Math.min(n++,t-1))}function vke(e,t){return t!=null&&t>0&&(e??0)>t}function QR(e,t,n){const[r,i,s]=e.split("-").map(Number);return!r||!i||!s?e:Ih(new Date(r,i-1,s).getTime(),new Date(t),n)}function xke(e,t=3){return[...e.topLevelFiles,...e.dirs.flatMap(r=>r.entries)].filter(r=>!Number.isNaN(Date.parse(r.modifiedAt))).sort((r,i)=>Date.parse(i.modifiedAt)-Date.parse(r.modifiedAt)).slice(0,t).map(r=>({path:r.path,name:r.name,modifiedAt:r.modifiedAt}))}const zH={padding:"10px 14px",borderRadius:10,cursor:"pointer",minWidth:0,display:"flex",alignItems:"center",gap:10},yke={large:{side:40,radius:12,font:14},row:{side:34,radius:10,font:12}};function WH({text:e,accent:t,large:n=!1}){const r=yke[n?"large":"row"];return o.jsx("div",{style:{width:r.side,height:r.side,borderRadius:r.radius,background:t?"var(--proto-line-3)":C.gray,color:t?C.ink:C.sub,display:"grid",placeItems:"center",fontSize:r.font,fontWeight:650,flex:"none"},children:e})}function bke({row:e,copy:t}){return e.todayCost==null?null:o.jsx("div",{style:{display:"flex",alignItems:"center",gap:5,fontSize:12,color:C.muted,marginTop:2,...$e},children:o.jsxs("span",{children:[t.usageToday," ",hr(e.todayCost)]})})}function wke({row:e}){const t=Z().projAttention;return e.badgeCount<=0?null:o.jsx("span",{"aria-label":t,"data-attention-tone":e.badgeTone,style:{color:e.badgeTone==="action"?"var(--proto-amber-fg)":"var(--proto-accent)",fontSize:13,fontWeight:650,flex:"none",...$e},children:e.badgeCount})}const Ske=o.jsx("span",{"aria-hidden":"true",style:{fontSize:15,fontWeight:700,lineHeight:1,color:C.ink,flex:"none"},children:"✓"}),kke=o.jsx("span",{"aria-hidden":"true",style:{fontSize:17,lineHeight:1,color:C.faint,flex:"none"},children:"›"});function rk({row:e,current:t=!1,onSwitch:n}){const r=Z();return o.jsxs("div",{className:"m-press","data-project-id":e.id,"aria-current":t||void 0,onClick:()=>n(e.id),style:zH,children:[o.jsx(WH,{text:e.initials,accent:t}),o.jsxs("div",{style:{minWidth:0,flex:1},children:[o.jsx("div",{style:{fontSize:14,fontWeight:600,color:C.ink,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.id}),o.jsx(bke,{row:e,copy:r})]}),o.jsx(wke,{row:e}),t?Ske:kke]})}function BH({onClick:e}){const t=Z();return o.jsxs("div",{className:"m-press",onClick:e,style:{...zH,color:C.ink},children:[o.jsx("span",{style:{width:34,height:34,borderRadius:10,background:C.gray,color:C.sub,display:"grid",placeItems:"center",flex:"none"},children:o.jsx(Ba,{size:14,strokeWidth:2})}),o.jsx("span",{style:{fontSize:14,fontWeight:600},children:t.newProject})]})}function jke(e){return e.reduce((t,n)=>t+(n.online?1:0),0)}function $H(e){const t={byProject:my(),global:0};for(const n of e)n.status==="pending"&&(n.projectId==null?t.global++:t.byProject[n.projectId]=(t.byProject[n.projectId]??0)+1);return t}function Cke(e,t,n,r={},i={},s={},a={}){const l=e.filter(c=>c.id!==t);return NH(l,i).map(c=>{const u=n==null?void 0:n[c.id],d=r[c.id]??0,p=(s[c.id]??0)+(a[c.id]??0),h=IH(d,p);return{id:c.id,initials:dH(c.id),todayCost:u?u.today:null,badgeCount:h.count,badgeTone:h.tone}})}const XR=[];function HH(e,t){const{projects:n,sessions:r,globalByProject:i,approvalsByProject:s}=t,a=f.useMemo(()=>AH(r),[r]),l=f.useMemo(()=>PH(r),[r]),c=f.useMemo(()=>LH(r),[r]);return f.useMemo(()=>Cke(n,e,i,a,c,l,s),[n,e,i,a,c,l,s])}function Tke(e){const t=ve(),n=xe({...t.projects.list.queryOptions({}),refetchOnMount:!1}).data,r=Zi("direct").data,i=xe(t.cost.summary.queryOptions({})).data,s=xe(t.approvals.list.queryOptions({status:"pending"})).data,a=f.useMemo(()=>$H(s??[]).byProject,[s]),l=HH(null,{projects:n??XR,sessions:r??XR,globalByProject:i==null?void 0:i.byProject,approvalsByProject:a});return f.useMemo(()=>({current:l.find(c=>c.id===e)??null,others:l.filter(c=>c.id!==e)}),[l,e])}function Eke({current:e,others:t,onPick:n,onNewProject:r,onClose:i}){const s=Z();return o.jsxs(Kn,{onClose:i,children:[o.jsx("div",{style:{padding:"0 2px 8px",fontSize:17,fontWeight:650,color:C.ink},children:s.projSwitch}),o.jsxs(Xi,{inset:58,children:[e&&o.jsx(rk,{row:e,current:!0,onSwitch:i},e.id),t.map(a=>o.jsx(rk,{row:a,onSwitch:n},a.id)),o.jsx(BH,{onClick:r})]})]})}function Rke({currentProjectId:e,onPick:t,onNewProject:n,onClose:r}){const{current:i,others:s}=Tke(e);return o.jsx(Eke,{current:i,others:s,onPick:t,onNewProject:n,onClose:r})}function Tj(e){return e.trim().length>0}function Mke(e,t){const n=e&&typeof e=="object"&&"message"in e?e.message:void 0;return typeof n=="string"&&n.trim().length>0?n:t}function UH({onCreated:e}={}){const t=ve(),n=_e(),[r,i]=f.useState(null),s=Z().npCreateFailed,a=Se(t.projects.create.mutationOptions({})),l=f.useCallback(()=>i(null),[]);return{createProject:f.useCallback(async u=>{if(!Tj(u)||a.isPending)return null;i(null);let d;try{d=await a.mutateAsync({name:u.trim()})}catch(p){return i(Mke(p,s)),null}return await n.invalidateQueries(t.projects.list.queryFilter()),await(e==null?void 0:e(d.id)),d.id},[s,a,e,n,t.projects.list]),clearError:l,error:r,isPending:a.isPending}}function Ake(e,{setCurrentProject:t,close:n,navigate:r}){t(e),n(),r("/m/session/new")}function Pke({name:e,onNameChange:t,onCreate:n,onClose:r,error:i,pending:s}){const a=Z(),c=Tj(e)&&!s;return o.jsxs(Kn,{onClose:r,children:[o.jsx("div",{style:{display:"flex",alignItems:"baseline",padding:"0 2px 12px"},children:o.jsx("span",{style:{fontSize:17,fontWeight:650,color:C.ink},children:a.newProject})}),o.jsx("input",{value:e,onChange:u=>t(u.target.value),onKeyDown:u=>{u.key==="Enter"&&c&&n()},placeholder:a.npNamePlaceholder,autoFocus:!0,style:{width:"100%",height:48,border:"1px solid var(--proto-line-3)",borderRadius:"var(--r-control)",background:"var(--material-inset-bg)",padding:"0 14px",fontSize:16,fontFamily:"inherit",color:C.ink,boxSizing:"border-box"}}),i&&o.jsx("div",{"data-project-create-error":!0,style:{marginTop:8,fontSize:12.5,lineHeight:1.5,color:"var(--proto-danger)"},children:i}),o.jsx("button",{type:"button",onClick:n,disabled:!c,"aria-busy":s,style:{width:"100%",height:48,border:"none",borderRadius:"var(--r-control)",background:C.inkSolid,color:"var(--ink-solid-fg)",display:"flex",alignItems:"center",justifyContent:"center",fontFamily:"var(--font-ui)",fontSize:15,fontWeight:600,marginTop:12,opacity:c?1:.45,cursor:c?"pointer":"default"},children:a.npCreateAndChat})]})}function VH(e,t){const[n,r]=f.useState(!1),[i,s]=f.useState(""),a=f.useCallback(()=>r(!1),[]),l=f.useCallback(h=>{Ake(h,{setCurrentProject:t,close:a,navigate:e})},[a,e,t]),c=UH({onCreated:l}),u=f.useCallback(h=>{s(h),c.clearError()},[c.clearError]),d=f.useCallback(()=>{c.createProject(i)},[c.createProject,i]),p=f.useCallback(()=>{s(""),c.clearError(),r(!0)},[c.clearError]);return{open:n,name:i,setName:u,submit:d,close:a,show:p,error:c.error,pending:c.isPending}}function qH({project:e}){return e.open?o.jsx(Pke,{name:e.name,onNameChange:e.setName,onCreate:e.submit,onClose:e.close,error:e.error,pending:e.pending}):null}const Ike=10,Lke=1.2,ZR=.4,JR=.35,Nke=100;function Dke(e,t,n){return Math.max(Math.abs(e),Math.abs(t))<Ike?"pending":Math.abs(e)<=Math.abs(t)*Lke?"ignore":(n?e<0:e>0)?"drawer":"ignore"}function Oke(e,t,n){if(t<=0)return n?1:0;const r=(n?1:0)+e/t;return Math.min(1,Math.max(0,r))}function Fke(e,t,n){return t>=ZR?!0:t<=-ZR?!1:n?e>1-JR:e>=JR}function eM(e,t){const n=e.filter(r=>t-r.t<=Nke);return n.length>0?n:e.slice(-1)}function _ke(e){if(e.length<2)return 0;const t=e[0],n=e[e.length-1],r=n.t-t.t;return r>0?(n.x-t.x)/r:0}const L2=280,tM="cubic-bezier(.32,.72,0,1)",zke=.38,Wke=350,Bke='input, textarea, select, [contenteditable="true"]';function Jg({panel:e,scrim:t},n,r){const i=e.current,s=t.current;if(!i||!s)return;const a=n>0,l=`visibility 0s linear ${a?0:L2}ms`;i.style.transition=r?`transform ${L2}ms ${tM}, ${l}`:"none",i.style.transform=`translate3d(${(n-1)*100}%, 0, 0)`,i.style.visibility=a?"visible":"hidden",s.style.transition=r?`opacity ${L2}ms ${tM}, ${l}`:"none",s.style.opacity=String(n*zke),s.style.visibility=a?"visible":"hidden",s.style.pointerEvents=n===1?"auto":"none"}function nM(e){const t=f.useRef(e);return t.current=e,t}function $ke(e,t,n,r){f.useEffect(()=>{const i=e.current;if(!i)return;let s=null,a=0,l=0;const c=v=>{cancelAnimationFrame(a),a=requestAnimationFrame(()=>Jg(t,v,!1))},u=v=>{var x;if(!v.isPrimary||v.button!==0||(s=null,v.target instanceof Element&&v.target.closest(Bke)))return;const g=n.current;s={id:v.pointerId,x0:v.clientX,y0:v.clientY,startedOpen:g,lock:"pending",width:((x=t.panel.current)==null?void 0:x.offsetWidth)??0,progress:g?1:0,samples:[{x:v.clientX,t:v.timeStamp}]}},d=v=>{var x;if(!s||v.pointerId!==s.id)return;const g=v.clientX-s.x0;s.lock==="pending"&&(s.lock=Dke(g,v.clientY-s.y0,s.startedOpen),s.lock==="drawer"&&((x=i.setPointerCapture)==null||x.call(i,v.pointerId))),s.lock==="drawer"&&(s.samples=eM([...s.samples,{x:v.clientX,t:v.timeStamp}],v.timeStamp),s.progress=Oke(g,s.width,s.startedOpen),c(s.progress))},p=v=>{if(!s||v.pointerId!==s.id)return;const g=s;if(s=null,g.lock!=="drawer")return;cancelAnimationFrame(a),l=v.timeStamp+Wke;const x=eM([...g.samples,{x:v.clientX,t:v.timeStamp}],v.timeStamp),y=Fke(g.progress,_ke(x),g.startedOpen);Jg(t,y?1:0,!0),y!==n.current&&r.current(y)},h=v=>{if(!s||v.pointerId!==s.id)return;const g=s;s=null,cancelAnimationFrame(a),g.lock==="drawer"&&Jg(t,g.startedOpen?1:0,!0)},m=v=>{v.timeStamp>l||(v.stopPropagation(),v.preventDefault())};return i.addEventListener("pointerdown",u),i.addEventListener("pointermove",d),i.addEventListener("pointerup",p),i.addEventListener("pointercancel",h),i.addEventListener("click",m,!0),()=>{cancelAnimationFrame(a),i.removeEventListener("pointerdown",u),i.removeEventListener("pointermove",d),i.removeEventListener("pointerup",p),i.removeEventListener("pointercancel",h),i.removeEventListener("click",m,!0)}},[e,t,n,r])}function Hke(e,t){const n=f.useRef(e);f.useEffect(()=>{const r=t.current;if(!r||n.current===e)return;n.current=e;const i=document.activeElement;e&&!r.contains(i)&&r.focus({preventScroll:!0}),!e&&i instanceof HTMLElement&&r.contains(i)&&i.blur()},[e,t])}const Uke={position:"relative",height:"100%",overflow:"hidden"},Vke={position:"absolute",inset:0,zIndex:8,background:"var(--overlay-ink)",opacity:0,visibility:"hidden",pointerEvents:"none",willChange:"opacity"},qke={position:"absolute",top:0,bottom:0,left:0,zIndex:9,width:"min(calc(100% - 56px), 420px)",background:C.backdrop,boxShadow:"var(--material-overlay-shadow)",outline:"none",transform:"translate3d(-100%, 0, 0)",visibility:"hidden",willChange:"transform"};function Kke({open:e,onOpenChange:t,panelLabel:n,panel:r,children:i}){const s=f.useRef(null),a=f.useRef(null),l=f.useRef(null),c=f.useMemo(()=>({panel:a,scrim:l}),[]),u=nM(e),d=nM(t),p=f.useRef(!1);return f.useLayoutEffect(()=>{Jg(c,e?1:0,p.current),p.current=!0},[e,c]),Hke(e,a),$ke(s,c,u,d),o.jsxs("div",{ref:s,"data-m-drawer-host":"",style:Uke,children:[o.jsx("div",{style:{height:"100%"},children:i}),o.jsx("div",{ref:l,"data-m-drawer-scrim":"",style:Vke,onClick:()=>t(!1)}),o.jsx("div",{ref:a,"data-m-drawer-panel":"","data-open":e?"true":"false",role:"dialog","aria-modal":"true","aria-label":n,tabIndex:-1,style:qke,children:r})]})}const KH={appearance:"stNavAppearance",platform:"stNavPlatform",accounts:"stNavAccounts",models:"stNavModels",budget:"stNavBudget",usage:"stNavUsage",machines:"stNavMachines",environments:"stNavEnvironments",plugins:"stNavPlugins",mcp:"stNavMcp",notifications:"stNavNotifications",hooks:"stNavHooks",privacy:"tmNavPrivacy",advanced:"stNavAdvanced"},GH={appearance:"M12 3a9 9 0 1 0 0 18c1.2 0 2-.9 2-2 0-.6-.3-1-.6-1.4-.3-.4-.4-.7-.4-1.1 0-1.1.9-2 2-2h1.6a4.4 4.4 0 0 0 4.4-4.4C21 6.2 17 3 12 3zM7.5 10.5h.01M10.5 7.5h.01M15.5 7.5h.01",accounts:"M12 12a4 4 0 1 0 0-8 4 4 0 0 0 0 8zM4.5 20.5a7.5 7.5 0 0 1 15 0",platform:"M12 3a9 9 0 1 0 0 18 9 9 0 0 0 0-18zM3.3 12h17.4M12 3a13 13 0 0 1 0 18M12 3a13 13 0 0 0 0 18",notifications:"M18 8.5a6 6 0 1 0-12 0c0 6.5-2.5 7.5-2.5 7.5h17S18 15 18 8.5M13.7 19.5a2 2 0 0 1-3.4 0",models:"M4 7h9M17 7h3M4 17h3M11 17h9M14.5 4.2v5.6M7.5 14.2v5.6",environments:"M12 3 3 7.5l9 4.5 9-4.5zM3 12l9 4.5L21 12M3 16.5 12 21l9-4.5",plugins:"M4.5 4.5h6v6h-6zM13.5 4.5h6v6h-6zM4.5 13.5h6v6h-6zM13.5 13.5h6v6h-6z",mcp:"M4 7a3 3 0 0 1 3-3h10a3 3 0 0 1 3 3v10a3 3 0 0 1-3 3H7a3 3 0 0 1-3-3zM9 9h6v6H9zM12 4V2M12 22v-2M4 12H2M22 12h-2",hooks:"M9.5 17H7.5a5 5 0 0 1 0-10h2M14.5 7h2a5 5 0 0 1 0 10h-2M8.5 12h7",budget:"M3.5 8.5a2 2 0 0 1 2-2h11M3.5 8.5v8a2 2 0 0 0 2 2h13a2 2 0 0 0 2-2v-6a2 2 0 0 0-2-2h-13a2 2 0 0 1-2-2zM16.8 13.5h.01",usage:"M3.34 19a10 10 0 1 1 17.32 0M12 14l4-4",machines:"M4 4.5h16v5.5H4zM4 14h16v5.5H4zM7.5 7.2h.01M7.5 16.8h.01M11 7.2h5M11 16.8h5",privacy:"M12 3 4.5 6v5.5c0 4.6 3.2 8.4 7.5 9.5 4.3-1.1 7.5-4.9 7.5-9.5V6zM9 12l2 2 4-4",advanced:"M12 3v2M12 19v2M3 12h2M19 12h2M5.6 5.6 7 7M17 17l1.4 1.4M5.6 18.4 7 17M17 7l1.4-1.4M12 8.2a3.8 3.8 0 1 0 0 7.6 3.8 3.8 0 0 0 0-7.6z"},Gke={workspace:"stGroupWorkspace",agent:"stGroupAgent",resources:"stGroupResources",system:"stGroupSystem"},Yke=[{key:"workspace",keys:["appearance","accounts","platform","notifications"]},{key:"agent",keys:["models","environments","plugins","mcp","hooks"]},{key:"resources",keys:["budget","usage","machines"]},{key:"system",keys:["advanced","privacy"]}];function Qke(e,t){return{key:t,label:e[KH[t]],icon:GH[t]}}function YH(e){return GH[e]}function QH(e){return Yke.map(t=>({key:t.key,label:e[Gke[t.key]],entries:t.keys.map(n=>Qke(e,n))}))}function Xke(e,t){return e[KH[t]]}function Zke(e){return e==="five_hour"?"5h":e==="seven_day"||e==="seven_day_overage_included"?"7d":e.replaceAll("_"," ")}function Ej(e,t){return zc(Math.max(1,Math.ceil(e/60))*6e4,t)}function Jke(e,t){const n=cn(t);return G(e===1?n.rlWaitingOne:n.rlWaitingMany,{n:e})}function e5e(e,t,n){return{type:e.type,typeLabel:e.label??Zke(e.type),resetsAt:e.resetsAt,countdown:Ej(e.resetsAt-t,n)}}function t5e(e,t,n){const r=e.windows.filter(a=>a.resetsAt>t).sort((a,l)=>a.resetsAt-l.resetsAt||a.type.localeCompare(l.type)||(a.label??"").localeCompare(l.label??"")).map(a=>e5e(a,t,n));if(r.length===0)return null;const i=Math.max(...r.map(a=>a.resetsAt)),s=e.waitingSessions??0;return{provider:e.provider,displayName:e.displayName,recoveryAt:i,recoveryCountdown:Ej(i-t,n),waitingLabel:Jke(s,n),windows:r}}function n5e(e){return`${e.displayName} · ${e.recoveryCountdown}`}function r5e(e,t,n){return G(cn(n).rlAggregate,{count:e,countdown:t})}function i5e(e,t,n){const r=((e==null?void 0:e.providers)??[]).map(a=>t5e(a,t,n)).filter(a=>a!==null).sort((a,l)=>a.displayName.localeCompare(l.displayName)||a.provider.localeCompare(l.provider));if(r.length===0)return null;const i=Math.min(...r.map(a=>a.recoveryAt)),s=Ej(i-t,n);return{lang:n,providers:r,label:r.length===1?n5e(r[0]):r5e(r.length,s,n)}}function N2(){return Math.floor(Date.now()/1e3)}function XH(){var u;const e=ve(),t=_e(),n=Qe(),r=xe(e.system.rateLimitStatus.queryOptions({})),{reconnectEpoch:i}=oj(),[s,a]=f.useState(N2),l=()=>{t.invalidateQueries(e.system.rateLimitStatus.queryFilter())};vl(x$,l),f.useEffect(()=>{i>0&&l()},[i]);const c=(((u=r.data)==null?void 0:u.providers.length)??0)>0;return f.useEffect(()=>{if(!c)return;a(N2());const d=window.setInterval(()=>a(N2()),3e4);return()=>window.clearInterval(d)},[c]),i5e(r.data,s,n)}const o5e=f.forwardRef(function({label:t,...n},r){const i=M();return o.jsxs("button",{ref:r,type:"button",...n,className:`content-surface ${n.className??""}`,"aria-label":i.rlStatusAria,title:t,style:{width:"100%",height:34,padding:"0 12px",border:"1px solid var(--pill-waiting-bg)",background:"var(--pill-waiting-bg)",color:"var(--pill-waiting-fg)",borderRadius:"var(--r-control)",display:"flex",alignItems:"center",gap:8,cursor:"pointer",textAlign:"left",font:"550 12.5px var(--font-ui)"},children:[o.jsx("span",{"aria-hidden":"true",style:{width:7,height:7,borderRadius:"50%",background:"var(--pill-waiting-fg)",flex:"none"}}),o.jsx("span",{style:{flex:1,minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:t})]})});function s5e({status:e}){return e?o.jsx(o_,{trigger:o.jsx(o5e,{label:e.label}),side:"top",align:"center",children:o.jsx(ZH,{status:e})}):null}function a5e({status:e,onOpen:t}){const n=M();return e?o.jsx("button",{type:"button",className:"content-surface","aria-label":n.rlStatusAria,title:e.label,onClick:t,style:{border:`1px solid ${C.amberBorder}`,background:C.amberBg,color:C.amberText,borderRadius:"var(--r-pill)",padding:"3px 7px",maxWidth:190,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",font:`600 11px ${qn}`,cursor:"pointer"},children:e.label}):null}function l5e(e,t){return{border:`1px solid ${e?C.amberBorder:"var(--pill-waiting-bg)"}`,background:"transparent",color:e?C.amberText:"var(--pill-waiting-fg)",borderRadius:"var(--r-pill)",padding:"2px 8px",font:"600 11px 'IBM Plex Mono',monospace",cursor:t?"progress":"pointer",opacity:t?.6:1}}function c5e({provider:e,mobile:t=!1}){const n=M(),r=ve(),i=_e(),s=Se(r.system.clearRateLimit.mutationOptions({onSuccess:()=>void i.invalidateQueries(r.system.rateLimitStatus.queryFilter())})),a=s.isPending;return o.jsx("button",{type:"button",disabled:a,title:n.rlClearTitle,onClick:()=>s.mutate({provider:e}),style:l5e(t,a),children:a?n.rlClearing:n.rlClear})}function u5e(e){return e.provider.windows.map(t=>o.jsxs("div",{style:{display:"flex",flexWrap:"wrap",alignItems:"center",gap:10,marginTop:6,color:e.muted},children:[o.jsx("span",{style:{font:`600 11px ${qn}`},children:t.typeLabel}),o.jsxs("span",{style:{marginLeft:"auto",font:`500 11px ${qn}`},children:[t.countdown," ",e.recovers]})]},`${t.type}:${t.typeLabel}:${t.resetsAt}`))}function d5e(e){const{provider:t,index:n,mobile:r}=e,i=M(),s=r?C.muted:"var(--proto-muted)",a=r?C.hairline:"var(--proto-line)",l=r?C.amberText:"var(--pill-waiting-fg)";return o.jsxs("div",{style:{borderTop:n>0?`1px solid ${a}`:"none",paddingTop:n>0?9:0,marginTop:n>0?9:0},children:[o.jsxs("div",{style:{display:"flex",flexWrap:"wrap",alignItems:"baseline",gap:8},children:[o.jsx("span",{style:{fontSize:11,fontWeight:700},children:t.displayName}),o.jsxs("span",{style:{marginLeft:"auto",display:"flex",alignItems:"center",gap:8},children:[o.jsx(c5e,{provider:t.provider,mobile:r}),o.jsx("span",{style:{font:`600 11px ${qn}`,color:l},children:t.recoveryCountdown})]})]}),o.jsx("div",{style:{marginTop:4,color:s,font:`500 11px ${qn}`},children:t.waitingLabel}),o.jsx(u5e,{provider:t,recovers:i.rlRecovers,muted:s})]})}function ZH({status:e,mobile:t=!1}){const n=M(),r=t?C.ink:"var(--proto-ink)";return o.jsxs("div",{className:"content-surface",style:{minWidth:t?0:230,color:r},children:[o.jsx("div",{style:{fontSize:12,fontWeight:700,marginBottom:8},children:n.rlDetailsTitle}),e.providers.map((i,s)=>o.jsx(d5e,{provider:i,index:s,mobile:t},i.provider))]})}function f5e({status:e,onClose:t}){return o.jsx(Kn,{onClose:t,children:o.jsx("div",{style:{padding:"2px 18px 24px"},children:o.jsx(ZH,{status:e,mobile:!0})})})}function p5e({copy:e,busy:t,onAdd:n}){const[r,i]=f.useState(""),s=async a=>{a.preventDefault(),a.stopPropagation();const l=r.trim();!l||t||(await n(l),i(""))};return o.jsxs("form",{onSubmit:s,onClick:a=>a.stopPropagation(),style:{display:"flex",alignItems:"center",gap:8,marginTop:8,background:"var(--material-inset-bg)",borderRadius:"var(--r-control)",padding:"0 12px",minHeight:40,boxSizing:"border-box"},children:[o.jsx("svg",{width:"12",height:"12",viewBox:"0 0 14 14",fill:"none",stroke:C.muted,strokeWidth:"1.6",style:{flex:"none"},children:o.jsx("path",{d:"M9.8 1.8l2.4 2.4L4.6 11.8l-3 .6.6-3z"})}),o.jsx("input",{value:r,onChange:a=>i(a.target.value),placeholder:e.noteQuickPlaceholder,"aria-label":e.noteQuickPlaceholder,style:{flex:1,minWidth:0,border:0,outline:0,background:"transparent",fontSize:16,color:C.ink}})]})}function h5e({vm:e,busy:t,onOpen:n,onAdd:r}){const i=Z();return o.jsxs("div",{"data-mobile-notes-card":"",className:"m-press",onClick:n,style:{padding:"12px 14px",borderRadius:10,cursor:"pointer",minWidth:0},children:[o.jsxs("div",{style:{display:"flex",alignItems:"center",gap:7},children:[o.jsx("span",{style:{fontSize:14,fontWeight:600,color:C.ink},children:i.noteTitle}),o.jsx("span",{style:{fontSize:12,fontWeight:500,color:C.faint,...$e},children:e.activeCount}),o.jsx("span",{"aria-hidden":"true",style:{marginLeft:"auto",fontSize:17,lineHeight:1,color:C.faint},children:"›"})]}),e.previews.map(s=>o.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,marginTop:6},children:[o.jsx("span",{style:{width:13,height:13,borderRadius:"50%",border:`1.5px solid ${C.hairline}`,boxSizing:"border-box",flex:"none"}}),o.jsx("span",{style:{fontSize:13,lineHeight:1.5,color:C.sub,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:s.text})]},s.id)),o.jsx(p5e,{copy:i,busy:t,onAdd:r})]})}const JH={fill:"none",stroke:"currentColor",strokeWidth:1.8,strokeLinecap:"round",strokeLinejoin:"round"};function eU({label:e,onClick:t,children:n}){return o.jsx("button",{type:"button","aria-label":e,onClick:t,style:{display:"flex",alignItems:"center",justifyContent:"center",width:44,height:44,border:"none",background:"transparent",color:C.sub,cursor:"pointer",padding:0,flex:"none"},children:n})}function m5e({label:e,onClick:t}){return o.jsx(eU,{label:e,onClick:t,children:o.jsx("svg",{width:"19",height:"19",viewBox:"0 0 24 24","aria-hidden":"true",...JH,children:o.jsx("path",{d:YH("usage")})})})}function g5e({label:e,onClick:t}){return o.jsx(eU,{label:e,onClick:t,children:o.jsxs("svg",{width:"19",height:"19",viewBox:"0 0 24 24","aria-hidden":"true",...JH,children:[o.jsx("circle",{cx:"12",cy:"12",r:"3.2"}),o.jsx("path",{d:"M19.4 15a1.7 1.7 0 0 0 .34 1.87l.06.06a2 2 0 1 1-2.83 2.83l-.06-.06a1.7 1.7 0 0 0-1.87-.34 1.7 1.7 0 0 0-1 1.55V21a2 2 0 1 1-4 0v-.09a1.7 1.7 0 0 0-1-1.55 1.7 1.7 0 0 0-1.87.34l-.06.06a2 2 0 1 1-2.83-2.83l.06-.06a1.7 1.7 0 0 0 .34-1.87 1.7 1.7 0 0 0-1.55-1H3a2 2 0 1 1 0-4h.09a1.7 1.7 0 0 0 1.55-1 1.7 1.7 0 0 0-.34-1.87l-.06-.06a2 2 0 1 1 2.83-2.83l.06.06a1.7 1.7 0 0 0 1.87.34h.09a1.7 1.7 0 0 0 1-1.55V3a2 2 0 1 1 4 0v.09a1.7 1.7 0 0 0 1 1.55 1.7 1.7 0 0 0 1.87-.34l.06-.06a2 2 0 1 1 2.83 2.83l-.06.06a1.7 1.7 0 0 0-.34 1.87v.09a1.7 1.7 0 0 0 1.55 1H21a2 2 0 1 1 0 4h-.09a1.7 1.7 0 0 0-1.55 1z"})]})})}const tU=o.jsx("span",{"aria-hidden":"true",style:{marginLeft:"auto",fontSize:17,lineHeight:1,color:C.faint,flex:"none"},children:"›"}),nU={padding:"12px 14px",borderRadius:10,cursor:"pointer",minWidth:0};function v5e({current:e,copy:t}){return o.jsxs("div",{style:{display:"flex",alignItems:"center",gap:12},children:[o.jsx(WH,{text:e.initials,accent:!0,large:!0}),o.jsxs("div",{style:{minWidth:0,flex:1},children:[o.jsxs("div",{style:{display:"flex",alignItems:"center",gap:7},children:[o.jsx("span",{style:{fontSize:17,fontWeight:650,color:C.ink,minWidth:0,overflowWrap:"anywhere"},children:e.id}),o.jsx("span",{style:{fontSize:12,fontWeight:500,padding:"1px 7px",borderRadius:6,background:"var(--proto-gray)",color:C.muted,flex:"none"},children:t.projCurrent})]}),o.jsxs("div",{style:{fontSize:12,color:C.muted,marginTop:2,...$e},children:[e.needsYou," ",t.projNeedsYou]})]})]})}function x5e({cost:e,copy:t}){const n=FH(e.today,e.dailyBudget);return o.jsxs("div",{style:{marginTop:16,...$e},children:[o.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:6},children:[o.jsx("span",{style:{fontSize:26,fontWeight:650,color:C.ink,letterSpacing:"-.02em"},children:hr(e.today)}),o.jsxs("span",{style:{fontSize:12,color:C.muted},children:["/ ",hr(e.dailyBudget)," ",t.projPerDay]})]}),o.jsx("div",{style:{height:5,borderRadius:"var(--r-pill)",background:"var(--proto-line-2)",overflow:"hidden",marginTop:8},children:o.jsx("div",{style:{width:`${n??0}%`,height:"100%",borderRadius:"var(--r-pill)",background:C.run}})}),o.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"4px 14px",flexWrap:"wrap",marginTop:8,fontSize:12,color:C.muted},children:[o.jsxs("span",{children:[t.projWeek," ",o.jsx("b",{style:{fontWeight:600,color:C.body},children:hr(e.week)})]}),o.jsxs("span",{children:[t.projMonth," ",o.jsx("b",{style:{fontWeight:600,color:C.body},children:hr(e.month)})]}),o.jsxs("span",{style:{marginLeft:"auto",color:"var(--proto-amber-text)"},children:[t.projForecast," ",hr(e.forecastToday)]})]})]})}function y5e({current:e,copy:t}){return o.jsxs("div",{style:{padding:"4px 14px 2px"},children:[o.jsx(v5e,{current:e,copy:t}),e.cost&&o.jsx(x5e,{cost:e.cost,copy:t})]})}function b5e({pending:e,globalPending:t,copy:n,onClick:r}){return o.jsxs("div",{onClick:r,style:{display:"flex",alignItems:"center",gap:10,marginTop:16,background:C.amberBg,borderRadius:12,padding:"11px 14px",cursor:"pointer"},children:[o.jsx("span",{style:{width:7,height:7,borderRadius:"50%",background:C.amber,flex:"none"}}),o.jsxs("div",{style:{minWidth:0,flex:1},children:[o.jsxs("div",{style:{fontSize:14,fontWeight:600,color:"var(--proto-amber-fg)",...$e},children:[n.approvals," · ",e," ",n.projPending]}),t>0&&o.jsxs("div",{style:{fontSize:12,color:C.amberText,marginTop:1,...$e},children:[t," ",n.projGlobal]})]}),o.jsxs("span",{style:{fontSize:13,fontWeight:600,color:C.amberInk,flex:"none"},children:[n.projReview," ›"]})]})}function w5e({n:e}){return o.jsx("span",{style:{fontSize:12,fontWeight:500,color:C.faint,...$e},children:e})}function S5e({issues:e,copy:t,onClick:n}){const r=e.count-e.previews.length,i=Z();return o.jsxs("div",{className:"m-press",onClick:n,style:nU,children:[o.jsxs("div",{style:{display:"flex",alignItems:"center",gap:7},children:[o.jsx("span",{style:{fontSize:14,fontWeight:600,color:C.ink},children:t.issuesTitle}),o.jsx(w5e,{n:e.count}),tU]}),e.previews.map(s=>o.jsx("div",{style:{fontSize:13,lineHeight:1.5,color:C.sub,marginTop:4,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:s},s)),r>0&&o.jsx("div",{style:{fontSize:12,color:C.muted,marginTop:4,...$e},children:i.cmMoreCount.replace("{n}",String(r))})]})}function k5e({label:e,onClick:t}){return o.jsxs("div",{className:"m-press",onClick:t,style:{...nU,display:"flex",alignItems:"center"},children:[o.jsx("span",{style:{fontSize:14,fontWeight:600,color:C.ink},children:e}),tU]})}function j5e({props:e}){const t=Z(),{current:n,pendingApprovals:r,globalPendingApprovals:i,issues:s}=e;return o.jsxs(o.Fragment,{children:[n&&o.jsx(y5e,{current:n,copy:t}),r>0&&o.jsx(b5e,{pending:r,globalPending:i,copy:t,onClick:e.onApprovals}),o.jsxs(Xi,{style:{marginTop:14},children:[s.count>0&&o.jsx(S5e,{issues:s,copy:t,onClick:e.onIssues}),o.jsx(h5e,{vm:e.notesVm,busy:e.notesBusy,onOpen:e.onNotes,onAdd:e.onAddNote}),o.jsx(k5e,{label:t.projectMemory,onClick:e.onMemory})]})]})}function C5e({props:e}){const t=Z();return o.jsxs("section",{style:{marginTop:22},children:[e.switchRows.length>0&&o.jsx(Yx,{children:t.projSwitch}),o.jsxs(Xi,{inset:58,children:[e.switchRows.map(n=>o.jsx(rk,{row:n,onSwitch:e.onSwitch},n.id)),o.jsx(BH,{onClick:e.onNewProject})]})]})}function T5e(e){const t=Z(),n=o.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,minWidth:0},children:[o.jsx(a5e,{status:e.rateLimitStatus,onOpen:e.onOpenRateLimit}),o.jsxs("div",{style:{display:"flex",alignItems:"center",flex:"none"},children:[o.jsx(m5e,{label:t.stNavUsage,onClick:e.onUsage}),o.jsx(g5e,{label:t.settings,onClick:e.onSettings})]})]});return o.jsx(hl,{label:"1e projects",floatingHeader:!0,header:o.jsx(NW,{title:t.projTitle,trailing:n}),children:o.jsxs(kf,{gap:0,padding:SF,children:[o.jsx(j5e,{props:e}),o.jsx(C5e,{props:e})]})})}function Rj(e){const t=ve(),n=_e(),r=f.useRef(e);r.current=e;const i=h=>n.invalidateQueries(t.notes.list.queryFilter({projectId:h})),s=(h,m,v)=>i(v.projectId),a=xe({...t.notes.list.queryOptions({projectId:e}),enabled:!!e}),l=Se(t.notes.add.mutationOptions({onSettled:s})),c=Se(t.notes.update.mutationOptions({onSettled:s})),u=Se(t.notes.setCompleted.mutationOptions({onSettled:s})),d=Se(t.notes.delete.mutationOptions({onSettled:s})),p=Se(t.notes.clearCompleted.mutationOptions({onSettled:s}));return{notes:a.data??[],busy:l.isPending||c.isPending||u.isPending||d.isPending||p.isPending,add:h=>l.mutateAsync({projectId:r.current,text:h}),update:(h,m)=>c.mutateAsync({projectId:r.current,id:h,text:m}),setCompleted:(h,m)=>u.mutateAsync({projectId:r.current,id:h,completed:m}),delete:async h=>{await d.mutateAsync({projectId:r.current,id:h})},clearCompleted:async()=>{await p.mutateAsync({projectId:r.current})}}}function E5e(e,t){return e===1?t.noteYesterday:G(t.noteDaysAgo,{n:Math.max(2,e)})}function R5e(e,t){return e.getFullYear()===t.getFullYear()&&e.getMonth()===t.getMonth()&&e.getDate()===t.getDate()}function M5e(e){const t=String(e.getHours()).padStart(2,"0"),n=String(e.getMinutes()).padStart(2,"0");return`${t}:${n}`}function A5e(e,t,n){const r=Date.parse(e);if(Number.isNaN(r))return"—";const i=new Date(r);if(R5e(i,new Date(t)))return M5e(i);const s=Math.max(1,Math.floor((t-r)/864e5));return E5e(s,n)}function P5e(e,t,n){return{...e,timeLabel:A5e(e.createdAt,t,n)}}function rU(e,t,n){const r=e.map(a=>P5e(a,t,n)),i=r.filter(a=>!a.completed),s=r.filter(a=>a.completed);return{active:i,completed:s,previews:i.slice(0,3),activeCount:i.length,completedCount:s.length}}function I5e(e){return(e.metaKey||e.ctrlKey)&&e.shiftKey&&!e.altKey&&e.key.toLowerCase()==="n"}const iU=380,L5e=8,ev=12,oU={top:56,right:ev};function N5e(e,t){if(!t)return oU;const n=Math.max(ev,e.width-iU-ev),r=Math.min(n,Math.max(ev,e.right-t.right));return{top:Math.round(t.bottom-e.top+L5e),right:Math.round(r)}}function sU(e,t,n){const r=rU(e,t,n);return{...r,previews:r.active.slice(0,2)}}function D5e(e){const t=ve();return{projects:xe({...t.projects.list.queryOptions({}),refetchOnMount:!1}).data??[],sessions:Zi("direct").data??[],scopedCost:xe({...t.cost.summary.queryOptions({projectId:e||void 0}),enabled:!!e}).data??null,globalCost:xe(t.cost.summary.queryOptions({})).data,approvals:xe(t.approvals.list.queryOptions({status:"pending"})).data??[],issues:xe({...t.issues.list.queryOptions({projectId:e}),enabled:!!e}).data??[]}}function O5e(e,t,n){return f.useMemo(()=>e?{id:e,initials:dH(e),needsYou:n,cost:t.scopedCost}:null,[e,n,t.scopedCost])}function F5e({rate:e,rateOpen:t,closeRate:n,project:r}){return o.jsxs(o.Fragment,{children:[t&&e&&o.jsx(f5e,{status:e,onClose:n}),o.jsx(qH,{project:r})]})}function _5e(){const e=XH(),[t,n]=f.useState(!1);return f.useEffect(()=>{e||n(!1)},[e]),{rate:e,rateOpen:t,setRateOpen:n}}function z5e(){var w;const e=qe(),t=M(),{currentProjectId:n,setCurrentProject:r}=Wt(),i=n??"",s=D5e(i),{notes:a,busy:l,add:c}=Rj(i),u=f.useMemo(()=>sU(a,Date.now(),t),[a,t]),d=f.useMemo(()=>$H(s.approvals),[s.approvals]),p=i?d.byProject[i]??0:0,h=O5e(i,s,p),m=HH(i,{projects:s.projects,sessions:s.sessions,globalByProject:(w=s.globalCost)==null?void 0:w.byProject,approvalsByProject:d.byProject}),{rate:v,rateOpen:g,setRateOpen:x}=_5e(),y=VH(e,r),b=f.useMemo(()=>({count:s.issues.length,previews:s.issues.slice(0,2).map(R=>R.title)}),[s.issues]),S=R=>{r(R),WW(!1,e)},j={current:h,pendingApprovals:p+d.global,globalPendingApprovals:d.global,issues:b,notesVm:u,notesBusy:l,switchRows:m,rateLimitStatus:v,onOpenRateLimit:()=>x(!0),onIssues:()=>e("/m/issues"),onNotes:()=>e("/m/notes"),onAddNote:c,onApprovals:()=>e("/m/approvals"),onMemory:()=>e("/m/memory"),onUsage:()=>e("/m/settings/usage",{state:{from:"project"}}),onSettings:()=>e("/m/settings"),onSwitch:S,onNewProject:y.show};return o.jsxs(o.Fragment,{children:[o.jsx(T5e,{...j}),o.jsx(F5e,{rate:v,rateOpen:g,closeRate:()=>x(!1),project:y})]})}function W5e(e,t,n){const r=ve(),i=hy();gH();const s=Ga(e,"direct"),a=Ga(e,"scheduled"),l=xe(r.schedules.list.queryOptions({projectId:e??void 0})),c=f.useMemo(()=>i4e(e,s.data??[],a.data??[],l.data??[],Date.now(),t,n,i),[e,s.data,a.data,l.data,t,n,i]);return{loading:s.isLoading,...c}}function B5e(e,t){const n=TH();if(e)return{projectId:e,rows:t,expanded:!n.collapsed.has(e),onToggle:()=>n.toggle(e)}}function $5e(e){const t=qe(),{currentProjectId:n,setCurrentProject:r}=Wt(),i=VH(t,r),s=()=>e(null);return{currentProjectId:n,newProject:i,close:s,pick:c=>{r(c),s()},createNew:()=>{s(),i.show()}}}function H5e({sheet:e,setSheet:t,scheduleRows:n,switcher:r}){const i=qe(),s=a=>{t(null),i(`/m/session/${a}`,{replace:!0})};return o.jsxs(o.Fragment,{children:[e==="schedule"&&o.jsx(TSe,{rows:n,onOpenSession:s,onClose:()=>t(null)}),e==="projects"&&o.jsx(Rke,{currentProjectId:r.currentProjectId,onPick:r.pick,onNewProject:r.createNew,onClose:r.close}),o.jsx(qH,{project:r.newProject})]})}function U5e(){const e=qe(),t=Gx(_n().pathname),n=f.useRef(t==="projects");t!==null&&(n.current=t==="projects");const r=f.useCallback(i=>WW(i,e),[e]);return{open:n.current,setOpen:r}}function V5e(e){const[t,n]=f.useState(e);return f.useEffect(()=>{if(t)return;if(e){n(!0);return}const r=window.setTimeout(()=>n(!0),300);return()=>window.clearTimeout(r)},[t,e]),t||e}function q5e(){var t;const e=ve();return((t=xe(e.approvals.list.queryOptions({status:"pending"})).data)==null?void 0:t.length)??0}function rM({panel:e,children:t}){const n=M().projTitle,r=V5e(e.open);return o.jsx(Kke,{open:e.open,onOpenChange:e.setOpen,panelLabel:n,panel:r?o.jsx(z5e,{}):null,children:t})}function iM(){const e=qe(),t=Qe(),n=M(),r=O0(),[i,s]=f.useState(null),a=$5e(s),{loading:l,rows:c,starredRows:u,scheduleRows:d}=W5e(a.currentProjectId,t,n),p=B5e(a.currentProjectId,u),h=U5e(),m=q5e();if(l)return o.jsx(rM,{panel:h,children:o.jsx(hl,{label:"1a sessions",children:o.jsx("div",{style:{padding:16,color:C.muted,fontSize:13},children:n.slEmpty})})});const v=d.length>0?{unread:mH(d),onOpen:()=>s("schedule")}:void 0,g={name:a.currentProjectId,switchLabel:n.projSwitch,onSwitch:()=>s("projects")};return o.jsxs(rM,{panel:h,children:[o.jsx(b4e,{rows:c,stars:p,presence:r,project:g,projects:{needsYou:m,onOpen:()=>h.setOpen(!0)},newLabel:n.wbNewSession,scheduled:v,onOpen:x=>e(`/m/session/${x}`),onNew:()=>e("/m/session/new")}),o.jsx(H5e,{sheet:i,setSheet:s,scheduleRows:d,switcher:a})]})}function K5e(e){var n,r;const t=e.role==="tool";return{type:e.role,...e.blockId?{blockId:e.blockId}:{},text:t?null:e.text??"",toolName:t?e.toolName??"":null,toolInput:t?e.toolInput??"":null,...t&&e.toolDevice?{toolDevice:e.toolDevice}:{},...t&&e.teamAction?{teamAction:e.teamAction}:{},...t&&e.boardAction?{boardAction:e.boardAction}:{},...e.role==="worker-progress"&&e.worker?{worker:e.worker}:{},ts:e.ts,elapsedMs:null,attachments:e.attachments,...e.systemOrigin?{systemOrigin:e.systemOrigin}:{},...(n=e.decisions)!=null&&n.length?{decisions:e.decisions}:{},...e.noticeLevel?{noticeLevel:e.noticeLevel}:{},...e.noticeAction?{noticeAction:e.noticeAction}:{},...e.authAction?{authAction:e.authAction}:{},...e.subagentId?{subagentId:e.subagentId}:{},...(r=e.subagentSpawns)!=null&&r.length?{subagentSpawns:e.subagentSpawns}:{},...e.subagentType?{subagentType:e.subagentType}:{},...e.subagentDescription?{subagentDescription:e.subagentDescription}:{},...e.subagentModel?{subagentModel:e.subagentModel}:{},...e.subagentEnded?{subagentEnded:e.subagentEnded}:{},...e.subagentClean?{subagentClean:!0}:{}}}function G5e(e,t){const{messageTs:n,pendingId:r}=t;if(!r&&!n)return{pending:e,committed:null};const i=r?e.findIndex(a=>a.id===r):e.findIndex(a=>a.ts===n);if(i===-1)return{pending:e,committed:null};const s=e[i];return{pending:e.filter((a,l)=>l!==i),committed:{sessionId:t.sessionId??"",role:"user",text:s.text,ts:t.committedTs||s.ts,attachments:s.attachments,...s.systemOrigin?{systemOrigin:s.systemOrigin}:{}}}}function Y5e(e,t,n){if(!t)return e;if(t.pendingUserMessages!==void 0)return t.pendingUserMessages.filter(s=>!(n!=null&&n.has(s.id))).map(s=>({...s}));if(e.length===0)return e;const r=[];for(const s of t.turns)for(const a of s.messages)a.type==="user"&&r.push({text:a.text??"",ts:a.ts});const i=[];for(const s of e){const a=r.findIndex(l=>l.text===s.text&&l.ts>=s.ts);a===-1?i.push(s):r.splice(a,1)}return i.length===e.length?e:i}const aU=/^<\/?system-reminder>$/i;function Mj(e,t){switch(e){case"resume":return t.chatSystemOriginResume;case"task-callback":return t.chatSystemOriginTaskCallback;case"thread-callback":return t.chatSystemOriginThreadCallback;case"subtask-question":return t.chatSystemOriginSubtaskQuestion;case"agent-result":return t.chatSystemOriginAgentResult;case"external-signal":return t.chatSystemOriginExternalSignal;case"team-lead":return t.chatSystemOriginTeamLead;case"worker-result":return t.chatSystemOriginWorkerResult;case"worker-question":return t.chatSystemOriginWorkerQuestion;case"scheduled":return t.chatSystemOriginScheduled;case"background-task":return t.chatSystemOriginBackgroundTask;default:return Q5e(e,t)}}function Q5e(e,t){return t.chatSystemOriginGeneric}function Ud(e){switch(e){case"team-lead":case"scheduled":return"bubble";case"worker-result":case"worker-question":return"expandable";default:return"hint"}}const X5e=/^\[Unread routine updates\]$/;function lU(e){const t=(e??"").split(`
424
424
  `).filter(r=>!aU.test(r.trim())),n=t.findIndex(r=>X5e.test(r.trim()));return(n>=0?t.slice(0,n):t).join(`
425
425
  `).trim()}function Z5e(e,t=80){const n=(e??"").split(`
@@ -494,7 +494,7 @@ ${e.done}`,style:{flex:1},children:[e.done?o.jsx("span",{style:D8e,children:e.do
494
494
  if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', watch);
495
495
  else watch();
496
496
  })();
497
- `.trim();function ug(e){return(e??"").replace(/<\/style/gi,"<\\/style")}function REe(e){const t=e.pendingContent.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;"),n=e.body.replaceAll("{{boardPendingContent}}",()=>t),r=`:root{color-scheme:${e.theme}}html,body{background:transparent}html{overflow:hidden}`;return`<!DOCTYPE html><html><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><meta http-equiv="Content-Security-Policy" content="${s$()}"><style data-board-layer="theme">${r}${ug(e.themeCss)}</style>`+(e.mathCss?`<style data-board-layer="math">${ug(e.mathCss)}</style>`:"")+`<style data-board-layer="preset">${ug(e.defaultCss)}</style>`+(e.userCss?`<style data-board-layer="user">${ug(e.userCss)}</style>`:"")+`<script>${EEe}<\/script></head><body>${n}</body></html>`}const MEe=240;function AEe({srcDoc:e,title:t,onOpen:n,onLink:r}){const i=f.useRef(null),[s,a]=f.useState(MEe),l=f.useRef({onOpen:n,onLink:r});return l.current={onOpen:n,onLink:r},f.useEffect(()=>{const c=u=>{if(!i.current||u.source!==i.current.contentWindow)return;const d=TEe(u.data);d&&(d.type==="height"?a(Math.max(d.value,1)):d.type==="open"?l.current.onOpen(d.path):l.current.onLink(d.href))};return window.addEventListener("message",c),()=>window.removeEventListener("message",c)},[]),o.jsx("iframe",{ref:i,title:t,sandbox:i$,srcDoc:e,referrerPolicy:"no-referrer","data-board-frame":"",style:{display:"block",width:"100%",height:s,border:0,background:"transparent"}})}const w1={minWidth:0,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},PEe=120;function IEe(e){switch(or(e)){case"idle":case"waiting":return Na(e,8);case"running":return{...Na(e,7),animation:"cxring 1.8s ease-out infinite"};case"you":return Na(e,7)}}function LEe(e,t,n){const r=Date.parse(e.lastUsedAt);return Number.isNaN(r)?null:_c(t-r,n)}function VM({tone:e,expanded:t,onClick:n,children:r,data:i}){return o.jsxs("button",{type:"button",className:`${ye} group/strip-link`,onClick:s=>{s.stopPropagation(),n()},"aria-expanded":t,[i]:"",style:{flex:"none",display:"inline-flex",alignItems:"center",gap:4,height:24,padding:"0 3px",margin:"0 -3px",border:0,borderRadius:4,background:"transparent",cursor:"pointer",whiteSpace:"nowrap",fontFamily:"inherit",fontSize:12.5,fontWeight:550,fontVariantNumeric:"tabular-nums",color:e==="ask"?"var(--proto-amber-fg)":"var(--proto-accent)"},children:[o.jsx("span",{className:"group-hover/strip-link:underline underline-offset-[3px]",children:r}),o.jsx("span",{"aria-hidden":"true",style:{display:"inline-block",fontSize:14,lineHeight:1,transition:"transform .15s ease",transform:t?"rotate(90deg)":"none"},children:"›"})]})}function NEe({session:e,now:t,onOpen:n}){const r=M(),i=Qe(),s=`${Tc(e)} · ${Cj(e,t,r,i)}`,a=LEe(e,t,i);return o.jsxs("button",{type:"button",className:ye,"data-board-session":e.sessionId,onClick:()=>n(e),title:s,"aria-label":s,style:{flex:"1 1 0",minWidth:PEe,maxWidth:"max-content",display:"inline-flex",alignItems:"center",gap:6,height:24,padding:"0 3px",margin:"0 -3px",border:0,borderRadius:4,background:"transparent",cursor:"pointer",fontFamily:"inherit",fontSize:12.5,color:"var(--proto-faint)"},children:[o.jsx("span",{style:IEe(e),"data-board-dot":or(e)}),o.jsx("span",{style:{...w1,fontWeight:550,color:"var(--proto-ink-3)",maxWidth:160},children:Tc(e)}),a&&o.jsx("span",{style:{flex:"none",whiteSpace:"nowrap",fontVariantNumeric:"tabular-nums"},children:a})]})}function DEe({sessions:e,onOpen:t}){const n=n7(e);return o.jsx("div",{"data-board-pending-list":"",onClick:r=>r.stopPropagation(),style:{position:"absolute",right:0,top:28,width:300,maxHeight:280,overflowY:"auto",zIndex:20,padding:4,boxSizing:"border-box",border:"1px solid var(--proto-line)",borderRadius:"var(--r-card)",...io},children:e.map(r=>o.jsxs("button",{type:"button",className:ye,onClick:()=>t(r),style:{display:"flex",flexDirection:"column",alignItems:"stretch",gap:2,width:"100%",padding:"6px 8px",border:0,borderRadius:"var(--r-chip)",background:"transparent",cursor:"pointer",textAlign:"left",fontFamily:"inherit"},onMouseEnter:i=>{i.currentTarget.style.background="var(--proto-gray)"},onMouseLeave:i=>{i.currentTarget.style.background="transparent"},children:[o.jsxs("span",{style:{display:"flex",alignItems:"center",gap:6,fontSize:12.5,color:"var(--proto-ink)"},children:[o.jsx("span",{style:Na(r,7)}),o.jsx("span",{style:w1,children:Tc(r)})]}),n[r.sessionId]&&o.jsx("span",{style:{...w1,fontSize:12,color:"var(--proto-muted)",paddingLeft:13},children:n[r.sessionId]})]},r.sessionId))})}function OEe(e){const t=M(),{board:n,showTitle:r=!0,gutter:i=20}=e,s=bl(!0,3e4),[a,l]=f.useState(!1),c=f.useCallback(()=>l(!1),[]);Nc(a,c,c);const{shown:u,pending:d}=Ey(e.sessions),p=()=>{d.length===1?e.onOpenSession(d[0]):l(h=>!h)};return o.jsxs("div",{"data-board-strip":"",style:{flex:"none",padding:`6px ${i}px`,borderBottom:"1px solid var(--proto-line)"},children:[r&&o.jsxs("div",{"data-board-strip-title":"",style:{display:"flex",alignItems:"center",gap:8,minWidth:0,padding:"4px 0 2px"},children:[o.jsx(Pf,{stroke:My[Ry(d.length)]}),o.jsx("span",{title:n.title,style:{...w1,fontSize:13.5,fontWeight:600,color:"var(--proto-ink)"},children:n.title})]}),o.jsxs("div",{style:{display:"flex",alignItems:"flex-start",gap:16,minWidth:0},children:[o.jsx("div",{style:{flex:1,minWidth:0,display:"flex",alignItems:"center",flexWrap:"wrap",gap:"2px 16px",minHeight:28},children:u.length===0?o.jsx("span",{style:{fontSize:12.5,color:"var(--proto-muted)"},children:t.boardNoSessions}):u.map(h=>o.jsx(NEe,{session:h,now:s,onOpen:e.onOpenSession},h.sessionId))}),o.jsxs("span",{style:{flex:"none",height:28,display:"flex",alignItems:"center",gap:14,position:"relative"},children:[d.length>0&&o.jsx(VM,{tone:"ask",data:"data-board-pending",expanded:a,onClick:p,children:G(t.boardNeedsYou,{n:d.length})}),o.jsx(VM,{tone:"accent",data:"data-board-decisions",expanded:e.decisionsOpen,onClick:e.onToggleDecisions,children:G(t.boardDecisions,{n:e.decisionCount})}),a&&d.length>1&&o.jsx(DEe,{sessions:d,onOpen:h=>{l(!1),e.onOpenSession(h)}})]})]})]})}const Rq=2*1024*1024,FEe=16*1024*1024,_Ee=64,Mq=/<(img|source|video|audio|image|input|track)\b[^>]*>/gi,Aq=/(\s(?:src|poster|href|xlink:href)\s*=\s*)(?:"([^"]*)"|'([^']*)')/gi,Pq=/url\(\s*(?:"([^"]*)"|'([^']*)'|([^'")\s]+))\s*\)/gi,Iq=/<!--[\s\S]*?(?:-->|$)/g;function Lq(e,t){let n="",r=0;for(const i of e.matchAll(Iq))n+=t(e.slice(r,i.index))+i[0],r=i.index+i[0].length;return n+t(e.slice(r))}function zEe(e,t){const n=e.replace(Iq,"");for(const r of n.matchAll(Mq))for(const i of r[0].matchAll(Aq))t(i[2]??i[3]??"");for(const r of n.matchAll(Pq))t(r[1]??r[2]??r[3]??"")}function WEe(e,t){const n=new Set;return zEe(e,r=>{const i=Ay(t,r);i&&n.add(i)}),[...n]}const BEe=/^<(?:img|video|source)\b/i,$Ee=/\ssrc\s*=\s*(?:"([^"]*)"|'([^']*)')/i;function HEe(e,t,n){if(!BEe.test(e))return"";const r=e.match($Ee),i=r?r[1]??r[2]??"":"",s=Ay(t,i);if(!s)return"";const a=` data-board-src="${i.replace(/"/g,"&quot;")}"`;return n.has(s)?a:`${a} data-board-missing=""`}function UEe(e,t,n){const r=s=>{const a=Ay(t,s);return a?n.get(a)??null:null},i=s=>{const a=HEe(s,t,n),l=s.replace(Aq,(c,u,d,p)=>{const h=r(d??p??"");return h?`${u}"${h}"`:c});return a?l.replace(/^<[a-z]+/i,c=>c+a):l};return Lq(e,s=>s.replace(Mq,i).replace(Pq,(a,l,c,u)=>{const d=r(l??c??u??"");return d?`url("${d}")`:a}))}function VEe(e){let t="";for(let r=0;r<e.length;r+=32768)t+=String.fromCharCode(...e.subarray(r,r+32768));return btoa(t)}function qEe(e,t){const n=new Map;let r=0;return e.forEach((i,s)=>{const a=t[s];if(!a||a.bytes.byteLength>Rq||(r+=a.bytes.byteLength,r>FEe))return;const l=a.mime.split(";")[0].trim()||"application/octet-stream";n.set(i,`data:${l};base64,${VEe(a.bytes)}`)}),n}async function KEe(e,t,n){const r=WEe(e,t).slice(0,_Ee);if(r.length===0)return e;const i=await Promise.all(r.map(s=>n(s,Rq).catch(()=>null)));return UEe(e,t,qEe(r,i))}const GEe=String.raw`\sclass\s*=\s*(?:"(?:[^"]*\s)?tex(?:\s[^"]*)?"|'(?:[^']*\s)?tex(?:\s[^']*)?'|tex(?=[\s/>]))`,Nq=String.raw`<(span|div)\b(?=[^>]*${GEe})([^>]*)>([\s\S]*?)<\/\1\s*>`,YEe=/<!--[\s\S]*?(?:-->|$)/g,QEe={throwOnError:!1,trust:!1,maxExpand:1e3,maxSize:50},XEe={lt:"<",gt:">",amp:"&",quot:'"',apos:"'",nbsp:" "},ZEe=/&(?:(lt|gt|amp|quot|apos|nbsp)|#(\d+)|#x([0-9a-f]+));/gi;function JEe(e){return e.replace(ZEe,(t,n,r,i)=>{if(n)return XEe[n.toLowerCase()]??t;const s=r?Number(r):parseInt(i,16);return s>0&&s<=1114111?String.fromCodePoint(s):t})}function eRe(e,t,n,r){try{const i=VB.renderToString(JEe(r),{...QEe,displayMode:t.toLowerCase()==="div"});return`<${t}${n}>${i}</${t}>`}catch{return e}}function tRe(e){return new RegExp(Nq,"i").test(e.replace(YEe,""))}function nRe(e){const t=new RegExp(Nq,"gi");return Lq(e,n=>n.replace(t,eRe))}const rRe=/src:url\(fonts\/(KaTeX_[\w-]+)\.woff2\)[^;}]*/g;function Qlt(e,t){return e.replace(rRe,(n,r)=>{const i=t[r];return i?`src:url(${i}) format("woff2")`:n})}const iRe=120;async function oRe(e,t,n){var s;const r=await fetch(qW(e,t,"inline"),{headers:Io(),cache:"no-cache"});if(!r.ok)return await((s=r.body)==null?void 0:s.cancel().catch(()=>{})),null;const i=await a$(r,n);return i.kind==="ok"?{mime:r.headers.get("content-type")??"",bytes:i.bytes}:null}function sRe(){return document.documentElement.getAttribute("data-theme")==="dark"?"dark":"light"}function aRe(){const[e,t]=f.useState(0);return f.useEffect(()=>{var a,l;let n=null;const r=()=>{n&&clearTimeout(n),n=setTimeout(()=>t(c=>c+1),iRe)},i=new MutationObserver(r);i.observe(document.documentElement,{attributes:!0});const s=(a=window.matchMedia)==null?void 0:a.call(window,"(prefers-color-scheme: dark)");return(l=s==null?void 0:s.addEventListener)==null||l.call(s,"change",r),()=>{var c;n&&clearTimeout(n),i.disconnect(),(c=s==null?void 0:s.removeEventListener)==null||c.call(s,"change",r)}},[]),e}async function lRe(e,t,n){const r=await KEe(e,n,(s,a)=>oRe(t,s,a)).catch(()=>e);if(!tRe(r))return{html:r,mathCss:null};const i=await Wc(()=>import("./board-math-css-BmiXB1z5.js"),[]).then(s=>s.BOARD_MATH_CSS).catch(()=>null);return{html:nRe(r),mathCss:i}}function cRe({projectId:e,slug:t,body:n,refresh:r}){const[i,s]=f.useState(null);return f.useEffect(()=>{if(n===null||!e||!t)return;let a=!1;return lRe(n,e,t).then(l=>{a||s(l)}),()=>{a=!0}},[n,e,t,r]),i}function uRe(e){const{body:t,style:n}=e,r=cRe(e),{boardPendingContent:i}=M(),s=aRe(),a=f.useMemo(()=>wEe(n==null?void 0:n.defaultCss,n==null?void 0:n.userCss,t),[n==null?void 0:n.defaultCss,n==null?void 0:n.userCss,t]),l=f.useMemo(()=>({css:jEe(a,document.documentElement),mode:sRe()}),[a,s]);return f.useMemo(()=>r===null||n===null?null:REe({themeCss:l.css,mathCss:r.mathCss,defaultCss:n.defaultCss,userCss:n.userCss,body:r.html,pendingContent:i,theme:l.mode}),[r,n,l,i])}const xk={display:"flex",alignItems:"center",justifyContent:"center",minHeight:120,padding:20,color:"var(--proto-muted)",fontSize:12.5,textAlign:"center"},dRe="color-mix(in srgb, var(--proto-card) 78%, transparent)";function fRe(e,t){const{openMedia:n}=ml(),{openDoc:r}=Uc();return f.useCallback(i=>{const s=Ay(t,i);if(!s)return;const a=_Te(s),l=bge(e,s),c=BTe(a);if(c)return n({kind:c,name:a,path:l});const u=nj(a);if(u)return r({kind:u,name:a,path:l});o1(l,a).catch(()=>{})},[e,t,n,r])}function pRe(e){bt()?Ka(e).catch(()=>{}):window.open(e,"_blank","noopener,noreferrer")}function hRe({files:e,onOpen:t}){const n=M();return o.jsxs("div",{style:{...xk,flexDirection:"column",gap:8},"data-board-empty":"",children:[o.jsx("span",{children:n.boardNoBody}),e.length>0&&o.jsx("span",{style:{display:"flex",gap:12},children:e.map(r=>o.jsx("button",{type:"button","data-board-file":r,onClick:()=>t(r),style:{border:0,padding:0,background:"transparent",cursor:"pointer",fontFamily:"inherit",fontSize:12.5,fontWeight:500,color:"var(--proto-accent)"},children:r},r))})]})}function Dq({boardId:e,onOpenSession:t,touch:n,showTitle:r=!0}){const i=M(),s=HTe(e),[a,l]=f.useState(!1),[c,u]=f.useState(0);sbe(f.useCallback(x=>{x===e&&u(y=>y+1)},[e]));const{board:d}=s,p=n?16:20,h=(d==null?void 0:d.projectId)??"",m=(d==null?void 0:d.slug)??"",v=fRe(h,m),g=uRe({projectId:h,slug:m,body:s.body.kind==="body"?s.body.html:null,style:s.style,refresh:c});return d?o.jsxs("div",{"data-board-view":e,style:{flex:1,minHeight:0,display:"flex",flexDirection:"column"},children:[o.jsx(OEe,{board:d,sessions:s.sessions,decisionCount:s.decisions.length,decisionsOpen:a,onToggleDecisions:()=>l(x=>!x),onOpenSession:t,showTitle:r,gutter:p}),a&&o.jsx(yEe,{decisions:s.decisions,touch:n}),o.jsx("div",{"data-board-scroll":"",style:{flex:1,minHeight:0,overflowY:"auto",background:dRe,padding:n?"18px 16px 28px":"24px 28px 32px"},children:s.body.kind==="empty"?o.jsx(hRe,{files:s.body.files,onOpen:v}):g===null?o.jsx("div",{style:xk,children:i.boardLoading}):o.jsx(AEe,{srcDoc:g,title:d.title,onOpen:v,onLink:pRe})})]}):o.jsx("div",{style:xk,children:s.missing?i.boardMissing:i.boardLoading})}const mRe={position:"absolute",inset:0,zIndex:12,display:"flex",flexDirection:"column",pointerEvents:"auto",background:C.backdrop,paddingTop:"env(safe-area-inset-top)",paddingBottom:"env(safe-area-inset-bottom)",boxSizing:"border-box"},gRe={minWidth:0,fontSize:15.5,fontWeight:620,color:C.ink,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"};function vRe({boardId:e,onClose:t,onOpenSession:n}){const r=Z(),i=uq(e)??r.boardTitle;return kx(t),o.jsx(G3,{children:o.jsxs("div",{"data-board-sheet":e,style:mRe,children:[o.jsxs("div",{style:{flex:"none",height:48,display:"flex",alignItems:"center",gap:6,padding:"0 12px 0 4px",minWidth:0},children:[o.jsx("button",{type:"button","aria-label":r.back,onClick:t,style:{width:44,height:44,border:0,padding:0,background:"transparent",cursor:"pointer",display:"grid",placeItems:"center",color:C.ink},children:o.jsx(Ds,{})}),o.jsx("span",{"data-board-sheet-title":"",style:gRe,children:i})]}),o.jsx(Dq,{boardId:e,touch:!0,showTitle:!1,onOpenSession:s=>{t(),n(s)}})]})})}const xRe=10;function yRe(e){const t=atob(e),n=new Uint8Array(new ArrayBuffer(t.length));for(let r=0;r<t.length;r++)n[r]=t.charCodeAt(r);return n}function bRe({sessionId:e,enabled:t,boxRef:n,canvasRef:r}){const[i,s]=f.useReducer(XTe,QTe),a=f.useRef(null),l=f.useRef(null),c=f.useRef(null),u=f.useCallback(()=>{const v=n.current,g=l.current,x=c.current;return!v||!x?{x:0,y:0,width:0,height:0}:UTe(v.clientWidth,v.clientHeight,(g==null?void 0:g.width)??x.deviceWidth,(g==null?void 0:g.height)??x.deviceHeight)},[n]),d=f.useCallback(()=>{const v=n.current,g=r.current,x=l.current;if(!v||!g)return;const y=globalThis.devicePixelRatio||1,b=Math.max(1,Math.round(v.clientWidth*y)),S=Math.max(1,Math.round(v.clientHeight*y));g.width!==b&&(g.width=b),g.height!==S&&(g.height=S);const j=g.getContext("2d");if(!j||(j.clearRect(0,0,b,S),!x))return;const w=u();j.imageSmoothingQuality="high",j.drawImage(x,w.x*y,w.y*y,w.width*y,w.height*y)},[n,r,u]);f.useEffect(()=>{const v=n.current;if(!v||typeof ResizeObserver>"u")return;const g=new ResizeObserver(()=>d());return g.observe(v),()=>g.disconnect()},[n,d]),f.useEffect(()=>{if(!t){s({type:"stop"});return}let v=!1,g=0,x=null;const y=()=>{v||(g+=1,s({type:"drop"}),x=setTimeout(()=>void S(),ZTe(g)))},b=async(j,w,R,T)=>{var P;let A=null;try{A=await createImageBitmap(new Blob([yRe(R)],{type:"image/jpeg"}))}catch{}if(v||j!==a.current){A==null||A.close();return}if(A){(P=l.current)==null||P.close(),l.current=A;const L=c.current;c.current=T,d(),g=0,(!L||L.deviceWidth!==T.deviceWidth||L.deviceHeight!==T.deviceHeight)&&s({type:"frame",meta:T})}j.readyState===WebSocket.OPEN&&j.send(JSON.stringify({type:"ack",seq:w}))},S=async()=>{if(v)return;s({type:"connect"});let j;try{j=await l9e(e)}catch{y();return}if(v)return;const w=new WebSocket(u9e(e,j,xRe));a.current=w,w.onopen=()=>{v||s({type:"open"})},w.onmessage=R=>{if(typeof R.data!="string")return;const T=JTe(R.data);T&&(T.type==="frame"?b(w,T.seq,T.data,T.meta):s(T))},w.onclose=()=>{a.current===w&&(a.current=null),y()}};return S(),()=>{v=!0,x&&clearTimeout(x);const j=a.current;a.current=null,j&&(j.onclose=null,j.close())}},[t,e,d]),f.useEffect(()=>()=>{var v;(v=l.current)==null||v.close(),l.current=null,c.current=null},[e]);const p=f.useCallback(v=>{const g=a.current;g&&g.readyState===WebSocket.OPEN&&g.send(JSON.stringify(v))},[]),h=f.useCallback(()=>c.current,[]),m=f.useCallback(v=>s({type:"takeover",...v}),[]);return{view:i,send:p,frameRect:u,frameMeta:h,noteTakeover:m}}function wRe(){const[e,t]=f.useState(()=>typeof document>"u"||document.visibilityState!=="hidden");return f.useEffect(()=>{const n=()=>t(document.visibilityState!=="hidden");return document.addEventListener("visibilitychange",n),()=>document.removeEventListener("visibilitychange",n)},[]),e}function Oq({sessionId:e,visible:t,readOnly:n=!1}){const r=M(),i=wRe(),s=t7(e,{viewing:t&&i}),a=d9e(),l=f.useRef(null),c=f.useRef(null),u=bRe({sessionId:e,enabled:t&&(i||!n&&(s==null?void 0:s.takenOver)===!0)&&(s==null?void 0:s.state)==="ready",boxRef:l,canvasRef:c}),[d,p]=f.useState(null),h=u.view.takeover,m=!n&&((h==null?void 0:h.takenOver)??(s==null?void 0:s.takenOver)??!1)&&((h==null?void 0:h.mine)??!0),v=t9e(s,u.view),g=h==null?void 0:h.takenOver,x=s==null?void 0:s.takenOver;f.useEffect(()=>{g===void 0||x===void 0||g===x||a(e,{takenOver:g})},[g,x,e,a]);const y=f.useRef(!1);f.useEffect(()=>{var w;!m||!y.current||(y.current=!1,(w=c.current)==null||w.focus())},[m]);const{noteTakeover:b}=u,S=f.useCallback(w=>{b({takenOver:w,mine:w}),a(e,{takenOver:w}),y.current=w},[b,a,e]),j=v!=="live"&&(!u.view.hasFrame||v==="error"||v==="none"||v==="starting");return o.jsxs("div",{className:"browser-workspace agent-browser","data-agent-browser":e,"data-status":v,children:[o.jsx(kRe,{session:s,view:u.view,status:v,readOnly:n,holding:m,onError:p,onTakeover:S}),m&&o.jsx(jRe,{sessionId:e,onError:p}),d&&o.jsxs("div",{className:"browser-notice",role:"alert",children:[o.jsx("span",{className:"browser-error",children:G(r.abActionFailed,{message:d})}),o.jsx("button",{type:"button",className:"browser-control browser-icon",title:r.cmDismiss,"aria-label":r.cmDismiss,onClick:()=>p(null),children:"×"})]}),o.jsxs("div",{ref:l,className:"agent-browser-stage","data-taken-over":m?"true":void 0,children:[o.jsx(CRe,{canvasRef:c,stream:u,takenOver:m,sessionId:e,onError:p}),j&&o.jsx("div",{className:"browser-empty agent-browser-overlay","data-agent-browser-status":v,children:o.jsx(SRe,{status:v,session:s,copy:r})})]})]})}function s7(e,t){return e instanceof mk&&e.code==="no-browser"?t.abNone:e instanceof mk&&e.code==="not-taken-over"?t.abTakeOverTitle:e.message}function SRe({status:e,session:t,copy:n}){if(e==="error")return o.jsxs(o.Fragment,{children:[o.jsx("strong",{children:n.abFailed}),(t==null?void 0:t.error)&&o.jsx("p",{className:"agent-browser-error-detail",children:t.error})]});const r={none:n.abNone,starting:n.abStarting,connecting:n.abConnecting,retrying:n.abReconnecting};return o.jsx("span",{children:e==="live"?"":r[e]})}function kRe({session:e,view:t,status:n,readOnly:r,holding:i,onError:s,onTakeover:a}){const l=M(),[c,u]=f.useState(!1),d=t.url??(e==null?void 0:e.url)??null,p=e9e(d,e,t.title),h=async()=>{if(e){u(!0),s(null);try{a(await c9e(e.sessionId,!i))}catch(m){s(s7(m,l))}finally{u(!1)}}};return o.jsxs("div",{className:"browser-toolbar","aria-label":l.abTitle,children:[o.jsxs("div",{className:"browser-address agent-browser-address",title:[p,d].filter(Boolean).join(`
497
+ `.trim();function ug(e){return(e??"").replace(/<\/style/gi,"<\\/style")}function REe(e){const t=e.pendingContent.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;"),n=e.body.replaceAll("{{boardPendingContent}}",()=>t),r=`:root{color-scheme:${e.theme}}html,body{background:transparent}html{overflow:hidden}`;return`<!DOCTYPE html><html><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><meta http-equiv="Content-Security-Policy" content="${s$()}"><style data-board-layer="theme">${r}${ug(e.themeCss)}</style>`+(e.mathCss?`<style data-board-layer="math">${ug(e.mathCss)}</style>`:"")+`<style data-board-layer="preset">${ug(e.defaultCss)}</style>`+(e.userCss?`<style data-board-layer="user">${ug(e.userCss)}</style>`:"")+`<script>${EEe}<\/script></head><body>${n}</body></html>`}const MEe=240;function AEe({srcDoc:e,title:t,onOpen:n,onLink:r}){const i=f.useRef(null),[s,a]=f.useState(MEe),l=f.useRef({onOpen:n,onLink:r});return l.current={onOpen:n,onLink:r},f.useEffect(()=>{const c=u=>{if(!i.current||u.source!==i.current.contentWindow)return;const d=TEe(u.data);d&&(d.type==="height"?a(Math.max(d.value,1)):d.type==="open"?l.current.onOpen(d.path):l.current.onLink(d.href))};return window.addEventListener("message",c),()=>window.removeEventListener("message",c)},[]),o.jsx("iframe",{ref:i,title:t,sandbox:i$,srcDoc:e,referrerPolicy:"no-referrer","data-board-frame":"",style:{display:"block",width:"100%",height:s,border:0,background:"transparent"}})}const w1={minWidth:0,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},PEe=120;function IEe(e){switch(or(e)){case"idle":case"waiting":return Na(e,8);case"running":return{...Na(e,7),animation:"cxring 1.8s ease-out infinite"};case"you":return Na(e,7)}}function LEe(e,t,n){const r=Date.parse(e.lastUsedAt);return Number.isNaN(r)?null:_c(t-r,n)}function VM({tone:e,expanded:t,onClick:n,children:r,data:i}){return o.jsxs("button",{type:"button",className:`${ye} group/strip-link`,onClick:s=>{s.stopPropagation(),n()},"aria-expanded":t,[i]:"",style:{flex:"none",display:"inline-flex",alignItems:"center",gap:4,height:24,padding:"0 3px",margin:"0 -3px",border:0,borderRadius:4,background:"transparent",cursor:"pointer",whiteSpace:"nowrap",fontFamily:"inherit",fontSize:12.5,fontWeight:550,fontVariantNumeric:"tabular-nums",color:e==="ask"?"var(--proto-amber-fg)":"var(--proto-accent)"},children:[o.jsx("span",{className:"group-hover/strip-link:underline underline-offset-[3px]",children:r}),o.jsx("span",{"aria-hidden":"true",style:{display:"inline-block",fontSize:14,lineHeight:1,transition:"transform .15s ease",transform:t?"rotate(90deg)":"none"},children:"›"})]})}function NEe({session:e,now:t,onOpen:n}){const r=M(),i=Qe(),s=`${Tc(e)} · ${Cj(e,t,r,i)}`,a=LEe(e,t,i);return o.jsxs("button",{type:"button",className:ye,"data-board-session":e.sessionId,onClick:()=>n(e),title:s,"aria-label":s,style:{flex:"1 1 0",minWidth:PEe,maxWidth:"max-content",display:"inline-flex",alignItems:"center",gap:6,height:24,padding:"0 3px",margin:"0 -3px",border:0,borderRadius:4,background:"transparent",cursor:"pointer",fontFamily:"inherit",fontSize:12.5,color:"var(--proto-faint)"},children:[o.jsx("span",{style:IEe(e),"data-board-dot":or(e)}),o.jsx("span",{style:{...w1,fontWeight:550,color:"var(--proto-ink-3)",maxWidth:160},children:Tc(e)}),a&&o.jsx("span",{style:{flex:"none",whiteSpace:"nowrap",fontVariantNumeric:"tabular-nums"},children:a})]})}function DEe({sessions:e,onOpen:t}){const n=n7(e);return o.jsx("div",{"data-board-pending-list":"",onClick:r=>r.stopPropagation(),style:{position:"absolute",right:0,top:28,width:300,maxHeight:280,overflowY:"auto",zIndex:20,padding:4,boxSizing:"border-box",border:"1px solid var(--proto-line)",borderRadius:"var(--r-card)",...io},children:e.map(r=>o.jsxs("button",{type:"button",className:ye,onClick:()=>t(r),style:{display:"flex",flexDirection:"column",alignItems:"stretch",gap:2,width:"100%",padding:"6px 8px",border:0,borderRadius:"var(--r-chip)",background:"transparent",cursor:"pointer",textAlign:"left",fontFamily:"inherit"},onMouseEnter:i=>{i.currentTarget.style.background="var(--proto-gray)"},onMouseLeave:i=>{i.currentTarget.style.background="transparent"},children:[o.jsxs("span",{style:{display:"flex",alignItems:"center",gap:6,fontSize:12.5,color:"var(--proto-ink)"},children:[o.jsx("span",{style:Na(r,7)}),o.jsx("span",{style:w1,children:Tc(r)})]}),n[r.sessionId]&&o.jsx("span",{style:{...w1,fontSize:12,color:"var(--proto-muted)",paddingLeft:13},children:n[r.sessionId]})]},r.sessionId))})}function OEe(e){const t=M(),{board:n,showTitle:r=!0,gutter:i=20}=e,s=bl(!0,3e4),[a,l]=f.useState(!1),c=f.useCallback(()=>l(!1),[]);Nc(a,c,c);const{shown:u,pending:d}=Ey(e.sessions),p=()=>{d.length===1?e.onOpenSession(d[0]):l(h=>!h)};return o.jsxs("div",{"data-board-strip":"",style:{flex:"none",padding:`6px ${i}px`,borderBottom:"1px solid var(--proto-line)"},children:[r&&o.jsxs("div",{"data-board-strip-title":"",style:{display:"flex",alignItems:"center",gap:8,minWidth:0,padding:"4px 0 2px"},children:[o.jsx(Pf,{stroke:My[Ry(d.length)]}),o.jsx("span",{title:n.title,style:{...w1,fontSize:13.5,fontWeight:600,color:"var(--proto-ink)"},children:n.title})]}),o.jsxs("div",{style:{display:"flex",alignItems:"flex-start",gap:16,minWidth:0},children:[o.jsx("div",{style:{flex:1,minWidth:0,display:"flex",alignItems:"center",flexWrap:"wrap",gap:"2px 16px",minHeight:28},children:u.length===0?o.jsx("span",{style:{fontSize:12.5,color:"var(--proto-muted)"},children:t.boardNoSessions}):u.map(h=>o.jsx(NEe,{session:h,now:s,onOpen:e.onOpenSession},h.sessionId))}),o.jsxs("span",{style:{flex:"none",height:28,display:"flex",alignItems:"center",gap:14,position:"relative"},children:[d.length>0&&o.jsx(VM,{tone:"ask",data:"data-board-pending",expanded:a,onClick:p,children:G(t.boardNeedsYou,{n:d.length})}),o.jsx(VM,{tone:"accent",data:"data-board-decisions",expanded:e.decisionsOpen,onClick:e.onToggleDecisions,children:G(t.boardDecisions,{n:e.decisionCount})}),a&&d.length>1&&o.jsx(DEe,{sessions:d,onOpen:h=>{l(!1),e.onOpenSession(h)}})]})]})]})}const Rq=2*1024*1024,FEe=16*1024*1024,_Ee=64,Mq=/<(img|source|video|audio|image|input|track)\b[^>]*>/gi,Aq=/(\s(?:src|poster|href|xlink:href)\s*=\s*)(?:"([^"]*)"|'([^']*)')/gi,Pq=/url\(\s*(?:"([^"]*)"|'([^']*)'|([^'")\s]+))\s*\)/gi,Iq=/<!--[\s\S]*?(?:-->|$)/g;function Lq(e,t){let n="",r=0;for(const i of e.matchAll(Iq))n+=t(e.slice(r,i.index))+i[0],r=i.index+i[0].length;return n+t(e.slice(r))}function zEe(e,t){const n=e.replace(Iq,"");for(const r of n.matchAll(Mq))for(const i of r[0].matchAll(Aq))t(i[2]??i[3]??"");for(const r of n.matchAll(Pq))t(r[1]??r[2]??r[3]??"")}function WEe(e,t){const n=new Set;return zEe(e,r=>{const i=Ay(t,r);i&&n.add(i)}),[...n]}const BEe=/^<(?:img|video|source)\b/i,$Ee=/\ssrc\s*=\s*(?:"([^"]*)"|'([^']*)')/i;function HEe(e,t,n){if(!BEe.test(e))return"";const r=e.match($Ee),i=r?r[1]??r[2]??"":"",s=Ay(t,i);if(!s)return"";const a=` data-board-src="${i.replace(/"/g,"&quot;")}"`;return n.has(s)?a:`${a} data-board-missing=""`}function UEe(e,t,n){const r=s=>{const a=Ay(t,s);return a?n.get(a)??null:null},i=s=>{const a=HEe(s,t,n),l=s.replace(Aq,(c,u,d,p)=>{const h=r(d??p??"");return h?`${u}"${h}"`:c});return a?l.replace(/^<[a-z]+/i,c=>c+a):l};return Lq(e,s=>s.replace(Mq,i).replace(Pq,(a,l,c,u)=>{const d=r(l??c??u??"");return d?`url("${d}")`:a}))}function VEe(e){let t="";for(let r=0;r<e.length;r+=32768)t+=String.fromCharCode(...e.subarray(r,r+32768));return btoa(t)}function qEe(e,t){const n=new Map;let r=0;return e.forEach((i,s)=>{const a=t[s];if(!a||a.bytes.byteLength>Rq||(r+=a.bytes.byteLength,r>FEe))return;const l=a.mime.split(";")[0].trim()||"application/octet-stream";n.set(i,`data:${l};base64,${VEe(a.bytes)}`)}),n}async function KEe(e,t,n){const r=WEe(e,t).slice(0,_Ee);if(r.length===0)return e;const i=await Promise.all(r.map(s=>n(s,Rq).catch(()=>null)));return UEe(e,t,qEe(r,i))}const GEe=String.raw`\sclass\s*=\s*(?:"(?:[^"]*\s)?tex(?:\s[^"]*)?"|'(?:[^']*\s)?tex(?:\s[^']*)?'|tex(?=[\s/>]))`,Nq=String.raw`<(span|div)\b(?=[^>]*${GEe})([^>]*)>([\s\S]*?)<\/\1\s*>`,YEe=/<!--[\s\S]*?(?:-->|$)/g,QEe={throwOnError:!1,trust:!1,maxExpand:1e3,maxSize:50},XEe={lt:"<",gt:">",amp:"&",quot:'"',apos:"'",nbsp:" "},ZEe=/&(?:(lt|gt|amp|quot|apos|nbsp)|#(\d+)|#x([0-9a-f]+));/gi;function JEe(e){return e.replace(ZEe,(t,n,r,i)=>{if(n)return XEe[n.toLowerCase()]??t;const s=r?Number(r):parseInt(i,16);return s>0&&s<=1114111?String.fromCodePoint(s):t})}function eRe(e,t,n,r){try{const i=VB.renderToString(JEe(r),{...QEe,displayMode:t.toLowerCase()==="div"});return`<${t}${n}>${i}</${t}>`}catch{return e}}function tRe(e){return new RegExp(Nq,"i").test(e.replace(YEe,""))}function nRe(e){const t=new RegExp(Nq,"gi");return Lq(e,n=>n.replace(t,eRe))}const rRe=/src:url\(fonts\/(KaTeX_[\w-]+)\.woff2\)[^;}]*/g;function Qlt(e,t){return e.replace(rRe,(n,r)=>{const i=t[r];return i?`src:url(${i}) format("woff2")`:n})}const iRe=120;async function oRe(e,t,n){var s;const r=await fetch(qW(e,t,"inline"),{headers:Io(),cache:"no-cache"});if(!r.ok)return await((s=r.body)==null?void 0:s.cancel().catch(()=>{})),null;const i=await a$(r,n);return i.kind==="ok"?{mime:r.headers.get("content-type")??"",bytes:i.bytes}:null}function sRe(){return document.documentElement.getAttribute("data-theme")==="dark"?"dark":"light"}function aRe(){const[e,t]=f.useState(0);return f.useEffect(()=>{var a,l;let n=null;const r=()=>{n&&clearTimeout(n),n=setTimeout(()=>t(c=>c+1),iRe)},i=new MutationObserver(r);i.observe(document.documentElement,{attributes:!0});const s=(a=window.matchMedia)==null?void 0:a.call(window,"(prefers-color-scheme: dark)");return(l=s==null?void 0:s.addEventListener)==null||l.call(s,"change",r),()=>{var c;n&&clearTimeout(n),i.disconnect(),(c=s==null?void 0:s.removeEventListener)==null||c.call(s,"change",r)}},[]),e}async function lRe(e,t,n){const r=await KEe(e,n,(s,a)=>oRe(t,s,a)).catch(()=>e);if(!tRe(r))return{html:r,mathCss:null};const i=await Wc(()=>import("./board-math-css-BPXakv_3.js"),[]).then(s=>s.BOARD_MATH_CSS).catch(()=>null);return{html:nRe(r),mathCss:i}}function cRe({projectId:e,slug:t,body:n,refresh:r}){const[i,s]=f.useState(null);return f.useEffect(()=>{if(n===null||!e||!t)return;let a=!1;return lRe(n,e,t).then(l=>{a||s(l)}),()=>{a=!0}},[n,e,t,r]),i}function uRe(e){const{body:t,style:n}=e,r=cRe(e),{boardPendingContent:i}=M(),s=aRe(),a=f.useMemo(()=>wEe(n==null?void 0:n.defaultCss,n==null?void 0:n.userCss,t),[n==null?void 0:n.defaultCss,n==null?void 0:n.userCss,t]),l=f.useMemo(()=>({css:jEe(a,document.documentElement),mode:sRe()}),[a,s]);return f.useMemo(()=>r===null||n===null?null:REe({themeCss:l.css,mathCss:r.mathCss,defaultCss:n.defaultCss,userCss:n.userCss,body:r.html,pendingContent:i,theme:l.mode}),[r,n,l,i])}const xk={display:"flex",alignItems:"center",justifyContent:"center",minHeight:120,padding:20,color:"var(--proto-muted)",fontSize:12.5,textAlign:"center"},dRe="color-mix(in srgb, var(--proto-card) 78%, transparent)";function fRe(e,t){const{openMedia:n}=ml(),{openDoc:r}=Uc();return f.useCallback(i=>{const s=Ay(t,i);if(!s)return;const a=_Te(s),l=bge(e,s),c=BTe(a);if(c)return n({kind:c,name:a,path:l});const u=nj(a);if(u)return r({kind:u,name:a,path:l});o1(l,a).catch(()=>{})},[e,t,n,r])}function pRe(e){bt()?Ka(e).catch(()=>{}):window.open(e,"_blank","noopener,noreferrer")}function hRe({files:e,onOpen:t}){const n=M();return o.jsxs("div",{style:{...xk,flexDirection:"column",gap:8},"data-board-empty":"",children:[o.jsx("span",{children:n.boardNoBody}),e.length>0&&o.jsx("span",{style:{display:"flex",gap:12},children:e.map(r=>o.jsx("button",{type:"button","data-board-file":r,onClick:()=>t(r),style:{border:0,padding:0,background:"transparent",cursor:"pointer",fontFamily:"inherit",fontSize:12.5,fontWeight:500,color:"var(--proto-accent)"},children:r},r))})]})}function Dq({boardId:e,onOpenSession:t,touch:n,showTitle:r=!0}){const i=M(),s=HTe(e),[a,l]=f.useState(!1),[c,u]=f.useState(0);sbe(f.useCallback(x=>{x===e&&u(y=>y+1)},[e]));const{board:d}=s,p=n?16:20,h=(d==null?void 0:d.projectId)??"",m=(d==null?void 0:d.slug)??"",v=fRe(h,m),g=uRe({projectId:h,slug:m,body:s.body.kind==="body"?s.body.html:null,style:s.style,refresh:c});return d?o.jsxs("div",{"data-board-view":e,style:{flex:1,minHeight:0,display:"flex",flexDirection:"column"},children:[o.jsx(OEe,{board:d,sessions:s.sessions,decisionCount:s.decisions.length,decisionsOpen:a,onToggleDecisions:()=>l(x=>!x),onOpenSession:t,showTitle:r,gutter:p}),a&&o.jsx(yEe,{decisions:s.decisions,touch:n}),o.jsx("div",{"data-board-scroll":"",style:{flex:1,minHeight:0,overflowY:"auto",background:dRe,padding:n?"18px 16px 28px":"24px 28px 32px"},children:s.body.kind==="empty"?o.jsx(hRe,{files:s.body.files,onOpen:v}):g===null?o.jsx("div",{style:xk,children:i.boardLoading}):o.jsx(AEe,{srcDoc:g,title:d.title,onOpen:v,onLink:pRe})})]}):o.jsx("div",{style:xk,children:s.missing?i.boardMissing:i.boardLoading})}const mRe={position:"absolute",inset:0,zIndex:12,display:"flex",flexDirection:"column",pointerEvents:"auto",background:C.backdrop,paddingTop:"env(safe-area-inset-top)",paddingBottom:"env(safe-area-inset-bottom)",boxSizing:"border-box"},gRe={minWidth:0,fontSize:15.5,fontWeight:620,color:C.ink,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"};function vRe({boardId:e,onClose:t,onOpenSession:n}){const r=Z(),i=uq(e)??r.boardTitle;return kx(t),o.jsx(G3,{children:o.jsxs("div",{"data-board-sheet":e,style:mRe,children:[o.jsxs("div",{style:{flex:"none",height:48,display:"flex",alignItems:"center",gap:6,padding:"0 12px 0 4px",minWidth:0},children:[o.jsx("button",{type:"button","aria-label":r.back,onClick:t,style:{width:44,height:44,border:0,padding:0,background:"transparent",cursor:"pointer",display:"grid",placeItems:"center",color:C.ink},children:o.jsx(Ds,{})}),o.jsx("span",{"data-board-sheet-title":"",style:gRe,children:i})]}),o.jsx(Dq,{boardId:e,touch:!0,showTitle:!1,onOpenSession:s=>{t(),n(s)}})]})})}const xRe=10;function yRe(e){const t=atob(e),n=new Uint8Array(new ArrayBuffer(t.length));for(let r=0;r<t.length;r++)n[r]=t.charCodeAt(r);return n}function bRe({sessionId:e,enabled:t,boxRef:n,canvasRef:r}){const[i,s]=f.useReducer(XTe,QTe),a=f.useRef(null),l=f.useRef(null),c=f.useRef(null),u=f.useCallback(()=>{const v=n.current,g=l.current,x=c.current;return!v||!x?{x:0,y:0,width:0,height:0}:UTe(v.clientWidth,v.clientHeight,(g==null?void 0:g.width)??x.deviceWidth,(g==null?void 0:g.height)??x.deviceHeight)},[n]),d=f.useCallback(()=>{const v=n.current,g=r.current,x=l.current;if(!v||!g)return;const y=globalThis.devicePixelRatio||1,b=Math.max(1,Math.round(v.clientWidth*y)),S=Math.max(1,Math.round(v.clientHeight*y));g.width!==b&&(g.width=b),g.height!==S&&(g.height=S);const j=g.getContext("2d");if(!j||(j.clearRect(0,0,b,S),!x))return;const w=u();j.imageSmoothingQuality="high",j.drawImage(x,w.x*y,w.y*y,w.width*y,w.height*y)},[n,r,u]);f.useEffect(()=>{const v=n.current;if(!v||typeof ResizeObserver>"u")return;const g=new ResizeObserver(()=>d());return g.observe(v),()=>g.disconnect()},[n,d]),f.useEffect(()=>{if(!t){s({type:"stop"});return}let v=!1,g=0,x=null;const y=()=>{v||(g+=1,s({type:"drop"}),x=setTimeout(()=>void S(),ZTe(g)))},b=async(j,w,R,T)=>{var P;let A=null;try{A=await createImageBitmap(new Blob([yRe(R)],{type:"image/jpeg"}))}catch{}if(v||j!==a.current){A==null||A.close();return}if(A){(P=l.current)==null||P.close(),l.current=A;const L=c.current;c.current=T,d(),g=0,(!L||L.deviceWidth!==T.deviceWidth||L.deviceHeight!==T.deviceHeight)&&s({type:"frame",meta:T})}j.readyState===WebSocket.OPEN&&j.send(JSON.stringify({type:"ack",seq:w}))},S=async()=>{if(v)return;s({type:"connect"});let j;try{j=await l9e(e)}catch{y();return}if(v)return;const w=new WebSocket(u9e(e,j,xRe));a.current=w,w.onopen=()=>{v||s({type:"open"})},w.onmessage=R=>{if(typeof R.data!="string")return;const T=JTe(R.data);T&&(T.type==="frame"?b(w,T.seq,T.data,T.meta):s(T))},w.onclose=()=>{a.current===w&&(a.current=null),y()}};return S(),()=>{v=!0,x&&clearTimeout(x);const j=a.current;a.current=null,j&&(j.onclose=null,j.close())}},[t,e,d]),f.useEffect(()=>()=>{var v;(v=l.current)==null||v.close(),l.current=null,c.current=null},[e]);const p=f.useCallback(v=>{const g=a.current;g&&g.readyState===WebSocket.OPEN&&g.send(JSON.stringify(v))},[]),h=f.useCallback(()=>c.current,[]),m=f.useCallback(v=>s({type:"takeover",...v}),[]);return{view:i,send:p,frameRect:u,frameMeta:h,noteTakeover:m}}function wRe(){const[e,t]=f.useState(()=>typeof document>"u"||document.visibilityState!=="hidden");return f.useEffect(()=>{const n=()=>t(document.visibilityState!=="hidden");return document.addEventListener("visibilitychange",n),()=>document.removeEventListener("visibilitychange",n)},[]),e}function Oq({sessionId:e,visible:t,readOnly:n=!1}){const r=M(),i=wRe(),s=t7(e,{viewing:t&&i}),a=d9e(),l=f.useRef(null),c=f.useRef(null),u=bRe({sessionId:e,enabled:t&&(i||!n&&(s==null?void 0:s.takenOver)===!0)&&(s==null?void 0:s.state)==="ready",boxRef:l,canvasRef:c}),[d,p]=f.useState(null),h=u.view.takeover,m=!n&&((h==null?void 0:h.takenOver)??(s==null?void 0:s.takenOver)??!1)&&((h==null?void 0:h.mine)??!0),v=t9e(s,u.view),g=h==null?void 0:h.takenOver,x=s==null?void 0:s.takenOver;f.useEffect(()=>{g===void 0||x===void 0||g===x||a(e,{takenOver:g})},[g,x,e,a]);const y=f.useRef(!1);f.useEffect(()=>{var w;!m||!y.current||(y.current=!1,(w=c.current)==null||w.focus())},[m]);const{noteTakeover:b}=u,S=f.useCallback(w=>{b({takenOver:w,mine:w}),a(e,{takenOver:w}),y.current=w},[b,a,e]),j=v!=="live"&&(!u.view.hasFrame||v==="error"||v==="none"||v==="starting");return o.jsxs("div",{className:"browser-workspace agent-browser","data-agent-browser":e,"data-status":v,children:[o.jsx(kRe,{session:s,view:u.view,status:v,readOnly:n,holding:m,onError:p,onTakeover:S}),m&&o.jsx(jRe,{sessionId:e,onError:p}),d&&o.jsxs("div",{className:"browser-notice",role:"alert",children:[o.jsx("span",{className:"browser-error",children:G(r.abActionFailed,{message:d})}),o.jsx("button",{type:"button",className:"browser-control browser-icon",title:r.cmDismiss,"aria-label":r.cmDismiss,onClick:()=>p(null),children:"×"})]}),o.jsxs("div",{ref:l,className:"agent-browser-stage","data-taken-over":m?"true":void 0,children:[o.jsx(CRe,{canvasRef:c,stream:u,takenOver:m,sessionId:e,onError:p}),j&&o.jsx("div",{className:"browser-empty agent-browser-overlay","data-agent-browser-status":v,children:o.jsx(SRe,{status:v,session:s,copy:r})})]})]})}function s7(e,t){return e instanceof mk&&e.code==="no-browser"?t.abNone:e instanceof mk&&e.code==="not-taken-over"?t.abTakeOverTitle:e.message}function SRe({status:e,session:t,copy:n}){if(e==="error")return o.jsxs(o.Fragment,{children:[o.jsx("strong",{children:n.abFailed}),(t==null?void 0:t.error)&&o.jsx("p",{className:"agent-browser-error-detail",children:t.error})]});const r={none:n.abNone,starting:n.abStarting,connecting:n.abConnecting,retrying:n.abReconnecting};return o.jsx("span",{children:e==="live"?"":r[e]})}function kRe({session:e,view:t,status:n,readOnly:r,holding:i,onError:s,onTakeover:a}){const l=M(),[c,u]=f.useState(!1),d=t.url??(e==null?void 0:e.url)??null,p=e9e(d,e,t.title),h=async()=>{if(e){u(!0),s(null);try{a(await c9e(e.sessionId,!i))}catch(m){s(s7(m,l))}finally{u(!1)}}};return o.jsxs("div",{className:"browser-toolbar","aria-label":l.abTitle,children:[o.jsxs("div",{className:"browser-address agent-browser-address",title:[p,d].filter(Boolean).join(`
498
498
  `),children:[o.jsx("span",{className:"agent-browser-dot","data-status":n,"aria-hidden":"true"}),p&&o.jsx("span",{className:"agent-browser-title",children:p}),o.jsx("span",{className:"agent-browser-url",children:d??""})]}),o.jsxs("div",{className:"browser-tools",children:[e&&o.jsx("span",{className:"agent-browser-device",children:fq(e.device,l)}),!r&&o.jsx("button",{type:"button",className:"browser-control","data-agent-browser-takeover":"","aria-pressed":i,title:i?l.abHandBack:l.abTakeOverTitle,disabled:c||(e==null?void 0:e.state)!=="ready",onClick:()=>void h(),children:i?l.abHandBack:l.abTakeOver})]})]})}function jRe({sessionId:e,onError:t}){const n=M(),[r,i]=f.useState(""),[s,a]=f.useState(!1),l=async()=>{if(!(!r||s)){a(!0),t(null);try{await vq(e,r),i("")}catch(c){t(s7(c,n))}finally{a(!1)}}};return o.jsxs("div",{className:"browser-notice agent-browser-control",children:[o.jsx("span",{className:"agent-browser-in-control",children:n.abInControl}),o.jsx("form",{className:"browser-address agent-browser-paste",onSubmit:c=>{c.preventDefault(),l()},children:o.jsx("input",{value:r,"aria-label":n.abPasteLabel,placeholder:n.abPastePlaceholder,spellCheck:!1,autoComplete:"off",disabled:s,"data-agent-browser-paste":"",onChange:c=>i(c.target.value)})}),o.jsx("button",{type:"button",className:"browser-control",disabled:!r||s,onClick:()=>void l(),children:n.abPasteSend})]})}const qM={position:"absolute",inset:0,width:"100%",height:"100%",display:"block",outline:"none"};function CRe({canvasRef:e,stream:t,takenOver:n,sessionId:r,onError:i}){const s=M(),a=f.useRef(null),l=f.useRef(null),c=f.useCallback((g,x)=>{const y=e.current,b=t.frameMeta();if(!y||!b)return null;const S=y.getBoundingClientRect();return VTe(g-S.left,x-S.top,t.frameRect(),b)},[e,t]),u=f.useCallback((g,x,y={})=>{const b=c(g.clientX,g.clientY);return b?{type:"input_mouse",eventType:x,x:b.x,y:b.y,button:qTe(g.button),clickCount:0,modifiers:dq(g),...y}:null},[c]);if(f.useEffect(()=>{const g=e.current;if(!g||!n)return;const x=y=>{y.preventDefault();const b=u(y,"mouseWheel",{button:"none",deltaX:_M(y.deltaX,y.deltaMode),deltaY:_M(y.deltaY,y.deltaMode)});b&&t.send(b)};return g.addEventListener("wheel",x,{passive:!1}),()=>g.removeEventListener("wheel",x)},[e,n,u,t]),f.useEffect(()=>()=>{l.current!==null&&cancelAnimationFrame(l.current)},[]),!n)return o.jsx("canvas",{ref:e,style:qM,"aria-hidden":"true"});const d=g=>{var y,b;g.preventDefault(),g.currentTarget.focus(),(b=(y=g.currentTarget).setPointerCapture)==null||b.call(y,g.pointerId);const x=u(g,"mousePressed",{clickCount:Math.max(1,g.detail||1)});x&&t.send(x)},p=g=>{const x=u(g,"mouseReleased",{clickCount:Math.max(1,g.detail||1)});x&&t.send(x)},h=g=>{a.current=u(g,"mouseMoved",{button:KTe(g.buttons)}),l.current===null&&(l.current=requestAnimationFrame(()=>{l.current=null,a.current&&t.send(a.current),a.current=null}))},m=g=>x=>{const y={key:x.key,code:x.code,keyCode:x.nativeEvent.keyCode,isComposing:x.nativeEvent.isComposing,altKey:x.altKey,ctrlKey:x.ctrlKey,metaKey:x.metaKey,shiftKey:x.shiftKey};GTe(y)==="page"&&(x.preventDefault(),x.stopPropagation(),t.send(YTe(y,g)))},v=g=>{const x=g.clipboardData.getData("text");x&&(g.preventDefault(),vq(r,x).catch(y=>i(s7(y,s))))};return o.jsx("canvas",{ref:e,style:qM,tabIndex:0,"data-agent-browser-canvas":"",onPointerDown:d,onPointerUp:p,onPointerMove:h,onKeyDown:m("keyDown"),onKeyUp:m("keyUp"),onPaste:v,onContextMenu:g=>g.preventDefault()})}const TRe={position:"absolute",inset:0,zIndex:12,display:"flex",flexDirection:"column",pointerEvents:"auto",background:C.backdrop,paddingTop:"env(safe-area-inset-top)",paddingBottom:"env(safe-area-inset-bottom)",boxSizing:"border-box"},ERe={minWidth:0,fontSize:15.5,fontWeight:620,color:C.ink,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"};function RRe({sessionId:e,onClose:t}){const n=Z();return kx(t),o.jsx(G3,{children:o.jsxs("div",{"data-agent-browser-sheet":e,style:TRe,children:[o.jsxs("div",{style:{flex:"none",height:48,display:"flex",alignItems:"center",gap:6,padding:"0 12px 0 4px",minWidth:0},children:[o.jsx("button",{type:"button","aria-label":n.back,onClick:t,style:{width:44,height:44,border:0,padding:0,background:"transparent",cursor:"pointer",display:"grid",placeItems:"center",color:C.ink},children:o.jsx(Ds,{})}),o.jsx("span",{style:ERe,children:n.abTitle})]}),o.jsx("div",{style:{flex:1,minHeight:0,display:"flex",flexDirection:"column"},children:o.jsx(Oq,{sessionId:e,visible:!0,readOnly:!0})})]})})}function MRe({text:e,onClose:t}){return o.jsxs(Kn,{onClose:t,children:[o.jsx("div",{style:{fontSize:13,fontWeight:600,color:C.muted,padding:"0 2px 8px"},children:Z().chatOriginalMessage}),o.jsx("div",{style:{background:"var(--proto-card)",border:`1px solid ${C.hairline}`,borderRadius:"var(--r-card)",padding:"11px 13px",fontSize:13,lineHeight:1.6,color:C.body,whiteSpace:"pre-wrap",overflowWrap:"break-word",maxHeight:"50vh",overflow:"auto"},children:e})]})}function ARe({props:e,overlay:t}){var r,i;const n=(r=e.sessionStatsRows)!=null&&r.length?e.sessionStatsRows:null;return o.jsxs(o.Fragment,{children:[o.jsx(gEe,{metadataSession:e.metadataSession,open:t.is("more"),onClose:()=>t.close("more"),onSessionId:()=>t.open("sessionId"),onSessionStats:n?()=>t.open("stats"):void 0}),t.is("stats")&&n&&o.jsx(J9e,{rows:n,onClose:()=>t.close("stats")}),t.is("sessionId")&&o.jsx(X9e,{sessionId:e.sessionId,backendUuid:e.backendUuid,onClose:()=>t.close("sessionId")}),t.is("workspace")&&((i=e.cleanWorkspace)==null?void 0:i.dir)&&o.jsx(Z9e,{dir:e.cleanWorkspace.dir,onClose:()=>t.close("workspace")}),t.originalText!=null&&o.jsx(MRe,{text:t.originalText,onClose:()=>t.close("original")}),t.is("context")&&(e.contextUsageSupported||e.contextUsage!=null)?o.jsx(eEe,{usage:e.contextUsage??null,compactAction:e.contextCompactAction,onClose:()=>t.close("context")}):null,t.is("todo")&&o.jsx(N9e,{props:e,onClose:()=>t.close("todo")}),t.is("wait")&&o.jsx(D9e,{props:e,onClose:()=>t.close("wait")}),t.is("team")&&e.onOpenWorker&&o.jsx(R9e,{workers:e.workers??[],onClose:()=>t.close("team"),onOpen:s=>{t.close("team"),e.onOpenWorker(s)}}),t.boardId&&o.jsx(vRe,{boardId:t.boardId,onClose:()=>t.close("board"),onOpenSession:s=>{var a;return(a=e.onOpenBoardSession)==null?void 0:a.call(e,s.sessionId)}}),t.is("agentBrowser")&&e.sessionId&&o.jsx(RRe,{sessionId:e.sessionId,onClose:()=>t.close("agentBrowser")})]})}function PRe({props:e,overlay:t,files:n}){return o.jsx(o.Fragment,{children:t.is("attach")&&o.jsx(W9e,{onClose:()=>t.close("attach"),onCamera:n.camera,onLibrary:n.library,onFile:n.file,onCommands:()=>{e.onCommands?e.onCommands():e.composerValue||e.onComposerChange("/")}})})}function IRe({props:e,overlay:t,selection:n,files:r}){return o.jsxs(o.Fragment,{children:[o.jsx(ARe,{props:e,overlay:t}),o.jsx(PRe,{props:e,overlay:t,files:r}),o.jsx(lEe,{selection:e.selection,view:n,onPick:e.onPickSelection})]})}function LRe(e,t){return e.open?{vm:JCe({...e,copy:{favorites:t.chatFavoritesTitle,model:t.wbModel,thinking:t.wbThinking,mode:t.wbRoute,defaultThinking:t.chatThinkingDefault,crossBackend:t.chatModelCrossBackend}}),pending:e.catalogLoading||!e.modelsReady}:null}function NRe(e,t){return!e.agentOpen||!Fj(e.agents)?null:eTe({agents:e.agents,agentName:e.agentName,copy:{agentDefault:t.wbAgentDefault,agentFollowDefault:t.wbAgentFollowDefault}})}function DRe(e,t){const n=VU(e.agentOptions,e.agentName);return{chip:qU(e.effective),agentChip:Fj(e.agents)?{label:n.name??t.wbAgentDefault,followingDefault:n.followingDefault}:null,sheet:LRe(e,t),agentRows:NRe(e,t)}}function ORe(e){const[t,n]=f.useState({scope:e,overlay:null}),r=t.scope===e?t.overlay:null,i=s=>{n(a=>({scope:e,overlay:s(a.scope===e?a.overlay:null)}))};return{is:s=>(r==null?void 0:r.kind)===s,originalText:(r==null?void 0:r.kind)==="original"?r.text:null,boardId:(r==null?void 0:r.kind)==="board"&&"boardId"in r?r.boardId:null,open:s=>i(()=>({kind:s})),toggle:s=>i(a=>(a==null?void 0:a.kind)===s?null:{kind:s}),showOriginal:s=>i(()=>({kind:"original",text:s})),openBoard:s=>i(()=>({kind:"board",boardId:s})),close:s=>i(a=>(a==null?void 0:a.kind)===s?null:a)}}function FRe(){const e=f.useRef(null),[t,n]=f.useState(94);f.useEffect(()=>{const i=e.current;if(!i||typeof ResizeObserver>"u")return;const s=()=>n(i.getBoundingClientRect().height),a=new ResizeObserver(s);return s(),a.observe(i,{box:"border-box"}),()=>a.disconnect()},[]);const r=Math.max(150,t+56);return{composerRef:e,tailHeight:r,shellHeight:t}}const _Re=40,Fq=40,zRe=600;function WRe(e,t){const n=Math.max(0,e-_Re);return t===null?n:Math.min(t,n)}function BRe(e){return Math.max(0,e-Fq)}function $Re(e,t){e&&t&&(e.scrollTop=t.scrollTop+(e.scrollHeight-t.scrollHeight))}function HRe(e,t){return!!e&&t>0&&e.clientHeight>0&&e.scrollHeight<=e.clientHeight}function URe(e,t){return!!e&&t>0&&e.scrollTop<zRe}function _q({total:e,streamKey:t,settled:n,scrollRef:r}){const[i,s]=f.useState(null),a=i&&i.key===t?i.start:null,l=WRe(e,a),c=f.useRef(null),u=f.useRef(null),d=v=>{const g=r.current;g&&(c.current={scrollTop:g.scrollTop,scrollHeight:g.scrollHeight}),s({key:t,start:v})},p=()=>d(Math.max(0,l-Fq));return f.useLayoutEffect(()=>{n&&e>0&&a===null&&s({key:t,start:l})},[n,e,a,t,l]),f.useLayoutEffect(()=>{$Re(r.current,c.current),c.current=null;const v=u.current;u.current=null,v==null||v(),HRe(r.current,l)&&p()},[l]),{start:l,onScroll:()=>{URe(r.current,l)&&p()},reveal:(v,g)=>{if(v>=l)return g==null?void 0:g();u.current=g??null,d(BRe(v))}}}const VRe=40;function zq(e,t,n){const r=f.useRef(!0),i=f.useRef(0),s=()=>{const a=e.current;a&&r.current&&Date.now()>=i.current&&(a.scrollTop=a.scrollHeight)};return f.useLayoutEffect(()=>{r.current=!0,i.current=0;const a=e.current;a&&(a.scrollTop=a.scrollHeight)},[n.streamKey,e]),f.useEffect(s,n.changes),f.useEffect(()=>{const a=t.current;if(!a||typeof ResizeObserver>"u")return;const l=new ResizeObserver(s);return l.observe(a),()=>l.disconnect()},[t]),qRe(e,r,i,n.freezeMs)}function qRe(e,t,n,r){return{onScroll:()=>{const i=e.current;i&&(t.current=i.scrollHeight-i.scrollTop-i.clientHeight<VRe)},freeze:()=>{r&&(n.current=Date.now()+r)},release:()=>{t.current=!1},pinned:()=>t.current}}function KRe(e){if(e.lastReadAt===void 0)return null;if(e.lastReadAt===null)return e.origin==="scheduled"?-1/0:null;const t=Date.parse(e.lastReadAt);return Number.isNaN(t)?null:t}function KM(e){return{key:e,boundary:"pending",loaded:null,judged:!1,high:0,candidates:new Set,seen:new Set}}function GRe(e,t){return e.kind!=="assistant"?!1:t===-1/0||!!e.ts&&Date.parse(e.ts)>t}function YRe(e,t){if(e.judged||e.loaded===null||e.boundary==="pending")return;e.judged=!0;const n=e.boundary;n!==null&&t.slice(0,e.loaded).forEach((r,i)=>{GRe(r,n)&&e.candidates.add(i)})}function QRe(e,t,n){for(let r=e.high;r<t.length;r++)n&&t[r].kind==="assistant"&&e.candidates.add(r);e.high=Math.max(e.high,t.length)}function XRe(e,t){e.boundary==="pending"&&t.mark&&(e.boundary=KRe(t.mark)),e.loaded===null&&t.fetched&&(e.loaded=t.rows.length,e.high=t.rows.length),YRe(e,t.rows),e.loaded!==null&&QRe(e,t.rows,t.away)}function ZRe(e,t){return e.kind==="work"?e.live||t?e.indexes:[]:e.role==="plain"?[]:[e.index]}function JRe(e,t,n){return ZRe(e,n).filter(r=>t[r].kind==="assistant")}function eMe(e,t){return[...e.candidates].filter(n=>n<t&&!e.seen.has(n))}function tMe(e,t,n){const r=eMe(e,t.length);if(r.length===0)return null;const i=new Set(qj(t,{live:n.live}).flatMap(a=>JRe(a,t,n.workOpen))),s=r.filter(a=>i.has(a)).sort((a,l)=>a-l);return s.length?{row:s[0],count:s.length}:null}const nMe=32;function rMe(e,t){const n=e.getBoundingClientRect();return{top:n.top,bottom:Math.max(n.top,n.bottom-t)}}function iMe(e,t){const n=e.getBoundingClientRect();return Math.min(n.bottom,t.bottom)-Math.max(n.top,t.top)>=Math.min(n.height,nMe)}function oMe(e,t,n){let r=!1;return e.querySelectorAll("[data-chat-row]").forEach(i=>{const s=Number(i.dataset.chatRow);!t.candidates.has(s)||t.seen.has(s)||!iMe(i,n)||(t.seen.add(s),r=!0)}),r}function sMe(e,t,n){const r=e.querySelector(`[data-chat-row="${t}"]`);return!r||r.getBoundingClientRect().bottom<=n.top}function aMe(e,t){return t.pinned()&&e.scrollHeight-e.scrollTop-e.clientHeight>1}function lMe(e,t,n){const r=e==null?void 0:e.querySelector(`[data-chat-row="${n}"]`);if(!e||!r)return;const i=t&&parseFloat(getComputedStyle(t).paddingTop)||0;e.scrollTop+=r.getBoundingClientRect().top-e.getBoundingClientRect().top-i}function cMe(e){const t=f.useRef(KM(e.streamKey));t.current.key!==e.streamKey&&(t.current=KM(e.streamKey));const n=typeof document<"u"&&document.visibilityState==="hidden";return XRe(t.current,{rows:e.rows,fetched:e.fetched,mark:e.mark,away:!e.stick.pinned()||n}),t}function uMe(e){const t=f.useRef(0);return f.useEffect(()=>()=>{t.current&&typeof cancelAnimationFrame<"u"&&cancelAnimationFrame(t.current)},[]),f.useCallback(()=>{if(typeof requestAnimationFrame>"u")return e();t.current||(t.current=requestAnimationFrame(()=>{t.current=0,e()}))},[e])}function Wq(e){const t=cMe(e),n=Sy()==="expanded",[,r]=f.useState(0),[i,s]=f.useState(!0),a=tMe(t.current,e.rows,{live:e.live,workOpen:n}),l=f.useRef({row:(a==null?void 0:a.row)??null,cover:e.coverBottom??0,stick:e.stick});l.current={row:(a==null?void 0:a.row)??null,cover:e.coverBottom??0,stick:e.stick};const c=f.useCallback(()=>{const p=e.scrollRef.current,{row:h,cover:m,stick:v}=l.current;if(!p||h===null||aMe(p,v))return;const g=rMe(p,m);oMe(p,t.current,g)&&r(x=>x+1),s(sMe(p,h,g))},[e.scrollRef,t]),u=uMe(c);f.useEffect(u,[u,e.rows,a==null?void 0:a.row,e.win.start]);const d=()=>{a&&(e.stick.release(),e.win.reveal(a.row,()=>lMe(e.scrollRef.current,e.contentRef.current,a.row)))};return{target:a&&{...a,above:i},onScroll:u,jump:d}}const dMe=800;function fMe(e,t){const n=f.useRef(null),r=f.useRef(null),i=_q({total:e.rows.length,streamKey:e.sessionId,settled:!e.loading,scrollRef:n}),s=zq(n,r,{streamKey:e.sessionId,changes:[e.rows,e.systemLines],freezeMs:dMe}),a=Wq({rows:e.rows,live:!!e.live,fetched:e.fetched??!e.loading,streamKey:e.sessionId,mark:e.readMark,scrollRef:n,contentRef:r,stick:s,win:i,coverBottom:t});return{scrollRef:n,contentRef:r,win:i,unseen:a,onScroll:()=>{s.onScroll(),i.onScroll(),a.onScroll()},onContentClick:s.freeze}}const Bq=f.createContext(null);function pMe(){return f.useContext(Bq)}const hMe=4,mMe={minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"};function gMe({session:e,leadLabel:t}){const n=e.teamLeadId||t===null?Tc(e):t;return o.jsxs("span",{"data-board-peer":e.sessionId,style:{display:"inline-flex",alignItems:"center",gap:4,minWidth:0,color:"var(--proto-muted)"},children:[o.jsx("span",{style:Na(e,6)}),o.jsx("span",{style:{...mMe,maxWidth:96},children:n})]})}function vMe({sessions:e}){const t=M();if(e.length===0)return null;const n=e.slice(0,hMe),r=e.length-n.length,i=e.filter(s=>!s.teamLeadId).length>1?null:t.boardLead;return o.jsxs(o.Fragment,{children:[n.map(s=>o.jsx(gMe,{session:s,leadLabel:i},s.sessionId)),r>0&&o.jsxs("span",{"data-board-peers-more":"",style:{flex:"none",fontSize:12,fontVariantNumeric:"tabular-nums",color:"var(--proto-muted)"},children:["+",r]})]})}function xMe({count:e}){const t=M();return e===0?null:o.jsx("span",{"data-board-pending-count":e,style:{flex:"none",fontSize:12,fontWeight:550,lineHeight:"18px",whiteSpace:"nowrap",fontVariantNumeric:"tabular-nums",color:"var(--proto-amber-fg)"},children:G(t.boardNeedsYou,{n:e})})}const $q={minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"};function yMe({disabled:e,touch:t,onOpen:n,label:r,title:i}){const[s,a]=f.useState(!1);return o.jsxs("button",{type:"button",className:ye,"data-board-card-open":"",disabled:e,title:i,onClick:n,onMouseEnter:()=>a(!0),onMouseLeave:()=>a(!1),style:{flex:"none",display:"inline-flex",alignItems:"center",gap:6,height:t?34:30,padding:"0 13px",border:0,borderRadius:"var(--r-control)",fontFamily:"inherit",fontSize:12.5,fontWeight:600,whiteSpace:"nowrap",cursor:e?"default":"pointer",color:e?"var(--proto-muted)":"var(--proto-accent)",background:e?"var(--proto-gray)":s?"color-mix(in srgb, var(--proto-accent) 14%, var(--proto-accent-bg))":"var(--proto-accent-bg)",boxShadow:e?"none":"inset 0 0 0 1px var(--proto-accent-border)"},children:[r," →"]})}function bMe({action:e,onOpen:t,touch:n}){const r=M(),{board:i,missing:s,sessions:a}=$0(e.boardId),{shown:l,pending:c}=Ey(a),u=Ry(c.length),d=u==="ask",p=(i==null?void 0:i.title)??e.title;return o.jsxs("div",{"data-board-card":e.boardId,"data-board-flag":u,"data-board-missing":s?"":void 0,style:{display:"flex",alignItems:"center",gap:12,minWidth:0,padding:n?"11px 12px":"11px 14px",borderRadius:"var(--r-card)",background:"var(--material-card-bg)",border:"1px solid var(--border-card)",boxShadow:"var(--material-card-shadow)"},children:[o.jsx("span",{"aria-hidden":"true",style:{flex:"none",width:32,height:32,borderRadius:"var(--r-control)",display:"grid",placeItems:"center",background:d?"var(--proto-amber-bg)":"var(--proto-accent-bg)",boxShadow:`inset 0 0 0 1px ${d?"var(--proto-amber-border)":"var(--proto-accent-border)"}`},children:o.jsx(Pf,{size:15,stroke:s?"var(--proto-muted)":My[u]})}),o.jsxs("div",{style:{flex:1,minWidth:0},children:[o.jsx("div",{style:{fontSize:12,fontWeight:500,color:"var(--proto-muted)"},children:r.boardCreatedKicker}),o.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,minWidth:0,marginTop:1},children:[o.jsx("b",{title:p,style:{...$q,fontSize:14,fontWeight:650,color:"var(--proto-ink)"},children:p}),o.jsx(xMe,{count:c.length})]}),l.length>0&&o.jsx("div",{style:{display:"flex",flexWrap:"wrap",alignItems:"center",columnGap:10,rowGap:2,minWidth:0,marginTop:4,fontSize:12},children:o.jsx(vMe,{sessions:l})})]}),o.jsx(yMe,{disabled:s,touch:n,onOpen:()=>t(e.boardId),label:r.boardOpen,title:s?r.boardMissing:void 0})]})}function wMe({action:e,onOpen:t,touch:n}){const r=M(),{board:i,missing:s}=$0(e.boardId),a=(i==null?void 0:i.title)??e.title;return o.jsxs("div",{"data-board-line":e.boardId,"data-board-missing":s?"":void 0,style:{display:"flex",alignItems:"center",gap:n?9:10,minWidth:0,padding:0,minHeight:n?40:30,fontSize:n?13.5:13,color:"var(--proto-muted)"},children:[o.jsx("span",{style:{width:16,display:"flex",justifyContent:"center",flex:"none"},children:o.jsx(Pf,{size:12,stroke:s?"var(--proto-muted)":"var(--proto-accent)"})}),o.jsx("span",{style:{flex:"none"},children:r.boardAttachedLine}),o.jsx("b",{title:a,style:{...$q,fontWeight:600,color:"var(--proto-ink)"},children:a}),o.jsxs("button",{type:"button",className:ye,"data-board-card-open":"",disabled:s,title:s?r.boardMissing:void 0,onClick:()=>t(e.boardId),style:{flex:"none",border:0,padding:"0 2px",background:"transparent",fontFamily:"inherit",fontSize:12,fontWeight:550,whiteSpace:"nowrap",color:s?"var(--proto-muted)":"var(--proto-accent)",cursor:s?"default":"pointer"},children:["· ",r.boardBarOpen," →"]})]})}function Hq({action:e,onOpen:t,touch:n=!1}){return e.created?o.jsx(bMe,{action:e,onOpen:t,touch:n}):o.jsx(wMe,{action:e,onOpen:t,touch:n})}function SMe({children:e}){const{openBoard:t}=Bo(),n=f.useMemo(()=>({row:r=>o.jsx(Hq,{action:r.action,onOpen:t})}),[t]);return o.jsx(Bq.Provider,{value:n,children:e})}const Uq=f.createContext(null);function Vq(){return f.useContext(Uq)}function Ly(e,t,n){if(n){const r=e.find(i=>i.sessionId===n);if(r)return r}return t?e.find(r=>r.workerName===t)??null:null}const GM=12;function YM(e){return e.replace(/…$/,"").replace(/\s+/g," ").trim()}function kMe(e,t){if(!t)return null;const n=YM(t);return n.length<GM?null:e.find(r=>{const i=r.workerBrief?YM(r.workerBrief):"";return i.length>=GM&&(n.startsWith(i)||i.startsWith(n))})??null}function jMe(e){return e.filter(t=>{if(t.awaitingInput||(t.waitingOnLead??0)>0)return!1;const n=or(t);return n==="running"||n==="waiting"})}function CMe(e,t=new Date){var i,s;const n=Ji(((i=e[0])==null?void 0:i.ts)??void 0,t),r=Ji(((s=e.at(-1))==null?void 0:s.ts)??void 0,t);return!n||!r?n??r:n===r?n:`${n} – ${r}`}function TMe(e,t,n=null){const r=[...e.updates].reverse().find(i=>i.kind==="question"||i.kind==="plan");return!r||!r.answer&&!a7(e,n)?null:r.kind==="plan"?r.answer?r.answer.approved===!1?t.wbTeamPlanRejected:t.wbTeamPlanApproved:t.wbTeamPlanAwaiting:r.answer?t.wbTeamQuestionAnswered:t.wbTeamQuestionOpen}function a7(e,t){return!e.latest||t&&!t.awaitingInput?null:T3e(e)}const qq=f.createContext({workers:[],leadRunning:!1}),EMe=3e4,Vc={minWidth:0,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},RMe={display:"-webkit-box",WebkitLineClamp:2,WebkitBoxOrient:"vertical",overflow:"hidden",minWidth:0,overflowWrap:"anywhere"},l7={fontSize:12,color:"var(--proto-faint)",flex:"none",whiteSpace:"nowrap"};function Kq(e){return{...W0(e,!0),color:"var(--proto-muted)"}}const c7={width:16,height:16,flex:"none",display:"flex",alignItems:"center",justifyContent:"center"},Gq={...Vc,flex:"none",maxWidth:"45%",fontWeight:550,color:"var(--proto-ink-3)"},Yq={marginLeft:"auto",paddingLeft:12,flex:"none",display:"inline-flex",alignItems:"center",gap:6,fontSize:12,color:"var(--proto-faint)"},Qq={fontSize:13,fontWeight:550,color:"var(--proto-ink-3)",flex:"none"};function u7(e,t=!1){return e.kind==="progress"?"var(--proto-muted)":t?"var(--proto-ink)":"var(--proto-ink-2)"}const d7={fontSize:12.5,lineHeight:1.6,color:"var(--proto-ink-2)",minWidth:0,overflowWrap:"break-word",wordBreak:"break-word"};function qc(){return f.useContext(qq)}function H0(e){return{role:"button",tabIndex:0,onClick:e,onKeyDown:t=>{(t.key==="Enter"||t.key===" ")&&(t.preventDefault(),e())}}}function MMe({open:e}){return o.jsx("svg",{width:"10",height:"10",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",style:{flex:"none",transform:`rotate(${e?180:0}deg)`,transition:"transform 160ms ease"},children:o.jsx("path",{d:"m4 6 4 4 4-4"})})}function f7({worker:e}){if(!e)return o.jsx("span",{"aria-hidden":"true",style:{width:7,height:7,borderRadius:"50%",flex:"none",background:"var(--proto-line-3)"}});const t=or(e)==="running";return o.jsx("span",{"aria-hidden":"true","data-worker-dot":or(e),style:{...Na(e,7),...t?{animation:"cxring 1.8s ease-out infinite"}:null}})}function Xq({name:e,worker:t}){const n=Z(),{onOpenWorker:r}=qc(),i=t&&r?()=>r(t.sessionId):null,s={display:"inline-flex",alignItems:"center",gap:6,flex:"0 1 auto",minWidth:0,maxWidth:220,padding:0,border:0,background:"transparent",borderRadius:4,fontSize:"inherit",fontWeight:550,color:"var(--proto-ink-2)",lineHeight:"inherit"},a=o.jsxs(o.Fragment,{children:[o.jsx(f7,{worker:t}),o.jsx("span",{style:Vc,children:e})]});return i?o.jsx("button",{type:"button","data-worker-pill":e,className:ye,title:n.wbTeamOpenWorker,onClick:l=>{l.stopPropagation(),i()},style:{...s,cursor:"pointer",fontFamily:"inherit"},children:a}):o.jsx("span",{"data-worker-pill":e,style:s,children:a})}function Zq({worker:e,label:t}){const{onOpenWorker:n}=qc();return!e||!n?null:o.jsxs("button",{type:"button","data-open-worker":"",className:ye,onClick:r=>{r.stopPropagation(),n(e.sessionId)},style:{border:0,background:"transparent",padding:0,cursor:"pointer",fontFamily:"inherit",fontSize:12,fontWeight:550,color:"var(--proto-accent)",flex:"none"},children:[t," ↗"]})}function yk(e,t){switch(e.op){case"spawn":return t.wbTeamActSpawn;case"send":return t.wbTeamActSend;case"stop":return t.wbTeamActStop;case"answer":return e.approved===!0?t.wbTeamActApproved:e.approved===!1?t.wbTeamActRejected:t.wbTeamActAnswered}}function AMe(e){switch(e.op){case"spawn":return{name:"plus",color:"var(--proto-accent)"};case"send":return{name:"arrow"};case"stop":return{name:"stop"};case"answer":return e.approved===!0?{name:"check",color:"var(--proto-success)"}:e.approved===!1?{name:"cross",color:"var(--proto-danger)"}:{name:"reply"}}}function Jq({action:e}){const{name:t,color:n}=AMe(e);return o.jsx("span",{style:{...c7,color:n??"var(--proto-faint)"},children:o.jsx(bn,{name:t})})}function p7(e,t){return t?`${e}…`:e}function PMe({action:e,touch:t}){const n=Z(),{workers:r}=qc(),[i,s]=f.useState(!1),a=Ly(r,e.worker)??(e.worker?null:kMe(r,e.text)),l=e.worker??(a==null?void 0:a.workerName)??null,c=[yk(e,n),l,e.model].filter(Boolean).join(" · ");return o.jsxs("div",{"data-team-action":"spawn",style:{display:"flex",flexDirection:"column",gap:2},children:[o.jsxs("div",{title:c,style:{display:"flex",alignItems:"center",gap:t?9:10,minWidth:0,minHeight:t?40:30,fontSize:t?13.5:13},children:[o.jsx(Jq,{action:e}),o.jsx("span",{style:Qq,children:yk(e,n)}),l&&o.jsx(Xq,{name:l,worker:a}),e.model&&!t&&o.jsx("span",{"data-spawn-model":"",style:{...Vc,flex:"0 1000 auto",fontSize:12,color:"var(--proto-faint)"},children:e.model}),o.jsx("span",{style:{flex:1}}),o.jsx(Zq,{worker:a,label:n.wbTeamOpenShort})]}),e.text&&o.jsxs("div",{...H0(()=>s(u=>!u)),"aria-expanded":i,title:i?n.wbTeamHideFull:n.wbTeamShowFull,style:{...d7,fontSize:t?13:12.5,lineHeight:1.55,color:"var(--proto-muted)",cursor:"pointer",paddingLeft:26,...i?{color:"var(--proto-ink-2)"}:RMe},children:[i&&t&&e.model&&o.jsx("div",{"data-spawn-model":"",style:{fontSize:12,color:"var(--proto-faint)",marginBottom:2},children:e.model}),i?o.jsx(br,{text:p7(e.text,e.partial)}):e.text]})]})}function IMe({action:e,open:t}){const n=Z(),{workers:r}=qc(),i=Ly(r,e.worker),s=e.op==="stop"?null:e.text,a=Ji(e.ts??void 0);return o.jsxs(o.Fragment,{children:[o.jsx(Jq,{action:e}),o.jsx("span",{style:Qq,children:yk(e,n)}),e.worker&&o.jsx(Xq,{name:e.worker,worker:i}),s&&o.jsx("span",{"data-team-action-preview":"",style:{...Vc,flex:"0 1000 auto",color:"var(--proto-muted)"},children:t?null:s}),o.jsx("span",{style:{flex:1}}),a&&o.jsx("span",{style:l7,children:a})]})}function LMe({action:e,touch:t}){const[n,r]=f.useState(!1),i=e.op!=="stop"&&!!e.text,s=o.jsx("div",{"data-team-action":e.op,...i?H0(()=>r(a=>!a)):{},"aria-expanded":i?n:void 0,style:{display:"flex",alignItems:"center",gap:t?9:10,minWidth:0,padding:0,minHeight:t?40:30,fontSize:t?13.5:13,color:"var(--proto-muted)",cursor:i?"pointer":void 0},children:o.jsx(IMe,{action:e,open:n})});return!n||!e.text?s:o.jsxs("div",{children:[s,o.jsx("div",{"data-team-action-body":"",style:{...d7,margin:"0 0 4px 26px",padding:"2px 0 6px"},children:o.jsx(br,{text:p7(e.text,e.partial)})})]})}function eK({action:e,touch:t=!1}){return e.op==="spawn"?o.jsx(PMe,{action:e,touch:t}):o.jsx(LMe,{action:e,touch:t})}const Ny={fontSize:11,fontWeight:600,padding:"0 6px",borderRadius:5,marginRight:6,whiteSpace:"nowrap",display:"inline-block",lineHeight:"17px"},NMe={...Ny,background:"var(--proto-amber-bg)",color:"var(--proto-amber-fg)",boxShadow:"inset 0 0 0 1px var(--proto-amber-border)"},DMe={...Ny,background:"var(--proto-accent-bg)",color:"var(--proto-accent)"},OMe={...Ny,background:"var(--proto-success-bg)",color:"var(--proto-success)"},tK={...Ny,background:"var(--proto-danger-bg)",color:"var(--proto-danger)"};function nK(e,t){return e.kind==="plan"?t.wbTeamTagPlan:e.kind==="question"?t.wbTeamTagQuestion:e.outcome?e.outcome==="failed"?t.wbTeamOutcomeFailed:t.wbTeamOutcomeStopped:null}function h7({update:e,plain:t=!1}){const n=Z(),r=nK(e,n);if(!r)return null;const i=e.kind==="plan"?NMe:e.kind==="question"?DMe:tK;return t?o.jsx("span",{style:{color:i.color,fontWeight:550,marginRight:6},children:r}):o.jsx("span",{style:i,children:r})}function FMe({update:e}){const t=Z(),n=e.answer;if(!n)return null;const r=Ji(n.ts??void 0)??"",i=e.kind==="plan"?G(n.approved===!1?t.wbTeamLeadRejectedAt:t.wbTeamLeadApprovedAt,{time:r}):G(t.wbTeamAnsweredAt,{time:r});return o.jsx("span",{style:{...n.approved===!1?tK:OMe,marginLeft:6,marginRight:0},children:i.trim()})}function _Me({update:e,last:t,showName:n,touch:r}){var l;const i=Z(),[s,a]=f.useState(!1);return o.jsxs("div",{"data-team-update":e.kind,...H0(()=>a(c=>!c)),"aria-expanded":s,className:r?void 0:"hover:bg-[var(--proto-gray)]",style:{display:"grid",gridTemplateColumns:"minmax(42px, max-content) minmax(0, 1fr)",gap:8,padding:r?"6px 4px":"5px 4px",borderRadius:6,cursor:"pointer"},children:[o.jsx("span",{style:{...l7,paddingTop:2},children:Ji(e.ts??void 0)??""}),o.jsxs("div",{style:{minWidth:0},children:[o.jsxs("div",{style:{...s?{overflowWrap:"anywhere"}:Vc,fontSize:r?13:12.5,lineHeight:1.55,color:u7(e,t)},children:[n&&o.jsxs("span",{style:{fontWeight:550,color:"var(--proto-ink-2)"},children:[e.worker," · "]}),o.jsx(h7,{update:e}),!s&&e.line,o.jsx(FMe,{update:e})]}),s&&o.jsxs("div",{"data-team-update-body":"",style:{...d7,fontSize:r?13.5:12.5,marginTop:2},children:[e.body&&o.jsx(br,{text:e.body,wideTables:!r,dropTrailingHr:r}),((l=e.answer)==null?void 0:l.text)&&o.jsxs("div",{style:{marginTop:6,paddingLeft:10,borderLeft:"2px solid var(--proto-line-3)"},children:[o.jsx("div",{style:{fontSize:11.5,fontWeight:600,color:"var(--proto-muted)"},children:i.wbTeamLeadReply}),o.jsx(br,{text:p7(e.answer.text,e.answer.partial)})]})]})]})]})}function rK({updates:e,showName:t,touch:n}){return o.jsx("div",{"data-team-timeline":"",onClick:r=>r.stopPropagation(),style:{padding:"2px 8px 6px 8px"},children:e.map((r,i)=>o.jsx(_Me,{update:r,last:i===e.length-1,showName:t,touch:n},i))})}function iK(e,t,n,r,i,s){return n?{kind:"waiting",text:n.kind==="plan"?i.wbTeamPlanWaiting:i.wbTeamQuestionWaiting}:e.latest&&t&&!_0(t,r)?{kind:or(t),text:Cj(t,r,i,s)}:{kind:"history",text:null}}function oK({thread:e,shown:t,range:n}){const r=(n&&!e.latest?CMe(e.updates):null)??Ji(t.ts??void 0);return r?o.jsx("span",{"data-thread-time":"",style:l7,children:r}):null}function sK(e,t,n,r){const i=[nK(t,r),t.line].filter(Boolean).join(" ");return[e,i,...n].filter(Boolean).join(" · ")}function zMe({row:e,touch:t,now:n}){const r=Z(),i=gf(),{workers:s}=qc(),[a,l]=f.useState(!1),c=e.threads[0],u=Ly(s,c.worker,c.sessionId),d=a7(c,u),p=gU(c.updates),h=TMe(c,r,u),m=iK(c,u,d,n,r,i),v=sK(c.worker,p,[m.text,d?null:h],r);return o.jsxs("div",{"data-team-card":"","data-team-card-open":a?"true":void 0,style:{opacity:e.pending?.55:1,minWidth:0},children:[o.jsxs("div",{...H0(()=>l(g=>!g)),"aria-expanded":a,"aria-label":v,title:v,"data-thread-status":m.kind,className:`${ye}${t?"":" hover:bg-[var(--proto-gray)]"}`,style:Kq(t),children:[o.jsx("span",{style:c7,children:o.jsx(f7,{worker:c.latest?u:null})}),o.jsx("span",{style:Gq,children:c.worker}),o.jsxs("span",{"data-team-headline":p.kind,style:{...Vc,color:u7(p)},children:[o.jsx(h7,{update:p,plain:!0}),p.line]}),o.jsx("span",{style:Yq,children:o.jsx(oK,{thread:c,shown:p,range:!t})})]}),a&&o.jsxs("div",{style:{padding:t?"0 0 4px 17px":"0 0 4px 18px"},children:[o.jsx(rK,{updates:c.updates,showName:!1,touch:t}),u&&o.jsx("div",{style:{display:"flex",padding:"0 0 4px 8px"},children:o.jsx(Zq,{worker:u,label:r.wbTeamOpenWorker})})]})]})}function WMe({row:e,touch:t,now:n}){const r=Z(),i=gf(),{workers:s}=qc(),[a,l]=f.useState(!1),c=()=>l(d=>!d),u=e.updates.length;return o.jsxs("div",{"data-team-card":"","data-team-card-open":a?"true":void 0,style:{opacity:e.pending?.55:1,minWidth:0},children:[e.threads.map(d=>{const p=Ly(s,d.worker,d.sessionId),h=a7(d,p),m=h??gU(d.updates),v=iK(d,p,h,n,r,i),g=sK(d.worker,m,[v.text],r);return o.jsxs("div",{"data-team-thread":d.worker,...H0(c),"aria-label":g,title:g,"data-thread-status":v.kind,className:`${ye}${t?"":" hover:bg-[var(--proto-gray)]"}`,style:Kq(t),children:[o.jsx("span",{style:c7,children:o.jsx(f7,{worker:d.latest?p:null})}),o.jsx("span",{style:Gq,children:d.worker}),o.jsxs("span",{"data-team-headline":m.kind,style:{...Vc,color:u7(m)},children:[o.jsx(h7,{update:m,plain:!0}),m.line]}),o.jsx("span",{style:Yq,children:o.jsx(oK,{thread:d,shown:m,range:!1})})]},d.worker)}),a&&o.jsx("div",{style:{padding:t?"0 0 4px 17px":"0 0 4px 18px"},children:o.jsx(rK,{updates:e.updates,showName:!0,touch:t})}),o.jsxs("button",{type:"button",className:ye,"aria-expanded":a,onClick:c,style:{display:"inline-flex",alignItems:"center",gap:6,border:0,background:"transparent",cursor:"pointer",padding:t?"6px 0 6px 26px":"2px 0 2px 26px",fontFamily:"inherit",fontSize:12,color:"var(--proto-faint)"},children:[u===1?r.wbTeamItemsOne:G(r.wbTeamItemsMany,{n:u})," · ",a?r.wbTeamHideFull:r.wbTeamExpandTimeline,o.jsx(MMe,{open:a})]})]})}function aK({row:e,touch:t=!1}){const n=bl(!0,EMe);return e.threads.length===0?null:e.threads.length===1?o.jsx(zMe,{row:e,touch:t,now:n}):o.jsx(WMe,{row:e,touch:t,now:n})}function BMe({row:e,touch:t=!1}){return e.kind==="team-action"?o.jsx(eK,{action:e.action,touch:t}):o.jsx(aK,{row:e,touch:t})}function lK({touch:e=!1,offset:t=0}){const n=Z(),{workers:r,leadRunning:i}=qc(),s=f.useMemo(()=>jMe(r),[r]);if(i||s.length===0)return null;let a;if(s.length===1){const[l,c]=n.wbTeamLeadWaitingOne.split("{name}");a=o.jsxs(o.Fragment,{children:[l,o.jsx("span",{style:{fontWeight:550,color:"var(--proto-ink-2)"},children:s[0].workerName??""}),c]})}else a=G(n.wbTeamLeadWaitingMany,{n:s.length});return o.jsxs("div",{"data-lead-waiting":"",style:{display:"flex",alignItems:"center",gap:e?9:10,marginTop:t,minHeight:e?36:28,fontSize:e?13:12.5,color:"var(--proto-muted)"},children:[o.jsx("span",{style:{width:16,display:"flex",justifyContent:"center",flex:"none"},children:o.jsx("span",{"aria-hidden":"true",style:{width:7,height:7,borderRadius:"50%",boxSizing:"border-box",border:"1.5px solid var(--proto-muted-3)",flex:"none"}})}),o.jsx("span",{style:{minWidth:0},children:a})]})}const $Me={row:e=>o.jsx(BMe,{row:e}),tail:o.jsx(lK,{offset:14})};function cK({workers:e,leadRunning:t,onOpenWorker:n,children:r}){const i=f.useMemo(()=>({workers:e,leadRunning:t,onOpenWorker:n}),[e,t,n]);return o.jsx(qq.Provider,{value:i,children:o.jsx(Uq.Provider,{value:$Me,children:r})})}const HMe={flex:"none",padding:"1px 6px",border:"1px solid var(--proto-line-3)",borderRadius:"var(--r-chip)",background:"transparent",fontFamily:"var(--font-ui)",fontSize:11.5,lineHeight:1.4,color:C.muted,cursor:"pointer"},UMe={position:"absolute",top:"calc(8px + env(safe-area-inset-top))",left:10,right:10,zIndex:5,display:"flex",flexDirection:"column",gap:6},VMe={position:"relative",height:56,flex:"none",display:"flex",alignItems:"center",gap:4,padding:"0 4px",borderRadius:"var(--r-float)",background:C.glass,backdropFilter:C.glassFilter,WebkitBackdropFilter:C.glassFilter,boxShadow:"0 0 0 1px var(--proto-line), var(--shadow-chrome-float)",boxSizing:"border-box"},QM={flex:"none",width:44,height:44,border:0,background:"transparent",padding:0,borderRadius:"var(--r-control)",cursor:"pointer"};function qMe(e){return e.tone==="waiting"?"var(--proto-amber)":e.running?"var(--proto-accent)":"var(--proto-line-3)"}function KMe(e){const t=Z();return o.jsxs("div",{"data-chat-header":"true",style:VMe,children:[o.jsx("button",{type:"button","aria-label":t.back,onClick:e.onBack,style:{...QM,color:C.ink,display:"grid",placeItems:"center"},children:o.jsx(Ds,{})}),o.jsxs("div",{style:{flex:1,minWidth:0,padding:"0 2px"},children:[o.jsxs("div",{style:{display:"flex",alignItems:"center",gap:7},children:[o.jsx("span",{"data-chat-status-dot":e.status.tone,style:{width:7,height:7,borderRadius:"50%",flex:"none",background:qMe(e.status)}}),e.parent&&o.jsxs("button",{type:"button","data-lead-crumb":"","aria-label":`${t.wbTeamOpenLead} · ${e.parent.title}`,onClick:e.parent.onSelect,style:{display:"inline-flex",alignItems:"center",gap:4,minWidth:0,maxWidth:"45%",flexShrink:1,padding:0,border:0,background:"transparent",cursor:"pointer",fontFamily:"var(--font-ui)",fontSize:15,color:C.muted},children:[o.jsx("span",{style:{minWidth:0,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:e.parent.title}),o.jsx("span",{"aria-hidden":"true",style:{flex:"none"},children:"/"})]}),o.jsx("span",{style:{minWidth:0,fontSize:15.5,fontWeight:620,color:C.ink,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:e.title}),e.clean&&o.jsx("button",{type:"button","data-clean-label":"","aria-label":`${t.wbClean} · ${t.wbCleanWorkspace}`,disabled:!e.clean.onOpen,onClick:e.clean.onOpen??void 0,style:HMe,children:t.wbClean})]}),o.jsx(GMe,{status:e.status})]}),e.contextControl,o.jsx("button",{type:"button","aria-label":t.more,onClick:e.onMore,style:{...QM,color:"var(--proto-muted-2)",fontSize:18,letterSpacing:"1px"},children:"⋯"})]})}function GMe({status:e}){const t=bl(!!e.liveText),n=e.liveText?e.liveText(t):e.text;return o.jsx("div",{"data-chat-status-line":"true",style:{fontSize:12.5,color:e.tone==="waiting"?"var(--proto-amber-fg)":C.muted,marginTop:1,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",...$e},children:n})}function XM({rows:e,sessionId:t}){return o.jsx(o.Fragment,{children:e.map((n,r)=>n.kind==="tools"&&n.count>0?o.jsx(uK,{row:n,sessionId:t},r):n.kind==="assistant"&&n.text?o.jsx("div",{style:{fontSize:12.5,lineHeight:1.6,color:C.body,overflowWrap:"break-word",wordBreak:"break-word"},children:o.jsx(br,{text:n.text})},r):null)})}function YMe({row:e,sessionId:t}){return e.detailMode!=="lazy"||!e.hasDetails||!t?o.jsx(XM,{rows:e.children,sessionId:t}):o.jsx(bU,{sessionId:t,subagentId:e.id,fallbackRows:e.children,render:n=>o.jsx(XM,{rows:n,sessionId:t})})}function QMe({row:e,sessionId:t,background:n=!1}){return o.jsx(wV,{agentType:e.agentType,description:e.description,prompt:e.prompt,model:e.model,status:e.status,toolCount:e.toolCount,background:n,clean:e.clean,touch:!0,children:o.jsx(YMe,{row:e,sessionId:t})})}function uK({row:e,sessionId:t,live:n=!1}){return o.jsx(MV,{calls:e.calls,sessionId:t,live:n,touch:!0})}const sd=()=>{},XMe=[],ZMe=[];function JMe({text:e,preview:t,streamKey:n,ts:r}){const i=gV(e,!!t,n);return i.trim()?o.jsx(uV,{sessionId:n,ts:r,children:o.jsx(br,{text:i,dropTrailingHr:!0,renderMath:!0})}):null}function eAe({row:e,interactions:t}){const n=Z(),r=QV(e,n);if(r.kind==="ask"&&r.model.status!=="pending"){const a=r.model;return o.jsx(nAe,{count:a.questions.length,time:a.timeLabel,children:o.jsx(LM,{model:a,state:fk,copy:n,onPick:sd,onToggle:sd,onConfirmMulti:sd})})}if(r.kind==="ask"){const a=r.model;return o.jsx(LM,{model:a,state:(t==null?void 0:t.askState(a.requestId))??fk,copy:n,onPick:l=>t==null?void 0:t.onAskPick(a,l),onToggle:l=>t==null?void 0:t.onAskToggle(a,l),onConfirmMulti:()=>t==null?void 0:t.onAskConfirmMulti(a)})}if(r.kind==="plan")return o.jsx(tAe,{model:r.model,interactions:t});const i=r.tone==="rejected"?"var(--proto-danger)":r.tone==="inactive"?void 0:C.done,s=r.tone==="rejected"?"cross":r.tone==="inactive"?"circle":"check";return o.jsx(yl,{touch:!0,icon:o.jsx(bn,{name:s,color:i}),label:r.label,summary:r.text,attrs:{"data-interaction-summary":r.tone}})}function tAe({model:e,interactions:t}){const n=Z();if(e.status!=="approved"&&e.status!=="rejected")return o.jsx(_Ce,{model:e,copy:n,dimmed:(t==null?void 0:t.rejectingId)===e.requestId,onApprove:t?()=>t.onApprove(e):sd,onRejectStart:t?()=>t.onRejectStart(e):sd,onOpenRead:t?()=>t.onOpenRead(e):sd});const r=e.status==="approved";return o.jsxs(o.Fragment,{children:[o.jsx(yl,{touch:!0,icon:o.jsx(bn,{name:r?"check":"cross",color:r?"var(--proto-success)":"var(--proto-danger)"}),label:r?n.chatPlanApproved:n.chatPlanRejected,summary:e.title,meta:o.jsx("span",{style:{color:"var(--proto-accent)",fontWeight:550},children:n.chatPlanView}),onClick:t?()=>t.onOpenRead(e):void 0,attrs:{"data-interaction-sealed":r?"plan-approved":"plan-rejected"}}),!r&&e.feedback&&o.jsx("div",{style:{alignSelf:"flex-end",maxWidth:"82%",background:C.inkSolid,color:"var(--ink-solid-fg)",borderRadius:"var(--r-float) var(--r-float) 4px var(--r-float)",padding:"9px 13px",fontSize:13.5,lineHeight:1.55,whiteSpace:"pre-wrap",overflowWrap:"break-word"},children:e.feedback})]})}function nAe({count:e,time:t,children:n}){const r=Z(),[i,s]=f.useState(!1);return o.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:6},children:[o.jsx(yl,{touch:!0,icon:o.jsx(bn,{name:i?"chevron":"check",open:i,color:i?void 0:C.done}),label:r.ixAnswered,summary:e===1?r.chatAskAnsweredOne:G(r.chatAskAnsweredMany,{n:e}),meta:t,expanded:i,onClick:()=>s(a=>!a),attrs:{"data-interaction-sealed":"ask"}}),i&&n]})}function rAe({row:e}){return o.jsx(TV,{origin:e.systemOrigin,text:e.text,pending:e.pending,expandable:Ud(e.systemOrigin)==="expandable",touch:!0})}const If={opacity:.35,pointerEvents:"none"};function iAe({row:e,dimmed:t}){return o.jsxs("div",{style:{display:"flex",alignItems:"center",gap:12,...t?{opacity:.35}:{}},children:[o.jsx("div",{style:{flex:1,height:1,background:"var(--proto-line)"}}),o.jsx("div",{style:{fontSize:12,fontWeight:600,color:C.muted,...$e},children:e.text}),o.jsx("div",{style:{flex:1,height:1,background:"var(--proto-line)"}})]})}function oAe(e,t,n){return{background:"var(--material-card-bg)",border:"1px solid var(--proto-line)",color:e?C.muted:C.ink,borderRadius:"18px 18px 6px 18px",padding:"10px 14px",fontSize:15,lineHeight:1.5,boxShadow:"var(--material-card-shadow)",whiteSpace:"pre-wrap",overflowWrap:"break-word",wordBreak:"break-word",WebkitUserSelect:t?"none":void 0,userSelect:t?"none":void 0,WebkitTouchCallout:t?"none":void 0,...n?{boxShadow:`var(--material-card-shadow), 0 0 0 1.5px ${C.run}`}:{}}}function sAe({editing:e}){const t=Z();return o.jsx("div",{style:{display:"flex",justifyContent:"flex-end"},children:o.jsx("span",{style:{fontSize:12,fontWeight:600,color:"var(--m-amber-ink)",background:C.amberBg,padding:"2px 7px",borderRadius:6,...$e},children:G(t.chatWillRewind,{replies:G(e.replies===1?t.msgReplyOne:t.msgReplyMany,{n:e.replies}),tools:G(e.toolCalls===1?t.msgToolCallOne:t.msgToolCallMany,{n:e.toolCalls})})})})}function aAe({onTap:e}){return o.jsx("span",{role:"button",onClick:e,style:{fontSize:12,color:C.muted,cursor:"pointer"},children:o.jsx("span",{style:{borderBottom:`1px dotted ${C.muted}`},children:Z().msgEdited})})}function lAe({row:e,index:t,dimmed:n,ctx:r}){var c;const i=Z(),s=((c=r.editing)==null?void 0:c.rowIndex)===t,a=r.holdFor(e,t),l=r.editable&&e.edited&&!s?e.edited:null;return o.jsxs(o.Fragment,{children:[e.attachments&&e.attachments.length>0&&o.jsx(eq,{attachments:e.attachments}),o.jsxs("div",{style:{alignSelf:"flex-end",display:"flex",flexDirection:"column",alignItems:"flex-end",gap:5,maxWidth:"84%",...n?If:{}},children:[s&&o.jsx("span",{style:{fontSize:12,fontWeight:600,color:C.run,background:"var(--proto-accent-bg)",padding:"2px 7px",borderRadius:6},children:i.chatEditingBadge}),e.systemOrigin&&o.jsx("span",{"data-bubble-label":"",style:{fontSize:12,fontWeight:600,color:C.muted},children:Mj(e.systemOrigin,i)}),o.jsx("div",{...a??{},"data-msg-bubble":a?t:void 0,style:oAe(e.pending,!!a,s),children:e.text}),l&&o.jsx(aAe,{onTap:r.onShowOriginal?()=>r.onShowOriginal(l):void 0})]}),s&&r.editing&&o.jsx(sAe,{editing:r.editing})]})}function cAe(e){const{row:t,dimmed:n,copyText:r}=e;return!t.systemOrigin||Ud(t.systemOrigin)==="bubble"?o.jsx(lAe,{...e}):o.jsxs("div",{style:n?If:void 0,children:[o.jsx(rAe,{row:t}),o.jsx(B0,{text:r})]})}function uAe({row:e,index:t,dimmed:n,copyText:r,ctx:i,inWork:s}){var l;const a=Z();return o.jsxs("div",{"data-chat-row":t,"data-narration":s?"true":void 0,style:{fontSize:s?14:15,lineHeight:1.6,color:s?C.sub:C.body,minWidth:0,overflowWrap:"break-word",wordBreak:"break-word",...s?{margin:"2px 0"}:{},...n?If:{}},children:[((l=i.regen)==null?void 0:l.has(t))&&o.jsxs("div",{style:{display:"flex",alignItems:"center",gap:5,fontSize:12,color:C.muted,marginBottom:4},children:[o.jsx("span",{style:{width:5,height:5,borderRadius:"50%",background:"var(--proto-line-3)",flex:"none"}}),a.msgRegenNote]}),o.jsx(JMe,{text:e.text,preview:e.preview,streamKey:i.streamKey,ts:e.ts}),e.attachments&&e.attachments.length>0&&o.jsx("div",{style:{marginTop:8},children:o.jsx(eq,{attachments:e.attachments,side:"left"})}),e.decisions&&e.decisions.length>0&&o.jsx(UV,{decisions:e.decisions,sessionId:i.streamKey,touch:!0}),o.jsx(B0,{text:r})]})}function Vs({dimmed:e,copyText:t,children:n}){return o.jsxs("div",{style:e?If:void 0,children:[n,o.jsx(B0,{text:t})]})}const dAe={divider:iAe,user:cAe,assistant:uAe,thinking:({row:e,dimmed:t})=>o.jsx(Vs,{dimmed:t,children:o.jsx(Uj,{text:e.text,preview:e.preview,touch:!0})}),subagent:({row:e,dimmed:t,copyText:n,ctx:r,background:i})=>o.jsx(Vs,{dimmed:t,copyText:n,children:o.jsx(QMe,{row:e,sessionId:r.streamKey,background:i})}),waitpoint:({row:e,dimmed:t,copyText:n})=>o.jsx(Vs,{dimmed:t,copyText:n,children:o.jsx(FV,{wait:e.wait,touch:!0})}),tools:({row:e,index:t,dimmed:n,copyText:r,ctx:i})=>o.jsx(Vs,{dimmed:n,copyText:r,children:o.jsx(uK,{row:e,sessionId:i.streamKey,live:t===i.liveTools})}),notice:({row:e,dimmed:t,copyText:n,ctx:r})=>{var i,s;return o.jsx(Vs,{dimmed:t,copyText:n,children:o.jsx(bV,{level:e.level,text:e.text,authAction:e.authAction,noticeAction:e.noticeAction,onNoticeAction:(i=r.interactions)==null?void 0:i.onCancelResume,noticeActionDone:(s=r.interactions)==null?void 0:s.resumeCancelled})})},interaction:({row:e,dimmed:t,copyText:n,ctx:r})=>o.jsxs("div",{style:{display:"flex",flexDirection:"column",...t?If:{}},children:[o.jsx(eAe,{row:e,interactions:r.interactions}),o.jsx(B0,{text:n})]}),"team-action":({row:e,dimmed:t,copyText:n})=>o.jsx(Vs,{dimmed:t,copyText:n,children:o.jsx(eK,{action:e.action,touch:!0})}),"team-updates":({row:e,dimmed:t,copyText:n})=>o.jsx(Vs,{dimmed:t,copyText:n,children:o.jsx(aK,{row:e,touch:!0})}),"board-action":({row:e,dimmed:t,copyText:n,ctx:r})=>o.jsx(Vs,{dimmed:t,copyText:n,children:o.jsx(Hq,{action:e.action,onOpen:i=>{var s;return(s=r.onOpenBoard)==null?void 0:s.call(r,i)},touch:!0})})};function W2(e){const t=dAe[e.row.kind];return o.jsx(t,{...e})}function fAe(e,t,n){return t?e.kind==="row"&&n[e.index].kind==="divider"?24:t.kind==="row"&&n[t.index].kind==="divider"?16:e.segment!==t.segment?26:6:0}function pAe({rows:e,start:t=0,interactions:n,editing:r,onLongPress:i,onShowOriginal:s,onOpenBoard:a,streamKey:l,group:c=!1,live:u=!1}){const d=f.useMemo(()=>c?qj(e,{live:u}):null,[e,c,u]),p=f.useMemo(()=>{const S=fU(e,{live:u});return d?WV(d,S,e):S},[e,d,u]),h=(r==null?void 0:r.rowIndex)??null,m=f.useMemo(()=>pU(e,!!u),[e,u]),v={interactions:n,streamKey:l,editing:r,onShowOriginal:s,onOpenBoard:a,liveTools:m,editable:!!i,regen:i?dU(e):null,holdFor:(S,j)=>i&&h==null&&S.kind==="user"&&!S.systemOrigin?iTe(w=>i(j,w)):null},g=(S,j)=>S.kind==="interaction"&&S.detail?`int-${S.detail.id}`:S.kind==="team-updates"?`team-${S.id}`:j,x=S=>h!=null&&S>h;if(!d)return o.jsx(o.Fragment,{children:e.slice(t).map((S,j)=>{const w=t+j;return o.jsx(W2,{row:S,index:w,dimmed:x(w),copyText:p.get(w),ctx:v},g(S,w))})});const y=[];let b;return d.forEach((S,j)=>{const w=BV(S);if(w[w.length-1]<t)return;const R=fAe(S,b,e);if(R&&y.push(o.jsx("div",{"aria-hidden":"true",style:{height:R,flex:"none"}},`gap-${j}`)),b=S,S.kind==="row"){const T=e[S.index];y.push(o.jsx(W2,{row:T,index:S.index,dimmed:x(S.index),copyText:p.get(j),ctx:v,background:S.role==="pinned"&&T.kind==="subagent"},g(T,S.index)));return}y.push(o.jsx("div",{style:x(S.indexes[0])?If:void 0,children:o.jsx(OV,{stats:S.stats,live:S.live,touch:!0,footer:o.jsx(B0,{text:p.get(j)}),children:S.indexes.map(T=>o.jsx(W2,{row:e[T],index:T,dimmed:!1,ctx:v,inWork:!0},g(e[T],T)))})},S.key))}),o.jsx("div",{style:{display:"flex",flexDirection:"column",minWidth:0},children:y})}function hAe({text:e}){return o.jsxs("div",{style:{alignSelf:"center",display:"flex",alignItems:"center",gap:6,fontSize:12,color:C.muted,background:"var(--material-control-bg)",boxShadow:"var(--material-control-shadow)",border:"1px solid var(--proto-line-2)",padding:"3px 10px",borderRadius:"var(--r-pill)"},children:[o.jsx("span",{style:{width:5,height:5,borderRadius:"50%",background:C.faint}}),e]})}const dK=`var(${jy})`,ZM=`calc(${dK} + 12px)`;function mAe({props:e,shellHeight:t,tailHeight:n,onShowOriginal:r,onOpenBoard:i}){var m;const{scrollRef:s,contentRef:a,win:l,unseen:c,onScroll:u,onContentClick:d}=fMe(e,t+20),p=`calc(100% - ${t+20}px - env(safe-area-inset-bottom))`,h=`linear-gradient(to bottom, transparent ${dK}, #000 ${ZM}, #000 calc(${p} - 48px), transparent ${p})`;return o.jsxs(o.Fragment,{children:[o.jsx("div",{ref:s,onScroll:u,onClick:d,"data-transcript-scroller":!0,style:{flex:1,minHeight:0,overflow:"auto",scrollbarGutter:"stable",isolation:"isolate",maskImage:h,WebkitMaskImage:h,"--transcript-sticky-top":ZM},children:o.jsxs("div",{ref:a,style:{padding:"var(--transcript-sticky-top) 16px 0",display:"flex",flexDirection:"column",gap:16},children:[e.transcriptError&&e.rows.length===0&&e.onRetryTranscript&&o.jsx(hV,{onRetry:e.onRetryTranscript}),o.jsx(pAe,{rows:e.rows,start:l.start,interactions:e.interactions,editing:e.editing,onLongPress:e.onLongPress,onShowOriginal:v=>r(v.originalText),onOpenBoard:i,streamKey:e.sessionId,group:!0,live:e.live}),o.jsx(lK,{touch:!0}),o.jsx(_V,{running:!!e.live,touch:!0}),(m=e.systemLines)==null?void 0:m.map((v,g)=>o.jsx(hAe,{text:v},g)),o.jsx("div",{"data-composer-clearance":!0,style:{height:`calc(${n}px + env(safe-area-inset-bottom))`,flex:"none"}})]})}),o.jsx(vV,{target:c.target,onJump:c.jump,touch:!0,bottom:`calc(${t+30}px + env(safe-area-inset-bottom))`})]})}function gAe({props:e,shellRef:t,overlay:n,selection:r}){var l;const i=Z(),s=!!(e.editing||e.rejectBar),a=!s&&((l=e.slashSuggestions)!=null&&l.length)&&e.onSlashPick?o.jsx(Y9e,{suggestions:e.slashSuggestions,onPick:e.onSlashPick}):void 0;return o.jsx(Sme,{shellRef:t,placeholder:e.composerPlaceholder??(e.attachments.length>0?i.chatAttachPlaceholder:i.chatComposerPh),value:e.composerValue,onChange:e.onComposerChange,onSend:e.onSend,sendEnabled:e.sendEnabled,running:e.status.running,onStop:e.onStop,stopEnabled:e.stopEnabled,leading:s?void 0:o.jsx(q9e,{onClick:()=>n.toggle("attach")}),tools:s?null:o.jsx(K9e,{selection:e.selection,view:r,clean:e.cleanDraft}),above:o.jsx($9e,{props:e,overlay:n}),commandMenu:a,onPlus:()=>n.toggle("attach"),lineUnit:i.chatLineUnit,charUnit:i.chatCharUnit,tone:e.editing?"accent":e.rejectBar?"amber":"default"})}function vAe({props:e,overlay:t,selection:n}){const{composerRef:r,tailHeight:i,shellHeight:s}=FRe(),a=e.msgMenu?e.rows[e.msgMenu.rowIndex]:void 0;return o.jsxs("div",{style:{position:"relative",flex:1,minHeight:0,display:"flex",flexDirection:"column"},children:[o.jsx(mAe,{props:e,shellHeight:s,tailHeight:i,onShowOriginal:t.showOriginal,onOpenBoard:t.openBoard}),o.jsx(gAe,{props:e,shellRef:r,overlay:t,selection:n}),e.msgMenu&&a&&o.jsx(fTe,{row:a,menu:e.msgMenu})]})}function xAe(e,t){return!e.contextUsageSupported&&e.contextUsage==null?null:o.jsx(dV,{usage:e.contextUsage??null,variant:"mobile",onClick:t,"data-context-usage-position":"chat-header","data-context-compact-enabled":e.contextCompactAction?"true":void 0,style:yAe})}const yAe={width:44,height:44,borderRadius:"50%",background:"transparent",border:0,flexShrink:0,boxSizing:"border-box",justifyContent:"center"};function bAe(e){var s;const t=ORe(e.sessionId??""),n=G9e(e.onAddFiles),r=DRe(e.selection,Z()),i=rTe();return o.jsx(cK,{workers:e.workers??XMe,leadRunning:e.status.running,onOpenWorker:e.onOpenWorkerFromChat??e.onOpenWorker,children:o.jsx(NV,{backgroundRunning:!!e.backgroundRunning,waitpoints:((s=e.waitpoints)==null?void 0:s.waitpoints)??ZMe,children:o.jsxs("div",{ref:i.rootRef,"data-screen-label":"1b chat detail",style:{height:"100%",position:"relative",display:"flex",flexDirection:"column",boxSizing:"border-box"},children:[n.input,o.jsx("div",{ref:i.stackRef,"data-chat-header-stack":"",style:UMe,children:o.jsx(KMe,{title:e.title,parent:e.parent,status:e.status,onBack:e.onBack,onMore:()=>t.toggle("more"),contextControl:xAe(e,()=>t.open("context")),clean:e.cleanWorkspace?{onOpen:e.cleanWorkspace.dir?()=>t.open("workspace"):null}:null})}),o.jsx(vAe,{props:e,overlay:t,selection:r}),o.jsx(IRe,{props:e,overlay:t,selection:r,files:n})]})})})}function wAe(e){var t;for(const n of e)if(!(n.kind!=="interaction"||((t=n.detail)==null?void 0:t.status)!=="pending")&&!(n.detail.kind==="ask-user"&&n.detail.payload.blocking===!1))return{detail:n.detail,ts:n.ts??null};return null}function SAe(e){const[t,n]=f.useState({}),r=a=>t[a]??fk,i=(a,l)=>{n(c=>({...c,[a.requestId]:l})),kCe(a,l)&&e.answerQuestion(a.requestId,jCe(a,l))};return{stateOf:r,answerCurrent:(a,l)=>{const c=r(a.requestId),u=a.questions[qh(a,c)];u&&i(a,KV(c,u.question,l))},toggle:(a,l)=>{n(c=>({...c,[a.requestId]:wCe(r(a.requestId),l)}))},confirmMulti:a=>{const l=r(a.requestId),c=a.questions[qh(a,l)];c&&l.selected.length>0&&i(a,SCe(l,c.question))}}}function kAe(e){const[t,n]=f.useState(null),r=_n(),i=qe();return f.useEffect(()=>{const s=r.state;s!=null&&s.rejectPlan&&(n(s.rejectPlan),i(r.pathname,{replace:!0}))},[r.state]),f.useEffect(()=>{t&&t!==e&&n(null)},[t,e]),{rejectingId:t,setRejectingId:n}}function jAe(e){const t=M(),n=qe(),r=f.useMemo(()=>wAe(e.rows),[e.rows]),i=(r==null?void 0:r.detail.kind)==="ask-user"?qV(r.detail,r.ts):null,s=(r==null?void 0:r.detail.kind)==="plan-approval"?Gj(r.detail,r.ts,t):null,a=SAe(e.actions),{rejectingId:l,setRejectingId:c}=kAe((s==null?void 0:s.requestId)??null),u=!e.editing&&!!l&&l===(s==null?void 0:s.requestId),d=i?qh(i,a.stateOf(i.requestId)):0,p=h=>{if(u)e.actions.rejectPlan(l,h),c(null);else if(i)a.answerCurrent(i,h);else return!1;return e.setText(""),!0};return{interactions:{askState:a.stateOf,onAskPick:a.answerCurrent,onAskToggle:a.toggle,onAskConfirmMulti:a.confirmMulti,rejectingId:u?l:null,onApprove:h=>e.actions.approvePlan(h.requestId),onRejectStart:h=>c(h.requestId),onOpenRead:h=>n(`/m/session/${e.sessionId}/plan/${h.requestId}`),onCancelResume:e.actions.cancelResume,resumeCancelled:e.actions.resumeCancelled},rejectArmed:u,rejectBar:u&&s?{title:G(t.chatRejectTitle,{title:s.title}),chips:[t.chatRejectChipScope,t.chatRejectChipDryRun,t.chatRejectChipBudget,t.chatRejectChipOrder],onChipTap:h=>e.setText(m=>m?`${m}${t.chatRejectChipJoin}${h}`:h),onCancel:()=>c(null)}:void 0,answering:!!i,headerStatus:r?QCe(r.detail.kind,d,(i==null?void 0:i.questions.length)??1,t):null,placeholder:u?t.chatRejectPh:i?G(t.chatAskPh,{n:Math.min(d+1,i.questions.length)}):void 0,disarmReject:()=>c(null),submit:p}}function tp(e){return!!e&&e.kind==="user"&&e.turnIndex!==void 0}function CAe(e){const{rows:t,running:n,setText:r,rewind:i}=e,[s,a]=f.useState(null),[l,c]=f.useState(null),[u,d]=f.useState(null),p=f.useRef(""),h=()=>{a(null),r(p.current),p.current=""},m=b=>{const S=t[b];!tp(S)||n||(p.current=e.text,e.onStart(),a(b),r(S.text))};f.useEffect(()=>{s!=null&&(tp(t[s])||h())},[t,s]);const v=s!=null?t[s]:null,g=tp(v),x=l!=null?t[l]:null,y=x&&(x.kind==="user"||x.kind==="assistant")?{rowIndex:l,anchorTop:u,onCopy:()=>{E0(x.text)},...tp(x)?{onEdit:()=>m(l),editDisabled:n||i.pending}:{},onClose:()=>c(null)}:null;return{armed:g,editing:g?{rowIndex:s,...uU(t,s),onCancel:h}:null,msgMenu:y,hold:(b,S)=>{d(S),c(b)},submit:b=>{tp(v)&&i.submit(v.turnIndex,b).then(h,()=>{})}}}const JM="/m/session/new";function TAe(){const{sessionId:e}=fW(),t=e==="new",n=Zi("direct"),r=Zi("scheduled"),i=f.useMemo(()=>[...n.data??[],...r.data??[]].find(u=>u.sessionId===e)??null,[n.data,r.data,e]),{currentProjectId:s,setCurrentProject:a}=Wt(),l=t?null:(i==null?void 0:i.projectId)??null;return f.useEffect(()=>{l&&l!==s&&a(l)},[l,s,a]),{routeParam:e,isDraft:t,active:t?null:i,sessionId:t?"":(i==null?void 0:i.sessionId)??e??"",projectId:s,directSessions:n.data,scheduledSessions:r.data}}function EAe(e,t,n){const[r,i]=f.useState(null);return f.useEffect(()=>{if(!r)return;const s=e===r.sessionId,a=!t&&n!==r.sessionId;(s||a)&&i(null)},[e,t,r,n]),[r,i]}function RAe(e){if(!e.isDraft)return{cleanDraft:null,cleanWorkspace:e.clean?{dir:e.workspaceDir}:null};const t=!!e.draft.clean;return{cleanDraft:{on:t,disabled:e.creating,onToggle:()=>e.setDraft({clean:!t})},cleanWorkspace:null}}function MAe(e){const t=M(),n=Qe();return f.useMemo(()=>{var r;return((r=JU((e==null?void 0:e.totals)??null,ZU(e==null?void 0:e.createdAt,e==null?void 0:e.lastUsedAt),{scope:t.wbSessionScope,turnsUnit:t.wbTurnsUnit,runsUnit:t.wbRunsUnit,runsLabel:t.wbStatRuns,turnsLabel:t.wbStatTurns,activeLabel:t.wbStatActive,spanLabel:t.wbStatSpan,costLabel:t.wbStatCost,subagentLabel:t.wbStatSubagent},n))==null?void 0:r.rows)??null},[e==null?void 0:e.totals,e==null?void 0:e.createdAt,e==null?void 0:e.lastUsedAt,t,n])}function AAe(e,t){var r,i;const n=IU(e);return{id:e.id,name:((r=e.file)==null?void 0:r.name)??((i=e.meta)==null?void 0:i.name)??t,progress:e.progress,status:e.status,type:n==="image"||n==="video"?n:"file",previewUrl:e.previewUrl}}function PAe(e){const{edit:t,routing:n,composer:r}=e,i=!!e.text.trim()&&!e.uploadsBusy,s=t.armed||n.rejectArmed||n.answering,a=t.armed?e.rewindPending:e.interactionsBusy,l=s?i&&!a:r.canSend;return{sendEnabled:l,onSend:()=>{if(!s){r.submit();return}l&&(t.armed?t.submit(e.text.trim()):n.submit(e.text.trim()))}}}function IAe(){const e=qe(),t=_n(),n=Qe(),r=M(),i=TAe(),{isDraft:s,active:a,sessionId:l}=i,c=eV(a,i.directSessions),u=AU(l,a,{isDraft:s,projectId:i.projectId??"general",scheduledRuns:i.scheduledSessions}),d=f.useMemo(()=>YCe(u.transcript,u.liveTail,{streaming:u.streaming,running:u.running,streamingText:u.streamingText,thinkingText:u.thinkingText,pendingUser:u.pendingUser,stripScheduledPrefix:!!(a!=null&&a.scheduleId)||u.isScheduledRun,lang:n}),[u.transcript,u.liveTail,u.streaming,u.running,u.streamingText,u.thinkingText,u.pendingUser,a==null?void 0:a.scheduleId,u.isScheduledRun,n]),[p,h]=f.useState([]),m=z=>h(J=>[...J,z]),[v,g]=XU(s),[x,y]=EAe(a==null?void 0:a.sessionId,s,l),b=QU({sessionId:l,isDraft:s,hasHistory:u.hasHistory,currentSelection:a==null?void 0:a.selection,currentAgent:a==null?void 0:a.agentName,draftSelection:v,setDraftSelection:g,pendingCreatedSession:x}),S=z=>{z.modelOption?b.pickModel(z.modelOption):b.apply(z.change)},j=f.useRef(!1);j.current=s&&L6(t.pathname)===JM;const w=WU({sessionId:l,isDraft:s,projectId:i.projectId??"general",optimistic:u.optimistic,running:u.running,compactAction:u.compactAction,creation:{selection:v},slash:{modelOptions:b.favoriteOptions,backend:b.effective.backend,agentName:b.agentName,onNew:()=>e(JM),onModel:z=>b.pickModel(z),onSettings:()=>e("/m/settings"),onUsage:()=>e("/m/settings/usage",{state:{from:"chat"}})},onCreated:z=>{j.current&&(y({sessionId:z,selection:v.selection,agentName:v.agentName??null,...v.clean?{clean:!0}:{}}),e(`/m/session/${z}`,{replace:!0,state:Ume}))},onSendFailed:z=>m(G(r.chatSendFailed,{error:z.message})),onSlashFeedback:z=>{z&&m(r[z])}}),{text:R,setText:T,uploads:A}=w,P=CAe({rows:d,running:u.running,text:R,setText:T,rewind:u.rewind,onStart:()=>L.disarmReject()}),L=jAe({rows:d,sessionId:l,actions:u.interactionActions,editing:P.armed,setText:T}),{sendEnabled:F,onSend:B}=PAe({edit:P,routing:L,composer:w,text:R,uploadsBusy:A.hasNonDone,rewindPending:u.rewind.pending,interactionsBusy:!!u.interactionActions.busy}),K=MAe(a),V=XCe({isDraft:s,running:u.running,backgroundRunning:u.backgroundRunning,starting:u.pendingUser.length>0,turns:u.turns,cost:(a==null?void 0:a.costUsd)??null,turnClock:u.turnClock,waitingOn:(a==null?void 0:a.waitingOn)??0,workers:Ja(c.workers).active.length,lastUsedAt:(a==null?void 0:a.lastUsedAt)??null},r,n),Q=L.headerStatus??{running:V.active,tone:V.active?"running":"idle",text:V.text,liveText:V.liveText},re=s?r.newSession:a?v1(a,u.runTitle):i.routeParam??"",ue=u.isScheduledRun?r.chatScheduledHint:null;return o.jsx(bAe,{title:re,parent:c.lead?{title:v1(c.lead,null),onSelect:()=>e(`/m/session/${c.lead.sessionId}`)}:null,workers:c.workers,onOpenWorker:z=>e(`/m/session/${z}`,{replace:!0}),onOpenWorkerFromChat:z=>e(`/m/session/${z}`),boardId:s?null:(a==null?void 0:a.boardId)??null,onOpenBoardSession:z=>{z!==l&&e(`/m/session/${z}`)},metadataSession:!s&&a?{sessionId:a.sessionId,title:re,starred:a.starred}:null,status:Q,rows:d,live:u.running&&!u.backgroundRunning,backgroundRunning:u.backgroundRunning,loading:!!l&&u.transcriptPending,fetched:u.transcriptFetched,readMark:!s&&a?{lastReadAt:a.lastReadAt,origin:a.origin}:void 0,transcriptError:u.transcriptError,onRetryTranscript:u.retryTranscript,onBack:()=>Kt(e,"/m/sessions"),sessionStatsRows:K,backendUuid:(a==null?void 0:a.backendSessionId)??null,systemLines:ue?[...p,ue]:p,interactions:L.interactions,rejectBar:L.rejectBar,msgMenu:P.msgMenu,onLongPress:P.hold,editing:P.editing,sessionId:l,todos:u.todos,waitpoints:u.waitpoints,composerValue:R,onComposerChange:T,onSend:B,onCommands:w.openCommands,slashSuggestions:P.armed||L.rejectArmed||L.answering?[]:w.slashSuggestions,onSlashPick:z=>{w.pickSlash(z)},sendEnabled:F,composerPlaceholder:L.placeholder,onStop:w.stop,stopEnabled:!w.stopPending,selection:b,onPickSelection:S,...RAe({isDraft:s,draft:v,setDraft:g,creating:w.creating,clean:YU(a==null?void 0:a.clean,x,l),workspaceDir:(a==null?void 0:a.workspaceDir)??null}),contextUsage:u.contextUsage,contextUsageSupported:!!(a!=null&&a.contextCompactionSupported),contextCompactAction:u.compactAction,attachments:A.items.map(z=>AAe(z,r.chatFileFallback)),onRemoveAttachment:A.remove,onRetryAttachment:A.retry,onAddFiles:A.addFiles})}function fK(e,t,n){if(n<=t)return 100;const r=Math.round((e+t)/n*100);return Math.max(0,Math.min(100,r))}function m7(e,t){switch(e){case"pending":return t.ixStatusPending;case"approved":return t.ixStatusApproved;case"rejected":return t.ixStatusRejected;case"cancelled":return t.ixStatusCancelled;default:return t.ixStatusExpired}}function pK(e,t,n,r){const i=G(r.cmLines,{n:t});return[e,i,n].filter(Boolean).join(" · ")}function LAe({model:e,onBack:t,onApprove:n,onReject:r}){const i=e.status==="pending",s=Z(),[a,l]=f.useState(0),c=f.useRef(null),u=()=>{const h=c.current;if(!h)return;const m=fK(h.scrollTop,h.clientHeight,h.scrollHeight);l(v=>Math.max(v,m))},d=m7(e.status,s),p=e.status==="approved"?{text:`${s.ixPlanApprovedPill}${e.timeLabel?` · ${e.timeLabel} ${s.ixApprovedBy}`:""}`,fg:C.done,bg:C.doneBg}:e.status==="rejected"?{text:`${s.ixPlanRejectedPill}${e.timeLabel?` · ${e.timeLabel}`:""}`,fg:C.grayInk,bg:C.gray}:e.status==="cancelled"?{text:s.ixCancelled,fg:C.grayInk,bg:C.gray}:{text:s.ixExpired,fg:C.grayInk,bg:C.gray};return o.jsxs("div",{"data-screen-label":"6b plan read",style:{height:"100%",display:"flex",flexDirection:"column",boxSizing:"border-box",position:"relative"},children:[o.jsxs("div",{style:{flex:"none",padding:"8px 14px 10px 8px",paddingTop:"calc(8px + env(safe-area-inset-top))",borderBottom:`1px solid ${C.hairline}`,background:C.glassRaised},children:[o.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6},children:[o.jsx("button",{type:"button","aria-label":s.back,onClick:t,style:{border:"none",background:"transparent",color:C.ink,padding:0,margin:0,cursor:"pointer",flex:"none",minHeight:44,minWidth:44,display:"grid",placeItems:"center"},children:o.jsx(Ds,{})}),o.jsxs("div",{style:{minWidth:0},children:[o.jsx("div",{style:{fontSize:15.5,fontWeight:620,color:C.ink,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:e.title}),o.jsxs("div",{style:{fontSize:12.5,color:C.muted,marginTop:1,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",...$e},children:[e.filePath&&o.jsx("span",{style:{font:"400 11.5px var(--font-code)"},children:e.filePath}),e.filePath?" · ":"",pK(null,e.lineCount,d,s)]})]}),i?o.jsx("span",{style:{marginLeft:"auto",fontSize:12,fontWeight:600,color:C.amberInk,background:C.amberBg,padding:"2px 8px",borderRadius:"var(--r-pill)",flex:"none"},children:s.ixPlanPending}):o.jsx("span",{style:{marginLeft:"auto",fontSize:12,fontWeight:600,color:p.fg,background:p.bg,padding:"2px 8px",borderRadius:"var(--r-pill)",flex:"none"},children:d})]}),i&&o.jsx("div",{style:{height:3,borderRadius:"var(--r-pill)",background:"var(--proto-line)",overflow:"hidden",marginTop:9},children:o.jsx("div",{style:{width:`${a}%`,height:"100%",background:C.run}})})]}),o.jsxs("div",{style:{flex:1,minHeight:0,position:"relative",background:"var(--proto-card)"},children:[o.jsxs("div",{ref:c,onScroll:u,style:{position:"absolute",inset:0,overflow:"auto",padding:"16px 18px 24px",boxSizing:"border-box"},children:[e.timeLabel&&o.jsx("div",{style:{fontSize:12,color:C.muted,paddingBottom:8,...$e},children:e.timeLabel}),o.jsx("div",{style:{fontSize:14.5,lineHeight:1.7,color:C.body,overflowWrap:"anywhere"},children:o.jsx(br,{text:e.planContent})}),e.status==="rejected"&&e.feedback&&o.jsxs("div",{style:{marginTop:16,border:`1px solid ${C.amberBorder}`,background:C.amberCard,borderRadius:"var(--r-control)",padding:"10px 13px"},children:[o.jsx("div",{style:{fontSize:12.5,fontWeight:600,color:C.amberText,paddingBottom:4},children:s.ixRejectFeedback}),o.jsx("div",{style:{fontSize:12.5,lineHeight:1.6,color:"var(--proto-amber-fg)",whiteSpace:"pre-wrap"},children:e.feedback})]})]}),o.jsx("div",{style:{position:"absolute",left:0,right:0,bottom:0,height:56,background:"linear-gradient(180deg,var(--proto-card-transparent),var(--proto-card))",pointerEvents:"none"}})]}),o.jsx("div",{style:{flex:"none",background:"var(--proto-card)",borderTop:"1px solid var(--proto-line-2)",padding:"10px 14px",paddingBottom:"calc(14px + env(safe-area-inset-bottom))"},children:i?o.jsxs("div",{style:{display:"flex",gap:10},children:[o.jsx("button",{type:"button",onClick:r,style:{flex:1,height:48,borderRadius:"var(--r-control)",border:"1px solid var(--proto-line-3)",background:"var(--material-control-bg)",color:C.ink,fontFamily:"var(--font-ui)",fontSize:15,fontWeight:600,boxSizing:"border-box",cursor:"pointer"},children:s.ixRejectNote}),o.jsx("button",{type:"button",onClick:n,style:{flex:1,height:48,borderRadius:"var(--r-control)",background:C.inkSolid,color:C.inkSolidFg,border:"none",display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",gap:1,cursor:"pointer"},children:o.jsx("span",{style:{fontFamily:"var(--font-ui)",fontSize:15,fontWeight:600},children:s.ixApprovePlan})})]}):o.jsx("div",{style:{minHeight:48,padding:"8px 12px",boxSizing:"border-box",overflowWrap:"anywhere",borderRadius:"var(--r-control)",background:p.bg,color:p.fg,display:"flex",alignItems:"center",justifyContent:"center",fontSize:13.5,fontWeight:600},children:p.text})})]})}function NAe(){const{sessionId:e="",requestId:t=""}=fW(),n=qe(),r=M(),i=jU(e);SU(e,void 0);const s=kU(e),a=ICe(i.data,t),l=()=>Kt(n,`/m/session/${e}`);if(!a)return o.jsxs("div",{style:{height:"100%",display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",gap:10},children:[o.jsx("div",{style:{fontSize:13,color:C.muted},children:i.isPending?"…":r.ixPlanNotFound}),o.jsx("button",{type:"button",onClick:l,style:{border:"1px solid var(--proto-line-3)",background:"var(--material-control-bg)",borderRadius:"var(--r-control)",minHeight:44,padding:"0 16px",fontFamily:"var(--font-ui)",fontSize:14,fontWeight:600,color:C.ink,cursor:"pointer"},children:r.ixBackToChat})]});const c=Gj(a.detail,a.ts,r);return o.jsx(LAe,{model:c,onBack:l,onApprove:()=>{c.status==="pending"&&s.approvePlan(c.requestId)},onReject:()=>n(`/m/session/${e}`,{state:{rejectPlan:t}})})}const B2="—";function DAe(e,t){switch(e){case"pending":return{text:t.apprPillPending,bg:"var(--pill-waiting-bg)",fg:"var(--pill-waiting-fg)"};case"approved":return{text:t.apprPillApproved,bg:"var(--pill-done-bg)",fg:"var(--pill-done-fg)"};case"rejected":return{text:t.apprPillRejected,bg:"var(--pill-failed-bg)",fg:"var(--pill-failed-fg)"};case"failed":return{text:t.apprPillFailed,bg:"var(--pill-failed-bg)",fg:"var(--pill-failed-fg)"}}}function OAe(e,t){return G(e===1?t.apprPendingOne:t.apprPendingMany,{n:e})}function FAe(e){return{id:e.id,title:e.title,age:e.queuedAt,origin:e.provenance,project:e.projectId}}function _Ae(e,t){const n=e.command;return{id:e.id,title:e.title,project:e.projectId,pill:DAe(e.status,t),queued:e.queuedAt?G(t.apprQueuedAt,{date:e.queuedAt}):null,operation:e.operation??B2,reason:e.reason??B2,impact:e.impact??B2,command:n,hasCommand:n!=null&&n.trim()!=="",feedback:e.feedback,origin:e.provenance,task:e.taskRef}}function Dy(e,t){var n;return t&&e.some(r=>r.id===t)?t:((n=e[0])==null?void 0:n.id)??null}function hK({enabled:e=!0}={}){const t=ve(),n=_e(),r=xe({...t.approvals.list.queryOptions({status:"pending"}),enabled:e}),i=()=>n.invalidateQueries(t.approvals.list.queryFilter()),s=Se(t.approvals.approve.mutationOptions({onSettled:i})),a=Se(t.approvals.reject.mutationOptions({onSettled:i})),l=async u=>{await s.mutateAsync({id:u})},c=async(u,d="")=>{await a.mutateAsync({id:u,feedback:d.trim()||void 0})};return{entries:r.data??[],approve:l,reject:c,isPending:s.isPending||a.isPending}}function zAe({vm:e,expandedId:t,feedback:n,busy:r,onBack:i,onExpand:s,onFeedback:a,onApprove:l,onReject:c,onOpenPlan:u}){const d=Z();return o.jsx(hl,{label:"1f approvals",header:o.jsxs(L0,{onBack:i,children:[o.jsx("div",{style:{fontSize:16,fontWeight:650,color:C.ink,flex:"none"},children:d.approvals}),o.jsxs("span",{"data-approvals-pending":"",style:{fontSize:13,fontWeight:600,color:e.pendingCount>0?"var(--proto-amber-fg)":C.muted,flex:"none",...$e},children:[e.pendingCount," ",d.apprToProcess]})]}),children:o.jsxs(kf,{gap:10,children:[e.pendingCount===0&&o.jsx("div",{style:{padding:"40px 0",textAlign:"center",color:C.muted,fontSize:13},children:d.apprEmpty}),e.groups.map(p=>o.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:10},children:[o.jsx(WAe,{label:p.projectId??d.apprGlobalGroup}),p.plans.map(h=>o.jsx(DW,{leading:o.jsx(gK,{children:d.ixPlan}),title:h.title,sub:h.session,onExpand:()=>u(h)},h.requestId)),p.cards.map(h=>h.id===t?o.jsx(BAe,{card:h,copy:d,feedback:n,busy:r,onFeedback:a,onApprove:l,onReject:c},h.id):o.jsx($Ae,{card:h,copy:d,onExpand:s},h.id))]},p.projectId??"__global__"))]})})}function WAe({label:e}){return o.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10,padding:"2px 2px 0"},children:[o.jsx("div",{style:{fontSize:13,fontWeight:600,color:C.muted},children:e}),o.jsx("div",{style:{flex:1,height:1,background:"var(--proto-line)"}})]})}function mK({copy:e,operation:t}){return o.jsxs(gK,{children:[e.apprTier," · ",t]})}function gK({children:e}){return o.jsx("span",{style:{fontSize:12,fontWeight:600,padding:"2px 8px",borderRadius:"var(--r-pill)",background:C.amberBg,color:C.amberInk,minWidth:0,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:e})}function BAe({card:e,copy:t,feedback:n,busy:r,onFeedback:i,onApprove:s,onReject:a}){return o.jsxs(F6,{tone:"amber",padding:0,style:{overflow:"hidden",boxShadow:"var(--material-card-shadow)"},children:[o.jsxs("div",{style:{padding:"12px 14px 0"},children:[o.jsxs("div",{style:{display:"flex",alignItems:"center",gap:7,overflow:"hidden"},children:[e.operation&&o.jsx(mK,{copy:t,operation:e.operation}),o.jsx("span",{style:{font:`400 11px ${qn}`,color:C.amberText,flex:1,minWidth:0,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:e.id}),e.time&&o.jsx("span",{style:{fontSize:12,color:C.muted,flex:"none",...$e},children:e.time})]}),o.jsx("div",{style:{fontSize:16,fontWeight:650,color:C.ink,lineHeight:1.4,marginTop:8},children:e.title}),e.reason&&o.jsx("div",{style:{fontSize:12,lineHeight:1.55,color:C.sub,marginTop:4},children:e.reason}),e.impact&&o.jsx("div",{style:{fontSize:12,lineHeight:1.55,color:C.sub,marginTop:4},children:e.impact}),e.command&&o.jsx("div",{style:{marginTop:8,padding:"8px 10px",background:C.amberCard,border:`1px solid ${C.amberBg}`,borderRadius:"var(--r-chip)",font:`400 11px ${qn}`,color:"var(--proto-amber-fg)",whiteSpace:"pre-wrap",wordBreak:"break-all"},children:e.command}),o.jsxs("div",{style:{fontSize:12,lineHeight:1.55,color:C.sub,marginTop:4},children:[e.provenance&&o.jsxs(o.Fragment,{children:[t.apFrom," ",o.jsx("span",{style:{color:C.ink,fontWeight:500},children:e.provenance})," · "]}),t.apprPaused]}),o.jsx("textarea",{"data-approval-feedback":!0,value:n,disabled:r,rows:2,onChange:l=>i(l.target.value),placeholder:t.apprFeedbackPlaceholder,"aria-label":t.apprFeedbackPlaceholder,style:{width:"100%",minHeight:58,marginTop:10,padding:"9px 10px",resize:"vertical",border:"1px solid var(--proto-line-3)",borderRadius:"var(--r-chip)",background:"var(--material-inset-bg)",color:C.ink,fontSize:16,lineHeight:1.45,fontFamily:"inherit",boxSizing:"border-box",opacity:r?.6:1}})]}),o.jsxs("div",{style:{display:"flex",gap:8,padding:"12px 14px 14px"},children:[o.jsx(pt,{variant:"outline",disabled:r,onClick:()=>a(e.id,n),style:{flex:1},children:t.apprRejectFeedback}),o.jsx(pt,{variant:"ink",disabled:r,onClick:()=>s(e.id),style:{flex:1},children:t.approve})]})]})}function $Ae({card:e,copy:t,onExpand:n}){const r=[e.id,e.provenance?`${t.apFrom} ${e.provenance}`:null,t.apprSeeDiff].filter(Boolean).join(" · ");return o.jsx(DW,{leading:e.operation&&o.jsx(mK,{copy:t,operation:e.operation}),title:e.title,meta:e.time,sub:r,onExpand:()=>n(e.id)})}function HAe(e,t,n){return{id:e.id,projectId:e.projectId,operation:e.operation,title:e.title,time:zr(e.queuedAt,t,n),reason:e.reason,impact:e.impact,command:e.command,provenance:e.provenance}}function eA(e){const t=new Map;for(const n of e){const r=n.projectId??"";t.set(r,[...t.get(r)??[],n])}return t}function UAe(e,t){const n=r=>r===t?0:r===""?1:2;return[...new Set(e)].sort((r,i)=>n(r)-n(i)||r.localeCompare(i))}function VAe(e,t,n,r,i=[]){const s=eA(e.filter(u=>u.status==="pending").map(u=>HAe(u,t,r))),a=eA(i),l=UAe([...s.keys(),...a.keys()],n).map(u=>({projectId:u===""?null:u,cards:s.get(u)??[],plans:a.get(u)??[]})),c=l.flatMap(u=>u.cards);return{pendingCount:c.length+i.length,groups:l,cards:c}}function qAe(){const e=ve(),t=Z(),n=Zi("direct").data,r=f.useMemo(()=>(n??[]).filter(a=>a.awaitingInput),[n]),i=y0({queries:r.map(a=>e.sessions.pendingInteraction.queryOptions({sessionId:a.sessionId}))}),s=[];return r.forEach((a,l)=>{var u,d;const c=(d=(u=i[l])==null?void 0:u.data)==null?void 0:d.plan;c&&s.push({sessionId:a.sessionId,requestId:c.requestId,projectId:a.projectId||null,title:YV(c.planContent,c.planFilePath,t),session:a.label??Ti(a.sessionId)})}),s}function KAe(e){const t=_n(),n=F0(new URLSearchParams(t.search).get("approvalId"))??null,[r,i]=f.useState(n),[s,a]=f.useState("");return f.useEffect(()=>{i(n),a("")},[n,t.key]),{expandedId:Dy(e,r),feedback:s,expand:d=>{a(""),i(d)},setFeedback:a,settle:d=>{d.catch(()=>{}).finally(()=>a(""))}}}function GAe(){const e=qe(),t=Qe(),n=hK(),r=qAe(),{currentProjectId:i}=Wt(),s=f.useMemo(()=>VAe(n.entries,Date.now(),i,t,r),[n.entries,i,t,r]),a=KAe(s.cards);return o.jsx(zAe,{vm:s,expandedId:a.expandedId,feedback:a.feedback,busy:n.isPending,onBack:()=>Kt(e,"/m/project"),onExpand:a.expand,onFeedback:a.setFeedback,onApprove:l=>a.settle(n.approve(l)),onReject:(l,c)=>a.settle(n.reject(l,c)),onOpenPlan:l=>e(`/m/session/${l.sessionId}/plan/${l.requestId}`)})}const YAe=/^\s*-\s+([^::]{1,30}?)\s*[::]\s*(.*)$/;function QAe(e){const t=[],n=[];let r=null;for(const i of e.split(`
499
499
  `)){const s=i.trim();if(s==="")continue;const a=i.match(YAe);if(a){r={label:a[1].trim(),text:a[2].trim()},t.push(r);continue}if(/^\s*-\s+/.test(i)){r=null,n.push(s.replace(/^-\s+/,""));continue}r?r.text+=`
500
500
  ${s}`:n.push(s)}return{fields:t,desc:n.length>0?n.join(`