@pasko70/pibo 3.4.3 → 3.4.4

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.
@@ -1,4 +1,4 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/dist-mpRGeo_R.js","assets/dist-CqM4On9D.js","assets/dist-S3zJGntM.js","assets/dist-DHvUPfrF.js","assets/dist-DLJCGrGQ.js","assets/dist-LCx98fA_.js","assets/dist-DpF08Yd7.js","assets/dist-C8GzUMPk.js","assets/dist-RKTRnzGb.js","assets/dist-fPhZsAUX.js","assets/dist-Cyb4rVa6.js","assets/dist-DeMKnZR8.js","assets/dist-DTeLDijr.js","assets/dist-eddbbGyw.js","assets/dist-BJ-TIk3N.js","assets/dist-DMiglryg.js","assets/dist-XVYGiB-c.js","assets/dist-CswnpKik.js","assets/dockerfile-DJkHQgkl.js","assets/simple-mode-DXiLM1-G.js","assets/factor-LKH5gN8L.js","assets/nsis-CfSuhXs5.js","assets/pug-Gsm0M45u.js","assets/javascript-DoL9Wb-Q.js","assets/dist-B4YhOxh0.js","assets/dist-BkUu8WPA.js"])))=>i.map(i=>d[i]);
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/dist-mpRGeo_R.js","assets/dist-CqM4On9D.js","assets/dist-S3zJGntM.js","assets/dist-DHvUPfrF.js","assets/dist-DLJCGrGQ.js","assets/dist-LCx98fA_.js","assets/dist-DpF08Yd7.js","assets/dist-23lt_7qm.js","assets/dist-RKTRnzGb.js","assets/dist-fPhZsAUX.js","assets/dist-DsgL8w-W.js","assets/dist-Bf2KScPo.js","assets/dist-DTeLDijr.js","assets/dist-eddbbGyw.js","assets/dist-BJ-TIk3N.js","assets/dist-DMiglryg.js","assets/dist-XVYGiB-c.js","assets/dist-CswnpKik.js","assets/dockerfile-DJkHQgkl.js","assets/simple-mode-DXiLM1-G.js","assets/factor-LKH5gN8L.js","assets/nsis-CfSuhXs5.js","assets/pug-Gsm0M45u.js","assets/javascript-DoL9Wb-Q.js","assets/dist-CH3SvpYV.js","assets/dist-V06sfuZa.js"])))=>i.map(i=>d[i]);
2
2
  import{a as e,n as t,o as n,s as r,t as i}from"./dist-DLJCGrGQ.js";import{$ as a,A as o,At as s,B as c,Bt as l,C as u,Ct as d,D as f,Dt as p,E as m,Et as h,F as g,Ft as _,G as v,H as y,Ht as b,I as x,It as S,J as C,K as w,L as T,Lt as E,M as D,N as O,Nt as k,O as A,P as j,Pt as M,Q as N,R as P,Rt as F,S as I,St as L,T as R,Tt as z,U as ee,V as te,Vt as ne,W as re,X as ie,Y as B,Z as ae,_ as oe,a as se,at as ce,b as le,bt as ue,c as de,ct as fe,d as pe,dt as me,et as he,f as ge,g as _e,gt as ve,h as ye,ht as be,i as xe,j as Se,jt as Ce,k as we,kt as Te,l as V,lt as Ee,m as De,mt as Oe,n as ke,nt as Ae,o as je,ot as Me,p as Ne,pt as Pe,q as Fe,r as Ie,rt as Le,s as Re,st as ze,t as Be,tt as Ve,u as He,ut as Ue,v as We,vt as Ge,w as Ke,wt as qe,x as Je,xt as Ye,y as Xe,yt as Ze,z as Qe,zt as $e}from"./dist-CqM4On9D.js";import{a as et,c as tt,i as nt,n as rt,o as it,r as at,s as ot,t as st}from"./dist-S3zJGntM.js";(function(){let e=document.createElement(`link`).relList;if(e&&e.supports&&e.supports(`modulepreload`))return;for(let e of document.querySelectorAll(`link[rel="modulepreload"]`))n(e);new MutationObserver(e=>{for(let t of e)if(t.type===`childList`)for(let e of t.addedNodes)e.tagName===`LINK`&&e.rel===`modulepreload`&&n(e)}).observe(document,{childList:!0,subtree:!0});function t(e){let t={};return e.integrity&&(t.integrity=e.integrity),e.referrerPolicy&&(t.referrerPolicy=e.referrerPolicy),t.credentials=e.crossOrigin===`use-credentials`?`include`:e.crossOrigin===`anonymous`?`omit`:`same-origin`,t}function n(e){if(e.ep)return;e.ep=!0;let n=t(e);fetch(e.href,n)}})();var ct=e((e=>{var t=Symbol.for(`react.transitional.element`),n=Symbol.for(`react.portal`),r=Symbol.for(`react.fragment`),i=Symbol.for(`react.strict_mode`),a=Symbol.for(`react.profiler`),o=Symbol.for(`react.consumer`),s=Symbol.for(`react.context`),c=Symbol.for(`react.forward_ref`),l=Symbol.for(`react.suspense`),u=Symbol.for(`react.memo`),d=Symbol.for(`react.lazy`),f=Symbol.for(`react.activity`),p=Symbol.iterator;function m(e){return typeof e!=`object`||!e?null:(e=p&&e[p]||e[`@@iterator`],typeof e==`function`?e:null)}var h={isMounted:function(){return!1},enqueueForceUpdate:function(){},enqueueReplaceState:function(){},enqueueSetState:function(){}},g=Object.assign,_={};function v(e,t,n){this.props=e,this.context=t,this.refs=_,this.updater=n||h}v.prototype.isReactComponent={},v.prototype.setState=function(e,t){if(typeof e!=`object`&&typeof e!=`function`&&e!=null)throw Error(`takes an object of state variables to update or a function which returns an object of state variables.`);this.updater.enqueueSetState(this,e,t,`setState`)},v.prototype.forceUpdate=function(e){this.updater.enqueueForceUpdate(this,e,`forceUpdate`)};function y(){}y.prototype=v.prototype;function b(e,t,n){this.props=e,this.context=t,this.refs=_,this.updater=n||h}var x=b.prototype=new y;x.constructor=b,g(x,v.prototype),x.isPureReactComponent=!0;var S=Array.isArray;function C(){}var w={H:null,A:null,T:null,S:null},T=Object.prototype.hasOwnProperty;function E(e,n,r){var i=r.ref;return{$$typeof:t,type:e,key:n,ref:i===void 0?null:i,props:r}}function D(e,t){return E(e.type,t,e.props)}function O(e){return typeof e==`object`&&!!e&&e.$$typeof===t}function k(e){var t={"=":`=0`,":":`=2`};return`$`+e.replace(/[=:]/g,function(e){return t[e]})}var A=/\/+/g;function j(e,t){return typeof e==`object`&&e&&e.key!=null?k(``+e.key):t.toString(36)}function M(e){switch(e.status){case`fulfilled`:return e.value;case`rejected`:throw e.reason;default:switch(typeof e.status==`string`?e.then(C,C):(e.status=`pending`,e.then(function(t){e.status===`pending`&&(e.status=`fulfilled`,e.value=t)},function(t){e.status===`pending`&&(e.status=`rejected`,e.reason=t)})),e.status){case`fulfilled`:return e.value;case`rejected`:throw e.reason}}throw e}function N(e,r,i,a,o){var s=typeof e;(s===`undefined`||s===`boolean`)&&(e=null);var c=!1;if(e===null)c=!0;else switch(s){case`bigint`:case`string`:case`number`:c=!0;break;case`object`:switch(e.$$typeof){case t:case n:c=!0;break;case d:return c=e._init,N(c(e._payload),r,i,a,o)}}if(c)return o=o(e),c=a===``?`.`+j(e,0):a,S(o)?(i=``,c!=null&&(i=c.replace(A,`$&/`)+`/`),N(o,r,i,``,function(e){return e})):o!=null&&(O(o)&&(o=D(o,i+(o.key==null||e&&e.key===o.key?``:(``+o.key).replace(A,`$&/`)+`/`)+c)),r.push(o)),1;c=0;var l=a===``?`.`:a+`:`;if(S(e))for(var u=0;u<e.length;u++)a=e[u],s=l+j(a,u),c+=N(a,r,i,s,o);else if(u=m(e),typeof u==`function`)for(e=u.call(e),u=0;!(a=e.next()).done;)a=a.value,s=l+j(a,u++),c+=N(a,r,i,s,o);else if(s===`object`){if(typeof e.then==`function`)return N(M(e),r,i,a,o);throw r=String(e),Error(`Objects are not valid as a React child (found: `+(r===`[object Object]`?`object with keys {`+Object.keys(e).join(`, `)+`}`:r)+`). If you meant to render a collection of children, use an array instead.`)}return c}function P(e,t,n){if(e==null)return e;var r=[],i=0;return N(e,r,``,``,function(e){return t.call(n,e,i++)}),r}function F(e){if(e._status===-1){var t=e._result;t=t(),t.then(function(t){(e._status===0||e._status===-1)&&(e._status=1,e._result=t)},function(t){(e._status===0||e._status===-1)&&(e._status=2,e._result=t)}),e._status===-1&&(e._status=0,e._result=t)}if(e._status===1)return e._result.default;throw e._result}var I=typeof reportError==`function`?reportError:function(e){if(typeof window==`object`&&typeof window.ErrorEvent==`function`){var t=new window.ErrorEvent(`error`,{bubbles:!0,cancelable:!0,message:typeof e==`object`&&e&&typeof e.message==`string`?String(e.message):String(e),error:e});if(!window.dispatchEvent(t))return}else if(typeof process==`object`&&typeof process.emit==`function`){process.emit(`uncaughtException`,e);return}console.error(e)},L={map:P,forEach:function(e,t,n){P(e,function(){t.apply(this,arguments)},n)},count:function(e){var t=0;return P(e,function(){t++}),t},toArray:function(e){return P(e,function(e){return e})||[]},only:function(e){if(!O(e))throw Error(`React.Children.only expected to receive a single React element child.`);return e}};e.Activity=f,e.Children=L,e.Component=v,e.Fragment=r,e.Profiler=a,e.PureComponent=b,e.StrictMode=i,e.Suspense=l,e.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE=w,e.__COMPILER_RUNTIME={__proto__:null,c:function(e){return w.H.useMemoCache(e)}},e.cache=function(e){return function(){return e.apply(null,arguments)}},e.cacheSignal=function(){return null},e.cloneElement=function(e,t,n){if(e==null)throw Error(`The argument must be a React element, but you passed `+e+`.`);var r=g({},e.props),i=e.key;if(t!=null)for(a in t.key!==void 0&&(i=``+t.key),t)!T.call(t,a)||a===`key`||a===`__self`||a===`__source`||a===`ref`&&t.ref===void 0||(r[a]=t[a]);var a=arguments.length-2;if(a===1)r.children=n;else if(1<a){for(var o=Array(a),s=0;s<a;s++)o[s]=arguments[s+2];r.children=o}return E(e.type,i,r)},e.createContext=function(e){return e={$$typeof:s,_currentValue:e,_currentValue2:e,_threadCount:0,Provider:null,Consumer:null},e.Provider=e,e.Consumer={$$typeof:o,_context:e},e},e.createElement=function(e,t,n){var r,i={},a=null;if(t!=null)for(r in t.key!==void 0&&(a=``+t.key),t)T.call(t,r)&&r!==`key`&&r!==`__self`&&r!==`__source`&&(i[r]=t[r]);var o=arguments.length-2;if(o===1)i.children=n;else if(1<o){for(var s=Array(o),c=0;c<o;c++)s[c]=arguments[c+2];i.children=s}if(e&&e.defaultProps)for(r in o=e.defaultProps,o)i[r]===void 0&&(i[r]=o[r]);return E(e,a,i)},e.createRef=function(){return{current:null}},e.forwardRef=function(e){return{$$typeof:c,render:e}},e.isValidElement=O,e.lazy=function(e){return{$$typeof:d,_payload:{_status:-1,_result:e},_init:F}},e.memo=function(e,t){return{$$typeof:u,type:e,compare:t===void 0?null:t}},e.startTransition=function(e){var t=w.T,n={};w.T=n;try{var r=e(),i=w.S;i!==null&&i(n,r),typeof r==`object`&&r&&typeof r.then==`function`&&r.then(C,I)}catch(e){I(e)}finally{t!==null&&n.types!==null&&(t.types=n.types),w.T=t}},e.unstable_useCacheRefresh=function(){return w.H.useCacheRefresh()},e.use=function(e){return w.H.use(e)},e.useActionState=function(e,t,n){return w.H.useActionState(e,t,n)},e.useCallback=function(e,t){return w.H.useCallback(e,t)},e.useContext=function(e){return w.H.useContext(e)},e.useDebugValue=function(){},e.useDeferredValue=function(e,t){return w.H.useDeferredValue(e,t)},e.useEffect=function(e,t){return w.H.useEffect(e,t)},e.useEffectEvent=function(e){return w.H.useEffectEvent(e)},e.useId=function(){return w.H.useId()},e.useImperativeHandle=function(e,t,n){return w.H.useImperativeHandle(e,t,n)},e.useInsertionEffect=function(e,t){return w.H.useInsertionEffect(e,t)},e.useLayoutEffect=function(e,t){return w.H.useLayoutEffect(e,t)},e.useMemo=function(e,t){return w.H.useMemo(e,t)},e.useOptimistic=function(e,t){return w.H.useOptimistic(e,t)},e.useReducer=function(e,t,n){return w.H.useReducer(e,t,n)},e.useRef=function(e){return w.H.useRef(e)},e.useState=function(e){return w.H.useState(e)},e.useSyncExternalStore=function(e,t,n){return w.H.useSyncExternalStore(e,t,n)},e.useTransition=function(){return w.H.useTransition()},e.version=`19.2.8`})),lt=e(((e,t)=>{t.exports=ct()})),ut=e((e=>{function t(e,t){var n=e.length;e.push(t);a:for(;0<n;){var r=n-1>>>1,a=e[r];if(0<i(a,t))e[r]=t,e[n]=a,n=r;else break a}}function n(e){return e.length===0?null:e[0]}function r(e){if(e.length===0)return null;var t=e[0],n=e.pop();if(n!==t){e[0]=n;a:for(var r=0,a=e.length,o=a>>>1;r<o;){var s=2*(r+1)-1,c=e[s],l=s+1,u=e[l];if(0>i(c,n))l<a&&0>i(u,c)?(e[r]=u,e[l]=n,r=l):(e[r]=c,e[s]=n,r=s);else if(l<a&&0>i(u,n))e[r]=u,e[l]=n,r=l;else break a}}return t}function i(e,t){var n=e.sortIndex-t.sortIndex;return n===0?e.id-t.id:n}if(e.unstable_now=void 0,typeof performance==`object`&&typeof performance.now==`function`){var a=performance;e.unstable_now=function(){return a.now()}}else{var o=Date,s=o.now();e.unstable_now=function(){return o.now()-s}}var c=[],l=[],u=1,d=null,f=3,p=!1,m=!1,h=!1,g=!1,_=typeof setTimeout==`function`?setTimeout:null,v=typeof clearTimeout==`function`?clearTimeout:null,y=typeof setImmediate<`u`?setImmediate:null;function b(e){for(var i=n(l);i!==null;){if(i.callback===null)r(l);else if(i.startTime<=e)r(l),i.sortIndex=i.expirationTime,t(c,i);else break;i=n(l)}}function x(e){if(h=!1,b(e),!m){if(n(c)!==null)m=!0,S||(S=!0,O());else{var t=n(l);t!==null&&j(x,t.startTime-e)}}}var S=!1,C=-1,w=5,T=-1;function E(){return g?!0:!(e.unstable_now()-T<w)}function D(){if(g=!1,S){var t=e.unstable_now();T=t;var i=!0;try{a:{m=!1,h&&(h=!1,v(C),C=-1),p=!0;var a=f;try{b:{for(b(t),d=n(c);d!==null&&!(d.expirationTime>t&&E());){var o=d.callback;if(typeof o==`function`){d.callback=null,f=d.priorityLevel;var s=o(d.expirationTime<=t);if(t=e.unstable_now(),typeof s==`function`){d.callback=s,b(t),i=!0;break b}d===n(c)&&r(c),b(t)}else r(c);d=n(c)}if(d!==null)i=!0;else{var u=n(l);u!==null&&j(x,u.startTime-t),i=!1}}break a}finally{d=null,f=a,p=!1}i=void 0}}finally{i?O():S=!1}}}var O;if(typeof y==`function`)O=function(){y(D)};else if(typeof MessageChannel<`u`){var k=new MessageChannel,A=k.port2;k.port1.onmessage=D,O=function(){A.postMessage(null)}}else O=function(){_(D,0)};function j(t,n){C=_(function(){t(e.unstable_now())},n)}e.unstable_IdlePriority=5,e.unstable_ImmediatePriority=1,e.unstable_LowPriority=4,e.unstable_NormalPriority=3,e.unstable_Profiling=null,e.unstable_UserBlockingPriority=2,e.unstable_cancelCallback=function(e){e.callback=null},e.unstable_forceFrameRate=function(e){0>e||125<e?console.error(`forceFrameRate takes a positive int between 0 and 125, forcing frame rates higher than 125 fps is not supported`):w=0<e?Math.floor(1e3/e):5},e.unstable_getCurrentPriorityLevel=function(){return f},e.unstable_next=function(e){switch(f){case 1:case 2:case 3:var t=3;break;default:t=f}var n=f;f=t;try{return e()}finally{f=n}},e.unstable_requestPaint=function(){g=!0},e.unstable_runWithPriority=function(e,t){switch(e){case 1:case 2:case 3:case 4:case 5:break;default:e=3}var n=f;f=e;try{return t()}finally{f=n}},e.unstable_scheduleCallback=function(r,i,a){var o=e.unstable_now();switch(typeof a==`object`&&a?(a=a.delay,a=typeof a==`number`&&0<a?o+a:o):a=o,r){case 1:var s=-1;break;case 2:s=250;break;case 5:s=1073741823;break;case 4:s=1e4;break;default:s=5e3}return s=a+s,r={id:u++,callback:i,priorityLevel:r,startTime:a,expirationTime:s,sortIndex:-1},a>o?(r.sortIndex=a,t(l,r),n(c)===null&&r===n(l)&&(h?(v(C),C=-1):h=!0,j(x,a-o))):(r.sortIndex=s,t(c,r),m||p||(m=!0,S||(S=!0,O()))),r},e.unstable_shouldYield=E,e.unstable_wrapCallback=function(e){var t=f;return function(){var n=f;f=t;try{return e.apply(this,arguments)}finally{f=n}}}})),dt=e(((e,t)=>{t.exports=ut()})),ft=e((e=>{var t=lt();function n(e){var t=`https://react.dev/errors/`+e;if(1<arguments.length){t+=`?args[]=`+encodeURIComponent(arguments[1]);for(var n=2;n<arguments.length;n++)t+=`&args[]=`+encodeURIComponent(arguments[n])}return`Minified React error #`+e+`; visit `+t+` for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`}function r(){}var i={d:{f:r,r:function(){throw Error(n(522))},D:r,C:r,L:r,m:r,X:r,S:r,M:r},p:0,findDOMNode:null},a=Symbol.for(`react.portal`);function o(e,t,n){var r=3<arguments.length&&arguments[3]!==void 0?arguments[3]:null;return{$$typeof:a,key:r==null?null:``+r,children:e,containerInfo:t,implementation:n}}var s=t.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE;function c(e,t){if(e===`font`)return``;if(typeof t==`string`)return t===`use-credentials`?t:``}e.__DOM_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE=i,e.createPortal=function(e,t){var r=2<arguments.length&&arguments[2]!==void 0?arguments[2]:null;if(!t||t.nodeType!==1&&t.nodeType!==9&&t.nodeType!==11)throw Error(n(299));return o(e,t,null,r)},e.flushSync=function(e){var t=s.T,n=i.p;try{if(s.T=null,i.p=2,e)return e()}finally{s.T=t,i.p=n,i.d.f()}},e.preconnect=function(e,t){typeof e==`string`&&(t?(t=t.crossOrigin,t=typeof t==`string`?t===`use-credentials`?t:``:void 0):t=null,i.d.C(e,t))},e.prefetchDNS=function(e){typeof e==`string`&&i.d.D(e)},e.preinit=function(e,t){if(typeof e==`string`&&t&&typeof t.as==`string`){var n=t.as,r=c(n,t.crossOrigin),a=typeof t.integrity==`string`?t.integrity:void 0,o=typeof t.fetchPriority==`string`?t.fetchPriority:void 0;n===`style`?i.d.S(e,typeof t.precedence==`string`?t.precedence:void 0,{crossOrigin:r,integrity:a,fetchPriority:o}):n===`script`&&i.d.X(e,{crossOrigin:r,integrity:a,fetchPriority:o,nonce:typeof t.nonce==`string`?t.nonce:void 0})}},e.preinitModule=function(e,t){if(typeof e==`string`){if(typeof t==`object`&&t){if(t.as==null||t.as===`script`){var n=c(t.as,t.crossOrigin);i.d.M(e,{crossOrigin:n,integrity:typeof t.integrity==`string`?t.integrity:void 0,nonce:typeof t.nonce==`string`?t.nonce:void 0})}}else t??i.d.M(e)}},e.preload=function(e,t){if(typeof e==`string`&&typeof t==`object`&&t&&typeof t.as==`string`){var n=t.as,r=c(n,t.crossOrigin);i.d.L(e,n,{crossOrigin:r,integrity:typeof t.integrity==`string`?t.integrity:void 0,nonce:typeof t.nonce==`string`?t.nonce:void 0,type:typeof t.type==`string`?t.type:void 0,fetchPriority:typeof t.fetchPriority==`string`?t.fetchPriority:void 0,referrerPolicy:typeof t.referrerPolicy==`string`?t.referrerPolicy:void 0,imageSrcSet:typeof t.imageSrcSet==`string`?t.imageSrcSet:void 0,imageSizes:typeof t.imageSizes==`string`?t.imageSizes:void 0,media:typeof t.media==`string`?t.media:void 0})}},e.preloadModule=function(e,t){if(typeof e==`string`){if(t){var n=c(t.as,t.crossOrigin);i.d.m(e,{as:typeof t.as==`string`&&t.as!==`script`?t.as:void 0,crossOrigin:n,integrity:typeof t.integrity==`string`?t.integrity:void 0})}else i.d.m(e)}},e.requestFormReset=function(e){i.d.r(e)},e.unstable_batchedUpdates=function(e,t){return e(t)},e.useFormState=function(e,t,n){return s.H.useFormState(e,t,n)},e.useFormStatus=function(){return s.H.useHostTransitionStatus()},e.version=`19.2.8`})),pt=e(((e,t)=>{function n(){if(!(typeof __REACT_DEVTOOLS_GLOBAL_HOOK__>`u`||typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE!=`function`))try{__REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(n)}catch(e){console.error(e)}}n(),t.exports=ft()})),mt=e((e=>{var t=dt(),n=lt(),r=pt();function i(e){var t=`https://react.dev/errors/`+e;if(1<arguments.length){t+=`?args[]=`+encodeURIComponent(arguments[1]);for(var n=2;n<arguments.length;n++)t+=`&args[]=`+encodeURIComponent(arguments[n])}return`Minified React error #`+e+`; visit `+t+` for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`}function a(e){return!(!e||e.nodeType!==1&&e.nodeType!==9&&e.nodeType!==11)}function o(e){var t=e,n=e;if(e.alternate)for(;t.return;)t=t.return;else{e=t;do t=e,t.flags&4098&&(n=t.return),e=t.return;while(e)}return t.tag===3?n:null}function s(e){if(e.tag===13){var t=e.memoizedState;if(t===null&&(e=e.alternate,e!==null&&(t=e.memoizedState)),t!==null)return t.dehydrated}return null}function c(e){if(e.tag===31){var t=e.memoizedState;if(t===null&&(e=e.alternate,e!==null&&(t=e.memoizedState)),t!==null)return t.dehydrated}return null}function l(e){if(o(e)!==e)throw Error(i(188))}function u(e){var t=e.alternate;if(!t){if(t=o(e),t===null)throw Error(i(188));return t===e?e:null}for(var n=e,r=t;;){var a=n.return;if(a===null)break;var s=a.alternate;if(s===null){if(r=a.return,r!==null){n=r;continue}break}if(a.child===s.child){for(s=a.child;s;){if(s===n)return l(a),e;if(s===r)return l(a),t;s=s.sibling}throw Error(i(188))}if(n.return!==r.return)n=a,r=s;else{for(var c=!1,u=a.child;u;){if(u===n){c=!0,n=a,r=s;break}if(u===r){c=!0,r=a,n=s;break}u=u.sibling}if(!c){for(u=s.child;u;){if(u===n){c=!0,n=s,r=a;break}if(u===r){c=!0,r=s,n=a;break}u=u.sibling}if(!c)throw Error(i(189))}}if(n.alternate!==r)throw Error(i(190))}if(n.tag!==3)throw Error(i(188));return n.stateNode.current===n?e:t}function d(e){var t=e.tag;if(t===5||t===26||t===27||t===6)return e;for(e=e.child;e!==null;){if(t=d(e),t!==null)return t;e=e.sibling}return null}var f=Object.assign,p=Symbol.for(`react.element`),m=Symbol.for(`react.transitional.element`),h=Symbol.for(`react.portal`),g=Symbol.for(`react.fragment`),_=Symbol.for(`react.strict_mode`),v=Symbol.for(`react.profiler`),y=Symbol.for(`react.consumer`),b=Symbol.for(`react.context`),x=Symbol.for(`react.forward_ref`),S=Symbol.for(`react.suspense`),C=Symbol.for(`react.suspense_list`),w=Symbol.for(`react.memo`),T=Symbol.for(`react.lazy`),E=Symbol.for(`react.activity`),D=Symbol.for(`react.memo_cache_sentinel`),O=Symbol.iterator;function k(e){return typeof e!=`object`||!e?null:(e=O&&e[O]||e[`@@iterator`],typeof e==`function`?e:null)}var A=Symbol.for(`react.client.reference`);function j(e){if(e==null)return null;if(typeof e==`function`)return e.$$typeof===A?null:e.displayName||e.name||null;if(typeof e==`string`)return e;switch(e){case g:return`Fragment`;case v:return`Profiler`;case _:return`StrictMode`;case S:return`Suspense`;case C:return`SuspenseList`;case E:return`Activity`}if(typeof e==`object`)switch(e.$$typeof){case h:return`Portal`;case b:return e.displayName||`Context`;case y:return(e._context.displayName||`Context`)+`.Consumer`;case x:var t=e.render;return e=e.displayName,e||=(e=t.displayName||t.name||``,e===``?`ForwardRef`:`ForwardRef(`+e+`)`),e;case w:return t=e.displayName||null,t===null?j(e.type)||`Memo`:t;case T:t=e._payload,e=e._init;try{return j(e(t))}catch{}}return null}var M=Array.isArray,N=n.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,P=r.__DOM_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,F={pending:!1,data:null,method:null,action:null},I=[],L=-1;function R(e){return{current:e}}function z(e){0>L||(e.current=I[L],I[L]=null,L--)}function ee(e,t){L++,I[L]=e.current,e.current=t}var te=R(null),ne=R(null),re=R(null),ie=R(null);function B(e,t){switch(ee(re,t),ee(ne,e),ee(te,null),t.nodeType){case 9:case 11:e=(e=t.documentElement)&&(e=e.namespaceURI)?Ud(e):0;break;default:if(e=t.tagName,t=t.namespaceURI)t=Ud(t),e=K(t,e);else switch(e){case`svg`:e=1;break;case`math`:e=2;break;default:e=0}}z(te),ee(te,e)}function ae(){z(te),z(ne),z(re)}function oe(e){e.memoizedState!==null&&ee(ie,e);var t=te.current,n=K(t,e.type);t!==n&&(ee(ne,e),ee(te,n))}function se(e){ne.current===e&&(z(te),z(ne)),ie.current===e&&(z(ie),$f._currentValue=F)}var ce,le;function ue(e){if(ce===void 0)try{throw Error()}catch(e){var t=e.stack.trim().match(/\n( *(at )?)/);ce=t&&t[1]||``,le=-1<e.stack.indexOf(`
3
3
  at`)?` (<anonymous>)`:-1<e.stack.indexOf(`@`)?`@unknown:0:0`:``}return`
4
4
  `+ce+e+le}var de=!1;function fe(e,t){if(!e||de)return``;de=!0;var n=Error.prepareStackTrace;Error.prepareStackTrace=void 0;try{var r={DetermineComponentFrameRoot:function(){try{if(t){var n=function(){throw Error()};if(Object.defineProperty(n.prototype,"props",{set:function(){throw Error()}}),typeof Reflect==`object`&&Reflect.construct){try{Reflect.construct(n,[])}catch(e){var r=e}Reflect.construct(e,[],n)}else{try{n.call()}catch(e){r=e}e.call(n.prototype)}}else{try{throw Error()}catch(e){r=e}(n=e())&&typeof n.catch==`function`&&n.catch(function(){})}}catch(e){if(e&&r&&typeof e.stack==`string`)return[e.stack,r.stack]}return[null,null]}};r.DetermineComponentFrameRoot.displayName=`DetermineComponentFrameRoot`;var i=Object.getOwnPropertyDescriptor(r.DetermineComponentFrameRoot,`name`);i&&i.configurable&&Object.defineProperty(r.DetermineComponentFrameRoot,"name",{value:`DetermineComponentFrameRoot`});var a=r.DetermineComponentFrameRoot(),o=a[0],s=a[1];if(o&&s){var c=o.split(`
@@ -172,7 +172,7 @@ Error generating stack: `+e.message+`
172
172
  \${}
173
173
  }`,{label:`interface`,detail:`definition`,type:`keyword`}),tt("type ${name} = ${type}",{label:`type`,detail:`definition`,type:`keyword`}),tt(`enum \${name} {
174
174
  \${}
175
- }`,{label:`enum`,detail:`definition`,type:`keyword`})]),RI=new ee,zI=new Set([`Script`,`Block`,`FunctionExpression`,`FunctionDeclaration`,`ArrowFunction`,`MethodDeclaration`,`ForStatement`]);function BI(e){return(t,n)=>{let r=t.node.getChild(`VariableDefinition`);return r&&n(r,e),!0}}var abe=[`FunctionDeclaration`],obe={FunctionDeclaration:BI(`function`),ClassDeclaration:BI(`class`),ClassExpression:()=>!0,EnumDeclaration:BI(`constant`),TypeAliasDeclaration:BI(`type`),NamespaceDeclaration:BI(`namespace`),VariableDefinition(e,t){e.matchContext(abe)||t(e,`variable`)},TypeDefinition(e,t){t(e,`type`)},__proto__:null};function VI(e,t){let n=RI.get(t);if(n)return n;let r=[],i=!0;function a(t,n){let i=e.sliceString(t.from,t.to);r.push({label:i,type:n})}return t.cursor(Qe.IncludeAnonymous).iterate(t=>{if(i)i=!1;else if(t.name){let e=obe[t.name];if(e&&e(t,a)||zI.has(t.name))return!1}else if(t.to-t.from>8192){for(let n of VI(e,t.node))r.push(n);return!1}}),RI.set(t,r),r}var HI=/^[\w$\xa1-\uffff][\w$\d\xa1-\uffff]*$/,UI=[`TemplateString`,`String`,`RegExp`,`LineComment`,`BlockComment`,`VariableDefinition`,`TypeDefinition`,`Label`,`PropertyDefinition`,`PropertyName`,`PrivatePropertyDefinition`,`PrivatePropertyName`,`JSXText`,`JSXAttributeValue`,`JSXOpenTag`,`JSXCloseTag`,`JSXSelfClosingTag`,`.`,`?.`];function WI(e){let t=g(e.state).resolveInner(e.pos,-1);if(UI.indexOf(t.name)>-1)return null;let n=t.name==`VariableName`||t.to-t.from<20&&HI.test(e.state.sliceDoc(t.from,t.to));if(!n&&!e.explicit)return null;let r=[];for(let n=t;n;n=n.parent)zI.has(n.name)&&(r=r.concat(VI(e.state.doc,n)));return{options:r,from:n?t.from:e.pos,validFor:HI}}var GI=Re.define({name:`javascript`,parser:ibe.configure({props:[f.add({IfStatement:ye({except:/^\s*({|else\b)/}),TryStatement:ye({except:/^\s*({|catch\b|finally\b)/}),LabeledStatement:Xe,SwitchBody:e=>{let t=e.textAfter,n=/^\s*\}/.test(t),r=/^\s*(case|default)\b/.test(t);return e.baseIndent+(n?0:r?1:2)*e.unit},Block:We({closing:`}`}),ArrowFunction:e=>e.baseIndent+e.unit,"TemplateString BlockComment":()=>null,"Statement Property":ye({except:/^\s*{/}),JSXElement(e){let t=/^\s*<\//.test(e.textAfter);return e.lineIndent(e.node.from)+(t?0:e.unit)},JSXEscape(e){let t=/\s*\}/.test(e.textAfter);return e.lineIndent(e.node.from)+(t?0:e.unit)},"JSXOpenTag JSXSelfClosingTag"(e){return e.column(e.node.from)+e.unit}}),u.add({"Block ClassBody SwitchBody EnumBody ObjectExpression ArrayExpression ObjectType":Je,BlockComment(e){return{from:e.from+2,to:e.to-2}},JSXElement(e){let t=e.firstChild;if(!t||t.name==`JSXSelfClosingTag`)return null;let n=e.lastChild;return{from:t.to,to:n.type.isError?e.to:n.from}},"JSXSelfClosingTag JSXOpenTag"(e){let t=e.firstChild?.nextSibling,n=e.lastChild;return!t||t.type.isError?null:{from:t.to,to:n.type.isError?e.to:n.from}}})]}),languageData:{closeBrackets:{brackets:[`(`,`[`,`{`,`'`,`"`,"`"]},commentTokens:{line:`//`,block:{open:`/*`,close:`*/`}},indentOnInput:/^\s*(?:case |default:|\{|\}|<\/)$/,wordChars:`$`}}),KI={test:e=>/^JSX/.test(e.name),facet:oe({commentTokens:{block:{open:`{/*`,close:`*/}`}}})},qI=GI.configure({dialect:`ts`},`typescript`),JI=GI.configure({dialect:`jsx`,props:[O.add(e=>e.isTop?[KI]:void 0)]}),YI=GI.configure({dialect:`jsx ts`,props:[O.add(e=>e.isTop?[KI]:void 0)]},`typescript`),XI=e=>({label:e,type:`keyword`}),ZI=`break case const continue default delete export extends false finally in instanceof let new return static super switch this throw true typeof var yield`.split(` `).map(XI),sbe=ZI.concat([`declare`,`implements`,`private`,`protected`,`public`].map(XI));function QI(e={}){let t=e.jsx?e.typescript?YI:JI:e.typescript?qI:GI,n=e.typescript?LI.concat(sbe):II.concat(ZI);return new He(t,[GI.data.of({autocomplete:ot(UI,et(n))}),GI.data.of({autocomplete:WI}),e.jsx?eL:[]])}function cbe(e){for(;;){if(e.name==`JSXOpenTag`||e.name==`JSXSelfClosingTag`||e.name==`JSXFragmentTag`)return e;if(e.name==`JSXEscape`||!e.parent)return null;e=e.parent}}function $I(e,t,n=e.length){for(let r=t?.firstChild;r;r=r.nextSibling)if(r.name==`JSXIdentifier`||r.name==`JSXBuiltin`||r.name==`JSXNamespacedName`||r.name==`JSXMemberExpression`)return e.sliceString(r.from,Math.min(r.to,n));return``}var lbe=typeof navigator==`object`&&/Android\b/.test(navigator.userAgent),eL=B.inputHandler.of((e,t,n,r,i)=>{if((lbe?e.composing:e.compositionStarted)||e.state.readOnly||t!=n||r!=`>`&&r!=`/`||!GI.isActiveAt(e.state,t,-1))return!1;let a=i(),{state:o}=a,s=o.changeByRange(e=>{let{head:t}=e,n=g(o).resolveInner(t-1,-1),i;if(n.name==`JSXStartTag`&&(n=n.parent),!(o.doc.sliceString(t-1,t)!=r||n.name==`JSXAttributeValue`&&n.to>t)){if(r==`>`&&n.name==`JSXFragmentTag`)return{range:e,changes:{from:t,insert:`</>`}};if(r==`/`&&n.name==`JSXStartCloseTag`){let e=n.parent,r=e.parent;if(r&&e.from==t-2&&((i=$I(o.doc,r.firstChild,t))||r.firstChild?.name==`JSXFragmentTag`)){let e=`${i}>`;return{range:z.cursor(t+e.length,-1),changes:{from:t,insert:e}}}}else if(r==`>`){let r=cbe(n);if(r&&r.name==`JSXOpenTag`&&!/^\/?>|^<\//.test(o.doc.sliceString(t,t+2))&&(i=$I(o.doc,r,t)))return{range:e,changes:{from:t,insert:`</${i}>`}}}}return{range:e}});return!s.changes.empty&&(e.dispatch([a,o.update(s,{userEvent:`input.complete`,scrollIntoView:!0})]),!0)}),ube=n({autoCloseTags:()=>TL,html:()=>CL,htmlCompletionSource:()=>_L,htmlCompletionSourceWith:()=>vL,htmlLanguage:()=>SL}),tL=[`_blank`,`_self`,`_top`,`_parent`],nL=[`ascii`,`utf-8`,`utf-16`,`latin1`,`latin1`],rL=[`get`,`post`,`put`,`delete`],iL=[`application/x-www-form-urlencoded`,`multipart/form-data`,`text/plain`],aL=[`true`,`false`],oL={},dbe={a:{attrs:{href:null,ping:null,type:null,media:null,target:tL,hreflang:null}},abbr:oL,address:oL,area:{attrs:{alt:null,coords:null,href:null,target:null,ping:null,media:null,hreflang:null,type:null,shape:[`default`,`rect`,`circle`,`poly`]}},article:oL,aside:oL,audio:{attrs:{src:null,mediagroup:null,crossorigin:[`anonymous`,`use-credentials`],preload:[`none`,`metadata`,`auto`],autoplay:[`autoplay`],loop:[`loop`],controls:[`controls`]}},b:oL,base:{attrs:{href:null,target:tL}},bdi:oL,bdo:oL,blockquote:{attrs:{cite:null}},body:oL,br:oL,button:{attrs:{form:null,formaction:null,name:null,value:null,autofocus:[`autofocus`],disabled:[`autofocus`],formenctype:iL,formmethod:rL,formnovalidate:[`novalidate`],formtarget:tL,type:[`submit`,`reset`,`button`]}},canvas:{attrs:{width:null,height:null}},caption:oL,center:oL,cite:oL,code:oL,col:{attrs:{span:null}},colgroup:{attrs:{span:null}},command:{attrs:{type:[`command`,`checkbox`,`radio`],label:null,icon:null,radiogroup:null,command:null,title:null,disabled:[`disabled`],checked:[`checked`]}},data:{attrs:{value:null}},datagrid:{attrs:{disabled:[`disabled`],multiple:[`multiple`]}},datalist:{attrs:{data:null}},dd:oL,del:{attrs:{cite:null,datetime:null}},details:{attrs:{open:[`open`]}},dfn:oL,div:oL,dl:oL,dt:oL,em:oL,embed:{attrs:{src:null,type:null,width:null,height:null}},eventsource:{attrs:{src:null}},fieldset:{attrs:{disabled:[`disabled`],form:null,name:null}},figcaption:oL,figure:oL,footer:oL,form:{attrs:{action:null,name:null,"accept-charset":nL,autocomplete:[`on`,`off`],enctype:iL,method:rL,novalidate:[`novalidate`],target:tL}},h1:oL,h2:oL,h3:oL,h4:oL,h5:oL,h6:oL,head:{children:[`title`,`base`,`link`,`style`,`meta`,`script`,`noscript`,`command`]},header:oL,hgroup:oL,hr:oL,html:{attrs:{manifest:null}},i:oL,iframe:{attrs:{src:null,srcdoc:null,name:null,width:null,height:null,sandbox:[`allow-top-navigation`,`allow-same-origin`,`allow-forms`,`allow-scripts`],seamless:[`seamless`]}},img:{attrs:{alt:null,src:null,ismap:null,usemap:null,width:null,height:null,crossorigin:[`anonymous`,`use-credentials`]}},input:{attrs:{alt:null,dirname:null,form:null,formaction:null,height:null,list:null,max:null,maxlength:null,min:null,name:null,pattern:null,placeholder:null,size:null,src:null,step:null,value:null,width:null,accept:[`audio/*`,`video/*`,`image/*`],autocomplete:[`on`,`off`],autofocus:[`autofocus`],checked:[`checked`],disabled:[`disabled`],formenctype:iL,formmethod:rL,formnovalidate:[`novalidate`],formtarget:tL,multiple:[`multiple`],readonly:[`readonly`],required:[`required`],type:[`hidden`,`text`,`search`,`tel`,`url`,`email`,`password`,`datetime`,`date`,`month`,`week`,`time`,`datetime-local`,`number`,`range`,`color`,`checkbox`,`radio`,`file`,`submit`,`image`,`reset`,`button`]}},ins:{attrs:{cite:null,datetime:null}},kbd:oL,keygen:{attrs:{challenge:null,form:null,name:null,autofocus:[`autofocus`],disabled:[`disabled`],keytype:[`RSA`]}},label:{attrs:{for:null,form:null}},legend:oL,li:{attrs:{value:null}},link:{attrs:{href:null,type:null,hreflang:null,media:null,sizes:[`all`,`16x16`,`16x16 32x32`,`16x16 32x32 64x64`]}},map:{attrs:{name:null}},mark:oL,menu:{attrs:{label:null,type:[`list`,`context`,`toolbar`]}},meta:{attrs:{content:null,charset:nL,name:[`viewport`,`application-name`,`author`,`description`,`generator`,`keywords`],"http-equiv":[`content-language`,`content-type`,`default-style`,`refresh`]}},meter:{attrs:{value:null,min:null,low:null,high:null,max:null,optimum:null}},nav:oL,noscript:oL,object:{attrs:{data:null,type:null,name:null,usemap:null,form:null,width:null,height:null,typemustmatch:[`typemustmatch`]}},ol:{attrs:{reversed:[`reversed`],start:null,type:[`1`,`a`,`A`,`i`,`I`]},children:[`li`,`script`,`template`,`ul`,`ol`]},optgroup:{attrs:{disabled:[`disabled`],label:null}},option:{attrs:{disabled:[`disabled`],label:null,selected:[`selected`],value:null}},output:{attrs:{for:null,form:null,name:null}},p:oL,param:{attrs:{name:null,value:null}},pre:oL,progress:{attrs:{value:null,max:null}},q:{attrs:{cite:null}},rp:oL,rt:oL,ruby:oL,samp:oL,script:{attrs:{type:[`text/javascript`],src:null,async:[`async`],defer:[`defer`],charset:nL}},section:oL,select:{attrs:{form:null,name:null,size:null,autofocus:[`autofocus`],disabled:[`disabled`],multiple:[`multiple`]}},slot:{attrs:{name:null}},small:oL,source:{attrs:{src:null,type:null,media:null}},span:oL,strong:oL,style:{attrs:{type:[`text/css`],media:null,scoped:null}},sub:oL,summary:oL,sup:oL,table:oL,tbody:oL,td:{attrs:{colspan:null,rowspan:null,headers:null}},template:oL,textarea:{attrs:{dirname:null,form:null,maxlength:null,name:null,placeholder:null,rows:null,cols:null,autofocus:[`autofocus`],disabled:[`disabled`],readonly:[`readonly`],required:[`required`],wrap:[`soft`,`hard`]}},tfoot:oL,th:{attrs:{colspan:null,rowspan:null,headers:null,scope:[`row`,`col`,`rowgroup`,`colgroup`]}},thead:oL,time:{attrs:{datetime:null}},title:oL,tr:oL,track:{attrs:{src:null,label:null,default:null,kind:[`subtitles`,`captions`,`descriptions`,`chapters`,`metadata`],srclang:null}},ul:{children:[`li`,`script`,`template`,`ul`,`ol`]},var:oL,video:{attrs:{src:null,poster:null,width:null,height:null,crossorigin:[`anonymous`,`use-credentials`],preload:[`auto`,`metadata`,`none`],autoplay:[`autoplay`],mediagroup:[`movie`],muted:[`muted`],controls:[`controls`]}},wbr:oL},fbe={accesskey:null,class:null,contenteditable:aL,contextmenu:null,dir:[`ltr`,`rtl`,`auto`],draggable:[`true`,`false`,`auto`],dropzone:[`copy`,`move`,`link`,`string:`,`file:`],hidden:[`hidden`],id:null,inert:[`inert`],itemid:null,itemprop:null,itemref:null,itemscope:[`itemscope`],itemtype:null,lang:[`ar`,`bn`,`de`,`en-GB`,`en-US`,`es`,`fr`,`hi`,`id`,`ja`,`pa`,`pt`,`ru`,`tr`,`zh`],spellcheck:aL,autocorrect:aL,autocapitalize:aL,style:null,tabindex:null,title:null,translate:[`yes`,`no`],rel:[`stylesheet`,`alternate`,`author`,`bookmark`,`help`,`license`,`next`,`nofollow`,`noreferrer`,`prefetch`,`prev`,`search`,`tag`],role:`alert application article banner button cell checkbox complementary contentinfo dialog document feed figure form grid gridcell heading img list listbox listitem main navigation region row rowgroup search switch tab table tabpanel textbox timer`.split(` `),"aria-activedescendant":null,"aria-atomic":aL,"aria-autocomplete":[`inline`,`list`,`both`,`none`],"aria-busy":aL,"aria-checked":[`true`,`false`,`mixed`,`undefined`],"aria-controls":null,"aria-describedby":null,"aria-disabled":aL,"aria-dropeffect":null,"aria-expanded":[`true`,`false`,`undefined`],"aria-flowto":null,"aria-grabbed":[`true`,`false`,`undefined`],"aria-haspopup":aL,"aria-hidden":aL,"aria-invalid":[`true`,`false`,`grammar`,`spelling`],"aria-label":null,"aria-labelledby":null,"aria-level":null,"aria-live":[`off`,`polite`,`assertive`],"aria-multiline":aL,"aria-multiselectable":aL,"aria-owns":null,"aria-posinset":null,"aria-pressed":[`true`,`false`,`mixed`,`undefined`],"aria-readonly":aL,"aria-relevant":null,"aria-required":aL,"aria-selected":[`true`,`false`,`undefined`],"aria-setsize":null,"aria-sort":[`ascending`,`descending`,`none`,`other`],"aria-valuemax":null,"aria-valuemin":null,"aria-valuenow":null,"aria-valuetext":null},sL=`beforeunload copy cut dragstart dragover dragleave dragenter dragend drag paste focus blur change click load mousedown mouseenter mouseleave mouseup keydown keyup resize scroll unload`.split(` `).map(e=>`on`+e);for(let e of sL)fbe[e]=null;var cL=class{constructor(e,t){this.tags={...dbe,...e},this.globalAttrs={...fbe,...t},this.allTags=Object.keys(this.tags),this.globalAttrNames=Object.keys(this.globalAttrs)}};cL.default=new cL;function lL(e,t,n=e.length){if(!t)return``;let r=t.firstChild,i=r&&r.getChild(`TagName`);return i?e.sliceString(i.from,Math.min(i.to,n)):``}function uL(e,t=!1){for(;e;e=e.parent)if(e.name==`Element`){if(t)t=!1;else return e}return null}function dL(e,t,n){return n.tags[lL(e,uL(t))]?.children||n.allTags}function fL(e,t){let n=[];for(let r=uL(t);r&&!r.type.isTop;r=uL(r.parent)){let i=lL(e,r);if(i&&r.lastChild.name==`CloseTag`)break;i&&n.indexOf(i)<0&&(t.name==`EndTag`||t.from>=r.firstChild.to)&&n.push(i)}return n}var pL=/^[:\-\.\w\u00b7-\uffff]*$/;function mL(e,t,n,r,i){let a=/\s*>/.test(e.sliceDoc(i,i+5))?``:`>`,o=uL(n,n.name==`StartTag`||n.name==`TagName`);return{from:r,to:i,options:dL(e.doc,o,t).map(e=>({label:e,type:`type`})).concat(fL(e.doc,n).map((e,t)=>({label:`/`+e,apply:`/`+e+a,type:`type`,boost:99-t}))),validFor:/^\/?[:\-\.\w\u00b7-\uffff]*$/}}function hL(e,t,n,r){let i=/\s*>/.test(e.sliceDoc(r,r+5))?``:`>`;return{from:n,to:r,options:fL(e.doc,t).map((e,t)=>({label:e,apply:e+i,type:`type`,boost:99-t})),validFor:pL}}function pbe(e,t,n,r){let i=[],a=0;for(let r of dL(e.doc,n,t))i.push({label:`<`+r,type:`type`});for(let t of fL(e.doc,n))i.push({label:`</`+t+`>`,type:`type`,boost:99-a++});return{from:r,to:r,options:i,validFor:/^<\/?[:\-\.\w\u00b7-\uffff]*$/}}function mbe(e,t,n,r,i){let a=uL(n),o=a?t.tags[lL(e.doc,a)]:null,s=o&&o.attrs?Object.keys(o.attrs):[];return{from:r,to:i,options:(o&&o.globalAttrs===!1?s:s.length?s.concat(t.globalAttrNames):t.globalAttrNames).map(e=>({label:e,type:`property`})),validFor:pL}}function hbe(e,t,n,r,i){let a=n.parent?.getChild(`AttributeName`),o=[],s;if(a){let c=e.sliceDoc(a.from,a.to),l=t.globalAttrs[c];if(!l){let r=uL(n),i=r?t.tags[lL(e.doc,r)]:null;l=i?.attrs&&i.attrs[c]}if(l){let t=e.sliceDoc(r,i).toLowerCase(),n=`"`,a=`"`;/^['"]/.test(t)?(s=t[0]==`"`?/^[^"]*$/:/^[^']*$/,n=``,a=e.sliceDoc(i,i+1)==t[0]?``:t[0],t=t.slice(1),r++):s=/^[^\s<>='"]*$/;for(let e of l)o.push({label:e,apply:n+e+a,type:`constant`})}}return{from:r,to:i,options:o,validFor:s}}function gL(e,t){let{state:n,pos:r}=t,i=g(n).resolveInner(r,-1),a=i.resolve(r);for(let e=r,t;a==i&&(t=i.childBefore(e));){let n=t.lastChild;if(!n||!n.type.isError||n.from<n.to)break;a=i=t,e=n.from}return i.name==`TagName`?i.parent&&/CloseTag$/.test(i.parent.name)?hL(n,i,i.from,r):mL(n,e,i,i.from,r):i.name==`StartTag`||i.name==`IncompleteTag`?mL(n,e,i,r,r):i.name==`StartCloseTag`||i.name==`IncompleteCloseTag`?hL(n,i,r,r):i.name==`OpenTag`||i.name==`SelfClosingTag`||i.name==`AttributeName`?mbe(n,e,i,i.name==`AttributeName`?i.from:r,r):i.name==`Is`||i.name==`AttributeValue`||i.name==`UnquotedAttributeValue`?hbe(n,e,i,i.name==`Is`?r:i.from,r):t.explicit&&(a.name==`Element`||a.name==`Text`||a.name==`Document`)?pbe(n,e,i,r):null}function _L(e){return gL(cL.default,e)}function vL(e){let{extraTags:t,extraGlobalAttributes:n}=e,r=n||t?new cL(t,n):cL.default;return e=>gL(r,e)}var gbe=GI.parser.configure({top:`SingleExpression`}),yL=[{tag:`script`,attrs:e=>e.type==`text/typescript`||e.lang==`ts`,parser:qI.parser},{tag:`script`,attrs:e=>e.type==`text/babel`||e.type==`text/jsx`,parser:JI.parser},{tag:`script`,attrs:e=>e.type==`text/typescript-jsx`,parser:YI.parser},{tag:`script`,attrs(e){return/^(importmap|speculationrules|application\/(.+\+)?json)$/i.test(e.type)},parser:gbe},{tag:`script`,attrs(e){return!e.type||/^(?:text|application)\/(?:x-)?(?:java|ecma)script$|^module$|^$/i.test(e.type)},parser:GI.parser},{tag:`style`,attrs(e){return(!e.lang||e.lang==`css`)&&(!e.type||/^(text\/)?(x-)?(stylesheet|css)$/i.test(e.type))},parser:t.parser}],bL=[{name:`style`,parser:t.parser.configure({top:`Styles`})}].concat(sL.map(e=>({name:e,parser:GI.parser}))),xL=Re.define({name:`html`,parser:Dye.configure({props:[f.add({Element(e){let t=/^(\s*)(<\/)?/.exec(e.textAfter);return e.node.to<=e.pos+t[0].length?e.continue():e.lineIndent(e.node.from)+(t[2]?0:e.unit)},"OpenTag CloseTag SelfClosingTag"(e){return e.column(e.node.from)+e.unit},Document(e){if(e.pos+/\s*/.exec(e.textAfter)[0].length<e.node.to)return e.continue();let t=null,n;for(let n=e.node;;){let e=n.lastChild;if(!e||e.name!=`Element`||e.to!=n.to)break;t=n=e}return t&&!((n=t.lastChild)&&(n.name==`CloseTag`||n.name==`SelfClosingTag`))?e.lineIndent(t.from)+e.unit:null}}),u.add({Element(e){let t=e.firstChild,n=e.lastChild;return!t||t.name!=`OpenTag`?null:{from:t.to,to:n.name==`CloseTag`?n.from:e.to}}}),De.add({"OpenTag CloseTag":e=>e.getChild(`TagName`)})]}),languageData:{commentTokens:{block:{open:`<!--`,close:`-->`}},indentOnInput:/^\s*<\/\w+\W$/,wordChars:`-_`}}),SL=xL.configure({wrap:kI(yL,bL)});function CL(e={}){let t=``,n;e.matchClosingTags===!1&&(t=`noMatch`),e.selfClosingTags===!0&&(t=(t?t+` `:``)+`selfClosing`),(e.nestedLanguages&&e.nestedLanguages.length||e.nestedAttributes&&e.nestedAttributes.length)&&(n=kI((e.nestedLanguages||[]).concat(yL),(e.nestedAttributes||[]).concat(bL)));let r=n?xL.configure({wrap:n,dialect:t}):t?SL.configure({dialect:t}):SL;return new He(r,[SL.data.of({autocomplete:vL(e)}),e.autoCloseTags===!1?[]:TL,QI().support,i().support])}var wL=new Set(`area base br col command embed frame hr img input keygen link meta param source track wbr menuitem`.split(` `));function _be(e,t,n){for(;;){if(t.lastChild?.name!=`CloseTag`)return!1;let r=t.parent;if(!r||lL(e,r)!=n)return!0;t=r}}var TL=B.inputHandler.of((e,t,n,r,i)=>{if(e.composing||e.state.readOnly||t!=n||r!=`>`&&r!=`/`||!SL.isActiveAt(e.state,t,-1))return!1;let a=i(),{state:o}=a,s=o.changeByRange(e=>{let t=o.doc.sliceString(e.from-1,e.to)==r,{head:n}=e,i=g(o).resolveInner(n,-1),a;if(t&&r==`>`&&i.name==`EndTag`){let t=i.parent;if((a=lL(o.doc,t.parent,n))&&!wL.has(a)&&!_be(o.doc,t.parent,a))return{range:e,changes:{from:n,to:n+ +(o.doc.sliceString(n,n+1)===`>`),insert:`</${a}>`}}}else if(t&&r==`/`&&i.name==`IncompleteCloseTag`){let e=i.parent;if(i.from==n-2&&e.lastChild?.name!=`CloseTag`&&(a=lL(o.doc,e,n))&&!wL.has(a)){let e=n+ +(o.doc.sliceString(n,n+1)===`>`),t=`${a}>`;return{range:z.cursor(n+t.length,-1),changes:{from:n,to:e,insert:t}}}}return{range:e}});return!s.changes.empty&&(e.dispatch([a,o.update(s,{userEvent:`input.complete`,scrollIntoView:!0})]),!0)});function vbe(e,t,n,r){let i=kd(yS),a=jd(sC),o=H.useRef(null),{lexicalNode:s}=BP(),c=H.useRef(!1),l=H.useRef(!1),u=H.useCallback(()=>{a({editorType:t,rootNode:s,editorRef:o.current})},[t,s,a]),d=H.useCallback(t=>{if(t.key===`ArrowDown`){let t=o.current?.getCodemirror()?.state;t&&t.doc.length===t.selection.ranges[0].to&&(c.current?(i?.update(()=>{var t;let n=qg(e);n.getNextSibling()?((t=o.current?.getCodemirror())==null||t.contentDOM.blur(),n.selectNext()):n.insertAfter(Dg())}),c.current=!1):c.current=!0)}else if(t.key===`ArrowUp`){let t=o.current?.getCodemirror()?.state;t&&t.selection.ranges[0].from===0&&(l.current?(i?.update(()=>{var t;let n=qg(e);n.getPreviousSibling()&&((t=o.current?.getCodemirror())==null||t.contentDOM.blur(),n.selectPrevious())}),l.current=!1):l.current=!0)}else t.key===`Enter`?t.stopPropagation():(t.key===`Backspace`||t.key===`Delete`)&&(o.current?.getCodemirror()?.state)?.doc.length===0&&i?.update(()=>{qg(e).remove()})},[i,e]);return H.useEffect(()=>{let e=o.current;return setTimeout(()=>{var t,n;(t=e?.getCodemirror())==null||t.contentDOM.addEventListener(`focus`,u),(n=e?.getCodemirror())==null||n.contentDOM.addEventListener(`keydown`,d)},300),()=>{var t,n;(t=e?.getCodemirror())==null||t.contentDOM.removeEventListener(`focus`,u),(n=e?.getCodemirror())==null||n.contentDOM.removeEventListener(`keydown`,d)}},[o,u,d,n]),H.useEffect(()=>{r.subscribe(()=>{var e;(e=o.current?.getCodemirror())==null||e.focus(),u()})},[r,o,e,u]),o}function Z(e){return new He(ge.define(e))}function EL(e){return X(()=>import(`./dist-mpRGeo_R.js`).then(t=>t.sql({dialect:t[e]})),__vite__mapDeps([0,1,2]))}var ybe=[V.of({name:`C`,extensions:[`c`,`h`,`ino`],load(){return X(()=>import(`./dist-DHvUPfrF.js`).then(e=>e.cpp()),__vite__mapDeps([3,1]))}}),V.of({name:`C++`,alias:[`cpp`],extensions:[`cpp`,`c++`,`cc`,`cxx`,`hpp`,`h++`,`hh`,`hxx`],load(){return X(()=>import(`./dist-DHvUPfrF.js`).then(e=>e.cpp()),__vite__mapDeps([3,1]))}}),V.of({name:`CQL`,alias:[`cassandra`],extensions:[`cql`],load(){return EL(`Cassandra`)}}),V.of({name:`CSS`,extensions:[`css`],load(){return X(()=>import(`./dist-DLJCGrGQ.js`).then(e=>e.i).then(e=>e.css()),__vite__mapDeps([4,1]))}}),V.of({name:`Go`,extensions:[`go`],load(){return X(()=>import(`./dist-LCx98fA_.js`).then(e=>e.go()),__vite__mapDeps([5,1,2]))}}),V.of({name:`HTML`,alias:[`xhtml`],extensions:[`html`,`htm`,`handlebars`,`hbs`],load(){return X(()=>Promise.resolve().then(()=>ube).then(e=>e.html()),void 0)}}),V.of({name:`Java`,extensions:[`java`],load(){return X(()=>import(`./dist-DpF08Yd7.js`).then(e=>e.java()),__vite__mapDeps([6,1]))}}),V.of({name:`JavaScript`,alias:[`ecmascript`,`js`,`node`],extensions:[`js`,`mjs`,`cjs`],load(){return X(()=>Promise.resolve().then(()=>FI).then(e=>e.javascript()),void 0)}}),V.of({name:`Jinja`,extensions:[`j2`,`jinja`,`jinja2`],load(){return X(()=>import(`./dist-C8GzUMPk.js`).then(e=>e.jinja()),__vite__mapDeps([7,1]))}}),V.of({name:`JSON`,alias:[`json5`],extensions:[`json`,`map`],load(){return X(()=>import(`./dist-RKTRnzGb.js`).then(e=>e.json()),__vite__mapDeps([8,1]))}}),V.of({name:`JSX`,extensions:[`jsx`],load(){return X(()=>Promise.resolve().then(()=>FI).then(e=>e.javascript({jsx:!0})),void 0)}}),V.of({name:`LESS`,extensions:[`less`],load(){return X(()=>import(`./dist-fPhZsAUX.js`).then(e=>e.less()),__vite__mapDeps([9,4,1]))}}),V.of({name:`Liquid`,extensions:[`liquid`],load(){return X(()=>import(`./dist-Cyb4rVa6.js`).then(e=>e.liquid()),__vite__mapDeps([10,1]))}}),V.of({name:`MariaDB SQL`,load(){return EL(`MariaSQL`)}}),V.of({name:`Markdown`,extensions:[`md`,`markdown`,`mkd`],load(){return X(()=>Promise.resolve().then(()=>bwe).then(e=>e.markdown()),void 0)}}),V.of({name:`MS SQL`,load(){return EL(`MSSQL`)}}),V.of({name:`MySQL`,load(){return EL(`MySQL`)}}),V.of({name:`PHP`,extensions:[`php`,`php3`,`php4`,`php5`,`php7`,`phtml`],load(){return X(()=>import(`./dist-DeMKnZR8.js`).then(e=>e.php()),__vite__mapDeps([11,1]))}}),V.of({name:`PLSQL`,extensions:[`pls`],load(){return EL(`PLSQL`)}}),V.of({name:`PostgreSQL`,load(){return EL(`PostgreSQL`)}}),V.of({name:`Python`,extensions:[`BUILD`,`bzl`,`py`,`pyw`],filename:/^(BUCK|BUILD)$/,load(){return X(()=>import(`./dist-DTeLDijr.js`).then(e=>e.python()),__vite__mapDeps([12,1,2]))}}),V.of({name:`Rust`,extensions:[`rs`],load(){return X(()=>import(`./dist-eddbbGyw.js`).then(e=>e.rust()),__vite__mapDeps([13,1]))}}),V.of({name:`Sass`,extensions:[`sass`],load(){return X(()=>import(`./dist-BJ-TIk3N.js`).then(e=>e.sass({indented:!0})),__vite__mapDeps([14,4,1]))}}),V.of({name:`SCSS`,extensions:[`scss`],load(){return X(()=>import(`./dist-BJ-TIk3N.js`).then(e=>e.sass()),__vite__mapDeps([14,4,1]))}}),V.of({name:`SQL`,extensions:[`sql`],load(){return EL(`StandardSQL`)}}),V.of({name:`SQLite`,load(){return EL(`SQLite`)}}),V.of({name:`TSX`,extensions:[`tsx`],load(){return X(()=>Promise.resolve().then(()=>FI).then(e=>e.javascript({jsx:!0,typescript:!0})),void 0)}}),V.of({name:`TypeScript`,alias:[`ts`],extensions:[`ts`,`mts`,`cts`],load(){return X(()=>Promise.resolve().then(()=>FI).then(e=>e.javascript({typescript:!0})),void 0)}}),V.of({name:`WebAssembly`,extensions:[`wat`,`wast`],load(){return X(()=>import(`./dist-DMiglryg.js`).then(e=>e.wast()),__vite__mapDeps([15,1]))}}),V.of({name:`XML`,alias:[`rss`,`wsdl`,`xsd`],extensions:[`xml`,`xsl`,`xsd`,`svg`],load(){return X(()=>import(`./dist-XVYGiB-c.js`).then(e=>e.xml()),__vite__mapDeps([16,1]))}}),V.of({name:`YAML`,alias:[`yml`],extensions:[`yaml`,`yml`],load(){return X(()=>import(`./dist-CswnpKik.js`).then(e=>e.yaml()),__vite__mapDeps([17,1]))}}),V.of({name:`APL`,extensions:[`dyalog`,`apl`],load(){return X(()=>import(`./apl-gfMMiTNf.js`).then(e=>Z(e.apl)),[])}}),V.of({name:`PGP`,alias:[`asciiarmor`],extensions:[`asc`,`pgp`,`sig`],load(){return X(()=>import(`./asciiarmor-C_eisQCp.js`).then(e=>Z(e.asciiArmor)),[])}}),V.of({name:`ASN.1`,extensions:[`asn`,`asn1`],load(){return X(()=>import(`./asn1-DCl_8MCW.js`).then(e=>Z(e.asn1({}))),[])}}),V.of({name:`Asterisk`,filename:/^extensions\.conf$/i,load(){return X(()=>import(`./asterisk-BEn0Cwpx.js`).then(e=>Z(e.asterisk)),[])}}),V.of({name:`Brainfuck`,extensions:[`b`,`bf`],load(){return X(()=>import(`./brainfuck-D5EjA2JK.js`).then(e=>Z(e.brainfuck)),[])}}),V.of({name:`Cobol`,extensions:[`cob`,`cpy`],load(){return X(()=>import(`./cobol-DHLQUbN7.js`).then(e=>Z(e.cobol)),[])}}),V.of({name:`C#`,alias:[`csharp`,`cs`],extensions:[`cs`],load(){return X(()=>import(`./clike-D_6L3tnO.js`).then(e=>Z(e.csharp)),[])}}),V.of({name:`Clojure`,extensions:[`clj`,`cljc`,`cljx`],load(){return X(()=>import(`./clojure-BflJGmDX.js`).then(e=>Z(e.clojure)),[])}}),V.of({name:`ClojureScript`,extensions:[`cljs`],load(){return X(()=>import(`./clojure-BflJGmDX.js`).then(e=>Z(e.clojure)),[])}}),V.of({name:`Closure Stylesheets (GSS)`,extensions:[`gss`],load(){return X(()=>import(`./css-CnaYoQib.js`).then(e=>Z(e.gss)),[])}}),V.of({name:`CMake`,extensions:[`cmake`,`cmake.in`],filename:/^CMakeLists\.txt$/,load(){return X(()=>import(`./cmake-84nbDH0I.js`).then(e=>Z(e.cmake)),[])}}),V.of({name:`CoffeeScript`,alias:[`coffee`,`coffee-script`],extensions:[`coffee`],load(){return X(()=>import(`./coffeescript-De_zI4J0.js`).then(e=>Z(e.coffeeScript)),[])}}),V.of({name:`Common Lisp`,alias:[`lisp`],extensions:[`cl`,`lisp`,`el`],load(){return X(()=>import(`./commonlisp-DgAKBe0r.js`).then(e=>Z(e.commonLisp)),[])}}),V.of({name:`Cypher`,extensions:[`cyp`,`cypher`],load(){return X(()=>import(`./cypher-p9eYesGn.js`).then(e=>Z(e.cypher)),[])}}),V.of({name:`Cython`,extensions:[`pyx`,`pxd`,`pxi`],load(){return X(()=>import(`./python-B_1Jd8HM.js`).then(e=>Z(e.cython)),[])}}),V.of({name:`Crystal`,extensions:[`cr`],load(){return X(()=>import(`./crystal-Bsdphhtm.js`).then(e=>Z(e.crystal)),[])}}),V.of({name:`D`,extensions:[`d`],load(){return X(()=>import(`./d-DWkQyNnU.js`).then(e=>Z(e.d)),[])}}),V.of({name:`Dart`,extensions:[`dart`],load(){return X(()=>import(`./clike-D_6L3tnO.js`).then(e=>Z(e.dart)),[])}}),V.of({name:`diff`,extensions:[`diff`,`patch`],load(){return X(()=>import(`./diff-ChtP43wD.js`).then(e=>Z(e.diff)),[])}}),V.of({name:`Dockerfile`,filename:/^Dockerfile$/,load(){return X(()=>import(`./dockerfile-DJkHQgkl.js`).then(e=>Z(e.dockerFile)),__vite__mapDeps([18,19]))}}),V.of({name:`DTD`,extensions:[`dtd`],load(){return X(()=>import(`./dtd-DTF72YNO.js`).then(e=>Z(e.dtd)),[])}}),V.of({name:`Dylan`,extensions:[`dylan`,`dyl`,`intr`],load(){return X(()=>import(`./dylan-BCDoL_-p.js`).then(e=>Z(e.dylan)),[])}}),V.of({name:`EBNF`,load(){return X(()=>import(`./ebnf-D4c0_ac3.js`).then(e=>Z(e.ebnf)),[])}}),V.of({name:`ECL`,extensions:[`ecl`],load(){return X(()=>import(`./ecl-BVIeWmwY.js`).then(e=>Z(e.ecl)),[])}}),V.of({name:`edn`,extensions:[`edn`],load(){return X(()=>import(`./clojure-BflJGmDX.js`).then(e=>Z(e.clojure)),[])}}),V.of({name:`Eiffel`,extensions:[`e`],load(){return X(()=>import(`./eiffel-BEjRio4Q.js`).then(e=>Z(e.eiffel)),[])}}),V.of({name:`Elm`,extensions:[`elm`],load(){return X(()=>import(`./elm-Cshzl8qu.js`).then(e=>Z(e.elm)),[])}}),V.of({name:`Erlang`,extensions:[`erl`],load(){return X(()=>import(`./erlang-BV0c4Hdn.js`).then(e=>Z(e.erlang)),[])}}),V.of({name:`Esper`,load(){return X(()=>import(`./sql-DuQMFDvy.js`).then(e=>Z(e.esper)),[])}}),V.of({name:`Factor`,extensions:[`factor`],load(){return X(()=>import(`./factor-LKH5gN8L.js`).then(e=>Z(e.factor)),__vite__mapDeps([20,19]))}}),V.of({name:`FCL`,load(){return X(()=>import(`./fcl-ClOhbFR7.js`).then(e=>Z(e.fcl)),[])}}),V.of({name:`Forth`,extensions:[`forth`,`fth`,`4th`],load(){return X(()=>import(`./forth-Cezjo90N.js`).then(e=>Z(e.forth)),[])}}),V.of({name:`Fortran`,extensions:[`f`,`for`,`f77`,`f90`,`f95`],load(){return X(()=>import(`./fortran-Bt6PBEDR.js`).then(e=>Z(e.fortran)),[])}}),V.of({name:`F#`,alias:[`fsharp`],extensions:[`fs`],load(){return X(()=>import(`./mllike-B45xgp2S.js`).then(e=>Z(e.fSharp)),[])}}),V.of({name:`Gas`,extensions:[`s`],load(){return X(()=>import(`./gas-BHEdbvp9.js`).then(e=>Z(e.gas)),[])}}),V.of({name:`Gherkin`,extensions:[`feature`],load(){return X(()=>import(`./gherkin-oBAE_ms0.js`).then(e=>Z(e.gherkin)),[])}}),V.of({name:`Groovy`,extensions:[`groovy`,`gradle`],filename:/^Jenkinsfile$/,load(){return X(()=>import(`./groovy-CUpZ7dEl.js`).then(e=>Z(e.groovy)),[])}}),V.of({name:`Haskell`,extensions:[`hs`],load(){return X(()=>import(`./haskell-BRsoo5mP.js`).then(e=>Z(e.haskell)),[])}}),V.of({name:`Haxe`,extensions:[`hx`],load(){return X(()=>import(`./haxe-DjVOVvNP.js`).then(e=>Z(e.haxe)),[])}}),V.of({name:`HXML`,extensions:[`hxml`],load(){return X(()=>import(`./haxe-DjVOVvNP.js`).then(e=>Z(e.hxml)),[])}}),V.of({name:`HTTP`,load(){return X(()=>import(`./http-CLVgA2GD.js`).then(e=>Z(e.http)),[])}}),V.of({name:`IDL`,extensions:[`pro`],load(){return X(()=>import(`./idl-BUZw3wgd.js`).then(e=>Z(e.idl)),[])}}),V.of({name:`JSON-LD`,alias:[`jsonld`],extensions:[`jsonld`],load(){return X(()=>import(`./javascript-DoL9Wb-Q.js`).then(e=>Z(e.jsonld)),[])}}),V.of({name:`Julia`,extensions:[`jl`],load(){return X(()=>import(`./julia-CQfgDRfP.js`).then(e=>Z(e.julia)),[])}}),V.of({name:`Kotlin`,extensions:[`kt`,`kts`],load(){return X(()=>import(`./clike-D_6L3tnO.js`).then(e=>Z(e.kotlin)),[])}}),V.of({name:`LiveScript`,alias:[`ls`],extensions:[`ls`],load(){return X(()=>import(`./livescript-BXxG0Yva.js`).then(e=>Z(e.liveScript)),[])}}),V.of({name:`Lua`,extensions:[`lua`],load(){return X(()=>import(`./lua-CiA1ziua.js`).then(e=>Z(e.lua)),[])}}),V.of({name:`mIRC`,extensions:[`mrc`],load(){return X(()=>import(`./mirc-C9zpzAZU.js`).then(e=>Z(e.mirc)),[])}}),V.of({name:`Mathematica`,extensions:[`m`,`nb`,`wl`,`wls`],load(){return X(()=>import(`./mathematica-u8YMmbU0.js`).then(e=>Z(e.mathematica)),[])}}),V.of({name:`Modelica`,extensions:[`mo`],load(){return X(()=>import(`./modelica-CqHI_q-D.js`).then(e=>Z(e.modelica)),[])}}),V.of({name:`MUMPS`,extensions:[`mps`],load(){return X(()=>import(`./mumps-BSzj6Xyz.js`).then(e=>Z(e.mumps)),[])}}),V.of({name:`Mbox`,extensions:[`mbox`],load(){return X(()=>import(`./mbox-BEMVcqjs.js`).then(e=>Z(e.mbox)),[])}}),V.of({name:`Nginx`,filename:/nginx.*\.conf$/i,load(){return X(()=>import(`./nginx-BMaDbqW3.js`).then(e=>Z(e.nginx)),[])}}),V.of({name:`NSIS`,extensions:[`nsh`,`nsi`],load(){return X(()=>import(`./nsis-CfSuhXs5.js`).then(e=>Z(e.nsis)),__vite__mapDeps([21,19]))}}),V.of({name:`NTriples`,extensions:[`nt`,`nq`],load(){return X(()=>import(`./ntriples-B9h1VB_g.js`).then(e=>Z(e.ntriples)),[])}}),V.of({name:`Objective-C`,alias:[`objective-c`,`objc`],extensions:[`m`],load(){return X(()=>import(`./clike-D_6L3tnO.js`).then(e=>Z(e.objectiveC)),[])}}),V.of({name:`Objective-C++`,alias:[`objective-c++`,`objc++`],extensions:[`mm`],load(){return X(()=>import(`./clike-D_6L3tnO.js`).then(e=>Z(e.objectiveCpp)),[])}}),V.of({name:`OCaml`,extensions:[`ml`,`mli`,`mll`,`mly`],load(){return X(()=>import(`./mllike-B45xgp2S.js`).then(e=>Z(e.oCaml)),[])}}),V.of({name:`Octave`,extensions:[`m`],load(){return X(()=>import(`./octave-D2Q8cUp1.js`).then(e=>Z(e.octave)),[])}}),V.of({name:`Oz`,extensions:[`oz`],load(){return X(()=>import(`./oz-BwTct_5T.js`).then(e=>Z(e.oz)),[])}}),V.of({name:`Pascal`,extensions:[`p`,`pas`],load(){return X(()=>import(`./pascal-Dp_KdFgX.js`).then(e=>Z(e.pascal)),[])}}),V.of({name:`Perl`,extensions:[`pl`,`pm`],load(){return X(()=>import(`./perl-BkSkiI9m.js`).then(e=>Z(e.perl)),[])}}),V.of({name:`Pig`,extensions:[`pig`],load(){return X(()=>import(`./pig-AF4Hwhju.js`).then(e=>Z(e.pig)),[])}}),V.of({name:`PowerShell`,extensions:[`ps1`,`psd1`,`psm1`],load(){return X(()=>import(`./powershell-BcIto6Sf.js`).then(e=>Z(e.powerShell)),[])}}),V.of({name:`Properties files`,alias:[`ini`,`properties`],extensions:[`properties`,`ini`,`in`],load(){return X(()=>import(`./properties-C357ku5U.js`).then(e=>Z(e.properties)),[])}}),V.of({name:`ProtoBuf`,extensions:[`proto`],load(){return X(()=>import(`./protobuf-D1ij_kNL.js`).then(e=>Z(e.protobuf)),[])}}),V.of({name:`Pug`,alias:[`jade`],extensions:[`pug`,`jade`],load(){return X(()=>import(`./pug-Gsm0M45u.js`).then(e=>Z(e.pug)),__vite__mapDeps([22,23]))}}),V.of({name:`Puppet`,extensions:[`pp`],load(){return X(()=>import(`./puppet-BZyAS7I4.js`).then(e=>Z(e.puppet)),[])}}),V.of({name:`Q`,extensions:[`q`],load(){return X(()=>import(`./q-B9NhS7L_.js`).then(e=>Z(e.q)),[])}}),V.of({name:`R`,alias:[`rscript`],extensions:[`r`,`R`],load(){return X(()=>import(`./r-CxDmU1I4.js`).then(e=>Z(e.r)),[])}}),V.of({name:`RPM Changes`,load(){return X(()=>import(`./rpm-gpDK5sbt.js`).then(e=>Z(e.rpmChanges)),[])}}),V.of({name:`RPM Spec`,extensions:[`spec`],load(){return X(()=>import(`./rpm-gpDK5sbt.js`).then(e=>Z(e.rpmSpec)),[])}}),V.of({name:`Ruby`,alias:[`jruby`,`macruby`,`rake`,`rb`,`rbx`],extensions:[`rb`],filename:/^(Gemfile|Rakefile)$/,load(){return X(()=>import(`./ruby-BjXV7-Qa.js`).then(e=>Z(e.ruby)),[])}}),V.of({name:`SAS`,extensions:[`sas`],load(){return X(()=>import(`./sas-C2OyD2Y6.js`).then(e=>Z(e.sas)),[])}}),V.of({name:`Scala`,extensions:[`scala`],load(){return X(()=>import(`./clike-D_6L3tnO.js`).then(e=>Z(e.scala)),[])}}),V.of({name:`Scheme`,extensions:[`scm`,`ss`],load(){return X(()=>import(`./scheme-D9qYN0V5.js`).then(e=>Z(e.scheme)),[])}}),V.of({name:`Shell`,alias:[`bash`,`sh`,`zsh`],extensions:[`sh`,`ksh`,`bash`],filename:/^PKGBUILD$/,load(){return X(()=>import(`./shell-DwuoZtxw.js`).then(e=>Z(e.shell)),[])}}),V.of({name:`Sieve`,extensions:[`siv`,`sieve`],load(){return X(()=>import(`./sieve-BAxa3IjF.js`).then(e=>Z(e.sieve)),[])}}),V.of({name:`Smalltalk`,extensions:[`st`],load(){return X(()=>import(`./smalltalk-BLp5-jwC.js`).then(e=>Z(e.smalltalk)),[])}}),V.of({name:`Solr`,load(){return X(()=>import(`./solr-BBopId9w.js`).then(e=>Z(e.solr)),[])}}),V.of({name:`SML`,extensions:[`sml`,`sig`,`fun`,`smackspec`],load(){return X(()=>import(`./mllike-B45xgp2S.js`).then(e=>Z(e.sml)),[])}}),V.of({name:`SPARQL`,alias:[`sparul`],extensions:[`rq`,`sparql`],load(){return X(()=>import(`./sparql-Dz-mlCAC.js`).then(e=>Z(e.sparql)),[])}}),V.of({name:`Spreadsheet`,alias:[`excel`,`formula`],load(){return X(()=>import(`./spreadsheet-CTIncYxj.js`).then(e=>Z(e.spreadsheet)),[])}}),V.of({name:`Squirrel`,extensions:[`nut`],load(){return X(()=>import(`./clike-D_6L3tnO.js`).then(e=>Z(e.squirrel)),[])}}),V.of({name:`Stylus`,extensions:[`styl`],load(){return X(()=>import(`./stylus-BOVgKnng.js`).then(e=>Z(e.stylus)),[])}}),V.of({name:`Swift`,extensions:[`swift`],load(){return X(()=>import(`./swift-DKB6_1j6.js`).then(e=>Z(e.swift)),[])}}),V.of({name:`sTeX`,load(){return X(()=>import(`./stex-DNzd62Q_.js`).then(e=>Z(e.stex)),[])}}),V.of({name:`LaTeX`,alias:[`tex`],extensions:[`text`,`ltx`,`tex`],load(){return X(()=>import(`./stex-DNzd62Q_.js`).then(e=>Z(e.stex)),[])}}),V.of({name:`SystemVerilog`,extensions:[`v`,`sv`,`svh`],load(){return X(()=>import(`./verilog-7LoJAqYT.js`).then(e=>Z(e.verilog)),[])}}),V.of({name:`Tcl`,extensions:[`tcl`],load(){return X(()=>import(`./tcl-BGfruO1u.js`).then(e=>Z(e.tcl)),[])}}),V.of({name:`Textile`,extensions:[`textile`],load(){return X(()=>import(`./textile-C4jVoHG1.js`).then(e=>Z(e.textile)),[])}}),V.of({name:`TiddlyWiki`,load(){return X(()=>import(`./tiddlywiki-VlUiK86J.js`).then(e=>Z(e.tiddlyWiki)),[])}}),V.of({name:`Tiki wiki`,load(){return X(()=>import(`./tiki-AK6FwT8q.js`).then(e=>Z(e.tiki)),[])}}),V.of({name:`TOML`,extensions:[`toml`],load(){return X(()=>import(`./toml-BPTmHmyx.js`).then(e=>Z(e.toml)),[])}}),V.of({name:`Troff`,extensions:[`1`,`2`,`3`,`4`,`5`,`6`,`7`,`8`,`9`],load(){return X(()=>import(`./troff-C2dAgh7P.js`).then(e=>Z(e.troff)),[])}}),V.of({name:`TTCN`,extensions:[`ttcn`,`ttcn3`,`ttcnpp`],load(){return X(()=>import(`./ttcn-PPSTk1ow.js`).then(e=>Z(e.ttcn)),[])}}),V.of({name:`TTCN_CFG`,extensions:[`cfg`],load(){return X(()=>import(`./ttcn-cfg-2b4Gb5sE.js`).then(e=>Z(e.ttcnCfg)),[])}}),V.of({name:`Turtle`,extensions:[`ttl`],load(){return X(()=>import(`./turtle-Cx3rYX2g.js`).then(e=>Z(e.turtle)),[])}}),V.of({name:`Web IDL`,extensions:[`webidl`],load(){return X(()=>import(`./webidl-D5jiJvOU.js`).then(e=>Z(e.webIDL)),[])}}),V.of({name:`VB.NET`,extensions:[`vb`],load(){return X(()=>import(`./vb-BthdM_4N.js`).then(e=>Z(e.vb)),[])}}),V.of({name:`VBScript`,extensions:[`vbs`],load(){return X(()=>import(`./vbscript-D9f6rSsU.js`).then(e=>Z(e.vbScript)),[])}}),V.of({name:`Velocity`,extensions:[`vtl`],load(){return X(()=>import(`./velocity-CqftRsjg.js`).then(e=>Z(e.velocity)),[])}}),V.of({name:`Verilog`,extensions:[`v`],load(){return X(()=>import(`./verilog-7LoJAqYT.js`).then(e=>Z(e.verilog)),[])}}),V.of({name:`VHDL`,extensions:[`vhd`,`vhdl`],load(){return X(()=>import(`./vhdl-kS471soi.js`).then(e=>Z(e.vhdl)),[])}}),V.of({name:`XQuery`,extensions:[`xy`,`xquery`,`xq`,`xqm`,`xqy`],load(){return X(()=>import(`./xquery-BKJx4mf9.js`).then(e=>Z(e.xQuery)),[])}}),V.of({name:`Yacas`,extensions:[`ys`],load(){return X(()=>import(`./yacas-CXXgtw0p.js`).then(e=>Z(e.yacas)),[])}}),V.of({name:`Z80`,extensions:[`z80`],load(){return X(()=>import(`./z80-Co3PbHdE.js`).then(e=>Z(e.z80)),[])}}),V.of({name:`MscGen`,extensions:[`mscgen`,`mscin`,`msc`],load(){return X(()=>import(`./mscgen-qgSLujhx.js`).then(e=>Z(e.mscgen)),[])}}),V.of({name:`Xù`,extensions:[`xu`],load(){return X(()=>import(`./mscgen-qgSLujhx.js`).then(e=>Z(e.xu)),[])}}),V.of({name:`MsGenny`,extensions:[`msgenny`],load(){return X(()=>import(`./mscgen-qgSLujhx.js`).then(e=>Z(e.msgenny)),[])}}),V.of({name:`Vue`,extensions:[`vue`],load(){return X(()=>import(`./dist-B4YhOxh0.js`).then(e=>e.vue()),__vite__mapDeps([24,1]))}}),V.of({name:`Angular Template`,load(){return X(()=>import(`./dist-BkUu8WPA.js`).then(e=>e.angular()),__vite__mapDeps([25,1]))}})],DL=`#2e3440`,OL=`#3b4252`,kL=`#434c5e`,AL=`#4c566a`,jL=`#e5e9f0`,ML=`#eceff4`,NL=`#8fbcbb`,PL=`#88c0d0`,bbe=`#81a1c1`,FL=`#5e81ac`,xbe=`#bf616a`,IL=`#d08770`,LL=`#ebcb8b`,RL=`#a3be8c`,Sbe=`#b48ead`,zL=`#d30102`,BL=ML,VL=BL,Cbe=`#ffffff`,HL=OL,wbe=BL,UL=OL,Tbe=B.theme({"&":{color:DL,backgroundColor:Cbe},".cm-content":{caretColor:UL},".cm-cursor, .cm-dropCursor":{borderLeftColor:UL},"&.cm-focused .cm-selectionBackground, .cm-selectionBackground, .cm-content ::selection":{backgroundColor:wbe},".cm-panels":{backgroundColor:BL,color:AL},".cm-panels.cm-panels-top":{borderBottom:`2px solid black`},".cm-panels.cm-panels-bottom":{borderTop:`2px solid black`},".cm-searchMatch":{backgroundColor:`#72a1ff59`,outline:`1px solid ${AL}`},".cm-searchMatch.cm-searchMatch-selected":{backgroundColor:jL},".cm-activeLine":{backgroundColor:VL},".cm-selectionMatch":{backgroundColor:jL},"&.cm-focused .cm-matchingBracket, &.cm-focused .cm-nonmatchingBracket":{outline:`1px solid ${AL}`},"&.cm-focused .cm-matchingBracket":{backgroundColor:ML},".cm-gutters":{backgroundColor:ML,color:DL,border:`none`},".cm-activeLineGutter":{backgroundColor:VL},".cm-foldPlaceholder":{backgroundColor:`transparent`,border:`none`,color:`#ddd`},".cm-tooltip":{border:`none`,backgroundColor:HL},".cm-tooltip .cm-tooltip-arrow:before":{borderTopColor:`transparent`,borderBottomColor:`transparent`},".cm-tooltip .cm-tooltip-arrow:after":{borderTopColor:HL,borderBottomColor:HL},".cm-tooltip-autocomplete":{"& > ul > li[aria-selected]":{backgroundColor:VL,color:AL}}},{dark:!1}),Ebe=se.define([{tag:P.keyword,color:FL},{tag:[P.name,P.deleted,P.character,P.propertyName,P.macroName],color:IL},{tag:[P.variableName],color:IL},{tag:[P.function(P.variableName)],color:FL},{tag:[P.labelName],color:bbe},{tag:[P.color,P.constant(P.name),P.standard(P.name)],color:FL},{tag:[P.definition(P.name),P.separator],color:RL},{tag:[P.brace],color:NL},{tag:[P.annotation],color:zL},{tag:[P.number,P.changed,P.annotation,P.modifier,P.self,P.namespace],color:PL},{tag:[P.typeName,P.className],color:LL},{tag:[P.operator,P.operatorKeyword],color:RL},{tag:[P.tagName],color:Sbe},{tag:[P.squareBracket],color:xbe},{tag:[P.angleBracket],color:IL},{tag:[P.attributeName],color:LL},{tag:[P.regexp],color:FL},{tag:[P.quote],color:OL},{tag:[P.string],color:IL},{tag:P.link,color:NL,textDecoration:`underline`,textUnderlinePosition:`under`},{tag:[P.url,P.escape,P.special(P.string)],color:IL},{tag:[P.meta],color:PL},{tag:[P.comment],color:kL,fontStyle:`italic`},{tag:P.strong,fontWeight:`bold`,color:FL},{tag:P.emphasis,fontStyle:`italic`,color:FL},{tag:P.strikethrough,textDecoration:`line-through`},{tag:P.heading,fontWeight:`bold`,color:FL},{tag:P.special(P.heading1),fontWeight:`bold`,color:FL},{tag:P.heading1,fontWeight:`bold`,color:FL},{tag:[P.heading2,P.heading3,P.heading4],fontWeight:`bold`,color:FL},{tag:[P.heading5,P.heading6],color:FL},{tag:[P.atom,P.bool,P.special(P.variableName)],color:IL},{tag:[P.processingInstruction,P.inserted],color:NL},{tag:[P.contentSeparator],color:LL},{tag:P.invalid,color:kL,borderBottom:`1px dotted ${zL}`}]),WL=[Tbe,j(Ebe)],GL=typeof String.prototype.normalize==`function`?e=>e.normalize(`NFKD`):e=>e,KL=class{constructor(e,t,n=0,r=e.length,i,a){this.test=a,this.value={from:0,to:0,precise:!1},this.done=!1,this.matches=[],this.buffer=``,this.bufferPos=0,this.iter=e.iterRange(n,r),this.bufferStart=n,this.normalize=i?e=>i(GL(e)):GL,this.query=this.normalize(t)}peek(){if(this.bufferPos==this.buffer.length){if(this.bufferStart+=this.buffer.length,this.iter.next(),this.iter.done)return-1;this.bufferPos=0,this.buffer=this.iter.value}return E(this.buffer,this.bufferPos)}next(){for(;this.matches.length;)this.matches.pop();return this.nextOverlapping()}nextOverlapping(){for(;;){let e=this.peek();if(e<0)return this.done=!0,this;let t=b(e),n=this.bufferStart+this.bufferPos;this.bufferPos+=F(e);let r=this.normalize(t);if(r.length)for(let e=0,i=n,a=!0;;e++){let n=r.charCodeAt(e),o=this.match(n,i,a,this.bufferPos+this.bufferStart,e==r.length-1);if(o)return this.value=o,this;if(e==r.length-1)break;a&&e<t.length&&t.charCodeAt(e)==n?i++:a=!1}}}match(e,t,n,r,i){let a=null;for(let t=0;t<this.matches.length;){let n=this.matches[t],o=!1;this.query.charCodeAt(n.index)==e&&(n.index==this.query.length-1?a={from:n.from,to:r,precise:i&&n.precise}:(n.index++,o=!0)),o?t++:this.matches.splice(t,1)}return this.query.charCodeAt(0)==e&&(this.query.length==1?a={from:t,to:r,precise:n&&i}:this.matches.push({from:t,index:1,precise:n})),a&&this.test&&!this.test(a.from,a.to,this.buffer,this.bufferStart)&&(a=null),a}};typeof Symbol<`u`&&(KL.prototype[Symbol.iterator]=function(){return this});var qL={from:-1,to:-1,match:/.*/.exec(``),precise:!0},JL=`gm`+(/x/.unicode==null?``:`u`),YL=class{constructor(e,t,n,r=0,i=e.length){if(this.text=e,this.to=i,this.curLine=``,this.done=!1,this.value=qL,/\\[sWDnr]|\n|\r|\[\^/.test(t))return new QL(e,t,n,r,i);this.re=new RegExp(t,JL+(n?.ignoreCase?`i`:``)),this.test=n?.test,this.iter=e.iter();let a=e.lineAt(r);this.curLineStart=a.from,this.matchPos=$L(e,r),this.getLine(this.curLineStart)}getLine(e){this.iter.next(e),this.iter.lineBreak?this.curLine=``:(this.curLine=this.iter.value,this.curLineStart+this.curLine.length>this.to&&(this.curLine=this.curLine.slice(0,this.to-this.curLineStart)),this.iter.next())}nextLine(){this.curLineStart=this.curLineStart+this.curLine.length+1,this.curLineStart>this.to?this.curLine=``:this.getLine(0)}next(){for(let e=this.matchPos-this.curLineStart;;){this.re.lastIndex=e;let t=this.matchPos<=this.to&&this.re.exec(this.curLine);if(t){let n=this.curLineStart+t.index,r=n+t[0].length;if(this.matchPos=$L(this.text,r+ +(n==r)),n==this.curLineStart+this.curLine.length&&this.nextLine(),(n<r||n>this.value.to)&&(!this.test||this.test(n,r,t)))return this.value={from:n,to:r,precise:!0,match:t},this;e=this.matchPos-this.curLineStart}else if(this.curLineStart+this.curLine.length<this.to)this.nextLine(),e=0;else return this.done=!0,this}}},XL=new WeakMap,ZL=class e{constructor(e,t){this.from=e,this.text=t}get to(){return this.from+this.text.length}static get(t,n,r){let i=XL.get(t);if(!i||i.from>=r||i.to<=n){let i=new e(n,t.sliceString(n,r));return XL.set(t,i),i}if(i.from==n&&i.to==r)return i;let{text:a,from:o}=i;return o>n&&(a=t.sliceString(n,o)+a,o=n),i.to<r&&(a+=t.sliceString(i.to,r)),XL.set(t,new e(o,a)),new e(n,a.slice(n-o,r-o))}},QL=class{constructor(e,t,n,r,i){this.text=e,this.to=i,this.done=!1,this.value=qL,this.matchPos=$L(e,r),this.re=new RegExp(t,JL+(n?.ignoreCase?`i`:``)),this.test=n?.test,this.flat=ZL.get(e,r,this.chunkEnd(r+5e3))}chunkEnd(e){return e>=this.to?this.to:this.text.lineAt(e).to}next(){for(;;){let e=this.re.lastIndex=this.matchPos-this.flat.from,t=this.re.exec(this.flat.text);if(t&&!t[0]&&t.index==e&&(this.re.lastIndex=e+1,t=this.re.exec(this.flat.text)),t){let e=this.flat.from+t.index,n=e+t[0].length;if((this.flat.to>=this.to||t.index+t[0].length<=this.flat.text.length-10)&&(!this.test||this.test(e,n,t)))return this.value={from:e,to:n,precise:!0,match:t},this.matchPos=$L(this.text,n+ +(e==n)),this}if(this.flat.to==this.to)return this.done=!0,this;this.flat=ZL.get(this.text,this.flat.from,this.chunkEnd(this.flat.from+this.flat.text.length*2))}}};typeof Symbol<`u`&&(YL.prototype[Symbol.iterator]=QL.prototype[Symbol.iterator]=function(){return this});function Dbe(e){try{return new RegExp(e,JL),!0}catch{return!1}}function $L(e,t){if(t>=e.length)return t;let n=e.lineAt(t),r;for(;t<n.to&&(r=n.text.charCodeAt(t-n.from))>=56320&&r<57344;)t++;return t}var Obe=e=>{let{state:t}=e,n=String(t.doc.lineAt(e.state.selection.main.head).number),{close:r,result:i}=be(e,{label:t.phrase(`Go to line`),input:{type:`text`,name:`line`,value:n},focus:!0,submitLabel:t.phrase(`go`)});return i.then(n=>{let i=n&&/^([+-])?(\d+)?(:\d+)?(%)?$/.exec(n.elements.line.value);if(!i){e.dispatch({effects:r});return}let a=t.doc.lineAt(t.selection.main.head),[,o,s,c,l]=i,u=c?+c.slice(1):0,d=s?+s:a.number;if(s&&l){let e=d/100;o&&(e=e*(o==`-`?-1:1)+a.number/t.doc.lines),d=Math.round(t.doc.lines*e)}else s&&o&&(d=d*(o==`-`?-1:1)+a.number);let f=t.doc.line(Math.max(1,Math.min(t.doc.lines,d))),p=z.cursor(f.from+Math.max(0,Math.min(u,f.length)));e.dispatch({effects:[r,B.scrollIntoView(p.from,{y:`center`})],selection:p})}),!0},kbe={highlightWordAroundCursor:!1,minSelectionLength:1,maxMatches:100,wholeWords:!1},eR=p.define({combine(e){return $e(e,kbe,{highlightWordAroundCursor:(e,t)=>e||t,minSelectionLength:Math.min,maxMatches:Math.min})}});function Abe(e){let t=[Fbe,Pbe];return e&&t.push(eR.of(e)),t}var jbe=Fe.mark({class:`cm-selectionMatch`}),Mbe=Fe.mark({class:`cm-selectionMatch cm-selectionMatch-main`});function tR(e,t,n,r){return(n==0||e(t.sliceDoc(n-1,n))!=d.Word)&&(r==t.doc.length||e(t.sliceDoc(r,r+1))!=d.Word)}function Nbe(e,t,n,r){return e(t.sliceDoc(n,n+1))==d.Word&&e(t.sliceDoc(r-1,r))==d.Word}var Pbe=ae.fromClass(class{constructor(e){this.decorations=this.getDeco(e)}update(e){(e.selectionSet||e.docChanged||e.viewportChanged)&&(this.decorations=this.getDeco(e.view))}getDeco(e){let t=e.state.facet(eR),{state:n}=e,r=n.selection;if(r.ranges.length>1)return Fe.none;let i=r.main,a,o=null;if(i.empty){if(!t.highlightWordAroundCursor)return Fe.none;let e=n.wordAt(i.head);if(!e)return Fe.none;o=n.charCategorizer(i.head),a=n.sliceDoc(e.from,e.to)}else{let e=i.to-i.from;if(e<t.minSelectionLength||e>200)return Fe.none;if(t.wholeWords){if(a=n.sliceDoc(i.from,i.to),o=n.charCategorizer(i.head),!(tR(o,n,i.from,i.to)&&Nbe(o,n,i.from,i.to)))return Fe.none}else if(a=n.sliceDoc(i.from,i.to),!a)return Fe.none}let s=[];for(let r of e.visibleRanges){let e=new KL(n.doc,a,r.from,r.to);for(;!e.next().done;){let{from:r,to:a}=e.value;if((!o||tR(o,n,r,a))&&(i.empty&&r<=i.from&&a>=i.to?s.push(Mbe.range(r,a)):(r>=i.to||a<=i.from)&&s.push(jbe.range(r,a)),s.length>t.maxMatches))return Fe.none}}return Fe.set(s)}},{decorations:e=>e.decorations}),Fbe=B.baseTheme({".cm-selectionMatch":{backgroundColor:`#99ff7780`},".cm-searchMatch .cm-selectionMatch":{backgroundColor:`transparent`}}),Ibe=({state:e,dispatch:t})=>{let{selection:n}=e,r=z.create(n.ranges.map(t=>e.wordAt(t.head)||z.cursor(t.head)),n.mainIndex);return!r.eq(n)&&(t(e.update({selection:r})),!0)};function Lbe(e,t){let{main:n,ranges:r}=e.selection,i=e.wordAt(n.head),a=i&&i.from==n.from&&i.to==n.to;for(let n=!1,i=new KL(e.doc,t,r[r.length-1].to);;)if(i.next(),i.done){if(n)return null;i=new KL(e.doc,t,0,Math.max(0,r[r.length-1].from-1)),n=!0}else{if(n&&r.some(e=>e.from==i.value.from))continue;if(a){let t=e.wordAt(i.value.from);if(!t||t.from!=i.value.from||t.to!=i.value.to)continue}return i.value}}var Rbe=({state:e,dispatch:t})=>{let{ranges:n}=e.selection;if(n.some(e=>e.from===e.to))return Ibe({state:e,dispatch:t});let r=e.sliceDoc(n[0].from,n[0].to);if(e.selection.ranges.some(t=>e.sliceDoc(t.from,t.to)!=r))return!1;let i=Lbe(e,r);return i?(t(e.update({selection:e.selection.addRange(z.range(i.from,i.to),!1),effects:B.scrollIntoView(i.to)})),!0):!1},nR=p.define({combine(e){return $e(e,{top:!1,caseSensitive:!1,literal:!1,regexp:!1,wholeWord:!1,createPanel:e=>new Qbe(e),scrollToMatch:e=>B.scrollIntoView(e)})}}),rR=class{constructor(e){this.search=e.search,this.caseSensitive=!!e.caseSensitive,this.literal=!!e.literal,this.regexp=!!e.regexp,this.replace=e.replace||``,this.valid=!!this.search&&(!this.regexp||Dbe(this.search)),this.unquoted=this.unquote(this.search),this.wholeWord=!!e.wholeWord,this.test=e.test}unquote(e){return this.literal?e:e.replace(/\\([nrt\\])/g,(e,t)=>t==`n`?`
175
+ }`,{label:`enum`,detail:`definition`,type:`keyword`})]),RI=new ee,zI=new Set([`Script`,`Block`,`FunctionExpression`,`FunctionDeclaration`,`ArrowFunction`,`MethodDeclaration`,`ForStatement`]);function BI(e){return(t,n)=>{let r=t.node.getChild(`VariableDefinition`);return r&&n(r,e),!0}}var abe=[`FunctionDeclaration`],obe={FunctionDeclaration:BI(`function`),ClassDeclaration:BI(`class`),ClassExpression:()=>!0,EnumDeclaration:BI(`constant`),TypeAliasDeclaration:BI(`type`),NamespaceDeclaration:BI(`namespace`),VariableDefinition(e,t){e.matchContext(abe)||t(e,`variable`)},TypeDefinition(e,t){t(e,`type`)},__proto__:null};function VI(e,t){let n=RI.get(t);if(n)return n;let r=[],i=!0;function a(t,n){let i=e.sliceString(t.from,t.to);r.push({label:i,type:n})}return t.cursor(Qe.IncludeAnonymous).iterate(t=>{if(i)i=!1;else if(t.name){let e=obe[t.name];if(e&&e(t,a)||zI.has(t.name))return!1}else if(t.to-t.from>8192){for(let n of VI(e,t.node))r.push(n);return!1}}),RI.set(t,r),r}var HI=/^[\w$\xa1-\uffff][\w$\d\xa1-\uffff]*$/,UI=[`TemplateString`,`String`,`RegExp`,`LineComment`,`BlockComment`,`VariableDefinition`,`TypeDefinition`,`Label`,`PropertyDefinition`,`PropertyName`,`PrivatePropertyDefinition`,`PrivatePropertyName`,`JSXText`,`JSXAttributeValue`,`JSXOpenTag`,`JSXCloseTag`,`JSXSelfClosingTag`,`.`,`?.`];function WI(e){let t=g(e.state).resolveInner(e.pos,-1);if(UI.indexOf(t.name)>-1)return null;let n=t.name==`VariableName`||t.to-t.from<20&&HI.test(e.state.sliceDoc(t.from,t.to));if(!n&&!e.explicit)return null;let r=[];for(let n=t;n;n=n.parent)zI.has(n.name)&&(r=r.concat(VI(e.state.doc,n)));return{options:r,from:n?t.from:e.pos,validFor:HI}}var GI=Re.define({name:`javascript`,parser:ibe.configure({props:[f.add({IfStatement:ye({except:/^\s*({|else\b)/}),TryStatement:ye({except:/^\s*({|catch\b|finally\b)/}),LabeledStatement:Xe,SwitchBody:e=>{let t=e.textAfter,n=/^\s*\}/.test(t),r=/^\s*(case|default)\b/.test(t);return e.baseIndent+(n?0:r?1:2)*e.unit},Block:We({closing:`}`}),ArrowFunction:e=>e.baseIndent+e.unit,"TemplateString BlockComment":()=>null,"Statement Property":ye({except:/^\s*{/}),JSXElement(e){let t=/^\s*<\//.test(e.textAfter);return e.lineIndent(e.node.from)+(t?0:e.unit)},JSXEscape(e){let t=/\s*\}/.test(e.textAfter);return e.lineIndent(e.node.from)+(t?0:e.unit)},"JSXOpenTag JSXSelfClosingTag"(e){return e.column(e.node.from)+e.unit}}),u.add({"Block ClassBody SwitchBody EnumBody ObjectExpression ArrayExpression ObjectType":Je,BlockComment(e){return{from:e.from+2,to:e.to-2}},JSXElement(e){let t=e.firstChild;if(!t||t.name==`JSXSelfClosingTag`)return null;let n=e.lastChild;return{from:t.to,to:n.type.isError?e.to:n.from}},"JSXSelfClosingTag JSXOpenTag"(e){let t=e.firstChild?.nextSibling,n=e.lastChild;return!t||t.type.isError?null:{from:t.to,to:n.type.isError?e.to:n.from}}})]}),languageData:{closeBrackets:{brackets:[`(`,`[`,`{`,`'`,`"`,"`"]},commentTokens:{line:`//`,block:{open:`/*`,close:`*/`}},indentOnInput:/^\s*(?:case |default:|\{|\}|<\/)$/,wordChars:`$`}}),KI={test:e=>/^JSX/.test(e.name),facet:oe({commentTokens:{block:{open:`{/*`,close:`*/}`}}})},qI=GI.configure({dialect:`ts`},`typescript`),JI=GI.configure({dialect:`jsx`,props:[O.add(e=>e.isTop?[KI]:void 0)]}),YI=GI.configure({dialect:`jsx ts`,props:[O.add(e=>e.isTop?[KI]:void 0)]},`typescript`),XI=e=>({label:e,type:`keyword`}),ZI=`break case const continue default delete export extends false finally in instanceof let new return static super switch this throw true typeof var yield`.split(` `).map(XI),sbe=ZI.concat([`declare`,`implements`,`private`,`protected`,`public`].map(XI));function QI(e={}){let t=e.jsx?e.typescript?YI:JI:e.typescript?qI:GI,n=e.typescript?LI.concat(sbe):II.concat(ZI);return new He(t,[GI.data.of({autocomplete:ot(UI,et(n))}),GI.data.of({autocomplete:WI}),e.jsx?eL:[]])}function cbe(e){for(;;){if(e.name==`JSXOpenTag`||e.name==`JSXSelfClosingTag`||e.name==`JSXFragmentTag`)return e;if(e.name==`JSXEscape`||!e.parent)return null;e=e.parent}}function $I(e,t,n=e.length){for(let r=t?.firstChild;r;r=r.nextSibling)if(r.name==`JSXIdentifier`||r.name==`JSXBuiltin`||r.name==`JSXNamespacedName`||r.name==`JSXMemberExpression`)return e.sliceString(r.from,Math.min(r.to,n));return``}var lbe=typeof navigator==`object`&&/Android\b/.test(navigator.userAgent),eL=B.inputHandler.of((e,t,n,r,i)=>{if((lbe?e.composing:e.compositionStarted)||e.state.readOnly||t!=n||r!=`>`&&r!=`/`||!GI.isActiveAt(e.state,t,-1))return!1;let a=i(),{state:o}=a,s=o.changeByRange(e=>{let{head:t}=e,n=g(o).resolveInner(t-1,-1),i;if(n.name==`JSXStartTag`&&(n=n.parent),!(o.doc.sliceString(t-1,t)!=r||n.name==`JSXAttributeValue`&&n.to>t)){if(r==`>`&&n.name==`JSXFragmentTag`)return{range:e,changes:{from:t,insert:`</>`}};if(r==`/`&&n.name==`JSXStartCloseTag`){let e=n.parent,r=e.parent;if(r&&e.from==t-2&&((i=$I(o.doc,r.firstChild,t))||r.firstChild?.name==`JSXFragmentTag`)){let e=`${i}>`;return{range:z.cursor(t+e.length,-1),changes:{from:t,insert:e}}}}else if(r==`>`){let r=cbe(n);if(r&&r.name==`JSXOpenTag`&&!/^\/?>|^<\//.test(o.doc.sliceString(t,t+2))&&(i=$I(o.doc,r,t)))return{range:e,changes:{from:t,insert:`</${i}>`}}}}return{range:e}});return!s.changes.empty&&(e.dispatch([a,o.update(s,{userEvent:`input.complete`,scrollIntoView:!0})]),!0)}),ube=n({autoCloseTags:()=>TL,html:()=>CL,htmlCompletionSource:()=>_L,htmlCompletionSourceWith:()=>vL,htmlLanguage:()=>SL}),tL=[`_blank`,`_self`,`_top`,`_parent`],nL=[`ascii`,`utf-8`,`utf-16`,`latin1`,`latin1`],rL=[`get`,`post`,`put`,`delete`],iL=[`application/x-www-form-urlencoded`,`multipart/form-data`,`text/plain`],aL=[`true`,`false`],oL={},dbe={a:{attrs:{href:null,ping:null,type:null,media:null,target:tL,hreflang:null}},abbr:oL,address:oL,area:{attrs:{alt:null,coords:null,href:null,target:null,ping:null,media:null,hreflang:null,type:null,shape:[`default`,`rect`,`circle`,`poly`]}},article:oL,aside:oL,audio:{attrs:{src:null,mediagroup:null,crossorigin:[`anonymous`,`use-credentials`],preload:[`none`,`metadata`,`auto`],autoplay:[`autoplay`],loop:[`loop`],controls:[`controls`]}},b:oL,base:{attrs:{href:null,target:tL}},bdi:oL,bdo:oL,blockquote:{attrs:{cite:null}},body:oL,br:oL,button:{attrs:{form:null,formaction:null,name:null,value:null,autofocus:[`autofocus`],disabled:[`autofocus`],formenctype:iL,formmethod:rL,formnovalidate:[`novalidate`],formtarget:tL,type:[`submit`,`reset`,`button`]}},canvas:{attrs:{width:null,height:null}},caption:oL,center:oL,cite:oL,code:oL,col:{attrs:{span:null}},colgroup:{attrs:{span:null}},command:{attrs:{type:[`command`,`checkbox`,`radio`],label:null,icon:null,radiogroup:null,command:null,title:null,disabled:[`disabled`],checked:[`checked`]}},data:{attrs:{value:null}},datagrid:{attrs:{disabled:[`disabled`],multiple:[`multiple`]}},datalist:{attrs:{data:null}},dd:oL,del:{attrs:{cite:null,datetime:null}},details:{attrs:{open:[`open`]}},dfn:oL,div:oL,dl:oL,dt:oL,em:oL,embed:{attrs:{src:null,type:null,width:null,height:null}},eventsource:{attrs:{src:null}},fieldset:{attrs:{disabled:[`disabled`],form:null,name:null}},figcaption:oL,figure:oL,footer:oL,form:{attrs:{action:null,name:null,"accept-charset":nL,autocomplete:[`on`,`off`],enctype:iL,method:rL,novalidate:[`novalidate`],target:tL}},h1:oL,h2:oL,h3:oL,h4:oL,h5:oL,h6:oL,head:{children:[`title`,`base`,`link`,`style`,`meta`,`script`,`noscript`,`command`]},header:oL,hgroup:oL,hr:oL,html:{attrs:{manifest:null}},i:oL,iframe:{attrs:{src:null,srcdoc:null,name:null,width:null,height:null,sandbox:[`allow-top-navigation`,`allow-same-origin`,`allow-forms`,`allow-scripts`],seamless:[`seamless`]}},img:{attrs:{alt:null,src:null,ismap:null,usemap:null,width:null,height:null,crossorigin:[`anonymous`,`use-credentials`]}},input:{attrs:{alt:null,dirname:null,form:null,formaction:null,height:null,list:null,max:null,maxlength:null,min:null,name:null,pattern:null,placeholder:null,size:null,src:null,step:null,value:null,width:null,accept:[`audio/*`,`video/*`,`image/*`],autocomplete:[`on`,`off`],autofocus:[`autofocus`],checked:[`checked`],disabled:[`disabled`],formenctype:iL,formmethod:rL,formnovalidate:[`novalidate`],formtarget:tL,multiple:[`multiple`],readonly:[`readonly`],required:[`required`],type:[`hidden`,`text`,`search`,`tel`,`url`,`email`,`password`,`datetime`,`date`,`month`,`week`,`time`,`datetime-local`,`number`,`range`,`color`,`checkbox`,`radio`,`file`,`submit`,`image`,`reset`,`button`]}},ins:{attrs:{cite:null,datetime:null}},kbd:oL,keygen:{attrs:{challenge:null,form:null,name:null,autofocus:[`autofocus`],disabled:[`disabled`],keytype:[`RSA`]}},label:{attrs:{for:null,form:null}},legend:oL,li:{attrs:{value:null}},link:{attrs:{href:null,type:null,hreflang:null,media:null,sizes:[`all`,`16x16`,`16x16 32x32`,`16x16 32x32 64x64`]}},map:{attrs:{name:null}},mark:oL,menu:{attrs:{label:null,type:[`list`,`context`,`toolbar`]}},meta:{attrs:{content:null,charset:nL,name:[`viewport`,`application-name`,`author`,`description`,`generator`,`keywords`],"http-equiv":[`content-language`,`content-type`,`default-style`,`refresh`]}},meter:{attrs:{value:null,min:null,low:null,high:null,max:null,optimum:null}},nav:oL,noscript:oL,object:{attrs:{data:null,type:null,name:null,usemap:null,form:null,width:null,height:null,typemustmatch:[`typemustmatch`]}},ol:{attrs:{reversed:[`reversed`],start:null,type:[`1`,`a`,`A`,`i`,`I`]},children:[`li`,`script`,`template`,`ul`,`ol`]},optgroup:{attrs:{disabled:[`disabled`],label:null}},option:{attrs:{disabled:[`disabled`],label:null,selected:[`selected`],value:null}},output:{attrs:{for:null,form:null,name:null}},p:oL,param:{attrs:{name:null,value:null}},pre:oL,progress:{attrs:{value:null,max:null}},q:{attrs:{cite:null}},rp:oL,rt:oL,ruby:oL,samp:oL,script:{attrs:{type:[`text/javascript`],src:null,async:[`async`],defer:[`defer`],charset:nL}},section:oL,select:{attrs:{form:null,name:null,size:null,autofocus:[`autofocus`],disabled:[`disabled`],multiple:[`multiple`]}},slot:{attrs:{name:null}},small:oL,source:{attrs:{src:null,type:null,media:null}},span:oL,strong:oL,style:{attrs:{type:[`text/css`],media:null,scoped:null}},sub:oL,summary:oL,sup:oL,table:oL,tbody:oL,td:{attrs:{colspan:null,rowspan:null,headers:null}},template:oL,textarea:{attrs:{dirname:null,form:null,maxlength:null,name:null,placeholder:null,rows:null,cols:null,autofocus:[`autofocus`],disabled:[`disabled`],readonly:[`readonly`],required:[`required`],wrap:[`soft`,`hard`]}},tfoot:oL,th:{attrs:{colspan:null,rowspan:null,headers:null,scope:[`row`,`col`,`rowgroup`,`colgroup`]}},thead:oL,time:{attrs:{datetime:null}},title:oL,tr:oL,track:{attrs:{src:null,label:null,default:null,kind:[`subtitles`,`captions`,`descriptions`,`chapters`,`metadata`],srclang:null}},ul:{children:[`li`,`script`,`template`,`ul`,`ol`]},var:oL,video:{attrs:{src:null,poster:null,width:null,height:null,crossorigin:[`anonymous`,`use-credentials`],preload:[`auto`,`metadata`,`none`],autoplay:[`autoplay`],mediagroup:[`movie`],muted:[`muted`],controls:[`controls`]}},wbr:oL},fbe={accesskey:null,class:null,contenteditable:aL,contextmenu:null,dir:[`ltr`,`rtl`,`auto`],draggable:[`true`,`false`,`auto`],dropzone:[`copy`,`move`,`link`,`string:`,`file:`],hidden:[`hidden`],id:null,inert:[`inert`],itemid:null,itemprop:null,itemref:null,itemscope:[`itemscope`],itemtype:null,lang:[`ar`,`bn`,`de`,`en-GB`,`en-US`,`es`,`fr`,`hi`,`id`,`ja`,`pa`,`pt`,`ru`,`tr`,`zh`],spellcheck:aL,autocorrect:aL,autocapitalize:aL,style:null,tabindex:null,title:null,translate:[`yes`,`no`],rel:[`stylesheet`,`alternate`,`author`,`bookmark`,`help`,`license`,`next`,`nofollow`,`noreferrer`,`prefetch`,`prev`,`search`,`tag`],role:`alert application article banner button cell checkbox complementary contentinfo dialog document feed figure form grid gridcell heading img list listbox listitem main navigation region row rowgroup search switch tab table tabpanel textbox timer`.split(` `),"aria-activedescendant":null,"aria-atomic":aL,"aria-autocomplete":[`inline`,`list`,`both`,`none`],"aria-busy":aL,"aria-checked":[`true`,`false`,`mixed`,`undefined`],"aria-controls":null,"aria-describedby":null,"aria-disabled":aL,"aria-dropeffect":null,"aria-expanded":[`true`,`false`,`undefined`],"aria-flowto":null,"aria-grabbed":[`true`,`false`,`undefined`],"aria-haspopup":aL,"aria-hidden":aL,"aria-invalid":[`true`,`false`,`grammar`,`spelling`],"aria-label":null,"aria-labelledby":null,"aria-level":null,"aria-live":[`off`,`polite`,`assertive`],"aria-multiline":aL,"aria-multiselectable":aL,"aria-owns":null,"aria-posinset":null,"aria-pressed":[`true`,`false`,`mixed`,`undefined`],"aria-readonly":aL,"aria-relevant":null,"aria-required":aL,"aria-selected":[`true`,`false`,`undefined`],"aria-setsize":null,"aria-sort":[`ascending`,`descending`,`none`,`other`],"aria-valuemax":null,"aria-valuemin":null,"aria-valuenow":null,"aria-valuetext":null},sL=`beforeunload copy cut dragstart dragover dragleave dragenter dragend drag paste focus blur change click load mousedown mouseenter mouseleave mouseup keydown keyup resize scroll unload`.split(` `).map(e=>`on`+e);for(let e of sL)fbe[e]=null;var cL=class{constructor(e,t){this.tags={...dbe,...e},this.globalAttrs={...fbe,...t},this.allTags=Object.keys(this.tags),this.globalAttrNames=Object.keys(this.globalAttrs)}};cL.default=new cL;function lL(e,t,n=e.length){if(!t)return``;let r=t.firstChild,i=r&&r.getChild(`TagName`);return i?e.sliceString(i.from,Math.min(i.to,n)):``}function uL(e,t=!1){for(;e;e=e.parent)if(e.name==`Element`){if(t)t=!1;else return e}return null}function dL(e,t,n){return n.tags[lL(e,uL(t))]?.children||n.allTags}function fL(e,t){let n=[];for(let r=uL(t);r&&!r.type.isTop;r=uL(r.parent)){let i=lL(e,r);if(i&&r.lastChild.name==`CloseTag`)break;i&&n.indexOf(i)<0&&(t.name==`EndTag`||t.from>=r.firstChild.to)&&n.push(i)}return n}var pL=/^[:\-\.\w\u00b7-\uffff]*$/;function mL(e,t,n,r,i){let a=/\s*>/.test(e.sliceDoc(i,i+5))?``:`>`,o=uL(n,n.name==`StartTag`||n.name==`TagName`);return{from:r,to:i,options:dL(e.doc,o,t).map(e=>({label:e,type:`type`})).concat(fL(e.doc,n).map((e,t)=>({label:`/`+e,apply:`/`+e+a,type:`type`,boost:99-t}))),validFor:/^\/?[:\-\.\w\u00b7-\uffff]*$/}}function hL(e,t,n,r){let i=/\s*>/.test(e.sliceDoc(r,r+5))?``:`>`;return{from:n,to:r,options:fL(e.doc,t).map((e,t)=>({label:e,apply:e+i,type:`type`,boost:99-t})),validFor:pL}}function pbe(e,t,n,r){let i=[],a=0;for(let r of dL(e.doc,n,t))i.push({label:`<`+r,type:`type`});for(let t of fL(e.doc,n))i.push({label:`</`+t+`>`,type:`type`,boost:99-a++});return{from:r,to:r,options:i,validFor:/^<\/?[:\-\.\w\u00b7-\uffff]*$/}}function mbe(e,t,n,r,i){let a=uL(n),o=a?t.tags[lL(e.doc,a)]:null,s=o&&o.attrs?Object.keys(o.attrs):[];return{from:r,to:i,options:(o&&o.globalAttrs===!1?s:s.length?s.concat(t.globalAttrNames):t.globalAttrNames).map(e=>({label:e,type:`property`})),validFor:pL}}function hbe(e,t,n,r,i){let a=n.parent?.getChild(`AttributeName`),o=[],s;if(a){let c=e.sliceDoc(a.from,a.to),l=t.globalAttrs[c];if(!l){let r=uL(n),i=r?t.tags[lL(e.doc,r)]:null;l=i?.attrs&&i.attrs[c]}if(l){let t=e.sliceDoc(r,i).toLowerCase(),n=`"`,a=`"`;/^['"]/.test(t)?(s=t[0]==`"`?/^[^"]*$/:/^[^']*$/,n=``,a=e.sliceDoc(i,i+1)==t[0]?``:t[0],t=t.slice(1),r++):s=/^[^\s<>='"]*$/;for(let e of l)o.push({label:e,apply:n+e+a,type:`constant`})}}return{from:r,to:i,options:o,validFor:s}}function gL(e,t){let{state:n,pos:r}=t,i=g(n).resolveInner(r,-1),a=i.resolve(r);for(let e=r,t;a==i&&(t=i.childBefore(e));){let n=t.lastChild;if(!n||!n.type.isError||n.from<n.to)break;a=i=t,e=n.from}return i.name==`TagName`?i.parent&&/CloseTag$/.test(i.parent.name)?hL(n,i,i.from,r):mL(n,e,i,i.from,r):i.name==`StartTag`||i.name==`IncompleteTag`?mL(n,e,i,r,r):i.name==`StartCloseTag`||i.name==`IncompleteCloseTag`?hL(n,i,r,r):i.name==`OpenTag`||i.name==`SelfClosingTag`||i.name==`AttributeName`?mbe(n,e,i,i.name==`AttributeName`?i.from:r,r):i.name==`Is`||i.name==`AttributeValue`||i.name==`UnquotedAttributeValue`?hbe(n,e,i,i.name==`Is`?r:i.from,r):t.explicit&&(a.name==`Element`||a.name==`Text`||a.name==`Document`)?pbe(n,e,i,r):null}function _L(e){return gL(cL.default,e)}function vL(e){let{extraTags:t,extraGlobalAttributes:n}=e,r=n||t?new cL(t,n):cL.default;return e=>gL(r,e)}var gbe=GI.parser.configure({top:`SingleExpression`}),yL=[{tag:`script`,attrs:e=>e.type==`text/typescript`||e.lang==`ts`,parser:qI.parser},{tag:`script`,attrs:e=>e.type==`text/babel`||e.type==`text/jsx`,parser:JI.parser},{tag:`script`,attrs:e=>e.type==`text/typescript-jsx`,parser:YI.parser},{tag:`script`,attrs(e){return/^(importmap|speculationrules|application\/(.+\+)?json)$/i.test(e.type)},parser:gbe},{tag:`script`,attrs(e){return!e.type||/^(?:text|application)\/(?:x-)?(?:java|ecma)script$|^module$|^$/i.test(e.type)},parser:GI.parser},{tag:`style`,attrs(e){return(!e.lang||e.lang==`css`)&&(!e.type||/^(text\/)?(x-)?(stylesheet|css)$/i.test(e.type))},parser:t.parser}],bL=[{name:`style`,parser:t.parser.configure({top:`Styles`})}].concat(sL.map(e=>({name:e,parser:GI.parser}))),xL=Re.define({name:`html`,parser:Dye.configure({props:[f.add({Element(e){let t=/^(\s*)(<\/)?/.exec(e.textAfter);return e.node.to<=e.pos+t[0].length?e.continue():e.lineIndent(e.node.from)+(t[2]?0:e.unit)},"OpenTag CloseTag SelfClosingTag"(e){return e.column(e.node.from)+e.unit},Document(e){if(e.pos+/\s*/.exec(e.textAfter)[0].length<e.node.to)return e.continue();let t=null,n;for(let n=e.node;;){let e=n.lastChild;if(!e||e.name!=`Element`||e.to!=n.to)break;t=n=e}return t&&!((n=t.lastChild)&&(n.name==`CloseTag`||n.name==`SelfClosingTag`))?e.lineIndent(t.from)+e.unit:null}}),u.add({Element(e){let t=e.firstChild,n=e.lastChild;return!t||t.name!=`OpenTag`?null:{from:t.to,to:n.name==`CloseTag`?n.from:e.to}}}),De.add({"OpenTag CloseTag":e=>e.getChild(`TagName`)})]}),languageData:{commentTokens:{block:{open:`<!--`,close:`-->`}},indentOnInput:/^\s*<\/\w+\W$/,wordChars:`-_`}}),SL=xL.configure({wrap:kI(yL,bL)});function CL(e={}){let t=``,n;e.matchClosingTags===!1&&(t=`noMatch`),e.selfClosingTags===!0&&(t=(t?t+` `:``)+`selfClosing`),(e.nestedLanguages&&e.nestedLanguages.length||e.nestedAttributes&&e.nestedAttributes.length)&&(n=kI((e.nestedLanguages||[]).concat(yL),(e.nestedAttributes||[]).concat(bL)));let r=n?xL.configure({wrap:n,dialect:t}):t?SL.configure({dialect:t}):SL;return new He(r,[SL.data.of({autocomplete:vL(e)}),e.autoCloseTags===!1?[]:TL,QI().support,i().support])}var wL=new Set(`area base br col command embed frame hr img input keygen link meta param source track wbr menuitem`.split(` `));function _be(e,t,n){for(;;){if(t.lastChild?.name!=`CloseTag`)return!1;let r=t.parent;if(!r||lL(e,r)!=n)return!0;t=r}}var TL=B.inputHandler.of((e,t,n,r,i)=>{if(e.composing||e.state.readOnly||t!=n||r!=`>`&&r!=`/`||!SL.isActiveAt(e.state,t,-1))return!1;let a=i(),{state:o}=a,s=o.changeByRange(e=>{let t=o.doc.sliceString(e.from-1,e.to)==r,{head:n}=e,i=g(o).resolveInner(n,-1),a;if(t&&r==`>`&&i.name==`EndTag`){let t=i.parent;if((a=lL(o.doc,t.parent,n))&&!wL.has(a)&&!_be(o.doc,t.parent,a))return{range:e,changes:{from:n,to:n+ +(o.doc.sliceString(n,n+1)===`>`),insert:`</${a}>`}}}else if(t&&r==`/`&&i.name==`IncompleteCloseTag`){let e=i.parent;if(i.from==n-2&&e.lastChild?.name!=`CloseTag`&&(a=lL(o.doc,e,n))&&!wL.has(a)){let e=n+ +(o.doc.sliceString(n,n+1)===`>`),t=`${a}>`;return{range:z.cursor(n+t.length,-1),changes:{from:n,to:e,insert:t}}}}return{range:e}});return!s.changes.empty&&(e.dispatch([a,o.update(s,{userEvent:`input.complete`,scrollIntoView:!0})]),!0)});function vbe(e,t,n,r){let i=kd(yS),a=jd(sC),o=H.useRef(null),{lexicalNode:s}=BP(),c=H.useRef(!1),l=H.useRef(!1),u=H.useCallback(()=>{a({editorType:t,rootNode:s,editorRef:o.current})},[t,s,a]),d=H.useCallback(t=>{if(t.key===`ArrowDown`){let t=o.current?.getCodemirror()?.state;t&&t.doc.length===t.selection.ranges[0].to&&(c.current?(i?.update(()=>{var t;let n=qg(e);n.getNextSibling()?((t=o.current?.getCodemirror())==null||t.contentDOM.blur(),n.selectNext()):n.insertAfter(Dg())}),c.current=!1):c.current=!0)}else if(t.key===`ArrowUp`){let t=o.current?.getCodemirror()?.state;t&&t.selection.ranges[0].from===0&&(l.current?(i?.update(()=>{var t;let n=qg(e);n.getPreviousSibling()&&((t=o.current?.getCodemirror())==null||t.contentDOM.blur(),n.selectPrevious())}),l.current=!1):l.current=!0)}else t.key===`Enter`?t.stopPropagation():(t.key===`Backspace`||t.key===`Delete`)&&(o.current?.getCodemirror()?.state)?.doc.length===0&&i?.update(()=>{qg(e).remove()})},[i,e]);return H.useEffect(()=>{let e=o.current;return setTimeout(()=>{var t,n;(t=e?.getCodemirror())==null||t.contentDOM.addEventListener(`focus`,u),(n=e?.getCodemirror())==null||n.contentDOM.addEventListener(`keydown`,d)},300),()=>{var t,n;(t=e?.getCodemirror())==null||t.contentDOM.removeEventListener(`focus`,u),(n=e?.getCodemirror())==null||n.contentDOM.removeEventListener(`keydown`,d)}},[o,u,d,n]),H.useEffect(()=>{r.subscribe(()=>{var e;(e=o.current?.getCodemirror())==null||e.focus(),u()})},[r,o,e,u]),o}function Z(e){return new He(ge.define(e))}function EL(e){return X(()=>import(`./dist-mpRGeo_R.js`).then(t=>t.sql({dialect:t[e]})),__vite__mapDeps([0,1,2]))}var ybe=[V.of({name:`C`,extensions:[`c`,`h`,`ino`],load(){return X(()=>import(`./dist-DHvUPfrF.js`).then(e=>e.cpp()),__vite__mapDeps([3,1]))}}),V.of({name:`C++`,alias:[`cpp`],extensions:[`cpp`,`c++`,`cc`,`cxx`,`hpp`,`h++`,`hh`,`hxx`],load(){return X(()=>import(`./dist-DHvUPfrF.js`).then(e=>e.cpp()),__vite__mapDeps([3,1]))}}),V.of({name:`CQL`,alias:[`cassandra`],extensions:[`cql`],load(){return EL(`Cassandra`)}}),V.of({name:`CSS`,extensions:[`css`],load(){return X(()=>import(`./dist-DLJCGrGQ.js`).then(e=>e.i).then(e=>e.css()),__vite__mapDeps([4,1]))}}),V.of({name:`Go`,extensions:[`go`],load(){return X(()=>import(`./dist-LCx98fA_.js`).then(e=>e.go()),__vite__mapDeps([5,1,2]))}}),V.of({name:`HTML`,alias:[`xhtml`],extensions:[`html`,`htm`,`handlebars`,`hbs`],load(){return X(()=>Promise.resolve().then(()=>ube).then(e=>e.html()),void 0)}}),V.of({name:`Java`,extensions:[`java`],load(){return X(()=>import(`./dist-DpF08Yd7.js`).then(e=>e.java()),__vite__mapDeps([6,1]))}}),V.of({name:`JavaScript`,alias:[`ecmascript`,`js`,`node`],extensions:[`js`,`mjs`,`cjs`],load(){return X(()=>Promise.resolve().then(()=>FI).then(e=>e.javascript()),void 0)}}),V.of({name:`Jinja`,extensions:[`j2`,`jinja`,`jinja2`],load(){return X(()=>import(`./dist-23lt_7qm.js`).then(e=>e.jinja()),__vite__mapDeps([7,1]))}}),V.of({name:`JSON`,alias:[`json5`],extensions:[`json`,`map`],load(){return X(()=>import(`./dist-RKTRnzGb.js`).then(e=>e.json()),__vite__mapDeps([8,1]))}}),V.of({name:`JSX`,extensions:[`jsx`],load(){return X(()=>Promise.resolve().then(()=>FI).then(e=>e.javascript({jsx:!0})),void 0)}}),V.of({name:`LESS`,extensions:[`less`],load(){return X(()=>import(`./dist-fPhZsAUX.js`).then(e=>e.less()),__vite__mapDeps([9,4,1]))}}),V.of({name:`Liquid`,extensions:[`liquid`],load(){return X(()=>import(`./dist-DsgL8w-W.js`).then(e=>e.liquid()),__vite__mapDeps([10,1]))}}),V.of({name:`MariaDB SQL`,load(){return EL(`MariaSQL`)}}),V.of({name:`Markdown`,extensions:[`md`,`markdown`,`mkd`],load(){return X(()=>Promise.resolve().then(()=>bwe).then(e=>e.markdown()),void 0)}}),V.of({name:`MS SQL`,load(){return EL(`MSSQL`)}}),V.of({name:`MySQL`,load(){return EL(`MySQL`)}}),V.of({name:`PHP`,extensions:[`php`,`php3`,`php4`,`php5`,`php7`,`phtml`],load(){return X(()=>import(`./dist-Bf2KScPo.js`).then(e=>e.php()),__vite__mapDeps([11,1]))}}),V.of({name:`PLSQL`,extensions:[`pls`],load(){return EL(`PLSQL`)}}),V.of({name:`PostgreSQL`,load(){return EL(`PostgreSQL`)}}),V.of({name:`Python`,extensions:[`BUILD`,`bzl`,`py`,`pyw`],filename:/^(BUCK|BUILD)$/,load(){return X(()=>import(`./dist-DTeLDijr.js`).then(e=>e.python()),__vite__mapDeps([12,1,2]))}}),V.of({name:`Rust`,extensions:[`rs`],load(){return X(()=>import(`./dist-eddbbGyw.js`).then(e=>e.rust()),__vite__mapDeps([13,1]))}}),V.of({name:`Sass`,extensions:[`sass`],load(){return X(()=>import(`./dist-BJ-TIk3N.js`).then(e=>e.sass({indented:!0})),__vite__mapDeps([14,4,1]))}}),V.of({name:`SCSS`,extensions:[`scss`],load(){return X(()=>import(`./dist-BJ-TIk3N.js`).then(e=>e.sass()),__vite__mapDeps([14,4,1]))}}),V.of({name:`SQL`,extensions:[`sql`],load(){return EL(`StandardSQL`)}}),V.of({name:`SQLite`,load(){return EL(`SQLite`)}}),V.of({name:`TSX`,extensions:[`tsx`],load(){return X(()=>Promise.resolve().then(()=>FI).then(e=>e.javascript({jsx:!0,typescript:!0})),void 0)}}),V.of({name:`TypeScript`,alias:[`ts`],extensions:[`ts`,`mts`,`cts`],load(){return X(()=>Promise.resolve().then(()=>FI).then(e=>e.javascript({typescript:!0})),void 0)}}),V.of({name:`WebAssembly`,extensions:[`wat`,`wast`],load(){return X(()=>import(`./dist-DMiglryg.js`).then(e=>e.wast()),__vite__mapDeps([15,1]))}}),V.of({name:`XML`,alias:[`rss`,`wsdl`,`xsd`],extensions:[`xml`,`xsl`,`xsd`,`svg`],load(){return X(()=>import(`./dist-XVYGiB-c.js`).then(e=>e.xml()),__vite__mapDeps([16,1]))}}),V.of({name:`YAML`,alias:[`yml`],extensions:[`yaml`,`yml`],load(){return X(()=>import(`./dist-CswnpKik.js`).then(e=>e.yaml()),__vite__mapDeps([17,1]))}}),V.of({name:`APL`,extensions:[`dyalog`,`apl`],load(){return X(()=>import(`./apl-gfMMiTNf.js`).then(e=>Z(e.apl)),[])}}),V.of({name:`PGP`,alias:[`asciiarmor`],extensions:[`asc`,`pgp`,`sig`],load(){return X(()=>import(`./asciiarmor-C_eisQCp.js`).then(e=>Z(e.asciiArmor)),[])}}),V.of({name:`ASN.1`,extensions:[`asn`,`asn1`],load(){return X(()=>import(`./asn1-DCl_8MCW.js`).then(e=>Z(e.asn1({}))),[])}}),V.of({name:`Asterisk`,filename:/^extensions\.conf$/i,load(){return X(()=>import(`./asterisk-BEn0Cwpx.js`).then(e=>Z(e.asterisk)),[])}}),V.of({name:`Brainfuck`,extensions:[`b`,`bf`],load(){return X(()=>import(`./brainfuck-D5EjA2JK.js`).then(e=>Z(e.brainfuck)),[])}}),V.of({name:`Cobol`,extensions:[`cob`,`cpy`],load(){return X(()=>import(`./cobol-DHLQUbN7.js`).then(e=>Z(e.cobol)),[])}}),V.of({name:`C#`,alias:[`csharp`,`cs`],extensions:[`cs`],load(){return X(()=>import(`./clike-D_6L3tnO.js`).then(e=>Z(e.csharp)),[])}}),V.of({name:`Clojure`,extensions:[`clj`,`cljc`,`cljx`],load(){return X(()=>import(`./clojure-BflJGmDX.js`).then(e=>Z(e.clojure)),[])}}),V.of({name:`ClojureScript`,extensions:[`cljs`],load(){return X(()=>import(`./clojure-BflJGmDX.js`).then(e=>Z(e.clojure)),[])}}),V.of({name:`Closure Stylesheets (GSS)`,extensions:[`gss`],load(){return X(()=>import(`./css-CnaYoQib.js`).then(e=>Z(e.gss)),[])}}),V.of({name:`CMake`,extensions:[`cmake`,`cmake.in`],filename:/^CMakeLists\.txt$/,load(){return X(()=>import(`./cmake-84nbDH0I.js`).then(e=>Z(e.cmake)),[])}}),V.of({name:`CoffeeScript`,alias:[`coffee`,`coffee-script`],extensions:[`coffee`],load(){return X(()=>import(`./coffeescript-De_zI4J0.js`).then(e=>Z(e.coffeeScript)),[])}}),V.of({name:`Common Lisp`,alias:[`lisp`],extensions:[`cl`,`lisp`,`el`],load(){return X(()=>import(`./commonlisp-DgAKBe0r.js`).then(e=>Z(e.commonLisp)),[])}}),V.of({name:`Cypher`,extensions:[`cyp`,`cypher`],load(){return X(()=>import(`./cypher-p9eYesGn.js`).then(e=>Z(e.cypher)),[])}}),V.of({name:`Cython`,extensions:[`pyx`,`pxd`,`pxi`],load(){return X(()=>import(`./python-B_1Jd8HM.js`).then(e=>Z(e.cython)),[])}}),V.of({name:`Crystal`,extensions:[`cr`],load(){return X(()=>import(`./crystal-Bsdphhtm.js`).then(e=>Z(e.crystal)),[])}}),V.of({name:`D`,extensions:[`d`],load(){return X(()=>import(`./d-DWkQyNnU.js`).then(e=>Z(e.d)),[])}}),V.of({name:`Dart`,extensions:[`dart`],load(){return X(()=>import(`./clike-D_6L3tnO.js`).then(e=>Z(e.dart)),[])}}),V.of({name:`diff`,extensions:[`diff`,`patch`],load(){return X(()=>import(`./diff-ChtP43wD.js`).then(e=>Z(e.diff)),[])}}),V.of({name:`Dockerfile`,filename:/^Dockerfile$/,load(){return X(()=>import(`./dockerfile-DJkHQgkl.js`).then(e=>Z(e.dockerFile)),__vite__mapDeps([18,19]))}}),V.of({name:`DTD`,extensions:[`dtd`],load(){return X(()=>import(`./dtd-DTF72YNO.js`).then(e=>Z(e.dtd)),[])}}),V.of({name:`Dylan`,extensions:[`dylan`,`dyl`,`intr`],load(){return X(()=>import(`./dylan-BCDoL_-p.js`).then(e=>Z(e.dylan)),[])}}),V.of({name:`EBNF`,load(){return X(()=>import(`./ebnf-D4c0_ac3.js`).then(e=>Z(e.ebnf)),[])}}),V.of({name:`ECL`,extensions:[`ecl`],load(){return X(()=>import(`./ecl-BVIeWmwY.js`).then(e=>Z(e.ecl)),[])}}),V.of({name:`edn`,extensions:[`edn`],load(){return X(()=>import(`./clojure-BflJGmDX.js`).then(e=>Z(e.clojure)),[])}}),V.of({name:`Eiffel`,extensions:[`e`],load(){return X(()=>import(`./eiffel-BEjRio4Q.js`).then(e=>Z(e.eiffel)),[])}}),V.of({name:`Elm`,extensions:[`elm`],load(){return X(()=>import(`./elm-Cshzl8qu.js`).then(e=>Z(e.elm)),[])}}),V.of({name:`Erlang`,extensions:[`erl`],load(){return X(()=>import(`./erlang-BV0c4Hdn.js`).then(e=>Z(e.erlang)),[])}}),V.of({name:`Esper`,load(){return X(()=>import(`./sql-DuQMFDvy.js`).then(e=>Z(e.esper)),[])}}),V.of({name:`Factor`,extensions:[`factor`],load(){return X(()=>import(`./factor-LKH5gN8L.js`).then(e=>Z(e.factor)),__vite__mapDeps([20,19]))}}),V.of({name:`FCL`,load(){return X(()=>import(`./fcl-ClOhbFR7.js`).then(e=>Z(e.fcl)),[])}}),V.of({name:`Forth`,extensions:[`forth`,`fth`,`4th`],load(){return X(()=>import(`./forth-Cezjo90N.js`).then(e=>Z(e.forth)),[])}}),V.of({name:`Fortran`,extensions:[`f`,`for`,`f77`,`f90`,`f95`],load(){return X(()=>import(`./fortran-Bt6PBEDR.js`).then(e=>Z(e.fortran)),[])}}),V.of({name:`F#`,alias:[`fsharp`],extensions:[`fs`],load(){return X(()=>import(`./mllike-B45xgp2S.js`).then(e=>Z(e.fSharp)),[])}}),V.of({name:`Gas`,extensions:[`s`],load(){return X(()=>import(`./gas-BHEdbvp9.js`).then(e=>Z(e.gas)),[])}}),V.of({name:`Gherkin`,extensions:[`feature`],load(){return X(()=>import(`./gherkin-oBAE_ms0.js`).then(e=>Z(e.gherkin)),[])}}),V.of({name:`Groovy`,extensions:[`groovy`,`gradle`],filename:/^Jenkinsfile$/,load(){return X(()=>import(`./groovy-CUpZ7dEl.js`).then(e=>Z(e.groovy)),[])}}),V.of({name:`Haskell`,extensions:[`hs`],load(){return X(()=>import(`./haskell-BRsoo5mP.js`).then(e=>Z(e.haskell)),[])}}),V.of({name:`Haxe`,extensions:[`hx`],load(){return X(()=>import(`./haxe-DjVOVvNP.js`).then(e=>Z(e.haxe)),[])}}),V.of({name:`HXML`,extensions:[`hxml`],load(){return X(()=>import(`./haxe-DjVOVvNP.js`).then(e=>Z(e.hxml)),[])}}),V.of({name:`HTTP`,load(){return X(()=>import(`./http-CLVgA2GD.js`).then(e=>Z(e.http)),[])}}),V.of({name:`IDL`,extensions:[`pro`],load(){return X(()=>import(`./idl-BUZw3wgd.js`).then(e=>Z(e.idl)),[])}}),V.of({name:`JSON-LD`,alias:[`jsonld`],extensions:[`jsonld`],load(){return X(()=>import(`./javascript-DoL9Wb-Q.js`).then(e=>Z(e.jsonld)),[])}}),V.of({name:`Julia`,extensions:[`jl`],load(){return X(()=>import(`./julia-CQfgDRfP.js`).then(e=>Z(e.julia)),[])}}),V.of({name:`Kotlin`,extensions:[`kt`,`kts`],load(){return X(()=>import(`./clike-D_6L3tnO.js`).then(e=>Z(e.kotlin)),[])}}),V.of({name:`LiveScript`,alias:[`ls`],extensions:[`ls`],load(){return X(()=>import(`./livescript-BXxG0Yva.js`).then(e=>Z(e.liveScript)),[])}}),V.of({name:`Lua`,extensions:[`lua`],load(){return X(()=>import(`./lua-CiA1ziua.js`).then(e=>Z(e.lua)),[])}}),V.of({name:`mIRC`,extensions:[`mrc`],load(){return X(()=>import(`./mirc-C9zpzAZU.js`).then(e=>Z(e.mirc)),[])}}),V.of({name:`Mathematica`,extensions:[`m`,`nb`,`wl`,`wls`],load(){return X(()=>import(`./mathematica-u8YMmbU0.js`).then(e=>Z(e.mathematica)),[])}}),V.of({name:`Modelica`,extensions:[`mo`],load(){return X(()=>import(`./modelica-CqHI_q-D.js`).then(e=>Z(e.modelica)),[])}}),V.of({name:`MUMPS`,extensions:[`mps`],load(){return X(()=>import(`./mumps-BSzj6Xyz.js`).then(e=>Z(e.mumps)),[])}}),V.of({name:`Mbox`,extensions:[`mbox`],load(){return X(()=>import(`./mbox-BEMVcqjs.js`).then(e=>Z(e.mbox)),[])}}),V.of({name:`Nginx`,filename:/nginx.*\.conf$/i,load(){return X(()=>import(`./nginx-BMaDbqW3.js`).then(e=>Z(e.nginx)),[])}}),V.of({name:`NSIS`,extensions:[`nsh`,`nsi`],load(){return X(()=>import(`./nsis-CfSuhXs5.js`).then(e=>Z(e.nsis)),__vite__mapDeps([21,19]))}}),V.of({name:`NTriples`,extensions:[`nt`,`nq`],load(){return X(()=>import(`./ntriples-B9h1VB_g.js`).then(e=>Z(e.ntriples)),[])}}),V.of({name:`Objective-C`,alias:[`objective-c`,`objc`],extensions:[`m`],load(){return X(()=>import(`./clike-D_6L3tnO.js`).then(e=>Z(e.objectiveC)),[])}}),V.of({name:`Objective-C++`,alias:[`objective-c++`,`objc++`],extensions:[`mm`],load(){return X(()=>import(`./clike-D_6L3tnO.js`).then(e=>Z(e.objectiveCpp)),[])}}),V.of({name:`OCaml`,extensions:[`ml`,`mli`,`mll`,`mly`],load(){return X(()=>import(`./mllike-B45xgp2S.js`).then(e=>Z(e.oCaml)),[])}}),V.of({name:`Octave`,extensions:[`m`],load(){return X(()=>import(`./octave-D2Q8cUp1.js`).then(e=>Z(e.octave)),[])}}),V.of({name:`Oz`,extensions:[`oz`],load(){return X(()=>import(`./oz-BwTct_5T.js`).then(e=>Z(e.oz)),[])}}),V.of({name:`Pascal`,extensions:[`p`,`pas`],load(){return X(()=>import(`./pascal-Dp_KdFgX.js`).then(e=>Z(e.pascal)),[])}}),V.of({name:`Perl`,extensions:[`pl`,`pm`],load(){return X(()=>import(`./perl-BkSkiI9m.js`).then(e=>Z(e.perl)),[])}}),V.of({name:`Pig`,extensions:[`pig`],load(){return X(()=>import(`./pig-AF4Hwhju.js`).then(e=>Z(e.pig)),[])}}),V.of({name:`PowerShell`,extensions:[`ps1`,`psd1`,`psm1`],load(){return X(()=>import(`./powershell-BcIto6Sf.js`).then(e=>Z(e.powerShell)),[])}}),V.of({name:`Properties files`,alias:[`ini`,`properties`],extensions:[`properties`,`ini`,`in`],load(){return X(()=>import(`./properties-C357ku5U.js`).then(e=>Z(e.properties)),[])}}),V.of({name:`ProtoBuf`,extensions:[`proto`],load(){return X(()=>import(`./protobuf-D1ij_kNL.js`).then(e=>Z(e.protobuf)),[])}}),V.of({name:`Pug`,alias:[`jade`],extensions:[`pug`,`jade`],load(){return X(()=>import(`./pug-Gsm0M45u.js`).then(e=>Z(e.pug)),__vite__mapDeps([22,23]))}}),V.of({name:`Puppet`,extensions:[`pp`],load(){return X(()=>import(`./puppet-BZyAS7I4.js`).then(e=>Z(e.puppet)),[])}}),V.of({name:`Q`,extensions:[`q`],load(){return X(()=>import(`./q-B9NhS7L_.js`).then(e=>Z(e.q)),[])}}),V.of({name:`R`,alias:[`rscript`],extensions:[`r`,`R`],load(){return X(()=>import(`./r-CxDmU1I4.js`).then(e=>Z(e.r)),[])}}),V.of({name:`RPM Changes`,load(){return X(()=>import(`./rpm-gpDK5sbt.js`).then(e=>Z(e.rpmChanges)),[])}}),V.of({name:`RPM Spec`,extensions:[`spec`],load(){return X(()=>import(`./rpm-gpDK5sbt.js`).then(e=>Z(e.rpmSpec)),[])}}),V.of({name:`Ruby`,alias:[`jruby`,`macruby`,`rake`,`rb`,`rbx`],extensions:[`rb`],filename:/^(Gemfile|Rakefile)$/,load(){return X(()=>import(`./ruby-BjXV7-Qa.js`).then(e=>Z(e.ruby)),[])}}),V.of({name:`SAS`,extensions:[`sas`],load(){return X(()=>import(`./sas-C2OyD2Y6.js`).then(e=>Z(e.sas)),[])}}),V.of({name:`Scala`,extensions:[`scala`],load(){return X(()=>import(`./clike-D_6L3tnO.js`).then(e=>Z(e.scala)),[])}}),V.of({name:`Scheme`,extensions:[`scm`,`ss`],load(){return X(()=>import(`./scheme-D9qYN0V5.js`).then(e=>Z(e.scheme)),[])}}),V.of({name:`Shell`,alias:[`bash`,`sh`,`zsh`],extensions:[`sh`,`ksh`,`bash`],filename:/^PKGBUILD$/,load(){return X(()=>import(`./shell-DwuoZtxw.js`).then(e=>Z(e.shell)),[])}}),V.of({name:`Sieve`,extensions:[`siv`,`sieve`],load(){return X(()=>import(`./sieve-BAxa3IjF.js`).then(e=>Z(e.sieve)),[])}}),V.of({name:`Smalltalk`,extensions:[`st`],load(){return X(()=>import(`./smalltalk-BLp5-jwC.js`).then(e=>Z(e.smalltalk)),[])}}),V.of({name:`Solr`,load(){return X(()=>import(`./solr-BBopId9w.js`).then(e=>Z(e.solr)),[])}}),V.of({name:`SML`,extensions:[`sml`,`sig`,`fun`,`smackspec`],load(){return X(()=>import(`./mllike-B45xgp2S.js`).then(e=>Z(e.sml)),[])}}),V.of({name:`SPARQL`,alias:[`sparul`],extensions:[`rq`,`sparql`],load(){return X(()=>import(`./sparql-Dz-mlCAC.js`).then(e=>Z(e.sparql)),[])}}),V.of({name:`Spreadsheet`,alias:[`excel`,`formula`],load(){return X(()=>import(`./spreadsheet-CTIncYxj.js`).then(e=>Z(e.spreadsheet)),[])}}),V.of({name:`Squirrel`,extensions:[`nut`],load(){return X(()=>import(`./clike-D_6L3tnO.js`).then(e=>Z(e.squirrel)),[])}}),V.of({name:`Stylus`,extensions:[`styl`],load(){return X(()=>import(`./stylus-BOVgKnng.js`).then(e=>Z(e.stylus)),[])}}),V.of({name:`Swift`,extensions:[`swift`],load(){return X(()=>import(`./swift-DKB6_1j6.js`).then(e=>Z(e.swift)),[])}}),V.of({name:`sTeX`,load(){return X(()=>import(`./stex-DNzd62Q_.js`).then(e=>Z(e.stex)),[])}}),V.of({name:`LaTeX`,alias:[`tex`],extensions:[`text`,`ltx`,`tex`],load(){return X(()=>import(`./stex-DNzd62Q_.js`).then(e=>Z(e.stex)),[])}}),V.of({name:`SystemVerilog`,extensions:[`v`,`sv`,`svh`],load(){return X(()=>import(`./verilog-7LoJAqYT.js`).then(e=>Z(e.verilog)),[])}}),V.of({name:`Tcl`,extensions:[`tcl`],load(){return X(()=>import(`./tcl-BGfruO1u.js`).then(e=>Z(e.tcl)),[])}}),V.of({name:`Textile`,extensions:[`textile`],load(){return X(()=>import(`./textile-C4jVoHG1.js`).then(e=>Z(e.textile)),[])}}),V.of({name:`TiddlyWiki`,load(){return X(()=>import(`./tiddlywiki-VlUiK86J.js`).then(e=>Z(e.tiddlyWiki)),[])}}),V.of({name:`Tiki wiki`,load(){return X(()=>import(`./tiki-AK6FwT8q.js`).then(e=>Z(e.tiki)),[])}}),V.of({name:`TOML`,extensions:[`toml`],load(){return X(()=>import(`./toml-BPTmHmyx.js`).then(e=>Z(e.toml)),[])}}),V.of({name:`Troff`,extensions:[`1`,`2`,`3`,`4`,`5`,`6`,`7`,`8`,`9`],load(){return X(()=>import(`./troff-C2dAgh7P.js`).then(e=>Z(e.troff)),[])}}),V.of({name:`TTCN`,extensions:[`ttcn`,`ttcn3`,`ttcnpp`],load(){return X(()=>import(`./ttcn-PPSTk1ow.js`).then(e=>Z(e.ttcn)),[])}}),V.of({name:`TTCN_CFG`,extensions:[`cfg`],load(){return X(()=>import(`./ttcn-cfg-2b4Gb5sE.js`).then(e=>Z(e.ttcnCfg)),[])}}),V.of({name:`Turtle`,extensions:[`ttl`],load(){return X(()=>import(`./turtle-Cx3rYX2g.js`).then(e=>Z(e.turtle)),[])}}),V.of({name:`Web IDL`,extensions:[`webidl`],load(){return X(()=>import(`./webidl-D5jiJvOU.js`).then(e=>Z(e.webIDL)),[])}}),V.of({name:`VB.NET`,extensions:[`vb`],load(){return X(()=>import(`./vb-BthdM_4N.js`).then(e=>Z(e.vb)),[])}}),V.of({name:`VBScript`,extensions:[`vbs`],load(){return X(()=>import(`./vbscript-D9f6rSsU.js`).then(e=>Z(e.vbScript)),[])}}),V.of({name:`Velocity`,extensions:[`vtl`],load(){return X(()=>import(`./velocity-CqftRsjg.js`).then(e=>Z(e.velocity)),[])}}),V.of({name:`Verilog`,extensions:[`v`],load(){return X(()=>import(`./verilog-7LoJAqYT.js`).then(e=>Z(e.verilog)),[])}}),V.of({name:`VHDL`,extensions:[`vhd`,`vhdl`],load(){return X(()=>import(`./vhdl-kS471soi.js`).then(e=>Z(e.vhdl)),[])}}),V.of({name:`XQuery`,extensions:[`xy`,`xquery`,`xq`,`xqm`,`xqy`],load(){return X(()=>import(`./xquery-BKJx4mf9.js`).then(e=>Z(e.xQuery)),[])}}),V.of({name:`Yacas`,extensions:[`ys`],load(){return X(()=>import(`./yacas-CXXgtw0p.js`).then(e=>Z(e.yacas)),[])}}),V.of({name:`Z80`,extensions:[`z80`],load(){return X(()=>import(`./z80-Co3PbHdE.js`).then(e=>Z(e.z80)),[])}}),V.of({name:`MscGen`,extensions:[`mscgen`,`mscin`,`msc`],load(){return X(()=>import(`./mscgen-qgSLujhx.js`).then(e=>Z(e.mscgen)),[])}}),V.of({name:`Xù`,extensions:[`xu`],load(){return X(()=>import(`./mscgen-qgSLujhx.js`).then(e=>Z(e.xu)),[])}}),V.of({name:`MsGenny`,extensions:[`msgenny`],load(){return X(()=>import(`./mscgen-qgSLujhx.js`).then(e=>Z(e.msgenny)),[])}}),V.of({name:`Vue`,extensions:[`vue`],load(){return X(()=>import(`./dist-CH3SvpYV.js`).then(e=>e.vue()),__vite__mapDeps([24,1]))}}),V.of({name:`Angular Template`,load(){return X(()=>import(`./dist-V06sfuZa.js`).then(e=>e.angular()),__vite__mapDeps([25,1]))}})],DL=`#2e3440`,OL=`#3b4252`,kL=`#434c5e`,AL=`#4c566a`,jL=`#e5e9f0`,ML=`#eceff4`,NL=`#8fbcbb`,PL=`#88c0d0`,bbe=`#81a1c1`,FL=`#5e81ac`,xbe=`#bf616a`,IL=`#d08770`,LL=`#ebcb8b`,RL=`#a3be8c`,Sbe=`#b48ead`,zL=`#d30102`,BL=ML,VL=BL,Cbe=`#ffffff`,HL=OL,wbe=BL,UL=OL,Tbe=B.theme({"&":{color:DL,backgroundColor:Cbe},".cm-content":{caretColor:UL},".cm-cursor, .cm-dropCursor":{borderLeftColor:UL},"&.cm-focused .cm-selectionBackground, .cm-selectionBackground, .cm-content ::selection":{backgroundColor:wbe},".cm-panels":{backgroundColor:BL,color:AL},".cm-panels.cm-panels-top":{borderBottom:`2px solid black`},".cm-panels.cm-panels-bottom":{borderTop:`2px solid black`},".cm-searchMatch":{backgroundColor:`#72a1ff59`,outline:`1px solid ${AL}`},".cm-searchMatch.cm-searchMatch-selected":{backgroundColor:jL},".cm-activeLine":{backgroundColor:VL},".cm-selectionMatch":{backgroundColor:jL},"&.cm-focused .cm-matchingBracket, &.cm-focused .cm-nonmatchingBracket":{outline:`1px solid ${AL}`},"&.cm-focused .cm-matchingBracket":{backgroundColor:ML},".cm-gutters":{backgroundColor:ML,color:DL,border:`none`},".cm-activeLineGutter":{backgroundColor:VL},".cm-foldPlaceholder":{backgroundColor:`transparent`,border:`none`,color:`#ddd`},".cm-tooltip":{border:`none`,backgroundColor:HL},".cm-tooltip .cm-tooltip-arrow:before":{borderTopColor:`transparent`,borderBottomColor:`transparent`},".cm-tooltip .cm-tooltip-arrow:after":{borderTopColor:HL,borderBottomColor:HL},".cm-tooltip-autocomplete":{"& > ul > li[aria-selected]":{backgroundColor:VL,color:AL}}},{dark:!1}),Ebe=se.define([{tag:P.keyword,color:FL},{tag:[P.name,P.deleted,P.character,P.propertyName,P.macroName],color:IL},{tag:[P.variableName],color:IL},{tag:[P.function(P.variableName)],color:FL},{tag:[P.labelName],color:bbe},{tag:[P.color,P.constant(P.name),P.standard(P.name)],color:FL},{tag:[P.definition(P.name),P.separator],color:RL},{tag:[P.brace],color:NL},{tag:[P.annotation],color:zL},{tag:[P.number,P.changed,P.annotation,P.modifier,P.self,P.namespace],color:PL},{tag:[P.typeName,P.className],color:LL},{tag:[P.operator,P.operatorKeyword],color:RL},{tag:[P.tagName],color:Sbe},{tag:[P.squareBracket],color:xbe},{tag:[P.angleBracket],color:IL},{tag:[P.attributeName],color:LL},{tag:[P.regexp],color:FL},{tag:[P.quote],color:OL},{tag:[P.string],color:IL},{tag:P.link,color:NL,textDecoration:`underline`,textUnderlinePosition:`under`},{tag:[P.url,P.escape,P.special(P.string)],color:IL},{tag:[P.meta],color:PL},{tag:[P.comment],color:kL,fontStyle:`italic`},{tag:P.strong,fontWeight:`bold`,color:FL},{tag:P.emphasis,fontStyle:`italic`,color:FL},{tag:P.strikethrough,textDecoration:`line-through`},{tag:P.heading,fontWeight:`bold`,color:FL},{tag:P.special(P.heading1),fontWeight:`bold`,color:FL},{tag:P.heading1,fontWeight:`bold`,color:FL},{tag:[P.heading2,P.heading3,P.heading4],fontWeight:`bold`,color:FL},{tag:[P.heading5,P.heading6],color:FL},{tag:[P.atom,P.bool,P.special(P.variableName)],color:IL},{tag:[P.processingInstruction,P.inserted],color:NL},{tag:[P.contentSeparator],color:LL},{tag:P.invalid,color:kL,borderBottom:`1px dotted ${zL}`}]),WL=[Tbe,j(Ebe)],GL=typeof String.prototype.normalize==`function`?e=>e.normalize(`NFKD`):e=>e,KL=class{constructor(e,t,n=0,r=e.length,i,a){this.test=a,this.value={from:0,to:0,precise:!1},this.done=!1,this.matches=[],this.buffer=``,this.bufferPos=0,this.iter=e.iterRange(n,r),this.bufferStart=n,this.normalize=i?e=>i(GL(e)):GL,this.query=this.normalize(t)}peek(){if(this.bufferPos==this.buffer.length){if(this.bufferStart+=this.buffer.length,this.iter.next(),this.iter.done)return-1;this.bufferPos=0,this.buffer=this.iter.value}return E(this.buffer,this.bufferPos)}next(){for(;this.matches.length;)this.matches.pop();return this.nextOverlapping()}nextOverlapping(){for(;;){let e=this.peek();if(e<0)return this.done=!0,this;let t=b(e),n=this.bufferStart+this.bufferPos;this.bufferPos+=F(e);let r=this.normalize(t);if(r.length)for(let e=0,i=n,a=!0;;e++){let n=r.charCodeAt(e),o=this.match(n,i,a,this.bufferPos+this.bufferStart,e==r.length-1);if(o)return this.value=o,this;if(e==r.length-1)break;a&&e<t.length&&t.charCodeAt(e)==n?i++:a=!1}}}match(e,t,n,r,i){let a=null;for(let t=0;t<this.matches.length;){let n=this.matches[t],o=!1;this.query.charCodeAt(n.index)==e&&(n.index==this.query.length-1?a={from:n.from,to:r,precise:i&&n.precise}:(n.index++,o=!0)),o?t++:this.matches.splice(t,1)}return this.query.charCodeAt(0)==e&&(this.query.length==1?a={from:t,to:r,precise:n&&i}:this.matches.push({from:t,index:1,precise:n})),a&&this.test&&!this.test(a.from,a.to,this.buffer,this.bufferStart)&&(a=null),a}};typeof Symbol<`u`&&(KL.prototype[Symbol.iterator]=function(){return this});var qL={from:-1,to:-1,match:/.*/.exec(``),precise:!0},JL=`gm`+(/x/.unicode==null?``:`u`),YL=class{constructor(e,t,n,r=0,i=e.length){if(this.text=e,this.to=i,this.curLine=``,this.done=!1,this.value=qL,/\\[sWDnr]|\n|\r|\[\^/.test(t))return new QL(e,t,n,r,i);this.re=new RegExp(t,JL+(n?.ignoreCase?`i`:``)),this.test=n?.test,this.iter=e.iter();let a=e.lineAt(r);this.curLineStart=a.from,this.matchPos=$L(e,r),this.getLine(this.curLineStart)}getLine(e){this.iter.next(e),this.iter.lineBreak?this.curLine=``:(this.curLine=this.iter.value,this.curLineStart+this.curLine.length>this.to&&(this.curLine=this.curLine.slice(0,this.to-this.curLineStart)),this.iter.next())}nextLine(){this.curLineStart=this.curLineStart+this.curLine.length+1,this.curLineStart>this.to?this.curLine=``:this.getLine(0)}next(){for(let e=this.matchPos-this.curLineStart;;){this.re.lastIndex=e;let t=this.matchPos<=this.to&&this.re.exec(this.curLine);if(t){let n=this.curLineStart+t.index,r=n+t[0].length;if(this.matchPos=$L(this.text,r+ +(n==r)),n==this.curLineStart+this.curLine.length&&this.nextLine(),(n<r||n>this.value.to)&&(!this.test||this.test(n,r,t)))return this.value={from:n,to:r,precise:!0,match:t},this;e=this.matchPos-this.curLineStart}else if(this.curLineStart+this.curLine.length<this.to)this.nextLine(),e=0;else return this.done=!0,this}}},XL=new WeakMap,ZL=class e{constructor(e,t){this.from=e,this.text=t}get to(){return this.from+this.text.length}static get(t,n,r){let i=XL.get(t);if(!i||i.from>=r||i.to<=n){let i=new e(n,t.sliceString(n,r));return XL.set(t,i),i}if(i.from==n&&i.to==r)return i;let{text:a,from:o}=i;return o>n&&(a=t.sliceString(n,o)+a,o=n),i.to<r&&(a+=t.sliceString(i.to,r)),XL.set(t,new e(o,a)),new e(n,a.slice(n-o,r-o))}},QL=class{constructor(e,t,n,r,i){this.text=e,this.to=i,this.done=!1,this.value=qL,this.matchPos=$L(e,r),this.re=new RegExp(t,JL+(n?.ignoreCase?`i`:``)),this.test=n?.test,this.flat=ZL.get(e,r,this.chunkEnd(r+5e3))}chunkEnd(e){return e>=this.to?this.to:this.text.lineAt(e).to}next(){for(;;){let e=this.re.lastIndex=this.matchPos-this.flat.from,t=this.re.exec(this.flat.text);if(t&&!t[0]&&t.index==e&&(this.re.lastIndex=e+1,t=this.re.exec(this.flat.text)),t){let e=this.flat.from+t.index,n=e+t[0].length;if((this.flat.to>=this.to||t.index+t[0].length<=this.flat.text.length-10)&&(!this.test||this.test(e,n,t)))return this.value={from:e,to:n,precise:!0,match:t},this.matchPos=$L(this.text,n+ +(e==n)),this}if(this.flat.to==this.to)return this.done=!0,this;this.flat=ZL.get(this.text,this.flat.from,this.chunkEnd(this.flat.from+this.flat.text.length*2))}}};typeof Symbol<`u`&&(YL.prototype[Symbol.iterator]=QL.prototype[Symbol.iterator]=function(){return this});function Dbe(e){try{return new RegExp(e,JL),!0}catch{return!1}}function $L(e,t){if(t>=e.length)return t;let n=e.lineAt(t),r;for(;t<n.to&&(r=n.text.charCodeAt(t-n.from))>=56320&&r<57344;)t++;return t}var Obe=e=>{let{state:t}=e,n=String(t.doc.lineAt(e.state.selection.main.head).number),{close:r,result:i}=be(e,{label:t.phrase(`Go to line`),input:{type:`text`,name:`line`,value:n},focus:!0,submitLabel:t.phrase(`go`)});return i.then(n=>{let i=n&&/^([+-])?(\d+)?(:\d+)?(%)?$/.exec(n.elements.line.value);if(!i){e.dispatch({effects:r});return}let a=t.doc.lineAt(t.selection.main.head),[,o,s,c,l]=i,u=c?+c.slice(1):0,d=s?+s:a.number;if(s&&l){let e=d/100;o&&(e=e*(o==`-`?-1:1)+a.number/t.doc.lines),d=Math.round(t.doc.lines*e)}else s&&o&&(d=d*(o==`-`?-1:1)+a.number);let f=t.doc.line(Math.max(1,Math.min(t.doc.lines,d))),p=z.cursor(f.from+Math.max(0,Math.min(u,f.length)));e.dispatch({effects:[r,B.scrollIntoView(p.from,{y:`center`})],selection:p})}),!0},kbe={highlightWordAroundCursor:!1,minSelectionLength:1,maxMatches:100,wholeWords:!1},eR=p.define({combine(e){return $e(e,kbe,{highlightWordAroundCursor:(e,t)=>e||t,minSelectionLength:Math.min,maxMatches:Math.min})}});function Abe(e){let t=[Fbe,Pbe];return e&&t.push(eR.of(e)),t}var jbe=Fe.mark({class:`cm-selectionMatch`}),Mbe=Fe.mark({class:`cm-selectionMatch cm-selectionMatch-main`});function tR(e,t,n,r){return(n==0||e(t.sliceDoc(n-1,n))!=d.Word)&&(r==t.doc.length||e(t.sliceDoc(r,r+1))!=d.Word)}function Nbe(e,t,n,r){return e(t.sliceDoc(n,n+1))==d.Word&&e(t.sliceDoc(r-1,r))==d.Word}var Pbe=ae.fromClass(class{constructor(e){this.decorations=this.getDeco(e)}update(e){(e.selectionSet||e.docChanged||e.viewportChanged)&&(this.decorations=this.getDeco(e.view))}getDeco(e){let t=e.state.facet(eR),{state:n}=e,r=n.selection;if(r.ranges.length>1)return Fe.none;let i=r.main,a,o=null;if(i.empty){if(!t.highlightWordAroundCursor)return Fe.none;let e=n.wordAt(i.head);if(!e)return Fe.none;o=n.charCategorizer(i.head),a=n.sliceDoc(e.from,e.to)}else{let e=i.to-i.from;if(e<t.minSelectionLength||e>200)return Fe.none;if(t.wholeWords){if(a=n.sliceDoc(i.from,i.to),o=n.charCategorizer(i.head),!(tR(o,n,i.from,i.to)&&Nbe(o,n,i.from,i.to)))return Fe.none}else if(a=n.sliceDoc(i.from,i.to),!a)return Fe.none}let s=[];for(let r of e.visibleRanges){let e=new KL(n.doc,a,r.from,r.to);for(;!e.next().done;){let{from:r,to:a}=e.value;if((!o||tR(o,n,r,a))&&(i.empty&&r<=i.from&&a>=i.to?s.push(Mbe.range(r,a)):(r>=i.to||a<=i.from)&&s.push(jbe.range(r,a)),s.length>t.maxMatches))return Fe.none}}return Fe.set(s)}},{decorations:e=>e.decorations}),Fbe=B.baseTheme({".cm-selectionMatch":{backgroundColor:`#99ff7780`},".cm-searchMatch .cm-selectionMatch":{backgroundColor:`transparent`}}),Ibe=({state:e,dispatch:t})=>{let{selection:n}=e,r=z.create(n.ranges.map(t=>e.wordAt(t.head)||z.cursor(t.head)),n.mainIndex);return!r.eq(n)&&(t(e.update({selection:r})),!0)};function Lbe(e,t){let{main:n,ranges:r}=e.selection,i=e.wordAt(n.head),a=i&&i.from==n.from&&i.to==n.to;for(let n=!1,i=new KL(e.doc,t,r[r.length-1].to);;)if(i.next(),i.done){if(n)return null;i=new KL(e.doc,t,0,Math.max(0,r[r.length-1].from-1)),n=!0}else{if(n&&r.some(e=>e.from==i.value.from))continue;if(a){let t=e.wordAt(i.value.from);if(!t||t.from!=i.value.from||t.to!=i.value.to)continue}return i.value}}var Rbe=({state:e,dispatch:t})=>{let{ranges:n}=e.selection;if(n.some(e=>e.from===e.to))return Ibe({state:e,dispatch:t});let r=e.sliceDoc(n[0].from,n[0].to);if(e.selection.ranges.some(t=>e.sliceDoc(t.from,t.to)!=r))return!1;let i=Lbe(e,r);return i?(t(e.update({selection:e.selection.addRange(z.range(i.from,i.to),!1),effects:B.scrollIntoView(i.to)})),!0):!1},nR=p.define({combine(e){return $e(e,{top:!1,caseSensitive:!1,literal:!1,regexp:!1,wholeWord:!1,createPanel:e=>new Qbe(e),scrollToMatch:e=>B.scrollIntoView(e)})}}),rR=class{constructor(e){this.search=e.search,this.caseSensitive=!!e.caseSensitive,this.literal=!!e.literal,this.regexp=!!e.regexp,this.replace=e.replace||``,this.valid=!!this.search&&(!this.regexp||Dbe(this.search)),this.unquoted=this.unquote(this.search),this.wholeWord=!!e.wholeWord,this.test=e.test}unquote(e){return this.literal?e:e.replace(/\\([nrt\\])/g,(e,t)=>t==`n`?`
176
176
  `:t==`r`?`\r`:t==`t`?` `:`\\`)}eq(e){return this.search==e.search&&this.replace==e.replace&&this.caseSensitive==e.caseSensitive&&this.regexp==e.regexp&&this.wholeWord==e.wholeWord&&this.test==e.test}create(){return this.regexp?new Wbe(this):new Vbe(this)}getCursor(e,t=0,n){let r=e.doc?e:h.create({doc:e});return n??=r.doc.length,this.regexp?oR(this,r,t,n):aR(this,r,t,n)}},iR=class{constructor(e){this.spec=e}};function zbe(e,t,n){return(r,i,a,o)=>n&&!n(r,i,a,o)?!1:e(r>=o&&i<=o+a.length?a.slice(r-o,i-o):t.doc.sliceString(r,i),t,r,i)}function aR(e,t,n,r){let i;return e.wholeWord&&(i=Bbe(t.doc,t.charCategorizer(t.selection.main.head))),e.test&&(i=zbe(e.test,t,i)),new KL(t.doc,e.unquoted,n,r,e.caseSensitive?void 0:e=>e.toLowerCase(),i)}function Bbe(e,t){return(n,r,i,a)=>((a>n||a+i.length<r)&&(a=Math.max(0,n-2),i=e.sliceString(a,Math.min(e.length,r+2))),(t(sR(i,n-a))!=d.Word||t(cR(i,n-a))!=d.Word)&&(t(cR(i,r-a))!=d.Word||t(sR(i,r-a))!=d.Word))}var Vbe=class extends iR{constructor(e){super(e)}nextMatch(e,t,n){let r=aR(this.spec,e,n,e.doc.length).nextOverlapping();if(r.done){let n=Math.min(e.doc.length,t+this.spec.unquoted.length);r=aR(this.spec,e,0,n).nextOverlapping()}return r.done||r.value.from==t&&r.value.to==n?null:r.value}prevMatchInRange(e,t,n){for(let r=n;;){let n=Math.max(t,r-1e4-this.spec.unquoted.length),i=aR(this.spec,e,n,r),a=null;for(;!i.nextOverlapping().done;)a=i.value;if(a)return a;if(n==t)return null;r-=1e4}}prevMatch(e,t,n){let r=this.prevMatchInRange(e,0,t);return r||=this.prevMatchInRange(e,Math.max(0,n-this.spec.unquoted.length),e.doc.length),r&&(r.from!=t||r.to!=n)?r:null}getReplacement(e){return this.spec.unquote(this.spec.replace)}matchAll(e,t){let n=aR(this.spec,e,0,e.doc.length),r=[];for(;!n.next().done;){if(r.length>=t)return null;r.push(n.value)}return r}highlight(e,t,n,r){let i=aR(this.spec,e,Math.max(0,t-this.spec.unquoted.length),Math.min(n+this.spec.unquoted.length,e.doc.length));for(;!i.next().done;)r(i.value.from,i.value.to)}};function Hbe(e,t,n){return(r,i,a)=>(!n||n(r,i,a))&&e(a[0],t,r,i)}function oR(e,t,n,r){let i;return e.wholeWord&&(i=Ube(t.charCategorizer(t.selection.main.head))),e.test&&(i=Hbe(e.test,t,i)),new YL(t.doc,e.search,{ignoreCase:!e.caseSensitive,test:i},n,r)}function sR(e,t){return e.slice(ne(e,t,!1),t)}function cR(e,t){return e.slice(t,ne(e,t))}function Ube(e){return(t,n,r)=>!r[0].length||(e(sR(r.input,r.index))!=d.Word||e(cR(r.input,r.index))!=d.Word)&&(e(cR(r.input,r.index+r[0].length))!=d.Word||e(sR(r.input,r.index+r[0].length))!=d.Word)}var Wbe=class extends iR{nextMatch(e,t,n){let r=oR(this.spec,e,n,e.doc.length).next();return r.done&&(r=oR(this.spec,e,0,t).next()),r.done?null:r.value}prevMatchInRange(e,t,n){for(let r=1;;r++){let i=Math.max(t,n-r*1e4),a=oR(this.spec,e,i,n),o=null;for(;!a.next().done;)o=a.value;if(o&&(i==t||o.from>i+10))return o;if(i==t)return null}}prevMatch(e,t,n){return this.prevMatchInRange(e,0,t)||this.prevMatchInRange(e,n,e.doc.length)}getReplacement(e){return this.spec.unquote(this.spec.replace).replace(/\$([$&]|\d+)/g,(t,n)=>{if(n==`&`)return e.match[0];if(n==`$`)return`$`;for(let t=n.length;t>0;t--){let r=+n.slice(0,t);if(r>0&&r<e.match.length)return e.match[r]+n.slice(t)}return t})}matchAll(e,t){let n=oR(this.spec,e,0,e.doc.length),r=[];for(;!n.next().done;){if(r.length>=t)return null;r.push(n.value)}return r}highlight(e,t,n,r){let i=oR(this.spec,e,Math.max(0,t-250),Math.min(n+250,e.doc.length));for(;!i.next().done;)r(i.value.from,i.value.to)}},lR=k.define(),uR=k.define(),dR=M.define({create(e){return new fR(vR(e).create(),null)},update(e,t){for(let n of t.effects)n.is(lR)?e=new fR(n.value.create(),e.panel):n.is(uR)&&(e=new fR(e.query,n.value?_R:null));return e},provide:e=>ve.from(e,e=>e.panel)}),fR=class{constructor(e,t){this.query=e,this.panel=t}},Gbe=Fe.mark({class:`cm-searchMatch`}),Kbe=Fe.mark({class:`cm-searchMatch cm-searchMatch-selected`}),qbe=ae.fromClass(class{constructor(e){this.view=e,this.decorations=this.highlight(e.state.field(dR))}update(e){let t=e.state.field(dR);(t!=e.startState.field(dR)||e.docChanged||e.selectionSet||e.viewportChanged)&&(this.decorations=this.highlight(t))}highlight({query:e,panel:t}){if(!t||!e.spec.valid)return Fe.none;let{view:n}=this,r=new Ce;for(let t=0,i=n.visibleRanges,a=i.length;t<a;t++){let{from:o,to:s}=i[t];for(;t<a-1&&s>i[t+1].from-500;)s=i[++t].to;e.highlight(n.state,o,s,(e,t)=>{let i=n.state.selection.ranges.some(n=>n.from==e&&n.to==t);r.add(e,t,i?Kbe:Gbe)})}return r.finish()}},{decorations:e=>e.decorations});function pR(e){return t=>{let n=t.state.field(dR,!1);return n&&n.query.spec.valid?e(t,n):xR(t)}}var mR=pR((e,{query:t})=>{let{to:n}=e.state.selection.main,r=t.nextMatch(e.state,n,n);if(!r)return!1;let i=z.single(r.from,r.to),a=e.state.facet(nR);return e.dispatch({selection:i,effects:[ER(e,r),a.scrollToMatch(i.main,e)],userEvent:`select.search`}),bR(e),!0}),hR=pR((e,{query:t})=>{let{state:n}=e,{from:r}=n.selection.main,i=t.prevMatch(n,r,r);if(!i)return!1;let a=z.single(i.from,i.to),o=e.state.facet(nR);return e.dispatch({selection:a,effects:[ER(e,i),o.scrollToMatch(a.main,e)],userEvent:`select.search`}),bR(e),!0}),Jbe=pR((e,{query:t})=>{let n=t.matchAll(e.state,1e3);return!n||!n.length?!1:(e.dispatch({selection:z.create(n.map(e=>z.range(e.from,e.to))),userEvent:`select.search.matches`}),!0)}),Ybe=({state:e,dispatch:t})=>{let n=e.selection;if(n.ranges.length>1||n.main.empty)return!1;let{from:r,to:i}=n.main,a=[],o=0;for(let t=new KL(e.doc,e.sliceDoc(r,i));!t.next().done;){if(a.length>1e3)return!1;t.value.from==r&&(o=a.length),a.push(z.range(t.value.from,t.value.to))}return t(e.update({selection:z.create(a,o),userEvent:`select.search.matches`})),!0},gR=pR((e,{query:t})=>{let{state:n}=e,{from:r,to:i}=n.selection.main;if(n.readOnly)return!1;let a=t.nextMatch(n,r,r);if(!a)return!1;let o=a,s=[],c,l,u=[];o.precise?o.from==r&&o.to==i&&(l=n.toText(t.getReplacement(o)),s.push({from:o.from,to:o.to,insert:l}),o=t.nextMatch(n,o.from,o.to),u.push(B.announce.of(n.phrase(`replaced match on line $`,n.doc.lineAt(r).number)+`.`))):o=t.nextMatch(n,o.from,o.to);let d=e.state.changes(s);return o&&(c=z.single(o.from,o.to).map(d),u.push(ER(e,o)),u.push(n.facet(nR).scrollToMatch(c.main,e))),e.dispatch({changes:d,selection:c,effects:u,userEvent:`input.replace`}),!0}),Xbe=pR((e,{query:t})=>{if(e.state.readOnly)return!1;let n=[];for(let r of t.matchAll(e.state,1e9)){let{from:e,to:i,precise:a}=r;a&&n.push({from:e,to:i,insert:t.getReplacement(r)})}if(!n.length)return!1;let r=e.state.phrase(`replaced $ matches`,n.length)+`.`;return e.dispatch({changes:n,effects:B.announce.of(r),userEvent:`input.replace.all`}),!0});function _R(e){return e.state.facet(nR).createPanel(e)}function vR(e,t){let n=e.selection.main,r=n.empty||n.to>n.from+100?``:e.sliceDoc(n.from,n.to);if(t&&!r)return t;let i=e.facet(nR);return new rR({search:t?.literal??i.literal?r:r.replace(/\n/g,`\\n`),caseSensitive:t?.caseSensitive??i.caseSensitive,literal:t?.literal??i.literal,regexp:t?.regexp??i.regexp,wholeWord:t?.wholeWord??i.wholeWord})}function yR(e){let t=Le(e,_R);return t&&t.dom.querySelector(`[main-field]`)}function bR(e){let t=yR(e);t&&t==e.root.activeElement&&t.select()}var xR=e=>{let t=e.state.field(dR,!1);if(t&&t.panel){let n=yR(e);if(n&&n!=e.root.activeElement){let r=vR(e.state,t.query.spec);r.valid&&e.dispatch({effects:lR.of(r)}),n.focus(),n.select()}}else e.dispatch({effects:[uR.of(!0),t?lR.of(vR(e.state,t.query.spec)):k.appendConfig.of(exe)]});return!0},SR=e=>{let t=e.state.field(dR,!1);if(!t||!t.panel)return!1;let n=Le(e,_R);return n&&n.dom.contains(e.root.activeElement)&&e.focus(),e.dispatch({effects:uR.of(!1)}),!0},Zbe=[{key:`Mod-f`,run:xR,scope:`editor search-panel`},{key:`F3`,run:mR,shift:hR,scope:`editor search-panel`,preventDefault:!0},{key:`Mod-g`,run:mR,shift:hR,scope:`editor search-panel`,preventDefault:!0},{key:`Escape`,run:SR,scope:`editor search-panel`},{key:`Mod-Shift-l`,run:Ybe},{key:`Mod-Alt-g`,run:Obe},{key:`Mod-d`,run:Rbe,preventDefault:!0}],Qbe=class{constructor(e){this.view=e;let t=this.query=e.state.field(dR).query.spec;this.commit=this.commit.bind(this),this.searchField=Ge(`input`,{value:t.search,placeholder:CR(e,`Find`),"aria-label":CR(e,`Find`),class:`cm-textfield`,name:`search`,form:``,"main-field":`true`,onchange:this.commit,onkeyup:this.commit}),this.replaceField=Ge(`input`,{value:t.replace,placeholder:CR(e,`Replace`),"aria-label":CR(e,`Replace`),class:`cm-textfield`,name:`replace`,form:``,onchange:this.commit,onkeyup:this.commit}),this.caseField=Ge(`input`,{type:`checkbox`,name:`case`,form:``,checked:t.caseSensitive,onchange:this.commit}),this.reField=Ge(`input`,{type:`checkbox`,name:`re`,form:``,checked:t.regexp,onchange:this.commit}),this.wordField=Ge(`input`,{type:`checkbox`,name:`word`,form:``,checked:t.wholeWord,onchange:this.commit});function n(e,t,n){return Ge(`button`,{class:`cm-button`,name:e,onclick:t,type:`button`},n)}this.dom=Ge(`div`,{onkeydown:e=>this.keydown(e),class:`cm-search`},[this.searchField,n(`next`,()=>mR(e),[CR(e,`next`)]),n(`prev`,()=>hR(e),[CR(e,`previous`)]),n(`select`,()=>Jbe(e),[CR(e,`all`)]),Ge(`label`,null,[this.caseField,CR(e,`match case`)]),Ge(`label`,null,[this.reField,CR(e,`regexp`)]),Ge(`label`,null,[this.wordField,CR(e,`by word`)]),...e.state.readOnly?[]:[Ge(`br`),this.replaceField,n(`replace`,()=>gR(e),[CR(e,`replace`)]),n(`replaceAll`,()=>Xbe(e),[CR(e,`replace all`)])],Ge(`button`,{name:`close`,onclick:()=>SR(e),"aria-label":CR(e,`close`),type:`button`},[`×`])])}commit(){let e=new rR({search:this.searchField.value,caseSensitive:this.caseField.checked,regexp:this.reField.checked,wholeWord:this.wordField.checked,replace:this.replaceField.value});e.eq(this.query)||(this.query=e,this.view.dispatch({effects:lR.of(e)}))}keydown(e){Oe(this.view,e,`search-panel`)?e.preventDefault():e.keyCode==13&&e.target==this.searchField?(e.preventDefault(),(e.shiftKey?hR:mR)(this.view)):e.keyCode==13&&e.target==this.replaceField&&(e.preventDefault(),gR(this.view))}update(e){for(let t of e.transactions)for(let e of t.effects)e.is(lR)&&!e.value.eq(this.query)&&this.setQuery(e.value)}setQuery(e){this.query=e,this.searchField.value=e.search,this.replaceField.value=e.replace,this.caseField.checked=e.caseSensitive,this.reField.checked=e.regexp,this.wordField.checked=e.wholeWord}mount(){this.searchField.select()}get pos(){return 80}get top(){return this.view.state.facet(nR).top}};function CR(e,t){return e.state.phrase(t)}var wR=30,TR=/[\s\.,:;?!]/;function ER(e,{from:t,to:n}){let r=e.state.doc.lineAt(t),i=e.state.doc.lineAt(n).to,a=Math.max(r.from,t-wR),o=Math.min(i,n+wR),s=e.state.sliceDoc(a,o);if(a!=r.from){for(let e=0;e<wR;e++)if(!TR.test(s[e+1])&&TR.test(s[e])){s=s.slice(e);break}}if(o!=i){for(let e=s.length-1;e>s.length-wR;e--)if(!TR.test(s[e-1])&&TR.test(s[e])){s=s.slice(0,e);break}}return B.announce.of(`${e.state.phrase(`current match`)}. ${s} ${e.state.phrase(`on line`)} ${r.number}.`)}var $be=B.baseTheme({".cm-panel.cm-search":{padding:`2px 6px 4px`,position:`relative`,"& [name=close]":{position:`absolute`,top:`0`,right:`4px`,backgroundColor:`inherit`,border:`none`,font:`inherit`,padding:0,margin:0},"& input, & button, & label":{margin:`.2em .6em .2em 0`},"& input[type=checkbox]":{marginRight:`.2em`},"& label":{fontSize:`80%`,whiteSpace:`pre`}},"&light .cm-searchMatch":{backgroundColor:`#ffff0054`},"&dark .cm-searchMatch":{backgroundColor:`#00ffff8a`},"&light .cm-searchMatch-selected":{backgroundColor:`#ff6a0054`},"&dark .cm-searchMatch-selected":{backgroundColor:`#ff00ff8a`}}),exe=[dR,Te.low(qbe),$be],DR=class{constructor(e,t,n){this.from=e,this.to=t,this.diagnostic=n}},OR=class e{constructor(e,t,n){this.diagnostics=e,this.panel=t,this.selected=n}static init(t,n,r){let i=r.facet(FR).markerFilter;i&&(t=i(t,r));let a=t.slice().sort((e,t)=>e.from-t.from||e.to-t.to),o=new Ce,s=[],c=0,l=r.doc.iter(),u=0,d=r.doc.length;for(let e=0;;){let t=e==a.length?null:a[e];if(!t&&!s.length)break;let n,r;if(s.length)n=c,r=s.reduce((e,t)=>Math.min(e,t.to),t&&t.from>n?t.from:1e8);else{if(n=t.from,n>d)break;r=t.to,s.push(t),e++}for(;e<a.length;){let t=a[e];if(t.from==n&&(t.to>t.from||t.to==n))s.push(t),e++,r=Math.min(t.to,r);else{r=Math.min(t.from,r);break}}r=Math.min(r,d);let i=!1;if(s.some(e=>e.from==n&&(e.to==r||r==d))&&(i=n==r,!i&&r-n<10)){let e=n-(u+l.value.length);e>0&&(l.next(e),u=n);for(let e=n;;){if(e>=r){i=!0;break}if(!l.lineBreak&&u+l.value.length>e)break;e=u+l.value.length,u+=l.value.length,l.next()}}let f=pxe(s);if(i)o.add(n,n,Fe.widget({widget:new cxe(f),diagnostics:s.slice()}));else{let e=s.reduce((e,t)=>t.markClass?e+` `+t.markClass:e,``);o.add(n,r,Fe.mark({class:`cm-lintRange cm-lintRange-`+f+e,diagnostics:s.slice(),inclusiveEnd:s.some(e=>e.to>r)}))}if(c=r,c==d)break;for(let e=0;e<s.length;e++)s[e].to<=c&&s.splice(e--,1)}let f=o.finish();return new e(f,n,kR(f))}};function kR(e,t=null,n=0){let r=null;return e.between(n,1e9,(e,n,{spec:i})=>{if(!(t&&i.diagnostics.indexOf(t)<0)){if(!r)r=new DR(e,n,t||i.diagnostics[0]);else if(i.diagnostics.indexOf(r.diagnostic)<0)return!1;else r=new DR(r.from,n,r.diagnostic)}}),r}function txe(e,t){let n=t.pos,r=t.end||n,i=e.state.facet(FR).hideOn(e,n,r);if(i!=null)return i;let a=e.startState.doc.lineAt(t.pos);return!!(e.effects.some(e=>e.is(AR))||e.changes.touchesRange(a.from,Math.max(a.to,r)))}function nxe(e,t){return e.field(NR,!1)?t:t.concat(k.appendConfig.of(hxe))}var AR=k.define(),jR=k.define(),MR=k.define(),NR=M.define({create(){return new OR(Fe.none,null,null)},update(e,t){if(t.docChanged&&e.diagnostics.size){let n=e.diagnostics.map(t.changes),r=null,i=e.panel;if(e.selected){let i=t.changes.mapPos(e.selected.from,1);r=kR(n,e.selected.diagnostic,i)||kR(n,null,i)}!n.size&&i&&t.state.facet(FR).autoPanel&&(i=null),e=new OR(n,i,r)}for(let n of t.effects)if(n.is(AR)){let r=t.state.facet(FR).autoPanel?n.value.length?zR.open:null:e.panel;e=OR.init(n.value,r,t.state)}else n.is(jR)?e=new OR(e.diagnostics,n.value?zR.open:null,e.selected):n.is(MR)&&(e=new OR(e.diagnostics,e.panel,n.value));return e},provide:e=>[ve.from(e,e=>e.panel),B.decorations.from(e,e=>e.diagnostics)]}),rxe=Fe.mark({class:`cm-lintRange cm-lintRange-active`});function ixe(e,t,n){let{diagnostics:r}=e.state.field(NR),i,a=-1,o=-1;r.between(t-+(n<0),t+ +(n>0),(e,r,{spec:s})=>{if(t>=e&&t<=r&&(e==r||(t>e||n>0)&&(t<r||n<0)))return i=s.diagnostics,a=e,o=r,!1});let s=e.state.facet(FR).tooltipFilter;return i&&s&&(i=s(i,e.state)),i?{pos:a,end:o,above:!0,create(){return{dom:axe(e,i)}}}:null}function axe(e,t){return Ge(`ul`,{class:`cm-tooltip-lint`},t.map(t=>RR(e,t,!1)))}var oxe=e=>{let t=e.state.field(NR,!1);(!t||!t.panel)&&e.dispatch({effects:nxe(e.state,[jR.of(!0)])});let n=Le(e,zR.open);return n&&n.dom.querySelector(`.cm-panel-lint ul`).focus(),!0},PR=e=>{let t=e.state.field(NR,!1);return!t||!t.panel?!1:(e.dispatch({effects:jR.of(!1)}),!0)},sxe=[{key:`Mod-Shift-m`,run:oxe,preventDefault:!0},{key:`F8`,run:e=>{let t=e.state.field(NR,!1);if(!t)return!1;let n=e.state.selection.main,r=kR(t.diagnostics,null,n.to+1);return!r&&(r=kR(t.diagnostics,null,0),!r||r.from==n.from&&r.to==n.to)?!1:(e.dispatch({selection:{anchor:r.from,head:r.to},scrollIntoView:!0}),a(e,r.from,1,{tooltip:mxe,until:e=>e.docChanged||e.newSelection.main.head<r.from||e.newSelection.main.head>r.to}),!0)}}],FR=p.define({combine(e){return{sources:e.map(e=>e.source).filter(e=>e!=null),...$e(e.map(e=>e.config),{delay:750,markerFilter:null,tooltipFilter:null,needsRefresh:null,hideOn:()=>null},{delay:Math.max,markerFilter:IR,tooltipFilter:IR,needsRefresh:(e,t)=>e?t?n=>e(n)||t(n):e:t,hideOn:(e,t)=>e?t?(n,r,i)=>e(n,r,i)||t(n,r,i):e:t,autoPanel:(e,t)=>e||t})}}});function IR(e,t){return e?t?(n,r)=>t(e(n,r),r):e:t}function LR(e){let t=[];if(e)actions:for(let{name:n}of e){for(let e=0;e<n.length;e++){let r=n[e];if(/[a-zA-Z]/.test(r)&&!t.some(e=>e.toLowerCase()==r.toLowerCase())){t.push(r);continue actions}}t.push(``)}return t}function RR(e,t,n){let r=n?LR(t.actions):[];return Ge(`li`,{class:`cm-diagnostic cm-diagnostic-`+t.severity},Ge(`span`,{class:`cm-diagnosticText`},t.renderMessage?t.renderMessage(e):t.message),t.actions?.map((n,i)=>{let a=!1,o=r=>{if(r.preventDefault(),a)return;a=!0;let i=kR(e.state.field(NR).diagnostics,t);i&&n.apply(e,i.from,i.to)},{name:s}=n,c=r[i]?s.indexOf(r[i]):-1,l=c<0?s:[s.slice(0,c),Ge(`u`,s.slice(c,c+1)),s.slice(c+1)],u=n.markClass?` `+n.markClass:``;return Ge(`button`,{type:`button`,class:`cm-diagnosticAction`+u,onclick:o,onmousedown:o,"aria-label":` Action: ${s}${c<0?``:` (access key "${r[i]})"`}.`},l)}),t.source&&Ge(`div`,{class:`cm-diagnosticSource`},t.source))}var cxe=class extends N{constructor(e){super(),this.sev=e}eq(e){return e.sev==this.sev}toDOM(){return Ge(`span`,{class:`cm-lintPoint cm-lintPoint-`+this.sev})}},lxe=class{constructor(e,t){this.diagnostic=t,this.id=`item_`+Math.floor(Math.random()*4294967295).toString(16),this.dom=RR(e,t,!0),this.dom.id=this.id,this.dom.setAttribute(`role`,`option`)}},zR=class e{constructor(e){this.view=e,this.items=[];let t=t=>{if(!(t.ctrlKey||t.altKey||t.metaKey)){if(t.keyCode==27)PR(this.view),this.view.focus();else if(t.keyCode==38||t.keyCode==33)this.moveSelection((this.selectedIndex-1+this.items.length)%this.items.length);else if(t.keyCode==40||t.keyCode==34)this.moveSelection((this.selectedIndex+1)%this.items.length);else if(t.keyCode==36)this.moveSelection(0);else if(t.keyCode==35)this.moveSelection(this.items.length-1);else if(t.keyCode==13)this.view.focus();else if(t.keyCode>=65&&t.keyCode<=90&&this.selectedIndex>=0){let{diagnostic:n}=this.items[this.selectedIndex],r=LR(n.actions);for(let i=0;i<r.length;i++)if(r[i].toUpperCase().charCodeAt(0)==t.keyCode){let t=kR(this.view.state.field(NR).diagnostics,n);t&&n.actions[i].apply(e,t.from,t.to)}}else return;t.preventDefault()}},n=e=>{for(let t=0;t<this.items.length;t++)this.items[t].dom.contains(e.target)&&this.moveSelection(t)};this.list=Ge(`ul`,{tabIndex:0,role:`listbox`,"aria-label":this.view.state.phrase(`Diagnostics`),onkeydown:t,onclick:n}),this.dom=Ge(`div`,{class:`cm-panel-lint`},this.list,Ge(`button`,{type:`button`,name:`close`,"aria-label":this.view.state.phrase(`close`),onclick:()=>PR(this.view)},`×`)),this.update()}get selectedIndex(){let e=this.view.state.field(NR).selected;if(!e)return-1;for(let t=0;t<this.items.length;t++)if(this.items[t].diagnostic==e.diagnostic)return t;return-1}update(){let{diagnostics:e,selected:t}=this.view.state.field(NR),n=0,r=!1,i=null,a=new Set;for(e.between(0,this.view.state.doc.length,(e,o,{spec:s})=>{for(let e of s.diagnostics){if(a.has(e))continue;a.add(e);let o=-1,s;for(let t=n;t<this.items.length;t++)if(this.items[t].diagnostic==e){o=t;break}o<0?(s=new lxe(this.view,e),this.items.splice(n,0,s),r=!0):(s=this.items[o],o>n&&(this.items.splice(n,o-n),r=!0)),t&&s.diagnostic==t.diagnostic?s.dom.hasAttribute(`aria-selected`)||(s.dom.setAttribute(`aria-selected`,`true`),i=s):s.dom.hasAttribute(`aria-selected`)&&s.dom.removeAttribute(`aria-selected`),n++}});n<this.items.length&&!(this.items.length==1&&this.items[0].diagnostic.from<0);)r=!0,this.items.pop();this.items.length==0&&(this.items.push(new lxe(this.view,{from:-1,to:-1,severity:`info`,message:this.view.state.phrase(`No diagnostics`)})),r=!0),i?(this.list.setAttribute(`aria-activedescendant`,i.id),this.view.requestMeasure({key:this,read:()=>({sel:i.dom.getBoundingClientRect(),panel:this.list.getBoundingClientRect()}),write:({sel:e,panel:t})=>{let n=t.height/this.list.offsetHeight;e.top<t.top?this.list.scrollTop-=(t.top-e.top)/n:e.bottom>t.bottom&&(this.list.scrollTop+=(e.bottom-t.bottom)/n)}})):this.selectedIndex<0&&this.list.removeAttribute(`aria-activedescendant`),r&&this.sync()}sync(){let e=this.list.firstChild;function t(){let t=e;e=t.nextSibling,t.remove()}for(let n of this.items)if(n.dom.parentNode==this.list){for(;e!=n.dom;)t();e=n.dom.nextSibling}else this.list.insertBefore(n.dom,e);for(;e;)t()}moveSelection(e){if(this.selectedIndex<0)return;let t=kR(this.view.state.field(NR).diagnostics,this.items[e].diagnostic);t&&this.view.dispatch({selection:{anchor:t.from,head:t.to},scrollIntoView:!0,effects:MR.of(t)})}static open(t){return new e(t)}};function uxe(e,t=`viewBox="0 0 40 40"`){return`url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" ${t}>${encodeURIComponent(e)}</svg>')`}function BR(e){return uxe(`<path d="m0 2.5 l2 -1.5 l1 0 l2 1.5 l1 0" stroke="${e}" fill="none" stroke-width=".7"/>`,`width="6" height="3"`)}var dxe=B.baseTheme({".cm-diagnostic":{padding:`3px 6px 3px 8px`,marginLeft:`-1px`,display:`block`,whiteSpace:`pre-wrap`},".cm-diagnostic-error":{borderLeft:`5px solid #d11`},".cm-diagnostic-warning":{borderLeft:`5px solid orange`},".cm-diagnostic-info":{borderLeft:`5px solid #999`},".cm-diagnostic-hint":{borderLeft:`5px solid #66d`},".cm-diagnosticAction":{font:`inherit`,border:`none`,padding:`2px 4px`,backgroundColor:`#444`,color:`white`,borderRadius:`3px`,marginLeft:`8px`,cursor:`pointer`},".cm-diagnosticSource":{fontSize:`70%`,opacity:.7},".cm-lintRange":{backgroundPosition:`left bottom`,backgroundRepeat:`repeat-x`,paddingBottom:`0.7px`},".cm-lintRange-error":{backgroundImage:BR(`#f11`)},".cm-lintRange-warning":{backgroundImage:BR(`orange`)},".cm-lintRange-info":{backgroundImage:BR(`#999`)},".cm-lintRange-hint":{backgroundImage:BR(`#66d`)},".cm-lintRange-active":{backgroundColor:`#ffdd9980`},".cm-tooltip-lint":{padding:0,margin:0},".cm-lintPoint":{position:`relative`,"&:after":{content:`""`,position:`absolute`,bottom:0,left:`-2px`,borderLeft:`3px solid transparent`,borderRight:`3px solid transparent`,borderBottom:`4px solid #d11`}},".cm-lintPoint-warning":{"&:after":{borderBottomColor:`orange`}},".cm-lintPoint-info":{"&:after":{borderBottomColor:`#999`}},".cm-lintPoint-hint":{"&:after":{borderBottomColor:`#66d`}},".cm-panel.cm-panel-lint":{position:`relative`,"& ul":{maxHeight:`100px`,overflowY:`auto`,"& [aria-selected]":{backgroundColor:`#ddd`,"& u":{textDecoration:`underline`}},"&:focus [aria-selected]":{background_fallback:`#bdf`,backgroundColor:`Highlight`,color_fallback:`white`,color:`HighlightText`},"& u":{textDecoration:`none`},padding:0,margin:0},"& [name=close]":{position:`absolute`,top:`0`,right:`2px`,background:`inherit`,border:`none`,font:`inherit`,padding:0,margin:0}},"&dark .cm-lintRange-active":{backgroundColor:`#86714a80`},"&dark .cm-panel.cm-panel-lint ul":{"& [aria-selected]":{backgroundColor:`#2e343e`}}});function fxe(e){return e==`error`?4:e==`warning`?3:e==`info`?2:1}function pxe(e){let t=`hint`,n=1;for(let r of e){let e=fxe(r.severity);e>n&&(n=e,t=r.severity)}return t}var mxe=Ee(ixe,{hideOn:txe}),hxe=[NR,B.decorations.compute([NR],e=>{let{selected:t,panel:n}=e.field(NR);return!t||!n||t.from==t.to?Fe.none:Fe.set([rxe.range(t.from,t.to)])}),mxe,dxe],gxe=[me(),ze(),fe(),B_e(),le(),Ve(),Ae(),h.allowMultipleSelections.of(!0),A(),j(_e,{fallback:!0}),Ne(),at(),rt(),Pe(),he(),Me(),Abe(),Ue.of([...nt,...Hve,...Zbe,...Y_e,...I,...it,...sxe])],_xe=Object.defineProperty,vxe=(e,t)=>_xe(e,`name`,{value:t,configurable:!0});function VR(e,[t,n]){return Math.min(n,Math.max(t,e))}vxe(VR,`clamp`);var yxe=Object.defineProperty,bxe=(e,t)=>yxe(e,`name`,{value:t,configurable:!0});function xxe(e){let t=H.useRef({value:e,previous:e});return H.useMemo(()=>(t.current.value!==e&&(t.current.previous=t.current.value,t.current.value=e),t.current.previous),[e])}bxe(xxe,`usePrevious`);var Sxe=Object.defineProperty,Cxe=(e,t)=>Sxe(e,`name`,{value:t,configurable:!0}),wxe=Object.freeze({position:`absolute`,border:0,width:1,height:1,padding:0,margin:-1,overflow:`hidden`,clip:`rect(0, 0, 0, 0)`,whiteSpace:`nowrap`,wordWrap:`normal`}),Txe=H.forwardRef(Cxe(function(e,t){return(0,U.jsx)(FT.span,{...e,ref:t,style:{...wxe,...e.style}})},`VisuallyHidden`)),Exe=Object.defineProperty,HR=(e,t)=>Exe(e,`name`,{value:t,configurable:!0}),Dxe=[` `,`Enter`,`ArrowUp`,`ArrowDown`],Oxe=[` `,`Enter`],UR=`Select`,[WR,GR,kxe]=JD(UR),[KR,Axe]=CT(UR,[kxe,iD]),qR=iD(),[jxe,JR]=KR(UR),[Mxe,Nxe]=KR(UR);function Pxe(e){let{__scopeSelect:t,children:n,open:r,defaultOpen:i,onOpenChange:a,value:o,defaultValue:s,onValueChange:c,dir:l,name:u,autoComplete:d,disabled:f,required:p,form:m,internal_do_not_use_render:h}=e,g=qR(t),[_,v]=H.useState(null),[y,b]=H.useState(null),[x,S]=H.useState(!1),C=iO(l),[w,T]=hD({prop:r,defaultProp:i??!1,onChange:a,caller:UR}),[E,D]=hD({prop:o,defaultProp:s,onChange:c,caller:UR}),O=H.useRef(null),k=H.useRef(E);H.useEffect(()=>{let e=m?_?.ownerDocument.getElementById(m):_?.form;if(e instanceof HTMLFormElement){let t=HR(()=>D(k.current),`reset`);return e.addEventListener(`reset`,t),()=>e.removeEventListener(`reset`,t)}},[m,_,D]);let A=!_||!!m||!!_.closest(`form`),[j,M]=H.useState(new Set),N=gE(),P=Array.from(j).map(e=>e.props.value).join(`;`),F=H.useCallback(e=>{M(t=>new Set(t).add(e))},[]),I=H.useCallback(e=>{M(t=>{let n=new Set(t);return n.delete(e),n})},[]),L={required:p,trigger:_,onTriggerChange:v,valueNode:y,onValueNodeChange:b,valueNodeHasChildren:x,onValueNodeHasChildrenChange:S,contentId:N,value:E,onValueChange:D,open:w,onOpenChange:T,dir:C,triggerPointerDownPosRef:O,disabled:f,name:u,autoComplete:d,form:m,nativeOptions:j,nativeSelectKey:P,isFormControl:A};return(0,U.jsx)(oD,{...g,children:(0,U.jsx)(jxe,{scope:t,...L,children:(0,U.jsx)(WR.Provider,{scope:t,children:(0,U.jsx)(Mxe,{scope:t,onNativeOptionAdd:F,onNativeOptionRemove:I,children:uSe(h)?h(L):n})})})})}HR(Pxe,`SelectProvider`);var Fxe=HR(e=>{let{__scopeSelect:t,children:n,...r}=e;return(0,U.jsx)(Pxe,{__scopeSelect:t,...r,internal_do_not_use_render:({isFormControl:e})=>(0,U.jsxs)(U.Fragment,{children:[n,e?(0,U.jsx)(lSe,{__scopeSelect:t}):null]})})},`Select`),Ixe=`SelectTrigger`,Lxe=H.forwardRef(HR(function(e,t){let{__scopeSelect:n,disabled:r=!1,...i}=e,a=qR(n),o=JR(Ixe,n),s=o.disabled||r,c=xT(t,o.onTriggerChange),l=GR(n),u=H.useRef(`touch`),[d,f,p]=tz(e=>{let t=l().filter(e=>!e.disabled),n=nz(t,e,t.find(e=>e.value===o.value));n!==void 0&&o.onValueChange(n.value)}),m=HR(e=>{s||(o.onOpenChange(!0),p()),e&&(o.triggerPointerDownPosRef.current={x:Math.round(e.pageX),y:Math.round(e.pageY)})},`handleOpen`);return(0,U.jsx)(sD,{asChild:!0,...a,children:(0,U.jsx)(FT.button,{type:`button`,role:`combobox`,"aria-controls":o.open?o.contentId:void 0,"aria-expanded":o.open,"aria-required":o.required,"aria-autocomplete":`none`,dir:o.dir,"data-state":o.open?`open`:`closed`,disabled:s,"data-disabled":s?``:void 0,"data-placeholder":ez(o.value)?``:void 0,...i,ref:c,onClick:mT(i.onClick,e=>{e.currentTarget.focus(),u.current!==`mouse`&&m(e)}),onPointerDown:mT(i.onPointerDown,e=>{u.current=e.pointerType;let t=e.target;t.hasPointerCapture(e.pointerId)&&t.releasePointerCapture(e.pointerId),e.button===0&&e.ctrlKey===!1&&e.pointerType===`mouse`&&(m(e),e.preventDefault())}),onKeyDown:mT(i.onKeyDown,e=>{let t=d.current!==``;!(e.ctrlKey||e.altKey||e.metaKey)&&e.key.length===1&&f(e.key),!(t&&e.key===` `)&&Dxe.includes(e.key)&&(m(),e.preventDefault())})})})},`SelectTrigger`)),Rxe=`SelectValue`,zxe=H.forwardRef(HR(function(e,t){let{__scopeSelect:n,className:r,style:i,children:a,placeholder:o=``,...s}=e,c=JR(Rxe,n),{onValueNodeHasChildrenChange:l}=c,u=a!==void 0,d=xT(t,c.onValueNodeChange);hE(()=>{l(u)},[l,u]);let f=ez(c.value);return(0,U.jsx)(FT.span,{...s,asChild:!f&&s.asChild,ref:d,style:{pointerEvents:`none`},children:(0,U.jsx)(H.Fragment,{children:f?o:a},f?`placeholder`:`value`)})},`SelectValue`)),Bxe=H.forwardRef(HR(function(e,t){let{__scopeSelect:n,children:r,...i}=e;return(0,U.jsx)(FT.span,{"aria-hidden":!0,...i,ref:t,children:r||`▼`})},`SelectIcon`)),[Vxe,Hxe]=KR(`SelectPortal`,{forceMount:void 0}),Uxe=HR(e=>{let{__scopeSelect:t,forceMount:n,...r}=e;return(0,U.jsx)(Vxe,{scope:e.__scopeSelect,forceMount:n,children:(0,U.jsx)(lD,{asChild:!0,...r})})},`SelectPortal`),YR=`SelectContent`,Wxe=H.forwardRef(HR(function(e,t){let n=Hxe(YR,e.__scopeSelect),{forceMount:r=n.forceMount,...i}=e,a=JR(YR,e.__scopeSelect),[o,s]=H.useState();return hE(()=>{s(new DocumentFragment)},[]),(0,U.jsx)(dD,{present:r||a.open,children:({present:e})=>e?(0,U.jsx)(Jxe,{...i,ref:t}):(0,U.jsx)(Gxe,{...i,fragment:o})})},`SelectContent`)),Gxe=H.forwardRef(HR(function(e,t){let{__scopeSelect:n,children:r,fragment:i}=e;return i?Ml.createPortal((0,U.jsx)(Kxe,{scope:n,children:(0,U.jsx)(WR.Slot,{scope:n,children:(0,U.jsx)(`div`,{ref:t,children:r})})}),i):null},`SelectContentFragment`)),XR=10,[Kxe,ZR]=KR(YR),qxe=ET(`SelectContent.RemoveScroll`),Jxe=H.forwardRef(HR(function(e,t){let{__scopeSelect:n}=e,{position:r=`item-aligned`,onCloseAutoFocus:i,onEscapeKeyDown:a,onPointerDownOutside:o,side:s,sideOffset:c,align:l,alignOffset:u,arrowPadding:d,collisionBoundary:f,collisionPadding:p,sticky:m,hideWhenDetached:h,avoidCollisions:g,..._}=e,v=JR(YR,n),[y,b]=H.useState(null),[x,S]=H.useState(null),C=xT(t,b),[w,T]=H.useState(null),[E,D]=H.useState(null),O=GR(n),[k,A]=H.useState(!1),j=H.useRef(!1);H.useEffect(()=>{if(y)return bD(y)},[y]),ZT();let M=H.useCallback(e=>{let[t,...n]=O().map(e=>e.ref.current),[r]=n.slice(-1),i=document.activeElement;for(let n of e)if(n===i||(n?.scrollIntoView({block:`nearest`}),n===t&&x&&(x.scrollTop=0),n===r&&x&&(x.scrollTop=x.scrollHeight),n?.focus(),document.activeElement!==i))return},[O,x]),N=H.useCallback(()=>M([w,y]),[M,w,y]);H.useEffect(()=>{k&&N()},[k,N]);let{onOpenChange:P,triggerPointerDownPosRef:F}=v;H.useEffect(()=>{if(y){let e={x:0,y:0},t=HR(t=>{e={x:Math.abs(Math.round(t.pageX)-(F.current?.x??0)),y:Math.abs(Math.round(t.pageY)-(F.current?.y??0))}},`handlePointerMove`),n=HR(n=>{e.x<=10&&e.y<=10?n.preventDefault():n.composedPath().includes(y)||P(!1),document.removeEventListener(`pointermove`,t),F.current=null},`handlePointerUp`);return F.current!==null&&(document.addEventListener(`pointermove`,t),document.addEventListener(`pointerup`,n,{capture:!0,once:!0})),()=>{document.removeEventListener(`pointermove`,t),document.removeEventListener(`pointerup`,n,{capture:!0})}}},[y,P,F]),H.useEffect(()=>{let e=HR(()=>P(!1),`close`);return window.addEventListener(`blur`,e),window.addEventListener(`resize`,e),()=>{window.removeEventListener(`blur`,e),window.removeEventListener(`resize`,e)}},[P]);let[I,L]=tz(e=>{let t=O().filter(e=>!e.disabled),n=nz(t,e,t.find(e=>e.ref.current===document.activeElement));n&&setTimeout(()=>n.ref.current?.focus())}),R=H.useCallback((e,t,n)=>{let r=!j.current&&!n;(v.value!==void 0&&v.value===t||r)&&(T(e),r&&(j.current=!0))},[v.value]),z=H.useCallback(()=>y?.focus(),[y]),ee=H.useCallback((e,t,n)=>{let r=!j.current&&!n;(v.value!==void 0&&v.value===t||r)&&D(e)},[v.value]),te=r===`popper`?Xxe:Yxe,ne=te===Xxe?{side:s,sideOffset:c,align:l,alignOffset:u,arrowPadding:d,collisionBoundary:f,collisionPadding:p,sticky:m,hideWhenDetached:h,avoidCollisions:g}:{};return(0,U.jsx)(Kxe,{scope:n,content:y,viewport:x,onViewportChange:S,itemRefCallback:R,selectedItem:w,onItemLeave:z,itemTextRefCallback:ee,focusSelectedItem:N,selectedItemText:E,position:r,isPositioned:k,searchRef:I,children:(0,U.jsx)(PD,{as:qxe,allowPinchZoom:!0,children:(0,U.jsx)(rE,{asChild:!0,trapped:v.open,onMountAutoFocus:e=>{e.preventDefault()},onUnmountAutoFocus:mT(i,e=>{v.trigger?.focus({preventScroll:!0}),e.preventDefault()}),children:(0,U.jsx)(HT,{asChild:!0,disableOutsidePointerEvents:!0,onEscapeKeyDown:a,onPointerDownOutside:o,onFocusOutside:e=>e.preventDefault(),onDismiss:()=>v.onOpenChange(!1),children:(0,U.jsx)(te,{role:`listbox`,id:v.contentId,"data-state":v.open?`open`:`closed`,dir:v.dir,onContextMenu:e=>e.preventDefault(),..._,...ne,onPlaced:()=>A(!0),ref:C,style:{display:`flex`,flexDirection:`column`,outline:`none`,..._.style},onKeyDown:mT(_.onKeyDown,e=>{let t=e.ctrlKey||e.altKey||e.metaKey;if(e.key===`Tab`&&e.preventDefault(),!t&&e.key.length===1&&L(e.key),[`ArrowUp`,`ArrowDown`,`Home`,`End`].includes(e.key)){let t=O().filter(e=>!e.disabled).map(e=>e.ref.current);if([`ArrowUp`,`End`].includes(e.key)&&(t=t.slice().reverse()),[`ArrowUp`,`ArrowDown`].includes(e.key)){let n=e.target,r=t.indexOf(n);t=t.slice(r+1)}setTimeout(()=>M(t)),e.preventDefault()}})})})})})})},`SelectContentImpl`)),Yxe=H.forwardRef(HR(function(e,t){let{__scopeSelect:n,onPlaced:r,...i}=e,a=JR(YR,n),o=ZR(YR,n),[s,c]=H.useState(null),[l,u]=H.useState(null),d=xT(t,u),f=GR(n),p=H.useRef(!1),m=H.useRef(!0),{viewport:h,selectedItem:g,selectedItemText:_,focusSelectedItem:v}=o,y=H.useCallback(()=>{if(a.trigger&&a.valueNode&&s&&l&&h&&g&&_){let e=a.trigger.getBoundingClientRect(),t=l.getBoundingClientRect(),n=a.valueNode.getBoundingClientRect(),i=_.getBoundingClientRect();if(a.dir!==`rtl`){let r=i.left-t.left,a=n.left-r,o=e.left-a,c=e.width+o,l=Math.max(c,t.width),u=window.innerWidth-XR,d=VR(a,[XR,Math.max(XR,u-l)]);s.style.minWidth=c+`px`,s.style.left=d+`px`}else{let r=t.right-i.right,a=window.innerWidth-n.right-r,o=window.innerWidth-e.right-a,c=e.width+o,l=Math.max(c,t.width),u=window.innerWidth-XR,d=VR(a,[XR,Math.max(XR,u-l)]);s.style.minWidth=c+`px`,s.style.right=d+`px`}let o=f(),c=window.innerHeight-XR*2,u=h.scrollHeight,d=window.getComputedStyle(l),m=parseInt(d.borderTopWidth,10),v=parseInt(d.paddingTop,10),y=parseInt(d.borderBottomWidth,10),b=parseInt(d.paddingBottom,10),x=m+v+u+b+y,S=Math.min(g.offsetHeight*5,x),C=window.getComputedStyle(h),w=parseInt(C.paddingTop,10),T=parseInt(C.paddingBottom,10),E=e.top+e.height/2-XR,D=c-E,O=g.offsetHeight/2,k=g.offsetTop+O,A=m+v+k,j=x-A;if(A<=E){let e=o.length>0&&g===o[o.length-1].ref.current;s.style.bottom=`0px`;let t=l.clientHeight-h.offsetTop-h.offsetHeight,n=A+Math.max(D,O+(e?T:0)+t+y);s.style.height=n+`px`}else{let e=o.length>0&&g===o[0].ref.current;s.style.top=`0px`;let t=Math.max(E,m+h.offsetTop+(e?w:0)+O)+j;s.style.height=t+`px`,h.scrollTop=A-E+h.offsetTop}s.style.margin=`${XR}px 0`,s.style.minHeight=S+`px`,s.style.maxHeight=c+`px`,r?.(),requestAnimationFrame(()=>p.current=!0)}},[f,a.trigger,a.valueNode,s,l,h,g,_,a.dir,r]);hE(()=>y(),[y]);let[b,x]=H.useState();hE(()=>{l&&x(window.getComputedStyle(l).zIndex)},[l]);let S=H.useCallback(e=>{e&&m.current===!0&&(y(),v?.(),m.current=!1)},[y,v]);return(0,U.jsx)(Zxe,{scope:n,contentWrapper:s,shouldExpandOnScrollRef:p,onScrollButtonChange:S,children:(0,U.jsx)(`div`,{ref:c,style:{display:`flex`,flexDirection:`column`,position:`fixed`,zIndex:b},children:(0,U.jsx)(FT.div,{...i,ref:d,style:{boxSizing:`border-box`,maxHeight:`100%`,...i.style}})})})},`SelectItemAlignedPosition`)),Xxe=H.forwardRef(HR(function(e,t){let{__scopeSelect:n,align:r=`start`,collisionPadding:i=XR,...a}=e,o=qR(n);return(0,U.jsx)(cD,{...o,...a,ref:t,align:r,collisionPadding:i,style:{boxSizing:`border-box`,...a.style,"--radix-select-content-transform-origin":`var(--radix-popper-transform-origin)`,"--radix-select-content-available-width":`var(--radix-popper-available-width)`,"--radix-select-content-available-height":`var(--radix-popper-available-height)`,"--radix-select-trigger-width":`var(--radix-popper-anchor-width)`,"--radix-select-trigger-height":`var(--radix-popper-anchor-height)`}})},`SelectPopperPosition`)),[Zxe,Qxe]=KR(YR,{}),$xe=`SelectViewport`,eSe=H.forwardRef(HR(function(e,t){let{__scopeSelect:n,nonce:r,...i}=e,a=ZR($xe,n),o=Qxe($xe,n),s=xT(t,a.onViewportChange),c=H.useRef(0);return(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(`style`,{dangerouslySetInnerHTML:{__html:`[data-radix-select-viewport]{scrollbar-width:none;-ms-overflow-style:none;-webkit-overflow-scrolling:touch;}[data-radix-select-viewport]::-webkit-scrollbar{display:none}`},nonce:r}),(0,U.jsx)(WR.Slot,{scope:n,children:(0,U.jsx)(FT.div,{"data-radix-select-viewport":``,role:`presentation`,...i,ref:s,style:{position:`relative`,flex:1,overflow:`hidden auto`,...i.style},onScroll:mT(i.onScroll,e=>{let t=e.currentTarget,{contentWrapper:n,shouldExpandOnScrollRef:r}=o;if(r?.current&&n){let e=Math.abs(c.current-t.scrollTop);if(e>0){let r=window.innerHeight-XR*2,i=parseFloat(n.style.minHeight),a=parseFloat(n.style.height),o=Math.max(i,a);if(o<r){let i=o+e,a=Math.min(r,i),s=i-a;n.style.height=a+`px`,n.style.bottom===`0px`&&(t.scrollTop=s>0?s:0,n.style.justifyContent=`flex-end`)}}}c.current=t.scrollTop})})})]})},`SelectViewport`)),[tSe,nSe]=KR(`SelectGroup`),QR=`SelectItem`,[rSe,iSe]=KR(QR),aSe=H.forwardRef(HR(function(e,t){let{__scopeSelect:n,value:r,disabled:i=!1,textValue:a,...o}=e,s=JR(QR,n),c=ZR(QR,n),l=s.value===r,[u,d]=H.useState(a??``),[f,p]=H.useState(!1),m=xT(t,LT(e=>c.itemRefCallback?.(e,r,i))),h=gE(),g=H.useRef(`touch`),_=HR(()=>{i||(s.onValueChange(r),s.onOpenChange(!1))},`handleSelect`);return(0,U.jsx)(rSe,{scope:n,value:r,disabled:i,textId:h,isSelected:l,onItemTextChange:H.useCallback(e=>{d(t=>t||(e?.textContent??``).trim())},[]),children:(0,U.jsx)(WR.ItemSlot,{scope:n,value:r,disabled:i,textValue:u,children:(0,U.jsx)(FT.div,{role:`option`,"aria-labelledby":h,"data-highlighted":f?``:void 0,"aria-selected":l&&f,"data-state":l?`checked`:`unchecked`,"aria-disabled":i||void 0,"data-disabled":i?``:void 0,tabIndex:i?void 0:-1,...o,ref:m,onFocus:mT(o.onFocus,()=>p(!0)),onBlur:mT(o.onBlur,()=>p(!1)),onClick:mT(o.onClick,()=>{g.current!==`mouse`&&_()}),onPointerUp:mT(o.onPointerUp,()=>{g.current===`mouse`&&_()}),onPointerDown:mT(o.onPointerDown,e=>{g.current=e.pointerType}),onPointerMove:mT(o.onPointerMove,e=>{g.current=e.pointerType,i?c.onItemLeave?.():g.current===`mouse`&&e.currentTarget.focus({preventScroll:!0})}),onPointerLeave:mT(o.onPointerLeave,e=>{e.currentTarget===document.activeElement&&c.onItemLeave?.()}),onKeyDown:mT(o.onKeyDown,e=>{i||e.target!==e.currentTarget||(c.searchRef?.current===``||e.key!==` `)&&(Oxe.includes(e.key)&&_(),e.key===` `&&e.preventDefault())})})})})},`SelectItem`)),$R=`SelectItemText`,oSe=H.forwardRef(HR(function(e,t){let{__scopeSelect:n,className:r,style:i,...a}=e,o=JR($R,n),s=ZR($R,n),c=iSe($R,n),l=Nxe($R,n),[u,d]=H.useState(null),f=LT(e=>s.itemTextRefCallback?.(e,c.value,c.disabled)),p=xT(t,d,c.onItemTextChange,f),m=u?.textContent,h=H.useMemo(()=>(0,U.jsx)(`option`,{value:c.value,disabled:c.disabled,children:m},c.value),[c.disabled,c.value,m]),{onNativeOptionAdd:g,onNativeOptionRemove:_}=l;return hE(()=>(g(h),()=>_(h)),[g,_,h]),(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(FT.span,{id:c.textId,...a,ref:p}),c.isSelected&&o.valueNode&&!o.valueNodeHasChildren&&!ez(o.value)?Ml.createPortal(a.children,o.valueNode):null]})},`SelectItemText`)),sSe=H.forwardRef(HR(function(e,t){let{__scopeSelect:n,...r}=e;return(0,U.jsx)(FT.div,{"aria-hidden":!0,...r,ref:t})},`SelectSeparator`)),cSe=`SelectBubbleInput`,lSe=H.forwardRef(HR(function({__scopeSelect:e,...t},n){let r=JR(cSe,e),{value:i,onValueChange:a,required:o,disabled:s,name:c,autoComplete:l,form:u}=r,{nativeOptions:d,nativeSelectKey:f}=r,p=H.useRef(null),m=xT(n,p),h=i??``,g=xxe(h),_=Array.from(d).some(e=>(e.props.value??``)===``);return H.useEffect(()=>{let e=p.current;if(!e)return;let t=window.HTMLSelectElement.prototype,n=Object.getOwnPropertyDescriptor(t,`value`).set;if(g!==h&&n){let t=new Event(`change`,{bubbles:!0});n.call(e,h),e.dispatchEvent(t)}},[g,h]),(0,U.jsxs)(FT.select,{"aria-hidden":!0,required:o,tabIndex:-1,name:c,autoComplete:l,disabled:s,form:u,onChange:e=>a(e.target.value),...t,style:{...wxe,...t.style},ref:m,defaultValue:h,children:[ez(i)&&!_?(0,U.jsx)(`option`,{value:``}):null,Array.from(d)]},f)},`SelectBubbleInput`));function uSe(e){return typeof e==`function`}HR(uSe,`isFunction`);function ez(e){return e===``||e===void 0}HR(ez,`shouldShowPlaceholder`);function tz(e){let t=LT(e),n=H.useRef(``),r=H.useRef(0),i=H.useCallback(e=>{let i=n.current+e;t(i),HR((function e(t){n.current=t,window.clearTimeout(r.current),t!==``&&(r.current=window.setTimeout(()=>e(``),1e3))}),`updateSearch`)(i)},[t]),a=H.useCallback(()=>{n.current=``,window.clearTimeout(r.current)},[]);return H.useEffect(()=>()=>window.clearTimeout(r.current),[]),[n,i,a]}HR(tz,`useTypeaheadSearch`);function nz(e,t,n){let r=t.length>1&&Array.from(t).every(e=>e===t[0])?t[0]:t,i=n?e.indexOf(n):-1,a=dSe(e,Math.max(i,0));r.length===1&&(a=a.filter(e=>e!==n));let o=a.find(e=>e.textValue.toLowerCase().startsWith(r.toLowerCase()));return o===n?void 0:o}HR(nz,`findNextItem`);function dSe(e,t){return e.map((n,r)=>e[(t+r)%e.length])}HR(dSe,`wrapArray`);var fSe=Object.defineProperty,rz=(e,t)=>fSe(e,`name`,{value:t,configurable:!0}),[iz,pSe]=CT(`Tooltip`,[iD]),az=iD(),mSe=`TooltipProvider`,hSe=700,oz=`tooltip.open`,[gSe,sz]=iz(mSe),_Se=rz(e=>{let{__scopeTooltip:t,delayDuration:n=hSe,skipDelayDuration:r=300,disableHoverableContent:i=!1,children:a}=e,o=H.useRef(!0),s=H.useRef(!1),c=H.useRef(0);return H.useEffect(()=>{let e=c.current;return()=>window.clearTimeout(e)},[]),(0,U.jsx)(gSe,{scope:t,isOpenDelayedRef:o,delayDuration:n,onOpen:H.useCallback(()=>{r<=0||(window.clearTimeout(c.current),o.current=!1)},[r]),onClose:H.useCallback(()=>{r<=0||(window.clearTimeout(c.current),c.current=window.setTimeout(()=>o.current=!0,r))},[r]),isPointerInTransitRef:s,onPointerInTransitChange:H.useCallback(e=>{s.current=e},[]),disableHoverableContent:i,children:a})},`TooltipProvider`),cz=`Tooltip`,[vSe,lz]=iz(cz),ySe=rz(e=>{let{__scopeTooltip:t,children:n,open:r,defaultOpen:i,onOpenChange:a,disableHoverableContent:o,delayDuration:s}=e,c=sz(cz,e.__scopeTooltip),l=az(t),[u,d]=H.useState(null),[f,p]=H.useState(void 0),m=gE(),h=H.useRef(0),g=o??c.disableHoverableContent,_=s??c.delayDuration,v=H.useRef(!1),[y,b]=hD({prop:r,defaultProp:i??!1,onChange:rz(e=>{e?(c.onOpen(),document.dispatchEvent(new CustomEvent(oz))):c.onClose(),a?.(e)},`onChange`),caller:cz}),x=H.useMemo(()=>y?v.current?`delayed-open`:`instant-open`:`closed`,[y]),S=H.useCallback(()=>{window.clearTimeout(h.current),h.current=0,v.current=!1,b(!0)},[b]),C=H.useCallback(()=>{window.clearTimeout(h.current),h.current=0,b(!1)},[b]),w=H.useCallback(()=>{window.clearTimeout(h.current),h.current=window.setTimeout(()=>{v.current=!0,b(!0),h.current=0},_)},[_,b]);H.useEffect(()=>()=>{h.current&&=(window.clearTimeout(h.current),0)},[]);let T=f??m;return(0,U.jsx)(oD,{...l,children:(0,U.jsx)(vSe,{scope:t,contentId:T,setContentId:p,open:y,stateAttribute:x,trigger:u,onTriggerChange:d,onTriggerEnter:H.useCallback(()=>{c.isOpenDelayedRef.current?w():S()},[c.isOpenDelayedRef,w,S]),onTriggerLeave:H.useCallback(()=>{g?C():(window.clearTimeout(h.current),h.current=0)},[C,g]),onOpen:S,onClose:C,disableHoverableContent:g,children:n})})},`Tooltip`),bSe=`TooltipTrigger`,xSe=H.forwardRef(rz(function(e,t){let{__scopeTooltip:n,...r}=e,i=lz(bSe,n),a=sz(bSe,n),o=az(n),s=xT(t,H.useRef(null),i.onTriggerChange),c=H.useRef(!1),l=H.useRef(!1),u=H.useCallback(()=>c.current=!1,[]);return H.useEffect(()=>()=>document.removeEventListener(`pointerup`,u),[u]),(0,U.jsx)(sD,{asChild:!0,...o,children:(0,U.jsx)(FT.button,{"aria-describedby":i.open?i.contentId:void 0,"data-state":i.stateAttribute,...r,ref:s,onPointerMove:mT(e.onPointerMove,e=>{e.pointerType!==`touch`&&!l.current&&!a.isPointerInTransitRef.current&&(i.onTriggerEnter(),l.current=!0)}),onPointerLeave:mT(e.onPointerLeave,()=>{i.onTriggerLeave(),l.current=!1}),onPointerDown:mT(e.onPointerDown,()=>{i.open&&i.onClose(),c.current=!0,document.addEventListener(`pointerup`,u,{once:!0})}),onFocus:mT(e.onFocus,()=>{c.current||i.onOpen()}),onBlur:mT(e.onBlur,i.onClose),onClick:mT(e.onClick,i.onClose)})})},`TooltipTrigger`)),SSe=`TooltipPortal`,[CSe,wSe]=iz(SSe,{forceMount:void 0}),TSe=rz(e=>{let{__scopeTooltip:t,forceMount:n,children:r,container:i}=e,a=lz(SSe,t);return(0,U.jsx)(CSe,{scope:t,forceMount:n,children:(0,U.jsx)(dD,{present:n||a.open,children:(0,U.jsx)(lD,{asChild:!0,container:i,children:r})})})},`TooltipPortal`),uz=`TooltipContent`,ESe=H.forwardRef(rz(function(e,t){let n=wSe(uz,e.__scopeTooltip),{forceMount:r=n.forceMount,side:i=`top`,...a}=e,o=lz(uz,e.__scopeTooltip);return(0,U.jsx)(dD,{present:r||o.open,children:o.disableHoverableContent?(0,U.jsx)(kSe,{side:i,...a,ref:t}):(0,U.jsx)(DSe,{side:i,...a,ref:t})})},`TooltipContent`)),DSe=H.forwardRef(rz(function(e,t){let n=lz(uz,e.__scopeTooltip),r=sz(uz,e.__scopeTooltip),i=H.useRef(null),a=xT(t,i),[o,s]=H.useState(null),{trigger:c,onClose:l}=n,u=i.current,{onPointerInTransitChange:d}=r,f=H.useCallback(()=>{s(null),d(!1)},[d]),p=H.useCallback((e,t)=>{let n=e.currentTarget,r={x:e.clientX,y:e.clientY},i=MSe(r,jSe(r,n.getBoundingClientRect())),a=NSe(t.getBoundingClientRect()),o=FSe([...i,...a]);s(o),d(!0)},[d]);return H.useEffect(()=>()=>f(),[f]),H.useEffect(()=>{if(c&&u){let e=rz(e=>p(e,u),`handleTriggerLeave`),t=rz(e=>p(e,c),`handleContentLeave`);return c.addEventListener(`pointerleave`,e),u.addEventListener(`pointerleave`,t),()=>{c.removeEventListener(`pointerleave`,e),u.removeEventListener(`pointerleave`,t)}}},[c,u,p,f]),H.useEffect(()=>{if(o){let e=rz(e=>{let t=e.target,n={x:e.clientX,y:e.clientY},r=c?.contains(t)||u?.contains(t),i=!PSe(n,o);r?f():i&&(f(),l())},`handleTrackPointerGrace`);return document.addEventListener(`pointermove`,e),()=>document.removeEventListener(`pointermove`,e)}},[c,u,o,l,f]),(0,U.jsx)(kSe,{...e,ref:a})},`TooltipContentHoverable`)),OSe=OT(`TooltipContent`),kSe=H.forwardRef(rz(function(e,t){let{__scopeTooltip:n,children:r,"aria-label":i,id:a,onEscapeKeyDown:o,onPointerDownOutside:s,...c}=e,l=lz(uz,n),u=az(n),{onClose:d}=l;H.useEffect(()=>(document.addEventListener(oz,d),()=>document.removeEventListener(oz,d)),[d]),H.useEffect(()=>{if(l.trigger){let e=rz(e=>{e.target instanceof Node&&e.target.contains(l.trigger)&&d()},`handleScroll`);return window.addEventListener(`scroll`,e,{capture:!0}),()=>window.removeEventListener(`scroll`,e,{capture:!0})}},[l.trigger,d]);let{setContentId:f}=l;return hE(()=>(f(a),()=>{f(void 0)}),[a,f]),(0,U.jsx)(HT,{asChild:!0,disableOutsidePointerEvents:!1,onEscapeKeyDown:o,onPointerDownOutside:s,onFocusOutside:e=>e.preventDefault(),onDismiss:d,children:(0,U.jsxs)(cD,{"data-state":l.stateAttribute,role:i?void 0:`tooltip`,id:i?void 0:l.contentId,...u,...c,ref:t,style:{...c.style,"--radix-tooltip-content-transform-origin":`var(--radix-popper-transform-origin)`,"--radix-tooltip-content-available-width":`var(--radix-popper-available-width)`,"--radix-tooltip-content-available-height":`var(--radix-popper-available-height)`,"--radix-tooltip-trigger-width":`var(--radix-popper-anchor-width)`,"--radix-tooltip-trigger-height":`var(--radix-popper-anchor-height)`},children:[(0,U.jsx)(OSe,{children:r}),i?(0,U.jsx)(Txe,{id:l.contentId,role:`tooltip`,children:i}):null]})})},`TooltipContentImpl`)),ASe=H.forwardRef(rz(function(e,t){let{__scopeTooltip:n,...r}=e,i=az(n);return(0,U.jsx)(dde,{...i,...r,ref:t})},`TooltipArrow`));function jSe(e,t){let n=Math.abs(t.top-e.y),r=Math.abs(t.bottom-e.y),i=Math.abs(t.right-e.x),a=Math.abs(t.left-e.x);switch(Math.min(n,r,i,a)){case a:return`left`;case i:return`right`;case n:return`top`;case r:return`bottom`;default:throw Error(`unreachable`)}}rz(jSe,`getExitSideFromRect`);function MSe(e,t,n=5){let r=[];switch(t){case`top`:r.push({x:e.x-n,y:e.y+n},{x:e.x+n,y:e.y+n});break;case`bottom`:r.push({x:e.x-n,y:e.y-n},{x:e.x+n,y:e.y-n});break;case`left`:r.push({x:e.x+n,y:e.y-n},{x:e.x+n,y:e.y+n});break;case`right`:r.push({x:e.x-n,y:e.y-n},{x:e.x-n,y:e.y+n})}return r}rz(MSe,`getPaddedExitPoints`);function NSe(e){let{top:t,right:n,bottom:r,left:i}=e;return[{x:i,y:t},{x:n,y:t},{x:n,y:r},{x:i,y:r}]}rz(NSe,`getPointsFromRect`);function PSe(e,t){let{x:n,y:r}=e,i=!1;for(let e=0,a=t.length-1;e<t.length;a=e++){let o=t[e],s=t[a],c=o.x,l=o.y,u=s.x,d=s.y;l>r!=d>r&&n<(u-c)*(r-l)/(d-l)+c&&(i=!i)}return i}rz(PSe,`isPointInPolygon`);function FSe(e){let t=e.slice();return t.sort((e,t)=>e.x<t.x?-1:e.x>t.x?1:e.y<t.y?-1:+(e.y>t.y)),ISe(t)}rz(FSe,`getHull`);function ISe(e){if(e.length<=1)return e.slice();let t=[];for(let n=0;n<e.length;n++){let r=e[n];for(;t.length>=2;){let e=t[t.length-1],n=t[t.length-2];if((e.x-n.x)*(r.y-n.y)>=(e.y-n.y)*(r.x-n.x))t.pop();else break}t.push(r)}t.pop();let n=[];for(let t=e.length-1;t>=0;t--){let r=e[t];for(;n.length>=2;){let e=n[n.length-1],t=n[n.length-2];if((e.x-t.x)*(r.y-t.y)>=(e.y-t.y)*(r.x-t.x))n.pop();else break}n.push(r)}return n.pop(),t.length===1&&n.length===1&&t[0].x===n[0].x&&t[0].y===n[0].y?t:t.concat(n)}rz(ISe,`getHullPresorted`);var LSe=_Se,RSe=ySe,zSe=xSe,BSe=TSe,VSe=ESe,HSe=ASe,dz=H.forwardRef(({title:e,children:t},n)=>{let r=kd(qS);return H.createElement(LSe,{delayDuration:100},H.createElement(RSe,null,H.createElement(zSe,{ref:n,asChild:!0},H.createElement(`span`,{className:Y.tooltipTrigger},t)),H.createElement(BSe,{container:r?.current},H.createElement(VSe,{className:(0,Mw.default)(Y.tooltipContent),sideOffset:10},e))))}),USe=H.forwardRef(({children:e,className:t,...n},r)=>H.createElement(aSe,{...n,ref:r,className:(0,Mw.default)(t,Y.selectItem)},H.createElement(oSe,null,e))),WSe=({title:e,placeholder:t,className:n})=>{let[r,i]=Ad(SS,lC);return H.createElement(dz,{title:e},H.createElement(Lxe,{"aria-label":t,className:(0,Mw.default)(Y.selectTrigger,n),"data-toolbar-item":!0,disabled:r},H.createElement(zxe,{placeholder:t}),H.createElement(Bxe,{className:Y.selectDropdownArrow},i(`arrow_drop_down`))))},GSe=({children:e,className:t=Y.selectContainer})=>{let n=kd(qS);return H.createElement(Uxe,{container:n?.current},H.createElement(Wxe,{className:(0,Mw.default)(t,`mdxeditor-select-content`),onCloseAutoFocus:e=>{e.preventDefault()},position:`popper`},H.createElement(eSe,{"data-editor-dropdown":!0,style:{maxHeight:`var(--radix-select-content-available-height)`}},e)))},fz=e=>H.createElement(Fxe,{value:e.value||``,onValueChange:e.onChange,disabled:e.disabled},H.createElement(WSe,{title:e.triggerTitle,placeholder:e.placeholder}),H.createElement(GSe,null,e.items.map((e,t)=>e===`separator`?H.createElement(sSe,{key:t}):H.createElement(USe,{key:t,value:e.value},e.label)))),KSe=({language:e,nodeKey:t,code:n,focusEmitter:r})=>{let i=NC(),{parentEditor:a,lexicalNode:o}=BP(),[s,c,l,u,d]=Ad(SS,hz,gz,lC,mz),f=vbe(t,`codeblock`,e,r),{setCode:p}=BP(),m=H.useRef(null),g=H.useRef(null),{value:_,items:v}=H.useMemo(()=>JSe(d,e),[d,e]),y=H.useRef(p);return y.current=p,f.current={getCodemirror:()=>m.current},H.useEffect(()=>{let t=g.current;return(async()=>{let r=[...c,gxe,WL,me(),Ue.of([Uve]),B.lineWrapping,B.updateListener.of(({state:e})=>{y.current(e.doc.toString())}),B.domEventHandlers({focus:()=>{a.update(()=>{Zg(null)})}})];if(s&&r.push(h.readOnly.of(!0)),e!==``){let t=d.keyMap[e]??e,n=d.supportMap[t];if(n)r.push(n.extension);else if(l){let t=ybe.find(t=>t.name===e||t.alias.includes(e)||t.extensions.includes(e));if(t)try{let e=await t.load();r.push(e.extension)}catch{console.warn(`failed to load language support for`,e)}}}t.innerHTML=``,m.current=new B({parent:t,state:h.create({doc:n,extensions:r})}),t.addEventListener(`keydown`,qSe)})(),()=>{var e;(e=m.current)==null||e.destroy(),m.current=null,t.removeEventListener(`keydown`,qSe)}},[s,e,...c]),H.createElement(`div`,{className:Y.codeMirrorWrapper},H.createElement(`div`,{className:Y.codeMirrorToolbar},H.createElement(fz,{disabled:s,value:_,onChange:e=>{a.update(()=>{o.setLanguage(e===`__EMPTY_VALUE__`?``:e),setTimeout(()=>{a.update(()=>{o.getLatest().select()})})})},triggerTitle:i(`codeBlock.selectLanguage`,`Select code block language`),placeholder:i(`codeBlock.inlineLanguage`,`Language`),items:v}),H.createElement(`button`,{className:Y.iconButton,type:`button`,disabled:s,title:i(`codeblock.delete`,`Delete code block`),onClick:e=>{e.preventDefault(),a.update(()=>{o.remove()})}},u(`delete_small`))),H.createElement(`div`,{ref:g}))};function qSe(e){e.stopPropagation()}function pz(e){let t=[],n={},r={};if(Array.isArray(e))for(let i of e){let e=i.alias?.[0]??i.name.toLowerCase(),a=e||`__EMPTY_VALUE__`;if(t.push({value:a,label:i.name}),n[e]=a,i.alias)for(let e of i.alias)n[e]=a;if(i.extensions)for(let e of i.extensions)n[e]=a;n[i.name.toLowerCase()]=a,i.support&&(r[a]=i.support)}else{let r={};for(let[i,a]of Object.entries(e))a in r||(r[a]=i,t.push({value:i||`__EMPTY_VALUE__`,label:a})),n[i]=r[a]||`__EMPTY_VALUE__`}return{items:t,keyMap:n,supportMap:r}}function JSe(e,t){let n=e.keyMap[t]??t;return!n||e.items.some(e=>e.value===n)?{value:n,items:e.items}:{value:n,items:[...e.items,{value:n,label:t}]}}var mz=wd(pz({js:`JavaScript`,ts:`TypeScript`,tsx:`TypeScript (React)`,jsx:`JavaScript (React)`,css:`CSS`})),YSe=Td(e=>{e.link(e.pipe(YSe,Md(({language:e,code:t})=>({code:t,language:e,meta:``}))),WP)}),hz=wd([]),gz=wd(!0),XSe=zd({update(e,t){e.pubIn({[mz]:pz(t?.codeBlockLanguages??{}),[hz]:t?.codeMirrorExtensions??[],[gz]:t?.autoLoadLanguageSupport??!0})},init(e,t){let n=pz(t?.codeBlockLanguages??{});e.pubIn({[mz]:n,[hz]:t?.codeMirrorExtensions??[],[D_e]:ZSe(),[gz]:t?.autoLoadLanguageSupport??!0})}});function ZSe(e){return{match(e,t){return!t},priority:1,Editor:KSe}}function QSe({url:e,title:t,text:n,onSubmit:r,onCancel:i,linkAutocompleteSuggestions:a,showLinkTitleField:o,showAnchorTextField:s}){let{register:c,handleSubmit:l,control:u,setValue:d,reset:f}=WA({values:{url:e,title:t,text:n}}),p=NC();return H.createElement(`form`,{onSubmit:e=>{l(r)(e),e.stopPropagation(),e.preventDefault()},onReset:e=>{e.stopPropagation(),i()},onKeyDown:e=>{e.key===`Escape`&&(e.stopPropagation(),i())},className:(0,Mw.default)(Y.multiFieldForm,Y.linkDialogEditForm)},H.createElement(`div`,{className:Y.formField},H.createElement(`label`,{htmlFor:`link-url`},p(`createLink.url`,`URL`)),H.createElement(uge,{register:c,initialInputValue:e,inputName:`url`,suggestions:a,setValue:d,control:u,placeholder:p(`createLink.urlPlaceholder`,`Select or paste an URL`),autofocus:!0})),s?H.createElement(`div`,{className:Y.formField},H.createElement(`label`,{htmlFor:`link-text`,title:p(`createLink.textTooltip`,`The text to be displayed for the link`)},p(`createLink.text`,`Anchor text`)),H.createElement(`input`,{id:`link-text`,className:Y.textInput,size:40,...c(`text`)})):null,o?H.createElement(`div`,{className:Y.formField},H.createElement(`label`,{htmlFor:`link-title`,title:p(`createLink.titleTooltip`,`The link's title attribute, shown on hover`)},p(`createLink.title`,`Link title`)),H.createElement(`input`,{id:`link-title`,className:Y.textInput,size:40,...c(`title`)})):null,H.createElement(`div`,{style:{display:`flex`,justifyContent:`flex-end`,gap:`var(--spacing-2)`}},H.createElement(`button`,{type:`submit`,title:p(`createLink.saveTooltip`,`Set URL`),"aria-label":p(`createLink.saveTooltip`,`Set URL`),className:(0,Mw.default)(Y.primaryButton)},p(`dialogControls.save`,`Save`)),H.createElement(`button`,{type:`reset`,title:p(`createLink.cancelTooltip`,`Cancel change`),"aria-label":p(`createLink.cancelTooltip`,`Cancel change`),className:(0,Mw.default)(Y.secondaryButton)},p(`dialogControls.cancel`,`Cancel`))))}var $Se=()=>{let[e,t,n,r,i,a,o]=Ad(qS,yS,lC,yz,aCe,oCe,lCe),s=jd(eCe),c=jd(tCe),l=jd(nCe),u=jd(rCe),d=jd(iCe);H.useEffect(()=>{let e=()=>{t?.getEditorState().read(()=>{s(!0)})};return window.addEventListener(`resize`,e),window.addEventListener(`scroll`,e),()=>{window.removeEventListener(`resize`,e),window.removeEventListener(`scroll`,e)}},[t,s]);let[f,p]=H.useState(!1),m=NC();if(r.type===`inactive`)return null;let h=r.rectangle,g=r.type===`preview`&&r.url.startsWith(`http`);return H.createElement(WD,{open:!0},H.createElement(Ufe,{"data-visible":r.type===`edit`,className:Y.linkDialogAnchor,style:{top:`${h.top}px`,left:`${h.left}px`,width:`${h.width}px`,height:`${h.height}px`}}),H.createElement(GD,{container:e?.current},H.createElement(Wfe,{className:(0,Mw.default)(Y.linkDialogPopoverContent),sideOffset:5,onOpenAutoFocus:e=>{e.preventDefault()},key:r.linkNodeKey},r.type===`edit`&&H.createElement(QSe,{url:r.url,title:r.title,text:r.text,onSubmit:c,onCancel:l.bind(null),linkAutocompleteSuggestions:i,showLinkTitleField:o,showAnchorTextField:r.withAnchorText}),r.type===`preview`&&H.createElement(H.Fragment,null,H.createElement(`a`,{className:Y.linkDialogPreviewAnchor,href:r.url,...g?{target:`_blank`,rel:`noreferrer`}:{},onClick:e=>{a!==null&&(e.preventDefault(),a(r.url))},title:g?m(`linkPreview.open`,`Open {{url}} in new window`,{url:r.url}):r.url},H.createElement(`span`,null,r.url),g&&n(`open_in_new`)),H.createElement(_z,{onClick:()=>{u()},title:m(`linkPreview.edit`,`Edit link URL`),"aria-label":m(`linkPreview.edit`,`Edit link URL`)},n(`edit`)),H.createElement(LSe,null,H.createElement(RSe,{open:f},H.createElement(zSe,{asChild:!0},H.createElement(_z,{title:m(`linkPreview.copyToClipboard`,`Copy to clipboard`),"aria-label":m(`linkPreview.copyToClipboard`,`Copy to clipboard`),onClick:()=>{window.navigator.clipboard.writeText(r.url).then(()=>{p(!0),setTimeout(()=>{p(!1)},1e3)})}},n(f?`check`:`content_copy`))),H.createElement(BSe,{container:e?.current},H.createElement(VSe,{className:(0,Mw.default)(Y.tooltipContent),sideOffset:5},m(`linkPreview.copied`,`Copied!`),H.createElement(HSe,null))))),H.createElement(_z,{title:m(`linkPreview.remove`,`Remove link`),"aria-label":m(`linkPreview.remove`,`Remove link`),onClick:()=>{d()}},n(`link_off`))),H.createElement(KD,{className:Y.popoverArrow}))))},_z=H.forwardRef(({className:e,...t},n)=>H.createElement(`button`,{className:(0,Mw.default)(Y.actionButton,e),ref:n,...t}));function vz(e){if(!e)return null;let t=Kse(e);if(t===null)return null;let n=t.getParent();return KC(n)?n:KC(t)?t:null}var eCe=Td(),yz=wd({type:`inactive`},e=>{e.pub(pC,t=>t.registerCommand(rm,()=>e.getValue(yz).type===`preview`&&(e.pub(yz,{type:`inactive`}),!0),1)),e.sub(e.pipe(DC),t=>{t!==`rich-text`&&e.pub(yz,{type:`inactive`})}),e.pub(pC,t=>t.registerCommand(Yp,t=>t.key===`k`&&(Fw?t.metaKey:t.ctrlKey)&&!e.getValue(SS)&&q(Fh())?(e.pub(bz),t.stopPropagation(),t.preventDefault(),!0):!1,3)),e.sub(e.pipe(rCe,Nd(yz,yS)),([,t,n])=>{if(t.type===`preview`)setTimeout(()=>{n?.getEditorState().read(()=>{let n=qg(t.linkNodeKey),r=KC(n)?n.getTextContent().length>0&&n.getChildrenSize()<=1:!1,i=r&&n?n.getTextContent():``;e.pub(yz,{type:`edit`,initialUrl:t.url,url:t.url,title:t.title,text:i,withAnchorText:r,linkNodeKey:t.linkNodeKey,rectangle:t.rectangle})})});else throw Error(`Cannot switch to edit mode when not in preview mode`)}),e.sub(e.pipe(tCe,Nd(yS,yz,AS)),([t,n,r,i])=>{let a=t.text?.trim()??``,o=t.url?.trim()??``,s=t.title?.trim()??``;if(o!==``){if(i?.isCollapsed()){let e=a||s||o;n?.update(()=>{let t=vz(i);if(!t){let t=GC(o,{title:s});t.append(uh(e)),Hh([t]),t.select()}else if(YC(t)){let e=GC(o,{title:s});e.append(uh(a)),t.replace(e),e.select()}else t.setURL(o),t.setTitle(s),cCe(t.getFirstChild(),a)},{discrete:!0})}else n?.update(()=>{cCe(i?.anchor.getNode(),a)}),n?.dispatchCommand(XC,{url:o,title:s});e.pub(yz,{type:`preview`,linkNodeKey:r.linkNodeKey,rectangle:r.rectangle,title:s,url:o})}else r.type===`edit`&&r.initialUrl!==``&&n?.dispatchCommand(XC,null),e.pub(yz,{type:`inactive`})}),e.link(e.pipe(nCe,Nd(yz,yS),Md(([,e,t])=>{if(e.type===`edit`)return t?.focus(),e.initialUrl===``?{type:`inactive`}:{type:`preview`,url:e.initialUrl,linkNodeKey:e.linkNodeKey,rectangle:e.rectangle};throw Error(`Cannot cancel edit when not in edit mode`)})),yz),e.link(e.pipe(e.combine(AS,eCe),Nd(yS,yz,SS),Md(([[e],t,n,r])=>{if(q(e)&&t&&!r){let n=vz(e);if(!e.isCollapsed())return{type:`inactive`};if(n){let e=jw(t);return e?{type:`preview`,url:n.getURL(),linkNodeKey:n.getKey(),title:n.getTitle(),rectangle:e}:{type:`inactive`}}return{type:`inactive`}}return{type:`inactive`}})),yz)}),tCe=Td(),nCe=Ed();Ed();var rCe=Ed(),iCe=Ed(e=>{e.sub(e.pipe(iCe,Nd(yS)),([,e])=>{e?.dispatchCommand(XC,null)})}),bz=Ed(e=>{e.sub(e.pipe(bz,Nd(AS,yS),Fd(([,e])=>q(e))),([,t,n])=>{n?.focus(()=>{setTimeout(()=>{n.getEditorState().read(()=>{let r=vz(t),i=jw(n),a=r?.getURL()??``,o=r?.getURL()??``,s=r?.getTitle()??``,c=r?.getKey()??``,l=r?r.getTextContent().length>0&&r.getChildrenSize()<=1:!!t?.isCollapsed(),u=l&&r?r.getTextContent():``;e.pub(yz,{type:`edit`,initialUrl:a,url:o,title:s,text:u,withAnchorText:l,linkNodeKey:c,rectangle:i})})})})})}),aCe=wd([]),oCe=wd(null),sCe=wd(null,e=>{e.pub(pC,t=>{function n(n){let[r,i]=e.getValues([SS,sCe]);!r||i===null||t.update(()=>{let e=Yg(n.target);if(e!==null){let t=Bv(e,e=>e instanceof WC);t!==null&&i(n,t,t.getURL())}})}return t.registerRootListener((e,t)=>{e&&e.addEventListener(`click`,n),t&&t.removeEventListener(`click`,n)})})});function cCe(e,t){dh(e)&&t&&(e.setTextContent(t),e.selectStart())}var lCe=wd(!0),uCe=zd({init(e,t){e.pub(gC,t?.LinkDialog??$Se),e.pub(oCe,t?.onClickLinkCallback??null),e.pub(sCe,t?.onReadOnlyClickLinkCallback??null),e.pub(lCe,t?.showLinkTitleField??!0)},update(e,t={}){e.pub(aCe,t.linkAutocompleteSuggestions??[])}});function xz(e,t){return H.forwardRef((n,r)=>{let i=(0,Mw.default)(t.className,n.className);return H.createElement(e,{...t,...n,className:i,ref:r})})}function dCe(e){return({title:t,children:n,...r})=>H.createElement(e,{"aria-label":t,...r},H.createElement(dz,{title:t},n))}var fCe=({readOnly:e,children:t,className:n})=>H.createElement(FO,{className:(0,Mw.default)(`mdxeditor-toolbar`,Y.toolbarRoot,{[Y.readOnlyToolbarRoot]:e},n),...e?{tabIndex:-1}:{}},t),Sz=dCe(xz(IO,{className:Y.toolbarButton,"data-toolbar-item":!0})),pCe=xz(RO,{className:Y.toolbarToggleItem,"data-toolbar-item":!0});xz(LO,{type:`single`,className:Y.toolbarToggleSingleGroup});var mCe=H.forwardRef(({on:e,title:t,children:n,disabled:r,...i},a)=>H.createElement(LO,{type:`single`,className:Y.toolbarToggleSingleGroup,...i,value:e?`on`:`off`,ref:a},H.createElement(pCe,{"aria-label":t,value:`on`,disabled:r},H.createElement(dz,{title:t},n)))),hCe=({items:e})=>H.createElement(`div`,{className:Y.toolbarGroupOfGroups},e.map((e,t)=>H.createElement(mCe,{key:t,title:e.title,on:e.active,onValueChange:t=>{e.onChange(t===`on`)},disabled:e.disabled},e.contents))),gCe=({value:e,onChange:t,className:n,ggClassName:r,items:i,disabled:a})=>{let o=NC();return H.createElement(`div`,{className:(0,Mw.default)(Y.toolbarGroupOfGroups,r)},H.createElement(LO,{"aria-label":o(`toolbar.toggleGroup`,`toggle group`),type:`single`,className:(0,Mw.default)(Y.toolbarToggleSingleGroup,n),onValueChange:t,value:e||``,disabled:a,onFocus:e=>{e.preventDefault()}},i.map((e,t)=>H.createElement(pCe,{key:t,"aria-label":e.title,value:e.value},H.createElement(dz,{title:e.title},e.contents)))))};function _Ce(e){return Object.hasOwn(e,`when`)}var vCe=({options:e})=>{let t=kd(sC),n=H.useMemo(()=>{let n=e.find(e=>{if(_Ce(e)){if(e.when(t))return!0}else return!0});return n?_Ce(n)?n.contents():n.fallback():null},[e,t]);return H.createElement(`div`,{style:{display:`flex`}},n)},Cz=Vpe,wz=wd(()=>null),Tz=wd(``),yCe=()=>"This is an empty toolbar. Pass `{toolbarContents: () => { return <>toolbar components</> }}` to the toolbarPlugin to customize it.",bCe=zd({init(e,t){let n=t?.toolbarPosition===`bottom`?fse:dse;e.pubIn({[wz]:t?.toolbarContents??yCe,[Tz]:t?.toolbarClassName??``,[n]:()=>{let[e,t,n]=Ad(wz,SS,Tz);return H.createElement(fCe,{className:n,readOnly:t},e())}})},update(e,t){e.pub(wz,t?.toolbarContents??yCe),e.pub(Tz,t?.toolbarClassName??``)}}),Ez=class e{constructor(e,t,n,r){this.fromA=e,this.toA=t,this.fromB=n,this.toB=r}offset(t,n=t){return new e(this.fromA+t,this.toA+t,this.fromB+n,this.toB+n)}};function Dz(e,t,n,r,i,a){if(e==r)return[];let o=Nz(e,t,n,r,i,a),s=Pz(e,t+o,n,r,i+o,a);t+=o,n-=s,i+=o,a-=s;let c=n-t,l=a-i;if(!c||!l)return[new Ez(t,n,i,a)];if(c>l){let o=e.slice(t,n).indexOf(r.slice(i,a));if(o>-1)return[new Ez(t,t+o,i,i),new Ez(t+o+l,n,a,a)]}else if(l>c){let o=r.slice(i,a).indexOf(e.slice(t,n));if(o>-1)return[new Ez(t,t,i,i+o),new Ez(n,n,i+o+c,a)]}if(c==1||l==1)return[new Ez(t,n,i,a)];let u=TCe(e,t,n,r,i,a);if(u){let[o,s,c]=u;return Dz(e,t,o,r,i,s).concat(Dz(e,o+c,n,r,s+c,a))}return xCe(e,t,n,r,i,a)}var Oz=1e9,kz=0,Az=!1;function xCe(e,t,n,r,i,a){let o=n-t,s=a-i;if(Oz<1e9&&Math.min(o,s)>Oz*16||kz>0&&Date.now()>kz)return Math.min(o,s)>Oz*64?[new Ez(t,n,i,a)]:ECe(e,t,n,r,i,a);let c=Math.ceil((o+s)/2);jz.reset(c),Mz.reset(c);let l=(n,a)=>e.charCodeAt(t+n)==r.charCodeAt(i+a),u=(t,i)=>e.charCodeAt(n-t-1)==r.charCodeAt(a-i-1),d=(o-s)%2==0?null:Mz,f=d?null:jz;for(let p=0;p<c;p++){if(p>Oz||kz>0&&!(p&63)&&Date.now()>kz)return ECe(e,t,n,r,i,a);let m=jz.advance(p,o,s,c,d,!1,l)||Mz.advance(p,o,s,c,f,!0,u);if(m)return CCe(e,t,n,t+m[0],r,i,a,i+m[1])}return[new Ez(t,n,i,a)]}var SCe=class{constructor(){this.vec=[]}reset(e){this.len=e<<1;for(let e=0;e<this.len;e++)this.vec[e]=-1;this.vec[e+1]=0,this.start=this.end=0}advance(e,t,n,r,i,a,o){for(let s=-e+this.start;s<=e-this.end;s+=2){let c=r+s,l=s==-e||s!=e&&this.vec[c-1]<this.vec[c+1]?this.vec[c+1]:this.vec[c-1]+1,u=l-s;for(;l<t&&u<n&&o(l,u);)l++,u++;if(this.vec[c]=l,l>t)this.end+=2;else if(u>n)this.start+=2;else if(i){let e=r+(t-n)-s;if(e>=0&&e<this.len&&i.vec[e]!=-1){if(a){let n=i.vec[e];if(n>=t-l)return[n,r+n-e]}else{let n=t-i.vec[e];if(l>=n)return[l,u]}}}}return null}},jz=new SCe,Mz=new SCe;function CCe(e,t,n,r,i,a,o,s){let c=!1;return!Kz(e,r)&&++r==n&&(c=!0),!Kz(i,s)&&++s==o&&(c=!0),c?[new Ez(t,n,a,o)]:Dz(e,t,r,i,a,s).concat(Dz(e,r,n,i,s,o))}function wCe(e,t){let n=1,r=Math.min(e,t);for(;n<r;)n<<=1;return n}function Nz(e,t,n,r,i,a){if(t==n||t==a||e.charCodeAt(t)!=r.charCodeAt(i))return 0;let o=wCe(n-t,a-i);for(let s=t,c=i;;){let i=s+o,l=c+o;if(i>n||l>a||e.slice(s,i)!=r.slice(c,l)){if(o==1)return s-t-+!Kz(e,s);o>>=1}else if(i==n||l==a)return i-t;else s=i,c=l}}function Pz(e,t,n,r,i,a){if(t==n||i==a||e.charCodeAt(n-1)!=r.charCodeAt(a-1))return 0;let o=wCe(n-t,a-i);for(let s=n,c=a;;){let a=s-o,l=c-o;if(a<t||l<i||e.slice(a,s)!=r.slice(l,c)){if(o==1)return n-s-+!Kz(e,s);o>>=1}else if(a==t||l==i)return n-a;else s=a,c=l}}function Fz(e,t,n,r,i,a,o,s){let c=r.slice(i,a),l=null;for(;;){if(l||o<s)return l;for(let s=t+o;;){Kz(e,s)||s++;let u=s+o;if(Kz(e,u)||(u+=u==s+1?1:-1),u>=n)break;let d=e.slice(s,u),f=-1;for(;(f=c.indexOf(d,f+1))!=-1;){let o=Nz(e,u,n,r,i+f+d.length,a),c=Pz(e,t,s,r,i,i+f),p=d.length+o+c;(!l||l[2]<p)&&(l=[s-c,i+f-c,p])}s=u}if(s<0)return l;o>>=1}}function TCe(e,t,n,r,i,a){let o=n-t,s=a-i;if(o<s){let o=TCe(r,i,a,e,t,n);return o&&[o[1],o[0],o[2]]}return o<4||s*2<o?null:Fz(e,t,n,r,i,a,Math.floor(o/4),-1)}function ECe(e,t,n,r,i,a){Az=!0;let o=n-t,s=a-i,c;if(o<s){let s=Fz(r,i,a,e,t,n,Math.floor(o/6),50);c=s&&[s[1],s[0],s[2]]}else c=Fz(e,t,n,r,i,a,Math.floor(s/6),50);if(!c)return[new Ez(t,n,i,a)];let[l,u,d]=c;return Dz(e,t,l,r,i,u).concat(Dz(e,l+d,n,r,u+d,a))}function DCe(e,t){for(let n=1;n<e.length;n++){let r=e[n-1],i=e[n];r.toA>i.fromA-t&&r.toB>i.fromB-t&&(e[n-1]=new Ez(r.fromA,i.toA,r.fromB,i.toB),e.splice(n--,1))}}function OCe(e,t,n){for(;;){DCe(n,1);let r=!1;for(let i=0;i<n.length;i++){let a=n[i],o,s;(o=Nz(e,a.fromA,a.toA,t,a.fromB,a.toB))&&(a=n[i]=new Ez(a.fromA+o,a.toA,a.fromB+o,a.toB)),(s=Pz(e,a.fromA,a.toA,t,a.fromB,a.toB))&&(a=n[i]=new Ez(a.fromA,a.toA-s,a.fromB,a.toB-s));let c=a.toA-a.fromA,l=a.toB-a.fromB;if(c&&l)continue;let u=a.fromA-(i?n[i-1].toA:0),d=(i<n.length-1?n[i+1].fromA:e.length)-a.toA;if(!u||!d)continue;let f=c?e.slice(a.fromA,a.toA):t.slice(a.fromB,a.toB);u<=f.length&&e.slice(a.fromA-u,a.fromA)==f.slice(f.length-u)?(n[i]=new Ez(a.fromA-u,a.toA-u,a.fromB-u,a.toB-u),r=!0):d<=f.length&&e.slice(a.toA,a.toA+d)==f.slice(0,d)&&(n[i]=new Ez(a.fromA+d,a.toA+d,a.fromB+d,a.toB+d),r=!0)}if(!r)break}return n}function kCe(e,t,n){for(let r=0,i=0;i<e.length;i++){let a=e[i],o=a.toA-a.fromA,s=a.toB-a.fromB;if(o&&s||o>3||s>3){let c=i==e.length-1?t.length:e[i+1].fromA,l=a.fromA-r,u=c-a.toA,d=Vz(t,a.fromA,l),f=Bz(t,a.toA,u),p=a.fromA-d,m=f-a.toA;if((!o||!s)&&p&&m){let l=Math.max(o,s),[u,h,g]=o?[t,a.fromA,a.toA]:[n,a.fromB,a.toB];l>p&&t.slice(d,a.fromA)==u.slice(g-p,g)?(a=e[i]=new Ez(d,d+o,a.fromB-p,a.toB-p),d=a.fromA,f=Bz(t,a.toA,c-a.toA)):l>m&&t.slice(a.toA,f)==u.slice(h,h+m)&&(a=e[i]=new Ez(f-o,f,a.fromB+m,a.toB+m),f=a.toA,d=Vz(t,a.fromA,a.fromA-r)),p=a.fromA-d,m=f-a.toA}if(p||m)a=e[i]=new Ez(a.fromA-p,a.toA+m,a.fromB-p,a.toB+m);else if(!o){let t=Uz(n,a.fromB,a.toB),r,o=t<0?-1:Hz(n,a.toB,a.fromB);t>-1&&(r=t-a.fromB)<=u&&n.slice(a.fromB,t)==n.slice(a.toB,a.toB+r)?a=e[i]=a.offset(r):o>-1&&(r=a.toB-o)<=l&&n.slice(a.fromB-r,a.fromB)==n.slice(o,a.toB)&&(a=e[i]=a.offset(-r))}else if(!s){let n=Uz(t,a.fromA,a.toA),r,o=n<0?-1:Hz(t,a.toA,a.fromA);n>-1&&(r=n-a.fromA)<=u&&t.slice(a.fromA,n)==t.slice(a.toA,a.toA+r)?a=e[i]=a.offset(r):o>-1&&(r=a.toA-o)<=l&&t.slice(a.fromA-r,a.fromA)==t.slice(o,a.toA)&&(a=e[i]=a.offset(-r))}}r=a.toA}return DCe(e,3),e}var Iz;try{Iz=RegExp(`[\\p{Alphabetic}\\p{Number}]`,`u`)}catch{}function ACe(e){return e>48&&e<58||e>64&&e<91||e>96&&e<123}function Lz(e,t){if(t==e.length)return 0;let n=e.charCodeAt(t);return n<192?+!!ACe(n):Iz?!Wz(n)||t==e.length-1?+!!Iz.test(String.fromCharCode(n)):Iz.test(e.slice(t,t+2))?2:0:0}function Rz(e,t){if(!t)return 0;let n=e.charCodeAt(t-1);return n<192?+!!ACe(n):Iz?!Gz(n)||t==1?+!!Iz.test(String.fromCharCode(n)):Iz.test(e.slice(t-2,t))?2:0:0}var zz=8;function Bz(e,t,n){if(t==e.length||!Rz(e,t))return t;for(let r=t,i=t+n,a=0;a<zz;a++){let t=Lz(e,r);if(!t||r+t>i)return r;r+=t}return t}function Vz(e,t,n){if(!t||!Lz(e,t))return t;for(let r=t,i=t-n,a=0;a<zz;a++){let t=Rz(e,r);if(!t||r-t<i)return r;r-=t}return t}function Hz(e,t,n){for(;t!=n;t--)if(e.charCodeAt(t-1)==10)return t;return-1}function Uz(e,t,n){for(;t!=n;t++)if(e.charCodeAt(t)==10)return t;return-1}var Wz=e=>e>=55296&&e<=56319,Gz=e=>e>=56320&&e<=57343;function Kz(e,t){return!t||t==e.length||!Wz(e.charCodeAt(t-1))||!Gz(e.charCodeAt(t))}function jCe(e,t,n){let r=n?.override;return r?r(e,t):(Oz=(n?.scanLimit??1e9)>>1,kz=n?.timeout?Date.now()+n.timeout:0,Az=!1,OCe(e,t,Dz(e,0,e.length,t,0,t.length)))}function qz(){return!Az}function Jz(e,t,n){return kCe(jCe(e,t,n),e,t)}var Yz=p.define({combine:e=>e[0]}),Xz=k.define(),MCe=p.define(),Zz=M.define({create(e){return null},update(e,t){for(let n of t.effects)n.is(Xz)&&(e=n.value);for(let n of t.state.facet(MCe))e=n(e,t);return e}}),Qz=class e{constructor(e,t,n,r,i,a=!0){this.changes=e,this.fromA=t,this.toA=n,this.fromB=r,this.toB=i,this.precise=a}offset(t,n){return t||n?new e(this.changes,this.fromA+t,this.toA+t,this.fromB+n,this.toB+n,this.precise):this}get endA(){return Math.max(this.fromA,this.toA-1)}get endB(){return Math.max(this.fromB,this.toB-1)}static build(e,t,n){return tB(Jz(e.toString(),t.toString(),n),e,t,0,0,qz())}static updateA(e,t,n,r,i){return aB(iB(e,r,!0,n.length),e,t,n,i)}static updateB(e,t,n,r,i){return aB(iB(e,r,!1,t.length),e,t,n,i)}};function $z(e,t,n,r){let i=n.lineAt(e),a=r.lineAt(t);return i.to==e&&a.to==t&&e<n.length&&t<r.length?[e+1,t+1]:[i.from,a.from]}function eB(e,t,n,r){let i=n.lineAt(e),a=r.lineAt(t);return i.from==e&&a.from==t?[e,t]:[i.to+1,a.to+1]}function tB(e,t,n,r,i,a){let o=[];for(let s=0;s<e.length;s++){let c=e[s],[l,u]=$z(c.fromA+r,c.fromB+i,t,n),[d,f]=eB(c.toA+r,c.toB+i,t,n),p=[c.offset(-l+r,-u+i)];for(;s<e.length-1;){let a=e[s+1],[o,c]=$z(a.fromA+r,a.fromB+i,t,n);if(o>d+1&&c>f+1)break;p.push(a.offset(-l+r,-u+i)),[d,f]=eB(a.toA+r,a.toB+i,t,n),s++}o.push(new Qz(p,l,Math.max(l,d),u,Math.max(u,f),a))}return o}var nB=1e3;function rB(e,t,n,r){let i=0,a=e.length;for(;;){if(i==a){let r=0,a=0;i&&({toA:r,toB:a}=e[i-1]);let o=t-(n?r:a);return[r+o,a+o]}let o=i+a>>1,s=e[o],[c,l]=n?[s.fromA,s.toA]:[s.fromB,s.toB];if(c>t)a=o;else if(l<=t)i=o+1;else return r?[s.fromA,s.fromB]:[s.toA,s.toB]}}function iB(e,t,n,r){let i=[];return t.iterChangedRanges((a,o,s,c)=>{let l=0,u=n?t.length:r,d=0,f=n?r:t.length;a>nB&&([l,d]=rB(e,a-nB,n,!0)),o<t.length-nB&&([u,f]=rB(e,o+nB,n,!1));let p=c-s-(o-a),m,[h,g]=n?[p,0]:[0,p];i.length&&(m=i[i.length-1]).toA>=l?i[i.length-1]={fromA:m.fromA,fromB:m.fromB,toA:u,toB:f,diffA:m.diffA+h,diffB:m.diffB+g}:i.push({fromA:l,toA:u,fromB:d,toB:f,diffA:h,diffB:g})}),i}function aB(e,t,n,r,i){if(!e.length)return t;let a=[];for(let o=0,s=0,c=0,l=0;;o++){let u=o==e.length?null:e[o],d=u?u.fromA+s:n.length,f=u?u.fromB+c:r.length;for(;l<t.length;){let e=t[l];if(u&&(e.toA+s>d||e.toB+c>f))break;a.push(e.offset(s,c)),l++}if(!u)break;let p=u.toA+s+u.diffA,m=u.toB+c+u.diffB,h=Jz(n.sliceString(d,p),r.sliceString(f,m),i);for(let e of tB(h,n,r,d,f,qz()))a.push(e);for(s+=u.diffA,c+=u.diffB;l<t.length;){let e=t[l];if(e.fromA+s>p&&e.fromB+c>m)break;l++}}return a}var NCe={scanLimit:500},oB=ae.fromClass(class{constructor(e){({deco:this.deco,gutter:this.gutter}=uB(e))}update(e){(e.docChanged||e.viewportChanged||PCe(e.startState,e.state)||FCe(e.startState,e.state))&&({deco:this.deco,gutter:this.gutter}=uB(e.view))}},{decorations:e=>e.deco}),sB=Te.low(ce({class:`cm-changeGutter`,markers:e=>e.plugin(oB)?.gutter||s.empty}));function PCe(e,t){return e.field(Zz,!1)!=t.field(Zz,!1)}function FCe(e,t){return e.facet(Yz)!=t.facet(Yz)}var cB=Fe.line({class:`cm-changedLine`}),ICe=Fe.mark({class:`cm-changedText`}),LCe=Fe.mark({tagName:`ins`,class:`cm-insertedLine`}),RCe=Fe.mark({tagName:`del`,class:`cm-deletedLine`}),lB=new class extends ie{constructor(){super(...arguments),this.elementClass=`cm-changedLineGutter`}};function zCe(e,t,n,r,i,a){let o=n?e.fromA:e.fromB,s=n?e.toA:e.toB,c=0;if(o!=s){i.add(o,o,cB),i.add(o,s,n?RCe:LCe),a&&a.add(o,o,lB);for(let l=t.iterRange(o,s-1),u=o;!l.next().done;){if(l.lineBreak){u++,i.add(u,u,cB),a&&a.add(u,u,lB);continue}let t=u+l.value.length;if(r)for(;c<e.changes.length;){let r=e.changes[c],a=o+(n?r.fromA:r.fromB),s=o+(n?r.toA:r.toB),l=Math.max(u,a),d=Math.min(t,s);if(l<d&&i.add(l,d,ICe),s<t)c++;else break}u=t}}}function uB(e){let t=e.state.field(Zz),{side:n,highlightChanges:r,markGutter:i,overrideChunk:a}=e.state.facet(Yz),o=n==`a`,s=new Ce,c=i?new Ce:null,{from:l,to:u}=e.viewport;for(let n of t){if((o?n.fromA:n.fromB)>=u)break;(o?n.toA:n.toB)>l&&(!a||!a(e.state,n,s,c))&&zCe(n,e.state.doc,o,r,s,c)}return{deco:s.finish(),gutter:c&&c.finish()}}var dB=class extends N{constructor(e){super(),this.height=e}eq(e){return this.height==e.height}toDOM(){let e=document.createElement(`div`);return e.className=`cm-mergeSpacer`,e.style.height=this.height+`px`,e}updateDOM(e){return e.style.height=this.height+`px`,!0}get estimatedHeight(){return this.height}ignoreEvent(){return!1}},fB=k.define({map:(e,t)=>e.map(t)}),pB=M.define({create:()=>Fe.none,update:(e,t)=>{for(let e of t.effects)if(e.is(fB))return e.value;return e.map(t.changes)},provide:e=>B.decorations.from(e)}),mB=.01;function hB(e,t){if(e.size!=t.size)return!1;let n=e.iter(),r=t.iter();for(;n.value;){if(n.from!=r.from||Math.abs(n.value.spec.widget.height-r.value.spec.widget.height)>1)return!1;n.next(),r.next()}return!0}function BCe(e,t,n){let r=new Ce,i=new Ce,a=e.state.field(pB).iter(),o=t.state.field(pB).iter(),s=0,c=0,l=0,u=0,d=e.viewport,f=t.viewport;for(let p=0;;p++){let m=p<n.length?n[p]:null,h=m?m.fromA:e.state.doc.length,g=m?m.fromB:t.state.doc.length;if(s<h){let n=e.lineBlockAt(s).top+l-(t.lineBlockAt(c).top+u);n<-.01?(l-=n,r.add(s,s,Fe.widget({widget:new dB(-n),block:!0,side:-1}))):n>mB&&(u+=n,i.add(c,c,Fe.widget({widget:new dB(n),block:!0,side:-1})))}if(h>s+1e3&&s<d.from&&h>d.from&&c<f.from&&g>f.from){let e=Math.min(d.from-s,f.from-c);s+=e,c+=e,p--}else if(m)s=m.toA,c=m.toB;else break;for(;a.value&&a.from<s;)l-=a.value.spec.widget.height,a.next();for(;o.value&&o.from<c;)u-=o.value.spec.widget.height,o.next()}for(;a.value;)l-=a.value.spec.widget.height,a.next();for(;o.value;)u-=o.value.spec.widget.height,o.next();let p=e.contentHeight+l-(t.contentHeight+u);p<mB?r.add(e.state.doc.length,e.state.doc.length,Fe.widget({widget:new dB(-p),block:!0,side:1})):p>mB&&i.add(t.state.doc.length,t.state.doc.length,Fe.widget({widget:new dB(p),block:!0,side:1}));let m=r.finish(),h=i.finish();hB(m,e.state.field(pB))||e.dispatch({effects:fB.of(m)}),hB(h,t.state.field(pB))||t.dispatch({effects:fB.of(h)})}var gB=k.define({map:(e,t)=>t.mapPos(e)}),VCe=class extends N{constructor(e){super(),this.lines=e}eq(e){return this.lines==e.lines}toDOM(e){let t=document.createElement(`div`);return t.className=`cm-collapsedLines`,t.textContent=e.state.phrase(`$ unchanged lines`,this.lines),t.addEventListener(`click`,t=>{let n=e.posAtDOM(t.target);e.dispatch({effects:gB.of(n)});let{side:r,sibling:i}=e.state.facet(Yz);i&&i().dispatch({effects:gB.of(HCe(n,e.state.field(Zz),r==`a`))})}),t}ignoreEvent(e){return e instanceof MouseEvent}get estimatedHeight(){return 27}get type(){return`collapsed-unchanged-code`}};function HCe(e,t,n){let r=0,i=0;for(let a=0;;a++){let o=a<t.length?t[a]:null;if(!o||(n?o.fromA:o.fromB)>=e)return i+(e-r);[r,i]=n?[o.toA,o.toB]:[o.toB,o.toA]}}var UCe=M.define({create(e){return Fe.none},update(e,t){e=e.map(t.changes);for(let n of t.effects)n.is(gB)&&(e=e.update({filter:e=>e!=n.value}));if(e.size&&t.state.field(Zz)!=t.startState.field(Zz,!1)){let n=t.state.facet(Yz).side==`a`,r=[];for(let i of t.state.field(Zz))e.between(n?i.fromA:i.fromB,n?i.toA:i.toB,e=>{r.push(e)});r.length&&(e=e.update({filter:e=>r.indexOf(e)<0}))}return e},provide:e=>B.decorations.from(e)});function _B({margin:e=3,minSize:t=4}){return UCe.init(n=>WCe(n,e,t))}function WCe(e,t,n){let r=new Ce,i=e.facet(Yz).side==`a`,a=e.field(Zz),o=1;for(let s=0;;s++){let c=s<a.length?a[s]:null,l=s?o+t:1,u=c?e.doc.lineAt(i?c.fromA:c.fromB).number-1-t:e.doc.lines,d=u-l+1;if(d>=n&&r.add(e.doc.line(l).from,e.doc.line(u).to,Fe.replace({widget:new VCe(d),block:!0})),!c)break;o=e.doc.lineAt(Math.min(e.doc.length,i?c.toA:c.toB)).number}return r.finish()}var GCe=B.styleModule.of(new Ze({".cm-mergeView":{overflowY:`auto`},".cm-mergeViewEditors":{display:`flex`,alignItems:`stretch`},".cm-mergeViewEditor":{flexGrow:1,flexBasis:0,overflow:`hidden`},".cm-merge-revert":{width:`1.6em`,flexGrow:0,flexShrink:0,position:`relative`},".cm-merge-revert button":{position:`absolute`,display:`block`,width:`100%`,boxSizing:`border-box`,textAlign:`center`,background:`none`,border:`none`,font:`inherit`,cursor:`pointer`}})),KCe=B.baseTheme({".cm-mergeView & .cm-scroller, .cm-mergeView &":{height:`auto !important`,overflowY:`visible !important`},"&.cm-merge-a .cm-changedLine, .cm-deletedChunk":{backgroundColor:`rgba(160, 128, 100, .08)`},"&.cm-merge-b .cm-changedLine, .cm-inlineChangedLine":{backgroundColor:`rgba(100, 160, 128, .08)`},"&light.cm-merge-a .cm-changedText, &light .cm-deletedChunk .cm-deletedText":{background:`linear-gradient(#ee443366, #ee443366) bottom/100% 2px no-repeat`},"&dark.cm-merge-a .cm-changedText, &dark .cm-deletedChunk .cm-deletedText":{background:`linear-gradient(#ffaa9966, #ffaa9966) bottom/100% 2px no-repeat`},"&light.cm-merge-b .cm-changedText":{background:`linear-gradient(#22bb22aa, #22bb22aa) bottom/100% 2px no-repeat`},"&dark.cm-merge-b .cm-changedText":{background:`linear-gradient(#88ff88aa, #88ff88aa) bottom/100% 2px no-repeat`},"&.cm-merge-b .cm-deletedText":{background:`#ff000033`},".cm-insertedLine, .cm-deletedLine, .cm-deletedLine del":{textDecoration:`none`},".cm-deletedChunk":{paddingLeft:`6px`,"& .cm-chunkButtons":{position:`absolute`,insetInlineEnd:`5px`},"& button":{border:`none`,cursor:`pointer`,color:`white`,margin:`0 2px`,borderRadius:`3px`,"&[name=accept]":{background:`#2a2`},"&[name=reject]":{background:`#d43`}}},".cm-collapsedLines":{padding:`5px 5px 5px 10px`,cursor:`pointer`,"&:before":{content:`"⦚"`,marginInlineEnd:`7px`},"&:after":{content:`"⦚"`,marginInlineStart:`7px`}},"&light .cm-collapsedLines":{color:`#444`,background:`linear-gradient(to bottom, transparent 0, #f3f3f3 30%, #f3f3f3 70%, transparent 100%)`},"&dark .cm-collapsedLines":{color:`#ddd`,background:`linear-gradient(to bottom, transparent 0, #222 30%, #222 70%, transparent 100%)`},".cm-changeGutter":{width:`3px`,paddingLeft:`1px`},"&light.cm-merge-a .cm-changedLineGutter, &light .cm-deletedLineGutter":{background:`#e43`},"&dark.cm-merge-a .cm-changedLineGutter, &dark .cm-deletedLineGutter":{background:`#fa9`},"&light.cm-merge-b .cm-changedLineGutter":{background:`#2b2`},"&dark.cm-merge-b .cm-changedLineGutter":{background:`#8f8`},".cm-inlineChangedLineGutter":{background:`#75d`}}),vB=new qe,yB=new qe,qCe=class{constructor(e){this.revertDOM=null,this.revertToA=!1,this.revertToLeft=!1,this.measuring=-1,this.diffConf=e.diffConfig||NCe;let t=[Te.low(oB),KCe,GCe,pB,B.updateListener.of(e=>{this.measuring<0&&(e.heightChanged||e.viewportChanged)&&!e.transactions.some(e=>e.effects.some(e=>e.is(fB)))&&this.measure()})],n=[Yz.of({side:`a`,sibling:()=>this.b,highlightChanges:e.highlightChanges!==!1,markGutter:e.gutter!==!1})];e.gutter!==!1&&n.push(sB);let r=h.create({doc:e.a.doc,selection:e.a.selection,extensions:[e.a.extensions||[],B.editorAttributes.of({class:`cm-merge-a`}),yB.of(n),t]}),i=[Yz.of({side:`b`,sibling:()=>this.a,highlightChanges:e.highlightChanges!==!1,markGutter:e.gutter!==!1})];e.gutter!==!1&&i.push(sB);let a=h.create({doc:e.b.doc,selection:e.b.selection,extensions:[e.b.extensions||[],B.editorAttributes.of({class:`cm-merge-b`}),yB.of(i),t]});this.chunks=Qz.build(r.doc,a.doc,this.diffConf);let o=[Zz.init(()=>this.chunks),vB.of(e.collapseUnchanged?_B(e.collapseUnchanged):[])];r=r.update({effects:k.appendConfig.of(o)}).state,a=a.update({effects:k.appendConfig.of(o)}).state,this.dom=document.createElement(`div`),this.dom.className=`cm-mergeView`,this.editorDOM=this.dom.appendChild(document.createElement(`div`)),this.editorDOM.className=`cm-mergeViewEditors`;let s=e.orientation||`a-b`,c=document.createElement(`div`);c.className=`cm-mergeViewEditor`;let l=document.createElement(`div`);l.className=`cm-mergeViewEditor`,this.editorDOM.appendChild(s==`a-b`?c:l),this.editorDOM.appendChild(s==`a-b`?l:c),this.a=new B({state:r,parent:c,root:e.root,dispatchTransactions:e=>this.dispatch(e,this.a)}),this.b=new B({state:a,parent:l,root:e.root,dispatchTransactions:e=>this.dispatch(e,this.b)}),this.setupRevertControls(!!e.revertControls,e.revertControls==`b-to-a`,e.renderRevertControl),e.parent&&e.parent.appendChild(this.dom),this.scheduleMeasure()}dispatch(e,t){if(e.some(e=>e.docChanged)){let n=e[e.length-1],r=e.reduce((e,t)=>e.compose(t.changes),L.empty(e[0].startState.doc.length));this.chunks=t==this.a?Qz.updateA(this.chunks,n.newDoc,this.b.state.doc,r,this.diffConf):Qz.updateB(this.chunks,this.a.state.doc,n.newDoc,r,this.diffConf),t.update([...e,n.state.update({effects:Xz.of(this.chunks)})]);let i=t==this.a?this.b:this.a;i.update([i.state.update({effects:Xz.of(this.chunks)})]),this.scheduleMeasure()}else t.update(e)}reconfigure(e){if(`diffConfig`in e&&(this.diffConf=e.diffConfig),`orientation`in e){let t=e.orientation!=`b-a`;if(t!=(this.editorDOM.firstChild==this.a.dom.parentNode)){let e=this.a.dom.parentNode,n=this.b.dom.parentNode;e.remove(),n.remove(),this.editorDOM.insertBefore(t?e:n,this.editorDOM.firstChild),this.editorDOM.appendChild(t?n:e),this.revertToLeft=!this.revertToLeft,this.revertDOM&&(this.revertDOM.textContent=``)}}if(`revertControls`in e||`renderRevertControl`in e){let t=!!this.revertDOM,n=this.revertToA,r=this.renderRevert;`revertControls`in e&&(t=!!e.revertControls,n=e.revertControls==`b-to-a`),`renderRevertControl`in e&&(r=e.renderRevertControl),this.setupRevertControls(t,n,r)}let t=`highlightChanges`in e,n=`gutter`in e,r=`collapseUnchanged`in e;if(t||n||r){let i=[],a=[];if(t||n){let r=this.a.state.facet(Yz),o=n?e.gutter!==!1:r.markGutter,s=t?e.highlightChanges!==!1:r.highlightChanges;i.push(yB.reconfigure([Yz.of({side:`a`,sibling:()=>this.b,highlightChanges:s,markGutter:o}),o?sB:[]])),a.push(yB.reconfigure([Yz.of({side:`b`,sibling:()=>this.a,highlightChanges:s,markGutter:o}),o?sB:[]]))}if(r){let t=vB.reconfigure(e.collapseUnchanged?_B(e.collapseUnchanged):[]);i.push(t),a.push(t)}this.a.dispatch({effects:i}),this.b.dispatch({effects:a})}this.scheduleMeasure()}setupRevertControls(e,t,n){this.revertToA=t,this.revertToLeft=this.revertToA==(this.editorDOM.firstChild==this.a.dom.parentNode),this.renderRevert=n,!e&&this.revertDOM?(this.revertDOM.remove(),this.revertDOM=null):e&&!this.revertDOM?(this.revertDOM=this.editorDOM.insertBefore(document.createElement(`div`),this.editorDOM.firstChild.nextSibling),this.revertDOM.addEventListener(`mousedown`,e=>this.revertClicked(e)),this.revertDOM.className=`cm-merge-revert`):this.revertDOM&&(this.revertDOM.textContent=``)}scheduleMeasure(){if(this.measuring<0){let e=this.dom.ownerDocument.defaultView||window;this.measuring=e.requestAnimationFrame(()=>{this.measuring=-1,this.measure()})}}measure(){BCe(this.a,this.b,this.chunks),this.revertDOM&&this.updateRevertButtons()}updateRevertButtons(){let e=this.revertDOM,t=e.firstChild,n=this.a.viewport,r=this.b.viewport;for(let i=0;i<this.chunks.length;i++){let a=this.chunks[i];if(a.fromA>n.to||a.fromB>r.to)break;if(a.fromA<n.from||a.fromB<r.from)continue;let o=this.a.lineBlockAt(a.fromA).top+`px`;for(;t&&+t.dataset.chunk<i;)t=bB(t);t&&t.dataset.chunk==String(i)?(t.style.top!=o&&(t.style.top=o),t=t.nextSibling):e.insertBefore(this.renderRevertButton(o,i),t)}for(;t;)t=bB(t)}renderRevertButton(e,t){let n;if(this.renderRevert)n=this.renderRevert();else{n=document.createElement(`button`);let e=this.a.state.phrase(`Revert this chunk`);n.setAttribute(`aria-label`,e),n.setAttribute(`title`,e),n.textContent=this.revertToLeft?`⇜`:`⇝`}return n.style.top=e,n.setAttribute(`data-chunk`,String(t)),n}revertClicked(e){let t=e.target,n;for(;t&&t.parentNode!=this.revertDOM;)t=t.parentNode;if(t&&(n=this.chunks[t.dataset.chunk])){let[t,r,i,a,o,s]=this.revertToA?[this.b,this.a,n.fromB,n.toB,n.fromA,n.toA]:[this.a,this.b,n.fromA,n.toA,n.fromB,n.toB],c=t.state.sliceDoc(i,Math.max(i,a-1));i!=a&&s<=r.state.doc.length&&(c+=t.state.lineBreak),r.dispatch({changes:{from:o,to:Math.min(r.state.doc.length,s),insert:c},userEvent:`revert`}),e.preventDefault()}}destroy(){this.a.destroy(),this.b.destroy(),this.measuring>-1&&(this.dom.ownerDocument.defaultView||window).cancelAnimationFrame(this.measuring),this.dom.remove()}};function bB(e){let t=e.nextSibling;return e.remove(),t}var xB=class e{static create(t,n,r,i,a){let o=i+(i<<8)+t+(n<<4)|0;return new e(t,n,r,o,a,[],[])}constructor(e,t,n,r,i,a,o){this.type=e,this.value=t,this.from=n,this.hash=r,this.end=i,this.children=a,this.positions=o,this.hashProp=[[c.contextHash,r]]}addChild(e,t){e.prop(c.contextHash)!=this.hash&&(e=new v(e.type,e.children,e.positions,e.length,this.hashProp)),this.children.push(e),this.positions.push(t)}toTree(e,t=this.end){let n=this.children.length-1;return n>=0&&(t=Math.max(t,this.positions[n]+this.children[n].length+this.from)),new v(e.types[this.type],this.children,this.positions,t-this.from).balance({makeTree:(e,t,n)=>new v(y.none,e,t,n,this.hashProp)})}},SB;(function(e){e[e.Document=1]=`Document`,e[e.CodeBlock=2]=`CodeBlock`,e[e.FencedCode=3]=`FencedCode`,e[e.Blockquote=4]=`Blockquote`,e[e.HorizontalRule=5]=`HorizontalRule`,e[e.BulletList=6]=`BulletList`,e[e.OrderedList=7]=`OrderedList`,e[e.ListItem=8]=`ListItem`,e[e.ATXHeading1=9]=`ATXHeading1`,e[e.ATXHeading2=10]=`ATXHeading2`,e[e.ATXHeading3=11]=`ATXHeading3`,e[e.ATXHeading4=12]=`ATXHeading4`,e[e.ATXHeading5=13]=`ATXHeading5`,e[e.ATXHeading6=14]=`ATXHeading6`,e[e.SetextHeading1=15]=`SetextHeading1`,e[e.SetextHeading2=16]=`SetextHeading2`,e[e.HTMLBlock=17]=`HTMLBlock`,e[e.LinkReference=18]=`LinkReference`,e[e.Paragraph=19]=`Paragraph`,e[e.CommentBlock=20]=`CommentBlock`,e[e.ProcessingInstructionBlock=21]=`ProcessingInstructionBlock`,e[e.Escape=22]=`Escape`,e[e.Entity=23]=`Entity`,e[e.HardBreak=24]=`HardBreak`,e[e.Emphasis=25]=`Emphasis`,e[e.StrongEmphasis=26]=`StrongEmphasis`,e[e.Link=27]=`Link`,e[e.Image=28]=`Image`,e[e.InlineCode=29]=`InlineCode`,e[e.HTMLTag=30]=`HTMLTag`,e[e.Comment=31]=`Comment`,e[e.ProcessingInstruction=32]=`ProcessingInstruction`,e[e.Autolink=33]=`Autolink`,e[e.HeaderMark=34]=`HeaderMark`,e[e.QuoteMark=35]=`QuoteMark`,e[e.ListMark=36]=`ListMark`,e[e.LinkMark=37]=`LinkMark`,e[e.EmphasisMark=38]=`EmphasisMark`,e[e.CodeMark=39]=`CodeMark`,e[e.CodeText=40]=`CodeText`,e[e.CodeInfo=41]=`CodeInfo`,e[e.LinkTitle=42]=`LinkTitle`,e[e.LinkLabel=43]=`LinkLabel`,e[e.URL=44]=`URL`})(SB||={});var JCe=class{constructor(e,t){this.start=e,this.content=t,this.marks=[],this.parsers=[]}},YCe=class{constructor(){this.text=``,this.baseIndent=0,this.basePos=0,this.depth=0,this.markers=[],this.pos=0,this.indent=0,this.next=-1}forward(){this.basePos>this.pos&&this.forwardInner()}forwardInner(){let e=this.skipSpace(this.basePos);this.indent=this.countIndent(e,this.pos,this.indent),this.pos=e,this.next=e==this.text.length?-1:this.text.charCodeAt(e)}skipSpace(e){return EB(this.text,e)}reset(e){for(this.text=e,this.baseIndent=this.basePos=this.pos=this.indent=0,this.forwardInner(),this.depth=1;this.markers.length;)this.markers.pop()}moveBase(e){this.basePos=e,this.baseIndent=this.countIndent(e,this.pos,this.indent)}moveBaseColumn(e){this.baseIndent=e,this.basePos=this.findColumn(e)}addMarker(e){this.markers.push(e)}countIndent(e,t=0,n=0){for(let r=t;r<e;r++)n+=this.text.charCodeAt(r)==9?4-n%4:1;return n}findColumn(e){let t=0;for(let n=0;t<this.text.length&&n<e;t++)n+=this.text.charCodeAt(t)==9?4-n%4:1;return t}scrub(){if(!this.baseIndent)return this.text;let e=``;for(let t=0;t<this.basePos;t++)e+=` `;return e+this.text.slice(this.basePos)}};function CB(e,t,n){if(n.pos==n.text.length||e!=t.block&&n.indent>=t.stack[n.depth+1].value+n.baseIndent)return!0;if(n.indent>=n.baseIndent+4)return!1;let r=(e.type==SB.OrderedList?NB:MB)(n,t,!1);return r>0&&(e.type!=SB.BulletList||AB(n,t,!1)<0)&&n.text.charCodeAt(n.pos+r-1)==e.value}var wB={[SB.Blockquote](e,t,n){return n.next==62&&(n.markers.push(nV(SB.QuoteMark,t.lineStart+n.pos,t.lineStart+n.pos+1)),n.moveBase(n.pos+(TB(n.text.charCodeAt(n.pos+1))?2:1)),e.end=t.lineStart+n.text.length,!0)},[SB.ListItem](e,t,n){return n.indent<n.baseIndent+e.value&&n.next>-1?!1:(n.moveBaseColumn(n.baseIndent+e.value),!0)},[SB.OrderedList]:CB,[SB.BulletList]:CB,[SB.Document](){return!0}};function TB(e){return e==32||e==9||e==10||e==13}function EB(e,t=0){for(;t<e.length&&TB(e.charCodeAt(t));)t++;return t}function DB(e,t,n){for(;t>n&&TB(e.charCodeAt(t-1));)t--;return t}function OB(e){if(e.next!=96&&e.next!=126)return-1;let t=e.pos+1;for(;t<e.text.length&&e.text.charCodeAt(t)==e.next;)t++;if(t<e.pos+3)return-1;if(e.next==96){for(let n=t;n<e.text.length;n++)if(e.text.charCodeAt(n)==96)return-1}return t}function kB(e){return e.next==62?e.text.charCodeAt(e.pos+1)==32?2:1:-1}function AB(e,t,n){if(e.next!=42&&e.next!=45&&e.next!=95)return-1;let r=1;for(let t=e.pos+1;t<e.text.length;t++){let n=e.text.charCodeAt(t);if(n==e.next)r++;else if(!TB(n))return-1}return n&&e.next==45&&FB(e)>-1&&e.depth==t.stack.length&&t.parser.leafBlockParsers.indexOf(GB.SetextHeading)>-1||r<3?-1:1}function jB(e,t){for(let n=e.stack.length-1;n>=0;n--)if(e.stack[n].type==t)return!0;return!1}function MB(e,t,n){return(e.next==45||e.next==43||e.next==42)&&(e.pos==e.text.length-1||TB(e.text.charCodeAt(e.pos+1)))&&(!n||jB(t,SB.BulletList)||e.skipSpace(e.pos+2)<e.text.length)?1:-1}function NB(e,t,n){let r=e.pos,i=e.next;for(;i>=48&&i<=57;){if(r++,r==e.text.length)return-1;i=e.text.charCodeAt(r)}return r==e.pos||r>e.pos+9||i!=46&&i!=41||r<e.text.length-1&&!TB(e.text.charCodeAt(r+1))||n&&!jB(t,SB.OrderedList)&&(e.skipSpace(r+1)==e.text.length||r>e.pos+1||e.next!=49)?-1:r+1-e.pos}function PB(e){if(e.next!=35)return-1;let t=e.pos+1;for(;t<e.text.length&&e.text.charCodeAt(t)==35;)t++;if(t<e.text.length&&e.text.charCodeAt(t)!=32)return-1;let n=t-e.pos;return n>6?-1:n}function FB(e){if(e.next!=45&&e.next!=61||e.indent>=e.baseIndent+4)return-1;let t=e.pos+1;for(;t<e.text.length&&e.text.charCodeAt(t)==e.next;)t++;let n=t;for(;t<e.text.length&&TB(e.text.charCodeAt(t));)t++;return t==e.text.length?n:-1}var IB=/^[ \t]*$/,LB=/-->/,RB=/\?>/,zB=[[/^<(?:script|pre|style)(?:\s|>|$)/i,/<\/(?:script|pre|style)>/i],[/^\s*<!--/,LB],[/^\s*<\?/,RB],[/^\s*<![A-Z]/,/>/],[/^\s*<!\[CDATA\[/,/\]\]>/],[/^\s*<\/?(?:address|article|aside|base|basefont|blockquote|body|caption|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption|figure|footer|form|frame|frameset|h1|h2|h3|h4|h5|h6|head|header|hr|html|iframe|legend|li|link|main|menu|menuitem|nav|noframes|ol|optgroup|option|p|param|section|source|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul)(?:\s|\/?>|$)/i,IB],[/^\s*(?:<\/[a-z][\w-]*\s*>|<[a-z][\w-]*(\s+[a-z:_][\w-.]*(?:\s*=\s*(?:[^\s"'=<>`]+|'[^']*'|"[^"]*"))?)*\s*>)\s*$/i,IB]];function BB(e,t,n){if(e.next!=60)return-1;let r=e.text.slice(e.pos);for(let e=0,t=zB.length-+!!n;e<t;e++)if(zB[e][0].test(r))return e;return-1}function VB(e,t){let n=e.countIndent(t,e.pos,e.indent),r=e.skipSpace(t),i=e.countIndent(r,t,n);return i>=n+5||r==e.text.length?n+1:i}function HB(e,t,n){let r=e.length-1;r>=0&&e[r].to==t&&e[r].type==SB.CodeText?e[r].to=n:e.push(nV(SB.CodeText,t,n))}var UB={LinkReference:void 0,IndentedCode(e,t){let n=t.baseIndent+4;if(t.indent<n)return!1;let r=t.findColumn(n),i=e.lineStart+r,a=e.lineStart+t.text.length,o=[],s=[];for(HB(o,i,a);e.nextLine()&&t.depth>=e.stack.length;)if(t.pos==t.text.length){HB(s,e.lineStart-1,e.lineStart);for(let e of t.markers)s.push(e)}else if(t.indent<n)break;else{if(s.length){for(let e of s)e.type==SB.CodeText?HB(o,e.from,e.to):o.push(e);s=[]}HB(o,e.lineStart-1,e.lineStart);for(let e of t.markers)o.push(e);a=e.lineStart+t.text.length;let n=e.lineStart+t.findColumn(t.baseIndent+4);n<a&&HB(o,n,a)}return s.length&&(s=s.filter(e=>e.type!=SB.CodeText),s.length&&(t.markers=s.concat(t.markers))),e.addNode(e.buffer.writeElements(o,-i).finish(SB.CodeBlock,a-i),i),!0},FencedCode(e,t){let n=OB(t);if(n<0)return!1;let r=e.lineStart+t.pos,i=t.next,a=n-t.pos,o=t.skipSpace(n),s=DB(t.text,t.text.length,o),c=[nV(SB.CodeMark,r,r+a)];o<s&&c.push(nV(SB.CodeInfo,e.lineStart+o,e.lineStart+s));for(let n=!0,r=!0,o=!1;e.nextLine()&&t.depth>=e.stack.length;n=!1){let s=t.pos;if(t.indent-t.baseIndent<4)for(;s<t.text.length&&t.text.charCodeAt(s)==i;)s++;if(s-t.pos>=a&&t.skipSpace(s)==t.text.length){for(let e of t.markers)c.push(e);r&&o&&HB(c,e.lineStart-1,e.lineStart),c.push(nV(SB.CodeMark,e.lineStart+t.pos,e.lineStart+s)),e.nextLine();break}{o=!0,n||(HB(c,e.lineStart-1,e.lineStart),r=!1);for(let e of t.markers)c.push(e);let i=e.lineStart+t.basePos,a=e.lineStart+t.text.length;i<a&&(HB(c,i,a),r=!1)}}return e.addNode(e.buffer.writeElements(c,-r).finish(SB.FencedCode,e.prevLineEnd()-r),r),!0},Blockquote(e,t){let n=kB(t);return n<0?!1:(e.startContext(SB.Blockquote,t.pos),e.addNode(SB.QuoteMark,e.lineStart+t.pos,e.lineStart+t.pos+1),t.moveBase(t.pos+n),null)},HorizontalRule(e,t){if(AB(t,e,!1)<0)return!1;let n=e.lineStart+t.pos;return e.nextLine(),e.addNode(SB.HorizontalRule,n),!0},BulletList(e,t){let n=MB(t,e,!1);if(n<0)return!1;e.block.type!=SB.BulletList&&e.startContext(SB.BulletList,t.basePos,t.next);let r=VB(t,t.pos+1);return e.startContext(SB.ListItem,t.basePos,r-t.baseIndent),e.addNode(SB.ListMark,e.lineStart+t.pos,e.lineStart+t.pos+n),t.moveBaseColumn(r),null},OrderedList(e,t){let n=NB(t,e,!1);if(n<0)return!1;e.block.type!=SB.OrderedList&&e.startContext(SB.OrderedList,t.basePos,t.text.charCodeAt(t.pos+n-1));let r=VB(t,t.pos+n);return e.startContext(SB.ListItem,t.basePos,r-t.baseIndent),e.addNode(SB.ListMark,e.lineStart+t.pos,e.lineStart+t.pos+n),t.moveBaseColumn(r),null},ATXHeading(e,t){let n=PB(t);if(n<0)return!1;let r=t.pos,i=e.lineStart+r,a=DB(t.text,t.text.length,r),o=a;for(;o>r&&t.text.charCodeAt(o-1)==t.next;)o--;(o==a||o==r||!TB(t.text.charCodeAt(o-1)))&&(o=t.text.length);let s=e.buffer.write(SB.HeaderMark,0,n).writeElements(e.parser.parseInline(t.text.slice(r+n+1,o),i+n+1),-i);o<t.text.length&&s.write(SB.HeaderMark,o-r,a-r);let c=s.finish(SB.ATXHeading1-1+n,t.text.length-r);return e.nextLine(),e.addNode(c,i),!0},HTMLBlock(e,t){let n=BB(t,e,!1);if(n<0)return!1;let r=e.lineStart+t.pos,i=zB[n][1],a=[],o=i!=IB;for(;!i.test(t.text)&&e.nextLine();){if(t.depth<e.stack.length){o=!1;break}for(let e of t.markers)a.push(e)}o&&e.nextLine();let s=i==LB?SB.CommentBlock:i==RB?SB.ProcessingInstructionBlock:SB.HTMLBlock,c=e.prevLineEnd();return e.addNode(e.buffer.writeElements(a,-r).finish(s,c-r),r),!0},SetextHeading:void 0},XCe=class{constructor(e){this.stage=0,this.elts=[],this.pos=0,this.start=e.start,this.advance(e.content)}nextLine(e,t,n){if(this.stage==-1)return!1;let r=n.content+`
177
177
  `+t.scrub(),i=this.advance(r);return i>-1&&i<r.length&&this.complete(e,n,i)}finish(e,t){return(this.stage==2||this.stage==3)&&EB(t.content,this.pos)==t.content.length&&this.complete(e,t,t.content.length)}complete(e,t,n){return e.addLeafElement(t,nV(SB.LinkReference,this.start,this.start+n,this.elts)),!0}nextStage(e){return e?(this.pos=e.to-this.start,this.elts.push(e),this.stage++,!0):(e===!1&&(this.stage=-1),!1)}advance(e){for(;;)if(this.stage==-1)return-1;else if(this.stage==0){if(!this.nextStage(fV(e,this.pos,this.start,!0)))return-1;if(e.charCodeAt(this.pos)!=58)return this.stage=-1;this.elts.push(nV(SB.LinkMark,this.pos+this.start,this.pos+this.start+1)),this.pos++}else if(this.stage==1){if(!this.nextStage(uV(e,EB(e,this.pos),this.start)))return-1}else if(this.stage==2){let t=EB(e,this.pos),n=0;if(t>this.pos){let r=dV(e,t,this.start);if(r){let t=WB(e,r.to-this.start);t>0&&(this.nextStage(r),n=t)}}return n||=WB(e,this.pos),n>0&&n<e.length?n:-1}else return WB(e,this.pos)}};function WB(e,t){for(;t<e.length;t++){let n=e.charCodeAt(t);if(n==10)break;if(!TB(n))return-1}return t}var ZCe=class{nextLine(e,t,n){let r=t.depth<e.stack.length?-1:FB(t),i=t.next;if(r<0)return!1;let a=nV(SB.HeaderMark,e.lineStart+t.pos,e.lineStart+r);return e.nextLine(),e.addLeafElement(n,nV(i==61?SB.SetextHeading1:SB.SetextHeading2,n.start,e.prevLineEnd(),[...e.parser.parseInline(n.content,n.start),a])),!0}finish(){return!1}},GB={LinkReference(e,t){return t.content.charCodeAt(0)==91?new XCe(t):null},SetextHeading(){return new ZCe}},QCe=[(e,t)=>PB(t)>=0,(e,t)=>OB(t)>=0,(e,t)=>kB(t)>=0,(e,t)=>MB(t,e,!0)>=0,(e,t)=>NB(t,e,!0)>=0,(e,t)=>AB(t,e,!0)>=0,(e,t)=>BB(t,e,!0)>=0],$Ce={text:``,end:0},ewe=class{constructor(e,t,n,r){this.parser=e,this.input=t,this.ranges=r,this.line=new YCe,this.atEnd=!1,this.reusePlaceholders=new Map,this.stoppedAt=null,this.rangeI=0,this.to=r[r.length-1].to,this.lineStart=this.absoluteLineStart=this.absoluteLineEnd=r[0].from,this.block=xB.create(SB.Document,0,this.lineStart,0,0),this.stack=[this.block],this.fragments=n.length?new iwe(n,t):null,this.readLine()}get parsedPos(){return this.absoluteLineStart}advance(){if(this.stoppedAt!=null&&this.absoluteLineStart>this.stoppedAt)return this.finish();let{line:e}=this;for(;;){for(let t=0;;){let n=e.depth<this.stack.length?this.stack[this.stack.length-1]:null;for(;t<e.markers.length&&(!n||e.markers[t].from<n.end);){let n=e.markers[t++];this.addNode(n.type,n.from,n.to)}if(!n)break;this.finishContext()}if(e.pos<e.text.length)break;if(!this.nextLine())return this.finish()}if(this.fragments&&this.reuseFragment(e.basePos))return null;start:for(;;){for(let t of this.parser.blockParsers)if(t){let n=t(this,e);if(n!=0){if(n==1)return null;e.forward();continue start}}break}if(e.pos==e.text.length)return this.nextLine()?null:this.finish();let t=new JCe(this.lineStart+e.pos,e.text.slice(e.pos));for(let e of this.parser.leafBlockParsers)if(e){let n=e(this,t);n&&t.parsers.push(n)}lines:for(;this.nextLine()&&e.pos!=e.text.length;){if(e.indent<e.baseIndent+4){for(let n of this.parser.endLeafBlock)if(n(this,e,t))break lines}for(let n of t.parsers)if(n.nextLine(this,e,t))return null;t.content+=`
178
178
  `+e.scrub();for(let n of e.markers)t.marks.push(n)}return this.finishLeaf(t),null}stopAt(e){if(this.stoppedAt!=null&&this.stoppedAt<e)throw RangeError(`Can't move stoppedAt forward`);this.stoppedAt=e}reuseFragment(e){if(!this.fragments.moveTo(this.absoluteLineStart+e,this.absoluteLineStart)||!this.fragments.matches(this.block.hash))return!1;let t=this.fragments.takeNodes(this);return t?(this.absoluteLineStart+=t,this.lineStart=hV(this.absoluteLineStart,this.ranges),this.moveRangeI(),this.absoluteLineStart<this.to?(this.lineStart++,this.absoluteLineStart++,this.readLine()):(this.atEnd=!0,this.readLine()),!0):!1}get depth(){return this.stack.length}parentType(e=this.depth-1){return this.parser.nodeSet.types[this.stack[e].type]}nextLine(){return this.lineStart+=this.line.text.length,this.absoluteLineEnd>=this.to?(this.absoluteLineStart=this.absoluteLineEnd,this.atEnd=!0,this.readLine(),!1):(this.lineStart++,this.absoluteLineStart=this.absoluteLineEnd+1,this.moveRangeI(),this.readLine(),!0)}peekLine(){return this.scanLine(this.absoluteLineEnd+1).text}moveRangeI(){for(;this.rangeI<this.ranges.length-1&&this.absoluteLineStart>=this.ranges[this.rangeI].to;)this.rangeI++,this.absoluteLineStart=Math.max(this.absoluteLineStart,this.ranges[this.rangeI].from)}scanLine(e){let t=$Ce;if(t.end=e,e>=this.to)t.text=``;else if(t.text=this.lineChunkAt(e),t.end+=t.text.length,this.ranges.length>1){let e=this.absoluteLineStart,n=this.rangeI;for(;this.ranges[n].to<t.end;){n++;let r=this.ranges[n].from,i=this.lineChunkAt(r);t.end=r+i.length,t.text=t.text.slice(0,this.ranges[n-1].to-e)+i,e=t.end-t.text.length}}return t}readLine(){let{line:e}=this,{text:t,end:n}=this.scanLine(this.absoluteLineStart);for(this.absoluteLineEnd=n,e.reset(t);e.depth<this.stack.length;e.depth++){let t=this.stack[e.depth],n=this.parser.skipContextMarkup[t.type];if(!n)throw Error(`Unhandled block context `+SB[t.type]);let r=this.line.markers.length;if(!n(t,this,e)){this.line.markers.length>r&&(t.end=this.line.markers[this.line.markers.length-1].to),e.forward();break}e.forward()}}lineChunkAt(e){let t=this.input.chunk(e),n;if(this.input.lineChunks)n=t==`
@@ -209,7 +209,7 @@ Error generating stack: `+e.message+`
209
209
 
210
210
  `}${n}`:n:e}function KNe(){return[`audio/webm;codecs=opus`,`audio/webm`,`audio/ogg;codecs=opus`,`audio/mp4`].find(e=>MediaRecorder.isTypeSupported(e))}function qNe(e){let t=e.includes(`ogg`)?`ogg`:e.includes(`mp4`)?`m4a`:`webm`;return`recording-${Date.now()}.${t}`}function JNe(e){if(!e)return;if(e.value&&!e.value.includes(`
211
211
  `)&&e.value.length<80){e.style.height=``,e.style.overflowY=`hidden`;return}let t=window.getComputedStyle(e),n=WY(t.lineHeight,20),r=WY(t.borderTopWidth)+WY(t.borderBottomWidth),i=n*5+WY(t.paddingTop)+WY(t.paddingBottom);e.style.height=`auto`;let a=e.scrollHeight,o=a>i;e.style.height=`${Math.min(a,i)+r}px`,e.style.overflowY=o?`auto`:`hidden`,o&&e.selectionStart===e.value.length&&e.selectionEnd===e.value.length&&(e.scrollTop=a)}function WY(e,t=0){let n=Number.parseFloat(e);return Number.isFinite(n)?n:t}function GY(e){if(!(!e||typeof e!=`object`||Array.isArray(e)))return e}function KY(e){return typeof e==`number`&&Number.isFinite(e)?e:void 0}function qY(e){let t=KY(e);return t===void 0?void 0:Math.max(0,Math.min(100,t))}function YNe(e){let t=GY(e);if(typeof e==`string`)try{t=GY(JSON.parse(e))}catch{t=void 0}if(!t)return{};let n=GY(t.contextUsage),r=KY(n?.tokens),i=KY(n?.contextWindow),a=qY(n?.percent??(r!==void 0&&i?r/i*100:void 0)),o=GY(t.providerUsage),s=(Array.isArray(o?.limits)?o.limits.map(GY).filter(e=>!!e):[]).find(e=>{let t=typeof e?.label==`string`?e.label.toLowerCase():``;return/(^|\s)(weekly|1w|7d)(\s|$)/.test(t)}),c=qY(s?.usedPercent);return{contextPercent:a,weeklyRemainingPercent:qY(s?.remainingPercent??(c===void 0?void 0:100-c)),weeklyResetAt:typeof s?.resetsAt==`string`?s.resetsAt:void 0}}function JY(e,t,n){return`rgb(${e.map((e,r)=>Math.round(e+((t[r]??e)-e)*n)).join(`, `)})`}function XNe(e){if(e===void 0)return`#64748b`;let t=Math.max(0,Math.min(100,e));return t<=50?JY([239,68,68],[250,204,21],t/50):JY([250,204,21],[34,197,94],(t-50)/50)}function YY({label:e,percent:t,healthPercent:n,title:r}){let i=XNe(n),a=t===void 0?0:t;return(0,U.jsxs)(`div`,{className:`grid grid-cols-[5.25rem_minmax(3rem,1fr)_2.25rem] items-center gap-1`,"data-pibo-usage-meter":e.toLowerCase().replaceAll(` `,`-`),title:r,children:[(0,U.jsx)(`span`,{className:`truncate text-[9px] font-bold uppercase tracking-wide text-slate-500`,children:e}),(0,U.jsx)(`div`,{className:`h-1 overflow-hidden rounded-full bg-slate-800`,children:(0,U.jsx)(`div`,{className:`h-full rounded-full transition-[width,background-color] duration-300`,style:{width:`${a}%`,backgroundColor:i}})}),(0,U.jsx)(`span`,{className:`text-right font-mono text-[10px] tabular-nums`,style:{color:i},children:t===void 0?`--`:`${Math.round(t)}%`})]})}function ZNe({status:e}){let t=YNe(e),n=t.weeklyResetAt?new Date(t.weeklyResetAt):void 0,r=n&&!Number.isNaN(n.getTime())?`Weekly limit resets ${n.toLocaleString()}`:`Weekly limit remaining`;return(0,U.jsxs)(`div`,{className:`ml-1 w-48 shrink-0 space-y-0.5 border-l border-slate-800 pl-2`,"data-pibo-debug":`terminal-header-usage`,"aria-label":`Terminal usage status`,children:[(0,U.jsx)(YY,{label:`Weekly Limit`,percent:t.weeklyRemainingPercent,healthPercent:t.weeklyRemainingPercent,title:r}),(0,U.jsx)(YY,{label:`Context Usage`,percent:t.contextPercent,healthPercent:t.contextPercent===void 0?void 0:100-t.contextPercent,title:`Current context window usage`})]})}function QNe(e,t){let n=e?.workflowSessionKind??nPe(t?.metadata,`workflowSessionKind`);return n===`main_workflow`||n===`nested_workflow`||n===`agent_node`}function $Ne(e){return{workflowId:e.workflowId,state:tPe(e),...e.workflowRunId?{workflowRunId:e.workflowRunId}:{}}}function ePe({summary:e}){return(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(`span`,{className:`text-slate-600`,children:`·`}),(0,U.jsxs)(`span`,{className:`min-w-0 max-w-52 truncate rounded border border-[#11a4d4]/35 bg-[#11a4d4]/10 px-1.5 py-0.5 text-[10px] uppercase tracking-wide text-[#11a4d4]`,title:e.workflowId,children:[`workflow `,e.workflowId]}),(0,U.jsxs)(`span`,{className:XY(e.state),children:[`state `,e.state]}),e.workflowRunId?(0,U.jsxs)(`span`,{className:`min-w-0 max-w-40 truncate rounded border border-slate-700 bg-slate-900/40 px-1.5 py-0.5 text-[10px] text-slate-400`,title:e.workflowRunId,children:[`run `,ZY(e.workflowRunId)]}):null]})}function tPe(e){return e.state.replace(/_/g,` `)}function XY(e){let t=e.toLowerCase(),n=`shrink-0 rounded border px-1.5 py-0.5 text-[10px] uppercase tracking-wide`;return t.includes(`failed`)||t.includes(`error`)?`${n} border-red-500/40 bg-red-500/10 text-red-300`:t.includes(`waiting`)?`${n} border-amber-500/40 bg-amber-500/10 text-amber-300`:t.includes(`complete`)?`${n} border-emerald-500/40 bg-emerald-500/10 text-emerald-300`:`${n} border-[#11a4d4]/40 bg-[#11a4d4]/10 text-[#11a4d4]`}function ZY(e){return e.length>18?`${e.slice(0,10)}…${e.slice(-6)}`:e}function nPe(e,t){let n=e?.[t];return typeof n==`string`&&n.trim()?n.trim():void 0}function rPe({title:e,contextKind:t,contextLabel:n,headerPiboSessionId:r,terminalUsageStatus:i,workflowHeader:a,sessionViewId:o,currentSessionView:s,activeViewId:c,desktopTerminalOnly:l=!1,terminalFullscreenAvailable:u,onEnterTerminalFullscreen:d,onOpenSessionWindow:f,debugMode:p,showThinking:m,expandThinking:h,toolDisplayMode:g,toolIntentSupported:_,onToolDisplayModeChange:v,onToggleDebugMode:y,onToggleThinking:b,onToggleExpandThinking:x}){let[S,C]=(0,H.useState)(null),w=(0,H.useRef)(void 0),T=S===r,E=c??o,D=s.id===`terminal`&&E===`terminal`,O=`Room`;(0,H.useEffect)(()=>()=>{w.current&&window.clearTimeout(w.current)},[]);let k=()=>{r&&(Rq(r).catch(()=>void 0),C(r),w.current&&window.clearTimeout(w.current),w.current=window.setTimeout(()=>C(null),900))};return(0,U.jsxs)(`div`,{className:`h-14 px-4 bg-[#151f24] border-b border-slate-800 flex items-center justify-between max-[980px]:h-auto max-[980px]:flex-wrap max-[980px]:py-2 max-[980px]:gap-2 @max-[680px]:h-auto @max-[680px]:flex-wrap @max-[680px]:gap-2 @max-[680px]:py-2`,children:[(0,U.jsxs)(`div`,{className:`min-w-0 flex-1 max-[980px]:order-1 @max-[680px]:order-1`,children:[(0,U.jsx)(`h1`,{className:`text-base font-semibold truncate`,children:e}),(0,U.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5 font-mono text-[11px] text-slate-500`,children:[(0,U.jsxs)(`span`,{"data-pibo-debug":`session-context`,"data-pibo-context-kind":t,title:`${O}: ${n}`,"aria-label":`${O}: ${n}`,className:`inline-flex min-w-0 max-w-full items-center gap-1.5`,children:[(0,U.jsx)(`span`,{className:`shrink-0 uppercase tracking-wide text-[#11a4d4]`,children:O}),(0,U.jsx)(`span`,{className:`truncate text-slate-400`,children:n})]}),r?(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(`span`,{className:`text-slate-600`,children:`·`}),(0,U.jsx)(`button`,{type:`button`,onMouseDown:e=>e.preventDefault(),onClick:()=>void k(),title:T?`Copied Pibo session ID`:`Copy Pibo session ID`,"aria-label":T?`Copied Pibo session ID`:`Copy Pibo session ID`,className:`min-w-0 max-w-48 truncate rounded-sm px-1 font-mono underline-offset-2 transition-colors duration-150 focus:outline-none focus:ring-1 focus:ring-[#11a4d4] ${T?`bg-emerald-500/15 text-emerald-300 ring-1 ring-emerald-400/50`:`text-slate-400 hover:text-[#11a4d4] hover:underline`}`,children:r})]}):null,a?(0,U.jsx)(ePe,{summary:a}):null]})]}),(0,U.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2 max-[980px]:order-3 max-[980px]:w-full max-[980px]:flex-wrap max-[980px]:gap-1 @max-[680px]:order-3 @max-[680px]:w-full @max-[680px]:flex-wrap @max-[680px]:gap-1`,children:[f?(0,U.jsx)(`button`,{type:`button`,onClick:f,title:`Open selected session in new window`,"aria-label":`Open selected session in new window`,"data-pibo-debug":`open-session-window`,className:`h-8 w-8 inline-flex items-center justify-center border border-slate-700 rounded-sm text-slate-400 transition-colors hover:border-[#11a4d4] hover:text-[#11a4d4]`,children:(0,U.jsx)(rl,{size:15})}):null,(0,U.jsxs)(`select`,{value:g,onChange:e=>v(e.target.value),title:`Tool display mode`,"aria-label":`Tool display mode`,"data-pibo-debug":`tool-display-mode`,className:`h-8 rounded-sm border border-slate-700 bg-[#0e1116] px-2 text-[11px] font-bold uppercase tracking-wide text-slate-300 outline-none focus:border-[#11a4d4]`,children:[(0,U.jsx)(`option`,{value:`default`,children:`Tools: Default`}),(0,U.jsx)(`option`,{value:`hide`,children:`Tools: Hide`}),(0,U.jsx)(`option`,{value:`slim`,children:`Tools: Slim`}),(0,U.jsx)(`option`,{value:`intent`,disabled:!_,children:`Tools: Intent`})]}),u&&d?(0,U.jsx)(`button`,{type:`button`,onClick:d,title:`Enter Terminal fullscreen`,"aria-label":`Enter Terminal fullscreen`,"data-pibo-debug":`enter-terminal-fullscreen`,className:`h-8 w-8 inline-flex items-center justify-center border border-slate-700 rounded-sm text-slate-400 transition-colors hover:border-[#11a4d4] hover:text-[#11a4d4]`,children:(0,U.jsx)(Lc,{size:14})}):null,(0,U.jsx)(QY,{onClick:y,title:p?`Disable Debug`:`Enable Debug`,ariaLabel:`Debug`,active:p,children:(0,U.jsx)(Vs,{size:14})}),(0,U.jsx)(QY,{onClick:b,title:m?`Hide Thinking`:`Show Thinking`,ariaLabel:`Thinking`,active:m,children:m?(0,U.jsx)(Bs,{size:14}):(0,U.jsx)(pc,{size:14})}),m?(0,U.jsx)(QY,{onClick:x,title:h?`Collapse Thinking`:`Expand Thinking`,ariaLabel:`Thinking expansion`,active:h,children:h?(0,U.jsx)(Ys,{size:14}):(0,U.jsx)(Qs,{size:14})}):null]}),D?(0,U.jsx)(`div`,{className:`shrink-0 max-[980px]:order-2 @max-[680px]:order-2`,children:(0,U.jsx)(ZNe,{status:i})}):null]})}function QY({title:e,ariaLabel:t,ariaControls:n,active:r,onClick:i,children:a}){return(0,U.jsx)(`button`,{type:`button`,onClick:i,title:e,"aria-label":t,"aria-controls":n,"aria-pressed":r,className:`h-8 w-8 inline-flex items-center justify-center border rounded-sm transition-colors ${r?`border-[#11a4d4] bg-[#11a4d4]/10 text-[#11a4d4]`:`border-slate-700 text-slate-400 hover:border-[#11a4d4] hover:text-[#11a4d4]`}`,children:a})}function iPe(e){let t=[];for(let n of e){let e=t[t.length-1];if(e&&aPe(e,n)){e.count+=1,e.createdAt=n.createdAt,e.payload={...tX(e.payload)?e.payload:{},text:`${$Y(e.payload)}${$Y(n.payload)}`};continue}t.push({...n,count:1})}return t}function aPe(e,t){if(e.type!==t.type||e.type!==`assistant_delta`&&e.type!==`thinking_delta`&&e.type!==`TEXT_MESSAGE_CONTENT`&&e.type!==`REASONING_MESSAGE_CONTENT`)return!1;let n=tX(e.payload)?e.payload:{},r=tX(t.payload)?t.payload:{};return eX(n)===eX(r)}function $Y(e){return tX(e)?typeof e.text==`string`?e.text:typeof e.delta==`string`?e.delta:``:``}function eX(e){return e.eventId??e.messageId}function tX(e){return!!e&&typeof e==`object`&&!Array.isArray(e)}function nX({traceView:e,eventLimit:t,isFetching:n,visible:r,onLoadOlder:i}){let a=(0,H.useMemo)(()=>r?iPe(e?.rawEvents??[]):[],[e?.rawEvents,r]);return r?(0,U.jsxs)(`aside`,{id:`raw-events-inspector`,"aria-label":`Raw Events`,className:`min-h-0 overflow-auto overscroll-contain bg-[#0e1116] border-l border-slate-800 max-[980px]:fixed max-[980px]:right-0 max-[980px]:top-0 max-[980px]:bottom-0 max-[980px]:z-40 max-[980px]:w-[320px] max-[980px]:max-w-[80vw] max-[980px]:shadow-2xl`,children:[(0,U.jsx)(`div`,{className:`h-11 px-3 border-b border-slate-800 flex items-center text-xs font-bold uppercase tracking-wider`,children:`Raw Events`}),(0,U.jsxs)(`div`,{className:`p-3 flex flex-col gap-2`,children:[e&&a.length>=t?(0,U.jsx)(`button`,{type:`button`,onClick:i,disabled:n,className:`mb-1 rounded-sm border border-slate-700 px-2 py-1 text-xs text-slate-400 hover:border-[#11a4d4] hover:text-[#11a4d4] disabled:opacity-60`,children:n?`Loading raw events…`:`Load older raw events (${a.length})`}):null,a.slice(-t).reverse().map(e=>(0,U.jsxs)(`div`,{className:`border-l-2 border-[#11a4d4] bg-[#151f24] p-2`,children:[(0,U.jsxs)(`div`,{className:`flex items-center justify-between gap-2 text-[#11a4d4] font-mono text-[11px] mb-1`,children:[(0,U.jsx)(`span`,{children:e.type}),e.count>1?(0,U.jsxs)(`span`,{className:`text-slate-500`,children:[`x`,e.count]}):null]}),(0,U.jsx)(ZK,{value:e.payload,showControls:!1})]},e.id))]})]}):null}function oPe({title:e,contextKind:t,contextLabel:n,onOpenSessionWindow:r,onExit:i}){let a=`Room`;return(0,U.jsxs)(`div`,{"data-pibo-debug":`terminal-fullscreen-top-bar`,className:`h-7 min-h-7 flex items-center border-b border-slate-600 bg-[#151f24]`,children:[(0,U.jsxs)(`div`,{className:`flex min-w-0 flex-1 items-center`,children:[(0,U.jsxs)(`div`,{"data-pibo-debug":`session-context`,"data-pibo-context-kind":t,title:`${a}: ${n}`,"aria-label":`${a}: ${n}`,className:`flex min-w-0 max-w-[45%] shrink-0 items-center gap-1.5 px-2 font-mono text-[10px] leading-none`,children:[(0,U.jsx)(`span`,{className:`shrink-0 uppercase tracking-wide text-[#11a4d4]`,children:a}),(0,U.jsx)(`span`,{className:`truncate text-slate-300`,children:n})]}),(0,U.jsx)(`span`,{className:`shrink-0 text-slate-600`,children:`·`}),(0,U.jsx)(`div`,{className:`min-w-0 flex-1 truncate px-2 text-base font-semibold leading-none`,children:e})]}),r?(0,U.jsx)(`button`,{type:`button`,onClick:r,title:`Open selected session in new window`,"aria-label":`Open selected session in new window`,"data-pibo-debug":`open-session-window`,className:`h-full w-7 shrink-0 inline-flex items-center justify-center text-slate-400 hover:bg-[#11a4d4]/10 hover:text-[#11a4d4]`,children:(0,U.jsx)(rl,{size:14})}):null,(0,U.jsx)(`button`,{type:`button`,onClick:i,title:`Show normal top bar`,"aria-label":`Exit Terminal fullscreen`,className:`h-full w-7 shrink-0 inline-flex items-center justify-center text-slate-400 hover:bg-[#11a4d4]/10 hover:text-[#11a4d4]`,children:(0,U.jsx)(Zc,{size:14})})]})}function sPe({enabled:e,onFilesDropped:t,children:n,className:r,...i}){let a=(0,H.useRef)(0),[o,s]=(0,H.useState)(!1),[c,l]=(0,H.useState)(0),u=c>0;(0,H.useEffect)(()=>{e||(a.current=0,s(!1))},[e]);let d=()=>{a.current=0,s(!1)},f=t=>lPe(t.dataTransfer)?(t.preventDefault(),t.stopPropagation(),t.dataTransfer.dropEffect=e&&!u?`copy`:`none`,!0):!1,p=t=>{!f(t)||!e||u||(a.current+=1,s(!0))},m=e=>{f(e)},h=e=>{!f(e)||a.current===0||(a.current=Math.max(0,a.current-1),a.current===0&&s(!1))},g=async n=>{if(!f(n)||(d(),!e||u))return;let r=uPe(n.dataTransfer);if(r.length){l(r.length);try{await t(r)}finally{l(0)}}},_=u?`uploading`:o?`drag-active`:`idle`;return(0,U.jsxs)(`main`,{...i,"data-pibo-file-drop-state":_,className:`relative ${r??``}`,onDragEnter:p,onDragOver:m,onDragLeave:h,onDragEnd:d,onDrop:g,children:[n,o||u?(0,U.jsx)(cPe,{uploadingFileCount:c}):null]})}function cPe({uploadingFileCount:e}){let t=e>0;return(0,U.jsx)(`div`,{"data-pibo-debug":`terminal-file-drop-overlay`,"data-pibo-state":t?`uploading`:`drag-active`,role:`status`,"aria-live":`polite`,className:`pointer-events-none absolute inset-0 z-40 grid place-items-center bg-[#071015]/90 p-6 backdrop-blur-[2px]`,children:(0,U.jsxs)(`div`,{className:`flex max-w-sm flex-col items-center rounded-sm border border-dashed border-[#11a4d4] bg-[#0e1116]/95 px-8 py-7 text-center shadow-2xl shadow-black/50`,children:[t?(0,U.jsx)(Pc,{size:36,className:`mb-3 animate-spin text-[#11a4d4]`,"aria-hidden":`true`}):(0,U.jsx)(Tl,{size:36,className:`mb-3 text-[#11a4d4]`,"aria-hidden":`true`}),(0,U.jsx)(`span`,{className:`text-sm font-semibold text-slate-100`,children:t?`Uploading ${e} file${e===1?``:`s`}…`:`Drop files to upload`}),(0,U.jsx)(`span`,{className:`mt-1 text-xs leading-5 text-slate-400`,children:t?`Saving to the Pibo uploads directory`:`Images and other files will be attached to your next message.`})]})})}function lPe(e){return Array.from(e.types).includes(`Files`)||Array.from(e.items).some(e=>e.kind===`file`)}function uPe(e){return Array.from(e.files)}function dPe({hideComposer:e=!1,auxiliaryPanel:t}){return!e&&!t}function fPe({selectedPiboSessionId:e,selectedRoomId:t,fallbackRoomId:n,sessionViewId:r,loadingTrace:i,roomNavigationPending:a=!1,sessionNavigationPending:o=!1,traceError:s,showRawEvents:c,currentTraceView:l,rawEventLimit:u,tracePageFetching:d,onLoadMoreRawEvents:f,terminalFullscreen:p,fullscreenTopBar:m,fullscreenContent:h,hideComposer:g=!1,terminalFileDropEnabled:_,onTerminalFilesDropped:v,onOpenSessionWindow:y,onExitTerminalFullscreen:b,headerProps:x,auxiliaryPanel:S,currentSessionView:C,sessionViewProps:w,runtimeRequestPanel:T,composerProps:E,containerResponsive:D=!1}){let O=a||o&&!l||i;return(0,U.jsxs)(U.Fragment,{children:[(0,U.jsxs)(sPe,{enabled:_,onFilesDropped:v,"data-pibo-debug":`chat-shell`,"data-pibo-session-id":e??void 0,"data-pibo-room-id":t??n??void 0,"data-pibo-view-id":r,"data-pibo-state":a?`room-loading`:o?`session-loading`:i?`loading`:s?`error`:e?`ready`:`empty`,"data-pibo-terminal-fullscreen":p?`true`:`false`,className:`min-h-0 h-full flex flex-col ${D?`@container`:``}`,children:[p?m??(0,U.jsx)(oPe,{title:x.title,contextKind:x.contextKind,contextLabel:x.contextLabel,onOpenSessionWindow:y,onExit:b}):(0,U.jsx)(rPe,{...x}),p&&h?h:!p&&S?S:O?(0,U.jsx)(pPe,{label:a?`Loading room`:`Loading session`}):s&&!l?(0,U.jsx)(`div`,{className:`min-h-0 flex-1 p-4 text-sm text-red-200`,children:s}):C.render({...w,terminalFullscreen:p}),T,dPe({hideComposer:g,auxiliaryPanel:S})?(0,U.jsx)(zNe,{...E}):null]}),(0,U.jsx)(nX,{traceView:l,eventLimit:u,isFetching:d,visible:c&&!p,onLoadOlder:f})]})}function pPe({label:e}){return(0,U.jsx)(`section`,{"data-pibo-debug":`room-navigation-loading`,className:`relative min-w-0 flex-1 overflow-hidden bg-[#0b0b0b] text-[#d4d4d4]`,"aria-live":`polite`,"aria-label":e,children:(0,U.jsx)(`div`,{className:`min-h-0 h-full overflow-hidden font-mono text-[12px] leading-[1.45]`,children:(0,U.jsxs)(`div`,{className:`px-4`,children:[(0,U.jsx)(`div`,{className:`group border-b border-[#141414] py-2`,children:(0,U.jsxs)(`div`,{className:`grid grid-cols-[1.9rem_minmax(0,1fr)] gap-2 leading-[1.45]`,children:[(0,U.jsx)(`span`,{className:`flex items-center text-[#38bdf8]`,children:(0,U.jsx)(`span`,{className:`h-1.5 w-1.5 rounded-full bg-[#38bdf8] animate-pulse`})}),(0,U.jsxs)(`span`,{className:`flex min-w-0 items-center gap-2`,children:[(0,U.jsx)(`span`,{className:`font-semibold text-[#d4d4d4]`,children:e}),(0,U.jsx)(`span`,{className:`h-2 w-24 rounded-sm bg-[#262626] animate-pulse`})]})]})}),[{kind:`tool`,lines:5},{kind:`markdown`,lines:4},{kind:`command`,lines:4},{kind:`tool`,lines:3},{kind:`markdown`,lines:5}].map((e,t)=>(0,U.jsx)(mPe,{kind:e.kind,lineCount:e.lines},t))]})})})}function mPe({kind:e,lineCount:t}){let n=e===`command`,r=e===`markdown`;return(0,U.jsx)(`div`,{className:`group border-b border-[#141414] py-2 animate-pulse ${n?`bg-[#f59e0b]/5`:``}`,"aria-hidden":`true`,children:Array.from({length:t}).map((e,i)=>(0,U.jsxs)(`div`,{className:`grid grid-cols-[1.9rem_minmax(0,1fr)] gap-2 leading-[1.45]`,children:[(0,U.jsx)(`span`,{className:`flex items-center text-[#737373]`,children:i===0&&!r?(0,U.jsx)(`span`,{className:`h-1.5 w-1.5 rounded-full ${n?`bg-[#f59e0b]`:`bg-[#22c55e]`}`}):i>0&&!r?(0,U.jsx)(`span`,{className:`text-[10px]`,children:`L`}):null}),(0,U.jsx)(`span`,{className:`min-w-0 py-[3px]`,children:i===0?(0,U.jsxs)(`span`,{className:`inline-flex min-w-0 items-center gap-2`,children:[(0,U.jsx)(`span`,{className:`h-[13px] rounded-sm ${r?`w-56 bg-[#d4d4d4]/45`:n?`w-28 bg-[#f59e0b]/65`:`w-24 bg-[#22c55e]/65`}`}),r?null:(0,U.jsx)(`span`,{className:`h-[13px] w-64 rounded-sm bg-[#262626]`})]}):(0,U.jsx)(`span`,{className:`block h-[10px] rounded-sm bg-[#262626] ${i===t-1?`w-[42%]`:i%2==0?`w-[72%]`:`w-[58%]`}`})})]},i))})}var rX=[`a[href]`,`button:not([disabled])`,`input:not([disabled])`,`select:not([disabled])`,`textarea:not([disabled])`,`[tabindex]:not([tabindex="-1"])`].join(`,`);function iX({title:e,description:t,onClose:n,initialFocusRef:r,onKeyDown:i,children:a,closeLabel:o=`Close dialog`,closeDisabled:s=!1,maxWidthClassName:c=`max-w-lg`}){let l=(0,H.useId)(),u=(0,H.useId)(),d=(0,H.useRef)(null);(0,H.useEffect)(()=>{let e=document.activeElement instanceof HTMLElement?document.activeElement:null,t=window.requestAnimationFrame(()=>{(r?.current??d.current?.querySelector(rX)??d.current)?.focus()});return()=>{window.cancelAnimationFrame(t),e?.isConnected&&e.focus()}},[r]);let f=e=>{if(e.key===`Escape`){e.preventDefault(),s||n();return}if(e.key!==`Tab`)return;let t=Array.from(d.current?.querySelectorAll(rX)??[]);if(t.length===0){e.preventDefault(),d.current?.focus();return}let r=t[0],i=t[t.length-1],a=document.activeElement;t.includes(a)?e.shiftKey&&a===r?(e.preventDefault(),i.focus()):!e.shiftKey&&a===i&&(e.preventDefault(),r.focus()):(e.preventDefault(),(e.shiftKey?i:r).focus())};return(0,U.jsx)(`div`,{className:`fixed inset-0 z-50 grid place-items-center bg-black/70 p-2 sm:p-4`,role:`dialog`,"aria-modal":`true`,"aria-labelledby":l,"aria-describedby":u,onClick:e=>{!s&&e.target===e.currentTarget&&n()},onKeyDown:e=>{i?.(e),e.defaultPrevented||f(e)},children:(0,U.jsxs)(`div`,{ref:d,tabIndex:-1,className:`max-h-[calc(100dvh-1rem)] w-full ${c} overflow-y-auto rounded-sm border border-slate-700 bg-[#1a262b] text-slate-200 shadow-2xl outline-none sm:max-h-[calc(100dvh-2rem)]`,children:[(0,U.jsxs)(`div`,{className:`flex items-start justify-between gap-3 border-b border-slate-800 px-4 py-3`,children:[(0,U.jsxs)(`div`,{children:[(0,U.jsx)(`h2`,{id:l,className:`text-sm font-bold uppercase tracking-wider text-slate-100`,children:e}),(0,U.jsx)(`p`,{id:u,className:`mt-1 text-xs text-slate-400`,children:t})]}),(0,U.jsx)(`button`,{type:`button`,onClick:n,disabled:s,"aria-label":o,className:`inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-sm border border-slate-700 text-slate-400 hover:border-[#11a4d4] hover:text-[#11a4d4] disabled:cursor-not-allowed disabled:opacity-50`,children:(0,U.jsx)(jl,{size:14})})]}),a]})})}var hPe=5e3,gPe=0,aX=new Map,_Pe=0;function vPe(e){let t=aX.get(e);return t||(t={snapshots:[],pending:null,pendingTimer:null},aX.set(e,t)),t}function oX(){if(typeof window<`u`&&window.__piboTraceSnapshotCollectionEnabled===!0)return!0;try{return localStorage.getItem(`pibo.chat.traceDebug`)===`true`}catch{return!1}}function yPe(e){let t=0;for(let n of e)for(let e=0;e<n.length;e++)t=(t<<5)-t+n.charCodeAt(e),t|=0;return t.toString(36)}function sX(e){return yPe([JSON.stringify(e)])}function cX(e){return JSON.stringify({trigger:e.trigger,traceVersion:e.traceVersion,baseTraceVersion:e.baseTraceVersion,latestStreamId:e.latestStreamId,lastRawEventId:e.lastRawEventId,selectedSessionStatus:e.selectedSessionStatus,overlayEventCount:e.overlayEventCount,layers:e.layers.map(e=>[e.kind,e.digest])})}function lX(e){if(!e.pending)return;let t=e.pending;if(t.layers.length===0){e.pending=null;return}let n=e.snapshots.at(-1);(!n||cX(n)!==cX(t))&&(e.snapshots.push(t),e.snapshots.length>hPe&&e.snapshots.shift()),e.pending=null}function uX(e){if(!oX())return;let t=vPe(e.piboSessionId);t.pendingTimer&&=(clearTimeout(t.pendingTimer),null);let n=e.layer&&t.pending?.layers?.find(t=>t.kind===e.layer.kind),r=t.pending&&gX(t.pending.traceVersion,e.traceVersion)&&gX(t.pending.baseTraceVersion,e.baseTraceVersion)&&gX(t.pending.latestStreamId,e.latestStreamId)&&gX(t.pending.lastRawEventId,e.lastRawEventId)&&gX(t.pending.selectedSessionStatus,e.selectedSessionStatus)&&gX(t.pending.overlayEventCount,e.overlayEventCount);if(t.pending&&t.pending.trigger===e.trigger&&t.pending.piboSessionId===e.piboSessionId&&r&&(!n||n.digest===e.layer?.digest)||lX(t),t.pending||={sequence:++_Pe,timestamp:Date.now(),piboSessionId:e.piboSessionId,trigger:e.trigger,layers:[],expansionOverrides:e.expansionOverrides,traceVersion:e.traceVersion,baseTraceVersion:e.baseTraceVersion,latestStreamId:e.latestStreamId,lastRawEventId:e.lastRawEventId,selectedSessionStatus:e.selectedSessionStatus,overlayEventCount:e.overlayEventCount},e.layer){let n=t.pending.layers.findIndex(t=>t.kind===e.layer.kind);n>=0?t.pending.layers[n]=e.layer:t.pending.layers.push(e.layer)}e.expansionOverrides!==void 0&&(t.pending.expansionOverrides=e.expansionOverrides),e.traceVersion!==void 0&&(t.pending.traceVersion=e.traceVersion),e.baseTraceVersion!==void 0&&(t.pending.baseTraceVersion=e.baseTraceVersion),e.latestStreamId!==void 0&&(t.pending.latestStreamId=e.latestStreamId),e.lastRawEventId!==void 0&&(t.pending.lastRawEventId=e.lastRawEventId),e.selectedSessionStatus!==void 0&&(t.pending.selectedSessionStatus=e.selectedSessionStatus),e.overlayEventCount!==void 0&&(t.pending.overlayEventCount=e.overlayEventCount),t.pendingTimer=setTimeout(()=>{lX(t),t.pendingTimer=null},gPe)}function dX(e){let t={traceVersion:e.currentTraceView.version,baseTraceVersion:e.baseTraceView?.version,latestStreamId:e.currentTraceView.latestStreamId,lastRawEventId:e.currentTraceView.rawEvents.at(-1)?.id,selectedSessionStatus:e.selectedSessionStatus,overlayEventCount:e.overlayEvents.length};fX(e.piboSessionId,e.trigger,`baseNodes`,e.baseTraceView?.nodes??[],t),bPe(e.piboSessionId,e.trigger,e.overlayEvents,t),fX(e.piboSessionId,e.trigger,`currentNodes`,e.currentTraceView.nodes,t)}function fX(e,t,n,r,i){let a=_X(r).map(wPe);uX({piboSessionId:e,trigger:t,layer:{kind:n,ids:a.map(e=>e.id),digest:sX(a),meta:a},...i})}function bPe(e,t,n,r){let i=n.map(e=>({id:e.id,type:e.type,eventId:e.eventId,eventSequence:e.eventSequence,streamId:e.streamId,streamFrameIndex:e.streamFrameIndex}));uX({piboSessionId:e,trigger:t,layer:{kind:`overlayEvents`,ids:i.map(e=>e.id),digest:sX(i),meta:i},...r})}function xPe(e,t,n,r){let i=n.map(e=>({id:e.id,kind:e.kind,status:e.status,sourceNodeIds:[...e.sourceNodeIds],eventId:e.eventId,runId:e.runId,orderSource:e.orderSource,orderStreamId:e.orderStreamId,orderStreamFrameIndex:e.orderStreamFrameIndex}));uX({piboSessionId:e,trigger:t,layer:{kind:`terminalRows`,ids:i.map(e=>e.id),digest:sX(i),meta:i},...r})}function pX(e){let t=aX.get(e);return t?(lX(t),t.snapshots):[]}function SPe(e){let t=aX.get(e);return t?.pending?.sequence??t?.snapshots.at(-1)?.sequence}function mX(e){if(e)return JSON.stringify({piboSessionId:e,snapshots:pX(e)},null,2);let t={};for(let[e,n]of aX)lX(n),t[e]=n.snapshots;return JSON.stringify(t,null,2)}function CPe(e){if(e){hX(aX.get(e)),aX.delete(e);return}for(let e of aX.values())hX(e);aX.clear()}function hX(e){e?.pendingTimer&&(clearTimeout(e.pendingTimer),e.pendingTimer=null)}function gX(e,t){return t===void 0||e===void 0||e===t}function _X(e){return e.flatMap(e=>[e,..._X(e.children??[])])}function wPe(e){let t=EPe(e);return{id:e.id,type:e.type,status:e.status,parentId:e.parentId,childIds:e.children.map(e=>e.id),entryId:e.entryId,eventId:e.eventId,toolCallId:e.toolCallId,runId:e.runId,stableKey:e.stableKey,source:e.source,orderKey:e.orderKey,contentLength:t.length,contentKind:TPe(t)}}function TPe(e){return e.startsWith(`<pibo_run_notification>`)?`pibo-run-notification`:e.startsWith(`<pibo_goal_continuation>`)?`pibo-goal-continuation`:e.startsWith(`<pibo_`)?`pibo-system`:`message`}function EPe(e){return typeof e.output==`string`?e.output:typeof e.summary==`string`?e.summary:e.output&&typeof e.output==`object`&&`text`in e.output&&typeof e.output.text==`string`?e.output.text:``}typeof window<`u`&&(window.__piboTraceSnapshots={exportAsJson:e=>{let t=mX(e),n=new Blob([t],{type:`application/json`}),r=URL.createObjectURL(n),i=document.createElement(`a`);i.href=r,i.download=`trace-snapshots-${e??`all`}-${Date.now()}.json`,i.click(),URL.revokeObjectURL(r)},getSnapshots:pX,getLatestSequence:SPe,clearSnapshots:CPe,exportSnapshots:mX});function vX(e){let t=!1,n=e.map(e=>e.children.length?(t=!0,{...e,children:vX(e.children)}):e);return DPe(n)?t?n:[...e]:[...n].sort(yX)}function DPe(e){for(let t=1;t<e.length;t+=1)if(yX(e[t-1],e[t])>0)return!1;return!0}function yX(e,t){if(!e.orderKey&&!t.orderKey)return OPe(e,t);let n=Iu(e.orderKey,t.orderKey);return n===0?e.id.localeCompare(t.id):n}function OPe(e,t){let n=bX(e.startedAt),r=bX(t.startedAt);if(n!==r){if(n===void 0)return 1;if(r===void 0)return-1;let e=n.localeCompare(r);if(e!==0)return e}return e.id.localeCompare(t.id)}function bX(e){return e!==void 0&&Number.isFinite(Date.parse(e))?e:void 0}function xX(e){let t=[],n=[...e].reverse();for(;n.length;){let e=n.pop();if(e){t.push(e);for(let t=e.children.length-1;t>=0;--t)n.push(e.children[t])}}return t}function kPe(e){let t=new Map;for(let n of e)t.set(n.id,{...n,children:[...n.children]});let n=new Set;for(let e of t.values()){if(!e.parentId)continue;let r=t.get(e.parentId);r&&(r.children.push(e),n.add(e.id))}return vX([...t.values()].filter(e=>!n.has(e.id)))}var SX=`tool-invocation:`,CX=`history-tool:`,APe=`tool:`,wX=`event-tool`;function TX(e,t,n){let r=JSON.stringify([wX,t,n]);return`${SX}${encodeURIComponent(JSON.stringify([e,r]))}`}function EX(e){if(e.startsWith(APe)){let t=e.slice(5);return t?{toolCallId:t}:void 0}let t=e.startsWith(SX)?SX:e.startsWith(CX)?CX:void 0;if(t)try{let n=JSON.parse(decodeURIComponent(e.slice(t.length)));if(!Array.isArray(n)||n.length!==2||typeof n[0]!=`string`||n[0].length===0||typeof n[1]!=`string`)return;let r=JSON.parse(n[1]);if(!Array.isArray(r)||r.length!==3||r[0]!==wX||typeof r[1]!=`string`||r[1].length===0||!Number.isSafeInteger(r[2])||Number(r[2])<0)return;let i={toolCallId:n[0],qualifier:{eventId:r[1],invocationOrdinal:Number(r[2])}},a=TX(i.toolCallId,i.qualifier.eventId,i.qualifier.invocationOrdinal);return a===e||a.replace(SX,CX)===e?i:void 0}catch{return}}function jPe(e,t,n,r){if(!DX(t))return;let i=NPe(n),a=r.get(e)?.filter(e=>t===`pibo_agents_send_message`?e.metadata?.subagentToolName===t&&(!i||e.metadata?.subagentName===i):e.metadata?.subagentToolName===t)??[],o=PPe(n);return o?a.find(e=>e.metadata?.threadKey===o)?.id:a.length===1?a[0].id:void 0}function DX(e){return e===`pibo_agents_send_message`||e.startsWith(`pibo_subagent_`)}function MPe(e){return e===`pibo_agents_send_message`?`agent`:e.slice(14)}function OX(e){return`args`in e&&e.args&&typeof e.args==`object`&&!Array.isArray(e.args)?e.args:void 0}function NPe(e){let t=OX(e)?.name;return typeof t==`string`&&t.trim()?t.trim():void 0}function PPe(e){let t=OX(e)?.threadKey;return typeof t==`string`&&t.trim()?t.trim():void 0}function kX(e,t,n,r){let i=IPe(e,t,n,r);if(!i)return;let a=e.children.find(e=>e.id===i.id);if(a){LPe(a,i),a.runId=i.runId??a.runId;return}e.children.push(i)}function FPe(e){let t=new Map;for(let n of xX(e)){let e=jX(n.output);if(!e)continue;let r=NX(e.runId);r&&t.set(r,{snapshot:e,completedAt:NX(e.completedAt)??NX(e.updatedAt)??n.completedAt})}for(let n of xX(e)){if(n.type!==`agent.async`||!n.runId)continue;let e=t.get(n.runId);if(!e)continue;let r=NX(e.snapshot.status);(r===`completed`||r===`cancelled`||r===`failed`||r===`timed_out`)&&(n.status=r===`failed`||r===`timed_out`?`error`:`done`,n.completedAt=e.completedAt??n.completedAt,n.output=e.snapshot,(r===`failed`||r===`timed_out`)&&(n.error=NX(e.snapshot.summary)??n.error))}}function IPe(e,t,n,r){if(!AX(e))return;let i=jX(e.output),a=PX(e.input)?e.input:{},o=NX(i?.toolName)??NX(a.toolName)??r?.title;if(!o||!DX(o))return;let s=a.arguments,c=NX(r?.summary)??(PX(s)?NX(s.name):void 0)??MPe(o),l=NX(i?.runId),u=NX(i?.status),d=NX(i?.completionPolicy)??NX(a.completionPolicy);return{id:`${e.id}:async-agent`,parentId:e.id,piboSessionId:t,eventId:e.eventId,toolCallId:e.toolCallId,runId:l,type:`agent.async`,title:c,status:RPe(e,u),startedAt:r?.startedAt??n??e.startedAt,completedAt:u===`completed`||u===`cancelled`||u===`failed`||u===`timed_out`?e.completedAt:void 0,summary:`Started by ${e.title}`,input:{startedBy:e.title,startToolCallId:e.toolCallId,toolName:o,subagentName:c,runId:l,completionPolicy:d,arguments:s,threadKey:PX(r?.input)?r.input.threadKey:void 0},output:i,error:e.error,linkedPiboSessionId:r?.linkedPiboSessionId??e.linkedPiboSessionId,source:e.source,stableKey:l?`async-agent:${l}`:`${e.stableKey??e.id}:async-agent`,orderKey:Fu(e.orderKey,`agent.async`),children:[]}}function AX(e){return e.type===`tool.call`&&e.title===`pibo_run_start`}function LPe(e,t){e.status=t.status,e.summary=t.summary??e.summary,e.input=t.input??e.input,e.output=t.output??e.output,e.error=t.error??e.error,e.completedAt=t.completedAt??e.completedAt,e.linkedPiboSessionId=t.linkedPiboSessionId??e.linkedPiboSessionId}function jX(e){if(PX(e)){if(MX(e))return e;if(PX(e.details)&&MX(e.details))return e.details}}function MX(e){return typeof e.runId==`string`&&typeof e.toolName==`string`}function NX(e){return typeof e==`string`?e:void 0}function RPe(e,t){return e.status===`error`||t===`failed`?`error`:t===`completed`||t===`cancelled`?`done`:`running`}function PX(e){return!!e&&typeof e==`object`&&!Array.isArray(e)}function FX(e){let t=(e??``).trim();if(!t.startsWith(`<pibo_run_notification>`)||!t.endsWith(`</pibo_run_notification>`))return;let n=t.slice(23,t.length-24).trim();try{let e=JSON.parse(n);return!e||typeof e!=`object`||Array.isArray(e)?void 0:e}catch{return}}function zPe(e){let t=BPe(e.notification),n=t.length===1?t[0]:void 0,r=LX(e.notification.failed)+LX(e.notification.timedOut),i=LX(e.notification.running);return{id:e.id,entryId:e.entryId,piboSessionId:e.piboSessionId,eventId:e.eventId,runId:typeof n?.runId==`string`?n.runId:void 0,type:`yielded.run`,title:`Run Notification`,status:r>0?`error`:i>0?`running`:`done`,startedAt:e.startedAt,summary:VPe(e.notification),output:e.notification,source:e.source,stableKey:e.stableKey??e.id,orderKey:e.orderKey,children:[]}}function BPe(e){return[...IX(e.completed),...IX(e.failed),...IX(e.timedOut),...IX(e.cancelled),...IX(e.running)]}function IX(e){return Array.isArray(e)?e.filter(HPe):[]}function LX(e){return Array.isArray(e)?e.length:0}function VPe(e){let t=[[LX(e.completed),`completed`],[LX(e.failed),`failed`],[LX(e.timedOut),`timed out`],[LX(e.cancelled),`cancelled`],[LX(e.running),`running`]].filter(([e])=>Number(e)>0).map(([e,t])=>`${e} ${t}`);return t.length?t.join(`, `):`No yielded run updates`}function HPe(e){return!!e&&typeof e==`object`&&!Array.isArray(e)}function UPe(e,t,n,r,i,a,o,s,c){let l=r.payload;if(l.type===`message_started`&&l.source===`user`&&l.eventId){let t=xX([...e]).find(e=>e.type===`user.message`&&VX(e.source)&&e.eventId===l.eventId);t&&zX(t,r,l)}let u=o.mode===`none`?void 0:BX(e,r);if(u){zX(u,r,l),l.type===`message_steered`&&l.activeEventId&&(u.parentId=XX(l.activeEventId));return}if((o.mode===`native`&&dFe(l)||o.mode===`product`&&uFe(l))&&KX(l,o)&&!fFe(l,s)){RX(t,r,l);return}if(pFe(l,o,c)){RX(t,r,l);return}if(l.type===`assistant_delta`){aFe(e,t,l,c,r.createdAt,r.eventSequence,r.streamId,r.streamFrameIndex,r.traceSource,r.id);return}if(l.type===`thinking_delta`){oFe(e,t,l,c,r.createdAt,r.eventSequence,r.streamId,r.streamFrameIndex,r.traceSource,r.id);return}if(l.type===`assistant_message`){let i=KPe(n,l,r.createdAt,r.eventSequence,r.streamId,r.streamFrameIndex,r.traceSource,r.id),a=t.get(i.id)??WX(t,i);if(a){GX(a,i);return}e.push(i),t.set(i.id,i);return}let d=iFe(n,l,i,a,c,r.createdAt,r.eventSequence,r.streamId,r.streamFrameIndex,r.traceSource,r.id);if(d){if(GPe(d,l,r.storedPayloadRef),l.type===`session_error`&&l.eventId&&(d.parentId=YPe(t,l.eventId,l,r.createdAt)),d.type===`user.message`&&d.status===`running`&&!d.parentId&&l.type===`message_steered`){let e=[...t.values()].reverse().find(e=>e.type===`agent.turn`&&e.status===`running`);e&&(d.parentId=e.id)}if(d.type===`agent.turn`&&d.eventId){let e=[...t.values()].find(e=>e.type===`agent.turn`&&e.eventId===d.eventId);if(e){e.status=d.status,e.completedAt=d.completedAt??e.completedAt;return}}if(d.type===`assistant.message`){let e=t.get(d.id)??WX(t,d);if(e){GX(e,d);return}}if(d.type===`execution.compaction`){let t=_Fe(e);if(t){vFe(t,d);return}}if(d.type===`model.reasoning`){let e=t.get(d.id)??WX(t,d);if(e){sFe(e,d);return}}if(d.type===`agent.delegation`&&!d.toolCallId&&d.linkedPiboSessionId){let e=gFe([...t.values()],d);if(e){hFe(e,d);return}}if(d.toolCallId){let e=t.get(d.id)??WPe(t,d,l);if(e){if(AX(e)&&d.type===`agent.delegation`){kX(e,n,r.createdAt,d);return}mFe(e,d),kX(e,n,r.createdAt);return}}if(d.eventId){let e=t.get(d.id);if(e){d.type===`user.message`?(e.status=d.status,e.parentId=d.parentId??e.parentId,e.summary=d.summary??e.summary,e.output=d.output??e.output):d.type===`execution.command`&&(e.status=d.status,e.output=d.output??e.output,e.error=d.error??e.error,e.completedAt=d.completedAt??e.completedAt);return}}qPe(d,t),kX(d,n,r.createdAt),e.push(d);for(let e of xX([d]))t.set(e.id,e)}}function WPe(e,t,n){if(`eventId`in n&&n.eventId)return;let r=[...e.values()].filter(e=>e.toolCallId===t.toolCallId&&(e.type===`tool.call`||e.type===`tool.result`||e.type===`agent.delegation`));return r.length===1?r[0]:void 0}function RX(e,t,n){let r=YX(n,aZ(t.eventSequence,t.streamId,n,t.id)),i=`eventId`in n&&typeof n.eventId==`string`?n.eventId:void 0,a=[...e.values()].find(e=>e.stableKey===r||`toolCallId`in n&&typeof n.toolCallId==`string`&&e.toolCallId===n.toolCallId&&(!i||!e.eventId||e.eventId===i));a&&zX(a,t,n)}function zX(e,t,n){let r=t.renderSequence??n.renderSequence,i=t.eventSequence??t.streamId;(r!==void 0||i!==void 0)&&(e.orderKey={...e.orderKey??Mu(i,JX(n.type)),...i===void 0?{}:{turnSeq:i,eventSequence:i},...r===void 0?{}:{renderSequence:r}})}function GPe(e,t,n){n&&((t.type===`tool_call`||t.type===`tool_execution_started`)&&(e.payloadRefs={...e.payloadRefs,input:n}),(t.type===`tool_execution_finished`||t.type===`tool_execution_updated`)&&(e.payloadRefs={...e.payloadRefs,output:n}))}function KPe(e,t,n,r,i,a,o,s){let c=typeof t.eventId==`string`?t.eventId:void 0,l=QX(t),u=aZ(r,i,t,s);return{id:l?ZX(l):`event:${t.type}:${u}`,piboSessionId:e,eventId:c,parentId:c?XX(c):void 0,type:`assistant.message`,title:`Agent Message`,status:`done`,startedAt:n,completedAt:n,summary:t.text,output:t.text,source:`event-log`,stableKey:l?`assistant:${l}`:YX(t,u),orderKey:qX(r,t.type,i,a,o,t.renderSequence,n),children:[]}}function qPe(e,t){if(e.type!==`execution.command`||e.parentId&&t.has(e.parentId))return;let n=[...t.values()].filter(n=>{if(n.type!==`agent.turn`||!n.startedAt||!e.startedAt||n.startedAt>e.startedAt)return!1;let r=JPe(n,t);return r===void 0||e.startedAt<=r}).sort(yX).at(-1);n&&(e.parentId=n.id)}function JPe(e,t){return e.completedAt?e.completedAt:[...t.values()].filter(t=>t.type===`error`&&t.eventId!==void 0&&t.eventId===e.eventId&&t.startedAt!==void 0).sort(yX).at(0)?.startedAt}function YPe(e,t,n,r){let i=XX(t),a=e.get(i)??[...e.values()].find(e=>e.type===`agent.turn`&&e.eventId===t);if(a)return a.status=`error`,a.completedAt=r??a.completedAt,a.summary=n.errorDetails?.userMessage??n.error,a.error=n.error,XPe(e,a.id,n.error,r),a.id}function XPe(e,t,n,r){for(let i of e.values()){if(i.parentId!==t)continue;let e=i.status===`running`&&(i.type===`assistant.message`||i.type===`model.reasoning`||i.type===`tool.call`),a=i.type===`tool.call`&&i.completedAt===void 0;!e&&!a||(i.status=`error`,i.completedAt=r,i.error=n)}}function ZPe(e){return e.some(e=>{let t=e.payload.type;return t!==`assistant_delta`&&t!==`thinking_delta`})}function QPe(e){if(e.type===`assistant_delta`){if(e.text.length===0)return;let t=QX(e);return t?ZX(t):void 0}if(e.type===`thinking_delta`){if(e.text.length===0)return;let t=eZ(e);return t?$X(t):void 0}}function $Pe(e,t){return!!BX(e,t)}function BX(e,t){let n=t.payload;if(n.type!==`message_queued`&&n.type!==`message_steered`||n.source!==`user`)return;let r=typeof n.eventId==`string`?n.eventId:void 0,i=r??t.eventId,a=t.id?`instance:${t.id}`:sZ(n),o=`event:${n.type}:${r??a}`,s=YX(n,a),c=typeof n.text==`string`?n.text:void 0,l=xX([...e]).filter(e=>e.type===`user.message`&&VX(e.source));return l.find(e=>eFe(e,o,s,i))||l.find(e=>!tFe(e)&&!!(c&&nFe(e)===c))}function VX(e){return e===`transcript`||e===`product-history`}function eFe(e,t,n,r){return e.id===t||e.stableKey===n?!0:r?e.entryId===r||e.stableKey===`entry:${r}`||[e.id,e.stableKey].some(e=>HX(e)===r):!1}function tFe(e){return[e.id,e.stableKey].some(e=>HX(e)!==void 0)}function HX(e){for(let t of[`event:message_queued:`,`event:message_steered:`])if(e?.startsWith(t))return e.slice(t.length)}function nFe(e){if(typeof e.output==`string`)return e.output;if(typeof e.summary==`string`)return e.summary}function UX(e){if(e.streamId!==void 0){let t=e.payload;return e.streamFrameIndex===void 0?`stream:${e.streamId}:${t.type}`:`stream:${e.streamId}:${e.streamFrameIndex}:${t.type}`}return e.eventSequence===void 0?`id:${e.id}`:`sequence:${e.piboSessionId??``}:${e.eventSequence}`}function rFe(e,t){let n=t;for(let t of e)t.streamId!==void 0&&(n=n===void 0?t.streamId:Math.max(n,t.streamId));return n}function iFe(e,t,n,r,i,a,o,s,c,l,u){let d=`eventId`in t&&typeof t.eventId==`string`?t.eventId:void 0,f=aZ(o,s,t,u),p=`event:${t.type}:${d??f}`,m=d?XX(d):void 0,h={id:p,piboSessionId:e,eventId:d,startedAt:a,source:`event-log`,stableKey:YX(t,f),orderKey:qX(o,t.type,s,c,l,t.renderSequence,a),children:[]};switch(t.type){case`message_queued`:case`message_steered`:{let n=FX(t.text);return t.source===`service`&&n?zPe({id:p,piboSessionId:e,eventId:d,startedAt:a,source:`event-log`,stableKey:d?`run-notification:${d}`:p,orderKey:qX(o,t.type,s,c,l,t.renderSequence,a),notification:n}):{...h,...t.type===`message_steered`&&t.activeEventId?{parentId:XX(t.activeEventId)}:{},type:`user.message`,title:`User Message`,status:cFe(t)?`running`:`done`,summary:t.text,output:t.text}}case`message_started`:case`message_finished`:return{...h,id:d?XX(d):p,type:`agent.turn`,startedAt:t.type===`message_started`?a:void 0,title:`Agent Turn`,status:t.type===`message_finished`||i!==`running`?`done`:`running`,completedAt:t.type===`message_finished`?a:void 0,stableKey:d?`turn:${d}`:h.stableKey};case`thinking_finished`:{if(!yFe(t.text))return;let e=eZ(t);return{...h,id:e?$X(e):p,parentId:m,type:`model.reasoning`,title:`Thinking`,status:`done`,summary:t.text,output:t.text,stableKey:e?`reasoning:${e}`:h.stableKey}}case`assistant_message`:{let e=QX(t);return{...h,id:e?ZX(e):p,parentId:m,type:`assistant.message`,title:`Agent Message`,status:`done`,completedAt:a,summary:t.text,output:t.text,stableKey:e?`assistant:${e}`:h.stableKey}}case`tool_call`:case`tool_execution_started`:case`tool_execution_updated`:case`tool_execution_finished`:{let o=oZ(t),s=DX(t.toolName),c=r.get(o)??(s?jPe(e,t.toolName,t,n):void 0);return{...h,id:o,parentId:m,toolCallId:t.toolCallId,toolInvocationOrdinal:t.toolInvocationOrdinal??0,intent:t.intent,toolMetrics:t.type===`tool_execution_finished`?t.toolMetrics:void 0,type:s?`agent.delegation`:`tool.call`,title:t.toolName,status:t.type===`tool_execution_finished`?t.isError?`error`:`done`:i===`running`&&(t.type===`tool_execution_started`||t.type===`tool_execution_updated`)?`running`:`done`,completedAt:t.type===`tool_execution_finished`?a:void 0,input:`args`in t?t.args:void 0,output:t.type===`tool_execution_finished`?t.result:t.type===`tool_execution_updated`?t.partialResult:void 0,error:t.type===`tool_execution_finished`&&t.isError?bFe(t.result):void 0,linkedPiboSessionId:c,stableKey:o,children:[]}}case`subagent_session`:{let e=xFe(t.childPiboSessionId),n=aZ(o,s,t,u),r=t.toolCallId?oZ(t):void 0;return{...h,id:r??`event:subagent_session:${n}`,eventId:d,toolCallId:t.toolCallId,toolInvocationOrdinal:t.toolInvocationOrdinal,type:`agent.delegation`,title:t.toolName,status:i===`running`?`running`:`done`,summary:t.subagentName,input:{subagentName:t.subagentName,threadKey:t.threadKey},linkedPiboSessionId:e,stableKey:r||(e?`subagent:${e}`:`subagent:event:${n}`),children:[]}}case`execution_result`:return lFe(t.action)?void 0:{...h,type:`execution.command`,title:t.action,status:`done`,input:{action:t.action},output:t.result};case`compaction_start`:{let e=aZ(o,s,t,u);return{...h,id:`event:compaction:${e}`,type:`execution.compaction`,title:`compact`,status:`running`,summary:`Compacting`,input:{reason:t.reason},stableKey:`compaction:${e}`}}case`compaction_end`:{let e=aZ(o,s,t,u);return{...h,id:`event:compaction:end:${e}`,type:`execution.compaction`,title:`compact`,status:t.errorMessage?`error`:`done`,completedAt:a,summary:t.aborted?`Compaction skipped`:t.errorMessage?`Compaction failed`:`Compacted`,input:{reason:t.reason},output:t.result,error:t.errorMessage,stableKey:`compaction:${e}`}}case`session_error`:return{...h,type:`error`,title:`Session Error`,status:`error`,summary:t.errorDetails?.userMessage,input:t.errorDetails,error:t.error,output:t.error};default:return}}function aFe(e,t,n,r,i,a,o,s,c,l){if(typeof n.text!=`string`||n.text.length===0)return;let u=QX(n),d=aZ(a,o,n,l),f=u?ZX(u):`event:assistant_delta:${d}`,p=t.get(f);if(p){let e=`${typeof p.output==`string`?p.output:``}${n.text}`;p.status=r===`running`?`running`:`done`,p.summary=e,p.output=e;return}let m={id:f,parentId:n.eventId?XX(n.eventId):void 0,piboSessionId:n.piboSessionId,eventId:n.eventId,type:`assistant.message`,title:`Agent Message`,status:r===`running`?`running`:`done`,startedAt:i,summary:n.text,output:n.text,source:`event-log`,stableKey:u?`assistant:${u}`:f,orderKey:qX(a,n.type,o,s,c,n.renderSequence,i),children:[]};e.push(m),t.set(m.id,m)}function WX(e,t){if(t.stableKey)return[...e.values()].find(e=>e.type===t.type&&e.stableKey===t.stableKey)}function GX(e,t){e.status=t.status,e.summary=t.summary??e.summary,e.output=t.output??e.output,e.error=t.error??e.error,e.completedAt=t.completedAt??e.completedAt}function oFe(e,t,n,r,i,a,o,s,c,l){if(typeof n.text!=`string`||n.text.length===0)return;let u=eZ(n),d=aZ(a,o,n,l),f=u?$X(u):`event:thinking_delta:${d}`,p=u?`reasoning:${u}`:f,m=t.get(f)??[...t.values()].find(e=>e.type===`model.reasoning`&&e.stableKey===p);if(m){let e=`${typeof m.output==`string`?m.output:``}${n.text}`;m.status=r===`running`?`running`:`done`,m.summary=e,m.output=e;return}let h={id:f,parentId:n.eventId?XX(n.eventId):void 0,piboSessionId:n.piboSessionId,eventId:n.eventId,type:`model.reasoning`,title:`Thinking`,status:r===`running`?`running`:`done`,startedAt:i,summary:n.text,output:n.text,source:`event-log`,stableKey:p,orderKey:qX(a,n.type,o,s,c,n.renderSequence,i),children:[]};e.push(h),t.set(h.id,h)}function sFe(e,t){e.status=t.status,e.summary=t.summary??e.summary,e.output=t.output??e.output,e.completedAt=t.completedAt??e.completedAt}function cFe(e){return(e.type===`message_queued`||e.type===`message_steered`)&&`clientTxnId`in e&&typeof e.clientTxnId==`string`}function lFe(e){return e===`session.fork`||e===`session.clone`||e===`session.switch`}function uFe(e){return e.type===`assistant_delta`||e.type===`assistant_message`}function dFe(e){return e.type===`message_queued`||e.type===`message_started`||e.type===`message_finished`||e.type===`assistant_delta`||e.type===`assistant_message`||e.type===`thinking_started`||e.type===`thinking_delta`||e.type===`thinking_finished`}function fFe(e,t){let n=`eventId`in e&&typeof e.eventId==`string`?e.eventId:void 0;return!!(n&&t.has(n))}function KX(e,t){let n=`eventId`in e&&typeof e.eventId==`string`?e.eventId:void 0;return n===void 0||t.eventIds.has(n)}function pFe(e,t,n){return t.mode!==`native`||n===`running`||e.type!==`tool_call`&&e.type!==`tool_execution_started`&&e.type!==`tool_execution_updated`&&e.type!==`tool_execution_finished`||typeof e.intent==`string`&&e.intent.trim()?!1:t.toolCallIds.has(e.toolCallId)||KX(e,t)}function qX(e,t,n,r,i,a,o){let s=i===`live`?Nu(n,r,JX(t)):Mu(e??n,JX(t)),c=(a!==void 0&&a>=9466848e8?Math.floor(a/1e3):void 0)??(o&&Number.isFinite(Date.parse(o))?Date.parse(o):void 0);return{...s,...a===void 0?{}:{renderSequence:a},...c===void 0?{}:{chronologyMs:c}}}function JX(e){switch(e){case`message_queued`:case`message_steered`:return`user.message`;case`message_started`:case`message_finished`:return`agent.turn`;case`thinking_started`:case`thinking_delta`:case`thinking_finished`:return`model.reasoning`;case`tool_call`:case`tool_execution_started`:case`tool_execution_updated`:case`tool_execution_finished`:case`subagent_session`:return`tool.call`;case`assistant_delta`:case`assistant_message`:return`assistant.message`;case`execution_result`:return`execution.command`;case`compaction_start`:case`compaction_end`:return`execution.compaction`;case`session_error`:return`error`;default:return`execution.command`}}function YX(e,t){let n=`eventId`in e&&typeof e.eventId==`string`?e.eventId:void 0;if(e.type===`tool_call`||e.type===`tool_execution_started`||e.type===`tool_execution_updated`||e.type===`tool_execution_finished`||e.type===`subagent_session`&&e.toolCallId)return oZ(e);if(n&&(e.type===`message_started`||e.type===`message_finished`))return`turn:${n}`;if(e.type===`thinking_started`||e.type===`thinking_delta`||e.type===`thinking_finished`){let t=eZ(e);if(t)return`reasoning:${t}`}if(e.type===`assistant_delta`||e.type===`assistant_message`){let t=QX(e);if(t)return`assistant:${t}`}return`event:${e.type}:${n??t??sZ(e)}`}function XX(e){return`event:message:${e}`}function ZX(e){return`event:assistant:${e}`}function QX(e){if(!e.eventId)return;let t=typeof e.assistantIndex==`number`?e.assistantIndex:e.contentIndex;return typeof t==`number`?`${e.eventId}:assistant:${t}`:e.eventId}function $X(e){return`event:thinking:${e}`}function eZ(e){if(!e.eventId)return;let t=typeof e.thinkingIndex==`number`?e.thinkingIndex:e.contentIndex;return typeof t==`number`?`${e.eventId}:thinking:${t}`:e.eventId}function mFe(e,t){e.status=t.status,e.intent=t.intent??e.intent,e.toolMetrics=t.toolMetrics??e.toolMetrics,e.summary=t.summary??e.summary,e.input=rZ(e,t),e.output=t.output??e.output,e.error=t.error??e.error,e.completedAt=t.completedAt??e.completedAt,e.payloadRefs={...e.payloadRefs,...t.payloadRefs},e.linkedPiboSessionId=t.linkedPiboSessionId??e.linkedPiboSessionId}function hFe(e,t){e.summary=t.summary??e.summary,e.input=rZ(e,t),e.linkedPiboSessionId=t.linkedPiboSessionId??e.linkedPiboSessionId}function gFe(e,t){let n=[...e].reverse().filter(e=>e.type===`agent.delegation`),r=tZ(t),i=n.filter(e=>!e.linkedPiboSessionId&&tZ(e)===r),a=nZ(t.input);return(a?i.find(e=>nZ(e.input)===a):i.length===1?i[0]:void 0)||n.find(e=>e.linkedPiboSessionId===t.linkedPiboSessionId)}function tZ(e){let t=iZ(e.input)?e.input:void 0,n=typeof t?.name==`string`?t.name:typeof t?.subagentName==`string`?t.subagentName:e.summary??e.title;return typeof n==`string`&&n.replace(/^pibo_agents_send_message$/,`agent`).replace(/^pibo_subagent_/,``).trim().toLowerCase()||void 0}function nZ(e){if(!(!iZ(e)||typeof e.threadKey!=`string`))return e.threadKey.trim()||void 0}function rZ(e,t){return e.type!==`agent.delegation`||!iZ(e.input)||!iZ(t.input)?t.input??e.input:Object.fromEntries(Object.entries({...e.input,...t.input}).filter(([,e])=>e!==void 0))}function iZ(e){return!!e&&typeof e==`object`&&!Array.isArray(e)}function _Fe(e){return xX([...e]).reverse().find(e=>e.type===`execution.compaction`&&e.status===`running`)}function vFe(e,t){e.status=t.status,e.summary=t.summary??e.summary,e.input=t.input??e.input,e.output=t.output??e.output,e.error=t.error??e.error,e.completedAt=t.completedAt??e.completedAt}function yFe(e){return typeof e==`string`&&e.trim().length>0}function bFe(e){if(typeof e==`string`)return e;try{return JSON.stringify(e)}catch{return String(e)}}function aZ(e,t,n,r){return e===void 0?t===void 0?r?`instance:${r}`:sZ(n):`stream:${t}`:`sequence:${e}`}function oZ(e){let t=e.eventId??(e.renderSequence===void 0?`unscoped`:`render:${e.renderSequence}`);return TX(e.toolCallId??`unlinked`,t,e.toolInvocationOrdinal??0)}function xFe(e){if(typeof e==`string`)return e.trim()||void 0}function sZ(e){let t=cZ.get(e);if(t)return t;let n=`live:${++SFe}`;return cZ.set(e,n),n}var cZ=new WeakMap,SFe=0;function CFe(e){let t=new Map;for(let n of e)t.set(n.id,n);let n=[];for(let r of e){if(!r.parentId){n.push(r);continue}let e=t.get(r.parentId);e?e.children.push(r):n.push(r)}return vX(n)}function wFe(e,t,n){return t.map(t=>lZ(e,t,n))}function lZ(e,t,n){let r=e.get(t.id);if(t.children.length===0){let e=r!==void 0&&r.children.length===0;return r&&e&&(n&&!n.has(t.id)||uZ(r,t))?r:e?{...t,children:r.children}:{...t,children:[]}}let i=t.children.map(t=>lZ(e,t,n)),a=r!==void 0&&r.children.length===i.length&&r.children.every((e,t)=>e===i[t]);return r&&a&&(n&&!n.has(t.id)||uZ(r,t))?r:a?{...t,children:r?.children??i}:{...t,children:i}}function uZ(e,t){return e.id===t.id&&e.parentId===t.parentId&&e.entryId===t.entryId&&e.piboSessionId===t.piboSessionId&&e.eventId===t.eventId&&e.toolCallId===t.toolCallId&&e.toolInvocationOrdinal===t.toolInvocationOrdinal&&e.runId===t.runId&&e.intent===t.intent&&e.type===t.type&&e.title===t.title&&e.status===t.status&&e.startedAt===t.startedAt&&e.completedAt===t.completedAt&&e.durationMs===t.durationMs&&e.toolMetrics?.durationMs===t.toolMetrics?.durationMs&&e.toolMetrics?.inputTokens===t.toolMetrics?.inputTokens&&e.toolMetrics?.outputTokens===t.toolMetrics?.outputTokens&&e.toolMetrics?.tokenBasis===t.toolMetrics?.tokenBasis&&e.summary===t.summary&&e.input===t.input&&e.output===t.output&&e.error===t.error&&e.linkedPiboSessionId===t.linkedPiboSessionId&&e.source===t.source&&e.stableKey===t.stableKey&&TFe(e.orderKey,t.orderKey)}function TFe(e,t){return e===t?!0:!e||!t?!1:e.sourceRank===t.sourceRank&&e.turnSeq===t.turnSeq&&e.renderSequence===t.renderSequence&&e.transcriptIndex===t.transcriptIndex&&e.contentPartIndex===t.contentPartIndex&&e.eventSequence===t.eventSequence&&e.streamId===t.streamId&&e.streamFrameIndex===t.streamFrameIndex&&e.phaseRank===t.phaseRank}function dZ(e,t,n){if(!t.length)return e;let r=new Set(e.rawEvents.map(e=>UX(e))),i=[];for(let e of t){let t=UX(e);r.has(t)||(r.add(t),i.push(e))}if(!i.length)return e;let a=xX(e.nodes),o=[],s=new Map,c=new Map;for(let e of a){c.set(e.id,e);let t={...e,children:[]};o.push(t),s.set(t.id,t)}let l=new Map,u=new Map,d=new Set,f={mode:`none`,eventIds:new Set,toolCallIds:new Set},p=[],m=new Set;for(let t of i){if($Pe(o,t))continue;p.push(t);let r=QPe(t.payload);m&&r?m.add(r):m=void 0,UPe(o,s,e.piboSessionId,t,l,u,f,d,n)}if(!p.length)return e;let h=CFe(o);ZPe(p)&&FPe(h);let g=wFe(c,h,m);return{...e,rawEvents:e.rawEvents.length?[...e.rawEvents,...p]:p,nodes:g,latestStreamId:rFe(p,e.latestStreamId)}}function fZ(e){let t=new Map;if(mZ(e.nodes,t),!t.size)return e;let{nodes:n,changed:r}=hZ(e.nodes,t);return r?{...e,nodes:n}:e}function EFe(e){return e.some(pZ)}function DFe(e){let t=new Map;return _Z(e,e=>{if(e.type!==`user.message`||!e.entryId)return;let n=vZ(e),r=t.get(n);r?r.push(e.entryId):t.set(n,[e.entryId])}),t}function OFe(e,t){if(!t.size)return;let n=new Map;_Z(e,e=>{if(e.type!==`user.message`||!e.entryId)return;let t=vZ(e),r=n.get(t)??new Set;r.add(e.entryId),n.set(t,r)});let r=new Map;_Z(e,e=>{if(e.type!==`user.message`||e.entryId)return;let i=vZ(e),a=t.get(i);if(!a?.length)return;let o=n.get(i)??new Set,s=r.get(i)??0;for(;s<a.length&&o.has(a[s]);)s+=1;let c=a[s];c&&(e.entryId=c,o.add(c),n.set(i,o),r.set(i,s+1))})}function pZ(e){let t=e.payload;return!!(t&&typeof t==`object`&&!Array.isArray(t)&&`type`in t&&(t.type===`message_queued`||t.type===`message_steered`)&&`source`in t&&t.source===`user`&&`text`in t&&typeof t.text==`string`)}function mZ(e,t){for(let n of e){if(n.type===`user.message`&&!gZ(n)&&!kFe(n)){let e=vZ(n);e&&t.set(e,(t.get(e)??0)+1)}mZ(n.children,t)}}function hZ(e,t){let n=!1,r=[];for(let i of e){if(gZ(i)){let e=vZ(i),r=e?t.get(e)??0:0;if(r>0){t.set(e,r-1),n=!0;continue}}let e=hZ(i.children,t);n||=e.changed,r.push(e.changed?{...i,children:e.nodes}:i)}return{nodes:n?r:e,changed:n}}function kFe(e){return[e.id,e.stableKey].some(e=>e?.startsWith(`event:message_queued:`)||e?.startsWith(`event:message_steered:`))}function gZ(e){return e.type===`user.message`?e.source===`event-log`&&(e.id.startsWith(`event:message_queued:`)||e.id.startsWith(`event:message_steered:`))?!0:[e.id,e.stableKey,e.eventId].filter(e=>typeof e==`string`).some(e=>e.startsWith(`optimistic:user-message:`)||e.includes(`:optimistic:user-message:`)):!1}function _Z(e,t){for(let n of e)t(n),_Z(n.children,t)}function vZ(e){return typeof e.output==`string`?e.output:typeof e.summary==`string`?e.summary:``}function AFe(e,t,n){return t&&e.set(t.piboSessionId,t),n?e.get(n)??null:null}function yZ(e,t,n){t&&t.piboSessionId!==n.piboSessionId&&e.set(t.piboSessionId,t);let r=bZ(t?.piboSessionId===n.piboSessionId?t:e.get(n.piboSessionId)??null,n);return r?e.set(n.piboSessionId,r):e.delete(n.piboSessionId),r}function bZ(e,t){if(!e||e.piboSessionId!==t.piboSessionId)return e;let n=MFe(t),r=xZ(t.nodes),i=e.events.filter(e=>{let i=wZ(e);if(i&&n.has(i))return!1;if(pZ(e)){let t=r.get(e.payload.text)??0;if(t>0)return t===1?r.delete(e.payload.text):r.set(e.payload.text,t-1),!1}return!NFe(t,e)});return i.length?{...e,events:i}:null}function xZ(e){let t=new Map;for(let n of e){if(n.type===`user.message`&&CZ(n)&&!jFe(n)){let e=FFe(n);e&&t.set(e,(t.get(e)??0)+1)}for(let[e,r]of xZ(n.children))t.set(e,(t.get(e)??0)+r)}return t}function jFe(e){return[e.id,e.stableKey].some(e=>e?.startsWith(`event:message_queued:`)||e?.startsWith(`event:message_steered:`))}function MFe(e){let t=new Set;for(let n of e.rawEvents){let e=wZ(n);e&&t.add(e)}return SZ(e.nodes,t),t}function SZ(e,t){for(let n of e){if(n.type===`user.message`)for(let e of[`message_queued`,`message_steered`]){let r=`event:${e}:`,i=n.id.startsWith(r)?n.id.slice(r.length):void 0;i&&t.add(`${n.piboSessionId}:${e}:${i}`),CZ(n)&&n.entryId&&t.add(`${n.piboSessionId}:${e}:${n.entryId}`)}if(n.type===`assistant.message`){let e=TZ(n,`assistant:`);e&&(t.add(`${n.piboSessionId}:assistant_delta:${e}`),(CZ(n)||n.completedAt!==void 0)&&t.add(`${n.piboSessionId}:assistant_message:${e}`)),CZ(n)&&n.eventId&&(t.add(`${n.piboSessionId}:message_started:${n.eventId}`),t.add(`${n.piboSessionId}:message_finished:${n.eventId}`))}if(n.type===`model.reasoning`){let e=TZ(n,`reasoning:`);e&&(t.add(`${n.piboSessionId}:thinking_delta:${e}`),CZ(n)&&(t.add(`${n.piboSessionId}:thinking_started:${e}`),t.add(`${n.piboSessionId}:thinking_finished:${e}`)))}if(n.toolCallId&&(n.type===`tool.call`||n.type===`tool.result`||n.type===`agent.delegation`)){let e=EX(n.id),r=e?.qualifier?TX(e.toolCallId,e.qualifier.eventId,e.qualifier.invocationOrdinal):TX(n.toolCallId,n.eventId??`unscoped`,n.toolInvocationOrdinal??0);t.add(`${n.piboSessionId}:tool_call:${r}`);let i=n.completedAt!==void 0||n.type===`tool.result`||n.status===`error`;(n.status===`running`||n.output!==void 0||i)&&t.add(`${n.piboSessionId}:tool_execution_started:${r}`),(n.output!==void 0&&!i||i)&&t.add(`${n.piboSessionId}:tool_execution_updated:${r}`),i&&t.add(`${n.piboSessionId}:tool_execution_finished:${r}`)}SZ(n.children,t)}}function CZ(e){return e.source===`transcript`||e.source===`product-history`}function NFe(e,t){let n=t.payload;if(!n||typeof n!=`object`||Array.isArray(n))return!1;let r=`source`in n?n.source:void 0,i=`text`in n?n.text:void 0;return r!==`service`||typeof i!=`string`||!FX(i)?!1:PFe(e,t)}function PFe(e,t){let n=t.eventSequence;if(n===void 0||e.firstEventSequence===void 0)return!1;let r=e.lastEventSequence??e.eventCount;return r!==void 0&&n>=e.firstEventSequence&&n<=r}function wZ(e){let t=e.payload;if(!t||typeof t!=`object`||Array.isArray(t))return;let n=`eventId`in t&&typeof t.eventId==`string`?t.eventId:e.eventId,r=`piboSessionId`in t&&typeof t.piboSessionId==`string`?t.piboSessionId:e.piboSessionId;if(r){if(e.type===`tool_call`||e.type===`tool_execution_started`||e.type===`tool_execution_updated`||e.type===`tool_execution_finished`){let i=`toolCallId`in t&&typeof t.toolCallId==`string`?t.toolCallId:void 0;if(!i)return;let a=EZ(t,`toolInvocationOrdinal`)??0,o=n??(e.renderSequence===void 0?`unscoped`:`render:${e.renderSequence}`);return`${r}:${e.type}:${TX(i,o,a)}`}if(n){if(e.type===`assistant_delta`||e.type===`assistant_message`){let i=EZ(t,`assistantIndex`)??EZ(t,`contentIndex`),a=i===void 0?n:`${n}:assistant:${i}`;return`${r}:${e.type}:${a}`}if(e.type===`thinking_started`||e.type===`thinking_delta`||e.type===`thinking_finished`){let i=EZ(t,`thinkingIndex`)??EZ(t,`contentIndex`),a=i===void 0?n:`${n}:thinking:${i}`;return`${r}:${e.type}:${a}`}return`${r}:${e.type}:${n}`}}}function TZ(e,t){return e.stableKey?.startsWith(t)?e.stableKey.slice(t.length):e.eventId}function EZ(e,t){let n=t in e?e[t]:void 0;return typeof n==`number`&&Number.isFinite(n)?n:void 0}function FFe(e){return typeof e.output==`string`?e.output:e.output&&typeof e.output==`object`&&`text`in e.output&&typeof e.output.text==`string`?e.output.text:``}function IFe({selectedPiboSessionId:e,reconciledBaseTraceView:t,liveTraceOverlay:n,selectedSessionStatus:r,persistedUserMessageIndexForBaseTrace:i,now:a,previousProjection:o}){if(!e||t?.piboSessionId!==e)return{traceView:null};let s=(n?.piboSessionId===e?bZ(n,t):null)?.events??[];if(!s.length)return{traceView:t};let c=a?.(),l=r??`idle`,u=o?.baseTraceView===t&&o.sessionStatus===l&&s.length>=o.overlayEvents.length&&o.overlayEvents.every((e,t)=>s[t]===e),d=u?s.slice(o.overlayEvents.length):s,f=u?dZ(o.traceView,d,l):dZ(t,s,l),p=EFe(s);p&&OFe(f.nodes,i);let m=p?fZ(f):f;return{traceView:m,appliedLiveEventCount:d.length,projectionCache:{baseTraceView:t,overlayEvents:s,sessionStatus:l,traceView:m},liveTraceComputeDurationMs:c!==void 0&&a?a()-c:void 0}}function DZ(e,t){for(let n of e)t(n),DZ(n.children,t)}function LFe(e){return typeof e.output==`string`?e.output:typeof e.summary==`string`?e.summary:``}function OZ(e){if(!e)return;let t=0;return DZ(e.nodes,e=>{e.type===`assistant.message`&&(t+=LFe(e).length)}),t}function RFe({selectedPiboSessionId:e,baseTraceView:t,liveTraceOverlay:n,selectedSessionStatus:r}){let i=(0,H.useMemo)(()=>t?fZ(t):null,[t]),a=(0,H.useMemo)(()=>i?DFe(i.nodes):new Map,[i]),o=(0,H.useRef)(void 0),s=(0,H.useMemo)(()=>{let t=IFe({selectedPiboSessionId:e,reconciledBaseTraceView:i,liveTraceOverlay:n,selectedSessionStatus:r,persistedUserMessageIndexForBaseTrace:a,previousProjection:o.current,now:RW()?()=>performance.now():void 0});return o.current=t.projectionCache,t},[n,e,r,i,a]),c=s.traceView;return(0,H.useEffect)(()=>{!e||!c?.piboSessionId||!RW()||(zW(c.piboSessionId,{overlayEventCount:n?.piboSessionId===c.piboSessionId?n.events.length:0,traceBaseOutputLength:OZ(t),currentOutputLength:OZ(c)}),s.liveTraceComputeDurationMs!==void 0&&QOe(c.piboSessionId,s.liveTraceComputeDurationMs))},[t,s.liveTraceComputeDurationMs,c,n,e]),(0,H.useEffect)(()=>{if(!c?.piboSessionId||!oX())return;let e=n?.piboSessionId===c.piboSessionId?n.events:[];dX({piboSessionId:c.piboSessionId,trigger:`trace-state:render`,baseTraceView:t,currentTraceView:c,overlayEvents:e,selectedSessionStatus:r})},[t,c,n,r]),(0,H.useEffect)(()=>{let e=()=>{if(!c?.piboSessionId||!oX())return;let e=n?.piboSessionId===c.piboSessionId?n.events:[];dX({piboSessionId:c.piboSessionId,trigger:`trace-state:tab:${document.visibilityState}`,baseTraceView:t,currentTraceView:c,overlayEvents:e,selectedSessionStatus:r})};return document.addEventListener(`visibilitychange`,e),()=>document.removeEventListener(`visibilitychange`,e)},[t,c,n,r]),c}var kZ=1e4,AZ=3e5;function zFe(e,t=!1,n){return[`chat`,`bootstrap`,e??``,t?`archived`:`active`,n??``]}function BFe(e=!1,t,n){return[`chat`,`sessions`,e?`archived`:`active`,t??``,n??``]}var jZ=new WeakMap;function MZ(e){return jZ.get(e)??0}async function NZ(e){jZ.set(e,MZ(e)+1),await e.cancelQueries({queryKey:[`chat`,`sessions`]}),e.removeQueries({queryKey:[`chat`,`sessions`]})}async function VFe(e,t,n){let r=BFe(t.includeArchived,t.roomId,t.piboSessionId),i=MZ(e);if(t.force)e.removeQueries({queryKey:r,exact:!0});else{let t=e.getQueryData(r);if(t)return t}let a=await n();return i===MZ(e)&&e.setQueryData(r,a),a}function HFe(e){return[`chat`,`trace-summary`,e]}function UFe(e,t=!1,n,r=t?60:120){return[`chat`,`session-page`,e,t?`archived`:`active`,n??``,r]}function PZ(e,t={}){let n=t.pageSize??t.eventLimit??100,r=t.beforeCursor??t.beforeSequence;return[`chat`,`trace-page`,e,t.includeRawEvents?`raw`:`compact`,t.rawEventsLimit??80,n,r===void 0?`tail`:String(r)]}function FZ(e){return[`chat`,`trace-summary`,e]}function IZ(e){return[`chat`,`trace-page`,e]}function WFe(e,t){if(e.piboSessionId!==t.piboSessionId)return e;let n=VZ(t.rawEvents,e.rawEvents,!1),r=KZ(t.nodes,e.nodes);return{...e,version:e.version,integrityStatus:RZ(r)??e.integrityStatus??t.integrityStatus,nodes:r,rawEvents:n,beforeCursor:t.beforeCursor??e.beforeCursor,firstEventSequence:t.firstEventSequence??e.firstEventSequence,nextBeforeSequence:t.nextBeforeSequence,nextBeforeCursor:t.nextBeforeCursor,hasOlderEvents:t.hasOlderEvents,eventLimit:(e.eventLimit??0)+(t.eventLimit??t.pageSize??0)}}function GFe(e,t){if(e.piboSessionId!==t.piboSessionId)return t;let n=KFe(e.nodes,t);return{...t,integrityStatus:RZ(n)??t.integrityStatus,nodes:n,rawEvents:VZ(e.rawEvents,t.rawEvents,!0),beforeCursor:e.beforeCursor,firstEventSequence:e.firstEventSequence??t.firstEventSequence,nextBeforeSequence:e.nextBeforeSequence,nextBeforeCursor:e.nextBeforeCursor,hasOlderEvents:e.hasOlderEvents,eventLimit:e.eventLimit??t.eventLimit}}function KFe(e,t){let n=xX([...e]),r=xX([...t.nodes]),i=new Set(r.map(e=>e.id)),a=qFe(r),o=JFe([...n,...r]),s=XFe(r),c=ZFe(r),l=n.filter(e=>{if(zZ(e)&&e.eventId&&a.has(e.eventId))return!1;if(i.has(e.id))return!0;if(e.type===`agent.turn`&&e.source===`event-log`&&e.eventId&&o.has(e.eventId)||YFe(e))return!1;let n=e.orderKey?.eventSequence;if(n!==void 0&&t.firstEventSequence!==void 0)return n<t.firstEventSequence;let r=e.orderKey?s.get(e.orderKey.sourceRank):void 0;if(e.orderKey&&r)return Iu(e.orderKey,r)<0;if(e.source===`live`||e.orderKey?.streamId!==void 0)return!1;let l=BZ(e.startedAt);return l!==void 0&&c!==void 0&&l<c}),u=new Set([...l,...r].map(e=>e.id)),d=new Set(n.filter(e=>!u.has(e.id)).map(e=>e.id));return KZ(LZ(l,d),LZ(r,d))}function LZ(e,t){return e.map(e=>({...e,...e.parentId&&t.has(e.parentId)?{parentId:void 0}:{},children:[]}))}function RZ(e){return xX([...e]).some(zZ)?`incomplete`:void 0}function zZ(e){return e.id.startsWith(`event:incomplete-turn:`)||e.stableKey?.startsWith(`incomplete-turn:`)===!0}function qFe(e){return new Set(e.flatMap(e=>e.eventId&&(e.type===`agent.turn`&&e.completedAt||e.type===`error`&&e.title===`Session Error`)?[e.eventId]:[]))}function JFe(e){let t=new Set;for(let n of e)(n.source===`transcript`||n.source===`product-history`)&&n.eventId&&t.add(n.eventId);return t}function YFe(e){return e.source===`live`||e.orderKey?.streamId!==void 0}function XFe(e){let t=new Map;for(let n of e){if(!n.orderKey)continue;let e=t.get(n.orderKey.sourceRank);(!e||Iu(n.orderKey,e)<0)&&t.set(n.orderKey.sourceRank,n.orderKey)}return t}function ZFe(e){let t;for(let n of e){let e=BZ(n.startedAt);e!==void 0&&(t=t===void 0?e:Math.min(t,e))}return t}function BZ(e){if(!e)return;let t=Date.parse(e);return Number.isFinite(t)?t:void 0}function VZ(e,t,n){if(!t.length)return[...e].sort(HZ);let r=n?t.reduce((e,t)=>t.eventSequence===void 0?e:e===void 0?t.eventSequence:Math.min(e,t.eventSequence),void 0):void 0,i=new Map;for(let t of e)r!==void 0&&t.eventSequence!==void 0&&t.eventSequence>=r||i.set(GZ(t),t);for(let e of t)i.set(GZ(e),e);return[...i.values()].sort(HZ)}function HZ(e,t){return(e.eventSequence===void 0?0:1)-(t.eventSequence===void 0?0:1)||(e.eventSequence!==void 0&&t.eventSequence!==void 0?e.eventSequence-t.eventSequence:0)||QFe(WZ(e.createdAt),WZ(t.createdAt))||UZ(e.streamId,t.streamId)||UZ(e.streamFrameIndex,t.streamFrameIndex)||(e.eventSequence===void 0&&t.eventSequence===void 0?UZ(e.renderSequence,t.renderSequence):0)||e.id.localeCompare(t.id)||e.type.localeCompare(t.type)}function UZ(e,t){return e===t?0:e===void 0?1:t===void 0?-1:e-t}function QFe(e,t){return e===t?0:e===void 0?1:t===void 0?-1:e.localeCompare(t)}function WZ(e){return Number.isFinite(Date.parse(e))?e:void 0}function GZ(e){return e.id||`${e.eventSequence??``}:${e.type}:${e.createdAt}`}function KZ(e,t){let n=new Map;for(let t of xX([...e]))n.set(t.id,{...t,children:[]});for(let e of xX([...t])){let t=n.get(e.id);n.set(e.id,{...t,...e,children:[]})}return kPe([...n.values()])}function qZ(e,t=[]){let n=new Map,r=[],i=e.hasOlderEvents??e.cursor.hasOlder,a=i?e.nextBeforeCursor??e.cursor.before:void 0,o=i?e.nextBeforeSequence??JZ(e.cursor.before):void 0;for(let t of e.nodes)n.set(t.nodeId,$Fe(t));for(let t of e.nodes){let e=n.get(t.nodeId);if(!e)continue;let i=t.parentId?n.get(t.parentId):void 0;i?i.children.push(e):r.push(e)}return{piboSessionId:e.piboSessionId,piSessionId:e.piSessionId,integrityStatus:e.integrityStatus,title:e.title,version:e.version,latestStreamId:e.latestStreamId,eventCount:e.eventCount,eventLimit:e.pageSize,pageSize:e.pageSize,beforeCursor:e.cursor.before,firstEventSequence:e.firstEventSequence??JZ(e.cursor.before),lastEventSequence:e.lastEventSequence??JZ(e.cursor.after),nextBeforeSequence:o,nextBeforeCursor:a,hasOlderEvents:i,nodes:r,rawEvents:t}}function JZ(e){if(!e)return;let t=Number.parseInt(e,10);return Number.isFinite(t)?t:void 0}function $Fe(e){let t=e.preview?.text,n=e.payloadRefs?.input?.preview,r=e.payloadRefs?.output?.preview??e.payloadRefs?.reasoning?.preview??t,i=e.payloadRefs?.error?.preview,a=e.inlinePayloads?.output??e.inlinePayloads?.reasoning;return{id:e.nodeId,parentId:e.parentId,entryId:e.entryId,nativeTurnId:e.nativeTurnId,piboSessionId:e.piboSessionId,eventId:e.eventId,toolCallId:e.toolCallId,runId:e.runId,intent:e.intent,type:e.type,title:e.title,status:e.status,startedAt:e.startedAt,completedAt:e.completedAt,durationMs:e.durationMs,toolMetrics:e.toolMetrics,summary:t,input:e.inlinePayloads?.input??n,output:a??r,error:typeof e.inlinePayloads?.error==`string`?e.inlinePayloads.error:i,payloadRefs:e.payloadRefs,linkedPiboSessionId:e.linkedPiboSessionId,source:e.source,stableKey:e.stableKey,orderKey:e.orderKey,children:[]}}var eIe=128;function tIe({selectedPiboSessionId:e,showRawEvents:t,liveTraceOverlay:n,liveTraceOverlayCacheRef:r,setLiveTraceOverlay:i}){let a=kn(),[o,s]=(0,H.useState)(100),[c,l]=(0,H.useState)(80),[u,d]=(0,H.useState)(null),f=(0,H.useRef)(new Map),[p,m]=(0,H.useState)(void 0),[h,g]=(0,H.useState)(!1),_=(0,H.useRef)(null),v=(0,H.useRef)(new Set),y=(0,H.useMemo)(()=>e?HFe(e):null,[e]),b=(0,H.useMemo)(()=>e?PZ(e,{includeRawEvents:!1,rawEventsLimit:0,pageSize:100}):null,[e]),x=Wn({queryKey:y??[`chat`,`trace-summary`,`idle`],queryFn:async({signal:t})=>{if(!e||!y)throw Error(`Session is required`);let n=a.getQueryData(y),r=await yu(e,n?.version,{signal:t});if(r.notModified&&n)return n;if(!r.summary)throw Error(`Trace summary response missing payload.`);return r.summary},enabled:!1,staleTime:kZ,gcTime:AZ,refetchOnWindowFocus:!1,retry:1}),S=Wn({queryKey:b??[`chat`,`trace-page`,`idle`,`compact`,c,100,`tail`],queryFn:async({signal:t})=>{if(!e||!b)throw Error(`Session is required`);let n=a.getQueryData(b),r=await bu(e,{limit:100,knownVersion:n?.version,signal:t});if(r.notModified&&n)return n;if(!r.timeline)throw Error(`Trace timeline response missing payload.`);return qZ(r.timeline)},enabled:!!e,staleTime:kZ,gcTime:AZ,refetchOnWindowFocus:!1,retry:1});(0,H.useLayoutEffect)(()=>{let t=b?a.getQueryData(b):void 0;s(100),l(80),m(void 0),g(!1),d(n=>(n&&f.current.set(n.piboSessionId,n),e?f.current.get(e)??(t?.piboSessionId===e?t:null):null)),i(t=>AFe(r.current,t,e)),_.current=null,v.current=new Set},[r,a,e,i,b]);let C=Wn({queryKey:e?[`chat`,`trace-raw-events`,e,c,p??`tail`]:[`chat`,`trace-raw-events`,`idle`],queryFn:async({signal:t})=>{if(!e)throw Error(`Session is required`);return xu(e,{limit:c,beforeSequence:p,signal:t})},enabled:!!(e&&t),staleTime:kZ,gcTime:AZ,refetchOnWindowFocus:!1,retry:1});(0,H.useEffect)(()=>{let t=S.data;!t||t.piboSessionId!==e||(RW()&&zW(t.piboSessionId,{overlayEventCount:0,traceBaseOutputLength:OZ(t),traceBaseUpdated:!0}),(0,H.startTransition)(()=>{d(e=>{let n=e?.piboSessionId===t.piboSessionId?GFe(e,t):t;return f.current.set(t.piboSessionId,n),n}),i(e=>yZ(r.current,e,t))}))},[r,e,i,S.data]),(0,H.useEffect)(()=>{let t=u;!t||t.piboSessionId!==e||(0,H.startTransition)(()=>{i(e=>yZ(r.current,e,t))})},[u,r,e,i]),(0,H.useEffect)(()=>{let t=C.data;!t||t.piboSessionId!==e||(0,H.startTransition)(()=>{d(e=>{if(!e)return e;if(p===void 0)return{...e,rawEvents:t.events};let n=new Set(t.events.map(e=>e.id));return{...e,rawEvents:[...t.events,...e.rawEvents.filter(e=>!n.has(e.id))]}})})},[p,C.data,e]);let w=(0,H.useCallback)(async n=>{if(!e||!n)return;let r=`${e}:${n}`;if(_.current||v.current.has(r))return;_.current=r,g(!0);let i=PZ(e,{includeRawEvents:t,rawEventsLimit:c,pageSize:100,beforeCursor:n});try{let t=await a.fetchQuery({queryKey:i,queryFn:async({signal:t})=>{let r=a.getQueryData(i),o=await bu(e,{limit:100,beforeCursor:n,knownVersion:r?.version,signal:t});if(o.notModified&&r)return r;if(!o.timeline)throw Error(`Trace timeline response missing payload.`);return qZ(o.timeline)},staleTime:kZ,gcTime:AZ});(0,H.startTransition)(()=>{d(e=>e?WFe(e,t):t),s(e=>e+(t.pageSize??100))}),nIe(v.current,r)}finally{_.current===r&&(_.current=null),g(!1)}},[a,c,e,t]),T=e?u?.piboSessionId===e?u:f.current.get(e)??(S.data?.piboSessionId===e?S.data:null):null,E=e?n?.piboSessionId===e?n:r.current.get(e)??null:null,D=(0,H.useCallback)(()=>{let e=T?.rawEvents[0]?.eventSequence;m(e),l(e=>e+80)},[T?.rawEvents]);return{baseTraceView:T,liveTraceOverlay:E,traceEventLimit:o,rawEventLimit:c,traceSummaryQuery:x,tracePageQuery:S,rawEventsQuery:C,loadingOlderTracePage:h,tracePageReady:!!b,loadOlderTracePage:w,loadMoreRawEvents:D}}function nIe(e,t){if(e.add(t),e.size<=eIe)return;let n=e.values().next();n.done||e.delete(n.value)}function rIe(e){let t=e.currentEvents,n,r,i=()=>(r??=new Set(t.map($Z)),r),a=e=>{n??=t.slice(),n.push(e),t=n};for(let o of e.streamEvents){let s=oIe(o,e.piboSessionId,e.nextSequence,e.now??(()=>new Date().toISOString()));if(!s)continue;if(iIe(s)){t=aIe(t,s),n=t,r=void 0;continue}let c=$Z(s),l=i();l.has(c)||(l.add(c),a(s))}return t}function iIe(e){return e.type===`assistant_message`||e.type===`thinking_finished`||e.type===`tool_execution_finished`}function aIe(e,t){return t.type===`assistant_message`?[...QZ(e,t,`assistant_delta`),t]:t.type===`thinking_finished`?[...QZ(e,t,`thinking_delta`),t]:t.type===`tool_execution_finished`?[...QZ(e,t,`tool_execution_updated`),t]:e}function oIe(e,t,n,r){if(e.type===`RAW_EVENT`&&nQ(e.event)&&typeof e.event.type==`string`){let i=e.event;return YZ(e,t,e.event.type,i,n,r)}if(e.type===`TEXT_MESSAGE_CONTENT`&&typeof e.delta==`string`)return YZ(e,t,`assistant_delta`,{type:`assistant_delta`,piboSessionId:t,eventId:typeof e.runId==`string`?e.runId:void 0,...tQ(typeof e.messageId==`string`?e.messageId:void 0,`assistant`),text:e.delta},n,r);if(e.type===`REASONING_MESSAGE_CONTENT`&&typeof e.delta==`string`)return YZ(e,t,`thinking_delta`,{type:`thinking_delta`,piboSessionId:t,eventId:typeof e.runId==`string`?e.runId:void 0,...tQ(typeof e.messageId==`string`?e.messageId:void 0,`thinking`),text:e.delta},n,r);if(e.type===`TOOL_CALL_START`&&typeof e.toolCallId==`string`&&typeof e.toolName==`string`)return YZ(e,t,`tool_execution_started`,{type:`tool_execution_started`,piboSessionId:t,eventId:typeof e.runId==`string`?e.runId:void 0,toolCallId:e.toolCallId,toolName:e.toolName,toolInvocationOrdinal:ZZ(e.toolInvocationOrdinal)?e.toolInvocationOrdinal:void 0,args:e.args,...e.intent?{intent:e.intent}:{}},n,r);if(e.type===`TOOL_CALL_ARGS`&&typeof e.toolCallId==`string`&&typeof e.toolName==`string`){let i=typeof e.runId==`string`?e.runId:void 0,a=e.sourceEventType===`tool_execution_updated`?`tool_execution_updated`:`tool_call`;return YZ(e,t,a,a===`tool_execution_updated`?{type:`tool_execution_updated`,piboSessionId:t,eventId:i,toolCallId:e.toolCallId,toolName:e.toolName,toolInvocationOrdinal:ZZ(e.toolInvocationOrdinal)?e.toolInvocationOrdinal:void 0,args:e.args,partialResult:e.partialResult,...e.intent?{intent:e.intent}:{}}:{type:`tool_call`,piboSessionId:t,eventId:i,toolCallId:e.toolCallId,toolName:e.toolName,toolInvocationOrdinal:ZZ(e.toolInvocationOrdinal)?e.toolInvocationOrdinal:void 0,args:e.args,argsComplete:!!e.argsComplete,...e.intent?{intent:e.intent}:{}},n,r)}if(e.type===`TOOL_CALL_RESULT`&&typeof e.toolCallId==`string`&&typeof e.toolName==`string`)return YZ(e,t,`tool_execution_finished`,{type:`tool_execution_finished`,piboSessionId:t,eventId:typeof e.runId==`string`?e.runId:void 0,toolCallId:e.toolCallId,toolName:e.toolName,toolInvocationOrdinal:ZZ(e.toolInvocationOrdinal)?e.toolInvocationOrdinal:void 0,result:e.result,toolMetrics:e.toolMetrics,isError:!!e.isError,...e.intent?{intent:e.intent}:{}},n,r);if(e.type===`RUN_ERROR`&&typeof e.message==`string`)return YZ(e,t,`session_error`,{type:`session_error`,piboSessionId:t,eventId:typeof e.runId==`string`?e.runId:void 0,error:e.message,errorDetails:e.errorDetails},n,r)}function YZ(e,t,n,r,i,a){let o=typeof e.streamFrameId==`string`?e.streamFrameId:void 0,s=typeof e.streamFrameIndex==`number`?e.streamFrameIndex:void 0,c=typeof e.liveReplayId==`number`&&Number.isFinite(e.liveReplayId)?e.liveReplayId:void 0,l=i(),u=XZ(e.renderSequence)?e.renderSequence:XZ(r.renderSequence)?r.renderSequence:void 0,d=u!==void 0&&r.renderSequence===void 0?{...r,renderSequence:u}:r;return{id:typeof e.streamId==`number`?`stream:${e.streamId}:${s??`raw`}:${n}`:c===void 0?o?`stream:${o}:${n}`:`live:${l}:${n}`:`live-replay:${c}:${n}`,piboSessionId:t,eventSequence:l,renderSequence:u,streamId:typeof e.streamId==`number`?e.streamId:void 0,streamFrameIndex:s,traceSource:`live`,eventId:typeof d.eventId==`string`?d.eventId:void 0,type:n,createdAt:sIe(e)??a(),payload:d}}function XZ(e){return typeof e==`number`&&Number.isSafeInteger(e)&&e>=0}function ZZ(e){return typeof e==`number`&&Number.isSafeInteger(e)&&e>=0}function sIe(e){if(!(typeof e.createdAt!=`string`||!Number.isFinite(Date.parse(e.createdAt))))return e.createdAt}function QZ(e,t,n){let r=eQ(t);return e.filter(e=>e.type!==n||eQ(e)!==r)}function $Z(e){return e.streamId===void 0?`${e.id}:${e.type}`:e.streamFrameIndex===void 0?`stream:${e.streamId}:${e.id}:${e.type}`:`stream:${e.streamId}:${e.streamFrameIndex}:${e.type}`}function eQ(e){let t=nQ(e.payload)?e.payload:{},n=typeof t.piboSessionId==`string`?t.piboSessionId:e.piboSessionId??``,r=typeof t.eventId==`string`?t.eventId:e.eventId??``;if(typeof t.toolCallId==`string`){let e=typeof t.toolInvocationOrdinal==`number`?t.toolInvocationOrdinal:0;return`${n}:${r}:tool:${t.toolCallId}:${e}`}let i=typeof t.assistantIndex==`number`?t.assistantIndex:void 0,a=typeof t.thinkingIndex==`number`?t.thinkingIndex:void 0,o=typeof t.contentIndex==`number`?t.contentIndex:0;return`${n}:${r}:${i??a??o}`}function tQ(e,t){let n=e?.match(RegExp(`:${t}:(\\d+)$`));if(!n)return{};let r=Number(n[1]);return Number.isInteger(r)?t===`assistant`?{assistantIndex:r}:{thinkingIndex:r}:{}}function nQ(e){return!!e&&typeof e==`object`&&!Array.isArray(e)}var cIe=500,lIe=1e4,uIe=45e3,dIe=15e3,fIe=100,pIe=2;function mIe(e){let t=Math.max(e.eventCount??0,e.lastEventSequence??0);for(let n of e.rawEvents)t=Math.max(t,n.eventSequence??0);return t+1}function rQ(e){if(e.forceReconnect)return!0;let t=e.liveStream;return!t||t.piboSessionId!==e.selectedPiboSessionId||t.readyState===pIe||(e.nowMs??Date.now())-t.lastActivityAt>uIe}function iQ(e,t){return e===t}function hIe({selectedPiboSessionId:e,tracePageData:t,currentTraceView:n,liveEventSeqRef:r,selectedSessionStatus:i,tracePageReady:a,setLiveTraceOverlay:o,onRefreshTrace:s,onRefreshBootstrap:c,onRuntimeRequestEvent:l,onError:u}){let d=(0,H.useRef)(e);d.current=e;let f=(0,H.useRef)(new Map),p=(0,H.useRef)(void 0),m=(0,H.useRef)(void 0),h=(0,H.useRef)(new Map),g=(0,H.useRef)(new Map),_=(0,H.useRef)(null),v=(0,H.useRef)(void 0),y=(0,H.useRef)(0),b=(0,H.useRef)(!1),x=(0,H.useRef)(!1),[S,C]=(0,H.useState)(0);(0,H.useEffect)(()=>{let n=t;!n||n.piboSessionId!==e||(r.current=Math.max(r.current,mIe(n)),n.latestStreamId!==void 0&&Bu(g.current,n.piboSessionId,n.latestStreamId))},[r,e,t]);let w=(0,H.useCallback)(e=>{let t=f.current.get(e);t?.length&&(f.current.delete(e),iQ(e,d.current)&&o(n=>{if(!iQ(e,d.current))return n;let i=rIe({currentEvents:n?.piboSessionId===e?n.events:[],streamEvents:t,piboSessionId:e,nextSequence:()=>r.current++});return ZOe(e,t.length,i.length),{piboSessionId:e,events:i}}))},[]),T=(0,H.useCallback)(()=>{if(!(p.current!==void 0||m.current!==void 0||!e)){if(document.hidden){m.current=setTimeout(()=>{m.current=void 0,w(e)},fIe);return}p.current=requestAnimationFrame(()=>{p.current=void 0,w(e)})}},[w,e]),E=(0,H.useCallback)((t,n,r=!1)=>{Ku(h.current,t,n);let i=r||qu(h.current,t,n),a=f.current.get(t)??[];a.push(n),f.current.set(t,a),XOe(t,n,a.length,i),i||t!==e?w(t):T()},[w,T,e]);(0,H.useEffect)(()=>()=>{p.current!==void 0&&cancelAnimationFrame(p.current),m.current!==void 0&&clearTimeout(m.current),v.current!==void 0&&clearTimeout(v.current)},[]);let D=(0,H.useCallback)((e,t)=>{Vu(g.current,e,t)},[]),O=(0,H.useCallback)((e=0)=>{if(v.current!==void 0){if(e>0)return;clearTimeout(v.current)}v.current=setTimeout(()=>{v.current=void 0,C(e=>e+1)},e)},[]),k=(0,H.useCallback)((t=!1)=>{if(!e)return;w(e),s().catch(e=>u(aQ(e))),c().catch(e=>u(aQ(e)));let n=_.current;if(rQ({selectedPiboSessionId:e,liveStream:n?{piboSessionId:n.piboSessionId,lastActivityAt:n.lastActivityAt,readyState:n.events.readyState}:null,forceReconnect:t})){if(t){if(b.current)return;b.current=!0}O()}},[w,u,c,s,O,e]);(0,H.useEffect)(()=>{if(!e||!a||!n||n.piboSessionId!==e)return;let t=new URLSearchParams({piboSessionId:e});t.set(`mode`,`live`);let r=g.current.get(e),i=r?.cursor??(n.latestStreamId===void 0?void 0:Hu(n.latestStreamId));i!==void 0&&t.set(`since`,i),r?.liveReplayId!==void 0&&t.set(`liveSince`,String(r.liveReplayId));let o=new EventSource(`/api/chat/events?${t.toString()}`),d=Date.now();_.current={piboSessionId:e,events:o,openedAt:d,lastActivityAt:d};let f=!1,p,m,h=!1,x=!1,S=(t,n=!1)=>{if(p){if(!n)return;clearTimeout(p)}eke(e,t),p=setTimeout(()=>{p=void 0,s().catch(e=>u(aQ(e)))},t)},C=()=>{if(h){x=!0;return}h=!0,c().catch(e=>u(aQ(e))).finally(()=>{h=!1,x&&(x=!1,T(250,!0))})},T=(e,t=!1)=>{if(m){if(!t)return;clearTimeout(m)}m=setTimeout(()=>{m=void 0,C()},e)},k=()=>{T(900,!0)};return o.onopen=()=>{y.current=0,b.current=!1,v.current!==void 0&&(clearTimeout(v.current),v.current=void 0),qOe(e,o.readyState);let t=_.current;t?.events===o&&(t.lastActivityAt=Date.now())},o.onerror=()=>{if(f)return;JOe(e,o.readyState);let t=_.current;t?.events===o&&(t.lastErrorAt=Date.now());let n=y.current++,r=Math.min(lIe,cIe*2**n);O(r)},o.addEventListener(`pibo`,t=>{if(f)return;let n=zu(t);if(!n)return;let r=n.piboSessionId||e,i=_.current;if(i?.events===o&&(i.lastActivityAt=Date.now()),D(r,n),YOe(r,n,t.lastEventId,o.readyState),r===e&&n.type===`ready`&&n.liveReplay?.missed&&S(0,!0),rke(n))return;(n.type===`RUNTIME_APPROVAL_REQUESTED`||n.type===`RUNTIME_APPROVAL_RESOLVED`||n.type===`RUNTIME_USER_INPUT_REQUESTED`||n.type===`RUNTIME_USER_INPUT_RESOLVED`)&&l?.(n);let a=n.type!==`TEXT_MESSAGE_CONTENT`&&n.type!==`REASONING_MESSAGE_CONTENT`;r===e&&Gu(n)&&E(r,n,a);let s=Uu(n);r===e&&s!==void 0?S(s,!0):r===e&&n.type!==`ready`&&n.type!==`RAW_EVENT`&&S(1500,!0),Wu(n)&&(n.type===`RUN_FINISHED`||n.type===`RUN_ERROR`||n.type===`TEXT_MESSAGE_END`?k():T(r===e?0:150))}),()=>{f=!0,p&&clearTimeout(p),m&&clearTimeout(m),w(e),_.current?.events===o&&(_.current=null),o.close()}},[n?.piboSessionId,E,w,u,c,s,l,D,O,S,e,a]),(0,H.useEffect)(()=>{n?.piboSessionId&&w(n.piboSessionId)},[n?.piboSessionId,w]),(0,H.useEffect)(()=>{let e=()=>k(),t=()=>k(!0),n=()=>{x.current=!0,_.current?.events.close()},r=()=>{if(document.hidden){n();return}x.current=!1,k(!0)},i=e=>{let t=x.current||e.persisted;x.current=!1,k(t)};return window.addEventListener(`focus`,e),window.addEventListener(`online`,t),window.addEventListener(`pagehide`,n),window.addEventListener(`pageshow`,i),document.addEventListener(`visibilitychange`,r),()=>{window.removeEventListener(`focus`,e),window.removeEventListener(`online`,t),window.removeEventListener(`pagehide`,n),window.removeEventListener(`pageshow`,i),document.removeEventListener(`visibilitychange`,r)}},[k]),(0,H.useEffect)(()=>{if(!e||i!==`running`)return;let t=window.setInterval(()=>{w(e);let t=_.current;rQ({selectedPiboSessionId:e,liveStream:t?{piboSessionId:t.piboSessionId,lastActivityAt:t.lastActivityAt,readyState:t.events.readyState}:null})&&(s().catch(e=>u(aQ(e))),O())},dIe);return()=>window.clearInterval(t)},[w,u,s,O,e,i])}function aQ(e){return e instanceof Error?e.message:String(e)}async function gIe(e,t={}){let n=new URLSearchParams({piboSessionId:e});return t.status&&n.set(`status`,t.status),t.limit&&n.set(`limit`,String(t.limit)),t.scope&&n.set(`scope`,t.scope),G(`/api/web-annotations?${n.toString()}`)}async function _Ie(e,t){return G(`/api/web-annotations/${encodeURIComponent(e)}`,{method:`PATCH`,headers:{"content-type":`application/json`},body:JSON.stringify(sQ(t))})}async function vIe(e){let t=new URLSearchParams;return e?.trim()&&t.set(`cdpUrl`,e.trim()),G(`/api/web-annotations/targets${t.size?`?${t.toString()}`:``}`)}async function oQ(e){return G(`/api/web-annotations/bindings`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify(sQ(e))})}async function yIe(e,t){return G(`/api/web-annotations/bindings/${encodeURIComponent(e)}/inject`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify(sQ(t))})}function sQ(e){return Object.fromEntries(Object.entries(e).filter(([,e])=>e!==void 0&&e!==``))}var cQ=`pibo.chat.webAnnotations.cdpUrl`,lQ=`pibo.chat.webAnnotations.selected`,uQ=`${lQ}.`,bIe=`pibo.chat.webAnnotations.overlay.`,dQ=`pibo.chat.shortcuts.webAnnotationsToggle`,fQ=`Alt+Shift+A`;function xIe(){try{return localStorage.getItem(cQ)??``}catch{return``}}function SIe(e){try{e.trim()?localStorage.setItem(cQ,e.trim()):localStorage.removeItem(cQ)}catch{}}function pQ(){try{return localStorage.getItem(dQ)||`Alt+Shift+A`}catch{return fQ}}function mQ(e){let t=gQ(e)||`Alt+Shift+A`;try{localStorage.setItem(dQ,t)}catch{}}function hQ(e){window.__piboWebAnnotations?.setShortcut?.(e);try{window.dispatchEvent(new CustomEvent(`pibo:web-annotation-shortcut-changed`,{detail:{shortcut:e}}))}catch{}}function gQ(e){return e.replace(/[\u0000-\u001f\u007f]/g,``).trim().slice(0,80)}function CIe(e){if([`Alt`,`Control`,`Meta`,`Shift`].includes(e.key)||!e.altKey&&!e.ctrlKey&&!e.metaKey)return null;let t=e.code?.match(/^Key[A-Z]$/)?e.code.slice(3):e.key===` `?`Space`:e.key.length===1?e.key.toUpperCase():e.key,n=[];return e.ctrlKey&&n.push(`Ctrl`),e.altKey&&n.push(`Alt`),e.shiftKey&&n.push(`Shift`),e.metaKey&&n.push(`Meta`),n.push(t),n.join(`+`)}function _Q(e){try{return yQ(localStorage.getItem(vQ(e)))}catch{return null}}function vQ(e){return bIe+e}function yQ(e){if(!e)return null;try{return bQ(JSON.parse(e))}catch{return null}}function bQ(e){if(!e||typeof e!=`object`)return null;let t=e,n=typeof t.piboSessionId==`string`?t.piboSessionId.trim():``;return n?{bindingId:typeof t.bindingId==`string`?t.bindingId:void 0,piboSessionId:n,installed:t.installed!==!1,active:t.active===!0,toolbarExpanded:t.toolbarExpanded===!0,mode:typeof t.mode==`string`?t.mode:void 0,reason:typeof t.reason==`string`?t.reason:void 0,updatedAt:typeof t.updatedAt==`string`?t.updatedAt:void 0}:null}function wIe(e){try{let t=SQ(localStorage.getItem(lQ));if(t.length||!e)return t;let n=uQ+e,r=SQ(localStorage.getItem(n));return r.length&&(localStorage.setItem(lQ,JSON.stringify(r)),localStorage.removeItem(n)),r}catch{return[]}}function xQ(e,t){try{let n=[...new Set(t.filter(e=>e.trim()))].slice(0,5);n.length?localStorage.setItem(lQ,JSON.stringify(n)):localStorage.removeItem(lQ),e&&localStorage.removeItem(uQ+e)}catch{}}function SQ(e){if(!e)return[];try{let t=JSON.parse(e);return Array.isArray(t)?t.filter(e=>typeof e==`string`&&!!e.trim()).slice(0,5):[]}catch{return[]}}function TIe({selectedPiboSessionId:e,onError:t,formatError:n,forcePanelVisible:r=!1}){let[i,a]=(0,H.useState)([]),[o,s]=(0,H.useState)(!1),[c,l]=(0,H.useState)(()=>e?_Q(e):null),[u,d]=(0,H.useState)(!1),f=!!(e&&c?.piboSessionId===e&&c.installed),p=!!e&&(r||o||f),m=Wn({queryKey:[`web-annotations`,`app`,e],queryFn:async()=>{if(!e)throw Error(`Session is required`);return gIe(e,{limit:100,scope:`app`})},enabled:!!e&&(p||i.length>0),staleTime:1e3,refetchOnWindowFocus:p,refetchInterval:p?5e3:!1,retry:1}),h=m.refetch,g=(0,H.useMemo)(()=>(m.data?.annotations??[]).filter(e=>e.status!==`resolved`&&e.status!==`dismissed`),[m.data?.annotations]),_=(0,H.useMemo)(()=>i.map(e=>g.find(t=>t.id===e)).filter(e=>!!e),[i,g]);(0,H.useEffect)(()=>{a(e?wIe(e):[]),l(e?_Q(e):null)},[e]),(0,H.useEffect)(()=>{if(!e)return;let t=t=>{!t||t.piboSessionId!==e||(l(e=>t.installed?t:e?.installed&&e.bindingId&&t.bindingId&&e.bindingId!==t.bindingId?e:t),t.installed?h():s(!1))},n=e=>t(bQ(e.detail)),r=n=>{n.key===vQ(e)&&t(yQ(n.newValue))},i=()=>t(_Q(e));return window.addEventListener(`pibo:web-annotation-overlay-state`,n),window.addEventListener(`storage`,r),window.addEventListener(`focus`,i),document.addEventListener(`visibilitychange`,i),i(),()=>{window.removeEventListener(`pibo:web-annotation-overlay-state`,n),window.removeEventListener(`storage`,r),window.removeEventListener(`focus`,i),document.removeEventListener(`visibilitychange`,i)}},[h,e]),(0,H.useEffect)(()=>{if(!m.data)return;if(!g.length){a(t=>(t.length&&e&&xQ(e,[]),t.length?[]:t));return}let t=new Set(g.map(e=>e.id));a(n=>{let r=n.filter(e=>t.has(e));return r.length!==n.length&&e&&xQ(e,r),r.length===n.length?n:r})},[e,g,m.data]),(0,H.useEffect)(()=>{let e=()=>{s(!0),h()};return window.addEventListener(`pibo:web-annotation-saved`,e),()=>window.removeEventListener(`pibo:web-annotation-saved`,e)},[h]);let v=(0,H.useCallback)(t=>{a(n=>{let r=t(n);return e&&xQ(e,r),r})},[e]),y=(0,H.useCallback)(e=>{v(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e].slice(0,5))},[v]),b=(0,H.useCallback)(()=>v(()=>[]),[v]);return{selectedWebAnnotationIds:i,selectedWebAnnotations:_,visibleWebAnnotations:g,webAnnotationsPanelRendered:p,webAnnotationsPanelVisible:o,webAnnotationsQuery:m,clearingWebAnnotations:u,setWebAnnotationsPanelVisible:s,toggleWebAnnotationAttachment:y,detachWebAnnotationAttachment:(0,H.useCallback)(e=>{v(t=>t.filter(t=>t!==e))},[v]),clearSelectedWebAnnotationAttachments:b,clearVisibleWebAnnotations:(0,H.useCallback)(async()=>{if(!(!g.length||u)&&window.confirm(`Dismiss ${g.length} visible web annotations? This keeps sent messages but clears the annotation list.`)){d(!0);try{await Promise.all(g.map(e=>_Ie(e.id,{piboSessionId:e.piboSessionId,status:`dismissed`,summary:`Cleared from Chat Web UI`}))),b(),await h()}catch(e){t(n(e,`Could not clear web annotations`))}finally{d(!1)}}},[u,b,n,t,h,g])}}function EIe({piboSessionId:e,annotations:t,selectedIds:n,loading:r,error:i,onRefresh:a,onToggle:o,onClear:s}){return e?(0,U.jsxs)(`section`,{className:`bg-[#101d22] px-3 py-3 sm:px-4`,"data-pibo-debug":`web-annotations-session-panel`,"data-pibo-session-id":e,children:[(0,U.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[(0,U.jsx)(`div`,{className:`min-w-0`,children:(0,U.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,U.jsx)(`div`,{className:`text-[11px] font-bold uppercase tracking-wider text-[#11a4d4]`,children:`Web annotations`}),(0,U.jsx)(`span`,{className:`rounded-sm border border-slate-700 px-1.5 py-0.5 text-[10px] text-slate-400`,children:t.length}),n.length?(0,U.jsxs)(`span`,{className:`rounded-sm border border-[#11a4d4]/50 px-1.5 py-0.5 text-[10px] text-[#11a4d4]`,children:[n.length,` attached`]}):null]})}),(0,U.jsxs)(`div`,{className:`ml-auto flex shrink-0 items-center gap-1`,children:[(0,U.jsx)(`button`,{type:`button`,onClick:a,disabled:r,title:`Refresh annotations`,"aria-label":`Refresh annotations`,className:`inline-flex h-8 w-8 items-center justify-center rounded-sm border border-slate-700 text-slate-300 hover:border-[#11a4d4] hover:text-[#11a4d4] disabled:opacity-50 sm:h-7 sm:w-7`,"data-pibo-debug":`web-annotations-refresh`,children:(0,U.jsx)(ol,{size:12,className:r?`animate-spin`:void 0})}),(0,U.jsx)(`button`,{type:`button`,onClick:s,disabled:r||!t.length,title:`Clear visible annotations`,"aria-label":`Clear visible annotations`,className:`inline-flex h-8 w-8 items-center justify-center rounded-sm border border-slate-700 text-slate-300 hover:border-red-500 hover:text-red-300 disabled:opacity-50 sm:h-7 sm:w-7`,children:(0,U.jsx)(Cl,{size:12})})]})]}),(0,U.jsxs)(`div`,{children:[(0,U.jsx)(`div`,{className:`text-[11px] text-slate-500`,children:`Global annotation list. Selected attachments follow you when switching sessions.`}),i?(0,U.jsx)(`div`,{className:`rounded-sm border border-red-900 bg-red-950/40 px-3 py-2 text-xs text-red-200`,"data-pibo-debug":`web-annotations-error`,children:DQ(i,220)}):r&&!t.length?(0,U.jsx)(`div`,{className:`rounded-sm border border-slate-800 bg-[#0e1116] px-3 py-2 text-xs text-slate-400`,"data-pibo-debug":`web-annotations-loading`,children:`Loading annotations…`}):t.length?(0,U.jsx)(`div`,{className:`mt-2 grid grid-cols-1 gap-2 @min-[560px]:grid-cols-[repeat(auto-fill,minmax(16rem,1fr))]`,"data-pibo-debug":`web-annotations-list`,children:t.map((e,t)=>{let r=n.includes(e.id),i=DQ(e.primaryTarget||e.label||e.selector||e.targetKind||`target`,64),a=`${t+1}: ${i}`;return(0,U.jsxs)(`div`,{"data-pibo-debug":`web-annotation-chip`,"data-web-annotation-id":e.id,"data-web-annotation-session-id":e.piboSessionId,"data-web-annotation-selected":r?`true`:`false`,className:`min-w-0 rounded-sm border px-3 py-2 text-xs ${r?`border-[#11a4d4] bg-[#11a4d4]/10`:`border-slate-800 bg-[#0e1116]`}`,children:[(0,U.jsxs)(`div`,{className:`mb-1 flex items-center justify-between gap-2`,children:[(0,U.jsxs)(`span`,{className:`min-w-0 truncate font-mono text-[11px] text-slate-500`,children:[e.status,` · `,e.targetKind]}),(0,U.jsxs)(`button`,{type:`button`,onClick:()=>o(e.id),"aria-pressed":r,"aria-label":`Include web annotation ${a}`,title:`${r?`Detach`:`Attach`} web annotation ${a}`,className:`inline-flex h-8 shrink-0 items-center gap-1 rounded-sm border px-2 text-[11px] sm:h-6 sm:px-1.5 ${r?`border-[#11a4d4] text-[#11a4d4]`:`border-slate-700 text-slate-300 hover:border-[#11a4d4] hover:text-[#11a4d4]`}`,children:[r?(0,U.jsx)(jl,{size:11}):(0,U.jsx)(rl,{size:11}),` `,r?`Detach`:`Attach`]})]}),(0,U.jsx)(`div`,{className:`truncate text-slate-200`,title:e.primaryTarget||e.label||e.selector||e.id,children:DQ(e.primaryTarget||e.label||e.selector||e.id,120)}),e.piboContext?(0,U.jsx)(`div`,{className:`truncate font-mono text-[11px] text-[#11a4d4]`,title:e.piboContext,children:DQ(e.piboContext,140)}):null,(0,U.jsx)(`div`,{className:`truncate font-mono text-[11px] text-slate-500`,title:e.url,children:EQ(e.url)}),(0,U.jsxs)(`div`,{className:`truncate font-mono text-[11px] text-slate-500`,title:jIe(e),children:[`Source `,AIe(e)]}),(0,U.jsx)(`div`,{className:`mt-1 line-clamp-2 text-slate-400`,title:e.note,children:DQ(e.note,180)}),(0,U.jsx)(`div`,{className:`mt-1 text-[11px] text-slate-600`,children:MIe(e.createdAt)})]},e.id)})}):(0,U.jsx)(`div`,{className:`rounded-sm border border-slate-800 bg-[#0e1116] px-3 py-2 text-xs text-slate-500`,"data-pibo-debug":`web-annotations-empty`,children:`No open annotations for this session.`})]})]}):null}function DIe({piboSessionId:e,piboRoomId:t,disabled:n,onError:r}){let[i,a]=(0,H.useState)(``),[o,s]=(0,H.useState)(()=>xIe()),[c,l]=(0,H.useState)([]),[u,d]=(0,H.useState)(`idle`),[f,p]=(0,H.useState)(!1),[m,h]=(0,H.useState)(null);(0,H.useEffect)(()=>{SIe(o)},[o]);let g=async()=>{if(e){d(`loading`),h(null);try{let e=await vIe(o);l(e.targets.filter(e=>e.type===`page`||e.attachable)),d(`loaded`)}catch(e){let t=wQ(e,`CDP unavailable`);l([]),d(`error`),h({kind:`error`,message:t}),r(t)}}},_=async n=>{if(!e)throw Error(`No active session context`);return yIe(n.binding.id,CQ({piboSessionId:e,piboRoomId:t,cdpUrl:o,annotationShortcut:pQ()}))},v=async()=>{if(!(!e||f)){p(!0),h({kind:`info`,message:`Injecting annotation overlay into this Pibo page…`});try{let n=await oQ({piboSessionId:e,piboRoomId:t,url:window.location.href,title:document.title,sameOrigin:!0,annotationShortcut:pQ()});if(!n.overlay)throw Error(`Overlay config missing from same-origin binding response`);await kIe(n.overlay),h({kind:`success`,message:`Annotation overlay is ready on this Pibo page. Open the overlay controls or use the shortcut to start annotating.`}),r(null)}catch(e){let t=wQ(e,`Current-page annotation failed`);h({kind:`error`,message:t}),r(t)}finally{p(!1)}}},y=async()=>{if(!e||f)return;let n=i.trim();if(!n){h({kind:`error`,message:`URL is required`});return}if(OIe(n)){let e=`That looks like a CDP endpoint. Put it in CDP URL, and put the page you want to annotate in Annotate URL.`;h({kind:`error`,message:e}),r(e);return}p(!0),h({kind:`info`,message:`Opening target and injecting overlay…`});try{let i=await oQ(CQ({piboSessionId:e,piboRoomId:t,url:n,cdpUrl:o})),s=await _(i);h({kind:`success`,message:`Annotation overlay injected for ${TQ(s.target??i.target,s.binding.url)}`}),a(``),r(null)}catch(e){let t=wQ(e,`Annotation failed`);h({kind:`error`,message:t}),r(t)}finally{p(!1)}},b=async n=>{if(!(!e||f)){p(!0),h({kind:`info`,message:`Binding selected target and injecting overlay…`});try{let i=await oQ(CQ({piboSessionId:e,piboRoomId:t,targetId:n.id,cdpUrl:o})),a=await _(i);h({kind:`success`,message:`Annotation overlay injected for ${TQ(a.target??n,a.binding.url)}`}),r(null)}catch(e){let t=wQ(e,n.attachable?`Target annotation failed`:`Target not attachable`);h({kind:`error`,message:t}),r(t)}finally{p(!1)}}};return(0,U.jsxs)(`section`,{className:`border-b border-slate-800 bg-[#0e1116] p-3 text-sm sm:p-4`,"data-pibo-debug":`web-annotations-entry`,"data-pibo-session-id":e??void 0,children:[(0,U.jsxs)(`div`,{className:`mb-2 flex items-start gap-2`,children:[(0,U.jsx)(Is,{size:15,className:`mt-0.5 shrink-0 text-[#11a4d4]`}),(0,U.jsxs)(`div`,{children:[(0,U.jsx)(`div`,{className:`text-xs font-bold uppercase tracking-wider text-[#11a4d4]`,children:`Web Annotations`}),(0,U.jsx)(`div`,{className:`mt-1 text-xs text-slate-500`,children:`Start an inactive overlay for this Pibo page, or bind a CDP target for external pages.`})]})]}),(0,U.jsx)(`button`,{type:`button`,onClick:()=>void v(),disabled:f||n,className:`mb-3 h-10 w-full rounded-sm bg-emerald-600 px-3 text-xs font-medium text-white hover:bg-emerald-500 disabled:opacity-50 sm:h-9`,"data-pibo-debug":`web-annotations-current-page`,children:`Annotate this Pibo page`}),(0,U.jsx)(`label`,{className:`mb-2 block text-[11px] font-bold uppercase tracking-wider text-slate-500`,htmlFor:`web-annotation-url`,children:`Annotate URL via CDP`}),(0,U.jsxs)(`div`,{className:`grid grid-cols-1 gap-2 sm:grid-cols-[1fr_auto]`,children:[(0,U.jsx)(`input`,{id:`web-annotation-url`,value:i,onChange:e=>a(e.target.value),onKeyDown:e=>{e.key===`Enter`&&y()},placeholder:`http://localhost:5173`,disabled:f||n,className:`h-10 min-w-0 rounded-sm border border-slate-700 bg-[#151f24] px-2 text-base text-slate-100 outline-none focus:border-[#11a4d4] disabled:opacity-60 sm:h-9 sm:text-xs`}),(0,U.jsx)(`button`,{type:`button`,onClick:()=>void y(),disabled:f||n||!i.trim(),className:`h-10 rounded-sm bg-[#11a4d4] px-3 text-xs font-medium text-white disabled:opacity-50 sm:h-9`,children:`Annotate`})]}),(0,U.jsx)(`label`,{className:`mt-3 mb-1 block text-[11px] font-bold uppercase tracking-wider text-slate-500`,htmlFor:`web-annotation-cdp-url`,children:`CDP URL (optional)`}),(0,U.jsx)(`input`,{id:`web-annotation-cdp-url`,value:o,onChange:e=>s(e.target.value),placeholder:`Use gateway default`,disabled:f||n,className:`h-10 w-full rounded-sm border border-slate-800 bg-[#151f24] px-2 font-mono text-base text-slate-300 outline-none focus:border-[#11a4d4] disabled:opacity-60 sm:h-8 sm:text-[11px]`}),(0,U.jsxs)(`div`,{className:`mt-3 flex items-center justify-between gap-2`,children:[(0,U.jsx)(`div`,{className:`text-[11px] font-bold uppercase tracking-wider text-slate-500`,children:`Existing targets`}),(0,U.jsxs)(`button`,{type:`button`,onClick:()=>void g(),disabled:f||n||u===`loading`,className:`inline-flex h-7 items-center gap-1 rounded-sm border border-slate-700 px-2 text-[11px] text-slate-300 hover:border-[#11a4d4] hover:text-[#11a4d4] disabled:opacity-50`,children:[(0,U.jsx)(ol,{size:12,className:u===`loading`?`animate-spin`:void 0}),` Refresh`]})]}),(0,U.jsxs)(`div`,{className:`mt-2 rounded-sm border border-slate-800`,children:[u===`idle`?(0,U.jsx)(`div`,{className:`px-3 py-3 text-xs text-slate-500`,children:`Refresh to list reachable browser targets.`}):null,u===`loading`?(0,U.jsx)(`div`,{className:`px-3 py-3 text-xs text-slate-400`,children:`Loading targets…`}):null,u===`loaded`&&!c.length?(0,U.jsx)(`div`,{className:`px-3 py-3 text-xs text-slate-500`,children:`No attachable browser targets found.`}):null,c.map(e=>(0,U.jsxs)(`div`,{className:`grid grid-cols-1 gap-2 border-b border-slate-800 px-3 py-2 last:border-b-0 sm:grid-cols-[1fr_auto]`,children:[(0,U.jsxs)(`div`,{className:`min-w-0`,children:[(0,U.jsx)(`div`,{className:`truncate text-xs text-slate-200`,title:e.title||e.url,children:DQ(e.title||`Untitled target`,120)}),(0,U.jsx)(`div`,{className:`truncate font-mono text-[11px] text-slate-500`,title:e.url,children:DQ(e.url||e.id,160)})]}),(0,U.jsx)(`button`,{type:`button`,onClick:()=>void b(e),disabled:f||!e.attachable,title:e.attachable?`Attach selected target`:`Target is not attachable`,className:`h-9 rounded-sm border border-slate-700 px-2 text-[11px] text-slate-300 hover:border-[#11a4d4] hover:text-[#11a4d4] disabled:opacity-40 sm:h-8`,children:`Attach`})]},e.id))]}),m?(0,U.jsx)(`div`,{className:`mt-2 rounded-sm border px-2 py-2 text-xs ${m.kind===`error`?`border-red-900 bg-red-950/40 text-red-200`:m.kind===`success`?`border-emerald-900/60 bg-emerald-950/30 text-emerald-300`:`border-slate-700 bg-[#151f24] text-slate-300`}`,children:m.message}):null]})}function CQ(e){return Object.fromEntries(Object.entries(e).filter(([,e])=>e&&e.trim()))}function OIe(e){try{let t=new URL(e);return t.port===`56663`||t.pathname.startsWith(`/json/`)}catch{return!1}}function kIe(e){return new Promise((t,n)=>{let r=window;try{r.__piboWebAnnotations?.remove?.(),r.__piboWebAnnotationConfig=e;let i=document.createElement(`script`);i.src=`/apps/web-annotations/overlay.js?ts=${Date.now()}`,i.async=!0,i.onload=()=>t(),i.onerror=()=>n(Error(`Could not load Web Annotation overlay script`)),document.head.appendChild(i)}catch(e){n(e)}})}function wQ(e,t){let n=NIe(e);return!n||n===`undefined`?t:/target.*not found|selected cdp target/i.test(n)?`Target not found: ${n}`:/inject|overlay|evaluation/i.test(n)?`Injection failed: ${n}`:/cdp endpoint.*is unreachable|failed to fetch|fetch failed|chrome target discovery|cdp unavailable|econnrefused|connect/i.test(n)?`CDP unavailable: ${n}`:`${t}: ${n}`}function TQ(e,t){let n=e?.url||t||e?.title||`target`;return EQ(e?.title||n)}function EQ(e){try{let t=new URL(e);return`${t.host}${t.pathname===`/`?``:t.pathname}`}catch{return DQ(e,80)}}function AIe(e){return e.piboRoomId?`${DQ(e.piboSessionId,24)} · room ${DQ(e.piboRoomId,18)}`:DQ(e.piboSessionId,44)}function jIe(e){return e.piboRoomId?`Session ${e.piboSessionId} in room ${e.piboRoomId}`:`Session ${e.piboSessionId}`}function DQ(e,t){return e.length>t?`${e.slice(0,Math.max(0,t-1))}…`:e}function MIe(e){let t=new Date(e);return Number.isNaN(t.getTime())?e:t.toLocaleString(void 0,{dateStyle:`short`,timeStyle:`short`})}function NIe(e){return e instanceof Error?e.message:String(e)}function OQ(e){return e.session?.profile??e.agents[0]?.name??e.customAgents[0]?.profileName??``}function PIe(e){return e?.identity??{userId:`user`}}function FIe(e,t){let n=LIe(e,t);return n?IIe(n):void 0}function kQ(e,t){for(let n of e){if(n.piboSessionId===t)return n;let e=kQ(n.children,t);if(e)return e}}function AQ(e,t,n=[]){for(let r of e){let e=[...n,r];if(r.piboSessionId===t)return e;let i=AQ(r.children,t,e);if(i.length)return i}return[]}function jQ(){let e=globalThis.crypto?.randomUUID?.()??Math.random().toString(36).slice(2);return`web-${Date.now().toString(36)}-${e}`}function MQ(e,t){return!e||e.startsWith(`optimistic-session-`)||t}function IIe(e){return`${e.provider}/${e.id}`}function LIe(e,t){if(t.activeModel)return t.activeModel;let n=e.agents.find(e=>e.name===t.profile);if(n?.model)return n.model;let r=e.customAgents.find(e=>e.profileName===t.profile),i=n??r;return t.parentId?i?.subagentModel??e.modelDefaults?.subagent:i?.mainModel??e.modelDefaults?.main}var NQ=new WeakMap;function RIe(e,t,n){let r=n.map(e=>PQ(e)),i=IQ(r),a=i.length?Math.min(...i.map(e=>e.startTime)):Date.now()*1e3,o=i.flatMap(e=>e.endTime?[e.endTime]:[]),s=o.length?Math.max(...o):void 0,c=i.some(e=>e.status===`UNSET`);return{id:e,name:t,status:i.some(e=>e.status===`ERROR`)?`ERROR`:c?`UNSET`:`OK`,spans:r,startedAt:new Date(a/1e3),completedAt:s?new Date(s/1e3):void 0,totalDurationMs:s?(s-a)/1e3:0}}function PQ(e){let t=NQ.get(e);if(t)return t;let n=FQ(e.startedAt)??Date.now()*1e3,r=FQ(e.completedAt),i=UIe(e.status),a=zIe(e.type),o={id:e.id,parentId:e.parentId,name:BIe(e),spanType:a,startTime:n,endTime:r,durationUs:e.durationMs===void 0?void 0:e.durationMs*1e3,attributes:VIe(e),status:i,statusMessage:e.error,events:e.error?[{name:`exception`,timestamp:r??n,attributes:{message:e.error}}]:[],children:e.children?.map(PQ),pibo:{entryId:e.entryId,linkedPiboSessionId:e.linkedPiboSessionId,traceNodeType:e.type,traceOrder:e.orderKey,stableKey:e.stableKey,source:e.source}};return NQ.set(e,o),o}function zIe(e){switch(e){case`user.message`:return`user.prompt`;case`assistant.message`:return`model.response`;case`model.reasoning`:return`model.reasoning`;case`tool.call`:return`tool.call`;case`tool.result`:return`tool.result`;case`agent.delegation`:return`agent.delegation`;case`agent.async`:return`agent.async`;case`execution.command`:case`execution.compaction`:return`execution.command`;case`yielded.run`:return`yielded.run`;case`agent.turn`:return`agent.run`;case`error`:return`tool.result`}}function BIe(e){return e.type===`assistant.message`?`assistant_message`:e.type===`user.message`?`user_prompt`:e.type===`model.reasoning`?`model_reasoning`:e.title||e.type}function VIe(e){let t={};if(e.summary&&(t.content=e.summary),e.input!==void 0&&(t.input=e.input,t.args=e.input,t.arguments=e.input),e.output!==void 0&&(t.output=e.output,t.result=e.output),e.error&&(t.error=e.error),e.toolCallId&&(t.tool_call_id=e.toolCallId),e.runId&&(t.run_id=e.runId),e.intent&&(t.intent=e.intent),(e.type===`tool.call`||e.type===`agent.delegation`)&&(t.tool_name=e.title),e.type===`assistant.message`&&(t.content=e.output??e.summary??``),e.type===`user.message`){t.content=e.output??e.summary??``;let n=HIe(e);n&&(t[`message.pending_delivery`]=n)}return e.type===`model.reasoning`&&(t.reasoning=e.output??e.summary??``),e.type===`agent.delegation`&&(t[`delegation.target_agent`]=LQ(e.input)&&typeof e.input.name==`string`?e.input.name:e.title.replace(/^pibo_agents_send_message$/,`agent`).replace(/^pibo_subagent_/,``),t[`delegation.query`]=e.summary??e.input,t[`result.status`]=e.status===`done`?`completed`:e.status,t.linked_pibo_session_id=e.linkedPiboSessionId),e.type===`agent.async`&&(t[`async_agent.target_agent`]=e.title,t[`async_agent.started_by`]=LQ(e.input)?e.input.startedBy:`pibo_run_start`,t[`async_agent.query`]=LQ(e.input)?e.input.arguments:e.input,t[`result.status`]=e.status===`done`?`started`:e.status,t.linked_pibo_session_id=e.linkedPiboSessionId),e.type===`yielded.run`&&(t[`run.notification`]=!0,t[`run.status`]=e.status),t}function HIe(e){if(e.type===`user.message`&&e.status===`running`){if(e.id.startsWith(`event:message_steered:`))return`steer`;if(e.id.startsWith(`event:message_queued:`))return`queue`}}function UIe(e){return e===`running`?`UNSET`:e===`error`?`ERROR`:`OK`}function FQ(e){if(!e)return;let t=new Date(e).getTime();return Number.isFinite(t)?t*1e3:void 0}function IQ(e){return e.flatMap(e=>[e,...e.children?IQ(e.children):[]])}function LQ(e){return!!e&&typeof e==`object`&&!Array.isArray(e)}function WIe(e,t,n){return BQ(e,t,n)?.capabilities.lifecycle.fork===!0}function GIe(e,t,n){return BQ(e,t,n)?.capabilities.lifecycle.forkWhileRunning===!0}function KIe(e){if(!e)return`none`;let t=VQ(e.nodes).filter(e=>e.type===`user.message`);return`${t.length}:${t.at(-1)?.id??``}`}function qIe(e,t){if(!e)return e;let n=VQ(e.nodes).filter(e=>e.type===`user.message`),r=new Set,i=t.filter(e=>!e.entryId.trim()||r.has(e.entryId)?!1:(r.add(e.entryId),!0)),a=new Set(i.map(e=>e.entryId)),o=e=>e.entryId&&a.has(e.entryId)?e.entryId:void 0,s=new Map,c=n.length===i.length&&n.every((e,t)=>!o(e)||o(e)===i[t].entryId),l=i.length<n.length&&i.every((e,t)=>{let r=n[t],i=o(r);return i?i===e.entryId:RQ(r)===e.text});if(c||l)for(let e=0;e<i.length;e+=1)s.set(n[e].id,i[e].entryId);else{let e=new Set(n.flatMap(e=>{let t=o(e);return t?[t]:[]})),t=n.filter(e=>!o(e)),r=new Map,a=new Map;for(let e of t){let t=RQ(e);r.set(t,(r.get(t)??0)+1)}for(let t of i){if(e.has(t.entryId))continue;let n=a.get(t.text);n?n.push(t):a.set(t.text,[t])}for(let e of t){let t=RQ(e),n=a.get(t)??[];r.get(t)===1&&n.length===1&&s.set(e.id,n[0].entryId)}}let u=zQ(e.nodes,s,a);return u.every((t,n)=>t===e.nodes[n])?e:{...e,nodes:u}}function RQ(e){return typeof e.output==`string`?e.output:typeof e.summary==`string`?e.summary:e.title}function zQ(e,t,n){return e.map(e=>{let r=zQ(e.children,t,n),i=t.get(e.id),a=e.type===`user.message`?i??(e.entryId&&n.has(e.entryId)?e.entryId:void 0):e.entryId,o=r.some((t,n)=>t!==e.children[n]);if(a===e.entryId&&!o)return e;let{entryId:s,...c}=e;return{...c,...a?{entryId:a}:{},children:r}})}function BQ(e,t,n){let r=t?kQ(e.sessions,t):void 0,i=e.agents.find(e=>e.name===n),a=e.customAgents.find(e=>e.profileName===n)??i,o=e.session?.id===t?e.session.runtimeBinding:void 0,s=r?.runtimeInstanceId??o?.runtimeInstanceId??a?.runtimeInstanceId;return e.agentCatalog?.agentRuntimes.find(e=>s?e.id===s:r?.runtimeAdapterId?e.adapterId===r.runtimeAdapterId:!1)}function JIe(e,t,n,r){if(r?.latestTurn?.state!==`running`)return!1;let i=BQ(e,t,n);return i?.enabled!==!1&&i?.available!==!1&&i?.capabilities.input?.steering===!0}function YIe(e,t,n){t&&kQ(e.sessions,t);let r=e.agents.find(e=>e.name===n),i=e.customAgents.find(e=>e.profileName===n)??r,a=BQ(e,t,n)?.capabilities.tools.intentTracing;if(!a?.supported)return!1;if(!a.configurable)return!0;let o=(e.session?.id===t?e.session.runtimeBinding:void 0)?.metadata?.intentTracing;if(typeof o==`boolean`)return o;let s=i?.runtimeOptions?.intentTracing;return typeof s==`boolean`?s:a.enabledByDefault}function XIe(e){return(e.selectedPiboSessionId?kQ(e.sessionNodes,e.selectedPiboSessionId):void 0)?.title||e.traceTitle||e.selectedPiboSessionId||e.fallback}function ZIe(e,t){return t?{sessionBreadcrumbs:nLe(e,t),originSession:eLe(e,t),derivedSessions:tLe(e,t)}:{sessionBreadcrumbs:[],originSession:void 0,derivedSessions:[]}}function QIe(e){let t=e.selectedPiboSessionId?kQ(e.bootstrap.sessions,e.selectedPiboSessionId):void 0,n=oLe(e.currentTraceView);return aLe(e.selectedSessionActiveModel,e.bootstrap.runtimeStatus?.thinkingLevel??n.level??t?.initialThinkingLevel??rLe(e.bootstrap,e.selectedSessionProfile,!!t?.parentId),e.bootstrap.runtimeStatus?.fastMode??n.fast??iLe(e.bootstrap,e.selectedSessionProfile,!!t?.parentId)??!1)}function $Ie(e){return{traceView:e.currentTraceView,selectedTrace:e.currentTraceView?RIe(e.currentTraceView.piboSessionId,e.currentTraceView.title,e.currentTraceView.nodes):null,isLoading:e.isLoading,showThinking:e.showThinking,debugMode:e.debugMode,toolMetricThresholds:e.toolMetricThresholds,expandThinking:e.expandThinking,toolDisplayMode:e.toolDisplayMode,sessionAgentProfile:e.selectedSessionProfile,sessionActiveModel:e.sessionActiveModelBadge,sessionRuntimeBinding:e.sessionRuntimeBinding,selectedSessionStatus:e.selectedSessionStatus,selectedSessionSignal:e.selectedSessionSignal,signals:e.signals,sessionGoal:e.sessionGoal,selectedPiboSessionId:e.selectedPiboSessionId,workflowSessionLinked:e.workflowSessionLinked,sessionNodes:e.sessionNodes,sessionBreadcrumbs:e.sessionLinks.sessionBreadcrumbs,originSession:e.sessionLinks.originSession,derivedSessions:e.sessionLinks.derivedSessions,agentProfiles:e.agentProfiles,sessionProfileChangeDisabled:e.sessionProfileChangeDisabled,onSessionAgentProfileChange:e.onSessionAgentProfileChange,onFork:e.onFork,onOpenSession:e.onOpenSession,onLoadOlderTracePage:e.onLoadOlderTracePage,hasOlderTraceEvents:e.hasOlderTraceEvents,isFetchingOlderTracePage:e.isFetchingOlderTracePage,onThinkingLevelChange:e.onThinkingLevelChange,onModelChanged:async()=>{await e.onRefreshBootstrap(),await e.onRefreshTrace()},onRefreshBootstrap:e.onRefreshBootstrap,onError:e.onError}}function eLe(e,t){let n=kQ(e,t);if(!n?.originId)return;let r=kQ(e,n.originId);return{piboSessionId:n.originId,label:r?HQ(r,0):n.originId}}function tLe(e,t){return kQ(e,t)?.derivedSessions.map(e=>({piboSessionId:e.piboSessionId,label:cLe(e),profile:e.profile,status:e.status}))??[]}function nLe(e,t){return AQ(e,t).map((e,t)=>({piboSessionId:e.piboSessionId,label:HQ(e,t)}))}function rLe(e,t,n=!1){let r=e.agents.find(e=>e.name===t),i=e.customAgents.find(e=>e.profileName===t),a=r??i;return n?a?.subagentThinkingLevel??a?.thinkingLevel??e.modelDefaults?.subagentThinking??e.modelDefaults?.thinking:a?.mainThinkingLevel??a?.thinkingLevel??e.modelDefaults?.mainThinking??e.modelDefaults?.thinking}function iLe(e,t,n=!1){let r=e.agents.find(e=>e.name===t),i=e.customAgents.find(e=>e.profileName===t),a=r??i;return n?a?.subagentFast??a?.fast??e.modelDefaults?.subagentFast??e.modelDefaults?.fast:a?.mainFast??a?.fast??e.modelDefaults?.mainFast??e.modelDefaults?.fast}function aLe(e,t,n){if(e)return[e,t,n?`fast`:void 0].filter(Boolean).join(` `)}function oLe(e){let t={};if(!e)return t;for(let n of VQ(e.nodes)){if(n.type!==`execution.command`||n.title!==`thinking`&&n.title!==`fast_mode`)continue;let e=n.output&&typeof n.output==`object`?n.output:void 0;t={level:(typeof e?.level==`string`&&sLe(e.level)?e.level:void 0)??t.level,fast:n.title===`fast_mode`?e?.mode===`fast`:t.fast}}return t}function VQ(e){return e.flatMap(e=>[e,...VQ(e.children)])}function sLe(e){return Zq.includes(e)}function HQ(e,t){return t?e.subagentName&&e.subagentName!==e.profile?`${e.subagentName} (${e.profile})`:e.profile||e.subagentName||e.title:e.profile||e.title}function cLe(e){return e.subagentName&&e.subagentName!==e.profile?`${e.subagentName} (${e.profile})`:e.title||e.profile||e.subagentName||`Untitled Session`}function lLe({piboSessionId:e,text:t,selectedWebAnnotations:n,selectedUploadAttachments:r,eventSequence:i,now:a,clientTxnId:o,delivery:s=`queue`}){let c=n.map(e=>e.id),l=r.map(e=>e.path),u=s===`steer`?`message_steered`:`message_queued`;return{piboSessionId:e,text:t,webAnnotationIds:c,fileAttachmentPaths:l,clientTxnId:o,delivery:s,optimisticEvent:{id:o,piboSessionId:e,eventSequence:i,eventId:o,type:u,createdAt:a,payload:{type:u,piboSessionId:e,eventId:o,clientTxnId:o,delivery:s,...s===`queue`?{queuedMessages:1}:{},text:t,...l.length?{fileAttachmentPaths:l}:{},source:`user`}}}}function uLe(e,t){if(e.delivery===t)return e;let n=t===`steer`?`message_steered`:`message_queued`,r={...e.optimisticEvent.payload};return delete r.queuedMessages,{...e,delivery:t,optimisticEvent:{...e.optimisticEvent,type:n,payload:{...r,type:n,delivery:t,...t===`queue`?{queuedMessages:1}:{}}}}}function dLe(e,t,n){return{piboSessionId:t,events:[...e?.piboSessionId===t?e.events:[],n]}}var fLe=`optimistic-session-`;function pLe(e){return e?.startsWith(fLe)===!0}function UQ(e){return e&&!pLe(e)?e:null}async function mLe(e){return G(`/api/chat/workflow-sessions`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify(e)})}async function WQ(e){return G(`/api/chat/sessions/${encodeURIComponent(e)}/workflow`,{cache:`no-store`})}async function GQ(e){let t=new URLSearchParams;return e&&t.set(`selectedProfileId`,e),G(`/api/chat/workflows/pickers/profiles${t.size?`?${t.toString()}`:``}`)}async function hLe(e){let t=new URLSearchParams;return e&&t.set(`selectedHandlerId`,e),G(`/api/chat/workflows/pickers/handlers${t.size?`?${t.toString()}`:``}`)}async function gLe(e){let t=new URLSearchParams;return e&&t.set(`selectedRefId`,e),G(`/api/chat/workflows/pickers/guards${t.size?`?${t.toString()}`:``}`)}async function KQ(e){let t=new URLSearchParams;return e&&t.set(`selectedRefId`,e),G(`/api/chat/workflows/pickers/adapters${t.size?`?${t.toString()}`:``}`)}async function qQ(e){let t=new URLSearchParams;return e&&t.set(`selectedRefId`,e),G(`/api/chat/workflows/pickers/human-actions${t.size?`?${t.toString()}`:``}`)}async function _Le(e){let t=new URLSearchParams;return e&&t.set(`selectedRefId`,e),G(`/api/chat/workflows/pickers/prompt-assets${t.size?`?${t.toString()}`:``}`)}async function vLe(e){return G(`/api/chat/workflows/prompt-assets/${encodeURIComponent(e)}`)}async function yLe(e){return G(`/api/chat/workflows/prompt-assets`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify(e)})}async function bLe(e={}){let t=new URLSearchParams;return e.includeArchived&&t.set(`includeArchived`,`true`),G(`/api/chat/workflows${t.size?`?${t.toString()}`:``}`)}async function JQ(e,t,n={}){let r=new URLSearchParams;n.includeArchived&&r.set(`includeArchived`,`true`);let i=r.size?`?${r.toString()}`:``;return G(`/api/chat/workflows/${encodeURIComponent(e)}/versions/${encodeURIComponent(t)}${i}`)}async function YQ(e={}){let t=new URLSearchParams;return e.selectedWorkflowId&&t.set(`selectedWorkflowId`,e.selectedWorkflowId),e.selectedWorkflowVersion&&t.set(`selectedWorkflowVersion`,e.selectedWorkflowVersion),G(`/api/chat/workflows/pickers/workflow-versions${t.size?`?${t.toString()}`:``}`)}async function xLe(e={}){let t=new URLSearchParams;return e.selectedWorkflowId&&t.set(`selectedWorkflowId`,e.selectedWorkflowId),e.selectedWorkflowVersion&&t.set(`selectedWorkflowVersion`,e.selectedWorkflowVersion),G(`/api/chat/workflows/pickers/version-history${t.size?`?${t.toString()}`:``}`)}async function SLe(e){return G(`/api/chat/sessions/${encodeURIComponent(e)}/workflow/start`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({})})}async function CLe(e,t){return G(`/api/chat/sessions/${encodeURIComponent(e)}/workflow/human-actions`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify(t)})}async function wLe(e){return G(`/api/chat/workflows`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify(e)})}async function TLe(e){return G(`/api/chat/workflows/drafts/${encodeURIComponent(e)}`)}async function XQ(e,t){return G(`/api/chat/workflows/drafts/${encodeURIComponent(e)}`,{method:`PATCH`,headers:{"content-type":`application/json`},body:JSON.stringify(t)})}async function ELe(e,t){return G(`/api/chat/workflows/drafts/${encodeURIComponent(e)}/manual-trigger-runs`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify(t)})}async function DLe(e,t={}){return G(`/api/chat/workflows/${encodeURIComponent(e)}/duplicate`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify(t)})}function ZQ(e){return e instanceof Error?e.message:String(e)}var OLe=[`(display-mode: standalone)`,`(display-mode: window-controls-overlay)`];function kLe(e,t){return OLe.some(t=>e(t).matches)?typeof t.userAgentData?.mobile==`boolean`?!t.userAgentData.mobile:!(/Android|iPhone|iPad|iPod|Mobile/i.test(t.userAgent)||/Macintosh/i.test(t.userAgent)&&t.maxTouchPoints>1):!1}function ALe(){return typeof window<`u`&&typeof navigator<`u`&&kLe(window.matchMedia.bind(window),navigator)}function jLe(e,t){return{url:e,name:`pibo-session-${t}`,features:`width=1280,height=900`}}function MLe(){let e=jLe(window.location.href,crypto.randomUUID());return window.open(e.url,e.name,e.features)}var NLe=[{id:`accept`,label:`Approve once`},{id:`acceptForSession`,label:`Approve for session`},{id:`decline`,label:`Decline`},{id:`cancel`,label:`Cancel turn`}];function QQ({piboSessionId:e,approvals:t,userInputs:n,onResolved:r,onError:i}){let[a,o]=(0,H.useState)(null);if(t.length===0&&n.length===0)return null;let s=async(t,n)=>{if(!a){o(t),i(null);try{await Yl(e,`runtime.approval.respond`,{requestId:t,decision:n}),r(t)}catch(e){i(ZQ(e))}finally{o(null)}}},c=async(t,n)=>{if(!a){o(t),i(null);try{await Yl(e,`runtime.user_input.respond`,{requestId:t,answers:n}),r(t)}catch(e){i(ZQ(e))}finally{o(null)}}};return(0,U.jsx)(`section`,{className:`border-t border-slate-800 bg-[#101d22] px-3 py-2 sm:px-4`,"data-pibo-debug":`runtime-request-panel`,"aria-label":`Runtime requests`,children:(0,U.jsxs)(`div`,{className:`mx-auto grid w-full max-w-4xl gap-2`,children:[t.map(e=>(0,U.jsx)(PLe,{request:e,busy:a===e.requestId,disabled:a!==null,onDecision:t=>void s(e.requestId,t)},e.requestId)),n.map(e=>(0,U.jsx)(FLe,{request:e,busy:a===e.requestId,disabled:a!==null,onSubmit:t=>void c(e.requestId,t)},e.requestId))]})})}function PLe({request:e,busy:t,disabled:n,onDecision:r}){let i=e.decisions?.length?e.decisions:NLe;return(0,U.jsxs)(`article`,{className:`rounded-sm border border-amber-500/40 bg-amber-500/5`,"data-pibo-debug":`runtime-approval-request`,children:[(0,U.jsxs)(`div`,{className:`flex items-start gap-3 border-b border-amber-500/20 px-3 py-2`,children:[(0,U.jsx)(gl,{size:16,className:`mt-0.5 shrink-0 text-amber-400`,"aria-hidden":`true`}),(0,U.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,U.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,U.jsx)(`h3`,{className:`text-xs font-bold uppercase tracking-wider text-amber-300`,children:e.title||`Approval required`}),(0,U.jsx)(`span`,{className:`rounded-sm border border-slate-700 px-1.5 py-0.5 font-mono text-[10px] uppercase text-slate-400`,children:e.requestType})]}),e.detail?(0,U.jsx)(`p`,{className:`mt-1 text-xs leading-5 text-slate-300`,children:e.detail}):null]})]}),e.arguments===void 0?null:(0,U.jsx)(`pre`,{className:`max-h-36 overflow-auto border-b border-slate-800 bg-[#0e1116] px-3 py-2 font-mono text-[11px] leading-5 text-slate-300`,children:RLe(e.arguments)}),(0,U.jsx)(`div`,{className:`flex flex-wrap gap-2 px-3 py-2`,children:i.map(e=>(0,U.jsx)(`button`,{type:`button`,onClick:()=>r(e.id),disabled:n,title:e.description,className:LLe(e.id),"data-pibo-decision":e.id,children:t?`Responding…`:e.label},e.id))})]})}function FLe({request:e,busy:t,disabled:n,onSubmit:r}){let[i,a]=(0,H.useState)({}),o=(0,H.useMemo)(()=>e.questions.every(e=>!!i[e.id]?.trim()),[i,e.questions]);return(0,U.jsxs)(`article`,{className:`rounded-sm border border-cyan-500/40 bg-cyan-500/5`,"data-pibo-debug":`runtime-user-input-request`,children:[(0,U.jsxs)(`div`,{className:`flex items-start gap-3 border-b border-cyan-500/20 px-3 py-2`,children:[(0,U.jsx)(nc,{size:16,className:`mt-0.5 shrink-0 text-cyan-400`,"aria-hidden":`true`}),(0,U.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,U.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,U.jsx)(`h3`,{className:`text-xs font-bold uppercase tracking-wider text-cyan-300`,children:`Input requested`}),(0,U.jsx)(`span`,{className:`rounded-sm border border-slate-700 px-1.5 py-0.5 font-mono text-[10px] uppercase text-slate-400`,children:e.blocking===!1?`non-blocking`:`blocking`})]}),(0,U.jsx)(`p`,{className:`mt-1 text-xs leading-5 text-slate-400`,children:`Codex is waiting for structured input before continuing this turn.`})]})]}),(0,U.jsx)(`div`,{className:`grid gap-3 px-3 py-3`,children:e.questions.map(t=>(0,U.jsx)(ILe,{question:t,groupName:`runtime-question-${e.requestId}-${t.id}`,value:i[t.id]??``,disabled:n,onChange:e=>a(n=>({...n,[t.id]:e}))},t.id))}),(0,U.jsx)(`div`,{className:`flex justify-end border-t border-cyan-500/20 px-3 py-2`,children:(0,U.jsx)(`button`,{type:`button`,onClick:()=>r(i),disabled:n||!o,className:`rounded-sm border border-[#11a4d4] bg-[#11a4d4] px-3 py-1.5 text-xs font-semibold text-white transition hover:bg-[#0d8eb8] disabled:cursor-not-allowed disabled:opacity-50`,children:t?`Submitting…`:`Submit response`})})]})}function ILe({question:e,groupName:t,value:n,disabled:r,onChange:i}){let a=e.options??[],o=new Set(a.map(e=>e.label)),s=!!n&&!o.has(n);return(0,U.jsxs)(`fieldset`,{className:`grid gap-2`,disabled:r,children:[(0,U.jsxs)(`legend`,{className:`text-xs font-semibold text-slate-200`,children:[e.header?(0,U.jsx)(`span`,{className:`mr-2 font-mono uppercase text-cyan-400`,children:e.header}):null,e.question]}),a.length?(0,U.jsxs)(`div`,{className:`grid gap-1.5 sm:grid-cols-2`,children:[a.map(e=>(0,U.jsxs)(`label`,{className:`flex cursor-pointer gap-2 rounded-sm border border-slate-700 bg-[#151f24] px-2.5 py-2 text-xs hover:border-cyan-500/60`,children:[(0,U.jsx)(`input`,{type:`radio`,name:t,value:e.label,checked:n===e.label,onChange:()=>i(e.label),className:`mt-0.5 accent-[#11a4d4]`}),(0,U.jsxs)(`span`,{children:[(0,U.jsx)(`span`,{className:`block font-semibold text-slate-200`,children:e.label}),e.description?(0,U.jsx)(`span`,{className:`mt-0.5 block leading-4 text-slate-400`,children:e.description}):null]})]},e.label)),e.allowFreeform?(0,U.jsxs)(`label`,{className:`flex cursor-pointer gap-2 rounded-sm border border-slate-700 bg-[#151f24] px-2.5 py-2 text-xs hover:border-cyan-500/60`,children:[(0,U.jsx)(`input`,{type:`radio`,name:t,checked:s,onChange:()=>i(`Other`),className:`mt-0.5 accent-[#11a4d4]`}),(0,U.jsx)(`span`,{className:`font-semibold text-slate-200`,children:`Other`})]}):null]}):null,a.length===0||e.allowFreeform&&s?(0,U.jsx)(`input`,{type:e.secret?`password`:`text`,value:s&&n===`Other`?``:n,onChange:e=>i(e.target.value),autoComplete:`off`,placeholder:e.secret?`Enter a private response`:`Enter a response`,className:`w-full rounded-sm border border-slate-700 bg-[#0e1116] px-2.5 py-2 font-mono text-xs text-slate-200 outline-none focus:border-[#11a4d4] focus:ring-1 focus:ring-[#11a4d4]/40`}):null]})}function LLe(e){let t=`rounded-sm border px-2.5 py-1.5 text-xs font-semibold transition disabled:cursor-not-allowed disabled:opacity-50`;return e===`accept`?`${t} border-emerald-500/60 bg-emerald-500/10 text-emerald-300 hover:bg-emerald-500/20`:e===`acceptForSession`?`${t} border-cyan-500/60 bg-cyan-500/10 text-cyan-300 hover:bg-cyan-500/20`:e===`cancel`?`${t} border-red-500/60 bg-red-500/10 text-red-300 hover:bg-red-500/20`:`${t} border-slate-600 bg-slate-800/60 text-slate-300 hover:border-slate-500`}function RLe(e){if(typeof e==`string`)return e;try{return JSON.stringify(e,null,2)}catch{return`[unavailable]`}}async function zLe(e,t={}){return G(`/api/previews?piboSessionId=${encodeURIComponent(e)}`,{signal:t.signal})}function BLe(e,t){let n=new URLSearchParams({piboSessionId:e}),r=new EventSource(`/api/previews/events?${n.toString()}`);return r.addEventListener(`preview-created`,n=>{try{let r=JSON.parse(n.data);r.type===`preview-created`&&r.preview?.piboSessionId===e&&t(r)}catch{}}),()=>r.close()}async function VLe(e){return(await G(`/api/previews/${encodeURIComponent(e)}/start`,{method:`POST`,headers:{"content-type":`application/json`},body:`{}`})).preview}async function HLe(e){return(await G(`/api/previews/${encodeURIComponent(e)}/stop`,{method:`POST`,headers:{"content-type":`application/json`},body:`{}`})).preview}async function ULe(e){return G(`/api/previews/${encodeURIComponent(e)}`,{method:`DELETE`,headers:{"content-type":`application/json`}})}function WLe(e){let t=e.selectedPiboSessionId;return t?e.error?{kind:`error`,piboSessionId:t,previews:[],message:e.error}:e.loading||e.data?.piboSessionId!==t?{kind:`loading`,piboSessionId:t,previews:[]}:e.data.configured?e.data.previews.length===0?{kind:`empty`,piboSessionId:t,previews:[]}:{kind:`ready`,piboSessionId:t,previews:e.data.previews}:{kind:`unconfigured`,piboSessionId:t,previews:[]}:{kind:`idle`,previews:[]}}function GLe(e,t){if(e.kind===`ready`)return t?.piboSessionId===e.piboSessionId?e.previews.find(e=>e.id===t.previewId)??e.previews[0]:e.previews[0]}function KLe(e,t){if(t.piboSessionId!==e)throw Error(`Preview lifecycle response belongs to a different Pibo Session`);return t}function $Q(e){return e===`online`?`border-emerald-500/50 bg-emerald-500/10 text-emerald-300`:e===`starting`||e===`stopping`?`border-cyan-500/50 bg-cyan-500/10 text-cyan-300`:e===`offline`||e===`error`?`border-amber-500/50 bg-amber-500/10 text-amber-300`:`border-slate-600 bg-slate-800 text-slate-400`}function e$(e){e.health===`online`&&window.open(e.openUrl,`_blank`,`noopener,noreferrer`)}function qLe(e,t){let n=new URL(e.openUrl,window.location.origin);return n.searchParams.set(`piboPreviewReload`,String(t)),n.toString()}function t$({previews:e,selectedPreview:t,loading:n,error:r,reloadKey:i,fullscreen:a=!1,actionPending:o=!1,onSelect:s,onReload:c,onRefresh:l,onStart:u,onStop:d,onRemove:f,onEnterFullscreen:p,onExitFullscreen:m}){let[h,g]=(0,H.useState)(!1),_=(0,H.useRef)(m);if(_.current=m,(0,H.useEffect)(()=>{a&&!t&&_.current?.()},[a,t]),n)return(0,U.jsx)(i$,{label:`Loading live previews…`});if(r)return(0,U.jsx)(i$,{label:r,tone:`error`});if(!t)return(0,U.jsx)(i$,{label:`No active live preview is attached to this Pibo Session.`});let v=t.health===`online`,y=t.managed&&[`running`,`starting`,`stopping`].includes(t.serverState??``),b=t.managed&&!y,x=t.managed&&t.serverState!==`stopping`&&y;return(0,U.jsxs)(`section`,{"data-pibo-debug":`session-live-preview`,"data-pibo-preview-id":t.id,"data-pibo-preview-session-id":t.piboSessionId,"data-pibo-preview-public-origin":new URL(t.publicUrl).origin,"data-pibo-preview-fullscreen":a?`true`:`false`,className:`min-h-0 flex-1 bg-[#0e1116] flex flex-col`,children:[a&&m?(0,U.jsx)(n$,{preview:t,actionPending:o,onReload:c,onStart:()=>u(t.id),onStop:()=>d(t.id),onExit:m}):a?null:(0,U.jsxs)(`div`,{className:`min-h-11 border-b border-slate-800 bg-[#151f24] px-3 flex items-center gap-2 max-[640px]:flex-wrap max-[640px]:py-1.5`,children:[(0,U.jsx)(`label`,{className:`sr-only`,htmlFor:`session-live-preview-select`,children:`Selected live preview`}),(0,U.jsx)(`select`,{id:`session-live-preview-select`,name:`session-live-preview`,value:t.id,onChange:e=>s(e.target.value),"aria-label":`Selected live preview`,className:`min-w-0 max-w-72 h-8 border border-slate-700 bg-[#0e1116] px-2 text-xs text-slate-200 focus:border-[#11a4d4] focus:outline-none`,children:e.map(e=>(0,U.jsx)(`option`,{value:e.id,children:e.label},e.id))}),(0,U.jsx)(`span`,{className:`rounded-sm border px-2 py-1 text-[10px] font-bold uppercase tracking-wider ${$Q(t.health)}`,children:t.health}),(0,U.jsx)(`span`,{className:`min-w-0 flex-1 truncate font-mono text-[11px] text-slate-500`,children:t.serverStopAt&&y?`stops ${YLe(t.serverStopAt)}`:`session-linked`}),(0,U.jsx)(r$,{label:`Refresh preview status`,onClick:l,children:(0,U.jsx)(ol,{size:14})}),b?(0,U.jsx)(r$,{label:`Start Preview server`,disabled:o,onClick:()=>u(t.id),children:(0,U.jsx)(nl,{size:14})}):null,x?(0,U.jsx)(r$,{label:`Stop Preview server`,disabled:o,onClick:()=>d(t.id),children:(0,U.jsx)(xl,{size:13})}):null,(0,U.jsx)(r$,{label:`Reload live preview`,disabled:!v,onClick:c,children:(0,U.jsx)(ol,{size:14})}),(0,U.jsx)(r$,{label:h?`Copied preview link`:`Copy authenticated preview link`,disabled:!v,onClick:()=>{v&&Rq(new URL(t.openUrl,window.location.origin).toString()).then(()=>{g(!0),window.setTimeout(()=>g(!1),900)})},children:(0,U.jsx)(sc,{size:14})}),(0,U.jsx)(r$,{label:`Open live preview in new window`,disabled:!v,onClick:()=>e$(t),children:(0,U.jsx)(fc,{size:14})}),p?(0,U.jsx)(r$,{label:`Enter Preview fullscreen`,disabled:!v,onClick:p,children:(0,U.jsx)(Lc,{size:14})}):null,(0,U.jsx)(r$,{label:`Remove live preview`,danger:!0,disabled:o,onClick:()=>f(t.id),children:(0,U.jsx)(Cl,{size:14})})]}),v?(0,U.jsx)(`iframe`,{title:`Live preview: ${t.label}`,src:qLe(t,i),sandbox:`allow-scripts allow-same-origin allow-forms allow-downloads allow-modals allow-popups allow-pointer-lock`,referrerPolicy:`no-referrer`,className:`min-h-0 flex-1 w-full border-0 bg-white`,"data-pibo-debug":`session-live-preview-frame`},`${t.piboSessionId}:${t.id}:${i}`):(0,U.jsx)(JLe,{preview:t,actionPending:o,onStart:()=>u(t.id)})]})}function n$({preview:e,actionPending:t=!1,onReload:n,onStart:r,onStop:i,onExit:a}){let o=(0,H.useRef)(null),s=(0,H.useRef)(a);s.current=a,(0,H.useEffect)(()=>{let e=document.activeElement instanceof HTMLElement?document.activeElement:void 0,t=()=>{let t=document.querySelector(`[data-pibo-debug="session-live-preview"] [aria-label="Enter Preview fullscreen"]`);t?t.focus():e?.isConnected&&e.focus()};o.current?.focus();let n=e=>{e.key===`Escape`&&(e.preventDefault(),s.current())};return window.addEventListener(`keydown`,n,!0),()=>{window.removeEventListener(`keydown`,n,!0),window.setTimeout(t,0)}},[]);let c=e.health===`online`,l=e.managed&&[`running`,`starting`,`stopping`].includes(e.serverState??``);return(0,U.jsxs)(`div`,{"data-pibo-debug":`preview-fullscreen-top-bar`,className:`h-8 min-h-8 flex items-center gap-2 border-b border-slate-600 bg-[#151f24] px-2`,children:[(0,U.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-sm font-semibold`,children:e.label}),(0,U.jsx)(`span`,{className:`rounded-sm border px-1.5 py-0.5 text-[9px] font-bold uppercase tracking-wider ${$Q(e.health)}`,children:e.health}),e.managed&&!l?(0,U.jsx)(r$,{label:`Start Preview server`,disabled:t,onClick:r,children:(0,U.jsx)(nl,{size:14})}):null,e.managed&&e.serverState!==`stopping`&&l?(0,U.jsx)(r$,{label:`Stop Preview server`,disabled:t,onClick:i,children:(0,U.jsx)(xl,{size:13})}):null,(0,U.jsx)(r$,{label:`Reload live preview`,disabled:!c,onClick:n,children:(0,U.jsx)(ol,{size:14})}),(0,U.jsx)(r$,{label:`Open live preview in new window`,disabled:!c,onClick:()=>e$(e),children:(0,U.jsx)(fc,{size:14})}),(0,U.jsx)(r$,{buttonRef:o,label:`Exit Preview fullscreen`,onClick:a,children:(0,U.jsx)(Zc,{size:14})})]})}function JLe({preview:e,actionPending:t,onStart:n}){let r=[`running`,`starting`,`stopping`].includes(e.serverState??``),i=e.health===`starting`?`Starting Preview server…`:e.health===`stopping`?`Stopping Preview server…`:e.health===`error`?`The Preview server could not stay running.`:e.managed&&r?`The Preview server is running, but its port is not reachable.`:e.managed?`The Preview server is stopped.`:`The exposed server is offline.`;return(0,U.jsx)(`div`,{className:`min-h-0 flex-1 grid place-items-center bg-[#0e1116] p-6 text-center`,role:`status`,"aria-live":`polite`,children:(0,U.jsxs)(`div`,{children:[(0,U.jsx)(`div`,{className:`text-sm text-slate-400`,children:i}),e.managed&&!r?(0,U.jsxs)(`button`,{type:`button`,disabled:t,onClick:n,className:`mt-4 inline-flex items-center gap-2 border border-[#11a4d4] bg-[#11a4d4]/10 px-3 py-2 text-xs font-semibold text-[#7ddfff] hover:bg-[#11a4d4]/20 disabled:opacity-50`,children:[(0,U.jsx)(nl,{size:14}),` `,t?`Starting…`:`Start server`]}):null]})})}function r$({buttonRef:e,label:t,danger:n=!1,disabled:r=!1,onClick:i,children:a}){return(0,U.jsx)(`button`,{ref:e,type:`button`,title:t,"aria-label":t,disabled:r,onClick:i,className:`h-7 w-7 shrink-0 inline-flex items-center justify-center border rounded-sm transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[#11a4d4]/60 disabled:cursor-not-allowed disabled:opacity-35 ${n?`border-red-500/40 text-red-300 hover:border-red-300 hover:text-red-200`:`border-slate-700 text-slate-400 hover:border-[#11a4d4] hover:text-[#11a4d4]`}`,children:a})}function i$({label:e,tone:t=`normal`}){return(0,U.jsx)(`div`,{role:t===`error`?`alert`:`status`,className:`min-h-0 flex-1 grid place-items-center bg-[#0e1116] p-6 text-sm ${t===`error`?`text-red-200`:`text-slate-500`}`,children:e})}function YLe(e){let t=new Date(e);return Number.isNaN(t.getTime())?`soon`:t.toLocaleTimeString([],{hour:`2-digit`,minute:`2-digit`})}var a$={durationMs:{elevated:1e3,high:5e3,critical:15e3},inputTokens:{elevated:8e3,high:2e4,critical:5e4},outputTokens:{elevated:2e3,high:1e4,critical:5e4}},o$=`pibo.chat.toolMetricThresholds`;function XLe(e){return c$(e)?s$(e.durationMs)&&s$(e.inputTokens)&&s$(e.outputTokens):!1}function ZLe(){try{let e=localStorage.getItem(o$);if(!e)return a$;let t=JSON.parse(e);return XLe(t)?t:a$}catch{return a$}}function QLe(e){try{localStorage.setItem(o$,JSON.stringify(e))}catch{}}function s$(e){if(!c$(e))return!1;let t=e.elevated,n=e.high,r=e.critical;return typeof t==`number`&&Number.isSafeInteger(t)&&t>0&&typeof n==`number`&&Number.isSafeInteger(n)&&n>t&&typeof r==`number`&&Number.isSafeInteger(r)&&r>n}function c$(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}var l$=e=>[`chat`,`session-live-previews`,e];function $Le(e,t,n){let r=(0,H.useRef)(n);r.current=n,(0,H.useEffect)(()=>{e&&!t&&r.current?.()},[e,t])}function u$({bootstrap:e,selectedPiboSessionId:t,selectedRoomId:n,contextKind:r=`room`,contextLabel:i,selectedRoomArchived:a,roomNavigationPending:o,sessionNavigationPending:s,selectedSessionProfile:c,selectedSessionActiveModel:l,selectedSessionStatus:u,selectedSessionSignal:d,signals:f,activeViewId:p,sessionViewId:m,currentSessionView:h,desktopTerminalOnly:g=!1,containerResponsive:_=!1,creatingSession:v,terminalFullscreen:y=!1,onEnterTerminalFullscreen:b,onExitTerminalFullscreen:x,showRawEvents:S,showThinking:C,debugMode:w,toolMetricThresholds:T=a$,expandThinking:E,toolDisplayMode:D,commands:O,skills:k,composerText:A,composerFocusSignal:j,onComposerTextChange:M,onToggleDebugMode:N,onToggleThinking:P,onToggleExpandThinking:F,onToolDisplayModeChange:I,onSessionAgentProfileChange:L,onFork:R,onOpenSession:z,onCommand:ee,onThinkingLevelChange:te,onRefreshTrace:ne,onRefreshBootstrap:re,onSend:ie,onError:B,desktopActiveTool:ae=null,desktopToolHosts:oe,onOpenDesktopTool:se,onCloseDesktopTool:ce,desktopPreviewFullscreen:le=!1,onEnterDesktopPreviewFullscreen:ue,onExitDesktopPreviewFullscreen:de}){let fe=kn(),pe=(0,H.useRef)(0),me=(0,H.useRef)(new Map),[he,ge]=(0,H.useState)(null),_e=(0,H.useCallback)(e=>{ge(t=>{let n=typeof e==`function`?e(t):e;return n&&me.current.set(n.piboSessionId,n),n})},[]),[ve,ye]=(0,H.useState)(null),[be,xe]=(0,H.useState)([]),[Se,Ce]=(0,H.useState)([]),we=(0,H.useRef)(new Set),Te=(0,H.useRef)(null),V=(0,H.useRef)(null),Ee=UQ(t);(0,H.useEffect)(()=>{let t=e.runtimeStatus?.piboSessionId===Ee?e.runtimeStatus:void 0;xe(t?.pendingApprovals?[...t.pendingApprovals]:[]),Ce(t?.pendingUserInputs?[...t.pendingUserInputs]:[])},[e.runtimeStatus,Ee]);let De=(0,H.useCallback)(e=>{if(e.type===`RUNTIME_APPROVAL_REQUESTED`){xe(t=>[...t.filter(t=>t.requestId!==e.request.requestId),e.request]);return}if(e.type===`RUNTIME_USER_INPUT_REQUESTED`){Ce(t=>[...t.filter(t=>t.requestId!==e.request.requestId),e.request]);return}xe(t=>t.filter(t=>t.requestId!==e.requestId)),Ce(t=>t.filter(t=>t.requestId!==e.requestId))},[]),Oe=(0,H.useCallback)(e=>{xe(t=>t.filter(t=>t.requestId!==e)),Ce(t=>t.filter(t=>t.requestId!==e))},[]),ke=Wn({queryKey:Ee?[`chat`,`session-goal`,Ee]:[`chat`,`session-goal`,`idle`],queryFn:({signal:e})=>Bje(Ee,{signal:e}),enabled:!!Ee,refetchInterval:Ee?5e3:!1}),Ae=(0,H.useRef)(Ee);Ae.current=Ee;let je=(0,H.useRef)(se);je.current=se;let Me=!!se,[Ne,Pe]=(0,H.useState)(null),[Fe,Ie]=(0,H.useState)(),[Le,Re]=(0,H.useState)(),ze=(0,H.useRef)(new Set),[Be,Ve]=(0,H.useState)(new Set),He=Wn({queryKey:l$(Ee||`idle`),queryFn:async({signal:e})=>{let t=Ee;return{piboSessionId:t,...await zLe(t,{signal:e})}},enabled:!!Ee,refetchInterval:e=>Ee&&e.state.data?.configured!==!1?5e3:!1,retry:!1}),Ue=WLe({selectedPiboSessionId:Ee??void 0,data:He.data,loading:He.isPending&&!!Ee,error:He.isError?ZQ(He.error):void 0}),We=Ue.kind===`ready`?Ue.previews:[],Ge=GLe(Ue,Fe);$Le(le,Ue.kind===`ready`&&!!Ge,de);let Ke=!!(Ee&&Ne===Ee),qe=!!(Ee&&!y&&!Ke&&h.id===`terminal`&&(p??m)===`terminal`),Je=Wn({queryKey:Ee?[`chat`,`terminal-header-usage`,Ee,u]:[`chat`,`terminal-header-usage`,`idle`],queryFn:()=>Jl(Ee,{activate:!1}),enabled:qe,refetchInterval:qe?3e4:!1,staleTime:15e3,retry:!1}),Ye=Le?.piboSessionId===Ee?Le.value:0;(0,H.useEffect)(()=>{!Ee||Ne===Ee||(Ne&&y&&x?.(),Pe(null),Ie(void 0),Re(void 0))},[Ne,x,Ee,y]),(0,H.useEffect)(()=>{Ue.kind===`ready`&&(Fe?.piboSessionId===Ue.piboSessionId&&Ue.previews.some(e=>e.id===Fe.previewId)||Ie({piboSessionId:Ue.piboSessionId,previewId:Ue.previews[0].id}))},[Ue,Fe]),(0,H.useEffect)(()=>{if(!Me||!Ee)return;let e=Ee;return BLe(e,({preview:t})=>{Ae.current===e&&t.piboSessionId===e&&(fe.setQueryData(l$(e),n=>({piboSessionId:e,configured:!0,previews:[t,...n?.piboSessionId===e?n.previews.filter(e=>e.id!==t.id):[]]})),Ie({piboSessionId:e,previewId:t.id}),je.current?.(`preview`))})},[Me,fe,Ee]);let Xe=!!Ee&&ALe(),Ze=(0,H.useCallback)(()=>{MLe()||B(`The browser blocked the new Pibo window.`)},[B]),Qe=Xe?Ze:void 0,{baseTraceView:$e,liveTraceOverlay:et,rawEventLimit:tt,traceSummaryQuery:nt,tracePageQuery:rt,rawEventsQuery:it,loadingOlderTracePage:at,tracePageReady:ot,loadOlderTracePage:st,loadMoreRawEvents:ct}=tIe({selectedPiboSessionId:Ee,showRawEvents:S||!!oe?.[`raw-events`],liveTraceOverlay:he,liveTraceOverlayCacheRef:me,setLiveTraceOverlay:_e}),{selectedWebAnnotationIds:lt,selectedWebAnnotations:ut,visibleWebAnnotations:dt,webAnnotationsQuery:ft,clearingWebAnnotations:pt,toggleWebAnnotationAttachment:mt,detachWebAnnotationAttachment:ht,clearSelectedWebAnnotationAttachments:gt,clearVisibleWebAnnotations:_t}=TIe({selectedPiboSessionId:Ee,onError:B,formatError:wQ,forcePanelVisible:!!oe?.[`web-annotations`]}),{selectedUploadAttachments:vt,attachUploadedFiles:yt,detachUploadAttachment:bt,clearSelectedUploadAttachments:xt}=PNe(t,(0,H.useCallback)(()=>`upload-${jQ()}`,[])),St=RFe({selectedPiboSessionId:Ee,baseTraceView:$e,liveTraceOverlay:et,selectedSessionStatus:u}),Ct=WIe(e,t,c),wt=GIe(e,t,c),Tt=KIe(St),Et=u??`unknown`,Dt=!!Ee&&Tt!==`none`&&Tt!==`0:`&&Ct&&!a&&(u!==`running`||wt),Ot=Wn({queryKey:Ee?[`chat`,`fork-candidates`,Ee,Tt,Et]:[`chat`,`fork-candidates`,`idle`,`none`,Et],queryFn:({signal:e})=>Ll(Ee,{signal:e}),enabled:Dt,staleTime:0,retry:!1}),kt=(0,H.useMemo)(()=>Dt&&Ot.data?qIe(St,Ot.data.messages):St,[St,Dt,Ot.data]);hIe({selectedPiboSessionId:Ee,tracePageData:rt.data,currentTraceView:St,liveEventSeqRef:pe,selectedSessionStatus:u,tracePageReady:ot,setLiveTraceOverlay:_e,onRefreshTrace:ne,onRefreshBootstrap:re,onRuntimeRequestEvent:De,onError:B});let At=QIe({bootstrap:e,selectedPiboSessionId:t,selectedSessionProfile:c,selectedSessionActiveModel:l,currentTraceView:St}),jt=(0,H.useMemo)(()=>ZIe(e.sessions,t),[e.sessions,t]),Mt=!!t&&rt.isFetching&&!St,Nt=rt.error?ZQ(rt.error):nt.error?ZQ(nt.error):null,Pt=MQ(t,a)||!!(o||s),Ft=!Ke&&!Pt&&h.id===`terminal`&&(p??m)===`terminal`,It=(0,H.useCallback)(async e=>{try{PY(vt.length,e.length);let t=await pu(e);yt(t.files)}catch(e){B(ZQ(e))}},[yt,B,vt.length]),Lt=St?.piboSessionId??t??``,Rt=QNe(t?kQ(e.sessions,t):void 0,e.session?.id===t?e.session:void 0),zt=Wn({queryKey:[`chat`,`session-workflow`,t],queryFn:()=>WQ(t),enabled:!!(t&&Rt),refetchInterval:5e3,retry:!1}).data?.workflowSession,Bt=zt?$Ne(zt):null,Vt=e=>{for(let n of[750,2e3,5e3,1e4])window.setTimeout(()=>{t===e&&rt.refetch().catch(e=>B(ZQ(e)))},n)},Ht=async(e,t)=>{let n=uLe(e,t);_e(e=>dLe(e,n.piboSessionId,n.optimisticEvent)),await ie(n.text,n.webAnnotationIds,n.fileAttachmentPaths,n.clientTxnId,t),gt(),xt(),await Promise.all([rt.refetch(),ft.refetch()]),Vt(n.piboSessionId)},Ut=(e,t)=>{_e(t=>{let n=t?.piboSessionId===e.piboSessionId?t:me.current.get(e.piboSessionId)??null;if(!n)return t;let r=n.events.filter(t=>t.id!==e.clientTxnId),i=r.length?{...n,events:r}:null;return i?me.current.set(e.piboSessionId,i):me.current.delete(e.piboSessionId),t?.piboSessionId===e.piboSessionId?i:t}),M(t=>t||e.text),B(ZQ(t))},Wt=JIe(e,Ee,c,d),Gt=async e=>{if(Pt||!t)return;let n=lLe({piboSessionId:t,text:e,selectedWebAnnotations:ut,selectedUploadAttachments:vt,eventSequence:pe.current++,now:new Date().toISOString(),clientTxnId:jQ()});if(Wt){ye(n);return}try{await Ht(n,`queue`)}catch(e){Ut(n,e)}},Kt=()=>{ve&&(M(e=>e||ve.text),ye(null))},qt=async e=>{let t=ve;if(!(!t||we.current.has(t.clientTxnId))){we.current.add(t.clientTxnId),ye(e=>e?.clientTxnId===t.clientTxnId?null:e),B(null);try{await Ht(t,e)}catch(e){Ut(t,e)}finally{we.current.delete(t.clientTxnId)}}},Jt=(e,t)=>{let n=hNe(e,t);n&&(t.preventDefault(),(n===`queue`?Te:V).current?.focus())},Yt=YIe(e,t,c),Xt=D===`intent`&&!Yt?`slim`:D,Zt=$Ie({currentTraceView:kt,isLoading:Mt,showThinking:C,debugMode:w,toolMetricThresholds:T,expandThinking:E,toolDisplayMode:Xt,selectedSessionProfile:c,sessionActiveModelBadge:At,sessionRuntimeBinding:e.session?.id===Ee?e.session.runtimeBinding:void 0,selectedSessionStatus:u,selectedSessionSignal:d,signals:f,sessionGoal:ke.data?.goal,selectedPiboSessionId:t,workflowSessionLinked:Rt,sessionNodes:e.sessions,sessionLinks:jt,agentProfiles:e.agents,sessionProfileChangeDisabled:v||a,onSessionAgentProfileChange:L,onFork:R,onOpenSession:z,onLoadOlderTracePage:()=>st(St?.nextBeforeCursor??St?.nextBeforeSequence),hasOlderTraceEvents:St?.hasOlderEvents===!0||St?.nextBeforeCursor!==void 0||typeof St?.nextBeforeSequence==`number`,isFetchingOlderTracePage:at,onThinkingLevelChange:te,onRefreshTrace:ne,onRefreshBootstrap:re,onError:B}),Qt=(e,t)=>{t?ze.current.add(e):ze.current.delete(e),Ve(new Set(ze.current))},$t=async(e,t)=>{let n=Ee;if(!n)return;let r=`${n}:${e}`;if(!ze.current.has(r)){Qt(r,!0);try{let r=KLe(n,t===`start`?await VLe(e):t===`stop`?await HLe(e):(await ULe(e)).preview);fe.setQueryData(l$(n),e=>!e||e.piboSessionId!==n?e:{...e,previews:t===`remove`?e.previews.filter(e=>e.id!==r.id):e.previews.map(e=>e.id===r.id?r:e)}),Ae.current===n&&(t===`start`&&Re(e=>({piboSessionId:n,value:e?.piboSessionId===n?e.value+1:1})),t===`remove`&&Fe?.piboSessionId===n&&Fe.previewId===r.id&&Ie(void 0)),await fe.invalidateQueries({queryKey:l$(n),exact:!0})}catch(e){Ae.current===n&&B(ZQ(e))}finally{Qt(r,!1)}}},en=()=>{Ee&&Re(e=>({piboSessionId:Ee,value:e?.piboSessionId===Ee?e.value+1:1}))},tn=e=>{Ee&&Ie({piboSessionId:Ee,previewId:e})},nn=Ge?Be.has(`${Ge.piboSessionId}:${Ge.id}`):!1,rn=Ue.kind===`loading`?(0,U.jsx)(i$,{label:`Loading live previews…`}):Ue.kind===`error`?(0,U.jsx)(i$,{label:Ue.message,tone:`error`}):Ue.kind===`unconfigured`?(0,U.jsx)(i$,{label:`Live previews are not configured on this Pibo instance.`}):(0,U.jsx)(i$,{label:`No active live preview is attached to this Pibo Session.`}),an=Ke||oe?.preview?Ue.kind===`ready`&&Ge?(0,U.jsx)(t$,{previews:We,selectedPreview:Ge,loading:!1,reloadKey:Ye,onSelect:tn,onReload:en,onRefresh:()=>void He.refetch(),onStart:e=>void $t(e,`start`),onStop:e=>void $t(e,`stop`),onRemove:e=>void $t(e,`remove`),actionPending:nn,fullscreen:le,onEnterFullscreen:ue??b,onExitFullscreen:de}):rn:void 0,on=Ke?an:void 0,sn=Ke?Ue.kind===`ready`&&Ge?(0,U.jsx)(t$,{previews:We,selectedPreview:Ge,loading:!1,reloadKey:Ye,fullscreen:!0,onSelect:tn,onReload:en,onRefresh:()=>void He.refetch(),onStart:e=>void $t(e,`start`),onStop:e=>void $t(e,`stop`),onRemove:e=>void $t(e,`remove`),actionPending:nn}):rn:void 0,cn=Ke&&Ge?(0,U.jsx)(n$,{preview:Ge,onReload:en,onStart:()=>void $t(Ge.id,`start`),onStop:()=>void $t(Ge.id,`stop`),actionPending:nn,onExit:x??(()=>void 0)}):void 0,ln=(0,U.jsxs)(`div`,{className:`@container h-full min-h-0 overflow-y-auto bg-[#101d22]`,"data-pibo-debug":`web-annotations-tab-panel`,children:[(0,U.jsx)(DIe,{piboSessionId:t,piboRoomId:n??e.selectedRoomId??void 0,disabled:!t||a,onError:B}),(0,U.jsx)(EIe,{piboSessionId:t,annotations:dt,selectedIds:lt,loading:ft.isLoading||ft.isFetching||pt,error:ft.error?ZQ(ft.error):null,onRefresh:()=>void ft.refetch(),onToggle:mt,onClear:()=>void _t()})]}),un=Ee?(0,U.jsx)(`div`,{className:`h-full overflow-auto bg-[#101d22]`,children:be.length||Se.length?(0,U.jsx)(QQ,{piboSessionId:Ee,approvals:be,userInputs:Se,onResolved:Oe,onError:B}):(0,U.jsx)(`div`,{className:`grid h-full place-items-center p-6 text-center text-sm text-slate-500`,"data-pibo-debug":`desktop-runtime-requests-empty`,children:`No pending runtime requests for this Pibo Session.`})}):(0,U.jsx)(d$,{label:`Select a Pibo Session to inspect runtime requests.`}),dn=t?(0,U.jsxs)(`div`,{className:`h-full overflow-auto bg-[#0e1116] p-3`,"data-pibo-debug":`desktop-session-inspector`,children:[(0,U.jsx)(`div`,{className:`mb-3 text-[11px] font-bold uppercase tracking-wider text-[#11a4d4]`,children:`Selected Pibo Session`}),(0,U.jsx)(ZK,{value:{piboSessionId:t,roomId:n??e.selectedRoomId,profile:c,activeModel:l,status:u,runtimeStatus:e.runtimeStatus?.piboSessionId===Ee?e.runtimeStatus:void 0,signal:d}})]}):(0,U.jsx)(d$,{label:`Select a Pibo Session to inspect it.`}),fn={preview:an??(0,U.jsx)(d$,{label:`Select a Pibo Session to view its Preview.`}),"raw-events":(0,U.jsx)(nX,{traceView:St,eventLimit:tt,isFetching:it.isFetching,visible:!0,onLoadOlder:ct}),"web-annotations":ln,"runtime-requests":un,"session-inspector":dn};return(0,U.jsxs)(U.Fragment,{children:[ve?(0,U.jsx)(iX,{title:`Session is running`,description:`Choose how this message should be delivered.`,onClose:Kt,initialFocusRef:Te,children:(0,U.jsxs)(`div`,{className:`grid gap-2 p-4 sm:grid-cols-2`,"data-pibo-debug":`message-delivery-dialog`,children:[(0,U.jsxs)(`button`,{ref:Te,type:`button`,onClick:()=>void qt(`queue`),onKeyDown:e=>Jt(`queue`,e),className:`rounded-sm border border-slate-700 bg-[#151f24] p-3 text-left transition hover:border-[#11a4d4] hover:bg-[#11a4d4]/10 focus-visible:border-[#11a4d4] focus-visible:bg-[#11a4d4]/10 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[#11a4d4]/50 disabled:opacity-50`,"data-pibo-debug":`message-delivery-queue`,children:[(0,U.jsx)(`span`,{className:`block text-xs font-bold uppercase tracking-wider text-[#11a4d4]`,children:`Queue`}),(0,U.jsx)(`span`,{className:`mt-1 block text-xs leading-5 text-slate-400`,children:`Run it as the next turn after the active turn finishes.`})]}),(0,U.jsxs)(`button`,{ref:V,type:`button`,onClick:()=>void qt(`steer`),onKeyDown:e=>Jt(`steer`,e),className:`rounded-sm border border-amber-500/50 bg-amber-500/5 p-3 text-left transition hover:border-amber-400 hover:bg-amber-500/10 focus-visible:border-amber-400 focus-visible:bg-amber-500/10 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-amber-400/50 disabled:opacity-50`,"data-pibo-debug":`message-delivery-steer`,children:[(0,U.jsx)(`span`,{className:`block text-xs font-bold uppercase tracking-wider text-amber-400`,children:`Steer`}),(0,U.jsx)(`span`,{className:`mt-1 block text-xs leading-5 text-slate-400`,children:`Add it to the active turn after the current tool finishes, before the next model step.`})]})]})}):null,(0,U.jsx)(fPe,{selectedPiboSessionId:t,selectedRoomId:n,fallbackRoomId:e.selectedRoomId??void 0,sessionViewId:m,loadingTrace:Mt,roomNavigationPending:o,sessionNavigationPending:s,traceError:Nt,showRawEvents:S&&!Ke&&ae!==`raw-events`,currentTraceView:St,rawEventLimit:tt,tracePageFetching:S?it.isFetching:rt.isFetching,onLoadMoreRawEvents:ct,terminalFullscreen:y,fullscreenTopBar:cn,fullscreenContent:sn,hideComposer:Ke,terminalFileDropEnabled:Ft,onTerminalFilesDropped:It,onOpenSessionWindow:Qe,onExitTerminalFullscreen:x??(()=>void 0),headerProps:{title:XIe({sessionNodes:e.sessions,selectedPiboSessionId:t,traceTitle:St?.title,fallback:`No session selected`}),contextKind:r,contextLabel:i??(e.room?.id===n?e.room.name:void 0)??n??`Unknown room`,headerPiboSessionId:Lt,terminalUsageStatus:Je.data,workflowHeader:Bt,sessionViewId:m,currentSessionView:h,activeViewId:Ke?`preview`:p,desktopTerminalOnly:g,terminalFullscreenAvailable:!Ke&&h.id===`terminal`&&(p??m)===`terminal`,onEnterTerminalFullscreen:b,onOpenSessionWindow:Qe,debugMode:w,showThinking:C,expandThinking:E,toolDisplayMode:Xt,toolIntentSupported:Yt,onToolDisplayModeChange:I,onToggleDebugMode:N,onToggleThinking:P,onToggleExpandThinking:F},auxiliaryPanel:on,currentSessionView:h,sessionViewProps:Zt,runtimeRequestPanel:Ee&&!Ke&&ae!==`runtime-requests`?(0,U.jsx)(QQ,{piboSessionId:Ee,approvals:be,userInputs:Se,onResolved:Oe,onError:B}):void 0,containerResponsive:_,composerProps:{sessionId:t,disabled:Pt,commands:O,skills:k,value:A,focusSignal:j,selectedWebAnnotations:ut,selectedUploadAttachments:vt,onValueChange:M,onCommand:ee,onDetachWebAnnotation:ht,onClearWebAnnotations:gt,onAttachUploadedFiles:yt,onDetachUploadAttachment:bt,onClearUploadAttachments:xt,onSend:Gt}}),oe?Object.entries(oe).map(([e,t])=>t&&fn[e]?(0,Ml.createPortal)(fn[e],t,`desktop-session-tool-${e}`):null):null]})}function d$({label:e}){return(0,U.jsx)(`div`,{className:`grid h-full place-items-center bg-[#0e1116] p-6 text-center text-sm text-slate-500`,children:e})}function f$({node:e,signalNow:t,selectedPiboSessionId:n,selectedSessionPathIds:r,onSelect:i,onRename:a,onArchive:o,onPinnedChange:s,onDelete:c,onViewContext:l,depth:u=0,loadingPiboSessionId:d,autoRename:f=!1,onAutoRenameConsumed:p,draggable:m=!1,dropPosition:h=null,onSessionDragStart:g,onSessionDragOver:_,onSessionDrop:v,onSessionDragEnd:y,showWorkflowSessionKindMarkers:b=!1,mutationsDisabled:x=!1}){let S=Hq(e),C=Yje(e),[w,T]=(0,H.useState)(!1),[E,D]=(0,H.useState)(S),O=(0,H.useRef)(null),k=e.children.length>0,A=n!==null&&e.piboSessionId!==n&&r.has(e.piboSessionId),[j,M]=(0,H.useState)(A),N=(0,H.useRef)(n),P=(0,H.useId)();(0,H.useEffect)(()=>{w||D(S)},[w,S]),(0,H.useEffect)(()=>{!f||x||(D(S===`Untitled Session`?``:S),T(!0),p?.())},[f,x,S,p]),(0,H.useEffect)(()=>{x&&T(!1)},[x]),(0,H.useLayoutEffect)(()=>{w&&(O.current?.focus(),O.current?.select())},[w]),(0,H.useLayoutEffect)(()=>{if(N.current!==n){N.current=n,M(A);return}A&&M(!0)},[A,n]);let F=()=>{if(x)return;let t=E.trim();a(e.piboSessionId,t||null),T(!1)},I=Xje(e,t),L=d===e.piboSessionId,R=b?eRe(e.workflowSessionKind):null,z=R?.Icon,ee=u===0&&!e.archived&&!!s;return(0,U.jsxs)(`div`,{children:[(0,U.jsxs)(`div`,{"data-pibo-component":`SessionNode`,"data-pibo-debug":`session-row`,"data-pibo-session-id":e.piboSessionId,"data-pibo-title":S,"data-pibo-selected":e.piboSessionId===n?`true`:`false`,"data-pibo-state":L?`loading`:e.status??`idle`,"data-pibo-archived":e.archived?`true`:`false`,"data-pibo-pinned":e.pinned?`true`:`false`,"data-pibo-unread-count":e.unreadCount??0,draggable:m,onDragStart:g,onDragOver:_,onDrop:v,onDragEnd:y,className:`group relative w-full grid grid-cols-[1fr_auto] gap-0.5 items-center mb-0.5 border rounded-sm ${m?`cursor-grab active:cursor-grabbing`:``} ${e.piboSessionId===n?`border-[#11a4d4] bg-[#11a4d4]/10`:`border-transparent`}`,style:{paddingLeft:8+u*14},title:C,children:[h===`before`?(0,U.jsx)(`span`,{className:`pointer-events-none absolute inset-x-1 -top-px z-10 h-px bg-[#11a4d4]`}):null,w&&!x?(0,U.jsxs)(`form`,{className:`min-w-0 grid grid-cols-[1fr_auto_auto] gap-1 py-1 pr-1`,onSubmit:e=>{e.preventDefault(),F()},children:[(0,U.jsx)(`input`,{ref:O,value:E,"aria-label":`Session title for ${S}`,disabled:x,onChange:e=>D(e.target.value),onKeyDown:e=>{e.key===`Escape`&&(e.preventDefault(),T(!1),D(S))},autoFocus:!0,className:`min-w-0 bg-[#0e1116] border border-slate-700 rounded-sm px-2 py-1 text-sm outline-none focus:border-[#11a4d4]`}),(0,U.jsx)(`button`,{type:`submit`,disabled:x,title:`Save Session Title`,"aria-label":`Save Session Title`,className:`h-7 w-7 inline-flex items-center justify-center border border-slate-700 rounded-sm text-slate-400 hover:border-[#11a4d4] hover:text-[#11a4d4]`,children:(0,U.jsx)(Ws,{size:13})}),(0,U.jsx)(`button`,{type:`button`,disabled:x,onClick:()=>{T(!1),D(S)},title:`Cancel Rename`,"aria-label":`Cancel Rename`,className:`h-7 w-7 inline-flex items-center justify-center border border-slate-700 rounded-sm text-slate-400 hover:border-[#11a4d4] hover:text-[#11a4d4]`,children:(0,U.jsx)(jl,{size:13})})]}):(0,U.jsxs)(`div`,{className:`min-w-0 h-7 max-[980px]:h-8 grid grid-cols-[1fr_auto] gap-1 items-center pr-0.5`,children:[(0,U.jsxs)(`button`,{type:`button`,onClick:()=>{if(k&&e.piboSessionId===n){M(e=>!e);return}i(e.piboSessionId)},"aria-label":R?`${R.ariaLabel}: ${S}`:`Open session ${S}`,"aria-current":e.piboSessionId===n?`page`:void 0,className:`h-7 max-[980px]:h-8 min-w-0 text-left px-1 flex items-center gap-1.5`,children:[R&&z?(0,U.jsx)(`span`,{className:`h-4 w-4 shrink-0 inline-flex items-center justify-center rounded-sm border ${R.className}`,title:R.ariaLabel,"aria-label":R.ariaLabel,children:(0,U.jsx)(z,{size:11,"aria-hidden":`true`})}):null,e.pinned&&!e.archived?(0,U.jsx)(`span`,{className:`shrink-0 text-[#11a4d4]`,title:`Pinned session`,"aria-label":`Pinned session`,children:(0,U.jsx)(tl,{size:11,fill:`currentColor`,"aria-hidden":`true`})}):null,(0,U.jsx)(`span`,{className:`block min-w-0 truncate text-[13px] leading-none ${e.archived?`text-slate-500`:`text-slate-200`}`,children:S})]}),(0,U.jsxs)(`span`,{className:`inline-flex items-center justify-end gap-1`,children:[L?(0,U.jsx)(Pc,{size:12,className:`text-[#11a4d4] animate-spin`,"aria-label":`Loading session`}):(0,U.jsx)(`span`,{className:I.className,title:I.title,"aria-label":I.title}),k?(0,U.jsx)(`button`,{type:`button`,onClick:()=>M(e=>!e),"aria-expanded":j,"aria-controls":P,title:j?`Collapse Subsessions`:`Expand Subsessions`,"aria-label":`Subsessions for ${S}`,className:`h-5 w-5 inline-flex items-center justify-center rounded-sm transition-colors ${j?`text-[#0bda57]`:`text-slate-600 hover:text-[#11a4d4]`}`,children:(0,U.jsx)(kc,{size:12})}):null]})]}),w&&!x?null:(0,U.jsx)(`div`,{className:`flex items-center gap-0.5 opacity-0 group-hover:opacity-100 group-focus-within:opacity-100 transition-opacity max-[980px]:opacity-100`,children:(0,U.jsx)(KJ,{label:`Actions for session ${S}`,estimatedHeight:ee?192:144,disabled:x,children:e.archived?(0,U.jsxs)(U.Fragment,{children:[(0,U.jsxs)(qJ,{onSelect:()=>o(e.piboSessionId,!1),children:[(0,U.jsx)(Os,{size:16}),` Restore Session`]}),(0,U.jsxs)(qJ,{onSelect:()=>l(e.piboSessionId),children:[(0,U.jsx)(Vs,{size:16}),` View Context`]}),(0,U.jsxs)(qJ,{onSelect:()=>c(e),className:`text-red-300 hover:bg-red-500/10`,children:[(0,U.jsx)(Cl,{size:16}),` Delete Session`]})]}):(0,U.jsxs)(U.Fragment,{children:[ee?(0,U.jsxs)(qJ,{onSelect:()=>s?.(e.piboSessionId,!e.pinned),children:[e.pinned?(0,U.jsx)(el,{size:16}):(0,U.jsx)(tl,{size:16}),` `,e.pinned?`Unpin Session`:`Pin Session`]}):null,(0,U.jsxs)(qJ,{onSelect:()=>T(!0),children:[(0,U.jsx)($c,{size:16}),` Rename Session`]}),(0,U.jsxs)(qJ,{onSelect:()=>o(e.piboSessionId,!0),children:[(0,U.jsx)(ks,{size:16}),` Archive Session`]}),(0,U.jsxs)(qJ,{onSelect:()=>l(e.piboSessionId),children:[(0,U.jsx)(Vs,{size:16}),` View Context`]})]})})}),h===`after`?(0,U.jsx)(`span`,{className:`pointer-events-none absolute inset-x-1 -bottom-px z-10 h-px bg-[#11a4d4]`}):null]}),k?(0,U.jsx)(`div`,{id:P,hidden:!j,children:j?e.children.map(e=>(0,U.jsx)(f$,{node:e,signalNow:t,selectedPiboSessionId:n,selectedSessionPathIds:r,onSelect:i,onRename:a,onArchive:o,onDelete:c,onViewContext:l,depth:u+1,loadingPiboSessionId:d,showWorkflowSessionKindMarkers:b,mutationsDisabled:x},e.piboSessionId)):null}):null]})}function eRe(e){switch(e){case`main_workflow`:return{ariaLabel:`Main workflow session`,className:`border-[#11a4d4]/40 bg-[#11a4d4]/10 text-[#11a4d4]`,Icon:kc};case`nested_workflow`:return{ariaLabel:`Nested workflow session`,className:`border-violet-400/40 bg-violet-500/10 text-violet-300`,Icon:sc};case`agent_node`:return{ariaLabel:`Workflow agent node session`,className:`border-emerald-400/40 bg-emerald-500/10 text-emerald-300`,Icon:El};case`subagent`:return{ariaLabel:`Subagent session`,className:`border-amber-400/40 bg-amber-500/10 text-amber-300`,Icon:Dl};default:return null}}var tRe=`240px 0px`;function nRe(e){return e>99?`99+`:String(e)}function rRe({count:e}){return!e||e<=0?null:(0,U.jsx)(`span`,{className:`min-w-5 h-5 px-1.5 inline-flex items-center justify-center rounded-full bg-[#38bdf8] text-[#0e1116] text-[10px] font-bold tabular-nums leading-none`,"aria-label":`${e} unread messages`,title:`${e} unread messages`,children:nRe(e)})}function p$({bootstrap:e,selectedRoomId:t,selectedPiboSessionId:n,showArchivedRooms:r,onToggleArchivedRooms:i,creatingRoom:a,onCreateRoom:o,onSelectRoom:s,loadingRoomId:c,roomSessionsLoading:l=!1,onUpdateRoom:u,onArchiveRoom:d,onPinnedRoomChange:f,onReorderRoom:p,onReadAllRoom:m,onDeleteRoom:h,newSessionProfile:g,newSessionProfileReady:_,onNewSessionProfileChange:v,selectedRoomArchived:y,creatingSession:b,onCreateSession:x,onCreateWorkflowSession:S,showArchived:C,onToggleArchivedSessions:w,loadingArchivedSessions:T,visibleActiveSessions:E,visibleArchivedSessions:D,totalActiveSessionCount:O,totalArchivedSessionCount:k,hasMoreActiveSessions:A,hasMoreArchivedSessions:j,loadingActiveSessions:M,sessionListScrollRef:N,onLoadMoreSessions:P,signalNow:F,selectedSessionPathIds:I,onSelectSession:L,onRenameSession:R,onArchiveSession:z,onPinnedSessionChange:ee,onReorderSession:te,onDeleteSession:ne,onViewContext:re,loadingPiboSessionId:ie,autoRenameSessionId:B,onAutoRenameConsumed:ae}){let oe=!!(e.selectedRoomId||e.room||e.rooms.length),se=e.agents,ce=Gq(e.rooms),le=qq(e.rooms),ue=(0,H.useRef)(null),[de,fe]=(0,H.useState)(null),[pe,me]=(0,H.useState)(null),[he,ge]=(0,H.useState)(null),[_e,ve]=(0,H.useState)(null),ye=le.active.findIndex(e=>!Xq(e)),be=E.findIndex(e=>!e.pinned),xe=async()=>{let e=ue.current===document.activeElement;try{await w()}finally{requestAnimationFrame(()=>{e&&document.activeElement===document.body&&ue.current?.focus()})}};return(0,U.jsxs)(`div`,{"data-pibo-debug":`session-list`,"data-pibo-room-id":t??e.selectedRoomId??void 0,"data-pibo-selected-session-id":n??void 0,"data-pibo-state":C?`archived-visible`:`active-only`,className:`min-h-0 flex-1 overflow-hidden p-2 flex flex-col gap-3`,children:[oe?(0,U.jsxs)(U.Fragment,{children:[ce?(0,U.jsxs)(`div`,{className:`shrink-0`,children:[(0,U.jsx)(`div`,{className:`px-1 pb-1 text-[10px] font-bold uppercase tracking-wider text-slate-500`,children:`Shared Chat`}),(0,U.jsx)(h$,{room:ce,selectedRoomId:t,loadingRoomId:c,onSelect:e=>void s(e),onUpdate:(e,t)=>void u(e,t),onArchive:(e,t)=>void d(e,t),onReadAll:e=>void m(e),onDelete:h})]}):null,(0,U.jsxs)(`div`,{className:`min-h-0 flex-1 basis-0 overflow-hidden flex flex-col`,children:[(0,U.jsxs)(`div`,{className:`shrink-0 flex items-center justify-between gap-2 px-1 pb-1`,children:[(0,U.jsx)(`div`,{className:`text-[10px] font-bold uppercase tracking-wider text-slate-500`,children:`Rooms`}),(0,U.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,U.jsx)(`button`,{type:`button`,onClick:()=>void o(),disabled:a,title:`New Room`,"aria-label":`New Room`,className:`h-6 w-6 max-[980px]:h-8 max-[980px]:w-8 inline-flex items-center justify-center border border-slate-700 rounded-sm text-slate-400 hover:border-[#11a4d4] hover:text-[#11a4d4] disabled:opacity-50`,children:(0,U.jsx)(rl,{size:14})}),(0,U.jsx)(`button`,{type:`button`,onClick:i,title:r?`Hide Archived Rooms`:`Show Archived Rooms`,"aria-label":`Archived Rooms`,"aria-pressed":r,className:`h-6 w-6 max-[980px]:h-8 max-[980px]:w-8 inline-flex items-center justify-center border rounded-sm hover:border-[#11a4d4] hover:text-[#11a4d4] ${r?`border-[#11a4d4] text-[#11a4d4]`:`border-slate-700 text-slate-400`}`,children:r?(0,U.jsx)(Os,{size:14}):(0,U.jsx)(ks,{size:14})})]})]}),(0,U.jsxs)(`div`,{className:`min-h-0 flex-1 overflow-y-auto pr-1`,children:[le.active.map((e,n)=>{let r=ye>0&&n===ye,i=pe?.targetRoomId===e.id?pe.position:null;return(0,U.jsxs)(`div`,{children:[r?(0,U.jsx)(`div`,{"data-pibo-debug":`pinned-room-divider`,className:`mx-2 my-1 border-t border-slate-700/80`,"aria-hidden":`true`}):null,(0,U.jsx)(h$,{room:e,selectedRoomId:t,loadingRoomId:c,onSelect:e=>void s(e),onUpdate:(e,t)=>void u(e,t),onArchive:(e,t)=>void d(e,t),onPinnedChange:f?(e,t)=>void f(e,t):void 0,onReadAll:e=>void m(e),onDelete:h,draggable:!!p,dropPosition:i,onRoomDragStart:t=>{fe(e.id),me(null),t.dataTransfer.effectAllowed=`move`,t.dataTransfer.setData(`text/pibo-room-id`,e.id)},onRoomDragOver:t=>{let n=le.active.find(e=>e.id===de);if(!n||n.id===e.id||Xq(n)!==Xq(e))return;t.preventDefault(),t.dataTransfer.dropEffect=`move`;let r=t.currentTarget.getBoundingClientRect();me({targetRoomId:e.id,position:t.clientY<r.top+r.height/2?`before`:`after`})},onRoomDrop:t=>{t.preventDefault(),de&&pe?.targetRoomId===e.id&&p?.(de,e.id,pe.position),fe(null),me(null)},onRoomDragEnd:()=>{fe(null),me(null)}})]},e.id)}),le.active.length===0?(0,U.jsx)(`div`,{className:`px-2 py-3 text-xs text-slate-500 border border-dashed border-slate-700 rounded-sm`,children:`No rooms`}):null,r?(0,U.jsxs)(`div`,{className:`mt-3`,children:[(0,U.jsx)(`div`,{className:`px-1 pb-1 text-[10px] font-bold uppercase tracking-wider text-slate-500`,children:`Archived Rooms`}),le.archived.length?(0,U.jsx)(iRe,{rooms:le.archived,selectedRoomId:t,loadingRoomId:c,onSelect:e=>void s(e),onUpdate:(e,t)=>void u(e,t),onArchive:(e,t)=>void d(e,t),onReadAll:e=>void m(e),onDelete:h}):(0,U.jsx)(`div`,{className:`px-2 py-3 text-xs text-slate-500 border border-dashed border-slate-700 rounded-sm`,children:`No archived rooms`})]}):null]})]})]}):null,(0,U.jsxs)(`div`,{className:`min-h-0 flex-1 basis-0 overflow-hidden flex flex-col border-t border-slate-700/80 pt-3`,children:[(0,U.jsxs)(`div`,{className:`shrink-0 flex items-center justify-between gap-2 px-1 pb-1`,children:[(0,U.jsx)(`div`,{className:`text-[10px] font-bold uppercase tracking-wider text-slate-500`,children:`Sessions`}),(0,U.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,U.jsx)(`select`,{id:`new-session-agent-select`,value:g,onChange:e=>v(e.target.value),disabled:!_||!se.length||a||y||l,title:`Agent for new sessions`,"aria-label":`Agent for new sessions`,className:`h-6 w-28 max-[980px]:h-8 max-[980px]:w-32 max-[980px]:text-sm rounded-sm border border-slate-700 bg-[#101d22] px-1.5 text-[11px] font-medium normal-case tracking-normal text-slate-300 outline-none hover:border-[#11a4d4] focus:border-[#11a4d4] disabled:opacity-50`,children:se.map(e=>(0,U.jsx)(`option`,{value:e.name,title:e.description??e.name,children:e.name},e.name))}),(0,U.jsx)(`button`,{type:`button`,onClick:S,disabled:b||a||y||l,title:`New Workflow Session`,"aria-label":`New Workflow Session`,className:`h-6 w-6 max-[980px]:h-8 max-[980px]:w-8 inline-flex items-center justify-center border border-slate-700 rounded-sm text-slate-400 hover:border-[#11a4d4] hover:text-[#11a4d4] disabled:opacity-50`,children:(0,U.jsx)(kl,{size:14})}),(0,U.jsx)(`button`,{"data-pibo-debug":`new-session-button`,"data-pibo-room-id":t??e.selectedRoomId??void 0,"data-pibo-state":b?`creating`:a?`room-creating`:l?`room-loading`:_?y?`archived-disabled`:`ready`:`profile-loading`,type:`button`,onClick:()=>void x(),disabled:!_||b||a||y||l,title:`New Session`,"aria-label":`New Session`,className:`h-6 w-6 max-[980px]:h-8 max-[980px]:w-8 inline-flex items-center justify-center border border-slate-700 rounded-sm text-slate-400 hover:border-[#11a4d4] hover:text-[#11a4d4] disabled:opacity-50`,children:(0,U.jsx)(rl,{size:14})}),(0,U.jsx)(`button`,{type:`button`,ref:ue,onClick:()=>void xe(),disabled:T,title:C?`Hide Archived Sessions`:`Show Archived Sessions`,"aria-label":`Archived Sessions`,"aria-pressed":C,className:`h-6 w-6 max-[980px]:h-8 max-[980px]:w-8 inline-flex items-center justify-center border rounded-sm hover:border-[#11a4d4] hover:text-[#11a4d4] disabled:opacity-70 ${C?`border-[#11a4d4] text-[#11a4d4]`:`border-slate-700 text-slate-400`}`,children:T?(0,U.jsx)(Pc,{size:14,className:`animate-spin`}):C?(0,U.jsx)(Os,{size:14}):(0,U.jsx)(ks,{size:14})})]})]}),(0,U.jsx)(`div`,{ref:N,className:`min-h-0 flex-1 overflow-y-auto pr-1`,children:l?(0,U.jsx)(aRe,{}):(0,U.jsxs)(U.Fragment,{children:[E.map((e,t)=>{let r=be>0&&t===be,i=_e?.targetPiboSessionId===e.piboSessionId?_e.position:null;return(0,U.jsxs)(`div`,{children:[r?(0,U.jsx)(`div`,{"data-pibo-debug":`pinned-session-divider`,className:`mx-2 my-1 border-t border-slate-700/80`,"aria-hidden":`true`}):null,(0,U.jsx)(f$,{node:e,signalNow:F,selectedPiboSessionId:n,selectedSessionPathIds:I,onSelect:e=>void L(e),onRename:(e,t)=>void R(e,t),onArchive:(e,t)=>void z(e,t),onPinnedChange:(e,t)=>void ee(e,t),onDelete:ne,onViewContext:re,loadingPiboSessionId:ie,autoRename:B===e.piboSessionId,onAutoRenameConsumed:()=>ae(),draggable:!y,dropPosition:i,onSessionDragStart:t=>{ge(e.piboSessionId),ve(null),t.dataTransfer.effectAllowed=`move`,t.dataTransfer.setData(`text/pibo-session-id`,e.piboSessionId)},onSessionDragOver:t=>{let n=E.find(e=>e.piboSessionId===he);if(!n||n.piboSessionId===e.piboSessionId||!!n.pinned!=!!e.pinned)return;t.preventDefault(),t.dataTransfer.dropEffect=`move`;let r=t.currentTarget.getBoundingClientRect();ve({targetPiboSessionId:e.piboSessionId,position:t.clientY<r.top+r.height/2?`before`:`after`})},onSessionDrop:t=>{t.preventDefault(),he&&_e?.targetPiboSessionId===e.piboSessionId&&te(he,e.piboSessionId,_e.position),ge(null),ve(null)},onSessionDragEnd:()=>{ge(null),ve(null)}})]},e.piboSessionId)}),O===0?(0,U.jsx)(`div`,{className:`px-2 py-3 text-xs text-slate-500 border border-dashed border-slate-700 rounded-sm`,children:`No active sessions`}):null,A?(0,U.jsx)(m$,{debugName:`active-session-load-more`,loading:M,rootRef:N,onLoadMore:()=>P(!1),children:M?`Loading active sessions…`:`Load more active sessions (${E.length} of ${O})`}):null,C?(0,U.jsxs)(`div`,{className:`mt-3`,children:[(0,U.jsxs)(`div`,{className:`px-1 pb-1 text-[10px] font-bold uppercase tracking-wider text-slate-500 flex items-center gap-1.5`,children:[(0,U.jsx)(`span`,{children:`Archived Sessions`}),T?(0,U.jsx)(Pc,{size:12,className:`text-[#11a4d4] animate-spin`,"aria-label":`Loading archived sessions`}):null]}),T?(0,U.jsxs)(`div`,{className:`px-2 py-3 text-xs text-slate-500 border border-dashed border-slate-700 rounded-sm flex items-center gap-2`,children:[(0,U.jsx)(Pc,{size:13,className:`text-[#11a4d4] animate-spin`}),` Loading archived sessions`]}):k?(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(oRe,{sessions:D,signalNow:F,selectedPiboSessionId:n,selectedSessionPathIds:I,onSelect:e=>void L(e),onRename:(e,t)=>void R(e,t),onArchive:(e,t)=>void z(e,t),onDelete:ne,onViewContext:re,loadingPiboSessionId:ie,autoRenameSessionId:B,onAutoRenameConsumed:()=>ae()}),j?(0,U.jsx)(m$,{debugName:`archived-session-load-more`,loading:T,rootRef:N,onLoadMore:()=>P(!0),children:T?`Loading archived sessions…`:`Load more archived sessions (${D.length} of ${k})`}):null]}):(0,U.jsx)(`div`,{className:`px-2 py-3 text-xs text-slate-500 border border-dashed border-slate-700 rounded-sm`,children:`No archived sessions`})]}):null]})})]})]})}function iRe({rooms:e,selectedRoomId:t,loadingRoomId:n,onSelect:r,onUpdate:i,onArchive:a,onReadAll:o,onDelete:s}){return(0,U.jsx)(`div`,{children:e.map(e=>(0,U.jsx)(h$,{room:e,selectedRoomId:t,loadingRoomId:n,onSelect:r,onUpdate:i,onArchive:a,onReadAll:o,onDelete:s},e.id))})}function aRe(){return(0,U.jsx)(`div`,{"data-pibo-debug":`room-sessions-loading`,className:`space-y-0.5`,"aria-live":`polite`,"aria-label":`Loading room sessions`,children:[0,1,2,3,4].map(e=>(0,U.jsxs)(`div`,{className:`h-7 max-[980px]:h-8 w-full grid grid-cols-[1fr_auto] gap-1 items-center border rounded-sm animate-pulse ${e===0?`border-[#11a4d4] bg-[#11a4d4]/10`:`border-transparent`}`,style:{paddingLeft:8},"aria-hidden":`true`,children:[(0,U.jsxs)(`div`,{className:`min-w-0 h-full grid grid-cols-[1fr_auto] gap-2 items-center pr-0.5`,children:[(0,U.jsx)(`span`,{className:`block h-3 min-w-0 rounded-sm ${e===0?`w-44 bg-slate-300/75`:e%2==0?`w-40 bg-slate-400/35`:`w-36 bg-slate-400/30`}`}),(0,U.jsx)(`span`,{className:`h-2 w-2 rounded-full ${e===0?`bg-[#11a4d4]`:e%2==0?`bg-slate-600`:`bg-[#11a4d4]/55`}`})]}),(0,U.jsx)(`span`,{className:`h-6 w-6 max-[980px]:h-8 max-[980px]:w-8`})]},e))})}function m$({children:e,debugName:t,loading:n,rootRef:r,onLoadMore:i}){let a=(0,H.useRef)(null),o=(0,H.useRef)(i),s=(0,H.useRef)(!1);(0,H.useEffect)(()=>{o.current=i},[i]),(0,H.useEffect)(()=>{n||(s.current=!1)},[n]);let c=(0,H.useCallback)(()=>{s.current||n||(s.current=!0,Promise.resolve(o.current()).finally(()=>{s.current=!1}))},[n]);return(0,H.useEffect)(()=>{if(n||typeof IntersectionObserver>`u`)return;let e=a.current;if(!e)return;let t=new IntersectionObserver(e=>{e.some(e=>e.isIntersecting)&&c()},{root:r.current,rootMargin:tRe,threshold:0});return t.observe(e),()=>t.disconnect()},[n,r,c]),(0,U.jsx)(`button`,{ref:a,"data-pibo-debug":t,type:`button`,onClick:c,disabled:n,className:`mt-2 w-full px-2 py-2 text-[11px] text-slate-400 border border-dashed border-slate-700 rounded-sm hover:border-[#11a4d4] hover:text-[#11a4d4] disabled:opacity-60`,children:e})}function oRe({sessions:e,signalNow:t,selectedPiboSessionId:n,selectedSessionPathIds:r,onSelect:i,onRename:a,onArchive:o,onDelete:s,onViewContext:c,loadingPiboSessionId:l,autoRenameSessionId:u,onAutoRenameConsumed:d}){return(0,U.jsx)(`div`,{children:e.map(e=>(0,U.jsx)(f$,{node:e,signalNow:t,selectedPiboSessionId:n,selectedSessionPathIds:r,onSelect:i,onRename:a,onArchive:o,onDelete:s,onViewContext:c,loadingPiboSessionId:l,autoRename:u===e.piboSessionId,onAutoRenameConsumed:d},e.piboSessionId))})}function h$({room:e,selectedRoomId:t,loadingRoomId:n,onSelect:r,onUpdate:i,onArchive:a,onPinnedChange:o,onReadAll:s,onDelete:c,depth:l=0,draggable:u=!1,dropPosition:d=null,onRoomDragStart:f,onRoomDragOver:p,onRoomDrop:m,onRoomDragEnd:h}){let[g,_]=(0,H.useState)(!1),[v,y]=(0,H.useState)(e.name),[b,x]=(0,H.useState)(e.topic??``),[S,C]=(0,H.useState)(e.workspace??``),w=Jq(e),T=Yq(e),E=Xq(e),D=e.id===n,O=Jje(e),k=l===0&&!w&&!T&&!!o,A=()=>{Rq(e.id).catch(()=>void 0)};(0,H.useEffect)(()=>{g||(y(e.name),x(e.topic??``),C(e.workspace??``))},[g,e.name,e.topic,e.workspace]);let j=()=>{let t=v.trim();t&&(i(e.id,{name:t,topic:b.trim()||null,workspace:S.trim()||null}),_(!1))};return(0,U.jsxs)(`div`,{children:[(0,U.jsxs)(`div`,{"data-pibo-debug":`room-node`,"data-pibo-room-id":e.id,"data-pibo-state":D?`loading`:e.id===t?`selected`:T?`archived`:`idle`,"data-pibo-pinned":E?`true`:`false`,draggable:u,onDragStart:f,onDragOver:p,onDrop:m,onDragEnd:h,className:`group relative mb-0.5 border rounded-sm ${u?`cursor-grab active:cursor-grabbing`:``} ${w?e.id===t?`border-[#0bda57] bg-[#0bda57]/10`:`border-[#0bda57]/50 bg-[#0bda57]/5`:e.id===t?`border-[#11a4d4] bg-[#11a4d4]/10`:T?`border-[#f59e0b]/40 bg-[#f59e0b]/5`:`border-transparent`}`,style:{marginLeft:l*12},title:O,children:[d===`before`?(0,U.jsx)(`span`,{className:`pointer-events-none absolute inset-x-1 -top-px z-10 h-px bg-[#11a4d4]`}):null,g&&!w?(0,U.jsxs)(`form`,{className:`grid gap-1 p-1`,onSubmit:e=>{e.preventDefault(),j()},children:[(0,U.jsx)(`input`,{value:v,"aria-label":`Room name for ${e.name}`,onChange:e=>y(e.target.value),className:`min-w-0 bg-[#0e1116] border border-slate-700 rounded-sm px-2 py-1 text-sm outline-none focus:border-[#11a4d4]`,autoFocus:!0}),(0,U.jsx)(`input`,{value:b,"aria-label":`Room topic for ${e.name}`,onChange:e=>x(e.target.value),placeholder:`Topic`,className:`min-w-0 bg-[#0e1116] border border-slate-700 rounded-sm px-2 py-1 text-xs outline-none focus:border-[#11a4d4]`}),(0,U.jsx)(`input`,{value:S,"aria-label":`Room workspace for ${e.name}`,onChange:e=>C(e.target.value),placeholder:`Workspace (/absolute/path)`,className:`min-w-0 bg-[#0e1116] border border-slate-700 rounded-sm px-2 py-1 text-xs font-mono outline-none focus:border-[#11a4d4]`}),(0,U.jsxs)(`div`,{className:`flex justify-end gap-1`,children:[(0,U.jsx)(`button`,{type:`submit`,className:`h-7 w-7 inline-flex items-center justify-center border border-slate-700 rounded-sm text-slate-400 hover:border-[#11a4d4] hover:text-[#11a4d4]`,children:(0,U.jsx)(Ws,{size:13})}),(0,U.jsx)(`button`,{type:`button`,onClick:()=>_(!1),className:`h-7 w-7 inline-flex items-center justify-center border border-slate-700 rounded-sm text-slate-400 hover:border-[#11a4d4] hover:text-[#11a4d4]`,children:(0,U.jsx)(jl,{size:13})})]})]}):(0,U.jsxs)(`div`,{className:`grid grid-cols-[1fr_auto] items-center gap-0.5 pr-0.5`,children:[(0,U.jsxs)(`button`,{type:`button`,onClick:()=>r(e.id),"aria-current":e.id===t?`page`:void 0,className:`h-7 max-[980px]:h-8 min-w-0 text-left px-1.5 flex gap-1.5 items-center`,children:[(0,U.jsx)(`span`,{className:`h-5 w-5 shrink-0 inline-flex items-center justify-center rounded-sm ${w?`bg-[#0bda57]/15 text-[#0bda57]`:T?`bg-[#f59e0b]/15 text-[#f59e0b]`:`bg-[#151f24] text-slate-500`}`,children:w?(0,U.jsx)(Ic,{size:12}):T?(0,U.jsx)(ks,{size:12}):(0,U.jsx)(yc,{size:12})}),E&&!T?(0,U.jsx)(`span`,{className:`shrink-0 text-[#11a4d4]`,title:`Pinned room`,"aria-label":`Pinned room`,children:(0,U.jsx)(tl,{size:11,fill:`currentColor`,"aria-hidden":`true`})}):null,(0,U.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-[13px] leading-none ${T?`text-slate-500`:`text-slate-200`}`,children:e.name}),(0,U.jsxs)(`span`,{className:`ml-auto inline-flex items-center justify-end gap-1`,children:[D?(0,U.jsx)(Pc,{size:12,className:`animate-spin text-[#11a4d4]`,"aria-label":`Loading room`}):null,(0,U.jsx)(rRe,{count:e.unreadCount})]})]}),(0,U.jsx)(`div`,{className:`flex items-center gap-0.5 opacity-0 group-hover:opacity-100 group-focus-within:opacity-100 transition-opacity max-[980px]:opacity-100`,children:w?(0,U.jsx)(KJ,{label:`Actions for room ${e.name}`,estimatedHeight:48,children:(0,U.jsxs)(qJ,{onSelect:()=>s(e.id),children:[(0,U.jsx)(Us,{size:16}),` Read All`]})}):(0,U.jsx)(KJ,{label:`Actions for room ${e.name}`,estimatedHeight:T?144:k?240:192,children:T?(0,U.jsxs)(U.Fragment,{children:[(0,U.jsxs)(qJ,{onSelect:A,children:[(0,U.jsx)(sc,{size:16}),` Copy Room ID`]}),(0,U.jsxs)(qJ,{onSelect:()=>a(e.id,!1),children:[(0,U.jsx)(Os,{size:16}),` Restore Room`]}),(0,U.jsxs)(qJ,{onSelect:()=>c(e),className:`text-red-300 hover:bg-red-500/10`,children:[(0,U.jsx)(Cl,{size:16}),` Delete Room`]})]}):(0,U.jsxs)(U.Fragment,{children:[k?(0,U.jsxs)(qJ,{onSelect:()=>o?.(e.id,!E),children:[E?(0,U.jsx)(el,{size:16}):(0,U.jsx)(tl,{size:16}),` `,E?`Unpin Room`:`Pin Room`]}):null,(0,U.jsxs)(qJ,{onSelect:A,children:[(0,U.jsx)(sc,{size:16}),` Copy Room ID`]}),(0,U.jsxs)(qJ,{onSelect:()=>_(!0),children:[(0,U.jsx)($c,{size:16}),` Edit Room`]}),(0,U.jsxs)(qJ,{onSelect:()=>s(e.id),children:[(0,U.jsx)(Us,{size:16}),` Read All`]}),(0,U.jsxs)(qJ,{onSelect:()=>a(e.id,!0),children:[(0,U.jsx)(ks,{size:16}),` Archive Room`]})]})})})]}),d===`after`?(0,U.jsx)(`span`,{className:`pointer-events-none absolute inset-x-1 -bottom-px z-10 h-px bg-[#11a4d4]`}):null]}),(e.children??[]).map(e=>(0,U.jsx)(h$,{room:e,selectedRoomId:t,loadingRoomId:n,onSelect:r,onUpdate:i,onArchive:a,onReadAll:s,onDelete:c,depth:l+1},e.id))]})}async function sRe(){await fetch(`/api/auth/sign-out`,{method:`POST`,credentials:`same-origin`,headers:{"content-type":`application/json`},body:`{}`})}async function cRe(){let e=location.pathname.startsWith(`/apps/chat`)?`${location.pathname}${location.search}`:`/apps/chat`,t=await fetch(`/api/auth/sign-in/social`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({provider:`google`,callbackURL:e,disableRedirect:!0})}),n=await t.json();if(!t.ok||!n.url)throw Error(n.message||n.error||`Could not start Google sign in.`);location.href=n.url}var lRe=[`sessions`,`workflows`,`cron`,`loops`,`agents`,`context`,`settings`],g$={sessions:`sessions`,vscode:`VS Code`,workflows:`workflows`,cron:`cron`,loops:`loops`,agents:`agents`,context:`context`,settings:`settings`};function uRe(e){return e?[`sessions`,`vscode`,`workflows`,`cron`,`loops`,`agents`,`context`,`settings`]:lRe}var _$=`main-navigation-menu`;function v$({identity:e,size:t=`default`}){let[n,r]=(0,H.useState)(!1),[i,a]=(0,H.useState)({left:8,top:8}),o=(0,H.useRef)(null),s=(0,H.useRef)(null),c=(0,H.useId)(),l=e.email||e.name||e.userId,u=t===`large`?`h-8 w-8`:`h-7 w-7`,d=t===`large`?15:14,f=(0,H.useCallback)(()=>{let e=o.current?.getBoundingClientRect();e&&a({left:Math.max(8,Math.min(window.innerWidth-176-8,e.right-176)),top:e.bottom+8})},[]);(0,H.useLayoutEffect)(()=>{n&&(f(),s.current?.querySelector(`[role=menuitem]`)?.focus())},[n,f]),(0,H.useEffect)(()=>{if(!n)return;let e=e=>{let t=e.target;o.current?.contains(t)||s.current?.contains(t)||r(!1)},t=e=>{e.key===`Escape`&&(e.preventDefault(),r(!1),o.current?.focus())};return document.addEventListener(`pointerdown`,e),document.addEventListener(`keydown`,t),window.addEventListener(`resize`,f),window.addEventListener(`scroll`,f,!0),()=>{document.removeEventListener(`pointerdown`,e),document.removeEventListener(`keydown`,t),window.removeEventListener(`resize`,f),window.removeEventListener(`scroll`,f,!0)}},[n,f]);let p=()=>{f(),r(!0)};return(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(`button`,{ref:o,type:`button`,"data-pibo-debug":`account-avatar`,title:l,"aria-label":`Open account menu`,"aria-haspopup":`menu`,"aria-controls":c,"aria-expanded":n,onClick:()=>n?r(!1):p(),onKeyDown:e=>{e.key===`ArrowDown`&&(e.preventDefault(),p())},className:`inline-flex ${u} shrink-0 items-center justify-center rounded-full bg-[#101a1f] text-slate-300 ring-1 ring-inset ring-slate-600 outline-none transition-colors hover:bg-[#11a4d4]/10 hover:text-[#11a4d4] hover:ring-[#11a4d4] focus-visible:ring-2 focus-visible:ring-[#11a4d4]`,children:(0,U.jsx)(El,{size:d})}),n&&typeof document<`u`?(0,Ml.createPortal)((0,U.jsx)(`div`,{ref:s,id:c,role:`menu`,"aria-label":`Account menu`,className:`fixed z-[100] w-44 rounded-sm border border-slate-700 bg-[#1a262b] p-1 shadow-xl`,style:i,children:(0,U.jsxs)(`button`,{type:`button`,role:`menuitem`,"aria-label":`Sign out`,onClick:()=>void sRe().then(()=>location.reload()),className:`flex w-full items-center gap-2 rounded-sm px-3 py-2 text-left text-xs text-slate-300 outline-none hover:bg-slate-800 hover:text-[#11a4d4] focus-visible:bg-slate-800 focus-visible:text-[#11a4d4]`,children:[(0,U.jsx)(Fc,{size:14}),(0,U.jsx)(`span`,{children:`Sign out`})]})}),document.body):null]})}function dRe(){return(0,U.jsxs)(`div`,{className:`fixed top-0 left-0 right-0 z-50 bg-red-600 text-white text-center text-sm font-bold py-1.5 px-4 flex items-center justify-center gap-2 shadow-lg`,children:[(0,U.jsx)(wl,{size:16}),`Recovery Mode: Main gateway is down. You are connected to a fallback instance.`]})}function fRe({area:e,identity:t,mobileAreaMenuOpen:n,mobileSidebarTriggerRef:r,totalRoomUnreadCount:i,vscodeEnabled:a=!1,showMobileSidebarTrigger:o=!0,onOpenMobileSidebar:s,onSelectMainNavArea:c,onToggleMobileAreaMenu:l,onCloseMobileAreaMenu:u}){let d=(0,H.useRef)(null),f=(0,H.useRef)(null),p=(0,H.useRef)([]),m=(0,H.useRef)(null),h=uRe(a),g=e=>{let t=(e+h.length)%h.length;p.current[t]?.focus()},_=e=>{if(n){g(e);return}m.current=e,l()};return(0,H.useLayoutEffect)(()=>{if(!n){m.current=null;return}let e=m.current;e!==null&&(m.current=null,g(e))},[n]),(0,H.useEffect)(()=>{if(!n)return;let e=e=>{d.current&&!d.current.contains(e.target)&&u()},t=e=>{e.key===`Escape`&&(e.preventDefault(),u(),f.current?.focus())};return document.addEventListener(`mousedown`,e),document.addEventListener(`touchstart`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`touchstart`,e),document.removeEventListener(`keydown`,t)}},[n,u]),(0,U.jsxs)(`header`,{className:`relative flex items-center gap-3 px-4 bg-[#1a262b] border-b border-slate-800 min-h-14 max-[980px]:px-3`,children:[(0,U.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[o?(0,U.jsx)(`button`,{ref:r,type:`button`,onClick:s,className:`min-[981px]:hidden shrink-0 p-1.5 border border-slate-700 rounded-sm text-slate-400 hover:border-[#11a4d4] hover:text-[#11a4d4]`,title:`Open sidebar`,"aria-label":`Open sidebar`,children:(0,U.jsx)(Rc,{size:16})}):null,(0,U.jsx)(`img`,{src:`/apps/chat/assets/pwa-images/android/launchericon-512x512.png`,alt:`Logo`,className:`h-5 w-auto shrink-0`}),(0,U.jsx)(`div`,{className:`truncate font-extrabold tracking-[0.08em] uppercase text-lg max-[420px]:text-base`,children:`Pibo Chat`})]}),(0,U.jsx)(`nav`,{"aria-label":`Main navigation`,className:`flex gap-1 max-[1200px]:hidden min-[1201px]:absolute min-[1201px]:left-1/2 min-[1201px]:-translate-x-1/2`,children:h.map(t=>(0,U.jsx)(`button`,{type:`button`,onClick:()=>c(t),"aria-current":e===t?`page`:void 0,className:`h-8 px-3 border rounded-sm text-xs uppercase tracking-wider ${e===t?`border-[#11a4d4] text-[#11a4d4] bg-[#11a4d4]/10`:`border-slate-700 text-slate-400`}`,children:(0,U.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,U.jsx)(`span`,{children:g$[t]}),t===`sessions`?(0,U.jsx)(y$,{count:i}):null]})},t))}),(0,U.jsxs)(`div`,{className:`ml-auto flex shrink-0 items-center justify-end gap-2 text-xs text-slate-400 min-[1201px]:ml-0`,children:[(0,U.jsx)(v$,{identity:t}),(0,U.jsxs)(`div`,{className:`relative min-[1201px]:hidden`,ref:d,children:[(0,U.jsx)(`button`,{ref:f,type:`button`,onClick:()=>{m.current=null,l()},onKeyDown:e=>{e.key===`Enter`||e.key===` `||e.key===`ArrowDown`?(e.preventDefault(),_(0)):e.key===`ArrowUp`&&(e.preventDefault(),_(h.length-1))},className:`p-1 border rounded-sm hover:border-[#11a4d4] hover:text-[#11a4d4] ${n?`border-[#11a4d4] text-[#11a4d4] bg-[#11a4d4]/10`:`border-slate-700 text-slate-400`}`,title:`Open navigation menu`,"aria-label":`Open navigation menu`,"aria-haspopup":`menu`,"aria-controls":_$,"aria-expanded":n,children:(0,U.jsx)(Nc,{size:14})}),n?(0,U.jsx)(`div`,{id:_$,className:`absolute right-0 top-full z-50 mt-2 w-52 rounded-sm border border-slate-700 bg-[#1a262b] p-1 shadow-xl`,role:`menu`,"aria-label":`Main navigation`,onKeyDown:e=>{if(e.key===`Tab`){u();return}let t=p.current.findIndex(e=>e===document.activeElement),n=null;e.key===`ArrowDown`?n=t<0?0:t+1:e.key===`ArrowUp`?n=t<0?h.length-1:t-1:e.key===`Home`?n=0:e.key===`End`&&(n=h.length-1),n!==null&&(e.preventDefault(),e.stopPropagation(),g(n))},children:h.map((t,n)=>(0,U.jsxs)(`button`,{ref:e=>{p.current[n]=e},type:`button`,onClick:()=>{u(),c(t)},"aria-current":e===t?`page`:void 0,className:`flex w-full items-center justify-between gap-2 rounded-sm px-3 py-2 text-left text-xs uppercase tracking-wider ${e===t?`bg-[#11a4d4]/10 text-[#11a4d4]`:`text-slate-300 hover:bg-slate-800/80 hover:text-[#11a4d4]`}`,role:`menuitem`,tabIndex:-1,children:[(0,U.jsx)(`span`,{children:g$[t]}),t===`sessions`?(0,U.jsx)(y$,{count:i}):null]},t))}):null]})]})]})}function pRe({message:e,onDismiss:t}){return(0,U.jsxs)(`div`,{className:`border-b border-red-500/40 bg-red-500/10 px-4 py-2 text-sm text-red-100 flex items-start justify-between gap-3`,children:[(0,U.jsxs)(`div`,{className:`min-w-0 flex items-start gap-2`,children:[(0,U.jsx)(wl,{size:16,className:`mt-0.5 shrink-0 text-red-300`}),(0,U.jsxs)(`div`,{className:`min-w-0`,children:[(0,U.jsx)(`div`,{className:`text-[11px] font-bold uppercase tracking-wider text-red-300`,children:`Session Error`}),(0,U.jsx)(`div`,{className:`break-words`,children:e})]})]}),(0,U.jsx)(`button`,{type:`button`,onClick:t,className:`shrink-0 rounded-sm border border-red-500/40 px-2 py-1 text-[11px] uppercase tracking-wider text-red-200 hover:border-red-300 hover:text-red-100`,children:`Dismiss`})]})}function mRe({message:e}){return(0,U.jsx)(`div`,{className:`min-h-screen bg-[#101d22] text-slate-300 grid place-items-center`,children:(0,U.jsxs)(`div`,{className:`border border-slate-700 bg-[#1a262b] p-5 rounded-sm`,children:[(0,U.jsx)(`div`,{className:`mb-4 text-sm text-slate-400`,children:e}),(0,U.jsx)(`button`,{type:`button`,onClick:()=>void cRe(),className:`px-3 py-2 bg-[#11a4d4] rounded-sm`,children:`Sign in with Google`})]})})}function hRe({message:e,onRetry:t}){return(0,U.jsx)(`div`,{className:`min-h-screen bg-[#101d22] text-slate-300 grid place-items-center px-4`,children:(0,U.jsxs)(`div`,{className:`w-full max-w-md border border-slate-700 bg-[#1a262b] p-5 rounded-sm`,role:`alert`,children:[(0,U.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,U.jsx)(wl,{size:18,className:`mt-0.5 shrink-0 text-orange-400`}),(0,U.jsxs)(`div`,{children:[(0,U.jsx)(`div`,{className:`text-sm font-bold uppercase tracking-wider text-slate-100`,children:`Could not load Pibo Chat`}),(0,U.jsx)(`div`,{className:`mt-2 text-sm text-slate-400`,children:e})]})]}),(0,U.jsxs)(`button`,{type:`button`,onClick:t,className:`mt-4 inline-flex items-center gap-2 px-3 py-2 bg-[#11a4d4] text-white rounded-sm`,children:[(0,U.jsx)(ol,{size:14}),`Retry`]})]})})}function gRe(e){return e>99?`99+`:String(e)}function y$({count:e}){return!e||e<=0?null:(0,U.jsx)(`span`,{className:`min-w-5 h-5 px-1.5 inline-flex items-center justify-center rounded-full bg-[#38bdf8] text-[#0e1116] text-[10px] font-bold tabular-nums leading-none`,"aria-label":`${e} unread messages across all rooms`,title:`${e} unread messages across all rooms`,children:gRe(e)})}var b$=`pibo.chat.desktopSessionSidebar.v1`;function x$(){return{version:1,width:300,collapsed:!1}}function S$(e,t){return{...e,width:C$(t)}}function C$(e){return Number.isFinite(e)?Math.round(Math.max(150,Math.min(680,e))):300}function _Re(e){return JSON.stringify({version:1,width:C$(e.width),collapsed:e.collapsed})}function vRe(e){if(!e)return x$();try{let t=JSON.parse(e);return!xRe(t)||t.version!==1?x$():{version:1,width:C$(typeof t.width==`number`?t.width:300),collapsed:t.collapsed===!0}}catch{return x$()}}function yRe(e=typeof localStorage>`u`?void 0:localStorage){try{return vRe(e?.getItem(b$))}catch{return x$()}}function bRe(e,t=typeof localStorage>`u`?void 0:localStorage){try{t?.setItem(b$,_Re(e))}catch{}}function xRe(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function SRe(){let[e,t]=(0,H.useState)(()=>yRe());return(0,H.useEffect)(()=>bRe(e),[e]),{state:e,setState:t}}function CRe({state:e,onStateChange:t,onRefresh:n,identity:r,children:i,hidden:a=!1}){let o={width:e.collapsed?`44px`:`${e.width}px`};return(0,U.jsxs)(`aside`,{"data-pibo-debug":`desktop-session-sidebar`,"data-pibo-state":e.collapsed?`collapsed`:`open`,tabIndex:-1,hidden:a,"aria-hidden":a||void 0,className:`@container relative min-h-0 shrink-0 overflow-hidden border-r border-slate-800 bg-[#1a262b] outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-[#11a4d4]`,style:o,children:[(0,U.jsx)(`div`,{role:`separator`,"aria-label":`Resize Sessions sidebar`,"aria-orientation":`vertical`,"aria-valuemin":150,"aria-valuemax":680,"aria-valuenow":e.width,tabIndex:e.collapsed?-1:0,onPointerDown:n=>{n.preventDefault();let r=n.clientX,i=n.currentTarget.parentElement?.getBoundingClientRect().width??e.width,a=n=>t(S$(e,i+n.clientX-r)),o=()=>{window.removeEventListener(`pointermove`,a),window.removeEventListener(`pointerup`,o),document.body.style.removeProperty(`cursor`),document.body.style.removeProperty(`user-select`)};document.body.style.cursor=`col-resize`,document.body.style.userSelect=`none`,window.addEventListener(`pointermove`,a),window.addEventListener(`pointerup`,o)},onKeyDown:n=>{(n.key===`ArrowLeft`||n.key===`ArrowRight`)&&(n.preventDefault(),t(S$(e,(n.currentTarget.parentElement?.getBoundingClientRect().width??e.width)+(n.key===`ArrowRight`?24:-24))))},className:`absolute inset-y-0 right-0 z-20 w-2 touch-none cursor-col-resize outline-none hover:bg-[#11a4d4]/35 focus-visible:bg-[#11a4d4]/60 ${e.collapsed?`hidden`:``}`}),e.collapsed?(0,U.jsxs)(`div`,{className:`flex h-full flex-col items-center gap-2 bg-[#151f24] pb-2`,children:[(0,U.jsx)(`div`,{className:`flex h-14 w-full shrink-0 items-center justify-center border-b border-slate-800`,children:(0,U.jsx)(`img`,{src:`/apps/chat/assets/pwa-images/android/launchericon-512x512.png`,alt:`Pibo Chat`,title:`Pibo Chat`,className:`h-5 w-5`})}),(0,U.jsx)(v$,{identity:r,size:`large`}),(0,U.jsx)(`button`,{type:`button`,onClick:()=>t({...e,collapsed:!1}),className:`inline-flex h-8 w-8 items-center justify-center rounded-sm border border-slate-700 text-slate-300 hover:border-[#11a4d4] hover:text-[#11a4d4] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[#11a4d4]`,title:`Reopen Sessions sidebar`,"aria-label":`Reopen Sessions sidebar`,children:(0,U.jsx)(Jc,{size:15})}),(0,U.jsx)(`span`,{className:`mt-1 font-mono text-[10px] text-slate-500 [writing-mode:vertical-rl]`,children:`Sessions`})]}):(0,U.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col`,children:[(0,U.jsxs)(`div`,{"data-pibo-debug":`desktop-sidebar-app-header`,className:`flex h-14 shrink-0 items-center gap-1 border-b border-slate-800 bg-[#1a262b] px-2 @max-[190px]:h-20 @max-[190px]:flex-col @max-[190px]:justify-center @max-[190px]:gap-1 @max-[190px]:py-2`,children:[(0,U.jsxs)(`div`,{className:`flex min-w-0 items-center gap-1.5 @max-[190px]:w-full @max-[190px]:justify-center`,children:[(0,U.jsx)(`img`,{src:`/apps/chat/assets/pwa-images/android/launchericon-512x512.png`,alt:`Logo`,className:`h-4 w-4 shrink-0`}),(0,U.jsx)(`span`,{className:`truncate text-xs font-extrabold uppercase tracking-[0.06em] text-slate-100`,children:`Pibo Chat`})]}),(0,U.jsx)(`div`,{className:`ml-auto flex shrink-0 items-center @max-[190px]:mx-auto`,children:(0,U.jsx)(v$,{identity:r})})]}),(0,U.jsxs)(`div`,{className:`flex h-11 shrink-0 items-center justify-between border-b border-slate-800 px-3 text-xs font-bold uppercase tracking-wider`,children:[(0,U.jsx)(`span`,{className:`truncate`,children:`Sessions`}),(0,U.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1`,children:[(0,U.jsx)(`button`,{type:`button`,onClick:n,title:`Refresh Sessions`,"aria-label":`Refresh Sessions`,className:`p-1 border border-slate-700 rounded-sm text-slate-400 hover:border-[#11a4d4] hover:text-[#11a4d4] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[#11a4d4]`,children:(0,U.jsx)(ol,{size:13})}),(0,U.jsx)(`button`,{type:`button`,onClick:()=>t({...e,collapsed:!0}),title:`Collapse Sessions sidebar`,"aria-label":`Collapse Sessions sidebar`,className:`p-1 border border-slate-700 rounded-sm text-slate-400 hover:border-[#11a4d4] hover:text-[#11a4d4] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[#11a4d4]`,children:(0,U.jsx)(qc,{size:13})})]})]}),i]})]})}var w$=0,T$=1,E$=2,D$=4;function wRe(e){return()=>e}function TRe(e){e()}function O$(e,t){return n=>e(t(n))}function ERe(e,t){return()=>e(t)}function DRe(e,t){return n=>e(t,n)}function k$(e){return e!==void 0}function ORe(...e){return()=>{e.map(TRe)}}function A$(){}function j$(e,t){return t(e),e}function kRe(e,t){return t(e)}function M$(...e){return e}function N$(e,t){return e(T$,t)}function P$(e,t){e(w$,t)}function F$(e){e(E$)}function I$(e){return e(D$)}function L$(e,t){return N$(e,DRe(t,w$))}function R$(e,t){let n=e(T$,e=>{n(),t(e)});return n}function z$(e){let t,n;return r=>i=>{t=i,n&&clearTimeout(n),n=setTimeout(()=>{r(t)},e)}}function B$(e,t){return e===t}function V$(e=B$){let t;return n=>r=>{e(t,r)||(t=r,n(r))}}function H$(e){return t=>n=>{e(n)&&t(n)}}function U$(e){return t=>O$(t,e)}function W$(e){return t=>()=>{t(e)}}function $(e,...t){let n=ARe(...t);return((t,r)=>{switch(t){case E$:F$(e);return;case T$:return N$(e,n(r))}})}function G$(e,t){return n=>r=>{n(t=e(t,r))}}function K$(e){return t=>n=>{e>0?e--:t(n)}}function q$(e){let t=null,n;return r=>i=>{t=i,!n&&(n=setTimeout(()=>{n=void 0,r(t)},e))}}function J$(...e){let t=Array.from({length:e.length}),n=0,r=null,i=2**e.length-1;return e.forEach((e,a)=>{let o=2**a;N$(e,e=>{let s=n;n|=o,t[a]=e,s!==i&&n===i&&r&&(r(),r=null)})}),e=>a=>{let o=()=>{e([a].concat(t))};n===i?o():r=o}}function ARe(...e){return t=>e.reduceRight(kRe,t)}function jRe(e){let t,n,r=()=>t?.();return function(i,a){switch(i){case T$:return a?n===a?void 0:(r(),n=a,t=N$(e,a),t):(r(),A$);case E$:r(),n=null;return}}}function Y$(e){let t=e,n=Z$();return((e,r)=>{switch(e){case w$:t=r;break;case T$:r(t);break;case D$:return t}return n(e,r)})}function X$(e,t){return j$(Y$(t),t=>L$(e,t))}function Z$(){let e=[];return((t,n)=>{switch(t){case w$:e.slice().forEach(e=>{e(n)});return;case E$:e.splice(0);return;case T$:return e.push(n),()=>{let t=e.indexOf(n);t>-1&&e.splice(t,1)}}})}function Q$(e){return j$(Z$(),t=>L$(e,t))}var MRe={singleton:!0};function $$(e,t=[],n=MRe){let{singleton:r}=n;return{constructor:e,dependencies:t,id:NRe(),singleton:r}}var NRe=()=>Symbol(`id`);function PRe(e){let t=new Map,n=({constructor:e,dependencies:r,id:i,singleton:a})=>{if(a&&t.has(i))return t.get(i);let o=e(r.map(e=>n(e)));return a&&t.set(i,o),o};return n(e)}function e1(...e){let t=Z$(),n=Array.from({length:e.length}),r=0,i=2**e.length-1;return e.forEach((e,a)=>{let o=2**a;N$(e,e=>{n[a]=e,r|=o,r===i&&P$(t,n)})}),function(e,a){switch(e){case E$:F$(t);return;case T$:return r===i&&a(n),N$(t,a)}}}function t1(e,t=B$){return $(e,V$(t))}function n1(...e){return function(t,n){switch(t){case E$:return;case T$:return ORe(...e.map(e=>N$(e,n)))}}}var r1={DEBUG:0,INFO:1,WARN:2,ERROR:3},FRe={[r1.DEBUG]:`debug`,[r1.ERROR]:`error`,[r1.INFO]:`log`,[r1.WARN]:`warn`},IRe=()=>typeof globalThis>`u`?window:globalThis,i1=$$(()=>{let e=Y$(r1.ERROR);return{log:Y$((t,n,r=r1.INFO)=>{r>=(IRe().VIRTUOSO_LOG_LEVEL??I$(e))&&console[FRe[r]](`%creact-virtuoso: %c%s %o`,`color: #0253b3; font-weight: bold`,`color: initial`,t,n)}),logLevel:e}},[],{singleton:!0});function LRe(e){return`self`in e?e.document.documentElement:e}function a1(e){let t=LRe(e);return t.ownerDocument.defaultView.getComputedStyle(t).direction===`rtl`}function o1(e,t){return a1(e)?-t:t}function s1(e,t){return a1(e)?-t:t}function c1(e,t,n){return l1(e,t,n).callbackRef}function l1(e,t,n){let r=H.useRef(null),i=e=>{},a=H.useMemo(()=>typeof ResizeObserver<`u`?new ResizeObserver(t=>{let r=()=>{let n=t[0].target;n.offsetParent!==null&&e(n)};n?r():requestAnimationFrame(r)}):null,[e,n]);return i=e=>{e&&t?(a?.observe(e),r.current=e):(r.current&&a?.unobserve(r.current),r.current=null)},{callbackRef:i,ref:r}}function u1(e,t,n,r,i,a,o,s,c){return l1(H.useCallback(n=>{let c=RRe(n.children,t,s?`offsetWidth`:`offsetHeight`,i),l=n.parentElement;for(;l.dataset.virtuosoScroller===void 0;)l=l.parentElement;let u=l.lastElementChild?.dataset.viewportType===`window`,d;u&&(d=l.ownerDocument.defaultView);let f=o?s?o.scrollWidth:o.scrollHeight:u?s?d.document.documentElement.scrollWidth:d.document.documentElement.scrollHeight:s?l.scrollWidth:l.scrollHeight,p=o?s?o.offsetWidth:o.offsetHeight:u?s?d.innerWidth:d.innerHeight:s?l.offsetWidth:l.offsetHeight,m=o?s?o1(o,o.scrollLeft):o.scrollTop:u?s?o1(d,d.scrollX||d.document.documentElement.scrollLeft):d.scrollY||d.document.documentElement.scrollTop:s?o1(l,l.scrollLeft):l.scrollTop;r({scrollHeight:f,scrollTop:Math.max(m,0),viewportHeight:p}),a?.(s?d1(`column-gap`,getComputedStyle(n).columnGap,i):d1(`row-gap`,getComputedStyle(n).rowGap,i)),c!==null&&e(c)},[e,t,i,a,o,r,s]),n,c)}function RRe(e,t,n,r){let i=e.length;if(i===0)return null;let a=[];for(let o=0;o<i;o++){let i=e.item(o);if(i.dataset.index===void 0)continue;let s=parseInt(i.dataset.index,10),c=parseFloat(i.dataset.knownSize),l=t(i,n);if(l===0&&r(`Zero-sized element, this should not happen`,{child:i},r1.ERROR),l===c)continue;let u=a[a.length-1];a.length===0||u.size!==l||u.endIndex!==s-1?a.push({endIndex:s,size:l,startIndex:s}):a[a.length-1].endIndex++}return a}function d1(e,t,n){return t!==`normal`&&t?.endsWith(`px`)!==!0&&n(`${e} was not resolved to pixel value correctly`,t,r1.WARN),t===`normal`?0:parseInt(t??`0`,10)}function f1(e,t,n){let r=H.useRef(null),i=H.useCallback(n=>{if(!n?.offsetParent)return;let i=n.getBoundingClientRect(),a=i.width,s,c;if(t){let e=t.getBoundingClientRect(),n=i.top-e.top;c=e.height-Math.max(0,n),s=n+t.scrollTop}else{let e=o.current.ownerDocument.defaultView;c=e.innerHeight-Math.max(0,i.top),s=i.top+e.scrollY}r.current={listHeight:i.height,offsetTop:s,visibleHeight:c,visibleWidth:a},e(r.current)},[e,t]),{callbackRef:a,ref:o}=l1(i,!0,n),s=H.useCallback(()=>{i(o.current)},[i,o]);return H.useEffect(()=>{if(t){t.addEventListener(`scroll`,s);let e=new ResizeObserver(()=>{requestAnimationFrame(s)});return e.observe(t),()=>{t.removeEventListener(`scroll`,s),e.unobserve(t)}}let e=o.current?.ownerDocument.defaultView;return e?.addEventListener(`scroll`,s),e?.addEventListener(`resize`,s),()=>{e?.removeEventListener(`scroll`,s),e?.removeEventListener(`resize`,s)}},[s,t,o]),a}var p1=$$(()=>{let e=Z$(),t=Z$(),n=Y$(0),r=Z$(),i=Y$(0),a=Z$(),o=Z$(),s=Y$(0),c=Y$(0),l=Y$(0),u=Y$(0),d=Z$(),f=Z$(),p=Y$(!1),m=Y$(!1),h=Y$(!1);return L$($(e,U$(({scrollTop:e})=>e)),t),L$($(e,U$(({scrollHeight:e})=>e)),o),L$(t,i),{deviation:n,fixedFooterHeight:l,fixedHeaderHeight:c,footerHeight:u,headerHeight:s,horizontalDirection:m,scrollBy:f,scrollContainerState:e,scrollHeight:o,scrollingInProgress:p,scrollTo:d,scrollTop:t,skipAnimationFrameInResizeObserver:h,smoothScrollTargetReached:r,statefulScrollTop:i,viewportHeight:a}},[],{singleton:!0}),m1={lvl:0};function h1(e,t){let n=e.length;if(n===0)return[];let{index:r,value:i}=t(e[0]),a=[];for(let o=1;o<n;o++){let{index:n,value:s}=t(e[o]);a.push({end:n-1,start:r,value:i}),r=n,i=s}return a.push({end:1/0,start:r,value:i}),a}function g1(e){return e===m1}function _1(e,t){if(!g1(e))return t===e.k?e.v:t<e.k?_1(e.l,t):_1(e.r,t)}function v1(e,t,n=`k`){if(g1(e))return[-1/0,void 0];if(Number(e[n])===t)return[e.k,e.v];if(Number(e[n])<t){let r=v1(e.r,t,n);return r[0]===-1/0?[e.k,e.v]:r}return v1(e.l,t,n)}function y1(e,t,n){return g1(e)?A1(t,n,1):t===e.k?E1(e,{k:t,v:n}):t<e.k?j1(E1(e,{l:y1(e.l,t,n)})):j1(E1(e,{r:y1(e.r,t,n)}))}function b1(){return m1}function x1(e,t,n){if(g1(e))return[];let r=v1(e,t)[0];return zRe(w1(e,r,n))}function S1(e,t){if(g1(e))return m1;let{k:n,l:r,r:i}=e;if(t===n){if(g1(r))return i;if(g1(i))return r;let[t,n]=k1(r);return T1(E1(e,{k:t,l:D1(r),v:n}))}return T1(t<n?E1(e,{l:S1(r,t)}):E1(e,{r:S1(i,t)}))}function C1(e){return g1(e)?[]:[...C1(e.l),{k:e.k,v:e.v},...C1(e.r)]}function w1(e,t,n){if(g1(e))return[];let{k:r,l:i,r:a,v:o}=e,s=[];return r>t&&(s=s.concat(w1(i,t,n))),r>=t&&r<=n&&s.push({k:r,v:o}),r<=n&&(s=s.concat(w1(a,t,n))),s}function T1(e){let{l:t,lvl:n,r}=e;if(r.lvl>=n-1&&t.lvl>=n-1)return e;if(n>r.lvl+1){if(O1(t))return M1(E1(e,{lvl:n-1}));if(!g1(t)&&!g1(t.r))return E1(t.r,{l:E1(t,{r:t.r.l}),lvl:n,r:E1(e,{l:t.r.r,lvl:n-1})});throw Error(`Unexpected empty nodes`)}if(O1(e))return N1(E1(e,{lvl:n-1}));if(!g1(r)&&!g1(r.l)){let t=r.l,i=O1(t)?r.lvl-1:r.lvl;return E1(t,{l:E1(e,{lvl:n-1,r:t.l}),lvl:t.lvl+1,r:N1(E1(r,{l:t.r,lvl:i}))})}throw Error(`Unexpected empty nodes`)}function E1(e,t){return A1(t.k===void 0?e.k:t.k,t.v===void 0?e.v:t.v,t.lvl===void 0?e.lvl:t.lvl,t.l===void 0?e.l:t.l,t.r===void 0?e.r:t.r)}function D1(e){return g1(e.r)?e.l:T1(E1(e,{r:D1(e.r)}))}function O1(e){return g1(e)||e.lvl>e.r.lvl}function k1(e){return g1(e.r)?[e.k,e.v]:k1(e.r)}function A1(e,t,n,r=m1,i=m1){return{k:e,l:r,lvl:n,r:i,v:t}}function j1(e){return N1(M1(e))}function M1(e){let{l:t}=e;return!g1(t)&&t.lvl===e.lvl?E1(t,{r:E1(e,{l:t.r})}):e}function N1(e){let{lvl:t,r:n}=e;return!g1(n)&&!g1(n.r)&&n.lvl===t&&n.r.lvl===t?E1(n,{l:E1(e,{r:n.l}),lvl:t+1}):e}function zRe(e){return h1(e,({k:e,v:t})=>({index:e,value:t}))}function P1(e,t){return!!(e&&e.startIndex===t.startIndex&&e.endIndex===t.endIndex)}function F1(e,t){return!!(e&&e[0]===t[0]&&e[1]===t[1])}var I1=$$(()=>({recalcInProgress:Y$(!1)}),[],{singleton:!0});function L1(e,t,n){return e[R1(e,t,n)]}function R1(e,t,n,r=0){let i=e.length-1;for(;r<=i;){let a=Math.floor((r+i)/2),o=e[a],s=n(o,t);if(s===0)return a;if(s===-1){if(i-r<2)return a-1;i=a-1}else{if(i===r)return a;r=a+1}}throw Error(`Failed binary finding record in array - ${e.join(`,`)}, searched for ${t}`)}function BRe(e,t,n,r){let i=R1(e,t,r),a=R1(e,n,r,i);return e.slice(i,a+1)}function z1(e,t){return Math.round(e.getBoundingClientRect()[t])}function B1(e){return!g1(e.groupOffsetTree)}function V1({index:e},t){return t===e?0:t<e?-1:1}function VRe(){return{groupIndices:[],groupOffsetTree:b1(),lastIndex:0,lastOffset:0,lastSize:0,offsetTree:[],sizeTree:b1()}}function HRe(e,t){let n=g1(e)?0:1/0;for(let r of t){let{endIndex:t,size:i,startIndex:a}=r;if(n=Math.min(n,a),g1(e)){e=y1(e,0,i);continue}let o=x1(e,a-1,t+1);if(o.some(YRe(r)))continue;let s=!1,c=!1;for(let{end:n,start:r,value:a}of o)s?(t>=r||i===a)&&(e=S1(e,r)):(c=a!==i,s=!0),n>t&&t>=r&&a!==i&&(e=y1(e,t+1,a));c&&(e=y1(e,a,i))}return[e,n]}function URe(e){return e.groupIndex!==void 0}function WRe({offset:e},t){return t===e?0:t<e?-1:1}function H1(e,t,n){if(t.length===0)return 0;let{index:r,offset:i,size:a}=L1(t,e,V1),o=e-r,s=a*o+(o-1)*n+i;return s>0?s+n:s}function U1(e,t){if(!B1(t))return e;let n=0;for(;t.groupIndices[n]<=e+n;)n++;return e+n}function W1(e,t,n){if(URe(e))return t.groupIndices[e.groupIndex]+1;let r=U1(e.index===`LAST`?n:e.index,t);return r=Math.max(0,Math.min(n,r)),r}function GRe(e,t,n,r=0){return r>0&&(t=Math.max(t,L1(e,r,V1).offset)),h1(BRe(e,t,n,WRe),JRe)}function KRe(e,[t,n,r,i]){t.length>0&&r(`received item sizes`,t,r1.DEBUG);let a=e.sizeTree,o=a,s=0;if(n.length>0&&g1(a)&&t.length===2){let e=t[0].size,r=t[1].size;o=n.reduce((t,n)=>y1(y1(t,n,e),n+1,r),o)}else[o,s]=HRe(o,t);if(o===a)return e;let{lastIndex:c,lastOffset:l,lastSize:u,offsetTree:d}=K1(e.offsetTree,s,o,i);return{groupIndices:n,groupOffsetTree:n.reduce((e,t)=>y1(e,t,H1(t,d,i)),b1()),lastIndex:c,lastOffset:l,lastSize:u,offsetTree:d,sizeTree:o}}function qRe(e){return C1(e).map(({k:e,v:t},n,r)=>{let i=r[n+1];return{endIndex:i===void 0?1/0:i.k-1,size:t,startIndex:e}})}function G1(e,t){let n=0,r=0;for(;n<e;)n+=t[r+1]-t[r]-1,r++;return r-(n===e?0:1)}function K1(e,t,n,r){let i=e,a=0,o=0,s=0,c=0;if(t===0)i=[];else{c=R1(i,t-1,V1),s=i[c].offset;let e=v1(n,t-1);a=e[0],o=e[1],i.length&&i[c].size===v1(n,t)[1]&&--c,i=i.slice(0,c+1)}for(let{start:e,value:c}of x1(n,t,1/0)){let t=e-a,n=t*o+s+t*r;i.push({index:e,offset:n,size:c}),a=e,s=n,o=c}return{lastIndex:a,lastOffset:s,lastSize:o,offsetTree:i}}function JRe(e){return{index:e.index,value:e}}function YRe(e){let{endIndex:t,size:n,startIndex:r}=e;return e=>e.start===r&&(e.end===t||e.end===1/0)&&e.value===n}var XRe={offsetHeight:`height`,offsetWidth:`width`},q1=$$(([{log:e},{recalcInProgress:t}])=>{let n=Z$(),r=Z$(),i=X$(r,0),a=Z$(),o=Z$(),s=Y$(0),c=Y$([]),l=Y$(void 0),u=Y$(void 0),d=Y$(void 0),f=Y$(void 0),p=Y$((e,t)=>z1(e,XRe[t])),m=Y$(void 0),h=Y$(0),g=VRe(),_=X$($(n,J$(c,e,h),G$(KRe,g),V$()),g),v=X$($(c,V$(),G$((e,t)=>({current:t,prev:e.current}),{current:[],prev:[]}),U$(({prev:e})=>e)),[]);L$($(c,H$(e=>e.length>0),J$(_,h),U$(([e,t,n])=>{let r=e.reduce((e,r,i)=>y1(e,r,H1(r,t.offsetTree,n)||i),b1());return{...t,groupIndices:e,groupOffsetTree:r}})),_),L$($(r,J$(_),H$(([e,{lastIndex:t}])=>e<t),U$(([e,{lastIndex:t,lastSize:n}])=>[{endIndex:t,size:n,startIndex:e}])),n),L$(l,u);let y=X$($(l,U$(e=>e===void 0)),!0);L$($(u,H$(e=>e!==void 0&&g1(I$(_).sizeTree)),U$(e=>{let t=I$(d),n=I$(c).length>0;return t!==void 0&&t!==0?n?[{endIndex:0,size:t,startIndex:0},{endIndex:1,size:e,startIndex:1}]:[]:[{endIndex:0,size:e,startIndex:0}]})),n),L$($(f,H$(e=>e!==void 0&&e.length>0&&g1(I$(_).sizeTree)),U$(e=>{let t=[],n=e[0],r=0;for(let i=1;i<e.length;i++){let a=e[i];a!==n&&(t.push({endIndex:i-1,size:n,startIndex:r}),n=a,r=i)}return t.push({endIndex:e.length-1,size:n,startIndex:r}),t})),n),L$($(c,J$(d,u),H$(([,e,t])=>e!==void 0&&t!==void 0),U$(([e,t,n])=>{let r=[];for(let i=0;i<e.length;i++){let a=e[i],o=e[i+1];r.push({startIndex:a,endIndex:a,size:t}),o!==void 0&&r.push({startIndex:a+1,endIndex:o-1,size:n})}return r})),n);let b=Q$($(n,J$(_),G$(({sizes:e},[t,n])=>({changed:n!==e,sizes:n}),{changed:!1,sizes:g}),U$(e=>e.changed)));N$($(s,G$((e,t)=>({diff:e.prev-t,prev:t}),{diff:0,prev:0}),U$(e=>e.diff)),e=>{let{groupIndices:n}=I$(_);if(e>0)P$(t,!0),P$(a,e+G1(e,n));else if(e<0){let t=I$(v);t.length>0&&(e-=G1(-e,t)),P$(o,e)}}),N$($(s,J$(e)),([e,t])=>{e<0&&t("`firstItemIndex` prop should not be set to less than zero. If you don't know the total count, just use a very high value",{firstItemIndex:s},r1.ERROR)});let x=Q$(a);L$($(a,J$(_),U$(([e,t])=>{let n=t.groupIndices.length>0,r=[],i=t.lastSize;if(n){let n=_1(t.sizeTree,0),a=0,o=0;for(;a<e;){let e=t.groupIndices[o],s=t.groupIndices.length===o+1?1/0:t.groupIndices[o+1]-e-1;r.push({endIndex:e,size:n,startIndex:e}),r.push({endIndex:e+1+s-1,size:i,startIndex:e+1}),o++,a+=s+1}let s=C1(t.sizeTree);return a!==e&&s.shift(),s.reduce((t,{k:n,v:r})=>{let i=t.ranges;return t.prevSize!==0&&(i=[...t.ranges,{endIndex:n+e-1,size:t.prevSize,startIndex:t.prevIndex}]),{prevIndex:n+e,prevSize:r,ranges:i}},{prevIndex:e,prevSize:0,ranges:r}).ranges}return C1(t.sizeTree).reduce((t,{k:n,v:r})=>({prevIndex:n+e,prevSize:r,ranges:[...t.ranges,{endIndex:n+e-1,size:t.prevSize,startIndex:t.prevIndex}]}),{prevIndex:0,prevSize:i,ranges:[]}).ranges})),n);let S=Q$($(o,J$(_,h),U$(([e,{offsetTree:t},n])=>H1(-e,t,n))));return L$($(o,J$(_,h),U$(([e,t,n])=>{if(t.groupIndices.length>0){if(g1(t.sizeTree))return t;let r=b1(),i=I$(v),a=0,o=0,s=0;for(;a<-e;){s=i[o];let e=i[o+1]-s-1;o++,a+=e+1}if(r=C1(t.sizeTree).reduce((t,{k:n,v:r})=>y1(t,Math.max(0,n+e),r),r),a!==-e){let n=_1(t.sizeTree,s);r=y1(r,0,n);let i=v1(t.sizeTree,-e+1)[1];r=y1(r,1,i)}return{...t,sizeTree:r,...K1(t.offsetTree,0,r,n)}}let r=C1(t.sizeTree).reduce((t,{k:n,v:r})=>y1(t,Math.max(0,n+e),r),b1());return{...t,sizeTree:r,...K1(t.offsetTree,0,r,n)}})),_),{beforeUnshiftWith:x,data:m,defaultItemSize:u,firstItemIndex:s,fixedItemSize:l,fixedGroupSize:d,gap:h,groupIndices:c,heightEstimates:f,itemSize:p,listRefresh:b,shiftWith:o,shiftWithOffset:S,sizeRanges:n,sizes:_,statefulTotalCount:i,totalCount:r,trackItemSizes:y,unshiftWith:a}},M$(i1,I1),{singleton:!0});function ZRe(e){return e.reduce((e,t)=>(e.groupIndices.push(e.totalCount),e.totalCount+=t+1,e),{groupIndices:[],totalCount:0})}var J1=$$(([{groupIndices:e,sizes:t,totalCount:n},{headerHeight:r,scrollTop:i}])=>{let a=Z$(),o=Z$(),s=Q$($(a,U$(ZRe)));return L$($(s,U$(e=>e.totalCount)),n),L$($(s,U$(e=>e.groupIndices)),e),L$($(e1(i,t,r),H$(([e,t])=>B1(t)),U$(([e,t,n])=>v1(t.groupOffsetTree,Math.max(e-n,0),`v`)[0]),V$(),U$(e=>[e])),o),{groupCounts:a,topItemsIndexes:o}},M$(q1,p1)),Y1=$$(([{log:e}])=>{let t=Y$(!1),n=Q$($(t,H$(e=>e),V$()));return N$(t,t=>{t&&I$(e)(`props updated`,{},r1.DEBUG)}),{didMount:n,propsReady:t}},M$(i1),{singleton:!0}),QRe=typeof document<`u`&&`scrollBehavior`in document.documentElement.style;function X1(e){let t=typeof e==`number`?{index:e}:{...e};return t.align||=`start`,(!t.behavior||!QRe)&&(t.behavior=`auto`),t.offset===void 0&&(t.offset=0),t}var Z1=$$(([{gap:e,listRefresh:t,sizes:n,totalCount:r},{fixedFooterHeight:i,fixedHeaderHeight:a,footerHeight:o,headerHeight:s,scrollingInProgress:c,scrollTo:l,smoothScrollTargetReached:u,viewportHeight:d},{log:f}])=>{let p=Z$(),m=Z$(),h=Y$(0),g=null,_=null,v=null;function y(){g!==null&&(g(),g=null),v!==null&&(v(),v=null),_&&=(clearTimeout(_),null),P$(c,!1)}return L$($(p,J$(n,d,r,h,s,o,f),J$(e,a,i),U$(([[e,n,r,i,a,o,s,l],d,f,h])=>{let b=X1(e),{align:x,behavior:S,offset:C}=b,w=i-1,T=W1(b,n,w),E=H1(T,n.offsetTree,d)+o;x===`end`?(E+=f+v1(n.sizeTree,T)[1]-r+h,T===w&&(E+=s)):x===`center`?E+=(f+v1(n.sizeTree,T)[1]-r+h)/2:E-=a,C!==void 0&&C!==0&&(E+=C);let D=t=>{y(),t?(l(`retrying to scroll to`,{location:e},r1.DEBUG),P$(p,e)):(P$(m,!0),l(`list did not change, scroll successful`,{},r1.DEBUG))};if(y(),S===`smooth`){let e=!1;v=N$(t,t=>{e||=t}),g=R$(u,()=>{D(e)})}else g=R$($(t,$Re(150)),D);return _=setTimeout(()=>{y()},1200),P$(c,!0),l(`scrolling from index to`,{behavior:S,index:T,top:E},r1.DEBUG),{behavior:S,top:E}})),l),{scrollTargetReached:m,scrollToIndex:p,topListHeight:h}},M$(q1,p1,i1),{singleton:!0});function $Re(e){return t=>{let n=setTimeout(()=>{t(!1)},e);return e=>{e&&(t(!0),clearTimeout(n))}}}function Q1(e,t){e===0?t():requestAnimationFrame(()=>{Q1(e-1,t)})}function $1(e,t){if(e===void 0)return 0;let n=t-1,r=typeof e==`number`?e:e.index===`LAST`?n:e.index;return Math.max(0,Math.min(r,n))}function e0(e){return e===void 0?!0:typeof e==`number`?e===0:e.index===0&&(e.align===void 0||e.align===`start`)&&(e.offset===void 0||e.offset===0)}var t0=$$(([{defaultItemSize:e,listRefresh:t,sizes:n},{scrollTop:r},{scrollTargetReached:i,scrollToIndex:a},{didMount:o}])=>{let s=Y$(!0),c=Y$(0),l=Y$(!0);return L$($(o,J$(c),H$(([e,t])=>!e0(t)),W$(!1)),s),L$($(o,J$(c),H$(([e,t])=>!e0(t)),W$(!1)),l),N$($(e1(t,o),J$(s,n,e,l),H$(([[,e],t,{sizeTree:n},r,i])=>e&&(!g1(n)||k$(r))&&!t&&!i),J$(c)),([,e])=>{if(e===void 0){P$(s,!0),P$(l,!0);return}R$(i,()=>{P$(l,!0)}),Q1(4,()=>{R$(r,()=>{P$(s,!0)}),P$(a,e)})}),{initialItemFinalLocationReached:l,initialTopMostItemIndex:c,scrolledToInitialItem:s}},M$(q1,p1,Z1,Y1),{singleton:!0});function n0(e,t){return Math.abs(e-t)<1.01}var r0=`up`,i0=`down`,eze=`none`,tze={atBottom:!1,notAtBottomBecause:`NOT_SHOWING_LAST_ITEM`,state:{offsetBottom:0,scrollHeight:0,scrollTop:0,viewportHeight:0}},nze=0,a0=$$(([{footerHeight:e,headerHeight:t,scrollBy:n,scrollContainerState:r,scrollTop:i,viewportHeight:a}])=>{let o=Y$(!1),s=Y$(!0),c=Z$(),l=Z$(),u=Y$(4),d=Y$(nze),f=X$($(n1($(t1(i),K$(1),W$(!0)),$(t1(i),K$(1),W$(!1),z$(100))),V$()),!1),p=X$($(n1($(n,W$(!0)),$(n,W$(!1),z$(200))),V$()),!1);L$($(e1(t1(i),t1(d)),U$(([e,t])=>e<=t),V$()),s),L$($(s,q$(50)),l);let m=Q$($(e1(r,t1(a),t1(t),t1(e),t1(u)),G$((e,[{scrollHeight:t,scrollTop:n},r,i,a,o])=>{let s=n+r-t>-o,c={scrollHeight:t,scrollTop:n,viewportHeight:r};if(s){let t,r;return n>e.state.scrollTop?(t=`SCROLLED_DOWN`,r=e.state.scrollTop-n):(t=`SIZE_DECREASED`,r=e.state.scrollTop-n||e.scrollTopDelta),{atBottom:!0,atBottomBecause:t,scrollTopDelta:r,state:c}}let l;return l=c.scrollHeight>e.state.scrollHeight?`SIZE_INCREASED`:r<e.state.viewportHeight?`VIEWPORT_HEIGHT_DECREASING`:n<e.state.scrollTop?`SCROLLING_UPWARDS`:`NOT_FULLY_SCROLLED_TO_LAST_ITEM_BOTTOM`,{atBottom:!1,notAtBottomBecause:l,state:c}},tze),V$((e,t)=>e!==void 0&&e.atBottom===t.atBottom))),h=X$($(r,G$((e,{scrollHeight:t,scrollTop:n,viewportHeight:r})=>{if(!n0(e.scrollHeight,t)){let i=t-(n+r)<1;return e.scrollTop!==n&&i?{changed:!0,jump:e.scrollTop-n,scrollHeight:t,scrollTop:n}:{changed:!0,jump:0,scrollHeight:t,scrollTop:n}}return{changed:!1,jump:0,scrollHeight:t,scrollTop:n}},{changed:!1,jump:0,scrollHeight:0,scrollTop:0}),H$(e=>e.changed),U$(e=>e.jump)),0);L$($(m,U$(e=>e.atBottom)),o),L$($(o,q$(50)),c);let g=Y$(i0);L$($(r,U$(({scrollTop:e})=>e),V$(),G$((e,t)=>I$(p)?{direction:e.direction,prevScrollTop:t}:{direction:t<e.prevScrollTop?r0:i0,prevScrollTop:t},{direction:i0,prevScrollTop:0}),U$(e=>e.direction)),g),L$($(r,q$(50),W$(eze)),g);let _=Y$(0);return L$($(f,H$(e=>!e),W$(0)),_),L$($(i,q$(100),J$(f),H$(([e,t])=>t),G$(([e,t],[n])=>[t,n],[0,0]),U$(([e,t])=>t-e)),_),{atBottomState:m,atBottomStateChange:c,atBottomThreshold:u,atTopStateChange:l,atTopThreshold:d,isAtBottom:o,isAtTop:s,isScrolling:f,lastJumpDueToItemResize:h,scrollDirection:g,scrollVelocity:_}},M$(p1)),o0=`top`,s0=`bottom`,c0=`none`;function l0(e,t,n){return typeof e==`number`?n===r0&&t===o0||n===i0&&t===s0?e:0:n===r0?t===o0?e.main:e.reverse:t===s0?e.main:e.reverse}function u0(e,t){return typeof e==`number`?e:e[t]??0}var d0=$$(([{deviation:e,fixedHeaderHeight:t,headerHeight:n,scrollTop:r,viewportHeight:i}])=>{let a=Z$(),o=Y$(0),s=Y$(0),c=Y$(0);return{increaseViewportBy:s,listBoundary:a,overscan:c,topListHeight:o,visibleRange:X$($(e1(t1(r),t1(i),t1(n),t1(a,F1),t1(c),t1(o),t1(t),t1(e),t1(s)),U$(([e,t,n,[r,i],a,o,s,c,l])=>{let u=e-c,d=o+s,f=Math.max(n-u,0),p=c0,m=u0(l,o0),h=u0(l,s0);return r-=c,r+=n+s,i+=n+s,i-=c,r>e+d-m&&(p=r0),i<e-f+t+h&&(p=i0),p===c0?null:[Math.max(u-n-l0(a,o0,p)-m,0),u-f-s+t+l0(a,s0,p)+h]}),H$(e=>e!==null),V$(F1)),[0,0])}},M$(p1),{singleton:!0});function rze(e,t,n){if(B1(t)){let r=U1(e,t);return[{index:v1(t.groupOffsetTree,r)[0],offset:0,size:0},{data:n?.[0],index:r,offset:0,size:0}]}return[{data:n?.[0],index:e,offset:0,size:0}]}var f0={bottom:0,firstItemIndex:0,items:[],offsetBottom:0,offsetTop:0,top:0,topItems:[],topListHeight:0,totalCount:0};function p0(e,t,n,r,i,a){let{lastIndex:o,lastOffset:s,lastSize:c}=i,l=0,u=0;if(e.length>0){l=e[0].offset;let t=e[e.length-1];u=t.offset+t.size}let d=n-o,f=s+d*c+(d-1)*r,p=l,m=f-u;return{bottom:u,firstItemIndex:a,items:h0(e,i,a),offsetBottom:m,offsetTop:l,top:p,topItems:h0(t,i,a),topListHeight:t.reduce((e,t)=>t.size+e,0),totalCount:n}}function m0(e,t,n,r,i,a){let o=0;if(n.groupIndices.length>0)for(let t of n.groupIndices){if(t-o>=e)break;o++}let s=e+o,c=$1(t,s);return p0(Array.from({length:s}).map((e,t)=>({data:a[t+c],index:t+c,offset:0,size:0})),[],s,i,n,r)}function h0(e,t,n){if(e.length===0)return[];if(!B1(t))return e.map(e=>({...e,index:e.index+n,originalIndex:e.index}));let r=e[0].index,i=e[e.length-1].index,a=[],o=x1(t.groupOffsetTree,r,i),s,c=0;for(let r of e){(!s||s.end<r.index)&&(s=o.shift(),c=t.groupIndices.indexOf(s.start));let e;e=r.index===s.start?{index:c,type:`group`}:{groupIndex:c,index:r.index-(c+1)+n},a.push({...e,data:r.data,offset:r.offset,originalIndex:r.index,size:r.size})}return a}function g0(e,t){return e===void 0?0:typeof e==`number`?e:e[t]??0}var _0=$$(([{data:e,firstItemIndex:t,gap:n,sizes:r,totalCount:i},a,{listBoundary:o,topListHeight:s,visibleRange:c},{initialTopMostItemIndex:l,scrolledToInitialItem:u},{topListHeight:d},f,{didMount:p},{recalcInProgress:m}])=>{let h=Y$([]),g=Y$(0),_=Z$(),v=Y$(0);L$(a.topItemsIndexes,h);let y=X$($(e1(p,m,t1(c,F1),t1(i),t1(r),t1(l),u,t1(h),t1(t),t1(n),t1(v),e),H$(([e,t,,n,,,,,,,,r])=>{let i=r!==void 0&&r.length!==n;return e&&!t&&!i}),U$(([,,[e,t],n,r,i,a,o,s,c,l,u])=>{let d=r,{offsetTree:f,sizeTree:p}=d,m=I$(g);if(n===0)return{...f0,totalCount:n};if(e===0&&t===0)return m===0?{...f0,totalCount:n}:m0(m,i,r,s,c,u||[]);if(g1(p))return m>0?null:p0(rze($1(i,n),d,u),[],n,c,d,s);let h=[];if(o.length>0){let e=o[0],t=o[o.length-1],n=0;for(let r of x1(p,e,t)){let i=r.value,a=Math.max(r.start,e),o=Math.min(r.end,t);for(let e=a;e<=o;e++)h.push({data:u?.[e],index:e,offset:n,size:i}),n+=i}}if(!a)return p0([],h,n,c,d,s);let _=o.length>0?o[o.length-1]+1:0,v=GRe(f,e,t,_);if(v.length===0)return null;let y=n-1,b=j$([],n=>{for(let r of v){let i=r.value,a=i.offset,o=r.start,s=i.size;if(i.offset<e){o+=Math.floor((e-i.offset+c)/(s+c));let t=o-r.start;a+=t*s+t*c}o<_&&(a+=(_-o)*s,o=_);let l=Math.min(r.end,y);for(let e=o;e<=l&&!(a>=t);e++)n.push({data:u?.[e],index:e,offset:a,size:s}),a+=s+c}}),x=g0(l,o0),S=g0(l,s0);if(b.length>0&&(x>0||S>0)){let e=b[0],t=b[b.length-1];if(x>0&&e.index>_){let t=Math.min(x,e.index-_),n=[],r=e.offset;for(let i=e.index-1;i>=e.index-t;i--){let t=x1(p,i,i)[0]?.value??e.size;r-=t+c,n.unshift({data:u?.[i],index:i,offset:r,size:t})}b.unshift(...n)}if(S>0&&t.index<y){let e=Math.min(S,y-t.index),n=t.offset+t.size+c;for(let r=t.index+1;r<=t.index+e;r++){let e=x1(p,r,r)[0]?.value??t.size;b.push({data:u?.[r],index:r,offset:n,size:e}),n+=e+c}}}return p0(b,h,n,c,d,s)}),H$(e=>e!==null),V$()),f0);L$($(e,H$(k$),U$(e=>e?.length)),i),L$($(y,U$(e=>e.topListHeight)),d),L$(d,s),L$($(y,U$(e=>[e.top,e.bottom])),o),L$($(y,U$(e=>e.items)),_);let b=Q$($(y,H$(({items:e})=>e.length>0),J$(i,e),H$(([{items:e},t])=>e[e.length-1].originalIndex===t-1),U$(([,e,t])=>[e-1,t]),V$(F1),U$(([e])=>e))),x=Q$($(y,q$(200),H$(({items:e,topItems:t})=>e.length>0&&e[0].originalIndex===t.length),U$(({items:e})=>e[0].index),V$()));return{endReached:b,initialItemCount:g,itemsRendered:_,listState:y,minOverscanItemCount:v,rangeChanged:Q$($(y,H$(({items:e})=>e.length>0),U$(({items:e})=>{let t=0,n=e.length-1;for(;e[t].type===`group`&&t<n;)t++;for(;e[n].type===`group`&&n>t;)n--;return{endIndex:e[n].index,startIndex:e[t].index}}),V$(P1))),startReached:x,topItemsIndexes:h,...f}},M$(q1,J1,d0,t0,Z1,a0,Y1,I1),{singleton:!0}),v0=$$(([{fixedFooterHeight:e,fixedHeaderHeight:t,footerHeight:n,headerHeight:r},{listState:i}])=>{let a=Z$(),o=X$($(e1(n,e,r,t,i),U$(([e,t,n,r,i])=>e+t+n+r+i.offsetBottom+i.bottom)),0);return L$(t1(o),a),{totalListHeight:o,totalListHeightChanged:a}},M$(p1,_0),{singleton:!0}),ize=$$(([{viewportHeight:e},{totalListHeight:t}])=>{let n=Y$(!1);return{alignToBottom:n,paddingTopAddition:X$($(e1(n,e,t),H$(([e])=>e),U$(([,e,t])=>Math.max(0,e-t)),q$(0),V$()),0)}},M$(p1,v0),{singleton:!0}),y0=$$(()=>({context:Y$(null)})),aze=({itemBottom:e,itemTop:t,locationParams:{align:n,behavior:r,...i},viewportBottom:a,viewportTop:o})=>t<o?{...i,align:n??`start`,...r===void 0?{}:{behavior:r}}:e>a?{...i,align:n??`end`,...r===void 0?{}:{behavior:r}}:null,b0=$$(([{gap:e,sizes:t,totalCount:n},{fixedFooterHeight:r,fixedHeaderHeight:i,headerHeight:a,scrollingInProgress:o,scrollTop:s,viewportHeight:c},{scrollToIndex:l}])=>{let u=Z$();return L$($(u,J$(t,c,n,a,i,r,s),J$(e),U$(([[e,t,n,r,i,a,s,c],l])=>{let{calculateViewLocation:u=aze,done:d,...f}=e,p=W1(e,t,r-1),m=H1(p,t.offsetTree,l)+i+a,h=m+v1(t.sizeTree,p)[1],g=c+a,_=u({itemBottom:h,itemTop:m,locationParams:f,viewportBottom:c+n-s,viewportTop:g});return _===null?d?.():d&&R$($(o,H$(e=>!e),K$(I$(o)?1:2)),d),_}),H$(e=>e!==null)),l),{scrollIntoView:u}},M$(q1,p1,Z1,_0,i1),{singleton:!0});function x0(e){return e===!1?!1:e===`smooth`?`smooth`:`auto`}var oze=(e,t)=>typeof e==`function`?x0(e(t)):t&&x0(e),sze=$$(([{listRefresh:e,totalCount:t,fixedItemSize:n,data:r},{atBottomState:i,isAtBottom:a},{scrollToIndex:o},{scrolledToInitialItem:s},{didMount:c,propsReady:l},{log:u},{scrollingInProgress:d},{context:f},{scrollIntoView:p}])=>{let m=Y$(!1),h=Z$(),g=null;function _(e){P$(o,{align:`end`,behavior:e,index:`LAST`})}N$($(e1($(t1(t),K$(1)),c),J$(t1(m),a,s,d),U$(([[e,t],n,r,i,a])=>{let o=t&&i,s=`auto`;return o&&(s=oze(n,r||a),o&&=s!==!1),{followOutputBehavior:s,shouldFollow:o,totalCount:e}}),H$(({shouldFollow:e})=>e)),({followOutputBehavior:t,totalCount:r})=>{g!==null&&(g(),g=null),I$(n)===void 0?g=R$(e,()=>{I$(u)(`following output to `,{totalCount:r},r1.DEBUG),_(t),g=null}):requestAnimationFrame(()=>{I$(u)(`following output to `,{totalCount:r},r1.DEBUG),_(t)})});function v(e){let t=R$(i,t=>{e&&!t.atBottom&&t.notAtBottomBecause===`SIZE_INCREASED`&&g===null&&(I$(u)(`scrolling to bottom due to increased size`,{},r1.DEBUG),_(`auto`))});setTimeout(t,100)}N$($(e1(t1(m),t,l),H$(([e,,t])=>e!==!1&&t),G$(({value:e},[,t])=>({refreshed:e===t,value:t}),{refreshed:!1,value:0}),H$(({refreshed:e})=>e),J$(m,t)),([,e])=>{I$(s)&&v(e!==!1)}),N$(h,()=>{v(I$(m)!==!1)}),N$(e1(t1(m),i),([e,t])=>{e!==!1&&!t.atBottom&&t.notAtBottomBecause===`VIEWPORT_HEIGHT_DECREASING`&&_(`auto`)});let y=Y$(null),b=Z$();return L$(n1($(t1(r),U$(e=>e?.length??0)),$(t1(t))),b),N$($(e1($(b,K$(1)),c),J$(t1(y),s,d,f),U$(([[e,t],n,r,i,a])=>t&&r&&n?.({context:a,totalCount:e,scrollingInProgress:i})),H$(e=>!!e),q$(0)),t=>{g!==null&&(g(),g=null),I$(n)===void 0?g=R$(e,()=>{I$(u)(`scrolling into view`,{}),P$(p,t),g=null}):requestAnimationFrame(()=>{I$(u)(`scrolling into view`,{}),P$(p,t)})}),{autoscrollToBottom:h,followOutput:m,scrollIntoViewOnChange:y}},M$(q1,a0,Z1,t0,Y1,i1,p1,y0,b0)),cze=$$(([{data:e,firstItemIndex:t,gap:n,sizes:r},{initialTopMostItemIndex:i},{initialItemCount:a,listState:o},{didMount:s}])=>(L$($(s,J$(a),H$(([,e])=>e!==0),J$(i,r,t,n,e),U$(([[,e],t,n,r,i,a=[]])=>m0(e,t,n,r,i,a))),o),{}),M$(q1,t0,_0,Y1),{singleton:!0}),lze=$$(([{didMount:e},{scrollTo:t},{listState:n}])=>{let r=Y$(0);return N$($(e,J$(r),H$(([,e])=>e!==0),U$(([,e])=>({top:e}))),e=>{R$($(n,K$(1),H$(e=>e.items.length>1)),()=>{requestAnimationFrame(()=>{P$(t,e)})})}),{initialScrollTop:r}},M$(Y1,p1,_0),{singleton:!0}),S0=$$(([{scrollVelocity:e}])=>{let t=Y$(!1),n=Z$(),r=Y$(!1);return L$($(e,J$(r,t,n),H$(([e,t])=>t!==!1&&t!==void 0),U$(([e,t,n,r])=>{let{enter:i,exit:a}=t;if(n){if(a(e,r))return!1}else if(i(e,r))return!0;return n}),V$()),t),N$($(e1(t,e,n),J$(r)),([[e,t,n],r])=>{e&&r!==!1&&r!==void 0&&r.change&&r.change(t,n)}),{isSeeking:t,scrollSeekConfiguration:r,scrollSeekRangeChanged:n,scrollVelocity:e}},M$(a0),{singleton:!0}),C0=$$(([{scrollContainerState:e,scrollTo:t}])=>{let n=Z$(),r=Z$(),i=Z$(),a=Y$(!1),o=Y$(void 0);return L$($(e1(n,r),U$(([{scrollTop:e,viewportHeight:t},{offsetTop:n,listHeight:r}])=>({scrollHeight:r,scrollTop:Math.max(0,e-n),viewportHeight:t}))),e),L$($(t,J$(r),U$(([e,{offsetTop:t}])=>({...e,top:e.top+t}))),i),{customScrollParent:o,useWindowScroll:a,windowScrollContainerState:n,windowScrollTo:i,windowViewportRect:r}},M$(p1)),uze=$$(([{sizeRanges:e,sizes:t},{headerHeight:n,scrollTop:r},{initialTopMostItemIndex:i},{didMount:a},{useWindowScroll:o,windowScrollContainerState:s,windowViewportRect:c}])=>{let l=Z$(),u=Y$(void 0),d=Y$(null),f=Y$(null);return L$(s,d),L$(c,f),N$($(l,J$(t,r,o,d,f,n)),([e,t,n,r,i,a,o])=>{let s=qRe(t.sizeTree);r&&i!==null&&a!==null&&(n=i.scrollTop-a.offsetTop),n-=o,e({ranges:s,scrollTop:n})}),L$($(u,H$(k$),U$(dze)),i),L$($(a,J$(u),H$(([,e])=>e!==void 0),V$(),U$(([,e])=>e.ranges)),e),{getState:l,restoreStateFrom:u}},M$(q1,p1,t0,Y1,C0));function dze(e){return{align:`start`,index:0,offset:e.scrollTop}}var fze=$$(([{topItemsIndexes:e}])=>{let t=Y$(0);return L$($(t,H$(e=>e>=0),U$(e=>Array.from({length:e}).map((e,t)=>t))),e),{topItemCount:t}},M$(_0));function w0(e){let t=!1,n;return(()=>(t||(t=!0,n=e()),n))}var pze=w0(()=>/iP(ad|od|hone)/i.test(navigator.userAgent)&&/WebKit/i.test(navigator.userAgent)),T0=$$(([{data:e,defaultItemSize:t,firstItemIndex:n,fixedItemSize:r,fixedGroupSize:i,gap:a,groupIndices:o,heightEstimates:s,itemSize:c,sizeRanges:l,sizes:u,statefulTotalCount:d,totalCount:f,trackItemSizes:p},{initialItemFinalLocationReached:m,initialTopMostItemIndex:h,scrolledToInitialItem:g},_,v,y,b,{scrollToIndex:x},S,{topItemCount:C},{groupCounts:w},T])=>{let{listState:E,minOverscanItemCount:D,topItemsIndexes:O,rangeChanged:k,...A}=b;return L$(k,T.scrollSeekRangeChanged),L$($(e1(T.windowViewportRect,_.headerHeight,_.fixedHeaderHeight),U$(([e,t,n])=>Math.max(t+n+1,e.visibleHeight))),_.viewportHeight),{data:e,defaultItemHeight:t,firstItemIndex:n,fixedItemHeight:r,fixedGroupHeight:i,gap:a,groupCounts:w,heightEstimates:s,initialItemFinalLocationReached:m,initialTopMostItemIndex:h,scrolledToInitialItem:g,sizeRanges:l,topItemCount:C,topItemsIndexes:O,totalCount:f,...y,groupIndices:o,itemSize:c,listState:E,minOverscanItemCount:D,scrollToIndex:x,statefulTotalCount:d,trackItemSizes:p,rangeChanged:k,...A,...T,..._,sizes:u,...v}},M$(q1,t0,p1,uze,sze,_0,Z1,$$(([{deviation:e,scrollBy:t,scrollingInProgress:n,scrollTop:r},{isAtBottom:i,isScrolling:a,lastJumpDueToItemResize:o,scrollDirection:s},{listState:c},{beforeUnshiftWith:l,gap:u,shiftWithOffset:d,sizes:f},{log:p},{recalcInProgress:m}])=>{let h=Q$($(c,J$(o),G$(([,e,t,n],[{bottom:r,items:i,offsetBottom:a,totalCount:o},s])=>{let c=r+a,l=0;return t===o&&e.length>0&&i.length>0&&(i[0].originalIndex===0&&e[0].originalIndex===0||(l=c-n,l!==0&&(l+=s))),[l,i,o,c]},[0,[],0,0]),H$(([e])=>e!==0),J$(r,s,n,i,p,m),H$(([,e,t,n,,,r])=>!r&&!n&&e!==0&&t===r0),U$(([[e],,,,,t])=>(t(`Upward scrolling compensation`,{amount:e},r1.DEBUG),e))));function g(n){n>0?(P$(t,{behavior:`auto`,top:-n}),P$(e,0)):(P$(e,0),P$(t,{behavior:`auto`,top:-n}))}return N$($(h,J$(e,a)),([t,n,r])=>{r&&pze()?P$(e,n-t):g(-t)}),N$($(e1(X$(a,!1),e,m),H$(([e,t,n])=>!e&&!n&&t!==0),U$(([e,t])=>t),q$(1)),g),L$($(d,U$(e=>({top:-e}))),t),N$($(l,J$(f,u),U$(([e,{groupIndices:t,lastSize:n,sizeTree:r},i])=>{function a(e){return e*(n+i)}if(t.length===0)return a(e);let o=0,s=_1(r,0),c=0,l=0;for(;c<e;){c++,o+=s;let n=t.length===l+1?1/0:t[l+1]-t[l]-1;c+n>e&&(o-=s,n=e-c+1),c+=n,o+=a(n),l++}return o})),n=>{P$(e,n),requestAnimationFrame(()=>{P$(t,{top:n}),requestAnimationFrame(()=>{P$(e,0),P$(m,!1)})})}),{deviation:e}},M$(p1,a0,_0,q1,i1,I1)),fze,J1,$$(([e,t,n,r,i,a,o,s,c,l,u])=>({...e,...t,...n,...r,...i,...a,...o,...s,...c,...l,...u}),M$(d0,cze,Y1,S0,v0,lze,ize,C0,b0,i1,y0))));function mze(e,t){let n={},r={},i=0,a=e.length;for(;i<a;)r[e[i]]=1,i+=1;for(let e in t)Object.hasOwn(r,e)||(n[e]=t[e]);return n}var E0=typeof document>`u`?H.useEffect:H.useLayoutEffect;function D0(e,t,n){let r=Object.keys(t.required||{}),i=Object.keys(t.optional||{}),a=Object.keys(t.methods||{}),o=Object.keys(t.events||{}),s=H.createContext({});function c(e,n){e.propsReady!==void 0&&P$(e.propsReady,!1);for(let i of r){let r=e[t.required[i]];P$(r,n[i])}for(let r of i)if(r in n){let i=e[t.optional[r]];P$(i,n[r])}e.propsReady!==void 0&&P$(e.propsReady,!0)}function l(e){return a.reduce((n,r)=>(n[r]=n=>{let i=e[t.methods[r]];P$(i,n)},n),{})}function u(e){return o.reduce((n,r)=>(n[r]=jRe(e[t.events[r]]),n),{})}return{Component:H.forwardRef(function(t,a){let{children:d,...f}=t,[p]=H.useState(()=>j$(PRe(e),e=>{c(e,f)})),[m]=H.useState(ERe(u,p));E0(()=>{for(let e of o)e in f&&N$(m[e],f[e]);return()=>{Object.values(m).map(F$)}},[f,m,p]),E0(()=>{c(p,f)}),H.useImperativeHandle(a,wRe(l(p)));let h=n;return(0,U.jsx)(s.Provider,{value:p,children:n===void 0?d:(0,U.jsx)(h,{...mze([...r,...i,...o],f),children:d})})}),useEmitter:(e,t)=>{let n=H.useContext(s)[e];E0(()=>N$(n,t),[t,n])},useEmitterValue:e=>{let t=H.useContext(s)[e],n=H.useCallback(e=>N$(t,e),[t]);return H.useSyncExternalStore(n,()=>I$(t),()=>I$(t))},usePublisher:e=>{let t=H.useContext(s);return H.useCallback(n=>{P$(t[e],n)},[t,e])}}}var O0=H.createContext(void 0),k0=H.createContext(void 0),A0=`-webkit-sticky`,j0=`sticky`,M0=w0(()=>{if(typeof document>`u`)return j0;let e=document.createElement(`div`);return e.style.position=A0,e.style.position===A0?A0:j0}),N0=typeof document>`u`?H.useEffect:H.useLayoutEffect;function P0(e){return`self`in e}function hze(e){return`body`in e}function F0(e,t,n,r=A$,i,a){let o=H.useRef(null),s=H.useRef(null),c=H.useRef(null),l=H.useCallback(n=>{let r,i,o,l=n.target;if(hze(l)||P0(l)){let e=P0(l)?l:l.defaultView;o=a===!0?o1(e,e.scrollX):e.scrollY,r=a===!0?e.document.documentElement.scrollWidth:e.document.documentElement.scrollHeight,i=a===!0?e.innerWidth:e.innerHeight}else o=a===!0?o1(l,l.scrollLeft):l.scrollTop,r=a===!0?l.scrollWidth:l.scrollHeight,i=a===!0?l.offsetWidth:l.offsetHeight;let u=()=>{e({scrollHeight:r,scrollTop:Math.max(o,0),viewportHeight:i})};n.suppressFlushSync===!0?u():Ml.flushSync(u),s.current!==null&&(o===s.current||o<=0||o===r-i)&&(s.current=null,t(!0),c.current&&=(clearTimeout(c.current),null))},[e,t,a]);H.useEffect(()=>{let e=i??o.current;return r(i??o.current),l({suppressFlushSync:!0,target:e}),e.addEventListener(`scroll`,l,{passive:!0}),()=>{r(null),e.removeEventListener(`scroll`,l)}},[o,l,n,r,i]);function u(n){let r=o.current;if(!r||(a===!0?`offsetWidth`in r&&r.offsetWidth===0:`offsetHeight`in r&&r.offsetHeight===0))return;let i=n.behavior===`smooth`,l,u,d;P0(r)?(u=Math.max(z1(r.document.documentElement,a===!0?`width`:`height`),a===!0?r.document.documentElement.scrollWidth:r.document.documentElement.scrollHeight),l=a===!0?r.innerWidth:r.innerHeight,d=a===!0?o1(r,r.scrollX):r.scrollY):(u=r[a===!0?`scrollWidth`:`scrollHeight`],l=z1(r,a===!0?`width`:`height`),d=a===!0?o1(r,r.scrollLeft):r.scrollTop);let f=u-l;if(n.top===void 0){r.scrollTo(n);return}let p=Math.ceil(Math.max(Math.min(f,n.top),0));if(n.top=p,n0(l,u)||p===d){e({scrollHeight:u,scrollTop:d,viewportHeight:l}),i&&t(!0);return}i?(s.current=p,c.current&&clearTimeout(c.current),c.current=setTimeout(()=>{c.current=null,s.current=null,t(!0)},1e3)):s.current=null,a===!0&&(n={...n.behavior===void 0?{}:{behavior:n.behavior},left:s1(r,p)}),r.scrollTo(n)}function d(e){a===!0&&(e={...e.behavior===void 0?{}:{behavior:e.behavior},...e.top===void 0?{}:{left:s1(o.current,e.top)}}),o.current.scrollBy(e)}return{scrollByCallback:d,scrollerRef:o,scrollToCallback:u}}function I0(e){return e}var gze=$$(([e,t])=>({...e,...t}),M$(T0,$$(()=>{let e=Y$(e=>`Item ${e}`),t=Y$(e=>`Group ${e}`),n=Y$({}),r=Y$(I0),i=Y$(`div`),a=Y$(A$),o=(e,t=null)=>X$($(n,U$(t=>t[e]),V$()),t);return{components:n,computeItemKey:r,EmptyPlaceholder:o(`EmptyPlaceholder`),FooterComponent:o(`Footer`),GroupComponent:o(`Group`,`div`),groupContent:t,HeaderComponent:o(`Header`),HeaderFooterTag:i,ItemComponent:o(`Item`,`div`),itemContent:e,ListComponent:o(`List`,`div`),ScrollerComponent:o(`Scroller`,`div`),scrollerRef:a,ScrollSeekPlaceholder:o(`ScrollSeekPlaceholder`),TopItemListComponent:o(`TopItemList`)}}))),_ze=({height:e})=>(0,U.jsx)(`div`,{style:{height:e}}),vze={overflowAnchor:`none`,position:M0(),zIndex:1},L0={overflowAnchor:`none`},yze={...L0,display:`inline-block`,height:`100%`},R0=H.memo(function({showTopList:e=!1}){let t=K0(`listState`),n=q0(`sizeRanges`),r=K0(`useWindowScroll`),i=K0(`customScrollParent`),a=q0(`windowScrollContainerState`),o=q0(`scrollContainerState`),s=i||r?a:o,c=K0(`itemContent`),l=K0(`context`),u=K0(`groupContent`),d=K0(`trackItemSizes`),f=K0(`itemSize`),p=K0(`log`),m=q0(`gap`),h=K0(`horizontalDirection`),{callbackRef:g}=u1(n,f,d,e?A$:s,p,m,i,h,K0(`skipAnimationFrameInResizeObserver`)),[_,v]=H.useState(0);G0(`deviation`,e=>{_!==e&&v(e)});let y=K0(`EmptyPlaceholder`),b=K0(`ScrollSeekPlaceholder`)??_ze,x=K0(`ListComponent`),S=K0(`ItemComponent`),C=K0(`GroupComponent`),w=K0(`computeItemKey`),T=K0(`isSeeking`),E=K0(`groupIndices`).length>0,D=K0(`alignToBottom`),O=K0(`initialItemFinalLocationReached`),k=e?{}:{boxSizing:`border-box`,...h?{display:`inline-block`,height:`100%`,marginInlineStart:_===0?D?`auto`:0:_,paddingInlineEnd:t.offsetBottom,paddingInlineStart:t.offsetTop,whiteSpace:`nowrap`}:{marginTop:_===0?D?`auto`:0:_,paddingBottom:t.offsetBottom,paddingTop:t.offsetTop},...O?{}:{visibility:`hidden`}};return!e&&t.totalCount===0&&y!=null?(0,U.jsx)(y,{...V0(y,l)}):(0,U.jsx)(x,{...V0(x,l),"data-testid":e?`virtuoso-top-item-list`:`virtuoso-item-list`,ref:g,style:k,children:(e?t.topItems:t.items).map(e=>{let n=e.originalIndex,r=w(n+t.firstItemIndex,e.data,l);return T?(0,H.createElement)(b,{...V0(b,l),height:e.size,index:e.index,key:r,type:e.type||`item`,...e.type===`group`?{}:{groupIndex:e.groupIndex}}):e.type===`group`?(0,H.createElement)(C,{...V0(C,l),"data-index":n,"data-item-index":e.index,"data-known-size":e.size,key:r,style:vze},u(e.index,l)):(0,H.createElement)(S,{...V0(S,l),...H0(S,e.data),"data-index":n,"data-item-group-index":e.groupIndex,"data-item-index":e.index,"data-known-size":e.size,key:r,style:h?yze:L0},E?c(e.index,e.groupIndex,e.data,l):c(e.index,e.data,l))})})}),bze={height:`100%`,outline:`none`,overflowY:`auto`,position:`relative`,WebkitOverflowScrolling:`touch`},xze={outline:`none`,overflowX:`auto`,position:`relative`},z0=e=>({height:`100%`,position:`absolute`,top:0,width:`100%`,...e?{display:`flex`,flexDirection:`column`}:void 0}),B0=(e,t,n=0)=>({...z0(e),position:t?`relative`:`absolute`,top:t?-n:0}),Sze={position:M0(),top:0,width:`100%`,zIndex:1};function V0(e,t){if(typeof e!=`string`)return{context:t}}function H0(e,t){return{item:typeof e==`string`?void 0:t}}var Cze=H.memo(function(){let e=K0(`HeaderComponent`),t=q0(`headerHeight`),n=K0(`HeaderFooterTag`),r=c1(H.useMemo(()=>e=>{t(z1(e,`height`))},[t]),!0,K0(`skipAnimationFrameInResizeObserver`)),i=K0(`context`);return e==null?null:(0,U.jsx)(n,{ref:r,children:(0,U.jsx)(e,{...V0(e,i)})})}),wze=H.memo(function(){let e=K0(`FooterComponent`),t=q0(`footerHeight`),n=K0(`HeaderFooterTag`),r=c1(H.useMemo(()=>e=>{t(z1(e,`height`))},[t]),!0,K0(`skipAnimationFrameInResizeObserver`)),i=K0(`context`);return e==null?null:(0,U.jsx)(n,{ref:r,children:(0,U.jsx)(e,{...V0(e,i)})})});function U0({useEmitter:e,useEmitterValue:t,usePublisher:n}){return H.memo(function({children:r,style:i,context:a,...o}){let s=n(`scrollContainerState`),c=t(`ScrollerComponent`),l=n(`smoothScrollTargetReached`),u=t(`scrollerRef`),d=t(`horizontalDirection`)||!1,{scrollByCallback:f,scrollerRef:p,scrollToCallback:m}=F0(s,l,c,u,void 0,d);return e(`scrollTo`,m),e(`scrollBy`,f),(0,U.jsx)(c,{"data-testid":`virtuoso-scroller`,"data-virtuoso-scroller":!0,ref:p,style:{...d?xze:bze,...i},tabIndex:0,...o,...V0(c,a),children:r})})}function W0({useEmitter:e,useEmitterValue:t,usePublisher:n}){return H.memo(function({children:r,style:i,context:a,...o}){let s=n(`windowScrollContainerState`),c=t(`ScrollerComponent`),l=n(`smoothScrollTargetReached`),u=t(`totalListHeight`),d=t(`deviation`),f=t(`customScrollParent`),p=H.useRef(null),{scrollByCallback:m,scrollerRef:h,scrollToCallback:g}=F0(s,l,c,t(`scrollerRef`),f);return N0(()=>(h.current=f??p.current?.ownerDocument.defaultView,()=>{h.current=null}),[h,f]),e(`windowScrollTo`,g),e(`scrollBy`,m),(0,U.jsx)(c,{ref:p,"data-virtuoso-scroller":!0,style:{position:`relative`,...i,...u===0?void 0:{height:u+d}},...o,...V0(c,a),children:r})})}var Tze=({children:e})=>{let t=H.useContext(O0),n=q0(`viewportHeight`),r=q0(`fixedItemHeight`),i=K0(`alignToBottom`),a=K0(`horizontalDirection`),o=c1(H.useMemo(()=>O$(n,e=>z1(e,a?`width`:`height`)),[n,a]),!0,K0(`skipAnimationFrameInResizeObserver`));return H.useEffect(()=>{t&&(n(t.viewportHeight),r(t.itemHeight))},[t,n,r]),(0,U.jsx)(`div`,{"data-viewport-type":`element`,ref:o,style:z0(i),children:e})},Eze=({children:e})=>{let t=H.useContext(O0),n=q0(`windowViewportRect`),r=q0(`fixedItemHeight`),i=K0(`customScrollParent`),a=K0(`useWindowScroll`),o=K0(`topListHeight`),s=f1(n,i,K0(`skipAnimationFrameInResizeObserver`)),c=K0(`alignToBottom`);return H.useEffect(()=>{t&&(r(t.itemHeight),n({listHeight:0,offsetTop:0,visibleHeight:t.viewportHeight,visibleWidth:100}))},[t,n,r]),(0,U.jsx)(`div`,{"data-viewport-type":`window`,ref:s,style:B0(c,a,o),children:e})},Dze=({children:e})=>{let t=K0(`TopItemListComponent`)??`div`,n=K0(`headerHeight`),r={...Sze,marginTop:`${n}px`},i=K0(`context`);return(0,U.jsx)(t,{style:r,...V0(t,i),children:e})},{Component:Oze,useEmitter:G0,useEmitterValue:K0,usePublisher:q0}=D0(gze,{optional:{restoreStateFrom:`restoreStateFrom`,context:`context`,followOutput:`followOutput`,scrollIntoViewOnChange:`scrollIntoViewOnChange`,itemContent:`itemContent`,groupContent:`groupContent`,overscan:`overscan`,increaseViewportBy:`increaseViewportBy`,minOverscanItemCount:`minOverscanItemCount`,totalCount:`totalCount`,groupCounts:`groupCounts`,topItemCount:`topItemCount`,firstItemIndex:`firstItemIndex`,initialTopMostItemIndex:`initialTopMostItemIndex`,components:`components`,atBottomThreshold:`atBottomThreshold`,atTopThreshold:`atTopThreshold`,computeItemKey:`computeItemKey`,defaultItemHeight:`defaultItemHeight`,fixedGroupHeight:`fixedGroupHeight`,fixedItemHeight:`fixedItemHeight`,heightEstimates:`heightEstimates`,itemSize:`itemSize`,scrollSeekConfiguration:`scrollSeekConfiguration`,headerFooterTag:`HeaderFooterTag`,data:`data`,initialItemCount:`initialItemCount`,initialScrollTop:`initialScrollTop`,alignToBottom:`alignToBottom`,useWindowScroll:`useWindowScroll`,customScrollParent:`customScrollParent`,scrollerRef:`scrollerRef`,logLevel:`logLevel`,horizontalDirection:`horizontalDirection`,skipAnimationFrameInResizeObserver:`skipAnimationFrameInResizeObserver`},methods:{scrollToIndex:`scrollToIndex`,scrollIntoView:`scrollIntoView`,scrollTo:`scrollTo`,scrollBy:`scrollBy`,autoscrollToBottom:`autoscrollToBottom`,getState:`getState`},events:{isScrolling:`isScrolling`,endReached:`endReached`,startReached:`startReached`,rangeChanged:`rangeChanged`,atBottomStateChange:`atBottomStateChange`,atTopStateChange:`atTopStateChange`,totalListHeightChanged:`totalListHeightChanged`,itemsRendered:`itemsRendered`,groupIndices:`groupIndices`}},H.memo(function(e){let t=K0(`useWindowScroll`),n=K0(`topItemsIndexes`).length>0,r=K0(`customScrollParent`),i=K0(`context`);return(0,U.jsxs)(r||t?Aze:kze,{...e,context:i,children:[n&&(0,U.jsx)(Dze,{children:(0,U.jsx)(R0,{showTopList:!0})}),(0,U.jsxs)(r||t?Eze:Tze,{children:[(0,U.jsx)(Cze,{}),(0,U.jsx)(R0,{}),(0,U.jsx)(wze,{})]})]})})),kze=U0({useEmitter:G0,useEmitterValue:K0,usePublisher:q0}),Aze=W0({useEmitter:G0,useEmitterValue:K0,usePublisher:q0}),jze=Oze,Mze=$$(([e,t])=>({...e,...t}),M$(T0,$$(()=>{let e=Y$(e=>(0,U.jsxs)(`td`,{children:[`Item $`,e]})),t=Y$(null),n=Y$(e=>(0,U.jsxs)(`td`,{colSpan:1e3,children:[`Group `,e]})),r=Y$(null),i=Y$(null),a=Y$({}),o=Y$(I0),s=Y$(A$),c=(e,t=null)=>X$($(a,U$(t=>t[e]),V$()),t);return{components:a,computeItemKey:o,context:t,EmptyPlaceholder:c(`EmptyPlaceholder`),FillerRow:c(`FillerRow`),fixedFooterContent:i,fixedHeaderContent:r,itemContent:e,groupContent:n,ScrollerComponent:c(`Scroller`,`div`),scrollerRef:s,ScrollSeekPlaceholder:c(`ScrollSeekPlaceholder`),TableBodyComponent:c(`TableBody`,`tbody`),TableComponent:c(`Table`,`table`),TableFooterComponent:c(`TableFoot`,`tfoot`),TableHeadComponent:c(`TableHead`,`thead`),TableRowComponent:c(`TableRow`,`tr`),GroupComponent:c(`Group`,`tr`)}}))),Nze=({height:e})=>(0,U.jsx)(`tr`,{children:(0,U.jsx)(`td`,{style:{height:e}})}),Pze=({height:e})=>(0,U.jsx)(`tr`,{children:(0,U.jsx)(`td`,{style:{border:0,height:e,padding:0}})}),Fze={overflowAnchor:`none`},J0={position:M0(),zIndex:2,overflowAnchor:`none`},Y0=H.memo(function({showTopList:e=!1}){let t=Z0(`listState`),n=Z0(`computeItemKey`),r=Z0(`firstItemIndex`),i=Z0(`context`),a=Z0(`isSeeking`),o=Z0(`fixedHeaderHeight`),s=Z0(`groupIndices`).length>0,c=Z0(`itemContent`),l=Z0(`groupContent`),u=Z0(`ScrollSeekPlaceholder`)??Nze,d=Z0(`GroupComponent`),f=Z0(`TableRowComponent`),p=(e?t.topItems:[]).reduce((e,t,n)=>(n===0?e.push(t.size):e.push(e[n-1]+t.size),e),[]);return(e?t.topItems:t.items).map(t=>{let m=t.originalIndex,h=n(m+r,t.data,i),g=e?m===0?0:p[m-1]:0;return a?(0,H.createElement)(u,{...V0(u,i),height:t.size,index:t.index,key:h,type:t.type||`item`}):t.type===`group`?(0,H.createElement)(d,{...V0(d,i),"data-index":m,"data-item-index":t.index,"data-known-size":t.size,key:h,style:{...J0,top:o}},l(t.index,i)):(0,H.createElement)(f,{...V0(f,i),...H0(f,t.data),"data-index":m,"data-item-index":t.index,"data-known-size":t.size,"data-item-group-index":t.groupIndex,key:h,style:e?{...J0,top:o+g}:Fze},s?c(t.index,t.groupIndex,t.data,i):c(t.index,t.data,i))})}),Ize=H.memo(function(){let e=Z0(`listState`),t=Z0(`topItemsIndexes`).length>0,n=Q0(`sizeRanges`),r=Z0(`useWindowScroll`),i=Z0(`customScrollParent`),a=Q0(`windowScrollContainerState`),o=Q0(`scrollContainerState`),s=i||r?a:o,c=Z0(`trackItemSizes`),{callbackRef:l,ref:u}=u1(n,Z0(`itemSize`),c,s,Z0(`log`),void 0,i,!1,Z0(`skipAnimationFrameInResizeObserver`)),[d,f]=H.useState(0);X0(`deviation`,e=>{d!==e&&(u.current.style.marginTop=`${e}px`,f(e))});let p=Z0(`EmptyPlaceholder`),m=Z0(`FillerRow`)??Pze,h=Z0(`TableBodyComponent`),g=Z0(`paddingTopAddition`),_=Z0(`statefulTotalCount`),v=Z0(`context`);if(_===0&&p!=null)return(0,U.jsx)(p,{...V0(p,v)});let y=(t?e.topItems:[]).reduce((e,t)=>e+t.size,0),b=e.offsetTop+g+d-y,x=e.offsetBottom,S=b>0?(0,U.jsx)(m,{context:v,height:b},`padding-top`):null,C=x>0?(0,U.jsx)(m,{context:v,height:x},`padding-bottom`):null;return(0,U.jsxs)(h,{"data-testid":`virtuoso-item-list`,ref:l,...V0(h,v),children:[S,t&&(0,U.jsx)(Y0,{showTopList:!0}),(0,U.jsx)(Y0,{}),C]})}),Lze=({children:e})=>{let t=H.useContext(O0),n=Q0(`viewportHeight`),r=Q0(`fixedItemHeight`),i=c1(H.useMemo(()=>O$(n,e=>z1(e,`height`)),[n]),!0,Z0(`skipAnimationFrameInResizeObserver`));return H.useEffect(()=>{t&&(n(t.viewportHeight),r(t.itemHeight))},[t,n,r]),(0,U.jsx)(`div`,{"data-viewport-type":`element`,ref:i,style:z0(!1),children:e})},Rze=({children:e})=>{let t=H.useContext(O0),n=Q0(`windowViewportRect`),r=Q0(`fixedItemHeight`),i=Z0(`customScrollParent`),a=Z0(`useWindowScroll`),o=f1(n,i,Z0(`skipAnimationFrameInResizeObserver`));return H.useEffect(()=>{t&&(r(t.itemHeight),n({listHeight:0,offsetTop:0,visibleHeight:t.viewportHeight,visibleWidth:100}))},[t,n,r]),(0,U.jsx)(`div`,{"data-viewport-type":`window`,ref:o,style:B0(!1,a),children:e})},{Component:zze,useEmitter:X0,useEmitterValue:Z0,usePublisher:Q0}=D0(Mze,{optional:{restoreStateFrom:`restoreStateFrom`,context:`context`,followOutput:`followOutput`,firstItemIndex:`firstItemIndex`,itemContent:`itemContent`,groupContent:`groupContent`,fixedHeaderContent:`fixedHeaderContent`,fixedFooterContent:`fixedFooterContent`,overscan:`overscan`,increaseViewportBy:`increaseViewportBy`,minOverscanItemCount:`minOverscanItemCount`,totalCount:`totalCount`,topItemCount:`topItemCount`,initialTopMostItemIndex:`initialTopMostItemIndex`,components:`components`,groupCounts:`groupCounts`,atBottomThreshold:`atBottomThreshold`,atTopThreshold:`atTopThreshold`,computeItemKey:`computeItemKey`,defaultItemHeight:`defaultItemHeight`,fixedGroupHeight:`fixedGroupHeight`,fixedItemHeight:`fixedItemHeight`,itemSize:`itemSize`,scrollSeekConfiguration:`scrollSeekConfiguration`,data:`data`,initialItemCount:`initialItemCount`,initialScrollTop:`initialScrollTop`,alignToBottom:`alignToBottom`,useWindowScroll:`useWindowScroll`,customScrollParent:`customScrollParent`,scrollerRef:`scrollerRef`,logLevel:`logLevel`},methods:{scrollToIndex:`scrollToIndex`,scrollIntoView:`scrollIntoView`,scrollTo:`scrollTo`,scrollBy:`scrollBy`,getState:`getState`},events:{isScrolling:`isScrolling`,endReached:`endReached`,startReached:`startReached`,rangeChanged:`rangeChanged`,atBottomStateChange:`atBottomStateChange`,atTopStateChange:`atTopStateChange`,totalListHeightChanged:`totalListHeightChanged`,itemsRendered:`itemsRendered`,groupIndices:`groupIndices`}},H.memo(function(e){let t=Z0(`useWindowScroll`),n=Z0(`customScrollParent`),r=Q0(`fixedHeaderHeight`),i=Q0(`fixedFooterHeight`),a=Z0(`fixedHeaderContent`),o=Z0(`fixedFooterContent`),s=Z0(`context`),c=c1(H.useMemo(()=>O$(r,e=>z1(e,`height`)),[r]),!0,Z0(`skipAnimationFrameInResizeObserver`)),l=c1(H.useMemo(()=>O$(i,e=>z1(e,`height`)),[i]),!0,Z0(`skipAnimationFrameInResizeObserver`)),u=n||t?Vze:Bze,d=n||t?Rze:Lze,f=Z0(`TableComponent`),p=Z0(`TableHeadComponent`),m=Z0(`TableFooterComponent`),h=a?(0,U.jsx)(p,{ref:c,style:{position:`sticky`,top:0,zIndex:2},...V0(p,s),children:a()},`TableHead`):null,g=o?(0,U.jsx)(m,{ref:l,style:{bottom:0,position:`sticky`,zIndex:1},...V0(m,s),children:o()},`TableFoot`):null;return(0,U.jsx)(u,{...e,...V0(u,s),children:(0,U.jsx)(d,{children:(0,U.jsxs)(f,{style:{borderSpacing:0,overflowAnchor:`none`},...V0(f,s),children:[h,(0,U.jsx)(Ize,{},`TableBody`),g]})})})})),Bze=U0({useEmitter:X0,useEmitterValue:Z0,usePublisher:Q0}),Vze=W0({useEmitter:X0,useEmitterValue:Z0,usePublisher:Q0}),$0={bottom:0,itemHeight:0,items:[],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},Hze={bottom:0,itemHeight:0,items:[{index:0}],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},{ceil:e2,floor:t2,max:n2,min:r2,round:i2}=Math;function a2(e,t,n){return Array.from({length:t-e+1}).map((t,r)=>({data:n===null?null:n[r+e],index:r+e}))}function Uze(e){return{...Hze,items:e}}function o2(e,t){return e!==void 0&&e.width===t.width&&e.height===t.height}function Wze(e,t){return e!==void 0&&e.column===t.column&&e.row===t.row}var Gze=$$(([{increaseViewportBy:e,listBoundary:t,overscan:n,visibleRange:r},{footerHeight:i,headerHeight:a,scrollBy:o,scrollContainerState:s,scrollTo:c,scrollTop:l,smoothScrollTargetReached:u,viewportHeight:d},f,p,{didMount:m,propsReady:h},{customScrollParent:g,useWindowScroll:_,windowScrollContainerState:v,windowScrollTo:y,windowViewportRect:b},x])=>{let S=Y$(0),C=Y$(0),w=Y$($0),T=Y$({height:0,width:0}),E=Y$({height:0,width:0}),D=Z$(),O=Z$(),k=Y$(0),A=Y$(null),j=Y$({column:0,row:0}),M=Z$(),N=Z$(),P=Y$(!1),F=Y$(0),I=Y$(!0),L=Y$(!1),R=Y$(!1);N$($(m,J$(F),H$(([e,t])=>!e0(t))),()=>{P$(I,!1)}),N$($(e1(m,I,E,T,F,L),H$(([e,t,n,r,,i])=>e&&!t&&n.height!==0&&r.height!==0&&!i)),([,,,,e])=>{if(e===void 0){P$(I,!0);return}P$(L,!0),Q1(1,()=>{P$(D,e)}),R$($(l),()=>{P$(t,[0,0]),P$(I,!0)})}),L$($(N,H$(e=>e!=null&&e.scrollTop>0),W$(0)),C),N$($(m,J$(N),H$(([,e])=>e!=null)),([,e])=>{e&&(P$(T,e.viewport),P$(E,e.item),P$(j,e.gap),e.scrollTop>0&&(P$(P,!0),R$($(l,K$(1)),e=>{P$(P,!1)}),P$(c,{top:e.scrollTop})))}),L$($(T,U$(({height:e})=>e)),d),L$($(e1(t1(T,o2),t1(E,o2),t1(j,(e,t)=>e!==void 0&&e.column===t.column&&e.row===t.row),t1(l)),U$(([e,t,n,r])=>({gap:n,item:t,scrollTop:r,viewport:e}))),M),L$($(e1(t1(S),r,t1(j,Wze),t1(E,o2),t1(T,o2),t1(A),t1(C),t1(P),t1(I),t1(F)),H$(([,,,,,,,e])=>!e),U$(([e,[t,n],r,i,a,o,s,,c,l])=>{let{column:u,row:d}=r,{height:f,width:p}=i,{width:m}=a;if(s===0&&(e===0||m===0))return $0;if(p===0){let t=$1(l,e);return Uze(a2(t,t+Math.max(s-1,0),o))}let h=s2(m,p,u),g,_;c?t===0&&n===0&&s>0?(g=0,_=s-1):(g=h*t2((t+d)/(f+d)),_=h*e2((n+d)/(f+d))-1,_=r2(e-1,n2(_,h-1)),g=r2(_,n2(0,g))):(g=0,_=-1);let v=a2(g,_,o),{bottom:y,top:b}=c2(a,r,i,v),x=e2(e/h);return{bottom:y,itemHeight:f,items:v,itemWidth:p,offsetBottom:x*f+(x-1)*d-y,offsetTop:b,top:b}})),w),L$($(A,H$(e=>e!==null),U$(e=>e.length)),S),L$($(e1(T,E,w,j),H$(([e,t,{items:n}])=>n.length>0&&t.height!==0&&e.height!==0),U$(([e,t,{items:n},r])=>{let{bottom:i,top:a}=c2(e,r,t,n);return[a,i]}),V$(F1)),t);let z=Y$(!1);L$($(l,J$(z),U$(([e,t])=>t||e!==0)),z);let ee=Q$($(e1(w,S),H$(([{items:e}])=>e.length>0),J$(z),H$(([[e,t],n])=>{let r=e.items[e.items.length-1].index===t-1;return(n||e.bottom>0&&e.itemHeight>0&&e.offsetBottom===0&&e.items.length===t)&&r}),U$(([[,e]])=>e-1),V$())),te=Q$($(t1(w),H$(({items:e})=>e.length>0&&e[0].index===0),W$(0),V$())),ne=Q$($(t1(w),J$(P),H$(([{items:e},t])=>e.length>0&&!t),U$(([{items:e}])=>({endIndex:e[e.length-1].index,startIndex:e[0].index})),V$(P1),q$(0)));L$(ne,p.scrollSeekRangeChanged),L$($(D,J$(T,E,S,j),U$(([e,t,n,r,i])=>{let a=X1(e),{align:o,behavior:s,offset:c}=a,l=a.index;l===`LAST`&&(l=r-1),l=n2(0,l,r2(r-1,l));let u=l2(t,i,n,l);return o===`end`?u=i2(u-t.height+n.height):o===`center`&&(u=i2(u-t.height/2+n.height/2)),c!==void 0&&c!==0&&(u+=c),{behavior:s,top:u}})),c);let re=X$($(w,U$(e=>e.offsetBottom+e.bottom)),0);return L$($(b,U$(e=>({height:e.visibleHeight,width:e.visibleWidth}))),T),{customScrollParent:g,data:A,deviation:k,footerHeight:i,gap:j,headerHeight:a,increaseViewportBy:e,initialItemCount:C,itemDimensions:E,overscan:n,restoreStateFrom:N,scrollBy:o,scrollContainerState:s,scrollHeight:O,scrollTo:c,scrollToIndex:D,scrollTop:l,smoothScrollTargetReached:u,totalCount:S,useWindowScroll:_,viewportDimensions:T,windowScrollContainerState:v,windowScrollTo:y,windowViewportRect:b,...p,gridState:w,horizontalDirection:R,initialTopMostItemIndex:F,totalListHeight:re,...f,endReached:ee,propsReady:h,rangeChanged:ne,startReached:te,stateChanged:M,stateRestoreInProgress:P,...x}},M$(d0,p1,a0,S0,Y1,C0,i1));function s2(e,t,n){return n2(1,t2((e+n)/(t2(t)+n)))}function c2(e,t,n,r){let{height:i}=n;if(i===void 0||r.length===0)return{bottom:0,top:0};let a=l2(e,t,n,r[0].index);return{bottom:l2(e,t,n,r[r.length-1].index)+i,top:a}}function l2(e,t,n,r){let i=t2(r/s2(e.width,n.width,t.column)),a=i*n.height+n2(0,i-1)*t.row;return a>0?a+t.row:a}var Kze=$$(([e,t])=>({...e,...t}),M$(Gze,$$(()=>{let e=Y$(e=>`Item ${e}`),t=Y$({}),n=Y$(null),r=Y$(`virtuoso-grid-item`),i=Y$(`virtuoso-grid-list`),a=Y$(I0),o=Y$(`div`),s=Y$(A$),c=(e,n=null)=>X$($(t,U$(t=>t[e]),V$()),n),l=Y$(!1),u=Y$(!1);return L$(t1(u),l),{components:t,computeItemKey:a,context:n,FooterComponent:c(`Footer`),HeaderComponent:c(`Header`),headerFooterTag:o,itemClassName:r,ItemComponent:c(`Item`,`div`),itemContent:e,listClassName:i,ListComponent:c(`List`,`div`),readyStateChanged:l,reportReadyState:u,ScrollerComponent:c(`Scroller`,`div`),scrollerRef:s,ScrollSeekPlaceholder:c(`ScrollSeekPlaceholder`,`div`)}}))),qze=H.memo(function(){let e=d2(`gridState`),t=d2(`listClassName`),n=d2(`itemClassName`),r=d2(`itemContent`),i=d2(`computeItemKey`),a=d2(`isSeeking`),o=f2(`scrollHeight`),s=d2(`ItemComponent`),c=d2(`ListComponent`),l=d2(`ScrollSeekPlaceholder`),u=d2(`context`),d=f2(`itemDimensions`),f=f2(`gap`),p=d2(`log`),m=d2(`stateRestoreInProgress`),h=f2(`reportReadyState`),g=c1(H.useMemo(()=>e=>{let t=e.parentElement.parentElement.scrollHeight;o(t);let n=e.firstChild;if(n!==null){let{height:e,width:t}=n.getBoundingClientRect();d({height:e,width:t})}f({column:p2(`column-gap`,getComputedStyle(e).columnGap,p),row:p2(`row-gap`,getComputedStyle(e).rowGap,p)})},[o,d,f,p]),!0,!1);return N0(()=>{e.itemHeight>0&&e.itemWidth>0&&h(!0)},[e]),m?null:(0,U.jsx)(c,{className:t,ref:g,...V0(c,u),"data-testid":`virtuoso-item-list`,style:{paddingBottom:e.offsetBottom,paddingTop:e.offsetTop},children:e.items.map(t=>{let o=i(t.index,t.data,u);return a?(0,U.jsx)(l,{...V0(l,u),height:e.itemHeight,index:t.index,width:e.itemWidth},o):(0,H.createElement)(s,{...V0(s,u),className:n,"data-index":t.index,key:o},r(t.index,t.data,u))})})}),Jze=H.memo(function(){let e=d2(`HeaderComponent`),t=f2(`headerHeight`),n=d2(`headerFooterTag`),r=c1(H.useMemo(()=>e=>{t(z1(e,`height`))},[t]),!0,!1),i=d2(`context`);return e==null?null:(0,U.jsx)(n,{ref:r,children:(0,U.jsx)(e,{...V0(e,i)})})}),Yze=H.memo(function(){let e=d2(`FooterComponent`),t=f2(`footerHeight`),n=d2(`headerFooterTag`),r=c1(H.useMemo(()=>e=>{t(z1(e,`height`))},[t]),!0,!1),i=d2(`context`);return e==null?null:(0,U.jsx)(n,{ref:r,children:(0,U.jsx)(e,{...V0(e,i)})})}),Xze=({children:e})=>{let t=H.useContext(k0),n=f2(`itemDimensions`),r=f2(`viewportDimensions`),i=c1(H.useMemo(()=>e=>{r(e.getBoundingClientRect())},[r]),!0,!1);return H.useEffect(()=>{t&&(r({height:t.viewportHeight,width:t.viewportWidth}),n({height:t.itemHeight,width:t.itemWidth}))},[t,r,n]),(0,U.jsx)(`div`,{ref:i,style:z0(!1),children:e})},Zze=({children:e})=>{let t=H.useContext(k0),n=f2(`windowViewportRect`),r=f2(`itemDimensions`),i=d2(`customScrollParent`),a=d2(`useWindowScroll`),o=f1(n,i,!1);return H.useEffect(()=>{t&&(r({height:t.itemHeight,width:t.itemWidth}),n({listHeight:0,offsetTop:0,visibleHeight:t.viewportHeight,visibleWidth:t.viewportWidth}))},[t,n,r]),(0,U.jsx)(`div`,{ref:o,style:B0(!1,a),children:e})},{Component:Qze,useEmitter:u2,useEmitterValue:d2,usePublisher:f2}=D0(Kze,{optional:{context:`context`,totalCount:`totalCount`,overscan:`overscan`,itemContent:`itemContent`,components:`components`,computeItemKey:`computeItemKey`,data:`data`,initialItemCount:`initialItemCount`,scrollSeekConfiguration:`scrollSeekConfiguration`,headerFooterTag:`headerFooterTag`,listClassName:`listClassName`,itemClassName:`itemClassName`,useWindowScroll:`useWindowScroll`,customScrollParent:`customScrollParent`,scrollerRef:`scrollerRef`,logLevel:`logLevel`,restoreStateFrom:`restoreStateFrom`,initialTopMostItemIndex:`initialTopMostItemIndex`,increaseViewportBy:`increaseViewportBy`},methods:{scrollTo:`scrollTo`,scrollBy:`scrollBy`,scrollToIndex:`scrollToIndex`},events:{isScrolling:`isScrolling`,endReached:`endReached`,startReached:`startReached`,rangeChanged:`rangeChanged`,atBottomStateChange:`atBottomStateChange`,atTopStateChange:`atTopStateChange`,stateChanged:`stateChanged`,readyStateChanged:`readyStateChanged`}},H.memo(function({...e}){let t=d2(`useWindowScroll`),n=d2(`customScrollParent`),r=n||t?eBe:$ze,i=n||t?Zze:Xze,a=d2(`context`);return(0,U.jsx)(r,{...e,...V0(r,a),children:(0,U.jsxs)(i,{children:[(0,U.jsx)(Jze,{}),(0,U.jsx)(qze,{}),(0,U.jsx)(Yze,{})]})})})),$ze=U0({useEmitter:u2,useEmitterValue:d2,usePublisher:f2}),eBe=W0({useEmitter:u2,useEmitterValue:d2,usePublisher:f2});function p2(e,t,n){return t!==`normal`&&t?.endsWith(`px`)!==!0&&n(`${e} was not resolved to pixel value correctly`,t,r1.WARN),t===`normal`?0:parseInt(t??`0`,10)}function tBe(e){return e.type!==`wheel`||(e.deltaY??0)===0?!1:(e.deltaMode??0)!==0||Math.abs(e.deltaY??0)>=80}function nBe(e,t){return e.type!==`wheel`||(e.deltaY??0)===0?0:e.deltaMode===1?(e.deltaY??0)*16:e.deltaMode===2?(e.deltaY??0)*t:e.deltaY??0}function rBe(e){if(e.type===`wheel`)return(e.deltaY??0)<0?`away`:(e.deltaY??0)>0?`toward`:void 0;if(e.type===`keydown`){if([`ArrowUp`,`PageUp`,`Home`].includes(e.key??``)||e.key===` `&&e.shiftKey)return`away`;if([`ArrowDown`,`PageDown`,`End`,` `].includes(e.key??``))return`toward`}}function m2(e){if(!(!e.hasUserScrollIntent||e.previousScrollTop===void 0)){if(e.scrollTop<e.previousScrollTop-1)return`away`;if(e.scrollTop>e.previousScrollTop+1)return`toward`}}function iBe({direction:e,oppositeCount:t,previousScrollTop:n,scrollTop:r}){let i=m2({hasUserScrollIntent:!0,previousScrollTop:n,scrollTop:r});if(!i)return{direction:e,oppositeCount:t,clamp:!1};if(!e||i===e)return{direction:i,oppositeCount:0,clamp:!1};let a=t+1;return a<2?{direction:e,oppositeCount:a,clamp:!0}:{direction:i,oppositeCount:0,clamp:!1}}function aBe(e,t){if(t!==void 0&&e!==void 0&&t!==e)return t>e?`away`:`toward`}function oBe(e){if(e.button===1)return`middle`;if(e.button!==0||!e.targetIsScroller||e.clientX===void 0||e.scrollerRight===void 0)return;let t=Math.max(12,e.verticalScrollbarWidth??0);return e.clientX>=e.scrollerRight-t?`scrollbar`:void 0}function h2(e,t){return e&&!t}function sBe(e,t){let n=t.length-e.length;if(n<=0)return 0;for(let r=0;r<e.length;r+=1)if(e[r]!==t[r+n])return 0;return n}function cBe({items:e,itemKeys:t,firstItemIndex:n,scrollTop:r,viewportHeight:i}){let a=r+i;return e.filter(e=>e.offset+e.size>r&&e.offset<a).sort((e,t)=>e.offset-t.offset).flatMap(e=>{let i=e.index-n,a=t[i];return a===void 0?[]:[{key:a,dataIndex:i,offset:e.offset-r}]})}function lBe(e){return[...e].sort((e,t)=>Math.abs(e.offset)-Math.abs(t.offset))[0]}function uBe({anchors:e,previousKeys:t,nextKeys:n}){if(!e.length||!n.length)return;let r=[...e].sort((e,t)=>Math.abs(e.offset)-Math.abs(t.offset));for(let e of r){let t=n.indexOf(e.key);if(t>=0)return g2(t,e.offset)}let i=r[0];if(t?.length){for(let e=i.dataIndex;e<t.length;e+=1){let r=n.indexOf(t[e]);if(r>=0)return g2(r,i.offset)}for(let e=i.dataIndex-1;e>=0;--e){let r=n.indexOf(t[e]);if(r>=0)return g2(r,i.offset)}}return g2(Math.min(Math.max(i.dataIndex,0),n.length-1),i.offset)}function g2(e,t){return{index:e,align:`start`,behavior:`auto`,offset:-t}}var dBe=24,fBe=700,pBe=120,mBe=500,hBe=250,gBe=100,_Be=1500,vBe=3,_2=1e6;function yBe({itemCount:e,itemKeys:t,isPrepending:n=!1,resetKey:r,contentKey:i,atBottomThreshold:a=dBe,onAtTop:o,onNearTop:s,atTopThreshold:c=0,nearTopThreshold:l=0,onUserScrollIntent:u,onScrollbarDragChange:d,onVisibleAnchorChange:f}){let p=(0,H.useRef)(null),m=(0,H.useRef)(e),h=(0,H.useRef)(n);h.current=n;let g=(0,H.useRef)(!0),_=(0,H.useRef)(void 0),v=(0,H.useRef)(void 0),y=(0,H.useRef)(void 0),b=(0,H.useRef)(void 0),x=(0,H.useRef)(void 0),S=(0,H.useRef)(!1),C=(0,H.useRef)(void 0),w=(0,H.useRef)(!1),T=(0,H.useRef)(!1),E=(0,H.useRef)(!1),D=(0,H.useRef)(void 0),O=(0,H.useRef)(()=>{}),k=(0,H.useRef)(!1),A=(0,H.useRef)(!1),j=(0,H.useRef)(!1),M=(0,H.useRef)(void 0),N=(0,H.useRef)(void 0),P=(0,H.useRef)(void 0),F=(0,H.useRef)(void 0),I=(0,H.useRef)(void 0),L=(0,H.useRef)(void 0),R=(0,H.useRef)(void 0),z=(0,H.useRef)(0),ee=(0,H.useRef)(void 0),te=(0,H.useRef)(void 0),ne=(0,H.useRef)(void 0),re=(0,H.useRef)(void 0),ie=(0,H.useRef)([]),B=(0,H.useRef)([]),ae=(0,H.useRef)(t),oe=(0,H.useRef)(void 0),se=(0,H.useRef)(void 0),ce=(0,H.useRef)(void 0),le=(0,H.useRef)(void 0),ue=(0,H.useRef)(void 0),de=(0,H.useRef)(void 0),fe=(0,H.useRef)(t),pe=(0,H.useRef)(_2),me=(0,H.useRef)(_2),he=(0,H.useRef)({resetKey:r,itemKeys:t}),ge=(0,H.useRef)(!1),_e=(0,H.useRef)(!1),ve=(0,H.useRef)(!1),[ye,be]=(0,H.useState)(!0),[xe,Se]=(0,H.useState)(!1),[Ce,we]=(0,H.useState)(null),Te=he.current;if(!Object.is(Te.resetKey,r))pe.current=_2,ge.current=!1,_e.current=!1;else{let e=sBe(Te.itemKeys,t);ge.current=e>0,e>0&&(pe.current-=e,_e.current=!0)}he.current={resetKey:r,itemKeys:t};let V=pe.current;(0,H.useLayoutEffect)(()=>{m.current=e},[e]);let Ee=(0,H.useCallback)(()=>{oe.current=void 0,se.current=void 0,ce.current!==void 0&&window.clearTimeout(ce.current),le.current!==void 0&&window.clearTimeout(le.current),ce.current=void 0,le.current=void 0},[]),De=(0,H.useCallback)(()=>{g.current||se.current||!B.current.length||(se.current={anchors:B.current,itemKeys:ae.current})},[]),Oe=(0,H.useCallback)((e,t=!0)=>{let n=g.current;g.current=e,e&&(Ee(),w.current=!1,T.current=!1,E.current=!1,D.current=void 0,k.current=!1,!n&&t&&f?.(void 0),j.current=!1,v.current!==void 0&&cancelAnimationFrame(v.current),v.current=void 0),be(e)},[Ee,f]),ke=(0,H.useCallback)(e=>{ve.current!==e&&(ve.current=e,Se(e))},[]),Ae=(0,H.useCallback)(e=>{let t=e<=c;return ke(t),t},[c,ke]),je=(0,H.useCallback)(()=>{if(!Ce||g.current)return;let e=fe.current,t=oe.current;if(t){let n=e.indexOf(t.key);if(n>=0){let r={...t,dataIndex:n};return B.current=[r],ae.current=e,f?.(r),r}}let n=bBe(Ce,e);B.current=n.length?n:cBe({items:ie.current,itemKeys:fe.current,firstItemIndex:me.current,scrollTop:y2(Ce),viewportHeight:b2(Ce)}),ae.current=fe.current;let r=lBe(B.current);return f?.(r),r},[f,Ce]),Me=(0,H.useCallback)(()=>{ue.current=B.current,de.current=ae.current},[]),Ne=(0,H.useCallback)(e=>{ie.current=e},[]),Pe=(0,H.useCallback)(e=>{!(e instanceof WheelEvent)||E.current||g.current||e.deltaY===0||B.current.length===0||(B.current=B.current.map(t=>({...t,offset:t.offset-e.deltaY})),(h.current||ue.current!==void 0)&&(ue.current=B.current,de.current=ae.current))},[]),Fe=(0,H.useCallback)(()=>{M.current!==void 0&&window.clearTimeout(M.current),M.current=window.setTimeout(()=>{S.current=!1,C.current=void 0,w.current=!1,T.current=!1,E.current=!1;let e=D.current;if(D.current=void 0,M.current=void 0,k.current&&(k.current=!1,v.current!==void 0&&cancelAnimationFrame(v.current),v.current=void 0,Ee(),ue.current=void 0,de.current=void 0),e){A.current=!1;let t=je();t&&(oe.current=t),O.current(e)}},fBe)},[je,Ee]),Ie=(0,H.useCallback)((e=!1)=>{if(g.current||F.current!==void 0)return;if(S.current&&w.current){k.current=!0;return}if(A.current&&!T.current||_e.current&&!e)return;let t=fe.current,n=oe.current,r=n?t.indexOf(n.key):-1,i=se.current,a=ue.current,o=r>=0?[{...n,dataIndex:r}]:i?.anchors??a??B.current,s=uBe({anchors:o,previousKeys:r>=0?t:i?.itemKeys??(a?de.current:ae.current)??[],nextKeys:t});if(!s)return;let c=()=>{if(g.current||F.current!==void 0)return!1;if(S.current&&w.current)return k.current=!0,!1;if(A.current&&!T.current)return!1;let e=!!(Ce&&x2(Ce,s,o,t));return!e&&!_e.current&&p.current?.scrollToIndex(s),e},l=c();_e.current&&!l||(v.current!==void 0&&cancelAnimationFrame(v.current),v.current=requestAnimationFrame(()=>{c(),v.current=requestAnimationFrame(()=>{v.current=void 0,c(),je()})}))},[je,Ce]),Le=(0,H.useCallback)(()=>{se.current&&(ce.current!==void 0&&window.clearTimeout(ce.current),le.current!==void 0&&window.clearTimeout(le.current),ce.current=window.setTimeout(()=>{ce.current=void 0,Ie(!0),le.current=window.setTimeout(()=>{le.current=void 0,se.current=void 0,je()},gBe)},hBe))},[je,Ie]),Re=(0,H.useCallback)(()=>{g.current||(je(),Me(),A.current=!1)},[je,Me]),ze=(0,H.useCallback)(e=>({startIndex:Math.max(0,e.startIndex-pe.current),endIndex:Math.max(0,e.endIndex-pe.current)}),[]),Be=(0,H.useCallback)(()=>{_.current!==void 0&&(cancelAnimationFrame(_.current),_.current=void 0)},[]),Ve=(0,H.useCallback)(e=>{let t=fe.current,n=t.indexOf(e.key);if(n<0)return!1;Ee(),Oe(!1),A.current=!1,oe.current={...e,dataIndex:n},B.current=[{...e,dataIndex:n}],ae.current=t,Me(),Be();let r={index:n,align:`start`,behavior:`auto`,offset:-e.offset},i=()=>{g.current||Ce&&x2(Ce,r,B.current,t)||p.current?.scrollToIndex(r)};return p.current?.scrollToIndex(r),v.current!==void 0&&cancelAnimationFrame(v.current),v.current=requestAnimationFrame(()=>{i(),v.current=requestAnimationFrame(()=>{v.current=void 0,i(),je()})}),!0},[je,Ee,Be,Ce,Oe,Me]),He=(0,H.useCallback)(()=>{!s||!Ce||x.current===void 0&&(x.current=requestAnimationFrame(()=>{x.current=void 0,!(!s||!Ce)&&y2(Ce)<=l&&(je(),Me(),s())}))},[je,l,s,Ce,Me]),Ue=(0,H.useCallback)((e=`auto`)=>{Be(),_.current=requestAnimationFrame(()=>{_.current=void 0,!(!g.current||m.current<1)&&(p.current?.autoscrollToBottom(),Ce&&C2(Ce),requestAnimationFrame(()=>{g.current&&Ce&&C2(Ce)}))})},[Be,Ce]),We=(0,H.useCallback)(()=>{!o||!Ce||b.current===void 0&&(b.current=requestAnimationFrame(()=>{b.current=void 0,!(!o||!Ce)&&Ae(y2(Ce))&&(je(),Me(),o())}))},[je,o,Ce,Me,Ae]);O.current=e=>{e===`at-top`?We():He()};let Ge=(0,H.useCallback)(()=>Ce?Ae(y2(Ce)):!1,[Ce,Ae]),Ke=(0,H.useCallback)((e=`auto`)=>{Oe(!0),Ue(e)},[Ue,Oe]),qe=(0,H.useCallback)((e,t=`center`,n=`auto`,r={})=>{Ee(),Oe(!1),A.current=!0,Be(),requestAnimationFrame(()=>{if(n!==`fast-smooth`){p.current?.scrollToIndex({index:e,align:t,behavior:n});return}if(r.stagingAlign){p.current?.scrollToIndex({index:e,align:r.stagingAlign,behavior:`auto`}),requestAnimationFrame(()=>{requestAnimationFrame(()=>{p.current?.scrollToIndex({index:e,align:t,behavior:`smooth`})})});return}let i=r.fromIndex,a=Math.abs(typeof i==`number`?i-e:0),o=r.stagingDistance??vBe;if(typeof i!=`number`||a<=o){p.current?.scrollToIndex({index:e,align:t,behavior:`smooth`});return}let s=m.current-1,c=e<i?Math.min(s,e+o):Math.max(0,e-o);p.current?.scrollToIndex({index:c,align:t,behavior:`auto`}),requestAnimationFrame(()=>{p.current?.scrollToIndex({index:e,align:t,behavior:`smooth`})})})},[Ee,Be,Oe]),Je=(0,H.useCallback)((e,t)=>{Ee(),S.current=!0,w.current=e?.type===`touchmove`,T.current=e?.type===`wheel`,E.current=tBe(w2(e));let n=t??rBe(w2(e));u?.(e,n),C.current=n,A.current=!0,n===`away`?(j.current=!1,Be(),Oe(!1),je()):n===`toward`&&(j.current=!0,Ce&&v2(Ce,1)&&Oe(!0)),n!==`away`&&Ce&&!v2(Ce,a)&&(Oe(!1),je()),Pe(e),v.current!==void 0&&cancelAnimationFrame(v.current),v.current=void 0;let r=Ce?y2(Ce):void 0;r!==void 0&&Ae(r)?E.current?D.current=`at-top`:We():xBe(e)&&r!==void 0&&r<=l&&(E.current?D.current=`near-top`:He()),Fe()},[a,je,Ee,Be,l,u,Pe,We,He,Fe,Ce,Oe,Ae]),Ye=(0,H.useCallback)(e=>{!(e instanceof WheelEvent)||!E.current||!Ce||(e.preventDefault(),S2(Ce,y2(Ce)+nBe(w2(e),b2(Ce))),je(),(h.current||ue.current!==void 0)&&Me())},[je,Ce,Me]),Xe=(0,H.useCallback)(e=>{let t=F.current;!t||e&&t!==e||(F.current=void 0,te.current!==void 0&&window.clearTimeout(te.current),te.current=void 0,t===`scrollbar`&&(L.current=void 0,R.current=void 0,z.current=0,ee.current=void 0,je(),Me(),d?.(!1)),Ce&&v2(Ce,1)&&C.current!==`away`&&Oe(!0))},[je,d,Ce,Oe,Me]),Ze=(0,H.useCallback)(()=>{if(!Ce)return;let e=y2(Ce),t=re.current,n=F.current,r=ee.current;if(n===`scrollbar`){let t=iBe({direction:R.current,oppositeCount:z.current,previousScrollTop:r,scrollTop:e});if(R.current=t.direction,z.current=t.oppositeCount,t.clamp&&r!==void 0){S2(Ce,r);return}ee.current=e}re.current=e,S.current&&Fe();let i=S.current||n!==void 0,o=m2({hasUserScrollIntent:i,previousScrollTop:t,scrollTop:e});o&&n&&(C.current=o,u?.(void 0,o)),n===`middle`&&(te.current!==void 0&&window.clearTimeout(te.current),te.current=window.setTimeout(()=>Xe(`middle`),_Be));let s=o===`away`;s?j.current=!1:o===`toward`&&C.current===`toward`&&(j.current=!0);let c=i||s||!g.current;if(A.current&&h.current&&ue.current!==void 0&&(je(),Me()),A.current&&(N.current!==void 0&&window.clearTimeout(N.current),P.current!==void 0&&window.clearTimeout(P.current),N.current=window.setTimeout(()=>{je(),h.current&&ue.current!==void 0&&Me(),A.current=!1,N.current=void 0},pBe),P.current=window.setTimeout(()=>{P.current=void 0,!(g.current||F.current!==void 0)&&(je(),h.current&&ue.current!==void 0&&Me())},mBe)),Ae(e)?i&&C.current===`away`&&(E.current?D.current=`at-top`:We()):c&&e<=l&&(E.current?D.current=`near-top`:He()),v2(Ce,a)){h2(j.current,s)&&Oe(!0);return}i&&Oe(!1)},[a,je,Xe,l,u,We,He,Fe,Ce,Oe,Me,Ae]);(0,H.useLayoutEffect)(()=>{if(!Ce||typeof MutationObserver>`u`)return;let e=Ce instanceof Window?document.scrollingElement:Ce;if(!e)return;let t=()=>{if(g.current){C2(Ce);return}se.current&&Le(),Ie(!0)},n=typeof ResizeObserver>`u`?void 0:new ResizeObserver(n=>{(g.current||n.some(t=>t.target!==e))&&t()}),r=()=>{let t=e.querySelector(`[data-testid="virtuoso-item-list"]`);t&&n?.observe(t)},i=new MutationObserver(()=>{r(),t()});return n?.observe(e),r(),i.observe(e,{subtree:!0,childList:!0,characterData:!0,attributes:!0,attributeFilter:[`style`,`data-index`,`data-item-index`]}),()=>{i.disconnect(),n?.disconnect()}},[Ie,Le,Ce]),(0,H.useLayoutEffect)(()=>{if(!Ce)return;let e=Ce,t=e=>{let t=e instanceof KeyboardEvent?e.key:``;t===`Escape`&&Xe(`middle`),[`ArrowUp`,`ArrowDown`,`PageUp`,`PageDown`,`Home`,`End`,` `].includes(t)&&(Xe(`middle`),Je(e))},n=t=>{if(!(t instanceof PointerEvent))return;let n=SBe(t,e);if(!n){t.button===0&&Xe(`middle`);return}if(n===`middle`&&F.current===`middle`){Xe(`middle`);return}if(Ee(),F.current=n,j.current=!1,Be(),Oe(!1),je(),n===`scrollbar`){L.current=t.clientY,R.current=void 0,z.current=0;let n=y2(e);ee.current=n,re.current=n,d?.(!0)}Je(t)},r=t=>{if(F.current!==`scrollbar`||!(t instanceof PointerEvent))return;let n=L.current;if(L.current=t.clientY,n===void 0)return;let r=t.clientY<n-.5?`away`:t.clientY>n+.5?`toward`:void 0;!r||r===R.current||(R.current=r,z.current=0,ee.current=y2(e))},i=t=>{if(F.current!==`scrollbar`)return;let n=t.type===`pointerup`?CBe(t,e):void 0;if(!n){Xe(`scrollbar`);return}R.current=n===`top`?`away`:`toward`,z.current=0,ee.current=y2(e),n===`top`?S2(e,0):C2(e),I.current!==void 0&&cancelAnimationFrame(I.current),I.current=requestAnimationFrame(()=>{I.current=void 0,Xe(`scrollbar`)})},a=e=>{ne.current=T2(e)},o=e=>{Xe(`middle`);let t=T2(e),n=ne.current;ne.current=t,Je(e,aBe(n,t))},s=e=>{Xe(`middle`),Je(e),Ye(e)};return e.addEventListener(`wheel`,s,{passive:!1}),e.addEventListener(`touchstart`,a,{passive:!0}),e.addEventListener(`touchmove`,o,{passive:!0}),e.addEventListener(`pointerdown`,n,{passive:!0}),e.addEventListener(`keydown`,t),e.addEventListener(`scroll`,Ze,{passive:!0}),window.addEventListener(`pointermove`,r,{passive:!0}),window.addEventListener(`pointerup`,i,{passive:!0}),window.addEventListener(`pointercancel`,i,{passive:!0}),()=>{e.removeEventListener(`wheel`,s),e.removeEventListener(`touchstart`,a),e.removeEventListener(`touchmove`,o),e.removeEventListener(`pointerdown`,n),e.removeEventListener(`keydown`,t),e.removeEventListener(`scroll`,Ze),window.removeEventListener(`pointermove`,r),window.removeEventListener(`pointerup`,i),window.removeEventListener(`pointercancel`,i)}},[Ye,je,Ee,Xe,Be,Je,d,Ce,Oe,Ze]),(0,H.useLayoutEffect)(()=>{Ee(),re.current=void 0,N.current!==void 0&&window.clearTimeout(N.current),P.current!==void 0&&window.clearTimeout(P.current),N.current=void 0,P.current=void 0,w.current=!1,T.current=!1,E.current=!1,D.current=void 0,k.current=!1,A.current=!1,B.current=[],ae.current=[],ue.current=void 0,de.current=void 0,ke(!1),Oe(!0,!1),Ue(`auto`)},[Ee,r,Ue,ke,Oe]);let Qe=(0,H.useCallback)(()=>{y.current!==void 0&&cancelAnimationFrame(y.current),y.current=requestAnimationFrame(()=>{y.current=requestAnimationFrame(()=>{y.current=void 0,_e.current=!1,Ie()})})},[Ie]);return(0,H.useLayoutEffect)(()=>{let e=ge.current;return ge.current=!1,fe.current=t,me.current=pe.current,!g.current&&ue.current!==void 0&&(A.current=!1),g.current?Ue(`auto`):e?Qe():Ie(),!g.current&&se.current&&Le(),ue.current=void 0,de.current=void 0,()=>{g.current||De(),!g.current&&ue.current===void 0&&Me()}},[i,e,t,Ie,Le,Qe,Ue,De,Me]),(0,H.useEffect)(()=>()=>{Ee(),Be(),v.current!==void 0&&cancelAnimationFrame(v.current),y.current!==void 0&&cancelAnimationFrame(y.current),b.current!==void 0&&cancelAnimationFrame(b.current),x.current!==void 0&&cancelAnimationFrame(x.current),M.current!==void 0&&window.clearTimeout(M.current),N.current!==void 0&&window.clearTimeout(N.current),P.current!==void 0&&window.clearTimeout(P.current),I.current!==void 0&&cancelAnimationFrame(I.current),te.current!==void 0&&window.clearTimeout(te.current)},[Ee,Be]),{virtuosoRef:p,firstItemIndex:V,itemsRendered:Ne,normalizeRange:ze,isSticky:ye,isAtTop:xe,isScrolledToTop:Ge,captureVisibleAnchor:je,prepareForPrepend:Re,restoreAnchor:Ve,stickToBottom:Ke,scrollToIndex:qe,scrollerRef:we,atBottomStateChange:(0,H.useCallback)(e=>{if(e){h2(j.current,!1)&&Oe(!0);return}S.current&&Oe(!1)},[Oe]),atBottomThreshold:a,followOutput:(0,H.useCallback)(()=>g.current?`auto`:!1,[]),totalListHeightChanged:(0,H.useCallback)(()=>{g.current?Ue(`auto`):_e.current?Qe():Ie()},[Ie,Qe,Ue])}}function v2(e,t){let n=e instanceof Window?document.scrollingElement:e;return!n||n.scrollHeight-n.scrollTop-n.clientHeight<=t}function y2(e){return(e instanceof Window?document.scrollingElement:e)?.scrollTop??0}function b2(e){return(e instanceof Window?document.scrollingElement:e)?.clientHeight??0}function bBe(e,t){let n=e instanceof Window?document:e,r=e instanceof Window?0:e.getBoundingClientRect().top,i=r+b2(e);return[...n.querySelectorAll(`[data-index][data-item-index]`)].flatMap(e=>{let n=Number(e.dataset.index),a=Number.isInteger(n)?t[n]:void 0;if(a===void 0)return[];let o=e.getBoundingClientRect();return o.bottom<=r||o.top>=i?[]:[{key:a,dataIndex:n,offset:o.top-r}]}).sort((e,t)=>e.offset-t.offset)}function x2(e,t,n,r){let i=n.find(e=>r.indexOf(e.key)===t.index);if(!i)return!1;let a=e instanceof Window?document:e,o=[...a.querySelectorAll(`[data-row-id]`)].find(e=>e.dataset.rowId===i.key)?.closest(`[data-index][data-item-index]`)??a.querySelector(`[data-index="${t.index}"][data-item-index]`);if(!o)return!1;let s=e instanceof Window?0:e.getBoundingClientRect().top,c=o.getBoundingClientRect().top-s-i.offset;return Math.abs(c)>.5&&S2(e,y2(e)+c),!0}function S2(e,t){let n=e instanceof Window?document.scrollingElement:e;n&&(n.scrollTop=t)}function C2(e){let t=e instanceof Window?document.scrollingElement:e;t&&(t.scrollTop=t.scrollHeight)}function xBe(e){return e instanceof WheelEvent?e.deltaY<0:e instanceof KeyboardEvent?[`ArrowUp`,`PageUp`,`Home`].includes(e.key)||e.key===` `&&e.shiftKey:e?.type===`touchmove`}function w2(e){return e instanceof WheelEvent?{type:`wheel`,deltaY:e.deltaY,deltaMode:e.deltaMode}:e instanceof KeyboardEvent?{type:`keydown`,key:e.key,shiftKey:e.shiftKey}:{type:e?.type}}function SBe(e,t){let n=t instanceof Window?document.scrollingElement:t,r=n?.getBoundingClientRect();return oBe({button:e.button,targetIsScroller:e.target===t,clientX:e.clientX,scrollerRight:r?.right,verticalScrollbarWidth:n?n.offsetWidth-n.clientWidth:void 0})}function CBe(e,t){if(!(e instanceof PointerEvent))return;let n=t instanceof Window?document.scrollingElement:t,r=n?.getBoundingClientRect();if(!n||!r)return;let i=Math.max(12,n.offsetWidth-n.clientWidth)*2;if(e.clientY<=r.top+i)return`top`;if(e.clientY>=r.bottom-i)return`bottom`}function T2(e){if(e instanceof TouchEvent)return e.touches[0]?.clientY}function wBe(e,t=`done`,n=!1){if(!e)return t===`running`?`running`:t===`error`?`failed`:`completed`;if(n)return t===`error`?`failed`:`completed`;let r=[e.localStatus,e.aggregateStatus];return r.some(jBe)?`cancelled`:e.hasError||e.hasErrorDescendant||r.some(ABe)?`failed`:e.isSettled===!1||e.isTreeActive||e.isLocalActive||e.hasActiveDescendant||r.some(OBe)||t===`running`&&r.every(kBe)?`running`:`completed`}function TBe(e,t,n){let r=k2(e)?e:void 0;return NBe(O2(r?.name)??O2(r?.subagentName)??MBe(t)??O2(n)??O2(t)??`Subagent`)}function E2(e){if(typeof e==`string`)return D2(e);if(k2(e)){for(let t of[`message`,`task`,`prompt`,`query`]){let n=D2(e[t]);if(n)return n}return E2(e.arguments)}}function EBe(e,t=180){let n=E2(e)?.replace(/\s+/g,` `).trim();if(!(!n||t<1))return n.length<=t?n:`${n.slice(0,Math.max(1,t-1)).trimEnd()}…`}function DBe(e){let t=Math.max(0,Math.floor(e/1e3));if(t<60)return`${t}s`;let n=Math.floor(t/3600),r=Math.floor(t%3600/60),i=t%60;return n>0?`${n}h ${r}m ${i}s`:`${r}m ${i}s`}function OBe(e){return[`queued`,`starting`,`running`,`streaming`,`waiting`,`blocked`,`retrying`,`compacting`,`pausing`,`paused`].includes(e)}function kBe(e){return e===`idle`||e===`unknown`}function ABe(e){return e===`error`}function jBe(e){return e===`cancelled`||e===`interrupted`||e===`disposed`}function MBe(e){let t=D2(e);if(t)return t===`pibo_agents_send_message`?void 0:t.replace(/^pibo_subagent_/,``)}function NBe(e){return e.replace(/^pibo_agents_send_message$/,`Agent`).replace(/^pibo_subagent_/,``).split(/[\s_-]+/).filter(Boolean).map(e=>`${e.charAt(0).toUpperCase()}${e.slice(1)}`).join(` `)||`Subagent`}function D2(e){return typeof e==`string`&&e.trim()?e.trim():void 0}function O2(e){return D2(e)}function k2(e){return!!e&&typeof e==`object`&&!Array.isArray(e)}function A2({title:e,summary:t,input:n,output:r,error:i,traceStatus:a=`done`,linkedPiboSessionId:o,startedAt:s,completedAt:c,durationMs:l,signals:u,onOpenSession:d}){let f=o?u?.sessions[o]:void 0,p=wBe(f,a,a===`error`||c!==void 0),m=(0,H.useMemo)(()=>{if(!(!o||!u))return Object.values(u.nodes).find(e=>e.childPiboSessionId===o||e.piboSessionId===o&&e.kind===`session`)},[o,u]),h=s??m?.startedAt??m?.createdAt,g=p===`running`?void 0:c??f?.updatedAt??m?.completedAt,[_,v]=(0,H.useState)(()=>Date.now()),[y,b]=(0,H.useState)(!1),x=TBe(n,e,t),S=EBe(n),C=FBe(h,g,p===`running`?void 0:l,_,p===`running`),w=n!==void 0||r!==void 0||!!i;return(0,H.useEffect)(()=>{if(p!==`running`)return;let e=window.setInterval(()=>v(Date.now()),1e3);return()=>window.clearInterval(e)},[p]),(0,U.jsxs)(`div`,{className:`min-w-0 overflow-hidden rounded-sm border border-[#f97316]/60 bg-[#1a140f] text-slate-200 shadow-sm`,"data-pibo-component":`AgentDelegationCard`,"data-delegation-status":p,children:[(0,U.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-start gap-3 border-b border-[#f97316]/25 bg-[#f97316]/8 px-3 py-2.5`,children:[(0,U.jsxs)(`span`,{className:`relative inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-full border border-[#f97316] bg-[#f97316]/15 text-[#f97316]`,children:[(0,U.jsx)(Sc,{size:16,"aria-hidden":`true`}),p===`running`?(0,U.jsx)(`span`,{className:`absolute -right-0.5 -top-0.5 h-2 w-2 animate-pulse rounded-full bg-[#0bda57]`,"aria-hidden":`true`}):null]}),(0,U.jsxs)(`div`,{className:`min-w-[12rem] flex-1`,children:[(0,U.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-center gap-2`,children:[(0,U.jsx)(`span`,{className:`text-[10px] font-bold uppercase tracking-wider text-[#f97316]`,children:`Agent Delegation`}),(0,U.jsxs)(`span`,{className:`inline-flex min-w-0 items-center gap-1 text-sm font-semibold text-slate-100`,children:[(0,U.jsx)(Rs,{size:14,className:`shrink-0 text-[#f97316]`,"aria-hidden":`true`}),(0,U.jsx)(`span`,{className:`truncate`,children:x})]}),(0,U.jsx)(PBe,{status:p})]}),S?(0,U.jsx)(`p`,{className:`mt-1 line-clamp-2 break-words font-mono text-xs leading-relaxed text-slate-400`,children:S}):null,C?(0,U.jsx)(`div`,{className:`mt-1 font-mono text-[10px] tabular-nums text-slate-500`,children:C}):null]}),o&&d?(0,U.jsxs)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),d(o)},className:`inline-flex min-h-8 shrink-0 items-center gap-1.5 rounded-sm border border-[#f97316]/70 px-2.5 py-1 text-[11px] font-semibold text-[#fb923c] hover:border-[#f97316] hover:bg-[#f97316]/10 focus:outline-none focus:ring-1 focus:ring-[#f97316]`,children:[(0,U.jsx)(fc,{size:13,"aria-hidden":`true`}),`Open sub-session`]}):null]}),w?(0,U.jsxs)(U.Fragment,{children:[(0,U.jsxs)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),b(e=>!e)},"aria-expanded":y,className:`flex min-h-9 w-full items-center justify-between gap-2 border-t border-[#f97316]/15 px-3 py-2 text-left text-[11px] font-semibold text-slate-400 hover:bg-[#f97316]/5 hover:text-slate-200 focus:outline-none focus:ring-1 focus:ring-inset focus:ring-[#f97316]`,children:[(0,U.jsx)(`span`,{children:`Technical details`}),(0,U.jsx)(`span`,{"aria-hidden":`true`,children:y?`−`:`+`})]}),y?(0,U.jsxs)(`div`,{className:`grid min-w-0 gap-3 border-t border-[#f97316]/15 bg-[#0e1116] p-3 text-xs`,children:[n===void 0?null:(0,U.jsx)(j2,{label:`Arguments`,value:n}),r===void 0?null:(0,U.jsx)(j2,{label:`Result`,value:r}),i?(0,U.jsx)(j2,{label:`Error`,value:i,error:!0}):null]}):null]}):null]})}function PBe({status:e}){let t={running:`border-[#0bda57]/40 bg-[#0bda57]/10 text-[#0bda57]`,completed:`border-green-500/40 bg-green-500/10 text-green-400`,failed:`border-red-500/40 bg-red-500/10 text-red-400`,cancelled:`border-slate-500/50 bg-slate-500/10 text-slate-300`},n=`${e.charAt(0).toUpperCase()}${e.slice(1)}`;return(0,U.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded-sm border px-1.5 py-0.5 text-[10px] font-bold uppercase tracking-wide ${t[e]}`,role:`status`,"aria-live":`polite`,"aria-atomic":`true`,children:[e===`running`?(0,U.jsx)(`span`,{className:`h-1.5 w-1.5 animate-pulse rounded-full bg-current`,"aria-hidden":`true`}):null,n]})}function j2({label:e,value:t,error:n=!1}){return(0,U.jsxs)(`div`,{className:`min-w-0`,children:[(0,U.jsx)(`div`,{className:`mb-1 text-[10px] font-bold uppercase tracking-wider ${n?`text-red-400`:`text-[#fb923c]`}`,children:e}),(0,U.jsx)(ZK,{value:t})]})}function FBe(e,t,n,r,i){let a=M2(e),o=M2(t),s=n??(a===void 0?void 0:Math.max(0,(o??r)-a)),c=[];return a!==void 0&&c.push(i?`Started ${IBe(r-a)}`:`Started ${LBe(a)}`),s!==void 0&&c.push(DBe(s)),c.length?c.join(` · `):void 0}function IBe(e){let t=Math.max(0,Math.floor(e/1e3));if(t<5)return`just now`;if(t<60)return`${t}s ago`;let n=Math.floor(t/60);return n<60?`${n}m ago`:`${Math.floor(n/60)}h ago`}function LBe(e){return`${new Date(e).toISOString().slice(11,19)} UTC`}function M2(e){if(!e)return;let t=new Date(e).getTime();return Number.isFinite(t)?t:void 0}async function RBe(){let e=await fetch(`/api/chat/speech/providers`),t=await e.json().catch(()=>void 0);if(!e.ok)throw Error(P2(t,`Could not load speech providers`));return t}async function zBe(e,t,n){let r=await fetch(`/api/chat/speech/sessions`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({offerSdp:e,text:t}),signal:n}),i=await r.json().catch(()=>void 0);if(!r.ok)throw Error(P2(i,`Speech session failed to start`));return i.speechSession}async function BBe(e,t,n){let r=await fetch(`/api/chat/speech/sessions/${encodeURIComponent(e)}/speak`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({text:t}),signal:n});if(!r.ok){let e=await r.json().catch(()=>void 0);throw Error(P2(e,`Speech synthesis failed`))}}async function N2(e){let t=await fetch(`/api/chat/speech/sessions/${encodeURIComponent(e)}`,{method:`DELETE`,headers:{"content-type":`application/json`},body:`{}`});if(!t.ok){let e=await t.json().catch(()=>void 0);throw Error(P2(e,`Speech session could not be stopped`))}}function P2(e,t){return e&&typeof e==`object`&&`error`in e?String(e.error):t}var VBe=2e3,HBe=150,UBe=1.2,WBe=50,GBe=900,KBe=.005;async function qBe(e){e.iceGatheringState!==`complete`&&await new Promise(t=>{let n=()=>{clearTimeout(i),e.removeEventListener(`icegatheringstatechange`,r),t()},r=()=>{e.iceGatheringState===`complete`&&n()},i=setTimeout(n,VBe);e.addEventListener(`icegatheringstatechange`,r)})}function JBe(e){if(typeof e==`string`)try{let t=JSON.parse(e);return t&&typeof t==`object`&&typeof t.type==`string`?t.type:void 0}catch{return}}function YBe(e){let t=e.context.sampleRate,n=Math.ceil(t*UBe),r=Math.max(1,Math.floor(t*.05)),i=e.context.createBuffer(1,n,t),a=i.getChannelData(0);for(let e=0;e<a.length;e+=1){let t=Math.min(1,e/r,(a.length-e-1)/r);a[e]=(Math.random()*2-1)*.14*Math.max(0,t)}let o=e.context.createBufferSource();e.inputSource=o,o.buffer=i,o.connect(e.destination),o.addEventListener(`ended`,()=>{e.inputSource===o&&(o.disconnect(),e.inputSource=void 0)},{once:!0}),o.start()}function F2({text:e,scopeKey:t=``,className:n=``}){let[r,i]=(0,H.useState)(`idle`),[a,o]=(0,H.useState)(null),s=(0,H.useRef)(null),c=(0,H.useRef)(null),l=(0,H.useRef)(null),u=(0,H.useRef)(null),d=(0,H.useRef)(0),f=(0,H.useCallback)(()=>{let e=s.current;s.current=null,e&&(e.ontrack=null,e.onconnectionstatechange=null,e.close());let t=c.current;if(c.current=null,t){if(t.monitor&&clearInterval(t.monitor),t.timer&&clearTimeout(t.timer),t.inputSource){try{t.inputSource.stop()}catch{}t.inputSource.disconnect()}t.outputSource?.disconnect(),t.outputAnalyser?.disconnect();for(let e of t.outputTracks)e.stop();for(let e of t.destination.stream.getTracks())e.stop();t.context.close().catch(()=>{})}},[]),p=(0,H.useCallback)(()=>{let e=l.current;l.current=null,e&&N2(e).catch(()=>{})},[]),m=(0,H.useCallback)(()=>{u.current?.abort(),u.current=null},[]),h=(0,H.useCallback)(()=>{d.current+=1,m(),f(),p()},[m,f,p]);(0,H.useEffect)(()=>(o(null),i(`idle`),h),[h,t,e]);let g=(0,H.useCallback)((e,t)=>{d.current===e&&(d.current+=1,m(),f(),p(),o(t instanceof Error?t.message:String(t)),i(`error`))},[m,f,p]),_=async t=>{if(t.stopPropagation(),r===`loading`||r===`playing`){h(),o(null),i(`idle`);return}let n=d.current+1;d.current=n,m(),f(),p();let a=new AbortController;u.current=a,o(null),i(`loading`);try{if(typeof RTCPeerConnection>`u`||typeof AudioContext>`u`)throw Error(`This browser does not support speech playback`);let t=new RTCPeerConnection;s.current=t;let r=new AudioContext,o=r.createMediaStreamDestination(),h={context:r,destination:o,outputTracks:new Set,triggered:!1};if(c.current=h,await r.resume(),d.current!==n)return;t.onconnectionstatechange=()=>{t.connectionState===`failed`&&g(n,Error(`Speech connection failed`))},t.ontrack=e=>{if(d.current===n)try{let t=e.streams[0]??new MediaStream([e.track]);h.outputTracks.add(e.track);let a=r.createMediaStreamSource(t),o=r.createAnalyser();o.fftSize=1024,a.connect(o),o.connect(r.destination),h.outputSource=a,h.outputAnalyser=o;let s=new Float32Array(o.fftSize),c=!1,l=0;h.monitor=setInterval(()=>{if(d.current!==n)return;o.getFloatTimeDomainData(s);let e=0;for(let t of s)e+=t*t;let t=Math.sqrt(e/s.length),r=performance.now();t>=KBe?(l=r,c||(c=!0,i(`playing`))):c&&r-l>=GBe&&(d.current+=1,m(),p(),f(),i(`idle`))},WBe),e.track.addEventListener(`ended`,()=>{d.current===n&&(d.current+=1,m(),p(),f(),i(`idle`))},{once:!0})}catch(e){g(n,e)}};let _=o.stream.getAudioTracks()[0];if(!_)throw Error(`Could not create a speech audio connection`);t.addTransceiver(_,{direction:`sendrecv`,streams:[o.stream]}),t.createDataChannel(`oai-events`).addEventListener(`message`,e=>{if(d.current!==n)return;let t=JBe(e.data);t===`output_transcript.added`&&i(`playing`),t===`session.context.appended`&&(c.current!==h||h.triggered||(h.timer&&clearTimeout(h.timer),h.timer=setTimeout(()=>{if(!(d.current!==n||h.triggered)){h.triggered=!0;try{YBe(h)}catch(e){g(n,e)}}},HBe)))});let v=await t.createOffer();if(d.current!==n||(await t.setLocalDescription(v),d.current!==n)||(await qBe(t),d.current!==n))return;let y=t.localDescription?.sdp;if(!y)throw Error(`Could not create a speech audio connection`);let b=await zBe(y,e,a.signal);if(d.current!==n){N2(b.sessionId).catch(()=>{});return}l.current=b.sessionId,BBe(b.sessionId,e,a.signal).then(()=>{d.current===n&&(d.current+=1,u.current=null,l.current=null,f(),i(`idle`))}).catch(e=>g(n,e)),await t.setRemoteDescription({type:`answer`,sdp:b.answerSdp})}catch(e){g(n,e)}},v=r===`loading`?`Cancel message audio`:r===`playing`?`Stop message audio`:r===`error`?`Retry message audio`:`Read message aloud`;return(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(`button`,{type:`button`,onClick:e=>void _(e),onDoubleClick:e=>e.stopPropagation(),"aria-label":v,"aria-busy":r===`loading`,title:a??v,"data-pibo-component":`MessageSpeechButton`,"data-speech-state":r,className:`inline-flex h-5 w-5 shrink-0 items-center justify-center rounded-sm text-slate-500 transition-colors hover:bg-slate-700/60 hover:text-[#11a4d4] focus:outline-none focus:ring-1 focus:ring-[#11a4d4] ${r===`error`?`text-red-400`:``} ${n}`,children:r===`loading`?(0,U.jsx)(Pc,{size:12,className:`animate-spin`,"aria-hidden":`true`}):r===`playing`?(0,U.jsx)(xl,{size:10,fill:`currentColor`,"aria-hidden":`true`}):(0,U.jsx)(Hc,{size:12,"aria-hidden":`true`})}),a?(0,U.jsx)(`span`,{className:`sr-only`,role:`alert`,children:a}):null]})}function I2({delivery:e,className:t=``}){let n=e===`steer`;return(0,U.jsxs)(`div`,{className:`flex items-start gap-3 rounded-sm border px-3 py-2.5 ${n?`border-amber-500/40 bg-amber-500/10`:`border-[#11a4d4]/40 bg-[#11a4d4]/10`} ${t}`,"data-pibo-debug":`pending-user-message-${e}`,"aria-live":`polite`,children:[(0,U.jsx)(ic,{size:15,className:`mt-0.5 shrink-0 animate-pulse ${n?`text-amber-400`:`text-[#11a4d4]`}`}),(0,U.jsxs)(`div`,{className:`min-w-0`,children:[(0,U.jsx)(`div`,{className:`text-[11px] font-bold uppercase tracking-wider ${n?`text-amber-400`:`text-[#11a4d4]`}`,children:n?`Steering pending`:`Queued for next turn`}),(0,U.jsx)(`div`,{className:`mt-0.5 text-xs leading-5 text-slate-400`,children:n?`Waiting for the next tool call boundary.`:`Waiting for the active turn to finish.`})]})]})}function L2(e){let t=e.pibo?.traceNodeType;return t?t===`tool.call`||t===`tool.result`||t===`agent.delegation`:e.spanType===`tool.call`||e.spanType===`tool.result`||e.spanType===`agent.delegation`}var R2={"agent.run":{color:`text-[#11a4d4]`,bgColor:`bg-[#11a4d4]/20`,borderColor:`border-[#11a4d4]`,label:`Agent Run`},"tool.call":{color:`text-purple-500`,bgColor:`bg-purple-500/20`,borderColor:`border-purple-500`,label:`Tool Call`},"tool.result":{color:`text-green-500`,bgColor:`bg-green-500/20`,borderColor:`border-green-500`,label:`Tool Result`},"model.request":{color:`text-blue-500`,bgColor:`bg-blue-500/20`,borderColor:`border-blue-500`,label:`Model Request`},"model.response":{color:`text-[#0bda57]`,bgColor:`bg-[#0bda57]/20`,borderColor:`border-[#0bda57]`,label:`Model Response`},"model.reasoning":{color:`text-amber-500`,bgColor:`bg-amber-500/20`,borderColor:`border-amber-500`,label:`Reasoning`},"agent.delegation":{color:`text-orange-500`,bgColor:`bg-orange-500/20`,borderColor:`border-orange-500`,label:`Agent Delegation`},"agent.async":{color:`text-orange-500`,bgColor:`bg-orange-500/20`,borderColor:`border-orange-500`,label:`Async Agent`},"yielded.run":{color:`text-[#11a4d4]`,bgColor:`bg-[#11a4d4]/20`,borderColor:`border-[#11a4d4]`,label:`Yielded Run`},"user.prompt":{color:`text-cyan-500`,bgColor:`bg-cyan-500/20`,borderColor:`border-cyan-500`,label:`User Prompt`},user_input:{color:`text-slate-500`,bgColor:`bg-slate-800`,borderColor:`border-slate-600`,label:`User Input`},"execution.command":{color:`text-yellow-500`,bgColor:`bg-yellow-500/20`,borderColor:`border-yellow-500`,label:`Command`}},z2=12;function B2(e,t){return t===`all`||e<t}(0,H.memo)(function e({span:t,startTime:n,depth:r=0,expansionDepth:i,expansionSignal:a,expandThinking:o,toolDisplayMode:s=`default`,onFork:c,onOpenSession:l}){let[u,d]=(0,H.useState)(()=>B2(r,i)),[f,p]=(0,H.useState)(()=>t.spanType===`model.reasoning`?o:B2(r,i));(0,H.useEffect)(()=>{let e=B2(r,i);d(e),p(t.spanType===`model.reasoning`?o:e)},[r,i,a,o,t.spanType]),R2[t.spanType]||R2[`agent.run`],t.status,t.status,t.spanType===`user.prompt`||t.spanType;let m=!!t.children?.length;U2(t.startTime,n),t.durationUs?`${(t.durationUs/1e3).toFixed(1)}`:t.endTime&&`${((t.endTime-t.startTime)/1e3).toFixed(1)}`;let h=(0,H.useCallback)(()=>{p(e=>!e),m&&d(e=>!e)},[m]);return(0,U.jsx)(XBe,{span:t,startTime:n,depth:r,contentExpanded:f,childrenExpanded:u,onToggle:h,onFork:c,onOpenSession:l,toolDisplayMode:s,childrenContent:m?t.children?.map(t=>(0,U.jsx)(e,{span:t,startTime:n,depth:r+1,expansionDepth:i,expansionSignal:a,expandThinking:o,toolDisplayMode:s,onFork:c,onOpenSession:l},t.id)):void 0})});var XBe=(0,H.memo)(function({span:e,startTime:t,depth:n=0,contentExpanded:r,childrenExpanded:i,onToggle:a,onFork:o,onOpenSession:s,signals:c,toolDisplayMode:l=`default`,childrenContent:u}){let d=R2[e.spanType]||R2[`agent.run`],f=e.status===`UNSET`,p=iVe(e.status,f),m=e.spanType===`user.prompt`||e.spanType===`user_input`,h=!!e.children?.length,g=l!=="default"&&L2(e),_=U2(e.startTime,t),v=e.durationUs?`${(e.durationUs/1e3).toFixed(1)}ms`:e.endTime?`${((e.endTime-e.startTime)/1e3).toFixed(1)}ms`:null;return e.spanType===`agent.delegation`&&l==="default"?(0,U.jsx)(`div`,{className:`relative mb-4`,"data-pibo-debug":`trace-span`,"data-trace-node-id":e.id,"data-span-type":e.spanType,"data-span-status":e.status,"data-order-source":e.pibo?.source,"data-stable-key":e.pibo?.stableKey,style:{marginLeft:n>0?z2:0,width:n>0?`calc(100% - ${z2}px)`:`var(--trace-readable-width)`,maxWidth:`100%`},children:(0,U.jsx)(A2,{title:e.name,summary:typeof e.attributes.content==`string`?e.attributes.content:void 0,input:e.attributes.input??e.attributes.arguments,output:e.attributes.output??e.attributes.result,error:e.statusMessage,traceStatus:e.status===`UNSET`?`running`:e.status===`ERROR`?`error`:`done`,linkedPiboSessionId:e.pibo?.linkedPiboSessionId,startedAt:new Date(e.startTime/1e3).toISOString(),completedAt:e.endTime?new Date(e.endTime/1e3).toISOString():void 0,durationMs:e.durationUs===void 0?void 0:e.durationUs/1e3,signals:c,onOpenSession:s})}):(0,U.jsx)(`div`,{className:`relative mb-4 group`,"data-pibo-debug":`trace-span`,"data-trace-node-id":e.id,"data-span-type":e.spanType,"data-span-status":e.status,"data-order-source":e.pibo?.source,"data-stable-key":e.pibo?.stableKey,style:{marginLeft:n>0?z2:0,width:n>0?`calc(100% - ${z2}px)`:`var(--trace-readable-width)`,maxWidth:`100%`},children:(0,U.jsxs)(`div`,{className:`min-w-0 ${m?`bg-[#11a4d4]/10`:`bg-white dark:bg-[#1a262b]`} border ${p.cardClass} rounded-sm shadow-sm transition-all hover:border-opacity-70 focus:outline-none focus:ring-1 focus:ring-[#11a4d4]/50 ${f?p.glowClass:``}`,onDoubleClick:e=>{g||V2(e)||a()},onKeyDown:e=>{g||V2(e)||(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),a())},role:g?void 0:`button`,tabIndex:g?void 0:0,"aria-expanded":g?void 0:r,children:[(0,U.jsx)(ZBe,{span:e,config:d,statusStyles:p,isActive:f,contentExpanded:r,duration:v,relativeTime:_,onToggle:a,onFork:o,onOpenSession:s,toolDisplayMode:l}),!g&&r?(0,U.jsx)(eVe,{span:e}):null,!g&&h&&i&&r?(0,U.jsx)(`div`,{className:`min-w-0 border-t border-slate-700 bg-slate-900/50 py-4`,children:u}):null]})})});function V2(e){let t=e.target;if(!(t instanceof Element)||t===e.currentTarget)return!1;let n=t.closest(`button, a, input, textarea, select, summary, [role='button'], [tabindex]:not([tabindex='-1'])`);return!!(n&&n!==e.currentTarget)}function ZBe({span:e,config:t,statusStyles:n,isActive:r,contentExpanded:i,duration:a,relativeTime:o,onToggle:s,onFork:c,onOpenSession:l,toolDisplayMode:u}){let d=u!=="default"&&L2(e),f=u===`intent`?H2(e.attributes.intent):void 0,p=e.spanType===`model.response`&&!r?H2(e.attributes.content??e.attributes.output??e.attributes.message):void 0,m=e.spanType===`user.prompt`||e.spanType===`user_input`?`bg-[#11a4d4]/10`:n.headerClass,h=`${i&&!d?`border-b ${t.borderColor}/20`:``} ${m}`;return(0,U.jsx)(`div`,{className:h,children:(0,U.jsxs)(`div`,{className:`box-border flex w-full min-w-0 items-center`,style:{maxWidth:`100%`},children:[(0,U.jsx)(`div`,{className:`min-w-0 flex-1 px-4 py-2 text-left`,children:(0,U.jsxs)(`span`,{className:`min-w-0 text-xs font-bold ${t.color} uppercase tracking-wider flex items-center gap-2`,children:[d?null:i?(0,U.jsx)(Gs,{size:12}):(0,U.jsx)(qs,{size:12}),(0,U.jsx)(QBe,{spanType:e.spanType,config:t,isActive:r}),f?(0,U.jsx)(`span`,{className:`min-w-0 truncate normal-case`,children:f}):(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(`span`,{className:`shrink-0`,children:t.label}),e.name?(0,U.jsxs)(`span`,{className:`min-w-0 truncate font-normal text-slate-500 dark:text-slate-400 normal-case`,children:[`: `,e.name]}):null]}),r?(0,U.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full bg-[#11a4d4] animate-pulse`}):null]})}),(0,U.jsx)(tVe,{forkEntryId:e.pibo?.traceNodeType===`user.message`?e.pibo.entryId:void 0,linkedPiboSessionId:e.pibo?.linkedPiboSessionId,onFork:c,onOpenSession:l}),(0,U.jsx)($Be,{duration:a,relativeTime:o,speechText:p,speechScopeKey:e.id})]})})}function QBe({spanType:e,config:t,isActive:n}){return(0,U.jsxs)(`span`,{className:`relative inline-flex h-6 w-6 shrink-0 items-center justify-center rounded-full ${t.bgColor} border-2 ${t.borderColor} ${n?`shadow-[0_0_10px_rgba(17,164,212,0.4)]`:``}`,children:[(0,U.jsx)(rVe,{type:e,className:t.color}),n?(0,U.jsx)(`span`,{className:`absolute -right-0.5 -top-0.5 h-1.5 w-1.5 rounded-full bg-[#11a4d4] animate-pulse`}):null]})}function $Be({duration:e,relativeTime:t,speechText:n,speechScopeKey:r}){return(0,U.jsxs)(`div`,{className:`ml-2 mr-4 flex w-40 shrink-0 items-center justify-end gap-2 font-mono tabular-nums`,children:[e?(0,U.jsx)(`span`,{className:`text-[10px] text-slate-500 dark:text-slate-400`,children:e}):null,n?.trim()?(0,U.jsx)(F2,{text:n,scopeKey:r}):null,(0,U.jsx)(`span`,{className:`text-xs text-slate-400 dark:text-slate-500`,children:t})]})}var eVe=(0,H.memo)(function({span:e}){let[t,n]=(0,H.useState)(!1),{spanType:r,attributes:i,name:a}=e,o=i.content||i.input||i.output||i.message,s=i.tool_name||i.tool?.name||i[`tool.name`],c=typeof s==`string`?s:null,l=i.output||i.result||i[`tool.result`],u=i.arguments||i.args||i[`tool.arguments`],d=H2(i[`message.pending_delivery`]),f=e.status===`ERROR`?(0,U.jsxs)(`div`,{className:`mx-4 mt-4 p-3 bg-red-500/10 border border-red-500/20 rounded-sm text-xs`,children:[(0,U.jsx)(`div`,{className:`flex items-center gap-2 font-semibold text-red-500 mb-1`,children:`Error`}),e.statusMessage?(0,U.jsx)(`div`,{className:`font-mono text-red-400 mb-2`,children:e.statusMessage}):null]}):null;if(r===`user.prompt`||r===`user_input`)return(0,U.jsxs)(`div`,{className:`flex flex-col`,children:[f,(0,U.jsx)(`div`,{className:`min-w-0 break-words p-4 font-mono text-sm text-slate-300 whitespace-pre-wrap`,children:typeof o==`string`?o:JSON.stringify(o)}),d===`queue`||d===`steer`?(0,U.jsx)(I2,{delivery:d,className:`mx-4 mb-4`}):null]});if(r===`model.response`)return(0,U.jsxs)(`div`,{className:`flex flex-col`,children:[f,(0,U.jsx)(`div`,{className:`model-response-markdown min-w-0 p-4 text-sm text-slate-200 leading-relaxed`,children:typeof o==`string`?(0,U.jsx)(nG,{children:o}):(0,U.jsx)(ZK,{value:o})})]});if(r===`tool.result`)return(0,U.jsxs)(`div`,{className:`flex flex-col`,children:[f,(0,U.jsxs)(`div`,{className:`p-4 bg-green-500/5 border-t border-green-500/20`,children:[(0,U.jsxs)(`div`,{className:`text-xs font-medium text-green-400 mb-2`,children:[`Returned from `,c||a,`:`]}),(0,U.jsx)(ZK,{value:l??o})]})]});if(r===`tool.call`){let e=W2(u)?u:{},r=Object.keys(e).length>0;return(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(`div`,{className:`p-4 bg-[#0e1116] border-b border-slate-800`,children:(0,U.jsx)(nVe,{name:c??a,args:e})}),l==null?null:(0,U.jsxs)(`div`,{className:`px-4 py-2 bg-[#1a262b] flex items-center gap-2`,children:[(0,U.jsx)(As,{size:14,className:`text-slate-400`}),(0,U.jsx)(`span`,{className:`text-xs font-mono text-slate-500`,children:`Output:`}),(0,U.jsx)(`code`,{className:`min-w-0 max-w-md truncate text-xs font-mono text-slate-300`,children:typeof l==`string`?l.slice(0,100):JSON.stringify(l).slice(0,100)})]}),(0,U.jsxs)(`button`,{type:`button`,onClick:()=>n(e=>!e),className:`w-full px-4 py-1.5 flex items-center gap-1.5 text-[11px] font-medium text-slate-400 hover:text-slate-200 bg-slate-900/40 hover:bg-slate-800/60 border-t border-slate-700/40 transition-colors`,children:[t?(0,U.jsx)(pc,{size:12}):(0,U.jsx)(mc,{size:12}),t?`Hide Details`:`Show Details`]}),t?(0,U.jsxs)(`div`,{className:`border-t border-slate-700/40 bg-[#0e1116]`,children:[r?(0,U.jsxs)(`div`,{className:`px-4 pt-3 pb-2`,children:[(0,U.jsx)(`div`,{className:`text-[10px] font-semibold text-blue-400 uppercase tracking-wider mb-1.5`,children:`Input`}),(0,U.jsx)(ZK,{value:e})]}):null,l==null?null:(0,U.jsxs)(`div`,{className:`px-4 pt-2 pb-3 border-t border-slate-700/30`,children:[(0,U.jsx)(`div`,{className:`text-[10px] font-semibold text-green-400 uppercase tracking-wider mb-1.5`,children:`Output`}),(0,U.jsx)(ZK,{value:l})]})]}):null,f]})}if(r===`yielded.run`){let e=W2(l)?l:W2(o)?o:{};return(0,U.jsxs)(`div`,{className:`flex flex-col`,children:[f,(0,U.jsxs)(`div`,{className:`p-4 border-b border-[#11a4d4]/20 bg-[#11a4d4]/5`,children:[(0,U.jsxs)(`div`,{className:`flex items-center gap-2 mb-2`,children:[(0,U.jsx)(Ps,{size:14,className:`text-[#11a4d4]`}),(0,U.jsx)(`span`,{className:`text-sm font-medium text-[#11a4d4]`,children:`Run notification`}),(0,U.jsx)(`span`,{className:`text-xs font-mono text-slate-400`,children:typeof i.content==`string`?i.content:a})]}),(0,U.jsx)(aVe,{notification:e})]}),(0,U.jsxs)(`button`,{type:`button`,onClick:()=>n(e=>!e),className:`w-full px-4 py-1.5 flex items-center gap-1.5 text-[11px] font-medium text-slate-400 hover:text-slate-200 bg-slate-900/40 hover:bg-slate-800/60 border-t border-slate-700/40 transition-colors`,children:[t?(0,U.jsx)(pc,{size:12}):(0,U.jsx)(mc,{size:12}),t?`Hide Details`:`Show Details`]}),t?(0,U.jsx)(`div`,{className:`border-t border-slate-700/40 bg-[#0e1116] px-4 py-3`,children:(0,U.jsx)(ZK,{value:e})}):null]})}if(r===`model.reasoning`){let e=i.reasoning||i[`model.reasoning`]||o;return(0,U.jsxs)(`div`,{className:`flex flex-col`,children:[f,(0,U.jsxs)(`div`,{className:`min-w-0 break-words p-4 font-mono text-sm text-slate-300 bg-amber-500/5 leading-relaxed whitespace-pre-wrap`,children:[(0,U.jsx)(`span`,{className:`text-amber-500 opacity-60`,children:`// Model reasoning`}),(0,U.jsx)(`br`,{}),typeof e==`string`?e:JSON.stringify(e,null,2)]})]})}if(r===`agent.delegation`){let e=i[`delegation.target_agent`],t=i[`delegation.query`],n=i[`result.status`];return(0,U.jsxs)(U.Fragment,{children:[f,(0,U.jsxs)(`div`,{className:`p-4 border-b border-orange-500/20 bg-orange-500/5`,children:[(0,U.jsxs)(`div`,{className:`flex items-center gap-2 mb-2`,children:[(0,U.jsx)(Sc,{size:14,className:`text-orange-500`}),(0,U.jsx)(`span`,{className:`text-sm font-medium text-orange-500`,children:`Delegated to:`}),(0,U.jsxs)(`span`,{className:`text-sm font-semibold text-slate-200`,children:[e||`unknown`,` agent`]}),n?(0,U.jsx)(`span`,{className:`ml-2 px-2 py-0.5 text-[10px] font-bold rounded-sm bg-green-500/20 text-green-500`,children:n.toUpperCase()}):null]}),t?(0,U.jsxs)(`div`,{className:`text-xs text-slate-400 font-mono italic line-clamp-2`,children:[`"`,G2(t),`"`]}):null]})]})}if(r===`agent.async`){let e=i[`async_agent.target_agent`],t=i[`async_agent.query`],n=i[`async_agent.started_by`],r=i.run_id,a=i[`result.status`];return(0,U.jsxs)(U.Fragment,{children:[f,(0,U.jsxs)(`div`,{className:`p-4 border-b border-orange-500/20 bg-orange-500/5`,children:[(0,U.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 mb-2`,children:[(0,U.jsx)(Sc,{size:14,className:`text-orange-500`}),(0,U.jsx)(`span`,{className:`text-sm font-medium text-orange-500`,children:`Async agent started:`}),(0,U.jsxs)(`span`,{className:`text-sm font-semibold text-slate-200`,children:[e||`unknown`,` agent`]}),a?(0,U.jsx)(`span`,{className:`px-2 py-0.5 text-[10px] font-bold rounded-sm bg-orange-500/15 text-orange-400`,children:a.toUpperCase()}):null]}),(0,U.jsxs)(`div`,{className:`mb-2 flex flex-wrap gap-x-3 gap-y-1 font-mono text-[11px] text-slate-500`,children:[(0,U.jsxs)(`span`,{children:[`Started by `,n||`pibo_run_start`]}),r?(0,U.jsx)(`span`,{children:r}):null]}),t?(0,U.jsxs)(`div`,{className:`text-xs text-slate-400 font-mono italic line-clamp-2`,children:[`"`,G2(t),`"`]}):null]})]})}return r===`agent.run`?(0,U.jsx)(`div`,{className:`flex flex-col`,children:f}):(0,U.jsxs)(`div`,{className:`flex flex-col`,children:[f,(0,U.jsx)(`div`,{className:`p-4 font-mono text-sm text-slate-300`,children:(0,U.jsx)(ZK,{value:i})})]})});function tVe({forkEntryId:e,linkedPiboSessionId:t,onFork:n,onOpenSession:r}){let i=e&&n?e:void 0,a=t&&r?t:void 0;return!i&&!a?null:(0,U.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1`,children:[i?(0,U.jsx)(`button`,{type:`button`,onClick:()=>n?.(i),className:`inline-flex h-8 w-8 items-center justify-center rounded-sm border border-slate-700 bg-[#151f24]/80 text-slate-400 transition-colors hover:border-[#11a4d4] hover:text-[#11a4d4]`,title:`Fork user message`,"aria-label":`Fork user message`,children:(0,U.jsx)(Sc,{size:14})}):null,a?(0,U.jsx)(`button`,{type:`button`,onClick:()=>r?.(a),className:`inline-flex h-8 w-8 items-center justify-center rounded-sm border border-slate-700 bg-[#151f24]/80 text-slate-400 transition-colors hover:border-[#11a4d4] hover:text-[#11a4d4]`,title:`Open child session`,"aria-label":`Open child session`,children:(0,U.jsx)(fc,{size:14})}):null]})}function nVe({name:e,args:t}){return(0,U.jsxs)(`code`,{className:`font-mono text-xs text-green-400`,children:[(0,U.jsx)(`span`,{className:`text-purple-400`,children:`def`}),` `,(0,U.jsx)(`span`,{className:`text-yellow-300`,children:e}),(0,U.jsxs)(`span`,{children:[`(`,Object.entries(t).map(([e,t],n)=>(0,U.jsxs)(`span`,{children:[n>0?`, `:null,(0,U.jsx)(`span`,{className:`text-blue-400`,children:e}),`=`,(0,U.jsx)(`span`,{className:`text-green-300`,children:typeof t==`string`?`'${t.slice(0,50)}${t.length>50?`...`:``}'`:G2(t).slice(0,50)})]},e)),`)`]})]})}function rVe({type:e,className:t}){let n={size:14,className:t};switch(e){case`agent.run`:return(0,U.jsx)(Bs,{...n});case`tool.call`:return(0,U.jsx)(Fs,{...n});case`tool.result`:return(0,U.jsx)(As,{...n});case`model.request`:return(0,U.jsx)(Rs,{...n});case`model.response`:return(0,U.jsx)(As,{...n});case`model.reasoning`:return(0,U.jsx)(Ac,{...n});case`agent.delegation`:return(0,U.jsx)(Sc,{...n});case`agent.async`:return(0,U.jsx)(Sc,{...n});case`yielded.run`:return(0,U.jsx)(Ps,{...n});case`user.prompt`:return(0,U.jsx)(Vc,{...n});case`user_input`:return(0,U.jsx)(Dl,{...n});case`execution.command`:return(0,U.jsx)(Fs,{...n});default:return(0,U.jsx)(Ws,{...n})}}function iVe(e,t){return e===`ERROR`?{cardClass:`border-[#ff6b00]/50`,headerClass:`bg-[#ff6b00]/5`,glowClass:``}:e===`OK`?{cardClass:`border-[#0bda57]/30`,headerClass:`bg-[#0bda57]/5`,glowClass:``}:t?{cardClass:`border-[#11a4d4]/50`,headerClass:`bg-[#11a4d4]/5`,glowClass:`shadow-[0_0_10px_rgba(17,164,212,0.1)]`}:{cardClass:`border-slate-700`,headerClass:`bg-[#151f24]`,glowClass:``}}function aVe({notification:e}){let t=[[`completed`,`text-green-500`,e.completed],[`failed`,`text-red-400`,e.failed],[`timed out`,`text-amber-400`,e.timedOut],[`cancelled`,`text-slate-400`,e.cancelled],[`running`,`text-[#11a4d4]`,e.running]].map(([e,t,n])=>({name:e,color:t,runs:Array.isArray(n)?n.filter(W2):[]})).filter(e=>e.runs.length>0);return t.length===0?(0,U.jsx)(`div`,{className:`text-xs text-slate-400`,children:`No yielded run updates.`}):(0,U.jsx)(`div`,{className:`grid gap-2`,children:t.map(e=>(0,U.jsxs)(`div`,{children:[(0,U.jsx)(`div`,{className:`mb-1 text-[10px] font-bold uppercase tracking-wider ${e.color}`,children:e.name}),(0,U.jsx)(`div`,{className:`grid gap-1`,children:e.runs.map((t,n)=>(0,U.jsxs)(`div`,{className:`grid grid-cols-[minmax(0,1fr)_auto] gap-2 rounded-sm border border-slate-700/60 bg-[#0e1116]/60 px-2 py-1.5`,children:[(0,U.jsxs)(`div`,{className:`min-w-0`,children:[(0,U.jsx)(`div`,{className:`truncate font-mono text-xs text-slate-200`,children:H2(t.toolName)||`yielded tool`}),(0,U.jsx)(`div`,{className:`truncate font-mono text-[10px] text-slate-500`,children:H2(t.runId)})]}),(0,U.jsx)(`div`,{className:`font-mono text-[10px] uppercase text-slate-400`,children:H2(t.status)||e.name})]},`${e.name}-${n}`))})]},e.name))})}function H2(e){return typeof e==`string`?e:``}function U2(e,t){let n=(e-t)/1e3,r=Math.floor(n/6e4),i=Math.floor(n%6e4/1e3),a=Math.floor(n%1e3);return`${String(r).padStart(2,`0`)}:${String(i).padStart(2,`0`)}.${String(a).padStart(3,`0`)}`}function W2(e){return!!e&&typeof e==`object`&&!Array.isArray(e)}function G2(e){if(typeof e==`string`)return e;try{return JSON.stringify(e)}catch{return String(e)}}function oVe({entryId:e,onFork:t,className:n=``}){let r=e=>e.stopPropagation();return(0,U.jsx)(`button`,{type:`button`,onClick:n=>{r(n),t(e)},onDoubleClick:r,"aria-label":`Fork from this user message`,title:`Fork from this user message`,"data-pibo-component":`MessageForkButton`,className:`inline-flex h-5 w-5 shrink-0 items-center justify-center rounded-sm text-slate-500 transition-colors hover:bg-slate-700/60 hover:text-[#11a4d4] focus:outline-none focus:ring-1 focus:ring-[#11a4d4] ${n}`,children:(0,U.jsx)(Sc,{size:12})})}function sVe(e){return e.isTreeActive||e.latestTurn?.state===`running`?`running`:e.localStatus===`error`||e.latestTurn?.state===`failed`?`error`:`idle`}function K2(e,t={}){if(!e)return cVe(t);let n=e.latestTurn,r=n?.state===`running`,i=e.isTreeActive||r;return{status:sVe({isTreeActive:i,localStatus:e.localStatus,latestTurn:n}),isTreeActive:i,isTurnActive:r,activeTurnId:r?n.eventId:void 0,activeTurnStartedAt:r?n.startedAt:void 0,latestTurn:n,source:`signals`}}function cVe(e){let t=e.status===`running`&&lVe(e.turnStartedAt);return{status:e.status??`idle`,isTreeActive:e.status===`running`,isTurnActive:t,activeTurnStartedAt:t?e.turnStartedAt:void 0,source:`fallback`}}function lVe(e){return!!(e&&Number.isFinite(Date.parse(e)))}function uVe({signal:e,fallbackStatus:t,fallbackTurnStartedAt:n}){return(0,H.useMemo)(()=>K2(e,{status:t,turnStartedAt:n}),[t,n,e])}function dVe({goal:e}){let t=q2(e),n=e?zq(e):void 0,[r,i]=(0,H.useState)(()=>Date.now());return(0,H.useEffect)(()=>{if(i(Date.now()),!t||!n)return;let e=window.setInterval(()=>i(Date.now()),1e3);return()=>window.clearInterval(e)},[e?.id,n,t]),(0,U.jsx)(fVe,{goal:e,nowMs:r})}function fVe({goal:e,nowMs:t}){let n=q2(e);if(!e||!n)return null;let r=n===`active`?`Pursuing Goal`:`Goal Paused`,i=n===`active`?`text-fuchsia-400`:`text-amber-300`,a=pVe(e,t),o=n===`active`?J2(e):void 0,s=[r,`Active time ${a}`,o?`Tokens ${o}`:void 0].filter(Boolean).join(`. `);return(0,U.jsxs)(`span`,{className:`ml-auto inline-flex shrink-0 items-center gap-2 font-sans text-sm font-semibold ${i}`,"data-pibo-debug":`session-goal-indicator`,"data-goal-id":e.id,"data-goal-status":n,"aria-label":s,title:`${e.name}: ${e.prompt}`,children:[(0,U.jsx)(Sl,{size:17,className:n===`active`?`animate-pulse`:``,"aria-hidden":`true`}),(0,U.jsxs)(`span`,{children:[r,`:`]}),(0,U.jsx)(`span`,{className:`tabular-nums`,children:a}),o?(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(`span`,{"aria-hidden":`true`,children:`·`}),(0,U.jsx)(`span`,{className:`font-mono tabular-nums`,children:o})]}):null]})}function q2(e){if(!e||e.mode!==`goal`)return;let t=e.state.goalStatus??(e.enabled?`active`:`paused`);return t===`active`||t===`paused`?t:void 0}function J2(e){let t=Y2(e.state.tokensUsed??0);return e.tokenBudget===void 0?t:`${t} / ${Y2(e.tokenBudget)}`}function Y2(e){let t=Number.isFinite(e)?Math.max(0,e):0;return t>=1e6?`${(t/1e6).toFixed(1)}M`:`${(t/1e3).toFixed(1)}k`}function pVe(e,t){let n=Bq(e,t),r=Math.floor(n/3600),i=Math.floor(n%3600/60),a=n%60;return r>0?`${r}:${String(i).padStart(2,`0`)}:${String(a).padStart(2,`0`)}`:`${i}:${String(a).padStart(2,`0`)}`}var mVe=[`o200k_base`,`cl100k_base`,`p50k_base`,`r50k_base`,`p50k_edit`,`gpt2`],hVe={method:`characters`,factor:4};function gVe(e){return e?e===`chars/4`?`chars ÷ 4`:e.startsWith(`characters/`)?`chars ÷ ${e.slice(11)}`:`tiktoken · ${e.slice(9)}`:`—`}var _Ve=new Intl.NumberFormat(`en-US`),vVe={duration:{unavailable:`border-[#525252] bg-[#171717] text-[#737373]`,normal:`border-[#c084fc] bg-[#c084fc]/15 text-[#e9d5ff]`,elevated:`border-[#ffb000] bg-[#ffb000]/20 text-[#ffd166]`,high:`border-[#ff6b00] bg-[#ff6b00]/20 text-[#ffad66]`,critical:`border-[#ff2bd6] bg-[#ff2bd6]/25 text-[#ff8bea]`},input:{unavailable:`border-[#525252] bg-[#171717] text-[#737373]`,normal:`border-[#00e5ff] bg-[#00e5ff]/15 text-[#7df9ff]`,elevated:`border-[#ffe600] bg-[#ffe600]/20 text-[#fff36b]`,high:`border-[#ff7a00] bg-[#ff7a00]/20 text-[#ffb15c]`,critical:`border-[#ff2bd6] bg-[#ff2bd6]/25 text-[#ff8bea]`},output:{unavailable:`border-[#525252] bg-[#171717] text-[#737373]`,normal:`border-[#a3ff12] bg-[#a3ff12]/15 text-[#c7ff6b]`,elevated:`border-[#ffe600] bg-[#ffe600]/20 text-[#fff36b]`,high:`border-[#ff6b00] bg-[#ff6b00]/25 text-[#ffad66]`,critical:`border-[#ff2bd6] bg-[#ff2bd6]/30 text-[#ff8bea]`}};function X2(e,t){return e===void 0||!Number.isFinite(e)||e<0?`—`:`${t?.startsWith(`tiktoken/`)?``:`≈`}${_Ve.format(Math.round(e))}`}function yVe(e){return e===void 0||!Number.isFinite(e)||e<0?`—`:e<1e3?`${Math.round(e)} ms`:e<6e4?`${(e/1e3).toFixed(1)} s`:`${Math.floor(e/6e4)}m ${Math.floor(e%6e4/1e3)}s`}function bVe(e,t,n){if(t===void 0||!Number.isFinite(t)||t<0)return`unavailable`;let r=e===`duration`?n.durationMs:e===`input`?n.inputTokens:n.outputTokens;return t>=r.critical?`critical`:t>=r.high?`high`:t>=r.elevated?`elevated`:`normal`}function Z2({kind:e,label:t,value:n,formatted:r,description:i,thresholds:a}){let o=bVe(e,n,a);return(0,U.jsxs)(`span`,{"data-metric-kind":e,"data-metric-level":o,title:i,className:`inline-flex min-w-0 items-baseline gap-1.5 border-l-2 px-2 py-0.5 font-bold ${vVe[e][o]}`,children:[(0,U.jsx)(`span`,{className:`text-[9px] font-black uppercase tracking-[0.14em] opacity-80`,children:t}),(0,U.jsx)(`span`,{className:`whitespace-nowrap text-[11px]`,children:r})]})}function xVe({basis:e}){let t=e?.startsWith(`tiktoken/`)?`tiktoken`:e?`characters`:`unavailable`;return(0,U.jsxs)(`span`,{"data-metric-kind":`basis`,"data-token-method":t,"data-token-factor":e===`chars/4`?`4`:e?.startsWith(`characters/`)?e.slice(11):void 0,"data-token-encoding":e?.startsWith(`tiktoken/`)?e.slice(9):void 0,title:`Payload token calculation used for this Tool call; this is not provider usage or billing attribution`,className:`inline-flex min-w-0 items-baseline gap-1.5 border-l-2 border-[#38bdf8] bg-[#38bdf8]/10 px-2 py-0.5 font-bold text-[#bae6fd]`,children:[(0,U.jsx)(`span`,{className:`text-[9px] font-black uppercase tracking-[0.14em] opacity-80`,children:`Calc`}),(0,U.jsx)(`span`,{className:`whitespace-nowrap text-[11px]`,children:gVe(e)})]})}function Q2({metrics:e,thresholds:t=a$}){return(0,U.jsxs)(`div`,{"data-pibo-debug":`tool-metrics`,"aria-label":`Tool call metrics`,className:`ml-[1.9rem] mt-1 flex flex-wrap items-stretch gap-px border-y border-[#262626] bg-[#050505] py-px font-mono leading-[1.45] tabular-nums`,children:[(0,U.jsx)(Z2,{kind:`duration`,label:`Time`,value:e?.durationMs,formatted:yVe(e?.durationMs),description:`Execution time from tool start to finish; color bands use the configured Debug thresholds; — means unavailable`,thresholds:t}),(0,U.jsx)(Z2,{kind:`input`,label:`In`,value:e?.inputTokens,formatted:X2(e?.inputTokens,e?.tokenBasis),description:`Tool-argument payload tokens using the recorded calculation method, not model input usage; color bands use the configured Debug thresholds; — means unavailable`,thresholds:t}),(0,U.jsx)(Z2,{kind:`output`,label:`Out`,value:e?.outputTokens,formatted:`${X2(e?.outputTokens,e?.tokenBasis)} tokens`,description:`Tool-result payload tokens using the recorded calculation method, not model output usage or billing; color bands use the configured Debug thresholds. Media and unmeasurable payloads show —.`,thresholds:t}),(0,U.jsx)(xVe,{basis:e?.tokenBasis})]})}function $2(e){if(e==null)return{kind:`empty`};let t=e4(e);return t===void 0?{kind:`json`,value:e}:{kind:`text`,text:t}}function e4(e){if(typeof e==`string`)return e;if(Array.isArray(e)){let t=e.map(e4).filter(e=>e!==void 0);return t.length===e.length&&t.length>0?t.join(``):void 0}if(!t4(e))return;let t=typeof e.type==`string`?e.type:void 0;if(t===`text`&&typeof e.text==`string`)return e.text;if(t===`text`&&typeof e.content==`string`)return e.content;if(t===`output_text`&&typeof e.text==`string`)return e.text;let n=e4(e.content);if(n!==void 0&&SVe(e))return n;let r=t4(e.message)?e4(e.message.content):void 0;if(r!==void 0)return r}function SVe(e){let t=Object.keys(e).filter(t=>e[t]!==void 0);return t.length===1&&t[0]===`content`||t.every(e=>e===`content`||e===`type`)||t.every(e=>e===`content`||e===`details`||e===`type`)?!0:typeof e.type==`string`&&e.type.includes(`text`)}function t4(e){return!!e&&typeof e==`object`&&!Array.isArray(e)}function CVe({row:e,onOpenSession:t}){return(0,U.jsx)(`div`,{className:`mt-2 border border-[#2a2a2a] bg-[#111111] px-3 py-2 text-[12px] text-[#d4d4d4]`,"data-shared-terminal-details":e.kind,children:e.detailItems?.length?(0,U.jsx)(`div`,{className:`space-y-3`,children:e.detailItems.map(e=>(0,U.jsxs)(`div`,{className:`space-y-2`,children:[(0,U.jsxs)(`div`,{className:`flex items-center gap-2 text-[11px]`,children:[(0,U.jsx)(`span`,{className:`font-semibold text-[#d4d4d4]`,children:e.label}),e.linkedPiboSessionId?(0,U.jsx)(`button`,{type:`button`,onClick:()=>t(e.linkedPiboSessionId),className:`border border-[#3a3a3a] px-2 py-0.5 text-[#38bdf8] hover:border-[#38bdf8]`,children:`Open Session`}):null]}),(0,U.jsx)(r4,{label:`Input`,value:e.input}),(0,U.jsx)(r4,{label:`Output`,value:e.output}),(0,U.jsx)(n4,{refs:e.payloadRefs}),(0,U.jsx)(i4,{value:e.output}),e.error?(0,U.jsx)(o4,{label:`Error`,value:e.error,tone:`red`}):null]},e.id))}):(0,U.jsxs)(`div`,{className:`space-y-3`,children:[(0,U.jsx)(r4,{label:`Input`,value:e.input}),(0,U.jsx)(r4,{label:`Output`,value:e.output}),(0,U.jsx)(n4,{refs:e.payloadRefs}),(0,U.jsx)(i4,{value:e.output}),e.error?(0,U.jsx)(o4,{label:`Error`,value:e.error,tone:`red`}):null,e.linkedPiboSessionId?(0,U.jsxs)(`div`,{className:`flex items-center gap-2 text-[11px]`,children:[(0,U.jsx)(`span`,{className:`text-[#737373]`,children:`Child session`}),(0,U.jsx)(`button`,{type:`button`,onClick:()=>t(e.linkedPiboSessionId),className:`border border-[#3a3a3a] px-2 py-0.5 text-[#38bdf8] hover:border-[#38bdf8]`,children:e.linkedPiboSessionId})]}):null]})})}function n4({refs:e}){if(!e)return null;let t=Object.entries(e).filter(e=>!!e[1]);return t.length?(0,U.jsx)(`div`,{className:`space-y-2`,children:t.map(([e,t])=>(0,U.jsx)(wVe,{kind:e,refInfo:t},`${e}:${t.ref}`))}):null}function wVe({kind:e,refInfo:t}){let[n,r]=(0,H.useState)({status:`loading`});return(0,H.useEffect)(()=>{let e=!1;return r({status:`loading`}),Su(t.ref,{offset:0,limit:65536}).then(t=>{e||r({status:`loaded`,data:t.data,hasMore:t.hasMore,nextOffset:t.nextOffset})}).catch(t=>{e||r({status:`error`,message:t instanceof Error?t.message:String(t)})}),()=>{e=!0}},[t.ref]),(0,U.jsxs)(`div`,{className:`space-y-1`,"data-shared-terminal-payload-ref":e,children:[(0,U.jsxs)(`div`,{className:`text-[11px] font-semibold text-[#737373]`,children:[e,` payload (`,Math.ceil(t.byteLength/1024),` KB)`]}),n.status===`loading`?(0,U.jsx)(`div`,{className:`border border-[#2a2a2a] bg-[#0b0b0b] p-2 text-[12px] text-[#737373]`,children:`Loading payload preview...`}):n.status===`error`?(0,U.jsx)(`div`,{className:`border border-[#2a2a2a] bg-[#0b0b0b] p-2 text-[12px] text-[#ef4444]`,children:n.message}):(0,U.jsxs)(`div`,{className:`space-y-1`,children:[(0,U.jsx)(`pre`,{className:`m-0 max-h-[520px] overflow-auto whitespace-pre-wrap break-words border border-[#2a2a2a] bg-[#0b0b0b] p-2 font-mono text-[12px] leading-[1.45] text-[#d4d4d4]`,children:n.data}),n.hasMore?(0,U.jsx)(`div`,{className:`text-[11px] text-[#737373]`,children:`Showing first chunk. More payload data is available on demand.`}):null]})]})}function r4({label:e,value:t}){let n=$2(t);if(n.kind===`empty`)return null;if(n.kind===`text`){let t=s4(n.text);return t?.kind===`json`?(0,U.jsx)(a4,{label:e,value:t.value,meta:t.meta}):t?.kind===`text`?(0,U.jsx)(o4,{label:e,value:t.text}):(0,U.jsx)(o4,{label:e,value:n.text})}return(0,U.jsx)(a4,{label:e,value:n.value})}function i4({value:e}){let t=TVe(e);return t?(0,U.jsxs)(`details`,{className:`space-y-1 border border-[#2a2a2a] bg-[#0b0b0b] p-2`,children:[(0,U.jsxs)(`summary`,{className:`cursor-pointer text-[11px] font-semibold text-[#38bdf8]`,children:[`Show full output (`,t.originalLines,` lines)`]}),t.fullOutput?(0,U.jsx)(`pre`,{className:`mt-2 max-h-[520px] overflow-auto whitespace-pre-wrap break-words font-mono text-[12px] leading-[1.45] text-[#d4d4d4]`,children:t.fullOutput}):t.fullOutputPath?(0,U.jsxs)(`div`,{className:`mt-2 min-w-0 break-words font-mono text-[12px] text-[#d4d4d4]`,children:[`Full output file: `,t.fullOutputPath]}):null]}):null}function TVe(e){if(!u4(e))return;let t=u4(e.details)?e.details.piboBashOutputCompaction:void 0;if(!u4(t)||t.kind!==`validation-output`)return;let n=typeof t.originalLines==`number`?t.originalLines:void 0;if(n!==void 0)return{originalLines:n,fullOutput:typeof t.fullOutput==`string`?t.fullOutput:void 0,fullOutputPath:typeof t.fullOutputPath==`string`?t.fullOutputPath:void 0}}function a4({label:e,value:t,meta:n}){return(0,U.jsxs)(`div`,{className:`space-y-1`,"data-shared-terminal-detail-json":e,children:[(0,U.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,U.jsx)(`div`,{className:`text-[11px] font-semibold text-[#737373]`,"data-shared-terminal-detail-label":e,children:e}),n?(0,U.jsxs)(`div`,{className:`min-w-0 break-words text-[11px] text-[#737373]`,children:[`Status: `,n]}):null]}),(0,U.jsx)(`div`,{className:`compact-terminal-json border border-[#2a2a2a] bg-[#0b0b0b] p-2`,children:(0,U.jsx)(ZK,{value:t,showControls:!1})})]})}function o4({label:e,value:t,tone:n=`default`}){return(0,U.jsxs)(`div`,{className:`space-y-1`,"data-shared-terminal-detail-text":e,children:[(0,U.jsx)(`div`,{className:`text-[11px] font-semibold text-[#737373]`,"data-shared-terminal-detail-label":e,children:e}),(0,U.jsx)(`pre`,{className:`m-0 whitespace-pre-wrap break-words border border-[#2a2a2a] bg-[#0b0b0b] p-2 font-mono text-[12px] leading-[1.45] ${n===`red`?`text-[#ef4444]`:`text-[#d4d4d4]`}`,children:t})]})}function s4(e){let t=e.trim();if(!t)return;let n=l4(t);if(n!==void 0)return c4(n);let r=t.split(/\r?\n/);for(let e=1;e<r.length;e+=1){let t=r.slice(e).join(`
212
- `).trim();if(!t.startsWith(`{`)&&!t.startsWith(`[`))continue;let n=l4(t);if(n!==void 0)return c4(n,r.slice(0,e).join(` `).trim()||void 0)}}function c4(e,t){let n=$2(e);if(n.kind===`text`){let e=s4(n.text);return e?.kind===`json`?{...e,meta:e.meta??t}:{kind:`text`,text:n.text}}return{kind:`json`,value:e,meta:t}}function l4(e){if(!(!e.startsWith(`{`)&&!e.startsWith(`[`)))try{let t=JSON.parse(e);return typeof t==`object`&&t?t:void 0}catch{return}}function u4(e){return!!e&&typeof e==`object`&&!Array.isArray(e)}function EVe({name:e,input:t}){return(0,U.jsxs)(`span`,{className:`compact-terminal-function-call`,children:[(0,U.jsx)(`span`,{className:`text-[#facc15] font-semibold`,children:e}),(0,U.jsx)(`span`,{className:`text-[#d4d4d4]`,children:`(`}),t===void 0?null:(0,U.jsx)(DVe,{value:t}),(0,U.jsx)(`span`,{className:`text-[#d4d4d4]`,children:`)`})]})}function DVe({value:e}){let[t,n]=(0,H.useState)(()=>new Set([`$`])),[r,i]=(0,H.useState)(()=>new Set);return(0,U.jsx)(d4,{value:e,path:`$`,expandedPaths:t,expandedStrings:r,onTogglePath:e=>{n(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},onToggleString:e=>{i(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}})}function d4({value:e,path:t,expandedPaths:n,expandedStrings:r,onTogglePath:i,onToggleString:a}){if(Array.isArray(e))return(0,U.jsx)(f4,{value:e,path:t,open:`[`,close:`]`,expandedPaths:n,expandedStrings:r,onTogglePath:i,onToggleString:a});if(AVe(e))return(0,U.jsx)(f4,{value:e,path:t,open:`{`,close:`}`,expandedPaths:n,expandedStrings:r,onTogglePath:i,onToggleString:a});if(typeof e==`string`){let n=r.has(t),i=e.length>140&&!n,o=i?`${e.slice(0,140)}...`:e,s=(0,U.jsx)(`span`,{className:`text-[#fb923c]`,children:JSON.stringify(o)});return!i&&e.length<=140?s:(0,U.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),a(t)},className:`compact-terminal-json-toggle text-left align-baseline`,title:n?`Collapse string`:`Expand string`,"aria-label":`String at ${OVe(t)}`,"aria-expanded":n,children:s})}return typeof e==`number`||typeof e==`boolean`||e===null?(0,U.jsx)(`span`,{className:`text-[#60a5fa]`,children:String(e)}):(0,U.jsx)(`span`,{className:`text-[#737373]`,children:JSON.stringify(String(e))})}function f4({value:e,path:t,open:n,close:r,expandedPaths:i,expandedStrings:a,onTogglePath:o,onToggleString:s}){let c=i.has(t),l=`inline-json-${(0,H.useId)()}`,u=c?Array.isArray(e)?e.map((e,t)=>[String(t),e]):Object.entries(e):[];return(0,U.jsxs)(`span`,{children:[(0,U.jsxs)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),o(t)},className:`compact-terminal-json-toggle align-baseline text-[#737373]`,title:c?`Collapse JSON`:`Expand JSON`,"aria-label":`JSON at ${t}`,"aria-expanded":c,"aria-controls":l,"data-inline-json-path":t,children:[(0,U.jsx)(`span`,{className:`compact-terminal-json-caret`,children:c?`▾`:`▸`}),n,c?null:`...${r}`]}),(0,U.jsxs)(`span`,{id:l,children:[u.map(([n,r],c)=>{let l=`${t}.${kVe(n)}`;return(0,U.jsxs)(`span`,{children:[c>0?(0,U.jsx)(`span`,{className:`text-[#737373]`,children:`, `}):null,Array.isArray(e)?null:(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(`span`,{className:`text-[#d4d4d4]`,children:JSON.stringify(n)}),(0,U.jsx)(`span`,{className:`text-[#737373]`,children:`:`})]}),(0,U.jsx)(d4,{value:r,path:l,expandedPaths:i,expandedStrings:a,onTogglePath:o,onToggleString:s})]},l)}),c?(0,U.jsx)(`span`,{className:`text-[#737373]`,children:r}):null]})]})}function OVe(e){let t=e.replace(/[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}/gi,`[id]`);return t.length<=80?t:`${t.slice(0,39)}…${t.slice(-39)}`}function kVe(e){return e.replaceAll(`\\`,`\\\\`).replaceAll(`.`,`\\.`)}function AVe(e){return!!e&&typeof e==`object`&&!Array.isArray(e)}var jVe=120;function MVe({line:e,status:t,clampLines:n}){let r=`min-w-0 whitespace-pre-wrap break-words ${n?`block overflow-hidden`:``}`,i=FVe(e.tokens),a=i.length>jVe&&!i.some(e=>e.href);return(0,U.jsxs)(`div`,{className:`grid grid-cols-[1.9rem_minmax(0,1fr)] gap-2 leading-[1.45]`,children:[(0,U.jsx)(`span`,{className:`whitespace-pre ${PVe(e.prefix,t)}`,children:NVe(e.prefix)}),(0,U.jsxs)(`span`,{className:r,style:n?{maxHeight:`${n*1.45}em`}:void 0,children:[a?(0,U.jsx)(`span`,{className:`text-[#d4d4d4]`,children:i.map(e=>e.text).join(``)}):i.map((e,t)=>e.href?(0,U.jsx)(`a`,{href:e.href,target:`_blank`,rel:`noreferrer noopener`,"aria-label":e.ariaLabel,className:`${p4(e)} underline decoration-[#60a5fa]/40 underline-offset-2 hover:decoration-[#60a5fa] focus:outline-none focus:ring-1 focus:ring-[#38bdf8]`,children:e.text},`${t}:${e.href}:${e.text}`):(0,U.jsx)(`span`,{className:p4(e),children:e.text},`${t}:${e.text}`)),e.functionCall?(0,U.jsx)(EVe,{name:e.functionCall.name,input:e.functionCall.input}):null]})]})}function NVe(e=`none`){switch(e){case`bullet`:return`•`;case`detail`:return`└`;case`continuation`:return` `;case`prompt`:return`›`;default:return` `}}function PVe(e=`none`,t){if(e===`bullet`){if(t===`running`)return`text-[#38bdf8]`;if(t===`error`)return`text-[#ef4444]`;if(t===`done`)return`text-[#22c55e]`}return`text-[#737373]`}function p4(e){return`${e.tone===`dim`?`text-[#737373]`:e.tone===`cyan`?`text-[#38bdf8]`:e.tone===`green`?`text-[#22c55e]`:e.tone===`red`?`text-[#ef4444]`:e.tone===`magenta`?`text-[#d946ef]`:e.tone===`yellow`?`text-[#facc15]`:e.tone===`blue`?`text-[#60a5fa]`:e.tone===`amber`?`text-[#f59e0b]`:`text-[#d4d4d4]`} ${e.weight===`bold`?`font-bold`:e.weight===`semibold`?`font-semibold`:`font-normal`} ${e.italic?`italic`:``}`.trim()}function FVe(e){let t=[];for(let n of e){if(!n.text)continue;let e=t.at(-1);if(e&&e.tone===n.tone&&e.weight===n.weight&&e.italic===n.italic&&e.href===n.href&&e.ariaLabel===n.ariaLabel){e.text+=n.text;continue}t.push({...n})}return t}async function IVe(){return await G(`/api/chat/provider-auth`)}async function m4(e){return(await G(`/api/chat/provider-auth`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify(e)})).result}function LVe(e){if(typeof e!=`object`||!e||Array.isArray(e))return!1;let t=e;return t.action===`show_login_menu`&&Array.isArray(t.providers)}function RVe(e){if(typeof e!=`object`||!e||Array.isArray(e))return!1;let t=e;return t.action===`show_model_menu`&&Array.isArray(t.providers)}function h4(e){return zVe(e)?e.result:e}function zVe(e){return!!e&&typeof e==`object`&&!Array.isArray(e)&&e.type===`execution_result`}var BVe={device_code:`Device code`,browser_oauth:`Browser OAuth`,api_key:`API key`};function VVe({row:e,piboSessionId:t}){let n=LVe(e.output)?e.output:void 0,r=(0,H.useMemo)(()=>n?.providers??[],[n?.providers]),[i,a]=(0,H.useState)({type:`select_provider`}),[o,s]=(0,H.useState)(!1),[c,l]=(0,H.useState)(``),[u,d]=(0,H.useState)(``),[f,p]=(0,H.useState)(null),m=(0,H.useRef)(!1),h=(0,H.useCallback)(()=>{a({type:`select_provider`}),l(``),d(``)},[]),g=(0,H.useCallback)(async e=>{try{await navigator.clipboard.writeText(e),p(e),window.setTimeout(()=>p(t=>t===e?null:t),1600)}catch{}},[]),_=(0,H.useCallback)(async(e,n)=>{if(!t){a({type:`error`,provider:e,message:`Select a chat session before starting login.`});return}s(!0),a({type:`device_starting`,provider:e});try{let r=h4(await Yl(t,`login.start`,{provider:e.id,method:n})),i=r?.url??r?.flow?.verificationUrl;if(!i){a({type:`error`,provider:e,message:`No login URL returned.`});return}a({type:`device_flow`,provider:e,url:i,flowId:r.flowId??r.state??r.flow?.flowId,completion:r.flow?.completion,userCode:r.userCode??r.flow?.userCode,instructions:r.instructions??r.flow?.instructions})}catch(t){a({type:`error`,provider:e,message:t instanceof Error?t.message:String(t)})}finally{s(!1)}},[t]),v=(0,H.useCallback)(async(e,n,r)=>{if(!(!t||!n)){s(!0);try{let i=h4(await Yl(t,`login.complete`,{provider:e.id,flowId:n,...r?{code:r}:{}}));if(i?.state===`pending`)return;if(i?.state===`failed`){a({type:`error`,provider:e,message:`Login failed. Start a new runtime login flow.`});return}a({type:`success`,provider:e,message:`${e.name} login completed for this runtime.`})}catch(t){a({type:`error`,provider:e,message:t instanceof Error?t.message:String(t)})}finally{s(!1)}}},[t]),y=(0,H.useCallback)(async(e,n)=>{if(!t||!n){h();return}s(!0);try{await Yl(t,`login.cancel`,{provider:e.id,flowId:n}),h()}catch(t){a({type:`error`,provider:e,message:t instanceof Error?t.message:String(t)})}finally{s(!1)}},[t,h]);(0,H.useEffect)(()=>{if(i.type!==`device_flow`||i.completion!==`notification`||!i.flowId||!t)return;let e=async()=>{if(!(m.current||i.type!==`device_flow`)){m.current=!0;try{let e=h4(await Yl(t,`login.complete`,{provider:i.provider.id,flowId:i.flowId}));e?.state===`connected`||e?.state===`partial`?a({type:`success`,provider:i.provider,message:`${i.provider.name} login completed for this runtime.`}):e?.state===`failed`&&a({type:`error`,provider:i.provider,message:`Login failed. Start a new runtime login flow.`})}catch(e){a({type:`error`,provider:i.provider,message:e instanceof Error?e.message:String(e)})}finally{m.current=!1}}},n=window.setInterval(()=>void e(),1500);return()=>window.clearInterval(n)},[t,i]);let b=(0,H.useCallback)(async e=>{if(!t)return;let n=c.trim();if(n){s(!0);try{await Yl(t,`login.apikey`,{provider:e.id,apiKey:n}),l(``),a({type:`success`,provider:e,message:`${e.name} API key saved.`})}catch(t){a({type:`error`,provider:e,message:t instanceof Error?t.message:String(t)})}finally{s(!1)}}},[c,t]);return n?(0,U.jsx)(g4,{title:i.type===`select_provider`?`Login`:UVe(i),tone:i.type===`error`?`red`:i.type===`success`?`green`:`cyan`,action:i.type===`select_provider`?void 0:(0,U.jsx)(HVe,{onClick:()=>{i.type===`device_flow`?y(i.provider,i.flowId):h()},disabled:o}),children:i.type===`select_provider`?(0,U.jsxs)(`div`,{className:`grid gap-2`,children:[(0,U.jsxs)(`div`,{className:`text-[11px] text-[#737373]`,children:[`Choose a provider. Use `,(0,U.jsx)(`span`,{className:`text-[#38bdf8]`,children:`/login`}),` anytime.`]}),(0,U.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:r.map(e=>(0,U.jsxs)(`button`,{type:`button`,onClick:()=>a({type:`select_method`,provider:e}),className:`inline-flex items-center gap-1 border border-[#3a3a3a] bg-transparent px-2 py-1 text-[11px] text-[#d4d4d4] hover:border-[#38bdf8] hover:text-[#38bdf8]`,children:[(0,U.jsx)(`span`,{children:e.name}),e.configured?(0,U.jsx)(`span`,{className:`text-[#22c55e]`,children:`●`}):null]},e.id))})]}):i.type===`select_method`?(0,U.jsxs)(`div`,{className:`grid gap-2`,children:[(0,U.jsxs)(`div`,{className:`flex items-center gap-2 text-[11px]`,children:[(0,U.jsx)(`span`,{className:`text-[#737373]`,children:`Provider:`}),(0,U.jsx)(`span`,{className:`text-[#d4d4d4]`,children:i.provider.name}),i.provider.configured?(0,U.jsx)(_4,{tone:`green`,children:`Configured`}):(0,U.jsx)(_4,{tone:`neutral`,children:`Not configured`})]}),(0,U.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:i.provider.authMethods.map(e=>(0,U.jsxs)(`button`,{type:`button`,onClick:()=>e===`api_key`?a({type:`api_key`,provider:i.provider}):void _(i.provider,e),className:`inline-flex items-center gap-1 border border-[#3a3a3a] bg-transparent px-2 py-1 text-[11px] text-[#d4d4d4] hover:border-[#38bdf8] hover:text-[#38bdf8]`,children:[e===`api_key`?(0,U.jsx)(Dc,{size:11}):(0,U.jsx)(Ic,{size:11}),BVe[e]]},e))})]}):i.type===`device_starting`?(0,U.jsxs)(`div`,{className:`inline-flex items-center gap-2 text-[11px] text-[#38bdf8]`,children:[(0,U.jsx)(Pc,{size:13,className:`animate-spin`}),` Starting device login...`]}):i.type===`device_flow`?(0,U.jsxs)(`div`,{className:`grid gap-2 text-[11px]`,children:[(0,U.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,U.jsx)(`span`,{className:`text-[#737373]`,children:`Open:`}),(0,U.jsxs)(`a`,{href:i.url,target:`_blank`,rel:`noreferrer`,className:`inline-flex items-center gap-1 text-[#38bdf8] hover:underline`,children:[WVe(i.url),` `,(0,U.jsx)(fc,{size:11})]}),(0,U.jsxs)(`button`,{type:`button`,onClick:()=>void g(i.url),className:`inline-flex items-center gap-1 border border-[#3a3a3a] px-1.5 py-0.5 text-[#737373] hover:border-[#38bdf8] hover:text-[#38bdf8]`,children:[f===i.url?(0,U.jsx)(tc,{size:10}):(0,U.jsx)(sc,{size:10}),` `,f===i.url?`Copied`:`Copy`]})]}),i.userCode?(0,U.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,U.jsx)(`span`,{className:`text-[#737373]`,children:`Code:`}),(0,U.jsx)(`button`,{type:`button`,onClick:()=>void g(i.userCode),className:`border border-[#1f4960] px-2 py-0.5 font-semibold tracking-widest text-[#38bdf8] hover:border-[#38bdf8]`,children:i.userCode}),(0,U.jsx)(`span`,{className:`text-[#737373]`,children:`then`}),i.completion===`notification`?(0,U.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-[#38bdf8]`,children:[(0,U.jsx)(Pc,{size:11,className:`animate-spin`}),` Waiting for runtime`]}):(0,U.jsxs)(`button`,{type:`button`,disabled:o||!i.flowId,onClick:()=>void v(i.provider,i.flowId),className:`inline-flex items-center gap-1 border border-[#3a3a3a] px-2 py-0.5 text-[#d4d4d4] hover:border-[#38bdf8] hover:text-[#38bdf8] disabled:opacity-50`,children:[o?(0,U.jsx)(Pc,{size:11,className:`animate-spin`}):(0,U.jsx)(tc,{size:11}),` Complete`]})]}):(0,U.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[(0,U.jsx)(`input`,{value:u,autoComplete:`off`,spellCheck:!1,onChange:e=>d(e.target.value),placeholder:`authorization code`,className:`min-w-0 flex-1 border border-[#2a2a2a] bg-[#0b0b0b] px-2 py-1 text-[11px] text-[#d4d4d4] outline-none focus:border-[#38bdf8]`}),(0,U.jsxs)(`button`,{type:`button`,disabled:o||!u.trim()||!i.flowId,onClick:()=>void v(i.provider,i.flowId,u.trim()),className:`inline-flex items-center gap-1 border border-[#3a3a3a] px-2 py-1 text-[#d4d4d4] hover:border-[#38bdf8] hover:text-[#38bdf8] disabled:opacity-50`,children:[o?(0,U.jsx)(Pc,{size:11,className:`animate-spin`}):(0,U.jsx)(tc,{size:11}),` Complete`]})]}),i.instructions?(0,U.jsx)(`div`,{className:`text-[#737373]`,children:i.instructions}):null]}):i.type===`api_key`?(0,U.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5 text-[11px]`,children:[(0,U.jsx)(`span`,{className:`text-[#737373]`,children:`API key:`}),(0,U.jsx)(`input`,{type:`password`,value:c,autoComplete:`off`,spellCheck:!1,onChange:e=>l(e.target.value),onKeyDown:e=>{e.key===`Enter`&&b(i.provider)},placeholder:`sk-...`,className:`min-w-[12rem] flex-1 border border-[#2a2a2a] bg-[#0b0b0b] px-2 py-1 text-[11px] text-[#d4d4d4] outline-none focus:border-[#38bdf8]`}),(0,U.jsxs)(`button`,{type:`button`,disabled:o||!c.trim(),onClick:()=>void b(i.provider),className:`inline-flex items-center gap-1 border border-[#3a3a3a] px-2 py-1 text-[#d4d4d4] hover:border-[#38bdf8] hover:text-[#38bdf8] disabled:opacity-50`,children:[o?(0,U.jsx)(Pc,{size:11,className:`animate-spin`}):(0,U.jsx)(tc,{size:11}),` Save`]})]}):i.type===`success`?(0,U.jsxs)(`div`,{className:`flex items-center gap-2 text-[11px] text-[#22c55e]`,children:[(0,U.jsx)(tc,{size:13}),` `,i.message]}):(0,U.jsxs)(`div`,{className:`flex items-start gap-2 text-[11px] text-[#ef4444]`,children:[(0,U.jsx)($s,{size:13,className:`mt-0.5 shrink-0`}),` `,(0,U.jsx)(`span`,{children:i.message})]})}):(0,U.jsx)(g4,{title:`Login`,tone:`red`,children:`Unparseable login payload.`})}function g4({title:e,tone:t,action:n,children:r}){return(0,U.jsxs)(`div`,{className:`mt-2 border border-[#2a2a2a] bg-[#111111] px-3 py-2 text-[12px] text-[#d4d4d4]`,"data-shared-terminal-card":`login`,children:[(0,U.jsxs)(`div`,{className:`mb-2 flex items-center gap-2`,children:[(0,U.jsx)(Ic,{size:14,className:t===`red`?`text-[#ef4444]`:t===`green`?`text-[#22c55e]`:`text-[#38bdf8]`}),(0,U.jsx)(`span`,{className:`font-semibold text-[#d4d4d4]`,children:e}),n?(0,U.jsx)(`div`,{className:`ml-auto`,children:n}):null]}),r]})}function HVe({onClick:e,disabled:t}){return(0,U.jsxs)(`button`,{type:`button`,disabled:t,onClick:e,className:`inline-flex items-center gap-1 border border-[#3a3a3a] bg-transparent px-1.5 py-0.5 text-[11px] text-[#737373] hover:border-[#38bdf8] hover:text-[#38bdf8] disabled:opacity-50`,children:[(0,U.jsx)(Ms,{size:10}),` Back`]})}function _4({tone:e,children:t}){return(0,U.jsx)(`span`,{className:`border px-1.5 py-0.5 text-[10px] ${e===`green`?`border-[#14532d] text-[#22c55e]`:`border-[#3a3a3a] text-[#737373]`}`,children:t})}function UVe(e){return`provider`in e&&e.provider?e.provider.name:`Login`}function WVe(e){try{let t=new URL(e);return`${t.host}${t.pathname}`}catch{return e.length>42?`${e.slice(0,39)}...`:e}}function GVe({row:e,piboSessionId:t,onModelChanged:n}){let r=h4(e.output),i=(RVe(r)?r:void 0)?.providers??[],a=(0,H.useMemo)(()=>i.flatMap(e=>e.models.map(t=>({...t,providerLabel:e.label,authConfigured:e.authConfigured}))),[i]),[o,s]=(0,H.useState)(``),[c,l]=(0,H.useState)(null),[u,d]=(0,H.useState)(!1),[f,p]=(0,H.useState)(null),m=(0,H.useMemo)(()=>{let e=o.trim().toLowerCase();return e?a.filter(t=>`${t.providerLabel} ${t.provider} ${t.label} ${t.id}`.toLowerCase().includes(e)):a},[a,o]),h=async e=>{if(!(!t||u||e.authConfigured===!1)){d(!0),l(e),p(null);try{await Wl(t,{activeModel:{provider:e.provider,id:e.id}}),p(`Selected ${e.provider}/${e.id}.`),await n?.()}catch(e){p(e instanceof Error?e.message:String(e))}finally{d(!1)}}};return(0,U.jsxs)(`div`,{className:`ml-[1.9rem] max-w-3xl border border-[#3a3a3a] bg-[#111111] text-[12px] shadow-lg`,"data-shared-terminal-card":`model`,children:[(0,U.jsx)(`div`,{className:`flex items-center justify-between gap-3 border-b border-[#2a2a2a] px-3 py-2`,children:(0,U.jsxs)(`div`,{children:[(0,U.jsx)(`div`,{className:`text-[#d4d4d4]`,children:`Model`}),(0,U.jsx)(`div`,{className:`text-[11px] text-[#737373]`,children:`Choose a model exposed by the active runtime.`})]})}),(0,U.jsxs)(`div`,{className:`space-y-2 p-3`,children:[i.length?(0,U.jsxs)(U.Fragment,{children:[(0,U.jsxs)(`label`,{className:`flex items-center gap-2 border border-[#2a2a2a] bg-[#0b0b0b] px-2 py-1 text-[#737373]`,children:[(0,U.jsx)(dl,{size:13}),(0,U.jsx)(`input`,{value:o,onChange:e=>s(e.target.value),placeholder:`Search models`,className:`min-w-0 flex-1 bg-transparent text-[#d4d4d4] outline-none placeholder:text-[#525252]`})]}),(0,U.jsx)(`div`,{className:`max-h-72 overflow-auto border border-[#2a2a2a]`,children:m.length?m.map(e=>(0,U.jsxs)(`button`,{type:`button`,disabled:u||e.authConfigured===!1,onClick:()=>void h(e),className:`grid w-full grid-cols-[150px_1fr_auto] gap-2 border-b border-[#1f1f1f] px-3 py-2 text-left hover:bg-[#38bdf8]/10 disabled:cursor-not-allowed disabled:opacity-50`,children:[(0,U.jsx)(`span`,{className:`truncate text-[#737373]`,children:e.providerLabel}),(0,U.jsxs)(`span`,{className:`min-w-0`,children:[(0,U.jsx)(`span`,{className:`block truncate text-[#d4d4d4]`,children:e.label}),(0,U.jsxs)(`span`,{className:`block truncate text-[11px] text-[#737373]`,children:[e.provider,`/`,e.id]})]}),e.authConfigured===!1?(0,U.jsx)(Ic,{size:13,className:`text-[#737373]`,"aria-label":`Provider authentication missing`}):c?.provider===e.provider&&c?.id===e.id?(0,U.jsx)(Ws,{size:14,className:`text-[#22c55e]`}):null]},`${e.provider}:${e.id}`)):(0,U.jsx)(`div`,{className:`px-3 py-2 text-[#737373]`,children:`No matching models.`})})]}):(0,U.jsx)(`div`,{className:`text-[#737373]`,children:`No models are available for the active runtime.`}),f?(0,U.jsx)(`div`,{className:`text-[11px] text-[#a3a3a3]`,children:f}):null]})]})}var KVe=[[/\bBearer\s+\S+/gi,`Bearer [redacted]`],[/\b(?:sk-(?:proj-)?[A-Za-z0-9_-]{16,}|(?:sk|rk)_(?:live|test)_[A-Za-z0-9]{16,}|gh[pousr]_[A-Za-z0-9_]{16,}|github_pat_[A-Za-z0-9_]{16,}|xox[baprs]-[A-Za-z0-9-]{16,})\b/g,`[redacted]`],[/\beyJ[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]{10,}\b/g,`[redacted]`],[/\b([A-Z0-9_]*(?:ACCESS[_-]?TOKEN|REFRESH[_-]?TOKEN|ID[_-]?TOKEN|API[_-]?KEY|AUTHORIZATION|COOKIE|CREDENTIAL|OAUTH|TOKEN|SECRET|PASSWORD|PASSWD)[A-Z0-9_]*)\b(\s*["']?\s*[:=]\s*["']?)([^\s"'&,;}]+)/gi,`$1$2[redacted]`]];function qVe(e){let t=e;for(let[e,n]of KVe)t=t.replace(e,n);return t}function JVe(e={}){let t=[],n=[],r=b4(e.warnings),i=b4(e.errors);(e.session?.id||e.session?.title)&&t.push({id:`session`,label:`Session`,value:v4([e.session?.title,e.session?.id].filter(Boolean).join(` | `))}),e.session?.profile&&t.push({id:`profile`,label:`Profile`,value:v4(e.session.profile)}),e.session?.status&&t.push({id:`session-status`,label:`Session status`,value:v4(e.session.status),tone:e.session.status===`error`||e.session.status===`disposed`?`red`:`neutral`}),(e.model?.provider||e.model?.id||e.model?.label)&&t.push({id:`model`,label:`Model`,value:v4(e.model.label??[e.model.provider,e.model.id].filter(Boolean).join(`/`))}),e.runtime?.state&&t.push({id:`runtime`,label:`Runtime`,value:v4(e.runtime.state),tone:e.runtime.connected===!1||e.runtime.disposed?`red`:`green`}),e.runtime?.disposed!==void 0&&t.push({id:`disposed`,label:`Disposed`,value:e.runtime.disposed?`yes`:`no`,tone:e.runtime.disposed?`red`:`neutral`}),typeof e.runtime?.queuedMessages==`number`&&t.push({id:`queue`,label:`Queue`,value:String(e.runtime.queuedMessages)}),e.runtime?.processing!==void 0&&t.push({id:`processing`,label:`Processing`,value:e.runtime.processing?`yes`:`no`,tone:e.runtime.processing?`cyan`:`neutral`}),e.runtime?.streaming!==void 0&&t.push({id:`streaming`,label:`Streaming`,value:e.runtime.streaming?`yes`:`no`,tone:e.runtime.streaming?`cyan`:`neutral`}),e.cwd&&t.push({id:`cwd`,label:`CWD`,value:v4(e.cwd)});let a=typeof e.thinking==`string`?{level:e.thinking}:e.thinking;(a?.level||a?.supported!==void 0)&&t.push({id:`thinking`,label:`Thinking`,value:v4(a.level??(a.supported===!1?`unsupported`:`available`)),tone:a.supported===!1?`red`:`yellow`}),e.fastMode!==void 0&&t.push({id:`fast-mode`,label:`Fast mode`,value:typeof e.fastMode==`string`?v4(e.fastMode):e.fastMode?`on`:`off`,tone:e.fastMode?`green`:`neutral`});let o=b4(e.tools?.enabled),s=b4(e.tools?.active);o.length&&t.push({id:`enabled-tools`,label:`Enabled tools`,value:`${o.length}${o.length<=4?` (${o.join(`, `)})`:``}`}),s.length&&t.push({id:`active-tools`,label:`Active tools`,value:`${s.length}${s.length<=4?` (${s.join(`, `)})`:``}`,tone:`cyan`}),e.providerUsage?.planType&&t.push({id:`provider-plan`,label:`Provider plan`,value:v4(e.providerUsage.planType)}),e.providerUsage?.credits&&t.push({id:`provider-credits`,label:`Credits`,value:e.providerUsage.credits.unlimited?`unlimited`:v4(e.providerUsage.credits.balance??`available`)}),e.message&&t.push({id:`message`,label:`Message`,value:v4(e.message)}),n.push(YVe(e.contextUsage));for(let t of XVe(e.providerUsage))n.push(t);return{kind:`status`,title:`Status`,fields:t,progress:n,warnings:r,errors:i}}function v4(e){return qVe(e).replace(/\b([A-Z0-9_]*(?:API[_-]?KEY|TOKEN|SECRET|PASSWORD|PASSWD)[A-Z0-9_]*)\s*:\s*\[redacted\]/gi,`$1=[redacted]`)}function YVe(e){if(!e||e.tokens===void 0&&e.contextWindow===void 0&&e.percent===void 0)return{id:`context`,label:`Context`,state:`unavailable`,text:`Context usage unavailable`,tone:`neutral`};let t=y4(e.percent??(e.tokens!==void 0&&e.contextWindow?e.tokens/e.contextWindow*100:void 0));return{id:`context`,label:`Context`,state:t===void 0?`unavailable`:`available`,value:e.tokens,max:e.contextWindow,percent:t,text:t===void 0?`Context usage unavailable`:`${e.tokens??`?`}/${e.contextWindow??`?`} tokens (${t.toFixed(1)}%)`,tone:ZVe(t)}}function XVe(e){return e?.limits?.length?e.limits.map((t,n)=>{let r=y4(t.usedPercent),i=y4(t.remainingPercent??(r===void 0?void 0:100-r)),a=e.provider?`${e.provider} `:``,o=[i===void 0?void 0:`${i.toFixed(1)}% remaining`,t.resetsAt?`resets ${v4(t.resetsAt)}`:void 0].filter(Boolean).join(`, `);return{id:`provider-${n}`,label:`${a}${t.label??`quota`}`.trim(),state:i===void 0?`unavailable`:`available`,percent:i,text:i===void 0?`Provider usage unavailable`:o,tone:QVe(i)}}):[{id:`provider`,label:`Provider quota`,state:`unavailable`,text:`Provider usage unavailable`,tone:`neutral`}]}function y4(e){if(!(typeof e!=`number`||!Number.isFinite(e)))return Math.max(0,Math.min(100,e))}function ZVe(e){return e===void 0?`neutral`:e>=80?`red`:e>=50?`yellow`:`green`}function QVe(e){return e===void 0?`neutral`:e<=20?`red`:e<=50?`yellow`:`green`}function b4(e){return(e??[]).map(e=>v4(e)).filter(e=>e.length>0)}function x4(e){switch(e.kind){case`tool.status`:return $Ve(e);case`tool.thinking`:return eHe(e);case`tool.model`:return tHe(e);case`tool.login`:return nHe(e);case`tool.call`:case`tool.image`:case`tool.group.exploring`:case`tool.group.images`:return rHe(e);case`yielded.run`:return S4(e,`yielded-run`,`Yielded run`,e.status===`error`?`red`:e.status===`running`?`cyan`:`green`);case`execution.compaction`:return S4(e,`compaction`,e.status===`error`?`Compaction failed`:e.status===`running`?`Compacting`:`Compaction`,e.status===`error`?`red`:`magenta`);case`execution.command`:return S4(e,`command`,`Command`,e.status===`error`?`red`:`yellow`);case`error`:return S4(e,`error`,`Error`,`red`);default:return}}function $Ve(e){let t=C4(e.output),n=w4(t,`activeModel`)??w4(t,`model`),r=JVe({session:{id:D4(t,`piboSessionId`)??D4(t,`sessionId`),title:D4(t,`sessionTitle`)??D4(t,`title`),profile:D4(t,`profile`)??D4(t,`activeAgentId`)??D4(t,`agentId`),status:O4(t,`disposed`)?`disposed`:D4(t,`sessionStatus`)},model:n?{provider:D4(n,`provider`),id:D4(n,`id`),label:D4(n,`label`)}:void 0,runtime:{state:O4(t,`disposed`)?`disposed`:O4(t,`processing`)?`processing`:O4(t,`streaming`)?`streaming`:D4(t,`mode`)??`idle`,connected:O4(t,`connected`),queuedMessages:aHe(t,`queuedMessages`),processing:O4(t,`processing`),streaming:O4(t,`streaming`),disposed:O4(t,`disposed`)},cwd:D4(t,`cwd`),contextUsage:w4(t,`contextUsage`),providerUsage:w4(t,`providerUsage`),tools:{enabled:E4(t,`enabledTools`),active:E4(t,`activeTools`)},thinking:D4(t,`thinkingLevel`)?{level:D4(t,`thinkingLevel`)}:void 0,fastMode:O4(t,`fastMode`),warnings:E4(t,`warnings`),errors:E4(t,`errors`),message:D4(t,`message`)});return{id:e.id,kind:`status`,title:`Status`,status:e.status,tone:e.status===`error`?`red`:`green`,rows:r.fields.map(e=>({label:e.label,value:e.value,tone:e.tone})),statusView:r,sourceRowKind:e.kind}}function eHe(e){let t=C4(e.output),n=D4(t,`level`)??`unknown`,r=t?.supported!==!1,i=E4(t,`availableLevels`);return{id:e.id,kind:`thinking`,title:`Thinking`,status:e.status,tone:r?`yellow`:`red`,rows:[{label:`Current`,value:v4(n)},{label:`Supported`,value:r?`yes`:`no`,tone:r?`green`:`red`}],actions:i.map(e=>({id:`thinking:${e}`,label:e,action:`thinking.set`,value:e,disabled:!r})),sourceRowKind:e.kind}}function tHe(e){let t=T4(C4(e.output),`providers`),n=t.flatMap(e=>{let t=D4(e,`id`)??D4(e,`provider`)??`provider`,n=D4(e,`label`)??D4(e,`name`)??t;return T4(e,`models`).map(e=>{let r=D4(e,`id`)??`model`,i=D4(e,`label`)??r;return{id:`model:${t}:${r}`,label:`${n} / ${i}`,action:`model.select`,value:`${t}/${r}`}})});return{id:e.id,kind:`model`,title:`Model`,status:e.status,tone:n.length?`cyan`:`neutral`,rows:[{label:`Providers`,value:String(t.length)},{label:`Models`,value:String(n.length)}],actions:n,sourceRowKind:e.kind}}function nHe(e){let t=T4(C4(e.output),`providers`),n=t.map(e=>{let t=D4(e,`id`)??`provider`;return{id:`login:${t}`,label:D4(e,`name`)??D4(e,`label`)??t,action:`login.selectProvider`,value:t,description:E4(e,`authMethods`).join(`, `)}});return{id:e.id,kind:`login`,title:`Login`,status:e.status,tone:n.length?`cyan`:`neutral`,rows:[{label:`Providers`,value:String(t.length)}],actions:n,sourceRowKind:e.kind}}function rHe(e){return S4(e,`tool`,e.kind===`tool.group.exploring`?`Exploring`:e.kind===`tool.image`||e.kind===`tool.group.images`?`Image`:`Tool`,e.status===`error`?`red`:e.status===`running`?`cyan`:`green`)}function S4(e,t,n,r){let i=e.lines.flatMap(e=>{let t=`${e.tokens.map(e=>e.text).join(``)}${e.functionCall?`${e.functionCall.name}${e.functionCall.input===void 0?``:` ${iHe(e.functionCall.input)}`}`:``}`.trim();return t?[{value:v4(t)}]:[]}),a=e.lines.length===0&&typeof e.output==`string`&&e.output.trim()?[{value:v4(e.output.trim())}]:[],o=[e.error?{label:`Error`,value:v4(e.error),tone:`red`}:void 0].filter(e=>!!e);return{id:e.id,kind:t,title:n,status:e.status,tone:r,rows:[...i,...a,...o],sourceRowKind:e.kind}}function iHe(e){try{return JSON.stringify(e)}catch{return String(e)}}function C4(e){if(e){if(typeof e==`string`)try{let t=JSON.parse(e);return t&&typeof t==`object`&&!Array.isArray(t)?t:void 0}catch{return}return typeof e==`object`&&!Array.isArray(e)?e:void 0}}function w4(e,t){let n=e?.[t];return n&&typeof n==`object`&&!Array.isArray(n)?n:void 0}function T4(e,t){let n=e?.[t];return Array.isArray(n)?n.filter(e=>!!e&&typeof e==`object`&&!Array.isArray(e)):[]}function E4(e,t){let n=e?.[t];return Array.isArray(n)?n.filter(e=>typeof e==`string`):[]}function D4(e,t){let n=e?.[t];return typeof n==`string`?n:void 0}function aHe(e,t){let n=e?.[t];return typeof n==`number`&&Number.isFinite(n)?n:void 0}function O4(e,t){let n=e?.[t];return typeof n==`boolean`?n:void 0}var oHe=1e3,sHe={browser_use_open_tabs:`browser_use.open_tabs`,browser_use_take_screenshot:`browser_use.take_screenshot`,browser_use_browser_use:`browser_use.browser_use`,node_repl_js:`node_repl.js`,node_repl_js_reset:`node_repl.js_reset`};function cHe(e,t){if(!e)return[];let n=j4(e.nodes),r=qHe(M4(e.nodes).sort((e,t)=>yX(e.node,t.node)).filter(e=>e.node.type!==`agent.turn`&&(t.showThinking||e.node.type!==`model.reasoning`)).map(e=>dHe(e.node,e.turnId)));xHe(r,n);let i=pHe(r);return lHe(!t.debugMode&&(t.toolDisplayMode??`default`)==="default"?XHe(i).map(e=>e.row):i.map(e=>e.row),t.toolDisplayMode??`default`)}function lHe(e,t){return t==="default"?e:t===`hide`?e.filter(e=>!k4(e)):e.flatMap(e=>{if(!k4(e))return[e];let n=e.intent?.trim();if(t===`intent`&&!n)return[];let r={...e,lines:e.lines.slice(0,1),input:void 0,output:void 0,error:void 0,markdown:void 0,expandable:!1,singleLine:!0,previewOmission:void 0,detailItems:void 0};return t===`intent`?[{...r,title:void 0,summary:void 0,lines:[{prefix:`bullet`,tokens:[e3(n,e.status===`error`?`red`:e.status===`done`?`green`:`cyan`,`semibold`)]}]}]:[r]})}function k4(e){return e.sourceNodeIds.some(e=>EX(e)!==void 0)||e.id.startsWith(`terminal:tool:`)||e.kind===`tool.call`||e.kind===`tool.image`||e.kind===`tool.group.exploring`||e.kind===`tool.group.images`||e.kind===`agent.delegation`}function uHe(e){if(!e)return;let t=new Set(M4(e.nodes).map(({node:e})=>e).filter(e=>e.type===`error`&&e.eventId).map(e=>e.eventId));return[...j4(e.nodes).values()].filter(e=>e.startedAt&&!e.completedAt&&(!e.eventId||!t.has(e.eventId))).sort(yX).at(-1)?.startedAt}function A4(e){let t=Math.max(0,Math.floor(e/1e3));return[Math.floor(t/3600),Math.floor(t%3600/60),t%60].map(e=>String(e).padStart(2,`0`)).join(`:`)}function j4(e){let t=new Map;for(let n of e){n.type===`agent.turn`&&t.set(n.id,n);for(let[e,r]of j4(n.children))t.set(e,r)}return t}function M4(e,t){let n=[];for(let r of e)r.type!==`agent.turn`&&n.push({node:r,turnId:t}),n.push(...M4(r.children,r.type===`agent.turn`?r.id:t));return n}function dHe(e,t){let n;switch(e.type){case`user.message`:n={row:wHe(e),turnId:t};break;case`assistant.message`:n={row:THe(e),turnId:t};break;case`model.reasoning`:n={row:EHe(e),turnId:t};break;case`tool.call`:n=DHe(e,t);break;case`tool.result`:n=kHe(e,t);break;case`agent.delegation`:n={row:jHe(e),turnId:t};break;case`agent.async`:n={row:MHe(e),turnId:t};break;case`yielded.run`:n={row:NHe(e),turnId:t};break;case`execution.command`:n={row:FHe(e),turnId:t};break;case`execution.compaction`:n={row:PHe(e),turnId:t};break;case`error`:n={row:GHe(e),turnId:t};break;case`agent.turn`:n={row:{id:e.id,kind:`error`,status:`neutral`,lines:[],sourceNodeIds:[e.id]},turnId:t}}return{...n,row:{...n.row,id:fHe(e),intent:e.intent,isToolCall:e.type===`tool.call`||e.type===`tool.result`||e.type===`agent.delegation`&&!!e.toolCallId,toolMetrics:e.toolMetrics,...CHe(e)}}}function fHe(e){if(e.type===`tool.call`||e.type===`tool.result`||e.type===`agent.delegation`){if(e.toolCallId)return EX(e.id)?.qualifier?`terminal:${e.id}`:`terminal:tool:${e.toolCallId}`;if(e.type===`agent.delegation`&&e.linkedPiboSessionId)return`terminal:delegation:${e.linkedPiboSessionId}`}if((e.type===`agent.async`||e.type===`yielded.run`)&&e.runId)return`terminal:run:${e.runId}`;if(e.type===`assistant.message`){let t=N4(e.stableKey,`assistant:`);if(t)return`terminal:assistant:${t}`}if(e.type===`model.reasoning`){let t=N4(e.stableKey,`reasoning:`);if(t)return`terminal:reasoning:${t}`}return e.id}function N4(e,t){if(!e?.startsWith(t))return;let n=e.slice(t.length);return n&&n!==`undefined`?n:void 0}function pHe(e){let t=[],n=new Map;for(let r of e){let e=n.get(r.row.id);if(e===void 0){n.set(r.row.id,t.length),t.push(r);continue}let i=t[e];t[e]={...r,turnId:r.turnId??i.turnId,row:{...i.row,...r.row,sourceNodeIds:[...new Set([...i.row.sourceNodeIds,...r.row.sourceNodeIds])],intent:r.row.intent??i.row.intent,input:r.row.input??i.row.input,output:r.row.output??i.row.output,error:r.row.error??i.row.error,payloadRefs:{...i.row.payloadRefs,...r.row.payloadRefs},imagePreviews:bHe(i.row.imagePreviews,r.row.imagePreviews)}}}return mHe(t)}function mHe(e){let t=new Map;for(let n=0;n<e.length;n+=1){let r=e[n].row,i=gHe(r)?`canonical`:_He(r)?`fallback`:void 0,a=yHe(r.id);if(!i||a===void 0||typeof r.output!=`string`)continue;let o=`${a}\0${r.output}`,s=t.get(o)??{canonical:[],fallback:[]};s[i].push(n),t.set(o,s)}let n=[...e],r=new Set;for(let e of t.values()){if(e.canonical.length!==1||e.fallback.length!==1)continue;let t=e.canonical[0],i=e.fallback[0],a=n[t],o=n[i];vHe(a.row,o.row)&&(n[t]=hHe(a,o),r.add(i))}return n.filter((e,t)=>!r.has(t))}function hHe(e,t){return{...t,...e,turnId:e.turnId??t.turnId,row:{...t.row,...e.row,sourceNodeIds:[...new Set([...e.row.sourceNodeIds,...t.row.sourceNodeIds])],completedAt:e.row.completedAt??t.row.completedAt,durationMs:e.row.durationMs??t.row.durationMs,payloadRefs:{...t.row.payloadRefs,...e.row.payloadRefs}}}}function gHe(e){let t=e.eventId;return e.kind===`message.assistant`&&e.status===`done`&&e.orderSource===`event-log`&&t!==void 0&&!t.startsWith(`native-history-group:`)}function _He(e){return e.kind===`message.assistant`&&e.status===`done`&&e.orderSource===`transcript`&&e.eventId?.startsWith(`native-history-group:`)===!0}function vHe(e,t){let n=Date.parse(e.completedAt??e.startedAt??``),r=Date.parse(t.completedAt??t.startedAt??``);return Number.isFinite(n)&&Number.isFinite(r)&&Math.abs(n-r)<=oHe}function yHe(e){let t=e.match(/:assistant:(\d+)$/);if(!t)return;let n=Number(t[1]);return Number.isSafeInteger(n)?n:void 0}function bHe(e,t){if(!e?.length)return t?.slice(0,20);if(!t?.length)return e.slice(0,20);let n=new Map(e.map(e=>[e.id,e]));for(let e of t)if(n.set(e.id,{...n.get(e.id),...e}),n.size>=20)break;return[...n.values()]}function xHe(e,t){for(let n of t.values()){if(!n.completedAt)continue;let t=e.filter(e=>e.turnId===n.id).at(-1);t?.row.kind===`message.assistant`&&t.row.status!==`running`&&(t.row.startedAt=n.startedAt,t.row.completedAt=n.completedAt,t.row.durationMs=n.durationMs??SHe(n.startedAt,n.completedAt))}}function SHe(e,t){if(!e||!t)return;let n=new Date(e).getTime(),r=new Date(t).getTime();return Number.isFinite(n)&&Number.isFinite(r)?Math.max(0,r-n):void 0}function CHe(e){return{eventId:e.eventId,runId:e.runId,orderSource:e.source,orderStreamId:e.orderKey?.streamId,orderStreamFrameIndex:e.orderKey?.streamFrameIndex,payloadRefs:e.payloadRefs}}function wHe(e){let t=t3(e.output)||t3(e.summary)||e.title;return{id:e.id,kind:`message.user`,status:Q4(e.status),lines:[{prefix:`prompt`,tokens:[e3(t)]}],sourceNodeIds:[e.id],forkEntryId:e.entryId,pendingMessageDelivery:yUe(e),startedAt:e.startedAt,output:t,payloadRefs:e.payloadRefs}}function THe(e){return{id:e.id,kind:`message.assistant`,status:Q4(e.status),lines:[],sourceNodeIds:[e.id],startedAt:e.startedAt,completedAt:e.source===`transcript`||e.source===`product-history`?e.completedAt:void 0,durationMs:e.source===`transcript`||e.source===`product-history`?e.durationMs:void 0,output:t3(e.output)||t3(e.summary)||``,error:e.error,payloadRefs:e.payloadRefs}}function EHe(e){let t=q4(e.output??e.summary);return{id:e.id,kind:`reasoning`,status:Q4(e.status),lines:[{prefix:`bullet`,tokens:[e3(e.status===`running`?`Thinking`:`Thought`,`amber`,`semibold`)]}],sourceNodeIds:[e.id],markdown:t,payloadRefs:e.payloadRefs}}function DHe(e,t){let n=Z4(e.input);if(n&&oUe(e.title))return{row:WHe(e,n),turnId:t,exploring:void 0};if(sUe(e.title))return{row:OHe(e),turnId:t};let r=L4(e);if(r)return{row:P4(e,r),turnId:t,image:r.groupable?r.detail:void 0};let i=G4(e.error??e.output,5,e.error?`red`:`dim`);return{row:{id:e.id,kind:`tool.call`,status:Q4(e.status),errorKind:e.status===`error`?`tool`:void 0,lines:[{prefix:`bullet`,tokens:[e3(_Ue(e.status),$4(e.status),`semibold`),e3(` `)],functionCall:{name:B4(e.title),input:e.input}},...i.lines],sourceNodeIds:[e.id],input:e.input,output:e.output,error:e.error,expandable:e.input!==void 0||e.output!==void 0||!!e.error,previewOmission:K4(i,e.error?`error`:`output`)},turnId:t,exploring:aUe(e)}}function OHe(e){let t=Q4(e.status),n=lUe(e),r=uUe(e),i=dUe(e),a=fUe(e),o=pUe(e),s=mUe(e.output),c=hUe(e.output),l=[{prefix:`bullet`,tokens:[e3(cUe(e.status,n),$4(e.status),e.status===`error`?`bold`:`semibold`)]}];r?l.push({prefix:`detail`,tokens:[e3(`query: ${JSON.stringify(r)}`,`cyan`)]}):i?.length&&l.push({prefix:`detail`,tokens:[e3(`queries: ${JSON.stringify(i)}`,`cyan`)]}),a&&l.push({prefix:`detail`,tokens:[e3(`page: `,`dim`),X4(a,`Open web page: ${a}`)]}),o&&l.push({prefix:`detail`,tokens:[e3(`find: ${JSON.stringify(o)}`,`cyan`)]}),e.status===`done`&&c!==void 0&&l.push({prefix:`detail`,tokens:[e3(`sources: ${c}`,`dim`)]});let u=s.slice(0,3);for(let e of u)l.push({prefix:`detail`,tokens:[...e.title?[e3(`${e.title}: `,`dim`)]:[],X4(e.url,`Open source: ${e.title??e.url}`)]});let d=Math.max(0,(c??s.length)-u.length);return u.length>0&&d>0&&l.push({prefix:`detail`,tokens:[e3(`+${d} more sources`,`dim`)]}),e.status===`error`&&e.error&&l.push({prefix:`detail`,tokens:[e3(e.error,`red`)]}),{id:e.id,kind:`tool.call`,status:t,errorKind:e.status===`error`?`tool`:void 0,lines:l,sourceNodeIds:[e.id],input:e.input,output:e.output,error:e.error,expandable:e.input!==void 0||e.output!==void 0||!!e.error}}function P4(e,t){let n=Q4(e.status),r=t.path?`Path: ${t.path}`:t.artifactId?`Artifact: ${t.artifactId}`:t.query?`Query: ${t.query}`:t.mimeType?`Type: ${t.mimeType}`:`Image content returned`;return{id:e.id,kind:`tool.image`,status:n,errorKind:e.status===`error`?`tool`:void 0,lines:[{prefix:`bullet`,tokens:[e3(t.verb,$4(e.status),`semibold`)]},{prefix:`detail`,tokens:[e3(r,e.status===`error`?`red`:`cyan`)]}],sourceNodeIds:[e.id],input:z4(e.input),output:t.summary,error:e.error,expandable:e.input!==void 0||t.summary!==void 0||!!e.error,imagePreviews:t.previews}}function kHe(e,t){let n=L4(e);return n?{row:P4(e,n),turnId:t,image:n.groupable?n.detail:void 0}:{row:AHe(e),turnId:t}}function AHe(e){let t=G4(e.error??e.output,5,e.error?`red`:`dim`);return{id:e.id,kind:`tool.call`,status:Q4(e.status),errorKind:e.status===`error`?`tool`:void 0,lines:[{prefix:`bullet`,tokens:[e3(e.status===`error`?`Tool failed`:`Returned`,$4(e.status),`semibold`),e3(` ${B4(e.title)}`)]},...t.lines],sourceNodeIds:[e.id],output:e.output,error:e.error,expandable:e.output!==void 0||!!e.error,previewOmission:K4(t,e.error?`error`:`output`)}}function jHe(e){let t=t3(n3(e.input)?e.input.subagentName:void 0)||e.summary||e.title,n=J4((n3(e.input)?e.input.arguments:void 0)??e.input),r=n?[{prefix:`detail`,tokens:[e3(n,`dim`)]}]:[];return{id:e.id,kind:`agent.delegation`,status:Q4(e.status),errorKind:e.status===`error`?`tool`:void 0,title:e.title,summary:e.summary,lines:[{prefix:`bullet`,tokens:[e3(vUe(e.status),$4(e.status),`semibold`),e3(` ${t}`,`cyan`)]},...r],sourceNodeIds:[e.id],linkedPiboSessionId:e.linkedPiboSessionId,startedAt:e.startedAt,completedAt:e.completedAt,durationMs:e.durationMs,input:e.input,output:e.output,error:e.error,expandable:e.input!==void 0||e.output!==void 0||!!e.error}}function MHe(e){let t=G4(e.error??e.output,5,e.error?`red`:`dim`);return{id:e.id,kind:`agent.async`,status:Q4(e.status),lines:[{prefix:`bullet`,tokens:[e3(bUe(e.status),$4(e.status),`semibold`),e3(` ${e.title}`,`cyan`)]},...t.lines],sourceNodeIds:[e.id],linkedPiboSessionId:e.linkedPiboSessionId,input:e.input,output:e.output,error:e.error,expandable:e.input!==void 0||e.output!==void 0||!!e.error,previewOmission:K4(t,e.error?`error`:`output`)}}function NHe(e){let t=G4(e.output,5);return{id:e.id,kind:`yielded.run`,status:Q4(e.status),errorKind:e.status===`error`?`tool`:void 0,lines:[{prefix:`bullet`,tokens:[e3(e.status===`running`?`Waiting on runs`:`Run update`,$4(e.status),`semibold`),e3(e.summary?` ${e.summary}`:``)]},...t.lines],sourceNodeIds:[e.id],output:e.output,error:e.error,expandable:e.output!==void 0||!!e.error,previewOmission:K4(t,`output`)}}function PHe(e){let t=e.status===`running`?`Compacting`:e.status===`error`?`Compaction failed`:t3(e.summary)||`Compacted`;return{id:e.id,kind:`execution.compaction`,status:Q4(e.status),lines:[{prefix:`bullet`,tokens:[e3(t,$4(e.status),e.status===`error`?`bold`:`semibold`)]}],sourceNodeIds:[e.id],input:e.input,output:e.output,error:e.error,expandable:e.input!==void 0||e.output!==void 0||!!e.error}}function FHe(e){if(e.title===`status`)return IHe(e);if(e.title===`thinking`)return YHe(e.output)?RHe(e):LHe(e);if(e.title===`fast_mode`)return zHe(e);if(e.title===`login`&&HHe(e.output))return BHe(e);if(e.title===`model`&&UHe(e.output))return VHe(e);Z4(e.output)??Z4(e.input)??e.title;let t=G4(e.error??e.output,5,e.error?`red`:`dim`,180);return{id:e.id,kind:`execution.command`,status:Q4(e.status),lines:[{prefix:`bullet`,tokens:[e3(`Command`,`yellow`,`semibold`),e3(` /${e.title}`,`yellow`)]},...t.lines],sourceNodeIds:[e.id],input:e.input,output:e.output,error:e.error,expandable:e.input!==void 0||e.output!==void 0||!!e.error,previewOmission:K4(t,e.error?`error`:`output`)}}function IHe(e){return{id:e.id,kind:`tool.status`,status:Q4(e.status),lines:[],sourceNodeIds:[e.id],input:e.input,output:e.output,error:e.error,expandable:!1}}function LHe(e){return{id:e.id,kind:`tool.thinking`,status:Q4(e.status),lines:[],sourceNodeIds:[e.id],input:e.input,output:e.output,error:e.error,expandable:!1}}function RHe(e){let t=n3(e.output)?e.output:void 0,n=t3(t?.level),r=t?.changed!==!1,i=t?.supported!==!1,a=i?n?r?`Thinking level set to ${n}.`:`Thinking level is already ${n}.`:`Thinking level updated.`:`Thinking level is not supported by this model.`;return{id:e.id,kind:`execution.command`,status:Q4(e.status),lines:[{prefix:`bullet`,tokens:[e3(a,i?`green`:`dim`,`semibold`)]}],sourceNodeIds:[e.id],input:e.input,output:e.output,error:e.error,expandable:!1}}function zHe(e){let t=n3(e.output)?e.output:void 0,n=t?.mode===`fast`?`fast`:t?.mode===`normal`?`normal`:void 0,r=t?.changed!==!1,i=t?.supported!==!1,a=i?n===`fast`?r?`Switched to Fast mode.`:`Fast mode is already on.`:n===`normal`?r?`Switched to Normal mode.`:`Normal mode is already on.`:`Fast mode updated.`:`Fast mode is not supported by this model.`;return{id:e.id,kind:`execution.command`,status:Q4(e.status),lines:[{prefix:`bullet`,tokens:[e3(a,i?`green`:`dim`,`semibold`)]}],sourceNodeIds:[e.id],input:e.input,output:e.output,error:e.error,expandable:!1}}function BHe(e){return{id:e.id,kind:`tool.login`,status:Q4(e.status),lines:[],sourceNodeIds:[e.id],input:e.input,output:e.output,error:e.error,expandable:!1}}function VHe(e){return{id:e.id,kind:`tool.model`,status:Q4(e.status),lines:[],sourceNodeIds:[e.id],input:e.input,output:e.output,error:e.error,expandable:!1}}function HHe(e){if(!e||typeof e!=`object`||Array.isArray(e))return!1;let t=e;return t.action===`show_login_menu`&&Array.isArray(t.providers)}function UHe(e){if(!e||typeof e!=`object`||Array.isArray(e))return!1;let t=e;return t.action===`show_model_menu`&&Array.isArray(t.providers)}function WHe(e,t){let n=G4(e.error??e.output,5,e.error?`red`:`dim`,180);return{id:e.id,kind:`execution.command`,status:Q4(e.status),errorKind:e.status===`error`?`tool`:void 0,lines:[{prefix:`bullet`,tokens:[e3(e.status===`running`?`Running`:`Ran`,$4(e.status),`semibold`),e3(` `),...gUe(t)]},...n.lines],sourceNodeIds:[e.id],input:e.input,output:e.output,error:e.error,expandable:e.input!==void 0||e.output!==void 0||!!e.error,previewOmission:K4(n,e.error?`error`:`output`)}}function GHe(e){return{id:e.id,kind:`error`,status:`error`,errorKind:`system`,lines:[{prefix:`bullet`,tokens:[e3(e.title||`Error`,`red`,`bold`),e3(e.error?` ${e.error}`:``,`red`)]},...KHe(e.input)],sourceNodeIds:[e.id],input:e.input,error:e.error,output:e.output,expandable:e.input!==void 0||e.output!==void 0||!!e.error}}function KHe(e){return n3(e)?[[`Class`,t3(e.errorClass)??t3(e.category)],[`Code`,t3(e.code)??t3(e.providerCode)],[`Origin`,t3(e.origin)],[`Provider`,[t3(e.api),t3(e.provider),t3(e.model)].filter(Boolean).join(` / `)||void 0],[`Retryable`,typeof e.retryable==`boolean`?e.retryable?`yes`:`no`:void 0]].filter(e=>typeof e[1]==`string`&&e[1].length>0).map(([e,t],n)=>({prefix:n===0?`detail`:`continuation`,tokens:[e3(`${e}: `,`dim`),e3(t,`red`)]})):[]}function qHe(e){let t=e.map(e=>e.row.output).filter(JHe).at(-1);return t?e.map(e=>e.row.kind!==`tool.thinking`||!n3(e.row.output)?e:{...e,row:{...e.row,output:{...e.row.output,level:t.level,availableLevels:t.availableLevels,supported:t.supported}}}):[...e]}function JHe(e){return n3(e)&&typeof e.level==`string`&&Array.isArray(e.availableLevels)}function YHe(e){return n3(e)&&e.action===`set_thinking_level`}function XHe(e){let t=[];for(let n=0;n<e.length;n+=1){let r=e[n],i=F4(r);if(!i){t.push(r);continue}let a=[r],o=n+1;for(;o<e.length&&F4(e[o])===i&&e[o].turnId===r.turnId;)a.push(e[o]),o+=1;if(a.length===1){t.push(r);continue}t.push({row:i===`images`?QHe(a):ZHe(a),turnId:r.turnId}),n=o-1}return t}function F4(e){if(e.image)return`images`;if(e.exploring)return`exploring`}function ZHe(e){let t=I4(e,`exploring`),n=t.slice(0,6),r=Math.max(0,t.length-n.length),i=e[0]?.row,a=i?.id??`exploring`,o=e[e.length-1]?.row.id??a,s=e.some(e=>e.row.status===`running`)?`running`:e.some(e=>e.row.status===`error`)?`error`:`done`;return{id:`group:exploring:${a}:${o}`,kind:`tool.group.exploring`,status:s,errorKind:s===`error`?`tool`:void 0,lines:[{prefix:`bullet`,tokens:[e3(s===`running`?`Exploring`:s===`error`?`Exploring failed`:`Explored`,$4(s),`semibold`)]},...n.map((e,t)=>({prefix:t===0?`detail`:`continuation`,tokens:[e3(e.label,e.status===`error`?`red`:`dim`)]})),...r>0?[{prefix:`continuation`,tokens:[e3(`+${r} more explorations`,`dim`,`normal`,!0)]}]:[]],sourceNodeIds:e.flatMap(e=>e.row.sourceNodeIds),eventId:i?.eventId,runId:i?.runId,orderSource:i?.orderSource,orderStreamId:i?.orderStreamId,orderStreamFrameIndex:i?.orderStreamFrameIndex,detailItems:t,expandable:t.some(e=>e.input!==void 0||e.output!==void 0||!!e.error),previewOmission:r>0?{source:`details`,visibleLineCount:n.length,omittedLineCount:r,totalLineCount:t.length,maxVisibleLineCount:6}:void 0}}function QHe(e){let t=I4(e,`images`),n=t.slice(0,6),r=Math.max(0,t.length-n.length),i=e[0]?.row,a=i?.id??`images`,o=e[e.length-1]?.row.id??a,s=e.some(e=>e.row.status===`running`)?`running`:e.some(e=>e.row.status===`error`)?`error`:`done`;return{id:`group:images:${a}:${o}`,kind:`tool.group.images`,status:s,errorKind:s===`error`?`tool`:void 0,lines:[{prefix:`bullet`,tokens:[e3(s===`running`?`Viewing images`:s===`error`?`Image reads failed`:`Viewed images`,$4(s),`semibold`)]},...n.map((e,t)=>({prefix:t===0?`detail`:`continuation`,tokens:[e3(e.label,e.status===`error`?`red`:`cyan`)]})),...r>0?[{prefix:`continuation`,tokens:[e3(`+${r} more image reads`,`dim`,`normal`,!0)]}]:[]],sourceNodeIds:e.flatMap(e=>e.row.sourceNodeIds),eventId:i?.eventId,runId:i?.runId,orderSource:i?.orderSource,orderStreamId:i?.orderStreamId,orderStreamFrameIndex:i?.orderStreamFrameIndex,detailItems:t,expandable:t.some(e=>e.input!==void 0||e.output!==void 0||!!e.error),imagePreviews:t.flatMap(e=>e.imagePreviews??[]).slice(0,20),previewOmission:r>0?{source:`details`,visibleLineCount:n.length,omittedLineCount:r,totalLineCount:t.length,maxVisibleLineCount:6}:void 0}}function I4(e,t){return e.map(e=>{let n=t===`images`?e.image:e.exploring;return{id:e.row.id,label:n?.label??e.row.lines[0]?.tokens.map(e=>e.text).join(``)??e.row.id,status:e.row.status,input:e.row.input,output:e.row.output,error:e.row.error,payloadRefs:e.row.payloadRefs,linkedPiboSessionId:e.row.linkedPiboSessionId,previewOmission:e.row.previewOmission,imagePreviews:e.row.imagePreviews}})}function L4(e){let t=(e.title??``).trim().toLowerCase(),n=n3(e.input)?e.input:void 0,r=n3(e.output)?e.output:void 0,i=iUe(r,`details`),a=t===`codex_image_generation`?tUe(i)??nUe(n):void 0,o=a?t3(i?.savedPath)??H4(i):H4(n)??H4(i)??H4(r),s=a?t3(i?.artifactId):void 0,c=U4(n),l=R4(e.output).slice(0,20),u=e.payloadRefs?.output,d=Math.min(u?.imageCount??0,20),f=V4(t,[`view_image`,`image`,`screenshot`])||t===`read`&&$He(o);if(!l.length&&!d&&!f&&!a)return;let p=l.map(e=>e.mimeType).find(e=>!!e),m=Math.max(1,l.length,d),h={type:m>1?`images`:l.length===1?`image`:`image_reference`,toolName:a?e.title:void 0,operation:a,path:o,savedPath:a?o:void 0,artifactId:s,model:a?t3(i?.model):void 0,referencedImageCount:a?W4(i?.referencedImageCount):void 0,query:c,mimeType:p,count:m>1?m:void 0,detail:l.length||d?`Image data hidden in terminal view.`:`Image path only; binary data is hidden in terminal view.`},g=o??s??c??p??`image`,_=a?rUe(e.status,a):eUe(e.status,m),v=l.length?l:Array.from({length:Math.max(1,d)},()=>({mimeType:p})),y=v.map((t,n)=>({id:`${e.id}:image:${n}`,label:v.length>1?`${g} (${n+1}/${v.length})`:g,path:o,artifactId:s,payloadRef:u?.ref,payloadImageIndex:u?n:void 0,traceNodeId:u?u.nodeId??e.id:void 0,generatedToolCallId:a?e.toolCallId:void 0,mimeType:t.mimeType??p}));return{count:m,path:o,artifactId:s,query:c,mimeType:p,verb:_,groupable:!a,summary:h,previews:y,detail:{id:e.id,label:`${_} ${g}`,status:Q4(e.status),input:z4(e.input),output:h,error:e.error,imagePreviews:y}}}function $He(e){return e?/\.(?:png|jpe?g|gif|webp|bmp|avif)$/i.test(e.split(/[?#]/,1)[0]??``):!1}function R4(e,t=0,n=new Set){if(t>5||n.size>=1e3||typeof e!=`object`||!e||n.has(e))return[];if(n.add(e),Array.isArray(e)){let r=[];for(let i of e)if(r.push(...R4(i,t+1,n)),r.length>=20)return r.slice(0,20);return r}let r=e,i=typeof r.type==`string`?r.type.toLowerCase():void 0,a=typeof r.mimeType==`string`?r.mimeType:typeof r.mime_type==`string`?r.mime_type:void 0,o=typeof r.data==`string`||typeof r.image_url==`string`||n3(r.image_url);if((i===`image`||i===`input_image`||i===`output_image`||i===`image_url`)&&(o||a?.startsWith(`image/`))||a?.startsWith(`image/`)&&o)return[{mimeType:a}];let s=[];`content`in r&&s.push(r.content),`message`in r&&s.push(r.message),`result`in r&&s.push(r.result),`output`in r&&s.push(r.output);let c=[];for(let e of s)if(c.push(...R4(e,t+1,n)),c.length>=20)break;return c.slice(0,20)}function z4(e){if(Array.isArray(e))return e.map(z4);if(!n3(e))return e;let t={};for(let[n,r]of Object.entries(e)){if((n===`data`||n===`image_url`)&&typeof r==`string`&&r.length>120){t[n]=`[hidden ${n}]`;continue}t[n]=z4(r)}return t}function eUe(e,t){return e===`running`?t>1?`Viewing images`:`Viewing image`:e===`error`?t>1?`Image reads failed`:`Image read failed`:t>1?`Viewed images`:`Viewed image`}function tUe(e){let t=t3(e?.operation);return t===`generate`||t===`edit`?t:void 0}function nUe(e){if(!e)return;let t=e.referenced_image_paths;return Array.isArray(t)&&t.length>0||W4(e.num_last_images_to_include)!==void 0?`edit`:`generate`}function rUe(e,t){return t===`edit`?e===`running`?`Editing image`:e===`error`?`Image edit failed`:`Edited image`:e===`running`?`Generating image`:e===`error`?`Image generation failed`:`Generated image`}function iUe(e,t){let n=e?.[t];return n3(n)?n:void 0}function aUe(e){let t=(e.title??``).trim().toLowerCase(),n=n3(e.input)?e.input:void 0;if(V4(t,[`read`,`open`]))return{id:e.id,label:`Read ${H4(n)??J4(e.input)}`,status:Q4(e.status),input:e.input,output:e.output,error:e.error};if(V4(t,[`list`,`ls`,`glob`]))return{id:e.id,label:`List ${H4(n)??J4(e.input)}`,status:Q4(e.status),input:e.input,output:e.output,error:e.error};if(V4(t,[`search`,`find`,`grep`,`rg`])){let t=U4(n),r=H4(n);return{id:e.id,label:`Search ${t??J4(e.input)}${r?` in ${r}`:``}`,status:Q4(e.status),input:e.input,output:e.output,error:e.error}}}function B4(e){return sHe[e]??e}function V4(e,t){return t.some(t=>e===t||e.startsWith(`${t}_`)||e.endsWith(`_${t}`)||e.includes(t))}function H4(e){if(e)for(let t of[`path`,`file`,`filePath`,`filepath`,`url`,`uri`,`cwd`,`pattern`,`glob`]){let n=t3(e[t]);if(n)return n}}function U4(e){if(e)for(let t of[`query`,`pattern`,`text`,`name`,`q`,`regex`]){let n=t3(e[t]);if(n)return n}}function W4(e){return typeof e==`number`&&Number.isFinite(e)?e:void 0}function G4(e,t,n=`dim`,r=160){let i={lines:[],visibleLineCount:0,omittedLineCount:0,totalLineCount:0,maxVisibleLineCount:t},a=q4(e);if(!a)return i;let o=a.split(/\r?\n/).map(e=>e.trimEnd()).filter((e,t,n)=>e.length>0||n.length===1);if(!o.length)return i;let s=o.slice(0,t),c=Math.max(0,o.length-s.length),l=s.map((e,t)=>({prefix:t===0?`detail`:`continuation`,tokens:[e3(e,n)]}));return c>0&&l.push({prefix:`continuation`,tokens:[e3(`+${c} more lines`,`dim`,`normal`,!0)]}),{lines:l,visibleLineCount:s.length,omittedLineCount:c,totalLineCount:o.length,maxVisibleLineCount:t}}function K4(e,t){if(!(e.omittedLineCount<=0))return{source:t,visibleLineCount:e.visibleLineCount,omittedLineCount:e.omittedLineCount,totalLineCount:e.totalLineCount,maxVisibleLineCount:e.maxVisibleLineCount}}function q4(e){let t=e4(e);if(t!==void 0)return t.trim();if(typeof e==`string`)return e.trim();if(e==null)return``;try{return JSON.stringify(e,null,2)}catch{return String(e)}}function J4(e){return(typeof e==`string`?e:q4(e)).replace(/\s+/g,` `).trim()}function oUe(e){let t=(e??``).trim().toLowerCase();return t===`shell`||t===`bash`||t===`terminal`}function sUe(e){return(e??``).trim().toLowerCase()===`web_search`}function cUe(e,t){return t===`open_page`?e===`running`?`Opening web page`:e===`error`?`Opening web page failed`:`Opened web page`:t===`find_in_page`?e===`running`?`Finding in web page`:e===`error`?`Finding in web page failed`:`Found in web page`:e===`running`?`Searching web`:e===`error`?`Web search failed`:`Searched web`}function lUe(e){let t=n3(e.input)?e.input:void 0,n=n3(e.output)?e.output:void 0;return t3(t?.actionType)??t3(n?.actionType)}function uUe(e){let t=n3(e.input)?e.input:void 0,n=n3(e.output)?e.output:void 0;return t3(t?.query)??t3(n?.query)??t3(e.summary)}function dUe(e){let t=n3(e.input)?e.input:void 0,n=n3(e.output)?e.output:void 0;for(let e of[t?.queries,n?.queries]){if(!Array.isArray(e))continue;let t=[...new Set(e.flatMap(e=>{let t=t3(e)?.trim();return t?[t]:[]}))];if(t.length)return t}}function fUe(e){let t=n3(e.input)?e.input:void 0,n=n3(e.output)?e.output:void 0;return t3(t?.url)??t3(n?.url)}function pUe(e){let t=n3(e.input)?e.input:void 0,n=n3(e.output)?e.output:void 0;return t3(t?.pattern)??t3(n?.pattern)}function mUe(e){if(!n3(e))return[];let t=e.sources??e.citations??e.results;if(!Array.isArray(t))return[];let n=new Map;for(let e of t){let t=n3(e)?e:void 0,r=Y4(typeof e==`string`?e:t3(t?.url)??t3(t?.href)??t3(t?.link),!0);if(!r)continue;let i=t3(t?.title)?.trim()??t3(t?.name)?.trim(),a=n.get(r);(!a||!a.title&&i)&&n.set(r,{url:r,...i?{title:i}:{}})}return[...n.values()]}function hUe(e){if(!n3(e))return;let t=e.sourceCount??e.sourcesCount;if(typeof t==`number`&&Number.isFinite(t))return t;let n=e.sources??e.citations??e.results;return Array.isArray(n)?n.length:void 0}function Y4(e,t=!1){if(e)try{let n=new URL(e.trim());return n.protocol!==`https:`&&n.protocol!==`http:`||n.username||n.password?void 0:(t&&(n.hash=``),n.href)}catch{return}}function X4(e,t){let n=Y4(e);return{...e3(e,n?`blue`:`dim`),...n?{href:n,ariaLabel:t}:{}}}function Z4(e){if(n3(e))for(let t of[`cmd`,`command`,`script`]){let n=t3(e[t]);if(n)return n}}function gUe(e){let t=e.match(/\s+|"(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|[^\s]+/g)??[e],n=!1;return t.map(e=>/^\s+$/.test(e)?e3(e):/^(?:&&|\|\||[|;<>]|2>&1)$/.test(e)?e3(e,`red`,`semibold`):e.startsWith(`-`)?e3(e,`magenta`):e.startsWith(`$`)||e.includes(`=`)?e3(e,`yellow`):/^['"]/.test(e)?e3(e,`green`):n?e.includes(`/`)||e.startsWith(`.`)?e3(e,`cyan`):e3(e,`default`):(n=!0,e3(e,`green`,`semibold`)))}function _Ue(e){return e===`running`?`Calling`:e===`error`?`Call failed`:`Called`}function vUe(e){return e===`running`?`Spawning`:e===`error`?`Spawn failed`:`Spawned`}function yUe(e){if(e.status===`running`){if(e.id.startsWith(`event:message_steered:`))return`steer`;if(e.id.startsWith(`event:message_queued:`))return`queue`}}function bUe(e){return e===`running`?`Waiting for`:`Finished waiting for`}function Q4(e){return e===`running`?`running`:e===`error`?`error`:`done`}function $4(e){return e===`running`?`cyan`:e===`error`?`red`:e===`done`?`green`:`default`}function e3(e,t=`default`,n=`normal`,r=!1){return{text:e,tone:t,weight:n,italic:r}}function t3(e){return typeof e==`string`&&e.trim().length?e:void 0}function n3(e){return!!e&&typeof e==`object`&&!Array.isArray(e)}function xUe(e){if(!e)return;let t;if(typeof e==`string`)try{t=JSON.parse(e)}catch{return}else typeof e==`object`&&!Array.isArray(e)&&(t=e);if(!t)return;let n=typeof t.contextUsage==`object`&&t.contextUsage!==null?t.contextUsage:void 0,r=typeof t.providerUsage==`object`&&t.providerUsage!==null?t.providerUsage:void 0,i=Array.isArray(r?.limits)?r.limits.filter(e=>!!e&&typeof e==`object`&&!Array.isArray(e)).map(e=>{let t=typeof e.usedPercent==`number`?e.usedPercent:void 0,n=typeof e.remainingPercent==`number`?e.remainingPercent:t===void 0?0:Math.max(0,Math.min(100,100-t));return{label:typeof e.label==`string`?e.label:`limit`,usedPercent:t??0,remainingPercent:n,resetsAt:typeof e.resetsAt==`string`?e.resetsAt:void 0}}):[],a=typeof r?.credits==`object`&&r.credits!==null?r.credits:void 0;return{piboSessionId:typeof t.piboSessionId==`string`?t.piboSessionId:void 0,queuedMessages:typeof t.queuedMessages==`number`?t.queuedMessages:void 0,processing:typeof t.processing==`boolean`?t.processing:void 0,streaming:typeof t.streaming==`boolean`?t.streaming:void 0,enabledTools:Array.isArray(t.enabledTools)?t.enabledTools.filter(e=>typeof e==`string`):Array.isArray(t.activeTools)?t.activeTools.filter(e=>typeof e==`string`):void 0,activeTools:Array.isArray(t.activeTools)?t.activeTools.filter(e=>typeof e==`string`):void 0,enabledSkills:Array.isArray(t.enabledSkills)?t.enabledSkills.filter(e=>typeof e==`string`):void 0,contextFiles:Array.isArray(t.contextFiles)?t.contextFiles.filter(e=>typeof e==`string`):void 0,cwd:typeof t.cwd==`string`?t.cwd:void 0,disposed:typeof t.disposed==`boolean`?t.disposed:void 0,contextUsage:n?{tokens:typeof n.tokens==`number`?n.tokens:void 0,contextWindow:typeof n.contextWindow==`number`?n.contextWindow:void 0,percent:typeof n.percent==`number`?n.percent:void 0}:void 0,providerUsage:r&&(i.length>0||a)?{provider:typeof r.provider==`string`?r.provider:void 0,planType:typeof r.planType==`string`?r.planType:void 0,fetchedAt:typeof r.fetchedAt==`string`?r.fetchedAt:void 0,limits:i,credits:a?{unlimited:a.unlimited===!0,balance:typeof a.balance==`string`?a.balance:void 0}:void 0}:void 0}}function r3(e,t,n){return n?{id:e,label:t,value:n}:void 0}function i3({field:e,icon:t}){let n=t===`session`?Tc:bc;return(0,U.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[11px]`,"data-shared-status-field":e.id,children:[(0,U.jsx)(n,{size:11,className:`shrink-0 text-[#737373]`}),(0,U.jsxs)(`span`,{className:`shrink-0 text-[#737373]`,children:[e.label,`:`]}),(0,U.jsx)(`span`,{className:`truncate font-mono ${e.id===`session`?`text-[#38bdf8]`:`text-[#d4d4d4]`}`,children:e.value})]})}function a3({progress:e,label:t}){let n=e.percent??0,r=e.tone===`red`?`bg-[#ef4444]`:e.tone===`yellow`?`bg-[#facc15]`:e.tone===`cyan`?`bg-[#38bdf8]`:`bg-[#22c55e]`;return(0,U.jsxs)(`div`,{className:`mt-3 space-y-1`,"data-shared-progress":e.id,"data-shared-progress-state":e.state,children:[(0,U.jsxs)(`div`,{className:`flex items-center justify-between text-[11px]`,children:[(0,U.jsx)(`span`,{className:`text-[#737373]`,children:t??e.label}),(0,U.jsx)(`span`,{className:`font-mono text-[#d4d4d4]`,children:e.state===`available`?e.text:`unavailable`})]}),e.state===`available`?(0,U.jsx)(`div`,{className:`h-1.5 w-full overflow-hidden rounded-full bg-[#2a2a2a]`,children:(0,U.jsx)(`div`,{className:`h-full rounded-full ${r} transition-all`,style:{width:`${Math.min(Math.max(n,0),100)}%`}})}):null]})}function SUe(e){if(!e)return;let t=new Date(e);if(!Number.isNaN(t.getTime()))return t.toLocaleString(void 0,{weekday:`short`,hour:`2-digit`,minute:`2-digit`})}function o3({label:e,items:t}){let[n,r]=(0,H.useState)(!1),i=t.length===0;return(0,U.jsxs)(`div`,{children:[(0,U.jsxs)(`button`,{type:`button`,disabled:i,onClick:()=>r(e=>!e),className:`flex items-center gap-1.5 text-[11px] text-[#737373] hover:text-[#d4d4d4] disabled:cursor-default disabled:text-[#525252]`,"aria-expanded":n,children:[(0,U.jsx)(`span`,{className:i?`text-[#525252]`:`text-[#d4d4d4]`,children:n?`▾`:`▸`}),(0,U.jsxs)(`span`,{children:[e,` (`,t.length,`)`]})]}),n?(0,U.jsx)(`div`,{className:`mt-1.5 flex flex-wrap gap-1`,children:t.map(e=>(0,U.jsx)(`span`,{title:e,className:`inline-block max-w-full truncate rounded-sm border border-[#2a2a2a] bg-[#0b0b0b] px-1.5 py-0.5 font-mono text-[11px] text-[#a3a3a3]`,children:e},e))}):null]})}function CUe({row:e,piboSessionId:t}){let[n,r]=(0,H.useState)(null),i=n?.rowId===e.id&&Object.is(n.sourceOutput,e.output)?n.output:e.output,[a,o]=(0,H.useState)(!1),[s,c]=(0,H.useState)(null),l=xUe(i),u=x4(e),d=i===e.output?u:x4({...e,output:i}),f=d?.kind===`status`?d.statusView:void 0,p=async()=>{if(!(!t||a)){o(!0),c(null);try{r({rowId:e.id,sourceOutput:e.output,output:await Jl(t)})}catch(e){c(e instanceof Error?e.message:String(e))}finally{o(!1)}}},m=(0,U.jsx)(`button`,{type:`button`,disabled:!t||a,onClick:()=>void p(),className:`ml-auto inline-flex h-7 w-7 shrink-0 items-center justify-center border border-[#3a3a3a] bg-[#151f24] text-[#737373] transition hover:border-[#38bdf8] hover:text-[#38bdf8] disabled:cursor-not-allowed disabled:opacity-50`,"aria-label":`Refresh status`,"aria-busy":a,title:a?`Refreshing status`:`Refresh status`,"data-pibo-debug":`terminal-status-refresh`,children:(0,U.jsx)(ol,{size:13,className:a?`animate-spin`:void 0})});if(!l||!f)return(0,U.jsxs)(`div`,{className:`mt-2 border border-[#2a2a2a] bg-[#111111] px-3 py-2 text-[12px] text-[#d4d4d4]`,"data-pibo-component":`TerminalStatusCard`,"data-pibo-debug":`terminal-status-card`,"data-shared-terminal-card":`status`,children:[(0,U.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,U.jsx)(`div`,{className:`text-[#737373]`,children:`Status (unparseable)`}),m]}),s?(0,U.jsx)(`div`,{className:`mt-2 text-[11px] text-[#ef4444]`,role:`alert`,children:s}):null]});let h=new Map(f.fields.map(e=>[e.id,e])),g=h.get(`session`)??r3(`session`,`Session`,l.piboSessionId),_=h.get(`cwd`)??r3(`cwd`,`CWD`,l.cwd),v=f.progress.find(e=>e.id===`context`),y=f.progress.filter(e=>e.id.startsWith(`provider`)),b=l.providerUsage?.limits.length?l.providerUsage.limits:void 0,x=l.enabledTools??l.activeTools??[],S=l.enabledSkills??[],C=l.contextFiles??[],w=f.fields.filter(e=>!new Set([`session`,`cwd`]).has(e.id)),T=l.providerUsage?.provider?`${l.providerUsage.provider} quota`:`Provider quota`;return(0,U.jsxs)(`div`,{className:`mt-2 border border-[#2a2a2a] bg-[#111111] px-3 py-2 text-[12px] text-[#d4d4d4]`,"data-pibo-component":`TerminalStatusCard`,"data-pibo-debug":`terminal-status-card`,"data-shared-terminal-card":`status`,children:[(0,U.jsxs)(`div`,{className:`mb-2 flex items-center gap-2`,children:[(0,U.jsx)(Ds,{size:14,className:`text-[#22c55e]`}),(0,U.jsx)(`span`,{className:`font-semibold text-[#d4d4d4]`,children:f.title}),m]}),s?(0,U.jsx)(`div`,{className:`mb-2 text-[11px] text-[#ef4444]`,role:`alert`,children:s}):null,(0,U.jsxs)(`div`,{className:`grid grid-cols-1 gap-1.5 @min-[420px]:grid-cols-2`,children:[g?(0,U.jsx)(i3,{field:g,icon:`session`}):null,_?(0,U.jsx)(i3,{field:_,icon:`cwd`}):null,w.slice(0,8).map(e=>(0,U.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[11px]`,"data-shared-status-field":e.id,children:[(0,U.jsxs)(`span`,{className:`shrink-0 text-[#737373]`,children:[e.label,`:`]}),(0,U.jsx)(`span`,{className:`truncate font-mono text-[#d4d4d4]`,children:e.value})]},e.id))]}),(0,U.jsxs)(`div`,{className:`mt-2 flex flex-wrap gap-1.5`,children:[l.processing?(0,U.jsxs)(`span`,{className:`inline-flex items-center gap-1 border border-[#1f4960] px-1.5 py-0.5 text-[11px] text-[#38bdf8]`,children:[(0,U.jsx)(cc,{size:10}),` Processing`]}):null,l.streaming?(0,U.jsxs)(`span`,{className:`inline-flex items-center gap-1 border border-[#1f4960] px-1.5 py-0.5 text-[11px] text-[#38bdf8]`,children:[(0,U.jsx)(Ds,{size:10}),` Streaming`]}):null,typeof l.queuedMessages==`number`&&l.queuedMessages>0?(0,U.jsxs)(`span`,{className:`inline-flex items-center gap-1 border border-[#3a3a3a] px-1.5 py-0.5 text-[11px] text-[#d4d4d4]`,children:[(0,U.jsx)(kc,{size:10}),` Queued: `,l.queuedMessages]}):null,l.disposed?(0,U.jsx)(`span`,{className:`inline-flex items-center gap-1 border border-[#5f2222] px-1.5 py-0.5 text-[11px] text-[#ef4444]`,children:`Disposed`}):null]}),v?(0,U.jsx)(a3,{progress:v,label:`Context Usage`}):null,y.length?(0,U.jsxs)(`div`,{className:`mt-3 space-y-1.5 border-t border-[#2a2a2a] pt-2`,"data-shared-provider-progress":y.length,children:[(0,U.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[11px] text-[#737373]`,"data-shared-status-field":`provider-quota`,children:[(0,U.jsx)(xc,{size:11}),(0,U.jsxs)(`span`,{children:[T,l.providerUsage?.planType?` (${l.providerUsage.planType})`:``]})]}),b?b.map(e=>{let t=SUe(e.resetsAt);return(0,U.jsxs)(`div`,{className:`space-y-1`,"data-shared-progress":`provider-limit:${e.label}`,"data-shared-progress-state":`available`,children:[(0,U.jsxs)(`div`,{className:`flex items-center justify-between gap-2 text-[11px]`,children:[(0,U.jsx)(`span`,{className:`text-[#a3a3a3]`,children:e.label}),(0,U.jsxs)(`span`,{className:`shrink-0 font-mono text-[#d4d4d4]`,children:[e.remainingPercent.toFixed(0),`% left`,t?` · resets ${t}`:``]})]}),(0,U.jsx)(`div`,{className:`h-1.5 w-full overflow-hidden rounded-full bg-[#2a2a2a]`,children:(0,U.jsx)(`div`,{className:`h-full rounded-full bg-[#38bdf8] transition-all`,style:{width:`${Math.min(Math.max(e.remainingPercent,0),100)}%`}})})]},`${e.label}-${e.resetsAt??``}`)}):y.map(e=>(0,U.jsx)(a3,{progress:e},e.id)),l.providerUsage?.credits?(0,U.jsxs)(`div`,{className:`text-[11px] text-[#a3a3a3]`,"data-shared-status-field":`provider-credits`,children:[`Credits: `,l.providerUsage.credits.unlimited?`unlimited`:l.providerUsage.credits.balance??`available`]}):null]}):null,f.warnings.length||f.errors.length?(0,U.jsxs)(`div`,{className:`mt-3 space-y-1 border-t border-[#2a2a2a] pt-2`,children:[f.warnings.map((e,t)=>(0,U.jsxs)(`div`,{"data-shared-status-warning":!0,className:`text-[11px] text-[#facc15]`,children:[`⚠ `,e]},`warning-${t}`)),f.errors.map((e,t)=>(0,U.jsxs)(`div`,{"data-shared-status-error":!0,className:`text-[11px] text-[#ef4444]`,children:[`✕ `,e]},`error-${t}`))]}):null,(0,U.jsxs)(`div`,{className:`mt-3 space-y-1.5`,children:[(0,U.jsx)(o3,{label:`Enabled tools`,items:x}),(0,U.jsx)(o3,{label:`Enabled skills`,items:S}),(0,U.jsx)(o3,{label:`Context files`,items:C})]})]})}function wUe(e){let t;if(typeof e==`string`)try{t=JSON.parse(e)}catch{return}else e&&typeof e==`object`&&!Array.isArray(e)&&(t=e);if(t)return{level:typeof t.level==`string`?t.level:void 0,availableLevels:Array.isArray(t.availableLevels)?t.availableLevels.filter(e=>typeof e==`string`):[],supported:typeof t.supported==`boolean`?t.supported:void 0}}function TUe(e){return Zq.includes(e)?e:void 0}function EUe({row:e,onLevelSelect:t}){let n=wUe(e.output);return n?(0,U.jsxs)(`div`,{className:`mt-2 border border-[#2a2a2a] bg-[#111111] px-3 py-2 text-[12px] text-[#d4d4d4]`,"data-shared-terminal-card":`thinking`,children:[(0,U.jsxs)(`div`,{className:`mb-2 flex items-center gap-2`,children:[(0,U.jsx)(Bs,{size:14,className:`text-[#f59e0b]`}),(0,U.jsx)(`span`,{className:`font-semibold text-[#d4d4d4]`,children:`Thinking`}),n.supported===!1?(0,U.jsxs)(`span`,{className:`ml-auto inline-flex items-center gap-1 border border-[#5f2222] px-1.5 py-0.5 text-[11px] text-[#ef4444]`,children:[(0,U.jsx)(jl,{size:10}),` Unsupported`]}):(0,U.jsxs)(`span`,{className:`ml-auto inline-flex items-center gap-1 border border-[#1f4960] px-1.5 py-0.5 text-[11px] text-[#38bdf8]`,children:[(0,U.jsx)(Ws,{size:10}),` Supported`]})]}),(0,U.jsxs)(`div`,{className:`grid gap-1.5 text-[11px]`,children:[(0,U.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,U.jsx)(`span`,{className:`text-[#737373]`,children:`Current:`}),(0,U.jsx)(`span`,{className:`font-mono font-semibold text-[#f59e0b]`,children:n.level??`unknown`})]}),n.availableLevels.length?(0,U.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[(0,U.jsx)(`span`,{className:`mr-1 text-[#737373]`,children:`Available:`}),n.availableLevels.map(e=>{let r=TUe(e),i=n.supported===!1||!r||!t;return(0,U.jsx)(`button`,{type:`button`,disabled:i,onClick:()=>{r&&t?.(r)},className:`border bg-transparent px-1.5 py-0.5 ${e===n.level?`border-[#f59e0b] text-[#f59e0b]`:`border-[#3a3a3a] text-[#d4d4d4]`} ${i?`cursor-default`:`cursor-pointer`}`,children:e},e)})]}):null,(0,U.jsxs)(`div`,{className:`text-[#737373]`,children:[`Click a level or use `,(0,U.jsx)(`span`,{className:`text-[#f59e0b]`,children:`/thinking <level>`}),`.`]})]})]}):(0,U.jsx)(`div`,{className:`mt-2 border border-[#2a2a2a] bg-[#111111] px-3 py-2 text-[12px] text-[#d4d4d4]`,"data-shared-terminal-card":`thinking`,children:(0,U.jsx)(`div`,{className:`text-[#737373]`,children:`Thinking (unparseable)`})})}var s3=`pibo.chat.terminalReadingPosition.`;function DUe(e){if(e)try{return OUe(sessionStorage.getItem(s3+e))}catch{return}}function c3(e,t){if(e)try{let n=s3+e;t?sessionStorage.setItem(n,JSON.stringify(t)):sessionStorage.removeItem(n)}catch{}}function OUe(e){if(e)try{let t=JSON.parse(e);return typeof t.rowId!=`string`||!t.rowId||typeof t.offsetPx!=`number`||!Number.isFinite(t.offsetPx)?void 0:{rowId:t.rowId,offsetPx:t.offsetPx}}catch{return}}var kUe=180,AUe=4800,jUe=800,MUe=20,NUe={top:2400,bottom:2400},PUe=84,FUe=6;function IUe({traceView:e,isLoading:t,terminalFullscreen:n,showThinking:r,debugMode:i=!1,toolMetricThresholds:a,expandThinking:o,toolDisplayMode:s,sessionAgentProfile:c,sessionActiveModel:l,sessionRuntimeBinding:u,selectedSessionStatus:d,selectedSessionSignal:f,signals:p,sessionGoal:m,sessionBreadcrumbs:h,originSession:g,derivedSessions:_,agentProfiles:v,sessionProfileChangeDisabled:y,onSessionAgentProfileChange:b,onFork:x,onOpenSession:S,onLoadOlderTracePage:C,hasOlderTraceEvents:w,isFetchingOlderTracePage:T,onThinkingLevelChange:E,onModelChanged:D}){let O=(0,H.useMemo)(()=>cHe(e,{showThinking:r,toolDisplayMode:s,debugMode:i}),[r,s,i,e]),k=(0,H.useMemo)(()=>O.map(e=>e.id),[O]),A=e?.piboSessionId??``,[j,M]=(0,H.useState)(),N=(0,H.useRef)(void 0),[P,F]=(0,H.useState)(new Set),[I,L]=(0,H.useState)(null),R=(0,H.useMemo)(()=>[O,P],[P,O]),[z,ee]=(0,H.useState)(null),te=(0,H.useRef)({}),ne=(0,H.useRef)(!1),re=(0,H.useRef)(!1),ie=(0,H.useRef)(!1),B=(0,H.useRef)(!1),ae=(0,H.useRef)(!1),oe=(0,H.useRef)(()=>void 0),se=O.filter(e=>m3(e,`user`)).length,ce=O.filter(e=>m3(e,`tool`)).length,le=O.filter(e=>m3(e,`system`)).length,ue=uVe({signal:f,fallbackStatus:d,fallbackTurnStartedAt:(0,H.useMemo)(()=>uHe(e),[e])}),de=ue.activeTurnStartedAt,fe=ue.isTurnActive,pe=!!q2(m);(0,H.useLayoutEffect)(()=>{!A||!e||!oX()||xPe(A,`compact-terminal:render`,O,{traceVersion:e.version,latestStreamId:e.latestStreamId,lastRawEventId:e.rawEvents.at(-1)?.id,selectedSessionStatus:d})},[A,O,d,e]);let me=(0,H.useCallback)(()=>{if(!w||T||ie.current)return;if(B.current){ae.current=!0;return}ie.current=!0,re.current=!1,oe.current();let e=C?.();Promise.resolve(e).then(()=>{ie.current=!1},()=>{ie.current=!1})},[w,T,C]),he=(0,H.useCallback)(()=>{ne.current&&re.current&&me()},[me]),ge=(0,H.useCallback)(()=>{ne.current&&(!re.current&&!B.current||me())},[me]),_e=(0,H.useCallback)(e=>{B.current=e,!(e||!ae.current)&&(ae.current=!1,me())},[me]),ve=(0,H.useCallback)((e,t)=>{tWe(e,t)&&(re.current=!0)},[]),ye=(0,H.useCallback)(e=>{!ne.current||s!=="default"||e.startIndex<=MUe&&he()},[he,s]),be=(0,H.useCallback)(e=>{A&&c3(A,e?{rowId:e.key,offsetPx:e.offset}:void 0)},[A]),xe=s==="default"?AUe:jUe,Se=yBe({itemCount:O.length,itemKeys:k,isPrepending:T,resetKey:e?.piboSessionId,contentKey:R,atBottomThreshold:kUe,nearTopThreshold:xe,onAtTop:ge,onNearTop:he,onUserScrollIntent:ve,onScrollbarDragChange:_e,onVisibleAnchorChange:be});oe.current=Se.prepareForPrepend,(0,H.useEffect)(()=>{N.current=void 0,ie.current=!1,B.current=!1,ae.current=!1,M(A?DUe(A):void 0),L(null)},[A]),(0,H.useEffect)(()=>{if(!A||!j)return;let t=k.indexOf(j.rowId);if(t>=0){let e=requestAnimationFrame(()=>{Se.restoreAnchor({key:j.rowId,dataIndex:t,offset:j.offsetPx})&&M(void 0)});return()=>cancelAnimationFrame(e)}if(!w){c3(A,void 0),M(void 0);return}if(T)return;let n=String(e?.nextBeforeCursor??e?.nextBeforeSequence??O.length),r=`${A}:${n}`;N.current!==r&&(N.current=r,C?.())},[w,T,C,A,j,k,O.length,Se.restoreAnchor,e?.nextBeforeCursor,e?.nextBeforeSequence]),(0,H.useEffect)(()=>{if(!A)return;let e=()=>{Se.captureVisibleAnchor()},t=()=>{document.visibilityState===`hidden`&&e()};return window.addEventListener(`beforeunload`,e),window.addEventListener(`pagehide`,e),document.addEventListener(`visibilitychange`,t),()=>{window.removeEventListener(`beforeunload`,e),window.removeEventListener(`pagehide`,e),document.removeEventListener(`visibilitychange`,t)}},[A,Se.captureVisibleAnchor]),(0,H.useEffect)(()=>{F(e=>UUe(e,O,o))},[o,O]),(0,H.useEffect)(()=>{ne.current=!1,re.current=!1;let e=window.setTimeout(()=>{ne.current=!0},250);return()=>window.clearTimeout(e)},[e?.piboSessionId]),(0,H.useEffect)(()=>{let e=new Set(O.map(e=>e.id));ee(t=>t&&e.has(t)?t:null);for(let t of[`system`,`tool`,`user`]){let n=te.current[t];n&&!e.has(n)&&delete te.current[t]}},[O]);let Ce=(0,H.useCallback)(e=>{let t=WUe(O,e,te.current[e]);t&&(te.current[e]=t.row.id,ee(t.row.id),Se.scrollToIndex(t.index,`start`,`fast-smooth`,{fromIndex:t.fromIndex,stagingAlign:e===`tool`?`end`:void 0}),GUe(t.row.id))},[O,Se]),we=e=>{e.expandable&&F(t=>{let n=new Set(t);return n.has(e.id)?n.delete(e.id):n.add(e.id),n})},Te=(0,H.useCallback)(e=>{let t=f3(e);t.length&&L({images:t,index:0})},[]),V=(0,H.useCallback)((t,n)=>(0,U.jsx)(`div`,{className:`px-4 @max-[420px]:px-2`,children:(0,U.jsx)(RUe,{row:n,debugMode:i,toolMetricThresholds:a,expanded:P.has(n.id),focused:z===n.id,piboSessionId:e?.piboSessionId??``,onToggle:()=>we(n),onFork:x,onOpenSession:S,onThinkingLevelChange:E,onModelChanged:D,onViewImages:Te,signals:p})}),[i,P,z,x,D,S,E,Te,p,a,e?.piboSessionId]),Ee=(0,H.useMemo)(()=>({Footer:fe||pe?()=>(0,U.jsx)(g3,{startedAt:de,isWorking:fe,goal:m}):void 0}),[de,fe,m,pe]);return(0,U.jsxs)(`section`,{className:`relative min-w-0 flex-1 flex flex-col overflow-hidden bg-[#0b0b0b] text-[#d4d4d4]`,"data-pibo-component":`CompactTerminalSessionView`,"data-pibo-debug":`compact-terminal-session-view`,"data-pibo-session-id":e?.piboSessionId??void 0,"data-pibo-terminal-fullscreen":n?`true`:`false`,"data-pibo-trace-has-older":e?.hasOlderEvents===!0?`true`:`false`,"data-pibo-trace-next-before":e?.nextBeforeCursor??e?.nextBeforeSequence??``,children:[n?null:(0,U.jsx)(LUe,{errorCount:le,toolErrorCount:ce,userMessageCount:se,onNavigate:Ce,sessionAgentProfile:c,sessionActiveModel:l,sessionRuntimeBinding:u,sessionBreadcrumbs:h,originSession:g,derivedSessions:_,onOpenSession:S}),(0,U.jsx)(`div`,{className:`min-h-0 flex-1 overflow-hidden`,children:e?O.length?(0,U.jsx)(jze,{ref:Se.virtuosoRef,data:O,firstItemIndex:Se.firstItemIndex,increaseViewportBy:NUe,defaultItemHeight:PUe,className:`min-h-0 h-full overflow-x-hidden font-mono text-[12px] leading-[1.45]`,computeItemKey:(e,t)=>t.id,scrollerRef:Se.scrollerRef,atBottomStateChange:Se.atBottomStateChange,atBottomThreshold:Se.atBottomThreshold,itemsRendered:Se.itemsRendered,rangeChanged:e=>ye(Se.normalizeRange(e)),followOutput:Se.followOutput,totalListHeightChanged:Se.totalListHeightChanged,alignToBottom:!0,components:Ee,itemContent:V}):(0,U.jsx)(C3,{isLoading:t,agentProfiles:v,disabled:y,onSelectAgentProfile:b,message:`No visible trace rows yet.`}):(0,U.jsx)(C3,{isLoading:t,agentProfiles:v,disabled:y,onSelectAgentProfile:b})}),O.length===0&&pe?(0,U.jsx)(g3,{isWorking:!1,goal:m}):null,I?(0,U.jsx)(HUe,{state:I,piboSessionId:A,onClose:()=>L(null),onIndexChange:e=>L(t=>t?{...t,index:Math.min(Math.max(e,0),t.images.length-1)}:null)}):null,Se.isSticky?null:(0,U.jsx)(`button`,{type:`button`,onClick:()=>{c3(A,void 0),Se.stickToBottom(`auto`)},title:`Scroll to latest`,"aria-label":`Scroll to latest`,className:`absolute right-4 bottom-4 z-30 inline-flex h-9 w-9 items-center justify-center rounded-sm border border-[#38bdf8] bg-[#111111]/95 text-[#38bdf8] shadow-lg shadow-black/30 hover:bg-[#161616]`,children:(0,U.jsx)(Gs,{size:18})})]})}function LUe({errorCount:e,toolErrorCount:t,userMessageCount:n,onNavigate:r,sessionAgentProfile:i,sessionActiveModel:a,sessionRuntimeBinding:o,sessionBreadcrumbs:s,originSession:c,derivedSessions:l,onOpenSession:u}){return(0,U.jsxs)(`div`,{"data-pibo-debug":`compact-terminal-header`,className:`border-b border-[#2a2a2a] bg-[#111111] px-4 py-2 text-[11px] @max-[420px]:px-2`,children:[(0,U.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[i?(0,U.jsx)(x3,{tone:`neutral`,children:i}):null,o?(0,U.jsxs)(x3,{tone:o.state===`missing`||o.state===`error`?`red`:o.state===`unbound`?`amber`:`cyan`,label:`Runtime ${o.runtimeInstanceId} · ${o.state}`,children:[o.runtimeInstanceId,` · `,o.state]}):null,a?(0,U.jsx)(x3,{tone:`purple`,children:a}):null,n>0?(0,U.jsxs)(x3,{tone:`cyan`,label:`${n} user messages · jump to previous user message`,onClick:()=>r(`user`),children:[n,(0,U.jsx)(Vc,{size:12})]}):null,e>0?(0,U.jsxs)(x3,{tone:`red`,label:`${e} errors · jump to previous error`,onClick:()=>r(`system`),children:[e,(0,U.jsx)(rc,{size:12})]}):null,t>0?(0,U.jsxs)(x3,{tone:`amber`,label:`${t} tool call errors · jump to previous tool error`,onClick:()=>r(`tool`),children:[t,(0,U.jsx)(wc,{size:12})]}):null,c?(0,U.jsxs)(l3,{onClick:()=>u(c.piboSessionId),children:[`Origin `,c.label]}):null,l.map(e=>(0,U.jsxs)(l3,{onClick:()=>u(e.piboSessionId),children:[`Derived `,e.label]},e.piboSessionId))]}),s.length?(0,U.jsx)(`div`,{className:`mt-2 flex flex-wrap items-center gap-1 text-[#737373]`,children:s.map((e,t)=>(0,U.jsxs)(`div`,{className:`flex items-center gap-1`,children:[t>0?(0,U.jsx)(qs,{size:12,className:`text-[#525252]`}):null,(0,U.jsx)(`button`,{type:`button`,onClick:()=>u(e.piboSessionId),className:`hover:text-[#38bdf8]`,children:e.label})]},e.piboSessionId))}):null]})}function l3({children:e,onClick:t}){return(0,U.jsx)(`button`,{type:`button`,onClick:t,className:`border border-[#3a3a3a] px-2 py-0.5 text-[#38bdf8] hover:border-[#38bdf8]`,children:e})}function RUe({row:e,debugMode:t,toolMetricThresholds:n,expanded:r,focused:i,piboSessionId:a,onToggle:o,onFork:s,onOpenSession:c,onThinkingLevelChange:l,onModelChanged:u,onViewImages:d,signals:f}){let p=!r&&qUe(e),m=p?KUe(e):e.lines;return e.kind===`agent.delegation`?(0,U.jsxs)(`div`,{className:p3(e,i),"data-pibo-component":`TerminalRow`,"data-pibo-debug":`terminal-row`,"data-pibo-terminal-row":`true`,"data-row-id":e.id,"data-row-kind":e.kind,"data-row-status":e.status,"data-trace-node-id":e.sourceNodeIds.join(` `),"data-event-id":e.eventId,"data-run-id":e.runId,"data-order-source":e.orderSource,"data-order-stream-id":e.orderStreamId,"data-order-frame-index":e.orderStreamFrameIndex,tabIndex:i?0:void 0,"aria-current":i?`true`:void 0,children:[(0,U.jsx)(A2,{title:e.title,summary:e.summary,input:e.input,output:e.output,error:e.error,traceStatus:e.status===`neutral`?`done`:e.status,linkedPiboSessionId:e.linkedPiboSessionId,startedAt:e.startedAt,completedAt:e.completedAt,durationMs:e.durationMs,signals:f,onOpenSession:c}),t&&e.isToolCall?(0,U.jsx)(Q2,{metrics:e.toolMetrics,thresholds:n}):null]}):(0,U.jsxs)(`div`,{className:p3(e,i),"data-pibo-component":`TerminalRow`,"data-pibo-debug":`terminal-row`,"data-pibo-terminal-row":`true`,"data-row-id":e.id,"data-row-kind":e.kind,"data-row-status":e.status,"data-trace-node-id":e.sourceNodeIds.join(` `),"data-event-id":e.eventId,"data-run-id":e.runId,"data-order-source":e.orderSource,"data-order-stream-id":e.orderStreamId,"data-order-frame-index":e.orderStreamFrameIndex,onDoubleClick:e.expandable?t=>{!e.expandable||h3(t)||o()}:void 0,onKeyDown:e.expandable?t=>{!e.expandable||h3(t)||(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),o())}:void 0,role:e.expandable?`button`:void 0,tabIndex:e.expandable||i?0:void 0,"aria-expanded":e.expandable?r:void 0,"aria-current":i?`true`:void 0,children:[(0,U.jsxs)(`div`,{className:`flex gap-3`,children:[(0,U.jsx)(`div`,{className:`min-w-0 flex-1`,children:(0,U.jsx)(zUe,{row:e,visibleLines:m,collapseToolCallPreview:p,piboSessionId:a,onThinkingLevelChange:l,onModelChanged:u,onFork:s})}),(0,U.jsx)(VUe,{row:e,onOpenSession:c,onViewImages:d})]}),r?(0,U.jsx)(CVe,{row:e,onOpenSession:c}):null,t&&e.isToolCall?(0,U.jsx)(Q2,{metrics:e.toolMetrics,thresholds:n}):null]})}function zUe({row:e,visibleLines:t,collapseToolCallPreview:n,piboSessionId:r,onThinkingLevelChange:i,onModelChanged:a,onFork:o}){return e.kind===`message.assistant`?(0,U.jsxs)(`div`,{className:`ml-[1.9rem] min-w-0`,"data-pibo-component":`TerminalAssistantMessage`,children:[(0,U.jsx)(`div`,{className:`compact-terminal-markdown`,"data-pibo-component":`MarkdownRendererHost`,"data-pibo-markdown-kind":`assistant-message`,children:(0,U.jsx)(nG,{streaming:e.status===`running`,children:typeof e.output==`string`?e.output:``})}),e.status===`running`?null:(0,U.jsx)(d3,{timestamp:e.completedAt,durationMs:e.durationMs,speechText:typeof e.output==`string`?e.output:void 0,speechScopeKey:`${r}:${e.id}`})]}):e.kind===`message.user`?(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(u3,{lines:t,status:e.status,clampPreview:n,singleLine:e.singleLine}),e.pendingMessageDelivery?(0,U.jsx)(I2,{delivery:e.pendingMessageDelivery,className:`ml-[1.9rem] mt-2`}):null,(0,U.jsx)(d3,{timestamp:e.startedAt,forkEntryId:e.forkEntryId,onFork:o})]}):e.kind===`tool.status`?(0,U.jsx)(CUe,{row:e,piboSessionId:r}):e.kind===`tool.thinking`?(0,U.jsx)(EUe,{row:e,onLevelSelect:i}):e.kind===`tool.login`?(0,U.jsx)(VVe,{row:e,piboSessionId:r}):e.kind===`tool.model`?(0,U.jsx)(GVe,{row:e,piboSessionId:r,onModelChanged:a}):e.kind===`execution.compaction`&&e.status===`running`?(0,U.jsx)(QUe,{}):e.kind===`reasoning`&&e.markdown?(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(u3,{lines:t,status:e.status,clampPreview:n,singleLine:e.singleLine}),(0,U.jsx)(`div`,{className:`ml-[1.9rem] min-w-0`,"data-pibo-component":`TerminalReasoningMarkdown`,children:(0,U.jsx)(`div`,{className:`compact-terminal-markdown compact-terminal-reasoning`,"data-pibo-component":`MarkdownRendererHost`,"data-pibo-markdown-kind":`reasoning`,children:(0,U.jsx)(nG,{streaming:e.status===`running`,children:e.markdown})})})]}):(0,U.jsx)(u3,{lines:t,status:e.status,clampPreview:n,singleLine:e.singleLine})}function u3({lines:e,status:t,clampPreview:n,singleLine:r}){return e.map((e,i)=>(0,U.jsx)(MVe,{line:e,status:t,clampLines:r?1:n&&i===0?5:void 0},i))}function d3({timestamp:e,durationMs:t,forkEntryId:n,onFork:r,speechText:i,speechScopeKey:a}){let o=BUe(e);return!o&&!n&&!i?.trim()?null:(0,U.jsxs)(`div`,{className:`mt-1 flex items-center justify-end gap-1 font-mono text-[10px] tabular-nums text-[#737373]`,"data-pibo-component":`TerminalMessageMetadata`,children:[n&&r?(0,U.jsx)(oVe,{entryId:n,onFork:r}):null,i?.trim()?(0,U.jsx)(F2,{text:i,scopeKey:a}):null,o?(0,U.jsxs)(`span`,{children:[o,t===void 0?null:` · ${A4(t)}`]}):null]})}function BUe(e){if(!e)return;let t=new Date(e);if(Number.isFinite(t.getTime()))return new Intl.DateTimeFormat(void 0,{hour:`2-digit`,minute:`2-digit`,hourCycle:`h23`}).format(t)}function VUe({row:e,onOpenSession:t,onViewImages:n}){let r=f3(e.imagePreviews??[]);return!e.linkedPiboSessionId&&r.length===0?null:(0,U.jsxs)(`div`,{className:`flex shrink-0 items-start gap-1`,children:[r.length?(0,U.jsxs)(S3,{label:r.length===1?`View image preview`:`View ${r.length} image previews`,onClick:()=>n(r),children:[(0,U.jsx)(Ec,{size:13,"aria-hidden":`true`}),` View`]}):null,e.linkedPiboSessionId?(0,U.jsx)(S3,{label:`Open linked session`,onClick:()=>t(e.linkedPiboSessionId),children:`Open`}):null]})}function HUe({state:e,piboSessionId:t,onClose:n,onIndexChange:r}){let i=e.images[e.index],a=i?fu(i,t)[0]:void 0,[o,s]=(0,H.useState)(`loading`),c=(0,H.useRef)(null),l=e.index>0,u=e.index+1<e.images.length;(0,H.useEffect)(()=>s(a?`loading`:`error`),[i?.id,a]);let d=t=>{t<0||t>=e.images.length||(r(t),window.requestAnimationFrame(()=>c.current?.focus()))};return(0,U.jsx)(iX,{title:`Image preview`,description:`${i?.label??`Image`} · ${e.index+1} of ${e.images.length}`,onClose:n,initialFocusRef:c,onKeyDown:t=>{if(t.key===`ArrowLeft`&&l)d(e.index-1);else if(t.key===`ArrowRight`&&u)d(e.index+1);else if(t.key===`Home`&&l)d(0);else if(t.key===`End`&&u)d(e.images.length-1);else return;t.preventDefault()},closeLabel:`Close image preview`,maxWidthClassName:`max-w-6xl`,children:(0,U.jsxs)(`div`,{ref:c,tabIndex:-1,className:`flex min-h-[12rem] flex-col bg-[#0b0b0b] outline-none sm:min-h-[18rem]`,"data-pibo-component":`TerminalImageDialog`,children:[(0,U.jsxs)(`div`,{className:`relative flex min-h-0 flex-1 items-center justify-center overflow-auto p-2 sm:p-4`,children:[a?(0,U.jsx)(`img`,{src:a,alt:`Tool image: ${i?.label??`image preview`}`,loading:`lazy`,decoding:`async`,onLoad:()=>s(`loaded`),onError:()=>s(`error`),className:`max-h-[calc(100dvh-12rem)] max-w-full object-contain ${o===`loaded`?`block`:`invisible`}`},a):null,o===`loading`?(0,U.jsx)(`div`,{className:`absolute inset-0 grid place-items-center text-xs text-[#a3a3a3]`,role:`status`,children:`Loading image preview…`}):null,o===`error`?(0,U.jsx)(`div`,{className:`absolute inset-0 grid place-items-center px-6 text-center text-xs text-[#f87171]`,role:`alert`,children:`Image preview is unavailable.`}):null]}),(0,U.jsxs)(`div`,{className:`flex items-center justify-between gap-3 border-t border-[#2a2a2a] px-3 py-2`,children:[(0,U.jsxs)(S3,{label:`Previous image`,onClick:()=>d(e.index-1),disabled:!l,children:[(0,U.jsx)(Ks,{size:14,"aria-hidden":`true`}),` Previous`]}),(0,U.jsxs)(`span`,{className:`text-[11px] tabular-nums text-[#a3a3a3]`,"aria-live":`polite`,children:[e.index+1,` / `,e.images.length]}),(0,U.jsxs)(S3,{label:`Next image`,onClick:()=>d(e.index+1),disabled:!u,children:[`Next `,(0,U.jsx)(qs,{size:14,"aria-hidden":`true`})]})]})]})})}function f3(e){return e.filter(e=>!!(e.payloadRef?e.traceNodeId:e.generatedToolCallId||e.path)).slice(0,20)}function p3(e,t=!1){let n=e.kind===`message.user`?`group border-b border-[#141414] bg-[#11a4d4]/10 py-2 last:border-b-0 hover:bg-[#11a4d4]/15`:e.kind===`agent.delegation`?`group border-b border-[#141414] bg-[#f97316]/5 py-2 last:border-b-0`:e.kind===`execution.command`?`group border-b border-[#141414] bg-[#f59e0b]/5 py-2 last:border-b-0 hover:bg-[#f59e0b]/10`:`group border-b border-[#141414] py-2 last:border-b-0 hover:bg-[#161616]`,r=e.expandable||t?` focus:outline-none focus:ring-1 focus:ring-[#38bdf8]/50`:``;return t?`${n}${r} ring-1 ring-[#38bdf8] bg-[#123040]`:`${n}${r}`}function UUe(e,t,n){let r=new Set;for(let i of t)e.has(i.id)&&r.add(i.id),n&&i.kind===`reasoning`&&i.expandable&&r.add(i.id);return eWe(e,r)?e:r}function m3(e,t){return t===`user`?e.kind===`message.user`:e.status===`error`?t===`tool`?e.errorKind===`tool`:e.errorKind!==`tool`:!1}function WUe(e,t,n){let r=e.map((e,t)=>({row:e,index:t})).filter(({row:e})=>m3(e,t));if(!r.length)return;let i=n?e.findIndex(e=>e.id===n):-1,a=i>=0?i:e.length;return{...r.filter(e=>e.index<a).at(-1)??r[r.length-1],fromIndex:a}}function GUe(e){let t=0,n=()=>{let r=Array.from(document.querySelectorAll(`[data-pibo-component="TerminalRow"]`)).find(t=>t.dataset.rowId===e);if(r){r.scrollIntoView({block:`start`,inline:`nearest`,behavior:`smooth`}),r.focus({preventScroll:!0});return}t+=1,t<8&&requestAnimationFrame(n)};requestAnimationFrame(()=>requestAnimationFrame(n))}function KUe(e){return e.kind===`tool.group.exploring`||e.kind===`tool.group.images`?e.lines.slice(0,FUe):e.lines}function qUe(e){return!!e.expandable&&(e.kind===`tool.call`||e.kind===`tool.image`||e.kind===`tool.group.exploring`||e.kind===`tool.group.images`||e.kind===`agent.delegation`||e.kind===`agent.async`||e.kind===`yielded.run`||e.kind===`execution.command`||e.kind===`execution.compaction`)}function h3(e){let t=e.target;if(!(t instanceof Element)||t===e.currentTarget)return!1;let n=t.closest(`button, a, input, textarea, select, summary, [role='button'], [tabindex]:not([tabindex='-1'])`);return!!(n&&n!==e.currentTarget)}var JUe=`Working...`,YUe=33;function g3({startedAt:e,isWorking:t,goal:n}){let r=ZUe(t?e:void 0),{chars:i,activeIndex:a}=XUe(JUe,t),o=q2(n),s=n&&o===`active`?J2(n):void 0,c=[t?`Working`:void 0,o===`active`?`Pursuing Goal`:o===`paused`?`Goal Paused`:void 0,s?`Tokens ${s}`:void 0].filter(Boolean).join(`. `);return(0,U.jsx)(`div`,{className:`border-t border-[#141414] px-4 py-2 @max-[420px]:px-2`,role:`status`,"aria-live":`polite`,"aria-label":c,"data-pibo-component":`TerminalStreamingFooter`,"data-pibo-active-turn-started-at":t?e:void 0,children:(0,U.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-baseline justify-between gap-x-4 gap-y-1`,"aria-hidden":`true`,children:[t?(0,U.jsxs)(`div`,{className:`grid min-w-0 flex-1 grid-cols-[1.9rem_minmax(0,1fr)] gap-2 whitespace-pre-wrap break-words`,children:[(0,U.jsx)(`span`,{className:`whitespace-pre text-[#737373]`,children:`•`}),(0,U.jsxs)(`span`,{className:`inline-flex min-w-0 items-baseline gap-2`,children:[r?(0,U.jsx)(`span`,{className:`shrink-0 tabular-nums text-[#737373]`,children:r}):null,(0,U.jsx)(`span`,{className:`compact-terminal-working-scramble`,children:i.map((e,t)=>(0,U.jsx)(`span`,{className:t===a?`compact-terminal-working-scramble-active`:void 0,children:e},t))})]})]}):(0,U.jsx)(`span`,{className:`min-w-0 flex-1`}),(0,U.jsx)(dVe,{goal:n})]})})}function XUe(e,t){let n=(0,H.useMemo)(()=>Array.from(e),[e]),[r,i]=(0,H.useState)(()=>n),[a,o]=(0,H.useState)(-1);return(0,H.useEffect)(()=>{if(!t||window.matchMedia(`(prefers-reduced-motion: reduce)`).matches){i(n),o(-1);return}let e=0,r=0,a=b3(),s=0;i(v3(n)),o(0);let c=window.setInterval(()=>{if(s>0){s--;return}if(e>=n.length){e=0,r=0,a=b3(),i(v3(n)),o(0);return}let t=e,c=n[t]??` `;if(o(t),r++,r<a){i(e=>_3(e,t,y3(c)));return}i(e=>_3(e,t,c)),e++,r=0,a=b3(),e>=n.length&&(i(n),o(-1),s=18)},55);return()=>window.clearInterval(c)},[t,n]),{chars:r,activeIndex:a}}function _3(e,t,n){let r=[...e];return r[t]=n,r}function v3(e){return e.map(e=>y3(e))}function y3(e){let t=``;do{let e=YUe+Math.floor(Math.random()*94);t=String.fromCharCode(e)}while(t===e);return t}function b3(){return 2+Math.floor(Math.random()*11)}function ZUe(e){let t=e?new Date(e).getTime():NaN,[n,r]=(0,H.useState)(()=>Date.now());return(0,H.useEffect)(()=>{if(r(Date.now()),!Number.isFinite(t))return;let e=window.setInterval(()=>r(Date.now()),1e3);return()=>window.clearInterval(e)},[t]),Number.isFinite(t)?A4(Math.max(0,n-t)):void 0}function QUe(){let e=$Ue();return(0,U.jsxs)(`div`,{className:`grid grid-cols-[1.9rem_minmax(0,1fr)] gap-2 whitespace-pre-wrap break-words`,children:[(0,U.jsx)(`span`,{className:`whitespace-pre text-[#38bdf8]`,children:`•`}),(0,U.jsxs)(`span`,{className:`min-w-0`,children:[(0,U.jsx)(`span`,{className:`font-semibold text-[#38bdf8]`,children:`Compacting`}),(0,U.jsx)(`span`,{className:`text-[#38bdf8]`,children:e})]})]})}function $Ue(){let[e,t]=(0,H.useState)(0);return(0,H.useEffect)(()=>{let e=window.setInterval(()=>t(e=>(e+1)%4),400);return()=>window.clearInterval(e)},[]),`.`.repeat(e)}function x3({tone:e,label:t,onClick:n,children:r}){let i=`inline-flex items-center gap-1 border px-2 py-0.5 ${e===`cyan`?`border-[#1f4960] text-[#38bdf8]`:e===`red`?`border-[#5f2222] text-[#ef4444]`:e===`amber`?`border-[#6b4e16] text-[#f59e0b]`:e===`purple`?`border-purple-500/40 text-purple-300`:`border-[#3a3a3a] text-[#d4d4d4]`}`;return n?(0,U.jsx)(`button`,{type:`button`,onClick:n,className:`${i} hover:bg-white/5 focus:outline-none focus:ring-1 focus:ring-[#38bdf8]`,title:t,"aria-label":t,children:r}):(0,U.jsx)(`span`,{className:i,title:t,"aria-label":t,children:r})}function S3({label:e,onClick:t,disabled:n=!1,children:r}){return(0,U.jsx)(`button`,{type:`button`,onClick:t,disabled:n,"aria-label":e,title:e,className:`inline-flex min-h-7 min-w-7 items-center gap-1 border border-[#3a3a3a] px-2 text-[11px] text-[#a3a3a3] hover:border-[#38bdf8] hover:text-[#38bdf8] disabled:cursor-not-allowed disabled:opacity-40 disabled:hover:border-[#3a3a3a] disabled:hover:text-[#a3a3a3]`,children:r})}function C3({isLoading:e,agentProfiles:t,disabled:n,onSelectAgentProfile:r,message:i}){return(0,U.jsxs)(`div`,{className:`flex min-h-full flex-col items-center justify-center gap-4 px-6 py-10 text-center text-[12px] text-[#737373] @max-[420px]:px-3`,children:[(0,U.jsx)(`div`,{children:e?`Loading trace…`:i??`No trace selected.`}),t.length?(0,U.jsx)(`div`,{className:`flex flex-wrap items-center justify-center gap-2`,children:t.map(e=>(0,U.jsx)(`button`,{type:`button`,disabled:n,onClick:()=>r(e.name),className:`border border-[#3a3a3a] px-2 py-1 text-[#d4d4d4] hover:border-[#38bdf8] hover:text-[#38bdf8] disabled:opacity-50`,children:e.name},e.name))}):null]})}function eWe(e,t){if(e.size!==t.size)return!1;for(let n of e)if(!t.has(n))return!1;return!0}function tWe(e,t){return t?t===`away`:e instanceof WheelEvent?e.deltaY<0:e instanceof KeyboardEvent?[`ArrowUp`,`PageUp`,`Home`].includes(e.key):e?.type===`touchmove`}function nWe({selectedPiboSessionId:e,workflowSessionLinked:t,sessionNodes:n,onOpenSession:r,onRefreshBootstrap:i,onError:a}){let o=kn(),s=[`chat`,`session-workflow`,e],c=Wn({queryKey:s,queryFn:()=>WQ(e),enabled:!!(e&&t),retry:!1}),[l,u]=(0,H.useState)(!1),[d,f]=(0,H.useState)(),[p,m]=(0,H.useState)(),h=c.data,g=async()=>{await Promise.all([c.refetch(),i?.()])},_=async()=>{if(!(!e||l)){u(!0),m(void 0),a?.(null);try{let t=await SLe(e);m(t.alreadyStarted?`Workflow run was already started.`:t.message||`Workflow run started.`),await o.invalidateQueries({queryKey:s}),await g()}catch(e){a?.(ZQ(e))}finally{u(!1)}}},v=async(t,n,r,i)=>{if(e){f(`${t}:${n??r??`resume`}`),a?.(null);try{await CLe(e,{waitTokenId:t,...n?{actionId:n}:{},...r?{kind:r}:{},...i===void 0?{}:{payload:i}}),m(`Human action accepted.`),await o.invalidateQueries({queryKey:s}),await g()}catch(e){a?.(ZQ(e))}finally{f(void 0)}}};if(!t)return(0,U.jsx)(O3,{title:`Workflow unavailable`,children:`This normal Session has no workflow linkage. Workflow inspection is requested only for linked Sessions.`});if(c.isLoading)return(0,U.jsxs)(O3,{title:`Loading Workflow`,children:[(0,U.jsx)(Pc,{className:`inline animate-spin text-[#11a4d4]`,size:15}),` Loading configuration and run facts…`]});if(c.error||!h)return(0,U.jsx)(O3,{title:`Workflow inspection failed`,error:!0,children:ZQ(c.error??`No workflow inspection response`)});let y=h.workflowSession,b=y.workflowDefinitionLink,x=b?.status===`live`?b.href??(y.workflowVersion?`/apps/chat/workflows/view/${encodeURIComponent(y.workflowId)}/${encodeURIComponent(y.workflowVersion)}`:void 0):void 0,S=cWe(n,y.piboSessionId);return(0,U.jsx)(`section`,{className:`min-w-0 flex-1 overflow-auto bg-[#0b0f14] p-4 text-slate-300`,"data-pibo-debug":`session-native-workflow-view`,children:(0,U.jsxs)(`div`,{className:`mx-auto flex max-w-6xl flex-col gap-4`,children:[(0,U.jsxs)(`header`,{className:`rounded-sm border border-slate-800 bg-[#111820] p-4`,children:[(0,U.jsxs)(`div`,{className:`flex flex-wrap items-start justify-between gap-3`,children:[(0,U.jsxs)(`div`,{children:[(0,U.jsxs)(`div`,{className:`flex items-center gap-2 font-semibold text-slate-100`,children:[(0,U.jsx)(Ds,{size:16,className:`text-[#11a4d4]`}),`Workflow Session`]}),(0,U.jsxs)(`div`,{className:`mt-2 flex flex-wrap gap-2 text-xs`,children:[(0,U.jsxs)(A3,{children:[y.workflowId,y.workflowVersion?`@${y.workflowVersion}`:``]}),(0,U.jsx)(`span`,{className:XY(y.state),children:y.state}),y.workflowRunId?(0,U.jsxs)(A3,{children:[`run `,ZY(y.workflowRunId)]}):null]}),(0,U.jsx)(`p`,{className:`mt-2 text-xs text-slate-500`,children:`This is a normal Pibo Session with Workflow-owned linkage and execution facts.`})]}),(0,U.jsxs)(`div`,{className:`flex gap-2`,children:[(0,U.jsxs)(`button`,{type:`button`,onClick:()=>void g(),disabled:c.isFetching,"aria-label":`Refresh Workflow state`,className:j3,children:[c.isFetching?(0,U.jsx)(Pc,{size:13,className:`animate-spin`}):(0,U.jsx)(ol,{size:13}),`Refresh`]}),y.state===`configured`&&!y.workflowRunId?(0,U.jsxs)(`button`,{type:`button`,onClick:()=>void _(),disabled:l,className:`${j3} border-emerald-600 text-emerald-200`,children:[l?(0,U.jsx)(Pc,{size:13,className:`animate-spin`}):(0,U.jsx)(nl,{size:13}),`Start Workflow`]}):null]})]}),p||y.state===`pending`&&h.snapshot?(0,U.jsx)(`div`,{role:`status`,className:`mt-3 rounded-sm border border-emerald-800 bg-emerald-950/20 p-2 text-xs text-emerald-200`,children:p??`Run recorded. General graph execution is not connected here; supported manual triggers run from the editor.`}):null]}),(0,U.jsx)(`div`,{className:`rounded-sm border border-amber-800/60 bg-amber-950/15 p-3 text-xs leading-5 text-amber-100/80`,"aria-label":`Workflow execution boundary`,children:`Workflow execution uses Pibo Workflow IR and registered capabilities. XState is a read-only visualization; this surface does not expose inline code, raw XState editing, or broaden Session profile permissions.`}),(0,U.jsxs)(`div`,{className:`grid gap-4 lg:grid-cols-2`,children:[(0,U.jsx)(D3,{icon:uc,title:`Configuration`,children:(0,U.jsx)(ZK,{value:y.configuration??{}})}),(0,U.jsx)(D3,{icon:Ds,title:`Current run`,children:h.run?(0,U.jsx)(ZK,{value:h.run}):(0,U.jsx)(k3,{children:`No run exists. Start remains explicit.`})}),(0,U.jsx)(D3,{icon:ec,title:`Final output`,children:h.run&&Object.hasOwn(h.run,`output`)?(0,U.jsx)(ZK,{value:h.run.output}):(0,U.jsx)(k3,{children:`No final Workflow output recorded.`})}),(0,U.jsx)(D3,{icon:wl,title:`Validation and diagnostics`,children:(0,U.jsx)(ZK,{value:{snapshotValidation:h.snapshot?.validation,lifecycleDiagnostics:h.lifecycleEvents.flatMap(e=>e.diagnostics??[])}})})]}),(0,U.jsx)(oWe,{snapshot:h.snapshot??(h.definitionSnapshot?{effectiveDefinition:h.definitionSnapshot.definition}:void 0),attempts:h.nodeAttempts,transfers:h.edgeTransfers}),(0,U.jsx)(rWe,{data:h,busy:d,onSubmit:v}),(0,U.jsxs)(`div`,{className:`grid gap-4 xl:grid-cols-2`,children:[(0,U.jsx)(E3,{title:`Node attempts`,icon:ec,records:h.nodeAttempts,empty:`No node attempts recorded.`}),(0,U.jsx)(E3,{title:`Edge transfers`,icon:cl,records:h.edgeTransfers,empty:`No edge transfers recorded.`}),(0,U.jsx)(E3,{title:`Wait tokens`,icon:ic,records:h.waitTokens,empty:`No workflow waits recorded.`}),(0,U.jsx)(E3,{title:`Human action history`,icon:Ds,records:h.humanActions,empty:`No human actions recorded.`}),(0,U.jsx)(E3,{title:`Lifecycle events`,icon:Sc,records:h.lifecycleEvents,empty:`No lifecycle events recorded.`}),(0,U.jsx)(D3,{icon:uc,title:`Immutable effective snapshot`,children:h.snapshot??h.definitionSnapshot?(0,U.jsx)(ZK,{value:h.snapshot??h.definitionSnapshot}):(0,U.jsx)(k3,{children:`No immutable snapshot is available.`})})]}),(0,U.jsxs)(`section`,{className:`rounded-sm border border-slate-800 bg-[#111820] p-4`,children:[(0,U.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,U.jsx)(`h2`,{className:`text-xs font-bold uppercase tracking-wider text-slate-300`,children:`Workflow links`}),x?(0,U.jsxs)(`a`,{href:x,className:j3,children:[(0,U.jsx)(fc,{size:13}),`Open definition`]}):null]}),b?.status===`snapshot_only_definition_deleted`?(0,U.jsx)(`div`,{className:`mt-3 rounded-sm border border-amber-800 bg-amber-950/20 p-3 text-xs text-amber-100`,children:b.tombstoneLabel??`The live definition is unavailable. Inspection uses the immutable Session snapshot.`}):null,(0,U.jsx)(`div`,{className:`mt-3 grid gap-2`,children:S.length?S.map(e=>(0,U.jsxs)(`button`,{type:`button`,onClick:()=>r(e.piboSessionId),className:`rounded-sm border border-slate-800 bg-[#0e1116] p-3 text-left text-xs hover:border-[#11a4d4]`,children:[(0,U.jsx)(`span`,{className:`font-semibold text-slate-200`,children:e.title}),(0,U.jsx)(`span`,{className:`ml-2 font-mono text-slate-500`,children:e.piboSessionId})]},e.piboSessionId)):(0,U.jsx)(k3,{children:`No linked child Workflow Sessions.`})})]})]})})}function rWe({data:e,busy:t,onSubmit:n}){let r=e.workflowSession.pendingHumanActions??[],i=e.waitTokens.filter(e=>!e.status||e.status===`pending`||e.status===`waiting`);return(0,U.jsxs)(`section`,{className:`rounded-sm border border-amber-800/60 bg-[#111820] p-4`,"aria-label":`Workflow human actions`,children:[(0,U.jsx)(`h2`,{className:`text-xs font-bold uppercase tracking-wider text-amber-200`,children:`Human actions`}),(0,U.jsx)(`div`,{className:`mt-3 grid gap-3`,children:r.length?r.map(e=>(0,U.jsx)(iWe,{action:e,busy:t,onSubmit:n},e.waitTokenId)):i.length?i.map(e=>(0,U.jsx)(aWe,{token:e,busy:t,onSubmit:n},e.id)):(0,U.jsx)(k3,{children:`No pending human action.`})})]})}function iWe({action:e,busy:t,onSubmit:n}){let[r,i]=(0,H.useState)(`{}`),[a,o]=(0,H.useState)(),s=(t,i)=>{let a;try{a=r.trim()?JSON.parse(r):void 0,o(void 0)}catch{o(`Payload must be valid JSON.`);return}n(e.waitTokenId,t,i,a)};return(0,U.jsxs)(`div`,{className:`rounded-sm border border-amber-700/50 bg-amber-950/10 p-3 text-xs`,children:[(0,U.jsx)(`div`,{className:`font-semibold text-amber-100`,children:e.prompt}),e.diagnostics.length?(0,U.jsx)(`div`,{role:`alert`,className:`mt-2 rounded-sm border border-red-800/70 bg-red-950/20 p-2 text-red-200`,children:(0,U.jsx)(ZK,{value:e.diagnostics})}):null,e.payloadRequirements.required||e.schema?(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(`textarea`,{"aria-label":`Human action payload for ${e.waitTokenId}`,value:r,onChange:e=>i(e.target.value),className:`mt-3 min-h-20 w-full rounded-sm border border-slate-700 bg-[#0e1116] p-2 font-mono text-xs`}),a?(0,U.jsx)(`div`,{role:`alert`,className:`mt-1 text-red-300`,children:a}):null]}):null,(0,U.jsx)(`div`,{className:`mt-3 flex flex-wrap gap-2`,children:e.availableActions.filter(e=>e.registered).map(e=>(0,U.jsx)(`button`,{type:`button`,disabled:!!t,onClick:()=>s(e.id,e.kind),className:j3,children:e.displayName},e.id))})]})}function aWe({token:e}){return(0,U.jsxs)(`div`,{className:`rounded-sm border border-amber-700/50 p-3 text-xs`,children:[(0,U.jsx)(`div`,{children:e.prompt??`Wait ${e.id}`}),(0,U.jsx)(`div`,{className:`mt-2 text-[11px] text-amber-100/70`,children:`No registered actions were returned for this wait token. Refresh after the runtime publishes actionable metadata.`})]})}function oWe({snapshot:e,attempts:t,transfers:n}){let r=(0,H.useMemo)(()=>sWe(e),[e]);return e?(0,U.jsxs)(D3,{icon:Sc,title:`Workflow graph`,children:[(0,U.jsx)(`div`,{className:`grid gap-2 sm:grid-cols-2 lg:grid-cols-3`,children:r.nodes.map(e=>{let n=[...t].reverse().find(t=>t.nodeId===e.id);return(0,U.jsxs)(`div`,{className:`rounded-sm border border-slate-700 bg-[#0e1116] p-3 text-xs`,children:[(0,U.jsx)(`div`,{className:`font-mono font-semibold text-[#8bdcf4]`,children:e.id}),(0,U.jsx)(`div`,{className:`mt-1 text-slate-400`,children:e.kind}),(0,U.jsx)(`div`,{className:`mt-2 text-[10px] uppercase text-slate-500`,children:n?.status??`not attempted`})]},e.id)})}),r.nodes.length===0?(0,U.jsx)(k3,{children:`The snapshot contains no graph nodes.`}):null,(0,U.jsx)(`div`,{className:`mt-3 grid gap-1 text-xs text-slate-400`,children:r.edges.map(e=>(0,U.jsxs)(`div`,{className:`rounded-sm border border-slate-800 p-2 font-mono`,children:[e.source,` → `,e.target,n.some(t=>t.edgeId===e.id)?` · transferred`:``]},e.id))})]}):(0,U.jsx)(D3,{icon:Sc,title:`Workflow graph`,children:(0,U.jsx)(k3,{children:`No immutable snapshot is available, so no graph is rendered.`})})}function sWe(e){let t=e?.effectiveDefinition;if(!t||typeof t!=`object`)return{nodes:[],edges:[]};let n=t.nodes,r=t.edges;return{nodes:n&&typeof n==`object`&&!Array.isArray(n)?Object.entries(n).map(([e,t])=>({id:e,kind:w3(t,`kind`)??`node`})):[],edges:r&&typeof r==`object`&&!Array.isArray(r)?Object.entries(r).map(([e,t])=>({id:e,source:T3(t,`from`)??w3(t,`source`)??`?`,target:T3(t,`to`)??w3(t,`target`)??`?`})):Array.isArray(r)?r.map((e,t)=>({id:w3(e,`id`)??`edge-${t+1}`,source:T3(e,`from`)??w3(e,`source`)??`?`,target:T3(e,`to`)??w3(e,`target`)??`?`})):[]}}function w3(e,t){if(!e||typeof e!=`object`)return;let n=e[t];return typeof n==`string`?n:void 0}function T3(e,t){if(!(!e||typeof e!=`object`))return w3(e[t],`nodeId`)}function cWe(e,t){let n=[],r=e=>{for(let i of e)i.parentId===t&&(i.workflowSessionKind===`nested_workflow`||i.workflowSessionKind===`agent_node`)&&n.push({piboSessionId:i.piboSessionId,title:i.title}),r(i.children)};return r(e),n}function E3({title:e,icon:t,records:n,empty:r}){return(0,U.jsx)(D3,{icon:t,title:e,children:n.length?(0,U.jsx)(`div`,{className:`grid gap-2`,children:n.map((e,t)=>(0,U.jsx)(`div`,{className:`rounded-sm border border-slate-800 bg-[#0e1116] p-2`,children:(0,U.jsx)(ZK,{value:e})},lWe(e,t)))}):(0,U.jsx)(k3,{children:r})})}function D3({icon:e,title:t,children:n}){return(0,U.jsxs)(`section`,{className:`min-w-0 rounded-sm border border-slate-800 bg-[#111820] p-4`,children:[(0,U.jsxs)(`h2`,{className:`mb-3 flex items-center gap-2 text-xs font-bold uppercase tracking-wider text-slate-300`,children:[(0,U.jsx)(e,{size:14,className:`text-[#11a4d4]`}),t]}),n]})}function O3({title:e,children:t,error:n=!1}){return(0,U.jsx)(`section`,{className:`min-w-0 flex-1 overflow-auto bg-[#0b0f14] p-4`,children:(0,U.jsxs)(`div`,{className:`mx-auto max-w-3xl rounded-sm border p-4 text-sm ${n?`border-red-900 bg-red-950/30 text-red-200`:`border-slate-800 bg-[#111820] text-slate-300`}`,children:[(0,U.jsxs)(`div`,{className:`mb-2 flex items-center gap-2 font-semibold`,children:[n?(0,U.jsx)(wl,{size:15}):null,e]}),t]})})}function k3({children:e}){return(0,U.jsx)(`div`,{className:`rounded-sm border border-dashed border-slate-700 p-3 text-xs text-slate-500`,children:e})}function A3({children:e}){return(0,U.jsx)(`span`,{className:`rounded border border-slate-700 bg-slate-900/40 px-2 py-1 font-mono text-slate-300`,children:e})}function lWe(e,t){return e&&typeof e==`object`&&typeof e.id==`string`?e.id:String(t)}var j3=`inline-flex items-center justify-center gap-1 rounded-sm border border-slate-700 px-3 py-1.5 text-xs font-semibold text-slate-200 hover:border-[#11a4d4] hover:text-white disabled:opacity-50`,M3=new Map([{id:`terminal`,label:`Terminal`,description:`Compact Codex-style terminal transcript.`,render:e=>(0,U.jsx)(IUe,{...e})},{id:`workflow`,label:`Workflow`,description:`Workflow configuration, graph, run facts, waits, and human actions for linked Sessions.`,render:e=>(0,U.jsx)(nWe,{...e})}].map(e=>[e.id,e]));function uWe(e){return M3.get(e)??M3.get(`terminal`)}function N3(e,t){return{localBootstrap:t,queryData:e.getQueriesData({queryKey:[`chat`,`bootstrap`]})}}function P3(e,t,n){return e.selectedRoomId===t?n(e):e}function F3(e){let t=!!(e.tempId&&e.currentSelectedPiboSessionId===e.tempId);return e.status===`success`?{selectedPiboSessionId:t?e.createdPiboSessionId:e.currentSelectedPiboSessionId,navigateToCreatedSession:t,autoRenameCreatedSession:t}:{selectedPiboSessionId:t?e.previousSelectedPiboSessionId??null:e.currentSelectedPiboSessionId,navigateToCreatedSession:!1,autoRenameCreatedSession:!1}}function I3(e,t){return!e||t===void 0?e:{...e,selectedPiboSessionId:t??``}}function L3(e,t){return Z3(e.sessions,t.piboSessionId)?e:{...e,sessions:R3(e.sessions,t)}}function dWe(e,t,n){let r=e.sessions.findIndex(e=>e.piboSessionId===t);if(r<0)return e;let i=[...e.sessions],[a]=i.splice(r,1),o={...a,pinned:n,sidebarOrder:Date.now()};return{...e,sessions:R3(i,o)}}function fWe(e,t,n,r){let i=e.sessions.findIndex(e=>e.piboSessionId===t),a=e.sessions.findIndex(e=>e.piboSessionId===n);if(i<0||a<0||i===a)return e;let o=e.sessions[i],s=e.sessions[a];if(!!o.pinned!=!!s.pinned||o.archived||s.archived)return e;let c=[...e.sessions];c.splice(i,1);let l=c.findIndex(e=>e.piboSessionId===n);return c.splice(r===`before`?l:l+1,0,o),{...e,sessions:c}}function R3(e,t){let n=[...e],r;return r=t.pinned?n.findIndex(e=>!e.archived):n.findIndex(e=>!e.pinned&&!e.archived),r<0&&(r=n.findIndex(e=>!!e.archived)),r<0&&(r=n.length),n.splice(r,0,t),n}function pWe(e,t){let n=z3(e.sessions,t),r=t.has(e.selectedPiboSessionId);return{...e,selectedPiboSessionId:r?``:e.selectedPiboSessionId,sessions:n}}function z3(e,t){let n=!1,r=[];for(let i of e){if(t.has(i.piboSessionId)){n=!0;continue}let e=z3(i.children,t);e===i.children?r.push(i):(n=!0,r.push({...i,children:e}))}return n?r:e}function B3(e){let t=new Set([e.piboSessionId]);for(let n of e.children)for(let e of B3(n))t.add(e);return t}function mWe(e,t,n){if(!t)return L3(e,n);let r=!1,i=J3(e.sessions,t,()=>(r=!0,n));return{...e,selectedPiboSessionId:e.selectedPiboSessionId===t?n.piboSessionId:e.selectedPiboSessionId,session:e.session.id===t?X3(n,e.session):e.session,sessions:r?i:R3(i,n)}}function hWe(e,t,n){let r=z3(e.sessions,new Set([t])),i=e.selectedPiboSessionId===t;return r===e.sessions&&!i?e:{...e,selectedPiboSessionId:i?n??``:e.selectedPiboSessionId,sessions:r}}function V3(e,t){let n=typeof t.metadata?.chatWebArchivedAt==`string`,r=typeof t.metadata?.chatWebPinnedAt==`string`,i=typeof t.metadata?.chatWebSidebarOrder==`number`?t.metadata.chatWebSidebarOrder:void 0;return{...e,session:e.session.id===t.id?t:e.session,sessions:J3(e.sessions,t.id,e=>({...e,profile:t.profile,activeModel:t.activeModel,title:t.title||e.title||`Untitled Session`,createdAt:t.createdAt,archived:n,pinned:r,sidebarOrder:i}))}}function H3(e,t,n){let r=e.session.id===t?X3(n(Y3(e.session)),e.session):e.session;return{...e,session:r,sessions:J3(e.sessions,t,n)}}function gWe(e,t){return Kq(e.rooms,t.id)?e:{...e,room:t,selectedRoomId:t.id,selectedPiboSessionId:``,rooms:[t,...e.rooms]}}function _We(e,t,n){let r=t!==n.id&&Kq(e.rooms,n.id)?K3(e.rooms,new Set([t])):G3(e.rooms,t,()=>n);return{...e,room:e.room?.id===t?n:e.room,selectedRoomId:e.selectedRoomId===t?n.id:e.selectedRoomId,rooms:Kq(r,n.id)?r:[n,...r]}}function U3(e,t,n){return{...e,room:e.room?.id===t?n(e.room):e.room,rooms:G3(e.rooms,t,n)}}function vWe(e,t,n){let r=e.rooms.findIndex(e=>e.id===t);if(r<0)return e;let i=[...e.rooms],[a]=i.splice(r,1);if(!a||Jq(a)||Yq(a))return e;let o={...a.metadata,chatRoomSidebarOrder:Date.now()};return n?o.chatRoomPinnedAt=new Date().toISOString():delete o.chatRoomPinnedAt,{...e,rooms:bWe(i,{...a,metadata:o})}}function yWe(e,t,n,r){let i=e.rooms.findIndex(e=>e.id===t),a=e.rooms.findIndex(e=>e.id===n);if(i<0||a<0||i===a)return e;let o=e.rooms[i],s=e.rooms[a];if(Jq(o)||Jq(s)||Yq(o)||Yq(s)||Xq(o)!==Xq(s))return e;let c=[...e.rooms];c.splice(i,1);let l=c.findIndex(e=>e.id===n);return c.splice(r===`before`?l:l+1,0,o),{...e,rooms:c}}function bWe(e,t){let n=[...e],r;return r=Xq(t)?n.findIndex(e=>!Jq(e)&&!Yq(e)):n.findIndex(e=>!Jq(e)&&!Yq(e)&&!Xq(e)),r<0&&(r=n.findIndex(e=>!Jq(e)&&Yq(e))),r<0&&(r=n.length),n.splice(r,0,t),n}function W3(e,t){let n=t.has(e.selectedRoomId);return{...e,room:e.room&&t.has(e.room.id)?void 0:e.room,selectedRoomId:n?``:e.selectedRoomId,selectedPiboSessionId:n?``:e.selectedPiboSessionId,rooms:K3(e.rooms,t)}}function G3(e,t,n){let r=!1,i=e.map(e=>{if(e.id===t)return r=!0,n(e);let i=e.children??[],a=G3(i,t,n);return a===i?e:(r=!0,{...e,children:a})});return r?i:e}function K3(e,t){let n=!1,r=[];for(let i of e){if(t.has(i.id)){n=!0;continue}let e=i.children??[],a=K3(e,t);a===e?r.push(i):(n=!0,r.push({...i,children:a}))}return n?r:e}function xWe(e,t){let n=new Date().toISOString();return{id:e,name:t,type:`chat`,createdAt:n,updatedAt:n,metadata:{},children:[]}}function q3(e){let t=new Set([e.id]);for(let n of e.children??[])for(let e of q3(n))t.add(e);return t}function J3(e,t,n){let r=!1,i=e.map(e=>{if(e.piboSessionId===t)return r=!0,n(e);let i=J3(e.children,t,n);return i===e.children?e:(r=!0,{...e,children:i})});return r?i:e}function SWe(e,t){return{piboSessionId:e,piSessionId:`pending`,profile:t,title:`New Session`,createdAt:new Date().toISOString(),status:`idle`,lastActivityAt:new Date().toISOString(),derivedSessions:[],children:[]}}function Y3(e){return{piboSessionId:e.id,piSessionId:e.piSessionId,profile:e.profile,activeModel:e.activeModel,title:e.title||`Untitled Session`,createdAt:e.createdAt,archived:typeof e.metadata?.chatWebArchivedAt==`string`,pinned:typeof e.metadata?.chatWebPinnedAt==`string`,sidebarOrder:typeof e.metadata?.chatWebSidebarOrder==`number`?e.metadata.chatWebSidebarOrder:void 0,status:`idle`,lastActivityAt:e.updatedAt,derivedSessions:[],children:[]}}function X3(e,t){return{...t,id:e.piboSessionId,piSessionId:e.piSessionId,profile:e.profile,activeModel:e.activeModel,title:Hq(e),updatedAt:e.lastActivityAt??t.updatedAt}}function Z3(e,t){for(let n of e){if(n.piboSessionId===t)return n;let e=Z3(n.children,t);if(e)return e}}function CWe(e){let t=e.trim();if(t.length>=2){let e=t[0],n=t[t.length-1];if(e===`"`&&n===`"`||e===`'`&&n===`'`)return t.slice(1,-1).trim()}return t}function wWe(e,t){if(e===`thinking`&&t)return{level:t.split(/\s+/,1)[0]};if(e===`compact`&&t)return{customInstructions:t};if(e===`goal`)return{command:t}}function TWe(e){return!Q3(e)||!Q3(e.result)?null:e}function EWe(e){if(!(!Q3(e)||!Q3(e.result)))return typeof e.result.piboSessionId==`string`?e.result.piboSessionId:void 0}function Q3(e){return!!e&&typeof e==`object`&&!Array.isArray(e)}function DWe(e){let t=e.flatMap(e=>e.slashCommands.filter(e=>e!==`tree`).map(t=>({slash:`/${t}`,action:e.name,description:e.name===`thinking`&&t===`thinking`?`Show thinking level or use /thinking <level>.`:e.description??e.name})));return t.push({slash:`/download`,action:`download`,description:`Download a file by absolute path or relative to the current working directory.`},{slash:`/upload`,action:`upload`,description:`Upload one or more files to the configured Pibo uploads directory.`},{slash:`/thinking-show`,action:`thinking-show`,description:`Toggle historical thinking display in this browser.`}),t}function OWe(e,t){if(!e)return[];let n=e.agentCatalog?.skills??[],r=e.agentCatalog?.userSkills??[],i=[...n,...r],a=OQ(e),o=t?kQ(e.sessions,t)?.profile??a:a,s=[...e.agents.map(e=>({name:e.name,skills:e.skills})),...e.customAgents.map(e=>({name:e.profileName,skills:e.skills}))].find(e=>e.name===o),c=new Set(s?.skills??[]);return i.filter(e=>c.has(e.name))}function kWe(e,t){let n=e.area===`sessions`?e.roomId:void 0,r=e.area===`sessions`||e.area===`context`?e.piboSessionId:void 0,i=n?t.sessionsByRoom?.[n]:t.piboSessionId;return{requestedRoomId:e.area===`sessions`?n??(r?void 0:t.roomId):e.area===`context`&&r?void 0:t.roomId,requestedPiboSessionId:e.area===`sessions`?r??(r?void 0:i):e.area===`context`?r:t.piboSessionId}}function AWe(e){let{bootstrap:t,creatingSession:n,route:r}=e,i=r.area===`sessions`||r.area===`context`?r.piboSessionId:void 0;return t&&r.area!==`sessions`&&(r.area!==`context`||!i||t.selectedPiboSessionId===i)||n?!0:!!(t&&r.area===`sessions`&&r.piboSessionId&&t.selectedPiboSessionId===r.piboSessionId&&t.selectedRoomId===r.roomId)}function jWe(e,t){if(e.area===`sessions`&&t.selectedPiboSessionId&&(e.roomId!==t.selectedRoomId||e.piboSessionId!==t.selectedPiboSessionId))return t}function MWe(e){return e.area===`sessions`&&!!(e.roomId||e.piboSessionId)}function NWe(e){if(!(!e||typeof e!=`object`||!(`status`in e)))return typeof e.status==`number`?e.status:void 0}function PWe(e){return e instanceof Error?e.message:String(e)}function FWe(e){let t=NWe(e),n=PWe(e);return t===401||t===403?{kind:`authentication-required`,message:n}:e instanceof TypeError||/failed to fetch|network(?:error| request failed)|internet disconnected|load failed/i.test(n)?{kind:`load-failed`,message:`Could not connect to Pibo Chat. Check your network connection and try again.`}:t!==void 0&&t>=500?{kind:`load-failed`,message:`Could not load Pibo Chat. The server may be unavailable. Try again.`}:{kind:`load-failed`,message:`Could not load Pibo Chat. Try again.`}}function $3(e,t){return t===`archivedAt`?e.metadata?.chatRoomArchivedAt:e[t]}function e6(e,t){let n={...e};return`name`in t&&(n.name=t.name),`topic`in t&&(n.topic=t.topic),`workspace`in t&&(n.workspace=t.workspace,n.metadata={...n.metadata},t.workspace===void 0?delete n.metadata.workspace:n.metadata.workspace=t.workspace),`archivedAt`in t&&(n.metadata={...n.metadata},t.archivedAt===void 0?delete n.metadata.chatRoomArchivedAt:n.metadata.chatRoomArchivedAt=t.archivedAt),n}function t6(e){for(let t=e.layers.length-1;t>=0;t--){let n=e.layers[t];if(n.status!==`failure`)return n.value}return e.base}var IWe=class{rooms=new Map;begin(e,t){let n={};t.name!==void 0&&(n.name=t.name),t.topic!==void 0&&(n.topic=t.topic??void 0),t.workspace!==void 0&&(n.workspace=t.workspace??void 0),t.archived!==void 0&&(n.archivedAt=t.archived?new Date().toISOString():void 0);let r=this.rooms.get(e.id)??new Map;this.rooms.set(e.id,r);let i={roomId:e.id,layers:new Map};for(let t of Object.keys(n)){let a=r.get(t)??{base:$3(e,t),layers:[]},o={value:n[t],status:`pending`};a.layers.push(o),r.set(t,a),i.layers.set(t,o)}return i}settle(e,t){let n=this.rooms.get(e.roomId),r={};for(let[i,a]of e.layers){a.status=t?`success`:`failure`,t&&(a.value=$3(t,i));let e=n.get(i);r[i]=t6(e),e.layers.some(e=>e.status===`pending`)||n.delete(i)}return n.size===0&&this.rooms.delete(e.roomId),n=>U3(n,e.roomId,e=>{let n=e6(e,r);return t&&t.updatedAt>n.updatedAt&&(n.updatedAt=t.updatedAt),n})}apply(e){let t=e;for(let[e,n]of this.rooms){let r={};for(let[e,t]of n)r[e]=t6(t);t=U3(t,e,e=>e6(e,r))}return t}};function n6({activePanel:e,onSelect:t,piPackageCount:n,userSkillCount:r}){return(0,U.jsx)(`div`,{className:`p-2`,children:(0,U.jsxs)(`div`,{className:`mb-4`,children:[(0,U.jsx)(`div`,{className:`px-1 pb-1 text-[10px] font-bold uppercase tracking-wider text-slate-500`,children:`Settings`}),(0,U.jsxs)(`button`,{type:`button`,onClick:()=>t(`general`),className:`mb-1 flex w-full items-center gap-2 border p-2 text-left ${e===`general`?`border-[#11a4d4] bg-[#11a4d4]/10`:`border-slate-800 bg-[#151f24] hover:border-slate-700`}`,children:[(0,U.jsx)(hl,{size:13,className:`text-[#11a4d4]`}),(0,U.jsxs)(`div`,{className:`min-w-0`,children:[(0,U.jsx)(`span`,{className:`block truncate text-sm text-slate-200`,children:`General`}),(0,U.jsx)(`span`,{className:`block truncate font-mono text-[10px] text-slate-500`,children:`browser + runtime`})]})]}),(0,U.jsxs)(`button`,{type:`button`,onClick:()=>t(`debug`),className:`mb-1 flex w-full items-center gap-2 border p-2 text-left ${e===`debug`?`border-[#11a4d4] bg-[#11a4d4]/10`:`border-slate-800 bg-[#151f24] hover:border-slate-700`}`,children:[(0,U.jsx)(Vs,{size:13,className:`text-[#11a4d4]`}),(0,U.jsxs)(`div`,{className:`min-w-0`,children:[(0,U.jsx)(`span`,{className:`block truncate text-sm text-slate-200`,children:`Debug`}),(0,U.jsx)(`span`,{className:`block truncate font-mono text-[10px] text-slate-500`,children:`tool metric signals`})]})]}),(0,U.jsxs)(`button`,{type:`button`,onClick:()=>t(`concurrency`),className:`mb-1 flex w-full items-center gap-2 border p-2 text-left ${e===`concurrency`?`border-[#11a4d4] bg-[#11a4d4]/10`:`border-slate-800 bg-[#151f24] hover:border-slate-700`}`,children:[(0,U.jsx)(xc,{size:13,className:`text-[#11a4d4]`}),(0,U.jsxs)(`div`,{className:`min-w-0`,children:[(0,U.jsx)(`span`,{className:`block truncate text-sm text-slate-200`,children:`Concurrency`}),(0,U.jsx)(`span`,{className:`block truncate font-mono text-[10px] text-slate-500`,children:`yielded runs`})]})]}),(0,U.jsxs)(`button`,{type:`button`,onClick:()=>t(`previews`),className:`mb-1 flex w-full items-center gap-2 border p-2 text-left ${e===`previews`?`border-[#11a4d4] bg-[#11a4d4]/10`:`border-slate-800 bg-[#151f24] hover:border-slate-700`}`,children:[(0,U.jsx)(Wc,{size:13,className:`text-[#11a4d4]`}),(0,U.jsxs)(`div`,{className:`min-w-0`,children:[(0,U.jsx)(`span`,{className:`block truncate text-sm text-slate-200`,children:`Previews`}),(0,U.jsx)(`span`,{className:`block truncate font-mono text-[10px] text-slate-500`,children:`server pool + lease`})]})]}),(0,U.jsxs)(`button`,{type:`button`,onClick:()=>t(`transcription`),className:`mb-1 flex w-full items-center gap-2 border p-2 text-left ${e===`transcription`?`border-[#11a4d4] bg-[#11a4d4]/10`:`border-slate-800 bg-[#151f24] hover:border-slate-700`}`,children:[(0,U.jsx)(Hc,{size:13,className:`text-[#11a4d4]`}),(0,U.jsxs)(`div`,{className:`min-w-0`,children:[(0,U.jsx)(`span`,{className:`block truncate text-sm text-slate-200`,children:`Transcription`}),(0,U.jsx)(`span`,{className:`block truncate font-mono text-[10px] text-slate-500`,children:`audio provider`})]})]}),(0,U.jsxs)(`button`,{type:`button`,onClick:()=>t(`speech`),className:`mb-1 flex w-full items-center gap-2 border p-2 text-left ${e===`speech`?`border-[#11a4d4] bg-[#11a4d4]/10`:`border-slate-800 bg-[#151f24] hover:border-slate-700`}`,children:[(0,U.jsx)(Ol,{size:13,className:`text-[#11a4d4]`}),(0,U.jsxs)(`div`,{className:`min-w-0`,children:[(0,U.jsx)(`span`,{className:`block truncate text-sm text-slate-200`,children:`Speech`}),(0,U.jsx)(`span`,{className:`block truncate font-mono text-[10px] text-slate-500`,children:`text-to-speech`})]})]}),(0,U.jsxs)(`button`,{type:`button`,onClick:()=>t(`shortcuts`),className:`mb-1 flex w-full items-center gap-2 border p-2 text-left ${e===`shortcuts`?`border-[#11a4d4] bg-[#11a4d4]/10`:`border-slate-800 bg-[#151f24] hover:border-slate-700`}`,children:[(0,U.jsx)(Oc,{size:13,className:`text-[#11a4d4]`}),(0,U.jsxs)(`div`,{className:`min-w-0`,children:[(0,U.jsx)(`span`,{className:`block truncate text-sm text-slate-200`,children:`Shortcuts`}),(0,U.jsx)(`span`,{className:`block truncate font-mono text-[10px] text-slate-500`,children:`keyboard`})]})]}),(0,U.jsxs)(`button`,{type:`button`,onClick:()=>t(`maintenance`),className:`mb-1 flex w-full items-center gap-2 border p-2 text-left ${e===`maintenance`?`border-[#11a4d4] bg-[#11a4d4]/10`:`border-slate-800 bg-[#151f24] hover:border-slate-700`}`,children:[(0,U.jsx)(uc,{size:13,className:`text-[#11a4d4]`}),(0,U.jsxs)(`div`,{className:`min-w-0`,children:[(0,U.jsx)(`span`,{className:`block truncate text-sm text-slate-200`,children:`Maintenance`}),(0,U.jsx)(`span`,{className:`block truncate font-mono text-[10px] text-slate-500`,children:`telemetry retention`})]})]}),(0,U.jsxs)(`button`,{type:`button`,onClick:()=>t(`pi-packages`),className:`mb-1 flex w-full items-center gap-2 border p-2 text-left ${e===`pi-packages`?`border-[#11a4d4] bg-[#11a4d4]/10`:`border-slate-800 bg-[#151f24] hover:border-slate-700`}`,children:[(0,U.jsx)(kc,{size:13,className:`text-[#11a4d4]`}),(0,U.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,U.jsx)(`span`,{className:`block truncate text-sm text-slate-200`,children:`Pi Packages`}),(0,U.jsx)(`span`,{className:`block truncate font-mono text-[10px] text-slate-500`,children:`runtime-packages`})]}),(0,U.jsx)(`span`,{className:`inline-flex min-w-6 items-center justify-center border border-slate-700 bg-[#101d22] px-1.5 py-0.5 text-[10px] font-mono text-slate-400`,children:n})]}),(0,U.jsxs)(`button`,{type:`button`,onClick:()=>t(`skills`),className:`mb-1 flex w-full items-center gap-2 border p-2 text-left ${e===`skills`?`border-[#11a4d4] bg-[#11a4d4]/10`:`border-slate-800 bg-[#151f24] hover:border-slate-700`}`,children:[(0,U.jsx)(Al,{size:13,className:`text-[#11a4d4]`}),(0,U.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,U.jsx)(`span`,{className:`block truncate text-sm text-slate-200`,children:`Skills`}),(0,U.jsx)(`span`,{className:`block truncate font-mono text-[10px] text-slate-500`,children:`user-managed`})]}),(0,U.jsx)(`span`,{className:`inline-flex min-w-6 items-center justify-center border border-slate-700 bg-[#101d22] px-1.5 py-0.5 text-[10px] font-mono text-slate-400`,children:r})]}),(0,U.jsxs)(`button`,{type:`button`,onClick:()=>t(`providers`),className:`flex w-full items-center gap-2 border p-2 text-left ${e===`providers`?`border-[#11a4d4] bg-[#11a4d4]/10`:`border-slate-800 bg-[#151f24] hover:border-slate-700`}`,children:[(0,U.jsx)(Dc,{size:13,className:`text-[#11a4d4]`}),(0,U.jsxs)(`div`,{className:`min-w-0`,children:[(0,U.jsx)(`span`,{className:`block truncate text-sm text-slate-200`,children:`Providers`}),(0,U.jsx)(`span`,{className:`block truncate font-mono text-[10px] text-slate-500`,children:`auth + api keys`})]})]})]})})}function LWe({debugMode:e,onDebugModeChange:t,thresholds:n,onThresholdsChange:r}){let[i,a]=(0,H.useState)(()=>i6(n)),[o,s]=(0,H.useState)(null),[c,l]=(0,H.useState)(null);(0,H.useEffect)(()=>a(i6(n)),[n]);let u=(e,t)=>{a(n=>({...n,[e]:t})),s(null),l(null)};return(0,U.jsx)(kJ,{title:`Tool diagnostics`,children:(0,U.jsxs)(`div`,{className:`max-w-3xl`,children:[(0,U.jsx)(PJ,{checked:e,title:`Show Tool Debug metrics`,onToggle:()=>t(!e)}),(0,U.jsx)(`p`,{className:`mt-3 text-xs leading-relaxed text-slate-400`,children:`Thresholds control only the signal-rail colors. Payload counts are diagnostics rather than provider usage or billing; the signal rail records the selected calculation method with every completed Tool call.`}),(0,U.jsx)(RWe,{}),(0,U.jsxs)(`div`,{className:`mt-5 grid gap-4`,children:[(0,U.jsx)(r6,{legend:`Execution time`,unit:`seconds`,values:[i.durationElevated,i.durationHigh,i.durationCritical],onChange:(e,t)=>u([`durationElevated`,`durationHigh`,`durationCritical`][e],t)}),(0,U.jsx)(r6,{legend:`Estimated input payload`,unit:`tokens`,values:[i.inputElevated,i.inputHigh,i.inputCritical],onChange:(e,t)=>u([`inputElevated`,`inputHigh`,`inputCritical`][e],t)}),(0,U.jsx)(r6,{legend:`Estimated output payload`,unit:`tokens`,values:[i.outputElevated,i.outputHigh,i.outputCritical],onChange:(e,t)=>u([`outputElevated`,`outputHigh`,`outputCritical`][e],t)})]}),(0,U.jsxs)(`div`,{className:`mt-5 flex flex-wrap items-center gap-2`,children:[(0,U.jsx)(`button`,{type:`button`,onClick:()=>{let e=zWe(i);if(!e){s(null),l(`Each row must contain three positive, increasing values.`);return}r(e),l(null),s(`Debug thresholds saved in this browser.`)},className:`border border-[#11a4d4] bg-[#11a4d4]/15 px-3 py-1.5 text-xs font-semibold text-cyan-100 hover:bg-[#11a4d4]/25`,children:`Save thresholds`}),(0,U.jsx)(`button`,{type:`button`,onClick:()=>{r(a$),a(i6(a$)),l(null),s(`Default Debug thresholds restored.`)},className:`border border-slate-700 bg-[#151f24] px-3 py-1.5 text-xs text-slate-300 hover:border-slate-600`,children:`Restore defaults`})]}),o?(0,U.jsx)(`p`,{role:`status`,className:`mt-3 text-xs text-emerald-300`,children:o}):null,c?(0,U.jsx)(`p`,{role:`alert`,className:`mt-3 text-xs text-red-300`,children:c}):null]})})}function RWe(){let e=kn(),{data:t,isLoading:n}=Wn({queryKey:[`user-settings`],queryFn:qH}),[r,i]=(0,H.useState)(hVe.method),[a,o]=(0,H.useState)(`4`),[s,c]=(0,H.useState)(`o200k_base`),[l,u]=(0,H.useState)(!1),[d,f]=(0,H.useState)(null),[p,m]=(0,H.useState)(null);(0,H.useEffect)(()=>{let e=t?.toolMetrics.tokenCalculation;e&&(i(e.method),e.method===`characters`?o(String(e.factor)):c(e.encoding))},[t]);let h=async()=>{let t=Number(a),n=r===`characters`?Number.isFinite(t)&&t>0?{method:r,factor:t}:void 0:{method:r,encoding:s};if(!n){f(null),m(`Character factor must be greater than zero.`);return}u(!0),f(null),m(null);try{let t=await JH({toolMetrics:{tokenCalculation:n}});e.setQueryData([`user-settings`],t),f(`Token calculation saved. Future Tool calls use this method.`)}catch(e){m(e instanceof Error?e.message:String(e))}finally{u(!1)}};return(0,U.jsxs)(`fieldset`,{className:`mt-5 border border-slate-800 bg-[#111820] p-3`,children:[(0,U.jsx)(`legend`,{className:`px-1 text-xs font-semibold text-slate-200`,children:`Token calculation`}),(0,U.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,U.jsxs)(`label`,{htmlFor:`tool-token-calculation-method`,className:`text-[11px] text-slate-400`,children:[(0,U.jsx)(`span`,{className:`mb-1 block font-semibold uppercase tracking-wide`,children:`Method`}),(0,U.jsxs)(`select`,{id:`tool-token-calculation-method`,value:r,disabled:n||l,onChange:e=>{i(e.target.value),f(null),m(null)},className:`w-full border border-slate-700 bg-[#0b1115] px-2 py-1.5 text-xs text-slate-100 outline-none focus:border-[#11a4d4]`,children:[(0,U.jsx)(`option`,{value:`characters`,children:`Characters ÷ factor`}),(0,U.jsx)(`option`,{value:`tiktoken`,children:`Tiktoken`})]})]}),r===`characters`?(0,U.jsxs)(`label`,{htmlFor:`tool-token-character-factor`,className:`text-[11px] text-slate-400`,children:[(0,U.jsx)(`span`,{className:`mb-1 block font-semibold uppercase tracking-wide`,children:`Characters per token`}),(0,U.jsx)(`input`,{id:`tool-token-character-factor`,type:`number`,min:`0.1`,step:`0.1`,value:a,disabled:l,onChange:e=>o(e.target.value),className:`w-full border border-slate-700 bg-[#0b1115] px-2 py-1.5 font-mono text-xs tabular-nums text-slate-100 outline-none focus:border-[#11a4d4]`})]}):(0,U.jsxs)(`label`,{htmlFor:`tool-token-tiktoken-encoding`,className:`text-[11px] text-slate-400`,children:[(0,U.jsx)(`span`,{className:`mb-1 block font-semibold uppercase tracking-wide`,children:`Encoding`}),(0,U.jsx)(`select`,{id:`tool-token-tiktoken-encoding`,value:s,disabled:l,onChange:e=>c(e.target.value),className:`w-full border border-slate-700 bg-[#0b1115] px-2 py-1.5 font-mono text-xs text-slate-100 outline-none focus:border-[#11a4d4]`,children:mVe.map(e=>(0,U.jsx)(`option`,{value:e,children:e},e))})]})]}),(0,U.jsx)(`p`,{className:`mt-3 text-[11px] leading-relaxed text-slate-500`,children:`Character mode keeps the bounded structural estimate and divides it by the selected factor. Tiktoken lazily loads its WASM tokenizer and encodes the serialized payload at Tool start and finish, which uses more CPU and memory. Neither method is provider billing attribution.`}),(0,U.jsx)(`button`,{type:`button`,onClick:()=>void h(),disabled:n||l,className:`mt-3 border border-[#11a4d4] bg-[#11a4d4]/15 px-3 py-1.5 text-xs font-semibold text-cyan-100 hover:bg-[#11a4d4]/25 disabled:opacity-60`,children:l?`Saving…`:`Save calculation`}),d?(0,U.jsx)(`p`,{role:`status`,className:`mt-3 text-xs text-emerald-300`,children:d}):null,p?(0,U.jsx)(`p`,{role:`alert`,className:`mt-3 text-xs text-red-300`,children:p}):null]})}function r6({legend:e,unit:t,values:n,onChange:r}){return(0,U.jsxs)(`fieldset`,{className:`border border-slate-800 bg-[#111820] p-3`,children:[(0,U.jsx)(`legend`,{className:`px-1 text-xs font-semibold text-slate-200`,children:e}),(0,U.jsx)(`div`,{className:`grid gap-3 sm:grid-cols-3`,children:[`Elevated`,`High`,`Critical`].map((i,a)=>{let o=`${e.toLowerCase().replaceAll(` `,`-`)}-${i.toLowerCase()}`;return(0,U.jsxs)(`label`,{htmlFor:o,className:`text-[11px] text-slate-400`,children:[(0,U.jsx)(`span`,{className:`mb-1 block font-semibold uppercase tracking-wide`,children:i}),(0,U.jsxs)(`div`,{className:`flex items-center border border-slate-700 bg-[#0b1115] focus-within:border-[#11a4d4]`,children:[(0,U.jsx)(`input`,{id:o,type:`number`,min:t===`seconds`?`0.1`:`1`,step:t===`seconds`?`0.1`:`1`,value:n[a],onChange:e=>r(a,e.target.value),className:`min-w-0 flex-1 bg-transparent px-2 py-1.5 font-mono text-xs tabular-nums text-slate-100 outline-none`}),(0,U.jsx)(`span`,{className:`border-l border-slate-800 px-2 text-[10px] text-slate-500`,children:t})]})]},i)})})]})}function i6(e){return{durationElevated:String(e.durationMs.elevated/1e3),durationHigh:String(e.durationMs.high/1e3),durationCritical:String(e.durationMs.critical/1e3),inputElevated:String(e.inputTokens.elevated),inputHigh:String(e.inputTokens.high),inputCritical:String(e.inputTokens.critical),outputElevated:String(e.outputTokens.elevated),outputHigh:String(e.outputTokens.high),outputCritical:String(e.outputTokens.critical)}}function zWe(e){let t=[e.durationElevated,e.durationHigh,e.durationCritical].map(e=>Math.round(Number(e)*1e3)),n=[e.inputElevated,e.inputHigh,e.inputCritical].map(Number),r=[e.outputElevated,e.outputHigh,e.outputCritical].map(Number);return!a6(t)||!a6(n)||!a6(r)?null:{durationMs:{elevated:t[0],high:t[1],critical:t[2]},inputTokens:{elevated:n[0],high:n[1],critical:n[2]},outputTokens:{elevated:r[0],high:r[1],critical:r[2]}}}function a6(e){return e.every(e=>Number.isSafeInteger(e)&&e>0)&&e[0]<e[1]&&e[1]<e[2]}function BWe({piboSessionId:e,onProviderAuthChanged:t}){let[n,r]=(0,H.useState)(null),[i,a]=(0,H.useState)(!0),[o,s]=(0,H.useState)(null),[c,l]=(0,H.useState)(null),[u,d]=(0,H.useState)({}),[f,p]=(0,H.useState)({}),[m,h]=(0,H.useState)({}),[g,_]=(0,H.useState)({}),[v,y]=(0,H.useState)(null),[b,x]=(0,H.useState)({}),S=(0,H.useRef)(!1),C=(0,H.useCallback)(async(e=!1)=>{e&&a(!0);try{r(await IVe()),s(null)}catch(e){s(e instanceof Error?e.message:String(e))}finally{a(!1)}},[]);(0,H.useEffect)(()=>{C(!0)},[C]);let w=(0,H.useMemo)(()=>n?.targets.flatMap(e=>e.providers.flatMap(t=>t.pending?.completion===`notification`?[{target:e,provider:t,flowId:t.pending.flowId}]:[]))??[],[n]);(0,H.useEffect)(()=>{if(w.length===0)return;let e=async()=>{if(!S.current){S.current=!0;try{for(let{target:e,provider:n,flowId:r}of w){let i=await m4({action:`complete`,runtimeInstanceId:e.runtimeInstanceId,providerId:n.id,flowId:r});(i.state===`connected`||i.state===`partial`)&&(f6(l,`${e.displayName} / ${n.displayName??n.id} is ${l6(i.state).toLowerCase()}.`),await t?.())}await C()}catch(e){s(e instanceof Error?e.message:String(e)),await C()}finally{S.current=!1}}},n=window.setInterval(()=>void e(),1500);return()=>window.clearInterval(n)},[w,t,C]);let T=(0,H.useCallback)(async(e,t)=>{x(t=>({...t,[e]:!0})),s(null),l(null);try{return await t()}catch(e){s(e instanceof Error?e.message:String(e));return}finally{x(t=>({...t,[e]:!1}))}},[]),E=(0,H.useCallback)(async(e,t,n)=>{let r=s6(e,t);await T(r,async()=>await m4({action:`start`,runtimeInstanceId:e.runtimeInstanceId,providerId:t.id,method:n}))&&await C()},[C,T]),D=(0,H.useCallback)(async(e,n,r)=>{if(!n.pending)return;let i=s6(e,n),a=await T(i,async()=>await m4({action:`complete`,runtimeInstanceId:e.runtimeInstanceId,providerId:n.id,flowId:n.pending.flowId,...r?{code:r}:{}}));a&&((a.state===`connected`||a.state===`partial`)&&(f6(l,`${e.displayName} / ${n.displayName??n.id} is ${l6(a.state).toLowerCase()}.`),p(e=>({...e,[i]:``})),await t?.()),await C())},[t,C,T]),O=(0,H.useCallback)(async(e,t)=>{if(!t.pending)return;let n=s6(e,t);await T(n,async()=>await m4({action:`cancel`,runtimeInstanceId:e.runtimeInstanceId,providerId:t.id,flowId:t.pending.flowId}))&&await C()},[C,T]),k=(0,H.useCallback)(async(e,n)=>{let r=s6(e,n),i=m[r]?.trim();i&&await T(r,async()=>await m4({action:`api_key`,runtimeInstanceId:e.runtimeInstanceId,providerId:n.id,apiKey:i}))&&(h(e=>({...e,[r]:``})),_(e=>({...e,[r]:!1})),d(e=>({...e,[r]:`collapsed`})),f6(l,`${e.displayName} / ${n.displayName??n.id} API key is configured.`),await t?.(),await C())},[m,t,C,T]),A=(0,H.useCallback)(async(e,n)=>{let r=s6(e,n);await T(r,async()=>await m4({action:`logout`,runtimeInstanceId:e.runtimeInstanceId,providerId:n.id}))&&(f6(l,`${e.displayName} / ${n.displayName??n.id} is disconnected.`),await t?.(),await C())},[t,C,T]),j=(0,H.useCallback)(async(e,t)=>{try{await navigator.clipboard.writeText(t),y(e),window.setTimeout(()=>y(t=>t===e?null:t),1800)}catch{}},[]);return(0,U.jsxs)(`div`,{className:`grid gap-4`,children:[(0,U.jsxs)(`div`,{className:`flex items-start justify-between gap-3 border border-slate-700 bg-[#1a262b] p-3`,children:[(0,U.jsxs)(`div`,{children:[(0,U.jsx)(`div`,{className:`text-xs font-bold uppercase tracking-wider text-slate-300`,children:`Runtime authentication targets`}),(0,U.jsx)(`div`,{className:`mt-1 text-[11px] leading-relaxed text-slate-500`,children:`Each target owns its effective account. The default runtime is marked below; credentials are never copied between runtimes.`})]}),(0,U.jsxs)(`button`,{type:`button`,disabled:i,onClick:()=>void C(!0),className:`inline-flex shrink-0 items-center gap-1 border border-slate-700 bg-[#0e1116] px-2 py-1 text-[11px] text-slate-300 hover:border-[#11a4d4] hover:text-[#11a4d4] disabled:opacity-50`,children:[(0,U.jsx)(ol,{size:12,className:i?`animate-spin`:``}),` Refresh`]})]}),o?(0,U.jsx)(d6,{tone:`red`,icon:(0,U.jsx)($s,{size:14}),children:o}):null,c?(0,U.jsx)(d6,{tone:`green`,icon:(0,U.jsx)(tc,{size:14}),children:c}):null,i&&!n?(0,U.jsx)(d6,{tone:`cyan`,icon:(0,U.jsx)(Pc,{size:14,className:`animate-spin`}),children:`Loading runtime authentication status...`}):null,n?.targets.map(e=>(0,U.jsxs)(`section`,{className:`border border-[#334155] bg-[#151f24]`,children:[(0,U.jsxs)(`header`,{className:`flex flex-wrap items-start justify-between gap-3 border-b border-slate-800 px-3 py-2.5`,children:[(0,U.jsxs)(`div`,{className:`min-w-0`,children:[(0,U.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,U.jsx)(ml,{size:14,className:`text-[#11a4d4]`}),(0,U.jsx)(`span`,{className:`text-sm font-medium text-slate-200`,children:e.displayName}),(0,U.jsx)(`span`,{className:`font-mono text-[10px] text-slate-500`,children:e.runtimeInstanceId}),e.isDefault?(0,U.jsx)(u6,{tone:`cyan`,children:`Default runtime`}):null,(0,U.jsx)(WWe,{state:e.state})]}),(0,U.jsx)(`div`,{className:`mt-1 text-[11px] text-slate-500`,children:e.credentialScope===`runtime-instance`?`Private account for this configured runtime instance.`:`Shared adapter credential store; changes apply to Pi instances using this adapter.`})]}),(0,U.jsx)(`div`,{className:`font-mono text-[10px] uppercase tracking-wider text-slate-600`,children:e.adapterId})]}),e.providers.length===0?(0,U.jsx)(`div`,{className:`px-3 py-3 text-xs text-slate-500`,children:e.state===`unsupported`?`This runtime does not expose provider authentication controls.`:`Provider authentication status is unavailable for this runtime.`}):e.providers.map(t=>{let n=s6(e,t),r=u[n]??`collapsed`,i=b[n]??!1,a=t.pending;return(0,U.jsxs)(`div`,{className:`border-b border-slate-800 last:border-b-0`,children:[(0,U.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3 px-3 py-3`,children:[(0,U.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,U.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,U.jsx)(`span`,{className:`text-sm text-slate-200`,children:t.displayName??t.id}),(0,U.jsx)(`span`,{className:`font-mono text-[10px] text-slate-600`,children:t.id}),t.methods.map(e=>(0,U.jsx)(u6,{tone:e.id===`api_key`?`amber`:`purple`,children:c6(e.id)},e.id))]}),(0,U.jsxs)(`div`,{className:`mt-1 flex flex-wrap items-center gap-2 text-[11px]`,children:[(0,U.jsx)(UWe,{state:t.state}),(0,U.jsx)(`span`,{className:HWe(t.state),children:l6(t.state)}),t.details?.accountType?(0,U.jsx)(`span`,{className:`text-slate-600`,children:GWe(t.details.accountType)}):null,t.details?.planType?(0,U.jsxs)(`span`,{className:`text-slate-600`,children:[`plan: `,t.details.planType]}):null]}),t.message?(0,U.jsx)(`div`,{className:`mt-1 text-[11px] text-slate-500`,children:t.message}):null]}),(0,U.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[t.state!==`pending`&&t.methods.map(a=>a.id===`api_key`?(0,U.jsxs)(`button`,{type:`button`,disabled:i||!e.available,onClick:()=>{let e=r===`api_key`;d(t=>({...t,[n]:e?`collapsed`:`api_key`})),e&&(h(e=>({...e,[n]:``})),_(e=>({...e,[n]:!1})))},className:o6,children:[(0,U.jsx)(Dc,{size:12}),` `,t.configured?`Replace key`:`API key`]},a.id):(0,U.jsxs)(`button`,{type:`button`,disabled:i||!e.available,onClick:()=>void E(e,t,a.id),className:o6,children:[i?(0,U.jsx)(Pc,{size:12,className:`animate-spin`}):(0,U.jsx)(Ic,{size:12}),` `,t.configured?`Reconnect`:c6(a.id)]},a.id)),(t.configured||t.state===`failed`)&&e.logoutSupported?(0,U.jsxs)(`button`,{type:`button`,disabled:i,onClick:()=>void A(e,t),className:`${o6} hover:!border-red-500 hover:!text-red-300`,children:[(0,U.jsx)(Cl,{size:12}),` `,t.configured?`Disconnect`:`Reset auth`]}):null]})]}),a?(0,U.jsx)(VWe,{flow:a,rowKey:n,busy:i,code:f[n]??``,onCodeChange:e=>p(t=>({...t,[n]:e})),onComplete:n=>void D(e,t,n),onCancel:e.cancelSupported?()=>void O(e,t):void 0,copied:v,onCopy:j}):r===`api_key`?(0,U.jsxs)(`div`,{className:`grid gap-2 border-t border-slate-800 bg-[#10191d] px-3 py-3`,children:[(0,U.jsxs)(`div`,{className:`text-[10px] font-bold uppercase tracking-wider text-slate-500`,children:[`API key for `,e.runtimeInstanceId]}),(0,U.jsxs)(`div`,{className:`relative`,children:[(0,U.jsx)(`input`,{type:g[n]?`text`:`password`,value:m[n]??``,autoComplete:`off`,spellCheck:!1,onChange:e=>h(t=>({...t,[n]:e.target.value})),onKeyDown:n=>{n.key===`Enter`&&k(e,t)},placeholder:`Enter provider API key`,className:`w-full border border-slate-700 bg-[#0e1116] px-2 py-1.5 pr-8 font-mono text-[12px] text-slate-300 outline-none placeholder:text-slate-600 focus:border-[#11a4d4]`}),(0,U.jsx)(`button`,{type:`button`,onClick:()=>_(e=>({...e,[n]:!e[n]})),className:`absolute right-2 top-1/2 -translate-y-1/2 text-slate-500 hover:text-[#11a4d4]`,"aria-label":g[n]?`Hide API key`:`Show API key`,children:g[n]?(0,U.jsx)(pc,{size:14}):(0,U.jsx)(mc,{size:14})})]}),(0,U.jsxs)(`div`,{className:`flex gap-2`,children:[(0,U.jsxs)(`button`,{type:`button`,disabled:i||!(m[n]??``).trim(),onClick:()=>void k(e,t),className:o6,children:[i?(0,U.jsx)(Pc,{size:12,className:`animate-spin`}):(0,U.jsx)(tc,{size:12}),` Save for this target`]}),(0,U.jsx)(`button`,{type:`button`,onClick:()=>{h(e=>({...e,[n]:``})),_(e=>({...e,[n]:!1})),d(e=>({...e,[n]:`collapsed`}))},className:`text-[11px] text-slate-500 hover:text-[#11a4d4]`,children:`Cancel`})]})]}):null]},t.id)}),e.diagnostics.some(e=>e.severity!==`info`)?(0,U.jsx)(`div`,{className:`border-t border-slate-800 px-3 py-2 text-[11px] text-slate-500`,children:e.diagnostics.find(e=>e.severity===`error`)?.message??e.diagnostics.find(e=>e.severity===`warning`)?.message}):null]},e.runtimeInstanceId)),n&&n.targets.length===0?(0,U.jsx)(`div`,{className:`border border-slate-700 bg-[#1a262b] p-4 text-sm text-slate-500`,children:`No configured runtime authentication targets are available.`}):null]})}function VWe({flow:e,rowKey:t,busy:n,code:r,onCodeChange:i,onComplete:a,onCancel:o,copied:s,onCopy:c}){let l=e.method===`browser_oauth`&&!e.userCode;return(0,U.jsxs)(`div`,{className:`grid gap-3 border-t border-slate-800 bg-[#10191d] px-3 py-3 text-[11px]`,children:[(0,U.jsxs)(`div`,{className:`flex items-center gap-2 text-[#11a4d4]`,children:[e.completion===`notification`?(0,U.jsx)(Pc,{size:13,className:`animate-spin`}):(0,U.jsx)(ic,{size:13}),e.completion===`notification`?`Waiting for the runtime's completion notification...`:`Login flow is pending.`]}),e.verificationUrl?(0,U.jsxs)(`div`,{className:`grid gap-1.5`,children:[(0,U.jsx)(`div`,{className:`text-[10px] font-bold uppercase tracking-wider text-slate-500`,children:`Verification URL`}),(0,U.jsx)(`div`,{className:`break-all border border-slate-700 bg-[#0e1116] p-2 font-mono text-slate-300`,children:e.verificationUrl}),(0,U.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,U.jsxs)(`button`,{type:`button`,onClick:()=>void c(`${t}:url`,e.verificationUrl),className:o6,children:[s===`${t}:url`?(0,U.jsx)(tc,{size:12}):(0,U.jsx)(sc,{size:12}),` `,s===`${t}:url`?`Copied`:`Copy URL`]}),(0,U.jsxs)(`a`,{href:e.verificationUrl,target:`_blank`,rel:`noreferrer`,className:o6,children:[(0,U.jsx)(fc,{size:12}),` Open in browser`]})]})]}):null,e.userCode?(0,U.jsxs)(`div`,{className:`grid gap-1.5`,children:[(0,U.jsx)(`div`,{className:`text-[10px] font-bold uppercase tracking-wider text-slate-500`,children:`One-time code`}),(0,U.jsxs)(`button`,{type:`button`,onClick:()=>void c(`${t}:code`,e.userCode),className:`w-fit border border-[#1f4960] bg-[#0e1116] px-3 py-2 font-mono text-lg font-bold tracking-[0.2em] text-[#11a4d4] hover:border-[#11a4d4]`,children:[e.userCode,` `,s===`${t}:code`?(0,U.jsx)(tc,{size:12,className:`inline`}):null]})]}):null,e.instructions?(0,U.jsx)(`div`,{className:`text-slate-500`,children:e.instructions}):null,l?(0,U.jsx)(`input`,{value:r,autoComplete:`off`,spellCheck:!1,onChange:e=>i(e.target.value),placeholder:`Paste authorization code`,className:`border border-slate-700 bg-[#0e1116] px-2 py-1.5 font-mono text-slate-300 outline-none placeholder:text-slate-600 focus:border-[#11a4d4]`}):null,(0,U.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[e.completion===`explicit`?(0,U.jsxs)(`button`,{type:`button`,disabled:n||l&&!r.trim(),onClick:()=>a(l?r.trim():void 0),className:o6,children:[n?(0,U.jsx)(Pc,{size:12,className:`animate-spin`}):(0,U.jsx)(tc,{size:12}),` Complete login`]}):null,o?(0,U.jsxs)(`button`,{type:`button`,disabled:n,onClick:o,className:`${o6} hover:!border-red-500 hover:!text-red-300`,children:[(0,U.jsx)(rc,{size:12}),` Cancel flow`]}):null]})]})}var o6=`inline-flex items-center gap-1 border border-slate-700 bg-[#0e1116] px-2 py-1 text-[11px] text-slate-300 hover:border-[#11a4d4] hover:text-[#11a4d4] disabled:opacity-50`;function s6(e,t){return`${e.runtimeInstanceId}:${t.id}`}function c6(e){return e===`api_key`?`API key`:e===`browser_oauth`?`Browser OAuth`:`Device code`}function l6(e){return e.charAt(0).toUpperCase()+e.slice(1)}function HWe(e){return e===`connected`?`text-[#0bda57]`:e===`pending`?`text-[#11a4d4]`:e===`partial`?`text-amber-300`:e===`failed`?`text-red-300`:`text-slate-500`}function UWe({state:e}){return e===`connected`?(0,U.jsx)(tc,{size:12,className:`text-[#0bda57]`}):e===`pending`?(0,U.jsx)(Pc,{size:12,className:`animate-spin text-[#11a4d4]`}):e===`failed`?(0,U.jsx)($s,{size:12,className:`text-red-400`}):e===`partial`?(0,U.jsx)($s,{size:12,className:`text-amber-300`}):(0,U.jsx)(Ic,{size:12,className:`text-slate-500`})}function WWe({state:e}){return(0,U.jsx)(u6,{tone:e===`connected`?`green`:e===`pending`?`cyan`:e===`partial`?`amber`:e===`failed`?`red`:`neutral`,children:l6(e)})}function u6({tone:e,children:t}){return(0,U.jsx)(`span`,{className:`border px-1.5 py-0.5 text-[10px] font-mono uppercase tracking-wider ${e===`cyan`?`border-[#11a4d4]/40 text-[#6dd7f6]`:e===`green`?`border-[#0bda57]/40 text-[#7cf2a2]`:e===`amber`?`border-amber-500/40 text-amber-300`:e===`purple`?`border-purple-500/40 text-purple-300`:e===`red`?`border-red-500/40 text-red-300`:`border-slate-700 text-slate-500`}`,children:t})}function d6({tone:e,icon:t,children:n}){return(0,U.jsxs)(`div`,{className:`flex items-center gap-2 border px-3 py-2 text-xs ${e===`red`?`border-red-500/30 bg-red-500/10 text-red-300`:e===`green`?`border-[#0bda57]/30 bg-[#0bda57]/10 text-[#7cf2a2]`:`border-[#11a4d4]/30 bg-[#11a4d4]/10 text-[#6dd7f6]`}`,children:[t,n]})}function GWe(e){return e===`api_key`?`API key account`:e===`chatgpt`?`ChatGPT account`:e===`oauth`?`OAuth account`:`Managed account`}function f6(e,t){e(t),window.setTimeout(()=>e(e=>e===t?null:e),5e3)}function p6({activePanel:e,showThinking:t,setShowThinking:n,expandThinking:r,setExpandThinking:i,debugMode:a,onDebugModeChange:o,toolMetricThresholds:s,onToolMetricThresholdsChange:c,modelDefaults:l,modelCatalog:u,onModelDefaultsChanged:d,piPackages:f,onPiPackageChanged:p,onPiPackageRemoved:m,userSkills:h,onUserSkillChanged:g,onUserSkillRemoved:_,piboSessionId:v,onProviderAuthChanged:y}){return e===`pi-packages`?(0,U.jsxs)(`div`,{className:`p-6 overflow-auto`,children:[(0,U.jsxs)(`h1`,{className:`text-sm font-bold uppercase tracking-wider mb-4 flex items-center gap-2`,children:[(0,U.jsx)(kc,{size:16}),`Pi Packages`]}),(0,U.jsx)(aGe,{packages:f,onPackageChanged:p,onPackageRemoved:m})]}):e===`skills`?(0,U.jsxs)(`div`,{className:`overflow-auto p-6 max-[640px]:p-3`,children:[(0,U.jsxs)(`h1`,{className:`mb-4 flex items-center gap-2 text-sm font-bold uppercase tracking-wider`,children:[(0,U.jsx)(Al,{size:16}),`Skills`]}),(0,U.jsx)(oGe,{skills:h,onSkillChanged:g,onSkillRemoved:_})]}):e===`debug`?(0,U.jsxs)(`div`,{className:`overflow-auto p-6 max-[640px]:p-3`,children:[(0,U.jsxs)(`h1`,{className:`mb-4 flex items-center gap-2 text-sm font-bold uppercase tracking-wider`,children:[(0,U.jsx)(Vs,{size:16}),`Debug`]}),(0,U.jsx)(LWe,{debugMode:a,onDebugModeChange:o,thresholds:s,onThresholdsChange:c})]}):e===`concurrency`?(0,U.jsxs)(`div`,{className:`p-6 overflow-auto`,children:[(0,U.jsxs)(`h1`,{className:`text-sm font-bold uppercase tracking-wider mb-4 flex items-center gap-2`,children:[(0,U.jsx)(xc,{size:16}),`Concurrency`]}),(0,U.jsx)(kJ,{title:`Yielded runs`,children:(0,U.jsx)(KWe,{})})]}):e===`transcription`?(0,U.jsxs)(`div`,{className:`p-6 overflow-auto`,children:[(0,U.jsxs)(`h1`,{className:`text-sm font-bold uppercase tracking-wider mb-4 flex items-center gap-2`,children:[(0,U.jsx)(Hc,{size:16}),`Transcription`]}),(0,U.jsx)(kJ,{title:`Audio transcription`,children:(0,U.jsx)(XWe,{})})]}):e===`previews`?(0,U.jsxs)(`div`,{className:`overflow-auto p-6 max-[640px]:p-3`,children:[(0,U.jsxs)(`h1`,{className:`mb-4 flex items-center gap-2 text-sm font-bold uppercase tracking-wider`,children:[(0,U.jsx)(Wc,{size:16}),`Previews`]}),(0,U.jsx)(kJ,{title:`Managed Preview servers`,children:(0,U.jsx)(qWe,{})})]}):e===`speech`?(0,U.jsxs)(`div`,{className:`p-6 overflow-auto`,children:[(0,U.jsxs)(`h1`,{className:`text-sm font-bold uppercase tracking-wider mb-4 flex items-center gap-2`,children:[(0,U.jsx)(Ol,{size:16}),`Speech`]}),(0,U.jsx)(kJ,{title:`Text-to-speech`,children:(0,U.jsx)(ZWe,{})})]}):e===`providers`?(0,U.jsxs)(`div`,{className:`p-6 overflow-auto`,children:[(0,U.jsxs)(`h1`,{className:`text-sm font-bold uppercase tracking-wider mb-4 flex items-center gap-2`,children:[(0,U.jsx)(Dc,{size:16}),`Providers`]}),(0,U.jsx)(BWe,{piboSessionId:v,onProviderAuthChanged:y})]}):e===`shortcuts`?(0,U.jsxs)(`div`,{className:`p-6 overflow-auto`,children:[(0,U.jsxs)(`h1`,{className:`text-sm font-bold uppercase tracking-wider mb-4 flex items-center gap-2`,children:[(0,U.jsx)(Oc,{size:16}),`Shortcuts`]}),(0,U.jsx)(eGe,{})]}):e===`maintenance`?(0,U.jsxs)(`div`,{className:`p-6 overflow-auto`,children:[(0,U.jsxs)(`h1`,{className:`text-sm font-bold uppercase tracking-wider mb-4 flex items-center gap-2`,children:[(0,U.jsx)(hl,{size:16}),`Maintenance`]}),(0,U.jsx)(QWe,{})]}):(0,U.jsxs)(`div`,{className:`p-6 overflow-auto`,children:[(0,U.jsxs)(`h1`,{className:`text-sm font-bold uppercase tracking-wider mb-4 flex items-center gap-2`,children:[(0,U.jsx)(hl,{size:16}),`General`]}),(0,U.jsxs)(kJ,{title:`General`,children:[(0,U.jsx)(YWe,{}),(0,U.jsx)(PJ,{checked:t,title:`Show thinking blocks`,onToggle:()=>{let e=!t;n(e),CY(e)}}),(0,U.jsx)(PJ,{checked:r,disabled:!t,title:`Expand thinking blocks`,onToggle:()=>{let e=!r;i(e),wY(e)}}),(0,U.jsx)(iGe,{modelDefaults:l,modelCatalog:u,onChanged:d})]})]})}function KWe(){let e=kn(),{data:t,isLoading:n}=Wn({queryKey:[`gateway-settings`],queryFn:HTe}),[r,i]=(0,H.useState)(`50`),[a,o]=(0,H.useState)(`10`),[s,c]=(0,H.useState)(!1),[l,u]=(0,H.useState)(null),[d,f]=(0,H.useState)(null);(0,H.useEffect)(()=>{t&&(i(String(t.maxConcurrentYieldedRuns)),o(String(t.sessionConcurrentYieldedRuns)))},[t]);let p=async()=>{let t=Number(r),n=Number(a);if(!Number.isSafeInteger(t)||t<1){f(`Gateway concurrency must be a positive integer.`);return}if(!Number.isSafeInteger(n)||n<1){f(`Session concurrency must be a positive integer.`);return}c(!0),u(null),f(null);try{let r=await UTe({maxConcurrentYieldedRuns:t,sessionConcurrentYieldedRuns:n});i(String(r.maxConcurrentYieldedRuns)),o(String(r.sessionConcurrentYieldedRuns)),e.setQueryData([`gateway-settings`],r),u(`Concurrency settings saved. New yielded runs use these limits immediately.`)}catch(e){f(e instanceof Error?e.message:String(e))}finally{c(!1)}};return(0,U.jsxs)(`div`,{className:`max-w-xl`,children:[(0,U.jsx)(`p`,{className:`mb-4 text-xs text-slate-400`,children:`Limit concurrent yielded tool and subagent runs across the gateway and within each controlling Pibo Session.`}),(0,U.jsxs)(`div`,{className:`grid gap-4 sm:grid-cols-2 @max-[520px]:grid-cols-1`,children:[(0,U.jsxs)(`label`,{className:`block text-xs text-slate-300`,htmlFor:`gateway-concurrent-yielded-runs`,children:[(0,U.jsx)(`span`,{className:`mb-1 block font-semibold`,children:`Gateway limit`}),(0,U.jsx)(`input`,{id:`gateway-concurrent-yielded-runs`,type:`number`,min:`1`,step:`1`,value:r,disabled:n||s,onChange:e=>i(e.target.value),className:`w-full rounded-sm border border-slate-700 bg-[#0e1116] px-3 py-2 font-mono text-sm outline-none focus:border-[#11a4d4] disabled:opacity-60`}),(0,U.jsx)(`span`,{className:`mt-1 block text-[11px] text-slate-500`,children:`Default: 50 across this gateway.`})]}),(0,U.jsxs)(`label`,{className:`block text-xs text-slate-300`,htmlFor:`session-concurrent-yielded-runs`,children:[(0,U.jsx)(`span`,{className:`mb-1 block font-semibold`,children:`Per-session limit`}),(0,U.jsx)(`input`,{id:`session-concurrent-yielded-runs`,type:`number`,min:`1`,step:`1`,value:a,disabled:n||s,onChange:e=>o(e.target.value),className:`w-full rounded-sm border border-slate-700 bg-[#0e1116] px-3 py-2 font-mono text-sm outline-none focus:border-[#11a4d4] disabled:opacity-60`}),(0,U.jsx)(`span`,{className:`mt-1 block text-[11px] text-slate-500`,children:`Default: 10 for each controlling session.`})]})]}),(0,U.jsxs)(`div`,{className:`mt-4 flex items-center gap-3`,children:[(0,U.jsx)(`button`,{type:`button`,disabled:n||s,onClick:()=>void p(),className:`whitespace-nowrap rounded-sm bg-[#11a4d4] px-3 py-2 text-xs font-semibold text-white hover:bg-[#0d8db7] disabled:opacity-60`,children:s?`Saving…`:`Save limits`}),l?(0,U.jsx)(`span`,{className:`text-xs text-green-400`,children:l}):null]}),d?(0,U.jsx)(`div`,{className:`mt-3 text-xs text-red-300`,children:d}):null,(0,U.jsx)(`p`,{className:`mt-4 font-mono text-[10px] text-slate-500`,children:`Environment fallbacks: PIBO_GATEWAY_MAX_CONCURRENT_YIELDED_RUNS and PIBO_SESSION_CONCURRENT_YIELDED_RUNS.`})]})}function qWe(){let e=kn(),t=Wn({queryKey:[`user-settings`],queryFn:qH}),[n,r]=(0,H.useState)(`3`),[i,a]=(0,H.useState)(`10`),[o,s]=(0,H.useState)(!1),[c,l]=(0,H.useState)(null),[u,d]=(0,H.useState)(null);(0,H.useEffect)(()=>{t.data?.previewServers&&(r(String(t.data.previewServers.maxRunningServers)),a(String(t.data.previewServers.autoStopMinutes)))},[t.data?.previewServers]);let f=async()=>{let t=Number(n),o=Number(i);if(!Number.isSafeInteger(t)||t<1||t>20){d(`Maximum running servers must be an integer from 1 to 20.`);return}if(!Number.isSafeInteger(o)||o<1||o>1440){d(`Automatic stop must be an integer from 1 to 1440 minutes.`);return}s(!0),l(null),d(null);try{let n=await JH({previewServers:{maxRunningServers:t,autoStopMinutes:o}});e.setQueryData([`user-settings`],n),r(String(n.previewServers.maxRunningServers)),a(String(n.previewServers.autoStopMinutes)),l(`Preview server settings saved.`)}catch(e){d(e instanceof Error?e.message:String(e))}finally{s(!1)}};return(0,U.jsxs)(`div`,{className:`max-w-2xl space-y-5`,children:[(0,U.jsxs)(`label`,{className:`block`,htmlFor:`preview-max-running`,children:[(0,U.jsx)(`span`,{className:`mb-1 block text-xs font-semibold uppercase tracking-wider text-slate-400`,children:`Maximum running servers`}),(0,U.jsx)(`input`,{id:`preview-max-running`,type:`number`,min:`1`,max:`20`,step:`1`,value:n,disabled:t.isLoading||o,onChange:e=>r(e.target.value),className:`w-32 rounded-sm border border-slate-700 bg-[#0e1116] px-3 py-2 font-mono text-sm outline-none focus:border-[#11a4d4] disabled:opacity-60`}),(0,U.jsx)(`span`,{className:`mt-1 block text-[11px] text-slate-500`,children:`Managed starts fail when the instance-wide pool is full. Existing servers are never stopped to make room.`})]}),(0,U.jsxs)(`label`,{className:`block`,htmlFor:`preview-auto-stop`,children:[(0,U.jsx)(`span`,{className:`mb-1 block text-xs font-semibold uppercase tracking-wider text-slate-400`,children:`Automatic stop after each start`}),(0,U.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,U.jsx)(`input`,{id:`preview-auto-stop`,type:`number`,min:`1`,max:`1440`,step:`1`,value:i,disabled:t.isLoading||o,onChange:e=>a(e.target.value),className:`w-32 rounded-sm border border-slate-700 bg-[#0e1116] px-3 py-2 font-mono text-sm outline-none focus:border-[#11a4d4] disabled:opacity-60`}),(0,U.jsx)(`span`,{className:`text-xs text-slate-500`,children:`minutes`})]}),(0,U.jsx)(`span`,{className:`mt-1 block text-[11px] text-slate-500`,children:`This is a fixed runtime lease, not an inactivity timer. A stopped Preview remains restartable.`})]}),(0,U.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,U.jsx)(`button`,{type:`button`,disabled:t.isLoading||o,onClick:()=>void f(),className:`rounded-sm bg-[#11a4d4] px-3 py-2 text-xs font-semibold text-white hover:bg-[#0d8db7] disabled:cursor-not-allowed disabled:opacity-50`,children:o?`Saving…`:`Save Preview settings`}),c?(0,U.jsx)(`span`,{className:`text-xs text-green-400`,role:`status`,children:c}):null]}),t.error?(0,U.jsx)(`div`,{className:`text-xs text-red-300`,role:`alert`,children:t.error instanceof Error?t.error.message:String(t.error)}):null,u?(0,U.jsx)(`div`,{className:`text-xs text-red-300`,role:`alert`,children:u}):null]})}var JWe=`UTC.Europe/Berlin.Europe/London.Europe/Paris.Europe/Madrid.Europe/Rome.Europe/Amsterdam.Europe/Vienna.Europe/Zurich.Europe/Warsaw.Europe/Istanbul.America/New_York.America/Chicago.America/Denver.America/Los_Angeles.America/Toronto.America/Sao_Paulo.America/Mexico_City.Asia/Dubai.Asia/Jerusalem.Asia/Kolkata.Asia/Bangkok.Asia/Singapore.Asia/Shanghai.Asia/Tokyo.Asia/Seoul.Australia/Sydney.Australia/Melbourne.Pacific/Auckland`.split(`.`);function YWe(){let e=kn(),{data:t,isLoading:n}=Wn({queryKey:[`user-settings`],queryFn:qH}),r=(0,H.useMemo)(()=>tGe(t?.timezone),[t?.timezone]),[i,a]=(0,H.useState)(`UTC`),[o,s]=(0,H.useState)(!1),[c,l]=(0,H.useState)(null);(0,H.useEffect)(()=>{t?.timezone&&a(t.timezone)},[t?.timezone]);let u=async(t=i)=>{s(!0),l(null);try{let n=await JH({timezone:t});a(n.timezone),e.setQueryData([`user-settings`],n)}catch(e){l(e instanceof Error?e.message:String(e))}finally{s(!1)}};return(0,U.jsxs)(`div`,{className:`border-b border-slate-800 pb-4 mb-4`,children:[(0,U.jsx)(`label`,{htmlFor:`app-timezone`,className:`mb-2 block text-xs font-semibold uppercase tracking-wider text-slate-400`,children:`App timezone`}),(0,U.jsx)(`div`,{className:`max-w-xl`,children:(0,U.jsx)(`select`,{id:`app-timezone`,value:i,disabled:n||o,onChange:e=>{let t=e.target.value;a(t),u(t)},className:`w-full min-w-0 rounded-sm border border-slate-700 bg-[#0e1116] px-3 py-2 text-sm outline-none focus:border-[#11a4d4] disabled:opacity-60`,children:r.map(e=>(0,U.jsx)(`option`,{value:e.value,children:e.label},e.value))})}),(0,U.jsx)(`div`,{className:`mt-2 text-[11px] text-slate-500`,children:`Choose a city-based timezone. Changes are saved automatically and loaded into every runtime context together with the current Pibo Session ID.`}),o?(0,U.jsx)(`div`,{className:`mt-2 text-xs text-slate-400`,children:`Saving…`}):null,c?(0,U.jsx)(`div`,{className:`mt-2 text-xs text-red-300`,children:c}):null]})}function XWe(){let e=kn(),t=Wn({queryKey:[`user-settings`],queryFn:qH}),n=Wn({queryKey:[`transcription-providers`],queryFn:gNe}),r=n.data?.providers??[],i=t.data?.transcription.providerId??n.data?.selectedProviderId??``,[a,o]=(0,H.useState)(``),[s,c]=(0,H.useState)(!1),[l,u]=(0,H.useState)(null);(0,H.useEffect)(()=>{i&&o(i)},[i]);let d=async t=>{o(t),c(!0),u(null);try{let n=await JH({transcription:{providerId:t}});e.setQueryData([`user-settings`],n),e.setQueryData([`transcription-providers`],e=>e&&{...e,selectedProviderId:n.transcription.providerId}),o(n.transcription.providerId)}catch(e){o(i),u(e instanceof Error?e.message:String(e))}finally{c(!1)}},f=r.some(e=>e.id===a);return(0,U.jsxs)(`div`,{children:[(0,U.jsx)(`div`,{className:`mb-2 text-xs font-semibold uppercase tracking-wider text-slate-400`,children:`Transcription provider`}),(0,U.jsx)(`div`,{className:`max-w-xl`,children:(0,U.jsxs)(`select`,{value:a,disabled:t.isLoading||n.isLoading||s||r.length===0,onChange:e=>void d(e.target.value),className:`w-full min-w-0 rounded-sm border border-slate-700 bg-[#0e1116] px-3 py-2 text-sm outline-none focus:border-[#11a4d4] disabled:opacity-60`,children:[a&&!f?(0,U.jsxs)(`option`,{value:a,children:[a,` (unavailable)`]}):null,r.map(e=>(0,U.jsxs)(`option`,{value:e.id,children:[e.name,e.configured?``:` — authentication required`]},e.id))]})}),(0,U.jsx)(`div`,{className:`mt-2 text-[11px] text-slate-500`,children:`This selection is independent from the providers used by chat models. Recordings use the selected provider and are inserted into the composer without sending the message.`}),r.find(e=>e.id===a)?.description?(0,U.jsx)(`div`,{className:`mt-2 text-[11px] text-slate-400`,children:r.find(e=>e.id===a)?.description}):null,r.length===0&&!n.isLoading?(0,U.jsx)(`div`,{className:`mt-2 text-xs text-amber-300`,children:`No transcription providers are registered.`}):null,n.error?(0,U.jsx)(`div`,{className:`mt-2 text-xs text-red-300`,children:n.error instanceof Error?n.error.message:String(n.error)}):null,s?(0,U.jsx)(`div`,{className:`mt-2 text-xs text-slate-400`,children:`Saving…`}):null,l?(0,U.jsx)(`div`,{className:`mt-2 text-xs text-red-300`,children:l}):null]})}function ZWe(){let e=kn(),t=Wn({queryKey:[`user-settings`],queryFn:qH}),n=Wn({queryKey:[`speech-providers`],queryFn:RBe}),r=n.data?.providers??[],i=t.data?.speech.providerId??n.data?.selectedProviderId??``,[a,o]=(0,H.useState)(``),[s,c]=(0,H.useState)(!1),[l,u]=(0,H.useState)(null);(0,H.useEffect)(()=>{i&&o(i)},[i]);let d=async t=>{let n=r.find(e=>e.id===t);if(!n?.configured){u(n?`${n.name} requires authentication`:`Unknown speech provider "${t}"`);return}o(t),c(!0),u(null);try{let n=await JH({speech:{providerId:t}});e.setQueryData([`user-settings`],n),e.setQueryData([`speech-providers`],e=>e&&{...e,selectedProviderId:n.speech.providerId}),o(n.speech.providerId)}catch(e){o(i),u(e instanceof Error?e.message:String(e))}finally{c(!1)}},f=r.find(e=>e.id===a),p=!!f;return(0,U.jsxs)(`div`,{children:[(0,U.jsx)(`div`,{className:`mb-2 text-xs font-semibold uppercase tracking-wider text-slate-400`,children:`Speech provider`}),(0,U.jsx)(`div`,{className:`max-w-xl`,children:(0,U.jsxs)(`select`,{value:a,disabled:t.isLoading||n.isLoading||s||r.length===0,onChange:e=>void d(e.target.value),"aria-describedby":`speech-provider-help speech-provider-status`,className:`w-full min-w-0 rounded-sm border border-slate-700 bg-[#0e1116] px-3 py-2 text-sm outline-none focus:border-[#11a4d4] disabled:opacity-60`,children:[a&&!p?(0,U.jsxs)(`option`,{value:a,children:[a,` (unavailable)`]}):null,r.map(e=>(0,U.jsxs)(`option`,{value:e.id,disabled:!e.configured,children:[e.name,e.configured?``:` — authentication required`]},e.id))]})}),(0,U.jsx)(`div`,{id:`speech-provider-help`,className:`mt-2 text-[11px] text-slate-500`,children:`Assistant-message audio uses this provider independently from transcription, chat-model providers, and future preview settings. The initial provider uses the ChatGPT/Codex subscription configured under Providers for the Native Codex runtime.`}),f?.description?(0,U.jsx)(`div`,{className:`mt-2 text-[11px] text-slate-400`,children:f.description}):null,(0,U.jsxs)(`div`,{id:`speech-provider-status`,"aria-live":`polite`,children:[r.length===0&&!n.isLoading&&!n.error?(0,U.jsx)(`div`,{className:`mt-2 text-xs text-amber-300`,children:`No speech providers are registered.`}):null,n.error?(0,U.jsx)(`div`,{className:`mt-2 text-xs text-red-300`,role:`alert`,children:n.error instanceof Error?n.error.message:String(n.error)}):null,a&&!p&&!n.isLoading&&!n.error?(0,U.jsx)(`div`,{className:`mt-2 text-xs text-amber-300`,children:`The selected speech provider is unavailable. Choose a configured provider.`}):null,f&&!f.configured?(0,U.jsxs)(`div`,{className:`mt-2 text-xs text-amber-300`,children:[f.name,` requires authentication before it can read messages aloud.`]}):null,s?(0,U.jsx)(`div`,{className:`mt-2 text-xs text-slate-400`,children:`Saving…`}):null,l?(0,U.jsx)(`div`,{className:`mt-2 text-xs text-red-300`,role:`alert`,children:l}):null]})]})}function QWe(){let e=kn(),{data:t,isLoading:n}=Wn({queryKey:[`user-settings`],queryFn:qH}),[r,i]=(0,H.useState)(30),[a,o]=(0,H.useState)(!0),[s,c]=(0,H.useState)(10),[l,u]=(0,H.useState)(!1),[d,f]=(0,H.useState)(!1),[p,m]=(0,H.useState)(null),[h,g]=(0,H.useState)(null),_=t?.telemetryRetention?.lastPrunedAt,v=Number.isInteger(s)&&s>=1&&s<=365;(0,H.useEffect)(()=>{t?.telemetryRetention&&(o(t.telemetryRetention.enabled),i(t.telemetryRetention.days),c(t.telemetryRetention.days))},[t?.telemetryRetention]);let y=async t=>{let n=t.enabled??a,s=$We(t.days??r);o(n),i(s),u(!0),g(null),m(null);try{let t=await JH({telemetryRetention:{enabled:n,days:s}});e.setQueryData([`user-settings`],t),o(t.telemetryRetention.enabled),i(t.telemetryRetention.days),m(`Telemetry retention settings saved.`)}catch(e){g(e instanceof Error?e.message:String(e))}finally{u(!1)}},b=async()=>{if(!v){g(`Manual cleanup retention must be between 1 and 365 days.`);return}let t=s;f(!0),g(null),m(null);try{let n=await WTe({days:t}),r=await qH();e.setQueryData([`user-settings`],r),m(`Deleted ${n.rowsDeleted.toLocaleString()} telemetry rows older than ${t} days. Cutoff: ${n.cutoff}.`)}catch(e){g(e instanceof Error?e.message:String(e))}finally{f(!1)}};return(0,U.jsx)(kJ,{title:`Telemetry retention`,children:(0,U.jsxs)(`div`,{className:`space-y-5`,children:[(0,U.jsxs)(`div`,{className:`rounded-sm border border-slate-800 bg-[#101d22] p-4`,children:[(0,U.jsx)(`div`,{className:`mb-2 text-xs font-semibold uppercase tracking-wider text-slate-300`,children:`Automatic cleanup`}),(0,U.jsx)(`p`,{className:`mb-4 max-w-2xl text-xs leading-5 text-slate-400`,children:`Pibo keeps sessions, rooms, chat messages, and renderable trace events. This retention policy deletes only runtime telemetry/debug rows older than the configured age.`}),(0,U.jsxs)(`label`,{className:`mb-4 flex items-center gap-3 text-sm text-slate-200`,children:[(0,U.jsx)(`input`,{type:`checkbox`,checked:a,disabled:n||l,onChange:e=>void y({enabled:e.target.checked}),className:`h-4 w-4 accent-[#11a4d4]`}),`Enable automatic telemetry retention`]}),(0,U.jsxs)(`div`,{className:`max-w-xs`,children:[(0,U.jsx)(`label`,{className:`mb-1 block text-[11px] font-semibold uppercase tracking-wider text-slate-500`,children:`Delete telemetry older than`}),(0,U.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,U.jsx)(`input`,{type:`number`,min:1,max:365,value:r,disabled:n||l,onChange:e=>i(Number(e.target.value)),onBlur:()=>void y({days:r}),className:`w-24 rounded-sm border border-slate-700 bg-[#0e1116] px-3 py-2 text-sm outline-none focus:border-[#11a4d4] disabled:opacity-60`}),(0,U.jsx)(`span`,{className:`text-xs text-slate-400`,children:`days`})]})]}),(0,U.jsx)(`div`,{className:`mt-3 text-[11px] text-slate-500`,children:`Default is 30 days. Automatic cleanup skips runs while runtime sessions are processing or streaming.`}),(0,U.jsxs)(`div`,{className:`mt-2 text-[11px] text-slate-500`,children:[`Last prune: `,_?new Date(_).toLocaleString():`never`]})]}),(0,U.jsxs)(`div`,{className:`rounded-sm border border-slate-800 bg-[#101d22] p-4`,children:[(0,U.jsx)(`div`,{className:`mb-2 text-xs font-semibold uppercase tracking-wider text-slate-300`,children:`Manual cleanup`}),(0,U.jsx)(`p`,{className:`mb-4 max-w-2xl text-xs leading-5 text-slate-400`,children:`Run retention now with a custom cutoff. This affects telemetry tables only and never deletes sessions, rooms, chat messages, or trace-render events.`}),(0,U.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,U.jsx)(`input`,{type:`number`,min:1,max:365,value:s,disabled:d,"aria-invalid":!v,onChange:e=>c(Number(e.target.value)),className:`w-24 rounded-sm border border-slate-700 bg-[#0e1116] px-3 py-2 text-sm outline-none focus:border-[#11a4d4] disabled:opacity-60`}),(0,U.jsx)(`span`,{className:`text-xs text-slate-400`,children:`days`}),(0,U.jsxs)(`button`,{type:`button`,disabled:d||!v,onClick:()=>void b(),className:`inline-flex items-center justify-center gap-2 rounded-sm border border-red-900/70 bg-red-950/30 px-3 py-2 text-xs font-semibold text-red-100 transition hover:border-red-500 disabled:cursor-not-allowed disabled:opacity-60`,children:[(0,U.jsx)(Cl,{size:13}),d?`Deleting…`:`Delete old telemetry now`]})]})]}),(0,U.jsx)(`div`,{className:`rounded-sm border border-amber-900/50 bg-amber-950/20 p-3 text-[11px] leading-5 text-amber-100`,children:`Detailed provider-event capture is intentionally off by default because it can be high-volume. Use the dedicated debug flag only for short incident windows.`}),l?(0,U.jsx)(`div`,{className:`text-xs text-slate-400`,children:`Saving…`}):null,p?(0,U.jsx)(`div`,{className:`text-xs text-emerald-300`,children:p}):null,h?(0,U.jsx)(`div`,{className:`text-xs text-red-300`,children:h}):null]})})}function $We(e){return Number.isFinite(e)?Math.max(1,Math.min(365,Math.trunc(e))):30}function eGe(){let e=kn(),{data:t,isLoading:n}=Wn({queryKey:[`user-settings`],queryFn:qH}),[r,i]=(0,H.useState)(fQ),[a,o]=(0,H.useState)(!1),[s,c]=(0,H.useState)(!1),[l,u]=(0,H.useState)(null);(0,H.useEffect)(()=>{let e=t?.shortcuts?.webAnnotationsToggle||pQ();i(e),mQ(e),hQ(e)},[t?.shortcuts?.webAnnotationsToggle]);let d=async t=>{let n=gQ(t)||`Alt+Shift+A`;i(n),c(!0),u(null);try{let t=await JH({shortcuts:{webAnnotationsToggle:n}});e.setQueryData([`user-settings`],t),mQ(t.shortcuts.webAnnotationsToggle),hQ(t.shortcuts.webAnnotationsToggle)}catch(e){u(e instanceof Error?e.message:String(e))}finally{c(!1)}};return(0,U.jsx)(kJ,{title:`Shortcuts`,children:(0,U.jsxs)(`div`,{className:`grid max-w-2xl gap-3 rounded-sm border border-slate-800 bg-[#151f24] p-3`,children:[(0,U.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[(0,U.jsxs)(`div`,{children:[(0,U.jsxs)(`div`,{className:`flex items-center gap-2 text-sm font-semibold text-slate-200`,children:[(0,U.jsx)(Is,{size:15}),` Toggle annotation mode`]}),(0,U.jsx)(`div`,{className:`mt-1 text-xs text-slate-500`,children:`Toggles the Web Annotation element mode with the pencil button.`})]}),(0,U.jsx)(`kbd`,{className:`rounded-sm border border-slate-700 bg-[#0e1116] px-2 py-1 font-mono text-xs text-[#7dd3fc]`,children:r})]}),(0,U.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,U.jsx)(`button`,{type:`button`,disabled:n||s,"aria-pressed":a,onClick:()=>{u(null),o(e=>!e)},onKeyDown:e=>{if(!a)return;if(e.key===`Escape`){e.preventDefault(),e.stopPropagation(),o(!1),u(null);return}let t=CIe(e);if(!t){[`Alt`,`Control`,`Meta`,`Shift`].includes(e.key)||(e.preventDefault(),e.stopPropagation(),u(`Use Ctrl, Alt, or Meta with another key.`));return}e.preventDefault(),e.stopPropagation(),o(!1),d(t)},className:`rounded-sm border px-3 py-2 text-xs font-medium ${a?`border-[#11a4d4] bg-[#11a4d4]/10 text-sky-100`:`border-slate-700 text-slate-300 hover:border-[#11a4d4] hover:text-[#7dd3fc]`} disabled:opacity-50`,children:a?`Press shortcut…`:`Record shortcut`}),(0,U.jsx)(`button`,{type:`button`,disabled:s||r===`Alt+Shift+A`,onClick:()=>void d(fQ),className:`rounded-sm border border-slate-700 px-3 py-2 text-xs text-slate-300 hover:border-[#11a4d4] hover:text-[#7dd3fc] disabled:opacity-50`,children:`Reset`}),s?(0,U.jsx)(`span`,{className:`text-xs text-slate-400`,children:`Saving…`}):null]}),(0,U.jsxs)(`div`,{className:`text-[11px] text-slate-500`,children:[`Default: `,fQ,`. Use a modifier combination to avoid conflicts with normal typing.`]}),l?(0,U.jsx)(`div`,{className:`text-xs text-red-300`,children:l}):null]})})}function tGe(e){let t=new Set([`UTC`,...Intl.supportedValuesOf?.(`timeZone`)??JWe]);return e&&t.add(e),[...t].map(e=>({value:e,label:nGe(e),offset:rGe(e)})).sort((e,t)=>e.offset-t.offset||e.label.localeCompare(t.label)).map(({value:e,label:t})=>({value:e,label:t}))}function nGe(e){let t=e===`UTC`?`UTC`:e.split(`/`).pop()?.replaceAll(`_`,` `)??e,n=e.includes(`/`)?e.split(`/`)[0].replaceAll(`_`,` `):void 0,r=m6(e);return`${t}${n?` (${n})`:``} — ${r}`}function m6(e){try{return new Intl.DateTimeFormat(`en-US`,{timeZone:e,timeZoneName:`shortOffset`}).formatToParts(new Date).find(e=>e.type===`timeZoneName`)?.value.replace(`GMT`,`UTC`)??e}catch{return e}}function rGe(e){let t=m6(e),n=/^UTC(?:(?<sign>[+-])(?<hours>\d{1,2})(?::(?<minutes>\d{2}))?)?$/.exec(t);return n?.groups?.sign?(n.groups.sign===`-`?-1:1)*(Number(n.groups.hours)*60+Number(n.groups.minutes??0)):0}function iGe({modelDefaults:e,modelCatalog:t,onChanged:n}){let[r,i]=(0,H.useState)(e??{}),[a,o]=(0,H.useState)(!1),[s,c]=(0,H.useState)(null);(0,H.useEffect)(()=>{i(e??{})},[e]);let l=async e=>{i(e),o(!0);try{n(await VTe(e)),c(null)}catch(e){c(e instanceof Error?e.message:String(e))}finally{o(!1)}};return(0,U.jsxs)(`div`,{className:`grid gap-3 border-t border-slate-800 pt-3`,children:[(0,U.jsx)(`div`,{className:`text-[10px] font-bold uppercase tracking-wider text-slate-500`,children:`Runtime Model Defaults`}),(0,U.jsx)(BJ,{title:`Main Agent`,modelTitle:`Main Agent Default`,model:r.main,thinking:r.mainThinking,fast:r.mainFast??!1,modelCatalog:t,readOnly:a,modelHint:`Unset to use provider fallback.`,configuredProvidersOnly:!0,onModelChange:e=>void l({...r,main:e}),onThinkingChange:e=>void l({...r,mainThinking:e}),onFastChange:e=>void l({...r,mainFast:e})}),(0,U.jsx)(BJ,{title:`Subagent`,modelTitle:`Subagent Default`,model:r.subagent,thinking:r.subagentThinking,fast:r.subagentFast??!1,modelCatalog:t,readOnly:a,modelHint:`Unset to use provider fallback.`,configuredProvidersOnly:!0,onModelChange:e=>void l({...r,subagent:e}),onThinkingChange:e=>void l({...r,subagentThinking:e}),onFastChange:e=>void l({...r,subagentFast:e})}),s?(0,U.jsx)(`div`,{className:`text-xs text-amber-100`,children:s}):null]})}function aGe({packages:e,onPackageChanged:t,onPackageRemoved:n}){let[r,i]=(0,H.useState)(``),[a,o]=(0,H.useState)(null),[s,c]=(0,H.useState)(null),[l,u]=(0,H.useState)(()=>new Set),d=e??[],f=d.filter(e=>e.installStatus===`installed`).length,p=d.filter(e=>e.enabled).length,m=async()=>{if(!a){o(`add`);try{let e=await Lke(r);t(e),i(``),u(t=>new Set(t).add(e.id)),c(null)}catch(e){c(e instanceof Error?e.message:String(e))}finally{o(null)}}},h=async e=>{if(!a){o(`${e.id}:enabled`);try{t(await Rke(e.id,{enabled:!e.enabled})),c(null)}catch(e){c(e instanceof Error?e.message:String(e))}finally{o(null)}}},g=async e=>{if(!a&&window.confirm(`Unregister Pi package "${e.name}"?`)){o(`${e.id}:delete`);try{n(await zke(e.id)),u(t=>{let n=new Set(t);return n.delete(e.id),n}),c(null)}catch(e){c(e instanceof Error?e.message:String(e))}finally{o(null)}}},_=e=>{u(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})};return(0,U.jsxs)(kJ,{title:`Pi Package Management`,children:[(0,U.jsxs)(`div`,{className:`grid gap-2`,children:[(0,U.jsxs)(`div`,{className:`grid grid-cols-[minmax(0,1fr)_auto] gap-2`,children:[(0,U.jsx)(`input`,{value:r,disabled:!e||a===`add`,onChange:e=>{let t=e.target.value;i(t),t.trim()||c(null)},className:`min-w-0 bg-[#0e1116] border border-slate-700 rounded-sm px-3 py-2 text-sm outline-none focus:border-[#11a4d4] disabled:opacity-60`,placeholder:`https://pi.dev/packages/package-name`}),(0,U.jsx)(`button`,{type:`button`,disabled:!e||a===`add`||!r.trim(),onClick:()=>void m(),title:`Add Pi Package`,"aria-label":`Add Pi Package`,className:`h-9 w-9 inline-flex items-center justify-center border border-[#11a4d4] rounded-sm text-[#11a4d4] bg-[#11a4d4]/10 disabled:opacity-50`,children:(0,U.jsx)(rl,{size:14})})]}),(0,U.jsx)(`div`,{className:`text-[11px] text-slate-500`,children:`Extensions execute code in the Pi runtime. Review package source before adding it.`}),s?(0,U.jsx)(`div`,{className:`border border-red-500/60 bg-red-500/10 text-red-200 px-3 py-2 text-sm rounded-sm`,children:s}):null,(0,U.jsxs)(`div`,{className:`font-mono text-[10px] uppercase tracking-wider text-slate-500`,children:[d.length,` registered / `,f,` installed / `,p,` enabled`]})]}),e?d.length?(0,U.jsx)(`div`,{className:`grid gap-2`,children:d.map(e=>(0,U.jsx)(cGe,{pkg:e,expanded:l.has(e.id),busy:a?.startsWith(`${e.id}:`)??!1,onToggleExpanded:()=>_(e.id),onToggleEnabled:()=>void h(e),onUnregister:()=>void g(e)},e.id))}):(0,U.jsx)(IJ,{message:`No Pi packages registered`}):(0,U.jsx)(IJ,{})]})}function oGe({skills:e,onSkillChanged:t,onSkillRemoved:n}){let[r,i]=(0,H.useState)(!1),[a,o]=(0,H.useState)(!1),[s,c]=(0,H.useState)(null),[l,u]=(0,H.useState)(``),[d,f]=(0,H.useState)(null),[p,m]=(0,H.useState)(null),h=e??[],g=h.filter(e=>e.enabled).length,_=async e=>{if(!d){f(`${e.id}:enabled`);try{t(await aG(e.id,{enabled:!e.enabled})),m(null)}catch(e){m(e instanceof Error?e.message:String(e))}finally{f(null)}}},v=async e=>{if(!d&&window.confirm(`Delete skill "${e.name}"?`)){f(`${e.id}:delete`);try{await Hke(e.id),n(e.id),m(null)}catch(e){m(e instanceof Error?e.message:String(e))}finally{f(null)}}},y=async e=>{f(`create`);try{t(await Vke(e)),i(!1),m(null)}catch(e){m(e instanceof Error?e.message:String(e))}finally{f(null)}},b=async e=>{f(`install`);try{t(await Uke(e)),o(!1),m(null)}catch(e){m(e instanceof Error?e.message:String(e))}finally{f(null)}},x=async(e,n)=>{f(`edit`);try{t(await aG(e,n)),c(null),m(null)}catch(e){m(e instanceof Error?e.message:String(e))}finally{f(null)}};return(0,U.jsxs)(U.Fragment,{children:[(0,U.jsxs)(kJ,{title:`Skill Management`,children:[(0,U.jsxs)(`div`,{className:`grid gap-2`,children:[(0,U.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,U.jsxs)(`button`,{type:`button`,disabled:d===`create`,onClick:()=>i(!0),className:`inline-flex items-center gap-2 border border-[#11a4d4] rounded-sm px-3 py-2 text-sm text-[#11a4d4] bg-[#11a4d4]/10 disabled:opacity-50`,children:[(0,U.jsx)(rl,{size:14}),`Create Skill`]}),(0,U.jsxs)(`button`,{type:`button`,disabled:d===`install`,onClick:()=>o(!0),className:`inline-flex items-center gap-2 border border-slate-700 rounded-sm px-3 py-2 text-sm text-slate-300 hover:border-[#11a4d4] hover:text-[#11a4d4] disabled:opacity-50`,children:[(0,U.jsx)(fc,{size:14}),`Install from URL`]})]}),p?(0,U.jsx)(`div`,{className:`border border-red-500/60 bg-red-500/10 text-red-200 px-3 py-2 text-sm rounded-sm`,children:p}):null,(0,U.jsxs)(`div`,{className:`font-mono text-[10px] uppercase tracking-wider text-slate-500`,children:[h.length,` skills / `,g,` enabled`]})]}),e?h.length?(0,U.jsx)(`div`,{className:`grid gap-2`,children:h.map(e=>(0,U.jsx)(`div`,{className:`border rounded-sm p-2 ${e.enabled?`border-slate-800 bg-[#151f24]`:`border-slate-800 bg-[#151f24] opacity-75`}`,children:(0,U.jsxs)(`div`,{className:`flex items-center justify-between gap-2 max-[640px]:items-start`,children:[(0,U.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,U.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-center gap-2`,children:[(0,U.jsx)(`span`,{className:`min-w-0 truncate text-sm text-slate-200`,children:e.name}),(0,U.jsx)(`span`,{className:`shrink-0 border px-1.5 py-0.5 font-mono text-[10px] uppercase tracking-wider ${e.enabled?`border-[#11a4d4]/60 text-[#7dd3fc]`:`border-slate-700 text-slate-500`}`,children:e.enabled?`enabled`:`disabled`}),(0,U.jsx)(`span`,{className:`shrink-0 border px-1.5 py-0.5 font-mono text-[10px] uppercase tracking-wider border-slate-700 text-slate-500`,children:e.scope??`global`}),(0,U.jsx)(`span`,{className:`shrink-0 border px-1.5 py-0.5 font-mono text-[10px] uppercase tracking-wider border-slate-700 text-slate-500`,children:e.source})]}),(0,U.jsx)(`div`,{className:`truncate text-xs text-slate-500`,children:e.description||e.path})]}),(0,U.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1`,children:[(0,U.jsx)(`button`,{type:`button`,disabled:d?.startsWith(`${e.id}:`)??!1,onClick:()=>void _(e),title:`${e.enabled?`Disable`:`Enable`} ${e.name}`,"aria-label":`${e.enabled?`Disable`:`Enable`} ${e.name}`,className:`h-7 w-7 inline-flex items-center justify-center border border-slate-700 rounded-sm text-slate-400 hover:border-[#11a4d4] hover:text-[#11a4d4] disabled:opacity-50`,children:e.enabled?(0,U.jsx)(il,{size:13}):(0,U.jsx)(al,{size:13})}),(0,U.jsx)(`button`,{type:`button`,disabled:d?.startsWith(`${e.id}:`)??!1,onClick:async()=>{try{let t=await Bke(e.id);c(e),u(t.markdown)}catch{c(e),u(``)}},title:`Edit ${e.name}`,"aria-label":`Edit ${e.name}`,className:`h-7 w-7 inline-flex items-center justify-center border border-slate-700 rounded-sm text-slate-400 hover:border-[#11a4d4] hover:text-[#11a4d4] disabled:opacity-50`,children:(0,U.jsx)($c,{size:13})}),(0,U.jsx)(`button`,{type:`button`,disabled:d?.startsWith(`${e.id}:`)??!1,onClick:()=>void v(e),title:`Delete ${e.name}`,"aria-label":`Delete ${e.name}`,className:`h-7 w-7 inline-flex items-center justify-center border border-slate-700 rounded-sm text-slate-400 hover:border-red-500 hover:text-red-400 disabled:opacity-50`,children:(0,U.jsx)(Cl,{size:13})})]})]})},e.id))}):(0,U.jsx)(IJ,{message:`No user skills`}):(0,U.jsx)(IJ,{})]}),r?(0,U.jsx)(g6,{title:`Create Skill`,onSave:y,onClose:()=>{i(!1),m(null)},busy:d===`create`}):null,a?(0,U.jsx)(sGe,{onInstall:b,onClose:()=>{o(!1),m(null)},busy:d===`install`}):null,s?(0,U.jsx)(g6,{title:`Edit Skill`,initialName:s.name,initialDescription:s.description,initialMarkdown:l,onSave:e=>void x(s.id,e),onClose:()=>c(null),busy:d===`edit`}):null]})}function h6({children:e,onClose:t}){return(0,U.jsxs)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/70 p-4`,children:[(0,U.jsx)(`div`,{className:`w-full max-w-2xl rounded-sm border border-slate-700 bg-[#151f24] shadow-2xl`,children:e}),(0,U.jsx)(`button`,{type:`button`,className:`absolute inset-0 -z-10`,onClick:t,"aria-label":`Close modal`})]})}function g6({title:e,initialName:t=``,initialDescription:n=``,initialMarkdown:r=``,onSave:i,onClose:a,busy:o}){let[s,c]=(0,H.useState)(t),[l,u]=(0,H.useState)(n),[d,f]=(0,H.useState)(r);return(0,U.jsxs)(h6,{onClose:a,children:[(0,U.jsxs)(`h2`,{className:`flex items-center gap-2 border-b border-slate-800 px-4 py-3 text-sm font-bold uppercase tracking-wider`,children:[(0,U.jsx)($c,{size:16}),e]}),(0,U.jsxs)(`div`,{className:`grid gap-3 p-4`,children:[(0,U.jsx)(`input`,{value:s,onChange:e=>c(e.target.value),placeholder:`Skill name (kebab-case)`,className:`min-w-0 bg-[#0e1116] border border-slate-700 rounded-sm px-3 py-2 text-sm outline-none focus:border-[#11a4d4]`}),(0,U.jsx)(`input`,{value:l,onChange:e=>u(e.target.value),placeholder:`Short description`,className:`min-w-0 bg-[#0e1116] border border-slate-700 rounded-sm px-3 py-2 text-sm outline-none focus:border-[#11a4d4]`}),(0,U.jsx)(`textarea`,{value:d,onChange:e=>f(e.target.value),placeholder:`Markdown instructions...`,rows:10,className:`min-w-0 bg-[#0e1116] border border-slate-700 rounded-sm px-3 py-2 text-sm outline-none focus:border-[#11a4d4] resize-vertical`}),(0,U.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,U.jsx)(`button`,{type:`button`,onClick:a,className:`px-3 py-2 text-sm border border-slate-700 rounded-sm hover:border-slate-500`,children:`Cancel`}),(0,U.jsx)(`button`,{type:`button`,disabled:o||!s.trim(),onClick:()=>i({name:s,description:l,markdown:d}),className:`px-3 py-2 text-sm border border-[#11a4d4] rounded-sm bg-[#11a4d4]/10 text-[#11a4d4] disabled:opacity-50`,children:o?`Saving...`:`Save`})]})]})]})}function sGe({onInstall:e,onClose:t,busy:n}){let[r,i]=(0,H.useState)(``);return(0,U.jsxs)(h6,{onClose:t,children:[(0,U.jsxs)(`h2`,{className:`flex items-center gap-2 border-b border-slate-800 px-4 py-3 text-sm font-bold uppercase tracking-wider`,children:[(0,U.jsx)(fc,{size:16}),`Install Skill`]}),(0,U.jsxs)(`div`,{className:`grid gap-3 p-4`,children:[(0,U.jsx)(`input`,{value:r,onChange:e=>i(e.target.value),placeholder:`https://skills.sh/account/skills/skill-name`,className:`min-w-0 bg-[#0e1116] border border-slate-700 rounded-sm px-3 py-2 text-sm outline-none focus:border-[#11a4d4]`}),(0,U.jsx)(`div`,{className:`text-[11px] text-slate-500`,children:`Supports skills.sh URLs, GitHub tree URLs, or account/repo shorthand.`}),(0,U.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,U.jsx)(`button`,{type:`button`,onClick:t,className:`px-3 py-2 text-sm border border-slate-700 rounded-sm hover:border-slate-500`,children:`Cancel`}),(0,U.jsx)(`button`,{type:`button`,disabled:n||!r.trim(),onClick:()=>e(r),className:`px-3 py-2 text-sm border border-[#11a4d4] rounded-sm bg-[#11a4d4]/10 text-[#11a4d4] disabled:opacity-50`,children:n?`Installing...`:`Install`})]})]})]})}function cGe({pkg:e,expanded:t,busy:n,onToggleExpanded:r,onToggleEnabled:i,onUnregister:a}){let o=e.diagnostics.some(e=>e.type===`error`);return(0,U.jsxs)(`div`,{className:`border rounded-sm ${e.enabled?`border-slate-800 bg-[#151f24]`:`border-slate-800 bg-[#151f24] opacity-75`}`,children:[(0,U.jsxs)(`div`,{className:`grid grid-cols-[1fr_auto] gap-2 p-2`,children:[(0,U.jsxs)(`div`,{className:`min-w-0`,children:[(0,U.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,U.jsx)(`span`,{className:`min-w-0 truncate text-sm text-slate-200`,children:e.name}),(0,U.jsx)(`span`,{className:`shrink-0 border px-1.5 py-0.5 font-mono text-[10px] uppercase tracking-wider ${e.enabled?`border-[#11a4d4]/60 text-[#7dd3fc]`:`border-slate-700 text-slate-500`}`,children:e.enabled?`enabled`:`disabled`}),(0,U.jsx)(`span`,{className:`shrink-0 border px-1.5 py-0.5 font-mono text-[10px] uppercase tracking-wider ${e.installStatus===`installed`?`border-[#0bda57]/50 text-green-300`:`border-[#f59e0b]/50 text-amber-100`}`,children:e.installStatus})]}),(0,U.jsx)(`div`,{className:`truncate text-xs text-slate-500`,children:e.description??e.source}),(0,U.jsx)(`div`,{className:`font-mono text-[10px] mt-1 ${o?`text-[#f59e0b]`:`text-[#11a4d4]`}`,children:DJ(e)})]}),(0,U.jsxs)(`div`,{className:`flex items-start gap-1`,children:[(0,U.jsx)(`button`,{type:`button`,onClick:r,title:t?`Hide Details`:`Show Details`,"aria-label":t?`Hide Details`:`Show Details`,className:`h-7 w-7 inline-flex items-center justify-center border border-slate-700 rounded-sm text-slate-400 hover:border-[#11a4d4] hover:text-[#11a4d4]`,children:t?(0,U.jsx)(Gs,{size:13}):(0,U.jsx)(qs,{size:13})}),(0,U.jsx)(`button`,{type:`button`,disabled:n,onClick:i,title:e.enabled?`Disable Package`:`Enable Package`,"aria-label":e.enabled?`Disable Package`:`Enable Package`,className:`h-7 w-7 inline-flex items-center justify-center border border-slate-700 rounded-sm text-slate-400 hover:border-[#11a4d4] hover:text-[#11a4d4] disabled:opacity-50`,children:e.enabled?(0,U.jsx)(il,{size:13}):(0,U.jsx)(al,{size:13})}),(0,U.jsx)(`button`,{type:`button`,disabled:n,onClick:a,title:`Unregister Package`,"aria-label":`Unregister Package`,className:`h-7 w-7 inline-flex items-center justify-center border border-slate-700 rounded-sm text-slate-400 hover:border-red-400 hover:text-red-300 disabled:opacity-50`,children:(0,U.jsx)(Cl,{size:13})})]})]}),t?(0,U.jsx)(MJ,{pkg:e}):null]})}function _6(e){if(typeof e==`string`||typeof e==`number`)return``+e;let t=``;if(Array.isArray(e))for(let n=0,r;n<e.length;n++)(r=_6(e[n]))!==``&&(t+=(t&&` `)+r);else for(let n in e)e[n]&&(t+=(t&&` `)+n);return t}var lGe={value:()=>{}};function v6(){for(var e=0,t=arguments.length,n={},r;e<t;++e){if(!(r=arguments[e]+``)||r in n||/[\s.]/.test(r))throw Error(`illegal type: `+r);n[r]=[]}return new y6(n)}function y6(e){this._=e}function uGe(e,t){return e.trim().split(/^|\s+/).map(function(e){var n=``,r=e.indexOf(`.`);if(r>=0&&(n=e.slice(r+1),e=e.slice(0,r)),e&&!t.hasOwnProperty(e))throw Error(`unknown type: `+e);return{type:e,name:n}})}y6.prototype=v6.prototype={constructor:y6,on:function(e,t){var n=this._,r=uGe(e+``,n),i,a=-1,o=r.length;if(arguments.length<2){for(;++a<o;)if((i=(e=r[a]).type)&&(i=dGe(n[i],e.name)))return i;return}if(t!=null&&typeof t!=`function`)throw Error(`invalid callback: `+t);for(;++a<o;)if(i=(e=r[a]).type)n[i]=b6(n[i],e.name,t);else if(t==null)for(i in n)n[i]=b6(n[i],e.name,null);return this},copy:function(){var e={},t=this._;for(var n in t)e[n]=t[n].slice();return new y6(e)},call:function(e,t){if((i=arguments.length-2)>0)for(var n=Array(i),r=0,i,a;r<i;++r)n[r]=arguments[r+2];if(!this._.hasOwnProperty(e))throw Error(`unknown type: `+e);for(a=this._[e],r=0,i=a.length;r<i;++r)a[r].value.apply(t,n)},apply:function(e,t,n){if(!this._.hasOwnProperty(e))throw Error(`unknown type: `+e);for(var r=this._[e],i=0,a=r.length;i<a;++i)r[i].value.apply(t,n)}};function dGe(e,t){for(var n=0,r=e.length,i;n<r;++n)if((i=e[n]).name===t)return i.value}function b6(e,t,n){for(var r=0,i=e.length;r<i;++r)if(e[r].name===t){e[r]=lGe,e=e.slice(0,r).concat(e.slice(r+1));break}return n!=null&&e.push({name:t,value:n}),e}var x6={svg:`http://www.w3.org/2000/svg`,xhtml:`http://www.w3.org/1999/xhtml`,xlink:`http://www.w3.org/1999/xlink`,xml:`http://www.w3.org/XML/1998/namespace`,xmlns:`http://www.w3.org/2000/xmlns/`};function S6(e){var t=e+=``,n=t.indexOf(`:`);return n>=0&&(t=e.slice(0,n))!==`xmlns`&&(e=e.slice(n+1)),x6.hasOwnProperty(t)?{space:x6[t],local:e}:e}function fGe(e){return function(){var t=this.ownerDocument,n=this.namespaceURI;return n===`http://www.w3.org/1999/xhtml`&&t.documentElement.namespaceURI===`http://www.w3.org/1999/xhtml`?t.createElement(e):t.createElementNS(n,e)}}function pGe(e){return function(){return this.ownerDocument.createElementNS(e.space,e.local)}}function C6(e){var t=S6(e);return(t.local?pGe:fGe)(t)}function mGe(){}function w6(e){return e==null?mGe:function(){return this.querySelector(e)}}function hGe(e){typeof e!=`function`&&(e=w6(e));for(var t=this._groups,n=t.length,r=Array(n),i=0;i<n;++i)for(var a=t[i],o=a.length,s=r[i]=Array(o),c,l,u=0;u<o;++u)(c=a[u])&&(l=e.call(c,c.__data__,u,a))&&(`__data__`in c&&(l.__data__=c.__data__),s[u]=l);return new z6(r,this._parents)}function gGe(e){return e==null?[]:Array.isArray(e)?e:Array.from(e)}function _Ge(){return[]}function T6(e){return e==null?_Ge:function(){return this.querySelectorAll(e)}}function vGe(e){return function(){return gGe(e.apply(this,arguments))}}function yGe(e){e=typeof e==`function`?vGe(e):T6(e);for(var t=this._groups,n=t.length,r=[],i=[],a=0;a<n;++a)for(var o=t[a],s=o.length,c,l=0;l<s;++l)(c=o[l])&&(r.push(e.call(c,c.__data__,l,o)),i.push(c));return new z6(r,i)}function E6(e){return function(){return this.matches(e)}}function D6(e){return function(t){return t.matches(e)}}var bGe=Array.prototype.find;function xGe(e){return function(){return bGe.call(this.children,e)}}function SGe(){return this.firstElementChild}function CGe(e){return this.select(e==null?SGe:xGe(typeof e==`function`?e:D6(e)))}var wGe=Array.prototype.filter;function TGe(){return Array.from(this.children)}function EGe(e){return function(){return wGe.call(this.children,e)}}function DGe(e){return this.selectAll(e==null?TGe:EGe(typeof e==`function`?e:D6(e)))}function OGe(e){typeof e!=`function`&&(e=E6(e));for(var t=this._groups,n=t.length,r=Array(n),i=0;i<n;++i)for(var a=t[i],o=a.length,s=r[i]=[],c,l=0;l<o;++l)(c=a[l])&&e.call(c,c.__data__,l,a)&&s.push(c);return new z6(r,this._parents)}function O6(e){return Array(e.length)}function kGe(){return new z6(this._enter||this._groups.map(O6),this._parents)}function k6(e,t){this.ownerDocument=e.ownerDocument,this.namespaceURI=e.namespaceURI,this._next=null,this._parent=e,this.__data__=t}k6.prototype={constructor:k6,appendChild:function(e){return this._parent.insertBefore(e,this._next)},insertBefore:function(e,t){return this._parent.insertBefore(e,t)},querySelector:function(e){return this._parent.querySelector(e)},querySelectorAll:function(e){return this._parent.querySelectorAll(e)}};function AGe(e){return function(){return e}}function jGe(e,t,n,r,i,a){for(var o=0,s,c=t.length,l=a.length;o<l;++o)(s=t[o])?(s.__data__=a[o],r[o]=s):n[o]=new k6(e,a[o]);for(;o<c;++o)(s=t[o])&&(i[o]=s)}function MGe(e,t,n,r,i,a,o){var s,c,l=new Map,u=t.length,d=a.length,f=Array(u),p;for(s=0;s<u;++s)(c=t[s])&&(f[s]=p=o.call(c,c.__data__,s,t)+``,l.has(p)?i[s]=c:l.set(p,c));for(s=0;s<d;++s)p=o.call(e,a[s],s,a)+``,(c=l.get(p))?(r[s]=c,c.__data__=a[s],l.delete(p)):n[s]=new k6(e,a[s]);for(s=0;s<u;++s)(c=t[s])&&l.get(f[s])===c&&(i[s]=c)}function NGe(e){return e.__data__}function PGe(e,t){if(!arguments.length)return Array.from(this,NGe);var n=t?MGe:jGe,r=this._parents,i=this._groups;typeof e!=`function`&&(e=AGe(e));for(var a=i.length,o=Array(a),s=Array(a),c=Array(a),l=0;l<a;++l){var u=r[l],d=i[l],f=d.length,p=FGe(e.call(u,u&&u.__data__,l,r)),m=p.length,h=s[l]=Array(m),g=o[l]=Array(m);n(u,d,h,g,c[l]=Array(f),p,t);for(var _=0,v=0,y,b;_<m;++_)if(y=h[_]){for(_>=v&&(v=_+1);!(b=g[v])&&++v<m;);y._next=b||null}}return o=new z6(o,r),o._enter=s,o._exit=c,o}function FGe(e){return typeof e==`object`&&`length`in e?e:Array.from(e)}function IGe(){return new z6(this._exit||this._groups.map(O6),this._parents)}function LGe(e,t,n){var r=this.enter(),i=this,a=this.exit();return typeof e==`function`?(r=e(r),r&&=r.selection()):r=r.append(e+``),t!=null&&(i=t(i),i&&=i.selection()),n==null?a.remove():n(a),r&&i?r.merge(i).order():i}function RGe(e){for(var t=e.selection?e.selection():e,n=this._groups,r=t._groups,i=n.length,a=r.length,o=Math.min(i,a),s=Array(i),c=0;c<o;++c)for(var l=n[c],u=r[c],d=l.length,f=s[c]=Array(d),p,m=0;m<d;++m)(p=l[m]||u[m])&&(f[m]=p);for(;c<i;++c)s[c]=n[c];return new z6(s,this._parents)}function zGe(){for(var e=this._groups,t=-1,n=e.length;++t<n;)for(var r=e[t],i=r.length-1,a=r[i],o;--i>=0;)(o=r[i])&&(a&&o.compareDocumentPosition(a)^4&&a.parentNode.insertBefore(o,a),a=o);return this}function BGe(e){e||=VGe;function t(t,n){return t&&n?e(t.__data__,n.__data__):!t-!n}for(var n=this._groups,r=n.length,i=Array(r),a=0;a<r;++a){for(var o=n[a],s=o.length,c=i[a]=Array(s),l,u=0;u<s;++u)(l=o[u])&&(c[u]=l);c.sort(t)}return new z6(i,this._parents).order()}function VGe(e,t){return e<t?-1:e>t?1:e>=t?0:NaN}function HGe(){var e=arguments[0];return arguments[0]=this,e.apply(null,arguments),this}function UGe(){return Array.from(this)}function WGe(){for(var e=this._groups,t=0,n=e.length;t<n;++t)for(var r=e[t],i=0,a=r.length;i<a;++i){var o=r[i];if(o)return o}return null}function GGe(){let e=0;for(let t of this)++e;return e}function KGe(){return!this.node()}function qGe(e){for(var t=this._groups,n=0,r=t.length;n<r;++n)for(var i=t[n],a=0,o=i.length,s;a<o;++a)(s=i[a])&&e.call(s,s.__data__,a,i);return this}function JGe(e){return function(){this.removeAttribute(e)}}function YGe(e){return function(){this.removeAttributeNS(e.space,e.local)}}function XGe(e,t){return function(){this.setAttribute(e,t)}}function ZGe(e,t){return function(){this.setAttributeNS(e.space,e.local,t)}}function QGe(e,t){return function(){var n=t.apply(this,arguments);n==null?this.removeAttribute(e):this.setAttribute(e,n)}}function $Ge(e,t){return function(){var n=t.apply(this,arguments);n==null?this.removeAttributeNS(e.space,e.local):this.setAttributeNS(e.space,e.local,n)}}function eKe(e,t){var n=S6(e);if(arguments.length<2){var r=this.node();return n.local?r.getAttributeNS(n.space,n.local):r.getAttribute(n)}return this.each((t==null?n.local?YGe:JGe:typeof t==`function`?n.local?$Ge:QGe:n.local?ZGe:XGe)(n,t))}function A6(e){return e.ownerDocument&&e.ownerDocument.defaultView||e.document&&e||e.defaultView}function tKe(e){return function(){this.style.removeProperty(e)}}function nKe(e,t,n){return function(){this.style.setProperty(e,t,n)}}function rKe(e,t,n){return function(){var r=t.apply(this,arguments);r==null?this.style.removeProperty(e):this.style.setProperty(e,r,n)}}function iKe(e,t,n){return arguments.length>1?this.each((t==null?tKe:typeof t==`function`?rKe:nKe)(e,t,n??``)):j6(this.node(),e)}function j6(e,t){return e.style.getPropertyValue(t)||A6(e).getComputedStyle(e,null).getPropertyValue(t)}function aKe(e){return function(){delete this[e]}}function oKe(e,t){return function(){this[e]=t}}function sKe(e,t){return function(){var n=t.apply(this,arguments);n==null?delete this[e]:this[e]=n}}function cKe(e,t){return arguments.length>1?this.each((t==null?aKe:typeof t==`function`?sKe:oKe)(e,t)):this.node()[e]}function M6(e){return e.trim().split(/^|\s+/)}function N6(e){return e.classList||new P6(e)}function P6(e){this._node=e,this._names=M6(e.getAttribute(`class`)||``)}P6.prototype={add:function(e){this._names.indexOf(e)<0&&(this._names.push(e),this._node.setAttribute(`class`,this._names.join(` `)))},remove:function(e){var t=this._names.indexOf(e);t>=0&&(this._names.splice(t,1),this._node.setAttribute(`class`,this._names.join(` `)))},contains:function(e){return this._names.indexOf(e)>=0}};function F6(e,t){for(var n=N6(e),r=-1,i=t.length;++r<i;)n.add(t[r])}function I6(e,t){for(var n=N6(e),r=-1,i=t.length;++r<i;)n.remove(t[r])}function lKe(e){return function(){F6(this,e)}}function uKe(e){return function(){I6(this,e)}}function dKe(e,t){return function(){(t.apply(this,arguments)?F6:I6)(this,e)}}function fKe(e,t){var n=M6(e+``);if(arguments.length<2){for(var r=N6(this.node()),i=-1,a=n.length;++i<a;)if(!r.contains(n[i]))return!1;return!0}return this.each((typeof t==`function`?dKe:t?lKe:uKe)(n,t))}function pKe(){this.textContent=``}function mKe(e){return function(){this.textContent=e}}function hKe(e){return function(){var t=e.apply(this,arguments);this.textContent=t??``}}function gKe(e){return arguments.length?this.each(e==null?pKe:(typeof e==`function`?hKe:mKe)(e)):this.node().textContent}function _Ke(){this.innerHTML=``}function vKe(e){return function(){this.innerHTML=e}}function yKe(e){return function(){var t=e.apply(this,arguments);this.innerHTML=t??``}}function bKe(e){return arguments.length?this.each(e==null?_Ke:(typeof e==`function`?yKe:vKe)(e)):this.node().innerHTML}function xKe(){this.nextSibling&&this.parentNode.appendChild(this)}function SKe(){return this.each(xKe)}function CKe(){this.previousSibling&&this.parentNode.insertBefore(this,this.parentNode.firstChild)}function wKe(){return this.each(CKe)}function TKe(e){var t=typeof e==`function`?e:C6(e);return this.select(function(){return this.appendChild(t.apply(this,arguments))})}function EKe(){return null}function DKe(e,t){var n=typeof e==`function`?e:C6(e),r=t==null?EKe:typeof t==`function`?t:w6(t);return this.select(function(){return this.insertBefore(n.apply(this,arguments),r.apply(this,arguments)||null)})}function OKe(){var e=this.parentNode;e&&e.removeChild(this)}function kKe(){return this.each(OKe)}function AKe(){var e=this.cloneNode(!1),t=this.parentNode;return t?t.insertBefore(e,this.nextSibling):e}function jKe(){var e=this.cloneNode(!0),t=this.parentNode;return t?t.insertBefore(e,this.nextSibling):e}function MKe(e){return this.select(e?jKe:AKe)}function NKe(e){return arguments.length?this.property(`__data__`,e):this.node().__data__}function PKe(e){return function(t){e.call(this,t,this.__data__)}}function FKe(e){return e.trim().split(/^|\s+/).map(function(e){var t=``,n=e.indexOf(`.`);return n>=0&&(t=e.slice(n+1),e=e.slice(0,n)),{type:e,name:t}})}function IKe(e){return function(){var t=this.__on;if(t){for(var n=0,r=-1,i=t.length,a;n<i;++n)a=t[n],(!e.type||a.type===e.type)&&a.name===e.name?this.removeEventListener(a.type,a.listener,a.options):t[++r]=a;++r?t.length=r:delete this.__on}}}function LKe(e,t,n){return function(){var r=this.__on,i,a=PKe(t);if(r){for(var o=0,s=r.length;o<s;++o)if((i=r[o]).type===e.type&&i.name===e.name){this.removeEventListener(i.type,i.listener,i.options),this.addEventListener(i.type,i.listener=a,i.options=n),i.value=t;return}}this.addEventListener(e.type,a,n),i={type:e.type,name:e.name,value:t,listener:a,options:n},r?r.push(i):this.__on=[i]}}function RKe(e,t,n){var r=FKe(e+``),i,a=r.length,o;if(arguments.length<2){var s=this.node().__on;if(s){for(var c=0,l=s.length,u;c<l;++c)for(i=0,u=s[c];i<a;++i)if((o=r[i]).type===u.type&&o.name===u.name)return u.value}return}for(s=t?LKe:IKe,i=0;i<a;++i)this.each(s(r[i],t,n));return this}function L6(e,t,n){var r=A6(e),i=r.CustomEvent;typeof i==`function`?i=new i(t,n):(i=r.document.createEvent(`Event`),n?(i.initEvent(t,n.bubbles,n.cancelable),i.detail=n.detail):i.initEvent(t,!1,!1)),e.dispatchEvent(i)}function zKe(e,t){return function(){return L6(this,e,t)}}function BKe(e,t){return function(){return L6(this,e,t.apply(this,arguments))}}function VKe(e,t){return this.each((typeof t==`function`?BKe:zKe)(e,t))}function*HKe(){for(var e=this._groups,t=0,n=e.length;t<n;++t)for(var r=e[t],i=0,a=r.length,o;i<a;++i)(o=r[i])&&(yield o)}var R6=[null];function z6(e,t){this._groups=e,this._parents=t}function B6(){return new z6([[document.documentElement]],R6)}function UKe(){return this}z6.prototype=B6.prototype={constructor:z6,select:hGe,selectAll:yGe,selectChild:CGe,selectChildren:DGe,filter:OGe,data:PGe,enter:kGe,exit:IGe,join:LGe,merge:RGe,selection:UKe,order:zGe,sort:BGe,call:HGe,nodes:UGe,node:WGe,size:GGe,empty:KGe,each:qGe,attr:eKe,style:iKe,property:cKe,classed:fKe,text:gKe,html:bKe,raise:SKe,lower:wKe,append:TKe,insert:DKe,remove:kKe,clone:MKe,datum:NKe,on:RKe,dispatch:VKe,[Symbol.iterator]:HKe};function V6(e){return typeof e==`string`?new z6([[document.querySelector(e)]],[document.documentElement]):new z6([[e]],R6)}function WKe(e){let t;for(;t=e.sourceEvent;)e=t;return e}function H6(e,t){if(e=WKe(e),t===void 0&&(t=e.currentTarget),t){var n=t.ownerSVGElement||t;if(n.createSVGPoint){var r=n.createSVGPoint();return r.x=e.clientX,r.y=e.clientY,r=r.matrixTransform(t.getScreenCTM().inverse()),[r.x,r.y]}if(t.getBoundingClientRect){var i=t.getBoundingClientRect();return[e.clientX-i.left-t.clientLeft,e.clientY-i.top-t.clientTop]}}return[e.pageX,e.pageY]}var GKe={passive:!1},U6={capture:!0,passive:!1};function W6(e){e.stopImmediatePropagation()}function G6(e){e.preventDefault(),e.stopImmediatePropagation()}function K6(e){var t=e.document.documentElement,n=V6(e).on(`dragstart.drag`,G6,U6);`onselectstart`in t?n.on(`selectstart.drag`,G6,U6):(t.__noselect=t.style.MozUserSelect,t.style.MozUserSelect=`none`)}function q6(e,t){var n=e.document.documentElement,r=V6(e).on(`dragstart.drag`,null);t&&(r.on(`click.drag`,G6,U6),setTimeout(function(){r.on(`click.drag`,null)},0)),`onselectstart`in n?r.on(`selectstart.drag`,null):(n.style.MozUserSelect=n.__noselect,delete n.__noselect)}var J6=e=>()=>e;function Y6(e,{sourceEvent:t,subject:n,target:r,identifier:i,active:a,x:o,y:s,dx:c,dy:l,dispatch:u}){Object.defineProperties(this,{type:{value:e,enumerable:!0,configurable:!0},sourceEvent:{value:t,enumerable:!0,configurable:!0},subject:{value:n,enumerable:!0,configurable:!0},target:{value:r,enumerable:!0,configurable:!0},identifier:{value:i,enumerable:!0,configurable:!0},active:{value:a,enumerable:!0,configurable:!0},x:{value:o,enumerable:!0,configurable:!0},y:{value:s,enumerable:!0,configurable:!0},dx:{value:c,enumerable:!0,configurable:!0},dy:{value:l,enumerable:!0,configurable:!0},_:{value:u}})}Y6.prototype.on=function(){var e=this._.on.apply(this._,arguments);return e===this._?this:e};function KKe(e){return!e.ctrlKey&&!e.button}function qKe(){return this.parentNode}function JKe(e,t){return t??{x:e.x,y:e.y}}function YKe(){return navigator.maxTouchPoints||`ontouchstart`in this}function X6(){var e=KKe,t=qKe,n=JKe,r=YKe,i={},a=v6(`start`,`drag`,`end`),o=0,s,c,l,u,d=0;function f(e){e.on(`mousedown.drag`,p).filter(r).on(`touchstart.drag`,g).on(`touchmove.drag`,_,GKe).on(`touchend.drag touchcancel.drag`,v).style(`touch-action`,`none`).style(`-webkit-tap-highlight-color`,`rgba(0,0,0,0)`)}function p(n,r){if(!(u||!e.call(this,n,r))){var i=y(this,t.call(this,n,r),n,r,`mouse`);i&&(V6(n.view).on(`mousemove.drag`,m,U6).on(`mouseup.drag`,h,U6),K6(n.view),W6(n),l=!1,s=n.clientX,c=n.clientY,i(`start`,n))}}function m(e){if(G6(e),!l){var t=e.clientX-s,n=e.clientY-c;l=t*t+n*n>d}i.mouse(`drag`,e)}function h(e){V6(e.view).on(`mousemove.drag mouseup.drag`,null),q6(e.view,l),G6(e),i.mouse(`end`,e)}function g(n,r){if(e.call(this,n,r)){var i=n.changedTouches,a=t.call(this,n,r),o=i.length,s,c;for(s=0;s<o;++s)(c=y(this,a,n,r,i[s].identifier,i[s]))&&(W6(n),c(`start`,n,i[s]))}}function _(e){var t=e.changedTouches,n=t.length,r,a;for(r=0;r<n;++r)(a=i[t[r].identifier])&&(G6(e),a(`drag`,e,t[r]))}function v(e){var t=e.changedTouches,n=t.length,r,a;for(u&&clearTimeout(u),u=setTimeout(function(){u=null},500),r=0;r<n;++r)(a=i[t[r].identifier])&&(W6(e),a(`end`,e,t[r]))}function y(e,t,r,s,c,l){var u=a.copy(),d=H6(l||r,t),p,m,h;if((h=n.call(e,new Y6(`beforestart`,{sourceEvent:r,target:f,identifier:c,active:o,x:d[0],y:d[1],dx:0,dy:0,dispatch:u}),s))!=null)return p=h.x-d[0]||0,m=h.y-d[1]||0,function n(r,a,l){var g=d,_;switch(r){case`start`:i[c]=n,_=o++;break;case`end`:delete i[c],--o;case`drag`:d=H6(l||a,t),_=o}u.call(r,e,new Y6(r,{sourceEvent:a,subject:h,target:f,identifier:c,active:_,x:d[0]+p,y:d[1]+m,dx:d[0]-g[0],dy:d[1]-g[1],dispatch:u}),s)}}return f.filter=function(t){return arguments.length?(e=typeof t==`function`?t:J6(!!t),f):e},f.container=function(e){return arguments.length?(t=typeof e==`function`?e:J6(e),f):t},f.subject=function(e){return arguments.length?(n=typeof e==`function`?e:J6(e),f):n},f.touchable=function(e){return arguments.length?(r=typeof e==`function`?e:J6(!!e),f):r},f.on=function(){var e=a.on.apply(a,arguments);return e===a?f:e},f.clickDistance=function(e){return arguments.length?(d=(e=+e)*e,f):Math.sqrt(d)},f}function Z6(e,t,n){e.prototype=t.prototype=n,n.constructor=e}function Q6(e,t){var n=Object.create(e.prototype);for(var r in t)n[r]=t[r];return n}function $6(){}var e8=.7,t8=1/e8,n8=`\\s*([+-]?\\d+)\\s*`,r8=`\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)\\s*`,i8=`\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)%\\s*`,XKe=/^#([0-9a-f]{3,8})$/,ZKe=RegExp(`^rgb\\(${n8},${n8},${n8}\\)$`),QKe=RegExp(`^rgb\\(${i8},${i8},${i8}\\)$`),$Ke=RegExp(`^rgba\\(${n8},${n8},${n8},${r8}\\)$`),eqe=RegExp(`^rgba\\(${i8},${i8},${i8},${r8}\\)$`),tqe=RegExp(`^hsl\\(${r8},${i8},${i8}\\)$`),nqe=RegExp(`^hsla\\(${r8},${i8},${i8},${r8}\\)$`),a8={aliceblue:15792383,antiquewhite:16444375,aqua:65535,aquamarine:8388564,azure:15794175,beige:16119260,bisque:16770244,black:0,blanchedalmond:16772045,blue:255,blueviolet:9055202,brown:10824234,burlywood:14596231,cadetblue:6266528,chartreuse:8388352,chocolate:13789470,coral:16744272,cornflowerblue:6591981,cornsilk:16775388,crimson:14423100,cyan:65535,darkblue:139,darkcyan:35723,darkgoldenrod:12092939,darkgray:11119017,darkgreen:25600,darkgrey:11119017,darkkhaki:12433259,darkmagenta:9109643,darkolivegreen:5597999,darkorange:16747520,darkorchid:10040012,darkred:9109504,darksalmon:15308410,darkseagreen:9419919,darkslateblue:4734347,darkslategray:3100495,darkslategrey:3100495,darkturquoise:52945,darkviolet:9699539,deeppink:16716947,deepskyblue:49151,dimgray:6908265,dimgrey:6908265,dodgerblue:2003199,firebrick:11674146,floralwhite:16775920,forestgreen:2263842,fuchsia:16711935,gainsboro:14474460,ghostwhite:16316671,gold:16766720,goldenrod:14329120,gray:8421504,green:32768,greenyellow:11403055,grey:8421504,honeydew:15794160,hotpink:16738740,indianred:13458524,indigo:4915330,ivory:16777200,khaki:15787660,lavender:15132410,lavenderblush:16773365,lawngreen:8190976,lemonchiffon:16775885,lightblue:11393254,lightcoral:15761536,lightcyan:14745599,lightgoldenrodyellow:16448210,lightgray:13882323,lightgreen:9498256,lightgrey:13882323,lightpink:16758465,lightsalmon:16752762,lightseagreen:2142890,lightskyblue:8900346,lightslategray:7833753,lightslategrey:7833753,lightsteelblue:11584734,lightyellow:16777184,lime:65280,limegreen:3329330,linen:16445670,magenta:16711935,maroon:8388608,mediumaquamarine:6737322,mediumblue:205,mediumorchid:12211667,mediumpurple:9662683,mediumseagreen:3978097,mediumslateblue:8087790,mediumspringgreen:64154,mediumturquoise:4772300,mediumvioletred:13047173,midnightblue:1644912,mintcream:16121850,mistyrose:16770273,moccasin:16770229,navajowhite:16768685,navy:128,oldlace:16643558,olive:8421376,olivedrab:7048739,orange:16753920,orangered:16729344,orchid:14315734,palegoldenrod:15657130,palegreen:10025880,paleturquoise:11529966,palevioletred:14381203,papayawhip:16773077,peachpuff:16767673,peru:13468991,pink:16761035,plum:14524637,powderblue:11591910,purple:8388736,rebeccapurple:6697881,red:16711680,rosybrown:12357519,royalblue:4286945,saddlebrown:9127187,salmon:16416882,sandybrown:16032864,seagreen:3050327,seashell:16774638,sienna:10506797,silver:12632256,skyblue:8900331,slateblue:6970061,slategray:7372944,slategrey:7372944,snow:16775930,springgreen:65407,steelblue:4620980,tan:13808780,teal:32896,thistle:14204888,tomato:16737095,turquoise:4251856,violet:15631086,wheat:16113331,white:16777215,whitesmoke:16119285,yellow:16776960,yellowgreen:10145074};Z6($6,c8,{copy(e){return Object.assign(new this.constructor,this,e)},displayable(){return this.rgb().displayable()},hex:o8,formatHex:o8,formatHex8:rqe,formatHsl:iqe,formatRgb:s8,toString:s8});function o8(){return this.rgb().formatHex()}function rqe(){return this.rgb().formatHex8()}function iqe(){return y8(this).formatHsl()}function s8(){return this.rgb().formatRgb()}function c8(e){var t,n;return e=(e+``).trim().toLowerCase(),(t=XKe.exec(e))?(n=t[1].length,t=parseInt(t[1],16),n===6?l8(t):n===3?new f8(t>>8&15|t>>4&240,t>>4&15|t&240,(t&15)<<4|t&15,1):n===8?u8(t>>24&255,t>>16&255,t>>8&255,(t&255)/255):n===4?u8(t>>12&15|t>>8&240,t>>8&15|t>>4&240,t>>4&15|t&240,((t&15)<<4|t&15)/255):null):(t=ZKe.exec(e))?new f8(t[1],t[2],t[3],1):(t=QKe.exec(e))?new f8(t[1]*255/100,t[2]*255/100,t[3]*255/100,1):(t=$Ke.exec(e))?u8(t[1],t[2],t[3],t[4]):(t=eqe.exec(e))?u8(t[1]*255/100,t[2]*255/100,t[3]*255/100,t[4]):(t=tqe.exec(e))?v8(t[1],t[2]/100,t[3]/100,1):(t=nqe.exec(e))?v8(t[1],t[2]/100,t[3]/100,t[4]):a8.hasOwnProperty(e)?l8(a8[e]):e===`transparent`?new f8(NaN,NaN,NaN,0):null}function l8(e){return new f8(e>>16&255,e>>8&255,e&255,1)}function u8(e,t,n,r){return r<=0&&(e=t=n=NaN),new f8(e,t,n,r)}function aqe(e){return e instanceof $6||(e=c8(e)),e?(e=e.rgb(),new f8(e.r,e.g,e.b,e.opacity)):new f8}function d8(e,t,n,r){return arguments.length===1?aqe(e):new f8(e,t,n,r??1)}function f8(e,t,n,r){this.r=+e,this.g=+t,this.b=+n,this.opacity=+r}Z6(f8,d8,Q6($6,{brighter(e){return e=e==null?t8:t8**+e,new f8(this.r*e,this.g*e,this.b*e,this.opacity)},darker(e){return e=e==null?e8:e8**+e,new f8(this.r*e,this.g*e,this.b*e,this.opacity)},rgb(){return this},clamp(){return new f8(g8(this.r),g8(this.g),g8(this.b),h8(this.opacity))},displayable(){return-.5<=this.r&&this.r<255.5&&-.5<=this.g&&this.g<255.5&&-.5<=this.b&&this.b<255.5&&0<=this.opacity&&this.opacity<=1},hex:p8,formatHex:p8,formatHex8:oqe,formatRgb:m8,toString:m8}));function p8(){return`#${_8(this.r)}${_8(this.g)}${_8(this.b)}`}function oqe(){return`#${_8(this.r)}${_8(this.g)}${_8(this.b)}${_8((isNaN(this.opacity)?1:this.opacity)*255)}`}function m8(){let e=h8(this.opacity);return`${e===1?`rgb(`:`rgba(`}${g8(this.r)}, ${g8(this.g)}, ${g8(this.b)}${e===1?`)`:`, ${e})`}`}function h8(e){return isNaN(e)?1:Math.max(0,Math.min(1,e))}function g8(e){return Math.max(0,Math.min(255,Math.round(e)||0))}function _8(e){return e=g8(e),(e<16?`0`:``)+e.toString(16)}function v8(e,t,n,r){return r<=0?e=t=n=NaN:n<=0||n>=1?e=t=NaN:t<=0&&(e=NaN),new b8(e,t,n,r)}function y8(e){if(e instanceof b8)return new b8(e.h,e.s,e.l,e.opacity);if(e instanceof $6||(e=c8(e)),!e)return new b8;if(e instanceof b8)return e;e=e.rgb();var t=e.r/255,n=e.g/255,r=e.b/255,i=Math.min(t,n,r),a=Math.max(t,n,r),o=NaN,s=a-i,c=(a+i)/2;return s?(o=t===a?(n-r)/s+(n<r)*6:n===a?(r-t)/s+2:(t-n)/s+4,s/=c<.5?a+i:2-a-i,o*=60):s=c>0&&c<1?0:o,new b8(o,s,c,e.opacity)}function sqe(e,t,n,r){return arguments.length===1?y8(e):new b8(e,t,n,r??1)}function b8(e,t,n,r){this.h=+e,this.s=+t,this.l=+n,this.opacity=+r}Z6(b8,sqe,Q6($6,{brighter(e){return e=e==null?t8:t8**+e,new b8(this.h,this.s,this.l*e,this.opacity)},darker(e){return e=e==null?e8:e8**+e,new b8(this.h,this.s,this.l*e,this.opacity)},rgb(){var e=this.h%360+(this.h<0)*360,t=isNaN(e)||isNaN(this.s)?0:this.s,n=this.l,r=n+(n<.5?n:1-n)*t,i=2*n-r;return new f8(C8(e>=240?e-240:e+120,i,r),C8(e,i,r),C8(e<120?e+240:e-120,i,r),this.opacity)},clamp(){return new b8(x8(this.h),S8(this.s),S8(this.l),h8(this.opacity))},displayable(){return(0<=this.s&&this.s<=1||isNaN(this.s))&&0<=this.l&&this.l<=1&&0<=this.opacity&&this.opacity<=1},formatHsl(){let e=h8(this.opacity);return`${e===1?`hsl(`:`hsla(`}${x8(this.h)}, ${S8(this.s)*100}%, ${S8(this.l)*100}%${e===1?`)`:`, ${e})`}`}}));function x8(e){return e=(e||0)%360,e<0?e+360:e}function S8(e){return Math.max(0,Math.min(1,e||0))}function C8(e,t,n){return(e<60?t+(n-t)*e/60:e<180?n:e<240?t+(n-t)*(240-e)/60:t)*255}var w8=e=>()=>e;function cqe(e,t){return function(n){return e+n*t}}function lqe(e,t,n){return e**=+n,t=t**+n-e,n=1/n,function(r){return(e+r*t)**+n}}function uqe(e){return(e=+e)==1?T8:function(t,n){return n-t?lqe(t,n,e):w8(isNaN(t)?n:t)}}function T8(e,t){var n=t-e;return n?cqe(e,n):w8(isNaN(e)?t:e)}var E8=(function e(t){var n=uqe(t);function r(e,t){var r=n((e=d8(e)).r,(t=d8(t)).r),i=n(e.g,t.g),a=n(e.b,t.b),o=T8(e.opacity,t.opacity);return function(t){return e.r=r(t),e.g=i(t),e.b=a(t),e.opacity=o(t),e+``}}return r.gamma=e,r})(1);function dqe(e,t){t||=[];var n=e?Math.min(t.length,e.length):0,r=t.slice(),i;return function(a){for(i=0;i<n;++i)r[i]=e[i]*(1-a)+t[i]*a;return r}}function fqe(e){return ArrayBuffer.isView(e)&&!(e instanceof DataView)}function pqe(e,t){var n=t?t.length:0,r=e?Math.min(n,e.length):0,i=Array(r),a=Array(n),o;for(o=0;o<r;++o)i[o]=j8(e[o],t[o]);for(;o<n;++o)a[o]=t[o];return function(e){for(o=0;o<r;++o)a[o]=i[o](e);return a}}function mqe(e,t){var n=new Date;return e=+e,t=+t,function(r){return n.setTime(e*(1-r)+t*r),n}}function D8(e,t){return e=+e,t=+t,function(n){return e*(1-n)+t*n}}function hqe(e,t){var n={},r={},i;for(i in(typeof e!=`object`||!e)&&(e={}),(typeof t!=`object`||!t)&&(t={}),t)i in e?n[i]=j8(e[i],t[i]):r[i]=t[i];return function(e){for(i in n)r[i]=n[i](e);return r}}var O8=/[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g,k8=new RegExp(O8.source,`g`);function gqe(e){return function(){return e}}function _qe(e){return function(t){return e(t)+``}}function A8(e,t){var n=O8.lastIndex=k8.lastIndex=0,r,i,a,o=-1,s=[],c=[];for(e+=``,t+=``;(r=O8.exec(e))&&(i=k8.exec(t));)(a=i.index)>n&&(a=t.slice(n,a),s[o]?s[o]+=a:s[++o]=a),(r=r[0])===(i=i[0])?s[o]?s[o]+=i:s[++o]=i:(s[++o]=null,c.push({i:o,x:D8(r,i)})),n=k8.lastIndex;return n<t.length&&(a=t.slice(n),s[o]?s[o]+=a:s[++o]=a),s.length<2?c[0]?_qe(c[0].x):gqe(t):(t=c.length,function(e){for(var n=0,r;n<t;++n)s[(r=c[n]).i]=r.x(e);return s.join(``)})}function j8(e,t){var n=typeof t,r;return t==null||n===`boolean`?w8(t):(n===`number`?D8:n===`string`?(r=c8(t))?(t=r,E8):A8:t instanceof c8?E8:t instanceof Date?mqe:fqe(t)?dqe:Array.isArray(t)?pqe:typeof t.valueOf!=`function`&&typeof t.toString!=`function`||isNaN(t)?hqe:D8)(e,t)}var M8=180/Math.PI,N8={translateX:0,translateY:0,rotate:0,skewX:0,scaleX:1,scaleY:1};function P8(e,t,n,r,i,a){var o,s,c;return(o=Math.sqrt(e*e+t*t))&&(e/=o,t/=o),(c=e*n+t*r)&&(n-=e*c,r-=t*c),(s=Math.sqrt(n*n+r*r))&&(n/=s,r/=s,c/=s),e*r<t*n&&(e=-e,t=-t,c=-c,o=-o),{translateX:i,translateY:a,rotate:Math.atan2(t,e)*M8,skewX:Math.atan(c)*M8,scaleX:o,scaleY:s}}var F8;function vqe(e){let t=new(typeof DOMMatrix==`function`?DOMMatrix:WebKitCSSMatrix)(e+``);return t.isIdentity?N8:P8(t.a,t.b,t.c,t.d,t.e,t.f)}function yqe(e){return e==null||(F8||=document.createElementNS(`http://www.w3.org/2000/svg`,`g`),F8.setAttribute(`transform`,e),!(e=F8.transform.baseVal.consolidate()))?N8:(e=e.matrix,P8(e.a,e.b,e.c,e.d,e.e,e.f))}function I8(e,t,n,r){function i(e){return e.length?e.pop()+` `:``}function a(e,r,i,a,o,s){if(e!==i||r!==a){var c=o.push(`translate(`,null,t,null,n);s.push({i:c-4,x:D8(e,i)},{i:c-2,x:D8(r,a)})}else(i||a)&&o.push(`translate(`+i+t+a+n)}function o(e,t,n,a){e===t?t&&n.push(i(n)+`rotate(`+t+r):(e-t>180?t+=360:t-e>180&&(e+=360),a.push({i:n.push(i(n)+`rotate(`,null,r)-2,x:D8(e,t)}))}function s(e,t,n,a){e===t?t&&n.push(i(n)+`skewX(`+t+r):a.push({i:n.push(i(n)+`skewX(`,null,r)-2,x:D8(e,t)})}function c(e,t,n,r,a,o){if(e!==n||t!==r){var s=a.push(i(a)+`scale(`,null,`,`,null,`)`);o.push({i:s-4,x:D8(e,n)},{i:s-2,x:D8(t,r)})}else(n!==1||r!==1)&&a.push(i(a)+`scale(`+n+`,`+r+`)`)}return function(t,n){var r=[],i=[];return t=e(t),n=e(n),a(t.translateX,t.translateY,n.translateX,n.translateY,r,i),o(t.rotate,n.rotate,r,i),s(t.skewX,n.skewX,r,i),c(t.scaleX,t.scaleY,n.scaleX,n.scaleY,r,i),t=n=null,function(e){for(var t=-1,n=i.length,a;++t<n;)r[(a=i[t]).i]=a.x(e);return r.join(``)}}}var bqe=I8(vqe,`px, `,`px)`,`deg)`),xqe=I8(yqe,`, `,`)`,`)`),Sqe=1e-12;function L8(e){return((e=Math.exp(e))+1/e)/2}function Cqe(e){return((e=Math.exp(e))-1/e)/2}function wqe(e){return((e=Math.exp(2*e))-1)/(e+1)}var R8=(function e(t,n,r){function i(e,i){var a=e[0],o=e[1],s=e[2],c=i[0],l=i[1],u=i[2],d=c-a,f=l-o,p=d*d+f*f,m,h;if(p<Sqe)h=Math.log(u/s)/t,m=function(e){return[a+e*d,o+e*f,s*Math.exp(t*e*h)]};else{var g=Math.sqrt(p),_=(u*u-s*s+r*p)/(2*s*n*g),v=(u*u-s*s-r*p)/(2*u*n*g),y=Math.log(Math.sqrt(_*_+1)-_);h=(Math.log(Math.sqrt(v*v+1)-v)-y)/t,m=function(e){var r=e*h,i=L8(y),c=s/(n*g)*(i*wqe(t*r+y)-Cqe(y));return[a+c*d,o+c*f,s*i/L8(t*r+y)]}}return m.duration=h*1e3*t/Math.SQRT2,m}return i.rho=function(t){var n=Math.max(.001,+t),r=n*n;return e(n,r,r*r)},i})(Math.SQRT2,2,4),z8=0,B8=0,V8=0,Tqe=1e3,H8,U8,W8=0,G8=0,K8=0,q8=typeof performance==`object`&&performance.now?performance:Date,Eqe=typeof window==`object`&&window.requestAnimationFrame?window.requestAnimationFrame.bind(window):function(e){setTimeout(e,17)};function J8(){return G8||=(Eqe(Dqe),q8.now()+K8)}function Dqe(){G8=0}function Y8(){this._call=this._time=this._next=null}Y8.prototype=Oqe.prototype={constructor:Y8,restart:function(e,t,n){if(typeof e!=`function`)throw TypeError(`callback is not a function`);n=(n==null?J8():+n)+(t==null?0:+t),!this._next&&U8!==this&&(U8?U8._next=this:H8=this,U8=this),this._call=e,this._time=n,X8()},stop:function(){this._call&&(this._call=null,this._time=1/0,X8())}};function Oqe(e,t,n){var r=new Y8;return r.restart(e,t,n),r}function kqe(){J8(),++z8;for(var e=H8,t;e;)(t=G8-e._time)>=0&&e._call.call(void 0,t),e=e._next;--z8}function Aqe(){G8=(W8=q8.now())+K8,z8=B8=0;try{kqe()}finally{z8=0,Mqe(),G8=0}}function jqe(){var e=q8.now(),t=e-W8;t>Tqe&&(K8-=t,W8=e)}function Mqe(){for(var e,t=H8,n,r=1/0;t;)t._call?(r>t._time&&(r=t._time),e=t,t=t._next):(n=t._next,t._next=null,t=e?e._next=n:H8=n);U8=e,X8(r)}function X8(e){z8||(B8&&=clearTimeout(B8),e-G8>24?(e<1/0&&(B8=setTimeout(Aqe,e-q8.now()-K8)),V8&&=clearInterval(V8)):(V8||=(W8=q8.now(),setInterval(jqe,Tqe)),z8=1,Eqe(Aqe)))}function Nqe(e,t,n){var r=new Y8;return t=t==null?0:+t,r.restart(n=>{r.stop(),e(n+t)},t,n),r}var Pqe=v6(`start`,`end`,`cancel`,`interrupt`),Fqe=[];function Z8(e,t,n,r,i,a){var o=e.__transition;if(!o)e.__transition={};else if(n in o)return;Iqe(e,n,{name:t,index:r,group:i,on:Pqe,tween:Fqe,time:a.time,delay:a.delay,duration:a.duration,ease:a.ease,timer:null,state:0})}function Q8(e,t){var n=e5(e,t);if(n.state>0)throw Error(`too late; already scheduled`);return n}function $8(e,t){var n=e5(e,t);if(n.state>3)throw Error(`too late; already running`);return n}function e5(e,t){var n=e.__transition;if(!n||!(n=n[t]))throw Error(`transition not found`);return n}function Iqe(e,t,n){var r=e.__transition,i;r[t]=n,n.timer=Oqe(a,0,n.time);function a(e){n.state=1,n.timer.restart(o,n.delay,n.time),n.delay<=e&&o(e-n.delay)}function o(a){var l,u,d,f;if(n.state!==1)return c();for(l in r)if(f=r[l],f.name===n.name){if(f.state===3)return Nqe(o);f.state===4?(f.state=6,f.timer.stop(),f.on.call(`interrupt`,e,e.__data__,f.index,f.group),delete r[l]):+l<t&&(f.state=6,f.timer.stop(),f.on.call(`cancel`,e,e.__data__,f.index,f.group),delete r[l])}if(Nqe(function(){n.state===3&&(n.state=4,n.timer.restart(s,n.delay,n.time),s(a))}),n.state=2,n.on.call(`start`,e,e.__data__,n.index,n.group),n.state===2){for(n.state=3,i=Array(d=n.tween.length),l=0,u=-1;l<d;++l)(f=n.tween[l].value.call(e,e.__data__,n.index,n.group))&&(i[++u]=f);i.length=u+1}}function s(t){for(var r=t<n.duration?n.ease.call(null,t/n.duration):(n.timer.restart(c),n.state=5,1),a=-1,o=i.length;++a<o;)i[a].call(e,r);n.state===5&&(n.on.call(`end`,e,e.__data__,n.index,n.group),c())}function c(){for(var i in n.state=6,n.timer.stop(),delete r[t],r)return;delete e.__transition}}function t5(e,t){var n=e.__transition,r,i,a=!0,o;if(n){for(o in t=t==null?null:t+``,n){if((r=n[o]).name!==t){a=!1;continue}i=r.state>2&&r.state<5,r.state=6,r.timer.stop(),r.on.call(i?`interrupt`:`cancel`,e,e.__data__,r.index,r.group),delete n[o]}a&&delete e.__transition}}function Lqe(e){return this.each(function(){t5(this,e)})}function Rqe(e,t){var n,r;return function(){var i=$8(this,e),a=i.tween;if(a!==n){r=n=a;for(var o=0,s=r.length;o<s;++o)if(r[o].name===t){r=r.slice(),r.splice(o,1);break}}i.tween=r}}function zqe(e,t,n){var r,i;if(typeof n!=`function`)throw Error();return function(){var a=$8(this,e),o=a.tween;if(o!==r){i=(r=o).slice();for(var s={name:t,value:n},c=0,l=i.length;c<l;++c)if(i[c].name===t){i[c]=s;break}c===l&&i.push(s)}a.tween=i}}function Bqe(e,t){var n=this._id;if(e+=``,arguments.length<2){for(var r=e5(this.node(),n).tween,i=0,a=r.length,o;i<a;++i)if((o=r[i]).name===e)return o.value;return null}return this.each((t==null?Rqe:zqe)(n,e,t))}function n5(e,t,n){var r=e._id;return e.each(function(){var e=$8(this,r);(e.value||={})[t]=n.apply(this,arguments)}),function(e){return e5(e,r).value[t]}}function Vqe(e,t){var n;return(typeof t==`number`?D8:t instanceof c8?E8:(n=c8(t))?(t=n,E8):A8)(e,t)}function Hqe(e){return function(){this.removeAttribute(e)}}function Uqe(e){return function(){this.removeAttributeNS(e.space,e.local)}}function Wqe(e,t,n){var r,i=n+``,a;return function(){var o=this.getAttribute(e);return o===i?null:o===r?a:a=t(r=o,n)}}function Gqe(e,t,n){var r,i=n+``,a;return function(){var o=this.getAttributeNS(e.space,e.local);return o===i?null:o===r?a:a=t(r=o,n)}}function Kqe(e,t,n){var r,i,a;return function(){var o,s=n(this),c;return s==null?void this.removeAttribute(e):(o=this.getAttribute(e),c=s+``,o===c?null:o===r&&c===i?a:(i=c,a=t(r=o,s)))}}function qqe(e,t,n){var r,i,a;return function(){var o,s=n(this),c;return s==null?void this.removeAttributeNS(e.space,e.local):(o=this.getAttributeNS(e.space,e.local),c=s+``,o===c?null:o===r&&c===i?a:(i=c,a=t(r=o,s)))}}function Jqe(e,t){var n=S6(e),r=n===`transform`?xqe:Vqe;return this.attrTween(e,typeof t==`function`?(n.local?qqe:Kqe)(n,r,n5(this,`attr.`+e,t)):t==null?(n.local?Uqe:Hqe)(n):(n.local?Gqe:Wqe)(n,r,t))}function Yqe(e,t){return function(n){this.setAttribute(e,t.call(this,n))}}function Xqe(e,t){return function(n){this.setAttributeNS(e.space,e.local,t.call(this,n))}}function Zqe(e,t){var n,r;function i(){var i=t.apply(this,arguments);return i!==r&&(n=(r=i)&&Xqe(e,i)),n}return i._value=t,i}function Qqe(e,t){var n,r;function i(){var i=t.apply(this,arguments);return i!==r&&(n=(r=i)&&Yqe(e,i)),n}return i._value=t,i}function $qe(e,t){var n=`attr.`+e;if(arguments.length<2)return(n=this.tween(n))&&n._value;if(t==null)return this.tween(n,null);if(typeof t!=`function`)throw Error();var r=S6(e);return this.tween(n,(r.local?Zqe:Qqe)(r,t))}function eJe(e,t){return function(){Q8(this,e).delay=+t.apply(this,arguments)}}function tJe(e,t){return t=+t,function(){Q8(this,e).delay=t}}function nJe(e){var t=this._id;return arguments.length?this.each((typeof e==`function`?eJe:tJe)(t,e)):e5(this.node(),t).delay}function rJe(e,t){return function(){$8(this,e).duration=+t.apply(this,arguments)}}function iJe(e,t){return t=+t,function(){$8(this,e).duration=t}}function aJe(e){var t=this._id;return arguments.length?this.each((typeof e==`function`?rJe:iJe)(t,e)):e5(this.node(),t).duration}function oJe(e,t){if(typeof t!=`function`)throw Error();return function(){$8(this,e).ease=t}}function sJe(e){var t=this._id;return arguments.length?this.each(oJe(t,e)):e5(this.node(),t).ease}function cJe(e,t){return function(){var n=t.apply(this,arguments);if(typeof n!=`function`)throw Error();$8(this,e).ease=n}}function lJe(e){if(typeof e!=`function`)throw Error();return this.each(cJe(this._id,e))}function uJe(e){typeof e!=`function`&&(e=E6(e));for(var t=this._groups,n=t.length,r=Array(n),i=0;i<n;++i)for(var a=t[i],o=a.length,s=r[i]=[],c,l=0;l<o;++l)(c=a[l])&&e.call(c,c.__data__,l,a)&&s.push(c);return new r5(r,this._parents,this._name,this._id)}function dJe(e){if(e._id!==this._id)throw Error();for(var t=this._groups,n=e._groups,r=t.length,i=n.length,a=Math.min(r,i),o=Array(r),s=0;s<a;++s)for(var c=t[s],l=n[s],u=c.length,d=o[s]=Array(u),f,p=0;p<u;++p)(f=c[p]||l[p])&&(d[p]=f);for(;s<r;++s)o[s]=t[s];return new r5(o,this._parents,this._name,this._id)}function fJe(e){return(e+``).trim().split(/^|\s+/).every(function(e){var t=e.indexOf(`.`);return t>=0&&(e=e.slice(0,t)),!e||e===`start`})}function pJe(e,t,n){var r,i,a=fJe(t)?Q8:$8;return function(){var o=a(this,e),s=o.on;s!==r&&(i=(r=s).copy()).on(t,n),o.on=i}}function mJe(e,t){var n=this._id;return arguments.length<2?e5(this.node(),n).on.on(e):this.each(pJe(n,e,t))}function hJe(e){return function(){var t=this.parentNode;for(var n in this.__transition)if(+n!==e)return;t&&t.removeChild(this)}}function gJe(){return this.on(`end.remove`,hJe(this._id))}function _Je(e){var t=this._name,n=this._id;typeof e!=`function`&&(e=w6(e));for(var r=this._groups,i=r.length,a=Array(i),o=0;o<i;++o)for(var s=r[o],c=s.length,l=a[o]=Array(c),u,d,f=0;f<c;++f)(u=s[f])&&(d=e.call(u,u.__data__,f,s))&&(`__data__`in u&&(d.__data__=u.__data__),l[f]=d,Z8(l[f],t,n,f,l,e5(u,n)));return new r5(a,this._parents,t,n)}function vJe(e){var t=this._name,n=this._id;typeof e!=`function`&&(e=T6(e));for(var r=this._groups,i=r.length,a=[],o=[],s=0;s<i;++s)for(var c=r[s],l=c.length,u,d=0;d<l;++d)if(u=c[d]){for(var f=e.call(u,u.__data__,d,c),p,m=e5(u,n),h=0,g=f.length;h<g;++h)(p=f[h])&&Z8(p,t,n,h,f,m);a.push(f),o.push(u)}return new r5(a,o,t,n)}var yJe=B6.prototype.constructor;function bJe(){return new yJe(this._groups,this._parents)}function xJe(e,t){var n,r,i;return function(){var a=j6(this,e),o=(this.style.removeProperty(e),j6(this,e));return a===o?null:a===n&&o===r?i:i=t(n=a,r=o)}}function SJe(e){return function(){this.style.removeProperty(e)}}function CJe(e,t,n){var r,i=n+``,a;return function(){var o=j6(this,e);return o===i?null:o===r?a:a=t(r=o,n)}}function wJe(e,t,n){var r,i,a;return function(){var o=j6(this,e),s=n(this),c=s+``;return s??(c=s=(this.style.removeProperty(e),j6(this,e))),o===c?null:o===r&&c===i?a:(i=c,a=t(r=o,s))}}function TJe(e,t){var n,r,i,a=`style.`+t,o=`end.`+a,s;return function(){var c=$8(this,e),l=c.on,u=c.value[a]==null?s||=SJe(t):void 0;(l!==n||i!==u)&&(r=(n=l).copy()).on(o,i=u),c.on=r}}function EJe(e,t,n){var r=(e+=``)==`transform`?bqe:Vqe;return t==null?this.styleTween(e,xJe(e,r)).on(`end.style.`+e,SJe(e)):typeof t==`function`?this.styleTween(e,wJe(e,r,n5(this,`style.`+e,t))).each(TJe(this._id,e)):this.styleTween(e,CJe(e,r,t),n).on(`end.style.`+e,null)}function DJe(e,t,n){return function(r){this.style.setProperty(e,t.call(this,r),n)}}function OJe(e,t,n){var r,i;function a(){var a=t.apply(this,arguments);return a!==i&&(r=(i=a)&&DJe(e,a,n)),r}return a._value=t,a}function kJe(e,t,n){var r=`style.`+(e+=``);if(arguments.length<2)return(r=this.tween(r))&&r._value;if(t==null)return this.tween(r,null);if(typeof t!=`function`)throw Error();return this.tween(r,OJe(e,t,n??``))}function AJe(e){return function(){this.textContent=e}}function jJe(e){return function(){var t=e(this);this.textContent=t??``}}function MJe(e){return this.tween(`text`,typeof e==`function`?jJe(n5(this,`text`,e)):AJe(e==null?``:e+``))}function NJe(e){return function(t){this.textContent=e.call(this,t)}}function PJe(e){var t,n;function r(){var r=e.apply(this,arguments);return r!==n&&(t=(n=r)&&NJe(r)),t}return r._value=e,r}function FJe(e){var t=`text`;if(arguments.length<1)return(t=this.tween(t))&&t._value;if(e==null)return this.tween(t,null);if(typeof e!=`function`)throw Error();return this.tween(t,PJe(e))}function IJe(){for(var e=this._name,t=this._id,n=zJe(),r=this._groups,i=r.length,a=0;a<i;++a)for(var o=r[a],s=o.length,c,l=0;l<s;++l)if(c=o[l]){var u=e5(c,t);Z8(c,e,n,l,o,{time:u.time+u.delay+u.duration,delay:0,duration:u.duration,ease:u.ease})}return new r5(r,this._parents,e,n)}function LJe(){var e,t,n=this,r=n._id,i=n.size();return new Promise(function(a,o){var s={value:o},c={value:function(){--i===0&&a()}};n.each(function(){var n=$8(this,r),i=n.on;i!==e&&(t=(e=i).copy(),t._.cancel.push(s),t._.interrupt.push(s),t._.end.push(c)),n.on=t}),i===0&&a()})}var RJe=0;function r5(e,t,n,r){this._groups=e,this._parents=t,this._name=n,this._id=r}function zJe(){return++RJe}var i5=B6.prototype;r5.prototype={constructor:r5,select:_Je,selectAll:vJe,selectChild:i5.selectChild,selectChildren:i5.selectChildren,filter:uJe,merge:dJe,selection:bJe,transition:IJe,call:i5.call,nodes:i5.nodes,node:i5.node,size:i5.size,empty:i5.empty,each:i5.each,on:mJe,attr:Jqe,attrTween:$qe,style:EJe,styleTween:kJe,text:MJe,textTween:FJe,remove:gJe,tween:Bqe,delay:nJe,duration:aJe,ease:sJe,easeVarying:lJe,end:LJe,[Symbol.iterator]:i5[Symbol.iterator]};function BJe(e){return((e*=2)<=1?e*e*e:(e-=2)*e*e+2)/2}var VJe={time:null,delay:0,duration:250,ease:BJe};function HJe(e,t){for(var n;!(n=e.__transition)||!(n=n[t]);)if(!(e=e.parentNode))throw Error(`transition ${t} not found`);return n}function UJe(e){var t,n;e instanceof r5?(t=e._id,e=e._name):(t=zJe(),(n=VJe).time=J8(),e=e==null?null:e+``);for(var r=this._groups,i=r.length,a=0;a<i;++a)for(var o=r[a],s=o.length,c,l=0;l<s;++l)(c=o[l])&&Z8(c,e,t,l,o,n||HJe(c,t));return new r5(r,this._parents,e,t)}B6.prototype.interrupt=Lqe,B6.prototype.transition=UJe;var a5=e=>()=>e;function WJe(e,{sourceEvent:t,target:n,transform:r,dispatch:i}){Object.defineProperties(this,{type:{value:e,enumerable:!0,configurable:!0},sourceEvent:{value:t,enumerable:!0,configurable:!0},target:{value:n,enumerable:!0,configurable:!0},transform:{value:r,enumerable:!0,configurable:!0},_:{value:i}})}function o5(e,t,n){this.k=e,this.x=t,this.y=n}o5.prototype={constructor:o5,scale:function(e){return e===1?this:new o5(this.k*e,this.x,this.y)},translate:function(e,t){return e===0&t===0?this:new o5(this.k,this.x+this.k*e,this.y+this.k*t)},apply:function(e){return[e[0]*this.k+this.x,e[1]*this.k+this.y]},applyX:function(e){return e*this.k+this.x},applyY:function(e){return e*this.k+this.y},invert:function(e){return[(e[0]-this.x)/this.k,(e[1]-this.y)/this.k]},invertX:function(e){return(e-this.x)/this.k},invertY:function(e){return(e-this.y)/this.k},rescaleX:function(e){return e.copy().domain(e.range().map(this.invertX,this).map(e.invert,e))},rescaleY:function(e){return e.copy().domain(e.range().map(this.invertY,this).map(e.invert,e))},toString:function(){return`translate(`+this.x+`,`+this.y+`) scale(`+this.k+`)`}};var s5=new o5(1,0,0);GJe.prototype=o5.prototype;function GJe(e){for(;!e.__zoom;)if(!(e=e.parentNode))return s5;return e.__zoom}function c5(e){e.stopImmediatePropagation()}function l5(e){e.preventDefault(),e.stopImmediatePropagation()}function KJe(e){return(!e.ctrlKey||e.type===`wheel`)&&!e.button}function qJe(){var e=this;return e instanceof SVGElement?(e=e.ownerSVGElement||e,e.hasAttribute(`viewBox`)?(e=e.viewBox.baseVal,[[e.x,e.y],[e.x+e.width,e.y+e.height]]):[[0,0],[e.width.baseVal.value,e.height.baseVal.value]]):[[0,0],[e.clientWidth,e.clientHeight]]}function JJe(){return this.__zoom||s5}function YJe(e){return-e.deltaY*(e.deltaMode===1?.05:e.deltaMode?1:.002)*(e.ctrlKey?10:1)}function XJe(){return navigator.maxTouchPoints||`ontouchstart`in this}function ZJe(e,t,n){var r=e.invertX(t[0][0])-n[0][0],i=e.invertX(t[1][0])-n[1][0],a=e.invertY(t[0][1])-n[0][1],o=e.invertY(t[1][1])-n[1][1];return e.translate(i>r?(r+i)/2:Math.min(0,r)||Math.max(0,i),o>a?(a+o)/2:Math.min(0,a)||Math.max(0,o))}function QJe(){var e=KJe,t=qJe,n=ZJe,r=YJe,i=XJe,a=[0,1/0],o=[[-1/0,-1/0],[1/0,1/0]],s=250,c=R8,l=v6(`start`,`zoom`,`end`),u,d,f,p=500,m=150,h=0,g=10;function _(e){e.property(`__zoom`,JJe).on(`wheel.zoom`,w,{passive:!1}).on(`mousedown.zoom`,T).on(`dblclick.zoom`,E).filter(i).on(`touchstart.zoom`,D).on(`touchmove.zoom`,O).on(`touchend.zoom touchcancel.zoom`,k).style(`-webkit-tap-highlight-color`,`rgba(0,0,0,0)`)}_.transform=function(e,t,n,r){var i=e.selection?e.selection():e;i.property(`__zoom`,JJe),e===i?i.interrupt().each(function(){S(this,arguments).event(r).start().zoom(null,typeof t==`function`?t.apply(this,arguments):t).end()}):x(e,t,n,r)},_.scaleBy=function(e,t,n,r){_.scaleTo(e,function(){return this.__zoom.k*(typeof t==`function`?t.apply(this,arguments):t)},n,r)},_.scaleTo=function(e,r,i,a){_.transform(e,function(){var e=t.apply(this,arguments),a=this.__zoom,s=i==null?b(e):typeof i==`function`?i.apply(this,arguments):i,c=a.invert(s),l=typeof r==`function`?r.apply(this,arguments):r;return n(y(v(a,l),s,c),e,o)},i,a)},_.translateBy=function(e,r,i,a){_.transform(e,function(){return n(this.__zoom.translate(typeof r==`function`?r.apply(this,arguments):r,typeof i==`function`?i.apply(this,arguments):i),t.apply(this,arguments),o)},null,a)},_.translateTo=function(e,r,i,a,s){_.transform(e,function(){var e=t.apply(this,arguments),s=this.__zoom,c=a==null?b(e):typeof a==`function`?a.apply(this,arguments):a;return n(s5.translate(c[0],c[1]).scale(s.k).translate(typeof r==`function`?-r.apply(this,arguments):-r,typeof i==`function`?-i.apply(this,arguments):-i),e,o)},a,s)};function v(e,t){return t=Math.max(a[0],Math.min(a[1],t)),t===e.k?e:new o5(t,e.x,e.y)}function y(e,t,n){var r=t[0]-n[0]*e.k,i=t[1]-n[1]*e.k;return r===e.x&&i===e.y?e:new o5(e.k,r,i)}function b(e){return[(+e[0][0]+ +e[1][0])/2,(+e[0][1]+ +e[1][1])/2]}function x(e,n,r,i){e.on(`start.zoom`,function(){S(this,arguments).event(i).start()}).on(`interrupt.zoom end.zoom`,function(){S(this,arguments).event(i).end()}).tween(`zoom`,function(){var e=this,a=arguments,o=S(e,a).event(i),s=t.apply(e,a),l=r==null?b(s):typeof r==`function`?r.apply(e,a):r,u=Math.max(s[1][0]-s[0][0],s[1][1]-s[0][1]),d=e.__zoom,f=typeof n==`function`?n.apply(e,a):n,p=c(d.invert(l).concat(u/d.k),f.invert(l).concat(u/f.k));return function(e){if(e===1)e=f;else{var t=p(e),n=u/t[2];e=new o5(n,l[0]-t[0]*n,l[1]-t[1]*n)}o.zoom(null,e)}})}function S(e,t,n){return!n&&e.__zooming||new C(e,t)}function C(e,n){this.that=e,this.args=n,this.active=0,this.sourceEvent=null,this.extent=t.apply(e,n),this.taps=0}C.prototype={event:function(e){return e&&(this.sourceEvent=e),this},start:function(){return++this.active===1&&(this.that.__zooming=this,this.emit(`start`)),this},zoom:function(e,t){return this.mouse&&e!==`mouse`&&(this.mouse[1]=t.invert(this.mouse[0])),this.touch0&&e!==`touch`&&(this.touch0[1]=t.invert(this.touch0[0])),this.touch1&&e!==`touch`&&(this.touch1[1]=t.invert(this.touch1[0])),this.that.__zoom=t,this.emit(`zoom`),this},end:function(){return--this.active===0&&(delete this.that.__zooming,this.emit(`end`)),this},emit:function(e){var t=V6(this.that).datum();l.call(e,this.that,new WJe(e,{sourceEvent:this.sourceEvent,target:_,type:e,transform:this.that.__zoom,dispatch:l}),t)}};function w(t,...i){if(!e.apply(this,arguments))return;var s=S(this,i).event(t),c=this.__zoom,l=Math.max(a[0],Math.min(a[1],c.k*2**r.apply(this,arguments))),u=H6(t);if(s.wheel)(s.mouse[0][0]!==u[0]||s.mouse[0][1]!==u[1])&&(s.mouse[1]=c.invert(s.mouse[0]=u)),clearTimeout(s.wheel);else if(c.k===l)return;else s.mouse=[u,c.invert(u)],t5(this),s.start();l5(t),s.wheel=setTimeout(d,m),s.zoom(`mouse`,n(y(v(c,l),s.mouse[0],s.mouse[1]),s.extent,o));function d(){s.wheel=null,s.end()}}function T(t,...r){if(f||!e.apply(this,arguments))return;var i=t.currentTarget,a=S(this,r,!0).event(t),s=V6(t.view).on(`mousemove.zoom`,d,!0).on(`mouseup.zoom`,p,!0),c=H6(t,i),l=t.clientX,u=t.clientY;K6(t.view),c5(t),a.mouse=[c,this.__zoom.invert(c)],t5(this),a.start();function d(e){if(l5(e),!a.moved){var t=e.clientX-l,r=e.clientY-u;a.moved=t*t+r*r>h}a.event(e).zoom(`mouse`,n(y(a.that.__zoom,a.mouse[0]=H6(e,i),a.mouse[1]),a.extent,o))}function p(e){s.on(`mousemove.zoom mouseup.zoom`,null),q6(e.view,a.moved),l5(e),a.event(e).end()}}function E(r,...i){if(e.apply(this,arguments)){var a=this.__zoom,c=H6(r.changedTouches?r.changedTouches[0]:r,this),l=a.invert(c),u=a.k*(r.shiftKey?.5:2),d=n(y(v(a,u),c,l),t.apply(this,i),o);l5(r),s>0?V6(this).transition().duration(s).call(x,d,c,r):V6(this).call(_.transform,d,c,r)}}function D(t,...n){if(e.apply(this,arguments)){var r=t.touches,i=r.length,a=S(this,n,t.changedTouches.length===i).event(t),o,s,c,l;for(c5(t),s=0;s<i;++s)c=r[s],l=H6(c,this),l=[l,this.__zoom.invert(l),c.identifier],a.touch0?!a.touch1&&a.touch0[2]!==l[2]&&(a.touch1=l,a.taps=0):(a.touch0=l,o=!0,a.taps=1+!!u);u&&=clearTimeout(u),o&&(a.taps<2&&(d=l[0],u=setTimeout(function(){u=null},p)),t5(this),a.start())}}function O(e,...t){if(this.__zooming){var r=S(this,t).event(e),i=e.changedTouches,a=i.length,s,c,l,u;for(l5(e),s=0;s<a;++s)c=i[s],l=H6(c,this),r.touch0&&r.touch0[2]===c.identifier?r.touch0[0]=l:r.touch1&&r.touch1[2]===c.identifier&&(r.touch1[0]=l);if(c=r.that.__zoom,r.touch1){var d=r.touch0[0],f=r.touch0[1],p=r.touch1[0],m=r.touch1[1],h=(h=p[0]-d[0])*h+(h=p[1]-d[1])*h,g=(g=m[0]-f[0])*g+(g=m[1]-f[1])*g;c=v(c,Math.sqrt(h/g)),l=[(d[0]+p[0])/2,(d[1]+p[1])/2],u=[(f[0]+m[0])/2,(f[1]+m[1])/2]}else if(r.touch0)l=r.touch0[0],u=r.touch0[1];else return;r.zoom(`touch`,n(y(c,l,u),r.extent,o))}}function k(e,...t){if(this.__zooming){var n=S(this,t).event(e),r=e.changedTouches,i=r.length,a,o;for(c5(e),f&&clearTimeout(f),f=setTimeout(function(){f=null},p),a=0;a<i;++a)o=r[a],n.touch0&&n.touch0[2]===o.identifier?delete n.touch0:n.touch1&&n.touch1[2]===o.identifier&&delete n.touch1;if(n.touch1&&!n.touch0&&(n.touch0=n.touch1,delete n.touch1),n.touch0)n.touch0[1]=this.__zoom.invert(n.touch0[0]);else if(n.end(),n.taps===2&&(o=H6(o,this),Math.hypot(d[0]-o[0],d[1]-o[1])<g)){var s=V6(this).on(`dblclick.zoom`);s&&s.apply(this,arguments)}}}return _.wheelDelta=function(e){return arguments.length?(r=typeof e==`function`?e:a5(+e),_):r},_.filter=function(t){return arguments.length?(e=typeof t==`function`?t:a5(!!t),_):e},_.touchable=function(e){return arguments.length?(i=typeof e==`function`?e:a5(!!e),_):i},_.extent=function(e){return arguments.length?(t=typeof e==`function`?e:a5([[+e[0][0],+e[0][1]],[+e[1][0],+e[1][1]]]),_):t},_.scaleExtent=function(e){return arguments.length?(a[0]=+e[0],a[1]=+e[1],_):[a[0],a[1]]},_.translateExtent=function(e){return arguments.length?(o[0][0]=+e[0][0],o[1][0]=+e[1][0],o[0][1]=+e[0][1],o[1][1]=+e[1][1],_):[[o[0][0],o[0][1]],[o[1][0],o[1][1]]]},_.constrain=function(e){return arguments.length?(n=e,_):n},_.duration=function(e){return arguments.length?(s=+e,_):s},_.interpolate=function(e){return arguments.length?(c=e,_):c},_.on=function(){var e=l.on.apply(l,arguments);return e===l?_:e},_.clickDistance=function(e){return arguments.length?(h=(e=+e)*e,_):Math.sqrt(h)},_.tapDistance=function(e){return arguments.length?(g=+e,_):g},_}var u5={error001:()=>`[React Flow]: Seems like you have not used zustand provider as an ancestor. Help: https://reactflow.dev/error#001`,error002:()=>`It looks like you've created a new nodeTypes or edgeTypes object. If this wasn't on purpose please define the nodeTypes/edgeTypes outside of the component or memoize them.`,error003:e=>`Node type "${e}" not found. Using fallback type "default".`,error004:()=>`The React Flow parent container needs a width and a height to render the graph.`,error005:()=>`Only child nodes can use a parent extent.`,error006:()=>`Can't create edge. An edge needs a source and a target.`,error007:e=>`The old edge with id=${e} does not exist.`,error009:e=>`Marker type "${e}" doesn't exist.`,error008:(e,{id:t,sourceHandle:n,targetHandle:r})=>`Couldn't create edge for ${e} handle id: "${e===`source`?n:r}", edge id: ${t}.`,error010:()=>`Handle: No node id found. Make sure to only use a Handle inside a custom Node.`,error011:e=>`Edge type "${e}" not found. Using fallback type "default".`,error012:e=>`Node with id "${e}" does not exist, it may have been removed. This can happen when a node is deleted before the "onNodeClick" handler is called.`,error013:(e=`react`)=>`It seems that you haven't loaded the styles. Please import '@xyflow/${e}/dist/style.css' or base.css to make sure everything is working properly.`,error014:()=>`useNodeConnections: No node ID found. Call useNodeConnections inside a custom Node or provide a node ID.`,error015:()=>`It seems that you are trying to drag a node that is not initialized. Please use onNodesChange as explained in the docs.`},d5=[[-1/0,-1/0],[1/0,1/0]],$Je=[`Enter`,` `,`Escape`],eYe={"node.a11yDescription.default":`Press enter or space to select a node. Press delete to remove it and escape to cancel.`,"node.a11yDescription.keyboardDisabled":`Press enter or space to select a node. You can then use the arrow keys to move the node around. Press delete to remove it and escape to cancel.`,"node.a11yDescription.ariaLiveMessage":({direction:e,x:t,y:n})=>`Moved selected node ${e}. New position, x: ${t}, y: ${n}`,"edge.a11yDescription.default":`Press enter or space to select an edge. You can then press delete to remove it or escape to cancel.`,"controls.ariaLabel":`Control Panel`,"controls.zoomIn.ariaLabel":`Zoom In`,"controls.zoomOut.ariaLabel":`Zoom Out`,"controls.fitView.ariaLabel":`Fit View`,"controls.interactive.ariaLabel":`Toggle Interactivity`,"minimap.ariaLabel":`Mini Map`,"handle.ariaLabel":`Handle`},f5;(function(e){e.Strict=`strict`,e.Loose=`loose`})(f5||={});var p5;(function(e){e.Free=`free`,e.Vertical=`vertical`,e.Horizontal=`horizontal`})(p5||={});var m5;(function(e){e.Partial=`partial`,e.Full=`full`})(m5||={});var tYe={inProgress:!1,isValid:null,from:null,fromHandle:null,fromPosition:null,fromNode:null,to:null,toHandle:null,toPosition:null,toNode:null,pointer:null},h5;(function(e){e.Bezier=`default`,e.Straight=`straight`,e.Step=`step`,e.SmoothStep=`smoothstep`,e.SimpleBezier=`simplebezier`})(h5||={});var g5;(function(e){e.Arrow=`arrow`,e.ArrowClosed=`arrowclosed`})(g5||={});var _5;(function(e){e.Left=`left`,e.Top=`top`,e.Right=`right`,e.Bottom=`bottom`})(_5||={});var nYe={[_5.Left]:_5.Right,[_5.Right]:_5.Left,[_5.Top]:_5.Bottom,[_5.Bottom]:_5.Top};function rYe(e){return e===null?null:e?`valid`:`invalid`}var iYe=e=>`id`in e&&`source`in e&&`target`in e,aYe=e=>`id`in e&&`position`in e&&!(`source`in e)&&!(`target`in e),v5=e=>`id`in e&&`internals`in e&&!(`source`in e)&&!(`target`in e),y5=(e,t=[0,0])=>{let{width:n,height:r}=R5(e),i=e.origin??t,a=n*i[0],o=r*i[1];return{x:e.position.x-a,y:e.position.y-o}},oYe=(e,t={nodeOrigin:[0,0]})=>e.length===0?{x:0,y:0,width:0,height:0}:E5(e.reduce((e,n)=>{let r=typeof n==`string`,i=!t.nodeLookup&&!r?n:void 0;return t.nodeLookup&&(i=r?t.nodeLookup.get(n):v5(n)?n:t.nodeLookup.get(n.id)),w5(e,i?O5(i,t.nodeOrigin):{x:0,y:0,x2:0,y2:0})},{x:1/0,y:1/0,x2:-1/0,y2:-1/0})),b5=(e,t={})=>{let n={x:1/0,y:1/0,x2:-1/0,y2:-1/0},r=!1;return e.forEach(e=>{(t.filter===void 0||t.filter(e))&&(n=w5(n,O5(e)),r=!0)}),r?E5(n):{x:0,y:0,width:0,height:0}},x5=(e,t,[n,r,i]=[0,0,1],a=!1,o=!1)=>{let s={...M5(t,[n,r,i]),width:t.width/i,height:t.height/i},c=[];for(let t of e.values()){let{measured:e,selectable:n=!0,hidden:r=!1}=t;if(o&&!n||r)continue;let i=e.width??t.width??t.initialWidth??null,l=e.height??t.height??t.initialHeight??null,u=k5(s,D5(t)),d=(i??0)*(l??0),f=a&&u>0;(!t.internals.handleBounds||f||u>=d||t.dragging)&&c.push(t)}return c},sYe=(e,t)=>{let n=new Set;return e.forEach(e=>{n.add(e.id)}),t.filter(e=>n.has(e.source)||n.has(e.target))};function cYe(e,t){let n=new Map,r=t?.nodes?new Set(t.nodes.map(e=>e.id)):null;return e.forEach(e=>{e.measured.width&&e.measured.height&&(t?.includeHiddenNodes||!e.hidden)&&(!r||r.has(e.id))&&n.set(e.id,e)}),n}async function lYe({nodes:e,width:t,height:n,panZoom:r,minZoom:i,maxZoom:a},o){if(e.size===0)return Promise.resolve(!0);let s=F5(b5(cYe(e,o)),t,n,o?.minZoom??i,o?.maxZoom??a,o?.padding??.1);return await r.setViewport(s,{duration:o?.duration,ease:o?.ease,interpolate:o?.interpolate}),Promise.resolve(!0)}function uYe({nodeId:e,nextPosition:t,nodeLookup:n,nodeOrigin:r=[0,0],nodeExtent:i,onError:a}){let o=n.get(e),s=o.parentId?n.get(o.parentId):void 0,{x:c,y:l}=s?s.internals.positionAbsolute:{x:0,y:0},u=o.origin??r,d=o.extent||i;if(o.extent===`parent`&&!o.expandParent){if(!s)a?.(`005`,u5.error005());else{let e=s.measured.width,t=s.measured.height;e&&t&&(d=[[c,l],[c+e,l+t]])}}else s&&L5(o.extent)&&(d=[[o.extent[0][0]+c,o.extent[0][1]+l],[o.extent[1][0]+c,o.extent[1][1]+l]]);let f=L5(d)?C5(t,d,o.measured):t;return(o.measured.width===void 0||o.measured.height===void 0)&&a?.(`015`,u5.error015()),{position:{x:f.x-c+(o.measured.width??0)*u[0],y:f.y-l+(o.measured.height??0)*u[1]},positionAbsolute:f}}async function dYe({nodesToRemove:e=[],edgesToRemove:t=[],nodes:n,edges:r,onBeforeDelete:i}){let a=new Set(e.map(e=>e.id)),o=[];for(let e of n){if(e.deletable===!1)continue;let t=a.has(e.id),n=!t&&e.parentId&&o.find(t=>t.id===e.parentId);(t||n)&&o.push(e)}let s=new Set(t.map(e=>e.id)),c=r.filter(e=>e.deletable!==!1),l=sYe(o,c);for(let e of c)s.has(e.id)&&!l.find(t=>t.id===e.id)&&l.push(e);if(!i)return{edges:l,nodes:o};let u=await i({nodes:o,edges:l});return typeof u==`boolean`?u?{edges:l,nodes:o}:{edges:[],nodes:[]}:u}var S5=(e,t=0,n=1)=>Math.min(Math.max(e,t),n),C5=(e={x:0,y:0},t,n)=>({x:S5(e.x,t[0][0],t[1][0]-(n?.width??0)),y:S5(e.y,t[0][1],t[1][1]-(n?.height??0))});function fYe(e,t,n){let{width:r,height:i}=R5(n),{x:a,y:o}=n.internals.positionAbsolute;return C5(e,[[a,o],[a+r,o+i]],t)}var pYe=(e,t,n)=>e<t?S5(Math.abs(e-t),1,t)/t:e>n?-S5(Math.abs(e-n),1,t)/t:0,mYe=(e,t,n=15,r=40)=>[pYe(e.x,r,t.width-r)*n,pYe(e.y,r,t.height-r)*n],w5=(e,t)=>({x:Math.min(e.x,t.x),y:Math.min(e.y,t.y),x2:Math.max(e.x2,t.x2),y2:Math.max(e.y2,t.y2)}),T5=({x:e,y:t,width:n,height:r})=>({x:e,y:t,x2:e+n,y2:t+r}),E5=({x:e,y:t,x2:n,y2:r})=>({x:e,y:t,width:n-e,height:r-t}),D5=(e,t=[0,0])=>{let{x:n,y:r}=v5(e)?e.internals.positionAbsolute:y5(e,t);return{x:n,y:r,width:e.measured?.width??e.width??e.initialWidth??0,height:e.measured?.height??e.height??e.initialHeight??0}},O5=(e,t=[0,0])=>{let{x:n,y:r}=v5(e)?e.internals.positionAbsolute:y5(e,t);return{x:n,y:r,x2:n+(e.measured?.width??e.width??e.initialWidth??0),y2:r+(e.measured?.height??e.height??e.initialHeight??0)}},hYe=(e,t)=>E5(w5(T5(e),T5(t))),k5=(e,t)=>{let n=Math.max(0,Math.min(e.x+e.width,t.x+t.width)-Math.max(e.x,t.x)),r=Math.max(0,Math.min(e.y+e.height,t.y+t.height)-Math.max(e.y,t.y));return Math.ceil(n*r)},gYe=e=>A5(e.width)&&A5(e.height)&&A5(e.x)&&A5(e.y),A5=e=>!isNaN(e)&&isFinite(e),_Ye=(e,t)=>{},j5=(e,t=[1,1])=>({x:t[0]*Math.round(e.x/t[0]),y:t[1]*Math.round(e.y/t[1])}),M5=({x:e,y:t},[n,r,i],a=!1,o=[1,1])=>{let s={x:(e-n)/i,y:(t-r)/i};return a?j5(s,o):s},N5=({x:e,y:t},[n,r,i])=>({x:e*i+n,y:t*i+r});function P5(e,t){if(typeof e==`number`)return Math.floor((t-t/(1+e))*.5);if(typeof e==`string`&&e.endsWith(`px`)){let t=parseFloat(e);if(!Number.isNaN(t))return Math.floor(t)}if(typeof e==`string`&&e.endsWith(`%`)){let n=parseFloat(e);if(!Number.isNaN(n))return Math.floor(t*n*.01)}return console.error(`[React Flow] The padding value "${e}" is invalid. Please provide a number or a string with a valid unit (px or %).`),0}function vYe(e,t,n){if(typeof e==`string`||typeof e==`number`){let r=P5(e,n),i=P5(e,t);return{top:r,right:i,bottom:r,left:i,x:i*2,y:r*2}}if(typeof e==`object`){let r=P5(e.top??e.y??0,n),i=P5(e.bottom??e.y??0,n),a=P5(e.left??e.x??0,t),o=P5(e.right??e.x??0,t);return{top:r,right:o,bottom:i,left:a,x:a+o,y:r+i}}return{top:0,right:0,bottom:0,left:0,x:0,y:0}}function yYe(e,t,n,r,i,a){let{x:o,y:s}=N5(e,[t,n,r]),{x:c,y:l}=N5({x:e.x+e.width,y:e.y+e.height},[t,n,r]),u=i-c,d=a-l;return{left:Math.floor(o),top:Math.floor(s),right:Math.floor(u),bottom:Math.floor(d)}}var F5=(e,t,n,r,i,a)=>{let o=vYe(a,t,n),s=(t-o.x)/e.width,c=(n-o.y)/e.height,l=S5(Math.min(s,c),r,i),u=e.x+e.width/2,d=e.y+e.height/2,f=t/2-u*l,p=n/2-d*l,m=yYe(e,f,p,l,t,n),h={left:Math.min(m.left-o.left,0),top:Math.min(m.top-o.top,0),right:Math.min(m.right-o.right,0),bottom:Math.min(m.bottom-o.bottom,0)};return{x:f-h.left+h.right,y:p-h.top+h.bottom,zoom:l}},I5=()=>typeof navigator<`u`&&navigator?.userAgent?.indexOf(`Mac`)>=0;function L5(e){return e!=null&&e!==`parent`}function R5(e){return{width:e.measured?.width??e.width??e.initialWidth??0,height:e.measured?.height??e.height??e.initialHeight??0}}function bYe(e){return(e.measured?.width??e.width??e.initialWidth)!==void 0&&(e.measured?.height??e.height??e.initialHeight)!==void 0}function xYe(e,t={width:0,height:0},n,r,i){let a={...e},o=r.get(n);if(o){let e=o.origin||i;a.x+=o.internals.positionAbsolute.x-(t.width??0)*e[0],a.y+=o.internals.positionAbsolute.y-(t.height??0)*e[1]}return a}function SYe(e,t){if(e.size!==t.size)return!1;for(let n of e)if(!t.has(n))return!1;return!0}function CYe(){let e,t;return{promise:new Promise((n,r)=>{e=n,t=r}),resolve:e,reject:t}}function wYe(e){return{...eYe,...e||{}}}function z5(e,{snapGrid:t=[0,0],snapToGrid:n=!1,transform:r,containerBounds:i}){let{x:a,y:o}=V5(e),s=M5({x:a-(i?.left??0),y:o-(i?.top??0)},r),{x:c,y:l}=n?j5(s,t):s;return{xSnapped:c,ySnapped:l,...s}}var B5=e=>({width:e.offsetWidth,height:e.offsetHeight}),TYe=e=>e?.getRootNode?.()||window?.document,EYe=[`INPUT`,`SELECT`,`TEXTAREA`];function DYe(e){let t=e.composedPath?.()?.[0]||e.target;return t?.nodeType===1?EYe.includes(t.nodeName)||t.hasAttribute(`contenteditable`)||!!t.closest(`.nokey`):!1}var OYe=e=>`clientX`in e,V5=(e,t)=>{let n=OYe(e),r=n?e.clientX:e.touches?.[0].clientX,i=n?e.clientY:e.touches?.[0].clientY;return{x:r-(t?.left??0),y:i-(t?.top??0)}},kYe=(e,t,n,r,i)=>{let a=t.querySelectorAll(`.${e}`);return!a||!a.length?null:Array.from(a).map(t=>{let a=t.getBoundingClientRect();return{id:t.getAttribute(`data-handleid`),type:e,nodeId:i,position:t.getAttribute(`data-handlepos`),x:(a.left-n.left)/r,y:(a.top-n.top)/r,...B5(t)}})};function AYe({sourceX:e,sourceY:t,targetX:n,targetY:r,sourceControlX:i,sourceControlY:a,targetControlX:o,targetControlY:s}){let c=e*.125+i*.375+o*.375+n*.125,l=t*.125+a*.375+s*.375+r*.125;return[c,l,Math.abs(c-e),Math.abs(l-t)]}function H5(e,t){return e>=0?.5*e:t*25*Math.sqrt(-e)}function jYe({pos:e,x1:t,y1:n,x2:r,y2:i,c:a}){switch(e){case _5.Left:return[t-H5(t-r,a),n];case _5.Right:return[t+H5(r-t,a),n];case _5.Top:return[t,n-H5(n-i,a)];case _5.Bottom:return[t,n+H5(i-n,a)]}}function MYe({sourceX:e,sourceY:t,sourcePosition:n=_5.Bottom,targetX:r,targetY:i,targetPosition:a=_5.Top,curvature:o=.25}){let[s,c]=jYe({pos:n,x1:e,y1:t,x2:r,y2:i,c:o}),[l,u]=jYe({pos:a,x1:r,y1:i,x2:e,y2:t,c:o}),[d,f,p,m]=AYe({sourceX:e,sourceY:t,targetX:r,targetY:i,sourceControlX:s,sourceControlY:c,targetControlX:l,targetControlY:u});return[`M${e},${t} C${s},${c} ${l},${u} ${r},${i}`,d,f,p,m]}function NYe({sourceX:e,sourceY:t,targetX:n,targetY:r}){let i=Math.abs(n-e)/2,a=n<e?n+i:n-i,o=Math.abs(r-t)/2;return[a,r<t?r+o:r-o,i,o]}function PYe({sourceNode:e,targetNode:t,selected:n=!1,zIndex:r=0,elevateOnSelect:i=!1,zIndexMode:a=`basic`}){return a===`manual`?r:(i&&n?r+1e3:r)+Math.max(e.parentId||i&&e.selected?e.internals.z:0,t.parentId||i&&t.selected?t.internals.z:0)}function FYe({sourceNode:e,targetNode:t,width:n,height:r,transform:i}){let a=w5(O5(e),O5(t));return a.x===a.x2&&(a.x2+=1),a.y===a.y2&&(a.y2+=1),k5({x:-i[0]/i[2],y:-i[1]/i[2],width:n/i[2],height:r/i[2]},E5(a))>0}var IYe=({source:e,sourceHandle:t,target:n,targetHandle:r})=>`xy-edge__${e}${t||``}-${n}${r||``}`,LYe=(e,t)=>t.some(t=>t.source===e.source&&t.target===e.target&&(t.sourceHandle===e.sourceHandle||!t.sourceHandle&&!e.sourceHandle)&&(t.targetHandle===e.targetHandle||!t.targetHandle&&!e.targetHandle)),RYe=(e,t,n={})=>{if(!e.source||!e.target)return u5.error006(),t;let r=n.getEdgeId||IYe,i;return i=iYe(e)?{...e}:{...e,id:r(e)},LYe(i,t)?t:(i.sourceHandle===null&&delete i.sourceHandle,i.targetHandle===null&&delete i.targetHandle,t.concat(i))};function zYe({sourceX:e,sourceY:t,targetX:n,targetY:r}){let[i,a,o,s]=NYe({sourceX:e,sourceY:t,targetX:n,targetY:r});return[`M ${e},${t}L ${n},${r}`,i,a,o,s]}var BYe={[_5.Left]:{x:-1,y:0},[_5.Right]:{x:1,y:0},[_5.Top]:{x:0,y:-1},[_5.Bottom]:{x:0,y:1}},VYe=({source:e,sourcePosition:t=_5.Bottom,target:n})=>t===_5.Left||t===_5.Right?e.x<n.x?{x:1,y:0}:{x:-1,y:0}:e.y<n.y?{x:0,y:1}:{x:0,y:-1},HYe=(e,t)=>Math.sqrt((t.x-e.x)**2+(t.y-e.y)**2);function UYe({source:e,sourcePosition:t=_5.Bottom,target:n,targetPosition:r=_5.Top,center:i,offset:a,stepPosition:o}){let s=BYe[t],c=BYe[r],l={x:e.x+s.x*a,y:e.y+s.y*a},u={x:n.x+c.x*a,y:n.y+c.y*a},d=VYe({source:l,sourcePosition:t,target:u}),f=d.x===0?`y`:`x`,p=d[f],m=[],h,g,_={x:0,y:0},v={x:0,y:0},[,,y,b]=NYe({sourceX:e.x,sourceY:e.y,targetX:n.x,targetY:n.y});if(s[f]*c[f]===-1){f===`x`?(h=i.x??l.x+(u.x-l.x)*o,g=i.y??(l.y+u.y)/2):(h=i.x??(l.x+u.x)/2,g=i.y??l.y+(u.y-l.y)*o);let e=[{x:h,y:l.y},{x:h,y:u.y}],t=[{x:l.x,y:g},{x:u.x,y:g}];m=s[f]===p?f===`x`?e:t:f===`x`?t:e}else{let i=[{x:l.x,y:u.y}],o=[{x:u.x,y:l.y}];if(m=f===`x`?s.x===p?o:i:s.y===p?i:o,t===r){let t=Math.abs(e[f]-n[f]);if(t<=a){let r=Math.min(a-1,a-t);s[f]===p?_[f]=(l[f]>e[f]?-1:1)*r:v[f]=(u[f]>n[f]?-1:1)*r}}if(t!==r){let e=f===`x`?`y`:`x`,t=s[f]===c[e],n=l[e]>u[e],r=l[e]<u[e];(s[f]===1&&(!t&&n||t&&r)||s[f]!==1&&(!t&&r||t&&n))&&(m=f===`x`?i:o)}let d={x:l.x+_.x,y:l.y+_.y},y={x:u.x+v.x,y:u.y+v.y};Math.max(Math.abs(d.x-m[0].x),Math.abs(y.x-m[0].x))>=Math.max(Math.abs(d.y-m[0].y),Math.abs(y.y-m[0].y))?(h=(d.x+y.x)/2,g=m[0].y):(h=m[0].x,g=(d.y+y.y)/2)}let x={x:l.x+_.x,y:l.y+_.y},S={x:u.x+v.x,y:u.y+v.y};return[[e,...x.x!==m[0].x||x.y!==m[0].y?[x]:[],...m,...S.x!==m[m.length-1].x||S.y!==m[m.length-1].y?[S]:[],n],h,g,y,b]}function WYe(e,t,n,r){let i=Math.min(HYe(e,t)/2,HYe(t,n)/2,r),{x:a,y:o}=t;if(e.x===a&&a===n.x||e.y===o&&o===n.y)return`L${a} ${o}`;if(e.y===o){let t=e.x<n.x?-1:1,r=e.y<n.y?1:-1;return`L ${a+i*t},${o}Q ${a},${o} ${a},${o+i*r}`}let s=e.x<n.x?1:-1;return`L ${a},${o+i*(e.y<n.y?-1:1)}Q ${a},${o} ${a+i*s},${o}`}function U5({sourceX:e,sourceY:t,sourcePosition:n=_5.Bottom,targetX:r,targetY:i,targetPosition:a=_5.Top,borderRadius:o=5,centerX:s,centerY:c,offset:l=20,stepPosition:u=.5}){let[d,f,p,m,h]=UYe({source:{x:e,y:t},sourcePosition:n,target:{x:r,y:i},targetPosition:a,center:{x:s,y:c},offset:l,stepPosition:u}),g=`M${d[0].x} ${d[0].y}`;for(let e=1;e<d.length-1;e++)g+=WYe(d[e-1],d[e],d[e+1],o);return g+=`L${d[d.length-1].x} ${d[d.length-1].y}`,[g,f,p,m,h]}function GYe(e){return e&&!!(e.internals.handleBounds||e.handles?.length)&&!!(e.measured.width||e.width||e.initialWidth)}function KYe(e){let{sourceNode:t,targetNode:n}=e;if(!GYe(t)||!GYe(n))return null;let r=t.internals.handleBounds||qYe(t.handles),i=n.internals.handleBounds||qYe(n.handles),a=JYe(r?.source??[],e.sourceHandle),o=JYe(e.connectionMode===f5.Strict?i?.target??[]:(i?.target??[]).concat(i?.source??[]),e.targetHandle);if(!a||!o)return e.onError?.(`008`,u5.error008(a?`target`:`source`,{id:e.id,sourceHandle:e.sourceHandle,targetHandle:e.targetHandle})),null;let s=a?.position||_5.Bottom,c=o?.position||_5.Top,l=W5(t,a,s),u=W5(n,o,c);return{sourceX:l.x,sourceY:l.y,targetX:u.x,targetY:u.y,sourcePosition:s,targetPosition:c}}function qYe(e){if(!e)return null;let t=[],n=[];for(let r of e)r.width=r.width??1,r.height=r.height??1,r.type===`source`?t.push(r):r.type===`target`&&n.push(r);return{source:t,target:n}}function W5(e,t,n=_5.Left,r=!1){let i=(t?.x??0)+e.internals.positionAbsolute.x,a=(t?.y??0)+e.internals.positionAbsolute.y,{width:o,height:s}=t??R5(e);if(r)return{x:i+o/2,y:a+s/2};switch(t?.position??n){case _5.Top:return{x:i+o/2,y:a};case _5.Right:return{x:i+o,y:a+s/2};case _5.Bottom:return{x:i+o/2,y:a+s};case _5.Left:return{x:i,y:a+s/2}}}function JYe(e,t){return e&&(t?e.find(e=>e.id===t):e[0])||null}function G5(e,t){return e?typeof e==`string`?e:`${t?`${t}__`:``}${Object.keys(e).sort().map(t=>`${t}=${e[t]}`).join(`&`)}`:``}function YYe(e,{id:t,defaultColor:n,defaultMarkerStart:r,defaultMarkerEnd:i}){let a=new Set;return e.reduce((e,o)=>([o.markerStart||r,o.markerEnd||i].forEach(r=>{if(r&&typeof r==`object`){let i=G5(r,t);a.has(i)||(e.push({id:i,color:r.color||n,...r}),a.add(i))}}),e),[]).sort((e,t)=>e.id.localeCompare(t.id))}var XYe=1e3,ZYe=10,K5={nodeOrigin:[0,0],nodeExtent:d5,elevateNodesOnSelect:!0,zIndexMode:`basic`,defaults:{}},QYe={...K5,checkEquality:!0};function q5(e,t){let n={...e};for(let e in t)t[e]!==void 0&&(n[e]=t[e]);return n}function $Ye(e,t,n){let r=q5(K5,n);for(let n of e.values())if(n.parentId)X5(n,e,t,r);else{let e=C5(y5(n,r.nodeOrigin),L5(n.extent)?n.extent:r.nodeExtent,R5(n));n.internals.positionAbsolute=e}}function eXe(e,t){if(!e.handles)return e.measured?t?.internals.handleBounds:void 0;let n=[],r=[];for(let t of e.handles){let i={id:t.id,width:t.width??1,height:t.height??1,nodeId:e.id,x:t.x,y:t.y,position:t.position,type:t.type};t.type===`source`?n.push(i):t.type===`target`&&r.push(i)}return{source:n,target:r}}function J5(e){return e===`manual`}function Y5(e,t,n,r={}){let i=q5(QYe,r),a={i:0},o=new Map(t),s=i?.elevateNodesOnSelect&&!J5(i.zIndexMode)?XYe:0,c=e.length>0,l=!1;t.clear(),n.clear();for(let u of e){let e=o.get(u.id);if(i.checkEquality&&u===e?.internals.userNode)t.set(u.id,e);else{let n=C5(y5(u,i.nodeOrigin),L5(u.extent)?u.extent:i.nodeExtent,R5(u));e={...i.defaults,...u,measured:{width:u.measured?.width,height:u.measured?.height},internals:{positionAbsolute:n,handleBounds:eXe(u,e),z:nXe(u,s,i.zIndexMode),userNode:u}},t.set(u.id,e)}(e.measured===void 0||e.measured.width===void 0||e.measured.height===void 0)&&!e.hidden&&(c=!1),u.parentId&&X5(e,t,n,r,a),l||=u.selected??!1}return{nodesInitialized:c,hasSelectedNodes:l}}function tXe(e,t){if(!e.parentId)return;let n=t.get(e.parentId);n?n.set(e.id,e):t.set(e.parentId,new Map([[e.id,e]]))}function X5(e,t,n,r,i){let{elevateNodesOnSelect:a,nodeOrigin:o,nodeExtent:s,zIndexMode:c}=q5(K5,r),l=e.parentId,u=t.get(l);if(!u){console.warn(`Parent node ${l} not found. Please make sure that parent nodes are in front of their child nodes in the nodes array.`);return}tXe(e,n),i&&!u.parentId&&u.internals.rootParentIndex===void 0&&c===`auto`&&(u.internals.rootParentIndex=++i.i,u.internals.z=u.internals.z+i.i*ZYe),i&&u.internals.rootParentIndex!==void 0&&(i.i=u.internals.rootParentIndex);let{x:d,y:f,z:p}=rXe(e,u,o,s,a&&!J5(c)?XYe:0,c),{positionAbsolute:m}=e.internals,h=d!==m.x||f!==m.y;(h||p!==e.internals.z)&&t.set(e.id,{...e,internals:{...e.internals,positionAbsolute:h?{x:d,y:f}:m,z:p}})}function nXe(e,t,n){let r=A5(e.zIndex)?e.zIndex:0;return J5(n)?r:r+(e.selected?t:0)}function rXe(e,t,n,r,i,a){let{x:o,y:s}=t.internals.positionAbsolute,c=R5(e),l=y5(e,n),u=L5(e.extent)?C5(l,e.extent,c):l,d=C5({x:o+u.x,y:s+u.y},r,c);e.extent===`parent`&&(d=fYe(d,c,t));let f=nXe(e,i,a),p=t.internals.z??0;return{x:d.x,y:d.y,z:p>=f?p+1:f}}function Z5(e,t,n,r=[0,0]){let i=[],a=new Map;for(let n of e){let e=t.get(n.parentId);if(!e)continue;let r=hYe(a.get(n.parentId)?.expandedRect??D5(e),n.rect);a.set(n.parentId,{expandedRect:r,parent:e})}return a.size>0&&a.forEach(({expandedRect:t,parent:a},o)=>{let s=a.internals.positionAbsolute,c=R5(a),l=a.origin??r,u=t.x<s.x?Math.round(Math.abs(s.x-t.x)):0,d=t.y<s.y?Math.round(Math.abs(s.y-t.y)):0,f=Math.max(c.width,Math.round(t.width)),p=Math.max(c.height,Math.round(t.height)),m=(f-c.width)*l[0],h=(p-c.height)*l[1];(u>0||d>0||m||h)&&(i.push({id:o,type:`position`,position:{x:a.position.x-u+m,y:a.position.y-d+h}}),n.get(o)?.forEach(t=>{e.some(e=>e.id===t.id)||i.push({id:t.id,type:`position`,position:{x:t.position.x+u,y:t.position.y+d}})})),(c.width<t.width||c.height<t.height||u||d)&&i.push({id:o,type:`dimensions`,setAttributes:!0,dimensions:{width:f+(u?l[0]*u-m:0),height:p+(d?l[1]*d-h:0)}})}),i}function iXe(e,t,n,r,i,a,o){let s=r?.querySelector(`.xyflow__viewport`),c=!1;if(!s)return{changes:[],updatedInternals:c};let l=[],u=window.getComputedStyle(s),{m22:d}=new window.DOMMatrixReadOnly(u.transform),f=[];for(let r of e.values()){let e=t.get(r.id);if(!e)continue;if(e.hidden){t.set(e.id,{...e,internals:{...e.internals,handleBounds:void 0}}),c=!0;continue}let s=B5(r.nodeElement),u=e.measured.width!==s.width||e.measured.height!==s.height;if(s.width&&s.height&&(u||!e.internals.handleBounds||r.force)){let p=r.nodeElement.getBoundingClientRect(),m=L5(e.extent)?e.extent:a,{positionAbsolute:h}=e.internals;e.parentId&&e.extent===`parent`?h=fYe(h,s,t.get(e.parentId)):m&&(h=C5(h,m,s));let g={...e,measured:s,internals:{...e.internals,positionAbsolute:h,handleBounds:{source:kYe(`source`,r.nodeElement,p,d,e.id),target:kYe(`target`,r.nodeElement,p,d,e.id)}}};t.set(e.id,g),e.parentId&&X5(g,t,n,{nodeOrigin:i,zIndexMode:o}),c=!0,u&&(l.push({id:e.id,type:`dimensions`,dimensions:s}),e.expandParent&&e.parentId&&f.push({id:e.id,parentId:e.parentId,rect:D5(g,i)}))}}if(f.length>0){let e=Z5(f,t,n,i);l.push(...e)}return{changes:l,updatedInternals:c}}async function aXe({delta:e,panZoom:t,transform:n,translateExtent:r,width:i,height:a}){if(!t||!e.x&&!e.y)return Promise.resolve(!1);let o=await t.setViewportConstrained({x:n[0]+e.x,y:n[1]+e.y,zoom:n[2]},[[0,0],[i,a]],r),s=!!o&&(o.x!==n[0]||o.y!==n[1]||o.k!==n[2]);return Promise.resolve(s)}function oXe(e,t,n,r,i,a){let o=i,s=r.get(o)||new Map;r.set(o,s.set(n,t)),o=`${i}-${e}`;let c=r.get(o)||new Map;if(r.set(o,c.set(n,t)),a){o=`${i}-${e}-${a}`;let s=r.get(o)||new Map;r.set(o,s.set(n,t))}}function sXe(e,t,n){e.clear(),t.clear();for(let r of n){let{source:n,target:i,sourceHandle:a=null,targetHandle:o=null}=r,s={edgeId:r.id,source:n,target:i,sourceHandle:a,targetHandle:o},c=`${n}-${a}--${i}-${o}`;oXe(`source`,s,`${i}-${o}--${n}-${a}`,e,n,a),oXe(`target`,s,c,e,i,o),t.set(r.id,r)}}function cXe(e,t){if(!e.parentId)return!1;let n=t.get(e.parentId);return n?n.selected?!0:cXe(n,t):!1}function lXe(e,t,n){let r=e;do{if(r?.matches?.(t))return!0;if(r===n)return!1;r=r?.parentElement}while(r);return!1}function uXe(e,t,n,r){let i=new Map;for(let[a,o]of e)if((o.selected||o.id===r)&&(!o.parentId||!cXe(o,e))&&(o.draggable||t&&o.draggable===void 0)){let t=e.get(a);t&&i.set(a,{id:a,position:t.position||{x:0,y:0},distance:{x:n.x-t.internals.positionAbsolute.x,y:n.y-t.internals.positionAbsolute.y},extent:t.extent,parentId:t.parentId,origin:t.origin,expandParent:t.expandParent,internals:{positionAbsolute:t.internals.positionAbsolute||{x:0,y:0}},measured:{width:t.measured.width??0,height:t.measured.height??0}})}return i}function Q5({nodeId:e,dragItems:t,nodeLookup:n,dragging:r=!0}){let i=[];for(let[e,a]of t){let t=n.get(e)?.internals.userNode;t&&i.push({...t,position:a.position,dragging:r})}if(!e)return[i[0],i];let a=n.get(e)?.internals.userNode;return[a?{...a,position:t.get(e)?.position||a.position,dragging:r}:i[0],i]}function dXe({dragItems:e,snapGrid:t,x:n,y:r}){let i=e.values().next().value;if(!i)return null;let a={x:n-i.distance.x,y:r-i.distance.y},o=j5(a,t);return{x:o.x-a.x,y:o.y-a.y}}function fXe({onNodeMouseDown:e,getStoreItems:t,onDragStart:n,onDrag:r,onDragStop:i}){let a={x:null,y:null},o=0,s=new Map,c=!1,l={x:0,y:0},u=null,d=!1,f=null,p=!1,m=!1,h=null;function g({noDragClassName:g,handleSelector:_,domNode:v,isSelectable:y,nodeId:b,nodeClickDistance:x=0}){f=V6(v);function S({x:e,y:n}){let{nodeLookup:i,nodeExtent:o,snapGrid:c,snapToGrid:l,nodeOrigin:u,onNodeDrag:d,onSelectionDrag:f,onError:p,updateNodePositions:g}=t();a={x:e,y:n};let _=!1,v=s.size>1,y=v&&o?T5(b5(s)):null,x=v&&l?dXe({dragItems:s,snapGrid:c,x:e,y:n}):null;for(let[t,r]of s){if(!i.has(t))continue;let a={x:e-r.distance.x,y:n-r.distance.y};l&&(a=x?{x:Math.round(a.x+x.x),y:Math.round(a.y+x.y)}:j5(a,c));let s=null;if(v&&o&&!r.extent&&y){let{positionAbsolute:e}=r.internals,t=e.x-y.x+o[0][0],n=e.x+r.measured.width-y.x2+o[1][0],i=e.y-y.y+o[0][1],a=e.y+r.measured.height-y.y2+o[1][1];s=[[t,i],[n,a]]}let{position:d,positionAbsolute:f}=uYe({nodeId:t,nextPosition:a,nodeLookup:i,nodeExtent:s||o,nodeOrigin:u,onError:p});_=_||r.position.x!==d.x||r.position.y!==d.y,r.position=d,r.internals.positionAbsolute=f}if(m||=_,_&&(g(s,!0),h&&(r||d||!b&&f))){let[e,t]=Q5({nodeId:b,dragItems:s,nodeLookup:i});r?.(h,s,e,t),d?.(h,e,t),b||f?.(h,t)}}async function C(){if(!u)return;let{transform:e,panBy:n,autoPanSpeed:r,autoPanOnNodeDrag:i}=t();if(!i){c=!1,cancelAnimationFrame(o);return}let[s,d]=mYe(l,u,r);(s!==0||d!==0)&&(a.x=(a.x??0)-s/e[2],a.y=(a.y??0)-d/e[2],await n({x:s,y:d})&&S(a)),o=requestAnimationFrame(C)}function w(r){let{nodeLookup:i,multiSelectionActive:o,nodesDraggable:c,transform:l,snapGrid:f,snapToGrid:p,selectNodesOnDrag:m,onNodeDragStart:h,onSelectionDragStart:g,unselectNodesAndEdges:_}=t();d=!0,(!m||!y)&&!o&&b&&(i.get(b)?.selected||_()),y&&m&&b&&e?.(b);let v=z5(r.sourceEvent,{transform:l,snapGrid:f,snapToGrid:p,containerBounds:u});if(a=v,s=uXe(i,c,v,b),s.size>0&&(n||h||!b&&g)){let[e,t]=Q5({nodeId:b,dragItems:s,nodeLookup:i});n?.(r.sourceEvent,s,e,t),h?.(r.sourceEvent,e,t),b||g?.(r.sourceEvent,t)}}let T=X6().clickDistance(x).on(`start`,e=>{let{domNode:n,nodeDragThreshold:r,transform:i,snapGrid:o,snapToGrid:s}=t();u=n?.getBoundingClientRect()||null,p=!1,m=!1,h=e.sourceEvent,r===0&&w(e),a=z5(e.sourceEvent,{transform:i,snapGrid:o,snapToGrid:s,containerBounds:u}),l=V5(e.sourceEvent,u)}).on(`drag`,e=>{let{autoPanOnNodeDrag:n,transform:r,snapGrid:i,snapToGrid:o,nodeDragThreshold:f,nodeLookup:m}=t(),g=z5(e.sourceEvent,{transform:r,snapGrid:i,snapToGrid:o,containerBounds:u});if(h=e.sourceEvent,(e.sourceEvent.type===`touchmove`&&e.sourceEvent.touches.length>1||b&&!m.has(b))&&(p=!0),!p){if(!c&&n&&d&&(c=!0,C()),!d){let t=V5(e.sourceEvent,u),n=t.x-l.x,r=t.y-l.y;Math.sqrt(n*n+r*r)>f&&w(e)}(a.x!==g.xSnapped||a.y!==g.ySnapped)&&s&&d&&(l=V5(e.sourceEvent,u),S(g))}}).on(`end`,e=>{if(!(!d||p)&&(c=!1,d=!1,cancelAnimationFrame(o),s.size>0)){let{nodeLookup:n,updateNodePositions:r,onNodeDragStop:a,onSelectionDragStop:o}=t();if(m&&=(r(s,!1),!1),i||a||!b&&o){let[t,r]=Q5({nodeId:b,dragItems:s,nodeLookup:n,dragging:!1});i?.(e.sourceEvent,s,t,r),a?.(e.sourceEvent,t,r),b||o?.(e.sourceEvent,r)}}}).filter(e=>{let t=e.target;return!e.button&&(!g||!lXe(t,`.${g}`,v))&&(!_||lXe(t,_,v))});f.call(T)}function _(){f?.on(`.drag`,null)}return{update:g,destroy:_}}function pXe(e,t,n){let r=[],i={x:e.x-n,y:e.y-n,width:n*2,height:n*2};for(let e of t.values())k5(i,D5(e))>0&&r.push(e);return r}var mXe=250;function hXe(e,t,n,r){let i=[],a=1/0,o=pXe(e,n,t+mXe);for(let n of o){let o=[...n.internals.handleBounds?.source??[],...n.internals.handleBounds?.target??[]];for(let s of o){if(r.nodeId===s.nodeId&&r.type===s.type&&r.id===s.id)continue;let{x:o,y:c}=W5(n,s,s.position,!0),l=Math.sqrt((o-e.x)**2+(c-e.y)**2);l>t||(l<a?(i=[{...s,x:o,y:c}],a=l):l===a&&i.push({...s,x:o,y:c}))}}if(!i.length)return null;if(i.length>1){let e=r.type===`source`?`target`:`source`;return i.find(t=>t.type===e)??i[0]}return i[0]}function gXe(e,t,n,r,i,a=!1){let o=r.get(e);if(!o)return null;let s=i===`strict`?o.internals.handleBounds?.[t]:[...o.internals.handleBounds?.source??[],...o.internals.handleBounds?.target??[]],c=(n?s?.find(e=>e.id===n):s?.[0])??null;return c&&a?{...c,...W5(o,c,c.position,!0)}:c}function _Xe(e,t){return e||(t?.classList.contains(`target`)?`target`:t?.classList.contains(`source`)?`source`:null)}function vXe(e,t){let n=null;return t?n=!0:e&&!t&&(n=!1),n}var yXe=()=>!0;function bXe(e,{connectionMode:t,connectionRadius:n,handleId:r,nodeId:i,edgeUpdaterType:a,isTarget:o,domNode:s,nodeLookup:c,lib:l,autoPanOnConnect:u,flowId:d,panBy:f,cancelConnection:p,onConnectStart:m,onConnect:h,onConnectEnd:g,isValidConnection:_=yXe,onReconnectEnd:v,updateConnection:y,getTransform:b,getFromHandle:x,autoPanSpeed:S,dragThreshold:C=1,handleDomNode:w}){let T=TYe(e.target),E=0,D,{x:O,y:k}=V5(e),A=_Xe(a,w),j=s?.getBoundingClientRect(),M=!1;if(!j||!A)return;let N=gXe(i,A,r,c,t);if(!N)return;let P=V5(e,j),F=!1,I=null,L=!1,R=null;function z(){if(!u||!j)return;let[e,t]=mYe(P,j,S);f({x:e,y:t}),E=requestAnimationFrame(z)}let ee={...N,nodeId:i,type:A,position:N.position},te=c.get(i),ne={inProgress:!0,isValid:null,from:W5(te,ee,_5.Left,!0),fromHandle:ee,fromPosition:ee.position,fromNode:te,to:P,toHandle:null,toPosition:nYe[ee.position],toNode:null,pointer:P};function re(){M=!0,y(ne),m?.(e,{nodeId:i,handleId:r,handleType:A})}C===0&&re();function ie(e){if(!M){let{x:t,y:n}=V5(e),r=t-O,i=n-k;if(!(r*r+i*i>C*C))return;re()}if(!x()||!ee){B(e);return}let a=b();P=V5(e,j),D=hXe(M5(P,a,!1,[1,1]),n,c,ee),F||=(z(),!0);let s=xXe(e,{handle:D,connectionMode:t,fromNodeId:i,fromHandleId:r,fromType:o?`target`:`source`,isValidConnection:_,doc:T,lib:l,flowId:d,nodeLookup:c});R=s.handleDomNode,I=s.connection,L=vXe(!!D,s.isValid);let u=c.get(i),f=u?W5(u,ee,_5.Left,!0):ne.from,p={...ne,from:f,isValid:L,to:s.toHandle&&L?N5({x:s.toHandle.x,y:s.toHandle.y},a):P,toHandle:s.toHandle,toPosition:L&&s.toHandle?s.toHandle.position:nYe[ee.position],toNode:s.toHandle?c.get(s.toHandle.nodeId):null,pointer:P};y(p),ne=p}function B(e){if(!(`touches`in e&&e.touches.length>0)){if(M){(D||R)&&I&&L&&h?.(I);let{inProgress:t,...n}=ne,r={...n,toPosition:ne.toHandle?ne.toPosition:null};g?.(e,r),a&&v?.(e,r)}p(),cancelAnimationFrame(E),F=!1,L=!1,I=null,R=null,T.removeEventListener(`mousemove`,ie),T.removeEventListener(`mouseup`,B),T.removeEventListener(`touchmove`,ie),T.removeEventListener(`touchend`,B)}}T.addEventListener(`mousemove`,ie),T.addEventListener(`mouseup`,B),T.addEventListener(`touchmove`,ie),T.addEventListener(`touchend`,B)}function xXe(e,{handle:t,connectionMode:n,fromNodeId:r,fromHandleId:i,fromType:a,doc:o,lib:s,flowId:c,isValidConnection:l=yXe,nodeLookup:u}){let d=a===`target`,f=t?o.querySelector(`.${s}-flow__handle[data-id="${c}-${t?.nodeId}-${t?.id}-${t?.type}"]`):null,{x:p,y:m}=V5(e),h=o.elementFromPoint(p,m),g=h?.classList.contains(`${s}-flow__handle`)?h:f,_={handleDomNode:g,isValid:!1,connection:null,toHandle:null};if(g){let e=_Xe(void 0,g),t=g.getAttribute(`data-nodeid`),a=g.getAttribute(`data-handleid`),o=g.classList.contains(`connectable`),s=g.classList.contains(`connectableend`);if(!t||!e)return _;let c={source:d?t:r,sourceHandle:d?a:i,target:d?r:t,targetHandle:d?i:a};_.connection=c,_.isValid=o&&s&&(n===f5.Strict?d&&e===`source`||!d&&e===`target`:t!==r||a!==i)&&l(c),_.toHandle=gXe(t,e,a,u,n,!0)}return _}var $5={onPointerDown:bXe,isValid:xXe};function SXe({domNode:e,panZoom:t,getTransform:n,getViewScale:r}){let i=V6(e);function a({translateExtent:e,width:a,height:o,zoomStep:s=1,pannable:c=!0,zoomable:l=!0,inversePan:u=!1}){let d=e=>{if(e.sourceEvent.type!==`wheel`||!t)return;let r=n(),i=e.sourceEvent.ctrlKey&&I5()?10:1,a=-e.sourceEvent.deltaY*(e.sourceEvent.deltaMode===1?.05:e.sourceEvent.deltaMode?1:.002)*s,o=r[2]*2**(a*i);t.scaleTo(o)},f=[0,0],p=QJe().on(`start`,e=>{(e.sourceEvent.type===`mousedown`||e.sourceEvent.type===`touchstart`)&&(f=[e.sourceEvent.clientX??e.sourceEvent.touches[0].clientX,e.sourceEvent.clientY??e.sourceEvent.touches[0].clientY])}).on(`zoom`,c?i=>{let s=n();if(i.sourceEvent.type!==`mousemove`&&i.sourceEvent.type!==`touchmove`||!t)return;let c=[i.sourceEvent.clientX??i.sourceEvent.touches[0].clientX,i.sourceEvent.clientY??i.sourceEvent.touches[0].clientY],l=[c[0]-f[0],c[1]-f[1]];f=c;let d=r()*Math.max(s[2],Math.log(s[2]))*(u?-1:1),p={x:s[0]-l[0]*d,y:s[1]-l[1]*d},m=[[0,0],[a,o]];t.setViewportConstrained({x:p.x,y:p.y,zoom:s[2]},m,e)}:null).on(`zoom.wheel`,l?d:null);i.call(p,{})}function o(){i.on(`zoom`,null)}return{update:a,destroy:o,pointer:H6}}var e7=e=>({x:e.x,y:e.y,zoom:e.k}),t7=({x:e,y:t,zoom:n})=>s5.translate(e,t).scale(n),n7=(e,t)=>e.target.closest(`.${t}`),CXe=(e,t)=>t===2&&Array.isArray(e)&&e.includes(2),wXe=e=>((e*=2)<=1?e*e*e:(e-=2)*e*e+2)/2,r7=(e,t=0,n=wXe,r=()=>{})=>{let i=typeof t==`number`&&t>0;return i||r(),i?e.transition().duration(t).ease(n).on(`end`,r):e},TXe=e=>{let t=e.ctrlKey&&I5()?10:1;return-e.deltaY*(e.deltaMode===1?.05:e.deltaMode?1:.002)*t};function EXe({zoomPanValues:e,noWheelClassName:t,d3Selection:n,d3Zoom:r,panOnScrollMode:i,panOnScrollSpeed:a,zoomOnPinch:o,onPanZoomStart:s,onPanZoom:c,onPanZoomEnd:l}){return u=>{if(n7(u,t))return u.ctrlKey&&u.preventDefault(),!1;u.preventDefault(),u.stopImmediatePropagation();let d=n.property(`__zoom`).k||1;if(u.ctrlKey&&o){let e=H6(u),t=d*2**TXe(u);r.scaleTo(n,t,e,u);return}let f=u.deltaMode===1?20:1,p=i===p5.Vertical?0:u.deltaX*f,m=i===p5.Horizontal?0:u.deltaY*f;!I5()&&u.shiftKey&&i!==p5.Vertical&&(p=u.deltaY*f,m=0),r.translateBy(n,-(p/d)*a,-(m/d)*a,{internal:!0});let h=e7(n.property(`__zoom`));clearTimeout(e.panScrollTimeout),e.isPanScrolling?(c?.(u,h),e.panScrollTimeout=setTimeout(()=>{l?.(u,h),e.isPanScrolling=!1},150)):(e.isPanScrolling=!0,s?.(u,h))}}function DXe({noWheelClassName:e,preventScrolling:t,d3ZoomHandler:n}){return function(r,i){let a=r.type===`wheel`,o=!t&&a&&!r.ctrlKey,s=n7(r,e);if(r.ctrlKey&&a&&s&&r.preventDefault(),o||s)return null;r.preventDefault(),n.call(this,r,i)}}function OXe({zoomPanValues:e,onDraggingChange:t,onPanZoomStart:n}){return r=>{if(r.sourceEvent?.internal)return;let i=e7(r.transform);e.mouseButton=r.sourceEvent?.button||0,e.isZoomingOrPanning=!0,e.prevViewport=i,r.sourceEvent?.type===`mousedown`&&t(!0),n&&n?.(r.sourceEvent,i)}}function kXe({zoomPanValues:e,panOnDrag:t,onPaneContextMenu:n,onTransformChange:r,onPanZoom:i}){return a=>{e.usedRightMouseButton=!!(n&&CXe(t,e.mouseButton??0)),a.sourceEvent?.sync||r([a.transform.x,a.transform.y,a.transform.k]),i&&!a.sourceEvent?.internal&&i?.(a.sourceEvent,e7(a.transform))}}function AXe({zoomPanValues:e,panOnDrag:t,panOnScroll:n,onDraggingChange:r,onPanZoomEnd:i,onPaneContextMenu:a}){return o=>{if(!o.sourceEvent?.internal&&(e.isZoomingOrPanning=!1,a&&CXe(t,e.mouseButton??0)&&!e.usedRightMouseButton&&o.sourceEvent&&a(o.sourceEvent),e.usedRightMouseButton=!1,r(!1),i)){let t=e7(o.transform);e.prevViewport=t,clearTimeout(e.timerId),e.timerId=setTimeout(()=>{i?.(o.sourceEvent,t)},n?150:0)}}}function jXe({zoomActivationKeyPressed:e,zoomOnScroll:t,zoomOnPinch:n,panOnDrag:r,panOnScroll:i,zoomOnDoubleClick:a,userSelectionActive:o,noWheelClassName:s,noPanClassName:c,lib:l,connectionInProgress:u}){return d=>{let f=e||t,p=n&&d.ctrlKey,m=d.type===`wheel`;if(d.button===1&&d.type===`mousedown`&&(n7(d,`${l}-flow__node`)||n7(d,`${l}-flow__edge`)))return!0;if(!r&&!f&&!i&&!a&&!n||o||u&&!m||n7(d,s)&&m||n7(d,c)&&(!m||i&&m&&!e)||!n&&d.ctrlKey&&m)return!1;if(!n&&d.type===`touchstart`&&d.touches?.length>1)return d.preventDefault(),!1;if(!f&&!i&&!p&&m||!r&&(d.type===`mousedown`||d.type===`touchstart`)||Array.isArray(r)&&!r.includes(d.button)&&d.type===`mousedown`)return!1;let h=Array.isArray(r)&&r.includes(d.button)||!d.button||d.button<=1;return(!d.ctrlKey||m)&&h}}function MXe({domNode:e,minZoom:t,maxZoom:n,translateExtent:r,viewport:i,onPanZoom:a,onPanZoomStart:o,onPanZoomEnd:s,onDraggingChange:c}){let l={isZoomingOrPanning:!1,usedRightMouseButton:!1,prevViewport:{x:0,y:0,zoom:0},mouseButton:0,timerId:void 0,panScrollTimeout:void 0,isPanScrolling:!1},u=e.getBoundingClientRect(),d=QJe().scaleExtent([t,n]).translateExtent(r),f=V6(e).call(d);v({x:i.x,y:i.y,zoom:S5(i.zoom,t,n)},[[0,0],[u.width,u.height]],r);let p=f.on(`wheel.zoom`),m=f.on(`dblclick.zoom`);d.wheelDelta(TXe);function h(e,t){return f?new Promise(n=>{d?.interpolate(t?.interpolate===`linear`?j8:R8).transform(r7(f,t?.duration,t?.ease,()=>n(!0)),e)}):Promise.resolve(!1)}function g({noWheelClassName:e,noPanClassName:t,onPaneContextMenu:n,userSelectionActive:r,panOnScroll:i,panOnDrag:u,panOnScrollMode:h,panOnScrollSpeed:g,preventScrolling:v,zoomOnPinch:y,zoomOnScroll:b,zoomOnDoubleClick:x,zoomActivationKeyPressed:S,lib:C,onTransformChange:w,connectionInProgress:T,paneClickDistance:E,selectionOnDrag:D}){r&&!l.isZoomingOrPanning&&_();let O=i&&!S&&!r;d.clickDistance(D?1/0:!A5(E)||E<0?0:E);let k=O?EXe({zoomPanValues:l,noWheelClassName:e,d3Selection:f,d3Zoom:d,panOnScrollMode:h,panOnScrollSpeed:g,zoomOnPinch:y,onPanZoomStart:o,onPanZoom:a,onPanZoomEnd:s}):DXe({noWheelClassName:e,preventScrolling:v,d3ZoomHandler:p});if(f.on(`wheel.zoom`,k,{passive:!1}),!r){let e=OXe({zoomPanValues:l,onDraggingChange:c,onPanZoomStart:o});d.on(`start`,e);let t=kXe({zoomPanValues:l,panOnDrag:u,onPaneContextMenu:!!n,onPanZoom:a,onTransformChange:w});d.on(`zoom`,t);let r=AXe({zoomPanValues:l,panOnDrag:u,panOnScroll:i,onPaneContextMenu:n,onPanZoomEnd:s,onDraggingChange:c});d.on(`end`,r)}let A=jXe({zoomActivationKeyPressed:S,panOnDrag:u,zoomOnScroll:b,panOnScroll:i,zoomOnDoubleClick:x,zoomOnPinch:y,userSelectionActive:r,noPanClassName:t,noWheelClassName:e,lib:C,connectionInProgress:T});d.filter(A),x?f.on(`dblclick.zoom`,m):f.on(`dblclick.zoom`,null)}function _(){d.on(`zoom`,null)}async function v(e,t,n){let r=t7(e),i=d?.constrain()(r,t,n);return i&&await h(i),new Promise(e=>e(i))}async function y(e,t){let n=t7(e);return await h(n,t),new Promise(e=>e(n))}function b(e){if(f){let t=t7(e),n=f.property(`__zoom`);(n.k!==e.zoom||n.x!==e.x||n.y!==e.y)&&d?.transform(f,t,null,{sync:!0})}}function x(){let e=f?GJe(f.node()):{x:0,y:0,k:1};return{x:e.x,y:e.y,zoom:e.k}}function S(e,t){return f?new Promise(n=>{d?.interpolate(t?.interpolate===`linear`?j8:R8).scaleTo(r7(f,t?.duration,t?.ease,()=>n(!0)),e)}):Promise.resolve(!1)}function C(e,t){return f?new Promise(n=>{d?.interpolate(t?.interpolate===`linear`?j8:R8).scaleBy(r7(f,t?.duration,t?.ease,()=>n(!0)),e)}):Promise.resolve(!1)}function w(e){d?.scaleExtent(e)}function T(e){d?.translateExtent(e)}function E(e){let t=!A5(e)||e<0?0:e;d?.clickDistance(t)}return{update:g,destroy:_,setViewport:y,setViewportConstrained:v,getViewport:x,scaleTo:S,scaleBy:C,setScaleExtent:w,setTranslateExtent:T,syncViewport:b,setClickDistance:E}}var i7;(function(e){e.Line=`line`,e.Handle=`handle`})(i7||={});function NXe({width:e,prevWidth:t,height:n,prevHeight:r,affectsX:i,affectsY:a}){let o=e-t,s=n-r,c=[o>0?1:o<0?-1:0,s>0?1:s<0?-1:0];return o&&i&&(c[0]*=-1),s&&a&&(c[1]*=-1),c}function PXe(e){return{isHorizontal:e.includes(`right`)||e.includes(`left`),isVertical:e.includes(`bottom`)||e.includes(`top`),affectsX:e.includes(`left`),affectsY:e.includes(`top`)}}function a7(e,t){return Math.max(0,t-e)}function o7(e,t){return Math.max(0,e-t)}function s7(e,t,n){return Math.max(0,t-e,e-n)}function FXe(e,t){return e?!t:t}function IXe(e,t,n,r,i,a,o,s){let{affectsX:c,affectsY:l}=t,{isHorizontal:u,isVertical:d}=t,f=u&&d,{xSnapped:p,ySnapped:m}=n,{minWidth:h,maxWidth:g,minHeight:_,maxHeight:v}=r,{x:y,y:b,width:x,height:S,aspectRatio:C}=e,w=Math.floor(u?p-e.pointerX:0),T=Math.floor(d?m-e.pointerY:0),E=x+(c?-w:w),D=S+(l?-T:T),O=-a[0]*x,k=-a[1]*S,A=s7(E,h,g),j=s7(D,_,v);if(o){let e=0,t=0;c&&w<0?e=a7(y+w+O,o[0][0]):!c&&w>0&&(e=o7(y+E+O,o[1][0])),l&&T<0?t=a7(b+T+k,o[0][1]):!l&&T>0&&(t=o7(b+D+k,o[1][1])),A=Math.max(A,e),j=Math.max(j,t)}if(s){let e=0,t=0;c&&w>0?e=o7(y+w,s[0][0]):!c&&w<0&&(e=a7(y+E,s[1][0])),l&&T>0?t=o7(b+T,s[0][1]):!l&&T<0&&(t=a7(b+D,s[1][1])),A=Math.max(A,e),j=Math.max(j,t)}if(i){if(u){let e=s7(E/C,_,v)*C;if(A=Math.max(A,e),o){let e=0;e=!c&&!l||c&&!l&&f?o7(b+k+E/C,o[1][1])*C:a7(b+k+(c?w:-w)/C,o[0][1])*C,A=Math.max(A,e)}if(s){let e=0;e=!c&&!l||c&&!l&&f?a7(b+E/C,s[1][1])*C:o7(b+(c?w:-w)/C,s[0][1])*C,A=Math.max(A,e)}}if(d){let e=s7(D*C,h,g)/C;if(j=Math.max(j,e),o){let e=0;e=!c&&!l||l&&!c&&f?o7(y+D*C+O,o[1][0])/C:a7(y+(l?T:-T)*C+O,o[0][0])/C,j=Math.max(j,e)}if(s){let e=0;e=!c&&!l||l&&!c&&f?a7(y+D*C,s[1][0])/C:o7(y+(l?T:-T)*C,s[0][0])/C,j=Math.max(j,e)}}}T+=T<0?j:-j,w+=w<0?A:-A,i&&(f?E>D*C?T=(FXe(c,l)?-w:w)/C:w=(FXe(c,l)?-T:T)*C:u?(T=w/C,l=c):(w=T*C,c=l));let M=c?y+w:y,N=l?b+T:b;return{width:x+(c?-w:w),height:S+(l?-T:T),x:a[0]*w*(c?-1:1)+M,y:a[1]*T*(l?-1:1)+N}}var LXe={width:0,height:0,x:0,y:0},RXe={...LXe,pointerX:0,pointerY:0,aspectRatio:1};function zXe(e){return[[0,0],[e.measured.width,e.measured.height]]}function BXe(e,t,n){let r=t.position.x+e.position.x,i=t.position.y+e.position.y,a=e.measured.width??0,o=e.measured.height??0,s=n[0]*a,c=n[1]*o;return[[r-s,i-c],[r+a-s,i+o-c]]}function VXe({domNode:e,nodeId:t,getStoreItems:n,onChange:r,onEnd:i}){let a=V6(e),o={controlDirection:PXe(`bottom-right`),boundaries:{minWidth:0,minHeight:0,maxWidth:Number.MAX_VALUE,maxHeight:Number.MAX_VALUE},resizeDirection:void 0,keepAspectRatio:!1};function s({controlPosition:e,boundaries:s,keepAspectRatio:c,resizeDirection:l,onResizeStart:u,onResize:d,onResizeEnd:f,shouldResize:p}){let m={...LXe},h={...RXe};o={boundaries:s,resizeDirection:l,keepAspectRatio:c,controlDirection:PXe(e)};let g,_=null,v=[],y,b,x,S=!1,C=X6().on(`start`,e=>{let{nodeLookup:r,transform:i,snapGrid:a,snapToGrid:o,nodeOrigin:s,paneDomNode:c}=n();if(g=r.get(t),!g)return;_=c?.getBoundingClientRect()??null;let{xSnapped:l,ySnapped:d}=z5(e.sourceEvent,{transform:i,snapGrid:a,snapToGrid:o,containerBounds:_});m={width:g.measured.width??0,height:g.measured.height??0,x:g.position.x??0,y:g.position.y??0},h={...m,pointerX:l,pointerY:d,aspectRatio:m.width/m.height},y=void 0,g.parentId&&(g.extent===`parent`||g.expandParent)&&(y=r.get(g.parentId),b=y&&g.extent===`parent`?zXe(y):void 0),v=[],x=void 0;for(let[e,n]of r)if(n.parentId===t&&(v.push({id:e,position:{...n.position},extent:n.extent}),n.extent===`parent`||n.expandParent)){let e=BXe(n,g,n.origin??s);x=x?[[Math.min(e[0][0],x[0][0]),Math.min(e[0][1],x[0][1])],[Math.max(e[1][0],x[1][0]),Math.max(e[1][1],x[1][1])]]:e}u?.(e,{...m})}).on(`drag`,e=>{let{transform:t,snapGrid:i,snapToGrid:a,nodeOrigin:s}=n(),c=z5(e.sourceEvent,{transform:t,snapGrid:i,snapToGrid:a,containerBounds:_}),l=[];if(!g)return;let{x:u,y:f,width:C,height:w}=m,T={},E=g.origin??s,{width:D,height:O,x:k,y:A}=IXe(h,o.controlDirection,c,o.boundaries,o.keepAspectRatio,E,b,x),j=D!==C,M=O!==w,N=k!==u&&j,P=A!==f&&M;if(!N&&!P&&!j&&!M)return;if((N||P||E[0]===1||E[1]===1)&&(T.x=N?k:m.x,T.y=P?A:m.y,m.x=T.x,m.y=T.y,v.length>0)){let e=k-u,t=A-f;for(let n of v)n.position={x:n.position.x-e+E[0]*(D-C),y:n.position.y-t+E[1]*(O-w)},l.push(n)}if((j||M)&&(T.width=j&&(!o.resizeDirection||o.resizeDirection===`horizontal`)?D:m.width,T.height=M&&(!o.resizeDirection||o.resizeDirection===`vertical`)?O:m.height,m.width=T.width,m.height=T.height),y&&g.expandParent){let e=E[0]*(T.width??0);T.x&&T.x<e&&(m.x=e,h.x-=T.x-e);let t=E[1]*(T.height??0);T.y&&T.y<t&&(m.y=t,h.y-=T.y-t)}let F=NXe({width:m.width,prevWidth:C,height:m.height,prevHeight:w,affectsX:o.controlDirection.affectsX,affectsY:o.controlDirection.affectsY}),I={...m,direction:F};p?.(e,I)!==!1&&(S=!0,d?.(e,I),r(T,l))}).on(`end`,e=>{S&&=(f?.(e,{...m}),i?.({...m}),!1)});a.call(C)}function c(){a.on(`.drag`,null)}return{update:s,destroy:c}}var HXe=e=>{let t,n=new Set,r=(e,r)=>{let i=typeof e==`function`?e(t):e;if(!Object.is(i,t)){let e=t;t=r??(typeof i!=`object`||!i)?i:Object.assign({},t,i),n.forEach(n=>n(t,e))}},i=()=>t,a={setState:r,getState:i,getInitialState:()=>o,subscribe:e=>(n.add(e),()=>n.delete(e)),destroy:()=>{n.clear()}},o=t=e(r,i,a);return a},UXe=e=>e?HXe(e):HXe,{useDebugValue:WXe}=H.default,{useSyncExternalStoreWithSelector:GXe}=xo.default,KXe=e=>e;function qXe(e,t=KXe,n){let r=GXe(e.subscribe,e.getState,e.getServerState||e.getInitialState,t,n);return WXe(r),r}var JXe=(e,t)=>{let n=UXe(e),r=(e,r=t)=>qXe(n,e,r);return Object.assign(r,n),r},YXe=(e,t)=>e?JXe(e,t):JXe;function c7(e,t){if(Object.is(e,t))return!0;if(typeof e!=`object`||!e||typeof t!=`object`||!t)return!1;if(e instanceof Map&&t instanceof Map){if(e.size!==t.size)return!1;for(let[n,r]of e)if(!Object.is(r,t.get(n)))return!1;return!0}if(e instanceof Set&&t instanceof Set){if(e.size!==t.size)return!1;for(let n of e)if(!t.has(n))return!1;return!0}let n=Object.keys(e);if(n.length!==Object.keys(t).length)return!1;for(let r of n)if(!Object.prototype.hasOwnProperty.call(t,r)||!Object.is(e[r],t[r]))return!1;return!0}var l7=(0,H.createContext)(null),XXe=l7.Provider,ZXe=u5.error001();function u7(e,t){let n=(0,H.useContext)(l7);if(n===null)throw Error(ZXe);return qXe(n,e,t)}function d7(){let e=(0,H.useContext)(l7);if(e===null)throw Error(ZXe);return(0,H.useMemo)(()=>({getState:e.getState,setState:e.setState,subscribe:e.subscribe}),[e])}var QXe={display:`none`},$Xe={position:`absolute`,width:1,height:1,margin:-1,border:0,padding:0,overflow:`hidden`,clip:`rect(0px, 0px, 0px, 0px)`,clipPath:`inset(100%)`},eZe=`react-flow__node-desc`,tZe=`react-flow__edge-desc`,nZe=`react-flow__aria-live`,rZe=e=>e.ariaLiveMessage,iZe=e=>e.ariaLabelConfig;function aZe({rfId:e}){let t=u7(rZe);return(0,U.jsx)(`div`,{id:`${nZe}-${e}`,"aria-live":`assertive`,"aria-atomic":`true`,style:$Xe,children:t})}function oZe({rfId:e,disableKeyboardA11y:t}){let n=u7(iZe);return(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(`div`,{id:`${eZe}-${e}`,style:QXe,children:t?n[`node.a11yDescription.default`]:n[`node.a11yDescription.keyboardDisabled`]}),(0,U.jsx)(`div`,{id:`${tZe}-${e}`,style:QXe,children:n[`edge.a11yDescription.default`]}),!t&&(0,U.jsx)(aZe,{rfId:e})]})}var f7=(0,H.forwardRef)(({position:e=`top-left`,children:t,className:n,style:r,...i},a)=>{let o=`${e}`.split(`-`);return(0,U.jsx)(`div`,{className:_6([`react-flow__panel`,n,...o]),style:r,ref:a,...i,children:t})});f7.displayName=`Panel`;function sZe({proOptions:e,position:t=`bottom-right`}){return e?.hideAttribution?null:(0,U.jsx)(f7,{position:t,className:`react-flow__attribution`,"data-message":`Please only hide this attribution when you are subscribed to React Flow Pro: https://pro.reactflow.dev`,children:(0,U.jsx)(`a`,{href:`https://reactflow.dev`,target:`_blank`,rel:`noopener noreferrer`,"aria-label":`React Flow attribution`,children:`React Flow`})})}var cZe=e=>{let t=[],n=[];for(let[,n]of e.nodeLookup)n.selected&&t.push(n.internals.userNode);for(let[,t]of e.edgeLookup)t.selected&&n.push(t);return{selectedNodes:t,selectedEdges:n}},p7=e=>e.id;function lZe(e,t){return c7(e.selectedNodes.map(p7),t.selectedNodes.map(p7))&&c7(e.selectedEdges.map(p7),t.selectedEdges.map(p7))}function uZe({onSelectionChange:e}){let t=d7(),{selectedNodes:n,selectedEdges:r}=u7(cZe,lZe);return(0,H.useEffect)(()=>{let i={nodes:n,edges:r};e?.(i),t.getState().onSelectionChangeHandlers.forEach(e=>e(i))},[n,r,e]),null}var dZe=e=>!!e.onSelectionChangeHandlers;function fZe({onSelectionChange:e}){let t=u7(dZe);return e||t?(0,U.jsx)(uZe,{onSelectionChange:e}):null}var m7=typeof window<`u`?H.useLayoutEffect:H.useEffect,pZe=[0,0],mZe={x:0,y:0,zoom:1},hZe=[...`nodes.edges.defaultNodes.defaultEdges.onConnect.onConnectStart.onConnectEnd.onClickConnectStart.onClickConnectEnd.nodesDraggable.autoPanOnNodeFocus.nodesConnectable.nodesFocusable.edgesFocusable.edgesReconnectable.elevateNodesOnSelect.elevateEdgesOnSelect.minZoom.maxZoom.nodeExtent.onNodesChange.onEdgesChange.elementsSelectable.connectionMode.snapGrid.snapToGrid.translateExtent.connectOnClick.defaultEdgeOptions.fitView.fitViewOptions.onNodesDelete.onEdgesDelete.onDelete.onNodeDrag.onNodeDragStart.onNodeDragStop.onSelectionDrag.onSelectionDragStart.onSelectionDragStop.onMoveStart.onMove.onMoveEnd.noPanClassName.nodeOrigin.autoPanOnConnect.autoPanOnNodeDrag.onError.connectionRadius.isValidConnection.selectNodesOnDrag.nodeDragThreshold.connectionDragThreshold.onBeforeDelete.debug.autoPanSpeed.ariaLabelConfig.zIndexMode`.split(`.`),`rfId`],gZe=e=>({setNodes:e.setNodes,setEdges:e.setEdges,setMinZoom:e.setMinZoom,setMaxZoom:e.setMaxZoom,setTranslateExtent:e.setTranslateExtent,setNodeExtent:e.setNodeExtent,reset:e.reset,setDefaultNodesAndEdges:e.setDefaultNodesAndEdges}),_Ze={translateExtent:d5,nodeOrigin:pZe,minZoom:.5,maxZoom:2,elementsSelectable:!0,noPanClassName:`nopan`,rfId:`1`};function vZe(e){let{setNodes:t,setEdges:n,setMinZoom:r,setMaxZoom:i,setTranslateExtent:a,setNodeExtent:o,reset:s,setDefaultNodesAndEdges:c}=u7(gZe,c7),l=d7();m7(()=>(c(e.defaultNodes,e.defaultEdges),()=>{u.current=_Ze,s()}),[]);let u=(0,H.useRef)(_Ze);return m7(()=>{for(let s of hZe){let c=e[s];c!==u.current[s]&&e[s]!==void 0&&(s===`nodes`?t(c):s===`edges`?n(c):s===`minZoom`?r(c):s===`maxZoom`?i(c):s===`translateExtent`?a(c):s===`nodeExtent`?o(c):s===`ariaLabelConfig`?l.setState({ariaLabelConfig:wYe(c)}):s===`fitView`?l.setState({fitViewQueued:c}):s===`fitViewOptions`?l.setState({fitViewOptions:c}):l.setState({[s]:c}))}u.current=e},hZe.map(t=>e[t])),null}function yZe(){return typeof window>`u`||!window.matchMedia?null:window.matchMedia(`(prefers-color-scheme: dark)`)}function bZe(e){let[t,n]=(0,H.useState)(e===`system`?null:e);return(0,H.useEffect)(()=>{if(e!==`system`){n(e);return}let t=yZe(),r=()=>n(t?.matches?`dark`:`light`);return r(),t?.addEventListener(`change`,r),()=>{t?.removeEventListener(`change`,r)}},[e]),t===null?yZe()?.matches?`dark`:`light`:t}var xZe=typeof document<`u`?document:null;function h7(e=null,t={target:xZe,actInsideInputWithModifier:!0}){let[n,r]=(0,H.useState)(!1),i=(0,H.useRef)(!1),a=(0,H.useRef)(new Set([])),[o,s]=(0,H.useMemo)(()=>{if(e!==null){let t=(Array.isArray(e)?e:[e]).filter(e=>typeof e==`string`).map(e=>e.replace(`+`,`
212
+ `).trim();if(!t.startsWith(`{`)&&!t.startsWith(`[`))continue;let n=l4(t);if(n!==void 0)return c4(n,r.slice(0,e).join(` `).trim()||void 0)}}function c4(e,t){let n=$2(e);if(n.kind===`text`){let e=s4(n.text);return e?.kind===`json`?{...e,meta:e.meta??t}:{kind:`text`,text:n.text}}return{kind:`json`,value:e,meta:t}}function l4(e){if(!(!e.startsWith(`{`)&&!e.startsWith(`[`)))try{let t=JSON.parse(e);return typeof t==`object`&&t?t:void 0}catch{return}}function u4(e){return!!e&&typeof e==`object`&&!Array.isArray(e)}function EVe({name:e,input:t}){return(0,U.jsxs)(`span`,{className:`compact-terminal-function-call`,children:[(0,U.jsx)(`span`,{className:`text-[#facc15] font-semibold`,children:e}),(0,U.jsx)(`span`,{className:`text-[#d4d4d4]`,children:`(`}),t===void 0?null:(0,U.jsx)(DVe,{value:t}),(0,U.jsx)(`span`,{className:`text-[#d4d4d4]`,children:`)`})]})}function DVe({value:e}){let[t,n]=(0,H.useState)(()=>new Set([`$`])),[r,i]=(0,H.useState)(()=>new Set);return(0,U.jsx)(d4,{value:e,path:`$`,expandedPaths:t,expandedStrings:r,onTogglePath:e=>{n(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},onToggleString:e=>{i(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}})}function d4({value:e,path:t,expandedPaths:n,expandedStrings:r,onTogglePath:i,onToggleString:a}){if(Array.isArray(e))return(0,U.jsx)(f4,{value:e,path:t,open:`[`,close:`]`,expandedPaths:n,expandedStrings:r,onTogglePath:i,onToggleString:a});if(AVe(e))return(0,U.jsx)(f4,{value:e,path:t,open:`{`,close:`}`,expandedPaths:n,expandedStrings:r,onTogglePath:i,onToggleString:a});if(typeof e==`string`){let n=r.has(t),i=e.length>140&&!n,o=i?`${e.slice(0,140)}...`:e,s=(0,U.jsx)(`span`,{className:`text-[#fb923c]`,children:JSON.stringify(o)});return!i&&e.length<=140?s:(0,U.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),a(t)},className:`compact-terminal-json-toggle text-left align-baseline`,title:n?`Collapse string`:`Expand string`,"aria-label":`String at ${OVe(t)}`,"aria-expanded":n,children:s})}return typeof e==`number`||typeof e==`boolean`||e===null?(0,U.jsx)(`span`,{className:`text-[#60a5fa]`,children:String(e)}):(0,U.jsx)(`span`,{className:`text-[#737373]`,children:JSON.stringify(String(e))})}function f4({value:e,path:t,open:n,close:r,expandedPaths:i,expandedStrings:a,onTogglePath:o,onToggleString:s}){let c=i.has(t),l=`inline-json-${(0,H.useId)()}`,u=c?Array.isArray(e)?e.map((e,t)=>[String(t),e]):Object.entries(e):[];return(0,U.jsxs)(`span`,{children:[(0,U.jsxs)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),o(t)},className:`compact-terminal-json-toggle align-baseline text-[#737373]`,title:c?`Collapse JSON`:`Expand JSON`,"aria-label":`JSON at ${t}`,"aria-expanded":c,"aria-controls":l,"data-inline-json-path":t,children:[(0,U.jsx)(`span`,{className:`compact-terminal-json-caret`,children:c?`▾`:`▸`}),n,c?null:`...${r}`]}),(0,U.jsxs)(`span`,{id:l,children:[u.map(([n,r],c)=>{let l=`${t}.${kVe(n)}`;return(0,U.jsxs)(`span`,{children:[c>0?(0,U.jsx)(`span`,{className:`text-[#737373]`,children:`, `}):null,Array.isArray(e)?null:(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(`span`,{className:`text-[#d4d4d4]`,children:JSON.stringify(n)}),(0,U.jsx)(`span`,{className:`text-[#737373]`,children:`:`})]}),(0,U.jsx)(d4,{value:r,path:l,expandedPaths:i,expandedStrings:a,onTogglePath:o,onToggleString:s})]},l)}),c?(0,U.jsx)(`span`,{className:`text-[#737373]`,children:r}):null]})]})}function OVe(e){let t=e.replace(/[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}/gi,`[id]`);return t.length<=80?t:`${t.slice(0,39)}…${t.slice(-39)}`}function kVe(e){return e.replaceAll(`\\`,`\\\\`).replaceAll(`.`,`\\.`)}function AVe(e){return!!e&&typeof e==`object`&&!Array.isArray(e)}var jVe=120;function MVe({line:e,status:t,clampLines:n}){let r=`min-w-0 whitespace-pre-wrap break-words ${n?`block overflow-hidden`:``}`,i=FVe(e.tokens),a=i.length>jVe&&!i.some(e=>e.href);return(0,U.jsxs)(`div`,{className:`grid grid-cols-[1.9rem_minmax(0,1fr)] gap-2 leading-[1.45]`,children:[(0,U.jsx)(`span`,{className:`whitespace-pre ${PVe(e.prefix,t)}`,children:NVe(e.prefix)}),(0,U.jsxs)(`span`,{className:r,style:n?{maxHeight:`${n*1.45}em`}:void 0,children:[a?(0,U.jsx)(`span`,{className:`text-[#d4d4d4]`,children:i.map(e=>e.text).join(``)}):i.map((e,t)=>e.href?(0,U.jsx)(`a`,{href:e.href,target:`_blank`,rel:`noreferrer noopener`,"aria-label":e.ariaLabel,className:`${p4(e)} underline decoration-[#60a5fa]/40 underline-offset-2 hover:decoration-[#60a5fa] focus:outline-none focus:ring-1 focus:ring-[#38bdf8]`,children:e.text},`${t}:${e.href}:${e.text}`):(0,U.jsx)(`span`,{className:p4(e),children:e.text},`${t}:${e.text}`)),e.functionCall?(0,U.jsx)(EVe,{name:e.functionCall.name,input:e.functionCall.input}):null]})]})}function NVe(e=`none`){switch(e){case`bullet`:return`•`;case`detail`:return`└`;case`continuation`:return` `;case`prompt`:return`›`;default:return` `}}function PVe(e=`none`,t){if(e===`bullet`){if(t===`running`)return`text-[#38bdf8]`;if(t===`error`)return`text-[#ef4444]`;if(t===`done`)return`text-[#22c55e]`}return`text-[#737373]`}function p4(e){return`${e.tone===`dim`?`text-[#737373]`:e.tone===`cyan`?`text-[#38bdf8]`:e.tone===`green`?`text-[#22c55e]`:e.tone===`red`?`text-[#ef4444]`:e.tone===`magenta`?`text-[#d946ef]`:e.tone===`yellow`?`text-[#facc15]`:e.tone===`blue`?`text-[#60a5fa]`:e.tone===`amber`?`text-[#f59e0b]`:`text-[#d4d4d4]`} ${e.weight===`bold`?`font-bold`:e.weight===`semibold`?`font-semibold`:`font-normal`} ${e.italic?`italic`:``}`.trim()}function FVe(e){let t=[];for(let n of e){if(!n.text)continue;let e=t.at(-1);if(e&&e.tone===n.tone&&e.weight===n.weight&&e.italic===n.italic&&e.href===n.href&&e.ariaLabel===n.ariaLabel){e.text+=n.text;continue}t.push({...n})}return t}async function IVe(){return await G(`/api/chat/provider-auth`)}async function m4(e){return(await G(`/api/chat/provider-auth`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify(e)})).result}function LVe(e){if(typeof e!=`object`||!e||Array.isArray(e))return!1;let t=e;return t.action===`show_login_menu`&&Array.isArray(t.providers)}function RVe(e){if(typeof e!=`object`||!e||Array.isArray(e))return!1;let t=e;return t.action===`show_model_menu`&&Array.isArray(t.providers)}function h4(e){return zVe(e)?e.result:e}function zVe(e){return!!e&&typeof e==`object`&&!Array.isArray(e)&&e.type===`execution_result`}var BVe={device_code:`Device code`,browser_oauth:`Browser OAuth`,api_key:`API key`};function VVe({row:e,piboSessionId:t}){let n=LVe(e.output)?e.output:void 0,r=(0,H.useMemo)(()=>n?.providers??[],[n?.providers]),[i,a]=(0,H.useState)({type:`select_provider`}),[o,s]=(0,H.useState)(!1),[c,l]=(0,H.useState)(``),[u,d]=(0,H.useState)(``),[f,p]=(0,H.useState)(null),m=(0,H.useRef)(!1),h=(0,H.useCallback)(()=>{a({type:`select_provider`}),l(``),d(``)},[]),g=(0,H.useCallback)(async e=>{try{await navigator.clipboard.writeText(e),p(e),window.setTimeout(()=>p(t=>t===e?null:t),1600)}catch{}},[]),_=(0,H.useCallback)(async(e,n)=>{if(!t){a({type:`error`,provider:e,message:`Select a chat session before starting login.`});return}s(!0),a({type:`device_starting`,provider:e});try{let r=h4(await Yl(t,`login.start`,{provider:e.id,method:n})),i=r?.url??r?.flow?.verificationUrl;if(!i){a({type:`error`,provider:e,message:`No login URL returned.`});return}a({type:`device_flow`,provider:e,url:i,flowId:r.flowId??r.state??r.flow?.flowId,completion:r.flow?.completion,userCode:r.userCode??r.flow?.userCode,instructions:r.instructions??r.flow?.instructions})}catch(t){a({type:`error`,provider:e,message:t instanceof Error?t.message:String(t)})}finally{s(!1)}},[t]),v=(0,H.useCallback)(async(e,n,r)=>{if(!(!t||!n)){s(!0);try{let i=h4(await Yl(t,`login.complete`,{provider:e.id,flowId:n,...r?{code:r}:{}}));if(i?.state===`pending`)return;if(i?.state===`failed`){a({type:`error`,provider:e,message:`Login failed. Start a new runtime login flow.`});return}a({type:`success`,provider:e,message:`${e.name} login completed for this runtime.`})}catch(t){a({type:`error`,provider:e,message:t instanceof Error?t.message:String(t)})}finally{s(!1)}}},[t]),y=(0,H.useCallback)(async(e,n)=>{if(!t||!n){h();return}s(!0);try{await Yl(t,`login.cancel`,{provider:e.id,flowId:n}),h()}catch(t){a({type:`error`,provider:e,message:t instanceof Error?t.message:String(t)})}finally{s(!1)}},[t,h]);(0,H.useEffect)(()=>{if(i.type!==`device_flow`||i.completion!==`notification`||!i.flowId||!t)return;let e=async()=>{if(!(m.current||i.type!==`device_flow`)){m.current=!0;try{let e=h4(await Yl(t,`login.complete`,{provider:i.provider.id,flowId:i.flowId}));e?.state===`connected`||e?.state===`partial`?a({type:`success`,provider:i.provider,message:`${i.provider.name} login completed for this runtime.`}):e?.state===`failed`&&a({type:`error`,provider:i.provider,message:`Login failed. Start a new runtime login flow.`})}catch(e){a({type:`error`,provider:i.provider,message:e instanceof Error?e.message:String(e)})}finally{m.current=!1}}},n=window.setInterval(()=>void e(),1500);return()=>window.clearInterval(n)},[t,i]);let b=(0,H.useCallback)(async e=>{if(!t)return;let n=c.trim();if(n){s(!0);try{await Yl(t,`login.apikey`,{provider:e.id,apiKey:n}),l(``),a({type:`success`,provider:e,message:`${e.name} API key saved.`})}catch(t){a({type:`error`,provider:e,message:t instanceof Error?t.message:String(t)})}finally{s(!1)}}},[c,t]);return n?(0,U.jsx)(g4,{title:i.type===`select_provider`?`Login`:UVe(i),tone:i.type===`error`?`red`:i.type===`success`?`green`:`cyan`,action:i.type===`select_provider`?void 0:(0,U.jsx)(HVe,{onClick:()=>{i.type===`device_flow`?y(i.provider,i.flowId):h()},disabled:o}),children:i.type===`select_provider`?(0,U.jsxs)(`div`,{className:`grid gap-2`,children:[(0,U.jsxs)(`div`,{className:`text-[11px] text-[#737373]`,children:[`Choose a provider. Use `,(0,U.jsx)(`span`,{className:`text-[#38bdf8]`,children:`/login`}),` anytime.`]}),(0,U.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:r.map(e=>(0,U.jsxs)(`button`,{type:`button`,onClick:()=>a({type:`select_method`,provider:e}),className:`inline-flex items-center gap-1 border border-[#3a3a3a] bg-transparent px-2 py-1 text-[11px] text-[#d4d4d4] hover:border-[#38bdf8] hover:text-[#38bdf8]`,children:[(0,U.jsx)(`span`,{children:e.name}),e.configured?(0,U.jsx)(`span`,{className:`text-[#22c55e]`,children:`●`}):null]},e.id))})]}):i.type===`select_method`?(0,U.jsxs)(`div`,{className:`grid gap-2`,children:[(0,U.jsxs)(`div`,{className:`flex items-center gap-2 text-[11px]`,children:[(0,U.jsx)(`span`,{className:`text-[#737373]`,children:`Provider:`}),(0,U.jsx)(`span`,{className:`text-[#d4d4d4]`,children:i.provider.name}),i.provider.configured?(0,U.jsx)(_4,{tone:`green`,children:`Configured`}):(0,U.jsx)(_4,{tone:`neutral`,children:`Not configured`})]}),(0,U.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:i.provider.authMethods.map(e=>(0,U.jsxs)(`button`,{type:`button`,onClick:()=>e===`api_key`?a({type:`api_key`,provider:i.provider}):void _(i.provider,e),className:`inline-flex items-center gap-1 border border-[#3a3a3a] bg-transparent px-2 py-1 text-[11px] text-[#d4d4d4] hover:border-[#38bdf8] hover:text-[#38bdf8]`,children:[e===`api_key`?(0,U.jsx)(Dc,{size:11}):(0,U.jsx)(Ic,{size:11}),BVe[e]]},e))})]}):i.type===`device_starting`?(0,U.jsxs)(`div`,{className:`inline-flex items-center gap-2 text-[11px] text-[#38bdf8]`,children:[(0,U.jsx)(Pc,{size:13,className:`animate-spin`}),` Starting device login...`]}):i.type===`device_flow`?(0,U.jsxs)(`div`,{className:`grid gap-2 text-[11px]`,children:[(0,U.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,U.jsx)(`span`,{className:`text-[#737373]`,children:`Open:`}),(0,U.jsxs)(`a`,{href:i.url,target:`_blank`,rel:`noreferrer`,className:`inline-flex items-center gap-1 text-[#38bdf8] hover:underline`,children:[WVe(i.url),` `,(0,U.jsx)(fc,{size:11})]}),(0,U.jsxs)(`button`,{type:`button`,onClick:()=>void g(i.url),className:`inline-flex items-center gap-1 border border-[#3a3a3a] px-1.5 py-0.5 text-[#737373] hover:border-[#38bdf8] hover:text-[#38bdf8]`,children:[f===i.url?(0,U.jsx)(tc,{size:10}):(0,U.jsx)(sc,{size:10}),` `,f===i.url?`Copied`:`Copy`]})]}),i.userCode?(0,U.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,U.jsx)(`span`,{className:`text-[#737373]`,children:`Code:`}),(0,U.jsx)(`button`,{type:`button`,onClick:()=>void g(i.userCode),className:`border border-[#1f4960] px-2 py-0.5 font-semibold tracking-widest text-[#38bdf8] hover:border-[#38bdf8]`,children:i.userCode}),(0,U.jsx)(`span`,{className:`text-[#737373]`,children:`then`}),i.completion===`notification`?(0,U.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-[#38bdf8]`,children:[(0,U.jsx)(Pc,{size:11,className:`animate-spin`}),` Waiting for runtime`]}):(0,U.jsxs)(`button`,{type:`button`,disabled:o||!i.flowId,onClick:()=>void v(i.provider,i.flowId),className:`inline-flex items-center gap-1 border border-[#3a3a3a] px-2 py-0.5 text-[#d4d4d4] hover:border-[#38bdf8] hover:text-[#38bdf8] disabled:opacity-50`,children:[o?(0,U.jsx)(Pc,{size:11,className:`animate-spin`}):(0,U.jsx)(tc,{size:11}),` Complete`]})]}):(0,U.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[(0,U.jsx)(`input`,{value:u,autoComplete:`off`,spellCheck:!1,onChange:e=>d(e.target.value),placeholder:`authorization code`,className:`min-w-0 flex-1 border border-[#2a2a2a] bg-[#0b0b0b] px-2 py-1 text-[11px] text-[#d4d4d4] outline-none focus:border-[#38bdf8]`}),(0,U.jsxs)(`button`,{type:`button`,disabled:o||!u.trim()||!i.flowId,onClick:()=>void v(i.provider,i.flowId,u.trim()),className:`inline-flex items-center gap-1 border border-[#3a3a3a] px-2 py-1 text-[#d4d4d4] hover:border-[#38bdf8] hover:text-[#38bdf8] disabled:opacity-50`,children:[o?(0,U.jsx)(Pc,{size:11,className:`animate-spin`}):(0,U.jsx)(tc,{size:11}),` Complete`]})]}),i.instructions?(0,U.jsx)(`div`,{className:`text-[#737373]`,children:i.instructions}):null]}):i.type===`api_key`?(0,U.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5 text-[11px]`,children:[(0,U.jsx)(`span`,{className:`text-[#737373]`,children:`API key:`}),(0,U.jsx)(`input`,{type:`password`,value:c,autoComplete:`off`,spellCheck:!1,onChange:e=>l(e.target.value),onKeyDown:e=>{e.key===`Enter`&&b(i.provider)},placeholder:`sk-...`,className:`min-w-[12rem] flex-1 border border-[#2a2a2a] bg-[#0b0b0b] px-2 py-1 text-[11px] text-[#d4d4d4] outline-none focus:border-[#38bdf8]`}),(0,U.jsxs)(`button`,{type:`button`,disabled:o||!c.trim(),onClick:()=>void b(i.provider),className:`inline-flex items-center gap-1 border border-[#3a3a3a] px-2 py-1 text-[#d4d4d4] hover:border-[#38bdf8] hover:text-[#38bdf8] disabled:opacity-50`,children:[o?(0,U.jsx)(Pc,{size:11,className:`animate-spin`}):(0,U.jsx)(tc,{size:11}),` Save`]})]}):i.type===`success`?(0,U.jsxs)(`div`,{className:`flex items-center gap-2 text-[11px] text-[#22c55e]`,children:[(0,U.jsx)(tc,{size:13}),` `,i.message]}):(0,U.jsxs)(`div`,{className:`flex items-start gap-2 text-[11px] text-[#ef4444]`,children:[(0,U.jsx)($s,{size:13,className:`mt-0.5 shrink-0`}),` `,(0,U.jsx)(`span`,{children:i.message})]})}):(0,U.jsx)(g4,{title:`Login`,tone:`red`,children:`Unparseable login payload.`})}function g4({title:e,tone:t,action:n,children:r}){return(0,U.jsxs)(`div`,{className:`mt-2 border border-[#2a2a2a] bg-[#111111] px-3 py-2 text-[12px] text-[#d4d4d4]`,"data-shared-terminal-card":`login`,children:[(0,U.jsxs)(`div`,{className:`mb-2 flex items-center gap-2`,children:[(0,U.jsx)(Ic,{size:14,className:t===`red`?`text-[#ef4444]`:t===`green`?`text-[#22c55e]`:`text-[#38bdf8]`}),(0,U.jsx)(`span`,{className:`font-semibold text-[#d4d4d4]`,children:e}),n?(0,U.jsx)(`div`,{className:`ml-auto`,children:n}):null]}),r]})}function HVe({onClick:e,disabled:t}){return(0,U.jsxs)(`button`,{type:`button`,disabled:t,onClick:e,className:`inline-flex items-center gap-1 border border-[#3a3a3a] bg-transparent px-1.5 py-0.5 text-[11px] text-[#737373] hover:border-[#38bdf8] hover:text-[#38bdf8] disabled:opacity-50`,children:[(0,U.jsx)(Ms,{size:10}),` Back`]})}function _4({tone:e,children:t}){return(0,U.jsx)(`span`,{className:`border px-1.5 py-0.5 text-[10px] ${e===`green`?`border-[#14532d] text-[#22c55e]`:`border-[#3a3a3a] text-[#737373]`}`,children:t})}function UVe(e){return`provider`in e&&e.provider?e.provider.name:`Login`}function WVe(e){try{let t=new URL(e);return`${t.host}${t.pathname}`}catch{return e.length>42?`${e.slice(0,39)}...`:e}}function GVe({row:e,piboSessionId:t,onModelChanged:n}){let r=h4(e.output),i=(RVe(r)?r:void 0)?.providers??[],a=(0,H.useMemo)(()=>i.flatMap(e=>e.models.map(t=>({...t,providerLabel:e.label,authConfigured:e.authConfigured}))),[i]),[o,s]=(0,H.useState)(``),[c,l]=(0,H.useState)(null),[u,d]=(0,H.useState)(!1),[f,p]=(0,H.useState)(null),m=(0,H.useMemo)(()=>{let e=o.trim().toLowerCase();return e?a.filter(t=>`${t.providerLabel} ${t.provider} ${t.label} ${t.id}`.toLowerCase().includes(e)):a},[a,o]),h=async e=>{if(!(!t||u||e.authConfigured===!1)){d(!0),l(e),p(null);try{await Wl(t,{activeModel:{provider:e.provider,id:e.id}}),p(`Selected ${e.provider}/${e.id}.`),await n?.()}catch(e){p(e instanceof Error?e.message:String(e))}finally{d(!1)}}};return(0,U.jsxs)(`div`,{className:`ml-[1.9rem] max-w-3xl border border-[#3a3a3a] bg-[#111111] text-[12px] shadow-lg`,"data-shared-terminal-card":`model`,children:[(0,U.jsx)(`div`,{className:`flex items-center justify-between gap-3 border-b border-[#2a2a2a] px-3 py-2`,children:(0,U.jsxs)(`div`,{children:[(0,U.jsx)(`div`,{className:`text-[#d4d4d4]`,children:`Model`}),(0,U.jsx)(`div`,{className:`text-[11px] text-[#737373]`,children:`Choose a model exposed by the active runtime.`})]})}),(0,U.jsxs)(`div`,{className:`space-y-2 p-3`,children:[i.length?(0,U.jsxs)(U.Fragment,{children:[(0,U.jsxs)(`label`,{className:`flex items-center gap-2 border border-[#2a2a2a] bg-[#0b0b0b] px-2 py-1 text-[#737373]`,children:[(0,U.jsx)(dl,{size:13}),(0,U.jsx)(`input`,{value:o,onChange:e=>s(e.target.value),placeholder:`Search models`,className:`min-w-0 flex-1 bg-transparent text-[#d4d4d4] outline-none placeholder:text-[#525252]`})]}),(0,U.jsx)(`div`,{className:`max-h-72 overflow-auto border border-[#2a2a2a]`,children:m.length?m.map(e=>(0,U.jsxs)(`button`,{type:`button`,disabled:u||e.authConfigured===!1,onClick:()=>void h(e),className:`grid w-full grid-cols-[150px_1fr_auto] gap-2 border-b border-[#1f1f1f] px-3 py-2 text-left hover:bg-[#38bdf8]/10 disabled:cursor-not-allowed disabled:opacity-50`,children:[(0,U.jsx)(`span`,{className:`truncate text-[#737373]`,children:e.providerLabel}),(0,U.jsxs)(`span`,{className:`min-w-0`,children:[(0,U.jsx)(`span`,{className:`block truncate text-[#d4d4d4]`,children:e.label}),(0,U.jsxs)(`span`,{className:`block truncate text-[11px] text-[#737373]`,children:[e.provider,`/`,e.id]})]}),e.authConfigured===!1?(0,U.jsx)(Ic,{size:13,className:`text-[#737373]`,"aria-label":`Provider authentication missing`}):c?.provider===e.provider&&c?.id===e.id?(0,U.jsx)(Ws,{size:14,className:`text-[#22c55e]`}):null]},`${e.provider}:${e.id}`)):(0,U.jsx)(`div`,{className:`px-3 py-2 text-[#737373]`,children:`No matching models.`})})]}):(0,U.jsx)(`div`,{className:`text-[#737373]`,children:`No models are available for the active runtime.`}),f?(0,U.jsx)(`div`,{className:`text-[11px] text-[#a3a3a3]`,children:f}):null]})]})}var KVe=[[/\bBearer\s+\S+/gi,`Bearer [redacted]`],[/\b(?:sk-(?:proj-)?[A-Za-z0-9_-]{16,}|(?:sk|rk)_(?:live|test)_[A-Za-z0-9]{16,}|gh[pousr]_[A-Za-z0-9_]{16,}|github_pat_[A-Za-z0-9_]{16,}|xox[baprs]-[A-Za-z0-9-]{16,})\b/g,`[redacted]`],[/\beyJ[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]{10,}\b/g,`[redacted]`],[/\b([A-Z0-9_]*(?:ACCESS[_-]?TOKEN|REFRESH[_-]?TOKEN|ID[_-]?TOKEN|API[_-]?KEY|AUTHORIZATION|COOKIE|CREDENTIAL|OAUTH|TOKEN|SECRET|PASSWORD|PASSWD)[A-Z0-9_]*)\b(\s*["']?\s*[:=]\s*["']?)([^\s"'&,;}]+)/gi,`$1$2[redacted]`]];function qVe(e){let t=e;for(let[e,n]of KVe)t=t.replace(e,n);return t}function JVe(e={}){let t=[],n=[],r=b4(e.warnings),i=b4(e.errors);(e.session?.id||e.session?.title)&&t.push({id:`session`,label:`Session`,value:v4([e.session?.title,e.session?.id].filter(Boolean).join(` | `))}),e.session?.profile&&t.push({id:`profile`,label:`Profile`,value:v4(e.session.profile)}),e.session?.status&&t.push({id:`session-status`,label:`Session status`,value:v4(e.session.status),tone:e.session.status===`error`||e.session.status===`disposed`?`red`:`neutral`}),(e.model?.provider||e.model?.id||e.model?.label)&&t.push({id:`model`,label:`Model`,value:v4(e.model.label??[e.model.provider,e.model.id].filter(Boolean).join(`/`))}),e.runtime?.state&&t.push({id:`runtime`,label:`Runtime`,value:v4(e.runtime.state),tone:e.runtime.connected===!1||e.runtime.disposed?`red`:`green`}),e.runtime?.disposed!==void 0&&t.push({id:`disposed`,label:`Disposed`,value:e.runtime.disposed?`yes`:`no`,tone:e.runtime.disposed?`red`:`neutral`}),typeof e.runtime?.queuedMessages==`number`&&t.push({id:`queue`,label:`Queue`,value:String(e.runtime.queuedMessages)}),e.runtime?.processing!==void 0&&t.push({id:`processing`,label:`Processing`,value:e.runtime.processing?`yes`:`no`,tone:e.runtime.processing?`cyan`:`neutral`}),e.runtime?.streaming!==void 0&&t.push({id:`streaming`,label:`Streaming`,value:e.runtime.streaming?`yes`:`no`,tone:e.runtime.streaming?`cyan`:`neutral`}),e.cwd&&t.push({id:`cwd`,label:`CWD`,value:v4(e.cwd)});let a=typeof e.thinking==`string`?{level:e.thinking}:e.thinking;(a?.level||a?.supported!==void 0)&&t.push({id:`thinking`,label:`Thinking`,value:v4(a.level??(a.supported===!1?`unsupported`:`available`)),tone:a.supported===!1?`red`:`yellow`}),e.fastMode!==void 0&&t.push({id:`fast-mode`,label:`Fast mode`,value:typeof e.fastMode==`string`?v4(e.fastMode):e.fastMode?`on`:`off`,tone:e.fastMode?`green`:`neutral`});let o=b4(e.tools?.enabled),s=b4(e.tools?.active);o.length&&t.push({id:`enabled-tools`,label:`Enabled tools`,value:`${o.length}${o.length<=4?` (${o.join(`, `)})`:``}`}),s.length&&t.push({id:`active-tools`,label:`Active tools`,value:`${s.length}${s.length<=4?` (${s.join(`, `)})`:``}`,tone:`cyan`}),e.providerUsage?.planType&&t.push({id:`provider-plan`,label:`Provider plan`,value:v4(e.providerUsage.planType)}),e.providerUsage?.credits&&t.push({id:`provider-credits`,label:`Credits`,value:e.providerUsage.credits.unlimited?`unlimited`:v4(e.providerUsage.credits.balance??`available`)}),e.message&&t.push({id:`message`,label:`Message`,value:v4(e.message)}),n.push(YVe(e.contextUsage));for(let t of XVe(e.providerUsage))n.push(t);return{kind:`status`,title:`Status`,fields:t,progress:n,warnings:r,errors:i}}function v4(e){return qVe(e).replace(/\b([A-Z0-9_]*(?:API[_-]?KEY|TOKEN|SECRET|PASSWORD|PASSWD)[A-Z0-9_]*)\s*:\s*\[redacted\]/gi,`$1=[redacted]`)}function YVe(e){if(!e||e.tokens===void 0&&e.contextWindow===void 0&&e.percent===void 0)return{id:`context`,label:`Context`,state:`unavailable`,text:`Context usage unavailable`,tone:`neutral`};let t=y4(e.percent??(e.tokens!==void 0&&e.contextWindow?e.tokens/e.contextWindow*100:void 0));return{id:`context`,label:`Context`,state:t===void 0?`unavailable`:`available`,value:e.tokens,max:e.contextWindow,percent:t,text:t===void 0?`Context usage unavailable`:`${e.tokens??`?`}/${e.contextWindow??`?`} tokens (${t.toFixed(1)}%)`,tone:ZVe(t)}}function XVe(e){return e?.limits?.length?e.limits.map((t,n)=>{let r=y4(t.usedPercent),i=y4(t.remainingPercent??(r===void 0?void 0:100-r)),a=e.provider?`${e.provider} `:``,o=[i===void 0?void 0:`${i.toFixed(1)}% remaining`,t.resetsAt?`resets ${v4(t.resetsAt)}`:void 0].filter(Boolean).join(`, `);return{id:`provider-${n}`,label:`${a}${t.label??`quota`}`.trim(),state:i===void 0?`unavailable`:`available`,percent:i,text:i===void 0?`Provider usage unavailable`:o,tone:QVe(i)}}):[{id:`provider`,label:`Provider quota`,state:`unavailable`,text:`Provider usage unavailable`,tone:`neutral`}]}function y4(e){if(!(typeof e!=`number`||!Number.isFinite(e)))return Math.max(0,Math.min(100,e))}function ZVe(e){return e===void 0?`neutral`:e>=80?`red`:e>=50?`yellow`:`green`}function QVe(e){return e===void 0?`neutral`:e<=20?`red`:e<=50?`yellow`:`green`}function b4(e){return(e??[]).map(e=>v4(e)).filter(e=>e.length>0)}function x4(e){switch(e.kind){case`tool.status`:return $Ve(e);case`tool.thinking`:return eHe(e);case`tool.model`:return tHe(e);case`tool.login`:return nHe(e);case`tool.call`:case`tool.image`:case`tool.group.exploring`:case`tool.group.images`:return rHe(e);case`yielded.run`:return S4(e,`yielded-run`,`Yielded run`,e.status===`error`?`red`:e.status===`running`?`cyan`:`green`);case`execution.compaction`:return S4(e,`compaction`,e.status===`error`?`Compaction failed`:e.status===`running`?`Compacting`:`Compaction`,e.status===`error`?`red`:`magenta`);case`execution.command`:return S4(e,`command`,`Command`,e.status===`error`?`red`:`yellow`);case`error`:return S4(e,`error`,`Error`,`red`);default:return}}function $Ve(e){let t=C4(e.output),n=w4(t,`activeModel`)??w4(t,`model`),r=JVe({session:{id:D4(t,`piboSessionId`)??D4(t,`sessionId`),title:D4(t,`sessionTitle`)??D4(t,`title`),profile:D4(t,`profile`)??D4(t,`activeAgentId`)??D4(t,`agentId`),status:O4(t,`disposed`)?`disposed`:D4(t,`sessionStatus`)},model:n?{provider:D4(n,`provider`),id:D4(n,`id`),label:D4(n,`label`)}:void 0,runtime:{state:O4(t,`disposed`)?`disposed`:O4(t,`processing`)?`processing`:O4(t,`streaming`)?`streaming`:D4(t,`mode`)??`idle`,connected:O4(t,`connected`),queuedMessages:aHe(t,`queuedMessages`),processing:O4(t,`processing`),streaming:O4(t,`streaming`),disposed:O4(t,`disposed`)},cwd:D4(t,`cwd`),contextUsage:w4(t,`contextUsage`),providerUsage:w4(t,`providerUsage`),tools:{enabled:E4(t,`enabledTools`),active:E4(t,`activeTools`)},thinking:D4(t,`thinkingLevel`)?{level:D4(t,`thinkingLevel`)}:void 0,fastMode:O4(t,`fastMode`),warnings:E4(t,`warnings`),errors:E4(t,`errors`),message:D4(t,`message`)});return{id:e.id,kind:`status`,title:`Status`,status:e.status,tone:e.status===`error`?`red`:`green`,rows:r.fields.map(e=>({label:e.label,value:e.value,tone:e.tone})),statusView:r,sourceRowKind:e.kind}}function eHe(e){let t=C4(e.output),n=D4(t,`level`)??`unknown`,r=t?.supported!==!1,i=E4(t,`availableLevels`);return{id:e.id,kind:`thinking`,title:`Thinking`,status:e.status,tone:r?`yellow`:`red`,rows:[{label:`Current`,value:v4(n)},{label:`Supported`,value:r?`yes`:`no`,tone:r?`green`:`red`}],actions:i.map(e=>({id:`thinking:${e}`,label:e,action:`thinking.set`,value:e,disabled:!r})),sourceRowKind:e.kind}}function tHe(e){let t=T4(C4(e.output),`providers`),n=t.flatMap(e=>{let t=D4(e,`id`)??D4(e,`provider`)??`provider`,n=D4(e,`label`)??D4(e,`name`)??t;return T4(e,`models`).map(e=>{let r=D4(e,`id`)??`model`,i=D4(e,`label`)??r;return{id:`model:${t}:${r}`,label:`${n} / ${i}`,action:`model.select`,value:`${t}/${r}`}})});return{id:e.id,kind:`model`,title:`Model`,status:e.status,tone:n.length?`cyan`:`neutral`,rows:[{label:`Providers`,value:String(t.length)},{label:`Models`,value:String(n.length)}],actions:n,sourceRowKind:e.kind}}function nHe(e){let t=T4(C4(e.output),`providers`),n=t.map(e=>{let t=D4(e,`id`)??`provider`;return{id:`login:${t}`,label:D4(e,`name`)??D4(e,`label`)??t,action:`login.selectProvider`,value:t,description:E4(e,`authMethods`).join(`, `)}});return{id:e.id,kind:`login`,title:`Login`,status:e.status,tone:n.length?`cyan`:`neutral`,rows:[{label:`Providers`,value:String(t.length)}],actions:n,sourceRowKind:e.kind}}function rHe(e){return S4(e,`tool`,e.kind===`tool.group.exploring`?`Exploring`:e.kind===`tool.image`||e.kind===`tool.group.images`?`Image`:`Tool`,e.status===`error`?`red`:e.status===`running`?`cyan`:`green`)}function S4(e,t,n,r){let i=e.lines.flatMap(e=>{let t=`${e.tokens.map(e=>e.text).join(``)}${e.functionCall?`${e.functionCall.name}${e.functionCall.input===void 0?``:` ${iHe(e.functionCall.input)}`}`:``}`.trim();return t?[{value:v4(t)}]:[]}),a=e.lines.length===0&&typeof e.output==`string`&&e.output.trim()?[{value:v4(e.output.trim())}]:[],o=[e.error?{label:`Error`,value:v4(e.error),tone:`red`}:void 0].filter(e=>!!e);return{id:e.id,kind:t,title:n,status:e.status,tone:r,rows:[...i,...a,...o],sourceRowKind:e.kind}}function iHe(e){try{return JSON.stringify(e)}catch{return String(e)}}function C4(e){if(e){if(typeof e==`string`)try{let t=JSON.parse(e);return t&&typeof t==`object`&&!Array.isArray(t)?t:void 0}catch{return}return typeof e==`object`&&!Array.isArray(e)?e:void 0}}function w4(e,t){let n=e?.[t];return n&&typeof n==`object`&&!Array.isArray(n)?n:void 0}function T4(e,t){let n=e?.[t];return Array.isArray(n)?n.filter(e=>!!e&&typeof e==`object`&&!Array.isArray(e)):[]}function E4(e,t){let n=e?.[t];return Array.isArray(n)?n.filter(e=>typeof e==`string`):[]}function D4(e,t){let n=e?.[t];return typeof n==`string`?n:void 0}function aHe(e,t){let n=e?.[t];return typeof n==`number`&&Number.isFinite(n)?n:void 0}function O4(e,t){let n=e?.[t];return typeof n==`boolean`?n:void 0}var oHe=1e3,sHe={browser_use_open_tabs:`browser_use.open_tabs`,browser_use_take_screenshot:`browser_use.take_screenshot`,browser_use_browser_use:`browser_use.browser_use`,node_repl_js:`node_repl.js`,node_repl_js_reset:`node_repl.js_reset`};function cHe(e,t){if(!e)return[];let n=j4(e.nodes),r=qHe(M4(e.nodes).sort((e,t)=>yX(e.node,t.node)).filter(e=>e.node.type!==`agent.turn`&&(t.showThinking||e.node.type!==`model.reasoning`)).map(e=>dHe(e.node,e.turnId)));xHe(r,n);let i=pHe(r);return lHe(!t.debugMode&&(t.toolDisplayMode??`default`)==="default"?XHe(i).map(e=>e.row):i.map(e=>e.row),t.toolDisplayMode??`default`)}function lHe(e,t){return t==="default"?e:t===`hide`?e.filter(e=>!k4(e)):e.flatMap(e=>{if(!k4(e))return[e];let n=e.intent?.trim();if(t===`intent`&&!n)return[];let r={...e,lines:e.lines.slice(0,1),singleLine:!0};return t===`intent`?[{...r,title:void 0,summary:void 0,lines:[{prefix:`bullet`,tokens:[e3(n,e.status===`error`?`red`:e.status===`done`?`green`:`cyan`,`semibold`)]}],input:void 0,output:void 0,error:void 0,markdown:void 0,expandable:!1,previewOmission:void 0,detailItems:void 0}]:[r]})}function k4(e){return e.sourceNodeIds.some(e=>EX(e)!==void 0)||e.id.startsWith(`terminal:tool:`)||e.kind===`tool.call`||e.kind===`tool.image`||e.kind===`tool.group.exploring`||e.kind===`tool.group.images`||e.kind===`agent.delegation`}function uHe(e){if(!e)return;let t=new Set(M4(e.nodes).map(({node:e})=>e).filter(e=>e.type===`error`&&e.eventId).map(e=>e.eventId));return[...j4(e.nodes).values()].filter(e=>e.startedAt&&!e.completedAt&&(!e.eventId||!t.has(e.eventId))).sort(yX).at(-1)?.startedAt}function A4(e){let t=Math.max(0,Math.floor(e/1e3));return[Math.floor(t/3600),Math.floor(t%3600/60),t%60].map(e=>String(e).padStart(2,`0`)).join(`:`)}function j4(e){let t=new Map;for(let n of e){n.type===`agent.turn`&&t.set(n.id,n);for(let[e,r]of j4(n.children))t.set(e,r)}return t}function M4(e,t){let n=[];for(let r of e)r.type!==`agent.turn`&&n.push({node:r,turnId:t}),n.push(...M4(r.children,r.type===`agent.turn`?r.id:t));return n}function dHe(e,t){let n;switch(e.type){case`user.message`:n={row:wHe(e),turnId:t};break;case`assistant.message`:n={row:THe(e),turnId:t};break;case`model.reasoning`:n={row:EHe(e),turnId:t};break;case`tool.call`:n=DHe(e,t);break;case`tool.result`:n=kHe(e,t);break;case`agent.delegation`:n={row:jHe(e),turnId:t};break;case`agent.async`:n={row:MHe(e),turnId:t};break;case`yielded.run`:n={row:NHe(e),turnId:t};break;case`execution.command`:n={row:FHe(e),turnId:t};break;case`execution.compaction`:n={row:PHe(e),turnId:t};break;case`error`:n={row:GHe(e),turnId:t};break;case`agent.turn`:n={row:{id:e.id,kind:`error`,status:`neutral`,lines:[],sourceNodeIds:[e.id]},turnId:t}}return{...n,row:{...n.row,id:fHe(e),intent:e.intent,isToolCall:e.type===`tool.call`||e.type===`tool.result`||e.type===`agent.delegation`&&!!e.toolCallId,toolMetrics:e.toolMetrics,...CHe(e)}}}function fHe(e){if(e.type===`tool.call`||e.type===`tool.result`||e.type===`agent.delegation`){if(e.toolCallId)return EX(e.id)?.qualifier?`terminal:${e.id}`:`terminal:tool:${e.toolCallId}`;if(e.type===`agent.delegation`&&e.linkedPiboSessionId)return`terminal:delegation:${e.linkedPiboSessionId}`}if((e.type===`agent.async`||e.type===`yielded.run`)&&e.runId)return`terminal:run:${e.runId}`;if(e.type===`assistant.message`){let t=N4(e.stableKey,`assistant:`);if(t)return`terminal:assistant:${t}`}if(e.type===`model.reasoning`){let t=N4(e.stableKey,`reasoning:`);if(t)return`terminal:reasoning:${t}`}return e.id}function N4(e,t){if(!e?.startsWith(t))return;let n=e.slice(t.length);return n&&n!==`undefined`?n:void 0}function pHe(e){let t=[],n=new Map;for(let r of e){let e=n.get(r.row.id);if(e===void 0){n.set(r.row.id,t.length),t.push(r);continue}let i=t[e];t[e]={...r,turnId:r.turnId??i.turnId,row:{...i.row,...r.row,sourceNodeIds:[...new Set([...i.row.sourceNodeIds,...r.row.sourceNodeIds])],intent:r.row.intent??i.row.intent,input:r.row.input??i.row.input,output:r.row.output??i.row.output,error:r.row.error??i.row.error,payloadRefs:{...i.row.payloadRefs,...r.row.payloadRefs},imagePreviews:bHe(i.row.imagePreviews,r.row.imagePreviews)}}}return mHe(t)}function mHe(e){let t=new Map;for(let n=0;n<e.length;n+=1){let r=e[n].row,i=gHe(r)?`canonical`:_He(r)?`fallback`:void 0,a=yHe(r.id);if(!i||a===void 0||typeof r.output!=`string`)continue;let o=`${a}\0${r.output}`,s=t.get(o)??{canonical:[],fallback:[]};s[i].push(n),t.set(o,s)}let n=[...e],r=new Set;for(let e of t.values()){if(e.canonical.length!==1||e.fallback.length!==1)continue;let t=e.canonical[0],i=e.fallback[0],a=n[t],o=n[i];vHe(a.row,o.row)&&(n[t]=hHe(a,o),r.add(i))}return n.filter((e,t)=>!r.has(t))}function hHe(e,t){return{...t,...e,turnId:e.turnId??t.turnId,row:{...t.row,...e.row,sourceNodeIds:[...new Set([...e.row.sourceNodeIds,...t.row.sourceNodeIds])],completedAt:e.row.completedAt??t.row.completedAt,durationMs:e.row.durationMs??t.row.durationMs,payloadRefs:{...t.row.payloadRefs,...e.row.payloadRefs}}}}function gHe(e){let t=e.eventId;return e.kind===`message.assistant`&&e.status===`done`&&e.orderSource===`event-log`&&t!==void 0&&!t.startsWith(`native-history-group:`)}function _He(e){return e.kind===`message.assistant`&&e.status===`done`&&e.orderSource===`transcript`&&e.eventId?.startsWith(`native-history-group:`)===!0}function vHe(e,t){let n=Date.parse(e.completedAt??e.startedAt??``),r=Date.parse(t.completedAt??t.startedAt??``);return Number.isFinite(n)&&Number.isFinite(r)&&Math.abs(n-r)<=oHe}function yHe(e){let t=e.match(/:assistant:(\d+)$/);if(!t)return;let n=Number(t[1]);return Number.isSafeInteger(n)?n:void 0}function bHe(e,t){if(!e?.length)return t?.slice(0,20);if(!t?.length)return e.slice(0,20);let n=new Map(e.map(e=>[e.id,e]));for(let e of t)if(n.set(e.id,{...n.get(e.id),...e}),n.size>=20)break;return[...n.values()]}function xHe(e,t){for(let n of t.values()){if(!n.completedAt)continue;let t=e.filter(e=>e.turnId===n.id).at(-1);t?.row.kind===`message.assistant`&&t.row.status!==`running`&&(t.row.startedAt=n.startedAt,t.row.completedAt=n.completedAt,t.row.durationMs=n.durationMs??SHe(n.startedAt,n.completedAt))}}function SHe(e,t){if(!e||!t)return;let n=new Date(e).getTime(),r=new Date(t).getTime();return Number.isFinite(n)&&Number.isFinite(r)?Math.max(0,r-n):void 0}function CHe(e){return{eventId:e.eventId,runId:e.runId,orderSource:e.source,orderStreamId:e.orderKey?.streamId,orderStreamFrameIndex:e.orderKey?.streamFrameIndex,payloadRefs:e.payloadRefs}}function wHe(e){let t=t3(e.output)||t3(e.summary)||e.title;return{id:e.id,kind:`message.user`,status:Q4(e.status),lines:[{prefix:`prompt`,tokens:[e3(t)]}],sourceNodeIds:[e.id],forkEntryId:e.entryId,pendingMessageDelivery:yUe(e),startedAt:e.startedAt,output:t,payloadRefs:e.payloadRefs}}function THe(e){return{id:e.id,kind:`message.assistant`,status:Q4(e.status),lines:[],sourceNodeIds:[e.id],startedAt:e.startedAt,completedAt:e.source===`transcript`||e.source===`product-history`?e.completedAt:void 0,durationMs:e.source===`transcript`||e.source===`product-history`?e.durationMs:void 0,output:t3(e.output)||t3(e.summary)||``,error:e.error,payloadRefs:e.payloadRefs}}function EHe(e){let t=q4(e.output??e.summary);return{id:e.id,kind:`reasoning`,status:Q4(e.status),lines:[{prefix:`bullet`,tokens:[e3(e.status===`running`?`Thinking`:`Thought`,`amber`,`semibold`)]}],sourceNodeIds:[e.id],markdown:t,payloadRefs:e.payloadRefs}}function DHe(e,t){let n=Z4(e.input);if(n&&oUe(e.title))return{row:WHe(e,n),turnId:t,exploring:void 0};if(sUe(e.title))return{row:OHe(e),turnId:t};let r=L4(e);if(r)return{row:P4(e,r),turnId:t,image:r.groupable?r.detail:void 0};let i=G4(e.error??e.output,5,e.error?`red`:`dim`);return{row:{id:e.id,kind:`tool.call`,status:Q4(e.status),errorKind:e.status===`error`?`tool`:void 0,lines:[{prefix:`bullet`,tokens:[e3(_Ue(e.status),$4(e.status),`semibold`),e3(` `)],functionCall:{name:B4(e.title),input:e.input}},...i.lines],sourceNodeIds:[e.id],input:e.input,output:e.output,error:e.error,expandable:e.input!==void 0||e.output!==void 0||!!e.error,previewOmission:K4(i,e.error?`error`:`output`)},turnId:t,exploring:aUe(e)}}function OHe(e){let t=Q4(e.status),n=lUe(e),r=uUe(e),i=dUe(e),a=fUe(e),o=pUe(e),s=mUe(e.output),c=hUe(e.output),l=[{prefix:`bullet`,tokens:[e3(cUe(e.status,n),$4(e.status),e.status===`error`?`bold`:`semibold`)]}];r?l.push({prefix:`detail`,tokens:[e3(`query: ${JSON.stringify(r)}`,`cyan`)]}):i?.length&&l.push({prefix:`detail`,tokens:[e3(`queries: ${JSON.stringify(i)}`,`cyan`)]}),a&&l.push({prefix:`detail`,tokens:[e3(`page: `,`dim`),X4(a,`Open web page: ${a}`)]}),o&&l.push({prefix:`detail`,tokens:[e3(`find: ${JSON.stringify(o)}`,`cyan`)]}),e.status===`done`&&c!==void 0&&l.push({prefix:`detail`,tokens:[e3(`sources: ${c}`,`dim`)]});let u=s.slice(0,3);for(let e of u)l.push({prefix:`detail`,tokens:[...e.title?[e3(`${e.title}: `,`dim`)]:[],X4(e.url,`Open source: ${e.title??e.url}`)]});let d=Math.max(0,(c??s.length)-u.length);return u.length>0&&d>0&&l.push({prefix:`detail`,tokens:[e3(`+${d} more sources`,`dim`)]}),e.status===`error`&&e.error&&l.push({prefix:`detail`,tokens:[e3(e.error,`red`)]}),{id:e.id,kind:`tool.call`,status:t,errorKind:e.status===`error`?`tool`:void 0,lines:l,sourceNodeIds:[e.id],input:e.input,output:e.output,error:e.error,expandable:e.input!==void 0||e.output!==void 0||!!e.error}}function P4(e,t){let n=Q4(e.status),r=t.path?`Path: ${t.path}`:t.artifactId?`Artifact: ${t.artifactId}`:t.query?`Query: ${t.query}`:t.mimeType?`Type: ${t.mimeType}`:`Image content returned`;return{id:e.id,kind:`tool.image`,status:n,errorKind:e.status===`error`?`tool`:void 0,lines:[{prefix:`bullet`,tokens:[e3(t.verb,$4(e.status),`semibold`)]},{prefix:`detail`,tokens:[e3(r,e.status===`error`?`red`:`cyan`)]}],sourceNodeIds:[e.id],input:z4(e.input),output:t.summary,error:e.error,expandable:e.input!==void 0||t.summary!==void 0||!!e.error,imagePreviews:t.previews}}function kHe(e,t){let n=L4(e);return n?{row:P4(e,n),turnId:t,image:n.groupable?n.detail:void 0}:{row:AHe(e),turnId:t}}function AHe(e){let t=G4(e.error??e.output,5,e.error?`red`:`dim`);return{id:e.id,kind:`tool.call`,status:Q4(e.status),errorKind:e.status===`error`?`tool`:void 0,lines:[{prefix:`bullet`,tokens:[e3(e.status===`error`?`Tool failed`:`Returned`,$4(e.status),`semibold`),e3(` ${B4(e.title)}`)]},...t.lines],sourceNodeIds:[e.id],output:e.output,error:e.error,expandable:e.output!==void 0||!!e.error,previewOmission:K4(t,e.error?`error`:`output`)}}function jHe(e){let t=t3(n3(e.input)?e.input.subagentName:void 0)||e.summary||e.title,n=J4((n3(e.input)?e.input.arguments:void 0)??e.input),r=n?[{prefix:`detail`,tokens:[e3(n,`dim`)]}]:[];return{id:e.id,kind:`agent.delegation`,status:Q4(e.status),errorKind:e.status===`error`?`tool`:void 0,title:e.title,summary:e.summary,lines:[{prefix:`bullet`,tokens:[e3(vUe(e.status),$4(e.status),`semibold`),e3(` ${t}`,`cyan`)]},...r],sourceNodeIds:[e.id],linkedPiboSessionId:e.linkedPiboSessionId,startedAt:e.startedAt,completedAt:e.completedAt,durationMs:e.durationMs,input:e.input,output:e.output,error:e.error,expandable:e.input!==void 0||e.output!==void 0||!!e.error}}function MHe(e){let t=G4(e.error??e.output,5,e.error?`red`:`dim`);return{id:e.id,kind:`agent.async`,status:Q4(e.status),lines:[{prefix:`bullet`,tokens:[e3(bUe(e.status),$4(e.status),`semibold`),e3(` ${e.title}`,`cyan`)]},...t.lines],sourceNodeIds:[e.id],linkedPiboSessionId:e.linkedPiboSessionId,input:e.input,output:e.output,error:e.error,expandable:e.input!==void 0||e.output!==void 0||!!e.error,previewOmission:K4(t,e.error?`error`:`output`)}}function NHe(e){let t=G4(e.output,5);return{id:e.id,kind:`yielded.run`,status:Q4(e.status),errorKind:e.status===`error`?`tool`:void 0,lines:[{prefix:`bullet`,tokens:[e3(e.status===`running`?`Waiting on runs`:`Run update`,$4(e.status),`semibold`),e3(e.summary?` ${e.summary}`:``)]},...t.lines],sourceNodeIds:[e.id],output:e.output,error:e.error,expandable:e.output!==void 0||!!e.error,previewOmission:K4(t,`output`)}}function PHe(e){let t=e.status===`running`?`Compacting`:e.status===`error`?`Compaction failed`:t3(e.summary)||`Compacted`;return{id:e.id,kind:`execution.compaction`,status:Q4(e.status),lines:[{prefix:`bullet`,tokens:[e3(t,$4(e.status),e.status===`error`?`bold`:`semibold`)]}],sourceNodeIds:[e.id],input:e.input,output:e.output,error:e.error,expandable:e.input!==void 0||e.output!==void 0||!!e.error}}function FHe(e){if(e.title===`status`)return IHe(e);if(e.title===`thinking`)return YHe(e.output)?RHe(e):LHe(e);if(e.title===`fast_mode`)return zHe(e);if(e.title===`login`&&HHe(e.output))return BHe(e);if(e.title===`model`&&UHe(e.output))return VHe(e);Z4(e.output)??Z4(e.input)??e.title;let t=G4(e.error??e.output,5,e.error?`red`:`dim`,180);return{id:e.id,kind:`execution.command`,status:Q4(e.status),lines:[{prefix:`bullet`,tokens:[e3(`Command`,`yellow`,`semibold`),e3(` /${e.title}`,`yellow`)]},...t.lines],sourceNodeIds:[e.id],input:e.input,output:e.output,error:e.error,expandable:e.input!==void 0||e.output!==void 0||!!e.error,previewOmission:K4(t,e.error?`error`:`output`)}}function IHe(e){return{id:e.id,kind:`tool.status`,status:Q4(e.status),lines:[],sourceNodeIds:[e.id],input:e.input,output:e.output,error:e.error,expandable:!1}}function LHe(e){return{id:e.id,kind:`tool.thinking`,status:Q4(e.status),lines:[],sourceNodeIds:[e.id],input:e.input,output:e.output,error:e.error,expandable:!1}}function RHe(e){let t=n3(e.output)?e.output:void 0,n=t3(t?.level),r=t?.changed!==!1,i=t?.supported!==!1,a=i?n?r?`Thinking level set to ${n}.`:`Thinking level is already ${n}.`:`Thinking level updated.`:`Thinking level is not supported by this model.`;return{id:e.id,kind:`execution.command`,status:Q4(e.status),lines:[{prefix:`bullet`,tokens:[e3(a,i?`green`:`dim`,`semibold`)]}],sourceNodeIds:[e.id],input:e.input,output:e.output,error:e.error,expandable:!1}}function zHe(e){let t=n3(e.output)?e.output:void 0,n=t?.mode===`fast`?`fast`:t?.mode===`normal`?`normal`:void 0,r=t?.changed!==!1,i=t?.supported!==!1,a=i?n===`fast`?r?`Switched to Fast mode.`:`Fast mode is already on.`:n===`normal`?r?`Switched to Normal mode.`:`Normal mode is already on.`:`Fast mode updated.`:`Fast mode is not supported by this model.`;return{id:e.id,kind:`execution.command`,status:Q4(e.status),lines:[{prefix:`bullet`,tokens:[e3(a,i?`green`:`dim`,`semibold`)]}],sourceNodeIds:[e.id],input:e.input,output:e.output,error:e.error,expandable:!1}}function BHe(e){return{id:e.id,kind:`tool.login`,status:Q4(e.status),lines:[],sourceNodeIds:[e.id],input:e.input,output:e.output,error:e.error,expandable:!1}}function VHe(e){return{id:e.id,kind:`tool.model`,status:Q4(e.status),lines:[],sourceNodeIds:[e.id],input:e.input,output:e.output,error:e.error,expandable:!1}}function HHe(e){if(!e||typeof e!=`object`||Array.isArray(e))return!1;let t=e;return t.action===`show_login_menu`&&Array.isArray(t.providers)}function UHe(e){if(!e||typeof e!=`object`||Array.isArray(e))return!1;let t=e;return t.action===`show_model_menu`&&Array.isArray(t.providers)}function WHe(e,t){let n=G4(e.error??e.output,5,e.error?`red`:`dim`,180);return{id:e.id,kind:`execution.command`,status:Q4(e.status),errorKind:e.status===`error`?`tool`:void 0,lines:[{prefix:`bullet`,tokens:[e3(e.status===`running`?`Running`:`Ran`,$4(e.status),`semibold`),e3(` `),...gUe(t)]},...n.lines],sourceNodeIds:[e.id],input:e.input,output:e.output,error:e.error,expandable:e.input!==void 0||e.output!==void 0||!!e.error,previewOmission:K4(n,e.error?`error`:`output`)}}function GHe(e){return{id:e.id,kind:`error`,status:`error`,errorKind:`system`,lines:[{prefix:`bullet`,tokens:[e3(e.title||`Error`,`red`,`bold`),e3(e.error?` ${e.error}`:``,`red`)]},...KHe(e.input)],sourceNodeIds:[e.id],input:e.input,error:e.error,output:e.output,expandable:e.input!==void 0||e.output!==void 0||!!e.error}}function KHe(e){return n3(e)?[[`Class`,t3(e.errorClass)??t3(e.category)],[`Code`,t3(e.code)??t3(e.providerCode)],[`Origin`,t3(e.origin)],[`Provider`,[t3(e.api),t3(e.provider),t3(e.model)].filter(Boolean).join(` / `)||void 0],[`Retryable`,typeof e.retryable==`boolean`?e.retryable?`yes`:`no`:void 0]].filter(e=>typeof e[1]==`string`&&e[1].length>0).map(([e,t],n)=>({prefix:n===0?`detail`:`continuation`,tokens:[e3(`${e}: `,`dim`),e3(t,`red`)]})):[]}function qHe(e){let t=e.map(e=>e.row.output).filter(JHe).at(-1);return t?e.map(e=>e.row.kind!==`tool.thinking`||!n3(e.row.output)?e:{...e,row:{...e.row,output:{...e.row.output,level:t.level,availableLevels:t.availableLevels,supported:t.supported}}}):[...e]}function JHe(e){return n3(e)&&typeof e.level==`string`&&Array.isArray(e.availableLevels)}function YHe(e){return n3(e)&&e.action===`set_thinking_level`}function XHe(e){let t=[];for(let n=0;n<e.length;n+=1){let r=e[n],i=F4(r);if(!i){t.push(r);continue}let a=[r],o=n+1;for(;o<e.length&&F4(e[o])===i&&e[o].turnId===r.turnId;)a.push(e[o]),o+=1;if(a.length===1){t.push(r);continue}t.push({row:i===`images`?QHe(a):ZHe(a),turnId:r.turnId}),n=o-1}return t}function F4(e){if(e.image)return`images`;if(e.exploring)return`exploring`}function ZHe(e){let t=I4(e,`exploring`),n=t.slice(0,6),r=Math.max(0,t.length-n.length),i=e[0]?.row,a=i?.id??`exploring`,o=e[e.length-1]?.row.id??a,s=e.some(e=>e.row.status===`running`)?`running`:e.some(e=>e.row.status===`error`)?`error`:`done`;return{id:`group:exploring:${a}:${o}`,kind:`tool.group.exploring`,status:s,errorKind:s===`error`?`tool`:void 0,lines:[{prefix:`bullet`,tokens:[e3(s===`running`?`Exploring`:s===`error`?`Exploring failed`:`Explored`,$4(s),`semibold`)]},...n.map((e,t)=>({prefix:t===0?`detail`:`continuation`,tokens:[e3(e.label,e.status===`error`?`red`:`dim`)]})),...r>0?[{prefix:`continuation`,tokens:[e3(`+${r} more explorations`,`dim`,`normal`,!0)]}]:[]],sourceNodeIds:e.flatMap(e=>e.row.sourceNodeIds),eventId:i?.eventId,runId:i?.runId,orderSource:i?.orderSource,orderStreamId:i?.orderStreamId,orderStreamFrameIndex:i?.orderStreamFrameIndex,detailItems:t,expandable:t.some(e=>e.input!==void 0||e.output!==void 0||!!e.error),previewOmission:r>0?{source:`details`,visibleLineCount:n.length,omittedLineCount:r,totalLineCount:t.length,maxVisibleLineCount:6}:void 0}}function QHe(e){let t=I4(e,`images`),n=t.slice(0,6),r=Math.max(0,t.length-n.length),i=e[0]?.row,a=i?.id??`images`,o=e[e.length-1]?.row.id??a,s=e.some(e=>e.row.status===`running`)?`running`:e.some(e=>e.row.status===`error`)?`error`:`done`;return{id:`group:images:${a}:${o}`,kind:`tool.group.images`,status:s,errorKind:s===`error`?`tool`:void 0,lines:[{prefix:`bullet`,tokens:[e3(s===`running`?`Viewing images`:s===`error`?`Image reads failed`:`Viewed images`,$4(s),`semibold`)]},...n.map((e,t)=>({prefix:t===0?`detail`:`continuation`,tokens:[e3(e.label,e.status===`error`?`red`:`cyan`)]})),...r>0?[{prefix:`continuation`,tokens:[e3(`+${r} more image reads`,`dim`,`normal`,!0)]}]:[]],sourceNodeIds:e.flatMap(e=>e.row.sourceNodeIds),eventId:i?.eventId,runId:i?.runId,orderSource:i?.orderSource,orderStreamId:i?.orderStreamId,orderStreamFrameIndex:i?.orderStreamFrameIndex,detailItems:t,expandable:t.some(e=>e.input!==void 0||e.output!==void 0||!!e.error),imagePreviews:t.flatMap(e=>e.imagePreviews??[]).slice(0,20),previewOmission:r>0?{source:`details`,visibleLineCount:n.length,omittedLineCount:r,totalLineCount:t.length,maxVisibleLineCount:6}:void 0}}function I4(e,t){return e.map(e=>{let n=t===`images`?e.image:e.exploring;return{id:e.row.id,label:n?.label??e.row.lines[0]?.tokens.map(e=>e.text).join(``)??e.row.id,status:e.row.status,input:e.row.input,output:e.row.output,error:e.row.error,payloadRefs:e.row.payloadRefs,linkedPiboSessionId:e.row.linkedPiboSessionId,previewOmission:e.row.previewOmission,imagePreviews:e.row.imagePreviews}})}function L4(e){let t=(e.title??``).trim().toLowerCase(),n=n3(e.input)?e.input:void 0,r=n3(e.output)?e.output:void 0,i=iUe(r,`details`),a=t===`codex_image_generation`?tUe(i)??nUe(n):void 0,o=a?t3(i?.savedPath)??H4(i):H4(n)??H4(i)??H4(r),s=a?t3(i?.artifactId):void 0,c=U4(n),l=R4(e.output).slice(0,20),u=e.payloadRefs?.output,d=Math.min(u?.imageCount??0,20),f=V4(t,[`view_image`,`image`,`screenshot`])||t===`read`&&$He(o);if(!l.length&&!d&&!f&&!a)return;let p=l.map(e=>e.mimeType).find(e=>!!e),m=Math.max(1,l.length,d),h={type:m>1?`images`:l.length===1?`image`:`image_reference`,toolName:a?e.title:void 0,operation:a,path:o,savedPath:a?o:void 0,artifactId:s,model:a?t3(i?.model):void 0,referencedImageCount:a?W4(i?.referencedImageCount):void 0,query:c,mimeType:p,count:m>1?m:void 0,detail:l.length||d?`Image data hidden in terminal view.`:`Image path only; binary data is hidden in terminal view.`},g=o??s??c??p??`image`,_=a?rUe(e.status,a):eUe(e.status,m),v=l.length?l:Array.from({length:Math.max(1,d)},()=>({mimeType:p})),y=v.map((t,n)=>({id:`${e.id}:image:${n}`,label:v.length>1?`${g} (${n+1}/${v.length})`:g,path:o,artifactId:s,payloadRef:u?.ref,payloadImageIndex:u?n:void 0,traceNodeId:u?u.nodeId??e.id:void 0,generatedToolCallId:a?e.toolCallId:void 0,mimeType:t.mimeType??p}));return{count:m,path:o,artifactId:s,query:c,mimeType:p,verb:_,groupable:!a,summary:h,previews:y,detail:{id:e.id,label:`${_} ${g}`,status:Q4(e.status),input:z4(e.input),output:h,error:e.error,imagePreviews:y}}}function $He(e){return e?/\.(?:png|jpe?g|gif|webp|bmp|avif)$/i.test(e.split(/[?#]/,1)[0]??``):!1}function R4(e,t=0,n=new Set){if(t>5||n.size>=1e3||typeof e!=`object`||!e||n.has(e))return[];if(n.add(e),Array.isArray(e)){let r=[];for(let i of e)if(r.push(...R4(i,t+1,n)),r.length>=20)return r.slice(0,20);return r}let r=e,i=typeof r.type==`string`?r.type.toLowerCase():void 0,a=typeof r.mimeType==`string`?r.mimeType:typeof r.mime_type==`string`?r.mime_type:void 0,o=typeof r.data==`string`||typeof r.image_url==`string`||n3(r.image_url);if((i===`image`||i===`input_image`||i===`output_image`||i===`image_url`)&&(o||a?.startsWith(`image/`))||a?.startsWith(`image/`)&&o)return[{mimeType:a}];let s=[];`content`in r&&s.push(r.content),`message`in r&&s.push(r.message),`result`in r&&s.push(r.result),`output`in r&&s.push(r.output);let c=[];for(let e of s)if(c.push(...R4(e,t+1,n)),c.length>=20)break;return c.slice(0,20)}function z4(e){if(Array.isArray(e))return e.map(z4);if(!n3(e))return e;let t={};for(let[n,r]of Object.entries(e)){if((n===`data`||n===`image_url`)&&typeof r==`string`&&r.length>120){t[n]=`[hidden ${n}]`;continue}t[n]=z4(r)}return t}function eUe(e,t){return e===`running`?t>1?`Viewing images`:`Viewing image`:e===`error`?t>1?`Image reads failed`:`Image read failed`:t>1?`Viewed images`:`Viewed image`}function tUe(e){let t=t3(e?.operation);return t===`generate`||t===`edit`?t:void 0}function nUe(e){if(!e)return;let t=e.referenced_image_paths;return Array.isArray(t)&&t.length>0||W4(e.num_last_images_to_include)!==void 0?`edit`:`generate`}function rUe(e,t){return t===`edit`?e===`running`?`Editing image`:e===`error`?`Image edit failed`:`Edited image`:e===`running`?`Generating image`:e===`error`?`Image generation failed`:`Generated image`}function iUe(e,t){let n=e?.[t];return n3(n)?n:void 0}function aUe(e){let t=(e.title??``).trim().toLowerCase(),n=n3(e.input)?e.input:void 0;if(V4(t,[`read`,`open`]))return{id:e.id,label:`Read ${H4(n)??J4(e.input)}`,status:Q4(e.status),input:e.input,output:e.output,error:e.error};if(V4(t,[`list`,`ls`,`glob`]))return{id:e.id,label:`List ${H4(n)??J4(e.input)}`,status:Q4(e.status),input:e.input,output:e.output,error:e.error};if(V4(t,[`search`,`find`,`grep`,`rg`])){let t=U4(n),r=H4(n);return{id:e.id,label:`Search ${t??J4(e.input)}${r?` in ${r}`:``}`,status:Q4(e.status),input:e.input,output:e.output,error:e.error}}}function B4(e){return sHe[e]??e}function V4(e,t){return t.some(t=>e===t||e.startsWith(`${t}_`)||e.endsWith(`_${t}`)||e.includes(t))}function H4(e){if(e)for(let t of[`path`,`file`,`filePath`,`filepath`,`url`,`uri`,`cwd`,`pattern`,`glob`]){let n=t3(e[t]);if(n)return n}}function U4(e){if(e)for(let t of[`query`,`pattern`,`text`,`name`,`q`,`regex`]){let n=t3(e[t]);if(n)return n}}function W4(e){return typeof e==`number`&&Number.isFinite(e)?e:void 0}function G4(e,t,n=`dim`,r=160){let i={lines:[],visibleLineCount:0,omittedLineCount:0,totalLineCount:0,maxVisibleLineCount:t},a=q4(e);if(!a)return i;let o=a.split(/\r?\n/).map(e=>e.trimEnd()).filter((e,t,n)=>e.length>0||n.length===1);if(!o.length)return i;let s=o.slice(0,t),c=Math.max(0,o.length-s.length),l=s.map((e,t)=>({prefix:t===0?`detail`:`continuation`,tokens:[e3(e,n)]}));return c>0&&l.push({prefix:`continuation`,tokens:[e3(`+${c} more lines`,`dim`,`normal`,!0)]}),{lines:l,visibleLineCount:s.length,omittedLineCount:c,totalLineCount:o.length,maxVisibleLineCount:t}}function K4(e,t){if(!(e.omittedLineCount<=0))return{source:t,visibleLineCount:e.visibleLineCount,omittedLineCount:e.omittedLineCount,totalLineCount:e.totalLineCount,maxVisibleLineCount:e.maxVisibleLineCount}}function q4(e){let t=e4(e);if(t!==void 0)return t.trim();if(typeof e==`string`)return e.trim();if(e==null)return``;try{return JSON.stringify(e,null,2)}catch{return String(e)}}function J4(e){return(typeof e==`string`?e:q4(e)).replace(/\s+/g,` `).trim()}function oUe(e){let t=(e??``).trim().toLowerCase();return t===`shell`||t===`bash`||t===`terminal`}function sUe(e){return(e??``).trim().toLowerCase()===`web_search`}function cUe(e,t){return t===`open_page`?e===`running`?`Opening web page`:e===`error`?`Opening web page failed`:`Opened web page`:t===`find_in_page`?e===`running`?`Finding in web page`:e===`error`?`Finding in web page failed`:`Found in web page`:e===`running`?`Searching web`:e===`error`?`Web search failed`:`Searched web`}function lUe(e){let t=n3(e.input)?e.input:void 0,n=n3(e.output)?e.output:void 0;return t3(t?.actionType)??t3(n?.actionType)}function uUe(e){let t=n3(e.input)?e.input:void 0,n=n3(e.output)?e.output:void 0;return t3(t?.query)??t3(n?.query)??t3(e.summary)}function dUe(e){let t=n3(e.input)?e.input:void 0,n=n3(e.output)?e.output:void 0;for(let e of[t?.queries,n?.queries]){if(!Array.isArray(e))continue;let t=[...new Set(e.flatMap(e=>{let t=t3(e)?.trim();return t?[t]:[]}))];if(t.length)return t}}function fUe(e){let t=n3(e.input)?e.input:void 0,n=n3(e.output)?e.output:void 0;return t3(t?.url)??t3(n?.url)}function pUe(e){let t=n3(e.input)?e.input:void 0,n=n3(e.output)?e.output:void 0;return t3(t?.pattern)??t3(n?.pattern)}function mUe(e){if(!n3(e))return[];let t=e.sources??e.citations??e.results;if(!Array.isArray(t))return[];let n=new Map;for(let e of t){let t=n3(e)?e:void 0,r=Y4(typeof e==`string`?e:t3(t?.url)??t3(t?.href)??t3(t?.link),!0);if(!r)continue;let i=t3(t?.title)?.trim()??t3(t?.name)?.trim(),a=n.get(r);(!a||!a.title&&i)&&n.set(r,{url:r,...i?{title:i}:{}})}return[...n.values()]}function hUe(e){if(!n3(e))return;let t=e.sourceCount??e.sourcesCount;if(typeof t==`number`&&Number.isFinite(t))return t;let n=e.sources??e.citations??e.results;return Array.isArray(n)?n.length:void 0}function Y4(e,t=!1){if(e)try{let n=new URL(e.trim());return n.protocol!==`https:`&&n.protocol!==`http:`||n.username||n.password?void 0:(t&&(n.hash=``),n.href)}catch{return}}function X4(e,t){let n=Y4(e);return{...e3(e,n?`blue`:`dim`),...n?{href:n,ariaLabel:t}:{}}}function Z4(e){if(n3(e))for(let t of[`cmd`,`command`,`script`]){let n=t3(e[t]);if(n)return n}}function gUe(e){let t=e.match(/\s+|"(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|[^\s]+/g)??[e],n=!1;return t.map(e=>/^\s+$/.test(e)?e3(e):/^(?:&&|\|\||[|;<>]|2>&1)$/.test(e)?e3(e,`red`,`semibold`):e.startsWith(`-`)?e3(e,`magenta`):e.startsWith(`$`)||e.includes(`=`)?e3(e,`yellow`):/^['"]/.test(e)?e3(e,`green`):n?e.includes(`/`)||e.startsWith(`.`)?e3(e,`cyan`):e3(e,`default`):(n=!0,e3(e,`green`,`semibold`)))}function _Ue(e){return e===`running`?`Calling`:e===`error`?`Call failed`:`Called`}function vUe(e){return e===`running`?`Spawning`:e===`error`?`Spawn failed`:`Spawned`}function yUe(e){if(e.status===`running`){if(e.id.startsWith(`event:message_steered:`))return`steer`;if(e.id.startsWith(`event:message_queued:`))return`queue`}}function bUe(e){return e===`running`?`Waiting for`:`Finished waiting for`}function Q4(e){return e===`running`?`running`:e===`error`?`error`:`done`}function $4(e){return e===`running`?`cyan`:e===`error`?`red`:e===`done`?`green`:`default`}function e3(e,t=`default`,n=`normal`,r=!1){return{text:e,tone:t,weight:n,italic:r}}function t3(e){return typeof e==`string`&&e.trim().length?e:void 0}function n3(e){return!!e&&typeof e==`object`&&!Array.isArray(e)}function xUe(e){if(!e)return;let t;if(typeof e==`string`)try{t=JSON.parse(e)}catch{return}else typeof e==`object`&&!Array.isArray(e)&&(t=e);if(!t)return;let n=typeof t.contextUsage==`object`&&t.contextUsage!==null?t.contextUsage:void 0,r=typeof t.providerUsage==`object`&&t.providerUsage!==null?t.providerUsage:void 0,i=Array.isArray(r?.limits)?r.limits.filter(e=>!!e&&typeof e==`object`&&!Array.isArray(e)).map(e=>{let t=typeof e.usedPercent==`number`?e.usedPercent:void 0,n=typeof e.remainingPercent==`number`?e.remainingPercent:t===void 0?0:Math.max(0,Math.min(100,100-t));return{label:typeof e.label==`string`?e.label:`limit`,usedPercent:t??0,remainingPercent:n,resetsAt:typeof e.resetsAt==`string`?e.resetsAt:void 0}}):[],a=typeof r?.credits==`object`&&r.credits!==null?r.credits:void 0;return{piboSessionId:typeof t.piboSessionId==`string`?t.piboSessionId:void 0,queuedMessages:typeof t.queuedMessages==`number`?t.queuedMessages:void 0,processing:typeof t.processing==`boolean`?t.processing:void 0,streaming:typeof t.streaming==`boolean`?t.streaming:void 0,enabledTools:Array.isArray(t.enabledTools)?t.enabledTools.filter(e=>typeof e==`string`):Array.isArray(t.activeTools)?t.activeTools.filter(e=>typeof e==`string`):void 0,activeTools:Array.isArray(t.activeTools)?t.activeTools.filter(e=>typeof e==`string`):void 0,enabledSkills:Array.isArray(t.enabledSkills)?t.enabledSkills.filter(e=>typeof e==`string`):void 0,contextFiles:Array.isArray(t.contextFiles)?t.contextFiles.filter(e=>typeof e==`string`):void 0,cwd:typeof t.cwd==`string`?t.cwd:void 0,disposed:typeof t.disposed==`boolean`?t.disposed:void 0,contextUsage:n?{tokens:typeof n.tokens==`number`?n.tokens:void 0,contextWindow:typeof n.contextWindow==`number`?n.contextWindow:void 0,percent:typeof n.percent==`number`?n.percent:void 0}:void 0,providerUsage:r&&(i.length>0||a)?{provider:typeof r.provider==`string`?r.provider:void 0,planType:typeof r.planType==`string`?r.planType:void 0,fetchedAt:typeof r.fetchedAt==`string`?r.fetchedAt:void 0,limits:i,credits:a?{unlimited:a.unlimited===!0,balance:typeof a.balance==`string`?a.balance:void 0}:void 0}:void 0}}function r3(e,t,n){return n?{id:e,label:t,value:n}:void 0}function i3({field:e,icon:t}){let n=t===`session`?Tc:bc;return(0,U.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[11px]`,"data-shared-status-field":e.id,children:[(0,U.jsx)(n,{size:11,className:`shrink-0 text-[#737373]`}),(0,U.jsxs)(`span`,{className:`shrink-0 text-[#737373]`,children:[e.label,`:`]}),(0,U.jsx)(`span`,{className:`truncate font-mono ${e.id===`session`?`text-[#38bdf8]`:`text-[#d4d4d4]`}`,children:e.value})]})}function a3({progress:e,label:t}){let n=e.percent??0,r=e.tone===`red`?`bg-[#ef4444]`:e.tone===`yellow`?`bg-[#facc15]`:e.tone===`cyan`?`bg-[#38bdf8]`:`bg-[#22c55e]`;return(0,U.jsxs)(`div`,{className:`mt-3 space-y-1`,"data-shared-progress":e.id,"data-shared-progress-state":e.state,children:[(0,U.jsxs)(`div`,{className:`flex items-center justify-between text-[11px]`,children:[(0,U.jsx)(`span`,{className:`text-[#737373]`,children:t??e.label}),(0,U.jsx)(`span`,{className:`font-mono text-[#d4d4d4]`,children:e.state===`available`?e.text:`unavailable`})]}),e.state===`available`?(0,U.jsx)(`div`,{className:`h-1.5 w-full overflow-hidden rounded-full bg-[#2a2a2a]`,children:(0,U.jsx)(`div`,{className:`h-full rounded-full ${r} transition-all`,style:{width:`${Math.min(Math.max(n,0),100)}%`}})}):null]})}function SUe(e){if(!e)return;let t=new Date(e);if(!Number.isNaN(t.getTime()))return t.toLocaleString(void 0,{weekday:`short`,hour:`2-digit`,minute:`2-digit`})}function o3({label:e,items:t}){let[n,r]=(0,H.useState)(!1),i=t.length===0;return(0,U.jsxs)(`div`,{children:[(0,U.jsxs)(`button`,{type:`button`,disabled:i,onClick:()=>r(e=>!e),className:`flex items-center gap-1.5 text-[11px] text-[#737373] hover:text-[#d4d4d4] disabled:cursor-default disabled:text-[#525252]`,"aria-expanded":n,children:[(0,U.jsx)(`span`,{className:i?`text-[#525252]`:`text-[#d4d4d4]`,children:n?`▾`:`▸`}),(0,U.jsxs)(`span`,{children:[e,` (`,t.length,`)`]})]}),n?(0,U.jsx)(`div`,{className:`mt-1.5 flex flex-wrap gap-1`,children:t.map(e=>(0,U.jsx)(`span`,{title:e,className:`inline-block max-w-full truncate rounded-sm border border-[#2a2a2a] bg-[#0b0b0b] px-1.5 py-0.5 font-mono text-[11px] text-[#a3a3a3]`,children:e},e))}):null]})}function CUe({row:e,piboSessionId:t}){let[n,r]=(0,H.useState)(null),i=n?.rowId===e.id&&Object.is(n.sourceOutput,e.output)?n.output:e.output,[a,o]=(0,H.useState)(!1),[s,c]=(0,H.useState)(null),l=xUe(i),u=x4(e),d=i===e.output?u:x4({...e,output:i}),f=d?.kind===`status`?d.statusView:void 0,p=async()=>{if(!(!t||a)){o(!0),c(null);try{r({rowId:e.id,sourceOutput:e.output,output:await Jl(t)})}catch(e){c(e instanceof Error?e.message:String(e))}finally{o(!1)}}},m=(0,U.jsx)(`button`,{type:`button`,disabled:!t||a,onClick:()=>void p(),className:`ml-auto inline-flex h-7 w-7 shrink-0 items-center justify-center border border-[#3a3a3a] bg-[#151f24] text-[#737373] transition hover:border-[#38bdf8] hover:text-[#38bdf8] disabled:cursor-not-allowed disabled:opacity-50`,"aria-label":`Refresh status`,"aria-busy":a,title:a?`Refreshing status`:`Refresh status`,"data-pibo-debug":`terminal-status-refresh`,children:(0,U.jsx)(ol,{size:13,className:a?`animate-spin`:void 0})});if(!l||!f)return(0,U.jsxs)(`div`,{className:`mt-2 border border-[#2a2a2a] bg-[#111111] px-3 py-2 text-[12px] text-[#d4d4d4]`,"data-pibo-component":`TerminalStatusCard`,"data-pibo-debug":`terminal-status-card`,"data-shared-terminal-card":`status`,children:[(0,U.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,U.jsx)(`div`,{className:`text-[#737373]`,children:`Status (unparseable)`}),m]}),s?(0,U.jsx)(`div`,{className:`mt-2 text-[11px] text-[#ef4444]`,role:`alert`,children:s}):null]});let h=new Map(f.fields.map(e=>[e.id,e])),g=h.get(`session`)??r3(`session`,`Session`,l.piboSessionId),_=h.get(`cwd`)??r3(`cwd`,`CWD`,l.cwd),v=f.progress.find(e=>e.id===`context`),y=f.progress.filter(e=>e.id.startsWith(`provider`)),b=l.providerUsage?.limits.length?l.providerUsage.limits:void 0,x=l.enabledTools??l.activeTools??[],S=l.enabledSkills??[],C=l.contextFiles??[],w=f.fields.filter(e=>!new Set([`session`,`cwd`]).has(e.id)),T=l.providerUsage?.provider?`${l.providerUsage.provider} quota`:`Provider quota`;return(0,U.jsxs)(`div`,{className:`mt-2 border border-[#2a2a2a] bg-[#111111] px-3 py-2 text-[12px] text-[#d4d4d4]`,"data-pibo-component":`TerminalStatusCard`,"data-pibo-debug":`terminal-status-card`,"data-shared-terminal-card":`status`,children:[(0,U.jsxs)(`div`,{className:`mb-2 flex items-center gap-2`,children:[(0,U.jsx)(Ds,{size:14,className:`text-[#22c55e]`}),(0,U.jsx)(`span`,{className:`font-semibold text-[#d4d4d4]`,children:f.title}),m]}),s?(0,U.jsx)(`div`,{className:`mb-2 text-[11px] text-[#ef4444]`,role:`alert`,children:s}):null,(0,U.jsxs)(`div`,{className:`grid grid-cols-1 gap-1.5 @min-[420px]:grid-cols-2`,children:[g?(0,U.jsx)(i3,{field:g,icon:`session`}):null,_?(0,U.jsx)(i3,{field:_,icon:`cwd`}):null,w.slice(0,8).map(e=>(0,U.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[11px]`,"data-shared-status-field":e.id,children:[(0,U.jsxs)(`span`,{className:`shrink-0 text-[#737373]`,children:[e.label,`:`]}),(0,U.jsx)(`span`,{className:`truncate font-mono text-[#d4d4d4]`,children:e.value})]},e.id))]}),(0,U.jsxs)(`div`,{className:`mt-2 flex flex-wrap gap-1.5`,children:[l.processing?(0,U.jsxs)(`span`,{className:`inline-flex items-center gap-1 border border-[#1f4960] px-1.5 py-0.5 text-[11px] text-[#38bdf8]`,children:[(0,U.jsx)(cc,{size:10}),` Processing`]}):null,l.streaming?(0,U.jsxs)(`span`,{className:`inline-flex items-center gap-1 border border-[#1f4960] px-1.5 py-0.5 text-[11px] text-[#38bdf8]`,children:[(0,U.jsx)(Ds,{size:10}),` Streaming`]}):null,typeof l.queuedMessages==`number`&&l.queuedMessages>0?(0,U.jsxs)(`span`,{className:`inline-flex items-center gap-1 border border-[#3a3a3a] px-1.5 py-0.5 text-[11px] text-[#d4d4d4]`,children:[(0,U.jsx)(kc,{size:10}),` Queued: `,l.queuedMessages]}):null,l.disposed?(0,U.jsx)(`span`,{className:`inline-flex items-center gap-1 border border-[#5f2222] px-1.5 py-0.5 text-[11px] text-[#ef4444]`,children:`Disposed`}):null]}),v?(0,U.jsx)(a3,{progress:v,label:`Context Usage`}):null,y.length?(0,U.jsxs)(`div`,{className:`mt-3 space-y-1.5 border-t border-[#2a2a2a] pt-2`,"data-shared-provider-progress":y.length,children:[(0,U.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[11px] text-[#737373]`,"data-shared-status-field":`provider-quota`,children:[(0,U.jsx)(xc,{size:11}),(0,U.jsxs)(`span`,{children:[T,l.providerUsage?.planType?` (${l.providerUsage.planType})`:``]})]}),b?b.map(e=>{let t=SUe(e.resetsAt);return(0,U.jsxs)(`div`,{className:`space-y-1`,"data-shared-progress":`provider-limit:${e.label}`,"data-shared-progress-state":`available`,children:[(0,U.jsxs)(`div`,{className:`flex items-center justify-between gap-2 text-[11px]`,children:[(0,U.jsx)(`span`,{className:`text-[#a3a3a3]`,children:e.label}),(0,U.jsxs)(`span`,{className:`shrink-0 font-mono text-[#d4d4d4]`,children:[e.remainingPercent.toFixed(0),`% left`,t?` · resets ${t}`:``]})]}),(0,U.jsx)(`div`,{className:`h-1.5 w-full overflow-hidden rounded-full bg-[#2a2a2a]`,children:(0,U.jsx)(`div`,{className:`h-full rounded-full bg-[#38bdf8] transition-all`,style:{width:`${Math.min(Math.max(e.remainingPercent,0),100)}%`}})})]},`${e.label}-${e.resetsAt??``}`)}):y.map(e=>(0,U.jsx)(a3,{progress:e},e.id)),l.providerUsage?.credits?(0,U.jsxs)(`div`,{className:`text-[11px] text-[#a3a3a3]`,"data-shared-status-field":`provider-credits`,children:[`Credits: `,l.providerUsage.credits.unlimited?`unlimited`:l.providerUsage.credits.balance??`available`]}):null]}):null,f.warnings.length||f.errors.length?(0,U.jsxs)(`div`,{className:`mt-3 space-y-1 border-t border-[#2a2a2a] pt-2`,children:[f.warnings.map((e,t)=>(0,U.jsxs)(`div`,{"data-shared-status-warning":!0,className:`text-[11px] text-[#facc15]`,children:[`⚠ `,e]},`warning-${t}`)),f.errors.map((e,t)=>(0,U.jsxs)(`div`,{"data-shared-status-error":!0,className:`text-[11px] text-[#ef4444]`,children:[`✕ `,e]},`error-${t}`))]}):null,(0,U.jsxs)(`div`,{className:`mt-3 space-y-1.5`,children:[(0,U.jsx)(o3,{label:`Enabled tools`,items:x}),(0,U.jsx)(o3,{label:`Enabled skills`,items:S}),(0,U.jsx)(o3,{label:`Context files`,items:C})]})]})}function wUe(e){let t;if(typeof e==`string`)try{t=JSON.parse(e)}catch{return}else e&&typeof e==`object`&&!Array.isArray(e)&&(t=e);if(t)return{level:typeof t.level==`string`?t.level:void 0,availableLevels:Array.isArray(t.availableLevels)?t.availableLevels.filter(e=>typeof e==`string`):[],supported:typeof t.supported==`boolean`?t.supported:void 0}}function TUe(e){return Zq.includes(e)?e:void 0}function EUe({row:e,onLevelSelect:t}){let n=wUe(e.output);return n?(0,U.jsxs)(`div`,{className:`mt-2 border border-[#2a2a2a] bg-[#111111] px-3 py-2 text-[12px] text-[#d4d4d4]`,"data-shared-terminal-card":`thinking`,children:[(0,U.jsxs)(`div`,{className:`mb-2 flex items-center gap-2`,children:[(0,U.jsx)(Bs,{size:14,className:`text-[#f59e0b]`}),(0,U.jsx)(`span`,{className:`font-semibold text-[#d4d4d4]`,children:`Thinking`}),n.supported===!1?(0,U.jsxs)(`span`,{className:`ml-auto inline-flex items-center gap-1 border border-[#5f2222] px-1.5 py-0.5 text-[11px] text-[#ef4444]`,children:[(0,U.jsx)(jl,{size:10}),` Unsupported`]}):(0,U.jsxs)(`span`,{className:`ml-auto inline-flex items-center gap-1 border border-[#1f4960] px-1.5 py-0.5 text-[11px] text-[#38bdf8]`,children:[(0,U.jsx)(Ws,{size:10}),` Supported`]})]}),(0,U.jsxs)(`div`,{className:`grid gap-1.5 text-[11px]`,children:[(0,U.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,U.jsx)(`span`,{className:`text-[#737373]`,children:`Current:`}),(0,U.jsx)(`span`,{className:`font-mono font-semibold text-[#f59e0b]`,children:n.level??`unknown`})]}),n.availableLevels.length?(0,U.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[(0,U.jsx)(`span`,{className:`mr-1 text-[#737373]`,children:`Available:`}),n.availableLevels.map(e=>{let r=TUe(e),i=n.supported===!1||!r||!t;return(0,U.jsx)(`button`,{type:`button`,disabled:i,onClick:()=>{r&&t?.(r)},className:`border bg-transparent px-1.5 py-0.5 ${e===n.level?`border-[#f59e0b] text-[#f59e0b]`:`border-[#3a3a3a] text-[#d4d4d4]`} ${i?`cursor-default`:`cursor-pointer`}`,children:e},e)})]}):null,(0,U.jsxs)(`div`,{className:`text-[#737373]`,children:[`Click a level or use `,(0,U.jsx)(`span`,{className:`text-[#f59e0b]`,children:`/thinking <level>`}),`.`]})]})]}):(0,U.jsx)(`div`,{className:`mt-2 border border-[#2a2a2a] bg-[#111111] px-3 py-2 text-[12px] text-[#d4d4d4]`,"data-shared-terminal-card":`thinking`,children:(0,U.jsx)(`div`,{className:`text-[#737373]`,children:`Thinking (unparseable)`})})}var s3=`pibo.chat.terminalReadingPosition.`;function DUe(e){if(e)try{return OUe(sessionStorage.getItem(s3+e))}catch{return}}function c3(e,t){if(e)try{let n=s3+e;t?sessionStorage.setItem(n,JSON.stringify(t)):sessionStorage.removeItem(n)}catch{}}function OUe(e){if(e)try{let t=JSON.parse(e);return typeof t.rowId!=`string`||!t.rowId||typeof t.offsetPx!=`number`||!Number.isFinite(t.offsetPx)?void 0:{rowId:t.rowId,offsetPx:t.offsetPx}}catch{return}}var kUe=180,AUe=4800,jUe=800,MUe=20,NUe={top:2400,bottom:2400},PUe=84,FUe=6;function IUe({traceView:e,isLoading:t,terminalFullscreen:n,showThinking:r,debugMode:i=!1,toolMetricThresholds:a,expandThinking:o,toolDisplayMode:s,sessionAgentProfile:c,sessionActiveModel:l,sessionRuntimeBinding:u,selectedSessionStatus:d,selectedSessionSignal:f,signals:p,sessionGoal:m,sessionBreadcrumbs:h,originSession:g,derivedSessions:_,agentProfiles:v,sessionProfileChangeDisabled:y,onSessionAgentProfileChange:b,onFork:x,onOpenSession:S,onLoadOlderTracePage:C,hasOlderTraceEvents:w,isFetchingOlderTracePage:T,onThinkingLevelChange:E,onModelChanged:D}){let O=(0,H.useMemo)(()=>cHe(e,{showThinking:r,toolDisplayMode:s,debugMode:i}),[r,s,i,e]),k=(0,H.useMemo)(()=>O.map(e=>e.id),[O]),A=e?.piboSessionId??``,[j,M]=(0,H.useState)(),N=(0,H.useRef)(void 0),[P,F]=(0,H.useState)(new Set),[I,L]=(0,H.useState)(null),R=(0,H.useMemo)(()=>[O,P],[P,O]),[z,ee]=(0,H.useState)(null),te=(0,H.useRef)({}),ne=(0,H.useRef)(!1),re=(0,H.useRef)(!1),ie=(0,H.useRef)(!1),B=(0,H.useRef)(!1),ae=(0,H.useRef)(!1),oe=(0,H.useRef)(()=>void 0),se=O.filter(e=>m3(e,`user`)).length,ce=O.filter(e=>m3(e,`tool`)).length,le=O.filter(e=>m3(e,`system`)).length,ue=uVe({signal:f,fallbackStatus:d,fallbackTurnStartedAt:(0,H.useMemo)(()=>uHe(e),[e])}),de=ue.activeTurnStartedAt,fe=ue.isTurnActive,pe=!!q2(m);(0,H.useLayoutEffect)(()=>{!A||!e||!oX()||xPe(A,`compact-terminal:render`,O,{traceVersion:e.version,latestStreamId:e.latestStreamId,lastRawEventId:e.rawEvents.at(-1)?.id,selectedSessionStatus:d})},[A,O,d,e]);let me=(0,H.useCallback)(()=>{if(!w||T||ie.current)return;if(B.current){ae.current=!0;return}ie.current=!0,re.current=!1,oe.current();let e=C?.();Promise.resolve(e).then(()=>{ie.current=!1},()=>{ie.current=!1})},[w,T,C]),he=(0,H.useCallback)(()=>{ne.current&&re.current&&me()},[me]),ge=(0,H.useCallback)(()=>{ne.current&&(!re.current&&!B.current||me())},[me]),_e=(0,H.useCallback)(e=>{B.current=e,!(e||!ae.current)&&(ae.current=!1,me())},[me]),ve=(0,H.useCallback)((e,t)=>{tWe(e,t)&&(re.current=!0)},[]),ye=(0,H.useCallback)(e=>{!ne.current||s!=="default"||e.startIndex<=MUe&&he()},[he,s]),be=(0,H.useCallback)(e=>{A&&c3(A,e?{rowId:e.key,offsetPx:e.offset}:void 0)},[A]),xe=s==="default"?AUe:jUe,Se=yBe({itemCount:O.length,itemKeys:k,isPrepending:T,resetKey:e?.piboSessionId,contentKey:R,atBottomThreshold:kUe,nearTopThreshold:xe,onAtTop:ge,onNearTop:he,onUserScrollIntent:ve,onScrollbarDragChange:_e,onVisibleAnchorChange:be});oe.current=Se.prepareForPrepend,(0,H.useEffect)(()=>{N.current=void 0,ie.current=!1,B.current=!1,ae.current=!1,M(A?DUe(A):void 0),L(null)},[A]),(0,H.useEffect)(()=>{if(!A||!j)return;let t=k.indexOf(j.rowId);if(t>=0){let e=requestAnimationFrame(()=>{Se.restoreAnchor({key:j.rowId,dataIndex:t,offset:j.offsetPx})&&M(void 0)});return()=>cancelAnimationFrame(e)}if(!w){c3(A,void 0),M(void 0);return}if(T)return;let n=String(e?.nextBeforeCursor??e?.nextBeforeSequence??O.length),r=`${A}:${n}`;N.current!==r&&(N.current=r,C?.())},[w,T,C,A,j,k,O.length,Se.restoreAnchor,e?.nextBeforeCursor,e?.nextBeforeSequence]),(0,H.useEffect)(()=>{if(!A)return;let e=()=>{Se.captureVisibleAnchor()},t=()=>{document.visibilityState===`hidden`&&e()};return window.addEventListener(`beforeunload`,e),window.addEventListener(`pagehide`,e),document.addEventListener(`visibilitychange`,t),()=>{window.removeEventListener(`beforeunload`,e),window.removeEventListener(`pagehide`,e),document.removeEventListener(`visibilitychange`,t)}},[A,Se.captureVisibleAnchor]),(0,H.useEffect)(()=>{F(e=>UUe(e,O,o))},[o,O]),(0,H.useEffect)(()=>{ne.current=!1,re.current=!1;let e=window.setTimeout(()=>{ne.current=!0},250);return()=>window.clearTimeout(e)},[e?.piboSessionId]),(0,H.useEffect)(()=>{let e=new Set(O.map(e=>e.id));ee(t=>t&&e.has(t)?t:null);for(let t of[`system`,`tool`,`user`]){let n=te.current[t];n&&!e.has(n)&&delete te.current[t]}},[O]);let Ce=(0,H.useCallback)(e=>{let t=WUe(O,e,te.current[e]);t&&(te.current[e]=t.row.id,ee(t.row.id),Se.scrollToIndex(t.index,`start`,`fast-smooth`,{fromIndex:t.fromIndex,stagingAlign:e===`tool`?`end`:void 0}),GUe(t.row.id))},[O,Se]),we=e=>{e.expandable&&F(t=>{let n=new Set(t);return n.has(e.id)?n.delete(e.id):n.add(e.id),n})},Te=(0,H.useCallback)(e=>{let t=f3(e);t.length&&L({images:t,index:0})},[]),V=(0,H.useCallback)((t,n)=>(0,U.jsx)(`div`,{className:`px-4 @max-[420px]:px-2`,children:(0,U.jsx)(RUe,{row:n,debugMode:i,toolMetricThresholds:a,expanded:P.has(n.id),focused:z===n.id,piboSessionId:e?.piboSessionId??``,onToggle:()=>we(n),onFork:x,onOpenSession:S,onThinkingLevelChange:E,onModelChanged:D,onViewImages:Te,signals:p})}),[i,P,z,x,D,S,E,Te,p,a,e?.piboSessionId]),Ee=(0,H.useMemo)(()=>({Footer:fe||pe?()=>(0,U.jsx)(g3,{startedAt:de,isWorking:fe,goal:m}):void 0}),[de,fe,m,pe]);return(0,U.jsxs)(`section`,{className:`relative min-w-0 flex-1 flex flex-col overflow-hidden bg-[#0b0b0b] text-[#d4d4d4]`,"data-pibo-component":`CompactTerminalSessionView`,"data-pibo-debug":`compact-terminal-session-view`,"data-pibo-session-id":e?.piboSessionId??void 0,"data-pibo-terminal-fullscreen":n?`true`:`false`,"data-pibo-trace-has-older":e?.hasOlderEvents===!0?`true`:`false`,"data-pibo-trace-next-before":e?.nextBeforeCursor??e?.nextBeforeSequence??``,children:[n?null:(0,U.jsx)(LUe,{errorCount:le,toolErrorCount:ce,userMessageCount:se,onNavigate:Ce,sessionAgentProfile:c,sessionActiveModel:l,sessionRuntimeBinding:u,sessionBreadcrumbs:h,originSession:g,derivedSessions:_,onOpenSession:S}),(0,U.jsx)(`div`,{className:`min-h-0 flex-1 overflow-hidden`,children:e?O.length?(0,U.jsx)(jze,{ref:Se.virtuosoRef,data:O,firstItemIndex:Se.firstItemIndex,increaseViewportBy:NUe,defaultItemHeight:PUe,className:`min-h-0 h-full overflow-x-hidden font-mono text-[12px] leading-[1.45]`,computeItemKey:(e,t)=>t.id,scrollerRef:Se.scrollerRef,atBottomStateChange:Se.atBottomStateChange,atBottomThreshold:Se.atBottomThreshold,itemsRendered:Se.itemsRendered,rangeChanged:e=>ye(Se.normalizeRange(e)),followOutput:Se.followOutput,totalListHeightChanged:Se.totalListHeightChanged,alignToBottom:!0,components:Ee,itemContent:V}):(0,U.jsx)(C3,{isLoading:t,agentProfiles:v,disabled:y,onSelectAgentProfile:b,message:`No visible trace rows yet.`}):(0,U.jsx)(C3,{isLoading:t,agentProfiles:v,disabled:y,onSelectAgentProfile:b})}),O.length===0&&pe?(0,U.jsx)(g3,{isWorking:!1,goal:m}):null,I?(0,U.jsx)(HUe,{state:I,piboSessionId:A,onClose:()=>L(null),onIndexChange:e=>L(t=>t?{...t,index:Math.min(Math.max(e,0),t.images.length-1)}:null)}):null,Se.isSticky?null:(0,U.jsx)(`button`,{type:`button`,onClick:()=>{c3(A,void 0),Se.stickToBottom(`auto`)},title:`Scroll to latest`,"aria-label":`Scroll to latest`,className:`absolute right-4 bottom-4 z-30 inline-flex h-9 w-9 items-center justify-center rounded-sm border border-[#38bdf8] bg-[#111111]/95 text-[#38bdf8] shadow-lg shadow-black/30 hover:bg-[#161616]`,children:(0,U.jsx)(Gs,{size:18})})]})}function LUe({errorCount:e,toolErrorCount:t,userMessageCount:n,onNavigate:r,sessionAgentProfile:i,sessionActiveModel:a,sessionRuntimeBinding:o,sessionBreadcrumbs:s,originSession:c,derivedSessions:l,onOpenSession:u}){return(0,U.jsxs)(`div`,{"data-pibo-debug":`compact-terminal-header`,className:`border-b border-[#2a2a2a] bg-[#111111] px-4 py-2 text-[11px] @max-[420px]:px-2`,children:[(0,U.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[i?(0,U.jsx)(x3,{tone:`neutral`,children:i}):null,o?(0,U.jsxs)(x3,{tone:o.state===`missing`||o.state===`error`?`red`:o.state===`unbound`?`amber`:`cyan`,label:`Runtime ${o.runtimeInstanceId} · ${o.state}`,children:[o.runtimeInstanceId,` · `,o.state]}):null,a?(0,U.jsx)(x3,{tone:`purple`,children:a}):null,n>0?(0,U.jsxs)(x3,{tone:`cyan`,label:`${n} user messages · jump to previous user message`,onClick:()=>r(`user`),children:[n,(0,U.jsx)(Vc,{size:12})]}):null,e>0?(0,U.jsxs)(x3,{tone:`red`,label:`${e} errors · jump to previous error`,onClick:()=>r(`system`),children:[e,(0,U.jsx)(rc,{size:12})]}):null,t>0?(0,U.jsxs)(x3,{tone:`amber`,label:`${t} tool call errors · jump to previous tool error`,onClick:()=>r(`tool`),children:[t,(0,U.jsx)(wc,{size:12})]}):null,c?(0,U.jsxs)(l3,{onClick:()=>u(c.piboSessionId),children:[`Origin `,c.label]}):null,l.map(e=>(0,U.jsxs)(l3,{onClick:()=>u(e.piboSessionId),children:[`Derived `,e.label]},e.piboSessionId))]}),s.length?(0,U.jsx)(`div`,{className:`mt-2 flex flex-wrap items-center gap-1 text-[#737373]`,children:s.map((e,t)=>(0,U.jsxs)(`div`,{className:`flex items-center gap-1`,children:[t>0?(0,U.jsx)(qs,{size:12,className:`text-[#525252]`}):null,(0,U.jsx)(`button`,{type:`button`,onClick:()=>u(e.piboSessionId),className:`hover:text-[#38bdf8]`,children:e.label})]},e.piboSessionId))}):null]})}function l3({children:e,onClick:t}){return(0,U.jsx)(`button`,{type:`button`,onClick:t,className:`border border-[#3a3a3a] px-2 py-0.5 text-[#38bdf8] hover:border-[#38bdf8]`,children:e})}function RUe({row:e,debugMode:t,toolMetricThresholds:n,expanded:r,focused:i,piboSessionId:a,onToggle:o,onFork:s,onOpenSession:c,onThinkingLevelChange:l,onModelChanged:u,onViewImages:d,signals:f}){let p=!r&&qUe(e),m=p?KUe(e):e.lines;return e.kind===`agent.delegation`?(0,U.jsxs)(`div`,{className:p3(e,i),"data-pibo-component":`TerminalRow`,"data-pibo-debug":`terminal-row`,"data-pibo-terminal-row":`true`,"data-row-id":e.id,"data-row-kind":e.kind,"data-row-status":e.status,"data-trace-node-id":e.sourceNodeIds.join(` `),"data-event-id":e.eventId,"data-run-id":e.runId,"data-order-source":e.orderSource,"data-order-stream-id":e.orderStreamId,"data-order-frame-index":e.orderStreamFrameIndex,tabIndex:i?0:void 0,"aria-current":i?`true`:void 0,children:[(0,U.jsx)(A2,{title:e.title,summary:e.summary,input:e.input,output:e.output,error:e.error,traceStatus:e.status===`neutral`?`done`:e.status,linkedPiboSessionId:e.linkedPiboSessionId,startedAt:e.startedAt,completedAt:e.completedAt,durationMs:e.durationMs,signals:f,onOpenSession:c}),t&&e.isToolCall?(0,U.jsx)(Q2,{metrics:e.toolMetrics,thresholds:n}):null]}):(0,U.jsxs)(`div`,{className:p3(e,i),"data-pibo-component":`TerminalRow`,"data-pibo-debug":`terminal-row`,"data-pibo-terminal-row":`true`,"data-row-id":e.id,"data-row-kind":e.kind,"data-row-status":e.status,"data-trace-node-id":e.sourceNodeIds.join(` `),"data-event-id":e.eventId,"data-run-id":e.runId,"data-order-source":e.orderSource,"data-order-stream-id":e.orderStreamId,"data-order-frame-index":e.orderStreamFrameIndex,onDoubleClick:e.expandable?t=>{!e.expandable||h3(t)||o()}:void 0,onKeyDown:e.expandable?t=>{!e.expandable||h3(t)||(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),o())}:void 0,role:e.expandable?`button`:void 0,tabIndex:e.expandable||i?0:void 0,"aria-expanded":e.expandable?r:void 0,"aria-current":i?`true`:void 0,children:[(0,U.jsxs)(`div`,{className:`flex gap-3`,children:[(0,U.jsx)(`div`,{className:`min-w-0 flex-1`,children:(0,U.jsx)(zUe,{row:e,visibleLines:m,collapseToolCallPreview:p,piboSessionId:a,onThinkingLevelChange:l,onModelChanged:u,onFork:s})}),(0,U.jsx)(VUe,{row:e,onOpenSession:c,onViewImages:d})]}),r?(0,U.jsx)(CVe,{row:e,onOpenSession:c}):null,t&&e.isToolCall?(0,U.jsx)(Q2,{metrics:e.toolMetrics,thresholds:n}):null]})}function zUe({row:e,visibleLines:t,collapseToolCallPreview:n,piboSessionId:r,onThinkingLevelChange:i,onModelChanged:a,onFork:o}){return e.kind===`message.assistant`?(0,U.jsxs)(`div`,{className:`ml-[1.9rem] min-w-0`,"data-pibo-component":`TerminalAssistantMessage`,children:[(0,U.jsx)(`div`,{className:`compact-terminal-markdown`,"data-pibo-component":`MarkdownRendererHost`,"data-pibo-markdown-kind":`assistant-message`,children:(0,U.jsx)(nG,{streaming:e.status===`running`,children:typeof e.output==`string`?e.output:``})}),e.status===`running`?null:(0,U.jsx)(d3,{timestamp:e.completedAt,durationMs:e.durationMs,speechText:typeof e.output==`string`?e.output:void 0,speechScopeKey:`${r}:${e.id}`})]}):e.kind===`message.user`?(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(u3,{lines:t,status:e.status,clampPreview:n,singleLine:e.singleLine}),e.pendingMessageDelivery?(0,U.jsx)(I2,{delivery:e.pendingMessageDelivery,className:`ml-[1.9rem] mt-2`}):null,(0,U.jsx)(d3,{timestamp:e.startedAt,forkEntryId:e.forkEntryId,onFork:o})]}):e.kind===`tool.status`?(0,U.jsx)(CUe,{row:e,piboSessionId:r}):e.kind===`tool.thinking`?(0,U.jsx)(EUe,{row:e,onLevelSelect:i}):e.kind===`tool.login`?(0,U.jsx)(VVe,{row:e,piboSessionId:r}):e.kind===`tool.model`?(0,U.jsx)(GVe,{row:e,piboSessionId:r,onModelChanged:a}):e.kind===`execution.compaction`&&e.status===`running`?(0,U.jsx)(QUe,{}):e.kind===`reasoning`&&e.markdown?(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(u3,{lines:t,status:e.status,clampPreview:n,singleLine:e.singleLine}),(0,U.jsx)(`div`,{className:`ml-[1.9rem] min-w-0`,"data-pibo-component":`TerminalReasoningMarkdown`,children:(0,U.jsx)(`div`,{className:`compact-terminal-markdown compact-terminal-reasoning`,"data-pibo-component":`MarkdownRendererHost`,"data-pibo-markdown-kind":`reasoning`,children:(0,U.jsx)(nG,{streaming:e.status===`running`,children:e.markdown})})})]}):(0,U.jsx)(u3,{lines:t,status:e.status,clampPreview:n,singleLine:e.singleLine})}function u3({lines:e,status:t,clampPreview:n,singleLine:r}){return e.map((e,i)=>(0,U.jsx)(MVe,{line:e,status:t,clampLines:r?1:n&&i===0?5:void 0},i))}function d3({timestamp:e,durationMs:t,forkEntryId:n,onFork:r,speechText:i,speechScopeKey:a}){let o=BUe(e);return!o&&!n&&!i?.trim()?null:(0,U.jsxs)(`div`,{className:`mt-1 flex items-center justify-end gap-1 font-mono text-[10px] tabular-nums text-[#737373]`,"data-pibo-component":`TerminalMessageMetadata`,children:[n&&r?(0,U.jsx)(oVe,{entryId:n,onFork:r}):null,i?.trim()?(0,U.jsx)(F2,{text:i,scopeKey:a}):null,o?(0,U.jsxs)(`span`,{children:[o,t===void 0?null:` · ${A4(t)}`]}):null]})}function BUe(e){if(!e)return;let t=new Date(e);if(Number.isFinite(t.getTime()))return new Intl.DateTimeFormat(void 0,{hour:`2-digit`,minute:`2-digit`,hourCycle:`h23`}).format(t)}function VUe({row:e,onOpenSession:t,onViewImages:n}){let r=f3(e.imagePreviews??[]);return!e.linkedPiboSessionId&&r.length===0?null:(0,U.jsxs)(`div`,{className:`flex shrink-0 items-start gap-1`,children:[r.length?(0,U.jsxs)(S3,{label:r.length===1?`View image preview`:`View ${r.length} image previews`,onClick:()=>n(r),children:[(0,U.jsx)(Ec,{size:13,"aria-hidden":`true`}),` View`]}):null,e.linkedPiboSessionId?(0,U.jsx)(S3,{label:`Open linked session`,onClick:()=>t(e.linkedPiboSessionId),children:`Open`}):null]})}function HUe({state:e,piboSessionId:t,onClose:n,onIndexChange:r}){let i=e.images[e.index],a=i?fu(i,t)[0]:void 0,[o,s]=(0,H.useState)(`loading`),c=(0,H.useRef)(null),l=e.index>0,u=e.index+1<e.images.length;(0,H.useEffect)(()=>s(a?`loading`:`error`),[i?.id,a]);let d=t=>{t<0||t>=e.images.length||(r(t),window.requestAnimationFrame(()=>c.current?.focus()))};return(0,U.jsx)(iX,{title:`Image preview`,description:`${i?.label??`Image`} · ${e.index+1} of ${e.images.length}`,onClose:n,initialFocusRef:c,onKeyDown:t=>{if(t.key===`ArrowLeft`&&l)d(e.index-1);else if(t.key===`ArrowRight`&&u)d(e.index+1);else if(t.key===`Home`&&l)d(0);else if(t.key===`End`&&u)d(e.images.length-1);else return;t.preventDefault()},closeLabel:`Close image preview`,maxWidthClassName:`max-w-6xl`,children:(0,U.jsxs)(`div`,{ref:c,tabIndex:-1,className:`flex min-h-[12rem] flex-col bg-[#0b0b0b] outline-none sm:min-h-[18rem]`,"data-pibo-component":`TerminalImageDialog`,children:[(0,U.jsxs)(`div`,{className:`relative flex min-h-0 flex-1 items-center justify-center overflow-auto p-2 sm:p-4`,children:[a?(0,U.jsx)(`img`,{src:a,alt:`Tool image: ${i?.label??`image preview`}`,loading:`lazy`,decoding:`async`,onLoad:()=>s(`loaded`),onError:()=>s(`error`),className:`max-h-[calc(100dvh-12rem)] max-w-full object-contain ${o===`loaded`?`block`:`invisible`}`},a):null,o===`loading`?(0,U.jsx)(`div`,{className:`absolute inset-0 grid place-items-center text-xs text-[#a3a3a3]`,role:`status`,children:`Loading image preview…`}):null,o===`error`?(0,U.jsx)(`div`,{className:`absolute inset-0 grid place-items-center px-6 text-center text-xs text-[#f87171]`,role:`alert`,children:`Image preview is unavailable.`}):null]}),(0,U.jsxs)(`div`,{className:`flex items-center justify-between gap-3 border-t border-[#2a2a2a] px-3 py-2`,children:[(0,U.jsxs)(S3,{label:`Previous image`,onClick:()=>d(e.index-1),disabled:!l,children:[(0,U.jsx)(Ks,{size:14,"aria-hidden":`true`}),` Previous`]}),(0,U.jsxs)(`span`,{className:`text-[11px] tabular-nums text-[#a3a3a3]`,"aria-live":`polite`,children:[e.index+1,` / `,e.images.length]}),(0,U.jsxs)(S3,{label:`Next image`,onClick:()=>d(e.index+1),disabled:!u,children:[`Next `,(0,U.jsx)(qs,{size:14,"aria-hidden":`true`})]})]})]})})}function f3(e){return e.filter(e=>!!(e.payloadRef?e.traceNodeId:e.generatedToolCallId||e.path)).slice(0,20)}function p3(e,t=!1){let n=e.kind===`message.user`?`group border-b border-[#141414] bg-[#11a4d4]/10 py-2 last:border-b-0 hover:bg-[#11a4d4]/15`:e.kind===`agent.delegation`?`group border-b border-[#141414] bg-[#f97316]/5 py-2 last:border-b-0`:e.kind===`execution.command`?`group border-b border-[#141414] bg-[#f59e0b]/5 py-2 last:border-b-0 hover:bg-[#f59e0b]/10`:`group border-b border-[#141414] py-2 last:border-b-0 hover:bg-[#161616]`,r=e.expandable||t?` focus:outline-none focus:ring-1 focus:ring-[#38bdf8]/50`:``;return t?`${n}${r} ring-1 ring-[#38bdf8] bg-[#123040]`:`${n}${r}`}function UUe(e,t,n){let r=new Set;for(let i of t)e.has(i.id)&&r.add(i.id),n&&i.kind===`reasoning`&&i.expandable&&r.add(i.id);return eWe(e,r)?e:r}function m3(e,t){return t===`user`?e.kind===`message.user`:e.status===`error`?t===`tool`?e.errorKind===`tool`:e.errorKind!==`tool`:!1}function WUe(e,t,n){let r=e.map((e,t)=>({row:e,index:t})).filter(({row:e})=>m3(e,t));if(!r.length)return;let i=n?e.findIndex(e=>e.id===n):-1,a=i>=0?i:e.length;return{...r.filter(e=>e.index<a).at(-1)??r[r.length-1],fromIndex:a}}function GUe(e){let t=0,n=()=>{let r=Array.from(document.querySelectorAll(`[data-pibo-component="TerminalRow"]`)).find(t=>t.dataset.rowId===e);if(r){r.scrollIntoView({block:`start`,inline:`nearest`,behavior:`smooth`}),r.focus({preventScroll:!0});return}t+=1,t<8&&requestAnimationFrame(n)};requestAnimationFrame(()=>requestAnimationFrame(n))}function KUe(e){return e.kind===`tool.group.exploring`||e.kind===`tool.group.images`?e.lines.slice(0,FUe):e.lines}function qUe(e){return!!e.expandable&&(e.kind===`tool.call`||e.kind===`tool.image`||e.kind===`tool.group.exploring`||e.kind===`tool.group.images`||e.kind===`agent.delegation`||e.kind===`agent.async`||e.kind===`yielded.run`||e.kind===`execution.command`||e.kind===`execution.compaction`)}function h3(e){let t=e.target;if(!(t instanceof Element)||t===e.currentTarget)return!1;let n=t.closest(`button, a, input, textarea, select, summary, [role='button'], [tabindex]:not([tabindex='-1'])`);return!!(n&&n!==e.currentTarget)}var JUe=`Working...`,YUe=33;function g3({startedAt:e,isWorking:t,goal:n}){let r=ZUe(t?e:void 0),{chars:i,activeIndex:a}=XUe(JUe,t),o=q2(n),s=n&&o===`active`?J2(n):void 0,c=[t?`Working`:void 0,o===`active`?`Pursuing Goal`:o===`paused`?`Goal Paused`:void 0,s?`Tokens ${s}`:void 0].filter(Boolean).join(`. `);return(0,U.jsx)(`div`,{className:`border-t border-[#141414] px-4 py-2 @max-[420px]:px-2`,role:`status`,"aria-live":`polite`,"aria-label":c,"data-pibo-component":`TerminalStreamingFooter`,"data-pibo-active-turn-started-at":t?e:void 0,children:(0,U.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-baseline justify-between gap-x-4 gap-y-1`,"aria-hidden":`true`,children:[t?(0,U.jsxs)(`div`,{className:`grid min-w-0 flex-1 grid-cols-[1.9rem_minmax(0,1fr)] gap-2 whitespace-pre-wrap break-words`,children:[(0,U.jsx)(`span`,{className:`whitespace-pre text-[#737373]`,children:`•`}),(0,U.jsxs)(`span`,{className:`inline-flex min-w-0 items-baseline gap-2`,children:[r?(0,U.jsx)(`span`,{className:`shrink-0 tabular-nums text-[#737373]`,children:r}):null,(0,U.jsx)(`span`,{className:`compact-terminal-working-scramble`,children:i.map((e,t)=>(0,U.jsx)(`span`,{className:t===a?`compact-terminal-working-scramble-active`:void 0,children:e},t))})]})]}):(0,U.jsx)(`span`,{className:`min-w-0 flex-1`}),(0,U.jsx)(dVe,{goal:n})]})})}function XUe(e,t){let n=(0,H.useMemo)(()=>Array.from(e),[e]),[r,i]=(0,H.useState)(()=>n),[a,o]=(0,H.useState)(-1);return(0,H.useEffect)(()=>{if(!t||window.matchMedia(`(prefers-reduced-motion: reduce)`).matches){i(n),o(-1);return}let e=0,r=0,a=b3(),s=0;i(v3(n)),o(0);let c=window.setInterval(()=>{if(s>0){s--;return}if(e>=n.length){e=0,r=0,a=b3(),i(v3(n)),o(0);return}let t=e,c=n[t]??` `;if(o(t),r++,r<a){i(e=>_3(e,t,y3(c)));return}i(e=>_3(e,t,c)),e++,r=0,a=b3(),e>=n.length&&(i(n),o(-1),s=18)},55);return()=>window.clearInterval(c)},[t,n]),{chars:r,activeIndex:a}}function _3(e,t,n){let r=[...e];return r[t]=n,r}function v3(e){return e.map(e=>y3(e))}function y3(e){let t=``;do{let e=YUe+Math.floor(Math.random()*94);t=String.fromCharCode(e)}while(t===e);return t}function b3(){return 2+Math.floor(Math.random()*11)}function ZUe(e){let t=e?new Date(e).getTime():NaN,[n,r]=(0,H.useState)(()=>Date.now());return(0,H.useEffect)(()=>{if(r(Date.now()),!Number.isFinite(t))return;let e=window.setInterval(()=>r(Date.now()),1e3);return()=>window.clearInterval(e)},[t]),Number.isFinite(t)?A4(Math.max(0,n-t)):void 0}function QUe(){let e=$Ue();return(0,U.jsxs)(`div`,{className:`grid grid-cols-[1.9rem_minmax(0,1fr)] gap-2 whitespace-pre-wrap break-words`,children:[(0,U.jsx)(`span`,{className:`whitespace-pre text-[#38bdf8]`,children:`•`}),(0,U.jsxs)(`span`,{className:`min-w-0`,children:[(0,U.jsx)(`span`,{className:`font-semibold text-[#38bdf8]`,children:`Compacting`}),(0,U.jsx)(`span`,{className:`text-[#38bdf8]`,children:e})]})]})}function $Ue(){let[e,t]=(0,H.useState)(0);return(0,H.useEffect)(()=>{let e=window.setInterval(()=>t(e=>(e+1)%4),400);return()=>window.clearInterval(e)},[]),`.`.repeat(e)}function x3({tone:e,label:t,onClick:n,children:r}){let i=`inline-flex items-center gap-1 border px-2 py-0.5 ${e===`cyan`?`border-[#1f4960] text-[#38bdf8]`:e===`red`?`border-[#5f2222] text-[#ef4444]`:e===`amber`?`border-[#6b4e16] text-[#f59e0b]`:e===`purple`?`border-purple-500/40 text-purple-300`:`border-[#3a3a3a] text-[#d4d4d4]`}`;return n?(0,U.jsx)(`button`,{type:`button`,onClick:n,className:`${i} hover:bg-white/5 focus:outline-none focus:ring-1 focus:ring-[#38bdf8]`,title:t,"aria-label":t,children:r}):(0,U.jsx)(`span`,{className:i,title:t,"aria-label":t,children:r})}function S3({label:e,onClick:t,disabled:n=!1,children:r}){return(0,U.jsx)(`button`,{type:`button`,onClick:t,disabled:n,"aria-label":e,title:e,className:`inline-flex min-h-7 min-w-7 items-center gap-1 border border-[#3a3a3a] px-2 text-[11px] text-[#a3a3a3] hover:border-[#38bdf8] hover:text-[#38bdf8] disabled:cursor-not-allowed disabled:opacity-40 disabled:hover:border-[#3a3a3a] disabled:hover:text-[#a3a3a3]`,children:r})}function C3({isLoading:e,agentProfiles:t,disabled:n,onSelectAgentProfile:r,message:i}){return(0,U.jsxs)(`div`,{className:`flex min-h-full flex-col items-center justify-center gap-4 px-6 py-10 text-center text-[12px] text-[#737373] @max-[420px]:px-3`,children:[(0,U.jsx)(`div`,{children:e?`Loading trace…`:i??`No trace selected.`}),t.length?(0,U.jsx)(`div`,{className:`flex flex-wrap items-center justify-center gap-2`,children:t.map(e=>(0,U.jsx)(`button`,{type:`button`,disabled:n,onClick:()=>r(e.name),className:`border border-[#3a3a3a] px-2 py-1 text-[#d4d4d4] hover:border-[#38bdf8] hover:text-[#38bdf8] disabled:opacity-50`,children:e.name},e.name))}):null]})}function eWe(e,t){if(e.size!==t.size)return!1;for(let n of e)if(!t.has(n))return!1;return!0}function tWe(e,t){return t?t===`away`:e instanceof WheelEvent?e.deltaY<0:e instanceof KeyboardEvent?[`ArrowUp`,`PageUp`,`Home`].includes(e.key):e?.type===`touchmove`}function nWe({selectedPiboSessionId:e,workflowSessionLinked:t,sessionNodes:n,onOpenSession:r,onRefreshBootstrap:i,onError:a}){let o=kn(),s=[`chat`,`session-workflow`,e],c=Wn({queryKey:s,queryFn:()=>WQ(e),enabled:!!(e&&t),retry:!1}),[l,u]=(0,H.useState)(!1),[d,f]=(0,H.useState)(),[p,m]=(0,H.useState)(),h=c.data,g=async()=>{await Promise.all([c.refetch(),i?.()])},_=async()=>{if(!(!e||l)){u(!0),m(void 0),a?.(null);try{let t=await SLe(e);m(t.alreadyStarted?`Workflow run was already started.`:t.message||`Workflow run started.`),await o.invalidateQueries({queryKey:s}),await g()}catch(e){a?.(ZQ(e))}finally{u(!1)}}},v=async(t,n,r,i)=>{if(e){f(`${t}:${n??r??`resume`}`),a?.(null);try{await CLe(e,{waitTokenId:t,...n?{actionId:n}:{},...r?{kind:r}:{},...i===void 0?{}:{payload:i}}),m(`Human action accepted.`),await o.invalidateQueries({queryKey:s}),await g()}catch(e){a?.(ZQ(e))}finally{f(void 0)}}};if(!t)return(0,U.jsx)(O3,{title:`Workflow unavailable`,children:`This normal Session has no workflow linkage. Workflow inspection is requested only for linked Sessions.`});if(c.isLoading)return(0,U.jsxs)(O3,{title:`Loading Workflow`,children:[(0,U.jsx)(Pc,{className:`inline animate-spin text-[#11a4d4]`,size:15}),` Loading configuration and run facts…`]});if(c.error||!h)return(0,U.jsx)(O3,{title:`Workflow inspection failed`,error:!0,children:ZQ(c.error??`No workflow inspection response`)});let y=h.workflowSession,b=y.workflowDefinitionLink,x=b?.status===`live`?b.href??(y.workflowVersion?`/apps/chat/workflows/view/${encodeURIComponent(y.workflowId)}/${encodeURIComponent(y.workflowVersion)}`:void 0):void 0,S=cWe(n,y.piboSessionId);return(0,U.jsx)(`section`,{className:`min-w-0 flex-1 overflow-auto bg-[#0b0f14] p-4 text-slate-300`,"data-pibo-debug":`session-native-workflow-view`,children:(0,U.jsxs)(`div`,{className:`mx-auto flex max-w-6xl flex-col gap-4`,children:[(0,U.jsxs)(`header`,{className:`rounded-sm border border-slate-800 bg-[#111820] p-4`,children:[(0,U.jsxs)(`div`,{className:`flex flex-wrap items-start justify-between gap-3`,children:[(0,U.jsxs)(`div`,{children:[(0,U.jsxs)(`div`,{className:`flex items-center gap-2 font-semibold text-slate-100`,children:[(0,U.jsx)(Ds,{size:16,className:`text-[#11a4d4]`}),`Workflow Session`]}),(0,U.jsxs)(`div`,{className:`mt-2 flex flex-wrap gap-2 text-xs`,children:[(0,U.jsxs)(A3,{children:[y.workflowId,y.workflowVersion?`@${y.workflowVersion}`:``]}),(0,U.jsx)(`span`,{className:XY(y.state),children:y.state}),y.workflowRunId?(0,U.jsxs)(A3,{children:[`run `,ZY(y.workflowRunId)]}):null]}),(0,U.jsx)(`p`,{className:`mt-2 text-xs text-slate-500`,children:`This is a normal Pibo Session with Workflow-owned linkage and execution facts.`})]}),(0,U.jsxs)(`div`,{className:`flex gap-2`,children:[(0,U.jsxs)(`button`,{type:`button`,onClick:()=>void g(),disabled:c.isFetching,"aria-label":`Refresh Workflow state`,className:j3,children:[c.isFetching?(0,U.jsx)(Pc,{size:13,className:`animate-spin`}):(0,U.jsx)(ol,{size:13}),`Refresh`]}),y.state===`configured`&&!y.workflowRunId?(0,U.jsxs)(`button`,{type:`button`,onClick:()=>void _(),disabled:l,className:`${j3} border-emerald-600 text-emerald-200`,children:[l?(0,U.jsx)(Pc,{size:13,className:`animate-spin`}):(0,U.jsx)(nl,{size:13}),`Start Workflow`]}):null]})]}),p||y.state===`pending`&&h.snapshot?(0,U.jsx)(`div`,{role:`status`,className:`mt-3 rounded-sm border border-emerald-800 bg-emerald-950/20 p-2 text-xs text-emerald-200`,children:p??`Run recorded. General graph execution is not connected here; supported manual triggers run from the editor.`}):null]}),(0,U.jsx)(`div`,{className:`rounded-sm border border-amber-800/60 bg-amber-950/15 p-3 text-xs leading-5 text-amber-100/80`,"aria-label":`Workflow execution boundary`,children:`Workflow execution uses Pibo Workflow IR and registered capabilities. XState is a read-only visualization; this surface does not expose inline code, raw XState editing, or broaden Session profile permissions.`}),(0,U.jsxs)(`div`,{className:`grid gap-4 lg:grid-cols-2`,children:[(0,U.jsx)(D3,{icon:uc,title:`Configuration`,children:(0,U.jsx)(ZK,{value:y.configuration??{}})}),(0,U.jsx)(D3,{icon:Ds,title:`Current run`,children:h.run?(0,U.jsx)(ZK,{value:h.run}):(0,U.jsx)(k3,{children:`No run exists. Start remains explicit.`})}),(0,U.jsx)(D3,{icon:ec,title:`Final output`,children:h.run&&Object.hasOwn(h.run,`output`)?(0,U.jsx)(ZK,{value:h.run.output}):(0,U.jsx)(k3,{children:`No final Workflow output recorded.`})}),(0,U.jsx)(D3,{icon:wl,title:`Validation and diagnostics`,children:(0,U.jsx)(ZK,{value:{snapshotValidation:h.snapshot?.validation,lifecycleDiagnostics:h.lifecycleEvents.flatMap(e=>e.diagnostics??[])}})})]}),(0,U.jsx)(oWe,{snapshot:h.snapshot??(h.definitionSnapshot?{effectiveDefinition:h.definitionSnapshot.definition}:void 0),attempts:h.nodeAttempts,transfers:h.edgeTransfers}),(0,U.jsx)(rWe,{data:h,busy:d,onSubmit:v}),(0,U.jsxs)(`div`,{className:`grid gap-4 xl:grid-cols-2`,children:[(0,U.jsx)(E3,{title:`Node attempts`,icon:ec,records:h.nodeAttempts,empty:`No node attempts recorded.`}),(0,U.jsx)(E3,{title:`Edge transfers`,icon:cl,records:h.edgeTransfers,empty:`No edge transfers recorded.`}),(0,U.jsx)(E3,{title:`Wait tokens`,icon:ic,records:h.waitTokens,empty:`No workflow waits recorded.`}),(0,U.jsx)(E3,{title:`Human action history`,icon:Ds,records:h.humanActions,empty:`No human actions recorded.`}),(0,U.jsx)(E3,{title:`Lifecycle events`,icon:Sc,records:h.lifecycleEvents,empty:`No lifecycle events recorded.`}),(0,U.jsx)(D3,{icon:uc,title:`Immutable effective snapshot`,children:h.snapshot??h.definitionSnapshot?(0,U.jsx)(ZK,{value:h.snapshot??h.definitionSnapshot}):(0,U.jsx)(k3,{children:`No immutable snapshot is available.`})})]}),(0,U.jsxs)(`section`,{className:`rounded-sm border border-slate-800 bg-[#111820] p-4`,children:[(0,U.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,U.jsx)(`h2`,{className:`text-xs font-bold uppercase tracking-wider text-slate-300`,children:`Workflow links`}),x?(0,U.jsxs)(`a`,{href:x,className:j3,children:[(0,U.jsx)(fc,{size:13}),`Open definition`]}):null]}),b?.status===`snapshot_only_definition_deleted`?(0,U.jsx)(`div`,{className:`mt-3 rounded-sm border border-amber-800 bg-amber-950/20 p-3 text-xs text-amber-100`,children:b.tombstoneLabel??`The live definition is unavailable. Inspection uses the immutable Session snapshot.`}):null,(0,U.jsx)(`div`,{className:`mt-3 grid gap-2`,children:S.length?S.map(e=>(0,U.jsxs)(`button`,{type:`button`,onClick:()=>r(e.piboSessionId),className:`rounded-sm border border-slate-800 bg-[#0e1116] p-3 text-left text-xs hover:border-[#11a4d4]`,children:[(0,U.jsx)(`span`,{className:`font-semibold text-slate-200`,children:e.title}),(0,U.jsx)(`span`,{className:`ml-2 font-mono text-slate-500`,children:e.piboSessionId})]},e.piboSessionId)):(0,U.jsx)(k3,{children:`No linked child Workflow Sessions.`})})]})]})})}function rWe({data:e,busy:t,onSubmit:n}){let r=e.workflowSession.pendingHumanActions??[],i=e.waitTokens.filter(e=>!e.status||e.status===`pending`||e.status===`waiting`);return(0,U.jsxs)(`section`,{className:`rounded-sm border border-amber-800/60 bg-[#111820] p-4`,"aria-label":`Workflow human actions`,children:[(0,U.jsx)(`h2`,{className:`text-xs font-bold uppercase tracking-wider text-amber-200`,children:`Human actions`}),(0,U.jsx)(`div`,{className:`mt-3 grid gap-3`,children:r.length?r.map(e=>(0,U.jsx)(iWe,{action:e,busy:t,onSubmit:n},e.waitTokenId)):i.length?i.map(e=>(0,U.jsx)(aWe,{token:e,busy:t,onSubmit:n},e.id)):(0,U.jsx)(k3,{children:`No pending human action.`})})]})}function iWe({action:e,busy:t,onSubmit:n}){let[r,i]=(0,H.useState)(`{}`),[a,o]=(0,H.useState)(),s=(t,i)=>{let a;try{a=r.trim()?JSON.parse(r):void 0,o(void 0)}catch{o(`Payload must be valid JSON.`);return}n(e.waitTokenId,t,i,a)};return(0,U.jsxs)(`div`,{className:`rounded-sm border border-amber-700/50 bg-amber-950/10 p-3 text-xs`,children:[(0,U.jsx)(`div`,{className:`font-semibold text-amber-100`,children:e.prompt}),e.diagnostics.length?(0,U.jsx)(`div`,{role:`alert`,className:`mt-2 rounded-sm border border-red-800/70 bg-red-950/20 p-2 text-red-200`,children:(0,U.jsx)(ZK,{value:e.diagnostics})}):null,e.payloadRequirements.required||e.schema?(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(`textarea`,{"aria-label":`Human action payload for ${e.waitTokenId}`,value:r,onChange:e=>i(e.target.value),className:`mt-3 min-h-20 w-full rounded-sm border border-slate-700 bg-[#0e1116] p-2 font-mono text-xs`}),a?(0,U.jsx)(`div`,{role:`alert`,className:`mt-1 text-red-300`,children:a}):null]}):null,(0,U.jsx)(`div`,{className:`mt-3 flex flex-wrap gap-2`,children:e.availableActions.filter(e=>e.registered).map(e=>(0,U.jsx)(`button`,{type:`button`,disabled:!!t,onClick:()=>s(e.id,e.kind),className:j3,children:e.displayName},e.id))})]})}function aWe({token:e}){return(0,U.jsxs)(`div`,{className:`rounded-sm border border-amber-700/50 p-3 text-xs`,children:[(0,U.jsx)(`div`,{children:e.prompt??`Wait ${e.id}`}),(0,U.jsx)(`div`,{className:`mt-2 text-[11px] text-amber-100/70`,children:`No registered actions were returned for this wait token. Refresh after the runtime publishes actionable metadata.`})]})}function oWe({snapshot:e,attempts:t,transfers:n}){let r=(0,H.useMemo)(()=>sWe(e),[e]);return e?(0,U.jsxs)(D3,{icon:Sc,title:`Workflow graph`,children:[(0,U.jsx)(`div`,{className:`grid gap-2 sm:grid-cols-2 lg:grid-cols-3`,children:r.nodes.map(e=>{let n=[...t].reverse().find(t=>t.nodeId===e.id);return(0,U.jsxs)(`div`,{className:`rounded-sm border border-slate-700 bg-[#0e1116] p-3 text-xs`,children:[(0,U.jsx)(`div`,{className:`font-mono font-semibold text-[#8bdcf4]`,children:e.id}),(0,U.jsx)(`div`,{className:`mt-1 text-slate-400`,children:e.kind}),(0,U.jsx)(`div`,{className:`mt-2 text-[10px] uppercase text-slate-500`,children:n?.status??`not attempted`})]},e.id)})}),r.nodes.length===0?(0,U.jsx)(k3,{children:`The snapshot contains no graph nodes.`}):null,(0,U.jsx)(`div`,{className:`mt-3 grid gap-1 text-xs text-slate-400`,children:r.edges.map(e=>(0,U.jsxs)(`div`,{className:`rounded-sm border border-slate-800 p-2 font-mono`,children:[e.source,` → `,e.target,n.some(t=>t.edgeId===e.id)?` · transferred`:``]},e.id))})]}):(0,U.jsx)(D3,{icon:Sc,title:`Workflow graph`,children:(0,U.jsx)(k3,{children:`No immutable snapshot is available, so no graph is rendered.`})})}function sWe(e){let t=e?.effectiveDefinition;if(!t||typeof t!=`object`)return{nodes:[],edges:[]};let n=t.nodes,r=t.edges;return{nodes:n&&typeof n==`object`&&!Array.isArray(n)?Object.entries(n).map(([e,t])=>({id:e,kind:w3(t,`kind`)??`node`})):[],edges:r&&typeof r==`object`&&!Array.isArray(r)?Object.entries(r).map(([e,t])=>({id:e,source:T3(t,`from`)??w3(t,`source`)??`?`,target:T3(t,`to`)??w3(t,`target`)??`?`})):Array.isArray(r)?r.map((e,t)=>({id:w3(e,`id`)??`edge-${t+1}`,source:T3(e,`from`)??w3(e,`source`)??`?`,target:T3(e,`to`)??w3(e,`target`)??`?`})):[]}}function w3(e,t){if(!e||typeof e!=`object`)return;let n=e[t];return typeof n==`string`?n:void 0}function T3(e,t){if(!(!e||typeof e!=`object`))return w3(e[t],`nodeId`)}function cWe(e,t){let n=[],r=e=>{for(let i of e)i.parentId===t&&(i.workflowSessionKind===`nested_workflow`||i.workflowSessionKind===`agent_node`)&&n.push({piboSessionId:i.piboSessionId,title:i.title}),r(i.children)};return r(e),n}function E3({title:e,icon:t,records:n,empty:r}){return(0,U.jsx)(D3,{icon:t,title:e,children:n.length?(0,U.jsx)(`div`,{className:`grid gap-2`,children:n.map((e,t)=>(0,U.jsx)(`div`,{className:`rounded-sm border border-slate-800 bg-[#0e1116] p-2`,children:(0,U.jsx)(ZK,{value:e})},lWe(e,t)))}):(0,U.jsx)(k3,{children:r})})}function D3({icon:e,title:t,children:n}){return(0,U.jsxs)(`section`,{className:`min-w-0 rounded-sm border border-slate-800 bg-[#111820] p-4`,children:[(0,U.jsxs)(`h2`,{className:`mb-3 flex items-center gap-2 text-xs font-bold uppercase tracking-wider text-slate-300`,children:[(0,U.jsx)(e,{size:14,className:`text-[#11a4d4]`}),t]}),n]})}function O3({title:e,children:t,error:n=!1}){return(0,U.jsx)(`section`,{className:`min-w-0 flex-1 overflow-auto bg-[#0b0f14] p-4`,children:(0,U.jsxs)(`div`,{className:`mx-auto max-w-3xl rounded-sm border p-4 text-sm ${n?`border-red-900 bg-red-950/30 text-red-200`:`border-slate-800 bg-[#111820] text-slate-300`}`,children:[(0,U.jsxs)(`div`,{className:`mb-2 flex items-center gap-2 font-semibold`,children:[n?(0,U.jsx)(wl,{size:15}):null,e]}),t]})})}function k3({children:e}){return(0,U.jsx)(`div`,{className:`rounded-sm border border-dashed border-slate-700 p-3 text-xs text-slate-500`,children:e})}function A3({children:e}){return(0,U.jsx)(`span`,{className:`rounded border border-slate-700 bg-slate-900/40 px-2 py-1 font-mono text-slate-300`,children:e})}function lWe(e,t){return e&&typeof e==`object`&&typeof e.id==`string`?e.id:String(t)}var j3=`inline-flex items-center justify-center gap-1 rounded-sm border border-slate-700 px-3 py-1.5 text-xs font-semibold text-slate-200 hover:border-[#11a4d4] hover:text-white disabled:opacity-50`,M3=new Map([{id:`terminal`,label:`Terminal`,description:`Compact Codex-style terminal transcript.`,render:e=>(0,U.jsx)(IUe,{...e})},{id:`workflow`,label:`Workflow`,description:`Workflow configuration, graph, run facts, waits, and human actions for linked Sessions.`,render:e=>(0,U.jsx)(nWe,{...e})}].map(e=>[e.id,e]));function uWe(e){return M3.get(e)??M3.get(`terminal`)}function N3(e,t){return{localBootstrap:t,queryData:e.getQueriesData({queryKey:[`chat`,`bootstrap`]})}}function P3(e,t,n){return e.selectedRoomId===t?n(e):e}function F3(e){let t=!!(e.tempId&&e.currentSelectedPiboSessionId===e.tempId);return e.status===`success`?{selectedPiboSessionId:t?e.createdPiboSessionId:e.currentSelectedPiboSessionId,navigateToCreatedSession:t,autoRenameCreatedSession:t}:{selectedPiboSessionId:t?e.previousSelectedPiboSessionId??null:e.currentSelectedPiboSessionId,navigateToCreatedSession:!1,autoRenameCreatedSession:!1}}function I3(e,t){return!e||t===void 0?e:{...e,selectedPiboSessionId:t??``}}function L3(e,t){return Z3(e.sessions,t.piboSessionId)?e:{...e,sessions:R3(e.sessions,t)}}function dWe(e,t,n){let r=e.sessions.findIndex(e=>e.piboSessionId===t);if(r<0)return e;let i=[...e.sessions],[a]=i.splice(r,1),o={...a,pinned:n,sidebarOrder:Date.now()};return{...e,sessions:R3(i,o)}}function fWe(e,t,n,r){let i=e.sessions.findIndex(e=>e.piboSessionId===t),a=e.sessions.findIndex(e=>e.piboSessionId===n);if(i<0||a<0||i===a)return e;let o=e.sessions[i],s=e.sessions[a];if(!!o.pinned!=!!s.pinned||o.archived||s.archived)return e;let c=[...e.sessions];c.splice(i,1);let l=c.findIndex(e=>e.piboSessionId===n);return c.splice(r===`before`?l:l+1,0,o),{...e,sessions:c}}function R3(e,t){let n=[...e],r;return r=t.pinned?n.findIndex(e=>!e.archived):n.findIndex(e=>!e.pinned&&!e.archived),r<0&&(r=n.findIndex(e=>!!e.archived)),r<0&&(r=n.length),n.splice(r,0,t),n}function pWe(e,t){let n=z3(e.sessions,t),r=t.has(e.selectedPiboSessionId);return{...e,selectedPiboSessionId:r?``:e.selectedPiboSessionId,sessions:n}}function z3(e,t){let n=!1,r=[];for(let i of e){if(t.has(i.piboSessionId)){n=!0;continue}let e=z3(i.children,t);e===i.children?r.push(i):(n=!0,r.push({...i,children:e}))}return n?r:e}function B3(e){let t=new Set([e.piboSessionId]);for(let n of e.children)for(let e of B3(n))t.add(e);return t}function mWe(e,t,n){if(!t)return L3(e,n);let r=!1,i=J3(e.sessions,t,()=>(r=!0,n));return{...e,selectedPiboSessionId:e.selectedPiboSessionId===t?n.piboSessionId:e.selectedPiboSessionId,session:e.session.id===t?X3(n,e.session):e.session,sessions:r?i:R3(i,n)}}function hWe(e,t,n){let r=z3(e.sessions,new Set([t])),i=e.selectedPiboSessionId===t;return r===e.sessions&&!i?e:{...e,selectedPiboSessionId:i?n??``:e.selectedPiboSessionId,sessions:r}}function V3(e,t){let n=typeof t.metadata?.chatWebArchivedAt==`string`,r=typeof t.metadata?.chatWebPinnedAt==`string`,i=typeof t.metadata?.chatWebSidebarOrder==`number`?t.metadata.chatWebSidebarOrder:void 0;return{...e,session:e.session.id===t.id?t:e.session,sessions:J3(e.sessions,t.id,e=>({...e,profile:t.profile,activeModel:t.activeModel,title:t.title||e.title||`Untitled Session`,createdAt:t.createdAt,archived:n,pinned:r,sidebarOrder:i}))}}function H3(e,t,n){let r=e.session.id===t?X3(n(Y3(e.session)),e.session):e.session;return{...e,session:r,sessions:J3(e.sessions,t,n)}}function gWe(e,t){return Kq(e.rooms,t.id)?e:{...e,room:t,selectedRoomId:t.id,selectedPiboSessionId:``,rooms:[t,...e.rooms]}}function _We(e,t,n){let r=t!==n.id&&Kq(e.rooms,n.id)?K3(e.rooms,new Set([t])):G3(e.rooms,t,()=>n);return{...e,room:e.room?.id===t?n:e.room,selectedRoomId:e.selectedRoomId===t?n.id:e.selectedRoomId,rooms:Kq(r,n.id)?r:[n,...r]}}function U3(e,t,n){return{...e,room:e.room?.id===t?n(e.room):e.room,rooms:G3(e.rooms,t,n)}}function vWe(e,t,n){let r=e.rooms.findIndex(e=>e.id===t);if(r<0)return e;let i=[...e.rooms],[a]=i.splice(r,1);if(!a||Jq(a)||Yq(a))return e;let o={...a.metadata,chatRoomSidebarOrder:Date.now()};return n?o.chatRoomPinnedAt=new Date().toISOString():delete o.chatRoomPinnedAt,{...e,rooms:bWe(i,{...a,metadata:o})}}function yWe(e,t,n,r){let i=e.rooms.findIndex(e=>e.id===t),a=e.rooms.findIndex(e=>e.id===n);if(i<0||a<0||i===a)return e;let o=e.rooms[i],s=e.rooms[a];if(Jq(o)||Jq(s)||Yq(o)||Yq(s)||Xq(o)!==Xq(s))return e;let c=[...e.rooms];c.splice(i,1);let l=c.findIndex(e=>e.id===n);return c.splice(r===`before`?l:l+1,0,o),{...e,rooms:c}}function bWe(e,t){let n=[...e],r;return r=Xq(t)?n.findIndex(e=>!Jq(e)&&!Yq(e)):n.findIndex(e=>!Jq(e)&&!Yq(e)&&!Xq(e)),r<0&&(r=n.findIndex(e=>!Jq(e)&&Yq(e))),r<0&&(r=n.length),n.splice(r,0,t),n}function W3(e,t){let n=t.has(e.selectedRoomId);return{...e,room:e.room&&t.has(e.room.id)?void 0:e.room,selectedRoomId:n?``:e.selectedRoomId,selectedPiboSessionId:n?``:e.selectedPiboSessionId,rooms:K3(e.rooms,t)}}function G3(e,t,n){let r=!1,i=e.map(e=>{if(e.id===t)return r=!0,n(e);let i=e.children??[],a=G3(i,t,n);return a===i?e:(r=!0,{...e,children:a})});return r?i:e}function K3(e,t){let n=!1,r=[];for(let i of e){if(t.has(i.id)){n=!0;continue}let e=i.children??[],a=K3(e,t);a===e?r.push(i):(n=!0,r.push({...i,children:a}))}return n?r:e}function xWe(e,t){let n=new Date().toISOString();return{id:e,name:t,type:`chat`,createdAt:n,updatedAt:n,metadata:{},children:[]}}function q3(e){let t=new Set([e.id]);for(let n of e.children??[])for(let e of q3(n))t.add(e);return t}function J3(e,t,n){let r=!1,i=e.map(e=>{if(e.piboSessionId===t)return r=!0,n(e);let i=J3(e.children,t,n);return i===e.children?e:(r=!0,{...e,children:i})});return r?i:e}function SWe(e,t){return{piboSessionId:e,piSessionId:`pending`,profile:t,title:`New Session`,createdAt:new Date().toISOString(),status:`idle`,lastActivityAt:new Date().toISOString(),derivedSessions:[],children:[]}}function Y3(e){return{piboSessionId:e.id,piSessionId:e.piSessionId,profile:e.profile,activeModel:e.activeModel,title:e.title||`Untitled Session`,createdAt:e.createdAt,archived:typeof e.metadata?.chatWebArchivedAt==`string`,pinned:typeof e.metadata?.chatWebPinnedAt==`string`,sidebarOrder:typeof e.metadata?.chatWebSidebarOrder==`number`?e.metadata.chatWebSidebarOrder:void 0,status:`idle`,lastActivityAt:e.updatedAt,derivedSessions:[],children:[]}}function X3(e,t){return{...t,id:e.piboSessionId,piSessionId:e.piSessionId,profile:e.profile,activeModel:e.activeModel,title:Hq(e),updatedAt:e.lastActivityAt??t.updatedAt}}function Z3(e,t){for(let n of e){if(n.piboSessionId===t)return n;let e=Z3(n.children,t);if(e)return e}}function CWe(e){let t=e.trim();if(t.length>=2){let e=t[0],n=t[t.length-1];if(e===`"`&&n===`"`||e===`'`&&n===`'`)return t.slice(1,-1).trim()}return t}function wWe(e,t){if(e===`thinking`&&t)return{level:t.split(/\s+/,1)[0]};if(e===`compact`&&t)return{customInstructions:t};if(e===`goal`)return{command:t}}function TWe(e){return!Q3(e)||!Q3(e.result)?null:e}function EWe(e){if(!(!Q3(e)||!Q3(e.result)))return typeof e.result.piboSessionId==`string`?e.result.piboSessionId:void 0}function Q3(e){return!!e&&typeof e==`object`&&!Array.isArray(e)}function DWe(e){let t=e.flatMap(e=>e.slashCommands.filter(e=>e!==`tree`).map(t=>({slash:`/${t}`,action:e.name,description:e.name===`thinking`&&t===`thinking`?`Show thinking level or use /thinking <level>.`:e.description??e.name})));return t.push({slash:`/download`,action:`download`,description:`Download a file by absolute path or relative to the current working directory.`},{slash:`/upload`,action:`upload`,description:`Upload one or more files to the configured Pibo uploads directory.`},{slash:`/thinking-show`,action:`thinking-show`,description:`Toggle historical thinking display in this browser.`}),t}function OWe(e,t){if(!e)return[];let n=e.agentCatalog?.skills??[],r=e.agentCatalog?.userSkills??[],i=[...n,...r],a=OQ(e),o=t?kQ(e.sessions,t)?.profile??a:a,s=[...e.agents.map(e=>({name:e.name,skills:e.skills})),...e.customAgents.map(e=>({name:e.profileName,skills:e.skills}))].find(e=>e.name===o),c=new Set(s?.skills??[]);return i.filter(e=>c.has(e.name))}function kWe(e,t){let n=e.area===`sessions`?e.roomId:void 0,r=e.area===`sessions`||e.area===`context`?e.piboSessionId:void 0,i=n?t.sessionsByRoom?.[n]:t.piboSessionId;return{requestedRoomId:e.area===`sessions`?n??(r?void 0:t.roomId):e.area===`context`&&r?void 0:t.roomId,requestedPiboSessionId:e.area===`sessions`?r??(r?void 0:i):e.area===`context`?r:t.piboSessionId}}function AWe(e){let{bootstrap:t,creatingSession:n,route:r}=e,i=r.area===`sessions`||r.area===`context`?r.piboSessionId:void 0;return t&&r.area!==`sessions`&&(r.area!==`context`||!i||t.selectedPiboSessionId===i)||n?!0:!!(t&&r.area===`sessions`&&r.piboSessionId&&t.selectedPiboSessionId===r.piboSessionId&&t.selectedRoomId===r.roomId)}function jWe(e,t){if(e.area===`sessions`&&t.selectedPiboSessionId&&(e.roomId!==t.selectedRoomId||e.piboSessionId!==t.selectedPiboSessionId))return t}function MWe(e){return e.area===`sessions`&&!!(e.roomId||e.piboSessionId)}function NWe(e){if(!(!e||typeof e!=`object`||!(`status`in e)))return typeof e.status==`number`?e.status:void 0}function PWe(e){return e instanceof Error?e.message:String(e)}function FWe(e){let t=NWe(e),n=PWe(e);return t===401||t===403?{kind:`authentication-required`,message:n}:e instanceof TypeError||/failed to fetch|network(?:error| request failed)|internet disconnected|load failed/i.test(n)?{kind:`load-failed`,message:`Could not connect to Pibo Chat. Check your network connection and try again.`}:t!==void 0&&t>=500?{kind:`load-failed`,message:`Could not load Pibo Chat. The server may be unavailable. Try again.`}:{kind:`load-failed`,message:`Could not load Pibo Chat. Try again.`}}function $3(e,t){return t===`archivedAt`?e.metadata?.chatRoomArchivedAt:e[t]}function e6(e,t){let n={...e};return`name`in t&&(n.name=t.name),`topic`in t&&(n.topic=t.topic),`workspace`in t&&(n.workspace=t.workspace,n.metadata={...n.metadata},t.workspace===void 0?delete n.metadata.workspace:n.metadata.workspace=t.workspace),`archivedAt`in t&&(n.metadata={...n.metadata},t.archivedAt===void 0?delete n.metadata.chatRoomArchivedAt:n.metadata.chatRoomArchivedAt=t.archivedAt),n}function t6(e){for(let t=e.layers.length-1;t>=0;t--){let n=e.layers[t];if(n.status!==`failure`)return n.value}return e.base}var IWe=class{rooms=new Map;begin(e,t){let n={};t.name!==void 0&&(n.name=t.name),t.topic!==void 0&&(n.topic=t.topic??void 0),t.workspace!==void 0&&(n.workspace=t.workspace??void 0),t.archived!==void 0&&(n.archivedAt=t.archived?new Date().toISOString():void 0);let r=this.rooms.get(e.id)??new Map;this.rooms.set(e.id,r);let i={roomId:e.id,layers:new Map};for(let t of Object.keys(n)){let a=r.get(t)??{base:$3(e,t),layers:[]},o={value:n[t],status:`pending`};a.layers.push(o),r.set(t,a),i.layers.set(t,o)}return i}settle(e,t){let n=this.rooms.get(e.roomId),r={};for(let[i,a]of e.layers){a.status=t?`success`:`failure`,t&&(a.value=$3(t,i));let e=n.get(i);r[i]=t6(e),e.layers.some(e=>e.status===`pending`)||n.delete(i)}return n.size===0&&this.rooms.delete(e.roomId),n=>U3(n,e.roomId,e=>{let n=e6(e,r);return t&&t.updatedAt>n.updatedAt&&(n.updatedAt=t.updatedAt),n})}apply(e){let t=e;for(let[e,n]of this.rooms){let r={};for(let[e,t]of n)r[e]=t6(t);t=U3(t,e,e=>e6(e,r))}return t}};function n6({activePanel:e,onSelect:t,piPackageCount:n,userSkillCount:r}){return(0,U.jsx)(`div`,{className:`p-2`,children:(0,U.jsxs)(`div`,{className:`mb-4`,children:[(0,U.jsx)(`div`,{className:`px-1 pb-1 text-[10px] font-bold uppercase tracking-wider text-slate-500`,children:`Settings`}),(0,U.jsxs)(`button`,{type:`button`,onClick:()=>t(`general`),className:`mb-1 flex w-full items-center gap-2 border p-2 text-left ${e===`general`?`border-[#11a4d4] bg-[#11a4d4]/10`:`border-slate-800 bg-[#151f24] hover:border-slate-700`}`,children:[(0,U.jsx)(hl,{size:13,className:`text-[#11a4d4]`}),(0,U.jsxs)(`div`,{className:`min-w-0`,children:[(0,U.jsx)(`span`,{className:`block truncate text-sm text-slate-200`,children:`General`}),(0,U.jsx)(`span`,{className:`block truncate font-mono text-[10px] text-slate-500`,children:`browser + runtime`})]})]}),(0,U.jsxs)(`button`,{type:`button`,onClick:()=>t(`debug`),className:`mb-1 flex w-full items-center gap-2 border p-2 text-left ${e===`debug`?`border-[#11a4d4] bg-[#11a4d4]/10`:`border-slate-800 bg-[#151f24] hover:border-slate-700`}`,children:[(0,U.jsx)(Vs,{size:13,className:`text-[#11a4d4]`}),(0,U.jsxs)(`div`,{className:`min-w-0`,children:[(0,U.jsx)(`span`,{className:`block truncate text-sm text-slate-200`,children:`Debug`}),(0,U.jsx)(`span`,{className:`block truncate font-mono text-[10px] text-slate-500`,children:`tool metric signals`})]})]}),(0,U.jsxs)(`button`,{type:`button`,onClick:()=>t(`concurrency`),className:`mb-1 flex w-full items-center gap-2 border p-2 text-left ${e===`concurrency`?`border-[#11a4d4] bg-[#11a4d4]/10`:`border-slate-800 bg-[#151f24] hover:border-slate-700`}`,children:[(0,U.jsx)(xc,{size:13,className:`text-[#11a4d4]`}),(0,U.jsxs)(`div`,{className:`min-w-0`,children:[(0,U.jsx)(`span`,{className:`block truncate text-sm text-slate-200`,children:`Concurrency`}),(0,U.jsx)(`span`,{className:`block truncate font-mono text-[10px] text-slate-500`,children:`yielded runs`})]})]}),(0,U.jsxs)(`button`,{type:`button`,onClick:()=>t(`previews`),className:`mb-1 flex w-full items-center gap-2 border p-2 text-left ${e===`previews`?`border-[#11a4d4] bg-[#11a4d4]/10`:`border-slate-800 bg-[#151f24] hover:border-slate-700`}`,children:[(0,U.jsx)(Wc,{size:13,className:`text-[#11a4d4]`}),(0,U.jsxs)(`div`,{className:`min-w-0`,children:[(0,U.jsx)(`span`,{className:`block truncate text-sm text-slate-200`,children:`Previews`}),(0,U.jsx)(`span`,{className:`block truncate font-mono text-[10px] text-slate-500`,children:`server pool + lease`})]})]}),(0,U.jsxs)(`button`,{type:`button`,onClick:()=>t(`transcription`),className:`mb-1 flex w-full items-center gap-2 border p-2 text-left ${e===`transcription`?`border-[#11a4d4] bg-[#11a4d4]/10`:`border-slate-800 bg-[#151f24] hover:border-slate-700`}`,children:[(0,U.jsx)(Hc,{size:13,className:`text-[#11a4d4]`}),(0,U.jsxs)(`div`,{className:`min-w-0`,children:[(0,U.jsx)(`span`,{className:`block truncate text-sm text-slate-200`,children:`Transcription`}),(0,U.jsx)(`span`,{className:`block truncate font-mono text-[10px] text-slate-500`,children:`audio provider`})]})]}),(0,U.jsxs)(`button`,{type:`button`,onClick:()=>t(`speech`),className:`mb-1 flex w-full items-center gap-2 border p-2 text-left ${e===`speech`?`border-[#11a4d4] bg-[#11a4d4]/10`:`border-slate-800 bg-[#151f24] hover:border-slate-700`}`,children:[(0,U.jsx)(Ol,{size:13,className:`text-[#11a4d4]`}),(0,U.jsxs)(`div`,{className:`min-w-0`,children:[(0,U.jsx)(`span`,{className:`block truncate text-sm text-slate-200`,children:`Speech`}),(0,U.jsx)(`span`,{className:`block truncate font-mono text-[10px] text-slate-500`,children:`text-to-speech`})]})]}),(0,U.jsxs)(`button`,{type:`button`,onClick:()=>t(`shortcuts`),className:`mb-1 flex w-full items-center gap-2 border p-2 text-left ${e===`shortcuts`?`border-[#11a4d4] bg-[#11a4d4]/10`:`border-slate-800 bg-[#151f24] hover:border-slate-700`}`,children:[(0,U.jsx)(Oc,{size:13,className:`text-[#11a4d4]`}),(0,U.jsxs)(`div`,{className:`min-w-0`,children:[(0,U.jsx)(`span`,{className:`block truncate text-sm text-slate-200`,children:`Shortcuts`}),(0,U.jsx)(`span`,{className:`block truncate font-mono text-[10px] text-slate-500`,children:`keyboard`})]})]}),(0,U.jsxs)(`button`,{type:`button`,onClick:()=>t(`maintenance`),className:`mb-1 flex w-full items-center gap-2 border p-2 text-left ${e===`maintenance`?`border-[#11a4d4] bg-[#11a4d4]/10`:`border-slate-800 bg-[#151f24] hover:border-slate-700`}`,children:[(0,U.jsx)(uc,{size:13,className:`text-[#11a4d4]`}),(0,U.jsxs)(`div`,{className:`min-w-0`,children:[(0,U.jsx)(`span`,{className:`block truncate text-sm text-slate-200`,children:`Maintenance`}),(0,U.jsx)(`span`,{className:`block truncate font-mono text-[10px] text-slate-500`,children:`telemetry retention`})]})]}),(0,U.jsxs)(`button`,{type:`button`,onClick:()=>t(`pi-packages`),className:`mb-1 flex w-full items-center gap-2 border p-2 text-left ${e===`pi-packages`?`border-[#11a4d4] bg-[#11a4d4]/10`:`border-slate-800 bg-[#151f24] hover:border-slate-700`}`,children:[(0,U.jsx)(kc,{size:13,className:`text-[#11a4d4]`}),(0,U.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,U.jsx)(`span`,{className:`block truncate text-sm text-slate-200`,children:`Pi Packages`}),(0,U.jsx)(`span`,{className:`block truncate font-mono text-[10px] text-slate-500`,children:`runtime-packages`})]}),(0,U.jsx)(`span`,{className:`inline-flex min-w-6 items-center justify-center border border-slate-700 bg-[#101d22] px-1.5 py-0.5 text-[10px] font-mono text-slate-400`,children:n})]}),(0,U.jsxs)(`button`,{type:`button`,onClick:()=>t(`skills`),className:`mb-1 flex w-full items-center gap-2 border p-2 text-left ${e===`skills`?`border-[#11a4d4] bg-[#11a4d4]/10`:`border-slate-800 bg-[#151f24] hover:border-slate-700`}`,children:[(0,U.jsx)(Al,{size:13,className:`text-[#11a4d4]`}),(0,U.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,U.jsx)(`span`,{className:`block truncate text-sm text-slate-200`,children:`Skills`}),(0,U.jsx)(`span`,{className:`block truncate font-mono text-[10px] text-slate-500`,children:`user-managed`})]}),(0,U.jsx)(`span`,{className:`inline-flex min-w-6 items-center justify-center border border-slate-700 bg-[#101d22] px-1.5 py-0.5 text-[10px] font-mono text-slate-400`,children:r})]}),(0,U.jsxs)(`button`,{type:`button`,onClick:()=>t(`providers`),className:`flex w-full items-center gap-2 border p-2 text-left ${e===`providers`?`border-[#11a4d4] bg-[#11a4d4]/10`:`border-slate-800 bg-[#151f24] hover:border-slate-700`}`,children:[(0,U.jsx)(Dc,{size:13,className:`text-[#11a4d4]`}),(0,U.jsxs)(`div`,{className:`min-w-0`,children:[(0,U.jsx)(`span`,{className:`block truncate text-sm text-slate-200`,children:`Providers`}),(0,U.jsx)(`span`,{className:`block truncate font-mono text-[10px] text-slate-500`,children:`auth + api keys`})]})]})]})})}function LWe({debugMode:e,onDebugModeChange:t,thresholds:n,onThresholdsChange:r}){let[i,a]=(0,H.useState)(()=>i6(n)),[o,s]=(0,H.useState)(null),[c,l]=(0,H.useState)(null);(0,H.useEffect)(()=>a(i6(n)),[n]);let u=(e,t)=>{a(n=>({...n,[e]:t})),s(null),l(null)};return(0,U.jsx)(kJ,{title:`Tool diagnostics`,children:(0,U.jsxs)(`div`,{className:`max-w-3xl`,children:[(0,U.jsx)(PJ,{checked:e,title:`Show Tool Debug metrics`,onToggle:()=>t(!e)}),(0,U.jsx)(`p`,{className:`mt-3 text-xs leading-relaxed text-slate-400`,children:`Thresholds control only the signal-rail colors. Payload counts are diagnostics rather than provider usage or billing; the signal rail records the selected calculation method with every completed Tool call.`}),(0,U.jsx)(RWe,{}),(0,U.jsxs)(`div`,{className:`mt-5 grid gap-4`,children:[(0,U.jsx)(r6,{legend:`Execution time`,unit:`seconds`,values:[i.durationElevated,i.durationHigh,i.durationCritical],onChange:(e,t)=>u([`durationElevated`,`durationHigh`,`durationCritical`][e],t)}),(0,U.jsx)(r6,{legend:`Estimated input payload`,unit:`tokens`,values:[i.inputElevated,i.inputHigh,i.inputCritical],onChange:(e,t)=>u([`inputElevated`,`inputHigh`,`inputCritical`][e],t)}),(0,U.jsx)(r6,{legend:`Estimated output payload`,unit:`tokens`,values:[i.outputElevated,i.outputHigh,i.outputCritical],onChange:(e,t)=>u([`outputElevated`,`outputHigh`,`outputCritical`][e],t)})]}),(0,U.jsxs)(`div`,{className:`mt-5 flex flex-wrap items-center gap-2`,children:[(0,U.jsx)(`button`,{type:`button`,onClick:()=>{let e=zWe(i);if(!e){s(null),l(`Each row must contain three positive, increasing values.`);return}r(e),l(null),s(`Debug thresholds saved in this browser.`)},className:`border border-[#11a4d4] bg-[#11a4d4]/15 px-3 py-1.5 text-xs font-semibold text-cyan-100 hover:bg-[#11a4d4]/25`,children:`Save thresholds`}),(0,U.jsx)(`button`,{type:`button`,onClick:()=>{r(a$),a(i6(a$)),l(null),s(`Default Debug thresholds restored.`)},className:`border border-slate-700 bg-[#151f24] px-3 py-1.5 text-xs text-slate-300 hover:border-slate-600`,children:`Restore defaults`})]}),o?(0,U.jsx)(`p`,{role:`status`,className:`mt-3 text-xs text-emerald-300`,children:o}):null,c?(0,U.jsx)(`p`,{role:`alert`,className:`mt-3 text-xs text-red-300`,children:c}):null]})})}function RWe(){let e=kn(),{data:t,isLoading:n}=Wn({queryKey:[`user-settings`],queryFn:qH}),[r,i]=(0,H.useState)(hVe.method),[a,o]=(0,H.useState)(`4`),[s,c]=(0,H.useState)(`o200k_base`),[l,u]=(0,H.useState)(!1),[d,f]=(0,H.useState)(null),[p,m]=(0,H.useState)(null);(0,H.useEffect)(()=>{let e=t?.toolMetrics.tokenCalculation;e&&(i(e.method),e.method===`characters`?o(String(e.factor)):c(e.encoding))},[t]);let h=async()=>{let t=Number(a),n=r===`characters`?Number.isFinite(t)&&t>0?{method:r,factor:t}:void 0:{method:r,encoding:s};if(!n){f(null),m(`Character factor must be greater than zero.`);return}u(!0),f(null),m(null);try{let t=await JH({toolMetrics:{tokenCalculation:n}});e.setQueryData([`user-settings`],t),f(`Token calculation saved. Future Tool calls use this method.`)}catch(e){m(e instanceof Error?e.message:String(e))}finally{u(!1)}};return(0,U.jsxs)(`fieldset`,{className:`mt-5 border border-slate-800 bg-[#111820] p-3`,children:[(0,U.jsx)(`legend`,{className:`px-1 text-xs font-semibold text-slate-200`,children:`Token calculation`}),(0,U.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,U.jsxs)(`label`,{htmlFor:`tool-token-calculation-method`,className:`text-[11px] text-slate-400`,children:[(0,U.jsx)(`span`,{className:`mb-1 block font-semibold uppercase tracking-wide`,children:`Method`}),(0,U.jsxs)(`select`,{id:`tool-token-calculation-method`,value:r,disabled:n||l,onChange:e=>{i(e.target.value),f(null),m(null)},className:`w-full border border-slate-700 bg-[#0b1115] px-2 py-1.5 text-xs text-slate-100 outline-none focus:border-[#11a4d4]`,children:[(0,U.jsx)(`option`,{value:`characters`,children:`Characters ÷ factor`}),(0,U.jsx)(`option`,{value:`tiktoken`,children:`Tiktoken`})]})]}),r===`characters`?(0,U.jsxs)(`label`,{htmlFor:`tool-token-character-factor`,className:`text-[11px] text-slate-400`,children:[(0,U.jsx)(`span`,{className:`mb-1 block font-semibold uppercase tracking-wide`,children:`Characters per token`}),(0,U.jsx)(`input`,{id:`tool-token-character-factor`,type:`number`,min:`0.1`,step:`0.1`,value:a,disabled:l,onChange:e=>o(e.target.value),className:`w-full border border-slate-700 bg-[#0b1115] px-2 py-1.5 font-mono text-xs tabular-nums text-slate-100 outline-none focus:border-[#11a4d4]`})]}):(0,U.jsxs)(`label`,{htmlFor:`tool-token-tiktoken-encoding`,className:`text-[11px] text-slate-400`,children:[(0,U.jsx)(`span`,{className:`mb-1 block font-semibold uppercase tracking-wide`,children:`Encoding`}),(0,U.jsx)(`select`,{id:`tool-token-tiktoken-encoding`,value:s,disabled:l,onChange:e=>c(e.target.value),className:`w-full border border-slate-700 bg-[#0b1115] px-2 py-1.5 font-mono text-xs text-slate-100 outline-none focus:border-[#11a4d4]`,children:mVe.map(e=>(0,U.jsx)(`option`,{value:e,children:e},e))})]})]}),(0,U.jsx)(`p`,{className:`mt-3 text-[11px] leading-relaxed text-slate-500`,children:`Character mode keeps the bounded structural estimate and divides it by the selected factor. Tiktoken lazily loads its WASM tokenizer and encodes the serialized payload at Tool start and finish, which uses more CPU and memory. Neither method is provider billing attribution.`}),(0,U.jsx)(`button`,{type:`button`,onClick:()=>void h(),disabled:n||l,className:`mt-3 border border-[#11a4d4] bg-[#11a4d4]/15 px-3 py-1.5 text-xs font-semibold text-cyan-100 hover:bg-[#11a4d4]/25 disabled:opacity-60`,children:l?`Saving…`:`Save calculation`}),d?(0,U.jsx)(`p`,{role:`status`,className:`mt-3 text-xs text-emerald-300`,children:d}):null,p?(0,U.jsx)(`p`,{role:`alert`,className:`mt-3 text-xs text-red-300`,children:p}):null]})}function r6({legend:e,unit:t,values:n,onChange:r}){return(0,U.jsxs)(`fieldset`,{className:`border border-slate-800 bg-[#111820] p-3`,children:[(0,U.jsx)(`legend`,{className:`px-1 text-xs font-semibold text-slate-200`,children:e}),(0,U.jsx)(`div`,{className:`grid gap-3 sm:grid-cols-3`,children:[`Elevated`,`High`,`Critical`].map((i,a)=>{let o=`${e.toLowerCase().replaceAll(` `,`-`)}-${i.toLowerCase()}`;return(0,U.jsxs)(`label`,{htmlFor:o,className:`text-[11px] text-slate-400`,children:[(0,U.jsx)(`span`,{className:`mb-1 block font-semibold uppercase tracking-wide`,children:i}),(0,U.jsxs)(`div`,{className:`flex items-center border border-slate-700 bg-[#0b1115] focus-within:border-[#11a4d4]`,children:[(0,U.jsx)(`input`,{id:o,type:`number`,min:t===`seconds`?`0.1`:`1`,step:t===`seconds`?`0.1`:`1`,value:n[a],onChange:e=>r(a,e.target.value),className:`min-w-0 flex-1 bg-transparent px-2 py-1.5 font-mono text-xs tabular-nums text-slate-100 outline-none`}),(0,U.jsx)(`span`,{className:`border-l border-slate-800 px-2 text-[10px] text-slate-500`,children:t})]})]},i)})})]})}function i6(e){return{durationElevated:String(e.durationMs.elevated/1e3),durationHigh:String(e.durationMs.high/1e3),durationCritical:String(e.durationMs.critical/1e3),inputElevated:String(e.inputTokens.elevated),inputHigh:String(e.inputTokens.high),inputCritical:String(e.inputTokens.critical),outputElevated:String(e.outputTokens.elevated),outputHigh:String(e.outputTokens.high),outputCritical:String(e.outputTokens.critical)}}function zWe(e){let t=[e.durationElevated,e.durationHigh,e.durationCritical].map(e=>Math.round(Number(e)*1e3)),n=[e.inputElevated,e.inputHigh,e.inputCritical].map(Number),r=[e.outputElevated,e.outputHigh,e.outputCritical].map(Number);return!a6(t)||!a6(n)||!a6(r)?null:{durationMs:{elevated:t[0],high:t[1],critical:t[2]},inputTokens:{elevated:n[0],high:n[1],critical:n[2]},outputTokens:{elevated:r[0],high:r[1],critical:r[2]}}}function a6(e){return e.every(e=>Number.isSafeInteger(e)&&e>0)&&e[0]<e[1]&&e[1]<e[2]}function BWe({piboSessionId:e,onProviderAuthChanged:t}){let[n,r]=(0,H.useState)(null),[i,a]=(0,H.useState)(!0),[o,s]=(0,H.useState)(null),[c,l]=(0,H.useState)(null),[u,d]=(0,H.useState)({}),[f,p]=(0,H.useState)({}),[m,h]=(0,H.useState)({}),[g,_]=(0,H.useState)({}),[v,y]=(0,H.useState)(null),[b,x]=(0,H.useState)({}),S=(0,H.useRef)(!1),C=(0,H.useCallback)(async(e=!1)=>{e&&a(!0);try{r(await IVe()),s(null)}catch(e){s(e instanceof Error?e.message:String(e))}finally{a(!1)}},[]);(0,H.useEffect)(()=>{C(!0)},[C]);let w=(0,H.useMemo)(()=>n?.targets.flatMap(e=>e.providers.flatMap(t=>t.pending?.completion===`notification`?[{target:e,provider:t,flowId:t.pending.flowId}]:[]))??[],[n]);(0,H.useEffect)(()=>{if(w.length===0)return;let e=async()=>{if(!S.current){S.current=!0;try{for(let{target:e,provider:n,flowId:r}of w){let i=await m4({action:`complete`,runtimeInstanceId:e.runtimeInstanceId,providerId:n.id,flowId:r});(i.state===`connected`||i.state===`partial`)&&(f6(l,`${e.displayName} / ${n.displayName??n.id} is ${l6(i.state).toLowerCase()}.`),await t?.())}await C()}catch(e){s(e instanceof Error?e.message:String(e)),await C()}finally{S.current=!1}}},n=window.setInterval(()=>void e(),1500);return()=>window.clearInterval(n)},[w,t,C]);let T=(0,H.useCallback)(async(e,t)=>{x(t=>({...t,[e]:!0})),s(null),l(null);try{return await t()}catch(e){s(e instanceof Error?e.message:String(e));return}finally{x(t=>({...t,[e]:!1}))}},[]),E=(0,H.useCallback)(async(e,t,n)=>{let r=s6(e,t);await T(r,async()=>await m4({action:`start`,runtimeInstanceId:e.runtimeInstanceId,providerId:t.id,method:n}))&&await C()},[C,T]),D=(0,H.useCallback)(async(e,n,r)=>{if(!n.pending)return;let i=s6(e,n),a=await T(i,async()=>await m4({action:`complete`,runtimeInstanceId:e.runtimeInstanceId,providerId:n.id,flowId:n.pending.flowId,...r?{code:r}:{}}));a&&((a.state===`connected`||a.state===`partial`)&&(f6(l,`${e.displayName} / ${n.displayName??n.id} is ${l6(a.state).toLowerCase()}.`),p(e=>({...e,[i]:``})),await t?.()),await C())},[t,C,T]),O=(0,H.useCallback)(async(e,t)=>{if(!t.pending)return;let n=s6(e,t);await T(n,async()=>await m4({action:`cancel`,runtimeInstanceId:e.runtimeInstanceId,providerId:t.id,flowId:t.pending.flowId}))&&await C()},[C,T]),k=(0,H.useCallback)(async(e,n)=>{let r=s6(e,n),i=m[r]?.trim();i&&await T(r,async()=>await m4({action:`api_key`,runtimeInstanceId:e.runtimeInstanceId,providerId:n.id,apiKey:i}))&&(h(e=>({...e,[r]:``})),_(e=>({...e,[r]:!1})),d(e=>({...e,[r]:`collapsed`})),f6(l,`${e.displayName} / ${n.displayName??n.id} API key is configured.`),await t?.(),await C())},[m,t,C,T]),A=(0,H.useCallback)(async(e,n)=>{let r=s6(e,n);await T(r,async()=>await m4({action:`logout`,runtimeInstanceId:e.runtimeInstanceId,providerId:n.id}))&&(f6(l,`${e.displayName} / ${n.displayName??n.id} is disconnected.`),await t?.(),await C())},[t,C,T]),j=(0,H.useCallback)(async(e,t)=>{try{await navigator.clipboard.writeText(t),y(e),window.setTimeout(()=>y(t=>t===e?null:t),1800)}catch{}},[]);return(0,U.jsxs)(`div`,{className:`grid gap-4`,children:[(0,U.jsxs)(`div`,{className:`flex items-start justify-between gap-3 border border-slate-700 bg-[#1a262b] p-3`,children:[(0,U.jsxs)(`div`,{children:[(0,U.jsx)(`div`,{className:`text-xs font-bold uppercase tracking-wider text-slate-300`,children:`Runtime authentication targets`}),(0,U.jsx)(`div`,{className:`mt-1 text-[11px] leading-relaxed text-slate-500`,children:`Each target owns its effective account. The default runtime is marked below; credentials are never copied between runtimes.`})]}),(0,U.jsxs)(`button`,{type:`button`,disabled:i,onClick:()=>void C(!0),className:`inline-flex shrink-0 items-center gap-1 border border-slate-700 bg-[#0e1116] px-2 py-1 text-[11px] text-slate-300 hover:border-[#11a4d4] hover:text-[#11a4d4] disabled:opacity-50`,children:[(0,U.jsx)(ol,{size:12,className:i?`animate-spin`:``}),` Refresh`]})]}),o?(0,U.jsx)(d6,{tone:`red`,icon:(0,U.jsx)($s,{size:14}),children:o}):null,c?(0,U.jsx)(d6,{tone:`green`,icon:(0,U.jsx)(tc,{size:14}),children:c}):null,i&&!n?(0,U.jsx)(d6,{tone:`cyan`,icon:(0,U.jsx)(Pc,{size:14,className:`animate-spin`}),children:`Loading runtime authentication status...`}):null,n?.targets.map(e=>(0,U.jsxs)(`section`,{className:`border border-[#334155] bg-[#151f24]`,children:[(0,U.jsxs)(`header`,{className:`flex flex-wrap items-start justify-between gap-3 border-b border-slate-800 px-3 py-2.5`,children:[(0,U.jsxs)(`div`,{className:`min-w-0`,children:[(0,U.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,U.jsx)(ml,{size:14,className:`text-[#11a4d4]`}),(0,U.jsx)(`span`,{className:`text-sm font-medium text-slate-200`,children:e.displayName}),(0,U.jsx)(`span`,{className:`font-mono text-[10px] text-slate-500`,children:e.runtimeInstanceId}),e.isDefault?(0,U.jsx)(u6,{tone:`cyan`,children:`Default runtime`}):null,(0,U.jsx)(WWe,{state:e.state})]}),(0,U.jsx)(`div`,{className:`mt-1 text-[11px] text-slate-500`,children:e.credentialScope===`runtime-instance`?`Private account for this configured runtime instance.`:`Shared adapter credential store; changes apply to Pi instances using this adapter.`})]}),(0,U.jsx)(`div`,{className:`font-mono text-[10px] uppercase tracking-wider text-slate-600`,children:e.adapterId})]}),e.providers.length===0?(0,U.jsx)(`div`,{className:`px-3 py-3 text-xs text-slate-500`,children:e.state===`unsupported`?`This runtime does not expose provider authentication controls.`:`Provider authentication status is unavailable for this runtime.`}):e.providers.map(t=>{let n=s6(e,t),r=u[n]??`collapsed`,i=b[n]??!1,a=t.pending;return(0,U.jsxs)(`div`,{className:`border-b border-slate-800 last:border-b-0`,children:[(0,U.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3 px-3 py-3`,children:[(0,U.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,U.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,U.jsx)(`span`,{className:`text-sm text-slate-200`,children:t.displayName??t.id}),(0,U.jsx)(`span`,{className:`font-mono text-[10px] text-slate-600`,children:t.id}),t.methods.map(e=>(0,U.jsx)(u6,{tone:e.id===`api_key`?`amber`:`purple`,children:c6(e.id)},e.id))]}),(0,U.jsxs)(`div`,{className:`mt-1 flex flex-wrap items-center gap-2 text-[11px]`,children:[(0,U.jsx)(UWe,{state:t.state}),(0,U.jsx)(`span`,{className:HWe(t.state),children:l6(t.state)}),t.details?.accountType?(0,U.jsx)(`span`,{className:`text-slate-600`,children:GWe(t.details.accountType)}):null,t.details?.planType?(0,U.jsxs)(`span`,{className:`text-slate-600`,children:[`plan: `,t.details.planType]}):null]}),t.message?(0,U.jsx)(`div`,{className:`mt-1 text-[11px] text-slate-500`,children:t.message}):null]}),(0,U.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[t.state!==`pending`&&t.methods.map(a=>a.id===`api_key`?(0,U.jsxs)(`button`,{type:`button`,disabled:i||!e.available,onClick:()=>{let e=r===`api_key`;d(t=>({...t,[n]:e?`collapsed`:`api_key`})),e&&(h(e=>({...e,[n]:``})),_(e=>({...e,[n]:!1})))},className:o6,children:[(0,U.jsx)(Dc,{size:12}),` `,t.configured?`Replace key`:`API key`]},a.id):(0,U.jsxs)(`button`,{type:`button`,disabled:i||!e.available,onClick:()=>void E(e,t,a.id),className:o6,children:[i?(0,U.jsx)(Pc,{size:12,className:`animate-spin`}):(0,U.jsx)(Ic,{size:12}),` `,t.configured?`Reconnect`:c6(a.id)]},a.id)),(t.configured||t.state===`failed`)&&e.logoutSupported?(0,U.jsxs)(`button`,{type:`button`,disabled:i,onClick:()=>void A(e,t),className:`${o6} hover:!border-red-500 hover:!text-red-300`,children:[(0,U.jsx)(Cl,{size:12}),` `,t.configured?`Disconnect`:`Reset auth`]}):null]})]}),a?(0,U.jsx)(VWe,{flow:a,rowKey:n,busy:i,code:f[n]??``,onCodeChange:e=>p(t=>({...t,[n]:e})),onComplete:n=>void D(e,t,n),onCancel:e.cancelSupported?()=>void O(e,t):void 0,copied:v,onCopy:j}):r===`api_key`?(0,U.jsxs)(`div`,{className:`grid gap-2 border-t border-slate-800 bg-[#10191d] px-3 py-3`,children:[(0,U.jsxs)(`div`,{className:`text-[10px] font-bold uppercase tracking-wider text-slate-500`,children:[`API key for `,e.runtimeInstanceId]}),(0,U.jsxs)(`div`,{className:`relative`,children:[(0,U.jsx)(`input`,{type:g[n]?`text`:`password`,value:m[n]??``,autoComplete:`off`,spellCheck:!1,onChange:e=>h(t=>({...t,[n]:e.target.value})),onKeyDown:n=>{n.key===`Enter`&&k(e,t)},placeholder:`Enter provider API key`,className:`w-full border border-slate-700 bg-[#0e1116] px-2 py-1.5 pr-8 font-mono text-[12px] text-slate-300 outline-none placeholder:text-slate-600 focus:border-[#11a4d4]`}),(0,U.jsx)(`button`,{type:`button`,onClick:()=>_(e=>({...e,[n]:!e[n]})),className:`absolute right-2 top-1/2 -translate-y-1/2 text-slate-500 hover:text-[#11a4d4]`,"aria-label":g[n]?`Hide API key`:`Show API key`,children:g[n]?(0,U.jsx)(pc,{size:14}):(0,U.jsx)(mc,{size:14})})]}),(0,U.jsxs)(`div`,{className:`flex gap-2`,children:[(0,U.jsxs)(`button`,{type:`button`,disabled:i||!(m[n]??``).trim(),onClick:()=>void k(e,t),className:o6,children:[i?(0,U.jsx)(Pc,{size:12,className:`animate-spin`}):(0,U.jsx)(tc,{size:12}),` Save for this target`]}),(0,U.jsx)(`button`,{type:`button`,onClick:()=>{h(e=>({...e,[n]:``})),_(e=>({...e,[n]:!1})),d(e=>({...e,[n]:`collapsed`}))},className:`text-[11px] text-slate-500 hover:text-[#11a4d4]`,children:`Cancel`})]})]}):null]},t.id)}),e.diagnostics.some(e=>e.severity!==`info`)?(0,U.jsx)(`div`,{className:`border-t border-slate-800 px-3 py-2 text-[11px] text-slate-500`,children:e.diagnostics.find(e=>e.severity===`error`)?.message??e.diagnostics.find(e=>e.severity===`warning`)?.message}):null]},e.runtimeInstanceId)),n&&n.targets.length===0?(0,U.jsx)(`div`,{className:`border border-slate-700 bg-[#1a262b] p-4 text-sm text-slate-500`,children:`No configured runtime authentication targets are available.`}):null]})}function VWe({flow:e,rowKey:t,busy:n,code:r,onCodeChange:i,onComplete:a,onCancel:o,copied:s,onCopy:c}){let l=e.method===`browser_oauth`&&!e.userCode;return(0,U.jsxs)(`div`,{className:`grid gap-3 border-t border-slate-800 bg-[#10191d] px-3 py-3 text-[11px]`,children:[(0,U.jsxs)(`div`,{className:`flex items-center gap-2 text-[#11a4d4]`,children:[e.completion===`notification`?(0,U.jsx)(Pc,{size:13,className:`animate-spin`}):(0,U.jsx)(ic,{size:13}),e.completion===`notification`?`Waiting for the runtime's completion notification...`:`Login flow is pending.`]}),e.verificationUrl?(0,U.jsxs)(`div`,{className:`grid gap-1.5`,children:[(0,U.jsx)(`div`,{className:`text-[10px] font-bold uppercase tracking-wider text-slate-500`,children:`Verification URL`}),(0,U.jsx)(`div`,{className:`break-all border border-slate-700 bg-[#0e1116] p-2 font-mono text-slate-300`,children:e.verificationUrl}),(0,U.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,U.jsxs)(`button`,{type:`button`,onClick:()=>void c(`${t}:url`,e.verificationUrl),className:o6,children:[s===`${t}:url`?(0,U.jsx)(tc,{size:12}):(0,U.jsx)(sc,{size:12}),` `,s===`${t}:url`?`Copied`:`Copy URL`]}),(0,U.jsxs)(`a`,{href:e.verificationUrl,target:`_blank`,rel:`noreferrer`,className:o6,children:[(0,U.jsx)(fc,{size:12}),` Open in browser`]})]})]}):null,e.userCode?(0,U.jsxs)(`div`,{className:`grid gap-1.5`,children:[(0,U.jsx)(`div`,{className:`text-[10px] font-bold uppercase tracking-wider text-slate-500`,children:`One-time code`}),(0,U.jsxs)(`button`,{type:`button`,onClick:()=>void c(`${t}:code`,e.userCode),className:`w-fit border border-[#1f4960] bg-[#0e1116] px-3 py-2 font-mono text-lg font-bold tracking-[0.2em] text-[#11a4d4] hover:border-[#11a4d4]`,children:[e.userCode,` `,s===`${t}:code`?(0,U.jsx)(tc,{size:12,className:`inline`}):null]})]}):null,e.instructions?(0,U.jsx)(`div`,{className:`text-slate-500`,children:e.instructions}):null,l?(0,U.jsx)(`input`,{value:r,autoComplete:`off`,spellCheck:!1,onChange:e=>i(e.target.value),placeholder:`Paste authorization code`,className:`border border-slate-700 bg-[#0e1116] px-2 py-1.5 font-mono text-slate-300 outline-none placeholder:text-slate-600 focus:border-[#11a4d4]`}):null,(0,U.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[e.completion===`explicit`?(0,U.jsxs)(`button`,{type:`button`,disabled:n||l&&!r.trim(),onClick:()=>a(l?r.trim():void 0),className:o6,children:[n?(0,U.jsx)(Pc,{size:12,className:`animate-spin`}):(0,U.jsx)(tc,{size:12}),` Complete login`]}):null,o?(0,U.jsxs)(`button`,{type:`button`,disabled:n,onClick:o,className:`${o6} hover:!border-red-500 hover:!text-red-300`,children:[(0,U.jsx)(rc,{size:12}),` Cancel flow`]}):null]})]})}var o6=`inline-flex items-center gap-1 border border-slate-700 bg-[#0e1116] px-2 py-1 text-[11px] text-slate-300 hover:border-[#11a4d4] hover:text-[#11a4d4] disabled:opacity-50`;function s6(e,t){return`${e.runtimeInstanceId}:${t.id}`}function c6(e){return e===`api_key`?`API key`:e===`browser_oauth`?`Browser OAuth`:`Device code`}function l6(e){return e.charAt(0).toUpperCase()+e.slice(1)}function HWe(e){return e===`connected`?`text-[#0bda57]`:e===`pending`?`text-[#11a4d4]`:e===`partial`?`text-amber-300`:e===`failed`?`text-red-300`:`text-slate-500`}function UWe({state:e}){return e===`connected`?(0,U.jsx)(tc,{size:12,className:`text-[#0bda57]`}):e===`pending`?(0,U.jsx)(Pc,{size:12,className:`animate-spin text-[#11a4d4]`}):e===`failed`?(0,U.jsx)($s,{size:12,className:`text-red-400`}):e===`partial`?(0,U.jsx)($s,{size:12,className:`text-amber-300`}):(0,U.jsx)(Ic,{size:12,className:`text-slate-500`})}function WWe({state:e}){return(0,U.jsx)(u6,{tone:e===`connected`?`green`:e===`pending`?`cyan`:e===`partial`?`amber`:e===`failed`?`red`:`neutral`,children:l6(e)})}function u6({tone:e,children:t}){return(0,U.jsx)(`span`,{className:`border px-1.5 py-0.5 text-[10px] font-mono uppercase tracking-wider ${e===`cyan`?`border-[#11a4d4]/40 text-[#6dd7f6]`:e===`green`?`border-[#0bda57]/40 text-[#7cf2a2]`:e===`amber`?`border-amber-500/40 text-amber-300`:e===`purple`?`border-purple-500/40 text-purple-300`:e===`red`?`border-red-500/40 text-red-300`:`border-slate-700 text-slate-500`}`,children:t})}function d6({tone:e,icon:t,children:n}){return(0,U.jsxs)(`div`,{className:`flex items-center gap-2 border px-3 py-2 text-xs ${e===`red`?`border-red-500/30 bg-red-500/10 text-red-300`:e===`green`?`border-[#0bda57]/30 bg-[#0bda57]/10 text-[#7cf2a2]`:`border-[#11a4d4]/30 bg-[#11a4d4]/10 text-[#6dd7f6]`}`,children:[t,n]})}function GWe(e){return e===`api_key`?`API key account`:e===`chatgpt`?`ChatGPT account`:e===`oauth`?`OAuth account`:`Managed account`}function f6(e,t){e(t),window.setTimeout(()=>e(e=>e===t?null:e),5e3)}function p6({activePanel:e,showThinking:t,setShowThinking:n,expandThinking:r,setExpandThinking:i,debugMode:a,onDebugModeChange:o,toolMetricThresholds:s,onToolMetricThresholdsChange:c,modelDefaults:l,modelCatalog:u,onModelDefaultsChanged:d,piPackages:f,onPiPackageChanged:p,onPiPackageRemoved:m,userSkills:h,onUserSkillChanged:g,onUserSkillRemoved:_,piboSessionId:v,onProviderAuthChanged:y}){return e===`pi-packages`?(0,U.jsxs)(`div`,{className:`p-6 overflow-auto`,children:[(0,U.jsxs)(`h1`,{className:`text-sm font-bold uppercase tracking-wider mb-4 flex items-center gap-2`,children:[(0,U.jsx)(kc,{size:16}),`Pi Packages`]}),(0,U.jsx)(aGe,{packages:f,onPackageChanged:p,onPackageRemoved:m})]}):e===`skills`?(0,U.jsxs)(`div`,{className:`overflow-auto p-6 max-[640px]:p-3`,children:[(0,U.jsxs)(`h1`,{className:`mb-4 flex items-center gap-2 text-sm font-bold uppercase tracking-wider`,children:[(0,U.jsx)(Al,{size:16}),`Skills`]}),(0,U.jsx)(oGe,{skills:h,onSkillChanged:g,onSkillRemoved:_})]}):e===`debug`?(0,U.jsxs)(`div`,{className:`overflow-auto p-6 max-[640px]:p-3`,children:[(0,U.jsxs)(`h1`,{className:`mb-4 flex items-center gap-2 text-sm font-bold uppercase tracking-wider`,children:[(0,U.jsx)(Vs,{size:16}),`Debug`]}),(0,U.jsx)(LWe,{debugMode:a,onDebugModeChange:o,thresholds:s,onThresholdsChange:c})]}):e===`concurrency`?(0,U.jsxs)(`div`,{className:`p-6 overflow-auto`,children:[(0,U.jsxs)(`h1`,{className:`text-sm font-bold uppercase tracking-wider mb-4 flex items-center gap-2`,children:[(0,U.jsx)(xc,{size:16}),`Concurrency`]}),(0,U.jsx)(kJ,{title:`Yielded runs`,children:(0,U.jsx)(KWe,{})})]}):e===`transcription`?(0,U.jsxs)(`div`,{className:`p-6 overflow-auto`,children:[(0,U.jsxs)(`h1`,{className:`text-sm font-bold uppercase tracking-wider mb-4 flex items-center gap-2`,children:[(0,U.jsx)(Hc,{size:16}),`Transcription`]}),(0,U.jsx)(kJ,{title:`Audio transcription`,children:(0,U.jsx)(XWe,{})})]}):e===`previews`?(0,U.jsxs)(`div`,{className:`overflow-auto p-6 max-[640px]:p-3`,children:[(0,U.jsxs)(`h1`,{className:`mb-4 flex items-center gap-2 text-sm font-bold uppercase tracking-wider`,children:[(0,U.jsx)(Wc,{size:16}),`Previews`]}),(0,U.jsx)(kJ,{title:`Managed Preview servers`,children:(0,U.jsx)(qWe,{})})]}):e===`speech`?(0,U.jsxs)(`div`,{className:`p-6 overflow-auto`,children:[(0,U.jsxs)(`h1`,{className:`text-sm font-bold uppercase tracking-wider mb-4 flex items-center gap-2`,children:[(0,U.jsx)(Ol,{size:16}),`Speech`]}),(0,U.jsx)(kJ,{title:`Text-to-speech`,children:(0,U.jsx)(ZWe,{})})]}):e===`providers`?(0,U.jsxs)(`div`,{className:`p-6 overflow-auto`,children:[(0,U.jsxs)(`h1`,{className:`text-sm font-bold uppercase tracking-wider mb-4 flex items-center gap-2`,children:[(0,U.jsx)(Dc,{size:16}),`Providers`]}),(0,U.jsx)(BWe,{piboSessionId:v,onProviderAuthChanged:y})]}):e===`shortcuts`?(0,U.jsxs)(`div`,{className:`p-6 overflow-auto`,children:[(0,U.jsxs)(`h1`,{className:`text-sm font-bold uppercase tracking-wider mb-4 flex items-center gap-2`,children:[(0,U.jsx)(Oc,{size:16}),`Shortcuts`]}),(0,U.jsx)(eGe,{})]}):e===`maintenance`?(0,U.jsxs)(`div`,{className:`p-6 overflow-auto`,children:[(0,U.jsxs)(`h1`,{className:`text-sm font-bold uppercase tracking-wider mb-4 flex items-center gap-2`,children:[(0,U.jsx)(hl,{size:16}),`Maintenance`]}),(0,U.jsx)(QWe,{})]}):(0,U.jsxs)(`div`,{className:`p-6 overflow-auto`,children:[(0,U.jsxs)(`h1`,{className:`text-sm font-bold uppercase tracking-wider mb-4 flex items-center gap-2`,children:[(0,U.jsx)(hl,{size:16}),`General`]}),(0,U.jsxs)(kJ,{title:`General`,children:[(0,U.jsx)(YWe,{}),(0,U.jsx)(PJ,{checked:t,title:`Show thinking blocks`,onToggle:()=>{let e=!t;n(e),CY(e)}}),(0,U.jsx)(PJ,{checked:r,disabled:!t,title:`Expand thinking blocks`,onToggle:()=>{let e=!r;i(e),wY(e)}}),(0,U.jsx)(iGe,{modelDefaults:l,modelCatalog:u,onChanged:d})]})]})}function KWe(){let e=kn(),{data:t,isLoading:n}=Wn({queryKey:[`gateway-settings`],queryFn:HTe}),[r,i]=(0,H.useState)(`50`),[a,o]=(0,H.useState)(`10`),[s,c]=(0,H.useState)(!1),[l,u]=(0,H.useState)(null),[d,f]=(0,H.useState)(null);(0,H.useEffect)(()=>{t&&(i(String(t.maxConcurrentYieldedRuns)),o(String(t.sessionConcurrentYieldedRuns)))},[t]);let p=async()=>{let t=Number(r),n=Number(a);if(!Number.isSafeInteger(t)||t<1){f(`Gateway concurrency must be a positive integer.`);return}if(!Number.isSafeInteger(n)||n<1){f(`Session concurrency must be a positive integer.`);return}c(!0),u(null),f(null);try{let r=await UTe({maxConcurrentYieldedRuns:t,sessionConcurrentYieldedRuns:n});i(String(r.maxConcurrentYieldedRuns)),o(String(r.sessionConcurrentYieldedRuns)),e.setQueryData([`gateway-settings`],r),u(`Concurrency settings saved. New yielded runs use these limits immediately.`)}catch(e){f(e instanceof Error?e.message:String(e))}finally{c(!1)}};return(0,U.jsxs)(`div`,{className:`max-w-xl`,children:[(0,U.jsx)(`p`,{className:`mb-4 text-xs text-slate-400`,children:`Limit concurrent yielded tool and subagent runs across the gateway and within each controlling Pibo Session.`}),(0,U.jsxs)(`div`,{className:`grid gap-4 sm:grid-cols-2 @max-[520px]:grid-cols-1`,children:[(0,U.jsxs)(`label`,{className:`block text-xs text-slate-300`,htmlFor:`gateway-concurrent-yielded-runs`,children:[(0,U.jsx)(`span`,{className:`mb-1 block font-semibold`,children:`Gateway limit`}),(0,U.jsx)(`input`,{id:`gateway-concurrent-yielded-runs`,type:`number`,min:`1`,step:`1`,value:r,disabled:n||s,onChange:e=>i(e.target.value),className:`w-full rounded-sm border border-slate-700 bg-[#0e1116] px-3 py-2 font-mono text-sm outline-none focus:border-[#11a4d4] disabled:opacity-60`}),(0,U.jsx)(`span`,{className:`mt-1 block text-[11px] text-slate-500`,children:`Default: 50 across this gateway.`})]}),(0,U.jsxs)(`label`,{className:`block text-xs text-slate-300`,htmlFor:`session-concurrent-yielded-runs`,children:[(0,U.jsx)(`span`,{className:`mb-1 block font-semibold`,children:`Per-session limit`}),(0,U.jsx)(`input`,{id:`session-concurrent-yielded-runs`,type:`number`,min:`1`,step:`1`,value:a,disabled:n||s,onChange:e=>o(e.target.value),className:`w-full rounded-sm border border-slate-700 bg-[#0e1116] px-3 py-2 font-mono text-sm outline-none focus:border-[#11a4d4] disabled:opacity-60`}),(0,U.jsx)(`span`,{className:`mt-1 block text-[11px] text-slate-500`,children:`Default: 10 for each controlling session.`})]})]}),(0,U.jsxs)(`div`,{className:`mt-4 flex items-center gap-3`,children:[(0,U.jsx)(`button`,{type:`button`,disabled:n||s,onClick:()=>void p(),className:`whitespace-nowrap rounded-sm bg-[#11a4d4] px-3 py-2 text-xs font-semibold text-white hover:bg-[#0d8db7] disabled:opacity-60`,children:s?`Saving…`:`Save limits`}),l?(0,U.jsx)(`span`,{className:`text-xs text-green-400`,children:l}):null]}),d?(0,U.jsx)(`div`,{className:`mt-3 text-xs text-red-300`,children:d}):null,(0,U.jsx)(`p`,{className:`mt-4 font-mono text-[10px] text-slate-500`,children:`Environment fallbacks: PIBO_GATEWAY_MAX_CONCURRENT_YIELDED_RUNS and PIBO_SESSION_CONCURRENT_YIELDED_RUNS.`})]})}function qWe(){let e=kn(),t=Wn({queryKey:[`user-settings`],queryFn:qH}),[n,r]=(0,H.useState)(`3`),[i,a]=(0,H.useState)(`10`),[o,s]=(0,H.useState)(!1),[c,l]=(0,H.useState)(null),[u,d]=(0,H.useState)(null);(0,H.useEffect)(()=>{t.data?.previewServers&&(r(String(t.data.previewServers.maxRunningServers)),a(String(t.data.previewServers.autoStopMinutes)))},[t.data?.previewServers]);let f=async()=>{let t=Number(n),o=Number(i);if(!Number.isSafeInteger(t)||t<1||t>20){d(`Maximum running servers must be an integer from 1 to 20.`);return}if(!Number.isSafeInteger(o)||o<1||o>1440){d(`Automatic stop must be an integer from 1 to 1440 minutes.`);return}s(!0),l(null),d(null);try{let n=await JH({previewServers:{maxRunningServers:t,autoStopMinutes:o}});e.setQueryData([`user-settings`],n),r(String(n.previewServers.maxRunningServers)),a(String(n.previewServers.autoStopMinutes)),l(`Preview server settings saved.`)}catch(e){d(e instanceof Error?e.message:String(e))}finally{s(!1)}};return(0,U.jsxs)(`div`,{className:`max-w-2xl space-y-5`,children:[(0,U.jsxs)(`label`,{className:`block`,htmlFor:`preview-max-running`,children:[(0,U.jsx)(`span`,{className:`mb-1 block text-xs font-semibold uppercase tracking-wider text-slate-400`,children:`Maximum running servers`}),(0,U.jsx)(`input`,{id:`preview-max-running`,type:`number`,min:`1`,max:`20`,step:`1`,value:n,disabled:t.isLoading||o,onChange:e=>r(e.target.value),className:`w-32 rounded-sm border border-slate-700 bg-[#0e1116] px-3 py-2 font-mono text-sm outline-none focus:border-[#11a4d4] disabled:opacity-60`}),(0,U.jsx)(`span`,{className:`mt-1 block text-[11px] text-slate-500`,children:`Managed starts fail when the instance-wide pool is full. Existing servers are never stopped to make room.`})]}),(0,U.jsxs)(`label`,{className:`block`,htmlFor:`preview-auto-stop`,children:[(0,U.jsx)(`span`,{className:`mb-1 block text-xs font-semibold uppercase tracking-wider text-slate-400`,children:`Automatic stop after each start`}),(0,U.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,U.jsx)(`input`,{id:`preview-auto-stop`,type:`number`,min:`1`,max:`1440`,step:`1`,value:i,disabled:t.isLoading||o,onChange:e=>a(e.target.value),className:`w-32 rounded-sm border border-slate-700 bg-[#0e1116] px-3 py-2 font-mono text-sm outline-none focus:border-[#11a4d4] disabled:opacity-60`}),(0,U.jsx)(`span`,{className:`text-xs text-slate-500`,children:`minutes`})]}),(0,U.jsx)(`span`,{className:`mt-1 block text-[11px] text-slate-500`,children:`This is a fixed runtime lease, not an inactivity timer. A stopped Preview remains restartable.`})]}),(0,U.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,U.jsx)(`button`,{type:`button`,disabled:t.isLoading||o,onClick:()=>void f(),className:`rounded-sm bg-[#11a4d4] px-3 py-2 text-xs font-semibold text-white hover:bg-[#0d8db7] disabled:cursor-not-allowed disabled:opacity-50`,children:o?`Saving…`:`Save Preview settings`}),c?(0,U.jsx)(`span`,{className:`text-xs text-green-400`,role:`status`,children:c}):null]}),t.error?(0,U.jsx)(`div`,{className:`text-xs text-red-300`,role:`alert`,children:t.error instanceof Error?t.error.message:String(t.error)}):null,u?(0,U.jsx)(`div`,{className:`text-xs text-red-300`,role:`alert`,children:u}):null]})}var JWe=`UTC.Europe/Berlin.Europe/London.Europe/Paris.Europe/Madrid.Europe/Rome.Europe/Amsterdam.Europe/Vienna.Europe/Zurich.Europe/Warsaw.Europe/Istanbul.America/New_York.America/Chicago.America/Denver.America/Los_Angeles.America/Toronto.America/Sao_Paulo.America/Mexico_City.Asia/Dubai.Asia/Jerusalem.Asia/Kolkata.Asia/Bangkok.Asia/Singapore.Asia/Shanghai.Asia/Tokyo.Asia/Seoul.Australia/Sydney.Australia/Melbourne.Pacific/Auckland`.split(`.`);function YWe(){let e=kn(),{data:t,isLoading:n}=Wn({queryKey:[`user-settings`],queryFn:qH}),r=(0,H.useMemo)(()=>tGe(t?.timezone),[t?.timezone]),[i,a]=(0,H.useState)(`UTC`),[o,s]=(0,H.useState)(!1),[c,l]=(0,H.useState)(null);(0,H.useEffect)(()=>{t?.timezone&&a(t.timezone)},[t?.timezone]);let u=async(t=i)=>{s(!0),l(null);try{let n=await JH({timezone:t});a(n.timezone),e.setQueryData([`user-settings`],n)}catch(e){l(e instanceof Error?e.message:String(e))}finally{s(!1)}};return(0,U.jsxs)(`div`,{className:`border-b border-slate-800 pb-4 mb-4`,children:[(0,U.jsx)(`label`,{htmlFor:`app-timezone`,className:`mb-2 block text-xs font-semibold uppercase tracking-wider text-slate-400`,children:`App timezone`}),(0,U.jsx)(`div`,{className:`max-w-xl`,children:(0,U.jsx)(`select`,{id:`app-timezone`,value:i,disabled:n||o,onChange:e=>{let t=e.target.value;a(t),u(t)},className:`w-full min-w-0 rounded-sm border border-slate-700 bg-[#0e1116] px-3 py-2 text-sm outline-none focus:border-[#11a4d4] disabled:opacity-60`,children:r.map(e=>(0,U.jsx)(`option`,{value:e.value,children:e.label},e.value))})}),(0,U.jsx)(`div`,{className:`mt-2 text-[11px] text-slate-500`,children:`Choose a city-based timezone. Changes are saved automatically and loaded into every runtime context together with the current Pibo Session ID.`}),o?(0,U.jsx)(`div`,{className:`mt-2 text-xs text-slate-400`,children:`Saving…`}):null,c?(0,U.jsx)(`div`,{className:`mt-2 text-xs text-red-300`,children:c}):null]})}function XWe(){let e=kn(),t=Wn({queryKey:[`user-settings`],queryFn:qH}),n=Wn({queryKey:[`transcription-providers`],queryFn:gNe}),r=n.data?.providers??[],i=t.data?.transcription.providerId??n.data?.selectedProviderId??``,[a,o]=(0,H.useState)(``),[s,c]=(0,H.useState)(!1),[l,u]=(0,H.useState)(null);(0,H.useEffect)(()=>{i&&o(i)},[i]);let d=async t=>{o(t),c(!0),u(null);try{let n=await JH({transcription:{providerId:t}});e.setQueryData([`user-settings`],n),e.setQueryData([`transcription-providers`],e=>e&&{...e,selectedProviderId:n.transcription.providerId}),o(n.transcription.providerId)}catch(e){o(i),u(e instanceof Error?e.message:String(e))}finally{c(!1)}},f=r.some(e=>e.id===a);return(0,U.jsxs)(`div`,{children:[(0,U.jsx)(`div`,{className:`mb-2 text-xs font-semibold uppercase tracking-wider text-slate-400`,children:`Transcription provider`}),(0,U.jsx)(`div`,{className:`max-w-xl`,children:(0,U.jsxs)(`select`,{value:a,disabled:t.isLoading||n.isLoading||s||r.length===0,onChange:e=>void d(e.target.value),className:`w-full min-w-0 rounded-sm border border-slate-700 bg-[#0e1116] px-3 py-2 text-sm outline-none focus:border-[#11a4d4] disabled:opacity-60`,children:[a&&!f?(0,U.jsxs)(`option`,{value:a,children:[a,` (unavailable)`]}):null,r.map(e=>(0,U.jsxs)(`option`,{value:e.id,children:[e.name,e.configured?``:` — authentication required`]},e.id))]})}),(0,U.jsx)(`div`,{className:`mt-2 text-[11px] text-slate-500`,children:`This selection is independent from the providers used by chat models. Recordings use the selected provider and are inserted into the composer without sending the message.`}),r.find(e=>e.id===a)?.description?(0,U.jsx)(`div`,{className:`mt-2 text-[11px] text-slate-400`,children:r.find(e=>e.id===a)?.description}):null,r.length===0&&!n.isLoading?(0,U.jsx)(`div`,{className:`mt-2 text-xs text-amber-300`,children:`No transcription providers are registered.`}):null,n.error?(0,U.jsx)(`div`,{className:`mt-2 text-xs text-red-300`,children:n.error instanceof Error?n.error.message:String(n.error)}):null,s?(0,U.jsx)(`div`,{className:`mt-2 text-xs text-slate-400`,children:`Saving…`}):null,l?(0,U.jsx)(`div`,{className:`mt-2 text-xs text-red-300`,children:l}):null]})}function ZWe(){let e=kn(),t=Wn({queryKey:[`user-settings`],queryFn:qH}),n=Wn({queryKey:[`speech-providers`],queryFn:RBe}),r=n.data?.providers??[],i=t.data?.speech.providerId??n.data?.selectedProviderId??``,[a,o]=(0,H.useState)(``),[s,c]=(0,H.useState)(!1),[l,u]=(0,H.useState)(null);(0,H.useEffect)(()=>{i&&o(i)},[i]);let d=async t=>{let n=r.find(e=>e.id===t);if(!n?.configured){u(n?`${n.name} requires authentication`:`Unknown speech provider "${t}"`);return}o(t),c(!0),u(null);try{let n=await JH({speech:{providerId:t}});e.setQueryData([`user-settings`],n),e.setQueryData([`speech-providers`],e=>e&&{...e,selectedProviderId:n.speech.providerId}),o(n.speech.providerId)}catch(e){o(i),u(e instanceof Error?e.message:String(e))}finally{c(!1)}},f=r.find(e=>e.id===a),p=!!f;return(0,U.jsxs)(`div`,{children:[(0,U.jsx)(`div`,{className:`mb-2 text-xs font-semibold uppercase tracking-wider text-slate-400`,children:`Speech provider`}),(0,U.jsx)(`div`,{className:`max-w-xl`,children:(0,U.jsxs)(`select`,{value:a,disabled:t.isLoading||n.isLoading||s||r.length===0,onChange:e=>void d(e.target.value),"aria-describedby":`speech-provider-help speech-provider-status`,className:`w-full min-w-0 rounded-sm border border-slate-700 bg-[#0e1116] px-3 py-2 text-sm outline-none focus:border-[#11a4d4] disabled:opacity-60`,children:[a&&!p?(0,U.jsxs)(`option`,{value:a,children:[a,` (unavailable)`]}):null,r.map(e=>(0,U.jsxs)(`option`,{value:e.id,disabled:!e.configured,children:[e.name,e.configured?``:` — authentication required`]},e.id))]})}),(0,U.jsx)(`div`,{id:`speech-provider-help`,className:`mt-2 text-[11px] text-slate-500`,children:`Assistant-message audio uses this provider independently from transcription, chat-model providers, and future preview settings. The initial provider uses the ChatGPT/Codex subscription configured under Providers for the Native Codex runtime.`}),f?.description?(0,U.jsx)(`div`,{className:`mt-2 text-[11px] text-slate-400`,children:f.description}):null,(0,U.jsxs)(`div`,{id:`speech-provider-status`,"aria-live":`polite`,children:[r.length===0&&!n.isLoading&&!n.error?(0,U.jsx)(`div`,{className:`mt-2 text-xs text-amber-300`,children:`No speech providers are registered.`}):null,n.error?(0,U.jsx)(`div`,{className:`mt-2 text-xs text-red-300`,role:`alert`,children:n.error instanceof Error?n.error.message:String(n.error)}):null,a&&!p&&!n.isLoading&&!n.error?(0,U.jsx)(`div`,{className:`mt-2 text-xs text-amber-300`,children:`The selected speech provider is unavailable. Choose a configured provider.`}):null,f&&!f.configured?(0,U.jsxs)(`div`,{className:`mt-2 text-xs text-amber-300`,children:[f.name,` requires authentication before it can read messages aloud.`]}):null,s?(0,U.jsx)(`div`,{className:`mt-2 text-xs text-slate-400`,children:`Saving…`}):null,l?(0,U.jsx)(`div`,{className:`mt-2 text-xs text-red-300`,role:`alert`,children:l}):null]})]})}function QWe(){let e=kn(),{data:t,isLoading:n}=Wn({queryKey:[`user-settings`],queryFn:qH}),[r,i]=(0,H.useState)(30),[a,o]=(0,H.useState)(!0),[s,c]=(0,H.useState)(10),[l,u]=(0,H.useState)(!1),[d,f]=(0,H.useState)(!1),[p,m]=(0,H.useState)(null),[h,g]=(0,H.useState)(null),_=t?.telemetryRetention?.lastPrunedAt,v=Number.isInteger(s)&&s>=1&&s<=365;(0,H.useEffect)(()=>{t?.telemetryRetention&&(o(t.telemetryRetention.enabled),i(t.telemetryRetention.days),c(t.telemetryRetention.days))},[t?.telemetryRetention]);let y=async t=>{let n=t.enabled??a,s=$We(t.days??r);o(n),i(s),u(!0),g(null),m(null);try{let t=await JH({telemetryRetention:{enabled:n,days:s}});e.setQueryData([`user-settings`],t),o(t.telemetryRetention.enabled),i(t.telemetryRetention.days),m(`Telemetry retention settings saved.`)}catch(e){g(e instanceof Error?e.message:String(e))}finally{u(!1)}},b=async()=>{if(!v){g(`Manual cleanup retention must be between 1 and 365 days.`);return}let t=s;f(!0),g(null),m(null);try{let n=await WTe({days:t}),r=await qH();e.setQueryData([`user-settings`],r),m(`Deleted ${n.rowsDeleted.toLocaleString()} telemetry rows older than ${t} days. Cutoff: ${n.cutoff}.`)}catch(e){g(e instanceof Error?e.message:String(e))}finally{f(!1)}};return(0,U.jsx)(kJ,{title:`Telemetry retention`,children:(0,U.jsxs)(`div`,{className:`space-y-5`,children:[(0,U.jsxs)(`div`,{className:`rounded-sm border border-slate-800 bg-[#101d22] p-4`,children:[(0,U.jsx)(`div`,{className:`mb-2 text-xs font-semibold uppercase tracking-wider text-slate-300`,children:`Automatic cleanup`}),(0,U.jsx)(`p`,{className:`mb-4 max-w-2xl text-xs leading-5 text-slate-400`,children:`Pibo keeps sessions, rooms, chat messages, and renderable trace events. This retention policy deletes only runtime telemetry/debug rows older than the configured age.`}),(0,U.jsxs)(`label`,{className:`mb-4 flex items-center gap-3 text-sm text-slate-200`,children:[(0,U.jsx)(`input`,{type:`checkbox`,checked:a,disabled:n||l,onChange:e=>void y({enabled:e.target.checked}),className:`h-4 w-4 accent-[#11a4d4]`}),`Enable automatic telemetry retention`]}),(0,U.jsxs)(`div`,{className:`max-w-xs`,children:[(0,U.jsx)(`label`,{className:`mb-1 block text-[11px] font-semibold uppercase tracking-wider text-slate-500`,children:`Delete telemetry older than`}),(0,U.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,U.jsx)(`input`,{type:`number`,min:1,max:365,value:r,disabled:n||l,onChange:e=>i(Number(e.target.value)),onBlur:()=>void y({days:r}),className:`w-24 rounded-sm border border-slate-700 bg-[#0e1116] px-3 py-2 text-sm outline-none focus:border-[#11a4d4] disabled:opacity-60`}),(0,U.jsx)(`span`,{className:`text-xs text-slate-400`,children:`days`})]})]}),(0,U.jsx)(`div`,{className:`mt-3 text-[11px] text-slate-500`,children:`Default is 30 days. Automatic cleanup skips runs while runtime sessions are processing or streaming.`}),(0,U.jsxs)(`div`,{className:`mt-2 text-[11px] text-slate-500`,children:[`Last prune: `,_?new Date(_).toLocaleString():`never`]})]}),(0,U.jsxs)(`div`,{className:`rounded-sm border border-slate-800 bg-[#101d22] p-4`,children:[(0,U.jsx)(`div`,{className:`mb-2 text-xs font-semibold uppercase tracking-wider text-slate-300`,children:`Manual cleanup`}),(0,U.jsx)(`p`,{className:`mb-4 max-w-2xl text-xs leading-5 text-slate-400`,children:`Run retention now with a custom cutoff. This affects telemetry tables only and never deletes sessions, rooms, chat messages, or trace-render events.`}),(0,U.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,U.jsx)(`input`,{type:`number`,min:1,max:365,value:s,disabled:d,"aria-invalid":!v,onChange:e=>c(Number(e.target.value)),className:`w-24 rounded-sm border border-slate-700 bg-[#0e1116] px-3 py-2 text-sm outline-none focus:border-[#11a4d4] disabled:opacity-60`}),(0,U.jsx)(`span`,{className:`text-xs text-slate-400`,children:`days`}),(0,U.jsxs)(`button`,{type:`button`,disabled:d||!v,onClick:()=>void b(),className:`inline-flex items-center justify-center gap-2 rounded-sm border border-red-900/70 bg-red-950/30 px-3 py-2 text-xs font-semibold text-red-100 transition hover:border-red-500 disabled:cursor-not-allowed disabled:opacity-60`,children:[(0,U.jsx)(Cl,{size:13}),d?`Deleting…`:`Delete old telemetry now`]})]})]}),(0,U.jsx)(`div`,{className:`rounded-sm border border-amber-900/50 bg-amber-950/20 p-3 text-[11px] leading-5 text-amber-100`,children:`Detailed provider-event capture is intentionally off by default because it can be high-volume. Use the dedicated debug flag only for short incident windows.`}),l?(0,U.jsx)(`div`,{className:`text-xs text-slate-400`,children:`Saving…`}):null,p?(0,U.jsx)(`div`,{className:`text-xs text-emerald-300`,children:p}):null,h?(0,U.jsx)(`div`,{className:`text-xs text-red-300`,children:h}):null]})})}function $We(e){return Number.isFinite(e)?Math.max(1,Math.min(365,Math.trunc(e))):30}function eGe(){let e=kn(),{data:t,isLoading:n}=Wn({queryKey:[`user-settings`],queryFn:qH}),[r,i]=(0,H.useState)(fQ),[a,o]=(0,H.useState)(!1),[s,c]=(0,H.useState)(!1),[l,u]=(0,H.useState)(null);(0,H.useEffect)(()=>{let e=t?.shortcuts?.webAnnotationsToggle||pQ();i(e),mQ(e),hQ(e)},[t?.shortcuts?.webAnnotationsToggle]);let d=async t=>{let n=gQ(t)||`Alt+Shift+A`;i(n),c(!0),u(null);try{let t=await JH({shortcuts:{webAnnotationsToggle:n}});e.setQueryData([`user-settings`],t),mQ(t.shortcuts.webAnnotationsToggle),hQ(t.shortcuts.webAnnotationsToggle)}catch(e){u(e instanceof Error?e.message:String(e))}finally{c(!1)}};return(0,U.jsx)(kJ,{title:`Shortcuts`,children:(0,U.jsxs)(`div`,{className:`grid max-w-2xl gap-3 rounded-sm border border-slate-800 bg-[#151f24] p-3`,children:[(0,U.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[(0,U.jsxs)(`div`,{children:[(0,U.jsxs)(`div`,{className:`flex items-center gap-2 text-sm font-semibold text-slate-200`,children:[(0,U.jsx)(Is,{size:15}),` Toggle annotation mode`]}),(0,U.jsx)(`div`,{className:`mt-1 text-xs text-slate-500`,children:`Toggles the Web Annotation element mode with the pencil button.`})]}),(0,U.jsx)(`kbd`,{className:`rounded-sm border border-slate-700 bg-[#0e1116] px-2 py-1 font-mono text-xs text-[#7dd3fc]`,children:r})]}),(0,U.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,U.jsx)(`button`,{type:`button`,disabled:n||s,"aria-pressed":a,onClick:()=>{u(null),o(e=>!e)},onKeyDown:e=>{if(!a)return;if(e.key===`Escape`){e.preventDefault(),e.stopPropagation(),o(!1),u(null);return}let t=CIe(e);if(!t){[`Alt`,`Control`,`Meta`,`Shift`].includes(e.key)||(e.preventDefault(),e.stopPropagation(),u(`Use Ctrl, Alt, or Meta with another key.`));return}e.preventDefault(),e.stopPropagation(),o(!1),d(t)},className:`rounded-sm border px-3 py-2 text-xs font-medium ${a?`border-[#11a4d4] bg-[#11a4d4]/10 text-sky-100`:`border-slate-700 text-slate-300 hover:border-[#11a4d4] hover:text-[#7dd3fc]`} disabled:opacity-50`,children:a?`Press shortcut…`:`Record shortcut`}),(0,U.jsx)(`button`,{type:`button`,disabled:s||r===`Alt+Shift+A`,onClick:()=>void d(fQ),className:`rounded-sm border border-slate-700 px-3 py-2 text-xs text-slate-300 hover:border-[#11a4d4] hover:text-[#7dd3fc] disabled:opacity-50`,children:`Reset`}),s?(0,U.jsx)(`span`,{className:`text-xs text-slate-400`,children:`Saving…`}):null]}),(0,U.jsxs)(`div`,{className:`text-[11px] text-slate-500`,children:[`Default: `,fQ,`. Use a modifier combination to avoid conflicts with normal typing.`]}),l?(0,U.jsx)(`div`,{className:`text-xs text-red-300`,children:l}):null]})})}function tGe(e){let t=new Set([`UTC`,...Intl.supportedValuesOf?.(`timeZone`)??JWe]);return e&&t.add(e),[...t].map(e=>({value:e,label:nGe(e),offset:rGe(e)})).sort((e,t)=>e.offset-t.offset||e.label.localeCompare(t.label)).map(({value:e,label:t})=>({value:e,label:t}))}function nGe(e){let t=e===`UTC`?`UTC`:e.split(`/`).pop()?.replaceAll(`_`,` `)??e,n=e.includes(`/`)?e.split(`/`)[0].replaceAll(`_`,` `):void 0,r=m6(e);return`${t}${n?` (${n})`:``} — ${r}`}function m6(e){try{return new Intl.DateTimeFormat(`en-US`,{timeZone:e,timeZoneName:`shortOffset`}).formatToParts(new Date).find(e=>e.type===`timeZoneName`)?.value.replace(`GMT`,`UTC`)??e}catch{return e}}function rGe(e){let t=m6(e),n=/^UTC(?:(?<sign>[+-])(?<hours>\d{1,2})(?::(?<minutes>\d{2}))?)?$/.exec(t);return n?.groups?.sign?(n.groups.sign===`-`?-1:1)*(Number(n.groups.hours)*60+Number(n.groups.minutes??0)):0}function iGe({modelDefaults:e,modelCatalog:t,onChanged:n}){let[r,i]=(0,H.useState)(e??{}),[a,o]=(0,H.useState)(!1),[s,c]=(0,H.useState)(null);(0,H.useEffect)(()=>{i(e??{})},[e]);let l=async e=>{i(e),o(!0);try{n(await VTe(e)),c(null)}catch(e){c(e instanceof Error?e.message:String(e))}finally{o(!1)}};return(0,U.jsxs)(`div`,{className:`grid gap-3 border-t border-slate-800 pt-3`,children:[(0,U.jsx)(`div`,{className:`text-[10px] font-bold uppercase tracking-wider text-slate-500`,children:`Runtime Model Defaults`}),(0,U.jsx)(BJ,{title:`Main Agent`,modelTitle:`Main Agent Default`,model:r.main,thinking:r.mainThinking,fast:r.mainFast??!1,modelCatalog:t,readOnly:a,modelHint:`Unset to use provider fallback.`,configuredProvidersOnly:!0,onModelChange:e=>void l({...r,main:e}),onThinkingChange:e=>void l({...r,mainThinking:e}),onFastChange:e=>void l({...r,mainFast:e})}),(0,U.jsx)(BJ,{title:`Subagent`,modelTitle:`Subagent Default`,model:r.subagent,thinking:r.subagentThinking,fast:r.subagentFast??!1,modelCatalog:t,readOnly:a,modelHint:`Unset to use provider fallback.`,configuredProvidersOnly:!0,onModelChange:e=>void l({...r,subagent:e}),onThinkingChange:e=>void l({...r,subagentThinking:e}),onFastChange:e=>void l({...r,subagentFast:e})}),s?(0,U.jsx)(`div`,{className:`text-xs text-amber-100`,children:s}):null]})}function aGe({packages:e,onPackageChanged:t,onPackageRemoved:n}){let[r,i]=(0,H.useState)(``),[a,o]=(0,H.useState)(null),[s,c]=(0,H.useState)(null),[l,u]=(0,H.useState)(()=>new Set),d=e??[],f=d.filter(e=>e.installStatus===`installed`).length,p=d.filter(e=>e.enabled).length,m=async()=>{if(!a){o(`add`);try{let e=await Lke(r);t(e),i(``),u(t=>new Set(t).add(e.id)),c(null)}catch(e){c(e instanceof Error?e.message:String(e))}finally{o(null)}}},h=async e=>{if(!a){o(`${e.id}:enabled`);try{t(await Rke(e.id,{enabled:!e.enabled})),c(null)}catch(e){c(e instanceof Error?e.message:String(e))}finally{o(null)}}},g=async e=>{if(!a&&window.confirm(`Unregister Pi package "${e.name}"?`)){o(`${e.id}:delete`);try{n(await zke(e.id)),u(t=>{let n=new Set(t);return n.delete(e.id),n}),c(null)}catch(e){c(e instanceof Error?e.message:String(e))}finally{o(null)}}},_=e=>{u(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})};return(0,U.jsxs)(kJ,{title:`Pi Package Management`,children:[(0,U.jsxs)(`div`,{className:`grid gap-2`,children:[(0,U.jsxs)(`div`,{className:`grid grid-cols-[minmax(0,1fr)_auto] gap-2`,children:[(0,U.jsx)(`input`,{value:r,disabled:!e||a===`add`,onChange:e=>{let t=e.target.value;i(t),t.trim()||c(null)},className:`min-w-0 bg-[#0e1116] border border-slate-700 rounded-sm px-3 py-2 text-sm outline-none focus:border-[#11a4d4] disabled:opacity-60`,placeholder:`https://pi.dev/packages/package-name`}),(0,U.jsx)(`button`,{type:`button`,disabled:!e||a===`add`||!r.trim(),onClick:()=>void m(),title:`Add Pi Package`,"aria-label":`Add Pi Package`,className:`h-9 w-9 inline-flex items-center justify-center border border-[#11a4d4] rounded-sm text-[#11a4d4] bg-[#11a4d4]/10 disabled:opacity-50`,children:(0,U.jsx)(rl,{size:14})})]}),(0,U.jsx)(`div`,{className:`text-[11px] text-slate-500`,children:`Extensions execute code in the Pi runtime. Review package source before adding it.`}),s?(0,U.jsx)(`div`,{className:`border border-red-500/60 bg-red-500/10 text-red-200 px-3 py-2 text-sm rounded-sm`,children:s}):null,(0,U.jsxs)(`div`,{className:`font-mono text-[10px] uppercase tracking-wider text-slate-500`,children:[d.length,` registered / `,f,` installed / `,p,` enabled`]})]}),e?d.length?(0,U.jsx)(`div`,{className:`grid gap-2`,children:d.map(e=>(0,U.jsx)(cGe,{pkg:e,expanded:l.has(e.id),busy:a?.startsWith(`${e.id}:`)??!1,onToggleExpanded:()=>_(e.id),onToggleEnabled:()=>void h(e),onUnregister:()=>void g(e)},e.id))}):(0,U.jsx)(IJ,{message:`No Pi packages registered`}):(0,U.jsx)(IJ,{})]})}function oGe({skills:e,onSkillChanged:t,onSkillRemoved:n}){let[r,i]=(0,H.useState)(!1),[a,o]=(0,H.useState)(!1),[s,c]=(0,H.useState)(null),[l,u]=(0,H.useState)(``),[d,f]=(0,H.useState)(null),[p,m]=(0,H.useState)(null),h=e??[],g=h.filter(e=>e.enabled).length,_=async e=>{if(!d){f(`${e.id}:enabled`);try{t(await aG(e.id,{enabled:!e.enabled})),m(null)}catch(e){m(e instanceof Error?e.message:String(e))}finally{f(null)}}},v=async e=>{if(!d&&window.confirm(`Delete skill "${e.name}"?`)){f(`${e.id}:delete`);try{await Hke(e.id),n(e.id),m(null)}catch(e){m(e instanceof Error?e.message:String(e))}finally{f(null)}}},y=async e=>{f(`create`);try{t(await Vke(e)),i(!1),m(null)}catch(e){m(e instanceof Error?e.message:String(e))}finally{f(null)}},b=async e=>{f(`install`);try{t(await Uke(e)),o(!1),m(null)}catch(e){m(e instanceof Error?e.message:String(e))}finally{f(null)}},x=async(e,n)=>{f(`edit`);try{t(await aG(e,n)),c(null),m(null)}catch(e){m(e instanceof Error?e.message:String(e))}finally{f(null)}};return(0,U.jsxs)(U.Fragment,{children:[(0,U.jsxs)(kJ,{title:`Skill Management`,children:[(0,U.jsxs)(`div`,{className:`grid gap-2`,children:[(0,U.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,U.jsxs)(`button`,{type:`button`,disabled:d===`create`,onClick:()=>i(!0),className:`inline-flex items-center gap-2 border border-[#11a4d4] rounded-sm px-3 py-2 text-sm text-[#11a4d4] bg-[#11a4d4]/10 disabled:opacity-50`,children:[(0,U.jsx)(rl,{size:14}),`Create Skill`]}),(0,U.jsxs)(`button`,{type:`button`,disabled:d===`install`,onClick:()=>o(!0),className:`inline-flex items-center gap-2 border border-slate-700 rounded-sm px-3 py-2 text-sm text-slate-300 hover:border-[#11a4d4] hover:text-[#11a4d4] disabled:opacity-50`,children:[(0,U.jsx)(fc,{size:14}),`Install from URL`]})]}),p?(0,U.jsx)(`div`,{className:`border border-red-500/60 bg-red-500/10 text-red-200 px-3 py-2 text-sm rounded-sm`,children:p}):null,(0,U.jsxs)(`div`,{className:`font-mono text-[10px] uppercase tracking-wider text-slate-500`,children:[h.length,` skills / `,g,` enabled`]})]}),e?h.length?(0,U.jsx)(`div`,{className:`grid gap-2`,children:h.map(e=>(0,U.jsx)(`div`,{className:`border rounded-sm p-2 ${e.enabled?`border-slate-800 bg-[#151f24]`:`border-slate-800 bg-[#151f24] opacity-75`}`,children:(0,U.jsxs)(`div`,{className:`flex items-center justify-between gap-2 max-[640px]:items-start`,children:[(0,U.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,U.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-center gap-2`,children:[(0,U.jsx)(`span`,{className:`min-w-0 truncate text-sm text-slate-200`,children:e.name}),(0,U.jsx)(`span`,{className:`shrink-0 border px-1.5 py-0.5 font-mono text-[10px] uppercase tracking-wider ${e.enabled?`border-[#11a4d4]/60 text-[#7dd3fc]`:`border-slate-700 text-slate-500`}`,children:e.enabled?`enabled`:`disabled`}),(0,U.jsx)(`span`,{className:`shrink-0 border px-1.5 py-0.5 font-mono text-[10px] uppercase tracking-wider border-slate-700 text-slate-500`,children:e.scope??`global`}),(0,U.jsx)(`span`,{className:`shrink-0 border px-1.5 py-0.5 font-mono text-[10px] uppercase tracking-wider border-slate-700 text-slate-500`,children:e.source})]}),(0,U.jsx)(`div`,{className:`truncate text-xs text-slate-500`,children:e.description||e.path})]}),(0,U.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1`,children:[(0,U.jsx)(`button`,{type:`button`,disabled:d?.startsWith(`${e.id}:`)??!1,onClick:()=>void _(e),title:`${e.enabled?`Disable`:`Enable`} ${e.name}`,"aria-label":`${e.enabled?`Disable`:`Enable`} ${e.name}`,className:`h-7 w-7 inline-flex items-center justify-center border border-slate-700 rounded-sm text-slate-400 hover:border-[#11a4d4] hover:text-[#11a4d4] disabled:opacity-50`,children:e.enabled?(0,U.jsx)(il,{size:13}):(0,U.jsx)(al,{size:13})}),(0,U.jsx)(`button`,{type:`button`,disabled:d?.startsWith(`${e.id}:`)??!1,onClick:async()=>{try{let t=await Bke(e.id);c(e),u(t.markdown)}catch{c(e),u(``)}},title:`Edit ${e.name}`,"aria-label":`Edit ${e.name}`,className:`h-7 w-7 inline-flex items-center justify-center border border-slate-700 rounded-sm text-slate-400 hover:border-[#11a4d4] hover:text-[#11a4d4] disabled:opacity-50`,children:(0,U.jsx)($c,{size:13})}),(0,U.jsx)(`button`,{type:`button`,disabled:d?.startsWith(`${e.id}:`)??!1,onClick:()=>void v(e),title:`Delete ${e.name}`,"aria-label":`Delete ${e.name}`,className:`h-7 w-7 inline-flex items-center justify-center border border-slate-700 rounded-sm text-slate-400 hover:border-red-500 hover:text-red-400 disabled:opacity-50`,children:(0,U.jsx)(Cl,{size:13})})]})]})},e.id))}):(0,U.jsx)(IJ,{message:`No user skills`}):(0,U.jsx)(IJ,{})]}),r?(0,U.jsx)(g6,{title:`Create Skill`,onSave:y,onClose:()=>{i(!1),m(null)},busy:d===`create`}):null,a?(0,U.jsx)(sGe,{onInstall:b,onClose:()=>{o(!1),m(null)},busy:d===`install`}):null,s?(0,U.jsx)(g6,{title:`Edit Skill`,initialName:s.name,initialDescription:s.description,initialMarkdown:l,onSave:e=>void x(s.id,e),onClose:()=>c(null),busy:d===`edit`}):null]})}function h6({children:e,onClose:t}){return(0,U.jsxs)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/70 p-4`,children:[(0,U.jsx)(`div`,{className:`w-full max-w-2xl rounded-sm border border-slate-700 bg-[#151f24] shadow-2xl`,children:e}),(0,U.jsx)(`button`,{type:`button`,className:`absolute inset-0 -z-10`,onClick:t,"aria-label":`Close modal`})]})}function g6({title:e,initialName:t=``,initialDescription:n=``,initialMarkdown:r=``,onSave:i,onClose:a,busy:o}){let[s,c]=(0,H.useState)(t),[l,u]=(0,H.useState)(n),[d,f]=(0,H.useState)(r);return(0,U.jsxs)(h6,{onClose:a,children:[(0,U.jsxs)(`h2`,{className:`flex items-center gap-2 border-b border-slate-800 px-4 py-3 text-sm font-bold uppercase tracking-wider`,children:[(0,U.jsx)($c,{size:16}),e]}),(0,U.jsxs)(`div`,{className:`grid gap-3 p-4`,children:[(0,U.jsx)(`input`,{value:s,onChange:e=>c(e.target.value),placeholder:`Skill name (kebab-case)`,className:`min-w-0 bg-[#0e1116] border border-slate-700 rounded-sm px-3 py-2 text-sm outline-none focus:border-[#11a4d4]`}),(0,U.jsx)(`input`,{value:l,onChange:e=>u(e.target.value),placeholder:`Short description`,className:`min-w-0 bg-[#0e1116] border border-slate-700 rounded-sm px-3 py-2 text-sm outline-none focus:border-[#11a4d4]`}),(0,U.jsx)(`textarea`,{value:d,onChange:e=>f(e.target.value),placeholder:`Markdown instructions...`,rows:10,className:`min-w-0 bg-[#0e1116] border border-slate-700 rounded-sm px-3 py-2 text-sm outline-none focus:border-[#11a4d4] resize-vertical`}),(0,U.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,U.jsx)(`button`,{type:`button`,onClick:a,className:`px-3 py-2 text-sm border border-slate-700 rounded-sm hover:border-slate-500`,children:`Cancel`}),(0,U.jsx)(`button`,{type:`button`,disabled:o||!s.trim(),onClick:()=>i({name:s,description:l,markdown:d}),className:`px-3 py-2 text-sm border border-[#11a4d4] rounded-sm bg-[#11a4d4]/10 text-[#11a4d4] disabled:opacity-50`,children:o?`Saving...`:`Save`})]})]})]})}function sGe({onInstall:e,onClose:t,busy:n}){let[r,i]=(0,H.useState)(``);return(0,U.jsxs)(h6,{onClose:t,children:[(0,U.jsxs)(`h2`,{className:`flex items-center gap-2 border-b border-slate-800 px-4 py-3 text-sm font-bold uppercase tracking-wider`,children:[(0,U.jsx)(fc,{size:16}),`Install Skill`]}),(0,U.jsxs)(`div`,{className:`grid gap-3 p-4`,children:[(0,U.jsx)(`input`,{value:r,onChange:e=>i(e.target.value),placeholder:`https://skills.sh/account/skills/skill-name`,className:`min-w-0 bg-[#0e1116] border border-slate-700 rounded-sm px-3 py-2 text-sm outline-none focus:border-[#11a4d4]`}),(0,U.jsx)(`div`,{className:`text-[11px] text-slate-500`,children:`Supports skills.sh URLs, GitHub tree URLs, or account/repo shorthand.`}),(0,U.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,U.jsx)(`button`,{type:`button`,onClick:t,className:`px-3 py-2 text-sm border border-slate-700 rounded-sm hover:border-slate-500`,children:`Cancel`}),(0,U.jsx)(`button`,{type:`button`,disabled:n||!r.trim(),onClick:()=>e(r),className:`px-3 py-2 text-sm border border-[#11a4d4] rounded-sm bg-[#11a4d4]/10 text-[#11a4d4] disabled:opacity-50`,children:n?`Installing...`:`Install`})]})]})]})}function cGe({pkg:e,expanded:t,busy:n,onToggleExpanded:r,onToggleEnabled:i,onUnregister:a}){let o=e.diagnostics.some(e=>e.type===`error`);return(0,U.jsxs)(`div`,{className:`border rounded-sm ${e.enabled?`border-slate-800 bg-[#151f24]`:`border-slate-800 bg-[#151f24] opacity-75`}`,children:[(0,U.jsxs)(`div`,{className:`grid grid-cols-[1fr_auto] gap-2 p-2`,children:[(0,U.jsxs)(`div`,{className:`min-w-0`,children:[(0,U.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,U.jsx)(`span`,{className:`min-w-0 truncate text-sm text-slate-200`,children:e.name}),(0,U.jsx)(`span`,{className:`shrink-0 border px-1.5 py-0.5 font-mono text-[10px] uppercase tracking-wider ${e.enabled?`border-[#11a4d4]/60 text-[#7dd3fc]`:`border-slate-700 text-slate-500`}`,children:e.enabled?`enabled`:`disabled`}),(0,U.jsx)(`span`,{className:`shrink-0 border px-1.5 py-0.5 font-mono text-[10px] uppercase tracking-wider ${e.installStatus===`installed`?`border-[#0bda57]/50 text-green-300`:`border-[#f59e0b]/50 text-amber-100`}`,children:e.installStatus})]}),(0,U.jsx)(`div`,{className:`truncate text-xs text-slate-500`,children:e.description??e.source}),(0,U.jsx)(`div`,{className:`font-mono text-[10px] mt-1 ${o?`text-[#f59e0b]`:`text-[#11a4d4]`}`,children:DJ(e)})]}),(0,U.jsxs)(`div`,{className:`flex items-start gap-1`,children:[(0,U.jsx)(`button`,{type:`button`,onClick:r,title:t?`Hide Details`:`Show Details`,"aria-label":t?`Hide Details`:`Show Details`,className:`h-7 w-7 inline-flex items-center justify-center border border-slate-700 rounded-sm text-slate-400 hover:border-[#11a4d4] hover:text-[#11a4d4]`,children:t?(0,U.jsx)(Gs,{size:13}):(0,U.jsx)(qs,{size:13})}),(0,U.jsx)(`button`,{type:`button`,disabled:n,onClick:i,title:e.enabled?`Disable Package`:`Enable Package`,"aria-label":e.enabled?`Disable Package`:`Enable Package`,className:`h-7 w-7 inline-flex items-center justify-center border border-slate-700 rounded-sm text-slate-400 hover:border-[#11a4d4] hover:text-[#11a4d4] disabled:opacity-50`,children:e.enabled?(0,U.jsx)(il,{size:13}):(0,U.jsx)(al,{size:13})}),(0,U.jsx)(`button`,{type:`button`,disabled:n,onClick:a,title:`Unregister Package`,"aria-label":`Unregister Package`,className:`h-7 w-7 inline-flex items-center justify-center border border-slate-700 rounded-sm text-slate-400 hover:border-red-400 hover:text-red-300 disabled:opacity-50`,children:(0,U.jsx)(Cl,{size:13})})]})]}),t?(0,U.jsx)(MJ,{pkg:e}):null]})}function _6(e){if(typeof e==`string`||typeof e==`number`)return``+e;let t=``;if(Array.isArray(e))for(let n=0,r;n<e.length;n++)(r=_6(e[n]))!==``&&(t+=(t&&` `)+r);else for(let n in e)e[n]&&(t+=(t&&` `)+n);return t}var lGe={value:()=>{}};function v6(){for(var e=0,t=arguments.length,n={},r;e<t;++e){if(!(r=arguments[e]+``)||r in n||/[\s.]/.test(r))throw Error(`illegal type: `+r);n[r]=[]}return new y6(n)}function y6(e){this._=e}function uGe(e,t){return e.trim().split(/^|\s+/).map(function(e){var n=``,r=e.indexOf(`.`);if(r>=0&&(n=e.slice(r+1),e=e.slice(0,r)),e&&!t.hasOwnProperty(e))throw Error(`unknown type: `+e);return{type:e,name:n}})}y6.prototype=v6.prototype={constructor:y6,on:function(e,t){var n=this._,r=uGe(e+``,n),i,a=-1,o=r.length;if(arguments.length<2){for(;++a<o;)if((i=(e=r[a]).type)&&(i=dGe(n[i],e.name)))return i;return}if(t!=null&&typeof t!=`function`)throw Error(`invalid callback: `+t);for(;++a<o;)if(i=(e=r[a]).type)n[i]=b6(n[i],e.name,t);else if(t==null)for(i in n)n[i]=b6(n[i],e.name,null);return this},copy:function(){var e={},t=this._;for(var n in t)e[n]=t[n].slice();return new y6(e)},call:function(e,t){if((i=arguments.length-2)>0)for(var n=Array(i),r=0,i,a;r<i;++r)n[r]=arguments[r+2];if(!this._.hasOwnProperty(e))throw Error(`unknown type: `+e);for(a=this._[e],r=0,i=a.length;r<i;++r)a[r].value.apply(t,n)},apply:function(e,t,n){if(!this._.hasOwnProperty(e))throw Error(`unknown type: `+e);for(var r=this._[e],i=0,a=r.length;i<a;++i)r[i].value.apply(t,n)}};function dGe(e,t){for(var n=0,r=e.length,i;n<r;++n)if((i=e[n]).name===t)return i.value}function b6(e,t,n){for(var r=0,i=e.length;r<i;++r)if(e[r].name===t){e[r]=lGe,e=e.slice(0,r).concat(e.slice(r+1));break}return n!=null&&e.push({name:t,value:n}),e}var x6={svg:`http://www.w3.org/2000/svg`,xhtml:`http://www.w3.org/1999/xhtml`,xlink:`http://www.w3.org/1999/xlink`,xml:`http://www.w3.org/XML/1998/namespace`,xmlns:`http://www.w3.org/2000/xmlns/`};function S6(e){var t=e+=``,n=t.indexOf(`:`);return n>=0&&(t=e.slice(0,n))!==`xmlns`&&(e=e.slice(n+1)),x6.hasOwnProperty(t)?{space:x6[t],local:e}:e}function fGe(e){return function(){var t=this.ownerDocument,n=this.namespaceURI;return n===`http://www.w3.org/1999/xhtml`&&t.documentElement.namespaceURI===`http://www.w3.org/1999/xhtml`?t.createElement(e):t.createElementNS(n,e)}}function pGe(e){return function(){return this.ownerDocument.createElementNS(e.space,e.local)}}function C6(e){var t=S6(e);return(t.local?pGe:fGe)(t)}function mGe(){}function w6(e){return e==null?mGe:function(){return this.querySelector(e)}}function hGe(e){typeof e!=`function`&&(e=w6(e));for(var t=this._groups,n=t.length,r=Array(n),i=0;i<n;++i)for(var a=t[i],o=a.length,s=r[i]=Array(o),c,l,u=0;u<o;++u)(c=a[u])&&(l=e.call(c,c.__data__,u,a))&&(`__data__`in c&&(l.__data__=c.__data__),s[u]=l);return new z6(r,this._parents)}function gGe(e){return e==null?[]:Array.isArray(e)?e:Array.from(e)}function _Ge(){return[]}function T6(e){return e==null?_Ge:function(){return this.querySelectorAll(e)}}function vGe(e){return function(){return gGe(e.apply(this,arguments))}}function yGe(e){e=typeof e==`function`?vGe(e):T6(e);for(var t=this._groups,n=t.length,r=[],i=[],a=0;a<n;++a)for(var o=t[a],s=o.length,c,l=0;l<s;++l)(c=o[l])&&(r.push(e.call(c,c.__data__,l,o)),i.push(c));return new z6(r,i)}function E6(e){return function(){return this.matches(e)}}function D6(e){return function(t){return t.matches(e)}}var bGe=Array.prototype.find;function xGe(e){return function(){return bGe.call(this.children,e)}}function SGe(){return this.firstElementChild}function CGe(e){return this.select(e==null?SGe:xGe(typeof e==`function`?e:D6(e)))}var wGe=Array.prototype.filter;function TGe(){return Array.from(this.children)}function EGe(e){return function(){return wGe.call(this.children,e)}}function DGe(e){return this.selectAll(e==null?TGe:EGe(typeof e==`function`?e:D6(e)))}function OGe(e){typeof e!=`function`&&(e=E6(e));for(var t=this._groups,n=t.length,r=Array(n),i=0;i<n;++i)for(var a=t[i],o=a.length,s=r[i]=[],c,l=0;l<o;++l)(c=a[l])&&e.call(c,c.__data__,l,a)&&s.push(c);return new z6(r,this._parents)}function O6(e){return Array(e.length)}function kGe(){return new z6(this._enter||this._groups.map(O6),this._parents)}function k6(e,t){this.ownerDocument=e.ownerDocument,this.namespaceURI=e.namespaceURI,this._next=null,this._parent=e,this.__data__=t}k6.prototype={constructor:k6,appendChild:function(e){return this._parent.insertBefore(e,this._next)},insertBefore:function(e,t){return this._parent.insertBefore(e,t)},querySelector:function(e){return this._parent.querySelector(e)},querySelectorAll:function(e){return this._parent.querySelectorAll(e)}};function AGe(e){return function(){return e}}function jGe(e,t,n,r,i,a){for(var o=0,s,c=t.length,l=a.length;o<l;++o)(s=t[o])?(s.__data__=a[o],r[o]=s):n[o]=new k6(e,a[o]);for(;o<c;++o)(s=t[o])&&(i[o]=s)}function MGe(e,t,n,r,i,a,o){var s,c,l=new Map,u=t.length,d=a.length,f=Array(u),p;for(s=0;s<u;++s)(c=t[s])&&(f[s]=p=o.call(c,c.__data__,s,t)+``,l.has(p)?i[s]=c:l.set(p,c));for(s=0;s<d;++s)p=o.call(e,a[s],s,a)+``,(c=l.get(p))?(r[s]=c,c.__data__=a[s],l.delete(p)):n[s]=new k6(e,a[s]);for(s=0;s<u;++s)(c=t[s])&&l.get(f[s])===c&&(i[s]=c)}function NGe(e){return e.__data__}function PGe(e,t){if(!arguments.length)return Array.from(this,NGe);var n=t?MGe:jGe,r=this._parents,i=this._groups;typeof e!=`function`&&(e=AGe(e));for(var a=i.length,o=Array(a),s=Array(a),c=Array(a),l=0;l<a;++l){var u=r[l],d=i[l],f=d.length,p=FGe(e.call(u,u&&u.__data__,l,r)),m=p.length,h=s[l]=Array(m),g=o[l]=Array(m);n(u,d,h,g,c[l]=Array(f),p,t);for(var _=0,v=0,y,b;_<m;++_)if(y=h[_]){for(_>=v&&(v=_+1);!(b=g[v])&&++v<m;);y._next=b||null}}return o=new z6(o,r),o._enter=s,o._exit=c,o}function FGe(e){return typeof e==`object`&&`length`in e?e:Array.from(e)}function IGe(){return new z6(this._exit||this._groups.map(O6),this._parents)}function LGe(e,t,n){var r=this.enter(),i=this,a=this.exit();return typeof e==`function`?(r=e(r),r&&=r.selection()):r=r.append(e+``),t!=null&&(i=t(i),i&&=i.selection()),n==null?a.remove():n(a),r&&i?r.merge(i).order():i}function RGe(e){for(var t=e.selection?e.selection():e,n=this._groups,r=t._groups,i=n.length,a=r.length,o=Math.min(i,a),s=Array(i),c=0;c<o;++c)for(var l=n[c],u=r[c],d=l.length,f=s[c]=Array(d),p,m=0;m<d;++m)(p=l[m]||u[m])&&(f[m]=p);for(;c<i;++c)s[c]=n[c];return new z6(s,this._parents)}function zGe(){for(var e=this._groups,t=-1,n=e.length;++t<n;)for(var r=e[t],i=r.length-1,a=r[i],o;--i>=0;)(o=r[i])&&(a&&o.compareDocumentPosition(a)^4&&a.parentNode.insertBefore(o,a),a=o);return this}function BGe(e){e||=VGe;function t(t,n){return t&&n?e(t.__data__,n.__data__):!t-!n}for(var n=this._groups,r=n.length,i=Array(r),a=0;a<r;++a){for(var o=n[a],s=o.length,c=i[a]=Array(s),l,u=0;u<s;++u)(l=o[u])&&(c[u]=l);c.sort(t)}return new z6(i,this._parents).order()}function VGe(e,t){return e<t?-1:e>t?1:e>=t?0:NaN}function HGe(){var e=arguments[0];return arguments[0]=this,e.apply(null,arguments),this}function UGe(){return Array.from(this)}function WGe(){for(var e=this._groups,t=0,n=e.length;t<n;++t)for(var r=e[t],i=0,a=r.length;i<a;++i){var o=r[i];if(o)return o}return null}function GGe(){let e=0;for(let t of this)++e;return e}function KGe(){return!this.node()}function qGe(e){for(var t=this._groups,n=0,r=t.length;n<r;++n)for(var i=t[n],a=0,o=i.length,s;a<o;++a)(s=i[a])&&e.call(s,s.__data__,a,i);return this}function JGe(e){return function(){this.removeAttribute(e)}}function YGe(e){return function(){this.removeAttributeNS(e.space,e.local)}}function XGe(e,t){return function(){this.setAttribute(e,t)}}function ZGe(e,t){return function(){this.setAttributeNS(e.space,e.local,t)}}function QGe(e,t){return function(){var n=t.apply(this,arguments);n==null?this.removeAttribute(e):this.setAttribute(e,n)}}function $Ge(e,t){return function(){var n=t.apply(this,arguments);n==null?this.removeAttributeNS(e.space,e.local):this.setAttributeNS(e.space,e.local,n)}}function eKe(e,t){var n=S6(e);if(arguments.length<2){var r=this.node();return n.local?r.getAttributeNS(n.space,n.local):r.getAttribute(n)}return this.each((t==null?n.local?YGe:JGe:typeof t==`function`?n.local?$Ge:QGe:n.local?ZGe:XGe)(n,t))}function A6(e){return e.ownerDocument&&e.ownerDocument.defaultView||e.document&&e||e.defaultView}function tKe(e){return function(){this.style.removeProperty(e)}}function nKe(e,t,n){return function(){this.style.setProperty(e,t,n)}}function rKe(e,t,n){return function(){var r=t.apply(this,arguments);r==null?this.style.removeProperty(e):this.style.setProperty(e,r,n)}}function iKe(e,t,n){return arguments.length>1?this.each((t==null?tKe:typeof t==`function`?rKe:nKe)(e,t,n??``)):j6(this.node(),e)}function j6(e,t){return e.style.getPropertyValue(t)||A6(e).getComputedStyle(e,null).getPropertyValue(t)}function aKe(e){return function(){delete this[e]}}function oKe(e,t){return function(){this[e]=t}}function sKe(e,t){return function(){var n=t.apply(this,arguments);n==null?delete this[e]:this[e]=n}}function cKe(e,t){return arguments.length>1?this.each((t==null?aKe:typeof t==`function`?sKe:oKe)(e,t)):this.node()[e]}function M6(e){return e.trim().split(/^|\s+/)}function N6(e){return e.classList||new P6(e)}function P6(e){this._node=e,this._names=M6(e.getAttribute(`class`)||``)}P6.prototype={add:function(e){this._names.indexOf(e)<0&&(this._names.push(e),this._node.setAttribute(`class`,this._names.join(` `)))},remove:function(e){var t=this._names.indexOf(e);t>=0&&(this._names.splice(t,1),this._node.setAttribute(`class`,this._names.join(` `)))},contains:function(e){return this._names.indexOf(e)>=0}};function F6(e,t){for(var n=N6(e),r=-1,i=t.length;++r<i;)n.add(t[r])}function I6(e,t){for(var n=N6(e),r=-1,i=t.length;++r<i;)n.remove(t[r])}function lKe(e){return function(){F6(this,e)}}function uKe(e){return function(){I6(this,e)}}function dKe(e,t){return function(){(t.apply(this,arguments)?F6:I6)(this,e)}}function fKe(e,t){var n=M6(e+``);if(arguments.length<2){for(var r=N6(this.node()),i=-1,a=n.length;++i<a;)if(!r.contains(n[i]))return!1;return!0}return this.each((typeof t==`function`?dKe:t?lKe:uKe)(n,t))}function pKe(){this.textContent=``}function mKe(e){return function(){this.textContent=e}}function hKe(e){return function(){var t=e.apply(this,arguments);this.textContent=t??``}}function gKe(e){return arguments.length?this.each(e==null?pKe:(typeof e==`function`?hKe:mKe)(e)):this.node().textContent}function _Ke(){this.innerHTML=``}function vKe(e){return function(){this.innerHTML=e}}function yKe(e){return function(){var t=e.apply(this,arguments);this.innerHTML=t??``}}function bKe(e){return arguments.length?this.each(e==null?_Ke:(typeof e==`function`?yKe:vKe)(e)):this.node().innerHTML}function xKe(){this.nextSibling&&this.parentNode.appendChild(this)}function SKe(){return this.each(xKe)}function CKe(){this.previousSibling&&this.parentNode.insertBefore(this,this.parentNode.firstChild)}function wKe(){return this.each(CKe)}function TKe(e){var t=typeof e==`function`?e:C6(e);return this.select(function(){return this.appendChild(t.apply(this,arguments))})}function EKe(){return null}function DKe(e,t){var n=typeof e==`function`?e:C6(e),r=t==null?EKe:typeof t==`function`?t:w6(t);return this.select(function(){return this.insertBefore(n.apply(this,arguments),r.apply(this,arguments)||null)})}function OKe(){var e=this.parentNode;e&&e.removeChild(this)}function kKe(){return this.each(OKe)}function AKe(){var e=this.cloneNode(!1),t=this.parentNode;return t?t.insertBefore(e,this.nextSibling):e}function jKe(){var e=this.cloneNode(!0),t=this.parentNode;return t?t.insertBefore(e,this.nextSibling):e}function MKe(e){return this.select(e?jKe:AKe)}function NKe(e){return arguments.length?this.property(`__data__`,e):this.node().__data__}function PKe(e){return function(t){e.call(this,t,this.__data__)}}function FKe(e){return e.trim().split(/^|\s+/).map(function(e){var t=``,n=e.indexOf(`.`);return n>=0&&(t=e.slice(n+1),e=e.slice(0,n)),{type:e,name:t}})}function IKe(e){return function(){var t=this.__on;if(t){for(var n=0,r=-1,i=t.length,a;n<i;++n)a=t[n],(!e.type||a.type===e.type)&&a.name===e.name?this.removeEventListener(a.type,a.listener,a.options):t[++r]=a;++r?t.length=r:delete this.__on}}}function LKe(e,t,n){return function(){var r=this.__on,i,a=PKe(t);if(r){for(var o=0,s=r.length;o<s;++o)if((i=r[o]).type===e.type&&i.name===e.name){this.removeEventListener(i.type,i.listener,i.options),this.addEventListener(i.type,i.listener=a,i.options=n),i.value=t;return}}this.addEventListener(e.type,a,n),i={type:e.type,name:e.name,value:t,listener:a,options:n},r?r.push(i):this.__on=[i]}}function RKe(e,t,n){var r=FKe(e+``),i,a=r.length,o;if(arguments.length<2){var s=this.node().__on;if(s){for(var c=0,l=s.length,u;c<l;++c)for(i=0,u=s[c];i<a;++i)if((o=r[i]).type===u.type&&o.name===u.name)return u.value}return}for(s=t?LKe:IKe,i=0;i<a;++i)this.each(s(r[i],t,n));return this}function L6(e,t,n){var r=A6(e),i=r.CustomEvent;typeof i==`function`?i=new i(t,n):(i=r.document.createEvent(`Event`),n?(i.initEvent(t,n.bubbles,n.cancelable),i.detail=n.detail):i.initEvent(t,!1,!1)),e.dispatchEvent(i)}function zKe(e,t){return function(){return L6(this,e,t)}}function BKe(e,t){return function(){return L6(this,e,t.apply(this,arguments))}}function VKe(e,t){return this.each((typeof t==`function`?BKe:zKe)(e,t))}function*HKe(){for(var e=this._groups,t=0,n=e.length;t<n;++t)for(var r=e[t],i=0,a=r.length,o;i<a;++i)(o=r[i])&&(yield o)}var R6=[null];function z6(e,t){this._groups=e,this._parents=t}function B6(){return new z6([[document.documentElement]],R6)}function UKe(){return this}z6.prototype=B6.prototype={constructor:z6,select:hGe,selectAll:yGe,selectChild:CGe,selectChildren:DGe,filter:OGe,data:PGe,enter:kGe,exit:IGe,join:LGe,merge:RGe,selection:UKe,order:zGe,sort:BGe,call:HGe,nodes:UGe,node:WGe,size:GGe,empty:KGe,each:qGe,attr:eKe,style:iKe,property:cKe,classed:fKe,text:gKe,html:bKe,raise:SKe,lower:wKe,append:TKe,insert:DKe,remove:kKe,clone:MKe,datum:NKe,on:RKe,dispatch:VKe,[Symbol.iterator]:HKe};function V6(e){return typeof e==`string`?new z6([[document.querySelector(e)]],[document.documentElement]):new z6([[e]],R6)}function WKe(e){let t;for(;t=e.sourceEvent;)e=t;return e}function H6(e,t){if(e=WKe(e),t===void 0&&(t=e.currentTarget),t){var n=t.ownerSVGElement||t;if(n.createSVGPoint){var r=n.createSVGPoint();return r.x=e.clientX,r.y=e.clientY,r=r.matrixTransform(t.getScreenCTM().inverse()),[r.x,r.y]}if(t.getBoundingClientRect){var i=t.getBoundingClientRect();return[e.clientX-i.left-t.clientLeft,e.clientY-i.top-t.clientTop]}}return[e.pageX,e.pageY]}var GKe={passive:!1},U6={capture:!0,passive:!1};function W6(e){e.stopImmediatePropagation()}function G6(e){e.preventDefault(),e.stopImmediatePropagation()}function K6(e){var t=e.document.documentElement,n=V6(e).on(`dragstart.drag`,G6,U6);`onselectstart`in t?n.on(`selectstart.drag`,G6,U6):(t.__noselect=t.style.MozUserSelect,t.style.MozUserSelect=`none`)}function q6(e,t){var n=e.document.documentElement,r=V6(e).on(`dragstart.drag`,null);t&&(r.on(`click.drag`,G6,U6),setTimeout(function(){r.on(`click.drag`,null)},0)),`onselectstart`in n?r.on(`selectstart.drag`,null):(n.style.MozUserSelect=n.__noselect,delete n.__noselect)}var J6=e=>()=>e;function Y6(e,{sourceEvent:t,subject:n,target:r,identifier:i,active:a,x:o,y:s,dx:c,dy:l,dispatch:u}){Object.defineProperties(this,{type:{value:e,enumerable:!0,configurable:!0},sourceEvent:{value:t,enumerable:!0,configurable:!0},subject:{value:n,enumerable:!0,configurable:!0},target:{value:r,enumerable:!0,configurable:!0},identifier:{value:i,enumerable:!0,configurable:!0},active:{value:a,enumerable:!0,configurable:!0},x:{value:o,enumerable:!0,configurable:!0},y:{value:s,enumerable:!0,configurable:!0},dx:{value:c,enumerable:!0,configurable:!0},dy:{value:l,enumerable:!0,configurable:!0},_:{value:u}})}Y6.prototype.on=function(){var e=this._.on.apply(this._,arguments);return e===this._?this:e};function KKe(e){return!e.ctrlKey&&!e.button}function qKe(){return this.parentNode}function JKe(e,t){return t??{x:e.x,y:e.y}}function YKe(){return navigator.maxTouchPoints||`ontouchstart`in this}function X6(){var e=KKe,t=qKe,n=JKe,r=YKe,i={},a=v6(`start`,`drag`,`end`),o=0,s,c,l,u,d=0;function f(e){e.on(`mousedown.drag`,p).filter(r).on(`touchstart.drag`,g).on(`touchmove.drag`,_,GKe).on(`touchend.drag touchcancel.drag`,v).style(`touch-action`,`none`).style(`-webkit-tap-highlight-color`,`rgba(0,0,0,0)`)}function p(n,r){if(!(u||!e.call(this,n,r))){var i=y(this,t.call(this,n,r),n,r,`mouse`);i&&(V6(n.view).on(`mousemove.drag`,m,U6).on(`mouseup.drag`,h,U6),K6(n.view),W6(n),l=!1,s=n.clientX,c=n.clientY,i(`start`,n))}}function m(e){if(G6(e),!l){var t=e.clientX-s,n=e.clientY-c;l=t*t+n*n>d}i.mouse(`drag`,e)}function h(e){V6(e.view).on(`mousemove.drag mouseup.drag`,null),q6(e.view,l),G6(e),i.mouse(`end`,e)}function g(n,r){if(e.call(this,n,r)){var i=n.changedTouches,a=t.call(this,n,r),o=i.length,s,c;for(s=0;s<o;++s)(c=y(this,a,n,r,i[s].identifier,i[s]))&&(W6(n),c(`start`,n,i[s]))}}function _(e){var t=e.changedTouches,n=t.length,r,a;for(r=0;r<n;++r)(a=i[t[r].identifier])&&(G6(e),a(`drag`,e,t[r]))}function v(e){var t=e.changedTouches,n=t.length,r,a;for(u&&clearTimeout(u),u=setTimeout(function(){u=null},500),r=0;r<n;++r)(a=i[t[r].identifier])&&(W6(e),a(`end`,e,t[r]))}function y(e,t,r,s,c,l){var u=a.copy(),d=H6(l||r,t),p,m,h;if((h=n.call(e,new Y6(`beforestart`,{sourceEvent:r,target:f,identifier:c,active:o,x:d[0],y:d[1],dx:0,dy:0,dispatch:u}),s))!=null)return p=h.x-d[0]||0,m=h.y-d[1]||0,function n(r,a,l){var g=d,_;switch(r){case`start`:i[c]=n,_=o++;break;case`end`:delete i[c],--o;case`drag`:d=H6(l||a,t),_=o}u.call(r,e,new Y6(r,{sourceEvent:a,subject:h,target:f,identifier:c,active:_,x:d[0]+p,y:d[1]+m,dx:d[0]-g[0],dy:d[1]-g[1],dispatch:u}),s)}}return f.filter=function(t){return arguments.length?(e=typeof t==`function`?t:J6(!!t),f):e},f.container=function(e){return arguments.length?(t=typeof e==`function`?e:J6(e),f):t},f.subject=function(e){return arguments.length?(n=typeof e==`function`?e:J6(e),f):n},f.touchable=function(e){return arguments.length?(r=typeof e==`function`?e:J6(!!e),f):r},f.on=function(){var e=a.on.apply(a,arguments);return e===a?f:e},f.clickDistance=function(e){return arguments.length?(d=(e=+e)*e,f):Math.sqrt(d)},f}function Z6(e,t,n){e.prototype=t.prototype=n,n.constructor=e}function Q6(e,t){var n=Object.create(e.prototype);for(var r in t)n[r]=t[r];return n}function $6(){}var e8=.7,t8=1/e8,n8=`\\s*([+-]?\\d+)\\s*`,r8=`\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)\\s*`,i8=`\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)%\\s*`,XKe=/^#([0-9a-f]{3,8})$/,ZKe=RegExp(`^rgb\\(${n8},${n8},${n8}\\)$`),QKe=RegExp(`^rgb\\(${i8},${i8},${i8}\\)$`),$Ke=RegExp(`^rgba\\(${n8},${n8},${n8},${r8}\\)$`),eqe=RegExp(`^rgba\\(${i8},${i8},${i8},${r8}\\)$`),tqe=RegExp(`^hsl\\(${r8},${i8},${i8}\\)$`),nqe=RegExp(`^hsla\\(${r8},${i8},${i8},${r8}\\)$`),a8={aliceblue:15792383,antiquewhite:16444375,aqua:65535,aquamarine:8388564,azure:15794175,beige:16119260,bisque:16770244,black:0,blanchedalmond:16772045,blue:255,blueviolet:9055202,brown:10824234,burlywood:14596231,cadetblue:6266528,chartreuse:8388352,chocolate:13789470,coral:16744272,cornflowerblue:6591981,cornsilk:16775388,crimson:14423100,cyan:65535,darkblue:139,darkcyan:35723,darkgoldenrod:12092939,darkgray:11119017,darkgreen:25600,darkgrey:11119017,darkkhaki:12433259,darkmagenta:9109643,darkolivegreen:5597999,darkorange:16747520,darkorchid:10040012,darkred:9109504,darksalmon:15308410,darkseagreen:9419919,darkslateblue:4734347,darkslategray:3100495,darkslategrey:3100495,darkturquoise:52945,darkviolet:9699539,deeppink:16716947,deepskyblue:49151,dimgray:6908265,dimgrey:6908265,dodgerblue:2003199,firebrick:11674146,floralwhite:16775920,forestgreen:2263842,fuchsia:16711935,gainsboro:14474460,ghostwhite:16316671,gold:16766720,goldenrod:14329120,gray:8421504,green:32768,greenyellow:11403055,grey:8421504,honeydew:15794160,hotpink:16738740,indianred:13458524,indigo:4915330,ivory:16777200,khaki:15787660,lavender:15132410,lavenderblush:16773365,lawngreen:8190976,lemonchiffon:16775885,lightblue:11393254,lightcoral:15761536,lightcyan:14745599,lightgoldenrodyellow:16448210,lightgray:13882323,lightgreen:9498256,lightgrey:13882323,lightpink:16758465,lightsalmon:16752762,lightseagreen:2142890,lightskyblue:8900346,lightslategray:7833753,lightslategrey:7833753,lightsteelblue:11584734,lightyellow:16777184,lime:65280,limegreen:3329330,linen:16445670,magenta:16711935,maroon:8388608,mediumaquamarine:6737322,mediumblue:205,mediumorchid:12211667,mediumpurple:9662683,mediumseagreen:3978097,mediumslateblue:8087790,mediumspringgreen:64154,mediumturquoise:4772300,mediumvioletred:13047173,midnightblue:1644912,mintcream:16121850,mistyrose:16770273,moccasin:16770229,navajowhite:16768685,navy:128,oldlace:16643558,olive:8421376,olivedrab:7048739,orange:16753920,orangered:16729344,orchid:14315734,palegoldenrod:15657130,palegreen:10025880,paleturquoise:11529966,palevioletred:14381203,papayawhip:16773077,peachpuff:16767673,peru:13468991,pink:16761035,plum:14524637,powderblue:11591910,purple:8388736,rebeccapurple:6697881,red:16711680,rosybrown:12357519,royalblue:4286945,saddlebrown:9127187,salmon:16416882,sandybrown:16032864,seagreen:3050327,seashell:16774638,sienna:10506797,silver:12632256,skyblue:8900331,slateblue:6970061,slategray:7372944,slategrey:7372944,snow:16775930,springgreen:65407,steelblue:4620980,tan:13808780,teal:32896,thistle:14204888,tomato:16737095,turquoise:4251856,violet:15631086,wheat:16113331,white:16777215,whitesmoke:16119285,yellow:16776960,yellowgreen:10145074};Z6($6,c8,{copy(e){return Object.assign(new this.constructor,this,e)},displayable(){return this.rgb().displayable()},hex:o8,formatHex:o8,formatHex8:rqe,formatHsl:iqe,formatRgb:s8,toString:s8});function o8(){return this.rgb().formatHex()}function rqe(){return this.rgb().formatHex8()}function iqe(){return y8(this).formatHsl()}function s8(){return this.rgb().formatRgb()}function c8(e){var t,n;return e=(e+``).trim().toLowerCase(),(t=XKe.exec(e))?(n=t[1].length,t=parseInt(t[1],16),n===6?l8(t):n===3?new f8(t>>8&15|t>>4&240,t>>4&15|t&240,(t&15)<<4|t&15,1):n===8?u8(t>>24&255,t>>16&255,t>>8&255,(t&255)/255):n===4?u8(t>>12&15|t>>8&240,t>>8&15|t>>4&240,t>>4&15|t&240,((t&15)<<4|t&15)/255):null):(t=ZKe.exec(e))?new f8(t[1],t[2],t[3],1):(t=QKe.exec(e))?new f8(t[1]*255/100,t[2]*255/100,t[3]*255/100,1):(t=$Ke.exec(e))?u8(t[1],t[2],t[3],t[4]):(t=eqe.exec(e))?u8(t[1]*255/100,t[2]*255/100,t[3]*255/100,t[4]):(t=tqe.exec(e))?v8(t[1],t[2]/100,t[3]/100,1):(t=nqe.exec(e))?v8(t[1],t[2]/100,t[3]/100,t[4]):a8.hasOwnProperty(e)?l8(a8[e]):e===`transparent`?new f8(NaN,NaN,NaN,0):null}function l8(e){return new f8(e>>16&255,e>>8&255,e&255,1)}function u8(e,t,n,r){return r<=0&&(e=t=n=NaN),new f8(e,t,n,r)}function aqe(e){return e instanceof $6||(e=c8(e)),e?(e=e.rgb(),new f8(e.r,e.g,e.b,e.opacity)):new f8}function d8(e,t,n,r){return arguments.length===1?aqe(e):new f8(e,t,n,r??1)}function f8(e,t,n,r){this.r=+e,this.g=+t,this.b=+n,this.opacity=+r}Z6(f8,d8,Q6($6,{brighter(e){return e=e==null?t8:t8**+e,new f8(this.r*e,this.g*e,this.b*e,this.opacity)},darker(e){return e=e==null?e8:e8**+e,new f8(this.r*e,this.g*e,this.b*e,this.opacity)},rgb(){return this},clamp(){return new f8(g8(this.r),g8(this.g),g8(this.b),h8(this.opacity))},displayable(){return-.5<=this.r&&this.r<255.5&&-.5<=this.g&&this.g<255.5&&-.5<=this.b&&this.b<255.5&&0<=this.opacity&&this.opacity<=1},hex:p8,formatHex:p8,formatHex8:oqe,formatRgb:m8,toString:m8}));function p8(){return`#${_8(this.r)}${_8(this.g)}${_8(this.b)}`}function oqe(){return`#${_8(this.r)}${_8(this.g)}${_8(this.b)}${_8((isNaN(this.opacity)?1:this.opacity)*255)}`}function m8(){let e=h8(this.opacity);return`${e===1?`rgb(`:`rgba(`}${g8(this.r)}, ${g8(this.g)}, ${g8(this.b)}${e===1?`)`:`, ${e})`}`}function h8(e){return isNaN(e)?1:Math.max(0,Math.min(1,e))}function g8(e){return Math.max(0,Math.min(255,Math.round(e)||0))}function _8(e){return e=g8(e),(e<16?`0`:``)+e.toString(16)}function v8(e,t,n,r){return r<=0?e=t=n=NaN:n<=0||n>=1?e=t=NaN:t<=0&&(e=NaN),new b8(e,t,n,r)}function y8(e){if(e instanceof b8)return new b8(e.h,e.s,e.l,e.opacity);if(e instanceof $6||(e=c8(e)),!e)return new b8;if(e instanceof b8)return e;e=e.rgb();var t=e.r/255,n=e.g/255,r=e.b/255,i=Math.min(t,n,r),a=Math.max(t,n,r),o=NaN,s=a-i,c=(a+i)/2;return s?(o=t===a?(n-r)/s+(n<r)*6:n===a?(r-t)/s+2:(t-n)/s+4,s/=c<.5?a+i:2-a-i,o*=60):s=c>0&&c<1?0:o,new b8(o,s,c,e.opacity)}function sqe(e,t,n,r){return arguments.length===1?y8(e):new b8(e,t,n,r??1)}function b8(e,t,n,r){this.h=+e,this.s=+t,this.l=+n,this.opacity=+r}Z6(b8,sqe,Q6($6,{brighter(e){return e=e==null?t8:t8**+e,new b8(this.h,this.s,this.l*e,this.opacity)},darker(e){return e=e==null?e8:e8**+e,new b8(this.h,this.s,this.l*e,this.opacity)},rgb(){var e=this.h%360+(this.h<0)*360,t=isNaN(e)||isNaN(this.s)?0:this.s,n=this.l,r=n+(n<.5?n:1-n)*t,i=2*n-r;return new f8(C8(e>=240?e-240:e+120,i,r),C8(e,i,r),C8(e<120?e+240:e-120,i,r),this.opacity)},clamp(){return new b8(x8(this.h),S8(this.s),S8(this.l),h8(this.opacity))},displayable(){return(0<=this.s&&this.s<=1||isNaN(this.s))&&0<=this.l&&this.l<=1&&0<=this.opacity&&this.opacity<=1},formatHsl(){let e=h8(this.opacity);return`${e===1?`hsl(`:`hsla(`}${x8(this.h)}, ${S8(this.s)*100}%, ${S8(this.l)*100}%${e===1?`)`:`, ${e})`}`}}));function x8(e){return e=(e||0)%360,e<0?e+360:e}function S8(e){return Math.max(0,Math.min(1,e||0))}function C8(e,t,n){return(e<60?t+(n-t)*e/60:e<180?n:e<240?t+(n-t)*(240-e)/60:t)*255}var w8=e=>()=>e;function cqe(e,t){return function(n){return e+n*t}}function lqe(e,t,n){return e**=+n,t=t**+n-e,n=1/n,function(r){return(e+r*t)**+n}}function uqe(e){return(e=+e)==1?T8:function(t,n){return n-t?lqe(t,n,e):w8(isNaN(t)?n:t)}}function T8(e,t){var n=t-e;return n?cqe(e,n):w8(isNaN(e)?t:e)}var E8=(function e(t){var n=uqe(t);function r(e,t){var r=n((e=d8(e)).r,(t=d8(t)).r),i=n(e.g,t.g),a=n(e.b,t.b),o=T8(e.opacity,t.opacity);return function(t){return e.r=r(t),e.g=i(t),e.b=a(t),e.opacity=o(t),e+``}}return r.gamma=e,r})(1);function dqe(e,t){t||=[];var n=e?Math.min(t.length,e.length):0,r=t.slice(),i;return function(a){for(i=0;i<n;++i)r[i]=e[i]*(1-a)+t[i]*a;return r}}function fqe(e){return ArrayBuffer.isView(e)&&!(e instanceof DataView)}function pqe(e,t){var n=t?t.length:0,r=e?Math.min(n,e.length):0,i=Array(r),a=Array(n),o;for(o=0;o<r;++o)i[o]=j8(e[o],t[o]);for(;o<n;++o)a[o]=t[o];return function(e){for(o=0;o<r;++o)a[o]=i[o](e);return a}}function mqe(e,t){var n=new Date;return e=+e,t=+t,function(r){return n.setTime(e*(1-r)+t*r),n}}function D8(e,t){return e=+e,t=+t,function(n){return e*(1-n)+t*n}}function hqe(e,t){var n={},r={},i;for(i in(typeof e!=`object`||!e)&&(e={}),(typeof t!=`object`||!t)&&(t={}),t)i in e?n[i]=j8(e[i],t[i]):r[i]=t[i];return function(e){for(i in n)r[i]=n[i](e);return r}}var O8=/[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g,k8=new RegExp(O8.source,`g`);function gqe(e){return function(){return e}}function _qe(e){return function(t){return e(t)+``}}function A8(e,t){var n=O8.lastIndex=k8.lastIndex=0,r,i,a,o=-1,s=[],c=[];for(e+=``,t+=``;(r=O8.exec(e))&&(i=k8.exec(t));)(a=i.index)>n&&(a=t.slice(n,a),s[o]?s[o]+=a:s[++o]=a),(r=r[0])===(i=i[0])?s[o]?s[o]+=i:s[++o]=i:(s[++o]=null,c.push({i:o,x:D8(r,i)})),n=k8.lastIndex;return n<t.length&&(a=t.slice(n),s[o]?s[o]+=a:s[++o]=a),s.length<2?c[0]?_qe(c[0].x):gqe(t):(t=c.length,function(e){for(var n=0,r;n<t;++n)s[(r=c[n]).i]=r.x(e);return s.join(``)})}function j8(e,t){var n=typeof t,r;return t==null||n===`boolean`?w8(t):(n===`number`?D8:n===`string`?(r=c8(t))?(t=r,E8):A8:t instanceof c8?E8:t instanceof Date?mqe:fqe(t)?dqe:Array.isArray(t)?pqe:typeof t.valueOf!=`function`&&typeof t.toString!=`function`||isNaN(t)?hqe:D8)(e,t)}var M8=180/Math.PI,N8={translateX:0,translateY:0,rotate:0,skewX:0,scaleX:1,scaleY:1};function P8(e,t,n,r,i,a){var o,s,c;return(o=Math.sqrt(e*e+t*t))&&(e/=o,t/=o),(c=e*n+t*r)&&(n-=e*c,r-=t*c),(s=Math.sqrt(n*n+r*r))&&(n/=s,r/=s,c/=s),e*r<t*n&&(e=-e,t=-t,c=-c,o=-o),{translateX:i,translateY:a,rotate:Math.atan2(t,e)*M8,skewX:Math.atan(c)*M8,scaleX:o,scaleY:s}}var F8;function vqe(e){let t=new(typeof DOMMatrix==`function`?DOMMatrix:WebKitCSSMatrix)(e+``);return t.isIdentity?N8:P8(t.a,t.b,t.c,t.d,t.e,t.f)}function yqe(e){return e==null||(F8||=document.createElementNS(`http://www.w3.org/2000/svg`,`g`),F8.setAttribute(`transform`,e),!(e=F8.transform.baseVal.consolidate()))?N8:(e=e.matrix,P8(e.a,e.b,e.c,e.d,e.e,e.f))}function I8(e,t,n,r){function i(e){return e.length?e.pop()+` `:``}function a(e,r,i,a,o,s){if(e!==i||r!==a){var c=o.push(`translate(`,null,t,null,n);s.push({i:c-4,x:D8(e,i)},{i:c-2,x:D8(r,a)})}else(i||a)&&o.push(`translate(`+i+t+a+n)}function o(e,t,n,a){e===t?t&&n.push(i(n)+`rotate(`+t+r):(e-t>180?t+=360:t-e>180&&(e+=360),a.push({i:n.push(i(n)+`rotate(`,null,r)-2,x:D8(e,t)}))}function s(e,t,n,a){e===t?t&&n.push(i(n)+`skewX(`+t+r):a.push({i:n.push(i(n)+`skewX(`,null,r)-2,x:D8(e,t)})}function c(e,t,n,r,a,o){if(e!==n||t!==r){var s=a.push(i(a)+`scale(`,null,`,`,null,`)`);o.push({i:s-4,x:D8(e,n)},{i:s-2,x:D8(t,r)})}else(n!==1||r!==1)&&a.push(i(a)+`scale(`+n+`,`+r+`)`)}return function(t,n){var r=[],i=[];return t=e(t),n=e(n),a(t.translateX,t.translateY,n.translateX,n.translateY,r,i),o(t.rotate,n.rotate,r,i),s(t.skewX,n.skewX,r,i),c(t.scaleX,t.scaleY,n.scaleX,n.scaleY,r,i),t=n=null,function(e){for(var t=-1,n=i.length,a;++t<n;)r[(a=i[t]).i]=a.x(e);return r.join(``)}}}var bqe=I8(vqe,`px, `,`px)`,`deg)`),xqe=I8(yqe,`, `,`)`,`)`),Sqe=1e-12;function L8(e){return((e=Math.exp(e))+1/e)/2}function Cqe(e){return((e=Math.exp(e))-1/e)/2}function wqe(e){return((e=Math.exp(2*e))-1)/(e+1)}var R8=(function e(t,n,r){function i(e,i){var a=e[0],o=e[1],s=e[2],c=i[0],l=i[1],u=i[2],d=c-a,f=l-o,p=d*d+f*f,m,h;if(p<Sqe)h=Math.log(u/s)/t,m=function(e){return[a+e*d,o+e*f,s*Math.exp(t*e*h)]};else{var g=Math.sqrt(p),_=(u*u-s*s+r*p)/(2*s*n*g),v=(u*u-s*s-r*p)/(2*u*n*g),y=Math.log(Math.sqrt(_*_+1)-_);h=(Math.log(Math.sqrt(v*v+1)-v)-y)/t,m=function(e){var r=e*h,i=L8(y),c=s/(n*g)*(i*wqe(t*r+y)-Cqe(y));return[a+c*d,o+c*f,s*i/L8(t*r+y)]}}return m.duration=h*1e3*t/Math.SQRT2,m}return i.rho=function(t){var n=Math.max(.001,+t),r=n*n;return e(n,r,r*r)},i})(Math.SQRT2,2,4),z8=0,B8=0,V8=0,Tqe=1e3,H8,U8,W8=0,G8=0,K8=0,q8=typeof performance==`object`&&performance.now?performance:Date,Eqe=typeof window==`object`&&window.requestAnimationFrame?window.requestAnimationFrame.bind(window):function(e){setTimeout(e,17)};function J8(){return G8||=(Eqe(Dqe),q8.now()+K8)}function Dqe(){G8=0}function Y8(){this._call=this._time=this._next=null}Y8.prototype=Oqe.prototype={constructor:Y8,restart:function(e,t,n){if(typeof e!=`function`)throw TypeError(`callback is not a function`);n=(n==null?J8():+n)+(t==null?0:+t),!this._next&&U8!==this&&(U8?U8._next=this:H8=this,U8=this),this._call=e,this._time=n,X8()},stop:function(){this._call&&(this._call=null,this._time=1/0,X8())}};function Oqe(e,t,n){var r=new Y8;return r.restart(e,t,n),r}function kqe(){J8(),++z8;for(var e=H8,t;e;)(t=G8-e._time)>=0&&e._call.call(void 0,t),e=e._next;--z8}function Aqe(){G8=(W8=q8.now())+K8,z8=B8=0;try{kqe()}finally{z8=0,Mqe(),G8=0}}function jqe(){var e=q8.now(),t=e-W8;t>Tqe&&(K8-=t,W8=e)}function Mqe(){for(var e,t=H8,n,r=1/0;t;)t._call?(r>t._time&&(r=t._time),e=t,t=t._next):(n=t._next,t._next=null,t=e?e._next=n:H8=n);U8=e,X8(r)}function X8(e){z8||(B8&&=clearTimeout(B8),e-G8>24?(e<1/0&&(B8=setTimeout(Aqe,e-q8.now()-K8)),V8&&=clearInterval(V8)):(V8||=(W8=q8.now(),setInterval(jqe,Tqe)),z8=1,Eqe(Aqe)))}function Nqe(e,t,n){var r=new Y8;return t=t==null?0:+t,r.restart(n=>{r.stop(),e(n+t)},t,n),r}var Pqe=v6(`start`,`end`,`cancel`,`interrupt`),Fqe=[];function Z8(e,t,n,r,i,a){var o=e.__transition;if(!o)e.__transition={};else if(n in o)return;Iqe(e,n,{name:t,index:r,group:i,on:Pqe,tween:Fqe,time:a.time,delay:a.delay,duration:a.duration,ease:a.ease,timer:null,state:0})}function Q8(e,t){var n=e5(e,t);if(n.state>0)throw Error(`too late; already scheduled`);return n}function $8(e,t){var n=e5(e,t);if(n.state>3)throw Error(`too late; already running`);return n}function e5(e,t){var n=e.__transition;if(!n||!(n=n[t]))throw Error(`transition not found`);return n}function Iqe(e,t,n){var r=e.__transition,i;r[t]=n,n.timer=Oqe(a,0,n.time);function a(e){n.state=1,n.timer.restart(o,n.delay,n.time),n.delay<=e&&o(e-n.delay)}function o(a){var l,u,d,f;if(n.state!==1)return c();for(l in r)if(f=r[l],f.name===n.name){if(f.state===3)return Nqe(o);f.state===4?(f.state=6,f.timer.stop(),f.on.call(`interrupt`,e,e.__data__,f.index,f.group),delete r[l]):+l<t&&(f.state=6,f.timer.stop(),f.on.call(`cancel`,e,e.__data__,f.index,f.group),delete r[l])}if(Nqe(function(){n.state===3&&(n.state=4,n.timer.restart(s,n.delay,n.time),s(a))}),n.state=2,n.on.call(`start`,e,e.__data__,n.index,n.group),n.state===2){for(n.state=3,i=Array(d=n.tween.length),l=0,u=-1;l<d;++l)(f=n.tween[l].value.call(e,e.__data__,n.index,n.group))&&(i[++u]=f);i.length=u+1}}function s(t){for(var r=t<n.duration?n.ease.call(null,t/n.duration):(n.timer.restart(c),n.state=5,1),a=-1,o=i.length;++a<o;)i[a].call(e,r);n.state===5&&(n.on.call(`end`,e,e.__data__,n.index,n.group),c())}function c(){for(var i in n.state=6,n.timer.stop(),delete r[t],r)return;delete e.__transition}}function t5(e,t){var n=e.__transition,r,i,a=!0,o;if(n){for(o in t=t==null?null:t+``,n){if((r=n[o]).name!==t){a=!1;continue}i=r.state>2&&r.state<5,r.state=6,r.timer.stop(),r.on.call(i?`interrupt`:`cancel`,e,e.__data__,r.index,r.group),delete n[o]}a&&delete e.__transition}}function Lqe(e){return this.each(function(){t5(this,e)})}function Rqe(e,t){var n,r;return function(){var i=$8(this,e),a=i.tween;if(a!==n){r=n=a;for(var o=0,s=r.length;o<s;++o)if(r[o].name===t){r=r.slice(),r.splice(o,1);break}}i.tween=r}}function zqe(e,t,n){var r,i;if(typeof n!=`function`)throw Error();return function(){var a=$8(this,e),o=a.tween;if(o!==r){i=(r=o).slice();for(var s={name:t,value:n},c=0,l=i.length;c<l;++c)if(i[c].name===t){i[c]=s;break}c===l&&i.push(s)}a.tween=i}}function Bqe(e,t){var n=this._id;if(e+=``,arguments.length<2){for(var r=e5(this.node(),n).tween,i=0,a=r.length,o;i<a;++i)if((o=r[i]).name===e)return o.value;return null}return this.each((t==null?Rqe:zqe)(n,e,t))}function n5(e,t,n){var r=e._id;return e.each(function(){var e=$8(this,r);(e.value||={})[t]=n.apply(this,arguments)}),function(e){return e5(e,r).value[t]}}function Vqe(e,t){var n;return(typeof t==`number`?D8:t instanceof c8?E8:(n=c8(t))?(t=n,E8):A8)(e,t)}function Hqe(e){return function(){this.removeAttribute(e)}}function Uqe(e){return function(){this.removeAttributeNS(e.space,e.local)}}function Wqe(e,t,n){var r,i=n+``,a;return function(){var o=this.getAttribute(e);return o===i?null:o===r?a:a=t(r=o,n)}}function Gqe(e,t,n){var r,i=n+``,a;return function(){var o=this.getAttributeNS(e.space,e.local);return o===i?null:o===r?a:a=t(r=o,n)}}function Kqe(e,t,n){var r,i,a;return function(){var o,s=n(this),c;return s==null?void this.removeAttribute(e):(o=this.getAttribute(e),c=s+``,o===c?null:o===r&&c===i?a:(i=c,a=t(r=o,s)))}}function qqe(e,t,n){var r,i,a;return function(){var o,s=n(this),c;return s==null?void this.removeAttributeNS(e.space,e.local):(o=this.getAttributeNS(e.space,e.local),c=s+``,o===c?null:o===r&&c===i?a:(i=c,a=t(r=o,s)))}}function Jqe(e,t){var n=S6(e),r=n===`transform`?xqe:Vqe;return this.attrTween(e,typeof t==`function`?(n.local?qqe:Kqe)(n,r,n5(this,`attr.`+e,t)):t==null?(n.local?Uqe:Hqe)(n):(n.local?Gqe:Wqe)(n,r,t))}function Yqe(e,t){return function(n){this.setAttribute(e,t.call(this,n))}}function Xqe(e,t){return function(n){this.setAttributeNS(e.space,e.local,t.call(this,n))}}function Zqe(e,t){var n,r;function i(){var i=t.apply(this,arguments);return i!==r&&(n=(r=i)&&Xqe(e,i)),n}return i._value=t,i}function Qqe(e,t){var n,r;function i(){var i=t.apply(this,arguments);return i!==r&&(n=(r=i)&&Yqe(e,i)),n}return i._value=t,i}function $qe(e,t){var n=`attr.`+e;if(arguments.length<2)return(n=this.tween(n))&&n._value;if(t==null)return this.tween(n,null);if(typeof t!=`function`)throw Error();var r=S6(e);return this.tween(n,(r.local?Zqe:Qqe)(r,t))}function eJe(e,t){return function(){Q8(this,e).delay=+t.apply(this,arguments)}}function tJe(e,t){return t=+t,function(){Q8(this,e).delay=t}}function nJe(e){var t=this._id;return arguments.length?this.each((typeof e==`function`?eJe:tJe)(t,e)):e5(this.node(),t).delay}function rJe(e,t){return function(){$8(this,e).duration=+t.apply(this,arguments)}}function iJe(e,t){return t=+t,function(){$8(this,e).duration=t}}function aJe(e){var t=this._id;return arguments.length?this.each((typeof e==`function`?rJe:iJe)(t,e)):e5(this.node(),t).duration}function oJe(e,t){if(typeof t!=`function`)throw Error();return function(){$8(this,e).ease=t}}function sJe(e){var t=this._id;return arguments.length?this.each(oJe(t,e)):e5(this.node(),t).ease}function cJe(e,t){return function(){var n=t.apply(this,arguments);if(typeof n!=`function`)throw Error();$8(this,e).ease=n}}function lJe(e){if(typeof e!=`function`)throw Error();return this.each(cJe(this._id,e))}function uJe(e){typeof e!=`function`&&(e=E6(e));for(var t=this._groups,n=t.length,r=Array(n),i=0;i<n;++i)for(var a=t[i],o=a.length,s=r[i]=[],c,l=0;l<o;++l)(c=a[l])&&e.call(c,c.__data__,l,a)&&s.push(c);return new r5(r,this._parents,this._name,this._id)}function dJe(e){if(e._id!==this._id)throw Error();for(var t=this._groups,n=e._groups,r=t.length,i=n.length,a=Math.min(r,i),o=Array(r),s=0;s<a;++s)for(var c=t[s],l=n[s],u=c.length,d=o[s]=Array(u),f,p=0;p<u;++p)(f=c[p]||l[p])&&(d[p]=f);for(;s<r;++s)o[s]=t[s];return new r5(o,this._parents,this._name,this._id)}function fJe(e){return(e+``).trim().split(/^|\s+/).every(function(e){var t=e.indexOf(`.`);return t>=0&&(e=e.slice(0,t)),!e||e===`start`})}function pJe(e,t,n){var r,i,a=fJe(t)?Q8:$8;return function(){var o=a(this,e),s=o.on;s!==r&&(i=(r=s).copy()).on(t,n),o.on=i}}function mJe(e,t){var n=this._id;return arguments.length<2?e5(this.node(),n).on.on(e):this.each(pJe(n,e,t))}function hJe(e){return function(){var t=this.parentNode;for(var n in this.__transition)if(+n!==e)return;t&&t.removeChild(this)}}function gJe(){return this.on(`end.remove`,hJe(this._id))}function _Je(e){var t=this._name,n=this._id;typeof e!=`function`&&(e=w6(e));for(var r=this._groups,i=r.length,a=Array(i),o=0;o<i;++o)for(var s=r[o],c=s.length,l=a[o]=Array(c),u,d,f=0;f<c;++f)(u=s[f])&&(d=e.call(u,u.__data__,f,s))&&(`__data__`in u&&(d.__data__=u.__data__),l[f]=d,Z8(l[f],t,n,f,l,e5(u,n)));return new r5(a,this._parents,t,n)}function vJe(e){var t=this._name,n=this._id;typeof e!=`function`&&(e=T6(e));for(var r=this._groups,i=r.length,a=[],o=[],s=0;s<i;++s)for(var c=r[s],l=c.length,u,d=0;d<l;++d)if(u=c[d]){for(var f=e.call(u,u.__data__,d,c),p,m=e5(u,n),h=0,g=f.length;h<g;++h)(p=f[h])&&Z8(p,t,n,h,f,m);a.push(f),o.push(u)}return new r5(a,o,t,n)}var yJe=B6.prototype.constructor;function bJe(){return new yJe(this._groups,this._parents)}function xJe(e,t){var n,r,i;return function(){var a=j6(this,e),o=(this.style.removeProperty(e),j6(this,e));return a===o?null:a===n&&o===r?i:i=t(n=a,r=o)}}function SJe(e){return function(){this.style.removeProperty(e)}}function CJe(e,t,n){var r,i=n+``,a;return function(){var o=j6(this,e);return o===i?null:o===r?a:a=t(r=o,n)}}function wJe(e,t,n){var r,i,a;return function(){var o=j6(this,e),s=n(this),c=s+``;return s??(c=s=(this.style.removeProperty(e),j6(this,e))),o===c?null:o===r&&c===i?a:(i=c,a=t(r=o,s))}}function TJe(e,t){var n,r,i,a=`style.`+t,o=`end.`+a,s;return function(){var c=$8(this,e),l=c.on,u=c.value[a]==null?s||=SJe(t):void 0;(l!==n||i!==u)&&(r=(n=l).copy()).on(o,i=u),c.on=r}}function EJe(e,t,n){var r=(e+=``)==`transform`?bqe:Vqe;return t==null?this.styleTween(e,xJe(e,r)).on(`end.style.`+e,SJe(e)):typeof t==`function`?this.styleTween(e,wJe(e,r,n5(this,`style.`+e,t))).each(TJe(this._id,e)):this.styleTween(e,CJe(e,r,t),n).on(`end.style.`+e,null)}function DJe(e,t,n){return function(r){this.style.setProperty(e,t.call(this,r),n)}}function OJe(e,t,n){var r,i;function a(){var a=t.apply(this,arguments);return a!==i&&(r=(i=a)&&DJe(e,a,n)),r}return a._value=t,a}function kJe(e,t,n){var r=`style.`+(e+=``);if(arguments.length<2)return(r=this.tween(r))&&r._value;if(t==null)return this.tween(r,null);if(typeof t!=`function`)throw Error();return this.tween(r,OJe(e,t,n??``))}function AJe(e){return function(){this.textContent=e}}function jJe(e){return function(){var t=e(this);this.textContent=t??``}}function MJe(e){return this.tween(`text`,typeof e==`function`?jJe(n5(this,`text`,e)):AJe(e==null?``:e+``))}function NJe(e){return function(t){this.textContent=e.call(this,t)}}function PJe(e){var t,n;function r(){var r=e.apply(this,arguments);return r!==n&&(t=(n=r)&&NJe(r)),t}return r._value=e,r}function FJe(e){var t=`text`;if(arguments.length<1)return(t=this.tween(t))&&t._value;if(e==null)return this.tween(t,null);if(typeof e!=`function`)throw Error();return this.tween(t,PJe(e))}function IJe(){for(var e=this._name,t=this._id,n=zJe(),r=this._groups,i=r.length,a=0;a<i;++a)for(var o=r[a],s=o.length,c,l=0;l<s;++l)if(c=o[l]){var u=e5(c,t);Z8(c,e,n,l,o,{time:u.time+u.delay+u.duration,delay:0,duration:u.duration,ease:u.ease})}return new r5(r,this._parents,e,n)}function LJe(){var e,t,n=this,r=n._id,i=n.size();return new Promise(function(a,o){var s={value:o},c={value:function(){--i===0&&a()}};n.each(function(){var n=$8(this,r),i=n.on;i!==e&&(t=(e=i).copy(),t._.cancel.push(s),t._.interrupt.push(s),t._.end.push(c)),n.on=t}),i===0&&a()})}var RJe=0;function r5(e,t,n,r){this._groups=e,this._parents=t,this._name=n,this._id=r}function zJe(){return++RJe}var i5=B6.prototype;r5.prototype={constructor:r5,select:_Je,selectAll:vJe,selectChild:i5.selectChild,selectChildren:i5.selectChildren,filter:uJe,merge:dJe,selection:bJe,transition:IJe,call:i5.call,nodes:i5.nodes,node:i5.node,size:i5.size,empty:i5.empty,each:i5.each,on:mJe,attr:Jqe,attrTween:$qe,style:EJe,styleTween:kJe,text:MJe,textTween:FJe,remove:gJe,tween:Bqe,delay:nJe,duration:aJe,ease:sJe,easeVarying:lJe,end:LJe,[Symbol.iterator]:i5[Symbol.iterator]};function BJe(e){return((e*=2)<=1?e*e*e:(e-=2)*e*e+2)/2}var VJe={time:null,delay:0,duration:250,ease:BJe};function HJe(e,t){for(var n;!(n=e.__transition)||!(n=n[t]);)if(!(e=e.parentNode))throw Error(`transition ${t} not found`);return n}function UJe(e){var t,n;e instanceof r5?(t=e._id,e=e._name):(t=zJe(),(n=VJe).time=J8(),e=e==null?null:e+``);for(var r=this._groups,i=r.length,a=0;a<i;++a)for(var o=r[a],s=o.length,c,l=0;l<s;++l)(c=o[l])&&Z8(c,e,t,l,o,n||HJe(c,t));return new r5(r,this._parents,e,t)}B6.prototype.interrupt=Lqe,B6.prototype.transition=UJe;var a5=e=>()=>e;function WJe(e,{sourceEvent:t,target:n,transform:r,dispatch:i}){Object.defineProperties(this,{type:{value:e,enumerable:!0,configurable:!0},sourceEvent:{value:t,enumerable:!0,configurable:!0},target:{value:n,enumerable:!0,configurable:!0},transform:{value:r,enumerable:!0,configurable:!0},_:{value:i}})}function o5(e,t,n){this.k=e,this.x=t,this.y=n}o5.prototype={constructor:o5,scale:function(e){return e===1?this:new o5(this.k*e,this.x,this.y)},translate:function(e,t){return e===0&t===0?this:new o5(this.k,this.x+this.k*e,this.y+this.k*t)},apply:function(e){return[e[0]*this.k+this.x,e[1]*this.k+this.y]},applyX:function(e){return e*this.k+this.x},applyY:function(e){return e*this.k+this.y},invert:function(e){return[(e[0]-this.x)/this.k,(e[1]-this.y)/this.k]},invertX:function(e){return(e-this.x)/this.k},invertY:function(e){return(e-this.y)/this.k},rescaleX:function(e){return e.copy().domain(e.range().map(this.invertX,this).map(e.invert,e))},rescaleY:function(e){return e.copy().domain(e.range().map(this.invertY,this).map(e.invert,e))},toString:function(){return`translate(`+this.x+`,`+this.y+`) scale(`+this.k+`)`}};var s5=new o5(1,0,0);GJe.prototype=o5.prototype;function GJe(e){for(;!e.__zoom;)if(!(e=e.parentNode))return s5;return e.__zoom}function c5(e){e.stopImmediatePropagation()}function l5(e){e.preventDefault(),e.stopImmediatePropagation()}function KJe(e){return(!e.ctrlKey||e.type===`wheel`)&&!e.button}function qJe(){var e=this;return e instanceof SVGElement?(e=e.ownerSVGElement||e,e.hasAttribute(`viewBox`)?(e=e.viewBox.baseVal,[[e.x,e.y],[e.x+e.width,e.y+e.height]]):[[0,0],[e.width.baseVal.value,e.height.baseVal.value]]):[[0,0],[e.clientWidth,e.clientHeight]]}function JJe(){return this.__zoom||s5}function YJe(e){return-e.deltaY*(e.deltaMode===1?.05:e.deltaMode?1:.002)*(e.ctrlKey?10:1)}function XJe(){return navigator.maxTouchPoints||`ontouchstart`in this}function ZJe(e,t,n){var r=e.invertX(t[0][0])-n[0][0],i=e.invertX(t[1][0])-n[1][0],a=e.invertY(t[0][1])-n[0][1],o=e.invertY(t[1][1])-n[1][1];return e.translate(i>r?(r+i)/2:Math.min(0,r)||Math.max(0,i),o>a?(a+o)/2:Math.min(0,a)||Math.max(0,o))}function QJe(){var e=KJe,t=qJe,n=ZJe,r=YJe,i=XJe,a=[0,1/0],o=[[-1/0,-1/0],[1/0,1/0]],s=250,c=R8,l=v6(`start`,`zoom`,`end`),u,d,f,p=500,m=150,h=0,g=10;function _(e){e.property(`__zoom`,JJe).on(`wheel.zoom`,w,{passive:!1}).on(`mousedown.zoom`,T).on(`dblclick.zoom`,E).filter(i).on(`touchstart.zoom`,D).on(`touchmove.zoom`,O).on(`touchend.zoom touchcancel.zoom`,k).style(`-webkit-tap-highlight-color`,`rgba(0,0,0,0)`)}_.transform=function(e,t,n,r){var i=e.selection?e.selection():e;i.property(`__zoom`,JJe),e===i?i.interrupt().each(function(){S(this,arguments).event(r).start().zoom(null,typeof t==`function`?t.apply(this,arguments):t).end()}):x(e,t,n,r)},_.scaleBy=function(e,t,n,r){_.scaleTo(e,function(){return this.__zoom.k*(typeof t==`function`?t.apply(this,arguments):t)},n,r)},_.scaleTo=function(e,r,i,a){_.transform(e,function(){var e=t.apply(this,arguments),a=this.__zoom,s=i==null?b(e):typeof i==`function`?i.apply(this,arguments):i,c=a.invert(s),l=typeof r==`function`?r.apply(this,arguments):r;return n(y(v(a,l),s,c),e,o)},i,a)},_.translateBy=function(e,r,i,a){_.transform(e,function(){return n(this.__zoom.translate(typeof r==`function`?r.apply(this,arguments):r,typeof i==`function`?i.apply(this,arguments):i),t.apply(this,arguments),o)},null,a)},_.translateTo=function(e,r,i,a,s){_.transform(e,function(){var e=t.apply(this,arguments),s=this.__zoom,c=a==null?b(e):typeof a==`function`?a.apply(this,arguments):a;return n(s5.translate(c[0],c[1]).scale(s.k).translate(typeof r==`function`?-r.apply(this,arguments):-r,typeof i==`function`?-i.apply(this,arguments):-i),e,o)},a,s)};function v(e,t){return t=Math.max(a[0],Math.min(a[1],t)),t===e.k?e:new o5(t,e.x,e.y)}function y(e,t,n){var r=t[0]-n[0]*e.k,i=t[1]-n[1]*e.k;return r===e.x&&i===e.y?e:new o5(e.k,r,i)}function b(e){return[(+e[0][0]+ +e[1][0])/2,(+e[0][1]+ +e[1][1])/2]}function x(e,n,r,i){e.on(`start.zoom`,function(){S(this,arguments).event(i).start()}).on(`interrupt.zoom end.zoom`,function(){S(this,arguments).event(i).end()}).tween(`zoom`,function(){var e=this,a=arguments,o=S(e,a).event(i),s=t.apply(e,a),l=r==null?b(s):typeof r==`function`?r.apply(e,a):r,u=Math.max(s[1][0]-s[0][0],s[1][1]-s[0][1]),d=e.__zoom,f=typeof n==`function`?n.apply(e,a):n,p=c(d.invert(l).concat(u/d.k),f.invert(l).concat(u/f.k));return function(e){if(e===1)e=f;else{var t=p(e),n=u/t[2];e=new o5(n,l[0]-t[0]*n,l[1]-t[1]*n)}o.zoom(null,e)}})}function S(e,t,n){return!n&&e.__zooming||new C(e,t)}function C(e,n){this.that=e,this.args=n,this.active=0,this.sourceEvent=null,this.extent=t.apply(e,n),this.taps=0}C.prototype={event:function(e){return e&&(this.sourceEvent=e),this},start:function(){return++this.active===1&&(this.that.__zooming=this,this.emit(`start`)),this},zoom:function(e,t){return this.mouse&&e!==`mouse`&&(this.mouse[1]=t.invert(this.mouse[0])),this.touch0&&e!==`touch`&&(this.touch0[1]=t.invert(this.touch0[0])),this.touch1&&e!==`touch`&&(this.touch1[1]=t.invert(this.touch1[0])),this.that.__zoom=t,this.emit(`zoom`),this},end:function(){return--this.active===0&&(delete this.that.__zooming,this.emit(`end`)),this},emit:function(e){var t=V6(this.that).datum();l.call(e,this.that,new WJe(e,{sourceEvent:this.sourceEvent,target:_,type:e,transform:this.that.__zoom,dispatch:l}),t)}};function w(t,...i){if(!e.apply(this,arguments))return;var s=S(this,i).event(t),c=this.__zoom,l=Math.max(a[0],Math.min(a[1],c.k*2**r.apply(this,arguments))),u=H6(t);if(s.wheel)(s.mouse[0][0]!==u[0]||s.mouse[0][1]!==u[1])&&(s.mouse[1]=c.invert(s.mouse[0]=u)),clearTimeout(s.wheel);else if(c.k===l)return;else s.mouse=[u,c.invert(u)],t5(this),s.start();l5(t),s.wheel=setTimeout(d,m),s.zoom(`mouse`,n(y(v(c,l),s.mouse[0],s.mouse[1]),s.extent,o));function d(){s.wheel=null,s.end()}}function T(t,...r){if(f||!e.apply(this,arguments))return;var i=t.currentTarget,a=S(this,r,!0).event(t),s=V6(t.view).on(`mousemove.zoom`,d,!0).on(`mouseup.zoom`,p,!0),c=H6(t,i),l=t.clientX,u=t.clientY;K6(t.view),c5(t),a.mouse=[c,this.__zoom.invert(c)],t5(this),a.start();function d(e){if(l5(e),!a.moved){var t=e.clientX-l,r=e.clientY-u;a.moved=t*t+r*r>h}a.event(e).zoom(`mouse`,n(y(a.that.__zoom,a.mouse[0]=H6(e,i),a.mouse[1]),a.extent,o))}function p(e){s.on(`mousemove.zoom mouseup.zoom`,null),q6(e.view,a.moved),l5(e),a.event(e).end()}}function E(r,...i){if(e.apply(this,arguments)){var a=this.__zoom,c=H6(r.changedTouches?r.changedTouches[0]:r,this),l=a.invert(c),u=a.k*(r.shiftKey?.5:2),d=n(y(v(a,u),c,l),t.apply(this,i),o);l5(r),s>0?V6(this).transition().duration(s).call(x,d,c,r):V6(this).call(_.transform,d,c,r)}}function D(t,...n){if(e.apply(this,arguments)){var r=t.touches,i=r.length,a=S(this,n,t.changedTouches.length===i).event(t),o,s,c,l;for(c5(t),s=0;s<i;++s)c=r[s],l=H6(c,this),l=[l,this.__zoom.invert(l),c.identifier],a.touch0?!a.touch1&&a.touch0[2]!==l[2]&&(a.touch1=l,a.taps=0):(a.touch0=l,o=!0,a.taps=1+!!u);u&&=clearTimeout(u),o&&(a.taps<2&&(d=l[0],u=setTimeout(function(){u=null},p)),t5(this),a.start())}}function O(e,...t){if(this.__zooming){var r=S(this,t).event(e),i=e.changedTouches,a=i.length,s,c,l,u;for(l5(e),s=0;s<a;++s)c=i[s],l=H6(c,this),r.touch0&&r.touch0[2]===c.identifier?r.touch0[0]=l:r.touch1&&r.touch1[2]===c.identifier&&(r.touch1[0]=l);if(c=r.that.__zoom,r.touch1){var d=r.touch0[0],f=r.touch0[1],p=r.touch1[0],m=r.touch1[1],h=(h=p[0]-d[0])*h+(h=p[1]-d[1])*h,g=(g=m[0]-f[0])*g+(g=m[1]-f[1])*g;c=v(c,Math.sqrt(h/g)),l=[(d[0]+p[0])/2,(d[1]+p[1])/2],u=[(f[0]+m[0])/2,(f[1]+m[1])/2]}else if(r.touch0)l=r.touch0[0],u=r.touch0[1];else return;r.zoom(`touch`,n(y(c,l,u),r.extent,o))}}function k(e,...t){if(this.__zooming){var n=S(this,t).event(e),r=e.changedTouches,i=r.length,a,o;for(c5(e),f&&clearTimeout(f),f=setTimeout(function(){f=null},p),a=0;a<i;++a)o=r[a],n.touch0&&n.touch0[2]===o.identifier?delete n.touch0:n.touch1&&n.touch1[2]===o.identifier&&delete n.touch1;if(n.touch1&&!n.touch0&&(n.touch0=n.touch1,delete n.touch1),n.touch0)n.touch0[1]=this.__zoom.invert(n.touch0[0]);else if(n.end(),n.taps===2&&(o=H6(o,this),Math.hypot(d[0]-o[0],d[1]-o[1])<g)){var s=V6(this).on(`dblclick.zoom`);s&&s.apply(this,arguments)}}}return _.wheelDelta=function(e){return arguments.length?(r=typeof e==`function`?e:a5(+e),_):r},_.filter=function(t){return arguments.length?(e=typeof t==`function`?t:a5(!!t),_):e},_.touchable=function(e){return arguments.length?(i=typeof e==`function`?e:a5(!!e),_):i},_.extent=function(e){return arguments.length?(t=typeof e==`function`?e:a5([[+e[0][0],+e[0][1]],[+e[1][0],+e[1][1]]]),_):t},_.scaleExtent=function(e){return arguments.length?(a[0]=+e[0],a[1]=+e[1],_):[a[0],a[1]]},_.translateExtent=function(e){return arguments.length?(o[0][0]=+e[0][0],o[1][0]=+e[1][0],o[0][1]=+e[0][1],o[1][1]=+e[1][1],_):[[o[0][0],o[0][1]],[o[1][0],o[1][1]]]},_.constrain=function(e){return arguments.length?(n=e,_):n},_.duration=function(e){return arguments.length?(s=+e,_):s},_.interpolate=function(e){return arguments.length?(c=e,_):c},_.on=function(){var e=l.on.apply(l,arguments);return e===l?_:e},_.clickDistance=function(e){return arguments.length?(h=(e=+e)*e,_):Math.sqrt(h)},_.tapDistance=function(e){return arguments.length?(g=+e,_):g},_}var u5={error001:()=>`[React Flow]: Seems like you have not used zustand provider as an ancestor. Help: https://reactflow.dev/error#001`,error002:()=>`It looks like you've created a new nodeTypes or edgeTypes object. If this wasn't on purpose please define the nodeTypes/edgeTypes outside of the component or memoize them.`,error003:e=>`Node type "${e}" not found. Using fallback type "default".`,error004:()=>`The React Flow parent container needs a width and a height to render the graph.`,error005:()=>`Only child nodes can use a parent extent.`,error006:()=>`Can't create edge. An edge needs a source and a target.`,error007:e=>`The old edge with id=${e} does not exist.`,error009:e=>`Marker type "${e}" doesn't exist.`,error008:(e,{id:t,sourceHandle:n,targetHandle:r})=>`Couldn't create edge for ${e} handle id: "${e===`source`?n:r}", edge id: ${t}.`,error010:()=>`Handle: No node id found. Make sure to only use a Handle inside a custom Node.`,error011:e=>`Edge type "${e}" not found. Using fallback type "default".`,error012:e=>`Node with id "${e}" does not exist, it may have been removed. This can happen when a node is deleted before the "onNodeClick" handler is called.`,error013:(e=`react`)=>`It seems that you haven't loaded the styles. Please import '@xyflow/${e}/dist/style.css' or base.css to make sure everything is working properly.`,error014:()=>`useNodeConnections: No node ID found. Call useNodeConnections inside a custom Node or provide a node ID.`,error015:()=>`It seems that you are trying to drag a node that is not initialized. Please use onNodesChange as explained in the docs.`},d5=[[-1/0,-1/0],[1/0,1/0]],$Je=[`Enter`,` `,`Escape`],eYe={"node.a11yDescription.default":`Press enter or space to select a node. Press delete to remove it and escape to cancel.`,"node.a11yDescription.keyboardDisabled":`Press enter or space to select a node. You can then use the arrow keys to move the node around. Press delete to remove it and escape to cancel.`,"node.a11yDescription.ariaLiveMessage":({direction:e,x:t,y:n})=>`Moved selected node ${e}. New position, x: ${t}, y: ${n}`,"edge.a11yDescription.default":`Press enter or space to select an edge. You can then press delete to remove it or escape to cancel.`,"controls.ariaLabel":`Control Panel`,"controls.zoomIn.ariaLabel":`Zoom In`,"controls.zoomOut.ariaLabel":`Zoom Out`,"controls.fitView.ariaLabel":`Fit View`,"controls.interactive.ariaLabel":`Toggle Interactivity`,"minimap.ariaLabel":`Mini Map`,"handle.ariaLabel":`Handle`},f5;(function(e){e.Strict=`strict`,e.Loose=`loose`})(f5||={});var p5;(function(e){e.Free=`free`,e.Vertical=`vertical`,e.Horizontal=`horizontal`})(p5||={});var m5;(function(e){e.Partial=`partial`,e.Full=`full`})(m5||={});var tYe={inProgress:!1,isValid:null,from:null,fromHandle:null,fromPosition:null,fromNode:null,to:null,toHandle:null,toPosition:null,toNode:null,pointer:null},h5;(function(e){e.Bezier=`default`,e.Straight=`straight`,e.Step=`step`,e.SmoothStep=`smoothstep`,e.SimpleBezier=`simplebezier`})(h5||={});var g5;(function(e){e.Arrow=`arrow`,e.ArrowClosed=`arrowclosed`})(g5||={});var _5;(function(e){e.Left=`left`,e.Top=`top`,e.Right=`right`,e.Bottom=`bottom`})(_5||={});var nYe={[_5.Left]:_5.Right,[_5.Right]:_5.Left,[_5.Top]:_5.Bottom,[_5.Bottom]:_5.Top};function rYe(e){return e===null?null:e?`valid`:`invalid`}var iYe=e=>`id`in e&&`source`in e&&`target`in e,aYe=e=>`id`in e&&`position`in e&&!(`source`in e)&&!(`target`in e),v5=e=>`id`in e&&`internals`in e&&!(`source`in e)&&!(`target`in e),y5=(e,t=[0,0])=>{let{width:n,height:r}=R5(e),i=e.origin??t,a=n*i[0],o=r*i[1];return{x:e.position.x-a,y:e.position.y-o}},oYe=(e,t={nodeOrigin:[0,0]})=>e.length===0?{x:0,y:0,width:0,height:0}:E5(e.reduce((e,n)=>{let r=typeof n==`string`,i=!t.nodeLookup&&!r?n:void 0;return t.nodeLookup&&(i=r?t.nodeLookup.get(n):v5(n)?n:t.nodeLookup.get(n.id)),w5(e,i?O5(i,t.nodeOrigin):{x:0,y:0,x2:0,y2:0})},{x:1/0,y:1/0,x2:-1/0,y2:-1/0})),b5=(e,t={})=>{let n={x:1/0,y:1/0,x2:-1/0,y2:-1/0},r=!1;return e.forEach(e=>{(t.filter===void 0||t.filter(e))&&(n=w5(n,O5(e)),r=!0)}),r?E5(n):{x:0,y:0,width:0,height:0}},x5=(e,t,[n,r,i]=[0,0,1],a=!1,o=!1)=>{let s={...M5(t,[n,r,i]),width:t.width/i,height:t.height/i},c=[];for(let t of e.values()){let{measured:e,selectable:n=!0,hidden:r=!1}=t;if(o&&!n||r)continue;let i=e.width??t.width??t.initialWidth??null,l=e.height??t.height??t.initialHeight??null,u=k5(s,D5(t)),d=(i??0)*(l??0),f=a&&u>0;(!t.internals.handleBounds||f||u>=d||t.dragging)&&c.push(t)}return c},sYe=(e,t)=>{let n=new Set;return e.forEach(e=>{n.add(e.id)}),t.filter(e=>n.has(e.source)||n.has(e.target))};function cYe(e,t){let n=new Map,r=t?.nodes?new Set(t.nodes.map(e=>e.id)):null;return e.forEach(e=>{e.measured.width&&e.measured.height&&(t?.includeHiddenNodes||!e.hidden)&&(!r||r.has(e.id))&&n.set(e.id,e)}),n}async function lYe({nodes:e,width:t,height:n,panZoom:r,minZoom:i,maxZoom:a},o){if(e.size===0)return Promise.resolve(!0);let s=F5(b5(cYe(e,o)),t,n,o?.minZoom??i,o?.maxZoom??a,o?.padding??.1);return await r.setViewport(s,{duration:o?.duration,ease:o?.ease,interpolate:o?.interpolate}),Promise.resolve(!0)}function uYe({nodeId:e,nextPosition:t,nodeLookup:n,nodeOrigin:r=[0,0],nodeExtent:i,onError:a}){let o=n.get(e),s=o.parentId?n.get(o.parentId):void 0,{x:c,y:l}=s?s.internals.positionAbsolute:{x:0,y:0},u=o.origin??r,d=o.extent||i;if(o.extent===`parent`&&!o.expandParent){if(!s)a?.(`005`,u5.error005());else{let e=s.measured.width,t=s.measured.height;e&&t&&(d=[[c,l],[c+e,l+t]])}}else s&&L5(o.extent)&&(d=[[o.extent[0][0]+c,o.extent[0][1]+l],[o.extent[1][0]+c,o.extent[1][1]+l]]);let f=L5(d)?C5(t,d,o.measured):t;return(o.measured.width===void 0||o.measured.height===void 0)&&a?.(`015`,u5.error015()),{position:{x:f.x-c+(o.measured.width??0)*u[0],y:f.y-l+(o.measured.height??0)*u[1]},positionAbsolute:f}}async function dYe({nodesToRemove:e=[],edgesToRemove:t=[],nodes:n,edges:r,onBeforeDelete:i}){let a=new Set(e.map(e=>e.id)),o=[];for(let e of n){if(e.deletable===!1)continue;let t=a.has(e.id),n=!t&&e.parentId&&o.find(t=>t.id===e.parentId);(t||n)&&o.push(e)}let s=new Set(t.map(e=>e.id)),c=r.filter(e=>e.deletable!==!1),l=sYe(o,c);for(let e of c)s.has(e.id)&&!l.find(t=>t.id===e.id)&&l.push(e);if(!i)return{edges:l,nodes:o};let u=await i({nodes:o,edges:l});return typeof u==`boolean`?u?{edges:l,nodes:o}:{edges:[],nodes:[]}:u}var S5=(e,t=0,n=1)=>Math.min(Math.max(e,t),n),C5=(e={x:0,y:0},t,n)=>({x:S5(e.x,t[0][0],t[1][0]-(n?.width??0)),y:S5(e.y,t[0][1],t[1][1]-(n?.height??0))});function fYe(e,t,n){let{width:r,height:i}=R5(n),{x:a,y:o}=n.internals.positionAbsolute;return C5(e,[[a,o],[a+r,o+i]],t)}var pYe=(e,t,n)=>e<t?S5(Math.abs(e-t),1,t)/t:e>n?-S5(Math.abs(e-n),1,t)/t:0,mYe=(e,t,n=15,r=40)=>[pYe(e.x,r,t.width-r)*n,pYe(e.y,r,t.height-r)*n],w5=(e,t)=>({x:Math.min(e.x,t.x),y:Math.min(e.y,t.y),x2:Math.max(e.x2,t.x2),y2:Math.max(e.y2,t.y2)}),T5=({x:e,y:t,width:n,height:r})=>({x:e,y:t,x2:e+n,y2:t+r}),E5=({x:e,y:t,x2:n,y2:r})=>({x:e,y:t,width:n-e,height:r-t}),D5=(e,t=[0,0])=>{let{x:n,y:r}=v5(e)?e.internals.positionAbsolute:y5(e,t);return{x:n,y:r,width:e.measured?.width??e.width??e.initialWidth??0,height:e.measured?.height??e.height??e.initialHeight??0}},O5=(e,t=[0,0])=>{let{x:n,y:r}=v5(e)?e.internals.positionAbsolute:y5(e,t);return{x:n,y:r,x2:n+(e.measured?.width??e.width??e.initialWidth??0),y2:r+(e.measured?.height??e.height??e.initialHeight??0)}},hYe=(e,t)=>E5(w5(T5(e),T5(t))),k5=(e,t)=>{let n=Math.max(0,Math.min(e.x+e.width,t.x+t.width)-Math.max(e.x,t.x)),r=Math.max(0,Math.min(e.y+e.height,t.y+t.height)-Math.max(e.y,t.y));return Math.ceil(n*r)},gYe=e=>A5(e.width)&&A5(e.height)&&A5(e.x)&&A5(e.y),A5=e=>!isNaN(e)&&isFinite(e),_Ye=(e,t)=>{},j5=(e,t=[1,1])=>({x:t[0]*Math.round(e.x/t[0]),y:t[1]*Math.round(e.y/t[1])}),M5=({x:e,y:t},[n,r,i],a=!1,o=[1,1])=>{let s={x:(e-n)/i,y:(t-r)/i};return a?j5(s,o):s},N5=({x:e,y:t},[n,r,i])=>({x:e*i+n,y:t*i+r});function P5(e,t){if(typeof e==`number`)return Math.floor((t-t/(1+e))*.5);if(typeof e==`string`&&e.endsWith(`px`)){let t=parseFloat(e);if(!Number.isNaN(t))return Math.floor(t)}if(typeof e==`string`&&e.endsWith(`%`)){let n=parseFloat(e);if(!Number.isNaN(n))return Math.floor(t*n*.01)}return console.error(`[React Flow] The padding value "${e}" is invalid. Please provide a number or a string with a valid unit (px or %).`),0}function vYe(e,t,n){if(typeof e==`string`||typeof e==`number`){let r=P5(e,n),i=P5(e,t);return{top:r,right:i,bottom:r,left:i,x:i*2,y:r*2}}if(typeof e==`object`){let r=P5(e.top??e.y??0,n),i=P5(e.bottom??e.y??0,n),a=P5(e.left??e.x??0,t),o=P5(e.right??e.x??0,t);return{top:r,right:o,bottom:i,left:a,x:a+o,y:r+i}}return{top:0,right:0,bottom:0,left:0,x:0,y:0}}function yYe(e,t,n,r,i,a){let{x:o,y:s}=N5(e,[t,n,r]),{x:c,y:l}=N5({x:e.x+e.width,y:e.y+e.height},[t,n,r]),u=i-c,d=a-l;return{left:Math.floor(o),top:Math.floor(s),right:Math.floor(u),bottom:Math.floor(d)}}var F5=(e,t,n,r,i,a)=>{let o=vYe(a,t,n),s=(t-o.x)/e.width,c=(n-o.y)/e.height,l=S5(Math.min(s,c),r,i),u=e.x+e.width/2,d=e.y+e.height/2,f=t/2-u*l,p=n/2-d*l,m=yYe(e,f,p,l,t,n),h={left:Math.min(m.left-o.left,0),top:Math.min(m.top-o.top,0),right:Math.min(m.right-o.right,0),bottom:Math.min(m.bottom-o.bottom,0)};return{x:f-h.left+h.right,y:p-h.top+h.bottom,zoom:l}},I5=()=>typeof navigator<`u`&&navigator?.userAgent?.indexOf(`Mac`)>=0;function L5(e){return e!=null&&e!==`parent`}function R5(e){return{width:e.measured?.width??e.width??e.initialWidth??0,height:e.measured?.height??e.height??e.initialHeight??0}}function bYe(e){return(e.measured?.width??e.width??e.initialWidth)!==void 0&&(e.measured?.height??e.height??e.initialHeight)!==void 0}function xYe(e,t={width:0,height:0},n,r,i){let a={...e},o=r.get(n);if(o){let e=o.origin||i;a.x+=o.internals.positionAbsolute.x-(t.width??0)*e[0],a.y+=o.internals.positionAbsolute.y-(t.height??0)*e[1]}return a}function SYe(e,t){if(e.size!==t.size)return!1;for(let n of e)if(!t.has(n))return!1;return!0}function CYe(){let e,t;return{promise:new Promise((n,r)=>{e=n,t=r}),resolve:e,reject:t}}function wYe(e){return{...eYe,...e||{}}}function z5(e,{snapGrid:t=[0,0],snapToGrid:n=!1,transform:r,containerBounds:i}){let{x:a,y:o}=V5(e),s=M5({x:a-(i?.left??0),y:o-(i?.top??0)},r),{x:c,y:l}=n?j5(s,t):s;return{xSnapped:c,ySnapped:l,...s}}var B5=e=>({width:e.offsetWidth,height:e.offsetHeight}),TYe=e=>e?.getRootNode?.()||window?.document,EYe=[`INPUT`,`SELECT`,`TEXTAREA`];function DYe(e){let t=e.composedPath?.()?.[0]||e.target;return t?.nodeType===1?EYe.includes(t.nodeName)||t.hasAttribute(`contenteditable`)||!!t.closest(`.nokey`):!1}var OYe=e=>`clientX`in e,V5=(e,t)=>{let n=OYe(e),r=n?e.clientX:e.touches?.[0].clientX,i=n?e.clientY:e.touches?.[0].clientY;return{x:r-(t?.left??0),y:i-(t?.top??0)}},kYe=(e,t,n,r,i)=>{let a=t.querySelectorAll(`.${e}`);return!a||!a.length?null:Array.from(a).map(t=>{let a=t.getBoundingClientRect();return{id:t.getAttribute(`data-handleid`),type:e,nodeId:i,position:t.getAttribute(`data-handlepos`),x:(a.left-n.left)/r,y:(a.top-n.top)/r,...B5(t)}})};function AYe({sourceX:e,sourceY:t,targetX:n,targetY:r,sourceControlX:i,sourceControlY:a,targetControlX:o,targetControlY:s}){let c=e*.125+i*.375+o*.375+n*.125,l=t*.125+a*.375+s*.375+r*.125;return[c,l,Math.abs(c-e),Math.abs(l-t)]}function H5(e,t){return e>=0?.5*e:t*25*Math.sqrt(-e)}function jYe({pos:e,x1:t,y1:n,x2:r,y2:i,c:a}){switch(e){case _5.Left:return[t-H5(t-r,a),n];case _5.Right:return[t+H5(r-t,a),n];case _5.Top:return[t,n-H5(n-i,a)];case _5.Bottom:return[t,n+H5(i-n,a)]}}function MYe({sourceX:e,sourceY:t,sourcePosition:n=_5.Bottom,targetX:r,targetY:i,targetPosition:a=_5.Top,curvature:o=.25}){let[s,c]=jYe({pos:n,x1:e,y1:t,x2:r,y2:i,c:o}),[l,u]=jYe({pos:a,x1:r,y1:i,x2:e,y2:t,c:o}),[d,f,p,m]=AYe({sourceX:e,sourceY:t,targetX:r,targetY:i,sourceControlX:s,sourceControlY:c,targetControlX:l,targetControlY:u});return[`M${e},${t} C${s},${c} ${l},${u} ${r},${i}`,d,f,p,m]}function NYe({sourceX:e,sourceY:t,targetX:n,targetY:r}){let i=Math.abs(n-e)/2,a=n<e?n+i:n-i,o=Math.abs(r-t)/2;return[a,r<t?r+o:r-o,i,o]}function PYe({sourceNode:e,targetNode:t,selected:n=!1,zIndex:r=0,elevateOnSelect:i=!1,zIndexMode:a=`basic`}){return a===`manual`?r:(i&&n?r+1e3:r)+Math.max(e.parentId||i&&e.selected?e.internals.z:0,t.parentId||i&&t.selected?t.internals.z:0)}function FYe({sourceNode:e,targetNode:t,width:n,height:r,transform:i}){let a=w5(O5(e),O5(t));return a.x===a.x2&&(a.x2+=1),a.y===a.y2&&(a.y2+=1),k5({x:-i[0]/i[2],y:-i[1]/i[2],width:n/i[2],height:r/i[2]},E5(a))>0}var IYe=({source:e,sourceHandle:t,target:n,targetHandle:r})=>`xy-edge__${e}${t||``}-${n}${r||``}`,LYe=(e,t)=>t.some(t=>t.source===e.source&&t.target===e.target&&(t.sourceHandle===e.sourceHandle||!t.sourceHandle&&!e.sourceHandle)&&(t.targetHandle===e.targetHandle||!t.targetHandle&&!e.targetHandle)),RYe=(e,t,n={})=>{if(!e.source||!e.target)return u5.error006(),t;let r=n.getEdgeId||IYe,i;return i=iYe(e)?{...e}:{...e,id:r(e)},LYe(i,t)?t:(i.sourceHandle===null&&delete i.sourceHandle,i.targetHandle===null&&delete i.targetHandle,t.concat(i))};function zYe({sourceX:e,sourceY:t,targetX:n,targetY:r}){let[i,a,o,s]=NYe({sourceX:e,sourceY:t,targetX:n,targetY:r});return[`M ${e},${t}L ${n},${r}`,i,a,o,s]}var BYe={[_5.Left]:{x:-1,y:0},[_5.Right]:{x:1,y:0},[_5.Top]:{x:0,y:-1},[_5.Bottom]:{x:0,y:1}},VYe=({source:e,sourcePosition:t=_5.Bottom,target:n})=>t===_5.Left||t===_5.Right?e.x<n.x?{x:1,y:0}:{x:-1,y:0}:e.y<n.y?{x:0,y:1}:{x:0,y:-1},HYe=(e,t)=>Math.sqrt((t.x-e.x)**2+(t.y-e.y)**2);function UYe({source:e,sourcePosition:t=_5.Bottom,target:n,targetPosition:r=_5.Top,center:i,offset:a,stepPosition:o}){let s=BYe[t],c=BYe[r],l={x:e.x+s.x*a,y:e.y+s.y*a},u={x:n.x+c.x*a,y:n.y+c.y*a},d=VYe({source:l,sourcePosition:t,target:u}),f=d.x===0?`y`:`x`,p=d[f],m=[],h,g,_={x:0,y:0},v={x:0,y:0},[,,y,b]=NYe({sourceX:e.x,sourceY:e.y,targetX:n.x,targetY:n.y});if(s[f]*c[f]===-1){f===`x`?(h=i.x??l.x+(u.x-l.x)*o,g=i.y??(l.y+u.y)/2):(h=i.x??(l.x+u.x)/2,g=i.y??l.y+(u.y-l.y)*o);let e=[{x:h,y:l.y},{x:h,y:u.y}],t=[{x:l.x,y:g},{x:u.x,y:g}];m=s[f]===p?f===`x`?e:t:f===`x`?t:e}else{let i=[{x:l.x,y:u.y}],o=[{x:u.x,y:l.y}];if(m=f===`x`?s.x===p?o:i:s.y===p?i:o,t===r){let t=Math.abs(e[f]-n[f]);if(t<=a){let r=Math.min(a-1,a-t);s[f]===p?_[f]=(l[f]>e[f]?-1:1)*r:v[f]=(u[f]>n[f]?-1:1)*r}}if(t!==r){let e=f===`x`?`y`:`x`,t=s[f]===c[e],n=l[e]>u[e],r=l[e]<u[e];(s[f]===1&&(!t&&n||t&&r)||s[f]!==1&&(!t&&r||t&&n))&&(m=f===`x`?i:o)}let d={x:l.x+_.x,y:l.y+_.y},y={x:u.x+v.x,y:u.y+v.y};Math.max(Math.abs(d.x-m[0].x),Math.abs(y.x-m[0].x))>=Math.max(Math.abs(d.y-m[0].y),Math.abs(y.y-m[0].y))?(h=(d.x+y.x)/2,g=m[0].y):(h=m[0].x,g=(d.y+y.y)/2)}let x={x:l.x+_.x,y:l.y+_.y},S={x:u.x+v.x,y:u.y+v.y};return[[e,...x.x!==m[0].x||x.y!==m[0].y?[x]:[],...m,...S.x!==m[m.length-1].x||S.y!==m[m.length-1].y?[S]:[],n],h,g,y,b]}function WYe(e,t,n,r){let i=Math.min(HYe(e,t)/2,HYe(t,n)/2,r),{x:a,y:o}=t;if(e.x===a&&a===n.x||e.y===o&&o===n.y)return`L${a} ${o}`;if(e.y===o){let t=e.x<n.x?-1:1,r=e.y<n.y?1:-1;return`L ${a+i*t},${o}Q ${a},${o} ${a},${o+i*r}`}let s=e.x<n.x?1:-1;return`L ${a},${o+i*(e.y<n.y?-1:1)}Q ${a},${o} ${a+i*s},${o}`}function U5({sourceX:e,sourceY:t,sourcePosition:n=_5.Bottom,targetX:r,targetY:i,targetPosition:a=_5.Top,borderRadius:o=5,centerX:s,centerY:c,offset:l=20,stepPosition:u=.5}){let[d,f,p,m,h]=UYe({source:{x:e,y:t},sourcePosition:n,target:{x:r,y:i},targetPosition:a,center:{x:s,y:c},offset:l,stepPosition:u}),g=`M${d[0].x} ${d[0].y}`;for(let e=1;e<d.length-1;e++)g+=WYe(d[e-1],d[e],d[e+1],o);return g+=`L${d[d.length-1].x} ${d[d.length-1].y}`,[g,f,p,m,h]}function GYe(e){return e&&!!(e.internals.handleBounds||e.handles?.length)&&!!(e.measured.width||e.width||e.initialWidth)}function KYe(e){let{sourceNode:t,targetNode:n}=e;if(!GYe(t)||!GYe(n))return null;let r=t.internals.handleBounds||qYe(t.handles),i=n.internals.handleBounds||qYe(n.handles),a=JYe(r?.source??[],e.sourceHandle),o=JYe(e.connectionMode===f5.Strict?i?.target??[]:(i?.target??[]).concat(i?.source??[]),e.targetHandle);if(!a||!o)return e.onError?.(`008`,u5.error008(a?`target`:`source`,{id:e.id,sourceHandle:e.sourceHandle,targetHandle:e.targetHandle})),null;let s=a?.position||_5.Bottom,c=o?.position||_5.Top,l=W5(t,a,s),u=W5(n,o,c);return{sourceX:l.x,sourceY:l.y,targetX:u.x,targetY:u.y,sourcePosition:s,targetPosition:c}}function qYe(e){if(!e)return null;let t=[],n=[];for(let r of e)r.width=r.width??1,r.height=r.height??1,r.type===`source`?t.push(r):r.type===`target`&&n.push(r);return{source:t,target:n}}function W5(e,t,n=_5.Left,r=!1){let i=(t?.x??0)+e.internals.positionAbsolute.x,a=(t?.y??0)+e.internals.positionAbsolute.y,{width:o,height:s}=t??R5(e);if(r)return{x:i+o/2,y:a+s/2};switch(t?.position??n){case _5.Top:return{x:i+o/2,y:a};case _5.Right:return{x:i+o,y:a+s/2};case _5.Bottom:return{x:i+o/2,y:a+s};case _5.Left:return{x:i,y:a+s/2}}}function JYe(e,t){return e&&(t?e.find(e=>e.id===t):e[0])||null}function G5(e,t){return e?typeof e==`string`?e:`${t?`${t}__`:``}${Object.keys(e).sort().map(t=>`${t}=${e[t]}`).join(`&`)}`:``}function YYe(e,{id:t,defaultColor:n,defaultMarkerStart:r,defaultMarkerEnd:i}){let a=new Set;return e.reduce((e,o)=>([o.markerStart||r,o.markerEnd||i].forEach(r=>{if(r&&typeof r==`object`){let i=G5(r,t);a.has(i)||(e.push({id:i,color:r.color||n,...r}),a.add(i))}}),e),[]).sort((e,t)=>e.id.localeCompare(t.id))}var XYe=1e3,ZYe=10,K5={nodeOrigin:[0,0],nodeExtent:d5,elevateNodesOnSelect:!0,zIndexMode:`basic`,defaults:{}},QYe={...K5,checkEquality:!0};function q5(e,t){let n={...e};for(let e in t)t[e]!==void 0&&(n[e]=t[e]);return n}function $Ye(e,t,n){let r=q5(K5,n);for(let n of e.values())if(n.parentId)X5(n,e,t,r);else{let e=C5(y5(n,r.nodeOrigin),L5(n.extent)?n.extent:r.nodeExtent,R5(n));n.internals.positionAbsolute=e}}function eXe(e,t){if(!e.handles)return e.measured?t?.internals.handleBounds:void 0;let n=[],r=[];for(let t of e.handles){let i={id:t.id,width:t.width??1,height:t.height??1,nodeId:e.id,x:t.x,y:t.y,position:t.position,type:t.type};t.type===`source`?n.push(i):t.type===`target`&&r.push(i)}return{source:n,target:r}}function J5(e){return e===`manual`}function Y5(e,t,n,r={}){let i=q5(QYe,r),a={i:0},o=new Map(t),s=i?.elevateNodesOnSelect&&!J5(i.zIndexMode)?XYe:0,c=e.length>0,l=!1;t.clear(),n.clear();for(let u of e){let e=o.get(u.id);if(i.checkEquality&&u===e?.internals.userNode)t.set(u.id,e);else{let n=C5(y5(u,i.nodeOrigin),L5(u.extent)?u.extent:i.nodeExtent,R5(u));e={...i.defaults,...u,measured:{width:u.measured?.width,height:u.measured?.height},internals:{positionAbsolute:n,handleBounds:eXe(u,e),z:nXe(u,s,i.zIndexMode),userNode:u}},t.set(u.id,e)}(e.measured===void 0||e.measured.width===void 0||e.measured.height===void 0)&&!e.hidden&&(c=!1),u.parentId&&X5(e,t,n,r,a),l||=u.selected??!1}return{nodesInitialized:c,hasSelectedNodes:l}}function tXe(e,t){if(!e.parentId)return;let n=t.get(e.parentId);n?n.set(e.id,e):t.set(e.parentId,new Map([[e.id,e]]))}function X5(e,t,n,r,i){let{elevateNodesOnSelect:a,nodeOrigin:o,nodeExtent:s,zIndexMode:c}=q5(K5,r),l=e.parentId,u=t.get(l);if(!u){console.warn(`Parent node ${l} not found. Please make sure that parent nodes are in front of their child nodes in the nodes array.`);return}tXe(e,n),i&&!u.parentId&&u.internals.rootParentIndex===void 0&&c===`auto`&&(u.internals.rootParentIndex=++i.i,u.internals.z=u.internals.z+i.i*ZYe),i&&u.internals.rootParentIndex!==void 0&&(i.i=u.internals.rootParentIndex);let{x:d,y:f,z:p}=rXe(e,u,o,s,a&&!J5(c)?XYe:0,c),{positionAbsolute:m}=e.internals,h=d!==m.x||f!==m.y;(h||p!==e.internals.z)&&t.set(e.id,{...e,internals:{...e.internals,positionAbsolute:h?{x:d,y:f}:m,z:p}})}function nXe(e,t,n){let r=A5(e.zIndex)?e.zIndex:0;return J5(n)?r:r+(e.selected?t:0)}function rXe(e,t,n,r,i,a){let{x:o,y:s}=t.internals.positionAbsolute,c=R5(e),l=y5(e,n),u=L5(e.extent)?C5(l,e.extent,c):l,d=C5({x:o+u.x,y:s+u.y},r,c);e.extent===`parent`&&(d=fYe(d,c,t));let f=nXe(e,i,a),p=t.internals.z??0;return{x:d.x,y:d.y,z:p>=f?p+1:f}}function Z5(e,t,n,r=[0,0]){let i=[],a=new Map;for(let n of e){let e=t.get(n.parentId);if(!e)continue;let r=hYe(a.get(n.parentId)?.expandedRect??D5(e),n.rect);a.set(n.parentId,{expandedRect:r,parent:e})}return a.size>0&&a.forEach(({expandedRect:t,parent:a},o)=>{let s=a.internals.positionAbsolute,c=R5(a),l=a.origin??r,u=t.x<s.x?Math.round(Math.abs(s.x-t.x)):0,d=t.y<s.y?Math.round(Math.abs(s.y-t.y)):0,f=Math.max(c.width,Math.round(t.width)),p=Math.max(c.height,Math.round(t.height)),m=(f-c.width)*l[0],h=(p-c.height)*l[1];(u>0||d>0||m||h)&&(i.push({id:o,type:`position`,position:{x:a.position.x-u+m,y:a.position.y-d+h}}),n.get(o)?.forEach(t=>{e.some(e=>e.id===t.id)||i.push({id:t.id,type:`position`,position:{x:t.position.x+u,y:t.position.y+d}})})),(c.width<t.width||c.height<t.height||u||d)&&i.push({id:o,type:`dimensions`,setAttributes:!0,dimensions:{width:f+(u?l[0]*u-m:0),height:p+(d?l[1]*d-h:0)}})}),i}function iXe(e,t,n,r,i,a,o){let s=r?.querySelector(`.xyflow__viewport`),c=!1;if(!s)return{changes:[],updatedInternals:c};let l=[],u=window.getComputedStyle(s),{m22:d}=new window.DOMMatrixReadOnly(u.transform),f=[];for(let r of e.values()){let e=t.get(r.id);if(!e)continue;if(e.hidden){t.set(e.id,{...e,internals:{...e.internals,handleBounds:void 0}}),c=!0;continue}let s=B5(r.nodeElement),u=e.measured.width!==s.width||e.measured.height!==s.height;if(s.width&&s.height&&(u||!e.internals.handleBounds||r.force)){let p=r.nodeElement.getBoundingClientRect(),m=L5(e.extent)?e.extent:a,{positionAbsolute:h}=e.internals;e.parentId&&e.extent===`parent`?h=fYe(h,s,t.get(e.parentId)):m&&(h=C5(h,m,s));let g={...e,measured:s,internals:{...e.internals,positionAbsolute:h,handleBounds:{source:kYe(`source`,r.nodeElement,p,d,e.id),target:kYe(`target`,r.nodeElement,p,d,e.id)}}};t.set(e.id,g),e.parentId&&X5(g,t,n,{nodeOrigin:i,zIndexMode:o}),c=!0,u&&(l.push({id:e.id,type:`dimensions`,dimensions:s}),e.expandParent&&e.parentId&&f.push({id:e.id,parentId:e.parentId,rect:D5(g,i)}))}}if(f.length>0){let e=Z5(f,t,n,i);l.push(...e)}return{changes:l,updatedInternals:c}}async function aXe({delta:e,panZoom:t,transform:n,translateExtent:r,width:i,height:a}){if(!t||!e.x&&!e.y)return Promise.resolve(!1);let o=await t.setViewportConstrained({x:n[0]+e.x,y:n[1]+e.y,zoom:n[2]},[[0,0],[i,a]],r),s=!!o&&(o.x!==n[0]||o.y!==n[1]||o.k!==n[2]);return Promise.resolve(s)}function oXe(e,t,n,r,i,a){let o=i,s=r.get(o)||new Map;r.set(o,s.set(n,t)),o=`${i}-${e}`;let c=r.get(o)||new Map;if(r.set(o,c.set(n,t)),a){o=`${i}-${e}-${a}`;let s=r.get(o)||new Map;r.set(o,s.set(n,t))}}function sXe(e,t,n){e.clear(),t.clear();for(let r of n){let{source:n,target:i,sourceHandle:a=null,targetHandle:o=null}=r,s={edgeId:r.id,source:n,target:i,sourceHandle:a,targetHandle:o},c=`${n}-${a}--${i}-${o}`;oXe(`source`,s,`${i}-${o}--${n}-${a}`,e,n,a),oXe(`target`,s,c,e,i,o),t.set(r.id,r)}}function cXe(e,t){if(!e.parentId)return!1;let n=t.get(e.parentId);return n?n.selected?!0:cXe(n,t):!1}function lXe(e,t,n){let r=e;do{if(r?.matches?.(t))return!0;if(r===n)return!1;r=r?.parentElement}while(r);return!1}function uXe(e,t,n,r){let i=new Map;for(let[a,o]of e)if((o.selected||o.id===r)&&(!o.parentId||!cXe(o,e))&&(o.draggable||t&&o.draggable===void 0)){let t=e.get(a);t&&i.set(a,{id:a,position:t.position||{x:0,y:0},distance:{x:n.x-t.internals.positionAbsolute.x,y:n.y-t.internals.positionAbsolute.y},extent:t.extent,parentId:t.parentId,origin:t.origin,expandParent:t.expandParent,internals:{positionAbsolute:t.internals.positionAbsolute||{x:0,y:0}},measured:{width:t.measured.width??0,height:t.measured.height??0}})}return i}function Q5({nodeId:e,dragItems:t,nodeLookup:n,dragging:r=!0}){let i=[];for(let[e,a]of t){let t=n.get(e)?.internals.userNode;t&&i.push({...t,position:a.position,dragging:r})}if(!e)return[i[0],i];let a=n.get(e)?.internals.userNode;return[a?{...a,position:t.get(e)?.position||a.position,dragging:r}:i[0],i]}function dXe({dragItems:e,snapGrid:t,x:n,y:r}){let i=e.values().next().value;if(!i)return null;let a={x:n-i.distance.x,y:r-i.distance.y},o=j5(a,t);return{x:o.x-a.x,y:o.y-a.y}}function fXe({onNodeMouseDown:e,getStoreItems:t,onDragStart:n,onDrag:r,onDragStop:i}){let a={x:null,y:null},o=0,s=new Map,c=!1,l={x:0,y:0},u=null,d=!1,f=null,p=!1,m=!1,h=null;function g({noDragClassName:g,handleSelector:_,domNode:v,isSelectable:y,nodeId:b,nodeClickDistance:x=0}){f=V6(v);function S({x:e,y:n}){let{nodeLookup:i,nodeExtent:o,snapGrid:c,snapToGrid:l,nodeOrigin:u,onNodeDrag:d,onSelectionDrag:f,onError:p,updateNodePositions:g}=t();a={x:e,y:n};let _=!1,v=s.size>1,y=v&&o?T5(b5(s)):null,x=v&&l?dXe({dragItems:s,snapGrid:c,x:e,y:n}):null;for(let[t,r]of s){if(!i.has(t))continue;let a={x:e-r.distance.x,y:n-r.distance.y};l&&(a=x?{x:Math.round(a.x+x.x),y:Math.round(a.y+x.y)}:j5(a,c));let s=null;if(v&&o&&!r.extent&&y){let{positionAbsolute:e}=r.internals,t=e.x-y.x+o[0][0],n=e.x+r.measured.width-y.x2+o[1][0],i=e.y-y.y+o[0][1],a=e.y+r.measured.height-y.y2+o[1][1];s=[[t,i],[n,a]]}let{position:d,positionAbsolute:f}=uYe({nodeId:t,nextPosition:a,nodeLookup:i,nodeExtent:s||o,nodeOrigin:u,onError:p});_=_||r.position.x!==d.x||r.position.y!==d.y,r.position=d,r.internals.positionAbsolute=f}if(m||=_,_&&(g(s,!0),h&&(r||d||!b&&f))){let[e,t]=Q5({nodeId:b,dragItems:s,nodeLookup:i});r?.(h,s,e,t),d?.(h,e,t),b||f?.(h,t)}}async function C(){if(!u)return;let{transform:e,panBy:n,autoPanSpeed:r,autoPanOnNodeDrag:i}=t();if(!i){c=!1,cancelAnimationFrame(o);return}let[s,d]=mYe(l,u,r);(s!==0||d!==0)&&(a.x=(a.x??0)-s/e[2],a.y=(a.y??0)-d/e[2],await n({x:s,y:d})&&S(a)),o=requestAnimationFrame(C)}function w(r){let{nodeLookup:i,multiSelectionActive:o,nodesDraggable:c,transform:l,snapGrid:f,snapToGrid:p,selectNodesOnDrag:m,onNodeDragStart:h,onSelectionDragStart:g,unselectNodesAndEdges:_}=t();d=!0,(!m||!y)&&!o&&b&&(i.get(b)?.selected||_()),y&&m&&b&&e?.(b);let v=z5(r.sourceEvent,{transform:l,snapGrid:f,snapToGrid:p,containerBounds:u});if(a=v,s=uXe(i,c,v,b),s.size>0&&(n||h||!b&&g)){let[e,t]=Q5({nodeId:b,dragItems:s,nodeLookup:i});n?.(r.sourceEvent,s,e,t),h?.(r.sourceEvent,e,t),b||g?.(r.sourceEvent,t)}}let T=X6().clickDistance(x).on(`start`,e=>{let{domNode:n,nodeDragThreshold:r,transform:i,snapGrid:o,snapToGrid:s}=t();u=n?.getBoundingClientRect()||null,p=!1,m=!1,h=e.sourceEvent,r===0&&w(e),a=z5(e.sourceEvent,{transform:i,snapGrid:o,snapToGrid:s,containerBounds:u}),l=V5(e.sourceEvent,u)}).on(`drag`,e=>{let{autoPanOnNodeDrag:n,transform:r,snapGrid:i,snapToGrid:o,nodeDragThreshold:f,nodeLookup:m}=t(),g=z5(e.sourceEvent,{transform:r,snapGrid:i,snapToGrid:o,containerBounds:u});if(h=e.sourceEvent,(e.sourceEvent.type===`touchmove`&&e.sourceEvent.touches.length>1||b&&!m.has(b))&&(p=!0),!p){if(!c&&n&&d&&(c=!0,C()),!d){let t=V5(e.sourceEvent,u),n=t.x-l.x,r=t.y-l.y;Math.sqrt(n*n+r*r)>f&&w(e)}(a.x!==g.xSnapped||a.y!==g.ySnapped)&&s&&d&&(l=V5(e.sourceEvent,u),S(g))}}).on(`end`,e=>{if(!(!d||p)&&(c=!1,d=!1,cancelAnimationFrame(o),s.size>0)){let{nodeLookup:n,updateNodePositions:r,onNodeDragStop:a,onSelectionDragStop:o}=t();if(m&&=(r(s,!1),!1),i||a||!b&&o){let[t,r]=Q5({nodeId:b,dragItems:s,nodeLookup:n,dragging:!1});i?.(e.sourceEvent,s,t,r),a?.(e.sourceEvent,t,r),b||o?.(e.sourceEvent,r)}}}).filter(e=>{let t=e.target;return!e.button&&(!g||!lXe(t,`.${g}`,v))&&(!_||lXe(t,_,v))});f.call(T)}function _(){f?.on(`.drag`,null)}return{update:g,destroy:_}}function pXe(e,t,n){let r=[],i={x:e.x-n,y:e.y-n,width:n*2,height:n*2};for(let e of t.values())k5(i,D5(e))>0&&r.push(e);return r}var mXe=250;function hXe(e,t,n,r){let i=[],a=1/0,o=pXe(e,n,t+mXe);for(let n of o){let o=[...n.internals.handleBounds?.source??[],...n.internals.handleBounds?.target??[]];for(let s of o){if(r.nodeId===s.nodeId&&r.type===s.type&&r.id===s.id)continue;let{x:o,y:c}=W5(n,s,s.position,!0),l=Math.sqrt((o-e.x)**2+(c-e.y)**2);l>t||(l<a?(i=[{...s,x:o,y:c}],a=l):l===a&&i.push({...s,x:o,y:c}))}}if(!i.length)return null;if(i.length>1){let e=r.type===`source`?`target`:`source`;return i.find(t=>t.type===e)??i[0]}return i[0]}function gXe(e,t,n,r,i,a=!1){let o=r.get(e);if(!o)return null;let s=i===`strict`?o.internals.handleBounds?.[t]:[...o.internals.handleBounds?.source??[],...o.internals.handleBounds?.target??[]],c=(n?s?.find(e=>e.id===n):s?.[0])??null;return c&&a?{...c,...W5(o,c,c.position,!0)}:c}function _Xe(e,t){return e||(t?.classList.contains(`target`)?`target`:t?.classList.contains(`source`)?`source`:null)}function vXe(e,t){let n=null;return t?n=!0:e&&!t&&(n=!1),n}var yXe=()=>!0;function bXe(e,{connectionMode:t,connectionRadius:n,handleId:r,nodeId:i,edgeUpdaterType:a,isTarget:o,domNode:s,nodeLookup:c,lib:l,autoPanOnConnect:u,flowId:d,panBy:f,cancelConnection:p,onConnectStart:m,onConnect:h,onConnectEnd:g,isValidConnection:_=yXe,onReconnectEnd:v,updateConnection:y,getTransform:b,getFromHandle:x,autoPanSpeed:S,dragThreshold:C=1,handleDomNode:w}){let T=TYe(e.target),E=0,D,{x:O,y:k}=V5(e),A=_Xe(a,w),j=s?.getBoundingClientRect(),M=!1;if(!j||!A)return;let N=gXe(i,A,r,c,t);if(!N)return;let P=V5(e,j),F=!1,I=null,L=!1,R=null;function z(){if(!u||!j)return;let[e,t]=mYe(P,j,S);f({x:e,y:t}),E=requestAnimationFrame(z)}let ee={...N,nodeId:i,type:A,position:N.position},te=c.get(i),ne={inProgress:!0,isValid:null,from:W5(te,ee,_5.Left,!0),fromHandle:ee,fromPosition:ee.position,fromNode:te,to:P,toHandle:null,toPosition:nYe[ee.position],toNode:null,pointer:P};function re(){M=!0,y(ne),m?.(e,{nodeId:i,handleId:r,handleType:A})}C===0&&re();function ie(e){if(!M){let{x:t,y:n}=V5(e),r=t-O,i=n-k;if(!(r*r+i*i>C*C))return;re()}if(!x()||!ee){B(e);return}let a=b();P=V5(e,j),D=hXe(M5(P,a,!1,[1,1]),n,c,ee),F||=(z(),!0);let s=xXe(e,{handle:D,connectionMode:t,fromNodeId:i,fromHandleId:r,fromType:o?`target`:`source`,isValidConnection:_,doc:T,lib:l,flowId:d,nodeLookup:c});R=s.handleDomNode,I=s.connection,L=vXe(!!D,s.isValid);let u=c.get(i),f=u?W5(u,ee,_5.Left,!0):ne.from,p={...ne,from:f,isValid:L,to:s.toHandle&&L?N5({x:s.toHandle.x,y:s.toHandle.y},a):P,toHandle:s.toHandle,toPosition:L&&s.toHandle?s.toHandle.position:nYe[ee.position],toNode:s.toHandle?c.get(s.toHandle.nodeId):null,pointer:P};y(p),ne=p}function B(e){if(!(`touches`in e&&e.touches.length>0)){if(M){(D||R)&&I&&L&&h?.(I);let{inProgress:t,...n}=ne,r={...n,toPosition:ne.toHandle?ne.toPosition:null};g?.(e,r),a&&v?.(e,r)}p(),cancelAnimationFrame(E),F=!1,L=!1,I=null,R=null,T.removeEventListener(`mousemove`,ie),T.removeEventListener(`mouseup`,B),T.removeEventListener(`touchmove`,ie),T.removeEventListener(`touchend`,B)}}T.addEventListener(`mousemove`,ie),T.addEventListener(`mouseup`,B),T.addEventListener(`touchmove`,ie),T.addEventListener(`touchend`,B)}function xXe(e,{handle:t,connectionMode:n,fromNodeId:r,fromHandleId:i,fromType:a,doc:o,lib:s,flowId:c,isValidConnection:l=yXe,nodeLookup:u}){let d=a===`target`,f=t?o.querySelector(`.${s}-flow__handle[data-id="${c}-${t?.nodeId}-${t?.id}-${t?.type}"]`):null,{x:p,y:m}=V5(e),h=o.elementFromPoint(p,m),g=h?.classList.contains(`${s}-flow__handle`)?h:f,_={handleDomNode:g,isValid:!1,connection:null,toHandle:null};if(g){let e=_Xe(void 0,g),t=g.getAttribute(`data-nodeid`),a=g.getAttribute(`data-handleid`),o=g.classList.contains(`connectable`),s=g.classList.contains(`connectableend`);if(!t||!e)return _;let c={source:d?t:r,sourceHandle:d?a:i,target:d?r:t,targetHandle:d?i:a};_.connection=c,_.isValid=o&&s&&(n===f5.Strict?d&&e===`source`||!d&&e===`target`:t!==r||a!==i)&&l(c),_.toHandle=gXe(t,e,a,u,n,!0)}return _}var $5={onPointerDown:bXe,isValid:xXe};function SXe({domNode:e,panZoom:t,getTransform:n,getViewScale:r}){let i=V6(e);function a({translateExtent:e,width:a,height:o,zoomStep:s=1,pannable:c=!0,zoomable:l=!0,inversePan:u=!1}){let d=e=>{if(e.sourceEvent.type!==`wheel`||!t)return;let r=n(),i=e.sourceEvent.ctrlKey&&I5()?10:1,a=-e.sourceEvent.deltaY*(e.sourceEvent.deltaMode===1?.05:e.sourceEvent.deltaMode?1:.002)*s,o=r[2]*2**(a*i);t.scaleTo(o)},f=[0,0],p=QJe().on(`start`,e=>{(e.sourceEvent.type===`mousedown`||e.sourceEvent.type===`touchstart`)&&(f=[e.sourceEvent.clientX??e.sourceEvent.touches[0].clientX,e.sourceEvent.clientY??e.sourceEvent.touches[0].clientY])}).on(`zoom`,c?i=>{let s=n();if(i.sourceEvent.type!==`mousemove`&&i.sourceEvent.type!==`touchmove`||!t)return;let c=[i.sourceEvent.clientX??i.sourceEvent.touches[0].clientX,i.sourceEvent.clientY??i.sourceEvent.touches[0].clientY],l=[c[0]-f[0],c[1]-f[1]];f=c;let d=r()*Math.max(s[2],Math.log(s[2]))*(u?-1:1),p={x:s[0]-l[0]*d,y:s[1]-l[1]*d},m=[[0,0],[a,o]];t.setViewportConstrained({x:p.x,y:p.y,zoom:s[2]},m,e)}:null).on(`zoom.wheel`,l?d:null);i.call(p,{})}function o(){i.on(`zoom`,null)}return{update:a,destroy:o,pointer:H6}}var e7=e=>({x:e.x,y:e.y,zoom:e.k}),t7=({x:e,y:t,zoom:n})=>s5.translate(e,t).scale(n),n7=(e,t)=>e.target.closest(`.${t}`),CXe=(e,t)=>t===2&&Array.isArray(e)&&e.includes(2),wXe=e=>((e*=2)<=1?e*e*e:(e-=2)*e*e+2)/2,r7=(e,t=0,n=wXe,r=()=>{})=>{let i=typeof t==`number`&&t>0;return i||r(),i?e.transition().duration(t).ease(n).on(`end`,r):e},TXe=e=>{let t=e.ctrlKey&&I5()?10:1;return-e.deltaY*(e.deltaMode===1?.05:e.deltaMode?1:.002)*t};function EXe({zoomPanValues:e,noWheelClassName:t,d3Selection:n,d3Zoom:r,panOnScrollMode:i,panOnScrollSpeed:a,zoomOnPinch:o,onPanZoomStart:s,onPanZoom:c,onPanZoomEnd:l}){return u=>{if(n7(u,t))return u.ctrlKey&&u.preventDefault(),!1;u.preventDefault(),u.stopImmediatePropagation();let d=n.property(`__zoom`).k||1;if(u.ctrlKey&&o){let e=H6(u),t=d*2**TXe(u);r.scaleTo(n,t,e,u);return}let f=u.deltaMode===1?20:1,p=i===p5.Vertical?0:u.deltaX*f,m=i===p5.Horizontal?0:u.deltaY*f;!I5()&&u.shiftKey&&i!==p5.Vertical&&(p=u.deltaY*f,m=0),r.translateBy(n,-(p/d)*a,-(m/d)*a,{internal:!0});let h=e7(n.property(`__zoom`));clearTimeout(e.panScrollTimeout),e.isPanScrolling?(c?.(u,h),e.panScrollTimeout=setTimeout(()=>{l?.(u,h),e.isPanScrolling=!1},150)):(e.isPanScrolling=!0,s?.(u,h))}}function DXe({noWheelClassName:e,preventScrolling:t,d3ZoomHandler:n}){return function(r,i){let a=r.type===`wheel`,o=!t&&a&&!r.ctrlKey,s=n7(r,e);if(r.ctrlKey&&a&&s&&r.preventDefault(),o||s)return null;r.preventDefault(),n.call(this,r,i)}}function OXe({zoomPanValues:e,onDraggingChange:t,onPanZoomStart:n}){return r=>{if(r.sourceEvent?.internal)return;let i=e7(r.transform);e.mouseButton=r.sourceEvent?.button||0,e.isZoomingOrPanning=!0,e.prevViewport=i,r.sourceEvent?.type===`mousedown`&&t(!0),n&&n?.(r.sourceEvent,i)}}function kXe({zoomPanValues:e,panOnDrag:t,onPaneContextMenu:n,onTransformChange:r,onPanZoom:i}){return a=>{e.usedRightMouseButton=!!(n&&CXe(t,e.mouseButton??0)),a.sourceEvent?.sync||r([a.transform.x,a.transform.y,a.transform.k]),i&&!a.sourceEvent?.internal&&i?.(a.sourceEvent,e7(a.transform))}}function AXe({zoomPanValues:e,panOnDrag:t,panOnScroll:n,onDraggingChange:r,onPanZoomEnd:i,onPaneContextMenu:a}){return o=>{if(!o.sourceEvent?.internal&&(e.isZoomingOrPanning=!1,a&&CXe(t,e.mouseButton??0)&&!e.usedRightMouseButton&&o.sourceEvent&&a(o.sourceEvent),e.usedRightMouseButton=!1,r(!1),i)){let t=e7(o.transform);e.prevViewport=t,clearTimeout(e.timerId),e.timerId=setTimeout(()=>{i?.(o.sourceEvent,t)},n?150:0)}}}function jXe({zoomActivationKeyPressed:e,zoomOnScroll:t,zoomOnPinch:n,panOnDrag:r,panOnScroll:i,zoomOnDoubleClick:a,userSelectionActive:o,noWheelClassName:s,noPanClassName:c,lib:l,connectionInProgress:u}){return d=>{let f=e||t,p=n&&d.ctrlKey,m=d.type===`wheel`;if(d.button===1&&d.type===`mousedown`&&(n7(d,`${l}-flow__node`)||n7(d,`${l}-flow__edge`)))return!0;if(!r&&!f&&!i&&!a&&!n||o||u&&!m||n7(d,s)&&m||n7(d,c)&&(!m||i&&m&&!e)||!n&&d.ctrlKey&&m)return!1;if(!n&&d.type===`touchstart`&&d.touches?.length>1)return d.preventDefault(),!1;if(!f&&!i&&!p&&m||!r&&(d.type===`mousedown`||d.type===`touchstart`)||Array.isArray(r)&&!r.includes(d.button)&&d.type===`mousedown`)return!1;let h=Array.isArray(r)&&r.includes(d.button)||!d.button||d.button<=1;return(!d.ctrlKey||m)&&h}}function MXe({domNode:e,minZoom:t,maxZoom:n,translateExtent:r,viewport:i,onPanZoom:a,onPanZoomStart:o,onPanZoomEnd:s,onDraggingChange:c}){let l={isZoomingOrPanning:!1,usedRightMouseButton:!1,prevViewport:{x:0,y:0,zoom:0},mouseButton:0,timerId:void 0,panScrollTimeout:void 0,isPanScrolling:!1},u=e.getBoundingClientRect(),d=QJe().scaleExtent([t,n]).translateExtent(r),f=V6(e).call(d);v({x:i.x,y:i.y,zoom:S5(i.zoom,t,n)},[[0,0],[u.width,u.height]],r);let p=f.on(`wheel.zoom`),m=f.on(`dblclick.zoom`);d.wheelDelta(TXe);function h(e,t){return f?new Promise(n=>{d?.interpolate(t?.interpolate===`linear`?j8:R8).transform(r7(f,t?.duration,t?.ease,()=>n(!0)),e)}):Promise.resolve(!1)}function g({noWheelClassName:e,noPanClassName:t,onPaneContextMenu:n,userSelectionActive:r,panOnScroll:i,panOnDrag:u,panOnScrollMode:h,panOnScrollSpeed:g,preventScrolling:v,zoomOnPinch:y,zoomOnScroll:b,zoomOnDoubleClick:x,zoomActivationKeyPressed:S,lib:C,onTransformChange:w,connectionInProgress:T,paneClickDistance:E,selectionOnDrag:D}){r&&!l.isZoomingOrPanning&&_();let O=i&&!S&&!r;d.clickDistance(D?1/0:!A5(E)||E<0?0:E);let k=O?EXe({zoomPanValues:l,noWheelClassName:e,d3Selection:f,d3Zoom:d,panOnScrollMode:h,panOnScrollSpeed:g,zoomOnPinch:y,onPanZoomStart:o,onPanZoom:a,onPanZoomEnd:s}):DXe({noWheelClassName:e,preventScrolling:v,d3ZoomHandler:p});if(f.on(`wheel.zoom`,k,{passive:!1}),!r){let e=OXe({zoomPanValues:l,onDraggingChange:c,onPanZoomStart:o});d.on(`start`,e);let t=kXe({zoomPanValues:l,panOnDrag:u,onPaneContextMenu:!!n,onPanZoom:a,onTransformChange:w});d.on(`zoom`,t);let r=AXe({zoomPanValues:l,panOnDrag:u,panOnScroll:i,onPaneContextMenu:n,onPanZoomEnd:s,onDraggingChange:c});d.on(`end`,r)}let A=jXe({zoomActivationKeyPressed:S,panOnDrag:u,zoomOnScroll:b,panOnScroll:i,zoomOnDoubleClick:x,zoomOnPinch:y,userSelectionActive:r,noPanClassName:t,noWheelClassName:e,lib:C,connectionInProgress:T});d.filter(A),x?f.on(`dblclick.zoom`,m):f.on(`dblclick.zoom`,null)}function _(){d.on(`zoom`,null)}async function v(e,t,n){let r=t7(e),i=d?.constrain()(r,t,n);return i&&await h(i),new Promise(e=>e(i))}async function y(e,t){let n=t7(e);return await h(n,t),new Promise(e=>e(n))}function b(e){if(f){let t=t7(e),n=f.property(`__zoom`);(n.k!==e.zoom||n.x!==e.x||n.y!==e.y)&&d?.transform(f,t,null,{sync:!0})}}function x(){let e=f?GJe(f.node()):{x:0,y:0,k:1};return{x:e.x,y:e.y,zoom:e.k}}function S(e,t){return f?new Promise(n=>{d?.interpolate(t?.interpolate===`linear`?j8:R8).scaleTo(r7(f,t?.duration,t?.ease,()=>n(!0)),e)}):Promise.resolve(!1)}function C(e,t){return f?new Promise(n=>{d?.interpolate(t?.interpolate===`linear`?j8:R8).scaleBy(r7(f,t?.duration,t?.ease,()=>n(!0)),e)}):Promise.resolve(!1)}function w(e){d?.scaleExtent(e)}function T(e){d?.translateExtent(e)}function E(e){let t=!A5(e)||e<0?0:e;d?.clickDistance(t)}return{update:g,destroy:_,setViewport:y,setViewportConstrained:v,getViewport:x,scaleTo:S,scaleBy:C,setScaleExtent:w,setTranslateExtent:T,syncViewport:b,setClickDistance:E}}var i7;(function(e){e.Line=`line`,e.Handle=`handle`})(i7||={});function NXe({width:e,prevWidth:t,height:n,prevHeight:r,affectsX:i,affectsY:a}){let o=e-t,s=n-r,c=[o>0?1:o<0?-1:0,s>0?1:s<0?-1:0];return o&&i&&(c[0]*=-1),s&&a&&(c[1]*=-1),c}function PXe(e){return{isHorizontal:e.includes(`right`)||e.includes(`left`),isVertical:e.includes(`bottom`)||e.includes(`top`),affectsX:e.includes(`left`),affectsY:e.includes(`top`)}}function a7(e,t){return Math.max(0,t-e)}function o7(e,t){return Math.max(0,e-t)}function s7(e,t,n){return Math.max(0,t-e,e-n)}function FXe(e,t){return e?!t:t}function IXe(e,t,n,r,i,a,o,s){let{affectsX:c,affectsY:l}=t,{isHorizontal:u,isVertical:d}=t,f=u&&d,{xSnapped:p,ySnapped:m}=n,{minWidth:h,maxWidth:g,minHeight:_,maxHeight:v}=r,{x:y,y:b,width:x,height:S,aspectRatio:C}=e,w=Math.floor(u?p-e.pointerX:0),T=Math.floor(d?m-e.pointerY:0),E=x+(c?-w:w),D=S+(l?-T:T),O=-a[0]*x,k=-a[1]*S,A=s7(E,h,g),j=s7(D,_,v);if(o){let e=0,t=0;c&&w<0?e=a7(y+w+O,o[0][0]):!c&&w>0&&(e=o7(y+E+O,o[1][0])),l&&T<0?t=a7(b+T+k,o[0][1]):!l&&T>0&&(t=o7(b+D+k,o[1][1])),A=Math.max(A,e),j=Math.max(j,t)}if(s){let e=0,t=0;c&&w>0?e=o7(y+w,s[0][0]):!c&&w<0&&(e=a7(y+E,s[1][0])),l&&T>0?t=o7(b+T,s[0][1]):!l&&T<0&&(t=a7(b+D,s[1][1])),A=Math.max(A,e),j=Math.max(j,t)}if(i){if(u){let e=s7(E/C,_,v)*C;if(A=Math.max(A,e),o){let e=0;e=!c&&!l||c&&!l&&f?o7(b+k+E/C,o[1][1])*C:a7(b+k+(c?w:-w)/C,o[0][1])*C,A=Math.max(A,e)}if(s){let e=0;e=!c&&!l||c&&!l&&f?a7(b+E/C,s[1][1])*C:o7(b+(c?w:-w)/C,s[0][1])*C,A=Math.max(A,e)}}if(d){let e=s7(D*C,h,g)/C;if(j=Math.max(j,e),o){let e=0;e=!c&&!l||l&&!c&&f?o7(y+D*C+O,o[1][0])/C:a7(y+(l?T:-T)*C+O,o[0][0])/C,j=Math.max(j,e)}if(s){let e=0;e=!c&&!l||l&&!c&&f?a7(y+D*C,s[1][0])/C:o7(y+(l?T:-T)*C,s[0][0])/C,j=Math.max(j,e)}}}T+=T<0?j:-j,w+=w<0?A:-A,i&&(f?E>D*C?T=(FXe(c,l)?-w:w)/C:w=(FXe(c,l)?-T:T)*C:u?(T=w/C,l=c):(w=T*C,c=l));let M=c?y+w:y,N=l?b+T:b;return{width:x+(c?-w:w),height:S+(l?-T:T),x:a[0]*w*(c?-1:1)+M,y:a[1]*T*(l?-1:1)+N}}var LXe={width:0,height:0,x:0,y:0},RXe={...LXe,pointerX:0,pointerY:0,aspectRatio:1};function zXe(e){return[[0,0],[e.measured.width,e.measured.height]]}function BXe(e,t,n){let r=t.position.x+e.position.x,i=t.position.y+e.position.y,a=e.measured.width??0,o=e.measured.height??0,s=n[0]*a,c=n[1]*o;return[[r-s,i-c],[r+a-s,i+o-c]]}function VXe({domNode:e,nodeId:t,getStoreItems:n,onChange:r,onEnd:i}){let a=V6(e),o={controlDirection:PXe(`bottom-right`),boundaries:{minWidth:0,minHeight:0,maxWidth:Number.MAX_VALUE,maxHeight:Number.MAX_VALUE},resizeDirection:void 0,keepAspectRatio:!1};function s({controlPosition:e,boundaries:s,keepAspectRatio:c,resizeDirection:l,onResizeStart:u,onResize:d,onResizeEnd:f,shouldResize:p}){let m={...LXe},h={...RXe};o={boundaries:s,resizeDirection:l,keepAspectRatio:c,controlDirection:PXe(e)};let g,_=null,v=[],y,b,x,S=!1,C=X6().on(`start`,e=>{let{nodeLookup:r,transform:i,snapGrid:a,snapToGrid:o,nodeOrigin:s,paneDomNode:c}=n();if(g=r.get(t),!g)return;_=c?.getBoundingClientRect()??null;let{xSnapped:l,ySnapped:d}=z5(e.sourceEvent,{transform:i,snapGrid:a,snapToGrid:o,containerBounds:_});m={width:g.measured.width??0,height:g.measured.height??0,x:g.position.x??0,y:g.position.y??0},h={...m,pointerX:l,pointerY:d,aspectRatio:m.width/m.height},y=void 0,g.parentId&&(g.extent===`parent`||g.expandParent)&&(y=r.get(g.parentId),b=y&&g.extent===`parent`?zXe(y):void 0),v=[],x=void 0;for(let[e,n]of r)if(n.parentId===t&&(v.push({id:e,position:{...n.position},extent:n.extent}),n.extent===`parent`||n.expandParent)){let e=BXe(n,g,n.origin??s);x=x?[[Math.min(e[0][0],x[0][0]),Math.min(e[0][1],x[0][1])],[Math.max(e[1][0],x[1][0]),Math.max(e[1][1],x[1][1])]]:e}u?.(e,{...m})}).on(`drag`,e=>{let{transform:t,snapGrid:i,snapToGrid:a,nodeOrigin:s}=n(),c=z5(e.sourceEvent,{transform:t,snapGrid:i,snapToGrid:a,containerBounds:_}),l=[];if(!g)return;let{x:u,y:f,width:C,height:w}=m,T={},E=g.origin??s,{width:D,height:O,x:k,y:A}=IXe(h,o.controlDirection,c,o.boundaries,o.keepAspectRatio,E,b,x),j=D!==C,M=O!==w,N=k!==u&&j,P=A!==f&&M;if(!N&&!P&&!j&&!M)return;if((N||P||E[0]===1||E[1]===1)&&(T.x=N?k:m.x,T.y=P?A:m.y,m.x=T.x,m.y=T.y,v.length>0)){let e=k-u,t=A-f;for(let n of v)n.position={x:n.position.x-e+E[0]*(D-C),y:n.position.y-t+E[1]*(O-w)},l.push(n)}if((j||M)&&(T.width=j&&(!o.resizeDirection||o.resizeDirection===`horizontal`)?D:m.width,T.height=M&&(!o.resizeDirection||o.resizeDirection===`vertical`)?O:m.height,m.width=T.width,m.height=T.height),y&&g.expandParent){let e=E[0]*(T.width??0);T.x&&T.x<e&&(m.x=e,h.x-=T.x-e);let t=E[1]*(T.height??0);T.y&&T.y<t&&(m.y=t,h.y-=T.y-t)}let F=NXe({width:m.width,prevWidth:C,height:m.height,prevHeight:w,affectsX:o.controlDirection.affectsX,affectsY:o.controlDirection.affectsY}),I={...m,direction:F};p?.(e,I)!==!1&&(S=!0,d?.(e,I),r(T,l))}).on(`end`,e=>{S&&=(f?.(e,{...m}),i?.({...m}),!1)});a.call(C)}function c(){a.on(`.drag`,null)}return{update:s,destroy:c}}var HXe=e=>{let t,n=new Set,r=(e,r)=>{let i=typeof e==`function`?e(t):e;if(!Object.is(i,t)){let e=t;t=r??(typeof i!=`object`||!i)?i:Object.assign({},t,i),n.forEach(n=>n(t,e))}},i=()=>t,a={setState:r,getState:i,getInitialState:()=>o,subscribe:e=>(n.add(e),()=>n.delete(e)),destroy:()=>{n.clear()}},o=t=e(r,i,a);return a},UXe=e=>e?HXe(e):HXe,{useDebugValue:WXe}=H.default,{useSyncExternalStoreWithSelector:GXe}=xo.default,KXe=e=>e;function qXe(e,t=KXe,n){let r=GXe(e.subscribe,e.getState,e.getServerState||e.getInitialState,t,n);return WXe(r),r}var JXe=(e,t)=>{let n=UXe(e),r=(e,r=t)=>qXe(n,e,r);return Object.assign(r,n),r},YXe=(e,t)=>e?JXe(e,t):JXe;function c7(e,t){if(Object.is(e,t))return!0;if(typeof e!=`object`||!e||typeof t!=`object`||!t)return!1;if(e instanceof Map&&t instanceof Map){if(e.size!==t.size)return!1;for(let[n,r]of e)if(!Object.is(r,t.get(n)))return!1;return!0}if(e instanceof Set&&t instanceof Set){if(e.size!==t.size)return!1;for(let n of e)if(!t.has(n))return!1;return!0}let n=Object.keys(e);if(n.length!==Object.keys(t).length)return!1;for(let r of n)if(!Object.prototype.hasOwnProperty.call(t,r)||!Object.is(e[r],t[r]))return!1;return!0}var l7=(0,H.createContext)(null),XXe=l7.Provider,ZXe=u5.error001();function u7(e,t){let n=(0,H.useContext)(l7);if(n===null)throw Error(ZXe);return qXe(n,e,t)}function d7(){let e=(0,H.useContext)(l7);if(e===null)throw Error(ZXe);return(0,H.useMemo)(()=>({getState:e.getState,setState:e.setState,subscribe:e.subscribe}),[e])}var QXe={display:`none`},$Xe={position:`absolute`,width:1,height:1,margin:-1,border:0,padding:0,overflow:`hidden`,clip:`rect(0px, 0px, 0px, 0px)`,clipPath:`inset(100%)`},eZe=`react-flow__node-desc`,tZe=`react-flow__edge-desc`,nZe=`react-flow__aria-live`,rZe=e=>e.ariaLiveMessage,iZe=e=>e.ariaLabelConfig;function aZe({rfId:e}){let t=u7(rZe);return(0,U.jsx)(`div`,{id:`${nZe}-${e}`,"aria-live":`assertive`,"aria-atomic":`true`,style:$Xe,children:t})}function oZe({rfId:e,disableKeyboardA11y:t}){let n=u7(iZe);return(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(`div`,{id:`${eZe}-${e}`,style:QXe,children:t?n[`node.a11yDescription.default`]:n[`node.a11yDescription.keyboardDisabled`]}),(0,U.jsx)(`div`,{id:`${tZe}-${e}`,style:QXe,children:n[`edge.a11yDescription.default`]}),!t&&(0,U.jsx)(aZe,{rfId:e})]})}var f7=(0,H.forwardRef)(({position:e=`top-left`,children:t,className:n,style:r,...i},a)=>{let o=`${e}`.split(`-`);return(0,U.jsx)(`div`,{className:_6([`react-flow__panel`,n,...o]),style:r,ref:a,...i,children:t})});f7.displayName=`Panel`;function sZe({proOptions:e,position:t=`bottom-right`}){return e?.hideAttribution?null:(0,U.jsx)(f7,{position:t,className:`react-flow__attribution`,"data-message":`Please only hide this attribution when you are subscribed to React Flow Pro: https://pro.reactflow.dev`,children:(0,U.jsx)(`a`,{href:`https://reactflow.dev`,target:`_blank`,rel:`noopener noreferrer`,"aria-label":`React Flow attribution`,children:`React Flow`})})}var cZe=e=>{let t=[],n=[];for(let[,n]of e.nodeLookup)n.selected&&t.push(n.internals.userNode);for(let[,t]of e.edgeLookup)t.selected&&n.push(t);return{selectedNodes:t,selectedEdges:n}},p7=e=>e.id;function lZe(e,t){return c7(e.selectedNodes.map(p7),t.selectedNodes.map(p7))&&c7(e.selectedEdges.map(p7),t.selectedEdges.map(p7))}function uZe({onSelectionChange:e}){let t=d7(),{selectedNodes:n,selectedEdges:r}=u7(cZe,lZe);return(0,H.useEffect)(()=>{let i={nodes:n,edges:r};e?.(i),t.getState().onSelectionChangeHandlers.forEach(e=>e(i))},[n,r,e]),null}var dZe=e=>!!e.onSelectionChangeHandlers;function fZe({onSelectionChange:e}){let t=u7(dZe);return e||t?(0,U.jsx)(uZe,{onSelectionChange:e}):null}var m7=typeof window<`u`?H.useLayoutEffect:H.useEffect,pZe=[0,0],mZe={x:0,y:0,zoom:1},hZe=[...`nodes.edges.defaultNodes.defaultEdges.onConnect.onConnectStart.onConnectEnd.onClickConnectStart.onClickConnectEnd.nodesDraggable.autoPanOnNodeFocus.nodesConnectable.nodesFocusable.edgesFocusable.edgesReconnectable.elevateNodesOnSelect.elevateEdgesOnSelect.minZoom.maxZoom.nodeExtent.onNodesChange.onEdgesChange.elementsSelectable.connectionMode.snapGrid.snapToGrid.translateExtent.connectOnClick.defaultEdgeOptions.fitView.fitViewOptions.onNodesDelete.onEdgesDelete.onDelete.onNodeDrag.onNodeDragStart.onNodeDragStop.onSelectionDrag.onSelectionDragStart.onSelectionDragStop.onMoveStart.onMove.onMoveEnd.noPanClassName.nodeOrigin.autoPanOnConnect.autoPanOnNodeDrag.onError.connectionRadius.isValidConnection.selectNodesOnDrag.nodeDragThreshold.connectionDragThreshold.onBeforeDelete.debug.autoPanSpeed.ariaLabelConfig.zIndexMode`.split(`.`),`rfId`],gZe=e=>({setNodes:e.setNodes,setEdges:e.setEdges,setMinZoom:e.setMinZoom,setMaxZoom:e.setMaxZoom,setTranslateExtent:e.setTranslateExtent,setNodeExtent:e.setNodeExtent,reset:e.reset,setDefaultNodesAndEdges:e.setDefaultNodesAndEdges}),_Ze={translateExtent:d5,nodeOrigin:pZe,minZoom:.5,maxZoom:2,elementsSelectable:!0,noPanClassName:`nopan`,rfId:`1`};function vZe(e){let{setNodes:t,setEdges:n,setMinZoom:r,setMaxZoom:i,setTranslateExtent:a,setNodeExtent:o,reset:s,setDefaultNodesAndEdges:c}=u7(gZe,c7),l=d7();m7(()=>(c(e.defaultNodes,e.defaultEdges),()=>{u.current=_Ze,s()}),[]);let u=(0,H.useRef)(_Ze);return m7(()=>{for(let s of hZe){let c=e[s];c!==u.current[s]&&e[s]!==void 0&&(s===`nodes`?t(c):s===`edges`?n(c):s===`minZoom`?r(c):s===`maxZoom`?i(c):s===`translateExtent`?a(c):s===`nodeExtent`?o(c):s===`ariaLabelConfig`?l.setState({ariaLabelConfig:wYe(c)}):s===`fitView`?l.setState({fitViewQueued:c}):s===`fitViewOptions`?l.setState({fitViewOptions:c}):l.setState({[s]:c}))}u.current=e},hZe.map(t=>e[t])),null}function yZe(){return typeof window>`u`||!window.matchMedia?null:window.matchMedia(`(prefers-color-scheme: dark)`)}function bZe(e){let[t,n]=(0,H.useState)(e===`system`?null:e);return(0,H.useEffect)(()=>{if(e!==`system`){n(e);return}let t=yZe(),r=()=>n(t?.matches?`dark`:`light`);return r(),t?.addEventListener(`change`,r),()=>{t?.removeEventListener(`change`,r)}},[e]),t===null?yZe()?.matches?`dark`:`light`:t}var xZe=typeof document<`u`?document:null;function h7(e=null,t={target:xZe,actInsideInputWithModifier:!0}){let[n,r]=(0,H.useState)(!1),i=(0,H.useRef)(!1),a=(0,H.useRef)(new Set([])),[o,s]=(0,H.useMemo)(()=>{if(e!==null){let t=(Array.isArray(e)?e:[e]).filter(e=>typeof e==`string`).map(e=>e.replace(`+`,`
213
213
  `).replace(`
214
214
 
215
215
  `,`